<div dir="ltr">Other than just overriding VisitRecordDecl (instead of VisitDecl) what you've done seems to make sense. Sorry about the confusion; I thought for some reason you already had a reference to the TypedefDecl and didn't want to do another AST visitation to find the struct.<div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 7, 2015 at 3:58 PM, Alberto Barbaro <span dir="ltr"><<a href="mailto:barbaro.alberto@gmail.com" target="_blank">barbaro.alberto@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi all,<br></div>i solved in this way. Probably it isn't the best one but i hope this help:<br><br>bool VisitDecl(Decl *D) { <br> clang::RecordDecl::field_iterator jt;<br> if (RecordDecl *var = dyn_cast<RecordDecl>(D)) {<br> for(jt = var->field_begin(); jt != var->field_end();++jt) { <br> std::cout << jt->getType().getAsString() << " " << jt->getNameAsString() << std::endl; <br> }<br> }<br>}<br><br></div><div>Any suggestion?<br><br></div>Thanks,<br></div>Alberto<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2015-03-07 23:07 GMT+00:00 Alberto Barbaro <span dir="ltr"><<a href="mailto:barbaro.alberto@gmail.com" target="_blank">barbaro.alberto@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>Hi All,<br></div>i'm trying again to access to the fields of the struct but also after the first help i can't do it. I tried in this way but it isn't correct and i can't understand how to fix it:<br><br>virtual bool VisitTypedefDecl (TypedefDecl *d) {<br> cout << "typedef\n";<br> QualType qt = d->getUnderlyingType();<br> qt.dump();<br> <br> for (clang::DeclContext::decl_iterator it = (qt).decls_begin(), declEnd = (qt).decls_end();it != declEnd; ++it) {<br> cout << "." << endl;<br> }<br> <br> return true;<br> }<br><br></div>Of course .decls_begins()/end() aren't available but i think cast to DeclContext() isn't the right solution.<br><br></div>Any suggestion?<br><br></div>Thanks,<br></div>Alberto<br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-02-18 23:50 GMT+00:00 Alberto Barbaro <span dir="ltr"><<a href="mailto:barbaro.alberto@gmail.com" target="_blank">barbaro.alberto@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Sean <br>
Thanks I'll do as you have suggested.</p><span><font color="#888888">
<p dir="ltr">Alberto</p></font></span><div><div>
<div class="gmail_quote">On 18 Feb 2015 23:43, "Sean Silva" <<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You will first want to get the RecordDecl through TypedefNameDecl::getUnderlyingType and then use the decls_begin/end iterators for iterating (or the decls() range in a range-for) (note these methods are inherited from DeclContext).<div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 14, 2015 at 1:15 PM, Alberto Barbaro <span dir="ltr"><<a href="mailto:barbaro.alberto@gmail.com" target="_blank">barbaro.alberto@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi All,<br></div>in my .c file I have a struct like this:<br><br>typedef struct var {<br> int x;<br> int y;<br>} point;<br><br><br></div>Overriding the VisitTypedefDecl method I can access to the structure using a TypedefNameDecl variable. How can I access to the fields of the struct?<br><br></div>Thanks,<br>Alberto<br></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>