diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-12-04 07:27:05 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-12-04 07:27:05 +0000 |
commit | 37ed12720a35b7bfa1c4de73ad6f1c6c1c88ee17 (patch) | |
tree | bba1cb7716cd13f295e22172dd4ca239d62fae54 /include/clang/Lex | |
parent | df1059cac42d613547d86b4e44c5e364bfc03073 (diff) |
Refactor recording the preprocessor conditional directive regions out of
PreprocessingRecord and into its own class, PPConditionalDirectiveRecord.
Decoupling allows a client to use the functionality of PPConditionalDirectiveRecord
without needing a PreprocessingRecord.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169229 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Lex')
-rw-r--r-- | include/clang/Lex/PPConditionalDirectiveRecord.h | 100 | ||||
-rw-r--r-- | include/clang/Lex/PreprocessingRecord.h | 65 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 2 | ||||
-rw-r--r-- | include/clang/Lex/PreprocessorOptions.h | 5 |
4 files changed, 102 insertions, 70 deletions
diff --git a/include/clang/Lex/PPConditionalDirectiveRecord.h b/include/clang/Lex/PPConditionalDirectiveRecord.h new file mode 100644 index 0000000000..36e6216beb --- /dev/null +++ b/include/clang/Lex/PPConditionalDirectiveRecord.h @@ -0,0 +1,100 @@ +//===--- 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 defines the PPConditionalDirectiveRecord class, which maintains +// a record of conditional directive regions. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_LEX_PPCONDITIONALDIRECTIVERECORD_H +#define LLVM_CLANG_LEX_PPCONDITIONALDIRECTIVERECORD_H + +#include "clang/Lex/PPCallbacks.h" +#include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/SmallVector.h" +#include <vector> + +namespace clang { + +/// \brief Records preprocessor conditional directive regions and allows +/// querying in which region source locations belong to. +class PPConditionalDirectiveRecord : public PPCallbacks { + SourceManager &SourceMgr; + + SmallVector<SourceLocation, 6> CondDirectiveStack; + + class CondDirectiveLoc { + SourceLocation Loc; + SourceLocation RegionLoc; + + public: + CondDirectiveLoc(SourceLocation Loc, SourceLocation RegionLoc) + : Loc(Loc), RegionLoc(RegionLoc) {} + + SourceLocation getLoc() const { return Loc; } + SourceLocation getRegionLoc() const { return RegionLoc; } + + class Comp { + SourceManager &SM; + public: + explicit Comp(SourceManager &SM) : SM(SM) {} + bool operator()(const CondDirectiveLoc &LHS, + const CondDirectiveLoc &RHS) { + return SM.isBeforeInTranslationUnit(LHS.getLoc(), RHS.getLoc()); + } + bool operator()(const CondDirectiveLoc &LHS, SourceLocation RHS) { + return SM.isBeforeInTranslationUnit(LHS.getLoc(), RHS); + } + bool operator()(SourceLocation LHS, const CondDirectiveLoc &RHS) { + return SM.isBeforeInTranslationUnit(LHS, RHS.getLoc()); + } + }; + }; + + typedef std::vector<CondDirectiveLoc> CondDirectiveLocsTy; + /// \brief The locations of conditional directives in source order. + CondDirectiveLocsTy CondDirectiveLocs; + + void addCondDirectiveLoc(CondDirectiveLoc DirLoc); + +public: + /// \brief Construct a new preprocessing record. + explicit PPConditionalDirectiveRecord(SourceManager &SM); + + size_t getTotalMemory() const; + + SourceManager &getSourceManager() const { return SourceMgr; } + + /// \brief Returns true if the given range intersects with a conditional + /// directive. if a \#if/\#endif block is fully contained within the range, + /// this function will return false. + bool rangeIntersectsConditionalDirective(SourceRange Range) const; + + /// \brief Returns true if the given locations are in different regions, + /// separated by conditional directive blocks. + bool areInDifferentConditionalDirectiveRegion(SourceLocation LHS, + SourceLocation RHS) const { + return findConditionalDirectiveRegionLoc(LHS) != + findConditionalDirectiveRegionLoc(RHS); + } + + SourceLocation findConditionalDirectiveRegionLoc(SourceLocation Loc) const; + +private: + virtual void If(SourceLocation Loc, SourceRange ConditionRange); + virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, + SourceLocation IfLoc); + virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok); + virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok); + virtual void Else(SourceLocation Loc, SourceLocation IfLoc); + virtual void Endif(SourceLocation Loc, SourceLocation IfLoc); +}; + +} // end namespace clang + +#endif // LLVM_CLANG_LEX_PPCONDITIONALDIRECTIVERECORD_H diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index 6189ee23ba..97bb33848d 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -303,44 +303,6 @@ namespace clang { /// and are referenced by the iterator using negative indices. std::vector<PreprocessedEntity *> LoadedPreprocessedEntities; - bool RecordCondDirectives; - SmallVector<SourceLocation, 6> CondDirectiveStack; - - class CondDirectiveLoc { - SourceLocation Loc; - SourceLocation RegionLoc; - - public: - CondDirectiveLoc(SourceLocation Loc, SourceLocation RegionLoc) - : Loc(Loc), RegionLoc(RegionLoc) {} - - SourceLocation getLoc() const { return Loc; } - SourceLocation getRegionLoc() const { return RegionLoc; } - - class Comp { - SourceManager &SM; - public: - explicit Comp(SourceManager &SM) : SM(SM) {} - bool operator()(const CondDirectiveLoc &LHS, - const CondDirectiveLoc &RHS) { - return SM.isBeforeInTranslationUnit(LHS.getLoc(), RHS.getLoc()); - } - bool operator()(const CondDirectiveLoc &LHS, SourceLocation RHS) { - return SM.isBeforeInTranslationUnit(LHS.getLoc(), RHS); - } - bool operator()(SourceLocation LHS, const CondDirectiveLoc &RHS) { - return SM.isBeforeInTranslationUnit(LHS, RHS.getLoc()); - } - }; - }; - - typedef std::vector<CondDirectiveLoc> CondDirectiveLocsTy; - /// \brief The locations of conditional directives in source order. - CondDirectiveLocsTy CondDirectiveLocs; - - void addCondDirectiveLoc(CondDirectiveLoc DirLoc); - SourceLocation findCondDirectiveRegionLoc(SourceLocation Loc) const; - /// \brief Global (loaded or local) ID for a preprocessed entity. /// Negative values are used to indicate preprocessed entities /// loaded from the external source while non-negative values are used to @@ -398,7 +360,7 @@ namespace clang { public: /// \brief Construct a new preprocessing record. - PreprocessingRecord(SourceManager &SM, bool RecordConditionalDirectives); + explicit PreprocessingRecord(SourceManager &SM); /// \brief Allocate memory in the preprocessing record. void *Allocate(unsigned Size, unsigned Align = 8) { @@ -582,24 +544,6 @@ namespace clang { /// \brief Add a new preprocessed entity to this record. PPEntityID addPreprocessedEntity(PreprocessedEntity *Entity); - /// \brief Returns true if this PreprocessingRecord is keeping track of - /// conditional directives locations. - bool isRecordingConditionalDirectives() const { - return RecordCondDirectives; - } - - /// \brief Returns true if the given range intersects with a conditional - /// directive. if a \#if/\#endif block is fully contained within the range, - /// this function will return false. - bool rangeIntersectsConditionalDirective(SourceRange Range) const; - - /// \brief Returns true if the given locations are in different regions, - /// separated by conditional directive blocks. - bool areInDifferentConditionalDirectiveRegion(SourceLocation LHS, - SourceLocation RHS) const { - return findCondDirectiveRegionLoc(LHS) != findCondDirectiveRegionLoc(RHS); - } - /// \brief Set the external source for preprocessed entities. void SetExternalSource(ExternalPreprocessingRecordSource &Source); @@ -626,13 +570,6 @@ namespace clang { StringRef SearchPath, StringRef RelativePath, const Module *Imported); - virtual void If(SourceLocation Loc, SourceRange ConditionRange); - virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc); - virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok); - virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok); - virtual void Else(SourceLocation Loc, SourceLocation IfLoc); - virtual void Endif(SourceLocation Loc, SourceLocation IfLoc); /// \brief Cached result of the last \see getPreprocessedEntitiesInRange /// query. diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 7e5c66cbd8..658e187156 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -611,7 +611,7 @@ public: /// \brief Create a new preprocessing record, which will keep track of /// all macro expansions, macro definitions, etc. - void createPreprocessingRecord(bool RecordConditionalDirectives); + void createPreprocessingRecord(); /// EnterMainSourceFile - Enter the specified FileID as the main source file, /// which implicitly adds the builtin defines etc. diff --git a/include/clang/Lex/PreprocessorOptions.h b/include/clang/Lex/PreprocessorOptions.h index a670267f02..ba61eb283a 100644 --- a/include/clang/Lex/PreprocessorOptions.h +++ b/include/clang/Lex/PreprocessorOptions.h @@ -53,10 +53,6 @@ public: unsigned DetailedRecord : 1; /// Whether we should maintain a detailed /// record of all macro definitions and /// expansions. - unsigned DetailedRecordConditionalDirectives : 1; /// Whether in the - /// preprocessing record we should also keep - /// track of locations of conditional directives - /// in non-system files. /// The implicit PCH included at the start of the translation unit, or empty. std::string ImplicitPCHInclude; @@ -179,7 +175,6 @@ public: public: PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), - DetailedRecordConditionalDirectives(false), DisablePCHValidation(false), AllowPCHWithCompilerErrors(false), DumpDeserializedPCHDecls(false), |