[cfe-dev] HOWTO: use a CXCursor referring a Typedef

Douglas Gregor dgregor at apple.com
Tue Jan 25 08:39:24 PST 2011


On Jan 25, 2011, at 6:00 AM, Stefan Seefeld wrote:

> On 2011-01-24 20:23, Douglas Gregor wrote:
>> 
>> CXType doesn't fully expose the Clang type system, although it could. I'd support the addition of APIs to extract more information from CXTypes.
> 
> The attached patch adds two new functions clang_isConstQualifiedType and clang_isVolatileQualifiedType. It works fine in the context I tried it in.
> How does that look ?

Index: tools/libclang/CXType.cpp
===================================================================
--- tools/libclang/CXType.cpp	(revision 124135)
+++ tools/libclang/CXType.cpp	(working copy)
@@ -186,6 +186,16 @@
   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();
+}
+
 CXType clang_getPointeeType(CXType CT) {
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();

These functions look good. Now, since you're using the "Local" variants of these functions, this returns the "const" or "volatile" qualifier as it was written in the source code, rather than whether the entity itself was semantically const. For example, given:

  typedef const int T;
  volatile T var;

the type of "var" is "volatile T". clang_isVolatileQualifiedType() will return true, while clang_isConstQualifiedType() will return false. If one maps down to the canonical type, we'll get

  const volatile int 

and then both clang_isVolatileQualifiedType() and clang_isConstQualifierType() will return true.

You probably knew all this, but I'd love to see it captured in the comments for clang_isConstQualifiedType() and clang_isVolatileQualifiedType() for clients using the library. 

Also, could you add clang_isRestrictQualifiedType(), to finish off the basic set?

Index: tools/libclang/libclang.exports
===================================================================
--- tools/libclang/libclang.exports	(revision 124135)
+++ tools/libclang/libclang.exports	(working copy)

this is great; could you also update libclang.darwin.exports?

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110125/fc7ca2b8/attachment.html>


More information about the cfe-dev mailing list