r338808 - [libclang 3/8] Add support for AttributedType
Michael Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 2 21:21:25 PDT 2018
Author: mwu
Date: Thu Aug 2 21:21:25 2018
New Revision: 338808
URL: http://llvm.org/viewvc/llvm-project?rev=338808&view=rev
Log:
[libclang 3/8] Add support for AttributedType
Summary:
This patch adds support to the libclang API for identifying AttributedTypes in CXTypes and reading the modified type that the type points to. Currently AttributedTypes are skipped. This patch continues to skip AttributedTypes by default, but adds a parsing option to CXTranslationUnit to include AttributedTypes.
This patch depends on D49066 since it also adds a CXType.
Testing will be added in another patch which depends on this one.
Reviewers: yvvan, jbcoe
Reviewed By: yvvan
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D49081
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/libclang/CXType.cpp
cfe/trunk/tools/libclang/libclang.exports
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338808&r1=338807&r2=338808&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 21:21:25 2018
@@ -1331,7 +1331,12 @@ enum CXTranslationUnit_Flags {
*
* The function bodies of the main file are not skipped.
*/
- CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800
+ CXTranslationUnit_LimitSkipFunctionBodiesToPreamble = 0x800,
+
+ /**
+ * Used to indicate that attributed types should be included in CXType.
+ */
+ CXTranslationUnit_IncludeAttributedTypes = 0x1000
};
/**
@@ -3268,7 +3273,8 @@ enum CXTypeKind {
CXType_OCLReserveID = 160,
CXType_ObjCObject = 161,
- CXType_ObjCTypeParam = 162
+ CXType_ObjCTypeParam = 162,
+ CXType_Attributed = 163
};
/**
@@ -3818,6 +3824,13 @@ CINDEX_LINKAGE long long clang_Type_getS
CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
/**
+ * Return the type that was modified by this attributed type.
+ *
+ * If the type is not an attributed type, an invalid type is returned.
+ */
+CINDEX_LINKAGE CXType clang_Type_getModifiedType(CXType T);
+
+/**
* Return the offset of the field represented by the Cursor.
*
* If the cursor is not a field declaration, -1 is returned.
Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=338808&r1=338807&r2=338808&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Thu Aug 2 21:21:25 2018
@@ -112,6 +112,7 @@ static CXTypeKind GetTypeKind(QualType T
TKCASE(Auto);
TKCASE(Elaborated);
TKCASE(Pipe);
+ TKCASE(Attributed);
default:
return CXType_Unexposed;
}
@@ -125,7 +126,9 @@ CXType cxtype::MakeCXType(QualType T, CX
if (TU && !T.isNull()) {
// Handle attributed types as the original type
if (auto *ATT = T->getAs<AttributedType>()) {
- return MakeCXType(ATT->getModifiedType(), TU);
+ if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes)) {
+ return MakeCXType(ATT->getModifiedType(), TU);
+ }
}
// Handle paren types as the original type
if (auto *PTT = T->getAs<ParenType>()) {
@@ -591,6 +594,7 @@ CXString clang_getTypeKindSpelling(enum
TKIND(Auto);
TKIND(Elaborated);
TKIND(Pipe);
+ TKIND(Attributed);
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id);
#include "clang/Basic/OpenCLImageTypes.def"
#undef IMAGE_TYPE
@@ -996,6 +1000,17 @@ long long clang_Type_getOffsetOf(CXType
return CXTypeLayoutError_InvalidFieldName;
}
+CXType clang_Type_getModifiedType(CXType CT) {
+ QualType T = GetQualType(CT);
+ if (T.isNull())
+ return MakeCXType(QualType(), GetTU(CT));
+
+ if (auto *ATT = T->getAs<AttributedType>())
+ return MakeCXType(ATT->getModifiedType(), GetTU(CT));
+
+ return MakeCXType(QualType(), GetTU(CT));
+}
+
long long clang_Cursor_getOffsetOfField(CXCursor C) {
if (clang_isDeclaration(C.kind)) {
// we need to validate the parent type
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=338808&r1=338807&r2=338808&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Thu Aug 2 21:21:25 2018
@@ -103,6 +103,7 @@ clang_Type_getNumObjCProtocolRefs
clang_Type_getObjCProtocolDecl
clang_Type_getNumObjCTypeArgs
clang_Type_getObjCTypeArg
+clang_Type_getModifiedType
clang_VerbatimBlockLineComment_getText
clang_VerbatimLineComment_getText
clang_HTMLTagComment_getAsString
More information about the cfe-commits
mailing list