Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-dev] How to Get The Scope of a Node

A correction:
IBinding.getScope() returns the scope in which the binding is declared
(not the scope that it represents).
For references CPPVisitor.getContainingScope(name) will find the scope
in which the reference is made, whereas name.resolveBinding().getScope()
returns the scope in which the referenced entity is declared. There are
also subtle differences for declarations and definitions.

To find references for a variable you best use:
IASTTranslationUnit.getReferences(IBinding)

Markus.



> -----Original Message-----
> From: cdt-dev-bounces@xxxxxxxxxxx 
> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of student08
> Sent: Friday, May 16, 2008 12:04 AM
> To: cdt-dev@xxxxxxxxxxx
> Subject: Re: [cdt-dev] How to Get The Scope of a Node
> Importance: Low
> 
> 
> Hi thanks for the reply. I want to be able to find all 
> references to a particular variable from within its scope, 
> not including its actual definition, is there a fairly 
> straightforward way of doing that?
> 
> 
> For IASTName nodes: name.resolveBinding().getScope().
> There's also CPPVisitor.getContainingScope().
> I'm not entirely sure what the difference is (because these 
> methods aren't documented). I think the first one returns the 
> scope that the name represents like if its a class name, and 
> the second one returns the scope that contains the particular 
> use of the name. Someone please correct me.
> 
> For AST nodes that represent lexical scopes, like 
> IASTFunctionDefinition and IASTCompoundStatement just use 
> getScope() on the node.
> 
> 
> Mike Kucera
> Software Developer
> IBM CDT Team, Toronto
> mkucera@xxxxxxxxxx
> 
> 
>                                                               
>          
>              student08                                        
>          
>              <pingu219@gmail.c                                
>          
>              om>                                              
>           To
>              Sent by:                  cdt-dev@xxxxxxxxxxx    
>          
>              cdt-dev-bounces@e                                
>           cc
>              clipse.org                                       
>          
>                                                               
>      Subject
>                                        [cdt-dev] How to Get 
> The Scope of a
>              05/15/2008 03:52          Node                   
>          
>              PM                                               
>          
>                                                               
>          
>                                                               
>          
>              Please respond to                                
>          
>                "CDT General                                   
>          
>              developers list."                                
>          
>              <cdt-dev@eclipse.                                
>          
>                    org>                                       
>          
>                                                               
>          
>                                                               
>          
> 
> 
> 
> 
> 
> Hi does anyone know how to get the scope for a particular node?
> --
> View this message in context:
> http://www.nabble.com/How-to-Get-The-Scope-of-a-Node-tp1726103
> 8p17261038.html
> 
> Sent from the Eclipse CDT - Development mailing list archive 
> at Nabble.com.
> 
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> 
>  
>  
>  
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> 
> 
> 
> --
> View this message in context: 
> http://www.nabble.com/How-to-Get-The-Scope-of-a-Node-tp1726103
> 8p17263576.html
> Sent from the Eclipse CDT - Development mailing list archive 
> at Nabble.com.
> 
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> 


Back to the top