mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +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 IKeywordMap keywordMap = new UPCKeywordMap ();
|
||||||
private List commentTokens = new ArrayList();
|
|
||||||
|
|
||||||
public UPCParser() { // constructor
|
public UPCParser() { // constructor
|
||||||
this(new C99Lexer() {
|
this(new C99Lexer() {
|
||||||
|
@ -205,11 +205,36 @@ public List getCommentTokens() {
|
||||||
return commentTokens;
|
return commentTokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetTokenStream() {
|
||||||
|
super.resetTokenStream();
|
||||||
|
action = new UPCParserAction (this, UPCParserprs.orderedTerminalSymbols);
|
||||||
|
commentTokens = new ArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public IParseResult parse() {
|
public IParseResult parse() {
|
||||||
// this has to be done, or... kaboom!
|
// this has to be done, or... kaboom!
|
||||||
setStreamLength(getSize());
|
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();
|
IASTTranslationUnit tu = action.getAST();
|
||||||
boolean encounteredError = action.encounteredError();
|
boolean encounteredError = action.encounteredError();
|
||||||
|
|
Loading…
Add table
Reference in a new issue