[cfe-dev] Adding a FieldDecl
Douglas Gregor
dgregor at apple.com
Mon Feb 14 10:53:32 PST 2011
On Feb 13, 2011, at 5:35 AM, Dimitrij Kotrev wrote:
> Hello,
>
> i want to add a FieldDecl to a class/struct. For example an integer variable.
> So far my code looks like this:
>
> clang::CXXRecordDecl* d;
> ...
> clang::ASTContext& astContext = d->getASTContext();
> clang::FieldDecl* fd = clang::FieldDecl::Create(
> astContext,
> d,
> clang::SourceLocation(),
> 0 /*identifierinfo*/,
> astContext.IntTy,
> 0 /*typesourceinfo*/,
> 0 /*bitwidth*/,
> 0 /*mutable*/
> );
>
> But i'm missing some pieces. Where do i get the IdentifierInfo for my
> new field?
Use the get() function of the ASTContext's identifier table.
> The field
> should be called 'foo' for example. Where do i get the TypeSourceInfo?
You can fake a TypeSourceInfo using ASTContext's getTrivialTypeSourceInfo()
> Is it enough
> to specify the SourceLocation like this? Am i missing anything else?
It's usually best to have *some* SourceLocation information. You could re-use the source location of the class/struct.
- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110214/99217e96/attachment.html>
More information about the cfe-dev
mailing list