aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-01-27 16:27:11 +0000
committerDouglas Gregor <dgregor@apple.com>2011-01-27 16:27:11 +0000
commite72fb6f40231a1e8372c7576b69f06f0a1eb28a7 (patch)
tree35cd709c463c840602b202f70d325d8644a3ffbe
parent9319b56154cfd9e3c781e54d2ee1c10c5858efed (diff)
Add libclang functions to determine the const/volatile/restrict
qualifiers on a CXType. Patch from Stefan Seefeld, test by me. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124377 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang-c/Index.h18
-rw-r--r--test/Index/print-typekind.c4
-rw-r--r--tools/c-index-test/c-index-test.c6
-rw-r--r--tools/libclang/CXType.cpp15
-rw-r--r--tools/libclang/libclang.darwin.exports3
-rw-r--r--tools/libclang/libclang.exports3
6 files changed, 47 insertions, 2 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 46b429dda2..b3b49c79c3 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -1782,6 +1782,24 @@ CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
/**
+ * \determine Determine whether a CXType has the "const" qualifier set,
+ * without looking through typedefs that may have added "const" at a different level.
+ */
+CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
+
+/**
+ * \determine Determine whether a CXType has the "volatile" qualifier set,
+ * without looking through typedefs that may have added "volatile" at a different level.
+ */
+CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
+
+/**
+ * \determine Determine whether a CXType has the "restrict" qualifier set,
+ * without looking through typedefs that may have added "restrict" at a different level.
+ */
+CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
+
+/**
* \brief For pointer types, returns the type of the pointee.
*
*/
diff --git a/test/Index/print-typekind.c b/test/Index/print-typekind.c
index fad3a2dc25..30bd409b09 100644
--- a/test/Index/print-typekind.c
+++ b/test/Index/print-typekind.c
@@ -1,7 +1,7 @@
typedef int FooType;
int *p;
int *f(int *p, char *x, FooType z) {
- FooType w = z;
+ const FooType w = z;
return p + z;
}
typedef double OtherType;
@@ -16,7 +16,7 @@ typedef double OtherType;
// CHECK: TypeRef=FooType:1:13 typekind=Typedef [canonical=Int] [isPOD=1]
// CHECK: UnexposedStmt= typekind=Invalid [isPOD=0]
// CHECK: UnexposedStmt= typekind=Invalid [isPOD=0]
-// CHECK: VarDecl=w:4:11 (Definition) typekind=Typedef [canonical=Int] [isPOD=1]
+// CHECK: VarDecl=w:4:17 (Definition) typekind=Typedef const [canonical=Int] [isPOD=1]
// CHECK: TypeRef=FooType:1:13 typekind=Typedef [canonical=Int] [isPOD=1]
// CHECK: DeclRefExpr=z:3:33 typekind=Typedef [canonical=Int] [isPOD=1]
// CHECK: UnexposedStmt= typekind=Invalid [isPOD=0]
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 7238f4a2d0..be3a079598 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -568,6 +568,12 @@ static enum CXChildVisitResult PrintTypeKind(CXCursor cursor, CXCursor p,
CXString S = clang_getTypeKindSpelling(T.kind);
PrintCursor(cursor);
printf(" typekind=%s", clang_getCString(S));
+ if (clang_isConstQualifiedType(T))
+ printf(" const");
+ if (clang_isVolatileQualifiedType(T))
+ printf(" volatile");
+ if (clang_isRestrictQualifiedType(T))
+ printf(" restrict");
clang_disposeString(S);
/* Print the canonical type if it is different. */
{
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 7b603c0f93..93326724de 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -186,6 +186,21 @@ CXType clang_getCanonicalType(CXType CT) {
return MakeCXType(AU->getASTContext().getCanonicalType(T), TU);
}
+unsigned clang_isConstQualifiedType(CXType CT) {
+ QualType T = GetQualType(CT);
+ return T.isLocalConstQualified();
+}
+
+unsigned clang_isVolatileQualifiedType(CXType CT) {
+ QualType T = GetQualType(CT);
+ return T.isLocalVolatileQualified();
+}
+
+unsigned clang_isRestrictQualifiedType(CXType CT) {
+ QualType T = GetQualType(CT);
+ return T.isLocalRestrictQualified();
+}
+
CXType clang_getPointeeType(CXType CT) {
QualType T = GetQualType(CT);
const Type *TP = T.getTypePtrOrNull();
diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports
index 1792312de2..7614544ca3 100644
--- a/tools/libclang/libclang.darwin.exports
+++ b/tools/libclang/libclang.darwin.exports
@@ -109,16 +109,19 @@ _clang_getTypeDeclaration
_clang_getTypeKindSpelling
_clang_hashCursor
_clang_isCursorDefinition
+_clang_isConstQualifiedType
_clang_isDeclaration
_clang_isExpression
_clang_isInvalid
_clang_isPODType
_clang_isPreprocessing
_clang_isReference
+_clang_isRestrictQualifiedType
_clang_isStatement
_clang_isTranslationUnit
_clang_isUnexposed
_clang_isVirtualBase
+_clang_isVolatileQualifiedType
_clang_parseTranslationUnit
_clang_reparseTranslationUnit
_clang_saveTranslationUnit
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index c5415e3614..c2f0587b9a 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -108,6 +108,7 @@ clang_getTranslationUnitSpelling
clang_getTypeDeclaration
clang_getTypeKindSpelling
clang_hashCursor
+clang_isConstQualifiedType
clang_isCursorDefinition
clang_isDeclaration
clang_isExpression
@@ -115,10 +116,12 @@ clang_isInvalid
clang_isPODType
clang_isPreprocessing
clang_isReference
+clang_isRestrictQualifiedType
clang_isStatement
clang_isTranslationUnit
clang_isUnexposed
clang_isVirtualBase
+clang_isVolatileQualifiedType
clang_parseTranslationUnit
clang_reparseTranslationUnit
clang_saveTranslationUnit