2024-10-09 22:21:57 +03:00
|
|
|
|
package _VisualDVM.ProjectData.SapforData.Loops;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import Common.Utils.Index;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import Common.Visual.Fonts.VisualiserFonts;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
|
|
|
|
|
import _VisualDVM.ProjectData.Messages.Message;
|
|
|
|
|
|
import _VisualDVM.ProjectData.SapforData.FileObjectWithMessages;
|
|
|
|
|
|
import _VisualDVM.ProjectData.SapforData.Functions.FuncCall;
|
2025-03-28 18:55:54 +03:00
|
|
|
|
import com.google.gson.annotations.Expose;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
2025-03-28 19:57:24 +03:00
|
|
|
|
import java.util.LinkedHashMap;
|
2025-03-28 18:55:54 +03:00
|
|
|
|
import java.util.List;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
public class Loop extends FileObjectWithMessages {
|
2025-03-28 18:55:54 +03:00
|
|
|
|
@Expose
|
2025-03-30 15:30:38 +03:00
|
|
|
|
private int lineNumAfterLoop;
|
2025-03-28 18:55:54 +03:00
|
|
|
|
@Expose
|
2025-03-30 15:30:38 +03:00
|
|
|
|
private int perfectLoop;
|
2025-03-28 18:55:54 +03:00
|
|
|
|
@Expose
|
2025-03-30 15:35:00 +03:00
|
|
|
|
private int hasNonRectangularBounds;
|
|
|
|
|
|
@Expose
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public LoopState loopState;
|
2025-03-28 18:55:54 +03:00
|
|
|
|
//---
|
|
|
|
|
|
@Expose
|
|
|
|
|
|
public List<FuncCall> func_calls = new Vector<>();
|
|
|
|
|
|
@Expose
|
|
|
|
|
|
public List<NonRectIter> non_rect_iters = new Vector<>();
|
|
|
|
|
|
@Expose
|
|
|
|
|
|
public List<EGoto> e_gotos = new Vector<>();
|
|
|
|
|
|
@Expose
|
|
|
|
|
|
public List<IGoto> i_gotos = new Vector<>();
|
|
|
|
|
|
@Expose
|
|
|
|
|
|
public List<IO> ios = new Vector<>();
|
|
|
|
|
|
@Expose
|
|
|
|
|
|
public List<Stop> stops = new Vector<>();
|
|
|
|
|
|
@Expose
|
2025-03-30 15:30:38 +03:00
|
|
|
|
public List<Loop> children = new Vector<>();
|
2025-03-28 18:55:54 +03:00
|
|
|
|
//--
|
2025-03-30 15:30:38 +03:00
|
|
|
|
public List<FileObjectWithMessages> getAllChildren(){
|
|
|
|
|
|
List<FileObjectWithMessages> all_children = new Vector<>();
|
|
|
|
|
|
all_children.addAll(func_calls);
|
|
|
|
|
|
all_children.addAll(non_rect_iters);
|
|
|
|
|
|
all_children.addAll(e_gotos);
|
|
|
|
|
|
all_children.addAll(i_gotos);
|
|
|
|
|
|
all_children.addAll(ios);
|
|
|
|
|
|
all_children.addAll(stops);
|
|
|
|
|
|
all_children.addAll(children);
|
|
|
|
|
|
return all_children;
|
2025-03-28 18:55:54 +03:00
|
|
|
|
}
|
2025-03-30 15:30:38 +03:00
|
|
|
|
/*
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public Loop(String[] packedLoopInfo, Index idx, DBProjectFile father_in) {
|
|
|
|
|
|
file = father_in.name;
|
2025-03-28 18:55:54 +03:00
|
|
|
|
int calls = Integer.parseInt(packedLoopInfo[idx.Inc()]);//+
|
2023-09-17 22:13:42 +03:00
|
|
|
|
for (int k = 0; k < calls; ++k) {
|
|
|
|
|
|
String c_name = packedLoopInfo[idx.Inc()];
|
|
|
|
|
|
int c_line = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
2025-03-28 18:55:54 +03:00
|
|
|
|
func_calls.add(new FuncCall(father_in, c_name, c_line));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
line = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
|
|
|
|
|
lineNumAfterLoop = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
|
|
|
|
|
perfectLoop = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
2025-03-28 19:57:24 +03:00
|
|
|
|
hasOutGoto = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
|
|
|
|
|
hasPrints = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
childCount = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
|
|
|
|
|
int state = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
|
|
|
|
|
switch (state) {
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
loopState = LoopState.GoodLoop;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
loopState = LoopState.BadLoop;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
loopState = LoopState.Loop;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-03-30 15:30:38 +03:00
|
|
|
|
hasNonRectangularBounds = Integer.parseInt(packedLoopInfo[idx.Inc()]); //+
|
|
|
|
|
|
if (hasNonRectangularBounds ==1)
|
2025-03-28 18:55:54 +03:00
|
|
|
|
non_rect_iters.add(new NonRectIter(father_in, line));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
////-------------------------------------------------------------------------------
|
|
|
|
|
|
// число внешних переходов
|
2025-03-28 18:55:54 +03:00
|
|
|
|
int e_gotos_size = Integer.parseInt(packedLoopInfo[idx.Inc()]); //+
|
|
|
|
|
|
for (int k = 0; k < e_gotos_size; ++k) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
int c_line = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
2025-03-28 18:55:54 +03:00
|
|
|
|
e_gotos.add(new EGoto(father_in, c_line));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
//число внутренних переходов
|
2025-03-28 18:55:54 +03:00
|
|
|
|
int i_gotos_size = Integer.parseInt(packedLoopInfo[idx.Inc()]); //+
|
|
|
|
|
|
for (int k = 0; k < i_gotos_size; ++k) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
int c_line = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
2025-03-28 18:55:54 +03:00
|
|
|
|
i_gotos.add(new IGoto(father_in, c_line));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
//число операторов печати
|
2025-03-28 18:55:54 +03:00
|
|
|
|
int IOs_size = Integer.parseInt(packedLoopInfo[idx.Inc()]); //+
|
|
|
|
|
|
for (int k = 0; k < IOs_size; ++k) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
int c_line = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
2025-03-28 18:55:54 +03:00
|
|
|
|
ios.add(new IO(father_in, c_line));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
//число операторов останова (STOPб PAUSE)
|
2025-03-28 18:55:54 +03:00
|
|
|
|
int stops_size = Integer.parseInt(packedLoopInfo[idx.Inc()]); //++
|
|
|
|
|
|
for (int k = 0; k < stops_size; ++k) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
int c_line = Integer.parseInt(packedLoopInfo[idx.Inc()]);
|
2025-03-28 18:55:54 +03:00
|
|
|
|
stops.add(new Stop(father_in, c_line));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
for (int i = 0; i < childCount; ++i) {
|
|
|
|
|
|
Loop nextChild = new Loop(packedLoopInfo, idx, father_in);
|
2025-03-30 15:30:38 +03:00
|
|
|
|
children.add(nextChild);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
father_in.AllLoops.put(line, this);
|
|
|
|
|
|
//нельзя использовать конструктор с параметрами из за особеностей распаковки.
|
|
|
|
|
|
CheckMessagesPresence();
|
|
|
|
|
|
}
|
2025-03-30 15:30:38 +03:00
|
|
|
|
*/
|
2023-09-17 22:13:42 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public String TypeKey() {
|
|
|
|
|
|
return loopState.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String Description() {
|
|
|
|
|
|
return "цикл";
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean HasMessage(Message message) {
|
|
|
|
|
|
return (message.line >= line) && (message.line < lineNumAfterLoop);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
|
return super.toString() + ((perfectLoop > 1) ? (" тесная вложенность " + perfectLoop) : "");
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public VisualiserFonts getFont() {
|
|
|
|
|
|
return loopState.getFont();
|
|
|
|
|
|
}
|
2025-03-28 19:57:24 +03:00
|
|
|
|
public void toMap_r(LinkedHashMap<Integer, Loop> loops_map){
|
|
|
|
|
|
loops_map.put(line, this);
|
2025-03-30 15:30:38 +03:00
|
|
|
|
for (Loop loop: children)
|
2025-03-28 19:57:24 +03:00
|
|
|
|
loop.toMap_r(loops_map);
|
|
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|