2009-08-26 22:36:44 +00:00
|
|
|
//===- CIndex.cpp - Clang-C Source Indexing Library -----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2009-11-30 20:42:43 +00:00
|
|
|
//
|
2009-08-26 22:36:44 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-01-05 19:32:54 +00:00
|
|
|
// This file implements the main API hooks in the Clang-C Source Indexing
|
|
|
|
// library.
|
2009-08-26 22:36:44 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-05 19:32:54 +00:00
|
|
|
#include "CIndexer.h"
|
2010-01-15 20:35:54 +00:00
|
|
|
#include "CXCursor.h"
|
2010-08-26 01:42:22 +00:00
|
|
|
#include "CXType.h"
|
2010-01-25 22:34:44 +00:00
|
|
|
#include "CXSourceLocation.h"
|
2010-01-28 00:27:43 +00:00
|
|
|
#include "CIndexDiagnostic.h"
|
2010-01-05 19:32:54 +00:00
|
|
|
|
2010-01-22 22:44:15 +00:00
|
|
|
#include "clang/Basic/Version.h"
|
2010-01-28 00:56:43 +00:00
|
|
|
|
2009-08-28 15:28:48 +00:00
|
|
|
#include "clang/AST/DeclVisitor.h"
|
2009-09-22 19:25:29 +00:00
|
|
|
#include "clang/AST/StmtVisitor.h"
|
2010-01-21 16:28:34 +00:00
|
|
|
#include "clang/AST/TypeLocVisitor.h"
|
2010-04-12 19:45:50 +00:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Frontend/ASTUnit.h"
|
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
2010-01-28 00:56:43 +00:00
|
|
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
2010-01-06 23:43:31 +00:00
|
|
|
#include "clang/Lex/Lexer.h"
|
2010-04-12 19:45:50 +00:00
|
|
|
#include "clang/Lex/PreprocessingRecord.h"
|
2010-01-22 19:49:59 +00:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2010-09-09 21:42:20 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2010-08-18 18:43:14 +00:00
|
|
|
#include "llvm/Support/CrashRecoveryContext.h"
|
2010-10-08 19:30:33 +00:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2009-10-16 21:24:31 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2010-10-02 22:49:11 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-08-09 21:00:09 +00:00
|
|
|
#include "llvm/Support/Timer.h"
|
2010-09-24 21:18:36 +00:00
|
|
|
#include "llvm/System/Mutex.h"
|
2009-10-18 11:19:36 +00:00
|
|
|
#include "llvm/System/Program.h"
|
2010-02-18 23:07:20 +00:00
|
|
|
#include "llvm/System/Signals.h"
|
2010-09-24 21:18:36 +00:00
|
|
|
#include "llvm/System/Threading.h"
|
2009-10-19 21:44:57 +00:00
|
|
|
|
2010-03-13 21:22:49 +00:00
|
|
|
// Needed to define L_TMPNAM on some systems.
|
|
|
|
#include <cstdio>
|
|
|
|
|
2009-08-28 15:28:48 +00:00
|
|
|
using namespace clang;
|
2010-01-15 20:35:54 +00:00
|
|
|
using namespace clang::cxcursor;
|
2010-02-17 00:41:08 +00:00
|
|
|
using namespace clang::cxstring;
|
2009-08-28 15:28:48 +00:00
|
|
|
|
2010-01-06 03:42:32 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Crash Reporting.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-05-22 00:06:46 +00:00
|
|
|
#ifdef USE_CRASHTRACER
|
2010-01-06 03:42:32 +00:00
|
|
|
#include "clang/Analysis/Support/SaveAndRestore.h"
|
|
|
|
// Integrate with crash reporter.
|
2010-05-20 23:50:23 +00:00
|
|
|
static const char *__crashreporter_info__ = 0;
|
|
|
|
asm(".desc ___crashreporter_info__, 0x10");
|
2010-02-17 21:12:23 +00:00
|
|
|
#define NUM_CRASH_STRINGS 32
|
2010-01-07 22:49:05 +00:00
|
|
|
static unsigned crashtracer_counter = 0;
|
2010-01-07 23:13:53 +00:00
|
|
|
static unsigned crashtracer_counter_id[NUM_CRASH_STRINGS] = { 0 };
|
2010-01-07 22:49:05 +00:00
|
|
|
static const char *crashtracer_strings[NUM_CRASH_STRINGS] = { 0 };
|
|
|
|
static const char *agg_crashtracer_strings[NUM_CRASH_STRINGS] = { 0 };
|
|
|
|
|
|
|
|
static unsigned SetCrashTracerInfo(const char *str,
|
|
|
|
llvm::SmallString<1024> &AggStr) {
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-07 23:13:53 +00:00
|
|
|
unsigned slot = 0;
|
2010-01-07 22:49:05 +00:00
|
|
|
while (crashtracer_strings[slot]) {
|
|
|
|
if (++slot == NUM_CRASH_STRINGS)
|
|
|
|
slot = 0;
|
|
|
|
}
|
|
|
|
crashtracer_strings[slot] = str;
|
2010-01-07 23:13:53 +00:00
|
|
|
crashtracer_counter_id[slot] = ++crashtracer_counter;
|
2010-01-07 22:49:05 +00:00
|
|
|
|
|
|
|
// We need to create an aggregate string because multiple threads
|
|
|
|
// may be in this method at one time. The crash reporter string
|
|
|
|
// will attempt to overapproximate the set of in-flight invocations
|
|
|
|
// of this function. Race conditions can still cause this goal
|
|
|
|
// to not be achieved.
|
|
|
|
{
|
2010-02-17 00:41:40 +00:00
|
|
|
llvm::raw_svector_ostream Out(AggStr);
|
2010-01-07 22:49:05 +00:00
|
|
|
for (unsigned i = 0; i < NUM_CRASH_STRINGS; ++i)
|
|
|
|
if (crashtracer_strings[i]) Out << crashtracer_strings[i] << '\n';
|
|
|
|
}
|
|
|
|
__crashreporter_info__ = agg_crashtracer_strings[slot] = AggStr.c_str();
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ResetCrashTracerInfo(unsigned slot) {
|
2010-01-07 23:13:53 +00:00
|
|
|
unsigned max_slot = 0;
|
|
|
|
unsigned max_value = 0;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-07 23:13:53 +00:00
|
|
|
crashtracer_strings[slot] = agg_crashtracer_strings[slot] = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0 ; i < NUM_CRASH_STRINGS; ++i)
|
|
|
|
if (agg_crashtracer_strings[i] &&
|
|
|
|
crashtracer_counter_id[i] > max_value) {
|
|
|
|
max_slot = i;
|
|
|
|
max_value = crashtracer_counter_id[i];
|
2010-01-07 22:49:05 +00:00
|
|
|
}
|
2010-01-07 23:13:53 +00:00
|
|
|
|
|
|
|
__crashreporter_info__ = agg_crashtracer_strings[max_slot];
|
2010-01-07 22:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class ArgsCrashTracerInfo {
|
|
|
|
llvm::SmallString<1024> CrashString;
|
|
|
|
llvm::SmallString<1024> AggregateString;
|
|
|
|
unsigned crashtracerSlot;
|
|
|
|
public:
|
|
|
|
ArgsCrashTracerInfo(llvm::SmallVectorImpl<const char*> &Args)
|
|
|
|
: crashtracerSlot(0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
llvm::raw_svector_ostream Out(CrashString);
|
2010-03-05 22:43:25 +00:00
|
|
|
Out << "ClangCIndex [" << getClangFullVersion() << "]"
|
|
|
|
<< "[createTranslationUnitFromSourceFile]: clang";
|
2010-01-07 22:49:05 +00:00
|
|
|
for (llvm::SmallVectorImpl<const char*>::iterator I=Args.begin(),
|
|
|
|
E=Args.end(); I!=E; ++I)
|
|
|
|
Out << ' ' << *I;
|
|
|
|
}
|
|
|
|
crashtracerSlot = SetCrashTracerInfo(CrashString.c_str(),
|
|
|
|
AggregateString);
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-07 22:49:05 +00:00
|
|
|
~ArgsCrashTracerInfo() {
|
|
|
|
ResetCrashTracerInfo(crashtracerSlot);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|
2010-01-06 03:42:32 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \brief The result of comparing two source ranges.
|
|
|
|
enum RangeComparisonResult {
|
|
|
|
/// \brief Either the ranges overlap or one of the ranges is invalid.
|
|
|
|
RangeOverlap,
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \brief The first range ends before the second range starts.
|
|
|
|
RangeBefore,
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \brief The first range starts after the second range ends.
|
|
|
|
RangeAfter
|
|
|
|
};
|
|
|
|
|
2010-02-17 00:41:40 +00:00
|
|
|
/// \brief Compare two source ranges to determine their relative position in
|
2010-01-22 19:49:59 +00:00
|
|
|
/// the translation unit.
|
2010-02-17 00:41:40 +00:00
|
|
|
static RangeComparisonResult RangeCompare(SourceManager &SM,
|
|
|
|
SourceRange R1,
|
2010-01-22 19:49:59 +00:00
|
|
|
SourceRange R2) {
|
|
|
|
assert(R1.isValid() && "First range is invalid?");
|
|
|
|
assert(R2.isValid() && "Second range is invalid?");
|
2010-07-22 20:22:31 +00:00
|
|
|
if (R1.getEnd() != R2.getBegin() &&
|
2010-02-14 10:02:57 +00:00
|
|
|
SM.isBeforeInTranslationUnit(R1.getEnd(), R2.getBegin()))
|
2010-01-22 19:49:59 +00:00
|
|
|
return RangeBefore;
|
2010-07-22 20:22:31 +00:00
|
|
|
if (R2.getEnd() != R1.getBegin() &&
|
2010-02-14 10:02:57 +00:00
|
|
|
SM.isBeforeInTranslationUnit(R2.getEnd(), R1.getBegin()))
|
2010-01-22 19:49:59 +00:00
|
|
|
return RangeAfter;
|
|
|
|
return RangeOverlap;
|
|
|
|
}
|
|
|
|
|
2010-05-05 00:55:23 +00:00
|
|
|
/// \brief Determine if a source location falls within, before, or after a
|
|
|
|
/// 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?");
|
2010-07-22 20:22:31 +00:00
|
|
|
if (L == R.getBegin() || L == R.getEnd())
|
2010-05-05 00:55:23 +00:00
|
|
|
return RangeOverlap;
|
|
|
|
if (SM.isBeforeInTranslationUnit(L, R.getBegin()))
|
|
|
|
return RangeBefore;
|
|
|
|
if (SM.isBeforeInTranslationUnit(R.getEnd(), L))
|
|
|
|
return RangeAfter;
|
|
|
|
return RangeOverlap;
|
|
|
|
}
|
|
|
|
|
2010-02-14 01:47:29 +00:00
|
|
|
/// \brief Translate a Clang source range into a CIndex source range.
|
|
|
|
///
|
|
|
|
/// Clang internally represents ranges where the end location points to the
|
|
|
|
/// start of the token at the end. However, for external clients it is more
|
|
|
|
/// useful to have a CXSourceRange be a proper half-open interval. This routine
|
|
|
|
/// does the appropriate translation.
|
2010-02-17 00:41:40 +00:00
|
|
|
CXSourceRange cxloc::translateSourceRange(const SourceManager &SM,
|
2010-02-14 01:47:29 +00:00
|
|
|
const LangOptions &LangOpts,
|
2010-06-18 22:45:06 +00:00
|
|
|
const CharSourceRange &R) {
|
2010-02-14 01:47:29 +00:00
|
|
|
// We want the last character in this location, so we will adjust the
|
Implement serialization and lazy deserialization of the preprocessing
record (which includes all macro instantiations and definitions). As
with all lay deserialization, this introduces a new external source
(here, an external preprocessing record source) that loads all of the
preprocessed entities prior to iterating over the entities.
The preprocessing record is an optional part of the precompiled header
that is disabled by default (enabled with
-detailed-preprocessing-record). When the preprocessor given to the
PCH writer has a preprocessing record, that record is written into the
PCH file. When the PCH reader is given a PCH file that contains a
preprocessing record, it will be lazily loaded (which, effectively,
implicitly adds -detailed-preprocessing-record). This is the first
case where we have sections of the precompiled header that are
added/removed based on a compilation flag, which is
unfortunate. However, this data consumes ~550k in the PCH file for
Cocoa.h (out of ~9.9MB), and there is a non-trivial cost to gathering
this detailed preprocessing information, so it's too expensive to turn
on by default. In the future, we should investigate a better encoding
of this information.
llvm-svn: 99002
2010-03-19 21:51:54 +00:00
|
|
|
// location accordingly.
|
|
|
|
// FIXME: How do do this with a macro instantiation location?
|
2010-02-14 01:47:29 +00:00
|
|
|
SourceLocation EndLoc = R.getEnd();
|
2010-06-18 22:45:06 +00:00
|
|
|
if (R.isTokenRange() && !EndLoc.isInvalid() && EndLoc.isFileID()) {
|
Implement serialization and lazy deserialization of the preprocessing
record (which includes all macro instantiations and definitions). As
with all lay deserialization, this introduces a new external source
(here, an external preprocessing record source) that loads all of the
preprocessed entities prior to iterating over the entities.
The preprocessing record is an optional part of the precompiled header
that is disabled by default (enabled with
-detailed-preprocessing-record). When the preprocessor given to the
PCH writer has a preprocessing record, that record is written into the
PCH file. When the PCH reader is given a PCH file that contains a
preprocessing record, it will be lazily loaded (which, effectively,
implicitly adds -detailed-preprocessing-record). This is the first
case where we have sections of the precompiled header that are
added/removed based on a compilation flag, which is
unfortunate. However, this data consumes ~550k in the PCH file for
Cocoa.h (out of ~9.9MB), and there is a non-trivial cost to gathering
this detailed preprocessing information, so it's too expensive to turn
on by default. In the future, we should investigate a better encoding
of this information.
llvm-svn: 99002
2010-03-19 21:51:54 +00:00
|
|
|
unsigned Length = Lexer::MeasureTokenLength(EndLoc, SM, LangOpts);
|
2010-02-14 01:47:29 +00:00
|
|
|
EndLoc = EndLoc.getFileLocWithOffset(Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceRange Result = { { (void *)&SM, (void *)&LangOpts },
|
|
|
|
R.getBegin().getRawEncoding(),
|
|
|
|
EndLoc.getRawEncoding() };
|
|
|
|
return Result;
|
|
|
|
}
|
2010-01-19 21:36:55 +00:00
|
|
|
|
2010-01-06 03:42:32 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-01-22 19:49:59 +00:00
|
|
|
// Cursor visitor.
|
2010-01-06 03:42:32 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-08-31 00:59:03 +00:00
|
|
|
namespace {
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
// Cursor visitor.
|
2010-01-21 16:28:34 +00:00
|
|
|
class CursorVisitor : public DeclVisitor<CursorVisitor, bool>,
|
2010-01-21 23:27:09 +00:00
|
|
|
public TypeLocVisitor<CursorVisitor, bool>,
|
|
|
|
public StmtVisitor<CursorVisitor, bool>
|
2010-01-21 16:28:34 +00:00
|
|
|
{
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \brief The translation unit we are traversing.
|
2010-01-20 23:57:43 +00:00
|
|
|
ASTUnit *TU;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \brief The parent cursor whose children we are traversing.
|
2010-01-20 20:59:29 +00:00
|
|
|
CXCursor Parent;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \brief The declaration that serves at the parent of any statement or
|
|
|
|
/// expression nodes.
|
2010-01-21 17:29:07 +00:00
|
|
|
Decl *StmtParent;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \brief The visitor function.
|
2010-01-20 20:59:29 +00:00
|
|
|
CXCursorVisitor Visitor;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \brief The opaque client data, to be passed along to the visitor.
|
2010-01-20 20:59:29 +00:00
|
|
|
CXClientData ClientData;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2009-10-16 20:01:17 +00:00
|
|
|
// MaxPCHLevel - the maximum PCH level of declarations that we will pass on
|
|
|
|
// to the visitor. Declarations with a PCH level greater than this value will
|
|
|
|
// be suppressed.
|
|
|
|
unsigned MaxPCHLevel;
|
2010-01-22 19:49:59 +00:00
|
|
|
|
|
|
|
/// \brief When valid, a source range to which the cursor should restrict
|
|
|
|
/// its search.
|
|
|
|
SourceRange RegionOfInterest;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
using DeclVisitor<CursorVisitor, bool>::Visit;
|
2010-01-21 16:28:34 +00:00
|
|
|
using TypeLocVisitor<CursorVisitor, bool>::Visit;
|
2010-01-21 23:27:09 +00:00
|
|
|
using StmtVisitor<CursorVisitor, bool>::Visit;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
/// \brief Determine whether this particular source range comes before, comes
|
|
|
|
/// after, or overlaps the region of interest.
|
2010-01-22 19:49:59 +00:00
|
|
|
///
|
2010-02-14 10:02:57 +00:00
|
|
|
/// \param R a half-open source range retrieved from the abstract syntax tree.
|
2010-02-17 00:41:40 +00:00
|
|
|
RangeComparisonResult CompareRegionOfInterest(SourceRange R);
|
|
|
|
|
2010-05-13 00:25:00 +00:00
|
|
|
class SetParentRAII {
|
|
|
|
CXCursor &Parent;
|
|
|
|
Decl *&StmtParent;
|
|
|
|
CXCursor OldParent;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SetParentRAII(CXCursor &Parent, Decl *&StmtParent, CXCursor NewParent)
|
|
|
|
: Parent(Parent), StmtParent(StmtParent), OldParent(Parent)
|
|
|
|
{
|
|
|
|
Parent = NewParent;
|
|
|
|
if (clang_isDeclaration(Parent.kind))
|
|
|
|
StmtParent = getCursorDecl(Parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
~SetParentRAII() {
|
|
|
|
Parent = OldParent;
|
|
|
|
if (clang_isDeclaration(Parent.kind))
|
|
|
|
StmtParent = getCursorDecl(Parent);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
public:
|
2010-02-17 00:41:40 +00:00
|
|
|
CursorVisitor(ASTUnit *TU, CXCursorVisitor Visitor, CXClientData ClientData,
|
|
|
|
unsigned MaxPCHLevel,
|
2010-01-22 19:49:59 +00:00
|
|
|
SourceRange RegionOfInterest = SourceRange())
|
2010-02-17 00:41:40 +00:00
|
|
|
: TU(TU), Visitor(Visitor), ClientData(ClientData),
|
2010-01-22 19:49:59 +00:00
|
|
|
MaxPCHLevel(MaxPCHLevel), RegionOfInterest(RegionOfInterest)
|
2010-01-20 20:59:29 +00:00
|
|
|
{
|
|
|
|
Parent.kind = CXCursor_NoDeclFound;
|
|
|
|
Parent.data[0] = 0;
|
|
|
|
Parent.data[1] = 0;
|
|
|
|
Parent.data[2] = 0;
|
2010-01-21 17:29:07 +00:00
|
|
|
StmtParent = 0;
|
2010-01-20 20:59:29 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false);
|
2010-03-20 00:41:21 +00:00
|
|
|
|
|
|
|
std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
|
|
|
|
getPreprocessedEntities();
|
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
bool VisitChildren(CXCursor Parent);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-21 16:28:34 +00:00
|
|
|
// Declaration visitors
|
2010-02-18 05:46:33 +00:00
|
|
|
bool VisitAttributes(Decl *D);
|
2010-04-11 21:47:37 +00:00
|
|
|
bool VisitBlockDecl(BlockDecl *B);
|
2010-08-27 21:34:58 +00:00
|
|
|
bool VisitCXXRecordDecl(CXXRecordDecl *D);
|
2010-01-20 20:59:29 +00:00
|
|
|
bool VisitDeclContext(DeclContext *DC);
|
2010-02-18 22:36:18 +00:00
|
|
|
bool VisitTranslationUnitDecl(TranslationUnitDecl *D);
|
|
|
|
bool VisitTypedefDecl(TypedefDecl *D);
|
|
|
|
bool VisitTagDecl(TagDecl *D);
|
2010-09-01 17:32:36 +00:00
|
|
|
bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D);
|
2010-08-31 19:31:58 +00:00
|
|
|
bool VisitClassTemplatePartialSpecializationDecl(
|
|
|
|
ClassTemplatePartialSpecializationDecl *D);
|
2010-08-31 17:01:39 +00:00
|
|
|
bool VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
|
2010-02-18 18:47:08 +00:00
|
|
|
bool VisitEnumConstantDecl(EnumConstantDecl *D);
|
2010-02-18 22:36:18 +00:00
|
|
|
bool VisitDeclaratorDecl(DeclaratorDecl *DD);
|
2010-02-18 18:47:08 +00:00
|
|
|
bool VisitFunctionDecl(FunctionDecl *ND);
|
2010-02-18 22:36:18 +00:00
|
|
|
bool VisitFieldDecl(FieldDecl *D);
|
|
|
|
bool VisitVarDecl(VarDecl *);
|
2010-09-01 20:16:53 +00:00
|
|
|
bool VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
|
2010-08-31 17:01:39 +00:00
|
|
|
bool VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
|
2010-08-31 19:02:00 +00:00
|
|
|
bool VisitClassTemplateDecl(ClassTemplateDecl *D);
|
2010-09-01 20:16:53 +00:00
|
|
|
bool VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
|
2010-02-18 22:36:18 +00:00
|
|
|
bool VisitObjCMethodDecl(ObjCMethodDecl *ND);
|
2010-02-18 18:47:08 +00:00
|
|
|
bool VisitObjCContainerDecl(ObjCContainerDecl *D);
|
2010-02-18 22:36:18 +00:00
|
|
|
bool VisitObjCCategoryDecl(ObjCCategoryDecl *ND);
|
|
|
|
bool VisitObjCProtocolDecl(ObjCProtocolDecl *PID);
|
2010-05-18 21:09:07 +00:00
|
|
|
bool VisitObjCPropertyDecl(ObjCPropertyDecl *PD);
|
2010-02-18 22:36:18 +00:00
|
|
|
bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
|
2010-02-18 18:47:08 +00:00
|
|
|
bool VisitObjCImplDecl(ObjCImplDecl *D);
|
2010-02-18 22:36:18 +00:00
|
|
|
bool VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
|
2010-01-22 00:50:27 +00:00
|
|
|
bool VisitObjCImplementationDecl(ObjCImplementationDecl *D);
|
2010-02-18 22:36:18 +00:00
|
|
|
// FIXME: ObjCCompatibleAliasDecl requires aliased-class locations.
|
|
|
|
bool VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
|
|
|
|
bool VisitObjCClassDecl(ObjCClassDecl *D);
|
2010-05-07 01:04:29 +00:00
|
|
|
bool VisitLinkageSpecDecl(LinkageSpecDecl *D);
|
2010-05-06 23:38:21 +00:00
|
|
|
bool VisitNamespaceDecl(NamespaceDecl *D);
|
2010-08-31 23:48:11 +00:00
|
|
|
bool VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
|
2010-09-01 03:07:18 +00:00
|
|
|
bool VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
|
2010-09-01 19:52:22 +00:00
|
|
|
bool VisitUsingDecl(UsingDecl *D);
|
|
|
|
bool VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
|
|
|
|
bool VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
|
2010-09-01 03:07:18 +00:00
|
|
|
|
2010-08-31 14:41:23 +00:00
|
|
|
// Name visitor
|
|
|
|
bool VisitDeclarationNameInfo(DeclarationNameInfo Name);
|
2010-09-02 17:35:32 +00:00
|
|
|
bool VisitNestedNameSpecifier(NestedNameSpecifier *NNS, SourceRange Range);
|
2010-08-31 14:41:23 +00:00
|
|
|
|
2010-08-31 17:01:39 +00:00
|
|
|
// Template visitors
|
|
|
|
bool VisitTemplateParameters(const TemplateParameterList *Params);
|
2010-08-31 20:37:03 +00:00
|
|
|
bool VisitTemplateName(TemplateName Name, SourceLocation Loc);
|
2010-08-31 17:01:39 +00:00
|
|
|
bool VisitTemplateArgumentLoc(const TemplateArgumentLoc &TAL);
|
|
|
|
|
2010-01-21 16:28:34 +00:00
|
|
|
// Type visitors
|
2010-08-31 14:41:23 +00:00
|
|
|
bool VisitQualifiedTypeLoc(QualifiedTypeLoc TL);
|
2010-01-21 17:29:07 +00:00
|
|
|
bool VisitBuiltinTypeLoc(BuiltinTypeLoc TL);
|
2010-01-21 16:28:34 +00:00
|
|
|
bool VisitTypedefTypeLoc(TypedefTypeLoc TL);
|
2010-01-21 17:29:07 +00:00
|
|
|
bool VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL);
|
|
|
|
bool VisitTagTypeLoc(TagTypeLoc TL);
|
2010-08-31 17:01:39 +00:00
|
|
|
bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL);
|
2010-01-21 17:29:07 +00:00
|
|
|
bool VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL);
|
2010-05-15 11:32:37 +00:00
|
|
|
bool VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL);
|
2010-01-21 17:29:07 +00:00
|
|
|
bool VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL);
|
|
|
|
bool VisitPointerTypeLoc(PointerTypeLoc TL);
|
|
|
|
bool VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL);
|
|
|
|
bool VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL);
|
|
|
|
bool VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL);
|
|
|
|
bool VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL);
|
2010-08-31 14:41:23 +00:00
|
|
|
bool VisitFunctionTypeLoc(FunctionTypeLoc TL, bool SkipResultType = false);
|
2010-01-21 17:29:07 +00:00
|
|
|
bool VisitArrayTypeLoc(ArrayTypeLoc TL);
|
2010-08-31 17:01:39 +00:00
|
|
|
bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL);
|
2010-01-21 20:48:56 +00:00
|
|
|
// FIXME: Implement visitors here when the unimplemented TypeLocs get
|
|
|
|
// implemented
|
|
|
|
bool VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL);
|
|
|
|
bool VisitTypeOfTypeLoc(TypeOfTypeLoc TL);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
// Statement visitors
|
|
|
|
bool VisitStmt(Stmt *S);
|
|
|
|
bool VisitDeclStmt(DeclStmt *S);
|
2010-09-10 00:22:18 +00:00
|
|
|
bool VisitGotoStmt(GotoStmt *S);
|
2010-01-22 01:00:11 +00:00
|
|
|
bool VisitIfStmt(IfStmt *S);
|
|
|
|
bool VisitSwitchStmt(SwitchStmt *S);
|
2010-05-13 00:25:00 +00:00
|
|
|
bool VisitCaseStmt(CaseStmt *S);
|
2010-01-25 16:12:32 +00:00
|
|
|
bool VisitWhileStmt(WhileStmt *S);
|
|
|
|
bool VisitForStmt(ForStmt *S);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-23 00:40:08 +00:00
|
|
|
// Expression visitors
|
2010-09-02 20:35:02 +00:00
|
|
|
bool VisitDeclRefExpr(DeclRefExpr *E);
|
2010-07-29 00:26:18 +00:00
|
|
|
bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
|
2010-04-11 21:47:37 +00:00
|
|
|
bool VisitBlockExpr(BlockExpr *B);
|
2010-01-23 00:40:08 +00:00
|
|
|
bool VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
|
2010-04-11 21:47:37 +00:00
|
|
|
bool VisitExplicitCastExpr(ExplicitCastExpr *E);
|
2010-03-08 16:40:19 +00:00
|
|
|
bool VisitObjCMessageExpr(ObjCMessageExpr *E);
|
2010-04-20 15:39:42 +00:00
|
|
|
bool VisitObjCEncodeExpr(ObjCEncodeExpr *E);
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-28 22:16:22 +00:00
|
|
|
bool VisitOffsetOfExpr(OffsetOfExpr *E);
|
2010-04-11 21:47:37 +00:00
|
|
|
bool VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
|
2010-09-02 21:07:44 +00:00
|
|
|
bool VisitMemberExpr(MemberExpr *E);
|
2010-09-10 00:22:18 +00:00
|
|
|
bool VisitAddrLabelExpr(AddrLabelExpr *E);
|
2010-08-10 15:02:34 +00:00
|
|
|
bool VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
|
|
|
|
bool VisitVAArgExpr(VAArgExpr *E);
|
2010-09-09 23:28:23 +00:00
|
|
|
bool VisitInitListExpr(InitListExpr *E);
|
|
|
|
bool VisitDesignatedInitExpr(DesignatedInitExpr *E);
|
2010-09-02 21:20:16 +00:00
|
|
|
bool VisitCXXTypeidExpr(CXXTypeidExpr *E);
|
2010-09-09 16:14:44 +00:00
|
|
|
bool VisitCXXUuidofExpr(CXXUuidofExpr *E);
|
2010-09-02 21:38:13 +00:00
|
|
|
bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { return false; }
|
2010-09-08 00:15:04 +00:00
|
|
|
bool VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
|
|
|
|
bool VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
|
2010-09-07 21:49:58 +00:00
|
|
|
bool VisitCXXNewExpr(CXXNewExpr *E);
|
2010-09-02 22:09:03 +00:00
|
|
|
bool VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
|
2010-09-09 16:14:44 +00:00
|
|
|
bool VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E);
|
2010-09-02 22:29:21 +00:00
|
|
|
bool VisitOverloadExpr(OverloadExpr *E);
|
2010-09-03 17:24:10 +00:00
|
|
|
bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
|
2010-09-08 00:15:04 +00:00
|
|
|
bool VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
|
2010-09-03 17:35:34 +00:00
|
|
|
bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
|
2010-09-03 18:01:25 +00:00
|
|
|
bool VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
|
2010-01-20 20:59:29 +00:00
|
|
|
};
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
} // end anonymous namespace
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
static SourceRange getRawCursorExtent(CXCursor C);
|
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) {
|
|
|
|
return RangeCompare(TU->getSourceManager(), R, RegionOfInterest);
|
|
|
|
}
|
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
/// \brief Visit the given cursor and, if requested by the visitor,
|
|
|
|
/// its children.
|
|
|
|
///
|
2010-01-22 19:49:59 +00:00
|
|
|
/// \param Cursor the cursor to visit.
|
|
|
|
///
|
|
|
|
/// \param CheckRegionOfInterest if true, then the caller already checked that
|
|
|
|
/// this cursor is within the region of interest.
|
|
|
|
///
|
2010-01-20 20:59:29 +00:00
|
|
|
/// \returns true if the visitation should be aborted, false if it
|
|
|
|
/// should continue.
|
2010-01-22 19:49:59 +00:00
|
|
|
bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) {
|
2010-01-20 20:59:29 +00:00
|
|
|
if (clang_isInvalid(Cursor.kind))
|
|
|
|
return false;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
if (clang_isDeclaration(Cursor.kind)) {
|
|
|
|
Decl *D = getCursorDecl(Cursor);
|
|
|
|
assert(D && "Invalid declaration cursor");
|
|
|
|
if (D->getPCHLevel() > MaxPCHLevel)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (D->isImplicit())
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
// If we have a range of interest, and this cursor doesn't intersect with it,
|
|
|
|
// we're done.
|
|
|
|
if (RegionOfInterest.isValid() && !CheckedRegionOfInterest) {
|
2010-07-22 20:22:31 +00:00
|
|
|
SourceRange Range = getRawCursorExtent(Cursor);
|
2010-02-14 08:32:05 +00:00
|
|
|
if (Range.isInvalid() || CompareRegionOfInterest(Range))
|
2010-01-22 19:49:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
switch (Visitor(Cursor, Parent, ClientData)) {
|
|
|
|
case CXChildVisit_Break:
|
|
|
|
return true;
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
case CXChildVisit_Continue:
|
|
|
|
return false;
|
2010-01-16 14:00:32 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
case CXChildVisit_Recurse:
|
|
|
|
return VisitChildren(Cursor);
|
|
|
|
}
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2010-01-25 16:45:46 +00:00
|
|
|
return false;
|
2010-01-20 20:59:29 +00:00
|
|
|
}
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2010-03-20 00:41:21 +00:00
|
|
|
std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
|
|
|
|
CursorVisitor::getPreprocessedEntities() {
|
|
|
|
PreprocessingRecord &PPRec
|
|
|
|
= *TU->getPreprocessor().getPreprocessingRecord();
|
|
|
|
|
|
|
|
bool OnlyLocalDecls
|
|
|
|
= !TU->isMainFileAST() && TU->getOnlyLocalDecls();
|
|
|
|
|
|
|
|
// There is no region of interest; we have to walk everything.
|
|
|
|
if (RegionOfInterest.isInvalid())
|
|
|
|
return std::make_pair(PPRec.begin(OnlyLocalDecls),
|
|
|
|
PPRec.end(OnlyLocalDecls));
|
|
|
|
|
|
|
|
// Find the file in which the region of interest lands.
|
|
|
|
SourceManager &SM = TU->getSourceManager();
|
|
|
|
std::pair<FileID, unsigned> Begin
|
|
|
|
= SM.getDecomposedInstantiationLoc(RegionOfInterest.getBegin());
|
|
|
|
std::pair<FileID, unsigned> End
|
|
|
|
= SM.getDecomposedInstantiationLoc(RegionOfInterest.getEnd());
|
|
|
|
|
|
|
|
// The region of interest spans files; we have to walk everything.
|
|
|
|
if (Begin.first != End.first)
|
|
|
|
return std::make_pair(PPRec.begin(OnlyLocalDecls),
|
|
|
|
PPRec.end(OnlyLocalDecls));
|
|
|
|
|
|
|
|
ASTUnit::PreprocessedEntitiesByFileMap &ByFileMap
|
|
|
|
= TU->getPreprocessedEntitiesByFile();
|
|
|
|
if (ByFileMap.empty()) {
|
|
|
|
// Build the mapping from files to sets of preprocessed entities.
|
|
|
|
for (PreprocessingRecord::iterator E = PPRec.begin(OnlyLocalDecls),
|
|
|
|
EEnd = PPRec.end(OnlyLocalDecls);
|
|
|
|
E != EEnd; ++E) {
|
|
|
|
std::pair<FileID, unsigned> P
|
|
|
|
= SM.getDecomposedInstantiationLoc((*E)->getSourceRange().getBegin());
|
|
|
|
ByFileMap[P.first].push_back(*E);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair(ByFileMap[Begin.first].begin(),
|
|
|
|
ByFileMap[Begin.first].end());
|
|
|
|
}
|
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
/// \brief Visit the children of the given cursor.
|
|
|
|
///
|
|
|
|
/// \returns true if the visitation should be aborted, false if it
|
|
|
|
/// should continue.
|
2010-02-17 00:41:40 +00:00
|
|
|
bool CursorVisitor::VisitChildren(CXCursor Cursor) {
|
2010-01-21 23:27:09 +00:00
|
|
|
if (clang_isReference(Cursor.kind)) {
|
|
|
|
// By definition, references have no children.
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
// Set the Parent field to Cursor, then back to its old value once we're
|
2010-01-20 20:59:29 +00:00
|
|
|
// done.
|
2010-05-13 00:25:00 +00:00
|
|
|
SetParentRAII SetParent(Parent, StmtParent, Cursor);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
if (clang_isDeclaration(Cursor.kind)) {
|
|
|
|
Decl *D = getCursorDecl(Cursor);
|
|
|
|
assert(D && "Invalid declaration cursor");
|
2010-02-18 18:47:01 +00:00
|
|
|
return VisitAttributes(D) || Visit(D);
|
2010-01-20 20:59:29 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
if (clang_isStatement(Cursor.kind))
|
|
|
|
return Visit(getCursorStmt(Cursor));
|
|
|
|
if (clang_isExpression(Cursor.kind))
|
|
|
|
return Visit(getCursorExpr(Cursor));
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
if (clang_isTranslationUnit(Cursor.kind)) {
|
2010-01-20 23:57:43 +00:00
|
|
|
ASTUnit *CXXUnit = getCursorASTUnit(Cursor);
|
2010-01-22 19:49:59 +00:00
|
|
|
if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() &&
|
|
|
|
RegionOfInterest.isInvalid()) {
|
2010-08-03 19:06:41 +00:00
|
|
|
for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(),
|
|
|
|
TLEnd = CXXUnit->top_level_end();
|
|
|
|
TL != TLEnd; ++TL) {
|
|
|
|
if (Visit(MakeCXCursor(*TL, CXXUnit), true))
|
2010-01-20 21:13:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-03-19 05:22:59 +00:00
|
|
|
} else if (VisitDeclContext(
|
|
|
|
CXXUnit->getASTContext().getTranslationUnitDecl()))
|
|
|
|
return true;
|
2010-03-19 03:57:57 +00:00
|
|
|
|
2010-03-19 05:22:59 +00:00
|
|
|
// Walk the preprocessing record.
|
2010-03-20 01:11:56 +00:00
|
|
|
if (CXXUnit->getPreprocessor().getPreprocessingRecord()) {
|
2010-03-19 05:22:59 +00:00
|
|
|
// FIXME: Once we have the ability to deserialize a preprocessing record,
|
|
|
|
// do so.
|
2010-03-20 00:41:21 +00:00
|
|
|
PreprocessingRecord::iterator E, EEnd;
|
|
|
|
for (llvm::tie(E, EEnd) = getPreprocessedEntities(); E != EEnd; ++E) {
|
2010-03-19 05:22:59 +00:00
|
|
|
if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) {
|
|
|
|
if (Visit(MakeMacroInstantiationCursor(MI, CXXUnit)))
|
|
|
|
return true;
|
2010-03-20 00:41:21 +00:00
|
|
|
|
2010-03-19 05:22:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) {
|
|
|
|
if (Visit(MakeMacroDefinitionCursor(MD, CXXUnit)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-20 21:13:59 +00:00
|
|
|
return false;
|
2010-01-20 20:59:29 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
// Nothing to visit at the moment.
|
|
|
|
return false;
|
2010-01-13 00:22:49 +00:00
|
|
|
}
|
|
|
|
|
2010-04-11 21:47:37 +00:00
|
|
|
bool CursorVisitor::VisitBlockDecl(BlockDecl *B) {
|
2010-06-04 22:33:30 +00:00
|
|
|
if (Visit(B->getSignatureAsWritten()->getTypeLoc()))
|
|
|
|
return true;
|
2010-04-11 21:47:37 +00:00
|
|
|
|
2010-07-22 11:30:19 +00:00
|
|
|
if (Stmt *Body = B->getBody())
|
|
|
|
return Visit(MakeCXCursor(Body, StmtParent, TU));
|
|
|
|
|
|
|
|
return false;
|
2010-04-11 21:47:37 +00:00
|
|
|
}
|
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
bool CursorVisitor::VisitDeclContext(DeclContext *DC) {
|
|
|
|
for (DeclContext::decl_iterator
|
|
|
|
I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) {
|
2010-02-18 05:46:33 +00:00
|
|
|
|
2010-05-18 21:09:07 +00:00
|
|
|
Decl *D = *I;
|
|
|
|
if (D->getLexicalDeclContext() != DC)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CXCursor Cursor = MakeCXCursor(D, TU);
|
2010-02-14 10:02:57 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
if (RegionOfInterest.isValid()) {
|
2010-07-22 20:22:31 +00:00
|
|
|
SourceRange Range = getRawCursorExtent(Cursor);
|
2010-02-14 10:02:57 +00:00
|
|
|
if (Range.isInvalid())
|
2010-01-22 19:49:59 +00:00
|
|
|
continue;
|
2010-02-14 10:02:57 +00:00
|
|
|
|
|
|
|
switch (CompareRegionOfInterest(Range)) {
|
2010-01-22 19:49:59 +00:00
|
|
|
case RangeBefore:
|
|
|
|
// This declaration comes before the region of interest; skip it.
|
|
|
|
continue;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
case RangeAfter:
|
|
|
|
// This declaration comes after the region of interest; we're done.
|
|
|
|
return false;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
case RangeOverlap:
|
|
|
|
// This declaration overlaps the region of interest; visit it.
|
|
|
|
break;
|
2010-02-17 00:41:40 +00:00
|
|
|
}
|
2010-01-22 19:49:59 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-02-14 10:02:57 +00:00
|
|
|
if (Visit(Cursor, true))
|
2010-01-20 20:59:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
return false;
|
2010-01-13 00:22:49 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
bool CursorVisitor::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
|
|
|
|
llvm_unreachable("Translation units are visited directly by Visit()");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTypedefDecl(TypedefDecl *D) {
|
|
|
|
if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTagDecl(TagDecl *D) {
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:32:36 +00:00
|
|
|
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();
|
|
|
|
if (TemplateSpecializationTypeLoc *TSTLoc
|
|
|
|
= dyn_cast<TemplateSpecializationTypeLoc>(&TL)) {
|
|
|
|
for (unsigned I = 0, N = TSTLoc->getNumArgs(); I != N; ++I)
|
|
|
|
if (VisitTemplateArgumentLoc(TSTLoc->getArgLoc(I)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldVisitBody && VisitCXXRecordDecl(D))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-31 19:31:58 +00: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.
|
|
|
|
const TemplateArgumentLoc *TemplateArgs = D->getTemplateArgsAsWritten();
|
|
|
|
for (unsigned I = 0, N = D->getNumTemplateArgsAsWritten(); I != N; ++I)
|
|
|
|
if (VisitTemplateArgumentLoc(TemplateArgs[I]))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitCXXRecordDecl(D);
|
|
|
|
}
|
|
|
|
|
2010-08-31 17:01:39 +00:00
|
|
|
bool CursorVisitor::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
|
2010-09-01 20:16:53 +00:00
|
|
|
// Visit the default argument.
|
|
|
|
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
|
|
|
|
if (TypeSourceInfo *DefArg = D->getDefaultArgumentInfo())
|
|
|
|
if (Visit(DefArg->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
2010-08-31 17:01:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
bool CursorVisitor::VisitEnumConstantDecl(EnumConstantDecl *D) {
|
|
|
|
if (Expr *Init = D->getInitExpr())
|
|
|
|
return Visit(MakeCXCursor(Init, StmtParent, TU));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-21 16:28:34 +00:00
|
|
|
bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) {
|
|
|
|
if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-09 21:42:20 +00:00
|
|
|
/// \brief Compare two base or member initializers based on their source order.
|
|
|
|
static int CompareCXXBaseOrMemberInitializers(const void* Xp, const void *Yp) {
|
|
|
|
CXXBaseOrMemberInitializer const * const *X
|
|
|
|
= static_cast<CXXBaseOrMemberInitializer const * const *>(Xp);
|
|
|
|
CXXBaseOrMemberInitializer const * const *Y
|
|
|
|
= static_cast<CXXBaseOrMemberInitializer const * const *>(Yp);
|
|
|
|
|
|
|
|
if ((*X)->getSourceOrder() < (*Y)->getSourceOrder())
|
|
|
|
return -1;
|
|
|
|
else if ((*X)->getSourceOrder() > (*Y)->getSourceOrder())
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
|
2010-08-31 14:41:23 +00:00
|
|
|
if (TypeSourceInfo *TSInfo = ND->getTypeSourceInfo()) {
|
|
|
|
// Visit the function declaration's syntactic components in the order
|
|
|
|
// written. This requires a bit of work.
|
|
|
|
TypeLoc TL = TSInfo->getTypeLoc();
|
|
|
|
FunctionTypeLoc *FTL = dyn_cast<FunctionTypeLoc>(&TL);
|
|
|
|
|
|
|
|
// If we have a function declared directly (without the use of a typedef),
|
|
|
|
// visit just the return type. Otherwise, just visit the function's type
|
|
|
|
// now.
|
|
|
|
if ((FTL && !isa<CXXConversionDecl>(ND) && Visit(FTL->getResultLoc())) ||
|
|
|
|
(!FTL && Visit(TL)))
|
|
|
|
return true;
|
|
|
|
|
2010-09-02 17:35:32 +00:00
|
|
|
// Visit the nested-name-specifier, if present.
|
|
|
|
if (NestedNameSpecifier *Qualifier = ND->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, ND->getQualifierRange()))
|
|
|
|
return true;
|
2010-08-31 14:41:23 +00:00
|
|
|
|
|
|
|
// Visit the declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(ND->getNameInfo()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// FIXME: Visit explicitly-specified template arguments!
|
|
|
|
|
|
|
|
// Visit the function parameters, if we have a function type.
|
|
|
|
if (FTL && VisitFunctionTypeLoc(*FTL, true))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// FIXME: Attributes?
|
|
|
|
}
|
|
|
|
|
2010-09-09 21:42:20 +00:00
|
|
|
if (ND->isThisDeclarationADefinition()) {
|
|
|
|
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ND)) {
|
|
|
|
// Find the initializers that were written in the source.
|
|
|
|
llvm::SmallVector<CXXBaseOrMemberInitializer *, 4> WrittenInits;
|
|
|
|
for (CXXConstructorDecl::init_iterator I = Constructor->init_begin(),
|
|
|
|
IEnd = Constructor->init_end();
|
|
|
|
I != IEnd; ++I) {
|
|
|
|
if (!(*I)->isWritten())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
WrittenInits.push_back(*I);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the initializers in source order
|
|
|
|
llvm::array_pod_sort(WrittenInits.begin(), WrittenInits.end(),
|
|
|
|
&CompareCXXBaseOrMemberInitializers);
|
|
|
|
|
|
|
|
// Visit the initializers in source order
|
|
|
|
for (unsigned I = 0, N = WrittenInits.size(); I != N; ++I) {
|
|
|
|
CXXBaseOrMemberInitializer *Init = WrittenInits[I];
|
|
|
|
if (Init->isMemberInitializer()) {
|
|
|
|
if (Visit(MakeCursorMemberRef(Init->getMember(),
|
|
|
|
Init->getMemberLocation(), TU)))
|
|
|
|
return true;
|
|
|
|
} else if (TypeSourceInfo *BaseInfo = Init->getBaseClassInfo()) {
|
|
|
|
if (Visit(BaseInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Visit the initializer value.
|
|
|
|
if (Expr *Initializer = Init->getInit())
|
|
|
|
if (Visit(MakeCXCursor(Initializer, ND, TU)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Visit(MakeCXCursor(ND->getBody(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-01-13 00:22:49 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
bool CursorVisitor::VisitFieldDecl(FieldDecl *D) {
|
|
|
|
if (VisitDeclaratorDecl(D))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
if (Expr *BitWidth = D->getBitWidth())
|
|
|
|
return Visit(MakeCXCursor(BitWidth, StmtParent, TU));
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitVarDecl(VarDecl *D) {
|
|
|
|
if (VisitDeclaratorDecl(D))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
if (Expr *Init = D->getInit())
|
|
|
|
return Visit(MakeCXCursor(Init, StmtParent, TU));
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-01 20:16:53 +00:00
|
|
|
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));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-31 17:01:39 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
return VisitFunctionDecl(D->getTemplatedDecl());
|
|
|
|
}
|
|
|
|
|
2010-08-31 19:02:00 +00: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;
|
|
|
|
|
|
|
|
return VisitCXXRecordDecl(D->getTemplatedDecl());
|
|
|
|
}
|
|
|
|
|
2010-09-01 20:16:53 +00:00
|
|
|
bool CursorVisitor::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
|
|
|
|
if (VisitTemplateParameters(D->getTemplateParameters()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited() &&
|
|
|
|
VisitTemplateArgumentLoc(D->getDefaultArgument()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) {
|
2010-03-08 14:59:44 +00:00
|
|
|
if (TypeSourceInfo *TSInfo = ND->getResultTypeSourceInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
2010-02-17 00:41:40 +00:00
|
|
|
for (ObjCMethodDecl::param_iterator P = ND->param_begin(),
|
2010-01-22 00:50:27 +00:00
|
|
|
PEnd = ND->param_end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if (Visit(MakeCXCursor(*P, TU)))
|
|
|
|
return true;
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
if (ND->isThisDeclarationADefinition() &&
|
|
|
|
Visit(MakeCXCursor(ND->getBody(), StmtParent, TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) {
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
bool CursorVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) {
|
2010-01-20 23:57:43 +00:00
|
|
|
if (Visit(MakeCursorObjCClassRef(ND->getClassInterface(), ND->getLocation(),
|
|
|
|
TU)))
|
2010-01-20 20:59:29 +00:00
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-16 15:44:18 +00: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)
|
2010-01-20 23:57:43 +00:00
|
|
|
if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
|
2010-01-20 20:59:29 +00:00
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
return VisitObjCContainerDecl(ND);
|
2010-01-13 00:22:49 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
bool CursorVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
|
|
|
|
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;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
return VisitObjCContainerDecl(PID);
|
|
|
|
}
|
|
|
|
|
2010-05-18 21:09:07 +00:00
|
|
|
bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) {
|
2010-09-09 17:09:21 +00:00
|
|
|
if (PD->getTypeSourceInfo() && Visit(PD->getTypeSourceInfo()->getTypeLoc()))
|
2010-06-04 22:33:30 +00:00
|
|
|
return true;
|
|
|
|
|
2010-05-18 21:09:07 +00:00
|
|
|
// 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 =
|
|
|
|
ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(ID), PropertyId);
|
|
|
|
|
|
|
|
if (!prevDecl)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Visit synthesized methods since they will be skipped when visiting
|
|
|
|
// the @interface.
|
|
|
|
if (ObjCMethodDecl *MD = prevDecl->getGetterMethodDecl())
|
2010-09-21 20:52:59 +00:00
|
|
|
if (MD->isSynthesized() && MD->getLexicalDeclContext() == CDecl)
|
2010-05-18 21:09:07 +00:00
|
|
|
if (Visit(MakeCXCursor(MD, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (ObjCMethodDecl *MD = prevDecl->getSetterMethodDecl())
|
2010-09-21 20:52:59 +00:00
|
|
|
if (MD->isSynthesized() && MD->getLexicalDeclContext() == CDecl)
|
2010-05-18 21:09:07 +00:00
|
|
|
if (Visit(MakeCXCursor(MD, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-20 20:59:29 +00:00
|
|
|
bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
|
2010-01-13 00:22:49 +00:00
|
|
|
// Issue callbacks for super class.
|
2010-01-20 20:59:29 +00:00
|
|
|
if (D->getSuperClass() &&
|
|
|
|
Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(),
|
2010-02-17 00:41:40 +00:00
|
|
|
D->getSuperClassLoc(),
|
2010-01-20 23:57:43 +00:00
|
|
|
TU)))
|
2010-01-20 20:59:29 +00:00
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-16 15:44:18 +00: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)
|
2010-01-20 23:57:43 +00:00
|
|
|
if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
|
2010-01-20 20:59:29 +00:00
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
return VisitObjCContainerDecl(D);
|
2010-01-13 00:22:49 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
bool CursorVisitor::VisitObjCImplDecl(ObjCImplDecl *D) {
|
|
|
|
return VisitObjCContainerDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
|
2010-03-19 20:39:03 +00:00
|
|
|
// 'ID' could be null when dealing with invalid code.
|
|
|
|
if (ObjCInterfaceDecl *ID = D->getClassInterface())
|
|
|
|
if (Visit(MakeCursorObjCClassRef(ID, D->getLocation(), TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
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(),
|
2010-02-17 00:41:40 +00:00
|
|
|
D->getSuperClassLoc(),
|
2010-01-22 00:50:27 +00:00
|
|
|
TU)))
|
2010-01-21 23:27:09 +00:00
|
|
|
return true;
|
2010-01-22 00:50:27 +00:00
|
|
|
#endif
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
return VisitObjCImplDecl(D);
|
2010-01-13 00:22:49 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
bool CursorVisitor::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
|
|
|
|
ObjCForwardProtocolDecl::protocol_loc_iterator PL = D->protocol_loc_begin();
|
|
|
|
for (ObjCForwardProtocolDecl::protocol_iterator I = D->protocol_begin(),
|
|
|
|
E = D->protocol_end();
|
|
|
|
I != E; ++I, ++PL)
|
2010-01-20 23:57:43 +00:00
|
|
|
if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
|
2010-01-20 20:59:29 +00:00
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
return false;
|
2010-01-13 00:22:49 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
bool CursorVisitor::VisitObjCClassDecl(ObjCClassDecl *D) {
|
|
|
|
for (ObjCClassDecl::iterator C = D->begin(), CEnd = D->end(); C != CEnd; ++C)
|
|
|
|
if (Visit(MakeCursorObjCClassRef(C->getInterface(), C->getLocation(), TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 00:50:27 +00:00
|
|
|
return false;
|
2010-01-13 00:22:49 +00:00
|
|
|
}
|
2009-10-18 16:11:04 +00:00
|
|
|
|
2010-05-06 23:38:21 +00:00
|
|
|
bool CursorVisitor::VisitNamespaceDecl(NamespaceDecl *D) {
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
2010-08-31 23:48:11 +00:00
|
|
|
bool CursorVisitor::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
|
2010-09-02 17:35:32 +00:00
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = D->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, D->getQualifierRange()))
|
|
|
|
return true;
|
2010-08-31 23:48:11 +00:00
|
|
|
|
|
|
|
return Visit(MakeCursorNamespaceRef(D->getAliasedNamespace(),
|
|
|
|
D->getTargetNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
2010-09-01 19:52:22 +00:00
|
|
|
bool CursorVisitor::VisitUsingDecl(UsingDecl *D) {
|
2010-09-02 17:35:32 +00:00
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = D->getTargetNestedNameDecl())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, D->getNestedNameRange()))
|
|
|
|
return true;
|
2010-09-01 19:52:22 +00:00
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
if (Visit(MakeCursorOverloadedDeclRef(D, D->getLocation(), TU)))
|
|
|
|
return true;
|
|
|
|
|
2010-09-01 19:52:22 +00:00
|
|
|
return VisitDeclarationNameInfo(D->getNameInfo());
|
|
|
|
}
|
|
|
|
|
2010-09-01 03:07:18 +00:00
|
|
|
bool CursorVisitor::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
|
2010-09-02 17:35:32 +00:00
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = D->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, D->getQualifierRange()))
|
|
|
|
return true;
|
2010-09-01 03:07:18 +00:00
|
|
|
|
|
|
|
return Visit(MakeCursorNamespaceRef(D->getNominatedNamespaceAsWritten(),
|
|
|
|
D->getIdentLocation(), TU));
|
|
|
|
}
|
|
|
|
|
2010-09-01 19:52:22 +00:00
|
|
|
bool CursorVisitor::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
|
2010-09-02 17:35:32 +00:00
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = D->getTargetNestedNameSpecifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, D->getTargetNestedNameRange()))
|
|
|
|
return true;
|
|
|
|
|
2010-09-01 19:52:22 +00:00
|
|
|
return VisitDeclarationNameInfo(D->getNameInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitUnresolvedUsingTypenameDecl(
|
|
|
|
UnresolvedUsingTypenameDecl *D) {
|
2010-09-02 17:35:32 +00:00
|
|
|
// Visit nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = D->getTargetNestedNameSpecifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, D->getTargetNestedNameRange()))
|
|
|
|
return true;
|
|
|
|
|
2010-09-01 19:52:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-31 14:41:23 +00:00
|
|
|
bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) {
|
|
|
|
switch (Name.getName().getNameKind()) {
|
|
|
|
case clang::DeclarationName::Identifier:
|
|
|
|
case clang::DeclarationName::CXXLiteralOperatorName:
|
|
|
|
case clang::DeclarationName::CXXOperatorName:
|
|
|
|
case clang::DeclarationName::CXXUsingDirective:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-02 17:35:32 +00:00
|
|
|
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:
|
|
|
|
// FIXME: The token at this source location might actually have been a
|
|
|
|
// namespace alias, but we don't model that. Lame!
|
|
|
|
return Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(), 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.
|
|
|
|
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:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-31 17:01:39 +00:00
|
|
|
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)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-31 20:37:03 +00:00
|
|
|
bool CursorVisitor::VisitTemplateName(TemplateName Name, SourceLocation Loc) {
|
|
|
|
switch (Name.getKind()) {
|
|
|
|
case TemplateName::Template:
|
|
|
|
return Visit(MakeCursorTemplateRef(Name.getAsTemplateDecl(), Loc, TU));
|
|
|
|
|
|
|
|
case TemplateName::OverloadedTemplate:
|
2010-09-13 22:52:57 +00:00
|
|
|
// Visit the overloaded template set.
|
|
|
|
if (Visit(MakeCursorOverloadedDeclRef(Name, Loc, TU)))
|
|
|
|
return true;
|
|
|
|
|
2010-08-31 20:37:03 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-31 17:01:39 +00:00
|
|
|
bool CursorVisitor::VisitTemplateArgumentLoc(const TemplateArgumentLoc &TAL) {
|
|
|
|
switch (TAL.getArgument().getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
case TemplateArgument::Integral:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateArgument::Pack:
|
|
|
|
// FIXME: Implement when variadic templates come along.
|
|
|
|
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));
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateArgument::Expression:
|
|
|
|
if (Expr *E = TAL.getSourceExpression())
|
|
|
|
return Visit(MakeCXCursor(E, StmtParent, TU));
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TemplateArgument::Template:
|
2010-08-31 20:37:03 +00:00
|
|
|
return VisitTemplateName(TAL.getArgument().getAsTemplate(),
|
|
|
|
TAL.getTemplateNameLoc());
|
2010-08-31 17:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-07 01:04:29 +00:00
|
|
|
bool CursorVisitor::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
|
|
|
|
return VisitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
2010-08-31 14:41:23 +00:00
|
|
|
bool CursorVisitor::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
|
|
|
|
return Visit(TL.getUnqualifiedLoc());
|
|
|
|
}
|
|
|
|
|
2010-01-21 17:29:07 +00:00
|
|
|
bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
|
|
|
|
ASTContext &Context = TU->getASTContext();
|
|
|
|
|
|
|
|
// Some builtin types (such as Objective-C's "id", "sel", and
|
|
|
|
// "Class") have associated declarations. Create cursors for those.
|
|
|
|
QualType VisitType;
|
|
|
|
switch (TL.getType()->getAs<BuiltinType>()->getKind()) {
|
2010-02-18 22:32:43 +00:00
|
|
|
case BuiltinType::Void:
|
2010-01-21 17:29:07 +00:00
|
|
|
case BuiltinType::Bool:
|
2010-02-18 22:32:43 +00:00
|
|
|
case BuiltinType::Char_U:
|
|
|
|
case BuiltinType::UChar:
|
2010-01-21 17:29:07 +00:00
|
|
|
case BuiltinType::Char16:
|
|
|
|
case BuiltinType::Char32:
|
2010-02-18 22:32:43 +00:00
|
|
|
case BuiltinType::UShort:
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
case BuiltinType::ULongLong:
|
|
|
|
case BuiltinType::UInt128:
|
2010-01-21 17:29:07 +00:00
|
|
|
case BuiltinType::Char_S:
|
2010-02-18 22:32:43 +00:00
|
|
|
case BuiltinType::SChar:
|
|
|
|
case BuiltinType::WChar:
|
|
|
|
case BuiltinType::Short:
|
2010-01-21 17:29:07 +00:00
|
|
|
case BuiltinType::Int:
|
|
|
|
case BuiltinType::Long:
|
2010-02-18 18:52:18 +00:00
|
|
|
case BuiltinType::LongLong:
|
2010-02-18 22:32:43 +00:00
|
|
|
case BuiltinType::Int128:
|
|
|
|
case BuiltinType::Float:
|
|
|
|
case BuiltinType::Double:
|
|
|
|
case BuiltinType::LongDouble:
|
2010-01-21 17:29:07 +00:00
|
|
|
case BuiltinType::NullPtr:
|
|
|
|
case BuiltinType::Overload:
|
2010-02-18 22:32:43 +00:00
|
|
|
case BuiltinType::Dependent:
|
2010-01-21 17:29:07 +00:00
|
|
|
break;
|
2010-02-18 22:32:43 +00:00
|
|
|
|
|
|
|
case BuiltinType::UndeducedAuto: // FIXME: Deserves a cursor?
|
2010-01-21 17:29:07 +00:00
|
|
|
break;
|
2010-02-18 22:32:43 +00:00
|
|
|
|
2010-01-21 17:29:07 +00:00
|
|
|
case BuiltinType::ObjCId:
|
|
|
|
VisitType = Context.getObjCIdType();
|
|
|
|
break;
|
2010-02-18 22:32:43 +00:00
|
|
|
|
|
|
|
case BuiltinType::ObjCClass:
|
|
|
|
VisitType = Context.getObjCClassType();
|
|
|
|
break;
|
|
|
|
|
2010-01-21 17:29:07 +00:00
|
|
|
case BuiltinType::ObjCSel:
|
|
|
|
VisitType = Context.getObjCSelType();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!VisitType.isNull()) {
|
|
|
|
if (const TypedefType *Typedef = VisitType->getAs<TypedefType>())
|
2010-02-17 00:41:40 +00:00
|
|
|
return Visit(MakeCursorTypeRef(Typedef->getDecl(), TL.getBuiltinLoc(),
|
2010-01-21 17:29:07 +00:00
|
|
|
TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-21 16:28:34 +00:00
|
|
|
bool CursorVisitor::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
|
|
|
|
return Visit(MakeCursorTypeRef(TL.getTypedefDecl(), TL.getNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
2010-01-21 17:29:07 +00:00
|
|
|
bool CursorVisitor::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
|
|
|
|
return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitTagTypeLoc(TagTypeLoc TL) {
|
|
|
|
return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
|
|
|
|
}
|
|
|
|
|
2010-08-31 17:01:39 +00:00
|
|
|
bool CursorVisitor::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
|
2010-09-13 22:52:57 +00:00
|
|
|
// FIXME: We can't visit the template type parameter, because there's
|
2010-08-31 17:01:39 +00:00
|
|
|
// no context information with which we can match up the depth/index in the
|
|
|
|
// type to the appropriate
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-21 17:29:07 +00:00
|
|
|
bool CursorVisitor::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
|
|
|
|
if (Visit(MakeCursorObjCClassRef(TL.getIFaceDecl(), TL.getNameLoc(), TU)))
|
|
|
|
return true;
|
|
|
|
|
2010-05-15 11:32:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
|
|
|
|
if (TL.hasBaseTypeAsWritten() && Visit(TL.getBaseLoc()))
|
|
|
|
return true;
|
|
|
|
|
2010-01-21 17:29:07 +00: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) {
|
2010-05-15 11:32:37 +00:00
|
|
|
return Visit(TL.getPointeeLoc());
|
2010-01-21 17:29:07 +00: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) {
|
2010-02-17 00:41:40 +00:00
|
|
|
return Visit(TL.getPointeeLoc());
|
2010-01-21 17:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
|
2010-02-17 00:41:40 +00:00
|
|
|
return Visit(TL.getPointeeLoc());
|
2010-01-21 17:29:07 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 14:41:23 +00:00
|
|
|
bool CursorVisitor::VisitFunctionTypeLoc(FunctionTypeLoc TL,
|
|
|
|
bool SkipResultType) {
|
|
|
|
if (!SkipResultType && Visit(TL.getResultLoc()))
|
2010-01-21 17:29:07 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
for (unsigned I = 0, N = TL.getNumArgs(); I != N; ++I)
|
2010-04-07 00:27:13 +00:00
|
|
|
if (Decl *D = TL.getArg(I))
|
|
|
|
if (Visit(MakeCXCursor(D, TU)))
|
|
|
|
return true;
|
2010-01-21 17:29:07 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitArrayTypeLoc(ArrayTypeLoc TL) {
|
|
|
|
if (Visit(TL.getElementLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Expr *Size = TL.getSizeExpr())
|
|
|
|
return Visit(MakeCXCursor(Size, StmtParent, TU));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-31 17:01:39 +00:00
|
|
|
bool CursorVisitor::VisitTemplateSpecializationTypeLoc(
|
|
|
|
TemplateSpecializationTypeLoc TL) {
|
2010-08-31 20:37:03 +00:00
|
|
|
// Visit the template name.
|
|
|
|
if (VisitTemplateName(TL.getTypePtr()->getTemplateName(),
|
|
|
|
TL.getTemplateNameLoc()))
|
|
|
|
return true;
|
2010-08-31 17:01:39 +00:00
|
|
|
|
|
|
|
// Visit the template arguments.
|
|
|
|
for (unsigned I = 0, N = TL.getNumArgs(); I != N; ++I)
|
|
|
|
if (VisitTemplateArgumentLoc(TL.getArgLoc(I)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-21 20:48:56 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
bool CursorVisitor::VisitStmt(Stmt *S) {
|
|
|
|
for (Stmt::child_iterator Child = S->child_begin(), ChildEnd = S->child_end();
|
|
|
|
Child != ChildEnd; ++Child) {
|
2010-05-13 00:25:00 +00:00
|
|
|
if (Stmt *C = *Child)
|
|
|
|
if (Visit(MakeCXCursor(C, StmtParent, TU)))
|
|
|
|
return true;
|
2010-01-21 23:27:09 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-13 00:25:00 +00:00
|
|
|
bool CursorVisitor::VisitCaseStmt(CaseStmt *S) {
|
|
|
|
// Specially handle CaseStmts because they can be nested, e.g.:
|
|
|
|
//
|
|
|
|
// case 1:
|
|
|
|
// case 2:
|
|
|
|
//
|
|
|
|
// In this case the second CaseStmt is the child of the first. Walking
|
|
|
|
// these recursively can blow out the stack.
|
|
|
|
CXCursor Cursor = MakeCXCursor(S, StmtParent, TU);
|
|
|
|
while (true) {
|
|
|
|
// Set the Parent field to Cursor, then back to its old value once we're
|
|
|
|
// done.
|
|
|
|
SetParentRAII SetParent(Parent, StmtParent, Cursor);
|
|
|
|
|
|
|
|
if (Stmt *LHS = S->getLHS())
|
|
|
|
if (Visit(MakeCXCursor(LHS, StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
if (Stmt *RHS = S->getRHS())
|
|
|
|
if (Visit(MakeCXCursor(RHS, StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
if (Stmt *SubStmt = S->getSubStmt()) {
|
|
|
|
if (!isa<CaseStmt>(SubStmt))
|
|
|
|
return Visit(MakeCXCursor(SubStmt, StmtParent, TU));
|
|
|
|
|
|
|
|
// Specially handle 'CaseStmt' so that we don't blow out the stack.
|
|
|
|
CaseStmt *CS = cast<CaseStmt>(SubStmt);
|
|
|
|
Cursor = MakeCXCursor(CS, StmtParent, TU);
|
|
|
|
if (RegionOfInterest.isValid()) {
|
|
|
|
SourceRange Range = CS->getSourceRange();
|
|
|
|
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:
|
|
|
|
// Perform tail-recursion manually.
|
|
|
|
S = CS;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
bool CursorVisitor::VisitDeclStmt(DeclStmt *S) {
|
|
|
|
for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
|
|
|
|
D != DEnd; ++D) {
|
2010-01-25 16:12:32 +00:00
|
|
|
if (*D && Visit(MakeCXCursor(*D, TU)))
|
2010-01-21 23:27:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-21 23:27:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
bool CursorVisitor::VisitGotoStmt(GotoStmt *S) {
|
|
|
|
return Visit(MakeCursorLabelRef(S->getLabel(), S->getLabelLoc(), TU));
|
|
|
|
}
|
|
|
|
|
2010-01-22 01:00:11 +00:00
|
|
|
bool CursorVisitor::VisitIfStmt(IfStmt *S) {
|
|
|
|
if (VarDecl *Var = S->getConditionVariable()) {
|
|
|
|
if (Visit(MakeCXCursor(Var, TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 16:12:32 +00:00
|
|
|
if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
|
|
|
|
return true;
|
2010-01-22 01:00:11 +00:00
|
|
|
if (S->getThen() && Visit(MakeCXCursor(S->getThen(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
if (S->getElse() && Visit(MakeCXCursor(S->getElse(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitSwitchStmt(SwitchStmt *S) {
|
|
|
|
if (VarDecl *Var = S->getConditionVariable()) {
|
|
|
|
if (Visit(MakeCXCursor(Var, TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 16:12:32 +00:00
|
|
|
if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
|
2010-01-22 01:00:11 +00:00
|
|
|
return true;
|
2010-01-25 16:12:32 +00:00
|
|
|
if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-25 16:12:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-01-22 01:00:11 +00:00
|
|
|
|
2010-01-25 16:12:32 +00:00
|
|
|
bool CursorVisitor::VisitWhileStmt(WhileStmt *S) {
|
|
|
|
if (VarDecl *Var = S->getConditionVariable()) {
|
|
|
|
if (Visit(MakeCXCursor(Var, TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 16:12:32 +00:00
|
|
|
if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitForStmt(ForStmt *S) {
|
|
|
|
if (S->getInit() && Visit(MakeCXCursor(S->getInit(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
if (VarDecl *Var = S->getConditionVariable()) {
|
|
|
|
if (Visit(MakeCXCursor(Var, TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 16:12:32 +00:00
|
|
|
if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
if (S->getInc() && Visit(MakeCXCursor(S->getInc(), StmtParent, TU)))
|
|
|
|
return true;
|
2010-01-22 01:00:11 +00:00
|
|
|
if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU)))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 01:00:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-02 20:35:02 +00:00
|
|
|
bool CursorVisitor::VisitDeclRefExpr(DeclRefExpr *E) {
|
|
|
|
// Visit nested-name-specifier, if present.
|
|
|
|
if (NestedNameSpecifier *Qualifier = E->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, E->getQualifierRange()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(E->getNameInfo()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit explicitly-specified template arguments.
|
|
|
|
if (E->hasExplicitTemplateArgs()) {
|
|
|
|
ExplicitTemplateArgumentList &Args = E->getExplicitTemplateArgs();
|
|
|
|
for (TemplateArgumentLoc *Arg = Args.getTemplateArgs(),
|
|
|
|
*ArgEnd = Arg + Args.NumTemplateArgs;
|
|
|
|
Arg != ArgEnd; ++Arg)
|
|
|
|
if (VisitTemplateArgumentLoc(*Arg))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-29 00:26:18 +00:00
|
|
|
bool CursorVisitor::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
|
|
|
|
if (Visit(MakeCXCursor(E->getArg(0), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Visit(MakeCXCursor(E->getCallee(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I)
|
|
|
|
if (Visit(MakeCXCursor(E->getArg(I), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-27 21:34:58 +00:00
|
|
|
bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
|
|
|
if (D->isDefinition()) {
|
|
|
|
for (CXXRecordDecl::base_class_iterator I = D->bases_begin(),
|
|
|
|
E = D->bases_end(); I != E; ++I) {
|
|
|
|
if (Visit(cxcursor::MakeCursorCXXBaseSpecifier(I, TU)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VisitTagDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-11 21:47:37 +00:00
|
|
|
bool CursorVisitor::VisitBlockExpr(BlockExpr *B) {
|
|
|
|
return Visit(B->getBlockDecl());
|
|
|
|
}
|
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-28 22:16:22 +00:00
|
|
|
bool CursorVisitor::VisitOffsetOfExpr(OffsetOfExpr *E) {
|
2010-09-09 23:10:46 +00:00
|
|
|
// Visit the type into which we're computing an offset.
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-28 22:16:22 +00:00
|
|
|
if (Visit(E->getTypeSourceInfo()->getTypeLoc()))
|
|
|
|
return true;
|
2010-09-09 23:10:46 +00:00
|
|
|
|
|
|
|
// Visit the components of the offsetof expression.
|
|
|
|
for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
|
|
|
|
typedef OffsetOfExpr::OffsetOfNode OffsetOfNode;
|
|
|
|
const OffsetOfNode &Node = E->getComponent(I);
|
|
|
|
switch (Node.getKind()) {
|
|
|
|
case OffsetOfNode::Array:
|
|
|
|
if (Visit(MakeCXCursor(E->getIndexExpr(Node.getArrayExprIndex()),
|
|
|
|
StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OffsetOfNode::Field:
|
|
|
|
if (Visit(MakeCursorMemberRef(Node.getField(), Node.getRange().getEnd(),
|
|
|
|
TU)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OffsetOfNode::Identifier:
|
|
|
|
case OffsetOfNode::Base:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-28 22:16:22 +00:00
|
|
|
|
2010-09-09 23:10:46 +00:00
|
|
|
return false;
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-28 22:16:22 +00:00
|
|
|
}
|
|
|
|
|
2010-01-23 00:40:08 +00:00
|
|
|
bool CursorVisitor::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
|
|
|
|
if (E->isArgumentType()) {
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getArgumentTypeInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-23 00:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-23 00:40:08 +00:00
|
|
|
return VisitExpr(E);
|
|
|
|
}
|
|
|
|
|
2010-09-02 21:07:44 +00:00
|
|
|
bool CursorVisitor::VisitMemberExpr(MemberExpr *E) {
|
|
|
|
// Visit the base expression.
|
|
|
|
if (Visit(MakeCXCursor(E->getBase(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the nested-name-specifier
|
|
|
|
if (NestedNameSpecifier *Qualifier = E->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, E->getQualifierRange()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(E->getMemberNameInfo()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the explicitly-specified template arguments, if any.
|
|
|
|
if (E->hasExplicitTemplateArgs()) {
|
|
|
|
for (const TemplateArgumentLoc *Arg = E->getTemplateArgs(),
|
|
|
|
*ArgEnd = Arg + E->getNumTemplateArgs();
|
|
|
|
Arg != ArgEnd;
|
|
|
|
++Arg) {
|
|
|
|
if (VisitTemplateArgumentLoc(*Arg))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-23 00:40:08 +00:00
|
|
|
bool CursorVisitor::VisitExplicitCastExpr(ExplicitCastExpr *E) {
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getTypeInfoAsWritten())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-23 00:40:08 +00:00
|
|
|
return VisitCastExpr(E);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getTypeSourceInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-23 00:40:08 +00:00
|
|
|
return VisitExpr(E);
|
|
|
|
}
|
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
bool CursorVisitor::VisitAddrLabelExpr(AddrLabelExpr *E) {
|
|
|
|
return Visit(MakeCursorLabelRef(E->getLabel(), E->getLabelLoc(), TU));
|
|
|
|
}
|
|
|
|
|
2010-08-10 15:02:34 +00:00
|
|
|
bool CursorVisitor::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
|
|
|
|
return Visit(E->getArgTInfo1()->getTypeLoc()) ||
|
|
|
|
Visit(E->getArgTInfo2()->getTypeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitVAArgExpr(VAArgExpr *E) {
|
|
|
|
if (Visit(E->getWrittenTypeInfo()->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Visit(MakeCXCursor(E->getSubExpr(), StmtParent, TU));
|
|
|
|
}
|
|
|
|
|
2010-09-09 23:28:23 +00:00
|
|
|
bool CursorVisitor::VisitInitListExpr(InitListExpr *E) {
|
|
|
|
// We care about the syntactic form of the initializer list, only.
|
2010-09-17 20:26:51 +00:00
|
|
|
if (InitListExpr *Syntactic = E->getSyntacticForm())
|
|
|
|
return VisitExpr(Syntactic);
|
|
|
|
|
|
|
|
return VisitExpr(E);
|
2010-09-09 23:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
|
|
|
|
// Visit the designators.
|
|
|
|
typedef DesignatedInitExpr::Designator Designator;
|
|
|
|
for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
|
|
|
|
DEnd = E->designators_end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
if (D->isFieldDesignator()) {
|
|
|
|
if (FieldDecl *Field = D->getField())
|
|
|
|
if (Visit(MakeCursorMemberRef(Field, D->getFieldLoc(), TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (D->isArrayDesignator()) {
|
|
|
|
if (Visit(MakeCXCursor(E->getArrayIndex(*D), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(D->isArrayRangeDesignator() && "Unknown designator kind");
|
|
|
|
if (Visit(MakeCXCursor(E->getArrayRangeStart(*D), StmtParent, TU)) ||
|
|
|
|
Visit(MakeCXCursor(E->getArrayRangeEnd(*D), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Visit the initializer value itself.
|
|
|
|
return Visit(MakeCXCursor(E->getInit(), StmtParent, TU));
|
|
|
|
}
|
|
|
|
|
2010-09-02 21:20:16 +00:00
|
|
|
bool CursorVisitor::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
|
|
|
|
if (E->isTypeOperand()) {
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getTypeOperandSourceInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return VisitExpr(E);
|
|
|
|
}
|
|
|
|
|
2010-09-09 16:14:44 +00:00
|
|
|
bool CursorVisitor::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
|
|
|
|
if (E->isTypeOperand()) {
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getTypeOperandSourceInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return VisitExpr(E);
|
|
|
|
}
|
|
|
|
|
2010-09-08 00:15:04 +00:00
|
|
|
bool CursorVisitor::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getTypeSourceInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
|
|
|
|
return VisitExpr(E);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CursorVisitor::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getTypeSourceInfo())
|
|
|
|
return Visit(TSInfo->getTypeLoc());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-07 21:49:58 +00:00
|
|
|
bool CursorVisitor::VisitCXXNewExpr(CXXNewExpr *E) {
|
|
|
|
// Visit placement arguments.
|
|
|
|
for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I)
|
|
|
|
if (Visit(MakeCXCursor(E->getPlacementArg(I), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the allocated type.
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getAllocatedTypeSourceInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the array size, if any.
|
|
|
|
if (E->isArray() && Visit(MakeCXCursor(E->getArraySize(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the initializer or constructor arguments.
|
|
|
|
for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I)
|
|
|
|
if (Visit(MakeCXCursor(E->getConstructorArg(I), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-02 22:09:03 +00:00
|
|
|
bool CursorVisitor::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
|
|
|
|
// Visit base expression.
|
|
|
|
if (Visit(MakeCXCursor(E->getBase(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = E->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, E->getQualifierRange()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the scope type that looks disturbingly like the nested-name-specifier
|
|
|
|
// but isn't.
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getScopeTypeInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the name of the type being destroyed.
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getDestroyedTypeInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-09 16:14:44 +00:00
|
|
|
bool CursorVisitor::VisitUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
|
|
|
|
return Visit(E->getQueriedTypeSourceInfo()->getTypeLoc());
|
|
|
|
}
|
|
|
|
|
2010-09-02 22:29:21 +00:00
|
|
|
bool CursorVisitor::VisitOverloadExpr(OverloadExpr *E) {
|
2010-09-02 22:19:24 +00:00
|
|
|
// Visit the nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = E->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, E->getQualifierRange()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(E->getNameInfo()))
|
|
|
|
return true;
|
2010-09-13 22:52:57 +00:00
|
|
|
|
|
|
|
// Visit the overloaded declaration reference.
|
|
|
|
if (Visit(MakeCursorOverloadedDeclRef(E, TU)))
|
|
|
|
return true;
|
|
|
|
|
2010-09-02 22:29:21 +00:00
|
|
|
// Visit the explicitly-specified template arguments.
|
|
|
|
if (const ExplicitTemplateArgumentList *ArgList
|
|
|
|
= E->getOptionalExplicitTemplateArgs()) {
|
|
|
|
for (const TemplateArgumentLoc *Arg = ArgList->getTemplateArgs(),
|
|
|
|
*ArgEnd = Arg + ArgList->NumTemplateArgs;
|
|
|
|
Arg != ArgEnd; ++Arg) {
|
|
|
|
if (VisitTemplateArgumentLoc(*Arg))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-02 22:19:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-03 17:24:10 +00:00
|
|
|
bool CursorVisitor::VisitDependentScopeDeclRefExpr(
|
|
|
|
DependentScopeDeclRefExpr *E) {
|
|
|
|
// Visit the nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = E->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, E->getQualifierRange()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(E->getNameInfo()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the explicitly-specified template arguments.
|
|
|
|
if (const ExplicitTemplateArgumentList *ArgList
|
|
|
|
= E->getOptionalExplicitTemplateArgs()) {
|
|
|
|
for (const TemplateArgumentLoc *Arg = ArgList->getTemplateArgs(),
|
|
|
|
*ArgEnd = Arg + ArgList->NumTemplateArgs;
|
|
|
|
Arg != ArgEnd; ++Arg) {
|
|
|
|
if (VisitTemplateArgumentLoc(*Arg))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-08 00:15:04 +00:00
|
|
|
bool CursorVisitor::VisitCXXUnresolvedConstructExpr(
|
|
|
|
CXXUnresolvedConstructExpr *E) {
|
|
|
|
if (TypeSourceInfo *TSInfo = E->getTypeSourceInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitExpr(E);
|
|
|
|
}
|
|
|
|
|
2010-09-03 17:35:34 +00:00
|
|
|
bool CursorVisitor::VisitCXXDependentScopeMemberExpr(
|
|
|
|
CXXDependentScopeMemberExpr *E) {
|
|
|
|
// Visit the base expression, if there is one.
|
|
|
|
if (!E->isImplicitAccess() &&
|
|
|
|
Visit(MakeCXCursor(E->getBase(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the nested-name-specifier.
|
|
|
|
if (NestedNameSpecifier *Qualifier = E->getQualifier())
|
|
|
|
if (VisitNestedNameSpecifier(Qualifier, E->getQualifierRange()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the declaration name.
|
|
|
|
if (VisitDeclarationNameInfo(E->getMemberNameInfo()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Visit the explicitly-specified template arguments.
|
|
|
|
if (const ExplicitTemplateArgumentList *ArgList
|
|
|
|
= E->getOptionalExplicitTemplateArgs()) {
|
|
|
|
for (const TemplateArgumentLoc *Arg = ArgList->getTemplateArgs(),
|
|
|
|
*ArgEnd = Arg + ArgList->NumTemplateArgs;
|
|
|
|
Arg != ArgEnd; ++Arg) {
|
|
|
|
if (VisitTemplateArgumentLoc(*Arg))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-03 18:01:25 +00:00
|
|
|
bool CursorVisitor::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
|
|
|
|
// Visit the base expression, if there is one.
|
|
|
|
if (!E->isImplicitAccess() &&
|
|
|
|
Visit(MakeCXCursor(E->getBase(), StmtParent, TU)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return VisitOverloadExpr(E);
|
|
|
|
}
|
2010-09-03 17:35:34 +00:00
|
|
|
|
2010-03-08 16:40:19 +00:00
|
|
|
bool CursorVisitor::VisitObjCMessageExpr(ObjCMessageExpr *E) {
|
Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:
1) Send to a object instance described by an expression (e.g., [x method:5])
2) Send to a class described by the class name (e.g., [NSString method:5])
3) Send to a superclass class (e.g, [super method:5] in class method)
4) Send to a superclass instance (e.g., [super method:5] in instance method)
Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:
1) Unchanged; the object instance is represented by an Expr*.
2) Previously stored the ObjCInterfaceDecl* referring to the class
receiving the message. Now stores a TypeSourceInfo* so that we know
how the class was spelled. This both maintains typedef information
and opens the door for more complicated C++ types (e.g., dependent
types). There was an alternative, unused representation of these
sends by naming the class via an IdentifierInfo *. In practice, we
either had an ObjCInterfaceDecl *, from which we would get the
IdentifierInfo *, or we fell into the case below...
3) Previously represented by a class message whose IdentifierInfo *
referred to "super". Sema and CodeGen would use isStr("super") to
determine if they had a send to super. Now represented as a
"class super" send, where we have both the location of the "super"
keyword and the ObjCInterfaceDecl* of the superclass we're
targetting (statically).
4) Previously represented by an instance message whose receiver is a
an ObjCSuperExpr, which Sema and CodeGen would check for via
isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
where we have both the location of the "super" keyword and the
ObjCInterfaceDecl* of the superclass we're targetting
(statically). Note that ObjCSuperExpr only has one remaining use in
the AST, which is for "super.prop" references.
The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!
This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:
if (message has a receiver expression) {
// instance message
if (isa<ObjCSuperExpr>(...)) {
// send to super
} else {
// send to an object
}
} else {
// class message
if (name->isStr("super")) {
// class send to super
} else {
// send to class
}
}
with a switch
switch (E->getReceiverKind()) {
case ObjCMessageExpr::SuperInstance: ...
case ObjCMessageExpr::Instance: ...
case ObjCMessageExpr::SuperClass: ...
case ObjCMessageExpr::Class:...
}
There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.
llvm-svn: 101972
2010-04-21 00:45:42 +00:00
|
|
|
if (TypeSourceInfo *TSInfo = E->getClassReceiverTypeInfo())
|
|
|
|
if (Visit(TSInfo->getTypeLoc()))
|
|
|
|
return true;
|
2010-03-08 16:40:19 +00:00
|
|
|
|
|
|
|
return VisitExpr(E);
|
|
|
|
}
|
|
|
|
|
2010-04-20 15:39:42 +00:00
|
|
|
bool CursorVisitor::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
|
|
|
|
return Visit(E->getEncodedTypeSourceInfo()->getTypeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-18 05:46:33 +00:00
|
|
|
bool CursorVisitor::VisitAttributes(Decl *D) {
|
2010-08-18 23:23:40 +00:00
|
|
|
for (AttrVec::const_iterator i = D->attr_begin(), e = D->attr_end();
|
|
|
|
i != e; ++i)
|
|
|
|
if (Visit(MakeCXCursor(*i, D, TU)))
|
2010-02-18 05:46:33 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-24 21:18:36 +00:00
|
|
|
static llvm::sys::Mutex EnableMultithreadingMutex;
|
|
|
|
static bool EnabledMultithreading;
|
|
|
|
|
2009-10-18 16:11:04 +00:00
|
|
|
extern "C" {
|
2010-02-18 23:07:20 +00:00
|
|
|
CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
|
|
|
|
int displayDiagnostics) {
|
2010-10-08 19:30:33 +00:00
|
|
|
// Disable pretty stack trace functionality, which will otherwise be a very
|
|
|
|
// poor citizen of the world and set up all sorts of signal handlers.
|
|
|
|
llvm::DisablePrettyStackTrace = true;
|
|
|
|
|
2010-08-18 18:43:14 +00:00
|
|
|
// We use crash recovery to make some of our APIs more reliable, implicitly
|
|
|
|
// enable it.
|
|
|
|
llvm::CrashRecoveryContext::Enable();
|
|
|
|
|
2010-09-24 21:18:36 +00:00
|
|
|
// Enable support for multithreading in LLVM.
|
|
|
|
{
|
|
|
|
llvm::sys::ScopedLock L(EnableMultithreadingMutex);
|
|
|
|
if (!EnabledMultithreading) {
|
|
|
|
llvm::llvm_start_multithreaded();
|
|
|
|
EnabledMultithreading = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-22 20:35:53 +00:00
|
|
|
CIndexer *CIdxr = new CIndexer();
|
2009-10-20 14:46:24 +00:00
|
|
|
if (excludeDeclarationsFromPCH)
|
|
|
|
CIdxr->setOnlyLocalDecls();
|
2010-02-18 23:07:20 +00:00
|
|
|
if (displayDiagnostics)
|
|
|
|
CIdxr->setDisplayDiagnostics();
|
2009-10-20 14:46:24 +00:00
|
|
|
return CIdxr;
|
2009-08-27 19:51:58 +00:00
|
|
|
}
|
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
void clang_disposeIndex(CXIndex CIdx) {
|
2010-01-29 00:47:48 +00:00
|
|
|
if (CIdx)
|
|
|
|
delete static_cast<CIndexer *>(CIdx);
|
2009-09-17 18:33:27 +00:00
|
|
|
}
|
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
|
2010-02-18 18:08:43 +00:00
|
|
|
const char *ast_filename) {
|
2010-01-29 00:47:48 +00:00
|
|
|
if (!CIdx)
|
|
|
|
return 0;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2009-10-16 20:01:17 +00:00
|
|
|
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2010-04-05 23:52:57 +00:00
|
|
|
llvm::IntrusiveRefCntPtr<Diagnostic> Diags;
|
2010-08-18 23:57:06 +00:00
|
|
|
return ASTUnit::LoadFromASTFile(ast_filename, Diags,
|
2010-02-18 18:08:43 +00:00
|
|
|
CXXIdx->getOnlyLocalDecls(),
|
|
|
|
0, 0, true);
|
2009-08-27 19:51:58 +00:00
|
|
|
}
|
|
|
|
|
2010-08-09 22:28:58 +00:00
|
|
|
unsigned clang_defaultEditingTranslationUnitOptions() {
|
2010-09-27 05:49:58 +00:00
|
|
|
return CXTranslationUnit_PrecompiledPreamble |
|
|
|
|
CXTranslationUnit_CacheCompletionResults;
|
2010-08-09 22:28:58 +00:00
|
|
|
}
|
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
CXTranslationUnit
|
|
|
|
clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
|
|
|
|
const char *source_filename,
|
|
|
|
int num_command_line_args,
|
2010-09-01 16:43:19 +00:00
|
|
|
const char * const *command_line_args,
|
2010-01-23 00:14:00 +00:00
|
|
|
unsigned num_unsaved_files,
|
2010-02-18 18:08:43 +00:00
|
|
|
struct CXUnsavedFile *unsaved_files) {
|
2010-07-21 18:52:53 +00:00
|
|
|
return clang_parseTranslationUnit(CIdx, source_filename,
|
|
|
|
command_line_args, num_command_line_args,
|
|
|
|
unsaved_files, num_unsaved_files,
|
|
|
|
CXTranslationUnit_DetailedPreprocessingRecord);
|
|
|
|
}
|
2010-08-18 18:43:17 +00:00
|
|
|
|
|
|
|
struct ParseTranslationUnitInfo {
|
|
|
|
CXIndex CIdx;
|
|
|
|
const char *source_filename;
|
2010-09-01 16:43:19 +00:00
|
|
|
const char *const *command_line_args;
|
2010-08-18 18:43:17 +00:00
|
|
|
int num_command_line_args;
|
|
|
|
struct CXUnsavedFile *unsaved_files;
|
|
|
|
unsigned num_unsaved_files;
|
|
|
|
unsigned options;
|
|
|
|
CXTranslationUnit result;
|
|
|
|
};
|
2010-08-19 23:44:10 +00:00
|
|
|
static void clang_parseTranslationUnit_Impl(void *UserData) {
|
2010-08-18 18:43:17 +00:00
|
|
|
ParseTranslationUnitInfo *PTUI =
|
|
|
|
static_cast<ParseTranslationUnitInfo*>(UserData);
|
|
|
|
CXIndex CIdx = PTUI->CIdx;
|
|
|
|
const char *source_filename = PTUI->source_filename;
|
2010-09-01 16:43:19 +00:00
|
|
|
const char * const *command_line_args = PTUI->command_line_args;
|
2010-08-18 18:43:17 +00:00
|
|
|
int num_command_line_args = PTUI->num_command_line_args;
|
|
|
|
struct CXUnsavedFile *unsaved_files = PTUI->unsaved_files;
|
|
|
|
unsigned num_unsaved_files = PTUI->num_unsaved_files;
|
|
|
|
unsigned options = PTUI->options;
|
|
|
|
PTUI->result = 0;
|
2010-07-21 18:52:53 +00:00
|
|
|
|
2010-01-29 00:47:48 +00:00
|
|
|
if (!CIdx)
|
2010-08-18 18:43:17 +00:00
|
|
|
return;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2009-10-20 14:46:24 +00:00
|
|
|
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
|
|
|
|
|
2010-07-23 00:33:23 +00:00
|
|
|
bool PrecompilePreamble = options & CXTranslationUnit_PrecompiledPreamble;
|
2010-08-09 20:45:32 +00:00
|
|
|
bool CompleteTranslationUnit
|
|
|
|
= ((options & CXTranslationUnit_Incomplete) == 0);
|
2010-08-13 22:48:40 +00:00
|
|
|
bool CacheCodeCompetionResults
|
|
|
|
= options & CXTranslationUnit_CacheCompletionResults;
|
|
|
|
|
2010-01-28 00:27:43 +00:00
|
|
|
// Configure the diagnostics.
|
|
|
|
DiagnosticOptions DiagOpts;
|
2010-04-05 23:52:57 +00:00
|
|
|
llvm::IntrusiveRefCntPtr<Diagnostic> Diags;
|
|
|
|
Diags = CompilerInstance::createDiagnostics(DiagOpts, 0, 0);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-23 00:14:00 +00:00
|
|
|
llvm::SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles;
|
|
|
|
for (unsigned I = 0; I != num_unsaved_files; ++I) {
|
2010-04-05 22:42:27 +00:00
|
|
|
llvm::StringRef Data(unsaved_files[I].Contents, unsaved_files[I].Length);
|
2010-02-17 00:41:40 +00:00
|
|
|
const llvm::MemoryBuffer *Buffer
|
2010-04-05 22:42:27 +00:00
|
|
|
= llvm::MemoryBuffer::getMemBufferCopy(Data, unsaved_files[I].Filename);
|
2010-01-23 00:14:00 +00:00
|
|
|
RemappedFiles.push_back(std::make_pair(unsaved_files[I].Filename,
|
|
|
|
Buffer));
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-10-11 16:52:23 +00:00
|
|
|
llvm::SmallVector<const char *, 16> Args;
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2009-10-22 00:03:57 +00: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.
|
2009-11-30 20:42:43 +00:00
|
|
|
if (source_filename)
|
2010-10-11 16:52:23 +00:00
|
|
|
Args.push_back(source_filename);
|
2010-07-09 18:39:07 +00:00
|
|
|
|
|
|
|
// 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.
|
2010-10-11 16:52:23 +00:00
|
|
|
// 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;
|
2009-10-20 14:46:24 +00:00
|
|
|
}
|
2010-10-11 16:52:23 +00:00
|
|
|
}
|
|
|
|
if (!FoundSpellCheckingArgument)
|
|
|
|
Args.push_back("-fno-spell-checking");
|
|
|
|
|
|
|
|
Args.insert(Args.end(), command_line_args,
|
|
|
|
command_line_args + num_command_line_args);
|
2010-01-28 06:00:51 +00:00
|
|
|
|
2010-07-23 00:33:23 +00:00
|
|
|
// Do we need the detailed preprocessing record?
|
|
|
|
if (options & CXTranslationUnit_DetailedPreprocessingRecord) {
|
2010-10-11 16:52:23 +00:00
|
|
|
Args.push_back("-Xclang");
|
|
|
|
Args.push_back("-detailed-preprocessing-record");
|
2010-07-23 00:33:23 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 16:52:23 +00:00
|
|
|
unsigned NumErrors = Diags->getNumErrors();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-10-11 16:52:23 +00:00
|
|
|
#ifdef USE_CRASHTRACER
|
|
|
|
ArgsCrashTracerInfo ACTI(Args);
|
|
|
|
#endif
|
2009-10-18 11:19:36 +00:00
|
|
|
|
2010-10-11 16:52:23 +00:00
|
|
|
llvm::OwningPtr<ASTUnit> Unit(
|
|
|
|
ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
|
|
|
|
Diags,
|
|
|
|
CXXIdx->getClangResourcesPath(),
|
|
|
|
CXXIdx->getOnlyLocalDecls(),
|
|
|
|
RemappedFiles.data(),
|
|
|
|
RemappedFiles.size(),
|
|
|
|
/*CaptureDiagnostics=*/true,
|
|
|
|
PrecompilePreamble,
|
|
|
|
CompleteTranslationUnit,
|
|
|
|
CacheCodeCompetionResults));
|
|
|
|
|
|
|
|
if (NumErrors != Diags->getNumErrors()) {
|
|
|
|
// Make sure to check that 'Unit' is non-NULL.
|
|
|
|
if (CXXIdx->getDisplayDiagnostics() && Unit.get()) {
|
|
|
|
for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),
|
|
|
|
DEnd = Unit->stored_diag_end();
|
|
|
|
D != DEnd; ++D) {
|
|
|
|
CXStoredDiagnostic Diag(*D, Unit->getASTContext().getLangOptions());
|
|
|
|
CXString Msg = clang_formatDiagnostic(&Diag,
|
|
|
|
clang_defaultDiagnosticDisplayOptions());
|
|
|
|
fprintf(stderr, "%s\n", clang_getCString(Msg));
|
|
|
|
clang_disposeString(Msg);
|
|
|
|
}
|
2010-02-22 23:17:23 +00:00
|
|
|
#ifdef LLVM_ON_WIN32
|
2010-10-11 16:52:23 +00: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
|
|
|
|
}
|
2010-02-18 18:08:43 +00:00
|
|
|
}
|
2010-01-28 06:00:51 +00:00
|
|
|
|
2010-10-11 16:52:23 +00:00
|
|
|
PTUI->result = Unit.take();
|
2010-08-18 18:43:17 +00:00
|
|
|
}
|
|
|
|
CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
|
|
|
|
const char *source_filename,
|
2010-09-01 16:43:19 +00:00
|
|
|
const char * const *command_line_args,
|
2010-08-18 18:43:17 +00:00
|
|
|
int num_command_line_args,
|
|
|
|
struct CXUnsavedFile *unsaved_files,
|
|
|
|
unsigned num_unsaved_files,
|
|
|
|
unsigned options) {
|
|
|
|
ParseTranslationUnitInfo PTUI = { CIdx, source_filename, command_line_args,
|
|
|
|
num_command_line_args, unsaved_files, num_unsaved_files,
|
|
|
|
options, 0 };
|
|
|
|
llvm::CrashRecoveryContext CRC;
|
|
|
|
|
|
|
|
if (!CRC.RunSafely(clang_parseTranslationUnit_Impl, &PTUI)) {
|
2010-08-23 22:35:34 +00: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");
|
|
|
|
|
2010-08-18 18:43:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PTUI.result;
|
2009-10-15 20:04:39 +00:00
|
|
|
}
|
|
|
|
|
2010-08-13 15:35:05 +00:00
|
|
|
unsigned clang_defaultSaveOptions(CXTranslationUnit TU) {
|
|
|
|
return CXSaveTranslationUnit_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName,
|
|
|
|
unsigned options) {
|
2010-08-13 05:36:37 +00:00
|
|
|
if (!TU)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return static_cast<ASTUnit *>(TU)->Save(FileName);
|
|
|
|
}
|
2010-08-18 18:43:17 +00:00
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
|
2010-08-18 23:09:31 +00:00
|
|
|
if (CTUnit) {
|
|
|
|
// If the translation unit has been marked as unsafe to free, just discard
|
|
|
|
// it.
|
|
|
|
if (static_cast<ASTUnit *>(CTUnit)->isUnsafeToFree())
|
|
|
|
return;
|
|
|
|
|
2010-01-29 00:47:48 +00:00
|
|
|
delete static_cast<ASTUnit *>(CTUnit);
|
2010-08-18 23:09:31 +00:00
|
|
|
}
|
2009-09-17 18:33:27 +00:00
|
|
|
}
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2010-08-11 15:58:42 +00:00
|
|
|
unsigned clang_defaultReparseOptions(CXTranslationUnit TU) {
|
|
|
|
return CXReparse_None;
|
|
|
|
}
|
|
|
|
|
2010-08-18 23:09:31 +00:00
|
|
|
struct ReparseTranslationUnitInfo {
|
|
|
|
CXTranslationUnit TU;
|
|
|
|
unsigned num_unsaved_files;
|
|
|
|
struct CXUnsavedFile *unsaved_files;
|
|
|
|
unsigned options;
|
|
|
|
int result;
|
|
|
|
};
|
2010-09-23 18:47:53 +00:00
|
|
|
|
2010-08-19 23:44:10 +00:00
|
|
|
static void clang_reparseTranslationUnit_Impl(void *UserData) {
|
2010-08-18 23:09:31 +00:00
|
|
|
ReparseTranslationUnitInfo *RTUI =
|
|
|
|
static_cast<ReparseTranslationUnitInfo*>(UserData);
|
|
|
|
CXTranslationUnit TU = RTUI->TU;
|
|
|
|
unsigned num_unsaved_files = RTUI->num_unsaved_files;
|
|
|
|
struct CXUnsavedFile *unsaved_files = RTUI->unsaved_files;
|
|
|
|
unsigned options = RTUI->options;
|
|
|
|
(void) options;
|
|
|
|
RTUI->result = 1;
|
|
|
|
|
2010-07-19 21:46:24 +00:00
|
|
|
if (!TU)
|
2010-08-18 23:09:31 +00:00
|
|
|
return;
|
2010-09-23 18:47:53 +00:00
|
|
|
|
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
|
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
2010-07-19 21:46:24 +00:00
|
|
|
|
|
|
|
llvm::SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles;
|
|
|
|
for (unsigned I = 0; I != num_unsaved_files; ++I) {
|
|
|
|
llvm::StringRef Data(unsaved_files[I].Contents, unsaved_files[I].Length);
|
|
|
|
const llvm::MemoryBuffer *Buffer
|
2010-08-04 16:47:14 +00:00
|
|
|
= llvm::MemoryBuffer::getMemBufferCopy(Data, unsaved_files[I].Filename);
|
2010-07-19 21:46:24 +00:00
|
|
|
RemappedFiles.push_back(std::make_pair(unsaved_files[I].Filename,
|
|
|
|
Buffer));
|
|
|
|
}
|
|
|
|
|
2010-09-23 18:47:53 +00:00
|
|
|
if (!CXXUnit->Reparse(RemappedFiles.data(), RemappedFiles.size()))
|
|
|
|
RTUI->result = 0;
|
2010-07-19 21:46:24 +00:00
|
|
|
}
|
2010-09-23 18:47:53 +00:00
|
|
|
|
2010-08-18 23:09:31 +00:00
|
|
|
int clang_reparseTranslationUnit(CXTranslationUnit TU,
|
|
|
|
unsigned num_unsaved_files,
|
|
|
|
struct CXUnsavedFile *unsaved_files,
|
|
|
|
unsigned options) {
|
|
|
|
ReparseTranslationUnitInfo RTUI = { TU, num_unsaved_files, unsaved_files,
|
|
|
|
options, 0 };
|
|
|
|
llvm::CrashRecoveryContext CRC;
|
|
|
|
|
|
|
|
if (!CRC.RunSafely(clang_reparseTranslationUnit_Impl, &RTUI)) {
|
2010-08-19 23:44:10 +00:00
|
|
|
fprintf(stderr, "libclang: crash detected during reparsing\n");
|
2010-08-18 23:09:31 +00:00
|
|
|
static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RTUI.result;
|
|
|
|
}
|
|
|
|
|
2010-08-09 20:45:32 +00:00
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) {
|
2010-01-29 00:47:48 +00:00
|
|
|
if (!CTUnit)
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString("");
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2009-09-03 18:19:54 +00:00
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(CXXUnit->getOriginalSourceFileName(), true);
|
2009-09-03 15:49:00 +00:00
|
|
|
}
|
2009-08-28 16:30:07 +00:00
|
|
|
|
2010-01-20 00:23:15 +00:00
|
|
|
CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
|
2010-01-20 23:57:43 +00:00
|
|
|
CXCursor Result = { CXCursor_TranslationUnit, { 0, 0, TU } };
|
2010-01-20 00:23:15 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
} // end: extern "C"
|
2009-08-27 19:51:58 +00:00
|
|
|
|
2010-01-19 21:36:55 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CXSourceLocation and CXSourceRange Operations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
extern "C" {
|
|
|
|
CXSourceLocation clang_getNullLocation() {
|
2010-01-28 00:27:43 +00:00
|
|
|
CXSourceLocation Result = { { 0, 0 }, 0 };
|
2010-01-22 21:44:22 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_equalLocations(CXSourceLocation loc1, CXSourceLocation loc2) {
|
2010-01-30 23:58:27 +00:00
|
|
|
return (loc1.ptr_data[0] == loc2.ptr_data[0] &&
|
|
|
|
loc1.ptr_data[1] == loc2.ptr_data[1] &&
|
|
|
|
loc1.int_data == loc2.int_data);
|
2010-01-22 21:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceLocation clang_getLocation(CXTranslationUnit tu,
|
|
|
|
CXFile file,
|
|
|
|
unsigned line,
|
|
|
|
unsigned column) {
|
2010-04-30 19:45:53 +00:00
|
|
|
if (!tu || !file)
|
2010-01-22 21:44:22 +00:00
|
|
|
return clang_getNullLocation();
|
2010-04-30 19:45:53 +00:00
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu);
|
|
|
|
SourceLocation SLoc
|
|
|
|
= CXXUnit->getSourceManager().getLocation(
|
2010-02-17 00:41:40 +00:00
|
|
|
static_cast<const FileEntry *>(file),
|
2010-01-22 21:44:22 +00:00
|
|
|
line, column);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-06-28 23:54:17 +00:00
|
|
|
return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
|
2010-01-22 21:44:22 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 00:27:43 +00:00
|
|
|
CXSourceRange clang_getNullRange() {
|
|
|
|
CXSourceRange Result = { { 0, 0 }, 0, 0 };
|
|
|
|
return Result;
|
|
|
|
}
|
2010-02-14 10:02:57 +00:00
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
CXSourceRange clang_getRange(CXSourceLocation begin, CXSourceLocation end) {
|
2010-01-28 00:27:43 +00:00
|
|
|
if (begin.ptr_data[0] != end.ptr_data[0] ||
|
|
|
|
begin.ptr_data[1] != end.ptr_data[1])
|
|
|
|
return clang_getNullRange();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
CXSourceRange Result = { { begin.ptr_data[0], begin.ptr_data[1] },
|
2010-01-28 00:27:43 +00:00
|
|
|
begin.int_data, end.int_data };
|
2010-01-22 21:44:22 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-01-26 19:19:08 +00:00
|
|
|
void clang_getInstantiationLocation(CXSourceLocation location,
|
|
|
|
CXFile *file,
|
|
|
|
unsigned *line,
|
|
|
|
unsigned *column,
|
|
|
|
unsigned *offset) {
|
2010-01-19 21:36:55 +00:00
|
|
|
SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
|
|
|
|
|
2010-02-14 01:47:36 +00:00
|
|
|
if (!location.ptr_data[0] || Loc.isInvalid()) {
|
2010-01-26 19:19:08 +00:00
|
|
|
if (file)
|
|
|
|
*file = 0;
|
|
|
|
if (line)
|
|
|
|
*line = 0;
|
|
|
|
if (column)
|
|
|
|
*column = 0;
|
|
|
|
if (offset)
|
|
|
|
*offset = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-14 01:47:36 +00:00
|
|
|
const SourceManager &SM =
|
|
|
|
*static_cast<const SourceManager*>(location.ptr_data[0]);
|
2010-01-19 21:36:55 +00:00
|
|
|
SourceLocation InstLoc = SM.getInstantiationLoc(Loc);
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
*file = (void *)SM.getFileEntryForID(SM.getFileID(InstLoc));
|
|
|
|
if (line)
|
|
|
|
*line = SM.getInstantiationLineNumber(InstLoc);
|
|
|
|
if (column)
|
|
|
|
*column = SM.getInstantiationColumnNumber(InstLoc);
|
2010-01-26 03:07:15 +00:00
|
|
|
if (offset)
|
2010-01-26 19:19:08 +00:00
|
|
|
*offset = SM.getDecomposedLoc(InstLoc).second;
|
2010-01-26 03:07:15 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 21:36:55 +00:00
|
|
|
CXSourceLocation clang_getRangeStart(CXSourceRange range) {
|
2010-02-17 00:41:40 +00:00
|
|
|
CXSourceLocation Result = { { range.ptr_data[0], range.ptr_data[1] },
|
2010-01-28 00:27:43 +00:00
|
|
|
range.begin_int_data };
|
2010-01-19 21:36:55 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceLocation clang_getRangeEnd(CXSourceRange range) {
|
2010-02-14 01:47:36 +00:00
|
|
|
CXSourceLocation Result = { { range.ptr_data[0], range.ptr_data[1] },
|
2010-01-28 00:27:43 +00:00
|
|
|
range.end_int_data };
|
2010-01-19 21:36:55 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
} // end: extern "C"
|
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CXFile Operations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
extern "C" {
|
2010-02-17 00:41:20 +00:00
|
|
|
CXString clang_getFileName(CXFile SFile) {
|
2010-01-18 22:46:11 +00:00
|
|
|
if (!SFile)
|
2010-02-17 00:41:20 +00:00
|
|
|
return createCXString(NULL);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2009-10-27 14:35:18 +00:00
|
|
|
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
|
2010-02-17 00:41:20 +00:00
|
|
|
return createCXString(FEnt->getName());
|
2009-10-27 14:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
time_t clang_getFileTime(CXFile SFile) {
|
2010-01-18 22:46:11 +00:00
|
|
|
if (!SFile)
|
|
|
|
return 0;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2009-10-27 14:35:18 +00:00
|
|
|
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
|
|
|
|
return FEnt->getModificationTime();
|
2009-09-25 21:45:39 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
CXFile clang_getFile(CXTranslationUnit tu, const char *file_name) {
|
|
|
|
if (!tu)
|
|
|
|
return 0;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
FileManager &FMgr = CXXUnit->getFileManager();
|
|
|
|
const FileEntry *File = FMgr.getFile(file_name, file_name+strlen(file_name));
|
|
|
|
return const_cast<FileEntry *>(File);
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
} // end: extern "C"
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CXCursor Operations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static Decl *getDeclFromExpr(Stmt *E) {
|
2010-10-01 21:11:22 +00:00
|
|
|
if (CastExpr *CE = dyn_cast<CastExpr>(E))
|
|
|
|
return getDeclFromExpr(CE->getSubExpr());
|
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
if (DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E))
|
|
|
|
return RefExpr->getDecl();
|
|
|
|
if (MemberExpr *ME = dyn_cast<MemberExpr>(E))
|
|
|
|
return ME->getMemberDecl();
|
|
|
|
if (ObjCIvarRefExpr *RE = dyn_cast<ObjCIvarRefExpr>(E))
|
|
|
|
return RE->getDecl();
|
2010-10-01 21:11:22 +00:00
|
|
|
if (ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(E))
|
|
|
|
return PRE->getProperty();
|
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
if (CallExpr *CE = dyn_cast<CallExpr>(E))
|
|
|
|
return getDeclFromExpr(CE->getCallee());
|
|
|
|
if (ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(E))
|
|
|
|
return OME->getMethodDecl();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-10-01 21:11:22 +00:00
|
|
|
if (ObjCProtocolExpr *PE = dyn_cast<ObjCProtocolExpr>(E))
|
|
|
|
return PE->getProtocol();
|
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-09-25 21:45:39 +00:00
|
|
|
|
2010-02-02 05:00:22 +00:00
|
|
|
static SourceLocation getLocationFromExpr(Expr *E) {
|
|
|
|
if (ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
|
|
|
|
return /*FIXME:*/Msg->getLeftLoc();
|
|
|
|
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
|
|
|
|
return DRE->getLocation();
|
|
|
|
if (MemberExpr *Member = dyn_cast<MemberExpr>(E))
|
|
|
|
return Member->getMemberLoc();
|
|
|
|
if (ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
|
|
|
|
return Ivar->getLocation();
|
|
|
|
return E->getLocStart();
|
|
|
|
}
|
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
extern "C" {
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
unsigned clang_visitChildren(CXCursor parent,
|
2010-01-20 20:59:29 +00:00
|
|
|
CXCursorVisitor visitor,
|
|
|
|
CXClientData client_data) {
|
2010-01-20 23:57:43 +00:00
|
|
|
ASTUnit *CXXUnit = getCursorASTUnit(parent);
|
2010-01-20 20:59:29 +00:00
|
|
|
|
2010-08-03 19:06:41 +00:00
|
|
|
CursorVisitor CursorVis(CXXUnit, visitor, client_data,
|
|
|
|
CXXUnit->getMaxPCHLevel());
|
2010-01-20 20:59:29 +00:00
|
|
|
return CursorVis.VisitChildren(parent);
|
|
|
|
}
|
|
|
|
|
2010-01-20 21:45:58 +00:00
|
|
|
static CXString getDeclSpelling(Decl *D) {
|
|
|
|
NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D);
|
|
|
|
if (!ND)
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString("");
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 21:45:58 +00:00
|
|
|
if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND))
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(OMD->getSelector().getAsString());
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 21:45:58 +00:00
|
|
|
if (ObjCCategoryImplDecl *CIMP = dyn_cast<ObjCCategoryImplDecl>(ND))
|
|
|
|
// 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.
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(CIMP->getIdentifier()->getNameStart());
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-09-01 03:07:18 +00:00
|
|
|
if (isa<UsingDirectiveDecl>(D))
|
|
|
|
return createCXString("");
|
|
|
|
|
2010-05-19 21:51:10 +00:00
|
|
|
llvm::SmallString<1024> S;
|
|
|
|
llvm::raw_svector_ostream os(S);
|
|
|
|
ND->printName(os);
|
|
|
|
|
|
|
|
return createCXString(os.str());
|
2010-01-20 21:45:58 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
CXString clang_getCursorSpelling(CXCursor C) {
|
2010-01-20 00:23:15 +00:00
|
|
|
if (clang_isTranslationUnit(C.kind))
|
2010-01-20 23:57:43 +00:00
|
|
|
return clang_getTranslationUnitSpelling(C.data[2]);
|
2010-01-20 00:23:15 +00:00
|
|
|
|
2009-09-02 18:26:48 +00:00
|
|
|
if (clang_isReference(C.kind)) {
|
|
|
|
switch (C.kind) {
|
2009-11-30 20:42:49 +00:00
|
|
|
case CXCursor_ObjCSuperClassRef: {
|
2010-01-16 14:00:32 +00:00
|
|
|
ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first;
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(Super->getIdentifier()->getNameStart());
|
2009-11-30 20:42:49 +00:00
|
|
|
}
|
|
|
|
case CXCursor_ObjCClassRef: {
|
2010-01-16 17:14:40 +00:00
|
|
|
ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(Class->getIdentifier()->getNameStart());
|
2009-11-30 20:42:49 +00:00
|
|
|
}
|
|
|
|
case CXCursor_ObjCProtocolRef: {
|
2010-01-16 15:44:18 +00:00
|
|
|
ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first;
|
2010-01-18 23:41:10 +00:00
|
|
|
assert(OID && "getCursorSpelling(): Missing protocol decl");
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(OID->getIdentifier()->getNameStart());
|
2009-11-30 20:42:49 +00:00
|
|
|
}
|
2010-08-27 21:34:58 +00:00
|
|
|
case CXCursor_CXXBaseSpecifier: {
|
|
|
|
CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C);
|
|
|
|
return createCXString(B->getType().getAsString());
|
|
|
|
}
|
2010-01-21 16:28:34 +00:00
|
|
|
case CXCursor_TypeRef: {
|
|
|
|
TypeDecl *Type = getCursorTypeRef(C).first;
|
|
|
|
assert(Type && "Missing type decl");
|
|
|
|
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(getCursorContext(C).getTypeDeclType(Type).
|
|
|
|
getAsString());
|
2010-01-21 16:28:34 +00:00
|
|
|
}
|
2010-08-31 20:37:03 +00:00
|
|
|
case CXCursor_TemplateRef: {
|
|
|
|
TemplateDecl *Template = getCursorTemplateRef(C).first;
|
2010-08-31 23:48:11 +00:00
|
|
|
assert(Template && "Missing template decl");
|
2010-08-31 20:37:03 +00:00
|
|
|
|
|
|
|
return createCXString(Template->getNameAsString());
|
|
|
|
}
|
2010-08-31 23:48:11 +00:00
|
|
|
|
|
|
|
case CXCursor_NamespaceRef: {
|
|
|
|
NamedDecl *NS = getCursorNamespaceRef(C).first;
|
|
|
|
assert(NS && "Missing namespace decl");
|
|
|
|
|
|
|
|
return createCXString(NS->getNameAsString());
|
|
|
|
}
|
2010-01-21 16:28:34 +00:00
|
|
|
|
2010-09-09 21:42:20 +00:00
|
|
|
case CXCursor_MemberRef: {
|
|
|
|
FieldDecl *Field = getCursorMemberRef(C).first;
|
|
|
|
assert(Field && "Missing member decl");
|
|
|
|
|
|
|
|
return createCXString(Field->getNameAsString());
|
|
|
|
}
|
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
case CXCursor_LabelRef: {
|
|
|
|
LabelStmt *Label = getCursorLabelRef(C).first;
|
|
|
|
assert(Label && "Missing label");
|
|
|
|
|
|
|
|
return createCXString(Label->getID()->getName());
|
|
|
|
}
|
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
case CXCursor_OverloadedDeclRef: {
|
|
|
|
OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first;
|
|
|
|
if (Decl *D = Storage.dyn_cast<Decl *>()) {
|
|
|
|
if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
|
|
|
|
return createCXString(ND->getNameAsString());
|
|
|
|
return createCXString("");
|
|
|
|
}
|
|
|
|
if (OverloadExpr *E = Storage.dyn_cast<OverloadExpr *>())
|
|
|
|
return createCXString(E->getName().getAsString());
|
|
|
|
OverloadedTemplateStorage *Ovl
|
|
|
|
= Storage.get<OverloadedTemplateStorage*>();
|
|
|
|
if (Ovl->size() == 0)
|
|
|
|
return createCXString("");
|
|
|
|
return createCXString((*Ovl->begin())->getNameAsString());
|
|
|
|
}
|
|
|
|
|
2009-11-30 20:42:49 +00:00
|
|
|
default:
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString("<not implemented>");
|
2009-09-02 18:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-19 23:20:36 +00:00
|
|
|
|
|
|
|
if (clang_isExpression(C.kind)) {
|
|
|
|
Decl *D = getDeclFromExpr(getCursorExpr(C));
|
|
|
|
if (D)
|
2010-01-20 21:45:58 +00:00
|
|
|
return getDeclSpelling(D);
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString("");
|
2010-01-19 23:20:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
if (clang_isStatement(C.kind)) {
|
|
|
|
Stmt *S = getCursorStmt(C);
|
|
|
|
if (LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
|
|
|
|
return createCXString(Label->getID()->getName());
|
|
|
|
|
|
|
|
return createCXString("");
|
|
|
|
}
|
|
|
|
|
Introduce the notion of a "preprocessing record", which keeps track of
the macro definitions and macro instantiations that are found
during preprocessing. Preprocessing records are *not* generated by
default; rather, we provide a PPCallbacks subclass that hooks into the
existing callback mechanism to record this activity.
The only client of preprocessing records is CIndex, which keeps track
of macro definitions and instantations so that they can be exposed via
cursors. At present, only token annotation uses these facilities, and
only for macro instantiations; both will change in the near
future. However, with this change, token annotation properly annotates
macro instantiations that do not produce any tokens and instantiations
of macros that are later undef'd, improving our consistency.
Preprocessing directives that are not macro definitions are still
handled by clang_annotateTokens() via re-lexing, so that we don't have
to track every preprocessing directive in the preprocessing record.
Performance impact of preprocessing records is still TBD, although it
is limited to CIndex and therefore out of the path of the main compiler.
llvm-svn: 98836
2010-03-18 17:52:52 +00:00
|
|
|
if (C.kind == CXCursor_MacroInstantiation)
|
|
|
|
return createCXString(getCursorMacroInstantiation(C)->getName()
|
|
|
|
->getNameStart());
|
|
|
|
|
2010-03-18 18:04:21 +00:00
|
|
|
if (C.kind == CXCursor_MacroDefinition)
|
|
|
|
return createCXString(getCursorMacroDefinition(C)->getName()
|
|
|
|
->getNameStart());
|
|
|
|
|
2010-01-25 16:56:17 +00:00
|
|
|
if (clang_isDeclaration(C.kind))
|
|
|
|
return getDeclSpelling(getCursorDecl(C));
|
2010-02-17 00:41:32 +00:00
|
|
|
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString("");
|
2009-09-02 18:26:48 +00:00
|
|
|
}
|
|
|
|
|
2010-10-02 22:49:11 +00:00
|
|
|
CXString clang_getCursorDisplayName(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return clang_getCursorSpelling(C);
|
|
|
|
|
|
|
|
Decl *D = getCursorDecl(C);
|
|
|
|
if (!D)
|
|
|
|
return createCXString("");
|
|
|
|
|
|
|
|
PrintingPolicy &Policy = getCursorContext(C).PrintingPolicy;
|
|
|
|
if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
|
|
|
|
D = FunTmpl->getTemplatedDecl();
|
|
|
|
|
|
|
|
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
llvm::SmallString<64> Str;
|
|
|
|
llvm::raw_svector_ostream OS(Str);
|
|
|
|
OS << Function->getNameAsString();
|
|
|
|
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 << ")";
|
|
|
|
return createCXString(OS.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(D)) {
|
|
|
|
llvm::SmallString<64> Str;
|
|
|
|
llvm::raw_svector_ostream OS(Str);
|
|
|
|
OS << ClassTemplate->getNameAsString();
|
|
|
|
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 << ">";
|
|
|
|
return createCXString(OS.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ClassTemplateSpecializationDecl *ClassSpec
|
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(D)) {
|
|
|
|
// If the type was explicitly written, use that.
|
|
|
|
if (TypeSourceInfo *TSInfo = ClassSpec->getTypeAsWritten())
|
|
|
|
return createCXString(TSInfo->getType().getAsString(Policy));
|
|
|
|
|
|
|
|
llvm::SmallString<64> Str;
|
|
|
|
llvm::raw_svector_ostream OS(Str);
|
|
|
|
OS << ClassSpec->getNameAsString();
|
|
|
|
OS << TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
ClassSpec->getTemplateArgs().getFlatArgumentList(),
|
|
|
|
ClassSpec->getTemplateArgs().flat_size(),
|
|
|
|
Policy);
|
|
|
|
return createCXString(OS.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getCursorSpelling(C);
|
|
|
|
}
|
|
|
|
|
2010-02-17 00:41:32 +00:00
|
|
|
CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
|
2009-08-31 00:59:03 +00:00
|
|
|
switch (Kind) {
|
2010-02-17 00:41:32 +00:00
|
|
|
case CXCursor_FunctionDecl:
|
|
|
|
return createCXString("FunctionDecl");
|
|
|
|
case CXCursor_TypedefDecl:
|
|
|
|
return createCXString("TypedefDecl");
|
|
|
|
case CXCursor_EnumDecl:
|
|
|
|
return createCXString("EnumDecl");
|
|
|
|
case CXCursor_EnumConstantDecl:
|
|
|
|
return createCXString("EnumConstantDecl");
|
|
|
|
case CXCursor_StructDecl:
|
|
|
|
return createCXString("StructDecl");
|
|
|
|
case CXCursor_UnionDecl:
|
|
|
|
return createCXString("UnionDecl");
|
|
|
|
case CXCursor_ClassDecl:
|
|
|
|
return createCXString("ClassDecl");
|
|
|
|
case CXCursor_FieldDecl:
|
|
|
|
return createCXString("FieldDecl");
|
|
|
|
case CXCursor_VarDecl:
|
|
|
|
return createCXString("VarDecl");
|
|
|
|
case CXCursor_ParmDecl:
|
|
|
|
return createCXString("ParmDecl");
|
|
|
|
case CXCursor_ObjCInterfaceDecl:
|
|
|
|
return createCXString("ObjCInterfaceDecl");
|
|
|
|
case CXCursor_ObjCCategoryDecl:
|
|
|
|
return createCXString("ObjCCategoryDecl");
|
|
|
|
case CXCursor_ObjCProtocolDecl:
|
|
|
|
return createCXString("ObjCProtocolDecl");
|
|
|
|
case CXCursor_ObjCPropertyDecl:
|
|
|
|
return createCXString("ObjCPropertyDecl");
|
|
|
|
case CXCursor_ObjCIvarDecl:
|
|
|
|
return createCXString("ObjCIvarDecl");
|
|
|
|
case CXCursor_ObjCInstanceMethodDecl:
|
|
|
|
return createCXString("ObjCInstanceMethodDecl");
|
|
|
|
case CXCursor_ObjCClassMethodDecl:
|
|
|
|
return createCXString("ObjCClassMethodDecl");
|
|
|
|
case CXCursor_ObjCImplementationDecl:
|
|
|
|
return createCXString("ObjCImplementationDecl");
|
|
|
|
case CXCursor_ObjCCategoryImplDecl:
|
|
|
|
return createCXString("ObjCCategoryImplDecl");
|
2010-04-13 23:39:06 +00:00
|
|
|
case CXCursor_CXXMethod:
|
|
|
|
return createCXString("CXXMethod");
|
2010-02-17 00:41:32 +00:00
|
|
|
case CXCursor_UnexposedDecl:
|
|
|
|
return createCXString("UnexposedDecl");
|
|
|
|
case CXCursor_ObjCSuperClassRef:
|
|
|
|
return createCXString("ObjCSuperClassRef");
|
|
|
|
case CXCursor_ObjCProtocolRef:
|
|
|
|
return createCXString("ObjCProtocolRef");
|
|
|
|
case CXCursor_ObjCClassRef:
|
|
|
|
return createCXString("ObjCClassRef");
|
|
|
|
case CXCursor_TypeRef:
|
|
|
|
return createCXString("TypeRef");
|
2010-08-31 20:37:03 +00:00
|
|
|
case CXCursor_TemplateRef:
|
|
|
|
return createCXString("TemplateRef");
|
2010-08-31 23:48:11 +00:00
|
|
|
case CXCursor_NamespaceRef:
|
|
|
|
return createCXString("NamespaceRef");
|
2010-09-09 21:42:20 +00:00
|
|
|
case CXCursor_MemberRef:
|
|
|
|
return createCXString("MemberRef");
|
2010-09-10 00:22:18 +00:00
|
|
|
case CXCursor_LabelRef:
|
|
|
|
return createCXString("LabelRef");
|
2010-09-13 22:52:57 +00:00
|
|
|
case CXCursor_OverloadedDeclRef:
|
|
|
|
return createCXString("OverloadedDeclRef");
|
2010-02-17 00:41:32 +00:00
|
|
|
case CXCursor_UnexposedExpr:
|
|
|
|
return createCXString("UnexposedExpr");
|
2010-04-11 21:47:37 +00:00
|
|
|
case CXCursor_BlockExpr:
|
|
|
|
return createCXString("BlockExpr");
|
2010-02-17 00:41:32 +00:00
|
|
|
case CXCursor_DeclRefExpr:
|
|
|
|
return createCXString("DeclRefExpr");
|
|
|
|
case CXCursor_MemberRefExpr:
|
|
|
|
return createCXString("MemberRefExpr");
|
|
|
|
case CXCursor_CallExpr:
|
|
|
|
return createCXString("CallExpr");
|
|
|
|
case CXCursor_ObjCMessageExpr:
|
|
|
|
return createCXString("ObjCMessageExpr");
|
|
|
|
case CXCursor_UnexposedStmt:
|
|
|
|
return createCXString("UnexposedStmt");
|
2010-09-10 00:22:18 +00:00
|
|
|
case CXCursor_LabelStmt:
|
|
|
|
return createCXString("LabelStmt");
|
2010-02-17 00:41:32 +00:00
|
|
|
case CXCursor_InvalidFile:
|
|
|
|
return createCXString("InvalidFile");
|
2010-03-19 20:39:05 +00:00
|
|
|
case CXCursor_InvalidCode:
|
|
|
|
return createCXString("InvalidCode");
|
2010-02-17 00:41:32 +00:00
|
|
|
case CXCursor_NoDeclFound:
|
|
|
|
return createCXString("NoDeclFound");
|
|
|
|
case CXCursor_NotImplemented:
|
|
|
|
return createCXString("NotImplemented");
|
|
|
|
case CXCursor_TranslationUnit:
|
|
|
|
return createCXString("TranslationUnit");
|
2010-02-18 03:09:07 +00:00
|
|
|
case CXCursor_UnexposedAttr:
|
|
|
|
return createCXString("UnexposedAttr");
|
|
|
|
case CXCursor_IBActionAttr:
|
|
|
|
return createCXString("attribute(ibaction)");
|
2010-03-18 00:42:48 +00:00
|
|
|
case CXCursor_IBOutletAttr:
|
|
|
|
return createCXString("attribute(iboutlet)");
|
2010-05-19 17:38:06 +00:00
|
|
|
case CXCursor_IBOutletCollectionAttr:
|
|
|
|
return createCXString("attribute(iboutletcollection)");
|
2010-03-18 00:42:48 +00:00
|
|
|
case CXCursor_PreprocessingDirective:
|
|
|
|
return createCXString("preprocessing directive");
|
2010-03-18 18:04:21 +00:00
|
|
|
case CXCursor_MacroDefinition:
|
|
|
|
return createCXString("macro definition");
|
2010-03-18 15:23:44 +00:00
|
|
|
case CXCursor_MacroInstantiation:
|
|
|
|
return createCXString("macro instantiation");
|
2010-05-06 23:38:21 +00:00
|
|
|
case CXCursor_Namespace:
|
|
|
|
return createCXString("Namespace");
|
2010-05-07 01:04:29 +00:00
|
|
|
case CXCursor_LinkageSpec:
|
|
|
|
return createCXString("LinkageSpec");
|
2010-08-27 21:34:58 +00:00
|
|
|
case CXCursor_CXXBaseSpecifier:
|
|
|
|
return createCXString("C++ base class specifier");
|
2010-08-31 14:41:23 +00:00
|
|
|
case CXCursor_Constructor:
|
|
|
|
return createCXString("CXXConstructor");
|
|
|
|
case CXCursor_Destructor:
|
|
|
|
return createCXString("CXXDestructor");
|
|
|
|
case CXCursor_ConversionFunction:
|
|
|
|
return createCXString("CXXConversion");
|
2010-08-31 17:01:39 +00:00
|
|
|
case CXCursor_TemplateTypeParameter:
|
|
|
|
return createCXString("TemplateTypeParameter");
|
|
|
|
case CXCursor_NonTypeTemplateParameter:
|
|
|
|
return createCXString("NonTypeTemplateParameter");
|
|
|
|
case CXCursor_TemplateTemplateParameter:
|
|
|
|
return createCXString("TemplateTemplateParameter");
|
|
|
|
case CXCursor_FunctionTemplate:
|
|
|
|
return createCXString("FunctionTemplate");
|
2010-08-31 19:02:00 +00:00
|
|
|
case CXCursor_ClassTemplate:
|
|
|
|
return createCXString("ClassTemplate");
|
2010-08-31 19:31:58 +00:00
|
|
|
case CXCursor_ClassTemplatePartialSpecialization:
|
|
|
|
return createCXString("ClassTemplatePartialSpecialization");
|
2010-08-31 23:48:11 +00:00
|
|
|
case CXCursor_NamespaceAlias:
|
|
|
|
return createCXString("NamespaceAlias");
|
2010-09-01 03:07:18 +00:00
|
|
|
case CXCursor_UsingDirective:
|
|
|
|
return createCXString("UsingDirective");
|
2010-09-01 19:52:22 +00:00
|
|
|
case CXCursor_UsingDeclaration:
|
|
|
|
return createCXString("UsingDeclaration");
|
2009-08-31 00:59:03 +00:00
|
|
|
}
|
2010-02-17 00:41:32 +00:00
|
|
|
|
2010-01-16 02:02:09 +00:00
|
|
|
llvm_unreachable("Unhandled CXCursorKind");
|
2010-02-17 00:41:32 +00:00
|
|
|
return createCXString(NULL);
|
2009-08-27 19:51:58 +00:00
|
|
|
}
|
2009-08-31 00:59:03 +00:00
|
|
|
|
2010-02-17 00:41:32 +00:00
|
|
|
enum CXChildVisitResult GetCursorVisitor(CXCursor cursor,
|
|
|
|
CXCursor parent,
|
2010-01-22 19:49:59 +00:00
|
|
|
CXClientData client_data) {
|
|
|
|
CXCursor *BestCursor = static_cast<CXCursor *>(client_data);
|
|
|
|
*BestCursor = cursor;
|
|
|
|
return CXChildVisit_Recurse;
|
|
|
|
}
|
2010-02-17 00:41:32 +00:00
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) {
|
|
|
|
if (!TU)
|
2010-01-14 01:51:23 +00:00
|
|
|
return clang_getNullCursor();
|
2010-02-17 00:41:32 +00:00
|
|
|
|
2010-01-22 21:44:22 +00:00
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
|
2010-03-05 21:16:25 +00:00
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
// Translate the given source location to make it point at the beginning of
|
|
|
|
// the token under the cursor.
|
2010-01-25 22:34:44 +00:00
|
|
|
SourceLocation SLoc = cxloc::translateSourceLocation(Loc);
|
2010-07-29 00:52:07 +00:00
|
|
|
|
|
|
|
// Guard against an invalid SourceLocation, or we may assert in one
|
|
|
|
// of the following calls.
|
|
|
|
if (SLoc.isInvalid())
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
SLoc = Lexer::GetBeginningOfToken(SLoc, CXXUnit->getSourceManager(),
|
|
|
|
CXXUnit->getASTContext().getLangOptions());
|
|
|
|
|
2010-01-22 19:49:59 +00:00
|
|
|
CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound);
|
|
|
|
if (SLoc.isValid()) {
|
|
|
|
// FIXME: Would be great to have a "hint" cursor, then walk from that
|
|
|
|
// hint cursor upward until we find a cursor whose source range encloses
|
|
|
|
// the region of interest, rather than starting from the translation unit.
|
|
|
|
CXCursor Parent = clang_getTranslationUnitCursor(CXXUnit);
|
2010-02-17 00:41:32 +00:00
|
|
|
CursorVisitor CursorVis(CXXUnit, GetCursorVisitor, &Result,
|
2010-07-22 20:22:31 +00:00
|
|
|
Decl::MaxPCHLevel, SourceLocation(SLoc));
|
2010-01-22 19:49:59 +00:00
|
|
|
CursorVis.VisitChildren(Parent);
|
2009-09-15 20:25:34 +00:00
|
|
|
}
|
2010-02-17 00:41:32 +00:00
|
|
|
return Result;
|
2009-09-15 20:25:34 +00:00
|
|
|
}
|
|
|
|
|
2009-11-17 19:28:59 +00:00
|
|
|
CXCursor clang_getNullCursor(void) {
|
2010-01-20 23:34:41 +00:00
|
|
|
return MakeCXCursorInvalid(CXCursor_InvalidFile);
|
2009-11-17 19:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_equalCursors(CXCursor X, CXCursor Y) {
|
2010-01-15 21:56:13 +00:00
|
|
|
return X == Y;
|
2009-11-17 19:28:59 +00:00
|
|
|
}
|
2009-11-30 20:42:43 +00:00
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
unsigned clang_isInvalid(enum CXCursorKind K) {
|
2009-09-15 20:25:34 +00:00
|
|
|
return K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid;
|
|
|
|
}
|
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
unsigned clang_isDeclaration(enum CXCursorKind K) {
|
2009-08-31 00:59:03 +00:00
|
|
|
return K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl;
|
|
|
|
}
|
2009-08-31 14:26:51 +00:00
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
unsigned clang_isReference(enum CXCursorKind K) {
|
2009-09-02 18:26:48 +00:00
|
|
|
return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
|
|
|
|
}
|
|
|
|
|
2010-01-19 23:20:36 +00: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;
|
|
|
|
}
|
|
|
|
|
2010-01-20 00:23:15 +00:00
|
|
|
unsigned clang_isTranslationUnit(enum CXCursorKind K) {
|
|
|
|
return K == CXCursor_TranslationUnit;
|
|
|
|
}
|
|
|
|
|
2010-03-18 00:42:48 +00:00
|
|
|
unsigned clang_isPreprocessing(enum CXCursorKind K) {
|
|
|
|
return K >= CXCursor_FirstPreprocessing && K <= CXCursor_LastPreprocessing;
|
|
|
|
}
|
|
|
|
|
2010-03-08 21:17:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-01 03:14:51 +00:00
|
|
|
CXCursorKind clang_getCursorKind(CXCursor C) {
|
2009-09-04 15:44:05 +00:00
|
|
|
return C.kind;
|
|
|
|
}
|
|
|
|
|
2010-01-18 22:46:11 +00:00
|
|
|
CXSourceLocation clang_getCursorLocation(CXCursor C) {
|
|
|
|
if (clang_isReference(C.kind)) {
|
2010-01-18 23:41:10 +00:00
|
|
|
switch (C.kind) {
|
2010-02-17 00:41:40 +00:00
|
|
|
case CXCursor_ObjCSuperClassRef: {
|
2010-01-18 23:41:10 +00:00
|
|
|
std::pair<ObjCInterfaceDecl *, SourceLocation> P
|
|
|
|
= getCursorObjCSuperClassRef(C);
|
2010-01-25 22:34:44 +00:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
2010-01-18 23:41:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-17 00:41:40 +00:00
|
|
|
case CXCursor_ObjCProtocolRef: {
|
2010-01-18 23:41:10 +00:00
|
|
|
std::pair<ObjCProtocolDecl *, SourceLocation> P
|
|
|
|
= getCursorObjCProtocolRef(C);
|
2010-01-25 22:34:44 +00:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
2010-01-18 23:41:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-17 00:41:40 +00:00
|
|
|
case CXCursor_ObjCClassRef: {
|
2010-01-18 23:41:10 +00:00
|
|
|
std::pair<ObjCInterfaceDecl *, SourceLocation> P
|
|
|
|
= getCursorObjCClassRef(C);
|
2010-01-25 22:34:44 +00:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
2010-01-18 23:41:10 +00:00
|
|
|
}
|
2010-01-21 16:28:34 +00:00
|
|
|
|
2010-02-17 00:41:40 +00:00
|
|
|
case CXCursor_TypeRef: {
|
2010-01-21 16:28:34 +00:00
|
|
|
std::pair<TypeDecl *, SourceLocation> P = getCursorTypeRef(C);
|
2010-01-25 22:34:44 +00:00
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
2010-01-21 16:28:34 +00:00
|
|
|
}
|
2010-08-31 20:37:03 +00:00
|
|
|
|
|
|
|
case CXCursor_TemplateRef: {
|
|
|
|
std::pair<TemplateDecl *, SourceLocation> P = getCursorTemplateRef(C);
|
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
2010-08-31 23:48:11 +00:00
|
|
|
case CXCursor_NamespaceRef: {
|
|
|
|
std::pair<NamedDecl *, SourceLocation> P = getCursorNamespaceRef(C);
|
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
2010-09-09 21:42:20 +00:00
|
|
|
case CXCursor_MemberRef: {
|
|
|
|
std::pair<FieldDecl *, SourceLocation> P = getCursorMemberRef(C);
|
|
|
|
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
|
|
|
|
}
|
|
|
|
|
2010-08-27 21:34:58 +00:00
|
|
|
case CXCursor_CXXBaseSpecifier: {
|
2010-10-02 19:51:13 +00:00
|
|
|
CXXBaseSpecifier *BaseSpec = getCursorCXXBaseSpecifier(C);
|
|
|
|
if (!BaseSpec)
|
|
|
|
return clang_getNullLocation();
|
|
|
|
|
|
|
|
if (TypeSourceInfo *TSInfo = BaseSpec->getTypeSourceInfo())
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
|
|
|
TSInfo->getTypeLoc().getBeginLoc());
|
|
|
|
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
|
|
|
BaseSpec->getSourceRange().getBegin());
|
2010-08-27 21:34:58 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
case CXCursor_LabelRef: {
|
|
|
|
std::pair<LabelStmt *, SourceLocation> P = getCursorLabelRef(C);
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), P.second);
|
|
|
|
}
|
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
case CXCursor_OverloadedDeclRef:
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
|
|
|
getCursorOverloadedDeclRef(C).second);
|
|
|
|
|
2010-01-18 23:41:10 +00:00
|
|
|
default:
|
|
|
|
// FIXME: Need a way to enumerate all non-reference cases.
|
|
|
|
llvm_unreachable("Missed a reference kind");
|
|
|
|
}
|
2010-01-18 22:46:11 +00:00
|
|
|
}
|
2010-01-19 23:20:36 +00:00
|
|
|
|
|
|
|
if (clang_isExpression(C.kind))
|
2010-02-17 00:41:40 +00:00
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
2010-01-19 23:20:36 +00:00
|
|
|
getLocationFromExpr(getCursorExpr(C)));
|
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
if (clang_isStatement(C.kind))
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C),
|
|
|
|
getCursorStmt(C)->getLocStart());
|
|
|
|
|
2010-03-18 00:42:48 +00:00
|
|
|
if (C.kind == CXCursor_PreprocessingDirective) {
|
|
|
|
SourceLocation L = cxcursor::getCursorPreprocessingDirective(C).getBegin();
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), L);
|
|
|
|
}
|
2010-03-18 15:23:44 +00:00
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroInstantiation) {
|
Introduce the notion of a "preprocessing record", which keeps track of
the macro definitions and macro instantiations that are found
during preprocessing. Preprocessing records are *not* generated by
default; rather, we provide a PPCallbacks subclass that hooks into the
existing callback mechanism to record this activity.
The only client of preprocessing records is CIndex, which keeps track
of macro definitions and instantations so that they can be exposed via
cursors. At present, only token annotation uses these facilities, and
only for macro instantiations; both will change in the near
future. However, with this change, token annotation properly annotates
macro instantiations that do not produce any tokens and instantiations
of macros that are later undef'd, improving our consistency.
Preprocessing directives that are not macro definitions are still
handled by clang_annotateTokens() via re-lexing, so that we don't have
to track every preprocessing directive in the preprocessing record.
Performance impact of preprocessing records is still TBD, although it
is limited to CIndex and therefore out of the path of the main compiler.
llvm-svn: 98836
2010-03-18 17:52:52 +00:00
|
|
|
SourceLocation L
|
|
|
|
= cxcursor::getCursorMacroInstantiation(C)->getSourceRange().getBegin();
|
2010-03-18 15:23:44 +00:00
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), L);
|
|
|
|
}
|
2010-03-18 18:04:21 +00:00
|
|
|
|
|
|
|
if (C.kind == CXCursor_MacroDefinition) {
|
|
|
|
SourceLocation L = cxcursor::getCursorMacroDefinition(C)->getLocation();
|
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), L);
|
|
|
|
}
|
2010-03-18 00:42:48 +00:00
|
|
|
|
2010-05-12 06:16:13 +00:00
|
|
|
if (C.kind < CXCursor_FirstDecl || C.kind > CXCursor_LastDecl)
|
2010-01-28 00:27:43 +00:00
|
|
|
return clang_getNullLocation();
|
2010-01-18 22:46:11 +00:00
|
|
|
|
2010-01-18 23:41:10 +00:00
|
|
|
Decl *D = getCursorDecl(C);
|
|
|
|
SourceLocation Loc = D->getLocation();
|
|
|
|
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D))
|
|
|
|
Loc = Class->getClassLoc();
|
2010-03-22 15:53:50 +00:00
|
|
|
return cxloc::translateSourceLocation(getCursorContext(C), Loc);
|
2009-10-27 14:35:18 +00:00
|
|
|
}
|
2010-01-19 00:34:46 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
} // end extern "C"
|
|
|
|
|
|
|
|
static SourceRange getRawCursorExtent(CXCursor C) {
|
2010-01-19 00:34:46 +00:00
|
|
|
if (clang_isReference(C.kind)) {
|
|
|
|
switch (C.kind) {
|
2010-07-22 20:22:31 +00:00
|
|
|
case CXCursor_ObjCSuperClassRef:
|
|
|
|
return getCursorObjCSuperClassRef(C).second;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
case CXCursor_ObjCProtocolRef:
|
|
|
|
return getCursorObjCProtocolRef(C).second;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
case CXCursor_ObjCClassRef:
|
|
|
|
return getCursorObjCClassRef(C).second;
|
2010-01-21 16:28:34 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
case CXCursor_TypeRef:
|
|
|
|
return getCursorTypeRef(C).second;
|
2010-08-31 20:37:03 +00:00
|
|
|
|
|
|
|
case CXCursor_TemplateRef:
|
|
|
|
return getCursorTemplateRef(C).second;
|
|
|
|
|
2010-08-31 23:48:11 +00:00
|
|
|
case CXCursor_NamespaceRef:
|
|
|
|
return getCursorNamespaceRef(C).second;
|
2010-09-09 21:42:20 +00:00
|
|
|
|
|
|
|
case CXCursor_MemberRef:
|
|
|
|
return getCursorMemberRef(C).second;
|
|
|
|
|
2010-08-27 21:34:58 +00:00
|
|
|
case CXCursor_CXXBaseSpecifier:
|
2010-10-02 19:51:13 +00:00
|
|
|
return getCursorCXXBaseSpecifier(C)->getSourceRange();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
case CXCursor_LabelRef:
|
|
|
|
return getCursorLabelRef(C).second;
|
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
case CXCursor_OverloadedDeclRef:
|
|
|
|
return getCursorOverloadedDeclRef(C).second;
|
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
default:
|
|
|
|
// FIXME: Need a way to enumerate all non-reference cases.
|
|
|
|
llvm_unreachable("Missed a reference kind");
|
2010-01-19 00:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-19 23:20:36 +00:00
|
|
|
|
|
|
|
if (clang_isExpression(C.kind))
|
2010-07-22 20:22:31 +00:00
|
|
|
return getCursorExpr(C)->getSourceRange();
|
2010-01-22 19:49:59 +00:00
|
|
|
|
|
|
|
if (clang_isStatement(C.kind))
|
2010-07-22 20:22:31 +00:00
|
|
|
return getCursorStmt(C)->getSourceRange();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
if (C.kind == CXCursor_PreprocessingDirective)
|
|
|
|
return cxcursor::getCursorPreprocessingDirective(C);
|
2010-03-18 15:23:44 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
if (C.kind == CXCursor_MacroInstantiation)
|
|
|
|
return cxcursor::getCursorMacroInstantiation(C)->getSourceRange();
|
2010-03-18 18:04:21 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
if (C.kind == CXCursor_MacroDefinition)
|
|
|
|
return cxcursor::getCursorMacroDefinition(C)->getSourceRange();
|
2010-03-18 00:42:48 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl)
|
|
|
|
return getCursorDecl(C)->getSourceRange();
|
|
|
|
|
|
|
|
return SourceRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
CXSourceRange clang_getCursorExtent(CXCursor C) {
|
|
|
|
SourceRange R = getRawCursorExtent(C);
|
|
|
|
if (R.isInvalid())
|
2010-01-28 00:27:43 +00:00
|
|
|
return clang_getNullRange();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
return cxloc::translateSourceRange(getCursorContext(C), R);
|
2010-01-19 00:34:46 +00:00
|
|
|
}
|
2010-01-19 01:20:04 +00:00
|
|
|
|
|
|
|
CXCursor clang_getCursorReferenced(CXCursor C) {
|
2010-01-20 23:57:43 +00:00
|
|
|
if (clang_isInvalid(C.kind))
|
|
|
|
return clang_getNullCursor();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 23:57:43 +00:00
|
|
|
ASTUnit *CXXUnit = getCursorASTUnit(C);
|
2010-09-13 22:52:57 +00:00
|
|
|
if (clang_isDeclaration(C.kind)) {
|
|
|
|
Decl *D = getCursorDecl(C);
|
|
|
|
if (UsingDecl *Using = dyn_cast<UsingDecl>(D))
|
|
|
|
return MakeCursorOverloadedDeclRef(Using, D->getLocation(), CXXUnit);
|
|
|
|
if (ObjCClassDecl *Classes = dyn_cast<ObjCClassDecl>(D))
|
|
|
|
return MakeCursorOverloadedDeclRef(Classes, D->getLocation(), CXXUnit);
|
|
|
|
if (ObjCForwardProtocolDecl *Protocols
|
|
|
|
= dyn_cast<ObjCForwardProtocolDecl>(D))
|
|
|
|
return MakeCursorOverloadedDeclRef(Protocols, D->getLocation(), CXXUnit);
|
|
|
|
|
2010-01-19 01:20:04 +00:00
|
|
|
return C;
|
2010-09-13 22:52:57 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 23:20:36 +00:00
|
|
|
if (clang_isExpression(C.kind)) {
|
2010-09-13 22:52:57 +00:00
|
|
|
Expr *E = getCursorExpr(C);
|
|
|
|
Decl *D = getDeclFromExpr(E);
|
2010-01-19 23:20:36 +00:00
|
|
|
if (D)
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(D, CXXUnit);
|
2010-09-13 22:52:57 +00:00
|
|
|
|
|
|
|
if (OverloadExpr *Ovl = dyn_cast_or_null<OverloadExpr>(E))
|
|
|
|
return MakeCursorOverloadedDeclRef(Ovl, CXXUnit);
|
|
|
|
|
2010-01-19 23:20:36 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
if (clang_isStatement(C.kind)) {
|
|
|
|
Stmt *S = getCursorStmt(C);
|
|
|
|
if (GotoStmt *Goto = dyn_cast_or_null<GotoStmt>(S))
|
|
|
|
return MakeCXCursor(Goto->getLabel(), getCursorDecl(C),
|
|
|
|
getCursorASTUnit(C));
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2010-03-18 18:23:03 +00:00
|
|
|
if (C.kind == CXCursor_MacroInstantiation) {
|
|
|
|
if (MacroDefinition *Def = getCursorMacroInstantiation(C)->getDefinition())
|
|
|
|
return MakeMacroDefinitionCursor(Def, CXXUnit);
|
|
|
|
}
|
|
|
|
|
2010-01-19 01:20:04 +00:00
|
|
|
if (!clang_isReference(C.kind))
|
|
|
|
return clang_getNullCursor();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-19 01:20:04 +00:00
|
|
|
switch (C.kind) {
|
|
|
|
case CXCursor_ObjCSuperClassRef:
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(getCursorObjCSuperClassRef(C).first, CXXUnit);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
case CXCursor_ObjCProtocolRef: {
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(getCursorObjCProtocolRef(C).first, CXXUnit);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
case CXCursor_ObjCClassRef:
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(getCursorObjCClassRef(C).first, CXXUnit);
|
2010-01-21 16:28:34 +00:00
|
|
|
|
2010-02-17 00:41:40 +00:00
|
|
|
case CXCursor_TypeRef:
|
2010-01-21 16:28:34 +00:00
|
|
|
return MakeCXCursor(getCursorTypeRef(C).first, CXXUnit);
|
2010-08-31 20:37:03 +00:00
|
|
|
|
|
|
|
case CXCursor_TemplateRef:
|
|
|
|
return MakeCXCursor(getCursorTemplateRef(C).first, CXXUnit);
|
|
|
|
|
2010-08-31 23:48:11 +00:00
|
|
|
case CXCursor_NamespaceRef:
|
|
|
|
return MakeCXCursor(getCursorNamespaceRef(C).first, CXXUnit);
|
|
|
|
|
2010-09-09 21:42:20 +00:00
|
|
|
case CXCursor_MemberRef:
|
|
|
|
return MakeCXCursor(getCursorMemberRef(C).first, CXXUnit);
|
|
|
|
|
2010-08-27 21:34:58 +00:00
|
|
|
case CXCursor_CXXBaseSpecifier: {
|
|
|
|
CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C);
|
|
|
|
return clang_getTypeDeclaration(cxtype::MakeCXType(B->getType(),
|
|
|
|
CXXUnit));
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-09-10 00:22:18 +00:00
|
|
|
case CXCursor_LabelRef:
|
|
|
|
// FIXME: We end up faking the "parent" declaration here because we
|
|
|
|
// don't want to make CXCursor larger.
|
|
|
|
return MakeCXCursor(getCursorLabelRef(C).first,
|
|
|
|
CXXUnit->getASTContext().getTranslationUnitDecl(),
|
|
|
|
CXXUnit);
|
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
case CXCursor_OverloadedDeclRef:
|
|
|
|
return C;
|
|
|
|
|
2010-01-19 01:20:04 +00:00
|
|
|
default:
|
|
|
|
// We would prefer to enumerate all non-reference cursor kinds here.
|
|
|
|
llvm_unreachable("Unhandled reference cursor kind");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-19 01:20:04 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2010-01-19 19:34:47 +00:00
|
|
|
CXCursor clang_getCursorDefinition(CXCursor C) {
|
2010-01-20 23:57:43 +00:00
|
|
|
if (clang_isInvalid(C.kind))
|
|
|
|
return clang_getNullCursor();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-20 23:57:43 +00:00
|
|
|
ASTUnit *CXXUnit = getCursorASTUnit(C);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-19 19:34:47 +00:00
|
|
|
bool WasReference = false;
|
2010-01-19 23:20:36 +00:00
|
|
|
if (clang_isReference(C.kind) || clang_isExpression(C.kind)) {
|
2010-01-19 19:34:47 +00:00
|
|
|
C = clang_getCursorReferenced(C);
|
|
|
|
WasReference = true;
|
|
|
|
}
|
|
|
|
|
2010-03-18 18:23:03 +00:00
|
|
|
if (C.kind == CXCursor_MacroInstantiation)
|
|
|
|
return clang_getCursorReferenced(C);
|
|
|
|
|
2010-01-19 19:34:47 +00:00
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
Decl *D = getCursorDecl(C);
|
|
|
|
if (!D)
|
|
|
|
return clang_getNullCursor();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-19 19:34:47 +00:00
|
|
|
switch (D->getKind()) {
|
|
|
|
// Declaration kinds that don't really separate the notions of
|
|
|
|
// declaration and definition.
|
|
|
|
case Decl::Namespace:
|
|
|
|
case Decl::Typedef:
|
|
|
|
case Decl::TemplateTypeParm:
|
|
|
|
case Decl::EnumConstant:
|
|
|
|
case Decl::Field:
|
|
|
|
case Decl::ObjCIvar:
|
|
|
|
case Decl::ObjCAtDefsField:
|
|
|
|
case Decl::ImplicitParam:
|
|
|
|
case Decl::ParmVar:
|
|
|
|
case Decl::NonTypeTemplateParm:
|
|
|
|
case Decl::TemplateTemplateParm:
|
|
|
|
case Decl::ObjCCategoryImpl:
|
|
|
|
case Decl::ObjCImplementation:
|
2010-06-05 05:09:32 +00:00
|
|
|
case Decl::AccessSpec:
|
2010-01-19 19:34:47 +00:00
|
|
|
case Decl::LinkageSpec:
|
|
|
|
case Decl::ObjCPropertyImpl:
|
|
|
|
case Decl::FileScopeAsm:
|
|
|
|
case Decl::StaticAssert:
|
|
|
|
case Decl::Block:
|
|
|
|
return C;
|
|
|
|
|
|
|
|
// Declaration kinds that don't make any sense here, but are
|
|
|
|
// nonetheless harmless.
|
|
|
|
case Decl::TranslationUnit:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Declaration kinds for which the definition is not resolvable.
|
|
|
|
case Decl::UnresolvedUsingTypename:
|
|
|
|
case Decl::UnresolvedUsingValue:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Decl::UsingDirective:
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(cast<UsingDirectiveDecl>(D)->getNominatedNamespace(),
|
|
|
|
CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
|
|
|
|
case Decl::NamespaceAlias:
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(cast<NamespaceAliasDecl>(D)->getNamespace(), CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
|
|
|
|
case Decl::Enum:
|
|
|
|
case Decl::Record:
|
|
|
|
case Decl::CXXRecord:
|
|
|
|
case Decl::ClassTemplateSpecialization:
|
|
|
|
case Decl::ClassTemplatePartialSpecialization:
|
2010-02-11 01:04:33 +00:00
|
|
|
if (TagDecl *Def = cast<TagDecl>(D)->getDefinition())
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(Def, CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::Function:
|
|
|
|
case Decl::CXXMethod:
|
|
|
|
case Decl::CXXConstructor:
|
|
|
|
case Decl::CXXDestructor:
|
|
|
|
case Decl::CXXConversion: {
|
|
|
|
const FunctionDecl *Def = 0;
|
|
|
|
if (cast<FunctionDecl>(D)->getBody(Def))
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(const_cast<FunctionDecl *>(Def), CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
case Decl::Var: {
|
2010-02-01 20:16:42 +00:00
|
|
|
// Ask the variable if it has a definition.
|
|
|
|
if (VarDecl *Def = cast<VarDecl>(D)->getDefinition())
|
|
|
|
return MakeCXCursor(Def, CXXUnit);
|
|
|
|
return clang_getNullCursor();
|
2010-01-19 19:34:47 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-19 19:34:47 +00:00
|
|
|
case Decl::FunctionTemplate: {
|
|
|
|
const FunctionDecl *Def = 0;
|
|
|
|
if (cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->getBody(Def))
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(Def->getDescribedFunctionTemplate(), CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-19 19:34:47 +00:00
|
|
|
case Decl::ClassTemplate: {
|
|
|
|
if (RecordDecl *Def = cast<ClassTemplateDecl>(D)->getTemplatedDecl()
|
2010-02-11 01:04:33 +00:00
|
|
|
->getDefinition())
|
2010-08-31 20:37:03 +00:00
|
|
|
return MakeCXCursor(cast<CXXRecordDecl>(Def)->getDescribedClassTemplate(),
|
2010-01-20 23:57:43 +00:00
|
|
|
CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
case Decl::Using:
|
|
|
|
return MakeCursorOverloadedDeclRef(cast<UsingDecl>(D),
|
|
|
|
D->getLocation(), CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
|
|
|
|
case Decl::UsingShadow:
|
|
|
|
return clang_getCursorDefinition(
|
2010-02-17 00:41:40 +00:00
|
|
|
MakeCXCursor(cast<UsingShadowDecl>(D)->getTargetDecl(),
|
2010-01-20 23:57:43 +00:00
|
|
|
CXXUnit));
|
2010-01-19 19:34:47 +00:00
|
|
|
|
|
|
|
case Decl::ObjCMethod: {
|
|
|
|
ObjCMethodDecl *Method = cast<ObjCMethodDecl>(D);
|
|
|
|
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.
|
|
|
|
if (ObjCInterfaceDecl *Class
|
|
|
|
= dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext()))
|
|
|
|
if (ObjCImplementationDecl *ClassImpl = Class->getImplementation())
|
|
|
|
if (ObjCMethodDecl *Def = ClassImpl->getMethod(Method->getSelector(),
|
|
|
|
Method->isInstanceMethod()))
|
|
|
|
if (Def->isThisDeclarationADefinition())
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(Def, CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
case Decl::ObjCCategory:
|
|
|
|
if (ObjCCategoryImplDecl *Impl
|
|
|
|
= cast<ObjCCategoryDecl>(D)->getImplementation())
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(Impl, CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::ObjCProtocol:
|
|
|
|
if (!cast<ObjCProtocolDecl>(D)->isForwardDecl())
|
|
|
|
return C;
|
|
|
|
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.
|
|
|
|
if (WasReference) {
|
|
|
|
if (!cast<ObjCInterfaceDecl>(D)->isForwardDecl())
|
|
|
|
return C;
|
|
|
|
} else if (ObjCImplementationDecl *Impl
|
|
|
|
= cast<ObjCInterfaceDecl>(D)->getImplementation())
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(Impl, CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-19 19:34:47 +00:00
|
|
|
case Decl::ObjCProperty:
|
|
|
|
// FIXME: We don't really know where to find the
|
|
|
|
// ObjCPropertyImplDecls that implement this property.
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::ObjCCompatibleAlias:
|
|
|
|
if (ObjCInterfaceDecl *Class
|
|
|
|
= cast<ObjCCompatibleAliasDecl>(D)->getClassInterface())
|
|
|
|
if (!Class->isForwardDecl())
|
2010-01-20 23:57:43 +00:00
|
|
|
return MakeCXCursor(Class, CXXUnit);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
case Decl::ObjCForwardProtocol:
|
|
|
|
return MakeCursorOverloadedDeclRef(cast<ObjCForwardProtocolDecl>(D),
|
|
|
|
D->getLocation(), CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
case Decl::ObjCClass:
|
|
|
|
return MakeCursorOverloadedDeclRef(cast<ObjCClassDecl>(D), D->getLocation(),
|
|
|
|
CXXUnit);
|
2010-01-19 19:34:47 +00:00
|
|
|
|
|
|
|
case Decl::Friend:
|
|
|
|
if (NamedDecl *Friend = cast<FriendDecl>(D)->getFriendDecl())
|
2010-01-20 23:57:43 +00:00
|
|
|
return clang_getCursorDefinition(MakeCXCursor(Friend, CXXUnit));
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
case Decl::FriendTemplate:
|
|
|
|
if (NamedDecl *Friend = cast<FriendTemplateDecl>(D)->getFriendDecl())
|
2010-01-20 23:57:43 +00:00
|
|
|
return clang_getCursorDefinition(MakeCXCursor(Friend, CXXUnit));
|
2010-01-19 19:34:47 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned clang_isCursorDefinition(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return clang_getCursorDefinition(C) == C;
|
|
|
|
}
|
|
|
|
|
2010-09-13 22:52:57 +00:00
|
|
|
unsigned clang_getNumOverloadedDecls(CXCursor C) {
|
2010-09-16 13:54:00 +00:00
|
|
|
if (C.kind != CXCursor_OverloadedDeclRef)
|
2010-09-13 22:52:57 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first;
|
|
|
|
if (OverloadExpr *E = Storage.dyn_cast<OverloadExpr *>())
|
|
|
|
return E->getNumDecls();
|
|
|
|
|
|
|
|
if (OverloadedTemplateStorage *S
|
|
|
|
= Storage.dyn_cast<OverloadedTemplateStorage*>())
|
|
|
|
return S->size();
|
|
|
|
|
|
|
|
Decl *D = Storage.get<Decl*>();
|
|
|
|
if (UsingDecl *Using = dyn_cast<UsingDecl>(D))
|
|
|
|
return Using->getNumShadowDecls();
|
|
|
|
if (ObjCClassDecl *Classes = dyn_cast<ObjCClassDecl>(D))
|
|
|
|
return Classes->size();
|
|
|
|
if (ObjCForwardProtocolDecl *Protocols =dyn_cast<ObjCForwardProtocolDecl>(D))
|
|
|
|
return Protocols->protocol_size();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) {
|
2010-09-16 13:54:00 +00:00
|
|
|
if (cursor.kind != CXCursor_OverloadedDeclRef)
|
2010-09-13 22:52:57 +00:00
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
if (index >= clang_getNumOverloadedDecls(cursor))
|
|
|
|
return clang_getNullCursor();
|
|
|
|
|
|
|
|
ASTUnit *Unit = getCursorASTUnit(cursor);
|
|
|
|
OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(cursor).first;
|
|
|
|
if (OverloadExpr *E = Storage.dyn_cast<OverloadExpr *>())
|
|
|
|
return MakeCXCursor(E->decls_begin()[index], Unit);
|
|
|
|
|
|
|
|
if (OverloadedTemplateStorage *S
|
|
|
|
= Storage.dyn_cast<OverloadedTemplateStorage*>())
|
|
|
|
return MakeCXCursor(S->begin()[index], Unit);
|
|
|
|
|
|
|
|
Decl *D = Storage.get<Decl*>();
|
|
|
|
if (UsingDecl *Using = dyn_cast<UsingDecl>(D)) {
|
|
|
|
// FIXME: This is, unfortunately, linear time.
|
|
|
|
UsingDecl::shadow_iterator Pos = Using->shadow_begin();
|
|
|
|
std::advance(Pos, index);
|
|
|
|
return MakeCXCursor(cast<UsingShadowDecl>(*Pos)->getTargetDecl(), Unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCClassDecl *Classes = dyn_cast<ObjCClassDecl>(D))
|
|
|
|
return MakeCXCursor(Classes->begin()[index].getInterface(), Unit);
|
|
|
|
|
|
|
|
if (ObjCForwardProtocolDecl *Protocols = dyn_cast<ObjCForwardProtocolDecl>(D))
|
|
|
|
return MakeCXCursor(Protocols->protocol_begin()[index], Unit);
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2009-11-30 20:42:43 +00:00
|
|
|
void clang_getDefinitionSpellingAndExtent(CXCursor C,
|
2009-09-23 17:52:52 +00:00
|
|
|
const char **startBuf,
|
|
|
|
const char **endBuf,
|
|
|
|
unsigned *startLine,
|
|
|
|
unsigned *startColumn,
|
|
|
|
unsigned *endLine,
|
2009-12-01 03:14:51 +00:00
|
|
|
unsigned *endColumn) {
|
2010-01-15 21:56:13 +00:00
|
|
|
assert(getCursorDecl(C) && "CXCursor has null decl");
|
|
|
|
NamedDecl *ND = static_cast<NamedDecl *>(getCursorDecl(C));
|
2009-09-23 17:52:52 +00:00
|
|
|
FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
|
|
|
|
CompoundStmt *Body = dyn_cast<CompoundStmt>(FD->getBody());
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2009-09-23 17:52:52 +00:00
|
|
|
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());
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-02-18 23:07:20 +00:00
|
|
|
void clang_enableStackTraces(void) {
|
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
|
|
|
}
|
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
} // end: extern "C"
|
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// 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
|
2010-02-17 00:41:40 +00:00
|
|
|
* ptr_data: for identifiers and keywords, an IdentifierInfo*.
|
2010-01-26 17:06:03 +00:00
|
|
|
* otherwise unused.
|
|
|
|
*/
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
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.
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(static_cast<IdentifierInfo *>(CXTok.ptr_data)
|
|
|
|
->getNameStart());
|
2010-01-26 17:06:03 +00:00
|
|
|
|
|
|
|
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);
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(llvm::StringRef(Text, CXTok.int_data[2]));
|
2010-01-26 17:06:03 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
case CXToken_Punctuation:
|
|
|
|
case CXToken_Comment:
|
|
|
|
break;
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
// We have to find the starting buffer pointer the hard way, by
|
2010-01-26 17:06:03 +00:00
|
|
|
// deconstructing the source location.
|
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
|
|
|
|
if (!CXXUnit)
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString("");
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]);
|
|
|
|
std::pair<FileID, unsigned> LocInfo
|
|
|
|
= CXXUnit->getSourceManager().getDecomposedLoc(Loc);
|
2010-03-16 00:06:06 +00:00
|
|
|
bool Invalid = false;
|
2010-03-16 14:14:31 +00:00
|
|
|
llvm::StringRef Buffer
|
2010-03-16 00:06:06 +00:00
|
|
|
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
|
|
|
|
if (Invalid)
|
2010-03-15 22:54:52 +00:00
|
|
|
return createCXString("");
|
2010-01-26 17:06:03 +00:00
|
|
|
|
2010-03-16 14:14:31 +00:00
|
|
|
return createCXString(Buffer.substr(LocInfo.second, CXTok.int_data[2]));
|
2010-01-26 17:06:03 +00:00
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
|
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
|
|
|
|
if (!CXXUnit)
|
|
|
|
return clang_getNullLocation();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
return cxloc::translateSourceLocation(CXXUnit->getASTContext(),
|
|
|
|
SourceLocation::getFromRawEncoding(CXTok.int_data[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) {
|
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
|
2010-01-28 00:27:43 +00:00
|
|
|
if (!CXXUnit)
|
|
|
|
return clang_getNullRange();
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
return cxloc::translateSourceRange(CXXUnit->getASTContext(),
|
2010-01-26 17:06:03 +00:00
|
|
|
SourceLocation::getFromRawEncoding(CXTok.int_data[1]));
|
|
|
|
}
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
|
|
|
|
CXToken **Tokens, unsigned *NumTokens) {
|
|
|
|
if (Tokens)
|
|
|
|
*Tokens = 0;
|
|
|
|
if (NumTokens)
|
|
|
|
*NumTokens = 0;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
|
|
|
|
if (!CXXUnit || !Tokens || !NumTokens)
|
|
|
|
return;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-03-05 21:16:25 +00:00
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
|
|
|
|
2010-02-14 08:31:57 +00:00
|
|
|
SourceRange R = cxloc::translateCXSourceRange(Range);
|
2010-01-26 17:06:03 +00:00
|
|
|
if (R.isInvalid())
|
|
|
|
return;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
SourceManager &SourceMgr = CXXUnit->getSourceManager();
|
|
|
|
std::pair<FileID, unsigned> BeginLocInfo
|
|
|
|
= SourceMgr.getDecomposedLoc(R.getBegin());
|
|
|
|
std::pair<FileID, unsigned> EndLocInfo
|
|
|
|
= SourceMgr.getDecomposedLoc(R.getEnd());
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
// Cannot tokenize across files.
|
|
|
|
if (BeginLocInfo.first != EndLocInfo.first)
|
|
|
|
return;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
|
|
|
// Create a lexer
|
2010-03-16 00:06:06 +00:00
|
|
|
bool Invalid = false;
|
2010-03-16 14:14:31 +00:00
|
|
|
llvm::StringRef Buffer
|
2010-03-16 00:06:06 +00:00
|
|
|
= SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
|
2010-03-16 20:26:15 +00:00
|
|
|
if (Invalid)
|
|
|
|
return;
|
2010-03-15 22:54:52 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
|
|
|
|
CXXUnit->getASTContext().getLangOptions(),
|
2010-03-16 14:14:31 +00:00
|
|
|
Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end());
|
2010-01-26 17:06:03 +00:00
|
|
|
Lex.SetCommentRetentionState(true);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
// Lex tokens until we hit the end of the range.
|
2010-03-16 14:14:31 +00:00
|
|
|
const char *EffectiveBufferEnd = Buffer.data() + EndLocInfo.second;
|
2010-01-26 17:06:03 +00:00
|
|
|
llvm::SmallVector<CXToken, 32> CXTokens;
|
|
|
|
Token Tok;
|
|
|
|
do {
|
|
|
|
// Lex the next token
|
|
|
|
Lex.LexFromRawLexer(Tok);
|
|
|
|
if (Tok.is(tok::eof))
|
|
|
|
break;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
// Initialize the CXToken.
|
|
|
|
CXToken CXTok;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
// - Common fields
|
|
|
|
CXTok.int_data[1] = Tok.getLocation().getRawEncoding();
|
|
|
|
CXTok.int_data[2] = Tok.getLength();
|
|
|
|
CXTok.int_data[3] = 0;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
// - Kind-specific fields
|
|
|
|
if (Tok.isLiteral()) {
|
|
|
|
CXTok.int_data[0] = CXToken_Literal;
|
|
|
|
CXTok.ptr_data = (void *)Tok.getLiteralData();
|
|
|
|
} else if (Tok.is(tok::identifier)) {
|
2010-03-15 22:54:52 +00:00
|
|
|
// Lookup the identifier to determine whether we have a keyword.
|
2010-01-26 17:06:03 +00:00
|
|
|
std::pair<FileID, unsigned> LocInfo
|
|
|
|
= SourceMgr.getDecomposedLoc(Tok.getLocation());
|
2010-03-16 00:06:06 +00:00
|
|
|
bool Invalid = false;
|
2010-03-16 14:14:31 +00:00
|
|
|
llvm::StringRef Buf
|
2010-03-16 00:06:06 +00:00
|
|
|
= CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
|
|
|
|
if (Invalid)
|
2010-03-15 22:54:52 +00:00
|
|
|
return;
|
|
|
|
|
2010-03-16 14:14:31 +00:00
|
|
|
const char *StartPos = Buf.data() + LocInfo.second;
|
2010-01-26 17:06:03 +00:00
|
|
|
IdentifierInfo *II
|
|
|
|
= CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok, StartPos);
|
2010-05-05 00:55:20 +00:00
|
|
|
|
|
|
|
if (II->getObjCKeywordID() != tok::objc_not_keyword) {
|
|
|
|
CXTok.int_data[0] = CXToken_Keyword;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CXTok.int_data[0] = II->getTokenID() == tok::identifier?
|
|
|
|
CXToken_Identifier
|
|
|
|
: CXToken_Keyword;
|
|
|
|
}
|
2010-01-26 17:06:03 +00:00
|
|
|
CXTok.ptr_data = II;
|
|
|
|
} else if (Tok.is(tok::comment)) {
|
|
|
|
CXTok.int_data[0] = CXToken_Comment;
|
|
|
|
CXTok.ptr_data = 0;
|
|
|
|
} else {
|
|
|
|
CXTok.int_data[0] = CXToken_Punctuation;
|
|
|
|
CXTok.ptr_data = 0;
|
|
|
|
}
|
|
|
|
CXTokens.push_back(CXTok);
|
|
|
|
} while (Lex.getBufferLocation() <= EffectiveBufferEnd);
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
if (CXTokens.empty())
|
|
|
|
return;
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
*Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size());
|
|
|
|
memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());
|
|
|
|
*NumTokens = CXTokens.size();
|
|
|
|
}
|
2010-01-26 18:31:56 +00:00
|
|
|
|
2010-05-05 00:55:15 +00:00
|
|
|
void clang_disposeTokens(CXTranslationUnit TU,
|
|
|
|
CXToken *Tokens, unsigned NumTokens) {
|
|
|
|
free(Tokens);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end: extern "C"
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Token annotation APIs.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-26 18:31:56 +00:00
|
|
|
typedef llvm::DenseMap<unsigned, CXCursor> AnnotateTokensData;
|
2010-05-05 00:55:23 +00:00
|
|
|
static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor,
|
|
|
|
CXCursor parent,
|
|
|
|
CXClientData client_data);
|
2010-05-05 00:55:15 +00:00
|
|
|
namespace {
|
|
|
|
class AnnotateTokensWorker {
|
|
|
|
AnnotateTokensData &Annotated;
|
2010-05-05 00:55:17 +00:00
|
|
|
CXToken *Tokens;
|
|
|
|
CXCursor *Cursors;
|
|
|
|
unsigned NumTokens;
|
2010-05-05 00:55:23 +00:00
|
|
|
unsigned TokIdx;
|
|
|
|
CursorVisitor AnnotateVis;
|
|
|
|
SourceManager &SrcMgr;
|
|
|
|
|
|
|
|
bool MoreTokens() const { return TokIdx < NumTokens; }
|
|
|
|
unsigned NextToken() const { return TokIdx; }
|
|
|
|
void AdvanceToken() { ++TokIdx; }
|
|
|
|
SourceLocation GetTokenLoc(unsigned tokI) {
|
|
|
|
return SourceLocation::getFromRawEncoding(Tokens[tokI].int_data[1]);
|
|
|
|
}
|
|
|
|
|
2010-05-05 00:55:15 +00:00
|
|
|
public:
|
2010-05-05 00:55:17 +00:00
|
|
|
AnnotateTokensWorker(AnnotateTokensData &annotated,
|
2010-05-05 00:55:23 +00:00
|
|
|
CXToken *tokens, CXCursor *cursors, unsigned numTokens,
|
|
|
|
ASTUnit *CXXUnit, SourceRange RegionOfInterest)
|
2010-05-05 00:55:17 +00:00
|
|
|
: Annotated(annotated), Tokens(tokens), Cursors(cursors),
|
2010-05-05 00:55:23 +00:00
|
|
|
NumTokens(numTokens), TokIdx(0),
|
|
|
|
AnnotateVis(CXXUnit, AnnotateTokensVisitor, this,
|
|
|
|
Decl::MaxPCHLevel, RegionOfInterest),
|
|
|
|
SrcMgr(CXXUnit->getSourceManager()) {}
|
2010-05-05 00:55:17 +00:00
|
|
|
|
2010-05-05 00:55:23 +00:00
|
|
|
void VisitChildren(CXCursor C) { AnnotateVis.VisitChildren(C); }
|
2010-05-05 00:55:15 +00:00
|
|
|
enum CXChildVisitResult Visit(CXCursor cursor, CXCursor parent);
|
2010-05-05 00:55:23 +00:00
|
|
|
void AnnotateTokens(CXCursor parent);
|
2010-05-05 00:55:15 +00:00
|
|
|
};
|
|
|
|
}
|
2010-01-26 18:31:56 +00:00
|
|
|
|
2010-05-05 00:55:23 +00:00
|
|
|
void AnnotateTokensWorker::AnnotateTokens(CXCursor parent) {
|
|
|
|
// Walk the AST within the region of interest, annotating tokens
|
|
|
|
// along the way.
|
|
|
|
VisitChildren(parent);
|
|
|
|
|
|
|
|
for (unsigned I = 0 ; I < TokIdx ; ++I) {
|
2010-05-05 00:55:17 +00:00
|
|
|
AnnotateTokensData::iterator Pos = Annotated.find(Tokens[I].int_data[1]);
|
2010-05-05 00:55:23 +00:00
|
|
|
if (Pos != Annotated.end())
|
|
|
|
Cursors[I] = Pos->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finish up annotating any tokens left.
|
|
|
|
if (!MoreTokens())
|
|
|
|
return;
|
2010-05-05 00:55:17 +00:00
|
|
|
|
2010-05-05 00:55:23 +00:00
|
|
|
const CXCursor &C = clang_getNullCursor();
|
|
|
|
for (unsigned I = TokIdx ; I < NumTokens ; ++I) {
|
|
|
|
AnnotateTokensData::iterator Pos = Annotated.find(Tokens[I].int_data[1]);
|
|
|
|
Cursors[I] = (Pos == Annotated.end()) ? C : Pos->second;
|
2010-05-05 00:55:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-05 00:55:15 +00:00
|
|
|
enum CXChildVisitResult
|
|
|
|
AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) {
|
2010-05-05 00:55:23 +00:00
|
|
|
CXSourceLocation Loc = clang_getCursorLocation(cursor);
|
|
|
|
// We can always annotate a preprocessing directive/macro instantiation.
|
|
|
|
if (clang_isPreprocessing(cursor.kind)) {
|
|
|
|
Annotated[Loc.int_data] = cursor;
|
2010-01-26 18:31:56 +00:00
|
|
|
return CXChildVisit_Recurse;
|
|
|
|
}
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-07-22 20:22:31 +00:00
|
|
|
SourceRange cursorRange = getRawCursorExtent(cursor);
|
2010-05-12 05:29:33 +00:00
|
|
|
|
2010-05-05 00:55:23 +00:00
|
|
|
if (cursorRange.isInvalid())
|
|
|
|
return CXChildVisit_Continue;
|
2010-05-12 05:29:33 +00:00
|
|
|
|
2010-05-05 00:55:23 +00:00
|
|
|
SourceLocation L = SourceLocation::getFromRawEncoding(Loc.int_data);
|
|
|
|
|
2010-05-12 05:29:33 +00:00
|
|
|
// Adjust the annotated range based specific declarations.
|
|
|
|
const enum CXCursorKind cursorK = clang_getCursorKind(cursor);
|
|
|
|
if (cursorK >= CXCursor_FirstDecl && cursorK <= CXCursor_LastDecl) {
|
2010-05-18 21:09:07 +00:00
|
|
|
Decl *D = cxcursor::getCursorDecl(cursor);
|
|
|
|
// Don't visit synthesized ObjC methods, since they have no syntatic
|
|
|
|
// representation in the source.
|
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
|
|
|
|
if (MD->isSynthesized())
|
|
|
|
return CXChildVisit_Continue;
|
|
|
|
}
|
|
|
|
if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
|
2010-05-12 05:29:33 +00:00
|
|
|
if (TypeSourceInfo *TI = DD->getTypeSourceInfo()) {
|
|
|
|
TypeLoc TL = TI->getTypeLoc();
|
2010-05-20 10:00:11 +00:00
|
|
|
SourceLocation TLoc = TL.getSourceRange().getBegin();
|
2010-05-13 15:38:38 +00:00
|
|
|
if (TLoc.isValid() &&
|
|
|
|
SrcMgr.isBeforeInTranslationUnit(TLoc, L))
|
2010-05-12 05:29:33 +00:00
|
|
|
cursorRange.setBegin(TLoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-14 01:14:06 +00:00
|
|
|
// If the location of the cursor occurs within a macro instantiation, record
|
|
|
|
// the spelling location of the cursor in our annotation map. We can then
|
|
|
|
// paper over the token labelings during a post-processing step to try and
|
|
|
|
// get cursor mappings for tokens that are the *arguments* of a macro
|
|
|
|
// instantiation.
|
|
|
|
if (L.isMacroID()) {
|
|
|
|
unsigned rawEncoding = SrcMgr.getSpellingLoc(L).getRawEncoding();
|
|
|
|
// Only invalidate the old annotation if it isn't part of a preprocessing
|
|
|
|
// directive. Here we assume that the default construction of CXCursor
|
|
|
|
// results in CXCursor.kind being an initialized value (i.e., 0). If
|
|
|
|
// this isn't the case, we can fix by doing lookup + insertion.
|
|
|
|
|
|
|
|
CXCursor &oldC = Annotated[rawEncoding];
|
|
|
|
if (!clang_isPreprocessing(oldC.kind))
|
|
|
|
oldC = cursor;
|
|
|
|
}
|
|
|
|
|
2010-05-05 00:55:23 +00:00
|
|
|
const enum CXCursorKind K = clang_getCursorKind(parent);
|
|
|
|
const CXCursor updateC =
|
2010-08-25 22:16:02 +00:00
|
|
|
(clang_isInvalid(K) || K == CXCursor_TranslationUnit)
|
|
|
|
? clang_getNullCursor() : parent;
|
2010-05-05 00:55:23 +00:00
|
|
|
|
|
|
|
while (MoreTokens()) {
|
|
|
|
const unsigned I = NextToken();
|
|
|
|
SourceLocation TokLoc = GetTokenLoc(I);
|
|
|
|
switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) {
|
|
|
|
case RangeBefore:
|
|
|
|
Cursors[I] = updateC;
|
|
|
|
AdvanceToken();
|
|
|
|
continue;
|
|
|
|
case RangeAfter:
|
|
|
|
case RangeOverlap:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Visit children to get their cursor information.
|
|
|
|
const unsigned BeforeChildren = NextToken();
|
|
|
|
VisitChildren(cursor);
|
|
|
|
const unsigned AfterChildren = NextToken();
|
|
|
|
|
|
|
|
// Adjust 'Last' to the last token within the extent of the cursor.
|
|
|
|
while (MoreTokens()) {
|
|
|
|
const unsigned I = NextToken();
|
|
|
|
SourceLocation TokLoc = GetTokenLoc(I);
|
|
|
|
switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) {
|
|
|
|
case RangeBefore:
|
|
|
|
assert(0 && "Infeasible");
|
|
|
|
case RangeAfter:
|
|
|
|
break;
|
|
|
|
case RangeOverlap:
|
|
|
|
Cursors[I] = updateC;
|
|
|
|
AdvanceToken();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const unsigned Last = NextToken();
|
2010-05-05 00:55:15 +00:00
|
|
|
|
2010-05-05 00:55:23 +00:00
|
|
|
// Scan the tokens that are at the beginning of the cursor, but are not
|
|
|
|
// capture by the child cursors.
|
|
|
|
|
|
|
|
// For AST elements within macros, rely on a post-annotate pass to
|
|
|
|
// to correctly annotate the tokens with cursors. Otherwise we can
|
|
|
|
// get confusing results of having tokens that map to cursors that really
|
|
|
|
// are expanded by an instantiation.
|
|
|
|
if (L.isMacroID())
|
|
|
|
cursor = clang_getNullCursor();
|
|
|
|
|
|
|
|
for (unsigned I = BeforeChildren; I != AfterChildren; ++I) {
|
|
|
|
if (!clang_isInvalid(clang_getCursorKind(Cursors[I])))
|
|
|
|
break;
|
|
|
|
Cursors[I] = cursor;
|
|
|
|
}
|
|
|
|
// Scan the tokens that are at the end of the cursor, but are not captured
|
|
|
|
// but the child cursors.
|
|
|
|
for (unsigned I = AfterChildren; I != Last; ++I)
|
|
|
|
Cursors[I] = cursor;
|
|
|
|
|
|
|
|
TokIdx = Last;
|
|
|
|
return CXChildVisit_Continue;
|
2010-01-26 18:31:56 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 00:55:15 +00:00
|
|
|
static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor,
|
|
|
|
CXCursor parent,
|
|
|
|
CXClientData client_data) {
|
|
|
|
return static_cast<AnnotateTokensWorker*>(client_data)->Visit(cursor, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2010-01-26 17:06:03 +00:00
|
|
|
void clang_annotateTokens(CXTranslationUnit TU,
|
|
|
|
CXToken *Tokens, unsigned NumTokens,
|
|
|
|
CXCursor *Cursors) {
|
2010-05-05 00:55:23 +00:00
|
|
|
|
|
|
|
if (NumTokens == 0 || !Tokens || !Cursors)
|
2010-01-26 18:31:56 +00:00
|
|
|
return;
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-01-26 18:31:56 +00:00
|
|
|
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
|
2010-05-05 00:55:23 +00:00
|
|
|
if (!CXXUnit) {
|
|
|
|
// Any token we don't specifically annotate will have a NULL cursor.
|
|
|
|
const CXCursor &C = clang_getNullCursor();
|
|
|
|
for (unsigned I = 0; I != NumTokens; ++I)
|
|
|
|
Cursors[I] = C;
|
2010-01-26 18:31:56 +00:00
|
|
|
return;
|
2010-05-05 00:55:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 21:16:25 +00:00
|
|
|
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-19 05:22:59 +00:00
|
|
|
// Determine the region of interest, which contains all of the tokens.
|
2010-01-26 18:31:56 +00:00
|
|
|
SourceRange RegionOfInterest;
|
2010-05-05 00:55:23 +00:00
|
|
|
RegionOfInterest.setBegin(cxloc::translateSourceLocation(
|
|
|
|
clang_getTokenLocation(TU, Tokens[0])));
|
2010-07-22 20:22:31 +00:00
|
|
|
RegionOfInterest.setEnd(cxloc::translateSourceLocation(
|
|
|
|
clang_getTokenLocation(TU,
|
|
|
|
Tokens[NumTokens - 1])));
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-19 05:22:59 +00:00
|
|
|
// A mapping from the source locations found when re-lexing or traversing the
|
|
|
|
// region of interest to the corresponding cursors.
|
2010-01-26 18:31:56 +00:00
|
|
|
AnnotateTokensData Annotated;
|
2010-05-05 00:55:23 +00:00
|
|
|
|
|
|
|
// Relex the tokens within the source range to look for preprocessing
|
2010-03-19 05:22:59 +00:00
|
|
|
// directives.
|
2010-03-18 00:42:48 +00:00
|
|
|
SourceManager &SourceMgr = CXXUnit->getSourceManager();
|
|
|
|
std::pair<FileID, unsigned> BeginLocInfo
|
|
|
|
= SourceMgr.getDecomposedLoc(RegionOfInterest.getBegin());
|
|
|
|
std::pair<FileID, unsigned> EndLocInfo
|
|
|
|
= SourceMgr.getDecomposedLoc(RegionOfInterest.getEnd());
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-18 00:42:48 +00:00
|
|
|
llvm::StringRef Buffer;
|
2010-03-19 05:22:59 +00:00
|
|
|
bool Invalid = false;
|
|
|
|
if (BeginLocInfo.first == EndLocInfo.first &&
|
|
|
|
((Buffer = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid)),true) &&
|
|
|
|
!Invalid) {
|
2010-03-18 00:42:48 +00:00
|
|
|
Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
|
|
|
|
CXXUnit->getASTContext().getLangOptions(),
|
2010-05-05 00:55:23 +00:00
|
|
|
Buffer.begin(), Buffer.data() + BeginLocInfo.second,
|
Introduce the notion of a "preprocessing record", which keeps track of
the macro definitions and macro instantiations that are found
during preprocessing. Preprocessing records are *not* generated by
default; rather, we provide a PPCallbacks subclass that hooks into the
existing callback mechanism to record this activity.
The only client of preprocessing records is CIndex, which keeps track
of macro definitions and instantations so that they can be exposed via
cursors. At present, only token annotation uses these facilities, and
only for macro instantiations; both will change in the near
future. However, with this change, token annotation properly annotates
macro instantiations that do not produce any tokens and instantiations
of macros that are later undef'd, improving our consistency.
Preprocessing directives that are not macro definitions are still
handled by clang_annotateTokens() via re-lexing, so that we don't have
to track every preprocessing directive in the preprocessing record.
Performance impact of preprocessing records is still TBD, although it
is limited to CIndex and therefore out of the path of the main compiler.
llvm-svn: 98836
2010-03-18 17:52:52 +00:00
|
|
|
Buffer.end());
|
2010-03-18 00:42:48 +00:00
|
|
|
Lex.SetCommentRetentionState(true);
|
2010-05-05 00:55:23 +00:00
|
|
|
|
|
|
|
// Lex tokens in raw mode until we hit the end of the range, to avoid
|
2010-03-18 00:42:48 +00:00
|
|
|
// entering #includes or expanding macros.
|
2010-03-18 15:23:44 +00:00
|
|
|
while (true) {
|
2010-03-18 00:42:48 +00:00
|
|
|
Token Tok;
|
|
|
|
Lex.LexFromRawLexer(Tok);
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-18 00:42:48 +00:00
|
|
|
reprocess:
|
|
|
|
if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) {
|
|
|
|
// We have found a preprocessing directive. Gobble it up so that we
|
|
|
|
// don't see it while preprocessing these tokens later, but keep track of
|
|
|
|
// all of the token locations inside this preprocessing directive so that
|
|
|
|
// we can annotate them appropriately.
|
|
|
|
//
|
|
|
|
// FIXME: Some simple tests here could identify macro definitions and
|
|
|
|
// #undefs, to provide specific cursor kinds for those.
|
|
|
|
std::vector<SourceLocation> Locations;
|
|
|
|
do {
|
|
|
|
Locations.push_back(Tok.getLocation());
|
2010-05-05 00:55:23 +00:00
|
|
|
Lex.LexFromRawLexer(Tok);
|
2010-03-18 00:42:48 +00:00
|
|
|
} while (!Tok.isAtStartOfLine() && !Tok.is(tok::eof));
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-18 00:42:48 +00:00
|
|
|
using namespace cxcursor;
|
|
|
|
CXCursor Cursor
|
2010-05-05 00:55:23 +00:00
|
|
|
= MakePreprocessingDirectiveCursor(SourceRange(Locations.front(),
|
|
|
|
Locations.back()),
|
2010-05-05 00:55:15 +00:00
|
|
|
CXXUnit);
|
2010-03-18 00:42:48 +00:00
|
|
|
for (unsigned I = 0, N = Locations.size(); I != N; ++I) {
|
|
|
|
Annotated[Locations[I].getRawEncoding()] = Cursor;
|
|
|
|
}
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-18 00:42:48 +00:00
|
|
|
if (Tok.isAtStartOfLine())
|
|
|
|
goto reprocess;
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-18 00:42:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-18 15:23:44 +00:00
|
|
|
if (Tok.is(tok::eof))
|
2010-03-18 00:42:48 +00:00
|
|
|
break;
|
|
|
|
}
|
Introduce the notion of a "preprocessing record", which keeps track of
the macro definitions and macro instantiations that are found
during preprocessing. Preprocessing records are *not* generated by
default; rather, we provide a PPCallbacks subclass that hooks into the
existing callback mechanism to record this activity.
The only client of preprocessing records is CIndex, which keeps track
of macro definitions and instantations so that they can be exposed via
cursors. At present, only token annotation uses these facilities, and
only for macro instantiations; both will change in the near
future. However, with this change, token annotation properly annotates
macro instantiations that do not produce any tokens and instantiations
of macros that are later undef'd, improving our consistency.
Preprocessing directives that are not macro definitions are still
handled by clang_annotateTokens() via re-lexing, so that we don't have
to track every preprocessing directive in the preprocessing record.
Performance impact of preprocessing records is still TBD, although it
is limited to CIndex and therefore out of the path of the main compiler.
llvm-svn: 98836
2010-03-18 17:52:52 +00:00
|
|
|
}
|
2010-05-05 00:55:23 +00:00
|
|
|
|
2010-03-19 05:22:59 +00:00
|
|
|
// Annotate all of the source locations in the region of interest that map to
|
2010-05-05 00:55:23 +00:00
|
|
|
// a specific cursor.
|
|
|
|
AnnotateTokensWorker W(Annotated, Tokens, Cursors, NumTokens,
|
|
|
|
CXXUnit, RegionOfInterest);
|
|
|
|
W.AnnotateTokens(clang_getTranslationUnitCursor(CXXUnit));
|
2010-01-26 17:06:03 +00:00
|
|
|
}
|
|
|
|
} // end: extern "C"
|
|
|
|
|
2010-03-03 06:36:57 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Operations for querying linkage of a cursor.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
CXLinkageKind clang_getCursorLinkage(CXCursor cursor) {
|
2010-03-19 05:22:59 +00:00
|
|
|
if (!clang_isDeclaration(cursor.kind))
|
|
|
|
return CXLinkage_Invalid;
|
|
|
|
|
2010-03-03 06:36:57 +00:00
|
|
|
Decl *D = cxcursor::getCursorDecl(cursor);
|
|
|
|
if (NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
|
|
|
|
switch (ND->getLinkage()) {
|
|
|
|
case NoLinkage: return CXLinkage_NoLinkage;
|
|
|
|
case InternalLinkage: return CXLinkage_Internal;
|
|
|
|
case UniqueExternalLinkage: return CXLinkage_UniqueExternal;
|
|
|
|
case ExternalLinkage: return CXLinkage_External;
|
|
|
|
};
|
|
|
|
|
|
|
|
return CXLinkage_Invalid;
|
|
|
|
}
|
|
|
|
} // end: extern "C"
|
|
|
|
|
2010-04-12 21:22:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Operations for querying language of a cursor.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static CXLanguageKind getDeclLanguage(const Decl *D) {
|
|
|
|
switch (D->getKind()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case Decl::ImplicitParam:
|
|
|
|
case Decl::ObjCAtDefsField:
|
|
|
|
case Decl::ObjCCategory:
|
|
|
|
case Decl::ObjCCategoryImpl:
|
|
|
|
case Decl::ObjCClass:
|
|
|
|
case Decl::ObjCCompatibleAlias:
|
|
|
|
case Decl::ObjCForwardProtocol:
|
|
|
|
case Decl::ObjCImplementation:
|
|
|
|
case Decl::ObjCInterface:
|
|
|
|
case Decl::ObjCIvar:
|
|
|
|
case Decl::ObjCMethod:
|
|
|
|
case Decl::ObjCProperty:
|
|
|
|
case Decl::ObjCPropertyImpl:
|
|
|
|
case Decl::ObjCProtocol:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
2010-08-23 23:00:57 +00:00
|
|
|
|
|
|
|
enum CXAvailabilityKind clang_getCursorAvailability(CXCursor cursor) {
|
|
|
|
if (clang_isDeclaration(cursor.kind))
|
|
|
|
if (Decl *D = cxcursor::getCursorDecl(cursor)) {
|
|
|
|
if (D->hasAttr<UnavailableAttr>() ||
|
|
|
|
(isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isDeleted()))
|
|
|
|
return CXAvailability_Available;
|
|
|
|
|
|
|
|
if (D->hasAttr<DeprecatedAttr>())
|
|
|
|
return CXAvailability_Deprecated;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CXAvailability_Available;
|
|
|
|
}
|
|
|
|
|
2010-04-12 21:22:16 +00:00
|
|
|
CXLanguageKind clang_getCursorLanguage(CXCursor cursor) {
|
|
|
|
if (clang_isDeclaration(cursor.kind))
|
|
|
|
return getDeclLanguage(cxcursor::getCursorDecl(cursor));
|
|
|
|
|
|
|
|
return CXLanguage_Invalid;
|
|
|
|
}
|
2010-09-22 21:22:29 +00:00
|
|
|
|
|
|
|
CXCursor clang_getCursorSemanticParent(CXCursor cursor) {
|
|
|
|
if (clang_isDeclaration(cursor.kind)) {
|
|
|
|
if (Decl *D = getCursorDecl(cursor)) {
|
|
|
|
DeclContext *DC = D->getDeclContext();
|
|
|
|
return MakeCXCursor(cast<Decl>(DC), getCursorASTUnit(cursor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clang_isStatement(cursor.kind) || clang_isExpression(cursor.kind)) {
|
|
|
|
if (Decl *D = getCursorDecl(cursor))
|
|
|
|
return MakeCXCursor(D, getCursorASTUnit(cursor));
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor clang_getCursorLexicalParent(CXCursor cursor) {
|
|
|
|
if (clang_isDeclaration(cursor.kind)) {
|
|
|
|
if (Decl *D = getCursorDecl(cursor)) {
|
|
|
|
DeclContext *DC = D->getLexicalDeclContext();
|
|
|
|
return MakeCXCursor(cast<Decl>(DC), getCursorASTUnit(cursor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Note that we can't easily compute the lexical context of a
|
|
|
|
// statement or expression, so we return nothing.
|
|
|
|
return clang_getNullCursor();
|
|
|
|
}
|
|
|
|
|
2010-10-01 20:25:15 +00:00
|
|
|
static void CollectOverriddenMethods(DeclContext *Ctx,
|
|
|
|
ObjCMethodDecl *Method,
|
|
|
|
llvm::SmallVectorImpl<ObjCMethodDecl *> &Methods) {
|
|
|
|
if (!Ctx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we have a class or category implementation, jump straight to the
|
|
|
|
// interface.
|
|
|
|
if (ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(Ctx))
|
|
|
|
return CollectOverriddenMethods(Impl->getClassInterface(), Method, Methods);
|
|
|
|
|
|
|
|
ObjCContainerDecl *Container = dyn_cast<ObjCContainerDecl>(Ctx);
|
|
|
|
if (!Container)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check whether we have a matching method at this level.
|
|
|
|
if (ObjCMethodDecl *Overridden = Container->getMethod(Method->getSelector(),
|
|
|
|
Method->isInstanceMethod()))
|
|
|
|
if (Method != Overridden) {
|
|
|
|
// We found an override at this level; there is no need to look
|
|
|
|
// into other protocols or categories.
|
|
|
|
Methods.push_back(Overridden);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
|
|
|
|
PEnd = Protocol->protocol_end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
CollectOverriddenMethods(*P, Method, Methods);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
|
|
|
|
for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(),
|
|
|
|
PEnd = Category->protocol_end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
CollectOverriddenMethods(*P, Method, Methods);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCInterfaceDecl *Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator P = Interface->protocol_begin(),
|
|
|
|
PEnd = Interface->protocol_end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
CollectOverriddenMethods(*P, Method, Methods);
|
|
|
|
|
|
|
|
for (ObjCCategoryDecl *Category = Interface->getCategoryList();
|
|
|
|
Category; Category = Category->getNextClassCategory())
|
|
|
|
CollectOverriddenMethods(Category, Method, Methods);
|
|
|
|
|
|
|
|
// We only look into the superclass if we haven't found anything yet.
|
|
|
|
if (Methods.empty())
|
|
|
|
if (ObjCInterfaceDecl *Super = Interface->getSuperClass())
|
|
|
|
return CollectOverriddenMethods(Super, Method, Methods);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_getOverriddenCursors(CXCursor cursor,
|
|
|
|
CXCursor **overridden,
|
|
|
|
unsigned *num_overridden) {
|
|
|
|
if (overridden)
|
|
|
|
*overridden = 0;
|
|
|
|
if (num_overridden)
|
|
|
|
*num_overridden = 0;
|
|
|
|
if (!overridden || !num_overridden)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!clang_isDeclaration(cursor.kind))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Decl *D = getCursorDecl(cursor);
|
|
|
|
if (!D)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Handle C++ member functions.
|
|
|
|
ASTUnit *CXXUnit = getCursorASTUnit(cursor);
|
|
|
|
if (CXXMethodDecl *CXXMethod = dyn_cast<CXXMethodDecl>(D)) {
|
|
|
|
*num_overridden = CXXMethod->size_overridden_methods();
|
|
|
|
if (!*num_overridden)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*overridden = new CXCursor [*num_overridden];
|
|
|
|
unsigned I = 0;
|
|
|
|
for (CXXMethodDecl::method_iterator
|
|
|
|
M = CXXMethod->begin_overridden_methods(),
|
|
|
|
MEnd = CXXMethod->end_overridden_methods();
|
|
|
|
M != MEnd; (void)++M, ++I)
|
|
|
|
(*overridden)[I] = MakeCXCursor(const_cast<CXXMethodDecl*>(*M), CXXUnit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D);
|
|
|
|
if (!Method)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Handle Objective-C methods.
|
|
|
|
llvm::SmallVector<ObjCMethodDecl *, 4> Methods;
|
|
|
|
CollectOverriddenMethods(Method->getDeclContext(), Method, Methods);
|
|
|
|
|
|
|
|
if (Methods.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
*num_overridden = Methods.size();
|
|
|
|
*overridden = new CXCursor [Methods.size()];
|
|
|
|
for (unsigned I = 0, N = Methods.size(); I != N; ++I)
|
|
|
|
(*overridden)[I] = MakeCXCursor(Methods[I], CXXUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clang_disposeOverriddenCursors(CXCursor *overridden) {
|
|
|
|
delete [] overridden;
|
|
|
|
}
|
|
|
|
|
2010-04-12 21:22:16 +00:00
|
|
|
} // end: extern "C"
|
|
|
|
|
2010-05-17 20:06:56 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// C++ AST instrospection.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
unsigned clang_CXXMethod_isStatic(CXCursor C) {
|
|
|
|
if (!clang_isDeclaration(C.kind))
|
|
|
|
return 0;
|
2010-08-31 22:12:17 +00:00
|
|
|
|
|
|
|
CXXMethodDecl *Method = 0;
|
|
|
|
Decl *D = cxcursor::getCursorDecl(C);
|
|
|
|
if (FunctionTemplateDecl *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(D))
|
|
|
|
Method = dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl());
|
|
|
|
else
|
|
|
|
Method = dyn_cast_or_null<CXXMethodDecl>(D);
|
|
|
|
return (Method && Method->isStatic()) ? 1 : 0;
|
2010-05-17 20:12:45 +00:00
|
|
|
}
|
2010-05-18 22:32:15 +00:00
|
|
|
|
2010-05-17 20:06:56 +00:00
|
|
|
} // end: extern "C"
|
|
|
|
|
2010-08-26 01:42:22 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Attribute introspection.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
CXType clang_getIBOutletCollectionType(CXCursor C) {
|
|
|
|
if (C.kind != CXCursor_IBOutletCollectionAttr)
|
|
|
|
return cxtype::MakeCXType(QualType(), cxcursor::getCursorASTUnit(C));
|
|
|
|
|
|
|
|
IBOutletCollectionAttr *A =
|
|
|
|
cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(C));
|
|
|
|
|
|
|
|
return cxtype::MakeCXType(A->getInterface(), cxcursor::getCursorASTUnit(C));
|
|
|
|
}
|
|
|
|
} // end: extern "C"
|
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CXString Operations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
const char *clang_getCString(CXString string) {
|
|
|
|
return string.Spelling;
|
|
|
|
}
|
2009-09-23 17:52:52 +00:00
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
void clang_disposeString(CXString string) {
|
|
|
|
if (string.MustFreeString && string.Spelling)
|
|
|
|
free((void*)string.Spelling);
|
|
|
|
}
|
2010-01-22 22:44:15 +00:00
|
|
|
|
2010-01-13 21:46:36 +00:00
|
|
|
} // end: extern "C"
|
2010-01-22 22:44:15 +00:00
|
|
|
|
2010-02-17 00:41:08 +00:00
|
|
|
namespace clang { namespace cxstring {
|
|
|
|
CXString createCXString(const char *String, bool DupString){
|
|
|
|
CXString Str;
|
|
|
|
if (DupString) {
|
|
|
|
Str.Spelling = strdup(String);
|
|
|
|
Str.MustFreeString = 1;
|
|
|
|
} else {
|
|
|
|
Str.Spelling = String;
|
|
|
|
Str.MustFreeString = 0;
|
|
|
|
}
|
|
|
|
return Str;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXString createCXString(llvm::StringRef String, bool DupString) {
|
|
|
|
CXString Result;
|
|
|
|
if (DupString || (!String.empty() && String.data()[String.size()] != 0)) {
|
|
|
|
char *Spelling = (char *)malloc(String.size() + 1);
|
|
|
|
memmove(Spelling, String.data(), String.size());
|
|
|
|
Spelling[String.size()] = 0;
|
|
|
|
Result.Spelling = Spelling;
|
|
|
|
Result.MustFreeString = 1;
|
|
|
|
} else {
|
|
|
|
Result.Spelling = String.data();
|
|
|
|
Result.MustFreeString = 0;
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
|
2010-01-22 22:44:15 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Misc. utility functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-02-17 00:41:40 +00:00
|
|
|
|
2010-01-22 22:44:15 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2010-02-12 22:54:40 +00:00
|
|
|
CXString clang_getClangVersion() {
|
2010-02-17 00:41:08 +00:00
|
|
|
return createCXString(getClangFullVersion());
|
2010-01-22 22:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end: extern "C"
|