2012-12-18 22:30:41 +08:00
|
|
|
//===- CIndex.cpp - Clang-C Source Indexing Library -----------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-12-18 22:30:41 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the main API hooks in the Clang-C Source Indexing
|
|
|
|
// library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CIndexDiagnostic.h"
|
2016-07-19 03:02:11 +08:00
|
|
|
#include "CIndexer.h"
|
2013-01-19 16:09:44 +08:00
|
|
|
#include "CLog.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "CXCursor.h"
|
|
|
|
#include "CXSourceLocation.h"
|
|
|
|
#include "CXString.h"
|
|
|
|
#include "CXTranslationUnit.h"
|
|
|
|
#include "CXType.h"
|
|
|
|
#include "CursorVisitor.h"
|
Remove unnecessary inclusion of Sema.h
Let me tell you a tale...
Within some twisted maze of debug info I've ended up implementing an
insane man's Include What You Use device. When the debugger emits debug
info it really shouldn't, I find out why & then realize the code could
be improved too.
In this instance CIndexDiagnostics.cpp had a lot more debug info with
Clang than GCC. Upon inspection a major culprit was all the debug info
describing clang::Sema. This was emitted because clang::Sema is
befriended by DiagnosticEngine which was rightly required, but GCC
doesn't emit debug info for friends so it never emitted anything for
Clang. Clang does emit debug info for friends (will be fixed/changed to
reduce debug info size).
But why didn't Clang just emit a declaration of Sema if this entire TU
didn't require a definition?
1) Diagnostic.h did the right thing, only using a declaration of Sema
and not including Sema.h at all.
2) Some other dependency of CIndexDiagnostics.cpp didn't do the right
thing. ASTUnit.h, only needing a declaration, still included Sema.h
(hence this commit which removes that include and adds the necessary
includes to the cpp files that were relying on this)
3) -flimit-debug-info didn't save us because of
EnterExpressionEvaluationContext, defined inline in Sema.h which fires
the "requiresCompleteType" check/flag (since it uses nested types from
Sema and calls Sema member functions) and thus, if debug info is ever
emitted for the type, the whole type is emitted and not just a
declaration.
Improving -flimit-debug-info to account for this would be... hard.
Modifying the code so that's not 'required to be complete' might be
possible, but probably only by moving EnterExpressionEvaluationContext
either into Sema, or out of Sema.h. That might be a bit too much of a
contortion to be bothered with.
Also, this is only one of the cases where emitting debug info for
friends caused us to emit a lot more debug info (this change reduces
Clang's DWO size by 0.93%, dropping friends entirely reduces debug info
by 3.2%) - I haven't hunted down the other cases, but I assume they
might be similar (Sema or something like it). IWYU or a similar tool
might help us reduce build times a bit, but analyzing debug info to find
these differences isn't worthwhile. I'll take the 3.2% win, provide this
small improvement to the code itself, and move on.
llvm-svn: 190715
2013-09-14 02:32:52 +08:00
|
|
|
#include "clang/AST/Attr.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/AST/StmtVisitor.h"
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
2014-02-13 03:12:37 +08:00
|
|
|
#include "clang/Basic/DiagnosticCategories.h"
|
|
|
|
#include "clang/Basic/DiagnosticIDs.h"
|
2018-07-04 05:34:13 +08:00
|
|
|
#include "clang/Basic/Stack.h"
|
2017-04-28 23:56:39 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
|
|
|
#include "clang/Frontend/ASTUnit.h"
|
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
2016-02-15 06:30:14 +08:00
|
|
|
#include "clang/Index/CodegenNameGenerator.h"
|
2013-11-14 06:16:51 +08:00
|
|
|
#include "clang/Index/CommentToXML.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
|
|
|
#include "clang/Lex/Lexer.h"
|
|
|
|
#include "clang/Lex/PreprocessingRecord.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2014-06-04 11:28:55 +08:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/CrashRecoveryContext.h"
|
2013-01-19 16:09:44 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2014-06-27 23:14:39 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
|
|
|
#include "llvm/Support/SaveAndRestore.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
2015-07-08 09:00:30 +08:00
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
|
|
|
#include "llvm/Support/Timer.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2019-08-07 22:44:40 +08:00
|
|
|
#include <mutex>
|
2013-01-11 02:54:52 +08:00
|
|
|
|
2014-07-06 14:24:00 +08:00
|
|
|
#if LLVM_ENABLE_THREADS != 0 && defined(__APPLE__)
|
|
|
|
#define USE_DARWIN_THREADS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_DARWIN_THREADS
|
2013-01-11 02:54:52 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::cxcursor;
|
|
|
|
using namespace clang::cxtu;
|
|
|
|
using namespace clang::cxindex;
|
|
|
|
|
2017-01-07 03:49:01 +08:00
|
|
|
CXTranslationUnit cxtu::MakeCXTranslationUnit(CIndexer *CIdx,
|
|
|
|
std::unique_ptr<ASTUnit> AU) {
|
2013-01-27 05:32:42 +08:00
|
|
|
if (!AU)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2014-02-13 03:12:37 +08:00
|
|
|
assert(CIdx);
|
2012-12-18 22:30:41 +08:00
|
|
|
CXTranslationUnit D = new CXTranslationUnitImpl();
|
|
|
|
D->CIdx = CIdx;
|
2017-01-07 03:49:01 +08:00
|
|
|
D->TheASTUnit = AU.release();
|
2013-02-03 21:52:47 +08:00
|
|
|
D->StringPool = new cxstring::CXStringPool();
|
2014-06-08 16:38:04 +08:00
|
|
|
D->Diagnostics = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
D->OverridenCursorsPool = createOverridenCXCursorsPool();
|
2014-06-08 16:38:04 +08:00
|
|
|
D->CommentToXML = nullptr;
|
2017-12-08 04:37:50 +08:00
|
|
|
D->ParsingOptions = 0;
|
|
|
|
D->Arguments = {};
|
2012-12-18 22:30:41 +08:00
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
2014-02-13 03:12:37 +08:00
|
|
|
bool cxtu::isASTReadError(ASTUnit *AU) {
|
|
|
|
for (ASTUnit::stored_diag_iterator D = AU->stored_diag_begin(),
|
|
|
|
DEnd = AU->stored_diag_end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
if (D->getLevel() >= DiagnosticsEngine::Error &&
|
|
|
|
DiagnosticIDs::getCategoryNumberForDiag(D->getID()) ==
|
|
|
|
diag::DiagCat_AST_Deserialization_Issue)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
cxtu::CXTUOwner::~CXTUOwner() {
|
|
|
|
if (TU)
|
|
|
|
clang_disposeTranslationUnit(TU);
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Compare two source ranges to determine their relative position in
|
2012-12-18 22:30:41 +08:00
|
|
|
/// the translation unit.
|
|
|
|
static RangeComparisonResult RangeCompare(SourceManager &SM,
|
|
|
|
SourceRange R1,
|
|
|
|
SourceRange R2) {
|
|
|
|
assert(R1.isValid() && "First range is invalid?");
|
|
|
|
assert(R2.isValid() && "Second range is invalid?");
|
|
|
|
if (R1.getEnd() != R2.getBegin() &&
|
|
|
|
SM.isBeforeInTranslationUnit(R1.getEnd(), R2.getBegin()))
|
|
|
|
return RangeBefore;
|
|
|
|
if (R2.getEnd() != R1.getBegin() &&
|
|
|
|
SM.isBeforeInTranslationUnit(R2.getEnd(), R1.getBegin()))
|
|
|
|
return RangeAfter;
|
|
|
|
return RangeOverlap;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Determine if a source location falls within, before, or after a
|
2012-12-18 22:30:41 +08:00
|
|
|
/// a given source range.
|
|
|
|
static RangeComparisonResult LocationCompare(SourceManager &SM,
|
|
|
|
SourceLocation L, SourceRange R) {
|
|
|
|
assert(R.isValid() && "First range is invalid?");
|
|
|
|
assert(L.isValid() && "Second range is invalid?");
|
|
|
|
if (L == R.getBegin() || L == R.getEnd())
|
|
|
|
return RangeOverlap;
|
|
|
|
if (SM.isBeforeInTranslationUnit(L, R.getBegin()))
|
|
|
|
return RangeBefore;
|
|
|
|
if (SM.isBeforeInTranslationUnit(R.getEnd(), L))
|
|
|
|
return RangeAfter;
|
|
|
|
return RangeOverlap;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Translate a Clang source range into a CIndex source range.
|
2012-12-18 22:30:41 +08:00
|
|
|
///
|
|
|
|
/// 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
|
|
|
|
/// useful to have a CXSourceRange be a proper half-open interval. This routine
|
|
|
|
/// does the appropriate translation.
|
|
|
|
CXSourceRange cxloc::translateSourceRange(const SourceManager &SM,
|
|
|
|
const LangOptions &LangOpts,
|
|
|
|
const CharSourceRange &R) {
|
|
|
|
// We want the last character in this location, so we will adjust the
|
|
|
|
// location accordingly.
|
|
|
|
SourceLocation EndLoc = R.getEnd();
|
2018-04-30 13:25:48 +08:00
|
|
|
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()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Length = Lexer::MeasureTokenLength(SM.getSpellingLoc(EndLoc),
|
|
|
|
SM, LangOpts);
|
|
|
|
EndLoc = EndLoc.getLocWithOffset(Length);
|
|
|
|
}
|
|
|
|
|
2013-01-23 16:25:41 +08:00
|
|
|
CXSourceRange Result = {
|
2013-01-23 23:56:07 +08:00
|
|
|
{ &SM, &LangOpts },
|
2013-01-23 16:25:41 +08:00
|
|
|
R.getBegin().getRawEncoding(),
|
|
|
|
EndLoc.getRawEncoding()
|
|
|
|
};
|
2012-12-18 22:30:41 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Cursor visitor.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static SourceRange getRawCursorExtent(CXCursor C);
|
|
|
|
static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr);
|
|
|
|
|
|
|
|
RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) {
|
|
|
|
return RangeCompare(AU->getSourceManager(), R, RegionOfInterest);
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Visit the given cursor and, if requested by the visitor,
|
2012-12-18 22:30:41 +08:00
|
|
|
/// its children.
|
|
|
|
///
|
|
|
|
/// \param Cursor the cursor to visit.
|
|
|
|
///
|
|
|
|
/// \param CheckedRegionOfInterest if true, then the caller already checked
|
|
|
|
/// that this cursor is within the region of interest.
|
|
|
|
///
|
|
|
|
/// \returns true if the visitation should be aborted, false if it
|
|
|
|
/// should continue.
|
|
|
|
bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) {
|
|
|
|
if (clang_isInvalid(Cursor.kind))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (clang_isDeclaration(Cursor.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = getCursorDecl(Cursor);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D) {
|
|
|
|
assert(0 && "Invalid declaration cursor");
|
|
|
|
return true; // abort.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore implicit declarations, unless it's an objc method because
|
|
|
|
// currently we should report implicit methods for properties when indexing.
|
|
|
|
if (D->isImplicit() && !isa<ObjCMethodDecl>(D))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a range of interest, and this cursor doesn't intersect with it,
|
|
|
|
// we're done.
|
|
|
|
if (RegionOfInterest.isValid() && !CheckedRegionOfInterest) {
|
|
|
|
SourceRange Range = getRawCursorExtent(Cursor);
|
|
|
|
if (Range.isInvalid() || CompareRegionOfInterest(Range))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Visitor(Cursor, Parent, ClientData)) {
|
|
|
|
case CXChildVisit_Break:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case CXChildVisit_Continue:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case CXChildVisit_Recurse: {
|
|
|
|
bool ret = VisitChildren(Cursor);
|
|
|
|
if (PostChildrenVisitor)
|
|
|
|
if (PostChildrenVisitor(Cursor, ClientData))
|
|
|
|
return true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid CXChildVisitResult!");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool visitPreprocessedEntitiesInRange(SourceRange R,
|
|
|
|
PreprocessingRecord &PPRec,
|
|
|
|
CursorVisitor &Visitor) {
|
|
|
|
SourceManager &SM = Visitor.getASTUnit()->getSourceManager();
|
|
|
|
FileID FID;
|
|
|
|
|
|
|
|
if (!Visitor.shouldVisitIncludedEntities()) {
|
|
|
|
// If the begin/end of the range lie in the same FileID, do the optimization
|
|
|
|
// where we skip preprocessed entities that do not come from the same FileID.
|
|
|
|
FID = SM.getFileID(SM.getFileLoc(R.getBegin()));
|
|
|
|
if (FID != SM.getFileID(SM.getFileLoc(R.getEnd())))
|
|
|
|
FID = FileID();
|
|
|
|
}
|
|
|
|
|
2015-02-07 01:25:10 +08:00
|
|
|
const auto &Entities = PPRec.getPreprocessedEntitiesInRange(R);
|
|
|
|
return Visitor.visitPreprocessedEntities(Entities.begin(), Entities.end(),
|
2012-12-18 22:30:41 +08:00
|
|
|
PPRec, FID);
|
|
|
|
}
|
|
|
|
|
2013-03-09 04:42:33 +08:00
|
|
|
bool CursorVisitor::visitFileRegion() {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (RegionOfInterest.isInvalid())
|
2013-03-09 04:42:33 +08:00
|
|
|
return false;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *Unit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceManager &SM = Unit->getSourceManager();
|
|
|
|
|
|
|
|
std::pair<FileID, unsigned>
|
|
|
|
Begin = SM.getDecomposedLoc(SM.getFileLoc(RegionOfInterest.getBegin())),
|
|
|
|
End = SM.getDecomposedLoc(SM.getFileLoc(RegionOfInterest.getEnd()));
|
|
|
|
|
|
|
|
if (End.first != Begin.first) {
|
|
|
|
// If the end does not reside in the same file, try to recover by
|
|
|
|
// picking the end of the file of begin location.
|
|
|
|
End.first = Begin.first;
|
|
|
|
End.second = SM.getFileIDSize(Begin.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(Begin.first == End.first);
|
|
|
|
if (Begin.second > End.second)
|
2013-03-09 04:42:33 +08:00
|
|
|
return false;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
FileID File = Begin.first;
|
|
|
|
unsigned Offset = Begin.second;
|
|
|
|
unsigned Length = End.second - Begin.second;
|
|
|
|
|
|
|
|
if (!VisitDeclsOnly && !VisitPreprocessorLast)
|
|
|
|
if (visitPreprocessedEntitiesInRegion())
|
2013-03-09 04:42:33 +08:00
|
|
|
return true; // visitation break.
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-03-09 04:42:33 +08:00
|
|
|
if (visitDeclsFromFileRegion(File, Offset, Length))
|
|
|
|
return true; // visitation break.
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (!VisitDeclsOnly && VisitPreprocessorLast)
|
2013-03-09 04:42:33 +08:00
|
|
|
return visitPreprocessedEntitiesInRegion();
|
|
|
|
|
|
|
|
return false;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isInLexicalContext(Decl *D, DeclContext *DC) {
|
|
|
|
if (!DC)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (DeclContext *DeclDC = D->getLexicalDeclContext();
|
|
|
|
DeclDC; DeclDC = DeclDC->getLexicalParent()) {
|
|
|
|
if (DeclDC == DC)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-09 04:42:33 +08:00
|
|
|
bool CursorVisitor::visitDeclsFromFileRegion(FileID File,
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Offset, unsigned Length) {
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *Unit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceManager &SM = Unit->getSourceManager();
|
|
|
|
SourceRange Range = RegionOfInterest;
|
|
|
|
|
|
|
|
SmallVector<Decl *, 16> Decls;
|
|
|
|
Unit->findFileRegionDecls(File, Offset, Length, Decls);
|
|
|
|
|
|
|
|
// If we didn't find any file level decls for the file, try looking at the
|
|
|
|
// file that it was included from.
|
|
|
|
while (Decls.empty() || Decls.front()->isTopLevelDeclInObjCContainer()) {
|
|
|
|
bool Invalid = false;
|
|
|
|
const SrcMgr::SLocEntry &SLEntry = SM.getSLocEntry(File, &Invalid);
|
|
|
|
if (Invalid)
|
2013-03-09 04:42:33 +08:00
|
|
|
return false;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
SourceLocation Outer;
|
|
|
|
if (SLEntry.isFile())
|
|
|
|
Outer = SLEntry.getFile().getIncludeLoc();
|
|
|
|
else
|
|
|
|
Outer = SLEntry.getExpansion().getExpansionLocStart();
|
|
|
|
if (Outer.isInvalid())
|
2013-03-09 04:42:33 +08:00
|
|
|
return false;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-03-02 21:01:17 +08:00
|
|
|
std::tie(File, Offset) = SM.getDecomposedExpansionLoc(Outer);
|
2012-12-18 22:30:41 +08:00
|
|
|
Length = 0;
|
|
|
|
Unit->findFileRegionDecls(File, Offset, Length, Decls);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!Decls.empty());
|
|
|
|
|
|
|
|
bool VisitedAtLeastOnce = false;
|
2014-06-08 16:38:04 +08:00
|
|
|
DeclContext *CurDC = nullptr;
|
2013-07-04 11:08:24 +08:00
|
|
|
SmallVectorImpl<Decl *>::iterator DIt = Decls.begin();
|
|
|
|
for (SmallVectorImpl<Decl *>::iterator DE = Decls.end(); DIt != DE; ++DIt) {
|
2012-12-18 22:30:41 +08:00
|
|
|
Decl *D = *DIt;
|
|
|
|
if (D->getSourceRange().isInvalid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (isInLexicalContext(D, CurDC))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CurDC = dyn_cast<DeclContext>(D);
|
|
|
|
|
|
|
|
if (TagDecl *TD = dyn_cast<TagDecl>(D))
|
|
|
|
if (!TD->isFreeStanding())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
RangeComparisonResult CompRes = RangeCompare(SM, D->getSourceRange(),Range);
|
|
|
|
if (CompRes == RangeBefore)
|
|
|
|
continue;
|
|
|
|
if (CompRes == RangeAfter)
|
|
|
|
break;
|
|
|
|
|
|
|
|
assert(CompRes == RangeOverlap);
|
|
|
|
VisitedAtLeastOnce = true;
|
|
|
|
|
|
|
|
if (isa<ObjCContainerDecl>(D)) {
|
|
|
|
FileDI_current = &DIt;
|
|
|
|
FileDE_current = DE;
|
|
|
|
} else {
|
2014-06-08 16:38:04 +08:00
|
|
|
FileDI_current = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true))
|
2013-03-09 04:42:33 +08:00
|
|
|
return true; // visitation break.
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (VisitedAtLeastOnce)
|
2013-03-09 04:42:33 +08:00
|
|
|
return false;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// No Decls overlapped with the range. Move up the lexical context until there
|
|
|
|
// is a context that contains the range or we reach the translation unit
|
|
|
|
// level.
|
|
|
|
DeclContext *DC = DIt == Decls.begin() ? (*DIt)->getLexicalDeclContext()
|
|
|
|
: (*(DIt-1))->getLexicalDeclContext();
|
|
|
|
|
|
|
|
while (DC && !DC->isTranslationUnit()) {
|
|
|
|
Decl *D = cast<Decl>(DC);
|
|
|
|
SourceRange CurDeclRange = D->getSourceRange();
|
|
|
|
if (CurDeclRange.isInvalid())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (RangeCompare(SM, CurDeclRange, Range) == RangeOverlap) {
|
2013-03-09 04:42:33 +08:00
|
|
|
if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true))
|
|
|
|
return true; // visitation break.
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DC = D->getLexicalDeclContext();
|
|
|
|
}
|
2013-03-09 04:42:33 +08:00
|
|
|
|
|
|
|
return false;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::visitPreprocessedEntitiesInRegion() {
|
|
|
|
if (!AU->getPreprocessor().getPreprocessingRecord())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
PreprocessingRecord &PPRec
|
|
|
|
= *AU->getPreprocessor().getPreprocessingRecord();
|
|
|
|
SourceManager &SM = AU->getSourceManager();
|
|
|
|
|
|
|
|
if (RegionOfInterest.isValid()) {
|
|
|
|
SourceRange MappedRange = AU->mapRangeToPreamble(RegionOfInterest);
|
|
|
|
SourceLocation B = MappedRange.getBegin();
|
|
|
|
SourceLocation E = MappedRange.getEnd();
|
|
|
|
|
|
|
|
if (AU->isInPreambleFileID(B)) {
|
|
|
|
if (SM.isLoadedSourceLocation(E))
|
|
|
|
return visitPreprocessedEntitiesInRange(SourceRange(B, E),
|
|
|
|
PPRec, *this);
|
|
|
|
|
|
|
|
// Beginning of range lies in the preamble but it also extends beyond
|
|
|
|
// it into the main file. Split the range into 2 parts, one covering
|
|
|
|
// the preamble and another covering the main file. This allows subsequent
|
|
|
|
// calls to visitPreprocessedEntitiesInRange to accept a source range that
|
|
|
|
// lies in the same FileID, allowing it to skip preprocessed entities that
|
|
|
|
// do not come from the same FileID.
|
|
|
|
bool breaked =
|
|
|
|
visitPreprocessedEntitiesInRange(
|
|
|
|
SourceRange(B, AU->getEndOfPreambleFileID()),
|
|
|
|
PPRec, *this);
|
|
|
|
if (breaked) return true;
|
|
|
|
return visitPreprocessedEntitiesInRange(
|
|
|
|
SourceRange(AU->getStartOfMainFileID(), E),
|
|
|
|
PPRec, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return visitPreprocessedEntitiesInRange(SourceRange(B, E), PPRec, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnlyLocalDecls
|
|
|
|
= !AU->isMainFileAST() && AU->getOnlyLocalDecls();
|
|
|
|
|
|
|
|
if (OnlyLocalDecls)
|
|
|
|
return visitPreprocessedEntities(PPRec.local_begin(), PPRec.local_end(),
|
|
|
|
PPRec);
|
|
|
|
|
|
|
|
return visitPreprocessedEntities(PPRec.begin(), PPRec.end(), PPRec);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
bool CursorVisitor::visitPreprocessedEntities(InputIterator First,
|
|
|
|
InputIterator Last,
|
|
|
|
PreprocessingRecord &PPRec,
|
|
|
|
FileID FID) {
|
|
|
|
for (; First != Last; ++First) {
|
|
|
|
if (!FID.isInvalid() && !PPRec.isEntityInFileID(First, FID))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PreprocessedEntity *PPE = *First;
|
2013-05-08 04:37:17 +08:00
|
|
|
if (!PPE)
|
|
|
|
continue;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (MacroExpansion *ME = dyn_cast<MacroExpansion>(PPE)) {
|
|
|
|
if (Visit(MakeMacroExpansionCursor(ME, TU)))
|
|
|
|
return true;
|
2015-05-04 10:25:31 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
2015-05-04 10:25:31 +08:00
|
|
|
|
|
|
|
if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(PPE)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Visit(MakeMacroDefinitionCursor(MD, TU)))
|
|
|
|
return true;
|
2015-05-04 10:25:31 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
|
|
|
|
if (Visit(MakeInclusionDirectiveCursor(ID, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Visit the children of the given cursor.
|
2012-12-18 22:30:41 +08:00
|
|
|
///
|
|
|
|
/// \returns true if the visitation should be aborted, false if it
|
|
|
|
/// should continue.
|
|
|
|
bool CursorVisitor::VisitChildren(CXCursor Cursor) {
|
|
|
|
if (clang_isReference(Cursor.kind) &&
|
|
|
|
Cursor.kind != CXCursor_CXXBaseSpecifier) {
|
|
|
|
// By definition, references have no children.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the Parent field to Cursor, then back to its old value once we're
|
|
|
|
// done.
|
|
|
|
SetParentRAII SetParent(Parent, StmtParent, Cursor);
|
|
|
|
|
|
|
|
if (clang_isDeclaration(Cursor.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
Decl *D = const_cast<Decl *>(getCursorDecl(Cursor));
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return VisitAttributes(D) || Visit(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isStatement(Cursor.kind)) {
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const Stmt *S = getCursorStmt(Cursor))
|
2012-12-18 22:30:41 +08:00
|
|
|
return Visit(S);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isExpression(Cursor.kind)) {
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const Expr *E = getCursorExpr(Cursor))
|
2012-12-18 22:30:41 +08:00
|
|
|
return Visit(E);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isTranslationUnit(Cursor.kind)) {
|
2013-01-27 02:53:38 +08:00
|
|
|
CXTranslationUnit TU = getCursorTU(Cursor);
|
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
int VisitOrder[2] = { VisitPreprocessorLast, !VisitPreprocessorLast };
|
|
|
|
for (unsigned I = 0; I != 2; ++I) {
|
|
|
|
if (VisitOrder[I]) {
|
|
|
|
if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() &&
|
|
|
|
RegionOfInterest.isInvalid()) {
|
|
|
|
for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(),
|
|
|
|
TLEnd = CXXUnit->top_level_end();
|
|
|
|
TL != TLEnd; ++TL) {
|
2016-07-02 03:10:54 +08:00
|
|
|
const Optional<bool> V = handleDeclForVisitation(*TL);
|
|
|
|
if (!V.hasValue())
|
|
|
|
continue;
|
|
|
|
return V.getValue();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
} else if (VisitDeclContext(
|
|
|
|
CXXUnit->getASTContext().getTranslationUnitDecl()))
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk the preprocessing record.
|
|
|
|
if (CXXUnit->getPreprocessor().getPreprocessingRecord())
|
|
|
|
visitPreprocessedEntitiesInRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cursor.kind == CXCursor_CXXBaseSpecifier) {
|
2013-01-12 05:01:49 +08:00
|
|
|
if (const CXXBaseSpecifier *Base = getCursorCXXBaseSpecifier(Cursor)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (TypeSourceInfo *BaseTSInfo = Base->getTypeSourceInfo()) {
|
|
|
|
return Visit(BaseTSInfo->getTypeLoc());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cursor.kind == CXCursor_IBOutletCollectionAttr) {
|
2013-01-27 02:08:08 +08:00
|
|
|
const IBOutletCollectionAttr *A =
|
2012-12-18 22:30:41 +08:00
|
|
|
cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(Cursor));
|
2013-10-31 09:56:18 +08:00
|
|
|
if (const ObjCObjectType *ObjT = A->getInterface()->getAs<ObjCObjectType>())
|
2013-11-01 05:23:20 +08:00
|
|
|
return Visit(cxcursor::MakeCursorObjCClassRef(
|
|
|
|
ObjT->getInterface(),
|
2018-08-10 05:08:08 +08:00
|
|
|
A->getInterfaceLoc()->getTypeLoc().getBeginLoc(), TU));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-08 03:16:25 +08:00
|
|
|
// If pointing inside a macro definition, check if the token is an identifier
|
|
|
|
// that was ever defined as a macro. In such a case, create a "pseudo" macro
|
|
|
|
// expansion cursor for that token.
|
|
|
|
SourceLocation BeginLoc = RegionOfInterest.getBegin();
|
|
|
|
if (Cursor.kind == CXCursor_MacroDefinition &&
|
|
|
|
BeginLoc == RegionOfInterest.getEnd()) {
|
|
|
|
SourceLocation Loc = AU->mapLocationToPreamble(BeginLoc);
|
2013-01-12 05:01:49 +08:00
|
|
|
const MacroInfo *MI =
|
|
|
|
getMacroInfo(cxcursor::getCursorMacroDefinition(Cursor), TU);
|
2015-05-04 10:25:31 +08:00
|
|
|
if (MacroDefinitionRecord *MacroDef =
|
|
|
|
checkForMacroInMacroDefinition(MI, Loc, TU))
|
2013-01-08 03:16:25 +08:00
|
|
|
return Visit(cxcursor::MakeMacroExpansionCursor(MacroDef, BeginLoc, TU));
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Nothing to visit at the moment.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitBlockDecl(BlockDecl *B) {
|
|
|
|
if (TypeSourceInfo *TSInfo = B->getSignatureAsWritten())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Stmt *Body = B->getBody())
|
|
|
|
return Visit(MakeCXCursor(Body, StmtParent, TU, RegionOfInterest));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-21 09:29:01 +08:00
|
|
|
Optional<bool> CursorVisitor::shouldVisitCursor(CXCursor Cursor) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (RegionOfInterest.isValid()) {
|
|
|
|
SourceRange Range = getFullCursorExtent(Cursor, AU->getSourceManager());
|
|
|
|
if (Range.isInvalid())
|
2013-02-21 09:47:18 +08:00
|
|
|
return None;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
switch (CompareRegionOfInterest(Range)) {
|
|
|
|
case RangeBefore:
|
|
|
|
// This declaration comes before the region of interest; skip it.
|
2013-02-21 09:47:18 +08:00
|
|
|
return None;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
case RangeAfter:
|
|
|
|
// This declaration comes after the region of interest; we're done.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case RangeOverlap:
|
|
|
|
// This declaration overlaps the region of interest; visit it.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitDeclContext(DeclContext *DC) {
|
|
|
|
DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end();
|
|
|
|
|
|
|
|
// FIXME: Eventually remove. This part of a hack to support proper
|
|
|
|
// iteration over all Decls contained lexically within an ObjC container.
|
|
|
|
SaveAndRestore<DeclContext::decl_iterator*> DI_saved(DI_current, &I);
|
|
|
|
SaveAndRestore<DeclContext::decl_iterator> DE_saved(DE_current, E);
|
|
|
|
|
|
|
|
for ( ; I != E; ++I) {
|
|
|
|
Decl *D = *I;
|
|
|
|
if (D->getLexicalDeclContext() != DC)
|
|
|
|
continue;
|
2016-07-02 03:10:54 +08:00
|
|
|
const Optional<bool> V = handleDeclForVisitation(D);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!V.hasValue())
|
|
|
|
continue;
|
2016-07-02 03:10:54 +08:00
|
|
|
return V.getValue();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-02 03:10:54 +08:00
|
|
|
|
|
|
|
Optional<bool> CursorVisitor::handleDeclForVisitation(const Decl *D) {
|
|
|
|
CXCursor Cursor = MakeCXCursor(D, TU, RegionOfInterest);
|
|
|
|
|
|
|
|
// Ignore synthesized ivars here, otherwise if we have something like:
|
|
|
|
// @synthesize prop = _prop;
|
|
|
|
// and '_prop' is not declared, we will encounter a '_prop' ivar before
|
|
|
|
// encountering the 'prop' synthesize declaration and we will think that
|
|
|
|
// we passed the region-of-interest.
|
|
|
|
if (auto *ivarD = dyn_cast<ObjCIvarDecl>(D)) {
|
|
|
|
if (ivarD->getSynthesize())
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: ObjCClassRef/ObjCProtocolRef for forward class/protocol
|
|
|
|
// declarations is a mismatch with the compiler semantics.
|
|
|
|
if (Cursor.kind == CXCursor_ObjCInterfaceDecl) {
|
|
|
|
auto *ID = cast<ObjCInterfaceDecl>(D);
|
|
|
|
if (!ID->isThisDeclarationADefinition())
|
|
|
|
Cursor = MakeCursorObjCClassRef(ID, ID->getLocation(), TU);
|
|
|
|
|
|
|
|
} else if (Cursor.kind == CXCursor_ObjCProtocolDecl) {
|
|
|
|
auto *PD = cast<ObjCProtocolDecl>(D);
|
|
|
|
if (!PD->isThisDeclarationADefinition())
|
|
|
|
Cursor = MakeCursorObjCProtocolRef(PD, PD->getLocation(), TU);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Optional<bool> V = shouldVisitCursor(Cursor);
|
|
|
|
if (!V.hasValue())
|
|
|
|
return None;
|
|
|
|
if (!V.getValue())
|
|
|
|
return false;
|
|
|
|
if (Visit(Cursor, true))
|
|
|
|
return true;
|
|
|
|
return None;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
bool CursorVisitor::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
|
|
|
|
llvm_unreachable("Translation units are visited directly by Visit()");
|
|
|
|
}
|
|
|
|
|
2015-11-15 21:48:32 +08:00
|
|
|
bool CursorVisitor::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
|
|
|
|
if (VisitTemplateParameters(D->getTemplateParameters()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Visit(MakeCXCursor(D->getTemplatedDecl(), TU, RegionOfInterest));
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool CursorVisitor::VisitTypeAliasDecl(TypeAliasDecl *D) {
|
|
|
|
if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTypedefDecl(TypedefDecl *D) {
|
|
|
|
if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTagDecl(TagDecl *D) {
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitClassTemplateSpecializationDecl(
|
|
|
|
ClassTemplateSpecializationDecl *D) {
|
|
|
|
bool ShouldVisitBody = false;
|
|
|
|
switch (D->getSpecializationKind()) {
|
|
|
|
case TSK_Undeclared:
|
|
|
|
case TSK_ImplicitInstantiation:
|
|
|
|
// Nothing to visit
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TSK_ExplicitInstantiationDeclaration:
|
|
|
|
case TSK_ExplicitInstantiationDefinition:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSK_ExplicitSpecialization:
|
|
|
|
ShouldVisitBody = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Visit the template arguments used in the specialization.
|
|
|
|
if (TypeSourceInfo *SpecType = D->getTypeAsWritten()) {
|
|
|
|
TypeLoc TL = SpecType->getTypeLoc();
|
2013-02-19 06:06:02 +08:00
|
|
|
if (TemplateSpecializationTypeLoc TSTLoc =
|
|
|
|
TL.getAs<TemplateSpecializationTypeLoc>()) {
|
|
|
|
for (unsigned I = 0, N = TSTLoc.getNumArgs(); I != N; ++I)
|
|
|
|
if (VisitTemplateArgumentLoc(TSTLoc.getArgLoc(I)))
|
2012-12-18 22:30:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-12-28 23:24:08 +08:00
|
|
|
|
|
|
|
return ShouldVisitBody && VisitCXXRecordDecl(D);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitClassTemplatePartialSpecializationDecl(
|
|
|
|
ClassTemplatePartialSpecializationDecl *D) {
|
|
|
|
// FIXME: Visit the "outer" template parameter lists on the TagDecl
|
|
|
|
// before visiting these template parameters.
|
|
|
|
if (VisitTemplateParameters(D->getTemplateParameters()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the partial specialization arguments.
|
2013-08-10 15:24:53 +08:00
|
|
|
const ASTTemplateArgumentListInfo *Info = D->getTemplateArgsAsWritten();
|
|
|
|
const TemplateArgumentLoc *TemplateArgs = Info->getTemplateArgs();
|
|
|
|
for (unsigned I = 0, N = Info->NumTemplateArgs; I != N; ++I)
|
2012-12-18 22:30:41 +08:00
|
|
|
if (VisitTemplateArgumentLoc(TemplateArgs[I]))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitCXXRecordDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
|
|
|
|
// Visit the default argument.
|
|
|
|
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
|
|
|
|
if (TypeSourceInfo *DefArg = D->getDefaultArgumentInfo())
|
|
|
|
if (Visit(DefArg->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitEnumConstantDecl(EnumConstantDecl *D) {
|
|
|
|
if (Expr *Init = D->getInitExpr())
|
|
|
|
return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) {
|
2013-04-06 05:04:10 +08:00
|
|
|
unsigned NumParamList = DD->getNumTemplateParameterLists();
|
|
|
|
for (unsigned i = 0; i < NumParamList; i++) {
|
|
|
|
TemplateParameterList* Params = DD->getTemplateParameterList(i);
|
|
|
|
if (VisitTemplateParameters(Params))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the nested-name-specifier, if present.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = DD->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
|
2018-01-03 18:33:21 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-03 22:35:48 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Compare two base or member initializers based on their source order.
|
2018-01-03 18:33:21 +08:00
|
|
|
static int CompareCXXCtorInitializers(CXXCtorInitializer *const *X,
|
|
|
|
CXXCtorInitializer *const *Y) {
|
2014-03-08 05:51:58 +08:00
|
|
|
return (*X)->getSourceOrder() - (*Y)->getSourceOrder();
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
|
2013-04-06 05:04:10 +08:00
|
|
|
unsigned NumParamList = ND->getNumTemplateParameterLists();
|
|
|
|
for (unsigned i = 0; i < NumParamList; i++) {
|
|
|
|
TemplateParameterList* Params = ND->getTemplateParameterList(i);
|
|
|
|
if (VisitTemplateParameters(Params))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (TypeSourceInfo *TSInfo = ND->getTypeSourceInfo()) {
|
|
|
|
// Visit the function declaration's syntactic components in the order
|
2018-01-03 18:33:21 +08:00
|
|
|
// written. This requires a bit of work.
|
|
|
|
TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
|
|
|
|
FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>();
|
2018-01-03 22:35:48 +08:00
|
|
|
const bool HasTrailingRT = HasTrailingReturnType(ND);
|
2018-01-03 18:33:21 +08:00
|
|
|
|
|
|
|
// 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.
|
2018-01-03 22:35:48 +08:00
|
|
|
if ((FTL && !isa<CXXConversionDecl>(ND) && !HasTrailingRT &&
|
|
|
|
Visit(FTL.getReturnLoc())) ||
|
2018-01-03 18:33:21 +08:00
|
|
|
(!FTL && Visit(TL)))
|
|
|
|
return true;
|
2018-01-03 22:35:48 +08:00
|
|
|
|
2018-01-03 18:33:21 +08:00
|
|
|
// Visit the nested-name-specifier, if present.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = ND->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
2012-12-18 22:30:41 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the declaration name.
|
2014-02-09 16:13:47 +08:00
|
|
|
if (!isa<CXXDestructorDecl>(ND))
|
|
|
|
if (VisitDeclarationNameInfo(ND->getNameInfo()))
|
|
|
|
return true;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// FIXME: Visit explicitly-specified template arguments!
|
|
|
|
|
2018-01-03 18:33:21 +08:00
|
|
|
// Visit the function parameters, if we have a function type.
|
|
|
|
if (FTL && VisitFunctionTypeLoc(FTL, true))
|
|
|
|
return true;
|
2018-01-03 22:35:48 +08:00
|
|
|
|
|
|
|
// Visit the function's trailing return type.
|
|
|
|
if (FTL && HasTrailingRT && Visit(FTL.getReturnLoc()))
|
|
|
|
return true;
|
|
|
|
|
2018-01-03 18:33:21 +08:00
|
|
|
// FIXME: Attributes?
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ND->doesThisDeclarationHaveABody() && !ND->isLateTemplateParsed()) {
|
|
|
|
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ND)) {
|
|
|
|
// Find the initializers that were written in the source.
|
|
|
|
SmallVector<CXXCtorInitializer *, 4> WrittenInits;
|
2014-03-14 01:34:31 +08:00
|
|
|
for (auto *I : Constructor->inits()) {
|
|
|
|
if (!I->isWritten())
|
2012-12-18 22:30:41 +08:00
|
|
|
continue;
|
|
|
|
|
2014-03-14 01:34:31 +08:00
|
|
|
WrittenInits.push_back(I);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the initializers in source order
|
2014-03-08 05:51:58 +08:00
|
|
|
llvm::array_pod_sort(WrittenInits.begin(), WrittenInits.end(),
|
|
|
|
&CompareCXXCtorInitializers);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Visit the initializers in source order
|
|
|
|
for (unsigned I = 0, N = WrittenInits.size(); I != N; ++I) {
|
|
|
|
CXXCtorInitializer *Init = WrittenInits[I];
|
|
|
|
if (Init->isAnyMemberInitializer()) {
|
|
|
|
if (Visit(MakeCursorMemberRef(Init->getAnyMember(),
|
|
|
|
Init->getMemberLocation(), TU)))
|
|
|
|
return true;
|
|
|
|
} else if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo()) {
|
|
|
|
if (Visit(TInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Visit the initializer value.
|
|
|
|
if (Expr *Initializer = Init->getInit())
|
|
|
|
if (Visit(MakeCXCursor(Initializer, ND, TU, RegionOfInterest)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitFieldDecl(FieldDecl *D) {
|
|
|
|
if (VisitDeclaratorDecl(D))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Expr *BitWidth = D->getBitWidth())
|
|
|
|
return Visit(MakeCXCursor(BitWidth, StmtParent, TU, RegionOfInterest));
|
|
|
|
|
2017-11-15 20:20:41 +08:00
|
|
|
if (Expr *Init = D->getInClassInitializer())
|
|
|
|
return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitVarDecl(VarDecl *D) {
|
|
|
|
if (VisitDeclaratorDecl(D))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Expr *Init = D->getInit())
|
|
|
|
return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
|
|
|
|
if (VisitDeclaratorDecl(D))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
|
|
|
|
if (Expr *DefArg = D->getDefaultArgument())
|
|
|
|
return Visit(MakeCXCursor(DefArg, StmtParent, TU, RegionOfInterest));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
|
|
|
|
// FIXME: Visit the "outer" template parameter lists on the FunctionDecl
|
|
|
|
// before visiting these template parameters.
|
|
|
|
if (VisitTemplateParameters(D->getTemplateParameters()))
|
|
|
|
return true;
|
|
|
|
|
2017-10-17 07:43:02 +08:00
|
|
|
auto* FD = D->getTemplatedDecl();
|
|
|
|
return VisitAttributes(FD) || VisitFunctionDecl(FD);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitClassTemplateDecl(ClassTemplateDecl *D) {
|
|
|
|
// FIXME: Visit the "outer" template parameter lists on the TagDecl
|
|
|
|
// before visiting these template parameters.
|
|
|
|
if (VisitTemplateParameters(D->getTemplateParameters()))
|
|
|
|
return true;
|
|
|
|
|
2017-10-17 07:43:02 +08:00
|
|
|
auto* CD = D->getTemplatedDecl();
|
|
|
|
return VisitAttributes(CD) || VisitCXXRecordDecl(CD);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
|
|
|
|
if (VisitTemplateParameters(D->getTemplateParameters()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited() &&
|
|
|
|
VisitTemplateArgumentLoc(D->getDefaultArgument()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:58:14 +08:00
|
|
|
bool CursorVisitor::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
|
|
|
|
// Visit the bound, if it's explicit.
|
|
|
|
if (D->hasExplicitBound()) {
|
|
|
|
if (auto TInfo = D->getTypeSourceInfo()) {
|
|
|
|
if (Visit(TInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) {
|
2014-01-26 00:55:45 +08:00
|
|
|
if (TypeSourceInfo *TSInfo = ND->getReturnTypeSourceInfo())
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
2016-06-24 12:05:48 +08:00
|
|
|
for (const auto *P : ND->parameters()) {
|
2014-03-08 01:50:17 +08:00
|
|
|
if (Visit(MakeCXCursor(P, TU, RegionOfInterest)))
|
2012-12-18 22:30:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-28 23:24:08 +08:00
|
|
|
return ND->isThisDeclarationADefinition() &&
|
|
|
|
Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename DeclIt>
|
|
|
|
static void addRangedDeclsInContainer(DeclIt *DI_current, DeclIt DE_current,
|
|
|
|
SourceManager &SM, SourceLocation EndLoc,
|
|
|
|
SmallVectorImpl<Decl *> &Decls) {
|
|
|
|
DeclIt next = *DI_current;
|
|
|
|
while (++next != DE_current) {
|
|
|
|
Decl *D_next = *next;
|
|
|
|
if (!D_next)
|
|
|
|
break;
|
2018-08-10 05:08:08 +08:00
|
|
|
SourceLocation L = D_next->getBeginLoc();
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!L.isValid())
|
|
|
|
break;
|
|
|
|
if (SM.isBeforeInTranslationUnit(L, EndLoc)) {
|
|
|
|
*DI_current = next;
|
|
|
|
Decls.push_back(D_next);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) {
|
|
|
|
// FIXME: Eventually convert back to just 'VisitDeclContext()'. Essentially
|
|
|
|
// an @implementation can lexically contain Decls that are not properly
|
|
|
|
// nested in the AST. When we identify such cases, we need to retrofit
|
|
|
|
// this nesting here.
|
|
|
|
if (!DI_current && !FileDI_current)
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
|
|
|
|
// Scan the Decls that immediately come after the container
|
|
|
|
// in the current DeclContext. If any fall within the
|
|
|
|
// container's lexical region, stash them into a vector
|
|
|
|
// for later processing.
|
|
|
|
SmallVector<Decl *, 24> DeclsInContainer;
|
|
|
|
SourceLocation EndLoc = D->getSourceRange().getEnd();
|
|
|
|
SourceManager &SM = AU->getSourceManager();
|
|
|
|
if (EndLoc.isValid()) {
|
|
|
|
if (DI_current) {
|
|
|
|
addRangedDeclsInContainer(DI_current, DE_current, SM, EndLoc,
|
|
|
|
DeclsInContainer);
|
|
|
|
} else {
|
|
|
|
addRangedDeclsInContainer(FileDI_current, FileDE_current, SM, EndLoc,
|
|
|
|
DeclsInContainer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The common case.
|
|
|
|
if (DeclsInContainer.empty())
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
|
|
|
|
// Get all the Decls in the DeclContext, and sort them with the
|
|
|
|
// additional ones we've collected. Then visit them.
|
2014-03-08 03:56:05 +08:00
|
|
|
for (auto *SubDecl : D->decls()) {
|
|
|
|
if (!SubDecl || SubDecl->getLexicalDeclContext() != D ||
|
2018-08-10 05:08:08 +08:00
|
|
|
SubDecl->getBeginLoc().isInvalid())
|
2012-12-18 22:30:41 +08:00
|
|
|
continue;
|
2014-03-08 03:56:05 +08:00
|
|
|
DeclsInContainer.push_back(SubDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now sort the Decls so that they appear in lexical order.
|
2018-09-27 06:16:28 +08:00
|
|
|
llvm::sort(DeclsInContainer,
|
2018-03-28 00:50:00 +08:00
|
|
|
[&SM](Decl *A, Decl *B) {
|
2018-08-10 05:08:08 +08:00
|
|
|
SourceLocation L_A = A->getBeginLoc();
|
|
|
|
SourceLocation L_B = B->getBeginLoc();
|
|
|
|
return L_A != L_B ? SM.isBeforeInTranslationUnit(L_A, L_B)
|
2018-08-10 05:09:38 +08:00
|
|
|
: SM.isBeforeInTranslationUnit(A->getEndLoc(),
|
|
|
|
B->getEndLoc());
|
2018-08-10 05:08:08 +08:00
|
|
|
});
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Now visit the decls.
|
|
|
|
for (SmallVectorImpl<Decl*>::iterator I = DeclsInContainer.begin(),
|
|
|
|
E = DeclsInContainer.end(); I != E; ++I) {
|
|
|
|
CXCursor Cursor = MakeCXCursor(*I, TU, RegionOfInterest);
|
2013-02-21 09:29:01 +08:00
|
|
|
const Optional<bool> &V = shouldVisitCursor(Cursor);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!V.hasValue())
|
|
|
|
continue;
|
|
|
|
if (!V.getValue())
|
|
|
|
return false;
|
|
|
|
if (Visit(Cursor, true))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) {
|
|
|
|
if (Visit(MakeCursorObjCClassRef(ND->getClassInterface(), ND->getLocation(),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
|
2015-07-07 11:57:35 +08:00
|
|
|
if (VisitObjCTypeParamList(ND->getTypeParamList()))
|
|
|
|
return true;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
ObjCCategoryDecl::protocol_loc_iterator PL = ND->protocol_loc_begin();
|
|
|
|
for (ObjCCategoryDecl::protocol_iterator I = ND->protocol_begin(),
|
|
|
|
E = ND->protocol_end(); I != E; ++I, ++PL)
|
|
|
|
if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitObjCContainerDecl(ND);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
|
|
|
|
if (!PID->isThisDeclarationADefinition())
|
|
|
|
return Visit(MakeCursorObjCProtocolRef(PID, PID->getLocation(), TU));
|
|
|
|
|
|
|
|
ObjCProtocolDecl::protocol_loc_iterator PL = PID->protocol_loc_begin();
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
|
|
|
|
E = PID->protocol_end(); I != E; ++I, ++PL)
|
|
|
|
if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitObjCContainerDecl(PID);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) {
|
|
|
|
if (PD->getTypeSourceInfo() && Visit(PD->getTypeSourceInfo()->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// FIXME: This implements a workaround with @property declarations also being
|
|
|
|
// installed in the DeclContext for the @interface. Eventually this code
|
|
|
|
// should be removed.
|
|
|
|
ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(PD->getDeclContext());
|
|
|
|
if (!CDecl || !CDecl->IsClassExtension())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ObjCInterfaceDecl *ID = CDecl->getClassInterface();
|
|
|
|
if (!ID)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
IdentifierInfo *PropertyId = PD->getIdentifier();
|
|
|
|
ObjCPropertyDecl *prevDecl =
|
2016-01-29 02:49:28 +08:00
|
|
|
ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(ID), PropertyId,
|
|
|
|
PD->getQueryKind());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (!prevDecl)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Visit synthesized methods since they will be skipped when visiting
|
|
|
|
// the @interface.
|
|
|
|
if (ObjCMethodDecl *MD = prevDecl->getGetterMethodDecl())
|
|
|
|
if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl)
|
|
|
|
if (Visit(MakeCXCursor(MD, TU, RegionOfInterest)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (ObjCMethodDecl *MD = prevDecl->getSetterMethodDecl())
|
|
|
|
if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl)
|
|
|
|
if (Visit(MakeCXCursor(MD, TU, RegionOfInterest)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:57:35 +08:00
|
|
|
bool CursorVisitor::VisitObjCTypeParamList(ObjCTypeParamList *typeParamList) {
|
|
|
|
if (!typeParamList)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (auto *typeParam : *typeParamList) {
|
|
|
|
// Visit the type parameter.
|
|
|
|
if (Visit(MakeCXCursor(typeParam, TU, RegionOfInterest)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
|
|
|
|
if (!D->isThisDeclarationADefinition()) {
|
|
|
|
// Forward declaration is treated like a reference.
|
|
|
|
return Visit(MakeCursorObjCClassRef(D, D->getLocation(), TU));
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:57:35 +08:00
|
|
|
// Objective-C type parameters.
|
|
|
|
if (VisitObjCTypeParamList(D->getTypeParamListAsWritten()))
|
|
|
|
return true;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Issue callbacks for super class.
|
|
|
|
if (D->getSuperClass() &&
|
|
|
|
Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(),
|
|
|
|
D->getSuperClassLoc(),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
|
2015-07-07 11:57:35 +08:00
|
|
|
if (TypeSourceInfo *SuperClassTInfo = D->getSuperClassTInfo())
|
|
|
|
if (Visit(SuperClassTInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin();
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
|
|
|
|
E = D->protocol_end(); I != E; ++I, ++PL)
|
|
|
|
if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitObjCContainerDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCImplDecl(ObjCImplDecl *D) {
|
|
|
|
return VisitObjCContainerDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
|
|
|
|
// 'ID' could be null when dealing with invalid code.
|
|
|
|
if (ObjCInterfaceDecl *ID = D->getClassInterface())
|
|
|
|
if (Visit(MakeCursorObjCClassRef(ID, D->getLocation(), TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitObjCImplDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
|
|
|
|
#if 0
|
|
|
|
// Issue callbacks for super class.
|
|
|
|
// FIXME: No source location information!
|
|
|
|
if (D->getSuperClass() &&
|
|
|
|
Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(),
|
|
|
|
D->getSuperClassLoc(),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return VisitObjCImplDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PD) {
|
|
|
|
if (ObjCIvarDecl *Ivar = PD->getPropertyIvarDecl())
|
|
|
|
if (PD->isIvarNameSpecified())
|
|
|
|
return Visit(MakeCursorMemberRef(Ivar, PD->getPropertyIvarDeclLoc(), TU));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitNamespaceDecl(NamespaceDecl *D) {
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
|
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Visit(MakeCursorNamespaceRef(D->getAliasedNamespace(),
|
|
|
|
D->getTargetNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitUsingDecl(UsingDecl *D) {
|
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) {
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Visit(MakeCursorOverloadedDeclRef(D, D->getLocation(), TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitDeclarationNameInfo(D->getNameInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
|
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Visit(MakeCursorNamespaceRef(D->getNominatedNamespaceAsWritten(),
|
|
|
|
D->getIdentLocation(), TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
|
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) {
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return VisitDeclarationNameInfo(D->getNameInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitUnresolvedUsingTypenameDecl(
|
|
|
|
UnresolvedUsingTypenameDecl *D) {
|
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-10 00:15:55 +08:00
|
|
|
bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
|
|
|
|
if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
|
|
|
|
return true;
|
2016-09-13 09:37:01 +08:00
|
|
|
if (StringLiteral *Message = D->getMessage())
|
|
|
|
if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
|
|
|
|
return true;
|
2016-06-10 00:15:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-04 14:29:27 +08:00
|
|
|
bool CursorVisitor::VisitFriendDecl(FriendDecl *D) {
|
|
|
|
if (NamedDecl *FriendD = D->getFriendDecl()) {
|
|
|
|
if (Visit(MakeCXCursor(FriendD, TU, RegionOfInterest)))
|
|
|
|
return true;
|
|
|
|
} else if (TypeSourceInfo *TI = D->getFriendType()) {
|
|
|
|
if (Visit(TI->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) {
|
|
|
|
switch (Name.getName().getNameKind()) {
|
|
|
|
case clang::DeclarationName::Identifier:
|
|
|
|
case clang::DeclarationName::CXXLiteralOperatorName:
|
2017-02-07 09:37:30 +08:00
|
|
|
case clang::DeclarationName::CXXDeductionGuideName:
|
2012-12-18 22:30:41 +08:00
|
|
|
case clang::DeclarationName::CXXOperatorName:
|
|
|
|
case clang::DeclarationName::CXXUsingDirective:
|
|
|
|
return false;
|
2017-02-07 09:37:30 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case clang::DeclarationName::CXXConstructorName:
|
|
|
|
case clang::DeclarationName::CXXDestructorName:
|
|
|
|
case clang::DeclarationName::CXXConversionFunctionName:
|
|
|
|
if (TypeSourceInfo *TSInfo = Name.getNamedTypeInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case clang::DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case clang::DeclarationName::ObjCOneArgSelector:
|
|
|
|
case clang::DeclarationName::ObjCMultiArgSelector:
|
|
|
|
// FIXME: Per-identifier location info?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid DeclarationName::Kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitNestedNameSpecifier(NestedNameSpecifier *NNS,
|
|
|
|
SourceRange Range) {
|
|
|
|
// FIXME: This whole routine is a hack to work around the lack of proper
|
|
|
|
// source information in nested-name-specifiers (PR5791). Since we do have
|
|
|
|
// a beginning source location, we can visit the first component of the
|
|
|
|
// nested-name-specifier, if it's a single-token component.
|
|
|
|
if (!NNS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get the first component in the nested-name-specifier.
|
|
|
|
while (NestedNameSpecifier *Prefix = NNS->getPrefix())
|
|
|
|
NNS = Prefix;
|
|
|
|
|
|
|
|
switch (NNS->getKind()) {
|
|
|
|
case NestedNameSpecifier::Namespace:
|
|
|
|
return Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(), Range.getBegin(),
|
|
|
|
TU));
|
|
|
|
|
|
|
|
case NestedNameSpecifier::NamespaceAlias:
|
|
|
|
return Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(),
|
|
|
|
Range.getBegin(), TU));
|
|
|
|
|
|
|
|
case NestedNameSpecifier::TypeSpec: {
|
|
|
|
// If the type has a form where we know that the beginning of the source
|
|
|
|
// range matches up with a reference cursor. Visit the appropriate reference
|
|
|
|
// cursor.
|
|
|
|
const Type *T = NNS->getAsType();
|
|
|
|
if (const TypedefType *Typedef = dyn_cast<TypedefType>(T))
|
|
|
|
return Visit(MakeCursorTypeRef(Typedef->getDecl(), Range.getBegin(), TU));
|
|
|
|
if (const TagType *Tag = dyn_cast<TagType>(T))
|
|
|
|
return Visit(MakeCursorTypeRef(Tag->getDecl(), Range.getBegin(), TU));
|
|
|
|
if (const TemplateSpecializationType *TST
|
|
|
|
= dyn_cast<TemplateSpecializationType>(T))
|
|
|
|
return VisitTemplateName(TST->getTemplateName(), Range.getBegin());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate:
|
|
|
|
case NestedNameSpecifier::Global:
|
|
|
|
case NestedNameSpecifier::Identifier:
|
2014-09-26 08:28:20 +08:00
|
|
|
case NestedNameSpecifier::Super:
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CursorVisitor::VisitNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier) {
|
|
|
|
SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
|
|
|
|
for (; Qualifier; Qualifier = Qualifier.getPrefix())
|
|
|
|
Qualifiers.push_back(Qualifier);
|
|
|
|
|
|
|
|
while (!Qualifiers.empty()) {
|
|
|
|
NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
|
|
|
|
NestedNameSpecifier *NNS = Q.getNestedNameSpecifier();
|
|
|
|
switch (NNS->getKind()) {
|
|
|
|
case NestedNameSpecifier::Namespace:
|
|
|
|
if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(),
|
|
|
|
Q.getLocalBeginLoc(),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::NamespaceAlias:
|
|
|
|
if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(),
|
|
|
|
Q.getLocalBeginLoc(),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::TypeSpec:
|
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate:
|
|
|
|
if (Visit(Q.getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::Global:
|
|
|
|
case NestedNameSpecifier::Identifier:
|
2014-09-26 08:28:20 +08:00
|
|
|
case NestedNameSpecifier::Super:
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTemplateParameters(
|
|
|
|
const TemplateParameterList *Params) {
|
|
|
|
if (!Params)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (TemplateParameterList::const_iterator P = Params->begin(),
|
|
|
|
PEnd = Params->end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if (Visit(MakeCXCursor(*P, TU, RegionOfInterest)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTemplateName(TemplateName Name, SourceLocation Loc) {
|
|
|
|
switch (Name.getKind()) {
|
|
|
|
case TemplateName::Template:
|
|
|
|
return Visit(MakeCursorTemplateRef(Name.getAsTemplateDecl(), Loc, TU));
|
|
|
|
|
|
|
|
case TemplateName::OverloadedTemplate:
|
|
|
|
// Visit the overloaded template set.
|
|
|
|
if (Visit(MakeCursorOverloadedDeclRef(Name, Loc, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
2019-05-09 11:31:27 +08:00
|
|
|
case TemplateName::AssumedTemplate:
|
|
|
|
// FIXME: Visit DeclarationName?
|
|
|
|
return false;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case TemplateName::DependentTemplate:
|
|
|
|
// FIXME: Visit nested-name-specifier.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateName::QualifiedTemplate:
|
|
|
|
// FIXME: Visit nested-name-specifier.
|
|
|
|
return Visit(MakeCursorTemplateRef(
|
|
|
|
Name.getAsQualifiedTemplateName()->getDecl(),
|
|
|
|
Loc, TU));
|
|
|
|
|
|
|
|
case TemplateName::SubstTemplateTemplateParm:
|
|
|
|
return Visit(MakeCursorTemplateRef(
|
|
|
|
Name.getAsSubstTemplateTemplateParm()->getParameter(),
|
|
|
|
Loc, TU));
|
|
|
|
|
|
|
|
case TemplateName::SubstTemplateTemplateParmPack:
|
|
|
|
return Visit(MakeCursorTemplateRef(
|
|
|
|
Name.getAsSubstTemplateTemplateParmPack()->getParameterPack(),
|
|
|
|
Loc, TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid TemplateName::Kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTemplateArgumentLoc(const TemplateArgumentLoc &TAL) {
|
|
|
|
switch (TAL.getArgument().getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
case TemplateArgument::Integral:
|
|
|
|
case TemplateArgument::Pack:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateArgument::Type:
|
|
|
|
if (TypeSourceInfo *TSInfo = TAL.getTypeSourceInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateArgument::Declaration:
|
|
|
|
if (Expr *E = TAL.getSourceDeclExpression())
|
|
|
|
return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateArgument::NullPtr:
|
|
|
|
if (Expr *E = TAL.getSourceNullPtrExpression())
|
|
|
|
return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateArgument::Expression:
|
|
|
|
if (Expr *E = TAL.getSourceExpression())
|
|
|
|
return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateArgument::Template:
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
if (VisitNestedNameSpecifierLoc(TAL.getTemplateQualifierLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitTemplateName(TAL.getArgument().getAsTemplateOrTemplatePattern(),
|
|
|
|
TAL.getTemplateNameLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid TemplateArgument::Kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
|
|
|
|
return Visit(TL.getUnqualifiedLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
|
|
|
|
ASTContext &Context = AU->getASTContext();
|
|
|
|
|
|
|
|
// Some builtin types (such as Objective-C's "id", "sel", and
|
|
|
|
// "Class") have associated declarations. Create cursors for those.
|
|
|
|
QualType VisitType;
|
|
|
|
switch (TL.getTypePtr()->getKind()) {
|
|
|
|
|
|
|
|
case BuiltinType::Void:
|
|
|
|
case BuiltinType::NullPtr:
|
|
|
|
case BuiltinType::Dependent:
|
2016-04-08 21:40:33 +08:00
|
|
|
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
|
|
|
|
case BuiltinType::Id:
|
2016-04-13 16:33:41 +08:00
|
|
|
#include "clang/Basic/OpenCLImageTypes.def"
|
2018-11-08 19:25:41 +08:00
|
|
|
#define EXT_OPAQUE_TYPE(ExtTYpe, Id, Ext) \
|
|
|
|
case BuiltinType::Id:
|
|
|
|
#include "clang/Basic/OpenCLExtensionTypes.def"
|
2013-02-07 20:47:42 +08:00
|
|
|
case BuiltinType::OCLSampler:
|
2013-01-20 20:31:11 +08:00
|
|
|
case BuiltinType::OCLEvent:
|
2015-09-15 19:18:52 +08:00
|
|
|
case BuiltinType::OCLClkEvent:
|
|
|
|
case BuiltinType::OCLQueue:
|
|
|
|
case BuiltinType::OCLReserveID:
|
2019-08-09 16:52:54 +08:00
|
|
|
#define SVE_TYPE(Name, Id, SingletonId) \
|
|
|
|
case BuiltinType::Id:
|
|
|
|
#include "clang/Basic/AArch64SVEACLETypes.def"
|
2012-12-18 22:30:41 +08:00
|
|
|
#define BUILTIN_TYPE(Id, SingletonId)
|
|
|
|
#define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
|
|
|
|
#define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
|
|
|
|
#define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
|
|
|
|
#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
|
|
|
|
#include "clang/AST/BuiltinTypes.def"
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BuiltinType::ObjCId:
|
|
|
|
VisitType = Context.getObjCIdType();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BuiltinType::ObjCClass:
|
|
|
|
VisitType = Context.getObjCClassType();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BuiltinType::ObjCSel:
|
|
|
|
VisitType = Context.getObjCSelType();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!VisitType.isNull()) {
|
|
|
|
if (const TypedefType *Typedef = VisitType->getAs<TypedefType>())
|
|
|
|
return Visit(MakeCursorTypeRef(Typedef->getDecl(), TL.getBuiltinLoc(),
|
|
|
|
TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
|
|
|
|
return Visit(MakeCursorTypeRef(TL.getTypedefNameDecl(), TL.getNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
|
|
|
|
return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTagTypeLoc(TagTypeLoc TL) {
|
|
|
|
if (TL.isDefinition())
|
|
|
|
return Visit(MakeCXCursor(TL.getDecl(), TU, RegionOfInterest));
|
|
|
|
|
|
|
|
return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
|
|
|
|
return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
|
2015-09-30 04:56:43 +08:00
|
|
|
return Visit(MakeCursorObjCClassRef(TL.getIFaceDecl(), TL.getNameLoc(), TU));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-09-14 01:25:08 +08:00
|
|
|
bool CursorVisitor::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) {
|
2018-08-10 05:08:08 +08:00
|
|
|
if (Visit(MakeCursorTypeRef(TL.getDecl(), TL.getBeginLoc(), TU)))
|
2016-09-14 01:25:08 +08:00
|
|
|
return true;
|
|
|
|
for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
|
|
|
|
if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool CursorVisitor::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
|
|
|
|
if (TL.hasBaseTypeAsWritten() && Visit(TL.getBaseLoc()))
|
|
|
|
return true;
|
|
|
|
|
2015-07-07 11:57:35 +08:00
|
|
|
for (unsigned I = 0, N = TL.getNumTypeArgs(); I != N; ++I) {
|
|
|
|
if (Visit(TL.getTypeArgTInfo(I)->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
|
|
|
|
if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
|
|
|
|
return Visit(TL.getPointeeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitParenTypeLoc(ParenTypeLoc TL) {
|
|
|
|
return Visit(TL.getInnerLoc());
|
|
|
|
}
|
|
|
|
|
2019-05-07 11:20:17 +08:00
|
|
|
bool CursorVisitor::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {
|
|
|
|
return Visit(TL.getInnerLoc());
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool CursorVisitor::VisitPointerTypeLoc(PointerTypeLoc TL) {
|
|
|
|
return Visit(TL.getPointeeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
|
|
|
|
return Visit(TL.getPointeeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
|
|
|
|
return Visit(TL.getPointeeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
|
|
|
|
return Visit(TL.getPointeeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
|
|
|
|
return Visit(TL.getPointeeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
|
|
|
|
return Visit(TL.getModifiedLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitFunctionTypeLoc(FunctionTypeLoc TL,
|
|
|
|
bool SkipResultType) {
|
2014-01-26 07:51:36 +08:00
|
|
|
if (!SkipResultType && Visit(TL.getReturnLoc()))
|
2012-12-18 22:30:41 +08:00
|
|
|
return true;
|
|
|
|
|
2014-01-21 08:32:38 +08:00
|
|
|
for (unsigned I = 0, N = TL.getNumParams(); I != N; ++I)
|
|
|
|
if (Decl *D = TL.getParam(I))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Visit(MakeCXCursor(D, TU, RegionOfInterest)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitArrayTypeLoc(ArrayTypeLoc TL) {
|
|
|
|
if (Visit(TL.getElementLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Expr *Size = TL.getSizeExpr())
|
|
|
|
return Visit(MakeCXCursor(Size, StmtParent, TU, RegionOfInterest));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-25 01:51:48 +08:00
|
|
|
bool CursorVisitor::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
|
|
|
|
return Visit(TL.getOriginalLoc());
|
|
|
|
}
|
|
|
|
|
2013-12-05 09:23:43 +08:00
|
|
|
bool CursorVisitor::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
|
|
|
|
return Visit(TL.getOriginalLoc());
|
|
|
|
}
|
|
|
|
|
2017-01-27 04:40:47 +08:00
|
|
|
bool CursorVisitor::VisitDeducedTemplateSpecializationTypeLoc(
|
|
|
|
DeducedTemplateSpecializationTypeLoc TL) {
|
|
|
|
if (VisitTemplateName(TL.getTypePtr()->getTemplateName(),
|
|
|
|
TL.getTemplateNameLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool CursorVisitor::VisitTemplateSpecializationTypeLoc(
|
|
|
|
TemplateSpecializationTypeLoc TL) {
|
|
|
|
// Visit the template name.
|
|
|
|
if (VisitTemplateName(TL.getTypePtr()->getTemplateName(),
|
|
|
|
TL.getTemplateNameLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the template arguments.
|
|
|
|
for (unsigned I = 0, N = TL.getNumArgs(); I != N; ++I)
|
|
|
|
if (VisitTemplateArgumentLoc(TL.getArgLoc(I)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
|
|
|
|
return Visit(MakeCXCursor(TL.getUnderlyingExpr(), StmtParent, TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
|
|
|
|
if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
|
|
|
|
if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
|
2015-09-30 04:56:43 +08:00
|
|
|
return VisitNestedNameSpecifierLoc(TL.getQualifierLoc());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitDependentTemplateSpecializationTypeLoc(
|
|
|
|
DependentTemplateSpecializationTypeLoc TL) {
|
|
|
|
// Visit the nested-name-specifier, if there is one.
|
|
|
|
if (TL.getQualifierLoc() &&
|
|
|
|
VisitNestedNameSpecifierLoc(TL.getQualifierLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the template arguments.
|
|
|
|
for (unsigned I = 0, N = TL.getNumArgs(); I != N; ++I)
|
|
|
|
if (VisitTemplateArgumentLoc(TL.getArgLoc(I)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
|
|
|
|
if (VisitNestedNameSpecifierLoc(TL.getQualifierLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Visit(TL.getNamedTypeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
|
|
|
|
return Visit(TL.getPatternLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
|
|
|
|
if (Expr *E = TL.getUnderlyingExpr())
|
|
|
|
return Visit(MakeCXCursor(E, StmtParent, TU));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
|
|
|
|
return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
|
|
|
|
return Visit(TL.getValueLoc());
|
|
|
|
}
|
|
|
|
|
2016-01-09 20:53:17 +08:00
|
|
|
bool CursorVisitor::VisitPipeTypeLoc(PipeTypeLoc TL) {
|
|
|
|
return Visit(TL.getValueLoc());
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
#define DEFAULT_TYPELOC_IMPL(CLASS, PARENT) \
|
|
|
|
bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
|
|
|
|
return Visit##PARENT##Loc(TL); \
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_TYPELOC_IMPL(Complex, Type)
|
|
|
|
DEFAULT_TYPELOC_IMPL(ConstantArray, ArrayType)
|
|
|
|
DEFAULT_TYPELOC_IMPL(IncompleteArray, ArrayType)
|
|
|
|
DEFAULT_TYPELOC_IMPL(VariableArray, ArrayType)
|
|
|
|
DEFAULT_TYPELOC_IMPL(DependentSizedArray, ArrayType)
|
2017-10-02 14:25:51 +08:00
|
|
|
DEFAULT_TYPELOC_IMPL(DependentAddressSpace, Type)
|
2018-07-14 03:46:04 +08:00
|
|
|
DEFAULT_TYPELOC_IMPL(DependentVector, Type)
|
2012-12-18 22:30:41 +08:00
|
|
|
DEFAULT_TYPELOC_IMPL(DependentSizedExtVector, Type)
|
|
|
|
DEFAULT_TYPELOC_IMPL(Vector, Type)
|
|
|
|
DEFAULT_TYPELOC_IMPL(ExtVector, VectorType)
|
|
|
|
DEFAULT_TYPELOC_IMPL(FunctionProto, FunctionType)
|
|
|
|
DEFAULT_TYPELOC_IMPL(FunctionNoProto, FunctionType)
|
|
|
|
DEFAULT_TYPELOC_IMPL(Record, TagType)
|
|
|
|
DEFAULT_TYPELOC_IMPL(Enum, TagType)
|
|
|
|
DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParm, Type)
|
|
|
|
DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParmPack, Type)
|
|
|
|
DEFAULT_TYPELOC_IMPL(Auto, Type)
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
|
|
|
// Visit the nested-name-specifier, if present.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (D->isCompleteDefinition()) {
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &I : D->bases()) {
|
|
|
|
if (Visit(cxcursor::MakeCursorCXXBaseSpecifier(&I, TU)))
|
2012-12-18 22:30:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VisitTagDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitAttributes(Decl *D) {
|
2014-03-09 06:19:01 +08:00
|
|
|
for (const auto *I : D->attrs())
|
2018-08-03 13:20:23 +08:00
|
|
|
if ((TU->ParsingOptions & CXTranslationUnit_VisitImplicitAttributes ||
|
|
|
|
!I->isImplicit()) &&
|
|
|
|
Visit(MakeCXCursor(I, D, TU)))
|
2012-12-18 22:30:41 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Data-recursive visitor methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
#define DEF_JOB(NAME, DATA, KIND)\
|
|
|
|
class NAME : public VisitorJob {\
|
|
|
|
public:\
|
2013-01-26 23:29:08 +08:00
|
|
|
NAME(const DATA *d, CXCursor parent) : \
|
|
|
|
VisitorJob(parent, VisitorJob::KIND, d) {} \
|
2012-12-18 22:30:41 +08:00
|
|
|
static bool classof(const VisitorJob *VJ) { return VJ->getKind() == KIND; }\
|
2013-01-26 23:29:08 +08:00
|
|
|
const DATA *get() const { return static_cast<const DATA*>(data[0]); }\
|
2012-12-18 22:30:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_JOB(StmtVisit, Stmt, StmtVisitKind)
|
|
|
|
DEF_JOB(MemberExprParts, MemberExpr, MemberExprPartsKind)
|
|
|
|
DEF_JOB(DeclRefExprParts, DeclRefExpr, DeclRefExprPartsKind)
|
|
|
|
DEF_JOB(OverloadExprParts, OverloadExpr, OverloadExprPartsKind)
|
|
|
|
DEF_JOB(SizeOfPackExprParts, SizeOfPackExpr, SizeOfPackExprPartsKind)
|
|
|
|
DEF_JOB(LambdaExprParts, LambdaExpr, LambdaExprPartsKind)
|
|
|
|
DEF_JOB(PostChildrenVisit, void, PostChildrenVisitKind)
|
|
|
|
#undef DEF_JOB
|
|
|
|
|
2015-12-24 10:59:37 +08:00
|
|
|
class ExplicitTemplateArgsVisit : public VisitorJob {
|
|
|
|
public:
|
|
|
|
ExplicitTemplateArgsVisit(const TemplateArgumentLoc *Begin,
|
|
|
|
const TemplateArgumentLoc *End, CXCursor parent)
|
|
|
|
: VisitorJob(parent, VisitorJob::ExplicitTemplateArgsVisitKind, Begin,
|
|
|
|
End) {}
|
|
|
|
static bool classof(const VisitorJob *VJ) {
|
|
|
|
return VJ->getKind() == ExplicitTemplateArgsVisitKind;
|
|
|
|
}
|
|
|
|
const TemplateArgumentLoc *begin() const {
|
|
|
|
return static_cast<const TemplateArgumentLoc *>(data[0]);
|
|
|
|
}
|
|
|
|
const TemplateArgumentLoc *end() {
|
|
|
|
return static_cast<const TemplateArgumentLoc *>(data[1]);
|
|
|
|
}
|
|
|
|
};
|
2012-12-18 22:30:41 +08:00
|
|
|
class DeclVisit : public VisitorJob {
|
|
|
|
public:
|
2013-01-26 23:29:08 +08:00
|
|
|
DeclVisit(const Decl *D, CXCursor parent, bool isFirst) :
|
2012-12-18 22:30:41 +08:00
|
|
|
VisitorJob(parent, VisitorJob::DeclVisitKind,
|
2014-06-08 16:38:04 +08:00
|
|
|
D, isFirst ? (void*) 1 : (void*) nullptr) {}
|
2012-12-18 22:30:41 +08:00
|
|
|
static bool classof(const VisitorJob *VJ) {
|
|
|
|
return VJ->getKind() == DeclVisitKind;
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
const Decl *get() const { return static_cast<const Decl *>(data[0]); }
|
2015-03-24 03:23:50 +08:00
|
|
|
bool isFirst() const { return data[1] != nullptr; }
|
2012-12-18 22:30:41 +08:00
|
|
|
};
|
|
|
|
class TypeLocVisit : public VisitorJob {
|
|
|
|
public:
|
|
|
|
TypeLocVisit(TypeLoc tl, CXCursor parent) :
|
|
|
|
VisitorJob(parent, VisitorJob::TypeLocVisitKind,
|
|
|
|
tl.getType().getAsOpaquePtr(), tl.getOpaqueData()) {}
|
|
|
|
|
|
|
|
static bool classof(const VisitorJob *VJ) {
|
|
|
|
return VJ->getKind() == TypeLocVisitKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeLoc get() const {
|
|
|
|
QualType T = QualType::getFromOpaquePtr(data[0]);
|
2013-01-26 23:29:08 +08:00
|
|
|
return TypeLoc(T, const_cast<void *>(data[1]));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class LabelRefVisit : public VisitorJob {
|
|
|
|
public:
|
|
|
|
LabelRefVisit(LabelDecl *LD, SourceLocation labelLoc, CXCursor parent)
|
|
|
|
: VisitorJob(parent, VisitorJob::LabelRefVisitKind, LD,
|
|
|
|
labelLoc.getPtrEncoding()) {}
|
|
|
|
|
|
|
|
static bool classof(const VisitorJob *VJ) {
|
|
|
|
return VJ->getKind() == VisitorJob::LabelRefVisitKind;
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
const LabelDecl *get() const {
|
|
|
|
return static_cast<const LabelDecl *>(data[0]);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceLocation getLoc() const {
|
|
|
|
return SourceLocation::getFromPtrEncoding(data[1]); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class NestedNameSpecifierLocVisit : public VisitorJob {
|
|
|
|
public:
|
|
|
|
NestedNameSpecifierLocVisit(NestedNameSpecifierLoc Qualifier, CXCursor parent)
|
|
|
|
: VisitorJob(parent, VisitorJob::NestedNameSpecifierLocVisitKind,
|
|
|
|
Qualifier.getNestedNameSpecifier(),
|
|
|
|
Qualifier.getOpaqueData()) { }
|
|
|
|
|
|
|
|
static bool classof(const VisitorJob *VJ) {
|
|
|
|
return VJ->getKind() == VisitorJob::NestedNameSpecifierLocVisitKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
NestedNameSpecifierLoc get() const {
|
2013-01-26 23:29:08 +08:00
|
|
|
return NestedNameSpecifierLoc(
|
|
|
|
const_cast<NestedNameSpecifier *>(
|
|
|
|
static_cast<const NestedNameSpecifier *>(data[0])),
|
|
|
|
const_cast<void *>(data[1]));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DeclarationNameInfoVisit : public VisitorJob {
|
|
|
|
public:
|
2013-01-26 23:29:08 +08:00
|
|
|
DeclarationNameInfoVisit(const Stmt *S, CXCursor parent)
|
2013-02-03 21:19:54 +08:00
|
|
|
: VisitorJob(parent, VisitorJob::DeclarationNameInfoVisitKind, S) {}
|
2012-12-18 22:30:41 +08:00
|
|
|
static bool classof(const VisitorJob *VJ) {
|
|
|
|
return VJ->getKind() == VisitorJob::DeclarationNameInfoVisitKind;
|
|
|
|
}
|
|
|
|
DeclarationNameInfo get() const {
|
2013-01-26 23:29:08 +08:00
|
|
|
const Stmt *S = static_cast<const Stmt *>(data[0]);
|
2012-12-18 22:30:41 +08:00
|
|
|
switch (S->getStmtClass()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled Stmt");
|
|
|
|
case clang::Stmt::MSDependentExistsStmtClass:
|
|
|
|
return cast<MSDependentExistsStmt>(S)->getNameInfo();
|
|
|
|
case Stmt::CXXDependentScopeMemberExprClass:
|
|
|
|
return cast<CXXDependentScopeMemberExpr>(S)->getMemberNameInfo();
|
|
|
|
case Stmt::DependentScopeDeclRefExprClass:
|
|
|
|
return cast<DependentScopeDeclRefExpr>(S)->getNameInfo();
|
2014-07-21 17:42:05 +08:00
|
|
|
case Stmt::OMPCriticalDirectiveClass:
|
|
|
|
return cast<OMPCriticalDirective>(S)->getDirectiveName();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
class MemberRefVisit : public VisitorJob {
|
|
|
|
public:
|
2013-01-26 23:29:08 +08:00
|
|
|
MemberRefVisit(const FieldDecl *D, SourceLocation L, CXCursor parent)
|
2012-12-18 22:30:41 +08:00
|
|
|
: VisitorJob(parent, VisitorJob::MemberRefVisitKind, D,
|
|
|
|
L.getPtrEncoding()) {}
|
|
|
|
static bool classof(const VisitorJob *VJ) {
|
|
|
|
return VJ->getKind() == VisitorJob::MemberRefVisitKind;
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
const FieldDecl *get() const {
|
|
|
|
return static_cast<const FieldDecl *>(data[0]);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
SourceLocation getLoc() const {
|
|
|
|
return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t) data[1]);
|
|
|
|
}
|
|
|
|
};
|
2013-01-26 23:29:08 +08:00
|
|
|
class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> {
|
2013-07-19 11:13:43 +08:00
|
|
|
friend class OMPClauseEnqueue;
|
2012-12-18 22:30:41 +08:00
|
|
|
VisitorWorkList &WL;
|
|
|
|
CXCursor Parent;
|
|
|
|
public:
|
|
|
|
EnqueueVisitor(VisitorWorkList &wl, CXCursor parent)
|
|
|
|
: WL(wl), Parent(parent) {}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void VisitAddrLabelExpr(const AddrLabelExpr *E);
|
|
|
|
void VisitBlockExpr(const BlockExpr *B);
|
|
|
|
void VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
|
|
|
|
void VisitCompoundStmt(const CompoundStmt *S);
|
|
|
|
void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { /* Do nothing. */ }
|
|
|
|
void VisitMSDependentExistsStmt(const MSDependentExistsStmt *S);
|
|
|
|
void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E);
|
|
|
|
void VisitCXXNewExpr(const CXXNewExpr *E);
|
|
|
|
void VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
|
|
|
|
void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *E);
|
|
|
|
void VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E);
|
|
|
|
void VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
|
|
|
|
void VisitCXXTypeidExpr(const CXXTypeidExpr *E);
|
|
|
|
void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *E);
|
|
|
|
void VisitCXXUuidofExpr(const CXXUuidofExpr *E);
|
|
|
|
void VisitCXXCatchStmt(const CXXCatchStmt *S);
|
2014-11-13 17:03:21 +08:00
|
|
|
void VisitCXXForRangeStmt(const CXXForRangeStmt *S);
|
2013-01-26 23:29:08 +08:00
|
|
|
void VisitDeclRefExpr(const DeclRefExpr *D);
|
|
|
|
void VisitDeclStmt(const DeclStmt *S);
|
|
|
|
void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E);
|
|
|
|
void VisitDesignatedInitExpr(const DesignatedInitExpr *E);
|
|
|
|
void VisitExplicitCastExpr(const ExplicitCastExpr *E);
|
|
|
|
void VisitForStmt(const ForStmt *FS);
|
|
|
|
void VisitGotoStmt(const GotoStmt *GS);
|
|
|
|
void VisitIfStmt(const IfStmt *If);
|
|
|
|
void VisitInitListExpr(const InitListExpr *IE);
|
|
|
|
void VisitMemberExpr(const MemberExpr *M);
|
|
|
|
void VisitOffsetOfExpr(const OffsetOfExpr *E);
|
|
|
|
void VisitObjCEncodeExpr(const ObjCEncodeExpr *E);
|
|
|
|
void VisitObjCMessageExpr(const ObjCMessageExpr *M);
|
|
|
|
void VisitOverloadExpr(const OverloadExpr *E);
|
|
|
|
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
|
|
|
|
void VisitStmt(const Stmt *S);
|
|
|
|
void VisitSwitchStmt(const SwitchStmt *S);
|
|
|
|
void VisitWhileStmt(const WhileStmt *W);
|
|
|
|
void VisitTypeTraitExpr(const TypeTraitExpr *E);
|
|
|
|
void VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E);
|
|
|
|
void VisitExpressionTraitExpr(const ExpressionTraitExpr *E);
|
|
|
|
void VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U);
|
|
|
|
void VisitVAArgExpr(const VAArgExpr *E);
|
|
|
|
void VisitSizeOfPackExpr(const SizeOfPackExpr *E);
|
|
|
|
void VisitPseudoObjectExpr(const PseudoObjectExpr *E);
|
|
|
|
void VisitOpaqueValueExpr(const OpaqueValueExpr *E);
|
|
|
|
void VisitLambdaExpr(const LambdaExpr *E);
|
2013-07-19 11:13:43 +08:00
|
|
|
void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
|
2014-08-19 19:27:13 +08:00
|
|
|
void VisitOMPLoopDirective(const OMPLoopDirective *D);
|
2013-07-19 11:13:43 +08:00
|
|
|
void VisitOMPParallelDirective(const OMPParallelDirective *D);
|
2014-02-27 16:29:12 +08:00
|
|
|
void VisitOMPSimdDirective(const OMPSimdDirective *D);
|
2014-06-18 12:14:57 +08:00
|
|
|
void VisitOMPForDirective(const OMPForDirective *D);
|
2014-09-18 13:12:34 +08:00
|
|
|
void VisitOMPForSimdDirective(const OMPForSimdDirective *D);
|
2014-06-25 19:44:49 +08:00
|
|
|
void VisitOMPSectionsDirective(const OMPSectionsDirective *D);
|
2014-06-26 16:21:58 +08:00
|
|
|
void VisitOMPSectionDirective(const OMPSectionDirective *D);
|
2014-06-26 20:05:45 +08:00
|
|
|
void VisitOMPSingleDirective(const OMPSingleDirective *D);
|
2014-07-17 16:54:58 +08:00
|
|
|
void VisitOMPMasterDirective(const OMPMasterDirective *D);
|
2014-07-21 17:42:05 +08:00
|
|
|
void VisitOMPCriticalDirective(const OMPCriticalDirective *D);
|
2014-07-07 21:01:15 +08:00
|
|
|
void VisitOMPParallelForDirective(const OMPParallelForDirective *D);
|
2014-09-23 17:33:00 +08:00
|
|
|
void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D);
|
2014-07-08 16:12:03 +08:00
|
|
|
void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D);
|
2014-07-11 19:25:16 +08:00
|
|
|
void VisitOMPTaskDirective(const OMPTaskDirective *D);
|
2014-07-18 15:47:19 +08:00
|
|
|
void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D);
|
2014-07-18 17:11:51 +08:00
|
|
|
void VisitOMPBarrierDirective(const OMPBarrierDirective *D);
|
2014-07-18 18:17:07 +08:00
|
|
|
void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D);
|
2015-06-18 20:14:09 +08:00
|
|
|
void VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *D);
|
2015-07-01 14:57:41 +08:00
|
|
|
void
|
|
|
|
VisitOMPCancellationPointDirective(const OMPCancellationPointDirective *D);
|
2015-07-02 19:25:17 +08:00
|
|
|
void VisitOMPCancelDirective(const OMPCancelDirective *D);
|
2014-07-21 19:26:11 +08:00
|
|
|
void VisitOMPFlushDirective(const OMPFlushDirective *D);
|
2014-07-22 14:45:04 +08:00
|
|
|
void VisitOMPOrderedDirective(const OMPOrderedDirective *D);
|
2014-07-22 18:10:35 +08:00
|
|
|
void VisitOMPAtomicDirective(const OMPAtomicDirective *D);
|
2014-09-19 16:19:49 +08:00
|
|
|
void VisitOMPTargetDirective(const OMPTargetDirective *D);
|
2015-07-21 21:44:28 +08:00
|
|
|
void VisitOMPTargetDataDirective(const OMPTargetDataDirective *D);
|
2016-01-20 03:15:56 +08:00
|
|
|
void VisitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective *D);
|
2016-01-20 04:04:50 +08:00
|
|
|
void VisitOMPTargetExitDataDirective(const OMPTargetExitDataDirective *D);
|
2016-01-27 02:48:41 +08:00
|
|
|
void VisitOMPTargetParallelDirective(const OMPTargetParallelDirective *D);
|
2016-02-03 23:46:42 +08:00
|
|
|
void
|
|
|
|
VisitOMPTargetParallelForDirective(const OMPTargetParallelForDirective *D);
|
2014-10-09 12:18:56 +08:00
|
|
|
void VisitOMPTeamsDirective(const OMPTeamsDirective *D);
|
2015-12-01 12:18:41 +08:00
|
|
|
void VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D);
|
2015-12-03 17:40:15 +08:00
|
|
|
void VisitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective *D);
|
2015-12-14 22:51:25 +08:00
|
|
|
void VisitOMPDistributeDirective(const OMPDistributeDirective *D);
|
2016-06-27 22:55:37 +08:00
|
|
|
void VisitOMPDistributeParallelForDirective(
|
|
|
|
const OMPDistributeParallelForDirective *D);
|
2016-07-05 13:00:15 +08:00
|
|
|
void VisitOMPDistributeParallelForSimdDirective(
|
|
|
|
const OMPDistributeParallelForSimdDirective *D);
|
2016-07-06 12:45:38 +08:00
|
|
|
void VisitOMPDistributeSimdDirective(const OMPDistributeSimdDirective *D);
|
2016-07-14 10:54:56 +08:00
|
|
|
void VisitOMPTargetParallelForSimdDirective(
|
|
|
|
const OMPTargetParallelForSimdDirective *D);
|
2016-07-21 06:57:10 +08:00
|
|
|
void VisitOMPTargetSimdDirective(const OMPTargetSimdDirective *D);
|
2016-08-05 22:37:37 +08:00
|
|
|
void VisitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective *D);
|
2016-10-25 20:50:55 +08:00
|
|
|
void VisitOMPTeamsDistributeSimdDirective(
|
|
|
|
const OMPTeamsDistributeSimdDirective *D);
|
2016-12-01 07:51:03 +08:00
|
|
|
void VisitOMPTeamsDistributeParallelForSimdDirective(
|
|
|
|
const OMPTeamsDistributeParallelForSimdDirective *D);
|
2016-12-09 11:24:30 +08:00
|
|
|
void VisitOMPTeamsDistributeParallelForDirective(
|
|
|
|
const OMPTeamsDistributeParallelForDirective *D);
|
2016-12-17 13:48:59 +08:00
|
|
|
void VisitOMPTargetTeamsDirective(const OMPTargetTeamsDirective *D);
|
2016-12-25 12:52:54 +08:00
|
|
|
void VisitOMPTargetTeamsDistributeDirective(
|
|
|
|
const OMPTargetTeamsDistributeDirective *D);
|
2016-12-30 06:16:30 +08:00
|
|
|
void VisitOMPTargetTeamsDistributeParallelForDirective(
|
|
|
|
const OMPTargetTeamsDistributeParallelForDirective *D);
|
2017-01-03 13:23:48 +08:00
|
|
|
void VisitOMPTargetTeamsDistributeParallelForSimdDirective(
|
|
|
|
const OMPTargetTeamsDistributeParallelForSimdDirective *D);
|
2017-01-11 02:08:18 +08:00
|
|
|
void VisitOMPTargetTeamsDistributeSimdDirective(
|
|
|
|
const OMPTargetTeamsDistributeSimdDirective *D);
|
2013-01-26 23:29:08 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
private:
|
2013-01-26 23:29:08 +08:00
|
|
|
void AddDeclarationNameInfo(const Stmt *S);
|
2012-12-18 22:30:41 +08:00
|
|
|
void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier);
|
2015-12-24 10:59:37 +08:00
|
|
|
void AddExplicitTemplateArgs(const TemplateArgumentLoc *A,
|
|
|
|
unsigned NumTemplateArgs);
|
2013-01-26 23:29:08 +08:00
|
|
|
void AddMemberRef(const FieldDecl *D, SourceLocation L);
|
|
|
|
void AddStmt(const Stmt *S);
|
|
|
|
void AddDecl(const Decl *D, bool isFirst = true);
|
2012-12-18 22:30:41 +08:00
|
|
|
void AddTypeLoc(TypeSourceInfo *TI);
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueChildren(const Stmt *S);
|
2013-07-19 11:13:43 +08:00
|
|
|
void EnqueueChildren(const OMPClause *S);
|
2012-12-18 22:30:41 +08:00
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
} // end anonyous namespace
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::AddDeclarationNameInfo(const Stmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// 'S' should always be non-null, since it comes from the
|
|
|
|
// statement we are visiting.
|
|
|
|
WL.push_back(DeclarationNameInfoVisit(S, Parent));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EnqueueVisitor::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier) {
|
|
|
|
if (Qualifier)
|
|
|
|
WL.push_back(NestedNameSpecifierLocVisit(Qualifier, Parent));
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::AddStmt(const Stmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (S)
|
|
|
|
WL.push_back(StmtVisit(S, Parent));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::AddDecl(const Decl *D, bool isFirst) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (D)
|
|
|
|
WL.push_back(DeclVisit(D, Parent, isFirst));
|
|
|
|
}
|
2015-12-24 10:59:37 +08:00
|
|
|
void EnqueueVisitor::AddExplicitTemplateArgs(const TemplateArgumentLoc *A,
|
|
|
|
unsigned NumTemplateArgs) {
|
|
|
|
WL.push_back(ExplicitTemplateArgsVisit(A, A + NumTemplateArgs, Parent));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::AddMemberRef(const FieldDecl *D, SourceLocation L) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (D)
|
|
|
|
WL.push_back(MemberRefVisit(D, L, Parent));
|
|
|
|
}
|
|
|
|
void EnqueueVisitor::AddTypeLoc(TypeSourceInfo *TI) {
|
|
|
|
if (TI)
|
|
|
|
WL.push_back(TypeLocVisit(TI->getTypeLoc(), Parent));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::EnqueueChildren(const Stmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned size = WL.size();
|
2015-07-03 05:03:14 +08:00
|
|
|
for (const Stmt *SubStmt : S->children()) {
|
|
|
|
AddStmt(SubStmt);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
if (size == WL.size())
|
|
|
|
return;
|
|
|
|
// Now reverse the entries we just added. This will match the DFS
|
|
|
|
// ordering performed by the worklist.
|
|
|
|
VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
|
|
|
|
std::reverse(I, E);
|
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
namespace {
|
|
|
|
class OMPClauseEnqueue : public ConstOMPClauseVisitor<OMPClauseEnqueue> {
|
|
|
|
EnqueueVisitor *Visitor;
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Process clauses with list of variables.
|
2013-09-24 11:17:45 +08:00
|
|
|
template <typename T>
|
|
|
|
void VisitOMPClauseList(T *Node);
|
2013-07-19 11:13:43 +08:00
|
|
|
public:
|
|
|
|
OMPClauseEnqueue(EnqueueVisitor *Visitor) : Visitor(Visitor) { }
|
|
|
|
#define OPENMP_CLAUSE(Name, Class) \
|
|
|
|
void Visit##Class(const Class *C);
|
|
|
|
#include "clang/Basic/OpenMPKinds.def"
|
2016-02-16 19:18:12 +08:00
|
|
|
void VisitOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
|
2016-02-25 13:25:57 +08:00
|
|
|
void VisitOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
|
2013-07-19 11:13:43 +08:00
|
|
|
};
|
|
|
|
|
2016-02-16 19:18:12 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPClauseWithPreInit(
|
|
|
|
const OMPClauseWithPreInit *C) {
|
|
|
|
Visitor->AddStmt(C->getPreInitStmt());
|
|
|
|
}
|
|
|
|
|
2016-02-25 13:25:57 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPClauseWithPostUpdate(
|
|
|
|
const OMPClauseWithPostUpdate *C) {
|
2016-03-04 15:21:16 +08:00
|
|
|
VisitOMPClauseWithPreInit(C);
|
2016-02-25 13:25:57 +08:00
|
|
|
Visitor->AddStmt(C->getPostUpdateExpr());
|
|
|
|
}
|
|
|
|
|
2014-02-13 13:29:23 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPIfClause(const OMPIfClause *C) {
|
2017-01-19 04:40:48 +08:00
|
|
|
VisitOMPClauseWithPreInit(C);
|
2014-02-13 13:29:23 +08:00
|
|
|
Visitor->AddStmt(C->getCondition());
|
|
|
|
}
|
|
|
|
|
2014-07-17 15:32:53 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPFinalClause(const OMPFinalClause *C) {
|
|
|
|
Visitor->AddStmt(C->getCondition());
|
|
|
|
}
|
|
|
|
|
2014-03-06 14:15:19 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
|
2017-01-25 08:57:16 +08:00
|
|
|
VisitOMPClauseWithPreInit(C);
|
2014-03-06 14:15:19 +08:00
|
|
|
Visitor->AddStmt(C->getNumThreads());
|
|
|
|
}
|
|
|
|
|
2014-03-21 12:51:18 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPSafelenClause(const OMPSafelenClause *C) {
|
|
|
|
Visitor->AddStmt(C->getSafelen());
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:14:16 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
|
|
|
|
Visitor->AddStmt(C->getSimdlen());
|
|
|
|
}
|
|
|
|
|
2019-03-13 02:52:33 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
|
|
|
|
Visitor->AddStmt(C->getAllocator());
|
|
|
|
}
|
|
|
|
|
2014-05-27 23:12:19 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPCollapseClause(const OMPCollapseClause *C) {
|
|
|
|
Visitor->AddStmt(C->getNumForLoops());
|
|
|
|
}
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
|
2013-09-24 11:17:45 +08:00
|
|
|
|
2014-05-06 14:04:14 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
|
|
|
|
|
2014-06-20 15:16:17 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPScheduleClause(const OMPScheduleClause *C) {
|
2016-02-16 19:18:12 +08:00
|
|
|
VisitOMPClauseWithPreInit(C);
|
2014-06-20 15:16:17 +08:00
|
|
|
Visitor->AddStmt(C->getChunkSize());
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:36:16 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *C) {
|
|
|
|
Visitor->AddStmt(C->getNumForLoops());
|
|
|
|
}
|
2014-06-20 17:44:06 +08:00
|
|
|
|
2014-06-20 19:19:47 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPNowaitClause(const OMPNowaitClause *) {}
|
|
|
|
|
2014-07-17 20:19:31 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPUntiedClause(const OMPUntiedClause *) {}
|
|
|
|
|
2014-07-17 20:47:03 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPMergeableClause(const OMPMergeableClause *) {}
|
|
|
|
|
2014-07-23 10:27:21 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPReadClause(const OMPReadClause *) {}
|
|
|
|
|
2014-07-23 15:46:59 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPWriteClause(const OMPWriteClause *) {}
|
|
|
|
|
2014-07-23 18:25:33 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPUpdateClause(const OMPUpdateClause *) {}
|
|
|
|
|
2014-07-24 14:46:57 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {}
|
|
|
|
|
2014-07-24 16:55:34 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
|
|
|
|
|
2015-09-25 18:37:12 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPThreadsClause(const OMPThreadsClause *) {}
|
|
|
|
|
2015-09-28 14:39:35 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPSIMDClause(const OMPSIMDClause *) {}
|
|
|
|
|
2015-12-07 18:51:44 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPNogroupClause(const OMPNogroupClause *) {}
|
|
|
|
|
2018-09-26 12:28:39 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPUnifiedAddressClause(
|
|
|
|
const OMPUnifiedAddressClause *) {}
|
|
|
|
|
2018-10-01 21:47:43 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPUnifiedSharedMemoryClause(
|
|
|
|
const OMPUnifiedSharedMemoryClause *) {}
|
|
|
|
|
2018-10-04 04:07:58 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPReverseOffloadClause(
|
|
|
|
const OMPReverseOffloadClause *) {}
|
|
|
|
|
2018-10-11 22:41:10 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPDynamicAllocatorsClause(
|
|
|
|
const OMPDynamicAllocatorsClause *) {}
|
|
|
|
|
2018-11-02 20:18:11 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPAtomicDefaultMemOrderClause(
|
|
|
|
const OMPAtomicDefaultMemOrderClause *) {}
|
|
|
|
|
2015-08-08 00:16:36 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) {
|
|
|
|
Visitor->AddStmt(C->getDevice());
|
|
|
|
}
|
|
|
|
|
2015-11-25 04:50:12 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
|
2017-01-25 19:28:18 +08:00
|
|
|
VisitOMPClauseWithPreInit(C);
|
2015-11-25 04:50:12 +08:00
|
|
|
Visitor->AddStmt(C->getNumTeams());
|
|
|
|
}
|
|
|
|
|
2015-11-28 02:47:36 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPThreadLimitClause(const OMPThreadLimitClause *C) {
|
2017-01-25 19:44:35 +08:00
|
|
|
VisitOMPClauseWithPreInit(C);
|
2015-11-28 02:47:36 +08:00
|
|
|
Visitor->AddStmt(C->getThreadLimit());
|
|
|
|
}
|
|
|
|
|
2015-12-01 18:17:31 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPPriorityClause(const OMPPriorityClause *C) {
|
|
|
|
Visitor->AddStmt(C->getPriority());
|
|
|
|
}
|
|
|
|
|
2015-12-07 20:52:51 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
|
|
|
|
Visitor->AddStmt(C->getGrainsize());
|
|
|
|
}
|
|
|
|
|
2015-12-08 20:06:20 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
|
|
|
|
Visitor->AddStmt(C->getNumTasks());
|
|
|
|
}
|
|
|
|
|
2015-12-15 16:19:24 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPHintClause(const OMPHintClause *C) {
|
|
|
|
Visitor->AddStmt(C->getHint());
|
|
|
|
}
|
|
|
|
|
2013-09-24 11:17:45 +08:00
|
|
|
template<typename T>
|
|
|
|
void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
|
2014-10-21 11:16:40 +08:00
|
|
|
for (const auto *I : Node->varlists()) {
|
2014-03-14 23:55:35 +08:00
|
|
|
Visitor->AddStmt(I);
|
2014-10-21 11:16:40 +08:00
|
|
|
}
|
2013-09-24 11:17:45 +08:00
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
|
2019-03-27 22:14:31 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPAllocateClause(const OMPAllocateClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
Visitor->AddStmt(C->getAllocator());
|
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) {
|
2013-09-24 11:17:45 +08:00
|
|
|
VisitOMPClauseList(C);
|
2014-10-21 11:16:40 +08:00
|
|
|
for (const auto *E : C->private_copies()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
2013-10-01 13:32:34 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPFirstprivateClause(
|
|
|
|
const OMPFirstprivateClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
2016-02-17 21:19:37 +08:00
|
|
|
VisitOMPClauseWithPreInit(C);
|
|
|
|
for (const auto *E : C->private_copies()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (const auto *E : C->inits()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2013-10-01 13:32:34 +08:00
|
|
|
}
|
2014-06-04 21:06:39 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPLastprivateClause(
|
|
|
|
const OMPLastprivateClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
2016-02-25 13:25:57 +08:00
|
|
|
VisitOMPClauseWithPostUpdate(C);
|
2015-04-16 12:54:05 +08:00
|
|
|
for (auto *E : C->private_copies()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->source_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->destination_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->assignment_ops()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2014-06-04 21:06:39 +08:00
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPSharedClause(const OMPSharedClause *C) {
|
2013-09-24 11:17:45 +08:00
|
|
|
VisitOMPClauseList(C);
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
2014-06-16 15:08:35 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPReductionClause(const OMPReductionClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
2016-03-02 12:57:40 +08:00
|
|
|
VisitOMPClauseWithPostUpdate(C);
|
2015-10-08 17:10:53 +08:00
|
|
|
for (auto *E : C->privates()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
for (auto *E : C->lhs_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->rhs_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->reduction_ops()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
2017-07-19 04:17:46 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPTaskReductionClause(
|
|
|
|
const OMPTaskReductionClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
VisitOMPClauseWithPostUpdate(C);
|
|
|
|
for (auto *E : C->privates()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->lhs_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->rhs_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->reduction_ops()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
}
|
2017-07-22 02:48:21 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPInReductionClause(
|
|
|
|
const OMPInReductionClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
VisitOMPClauseWithPostUpdate(C);
|
|
|
|
for (auto *E : C->privates()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->lhs_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->rhs_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->reduction_ops()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2017-07-27 21:20:36 +08:00
|
|
|
for (auto *E : C->taskgroup_descriptors())
|
|
|
|
Visitor->AddStmt(E);
|
2017-07-22 02:48:21 +08:00
|
|
|
}
|
2014-04-22 21:09:42 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPLinearClause(const OMPLinearClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
2016-03-09 17:49:00 +08:00
|
|
|
VisitOMPClauseWithPostUpdate(C);
|
2015-08-18 14:47:21 +08:00
|
|
|
for (const auto *E : C->privates()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2015-03-21 18:12:56 +08:00
|
|
|
for (const auto *E : C->inits()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (const auto *E : C->updates()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (const auto *E : C->finals()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2014-04-22 21:09:42 +08:00
|
|
|
Visitor->AddStmt(C->getStep());
|
2015-03-21 18:12:56 +08:00
|
|
|
Visitor->AddStmt(C->getCalcStep());
|
2014-04-22 21:09:42 +08:00
|
|
|
}
|
2014-05-29 22:36:25 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPAlignedClause(const OMPAlignedClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
Visitor->AddStmt(C->getAlignment());
|
|
|
|
}
|
2014-03-31 11:36:38 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPCopyinClause(const OMPCopyinClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
2015-04-16 13:39:01 +08:00
|
|
|
for (auto *E : C->source_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->destination_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->assignment_ops()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2014-03-31 11:36:38 +08:00
|
|
|
}
|
2014-06-27 18:37:06 +08:00
|
|
|
void
|
|
|
|
OMPClauseEnqueue::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
2015-03-23 14:18:07 +08:00
|
|
|
for (auto *E : C->source_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->destination_exprs()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
|
|
|
for (auto *E : C->assignment_ops()) {
|
|
|
|
Visitor->AddStmt(E);
|
|
|
|
}
|
2014-06-27 18:37:06 +08:00
|
|
|
}
|
2014-07-21 19:26:11 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPFlushClause(const OMPFlushClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
}
|
2015-06-23 22:25:19 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPDependClause(const OMPDependClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
}
|
2015-11-23 13:32:03 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPMapClause(const OMPMapClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
}
|
2016-01-16 02:50:31 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPDistScheduleClause(
|
|
|
|
const OMPDistScheduleClause *C) {
|
2016-02-16 19:18:12 +08:00
|
|
|
VisitOMPClauseWithPreInit(C);
|
2016-01-16 02:50:31 +08:00
|
|
|
Visitor->AddStmt(C->getChunkSize());
|
2016-01-27 00:37:23 +08:00
|
|
|
}
|
2016-02-16 19:18:12 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPDefaultmapClause(
|
|
|
|
const OMPDefaultmapClause * /*C*/) {}
|
2016-05-27 01:39:58 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPToClause(const OMPToClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
}
|
2016-05-27 01:49:04 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPFromClause(const OMPFromClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
}
|
2016-07-13 23:37:16 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPUseDevicePtrClause(const OMPUseDevicePtrClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
}
|
2016-07-14 01:16:49 +08:00
|
|
|
void OMPClauseEnqueue::VisitOMPIsDevicePtrClause(const OMPIsDevicePtrClause *C) {
|
|
|
|
VisitOMPClauseList(C);
|
|
|
|
}
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2013-09-24 11:17:45 +08:00
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
void EnqueueVisitor::EnqueueChildren(const OMPClause *S) {
|
|
|
|
unsigned size = WL.size();
|
|
|
|
OMPClauseEnqueue Visitor(this);
|
|
|
|
Visitor.Visit(S);
|
|
|
|
if (size == WL.size())
|
|
|
|
return;
|
|
|
|
// Now reverse the entries we just added. This will match the DFS
|
|
|
|
// ordering performed by the worklist.
|
|
|
|
VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
|
|
|
|
std::reverse(I, E);
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitAddrLabelExpr(const AddrLabelExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
WL.push_back(LabelRefVisit(E->getLabel(), E->getLabelLoc(), Parent));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitBlockExpr(const BlockExpr *B) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddDecl(B->getBlockDecl());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(E);
|
|
|
|
AddTypeLoc(E->getTypeSourceInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCompoundStmt(const CompoundStmt *S) {
|
2015-07-31 01:22:52 +08:00
|
|
|
for (auto &I : llvm::reverse(S->body()))
|
|
|
|
AddStmt(I);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
void EnqueueVisitor::
|
2013-01-26 23:29:08 +08:00
|
|
|
VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddStmt(S->getSubStmt());
|
|
|
|
AddDeclarationNameInfo(S);
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = S->getQualifierLoc())
|
|
|
|
AddNestedNameSpecifierLoc(QualifierLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnqueueVisitor::
|
2013-01-26 23:29:08 +08:00
|
|
|
VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
|
2015-12-24 10:59:37 +08:00
|
|
|
if (E->hasExplicitTemplateArgs())
|
|
|
|
AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
|
2012-12-18 22:30:41 +08:00
|
|
|
AddDeclarationNameInfo(E);
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc())
|
|
|
|
AddNestedNameSpecifierLoc(QualifierLoc);
|
|
|
|
if (!E->isImplicitAccess())
|
|
|
|
AddStmt(E->getBase());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXNewExpr(const CXXNewExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Enqueue the initializer , if any.
|
|
|
|
AddStmt(E->getInitializer());
|
|
|
|
// Enqueue the array size, if any.
|
2019-05-06 11:47:15 +08:00
|
|
|
AddStmt(E->getArraySize().getValueOr(nullptr));
|
2012-12-18 22:30:41 +08:00
|
|
|
// Enqueue the allocated type.
|
|
|
|
AddTypeLoc(E->getAllocatedTypeSourceInfo());
|
|
|
|
// Enqueue the placement arguments.
|
|
|
|
for (unsigned I = E->getNumPlacementArgs(); I > 0; --I)
|
|
|
|
AddStmt(E->getPlacementArg(I-1));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *CE) {
|
2012-12-18 22:30:41 +08:00
|
|
|
for (unsigned I = CE->getNumArgs(); I > 1 /* Yes, this is 1 */; --I)
|
|
|
|
AddStmt(CE->getArg(I-1));
|
|
|
|
AddStmt(CE->getCallee());
|
|
|
|
AddStmt(CE->getArg(0));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXPseudoDestructorExpr(
|
|
|
|
const CXXPseudoDestructorExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Visit the name of the type being destroyed.
|
|
|
|
AddTypeLoc(E->getDestroyedTypeInfo());
|
|
|
|
// Visit the scope type that looks disturbingly like the nested-name-specifier
|
|
|
|
// but isn't.
|
|
|
|
AddTypeLoc(E->getScopeTypeInfo());
|
|
|
|
// Visit the nested-name-specifier.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc())
|
|
|
|
AddNestedNameSpecifierLoc(QualifierLoc);
|
|
|
|
// Visit base expression.
|
|
|
|
AddStmt(E->getBase());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXScalarValueInitExpr(
|
|
|
|
const CXXScalarValueInitExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddTypeLoc(E->getTypeSourceInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXTemporaryObjectExpr(
|
|
|
|
const CXXTemporaryObjectExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(E);
|
|
|
|
AddTypeLoc(E->getTypeSourceInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXTypeidExpr(const CXXTypeidExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(E);
|
|
|
|
if (E->isTypeOperand())
|
|
|
|
AddTypeLoc(E->getTypeOperandSourceInfo());
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXUnresolvedConstructExpr(
|
|
|
|
const CXXUnresolvedConstructExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(E);
|
|
|
|
AddTypeLoc(E->getTypeSourceInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(E);
|
|
|
|
if (E->isTypeOperand())
|
|
|
|
AddTypeLoc(E->getTypeOperandSourceInfo());
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitCXXCatchStmt(const CXXCatchStmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(S);
|
|
|
|
AddDecl(S->getExceptionDecl());
|
|
|
|
}
|
|
|
|
|
2014-11-13 17:03:21 +08:00
|
|
|
void EnqueueVisitor::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
|
2014-11-13 17:50:19 +08:00
|
|
|
AddStmt(S->getBody());
|
2014-11-13 17:03:21 +08:00
|
|
|
AddStmt(S->getRangeInit());
|
2014-11-13 17:50:19 +08:00
|
|
|
AddDecl(S->getLoopVariable());
|
2014-11-13 17:03:21 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) {
|
2015-12-24 10:59:37 +08:00
|
|
|
if (DR->hasExplicitTemplateArgs())
|
|
|
|
AddExplicitTemplateArgs(DR->getTemplateArgs(), DR->getNumTemplateArgs());
|
2012-12-18 22:30:41 +08:00
|
|
|
WL.push_back(DeclRefExprParts(DR, Parent));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitDependentScopeDeclRefExpr(
|
|
|
|
const DependentScopeDeclRefExpr *E) {
|
2015-12-24 10:59:37 +08:00
|
|
|
if (E->hasExplicitTemplateArgs())
|
|
|
|
AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
|
2012-12-18 22:30:41 +08:00
|
|
|
AddDeclarationNameInfo(E);
|
|
|
|
AddNestedNameSpecifierLoc(E->getQualifierLoc());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitDeclStmt(const DeclStmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned size = WL.size();
|
|
|
|
bool isFirst = true;
|
2014-03-15 01:01:24 +08:00
|
|
|
for (const auto *D : S->decls()) {
|
|
|
|
AddDecl(D, isFirst);
|
2012-12-18 22:30:41 +08:00
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
if (size == WL.size())
|
|
|
|
return;
|
|
|
|
// Now reverse the entries we just added. This will match the DFS
|
|
|
|
// ordering performed by the worklist.
|
|
|
|
VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
|
|
|
|
std::reverse(I, E);
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddStmt(E->getInit());
|
2016-06-23 08:15:04 +08:00
|
|
|
for (const DesignatedInitExpr::Designator &D :
|
|
|
|
llvm::reverse(E->designators())) {
|
|
|
|
if (D.isFieldDesignator()) {
|
|
|
|
if (FieldDecl *Field = D.getField())
|
|
|
|
AddMemberRef(Field, D.getFieldLoc());
|
2012-12-18 22:30:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-23 08:15:04 +08:00
|
|
|
if (D.isArrayDesignator()) {
|
|
|
|
AddStmt(E->getArrayIndex(D));
|
2012-12-18 22:30:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-23 08:15:04 +08:00
|
|
|
assert(D.isArrayRangeDesignator() && "Unknown designator kind");
|
|
|
|
AddStmt(E->getArrayRangeEnd(D));
|
|
|
|
AddStmt(E->getArrayRangeStart(D));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitExplicitCastExpr(const ExplicitCastExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(E);
|
|
|
|
AddTypeLoc(E->getTypeInfoAsWritten());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitForStmt(const ForStmt *FS) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddStmt(FS->getBody());
|
|
|
|
AddStmt(FS->getInc());
|
|
|
|
AddStmt(FS->getCond());
|
|
|
|
AddDecl(FS->getConditionVariable());
|
|
|
|
AddStmt(FS->getInit());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitGotoStmt(const GotoStmt *GS) {
|
2012-12-18 22:30:41 +08:00
|
|
|
WL.push_back(LabelRefVisit(GS->getLabel(), GS->getLabelLoc(), Parent));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitIfStmt(const IfStmt *If) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddStmt(If->getElse());
|
|
|
|
AddStmt(If->getThen());
|
|
|
|
AddStmt(If->getCond());
|
|
|
|
AddDecl(If->getConditionVariable());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitInitListExpr(const InitListExpr *IE) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// We care about the syntactic form of the initializer list, only.
|
|
|
|
if (InitListExpr *Syntactic = IE->getSyntacticForm())
|
|
|
|
IE = Syntactic;
|
|
|
|
EnqueueChildren(IE);
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitMemberExpr(const MemberExpr *M) {
|
2012-12-18 22:30:41 +08:00
|
|
|
WL.push_back(MemberExprParts(M, Parent));
|
|
|
|
|
|
|
|
// If the base of the member access expression is an implicit 'this', don't
|
|
|
|
// visit it.
|
|
|
|
// FIXME: If we ever want to show these implicit accesses, this will be
|
|
|
|
// unfortunate. However, clang_getCursor() relies on this behavior.
|
2015-03-13 12:40:07 +08:00
|
|
|
if (M->isImplicitAccess())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ignore base anonymous struct/union fields, otherwise they will shadow the
|
2018-04-06 23:14:32 +08:00
|
|
|
// real field that we are interested in.
|
2015-03-13 12:40:07 +08:00
|
|
|
if (auto *SubME = dyn_cast<MemberExpr>(M->getBase())) {
|
|
|
|
if (auto *FD = dyn_cast_or_null<FieldDecl>(SubME->getMemberDecl())) {
|
|
|
|
if (FD->isAnonymousStructOrUnion()) {
|
|
|
|
AddStmt(SubME->getBase());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddStmt(M->getBase());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddTypeLoc(E->getEncodedTypeSourceInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitObjCMessageExpr(const ObjCMessageExpr *M) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(M);
|
|
|
|
AddTypeLoc(M->getClassReceiverTypeInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitOffsetOfExpr(const OffsetOfExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Visit the components of the offsetof expression.
|
|
|
|
for (unsigned N = E->getNumComponents(), I = N; I > 0; --I) {
|
|
|
|
const OffsetOfNode &Node = E->getComponent(I-1);
|
|
|
|
switch (Node.getKind()) {
|
|
|
|
case OffsetOfNode::Array:
|
|
|
|
AddStmt(E->getIndexExpr(Node.getArrayExprIndex()));
|
|
|
|
break;
|
|
|
|
case OffsetOfNode::Field:
|
|
|
|
AddMemberRef(Node.getField(), Node.getSourceRange().getEnd());
|
|
|
|
break;
|
|
|
|
case OffsetOfNode::Identifier:
|
|
|
|
case OffsetOfNode::Base:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Visit the type into which we're computing the offset.
|
|
|
|
AddTypeLoc(E->getTypeSourceInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitOverloadExpr(const OverloadExpr *E) {
|
2015-12-24 10:59:37 +08:00
|
|
|
if (E->hasExplicitTemplateArgs())
|
|
|
|
AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
|
2012-12-18 22:30:41 +08:00
|
|
|
WL.push_back(OverloadExprParts(E, Parent));
|
|
|
|
}
|
|
|
|
void EnqueueVisitor::VisitUnaryExprOrTypeTraitExpr(
|
2013-01-26 23:29:08 +08:00
|
|
|
const UnaryExprOrTypeTraitExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(E);
|
|
|
|
if (E->isArgumentType())
|
|
|
|
AddTypeLoc(E->getArgumentTypeInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitStmt(const Stmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(S);
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitSwitchStmt(const SwitchStmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddStmt(S->getBody());
|
|
|
|
AddStmt(S->getCond());
|
|
|
|
AddDecl(S->getConditionVariable());
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitWhileStmt(const WhileStmt *W) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddStmt(W->getBody());
|
|
|
|
AddStmt(W->getCond());
|
|
|
|
AddDecl(W->getConditionVariable());
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitTypeTraitExpr(const TypeTraitExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
for (unsigned I = E->getNumArgs(); I > 0; --I)
|
|
|
|
AddTypeLoc(E->getArg(I-1));
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddTypeLoc(E->getQueriedTypeSourceInfo());
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueChildren(E);
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U) {
|
2012-12-18 22:30:41 +08:00
|
|
|
VisitOverloadExpr(U);
|
|
|
|
if (!U->isImplicitAccess())
|
|
|
|
AddStmt(U->getBase());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitVAArgExpr(const VAArgExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddStmt(E->getSubExpr());
|
|
|
|
AddTypeLoc(E->getWrittenTypeInfo());
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitSizeOfPackExpr(const SizeOfPackExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
WL.push_back(SizeOfPackExprParts(E, Parent));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// If the opaque value has a source expression, just transparently
|
|
|
|
// visit that. This is useful for (e.g.) pseudo-object expressions.
|
|
|
|
if (Expr *SourceExpr = E->getSourceExpr())
|
|
|
|
return Visit(SourceExpr);
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitLambdaExpr(const LambdaExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
AddStmt(E->getBody());
|
|
|
|
WL.push_back(LambdaExprParts(E, Parent));
|
|
|
|
}
|
2013-01-26 23:29:08 +08:00
|
|
|
void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Treat the expression like its syntactic form.
|
|
|
|
Visit(E->getSyntacticForm());
|
|
|
|
}
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
void EnqueueVisitor::VisitOMPExecutableDirective(
|
|
|
|
const OMPExecutableDirective *D) {
|
|
|
|
EnqueueChildren(D);
|
|
|
|
for (ArrayRef<OMPClause *>::iterator I = D->clauses().begin(),
|
|
|
|
E = D->clauses().end();
|
|
|
|
I != E; ++I)
|
|
|
|
EnqueueChildren(*I);
|
|
|
|
}
|
|
|
|
|
2014-08-19 19:27:13 +08:00
|
|
|
void EnqueueVisitor::VisitOMPLoopDirective(const OMPLoopDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
void EnqueueVisitor::VisitOMPParallelDirective(const OMPParallelDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:29:12 +08:00
|
|
|
void EnqueueVisitor::VisitOMPSimdDirective(const OMPSimdDirective *D) {
|
2014-08-19 19:27:13 +08:00
|
|
|
VisitOMPLoopDirective(D);
|
2014-02-27 16:29:12 +08:00
|
|
|
}
|
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) {
|
2014-08-19 19:27:13 +08:00
|
|
|
VisitOMPLoopDirective(D);
|
2014-06-18 12:14:57 +08:00
|
|
|
}
|
|
|
|
|
2014-09-18 13:12:34 +08:00
|
|
|
void EnqueueVisitor::VisitOMPForSimdDirective(const OMPForSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-06-25 19:44:49 +08:00
|
|
|
void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-06-26 16:21:58 +08:00
|
|
|
void EnqueueVisitor::VisitOMPSectionDirective(const OMPSectionDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-06-26 20:05:45 +08:00
|
|
|
void EnqueueVisitor::VisitOMPSingleDirective(const OMPSingleDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-17 16:54:58 +08:00
|
|
|
void EnqueueVisitor::VisitOMPMasterDirective(const OMPMasterDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-21 17:42:05 +08:00
|
|
|
void EnqueueVisitor::VisitOMPCriticalDirective(const OMPCriticalDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
AddDeclarationNameInfo(D);
|
|
|
|
}
|
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
void
|
|
|
|
EnqueueVisitor::VisitOMPParallelForDirective(const OMPParallelForDirective *D) {
|
2014-08-19 19:27:13 +08:00
|
|
|
VisitOMPLoopDirective(D);
|
2014-07-07 21:01:15 +08:00
|
|
|
}
|
|
|
|
|
2014-09-23 17:33:00 +08:00
|
|
|
void EnqueueVisitor::VisitOMPParallelForSimdDirective(
|
|
|
|
const OMPParallelForSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-08 16:12:03 +08:00
|
|
|
void EnqueueVisitor::VisitOMPParallelSectionsDirective(
|
|
|
|
const OMPParallelSectionsDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-11 19:25:16 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTaskDirective(const OMPTaskDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-18 15:47:19 +08:00
|
|
|
void
|
|
|
|
EnqueueVisitor::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-18 17:11:51 +08:00
|
|
|
void EnqueueVisitor::VisitOMPBarrierDirective(const OMPBarrierDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-18 18:17:07 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2015-06-18 20:14:09 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTaskgroupDirective(
|
|
|
|
const OMPTaskgroupDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
2017-07-25 23:53:26 +08:00
|
|
|
if (const Expr *E = D->getReductionRef())
|
|
|
|
VisitStmt(E);
|
2015-06-18 20:14:09 +08:00
|
|
|
}
|
|
|
|
|
2014-07-21 19:26:11 +08:00
|
|
|
void EnqueueVisitor::VisitOMPFlushDirective(const OMPFlushDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-22 14:45:04 +08:00
|
|
|
void EnqueueVisitor::VisitOMPOrderedDirective(const OMPOrderedDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-07-22 18:10:35 +08:00
|
|
|
void EnqueueVisitor::VisitOMPAtomicDirective(const OMPAtomicDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-09-19 16:19:49 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetDirective(const OMPTargetDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2015-07-21 21:44:28 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetDataDirective(const
|
|
|
|
OMPTargetDataDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-01-20 03:15:56 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetEnterDataDirective(
|
|
|
|
const OMPTargetEnterDataDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-01-20 04:04:50 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetExitDataDirective(
|
|
|
|
const OMPTargetExitDataDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-01-27 02:48:41 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetParallelDirective(
|
|
|
|
const OMPTargetParallelDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-02-03 23:46:42 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetParallelForDirective(
|
|
|
|
const OMPTargetParallelForDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2014-10-09 12:18:56 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTeamsDirective(const OMPTeamsDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2015-07-01 14:57:41 +08:00
|
|
|
void EnqueueVisitor::VisitOMPCancellationPointDirective(
|
|
|
|
const OMPCancellationPointDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2015-07-02 19:25:17 +08:00
|
|
|
void EnqueueVisitor::VisitOMPCancelDirective(const OMPCancelDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2015-12-01 12:18:41 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2015-12-03 17:40:15 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTaskLoopSimdDirective(
|
|
|
|
const OMPTaskLoopSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2015-12-14 22:51:25 +08:00
|
|
|
void EnqueueVisitor::VisitOMPDistributeDirective(
|
|
|
|
const OMPDistributeDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-06-27 22:55:37 +08:00
|
|
|
void EnqueueVisitor::VisitOMPDistributeParallelForDirective(
|
|
|
|
const OMPDistributeParallelForDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-07-05 13:00:15 +08:00
|
|
|
void EnqueueVisitor::VisitOMPDistributeParallelForSimdDirective(
|
|
|
|
const OMPDistributeParallelForSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-07-06 12:45:38 +08:00
|
|
|
void EnqueueVisitor::VisitOMPDistributeSimdDirective(
|
|
|
|
const OMPDistributeSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-07-14 10:54:56 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetParallelForSimdDirective(
|
|
|
|
const OMPTargetParallelForSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-07-21 06:57:10 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetSimdDirective(
|
|
|
|
const OMPTargetSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-08-05 22:37:37 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTeamsDistributeDirective(
|
|
|
|
const OMPTeamsDistributeDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-10-25 20:50:55 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTeamsDistributeSimdDirective(
|
|
|
|
const OMPTeamsDistributeSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-12-01 07:51:03 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTeamsDistributeParallelForSimdDirective(
|
|
|
|
const OMPTeamsDistributeParallelForSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:24:30 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTeamsDistributeParallelForDirective(
|
|
|
|
const OMPTeamsDistributeParallelForDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-12-17 13:48:59 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetTeamsDirective(
|
|
|
|
const OMPTargetTeamsDirective *D) {
|
|
|
|
VisitOMPExecutableDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-12-25 12:52:54 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetTeamsDistributeDirective(
|
|
|
|
const OMPTargetTeamsDistributeDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:16:30 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForDirective(
|
|
|
|
const OMPTargetTeamsDistributeParallelForDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2017-01-03 13:23:48 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
|
|
|
|
const OMPTargetTeamsDistributeParallelForSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2017-01-11 02:08:18 +08:00
|
|
|
void EnqueueVisitor::VisitOMPTargetTeamsDistributeSimdDirective(
|
|
|
|
const OMPTargetTeamsDistributeSimdDirective *D) {
|
|
|
|
VisitOMPLoopDirective(D);
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) {
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::IsInRegionOfInterest(CXCursor C) {
|
|
|
|
if (RegionOfInterest.isValid()) {
|
|
|
|
SourceRange Range = getRawCursorExtent(C);
|
|
|
|
if (Range.isInvalid() || CompareRegionOfInterest(Range))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
|
|
|
|
while (!WL.empty()) {
|
|
|
|
// Dequeue the worklist item.
|
2013-08-24 00:11:15 +08:00
|
|
|
VisitorJob LI = WL.pop_back_val();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Set the Parent field, then back to its old value once we're done.
|
|
|
|
SetParentRAII SetParent(Parent, StmtParent, LI.getParent());
|
|
|
|
|
|
|
|
switch (LI.getKind()) {
|
|
|
|
case VisitorJob::DeclVisitKind: {
|
2013-01-26 23:29:08 +08:00
|
|
|
const Decl *D = cast<DeclVisit>(&LI)->get();
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// For now, perform default visitation for Decls.
|
|
|
|
if (Visit(MakeCXCursor(D, TU, RegionOfInterest,
|
|
|
|
cast<DeclVisit>(&LI)->isFirst())))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::ExplicitTemplateArgsVisitKind: {
|
2015-12-24 10:59:37 +08:00
|
|
|
for (const TemplateArgumentLoc &Arg :
|
|
|
|
*cast<ExplicitTemplateArgsVisit>(&LI)) {
|
|
|
|
if (VisitTemplateArgumentLoc(Arg))
|
2012-12-18 22:30:41 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::TypeLocVisitKind: {
|
|
|
|
// Perform default visitation for TypeLocs.
|
|
|
|
if (Visit(cast<TypeLocVisit>(&LI)->get()))
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::LabelRefVisitKind: {
|
2013-01-26 23:29:08 +08:00
|
|
|
const LabelDecl *LS = cast<LabelRefVisit>(&LI)->get();
|
2012-12-18 22:30:41 +08:00
|
|
|
if (LabelStmt *stmt = LS->getStmt()) {
|
|
|
|
if (Visit(MakeCursorLabelRef(stmt, cast<LabelRefVisit>(&LI)->getLoc(),
|
|
|
|
TU))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VisitorJob::NestedNameSpecifierLocVisitKind: {
|
|
|
|
NestedNameSpecifierLocVisit *V = cast<NestedNameSpecifierLocVisit>(&LI);
|
|
|
|
if (VisitNestedNameSpecifierLoc(V->get()))
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VisitorJob::DeclarationNameInfoVisitKind: {
|
|
|
|
if (VisitDeclarationNameInfo(cast<DeclarationNameInfoVisit>(&LI)
|
|
|
|
->get()))
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::MemberRefVisitKind: {
|
|
|
|
MemberRefVisit *V = cast<MemberRefVisit>(&LI);
|
|
|
|
if (Visit(MakeCursorMemberRef(V->get(), V->getLoc(), TU)))
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::StmtVisitKind: {
|
2013-01-26 23:29:08 +08:00
|
|
|
const Stmt *S = cast<StmtVisit>(&LI)->get();
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!S)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Update the current cursor.
|
|
|
|
CXCursor Cursor = MakeCXCursor(S, StmtParent, TU, RegionOfInterest);
|
|
|
|
if (!IsInRegionOfInterest(Cursor))
|
|
|
|
continue;
|
|
|
|
switch (Visitor(Cursor, Parent, ClientData)) {
|
|
|
|
case CXChildVisit_Break: return true;
|
|
|
|
case CXChildVisit_Continue: break;
|
|
|
|
case CXChildVisit_Recurse:
|
|
|
|
if (PostChildrenVisitor)
|
2014-06-08 16:38:04 +08:00
|
|
|
WL.push_back(PostChildrenVisit(nullptr, Cursor));
|
2012-12-18 22:30:41 +08:00
|
|
|
EnqueueWorkList(WL, S);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::MemberExprPartsKind: {
|
|
|
|
// Handle the other pieces in the MemberExpr besides the base.
|
2013-01-26 23:29:08 +08:00
|
|
|
const MemberExpr *M = cast<MemberExprParts>(&LI)->get();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Visit the nested-name-specifier
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = M->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(M->getMemberNameInfo()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the explicitly-specified template arguments, if any.
|
|
|
|
if (M->hasExplicitTemplateArgs()) {
|
|
|
|
for (const TemplateArgumentLoc *Arg = M->getTemplateArgs(),
|
|
|
|
*ArgEnd = Arg + M->getNumTemplateArgs();
|
|
|
|
Arg != ArgEnd; ++Arg) {
|
|
|
|
if (VisitTemplateArgumentLoc(*Arg))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::DeclRefExprPartsKind: {
|
2013-01-26 23:29:08 +08:00
|
|
|
const DeclRefExpr *DR = cast<DeclRefExprParts>(&LI)->get();
|
2012-12-18 22:30:41 +08:00
|
|
|
// Visit nested-name-specifier, if present.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = DR->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
// Visit declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(DR->getNameInfo()))
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::OverloadExprPartsKind: {
|
2013-01-26 23:29:08 +08:00
|
|
|
const OverloadExpr *O = cast<OverloadExprParts>(&LI)->get();
|
2012-12-18 22:30:41 +08:00
|
|
|
// Visit the nested-name-specifier.
|
|
|
|
if (NestedNameSpecifierLoc QualifierLoc = O->getQualifierLoc())
|
|
|
|
if (VisitNestedNameSpecifierLoc(QualifierLoc))
|
|
|
|
return true;
|
|
|
|
// Visit the declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(O->getNameInfo()))
|
|
|
|
return true;
|
|
|
|
// Visit the overloaded declaration reference.
|
|
|
|
if (Visit(MakeCursorOverloadedDeclRef(O, TU)))
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case VisitorJob::SizeOfPackExprPartsKind: {
|
2013-01-26 23:29:08 +08:00
|
|
|
const SizeOfPackExpr *E = cast<SizeOfPackExprParts>(&LI)->get();
|
2012-12-18 22:30:41 +08:00
|
|
|
NamedDecl *Pack = E->getPack();
|
|
|
|
if (isa<TemplateTypeParmDecl>(Pack)) {
|
|
|
|
if (Visit(MakeCursorTypeRef(cast<TemplateTypeParmDecl>(Pack),
|
|
|
|
E->getPackLoc(), TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isa<TemplateTemplateParmDecl>(Pack)) {
|
|
|
|
if (Visit(MakeCursorTemplateRef(cast<TemplateTemplateParmDecl>(Pack),
|
|
|
|
E->getPackLoc(), TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non-type template parameter packs and function parameter packs are
|
|
|
|
// treated like DeclRefExpr cursors.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VisitorJob::LambdaExprPartsKind: {
|
2019-05-21 17:21:35 +08:00
|
|
|
// Visit non-init captures.
|
2013-01-26 23:29:08 +08:00
|
|
|
const LambdaExpr *E = cast<LambdaExprParts>(&LI)->get();
|
2012-12-18 22:30:41 +08:00
|
|
|
for (LambdaExpr::capture_iterator C = E->explicit_capture_begin(),
|
|
|
|
CEnd = E->explicit_capture_end();
|
|
|
|
C != CEnd; ++C) {
|
2013-05-16 14:20:58 +08:00
|
|
|
if (!C->capturesVariable())
|
2012-12-18 22:30:41 +08:00
|
|
|
continue;
|
2013-05-16 14:20:58 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Visit(MakeCursorVariableRef(C->getCapturedVar(),
|
|
|
|
C->getLocation(),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-21 17:21:35 +08:00
|
|
|
// Visit init captures
|
|
|
|
for (auto InitExpr : E->capture_inits()) {
|
|
|
|
if (Visit(InitExpr))
|
|
|
|
return true;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2018-12-18 23:29:12 +08:00
|
|
|
TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
|
2012-12-18 22:30:41 +08:00
|
|
|
// Visit parameters and return type, if present.
|
2018-12-18 23:29:12 +08:00
|
|
|
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)))
|
2012-12-18 22:30:41 +08:00
|
|
|
return true;
|
2018-12-18 23:29:12 +08:00
|
|
|
}
|
|
|
|
if (E->hasExplicitResultType()) {
|
|
|
|
// Visit result type.
|
|
|
|
if (Visit(Proto.getReturnLoc()))
|
|
|
|
return true;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VisitorJob::PostChildrenVisitKind:
|
|
|
|
if (PostChildrenVisitor(Parent, ClientData))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
bool CursorVisitor::Visit(const Stmt *S) {
|
2014-06-08 16:38:04 +08:00
|
|
|
VisitorWorkList *WL = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!WorkListFreeList.empty()) {
|
|
|
|
WL = WorkListFreeList.back();
|
|
|
|
WL->clear();
|
|
|
|
WorkListFreeList.pop_back();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
WL = new VisitorWorkList();
|
|
|
|
WorkListCache.push_back(WL);
|
|
|
|
}
|
|
|
|
EnqueueWorkList(*WL, S);
|
|
|
|
bool result = RunVisitorWorkList(*WL);
|
|
|
|
WorkListFreeList.push_back(WL);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2013-01-13 03:30:44 +08:00
|
|
|
typedef SmallVector<SourceRange, 4> RefNamePieces;
|
2015-12-24 10:59:37 +08:00
|
|
|
RefNamePieces buildPieces(unsigned NameFlags, bool IsMemberRefExpr,
|
|
|
|
const DeclarationNameInfo &NI, SourceRange QLoc,
|
|
|
|
const SourceRange *TemplateArgsLoc = nullptr) {
|
2012-12-18 22:30:41 +08:00
|
|
|
const bool WantQualifier = NameFlags & CXNameRange_WantQualifier;
|
|
|
|
const bool WantTemplateArgs = NameFlags & CXNameRange_WantTemplateArgs;
|
|
|
|
const bool WantSinglePiece = NameFlags & CXNameRange_WantSinglePiece;
|
|
|
|
|
|
|
|
const DeclarationName::NameKind Kind = NI.getName().getNameKind();
|
|
|
|
|
|
|
|
RefNamePieces Pieces;
|
|
|
|
|
|
|
|
if (WantQualifier && QLoc.isValid())
|
|
|
|
Pieces.push_back(QLoc);
|
|
|
|
|
|
|
|
if (Kind != DeclarationName::CXXOperatorName || IsMemberRefExpr)
|
|
|
|
Pieces.push_back(NI.getLoc());
|
2015-12-24 10:59:37 +08:00
|
|
|
|
|
|
|
if (WantTemplateArgs && TemplateArgsLoc && TemplateArgsLoc->isValid())
|
|
|
|
Pieces.push_back(*TemplateArgsLoc);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Kind == DeclarationName::CXXOperatorName) {
|
|
|
|
Pieces.push_back(SourceLocation::getFromRawEncoding(
|
|
|
|
NI.getInfo().CXXOperatorName.BeginOpNameLoc));
|
|
|
|
Pieces.push_back(SourceLocation::getFromRawEncoding(
|
|
|
|
NI.getInfo().CXXOperatorName.EndOpNameLoc));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WantSinglePiece) {
|
|
|
|
SourceRange R(Pieces.front().getBegin(), Pieces.back().getEnd());
|
|
|
|
Pieces.clear();
|
|
|
|
Pieces.push_back(R);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Pieces;
|
|
|
|
}
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Misc. API hooks.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-03-28 02:28:23 +08:00
|
|
|
static void fatal_error_handler(void *user_data, const std::string& reason,
|
|
|
|
bool gen_crash_diag) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Write the result out to stderr avoiding errs() because raw_ostreams can
|
|
|
|
// call report_fatal_error.
|
|
|
|
fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str());
|
|
|
|
::abort();
|
|
|
|
}
|
|
|
|
|
2014-06-28 00:37:27 +08:00
|
|
|
namespace {
|
|
|
|
struct RegisterFatalErrorHandler {
|
|
|
|
RegisterFatalErrorHandler() {
|
|
|
|
llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static llvm::ManagedStatic<RegisterFatalErrorHandler> RegisterFatalErrorHandlerOnce;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
|
|
|
|
int displayDiagnostics) {
|
|
|
|
// We use crash recovery to make some of our APIs more reliable, implicitly
|
|
|
|
// enable it.
|
2013-11-27 16:58:09 +08:00
|
|
|
if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY"))
|
|
|
|
llvm::CrashRecoveryContext::Enable();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-06-28 00:37:27 +08:00
|
|
|
// Look through the managed static to trigger construction of the managed
|
|
|
|
// static which registers our fatal error handler. This ensures it is only
|
|
|
|
// registered once.
|
|
|
|
(void)*RegisterFatalErrorHandlerOnce;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-08 09:00:30 +08:00
|
|
|
// Initialize targets for clang module support.
|
|
|
|
llvm::InitializeAllTargets();
|
|
|
|
llvm::InitializeAllTargetMCs();
|
|
|
|
llvm::InitializeAllAsmPrinters();
|
|
|
|
llvm::InitializeAllAsmParsers();
|
|
|
|
|
2015-07-17 09:19:54 +08:00
|
|
|
CIndexer *CIdxr = new CIndexer();
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (excludeDeclarationsFromPCH)
|
|
|
|
CIdxr->setOnlyLocalDecls();
|
|
|
|
if (displayDiagnostics)
|
|
|
|
CIdxr->setDisplayDiagnostics();
|
|
|
|
|
|
|
|
if (getenv("LIBCLANG_BGPRIO_INDEX"))
|
|
|
|
CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() |
|
|
|
|
CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
|
|
|
|
if (getenv("LIBCLANG_BGPRIO_EDIT"))
|
|
|
|
CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() |
|
|
|
|
CXGlobalOpt_ThreadBackgroundPriorityForEditing);
|
|
|
|
|
|
|
|
return CIdxr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_disposeIndex(CXIndex CIdx) {
|
|
|
|
if (CIdx)
|
|
|
|
delete static_cast<CIndexer *>(CIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_CXIndex_setGlobalOptions(CXIndex CIdx, unsigned options) {
|
|
|
|
if (CIdx)
|
|
|
|
static_cast<CIndexer *>(CIdx)->setCXGlobalOptFlags(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_CXIndex_getGlobalOptions(CXIndex CIdx) {
|
|
|
|
if (CIdx)
|
|
|
|
return static_cast<CIndexer *>(CIdx)->getCXGlobalOptFlags();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-05 05:56:36 +08:00
|
|
|
void clang_CXIndex_setInvocationEmissionPathOption(CXIndex CIdx,
|
|
|
|
const char *Path) {
|
|
|
|
if (CIdx)
|
|
|
|
static_cast<CIndexer *>(CIdx)->setInvocationEmissionPath(Path ? Path : "");
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void clang_toggleCrashRecovery(unsigned isEnabled) {
|
|
|
|
if (isEnabled)
|
|
|
|
llvm::CrashRecoveryContext::Enable();
|
|
|
|
else
|
|
|
|
llvm::CrashRecoveryContext::Disable();
|
|
|
|
}
|
2014-02-13 03:12:37 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
|
|
|
|
const char *ast_filename) {
|
2014-02-19 18:24:00 +08:00
|
|
|
CXTranslationUnit TU;
|
2014-02-13 03:12:37 +08:00
|
|
|
enum CXErrorCode Result =
|
|
|
|
clang_createTranslationUnit2(CIdx, ast_filename, &TU);
|
2014-02-13 07:56:20 +08:00
|
|
|
(void)Result;
|
2014-02-13 03:12:37 +08:00
|
|
|
assert((TU && Result == CXError_Success) ||
|
|
|
|
(!TU && Result != CXError_Success));
|
|
|
|
return TU;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
|
|
|
|
const char *ast_filename,
|
|
|
|
CXTranslationUnit *out_TU) {
|
2014-02-19 18:24:00 +08:00
|
|
|
if (out_TU)
|
2014-06-08 16:38:04 +08:00
|
|
|
*out_TU = nullptr;
|
2014-02-19 18:24:00 +08:00
|
|
|
|
2014-02-13 03:12:37 +08:00
|
|
|
if (!CIdx || !ast_filename || !out_TU)
|
|
|
|
return CXError_InvalidArguments;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-05-25 06:24:07 +08:00
|
|
|
LOG_FUNC_SECTION {
|
|
|
|
*Log << ast_filename;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
|
|
|
|
FileSystemOptions FileSystemOpts;
|
|
|
|
|
2014-10-15 08:33:06 +08:00
|
|
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
|
|
|
CompilerInstance::createDiagnostics(new DiagnosticOptions());
|
2014-08-11 03:08:04 +08:00
|
|
|
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
|
2017-06-30 07:23:46 +08:00
|
|
|
ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(),
|
|
|
|
ASTUnit::LoadEverything, Diags,
|
2015-08-28 03:46:20 +08:00
|
|
|
FileSystemOpts, /*UseDebugInfo=*/false,
|
|
|
|
CXXIdx->getOnlyLocalDecls(), None,
|
2019-06-11 22:14:24 +08:00
|
|
|
CaptureDiagsKind::All,
|
2014-08-11 03:08:04 +08:00
|
|
|
/*AllowPCHWithCompilerErrors=*/true,
|
|
|
|
/*UserFilesAreVolatile=*/true);
|
2017-01-07 03:49:01 +08:00
|
|
|
*out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU));
|
2014-02-13 03:12:37 +08:00
|
|
|
return *out_TU ? CXError_Success : CXError_Failure;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_defaultEditingTranslationUnitOptions() {
|
|
|
|
return CXTranslationUnit_PrecompiledPreamble |
|
|
|
|
CXTranslationUnit_CacheCompletionResults;
|
|
|
|
}
|
2014-02-13 03:12:37 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXTranslationUnit
|
|
|
|
clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
|
|
|
|
const char *source_filename,
|
|
|
|
int num_command_line_args,
|
|
|
|
const char * const *command_line_args,
|
|
|
|
unsigned num_unsaved_files,
|
|
|
|
struct CXUnsavedFile *unsaved_files) {
|
|
|
|
unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord;
|
|
|
|
return clang_parseTranslationUnit(CIdx, source_filename,
|
|
|
|
command_line_args, num_command_line_args,
|
|
|
|
unsaved_files, num_unsaved_files,
|
|
|
|
Options);
|
|
|
|
}
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
static CXErrorCode
|
|
|
|
clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename,
|
|
|
|
const char *const *command_line_args,
|
|
|
|
int num_command_line_args,
|
|
|
|
ArrayRef<CXUnsavedFile> unsaved_files,
|
|
|
|
unsigned options, CXTranslationUnit *out_TU) {
|
2014-02-18 23:20:02 +08:00
|
|
|
// Set up the initial return values.
|
|
|
|
if (out_TU)
|
2014-06-08 16:38:04 +08:00
|
|
|
*out_TU = nullptr;
|
2014-02-18 23:20:02 +08:00
|
|
|
|
2014-02-13 03:12:37 +08:00
|
|
|
// Check arguments.
|
2015-07-26 04:55:44 +08:00
|
|
|
if (!CIdx || !out_TU)
|
|
|
|
return CXError_InvalidArguments;
|
2014-02-13 03:12:37 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
|
|
|
|
|
|
|
|
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
|
|
|
|
setThreadBackgroundPriority();
|
|
|
|
|
|
|
|
bool PrecompilePreamble = options & CXTranslationUnit_PrecompiledPreamble;
|
2015-12-15 17:30:31 +08:00
|
|
|
bool CreatePreambleOnFirstParse =
|
|
|
|
options & CXTranslationUnit_CreatePreambleOnFirstParse;
|
2012-12-18 22:30:41 +08:00
|
|
|
// FIXME: Add a flag for modules.
|
|
|
|
TranslationUnitKind TUKind
|
2017-06-09 09:20:48 +08:00
|
|
|
= (options & (CXTranslationUnit_Incomplete |
|
|
|
|
CXTranslationUnit_SingleFileParse))? TU_Prefix : TU_Complete;
|
2013-12-03 14:53:35 +08:00
|
|
|
bool CacheCodeCompletionResults
|
2018-05-17 17:15:22 +08:00
|
|
|
= options & CXTranslationUnit_CacheCompletionResults;
|
|
|
|
bool IncludeBriefCommentsInCodeCompletion
|
|
|
|
= options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
|
|
|
|
bool SingleFileParse = options & CXTranslationUnit_SingleFileParse;
|
|
|
|
bool ForSerialization = options & CXTranslationUnit_ForSerialization;
|
2018-05-17 17:24:37 +08:00
|
|
|
SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None;
|
|
|
|
if (options & CXTranslationUnit_SkipFunctionBodies) {
|
|
|
|
SkipFunctionBodies =
|
|
|
|
(options & CXTranslationUnit_LimitSkipFunctionBodiesToPreamble)
|
|
|
|
? SkipFunctionBodiesScope::Preamble
|
|
|
|
: SkipFunctionBodiesScope::PreambleAndMainFile;
|
|
|
|
}
|
2018-05-17 17:15:22 +08:00
|
|
|
|
|
|
|
// Configure the diagnostics.
|
|
|
|
IntrusiveRefCntPtr<DiagnosticsEngine>
|
2013-01-20 09:58:28 +08:00
|
|
|
Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-03-01 18:56:19 +08:00
|
|
|
if (options & CXTranslationUnit_KeepGoing)
|
2019-03-07 18:13:50 +08:00
|
|
|
Diags->setFatalsAsError(true);
|
2016-03-01 18:56:19 +08:00
|
|
|
|
2019-06-11 22:14:24 +08:00
|
|
|
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::All;
|
|
|
|
if (options & CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles)
|
|
|
|
CaptureDiagnostics = CaptureDiagsKind::AllWithoutNonErrorsFromIncludes;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Recover resources if we crash before exiting this function.
|
|
|
|
llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
|
|
|
|
llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
|
2014-07-05 11:08:06 +08:00
|
|
|
DiagCleanup(Diags.get());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles(
|
|
|
|
new std::vector<ASTUnit::RemappedFile>());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Recover resources if we crash before exiting this function.
|
|
|
|
llvm::CrashRecoveryContextCleanupRegistrar<
|
|
|
|
std::vector<ASTUnit::RemappedFile> > RemappedCleanup(RemappedFiles.get());
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
for (auto &UF : unsaved_files) {
|
2014-08-28 04:03:29 +08:00
|
|
|
std::unique_ptr<llvm::MemoryBuffer> MB =
|
2014-07-07 09:23:14 +08:00
|
|
|
llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
|
2014-08-28 04:03:29 +08:00
|
|
|
RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<std::vector<const char *>> Args(
|
|
|
|
new std::vector<const char *>());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Recover resources if we crash before exiting this method.
|
|
|
|
llvm::CrashRecoveryContextCleanupRegistrar<std::vector<const char*> >
|
|
|
|
ArgsCleanup(Args.get());
|
|
|
|
|
|
|
|
// Since the Clang C library is primarily used by batch tools dealing with
|
|
|
|
// (often very broken) source code, where spell-checking can have a
|
|
|
|
// significant negative impact on performance (particularly when
|
|
|
|
// precompiled headers are involved), we disable it by default.
|
|
|
|
// Only do this if we haven't found a spell-checking-related argument.
|
|
|
|
bool FoundSpellCheckingArgument = false;
|
|
|
|
for (int I = 0; I != num_command_line_args; ++I) {
|
|
|
|
if (strcmp(command_line_args[I], "-fno-spell-checking") == 0 ||
|
|
|
|
strcmp(command_line_args[I], "-fspell-checking") == 0) {
|
|
|
|
FoundSpellCheckingArgument = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Args->insert(Args->end(), command_line_args,
|
|
|
|
command_line_args + num_command_line_args);
|
|
|
|
|
2015-11-19 00:14:27 +08:00
|
|
|
if (!FoundSpellCheckingArgument)
|
|
|
|
Args->insert(Args->begin() + 1, "-fno-spell-checking");
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// The 'source_filename' argument is optional. If the caller does not
|
|
|
|
// specify it then it is assumed that the source file is specified
|
|
|
|
// in the actual argument list.
|
|
|
|
// Put the source file after command_line_args otherwise if '-x' flag is
|
|
|
|
// present it will be unused.
|
|
|
|
if (source_filename)
|
|
|
|
Args->push_back(source_filename);
|
|
|
|
|
|
|
|
// Do we need the detailed preprocessing record?
|
|
|
|
if (options & CXTranslationUnit_DetailedPreprocessingRecord) {
|
|
|
|
Args->push_back("-Xclang");
|
|
|
|
Args->push_back("-detailed-preprocessing-record");
|
|
|
|
}
|
2017-04-27 21:47:03 +08:00
|
|
|
|
|
|
|
// Suppress any editor placeholder diagnostics.
|
|
|
|
Args->push_back("-fallow-editor-placeholders");
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned NumErrors = Diags->getClient()->getNumErrors();
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<ASTUnit> ErrUnit;
|
2015-12-15 17:30:31 +08:00
|
|
|
// Unless the user specified that they want the preamble on the first parse
|
|
|
|
// set it up to be created on the first reparse. This makes the first parse
|
|
|
|
// faster, trading for a slower (first) reparse.
|
|
|
|
unsigned PrecompilePreambleAfterNParses =
|
|
|
|
!PrecompilePreamble ? 0 : 2 - CreatePreambleOnFirstParse;
|
2017-12-05 05:56:36 +08:00
|
|
|
|
|
|
|
LibclangInvocationReporter InvocationReporter(
|
|
|
|
*CXXIdx, LibclangInvocationReporter::OperationKind::ParseOperation,
|
2017-12-08 04:37:50 +08:00
|
|
|
options, llvm::makeArrayRef(*Args), /*InvocationArgs=*/None,
|
|
|
|
unsaved_files);
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCommandLine(
|
2015-06-21 02:53:08 +08:00
|
|
|
Args->data(), Args->data() + Args->size(),
|
|
|
|
CXXIdx->getPCHContainerOperations(), Diags,
|
2014-03-08 04:03:18 +08:00
|
|
|
CXXIdx->getClangResourcesPath(), CXXIdx->getOnlyLocalDecls(),
|
2019-06-11 22:14:24 +08:00
|
|
|
CaptureDiagnostics, *RemappedFiles.get(),
|
2015-12-15 17:30:31 +08:00
|
|
|
/*RemappedFilesKeepOriginalName=*/true, PrecompilePreambleAfterNParses,
|
|
|
|
TUKind, CacheCodeCompletionResults, IncludeBriefCommentsInCodeCompletion,
|
2017-06-09 09:20:48 +08:00
|
|
|
/*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,
|
2015-11-20 11:36:21 +08:00
|
|
|
/*UserFilesAreVolatile=*/true, ForSerialization,
|
|
|
|
CXXIdx->getPCHContainerOperations()->getRawReader().getFormat(),
|
|
|
|
&ErrUnit));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-14 07:27:56 +08:00
|
|
|
// Early failures in LoadFromCommandLine may return with ErrUnit unset.
|
2015-07-26 04:55:44 +08:00
|
|
|
if (!Unit && !ErrUnit)
|
|
|
|
return CXError_ASTReadError;
|
2015-07-14 07:27:56 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (NumErrors != Diags->getClient()->getNumErrors()) {
|
|
|
|
// Make sure to check that 'Unit' is non-NULL.
|
|
|
|
if (CXXIdx->getDisplayDiagnostics())
|
|
|
|
printDiagsToStderr(Unit ? Unit.get() : ErrUnit.get());
|
|
|
|
}
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
if (isASTReadError(Unit ? Unit.get() : ErrUnit.get()))
|
|
|
|
return CXError_ASTReadError;
|
|
|
|
|
2017-01-07 03:49:01 +08:00
|
|
|
*out_TU = MakeCXTranslationUnit(CXXIdx, std::move(Unit));
|
2017-12-08 04:37:50 +08:00
|
|
|
if (CXTranslationUnitImpl *TU = *out_TU) {
|
|
|
|
TU->ParsingOptions = options;
|
|
|
|
TU->Arguments.reserve(Args->size());
|
|
|
|
for (const char *Arg : *Args)
|
|
|
|
TU->Arguments.push_back(Arg);
|
|
|
|
return CXError_Success;
|
|
|
|
}
|
|
|
|
return CXError_Failure;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2014-02-13 03:12:37 +08:00
|
|
|
|
|
|
|
CXTranslationUnit
|
|
|
|
clang_parseTranslationUnit(CXIndex CIdx,
|
|
|
|
const char *source_filename,
|
|
|
|
const char *const *command_line_args,
|
|
|
|
int num_command_line_args,
|
|
|
|
struct CXUnsavedFile *unsaved_files,
|
|
|
|
unsigned num_unsaved_files,
|
|
|
|
unsigned options) {
|
|
|
|
CXTranslationUnit TU;
|
|
|
|
enum CXErrorCode Result = clang_parseTranslationUnit2(
|
|
|
|
CIdx, source_filename, command_line_args, num_command_line_args,
|
|
|
|
unsaved_files, num_unsaved_files, options, &TU);
|
2014-02-13 09:19:59 +08:00
|
|
|
(void)Result;
|
2014-02-18 23:20:02 +08:00
|
|
|
assert((TU && Result == CXError_Success) ||
|
|
|
|
(!TU && Result != CXError_Success));
|
2014-02-13 03:12:37 +08:00
|
|
|
return TU;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum CXErrorCode clang_parseTranslationUnit2(
|
2015-11-19 00:14:27 +08:00
|
|
|
CXIndex CIdx, const char *source_filename,
|
|
|
|
const char *const *command_line_args, int num_command_line_args,
|
|
|
|
struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
|
|
|
|
unsigned options, CXTranslationUnit *out_TU) {
|
|
|
|
SmallVector<const char *, 4> Args;
|
|
|
|
Args.push_back("clang");
|
|
|
|
Args.append(command_line_args, command_line_args + num_command_line_args);
|
|
|
|
return clang_parseTranslationUnit2FullArgv(
|
|
|
|
CIdx, source_filename, Args.data(), Args.size(), unsaved_files,
|
|
|
|
num_unsaved_files, options, out_TU);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum CXErrorCode clang_parseTranslationUnit2FullArgv(
|
|
|
|
CXIndex CIdx, const char *source_filename,
|
|
|
|
const char *const *command_line_args, int num_command_line_args,
|
|
|
|
struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
|
|
|
|
unsigned options, CXTranslationUnit *out_TU) {
|
2013-01-11 02:54:52 +08:00
|
|
|
LOG_FUNC_SECTION {
|
|
|
|
*Log << source_filename << ": ";
|
|
|
|
for (int i = 0; i != num_command_line_args; ++i)
|
|
|
|
*Log << command_line_args[i] << " ";
|
|
|
|
}
|
|
|
|
|
2014-07-07 09:23:14 +08:00
|
|
|
if (num_unsaved_files && !unsaved_files)
|
|
|
|
return CXError_InvalidArguments;
|
|
|
|
|
2014-07-08 06:42:03 +08:00
|
|
|
CXErrorCode result = CXError_Failure;
|
2015-07-26 04:55:44 +08:00
|
|
|
auto ParseTranslationUnitImpl = [=, &result] {
|
|
|
|
result = clang_parseTranslationUnit_Impl(
|
|
|
|
CIdx, source_filename, command_line_args, num_command_line_args,
|
|
|
|
llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU);
|
|
|
|
};
|
2017-08-29 17:08:02 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::CrashRecoveryContext CRC;
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
if (!RunSafely(CRC, ParseTranslationUnitImpl)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
fprintf(stderr, "libclang: crash detected during parsing: {\n");
|
|
|
|
fprintf(stderr, " 'source_filename' : '%s'\n", source_filename);
|
|
|
|
fprintf(stderr, " 'command_line_args' : [");
|
|
|
|
for (int i = 0; i != num_command_line_args; ++i) {
|
|
|
|
if (i)
|
|
|
|
fprintf(stderr, ", ");
|
|
|
|
fprintf(stderr, "'%s'", command_line_args[i]);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "],\n");
|
|
|
|
fprintf(stderr, " 'unsaved_files' : [");
|
|
|
|
for (unsigned i = 0; i != num_unsaved_files; ++i) {
|
|
|
|
if (i)
|
|
|
|
fprintf(stderr, ", ");
|
|
|
|
fprintf(stderr, "('%s', '...', %ld)", unsaved_files[i].Filename,
|
|
|
|
unsaved_files[i].Length);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "],\n");
|
|
|
|
fprintf(stderr, " 'options' : %d,\n", options);
|
|
|
|
fprintf(stderr, "}\n");
|
2014-02-13 03:12:37 +08:00
|
|
|
|
|
|
|
return CXError_Crashed;
|
2012-12-18 22:30:41 +08:00
|
|
|
} else if (getenv("LIBCLANG_RESOURCE_USAGE")) {
|
2015-07-26 04:55:44 +08:00
|
|
|
if (CXTranslationUnit *TU = out_TU)
|
2014-02-13 03:12:37 +08:00
|
|
|
PrintLibclangResourceUsage(*TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2014-07-08 06:42:03 +08:00
|
|
|
|
|
|
|
return result;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-01-16 08:20:02 +08:00
|
|
|
CXString clang_Type_getObjCEncoding(CXType CT) {
|
|
|
|
CXTranslationUnit tu = static_cast<CXTranslationUnit>(CT.data[1]);
|
|
|
|
ASTContext &Ctx = getASTUnit(tu)->getASTContext();
|
|
|
|
std::string encoding;
|
|
|
|
Ctx.getObjCEncodingForType(QualType::getFromOpaquePtr(CT.data[0]),
|
|
|
|
encoding);
|
|
|
|
|
|
|
|
return cxstring::createDup(encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IdentifierInfo *getMacroIdentifier(CXCursor C) {
|
|
|
|
if (C.kind == CXCursor_MacroDefinition) {
|
|
|
|
if (const MacroDefinitionRecord *MDR = getCursorMacroDefinition(C))
|
|
|
|
return MDR->getName();
|
|
|
|
} else if (C.kind == CXCursor_MacroExpansion) {
|
|
|
|
MacroExpansionCursor ME = getCursorMacroExpansion(C);
|
|
|
|
return ME.getName();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_Cursor_isMacroFunctionLike(CXCursor C) {
|
|
|
|
const IdentifierInfo *II = getMacroIdentifier(C);
|
|
|
|
if (!II) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ASTUnit *ASTU = getCursorASTUnit(C);
|
|
|
|
Preprocessor &PP = ASTU->getPreprocessor();
|
|
|
|
if (const MacroInfo *MI = PP.getMacroInfo(II))
|
|
|
|
return MI->isFunctionLike();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_Cursor_isMacroBuiltin(CXCursor C) {
|
|
|
|
const IdentifierInfo *II = getMacroIdentifier(C);
|
|
|
|
if (!II) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ASTUnit *ASTU = getCursorASTUnit(C);
|
|
|
|
Preprocessor &PP = ASTU->getPreprocessor();
|
|
|
|
if (const MacroInfo *MI = PP.getMacroInfo(II))
|
|
|
|
return MI->isBuiltinMacro();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_Cursor_isFunctionInlined(CXCursor C) {
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
|
|
|
|
if (!FD) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return FD->isInlined();
|
|
|
|
}
|
|
|
|
|
|
|
|
static StringLiteral* getCFSTR_value(CallExpr *callExpr) {
|
|
|
|
if (callExpr->getNumArgs() != 1) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringLiteral *S = nullptr;
|
|
|
|
auto *arg = callExpr->getArg(0);
|
|
|
|
if (arg->getStmtClass() == Stmt::ImplicitCastExprClass) {
|
|
|
|
ImplicitCastExpr *I = static_cast<ImplicitCastExpr *>(arg);
|
|
|
|
auto *subExpr = I->getSubExprAsWritten();
|
|
|
|
|
|
|
|
if(subExpr->getStmtClass() != Stmt::StringLiteralClass){
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
S = static_cast<StringLiteral *>(I->getSubExprAsWritten());
|
|
|
|
} else if (arg->getStmtClass() == Stmt::StringLiteralClass) {
|
|
|
|
S = static_cast<StringLiteral *>(callExpr->getArg(0));
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
2016-04-14 02:23:33 +08:00
|
|
|
struct ExprEvalResult {
|
2016-01-16 08:20:02 +08:00
|
|
|
CXEvalResultKind EvalType;
|
|
|
|
union {
|
2016-12-02 07:41:27 +08:00
|
|
|
unsigned long long unsignedVal;
|
|
|
|
long long intVal;
|
2016-01-16 08:20:02 +08:00
|
|
|
double floatVal;
|
|
|
|
char *stringVal;
|
|
|
|
} EvalData;
|
2016-12-02 07:41:27 +08:00
|
|
|
bool IsUnsignedInt;
|
2016-04-14 02:23:33 +08:00
|
|
|
~ExprEvalResult() {
|
|
|
|
if (EvalType != CXEval_UnExposed && EvalType != CXEval_Float &&
|
|
|
|
EvalType != CXEval_Int) {
|
2019-01-09 07:28:37 +08:00
|
|
|
delete[] EvalData.stringVal;
|
2016-01-16 08:20:02 +08:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 02:23:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void clang_EvalResult_dispose(CXEvalResult E) {
|
|
|
|
delete static_cast<ExprEvalResult *>(E);
|
2016-01-16 08:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E) {
|
|
|
|
if (!E) {
|
|
|
|
return CXEval_UnExposed;
|
|
|
|
}
|
|
|
|
return ((ExprEvalResult *)E)->EvalType;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clang_EvalResult_getAsInt(CXEvalResult E) {
|
2016-12-02 07:41:27 +08:00
|
|
|
return clang_EvalResult_getAsLongLong(E);
|
|
|
|
}
|
|
|
|
|
|
|
|
long long clang_EvalResult_getAsLongLong(CXEvalResult E) {
|
|
|
|
if (!E) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ExprEvalResult *Result = (ExprEvalResult*)E;
|
|
|
|
if (Result->IsUnsignedInt)
|
|
|
|
return Result->EvalData.unsignedVal;
|
|
|
|
return Result->EvalData.intVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_EvalResult_isUnsignedInt(CXEvalResult E) {
|
|
|
|
return ((ExprEvalResult *)E)->IsUnsignedInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long clang_EvalResult_getAsUnsigned(CXEvalResult E) {
|
2016-01-16 08:20:02 +08:00
|
|
|
if (!E) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-02 07:41:27 +08:00
|
|
|
|
|
|
|
ExprEvalResult *Result = (ExprEvalResult*)E;
|
|
|
|
if (Result->IsUnsignedInt)
|
|
|
|
return Result->EvalData.unsignedVal;
|
|
|
|
return Result->EvalData.intVal;
|
2016-01-16 08:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
double clang_EvalResult_getAsDouble(CXEvalResult E) {
|
|
|
|
if (!E) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ((ExprEvalResult *)E)->EvalData.floatVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* clang_EvalResult_getAsStr(CXEvalResult E) {
|
|
|
|
if (!E) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ((ExprEvalResult *)E)->EvalData.stringVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ExprEvalResult* evaluateExpr(Expr *expr, CXCursor C) {
|
|
|
|
Expr::EvalResult ER;
|
|
|
|
ASTContext &ctx = getCursorContext(C);
|
2016-04-14 02:36:19 +08:00
|
|
|
if (!expr)
|
2016-01-16 08:20:02 +08:00
|
|
|
return nullptr;
|
2016-04-14 02:36:19 +08:00
|
|
|
|
2016-01-16 08:20:02 +08:00
|
|
|
expr = expr->IgnoreParens();
|
2019-07-09 22:27:01 +08:00
|
|
|
if (expr->isValueDependent())
|
|
|
|
return nullptr;
|
2016-04-14 02:36:19 +08:00
|
|
|
if (!expr->EvaluateAsRValue(ER, ctx))
|
|
|
|
return nullptr;
|
|
|
|
|
2016-01-16 08:20:02 +08:00
|
|
|
QualType rettype;
|
|
|
|
CallExpr *callExpr;
|
2016-04-14 02:23:33 +08:00
|
|
|
auto result = llvm::make_unique<ExprEvalResult>();
|
2016-01-16 08:20:02 +08:00
|
|
|
result->EvalType = CXEval_UnExposed;
|
2016-12-02 07:41:27 +08:00
|
|
|
result->IsUnsignedInt = false;
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
if (ER.Val.isInt()) {
|
|
|
|
result->EvalType = CXEval_Int;
|
2016-12-02 07:41:27 +08:00
|
|
|
|
|
|
|
auto& val = ER.Val.getInt();
|
|
|
|
if (val.isUnsigned()) {
|
|
|
|
result->IsUnsignedInt = true;
|
|
|
|
result->EvalData.unsignedVal = val.getZExtValue();
|
|
|
|
} else {
|
|
|
|
result->EvalData.intVal = val.getExtValue();
|
|
|
|
}
|
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
return result.release();
|
|
|
|
}
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
if (ER.Val.isFloat()) {
|
|
|
|
llvm::SmallVector<char, 100> Buffer;
|
|
|
|
ER.Val.getFloat().toString(Buffer);
|
|
|
|
std::string floatStr(Buffer.data(), Buffer.size());
|
|
|
|
result->EvalType = CXEval_Float;
|
|
|
|
bool ignored;
|
|
|
|
llvm::APFloat apFloat = ER.Val.getFloat();
|
2016-12-14 19:57:17 +08:00
|
|
|
apFloat.convert(llvm::APFloat::IEEEdouble(),
|
2016-04-14 02:36:19 +08:00
|
|
|
llvm::APFloat::rmNearestTiesToEven, &ignored);
|
|
|
|
result->EvalData.floatVal = apFloat.convertToDouble();
|
|
|
|
return result.release();
|
|
|
|
}
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) {
|
|
|
|
const ImplicitCastExpr *I = dyn_cast<ImplicitCastExpr>(expr);
|
|
|
|
auto *subExpr = I->getSubExprAsWritten();
|
|
|
|
if (subExpr->getStmtClass() == Stmt::StringLiteralClass ||
|
|
|
|
subExpr->getStmtClass() == Stmt::ObjCStringLiteralClass) {
|
2016-01-16 08:20:02 +08:00
|
|
|
const StringLiteral *StrE = nullptr;
|
|
|
|
const ObjCStringLiteral *ObjCExpr;
|
2016-04-14 02:36:19 +08:00
|
|
|
ObjCExpr = dyn_cast<ObjCStringLiteral>(subExpr);
|
2016-01-16 08:20:02 +08:00
|
|
|
|
|
|
|
if (ObjCExpr) {
|
|
|
|
StrE = ObjCExpr->getString();
|
|
|
|
result->EvalType = CXEval_ObjCStrLiteral;
|
|
|
|
} else {
|
2016-04-14 02:36:19 +08:00
|
|
|
StrE = cast<StringLiteral>(I->getSubExprAsWritten());
|
2016-01-16 08:20:02 +08:00
|
|
|
result->EvalType = CXEval_StrLiteral;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string strRef(StrE->getString().str());
|
2016-04-14 02:23:33 +08:00
|
|
|
result->EvalData.stringVal = new char[strRef.size() + 1];
|
2016-04-14 02:36:19 +08:00
|
|
|
strncpy((char *)result->EvalData.stringVal, strRef.c_str(),
|
|
|
|
strRef.size());
|
2016-01-16 08:20:02 +08:00
|
|
|
result->EvalData.stringVal[strRef.size()] = '\0';
|
2016-04-14 02:23:33 +08:00
|
|
|
return result.release();
|
2016-04-14 02:36:19 +08:00
|
|
|
}
|
|
|
|
} else if (expr->getStmtClass() == Stmt::ObjCStringLiteralClass ||
|
|
|
|
expr->getStmtClass() == Stmt::StringLiteralClass) {
|
|
|
|
const StringLiteral *StrE = nullptr;
|
|
|
|
const ObjCStringLiteral *ObjCExpr;
|
|
|
|
ObjCExpr = dyn_cast<ObjCStringLiteral>(expr);
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
if (ObjCExpr) {
|
|
|
|
StrE = ObjCExpr->getString();
|
|
|
|
result->EvalType = CXEval_ObjCStrLiteral;
|
|
|
|
} else {
|
|
|
|
StrE = cast<StringLiteral>(expr);
|
|
|
|
result->EvalType = CXEval_StrLiteral;
|
|
|
|
}
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
std::string strRef(StrE->getString().str());
|
|
|
|
result->EvalData.stringVal = new char[strRef.size() + 1];
|
|
|
|
strncpy((char *)result->EvalData.stringVal, strRef.c_str(), strRef.size());
|
|
|
|
result->EvalData.stringVal[strRef.size()] = '\0';
|
|
|
|
return result.release();
|
|
|
|
}
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
if (expr->getStmtClass() == Stmt::CStyleCastExprClass) {
|
|
|
|
CStyleCastExpr *CC = static_cast<CStyleCastExpr *>(expr);
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
rettype = CC->getType();
|
|
|
|
if (rettype.getAsString() == "CFStringRef" &&
|
|
|
|
CC->getSubExpr()->getStmtClass() == Stmt::CallExprClass) {
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
callExpr = static_cast<CallExpr *>(CC->getSubExpr());
|
|
|
|
StringLiteral *S = getCFSTR_value(callExpr);
|
|
|
|
if (S) {
|
|
|
|
std::string strLiteral(S->getString().str());
|
|
|
|
result->EvalType = CXEval_CFStr;
|
|
|
|
|
|
|
|
result->EvalData.stringVal = new char[strLiteral.size() + 1];
|
|
|
|
strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(),
|
|
|
|
strLiteral.size());
|
|
|
|
result->EvalData.stringVal[strLiteral.size()] = '\0';
|
|
|
|
return result.release();
|
2016-01-16 08:20:02 +08:00
|
|
|
}
|
2016-04-14 02:36:19 +08:00
|
|
|
}
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
} else if (expr->getStmtClass() == Stmt::CallExprClass) {
|
|
|
|
callExpr = static_cast<CallExpr *>(expr);
|
|
|
|
rettype = callExpr->getCallReturnType(ctx);
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
if (rettype->isVectorType() || callExpr->getNumArgs() > 1)
|
|
|
|
return nullptr;
|
2016-01-16 08:20:02 +08:00
|
|
|
|
2016-04-14 02:36:19 +08:00
|
|
|
if (rettype->isIntegralType(ctx) || rettype->isRealFloatingType()) {
|
|
|
|
if (callExpr->getNumArgs() == 1 &&
|
|
|
|
!callExpr->getArg(0)->getType()->isIntegralType(ctx))
|
2016-01-16 08:20:02 +08:00
|
|
|
return nullptr;
|
2016-04-14 02:36:19 +08:00
|
|
|
} else if (rettype.getAsString() == "CFStringRef") {
|
|
|
|
|
|
|
|
StringLiteral *S = getCFSTR_value(callExpr);
|
|
|
|
if (S) {
|
|
|
|
std::string strLiteral(S->getString().str());
|
|
|
|
result->EvalType = CXEval_CFStr;
|
|
|
|
result->EvalData.stringVal = new char[strLiteral.size() + 1];
|
|
|
|
strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(),
|
|
|
|
strLiteral.size());
|
|
|
|
result->EvalData.stringVal[strLiteral.size()] = '\0';
|
2016-04-14 02:23:33 +08:00
|
|
|
return result.release();
|
2016-01-16 08:20:02 +08:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 02:36:19 +08:00
|
|
|
} else if (expr->getStmtClass() == Stmt::DeclRefExprClass) {
|
|
|
|
DeclRefExpr *D = static_cast<DeclRefExpr *>(expr);
|
|
|
|
ValueDecl *V = D->getDecl();
|
|
|
|
if (V->getKind() == Decl::Function) {
|
|
|
|
std::string strName = V->getNameAsString();
|
|
|
|
result->EvalType = CXEval_Other;
|
|
|
|
result->EvalData.stringVal = new char[strName.size() + 1];
|
|
|
|
strncpy(result->EvalData.stringVal, strName.c_str(), strName.size());
|
|
|
|
result->EvalData.stringVal[strName.size()] = '\0';
|
|
|
|
return result.release();
|
|
|
|
}
|
2016-01-16 08:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-09 06:32:51 +08:00
|
|
|
static const Expr *evaluateDeclExpr(const Decl *D) {
|
|
|
|
if (!D)
|
2018-07-11 03:48:53 +08:00
|
|
|
return nullptr;
|
2019-01-09 06:32:51 +08:00
|
|
|
if (auto *Var = dyn_cast<VarDecl>(D))
|
|
|
|
return Var->getInit();
|
|
|
|
else if (auto *Field = dyn_cast<FieldDecl>(D))
|
|
|
|
return Field->getInClassInitializer();
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-07-11 03:49:07 +08:00
|
|
|
|
2019-01-09 06:32:51 +08:00
|
|
|
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;
|
2018-07-11 03:49:07 +08:00
|
|
|
}
|
2018-07-10 03:56:45 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-09 06:32:51 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-01-16 08:20:02 +08:00
|
|
|
unsigned clang_Cursor_hasAttrs(CXCursor C) {
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
if (!D) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (D->hasAttrs()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned clang_defaultSaveOptions(CXTranslationUnit TU) {
|
|
|
|
return CXSaveTranslationUnit_None;
|
|
|
|
}
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
static CXSaveError clang_saveTranslationUnit_Impl(CXTranslationUnit TU,
|
|
|
|
const char *FileName,
|
|
|
|
unsigned options) {
|
|
|
|
CIndexer *CXXIdx = TU->CIdx;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
|
|
|
|
setThreadBackgroundPriority();
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
bool hadError = cxtu::getASTUnit(TU)->Save(FileName);
|
|
|
|
return hadError ? CXSaveError_Unknown : CXSaveError_None;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName,
|
|
|
|
unsigned options) {
|
2013-01-11 02:54:52 +08:00
|
|
|
LOG_FUNC_SECTION {
|
|
|
|
*Log << TU << ' ' << FileName;
|
|
|
|
}
|
|
|
|
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
return CXSaveError_InvalidTU;
|
2014-02-11 22:34:14 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
|
|
|
if (!CXXUnit->hasSema())
|
|
|
|
return CXSaveError_InvalidTU;
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
CXSaveError result;
|
|
|
|
auto SaveTranslationUnitImpl = [=, &result]() {
|
|
|
|
result = clang_saveTranslationUnit_Impl(TU, FileName, options);
|
|
|
|
};
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2017-11-14 17:34:39 +08:00
|
|
|
if (!CXXUnit->getDiagnostics().hasUnrecoverableErrorOccurred()) {
|
2015-07-26 04:55:44 +08:00
|
|
|
SaveTranslationUnitImpl();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (getenv("LIBCLANG_RESOURCE_USAGE"))
|
|
|
|
PrintLibclangResourceUsage(TU);
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
return result;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have an AST that has invalid nodes due to compiler errors.
|
|
|
|
// Use a crash recovery thread for protection.
|
|
|
|
|
|
|
|
llvm::CrashRecoveryContext CRC;
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
if (!RunSafely(CRC, SaveTranslationUnitImpl)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
fprintf(stderr, "libclang: crash detected during AST saving: {\n");
|
|
|
|
fprintf(stderr, " 'filename' : '%s'\n", FileName);
|
|
|
|
fprintf(stderr, " 'options' : %d,\n", options);
|
|
|
|
fprintf(stderr, "}\n");
|
|
|
|
|
|
|
|
return CXSaveError_Unknown;
|
|
|
|
|
|
|
|
} else if (getenv("LIBCLANG_RESOURCE_USAGE")) {
|
|
|
|
PrintLibclangResourceUsage(TU);
|
|
|
|
}
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
return result;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
|
|
|
|
if (CTUnit) {
|
|
|
|
// If the translation unit has been marked as unsafe to free, just discard
|
|
|
|
// it.
|
2014-02-13 03:12:37 +08:00
|
|
|
ASTUnit *Unit = cxtu::getASTUnit(CTUnit);
|
|
|
|
if (Unit && Unit->isUnsafeToFree())
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
delete cxtu::getASTUnit(CTUnit);
|
2013-01-27 06:44:19 +08:00
|
|
|
delete CTUnit->StringPool;
|
2012-12-18 22:30:41 +08:00
|
|
|
delete static_cast<CXDiagnosticSetImpl *>(CTUnit->Diagnostics);
|
|
|
|
disposeOverridenCXCursorsPool(CTUnit->OverridenCursorsPool);
|
2013-11-14 06:16:51 +08:00
|
|
|
delete CTUnit->CommentToXML;
|
2012-12-18 22:30:41 +08:00
|
|
|
delete CTUnit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 22:25:54 +08:00
|
|
|
unsigned clang_suspendTranslationUnit(CXTranslationUnit CTUnit) {
|
|
|
|
if (CTUnit) {
|
|
|
|
ASTUnit *Unit = cxtu::getASTUnit(CTUnit);
|
|
|
|
|
|
|
|
if (Unit && Unit->isUnsafeToFree())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Unit->ResetForParse();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned clang_defaultReparseOptions(CXTranslationUnit TU) {
|
|
|
|
return CXReparse_None;
|
|
|
|
}
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
static CXErrorCode
|
|
|
|
clang_reparseTranslationUnit_Impl(CXTranslationUnit TU,
|
|
|
|
ArrayRef<CXUnsavedFile> unsaved_files,
|
|
|
|
unsigned options) {
|
2014-02-13 03:12:37 +08:00
|
|
|
// Check arguments.
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
2015-07-26 04:55:44 +08:00
|
|
|
return CXError_InvalidArguments;
|
2014-02-13 03:12:37 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Reset the associated diagnostics.
|
|
|
|
delete static_cast<CXDiagnosticSetImpl*>(TU->Diagnostics);
|
2014-06-08 16:38:04 +08:00
|
|
|
TU->Diagnostics = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-27 05:49:50 +08:00
|
|
|
CIndexer *CXXIdx = TU->CIdx;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing))
|
|
|
|
setThreadBackgroundPriority();
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
2014-03-08 04:03:18 +08:00
|
|
|
|
|
|
|
std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles(
|
|
|
|
new std::vector<ASTUnit::RemappedFile>());
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Recover resources if we crash before exiting this function.
|
|
|
|
llvm::CrashRecoveryContextCleanupRegistrar<
|
|
|
|
std::vector<ASTUnit::RemappedFile> > RemappedCleanup(RemappedFiles.get());
|
2014-07-07 09:23:14 +08:00
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
for (auto &UF : unsaved_files) {
|
2014-08-28 04:03:29 +08:00
|
|
|
std::unique_ptr<llvm::MemoryBuffer> MB =
|
2014-07-07 09:23:14 +08:00
|
|
|
llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
|
2014-08-28 04:03:29 +08:00
|
|
|
RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2014-02-13 03:12:37 +08:00
|
|
|
|
2015-06-21 02:53:08 +08:00
|
|
|
if (!CXXUnit->Reparse(CXXIdx->getPCHContainerOperations(),
|
|
|
|
*RemappedFiles.get()))
|
2015-07-26 04:55:44 +08:00
|
|
|
return CXError_Success;
|
|
|
|
if (isASTReadError(CXXUnit))
|
|
|
|
return CXError_ASTReadError;
|
|
|
|
return CXError_Failure;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int clang_reparseTranslationUnit(CXTranslationUnit TU,
|
|
|
|
unsigned num_unsaved_files,
|
|
|
|
struct CXUnsavedFile *unsaved_files,
|
|
|
|
unsigned options) {
|
2013-01-11 02:54:52 +08:00
|
|
|
LOG_FUNC_SECTION {
|
|
|
|
*Log << TU;
|
|
|
|
}
|
|
|
|
|
2014-07-07 09:23:14 +08:00
|
|
|
if (num_unsaved_files && !unsaved_files)
|
|
|
|
return CXError_InvalidArguments;
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
CXErrorCode result;
|
|
|
|
auto ReparseTranslationUnitImpl = [=, &result]() {
|
|
|
|
result = clang_reparseTranslationUnit_Impl(
|
|
|
|
TU, llvm::makeArrayRef(unsaved_files, num_unsaved_files), options);
|
|
|
|
};
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
llvm::CrashRecoveryContext CRC;
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
if (!RunSafely(CRC, ReparseTranslationUnitImpl)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
fprintf(stderr, "libclang: crash detected during reparsing\n");
|
2013-01-27 02:53:38 +08:00
|
|
|
cxtu::getASTUnit(TU)->setUnsafeToFree(true);
|
2014-02-13 03:12:37 +08:00
|
|
|
return CXError_Crashed;
|
2012-12-18 22:30:41 +08:00
|
|
|
} else if (getenv("LIBCLANG_RESOURCE_USAGE"))
|
|
|
|
PrintLibclangResourceUsage(TU);
|
|
|
|
|
2014-07-08 06:42:03 +08:00
|
|
|
return result;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(CTUnit)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(CTUnit);
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2014-02-11 22:34:14 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(CXXUnit->getOriginalSourceFileName());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
2013-04-05 06:40:59 +08:00
|
|
|
return clang_getNullCursor();
|
2014-02-11 22:34:14 +08:00
|
|
|
}
|
2013-04-05 06:40:59 +08:00
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
|
|
|
|
}
|
|
|
|
|
2017-04-28 23:56:39 +08:00
|
|
|
CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit) {
|
|
|
|
if (isNotUsableTU(CTUnit)) {
|
|
|
|
LOG_BAD_TU(CTUnit);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXTargetInfoImpl* impl = new CXTargetInfoImpl();
|
|
|
|
impl->TranslationUnit = CTUnit;
|
|
|
|
return impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXString clang_TargetInfo_getTriple(CXTargetInfo TargetInfo) {
|
|
|
|
if (!TargetInfo)
|
|
|
|
return cxstring::createEmpty();
|
|
|
|
|
|
|
|
CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
|
|
|
|
assert(!isNotUsableTU(CTUnit) &&
|
|
|
|
"Unexpected unusable translation unit in TargetInfo");
|
|
|
|
|
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
|
|
|
|
std::string Triple =
|
|
|
|
CXXUnit->getASTContext().getTargetInfo().getTriple().normalize();
|
|
|
|
return cxstring::createDup(Triple);
|
|
|
|
}
|
|
|
|
|
|
|
|
int clang_TargetInfo_getPointerWidth(CXTargetInfo TargetInfo) {
|
|
|
|
if (!TargetInfo)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
|
|
|
|
assert(!isNotUsableTU(CTUnit) &&
|
|
|
|
"Unexpected unusable translation unit in TargetInfo");
|
|
|
|
|
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
|
|
|
|
return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_TargetInfo_dispose(CXTargetInfo TargetInfo) {
|
|
|
|
if (!TargetInfo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
delete TargetInfo;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CXFile Operations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
CXString clang_getFileName(CXFile SFile) {
|
|
|
|
if (!SFile)
|
2013-02-01 22:13:32 +08:00
|
|
|
return cxstring::createNull();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(FEnt->getName());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
time_t clang_getFileTime(CXFile SFile) {
|
|
|
|
if (!SFile)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
|
|
|
|
return FEnt->getModificationTime();
|
|
|
|
}
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
CXFile clang_getFile(CXTranslationUnit TU, const char *file_name) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2014-02-11 22:34:14 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
FileManager &FMgr = CXXUnit->getFileManager();
|
2019-08-02 05:31:56 +08:00
|
|
|
auto File = FMgr.getFile(file_name);
|
|
|
|
if (!File)
|
|
|
|
return nullptr;
|
|
|
|
return const_cast<FileEntry *>(*File);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2017-12-06 17:02:52 +08:00
|
|
|
const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
|
|
|
|
size_t *size) {
|
|
|
|
if (isNotUsableTU(TU)) {
|
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
|
|
|
|
FileID fid = SM.translateFile(static_cast<FileEntry *>(file));
|
|
|
|
bool Invalid = true;
|
2019-04-05 05:06:41 +08:00
|
|
|
const llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid);
|
2017-12-06 17:02:52 +08:00
|
|
|
if (Invalid) {
|
|
|
|
if (size)
|
|
|
|
*size = 0;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (size)
|
|
|
|
*size = buf->getBufferSize();
|
|
|
|
return buf->getBufferStart();
|
|
|
|
}
|
|
|
|
|
2014-02-11 22:34:14 +08:00
|
|
|
unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
|
|
|
|
CXFile file) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file)
|
2012-12-18 22:30:41 +08:00
|
|
|
return 0;
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
FileEntry *FEnt = static_cast<FileEntry *>(file);
|
|
|
|
return CXXUnit->getPreprocessor().getHeaderSearchInfo()
|
|
|
|
.isFileMultipleIncludeGuarded(FEnt);
|
|
|
|
}
|
|
|
|
|
2013-01-26 12:52:52 +08:00
|
|
|
int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID) {
|
|
|
|
if (!file || !outID)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
FileEntry *FEnt = static_cast<FileEntry *>(file);
|
2013-08-02 05:42:11 +08:00
|
|
|
const llvm::sys::fs::UniqueID &ID = FEnt->getUniqueID();
|
|
|
|
outID->data[0] = ID.getDevice();
|
|
|
|
outID->data[1] = ID.getFile();
|
2013-01-26 12:52:52 +08:00
|
|
|
outID->data[2] = FEnt->getModificationTime();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-16 08:26:19 +08:00
|
|
|
int clang_File_isEqual(CXFile file1, CXFile file2) {
|
|
|
|
if (file1 == file2)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!file1 || !file2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FileEntry *FEnt1 = static_cast<FileEntry *>(file1);
|
|
|
|
FileEntry *FEnt2 = static_cast<FileEntry *>(file2);
|
|
|
|
return FEnt1->getUniqueID() == FEnt2->getUniqueID();
|
|
|
|
}
|
|
|
|
|
2018-04-08 04:50:35 +08:00
|
|
|
CXString clang_File_tryGetRealPathName(CXFile SFile) {
|
|
|
|
if (!SFile)
|
|
|
|
return cxstring::createNull();
|
|
|
|
|
|
|
|
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
|
|
|
|
return cxstring::createRef(FEnt->tryGetRealPathName());
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CXCursor Operations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
static const Decl *getDeclFromExpr(const Stmt *E) {
|
|
|
|
if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return getDeclFromExpr(CE->getSubExpr());
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return RefExpr->getDecl();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const MemberExpr *ME = dyn_cast<MemberExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return ME->getMemberDecl();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCIvarRefExpr *RE = dyn_cast<ObjCIvarRefExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return RE->getDecl();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(E)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (PRE->isExplicitProperty())
|
|
|
|
return PRE->getExplicitProperty();
|
|
|
|
// It could be messaging both getter and setter as in:
|
|
|
|
// ++myobj.myprop;
|
|
|
|
// in which case prefer to associate the setter since it is less obvious
|
|
|
|
// from inspecting the source that the setter is going to get called.
|
|
|
|
if (PRE->isMessagingSetter())
|
|
|
|
return PRE->getImplicitPropertySetter();
|
|
|
|
return PRE->getImplicitPropertyGetter();
|
|
|
|
}
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return getDeclFromExpr(POE->getSyntacticForm());
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Expr *Src = OVE->getSourceExpr())
|
|
|
|
return getDeclFromExpr(Src);
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const CallExpr *CE = dyn_cast<CallExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return getDeclFromExpr(CE->getCallee());
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!CE->isElidable())
|
|
|
|
return CE->getConstructor();
|
P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:
Replace inheriting constructors implementation with new approach, voted into
C++ last year as a DR against C++11.
Instead of synthesizing a set of derived class constructors for each inherited
base class constructor, we make the constructors of the base class visible to
constructor lookup in the derived class, using the normal rules for
using-declarations.
For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived
class that tracks the requisite additional information. We create shadow
constructors (not found by name lookup) in the derived class to model the
actual initialization, and have a new expression node,
CXXInheritedCtorInitExpr, to model the initialization of a base class from such
a constructor. (This initialization is special because it performs real perfect
forwarding of arguments.)
In cases where argument forwarding is not possible (for inalloca calls,
variadic calls, and calls with callee parameter cleanup), the shadow inheriting
constructor is not emitted and instead we directly emit the initialization code
into the caller of the inherited constructor.
Note that this new model is not perfectly compatible with the old model in some
corner cases. In particular:
* if B inherits a private constructor from A, and C uses that constructor to
construct a B, then we previously required that A befriends B and B
befriends C, but the new rules require A to befriend C directly, and
* if a derived class has its own constructors (and so its implicit default
constructor is suppressed), it may still inherit a default constructor from
a base class
llvm-svn: 274049
2016-06-29 03:03:57 +08:00
|
|
|
if (const CXXInheritedCtorInitExpr *CE =
|
|
|
|
dyn_cast<CXXInheritedCtorInitExpr>(E))
|
|
|
|
return CE->getConstructor();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return OME->getMethodDecl();
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCProtocolExpr *PE = dyn_cast<ObjCProtocolExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return PE->getProtocol();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const SubstNonTypeTemplateParmPackExpr *NTTP
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast<SubstNonTypeTemplateParmPackExpr>(E))
|
|
|
|
return NTTP->getParameterPack();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (isa<NonTypeTemplateParmDecl>(SizeOfPack->getPack()) ||
|
|
|
|
isa<ParmVarDecl>(SizeOfPack->getPack()))
|
|
|
|
return SizeOfPack->getPack();
|
2014-06-08 16:38:04 +08:00
|
|
|
|
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
static SourceLocation getLocationFromExpr(const Expr *E) {
|
|
|
|
if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return getLocationFromExpr(CE->getSubExpr());
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return /*FIXME:*/Msg->getLeftLoc();
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return DRE->getLocation();
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const MemberExpr *Member = dyn_cast<MemberExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return Member->getMemberLoc();
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return Ivar->getLocation();
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return SizeOfPack->getPackLoc();
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const ObjCPropertyRefExpr *PropRef = dyn_cast<ObjCPropertyRefExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return PropRef->getLocation();
|
2018-08-10 05:08:08 +08:00
|
|
|
|
|
|
|
return E->getBeginLoc();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-12-20 00:50:43 +08:00
|
|
|
extern "C" {
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned clang_visitChildren(CXCursor parent,
|
|
|
|
CXCursorVisitor visitor,
|
|
|
|
CXClientData client_data) {
|
|
|
|
CursorVisitor CursorVis(getCursorTU(parent), visitor, client_data,
|
|
|
|
/*VisitPreprocessorLast=*/false);
|
|
|
|
return CursorVis.VisitChildren(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef __has_feature
|
|
|
|
#define __has_feature(x) 0
|
|
|
|
#endif
|
|
|
|
#if __has_feature(blocks)
|
|
|
|
typedef enum CXChildVisitResult
|
|
|
|
(^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
|
|
|
|
|
|
|
|
static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent,
|
|
|
|
CXClientData client_data) {
|
|
|
|
CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data;
|
|
|
|
return block(cursor, parent);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// If we are compiled with a compiler that doesn't have native blocks support,
|
|
|
|
// define and call the block manually, so the
|
|
|
|
typedef struct _CXChildVisitResult
|
|
|
|
{
|
|
|
|
void *isa;
|
|
|
|
int flags;
|
|
|
|
int reserved;
|
|
|
|
enum CXChildVisitResult(*invoke)(struct _CXChildVisitResult*, CXCursor,
|
|
|
|
CXCursor);
|
|
|
|
} *CXCursorVisitorBlock;
|
|
|
|
|
|
|
|
static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent,
|
|
|
|
CXClientData client_data) {
|
|
|
|
CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data;
|
|
|
|
return block->invoke(block, cursor, parent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
unsigned clang_visitChildrenWithBlock(CXCursor parent,
|
|
|
|
CXCursorVisitorBlock block) {
|
|
|
|
return clang_visitChildren(parent, visitWithBlock, block);
|
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
static CXString getDeclSpelling(const Decl *D) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const NamedDecl *ND = dyn_cast<NamedDecl>(D);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!ND) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCPropertyImplDecl *PropImpl =
|
|
|
|
dyn_cast<ObjCPropertyImplDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl())
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(Property->getIdentifier()->getName());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ImportDecl *ImportD = dyn_cast<ImportDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Module *Mod = ImportD->getImportedModule())
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(Mod->getFullModuleName());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND))
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(OMD->getSelector().getAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCCategoryImplDecl *CIMP = dyn_cast<ObjCCategoryImplDecl>(ND))
|
2012-12-18 22:30:41 +08:00
|
|
|
// No, this isn't the same as the code below. getIdentifier() is non-virtual
|
|
|
|
// and returns different names. NamedDecl returns the class name and
|
|
|
|
// ObjCCategoryImplDecl returns the category name.
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(CIMP->getIdentifier()->getNameStart());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (isa<UsingDirectiveDecl>(D))
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
SmallString<1024> S;
|
|
|
|
llvm::raw_svector_ostream os(S);
|
|
|
|
ND->printName(os);
|
|
|
|
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(os.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXString clang_getCursorSpelling(CXCursor C) {
|
|
|
|
if (clang_isTranslationUnit(C.kind))
|
2013-01-12 03:28:44 +08:00
|
|
|
return clang_getTranslationUnitSpelling(getCursorTU(C));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (clang_isReference(C.kind)) {
|
|
|
|
switch (C.kind) {
|
|
|
|
case CXCursor_ObjCSuperClassRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first;
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(Super->getIdentifier()->getNameStart());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
case CXCursor_ObjCClassRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(Class->getIdentifier()->getNameStart());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
case CXCursor_ObjCProtocolRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first;
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(OID && "getCursorSpelling(): Missing protocol decl");
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(OID->getIdentifier()->getNameStart());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
case CXCursor_CXXBaseSpecifier: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C);
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(B->getType().getAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
case CXCursor_TypeRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const TypeDecl *Type = getCursorTypeRef(C).first;
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(Type && "Missing type decl");
|
|
|
|
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(getCursorContext(C).getTypeDeclType(Type).
|
2012-12-18 22:30:41 +08:00
|
|
|
getAsString());
|
|
|
|
}
|
|
|
|
case CXCursor_TemplateRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const TemplateDecl *Template = getCursorTemplateRef(C).first;
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(Template && "Missing template decl");
|
|
|
|
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(Template->getNameAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_NamespaceRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const NamedDecl *NS = getCursorNamespaceRef(C).first;
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(NS && "Missing namespace decl");
|
|
|
|
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(NS->getNameAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_MemberRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const FieldDecl *Field = getCursorMemberRef(C).first;
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(Field && "Missing member decl");
|
|
|
|
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(Field->getNameAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_LabelRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const LabelStmt *Label = getCursorLabelRef(C).first;
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(Label && "Missing label");
|
|
|
|
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(Label->getName());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_OverloadedDeclRef: {
|
|
|
|
OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first;
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const Decl *D = Storage.dyn_cast<const Decl *>()) {
|
|
|
|
if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(ND->getNameAsString());
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(E->getName().getAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
OverloadedTemplateStorage *Ovl
|
|
|
|
= Storage.get<OverloadedTemplateStorage*>();
|
|
|
|
if (Ovl->size() == 0)
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup((*Ovl->begin())->getNameAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_VariableRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const VarDecl *Var = getCursorVariableRef(C).first;
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(Var && "Missing variable decl");
|
|
|
|
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(Var->getNameAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("<not implemented>");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isExpression(C.kind)) {
|
2014-03-04 03:40:52 +08:00
|
|
|
const Expr *E = getCursorExpr(C);
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_ObjCStringLiteral ||
|
|
|
|
C.kind == CXCursor_StringLiteral) {
|
|
|
|
const StringLiteral *SLit;
|
|
|
|
if (const ObjCStringLiteral *OSL = dyn_cast<ObjCStringLiteral>(E)) {
|
|
|
|
SLit = OSL->getString();
|
|
|
|
} else {
|
|
|
|
SLit = cast<StringLiteral>(E);
|
|
|
|
}
|
|
|
|
SmallString<256> Buf;
|
|
|
|
llvm::raw_svector_ostream OS(Buf);
|
|
|
|
SLit->outputString(OS);
|
|
|
|
return cxstring::createDup(OS.str());
|
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = getDeclFromExpr(getCursorExpr(C));
|
2012-12-18 22:30:41 +08:00
|
|
|
if (D)
|
|
|
|
return getDeclSpelling(D);
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isStatement(C.kind)) {
|
2013-01-26 23:29:08 +08:00
|
|
|
const Stmt *S = getCursorStmt(C);
|
|
|
|
if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(Label->getName());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroExpansion)
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(getCursorMacroExpansion(C).getName()
|
2012-12-18 22:30:41 +08:00
|
|
|
->getNameStart());
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroDefinition)
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(getCursorMacroDefinition(C)->getName()
|
2012-12-18 22:30:41 +08:00
|
|
|
->getNameStart());
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_InclusionDirective)
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(getCursorInclusionDirective(C)->getFileName());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (clang_isDeclaration(C.kind))
|
|
|
|
return getDeclSpelling(getCursorDecl(C));
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_AnnotateAttr) {
|
2013-01-27 02:08:08 +08:00
|
|
|
const AnnotateAttr *AA = cast<AnnotateAttr>(cxcursor::getCursorAttr(C));
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(AA->getAnnotation());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_AsmLabelAttr) {
|
2013-01-27 02:08:08 +08:00
|
|
|
const AsmLabelAttr *AA = cast<AsmLabelAttr>(cxcursor::getCursorAttr(C));
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(AA->getLabel());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-09-25 08:14:38 +08:00
|
|
|
if (C.kind == CXCursor_PackedAttr) {
|
|
|
|
return cxstring::createRef("packed");
|
|
|
|
}
|
|
|
|
|
2015-09-06 02:53:43 +08:00
|
|
|
if (C.kind == CXCursor_VisibilityAttr) {
|
|
|
|
const VisibilityAttr *AA = cast<VisibilityAttr>(cxcursor::getCursorAttr(C));
|
|
|
|
switch (AA->getVisibility()) {
|
|
|
|
case VisibilityAttr::VisibilityType::Default:
|
|
|
|
return cxstring::createRef("default");
|
|
|
|
case VisibilityAttr::VisibilityType::Hidden:
|
|
|
|
return cxstring::createRef("hidden");
|
|
|
|
case VisibilityAttr::VisibilityType::Protected:
|
|
|
|
return cxstring::createRef("protected");
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown visibility type");
|
|
|
|
}
|
|
|
|
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C,
|
|
|
|
unsigned pieceIndex,
|
|
|
|
unsigned options) {
|
|
|
|
if (clang_Cursor_isNull(C))
|
|
|
|
return clang_getNullRange();
|
|
|
|
|
|
|
|
ASTContext &Ctx = getCursorContext(C);
|
|
|
|
|
|
|
|
if (clang_isStatement(C.kind)) {
|
2013-01-26 23:29:08 +08:00
|
|
|
const Stmt *S = getCursorStmt(C);
|
|
|
|
if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (pieceIndex > 0)
|
|
|
|
return clang_getNullRange();
|
|
|
|
return cxloc::translateSourceRange(Ctx, Label->getIdentLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getNullRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_ObjCMessageExpr) {
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const ObjCMessageExpr *
|
2012-12-18 22:30:41 +08:00
|
|
|
ME = dyn_cast_or_null<ObjCMessageExpr>(getCursorExpr(C))) {
|
|
|
|
if (pieceIndex >= ME->getNumSelectorLocs())
|
|
|
|
return clang_getNullRange();
|
|
|
|
return cxloc::translateSourceRange(Ctx, ME->getSelectorLoc(pieceIndex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_ObjCInstanceMethodDecl ||
|
|
|
|
C.kind == CXCursor_ObjCClassMethodDecl) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCMethodDecl *
|
2012-12-18 22:30:41 +08:00
|
|
|
MD = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(C))) {
|
|
|
|
if (pieceIndex >= MD->getNumSelectorLocs())
|
|
|
|
return clang_getNullRange();
|
|
|
|
return cxloc::translateSourceRange(Ctx, MD->getSelectorLoc(pieceIndex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_ObjCCategoryDecl ||
|
|
|
|
C.kind == CXCursor_ObjCCategoryImplDecl) {
|
|
|
|
if (pieceIndex > 0)
|
|
|
|
return clang_getNullRange();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCCategoryDecl *
|
2012-12-18 22:30:41 +08:00
|
|
|
CD = dyn_cast_or_null<ObjCCategoryDecl>(getCursorDecl(C)))
|
|
|
|
return cxloc::translateSourceRange(Ctx, CD->getCategoryNameLoc());
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCCategoryImplDecl *
|
2012-12-18 22:30:41 +08:00
|
|
|
CID = dyn_cast_or_null<ObjCCategoryImplDecl>(getCursorDecl(C)))
|
|
|
|
return cxloc::translateSourceRange(Ctx, CID->getCategoryNameLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_ModuleImportDecl) {
|
|
|
|
if (pieceIndex > 0)
|
|
|
|
return clang_getNullRange();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ImportDecl *ImportD =
|
|
|
|
dyn_cast_or_null<ImportDecl>(getCursorDecl(C))) {
|
2012-12-18 22:30:41 +08:00
|
|
|
ArrayRef<SourceLocation> Locs = ImportD->getIdentifierLocs();
|
|
|
|
if (!Locs.empty())
|
|
|
|
return cxloc::translateSourceRange(Ctx,
|
|
|
|
SourceRange(Locs.front(), Locs.back()));
|
|
|
|
}
|
|
|
|
return clang_getNullRange();
|
|
|
|
}
|
|
|
|
|
2014-08-27 04:23:26 +08:00
|
|
|
if (C.kind == CXCursor_CXXMethod || C.kind == CXCursor_Destructor ||
|
2016-12-20 17:56:56 +08:00
|
|
|
C.kind == CXCursor_ConversionFunction ||
|
|
|
|
C.kind == CXCursor_FunctionDecl) {
|
2014-08-27 04:23:26 +08:00
|
|
|
if (pieceIndex > 0)
|
|
|
|
return clang_getNullRange();
|
|
|
|
if (const FunctionDecl *FD =
|
|
|
|
dyn_cast_or_null<FunctionDecl>(getCursorDecl(C))) {
|
|
|
|
DeclarationNameInfo FunctionName = FD->getNameInfo();
|
|
|
|
return cxloc::translateSourceRange(Ctx, FunctionName.getSourceRange());
|
|
|
|
}
|
|
|
|
return clang_getNullRange();
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// FIXME: A CXCursor_InclusionDirective should give the location of the
|
|
|
|
// filename, but we don't keep track of this.
|
|
|
|
|
|
|
|
// FIXME: A CXCursor_AnnotateAttr should give the location of the annotation
|
|
|
|
// but we don't keep track of this.
|
|
|
|
|
|
|
|
// FIXME: A CXCursor_AsmLabelAttr should give the location of the label
|
|
|
|
// but we don't keep track of this.
|
|
|
|
|
|
|
|
// Default handling, give the location of the cursor.
|
|
|
|
|
|
|
|
if (pieceIndex > 0)
|
|
|
|
return clang_getNullRange();
|
|
|
|
|
|
|
|
CXSourceLocation CXLoc = clang_getCursorLocation(C);
|
|
|
|
SourceLocation Loc = cxloc::translateSourceLocation(CXLoc);
|
|
|
|
return cxloc::translateSourceRange(Ctx, Loc);
|
|
|
|
}
|
|
|
|
|
2014-08-01 02:04:56 +08:00
|
|
|
CXString clang_Cursor_getMangling(CXCursor C) {
|
|
|
|
if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
|
|
|
|
return cxstring::createEmpty();
|
|
|
|
|
|
|
|
// Mangling only works for functions and variables.
|
2014-08-01 23:01:10 +08:00
|
|
|
const Decl *D = getCursorDecl(C);
|
2014-08-01 02:04:56 +08:00
|
|
|
if (!D || !(isa<FunctionDecl>(D) || isa<VarDecl>(D)))
|
|
|
|
return cxstring::createEmpty();
|
|
|
|
|
2016-02-15 06:30:14 +08:00
|
|
|
ASTContext &Ctx = D->getASTContext();
|
|
|
|
index::CodegenNameGenerator CGNameGen(Ctx);
|
|
|
|
return cxstring::createDup(CGNameGen.getName(D));
|
2014-08-01 02:04:56 +08:00
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:22 +08:00
|
|
|
CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) {
|
|
|
|
if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D)))
|
|
|
|
return nullptr;
|
|
|
|
|
2016-02-15 06:30:14 +08:00
|
|
|
ASTContext &Ctx = D->getASTContext();
|
|
|
|
index::CodegenNameGenerator CGNameGen(Ctx);
|
|
|
|
std::vector<std::string> Manglings = CGNameGen.getAllManglings(D);
|
2017-09-23 00:58:57 +08:00
|
|
|
return cxstring::createSet(Manglings);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXStringSet *clang_Cursor_getObjCManglings(CXCursor C) {
|
|
|
|
if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
if (!(isa<ObjCInterfaceDecl>(D) || isa<ObjCImplementationDecl>(D)))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
ASTContext &Ctx = D->getASTContext();
|
|
|
|
index::CodegenNameGenerator CGNameGen(Ctx);
|
|
|
|
std::vector<std::string> Manglings = CGNameGen.getAllManglings(D);
|
2015-11-12 11:57:22 +08:00
|
|
|
return cxstring::createSet(Manglings);
|
|
|
|
}
|
|
|
|
|
2018-01-16 18:19:56 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXString clang_getCursorDisplayName(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return clang_getCursorSpelling(C);
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = getCursorDecl(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
PrintingPolicy Policy = getCursorContext(C).getPrintingPolicy();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
D = FunTmpl->getTemplatedDecl();
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
SmallString<64> Str;
|
|
|
|
llvm::raw_svector_ostream OS(Str);
|
|
|
|
OS << *Function;
|
|
|
|
if (Function->getPrimaryTemplate())
|
|
|
|
OS << "<>";
|
|
|
|
OS << "(";
|
|
|
|
for (unsigned I = 0, N = Function->getNumParams(); I != N; ++I) {
|
|
|
|
if (I)
|
|
|
|
OS << ", ";
|
|
|
|
OS << Function->getParamDecl(I)->getType().getAsString(Policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Function->isVariadic()) {
|
|
|
|
if (Function->getNumParams())
|
|
|
|
OS << ", ";
|
|
|
|
OS << "...";
|
|
|
|
}
|
|
|
|
OS << ")";
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(OS.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
SmallString<64> Str;
|
|
|
|
llvm::raw_svector_ostream OS(Str);
|
|
|
|
OS << *ClassTemplate;
|
|
|
|
OS << "<";
|
|
|
|
TemplateParameterList *Params = ClassTemplate->getTemplateParameters();
|
|
|
|
for (unsigned I = 0, N = Params->size(); I != N; ++I) {
|
|
|
|
if (I)
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
NamedDecl *Param = Params->getParam(I);
|
|
|
|
if (Param->getIdentifier()) {
|
|
|
|
OS << Param->getIdentifier()->getName();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is no parameter name, which makes this tricky. Try to come up
|
|
|
|
// with something useful that isn't too long.
|
|
|
|
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
|
|
|
|
OS << (TTP->wasDeclaredWithTypename()? "typename" : "class");
|
|
|
|
else if (NonTypeTemplateParmDecl *NTTP
|
|
|
|
= dyn_cast<NonTypeTemplateParmDecl>(Param))
|
|
|
|
OS << NTTP->getType().getAsString(Policy);
|
|
|
|
else
|
|
|
|
OS << "template<...> class";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << ">";
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(OS.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ClassTemplateSpecializationDecl *ClassSpec
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(D)) {
|
|
|
|
// If the type was explicitly written, use that.
|
|
|
|
if (TypeSourceInfo *TSInfo = ClassSpec->getTypeAsWritten())
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(TSInfo->getType().getAsString(Policy));
|
2017-11-29 00:14:14 +08:00
|
|
|
|
2013-02-22 23:46:01 +08:00
|
|
|
SmallString<128> Str;
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::raw_svector_ostream OS(Str);
|
|
|
|
OS << *ClassSpec;
|
2017-11-29 00:14:14 +08:00
|
|
|
printTemplateArgumentList(OS, ClassSpec->getTemplateArgs().asArray(),
|
|
|
|
Policy);
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(OS.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getCursorSpelling(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
|
|
|
|
switch (Kind) {
|
|
|
|
case CXCursor_FunctionDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("FunctionDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_TypedefDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("TypedefDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_EnumDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("EnumDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_EnumConstantDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("EnumConstantDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_StructDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("StructDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UnionDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UnionDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ClassDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ClassDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_FieldDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("FieldDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_VarDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("VarDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ParmDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ParmDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCInterfaceDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCInterfaceDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCCategoryDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCCategoryDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCProtocolDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCProtocolDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCPropertyDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCPropertyDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCIvarDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCIvarDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCInstanceMethodDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCInstanceMethodDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCClassMethodDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCClassMethodDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCImplementationDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCImplementationDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCCategoryImplDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCCategoryImplDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXMethod:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXMethod");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UnexposedDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UnexposedDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCSuperClassRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCSuperClassRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCProtocolRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCProtocolRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCClassRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCClassRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_TypeRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("TypeRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_TemplateRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("TemplateRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_NamespaceRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("NamespaceRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_MemberRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("MemberRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_LabelRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("LabelRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_OverloadedDeclRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("OverloadedDeclRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_VariableRef:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("VariableRef");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_IntegerLiteral:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("IntegerLiteral");
|
2018-06-21 01:19:40 +08:00
|
|
|
case CXCursor_FixedPointLiteral:
|
|
|
|
return cxstring::createRef("FixedPointLiteral");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_FloatingLiteral:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("FloatingLiteral");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ImaginaryLiteral:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ImaginaryLiteral");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_StringLiteral:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("StringLiteral");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CharacterLiteral:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CharacterLiteral");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ParenExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ParenExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UnaryOperator:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UnaryOperator");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ArraySubscriptExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ArraySubscriptExpr");
|
2015-08-25 22:24:04 +08:00
|
|
|
case CXCursor_OMPArraySectionExpr:
|
|
|
|
return cxstring::createRef("OMPArraySectionExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_BinaryOperator:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("BinaryOperator");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CompoundAssignOperator:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CompoundAssignOperator");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ConditionalOperator:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ConditionalOperator");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CStyleCastExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CStyleCastExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CompoundLiteralExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CompoundLiteralExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_InitListExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("InitListExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_AddrLabelExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("AddrLabelExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_StmtExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("StmtExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_GenericSelectionExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("GenericSelectionExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_GNUNullExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("GNUNullExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXStaticCastExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXStaticCastExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXDynamicCastExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXDynamicCastExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXReinterpretCastExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXReinterpretCastExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXConstCastExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXConstCastExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXFunctionalCastExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXFunctionalCastExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXTypeidExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXTypeidExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXBoolLiteralExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXBoolLiteralExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXNullPtrLiteralExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXNullPtrLiteralExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXThisExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXThisExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXThrowExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXThrowExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXNewExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXNewExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXDeleteExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXDeleteExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UnaryExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UnaryExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCStringLiteral:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCStringLiteral");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCBoolLiteralExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCBoolLiteralExpr");
|
2016-07-16 08:35:23 +08:00
|
|
|
case CXCursor_ObjCAvailabilityCheckExpr:
|
|
|
|
return cxstring::createRef("ObjCAvailabilityCheckExpr");
|
2013-04-24 01:57:17 +08:00
|
|
|
case CXCursor_ObjCSelfExpr:
|
|
|
|
return cxstring::createRef("ObjCSelfExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCEncodeExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCEncodeExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCSelectorExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCSelectorExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCProtocolExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCProtocolExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCBridgedCastExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCBridgedCastExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_BlockExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("BlockExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_PackExpansionExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("PackExpansionExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_SizeOfPackExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("SizeOfPackExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_LambdaExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("LambdaExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UnexposedExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UnexposedExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_DeclRefExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("DeclRefExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_MemberRefExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("MemberRefExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CallExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CallExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCMessageExpr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCMessageExpr");
|
2019-07-03 02:28:13 +08:00
|
|
|
case CXCursor_BuiltinBitCastExpr:
|
|
|
|
return cxstring::createRef("BuiltinBitCastExpr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UnexposedStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UnexposedStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_DeclStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("DeclStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_LabelStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("LabelStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CompoundStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CompoundStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CaseStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CaseStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_DefaultStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("DefaultStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_IfStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("IfStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_SwitchStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("SwitchStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_WhileStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("WhileStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_DoStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("DoStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ForStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ForStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_GotoStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("GotoStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_IndirectGotoStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("IndirectGotoStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ContinueStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ContinueStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_BreakStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("BreakStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ReturnStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ReturnStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_GCCAsmStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("GCCAsmStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_MSAsmStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("MSAsmStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCAtTryStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCAtTryStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCAtCatchStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCAtCatchStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCAtFinallyStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCAtFinallyStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCAtThrowStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCAtThrowStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCAtSynchronizedStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCAtSynchronizedStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCAutoreleasePoolStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCAutoreleasePoolStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCForCollectionStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCForCollectionStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXCatchStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXCatchStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXTryStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXTryStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXForRangeStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXForRangeStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_SEHTryStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("SEHTryStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_SEHExceptStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("SEHExceptStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_SEHFinallyStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("SEHFinallyStmt");
|
2014-07-07 08:12:30 +08:00
|
|
|
case CXCursor_SEHLeaveStmt:
|
|
|
|
return cxstring::createRef("SEHLeaveStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_NullStmt:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("NullStmt");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_InvalidFile:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("InvalidFile");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_InvalidCode:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("InvalidCode");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_NoDeclFound:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("NoDeclFound");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_NotImplemented:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("NotImplemented");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_TranslationUnit:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("TranslationUnit");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UnexposedAttr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UnexposedAttr");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_IBActionAttr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("attribute(ibaction)");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_IBOutletAttr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("attribute(iboutlet)");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_IBOutletCollectionAttr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("attribute(iboutletcollection)");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXFinalAttr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("attribute(final)");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXOverrideAttr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("attribute(override)");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_AnnotateAttr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("attribute(annotate)");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_AsmLabelAttr:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("asm label");
|
2013-09-25 08:14:38 +08:00
|
|
|
case CXCursor_PackedAttr:
|
|
|
|
return cxstring::createRef("attribute(packed)");
|
2014-05-01 23:41:58 +08:00
|
|
|
case CXCursor_PureAttr:
|
|
|
|
return cxstring::createRef("attribute(pure)");
|
|
|
|
case CXCursor_ConstAttr:
|
|
|
|
return cxstring::createRef("attribute(const)");
|
|
|
|
case CXCursor_NoDuplicateAttr:
|
|
|
|
return cxstring::createRef("attribute(noduplicate)");
|
2014-05-29 03:29:58 +08:00
|
|
|
case CXCursor_CUDAConstantAttr:
|
|
|
|
return cxstring::createRef("attribute(constant)");
|
|
|
|
case CXCursor_CUDADeviceAttr:
|
|
|
|
return cxstring::createRef("attribute(device)");
|
|
|
|
case CXCursor_CUDAGlobalAttr:
|
|
|
|
return cxstring::createRef("attribute(global)");
|
|
|
|
case CXCursor_CUDAHostAttr:
|
|
|
|
return cxstring::createRef("attribute(host)");
|
2014-08-08 22:59:00 +08:00
|
|
|
case CXCursor_CUDASharedAttr:
|
|
|
|
return cxstring::createRef("attribute(shared)");
|
2015-09-06 02:53:43 +08:00
|
|
|
case CXCursor_VisibilityAttr:
|
|
|
|
return cxstring::createRef("attribute(visibility)");
|
2015-12-11 02:45:18 +08:00
|
|
|
case CXCursor_DLLExport:
|
|
|
|
return cxstring::createRef("attribute(dllexport)");
|
|
|
|
case CXCursor_DLLImport:
|
|
|
|
return cxstring::createRef("attribute(dllimport)");
|
2018-08-03 13:03:22 +08:00
|
|
|
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)");
|
2018-08-03 13:55:40 +08:00
|
|
|
case CXCursor_FlagEnum:
|
|
|
|
return cxstring::createRef("attribute(flag_enum)");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_PreprocessingDirective:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("preprocessing directive");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_MacroDefinition:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("macro definition");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_MacroExpansion:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("macro expansion");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_InclusionDirective:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("inclusion directive");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_Namespace:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("Namespace");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_LinkageSpec:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("LinkageSpec");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXBaseSpecifier:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("C++ base class specifier");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_Constructor:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXConstructor");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_Destructor:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXDestructor");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ConversionFunction:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXConversion");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_TemplateTypeParameter:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("TemplateTypeParameter");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_NonTypeTemplateParameter:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("NonTypeTemplateParameter");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_TemplateTemplateParameter:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("TemplateTemplateParameter");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_FunctionTemplate:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("FunctionTemplate");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ClassTemplate:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ClassTemplate");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ClassTemplatePartialSpecialization:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ClassTemplatePartialSpecialization");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_NamespaceAlias:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("NamespaceAlias");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UsingDirective:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UsingDirective");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_UsingDeclaration:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("UsingDeclaration");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_TypeAliasDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("TypeAliasDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCSynthesizeDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCSynthesizeDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ObjCDynamicDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ObjCDynamicDecl");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_CXXAccessSpecifier:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("CXXAccessSpecifier");
|
2012-12-18 22:30:41 +08:00
|
|
|
case CXCursor_ModuleImportDecl:
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef("ModuleImport");
|
2013-07-19 11:13:43 +08:00
|
|
|
case CXCursor_OMPParallelDirective:
|
2014-02-27 16:29:12 +08:00
|
|
|
return cxstring::createRef("OMPParallelDirective");
|
|
|
|
case CXCursor_OMPSimdDirective:
|
|
|
|
return cxstring::createRef("OMPSimdDirective");
|
2014-06-18 12:14:57 +08:00
|
|
|
case CXCursor_OMPForDirective:
|
|
|
|
return cxstring::createRef("OMPForDirective");
|
2014-09-18 13:12:34 +08:00
|
|
|
case CXCursor_OMPForSimdDirective:
|
|
|
|
return cxstring::createRef("OMPForSimdDirective");
|
2014-06-25 19:44:49 +08:00
|
|
|
case CXCursor_OMPSectionsDirective:
|
|
|
|
return cxstring::createRef("OMPSectionsDirective");
|
2014-06-26 16:21:58 +08:00
|
|
|
case CXCursor_OMPSectionDirective:
|
|
|
|
return cxstring::createRef("OMPSectionDirective");
|
2014-06-26 20:05:45 +08:00
|
|
|
case CXCursor_OMPSingleDirective:
|
|
|
|
return cxstring::createRef("OMPSingleDirective");
|
2014-07-17 16:54:58 +08:00
|
|
|
case CXCursor_OMPMasterDirective:
|
|
|
|
return cxstring::createRef("OMPMasterDirective");
|
2014-07-21 17:42:05 +08:00
|
|
|
case CXCursor_OMPCriticalDirective:
|
|
|
|
return cxstring::createRef("OMPCriticalDirective");
|
2014-07-07 21:01:15 +08:00
|
|
|
case CXCursor_OMPParallelForDirective:
|
|
|
|
return cxstring::createRef("OMPParallelForDirective");
|
2014-09-23 17:33:00 +08:00
|
|
|
case CXCursor_OMPParallelForSimdDirective:
|
|
|
|
return cxstring::createRef("OMPParallelForSimdDirective");
|
2014-07-08 16:12:03 +08:00
|
|
|
case CXCursor_OMPParallelSectionsDirective:
|
|
|
|
return cxstring::createRef("OMPParallelSectionsDirective");
|
2014-07-11 19:25:16 +08:00
|
|
|
case CXCursor_OMPTaskDirective:
|
|
|
|
return cxstring::createRef("OMPTaskDirective");
|
2014-07-18 15:47:19 +08:00
|
|
|
case CXCursor_OMPTaskyieldDirective:
|
|
|
|
return cxstring::createRef("OMPTaskyieldDirective");
|
2014-07-18 17:11:51 +08:00
|
|
|
case CXCursor_OMPBarrierDirective:
|
|
|
|
return cxstring::createRef("OMPBarrierDirective");
|
2014-07-18 18:17:07 +08:00
|
|
|
case CXCursor_OMPTaskwaitDirective:
|
|
|
|
return cxstring::createRef("OMPTaskwaitDirective");
|
2015-06-18 20:14:09 +08:00
|
|
|
case CXCursor_OMPTaskgroupDirective:
|
|
|
|
return cxstring::createRef("OMPTaskgroupDirective");
|
2014-07-21 19:26:11 +08:00
|
|
|
case CXCursor_OMPFlushDirective:
|
|
|
|
return cxstring::createRef("OMPFlushDirective");
|
2014-07-22 14:45:04 +08:00
|
|
|
case CXCursor_OMPOrderedDirective:
|
|
|
|
return cxstring::createRef("OMPOrderedDirective");
|
2014-07-22 18:10:35 +08:00
|
|
|
case CXCursor_OMPAtomicDirective:
|
|
|
|
return cxstring::createRef("OMPAtomicDirective");
|
2014-09-19 16:19:49 +08:00
|
|
|
case CXCursor_OMPTargetDirective:
|
|
|
|
return cxstring::createRef("OMPTargetDirective");
|
2015-07-21 21:44:28 +08:00
|
|
|
case CXCursor_OMPTargetDataDirective:
|
|
|
|
return cxstring::createRef("OMPTargetDataDirective");
|
2016-01-20 03:15:56 +08:00
|
|
|
case CXCursor_OMPTargetEnterDataDirective:
|
|
|
|
return cxstring::createRef("OMPTargetEnterDataDirective");
|
2016-01-20 04:04:50 +08:00
|
|
|
case CXCursor_OMPTargetExitDataDirective:
|
|
|
|
return cxstring::createRef("OMPTargetExitDataDirective");
|
2016-01-27 02:48:41 +08:00
|
|
|
case CXCursor_OMPTargetParallelDirective:
|
|
|
|
return cxstring::createRef("OMPTargetParallelDirective");
|
2016-02-03 23:46:42 +08:00
|
|
|
case CXCursor_OMPTargetParallelForDirective:
|
|
|
|
return cxstring::createRef("OMPTargetParallelForDirective");
|
2016-05-27 01:30:50 +08:00
|
|
|
case CXCursor_OMPTargetUpdateDirective:
|
|
|
|
return cxstring::createRef("OMPTargetUpdateDirective");
|
2014-10-09 12:18:56 +08:00
|
|
|
case CXCursor_OMPTeamsDirective:
|
|
|
|
return cxstring::createRef("OMPTeamsDirective");
|
2015-07-01 14:57:41 +08:00
|
|
|
case CXCursor_OMPCancellationPointDirective:
|
|
|
|
return cxstring::createRef("OMPCancellationPointDirective");
|
2015-07-02 19:25:17 +08:00
|
|
|
case CXCursor_OMPCancelDirective:
|
|
|
|
return cxstring::createRef("OMPCancelDirective");
|
2015-12-01 12:18:41 +08:00
|
|
|
case CXCursor_OMPTaskLoopDirective:
|
|
|
|
return cxstring::createRef("OMPTaskLoopDirective");
|
2015-12-03 17:40:15 +08:00
|
|
|
case CXCursor_OMPTaskLoopSimdDirective:
|
|
|
|
return cxstring::createRef("OMPTaskLoopSimdDirective");
|
2015-12-14 22:51:25 +08:00
|
|
|
case CXCursor_OMPDistributeDirective:
|
|
|
|
return cxstring::createRef("OMPDistributeDirective");
|
2016-06-27 22:55:37 +08:00
|
|
|
case CXCursor_OMPDistributeParallelForDirective:
|
|
|
|
return cxstring::createRef("OMPDistributeParallelForDirective");
|
2016-07-05 13:00:15 +08:00
|
|
|
case CXCursor_OMPDistributeParallelForSimdDirective:
|
|
|
|
return cxstring::createRef("OMPDistributeParallelForSimdDirective");
|
2016-07-06 12:45:38 +08:00
|
|
|
case CXCursor_OMPDistributeSimdDirective:
|
|
|
|
return cxstring::createRef("OMPDistributeSimdDirective");
|
2016-07-14 10:54:56 +08:00
|
|
|
case CXCursor_OMPTargetParallelForSimdDirective:
|
|
|
|
return cxstring::createRef("OMPTargetParallelForSimdDirective");
|
2016-07-21 06:57:10 +08:00
|
|
|
case CXCursor_OMPTargetSimdDirective:
|
|
|
|
return cxstring::createRef("OMPTargetSimdDirective");
|
2016-08-05 22:37:37 +08:00
|
|
|
case CXCursor_OMPTeamsDistributeDirective:
|
|
|
|
return cxstring::createRef("OMPTeamsDistributeDirective");
|
2016-10-25 20:50:55 +08:00
|
|
|
case CXCursor_OMPTeamsDistributeSimdDirective:
|
|
|
|
return cxstring::createRef("OMPTeamsDistributeSimdDirective");
|
2016-12-01 07:51:03 +08:00
|
|
|
case CXCursor_OMPTeamsDistributeParallelForSimdDirective:
|
|
|
|
return cxstring::createRef("OMPTeamsDistributeParallelForSimdDirective");
|
2016-12-09 11:24:30 +08:00
|
|
|
case CXCursor_OMPTeamsDistributeParallelForDirective:
|
|
|
|
return cxstring::createRef("OMPTeamsDistributeParallelForDirective");
|
2016-12-17 13:48:59 +08:00
|
|
|
case CXCursor_OMPTargetTeamsDirective:
|
|
|
|
return cxstring::createRef("OMPTargetTeamsDirective");
|
2016-12-25 12:52:54 +08:00
|
|
|
case CXCursor_OMPTargetTeamsDistributeDirective:
|
|
|
|
return cxstring::createRef("OMPTargetTeamsDistributeDirective");
|
2016-12-30 06:16:30 +08:00
|
|
|
case CXCursor_OMPTargetTeamsDistributeParallelForDirective:
|
|
|
|
return cxstring::createRef("OMPTargetTeamsDistributeParallelForDirective");
|
2017-01-03 13:23:48 +08:00
|
|
|
case CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective:
|
|
|
|
return cxstring::createRef(
|
|
|
|
"OMPTargetTeamsDistributeParallelForSimdDirective");
|
2017-01-11 02:08:18 +08:00
|
|
|
case CXCursor_OMPTargetTeamsDistributeSimdDirective:
|
|
|
|
return cxstring::createRef("OMPTargetTeamsDistributeSimdDirective");
|
2015-01-22 00:24:11 +08:00
|
|
|
case CXCursor_OverloadCandidate:
|
|
|
|
return cxstring::createRef("OverloadCandidate");
|
2015-11-15 21:48:32 +08:00
|
|
|
case CXCursor_TypeAliasTemplateDecl:
|
|
|
|
return cxstring::createRef("TypeAliasTemplateDecl");
|
2016-06-10 00:15:55 +08:00
|
|
|
case CXCursor_StaticAssert:
|
|
|
|
return cxstring::createRef("StaticAssert");
|
2016-11-04 14:29:27 +08:00
|
|
|
case CXCursor_FriendDecl:
|
2019-02-11 19:00:56 +08:00
|
|
|
return cxstring::createRef("FriendDecl");
|
|
|
|
case CXCursor_ConvergentAttr:
|
|
|
|
return cxstring::createRef("attribute(convergent)");
|
2019-02-26 05:24:52 +08:00
|
|
|
case CXCursor_WarnUnusedAttr:
|
|
|
|
return cxstring::createRef("attribute(warn_unused)");
|
|
|
|
case CXCursor_WarnUnusedResultAttr:
|
|
|
|
return cxstring::createRef("attribute(warn_unused_result)");
|
2019-03-14 00:16:54 +08:00
|
|
|
case CXCursor_AlignedAttr:
|
|
|
|
return cxstring::createRef("attribute(aligned)");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Unhandled CXCursorKind");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct GetCursorData {
|
|
|
|
SourceLocation TokenBeginLoc;
|
|
|
|
bool PointsAtMacroArgExpansion;
|
|
|
|
bool VisitedObjCPropertyImplDecl;
|
|
|
|
SourceLocation VisitedDeclaratorDeclStartLoc;
|
|
|
|
CXCursor &BestCursor;
|
|
|
|
|
|
|
|
GetCursorData(SourceManager &SM,
|
|
|
|
SourceLocation tokenBegin, CXCursor &outputCursor)
|
|
|
|
: TokenBeginLoc(tokenBegin), BestCursor(outputCursor) {
|
|
|
|
PointsAtMacroArgExpansion = SM.isMacroArgExpansion(tokenBegin);
|
|
|
|
VisitedObjCPropertyImplDecl = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum CXChildVisitResult GetCursorVisitor(CXCursor cursor,
|
|
|
|
CXCursor parent,
|
|
|
|
CXClientData client_data) {
|
|
|
|
GetCursorData *Data = static_cast<GetCursorData *>(client_data);
|
|
|
|
CXCursor *BestCursor = &Data->BestCursor;
|
|
|
|
|
|
|
|
// If we point inside a macro argument we should provide info of what the
|
|
|
|
// token is so use the actual cursor, don't replace it with a macro expansion
|
|
|
|
// cursor.
|
|
|
|
if (cursor.kind == CXCursor_MacroExpansion && Data->PointsAtMacroArgExpansion)
|
|
|
|
return CXChildVisit_Recurse;
|
|
|
|
|
|
|
|
if (clang_isDeclaration(cursor.kind)) {
|
|
|
|
// Avoid having the implicit methods override the property decls.
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCMethodDecl *MD
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(cursor))) {
|
|
|
|
if (MD->isImplicit())
|
|
|
|
return CXChildVisit_Break;
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
} else if (const ObjCInterfaceDecl *ID
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<ObjCInterfaceDecl>(getCursorDecl(cursor))) {
|
|
|
|
// Check that when we have multiple @class references in the same line,
|
|
|
|
// that later ones do not override the previous ones.
|
|
|
|
// If we have:
|
|
|
|
// @class Foo, Bar;
|
|
|
|
// source ranges for both start at '@', so 'Bar' will end up overriding
|
|
|
|
// 'Foo' even though the cursor location was at 'Foo'.
|
|
|
|
if (BestCursor->kind == CXCursor_ObjCInterfaceDecl ||
|
|
|
|
BestCursor->kind == CXCursor_ObjCClassRef)
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCInterfaceDecl *PrevID
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<ObjCInterfaceDecl>(getCursorDecl(*BestCursor))){
|
|
|
|
if (PrevID != ID &&
|
|
|
|
!PrevID->isThisDeclarationADefinition() &&
|
|
|
|
!ID->isThisDeclarationADefinition())
|
|
|
|
return CXChildVisit_Break;
|
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
} else if (const DeclaratorDecl *DD
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<DeclaratorDecl>(getCursorDecl(cursor))) {
|
|
|
|
SourceLocation StartLoc = DD->getSourceRange().getBegin();
|
|
|
|
// Check that when we have multiple declarators in the same line,
|
|
|
|
// that later ones do not override the previous ones.
|
|
|
|
// If we have:
|
|
|
|
// int Foo, Bar;
|
|
|
|
// source ranges for both start at 'int', so 'Bar' will end up overriding
|
|
|
|
// 'Foo' even though the cursor location was at 'Foo'.
|
|
|
|
if (Data->VisitedDeclaratorDeclStartLoc == StartLoc)
|
|
|
|
return CXChildVisit_Break;
|
|
|
|
Data->VisitedDeclaratorDeclStartLoc = StartLoc;
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
} else if (const ObjCPropertyImplDecl *PropImp
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<ObjCPropertyImplDecl>(getCursorDecl(cursor))) {
|
|
|
|
(void)PropImp;
|
|
|
|
// Check that when we have multiple @synthesize in the same line,
|
|
|
|
// that later ones do not override the previous ones.
|
|
|
|
// If we have:
|
|
|
|
// @synthesize Foo, Bar;
|
|
|
|
// source ranges for both start at '@', so 'Bar' will end up overriding
|
|
|
|
// 'Foo' even though the cursor location was at 'Foo'.
|
|
|
|
if (Data->VisitedObjCPropertyImplDecl)
|
|
|
|
return CXChildVisit_Break;
|
|
|
|
Data->VisitedObjCPropertyImplDecl = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isExpression(cursor.kind) &&
|
|
|
|
clang_isDeclaration(BestCursor->kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const Decl *D = getCursorDecl(*BestCursor)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Avoid having the cursor of an expression replace the declaration cursor
|
|
|
|
// when the expression source range overlaps the declaration range.
|
|
|
|
// This can happen for C++ constructor expressions whose range generally
|
|
|
|
// include the variable declaration, e.g.:
|
|
|
|
// MyCXXClass foo; // Make sure pointing at 'foo' returns a VarDecl cursor.
|
|
|
|
if (D->getLocation().isValid() && Data->TokenBeginLoc.isValid() &&
|
|
|
|
D->getLocation() == Data->TokenBeginLoc)
|
|
|
|
return CXChildVisit_Break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If our current best cursor is the construction of a temporary object,
|
|
|
|
// don't replace that cursor with a type reference, because we want
|
|
|
|
// clang_getCursor() to point at the constructor.
|
|
|
|
if (clang_isExpression(BestCursor->kind) &&
|
|
|
|
isa<CXXTemporaryObjectExpr>(getCursorExpr(*BestCursor)) &&
|
|
|
|
cursor.kind == CXCursor_TypeRef) {
|
|
|
|
// Keep the cursor pointing at CXXTemporaryObjectExpr but also mark it
|
|
|
|
// as having the actual point on the type reference.
|
|
|
|
*BestCursor = getTypeRefedCallExprCursor(*BestCursor);
|
|
|
|
return CXChildVisit_Recurse;
|
|
|
|
}
|
2015-07-07 11:57:35 +08:00
|
|
|
|
|
|
|
// If we already have an Objective-C superclass reference, don't
|
|
|
|
// update it further.
|
|
|
|
if (BestCursor->kind == CXCursor_ObjCSuperClassRef)
|
|
|
|
return CXChildVisit_Break;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
*BestCursor = cursor;
|
|
|
|
return CXChildVisit_Recurse;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
return clang_getNullCursor();
|
2014-02-11 22:34:14 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
|
|
|
|
|
|
|
SourceLocation SLoc = cxloc::translateSourceLocation(Loc);
|
|
|
|
CXCursor Result = cxcursor::getCursor(TU, SLoc);
|
|
|
|
|
2013-01-11 02:54:52 +08:00
|
|
|
LOG_FUNC_SECTION {
|
2012-12-18 22:30:41 +08:00
|
|
|
CXFile SearchFile;
|
|
|
|
unsigned SearchLine, SearchColumn;
|
|
|
|
CXFile ResultFile;
|
|
|
|
unsigned ResultLine, ResultColumn;
|
|
|
|
CXString SearchFileName, ResultFileName, KindSpelling, USR;
|
|
|
|
const char *IsDef = clang_isCursorDefinition(Result)? " (Definition)" : "";
|
|
|
|
CXSourceLocation ResultLoc = clang_getCursorLocation(Result);
|
2014-06-08 16:38:04 +08:00
|
|
|
|
|
|
|
clang_getFileLocation(Loc, &SearchFile, &SearchLine, &SearchColumn,
|
|
|
|
nullptr);
|
2013-01-11 02:54:52 +08:00
|
|
|
clang_getFileLocation(ResultLoc, &ResultFile, &ResultLine,
|
2014-06-08 16:38:04 +08:00
|
|
|
&ResultColumn, nullptr);
|
2012-12-18 22:30:41 +08:00
|
|
|
SearchFileName = clang_getFileName(SearchFile);
|
|
|
|
ResultFileName = clang_getFileName(ResultFile);
|
|
|
|
KindSpelling = clang_getCursorKindSpelling(Result.kind);
|
|
|
|
USR = clang_getCursorUSR(Result);
|
2013-01-11 02:54:52 +08:00
|
|
|
*Log << llvm::format("(%s:%d:%d) = %s",
|
|
|
|
clang_getCString(SearchFileName), SearchLine, SearchColumn,
|
|
|
|
clang_getCString(KindSpelling))
|
|
|
|
<< llvm::format("(%s:%d:%d):%s%s",
|
|
|
|
clang_getCString(ResultFileName), ResultLine, ResultColumn,
|
|
|
|
clang_getCString(USR), IsDef);
|
2012-12-18 22:30:41 +08:00
|
|
|
clang_disposeString(SearchFileName);
|
|
|
|
clang_disposeString(ResultFileName);
|
|
|
|
clang_disposeString(KindSpelling);
|
|
|
|
clang_disposeString(USR);
|
|
|
|
|
|
|
|
CXCursor Definition = clang_getCursorDefinition(Result);
|
|
|
|
if (!clang_equalCursors(Definition, clang_getNullCursor())) {
|
|
|
|
CXSourceLocation DefinitionLoc = clang_getCursorLocation(Definition);
|
|
|
|
CXString DefinitionKindSpelling
|
|
|
|
= clang_getCursorKindSpelling(Definition.kind);
|
|
|
|
CXFile DefinitionFile;
|
|
|
|
unsigned DefinitionLine, DefinitionColumn;
|
2013-01-11 02:54:52 +08:00
|
|
|
clang_getFileLocation(DefinitionLoc, &DefinitionFile,
|
2014-06-08 16:38:04 +08:00
|
|
|
&DefinitionLine, &DefinitionColumn, nullptr);
|
2012-12-18 22:30:41 +08:00
|
|
|
CXString DefinitionFileName = clang_getFileName(DefinitionFile);
|
2013-01-11 02:54:52 +08:00
|
|
|
*Log << llvm::format(" -> %s(%s:%d:%d)",
|
|
|
|
clang_getCString(DefinitionKindSpelling),
|
|
|
|
clang_getCString(DefinitionFileName),
|
|
|
|
DefinitionLine, DefinitionColumn);
|
2012-12-18 22:30:41 +08:00
|
|
|
clang_disposeString(DefinitionFileName);
|
|
|
|
clang_disposeString(DefinitionKindSpelling);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getNullCursor(void) {
|
|
|
|
return MakeCXCursorInvalid(CXCursor_InvalidFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_equalCursors(CXCursor X, CXCursor Y) {
|
2013-01-09 02:23:28 +08:00
|
|
|
// Clear out the "FirstInDeclGroup" part in a declaration cursor, since we
|
|
|
|
// can't set consistently. For example, when visiting a DeclStmt we will set
|
|
|
|
// it but we don't set it on the result of clang_getCursorDefinition for
|
|
|
|
// a reference of the same declaration.
|
|
|
|
// FIXME: Setting "FirstInDeclGroup" in CXCursors is a hack that only works
|
|
|
|
// when visiting a DeclStmt currently, the AST should be enhanced to be able
|
|
|
|
// to provide that kind of info.
|
|
|
|
if (clang_isDeclaration(X.kind))
|
2014-06-08 16:38:04 +08:00
|
|
|
X.data[1] = nullptr;
|
2013-01-09 02:23:28 +08:00
|
|
|
if (clang_isDeclaration(Y.kind))
|
2014-06-08 16:38:04 +08:00
|
|
|
Y.data[1] = nullptr;
|
2013-01-09 02:23:28 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
return X == Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_hashCursor(CXCursor C) {
|
|
|
|
unsigned Index = 0;
|
|
|
|
if (clang_isExpression(C.kind) || clang_isStatement(C.kind))
|
|
|
|
Index = 1;
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
return llvm::DenseMapInfo<std::pair<unsigned, const void*> >::getHashValue(
|
2012-12-18 22:30:41 +08:00
|
|
|
std::make_pair(C.kind, C.data[Index]));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isInvalid(enum CXCursorKind K) {
|
|
|
|
return K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isDeclaration(enum CXCursorKind K) {
|
|
|
|
return (K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl) ||
|
2018-01-03 18:33:21 +08:00
|
|
|
(K >= CXCursor_FirstExtraDecl && K <= CXCursor_LastExtraDecl);
|
|
|
|
}
|
|
|
|
|
2018-01-04 18:59:50 +08:00
|
|
|
unsigned clang_isInvalidDeclaration(CXCursor C) {
|
|
|
|
if (clang_isDeclaration(C.kind)) {
|
|
|
|
if (const Decl *D = getCursorDecl(C))
|
|
|
|
return D->isInvalidDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-03 18:33:21 +08:00
|
|
|
unsigned clang_isReference(enum CXCursorKind K) {
|
|
|
|
return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
unsigned clang_isExpression(enum CXCursorKind K) {
|
|
|
|
return K >= CXCursor_FirstExpr && K <= CXCursor_LastExpr;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isStatement(enum CXCursorKind K) {
|
|
|
|
return K >= CXCursor_FirstStmt && K <= CXCursor_LastStmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isAttribute(enum CXCursorKind K) {
|
|
|
|
return K >= CXCursor_FirstAttr && K <= CXCursor_LastAttr;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isTranslationUnit(enum CXCursorKind K) {
|
|
|
|
return K == CXCursor_TranslationUnit;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isPreprocessing(enum CXCursorKind K) {
|
|
|
|
return K >= CXCursor_FirstPreprocessing && K <= CXCursor_LastPreprocessing;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isUnexposed(enum CXCursorKind K) {
|
|
|
|
switch (K) {
|
|
|
|
case CXCursor_UnexposedDecl:
|
|
|
|
case CXCursor_UnexposedExpr:
|
|
|
|
case CXCursor_UnexposedStmt:
|
|
|
|
case CXCursor_UnexposedAttr:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursorKind clang_getCursorKind(CXCursor C) {
|
|
|
|
return C.kind;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceLocation clang_getCursorLocation(CXCursor C) {
|
|
|
|
if (clang_isReference(C.kind)) {
|
|
|
|
switch (C.kind) {
|
|
|
|
case CXCursor_ObjCSuperClassRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCInterfaceDecl *, SourceLocation> P
|
2012-12-18 22:30:41 +08:00
|
|
|
= getCursorObjCSuperClassRef(C);
|
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_ObjCProtocolRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCProtocolDecl *, SourceLocation> P
|
2012-12-18 22:30:41 +08:00
|
|
|
= getCursorObjCProtocolRef(C);
|
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_ObjCClassRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCInterfaceDecl *, SourceLocation> P
|
2012-12-18 22:30:41 +08:00
|
|
|
= getCursorObjCClassRef(C);
|
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_TypeRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const TypeDecl *, SourceLocation> P = getCursorTypeRef(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_TemplateRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const TemplateDecl *, SourceLocation> P =
|
|
|
|
getCursorTemplateRef(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_NamespaceRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const NamedDecl *, SourceLocation> P = getCursorNamespaceRef(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_MemberRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const FieldDecl *, SourceLocation> P = getCursorMemberRef(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_VariableRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const VarDecl *, SourceLocation> P = getCursorVariableRef(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_CXXBaseSpecifier: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const CXXBaseSpecifier *BaseSpec = getCursorCXXBaseSpecifier(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!BaseSpec)
|
|
|
|
return clang_getNullLocation();
|
|
|
|
|
|
|
|
if (TypeSourceInfo *TSInfo = BaseSpec->getTypeSourceInfo())
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
|
|
|
TSInfo->getTypeLoc().getBeginLoc());
|
2018-08-10 05:08:08 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
2018-08-10 05:08:08 +08:00
|
|
|
BaseSpec->getBeginLoc());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_LabelRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const LabelStmt *, SourceLocation> P = getCursorLabelRef(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), P.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_OverloadedDeclRef:
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
|
|
|
getCursorOverloadedDeclRef(C).second);
|
|
|
|
|
|
|
|
default:
|
|
|
|
// FIXME: Need a way to enumerate all non-reference cases.
|
|
|
|
llvm_unreachable("Missed a reference kind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isExpression(C.kind))
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
|
|
|
getLocationFromExpr(getCursorExpr(C)));
|
|
|
|
|
|
|
|
if (clang_isStatement(C.kind))
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
2018-08-10 05:08:08 +08:00
|
|
|
getCursorStmt(C)->getBeginLoc());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (C.kind == CXCursor_PreprocessingDirective) {
|
|
|
|
SourceLocation L = cxcursor::getCursorPreprocessingDirective(C).getBegin();
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), L);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroExpansion) {
|
|
|
|
SourceLocation L
|
2013-01-08 03:16:25 +08:00
|
|
|
= cxcursor::getCursorMacroExpansion(C).getSourceRange().getBegin();
|
2012-12-18 22:30:41 +08:00
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), L);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroDefinition) {
|
|
|
|
SourceLocation L = cxcursor::getCursorMacroDefinition(C)->getLocation();
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), L);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_InclusionDirective) {
|
|
|
|
SourceLocation L
|
|
|
|
= cxcursor::getCursorInclusionDirective(C)->getSourceRange().getBegin();
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), L);
|
|
|
|
}
|
|
|
|
|
2013-09-25 08:14:38 +08:00
|
|
|
if (clang_isAttribute(C.kind)) {
|
|
|
|
SourceLocation L
|
|
|
|
= cxcursor::getCursorAttr(C)->getLocation();
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), L);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return clang_getNullLocation();
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = getCursorDecl(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
|
|
|
return clang_getNullLocation();
|
|
|
|
|
|
|
|
SourceLocation Loc = D->getLocation();
|
|
|
|
// FIXME: Multiple variables declared in a single declaration
|
|
|
|
// currently lack the information needed to correctly determine their
|
|
|
|
// ranges when accounting for the type-specifier. We use context
|
|
|
|
// stored in the CXCursor to determine if the VarDecl is in a DeclGroup,
|
|
|
|
// and if so, whether it is the first decl.
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!cxcursor::isFirstInDeclGroup(C))
|
|
|
|
Loc = VD->getLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
// For ObjC methods, give the start location of the method name.
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
Loc = MD->getSelectorStartLoc();
|
|
|
|
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), Loc);
|
|
|
|
}
|
|
|
|
|
2016-12-20 00:50:43 +08:00
|
|
|
} // end extern "C"
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXCursor cxcursor::getCursor(CXTranslationUnit TU, SourceLocation SLoc) {
|
|
|
|
assert(TU);
|
|
|
|
|
|
|
|
// Guard against an invalid SourceLocation, or we may assert in one
|
|
|
|
// of the following calls.
|
|
|
|
if (SLoc.isInvalid())
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Translate the given source location to make it point at the beginning of
|
|
|
|
// the token under the cursor.
|
|
|
|
SLoc = Lexer::GetBeginningOfToken(SLoc, CXXUnit->getSourceManager(),
|
|
|
|
CXXUnit->getASTContext().getLangOpts());
|
|
|
|
|
|
|
|
CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound);
|
|
|
|
if (SLoc.isValid()) {
|
|
|
|
GetCursorData ResultData(CXXUnit->getSourceManager(), SLoc, Result);
|
|
|
|
CursorVisitor CursorVis(TU, GetCursorVisitor, &ResultData,
|
|
|
|
/*VisitPreprocessorLast=*/true,
|
|
|
|
/*VisitIncludedEntities=*/false,
|
|
|
|
SourceLocation(SLoc));
|
|
|
|
CursorVis.visitFileRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SourceRange getRawCursorExtent(CXCursor C) {
|
|
|
|
if (clang_isReference(C.kind)) {
|
|
|
|
switch (C.kind) {
|
|
|
|
case CXCursor_ObjCSuperClassRef:
|
|
|
|
return getCursorObjCSuperClassRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_ObjCProtocolRef:
|
|
|
|
return getCursorObjCProtocolRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_ObjCClassRef:
|
|
|
|
return getCursorObjCClassRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_TypeRef:
|
|
|
|
return getCursorTypeRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_TemplateRef:
|
|
|
|
return getCursorTemplateRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_NamespaceRef:
|
|
|
|
return getCursorNamespaceRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_MemberRef:
|
|
|
|
return getCursorMemberRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_CXXBaseSpecifier:
|
|
|
|
return getCursorCXXBaseSpecifier(C)->getSourceRange();
|
|
|
|
|
|
|
|
case CXCursor_LabelRef:
|
|
|
|
return getCursorLabelRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_OverloadedDeclRef:
|
|
|
|
return getCursorOverloadedDeclRef(C).second;
|
|
|
|
|
|
|
|
case CXCursor_VariableRef:
|
|
|
|
return getCursorVariableRef(C).second;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// FIXME: Need a way to enumerate all non-reference cases.
|
|
|
|
llvm_unreachable("Missed a reference kind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isExpression(C.kind))
|
|
|
|
return getCursorExpr(C)->getSourceRange();
|
|
|
|
|
|
|
|
if (clang_isStatement(C.kind))
|
|
|
|
return getCursorStmt(C)->getSourceRange();
|
|
|
|
|
|
|
|
if (clang_isAttribute(C.kind))
|
|
|
|
return getCursorAttr(C)->getRange();
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_PreprocessingDirective)
|
|
|
|
return cxcursor::getCursorPreprocessingDirective(C);
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroExpansion) {
|
|
|
|
ASTUnit *TU = getCursorASTUnit(C);
|
2013-01-08 03:16:25 +08:00
|
|
|
SourceRange Range = cxcursor::getCursorMacroExpansion(C).getSourceRange();
|
2012-12-18 22:30:41 +08:00
|
|
|
return TU->mapRangeFromPreamble(Range);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroDefinition) {
|
|
|
|
ASTUnit *TU = getCursorASTUnit(C);
|
|
|
|
SourceRange Range = cxcursor::getCursorMacroDefinition(C)->getSourceRange();
|
|
|
|
return TU->mapRangeFromPreamble(Range);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_InclusionDirective) {
|
|
|
|
ASTUnit *TU = getCursorASTUnit(C);
|
|
|
|
SourceRange Range = cxcursor::getCursorInclusionDirective(C)->getSourceRange();
|
|
|
|
return TU->mapRangeFromPreamble(Range);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_TranslationUnit) {
|
|
|
|
ASTUnit *TU = getCursorASTUnit(C);
|
|
|
|
FileID MainID = TU->getSourceManager().getMainFileID();
|
|
|
|
SourceLocation Start = TU->getSourceManager().getLocForStartOfFile(MainID);
|
|
|
|
SourceLocation End = TU->getSourceManager().getLocForEndOfFile(MainID);
|
|
|
|
return SourceRange(Start, End);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isDeclaration(C.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
|
|
|
return SourceRange();
|
|
|
|
|
|
|
|
SourceRange R = D->getSourceRange();
|
|
|
|
// FIXME: Multiple variables declared in a single declaration
|
|
|
|
// currently lack the information needed to correctly determine their
|
|
|
|
// ranges when accounting for the type-specifier. We use context
|
|
|
|
// stored in the CXCursor to determine if the VarDecl is in a DeclGroup,
|
|
|
|
// and if so, whether it is the first decl.
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!cxcursor::isFirstInDeclGroup(C))
|
|
|
|
R.setBegin(VD->getLocation());
|
|
|
|
}
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
return SourceRange();
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Retrieves the "raw" cursor extent, which is then extended to include
|
2012-12-18 22:30:41 +08:00
|
|
|
/// the decl-specifier-seq for declarations.
|
|
|
|
static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr) {
|
|
|
|
if (clang_isDeclaration(C.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
|
|
|
return SourceRange();
|
|
|
|
|
|
|
|
SourceRange R = D->getSourceRange();
|
|
|
|
|
|
|
|
// Adjust the start of the location for declarations preceded by
|
|
|
|
// declaration specifiers.
|
|
|
|
SourceLocation StartLoc;
|
|
|
|
if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
|
|
|
|
if (TypeSourceInfo *TI = DD->getTypeSourceInfo())
|
2018-08-10 05:08:08 +08:00
|
|
|
StartLoc = TI->getTypeLoc().getBeginLoc();
|
2013-01-24 01:25:27 +08:00
|
|
|
} else if (const TypedefDecl *Typedef = dyn_cast<TypedefDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (TypeSourceInfo *TI = Typedef->getTypeSourceInfo())
|
2018-08-10 05:08:08 +08:00
|
|
|
StartLoc = TI->getTypeLoc().getBeginLoc();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (StartLoc.isValid() && R.getBegin().isValid() &&
|
|
|
|
SrcMgr.isBeforeInTranslationUnit(StartLoc, R.getBegin()))
|
|
|
|
R.setBegin(StartLoc);
|
|
|
|
|
|
|
|
// FIXME: Multiple variables declared in a single declaration
|
|
|
|
// currently lack the information needed to correctly determine their
|
|
|
|
// ranges when accounting for the type-specifier. We use context
|
|
|
|
// stored in the CXCursor to determine if the VarDecl is in a DeclGroup,
|
|
|
|
// and if so, whether it is the first decl.
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!cxcursor::isFirstInDeclGroup(C))
|
|
|
|
R.setBegin(VD->getLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getRawCursorExtent(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceRange clang_getCursorExtent(CXCursor C) {
|
|
|
|
SourceRange R = getRawCursorExtent(C);
|
|
|
|
if (R.isInvalid())
|
|
|
|
return clang_getNullRange();
|
|
|
|
|
|
|
|
return cxloc::translateSourceRange(getCursorContext(C), R);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getCursorReferenced(CXCursor C) {
|
|
|
|
if (clang_isInvalid(C.kind))
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
CXTranslationUnit tu = getCursorTU(C);
|
|
|
|
if (clang_isDeclaration(C.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = getCursorDecl(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
|
|
|
return clang_getNullCursor();
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const UsingDecl *Using = dyn_cast<UsingDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCursorOverloadedDeclRef(Using, D->getLocation(), tu);
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCPropertyImplDecl *PropImpl =
|
|
|
|
dyn_cast<ObjCPropertyImplDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl())
|
|
|
|
return MakeCXCursor(Property, tu);
|
|
|
|
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isExpression(C.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
const Expr *E = getCursorExpr(C);
|
|
|
|
const Decl *D = getDeclFromExpr(E);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (D) {
|
|
|
|
CXCursor declCursor = MakeCXCursor(D, tu);
|
|
|
|
declCursor = getSelectorIdentifierCursor(getSelectorIdentifierIndex(C),
|
|
|
|
declCursor);
|
|
|
|
return declCursor;
|
|
|
|
}
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const OverloadExpr *Ovl = dyn_cast_or_null<OverloadExpr>(E))
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCursorOverloadedDeclRef(Ovl, tu);
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isStatement(C.kind)) {
|
2013-01-26 23:29:08 +08:00
|
|
|
const Stmt *S = getCursorStmt(C);
|
|
|
|
if (const GotoStmt *Goto = dyn_cast_or_null<GotoStmt>(S))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (LabelDecl *label = Goto->getLabel())
|
|
|
|
if (LabelStmt *labelS = label->getStmt())
|
|
|
|
return MakeCXCursor(labelS, getCursorDecl(C), tu);
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
2015-05-04 10:25:31 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (C.kind == CXCursor_MacroExpansion) {
|
2015-05-04 10:25:31 +08:00
|
|
|
if (const MacroDefinitionRecord *Def =
|
|
|
|
getCursorMacroExpansion(C).getDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeMacroDefinitionCursor(Def, tu);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!clang_isReference(C.kind))
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
switch (C.kind) {
|
|
|
|
case CXCursor_ObjCSuperClassRef:
|
|
|
|
return MakeCXCursor(getCursorObjCSuperClassRef(C).first, tu);
|
|
|
|
|
|
|
|
case CXCursor_ObjCProtocolRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const ObjCProtocolDecl *Prot = getCursorObjCProtocolRef(C).first;
|
|
|
|
if (const ObjCProtocolDecl *Def = Prot->getDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(Def, tu);
|
|
|
|
|
|
|
|
return MakeCXCursor(Prot, tu);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_ObjCClassRef: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
|
|
|
|
if (const ObjCInterfaceDecl *Def = Class->getDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(Def, tu);
|
|
|
|
|
|
|
|
return MakeCXCursor(Class, tu);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_TypeRef:
|
|
|
|
return MakeCXCursor(getCursorTypeRef(C).first, tu );
|
|
|
|
|
|
|
|
case CXCursor_TemplateRef:
|
|
|
|
return MakeCXCursor(getCursorTemplateRef(C).first, tu );
|
|
|
|
|
|
|
|
case CXCursor_NamespaceRef:
|
|
|
|
return MakeCXCursor(getCursorNamespaceRef(C).first, tu );
|
|
|
|
|
|
|
|
case CXCursor_MemberRef:
|
|
|
|
return MakeCXCursor(getCursorMemberRef(C).first, tu );
|
|
|
|
|
|
|
|
case CXCursor_CXXBaseSpecifier: {
|
2013-01-12 05:01:49 +08:00
|
|
|
const CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
return clang_getTypeDeclaration(cxtype::MakeCXType(B->getType(),
|
|
|
|
tu ));
|
|
|
|
}
|
|
|
|
|
|
|
|
case CXCursor_LabelRef:
|
|
|
|
// FIXME: We end up faking the "parent" declaration here because we
|
|
|
|
// don't want to make CXCursor larger.
|
2013-01-27 02:53:38 +08:00
|
|
|
return MakeCXCursor(getCursorLabelRef(C).first,
|
|
|
|
cxtu::getASTUnit(tu)->getASTContext()
|
|
|
|
.getTranslationUnitDecl(),
|
2012-12-18 22:30:41 +08:00
|
|
|
tu);
|
|
|
|
|
|
|
|
case CXCursor_OverloadedDeclRef:
|
|
|
|
return C;
|
|
|
|
|
|
|
|
case CXCursor_VariableRef:
|
|
|
|
return MakeCXCursor(getCursorVariableRef(C).first, tu);
|
|
|
|
|
|
|
|
default:
|
|
|
|
// We would prefer to enumerate all non-reference cursor kinds here.
|
|
|
|
llvm_unreachable("Unhandled reference cursor kind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getCursorDefinition(CXCursor C) {
|
|
|
|
if (clang_isInvalid(C.kind))
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
CXTranslationUnit TU = getCursorTU(C);
|
|
|
|
|
|
|
|
bool WasReference = false;
|
|
|
|
if (clang_isReference(C.kind) || clang_isExpression(C.kind)) {
|
|
|
|
C = clang_getCursorReferenced(C);
|
|
|
|
WasReference = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroExpansion)
|
|
|
|
return clang_getCursorReferenced(C);
|
|
|
|
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = getCursorDecl(C);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
switch (D->getKind()) {
|
|
|
|
// Declaration kinds that don't really separate the notions of
|
|
|
|
// declaration and definition.
|
|
|
|
case Decl::Namespace:
|
|
|
|
case Decl::Typedef:
|
|
|
|
case Decl::TypeAlias:
|
|
|
|
case Decl::TypeAliasTemplate:
|
|
|
|
case Decl::TemplateTypeParm:
|
|
|
|
case Decl::EnumConstant:
|
|
|
|
case Decl::Field:
|
2016-07-23 07:36:59 +08:00
|
|
|
case Decl::Binding:
|
2013-04-16 15:28:30 +08:00
|
|
|
case Decl::MSProperty:
|
2012-12-18 22:30:41 +08:00
|
|
|
case Decl::IndirectField:
|
|
|
|
case Decl::ObjCIvar:
|
|
|
|
case Decl::ObjCAtDefsField:
|
|
|
|
case Decl::ImplicitParam:
|
|
|
|
case Decl::ParmVar:
|
|
|
|
case Decl::NonTypeTemplateParm:
|
|
|
|
case Decl::TemplateTemplateParm:
|
|
|
|
case Decl::ObjCCategoryImpl:
|
|
|
|
case Decl::ObjCImplementation:
|
|
|
|
case Decl::AccessSpec:
|
|
|
|
case Decl::LinkageSpec:
|
2016-09-09 07:14:54 +08:00
|
|
|
case Decl::Export:
|
2012-12-18 22:30:41 +08:00
|
|
|
case Decl::ObjCPropertyImpl:
|
|
|
|
case Decl::FileScopeAsm:
|
|
|
|
case Decl::StaticAssert:
|
|
|
|
case Decl::Block:
|
2013-04-17 03:37:38 +08:00
|
|
|
case Decl::Captured:
|
2016-02-11 13:35:55 +08:00
|
|
|
case Decl::OMPCapturedExpr:
|
2012-12-18 22:30:41 +08:00
|
|
|
case Decl::Label: // FIXME: Is this right??
|
|
|
|
case Decl::ClassScopeFunctionSpecialization:
|
2017-02-18 04:05:37 +08:00
|
|
|
case Decl::CXXDeductionGuide:
|
2012-12-18 22:30:41 +08:00
|
|
|
case Decl::Import:
|
2013-03-22 14:34:35 +08:00
|
|
|
case Decl::OMPThreadPrivate:
|
2019-03-08 01:54:44 +08:00
|
|
|
case Decl::OMPAllocate:
|
2016-03-03 13:21:39 +08:00
|
|
|
case Decl::OMPDeclareReduction:
|
2019-02-02 04:25:04 +08:00
|
|
|
case Decl::OMPDeclareMapper:
|
2018-09-26 12:28:39 +08:00
|
|
|
case Decl::OMPRequires:
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
case Decl::ObjCTypeParam:
|
2015-11-04 11:40:30 +08:00
|
|
|
case Decl::BuiltinTemplate:
|
2016-03-03 01:28:48 +08:00
|
|
|
case Decl::PragmaComment:
|
2016-03-03 03:28:54 +08:00
|
|
|
case Decl::PragmaDetectMismatch:
|
2016-12-21 05:35:28 +08:00
|
|
|
case Decl::UsingPack:
|
2019-07-11 05:25:49 +08:00
|
|
|
case Decl::Concept:
|
2012-12-18 22:30:41 +08:00
|
|
|
return C;
|
|
|
|
|
|
|
|
// Declaration kinds that don't make any sense here, but are
|
|
|
|
// nonetheless harmless.
|
2013-02-23 01:44:58 +08:00
|
|
|
case Decl::Empty:
|
2012-12-18 22:30:41 +08:00
|
|
|
case Decl::TranslationUnit:
|
2015-03-07 08:04:49 +08:00
|
|
|
case Decl::ExternCContext:
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Declaration kinds for which the definition is not resolvable.
|
|
|
|
case Decl::UnresolvedUsingTypename:
|
|
|
|
case Decl::UnresolvedUsingValue:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Decl::UsingDirective:
|
|
|
|
return MakeCXCursor(cast<UsingDirectiveDecl>(D)->getNominatedNamespace(),
|
|
|
|
TU);
|
|
|
|
|
|
|
|
case Decl::NamespaceAlias:
|
|
|
|
return MakeCXCursor(cast<NamespaceAliasDecl>(D)->getNamespace(), TU);
|
|
|
|
|
|
|
|
case Decl::Enum:
|
|
|
|
case Decl::Record:
|
|
|
|
case Decl::CXXRecord:
|
|
|
|
case Decl::ClassTemplateSpecialization:
|
|
|
|
case Decl::ClassTemplatePartialSpecialization:
|
|
|
|
if (TagDecl *Def = cast<TagDecl>(D)->getDefinition())
|
|
|
|
return MakeCXCursor(Def, TU);
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::Function:
|
|
|
|
case Decl::CXXMethod:
|
|
|
|
case Decl::CXXConstructor:
|
|
|
|
case Decl::CXXDestructor:
|
|
|
|
case Decl::CXXConversion: {
|
2014-06-08 16:38:04 +08:00
|
|
|
const FunctionDecl *Def = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (cast<FunctionDecl>(D)->getBody(Def))
|
2013-01-14 08:46:27 +08:00
|
|
|
return MakeCXCursor(Def, TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
case Decl::Var:
|
|
|
|
case Decl::VarTemplateSpecialization:
|
2016-07-23 07:36:59 +08:00
|
|
|
case Decl::VarTemplatePartialSpecialization:
|
|
|
|
case Decl::Decomposition: {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Ask the variable if it has a definition.
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const VarDecl *Def = cast<VarDecl>(D)->getDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(Def, TU);
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
case Decl::FunctionTemplate: {
|
2014-06-08 16:38:04 +08:00
|
|
|
const FunctionDecl *Def = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->getBody(Def))
|
|
|
|
return MakeCXCursor(Def->getDescribedFunctionTemplate(), TU);
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
case Decl::ClassTemplate: {
|
|
|
|
if (RecordDecl *Def = cast<ClassTemplateDecl>(D)->getTemplatedDecl()
|
|
|
|
->getDefinition())
|
|
|
|
return MakeCXCursor(cast<CXXRecordDecl>(Def)->getDescribedClassTemplate(),
|
|
|
|
TU);
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
case Decl::VarTemplate: {
|
|
|
|
if (VarDecl *Def =
|
|
|
|
cast<VarTemplateDecl>(D)->getTemplatedDecl()->getDefinition())
|
|
|
|
return MakeCXCursor(cast<VarDecl>(Def)->getDescribedVarTemplate(), TU);
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case Decl::Using:
|
|
|
|
return MakeCursorOverloadedDeclRef(cast<UsingDecl>(D),
|
|
|
|
D->getLocation(), TU);
|
|
|
|
|
|
|
|
case Decl::UsingShadow:
|
P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:
Replace inheriting constructors implementation with new approach, voted into
C++ last year as a DR against C++11.
Instead of synthesizing a set of derived class constructors for each inherited
base class constructor, we make the constructors of the base class visible to
constructor lookup in the derived class, using the normal rules for
using-declarations.
For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived
class that tracks the requisite additional information. We create shadow
constructors (not found by name lookup) in the derived class to model the
actual initialization, and have a new expression node,
CXXInheritedCtorInitExpr, to model the initialization of a base class from such
a constructor. (This initialization is special because it performs real perfect
forwarding of arguments.)
In cases where argument forwarding is not possible (for inalloca calls,
variadic calls, and calls with callee parameter cleanup), the shadow inheriting
constructor is not emitted and instead we directly emit the initialization code
into the caller of the inherited constructor.
Note that this new model is not perfectly compatible with the old model in some
corner cases. In particular:
* if B inherits a private constructor from A, and C uses that constructor to
construct a B, then we previously required that A befriends B and B
befriends C, but the new rules require A to befriend C directly, and
* if a derived class has its own constructors (and so its implicit default
constructor is suppressed), it may still inherit a default constructor from
a base class
llvm-svn: 274049
2016-06-29 03:03:57 +08:00
|
|
|
case Decl::ConstructorUsingShadow:
|
2012-12-18 22:30:41 +08:00
|
|
|
return clang_getCursorDefinition(
|
|
|
|
MakeCXCursor(cast<UsingShadowDecl>(D)->getTargetDecl(),
|
|
|
|
TU));
|
|
|
|
|
|
|
|
case Decl::ObjCMethod: {
|
2013-01-24 01:25:27 +08:00
|
|
|
const ObjCMethodDecl *Method = cast<ObjCMethodDecl>(D);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Method->isThisDeclarationADefinition())
|
|
|
|
return C;
|
|
|
|
|
|
|
|
// Dig out the method definition in the associated
|
|
|
|
// @implementation, if we have it.
|
|
|
|
// FIXME: The ASTs should make finding the definition easier.
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCInterfaceDecl *Class
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext()))
|
|
|
|
if (ObjCImplementationDecl *ClassImpl = Class->getImplementation())
|
|
|
|
if (ObjCMethodDecl *Def = ClassImpl->getMethod(Method->getSelector(),
|
|
|
|
Method->isInstanceMethod()))
|
|
|
|
if (Def->isThisDeclarationADefinition())
|
|
|
|
return MakeCXCursor(Def, TU);
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
case Decl::ObjCCategory:
|
|
|
|
if (ObjCCategoryImplDecl *Impl
|
|
|
|
= cast<ObjCCategoryDecl>(D)->getImplementation())
|
|
|
|
return MakeCXCursor(Impl, TU);
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::ObjCProtocol:
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCProtocolDecl *Def = cast<ObjCProtocolDecl>(D)->getDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(Def, TU);
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::ObjCInterface: {
|
|
|
|
// There are two notions of a "definition" for an Objective-C
|
|
|
|
// class: the interface and its implementation. When we resolved a
|
|
|
|
// reference to an Objective-C class, produce the @interface as
|
|
|
|
// the definition; when we were provided with the interface,
|
|
|
|
// produce the @implementation as the definition.
|
2013-01-24 01:25:27 +08:00
|
|
|
const ObjCInterfaceDecl *IFace = cast<ObjCInterfaceDecl>(D);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (WasReference) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCInterfaceDecl *Def = IFace->getDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(Def, TU);
|
|
|
|
} else if (ObjCImplementationDecl *Impl = IFace->getImplementation())
|
|
|
|
return MakeCXCursor(Impl, TU);
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
case Decl::ObjCProperty:
|
|
|
|
// FIXME: We don't really know where to find the
|
|
|
|
// ObjCPropertyImplDecls that implement this property.
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::ObjCCompatibleAlias:
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCInterfaceDecl *Class
|
2012-12-18 22:30:41 +08:00
|
|
|
= cast<ObjCCompatibleAliasDecl>(D)->getClassInterface())
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCInterfaceDecl *Def = Class->getDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(Def, TU);
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::Friend:
|
|
|
|
if (NamedDecl *Friend = cast<FriendDecl>(D)->getFriendDecl())
|
|
|
|
return clang_getCursorDefinition(MakeCXCursor(Friend, TU));
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::FriendTemplate:
|
|
|
|
if (NamedDecl *Friend = cast<FriendTemplateDecl>(D)->getFriendDecl())
|
|
|
|
return clang_getCursorDefinition(MakeCXCursor(Friend, TU));
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isCursorDefinition(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return clang_getCursorDefinition(C) == C;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getCanonicalCursor(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return C;
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const Decl *D = getCursorDecl(C)) {
|
|
|
|
if (const ObjCCategoryImplDecl *CatImplD = dyn_cast<ObjCCategoryImplDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ObjCCategoryDecl *CatD = CatImplD->getCategoryDecl())
|
|
|
|
return MakeCXCursor(CatD, getCursorTU(C));
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D))
|
|
|
|
if (const ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(IFD, getCursorTU(C));
|
|
|
|
|
|
|
|
return MakeCXCursor(D->getCanonicalDecl(), getCursorTU(C));
|
|
|
|
}
|
|
|
|
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clang_Cursor_getObjCSelectorIndex(CXCursor cursor) {
|
|
|
|
return cxcursor::getSelectorIdentifierIndexAndLoc(cursor).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_getNumOverloadedDecls(CXCursor C) {
|
|
|
|
if (C.kind != CXCursor_OverloadedDeclRef)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first;
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
|
2012-12-18 22:30:41 +08:00
|
|
|
return E->getNumDecls();
|
|
|
|
|
|
|
|
if (OverloadedTemplateStorage *S
|
|
|
|
= Storage.dyn_cast<OverloadedTemplateStorage*>())
|
|
|
|
return S->size();
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = Storage.get<const Decl *>();
|
|
|
|
if (const UsingDecl *Using = dyn_cast<UsingDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
return Using->shadow_size();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) {
|
|
|
|
if (cursor.kind != CXCursor_OverloadedDeclRef)
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
if (index >= clang_getNumOverloadedDecls(cursor))
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
CXTranslationUnit TU = getCursorTU(cursor);
|
|
|
|
OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(cursor).first;
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(E->decls_begin()[index], TU);
|
|
|
|
|
|
|
|
if (OverloadedTemplateStorage *S
|
|
|
|
= Storage.dyn_cast<OverloadedTemplateStorage*>())
|
|
|
|
return MakeCXCursor(S->begin()[index], TU);
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = Storage.get<const Decl *>();
|
|
|
|
if (const UsingDecl *Using = dyn_cast<UsingDecl>(D)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// FIXME: This is, unfortunately, linear time.
|
|
|
|
UsingDecl::shadow_iterator Pos = Using->shadow_begin();
|
|
|
|
std::advance(Pos, index);
|
|
|
|
return MakeCXCursor(cast<UsingShadowDecl>(*Pos)->getTargetDecl(), TU);
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_getDefinitionSpellingAndExtent(CXCursor C,
|
|
|
|
const char **startBuf,
|
|
|
|
const char **endBuf,
|
|
|
|
unsigned *startLine,
|
|
|
|
unsigned *startColumn,
|
|
|
|
unsigned *endLine,
|
|
|
|
unsigned *endColumn) {
|
|
|
|
assert(getCursorDecl(C) && "CXCursor has null decl");
|
2013-01-24 01:25:27 +08:00
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(getCursorDecl(C));
|
2012-12-18 22:30:41 +08:00
|
|
|
CompoundStmt *Body = dyn_cast<CompoundStmt>(FD->getBody());
|
|
|
|
|
|
|
|
SourceManager &SM = FD->getASTContext().getSourceManager();
|
|
|
|
*startBuf = SM.getCharacterData(Body->getLBracLoc());
|
|
|
|
*endBuf = SM.getCharacterData(Body->getRBracLoc());
|
|
|
|
*startLine = SM.getSpellingLineNumber(Body->getLBracLoc());
|
|
|
|
*startColumn = SM.getSpellingColumnNumber(Body->getLBracLoc());
|
|
|
|
*endLine = SM.getSpellingLineNumber(Body->getRBracLoc());
|
|
|
|
*endColumn = SM.getSpellingColumnNumber(Body->getRBracLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CXSourceRange clang_getCursorReferenceNameRange(CXCursor C, unsigned NameFlags,
|
|
|
|
unsigned PieceIndex) {
|
|
|
|
RefNamePieces Pieces;
|
|
|
|
|
|
|
|
switch (C.kind) {
|
|
|
|
case CXCursor_MemberRefExpr:
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const MemberExpr *E = dyn_cast<MemberExpr>(getCursorExpr(C)))
|
2012-12-18 22:30:41 +08:00
|
|
|
Pieces = buildPieces(NameFlags, true, E->getMemberNameInfo(),
|
|
|
|
E->getQualifierLoc().getSourceRange());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CXCursor_DeclRefExpr:
|
2015-12-24 10:59:37 +08:00
|
|
|
if (const DeclRefExpr *E = dyn_cast<DeclRefExpr>(getCursorExpr(C))) {
|
|
|
|
SourceRange TemplateArgLoc(E->getLAngleLoc(), E->getRAngleLoc());
|
|
|
|
Pieces =
|
|
|
|
buildPieces(NameFlags, false, E->getNameInfo(),
|
|
|
|
E->getQualifierLoc().getSourceRange(), &TemplateArgLoc);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CXCursor_CallExpr:
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const CXXOperatorCallExpr *OCE =
|
2012-12-18 22:30:41 +08:00
|
|
|
dyn_cast<CXXOperatorCallExpr>(getCursorExpr(C))) {
|
2013-01-26 23:29:08 +08:00
|
|
|
const Expr *Callee = OCE->getCallee();
|
|
|
|
if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
|
2012-12-18 22:30:41 +08:00
|
|
|
Callee = ICE->getSubExpr();
|
|
|
|
|
2013-01-26 23:29:08 +08:00
|
|
|
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee))
|
2012-12-18 22:30:41 +08:00
|
|
|
Pieces = buildPieces(NameFlags, false, DRE->getNameInfo(),
|
|
|
|
DRE->getQualifierLoc().getSourceRange());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Pieces.empty()) {
|
|
|
|
if (PieceIndex == 0)
|
|
|
|
return clang_getCursorExtent(C);
|
|
|
|
} else if (PieceIndex < Pieces.size()) {
|
|
|
|
SourceRange R = Pieces[PieceIndex];
|
|
|
|
if (R.isValid())
|
|
|
|
return cxloc::translateSourceRange(getCursorContext(C), R);
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getNullRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_enableStackTraces(void) {
|
2016-06-09 08:53:41 +08:00
|
|
|
// FIXME: Provide an argv0 here so we can find llvm-symbolizer.
|
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal(StringRef());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void clang_executeOnThread(void (*fn)(void*), void *user_data,
|
|
|
|
unsigned stack_size) {
|
|
|
|
llvm::llvm_execute_on_thread(fn, user_data, stack_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Token-based Operations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/* CXToken layout:
|
|
|
|
* int_data[0]: a CXTokenKind
|
|
|
|
* int_data[1]: starting token location
|
|
|
|
* int_data[2]: token length
|
|
|
|
* int_data[3]: reserved
|
|
|
|
* ptr_data: for identifiers and keywords, an IdentifierInfo*.
|
|
|
|
* otherwise unused.
|
|
|
|
*/
|
|
|
|
CXTokenKind clang_getTokenKind(CXToken CXTok) {
|
|
|
|
return static_cast<CXTokenKind>(CXTok.int_data[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) {
|
|
|
|
switch (clang_getTokenKind(CXTok)) {
|
|
|
|
case CXToken_Identifier:
|
|
|
|
case CXToken_Keyword:
|
|
|
|
// We know we have an IdentifierInfo*, so use that.
|
2013-02-02 08:02:12 +08:00
|
|
|
return cxstring::createRef(static_cast<IdentifierInfo *>(CXTok.ptr_data)
|
2012-12-18 22:30:41 +08:00
|
|
|
->getNameStart());
|
|
|
|
|
|
|
|
case CXToken_Literal: {
|
|
|
|
// We have stashed the starting pointer in the ptr_data field. Use it.
|
|
|
|
const char *Text = static_cast<const char *>(CXTok.ptr_data);
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(StringRef(Text, CXTok.int_data[2]));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case CXToken_Punctuation:
|
|
|
|
case CXToken_Comment:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return cxstring::createEmpty();
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// We have to find the starting buffer pointer the hard way, by
|
|
|
|
// deconstructing the source location.
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!CXXUnit)
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]);
|
|
|
|
std::pair<FileID, unsigned> LocInfo
|
|
|
|
= CXXUnit->getSourceManager().getDecomposedSpellingLoc(Loc);
|
|
|
|
bool Invalid = false;
|
|
|
|
StringRef Buffer
|
|
|
|
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
|
|
|
|
if (Invalid)
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(Buffer.substr(LocInfo.second, CXTok.int_data[2]));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return clang_getNullLocation();
|
|
|
|
}
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!CXXUnit)
|
|
|
|
return clang_getNullLocation();
|
|
|
|
|
|
|
|
return cxloc::translateSourceLocation(CXXUnit->getASTContext(),
|
|
|
|
SourceLocation::getFromRawEncoding(CXTok.int_data[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return clang_getNullRange();
|
|
|
|
}
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!CXXUnit)
|
|
|
|
return clang_getNullRange();
|
|
|
|
|
|
|
|
return cxloc::translateSourceRange(CXXUnit->getASTContext(),
|
|
|
|
SourceLocation::getFromRawEncoding(CXTok.int_data[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void getTokens(ASTUnit *CXXUnit, SourceRange Range,
|
|
|
|
SmallVectorImpl<CXToken> &CXTokens) {
|
|
|
|
SourceManager &SourceMgr = CXXUnit->getSourceManager();
|
|
|
|
std::pair<FileID, unsigned> BeginLocInfo
|
2013-02-14 02:33:28 +08:00
|
|
|
= SourceMgr.getDecomposedSpellingLoc(Range.getBegin());
|
2012-12-18 22:30:41 +08:00
|
|
|
std::pair<FileID, unsigned> EndLocInfo
|
2013-02-14 02:33:28 +08:00
|
|
|
= SourceMgr.getDecomposedSpellingLoc(Range.getEnd());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Cannot tokenize across files.
|
|
|
|
if (BeginLocInfo.first != EndLocInfo.first)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Create a lexer
|
|
|
|
bool Invalid = false;
|
|
|
|
StringRef Buffer
|
|
|
|
= SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
|
|
|
|
if (Invalid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
|
|
|
|
CXXUnit->getASTContext().getLangOpts(),
|
|
|
|
Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end());
|
|
|
|
Lex.SetCommentRetentionState(true);
|
|
|
|
|
|
|
|
// Lex tokens until we hit the end of the range.
|
|
|
|
const char *EffectiveBufferEnd = Buffer.data() + EndLocInfo.second;
|
|
|
|
Token Tok;
|
|
|
|
bool previousWasAt = false;
|
|
|
|
do {
|
|
|
|
// Lex the next token
|
|
|
|
Lex.LexFromRawLexer(Tok);
|
|
|
|
if (Tok.is(tok::eof))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Initialize the CXToken.
|
|
|
|
CXToken CXTok;
|
|
|
|
|
|
|
|
// - Common fields
|
|
|
|
CXTok.int_data[1] = Tok.getLocation().getRawEncoding();
|
|
|
|
CXTok.int_data[2] = Tok.getLength();
|
|
|
|
CXTok.int_data[3] = 0;
|
|
|
|
|
|
|
|
// - Kind-specific fields
|
|
|
|
if (Tok.isLiteral()) {
|
|
|
|
CXTok.int_data[0] = CXToken_Literal;
|
2013-01-23 23:56:07 +08:00
|
|
|
CXTok.ptr_data = const_cast<char *>(Tok.getLiteralData());
|
2012-12-18 22:30:41 +08:00
|
|
|
} else if (Tok.is(tok::raw_identifier)) {
|
|
|
|
// Lookup the identifier to determine whether we have a keyword.
|
|
|
|
IdentifierInfo *II
|
|
|
|
= CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok);
|
|
|
|
|
|
|
|
if ((II->getObjCKeywordID() != tok::objc_not_keyword) && previousWasAt) {
|
|
|
|
CXTok.int_data[0] = CXToken_Keyword;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CXTok.int_data[0] = Tok.is(tok::identifier)
|
|
|
|
? CXToken_Identifier
|
|
|
|
: CXToken_Keyword;
|
|
|
|
}
|
|
|
|
CXTok.ptr_data = II;
|
|
|
|
} else if (Tok.is(tok::comment)) {
|
|
|
|
CXTok.int_data[0] = CXToken_Comment;
|
2014-06-08 16:38:04 +08:00
|
|
|
CXTok.ptr_data = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
} else {
|
|
|
|
CXTok.int_data[0] = CXToken_Punctuation;
|
2014-06-08 16:38:04 +08:00
|
|
|
CXTok.ptr_data = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
CXTokens.push_back(CXTok);
|
|
|
|
previousWasAt = Tok.is(tok::at);
|
2016-11-10 07:58:39 +08:00
|
|
|
} while (Lex.getBufferLocation() < EffectiveBufferEnd);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-06-13 20:37:08 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
|
|
|
|
CXToken **Tokens, unsigned *NumTokens) {
|
2013-01-11 02:54:52 +08:00
|
|
|
LOG_FUNC_SECTION {
|
|
|
|
*Log << TU << ' ' << Range;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Tokens)
|
2014-06-08 16:38:04 +08:00
|
|
|
*Tokens = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (NumTokens)
|
|
|
|
*NumTokens = 0;
|
|
|
|
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
2013-04-05 06:40:59 +08:00
|
|
|
return;
|
2014-02-11 22:34:14 +08:00
|
|
|
}
|
2013-04-05 06:40:59 +08:00
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!CXXUnit || !Tokens || !NumTokens)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
|
|
|
|
|
|
|
SourceRange R = cxloc::translateCXSourceRange(Range);
|
|
|
|
if (R.isInvalid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
SmallVector<CXToken, 32> CXTokens;
|
|
|
|
getTokens(CXXUnit, R, CXTokens);
|
|
|
|
|
|
|
|
if (CXTokens.empty())
|
|
|
|
return;
|
|
|
|
|
2018-02-21 10:02:39 +08:00
|
|
|
*Tokens = static_cast<CXToken *>(
|
|
|
|
llvm::safe_malloc(sizeof(CXToken) * CXTokens.size()));
|
2012-12-18 22:30:41 +08:00
|
|
|
memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());
|
|
|
|
*NumTokens = CXTokens.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_disposeTokens(CXTranslationUnit TU,
|
|
|
|
CXToken *Tokens, unsigned NumTokens) {
|
|
|
|
free(Tokens);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Token annotation APIs.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor,
|
|
|
|
CXCursor parent,
|
|
|
|
CXClientData client_data);
|
|
|
|
static bool AnnotateTokensPostChildrenVisitor(CXCursor cursor,
|
|
|
|
CXClientData client_data);
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class AnnotateTokensWorker {
|
|
|
|
CXToken *Tokens;
|
|
|
|
CXCursor *Cursors;
|
|
|
|
unsigned NumTokens;
|
|
|
|
unsigned TokIdx;
|
|
|
|
unsigned PreprocessingTokIdx;
|
|
|
|
CursorVisitor AnnotateVis;
|
|
|
|
SourceManager &SrcMgr;
|
|
|
|
bool HasContextSensitiveKeywords;
|
|
|
|
|
2018-08-23 17:48:11 +08:00
|
|
|
struct PostChildrenAction {
|
|
|
|
CXCursor cursor;
|
|
|
|
enum Action { Invalid, Ignore, Postpone } action;
|
|
|
|
};
|
|
|
|
using PostChildrenActions = SmallVector<PostChildrenAction, 0>;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
struct PostChildrenInfo {
|
|
|
|
CXCursor Cursor;
|
|
|
|
SourceRange CursorRange;
|
2013-02-08 09:12:25 +08:00
|
|
|
unsigned BeforeReachingCursorIdx;
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned BeforeChildrenTokenIdx;
|
2018-08-23 17:48:11 +08:00
|
|
|
PostChildrenActions ChildActions;
|
2012-12-18 22:30:41 +08:00
|
|
|
};
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<PostChildrenInfo, 8> PostChildrenInfos;
|
2013-11-27 13:50:55 +08:00
|
|
|
|
|
|
|
CXToken &getTok(unsigned Idx) {
|
|
|
|
assert(Idx < NumTokens);
|
|
|
|
return Tokens[Idx];
|
|
|
|
}
|
|
|
|
const CXToken &getTok(unsigned Idx) const {
|
|
|
|
assert(Idx < NumTokens);
|
|
|
|
return Tokens[Idx];
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
bool MoreTokens() const { return TokIdx < NumTokens; }
|
|
|
|
unsigned NextToken() const { return TokIdx; }
|
|
|
|
void AdvanceToken() { ++TokIdx; }
|
|
|
|
SourceLocation GetTokenLoc(unsigned tokI) {
|
2013-11-27 13:50:55 +08:00
|
|
|
return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
bool isFunctionMacroToken(unsigned tokI) const {
|
2013-11-27 13:50:55 +08:00
|
|
|
return getTok(tokI).int_data[3] != 0;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
SourceLocation getFunctionMacroTokenLoc(unsigned tokI) const {
|
2013-11-27 13:50:55 +08:00
|
|
|
return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[3]);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void annotateAndAdvanceTokens(CXCursor, RangeComparisonResult, SourceRange);
|
2013-02-08 09:12:25 +08:00
|
|
|
bool annotateAndAdvanceFunctionMacroTokens(CXCursor, RangeComparisonResult,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange);
|
|
|
|
|
|
|
|
public:
|
2013-01-08 03:16:30 +08:00
|
|
|
AnnotateTokensWorker(CXToken *tokens, CXCursor *cursors, unsigned numTokens,
|
2013-01-27 02:53:38 +08:00
|
|
|
CXTranslationUnit TU, SourceRange RegionOfInterest)
|
2013-01-08 03:16:30 +08:00
|
|
|
: Tokens(tokens), Cursors(cursors),
|
2012-12-18 22:30:41 +08:00
|
|
|
NumTokens(numTokens), TokIdx(0), PreprocessingTokIdx(0),
|
2013-01-27 02:53:38 +08:00
|
|
|
AnnotateVis(TU,
|
2012-12-18 22:30:41 +08:00
|
|
|
AnnotateTokensVisitor, this,
|
|
|
|
/*VisitPreprocessorLast=*/true,
|
|
|
|
/*VisitIncludedEntities=*/false,
|
|
|
|
RegionOfInterest,
|
|
|
|
/*VisitDeclsOnly=*/false,
|
|
|
|
AnnotateTokensPostChildrenVisitor),
|
2013-01-27 02:53:38 +08:00
|
|
|
SrcMgr(cxtu::getASTUnit(TU)->getSourceManager()),
|
2012-12-18 22:30:41 +08:00
|
|
|
HasContextSensitiveKeywords(false) { }
|
|
|
|
|
|
|
|
void VisitChildren(CXCursor C) { AnnotateVis.VisitChildren(C); }
|
|
|
|
enum CXChildVisitResult Visit(CXCursor cursor, CXCursor parent);
|
2018-08-23 17:48:11 +08:00
|
|
|
bool IsIgnoredChildCursor(CXCursor cursor) const;
|
|
|
|
PostChildrenActions DetermineChildActions(CXCursor Cursor) const;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool postVisitChildren(CXCursor cursor);
|
2018-08-23 17:48:11 +08:00
|
|
|
void HandlePostPonedChildCursors(const PostChildrenInfo &Info);
|
|
|
|
void HandlePostPonedChildCursor(CXCursor Cursor, unsigned StartTokenIndex);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void AnnotateTokens();
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Determine whether the annotator saw any cursors that have
|
2012-12-18 22:30:41 +08:00
|
|
|
/// context-sensitive keywords.
|
|
|
|
bool hasContextSensitiveKeywords() const {
|
|
|
|
return HasContextSensitiveKeywords;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AnnotateTokensWorker() {
|
|
|
|
assert(PostChildrenInfos.empty());
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
void AnnotateTokensWorker::AnnotateTokens() {
|
|
|
|
// Walk the AST within the region of interest, annotating tokens
|
|
|
|
// along the way.
|
|
|
|
AnnotateVis.visitFileRegion();
|
2013-01-08 03:16:30 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2018-08-23 17:48:11 +08:00
|
|
|
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)) {
|
2018-11-20 16:00:00 +08:00
|
|
|
const Decl *parentDecl = getCursorDecl(Cursor);
|
2018-08-23 17:48:11 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-08 03:16:30 +08:00
|
|
|
static inline void updateCursorAnnotation(CXCursor &Cursor,
|
|
|
|
const CXCursor &updateC) {
|
2013-02-08 09:12:25 +08:00
|
|
|
if (clang_isInvalid(updateC.kind) || !clang_isInvalid(Cursor.kind))
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
2013-01-08 03:16:30 +08:00
|
|
|
Cursor = updateC;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// It annotates and advances tokens with a cursor until the comparison
|
2012-12-18 22:30:41 +08:00
|
|
|
//// between the cursor location and the source range is the same as
|
|
|
|
/// \arg compResult.
|
|
|
|
///
|
|
|
|
/// Pass RangeBefore to annotate tokens with a cursor until a range is reached.
|
|
|
|
/// Pass RangeOverlap to annotate tokens inside a range.
|
|
|
|
void AnnotateTokensWorker::annotateAndAdvanceTokens(CXCursor updateC,
|
|
|
|
RangeComparisonResult compResult,
|
|
|
|
SourceRange range) {
|
|
|
|
while (MoreTokens()) {
|
|
|
|
const unsigned I = NextToken();
|
|
|
|
if (isFunctionMacroToken(I))
|
2013-02-08 09:12:25 +08:00
|
|
|
if (!annotateAndAdvanceFunctionMacroTokens(updateC, compResult, range))
|
|
|
|
return;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
SourceLocation TokLoc = GetTokenLoc(I);
|
|
|
|
if (LocationCompare(SrcMgr, TokLoc, range) == compResult) {
|
2013-01-08 03:16:30 +08:00
|
|
|
updateCursorAnnotation(Cursors[I], updateC);
|
2012-12-18 22:30:41 +08:00
|
|
|
AdvanceToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Special annotation handling for macro argument tokens.
|
2013-02-08 09:12:25 +08:00
|
|
|
/// \returns true if it advanced beyond all macro tokens, false otherwise.
|
|
|
|
bool AnnotateTokensWorker::annotateAndAdvanceFunctionMacroTokens(
|
2012-12-18 22:30:41 +08:00
|
|
|
CXCursor updateC,
|
|
|
|
RangeComparisonResult compResult,
|
|
|
|
SourceRange range) {
|
|
|
|
assert(MoreTokens());
|
|
|
|
assert(isFunctionMacroToken(NextToken()) &&
|
|
|
|
"Should be called only for macro arg tokens");
|
|
|
|
|
|
|
|
// This works differently than annotateAndAdvanceTokens; because expanded
|
|
|
|
// macro arguments can have arbitrary translation-unit source order, we do not
|
|
|
|
// advance the token index one by one until a token fails the range test.
|
|
|
|
// We only advance once past all of the macro arg tokens if all of them
|
|
|
|
// pass the range test. If one of them fails we keep the token index pointing
|
|
|
|
// at the start of the macro arg tokens so that the failing token will be
|
|
|
|
// annotated by a subsequent annotation try.
|
|
|
|
|
|
|
|
bool atLeastOneCompFail = false;
|
|
|
|
|
|
|
|
unsigned I = NextToken();
|
|
|
|
for (; I < NumTokens && isFunctionMacroToken(I); ++I) {
|
|
|
|
SourceLocation TokLoc = getFunctionMacroTokenLoc(I);
|
|
|
|
if (TokLoc.isFileID())
|
|
|
|
continue; // not macro arg token, it's parens or comma.
|
|
|
|
if (LocationCompare(SrcMgr, TokLoc, range) == compResult) {
|
|
|
|
if (clang_isInvalid(clang_getCursorKind(Cursors[I])))
|
|
|
|
Cursors[I] = updateC;
|
|
|
|
} else
|
|
|
|
atLeastOneCompFail = true;
|
|
|
|
}
|
|
|
|
|
2013-02-08 09:12:25 +08:00
|
|
|
if (atLeastOneCompFail)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TokIdx = I; // All of the tokens were handled, advance beyond all of them.
|
|
|
|
return true;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum CXChildVisitResult
|
|
|
|
AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) {
|
|
|
|
SourceRange cursorRange = getRawCursorExtent(cursor);
|
|
|
|
if (cursorRange.isInvalid())
|
|
|
|
return CXChildVisit_Recurse;
|
2018-08-23 17:48:11 +08:00
|
|
|
|
|
|
|
if (IsIgnoredChildCursor(cursor))
|
|
|
|
return CXChildVisit_Continue;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!HasContextSensitiveKeywords) {
|
|
|
|
// Objective-C properties can have context-sensitive keywords.
|
|
|
|
if (cursor.kind == CXCursor_ObjCPropertyDecl) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCPropertyDecl *Property
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<ObjCPropertyDecl>(getCursorDecl(cursor)))
|
|
|
|
HasContextSensitiveKeywords = Property->getPropertyAttributesAsWritten() != 0;
|
|
|
|
}
|
|
|
|
// Objective-C methods can have context-sensitive keywords.
|
|
|
|
else if (cursor.kind == CXCursor_ObjCInstanceMethodDecl ||
|
|
|
|
cursor.kind == CXCursor_ObjCClassMethodDecl) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCMethodDecl *Method
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(cursor))) {
|
|
|
|
if (Method->getObjCDeclQualifier())
|
|
|
|
HasContextSensitiveKeywords = true;
|
|
|
|
else {
|
2016-06-24 12:05:48 +08:00
|
|
|
for (const auto *P : Method->parameters()) {
|
2014-03-08 01:50:17 +08:00
|
|
|
if (P->getObjCDeclQualifier()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
HasContextSensitiveKeywords = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// C++ methods can have context-sensitive keywords.
|
|
|
|
else if (cursor.kind == CXCursor_CXXMethod) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const CXXMethodDecl *Method
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<CXXMethodDecl>(getCursorDecl(cursor))) {
|
|
|
|
if (Method->hasAttr<FinalAttr>() || Method->hasAttr<OverrideAttr>())
|
|
|
|
HasContextSensitiveKeywords = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// C++ classes can have context-sensitive keywords.
|
|
|
|
else if (cursor.kind == CXCursor_StructDecl ||
|
|
|
|
cursor.kind == CXCursor_ClassDecl ||
|
|
|
|
cursor.kind == CXCursor_ClassTemplate ||
|
|
|
|
cursor.kind == CXCursor_ClassTemplatePartialSpecialization) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const Decl *D = getCursorDecl(cursor))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (D->hasAttr<FinalAttr>())
|
|
|
|
HasContextSensitiveKeywords = true;
|
|
|
|
}
|
|
|
|
}
|
2013-06-05 02:24:30 +08:00
|
|
|
|
|
|
|
// Don't override a property annotation with its getter/setter method.
|
|
|
|
if (cursor.kind == CXCursor_ObjCInstanceMethodDecl &&
|
|
|
|
parent.kind == CXCursor_ObjCPropertyDecl)
|
|
|
|
return CXChildVisit_Continue;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (clang_isPreprocessing(cursor.kind)) {
|
|
|
|
// Items in the preprocessing record are kept separate from items in
|
|
|
|
// declarations, so we keep a separate token index.
|
|
|
|
unsigned SavedTokIdx = TokIdx;
|
|
|
|
TokIdx = PreprocessingTokIdx;
|
|
|
|
|
|
|
|
// Skip tokens up until we catch up to the beginning of the preprocessing
|
|
|
|
// entry.
|
|
|
|
while (MoreTokens()) {
|
|
|
|
const unsigned I = NextToken();
|
|
|
|
SourceLocation TokLoc = GetTokenLoc(I);
|
|
|
|
switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) {
|
|
|
|
case RangeBefore:
|
|
|
|
AdvanceToken();
|
|
|
|
continue;
|
|
|
|
case RangeAfter:
|
|
|
|
case RangeOverlap:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look at all of the tokens within this range.
|
|
|
|
while (MoreTokens()) {
|
|
|
|
const unsigned I = NextToken();
|
|
|
|
SourceLocation TokLoc = GetTokenLoc(I);
|
|
|
|
switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) {
|
|
|
|
case RangeBefore:
|
|
|
|
llvm_unreachable("Infeasible");
|
|
|
|
case RangeAfter:
|
|
|
|
break;
|
|
|
|
case RangeOverlap:
|
2013-02-14 02:33:28 +08:00
|
|
|
// For macro expansions, just note where the beginning of the macro
|
|
|
|
// expansion occurs.
|
|
|
|
if (cursor.kind == CXCursor_MacroExpansion) {
|
|
|
|
if (TokLoc == cursorRange.getBegin())
|
|
|
|
Cursors[I] = cursor;
|
|
|
|
AdvanceToken();
|
|
|
|
break;
|
|
|
|
}
|
2013-01-08 03:16:30 +08:00
|
|
|
// We may have already annotated macro names inside macro definitions.
|
|
|
|
if (Cursors[I].kind != CXCursor_MacroExpansion)
|
|
|
|
Cursors[I] = cursor;
|
2012-12-18 22:30:41 +08:00
|
|
|
AdvanceToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the preprocessing token index; restore the non-preprocessing
|
|
|
|
// token index.
|
|
|
|
PreprocessingTokIdx = TokIdx;
|
|
|
|
TokIdx = SavedTokIdx;
|
|
|
|
return CXChildVisit_Recurse;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursorRange.isInvalid())
|
|
|
|
return CXChildVisit_Continue;
|
2013-02-08 09:12:25 +08:00
|
|
|
|
|
|
|
unsigned BeforeReachingCursorIdx = NextToken();
|
2012-12-18 22:30:41 +08:00
|
|
|
const enum CXCursorKind cursorK = clang_getCursorKind(cursor);
|
|
|
|
const enum CXCursorKind K = clang_getCursorKind(parent);
|
|
|
|
const CXCursor updateC =
|
2013-02-08 09:12:25 +08:00
|
|
|
(clang_isInvalid(K) || K == CXCursor_TranslationUnit ||
|
|
|
|
// Attributes are annotated out-of-order, skip tokens until we reach it.
|
|
|
|
clang_isAttribute(cursor.kind))
|
2012-12-18 22:30:41 +08:00
|
|
|
? clang_getNullCursor() : parent;
|
|
|
|
|
|
|
|
annotateAndAdvanceTokens(updateC, RangeBefore, cursorRange);
|
|
|
|
|
|
|
|
// Avoid having the cursor of an expression "overwrite" the annotation of the
|
|
|
|
// variable declaration that it belongs to.
|
|
|
|
// This can happen for C++ constructor expressions whose range generally
|
|
|
|
// include the variable declaration, e.g.:
|
|
|
|
// MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr cursor.
|
2013-11-27 13:50:55 +08:00
|
|
|
if (clang_isExpression(cursorK) && MoreTokens()) {
|
2013-01-26 23:29:08 +08:00
|
|
|
const Expr *E = getCursorExpr(cursor);
|
2018-11-20 16:00:00 +08:00
|
|
|
if (const Decl *D = getCursorDecl(cursor)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
const unsigned I = NextToken();
|
2018-08-10 05:08:08 +08:00
|
|
|
if (E->getBeginLoc().isValid() && D->getLocation().isValid() &&
|
|
|
|
E->getBeginLoc() == D->getLocation() &&
|
|
|
|
E->getBeginLoc() == GetTokenLoc(I)) {
|
2013-01-08 03:16:30 +08:00
|
|
|
updateCursorAnnotation(Cursors[I], updateC);
|
2012-12-18 22:30:41 +08:00
|
|
|
AdvanceToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before recursing into the children keep some state that we are going
|
|
|
|
// to use in the AnnotateTokensWorker::postVisitChildren callback to do some
|
|
|
|
// extra work after the child nodes are visited.
|
|
|
|
// Note that we don't call VisitChildren here to avoid traversing statements
|
|
|
|
// code-recursively which can blow the stack.
|
|
|
|
|
|
|
|
PostChildrenInfo Info;
|
|
|
|
Info.Cursor = cursor;
|
|
|
|
Info.CursorRange = cursorRange;
|
2013-02-08 09:12:25 +08:00
|
|
|
Info.BeforeReachingCursorIdx = BeforeReachingCursorIdx;
|
2012-12-18 22:30:41 +08:00
|
|
|
Info.BeforeChildrenTokenIdx = NextToken();
|
2018-08-23 17:48:11 +08:00
|
|
|
Info.ChildActions = DetermineChildActions(cursor);
|
2012-12-18 22:30:41 +08:00
|
|
|
PostChildrenInfos.push_back(Info);
|
|
|
|
|
|
|
|
return CXChildVisit_Recurse;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AnnotateTokensWorker::postVisitChildren(CXCursor cursor) {
|
|
|
|
if (PostChildrenInfos.empty())
|
|
|
|
return false;
|
|
|
|
const PostChildrenInfo &Info = PostChildrenInfos.back();
|
|
|
|
if (!clang_equalCursors(Info.Cursor, cursor))
|
|
|
|
return false;
|
|
|
|
|
2018-08-23 17:48:11 +08:00
|
|
|
HandlePostPonedChildCursors(Info);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
const unsigned BeforeChildren = Info.BeforeChildrenTokenIdx;
|
|
|
|
const unsigned AfterChildren = NextToken();
|
|
|
|
SourceRange cursorRange = Info.CursorRange;
|
|
|
|
|
|
|
|
// Scan the tokens that are at the end of the cursor, but are not captured
|
|
|
|
// but the child cursors.
|
|
|
|
annotateAndAdvanceTokens(cursor, RangeOverlap, cursorRange);
|
|
|
|
|
|
|
|
// Scan the tokens that are at the beginning of the cursor, but are not
|
|
|
|
// capture by the child cursors.
|
|
|
|
for (unsigned I = BeforeChildren; I != AfterChildren; ++I) {
|
|
|
|
if (!clang_isInvalid(clang_getCursorKind(Cursors[I])))
|
|
|
|
break;
|
|
|
|
|
|
|
|
Cursors[I] = cursor;
|
|
|
|
}
|
|
|
|
|
2013-02-08 09:12:25 +08:00
|
|
|
// Attributes are annotated out-of-order, rewind TokIdx to when we first
|
|
|
|
// encountered the attribute cursor.
|
|
|
|
if (clang_isAttribute(cursor.kind))
|
|
|
|
TokIdx = Info.BeforeReachingCursorIdx;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
PostChildrenInfos.pop_back();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-23 17:48:11 +08:00
|
|
|
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) {
|
|
|
|
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++) {
|
2019-05-08 21:19:29 +08:00
|
|
|
const CXSourceRange CXRefNameRange = clang_getCursorReferenceNameRange(
|
|
|
|
Cursor, CXNameRange_WantQualifier, RefNameRangeNr);
|
2018-08-23 17:48:11 +08:00
|
|
|
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.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor,
|
|
|
|
CXCursor parent,
|
|
|
|
CXClientData client_data) {
|
|
|
|
return static_cast<AnnotateTokensWorker*>(client_data)->Visit(cursor, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool AnnotateTokensPostChildrenVisitor(CXCursor cursor,
|
|
|
|
CXClientData client_data) {
|
|
|
|
return static_cast<AnnotateTokensWorker*>(client_data)->
|
|
|
|
postVisitChildren(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Uses the macro expansions in the preprocessing record to find
|
2012-12-18 22:30:41 +08:00
|
|
|
/// and mark tokens that are macro arguments. This info is used by the
|
|
|
|
/// AnnotateTokensWorker.
|
|
|
|
class MarkMacroArgTokensVisitor {
|
|
|
|
SourceManager &SM;
|
|
|
|
CXToken *Tokens;
|
|
|
|
unsigned NumTokens;
|
|
|
|
unsigned CurIdx;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MarkMacroArgTokensVisitor(SourceManager &SM,
|
|
|
|
CXToken *tokens, unsigned numTokens)
|
|
|
|
: SM(SM), Tokens(tokens), NumTokens(numTokens), CurIdx(0) { }
|
|
|
|
|
|
|
|
CXChildVisitResult visit(CXCursor cursor, CXCursor parent) {
|
|
|
|
if (cursor.kind != CXCursor_MacroExpansion)
|
|
|
|
return CXChildVisit_Continue;
|
|
|
|
|
2013-01-08 03:16:25 +08:00
|
|
|
SourceRange macroRange = getCursorMacroExpansion(cursor).getSourceRange();
|
2012-12-18 22:30:41 +08:00
|
|
|
if (macroRange.getBegin() == macroRange.getEnd())
|
|
|
|
return CXChildVisit_Continue; // it's not a function macro.
|
|
|
|
|
|
|
|
for (; CurIdx < NumTokens; ++CurIdx) {
|
|
|
|
if (!SM.isBeforeInTranslationUnit(getTokenLoc(CurIdx),
|
|
|
|
macroRange.getBegin()))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CurIdx == NumTokens)
|
|
|
|
return CXChildVisit_Break;
|
|
|
|
|
|
|
|
for (; CurIdx < NumTokens; ++CurIdx) {
|
|
|
|
SourceLocation tokLoc = getTokenLoc(CurIdx);
|
|
|
|
if (!SM.isBeforeInTranslationUnit(tokLoc, macroRange.getEnd()))
|
|
|
|
break;
|
|
|
|
|
|
|
|
setFunctionMacroTokenLoc(CurIdx, SM.getMacroArgExpandedLocation(tokLoc));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CurIdx == NumTokens)
|
|
|
|
return CXChildVisit_Break;
|
|
|
|
|
|
|
|
return CXChildVisit_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-11-27 13:50:55 +08:00
|
|
|
CXToken &getTok(unsigned Idx) {
|
|
|
|
assert(Idx < NumTokens);
|
|
|
|
return Tokens[Idx];
|
|
|
|
}
|
|
|
|
const CXToken &getTok(unsigned Idx) const {
|
|
|
|
assert(Idx < NumTokens);
|
|
|
|
return Tokens[Idx];
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceLocation getTokenLoc(unsigned tokI) {
|
2013-11-27 13:50:55 +08:00
|
|
|
return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setFunctionMacroTokenLoc(unsigned tokI, SourceLocation loc) {
|
|
|
|
// The third field is reserved and currently not used. Use it here
|
|
|
|
// to mark macro arg expanded tokens with their expanded locations.
|
2013-11-27 13:50:55 +08:00
|
|
|
getTok(tokI).int_data[3] = loc.getRawEncoding();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
static CXChildVisitResult
|
|
|
|
MarkMacroArgTokensVisitorDelegate(CXCursor cursor, CXCursor parent,
|
|
|
|
CXClientData client_data) {
|
|
|
|
return static_cast<MarkMacroArgTokensVisitor*>(client_data)->visit(cursor,
|
|
|
|
parent);
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Used by \c annotatePreprocessorTokens.
|
2013-01-08 03:16:30 +08:00
|
|
|
/// \returns true if lexing was finished, false otherwise.
|
|
|
|
static bool lexNext(Lexer &Lex, Token &Tok,
|
|
|
|
unsigned &NextIdx, unsigned NumTokens) {
|
|
|
|
if (NextIdx >= NumTokens)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
++NextIdx;
|
|
|
|
Lex.LexFromRawLexer(Tok);
|
2015-12-28 23:24:08 +08:00
|
|
|
return Tok.is(tok::eof);
|
2013-01-08 03:16:30 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
static void annotatePreprocessorTokens(CXTranslationUnit TU,
|
|
|
|
SourceRange RegionOfInterest,
|
2013-01-08 03:16:30 +08:00
|
|
|
CXCursor *Cursors,
|
|
|
|
CXToken *Tokens,
|
|
|
|
unsigned NumTokens) {
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-08 03:16:32 +08:00
|
|
|
Preprocessor &PP = CXXUnit->getPreprocessor();
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceManager &SourceMgr = CXXUnit->getSourceManager();
|
|
|
|
std::pair<FileID, unsigned> BeginLocInfo
|
2013-02-14 02:33:28 +08:00
|
|
|
= SourceMgr.getDecomposedSpellingLoc(RegionOfInterest.getBegin());
|
2012-12-18 22:30:41 +08:00
|
|
|
std::pair<FileID, unsigned> EndLocInfo
|
2013-02-14 02:33:28 +08:00
|
|
|
= SourceMgr.getDecomposedSpellingLoc(RegionOfInterest.getEnd());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (BeginLocInfo.first != EndLocInfo.first)
|
|
|
|
return;
|
|
|
|
|
|
|
|
StringRef Buffer;
|
|
|
|
bool Invalid = false;
|
|
|
|
Buffer = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
|
|
|
|
if (Buffer.empty() || Invalid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
|
|
|
|
CXXUnit->getASTContext().getLangOpts(),
|
|
|
|
Buffer.begin(), Buffer.data() + BeginLocInfo.second,
|
|
|
|
Buffer.end());
|
|
|
|
Lex.SetCommentRetentionState(true);
|
|
|
|
|
2013-01-08 03:16:30 +08:00
|
|
|
unsigned NextIdx = 0;
|
2012-12-18 22:30:41 +08:00
|
|
|
// Lex tokens in raw mode until we hit the end of the range, to avoid
|
|
|
|
// entering #includes or expanding macros.
|
|
|
|
while (true) {
|
|
|
|
Token Tok;
|
2013-01-08 03:16:30 +08:00
|
|
|
if (lexNext(Lex, Tok, NextIdx, NumTokens))
|
|
|
|
break;
|
|
|
|
unsigned TokIdx = NextIdx-1;
|
|
|
|
assert(Tok.getLocation() ==
|
|
|
|
SourceLocation::getFromRawEncoding(Tokens[TokIdx].int_data[1]));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
reprocess:
|
|
|
|
if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) {
|
2013-01-08 03:16:30 +08:00
|
|
|
// We have found a preprocessing directive. Annotate the tokens
|
|
|
|
// appropriately.
|
2012-12-18 22:30:41 +08:00
|
|
|
//
|
|
|
|
// FIXME: Some simple tests here could identify macro definitions and
|
|
|
|
// #undefs, to provide specific cursor kinds for those.
|
2013-01-08 03:16:30 +08:00
|
|
|
|
|
|
|
SourceLocation BeginLoc = Tok.getLocation();
|
2013-01-08 03:16:32 +08:00
|
|
|
if (lexNext(Lex, Tok, NextIdx, NumTokens))
|
|
|
|
break;
|
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
MacroInfo *MI = nullptr;
|
2014-05-17 12:53:25 +08:00
|
|
|
if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "define") {
|
2013-01-08 03:16:32 +08:00
|
|
|
if (lexNext(Lex, Tok, NextIdx, NumTokens))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (Tok.is(tok::raw_identifier)) {
|
2014-05-17 12:53:25 +08:00
|
|
|
IdentifierInfo &II =
|
|
|
|
PP.getIdentifierTable().get(Tok.getRawIdentifier());
|
2013-01-08 03:16:32 +08:00
|
|
|
SourceLocation MappedTokLoc =
|
|
|
|
CXXUnit->mapLocationToPreamble(Tok.getLocation());
|
|
|
|
MI = getMacroInfo(II, MappedTokLoc, TU);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 03:16:30 +08:00
|
|
|
bool finished = false;
|
2012-12-18 22:30:41 +08:00
|
|
|
do {
|
2013-01-08 03:16:30 +08:00
|
|
|
if (lexNext(Lex, Tok, NextIdx, NumTokens)) {
|
|
|
|
finished = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-08 03:16:32 +08:00
|
|
|
// If we are in a macro definition, check if the token was ever a
|
|
|
|
// macro name and annotate it if that's the case.
|
|
|
|
if (MI) {
|
|
|
|
SourceLocation SaveLoc = Tok.getLocation();
|
|
|
|
Tok.setLocation(CXXUnit->mapLocationToPreamble(SaveLoc));
|
2015-05-04 10:25:31 +08:00
|
|
|
MacroDefinitionRecord *MacroDef =
|
|
|
|
checkForMacroInMacroDefinition(MI, Tok, TU);
|
2013-01-08 03:16:32 +08:00
|
|
|
Tok.setLocation(SaveLoc);
|
|
|
|
if (MacroDef)
|
2015-05-04 10:25:31 +08:00
|
|
|
Cursors[NextIdx - 1] =
|
|
|
|
MakeMacroExpansionCursor(MacroDef, Tok.getLocation(), TU);
|
2013-01-08 03:16:32 +08:00
|
|
|
}
|
2013-01-08 03:16:30 +08:00
|
|
|
} while (!Tok.isAtStartOfLine());
|
|
|
|
|
|
|
|
unsigned LastIdx = finished ? NextIdx-1 : NextIdx-2;
|
|
|
|
assert(TokIdx <= LastIdx);
|
|
|
|
SourceLocation EndLoc =
|
|
|
|
SourceLocation::getFromRawEncoding(Tokens[LastIdx].int_data[1]);
|
|
|
|
CXCursor Cursor =
|
|
|
|
MakePreprocessingDirectiveCursor(SourceRange(BeginLoc, EndLoc), TU);
|
|
|
|
|
|
|
|
for (; TokIdx <= LastIdx; ++TokIdx)
|
2013-01-08 03:16:32 +08:00
|
|
|
updateCursorAnnotation(Cursors[TokIdx], Cursor);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-08 03:16:30 +08:00
|
|
|
if (finished)
|
|
|
|
break;
|
|
|
|
goto reprocess;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This gets run a separate thread to avoid stack blowout.
|
2015-07-26 04:55:44 +08:00
|
|
|
static void clang_annotateTokensImpl(CXTranslationUnit TU, ASTUnit *CXXUnit,
|
|
|
|
CXToken *Tokens, unsigned NumTokens,
|
|
|
|
CXCursor *Cursors) {
|
2013-01-27 05:49:50 +08:00
|
|
|
CIndexer *CXXIdx = TU->CIdx;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing))
|
|
|
|
setThreadBackgroundPriority();
|
|
|
|
|
|
|
|
// Determine the region of interest, which contains all of the tokens.
|
|
|
|
SourceRange RegionOfInterest;
|
|
|
|
RegionOfInterest.setBegin(
|
|
|
|
cxloc::translateSourceLocation(clang_getTokenLocation(TU, Tokens[0])));
|
|
|
|
RegionOfInterest.setEnd(
|
|
|
|
cxloc::translateSourceLocation(clang_getTokenLocation(TU,
|
|
|
|
Tokens[NumTokens-1])));
|
|
|
|
|
|
|
|
// Relex the tokens within the source range to look for preprocessing
|
|
|
|
// directives.
|
2013-01-08 03:16:30 +08:00
|
|
|
annotatePreprocessorTokens(TU, RegionOfInterest, Cursors, Tokens, NumTokens);
|
2013-02-14 02:33:28 +08:00
|
|
|
|
|
|
|
// If begin location points inside a macro argument, set it to the expansion
|
|
|
|
// location so we can have the full context when annotating semantically.
|
|
|
|
{
|
|
|
|
SourceManager &SM = CXXUnit->getSourceManager();
|
|
|
|
SourceLocation Loc =
|
|
|
|
SM.getMacroArgExpandedLocation(RegionOfInterest.getBegin());
|
|
|
|
if (Loc.isMacroID())
|
|
|
|
RegionOfInterest.setBegin(SM.getExpansionLoc(Loc));
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (CXXUnit->getPreprocessor().getPreprocessingRecord()) {
|
|
|
|
// Search and mark tokens that are macro argument expansions.
|
|
|
|
MarkMacroArgTokensVisitor Visitor(CXXUnit->getSourceManager(),
|
|
|
|
Tokens, NumTokens);
|
|
|
|
CursorVisitor MacroArgMarker(TU,
|
|
|
|
MarkMacroArgTokensVisitorDelegate, &Visitor,
|
|
|
|
/*VisitPreprocessorLast=*/true,
|
|
|
|
/*VisitIncludedEntities=*/false,
|
|
|
|
RegionOfInterest);
|
|
|
|
MacroArgMarker.visitPreprocessedEntitiesInRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Annotate all of the source locations in the region of interest that map to
|
|
|
|
// a specific cursor.
|
2013-01-08 03:16:30 +08:00
|
|
|
AnnotateTokensWorker W(Tokens, Cursors, NumTokens, TU, RegionOfInterest);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// FIXME: We use a ridiculous stack size here because the data-recursion
|
|
|
|
// algorithm uses a large stack frame than the non-data recursive version,
|
|
|
|
// and AnnotationTokensWorker currently transforms the data-recursion
|
|
|
|
// algorithm back into a traditional recursion by explicitly calling
|
|
|
|
// VisitChildren(). We will need to remove this explicit recursive call.
|
|
|
|
W.AnnotateTokens();
|
|
|
|
|
|
|
|
// If we ran into any entities that involve context-sensitive keywords,
|
|
|
|
// take another pass through the tokens to mark them as such.
|
|
|
|
if (W.hasContextSensitiveKeywords()) {
|
|
|
|
for (unsigned I = 0; I != NumTokens; ++I) {
|
|
|
|
if (clang_getTokenKind(Tokens[I]) != CXToken_Identifier)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Cursors[I].kind == CXCursor_ObjCPropertyDecl) {
|
|
|
|
IdentifierInfo *II = static_cast<IdentifierInfo *>(Tokens[I].ptr_data);
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ObjCPropertyDecl *Property
|
2012-12-18 22:30:41 +08:00
|
|
|
= dyn_cast_or_null<ObjCPropertyDecl>(getCursorDecl(Cursors[I]))) {
|
|
|
|
if (Property->getPropertyAttributesAsWritten() != 0 &&
|
|
|
|
llvm::StringSwitch<bool>(II->getName())
|
|
|
|
.Case("readonly", true)
|
|
|
|
.Case("assign", true)
|
|
|
|
.Case("unsafe_unretained", true)
|
|
|
|
.Case("readwrite", true)
|
|
|
|
.Case("retain", true)
|
|
|
|
.Case("copy", true)
|
|
|
|
.Case("nonatomic", true)
|
|
|
|
.Case("atomic", true)
|
|
|
|
.Case("getter", true)
|
|
|
|
.Case("setter", true)
|
|
|
|
.Case("strong", true)
|
|
|
|
.Case("weak", true)
|
2016-06-01 07:22:04 +08:00
|
|
|
.Case("class", true)
|
2012-12-18 22:30:41 +08:00
|
|
|
.Default(false))
|
|
|
|
Tokens[I].int_data[0] = CXToken_Keyword;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cursors[I].kind == CXCursor_ObjCInstanceMethodDecl ||
|
|
|
|
Cursors[I].kind == CXCursor_ObjCClassMethodDecl) {
|
|
|
|
IdentifierInfo *II = static_cast<IdentifierInfo *>(Tokens[I].ptr_data);
|
|
|
|
if (llvm::StringSwitch<bool>(II->getName())
|
|
|
|
.Case("in", true)
|
|
|
|
.Case("out", true)
|
|
|
|
.Case("inout", true)
|
|
|
|
.Case("oneway", true)
|
|
|
|
.Case("bycopy", true)
|
|
|
|
.Case("byref", true)
|
|
|
|
.Default(false))
|
|
|
|
Tokens[I].int_data[0] = CXToken_Keyword;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cursors[I].kind == CXCursor_CXXFinalAttr ||
|
|
|
|
Cursors[I].kind == CXCursor_CXXOverrideAttr) {
|
|
|
|
Tokens[I].int_data[0] = CXToken_Keyword;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_annotateTokens(CXTranslationUnit TU,
|
|
|
|
CXToken *Tokens, unsigned NumTokens,
|
|
|
|
CXCursor *Cursors) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NumTokens == 0 || !Tokens || !Cursors) {
|
2013-01-11 02:54:52 +08:00
|
|
|
LOG_FUNC_SECTION { *Log << "<null input>"; }
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
2013-01-11 02:54:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG_FUNC_SECTION {
|
|
|
|
*Log << TU << ' ';
|
|
|
|
CXSourceLocation bloc = clang_getTokenLocation(TU, Tokens[0]);
|
|
|
|
CXSourceLocation eloc = clang_getTokenLocation(TU, Tokens[NumTokens-1]);
|
|
|
|
*Log << clang_getRange(bloc, eloc);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Any token we don't specifically annotate will have a NULL cursor.
|
|
|
|
CXCursor C = clang_getNullCursor();
|
|
|
|
for (unsigned I = 0; I != NumTokens; ++I)
|
|
|
|
Cursors[I] = C;
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!CXXUnit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
2015-07-26 04:55:44 +08:00
|
|
|
|
|
|
|
auto AnnotateTokensImpl = [=]() {
|
|
|
|
clang_annotateTokensImpl(TU, CXXUnit, Tokens, NumTokens, Cursors);
|
|
|
|
};
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::CrashRecoveryContext CRC;
|
2015-07-26 04:55:44 +08:00
|
|
|
if (!RunSafely(CRC, AnnotateTokensImpl, GetSafetyThreadStackSize() * 2)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
fprintf(stderr, "libclang: crash detected while annotating tokens\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Operations for querying linkage of a cursor.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
CXLinkageKind clang_getCursorLinkage(CXCursor cursor) {
|
|
|
|
if (!clang_isDeclaration(cursor.kind))
|
|
|
|
return CXLinkage_Invalid;
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = cxcursor::getCursorDecl(cursor);
|
|
|
|
if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
|
2013-05-13 08:12:11 +08:00
|
|
|
switch (ND->getLinkageInternal()) {
|
2013-05-26 01:16:20 +08:00
|
|
|
case NoLinkage:
|
|
|
|
case VisibleNoLinkage: return CXLinkage_NoLinkage;
|
2017-07-08 08:37:59 +08:00
|
|
|
case ModuleInternalLinkage:
|
2012-12-18 22:30:41 +08:00
|
|
|
case InternalLinkage: return CXLinkage_Internal;
|
|
|
|
case UniqueExternalLinkage: return CXLinkage_UniqueExternal;
|
2017-07-08 08:37:59 +08:00
|
|
|
case ModuleLinkage:
|
2012-12-18 22:30:41 +08:00
|
|
|
case ExternalLinkage: return CXLinkage_External;
|
|
|
|
};
|
|
|
|
|
|
|
|
return CXLinkage_Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2016-05-31 23:55:51 +08:00
|
|
|
// Operations for querying visibility of a cursor.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
CXVisibilityKind clang_getCursorVisibility(CXCursor cursor) {
|
|
|
|
if (!clang_isDeclaration(cursor.kind))
|
|
|
|
return CXVisibility_Invalid;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(cursor);
|
|
|
|
if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
|
|
|
|
switch (ND->getVisibility()) {
|
|
|
|
case HiddenVisibility: return CXVisibility_Hidden;
|
|
|
|
case ProtectedVisibility: return CXVisibility_Protected;
|
|
|
|
case DefaultVisibility: return CXVisibility_Default;
|
|
|
|
};
|
|
|
|
|
|
|
|
return CXVisibility_Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-12-18 22:30:41 +08:00
|
|
|
// Operations for querying language of a cursor.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static CXLanguageKind getDeclLanguage(const Decl *D) {
|
|
|
|
if (!D)
|
|
|
|
return CXLanguage_C;
|
|
|
|
|
|
|
|
switch (D->getKind()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case Decl::ImplicitParam:
|
|
|
|
case Decl::ObjCAtDefsField:
|
|
|
|
case Decl::ObjCCategory:
|
|
|
|
case Decl::ObjCCategoryImpl:
|
|
|
|
case Decl::ObjCCompatibleAlias:
|
|
|
|
case Decl::ObjCImplementation:
|
|
|
|
case Decl::ObjCInterface:
|
|
|
|
case Decl::ObjCIvar:
|
|
|
|
case Decl::ObjCMethod:
|
|
|
|
case Decl::ObjCProperty:
|
|
|
|
case Decl::ObjCPropertyImpl:
|
|
|
|
case Decl::ObjCProtocol:
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
case Decl::ObjCTypeParam:
|
2012-12-18 22:30:41 +08:00
|
|
|
return CXLanguage_ObjC;
|
|
|
|
case Decl::CXXConstructor:
|
|
|
|
case Decl::CXXConversion:
|
|
|
|
case Decl::CXXDestructor:
|
|
|
|
case Decl::CXXMethod:
|
|
|
|
case Decl::CXXRecord:
|
|
|
|
case Decl::ClassTemplate:
|
|
|
|
case Decl::ClassTemplatePartialSpecialization:
|
|
|
|
case Decl::ClassTemplateSpecialization:
|
|
|
|
case Decl::Friend:
|
|
|
|
case Decl::FriendTemplate:
|
|
|
|
case Decl::FunctionTemplate:
|
|
|
|
case Decl::LinkageSpec:
|
|
|
|
case Decl::Namespace:
|
|
|
|
case Decl::NamespaceAlias:
|
|
|
|
case Decl::NonTypeTemplateParm:
|
|
|
|
case Decl::StaticAssert:
|
|
|
|
case Decl::TemplateTemplateParm:
|
|
|
|
case Decl::TemplateTypeParm:
|
|
|
|
case Decl::UnresolvedUsingTypename:
|
|
|
|
case Decl::UnresolvedUsingValue:
|
|
|
|
case Decl::Using:
|
|
|
|
case Decl::UsingDirective:
|
|
|
|
case Decl::UsingShadow:
|
|
|
|
return CXLanguage_CPlusPlus;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CXLanguage_C;
|
|
|
|
}
|
|
|
|
|
2013-10-16 01:00:53 +08:00
|
|
|
static CXAvailabilityKind getCursorAvailabilityForDecl(const Decl *D) {
|
|
|
|
if (isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isDeleted())
|
2015-09-26 01:53:16 +08:00
|
|
|
return CXAvailability_NotAvailable;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-10-16 01:00:53 +08:00
|
|
|
switch (D->getAvailability()) {
|
|
|
|
case AR_Available:
|
|
|
|
case AR_NotYetIntroduced:
|
|
|
|
if (const EnumConstantDecl *EnumConst = dyn_cast<EnumConstantDecl>(D))
|
2013-10-16 02:53:18 +08:00
|
|
|
return getCursorAvailabilityForDecl(
|
|
|
|
cast<Decl>(EnumConst->getDeclContext()));
|
2013-10-16 01:00:53 +08:00
|
|
|
return CXAvailability_Available;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-10-16 01:00:53 +08:00
|
|
|
case AR_Deprecated:
|
|
|
|
return CXAvailability_Deprecated;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-10-16 01:00:53 +08:00
|
|
|
case AR_Unavailable:
|
|
|
|
return CXAvailability_NotAvailable;
|
|
|
|
}
|
2013-10-16 02:53:18 +08:00
|
|
|
|
|
|
|
llvm_unreachable("Unknown availability kind!");
|
2013-10-16 01:00:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum CXAvailabilityKind clang_getCursorAvailability(CXCursor cursor) {
|
|
|
|
if (clang_isDeclaration(cursor.kind))
|
|
|
|
if (const Decl *D = cxcursor::getCursorDecl(cursor))
|
|
|
|
return getCursorAvailabilityForDecl(D);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
return CXAvailability_Available;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CXVersion convertVersion(VersionTuple In) {
|
|
|
|
CXVersion Out = { -1, -1, -1 };
|
|
|
|
if (In.empty())
|
|
|
|
return Out;
|
|
|
|
|
|
|
|
Out.Major = In.getMajor();
|
|
|
|
|
2013-02-21 10:32:34 +08:00
|
|
|
Optional<unsigned> Minor = In.getMinor();
|
|
|
|
if (Minor.hasValue())
|
2012-12-18 22:30:41 +08:00
|
|
|
Out.Minor = *Minor;
|
|
|
|
else
|
|
|
|
return Out;
|
|
|
|
|
2013-02-21 10:32:34 +08:00
|
|
|
Optional<unsigned> Subminor = In.getSubminor();
|
|
|
|
if (Subminor.hasValue())
|
2012-12-18 22:30:41 +08:00
|
|
|
Out.Subminor = *Subminor;
|
|
|
|
|
|
|
|
return Out;
|
|
|
|
}
|
2013-10-16 01:00:53 +08:00
|
|
|
|
2017-06-13 03:06:30 +08:00
|
|
|
static void getCursorPlatformAvailabilityForDecl(
|
|
|
|
const Decl *D, int *always_deprecated, CXString *deprecated_message,
|
|
|
|
int *always_unavailable, CXString *unavailable_message,
|
|
|
|
SmallVectorImpl<AvailabilityAttr *> &AvailabilityAttrs) {
|
2013-10-16 01:00:53 +08:00
|
|
|
bool HadAvailAttr = false;
|
2014-03-09 06:19:01 +08:00
|
|
|
for (auto A : D->attrs()) {
|
|
|
|
if (DeprecatedAttr *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
|
2013-10-16 01:00:53 +08:00
|
|
|
HadAvailAttr = true;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (always_deprecated)
|
|
|
|
*always_deprecated = 1;
|
2014-04-24 13:16:45 +08:00
|
|
|
if (deprecated_message) {
|
2014-04-24 14:05:40 +08:00
|
|
|
clang_disposeString(*deprecated_message);
|
2013-02-02 10:19:29 +08:00
|
|
|
*deprecated_message = cxstring::createDup(Deprecated->getMessage());
|
2014-04-24 13:16:45 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-13 03:06:30 +08:00
|
|
|
|
2014-03-09 06:19:01 +08:00
|
|
|
if (UnavailableAttr *Unavailable = dyn_cast<UnavailableAttr>(A)) {
|
2013-10-16 01:00:53 +08:00
|
|
|
HadAvailAttr = true;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (always_unavailable)
|
|
|
|
*always_unavailable = 1;
|
|
|
|
if (unavailable_message) {
|
2014-04-24 14:05:40 +08:00
|
|
|
clang_disposeString(*unavailable_message);
|
2013-02-02 10:19:29 +08:00
|
|
|
*unavailable_message = cxstring::createDup(Unavailable->getMessage());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-13 03:06:30 +08:00
|
|
|
|
2014-03-09 06:19:01 +08:00
|
|
|
if (AvailabilityAttr *Avail = dyn_cast<AvailabilityAttr>(A)) {
|
2017-06-13 03:06:30 +08:00
|
|
|
AvailabilityAttrs.push_back(Avail);
|
2013-10-16 01:00:53 +08:00
|
|
|
HadAvailAttr = true;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
2013-10-16 01:00:53 +08:00
|
|
|
|
|
|
|
if (!HadAvailAttr)
|
|
|
|
if (const EnumConstantDecl *EnumConst = dyn_cast<EnumConstantDecl>(D))
|
|
|
|
return getCursorPlatformAvailabilityForDecl(
|
2017-06-13 03:06:30 +08:00
|
|
|
cast<Decl>(EnumConst->getDeclContext()), always_deprecated,
|
|
|
|
deprecated_message, always_unavailable, unavailable_message,
|
|
|
|
AvailabilityAttrs);
|
|
|
|
|
|
|
|
if (AvailabilityAttrs.empty())
|
|
|
|
return;
|
|
|
|
|
2018-09-27 06:16:28 +08:00
|
|
|
llvm::sort(AvailabilityAttrs,
|
2018-03-28 00:50:00 +08:00
|
|
|
[](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
|
|
|
|
return LHS->getPlatform()->getName() <
|
|
|
|
RHS->getPlatform()->getName();
|
2018-09-27 06:16:28 +08:00
|
|
|
});
|
2017-06-13 03:06:30 +08:00
|
|
|
ASTContext &Ctx = D->getASTContext();
|
|
|
|
auto It = std::unique(
|
|
|
|
AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
|
|
|
|
[&Ctx](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
|
|
|
|
if (LHS->getPlatform() != RHS->getPlatform())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (LHS->getIntroduced() == RHS->getIntroduced() &&
|
|
|
|
LHS->getDeprecated() == RHS->getDeprecated() &&
|
|
|
|
LHS->getObsoleted() == RHS->getObsoleted() &&
|
|
|
|
LHS->getMessage() == RHS->getMessage() &&
|
|
|
|
LHS->getReplacement() == RHS->getReplacement())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ((!LHS->getIntroduced().empty() && !RHS->getIntroduced().empty()) ||
|
|
|
|
(!LHS->getDeprecated().empty() && !RHS->getDeprecated().empty()) ||
|
|
|
|
(!LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (LHS->getIntroduced().empty() && !RHS->getIntroduced().empty())
|
|
|
|
LHS->setIntroduced(Ctx, RHS->getIntroduced());
|
|
|
|
|
|
|
|
if (LHS->getDeprecated().empty() && !RHS->getDeprecated().empty()) {
|
|
|
|
LHS->setDeprecated(Ctx, RHS->getDeprecated());
|
|
|
|
if (LHS->getMessage().empty())
|
|
|
|
LHS->setMessage(Ctx, RHS->getMessage());
|
|
|
|
if (LHS->getReplacement().empty())
|
|
|
|
LHS->setReplacement(Ctx, RHS->getReplacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()) {
|
|
|
|
LHS->setObsoleted(Ctx, RHS->getObsoleted());
|
|
|
|
if (LHS->getMessage().empty())
|
|
|
|
LHS->setMessage(Ctx, RHS->getMessage());
|
|
|
|
if (LHS->getReplacement().empty())
|
|
|
|
LHS->setReplacement(Ctx, RHS->getReplacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
AvailabilityAttrs.erase(It, AvailabilityAttrs.end());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-10-16 01:00:53 +08:00
|
|
|
|
2017-06-13 03:06:30 +08:00
|
|
|
int clang_getCursorPlatformAvailability(CXCursor cursor, int *always_deprecated,
|
2013-10-16 01:00:53 +08:00
|
|
|
CXString *deprecated_message,
|
|
|
|
int *always_unavailable,
|
|
|
|
CXString *unavailable_message,
|
|
|
|
CXPlatformAvailability *availability,
|
|
|
|
int availability_size) {
|
|
|
|
if (always_deprecated)
|
|
|
|
*always_deprecated = 0;
|
|
|
|
if (deprecated_message)
|
|
|
|
*deprecated_message = cxstring::createEmpty();
|
|
|
|
if (always_unavailable)
|
|
|
|
*always_unavailable = 0;
|
|
|
|
if (unavailable_message)
|
|
|
|
*unavailable_message = cxstring::createEmpty();
|
|
|
|
|
|
|
|
if (!clang_isDeclaration(cursor.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(cursor);
|
|
|
|
if (!D)
|
|
|
|
return 0;
|
|
|
|
|
2017-06-13 03:06:30 +08:00
|
|
|
SmallVector<AvailabilityAttr *, 8> AvailabilityAttrs;
|
|
|
|
getCursorPlatformAvailabilityForDecl(D, always_deprecated, deprecated_message,
|
|
|
|
always_unavailable, unavailable_message,
|
|
|
|
AvailabilityAttrs);
|
|
|
|
for (const auto &Avail :
|
|
|
|
llvm::enumerate(llvm::makeArrayRef(AvailabilityAttrs)
|
|
|
|
.take_front(availability_size))) {
|
|
|
|
availability[Avail.index()].Platform =
|
|
|
|
cxstring::createDup(Avail.value()->getPlatform()->getName());
|
|
|
|
availability[Avail.index()].Introduced =
|
|
|
|
convertVersion(Avail.value()->getIntroduced());
|
|
|
|
availability[Avail.index()].Deprecated =
|
|
|
|
convertVersion(Avail.value()->getDeprecated());
|
|
|
|
availability[Avail.index()].Obsoleted =
|
|
|
|
convertVersion(Avail.value()->getObsoleted());
|
|
|
|
availability[Avail.index()].Unavailable = Avail.value()->getUnavailable();
|
|
|
|
availability[Avail.index()].Message =
|
|
|
|
cxstring::createDup(Avail.value()->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return AvailabilityAttrs.size();
|
2013-10-16 01:00:53 +08:00
|
|
|
}
|
2017-06-13 03:06:30 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability) {
|
|
|
|
clang_disposeString(availability->Platform);
|
|
|
|
clang_disposeString(availability->Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXLanguageKind clang_getCursorLanguage(CXCursor cursor) {
|
|
|
|
if (clang_isDeclaration(cursor.kind))
|
|
|
|
return getDeclLanguage(cxcursor::getCursorDecl(cursor));
|
|
|
|
|
|
|
|
return CXLanguage_Invalid;
|
|
|
|
}
|
|
|
|
|
2017-09-13 10:15:09 +08:00
|
|
|
CXTLSKind clang_getCursorTLSKind(CXCursor cursor) {
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(cursor);
|
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
switch (VD->getTLSKind()) {
|
|
|
|
case VarDecl::TLS_None:
|
|
|
|
return CXTLS_None;
|
|
|
|
case VarDecl::TLS_Dynamic:
|
|
|
|
return CXTLS_Dynamic;
|
|
|
|
case VarDecl::TLS_Static:
|
|
|
|
return CXTLS_Static;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CXTLS_None;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// If the given cursor is the "templated" declaration
|
2018-04-06 23:14:32 +08:00
|
|
|
/// describing a class or function template, return the class or
|
2012-12-18 22:30:41 +08:00
|
|
|
/// function template.
|
2013-01-24 01:25:27 +08:00
|
|
|
static const Decl *maybeGetTemplateCursor(const Decl *D) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!D)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (FunctionTemplateDecl *FunTmpl = FD->getDescribedFunctionTemplate())
|
|
|
|
return FunTmpl;
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ClassTemplateDecl *ClassTmpl = RD->getDescribedClassTemplate())
|
|
|
|
return ClassTmpl;
|
|
|
|
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
2014-10-16 01:05:31 +08:00
|
|
|
|
|
|
|
enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor C) {
|
|
|
|
StorageClass sc = SC_None;
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
if (D) {
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
sc = FD->getStorageClass();
|
|
|
|
} else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
sc = VD->getStorageClass();
|
|
|
|
} else {
|
|
|
|
return CX_SC_Invalid;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return CX_SC_Invalid;
|
|
|
|
}
|
|
|
|
switch (sc) {
|
|
|
|
case SC_None:
|
|
|
|
return CX_SC_None;
|
|
|
|
case SC_Extern:
|
|
|
|
return CX_SC_Extern;
|
|
|
|
case SC_Static:
|
|
|
|
return CX_SC_Static;
|
|
|
|
case SC_PrivateExtern:
|
|
|
|
return CX_SC_PrivateExtern;
|
|
|
|
case SC_Auto:
|
|
|
|
return CX_SC_Auto;
|
|
|
|
case SC_Register:
|
|
|
|
return CX_SC_Register;
|
|
|
|
}
|
2014-10-16 02:03:26 +08:00
|
|
|
llvm_unreachable("Unhandled storage class!");
|
2014-10-16 01:05:31 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXCursor clang_getCursorSemanticParent(CXCursor cursor) {
|
|
|
|
if (clang_isDeclaration(cursor.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const Decl *D = getCursorDecl(cursor)) {
|
|
|
|
const DeclContext *DC = D->getDeclContext();
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!DC)
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
return MakeCXCursor(maybeGetTemplateCursor(cast<Decl>(DC)),
|
|
|
|
getCursorTU(cursor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isStatement(cursor.kind) || clang_isExpression(cursor.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const Decl *D = getCursorDecl(cursor))
|
2012-12-18 22:30:41 +08:00
|
|
|
return MakeCXCursor(D, getCursorTU(cursor));
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getCursorLexicalParent(CXCursor cursor) {
|
|
|
|
if (clang_isDeclaration(cursor.kind)) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const Decl *D = getCursorDecl(cursor)) {
|
|
|
|
const DeclContext *DC = D->getLexicalDeclContext();
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!DC)
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
return MakeCXCursor(maybeGetTemplateCursor(cast<Decl>(DC)),
|
|
|
|
getCursorTU(cursor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Note that we can't easily compute the lexical context of a
|
|
|
|
// statement or expression, so we return nothing.
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
CXFile clang_getIncludedFile(CXCursor cursor) {
|
|
|
|
if (cursor.kind != CXCursor_InclusionDirective)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2013-01-12 05:01:49 +08:00
|
|
|
const InclusionDirective *ID = getCursorInclusionDirective(cursor);
|
2013-01-23 23:56:07 +08:00
|
|
|
return const_cast<FileEntry *>(ID->getFile());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-04-19 06:15:49 +08:00
|
|
|
unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C, unsigned reserved) {
|
|
|
|
if (C.kind != CXCursor_ObjCPropertyDecl)
|
|
|
|
return CXObjCPropertyAttr_noattr;
|
|
|
|
|
|
|
|
unsigned Result = CXObjCPropertyAttr_noattr;
|
|
|
|
const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(getCursorDecl(C));
|
|
|
|
ObjCPropertyDecl::PropertyAttributeKind Attr =
|
|
|
|
PD->getPropertyAttributesAsWritten();
|
|
|
|
|
|
|
|
#define SET_CXOBJCPROP_ATTR(A) \
|
|
|
|
if (Attr & ObjCPropertyDecl::OBJC_PR_##A) \
|
|
|
|
Result |= CXObjCPropertyAttr_##A
|
|
|
|
SET_CXOBJCPROP_ATTR(readonly);
|
|
|
|
SET_CXOBJCPROP_ATTR(getter);
|
|
|
|
SET_CXOBJCPROP_ATTR(assign);
|
|
|
|
SET_CXOBJCPROP_ATTR(readwrite);
|
|
|
|
SET_CXOBJCPROP_ATTR(retain);
|
|
|
|
SET_CXOBJCPROP_ATTR(copy);
|
|
|
|
SET_CXOBJCPROP_ATTR(nonatomic);
|
|
|
|
SET_CXOBJCPROP_ATTR(setter);
|
|
|
|
SET_CXOBJCPROP_ATTR(atomic);
|
|
|
|
SET_CXOBJCPROP_ATTR(weak);
|
|
|
|
SET_CXOBJCPROP_ATTR(strong);
|
|
|
|
SET_CXOBJCPROP_ATTR(unsafe_unretained);
|
2016-06-01 07:22:04 +08:00
|
|
|
SET_CXOBJCPROP_ATTR(class);
|
2013-04-19 06:15:49 +08:00
|
|
|
#undef SET_CXOBJCPROP_ATTR
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2018-08-03 13:38:29 +08:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2013-04-19 07:29:12 +08:00
|
|
|
unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return CXObjCDeclQualifier_None;
|
|
|
|
|
|
|
|
Decl::ObjCDeclQualifier QT = Decl::OBJC_TQ_None;
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
|
|
|
|
QT = MD->getObjCDeclQualifier();
|
|
|
|
else if (const ParmVarDecl *PD = dyn_cast<ParmVarDecl>(D))
|
|
|
|
QT = PD->getObjCDeclQualifier();
|
|
|
|
if (QT == Decl::OBJC_TQ_None)
|
|
|
|
return CXObjCDeclQualifier_None;
|
|
|
|
|
|
|
|
unsigned Result = CXObjCDeclQualifier_None;
|
|
|
|
if (QT & Decl::OBJC_TQ_In) Result |= CXObjCDeclQualifier_In;
|
|
|
|
if (QT & Decl::OBJC_TQ_Inout) Result |= CXObjCDeclQualifier_Inout;
|
|
|
|
if (QT & Decl::OBJC_TQ_Out) Result |= CXObjCDeclQualifier_Out;
|
|
|
|
if (QT & Decl::OBJC_TQ_Bycopy) Result |= CXObjCDeclQualifier_Bycopy;
|
|
|
|
if (QT & Decl::OBJC_TQ_Byref) Result |= CXObjCDeclQualifier_Byref;
|
|
|
|
if (QT & Decl::OBJC_TQ_Oneway) Result |= CXObjCDeclQualifier_Oneway;
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2013-07-06 04:44:37 +08:00
|
|
|
unsigned clang_Cursor_isObjCOptional(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
|
|
|
|
return PD->getPropertyImplementation() == ObjCPropertyDecl::Optional;
|
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
|
|
|
|
return MD->getImplementationControl() == ObjCMethodDecl::Optional;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-19 07:53:05 +08:00
|
|
|
unsigned clang_Cursor_isVariadic(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
|
|
|
return FD->isVariadic();
|
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
|
|
|
|
return MD->isVariadic();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-10 23:10:36 +08:00
|
|
|
unsigned clang_Cursor_isExternalSymbol(CXCursor C,
|
|
|
|
CXString *language, CXString *definedIn,
|
|
|
|
unsigned *isGenerated) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
|
2017-05-20 12:11:33 +08:00
|
|
|
if (auto *attr = D->getExternalSourceSymbolAttr()) {
|
2017-05-10 23:10:36 +08:00
|
|
|
if (language)
|
|
|
|
*language = cxstring::createDup(attr->getLanguage());
|
|
|
|
if (definedIn)
|
|
|
|
*definedIn = cxstring::createDup(attr->getDefinedIn());
|
|
|
|
if (isGenerated)
|
|
|
|
*isGenerated = attr->getGeneratedDeclaration();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXSourceRange clang_Cursor_getCommentRange(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return clang_getNullRange();
|
|
|
|
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
ASTContext &Context = getCursorContext(C);
|
|
|
|
const RawComment *RC = Context.getRawCommentForAnyRedecl(D);
|
|
|
|
if (!RC)
|
|
|
|
return clang_getNullRange();
|
|
|
|
|
|
|
|
return cxloc::translateSourceRange(Context, RC->getSourceRange());
|
|
|
|
}
|
|
|
|
|
|
|
|
CXString clang_Cursor_getRawCommentText(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
2013-02-01 22:13:32 +08:00
|
|
|
return cxstring::createNull();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
ASTContext &Context = getCursorContext(C);
|
|
|
|
const RawComment *RC = Context.getRawCommentForAnyRedecl(D);
|
|
|
|
StringRef RawText = RC ? RC->getRawText(Context.getSourceManager()) :
|
|
|
|
StringRef();
|
|
|
|
|
|
|
|
// Don't duplicate the string because RawText points directly into source
|
|
|
|
// code.
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createRef(RawText);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXString clang_Cursor_getBriefCommentText(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
2013-02-01 22:13:32 +08:00
|
|
|
return cxstring::createNull();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
const Decl *D = getCursorDecl(C);
|
|
|
|
const ASTContext &Context = getCursorContext(C);
|
|
|
|
const RawComment *RC = Context.getRawCommentForAnyRedecl(D);
|
|
|
|
|
|
|
|
if (RC) {
|
|
|
|
StringRef BriefText = RC->getBriefText(Context);
|
|
|
|
|
|
|
|
// Don't duplicate the string because RawComment ensures that this memory
|
|
|
|
// will not go away.
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createRef(BriefText);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-02-01 22:13:32 +08:00
|
|
|
return cxstring::createNull();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXModule clang_Cursor_getModule(CXCursor C) {
|
|
|
|
if (C.kind == CXCursor_ModuleImportDecl) {
|
2013-01-24 01:25:27 +08:00
|
|
|
if (const ImportDecl *ImportD =
|
|
|
|
dyn_cast_or_null<ImportDecl>(getCursorDecl(C)))
|
2012-12-18 22:30:41 +08:00
|
|
|
return ImportD->getImportedModule();
|
|
|
|
}
|
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 07:14:37 +08:00
|
|
|
CXModule clang_getModuleForFile(CXTranslationUnit TU, CXFile File) {
|
|
|
|
if (isNotUsableTU(TU)) {
|
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!File)
|
|
|
|
return nullptr;
|
|
|
|
FileEntry *FE = static_cast<FileEntry *>(File);
|
|
|
|
|
|
|
|
ASTUnit &Unit = *cxtu::getASTUnit(TU);
|
|
|
|
HeaderSearch &HS = Unit.getPreprocessor().getHeaderSearchInfo();
|
|
|
|
ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE);
|
|
|
|
|
2014-10-23 10:01:19 +08:00
|
|
|
return Header.getModule();
|
2014-05-15 07:14:37 +08:00
|
|
|
}
|
|
|
|
|
2013-04-27 06:47:49 +08:00
|
|
|
CXFile clang_Module_getASTFile(CXModule CXMod) {
|
|
|
|
if (!CXMod)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-04-27 06:47:49 +08:00
|
|
|
Module *Mod = static_cast<Module*>(CXMod);
|
|
|
|
return const_cast<FileEntry *>(Mod->getASTFile());
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXModule clang_Module_getParent(CXModule CXMod) {
|
|
|
|
if (!CXMod)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
Module *Mod = static_cast<Module*>(CXMod);
|
|
|
|
return Mod->Parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXString clang_Module_getName(CXModule CXMod) {
|
|
|
|
if (!CXMod)
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
Module *Mod = static_cast<Module*>(CXMod);
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(Mod->Name);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXString clang_Module_getFullName(CXModule CXMod) {
|
|
|
|
if (!CXMod)
|
2013-02-01 22:21:22 +08:00
|
|
|
return cxstring::createEmpty();
|
2012-12-18 22:30:41 +08:00
|
|
|
Module *Mod = static_cast<Module*>(CXMod);
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(Mod->getFullModuleName());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 12:44:25 +08:00
|
|
|
int clang_Module_isSystem(CXModule CXMod) {
|
|
|
|
if (!CXMod)
|
|
|
|
return 0;
|
|
|
|
Module *Mod = static_cast<Module*>(CXMod);
|
|
|
|
return Mod->IsSystem;
|
|
|
|
}
|
|
|
|
|
2013-03-14 05:13:43 +08:00
|
|
|
unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit TU,
|
|
|
|
CXModule CXMod) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!CXMod)
|
2012-12-18 22:30:41 +08:00
|
|
|
return 0;
|
|
|
|
Module *Mod = static_cast<Module*>(CXMod);
|
2013-03-14 05:13:43 +08:00
|
|
|
FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager();
|
|
|
|
ArrayRef<const FileEntry *> TopHeaders = Mod->getTopHeaders(FileMgr);
|
|
|
|
return TopHeaders.size();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-03-14 05:13:43 +08:00
|
|
|
CXFile clang_Module_getTopLevelHeader(CXTranslationUnit TU,
|
|
|
|
CXModule CXMod, unsigned Index) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2014-02-11 22:34:14 +08:00
|
|
|
}
|
|
|
|
if (!CXMod)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
Module *Mod = static_cast<Module*>(CXMod);
|
2013-03-14 05:13:43 +08:00
|
|
|
FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-03-14 05:13:43 +08:00
|
|
|
ArrayRef<const FileEntry *> TopHeaders = Mod->getTopHeaders(FileMgr);
|
|
|
|
if (Index < TopHeaders.size())
|
|
|
|
return const_cast<FileEntry *>(TopHeaders[Index]);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// C++ AST instrospection.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-04-27 20:48:25 +08:00
|
|
|
unsigned clang_CXXConstructor_isDefaultConstructor(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
const CXXConstructorDecl *Constructor =
|
|
|
|
D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr;
|
|
|
|
return (Constructor && Constructor->isDefaultConstructor()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_CXXConstructor_isCopyConstructor(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
const CXXConstructorDecl *Constructor =
|
|
|
|
D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr;
|
|
|
|
return (Constructor && Constructor->isCopyConstructor()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_CXXConstructor_isMoveConstructor(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
const CXXConstructorDecl *Constructor =
|
|
|
|
D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr;
|
|
|
|
return (Constructor && Constructor->isMoveConstructor()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_CXXConstructor_isConvertingConstructor(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
const CXXConstructorDecl *Constructor =
|
|
|
|
D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr;
|
|
|
|
// Passing 'false' excludes constructors marked 'explicit'.
|
|
|
|
return (Constructor && Constructor->isConvertingConstructor(false)) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2015-10-27 23:50:22 +08:00
|
|
|
unsigned clang_CXXField_isMutable(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (const auto D = cxcursor::getCursorDecl(C))
|
|
|
|
if (const auto FD = dyn_cast_or_null<FieldDecl>(D))
|
|
|
|
return FD->isMutable() ? 1 : 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-18 02:38:35 +08:00
|
|
|
unsigned clang_CXXMethod_isPureVirtual(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
2014-01-22 15:29:52 +08:00
|
|
|
const CXXMethodDecl *Method =
|
2014-06-08 16:38:04 +08:00
|
|
|
D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
|
2013-05-18 02:38:35 +08:00
|
|
|
return (Method && Method->isVirtual() && Method->isPure()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2014-04-07 22:59:13 +08:00
|
|
|
unsigned clang_CXXMethod_isConst(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
const CXXMethodDecl *Method =
|
2014-06-08 16:38:04 +08:00
|
|
|
D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
|
2019-01-28 19:37:49 +08:00
|
|
|
return (Method && Method->getMethodQualifiers().hasConst()) ? 1 : 0;
|
2014-04-07 22:59:13 +08:00
|
|
|
}
|
|
|
|
|
2016-04-27 20:48:25 +08:00
|
|
|
unsigned clang_CXXMethod_isDefaulted(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
const CXXMethodDecl *Method =
|
|
|
|
D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
|
|
|
|
return (Method && Method->isDefaulted()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned clang_CXXMethod_isStatic(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
2014-01-22 15:29:52 +08:00
|
|
|
const CXXMethodDecl *Method =
|
2014-06-08 16:38:04 +08:00
|
|
|
D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
return (Method && Method->isStatic()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_CXXMethod_isVirtual(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
2014-01-22 15:29:52 +08:00
|
|
|
const CXXMethodDecl *Method =
|
2014-06-08 16:38:04 +08:00
|
|
|
D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
return (Method && Method->isVirtual()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2017-12-15 06:01:50 +08:00
|
|
|
unsigned clang_CXXRecord_isAbstract(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const auto *D = cxcursor::getCursorDecl(C);
|
|
|
|
const auto *RD = dyn_cast_or_null<CXXRecordDecl>(D);
|
|
|
|
if (RD)
|
|
|
|
RD = RD->getDefinition();
|
|
|
|
return (RD && RD->isAbstract()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2017-07-12 19:35:11 +08:00
|
|
|
unsigned clang_EnumDecl_isScoped(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
auto *Enum = dyn_cast_or_null<EnumDecl>(D);
|
|
|
|
return (Enum && Enum->isScoped()) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Attribute introspection.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
CXType clang_getIBOutletCollectionType(CXCursor C) {
|
|
|
|
if (C.kind != CXCursor_IBOutletCollectionAttr)
|
|
|
|
return cxtype::MakeCXType(QualType(), cxcursor::getCursorTU(C));
|
|
|
|
|
2013-01-27 02:08:08 +08:00
|
|
|
const IBOutletCollectionAttr *A =
|
2012-12-18 22:30:41 +08:00
|
|
|
cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(C));
|
|
|
|
|
|
|
|
return cxtype::MakeCXType(A->getInterface(), cxcursor::getCursorTU(C));
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Inspecting memory usage.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef std::vector<CXTUResourceUsageEntry> MemUsageEntries;
|
|
|
|
|
|
|
|
static inline void createCXTUResourceUsageEntry(MemUsageEntries &entries,
|
|
|
|
enum CXTUResourceUsageKind k,
|
|
|
|
unsigned long amount) {
|
|
|
|
CXTUResourceUsageEntry entry = { k, amount };
|
|
|
|
entries.push_back(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) {
|
|
|
|
const char *str = "";
|
|
|
|
switch (kind) {
|
|
|
|
case CXTUResourceUsage_AST:
|
|
|
|
str = "ASTContext: expressions, declarations, and types";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_Identifiers:
|
|
|
|
str = "ASTContext: identifiers";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_Selectors:
|
|
|
|
str = "ASTContext: selectors";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_GlobalCompletionResults:
|
|
|
|
str = "Code completion: cached global results";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_SourceManagerContentCache:
|
|
|
|
str = "SourceManager: content cache allocator";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_AST_SideTables:
|
|
|
|
str = "ASTContext: side tables";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_SourceManager_Membuffer_Malloc:
|
|
|
|
str = "SourceManager: malloc'ed memory buffers";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_SourceManager_Membuffer_MMap:
|
|
|
|
str = "SourceManager: mmap'ed memory buffers";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc:
|
|
|
|
str = "ExternalASTSource: malloc'ed memory buffers";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_ExternalASTSource_Membuffer_MMap:
|
|
|
|
str = "ExternalASTSource: mmap'ed memory buffers";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_Preprocessor:
|
|
|
|
str = "Preprocessor: malloc'ed memory";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_PreprocessingRecord:
|
|
|
|
str = "Preprocessor: PreprocessingRecord";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_SourceManager_DataStructures:
|
|
|
|
str = "SourceManager: data structures and tables";
|
|
|
|
break;
|
|
|
|
case CXTUResourceUsage_Preprocessor_HeaderSearch:
|
|
|
|
str = "Preprocessor: header search tables";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) {
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
2014-06-08 16:38:04 +08:00
|
|
|
CXTUResourceUsage usage = { (void*) nullptr, 0, nullptr };
|
2012-12-18 22:30:41 +08:00
|
|
|
return usage;
|
|
|
|
}
|
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *astUnit = cxtu::getASTUnit(TU);
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<MemUsageEntries> entries(new MemUsageEntries());
|
2012-12-18 22:30:41 +08:00
|
|
|
ASTContext &astContext = astUnit->getASTContext();
|
|
|
|
|
|
|
|
// How much memory is used by AST nodes and types?
|
|
|
|
createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_AST,
|
|
|
|
(unsigned long) astContext.getASTAllocatedMemory());
|
|
|
|
|
|
|
|
// How much memory is used by identifiers?
|
|
|
|
createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Identifiers,
|
|
|
|
(unsigned long) astContext.Idents.getAllocator().getTotalMemory());
|
|
|
|
|
|
|
|
// How much memory is used for selectors?
|
|
|
|
createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Selectors,
|
|
|
|
(unsigned long) astContext.Selectors.getTotalMemory());
|
|
|
|
|
|
|
|
// How much memory is used by ASTContext's side tables?
|
|
|
|
createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_AST_SideTables,
|
|
|
|
(unsigned long) astContext.getSideTableAllocatedMemory());
|
|
|
|
|
|
|
|
// How much memory is used for caching global code completion results?
|
|
|
|
unsigned long completionBytes = 0;
|
|
|
|
if (GlobalCodeCompletionAllocator *completionAllocator =
|
2014-07-05 11:08:06 +08:00
|
|
|
astUnit->getCachedCompletionAllocator().get()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
completionBytes = completionAllocator->getTotalMemory();
|
|
|
|
}
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_GlobalCompletionResults,
|
|
|
|
completionBytes);
|
|
|
|
|
|
|
|
// How much memory is being used by SourceManager's content cache?
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_SourceManagerContentCache,
|
|
|
|
(unsigned long) astContext.getSourceManager().getContentCacheSize());
|
|
|
|
|
|
|
|
// How much memory is being used by the MemoryBuffer's in SourceManager?
|
|
|
|
const SourceManager::MemoryBufferSizes &srcBufs =
|
|
|
|
astUnit->getSourceManager().getMemoryBufferSizes();
|
|
|
|
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_SourceManager_Membuffer_Malloc,
|
|
|
|
(unsigned long) srcBufs.malloc_bytes);
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_SourceManager_Membuffer_MMap,
|
|
|
|
(unsigned long) srcBufs.mmap_bytes);
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_SourceManager_DataStructures,
|
|
|
|
(unsigned long) astContext.getSourceManager()
|
|
|
|
.getDataStructureSizes());
|
|
|
|
|
|
|
|
// How much memory is being used by the ExternalASTSource?
|
|
|
|
if (ExternalASTSource *esrc = astContext.getExternalSource()) {
|
|
|
|
const ExternalASTSource::MemoryBufferSizes &sizes =
|
|
|
|
esrc->getMemoryBufferSizes();
|
|
|
|
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc,
|
|
|
|
(unsigned long) sizes.malloc_bytes);
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_ExternalASTSource_Membuffer_MMap,
|
|
|
|
(unsigned long) sizes.mmap_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// How much memory is being used by the Preprocessor?
|
|
|
|
Preprocessor &pp = astUnit->getPreprocessor();
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_Preprocessor,
|
|
|
|
pp.getTotalMemory());
|
|
|
|
|
|
|
|
if (PreprocessingRecord *pRec = pp.getPreprocessingRecord()) {
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_PreprocessingRecord,
|
|
|
|
pRec->getTotalMemory());
|
|
|
|
}
|
|
|
|
|
|
|
|
createCXTUResourceUsageEntry(*entries,
|
|
|
|
CXTUResourceUsage_Preprocessor_HeaderSearch,
|
|
|
|
pp.getHeaderSearchInfo().getTotalMemory());
|
2014-06-08 16:38:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXTUResourceUsage usage = { (void*) entries.get(),
|
|
|
|
(unsigned) entries->size(),
|
2015-01-23 23:36:10 +08:00
|
|
|
!entries->empty() ? &(*entries)[0] : nullptr };
|
2016-11-14 15:03:50 +08:00
|
|
|
(void)entries.release();
|
2012-12-18 22:30:41 +08:00
|
|
|
return usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage) {
|
|
|
|
if (usage.data)
|
|
|
|
delete (MemUsageEntries*) usage.data;
|
|
|
|
}
|
|
|
|
|
2013-12-07 02:55:45 +08:00
|
|
|
CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit TU, CXFile file) {
|
|
|
|
CXSourceRangeList *skipped = new CXSourceRangeList;
|
2013-12-05 16:19:32 +08:00
|
|
|
skipped->count = 0;
|
2014-06-08 16:38:04 +08:00
|
|
|
skipped->ranges = nullptr;
|
2013-12-05 16:19:32 +08:00
|
|
|
|
2014-02-11 23:02:48 +08:00
|
|
|
if (isNotUsableTU(TU)) {
|
2014-02-11 22:34:14 +08:00
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return skipped;
|
|
|
|
}
|
|
|
|
|
2013-12-05 16:19:32 +08:00
|
|
|
if (!file)
|
|
|
|
return skipped;
|
|
|
|
|
|
|
|
ASTUnit *astUnit = cxtu::getASTUnit(TU);
|
|
|
|
PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord();
|
|
|
|
if (!ppRec)
|
|
|
|
return skipped;
|
|
|
|
|
|
|
|
ASTContext &Ctx = astUnit->getASTContext();
|
|
|
|
SourceManager &sm = Ctx.getSourceManager();
|
|
|
|
FileEntry *fileEntry = static_cast<FileEntry *>(file);
|
|
|
|
FileID wantedFileID = sm.translateFile(fileEntry);
|
2018-01-16 03:14:16 +08:00
|
|
|
bool isMainFile = wantedFileID == sm.getMainFileID();
|
2013-12-05 16:19:32 +08:00
|
|
|
|
|
|
|
const std::vector<SourceRange> &SkippedRanges = ppRec->getSkippedRanges();
|
|
|
|
std::vector<SourceRange> wantedRanges;
|
|
|
|
for (std::vector<SourceRange>::const_iterator i = SkippedRanges.begin(), ei = SkippedRanges.end();
|
|
|
|
i != ei; ++i) {
|
|
|
|
if (sm.getFileID(i->getBegin()) == wantedFileID || sm.getFileID(i->getEnd()) == wantedFileID)
|
|
|
|
wantedRanges.push_back(*i);
|
2018-01-16 03:14:16 +08:00
|
|
|
else if (isMainFile && (astUnit->isInPreambleFileID(i->getBegin()) || astUnit->isInPreambleFileID(i->getEnd())))
|
|
|
|
wantedRanges.push_back(*i);
|
2013-12-05 16:19:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
skipped->count = wantedRanges.size();
|
|
|
|
skipped->ranges = new CXSourceRange[skipped->count];
|
|
|
|
for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
|
|
|
|
skipped->ranges[i] = cxloc::translateSourceRange(Ctx, wantedRanges[i]);
|
|
|
|
|
|
|
|
return skipped;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:43:55 +08:00
|
|
|
CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
|
|
|
|
CXSourceRangeList *skipped = new CXSourceRangeList;
|
|
|
|
skipped->count = 0;
|
|
|
|
skipped->ranges = nullptr;
|
|
|
|
|
|
|
|
if (isNotUsableTU(TU)) {
|
|
|
|
LOG_BAD_TU(TU);
|
|
|
|
return skipped;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTUnit *astUnit = cxtu::getASTUnit(TU);
|
|
|
|
PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord();
|
|
|
|
if (!ppRec)
|
|
|
|
return skipped;
|
|
|
|
|
|
|
|
ASTContext &Ctx = astUnit->getASTContext();
|
|
|
|
|
|
|
|
const std::vector<SourceRange> &SkippedRanges = ppRec->getSkippedRanges();
|
|
|
|
|
|
|
|
skipped->count = SkippedRanges.size();
|
|
|
|
skipped->ranges = new CXSourceRange[skipped->count];
|
|
|
|
for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
|
|
|
|
skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]);
|
|
|
|
|
|
|
|
return skipped;
|
|
|
|
}
|
|
|
|
|
2013-12-07 02:55:45 +08:00
|
|
|
void clang_disposeSourceRangeList(CXSourceRangeList *ranges) {
|
|
|
|
if (ranges) {
|
|
|
|
delete[] ranges->ranges;
|
|
|
|
delete ranges;
|
2013-12-05 16:19:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void clang::PrintLibclangResourceUsage(CXTranslationUnit TU) {
|
|
|
|
CXTUResourceUsage Usage = clang_getCXTUResourceUsage(TU);
|
|
|
|
for (unsigned I = 0; I != Usage.numEntries; ++I)
|
|
|
|
fprintf(stderr, " %s: %lu\n",
|
|
|
|
clang_getTUResourceUsageName(Usage.entries[I].kind),
|
|
|
|
Usage.entries[I].amount);
|
|
|
|
|
|
|
|
clang_disposeCXTUResourceUsage(Usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Misc. utility functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-07-04 05:34:13 +08:00
|
|
|
/// Default to using our desired 8 MB stack size on "safety" threads.
|
|
|
|
static unsigned SafetyStackThreadSize = DesiredStackSize;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
2015-07-26 04:55:44 +08:00
|
|
|
bool RunSafely(llvm::CrashRecoveryContext &CRC, llvm::function_ref<void()> Fn,
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Size) {
|
|
|
|
if (!Size)
|
|
|
|
Size = GetSafetyThreadStackSize();
|
2017-11-14 17:34:39 +08:00
|
|
|
if (Size && !getenv("LIBCLANG_NOTHREADS"))
|
2015-07-26 04:55:44 +08:00
|
|
|
return CRC.RunSafelyOnThread(Fn, Size);
|
|
|
|
return CRC.RunSafely(Fn);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned GetSafetyThreadStackSize() {
|
|
|
|
return SafetyStackThreadSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSafetyThreadStackSize(unsigned Value) {
|
|
|
|
SafetyStackThreadSize = Value;
|
|
|
|
}
|
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
void clang::setThreadBackgroundPriority() {
|
|
|
|
if (getenv("LIBCLANG_BGPRIO_DISABLE"))
|
|
|
|
return;
|
|
|
|
|
2019-04-22 03:18:41 +08:00
|
|
|
#if LLVM_ENABLE_THREADS
|
2019-04-18 21:49:20 +08:00
|
|
|
llvm::set_thread_priority(llvm::ThreadPriority::Background);
|
2019-04-22 03:18:41 +08:00
|
|
|
#endif
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void cxindex::printDiagsToStderr(ASTUnit *Unit) {
|
|
|
|
if (!Unit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),
|
|
|
|
DEnd = Unit->stored_diag_end();
|
|
|
|
D != DEnd; ++D) {
|
2014-04-23 01:40:12 +08:00
|
|
|
CXStoredDiagnostic Diag(*D, Unit->getLangOpts());
|
2012-12-18 22:30:41 +08:00
|
|
|
CXString Msg = clang_formatDiagnostic(&Diag,
|
|
|
|
clang_defaultDiagnosticDisplayOptions());
|
|
|
|
fprintf(stderr, "%s\n", clang_getCString(Msg));
|
|
|
|
clang_disposeString(Msg);
|
|
|
|
}
|
2018-04-28 03:11:14 +08:00
|
|
|
#ifdef _WIN32
|
2012-12-18 22:30:41 +08:00
|
|
|
// 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.
|
|
|
|
fflush(stderr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-08 03:16:25 +08:00
|
|
|
MacroInfo *cxindex::getMacroInfo(const IdentifierInfo &II,
|
|
|
|
SourceLocation MacroDefLoc,
|
|
|
|
CXTranslationUnit TU){
|
|
|
|
if (MacroDefLoc.isInvalid() || !TU)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
if (!II.hadMacroDefinition())
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *Unit = cxtu::getASTUnit(TU);
|
2013-01-08 03:16:30 +08:00
|
|
|
Preprocessor &PP = Unit->getPreprocessor();
|
2015-04-30 07:20:19 +08:00
|
|
|
MacroDirective *MD = PP.getLocalMacroDirectiveHistory(&II);
|
2013-03-27 01:17:01 +08:00
|
|
|
if (MD) {
|
|
|
|
for (MacroDirective::DefInfo
|
|
|
|
Def = MD->getDefinition(); Def; Def = Def.getPreviousDefinition()) {
|
|
|
|
if (MacroDefLoc == Def.getMacroInfo()->getDefinitionLoc())
|
|
|
|
return Def.getMacroInfo();
|
|
|
|
}
|
2013-01-08 03:16:25 +08:00
|
|
|
}
|
|
|
|
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
}
|
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
const MacroInfo *cxindex::getMacroInfo(const MacroDefinitionRecord *MacroDef,
|
2013-01-12 05:01:49 +08:00
|
|
|
CXTranslationUnit TU) {
|
2013-01-08 03:16:25 +08:00
|
|
|
if (!MacroDef || !TU)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
const IdentifierInfo *II = MacroDef->getName();
|
|
|
|
if (!II)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
return getMacroInfo(*II, MacroDef->getLocation(), TU);
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
MacroDefinitionRecord *
|
|
|
|
cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI, const Token &Tok,
|
|
|
|
CXTranslationUnit TU) {
|
2013-01-08 03:16:25 +08:00
|
|
|
if (!MI || !TU)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
if (Tok.isNot(tok::raw_identifier))
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
if (MI->getNumTokens() == 0)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
SourceRange DefRange(MI->getReplacementToken(0).getLocation(),
|
|
|
|
MI->getDefinitionEndLoc());
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *Unit = cxtu::getASTUnit(TU);
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
// Check that the token is inside the definition and not its argument list.
|
|
|
|
SourceManager &SM = Unit->getSourceManager();
|
|
|
|
if (SM.isBeforeInTranslationUnit(Tok.getLocation(), DefRange.getBegin()))
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
if (SM.isBeforeInTranslationUnit(DefRange.getEnd(), Tok.getLocation()))
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
Preprocessor &PP = Unit->getPreprocessor();
|
|
|
|
PreprocessingRecord *PPRec = PP.getPreprocessingRecord();
|
|
|
|
if (!PPRec)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
2014-05-17 12:53:25 +08:00
|
|
|
IdentifierInfo &II = PP.getIdentifierTable().get(Tok.getRawIdentifier());
|
2013-01-08 03:16:25 +08:00
|
|
|
if (!II.hadMacroDefinition())
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
// Check that the identifier is not one of the macro arguments.
|
2017-07-18 01:18:43 +08:00
|
|
|
if (std::find(MI->param_begin(), MI->param_end(), &II) != MI->param_end())
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
2015-04-30 07:20:19 +08:00
|
|
|
MacroDirective *InnerMD = PP.getLocalMacroDirectiveHistory(&II);
|
2013-02-20 08:54:57 +08:00
|
|
|
if (!InnerMD)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
2013-03-27 01:17:01 +08:00
|
|
|
return PPRec->findMacroDefinition(InnerMD->getMacroInfo());
|
2013-01-08 03:16:25 +08:00
|
|
|
}
|
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
MacroDefinitionRecord *
|
|
|
|
cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI, SourceLocation Loc,
|
|
|
|
CXTranslationUnit TU) {
|
2013-01-08 03:16:25 +08:00
|
|
|
if (Loc.isInvalid() || !MI || !TU)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
if (MI->getNumTokens() == 0)
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-27 02:53:38 +08:00
|
|
|
ASTUnit *Unit = cxtu::getASTUnit(TU);
|
2013-01-08 03:16:25 +08:00
|
|
|
Preprocessor &PP = Unit->getPreprocessor();
|
|
|
|
if (!PP.getPreprocessingRecord())
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
Loc = Unit->getSourceManager().getSpellingLoc(Loc);
|
|
|
|
Token Tok;
|
|
|
|
if (PP.getRawToken(Loc, Tok))
|
2014-06-08 16:38:04 +08:00
|
|
|
return nullptr;
|
2013-01-08 03:16:25 +08:00
|
|
|
|
|
|
|
return checkForMacroInMacroDefinition(MI, Tok, TU);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CXString clang_getClangVersion() {
|
2013-02-02 10:19:29 +08:00
|
|
|
return cxstring::createDup(getClangFullVersion());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-11 02:54:52 +08:00
|
|
|
Logger &cxindex::Logger::operator<<(CXTranslationUnit TU) {
|
|
|
|
if (TU) {
|
2013-01-27 02:53:38 +08:00
|
|
|
if (ASTUnit *Unit = cxtu::getASTUnit(TU)) {
|
2013-01-11 02:54:52 +08:00
|
|
|
LogOS << '<' << Unit->getMainFileName() << '>';
|
2013-03-06 04:21:14 +08:00
|
|
|
if (Unit->isMainFileAST())
|
|
|
|
LogOS << " (" << Unit->getASTFileName() << ')';
|
2013-01-11 02:54:52 +08:00
|
|
|
return *this;
|
|
|
|
}
|
2014-02-13 03:12:37 +08:00
|
|
|
} else {
|
|
|
|
LogOS << "<NULL TU>";
|
2013-01-11 02:54:52 +08:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-03-08 10:32:26 +08:00
|
|
|
Logger &cxindex::Logger::operator<<(const FileEntry *FE) {
|
|
|
|
*this << FE->getName();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger &cxindex::Logger::operator<<(CXCursor cursor) {
|
|
|
|
CXString cursorName = clang_getCursorDisplayName(cursor);
|
|
|
|
*this << cursorName << "@" << clang_getCursorLocation(cursor);
|
|
|
|
clang_disposeString(cursorName);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-01-11 02:54:52 +08:00
|
|
|
Logger &cxindex::Logger::operator<<(CXSourceLocation Loc) {
|
|
|
|
CXFile File;
|
|
|
|
unsigned Line, Column;
|
2014-06-08 16:38:04 +08:00
|
|
|
clang_getFileLocation(Loc, &File, &Line, &Column, nullptr);
|
2013-01-11 02:54:52 +08:00
|
|
|
CXString FileName = clang_getFileName(File);
|
|
|
|
*this << llvm::format("(%s:%d:%d)", clang_getCString(FileName), Line, Column);
|
|
|
|
clang_disposeString(FileName);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger &cxindex::Logger::operator<<(CXSourceRange range) {
|
|
|
|
CXSourceLocation BLoc = clang_getRangeStart(range);
|
|
|
|
CXSourceLocation ELoc = clang_getRangeEnd(range);
|
|
|
|
|
|
|
|
CXFile BFile;
|
|
|
|
unsigned BLine, BColumn;
|
2014-06-08 16:38:04 +08:00
|
|
|
clang_getFileLocation(BLoc, &BFile, &BLine, &BColumn, nullptr);
|
2013-01-11 02:54:52 +08:00
|
|
|
|
|
|
|
CXFile EFile;
|
|
|
|
unsigned ELine, EColumn;
|
2014-06-08 16:38:04 +08:00
|
|
|
clang_getFileLocation(ELoc, &EFile, &ELine, &EColumn, nullptr);
|
2013-01-11 02:54:52 +08:00
|
|
|
|
|
|
|
CXString BFileName = clang_getFileName(BFile);
|
|
|
|
if (BFile == EFile) {
|
|
|
|
*this << llvm::format("[%s %d:%d-%d:%d]", clang_getCString(BFileName),
|
|
|
|
BLine, BColumn, ELine, EColumn);
|
|
|
|
} else {
|
|
|
|
CXString EFileName = clang_getFileName(EFile);
|
|
|
|
*this << llvm::format("[%s:%d:%d - ", clang_getCString(BFileName),
|
|
|
|
BLine, BColumn)
|
|
|
|
<< llvm::format("%s:%d:%d]", clang_getCString(EFileName),
|
|
|
|
ELine, EColumn);
|
|
|
|
clang_disposeString(EFileName);
|
|
|
|
}
|
|
|
|
clang_disposeString(BFileName);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger &cxindex::Logger::operator<<(CXString Str) {
|
|
|
|
*this << clang_getCString(Str);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger &cxindex::Logger::operator<<(const llvm::format_object_base &Fmt) {
|
|
|
|
LogOS << Fmt;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-08-07 22:44:40 +08:00
|
|
|
static llvm::ManagedStatic<std::mutex> LoggingMutex;
|
2014-06-27 23:14:39 +08:00
|
|
|
|
2013-01-11 02:54:52 +08:00
|
|
|
cxindex::Logger::~Logger() {
|
2019-08-07 22:44:40 +08:00
|
|
|
std::lock_guard<std::mutex> L(*LoggingMutex);
|
2013-01-11 02:54:52 +08:00
|
|
|
|
|
|
|
static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();
|
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
raw_ostream &OS = llvm::errs();
|
2013-01-11 02:54:52 +08:00
|
|
|
OS << "[libclang:" << Name << ':';
|
|
|
|
|
2014-07-06 14:24:00 +08:00
|
|
|
#ifdef USE_DARWIN_THREADS
|
|
|
|
// TODO: Portability.
|
2013-01-11 02:54:52 +08:00
|
|
|
mach_port_t tid = pthread_mach_thread_np(pthread_self());
|
|
|
|
OS << tid << ':';
|
|
|
|
#endif
|
|
|
|
|
|
|
|
llvm::TimeRecord TR = llvm::TimeRecord::getCurrentTime();
|
|
|
|
OS << llvm::format("%7.4f] ", TR.getWallTime() - sBeginTR.getWallTime());
|
2015-03-10 15:33:23 +08:00
|
|
|
OS << Msg << '\n';
|
2013-01-11 02:54:52 +08:00
|
|
|
|
|
|
|
if (Trace) {
|
2015-03-06 03:15:09 +08:00
|
|
|
llvm::sys::PrintStackTrace(OS);
|
2013-01-11 02:54:52 +08:00
|
|
|
OS << "--------------------------------------------------\n";
|
|
|
|
}
|
|
|
|
}
|
2018-12-10 23:58:50 +08:00
|
|
|
|
|
|
|
#ifdef CLANG_TOOL_EXTRA_BUILD
|
|
|
|
// This anchor is used to force the linker to link the clang-tidy plugin.
|
|
|
|
extern volatile int ClangTidyPluginAnchorSource;
|
|
|
|
static int LLVM_ATTRIBUTE_UNUSED ClangTidyPluginAnchorDestination =
|
|
|
|
ClangTidyPluginAnchorSource;
|
|
|
|
|
|
|
|
// This anchor is used to force the linker to link the clang-include-fixer
|
|
|
|
// plugin.
|
|
|
|
extern volatile int ClangIncludeFixerPluginAnchorSource;
|
|
|
|
static int LLVM_ATTRIBUTE_UNUSED ClangIncludeFixerPluginAnchorDestination =
|
|
|
|
ClangIncludeFixerPluginAnchorSource;
|
|
|
|
#endif
|