mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
refactor CVisitor.getContainingScope to be less recursive
This commit is contained in:
parent
748be7f1ca
commit
f617b88f25
1 changed files with 36 additions and 59 deletions
|
@ -937,46 +937,44 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IScope getContainingScope( IASTNode node ){
|
public static IScope getContainingScope( IASTNode node ){
|
||||||
if( node instanceof IASTDeclaration )
|
if( node == null )
|
||||||
return getContainingScope( (IASTDeclaration) node );
|
return null;
|
||||||
else if( node instanceof IASTStatement )
|
while( node != null ){
|
||||||
return getContainingScope( (IASTStatement) node );
|
if( node instanceof IASTDeclaration ){
|
||||||
else if( node instanceof IASTDeclSpecifier )
|
IASTNode parent = node.getParent();
|
||||||
return getContainingScope( (IASTDeclSpecifier) node );
|
if( parent instanceof IASTTranslationUnit ){
|
||||||
else if( node instanceof IASTParameterDeclaration )
|
return ((IASTTranslationUnit)parent).getScope();
|
||||||
return getContainingScope( (IASTParameterDeclaration) node );
|
} else if( parent instanceof IASTDeclarationStatement ){
|
||||||
else if( node instanceof IASTEnumerator ){
|
return getContainingScope( (IASTStatement) parent );
|
||||||
//put the enumerators in the same scope as the enumeration
|
} else if( parent instanceof IASTForStatement ){
|
||||||
return getContainingScope( (IASTEnumerationSpecifier) node.getParent() );
|
return ((IASTForStatement)parent).getScope();
|
||||||
}
|
} else if( parent instanceof IASTCompositeTypeSpecifier ){
|
||||||
|
return ((IASTCompositeTypeSpecifier)parent).getScope();
|
||||||
return null;
|
} else if( parent instanceof ICASTKnRFunctionDeclarator ){
|
||||||
}
|
parent = ((IASTDeclarator)parent).getParent();
|
||||||
/**
|
if ( parent instanceof IASTFunctionDefinition ) {
|
||||||
* @param declaration
|
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent).getBody()).getScope();
|
||||||
* @return
|
}
|
||||||
*/
|
|
||||||
public static IScope getContainingScope(IASTDeclaration declaration) {
|
|
||||||
IASTNode parent = declaration.getParent();
|
|
||||||
if( parent instanceof IASTTranslationUnit ){
|
|
||||||
return ((IASTTranslationUnit)parent).getScope();
|
|
||||||
} else if( parent instanceof IASTDeclarationStatement ){
|
|
||||||
return getContainingScope( (IASTStatement) parent );
|
|
||||||
} else if( parent instanceof IASTForStatement ){
|
|
||||||
return ((IASTForStatement)parent).getScope();
|
|
||||||
} 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;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IScope getContainingScope( IASTStatement statement ){
|
public static IScope getContainingScope( IASTStatement statement ){
|
||||||
|
@ -1011,27 +1009,6 @@ public class CVisitor {
|
||||||
return scope;
|
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 ){
|
private static IASTNode getContainingBlockItem( IASTNode node ){
|
||||||
IASTNode parent = node.getParent();
|
IASTNode parent = node.getParent();
|
||||||
if( parent instanceof IASTDeclaration ){
|
if( parent instanceof IASTDeclaration ){
|
||||||
|
|
Loading…
Add table
Reference in a new issue