[llvm-branch-commits] [cfe-branch] r119419 - in /cfe/branches/Apple/whitney: include/clang-c/Index.h tools/c-index-test/c-index-test.c tools/libclang/CIndex.cpp tools/libclang/CIndexCXX.cpp tools/libclang/CIndexCodeCompletion.cpp tools/libclang/CIndexDiagnostic.cpp tools/libclang/CIndexInclusionStack.cpp tools/libclang/CXCursor.cpp tools/libclang/CXCursor.h tools/libclang/CXString.cpp tools/libclang/CXString.h tools/libclang/CXType.cpp tools/libclang/CXType.h
Daniel Dunbar
daniel at zuster.org
Tue Nov 16 16:23:43 PST 2010
Author: ddunbar
Date: Tue Nov 16 18:23:42 2010
New Revision: 119419
URL: http://llvm.org/viewvc/llvm-project?rev=119419&view=rev
Log:
Merge r119337:
--
Author: Ted Kremenek <kremenek at apple.com>
Date: Tue Nov 16 08:15:36 2010 +0000
Change CXTranslationUnit to not directly cast to an ASTUnit*,
but to wrap both an ASTUnit and a "string pool"
that will be used for fast USR generation.
This requires a bunch of mechanical changes, as
there was a ton of code that assumed that CXTranslationUnit
and ASTUnit* were the same.
Along with this change, introduce CXStringBuf,
which provides an llvm::SmallVector<char> backing
for repeatedly generating CXStrings without a huge
amount of malloc() traffic. This requires making
some changes to the representation of CXString
by renaming a few fields (but keeping the size
of the object the same).
Modified:
cfe/branches/Apple/whitney/include/clang-c/Index.h
cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c
cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
cfe/branches/Apple/whitney/tools/libclang/CIndexCXX.cpp
cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp
cfe/branches/Apple/whitney/tools/libclang/CIndexDiagnostic.cpp
cfe/branches/Apple/whitney/tools/libclang/CIndexInclusionStack.cpp
cfe/branches/Apple/whitney/tools/libclang/CXCursor.cpp
cfe/branches/Apple/whitney/tools/libclang/CXCursor.h
cfe/branches/Apple/whitney/tools/libclang/CXString.cpp
cfe/branches/Apple/whitney/tools/libclang/CXString.h
cfe/branches/Apple/whitney/tools/libclang/CXType.cpp
cfe/branches/Apple/whitney/tools/libclang/CXType.h
Modified: cfe/branches/Apple/whitney/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang-c/Index.h?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang-c/Index.h (original)
+++ cfe/branches/Apple/whitney/include/clang-c/Index.h Tue Nov 16 18:23:42 2010
@@ -63,7 +63,10 @@
/**
* \brief A single translation unit, which resides in an index.
*/
-typedef void *CXTranslationUnit; /* A translation unit instance. */
+typedef struct CXTranslationUnitImpl {
+ void *TUData;
+ void *StringPool;
+} *CXTranslationUnit; /* A translation unit instance. */
/**
* \brief Opaque pointer representing client data that will be passed through
@@ -133,7 +136,7 @@
* with the string data, call \c clang_disposeString() to free the string.
*/
typedef struct {
- const char *Spelling;
+ void *data;
unsigned private_flags;
} CXString;
Modified: cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c (original)
+++ cfe/branches/Apple/whitney/tools/c-index-test/c-index-test.c Tue Nov 16 18:23:42 2010
@@ -1305,7 +1305,7 @@
return not_usr("<class USR>", I[2]);
else {
CXString x;
- x.Spelling = I[2];
+ x.data = (void*) I[2];
x.private_flags = 0;
print_usr(clang_constructUSR_ObjCIvar(I[1], x));
}
@@ -1332,7 +1332,7 @@
return not_usr("<class USR>", I[3]);
else {
CXString x;
- x.Spelling = I[3];
+ x.data = (void*) I[3];
x.private_flags = 0;
print_usr(clang_constructUSR_ObjCMethod(I[1], atoi(I[2]), x));
}
@@ -1362,7 +1362,7 @@
return not_usr("<class USR>", I[2]);
else {
CXString x;
- x.Spelling = I[2];
+ x.data = (void*) I[2];
x.private_flags = 0;
print_usr(clang_constructUSR_ObjCProperty(I[1], x));
}
Modified: cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp Tue Nov 16 18:23:42 2010
@@ -51,6 +51,15 @@
using namespace clang::cxcursor;
using namespace clang::cxstring;
+static CXTranslationUnit MakeCXTranslationUnit(ASTUnit *TU) {
+ if (!TU)
+ return 0;
+ CXTranslationUnit D = new CXTranslationUnitImpl();
+ D->TUData = TU;
+ D->StringPool = createCXStringPool();
+ return D;
+}
+
/// \brief The result of comparing two source ranges.
enum RangeComparisonResult {
/// \brief Either the ranges overlap or one of the ranges is invalid.
@@ -161,7 +170,8 @@
public StmtVisitor<CursorVisitor, bool>
{
/// \brief The translation unit we are traversing.
- ASTUnit *TU;
+ CXTranslationUnit TU;
+ ASTUnit *AU;
/// \brief The parent cursor whose children we are traversing.
CXCursor Parent;
@@ -222,10 +232,12 @@
};
public:
- CursorVisitor(ASTUnit *TU, CXCursorVisitor Visitor, CXClientData ClientData,
+ CursorVisitor(CXTranslationUnit TU, CXCursorVisitor Visitor,
+ CXClientData ClientData,
unsigned MaxPCHLevel,
SourceRange RegionOfInterest = SourceRange())
- : TU(TU), Visitor(Visitor), ClientData(ClientData),
+ : TU(TU), AU(static_cast<ASTUnit*>(TU->TUData)),
+ Visitor(Visitor), ClientData(ClientData),
MaxPCHLevel(MaxPCHLevel), RegionOfInterest(RegionOfInterest),
DI_current(0)
{
@@ -236,7 +248,8 @@
StmtParent = 0;
}
- ASTUnit *getASTUnit() const { return TU; }
+ ASTUnit *getASTUnit() const { return static_cast<ASTUnit*>(TU->TUData); }
+ CXTranslationUnit getTU() const { return TU; }
bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false);
@@ -376,7 +389,7 @@
static SourceRange getRawCursorExtent(CXCursor C);
RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) {
- return RangeCompare(TU->getSourceManager(), R, RegionOfInterest);
+ return RangeCompare(AU->getSourceManager(), R, RegionOfInterest);
}
/// \brief Visit the given cursor and, if requested by the visitor,
@@ -428,10 +441,10 @@
std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
CursorVisitor::getPreprocessedEntities() {
PreprocessingRecord &PPRec
- = *TU->getPreprocessor().getPreprocessingRecord();
+ = *AU->getPreprocessor().getPreprocessingRecord();
bool OnlyLocalDecls
- = !TU->isMainFileAST() && TU->getOnlyLocalDecls();
+ = !AU->isMainFileAST() && AU->getOnlyLocalDecls();
// There is no region of interest; we have to walk everything.
if (RegionOfInterest.isInvalid())
@@ -439,7 +452,7 @@
PPRec.end(OnlyLocalDecls));
// Find the file in which the region of interest lands.
- SourceManager &SM = TU->getSourceManager();
+ SourceManager &SM = AU->getSourceManager();
std::pair<FileID, unsigned> Begin
= SM.getDecomposedInstantiationLoc(RegionOfInterest.getBegin());
std::pair<FileID, unsigned> End
@@ -451,7 +464,7 @@
PPRec.end(OnlyLocalDecls));
ASTUnit::PreprocessedEntitiesByFileMap &ByFileMap
- = TU->getPreprocessedEntitiesByFile();
+ = AU->getPreprocessedEntitiesByFile();
if (ByFileMap.empty()) {
// Build the mapping from files to sets of preprocessed entities.
for (PreprocessingRecord::iterator E = PPRec.begin(OnlyLocalDecls),
@@ -468,7 +481,7 @@
}
/// \brief Visit the children of the given cursor.
-///
+///
/// \returns true if the visitation should be aborted, false if it
/// should continue.
bool CursorVisitor::VisitChildren(CXCursor Cursor) {
@@ -493,13 +506,14 @@
return Visit(getCursorExpr(Cursor));
if (clang_isTranslationUnit(Cursor.kind)) {
- ASTUnit *CXXUnit = getCursorASTUnit(Cursor);
+ CXTranslationUnit tu = getCursorTU(Cursor);
+ ASTUnit *CXXUnit = static_cast<ASTUnit*>(tu->TUData);
if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() &&
RegionOfInterest.isInvalid()) {
for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(),
TLEnd = CXXUnit->top_level_end();
TL != TLEnd; ++TL) {
- if (Visit(MakeCXCursor(*TL, CXXUnit), true))
+ if (Visit(MakeCXCursor(*TL, tu), true))
return true;
}
} else if (VisitDeclContext(
@@ -513,21 +527,21 @@
PreprocessingRecord::iterator E, EEnd;
for (llvm::tie(E, EEnd) = getPreprocessedEntities(); E != EEnd; ++E) {
if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) {
- if (Visit(MakeMacroInstantiationCursor(MI, CXXUnit)))
+ if (Visit(MakeMacroInstantiationCursor(MI, tu)))
return true;
continue;
}
if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) {
- if (Visit(MakeMacroDefinitionCursor(MD, CXXUnit)))
+ if (Visit(MakeMacroDefinitionCursor(MD, tu)))
return true;
continue;
}
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) {
- if (Visit(MakeInclusionDirectiveCursor(ID, CXXUnit)))
+ if (Visit(MakeInclusionDirectiveCursor(ID, tu)))
return true;
continue;
@@ -885,7 +899,7 @@
// for later processing.
llvm::SmallVector<Decl *, 24> DeclsInContainer;
SourceLocation EndLoc = D->getSourceRange().getEnd();
- SourceManager &SM = TU->getSourceManager();
+ SourceManager &SM = AU->getSourceManager();
if (EndLoc.isValid()) {
DeclContext::decl_iterator next = *DI_current;
while (++next != DE_current) {
@@ -1269,7 +1283,7 @@
}
bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
- ASTContext &Context = TU->getASTContext();
+ ASTContext &Context = AU->getASTContext();
// Some builtin types (such as Objective-C's "id", "sel", and
// "Class") have associated declarations. Create cursors for those.
@@ -2133,9 +2147,10 @@
FileSystemOpts.WorkingDir = CXXIdx->getWorkingDirectory();
llvm::IntrusiveRefCntPtr<Diagnostic> Diags;
- return ASTUnit::LoadFromASTFile(ast_filename, Diags, FileSystemOpts,
+ ASTUnit *TU = ASTUnit::LoadFromASTFile(ast_filename, Diags, FileSystemOpts,
CXXIdx->getOnlyLocalDecls(),
0, 0, true);
+ return MakeCXTranslationUnit(TU);
}
unsigned clang_defaultEditingTranslationUnitOptions() {
@@ -2277,7 +2292,7 @@
}
}
- PTUI->result = Unit.take();
+ PTUI->result = MakeCXTranslationUnit(Unit.take());
}
CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
const char *source_filename,
@@ -2327,17 +2342,19 @@
if (!TU)
return 1;
- return static_cast<ASTUnit *>(TU)->Save(FileName);
+ return static_cast<ASTUnit *>(TU->TUData)->Save(FileName);
}
void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
if (CTUnit) {
// If the translation unit has been marked as unsafe to free, just discard
// it.
- if (static_cast<ASTUnit *>(CTUnit)->isUnsafeToFree())
+ if (static_cast<ASTUnit *>(CTUnit->TUData)->isUnsafeToFree())
return;
- delete static_cast<ASTUnit *>(CTUnit);
+ delete static_cast<ASTUnit *>(CTUnit->TUData);
+ disposeCXStringPool(CTUnit->StringPool);
+ delete CTUnit;
}
}
@@ -2366,7 +2383,7 @@
if (!TU)
return;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
llvm::SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles;
@@ -2392,7 +2409,7 @@
if (!RunSafely(CRC, clang_reparseTranslationUnit_Impl, &RTUI)) {
fprintf(stderr, "libclang: crash detected during reparsing\n");
- static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
+ static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true);
return 1;
}
@@ -2405,7 +2422,7 @@
if (!CTUnit)
return createCXString("");
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit->TUData);
return createCXString(CXXUnit->getOriginalSourceFileName(), true);
}
@@ -2439,7 +2456,7 @@
if (!tu || !file)
return clang_getNullLocation();
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
SourceLocation SLoc
= CXXUnit->getSourceManager().getLocation(
static_cast<const FileEntry *>(file),
@@ -2455,7 +2472,7 @@
if (!tu || !file)
return clang_getNullLocation();
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
SourceLocation Start
= CXXUnit->getSourceManager().getLocation(
static_cast<const FileEntry *>(file),
@@ -2583,7 +2600,7 @@
extern "C" {
CXString clang_getFileName(CXFile SFile) {
if (!SFile)
- return createCXString(NULL);
+ return createCXString((const char*)NULL);
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
return createCXString(FEnt->getName());
@@ -2601,7 +2618,7 @@
if (!tu)
return 0;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->TUData);
FileManager &FMgr = CXXUnit->getFileManager();
const FileEntry *File = FMgr.getFile(file_name, file_name+strlen(file_name),
@@ -2663,10 +2680,8 @@
unsigned clang_visitChildren(CXCursor parent,
CXCursorVisitor visitor,
CXClientData client_data) {
- ASTUnit *CXXUnit = getCursorASTUnit(parent);
-
- CursorVisitor CursorVis(CXXUnit, visitor, client_data,
- CXXUnit->getMaxPCHLevel());
+ CursorVisitor CursorVis(getCursorTU(parent), visitor, client_data,
+ getCursorASTUnit(parent)->getMaxPCHLevel());
return CursorVis.VisitChildren(parent);
}
@@ -2733,7 +2748,8 @@
CXString clang_getCursorSpelling(CXCursor C) {
if (clang_isTranslationUnit(C.kind))
- return clang_getTranslationUnitSpelling(C.data[2]);
+ return clang_getTranslationUnitSpelling(
+ static_cast<CXTranslationUnit>(C.data[2]));
if (clang_isReference(C.kind)) {
switch (C.kind) {
@@ -3063,7 +3079,7 @@
}
llvm_unreachable("Unhandled CXCursorKind");
- return createCXString(NULL);
+ return createCXString((const char*) 0);
}
enum CXChildVisitResult GetCursorVisitor(CXCursor cursor,
@@ -3087,7 +3103,7 @@
if (!TU)
return clang_getNullCursor();
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
// Translate the given source location to make it point at the beginning of
@@ -3108,8 +3124,8 @@
// 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);
- CursorVisitor CursorVis(CXXUnit, GetCursorVisitor, &Result,
+ CXCursor Parent = clang_getTranslationUnitCursor(TU);
+ CursorVisitor CursorVis(TU, GetCursorVisitor, &Result,
Decl::MaxPCHLevel, SourceLocation(SLoc));
CursorVis.VisitChildren(Parent);
}
@@ -3401,16 +3417,16 @@
if (clang_isInvalid(C.kind))
return clang_getNullCursor();
- ASTUnit *CXXUnit = getCursorASTUnit(C);
+ CXTranslationUnit tu = getCursorTU(C);
if (clang_isDeclaration(C.kind)) {
Decl *D = getCursorDecl(C);
if (UsingDecl *Using = dyn_cast<UsingDecl>(D))
- return MakeCursorOverloadedDeclRef(Using, D->getLocation(), CXXUnit);
+ return MakeCursorOverloadedDeclRef(Using, D->getLocation(), tu);
if (ObjCClassDecl *Classes = dyn_cast<ObjCClassDecl>(D))
- return MakeCursorOverloadedDeclRef(Classes, D->getLocation(), CXXUnit);
+ return MakeCursorOverloadedDeclRef(Classes, D->getLocation(), tu);
if (ObjCForwardProtocolDecl *Protocols
= dyn_cast<ObjCForwardProtocolDecl>(D))
- return MakeCursorOverloadedDeclRef(Protocols, D->getLocation(), CXXUnit);
+ return MakeCursorOverloadedDeclRef(Protocols, D->getLocation(), tu);
return C;
}
@@ -3419,10 +3435,10 @@
Expr *E = getCursorExpr(C);
Decl *D = getDeclFromExpr(E);
if (D)
- return MakeCXCursor(D, CXXUnit);
+ return MakeCXCursor(D, tu);
if (OverloadExpr *Ovl = dyn_cast_or_null<OverloadExpr>(E))
- return MakeCursorOverloadedDeclRef(Ovl, CXXUnit);
+ return MakeCursorOverloadedDeclRef(Ovl, tu);
return clang_getNullCursor();
}
@@ -3430,15 +3446,14 @@
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 MakeCXCursor(Goto->getLabel(), getCursorDecl(C), tu);
return clang_getNullCursor();
}
if (C.kind == CXCursor_MacroInstantiation) {
if (MacroDefinition *Def = getCursorMacroInstantiation(C)->getDefinition())
- return MakeMacroDefinitionCursor(Def, CXXUnit);
+ return MakeMacroDefinitionCursor(Def, tu);
}
if (!clang_isReference(C.kind))
@@ -3446,38 +3461,39 @@
switch (C.kind) {
case CXCursor_ObjCSuperClassRef:
- return MakeCXCursor(getCursorObjCSuperClassRef(C).first, CXXUnit);
+ return MakeCXCursor(getCursorObjCSuperClassRef(C).first, tu);
case CXCursor_ObjCProtocolRef: {
- return MakeCXCursor(getCursorObjCProtocolRef(C).first, CXXUnit);
+ return MakeCXCursor(getCursorObjCProtocolRef(C).first, tu);
case CXCursor_ObjCClassRef:
- return MakeCXCursor(getCursorObjCClassRef(C).first, CXXUnit);
+ return MakeCXCursor(getCursorObjCClassRef(C).first, tu );
case CXCursor_TypeRef:
- return MakeCXCursor(getCursorTypeRef(C).first, CXXUnit);
+ return MakeCXCursor(getCursorTypeRef(C).first, tu );
case CXCursor_TemplateRef:
- return MakeCXCursor(getCursorTemplateRef(C).first, CXXUnit);
+ return MakeCXCursor(getCursorTemplateRef(C).first, tu );
case CXCursor_NamespaceRef:
- return MakeCXCursor(getCursorNamespaceRef(C).first, CXXUnit);
+ return MakeCXCursor(getCursorNamespaceRef(C).first, tu );
case CXCursor_MemberRef:
- return MakeCXCursor(getCursorMemberRef(C).first, CXXUnit);
+ return MakeCXCursor(getCursorMemberRef(C).first, tu );
case CXCursor_CXXBaseSpecifier: {
CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C);
return clang_getTypeDeclaration(cxtype::MakeCXType(B->getType(),
- CXXUnit));
+ tu ));
}
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);
+ static_cast<ASTUnit*>(tu->TUData)->getASTContext()
+ .getTranslationUnitDecl(),
+ tu);
case CXCursor_OverloadedDeclRef:
return C;
@@ -3496,7 +3512,7 @@
if (clang_isInvalid(C.kind))
return clang_getNullCursor();
- ASTUnit *CXXUnit = getCursorASTUnit(C);
+ CXTranslationUnit TU = getCursorTU(C);
bool WasReference = false;
if (clang_isReference(C.kind) || clang_isExpression(C.kind)) {
@@ -3550,10 +3566,10 @@
case Decl::UsingDirective:
return MakeCXCursor(cast<UsingDirectiveDecl>(D)->getNominatedNamespace(),
- CXXUnit);
+ TU);
case Decl::NamespaceAlias:
- return MakeCXCursor(cast<NamespaceAliasDecl>(D)->getNamespace(), CXXUnit);
+ return MakeCXCursor(cast<NamespaceAliasDecl>(D)->getNamespace(), TU);
case Decl::Enum:
case Decl::Record:
@@ -3561,7 +3577,7 @@
case Decl::ClassTemplateSpecialization:
case Decl::ClassTemplatePartialSpecialization:
if (TagDecl *Def = cast<TagDecl>(D)->getDefinition())
- return MakeCXCursor(Def, CXXUnit);
+ return MakeCXCursor(Def, TU);
return clang_getNullCursor();
case Decl::Function:
@@ -3571,21 +3587,21 @@
case Decl::CXXConversion: {
const FunctionDecl *Def = 0;
if (cast<FunctionDecl>(D)->getBody(Def))
- return MakeCXCursor(const_cast<FunctionDecl *>(Def), CXXUnit);
+ return MakeCXCursor(const_cast<FunctionDecl *>(Def), TU);
return clang_getNullCursor();
}
case Decl::Var: {
// Ask the variable if it has a definition.
if (VarDecl *Def = cast<VarDecl>(D)->getDefinition())
- return MakeCXCursor(Def, CXXUnit);
+ return MakeCXCursor(Def, TU);
return clang_getNullCursor();
}
case Decl::FunctionTemplate: {
const FunctionDecl *Def = 0;
if (cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->getBody(Def))
- return MakeCXCursor(Def->getDescribedFunctionTemplate(), CXXUnit);
+ return MakeCXCursor(Def->getDescribedFunctionTemplate(), TU);
return clang_getNullCursor();
}
@@ -3593,18 +3609,18 @@
if (RecordDecl *Def = cast<ClassTemplateDecl>(D)->getTemplatedDecl()
->getDefinition())
return MakeCXCursor(cast<CXXRecordDecl>(Def)->getDescribedClassTemplate(),
- CXXUnit);
+ TU);
return clang_getNullCursor();
}
case Decl::Using:
return MakeCursorOverloadedDeclRef(cast<UsingDecl>(D),
- D->getLocation(), CXXUnit);
+ D->getLocation(), TU);
case Decl::UsingShadow:
return clang_getCursorDefinition(
MakeCXCursor(cast<UsingShadowDecl>(D)->getTargetDecl(),
- CXXUnit));
+ TU));
case Decl::ObjCMethod: {
ObjCMethodDecl *Method = cast<ObjCMethodDecl>(D);
@@ -3620,7 +3636,7 @@
if (ObjCMethodDecl *Def = ClassImpl->getMethod(Method->getSelector(),
Method->isInstanceMethod()))
if (Def->isThisDeclarationADefinition())
- return MakeCXCursor(Def, CXXUnit);
+ return MakeCXCursor(Def, TU);
return clang_getNullCursor();
}
@@ -3628,7 +3644,7 @@
case Decl::ObjCCategory:
if (ObjCCategoryImplDecl *Impl
= cast<ObjCCategoryDecl>(D)->getImplementation())
- return MakeCXCursor(Impl, CXXUnit);
+ return MakeCXCursor(Impl, TU);
return clang_getNullCursor();
case Decl::ObjCProtocol:
@@ -3647,7 +3663,7 @@
return C;
} else if (ObjCImplementationDecl *Impl
= cast<ObjCInterfaceDecl>(D)->getImplementation())
- return MakeCXCursor(Impl, CXXUnit);
+ return MakeCXCursor(Impl, TU);
return clang_getNullCursor();
case Decl::ObjCProperty:
@@ -3659,26 +3675,26 @@
if (ObjCInterfaceDecl *Class
= cast<ObjCCompatibleAliasDecl>(D)->getClassInterface())
if (!Class->isForwardDecl())
- return MakeCXCursor(Class, CXXUnit);
+ return MakeCXCursor(Class, TU);
return clang_getNullCursor();
case Decl::ObjCForwardProtocol:
return MakeCursorOverloadedDeclRef(cast<ObjCForwardProtocolDecl>(D),
- D->getLocation(), CXXUnit);
+ D->getLocation(), TU);
case Decl::ObjCClass:
return MakeCursorOverloadedDeclRef(cast<ObjCClassDecl>(D), D->getLocation(),
- CXXUnit);
+ TU);
case Decl::Friend:
if (NamedDecl *Friend = cast<FriendDecl>(D)->getFriendDecl())
- return clang_getCursorDefinition(MakeCXCursor(Friend, CXXUnit));
+ return clang_getCursorDefinition(MakeCXCursor(Friend, TU));
return clang_getNullCursor();
case Decl::FriendTemplate:
if (NamedDecl *Friend = cast<FriendTemplateDecl>(D)->getFriendDecl())
- return clang_getCursorDefinition(MakeCXCursor(Friend, CXXUnit));
+ return clang_getCursorDefinition(MakeCXCursor(Friend, TU));
return clang_getNullCursor();
}
@@ -3722,28 +3738,28 @@
if (index >= clang_getNumOverloadedDecls(cursor))
return clang_getNullCursor();
- ASTUnit *Unit = getCursorASTUnit(cursor);
+ CXTranslationUnit TU = getCursorTU(cursor);
OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(cursor).first;
if (OverloadExpr *E = Storage.dyn_cast<OverloadExpr *>())
- return MakeCXCursor(E->decls_begin()[index], Unit);
+ return MakeCXCursor(E->decls_begin()[index], TU);
if (OverloadedTemplateStorage *S
= Storage.dyn_cast<OverloadedTemplateStorage*>())
- return MakeCXCursor(S->begin()[index], Unit);
+ return MakeCXCursor(S->begin()[index], TU);
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);
+ return MakeCXCursor(cast<UsingShadowDecl>(*Pos)->getTargetDecl(), TU);
}
if (ObjCClassDecl *Classes = dyn_cast<ObjCClassDecl>(D))
- return MakeCXCursor(Classes->begin()[index].getInterface(), Unit);
+ return MakeCXCursor(Classes->begin()[index].getInterface(), TU);
if (ObjCForwardProtocolDecl *Protocols = dyn_cast<ObjCForwardProtocolDecl>(D))
- return MakeCXCursor(Protocols->protocol_begin()[index], Unit);
+ return MakeCXCursor(Protocols->protocol_begin()[index], TU);
return clang_getNullCursor();
}
@@ -3819,7 +3835,7 @@
// We have to find the starting buffer pointer the hard way, by
// deconstructing the source location.
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
if (!CXXUnit)
return createCXString("");
@@ -3836,7 +3852,7 @@
}
CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
if (!CXXUnit)
return clang_getNullLocation();
@@ -3845,7 +3861,7 @@
}
CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
if (!CXXUnit)
return clang_getNullRange();
@@ -3860,7 +3876,7 @@
if (NumTokens)
*NumTokens = 0;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
if (!CXXUnit || !Tokens || !NumTokens)
return;
@@ -3993,18 +4009,19 @@
public:
AnnotateTokensWorker(AnnotateTokensData &annotated,
CXToken *tokens, CXCursor *cursors, unsigned numTokens,
- ASTUnit *CXXUnit, SourceRange RegionOfInterest)
+ CXTranslationUnit tu, SourceRange RegionOfInterest)
: Annotated(annotated), Tokens(tokens), Cursors(cursors),
NumTokens(numTokens), TokIdx(0), PreprocessingTokIdx(0),
- AnnotateVis(CXXUnit, AnnotateTokensVisitor, this,
+ AnnotateVis(tu,
+ AnnotateTokensVisitor, this,
Decl::MaxPCHLevel, RegionOfInterest),
- SrcMgr(CXXUnit->getSourceManager()) {}
+ SrcMgr(static_cast<ASTUnit*>(tu->TUData)->getSourceManager()) {}
void VisitChildren(CXCursor C) { AnnotateVis.VisitChildren(C); }
enum CXChildVisitResult Visit(CXCursor cursor, CXCursor parent);
void AnnotateTokens(CXCursor parent);
void AnnotateTokens() {
- AnnotateTokens(clang_getTranslationUnitCursor(AnnotateVis.getASTUnit()));
+ AnnotateTokens(clang_getTranslationUnitCursor(AnnotateVis.getTU()));
}
};
}
@@ -4229,7 +4246,7 @@
for (unsigned I = 0; I != NumTokens; ++I)
Cursors[I] = C;
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
if (!CXXUnit)
return;
@@ -4291,7 +4308,7 @@
CXCursor Cursor
= MakePreprocessingDirectiveCursor(SourceRange(Locations.front(),
Locations.back()),
- CXXUnit);
+ TU);
for (unsigned I = 0, N = Locations.size(); I != N; ++I) {
Annotated[Locations[I].getRawEncoding()] = Cursor;
}
@@ -4310,7 +4327,7 @@
// Annotate all of the source locations in the region of interest that map to
// a specific cursor.
AnnotateTokensWorker W(Annotated, Tokens, Cursors, NumTokens,
- CXXUnit, RegionOfInterest);
+ TU, RegionOfInterest);
// Run the worker within a CrashRecoveryContext.
llvm::CrashRecoveryContext CRC;
@@ -4421,13 +4438,13 @@
if (clang_isDeclaration(cursor.kind)) {
if (Decl *D = getCursorDecl(cursor)) {
DeclContext *DC = D->getDeclContext();
- return MakeCXCursor(cast<Decl>(DC), getCursorASTUnit(cursor));
+ return MakeCXCursor(cast<Decl>(DC), getCursorTU(cursor));
}
}
if (clang_isStatement(cursor.kind) || clang_isExpression(cursor.kind)) {
if (Decl *D = getCursorDecl(cursor))
- return MakeCXCursor(D, getCursorASTUnit(cursor));
+ return MakeCXCursor(D, getCursorTU(cursor));
}
return clang_getNullCursor();
@@ -4437,7 +4454,7 @@
if (clang_isDeclaration(cursor.kind)) {
if (Decl *D = getCursorDecl(cursor)) {
DeclContext *DC = D->getLexicalDeclContext();
- return MakeCXCursor(cast<Decl>(DC), getCursorASTUnit(cursor));
+ return MakeCXCursor(cast<Decl>(DC), getCursorTU(cursor));
}
}
@@ -4520,7 +4537,7 @@
return;
// Handle C++ member functions.
- ASTUnit *CXXUnit = getCursorASTUnit(cursor);
+ CXTranslationUnit TU = getCursorTU(cursor);
if (CXXMethodDecl *CXXMethod = dyn_cast<CXXMethodDecl>(D)) {
*num_overridden = CXXMethod->size_overridden_methods();
if (!*num_overridden)
@@ -4532,7 +4549,7 @@
M = CXXMethod->begin_overridden_methods(),
MEnd = CXXMethod->end_overridden_methods();
M != MEnd; (void)++M, ++I)
- (*overridden)[I] = MakeCXCursor(const_cast<CXXMethodDecl*>(*M), CXXUnit);
+ (*overridden)[I] = MakeCXCursor(const_cast<CXXMethodDecl*>(*M), TU);
return;
}
@@ -4550,7 +4567,7 @@
*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);
+ (*overridden)[I] = MakeCXCursor(Methods[I], TU);
}
void clang_disposeOverriddenCursors(CXCursor *overridden) {
@@ -4595,12 +4612,12 @@
extern "C" {
CXType clang_getIBOutletCollectionType(CXCursor C) {
if (C.kind != CXCursor_IBOutletCollectionAttr)
- return cxtype::MakeCXType(QualType(), cxcursor::getCursorASTUnit(C));
+ return cxtype::MakeCXType(QualType(), cxcursor::getCursorTU(C));
IBOutletCollectionAttr *A =
cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(C));
- return cxtype::MakeCXType(A->getInterface(), cxcursor::getCursorASTUnit(C));
+ return cxtype::MakeCXType(A->getInterface(), cxcursor::getCursorTU(C));
}
} // end: extern "C"
Modified: cfe/branches/Apple/whitney/tools/libclang/CIndexCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndexCXX.cpp?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndexCXX.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndexCXX.cpp Tue Nov 16 18:23:42 2010
@@ -55,7 +55,7 @@
if (TemplateDecl *Template
= dyn_cast_or_null<TemplateDecl>(getCursorDecl(C)))
return MakeCXCursor(Template->getTemplatedDecl(),
- getCursorASTUnit(C)).kind;
+ static_cast<CXTranslationUnit>(C.data[2])).kind;
break;
case CXCursor_ClassTemplatePartialSpecialization:
@@ -117,7 +117,7 @@
if (!Template)
return clang_getNullCursor();
- return MakeCXCursor(Template, getCursorASTUnit(C));
+ return MakeCXCursor(Template, static_cast<CXTranslationUnit>(C.data[2]));
}
} // end extern "C"
Modified: cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndexCodeCompletion.cpp Tue Nov 16 18:23:42 2010
@@ -125,7 +125,7 @@
CXStoredCodeCompletionString *CCStr
= (CXStoredCodeCompletionString *)completion_string;
if (!CCStr || chunk_number >= CCStr->size())
- return createCXString(0);
+ return createCXString((const char*)0);
switch ((*CCStr)[chunk_number].Kind) {
case CodeCompletionString::CK_TypedText:
@@ -156,7 +156,7 @@
}
// Should be unreachable, but let's be careful.
- return createCXString(0);
+ return createCXString((const char*)0);
}
@@ -355,7 +355,7 @@
bool EnableLogging = getenv("LIBCLANG_CODE_COMPLETION_LOGGING") != 0;
- ASTUnit *AST = static_cast<ASTUnit *>(TU);
+ ASTUnit *AST = static_cast<ASTUnit *>(TU->TUData);
if (!AST)
return;
@@ -483,7 +483,7 @@
if (!RunSafely(CRC, clang_codeCompleteAt_Impl, &CCAI)) {
fprintf(stderr, "libclang: crash detected in code completion\n");
- static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
+ static_cast<ASTUnit *>(TU->TUData)->setUnsafeToFree(true);
return 0;
}
Modified: cfe/branches/Apple/whitney/tools/libclang/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndexDiagnostic.cpp?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndexDiagnostic.cpp Tue Nov 16 18:23:42 2010
@@ -33,12 +33,12 @@
extern "C" {
unsigned clang_getNumDiagnostics(CXTranslationUnit Unit) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit->TUData);
return CXXUnit? CXXUnit->stored_diag_size() : 0;
}
CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, unsigned Index) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit->TUData);
if (!CXXUnit || Index >= CXXUnit->stored_diag_size())
return 0;
Modified: cfe/branches/Apple/whitney/tools/libclang/CIndexInclusionStack.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndexInclusionStack.cpp?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndexInclusionStack.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndexInclusionStack.cpp Tue Nov 16 18:23:42 2010
@@ -24,7 +24,7 @@
void clang_getInclusions(CXTranslationUnit TU, CXInclusionVisitor CB,
CXClientData clientData) {
- ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU);
+ ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
SourceManager &SM = CXXUnit->getSourceManager();
ASTContext &Ctx = CXXUnit->getASTContext();
Modified: cfe/branches/Apple/whitney/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CXCursor.cpp?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CXCursor.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CXCursor.cpp Tue Nov 16 18:23:42 2010
@@ -45,13 +45,14 @@
return CXCursor_UnexposedAttr;
}
-CXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent, ASTUnit *TU) {
+CXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent,
+ CXTranslationUnit TU) {
assert(A && Parent && TU && "Invalid arguments!");
CXCursor C = { GetCursorKind(A), { Parent, (void*)A, TU } };
return C;
}
-CXCursor cxcursor::MakeCXCursor(Decl *D, ASTUnit *TU,
+CXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU,
bool FirstInDeclGroup) {
assert(D && TU && "Invalid arguments!");
CXCursor C = { getCursorKindForDecl(D),
@@ -60,7 +61,8 @@
return C;
}
-CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, ASTUnit *TU) {
+CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent,
+ CXTranslationUnit TU) {
assert(S && TU && "Invalid arguments!");
CXCursorKind K = CXCursor_NotImplemented;
@@ -200,7 +202,7 @@
CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(Super && TU && "Invalid arguments!");
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } };
@@ -217,7 +219,7 @@
CXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super,
SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(Super && TU && "Invalid arguments!");
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } };
@@ -234,7 +236,7 @@
CXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class,
SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
// 'Class' can be null for invalid code.
if (!Class)
return MakeCXCursorInvalid(CXCursor_InvalidCode);
@@ -253,7 +255,7 @@
}
CXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(Type && TU && "Invalid arguments!");
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } };
@@ -269,7 +271,8 @@
}
CXCursor cxcursor::MakeCursorTemplateRef(TemplateDecl *Template,
- SourceLocation Loc, ASTUnit *TU) {
+ SourceLocation Loc,
+ CXTranslationUnit TU) {
assert(Template && TU && "Invalid arguments!");
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
CXCursor C = { CXCursor_TemplateRef, { Template, RawLoc, TU } };
@@ -285,7 +288,7 @@
}
CXCursor cxcursor::MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU &&
"Invalid arguments!");
@@ -303,7 +306,7 @@
}
CXCursor cxcursor::MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(Field && TU && "Invalid arguments!");
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
@@ -319,7 +322,8 @@
reinterpret_cast<uintptr_t>(C.data[1])));
}
-CXCursor cxcursor::MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU){
+CXCursor cxcursor::MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B,
+ CXTranslationUnit TU){
CXCursor C = { CXCursor_CXXBaseSpecifier, { B, 0, TU } };
return C;
}
@@ -330,7 +334,7 @@
}
CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
CXCursor C = { CXCursor_PreprocessingDirective,
{ reinterpret_cast<void *>(Range.getBegin().getRawEncoding()),
reinterpret_cast<void *>(Range.getEnd().getRawEncoding()),
@@ -347,7 +351,8 @@
reinterpret_cast<uintptr_t> (C.data[1])));
}
-CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI, ASTUnit *TU) {
+CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI,
+ CXTranslationUnit TU) {
CXCursor C = { CXCursor_MacroDefinition, { MI, 0, TU } };
return C;
}
@@ -358,7 +363,7 @@
}
CXCursor cxcursor::MakeMacroInstantiationCursor(MacroInstantiation *MI,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } };
return C;
}
@@ -369,7 +374,7 @@
}
CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
CXCursor C = { CXCursor_InclusionDirective, { ID, 0, TU } };
return C;
}
@@ -380,7 +385,7 @@
}
CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(Label && TU && "Invalid arguments!");
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
@@ -397,7 +402,7 @@
}
CXCursor cxcursor::MakeCursorOverloadedDeclRef(OverloadExpr *E,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(E && TU && "Invalid arguments!");
OverloadedDeclRefStorage Storage(E);
void *RawLoc = reinterpret_cast<void *>(E->getNameLoc().getRawEncoding());
@@ -410,7 +415,7 @@
CXCursor cxcursor::MakeCursorOverloadedDeclRef(Decl *D,
SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(D && TU && "Invalid arguments!");
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
OverloadedDeclRefStorage Storage(D);
@@ -423,7 +428,7 @@
CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
SourceLocation Loc,
- ASTUnit *TU) {
+ CXTranslationUnit TU) {
assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!");
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate());
@@ -468,7 +473,12 @@
}
ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
- return static_cast<ASTUnit *>(Cursor.data[2]);
+ return static_cast<ASTUnit *>(static_cast<CXTranslationUnit>(Cursor.data[2])
+ ->TUData);
+}
+
+CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
+ return static_cast<CXTranslationUnit>(Cursor.data[2]);
}
bool cxcursor::operator==(CXCursor X, CXCursor Y) {
Modified: cfe/branches/Apple/whitney/tools/libclang/CXCursor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CXCursor.h?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CXCursor.h (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CXCursor.h Tue Nov 16 18:23:42 2010
@@ -44,16 +44,18 @@
namespace cxcursor {
-CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
-CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU,
+CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent,
+ CXTranslationUnit TU);
+CXCursor MakeCXCursor(clang::Decl *D, CXTranslationUnit TU,
bool FirstInDeclGroup = true);
-CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
+CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent,
+ CXTranslationUnit TU);
CXCursor MakeCXCursorInvalid(CXCursorKind K);
/// \brief Create an Objective-C superclass reference at the given location.
CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
SourceLocation Loc,
- ASTUnit *TU);
+ CXTranslationUnit TU);
/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
/// and optionally the location where the reference occurred.
@@ -62,7 +64,7 @@
/// \brief Create an Objective-C protocol reference at the given location.
CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
- ASTUnit *TU);
+ CXTranslationUnit TU);
/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
/// and optionally the location where the reference occurred.
@@ -71,7 +73,7 @@
/// \brief Create an Objective-C class reference at the given location.
CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
- ASTUnit *TU);
+ CXTranslationUnit TU);
/// \brief Unpack an ObjCClassRef cursor into the class it references
/// and optionally the location where the reference occurred.
@@ -79,7 +81,8 @@
getCursorObjCClassRef(CXCursor C);
/// \brief Create a type reference at the given location.
-CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
+CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc,
+ CXTranslationUnit TU);
/// \brief Unpack a TypeRef cursor into the class it references
/// and optionally the location where the reference occurred.
@@ -87,7 +90,7 @@
/// \brief Create a reference to a template at the given location.
CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc,
- ASTUnit *TU);
+ CXTranslationUnit TU);
/// \brief Unpack a TemplateRef cursor into the template it references and
/// the location where the reference occurred.
@@ -95,7 +98,8 @@
/// \brief Create a reference to a namespace or namespace alias at the given
/// location.
-CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, ASTUnit *TU);
+CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc,
+ CXTranslationUnit TU);
/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
/// it references and the location where the reference occurred.
@@ -103,62 +107,68 @@
/// \brief Create a reference to a field at the given location.
CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
- ASTUnit *TU);
+ CXTranslationUnit TU);
/// \brief Unpack a MemberRef cursor into the field it references and the
/// location where the reference occurred.
std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
/// \brief Create a CXX base specifier cursor.
-CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU);
+CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B,
+ CXTranslationUnit TU);
/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
/// \brief Create a preprocessing directive cursor.
-CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
+CXCursor MakePreprocessingDirectiveCursor(SourceRange Range,
+ CXTranslationUnit TU);
/// \brief Unpack a given preprocessing directive to retrieve its source range.
SourceRange getCursorPreprocessingDirective(CXCursor C);
/// \brief Create a macro definition cursor.
-CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
+CXCursor MakeMacroDefinitionCursor(MacroDefinition *, CXTranslationUnit TU);
/// \brief Unpack a given macro definition cursor to retrieve its
/// source range.
MacroDefinition *getCursorMacroDefinition(CXCursor C);
/// \brief Create a macro instantiation cursor.
-CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
+CXCursor MakeMacroInstantiationCursor(MacroInstantiation *,
+ CXTranslationUnit TU);
/// \brief Unpack a given macro instantiation cursor to retrieve its
/// source range.
MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
/// \brief Create an inclusion directive cursor.
-CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, ASTUnit *TU);
+CXCursor MakeInclusionDirectiveCursor(InclusionDirective *,
+ CXTranslationUnit TU);
/// \brief Unpack a given inclusion directive cursor to retrieve its
/// source range.
InclusionDirective *getCursorInclusionDirective(CXCursor C);
/// \brief Create a label reference at the given location.
-CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, ASTUnit *TU);
+CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
+ CXTranslationUnit TU);
/// \brief Unpack a label reference into the label statement it refers to and
/// the location of the reference.
std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
/// \brief Create a overloaded declaration reference cursor for an expression.
-CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, ASTUnit *TU);
+CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, CXTranslationUnit TU);
/// \brief Create a overloaded declaration reference cursor for a declaration.
CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location,
- ASTUnit *TU);
+ CXTranslationUnit TU);
/// \brief Create a overloaded declaration reference cursor for a template name.
CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
- SourceLocation Location, ASTUnit *TU);
+ SourceLocation Location,
+ CXTranslationUnit TU);
/// \brief Internal storage for an overloaded declaration reference cursor;
typedef llvm::PointerUnion3<OverloadExpr *, Decl *,
@@ -177,6 +187,7 @@
ASTContext &getCursorContext(CXCursor Cursor);
ASTUnit *getCursorASTUnit(CXCursor Cursor);
+CXTranslationUnit getCursorTU(CXCursor Cursor);
bool operator==(CXCursor X, CXCursor Y);
Modified: cfe/branches/Apple/whitney/tools/libclang/CXString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CXString.cpp?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CXString.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CXString.cpp Tue Nov 16 18:23:42 2010
@@ -16,20 +16,25 @@
#include "CXString.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang-c/Index.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/Support/ErrorHandling.h"
using namespace clang;
using namespace clang::cxstring;
-enum CXStringFlag { CXS_Unmanaged, CXS_Malloc };
+enum CXStringFlag { CXS_Unmanaged, CXS_Malloc, CXS_StringBuf };
+
+//===----------------------------------------------------------------------===//
+// Basic generation of CXStrings.
+//===----------------------------------------------------------------------===//
CXString cxstring::createCXString(const char *String, bool DupString){
CXString Str;
if (DupString) {
- Str.Spelling = strdup(String);
+ Str.data = strdup(String);
Str.private_flags = (unsigned) CXS_Malloc;
} else {
- Str.Spelling = String;
+ Str.data = (void*)String;
Str.private_flags = (unsigned) CXS_Unmanaged;
}
return Str;
@@ -41,27 +46,84 @@
char *Spelling = (char *)malloc(String.size() + 1);
memmove(Spelling, String.data(), String.size());
Spelling[String.size()] = 0;
- Result.Spelling = Spelling;
+ Result.data = Spelling;
Result.private_flags = (unsigned) CXS_Malloc;
} else {
- Result.Spelling = String.data();
+ Result.data = (void*) String.data();
Result.private_flags = (unsigned) CXS_Unmanaged;
}
return Result;
}
+CXString cxstring::createCXString(CXStringBuf *buf) {
+ CXString Str;
+ Str.data = buf;
+ Str.private_flags = (unsigned) CXS_StringBuf;
+ return Str;
+}
+
+
+//===----------------------------------------------------------------------===//
+// String pools.
+//===----------------------------------------------------------------------===//
+
+
+typedef std::vector<CXStringBuf *> CXStringPool;
+
+void *cxstring::createCXStringPool() {
+ return new CXStringPool();
+}
+
+void cxstring::disposeCXStringPool(void *p) {
+ CXStringPool *pool = static_cast<CXStringPool*>(p);
+ if (pool) {
+ for (CXStringPool::iterator I = pool->begin(), E = pool->end();
+ I != E; ++I) {
+ delete *I;
+ }
+ delete pool;
+ }
+}
+
+CXStringBuf *cxstring::getCXStringBuf(CXTranslationUnit TU) {
+ CXStringPool *pool = static_cast<CXStringPool*>(TU->StringPool);
+ if (pool->empty())
+ return new CXStringBuf(TU);
+ CXStringBuf *buf = pool->back();
+ buf->Data.clear();
+ pool->pop_back();
+ return buf;
+}
+
+void cxstring::disposeCXStringBuf(CXStringBuf *buf) {
+ if (buf)
+ static_cast<CXStringPool*>(buf->TU->StringPool)->push_back(buf);
+}
+
//===----------------------------------------------------------------------===//
// libClang public APIs.
//===----------------------------------------------------------------------===//
extern "C" {
const char *clang_getCString(CXString string) {
- return string.Spelling;
+ if (string.private_flags == (unsigned) CXS_StringBuf) {
+ return ((CXStringBuf*)string.data)->Data.data();
+ }
+ return (const char*) string.data;
}
void clang_disposeString(CXString string) {
- if (string.private_flags == CXS_Malloc && string.Spelling)
- free((void*)string.Spelling);
+ switch ((CXStringFlag) string.private_flags) {
+ case CXS_Unmanaged:
+ break;
+ case CXS_Malloc:
+ if (string.data)
+ free((void*)string.data);
+ break;
+ case CXS_StringBuf:
+ disposeCXStringBuf((CXStringBuf *) string.data);
+ break;
+ }
}
} // end: extern "C"
Modified: cfe/branches/Apple/whitney/tools/libclang/CXString.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CXString.h?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CXString.h (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CXString.h Tue Nov 16 18:23:42 2010
@@ -16,15 +16,35 @@
#include "clang-c/Index.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallString.h"
namespace clang {
namespace cxstring {
+
+struct CXStringBuf {
+ llvm::SmallString<128> Data;
+ CXTranslationUnit TU;
+ CXStringBuf(CXTranslationUnit tu) : TU(tu) {}
+};
/// \brief Create a CXString object from a C string.
CXString createCXString(const char *String, bool DupString = false);
-/// \brief Create a CXString ojbect from a StringRef.
-CXString createCXString(llvm::StringRef String, bool DupString = true);
+/// \brief Create a CXString object from a StringRef.
+CXString createCXString(llvm::StringRef String, bool DupString = true);
+
+/// \brief Create a CXString object that is backed by a string buffer.
+CXString createCXString(CXStringBuf *buf);
+
+/// \brief Create an opaque string pool used for fast geneneration of strings.
+void *createCXStringPool();
+
+/// \brief Dispose of a string pool.
+void disposeCXStringPool(void *pool);
+
+CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
+
+void disposeCXStringBuf(CXStringBuf *buf);
}
}
Modified: cfe/branches/Apple/whitney/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CXType.cpp?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CXType.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CXType.cpp Tue Nov 16 18:23:42 2010
@@ -89,7 +89,7 @@
}
-CXType cxtype::MakeCXType(QualType T, ASTUnit *TU) {
+CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
CXTypeKind TK = GetTypeKind(T);
CXType CT = { TK, { TK == CXType_Invalid ? 0 : T.getAsOpaquePtr(), TU }};
return CT;
@@ -101,8 +101,8 @@
return QualType::getFromOpaquePtr(CT.data[0]);
}
-static inline ASTUnit* GetASTU(CXType CT) {
- return static_cast<ASTUnit*>(CT.data[1]);
+static inline CXTranslationUnit GetTU(CXType CT) {
+ return static_cast<CXTranslationUnit>(CT.data[1]);
}
extern "C" {
@@ -110,27 +110,26 @@
CXType clang_getCursorType(CXCursor C) {
using namespace cxcursor;
- ASTUnit *AU = cxcursor::getCursorASTUnit(C);
-
+ CXTranslationUnit TU = cxcursor::getCursorTU(C);
if (clang_isExpression(C.kind)) {
QualType T = cxcursor::getCursorExpr(C)->getType();
- return MakeCXType(T, AU);
+ return MakeCXType(T, TU);
}
if (clang_isDeclaration(C.kind)) {
Decl *D = cxcursor::getCursorDecl(C);
if (TypeDecl *TD = dyn_cast<TypeDecl>(D))
- return MakeCXType(QualType(TD->getTypeForDecl(), 0), AU);
+ return MakeCXType(QualType(TD->getTypeForDecl(), 0), TU);
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D))
- return MakeCXType(QualType(ID->getTypeForDecl(), 0), AU);
+ return MakeCXType(QualType(ID->getTypeForDecl(), 0), TU);
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
- return MakeCXType(VD->getType(), AU);
+ return MakeCXType(VD->getType(), TU);
if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
- return MakeCXType(PD->getType(), AU);
+ return MakeCXType(PD->getType(), TU);
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
- return MakeCXType(FD->getType(), AU);
- return MakeCXType(QualType(), AU);
+ return MakeCXType(FD->getType(), TU);
+ return MakeCXType(QualType(), TU);
}
if (clang_isReference(C.kind)) {
@@ -139,21 +138,21 @@
return MakeCXType(
QualType(getCursorObjCSuperClassRef(C).first->getTypeForDecl(),
0),
- AU);
+ TU);
case CXCursor_ObjCClassRef:
return MakeCXType(
QualType(getCursorObjCClassRef(C).first->getTypeForDecl(),
0),
- AU);
+ TU);
case CXCursor_TypeRef:
return MakeCXType(QualType(getCursorTypeRef(C).first->getTypeForDecl(),
0),
- AU);
+ TU);
case CXCursor_CXXBaseSpecifier:
- return cxtype::MakeCXType(getCursorCXXBaseSpecifier(C)->getType(), AU);
+ return cxtype::MakeCXType(getCursorCXXBaseSpecifier(C)->getType(), TU);
case CXCursor_ObjCProtocolRef:
case CXCursor_TemplateRef:
@@ -164,10 +163,10 @@
break;
}
- return MakeCXType(QualType(), AU);
+ return MakeCXType(QualType(), TU);
}
- return MakeCXType(QualType(), AU);
+ return MakeCXType(QualType(), TU);
}
CXType clang_getCanonicalType(CXType CT) {
@@ -175,12 +174,13 @@
return CT;
QualType T = GetQualType(CT);
+ CXTranslationUnit TU = GetTU(CT);
if (T.isNull())
- return MakeCXType(QualType(), GetASTU(CT));
+ return MakeCXType(QualType(), GetTU(CT));
- ASTUnit *AU = GetASTU(CT);
- return MakeCXType(AU->getASTContext().getCanonicalType(T), AU);
+ ASTUnit *AU = static_cast<ASTUnit*>(TU->TUData);
+ return MakeCXType(AU->getASTContext().getCanonicalType(T), TU);
}
CXType clang_getPointeeType(CXType CT) {
@@ -188,7 +188,7 @@
Type *TP = T.getTypePtr();
if (!TP)
- return MakeCXType(QualType(), GetASTU(CT));
+ return MakeCXType(QualType(), GetTU(CT));
switch (TP->getTypeClass()) {
case Type::Pointer:
@@ -208,7 +208,7 @@
T = QualType();
break;
}
- return MakeCXType(T, GetASTU(CT));
+ return MakeCXType(T, GetTU(CT));
}
CXCursor clang_getTypeDeclaration(CXType CT) {
@@ -263,7 +263,7 @@
if (!D)
return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
- return cxcursor::MakeCXCursor(D, GetASTU(CT));
+ return cxcursor::MakeCXCursor(D, GetTU(CT));
}
CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
@@ -324,24 +324,24 @@
CXType clang_getResultType(CXType X) {
QualType T = GetQualType(X);
if (!T.getTypePtr())
- return MakeCXType(QualType(), GetASTU(X));
+ return MakeCXType(QualType(), GetTU(X));
if (const FunctionType *FD = T->getAs<FunctionType>())
- return MakeCXType(FD->getResultType(), GetASTU(X));
+ return MakeCXType(FD->getResultType(), GetTU(X));
- return MakeCXType(QualType(), GetASTU(X));
+ return MakeCXType(QualType(), GetTU(X));
}
CXType clang_getCursorResultType(CXCursor C) {
if (clang_isDeclaration(C.kind)) {
Decl *D = cxcursor::getCursorDecl(C);
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
- return MakeCXType(MD->getResultType(), cxcursor::getCursorASTUnit(C));
+ return MakeCXType(MD->getResultType(), cxcursor::getCursorTU(C));
return clang_getResultType(clang_getCursorType(C));
}
- return MakeCXType(QualType(), cxcursor::getCursorASTUnit(C));
+ return MakeCXType(QualType(), cxcursor::getCursorTU(C));
}
unsigned clang_isPODType(CXType X) {
Modified: cfe/branches/Apple/whitney/tools/libclang/CXType.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CXType.h?rev=119419&r1=119418&r2=119419&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CXType.h (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CXType.h Tue Nov 16 18:23:42 2010
@@ -23,7 +23,7 @@
namespace cxtype {
-CXType MakeCXType(QualType T, ASTUnit *TU);
+CXType MakeCXType(QualType T, CXTranslationUnit TU);
}} // end namespace clang::cxtype
#endif
More information about the llvm-branch-commits
mailing list