1//===--- Pragma.h - Pragma registration and handling ------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the PragmaHandler and PragmaTable interfaces. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_PRAGMA_H 15#define LLVM_CLANG_PRAGMA_H 16
| 1//===--- Pragma.h - Pragma registration and handling ------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the PragmaHandler and PragmaTable interfaces. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_PRAGMA_H 15#define LLVM_CLANG_PRAGMA_H 16
|
| 17#include "llvm/ADT/StringMap.h" 18#include "llvm/ADT/StringRef.h"
|
17#include <cassert> 18#include <vector> 19 20namespace clang { 21 class Preprocessor; 22 class Token; 23 class IdentifierInfo; 24 class PragmaNamespace; 25 26/// PragmaHandler - Instances of this interface defined to handle the various 27/// pragmas that the language front-end uses. Each handler optionally has a 28/// name (e.g. "pack") and the HandlePragma method is invoked when a pragma with 29/// that identifier is found. If a handler does not match any of the declared 30/// pragmas the handler with a null identifier is invoked, if it exists. 31/// 32/// Note that the PragmaNamespace class can be used to subdivide pragmas, e.g. 33/// we treat "#pragma STDC" and "#pragma GCC" as namespaces that contain other 34/// pragmas. 35class PragmaHandler {
| 19#include <cassert> 20#include <vector> 21 22namespace clang { 23 class Preprocessor; 24 class Token; 25 class IdentifierInfo; 26 class PragmaNamespace; 27 28/// PragmaHandler - Instances of this interface defined to handle the various 29/// pragmas that the language front-end uses. Each handler optionally has a 30/// name (e.g. "pack") and the HandlePragma method is invoked when a pragma with 31/// that identifier is found. If a handler does not match any of the declared 32/// pragmas the handler with a null identifier is invoked, if it exists. 33/// 34/// Note that the PragmaNamespace class can be used to subdivide pragmas, e.g. 35/// we treat "#pragma STDC" and "#pragma GCC" as namespaces that contain other 36/// pragmas. 37class PragmaHandler {
|
36 const IdentifierInfo *Name;
| 38 std::string Name;
|
37public:
| 39public:
|
38 PragmaHandler(const IdentifierInfo *name) : Name(name) {}
| 40 explicit PragmaHandler(llvm::StringRef name) : Name(name) {} 41 PragmaHandler() {}
|
39 virtual ~PragmaHandler(); 40
| 42 virtual ~PragmaHandler(); 43
|
41 const IdentifierInfo *getName() const { return Name; }
| 44 llvm::StringRef getName() const { return Name; }
|
42 virtual void HandlePragma(Preprocessor &PP, Token &FirstToken) = 0; 43 44 /// getIfNamespace - If this is a namespace, return it. This is equivalent to 45 /// using a dynamic_cast, but doesn't require RTTI. 46 virtual PragmaNamespace *getIfNamespace() { return 0; } 47}; 48
| 45 virtual void HandlePragma(Preprocessor &PP, Token &FirstToken) = 0; 46 47 /// getIfNamespace - If this is a namespace, return it. This is equivalent to 48 /// using a dynamic_cast, but doesn't require RTTI. 49 virtual PragmaNamespace *getIfNamespace() { return 0; } 50}; 51
|
| 52/// EmptyPragmaHandler - A pragma handler which takes no action, which can be 53/// used to ignore particular pragmas. 54class EmptyPragmaHandler : public PragmaHandler { 55public: 56 EmptyPragmaHandler(); 57 58 virtual void HandlePragma(Preprocessor &PP, Token &FirstToken); 59}; 60
|
49/// PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas, 50/// allowing hierarchical pragmas to be defined. Common examples of namespaces 51/// are "#pragma GCC", "#pragma STDC", and "#pragma omp", but any namespaces may 52/// be (potentially recursively) defined. 53class PragmaNamespace : public PragmaHandler {
| 61/// PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas, 62/// allowing hierarchical pragmas to be defined. Common examples of namespaces 63/// are "#pragma GCC", "#pragma STDC", and "#pragma omp", but any namespaces may 64/// be (potentially recursively) defined. 65class PragmaNamespace : public PragmaHandler {
|
54 /// Handlers - This is the list of handlers in this namespace.
| 66 /// Handlers - This is a map of the handlers in this namespace with their name 67 /// as key.
|
55 ///
| 68 ///
|
56 std::vector<PragmaHandler*> Handlers;
| 69 llvm::StringMap<PragmaHandler*> Handlers;
|
57public:
| 70public:
|
58 PragmaNamespace(const IdentifierInfo *Name) : PragmaHandler(Name) {}
| 71 explicit PragmaNamespace(llvm::StringRef Name) : PragmaHandler(Name) {}
|
59 virtual ~PragmaNamespace(); 60 61 /// FindHandler - Check to see if there is already a handler for the
| 72 virtual ~PragmaNamespace(); 73 74 /// FindHandler - Check to see if there is already a handler for the
|
62 /// specified name. If not, return the handler for the null identifier if it
| 75 /// specified name. If not, return the handler for the null name if it
|
63 /// exists, otherwise return null. If IgnoreNull is true (the default) then 64 /// the null handler isn't returned on failure to match.
| 76 /// exists, otherwise return null. If IgnoreNull is true (the default) then 77 /// the null handler isn't returned on failure to match.
|
65 PragmaHandler *FindHandler(const IdentifierInfo *Name,
| 78 PragmaHandler *FindHandler(llvm::StringRef Name,
|
66 bool IgnoreNull = true) const; 67 68 /// AddPragma - Add a pragma to this namespace. 69 ///
| 79 bool IgnoreNull = true) const; 80 81 /// AddPragma - Add a pragma to this namespace. 82 ///
|
70 void AddPragma(PragmaHandler *Handler) { 71 Handlers.push_back(Handler); 72 }
| 83 void AddPragma(PragmaHandler *Handler);
|
73 74 /// RemovePragmaHandler - Remove the given handler from the 75 /// namespace. 76 void RemovePragmaHandler(PragmaHandler *Handler); 77 78 bool IsEmpty() { 79 return Handlers.empty(); 80 } 81 82 virtual void HandlePragma(Preprocessor &PP, Token &FirstToken); 83 84 virtual PragmaNamespace *getIfNamespace() { return this; } 85}; 86 87 88} // end namespace clang 89 90#endif
| 84 85 /// RemovePragmaHandler - Remove the given handler from the 86 /// namespace. 87 void RemovePragmaHandler(PragmaHandler *Handler); 88 89 bool IsEmpty() { 90 return Handlers.empty(); 91 } 92 93 virtual void HandlePragma(Preprocessor &PP, Token &FirstToken); 94 95 virtual PragmaNamespace *getIfNamespace() { return this; } 96}; 97 98 99} // end namespace clang 100 101#endif
|