<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
color:black;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;
color:black;}
code
{mso-style-priority:99;
font-family:"Courier New";}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";}
span.EmailStyle21
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle22
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.EmailStyle24
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Hi<br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">It worked as a charm! Tnx<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I use it with a plugin:<o:p></o:p></span></p>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><span style="font-family:"Calibri",sans-serif;color:#1F497D"><br></span><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">class EditAPIsConsumer : public ASTConsumer {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">public:<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> EditAPIsConsumer(CompilerInstance &ci) : m_ci(ci) {}<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> bool HandleTopLevelDecl(DeclGroupRef DG) override {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> static ASTContext& ctx = m_ci.getASTContext();<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> if ((*I)->getKind() == Decl::Function) {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> FunctionDecl* f = static_cast<FunctionDecl*>(*I);<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> DeclarationName origName(f->getDeclName());<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> if (origName.getAsString() != "main") {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> static IdentifierInfo& venusNamespaceIdInfo(ctx.Idents.get(StringRef("bar")));<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> NamespaceDecl *newNamespace = NamespaceDecl::Create(ctx, ctx.getTranslationUnitDecl(), false, f->getLocStart(), f->getLocStart(), &venusNamespaceIdInfo, nullptr);<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> f->setDeclContext(newNamespace);<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> f->setLexicalDeclContext(newNamespace);<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> }<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> }<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> }<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> return true;<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> }<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">private:<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> CompilerInstance& m_ci;<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">};<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">class EditAPIsAction : public PluginASTAction {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">protected:<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) override {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> return llvm::make_unique<EditAPIsConsumer>(CI);<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> }<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> virtual ActionType getActionType() override { return AddBeforeMainAction; }<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> bool ParseArgs(const CompilerInstance &CI, const std::vector<std::string> &args) override {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> return true;<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> }<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">};<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">static FrontendPluginRegistry::Add<EditAPIsAction><o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">__reg("dump-apis", "creates declarative APIs");<o:p></o:p></span></code></pre>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">And I compiled foo() with it:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">some_code.h:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">int foo();<o:p></o:p></span></code></pre>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">some_code.cpp:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">int foo() {return 42;}<o:p></o:p></span></code></pre>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">And now foo()’s symbol is:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">[oriz@ llvm-plugin git:master]$ nm some_code.o<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">0000000000000000 T _ZN3bar3fooEv<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Now, I get another problem – I can’t the modified foo() in a test-<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I got this test:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">#include "some_code.h"<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">#include <iostream><o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">int main(int argc, char* argv[]) {<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> std::cout << bar::foo() << std::endl;<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"><o:p> </o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> return 0;<o:p></o:p></span></code></pre>
<pre style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">}<o:p></o:p></span></code></pre>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">And I build it with the same plugin above<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I got this error:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">./test/main.cpp:23:15: error: use of undeclared identifier 'bar'<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> std::cout << bar::foo() << std::endl;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I debugged it and it seems that the error is invoked before the fronted executes the action<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">What can I do about it?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="color:windowtext">From:</span></b><span style="color:windowtext"> Aleksei Sidorin [mailto:a.sidorin@samsung.com]
<br>
<b>Sent:</b> Monday, January 09, 2017 6:55 PM<br>
<b>To:</b> Ori Zaig <oriz@mellanox.com>; cfe-dev@lists.llvm.org<br>
<b>Cc:</b> Eran Jakoby <eranj@mellanox.com><br>
<b>Subject:</b> Re: [cfe-dev] Adding nodes to Clang's AST<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hello Ori,<br>
<br>
You can create different kinds of nodes directly. For example, to create a new namespace, you will need to use code like this:<br>
<br>
IdentifierInfo *IdInfo = Context.Idents.get("bar");<br>
NamespaceDecl *NewNS = NamespaceDecl::Create(Context, Context.getTranslationUnitDecl(), false, StartLoc, IdLoc, IdInfo, OldDecl);<br>
<br>
You can take a look at constructors of different Decl kinds (and static ::Create() methods) in Decl.h and DeclCXX.h (and other Decl*.h) for more information.<br>
To move a function to this namespace, you will need to set a new DeclContext for it:<br>
<br>
FD->setDeclContext(NewNS);<br>
FD->setLexicalDeclContext(NewNS);<br>
<br>
<br>
<br>
09.01.2017 18:59, Ori Zaig via cfe-dev пишет:<span style="font-size:12.0pt"><o:p></o:p></span></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;background:white">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">I need to insert new nodes to AST. For instance, adding a namespace to a function: Turning this -</span><o:p></o:p></p>
<pre style="background:#EFF0F1;max-height: 600px;word-wrap: normal;font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;widows: 2;-webkit-text-stroke-width: 0px;overflow:auto;word-spacing:0px"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">void foo();</span></code><o:p></o:p></pre>
<pre style="background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> </span></code><o:p></o:p></pre>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;background:white;font-variant-ligatures:
normal;font-variant-caps: normal;orphans: 2;widows:
2;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">into this -</span><o:p></o:p></p>
<pre style="background:#EFF0F1;max-height: 600px;word-wrap: normal;font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;widows: 2;-webkit-text-stroke-width: 0px;overflow:auto;word-spacing:0px"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">namespace bar {</span></code><o:p></o:p></pre>
<pre style="background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1"> void foo();</span></code><o:p></o:p></pre>
<pre style="background:#EFF0F1"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in;background:#EFF0F1">}</span></code><o:p></o:p></pre>
<p style="margin:0in;margin-bottom:.0001pt;background:white;font-variant-ligatures:
normal;font-variant-caps: normal;orphans: 2;widows:
2;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729"> </span><o:p></o:p></p>
<p style="margin:0in;margin-bottom:.0001pt;background:white"><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">I want to edit the AST directly - I prefer not using source-to-source compilation</span><o:p></o:p></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;background:white;font-variant-ligatures:
normal;font-variant-caps: normal;orphans: 2;widows:
2;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#242729">Tnx</span><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br>
<br>
<br>
<o:p></o:p></span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>cfe-dev mailing list<o:p></o:p></pre>
<pre><a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><o:p></o:p></pre>
<pre><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><o:p></o:p></pre>
</blockquote>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><o:p> </o:p></span></p>
<p><o:p> </o:p></p>
<pre>-- <o:p></o:p></pre>
<pre>Best regards,<o:p></o:p></pre>
<pre>Aleksei Sidorin<o:p></o:p></pre>
<pre>Software Engineer, <o:p></o:p></pre>
<pre>IMSWL-IMCG, SRR, Samsung Electronics<o:p></o:p></pre>
</div>
</body>
</html>