Skip to main content

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

To find the references of a binding that is stored in the index, it
suffices to search the index: IIndex.findNames(...). You will also find
references made throug a macro expansion.  

Local variables are not stored in the index, so you need to search the
ast:
IASTTranslationUnit.getReferences(..)

In case you want to find potential 'references' in comments or in
inactive code (#ifdef ...) you need to perform a text search as this is
done by the rename refactoring. 

Markus.

> -----Original Message-----
> From: pingu219@xxxxxxxxx [mailto:pingu219@xxxxxxxxx] 
> Sent: Friday, May 16, 2008 11:20 AM
> To: Schorn, Markus
> Subject: RE: How to Get The Scope of a Node
> 
> So I'm guessing in order to ensure I have all possible 
> project references to a particular binding, I should search 
> the project index first and then perform a more local search 
> via IASTTranslationUnit.getReferences(IBinding) within the 
> translation unit itself?
> 
> 
> Schorn, Markus wrote:
> > 
> > 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
> >> 
> > _______________________________________________
> > cdt-dev mailing list
> > cdt-dev@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/cdt-dev
> > 
> > 
> Quoted from: 
> http://www.nabble.com/How-to-Get-The-Scope-of-a-Node-tp1726103
> 8p17269037.html
> 
> 


Back to the top