From 63554988a94b8a4bcf3de77659a0b27c07a0975d Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Fri, 5 Oct 2012 03:32:00 +0000 Subject: [PATCH] tblgen: Use appropriate LLVM-style RTTI functions. Use isa<> or cast<> when semantically that is what is happening. Also some trivial "style" cleanups at fix sites. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165292 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/TableGen/Record.h | 10 +++++----- lib/TableGen/Record.cpp | 30 +++++++++--------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h index 0e75cf42893..079dc8ce8ed 100644 --- a/include/llvm/TableGen/Record.h +++ b/include/llvm/TableGen/Record.h @@ -1085,9 +1085,9 @@ class VarBitInit : public Init { VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) { assert(T->getType() && - (dyn_cast(T->getType()) || - (dyn_cast(T->getType()) && - dyn_cast(T->getType())->getNumBits() > B)) && + (isa(T->getType()) || + (isa(T->getType()) && + cast(T->getType())->getNumBits() > B)) && "Illegal VarBitInit expression!"); } @@ -1120,9 +1120,9 @@ class VarListElementInit : public TypedInit { unsigned Element; VarListElementInit(TypedInit *T, unsigned E) - : TypedInit(dyn_cast(T->getType())->getElementType()), + : TypedInit(cast(T->getType())->getElementType()), TI(T), Element(E) { - assert(T->getType() && dyn_cast(T->getType()) && + assert(T->getType() && isa(T->getType()) && "Illegal VarBitInit expression!"); } diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index e51ae44627b..83f2fff9312 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -113,9 +113,7 @@ Init *BitRecTy::convertValue(IntInit *II) { Init *BitRecTy::convertValue(TypedInit *VI) { RecTy *Ty = VI->getType(); - if (dyn_cast(Ty) || - dyn_cast(Ty) || - dyn_cast(Ty)) + if (isa(Ty) || isa(Ty) || isa(Ty)) return VI; // Accept variable if it is already of bit type! return 0; } @@ -181,7 +179,7 @@ Init *BitsRecTy::convertValue(BitsInit *BI) { } Init *BitsRecTy::convertValue(TypedInit *VI) { - if (Size == 1 && dyn_cast(VI->getType())) + if (Size == 1 && isa(VI->getType())) return BitsInit::get(VI); if (VI->getType()->typeIsConvertibleTo(this)) { @@ -243,7 +241,7 @@ Init *StringRecTy::convertValue(BinOpInit *BO) { Init *StringRecTy::convertValue(TypedInit *TI) { - if (dyn_cast(TI->getType())) + if (isa(TI->getType())) return TI; // Accept variable if already of the right type! return 0; } @@ -263,10 +261,8 @@ Init *ListRecTy::convertValue(ListInit *LI) { else return 0; - ListRecTy *LType = dyn_cast(LI->getType()); - if (LType == 0) { + if (!isa(LI->getType())) return 0; - } return ListInit::get(Elements, this); } @@ -1039,9 +1035,6 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, DagInit *MHSd = dynamic_cast(MHS); ListInit *MHSl = dynamic_cast(MHS); - DagRecTy *DagType = dyn_cast(Type); - ListRecTy *ListType = dyn_cast(Type); - OpInit *RHSo = dynamic_cast(RHS); if (!RHSo) { @@ -1054,7 +1047,7 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, throw TGError(CurRec->getLoc(), "!foreach requires typed variable\n"); } - if ((MHSd && DagType) || (MHSl && ListType)) { + if ((MHSd && isa(Type)) || (MHSl && isa(Type))) { if (MHSd) { Init *Val = MHSd->getOperator(); Init *Result = EvaluateOperation(RHSo, LHS, Val, @@ -1235,13 +1228,9 @@ std::string TernOpInit::getAsString() const { } RecTy *TypedInit::getFieldType(const std::string &FieldName) const { - RecordRecTy *RecordType = dyn_cast(getType()); - if (RecordType) { - RecordVal *Field = RecordType->getRecord()->getValue(FieldName); - if (Field) { + if (RecordRecTy *RecordType = dyn_cast(getType())) + if (RecordVal *Field = RecordType->getRecord()->getValue(FieldName)) return Field->getType(); - } - } return 0; } @@ -1344,7 +1333,7 @@ RecTy *VarInit::getFieldType(const std::string &FieldName) const { Init *VarInit::getFieldInit(Record &R, const RecordVal *RV, const std::string &FieldName) const { - if (dyn_cast(getType())) + if (isa(getType())) if (const RecordVal *Val = R.getValue(VarName)) { if (RV != Val && (RV || dynamic_cast(Val->getValue()))) return 0; @@ -1655,9 +1644,8 @@ void Record::checkName() { const TypedInit *TypedName = dynamic_cast(Name); assert(TypedName && "Record name is not typed!"); RecTy *Type = TypedName->getType(); - if (dyn_cast(Type) == 0) { + if (!isa(Type)) throw TGError(getLoc(), "Record name is not a string!"); - } } DefInit *Record::getDefInit() { -- 2.34.1