aboutsummaryrefslogtreecommitdiff
path: root/tools/libclang
diff options
context:
space:
mode:
Diffstat (limited to 'tools/libclang')
-rw-r--r--tools/libclang/BuildSystem.cpp6
-rw-r--r--tools/libclang/CIndex.cpp344
-rw-r--r--tools/libclang/CIndexCodeCompletion.cpp13
-rw-r--r--tools/libclang/CIndexDiagnostic.cpp1
-rw-r--r--tools/libclang/CMakeLists.txt20
-rw-r--r--tools/libclang/CXCursor.cpp63
-rw-r--r--tools/libclang/CXCursor.h17
-rw-r--r--tools/libclang/CXIndexDataConsumer.cpp6
-rw-r--r--tools/libclang/CXIndexDataConsumer.h2
-rw-r--r--tools/libclang/CXStoredDiagnostic.cpp2
-rw-r--r--tools/libclang/CXType.cpp132
-rw-r--r--tools/libclang/libclang.exports9
12 files changed, 502 insertions, 113 deletions
diff --git a/tools/libclang/BuildSystem.cpp b/tools/libclang/BuildSystem.cpp
index 79fa69c40bae..6c1f2c145b0a 100644
--- a/tools/libclang/BuildSystem.cpp
+++ b/tools/libclang/BuildSystem.cpp
@@ -13,12 +13,12 @@
#include "clang-c/BuildSystem.h"
#include "CXString.h"
-#include "clang/Basic/VirtualFileSystem.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
@@ -28,11 +28,11 @@ unsigned long long clang_getBuildSessionTimestamp(void) {
return llvm::sys::toTimeT(std::chrono::system_clock::now());
}
-DEFINE_SIMPLE_CONVERSION_FUNCTIONS(clang::vfs::YAMLVFSWriter,
+DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::vfs::YAMLVFSWriter,
CXVirtualFileOverlay)
CXVirtualFileOverlay clang_VirtualFileOverlay_create(unsigned) {
- return wrap(new clang::vfs::YAMLVFSWriter());
+ return wrap(new llvm::vfs::YAMLVFSWriter());
}
enum CXErrorCode
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 499d9abf9a8e..a9c3077e5fa2 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -31,14 +31,12 @@
#include "clang/Basic/Version.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Index/CodegenNameGenerator.h"
#include "clang/Index/CommentToXML.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/PreprocessingRecord.h"
#include "clang/Lex/Preprocessor.h"
-#include "clang/Serialization/SerializationDiagnostic.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringSwitch.h"
@@ -565,7 +563,7 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) {
if (const ObjCObjectType *ObjT = A->getInterface()->getAs<ObjCObjectType>())
return Visit(cxcursor::MakeCursorObjCClassRef(
ObjT->getInterface(),
- A->getInterfaceLoc()->getTypeLoc().getLocStart(), TU));
+ A->getInterfaceLoc()->getTypeLoc().getBeginLoc(), TU));
}
// If pointing inside a macro definition, check if the token is an identifier
@@ -993,7 +991,7 @@ static void addRangedDeclsInContainer(DeclIt *DI_current, DeclIt DE_current,
Decl *D_next = *next;
if (!D_next)
break;
- SourceLocation L = D_next->getLocStart();
+ SourceLocation L = D_next->getBeginLoc();
if (!L.isValid())
break;
if (SM.isBeforeInTranslationUnit(L, EndLoc)) {
@@ -1038,20 +1036,20 @@ bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) {
// additional ones we've collected. Then visit them.
for (auto *SubDecl : D->decls()) {
if (!SubDecl || SubDecl->getLexicalDeclContext() != D ||
- SubDecl->getLocStart().isInvalid())
+ SubDecl->getBeginLoc().isInvalid())
continue;
DeclsInContainer.push_back(SubDecl);
}
// Now sort the Decls so that they appear in lexical order.
- llvm::sort(DeclsInContainer.begin(), DeclsInContainer.end(),
+ llvm::sort(DeclsInContainer,
[&SM](Decl *A, Decl *B) {
- SourceLocation L_A = A->getLocStart();
- SourceLocation L_B = B->getLocStart();
- return L_A != L_B ?
- SM.isBeforeInTranslationUnit(L_A, L_B) :
- SM.isBeforeInTranslationUnit(A->getLocEnd(), B->getLocEnd());
- });
+ SourceLocation L_A = A->getBeginLoc();
+ SourceLocation L_B = B->getBeginLoc();
+ return L_A != L_B ? SM.isBeforeInTranslationUnit(L_A, L_B)
+ : SM.isBeforeInTranslationUnit(A->getEndLoc(),
+ B->getEndLoc());
+ });
// Now visit the decls.
for (SmallVectorImpl<Decl*>::iterator I = DeclsInContainer.begin(),
@@ -1519,6 +1517,9 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/Basic/OpenCLImageTypes.def"
+#define EXT_OPAQUE_TYPE(ExtTYpe, Id, Ext) \
+ case BuiltinType::Id:
+#include "clang/Basic/OpenCLExtensionTypes.def"
case BuiltinType::OCLSampler:
case BuiltinType::OCLEvent:
case BuiltinType::OCLClkEvent:
@@ -1578,7 +1579,7 @@ bool CursorVisitor::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
}
bool CursorVisitor::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) {
- if (Visit(MakeCursorTypeRef(TL.getDecl(), TL.getLocStart(), TU)))
+ if (Visit(MakeCursorTypeRef(TL.getDecl(), TL.getBeginLoc(), TU)))
return true;
for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I),
@@ -1802,7 +1803,9 @@ bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) {
bool CursorVisitor::VisitAttributes(Decl *D) {
for (const auto *I : D->attrs())
- if (!I->isImplicit() && Visit(MakeCXCursor(I, D, TU)))
+ if ((TU->ParsingOptions & CXTranslationUnit_VisitImplicitAttributes ||
+ !I->isImplicit()) &&
+ Visit(MakeCXCursor(I, D, TU)))
return true;
return false;
@@ -2205,6 +2208,21 @@ void OMPClauseEnqueue::VisitOMPSIMDClause(const OMPSIMDClause *) {}
void OMPClauseEnqueue::VisitOMPNogroupClause(const OMPNogroupClause *) {}
+void OMPClauseEnqueue::VisitOMPUnifiedAddressClause(
+ const OMPUnifiedAddressClause *) {}
+
+void OMPClauseEnqueue::VisitOMPUnifiedSharedMemoryClause(
+ const OMPUnifiedSharedMemoryClause *) {}
+
+void OMPClauseEnqueue::VisitOMPReverseOffloadClause(
+ const OMPReverseOffloadClause *) {}
+
+void OMPClauseEnqueue::VisitOMPDynamicAllocatorsClause(
+ const OMPDynamicAllocatorsClause *) {}
+
+void OMPClauseEnqueue::VisitOMPAtomicDefaultMemOrderClause(
+ const OMPAtomicDefaultMemOrderClause *) {}
+
void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) {
Visitor->AddStmt(C->getDevice());
}
@@ -3117,25 +3135,19 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
return true;
}
+ TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
// Visit parameters and return type, if present.
- if (E->hasExplicitParameters() || E->hasExplicitResultType()) {
- TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
- if (E->hasExplicitParameters() && E->hasExplicitResultType()) {
- // Visit the whole type.
- if (Visit(TL))
- return true;
- } else if (FunctionProtoTypeLoc Proto =
- TL.getAs<FunctionProtoTypeLoc>()) {
- if (E->hasExplicitParameters()) {
- // Visit parameters.
- for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)
- if (Visit(MakeCXCursor(Proto.getParam(I), TU)))
- return true;
- } else {
- // Visit result type.
- if (Visit(Proto.getReturnLoc()))
+ if (FunctionTypeLoc Proto = TL.getAs<FunctionProtoTypeLoc>()) {
+ if (E->hasExplicitParameters()) {
+ // Visit parameters.
+ for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)
+ if (Visit(MakeCXCursor(Proto.getParam(I), TU)))
return true;
- }
+ }
+ if (E->hasExplicitResultType()) {
+ // Visit result type.
+ if (Visit(Proto.getReturnLoc()))
+ return true;
}
}
break;
@@ -3682,7 +3694,7 @@ struct ExprEvalResult {
~ExprEvalResult() {
if (EvalType != CXEval_UnExposed && EvalType != CXEval_Float &&
EvalType != CXEval_Int) {
- delete EvalData.stringVal;
+ delete[] EvalData.stringVal;
}
}
};
@@ -3890,36 +3902,35 @@ static const ExprEvalResult* evaluateExpr(Expr *expr, CXCursor C) {
return nullptr;
}
-CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
- const Decl *D = getCursorDecl(C);
- if (D) {
- const Expr *expr = nullptr;
- if (auto *Var = dyn_cast<VarDecl>(D)) {
- expr = Var->getInit();
- } else if (auto *Field = dyn_cast<FieldDecl>(D)) {
- expr = Field->getInClassInitializer();
- }
- if (expr)
- return const_cast<CXEvalResult>(reinterpret_cast<const void *>(
- evaluateExpr(const_cast<Expr *>(expr), C)));
+static const Expr *evaluateDeclExpr(const Decl *D) {
+ if (!D)
return nullptr;
- }
+ if (auto *Var = dyn_cast<VarDecl>(D))
+ return Var->getInit();
+ else if (auto *Field = dyn_cast<FieldDecl>(D))
+ return Field->getInClassInitializer();
+ return nullptr;
+}
- const CompoundStmt *compoundStmt = dyn_cast_or_null<CompoundStmt>(getCursorStmt(C));
- if (compoundStmt) {
- Expr *expr = nullptr;
- for (auto *bodyIterator : compoundStmt->body()) {
- if ((expr = dyn_cast<Expr>(bodyIterator))) {
- break;
- }
- }
- if (expr)
- return const_cast<CXEvalResult>(
- reinterpret_cast<const void *>(evaluateExpr(expr, C)));
+static const Expr *evaluateCompoundStmtExpr(const CompoundStmt *CS) {
+ assert(CS && "invalid compound statement");
+ for (auto *bodyIterator : CS->body()) {
+ if (const auto *E = dyn_cast<Expr>(bodyIterator))
+ return E;
}
return nullptr;
}
+CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
+ if (const Expr *E =
+ clang_getCursorKind(C) == CXCursor_CompoundStmt
+ ? evaluateCompoundStmtExpr(cast<CompoundStmt>(getCursorStmt(C)))
+ : evaluateDeclExpr(getCursorDecl(C)))
+ return const_cast<CXEvalResult>(
+ reinterpret_cast<const void *>(evaluateExpr(const_cast<Expr *>(E), C)));
+ return nullptr;
+}
+
unsigned clang_Cursor_hasAttrs(CXCursor C) {
const Decl *D = getCursorDecl(C);
if (!D) {
@@ -4340,8 +4351,8 @@ static SourceLocation getLocationFromExpr(const Expr *E) {
return SizeOfPack->getPackLoc();
if (const ObjCPropertyRefExpr *PropRef = dyn_cast<ObjCPropertyRefExpr>(E))
return PropRef->getLocation();
-
- return E->getLocStart();
+
+ return E->getBeginLoc();
}
extern "C" {
@@ -5277,6 +5288,42 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("attribute(dllexport)");
case CXCursor_DLLImport:
return cxstring::createRef("attribute(dllimport)");
+ case CXCursor_NSReturnsRetained:
+ return cxstring::createRef("attribute(ns_returns_retained)");
+ case CXCursor_NSReturnsNotRetained:
+ return cxstring::createRef("attribute(ns_returns_not_retained)");
+ case CXCursor_NSReturnsAutoreleased:
+ return cxstring::createRef("attribute(ns_returns_autoreleased)");
+ case CXCursor_NSConsumesSelf:
+ return cxstring::createRef("attribute(ns_consumes_self)");
+ case CXCursor_NSConsumed:
+ return cxstring::createRef("attribute(ns_consumed)");
+ case CXCursor_ObjCException:
+ return cxstring::createRef("attribute(objc_exception)");
+ case CXCursor_ObjCNSObject:
+ return cxstring::createRef("attribute(NSObject)");
+ case CXCursor_ObjCIndependentClass:
+ return cxstring::createRef("attribute(objc_independent_class)");
+ case CXCursor_ObjCPreciseLifetime:
+ return cxstring::createRef("attribute(objc_precise_lifetime)");
+ case CXCursor_ObjCReturnsInnerPointer:
+ return cxstring::createRef("attribute(objc_returns_inner_pointer)");
+ case CXCursor_ObjCRequiresSuper:
+ return cxstring::createRef("attribute(objc_requires_super)");
+ case CXCursor_ObjCRootClass:
+ return cxstring::createRef("attribute(objc_root_class)");
+ case CXCursor_ObjCSubclassingRestricted:
+ return cxstring::createRef("attribute(objc_subclassing_restricted)");
+ case CXCursor_ObjCExplicitProtocolImpl:
+ return cxstring::createRef("attribute(objc_protocol_requires_explicit_implementation)");
+ case CXCursor_ObjCDesignatedInitializer:
+ return cxstring::createRef("attribute(objc_designated_initializer)");
+ case CXCursor_ObjCRuntimeVisible:
+ return cxstring::createRef("attribute(objc_runtime_visible)");
+ case CXCursor_ObjCBoxable:
+ return cxstring::createRef("attribute(objc_boxable)");
+ case CXCursor_FlagEnum:
+ return cxstring::createRef("attribute(flag_enum)");
case CXCursor_PreprocessingDirective:
return cxstring::createRef("preprocessing directive");
case CXCursor_MacroDefinition:
@@ -5752,9 +5799,9 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) {
if (TypeSourceInfo *TSInfo = BaseSpec->getTypeSourceInfo())
return cxloc::translateSourceLocation(getCursorContext(C),
TSInfo->getTypeLoc().getBeginLoc());
-
+
return cxloc::translateSourceLocation(getCursorContext(C),
- BaseSpec->getLocStart());
+ BaseSpec->getBeginLoc());
}
case CXCursor_LabelRef: {
@@ -5778,7 +5825,7 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) {
if (clang_isStatement(C.kind))
return cxloc::translateSourceLocation(getCursorContext(C),
- getCursorStmt(C)->getLocStart());
+ getCursorStmt(C)->getBeginLoc());
if (C.kind == CXCursor_PreprocessingDirective) {
SourceLocation L = cxcursor::getCursorPreprocessingDirective(C).getBegin();
@@ -5978,10 +6025,10 @@ static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr) {
SourceLocation StartLoc;
if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
if (TypeSourceInfo *TI = DD->getTypeSourceInfo())
- StartLoc = TI->getTypeLoc().getLocStart();
+ StartLoc = TI->getTypeLoc().getBeginLoc();
} else if (const TypedefDecl *Typedef = dyn_cast<TypedefDecl>(D)) {
if (TypeSourceInfo *TI = Typedef->getTypeSourceInfo())
- StartLoc = TI->getTypeLoc().getLocStart();
+ StartLoc = TI->getTypeLoc().getBeginLoc();
}
if (StartLoc.isValid() && R.getBegin().isValid() &&
@@ -6182,6 +6229,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) {
case Decl::Import:
case Decl::OMPThreadPrivate:
case Decl::OMPDeclareReduction:
+ case Decl::OMPRequires:
case Decl::ObjCTypeParam:
case Decl::BuiltinTemplate:
case Decl::PragmaComment:
@@ -6756,11 +6804,18 @@ class AnnotateTokensWorker {
SourceManager &SrcMgr;
bool HasContextSensitiveKeywords;
+ struct PostChildrenAction {
+ CXCursor cursor;
+ enum Action { Invalid, Ignore, Postpone } action;
+ };
+ using PostChildrenActions = SmallVector<PostChildrenAction, 0>;
+
struct PostChildrenInfo {
CXCursor Cursor;
SourceRange CursorRange;
unsigned BeforeReachingCursorIdx;
unsigned BeforeChildrenTokenIdx;
+ PostChildrenActions ChildActions;
};
SmallVector<PostChildrenInfo, 8> PostChildrenInfos;
@@ -6806,7 +6861,13 @@ public:
void VisitChildren(CXCursor C) { AnnotateVis.VisitChildren(C); }
enum CXChildVisitResult Visit(CXCursor cursor, CXCursor parent);
+ bool IsIgnoredChildCursor(CXCursor cursor) const;
+ PostChildrenActions DetermineChildActions(CXCursor Cursor) const;
+
bool postVisitChildren(CXCursor cursor);
+ void HandlePostPonedChildCursors(const PostChildrenInfo &Info);
+ void HandlePostPonedChildCursor(CXCursor Cursor, unsigned StartTokenIndex);
+
void AnnotateTokens();
/// Determine whether the annotator saw any cursors that have
@@ -6827,6 +6888,67 @@ void AnnotateTokensWorker::AnnotateTokens() {
AnnotateVis.visitFileRegion();
}
+bool AnnotateTokensWorker::IsIgnoredChildCursor(CXCursor cursor) const {
+ if (PostChildrenInfos.empty())
+ return false;
+
+ for (const auto &ChildAction : PostChildrenInfos.back().ChildActions) {
+ if (ChildAction.cursor == cursor &&
+ ChildAction.action == PostChildrenAction::Ignore) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+const CXXOperatorCallExpr *GetSubscriptOrCallOperator(CXCursor Cursor) {
+ if (!clang_isExpression(Cursor.kind))
+ return nullptr;
+
+ const Expr *E = getCursorExpr(Cursor);
+ if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
+ const OverloadedOperatorKind Kind = OCE->getOperator();
+ if (Kind == OO_Call || Kind == OO_Subscript)
+ return OCE;
+ }
+
+ return nullptr;
+}
+
+AnnotateTokensWorker::PostChildrenActions
+AnnotateTokensWorker::DetermineChildActions(CXCursor Cursor) const {
+ PostChildrenActions actions;
+
+ // The DeclRefExpr of CXXOperatorCallExpr refering to the custom operator is
+ // visited before the arguments to the operator call. For the Call and
+ // Subscript operator the range of this DeclRefExpr includes the whole call
+ // expression, so that all tokens in that range would be mapped to the
+ // operator function, including the tokens of the arguments. To avoid that,
+ // ensure to visit this DeclRefExpr as last node.
+ if (const auto *OCE = GetSubscriptOrCallOperator(Cursor)) {
+ const Expr *Callee = OCE->getCallee();
+ if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee)) {
+ const Expr *SubExpr = ICE->getSubExpr();
+ if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(SubExpr)) {
+ const Decl *parentDecl = getCursorDecl(Cursor);
+ CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor);
+
+ // Visit the DeclRefExpr as last.
+ CXCursor cxChild = MakeCXCursor(DRE, parentDecl, TU);
+ actions.push_back({cxChild, PostChildrenAction::Postpone});
+
+ // The parent of the DeclRefExpr, an ImplicitCastExpr, has an equally
+ // wide range as the DeclRefExpr. We can skip visiting this entirely.
+ cxChild = MakeCXCursor(ICE, parentDecl, TU);
+ actions.push_back({cxChild, PostChildrenAction::Ignore});
+ }
+ }
+ }
+
+ return actions;
+}
+
static inline void updateCursorAnnotation(CXCursor &Cursor,
const CXCursor &updateC) {
if (clang_isInvalid(updateC.kind) || !clang_isInvalid(Cursor.kind))
@@ -6903,7 +7025,10 @@ AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) {
SourceRange cursorRange = getRawCursorExtent(cursor);
if (cursorRange.isInvalid())
return CXChildVisit_Recurse;
-
+
+ if (IsIgnoredChildCursor(cursor))
+ return CXChildVisit_Continue;
+
if (!HasContextSensitiveKeywords) {
// Objective-C properties can have context-sensitive keywords.
if (cursor.kind == CXCursor_ObjCPropertyDecl) {
@@ -7029,11 +7154,11 @@ AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) {
// MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr cursor.
if (clang_isExpression(cursorK) && MoreTokens()) {
const Expr *E = getCursorExpr(cursor);
- if (const Decl *D = getCursorParentDecl(cursor)) {
+ if (const Decl *D = getCursorDecl(cursor)) {
const unsigned I = NextToken();
- if (E->getLocStart().isValid() && D->getLocation().isValid() &&
- E->getLocStart() == D->getLocation() &&
- E->getLocStart() == GetTokenLoc(I)) {
+ if (E->getBeginLoc().isValid() && D->getLocation().isValid() &&
+ E->getBeginLoc() == D->getLocation() &&
+ E->getBeginLoc() == GetTokenLoc(I)) {
updateCursorAnnotation(Cursors[I], updateC);
AdvanceToken();
}
@@ -7051,6 +7176,7 @@ AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) {
Info.CursorRange = cursorRange;
Info.BeforeReachingCursorIdx = BeforeReachingCursorIdx;
Info.BeforeChildrenTokenIdx = NextToken();
+ Info.ChildActions = DetermineChildActions(cursor);
PostChildrenInfos.push_back(Info);
return CXChildVisit_Recurse;
@@ -7063,6 +7189,8 @@ bool AnnotateTokensWorker::postVisitChildren(CXCursor cursor) {
if (!clang_equalCursors(Info.Cursor, cursor))
return false;
+ HandlePostPonedChildCursors(Info);
+
const unsigned BeforeChildren = Info.BeforeChildrenTokenIdx;
const unsigned AfterChildren = NextToken();
SourceRange cursorRange = Info.CursorRange;
@@ -7089,6 +7217,56 @@ bool AnnotateTokensWorker::postVisitChildren(CXCursor cursor) {
return false;
}
+void AnnotateTokensWorker::HandlePostPonedChildCursors(
+ const PostChildrenInfo &Info) {
+ for (const auto &ChildAction : Info.ChildActions) {
+ if (ChildAction.action == PostChildrenAction::Postpone) {
+ HandlePostPonedChildCursor(ChildAction.cursor,
+ Info.BeforeChildrenTokenIdx);
+ }
+ }
+}
+
+void AnnotateTokensWorker::HandlePostPonedChildCursor(
+ CXCursor Cursor, unsigned StartTokenIndex) {
+ const auto flags = CXNameRange_WantQualifier | CXNameRange_WantQualifier;
+ unsigned I = StartTokenIndex;
+
+ // The bracket tokens of a Call or Subscript operator are mapped to
+ // CallExpr/CXXOperatorCallExpr because we skipped visiting the corresponding
+ // DeclRefExpr. Remap these tokens to the DeclRefExpr cursors.
+ for (unsigned RefNameRangeNr = 0; I < NumTokens; RefNameRangeNr++) {
+ const CXSourceRange CXRefNameRange =
+ clang_getCursorReferenceNameRange(Cursor, flags, RefNameRangeNr);
+ if (clang_Range_isNull(CXRefNameRange))
+ break; // All ranges handled.
+
+ SourceRange RefNameRange = cxloc::translateCXSourceRange(CXRefNameRange);
+ while (I < NumTokens) {
+ const SourceLocation TokenLocation = GetTokenLoc(I);
+ if (!TokenLocation.isValid())
+ break;
+
+ // Adapt the end range, because LocationCompare() reports
+ // RangeOverlap even for the not-inclusive end location.
+ const SourceLocation fixedEnd =
+ RefNameRange.getEnd().getLocWithOffset(-1);
+ RefNameRange = SourceRange(RefNameRange.getBegin(), fixedEnd);
+
+ const RangeComparisonResult ComparisonResult =
+ LocationCompare(SrcMgr, TokenLocation, RefNameRange);
+
+ if (ComparisonResult == RangeOverlap) {
+ Cursors[I++] = Cursor;
+ } else if (ComparisonResult == RangeBefore) {
+ ++I; // Not relevant token, check next one.
+ } else if (ComparisonResult == RangeAfter) {
+ break; // All tokens updated for current range, check next.
+ }
+ }
+ }
+}
+
static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor,
CXCursor parent,
CXClientData client_data) {
@@ -7631,11 +7809,11 @@ static void getCursorPlatformAvailabilityForDecl(
if (AvailabilityAttrs.empty())
return;
- llvm::sort(AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
+ llvm::sort(AvailabilityAttrs,
[](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
return LHS->getPlatform()->getName() <
RHS->getPlatform()->getName();
- });
+ });
ASTContext &Ctx = D->getASTContext();
auto It = std::unique(
AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
@@ -7877,6 +8055,30 @@ unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C, unsigned reserved) {
return Result;
}
+CXString clang_Cursor_getObjCPropertyGetterName(CXCursor C) {
+ if (C.kind != CXCursor_ObjCPropertyDecl)
+ return cxstring::createNull();
+
+ const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(getCursorDecl(C));
+ Selector sel = PD->getGetterName();
+ if (sel.isNull())
+ return cxstring::createNull();
+
+ return cxstring::createDup(sel.getAsString());
+}
+
+CXString clang_Cursor_getObjCPropertySetterName(CXCursor C) {
+ if (C.kind != CXCursor_ObjCPropertyDecl)
+ return cxstring::createNull();
+
+ const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(getCursorDecl(C));
+ Selector sel = PD->getSetterName();
+ if (sel.isNull())
+ return cxstring::createNull();
+
+ return cxstring::createDup(sel.getAsString());
+}
+
unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return CXObjCDeclQualifier_None;
@@ -8159,7 +8361,7 @@ unsigned clang_CXXMethod_isConst(CXCursor C) {
const Decl *D = cxcursor::getCursorDecl(C);
const CXXMethodDecl *Method =
D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
- return (Method && (Method->getTypeQualifiers() & Qualifiers::Const)) ? 1 : 0;
+ return (Method && Method->getTypeQualifiers().hasConst()) ? 1 : 0;
}
unsigned clang_CXXMethod_isDefaulted(CXCursor C) {
diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp
index f49f9763c362..c5cece52ac6b 100644
--- a/tools/libclang/CIndexCodeCompletion.cpp
+++ b/tools/libclang/CIndexCodeCompletion.cpp
@@ -26,7 +26,6 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/Sema.h"
#include "llvm/ADT/SmallString.h"
@@ -487,7 +486,8 @@ static unsigned long long getContextsForContextKind(
contexts = CXCompletionContext_Namespace;
break;
}
- case CodeCompletionContext::CCC_PotentiallyQualifiedName: {
+ case CodeCompletionContext::CCC_SymbolOrNewName:
+ case CodeCompletionContext::CCC_Symbol: {
contexts = CXCompletionContext_NestedNameSpecifier;
break;
}
@@ -499,6 +499,10 @@ static unsigned long long getContextsForContextKind(
contexts = CXCompletionContext_NaturalLanguage;
break;
}
+ case CodeCompletionContext::CCC_IncludedFile: {
+ contexts = CXCompletionContext_IncludedFile;
+ break;
+ }
case CodeCompletionContext::CCC_SelectorName: {
contexts = CXCompletionContext_ObjCSelectorName;
break;
@@ -535,7 +539,7 @@ static unsigned long long getContextsForContextKind(
case CodeCompletionContext::CCC_Other:
case CodeCompletionContext::CCC_ObjCInterface:
case CodeCompletionContext::CCC_ObjCImplementation:
- case CodeCompletionContext::CCC_Name:
+ case CodeCompletionContext::CCC_NewName:
case CodeCompletionContext::CCC_MacroName:
case CodeCompletionContext::CCC_PreprocessorExpression:
case CodeCompletionContext::CCC_PreprocessorDirective:
@@ -653,7 +657,8 @@ namespace {
void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
OverloadCandidate *Candidates,
- unsigned NumCandidates) override {
+ unsigned NumCandidates,
+ SourceLocation OpenParLoc) override {
StoredResults.reserve(StoredResults.size() + NumCandidates);
for (unsigned I = 0; I != NumCandidates; ++I) {
CodeCompletionString *StoredCompletion
diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp
index 4e47b25a4bf0..a4e75e2aae31 100644
--- a/tools/libclang/CIndexDiagnostic.cpp
+++ b/tools/libclang/CIndexDiagnostic.cpp
@@ -19,7 +19,6 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/DiagnosticRenderer.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt
index e539c8308e75..32333b011ad1 100644
--- a/tools/libclang/CMakeLists.txt
+++ b/tools/libclang/CMakeLists.txt
@@ -40,6 +40,7 @@ set(LIBS
clangIndex
clangLex
clangSema
+ clangSerialization
clangTooling
)
@@ -151,3 +152,22 @@ if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDE's.
add_llvm_install_targets(install-libclang-headers
COMPONENT libclang-headers)
endif()
+
+# Create a target to install the python bindings to make them easier to
+# distribute. Since the bindings are over libclang, which is installed
+# unbundled to the clang version, follow suit.
+foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS})
+ install(DIRECTORY
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../bindings/python/clang
+ COMPONENT
+ libclang-python-bindings
+ DESTINATION
+ "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages")
+endforeach()
+if(NOT CMAKE_CONFIGURATION_TYPES)
+ add_custom_target(libclang-python-bindings)
+ add_llvm_install_targets(install-libclang-python-bindings
+ COMPONENT
+ libclang-python-bindings)
+endif()
+
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index b4ad0595cc53..99e4319fc1fa 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -61,6 +61,24 @@ static CXCursorKind GetCursorKind(const Attr *A) {
case attr::Visibility: return CXCursor_VisibilityAttr;
case attr::DLLExport: return CXCursor_DLLExport;
case attr::DLLImport: return CXCursor_DLLImport;
+ case attr::NSReturnsRetained: return CXCursor_NSReturnsRetained;
+ case attr::NSReturnsNotRetained: return CXCursor_NSReturnsNotRetained;
+ case attr::NSReturnsAutoreleased: return CXCursor_NSReturnsAutoreleased;
+ case attr::NSConsumesSelf: return CXCursor_NSConsumesSelf;
+ case attr::NSConsumed: return CXCursor_NSConsumed;
+ case attr::ObjCException: return CXCursor_ObjCException;
+ case attr::ObjCNSObject: return CXCursor_ObjCNSObject;
+ case attr::ObjCIndependentClass: return CXCursor_ObjCIndependentClass;
+ case attr::ObjCPreciseLifetime: return CXCursor_ObjCPreciseLifetime;
+ case attr::ObjCReturnsInnerPointer: return CXCursor_ObjCReturnsInnerPointer;
+ case attr::ObjCRequiresSuper: return CXCursor_ObjCRequiresSuper;
+ case attr::ObjCRootClass: return CXCursor_ObjCRootClass;
+ case attr::ObjCSubclassingRestricted: return CXCursor_ObjCSubclassingRestricted;
+ case attr::ObjCExplicitProtocolImpl: return CXCursor_ObjCExplicitProtocolImpl;
+ case attr::ObjCDesignatedInitializer: return CXCursor_ObjCDesignatedInitializer;
+ case attr::ObjCRuntimeVisible: return CXCursor_ObjCRuntimeVisible;
+ case attr::ObjCBoxable: return CXCursor_ObjCBoxable;
+ case attr::FlagEnum: return CXCursor_FlagEnum;
}
return CXCursor_UnexposedAttr;
@@ -223,16 +241,19 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
case Stmt::SEHLeaveStmtClass:
K = CXCursor_SEHLeaveStmt;
break;
-
+
+ case Stmt::CoroutineBodyStmtClass:
+ case Stmt::CoreturnStmtClass:
+ K = CXCursor_UnexposedStmt;
+ break;
+
case Stmt::ArrayTypeTraitExprClass:
case Stmt::AsTypeExprClass:
case Stmt::AtomicExprClass:
case Stmt::BinaryConditionalOperatorClass:
case Stmt::TypeTraitExprClass:
- case Stmt::CoroutineBodyStmtClass:
case Stmt::CoawaitExprClass:
case Stmt::DependentCoawaitExprClass:
- case Stmt::CoreturnStmtClass:
case Stmt::CoyieldExprClass:
case Stmt::CXXBindTemporaryExprClass:
case Stmt::CXXDefaultArgExprClass:
@@ -325,6 +346,10 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
K = CXCursor_CharacterLiteral;
break;
+ case Stmt::ConstantExprClass:
+ return MakeCXCursor(cast<ConstantExpr>(S)->getSubExpr(),
+ Parent, TU, RegionOfInterest);
+
case Stmt::ParenExprClass:
K = CXCursor_ParenExpr;
break;
@@ -990,10 +1015,6 @@ const Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
return static_cast<const Attr *>(Cursor.data[1]);
}
-const Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
- return static_cast<const Decl *>(Cursor.data[0]);
-}
-
ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
return getCursorASTUnit(Cursor)->getASTContext();
}
@@ -1146,6 +1167,9 @@ int clang_Cursor_getNumArguments(CXCursor C) {
if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
return CE->getNumArgs();
}
+ if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) {
+ return CE->getNumArgs();
+ }
}
return -1;
@@ -1174,6 +1198,13 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) {
cxcursor::getCursorTU(C));
}
}
+ if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) {
+ if (i < CE->getNumArgs()) {
+ return cxcursor::MakeCXCursor(CE->getArg(i),
+ getCursorDecl(C),
+ cxcursor::getCursorTU(C));
+ }
+ }
}
return clang_getNullCursor();
@@ -1394,16 +1425,16 @@ CXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
}
} else if (kind == CXCursor_MacroDefinition) {
const MacroDefinitionRecord *definition = getCursorMacroDefinition(cursor);
- const IdentifierInfo *MacroInfo = definition->getName();
+ const IdentifierInfo *Macro = definition->getName();
ASTUnit *unit = getCursorASTUnit(cursor);
- CodeCompletionResult Result(MacroInfo);
- CodeCompletionString *String
- = Result.CreateCodeCompletionString(unit->getASTContext(),
- unit->getPreprocessor(),
- CodeCompletionContext::CCC_Other,
- unit->getCodeCompletionTUInfo().getAllocator(),
- unit->getCodeCompletionTUInfo(),
- false);
+ CodeCompletionResult Result(
+ Macro,
+ unit->getPreprocessor().getMacroDefinition(Macro).getMacroInfo());
+ CodeCompletionString *String = Result.CreateCodeCompletionString(
+ unit->getASTContext(), unit->getPreprocessor(),
+ CodeCompletionContext::CCC_Other,
+ unit->getCodeCompletionTUInfo().getAllocator(),
+ unit->getCodeCompletionTUInfo(), false);
return String;
}
return nullptr;
diff --git a/tools/libclang/CXCursor.h b/tools/libclang/CXCursor.h
index a5d9fff2a55a..312fb3ff250b 100644
--- a/tools/libclang/CXCursor.h
+++ b/tools/libclang/CXCursor.h
@@ -43,11 +43,11 @@ class TemplateName;
class TypeDecl;
class VarDecl;
class IdentifierInfo;
-
+
namespace cxcursor {
CXCursor getCursor(CXTranslationUnit, SourceLocation);
-
+
CXCursor MakeCXCursor(const clang::Attr *A, const clang::Decl *Parent,
CXTranslationUnit TU);
CXCursor MakeCXCursor(const clang::Decl *D, CXTranslationUnit TU,
@@ -125,7 +125,7 @@ std::pair<const VarDecl *, SourceLocation> getCursorVariableRef(CXCursor C);
/// Create a reference to a field at the given location.
CXCursor MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
CXTranslationUnit TU);
-
+
/// Unpack a MemberRef cursor into the field it references and the
/// location where the reference occurred.
std::pair<const FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
@@ -232,17 +232,16 @@ CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
typedef llvm::PointerUnion3<const OverloadExpr *, const Decl *,
OverloadedTemplateStorage *>
OverloadedDeclRefStorage;
-
+
/// Unpack an overloaded declaration reference into an expression,
/// declaration, or template name along with the source location.
std::pair<OverloadedDeclRefStorage, SourceLocation>
getCursorOverloadedDeclRef(CXCursor C);
-
+
const Decl *getCursorDecl(CXCursor Cursor);
const Expr *getCursorExpr(CXCursor Cursor);
const Stmt *getCursorStmt(CXCursor Cursor);
const Attr *getCursorAttr(CXCursor Cursor);
-const Decl *getCursorParentDecl(CXCursor Cursor);
ASTContext &getCursorContext(CXCursor Cursor);
ASTUnit *getCursorASTUnit(CXCursor Cursor);
@@ -250,14 +249,14 @@ CXTranslationUnit getCursorTU(CXCursor Cursor);
void getOverriddenCursors(CXCursor cursor,
SmallVectorImpl<CXCursor> &overridden);
-
+
/// Create an opaque pool used for fast generation of overridden
/// CXCursor arrays.
void *createOverridenCXCursorsPool();
/// Dispose of the overridden CXCursors pool.
void disposeOverridenCXCursorsPool(void *pool);
-
+
/// Returns a index/location pair for a selector identifier if the cursor
/// points to one.
std::pair<int, SourceLocation> getSelectorIdentifierIndexAndLoc(CXCursor);
@@ -285,7 +284,7 @@ CXCursor getTypeRefCursor(CXCursor cursor);
bool getDeclCursorUSR(const Decl *D, SmallVectorImpl<char> &Buf);
bool operator==(CXCursor X, CXCursor Y);
-
+
inline bool operator!=(CXCursor X, CXCursor Y) {
return !(X == Y);
}
diff --git a/tools/libclang/CXIndexDataConsumer.cpp b/tools/libclang/CXIndexDataConsumer.cpp
index 616a0797f52b..3dec36a5daeb 100644
--- a/tools/libclang/CXIndexDataConsumer.cpp
+++ b/tools/libclang/CXIndexDataConsumer.cpp
@@ -222,9 +222,11 @@ bool CXIndexDataConsumer::handleDeclOccurence(
}
bool CXIndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
+ const Module *Mod,
SymbolRoleSet Roles,
SourceLocation Loc) {
- IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
+ if (Roles & (SymbolRoleSet)SymbolRole::Declaration)
+ IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
return !shouldAbort();
}
@@ -307,7 +309,7 @@ AttrListInfo::AttrListInfo(const Decl *D, CXIndexDataConsumer &IdxCtx)
const IBOutletCollectionAttr *
IBAttr = cast<IBOutletCollectionAttr>(IBInfo.A);
SourceLocation InterfaceLocStart =
- IBAttr->getInterfaceLoc()->getTypeLoc().getLocStart();
+ IBAttr->getInterfaceLoc()->getTypeLoc().getBeginLoc();
IBInfo.IBCollInfo.attrInfo = &IBInfo;
IBInfo.IBCollInfo.classLoc = IdxCtx.getIndexLoc(InterfaceLocStart);
IBInfo.IBCollInfo.objcClass = nullptr;
diff --git a/tools/libclang/CXIndexDataConsumer.h b/tools/libclang/CXIndexDataConsumer.h
index 19e39b281ab0..5c1ce80b2f49 100644
--- a/tools/libclang/CXIndexDataConsumer.h
+++ b/tools/libclang/CXIndexDataConsumer.h
@@ -467,7 +467,7 @@ private:
ArrayRef<index::SymbolRelation> Relations,
SourceLocation Loc, ASTNodeInfo ASTNode) override;
- bool handleModuleOccurence(const ImportDecl *ImportD,
+ bool handleModuleOccurence(const ImportDecl *ImportD, const Module *Mod,
index::SymbolRoleSet Roles,
SourceLocation Loc) override;
diff --git a/tools/libclang/CXStoredDiagnostic.cpp b/tools/libclang/CXStoredDiagnostic.cpp
index f2e9c1da28f6..6bd2f6746693 100644
--- a/tools/libclang/CXStoredDiagnostic.cpp
+++ b/tools/libclang/CXStoredDiagnostic.cpp
@@ -17,8 +17,8 @@
#include "CXSourceLocation.h"
#include "CXString.h"
+#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Frontend/ASTUnit.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
#include "llvm/ADT/Twine.h"
using namespace clang;
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 7c0f307944a1..b8009ddc1c1a 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -70,6 +70,8 @@ static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) {
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) BTCASE(Id);
#include "clang/Basic/OpenCLImageTypes.def"
#undef IMAGE_TYPE
+#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) BTCASE(Id);
+#include "clang/Basic/OpenCLExtensionTypes.def"
BTCASE(OCLSampler);
BTCASE(OCLEvent);
BTCASE(OCLQueue);
@@ -98,7 +100,9 @@ static CXTypeKind GetTypeKind(QualType T) {
TKCASE(Enum);
TKCASE(Typedef);
TKCASE(ObjCInterface);
+ TKCASE(ObjCObject);
TKCASE(ObjCObjectPointer);
+ TKCASE(ObjCTypeParam);
TKCASE(FunctionNoProto);
TKCASE(FunctionProto);
TKCASE(ConstantArray);
@@ -110,6 +114,7 @@ static CXTypeKind GetTypeKind(QualType T) {
TKCASE(Auto);
TKCASE(Elaborated);
TKCASE(Pipe);
+ TKCASE(Attributed);
default:
return CXType_Unexposed;
}
@@ -123,7 +128,9 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
if (TU && !T.isNull()) {
// Handle attributed types as the original type
if (auto *ATT = T->getAs<AttributedType>()) {
- return MakeCXType(ATT->getModifiedType(), TU);
+ if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes)) {
+ return MakeCXType(ATT->getModifiedType(), TU);
+ }
}
// Handle paren types as the original type
if (auto *PTT = T->getAs<ParenType>()) {
@@ -131,7 +138,7 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
}
ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext();
- if (Ctx.getLangOpts().ObjC1) {
+ if (Ctx.getLangOpts().ObjC) {
QualType UnqualT = T.getUnqualifiedType();
if (Ctx.isObjCIdType(UnqualT))
TK = CXType_ObjCId;
@@ -437,6 +444,7 @@ CXType clang_getPointeeType(CXType CT) {
if (!TP)
return MakeCXType(QualType(), GetTU(CT));
+try_again:
switch (TP->getTypeClass()) {
case Type::Pointer:
T = cast<PointerType>(TP)->getPointeeType();
@@ -454,6 +462,12 @@ CXType clang_getPointeeType(CXType CT) {
case Type::MemberPointer:
T = cast<MemberPointerType>(TP)->getPointeeType();
break;
+ case Type::Auto:
+ case Type::DeducedTemplateSpecialization:
+ TP = cast<DeducedType>(TP)->getDeducedType().getTypePtrOrNull();
+ if (TP)
+ goto try_again;
+ break;
default:
T = QualType();
break;
@@ -575,7 +589,9 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
TKIND(Enum);
TKIND(Typedef);
TKIND(ObjCInterface);
+ TKIND(ObjCObject);
TKIND(ObjCObjectPointer);
+ TKIND(ObjCTypeParam);
TKIND(FunctionNoProto);
TKIND(FunctionProto);
TKIND(ConstantArray);
@@ -587,9 +603,12 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
TKIND(Auto);
TKIND(Elaborated);
TKIND(Pipe);
+ TKIND(Attributed);
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id);
#include "clang/Basic/OpenCLImageTypes.def"
#undef IMAGE_TYPE
+#define EXT_OPAQUE_TYPE(ExtTYpe, Id, Ext) TKIND(Id);
+#include "clang/Basic/OpenCLExtensionTypes.def"
TKIND(OCLSampler);
TKIND(OCLEvent);
TKIND(OCLQueue);
@@ -632,6 +651,7 @@ CXCallingConv clang_getFunctionTypeCallingConv(CXType X) {
TCALLINGCONV(X86Pascal);
TCALLINGCONV(X86RegCall);
TCALLINGCONV(X86VectorCall);
+ TCALLINGCONV(AArch64VectorCall);
TCALLINGCONV(Win64);
TCALLINGCONV(X86_64SysV);
TCALLINGCONV(AAPCS);
@@ -992,6 +1012,17 @@ long long clang_Type_getOffsetOf(CXType PT, const char *S) {
return CXTypeLayoutError_InvalidFieldName;
}
+CXType clang_Type_getModifiedType(CXType CT) {
+ QualType T = GetQualType(CT);
+ if (T.isNull())
+ return MakeCXType(QualType(), GetTU(CT));
+
+ if (auto *ATT = T->getAs<AttributedType>())
+ return MakeCXType(ATT->getModifiedType(), GetTU(CT));
+
+ return MakeCXType(QualType(), GetTU(CT));
+}
+
long long clang_Cursor_getOffsetOfField(CXCursor C) {
if (clang_isDeclaration(C.kind)) {
// we need to validate the parent type
@@ -1098,6 +1129,74 @@ CXType clang_Type_getTemplateArgumentAsType(CXType CT, unsigned index) {
return MakeCXType(QT.getValueOr(QualType()), GetTU(CT));
}
+CXType clang_Type_getObjCObjectBaseType(CXType CT) {
+ QualType T = GetQualType(CT);
+ if (T.isNull())
+ return MakeCXType(QualType(), GetTU(CT));
+
+ const ObjCObjectType *OT = dyn_cast<ObjCObjectType>(T);
+ if (!OT)
+ return MakeCXType(QualType(), GetTU(CT));
+
+ return MakeCXType(OT->getBaseType(), GetTU(CT));
+}
+
+unsigned clang_Type_getNumObjCProtocolRefs(CXType CT) {
+ QualType T = GetQualType(CT);
+ if (T.isNull())
+ return 0;
+
+ const ObjCObjectType *OT = dyn_cast<ObjCObjectType>(T);
+ if (!OT)
+ return 0;
+
+ return OT->getNumProtocols();
+}
+
+CXCursor clang_Type_getObjCProtocolDecl(CXType CT, unsigned i) {
+ QualType T = GetQualType(CT);
+ if (T.isNull())
+ return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
+
+ const ObjCObjectType *OT = dyn_cast<ObjCObjectType>(T);
+ if (!OT)
+ return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
+
+ const ObjCProtocolDecl *PD = OT->getProtocol(i);
+ if (!PD)
+ return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
+
+ return cxcursor::MakeCXCursor(PD, GetTU(CT));
+}
+
+unsigned clang_Type_getNumObjCTypeArgs(CXType CT) {
+ QualType T = GetQualType(CT);
+ if (T.isNull())
+ return 0;
+
+ const ObjCObjectType *OT = dyn_cast<ObjCObjectType>(T);
+ if (!OT)
+ return 0;
+
+ return OT->getTypeArgs().size();
+}
+
+CXType clang_Type_getObjCTypeArg(CXType CT, unsigned i) {
+ QualType T = GetQualType(CT);
+ if (T.isNull())
+ return MakeCXType(QualType(), GetTU(CT));
+
+ const ObjCObjectType *OT = dyn_cast<ObjCObjectType>(T);
+ if (!OT)
+ return MakeCXType(QualType(), GetTU(CT));
+
+ const ArrayRef<QualType> TA = OT->getTypeArgs();
+ if ((size_t)i >= TA.size())
+ return MakeCXType(QualType(), GetTU(CT));
+
+ return MakeCXType(TA[i], GetTU(CT));
+}
+
unsigned clang_Type_visitFields(CXType PT,
CXFieldVisitor visitor,
CXClientData client_data){
@@ -1130,11 +1229,15 @@ unsigned clang_Cursor_isAnonymous(CXCursor C){
if (!clang_isDeclaration(C.kind))
return 0;
const Decl *D = cxcursor::getCursorDecl(C);
- if (const RecordDecl *FD = dyn_cast_or_null<RecordDecl>(D))
- return FD->isAnonymousStructOrUnion();
+ if (const NamespaceDecl *ND = dyn_cast_or_null<NamespaceDecl>(D)) {
+ return ND->isAnonymousNamespace();
+ } else if (const TagDecl *TD = dyn_cast_or_null<TagDecl>(D)) {
+ return TD->getTypedefNameForAnonDecl() == nullptr &&
+ TD->getIdentifier() == nullptr;
+ }
+
return 0;
}
-
CXType clang_Type_getNamedType(CXType CT){
QualType T = GetQualType(CT);
const Type *TP = T.getTypePtrOrNull();
@@ -1153,3 +1256,22 @@ unsigned clang_Type_isTransparentTagTypedef(CXType TT){
}
return false;
}
+
+enum CXTypeNullabilityKind clang_Type_getNullability(CXType CT) {
+ QualType T = GetQualType(CT);
+ if (T.isNull())
+ return CXTypeNullability_Invalid;
+
+ ASTContext &Ctx = cxtu::getASTUnit(GetTU(CT))->getASTContext();
+ if (auto nullability = T->getNullability(Ctx)) {
+ switch (*nullability) {
+ case NullabilityKind::NonNull:
+ return CXTypeNullability_NonNull;
+ case NullabilityKind::Nullable:
+ return CXTypeNullability_Nullable;
+ case NullabilityKind::Unspecified:
+ return CXTypeNullability_Unspecified;
+ }
+ }
+ return CXTypeNullability_Invalid;
+}
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 95a42712c4af..2c4b083a594a 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -31,6 +31,8 @@ clang_Cursor_getRawCommentText
clang_Cursor_getNumArguments
clang_Cursor_getObjCDeclQualifiers
clang_Cursor_getObjCPropertyAttributes
+clang_Cursor_getObjCPropertyGetterName
+clang_Cursor_getObjCPropertySetterName
clang_Cursor_getObjCSelectorIndex
clang_Cursor_getOffsetOfField
clang_Cursor_getSpellingNameRange
@@ -98,6 +100,13 @@ clang_Type_getCXXRefQualifier
clang_Type_visitFields
clang_Type_getNamedType
clang_Type_isTransparentTagTypedef
+clang_Type_getObjCObjectBaseType
+clang_Type_getNumObjCProtocolRefs
+clang_Type_getObjCProtocolDecl
+clang_Type_getNumObjCTypeArgs
+clang_Type_getObjCTypeArg
+clang_Type_getModifiedType
+clang_Type_getNullability
clang_VerbatimBlockLineComment_getText
clang_VerbatimLineComment_getText
clang_HTMLTagComment_getAsString