<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">In r140614, thanks!<div><br><div><div>On Sep 23, 2011, at 5:03 AM, Vinay Sajip wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="color:#000; background-color:#fff; font-family:tahoma, new york, times, serif;font-size:10pt"><div><span>I've attached a revised patch which takes your comments into account.</span></div><div><br><span></span></div><div><span>Regards,</span></div><div><br><span></span></div><div><span>Vinay Sajip<br></span></div><div><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><div style="font-family: tahoma,new york,times,serif; font-size: 10pt;"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Arial" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Argyrios Kyrtzidis <<a href="mailto:kyrtzidis@apple.com">kyrtzidis@apple.com</a>><br><b><span style="font-weight: bold;">To:</span></b> Vinay Sajip <<a href="mailto:vinay_sajip@yahoo.co.uk">vinay_sajip@yahoo.co.uk</a>><br><b><span style="font-weight: bold;">Cc:</span></b> "<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a>" <<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a>><br><b><span style="font-weight: bold;">Sent:</span></b> Wednesday, 21 September 2011, 2:03<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [cfe-commits] libclang: Patch to expose array size and element type<br></font><br><div id="yiv850599843"><div><blockquote type="cite"><div><font class="yiv850599843Apple-style-span" color="#000000">diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">index 07bcf9e..3257664 100644</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">--- a/include/clang-c/Index.h</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+++ b/include/clang-c/Index.h</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">@@ -1955,7 +1955,8 @@ enum CXTypeKind {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> CXType_ObjCInterface =
108,</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> CXType_ObjCObjectPointer = 109,</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> CXType_FunctionNoProto = 110,</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">- CXType_FunctionProto = 111</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ CXType_FunctionProto = 111,</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ CXType_ConstantArray = 112</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> };</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> </font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> /**</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">@@ -2047,6 +2048,20 @@ CINDEX_LINKAGE CXType
clang_getCursorResultType(CXCursor C);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> CINDEX_LINKAGE unsigned clang_isPODType(CXType T);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> </font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> /**</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ * \brief Return the element type of an array type.</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ *</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ * If a non-array type is passed in, an invalid type is returned.</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ */</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+/**</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ * \brief Return the the array size of a constant array.</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ *</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ * If a non-array type is passed in, -1 is returned.</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ */</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+CINDEX_LINKAGE int clang_getArraySize(CXType T);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+/**</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> * \brief Returns 1 if the base class
specified by the cursor with kind</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> * CX_CXXBaseSpecifier is virtual.</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> */</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">index 45c7346..2a20298 100644</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">--- a/tools/libclang/CXType.cpp</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+++ b/tools/libclang/CXType.cpp</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">@@ -84,6 +84,7 @@ static CXTypeKind GetTypeKind(QualType T) {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">
TKCASE(ObjCObjectPointer);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> TKCASE(FunctionNoProto);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> TKCASE(FunctionProto);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ TKCASE(ConstantArray);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> default:</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> return CXType_Unexposed;</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> }</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">@@ -330,6 +331,7 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">
TKIND(ObjCObjectPointer);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> TKIND(FunctionNoProto);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> TKIND(FunctionProto);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+ TKIND(ConstantArray);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> }</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> #undef TKIND</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> return cxstring::createCXString(s);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">@@ -373,6 +375,46 @@ unsigned clang_isPODType(CXType X) {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> return T.isPODType(AU->getASTContext()) ? 1 :
0;</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> }</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> </font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+CXType clang_getArrayElementType(CXType X)</font></div></blockquote><div><br></div><div>Nitpick but please use 'CXType CT' or 'T' as parameter name. I see that clang_isPODType also has 'X' but let's just ignore it :-)</div><div><br></div><blockquote type="cite"><div><font class="yiv850599843Apple-style-span" color="#000000">+{</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>CXTranslationUnit TU = GetTU(X);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>QualType ET = QualType();</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>QualType T = GetQualType(X);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>const Type *TP = T.getTypePtrOrNull();</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>if (TP) {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>switch (TP->getTypeClass()) {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>case
Type::ConstantArray:</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>ET = cast<ConstantArrayType>(TP)->getElementType();</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>break;</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>default:</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>break;</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>}</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>}</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>return MakeCXType(ET, TU);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+}</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+int clang_getArraySize(CXType X)</font></div></blockquote><div><br></div><div>Better to have it return 'long long' I think.</div><div><br></div><blockquote type="cite"><div><font class="yiv850599843Apple-style-span" color="#000000">+{</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>int result = -1;</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>QualType T = GetQualType(X);</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>const Type *TP = T.getTypePtrOrNull();</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>if (TP) {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>switch (TP->getTypeClass()) {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>case Type::ConstantArray:</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>{</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>llvm::APInt size = cast<ConstantArrayType>(TP)->getSize();</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>result = size.getSExtValue();</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>}</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>break;</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>default:</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>break;</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>}</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>}</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+<span class="yiv850599843Apple-tab-span" style="white-space: pre;"> </span>return result;</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+}</font></div></blockquote><div><br></div><div>LLVM conventions are no tabs, 2 spaces for indentation, and '{' on the same line as the case statement and the function
declaration. This applies to all your patches.</div><div><br></div><div>Could you also add a test at 'test/Index/print-typekind.c' ?</div><div><div><br></div><div>-Argyrios</div></div><br><blockquote type="cite"><div><font class="yiv850599843Apple-style-span" color="#000000">+</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> CXString clang_getDeclObjCTypeEncoding(CXCursor C) {</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> if ((C.kind < CXCursor_FirstDecl) || (C.kind > CXCursor_LastDecl))</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> return cxstring::createCXString("");</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">index ea7aaf0..cc6c326
100644</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">--- a/tools/libclang/libclang.exports</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+++ b/tools/libclang/libclang.exports</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">@@ -42,6 +42,8 @@ clang_equalRanges</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> clang_equalTypes</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> clang_executeOnThread</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> clang_formatDiagnostic</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+clang_getArrayElementType</font></div><div><font class="yiv850599843Apple-style-span" color="#000000">+clang_getArraySize</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> clang_getCString</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> clang_getCXTUResourceUsage</font></div><div><font class="yiv850599843Apple-style-span" color="#000000"> clang_getCXXAccessSpecifier</font></div></blockquote></div><div><div><br></div></div><div><br></div><br><div><div>On Sep 15, 2011, at 5:38 AM, Vinay Sajip wrote:</div><br class="yiv850599843Apple-interchange-newline"><blockquote type="cite"><div>I've attached a patch which exposes array size and element type via the libclang API. At the moment, only constant arrays are handled.<br><br><br>Comments welcome.<br><br>Regards,<br><br>Vinay Sajip<br><span><const-arrays.diff></span>_______________________________________________<br>cfe-commits mailing list<br><a rel="nofollow" ymailto="mailto:cfe-commits@cs.uiuc.edu" target="_blank" href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br></div></blockquote></div><br></div><br><br></div></div></blockquote></div></div></div><span><arrays.diff></span>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits<br></blockquote></div><br></div></body></html>