aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Lex
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-07-13 09:07:17 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-07-13 09:07:17 +0000
commit9b36c3f0de0105e903130bbda3c4aea7d792c0af (patch)
tree66f0c582d3ebf63b52b90596156e3ddf75814a4f /include/clang/Lex
parentde80ec1fa947855d2e53722a8cd71367ff513481 (diff)
Modify the pragma handlers to accept and use StringRefs instead of IdentifierInfos.
When loading the PCH, IdentifierInfos that are associated with pragmas cause declarations that use these identifiers to be deserialized (e.g. the "clang" pragma causes the "clang" namespace to be loaded). We can avoid this if we just use StringRefs for the pragmas. As a bonus, since we don't have to create and pass IdentifierInfos, the pragma interfaces get a bit more simplified. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108237 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Lex')
-rw-r--r--include/clang/Lex/Pragma.h24
-rw-r--r--include/clang/Lex/Preprocessor.h10
2 files changed, 21 insertions, 13 deletions
diff --git a/include/clang/Lex/Pragma.h b/include/clang/Lex/Pragma.h
index 52f01a9a97..c68555b2f9 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
@@ -60,25 +63,24 @@ public:
/// 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 6c9b9fb96e..1ee4bb6351 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);