GP-3284 Added TaskMonitor into Preprocessor and CParser parser loops

This commit is contained in:
emteere
2023-04-03 22:57:46 +00:00
parent 88d0110a09
commit 1876e884c8
4 changed files with 29 additions and 1 deletions
@@ -204,6 +204,7 @@ public class CParserPlugin extends ProgramPlugin {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
cpp.setOutputStream(bos);
cpp.setMonitor(monitor);
try {
for (String filename : filenames) {
@@ -257,6 +258,7 @@ public class CParserPlugin extends ProgramPlugin {
try {
parserMessages = "";
cParser.setParseFileName(fName);
cParser.setMonitor(monitor);
cParser.parse(bis);
}
finally {
@@ -441,6 +441,7 @@ public class CParserUtils {
PrintStream old = System.out;
System.setOut(os);
cpp.setMonitor(monitor);
cpp.setOutputStream(bos);
try {
@@ -494,6 +495,7 @@ public class CParserUtils {
try {
parserMessages = "";
cParser.setParseFileName(fName);
cParser.setMonitor(monitor);
cParser.parse(bis);
} finally {
parserMessages = cParser.getParseMessages();
@@ -84,6 +84,7 @@ package ghidra.app.util.cparser.C;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum;
import ghidra.util.Msg;
import ghidra.util.task.TaskMonitor;
import ghidra.util.InvalidNameException;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException;
@@ -138,6 +139,8 @@ public class CParser {
// true if parse was successful
private boolean parseSuccess = false;
private TaskMonitor monitor = null;
// packing size for structures
private int packSize = 0;
Stack<Integer> packStack = new Stack<Integer>();
@@ -546,6 +549,10 @@ public class CParser {
public boolean didParseSucceed() {
return parseSuccess;
}
public void setMonitor(TaskMonitor monitor) {
this.monitor = monitor;
}
private FunctionDefinitionDataType newAnonymousFunction(FunctionDefinitionDataType currentFuncDT) {
if (currentFuncDT != null) {
@@ -1440,6 +1447,9 @@ void ExternalDeclaration() : {}
";"
)
{
if (monitor != null && monitor.isCancelled()) {
throw new ParseException("Parsing Canceled");
}
typedefParsingStack.clear();
}
}
@@ -110,6 +110,7 @@ PARSER_BEGIN(PreProcessor)
package ghidra.app.util.cparser.CPP;
import ghidra.util.Msg;
import ghidra.util.task.TaskMonitor;
import java.util.*;
import java.io.*;
@@ -549,6 +550,8 @@ public class PreProcessor {
// true if parse was successful
private boolean parseSuccess = false;
private TaskMonitor monitor = null;
// Toggle printing
private int verboseLevel = 0;
@@ -1334,6 +1337,10 @@ public class PreProcessor {
public PreProcessor() throws ParseException {
this(System.in);
}
public void setMonitor(TaskMonitor monitor) {
this.monitor = monitor;
}
// Run the parser
public static void main(String args[]) {
@@ -1359,7 +1366,14 @@ void Input() :
ppt.emit(false);
}
{
( b=TranslationUnit(){if (b.getTruth()==false) break;})*
( b=TranslationUnit()
{
if (monitor != null && monitor.isCancelled()) {
throw new ParseException("Parsing Canceled");
}
if (b.getTruth()==false) break;
}
)*
{
if (conditionDepth!=execStack.size()) {
addParseMessage(null, "Imbalance in sequence/nesting of compile-time conditions/logic in input file "+curFileStackTop());