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

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Sep 12 09:45:35 PDT 2013


On Sep 12, 2013, at 5:06 AM, Anders Waldenborg <anders at 0x63.nu> wrote:

> 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.

Since libclang is supposed to be somewhat higher level and closer to the source, could we just report a DecayedType as the original (as written) one ?
Or do you have a specific use case where you need to know that it is a DecayedType ?

> 
> (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
> <D1657.1.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list