1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 18:35: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:
John Camelon 2005-05-20 02:47:51 +00:00
parent bc48508cee
commit 5af5a134fd
3 changed files with 71 additions and 170 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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,7 +2166,6 @@ 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)
@ -2178,9 +2174,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
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,29 +2182,22 @@ 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( ((ASTNode) templateSpecialization).setOffsetAndLength(firstToken
firstToken.getOffset(), calculateEndOffset(d) .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);
ICPPASTTemplateDeclaration templateDecl = createTemplateDeclaration();
try
{
IASTDeclaration d = declaration(); IASTDeclaration d = declaration();
ICPPASTTemplateDeclaration templateDecl = createTemplateDeclaration();
((ASTNode) templateDecl).setOffsetAndLength(firstToken.getOffset(), ((ASTNode) templateDecl).setOffsetAndLength(firstToken.getOffset(),
calculateEndOffset(d) - firstToken.getOffset()); calculateEndOffset(d) - firstToken.getOffset());
templateDecl.setExported(exported); templateDecl.setExported(exported);
@ -2225,11 +2211,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
parm.setParent(templateDecl); parm.setParent(templateDecl);
parm.setPropertyInParent(ICPPASTTemplateDeclaration.PARAMETER); parm.setPropertyInParent(ICPPASTTemplateDeclaration.PARAMETER);
} }
}
finally
{
--templateCount;
}
return templateDecl; return templateDecl;
} catch (BacktrackException bt) { } catch (BacktrackException bt) {
@ -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);
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 // did not work
backup(simpleDeclarationMark); backup(simpleDeclarationMark);
try { IASTDeclaration d = simpleDeclaration(
d2 = simpleDeclaration(SimpleDeclarationStrategy.TRY_VARIABLE, SimpleDeclarationStrategy.TRY_VARIABLE, false);
false); throwAwayMarksForInitializerClause();
if (after != null && after != LA(1)) { return d;
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) {