[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-commits
Subject: [cfe-commits] [patch] abstract classes and type of this pointer
From: Paolo Capriotti <p.capriotti () gmail ! com>
Date: 2012-01-08 20:02:27
Message-ID: CALMmMjaJoeyn32HgyrXJUNKz5t+fWMD+SeeqWaUF1Gh_a7OD0g () mail ! gmail ! com
[Download RAW message or body]
Hi all,
I'd like to submit the following patches for libclang:
abstract-classes.patch: add clang_isAbstractClassCursor function to
check whether a class is abstract
this-type.patch: add clang_getCursorThisType function that returns the
type of the "this" pointer for C++ methods.
BR,
Paolo
["abstract-classes.patch" (text/x-patch)]
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 92315a3..f93aa69 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -2502,6 +2502,12 @@ CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
/**
+ * \determine Determine whether a cursor represents a declaration for an
+ * abstract C++ class.
+ */
+CINDEX_LINKAGE unsigned clang_isAbstractClassCursor(CXCursor C);
+
+/**
* \brief For pointer types, returns the type of the pointee.
*
*/
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 52e77bd..475770c 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -273,6 +273,15 @@ unsigned clang_isRestrictQualifiedType(CXType CT) {
return T.isLocalRestrictQualified();
}
+unsigned clang_isAbstractClassCursor(CXCursor C) {
+ if (clang_isDeclaration(C.kind)) {
+ Decl *D = cxcursor::getCursorDecl(C);
+ if (CXXRecordDecl *TD = dyn_cast<CXXRecordDecl>(D))
+ return TD->isAbstract();
+ }
+ return false;
+}
+
CXType clang_getPointeeType(CXType CT) {
QualType T = GetQualType(CT);
const Type *TP = T.getTypePtrOrNull();
["this-type.patch" (text/x-patch)]
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index f93aa69..467b3bf 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -2571,6 +2571,14 @@ CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
/**
+ * \brief Retrieve the type of the this pointer associated to a given cursor.
+ *
+ * This only returns a valid type if the cursor refers to a C++ instance
+ * method.
+ */
+CINDEX_LINKAGE CXType clang_getCursorThisType(CXCursor C);
+
+/**
* \brief Return 1 if the CXType is a POD (plain old data) type, and 0
* otherwise.
*/
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 475770c..ebc833f 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -516,6 +516,23 @@ CXType clang_getCursorResultType(CXCursor C) {
return MakeCXType(QualType(), cxcursor::getCursorTU(C));
}
+CXType clang_getCursorThisType(CXCursor C) {
+ if (clang_isDeclaration(C.kind)) {
+ Decl *D = cxcursor::getCursorDecl(C);
+ if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D))
+ if (MD->isInstance()) {
+ CXTranslationUnit TU = static_cast<CXTranslationUnit>(C.data[2]);
+ ASTUnit *AU = static_cast<ASTUnit*>(TU->TUData);
+ ASTContext &Ctx = AU->getASTContext();
+ return MakeCXType(MD->getThisType(Ctx), cxcursor::getCursorTU(C));
+ }
+
+ return clang_getResultType(clang_getCursorType(C));
+ }
+
+ return MakeCXType(QualType(), cxcursor::getCursorTU(C));
+}
+
unsigned clang_isPODType(CXType X) {
QualType T = GetQualType(X);
if (T.isNull())
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic