[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] CDT DOM Usage
|
Andrew beat me to the punch. Thanks Andrew!
D
On Wed, 2005-09-28 at 15:16 -0400, Andrew Niefer wrote:
>
> A couple of comments:
> 1. Use the interfaces instead of the implementing classes, ie
> ICPPClassType instead of CPPClassType. This becomes a bigger issue
> when dealing with code that has templates.
> 2. You can check IASTName.isDeclaration(), isDefinition, isReference,
> to determine the relationship between the IASTName and the resulting
> binding. There is one binding for a class A, and all declarations and
> references to A will return the same binding.
> 3. Realize you are parsing the entire translation unit (including
> headers) and not just your file. IASTNode (which IASTName extends)
> has methods for getting the the containg file or location of the
> IASTName.
>
>
> -Andrew
>
> cdt-dev-bounces@xxxxxxxxxxx wrote on 09/28/2005 02:54:52 PM:
>
> > 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
> > }
> > }
> >
> > Small code examples like this would certainly help those unfamaliar
> with
> > the new CDT DOM become familiar.
> >
> > Thanks
> > Nick
> >
> >
> > Nick Allen <nwa@xxxxxxxxxxxxxxxx>
> >
> > _______________________________________________
> > cdt-dev mailing list
> > cdt-dev@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/cdt-dev