Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] pulling in extern definitions with CDT parser

I am currently working on developing a simple source-to-source
transformation tool using CDT.  I've managed to pull the parser
component out of CDT as a standalone tool (so that we don't have to
rely on Eclipse).  Namely, whereas before the AST had to be retrieved
in the following way:

ITranslationUnit tu = (ITranslationUnit)selected;
IASTTranslationUnit ast = tu.getAST();

Now, the AST is retrieved through a standalone parser, whose getAST()
is a slightly modified, almost identical version, of

StandaloneCParser parser = new StandaloneCParser("c:\\foo.c", tu);
IASTTranslationUnit astTu = parser.getAST();

The parser is able to resolve bindings to definitions in header files
(e.g. foo.h), but isn't able to do so for "extern" declarations, whose
actual definitions are located in other .c files (e.g. bar.c).  For
example, if foo.c calls a method called "barMethod()" that is declared
as "extern void barMethod();" in foo.h and actually defined in bar.c,
calling IASTName.resolveBinding() on "barMethod()" name returns a
CFunction whose CFunction.getDefinition() returns null.

Does CDT provide a mechanism for linking, so that these external
definitions can be pulled in automatically?  If not, what do you
recommend for connecting these various files together?  I know CDT is
more of an IDE tool than a traditional parser/compiler, but I've found
it very useful and I'd like to keep using it if possible.

Peter Kim
Ph.D. Student
Automated Software Design Group
Department of Computer Sciences
The University of Texas at Austin, USA
Phone: +1-512-461-9381
Office: ACES 5.246

Back to the top