summaryrefslogtreecommitdiffstats
path: root/clang/utils
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2019-12-10 16:20:36 -0500
committerJohn McCall <rjmccall@apple.com>2019-12-14 00:16:47 -0500
commit30066e522c94a193dbcae9bc4d4005f8a137bd4b (patch)
tree949f5ff5f8a5be1eed40e8bc91005c66434872bd /clang/utils
parentf39e1efaf5b0d4abb08bd042a3bae9a772836b5f (diff)
downloadbcm5719-llvm-30066e522c94a193dbcae9bc4d4005f8a137bd4b.tar.gz
bcm5719-llvm-30066e522c94a193dbcae9bc4d4005f8a137bd4b.zip
Extract out WrappedRecord as a convenience base class; NFC.
Diffstat (limited to 'clang/utils')
-rw-r--r--clang/utils/TableGen/ASTTableGen.h51
1 files changed, 30 insertions, 21 deletions
diff --git a/clang/utils/TableGen/ASTTableGen.h b/clang/utils/TableGen/ASTTableGen.h
index 3d623aa45b2..46f0ee8d05d 100644
--- a/clang/utils/TableGen/ASTTableGen.h
+++ b/clang/utils/TableGen/ASTTableGen.h
@@ -42,41 +42,50 @@
namespace clang {
namespace tblgen {
-/// An (optional) reference to a TableGen node representing a class
-/// in one of Clang's AST hierarchies.
-class ASTNode {
+class WrappedRecord {
llvm::Record *Record;
+
+protected:
+ WrappedRecord(llvm::Record *record = nullptr) : Record(record) {}
+
+ llvm::Record *get() const {
+ assert(Record && "accessing null record");
+ return Record;
+ }
+
public:
- ASTNode(llvm::Record *record = nullptr) : Record(record) {}
+ llvm::Record *getRecord() const { return Record; }
explicit operator bool() const { return Record != nullptr; }
- llvm::Record *getRecord() const { return Record; }
- llvm::StringRef getName() const {
- assert(Record && "getting name of null record");
- return Record->getName();
- }
llvm::ArrayRef<llvm::SMLoc> getLoc() const {
- assert(Record && "getting location of null record");
- return Record->getLoc();
+ return get()->getLoc();
+ }
+
+ /// Does the node inherit from the given TableGen class?
+ bool isSubClassOf(llvm::StringRef className) const {
+ return get()->isSubClassOf(className);
+ }
+};
+
+/// An (optional) reference to a TableGen node representing a class
+/// in one of Clang's AST hierarchies.
+class ASTNode : public WrappedRecord {
+public:
+ ASTNode(llvm::Record *record = nullptr) : WrappedRecord(record) {}
+
+ llvm::StringRef getName() const {
+ return get()->getName();
}
/// Return the node for the base, if there is one.
ASTNode getBase() const {
- assert(Record && "getting base of null record");
- return Record->getValueAsOptionalDef(BaseFieldName);
+ return get()->getValueAsOptionalDef(BaseFieldName);
}
/// Is the corresponding class abstract?
bool isAbstract() const {
- assert(Record && "querying null record");
- return Record->getValueAsBit(AbstractFieldName);
- }
-
- /// Does the node inherit from the given TableGen class?
- bool isSubClassOf(llvm::StringRef className) const {
- assert(Record && "querying null record");
- return Record->isSubClassOf(className);
+ return get()->getValueAsBit(AbstractFieldName);
}
friend bool operator<(ASTNode lhs, ASTNode rhs) {
OpenPOWER on IntegriCloud