Files
VisualSapfor/src/_VisualDVM/Passes/All/SPF_GetGraphFunctions.java

122 lines
5.7 KiB
Java

package _VisualDVM.Passes.All;
import Common.Utils.Utils_;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Passes.Sapfor.SapforAnalysis;
import _VisualDVM.ProjectData.Files.DBProjectFile;
import _VisualDVM.ProjectData.SapforData.Functions.FuncCall;
import _VisualDVM.ProjectData.SapforData.Functions.FuncInfo;
import _VisualDVM.ProjectData.SapforData.Functions.FunctionType;
import _VisualDVM.ProjectData.SapforData.Functions.Json.FileFunctionsJson;
import _VisualDVM.ProjectData.SapforData.Functions.Json.FunctionsJson;
import java.util.LinkedHashMap;
public class SPF_GetGraphFunctions extends SapforAnalysis {
@Override
protected void showPreparation() {
if (Global.mainModule.HasFile())
Global.mainModule.getFile().form.ShowNoFunctions();
Global.mainModule.getUI().getMainWindow().getProjectWindow().ShowNoFunctions();
if (SPF_GetGraphFunctionPositions.showByCurrentFunction)
Global.mainModule.getUI().getMainWindow().getProjectWindow().getFunctionsWindow().ShowNoCurrentFunction();
}
@Override
protected boolean alwaysCheck() {
return true;
}
@Override
protected boolean isAtomic() {
return false;
}
@Override
protected void performPreparation() throws Exception {
super.performPreparation(); //удаление интеррупта.
Global.mainModule.set(Current.Function, null);
Global.mainModule.set(Current.SelectedFunction, null);
target.main_function = null;
target.main_functionH = null;
target.allFunctions.clear();
target.functionsGraph.Clear();
target.inline_root.removeAllChildren();
target.inline_root2.removeAllChildren();
//-
target.numFunctions = 0;
for (DBProjectFile file : target.db.files.Data.values())
file.function_decls.clear();
}
@Override
protected void unpack(String packed) throws Exception {
LinkedHashMap<String, FuncInfo> declarated_functions = new LinkedHashMap<>();
//--
FunctionsJson functionsJson = Utils_.gson.fromJson(packed, FunctionsJson.class);
for (FileFunctionsJson fileFunctionsJson : functionsJson.allFunctions) {
fileFunctionsJson.file = Utils_.toW(fileFunctionsJson.file);
DBProjectFile projectFile = target.db.files.get(fileFunctionsJson.file);
projectFile.saveFunctions(fileFunctionsJson.functions);
//--
for (FuncInfo funcInfo: projectFile.function_decls.values()){
if (!declarated_functions.containsKey(funcInfo.funcName))
declarated_functions.put(funcInfo.funcName, funcInfo);
}
}
//---
//вторая фаза распаковки. дополняем список стандартными и не найденными функциями
//------
LinkedHashMap<String, FuncInfo> special_functions = new LinkedHashMap<>();
for (FuncInfo funcInfo : declarated_functions.values()) {
for (FuncCall funcCall : funcInfo.calls) {
if (!declarated_functions.containsKey(funcCall.funcName) && (
!special_functions.containsKey(funcCall.funcName)
)) {
//нет среди объявленных и еще не встречалась. значит это стандартная либо не найдено объявление.
special_functions.put(funcCall.funcName,
new FuncInfo(funcCall.funcName,
sapfor.isIntrinsic(funcCall.funcName) ?
FunctionType.Standard : FunctionType.NotFound
));
}
}
}
//------
//составляем единый список функций.
LinkedHashMap<String, FuncInfo> all_functions = target.allFunctions;
declarated_functions.values().forEach(funcInfo -> all_functions.put(funcInfo.funcName, funcInfo));
special_functions.values().forEach(funcInfo -> all_functions.put(funcInfo.funcName, funcInfo));
//------
//теперь когда известны все объявления, ищем где они вызвались
//<editor-fold desc="Функции и их вызовы по файлам">
target.BuildInlineGraph();
//</editor-fold>
//<editor-fold desc="иерархический граф.">
target.BuildInlineGraph2();
//--
//</editor-fold>
target.numFunctions += target.allFunctions.size();
target.UpdateFunctionsCount();
}
@Override
public String phase() {
return "CALL_GRAPH2";
}
@Override
protected void FocusResult() {
super.FocusResult();
if (Global.mainModule.HasFile())
Global.mainModule.getFile().form.FocusFunctions();
Global.mainModule.getUI().getMainWindow().getProjectWindow().FocusFunctions();
}
@Override
protected void showDone() throws Exception {
super.showDone();
Global.mainModule.getUI().getMainWindow().getProjectWindow().getAnalysisWindow().ShowFunctionsCount();
Global.mainModule.getUI().getMainWindow().getProjectWindow().getAnalysisWindow().ShowRegions();
if (Global.mainModule.HasFile())
Global.mainModule.getFile().form.ShowFunctions();
Global.mainModule.getPass(PassCode.SPF_GetGraphFunctionPositions).Do();
//--
DBProjectFile main=target.getMainProgramUnit();
if (main!=null)
Global.mainModule.getUI().getMainWindow().getProjectWindow().getFilesTreeForm().getTree().RefreshNode(main.node);
}
}