mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-01 12:06:57 +08:00
Merge remote-tracking branch
'origin/GP-3284_emteere_CParserCancelMoreResponsive' (Closes #5181)
This commit is contained in:
@@ -204,6 +204,7 @@ public class CParserPlugin extends ProgramPlugin {
|
|||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
cpp.setOutputStream(bos);
|
cpp.setOutputStream(bos);
|
||||||
|
cpp.setMonitor(monitor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (String filename : filenames) {
|
for (String filename : filenames) {
|
||||||
@@ -257,6 +258,7 @@ public class CParserPlugin extends ProgramPlugin {
|
|||||||
try {
|
try {
|
||||||
parserMessages = "";
|
parserMessages = "";
|
||||||
cParser.setParseFileName(fName);
|
cParser.setParseFileName(fName);
|
||||||
|
cParser.setMonitor(monitor);
|
||||||
cParser.parse(bis);
|
cParser.parse(bis);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|||||||
@@ -441,6 +441,7 @@ public class CParserUtils {
|
|||||||
PrintStream old = System.out;
|
PrintStream old = System.out;
|
||||||
System.setOut(os);
|
System.setOut(os);
|
||||||
|
|
||||||
|
cpp.setMonitor(monitor);
|
||||||
cpp.setOutputStream(bos);
|
cpp.setOutputStream(bos);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -494,6 +495,7 @@ public class CParserUtils {
|
|||||||
try {
|
try {
|
||||||
parserMessages = "";
|
parserMessages = "";
|
||||||
cParser.setParseFileName(fName);
|
cParser.setParseFileName(fName);
|
||||||
|
cParser.setMonitor(monitor);
|
||||||
cParser.parse(bis);
|
cParser.parse(bis);
|
||||||
} finally {
|
} finally {
|
||||||
parserMessages = cParser.getParseMessages();
|
parserMessages = cParser.getParseMessages();
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ package ghidra.app.util.cparser.C;
|
|||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.*;
|
||||||
import ghidra.program.model.data.Enum;
|
import ghidra.program.model.data.Enum;
|
||||||
import ghidra.util.Msg;
|
import ghidra.util.Msg;
|
||||||
|
import ghidra.util.task.TaskMonitor;
|
||||||
import ghidra.util.InvalidNameException;
|
import ghidra.util.InvalidNameException;
|
||||||
import ghidra.util.exception.DuplicateNameException;
|
import ghidra.util.exception.DuplicateNameException;
|
||||||
import ghidra.util.exception.InvalidInputException;
|
import ghidra.util.exception.InvalidInputException;
|
||||||
@@ -138,6 +139,8 @@ public class CParser {
|
|||||||
// true if parse was successful
|
// true if parse was successful
|
||||||
private boolean parseSuccess = false;
|
private boolean parseSuccess = false;
|
||||||
|
|
||||||
|
private TaskMonitor monitor = null;
|
||||||
|
|
||||||
// packing size for structures
|
// packing size for structures
|
||||||
private int packSize = 0;
|
private int packSize = 0;
|
||||||
Stack<Integer> packStack = new Stack<Integer>();
|
Stack<Integer> packStack = new Stack<Integer>();
|
||||||
@@ -552,6 +555,10 @@ public class CParser {
|
|||||||
public boolean didParseSucceed() {
|
public boolean didParseSucceed() {
|
||||||
return parseSuccess;
|
return parseSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMonitor(TaskMonitor monitor) {
|
||||||
|
this.monitor = monitor;
|
||||||
|
}
|
||||||
|
|
||||||
private FunctionDefinitionDataType newAnonymousFunction(FunctionDefinitionDataType currentFuncDT) {
|
private FunctionDefinitionDataType newAnonymousFunction(FunctionDefinitionDataType currentFuncDT) {
|
||||||
if (currentFuncDT != null) {
|
if (currentFuncDT != null) {
|
||||||
@@ -1444,6 +1451,9 @@ void ExternalDeclaration() : {}
|
|||||||
";"
|
";"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if (monitor != null && monitor.isCancelled()) {
|
||||||
|
throw new ParseException("Parsing Canceled");
|
||||||
|
}
|
||||||
typedefParsingStack.clear();
|
typedefParsingStack.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ PARSER_BEGIN(PreProcessor)
|
|||||||
package ghidra.app.util.cparser.CPP;
|
package ghidra.app.util.cparser.CPP;
|
||||||
|
|
||||||
import ghidra.util.Msg;
|
import ghidra.util.Msg;
|
||||||
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -549,6 +550,8 @@ public class PreProcessor {
|
|||||||
|
|
||||||
// true if parse was successful
|
// true if parse was successful
|
||||||
private boolean parseSuccess = false;
|
private boolean parseSuccess = false;
|
||||||
|
|
||||||
|
private TaskMonitor monitor = null;
|
||||||
|
|
||||||
// Toggle printing
|
// Toggle printing
|
||||||
private int verboseLevel = 0;
|
private int verboseLevel = 0;
|
||||||
@@ -1334,6 +1337,10 @@ public class PreProcessor {
|
|||||||
public PreProcessor() throws ParseException {
|
public PreProcessor() throws ParseException {
|
||||||
this(System.in);
|
this(System.in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMonitor(TaskMonitor monitor) {
|
||||||
|
this.monitor = monitor;
|
||||||
|
}
|
||||||
|
|
||||||
// Run the parser
|
// Run the parser
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
@@ -1359,7 +1366,14 @@ void Input() :
|
|||||||
ppt.emit(false);
|
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()) {
|
if (conditionDepth!=execStack.size()) {
|
||||||
addParseMessage(null, "Imbalance in sequence/nesting of compile-time conditions/logic in input file "+curFileStackTop());
|
addParseMessage(null, "Imbalance in sequence/nesting of compile-time conditions/logic in input file "+curFileStackTop());
|
||||||
|
|||||||
Reference in New Issue
Block a user