diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ARCMigrate/ObjCMT.cpp | 19 | ||||
-rw-r--r-- | lib/Edit/Commit.cpp | 4 | ||||
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 2 | ||||
-rw-r--r-- | lib/Lex/PPConditionalDirectiveRecord.cpp | 118 | ||||
-rw-r--r-- | lib/Lex/PreprocessingRecord.cpp | 101 | ||||
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 5 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 4 |
7 files changed, 138 insertions, 115 deletions
diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index dfe14e2b5d..58499572a8 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -20,6 +20,7 @@ #include "clang/Edit/EditsReceiver.h" #include "clang/Rewrite/Core/Rewriter.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/PPConditionalDirectiveRecord.h" #include "clang/Basic/FileManager.h" #include "llvm/ADT/SmallString.h" @@ -39,7 +40,7 @@ public: llvm::OwningPtr<edit::EditedSource> Editor; FileRemapper &Remapper; FileManager &FileMgr; - const PreprocessingRecord *PPRec; + const PPConditionalDirectiveRecord *PPRec; bool IsOutputFile; ObjCMigrateASTConsumer(StringRef migrateDir, @@ -47,7 +48,7 @@ public: bool migrateSubscripting, FileRemapper &remapper, FileManager &fileMgr, - const PreprocessingRecord *PPRec, + const PPConditionalDirectiveRecord *PPRec, bool isOutputFile = false) : MigrateDir(migrateDir), MigrateLiterals(migrateLiterals), @@ -93,6 +94,9 @@ ObjCMigrateAction::ObjCMigrateAction(FrontendAction *WrappedAction, ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { + PPConditionalDirectiveRecord * + PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager()); + CompInst->getPreprocessor().addPPCallbacks(PPRec); ASTConsumer * WrappedConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile); ASTConsumer *MTConsumer = new ObjCMigrateASTConsumer(MigrateDir, @@ -100,7 +104,7 @@ ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, MigrateSubscripting, Remapper, CompInst->getFileManager(), - CompInst->getPreprocessor().getPreprocessingRecord()); + PPRec); ASTConsumer *Consumers[] = { MTConsumer, WrappedConsumer }; return new MultiplexConsumer(Consumers); } @@ -110,8 +114,6 @@ bool ObjCMigrateAction::BeginInvocation(CompilerInstance &CI) { /*ignoreIfFilesChanges=*/true); CompInst = &CI; CI.getDiagnostics().setIgnoreAllWarnings(true); - CI.getPreprocessorOpts().DetailedRecord = true; - CI.getPreprocessorOpts().DetailedRecordConditionalDirectives = true; return true; } @@ -211,18 +213,19 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { bool MigrateSourceAction::BeginInvocation(CompilerInstance &CI) { CI.getDiagnostics().setIgnoreAllWarnings(true); - CI.getPreprocessorOpts().DetailedRecord = true; - CI.getPreprocessorOpts().DetailedRecordConditionalDirectives = true; return true; } ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { + PPConditionalDirectiveRecord * + PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager()); + CI.getPreprocessor().addPPCallbacks(PPRec); return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile, /*MigrateLiterals=*/true, /*MigrateSubscripting=*/true, Remapper, CI.getFileManager(), - CI.getPreprocessor().getPreprocessingRecord(), + PPRec, /*isOutputFile=*/true); } diff --git a/lib/Edit/Commit.cpp b/lib/Edit/Commit.cpp index 41c72e42e6..3a9719ada0 100644 --- a/lib/Edit/Commit.cpp +++ b/lib/Edit/Commit.cpp @@ -10,7 +10,7 @@ #include "clang/Edit/Commit.h" #include "clang/Edit/EditedSource.h" #include "clang/Lex/Lexer.h" -#include "clang/Lex/PreprocessingRecord.h" +#include "clang/Lex/PPConditionalDirectiveRecord.h" #include "clang/Basic/SourceManager.h" using namespace clang; @@ -37,7 +37,7 @@ CharSourceRange Commit::Edit::getInsertFromRange(SourceManager &SM) const { Commit::Commit(EditedSource &Editor) : SourceMgr(Editor.getSourceManager()), LangOpts(Editor.getLangOpts()), - PPRec(Editor.getPreprocessingRecord()), + PPRec(Editor.getPPCondDirectiveRecord()), Editor(&Editor), IsCommitable(true) { } bool Commit::insert(SourceLocation loc, StringRef text, diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index d481ebf511..e5c1512657 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -260,7 +260,7 @@ void CompilerInstance::createPreprocessor() { } if (PPOpts.DetailedRecord) - PP->createPreprocessingRecord(PPOpts.DetailedRecordConditionalDirectives); + PP->createPreprocessingRecord(); InitializePreprocessor(*PP, PPOpts, getHeaderSearchOpts(), getFrontendOpts()); diff --git a/lib/Lex/PPConditionalDirectiveRecord.cpp b/lib/Lex/PPConditionalDirectiveRecord.cpp new file mode 100644 index 0000000000..edcde871a0 --- /dev/null +++ b/lib/Lex/PPConditionalDirectiveRecord.cpp @@ -0,0 +1,118 @@ +//===--- PPConditionalDirectiveRecord.h - Preprocessing Directives-*- C++ -*-=// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the PPConditionalDirectiveRecord class, which maintains +// a record of conditional directive regions. +// +//===----------------------------------------------------------------------===// +#include "clang/Lex/PPConditionalDirectiveRecord.h" +#include "llvm/Support/Capacity.h" + +using namespace clang; + +PPConditionalDirectiveRecord::PPConditionalDirectiveRecord(SourceManager &SM) + : SourceMgr(SM) { + CondDirectiveStack.push_back(SourceLocation()); +} + +bool PPConditionalDirectiveRecord::rangeIntersectsConditionalDirective( + SourceRange Range) const { + if (Range.isInvalid()) + return false; + + CondDirectiveLocsTy::const_iterator + low = std::lower_bound(CondDirectiveLocs.begin(), CondDirectiveLocs.end(), + Range.getBegin(), CondDirectiveLoc::Comp(SourceMgr)); + if (low == CondDirectiveLocs.end()) + return false; + + if (SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), low->getLoc())) + return false; + + CondDirectiveLocsTy::const_iterator + upp = std::upper_bound(low, CondDirectiveLocs.end(), + Range.getEnd(), CondDirectiveLoc::Comp(SourceMgr)); + SourceLocation uppRegion; + if (upp != CondDirectiveLocs.end()) + uppRegion = upp->getRegionLoc(); + + return low->getRegionLoc() != uppRegion; +} + +SourceLocation PPConditionalDirectiveRecord::findConditionalDirectiveRegionLoc( + SourceLocation Loc) const { + if (Loc.isInvalid()) + return SourceLocation(); + if (CondDirectiveLocs.empty()) + return SourceLocation(); + + if (SourceMgr.isBeforeInTranslationUnit(CondDirectiveLocs.back().getLoc(), + Loc)) + return CondDirectiveStack.back(); + + CondDirectiveLocsTy::const_iterator + low = std::lower_bound(CondDirectiveLocs.begin(), CondDirectiveLocs.end(), + Loc, CondDirectiveLoc::Comp(SourceMgr)); + assert(low != CondDirectiveLocs.end()); + return low->getRegionLoc(); +} + +void PPConditionalDirectiveRecord::addCondDirectiveLoc( + CondDirectiveLoc DirLoc) { + // Ignore directives in system headers. + if (SourceMgr.isInSystemHeader(DirLoc.getLoc())) + return; + + assert(CondDirectiveLocs.empty() || + SourceMgr.isBeforeInTranslationUnit(CondDirectiveLocs.back().getLoc(), + DirLoc.getLoc())); + CondDirectiveLocs.push_back(DirLoc); +} + +void PPConditionalDirectiveRecord::If(SourceLocation Loc, + SourceRange ConditionRange) { + addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); + CondDirectiveStack.push_back(Loc); +} + +void PPConditionalDirectiveRecord::Ifdef(SourceLocation Loc, + const Token &MacroNameTok) { + addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); + CondDirectiveStack.push_back(Loc); +} + +void PPConditionalDirectiveRecord::Ifndef(SourceLocation Loc, + const Token &MacroNameTok) { + addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); + CondDirectiveStack.push_back(Loc); +} + +void PPConditionalDirectiveRecord::Elif(SourceLocation Loc, + SourceRange ConditionRange, + SourceLocation IfLoc) { + addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); + CondDirectiveStack.back() = Loc; +} + +void PPConditionalDirectiveRecord::Else(SourceLocation Loc, + SourceLocation IfLoc) { + addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); + CondDirectiveStack.back() = Loc; +} + +void PPConditionalDirectiveRecord::Endif(SourceLocation Loc, + SourceLocation IfLoc) { + addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); + assert(!CondDirectiveStack.empty()); + CondDirectiveStack.pop_back(); +} + +size_t PPConditionalDirectiveRecord::getTotalMemory() const { + return llvm::capacity_in_bytes(CondDirectiveLocs); +} diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp index 0376e449ae..5f1353c86e 100644 --- a/lib/Lex/PreprocessingRecord.cpp +++ b/lib/Lex/PreprocessingRecord.cpp @@ -38,14 +38,9 @@ InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec, this->FileName = StringRef(Memory, FileName.size()); } -PreprocessingRecord::PreprocessingRecord(SourceManager &SM, - bool RecordConditionalDirectives) +PreprocessingRecord::PreprocessingRecord(SourceManager &SM) : SourceMgr(SM), - RecordCondDirectives(RecordConditionalDirectives), - ExternalSource(0) -{ - if (RecordCondDirectives) - CondDirectiveStack.push_back(SourceLocation()); + ExternalSource(0) { } /// \brief Returns a pair of [Begin, End) iterators of preprocessed entities @@ -438,98 +433,6 @@ void PreprocessingRecord::InclusionDirective( addPreprocessedEntity(ID); } -bool PreprocessingRecord::rangeIntersectsConditionalDirective( - SourceRange Range) const { - if (Range.isInvalid()) - return false; - - CondDirectiveLocsTy::const_iterator - low = std::lower_bound(CondDirectiveLocs.begin(), CondDirectiveLocs.end(), - Range.getBegin(), CondDirectiveLoc::Comp(SourceMgr)); - if (low == CondDirectiveLocs.end()) - return false; - - if (SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), low->getLoc())) - return false; - - CondDirectiveLocsTy::const_iterator - upp = std::upper_bound(low, CondDirectiveLocs.end(), - Range.getEnd(), CondDirectiveLoc::Comp(SourceMgr)); - SourceLocation uppRegion; - if (upp != CondDirectiveLocs.end()) - uppRegion = upp->getRegionLoc(); - - return low->getRegionLoc() != uppRegion; -} - -SourceLocation -PreprocessingRecord::findCondDirectiveRegionLoc(SourceLocation Loc) const { - if (Loc.isInvalid()) - return SourceLocation(); - - CondDirectiveLocsTy::const_iterator - low = std::lower_bound(CondDirectiveLocs.begin(), CondDirectiveLocs.end(), - Loc, CondDirectiveLoc::Comp(SourceMgr)); - if (low == CondDirectiveLocs.end()) - return SourceLocation(); - return low->getRegionLoc(); -} - -void PreprocessingRecord::addCondDirectiveLoc(CondDirectiveLoc DirLoc) { - // Ignore directives in system headers. - if (SourceMgr.isInSystemHeader(DirLoc.getLoc())) - return; - - assert(CondDirectiveLocs.empty() || - SourceMgr.isBeforeInTranslationUnit(CondDirectiveLocs.back().getLoc(), - DirLoc.getLoc())); - CondDirectiveLocs.push_back(DirLoc); -} - -void PreprocessingRecord::If(SourceLocation Loc, SourceRange ConditionRange) { - if (RecordCondDirectives) { - addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); - CondDirectiveStack.push_back(Loc); - } -} - -void PreprocessingRecord::Ifdef(SourceLocation Loc, const Token &MacroNameTok) { - if (RecordCondDirectives) { - addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); - CondDirectiveStack.push_back(Loc); - } -} - -void PreprocessingRecord::Ifndef(SourceLocation Loc,const Token &MacroNameTok) { - if (RecordCondDirectives) { - addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); - CondDirectiveStack.push_back(Loc); - } -} - -void PreprocessingRecord::Elif(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) { - if (RecordCondDirectives) { - addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); - CondDirectiveStack.back() = Loc; - } -} - -void PreprocessingRecord::Else(SourceLocation Loc, SourceLocation IfLoc) { - if (RecordCondDirectives) { - addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); - CondDirectiveStack.back() = Loc; - } -} - -void PreprocessingRecord::Endif(SourceLocation Loc, SourceLocation IfLoc) { - if (RecordCondDirectives) { - addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); - assert(!CondDirectiveStack.empty()); - CondDirectiveStack.pop_back(); - } -} - size_t PreprocessingRecord::getTotalMemory() const { return BumpAlloc.getTotalMemory() + llvm::capacity_in_bytes(MacroDefinitions) diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 9488584105..b5fb89f091 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -765,11 +765,10 @@ CommentHandler::~CommentHandler() { } CodeCompletionHandler::~CodeCompletionHandler() { } -void Preprocessor::createPreprocessingRecord(bool RecordConditionalDirectives) { +void Preprocessor::createPreprocessingRecord() { if (Record) return; - Record = new PreprocessingRecord(getSourceManager(), - RecordConditionalDirectives); + Record = new PreprocessingRecord(getSourceManager()); addPPCallbacks(Record); } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 908d8c573c..bc08f3f5f6 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1907,7 +1907,7 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { = F.PreprocessorDetailCursor.GetCurrentBitNo(); if (!PP.getPreprocessingRecord()) - PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); + PP.createPreprocessingRecord(); if (!PP.getPreprocessingRecord()->getExternalSource()) PP.getPreprocessingRecord()->SetExternalSource(*this); break; @@ -2365,7 +2365,7 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { unsigned StartingID; if (!PP.getPreprocessingRecord()) - PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); + PP.createPreprocessingRecord(); if (!PP.getPreprocessingRecord()->getExternalSource()) PP.getPreprocessingRecord()->SetExternalSource(*this); StartingID |