From f441baf6ddf7eb2b4dbe3a645ca063a33f63f9a5 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 17 Feb 2010 00:41:40 +0000 Subject: [PATCH] Remove trailing spaces. llvm-svn: 96427 --- clang/tools/CIndex/CIndex.cpp | 424 +++++++++++++++++----------------- 1 file changed, 212 insertions(+), 212 deletions(-) diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp index eb30ba69255b..d24bcf64dffe 100644 --- a/clang/tools/CIndex/CIndex.cpp +++ b/clang/tools/CIndex/CIndex.cpp @@ -54,7 +54,7 @@ static const char *agg_crashtracer_strings[NUM_CRASH_STRINGS] = { 0 }; static unsigned SetCrashTracerInfo(const char *str, llvm::SmallString<1024> &AggStr) { - + unsigned slot = 0; while (crashtracer_strings[slot]) { if (++slot == NUM_CRASH_STRINGS) @@ -69,7 +69,7 @@ static unsigned SetCrashTracerInfo(const char *str, // of this function. Race conditions can still cause this goal // to not be achieved. { - llvm::raw_svector_ostream Out(AggStr); + llvm::raw_svector_ostream Out(AggStr); for (unsigned i = 0; i < NUM_CRASH_STRINGS; ++i) if (crashtracer_strings[i]) Out << crashtracer_strings[i] << '\n'; } @@ -80,7 +80,7 @@ static unsigned SetCrashTracerInfo(const char *str, static void ResetCrashTracerInfo(unsigned slot) { unsigned max_slot = 0; unsigned max_value = 0; - + crashtracer_strings[slot] = agg_crashtracer_strings[slot] = 0; for (unsigned i = 0 ; i < NUM_CRASH_STRINGS; ++i) @@ -112,7 +112,7 @@ public: crashtracerSlot = SetCrashTracerInfo(CrashString.c_str(), AggregateString); } - + ~ArgsCrashTracerInfo() { ResetCrashTracerInfo(crashtracerSlot); } @@ -125,18 +125,18 @@ public: enum RangeComparisonResult { /// \brief Either the ranges overlap or one of the ranges is invalid. RangeOverlap, - + /// \brief The first range ends before the second range starts. RangeBefore, - + /// \brief The first range starts after the second range ends. RangeAfter }; -/// \brief Compare two source ranges to determine their relative position in +/// \brief Compare two source ranges to determine their relative position in /// the translation unit. -static RangeComparisonResult RangeCompare(SourceManager &SM, - SourceRange R1, +static RangeComparisonResult RangeCompare(SourceManager &SM, + SourceRange R1, SourceRange R2) { assert(R1.isValid() && "First range is invalid?"); assert(R2.isValid() && "Second range is invalid?"); @@ -155,7 +155,7 @@ static RangeComparisonResult RangeCompare(SourceManager &SM, /// start of the token at the end. However, for external clients it is more /// useful to have a CXSourceRange be a proper half-open interval. This routine /// does the appropriate translation. -CXSourceRange cxloc::translateSourceRange(const SourceManager &SM, +CXSourceRange cxloc::translateSourceRange(const SourceManager &SM, const LangOptions &LangOpts, SourceRange R) { // FIXME: This is largely copy-paste from @@ -197,7 +197,7 @@ CXSourceRange cxloc::translateSourceRange(const SourceManager &SM, //===----------------------------------------------------------------------===// namespace { - + // Cursor visitor. class CursorVisitor : public DeclVisitor, public TypeLocVisitor, @@ -205,20 +205,20 @@ class CursorVisitor : public DeclVisitor, { /// \brief The translation unit we are traversing. ASTUnit *TU; - + /// \brief The parent cursor whose children we are traversing. CXCursor Parent; - + /// \brief The declaration that serves at the parent of any statement or /// expression nodes. Decl *StmtParent; - + /// \brief The visitor function. CXCursorVisitor Visitor; - + /// \brief The opaque client data, to be passed along to the visitor. CXClientData ClientData; - + // 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. @@ -227,22 +227,22 @@ class CursorVisitor : public DeclVisitor, /// \brief When valid, a source range to which the cursor should restrict /// its search. SourceRange RegionOfInterest; - + using DeclVisitor::Visit; using TypeLocVisitor::Visit; using StmtVisitor::Visit; - - /// \brief Determine whether this particular source range comes before, comes - /// after, or overlaps the region of interest. + + /// \brief Determine whether this particular source range comes before, comes + /// after, or overlaps the region of interest. /// /// \param R a half-open source range retrieved from the abstract syntax tree. - RangeComparisonResult CompareRegionOfInterest(SourceRange R); - + RangeComparisonResult CompareRegionOfInterest(SourceRange R); + public: - CursorVisitor(ASTUnit *TU, CXCursorVisitor Visitor, CXClientData ClientData, - unsigned MaxPCHLevel, + CursorVisitor(ASTUnit *TU, CXCursorVisitor Visitor, CXClientData ClientData, + unsigned MaxPCHLevel, SourceRange RegionOfInterest = SourceRange()) - : TU(TU), Visitor(Visitor), ClientData(ClientData), + : TU(TU), Visitor(Visitor), ClientData(ClientData), MaxPCHLevel(MaxPCHLevel), RegionOfInterest(RegionOfInterest) { Parent.kind = CXCursor_NoDeclFound; @@ -251,10 +251,10 @@ public: Parent.data[2] = 0; StmtParent = 0; } - + bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false); bool VisitChildren(CXCursor Parent); - + // Declaration visitors bool VisitDeclContext(DeclContext *DC); bool VisitTranslationUnitDecl(TranslationUnitDecl *D); @@ -300,7 +300,7 @@ public: // implemented bool VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL); bool VisitTypeOfTypeLoc(TypeOfTypeLoc TL); - + // Statement visitors bool VisitStmt(Stmt *S); bool VisitDeclStmt(DeclStmt *S); @@ -309,13 +309,13 @@ public: bool VisitSwitchStmt(SwitchStmt *S); bool VisitWhileStmt(WhileStmt *S); bool VisitForStmt(ForStmt *S); - + // Expression visitors bool VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); bool VisitExplicitCastExpr(ExplicitCastExpr *E); bool VisitCompoundLiteralExpr(CompoundLiteralExpr *E); }; - + } // end anonymous namespace RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) { @@ -335,7 +335,7 @@ RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) { bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) { if (clang_isInvalid(Cursor.kind)) return false; - + if (clang_isDeclaration(Cursor.kind)) { Decl *D = getCursorDecl(Cursor); assert(D && "Invalid declaration cursor"); @@ -354,7 +354,7 @@ bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) { if (Range.isInvalid() || CompareRegionOfInterest(Range)) return false; } - + switch (Visitor(Cursor, Parent, ClientData)) { case CXChildVisit_Break: return true; @@ -373,13 +373,13 @@ bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) { /// /// \returns true if the visitation should be aborted, false if it /// should continue. -bool CursorVisitor::VisitChildren(CXCursor Cursor) { +bool CursorVisitor::VisitChildren(CXCursor Cursor) { if (clang_isReference(Cursor.kind)) { // By definition, references have no children. return false; } - - // Set the Parent field to Cursor, then back to its old value once we're + + // Set the Parent field to Cursor, then back to its old value once we're // done. class SetParentRAII { CXCursor &Parent; @@ -388,31 +388,31 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) { public: SetParentRAII(CXCursor &Parent, Decl *&StmtParent, CXCursor NewParent) - : Parent(Parent), StmtParent(StmtParent), OldParent(Parent) + : 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); } } SetParent(Parent, StmtParent, Cursor); - + if (clang_isDeclaration(Cursor.kind)) { Decl *D = getCursorDecl(Cursor); assert(D && "Invalid declaration cursor"); return Visit(D); } - + if (clang_isStatement(Cursor.kind)) return Visit(getCursorStmt(Cursor)); if (clang_isExpression(Cursor.kind)) return Visit(getCursorExpr(Cursor)); - + if (clang_isTranslationUnit(Cursor.kind)) { ASTUnit *CXXUnit = getCursorASTUnit(Cursor); if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() && @@ -427,10 +427,10 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) { return VisitDeclContext( CXXUnit->getASTContext().getTranslationUnitDecl()); } - + return false; } - + // Nothing to visit at the moment. return false; } @@ -450,21 +450,21 @@ bool CursorVisitor::VisitDeclContext(DeclContext *DC) { case RangeBefore: // This declaration comes before the region of interest; skip it. continue; - + case RangeAfter: // This declaration comes after the region of interest; we're done. return false; - + case RangeOverlap: // This declaration overlaps the region of interest; visit it. break; - } + } } - + if (Visit(Cursor, true)) return true; } - + return false; } @@ -476,7 +476,7 @@ bool CursorVisitor::VisitTranslationUnitDecl(TranslationUnitDecl *D) { bool CursorVisitor::VisitTypedefDecl(TypedefDecl *D) { if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo()) return Visit(TSInfo->getTypeLoc()); - + return false; } @@ -505,45 +505,45 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) { if (ND->isThisDeclarationADefinition() && Visit(MakeCXCursor(ND->getBody(), StmtParent, TU))) return true; - + return false; } bool CursorVisitor::VisitFieldDecl(FieldDecl *D) { if (VisitDeclaratorDecl(D)) return true; - + if (Expr *BitWidth = D->getBitWidth()) return Visit(MakeCXCursor(BitWidth, StmtParent, TU)); - + return false; } bool CursorVisitor::VisitVarDecl(VarDecl *D) { if (VisitDeclaratorDecl(D)) return true; - + if (Expr *Init = D->getInit()) return Visit(MakeCXCursor(Init, StmtParent, TU)); - + return false; } bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) { // FIXME: We really need a TypeLoc covering Objective-C method declarations. - // At the moment, we don't have information about locations in the return + // At the moment, we don't have information about locations in the return // type. - for (ObjCMethodDecl::param_iterator P = ND->param_begin(), + for (ObjCMethodDecl::param_iterator P = ND->param_begin(), PEnd = ND->param_end(); P != PEnd; ++P) { if (Visit(MakeCXCursor(*P, TU))) return true; } - + if (ND->isThisDeclarationADefinition() && Visit(MakeCXCursor(ND->getBody(), StmtParent, TU))) return true; - + return false; } @@ -555,13 +555,13 @@ bool CursorVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) { if (Visit(MakeCursorObjCClassRef(ND->getClassInterface(), ND->getLocation(), TU))) return true; - + ObjCCategoryDecl::protocol_loc_iterator PL = ND->protocol_loc_begin(); for (ObjCCategoryDecl::protocol_iterator I = ND->protocol_begin(), E = ND->protocol_end(); I != E; ++I, ++PL) if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) return true; - + return VisitObjCContainerDecl(ND); } @@ -571,7 +571,7 @@ bool CursorVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { E = PID->protocol_end(); I != E; ++I, ++PL) if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) return true; - + return VisitObjCContainerDecl(PID); } @@ -579,16 +579,16 @@ bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { // Issue callbacks for super class. if (D->getSuperClass() && Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(), - D->getSuperClassLoc(), + D->getSuperClassLoc(), TU))) return true; - + ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(); for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I, ++PL) if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) return true; - + return VisitObjCContainerDecl(D); } @@ -597,10 +597,10 @@ bool CursorVisitor::VisitObjCImplDecl(ObjCImplDecl *D) { } bool CursorVisitor::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { - if (Visit(MakeCursorObjCClassRef(D->getCategoryDecl()->getClassInterface(), + if (Visit(MakeCursorObjCClassRef(D->getCategoryDecl()->getClassInterface(), D->getLocation(), TU))) return true; - + return VisitObjCImplDecl(D); } @@ -610,11 +610,11 @@ bool CursorVisitor::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { // FIXME: No source location information! if (D->getSuperClass() && Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(), - D->getSuperClassLoc(), + D->getSuperClassLoc(), TU))) return true; #endif - + return VisitObjCImplDecl(D); } @@ -625,15 +625,15 @@ bool CursorVisitor::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) { I != E; ++I, ++PL) if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) return true; - - return false; + + return false; } 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; - + return false; } @@ -663,8 +663,8 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { case BuiltinType::Long: case BuiltinType::LongLong: case BuiltinType::Int128: - case BuiltinType::Float: - case BuiltinType::Double: + case BuiltinType::Float: + case BuiltinType::Double: case BuiltinType::LongDouble: case BuiltinType::NullPtr: case BuiltinType::Overload: @@ -689,7 +689,7 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { if (!VisitType.isNull()) { if (const TypedefType *Typedef = VisitType->getAs()) - return Visit(MakeCursorTypeRef(Typedef->getDecl(), TL.getBuiltinLoc(), + return Visit(MakeCursorTypeRef(Typedef->getDecl(), TL.getBuiltinLoc(), TU)); } @@ -727,13 +727,13 @@ bool CursorVisitor::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { if (TL.hasProtocolsAsWritten()) { for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) { - if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), + if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I), TU))) return true; } } - + return false; } @@ -750,11 +750,11 @@ bool CursorVisitor::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { } bool CursorVisitor::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { - return Visit(TL.getPointeeLoc()); + return Visit(TL.getPointeeLoc()); } bool CursorVisitor::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { - return Visit(TL.getPointeeLoc()); + return Visit(TL.getPointeeLoc()); } bool CursorVisitor::VisitFunctionTypeLoc(FunctionTypeLoc TL) { @@ -795,7 +795,7 @@ bool CursorVisitor::VisitStmt(Stmt *S) { if (*Child && Visit(MakeCXCursor(*Child, StmtParent, TU))) return true; } - + return false; } @@ -805,7 +805,7 @@ bool CursorVisitor::VisitDeclStmt(DeclStmt *S) { if (*D && Visit(MakeCXCursor(*D, TU))) return true; } - + return false; } @@ -813,8 +813,8 @@ bool CursorVisitor::VisitIfStmt(IfStmt *S) { if (VarDecl *Var = S->getConditionVariable()) { if (Visit(MakeCXCursor(Var, TU))) return true; - } - + } + if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU))) return true; if (S->getThen() && Visit(MakeCXCursor(S->getThen(), StmtParent, TU))) @@ -829,13 +829,13 @@ bool CursorVisitor::VisitSwitchStmt(SwitchStmt *S) { if (VarDecl *Var = S->getConditionVariable()) { if (Visit(MakeCXCursor(Var, TU))) return true; - } - + } + if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU))) return true; if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU))) return true; - + return false; } @@ -843,8 +843,8 @@ bool CursorVisitor::VisitWhileStmt(WhileStmt *S) { if (VarDecl *Var = S->getConditionVariable()) { if (Visit(MakeCXCursor(Var, TU))) return true; - } - + } + if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU))) return true; if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU))) @@ -859,15 +859,15 @@ bool CursorVisitor::VisitForStmt(ForStmt *S) { if (VarDecl *Var = S->getConditionVariable()) { if (Visit(MakeCXCursor(Var, TU))) return true; - } - + } + if (S->getCond() && Visit(MakeCXCursor(S->getCond(), StmtParent, TU))) return true; if (S->getInc() && Visit(MakeCXCursor(S->getInc(), StmtParent, TU))) return true; if (S->getBody() && Visit(MakeCXCursor(S->getBody(), StmtParent, TU))) return true; - + return false; } @@ -875,10 +875,10 @@ bool CursorVisitor::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { if (E->isArgumentType()) { if (TypeSourceInfo *TSInfo = E->getArgumentTypeInfo()) return Visit(TSInfo->getTypeLoc()); - + return false; } - + return VisitExpr(E); } @@ -886,7 +886,7 @@ bool CursorVisitor::VisitExplicitCastExpr(ExplicitCastExpr *E) { if (TypeSourceInfo *TSInfo = E->getTypeInfoAsWritten()) if (Visit(TSInfo->getTypeLoc())) return true; - + return VisitCastExpr(E); } @@ -894,7 +894,7 @@ bool CursorVisitor::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { if (TypeSourceInfo *TSInfo = E->getTypeSourceInfo()) if (Visit(TSInfo->getTypeLoc())) return true; - + return VisitExpr(E); } @@ -924,7 +924,7 @@ CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, CXClientData diag_client_data) { if (!CIdx) return 0; - + CIndexer *CXXIdx = static_cast(CIdx); // Configure the diagnostics. @@ -933,7 +933,7 @@ CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, Diags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0)); CIndexDiagnosticClient DiagClient(diag_callback, diag_client_data); Diags->setClient(&DiagClient); - + return ASTUnit::LoadFromPCHFile(ast_filename, *Diags, CXXIdx->getOnlyLocalDecls()); } @@ -949,7 +949,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, CXClientData diag_client_data) { if (!CIdx) return 0; - + CIndexer *CXXIdx = static_cast(CIdx); // Configure the diagnostics. @@ -958,17 +958,17 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, Diags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0)); CIndexDiagnosticClient DiagClient(diag_callback, diag_client_data); Diags->setClient(&DiagClient); - + llvm::SmallVector RemappedFiles; for (unsigned I = 0; I != num_unsaved_files; ++I) { - const llvm::MemoryBuffer *Buffer + const llvm::MemoryBuffer *Buffer = llvm::MemoryBuffer::getMemBuffer(unsaved_files[I].Contents, unsaved_files[I].Contents + unsaved_files[I].Length, unsaved_files[I].Filename); RemappedFiles.push_back(std::make_pair(unsaved_files[I].Filename, Buffer)); } - + if (!CXXIdx->getUseExternalASTGeneration()) { llvm::SmallVector Args; @@ -981,19 +981,19 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, command_line_args + num_command_line_args); unsigned NumErrors = Diags->getNumErrors(); - + #ifdef USE_CRASHTRACER ArgsCrashTracerInfo ACTI(Args); #endif - + llvm::OwningPtr Unit( ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(), - *Diags, + *Diags, CXXIdx->getClangResourcesPath(), CXXIdx->getOnlyLocalDecls(), RemappedFiles.data(), RemappedFiles.size())); - + // FIXME: Until we have broader testing, just drop the entire AST if we // encountered an error. if (NumErrors != Diags->getNumErrors()) @@ -1028,12 +1028,12 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, std::vector RemapArgs; if (RemapFiles(num_unsaved_files, unsaved_files, RemapArgs, TemporaryFiles)) return 0; - + // The pointers into the elements of RemapArgs are stable because we // won't be adding anything to RemapArgs after this point. for (unsigned i = 0, e = RemapArgs.size(); i != e; ++i) argv.push_back(RemapArgs[i].c_str()); - + // Process the compiler options, stripping off '-o', '-c', '-fsyntax-only'. for (int i = 0; i < num_command_line_args; ++i) if (const char *arg = command_line_args[i]) { @@ -1079,7 +1079,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, if (*I) AllArgs += *I; } - + Diags->Report(diag::err_fe_clang) << AllArgs << ErrMsg; } @@ -1091,16 +1091,16 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, RemappedFiles.size()); if (ATU) ATU->unlinkTemporaryFile(); - + // FIXME: Currently we don't report diagnostics on invalid ASTs. if (ATU) - ReportSerializedDiagnostics(DiagnosticsFile, *Diags, + ReportSerializedDiagnostics(DiagnosticsFile, *Diags, num_unsaved_files, unsaved_files, ATU->getASTContext().getLangOptions()); for (unsigned i = 0, e = TemporaryFiles.size(); i != e; ++i) TemporaryFiles[i].eraseFromDisk(); - + return ATU; } @@ -1112,7 +1112,7 @@ void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) { CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) { if (!CTUnit) return createCXString(""); - + ASTUnit *CXXUnit = static_cast(CTUnit); return createCXString(CXXUnit->getOriginalSourceFileName(), true); } @@ -1146,13 +1146,13 @@ CXSourceLocation clang_getLocation(CXTranslationUnit tu, unsigned column) { if (!tu) return clang_getNullLocation(); - + ASTUnit *CXXUnit = static_cast(tu); SourceLocation SLoc = CXXUnit->getSourceManager().getLocation( - static_cast(file), + static_cast(file), line, column); - + return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc); } @@ -1165,8 +1165,8 @@ CXSourceRange clang_getRange(CXSourceLocation begin, CXSourceLocation end) { if (begin.ptr_data[0] != end.ptr_data[0] || begin.ptr_data[1] != end.ptr_data[1]) return clang_getNullRange(); - - CXSourceRange Result = { { begin.ptr_data[0], begin.ptr_data[1] }, + + CXSourceRange Result = { { begin.ptr_data[0], begin.ptr_data[1] }, begin.int_data, end.int_data }; return Result; } @@ -1205,7 +1205,7 @@ void clang_getInstantiationLocation(CXSourceLocation location, } CXSourceLocation clang_getRangeStart(CXSourceRange range) { - CXSourceLocation Result = { { range.ptr_data[0], range.ptr_data[1] }, + CXSourceLocation Result = { { range.ptr_data[0], range.ptr_data[1] }, range.begin_int_data }; return Result; } @@ -1226,7 +1226,7 @@ extern "C" { CXString clang_getFileName(CXFile SFile) { if (!SFile) return createCXString(NULL); - + FileEntry *FEnt = static_cast(SFile); return createCXString(FEnt->getName()); } @@ -1234,22 +1234,22 @@ CXString clang_getFileName(CXFile SFile) { time_t clang_getFileTime(CXFile SFile) { if (!SFile) return 0; - + FileEntry *FEnt = static_cast(SFile); return FEnt->getModificationTime(); } - + CXFile clang_getFile(CXTranslationUnit tu, const char *file_name) { if (!tu) return 0; - + ASTUnit *CXXUnit = static_cast(tu); - + FileManager &FMgr = CXXUnit->getFileManager(); const FileEntry *File = FMgr.getFile(file_name, file_name+strlen(file_name)); return const_cast(File); } - + } // end: extern "C" //===----------------------------------------------------------------------===// @@ -1263,14 +1263,14 @@ static Decl *getDeclFromExpr(Stmt *E) { return ME->getMemberDecl(); if (ObjCIvarRefExpr *RE = dyn_cast(E)) return RE->getDecl(); - + if (CallExpr *CE = dyn_cast(E)) return getDeclFromExpr(CE->getCallee()); if (CastExpr *CE = dyn_cast(E)) return getDeclFromExpr(CE->getSubExpr()); if (ObjCMessageExpr *OME = dyn_cast(E)) return OME->getMethodDecl(); - + return 0; } @@ -1287,23 +1287,23 @@ static SourceLocation getLocationFromExpr(Expr *E) { } extern "C" { - -unsigned clang_visitChildren(CXCursor parent, + +unsigned clang_visitChildren(CXCursor parent, CXCursorVisitor visitor, CXClientData client_data) { ASTUnit *CXXUnit = getCursorASTUnit(parent); unsigned PCHLevel = Decl::MaxPCHLevel; - + // Set the PCHLevel to filter out unwanted decls if requested. if (CXXUnit->getOnlyLocalDecls()) { PCHLevel = 0; - + // If the main input was an AST, bump the level. if (CXXUnit->isMainFileAST()) ++PCHLevel; } - + CursorVisitor CursorVis(CXXUnit, visitor, client_data, PCHLevel); return CursorVis.VisitChildren(parent); } @@ -1312,22 +1312,22 @@ static CXString getDeclSpelling(Decl *D) { NamedDecl *ND = dyn_cast_or_null(D); if (!ND) return createCXString(""); - + if (ObjCMethodDecl *OMD = dyn_cast(ND)) return createCXString(OMD->getSelector().getAsString()); - + if (ObjCCategoryImplDecl *CIMP = dyn_cast(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. return createCXString(CIMP->getIdentifier()->getNameStart()); - + if (ND->getIdentifier()) return createCXString(ND->getIdentifier()->getNameStart()); - + return createCXString(""); } - + CXString clang_getCursorSpelling(CXCursor C) { if (clang_isTranslationUnit(C.kind)) return clang_getTranslationUnitSpelling(C.data[2]); @@ -1518,29 +1518,29 @@ CXCursorKind clang_getCursorKind(CXCursor C) { CXSourceLocation clang_getCursorLocation(CXCursor C) { if (clang_isReference(C.kind)) { switch (C.kind) { - case CXCursor_ObjCSuperClassRef: { + case CXCursor_ObjCSuperClassRef: { std::pair P = getCursorObjCSuperClassRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } - case CXCursor_ObjCProtocolRef: { + case CXCursor_ObjCProtocolRef: { std::pair P = getCursorObjCProtocolRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } - case CXCursor_ObjCClassRef: { + case CXCursor_ObjCClassRef: { std::pair P = getCursorObjCClassRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } - case CXCursor_TypeRef: { + case CXCursor_TypeRef: { std::pair P = getCursorTypeRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } - + default: // FIXME: Need a way to enumerate all non-reference cases. llvm_unreachable("Missed a reference kind"); @@ -1548,7 +1548,7 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) { } if (clang_isExpression(C.kind)) - return cxloc::translateSourceLocation(getCursorContext(C), + return cxloc::translateSourceLocation(getCursorContext(C), getLocationFromExpr(getCursorExpr(C))); if (!getCursorDecl(C)) @@ -1564,30 +1564,30 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) { CXSourceRange clang_getCursorExtent(CXCursor C) { if (clang_isReference(C.kind)) { switch (C.kind) { - case CXCursor_ObjCSuperClassRef: { + case CXCursor_ObjCSuperClassRef: { std::pair P = getCursorObjCSuperClassRef(C); return cxloc::translateSourceRange(P.first->getASTContext(), P.second); } - - case CXCursor_ObjCProtocolRef: { + + case CXCursor_ObjCProtocolRef: { std::pair P = getCursorObjCProtocolRef(C); return cxloc::translateSourceRange(P.first->getASTContext(), P.second); } - - case CXCursor_ObjCClassRef: { + + case CXCursor_ObjCClassRef: { std::pair P = getCursorObjCClassRef(C); - + return cxloc::translateSourceRange(P.first->getASTContext(), P.second); } - case CXCursor_TypeRef: { + case CXCursor_TypeRef: { std::pair P = getCursorTypeRef(C); return cxloc::translateSourceRange(P.first->getASTContext(), P.second); } - + default: // FIXME: Need a way to enumerate all non-reference cases. llvm_unreachable("Missed a reference kind"); @@ -1595,16 +1595,16 @@ CXSourceRange clang_getCursorExtent(CXCursor C) { } if (clang_isExpression(C.kind)) - return cxloc::translateSourceRange(getCursorContext(C), + return cxloc::translateSourceRange(getCursorContext(C), getCursorExpr(C)->getSourceRange()); if (clang_isStatement(C.kind)) - return cxloc::translateSourceRange(getCursorContext(C), + return cxloc::translateSourceRange(getCursorContext(C), getCursorStmt(C)->getSourceRange()); - + if (!getCursorDecl(C)) return clang_getNullRange(); - + Decl *D = getCursorDecl(C); return cxloc::translateSourceRange(D->getASTContext(), D->getSourceRange()); } @@ -1612,11 +1612,11 @@ CXSourceRange clang_getCursorExtent(CXCursor C) { CXCursor clang_getCursorReferenced(CXCursor C) { if (clang_isInvalid(C.kind)) return clang_getNullCursor(); - + ASTUnit *CXXUnit = getCursorASTUnit(C); if (clang_isDeclaration(C.kind)) return C; - + if (clang_isExpression(C.kind)) { Decl *D = getDeclFromExpr(getCursorExpr(C)); if (D) @@ -1626,36 +1626,36 @@ CXCursor clang_getCursorReferenced(CXCursor C) { if (!clang_isReference(C.kind)) return clang_getNullCursor(); - + switch (C.kind) { case CXCursor_ObjCSuperClassRef: return MakeCXCursor(getCursorObjCSuperClassRef(C).first, CXXUnit); - - case CXCursor_ObjCProtocolRef: { + + case CXCursor_ObjCProtocolRef: { return MakeCXCursor(getCursorObjCProtocolRef(C).first, CXXUnit); - - case CXCursor_ObjCClassRef: + + case CXCursor_ObjCClassRef: return MakeCXCursor(getCursorObjCClassRef(C).first, CXXUnit); - case CXCursor_TypeRef: + case CXCursor_TypeRef: return MakeCXCursor(getCursorTypeRef(C).first, CXXUnit); - + default: // We would prefer to enumerate all non-reference cursor kinds here. llvm_unreachable("Unhandled reference cursor kind"); break; } } - + return clang_getNullCursor(); } CXCursor clang_getCursorDefinition(CXCursor C) { if (clang_isInvalid(C.kind)) return clang_getNullCursor(); - + ASTUnit *CXXUnit = getCursorASTUnit(C); - + bool WasReference = false; if (clang_isReference(C.kind) || clang_isExpression(C.kind)) { C = clang_getCursorReferenced(C); @@ -1668,7 +1668,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) { Decl *D = getCursorDecl(C); if (!D) return clang_getNullCursor(); - + switch (D->getKind()) { // Declaration kinds that don't really separate the notions of // declaration and definition. @@ -1737,19 +1737,19 @@ CXCursor clang_getCursorDefinition(CXCursor C) { return MakeCXCursor(Def, CXXUnit); return clang_getNullCursor(); } - + case Decl::FunctionTemplate: { const FunctionDecl *Def = 0; if (cast(D)->getTemplatedDecl()->getBody(Def)) return MakeCXCursor(Def->getDescribedFunctionTemplate(), CXXUnit); return clang_getNullCursor(); } - + case Decl::ClassTemplate: { if (RecordDecl *Def = cast(D)->getTemplatedDecl() ->getDefinition()) return MakeCXCursor( - cast(Def)->getDescribedClassTemplate(), + cast(Def)->getDescribedClassTemplate(), CXXUnit); return clang_getNullCursor(); } @@ -1757,15 +1757,15 @@ CXCursor clang_getCursorDefinition(CXCursor C) { case Decl::Using: { UsingDecl *Using = cast(D); CXCursor Def = clang_getNullCursor(); - for (UsingDecl::shadow_iterator S = Using->shadow_begin(), - SEnd = Using->shadow_end(); + for (UsingDecl::shadow_iterator S = Using->shadow_begin(), + SEnd = Using->shadow_end(); S != SEnd; ++S) { if (Def != clang_getNullCursor()) { // FIXME: We have no way to return multiple results. return clang_getNullCursor(); } - Def = clang_getCursorDefinition(MakeCXCursor((*S)->getTargetDecl(), + Def = clang_getCursorDefinition(MakeCXCursor((*S)->getTargetDecl(), CXXUnit)); } @@ -1774,7 +1774,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) { case Decl::UsingShadow: return clang_getCursorDefinition( - MakeCXCursor(cast(D)->getTargetDecl(), + MakeCXCursor(cast(D)->getTargetDecl(), CXXUnit)); case Decl::ObjCMethod: { @@ -1820,7 +1820,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) { = cast(D)->getImplementation()) return MakeCXCursor(Impl, CXXUnit); return clang_getNullCursor(); - + case Decl::ObjCProperty: // FIXME: We don't really know where to find the // ObjCPropertyImplDecls that implement this property. @@ -1831,14 +1831,14 @@ CXCursor clang_getCursorDefinition(CXCursor C) { = cast(D)->getClassInterface()) if (!Class->isForwardDecl()) return MakeCXCursor(Class, CXXUnit); - + return clang_getNullCursor(); case Decl::ObjCForwardProtocol: { ObjCForwardProtocolDecl *Forward = cast(D); if (Forward->protocol_size() == 1) return clang_getCursorDefinition( - MakeCXCursor(*Forward->protocol_begin(), + MakeCXCursor(*Forward->protocol_begin(), CXXUnit)); // FIXME: Cannot return multiple definitions. @@ -1890,7 +1890,7 @@ void clang_getDefinitionSpellingAndExtent(CXCursor C, NamedDecl *ND = static_cast(getCursorDecl(C)); FunctionDecl *FD = dyn_cast(ND); CompoundStmt *Body = dyn_cast(FD->getBody()); - + SourceManager &SM = FD->getASTContext().getSourceManager(); *startBuf = SM.getCharacterData(Body->getLBracLoc()); *endBuf = SM.getCharacterData(Body->getRBracLoc()); @@ -1899,7 +1899,7 @@ void clang_getDefinitionSpellingAndExtent(CXCursor C, *endLine = SM.getSpellingLineNumber(Body->getRBracLoc()); *endColumn = SM.getSpellingColumnNumber(Body->getRBracLoc()); } - + } // end: extern "C" //===----------------------------------------------------------------------===// @@ -1911,7 +1911,7 @@ void clang_getDefinitionSpellingAndExtent(CXCursor C, * int_data[1]: starting token location * int_data[2]: token length * int_data[3]: reserved - * ptr_data: for identifiers and keywords, an IdentifierInfo*. + * ptr_data: for identifiers and keywords, an IdentifierInfo*. * otherwise unused. */ extern "C" { @@ -1933,18 +1933,18 @@ CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) { const char *Text = static_cast(CXTok.ptr_data); return createCXString(llvm::StringRef(Text, CXTok.int_data[2])); } - + case CXToken_Punctuation: case CXToken_Comment: break; } - - // We have to find the starting buffer pointer the hard way, by + + // We have to find the starting buffer pointer the hard way, by // deconstructing the source location. ASTUnit *CXXUnit = static_cast(TU); if (!CXXUnit) return createCXString(""); - + SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]); std::pair LocInfo = CXXUnit->getSourceManager().getDecomposedLoc(Loc); @@ -1954,12 +1954,12 @@ CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) { return createCXString(llvm::StringRef(Buffer.first+LocInfo.second, CXTok.int_data[2])); } - + CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) { ASTUnit *CXXUnit = static_cast(TU); if (!CXXUnit) return clang_getNullLocation(); - + return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SourceLocation::getFromRawEncoding(CXTok.int_data[1])); } @@ -1968,44 +1968,44 @@ CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) { ASTUnit *CXXUnit = static_cast(TU); if (!CXXUnit) return clang_getNullRange(); - - return cxloc::translateSourceRange(CXXUnit->getASTContext(), + + return cxloc::translateSourceRange(CXXUnit->getASTContext(), SourceLocation::getFromRawEncoding(CXTok.int_data[1])); } - + void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, CXToken **Tokens, unsigned *NumTokens) { if (Tokens) *Tokens = 0; if (NumTokens) *NumTokens = 0; - + ASTUnit *CXXUnit = static_cast(TU); if (!CXXUnit || !Tokens || !NumTokens) return; - + SourceRange R = cxloc::translateCXSourceRange(Range); if (R.isInvalid()) return; - + SourceManager &SourceMgr = CXXUnit->getSourceManager(); std::pair BeginLocInfo = SourceMgr.getDecomposedLoc(R.getBegin()); std::pair EndLocInfo = SourceMgr.getDecomposedLoc(R.getEnd()); - + // Cannot tokenize across files. if (BeginLocInfo.first != EndLocInfo.first) return; - - // Create a lexer + + // Create a lexer std::pair Buffer = SourceMgr.getBufferData(BeginLocInfo.first); Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first), CXXUnit->getASTContext().getLangOptions(), Buffer.first, Buffer.first + BeginLocInfo.second, Buffer.second); Lex.SetCommentRetentionState(true); - + // Lex tokens until we hit the end of the range. const char *EffectiveBufferEnd = Buffer.first + EndLocInfo.second; llvm::SmallVector CXTokens; @@ -2015,25 +2015,25 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, Lex.LexFromRawLexer(Tok); if (Tok.is(tok::eof)) break; - + // Initialize the CXToken. CXToken CXTok; - + // - Common fields CXTok.int_data[1] = Tok.getLocation().getRawEncoding(); CXTok.int_data[2] = Tok.getLength(); CXTok.int_data[3] = 0; - + // - Kind-specific fields if (Tok.isLiteral()) { CXTok.int_data[0] = CXToken_Literal; CXTok.ptr_data = (void *)Tok.getLiteralData(); } else if (Tok.is(tok::identifier)) { - // Lookup the identifier to determine whether we have a + // Lookup the identifier to determine whether we have a std::pair LocInfo = SourceMgr.getDecomposedLoc(Tok.getLocation()); - const char *StartPos - = CXXUnit->getSourceManager().getBufferData(LocInfo.first).first + + const char *StartPos + = CXXUnit->getSourceManager().getBufferData(LocInfo.first).first + LocInfo.second; IdentifierInfo *II = CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok, StartPos); @@ -2050,10 +2050,10 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, } CXTokens.push_back(CXTok); } while (Lex.getBufferLocation() <= EffectiveBufferEnd); - + if (CXTokens.empty()) return; - + *Tokens = (CXToken *)malloc(sizeof(CXToken) * CXTokens.size()); memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size()); *NumTokens = CXTokens.size(); @@ -2061,8 +2061,8 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, typedef llvm::DenseMap AnnotateTokensData; -enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor, - CXCursor parent, +enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor, + CXCursor parent, CXClientData client_data) { AnnotateTokensData *Data = static_cast(client_data); @@ -2081,13 +2081,13 @@ enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor, CXCursor Referenced = clang_getCursorReferenced(cursor); if (Referenced == cursor || Referenced == clang_getNullCursor()) return CXChildVisit_Recurse; - + // Okay: we can annotate the location of this expression } else { // Nothing to annotate return CXChildVisit_Recurse; } - + CXSourceLocation Loc = clang_getCursorLocation(cursor); (*Data)[Loc.int_data] = cursor; return CXChildVisit_Recurse; @@ -2107,12 +2107,12 @@ void clang_annotateTokens(CXTranslationUnit TU, if (!CXXUnit || !Tokens) return; - // Annotate all of the source locations in the region of interest that map + // Annotate all of the source locations in the region of interest that map SourceRange RegionOfInterest; RegionOfInterest.setBegin( cxloc::translateSourceLocation(clang_getTokenLocation(TU, Tokens[0]))); SourceLocation End - = cxloc::translateSourceLocation(clang_getTokenLocation(TU, + = cxloc::translateSourceLocation(clang_getTokenLocation(TU, Tokens[NumTokens - 1])); RegionOfInterest.setEnd(CXXUnit->getPreprocessor().getLocForEndOfToken(End)); // FIXME: Would be great to have a "hint" cursor, then walk from that @@ -2120,7 +2120,7 @@ void clang_annotateTokens(CXTranslationUnit TU, // the region of interest, rather than starting from the translation unit. AnnotateTokensData Annotated; CXCursor Parent = clang_getTranslationUnitCursor(CXXUnit); - CursorVisitor AnnotateVis(CXXUnit, AnnotateTokensVisitor, &Annotated, + CursorVisitor AnnotateVis(CXXUnit, AnnotateTokensVisitor, &Annotated, Decl::MaxPCHLevel, RegionOfInterest); AnnotateVis.VisitChildren(Parent); @@ -2134,11 +2134,11 @@ void clang_annotateTokens(CXTranslationUnit TU, } } -void clang_disposeTokens(CXTranslationUnit TU, +void clang_disposeTokens(CXTranslationUnit TU, CXToken *Tokens, unsigned NumTokens) { free(Tokens); } - + } // end: extern "C" //===----------------------------------------------------------------------===// @@ -2189,7 +2189,7 @@ CXString createCXString(llvm::StringRef String, bool DupString) { //===----------------------------------------------------------------------===// // Misc. utility functions. //===----------------------------------------------------------------------===// - + extern "C" { CXString clang_getClangVersion() {