[PATCH] Request for approval to commit: [libclang] Expose DecayedType

Anders Waldenborg anders at 0x63.nu
Thu Sep 12 05:06:49 PDT 2013


Hi doug.gregor,

Adds support for DecayedType in the c bindings.

Makes it appear as its own TypeKind instead of the unexposed typekind. Adds two functions for getting the original and decayed-to types.

(coming up: patch to add it to the python bindings)

http://llvm-reviews.chandlerc.com/D1657

Files:
  include/clang-c/Index.h
  tools/libclang/CXType.cpp
  tools/libclang/libclang.exports

Index: include/clang-c/Index.h
===================================================================
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -2677,7 +2677,8 @@
   CXType_Vector = 113,
   CXType_IncompleteArray = 114,
   CXType_VariableArray = 115,
-  CXType_DependentSizedArray = 116
+  CXType_DependentSizedArray = 116,
+  CXType_Decayed = 117
 };
 
 /**
@@ -2923,6 +2924,21 @@
 CINDEX_LINKAGE long long clang_getArraySize(CXType T);
 
 /**
+ * \brief Return the original type of an decayed type.
+ *
+ * If a non-decayed type is passed in, an invalid type is returned.
+ */
+CINDEX_LINKAGE CXType clang_getDecayedOriginalType(CXType CT);
+
+/**
+ * \brief Return the decayed-to type of an decayed type.
+ *
+ * If a non-decayed type is passed in, an invalid type is returned.
+ */
+CINDEX_LINKAGE CXType clang_getDecayedDecayedType(CXType CT);
+
+
+/**
  * \brief List the possible error codes for \c clang_Type_getSizeOf,
  *   \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
  *   \c clang_Cursor_getOffsetOf.
Index: tools/libclang/CXType.cpp
===================================================================
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -23,6 +23,8 @@
 #include "clang/AST/Type.h"
 #include "clang/Frontend/ASTUnit.h"
 
+#include <iostream>
+
 using namespace clang;
 
 static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) {
@@ -89,6 +91,7 @@
     TKCASE(VariableArray);
     TKCASE(DependentSizedArray);
     TKCASE(Vector);
+    TKCASE(Decayed);
     default:
       return CXType_Unexposed;
   }
@@ -473,6 +476,7 @@
     TKIND(VariableArray);
     TKIND(DependentSizedArray);
     TKIND(Vector);
+    TKIND(Decayed);
   }
 #undef TKIND
   return cxstring::createRef(s);
@@ -639,6 +643,32 @@
   return result;
 }
 
+CXType clang_getDecayedOriginalType(CXType CT) {
+  QualType T = GetQualType(CT);
+  const Type *TP = T.getTypePtrOrNull();
+
+  if (!TP)
+    return MakeCXType(QualType(), GetTU(CT));
+
+  if (const DecayedType *DT = TP->getAs<DecayedType>())
+    return MakeCXType(DT->getOriginalType(), GetTU(CT));
+
+  return MakeCXType(QualType(), GetTU(CT));
+}
+
+CXType clang_getDecayedDecayedType(CXType CT) {
+  QualType T = GetQualType(CT);
+  const Type *TP = T.getTypePtrOrNull();
+
+  if (!TP)
+    return MakeCXType(QualType(), GetTU(CT));
+
+  if (const DecayedType *DT = TP->getAs<DecayedType>())
+    return MakeCXType(DT->getDecayedType(), GetTU(CT));
+
+  return MakeCXType(QualType(), GetTU(CT));
+}
+
 CXType clang_getArrayElementType(CXType CT) {
   QualType ET = QualType();
   QualType T = GetQualType(CT);
Index: tools/libclang/libclang.exports
===================================================================
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -152,6 +152,8 @@
 clang_getCursorSpelling
 clang_getCursorType
 clang_getCursorUSR
+clang_getDecayedOriginalType
+clang_getDecayedDecayedType
 clang_getDeclObjCTypeEncoding
 clang_getDefinitionSpellingAndExtent
 clang_getDiagnostic
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1657.1.patch
Type: text/x-patch
Size: 3021 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130912/91af493c/attachment.bin>


More information about the cfe-commits mailing list