From 30066e522c94a193dbcae9bc4d4005f8a137bd4b Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 10 Dec 2019 16:20:36 -0500 Subject: [PATCH] Extract out WrappedRecord as a convenience base class; NFC. --- clang/utils/TableGen/ASTTableGen.h | 51 ++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/clang/utils/TableGen/ASTTableGen.h b/clang/utils/TableGen/ASTTableGen.h index 3d623aa..46f0ee8 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 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) { -- 2.7.4