diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
commit | 4ba675006b5a8edfc48b6a9bd3dcf54a70cc08f2 (patch) | |
tree | 48b44512b5db8ced345df4a1a56b5065cf2a14d9 /include/clang/Lex | |
parent | d7279c4c177bca357ef96ff1379fd9bc420bfe83 (diff) |
Diffstat (limited to 'include/clang/Lex')
-rw-r--r-- | include/clang/Lex/PPCallbacks.h | 12 | ||||
-rw-r--r-- | include/clang/Lex/Pragma.h | 33 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 17 | ||||
-rw-r--r-- | include/clang/Lex/Token.h | 8 |
4 files changed, 55 insertions, 15 deletions
diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index d74124e9c79b..99fe29b22dc2 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -16,6 +16,7 @@ #include "clang/Lex/DirectoryLookup.h" #include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/StringRef.h" #include <string> namespace clang { @@ -70,6 +71,12 @@ public: const std::string &Str) { } + /// PragmaMessage - This callback is invoked when a #pragma message directive + /// is read. + /// + virtual void PragmaMessage(SourceLocation Loc, llvm::StringRef Str) { + } + /// MacroExpands - This is called by /// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is /// found. @@ -127,6 +134,11 @@ public: Second->PragmaComment(Loc, Kind, Str); } + virtual void PragmaMessage(SourceLocation Loc, llvm::StringRef Str) { + First->PragmaMessage(Loc, Str); + Second->PragmaMessage(Loc, Str); + } + virtual void MacroExpands(const Token &Id, const MacroInfo* MI) { First->MacroExpands(Id, MI); Second->MacroExpands(Id, MI); diff --git a/include/clang/Lex/Pragma.h b/include/clang/Lex/Pragma.h index ef367feb84db..c68555b2f967 100644 --- a/include/clang/Lex/Pragma.h +++ b/include/clang/Lex/Pragma.h @@ -14,6 +14,8 @@ #ifndef LLVM_CLANG_PRAGMA_H #define LLVM_CLANG_PRAGMA_H +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" #include <cassert> #include <vector> @@ -33,12 +35,13 @@ namespace clang { /// we treat "#pragma STDC" and "#pragma GCC" as namespaces that contain other /// pragmas. class PragmaHandler { - const IdentifierInfo *Name; + std::string Name; public: - PragmaHandler(const IdentifierInfo *name) : Name(name) {} + explicit PragmaHandler(llvm::StringRef name) : Name(name) {} + PragmaHandler() {} virtual ~PragmaHandler(); - const IdentifierInfo *getName() const { return Name; } + llvm::StringRef getName() const { return Name; } virtual void HandlePragma(Preprocessor &PP, Token &FirstToken) = 0; /// getIfNamespace - If this is a namespace, return it. This is equivalent to @@ -46,30 +49,38 @@ public: virtual PragmaNamespace *getIfNamespace() { return 0; } }; +/// EmptyPragmaHandler - A pragma handler which takes no action, which can be +/// used to ignore particular pragmas. +class EmptyPragmaHandler : public PragmaHandler { +public: + EmptyPragmaHandler(); + + virtual void HandlePragma(Preprocessor &PP, Token &FirstToken); +}; + /// PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas, /// allowing hierarchical pragmas to be defined. Common examples of namespaces /// are "#pragma GCC", "#pragma STDC", and "#pragma omp", but any namespaces may /// be (potentially recursively) defined. class PragmaNamespace : public PragmaHandler { - /// Handlers - This is the list of handlers in this namespace. + /// Handlers - This is a map of the handlers in this namespace with their name + /// as key. /// - std::vector<PragmaHandler*> Handlers; + llvm::StringMap<PragmaHandler*> Handlers; public: - PragmaNamespace(const IdentifierInfo *Name) : PragmaHandler(Name) {} + explicit PragmaNamespace(llvm::StringRef Name) : PragmaHandler(Name) {} virtual ~PragmaNamespace(); /// FindHandler - Check to see if there is already a handler for the - /// specified name. If not, return the handler for the null identifier if it + /// specified name. If not, return the handler for the null name if it /// exists, otherwise return null. If IgnoreNull is true (the default) then /// the null handler isn't returned on failure to match. - PragmaHandler *FindHandler(const IdentifierInfo *Name, + PragmaHandler *FindHandler(llvm::StringRef Name, bool IgnoreNull = true) const; /// AddPragma - Add a pragma to this namespace. /// - void AddPragma(PragmaHandler *Handler) { - Handlers.push_back(Handler); - } + void AddPragma(PragmaHandler *Handler); /// RemovePragmaHandler - Remove the given handler from the /// namespace. diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index f01b3afc45f5..1ee4bb635179 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -340,13 +340,19 @@ public: /// AddPragmaHandler - Add the specified pragma handler to the preprocessor. /// If 'Namespace' is non-null, then it is a token required to exist on the /// pragma line before the pragma string starts, e.g. "STDC" or "GCC". - void AddPragmaHandler(const char *Namespace, PragmaHandler *Handler); + void AddPragmaHandler(llvm::StringRef Namespace, PragmaHandler *Handler); + void AddPragmaHandler(PragmaHandler *Handler) { + AddPragmaHandler(llvm::StringRef(), Handler); + } /// RemovePragmaHandler - Remove the specific pragma handler from /// the preprocessor. If \arg Namespace is non-null, then it should /// be the namespace that \arg Handler was added to. It is an error /// to remove a handler that has not been registered. - void RemovePragmaHandler(const char *Namespace, PragmaHandler *Handler); + void RemovePragmaHandler(llvm::StringRef Namespace, PragmaHandler *Handler); + void RemovePragmaHandler(PragmaHandler *Handler) { + RemovePragmaHandler(llvm::StringRef(), Handler); + } /// \brief Add the specified comment handler to the preprocessor. void AddCommentHandler(CommentHandler *Handler); @@ -871,7 +877,11 @@ private: //===--------------------------------------------------------------------===// // Caching stuff. void CachingLex(Token &Result); - bool InCachingLexMode() const { return CurPPLexer == 0 && CurTokenLexer == 0;} + bool InCachingLexMode() const { + // If the Lexer pointers are 0 and IncludeMacroStack is empty, it means + // that we are past EOF, not that we are in CachingLex mode. + return CurPPLexer == 0 && CurTokenLexer == 0 && !IncludeMacroStack.empty(); + } void EnterCachingLexMode(); void ExitCachingLexMode() { if (InCachingLexMode()) @@ -918,6 +928,7 @@ public: void HandlePragmaSystemHeader(Token &SysHeaderTok); void HandlePragmaDependency(Token &DependencyTok); void HandlePragmaComment(Token &CommentTok); + void HandlePragmaMessage(Token &MessageTok); // Return true and store the first token only if any CommentHandler // has inserted some tokens and getCommentRetentionState() is false. bool HandleComment(Token &Token, SourceRange Comment); diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h index b5dde9a700e8..bd9b46869a35 100644 --- a/include/clang/Lex/Token.h +++ b/include/clang/Lex/Token.h @@ -148,6 +148,7 @@ public: Kind = tok::unknown; Flags = 0; PtrData = 0; + UintData = 0; Loc = SourceLocation(); } @@ -169,7 +170,7 @@ public: } void setLiteralData(const char *Ptr) { assert(isLiteral() && "Cannot set literal data of non-literal"); - PtrData = (void*)Ptr; + PtrData = const_cast<char*>(Ptr); } void *getAnnotationValue() const { @@ -254,4 +255,9 @@ struct PPConditionalInfo { } // end namespace clang +namespace llvm { + template <> + struct isPodLike<clang::Token> { static const bool value = true; }; +} // end namespace llvm + #endif |