Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] CDT DOM Usage


On Wed, 2005-09-28 at 14:54 -0400, Nick Allen wrote:
> On Wed, 2005-09-28 at 14:39 -0400, Nick Allen wrote: 
> > BTW, for now I am simply trying to parse a file and determine the C
> ++ 
> > classes which have been declared in that file.
> 
> At this point, I have found that I can do the following.  Any
> criticisms 
> on the following code would be appreciated.  
> 
> IFile file = ... 
> IASTTranslationUnit ast =
> CDOM.getInstance().getTranslationUnit(file); 
> CPPNameCollector col = new CPPNameCollector(); 
> ast.accept(col); 
>                  
> Iterator i = col.nameList.iterator(); 
> while (i.hasNext()) { 
>         IASTName n = (IASTName) i.next(); 
>         IBinding binding = n.resolveBinding(); 
>         
>         if(binding instanceof CPPClassType) { 
>                 // do something with the class 
>         } 
> }
> 

Looks great. Names can be declarations or references. You might want to
make sure you don't process the references, or the forward declarations.
I'm not sure, but I think a class definition would mark the name as
isDefinition() == true. Also, you should always use the public
interfaces provided, e.g. ICPPClassType, so that we can change
non-public methods on you :)

> Small code examples like this would certainly help those unfamaliar
> with 
> the new CDT DOM become familiar.

You are correct. We should look seriously at getting a wiki setup for
the CDT so that people like yourself can easily share tips like this. I
know eclipse.org is looking into something, I'll check with them.

> Thanks 
> Nick
> 
> 
> Nick Allen <nwa@xxxxxxxxxxxxxxxx>
> 
> _______________________________________________ 
> cdt-dev mailing list 
> cdt-dev@xxxxxxxxxxx 
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> 



Back to the top