<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 13, 2011, at 5:35 AM, Dimitrij Kotrev wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hello,<br><br>i want to add a FieldDecl to a class/struct. For example an integer variable.<br>So far my code looks like this:<br><br>clang::CXXRecordDecl* d;<br>...<br>clang::ASTContext& astContext = d->getASTContext();<br>clang::FieldDecl* fd = clang::FieldDecl::Create(<br>    astContext,<br>    d,<br>    clang::SourceLocation(),<br>    0 /*identifierinfo*/,<br>    astContext.IntTy,<br>    0 /*typesourceinfo*/,<br>    0 /*bitwidth*/,<br>    0 /*mutable*/<br>);<br><br>But i'm missing some pieces. Where do i get the IdentifierInfo for my<br>new field? </div></blockquote><div><br></div><div>Use the get() function of the ASTContext's identifier table.</div><div><br></div><blockquote type="cite"><div>The field<br>should be called 'foo' for example. Where do i get the TypeSourceInfo?<br></div></blockquote><div><br></div>You can fake a TypeSourceInfo using ASTContext's getTrivialTypeSourceInfo()</div><div><br><blockquote type="cite"><div>Is it enough<br>to specify the SourceLocation like this? Am i missing anything else?<br></div></blockquote></div><div><br></div>It's usually best to have *some* SourceLocation information. You could re-use the source location of the class/struct.<div><br><div><div><span class="Apple-tab-span" style="white-space:pre">      </span>- Doug</div></div></div></body></html>