2010-01-16 04:35:54 +08:00
|
|
|
//===- CXCursor.cpp - Routines for manipulating CXCursors -----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-01-16 22:00:32 +08:00
|
|
|
// This file defines routines for manipulating CXCursors. It should be the
|
|
|
|
// only file that has internal knowledge of the encoding of the data in
|
|
|
|
// CXCursor.
|
2010-01-16 04:35:54 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-18 07:24:11 +08:00
|
|
|
#include "CXTranslationUnit.h"
|
2010-01-16 04:35:54 +08:00
|
|
|
#include "CXCursor.h"
|
2010-11-16 09:56:27 +08:00
|
|
|
#include "CXString.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "CXType.h"
|
|
|
|
#include "clang-c/Index.h"
|
Remove unnecessary inclusion of Sema.h
Let me tell you a tale...
Within some twisted maze of debug info I've ended up implementing an
insane man's Include What You Use device. When the debugger emits debug
info it really shouldn't, I find out why & then realize the code could
be improved too.
In this instance CIndexDiagnostics.cpp had a lot more debug info with
Clang than GCC. Upon inspection a major culprit was all the debug info
describing clang::Sema. This was emitted because clang::Sema is
befriended by DiagnosticEngine which was rightly required, but GCC
doesn't emit debug info for friends so it never emitted anything for
Clang. Clang does emit debug info for friends (will be fixed/changed to
reduce debug info size).
But why didn't Clang just emit a declaration of Sema if this entire TU
didn't require a definition?
1) Diagnostic.h did the right thing, only using a declaration of Sema
and not including Sema.h at all.
2) Some other dependency of CIndexDiagnostics.cpp didn't do the right
thing. ASTUnit.h, only needing a declaration, still included Sema.h
(hence this commit which removes that include and adds the necessary
includes to the cpp files that were relying on this)
3) -flimit-debug-info didn't save us because of
EnterExpressionEvaluationContext, defined inline in Sema.h which fires
the "requiresCompleteType" check/flag (since it uses nested types from
Sema and calls Sema member functions) and thus, if debug info is ever
emitted for the type, the whole type is emitted and not just a
declaration.
Improving -flimit-debug-info to account for this would be... hard.
Modifying the code so that's not 'required to be complete' might be
possible, but probably only by moving EnterExpressionEvaluationContext
either into Sema, or out of Sema.h. That might be a bit too much of a
contortion to be bothered with.
Also, this is only one of the cases where emitting debug info for
friends caused us to emit a lot more debug info (this change reduces
Clang's DWO size by 0.93%, dropping friends entirely reduces debug info
by 3.2%) - I haven't hunted down the other cases, but I assume they
might be similar (Sema or something like it). IWYU or a similar tool
might help us reduce build times a bit, but analyzing debug info to find
these differences isn't worthwhile. I'll take the 3.2% win, provide this
small improvement to the code itself, and move on.
llvm-svn: 190715
2013-09-14 02:32:52 +08:00
|
|
|
#include "clang/AST/Attr.h"
|
2010-01-16 04:35:54 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
2010-09-01 07:48:11 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2010-01-16 05:56:13 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2011-10-06 15:00:54 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2010-01-16 05:56:13 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2010-09-14 06:52:57 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2011-10-06 15:00:54 +08:00
|
|
|
#include "clang/AST/ExprObjC.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "clang/Frontend/ASTUnit.h"
|
2010-01-16 08:36:30 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-01-16 04:35:54 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
2010-09-14 06:52:57 +08:00
|
|
|
using namespace cxcursor;
|
2010-01-16 04:35:54 +08:00
|
|
|
|
2012-05-01 03:06:49 +08:00
|
|
|
CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU) {
|
2010-01-21 07:34:41 +08:00
|
|
|
assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid);
|
2014-06-08 16:38:04 +08:00
|
|
|
CXCursor C = { K, 0, { nullptr, nullptr, TU } };
|
2010-01-21 07:34:41 +08:00
|
|
|
return C;
|
2010-01-16 04:35:54 +08:00
|
|
|
}
|
|
|
|
|
2010-02-18 11:09:07 +08:00
|
|
|
static CXCursorKind GetCursorKind(const Attr *A) {
|
|
|
|
assert(A && "Invalid arguments!");
|
|
|
|
switch (A->getKind()) {
|
|
|
|
default: break;
|
2010-06-17 07:43:53 +08:00
|
|
|
case attr::IBAction: return CXCursor_IBActionAttr;
|
|
|
|
case attr::IBOutlet: return CXCursor_IBOutletAttr;
|
|
|
|
case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr;
|
2011-09-14 01:39:31 +08:00
|
|
|
case attr::Final: return CXCursor_CXXFinalAttr;
|
|
|
|
case attr::Override: return CXCursor_CXXOverrideAttr;
|
2011-10-13 17:41:32 +08:00
|
|
|
case attr::Annotate: return CXCursor_AnnotateAttr;
|
2011-12-07 06:05:01 +08:00
|
|
|
case attr::AsmLabel: return CXCursor_AsmLabelAttr;
|
2013-09-25 08:14:38 +08:00
|
|
|
case attr::Packed: return CXCursor_PackedAttr;
|
2014-05-01 23:41:58 +08:00
|
|
|
case attr::Pure: return CXCursor_PureAttr;
|
|
|
|
case attr::Const: return CXCursor_ConstAttr;
|
|
|
|
case attr::NoDuplicate: return CXCursor_NoDuplicateAttr;
|
2014-05-29 03:29:58 +08:00
|
|
|
case attr::CUDAConstant: return CXCursor_CUDAConstantAttr;
|
|
|
|
case attr::CUDADevice: return CXCursor_CUDADeviceAttr;
|
|
|
|
case attr::CUDAGlobal: return CXCursor_CUDAGlobalAttr;
|
|
|
|
case attr::CUDAHost: return CXCursor_CUDAHostAttr;
|
2014-08-08 22:59:00 +08:00
|
|
|
case attr::CUDAShared: return CXCursor_CUDASharedAttr;
|
2015-09-06 02:53:43 +08:00
|
|
|
case attr::Visibility: return CXCursor_VisibilityAttr;
|
2015-12-11 02:45:18 +08:00
|
|
|
case attr::DLLExport: return CXCursor_DLLExport;
|
|
|
|
case attr::DLLImport: return CXCursor_DLLImport;
|
2010-02-18 11:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return CXCursor_UnexposedAttr;
|
|
|
|
}
|
|
|
|
|
2013-01-14 08:46:27 +08:00
|
|
|
CXCursor cxcursor::MakeCXCursor(const Attr *A, const Decl *Parent,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-02-18 11:09:07 +08:00
|
|
|
assert(A && Parent && TU && "Invalid arguments!");
|
2013-01-12 05:06:06 +08:00
|
|
|
CXCursor C = { GetCursorKind(A), 0, { Parent, A, TU } };
|
2010-02-18 11:09:07 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
CXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU,
|
2011-10-06 15:00:54 +08:00
|
|
|
SourceRange RegionOfInterest,
|
2010-11-02 07:26:51 +08:00
|
|
|
bool FirstInDeclGroup) {
|
2010-01-25 08:40:30 +08:00
|
|
|
assert(D && TU && "Invalid arguments!");
|
2011-10-06 15:00:54 +08:00
|
|
|
|
|
|
|
CXCursorKind K = getCursorKindForDecl(D);
|
|
|
|
|
|
|
|
if (K == CXCursor_ObjCClassMethodDecl ||
|
|
|
|
K == CXCursor_ObjCInstanceMethodDecl) {
|
|
|
|
int SelectorIdIndex = -1;
|
|
|
|
// Check if cursor points to a selector id.
|
|
|
|
if (RegionOfInterest.isValid() &&
|
|
|
|
RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
|
|
|
|
SmallVector<SourceLocation, 16> SelLocs;
|
|
|
|
cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs);
|
2013-07-04 11:08:24 +08:00
|
|
|
SmallVectorImpl<SourceLocation>::iterator
|
2011-10-06 15:00:54 +08:00
|
|
|
I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
|
|
|
|
if (I != SelLocs.end())
|
|
|
|
SelectorIdIndex = I - SelLocs.begin();
|
|
|
|
}
|
|
|
|
CXCursor C = { K, SelectorIdIndex,
|
|
|
|
{ D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
|
2010-01-21 07:34:41 +08:00
|
|
|
return C;
|
2010-01-16 08:36:30 +08:00
|
|
|
}
|
|
|
|
|
2013-01-14 08:46:27 +08:00
|
|
|
CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
|
2013-01-12 05:01:49 +08:00
|
|
|
CXTranslationUnit TU,
|
2011-10-06 15:00:54 +08:00
|
|
|
SourceRange RegionOfInterest) {
|
2010-01-25 08:40:30 +08:00
|
|
|
assert(S && TU && "Invalid arguments!");
|
2010-01-20 07:20:36 +08:00
|
|
|
CXCursorKind K = CXCursor_NotImplemented;
|
|
|
|
|
|
|
|
switch (S->getStmtClass()) {
|
|
|
|
case Stmt::NoStmtClass:
|
|
|
|
break;
|
2011-10-06 03:00:14 +08:00
|
|
|
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::CaseStmtClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_CaseStmt;
|
|
|
|
break;
|
|
|
|
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::DefaultStmtClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_DefaultStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::IfStmtClass:
|
|
|
|
K = CXCursor_IfStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::SwitchStmtClass:
|
|
|
|
K = CXCursor_SwitchStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::WhileStmtClass:
|
|
|
|
K = CXCursor_WhileStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::DoStmtClass:
|
|
|
|
K = CXCursor_DoStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ForStmtClass:
|
|
|
|
K = CXCursor_ForStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::GotoStmtClass:
|
|
|
|
K = CXCursor_GotoStmt;
|
|
|
|
break;
|
|
|
|
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::IndirectGotoStmtClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_IndirectGotoStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ContinueStmtClass:
|
|
|
|
K = CXCursor_ContinueStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::BreakStmtClass:
|
|
|
|
K = CXCursor_BreakStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ReturnStmtClass:
|
|
|
|
K = CXCursor_ReturnStmt;
|
|
|
|
break;
|
|
|
|
|
2012-08-25 08:11:56 +08:00
|
|
|
case Stmt::GCCAsmStmtClass:
|
|
|
|
K = CXCursor_GCCAsmStmt;
|
2011-10-06 03:00:14 +08:00
|
|
|
break;
|
2012-06-12 04:47:18 +08:00
|
|
|
|
|
|
|
case Stmt::MSAsmStmtClass:
|
|
|
|
K = CXCursor_MSAsmStmt;
|
|
|
|
break;
|
2011-10-06 03:00:14 +08:00
|
|
|
|
|
|
|
case Stmt::ObjCAtTryStmtClass:
|
|
|
|
K = CXCursor_ObjCAtTryStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCAtCatchStmtClass:
|
|
|
|
K = CXCursor_ObjCAtCatchStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCAtFinallyStmtClass:
|
|
|
|
K = CXCursor_ObjCAtFinallyStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCAtThrowStmtClass:
|
|
|
|
K = CXCursor_ObjCAtThrowStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCAtSynchronizedStmtClass:
|
|
|
|
K = CXCursor_ObjCAtSynchronizedStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCAutoreleasePoolStmtClass:
|
|
|
|
K = CXCursor_ObjCAutoreleasePoolStmt;
|
|
|
|
break;
|
|
|
|
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::ObjCForCollectionStmtClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_ObjCForCollectionStmt;
|
|
|
|
break;
|
|
|
|
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::CXXCatchStmtClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_CXXCatchStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXTryStmtClass:
|
|
|
|
K = CXCursor_CXXTryStmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXForRangeStmtClass:
|
|
|
|
K = CXCursor_CXXForRangeStmt;
|
|
|
|
break;
|
|
|
|
|
2011-04-28 09:08:34 +08:00
|
|
|
case Stmt::SEHTryStmtClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_SEHTryStmt;
|
|
|
|
break;
|
|
|
|
|
2011-04-28 09:08:34 +08:00
|
|
|
case Stmt::SEHExceptStmtClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_SEHExceptStmt;
|
|
|
|
break;
|
|
|
|
|
2011-04-28 09:08:34 +08:00
|
|
|
case Stmt::SEHFinallyStmtClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_SEHFinallyStmt;
|
|
|
|
break;
|
2014-07-07 08:12:30 +08:00
|
|
|
|
|
|
|
case Stmt::SEHLeaveStmtClass:
|
|
|
|
K = CXCursor_SEHLeaveStmt;
|
|
|
|
break;
|
2011-10-06 03:00:14 +08:00
|
|
|
|
|
|
|
case Stmt::ArrayTypeTraitExprClass:
|
|
|
|
case Stmt::AsTypeExprClass:
|
2011-10-11 10:20:01 +08:00
|
|
|
case Stmt::AtomicExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::BinaryConditionalOperatorClass:
|
2012-02-24 15:38:34 +08:00
|
|
|
case Stmt::TypeTraitExprClass:
|
2015-10-27 14:02:45 +08:00
|
|
|
case Stmt::CoroutineBodyStmtClass:
|
|
|
|
case Stmt::CoawaitExprClass:
|
2017-03-07 07:38:15 +08:00
|
|
|
case Stmt::DependentCoawaitExprClass:
|
2015-10-27 14:02:45 +08:00
|
|
|
case Stmt::CoreturnStmtClass:
|
|
|
|
case Stmt::CoyieldExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::CXXBindTemporaryExprClass:
|
|
|
|
case Stmt::CXXDefaultArgExprClass:
|
2013-04-21 06:23:05 +08:00
|
|
|
case Stmt::CXXDefaultInitExprClass:
|
2014-11-08 13:07:16 +08:00
|
|
|
case Stmt::CXXFoldExprClass:
|
2013-06-13 06:31:48 +08:00
|
|
|
case Stmt::CXXStdInitializerListExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::CXXScalarValueInitExprClass:
|
|
|
|
case Stmt::CXXUuidofExprClass:
|
|
|
|
case Stmt::ChooseExprClass:
|
|
|
|
case Stmt::DesignatedInitExprClass:
|
2015-06-10 08:27:52 +08:00
|
|
|
case Stmt::DesignatedInitUpdateExprClass:
|
2016-12-12 10:53:20 +08:00
|
|
|
case Stmt::ArrayInitLoopExprClass:
|
|
|
|
case Stmt::ArrayInitIndexExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::ExprWithCleanupsClass:
|
|
|
|
case Stmt::ExpressionTraitExprClass:
|
|
|
|
case Stmt::ExtVectorElementExprClass:
|
|
|
|
case Stmt::ImplicitCastExprClass:
|
|
|
|
case Stmt::ImplicitValueInitExprClass:
|
2015-06-10 08:27:52 +08:00
|
|
|
case Stmt::NoInitExprClass:
|
2011-06-22 01:03:29 +08:00
|
|
|
case Stmt::MaterializeTemporaryExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::ObjCIndirectCopyRestoreExprClass:
|
|
|
|
case Stmt::OffsetOfExprClass:
|
|
|
|
case Stmt::ParenListExprClass:
|
|
|
|
case Stmt::PredefinedExprClass:
|
|
|
|
case Stmt::ShuffleVectorExprClass:
|
2013-09-18 11:29:45 +08:00
|
|
|
case Stmt::ConvertVectorExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::VAArgExprClass:
|
2012-03-07 04:06:06 +08:00
|
|
|
case Stmt::ObjCArrayLiteralClass:
|
|
|
|
case Stmt::ObjCDictionaryLiteralClass:
|
2012-04-19 08:25:12 +08:00
|
|
|
case Stmt::ObjCBoxedExprClass:
|
2012-03-07 04:06:06 +08:00
|
|
|
case Stmt::ObjCSubscriptRefExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_UnexposedExpr;
|
|
|
|
break;
|
|
|
|
|
2011-11-06 17:01:30 +08:00
|
|
|
case Stmt::OpaqueValueExprClass:
|
|
|
|
if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr())
|
|
|
|
return MakeCXCursor(Src, Parent, TU, RegionOfInterest);
|
|
|
|
K = CXCursor_UnexposedExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::PseudoObjectExprClass:
|
|
|
|
return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(),
|
|
|
|
Parent, TU, RegionOfInterest);
|
|
|
|
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::CompoundStmtClass:
|
|
|
|
K = CXCursor_CompoundStmt;
|
2010-01-20 07:20:36 +08:00
|
|
|
break;
|
2012-04-14 08:33:13 +08:00
|
|
|
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::NullStmtClass:
|
|
|
|
K = CXCursor_NullStmt;
|
2010-09-10 08:22:18 +08:00
|
|
|
break;
|
2012-04-14 08:33:13 +08:00
|
|
|
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::LabelStmtClass:
|
|
|
|
K = CXCursor_LabelStmt;
|
|
|
|
break;
|
2012-04-14 08:33:13 +08:00
|
|
|
|
|
|
|
case Stmt::AttributedStmtClass:
|
|
|
|
K = CXCursor_UnexposedStmt;
|
|
|
|
break;
|
|
|
|
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::DeclStmtClass:
|
|
|
|
K = CXCursor_DeclStmt;
|
|
|
|
break;
|
2012-04-14 08:33:13 +08:00
|
|
|
|
2013-04-17 02:53:08 +08:00
|
|
|
case Stmt::CapturedStmtClass:
|
|
|
|
K = CXCursor_UnexposedStmt;
|
|
|
|
break;
|
|
|
|
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::IntegerLiteralClass:
|
|
|
|
K = CXCursor_IntegerLiteral;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::FloatingLiteralClass:
|
|
|
|
K = CXCursor_FloatingLiteral;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ImaginaryLiteralClass:
|
|
|
|
K = CXCursor_ImaginaryLiteral;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::StringLiteralClass:
|
|
|
|
K = CXCursor_StringLiteral;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CharacterLiteralClass:
|
|
|
|
K = CXCursor_CharacterLiteral;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ParenExprClass:
|
|
|
|
K = CXCursor_ParenExpr;
|
|
|
|
break;
|
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
case Stmt::UnaryOperatorClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_UnaryOperator;
|
|
|
|
break;
|
2012-04-14 08:33:13 +08:00
|
|
|
|
2016-06-10 00:16:06 +08:00
|
|
|
case Stmt::UnaryExprOrTypeTraitExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::CXXNoexceptExprClass:
|
|
|
|
K = CXCursor_UnaryExpr;
|
|
|
|
break;
|
|
|
|
|
2015-11-25 20:01:00 +08:00
|
|
|
case Stmt::MSPropertySubscriptExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::ArraySubscriptExprClass:
|
|
|
|
K = CXCursor_ArraySubscriptExpr;
|
|
|
|
break;
|
|
|
|
|
2015-08-25 22:24:04 +08:00
|
|
|
case Stmt::OMPArraySectionExprClass:
|
|
|
|
K = CXCursor_OMPArraySectionExpr;
|
|
|
|
break;
|
|
|
|
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::BinaryOperatorClass:
|
|
|
|
K = CXCursor_BinaryOperator;
|
|
|
|
break;
|
|
|
|
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::CompoundAssignOperatorClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_CompoundAssignOperator;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ConditionalOperatorClass:
|
|
|
|
K = CXCursor_ConditionalOperator;
|
|
|
|
break;
|
|
|
|
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::CStyleCastExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_CStyleCastExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CompoundLiteralExprClass:
|
|
|
|
K = CXCursor_CompoundLiteralExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::InitListExprClass:
|
|
|
|
K = CXCursor_InitListExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::AddrLabelExprClass:
|
|
|
|
K = CXCursor_AddrLabelExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::StmtExprClass:
|
|
|
|
K = CXCursor_StmtExpr;
|
|
|
|
break;
|
|
|
|
|
2011-04-15 08:35:48 +08:00
|
|
|
case Stmt::GenericSelectionExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_GenericSelectionExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::GNUNullExprClass:
|
|
|
|
K = CXCursor_GNUNullExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXStaticCastExprClass:
|
|
|
|
K = CXCursor_CXXStaticCastExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXDynamicCastExprClass:
|
|
|
|
K = CXCursor_CXXDynamicCastExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXReinterpretCastExprClass:
|
|
|
|
K = CXCursor_CXXReinterpretCastExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXConstCastExprClass:
|
|
|
|
K = CXCursor_CXXConstCastExpr;
|
|
|
|
break;
|
|
|
|
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::CXXFunctionalCastExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_CXXFunctionalCastExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXTypeidExprClass:
|
|
|
|
K = CXCursor_CXXTypeidExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXBoolLiteralExprClass:
|
|
|
|
K = CXCursor_CXXBoolLiteralExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXNullPtrLiteralExprClass:
|
|
|
|
K = CXCursor_CXXNullPtrLiteralExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXThisExprClass:
|
|
|
|
K = CXCursor_CXXThisExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXThrowExprClass:
|
|
|
|
K = CXCursor_CXXThrowExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXNewExprClass:
|
|
|
|
K = CXCursor_CXXNewExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CXXDeleteExprClass:
|
|
|
|
K = CXCursor_CXXDeleteExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCStringLiteralClass:
|
|
|
|
K = CXCursor_ObjCStringLiteral;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCEncodeExprClass:
|
|
|
|
K = CXCursor_ObjCEncodeExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCSelectorExprClass:
|
|
|
|
K = CXCursor_ObjCSelectorExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ObjCProtocolExprClass:
|
|
|
|
K = CXCursor_ObjCProtocolExpr;
|
|
|
|
break;
|
2012-03-07 04:06:06 +08:00
|
|
|
|
|
|
|
case Stmt::ObjCBoolLiteralExprClass:
|
|
|
|
K = CXCursor_ObjCBoolLiteralExpr;
|
|
|
|
break;
|
2016-07-16 08:35:23 +08:00
|
|
|
|
|
|
|
case Stmt::ObjCAvailabilityCheckExprClass:
|
|
|
|
K = CXCursor_ObjCAvailabilityCheckExpr;
|
|
|
|
break;
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
case Stmt::ObjCBridgedCastExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_ObjCBridgedCastExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::BlockExprClass:
|
|
|
|
K = CXCursor_BlockExpr;
|
|
|
|
break;
|
|
|
|
|
2011-01-04 01:17:50 +08:00
|
|
|
case Stmt::PackExpansionExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_PackExpansionExpr;
|
|
|
|
break;
|
|
|
|
|
2011-01-05 01:33:58 +08:00
|
|
|
case Stmt::SizeOfPackExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
K = CXCursor_SizeOfPackExpr;
|
2010-01-20 07:20:36 +08:00
|
|
|
break;
|
2011-10-06 03:00:14 +08:00
|
|
|
|
2013-04-24 01:57:17 +08:00
|
|
|
case Stmt::DeclRefExprClass:
|
|
|
|
if (const ImplicitParamDecl *IPD =
|
|
|
|
dyn_cast_or_null<ImplicitParamDecl>(cast<DeclRefExpr>(S)->getDecl())) {
|
|
|
|
if (const ObjCMethodDecl *MD =
|
|
|
|
dyn_cast<ObjCMethodDecl>(IPD->getDeclContext())) {
|
|
|
|
if (MD->getSelfDecl() == IPD) {
|
|
|
|
K = CXCursor_ObjCSelfExpr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
K = CXCursor_DeclRefExpr;
|
|
|
|
break;
|
|
|
|
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::DependentScopeDeclRefExprClass:
|
2011-07-15 13:09:51 +08:00
|
|
|
case Stmt::SubstNonTypeTemplateParmExprClass:
|
2011-01-15 09:15:58 +08:00
|
|
|
case Stmt::SubstNonTypeTemplateParmPackExprClass:
|
2012-09-12 08:56:43 +08:00
|
|
|
case Stmt::FunctionParmPackExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::UnresolvedLookupExprClass:
|
2014-10-28 02:07:20 +08:00
|
|
|
case Stmt::TypoExprClass: // A typo could actually be a DeclRef or a MemberRef
|
2010-01-20 07:20:36 +08:00
|
|
|
K = CXCursor_DeclRefExpr;
|
|
|
|
break;
|
|
|
|
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::CXXDependentScopeMemberExprClass:
|
|
|
|
case Stmt::CXXPseudoDestructorExprClass:
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::MemberExprClass:
|
2013-04-16 15:28:30 +08:00
|
|
|
case Stmt::MSPropertyRefExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::ObjCIsaExprClass:
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::ObjCIvarRefExprClass:
|
|
|
|
case Stmt::ObjCPropertyRefExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::UnresolvedMemberExprClass:
|
2010-01-20 07:20:36 +08:00
|
|
|
K = CXCursor_MemberRefExpr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::CallExprClass:
|
|
|
|
case Stmt::CXXOperatorCallExprClass:
|
|
|
|
case Stmt::CXXMemberCallExprClass:
|
2011-02-10 05:07:24 +08:00
|
|
|
case Stmt::CUDAKernelCallExprClass:
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::CXXConstructExprClass:
|
P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:
Replace inheriting constructors implementation with new approach, voted into
C++ last year as a DR against C++11.
Instead of synthesizing a set of derived class constructors for each inherited
base class constructor, we make the constructors of the base class visible to
constructor lookup in the derived class, using the normal rules for
using-declarations.
For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived
class that tracks the requisite additional information. We create shadow
constructors (not found by name lookup) in the derived class to model the
actual initialization, and have a new expression node,
CXXInheritedCtorInitExpr, to model the initialization of a base class from such
a constructor. (This initialization is special because it performs real perfect
forwarding of arguments.)
In cases where argument forwarding is not possible (for inalloca calls,
variadic calls, and calls with callee parameter cleanup), the shadow inheriting
constructor is not emitted and instead we directly emit the initialization code
into the caller of the inherited constructor.
Note that this new model is not perfectly compatible with the old model in some
corner cases. In particular:
* if B inherits a private constructor from A, and C uses that constructor to
construct a B, then we previously required that A befriends B and B
befriends C, but the new rules require A to befriend C directly, and
* if a derived class has its own constructors (and so its implicit default
constructor is suppressed), it may still inherit a default constructor from
a base class
llvm-svn: 274049
2016-06-29 03:03:57 +08:00
|
|
|
case Stmt::CXXInheritedCtorInitExprClass:
|
2010-01-20 07:20:36 +08:00
|
|
|
case Stmt::CXXTemporaryObjectExprClass:
|
2011-10-06 03:00:14 +08:00
|
|
|
case Stmt::CXXUnresolvedConstructExprClass:
|
2012-03-07 16:35:16 +08:00
|
|
|
case Stmt::UserDefinedLiteralClass:
|
2010-01-20 07:20:36 +08:00
|
|
|
K = CXCursor_CallExpr;
|
|
|
|
break;
|
|
|
|
|
2012-02-15 08:54:55 +08:00
|
|
|
case Stmt::LambdaExprClass:
|
|
|
|
K = CXCursor_LambdaExpr;
|
|
|
|
break;
|
|
|
|
|
2011-10-25 09:33:02 +08:00
|
|
|
case Stmt::ObjCMessageExprClass: {
|
2010-01-20 07:20:36 +08:00
|
|
|
K = CXCursor_ObjCMessageExpr;
|
2011-10-06 15:00:54 +08:00
|
|
|
int SelectorIdIndex = -1;
|
|
|
|
// Check if cursor points to a selector id.
|
|
|
|
if (RegionOfInterest.isValid() &&
|
|
|
|
RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
|
|
|
|
SmallVector<SourceLocation, 16> SelLocs;
|
|
|
|
cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs);
|
2013-07-04 11:08:24 +08:00
|
|
|
SmallVectorImpl<SourceLocation>::iterator
|
2011-10-06 15:00:54 +08:00
|
|
|
I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
|
|
|
|
if (I != SelLocs.end())
|
|
|
|
SelectorIdIndex = I - SelLocs.begin();
|
|
|
|
}
|
|
|
|
CXCursor C = { K, 0, { Parent, S, TU } };
|
|
|
|
return getSelectorIdentifierCursor(SelectorIdIndex, C);
|
2010-01-20 07:20:36 +08:00
|
|
|
}
|
2011-10-25 09:33:02 +08:00
|
|
|
|
|
|
|
case Stmt::MSDependentExistsStmtClass:
|
|
|
|
K = CXCursor_UnexposedStmt;
|
|
|
|
break;
|
2013-07-19 11:13:43 +08:00
|
|
|
case Stmt::OMPParallelDirectiveClass:
|
|
|
|
K = CXCursor_OMPParallelDirective;
|
|
|
|
break;
|
2014-02-27 16:29:12 +08:00
|
|
|
case Stmt::OMPSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPSimdDirective;
|
|
|
|
break;
|
2014-06-18 12:14:57 +08:00
|
|
|
case Stmt::OMPForDirectiveClass:
|
|
|
|
K = CXCursor_OMPForDirective;
|
|
|
|
break;
|
2014-09-18 13:12:34 +08:00
|
|
|
case Stmt::OMPForSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPForSimdDirective;
|
|
|
|
break;
|
2014-06-25 19:44:49 +08:00
|
|
|
case Stmt::OMPSectionsDirectiveClass:
|
|
|
|
K = CXCursor_OMPSectionsDirective;
|
|
|
|
break;
|
2014-06-26 16:21:58 +08:00
|
|
|
case Stmt::OMPSectionDirectiveClass:
|
|
|
|
K = CXCursor_OMPSectionDirective;
|
|
|
|
break;
|
2014-06-26 20:05:45 +08:00
|
|
|
case Stmt::OMPSingleDirectiveClass:
|
|
|
|
K = CXCursor_OMPSingleDirective;
|
|
|
|
break;
|
2014-07-17 16:54:58 +08:00
|
|
|
case Stmt::OMPMasterDirectiveClass:
|
|
|
|
K = CXCursor_OMPMasterDirective;
|
|
|
|
break;
|
2014-07-21 17:42:05 +08:00
|
|
|
case Stmt::OMPCriticalDirectiveClass:
|
|
|
|
K = CXCursor_OMPCriticalDirective;
|
|
|
|
break;
|
2014-07-07 21:01:15 +08:00
|
|
|
case Stmt::OMPParallelForDirectiveClass:
|
|
|
|
K = CXCursor_OMPParallelForDirective;
|
|
|
|
break;
|
2014-09-23 17:33:00 +08:00
|
|
|
case Stmt::OMPParallelForSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPParallelForSimdDirective;
|
|
|
|
break;
|
2014-07-08 16:12:03 +08:00
|
|
|
case Stmt::OMPParallelSectionsDirectiveClass:
|
|
|
|
K = CXCursor_OMPParallelSectionsDirective;
|
|
|
|
break;
|
2014-07-11 19:25:16 +08:00
|
|
|
case Stmt::OMPTaskDirectiveClass:
|
|
|
|
K = CXCursor_OMPTaskDirective;
|
|
|
|
break;
|
2014-07-18 15:47:19 +08:00
|
|
|
case Stmt::OMPTaskyieldDirectiveClass:
|
|
|
|
K = CXCursor_OMPTaskyieldDirective;
|
|
|
|
break;
|
2014-07-18 17:11:51 +08:00
|
|
|
case Stmt::OMPBarrierDirectiveClass:
|
|
|
|
K = CXCursor_OMPBarrierDirective;
|
|
|
|
break;
|
2014-07-18 18:17:07 +08:00
|
|
|
case Stmt::OMPTaskwaitDirectiveClass:
|
|
|
|
K = CXCursor_OMPTaskwaitDirective;
|
|
|
|
break;
|
2015-06-18 20:14:09 +08:00
|
|
|
case Stmt::OMPTaskgroupDirectiveClass:
|
|
|
|
K = CXCursor_OMPTaskgroupDirective;
|
|
|
|
break;
|
2014-07-21 19:26:11 +08:00
|
|
|
case Stmt::OMPFlushDirectiveClass:
|
|
|
|
K = CXCursor_OMPFlushDirective;
|
|
|
|
break;
|
2014-07-22 14:45:04 +08:00
|
|
|
case Stmt::OMPOrderedDirectiveClass:
|
|
|
|
K = CXCursor_OMPOrderedDirective;
|
|
|
|
break;
|
2014-07-22 18:10:35 +08:00
|
|
|
case Stmt::OMPAtomicDirectiveClass:
|
|
|
|
K = CXCursor_OMPAtomicDirective;
|
|
|
|
break;
|
2014-09-19 16:19:49 +08:00
|
|
|
case Stmt::OMPTargetDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetDirective;
|
|
|
|
break;
|
2015-07-21 21:44:28 +08:00
|
|
|
case Stmt::OMPTargetDataDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetDataDirective;
|
|
|
|
break;
|
2016-01-20 03:15:56 +08:00
|
|
|
case Stmt::OMPTargetEnterDataDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetEnterDataDirective;
|
|
|
|
break;
|
2016-01-20 04:04:50 +08:00
|
|
|
case Stmt::OMPTargetExitDataDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetExitDataDirective;
|
|
|
|
break;
|
2016-01-27 02:48:41 +08:00
|
|
|
case Stmt::OMPTargetParallelDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetParallelDirective;
|
|
|
|
break;
|
2016-02-03 23:46:42 +08:00
|
|
|
case Stmt::OMPTargetParallelForDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetParallelForDirective;
|
|
|
|
break;
|
2016-05-27 01:30:50 +08:00
|
|
|
case Stmt::OMPTargetUpdateDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetUpdateDirective;
|
|
|
|
break;
|
2014-10-09 12:18:56 +08:00
|
|
|
case Stmt::OMPTeamsDirectiveClass:
|
|
|
|
K = CXCursor_OMPTeamsDirective;
|
|
|
|
break;
|
2015-07-01 14:57:41 +08:00
|
|
|
case Stmt::OMPCancellationPointDirectiveClass:
|
|
|
|
K = CXCursor_OMPCancellationPointDirective;
|
|
|
|
break;
|
2015-07-02 19:25:17 +08:00
|
|
|
case Stmt::OMPCancelDirectiveClass:
|
|
|
|
K = CXCursor_OMPCancelDirective;
|
|
|
|
break;
|
2015-12-01 12:18:41 +08:00
|
|
|
case Stmt::OMPTaskLoopDirectiveClass:
|
|
|
|
K = CXCursor_OMPTaskLoopDirective;
|
|
|
|
break;
|
2015-12-03 17:40:15 +08:00
|
|
|
case Stmt::OMPTaskLoopSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPTaskLoopSimdDirective;
|
|
|
|
break;
|
2015-12-14 22:51:25 +08:00
|
|
|
case Stmt::OMPDistributeDirectiveClass:
|
|
|
|
K = CXCursor_OMPDistributeDirective;
|
|
|
|
break;
|
2016-06-27 22:55:37 +08:00
|
|
|
case Stmt::OMPDistributeParallelForDirectiveClass:
|
|
|
|
K = CXCursor_OMPDistributeParallelForDirective;
|
|
|
|
break;
|
2016-07-05 13:00:15 +08:00
|
|
|
case Stmt::OMPDistributeParallelForSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPDistributeParallelForSimdDirective;
|
2016-07-06 12:45:38 +08:00
|
|
|
break;
|
|
|
|
case Stmt::OMPDistributeSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPDistributeSimdDirective;
|
2016-07-14 10:54:56 +08:00
|
|
|
break;
|
|
|
|
case Stmt::OMPTargetParallelForSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetParallelForSimdDirective;
|
2016-07-21 06:57:10 +08:00
|
|
|
break;
|
|
|
|
case Stmt::OMPTargetSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetSimdDirective;
|
2016-07-05 13:00:15 +08:00
|
|
|
break;
|
2016-08-05 22:37:37 +08:00
|
|
|
case Stmt::OMPTeamsDistributeDirectiveClass:
|
|
|
|
K = CXCursor_OMPTeamsDistributeDirective;
|
|
|
|
break;
|
2016-10-25 20:50:55 +08:00
|
|
|
case Stmt::OMPTeamsDistributeSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPTeamsDistributeSimdDirective;
|
2016-12-01 07:51:03 +08:00
|
|
|
break;
|
|
|
|
case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPTeamsDistributeParallelForSimdDirective;
|
2016-10-25 20:50:55 +08:00
|
|
|
break;
|
2016-12-09 11:24:30 +08:00
|
|
|
case Stmt::OMPTeamsDistributeParallelForDirectiveClass:
|
|
|
|
K = CXCursor_OMPTeamsDistributeParallelForDirective;
|
|
|
|
break;
|
2016-12-17 13:48:59 +08:00
|
|
|
case Stmt::OMPTargetTeamsDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetTeamsDirective;
|
|
|
|
break;
|
2016-12-25 12:52:54 +08:00
|
|
|
case Stmt::OMPTargetTeamsDistributeDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetTeamsDistributeDirective;
|
|
|
|
break;
|
2016-12-30 06:16:30 +08:00
|
|
|
case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetTeamsDistributeParallelForDirective;
|
|
|
|
break;
|
2017-01-03 13:23:48 +08:00
|
|
|
case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective;
|
|
|
|
break;
|
2017-01-11 02:08:18 +08:00
|
|
|
case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
|
|
|
|
K = CXCursor_OMPTargetTeamsDistributeSimdDirective;
|
|
|
|
break;
|
2011-10-25 09:33:02 +08:00
|
|
|
}
|
2014-02-27 16:29:12 +08:00
|
|
|
|
2011-10-06 15:00:54 +08:00
|
|
|
CXCursor C = { K, 0, { Parent, S, TU } };
|
2010-01-20 07:20:36 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2010-01-16 22:00:32 +08:00
|
|
|
CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
|
2010-01-21 07:57:43 +08:00
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-01-25 08:40:30 +08:00
|
|
|
assert(Super && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2011-10-06 15:00:54 +08:00
|
|
|
CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } };
|
2010-01-16 22:00:32 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCInterfaceDecl *, SourceLocation>
|
2010-01-16 22:00:32 +08:00
|
|
|
cxcursor::getCursorObjCSuperClassRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_ObjCSuperClassRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-01-16 22:00:32 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
|
2010-01-21 07:57:43 +08:00
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2011-10-18 03:48:19 +08:00
|
|
|
assert(Proto && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2013-01-12 05:06:06 +08:00
|
|
|
CXCursor C = { CXCursor_ObjCProtocolRef, 0, { Proto, RawLoc, TU } };
|
2010-01-16 23:44:18 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCProtocolDecl *, SourceLocation>
|
2010-01-16 23:44:18 +08:00
|
|
|
cxcursor::getCursorObjCProtocolRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_ObjCProtocolRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-01-16 23:44:18 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
|
2010-01-21 07:57:43 +08:00
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-03-20 04:39:03 +08:00
|
|
|
// 'Class' can be null for invalid code.
|
|
|
|
if (!Class)
|
|
|
|
return MakeCXCursorInvalid(CXCursor_InvalidCode);
|
|
|
|
assert(TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2013-01-12 05:06:06 +08:00
|
|
|
CXCursor C = { CXCursor_ObjCClassRef, 0, { Class, RawLoc, TU } };
|
2010-01-17 01:14:40 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCInterfaceDecl *, SourceLocation>
|
2010-01-17 01:14:40 +08:00
|
|
|
cxcursor::getCursorObjCClassRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_ObjCClassRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-01-17 01:14:40 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 03:48:19 +08:00
|
|
|
CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-01-25 08:40:30 +08:00
|
|
|
assert(Type && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2013-01-12 05:06:06 +08:00
|
|
|
CXCursor C = { CXCursor_TypeRef, 0, { Type, RawLoc, TU } };
|
2010-01-22 00:28:34 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const TypeDecl *, SourceLocation>
|
2010-01-22 00:28:34 +08:00
|
|
|
cxcursor::getCursorTypeRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_TypeRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const TypeDecl *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-01-22 00:28:34 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template,
|
2010-11-16 16:15:36 +08:00
|
|
|
SourceLocation Loc,
|
|
|
|
CXTranslationUnit TU) {
|
2010-09-01 04:37:03 +08:00
|
|
|
assert(Template && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2013-01-12 05:06:06 +08:00
|
|
|
CXCursor C = { CXCursor_TemplateRef, 0, { Template, RawLoc, TU } };
|
2010-09-01 04:37:03 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const TemplateDecl *, SourceLocation>
|
2010-09-01 04:37:03 +08:00
|
|
|
cxcursor::getCursorTemplateRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_TemplateRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-09-01 04:37:03 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS,
|
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-09-01 07:48:11 +08:00
|
|
|
|
|
|
|
assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU &&
|
|
|
|
"Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2013-01-12 05:06:06 +08:00
|
|
|
CXCursor C = { CXCursor_NamespaceRef, 0, { NS, RawLoc, TU } };
|
2010-09-01 07:48:11 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const NamedDecl *, SourceLocation>
|
2010-09-01 07:48:11 +08:00
|
|
|
cxcursor::getCursorNamespaceRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_NamespaceRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const NamedDecl *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-09-01 07:48:11 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 08:54:55 +08:00
|
|
|
CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
|
|
|
|
CXTranslationUnit TU) {
|
|
|
|
|
|
|
|
assert(Var && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2013-01-12 05:06:06 +08:00
|
|
|
CXCursor C = { CXCursor_VariableRef, 0, { Var, RawLoc, TU } };
|
2012-02-15 08:54:55 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const VarDecl *, SourceLocation>
|
2012-02-15 08:54:55 +08:00
|
|
|
cxcursor::getCursorVariableRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_VariableRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const VarDecl *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2012-02-15 08:54:55 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 08:26:51 +08:00
|
|
|
CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-09-10 05:42:20 +08:00
|
|
|
|
|
|
|
assert(Field && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2013-01-12 05:06:06 +08:00
|
|
|
CXCursor C = { CXCursor_MemberRef, 0, { Field, RawLoc, TU } };
|
2010-09-10 05:42:20 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const FieldDecl *, SourceLocation>
|
2010-09-10 05:42:20 +08:00
|
|
|
cxcursor::getCursorMemberRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_MemberRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const FieldDecl *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-09-10 05:42:20 +08:00
|
|
|
}
|
|
|
|
|
2011-11-22 15:24:51 +08:00
|
|
|
CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU){
|
2014-06-08 16:38:04 +08:00
|
|
|
CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, nullptr, TU } };
|
2010-08-28 05:34:58 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
const CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
|
2010-08-28 05:34:58 +08:00
|
|
|
assert(C.kind == CXCursor_CXXBaseSpecifier);
|
2013-01-12 05:01:49 +08:00
|
|
|
return static_cast<const CXXBaseSpecifier*>(C.data[0]);
|
2010-08-28 05:34:58 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 08:42:48 +08:00
|
|
|
CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2011-10-06 15:00:54 +08:00
|
|
|
CXCursor C = { CXCursor_PreprocessingDirective, 0,
|
2013-02-16 09:07:48 +08:00
|
|
|
{ Range.getBegin().getPtrEncoding(),
|
|
|
|
Range.getEnd().getPtrEncoding(),
|
2010-03-18 08:42:48 +08:00
|
|
|
TU }
|
|
|
|
};
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_PreprocessingDirective);
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]),
|
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2011-09-26 16:01:41 +08:00
|
|
|
ASTUnit *TU = getCursorASTUnit(C);
|
|
|
|
return TU->mapRangeFromPreamble(Range);
|
2010-03-18 23:23:44 +08:00
|
|
|
}
|
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinitionRecord *MI,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2015-05-04 10:25:31 +08:00
|
|
|
CXCursor C = {CXCursor_MacroDefinition, 0, {MI, nullptr, TU}};
|
2010-03-19 02:04:21 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
const MacroDefinitionRecord *cxcursor::getCursorMacroDefinition(CXCursor C) {
|
2010-03-19 02:04:21 +08:00
|
|
|
assert(C.kind == CXCursor_MacroDefinition);
|
2015-05-04 10:25:31 +08:00
|
|
|
return static_cast<const MacroDefinitionRecord *>(C.data[0]);
|
2010-03-19 02:04:21 +08:00
|
|
|
}
|
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
|
2011-07-14 16:20:46 +08:00
|
|
|
CXTranslationUnit TU) {
|
2014-06-08 16:38:04 +08:00
|
|
|
CXCursor C = { CXCursor_MacroExpansion, 0, { MI, nullptr, TU } };
|
2010-03-18 23:23:44 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinitionRecord *MI,
|
2013-01-08 03:16:25 +08:00
|
|
|
SourceLocation Loc,
|
|
|
|
CXTranslationUnit TU) {
|
|
|
|
assert(Loc.isValid());
|
2015-05-04 10:25:31 +08:00
|
|
|
CXCursor C = {CXCursor_MacroExpansion, 0, {MI, Loc.getPtrEncoding(), TU}};
|
2013-01-08 03:16:25 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
const IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const {
|
|
|
|
if (isPseudo())
|
|
|
|
return getAsMacroDefinition()->getName();
|
|
|
|
return getAsMacroExpansion()->getName();
|
|
|
|
}
|
2015-05-04 10:25:31 +08:00
|
|
|
const MacroDefinitionRecord *
|
|
|
|
cxcursor::MacroExpansionCursor::getDefinition() const {
|
2013-01-08 03:16:25 +08:00
|
|
|
if (isPseudo())
|
|
|
|
return getAsMacroDefinition();
|
|
|
|
return getAsMacroExpansion()->getDefinition();
|
|
|
|
}
|
|
|
|
SourceRange cxcursor::MacroExpansionCursor::getSourceRange() const {
|
|
|
|
if (isPseudo())
|
|
|
|
return getPseudoLoc();
|
|
|
|
return getAsMacroExpansion()->getSourceRange();
|
2010-03-18 08:42:48 +08:00
|
|
|
}
|
|
|
|
|
2010-10-21 06:00:55 +08:00
|
|
|
CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2014-06-08 16:38:04 +08:00
|
|
|
CXCursor C = { CXCursor_InclusionDirective, 0, { ID, nullptr, TU } };
|
2010-10-21 06:00:55 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
const InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
|
2010-10-21 06:00:55 +08:00
|
|
|
assert(C.kind == CXCursor_InclusionDirective);
|
2013-01-12 05:01:49 +08:00
|
|
|
return static_cast<const InclusionDirective *>(C.data[0]);
|
2010-10-21 06:00:55 +08:00
|
|
|
}
|
|
|
|
|
2010-09-10 08:22:18 +08:00
|
|
|
CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-09-10 08:22:18 +08:00
|
|
|
|
|
|
|
assert(Label && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2011-10-06 15:00:54 +08:00
|
|
|
CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } };
|
2010-09-10 08:22:18 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const LabelStmt *, SourceLocation>
|
2010-09-10 08:22:18 +08:00
|
|
|
cxcursor::getCursorLabelRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_LabelRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(static_cast<const LabelStmt *>(C.data[0]),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-09-10 08:22:18 +08:00
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
CXCursor cxcursor::MakeCursorOverloadedDeclRef(const OverloadExpr *E,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-09-14 06:52:57 +08:00
|
|
|
assert(E && TU && "Invalid arguments!");
|
|
|
|
OverloadedDeclRefStorage Storage(E);
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = E->getNameLoc().getPtrEncoding();
|
2010-09-14 06:52:57 +08:00
|
|
|
CXCursor C = {
|
2011-10-06 15:00:54 +08:00
|
|
|
CXCursor_OverloadedDeclRef, 0,
|
2010-09-14 06:52:57 +08:00
|
|
|
{ Storage.getOpaqueValue(), RawLoc, TU }
|
|
|
|
};
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
CXCursor cxcursor::MakeCursorOverloadedDeclRef(const Decl *D,
|
2010-09-14 06:52:57 +08:00
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-09-14 06:52:57 +08:00
|
|
|
assert(D && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2010-09-14 06:52:57 +08:00
|
|
|
OverloadedDeclRefStorage Storage(D);
|
|
|
|
CXCursor C = {
|
2011-10-06 15:00:54 +08:00
|
|
|
CXCursor_OverloadedDeclRef, 0,
|
2010-09-14 06:52:57 +08:00
|
|
|
{ Storage.getOpaqueValue(), RawLoc, TU }
|
|
|
|
};
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
|
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU) {
|
2010-09-14 06:52:57 +08:00
|
|
|
assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!");
|
2013-02-16 09:07:48 +08:00
|
|
|
void *RawLoc = Loc.getPtrEncoding();
|
2010-09-14 06:52:57 +08:00
|
|
|
OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate());
|
|
|
|
CXCursor C = {
|
2011-10-06 15:00:54 +08:00
|
|
|
CXCursor_OverloadedDeclRef, 0,
|
2010-09-14 06:52:57 +08:00
|
|
|
{ Storage.getOpaqueValue(), RawLoc, TU }
|
|
|
|
};
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
|
|
|
|
cxcursor::getCursorOverloadedDeclRef(CXCursor C) {
|
|
|
|
assert(C.kind == CXCursor_OverloadedDeclRef);
|
2013-01-12 05:01:49 +08:00
|
|
|
return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(
|
|
|
|
const_cast<void *>(C.data[0])),
|
2013-02-15 04:07:36 +08:00
|
|
|
SourceLocation::getFromPtrEncoding(C.data[1]));
|
2010-09-14 06:52:57 +08:00
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
|
|
|
|
return static_cast<const Decl *>(Cursor.data[0]);
|
2010-01-16 05:56:13 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
const Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
|
2010-01-16 05:56:13 +08:00
|
|
|
return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
const Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
|
2010-01-16 23:44:18 +08:00
|
|
|
if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
|
2010-01-17 01:14:40 +08:00
|
|
|
Cursor.kind == CXCursor_ObjCProtocolRef ||
|
|
|
|
Cursor.kind == CXCursor_ObjCClassRef)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2010-01-16 22:00:32 +08:00
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
return static_cast<const Stmt *>(Cursor.data[1]);
|
2010-01-16 05:56:13 +08:00
|
|
|
}
|
|
|
|
|
2013-01-27 02:08:08 +08:00
|
|
|
const Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
|
|
|
|
return static_cast<const Attr *>(Cursor.data[1]);
|
2010-08-26 09:42:22 +08:00
|
|
|
}
|
|
|
|
|
2013-01-27 02:12:08 +08:00
|
|
|
const Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
|
|
|
|
return static_cast<const Decl *>(Cursor.data[0]);
|
2011-06-30 06:20:07 +08:00
|
|
|
}
|
|
|
|
|
2010-01-19 07:41:10 +08:00
|
|
|
ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
|
2010-01-21 07:57:43 +08:00
|
|
|
return getCursorASTUnit(Cursor)->getASTContext();
|
|
|
|
}
|
2010-01-20 07:20:36 +08:00
|
|
|
|
2010-01-21 07:57:43 +08:00
|
|
|
ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
|
2013-01-12 03:28:44 +08:00
|
|
|
CXTranslationUnit TU = getCursorTU(Cursor);
|
2011-12-09 08:17:49 +08:00
|
|
|
if (!TU)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-27 02:53:38 +08:00
|
|
|
return cxtu::getASTUnit(TU);
|
2010-11-16 16:15:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
|
2013-01-12 05:01:49 +08:00
|
|
|
return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2]));
|
2010-01-16 05:56:13 +08:00
|
|
|
}
|
|
|
|
|
2012-05-10 00:12:57 +08:00
|
|
|
void cxcursor::getOverriddenCursors(CXCursor cursor,
|
|
|
|
SmallVectorImpl<CXCursor> &overridden) {
|
|
|
|
assert(clang_isDeclaration(cursor.kind));
|
2012-10-09 09:23:50 +08:00
|
|
|
const NamedDecl *D = dyn_cast_or_null<NamedDecl>(getCursorDecl(cursor));
|
2012-05-10 00:12:57 +08:00
|
|
|
if (!D)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CXTranslationUnit TU = getCursorTU(cursor);
|
2012-10-09 09:23:50 +08:00
|
|
|
SmallVector<const NamedDecl *, 8> OverDecls;
|
|
|
|
D->getASTContext().getOverriddenMethods(D, OverDecls);
|
2012-05-10 00:12:57 +08:00
|
|
|
|
2013-07-04 11:08:24 +08:00
|
|
|
for (SmallVectorImpl<const NamedDecl *>::iterator
|
2012-10-09 09:23:50 +08:00
|
|
|
I = OverDecls.begin(), E = OverDecls.end(); I != E; ++I) {
|
2013-01-14 08:46:27 +08:00
|
|
|
overridden.push_back(MakeCXCursor(*I, TU));
|
2012-05-10 00:12:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-06 15:00:54 +08:00
|
|
|
std::pair<int, SourceLocation>
|
|
|
|
cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) {
|
|
|
|
if (cursor.kind == CXCursor_ObjCMessageExpr) {
|
|
|
|
if (cursor.xdata != -1)
|
|
|
|
return std::make_pair(cursor.xdata,
|
|
|
|
cast<ObjCMessageExpr>(getCursorExpr(cursor))
|
|
|
|
->getSelectorLoc(cursor.xdata));
|
|
|
|
} else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
|
|
|
|
cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
|
|
|
|
if (cursor.xdata != -1)
|
|
|
|
return std::make_pair(cursor.xdata,
|
|
|
|
cast<ObjCMethodDecl>(getCursorDecl(cursor))
|
|
|
|
->getSelectorLoc(cursor.xdata));
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair(-1, SourceLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) {
|
|
|
|
CXCursor newCursor = cursor;
|
|
|
|
|
|
|
|
if (cursor.kind == CXCursor_ObjCMessageExpr) {
|
|
|
|
if (SelIdx == -1 ||
|
|
|
|
unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor))
|
|
|
|
->getNumSelectorLocs())
|
|
|
|
newCursor.xdata = -1;
|
|
|
|
else
|
|
|
|
newCursor.xdata = SelIdx;
|
|
|
|
} else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
|
|
|
|
cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
|
|
|
|
if (SelIdx == -1 ||
|
|
|
|
unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor))
|
|
|
|
->getNumSelectorLocs())
|
|
|
|
newCursor.xdata = -1;
|
|
|
|
else
|
|
|
|
newCursor.xdata = SelIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) {
|
|
|
|
if (cursor.kind != CXCursor_CallExpr)
|
|
|
|
return cursor;
|
|
|
|
|
|
|
|
if (cursor.xdata == 0)
|
|
|
|
return cursor;
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
const Expr *E = getCursorExpr(cursor);
|
2014-06-08 16:38:04 +08:00
|
|
|
TypeSourceInfo *Type = nullptr;
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const CXXUnresolvedConstructExpr *
|
2011-10-06 15:00:54 +08:00
|
|
|
UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
|
|
|
|
Type = UnCtor->getTypeSourceInfo();
|
2013-01-26 23:29:08 +08:00
|
|
|
} else if (const CXXTemporaryObjectExpr *Tmp =
|
|
|
|
dyn_cast<CXXTemporaryObjectExpr>(E)){
|
2011-10-06 15:00:54 +08:00
|
|
|
Type = Tmp->getTypeSourceInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Type)
|
|
|
|
return cursor;
|
|
|
|
|
|
|
|
CXTranslationUnit TU = getCursorTU(cursor);
|
|
|
|
QualType Ty = Type->getType();
|
|
|
|
TypeLoc TL = Type->getTypeLoc();
|
|
|
|
SourceLocation Loc = TL.getBeginLoc();
|
|
|
|
|
|
|
|
if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) {
|
|
|
|
Ty = ElabT->getNamedType();
|
2013-02-19 06:06:02 +08:00
|
|
|
ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>();
|
2011-10-06 15:00:54 +08:00
|
|
|
Loc = ElabTL.getNamedTypeLoc().getBeginLoc();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const TypedefType *Typedef = Ty->getAs<TypedefType>())
|
|
|
|
return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU);
|
|
|
|
if (const TagType *Tag = Ty->getAs<TagType>())
|
|
|
|
return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
|
|
|
|
if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>())
|
|
|
|
return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
|
|
|
|
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
2010-01-16 05:56:13 +08:00
|
|
|
bool cxcursor::operator==(CXCursor X, CXCursor Y) {
|
|
|
|
return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] &&
|
|
|
|
X.data[2] == Y.data[2];
|
2010-01-16 22:00:32 +08:00
|
|
|
}
|
2010-11-02 07:26:51 +08:00
|
|
|
|
|
|
|
// FIXME: Remove once we can model DeclGroups and their appropriate ranges
|
|
|
|
// properly in the ASTs.
|
|
|
|
bool cxcursor::isFirstInDeclGroup(CXCursor C) {
|
|
|
|
assert(clang_isDeclaration(C.kind));
|
|
|
|
return ((uintptr_t) (C.data[1])) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-27 08:30:30 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// libclang CXCursor APIs
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-09-27 12:14:36 +08:00
|
|
|
int clang_Cursor_isNull(CXCursor cursor) {
|
|
|
|
return clang_equalCursors(cursor, clang_getNullCursor());
|
|
|
|
}
|
|
|
|
|
2011-09-27 08:30:30 +08:00
|
|
|
CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) {
|
|
|
|
return getCursorTU(cursor);
|
|
|
|
}
|
|
|
|
|
2012-04-12 03:32:19 +08:00
|
|
|
int clang_Cursor_getNumArguments(CXCursor C) {
|
|
|
|
if (clang_isDeclaration(C.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
2012-04-12 03:32:19 +08:00
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
|
|
|
|
return MD->param_size();
|
|
|
|
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
|
|
|
|
return FD->param_size();
|
|
|
|
}
|
|
|
|
|
2013-04-02 01:38:59 +08:00
|
|
|
if (clang_isExpression(C.kind)) {
|
|
|
|
const Expr *E = cxcursor::getCursorExpr(C);
|
|
|
|
if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
|
|
|
|
return CE->getNumArgs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 03:32:19 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) {
|
|
|
|
if (clang_isDeclaration(C.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
|
2012-04-12 03:32:19 +08:00
|
|
|
if (i < MD->param_size())
|
2014-07-07 17:02:20 +08:00
|
|
|
return cxcursor::MakeCXCursor(MD->parameters()[i],
|
2012-04-12 03:32:19 +08:00
|
|
|
cxcursor::getCursorTU(C));
|
2013-01-24 01:25:27 +08:00
|
|
|
} else if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
|
2012-04-12 03:32:19 +08:00
|
|
|
if (i < FD->param_size())
|
2014-07-07 17:02:20 +08:00
|
|
|
return cxcursor::MakeCXCursor(FD->parameters()[i],
|
2012-04-12 03:32:19 +08:00
|
|
|
cxcursor::getCursorTU(C));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-02 01:38:59 +08:00
|
|
|
if (clang_isExpression(C.kind)) {
|
|
|
|
const Expr *E = cxcursor::getCursorExpr(C);
|
|
|
|
if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
|
|
|
|
if (i < CE->getNumArgs()) {
|
|
|
|
return cxcursor::MakeCXCursor(CE->getArg(i),
|
|
|
|
getCursorDecl(C),
|
|
|
|
cxcursor::getCursorTU(C));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 03:32:19 +08:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2014-10-11 04:01:05 +08:00
|
|
|
int clang_Cursor_getNumTemplateArguments(CXCursor C) {
|
|
|
|
if (clang_getCursorKind(C) != CXCursor_FunctionDecl) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionDecl *FD = llvm::dyn_cast_or_null<clang::FunctionDecl>(
|
|
|
|
getCursorDecl(C));
|
|
|
|
if (!FD) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionTemplateSpecializationInfo* SpecInfo =
|
|
|
|
FD->getTemplateSpecializationInfo();
|
|
|
|
if (!SpecInfo) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SpecInfo->TemplateArguments->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum CXGetTemplateArgumentStatus {
|
|
|
|
/** \brief The operation completed successfully */
|
|
|
|
CXGetTemplateArgumentStatus_Success = 0,
|
|
|
|
|
|
|
|
/** \brief The specified cursor did not represent a FunctionDecl. */
|
|
|
|
CXGetTemplateArgumentStatus_CursorNotFunctionDecl = -1,
|
|
|
|
|
|
|
|
/** \brief The specified cursor was not castable to a FunctionDecl. */
|
|
|
|
CXGetTemplateArgumentStatus_BadFunctionDeclCast = -2,
|
|
|
|
|
|
|
|
/** \brief A NULL FunctionTemplateSpecializationInfo was retrieved. */
|
|
|
|
CXGetTemplateArgumentStatus_NullTemplSpecInfo = -3,
|
|
|
|
|
|
|
|
/** \brief An invalid (OOB) argument index was specified */
|
|
|
|
CXGetTemplateArgumentStatus_InvalidIndex = -4
|
|
|
|
};
|
|
|
|
|
|
|
|
static int clang_Cursor_getTemplateArgument(
|
|
|
|
CXCursor C, unsigned I, TemplateArgument *TA) {
|
|
|
|
if (clang_getCursorKind(C) != CXCursor_FunctionDecl) {
|
|
|
|
return CXGetTemplateArgumentStatus_CursorNotFunctionDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionDecl *FD = llvm::dyn_cast_or_null<clang::FunctionDecl>(
|
|
|
|
getCursorDecl(C));
|
|
|
|
if (!FD) {
|
|
|
|
return CXGetTemplateArgumentStatus_BadFunctionDeclCast;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionTemplateSpecializationInfo* SpecInfo =
|
|
|
|
FD->getTemplateSpecializationInfo();
|
|
|
|
if (!SpecInfo) {
|
|
|
|
return CXGetTemplateArgumentStatus_NullTemplSpecInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (I >= SpecInfo->TemplateArguments->size()) {
|
|
|
|
return CXGetTemplateArgumentStatus_InvalidIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
*TA = SpecInfo->TemplateArguments->get(I);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(CXCursor C,
|
|
|
|
unsigned I) {
|
|
|
|
TemplateArgument TA;
|
|
|
|
if (clang_Cursor_getTemplateArgument(C, I, &TA)) {
|
|
|
|
return CXTemplateArgumentKind_Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (TA.getKind()) {
|
|
|
|
case TemplateArgument::Null: return CXTemplateArgumentKind_Null;
|
|
|
|
case TemplateArgument::Type: return CXTemplateArgumentKind_Type;
|
|
|
|
case TemplateArgument::Declaration:
|
|
|
|
return CXTemplateArgumentKind_Declaration;
|
|
|
|
case TemplateArgument::NullPtr: return CXTemplateArgumentKind_NullPtr;
|
|
|
|
case TemplateArgument::Integral: return CXTemplateArgumentKind_Integral;
|
|
|
|
case TemplateArgument::Template: return CXTemplateArgumentKind_Template;
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
return CXTemplateArgumentKind_TemplateExpansion;
|
|
|
|
case TemplateArgument::Expression: return CXTemplateArgumentKind_Expression;
|
|
|
|
case TemplateArgument::Pack: return CXTemplateArgumentKind_Pack;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CXTemplateArgumentKind_Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXType clang_Cursor_getTemplateArgumentType(CXCursor C, unsigned I) {
|
|
|
|
TemplateArgument TA;
|
|
|
|
if (clang_Cursor_getTemplateArgument(C, I, &TA) !=
|
|
|
|
CXGetTemplateArgumentStatus_Success) {
|
|
|
|
return cxtype::MakeCXType(QualType(), getCursorTU(C));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TA.getKind() != TemplateArgument::Type) {
|
|
|
|
return cxtype::MakeCXType(QualType(), getCursorTU(C));
|
|
|
|
}
|
|
|
|
|
|
|
|
return cxtype::MakeCXType(TA.getAsType(), getCursorTU(C));
|
|
|
|
}
|
|
|
|
|
|
|
|
long long clang_Cursor_getTemplateArgumentValue(CXCursor C, unsigned I) {
|
|
|
|
TemplateArgument TA;
|
|
|
|
if (clang_Cursor_getTemplateArgument(C, I, &TA) !=
|
|
|
|
CXGetTemplateArgumentStatus_Success) {
|
|
|
|
assert(0 && "Unable to retrieve TemplateArgument");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TA.getKind() != TemplateArgument::Integral) {
|
|
|
|
assert(0 && "Passed template argument is not Integral");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TA.getAsIntegral().getSExtValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long clang_Cursor_getTemplateArgumentUnsignedValue(CXCursor C,
|
|
|
|
unsigned I) {
|
|
|
|
TemplateArgument TA;
|
|
|
|
if (clang_Cursor_getTemplateArgument(C, I, &TA) !=
|
|
|
|
CXGetTemplateArgumentStatus_Success) {
|
|
|
|
assert(0 && "Unable to retrieve TemplateArgument");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TA.getKind() != TemplateArgument::Integral) {
|
|
|
|
assert(0 && "Passed template argument is not Integral");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TA.getAsIntegral().getZExtValue();
|
|
|
|
}
|
|
|
|
|
2013-04-24 15:17:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CXCursorSet.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl;
|
|
|
|
|
|
|
|
static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) {
|
|
|
|
return (CXCursorSet) setImpl;
|
|
|
|
}
|
|
|
|
static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) {
|
|
|
|
return (CXCursorSet_Impl*) set;
|
|
|
|
}
|
|
|
|
namespace llvm {
|
|
|
|
template<> struct DenseMapInfo<CXCursor> {
|
|
|
|
public:
|
|
|
|
static inline CXCursor getEmptyKey() {
|
|
|
|
return MakeCXCursorInvalid(CXCursor_InvalidFile);
|
|
|
|
}
|
|
|
|
static inline CXCursor getTombstoneKey() {
|
|
|
|
return MakeCXCursorInvalid(CXCursor_NoDeclFound);
|
|
|
|
}
|
|
|
|
static inline unsigned getHashValue(const CXCursor &cursor) {
|
|
|
|
return llvm::DenseMapInfo<std::pair<const void *, const void *> >
|
|
|
|
::getHashValue(std::make_pair(cursor.data[0], cursor.data[1]));
|
|
|
|
}
|
|
|
|
static inline bool isEqual(const CXCursor &x, const CXCursor &y) {
|
|
|
|
return x.kind == y.kind &&
|
|
|
|
x.data[0] == y.data[0] &&
|
|
|
|
x.data[1] == y.data[1];
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2013-04-24 15:17:12 +08:00
|
|
|
|
|
|
|
CXCursorSet clang_createCXCursorSet() {
|
|
|
|
return packCXCursorSet(new CXCursorSet_Impl());
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_disposeCXCursorSet(CXCursorSet set) {
|
|
|
|
delete unpackCXCursorSet(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) {
|
|
|
|
CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
|
|
|
|
if (!setImpl)
|
|
|
|
return 0;
|
2013-04-24 15:25:40 +08:00
|
|
|
return setImpl->find(cursor) != setImpl->end();
|
2013-04-24 15:17:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) {
|
|
|
|
// Do not insert invalid cursors into the set.
|
|
|
|
if (cursor.kind >= CXCursor_FirstInvalid &&
|
|
|
|
cursor.kind <= CXCursor_LastInvalid)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
|
|
|
|
if (!setImpl)
|
|
|
|
return 1;
|
|
|
|
unsigned &entry = (*setImpl)[cursor];
|
|
|
|
unsigned flag = entry == 0 ? 1 : 0;
|
|
|
|
entry = 1;
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2011-08-05 04:04:59 +08:00
|
|
|
CXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
|
|
|
|
enum CXCursorKind kind = clang_getCursorKind(cursor);
|
|
|
|
if (clang_isDeclaration(kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *decl = getCursorDecl(cursor);
|
|
|
|
if (const NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) {
|
2011-08-05 04:04:59 +08:00
|
|
|
ASTUnit *unit = getCursorASTUnit(cursor);
|
2013-01-31 12:52:16 +08:00
|
|
|
CodeCompletionResult Result(namedDecl, CCP_Declaration);
|
2012-01-17 10:15:54 +08:00
|
|
|
CodeCompletionString *String
|
|
|
|
= Result.CreateCodeCompletionString(unit->getASTContext(),
|
|
|
|
unit->getPreprocessor(),
|
2015-07-07 14:20:19 +08:00
|
|
|
CodeCompletionContext::CCC_Other,
|
2012-04-11 01:23:48 +08:00
|
|
|
unit->getCodeCompletionTUInfo().getAllocator(),
|
2012-07-03 01:35:10 +08:00
|
|
|
unit->getCodeCompletionTUInfo(),
|
|
|
|
true);
|
2012-01-17 10:15:54 +08:00
|
|
|
return String;
|
2011-08-05 04:04:59 +08:00
|
|
|
}
|
2015-05-04 10:25:31 +08:00
|
|
|
} else if (kind == CXCursor_MacroDefinition) {
|
|
|
|
const MacroDefinitionRecord *definition = getCursorMacroDefinition(cursor);
|
2011-08-05 04:04:59 +08:00
|
|
|
const IdentifierInfo *MacroInfo = definition->getName();
|
|
|
|
ASTUnit *unit = getCursorASTUnit(cursor);
|
2013-01-14 08:36:42 +08:00
|
|
|
CodeCompletionResult Result(MacroInfo);
|
2015-07-07 14:20:19 +08:00
|
|
|
CodeCompletionString *String
|
|
|
|
= Result.CreateCodeCompletionString(unit->getASTContext(),
|
|
|
|
unit->getPreprocessor(),
|
|
|
|
CodeCompletionContext::CCC_Other,
|
|
|
|
unit->getCodeCompletionTUInfo().getAllocator(),
|
|
|
|
unit->getCodeCompletionTUInfo(),
|
|
|
|
false);
|
2012-01-17 10:15:54 +08:00
|
|
|
return String;
|
2011-08-05 04:04:59 +08:00
|
|
|
}
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2011-08-05 04:04:59 +08:00
|
|
|
}
|
2012-05-01 03:06:49 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct OverridenCursorsPool {
|
2013-01-13 03:30:44 +08:00
|
|
|
typedef SmallVector<CXCursor, 2> CursorVec;
|
2012-05-01 03:06:49 +08:00
|
|
|
std::vector<CursorVec*> AllCursors;
|
|
|
|
std::vector<CursorVec*> AvailableCursors;
|
|
|
|
|
|
|
|
~OverridenCursorsPool() {
|
|
|
|
for (std::vector<CursorVec*>::iterator I = AllCursors.begin(),
|
|
|
|
E = AllCursors.end(); I != E; ++I) {
|
|
|
|
delete *I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2012-05-01 03:06:49 +08:00
|
|
|
|
|
|
|
void *cxcursor::createOverridenCXCursorsPool() {
|
|
|
|
return new OverridenCursorsPool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cxcursor::disposeOverridenCXCursorsPool(void *pool) {
|
|
|
|
delete static_cast<OverridenCursorsPool*>(pool);
|
|
|
|
}
|
2012-05-01 03:33:45 +08:00
|
|
|
|
2012-05-01 03:06:49 +08:00
|
|
|
void clang_getOverriddenCursors(CXCursor cursor,
|
|
|
|
CXCursor **overridden,
|
|
|
|
unsigned *num_overridden) {
|
|
|
|
if (overridden)
|
2014-06-08 16:38:04 +08:00
|
|
|
*overridden = nullptr;
|
2012-05-01 03:06:49 +08:00
|
|
|
if (num_overridden)
|
|
|
|
*num_overridden = 0;
|
|
|
|
|
|
|
|
CXTranslationUnit TU = cxcursor::getCursorTU(cursor);
|
|
|
|
|
|
|
|
if (!overridden || !num_overridden || !TU)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!clang_isDeclaration(cursor.kind))
|
|
|
|
return;
|
|
|
|
|
|
|
|
OverridenCursorsPool &pool =
|
|
|
|
*static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
|
2014-06-08 16:38:04 +08:00
|
|
|
|
|
|
|
OverridenCursorsPool::CursorVec *Vec = nullptr;
|
|
|
|
|
2012-05-01 03:06:49 +08:00
|
|
|
if (!pool.AvailableCursors.empty()) {
|
|
|
|
Vec = pool.AvailableCursors.back();
|
|
|
|
pool.AvailableCursors.pop_back();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Vec = new OverridenCursorsPool::CursorVec();
|
|
|
|
pool.AllCursors.push_back(Vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear out the vector, but don't free the memory contents. This
|
|
|
|
// reduces malloc() traffic.
|
|
|
|
Vec->clear();
|
|
|
|
|
|
|
|
// Use the first entry to contain a back reference to the vector.
|
|
|
|
// This is a complete hack.
|
|
|
|
CXCursor backRefCursor = MakeCXCursorInvalid(CXCursor_InvalidFile, TU);
|
|
|
|
backRefCursor.data[0] = Vec;
|
|
|
|
assert(cxcursor::getCursorTU(backRefCursor) == TU);
|
|
|
|
Vec->push_back(backRefCursor);
|
|
|
|
|
|
|
|
// Get the overriden cursors.
|
|
|
|
cxcursor::getOverriddenCursors(cursor, *Vec);
|
|
|
|
|
|
|
|
// Did we get any overriden cursors? If not, return Vec to the pool
|
|
|
|
// of available cursor vectors.
|
|
|
|
if (Vec->size() == 1) {
|
|
|
|
pool.AvailableCursors.push_back(Vec);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now tell the caller about the overriden cursors.
|
|
|
|
assert(Vec->size() > 1);
|
|
|
|
*overridden = &((*Vec)[1]);
|
|
|
|
*num_overridden = Vec->size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_disposeOverriddenCursors(CXCursor *overridden) {
|
|
|
|
if (!overridden)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Use pointer arithmetic to get back the first faux entry
|
|
|
|
// which has a back-reference to the TU and the vector.
|
|
|
|
--overridden;
|
|
|
|
OverridenCursorsPool::CursorVec *Vec =
|
2013-01-12 05:01:49 +08:00
|
|
|
static_cast<OverridenCursorsPool::CursorVec *>(
|
|
|
|
const_cast<void *>(overridden->data[0]));
|
2012-05-01 03:06:49 +08:00
|
|
|
CXTranslationUnit TU = getCursorTU(*overridden);
|
|
|
|
|
|
|
|
assert(Vec && TU);
|
|
|
|
|
|
|
|
OverridenCursorsPool &pool =
|
|
|
|
*static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
|
|
|
|
|
|
|
|
pool.AvailableCursors.push_back(Vec);
|
|
|
|
}
|
2012-07-03 07:54:36 +08:00
|
|
|
|
|
|
|
int clang_Cursor_isDynamicCall(CXCursor C) {
|
2014-06-08 16:38:04 +08:00
|
|
|
const Expr *E = nullptr;
|
2012-07-03 07:54:36 +08:00
|
|
|
if (clang_isExpression(C.kind))
|
|
|
|
E = getCursorExpr(C);
|
|
|
|
if (!E)
|
|
|
|
return 0;
|
|
|
|
|
2014-11-11 07:21:35 +08:00
|
|
|
if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E)) {
|
|
|
|
if (MsgE->getReceiverKind() != ObjCMessageExpr::Instance)
|
|
|
|
return false;
|
|
|
|
if (auto *RecE = dyn_cast<ObjCMessageExpr>(
|
|
|
|
MsgE->getInstanceReceiver()->IgnoreParenCasts())) {
|
|
|
|
if (RecE->getMethodFamily() == OMF_alloc)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-03 07:54:36 +08:00
|
|
|
|
2017-04-28 01:23:04 +08:00
|
|
|
if (auto *PropRefE = dyn_cast<ObjCPropertyRefExpr>(E)) {
|
|
|
|
return !PropRefE->isSuperReceiver();
|
|
|
|
}
|
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
const MemberExpr *ME = nullptr;
|
2012-07-03 07:54:36 +08:00
|
|
|
if (isa<MemberExpr>(E))
|
|
|
|
ME = cast<MemberExpr>(E);
|
|
|
|
else if (const CallExpr *CE = dyn_cast<CallExpr>(E))
|
|
|
|
ME = dyn_cast_or_null<MemberExpr>(CE->getCallee());
|
|
|
|
|
|
|
|
if (ME) {
|
|
|
|
if (const CXXMethodDecl *
|
|
|
|
MD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
|
2017-04-28 01:23:04 +08:00
|
|
|
return MD->isVirtual() &&
|
|
|
|
ME->performsVirtualDispatch(
|
|
|
|
cxcursor::getCursorContext(C).getLangOpts());
|
2012-07-03 07:54:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-01 10:01:34 +08:00
|
|
|
CXType clang_Cursor_getReceiverType(CXCursor C) {
|
|
|
|
CXTranslationUnit TU = cxcursor::getCursorTU(C);
|
2014-06-08 16:38:04 +08:00
|
|
|
const Expr *E = nullptr;
|
2012-11-01 10:01:34 +08:00
|
|
|
if (clang_isExpression(C.kind))
|
|
|
|
E = getCursorExpr(C);
|
|
|
|
|
|
|
|
if (const ObjCMessageExpr *MsgE = dyn_cast_or_null<ObjCMessageExpr>(E))
|
|
|
|
return cxtype::MakeCXType(MsgE->getReceiverType(), TU);
|
|
|
|
|
2017-04-28 01:23:04 +08:00
|
|
|
if (auto *PropRefE = dyn_cast<ObjCPropertyRefExpr>(E)) {
|
|
|
|
return cxtype::MakeCXType(
|
|
|
|
PropRefE->getReceiverType(cxcursor::getCursorContext(C)), TU);
|
|
|
|
}
|
|
|
|
|
|
|
|
const MemberExpr *ME = nullptr;
|
|
|
|
if (isa<MemberExpr>(E))
|
|
|
|
ME = cast<MemberExpr>(E);
|
|
|
|
else if (const CallExpr *CE = dyn_cast<CallExpr>(E))
|
|
|
|
ME = dyn_cast_or_null<MemberExpr>(CE->getCallee());
|
|
|
|
|
|
|
|
if (ME) {
|
2017-04-28 04:22:40 +08:00
|
|
|
if (dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl())) {
|
2017-04-28 01:23:04 +08:00
|
|
|
auto receiverTy = ME->getBase()->IgnoreImpCasts()->getType();
|
|
|
|
return cxtype::MakeCXType(receiverTy, TU);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-01 10:01:34 +08:00
|
|
|
return cxtype::MakeCXType(QualType(), TU);
|
|
|
|
}
|