mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
bug #191121, fix perfomance problems in C99 parser by making the parser object a singleton
This commit is contained in:
parent
398742f0b8
commit
2b6e354084
1 changed files with 30 additions and 5 deletions
|
@ -172,9 +172,9 @@ public class UPCParser extends PrsStream implements RuleAction , IParserActionTo
|
|||
}
|
||||
|
||||
|
||||
private UPCParserAction action = new UPCParserAction (this, UPCParserprs.orderedTerminalSymbols);
|
||||
private UPCParserAction action = null;
|
||||
private List commentTokens = null;
|
||||
private IKeywordMap keywordMap = new UPCKeywordMap ();
|
||||
private List commentTokens = new ArrayList();
|
||||
|
||||
public UPCParser() { // constructor
|
||||
this(new C99Lexer() {
|
||||
|
@ -205,11 +205,36 @@ public List getCommentTokens() {
|
|||
return commentTokens;
|
||||
}
|
||||
|
||||
public void resetTokenStream() {
|
||||
super.resetTokenStream();
|
||||
action = new UPCParserAction (this, UPCParserprs.orderedTerminalSymbols);
|
||||
commentTokens = new ArrayList();
|
||||
}
|
||||
|
||||
|
||||
public IParseResult parse() {
|
||||
// this has to be done, or... kaboom!
|
||||
setStreamLength(getSize());
|
||||
// do the actual parsing, -1 means full error handling
|
||||
parser(null, -1);
|
||||
|
||||
final int errorRepairCount = -1; // -1 means full error handling
|
||||
|
||||
if(btParser == null) {
|
||||
parser(null, errorRepairCount);
|
||||
}
|
||||
else {
|
||||
try
|
||||
{
|
||||
// reuse the same btParser object for speed
|
||||
// (creating an new instance for every translation unit is dirt slow)
|
||||
btParser.parse(errorRepairCount);
|
||||
}
|
||||
catch (BadParseException e)
|
||||
{
|
||||
reset(e.error_token); // point to error token
|
||||
DiagnoseParser diagnoseParser = new DiagnoseParser(this, prs);
|
||||
diagnoseParser.diagnose(e.error_token);
|
||||
}
|
||||
}
|
||||
|
||||
IASTTranslationUnit tu = action.getAST();
|
||||
boolean encounteredError = action.encounteredError();
|
||||
|
|
Loading…
Add table
Reference in a new issue