[cfe-commits] r124377 - in /cfe/trunk: include/clang-c/Index.h test/Index/print-typekind.c tools/c-index-test/c-index-test.c tools/libclang/CXType.cpp tools/libclang/libclang.darwin.exports tools/libclang/libclang.exports

Douglas Gregor dgregor at apple.com
Thu Jan 27 08:27:11 PST 2011


Author: dgregor
Date: Thu Jan 27 10:27:11 2011
New Revision: 124377

URL: http://llvm.org/viewvc/llvm-project?rev=124377&view=rev
Log:
Add libclang functions to determine the const/volatile/restrict
qualifiers on a CXType. Patch from Stefan Seefeld, test by me.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/test/Index/print-typekind.c
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/CXType.cpp
    cfe/trunk/tools/libclang/libclang.darwin.exports
    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=124377&r1=124376&r2=124377&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Jan 27 10:27:11 2011
@@ -1782,6 +1782,24 @@
 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.
  *
  */

Modified: cfe/trunk/test/Index/print-typekind.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-typekind.c?rev=124377&r1=124376&r2=124377&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-typekind.c (original)
+++ cfe/trunk/test/Index/print-typekind.c Thu Jan 27 10:27:11 2011
@@ -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 @@
 // 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]

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=124377&r1=124376&r2=124377&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Jan 27 10:27:11 2011
@@ -568,6 +568,12 @@
     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. */
     {

Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=124377&r1=124376&r2=124377&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Thu Jan 27 10:27:11 2011
@@ -186,6 +186,21 @@
   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();

Modified: cfe/trunk/tools/libclang/libclang.darwin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.darwin.exports?rev=124377&r1=124376&r2=124377&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.darwin.exports (original)
+++ cfe/trunk/tools/libclang/libclang.darwin.exports Thu Jan 27 10:27:11 2011
@@ -109,16 +109,19 @@
 _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

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=124377&r1=124376&r2=124377&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Thu Jan 27 10:27:11 2011
@@ -108,6 +108,7 @@
 clang_getTypeDeclaration
 clang_getTypeKindSpelling
 clang_hashCursor
+clang_isConstQualifiedType
 clang_isCursorDefinition
 clang_isDeclaration
 clang_isExpression
@@ -115,10 +116,12 @@
 clang_isPODType
 clang_isPreprocessing
 clang_isReference
+clang_isRestrictQualifiedType
 clang_isStatement
 clang_isTranslationUnit
 clang_isUnexposed
 clang_isVirtualBase
+clang_isVolatileQualifiedType
 clang_parseTranslationUnit
 clang_reparseTranslationUnit
 clang_saveTranslationUnit





More information about the cfe-commits mailing list