<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Apr 4, 2013, at 6:33 PM, Loïc Jaquemet <<a href="mailto:loic.jaquemet@gmail.com">loic.jaquemet@gmail.com</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div dir="ltr"><div><div>ah yes.<br></div>The lookup failure. I forgot that one instance.<br><br></div>Attached patches pass tests on r178827.<br></div></div></blockquote><div><br></div><div>I think you meant to attach different files, these look like earlier versions of your patches (e.g. clang_getAlignOf, instead of clang_Type_getAlignOf)</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="gmail_extra"><br><br><div class="gmail_quote">2013/4/4 Argyrios Kyrtzidis<span class="Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;"><br><div><div><div class="h5"><div>On Apr 4, 2013, at 12:04 AM, Loïc Jaquemet <<a href="mailto:loic.jaquemet@gmail.com" target="_blank">loic.jaquemet@gmail.com</a>> wrote:</div><br><blockquote type="cite"><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div class="gmail_extra"><br><br><br><div class="gmail_quote">2013/4/1 Argyrios Kyrtzidis<span> </span><span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><br><div><div>+  /**</div><div>+   * \brief One field in the record is an incomplete Type.</div><div>+   */</div><div>+  CXTypeLayoutError_IncompleteFieldParent = -6,</div><div>+  /**</div><div>+   * \brief One field in the record is a dependent Type.</div><div>+   */</div><div>+  CXTypeLayoutError_DependentFieldParent = -7</div><div>+};</div><div><br></div><div>This was a bit confusing until I read</div><div><br></div><div><div>+ * If in the record there is another field's type declaration that is</div><div>+ *   an incomplete type, CXTypeLayoutError_IncompleteFieldParent is returned.</div><div>+ * If in the record there is another field's type declaration that is</div><div>+ *   a dependent type, CXTypeLayoutError_DependentFieldParent is returned.</div><div>+ */</div></div><div><br></div><div>Could we change it to a simpler, "the parent record is incomplete/dependent" ?</div><div><br></div></div></div></blockquote><div><br></div><div>Given the radical code change, these confusing errors do not exists any more.<br></div><div><br> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><div></div><div><br></div><div><div>+/**</div><div>+ * \brief Returns 1 if the cursor specifies a Record member that is a bitfield.</div><div>+ */</div><div>+CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);</div></div><div><br></div><div>the convention that we use is "Returns non-zero if ..."</div><div><br></div></div></blockquote><div><br>done<br></div><div><br> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><div></div><div><br></div><div><div>+static long long visitRecordForNamedField(const RecordDecl *RD,</div><div>+                                          StringRef FieldName) {</div><div><div>+  for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();</div><div>+       I != E; ++I) {</div></div></div></div></blockquote><div>[..]<span> </span><br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><div>+  return visitRecordForNamedField(RD, FieldName);<div>+}</div></div><div><br></div><div>I think there is a simpler and more efficient way to handle fields in anonymous records, something like this:</div><div>Inside clang_Type_getOffsetOf():</div><div><br></div><div> <span class="Apple-converted-space"> </span>CXTranslationUnit TU =<br>     <span class="Apple-converted-space"> </span>static_cast<CXTranslationUnit>(const_cast<void*>(PT.data[1]));<br> <span class="Apple-converted-space"> </span>ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext();<br> <span class="Apple-converted-space"> </span>IdentifierInfo *II = &Ctx.Idents.get(S);<br> <span class="Apple-converted-space"> </span>DeclarationName FieldName(II);<br> <span class="Apple-converted-space"> </span>RecordDecl::lookup_const_result Res = RD->lookup(FieldName);<br> <span class="Apple-converted-space"> </span>if (Res.size() != 1)<br>   <span class="Apple-converted-space"> </span>return CXTypeLayoutError_InvalidFieldName;<br> <span class="Apple-converted-space"> </span>if (const FieldDecl *FD = dyn_cast<FieldDecl>(Res.front()))<br>   <span class="Apple-converted-space"> </span>return getOffsetOfFieldDecl(FD);<br> <span class="Apple-converted-space"> </span>if (const IndirectFieldDecl *IFD = dyn_cast<IndirectFieldDecl>(Res.front()))<br>   <span class="Apple-converted-space"> </span>return Ctx.getFieldOffset(IFD); // Change getOffsetOfFieldDecl() to accept IFD.<br><br> <span class="Apple-converted-space"> </span>return CXTypeLayoutError_InvalidFieldName;<br><br></div></div></blockquote><div><br></div><div>Thanks! That was exactly was I was looking for.<br></div><div><br><br>In the process of implementing that new code, I stumble on some new crash tests cases.<br></div><div>The RecordLayoutBuilder forces me to do a full validation of all records fields in a record.<br></div><div>I have implemented a recursive validation function to do that.<br></div><div>At the end, it does simplify the testing quite a lot.<br></div><div>I do have to forget about the two previously confusing error types, as they would not be distinguishable.<br></div><div><br></div><div>So, basically, this code is now simpler and more robust.<br></div><div>I added some tests cases in the Incomplete namespace to demonstrate the several issues I uncovered.<br></div><div><br> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;"><div><div></div><div><br></div></div><div><blockquote type="cite"><div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><br>I also removed the duplicate clang_Cursor_getOffsetOf().<br>After consideration, it did not make sense, especially in the<br>anonymous record situation.<br></div></blockquote><div><br></div></div><div>Not sure about this, clang_Cursor_getOffsetOf is arguable more useful than clang_Type_getOffsetOf.</div><div>Let's say you have this use-case: "visit all fields in a record and get their offsets". To do this (as your changes in c-index-test show) you need to use this roundabout way where, you have the field, then you get its name, and pass it to clang_Type_getOffsetOf which looks for the same field.</div><div>Can't clang_Cursor_getOffsetOf just work, for example if you have a cursor for "foo" in</div><div><br></div><div>struct S {</div><div>   struct {</div><div>     <span class="Apple-converted-space"> </span>int foo;</div><div>   };</div><div>};</div><div><br></div><div>it should just return the offset of "foo" inside "struct S".</div></div></blockquote><div><br></div><div>That was also my feeling at the beginning.<br></div><div>But after several iteration on my own code, I see that my own use of this function is always in a context were I do have the record's type and the field's name at hand.<br></div><div>On top of that, the C++ standard calls for a Type signature.<br></div><div>So I will keep it to that.<span> </span><br></div><br></div><br>Please see attached diffs.<br></div></div></blockquote><div><br></div></div></div><div>test/Index/print-type-size.cpp failed when I applied the diffs on top of r178800, could you take a look ?</div><br><blockquote type="cite"><div class="im"><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div class="gmail_extra"><br>* Implementation of sizeof, alignof and offsetof for libclang.<br>* Unit Tests<br>* Python bindings<br>* Python tests<br><br>--<span> </span><br>Loïc Jaquemet<br></div></div></div><span><sizeof-alignof-offsetof-001></span><span><sizeof-alignof-offsetof-002-tests></span><span><sizeof-alignof-offsetof-003-python-bindings></span><span><sizeof-alignof-offsetof-004-python-bindings-tests></span></blockquote></div><br></div></blockquote></div><br><br clear="all"><br>--<span class="Apple-converted-space"> </span><br>Loïc Jaquemet<br></div><span><expose-ast-record-layout-001></span><span><expose-ast-record-layout-002-tests></span><span><expose-ast-record-layout-003-python-bindings></span><span><expose-ast-record-layout-004-python-bindings-tests></span></div></blockquote></div><br></body></html>