1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Removed AbstactGNUSourceCodeParser#mostRelevantScopeNode

This commit is contained in:
John Camelon 2005-04-15 15:22:06 +00:00
parent 21c09e5d0f
commit a27d2a6da5
3 changed files with 4908 additions and 4925 deletions

View file

@ -484,7 +484,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
IASTCompoundStatement result = createCompoundStatement();
((ASTNode) result).setOffset(startingOffset);
result.setParent(mostRelevantScopeNode);
result.setPropertyInParent(IASTFunctionDefinition.FUNCTION_BODY);
while (LT(1) != IToken.tRBRACE && LT(1) != IToken.tCOMPLETION && LT(1) != IToken.tEOC) {
int checkToken = LA(1).hashCode();
@ -2087,6 +2086,5 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throwBacktrack(token.getOffset(), token.getLength());
}
protected IASTNode mostRelevantScopeNode;
}

View file

@ -559,7 +559,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
translationUnit.setLocationResolver(scanner.getLocationResolver());
mostRelevantScopeNode = translationUnit;
int lastBacktrack = -1;
while (true) {

View file

@ -1447,15 +1447,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IToken m = mark();
try {
boolean amb = false;
if ( LT(1) == IToken.tIDENTIFIER )
if (LT(1) == IToken.tIDENTIFIER)
amb = true;
typeId = typeId(false, false);
if( amb && typeId.getDeclSpecifier() instanceof IASTNamedTypeSpecifier )
{
if( ! queryIsTypeName( ((IASTNamedTypeSpecifier) typeId.getDeclSpecifier()).getName() ) )
{
backup( m );
throwBacktrack( ((CPPASTNode)typeId).getOffset(), ((CPPASTNode)typeId).getLength() );
if (amb
&& typeId.getDeclSpecifier() instanceof IASTNamedTypeSpecifier) {
if (!queryIsTypeName(((IASTNamedTypeSpecifier) typeId
.getDeclSpecifier()).getName())) {
backup(m);
throwBacktrack(((CPPASTNode) typeId).getOffset(),
((CPPASTNode) typeId).getLength());
}
}
} catch (BacktrackException b) {
@ -2470,11 +2471,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
name.setParent(namespaceDefinition);
name.setPropertyInParent(ICPPASTNamespaceDefinition.NAMESPACE_NAME);
IASTNode n = mostRelevantScopeNode;
mostRelevantScopeNode = namespaceDefinition;
namespaceDefinition.setParent(n);
try {
namespaceDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
int checkToken = LA(1).hashCode();
switch (LT(1)) {
@ -2492,8 +2488,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTProblemDeclaration pd = createProblemDeclaration();
p.setParent(pd);
pd.setProblem(p);
((CPPASTNode) pd)
.setOffsetAndLength((CPPASTNode) p);
((CPPASTNode) pd).setOffsetAndLength((CPPASTNode) p);
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
namespaceDefinition.addDeclaration(pd);
pd.setParent(namespaceDefinition);
@ -2507,9 +2502,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (checkToken == LA(1).hashCode())
failParseWithErrorHandling();
}
} finally {
mostRelevantScopeNode = n;
}
// consume the }
int end = consume(IToken.tRBRACE).getEndOffset();
((CPPASTNode) namespaceDefinition).setLength(end
@ -3507,7 +3500,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
throws EndOfFileException, BacktrackException {
IASTDeclarator d = declarator(strategy, false, false);
IASTInitializer initializer = optionalCPPInitializer( d );
IASTInitializer initializer = optionalCPPInitializer(d);
if (initializer != null) {
d.setInitializer(initializer);
initializer.setParent(d);
@ -3519,7 +3512,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return d;
}
protected IASTInitializer optionalCPPInitializer( IASTDeclarator d )
protected IASTInitializer optionalCPPInitializer(IASTDeclarator d)
throws EndOfFileException, BacktrackException {
// handle initializer
@ -3533,9 +3526,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
throw eof;
}
} else if (LT(1) == IToken.tLPAREN) {
if( d instanceof IASTFunctionDeclarator && d.getNestedDeclarator() == null ){
//constructor initializer doesn't make sense for a function declarator,
//we must have an object to initialize, a function doesn't work.
if (d instanceof IASTFunctionDeclarator
&& d.getNestedDeclarator() == null) {
// constructor initializer doesn't make sense for a function
// declarator,
// we must have an object to initialize, a function doesn't
// work.
return null;
}
// initializer in constructor
@ -4100,11 +4096,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (LT(1) == IToken.tLBRACE) {
consume(IToken.tLBRACE);
IASTNode n = mostRelevantScopeNode;
mostRelevantScopeNode = astClassSpecifier;
astClassSpecifier.setParent(n);
try {
memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) {
int checkToken = LA(1).hashCode();
switch (LT(1)) {
@ -4152,9 +4144,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
failParseWithErrorHandling();
}
}
} finally {
mostRelevantScopeNode = n;
}
// consume the }
int l = consume(IToken.tRBRACE).getEndOffset();
((ASTNode) astClassSpecifier).setLength(l - classKey.getOffset());
@ -4438,7 +4428,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
translationUnit.setLocationResolver(scanner.getLocationResolver());
mostRelevantScopeNode = translationUnit;
while (true) {
try {
if (LT(1) == IToken.tEOC)
@ -5024,9 +5013,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
}
static class HeuristicTypeDetector extends CPPASTVisitor
{
static class HeuristicTypeDetector extends CPPASTVisitor {
IASTName searchName;
boolean found = false;
{
shouldVisitDeclarations = true;
@ -5037,24 +5026,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
public int visit(IASTDeclaration declaration) {
if( declaration instanceof IASTSimpleDeclaration )
{
if (declaration instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration sd = (IASTSimpleDeclaration) declaration;
if( sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef )
{
IASTDeclarator [] declarators = sd.getDeclarators();
for( int i = 0; i < declarators.length; ++i )
if( CharArrayUtils.equals( declarators[i].getName().toCharArray(), searchName.toCharArray() ) )
{
if (sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) {
IASTDeclarator[] declarators = sd.getDeclarators();
for (int i = 0; i < declarators.length; ++i)
if (CharArrayUtils.equals(declarators[i].getName()
.toCharArray(), searchName.toCharArray())) {
found = true;
return PROCESS_ABORT;
}
}
else if( sd.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier )
{
IASTCompositeTypeSpecifier comp = (IASTCompositeTypeSpecifier) sd.getDeclSpecifier();
if( CharArrayUtils.equals( comp.getName().toCharArray(), searchName.toCharArray() ) )
{
} else if (sd.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) {
IASTCompositeTypeSpecifier comp = (IASTCompositeTypeSpecifier) sd
.getDeclSpecifier();
if (CharArrayUtils.equals(comp.getName().toCharArray(),
searchName.toCharArray())) {
found = true;
return PROCESS_ABORT;
}
@ -5065,8 +5051,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
protected boolean queryIsTypeName(IASTName name) {
HeuristicTypeDetector visitor = new HeuristicTypeDetector( name );
translationUnit.accept( visitor );
HeuristicTypeDetector visitor = new HeuristicTypeDetector(name);
translationUnit.accept(visitor);
return visitor.found;
}