1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

refactor CVisitor.getContainingScope to be less recursive

This commit is contained in:
Andrew Niefer 2005-02-17 16:36:24 +00:00
parent 748be7f1ca
commit f617b88f25

View file

@ -937,27 +937,11 @@ public class CVisitor {
}
public static IScope getContainingScope( IASTNode node ){
if( node instanceof IASTDeclaration )
return getContainingScope( (IASTDeclaration) node );
else if( node instanceof IASTStatement )
return getContainingScope( (IASTStatement) node );
else if( node instanceof IASTDeclSpecifier )
return getContainingScope( (IASTDeclSpecifier) node );
else if( node instanceof IASTParameterDeclaration )
return getContainingScope( (IASTParameterDeclaration) node );
else if( node instanceof IASTEnumerator ){
//put the enumerators in the same scope as the enumeration
return getContainingScope( (IASTEnumerationSpecifier) node.getParent() );
}
if( node == null )
return null;
}
/**
* @param declaration
* @return
*/
public static IScope getContainingScope(IASTDeclaration declaration) {
IASTNode parent = declaration.getParent();
while( node != null ){
if( node instanceof IASTDeclaration ){
IASTNode parent = node.getParent();
if( parent instanceof IASTTranslationUnit ){
return ((IASTTranslationUnit)parent).getScope();
} else if( parent instanceof IASTDeclarationStatement ){
@ -967,15 +951,29 @@ public class CVisitor {
} else if( parent instanceof IASTCompositeTypeSpecifier ){
return ((IASTCompositeTypeSpecifier)parent).getScope();
} else if( parent instanceof ICASTKnRFunctionDeclarator ){
parent = declaration.getParent();
if( parent instanceof ICASTKnRFunctionDeclarator ){
parent = ((IASTDeclarator)parent).getParent();
if ( parent instanceof IASTFunctionDefinition ) {
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
}
}
} else if( node instanceof IASTStatement )
return getContainingScope( (IASTStatement) node );
else if( node instanceof IASTParameterDeclaration ){
IASTNode parent = node.getParent();
if( parent instanceof IASTStandardFunctionDeclarator ){
parent = ((IASTDeclarator)parent).getParent();
if ( parent instanceof IASTFunctionDefinition ) {
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
}
}
}
else if( node instanceof IASTEnumerator ){
//put the enumerators in the same scope as the enumeration
node = node.getParent();
}
node = node.getParent();
}
return null;
}
@ -1011,27 +1009,6 @@ public class CVisitor {
return scope;
}
public static IScope getContainingScope( IASTDeclSpecifier compTypeSpec ){
IASTNode parent = compTypeSpec.getParent();
return getContainingScope( parent );
}
/**
* @param parameterDeclaration
* @return
*/
public static IScope getContainingScope(IASTParameterDeclaration parameterDeclaration) {
IASTNode parent = parameterDeclaration.getParent();
if( parent instanceof IASTStandardFunctionDeclarator ){
parent = ((IASTDeclarator)parent).getParent();
if ( parent instanceof IASTFunctionDefinition ) {
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
}
}
return null;
}
private static IASTNode getContainingBlockItem( IASTNode node ){
IASTNode parent = node.getParent();
if( parent instanceof IASTDeclaration ){