|
42 | 42 | namespace clang {
|
43 | 43 | namespace tblgen {
|
44 | 44 |
|
45 |
| -/// An (optional) reference to a TableGen node representing a class |
46 |
| -/// in one of Clang's AST hierarchies. |
47 |
| -class ASTNode { |
| 45 | +class WrappedRecord { |
48 | 46 | llvm::Record *Record;
|
| 47 | + |
| 48 | +protected: |
| 49 | + WrappedRecord(llvm::Record *record = nullptr) : Record(record) {} |
| 50 | + |
| 51 | + llvm::Record *get() const { |
| 52 | + assert(Record && "accessing null record"); |
| 53 | + return Record; |
| 54 | + } |
| 55 | + |
49 | 56 | public:
|
50 |
| - ASTNode(llvm::Record *record = nullptr) : Record(record) {} |
| 57 | + llvm::Record *getRecord() const { return Record; } |
51 | 58 |
|
52 | 59 | explicit operator bool() const { return Record != nullptr; }
|
53 | 60 |
|
54 |
| - llvm::Record *getRecord() const { return Record; } |
55 |
| - llvm::StringRef getName() const { |
56 |
| - assert(Record && "getting name of null record"); |
57 |
| - return Record->getName(); |
58 |
| - } |
59 | 61 | llvm::ArrayRef<llvm::SMLoc> getLoc() const {
|
60 |
| - assert(Record && "getting location of null record"); |
61 |
| - return Record->getLoc(); |
| 62 | + return get()->getLoc(); |
| 63 | + } |
| 64 | + |
| 65 | + /// Does the node inherit from the given TableGen class? |
| 66 | + bool isSubClassOf(llvm::StringRef className) const { |
| 67 | + return get()->isSubClassOf(className); |
| 68 | + } |
| 69 | +}; |
| 70 | + |
| 71 | +/// An (optional) reference to a TableGen node representing a class |
| 72 | +/// in one of Clang's AST hierarchies. |
| 73 | +class ASTNode : public WrappedRecord { |
| 74 | +public: |
| 75 | + ASTNode(llvm::Record *record = nullptr) : WrappedRecord(record) {} |
| 76 | + |
| 77 | + llvm::StringRef getName() const { |
| 78 | + return get()->getName(); |
62 | 79 | }
|
63 | 80 |
|
64 | 81 | /// Return the node for the base, if there is one.
|
65 | 82 | ASTNode getBase() const {
|
66 |
| - assert(Record && "getting base of null record"); |
67 |
| - return Record->getValueAsOptionalDef(BaseFieldName); |
| 83 | + return get()->getValueAsOptionalDef(BaseFieldName); |
68 | 84 | }
|
69 | 85 |
|
70 | 86 | /// Is the corresponding class abstract?
|
71 | 87 | bool isAbstract() const {
|
72 |
| - assert(Record && "querying null record"); |
73 |
| - return Record->getValueAsBit(AbstractFieldName); |
74 |
| - } |
75 |
| - |
76 |
| - /// Does the node inherit from the given TableGen class? |
77 |
| - bool isSubClassOf(llvm::StringRef className) const { |
78 |
| - assert(Record && "querying null record"); |
79 |
| - return Record->isSubClassOf(className); |
| 88 | + return get()->getValueAsBit(AbstractFieldName); |
80 | 89 | }
|
81 | 90 |
|
82 | 91 | friend bool operator<(ASTNode lhs, ASTNode rhs) {
|
|
0 commit comments