summaryrefslogtreecommitdiff
path: root/tools/libclang
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 11:06:01 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 11:06:01 +0000
commit486754660bb926339aefcf012a3f848592babb8b (patch)
treeecdbc446c9876f4f120f701c243373cd3cb43db3 /tools/libclang
parent55e6d896ad333f07bb3b1ba487df214fc268a4ab (diff)
Notes
Diffstat (limited to 'tools/libclang')
-rw-r--r--tools/libclang/BuildSystem.cpp5
-rw-r--r--tools/libclang/CIndex.cpp344
-rw-r--r--tools/libclang/CIndexCodeCompletion.cpp97
-rw-r--r--tools/libclang/CIndexDiagnostic.h42
-rw-r--r--tools/libclang/CIndexHigh.cpp4
-rw-r--r--tools/libclang/CIndexer.cpp14
-rw-r--r--tools/libclang/CIndexer.h22
-rw-r--r--tools/libclang/CLog.h4
-rw-r--r--tools/libclang/CMakeLists.txt2
-rw-r--r--tools/libclang/CXCursor.cpp20
-rw-r--r--tools/libclang/CXCursor.h80
-rw-r--r--tools/libclang/CXIndexDataConsumer.cpp37
-rw-r--r--tools/libclang/CXIndexDataConsumer.h13
-rw-r--r--tools/libclang/CXLoadedDiagnostic.cpp2
-rw-r--r--tools/libclang/CXLoadedDiagnostic.h22
-rw-r--r--tools/libclang/CXSourceLocation.h8
-rw-r--r--tools/libclang/CXString.cpp2
-rw-r--r--tools/libclang/CXString.h20
-rw-r--r--tools/libclang/CXType.cpp46
-rw-r--r--tools/libclang/CursorVisitor.h24
-rw-r--r--tools/libclang/Index_Internal.h8
-rw-r--r--tools/libclang/Indexing.cpp25
-rw-r--r--tools/libclang/libclang.exports11
23 files changed, 624 insertions, 228 deletions
diff --git a/tools/libclang/BuildSystem.cpp b/tools/libclang/BuildSystem.cpp
index 99aa5b6f2ff0d..79fa69c40bae1 100644
--- a/tools/libclang/BuildSystem.cpp
+++ b/tools/libclang/BuildSystem.cpp
@@ -17,6 +17,7 @@
#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/raw_ostream.h"
@@ -78,7 +79,7 @@ clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay VFO, unsigned,
unwrap(VFO)->write(OS);
StringRef Data = OS.str();
- *out_buffer_ptr = (char*)malloc(Data.size());
+ *out_buffer_ptr = static_cast<char*>(llvm::safe_malloc(Data.size()));
*out_buffer_size = Data.size();
memcpy(*out_buffer_ptr, Data.data(), Data.size());
return CXError_Success;
@@ -140,7 +141,7 @@ clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor MMD, unsigned,
OS << "}\n";
StringRef Data = OS.str();
- *out_buffer_ptr = (char*)malloc(Data.size());
+ *out_buffer_ptr = static_cast<char*>(llvm::safe_malloc(Data.size()));
*out_buffer_size = Data.size();
memcpy(*out_buffer_ptr, Data.data(), Data.size());
return CXError_Success;
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index f4d347108c9ff..499d9abf9a8ef 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -26,6 +26,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticCategories.h"
#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/Stack.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
#include "clang/Frontend/ASTUnit.h"
@@ -103,7 +104,7 @@ cxtu::CXTUOwner::~CXTUOwner() {
clang_disposeTranslationUnit(TU);
}
-/// \brief Compare two source ranges to determine their relative position in
+/// Compare two source ranges to determine their relative position in
/// the translation unit.
static RangeComparisonResult RangeCompare(SourceManager &SM,
SourceRange R1,
@@ -119,7 +120,7 @@ static RangeComparisonResult RangeCompare(SourceManager &SM,
return RangeOverlap;
}
-/// \brief Determine if a source location falls within, before, or after a
+/// Determine if a source location falls within, before, or after a
/// a given source range.
static RangeComparisonResult LocationCompare(SourceManager &SM,
SourceLocation L, SourceRange R) {
@@ -134,7 +135,7 @@ static RangeComparisonResult LocationCompare(SourceManager &SM,
return RangeOverlap;
}
-/// \brief Translate a Clang source range into a CIndex source range.
+/// Translate a Clang source range into a CIndex source range.
///
/// Clang internally represents ranges where the end location points to the
/// start of the token at the end. However, for external clients it is more
@@ -146,9 +147,13 @@ CXSourceRange cxloc::translateSourceRange(const SourceManager &SM,
// We want the last character in this location, so we will adjust the
// location accordingly.
SourceLocation EndLoc = R.getEnd();
- if (EndLoc.isValid() && EndLoc.isMacroID() && !SM.isMacroArgExpansion(EndLoc))
- EndLoc = SM.getExpansionRange(EndLoc).second;
- if (R.isTokenRange() && EndLoc.isValid()) {
+ bool IsTokenRange = R.isTokenRange();
+ if (EndLoc.isValid() && EndLoc.isMacroID() && !SM.isMacroArgExpansion(EndLoc)) {
+ CharSourceRange Expansion = SM.getExpansionRange(EndLoc);
+ EndLoc = Expansion.getEnd();
+ IsTokenRange = Expansion.isTokenRange();
+ }
+ if (IsTokenRange && EndLoc.isValid()) {
unsigned Length = Lexer::MeasureTokenLength(SM.getSpellingLoc(EndLoc),
SM, LangOpts);
EndLoc = EndLoc.getLocWithOffset(Length);
@@ -174,7 +179,7 @@ RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) {
return RangeCompare(AU->getSourceManager(), R, RegionOfInterest);
}
-/// \brief Visit the given cursor and, if requested by the visitor,
+/// Visit the given cursor and, if requested by the visitor,
/// its children.
///
/// \param Cursor the cursor to visit.
@@ -478,7 +483,7 @@ bool CursorVisitor::visitPreprocessedEntities(InputIterator First,
return false;
}
-/// \brief Visit the children of the given cursor.
+/// Visit the children of the given cursor.
///
/// \returns true if the visitation should be aborted, false if it
/// should continue.
@@ -785,7 +790,17 @@ bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) {
return false;
}
-/// \brief Compare two base or member initializers based on their source order.
+static bool HasTrailingReturnType(FunctionDecl *ND) {
+ const QualType Ty = ND->getType();
+ if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
+ if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(AFT))
+ return FT->hasTrailingReturn();
+ }
+
+ return false;
+}
+
+/// Compare two base or member initializers based on their source order.
static int CompareCXXCtorInitializers(CXXCtorInitializer *const *X,
CXXCtorInitializer *const *Y) {
return (*X)->getSourceOrder() - (*Y)->getSourceOrder();
@@ -804,14 +819,16 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
// written. This requires a bit of work.
TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>();
+ const bool HasTrailingRT = HasTrailingReturnType(ND);
// If we have a function declared directly (without the use of a typedef),
// visit just the return type. Otherwise, just visit the function's type
// now.
- if ((FTL && !isa<CXXConversionDecl>(ND) && Visit(FTL.getReturnLoc())) ||
+ if ((FTL && !isa<CXXConversionDecl>(ND) && !HasTrailingRT &&
+ Visit(FTL.getReturnLoc())) ||
(!FTL && Visit(TL)))
return true;
-
+
// Visit the nested-name-specifier, if present.
if (NestedNameSpecifierLoc QualifierLoc = ND->getQualifierLoc())
if (VisitNestedNameSpecifierLoc(QualifierLoc))
@@ -827,7 +844,11 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
// Visit the function parameters, if we have a function type.
if (FTL && VisitFunctionTypeLoc(FTL, true))
return true;
-
+
+ // Visit the function's trailing return type.
+ if (FTL && HasTrailingRT && Visit(FTL.getReturnLoc()))
+ return true;
+
// FIXME: Attributes?
}
@@ -1023,8 +1044,8 @@ bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) {
}
// Now sort the Decls so that they appear in lexical order.
- std::sort(DeclsInContainer.begin(), DeclsInContainer.end(),
- [&SM](Decl *A, Decl *B) {
+ llvm::sort(DeclsInContainer.begin(), DeclsInContainer.end(),
+ [&SM](Decl *A, Decl *B) {
SourceLocation L_A = A->getLocStart();
SourceLocation L_B = B->getLocStart();
return L_A != L_B ?
@@ -1751,6 +1772,7 @@ DEFAULT_TYPELOC_IMPL(IncompleteArray, ArrayType)
DEFAULT_TYPELOC_IMPL(VariableArray, ArrayType)
DEFAULT_TYPELOC_IMPL(DependentSizedArray, ArrayType)
DEFAULT_TYPELOC_IMPL(DependentAddressSpace, Type)
+DEFAULT_TYPELOC_IMPL(DependentVector, Type)
DEFAULT_TYPELOC_IMPL(DependentSizedExtVector, Type)
DEFAULT_TYPELOC_IMPL(Vector, Type)
DEFAULT_TYPELOC_IMPL(ExtVector, VectorType)
@@ -1780,7 +1802,7 @@ bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) {
bool CursorVisitor::VisitAttributes(Decl *D) {
for (const auto *I : D->attrs())
- if (Visit(MakeCXCursor(I, D, TU)))
+ if (!I->isImplicit() && Visit(MakeCXCursor(I, D, TU)))
return true;
return false;
@@ -2099,7 +2121,7 @@ void EnqueueVisitor::EnqueueChildren(const Stmt *S) {
namespace {
class OMPClauseEnqueue : public ConstOMPClauseVisitor<OMPClauseEnqueue> {
EnqueueVisitor *Visitor;
- /// \brief Process clauses with list of variables.
+ /// Process clauses with list of variables.
template <typename T>
void VisitOMPClauseList(T *Node);
public:
@@ -2577,7 +2599,7 @@ void EnqueueVisitor::VisitMemberExpr(const MemberExpr *M) {
return;
// Ignore base anonymous struct/union fields, otherwise they will shadow the
- // real field that that we are interested in.
+ // real field that we are interested in.
if (auto *SubME = dyn_cast<MemberExpr>(M->getBase())) {
if (auto *FD = dyn_cast_or_null<FieldDecl>(SubME->getMemberDecl())) {
if (FD->isAnonymousStructOrUnion()) {
@@ -3360,9 +3382,15 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename,
= options & CXTranslationUnit_CacheCompletionResults;
bool IncludeBriefCommentsInCodeCompletion
= options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
- bool SkipFunctionBodies = options & CXTranslationUnit_SkipFunctionBodies;
bool SingleFileParse = options & CXTranslationUnit_SingleFileParse;
bool ForSerialization = options & CXTranslationUnit_ForSerialization;
+ SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None;
+ if (options & CXTranslationUnit_SkipFunctionBodies) {
+ SkipFunctionBodies =
+ (options & CXTranslationUnit_LimitSkipFunctionBodiesToPreamble)
+ ? SkipFunctionBodiesScope::Preamble
+ : SkipFunctionBodiesScope::PreambleAndMainFile;
+ }
// Configure the diagnostics.
IntrusiveRefCntPtr<DiagnosticsEngine>
@@ -4233,6 +4261,14 @@ int clang_File_isEqual(CXFile file1, CXFile file2) {
return FEnt1->getUniqueID() == FEnt2->getUniqueID();
}
+CXString clang_File_tryGetRealPathName(CXFile SFile) {
+ if (!SFile)
+ return cxstring::createNull();
+
+ FileEntry *FEnt = static_cast<FileEntry *>(SFile);
+ return cxstring::createRef(FEnt->tryGetRealPathName());
+}
+
//===----------------------------------------------------------------------===//
// CXCursor Operations.
//===----------------------------------------------------------------------===//
@@ -4690,6 +4726,195 @@ CXStringSet *clang_Cursor_getObjCManglings(CXCursor C) {
return cxstring::createSet(Manglings);
}
+CXPrintingPolicy clang_getCursorPrintingPolicy(CXCursor C) {
+ if (clang_Cursor_isNull(C))
+ return 0;
+ return new PrintingPolicy(getCursorContext(C).getPrintingPolicy());
+}
+
+void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy) {
+ if (Policy)
+ delete static_cast<PrintingPolicy *>(Policy);
+}
+
+unsigned
+clang_PrintingPolicy_getProperty(CXPrintingPolicy Policy,
+ enum CXPrintingPolicyProperty Property) {
+ if (!Policy)
+ return 0;
+
+ PrintingPolicy *P = static_cast<PrintingPolicy *>(Policy);
+ switch (Property) {
+ case CXPrintingPolicy_Indentation:
+ return P->Indentation;
+ case CXPrintingPolicy_SuppressSpecifiers:
+ return P->SuppressSpecifiers;
+ case CXPrintingPolicy_SuppressTagKeyword:
+ return P->SuppressTagKeyword;
+ case CXPrintingPolicy_IncludeTagDefinition:
+ return P->IncludeTagDefinition;
+ case CXPrintingPolicy_SuppressScope:
+ return P->SuppressScope;
+ case CXPrintingPolicy_SuppressUnwrittenScope:
+ return P->SuppressUnwrittenScope;
+ case CXPrintingPolicy_SuppressInitializers:
+ return P->SuppressInitializers;
+ case CXPrintingPolicy_ConstantArraySizeAsWritten:
+ return P->ConstantArraySizeAsWritten;
+ case CXPrintingPolicy_AnonymousTagLocations:
+ return P->AnonymousTagLocations;
+ case CXPrintingPolicy_SuppressStrongLifetime:
+ return P->SuppressStrongLifetime;
+ case CXPrintingPolicy_SuppressLifetimeQualifiers:
+ return P->SuppressLifetimeQualifiers;
+ case CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors:
+ return P->SuppressTemplateArgsInCXXConstructors;
+ case CXPrintingPolicy_Bool:
+ return P->Bool;
+ case CXPrintingPolicy_Restrict:
+ return P->Restrict;
+ case CXPrintingPolicy_Alignof:
+ return P->Alignof;
+ case CXPrintingPolicy_UnderscoreAlignof:
+ return P->UnderscoreAlignof;
+ case CXPrintingPolicy_UseVoidForZeroParams:
+ return P->UseVoidForZeroParams;
+ case CXPrintingPolicy_TerseOutput:
+ return P->TerseOutput;
+ case CXPrintingPolicy_PolishForDeclaration:
+ return P->PolishForDeclaration;
+ case CXPrintingPolicy_Half:
+ return P->Half;
+ case CXPrintingPolicy_MSWChar:
+ return P->MSWChar;
+ case CXPrintingPolicy_IncludeNewlines:
+ return P->IncludeNewlines;
+ case CXPrintingPolicy_MSVCFormatting:
+ return P->MSVCFormatting;
+ case CXPrintingPolicy_ConstantsAsWritten:
+ return P->ConstantsAsWritten;
+ case CXPrintingPolicy_SuppressImplicitBase:
+ return P->SuppressImplicitBase;
+ case CXPrintingPolicy_FullyQualifiedName:
+ return P->FullyQualifiedName;
+ }
+
+ assert(false && "Invalid CXPrintingPolicyProperty");
+ return 0;
+}
+
+void clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy,
+ enum CXPrintingPolicyProperty Property,
+ unsigned Value) {
+ if (!Policy)
+ return;
+
+ PrintingPolicy *P = static_cast<PrintingPolicy *>(Policy);
+ switch (Property) {
+ case CXPrintingPolicy_Indentation:
+ P->Indentation = Value;
+ return;
+ case CXPrintingPolicy_SuppressSpecifiers:
+ P->SuppressSpecifiers = Value;
+ return;
+ case CXPrintingPolicy_SuppressTagKeyword:
+ P->SuppressTagKeyword = Value;
+ return;
+ case CXPrintingPolicy_IncludeTagDefinition:
+ P->IncludeTagDefinition = Value;
+ return;
+ case CXPrintingPolicy_SuppressScope:
+ P->SuppressScope = Value;
+ return;
+ case CXPrintingPolicy_SuppressUnwrittenScope:
+ P->SuppressUnwrittenScope = Value;
+ return;
+ case CXPrintingPolicy_SuppressInitializers:
+ P->SuppressInitializers = Value;
+ return;
+ case CXPrintingPolicy_ConstantArraySizeAsWritten:
+ P->ConstantArraySizeAsWritten = Value;
+ return;
+ case CXPrintingPolicy_AnonymousTagLocations:
+ P->AnonymousTagLocations = Value;
+ return;
+ case CXPrintingPolicy_SuppressStrongLifetime:
+ P->SuppressStrongLifetime = Value;
+ return;
+ case CXPrintingPolicy_SuppressLifetimeQualifiers:
+ P->SuppressLifetimeQualifiers = Value;
+ return;
+ case CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors:
+ P->SuppressTemplateArgsInCXXConstructors = Value;
+ return;
+ case CXPrintingPolicy_Bool:
+ P->Bool = Value;
+ return;
+ case CXPrintingPolicy_Restrict:
+ P->Restrict = Value;
+ return;
+ case CXPrintingPolicy_Alignof:
+ P->Alignof = Value;
+ return;
+ case CXPrintingPolicy_UnderscoreAlignof:
+ P->UnderscoreAlignof = Value;
+ return;
+ case CXPrintingPolicy_UseVoidForZeroParams:
+ P->UseVoidForZeroParams = Value;
+ return;
+ case CXPrintingPolicy_TerseOutput:
+ P->TerseOutput = Value;
+ return;
+ case CXPrintingPolicy_PolishForDeclaration:
+ P->PolishForDeclaration = Value;
+ return;
+ case CXPrintingPolicy_Half:
+ P->Half = Value;
+ return;
+ case CXPrintingPolicy_MSWChar:
+ P->MSWChar = Value;
+ return;
+ case CXPrintingPolicy_IncludeNewlines:
+ P->IncludeNewlines = Value;
+ return;
+ case CXPrintingPolicy_MSVCFormatting:
+ P->MSVCFormatting = Value;
+ return;
+ case CXPrintingPolicy_ConstantsAsWritten:
+ P->ConstantsAsWritten = Value;
+ return;
+ case CXPrintingPolicy_SuppressImplicitBase:
+ P->SuppressImplicitBase = Value;
+ return;
+ case CXPrintingPolicy_FullyQualifiedName:
+ P->FullyQualifiedName = Value;
+ return;
+ }
+
+ assert(false && "Invalid CXPrintingPolicyProperty");
+}
+
+CXString clang_getCursorPrettyPrinted(CXCursor C, CXPrintingPolicy cxPolicy) {
+ if (clang_Cursor_isNull(C))
+ return cxstring::createEmpty();
+
+ if (clang_isDeclaration(C.kind)) {
+ const Decl *D = getCursorDecl(C);
+ if (!D)
+ return cxstring::createEmpty();
+
+ SmallString<128> Str;
+ llvm::raw_svector_ostream OS(Str);
+ PrintingPolicy *UserPolicy = static_cast<PrintingPolicy *>(cxPolicy);
+ D->print(OS, UserPolicy ? *UserPolicy
+ : getCursorContext(C).getPrintingPolicy());
+
+ return cxstring::createDup(OS.str());
+ }
+
+ return cxstring::createEmpty();
+}
+
CXString clang_getCursorDisplayName(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return clang_getCursorSpelling(C);
@@ -4838,6 +5063,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("VariableRef");
case CXCursor_IntegerLiteral:
return cxstring::createRef("IntegerLiteral");
+ case CXCursor_FixedPointLiteral:
+ return cxstring::createRef("FixedPointLiteral");
case CXCursor_FloatingLiteral:
return cxstring::createRef("FloatingLiteral");
case CXCursor_ImaginaryLiteral:
@@ -5421,6 +5648,15 @@ unsigned clang_isDeclaration(enum CXCursorKind K) {
(K >= CXCursor_FirstExtraDecl && K <= CXCursor_LastExtraDecl);
}
+unsigned clang_isInvalidDeclaration(CXCursor C) {
+ if (clang_isDeclaration(C.kind)) {
+ if (const Decl *D = getCursorDecl(C))
+ return D->isInvalidDecl();
+ }
+
+ return 0;
+}
+
unsigned clang_isReference(enum CXCursorKind K) {
return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
}
@@ -5727,7 +5963,7 @@ static SourceRange getRawCursorExtent(CXCursor C) {
return SourceRange();
}
-/// \brief Retrieves the "raw" cursor extent, which is then extended to include
+/// Retrieves the "raw" cursor extent, which is then extended to include
/// the decl-specifier-seq for declarations.
static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr) {
if (clang_isDeclaration(C.kind)) {
@@ -6420,6 +6656,42 @@ static void getTokens(ASTUnit *CXXUnit, SourceRange Range,
} while (Lex.getBufferLocation() < EffectiveBufferEnd);
}
+CXToken *clang_getToken(CXTranslationUnit TU, CXSourceLocation Location) {
+ LOG_FUNC_SECTION {
+ *Log << TU << ' ' << Location;
+ }
+
+ if (isNotUsableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return NULL;
+ }
+
+ ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
+ if (!CXXUnit)
+ return NULL;
+
+ SourceLocation Begin = cxloc::translateSourceLocation(Location);
+ if (Begin.isInvalid())
+ return NULL;
+ SourceManager &SM = CXXUnit->getSourceManager();
+ std::pair<FileID, unsigned> DecomposedEnd = SM.getDecomposedLoc(Begin);
+ DecomposedEnd.second += Lexer::MeasureTokenLength(Begin, SM, CXXUnit->getLangOpts());
+
+ SourceLocation End = SM.getComposedLoc(DecomposedEnd.first, DecomposedEnd.second);
+
+ SmallVector<CXToken, 32> CXTokens;
+ getTokens(CXXUnit, SourceRange(Begin, End), CXTokens);
+
+ if (CXTokens.empty())
+ return NULL;
+
+ CXTokens.resize(1);
+ CXToken *Token = static_cast<CXToken *>(llvm::safe_malloc(sizeof(CXToken)));
+
+ memmove(Token, CXTokens.data(), sizeof(CXToken));
+ return Token;
+}
+
void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
CXToken **Tokens, unsigned *NumTokens) {
LOG_FUNC_SECTION {
@@ -6452,7 +6724,8 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
if (CXTokens.empty())
return;
- *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());
+ *Tokens = static_cast<CXToken *>(
+ llvm::safe_malloc(sizeof(CXToken) * CXTokens.size()));
memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());
*NumTokens = CXTokens.size();
}
@@ -6536,7 +6809,7 @@ public:
bool postVisitChildren(CXCursor cursor);
void AnnotateTokens();
- /// \brief Determine whether the annotator saw any cursors that have
+ /// Determine whether the annotator saw any cursors that have
/// context-sensitive keywords.
bool hasContextSensitiveKeywords() const {
return HasContextSensitiveKeywords;
@@ -6561,7 +6834,7 @@ static inline void updateCursorAnnotation(CXCursor &Cursor,
Cursor = updateC;
}
-/// \brief It annotates and advances tokens with a cursor until the comparison
+/// It annotates and advances tokens with a cursor until the comparison
//// between the cursor location and the source range is the same as
/// \arg compResult.
///
@@ -6586,7 +6859,7 @@ void AnnotateTokensWorker::annotateAndAdvanceTokens(CXCursor updateC,
}
}
-/// \brief Special annotation handling for macro argument tokens.
+/// Special annotation handling for macro argument tokens.
/// \returns true if it advanced beyond all macro tokens, false otherwise.
bool AnnotateTokensWorker::annotateAndAdvanceFunctionMacroTokens(
CXCursor updateC,
@@ -6830,7 +7103,7 @@ static bool AnnotateTokensPostChildrenVisitor(CXCursor cursor,
namespace {
-/// \brief Uses the macro expansions in the preprocessing record to find
+/// Uses the macro expansions in the preprocessing record to find
/// and mark tokens that are macro arguments. This info is used by the
/// AnnotateTokensWorker.
class MarkMacroArgTokensVisitor {
@@ -6905,7 +7178,7 @@ MarkMacroArgTokensVisitorDelegate(CXCursor cursor, CXCursor parent,
parent);
}
-/// \brief Used by \c annotatePreprocessorTokens.
+/// Used by \c annotatePreprocessorTokens.
/// \returns true if lexing was finished, false otherwise.
static bool lexNext(Lexer &Lex, Token &Tok,
unsigned &NextIdx, unsigned NumTokens) {
@@ -7358,10 +7631,10 @@ static void getCursorPlatformAvailabilityForDecl(
if (AvailabilityAttrs.empty())
return;
- std::sort(AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
- [](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
- return LHS->getPlatform()->getName() <
- RHS->getPlatform()->getName();
+ llvm::sort(AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
+ [](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
+ return LHS->getPlatform()->getName() <
+ RHS->getPlatform()->getName();
});
ASTContext &Ctx = D->getASTContext();
auto It = std::unique(
@@ -7479,8 +7752,8 @@ CXTLSKind clang_getCursorTLSKind(CXCursor cursor) {
return CXTLS_None;
}
- /// \brief If the given cursor is the "templated" declaration
- /// descibing a class or function template, return the class or
+ /// If the given cursor is the "templated" declaration
+ /// describing a class or function template, return the class or
/// function template.
static const Decl *maybeGetTemplateCursor(const Decl *D) {
if (!D)
@@ -8135,6 +8408,7 @@ CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit TU, CXFile file) {
SourceManager &sm = Ctx.getSourceManager();
FileEntry *fileEntry = static_cast<FileEntry *>(file);
FileID wantedFileID = sm.translateFile(fileEntry);
+ bool isMainFile = wantedFileID == sm.getMainFileID();
const std::vector<SourceRange> &SkippedRanges = ppRec->getSkippedRanges();
std::vector<SourceRange> wantedRanges;
@@ -8142,6 +8416,8 @@ CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit TU, CXFile file) {
i != ei; ++i) {
if (sm.getFileID(i->getBegin()) == wantedFileID || sm.getFileID(i->getEnd()) == wantedFileID)
wantedRanges.push_back(*i);
+ else if (isMainFile && (astUnit->isInPreambleFileID(i->getBegin()) || astUnit->isInPreambleFileID(i->getEnd())))
+ wantedRanges.push_back(*i);
}
skipped->count = wantedRanges.size();
@@ -8200,8 +8476,8 @@ void clang::PrintLibclangResourceUsage(CXTranslationUnit TU) {
// Misc. utility functions.
//===----------------------------------------------------------------------===//
-/// Default to using an 8 MB stack size on "safety" threads.
-static unsigned SafetyStackThreadSize = 8 << 20;
+/// Default to using our desired 8 MB stack size on "safety" threads.
+static unsigned SafetyStackThreadSize = DesiredStackSize;
namespace clang {
@@ -8246,7 +8522,7 @@ void cxindex::printDiagsToStderr(ASTUnit *Unit) {
fprintf(stderr, "%s\n", clang_getCString(Msg));
clang_disposeString(Msg);
}
-#ifdef LLVM_ON_WIN32
+#ifdef _WIN32
// On Windows, force a flush, since there may be multiple copies of
// stderr and stdout in the file system, all with different buffers
// but writing to the same device.
diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp
index d4af0870c0b60..f49f9763c362a 100644
--- a/tools/libclang/CIndexCodeCompletion.cpp
+++ b/tools/libclang/CIndexCodeCompletion.cpp
@@ -16,6 +16,7 @@
#include "CIndexDiagnostic.h"
#include "CLog.h"
#include "CXCursor.h"
+#include "CXSourceLocation.h"
#include "CXString.h"
#include "CXTranslationUnit.h"
#include "clang/AST/Decl.h"
@@ -240,7 +241,7 @@ clang_getCompletionBriefComment(CXCompletionString completion_string) {
namespace {
-/// \brief The CXCodeCompleteResults structure we allocate internally;
+/// The CXCodeCompleteResults structure we allocate internally;
/// the client only sees the initial CXCodeCompleteResults structure.
///
/// Normally, clients of CXString shouldn't care whether or not a CXString is
@@ -251,62 +252,105 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults {
AllocatedCXCodeCompleteResults(IntrusiveRefCntPtr<FileManager> FileMgr);
~AllocatedCXCodeCompleteResults();
- /// \brief Diagnostics produced while performing code completion.
+ /// Diagnostics produced while performing code completion.
SmallVector<StoredDiagnostic, 8> Diagnostics;
- /// \brief Allocated API-exposed wrappters for Diagnostics.
+ /// Allocated API-exposed wrappters for Diagnostics.
SmallVector<CXStoredDiagnostic *, 8> DiagnosticsWrappers;
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
- /// \brief Diag object
+ /// Diag object
IntrusiveRefCntPtr<DiagnosticsEngine> Diag;
- /// \brief Language options used to adjust source locations.
+ /// Language options used to adjust source locations.
LangOptions LangOpts;
- /// \brief File manager, used for diagnostics.
+ /// File manager, used for diagnostics.
IntrusiveRefCntPtr<FileManager> FileMgr;
- /// \brief Source manager, used for diagnostics.
+ /// Source manager, used for diagnostics.
IntrusiveRefCntPtr<SourceManager> SourceMgr;
- /// \brief Temporary buffers that will be deleted once we have finished with
+ /// Temporary buffers that will be deleted once we have finished with
/// the code-completion results.
SmallVector<const llvm::MemoryBuffer *, 1> TemporaryBuffers;
- /// \brief Allocator used to store globally cached code-completion results.
+ /// Allocator used to store globally cached code-completion results.
std::shared_ptr<clang::GlobalCodeCompletionAllocator>
CachedCompletionAllocator;
- /// \brief Allocator used to store code completion results.
+ /// Allocator used to store code completion results.
std::shared_ptr<clang::GlobalCodeCompletionAllocator> CodeCompletionAllocator;
- /// \brief Context under which completion occurred.
+ /// Context under which completion occurred.
enum clang::CodeCompletionContext::Kind ContextKind;
- /// \brief A bitfield representing the acceptable completions for the
+ /// A bitfield representing the acceptable completions for the
/// current context.
unsigned long long Contexts;
- /// \brief The kind of the container for the current context for completions.
+ /// The kind of the container for the current context for completions.
enum CXCursorKind ContainerKind;
- /// \brief The USR of the container for the current context for completions.
+ /// The USR of the container for the current context for completions.
std::string ContainerUSR;
- /// \brief a boolean value indicating whether there is complete information
+ /// a boolean value indicating whether there is complete information
/// about the container
unsigned ContainerIsIncomplete;
- /// \brief A string containing the Objective-C selector entered thus far for a
+ /// A string containing the Objective-C selector entered thus far for a
/// message send.
std::string Selector;
+
+ /// Vector of fix-its for each completion result that *must* be applied
+ /// before that result for the corresponding completion item.
+ std::vector<std::vector<FixItHint>> FixItsVector;
};
} // end anonymous namespace
-/// \brief Tracks the number of code-completion result objects that are
+unsigned clang_getCompletionNumFixIts(CXCodeCompleteResults *results,
+ unsigned completion_index) {
+ AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+
+ if (!allocated_results || allocated_results->FixItsVector.size() <= completion_index)
+ return 0;
+
+ return static_cast<unsigned>(allocated_results->FixItsVector[completion_index].size());
+}
+
+CXString clang_getCompletionFixIt(CXCodeCompleteResults *results,
+ unsigned completion_index,
+ unsigned fixit_index,
+ CXSourceRange *replacement_range) {
+ AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+
+ if (!allocated_results || allocated_results->FixItsVector.size() <= completion_index) {
+ if (replacement_range)
+ *replacement_range = clang_getNullRange();
+ return cxstring::createNull();
+ }
+
+ ArrayRef<FixItHint> FixIts = allocated_results->FixItsVector[completion_index];
+ if (FixIts.size() <= fixit_index) {
+ if (replacement_range)
+ *replacement_range = clang_getNullRange();
+ return cxstring::createNull();
+ }
+
+ const FixItHint &FixIt = FixIts[fixit_index];
+ if (replacement_range) {
+ *replacement_range = cxloc::translateSourceRange(
+ *allocated_results->SourceMgr, allocated_results->LangOpts,
+ FixIt.RemoveRange);
+ }
+
+ return cxstring::createRef(FixIt.CodeToInsert.c_str());
+}
+
+/// Tracks the number of code-completion result objects that are
/// currently active.
///
/// Used for debugging purposes only.
@@ -531,8 +575,10 @@ namespace {
CodeCompletionResult *Results,
unsigned NumResults) override {
StoredResults.reserve(StoredResults.size() + NumResults);
+ if (includeFixIts())
+ AllocatedResults.FixItsVector.reserve(NumResults);
for (unsigned I = 0; I != NumResults; ++I) {
- CodeCompletionString *StoredCompletion
+ CodeCompletionString *StoredCompletion
= Results[I].CreateCodeCompletionString(S, Context, getAllocator(),
getCodeCompletionTUInfo(),
includeBriefComments());
@@ -541,8 +587,10 @@ namespace {
R.CursorKind = Results[I].CursorKind;
R.CompletionString = StoredCompletion;
StoredResults.push_back(R);
+ if (includeFixIts())
+ AllocatedResults.FixItsVector.emplace_back(std::move(Results[I].FixIts));
}
-
+
enum CodeCompletionContext::Kind contextKind = Context.getKind();
AllocatedResults.ContextKind = contextKind;
@@ -643,13 +691,14 @@ clang_codeCompleteAt_Impl(CXTranslationUnit TU, const char *complete_filename,
ArrayRef<CXUnsavedFile> unsaved_files,
unsigned options) {
bool IncludeBriefComments = options & CXCodeComplete_IncludeBriefComments;
+ bool SkipPreamble = options & CXCodeComplete_SkipPreamble;
+ bool IncludeFixIts = options & CXCodeComplete_IncludeCompletionsWithFixIts;
#ifdef UDP_CODE_COMPLETION_LOGGER
#ifdef UDP_CODE_COMPLETION_LOGGER_PORT
const llvm::TimeRecord &StartTime = llvm::TimeRecord::getCurrentTime();
#endif
#endif
-
bool EnableLogging = getenv("LIBCLANG_CODE_COMPLETION_LOGGING") != nullptr;
if (cxtu::isNotUsableTU(TU)) {
@@ -689,6 +738,8 @@ clang_codeCompleteAt_Impl(CXTranslationUnit TU, const char *complete_filename,
// Create a code-completion consumer to capture the results.
CodeCompleteOptions Opts;
Opts.IncludeBriefComments = IncludeBriefComments;
+ Opts.LoadExternal = !SkipPreamble;
+ Opts.IncludeFixIts = IncludeFixIts;
CaptureCompletionResults Capture(Opts, *Results, &TU);
// Perform completion.
@@ -911,7 +962,7 @@ CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *ResultsIn) {
return cxstring::createDup(Results->Selector);
}
-/// \brief Simple utility function that appends a \p New string to the given
+/// Simple utility function that appends a \p New string to the given
/// \p Old string, using the \p Buffer for storage.
///
/// \param Old The string to which we are appending. This parameter will be
@@ -935,7 +986,7 @@ static void AppendToString(StringRef &Old, StringRef New,
Old = Buffer.str();
}
-/// \brief Get the typed-text blocks from the given code-completion string
+/// Get the typed-text blocks from the given code-completion string
/// and return them as a single string.
///
/// \param String The code-completion string whose typed-text blocks will be
@@ -962,7 +1013,7 @@ namespace {
= (CodeCompletionString *)XR.CompletionString;
CodeCompletionString *Y
= (CodeCompletionString *)YR.CompletionString;
-
+
SmallString<256> XBuffer;
StringRef XText = GetTypedName(X, XBuffer);
SmallString<256> YBuffer;
diff --git a/tools/libclang/CIndexDiagnostic.h b/tools/libclang/CIndexDiagnostic.h
index 9f406987ebf1a..e865df0894a6f 100644
--- a/tools/libclang/CIndexDiagnostic.h
+++ b/tools/libclang/CIndexDiagnostic.h
@@ -58,34 +58,34 @@ public:
virtual ~CXDiagnosticImpl();
- /// \brief Return the severity of the diagnostic.
+ /// Return the severity of the diagnostic.
virtual CXDiagnosticSeverity getSeverity() const = 0;
- /// \brief Return the location of the diagnostic.
+ /// Return the location of the diagnostic.
virtual CXSourceLocation getLocation() const = 0;
- /// \brief Return the spelling of the diagnostic.
+ /// Return the spelling of the diagnostic.
virtual CXString getSpelling() const = 0;
- /// \brief Return the text for the diagnostic option.
+ /// Return the text for the diagnostic option.
virtual CXString getDiagnosticOption(CXString *Disable) const = 0;
- /// \brief Return the category of the diagnostic.
+ /// Return the category of the diagnostic.
virtual unsigned getCategory() const = 0;
- /// \brief Return the category string of the diagnostic.
+ /// Return the category string of the diagnostic.
virtual CXString getCategoryText() const = 0;
- /// \brief Return the number of source ranges for the diagnostic.
+ /// Return the number of source ranges for the diagnostic.
virtual unsigned getNumRanges() const = 0;
- /// \brief Return the source ranges for the diagnostic.
+ /// Return the source ranges for the diagnostic.
virtual CXSourceRange getRange(unsigned Range) const = 0;
- /// \brief Return the number of FixIts.
+ /// Return the number of FixIts.
virtual unsigned getNumFixIts() const = 0;
- /// \brief Return the FixIt information (source range and inserted text).
+ /// Return the FixIt information (source range and inserted text).
virtual CXString getFixIt(unsigned FixIt,
CXSourceRange *ReplacementRange) const = 0;
@@ -107,7 +107,7 @@ private:
Kind K;
};
-/// \brief The storage behind a CXDiagnostic
+/// The storage behind a CXDiagnostic
struct CXStoredDiagnostic : public CXDiagnosticImpl {
const StoredDiagnostic &Diag;
const LangOptions &LangOpts;
@@ -119,34 +119,34 @@ struct CXStoredDiagnostic : public CXDiagnosticImpl {
~CXStoredDiagnostic() override {}
- /// \brief Return the severity of the diagnostic.
+ /// Return the severity of the diagnostic.
CXDiagnosticSeverity getSeverity() const override;
- /// \brief Return the location of the diagnostic.
+ /// Return the location of the diagnostic.
CXSourceLocation getLocation() const override;
- /// \brief Return the spelling of the diagnostic.
+ /// Return the spelling of the diagnostic.
CXString getSpelling() const override;
- /// \brief Return the text for the diagnostic option.
+ /// Return the text for the diagnostic option.
CXString getDiagnosticOption(CXString *Disable) const override;
- /// \brief Return the category of the diagnostic.
+ /// Return the category of the diagnostic.
unsigned getCategory() const override;
- /// \brief Return the category string of the diagnostic.
+ /// Return the category string of the diagnostic.
CXString getCategoryText() const override;
- /// \brief Return the number of source ranges for the diagnostic.
+ /// Return the number of source ranges for the diagnostic.
unsigned getNumRanges() const override;
- /// \brief Return the source ranges for the diagnostic.
+ /// Return the source ranges for the diagnostic.
CXSourceRange getRange(unsigned Range) const override;
- /// \brief Return the number of FixIts.
+ /// Return the number of FixIts.
unsigned getNumFixIts() const override;
- /// \brief Return the FixIt information (source range and inserted text).
+ /// Return the FixIt information (source range and inserted text).
CXString getFixIt(unsigned FixIt,
CXSourceRange *ReplacementRange) const override;
diff --git a/tools/libclang/CIndexHigh.cpp b/tools/libclang/CIndexHigh.cpp
index d4666c2288c94..a9cd2cac42ec2 100644
--- a/tools/libclang/CIndexHigh.cpp
+++ b/tools/libclang/CIndexHigh.cpp
@@ -65,7 +65,7 @@ struct FindFileIdRefVisitData {
return cxtu::getASTUnit(TU)->getASTContext();
}
- /// \brief We are looking to find all semantically relevant identifiers,
+ /// We are looking to find all semantically relevant identifiers,
/// so the definition of "canonical" here is different than in the AST, e.g.
///
/// \code
@@ -129,7 +129,7 @@ private:
} // end anonymous namespace.
-/// \brief For a macro \arg Loc, returns the file spelling location and sets
+/// For a macro \arg Loc, returns the file spelling location and sets
/// to \arg isMacroArg whether the spelling resides inside a macro definition or
/// a macro argument.
static SourceLocation getFileSpellingLoc(SourceManager &SM,
diff --git a/tools/libclang/CIndexer.cpp b/tools/libclang/CIndexer.cpp
index 62ea881720699..3c6e1530f1984 100644
--- a/tools/libclang/CIndexer.cpp
+++ b/tools/libclang/CIndexer.cpp
@@ -17,20 +17,20 @@
#include "clang/Basic/Version.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
-#include "llvm/Config/llvm-config.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MutexGuard.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
+#include "llvm/Support/YAMLParser.h"
#include <cstdio>
#ifdef __CYGWIN__
#include <cygwin/version.h>
#include <sys/cygwin.h>
-#define LLVM_ON_WIN32 1
+#define _WIN32 1
#endif
-#ifdef LLVM_ON_WIN32
+#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
@@ -46,7 +46,7 @@ const std::string &CIndexer::getClangResourcesPath() {
SmallString<128> LibClangPath;
// Find the location where this library lives (libclang.dylib).
-#ifdef LLVM_ON_WIN32
+#ifdef _WIN32
MEMORY_BASIC_INFORMATION mbi;
char path[MAX_PATH];
VirtualQuery((void *)(uintptr_t)clang_createTranslationUnit, &mbi,
@@ -112,7 +112,7 @@ LibclangInvocationReporter::LibclangInvocationReporter(
// Write out the information about the invocation to it.
auto WriteStringKey = [&OS](StringRef Key, StringRef Value) {
OS << R"(")" << Key << R"(":")";
- OS << Value << '"';
+ OS << llvm::yaml::escape(Value) << '"';
};
OS << '{';
WriteStringKey("toolchain", Idx.getClangToolchainPath());
@@ -126,14 +126,14 @@ LibclangInvocationReporter::LibclangInvocationReporter(
for (const auto &I : llvm::enumerate(Args)) {
if (I.index())
OS << ',';
- OS << '"' << I.value() << '"';
+ OS << '"' << llvm::yaml::escape(I.value()) << '"';
}
if (!InvocationArgs.empty()) {
OS << R"(],"invocation-args":[)";
for (const auto &I : llvm::enumerate(InvocationArgs)) {
if (I.index())
OS << ',';
- OS << '"' << I.value() << '"';
+ OS << '"' << llvm::yaml::escape(I.value()) << '"';
}
}
if (!UnsavedFiles.empty()) {
diff --git a/tools/libclang/CIndexer.h b/tools/libclang/CIndexer.h
index 6c46eed4fb988..3ba35d6db6015 100644
--- a/tools/libclang/CIndexer.h
+++ b/tools/libclang/CIndexer.h
@@ -52,7 +52,7 @@ public:
Options(CXGlobalOpt_None), PCHContainerOps(std::move(PCHContainerOps)) {
}
- /// \brief Whether we only want to see "local" declarations (that did not
+ /// Whether we only want to see "local" declarations (that did not
/// come from a previous precompiled header). If false, we want to see all
/// declarations.
bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
@@ -74,7 +74,7 @@ public:
return Options & opt;
}
- /// \brief Get the path of the clang resource files.
+ /// Get the path of the clang resource files.
const std::string &getClangResourcesPath();
StringRef getClangToolchainPath();
@@ -103,47 +103,47 @@ private:
std::string File;
};
- /// \brief Return the current size to request for "safety".
+ /// Return the current size to request for "safety".
unsigned GetSafetyThreadStackSize();
- /// \brief Set the current size to request for "safety" (or 0, if safety
+ /// Set the current size to request for "safety" (or 0, if safety
/// threads should not be used).
void SetSafetyThreadStackSize(unsigned Value);
- /// \brief Execution the given code "safely", using crash recovery or safety
+ /// Execution the given code "safely", using crash recovery or safety
/// threads when possible.
///
/// \return False if a crash was detected.
bool RunSafely(llvm::CrashRecoveryContext &CRC, llvm::function_ref<void()> Fn,
unsigned Size = 0);
- /// \brief Set the thread priority to background.
+ /// Set the thread priority to background.
/// FIXME: Move to llvm/Support.
void setThreadBackgroundPriority();
- /// \brief Print libclang's resource usage to standard error.
+ /// Print libclang's resource usage to standard error.
void PrintLibclangResourceUsage(CXTranslationUnit TU);
namespace cxindex {
void printDiagsToStderr(ASTUnit *Unit);
- /// \brief If \c MacroDefLoc points at a macro definition with \c II as
+ /// If \c MacroDefLoc points at a macro definition with \c II as
/// its name, this retrieves its MacroInfo.
MacroInfo *getMacroInfo(const IdentifierInfo &II,
SourceLocation MacroDefLoc, CXTranslationUnit TU);
- /// \brief Retrieves the corresponding MacroInfo of a MacroDefinitionRecord.
+ /// Retrieves the corresponding MacroInfo of a MacroDefinitionRecord.
const MacroInfo *getMacroInfo(const MacroDefinitionRecord *MacroDef,
CXTranslationUnit TU);
- /// \brief If \c Loc resides inside the definition of \c MI and it points at
+ /// If \c Loc resides inside the definition of \c MI and it points at
/// an identifier that has ever been a macro name, this returns the latest
/// MacroDefinitionRecord for that name, otherwise it returns NULL.
MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
SourceLocation Loc,
CXTranslationUnit TU);
- /// \brief If \c Tok resides inside the definition of \c MI and it points at
+ /// If \c Tok resides inside the definition of \c MI and it points at
/// an identifier that has ever been a macro name, this returns the latest
/// MacroDefinitionRecord for that name, otherwise it returns NULL.
MacroDefinitionRecord *checkForMacroInMacroDefinition(const MacroInfo *MI,
diff --git a/tools/libclang/CLog.h b/tools/libclang/CLog.h
index e1d6a57e4a011..a935995a11357 100644
--- a/tools/libclang/CLog.h
+++ b/tools/libclang/CLog.h
@@ -31,7 +31,7 @@ namespace cxindex {
class Logger;
typedef IntrusiveRefCntPtr<Logger> LogRef;
-/// \brief Collects logging output and writes it to stderr when it's destructed.
+/// Collects logging output and writes it to stderr when it's destructed.
/// Common use case:
/// \code
/// if (LogRef Log = Logger::make(__func__)) {
@@ -90,7 +90,7 @@ public:
}
}
-/// \brief Macros to automate common uses of Logger. Like this:
+/// Macros to automate common uses of Logger. Like this:
/// \code
/// LOG_FUNC_SECTION {
/// *Log << "blah";
diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt
index 44406378207bb..e539c8308e756 100644
--- a/tools/libclang/CMakeLists.txt
+++ b/tools/libclang/CMakeLists.txt
@@ -67,7 +67,7 @@ option(LIBCLANG_BUILD_STATIC
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.exports)
if(MSVC)
- # Avoid LNK4197 not to spceify libclang.def here.
+ # Avoid LNK4197 by not specifying libclang.exports here.
# Each functions is exported as "dllexport" in include/clang-c.
# KB835326
set(LLVM_EXPORTED_SYMBOL_FILE)
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index fb61249a778f3..b4ad0595cc53d 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -305,6 +305,10 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
K = CXCursor_IntegerLiteral;
break;
+ case Stmt::FixedPointLiteralClass:
+ K = CXCursor_FixedPointLiteral;
+ break;
+
case Stmt::FloatingLiteralClass:
K = CXCursor_FloatingLiteral;
break;
@@ -1196,19 +1200,19 @@ int clang_Cursor_getNumTemplateArguments(CXCursor C) {
}
enum CXGetTemplateArgumentStatus {
- /** \brief The operation completed successfully */
+ /** The operation completed successfully */
CXGetTemplateArgumentStatus_Success = 0,
- /** \brief The specified cursor did not represent a FunctionDecl. */
+ /** The specified cursor did not represent a FunctionDecl. */
CXGetTemplateArgumentStatus_CursorNotFunctionDecl = -1,
- /** \brief The specified cursor was not castable to a FunctionDecl. */
+ /** The specified cursor was not castable to a FunctionDecl. */
CXGetTemplateArgumentStatus_BadFunctionDeclCast = -2,
- /** \brief A NULL FunctionTemplateSpecializationInfo was retrieved. */
+ /** A NULL FunctionTemplateSpecializationInfo was retrieved. */
CXGetTemplateArgumentStatus_NullTemplSpecInfo = -3,
- /** \brief An invalid (OOB) argument index was specified */
+ /** An invalid (OOB) argument index was specified */
CXGetTemplateArgumentStatus_InvalidIndex = -4
};
@@ -1469,17 +1473,17 @@ void clang_getOverriddenCursors(CXCursor cursor,
assert(cxcursor::getCursorTU(backRefCursor) == TU);
Vec->push_back(backRefCursor);
- // Get the overriden cursors.
+ // Get the overridden cursors.
cxcursor::getOverriddenCursors(cursor, *Vec);
- // Did we get any overriden cursors? If not, return Vec to the pool
+ // Did we get any overridden 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.
+ // Now tell the caller about the overridden cursors.
assert(Vec->size() > 1);
*overridden = &((*Vec)[1]);
*num_overridden = Vec->size() - 1;
diff --git a/tools/libclang/CXCursor.h b/tools/libclang/CXCursor.h
index 083b86934d165..a5d9fff2a55a4 100644
--- a/tools/libclang/CXCursor.h
+++ b/tools/libclang/CXCursor.h
@@ -58,109 +58,109 @@ CXCursor MakeCXCursor(const clang::Stmt *S, const clang::Decl *Parent,
SourceRange RegionOfInterest = SourceRange());
CXCursor MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU = nullptr);
-/// \brief Create an Objective-C superclass reference at the given location.
+/// Create an Objective-C superclass reference at the given location.
CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
+/// Unpack an ObjCSuperClassRef cursor into the interface it references
/// and optionally the location where the reference occurred.
std::pair<const ObjCInterfaceDecl *, SourceLocation>
getCursorObjCSuperClassRef(CXCursor C);
-/// \brief Create an Objective-C protocol reference at the given location.
+/// Create an Objective-C protocol reference at the given location.
CXCursor MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
+/// Unpack an ObjCProtocolRef cursor into the protocol it references
/// and optionally the location where the reference occurred.
std::pair<const ObjCProtocolDecl *, SourceLocation>
getCursorObjCProtocolRef(CXCursor C);
-/// \brief Create an Objective-C class reference at the given location.
+/// Create an Objective-C class reference at the given location.
CXCursor MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack an ObjCClassRef cursor into the class it references
+/// Unpack an ObjCClassRef cursor into the class it references
/// and optionally the location where the reference occurred.
std::pair<const ObjCInterfaceDecl *, SourceLocation>
getCursorObjCClassRef(CXCursor C);
-/// \brief Create a type reference at the given location.
+/// Create a type reference at the given location.
CXCursor MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack a TypeRef cursor into the class it references
+/// Unpack a TypeRef cursor into the class it references
/// and optionally the location where the reference occurred.
std::pair<const TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
-/// \brief Create a reference to a template at the given location.
+/// Create a reference to a template at the given location.
CXCursor MakeCursorTemplateRef(const TemplateDecl *Template, SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack a TemplateRef cursor into the template it references and
+/// Unpack a TemplateRef cursor into the template it references and
/// the location where the reference occurred.
std::pair<const TemplateDecl *, SourceLocation>
getCursorTemplateRef(CXCursor C);
-/// \brief Create a reference to a namespace or namespace alias at the given
+/// Create a reference to a namespace or namespace alias at the given
/// location.
CXCursor MakeCursorNamespaceRef(const NamedDecl *NS, SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
+/// Unpack a NamespaceRef cursor into the namespace or namespace alias
/// it references and the location where the reference occurred.
std::pair<const NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
-/// \brief Create a reference to a variable at the given location.
+/// Create a reference to a variable at the given location.
CXCursor MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack a VariableRef cursor into the variable it references and the
+/// Unpack a VariableRef cursor into the variable it references and the
/// location where the where the reference occurred.
std::pair<const VarDecl *, SourceLocation> getCursorVariableRef(CXCursor C);
-/// \brief Create a reference to a field at the given location.
+/// Create a reference to a field at the given location.
CXCursor MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack a MemberRef cursor into the field it references and the
+/// Unpack a MemberRef cursor into the field it references and the
/// location where the reference occurred.
std::pair<const FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
-/// \brief Create a CXX base specifier cursor.
+/// Create a CXX base specifier cursor.
CXCursor MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
CXTranslationUnit TU);
-/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
+/// Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
const CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
-/// \brief Create a preprocessing directive cursor.
+/// Create a preprocessing directive cursor.
CXCursor MakePreprocessingDirectiveCursor(SourceRange Range,
CXTranslationUnit TU);
-/// \brief Unpack a given preprocessing directive to retrieve its source range.
+/// Unpack a given preprocessing directive to retrieve its source range.
SourceRange getCursorPreprocessingDirective(CXCursor C);
-/// \brief Create a macro definition cursor.
+/// Create a macro definition cursor.
CXCursor MakeMacroDefinitionCursor(const MacroDefinitionRecord *,
CXTranslationUnit TU);
-/// \brief Unpack a given macro definition cursor to retrieve its
+/// Unpack a given macro definition cursor to retrieve its
/// source range.
const MacroDefinitionRecord *getCursorMacroDefinition(CXCursor C);
-/// \brief Create a macro expansion cursor.
+/// Create a macro expansion cursor.
CXCursor MakeMacroExpansionCursor(MacroExpansion *, CXTranslationUnit TU);
-/// \brief Create a "pseudo" macro expansion cursor, using a macro definition
+/// Create a "pseudo" macro expansion cursor, using a macro definition
/// and a source location.
CXCursor MakeMacroExpansionCursor(MacroDefinitionRecord *, SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Wraps a macro expansion cursor and provides a common interface
+/// Wraps a macro expansion cursor and provides a common interface
/// for a normal macro expansion cursor or a "pseudo" one.
///
/// "Pseudo" macro expansion cursors (essentially a macro definition along with
@@ -194,46 +194,46 @@ public:
SourceRange getSourceRange() const;
};
-/// \brief Unpack a given macro expansion cursor to retrieve its info.
+/// Unpack a given macro expansion cursor to retrieve its info.
static inline MacroExpansionCursor getCursorMacroExpansion(CXCursor C) {
return C;
}
-/// \brief Create an inclusion directive cursor.
+/// Create an inclusion directive cursor.
CXCursor MakeInclusionDirectiveCursor(InclusionDirective *,
CXTranslationUnit TU);
-/// \brief Unpack a given inclusion directive cursor to retrieve its
+/// Unpack a given inclusion directive cursor to retrieve its
/// source range.
const InclusionDirective *getCursorInclusionDirective(CXCursor C);
-/// \brief Create a label reference at the given location.
+/// Create a label reference at the given location.
CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
CXTranslationUnit TU);
-/// \brief Unpack a label reference into the label statement it refers to and
+/// Unpack a label reference into the label statement it refers to and
/// the location of the reference.
std::pair<const LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
-/// \brief Create a overloaded declaration reference cursor for an expression.
+/// Create a overloaded declaration reference cursor for an expression.
CXCursor MakeCursorOverloadedDeclRef(const OverloadExpr *E,
CXTranslationUnit TU);
-/// \brief Create a overloaded declaration reference cursor for a declaration.
+/// Create a overloaded declaration reference cursor for a declaration.
CXCursor MakeCursorOverloadedDeclRef(const Decl *D, SourceLocation Location,
CXTranslationUnit TU);
-/// \brief Create a overloaded declaration reference cursor for a template name.
+/// Create a overloaded declaration reference cursor for a template name.
CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
SourceLocation Location,
CXTranslationUnit TU);
-/// \brief Internal storage for an overloaded declaration reference cursor;
+/// Internal storage for an overloaded declaration reference cursor;
typedef llvm::PointerUnion3<const OverloadExpr *, const Decl *,
OverloadedTemplateStorage *>
OverloadedDeclRefStorage;
-/// \brief Unpack an overloaded declaration reference into an expression,
+/// Unpack an overloaded declaration reference into an expression,
/// declaration, or template name along with the source location.
std::pair<OverloadedDeclRefStorage, SourceLocation>
getCursorOverloadedDeclRef(CXCursor C);
@@ -251,14 +251,14 @@ CXTranslationUnit getCursorTU(CXCursor Cursor);
void getOverriddenCursors(CXCursor cursor,
SmallVectorImpl<CXCursor> &overridden);
-/// \brief Create an opaque pool used for fast generation of overriden
+/// Create an opaque pool used for fast generation of overridden
/// CXCursor arrays.
void *createOverridenCXCursorsPool();
-/// \brief Dispose of the overriden CXCursors pool.
+/// Dispose of the overridden CXCursors pool.
void disposeOverridenCXCursorsPool(void *pool);
-/// \brief Returns a index/location pair for a selector identifier if the cursor
+/// Returns a index/location pair for a selector identifier if the cursor
/// points to one.
std::pair<int, SourceLocation> getSelectorIdentifierIndexAndLoc(CXCursor);
static inline int getSelectorIdentifierIndex(CXCursor cursor) {
@@ -279,7 +279,7 @@ static inline CXCursor getTypeRefedCallExprCursor(CXCursor cursor) {
CXCursor getTypeRefCursor(CXCursor cursor);
-/// \brief Generate a USR for \arg D and put it in \arg Buf.
+/// Generate a USR for \arg D and put it in \arg Buf.
/// \returns true if no USR was computed or the result should be ignored,
/// false otherwise.
bool getDeclCursorUSR(const Decl *D, SmallVectorImpl<char> &Buf);
@@ -290,7 +290,7 @@ inline bool operator!=(CXCursor X, CXCursor Y) {
return !(X == Y);
}
-/// \brief Return true if the cursor represents a declaration that is the
+/// Return true if the cursor represents a declaration that is the
/// first in a declaration group.
bool isFirstInDeclGroup(CXCursor C);
diff --git a/tools/libclang/CXIndexDataConsumer.cpp b/tools/libclang/CXIndexDataConsumer.cpp
index 89ac23be73445..616a0797f52b1 100644
--- a/tools/libclang/CXIndexDataConsumer.cpp
+++ b/tools/libclang/CXIndexDataConsumer.cpp
@@ -148,15 +148,17 @@ public:
return true;
}
};
+
+CXSymbolRole getSymbolRole(SymbolRoleSet Role) {
+ // CXSymbolRole mirrors low 9 bits of clang::index::SymbolRole.
+ return CXSymbolRole(static_cast<uint32_t>(Role) & ((1 << 9) - 1));
+}
}
-bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
- SymbolRoleSet Roles,
- ArrayRef<SymbolRelation> Relations,
- FileID FID, unsigned Offset,
- ASTNodeInfo ASTNode) {
- SourceLocation Loc = getASTContext().getSourceManager()
- .getLocForStartOfFile(FID).getLocWithOffset(Offset);
+bool CXIndexDataConsumer::handleDeclOccurence(
+ const Decl *D, SymbolRoleSet Roles, ArrayRef<SymbolRelation> Relations,
+ SourceLocation Loc, ASTNodeInfo ASTNode) {
+ Loc = getASTContext().getSourceManager().getFileLoc(Loc);
if (Roles & (unsigned)SymbolRole::Reference) {
const NamedDecl *ND = dyn_cast<NamedDecl>(D);
@@ -184,6 +186,7 @@ bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
if (Roles & (unsigned)SymbolRole::Implicit) {
Kind = CXIdxEntityRef_Implicit;
}
+ CXSymbolRole CXRole = getSymbolRole(Roles);
CXCursor Cursor;
if (ASTNode.OrigE) {
@@ -202,7 +205,7 @@ bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
}
handleReference(ND, Loc, Cursor,
dyn_cast_or_null<NamedDecl>(ASTNode.Parent),
- ASTNode.ContainerDC, ASTNode.OrigE, Kind);
+ ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
} else {
const DeclContext *LexicalDC = ASTNode.ContainerDC;
@@ -220,8 +223,7 @@ bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
bool CXIndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
SymbolRoleSet Roles,
- FileID FID,
- unsigned Offset) {
+ SourceLocation Loc) {
IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
return !shouldAbort();
}
@@ -889,13 +891,14 @@ bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E,
- CXIdxEntityRefKind Kind) {
- if (!D)
+ CXIdxEntityRefKind Kind,
+ CXSymbolRole Role) {
+ if (!D || !DC)
return false;
CXCursor Cursor = E ? MakeCXCursor(E, cast<Decl>(DC), CXTU)
: getRefCursor(D, Loc);
- return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
+ return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
}
bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
@@ -903,11 +906,12 @@ bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E,
- CXIdxEntityRefKind Kind) {
+ CXIdxEntityRefKind Kind,
+ CXSymbolRole Role) {
if (!CB.indexEntityReference)
return false;
- if (!D)
+ if (!D || !DC)
return false;
if (Loc.isInvalid())
return false;
@@ -939,7 +943,8 @@ bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc
getIndexLoc(Loc),
&RefEntity,
Parent ? &ParentEntity : nullptr,
- &Container };
+ &Container,
+ Role };
CB.indexEntityReference(ClientData, &Info);
return true;
}
diff --git a/tools/libclang/CXIndexDataConsumer.h b/tools/libclang/CXIndexDataConsumer.h
index a54baadd07742..19e39b281ab0f 100644
--- a/tools/libclang/CXIndexDataConsumer.h
+++ b/tools/libclang/CXIndexDataConsumer.h
@@ -260,7 +260,7 @@ public:
}
unsigned getNumAttrs() const { return (unsigned)CXAttrs.size(); }
- /// \brief Retain/Release only useful when we allocate a AttrListInfo from the
+ /// Retain/Release only useful when we allocate a AttrListInfo from the
/// BumpPtrAllocator, and not from the stack; so that we keep a pointer
// in the EntityInfo
void Retain() { ++ref_cnt; }
@@ -436,13 +436,15 @@ public:
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
- CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+ CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+ CXSymbolRole Role = CXSymbolRole_None);
bool handleReference(const NamedDecl *D, SourceLocation Loc,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
- CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+ CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+ CXSymbolRole Role = CXSymbolRole_None);
bool isNotFromSourceFile(SourceLocation Loc) const;
@@ -463,12 +465,11 @@ public:
private:
bool handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
ArrayRef<index::SymbolRelation> Relations,
- FileID FID, unsigned Offset,
- ASTNodeInfo ASTNode) override;
+ SourceLocation Loc, ASTNodeInfo ASTNode) override;
bool handleModuleOccurence(const ImportDecl *ImportD,
index::SymbolRoleSet Roles,
- FileID FID, unsigned Offset) override;
+ SourceLocation Loc) override;
void finish() override;
diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp
index 36c3dcabb924c..fd6881e03ab02 100644
--- a/tools/libclang/CXLoadedDiagnostic.cpp
+++ b/tools/libclang/CXLoadedDiagnostic.cpp
@@ -47,7 +47,7 @@ public:
FileManager FakeFiles;
llvm::DenseMap<unsigned, const FileEntry *> Files;
- /// \brief Copy the string into our own allocator.
+ /// Copy the string into our own allocator.
const char *copyString(StringRef Blob) {
char *mem = Alloc.Allocate<char>(Blob.size() + 1);
memcpy(mem, Blob.data(), Blob.size());
diff --git a/tools/libclang/CXLoadedDiagnostic.h b/tools/libclang/CXLoadedDiagnostic.h
index 1209d76669f8d..521ebd84bf13a 100644
--- a/tools/libclang/CXLoadedDiagnostic.h
+++ b/tools/libclang/CXLoadedDiagnostic.h
@@ -27,34 +27,34 @@ public:
~CXLoadedDiagnostic() override;
- /// \brief Return the severity of the diagnostic.
+ /// Return the severity of the diagnostic.
CXDiagnosticSeverity getSeverity() const override;
- /// \brief Return the location of the diagnostic.
+ /// Return the location of the diagnostic.
CXSourceLocation getLocation() const override;
- /// \brief Return the spelling of the diagnostic.
+ /// Return the spelling of the diagnostic.
CXString getSpelling() const override;
- /// \brief Return the text for the diagnostic option.
+ /// Return the text for the diagnostic option.
CXString getDiagnosticOption(CXString *Disable) const override;
- /// \brief Return the category of the diagnostic.
+ /// Return the category of the diagnostic.
unsigned getCategory() const override;
- /// \brief Return the category string of the diagnostic.
+ /// Return the category string of the diagnostic.
CXString getCategoryText() const override;
- /// \brief Return the number of source ranges for the diagnostic.
+ /// Return the number of source ranges for the diagnostic.
unsigned getNumRanges() const override;
- /// \brief Return the source ranges for the diagnostic.
+ /// Return the source ranges for the diagnostic.
CXSourceRange getRange(unsigned Range) const override;
- /// \brief Return the number of FixIts.
+ /// Return the number of FixIts.
unsigned getNumFixIts() const override;
- /// \brief Return the FixIt information (source range and inserted text).
+ /// Return the FixIt information (source range and inserted text).
CXString getFixIt(unsigned FixIt,
CXSourceRange *ReplacementRange) const override;
@@ -62,7 +62,7 @@ public:
return D->getKind() == LoadedDiagnosticKind;
}
- /// \brief Decode the CXSourceLocation into file, line, column, and offset.
+ /// Decode the CXSourceLocation into file, line, column, and offset.
static void decodeLocation(CXSourceLocation location,
CXFile *file,
unsigned *line,
diff --git a/tools/libclang/CXSourceLocation.h b/tools/libclang/CXSourceLocation.h
index f0b3f4954919b..dddc8475906c2 100644
--- a/tools/libclang/CXSourceLocation.h
+++ b/tools/libclang/CXSourceLocation.h
@@ -25,7 +25,7 @@ class SourceManager;
namespace cxloc {
-/// \brief Translate a Clang source location into a CIndex source location.
+/// Translate a Clang source location into a CIndex source location.
static inline CXSourceLocation
translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts,
SourceLocation Loc) {
@@ -37,7 +37,7 @@ translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts,
return Result;
}
-/// \brief Translate a Clang source location into a CIndex source location.
+/// Translate a Clang source location into a CIndex source location.
static inline CXSourceLocation translateSourceLocation(ASTContext &Context,
SourceLocation Loc) {
return translateSourceLocation(Context.getSourceManager(),
@@ -45,7 +45,7 @@ static inline CXSourceLocation translateSourceLocation(ASTContext &Context,
Loc);
}
-/// \brief Translate a Clang source range into a CIndex source range.
+/// Translate a Clang source range into a CIndex source range.
///
/// Clang internally represents ranges where the end location points to the
/// start of the token at the end. However, for external clients it is more
@@ -55,7 +55,7 @@ CXSourceRange translateSourceRange(const SourceManager &SM,
const LangOptions &LangOpts,
const CharSourceRange &R);
-/// \brief Translate a Clang source range into a CIndex source range.
+/// Translate a Clang source range into a CIndex source range.
static inline CXSourceRange translateSourceRange(ASTContext &Context,
SourceRange R) {
return translateSourceRange(Context.getSourceManager(),
diff --git a/tools/libclang/CXString.cpp b/tools/libclang/CXString.cpp
index 4486031792032..cef4e53a42c27 100644
--- a/tools/libclang/CXString.cpp
+++ b/tools/libclang/CXString.cpp
@@ -96,7 +96,7 @@ CXString createRef(StringRef String) {
CXString createDup(StringRef String) {
CXString Result;
- char *Spelling = static_cast<char *>(malloc(String.size() + 1));
+ char *Spelling = static_cast<char *>(llvm::safe_malloc(String.size() + 1));
memmove(Spelling, String.data(), String.size());
Spelling[String.size()] = 0;
Result.data = Spelling;
diff --git a/tools/libclang/CXString.h b/tools/libclang/CXString.h
index 6473eb2d7103d..ed19261187016 100644
--- a/tools/libclang/CXString.h
+++ b/tools/libclang/CXString.h
@@ -27,33 +27,33 @@ namespace cxstring {
struct CXStringBuf;
-/// \brief Create a CXString object for an empty "" string.
+/// Create a CXString object for an empty "" string.
CXString createEmpty();
-/// \brief Create a CXString object for an NULL string.
+/// Create a CXString object for an NULL string.
///
/// A NULL string should be used as an "invalid" value in case of errors.
CXString createNull();
-/// \brief Create a CXString object from a nul-terminated C string. New
+/// Create a CXString object from a nul-terminated C string. New
/// CXString may contain a pointer to \p String.
///
/// \p String should not be changed by the caller afterwards.
CXString createRef(const char *String);
-/// \brief Create a CXString object from a nul-terminated C string. New
+/// Create a CXString object from a nul-terminated C string. New
/// CXString will contain a copy of \p String.
///
/// \p String can be changed or freed by the caller.
CXString createDup(const char *String);
-/// \brief Create a CXString object from a StringRef. New CXString may
+/// Create a CXString object from a StringRef. New CXString may
/// contain a pointer to the undrelying data of \p String.
///
/// \p String should not be changed by the caller afterwards.
CXString createRef(StringRef String);
-/// \brief Create a CXString object from a StringRef. New CXString will
+/// Create a CXString object from a StringRef. New CXString will
/// contain a copy of \p String.
///
/// \p String can be changed or freed by the caller.
@@ -65,12 +65,12 @@ CXString createDup(StringRef String);
// If you need to make a copy, call \c createDup(StringRef(String)).
CXString createRef(std::string String) = delete;
-/// \brief Create a CXString object that is backed by a string buffer.
+/// Create a CXString object that is backed by a string buffer.
CXString createCXString(CXStringBuf *buf);
CXStringSet *createSet(const std::vector<std::string> &Strings);
-/// \brief A string pool used for fast allocation/deallocation of strings.
+/// A string pool used for fast allocation/deallocation of strings.
class CXStringPool {
public:
~CXStringPool();
@@ -89,13 +89,13 @@ struct CXStringBuf {
CXStringBuf(CXTranslationUnit TU) : TU(TU) {}
- /// \brief Return this buffer to the pool.
+ /// Return this buffer to the pool.
void dispose();
};
CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
-/// \brief Returns true if the CXString data is managed by a pool.
+/// Returns true if the CXString data is managed by a pool.
bool isManagedByPool(CXString str);
}
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index dfc0152477685..7c0f307944a14 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -53,6 +53,12 @@ static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) {
BTCASE(Float);
BTCASE(Double);
BTCASE(LongDouble);
+ BTCASE(ShortAccum);
+ BTCASE(Accum);
+ BTCASE(LongAccum);
+ BTCASE(UShortAccum);
+ BTCASE(UAccum);
+ BTCASE(ULongAccum);
BTCASE(Float16);
BTCASE(Float128);
BTCASE(NullPtr);
@@ -119,6 +125,10 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
if (auto *ATT = T->getAs<AttributedType>()) {
return MakeCXType(ATT->getModifiedType(), TU);
}
+ // Handle paren types as the original type
+ if (auto *PTT = T->getAs<ParenType>()) {
+ return MakeCXType(PTT->getInnerType(), TU);
+ }
ASTContext &Ctx = cxtu::getASTUnit(TU)->getASTContext();
if (Ctx.getLangOpts().ObjC1) {
@@ -542,6 +552,12 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
TKIND(Float);
TKIND(Double);
TKIND(LongDouble);
+ TKIND(ShortAccum);
+ TKIND(Accum);
+ TKIND(LongAccum);
+ TKIND(UShortAccum);
+ TKIND(UAccum);
+ TKIND(ULongAccum);
TKIND(Float16);
TKIND(Float128);
TKIND(NullPtr);
@@ -689,13 +705,41 @@ CXType clang_getCursorResultType(CXCursor C) {
return MakeCXType(QualType(), cxcursor::getCursorTU(C));
}
+// FIXME: We should expose the canThrow(...) result instead of the EST.
+static CXCursor_ExceptionSpecificationKind
+getExternalExceptionSpecificationKind(ExceptionSpecificationType EST) {
+ switch (EST) {
+ case EST_None:
+ return CXCursor_ExceptionSpecificationKind_None;
+ case EST_DynamicNone:
+ return CXCursor_ExceptionSpecificationKind_DynamicNone;
+ case EST_Dynamic:
+ return CXCursor_ExceptionSpecificationKind_Dynamic;
+ case EST_MSAny:
+ return CXCursor_ExceptionSpecificationKind_MSAny;
+ case EST_BasicNoexcept:
+ return CXCursor_ExceptionSpecificationKind_BasicNoexcept;
+ case EST_NoexceptFalse:
+ case EST_NoexceptTrue:
+ case EST_DependentNoexcept:
+ return CXCursor_ExceptionSpecificationKind_ComputedNoexcept;
+ case EST_Unevaluated:
+ return CXCursor_ExceptionSpecificationKind_Unevaluated;
+ case EST_Uninstantiated:
+ return CXCursor_ExceptionSpecificationKind_Uninstantiated;
+ case EST_Unparsed:
+ return CXCursor_ExceptionSpecificationKind_Unparsed;
+ }
+ llvm_unreachable("invalid EST value");
+}
+
int clang_getExceptionSpecificationType(CXType X) {
QualType T = GetQualType(X);
if (T.isNull())
return -1;
if (const auto *FD = T->getAs<FunctionProtoType>())
- return static_cast<int>(FD->getExceptionSpecType());
+ return getExternalExceptionSpecificationKind(FD->getExceptionSpecType());
return -1;
}
diff --git a/tools/libclang/CursorVisitor.h b/tools/libclang/CursorVisitor.h
index 82f251a348f02..f2fb68fab954f 100644
--- a/tools/libclang/CursorVisitor.h
+++ b/tools/libclang/CursorVisitor.h
@@ -55,44 +55,44 @@ class CursorVisitor : public DeclVisitor<CursorVisitor, bool>,
public TypeLocVisitor<CursorVisitor, bool>
{
public:
- /// \brief Callback called after child nodes of a cursor have been visited.
+ /// Callback called after child nodes of a cursor have been visited.
/// Return true to break visitation or false to continue.
typedef bool (*PostChildrenVisitorTy)(CXCursor cursor,
CXClientData client_data);
private:
- /// \brief The translation unit we are traversing.
+ /// The translation unit we are traversing.
CXTranslationUnit TU;
ASTUnit *AU;
- /// \brief The parent cursor whose children we are traversing.
+ /// The parent cursor whose children we are traversing.
CXCursor Parent;
- /// \brief The declaration that serves at the parent of any statement or
+ /// The declaration that serves at the parent of any statement or
/// expression nodes.
const Decl *StmtParent;
- /// \brief The visitor function.
+ /// The visitor function.
CXCursorVisitor Visitor;
PostChildrenVisitorTy PostChildrenVisitor;
- /// \brief The opaque client data, to be passed along to the visitor.
+ /// The opaque client data, to be passed along to the visitor.
CXClientData ClientData;
- /// \brief Whether we should visit the preprocessing record entries last,
+ /// Whether we should visit the preprocessing record entries last,
/// after visiting other declarations.
bool VisitPreprocessorLast;
- /// \brief Whether we should visit declarations or preprocessing record
+ /// Whether we should visit declarations or preprocessing record
/// entries that are #included inside the \arg RegionOfInterest.
bool VisitIncludedEntities;
- /// \brief When valid, a source range to which the cursor should restrict
+ /// When valid, a source range to which the cursor should restrict
/// its search.
SourceRange RegionOfInterest;
- /// \brief Whether we should only visit declarations and not preprocessing
+ /// Whether we should only visit declarations and not preprocessing
/// record entries.
bool VisitDeclsOnly;
@@ -110,7 +110,7 @@ private:
using DeclVisitor<CursorVisitor, bool>::Visit;
using TypeLocVisitor<CursorVisitor, bool>::Visit;
- /// \brief Determine whether this particular source range comes before, comes
+ /// Determine whether this particular source range comes before, comes
/// after, or overlaps the region of interest.
///
/// \param R a half-open source range retrieved from the abstract syntax tree.
@@ -177,7 +177,7 @@ public:
bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false);
- /// \brief Visit declarations and preprocessed entities for the file region
+ /// Visit declarations and preprocessed entities for the file region
/// designated by \see RegionOfInterest.
bool visitFileRegion();
diff --git a/tools/libclang/Index_Internal.h b/tools/libclang/Index_Internal.h
index 98f069c88738a..fbe3cabf04c86 100644
--- a/tools/libclang/Index_Internal.h
+++ b/tools/libclang/Index_Internal.h
@@ -40,15 +40,15 @@ typedef struct _CXCursorAndRangeVisitorBlock {
#endif // !__has_feature(blocks)
-/// \brief The result of comparing two source ranges.
+/// The result of comparing two source ranges.
enum RangeComparisonResult {
- /// \brief Either the ranges overlap or one of the ranges is invalid.
+ /// Either the ranges overlap or one of the ranges is invalid.
RangeOverlap,
- /// \brief The first range ends before the second range starts.
+ /// The first range ends before the second range starts.
RangeBefore,
- /// \brief The first range starts after the second range ends.
+ /// The first range starts after the second range ends.
RangeAfter
};
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 021ebcfcfe430..4da046b282338 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -45,7 +45,7 @@ namespace {
// Skip Parsed Bodies
//===----------------------------------------------------------------------===//
-/// \brief A "region" in source code identified by the file/offset of the
+/// A "region" in source code identified by the file/offset of the
/// preprocessor conditional directive that it belongs to.
/// Multiple, non-consecutive ranges can be parts of the same region.
///
@@ -249,7 +249,8 @@ public:
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange, const FileEntry *File,
StringRef SearchPath, StringRef RelativePath,
- const Module *Imported) override {
+ const Module *Imported,
+ SrcMgr::CharacteristicKind FileType) override {
bool isImport = (IncludeTok.is(tok::identifier) &&
IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
DataConsumer.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled,
@@ -401,6 +402,8 @@ static IndexingOptions getIndexingOptionsFromCXOptions(unsigned index_options) {
IndexingOptions IdxOpts;
if (index_options & CXIndexOpt_IndexFunctionLocalSymbols)
IdxOpts.IndexFunctionLocals = true;
+ if (index_options & CXIndexOpt_IndexImplicitTemplateInstantiations)
+ IdxOpts.IndexImplicitInstantiation = true;
return IdxOpts;
}
@@ -659,8 +662,7 @@ static CXErrorCode clang_indexTranslationUnit_Impl(
? index_callbacks_size : sizeof(CB);
memcpy(&CB, client_index_callbacks, ClientCBSize);
- auto DataConsumer = std::make_shared<CXIndexDataConsumer>(client_data, CB,
- index_options, TU);
+ CXIndexDataConsumer DataConsumer(client_data, CB, index_options, TU);
ASTUnit *Unit = cxtu::getASTUnit(TU);
if (!Unit)
@@ -669,21 +671,22 @@ static CXErrorCode clang_indexTranslationUnit_Impl(
ASTUnit::ConcurrencyCheck Check(*Unit);
if (const FileEntry *PCHFile = Unit->getPCHFile())
- DataConsumer->importedPCH(PCHFile);
+ DataConsumer.importedPCH(PCHFile);
FileManager &FileMgr = Unit->getFileManager();
if (Unit->getOriginalSourceFileName().empty())
- DataConsumer->enteredMainFile(nullptr);
+ DataConsumer.enteredMainFile(nullptr);
else
- DataConsumer->enteredMainFile(FileMgr.getFile(Unit->getOriginalSourceFileName()));
+ DataConsumer.enteredMainFile(
+ FileMgr.getFile(Unit->getOriginalSourceFileName()));
- DataConsumer->setASTContext(Unit->getASTContext());
- DataConsumer->startedTranslationUnit();
+ DataConsumer.setASTContext(Unit->getASTContext());
+ DataConsumer.startedTranslationUnit();
- indexPreprocessingRecord(*Unit, *DataConsumer);
+ indexPreprocessingRecord(*Unit, DataConsumer);
indexASTUnit(*Unit, DataConsumer, getIndexingOptionsFromCXOptions(index_options));
- DataConsumer->indexDiagnostics();
+ DataConsumer.indexDiagnostics();
return CXError_Success;
}
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 4d3a029567d48..95a42712c4afe 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -46,6 +46,7 @@ clang_Cursor_isVariadic
clang_Cursor_getModule
clang_Cursor_getStorageClass
clang_File_isEqual
+clang_File_tryGetRealPathName
clang_Module_getASTFile
clang_Module_getParent
clang_Module_getName
@@ -170,6 +171,8 @@ clang_getCompletionBriefComment
clang_getCompletionChunkCompletionString
clang_getCompletionChunkKind
clang_getCompletionChunkText
+clang_getCompletionNumFixIts
+clang_getCompletionFixIt
clang_getCompletionNumAnnotations
clang_getCompletionParent
clang_getCompletionPriority
@@ -178,6 +181,8 @@ clang_getCursorAvailability
clang_getCursorCompletionString
clang_getCursorDefinition
clang_getCursorDisplayName
+clang_getCursorPrintingPolicy
+clang_getCursorPrettyPrinted
clang_getCursorExtent
clang_getCursorExceptionSpecificationType
clang_getCursorKind
@@ -220,6 +225,7 @@ clang_getExceptionSpecificationType
clang_getFieldDeclBitWidth
clang_getExpansionLocation
clang_getFile
+clang_getFileContents
clang_getFileLocation
clang_getFileName
clang_getFileTime
@@ -256,6 +262,7 @@ clang_getSpecializedCursorTemplate
clang_getSpellingLocation
clang_getTUResourceUsageName
clang_getTemplateCursorKind
+clang_getToken
clang_getTokenExtent
clang_getTokenKind
clang_getTokenLocation
@@ -290,6 +297,7 @@ clang_isAttribute
clang_isConstQualifiedType
clang_isCursorDefinition
clang_isDeclaration
+clang_isInvalidDeclaration
clang_isExpression
clang_isFileMultipleIncludeGuarded
clang_isFunctionTypeVariadic
@@ -357,3 +365,6 @@ clang_EvalResult_isUnsignedInt
clang_EvalResult_getAsDouble
clang_EvalResult_getAsStr
clang_EvalResult_dispose
+clang_PrintingPolicy_getProperty
+clang_PrintingPolicy_setProperty
+clang_PrintingPolicy_dispose