mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 10:25:32 +02:00
Undo some of the last checkin to remove the performance problems I created in generating the physical parse tree.
This commit is contained in:
parent
bc48508cee
commit
5af5a134fd
3 changed files with 71 additions and 170 deletions
|
@ -398,6 +398,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
throw backtrack;
|
throw backtrack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IToken simpleDeclarationMark;
|
||||||
|
|
||||||
private static final IASTNode[] EMPTY_NODE_ARRAY = new IASTNode[0];
|
private static final IASTNode[] EMPTY_NODE_ARRAY = new IASTNode[0];
|
||||||
|
|
||||||
|
@ -493,6 +494,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
errorHandling();
|
errorHandling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
protected void throwAwayMarksForInitializerClause() {
|
||||||
|
simpleDeclarationMark = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TODO
|
* @return TODO
|
||||||
|
@ -1584,32 +1590,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
return expressionStatement;
|
return expressionStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ds.getDeclaration() instanceof IASTAmbiguousDeclaration )
|
|
||||||
{
|
|
||||||
IASTAmbiguousDeclaration amb = (IASTAmbiguousDeclaration) ds.getDeclaration();
|
|
||||||
IASTDeclaration [] ambDs = amb.getDeclarations();
|
|
||||||
int ambCount = 0;
|
|
||||||
for( int i = 0; i < ambDs.length; ++i )
|
|
||||||
{
|
|
||||||
if (ambDs[i] instanceof IASTSimpleDeclaration
|
|
||||||
&& ((IASTSimpleDeclaration) ambDs[i])
|
|
||||||
.getDeclSpecifier() instanceof IASTSimpleDeclSpecifier
|
|
||||||
&& ((IASTSimpleDeclSpecifier) ((IASTSimpleDeclaration) ambDs[i]).getDeclSpecifier()).getType() == IASTSimpleDeclSpecifier.t_unspecified) {
|
|
||||||
++ambCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( ambCount == ambDs.length )
|
|
||||||
{
|
|
||||||
backup(mark);
|
|
||||||
while (true) {
|
|
||||||
if (consume() == lastTokenOfExpression)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return expressionStatement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ds.getDeclaration() instanceof IASTSimpleDeclaration
|
if (ds.getDeclaration() instanceof IASTSimpleDeclaration
|
||||||
&& ((IASTSimpleDeclaration) ds.getDeclaration())
|
&& ((IASTSimpleDeclaration) ds.getDeclaration())
|
||||||
.getDeclSpecifier() instanceof IASTNamedTypeSpecifier)
|
.getDeclSpecifier() instanceof IASTNamedTypeSpecifier)
|
||||||
|
|
|
@ -139,10 +139,18 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
supportGCCStyleDesignators = config.supportGCCStyleDesignators();
|
supportGCCStyleDesignators = config.supportGCCStyleDesignators();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param d
|
||||||
|
*/
|
||||||
|
protected void throwAwayMarksForInitializerClause() {
|
||||||
|
simpleDeclarationMark = null;
|
||||||
|
}
|
||||||
|
|
||||||
protected IASTInitializer optionalCInitializer() throws EndOfFileException,
|
protected IASTInitializer optionalCInitializer() throws EndOfFileException,
|
||||||
BacktrackException {
|
BacktrackException {
|
||||||
if (LT(1) == IToken.tASSIGN) {
|
if (LT(1) == IToken.tASSIGN) {
|
||||||
consume(IToken.tASSIGN);
|
consume(IToken.tASSIGN);
|
||||||
|
throwAwayMarksForInitializerClause();
|
||||||
return cInitializerClause(Collections.EMPTY_LIST);
|
return cInitializerClause(Collections.EMPTY_LIST);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -143,7 +143,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.BacktrackException;
|
import org.eclipse.cdt.internal.core.dom.parser.BacktrackException;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider;
|
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
|
||||||
import org.eclipse.cdt.internal.core.parser.SimpleDeclarationStrategy;
|
import org.eclipse.cdt.internal.core.parser.SimpleDeclarationStrategy;
|
||||||
|
@ -172,8 +171,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
private ScopeStack templateIdScopes = new ScopeStack();
|
private ScopeStack templateIdScopes = new ScopeStack();
|
||||||
|
|
||||||
private int templateCount = 0;
|
|
||||||
|
|
||||||
protected CPPASTTranslationUnit translationUnit;
|
protected CPPASTTranslationUnit translationUnit;
|
||||||
|
|
||||||
private static class ScopeStack {
|
private static class ScopeStack {
|
||||||
|
@ -946,7 +943,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
try {
|
try {
|
||||||
declSpecifier = declSpecifierSeq(true, true);
|
declSpecifier = declSpecifierSeq(true, true);
|
||||||
if (LT(1) != IToken.tEOC)
|
if (LT(1) != IToken.tEOC)
|
||||||
declarator = declarator(SimpleDeclarationStrategy.TRY_FUNCTION,
|
declarator = declarator(
|
||||||
|
SimpleDeclarationStrategy.TRY_FUNCTION,
|
||||||
forNewExpression);
|
forNewExpression);
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
|
@ -2125,7 +2123,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken firstToken = null;
|
IToken firstToken = null;
|
||||||
boolean exported = false;
|
boolean exported = false;
|
||||||
boolean encounteredExtraMod = false;
|
boolean encounteredExtraMod = false;
|
||||||
++templateCount;
|
|
||||||
if (LT(1) == IToken.t_export) {
|
if (LT(1) == IToken.t_export) {
|
||||||
exported = true;
|
exported = true;
|
||||||
firstToken = consume(IToken.t_export);
|
firstToken = consume(IToken.t_export);
|
||||||
|
@ -2169,18 +2166,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
templateInstantiation = temp;
|
templateInstantiation = temp;
|
||||||
} else
|
} else
|
||||||
templateInstantiation = createTemplateInstantiation();
|
templateInstantiation = createTemplateInstantiation();
|
||||||
try {
|
IASTDeclaration d = declaration();
|
||||||
IASTDeclaration d = declaration();
|
((ASTNode) templateInstantiation).setOffsetAndLength(firstToken
|
||||||
((ASTNode) templateInstantiation).setOffsetAndLength(firstToken
|
.getOffset(), calculateEndOffset(d)
|
||||||
.getOffset(), calculateEndOffset(d)
|
- firstToken.getOffset());
|
||||||
- firstToken.getOffset());
|
templateInstantiation.setDeclaration(d);
|
||||||
templateInstantiation.setDeclaration(d);
|
d.setParent(templateInstantiation);
|
||||||
d.setParent(templateInstantiation);
|
d
|
||||||
d
|
.setPropertyInParent(ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION);
|
||||||
.setPropertyInParent(ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION);
|
|
||||||
} finally {
|
|
||||||
--templateCount;
|
|
||||||
}
|
|
||||||
return templateInstantiation;
|
return templateInstantiation;
|
||||||
}
|
}
|
||||||
consume(IToken.tLT);
|
consume(IToken.tLT);
|
||||||
|
@ -2189,46 +2182,34 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
consume(IToken.tGT);
|
consume(IToken.tGT);
|
||||||
|
|
||||||
ICPPASTTemplateSpecialization templateSpecialization = createTemplateSpecialization();
|
ICPPASTTemplateSpecialization templateSpecialization = createTemplateSpecialization();
|
||||||
try {
|
IASTDeclaration d = declaration();
|
||||||
IASTDeclaration d = declaration();
|
((ASTNode) templateSpecialization).setOffsetAndLength(firstToken
|
||||||
((ASTNode) templateSpecialization).setOffsetAndLength(
|
.getOffset(), calculateEndOffset(d)
|
||||||
firstToken.getOffset(), calculateEndOffset(d)
|
- firstToken.getOffset());
|
||||||
- firstToken.getOffset());
|
templateSpecialization.setDeclaration(d);
|
||||||
templateSpecialization.setDeclaration(d);
|
d.setParent(templateSpecialization);
|
||||||
d.setParent(templateSpecialization);
|
d
|
||||||
d
|
.setPropertyInParent(ICPPASTTemplateSpecialization.OWNED_DECLARATION);
|
||||||
.setPropertyInParent(ICPPASTTemplateSpecialization.OWNED_DECLARATION);
|
|
||||||
} finally {
|
|
||||||
--templateCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return templateSpecialization;
|
return templateSpecialization;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List parms = templateParameterList();
|
List parms = templateParameterList();
|
||||||
consume(IToken.tGT);
|
consume(IToken.tGT);
|
||||||
|
IASTDeclaration d = declaration();
|
||||||
ICPPASTTemplateDeclaration templateDecl = createTemplateDeclaration();
|
ICPPASTTemplateDeclaration templateDecl = createTemplateDeclaration();
|
||||||
try
|
((ASTNode) templateDecl).setOffsetAndLength(firstToken.getOffset(),
|
||||||
{
|
calculateEndOffset(d) - firstToken.getOffset());
|
||||||
IASTDeclaration d = declaration();
|
templateDecl.setExported(exported);
|
||||||
((ASTNode) templateDecl).setOffsetAndLength(firstToken.getOffset(),
|
templateDecl.setDeclaration(d);
|
||||||
calculateEndOffset(d) - firstToken.getOffset());
|
d.setParent(templateDecl);
|
||||||
templateDecl.setExported(exported);
|
d.setPropertyInParent(ICPPASTTemplateDeclaration.OWNED_DECLARATION);
|
||||||
templateDecl.setDeclaration(d);
|
for (int i = 0; i < parms.size(); ++i) {
|
||||||
d.setParent(templateDecl);
|
ICPPASTTemplateParameter parm = (ICPPASTTemplateParameter) parms
|
||||||
d.setPropertyInParent(ICPPASTTemplateDeclaration.OWNED_DECLARATION);
|
.get(i);
|
||||||
for (int i = 0; i < parms.size(); ++i) {
|
templateDecl.addTemplateParamter(parm);
|
||||||
ICPPASTTemplateParameter parm = (ICPPASTTemplateParameter) parms
|
parm.setParent(templateDecl);
|
||||||
.get(i);
|
parm.setPropertyInParent(ICPPASTTemplateDeclaration.PARAMETER);
|
||||||
templateDecl.addTemplateParamter(parm);
|
|
||||||
parm.setParent(templateDecl);
|
|
||||||
parm.setPropertyInParent(ICPPASTTemplateDeclaration.PARAMETER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
--templateCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return templateDecl;
|
return templateDecl;
|
||||||
|
@ -2445,93 +2426,24 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
protected IASTDeclaration simpleDeclarationStrategyUnion()
|
protected IASTDeclaration simpleDeclarationStrategyUnion()
|
||||||
throws EndOfFileException, BacktrackException {
|
throws EndOfFileException, BacktrackException {
|
||||||
IToken simpleDeclarationMark = mark();
|
simpleDeclarationMark = mark();
|
||||||
IASTDeclaration d1 = null, d2 = null;
|
|
||||||
IToken after = null;
|
|
||||||
try {
|
try {
|
||||||
d1 = simpleDeclaration(SimpleDeclarationStrategy.TRY_FUNCTION,
|
IASTDeclaration d = simpleDeclaration(
|
||||||
false);
|
SimpleDeclarationStrategy.TRY_FUNCTION, false);
|
||||||
try {
|
throwAwayMarksForInitializerClause();
|
||||||
after = LA(1);
|
return d;
|
||||||
} catch (EndOfFileException eof) {
|
|
||||||
after = null;
|
|
||||||
}
|
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
d1 = null;
|
if (simpleDeclarationMark == null)
|
||||||
|
throwBacktrack(bt);
|
||||||
|
// did not work
|
||||||
|
backup(simpleDeclarationMark);
|
||||||
|
|
||||||
|
IASTDeclaration d = simpleDeclaration(
|
||||||
|
SimpleDeclarationStrategy.TRY_VARIABLE, false);
|
||||||
|
throwAwayMarksForInitializerClause();
|
||||||
|
return d;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (d1 != null) {
|
|
||||||
if( templateCount != 0 )
|
|
||||||
return d1;
|
|
||||||
if (d1 instanceof IASTFunctionDefinition)
|
|
||||||
return d1;
|
|
||||||
if (d1 instanceof IASTSimpleDeclaration) {
|
|
||||||
IASTSimpleDeclaration sd = (IASTSimpleDeclaration) d1;
|
|
||||||
if( sd.getDeclSpecifier() instanceof ICPPASTDeclSpecifier &&
|
|
||||||
((ICPPASTDeclSpecifier)sd.getDeclSpecifier()).isFriend() )
|
|
||||||
return d1;
|
|
||||||
if (sd.getDeclarators().length != 1)
|
|
||||||
return d1;
|
|
||||||
if (sd.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator) {
|
|
||||||
IASTStandardFunctionDeclarator fd = (IASTStandardFunctionDeclarator) sd
|
|
||||||
.getDeclarators()[0];
|
|
||||||
if (sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef)
|
|
||||||
return d1;
|
|
||||||
IASTParameterDeclaration[] parms = fd.getParameters();
|
|
||||||
for (int i = 0; i < parms.length; ++i) {
|
|
||||||
if (!(parms[i].getDeclSpecifier() instanceof IASTNamedTypeSpecifier))
|
|
||||||
return d1;
|
|
||||||
if (((ASTNode) parms[i].getDeclarator().getName())
|
|
||||||
.getLength() > 0)
|
|
||||||
return d1;
|
|
||||||
IASTDeclarator d = parms[i].getDeclarator();
|
|
||||||
while (d.getNestedDeclarator() != null)
|
|
||||||
d = d.getNestedDeclarator();
|
|
||||||
if (((ASTNode) d.getName()).getLength() > 0)
|
|
||||||
return d1;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
return d1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// did not work
|
|
||||||
backup(simpleDeclarationMark);
|
|
||||||
|
|
||||||
try {
|
|
||||||
d2 = simpleDeclaration(SimpleDeclarationStrategy.TRY_VARIABLE,
|
|
||||||
false);
|
|
||||||
if (after != null && after != LA(1)) {
|
|
||||||
backup(after);
|
|
||||||
return d1;
|
|
||||||
}
|
|
||||||
} catch (BacktrackException be) {
|
|
||||||
d2 = null;
|
|
||||||
if (d1 == null)
|
|
||||||
throwBacktrack(be);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d2 == null && d1 != null) {
|
|
||||||
backup(after);
|
|
||||||
return d1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d1 == null && d2 != null)
|
|
||||||
return d2;
|
|
||||||
|
|
||||||
IASTAmbiguousDeclaration result = createAmbiguousDeclaration();
|
|
||||||
((CPPASTNode) result).setOffsetAndLength((ASTNode) d1);
|
|
||||||
result.addDeclaration(d1);
|
|
||||||
d1.setParent(result);
|
|
||||||
d1.setPropertyInParent(IASTAmbiguousDeclaration.SUBDECLARATION);
|
|
||||||
result.addDeclaration(d2);
|
|
||||||
d2.setParent(result);
|
|
||||||
d2.setPropertyInParent(IASTAmbiguousDeclaration.SUBDECLARATION);
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IASTAmbiguousDeclaration createAmbiguousDeclaration() {
|
|
||||||
return new CPPASTAmbiguousDeclaration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3563,6 +3475,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
if (LT(1) == IToken.tASSIGN) {
|
if (LT(1) == IToken.tASSIGN) {
|
||||||
consume(IToken.tASSIGN);
|
consume(IToken.tASSIGN);
|
||||||
|
throwAwayMarksForInitializerClause();
|
||||||
try {
|
try {
|
||||||
return initializerClause();
|
return initializerClause();
|
||||||
} catch (EndOfFileException eof) {
|
} catch (EndOfFileException eof) {
|
||||||
|
@ -5083,7 +4996,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTNode condition = null;
|
IASTNode condition = null;
|
||||||
try {
|
try {
|
||||||
condition = cppStyleCondition(); // TODO should be while
|
condition = cppStyleCondition(); // TODO should be while
|
||||||
// condition
|
// condition
|
||||||
if (LT(1) == IToken.tEOC) {
|
if (LT(1) == IToken.tEOC) {
|
||||||
// Completing in the condition
|
// Completing in the condition
|
||||||
ICPPASTIfStatement new_if = createIfStatement();
|
ICPPASTIfStatement new_if = createIfStatement();
|
||||||
|
@ -5127,15 +5040,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
ICPPASTIfStatement new_if_statement = createIfStatement();
|
ICPPASTIfStatement new_if_statement = createIfStatement();
|
||||||
((ASTNode) new_if_statement).setOffset(so);
|
((ASTNode) new_if_statement).setOffset(so);
|
||||||
if (condition != null && condition instanceof IASTExpression) // shouldn't
|
if (condition != null && condition instanceof IASTExpression) // shouldn't
|
||||||
// be
|
// be
|
||||||
// possible
|
// possible
|
||||||
// but
|
// but
|
||||||
// failure
|
// failure
|
||||||
// in
|
// in
|
||||||
// condition()
|
// condition()
|
||||||
// makes
|
// makes
|
||||||
// it
|
// it
|
||||||
// so
|
// so
|
||||||
{
|
{
|
||||||
new_if_statement
|
new_if_statement
|
||||||
.setConditionExpression((IASTExpression) condition);
|
.setConditionExpression((IASTExpression) condition);
|
||||||
|
|
Loading…
Add table
Reference in a new issue