diff options
Diffstat (limited to 'include/clang/Lex')
-rw-r--r-- | include/clang/Lex/DirectoryLookup.h | 9 | ||||
-rw-r--r-- | include/clang/Lex/ExternalPreprocessorSource.h | 34 | ||||
-rw-r--r-- | include/clang/Lex/HeaderMap.h | 4 | ||||
-rw-r--r-- | include/clang/Lex/HeaderSearch.h | 11 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 33 |
5 files changed, 68 insertions, 23 deletions
diff --git a/include/clang/Lex/DirectoryLookup.h b/include/clang/Lex/DirectoryLookup.h index c94a990..64687a1 100644 --- a/include/clang/Lex/DirectoryLookup.h +++ b/include/clang/Lex/DirectoryLookup.h @@ -16,6 +16,9 @@ #include "clang/Basic/SourceManager.h" +namespace llvm { + class StringRef; +} namespace clang { class HeaderMap; class DirectoryEntry; @@ -118,12 +121,10 @@ public: /// LookupFile - Lookup the specified file in this search path, returning it /// if it exists or returning null if not. - const FileEntry *LookupFile(const char *FilenameStart, - const char *FilenameEnd, HeaderSearch &HS) const; + const FileEntry *LookupFile(llvm::StringRef Filename, HeaderSearch &HS) const; private: - const FileEntry *DoFrameworkLookup(const char *FilenameStart, - const char *FilenameEnd, + const FileEntry *DoFrameworkLookup(llvm::StringRef Filename, HeaderSearch &HS) const; }; diff --git a/include/clang/Lex/ExternalPreprocessorSource.h b/include/clang/Lex/ExternalPreprocessorSource.h new file mode 100644 index 0000000..af5c389 --- /dev/null +++ b/include/clang/Lex/ExternalPreprocessorSource.h @@ -0,0 +1,34 @@ +//===- ExternalPreprocessorSource.h - Abstract Macro Interface --*- 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 ExternalPreprocessorSource interface, which enables +// construction of macro definitions from some external source. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_LEX_EXTERNAL_PREPROCESSOR_SOURCE_H +#define LLVM_CLANG_LEX_EXTERNAL_PREPROCESSOR_SOURCE_H + +namespace clang { + +/// \brief Abstract interface for external sources of preprocessor +/// information. +/// +/// This abstract class allows an external sources (such as the \c PCHReader) +/// to provide additional macro definitions. +class ExternalPreprocessorSource { +public: + virtual ~ExternalPreprocessorSource(); + + /// \brief Read the set of macros defined by this external macro source. + virtual void ReadDefinedMacros() = 0; +}; + +} + +#endif // LLVM_CLANG_LEX_EXTERNAL_PREPROCESSOR_SOURCE_H diff --git a/include/clang/Lex/HeaderMap.h b/include/clang/Lex/HeaderMap.h index 6bb7c25..9837e29 100644 --- a/include/clang/Lex/HeaderMap.h +++ b/include/clang/Lex/HeaderMap.h @@ -16,6 +16,7 @@ namespace llvm { class MemoryBuffer; + class StringRef; } namespace clang { class FileEntry; @@ -46,8 +47,7 @@ public: /// LookupFile - Check to see if the specified relative filename is located in /// this HeaderMap. If so, open it and return its FileEntry. - const FileEntry *LookupFile(const char *FilenameStart,const char *FilenameEnd, - FileManager &FM) const; + const FileEntry *LookupFile(llvm::StringRef Filename, FileManager &FM) const; /// getFileName - Return the filename of the headermap. const char *getFileName() const; diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h index 7517440..16b8379 100644 --- a/include/clang/Lex/HeaderSearch.h +++ b/include/clang/Lex/HeaderSearch.h @@ -150,8 +150,7 @@ public: /// search location. This is used to implement #include_next. CurFileEnt, if /// non-null, indicates where the #including file is, in case a relative /// search is needed. - const FileEntry *LookupFile(const char *FilenameStart, - const char *FilenameEnd, bool isAngled, + const FileEntry *LookupFile(llvm::StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, const FileEntry *CurFileEnt); @@ -161,16 +160,14 @@ public: /// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox /// is a subframework within Carbon.framework. If so, return the FileEntry /// for the designated file, otherwise return null. - const FileEntry *LookupSubframeworkHeader(const char *FilenameStart, - const char *FilenameEnd, + const FileEntry *LookupSubframeworkHeader(llvm::StringRef Filename, const FileEntry *RelativeFileEnt); /// LookupFrameworkCache - Look up the specified framework name in our /// framework cache, returning the DirectoryEntry it is in if we know, /// otherwise, return null. - const DirectoryEntry *&LookupFrameworkCache(const char *FWNameStart, - const char *FWNameEnd) { - return FrameworkMap.GetOrCreateValue(FWNameStart, FWNameEnd).getValue(); + const DirectoryEntry *&LookupFrameworkCache(llvm::StringRef FWName) { + return FrameworkMap.GetOrCreateValue(FWName).getValue(); } /// ShouldEnterIncludeFile - Mark the specified file as a target of of a diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 7c838ff..fc2671f 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -32,6 +32,7 @@ namespace clang { class SourceManager; +class ExternalPreprocessorSource; class FileManager; class FileEntry; class HeaderSearch; @@ -42,7 +43,7 @@ class ScratchBuffer; class TargetInfo; class PPCallbacks; class DirectoryLookup; - + /// Preprocessor - This object engages in a tight little dance with the lexer to /// efficiently preprocess tokens. Lexers know only about tokens within a /// single source file, and don't know anything about preprocessor-level issues @@ -57,6 +58,9 @@ class Preprocessor { ScratchBuffer *ScratchBuf; HeaderSearch &HeaderInfo; + /// \brief External source of macros. + ExternalPreprocessorSource *ExternalSource; + /// PTH - An optional PTHManager object used for getting tokens from /// a token cache rather than lexing the original source file. llvm::OwningPtr<PTHManager> PTH; @@ -99,6 +103,9 @@ class Preprocessor { /// DisableMacroExpansion - True if macro expansion is disabled. bool DisableMacroExpansion : 1; + /// \brief Whether we have already loaded macros from the external source. + mutable bool ReadMacrosFromExternalSource : 1; + /// Identifiers - This is mapping/lookup information for all identifiers in /// the program, including program keywords. mutable IdentifierTable Identifiers; @@ -247,6 +254,14 @@ public: PTHManager *getPTHManager() { return PTH.get(); } + void setExternalSource(ExternalPreprocessorSource *Source) { + ExternalSource = Source; + } + + ExternalPreprocessorSource *getExternalSource() const { + return ExternalSource; + } + /// SetCommentRetentionState - Control whether or not the preprocessor retains /// comments in output. void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments) { @@ -296,11 +311,9 @@ public: /// state of the macro table. This visits every currently-defined macro. typedef llvm::DenseMap<IdentifierInfo*, MacroInfo*>::const_iterator macro_iterator; - macro_iterator macro_begin() const { return Macros.begin(); } - macro_iterator macro_end() const { return Macros.end(); } - - - + macro_iterator macro_begin(bool IncludeExternalMacros = true) const; + macro_iterator macro_end(bool IncludeExternalMacros = true) const; + const std::string &getPredefines() const { return Predefines; } /// setPredefines - Set the predefines for this Preprocessor. These /// predefines are automatically injected when parsing the main file. @@ -678,14 +691,14 @@ public: /// caller is expected to provide a buffer that is large enough to hold the /// spelling of the filename, but is also expected to handle the case when /// this method decides to use a different buffer. - bool GetIncludeFilenameSpelling(SourceLocation Loc, - const char *&BufStart, const char *&BufEnd); + bool GetIncludeFilenameSpelling(SourceLocation Loc,llvm::StringRef &Filename); /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file, /// return null on failure. isAngled indicates whether the file reference is /// for system #include's or not (i.e. using <> instead of ""). - const FileEntry *LookupFile(const char *FilenameStart,const char *FilenameEnd, - bool isAngled, const DirectoryLookup *FromDir, + const FileEntry *LookupFile(llvm::StringRef Filename, + SourceLocation FilenameTokLoc, bool isAngled, + const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir); /// GetCurLookup - The DirectoryLookup structure used to find the current |