From 0d206996cd68b9f08ae1b4d9da6f16293984302c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 4 Feb 2019 12:11:18 -0500 Subject: Feature/casting tidyup (#822) * Use 'is' over 'as' where appropriate. * dynamic_cast -> dynamicCast * Replace 'dynamicCast' with 'as' where has no change in behavior/ambiguity. * Replace dynamicCast with as where doesn't change behavior/non ambiguous. --- source/slang/syntax.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'source/slang/syntax.cpp') diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index 38618c7d3..6b58809a6 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -12,10 +12,8 @@ namespace Slang bool BasicExpressionType::EqualsImpl(Type * type) { - auto basicType = dynamic_cast(type); - if (basicType == nullptr) - return false; - return basicType->baseType == this->baseType; + auto basicType = dynamicCast(type); + return basicType && basicType->baseType == this->baseType; } RefPtr BasicExpressionType::CreateCanonicalType() @@ -130,7 +128,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool Type::EqualsVal(Val* val) { - if (auto type = dynamic_cast(val)) + if (auto type = dynamicCast(val)) return const_cast(this)->Equals(type); return false; } @@ -455,7 +453,7 @@ void Type::accept(IValVisitor* visitor, void* extra) SubtypeWitness* subtypeWitness, Decl* requirementKey) { - if(auto declaredSubtypeWitness = dynamic_cast(subtypeWitness)) + if(auto declaredSubtypeWitness = as(subtypeWitness)) { if(auto inheritanceDeclRef = declaredSubtypeWitness->declRef.as()) { @@ -529,7 +527,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // the case we especially care about is when this type references a declaration // of a generic parameter, since that is what we might be substituting... - if (auto genericTypeParamDecl = dynamic_cast(declRef.getDecl())) + if (auto genericTypeParamDecl = as(declRef.getDecl())) { // search for a substitution that might apply to us for(auto s = subst.substitutions; s; s = s->outer) @@ -567,7 +565,7 @@ void Type::accept(IValVisitor* visitor, void* extra) } } } - else if (auto globalGenParam = dynamic_cast(declRef.getDecl())) + else if (auto globalGenParam = as(declRef.getDecl())) { // search for a substitution that might apply to us for(auto s = subst.substitutions; s; s = s->outer) @@ -1275,7 +1273,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool GenericParamIntVal::EqualsVal(Val* val) { - if (auto genericParamVal = dynamic_cast(val)) + if (auto genericParamVal = as(val)) { return declRef.Equals(genericParamVal->declRef); } @@ -1365,7 +1363,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // both must be NULL, or non-NULL if (!this || !subst) return !this && !subst; - auto genericSubst = dynamic_cast(subst); + auto genericSubst = as(subst); if (!genericSubst) return false; if (genericDecl != genericSubst->genericDecl) @@ -1415,7 +1413,7 @@ void Type::accept(IValVisitor* visitor, void* extra) if (!subst) return false; - if (auto thisTypeSubst = dynamic_cast(subst)) + if (auto thisTypeSubst = as(subst)) { return witness->EqualsVal(thisTypeSubst->witness); } @@ -1464,7 +1462,7 @@ void Type::accept(IValVisitor* visitor, void* extra) { if (!subst) return false; - if (auto genSubst = dynamic_cast(subst)) + if (auto genSubst = as(subst)) { if (paramDecl != genSubst->paramDecl) return false; @@ -1900,7 +1898,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // to the parent declaration as were applied to the child. RefPtr substToApply = substitutions.substitutions; - if(auto interfaceDecl = dynamic_cast(decl)) + if(auto interfaceDecl = as(decl)) { // The declaration being referenced is an `interface` declaration, // and there might be a this-type substitution in place. @@ -1916,7 +1914,7 @@ void Type::accept(IValVisitor* visitor, void* extra) } } - if (auto parentGenericDecl = dynamic_cast(parentDecl)) + if (auto parentGenericDecl = as(parentDecl)) { // The parent of this declaration is a generic, which means // that the decl-ref to the current declaration might include @@ -2152,7 +2150,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool TypeEqualityWitness::EqualsVal(Val* val) { - auto otherWitness = dynamic_cast(val); + auto otherWitness = as(val); if (!otherWitness) return false; return sub->Equals(otherWitness->sub); @@ -2178,7 +2176,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool DeclaredSubtypeWitness::EqualsVal(Val* val) { - auto otherWitness = dynamic_cast(val); + auto otherWitness = as(val); if(!otherWitness) return false; @@ -2347,7 +2345,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool TransitiveSubtypeWitness::EqualsVal(Val* val) { - auto otherWitness = dynamic_cast(val); + auto otherWitness = as(val); if(!otherWitness) return false; -- cgit v1.2.3