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

90 lines
3.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.Passes.All;
import Common.Utils.Utils_;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Passes.Sapfor.SapforTransformation;
import _VisualDVM.ProjectData.SapforData.Functions.FuncCallH;
import java.util.Vector;
public class SPF_InlineProceduresH extends SapforTransformation {
@Override
protected PassCode necessary() {
return PassCode.SPF_GetGraphFunctions;
}
public void getCallsChainR(Vector<FuncCallH> chain, Vector<Vector<FuncCallH>> all) {
if (chain.lastElement().calls.isEmpty())
all.add(chain);
else {
for (FuncCallH descendant : chain.lastElement().calls) {
Vector<FuncCallH> new_chain = new Vector<>(chain);
new_chain.add(descendant);
getCallsChainR(new_chain, all);
}
}
}
public void extractSelectionChains(Vector<FuncCallH> chain, Vector<Vector<FuncCallH>> res) {
for (FuncCallH call : chain) {
if (call.isSelected()) {
//в цепочке есть хоть 1 выбранный элемент. значит берем ее.
res.add(chain);
return;
}
}
}
@Override
protected boolean canStart(Object... args) throws Exception {
if (super.canStart(args)) {
if (target.main_functionH == null) {
Log.Writeln("Отсутствует главная программная единица");
return false;
}
//получили все цепочки.
Vector<Vector<FuncCallH>> all = new Vector<>();
Vector<FuncCallH> first_chain = new Vector<>();
first_chain.add(target.main_functionH);
getCallsChainR(first_chain, all);
//-
//проверка наличия выбранных путей.
Vector<Vector<FuncCallH>> selectedChains = new Vector<>();
for (Vector<FuncCallH> chain : all)
extractSelectionChains(chain, selectedChains);
if (selectedChains.isEmpty()) {
Log.Writeln_(
(callsCount > 1) ? "Не отмечено ни одной цепочки вызовов процедур для подстановки" :
"Для иерархической подстановки процедур следует отметить\n" +
"хотя бы один вызов процедуры в иерархии."
);
return false;
}
Vector<String> Result = new Vector<>();
//-
Result.add(String.valueOf(selectedChains.size()));
for (Vector<FuncCallH> chain : selectedChains) {
Result.add(String.valueOf(chain.size()));
for (FuncCallH call : chain) {
Result.add(call.funcName);
Result.add(call.file);
Result.add(String.valueOf(call.line));
//--
//todo со стороны сапфора. подставлять ли вызов в конкретной цепочке.
Result.add(call.isSelected() ? "1" : "0");
}
}
Options = Utils_.toU(String.join("|", Result));
target.sapforProperties.PARSE_FOR_INLINE=true;
target.sapforProperties.Update();
SPF_ParseFilesWithOrder.silent = true;
return Global.mainModule.getPass(PassCode.SPF_ParseFilesWithOrder).Do();
}
return false;
}
@Override
protected void performFinish() throws Exception {
SPF_ParseFilesWithOrder.silent = false;
super.performFinish();
}
@Override
protected void FocusBeforeStart() {
Global.mainModule.getUI().getMainWindow().getProjectWindow().FocusHierarchy();
}
}