<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2017-02-07 9:41 GMT+07:00 David Fontaine <span dir="ltr"><<a href="mailto:dfontaine@nvidia.com" target="_blank">dfontaine@nvidia.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:calibri,arial,helvetica,sans-serif">
<p></p>
<p style="font-family:calibri,arial,helvetica,sans-serif;font-size:16px"><span style="color:rgb(33,33,33)">"The DeclContext is a declaration that is a container for other declarations. All non-leaf nodes of AST
 inherit it. If a contained declaration itself can contain other declarations (nested class, method of a class etc), it will be a nested DeclContext."</span><br></p><span class="gmail-">
<p style="font-family:calibri,arial,helvetica,sans-serif;font-size:16px"><span style="color:rgb(33,33,33);background-color:rgb(255,255,255)"><br>
</span></p>
</span><p style="font-family:calibri,arial,helvetica,sans-serif;font-size:16px"><span style="color:rgb(33,33,33);background-color:rgb(255,255,255)">Based on this, it seems that VarDecl and FieldDecl should also inherit DeclContext, because a function
 pointer declaration, which may contain named parameters, would be one of those two.  Any opinion on this?</span></p></div></blockquote><div>Nor VarDecl neither FieldDecl contain other declarations, so making them DeclContext is not obvious. DeclContext is used in many places including name lookup and such drastic semantic change can require redesign of other compiler components. And what about such case:</div><div><br></div><div>int (* (*abc)(long x))(int x);<br></div><div><br></div><div>Two DeclContexts would be needed here.</div><div><br></div><div>I would propose you another way, which probably is less invasive. The parameter names are not attributes of VarDecl, it looks more natural to obtained from corresponding function type, which can be obtained:</div><div><br></div><div>VarDecl->getType()->getAs<PointerType>()->getPointeeType()->getAs<FunctionProtoType>()</div><div><br></div><div>If FunctionProtoType had method `getDecl` as `RecordDecl` has, you could get the parameter declarations from corresponding FunctionDecl. So you need to construct bogus function declaration when parsing function pointer declaration and attach it to the FunctionProtoType. There is however a problem with different declarations for the same type:</div><div><br></div><div>void (*pFn)(int x);<br></div><div>void (*pFn2)(int y);<br></div><div><br></div><div>The variables have the same type, but to keep named parameters you need different FunctionDecls. Probably the bogus declarations should be linked into redeclaration chain.</div><div><br></div><div>It is only an idea, I don't know if it is viable.</div><div><br></div><div><div class="gmail_signature">Thanks,<br>--Serge<br></div></div><div><br></div></div></div></div>