Skip to content

Commit 30066e5

Browse files
committed
Extract out WrappedRecord as a convenience base class; NFC.
1 parent f39e1ef commit 30066e5

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

clang/utils/TableGen/ASTTableGen.h

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,50 @@
4242
namespace clang {
4343
namespace tblgen {
4444

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 {
4846
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+
4956
public:
50-
ASTNode(llvm::Record *record = nullptr) : Record(record) {}
57+
llvm::Record *getRecord() const { return Record; }
5158

5259
explicit operator bool() const { return Record != nullptr; }
5360

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-
}
5961
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();
6279
}
6380

6481
/// Return the node for the base, if there is one.
6582
ASTNode getBase() const {
66-
assert(Record && "getting base of null record");
67-
return Record->getValueAsOptionalDef(BaseFieldName);
83+
return get()->getValueAsOptionalDef(BaseFieldName);
6884
}
6985

7086
/// Is the corresponding class abstract?
7187
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);
8089
}
8190

8291
friend bool operator<(ASTNode lhs, ASTNode rhs) {

0 commit comments

Comments
 (0)