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

200 lines
7.6 KiB
Java
Raw Normal View History

2024-10-14 12:14:01 +03:00
package _VisualDVM.Passes.All;
2024-10-11 00:00:30 +03:00
import Common.Utils.Utils_;
import Common.Visual.UI;
import _VisualDVM.Global;
2024-10-09 22:21:57 +03:00
import _VisualDVM.GlobalData.Settings.SettingName;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Passes.Sapfor.SapforAnalysis;
2024-10-09 22:21:57 +03:00
import _VisualDVM.ProjectData.Files.DBProjectFile;
import _VisualDVM.ProjectData.Files.FileState;
import _VisualDVM.Repository.Component.Sapfor.TransformationPermission;
2023-09-17 22:13:42 +03:00
import org.apache.commons.io.FileUtils;
import java.util.Vector;
public class SPF_ParseFilesWithOrder extends SapforAnalysis {
public static boolean silent = false;
public static boolean precompilation_done = false;
int goodCount = 0;
int badCount = 0;
Vector<String> projLines = new Vector<>();
@Override
public String phase() {
return "PARSE_FILES";
}
@Override
2024-10-09 23:37:58 +03:00
protected PassCode necessary() {
2023-09-17 22:13:42 +03:00
return null;
}
protected boolean checkActiveFiles() {
int count = 0;
for (DBProjectFile f : target.db.files.Data.values())
if (f.isActiveProgram()) {
count++;
}
if (count == 0) {
Log.Writeln_("В проекте не найдено ни одного активного файла типа 'Программа'.");
return false;
} else return true;
}
@Override
protected boolean canStart(Object... args) throws Exception {
precompilation_done = false;
boolean res = (
silent ||
2024-10-12 00:17:51 +03:00
(!Global.mainModule.getDb().settings.get(SettingName.Precompilation).toBoolean() ||
2024-10-14 15:19:13 +03:00
(precompilation_done = Global.mainModule.getPass(PassCode.Precompilation).Do())))
2023-09-17 22:13:42 +03:00
&& super.canStart(args) && checkActiveFiles();
return res;
}
@Override
protected boolean isGoodCode() {
return sapfor.getErrorCode() == 0;
}
@Override
public boolean needsConfirmations() {
return !silent;
}
@Override
protected void unpackMessages() throws Exception {
target.updateLog(sapfor.getOutput());
projLines.clear();
goodCount = 0;
badCount = 0;
for (DBProjectFile f : target.db.files.Data.values())
if (f.isActive()) f.state = FileState.OK;
for (DBProjectFile f : target.db.files.Data.values()) {
f.ReadParseMessages();
f.father.db.Update(f);
if (f.isActive()) {
switch (f.state) {
case OK:
case HasNotes:
case HasWarnings:
if (f.isActiveProgram())
2024-10-11 00:00:30 +03:00
projLines.add(Utils_.toU(f.getDepFile().getAbsolutePath()));
2023-09-17 22:13:42 +03:00
goodCount++;
break;
case HasErrors:
badCount++;
break;
default:
break;
}
}
}
FileUtils.writeLines(target.getProjFile(), projLines, false);
}
@Override
protected boolean validate() {
if (super.validate()) {
if (badCount > 0) {
Log.Writeln_("Найдено файлов с синтаксическими ошибками: " + badCount);
return false;
}
if (goodCount == 0) {
Log.Writeln_("Не найдено ни одного успешно проанализированного файла на языке проекта :" +
2024-10-11 00:00:30 +03:00
Utils_.DQuotes(target.languageName.getDescription()));
2023-09-17 22:13:42 +03:00
return false;
}
return true;
}
return false;
}
@Override
protected void unpack(String packed) throws Exception {
for (String fileName_ : packed.split("\\|"))
2024-10-11 00:00:30 +03:00
target.files_order.add(Utils_.toW(fileName_));
2023-09-17 22:13:42 +03:00
}
@Override
protected void performPreparation() throws Exception {
super.performPreparation(); //удаление интеррупта.
//------------------------------------------------------------------------------------------>>> пакетный режим.
if (!precompilation_done && UI.isActive()) {
Global.mainModule.getPass(PassCode.Save).Do();
2023-09-17 22:13:42 +03:00
target.CleanAnalyses();
}
//перезапуск сапфора.------
sapfor.Restart(); // тут же идет и сброс актуальности всех анализов.
sapfor.cd(target.Home);
sapfor.GetIntrinsics();
//--------------------------
projLines.clear();
Global.transformationPermission = TransformationPermission.None;
target.CreateParserOptionsDirs();
//---------------------------
for (DBProjectFile f : target.db.files.Data.values()) {
if (f.isActiveProgram()) {
2024-10-11 00:00:30 +03:00
projLines.add(Utils_.toU(f.file.getAbsolutePath()));
2023-09-17 22:13:42 +03:00
f.CreateParserOptions();
}
}
FileUtils.writeLines(target.getProjFile(), projLines, false);
/*
if (projLines.isEmpty())
throw new PassException("Язык проекта "+
Utils.DQuotes(target.languageName.getDescription())+",\n" +
"но не найдено ни одного файла на этом языке");
*/
}
@Override
protected void showPreparation() throws Exception {
if (!precompilation_done) {
Global.mainModule.getUI().getMainWindow().getProjectWindow().ShowNoAnalyses();
if (Global.mainModule.HasFile()) {
Global.mainModule.getFile().form.ShowNoMessages();
Global.mainModule.getFile().form.ShowNoAnalyses();
2023-09-17 22:13:42 +03:00
}
}
}
@Override
protected void performDone() throws Exception {
super.performDone();
sapfor.Restart(); //рестарт скидывает все анализы в том числе парс и текущую папку.
sapfor.cd(target.Home);
Global.mainModule.getPass(PassCode.RestoreSavedArrays).Do();
2023-09-17 22:13:42 +03:00
setDone();
/*
//особенность парса. журнал появляется только сейчас.
if (!sapfor.getOutput().isEmpty()) {
target.updateLog(sapfor.getOutput());
}
*/
Global.transformationPermission = TransformationPermission.All;
Global.enable_text_changed = true;
}
/*
@Override
protected void showDone() throws Exception {
super.showDone();
UI.getNewMainWindow().getProjectWindow().ShowProjectSapforLog();
}
*/
@Override
protected void performFinish() throws Exception {
Global.changeSetting(SettingName.PARSE_FOR_INLINE, "0");
// Pass_2021.passes.get(PassCode_2021.UpdateSetting).Do(SettingName.PARSE_FOR_INLINE, "0");
super.performFinish();
}
@Override
protected void showFinish() throws Exception {
super.showFinish();
Global.mainModule.getUI().getMainWindow().getProjectWindow().ShowAllAnalyses();
if (Global.mainModule.HasFile())
Global.mainModule.getFile().form.ShowAllAnalyses();
2023-09-17 22:13:42 +03:00
}
@Override
protected void showFail() throws Exception {
super.showFail();
}
@Override
protected void FocusResult() {
super.FocusResult();
Global.mainModule.getUI().getMainWindow().getProjectWindow().FocusFile();
2023-09-17 22:13:42 +03:00
}
@Override
protected void performFail() throws Exception {
super.performFail();
2024-10-14 12:54:52 +03:00
Utils_.forceDeleteWithCheck(target.getProjFile());
2023-09-17 22:13:42 +03:00
}
}