From 11c547d1e94fa620f527c3590174e6e25ab21883 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 31 Jan 2019 10:14:26 -0500 Subject: Feature/as refactor (#817) * Made dynamicCast a free function. * Replace As with as or dynamicCast depending on if it is a type. * Fix problem with using non smart pointer cast. * Removed legacy asXXXX methods. * Remove As from Type. * Removed As from Qual type -> made coercable into Type*, such that can just use free 'as'. * Remove left over QualType::As() impl. * Remove As from SyntaxNodeBase. * Made as for instructions implemented by dynamicCast. * Replace As on DeclRef. Use the global as<> to do the cast. * Add const safe versions of dynamicCast and as for IRInst --- source/slang/syntax.cpp | 200 ++++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 101 deletions(-) (limited to 'source/slang/syntax.cpp') diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index fe8b2c4fe..2be1a79ed 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -130,11 +130,6 @@ void Type::accept(IValVisitor* visitor, void* extra) return false; } - NamedExpressionType* Type::AsNamedType() - { - return dynamic_cast(this); - } - RefPtr Type::SubstituteImpl(SubstitutionSet subst, int* ioDiff) { int diff = 0; @@ -174,11 +169,12 @@ void Type::accept(IValVisitor* visitor, void* extra) { return IsTexture() || IsSampler(); } + bool Type::IsStruct() { - auto declRefType = AsDeclRefType(); + auto declRefType = as(this); if (!declRefType) return false; - auto structDeclRef = declRefType->declRef.As(); + auto structDeclRef = declRefType->declRef.as(); if (!structDeclRef) return false; return true; } @@ -276,29 +272,29 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr Session::getPtrType( RefPtr valueType) { - return getPtrType(valueType, "PtrType").As(); + return getPtrType(valueType, "PtrType").dynamicCast(); } // Construct the type `Out` RefPtr Session::getOutType(RefPtr valueType) { - return getPtrType(valueType, "OutType").As(); + return getPtrType(valueType, "OutType").dynamicCast(); } RefPtr Session::getInOutType(RefPtr valueType) { - return getPtrType(valueType, "InOutType").As(); + return getPtrType(valueType, "InOutType").dynamicCast(); } RefPtr Session::getRefType(RefPtr valueType) { - return getPtrType(valueType, "RefType").As(); + return getPtrType(valueType, "RefType").dynamicCast(); } RefPtr Session::getPtrType(RefPtr valueType, char const* ptrTypeName) { auto genericDecl = findMagicDecl( - this, ptrTypeName).As(); + this, ptrTypeName).dynamicCast(); return getPtrType(valueType, genericDecl); } @@ -314,7 +310,7 @@ void Type::accept(IValVisitor* visitor, void* extra) auto rsType = DeclRefType::Create( this, declRef); - return rsType->As(); + return as( rsType); } RefPtr Session::getArrayType( @@ -341,7 +337,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool ArrayExpressionType::EqualsImpl(Type * type) { - auto arrType = type->AsArrayType(); + auto arrType = as(type); if (!arrType) return false; return (areValsEqual(ArrayLength, arrType->ArrayLength) && baseType->Equals(arrType->baseType.Ptr())); @@ -350,8 +346,8 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr ArrayExpressionType::SubstituteImpl(SubstitutionSet subst, int* ioDiff) { int diff = 0; - auto elementType = baseType->SubstituteImpl(subst, &diff).As(); - auto arrlen = ArrayLength->SubstituteImpl(subst, &diff).As(); + auto elementType = baseType->SubstituteImpl(subst, &diff).dynamicCast(); + auto arrlen = ArrayLength->SubstituteImpl(subst, &diff).dynamicCast(); SLANG_ASSERT(arrlen); if (diff) { @@ -401,7 +397,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool DeclRefType::EqualsImpl(Type * type) { - if (auto declRefType = type->AsDeclRefType()) + if (auto declRefType = as(type)) { return declRef.Equals(declRefType->declRef); } @@ -432,7 +428,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr RequirementWitness::getWitnessTable() { SLANG_ASSERT(getFlavor() == Flavor::witnessTable); - return m_obj.As(); + return m_obj.dynamicCast(); } @@ -464,7 +460,7 @@ void Type::accept(IValVisitor* visitor, void* extra) { if(auto declaredSubtypeWitness = dynamic_cast(subtypeWitness)) { - if(auto inheritanceDeclRef = declaredSubtypeWitness->declRef.As()) + if(auto inheritanceDeclRef = declaredSubtypeWitness->declRef.as()) { // A conformance that was declared as part of an inheritance clause // will have built up a dictionary of the satisfying declarations @@ -500,7 +496,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // reference to `ISidekick.Hero` with a this-type substitution that references // the `{S:ISidekick}` declaration as a witness. // - // The front-end will expand the generic appliation `followHero>` + // The front-end will expand the generic application `followHero>` // to `followHero, {Sidekick:ISidekick}[H->Batman]>` // (that is, the hidden second parameter will reference the inheritance // clause on `Sidekick`, with a substitution to map `H` to `Batman`. @@ -541,7 +537,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // search for a substitution that might apply to us for(auto s = subst.substitutions; s; s = s->outer) { - auto genericSubst = s.As(); + auto genericSubst = s.dynamicCast(); if(!genericSubst) continue; @@ -560,11 +556,11 @@ void Type::accept(IValVisitor* visitor, void* extra) (*ioDiff)++; return genericSubst->args[index]; } - else if (auto typeParam = m.As()) + else if (auto typeParam = as(m)) { index++; } - else if (auto valParam = m.As()) + else if (auto valParam = as(m)) { index++; } @@ -579,7 +575,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // search for a substitution that might apply to us for(auto s = subst.substitutions; s; s = s->outer) { - auto genericSubst = s.As(); + auto genericSubst = as(s); if(!genericSubst) continue; @@ -604,15 +600,15 @@ void Type::accept(IValVisitor* visitor, void* extra) // the outer interface, then try to replace the type with the // actual value of the associated type for the given implementation. // - if(auto substAssocTypeDecl = substDeclRef.decl->As()) + if(auto substAssocTypeDecl = as(substDeclRef.decl)) { for(auto s = substDeclRef.substitutions.substitutions; s; s = s->outer) { - auto thisSubst = s.As(); + auto thisSubst = s.as(); if(!thisSubst) continue; - if(auto interfaceDecl = substAssocTypeDecl->ParentDecl->As()) + if(auto interfaceDecl = as(substAssocTypeDecl->ParentDecl)) { if(thisSubst->interfaceDecl == interfaceDecl) { @@ -644,14 +640,14 @@ void Type::accept(IValVisitor* visitor, void* extra) static RefPtr ExtractGenericArgType(RefPtr val) { - auto type = val.As(); + auto type = val.dynamicCast(); SLANG_RELEASE_ASSERT(type.Ptr()); return type; } static RefPtr ExtractGenericArgInteger(RefPtr val) { - auto intVal = val.As(); + auto intVal = val.as(); SLANG_RELEASE_ASSERT(intVal.Ptr()); return intVal; } @@ -690,7 +686,7 @@ void Type::accept(IValVisitor* visitor, void* extra) dd = parentDecl; - if(auto genericParentDecl = parentDecl.As()) + if(auto genericParentDecl = parentDecl.as()) { // Don't specialize any parameters of a generic. if(childDecl != genericParentDecl->inner) @@ -700,7 +696,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr foundSubst; for(auto s = declRef.substitutions.substitutions; s; s = s->outer) { - auto genSubst = s.As(); + auto genSubst = s.as(); if(!genSubst) continue; @@ -753,7 +749,7 @@ void Type::accept(IValVisitor* visitor, void* extra) GenericSubstitution* subst = nullptr; for(auto s = declRef.substitutions.substitutions; s; s = s->outer) { - if(auto genericSubst = s.As()) + if(auto genericSubst = s.as()) { subst = genericSubst; break; @@ -967,7 +963,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool ErrorType::EqualsImpl(Type* type) { - if (auto errorType = type->As()) + if (auto errorType = as(type)) return true; return false; } @@ -1041,7 +1037,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool FuncType::EqualsImpl(Type * type) { - if (auto funcType = type->As()) + if (auto funcType = as(type)) { auto paramCount = getParamCount(); auto otherParamCount = funcType->getParamCount(); @@ -1072,13 +1068,13 @@ void Type::accept(IValVisitor* visitor, void* extra) int diff = 0; // result type - RefPtr substResultType = resultType->SubstituteImpl(subst, &diff).As(); + RefPtr substResultType = resultType->SubstituteImpl(subst, &diff).dynamicCast(); // parameter types List> substParamTypes; for( auto pp : paramTypes ) { - substParamTypes.Add(pp->SubstituteImpl(subst, &diff).As()); + substParamTypes.Add(pp->SubstituteImpl(subst, &diff).dynamicCast()); } // early exit for no change... @@ -1138,7 +1134,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool TypeType::EqualsImpl(Type * t) { - if (auto typeType = t->As()) + if (auto typeType = as(t)) { return t->Equals(typeType->type); } @@ -1167,7 +1163,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool GenericDeclRefType::EqualsImpl(Type * type) { - if (auto genericDeclRefType = type->As()) + if (auto genericDeclRefType = as(type)) { return declRef.Equals(genericDeclRefType->declRef); } @@ -1197,7 +1193,7 @@ void Type::accept(IValVisitor* visitor, void* extra) BasicExpressionType* VectorExpressionType::GetScalarType() { - return elementType->AsBasicType(); + return as(elementType); } // @@ -1206,7 +1202,7 @@ void Type::accept(IValVisitor* visitor, void* extra) { for(RefPtr s = subst; s; s = s->outer) { - if(auto genericSubst = s.As()) + if(auto genericSubst = as(s)) return genericSubst; } return nullptr; @@ -1223,22 +1219,22 @@ void Type::accept(IValVisitor* visitor, void* extra) BasicExpressionType* MatrixExpressionType::GetScalarType() { - return getElementType()->AsBasicType(); + return as(getElementType()); } Type* MatrixExpressionType::getElementType() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[0].As().Ptr(); + return dynamicCast(findInnerMostGenericSubstitution(declRef.substitutions)->args[0]); } IntVal* MatrixExpressionType::getRowCount() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[1].As().Ptr(); + return dynamicCast(findInnerMostGenericSubstitution(declRef.substitutions)->args[1]); } IntVal* MatrixExpressionType::getColumnCount() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[2].As().Ptr(); + return dynamicCast(findInnerMostGenericSubstitution(declRef.substitutions)->args[2]); } RefPtr MatrixExpressionType::getRowType() @@ -1255,7 +1251,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr elementCount) { auto vectorGenericDecl = findMagicDecl( - this, "Vector").As(); + this, "Vector").as(); auto vectorTypeDecl = vectorGenericDecl->inner; auto substitutions = new GenericSubstitution(); @@ -1265,9 +1261,9 @@ void Type::accept(IValVisitor* visitor, void* extra) auto declRef = DeclRef(vectorTypeDecl.Ptr(), substitutions); - return DeclRefType::Create( + return as(DeclRefType::Create( this, - declRef)->As(); + declRef)); } @@ -1275,7 +1271,7 @@ void Type::accept(IValVisitor* visitor, void* extra) Type* PtrTypeBase::getValueType() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[0].As().Ptr(); + return dynamicCast(findInnerMostGenericSubstitution(declRef.substitutions)->args[0]); } // GenericParamIntVal @@ -1304,7 +1300,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // search for a substitution that might apply to us for(auto s = subst.substitutions; s; s = s->outer) { - auto genSubst = s.As(); + auto genSubst = s.as(); if(!genSubst) continue; @@ -1323,11 +1319,11 @@ void Type::accept(IValVisitor* visitor, void* extra) (*ioDiff)++; return genSubst->args[index]; } - else if (auto typeParam = m.As()) + else if (auto typeParam = as(m)) { index++; } - else if (auto valParam = m.As()) + else if (auto valParam = as(m)) { index++; } @@ -1337,7 +1333,7 @@ void Type::accept(IValVisitor* visitor, void* extra) } } - // Nothing found: don't substittue. + // Nothing found: don't substitute. return this; } @@ -1402,8 +1398,10 @@ void Type::accept(IValVisitor* visitor, void* extra) int diff = 0; if(substOuter != outer) diff++; - auto substWitness = witness->SubstituteImpl(substSet, &diff).As(); + // NOTE: Must use .as because we must have a smart pointer here to keep in scope. + auto substWitness = witness->SubstituteImpl(substSet, &diff).as(); + if (!diff) return this; (*ioDiff)++; @@ -1440,7 +1438,7 @@ void Type::accept(IValVisitor* visitor, void* extra) if(substOuter != outer) diff++; - auto substActualType = actualType->SubstituteImpl(substSet, &diff).As(); + auto substActualType = actualType->SubstituteImpl(substSet, &diff).dynamicCast(); List substConstraintArgs; for(auto constraintArg : constraintArgs) @@ -1499,7 +1497,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // Otherwise we need to recurse on the type structure // and apply substitutions where it makes sense - return type->Substitute(substitutions).As(); + return type->Substitute(substitutions).dynamicCast(); } DeclRefBase DeclRefBase::Substitute(DeclRefBase declRef) const @@ -1529,7 +1527,7 @@ void Type::accept(IValVisitor* visitor, void* extra) Decl* dd = decl; while(dd) { - if(auto interfaceDecl = dd->As()) + if(auto interfaceDecl = as(dd)) return interfaceDecl; dd = dd->ParentDecl; @@ -1543,7 +1541,7 @@ void Type::accept(IValVisitor* visitor, void* extra) { for(auto s = substs; s; s = s->outer) { - auto gSubst = s.As(); + auto gSubst = s.as(); if(!gSubst) continue; @@ -1576,7 +1574,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // a recursive case that skips the rest of the function. for(auto specSubst = substsToSpecialize; specSubst; specSubst = specSubst->outer) { - auto specGlobalGenericSubst = specSubst.As(); + auto specGlobalGenericSubst = specSubst.as(); if(!specGlobalGenericSubst) continue; @@ -1607,7 +1605,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // the end of the list in all cases, so lets advance // until we see them. RefPtr appGlobalGenericSubsts = substsToApply; - while(appGlobalGenericSubsts && !appGlobalGenericSubsts.As()) + while(appGlobalGenericSubsts && !appGlobalGenericSubsts.as()) appGlobalGenericSubsts = appGlobalGenericSubsts->outer; @@ -1627,7 +1625,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr* link = &resultSubst; for(auto appSubst = appGlobalGenericSubsts; appSubst; appSubst = appSubst->outer) { - auto appGlobalGenericSubst = appSubst.As(); + auto appGlobalGenericSubst = appSubst.as(); if(!appSubst) continue; @@ -1661,7 +1659,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // Construct new substitutions to apply to a declaration, - // based on a provided substituion set to be applied + // based on a provided substitution set to be applied RefPtr specializeSubstitutions( Decl* declToSpecialize, RefPtr substsToSpecialize, @@ -1684,11 +1682,11 @@ void Type::accept(IValVisitor* visitor, void* extra) // corresponding to that decl. for(Decl* ancestorDecl = declToSpecialize; ancestorDecl; ancestorDecl = ancestorDecl->ParentDecl) { - if(auto ancestorGenericDecl = ancestorDecl->As()) + if(auto ancestorGenericDecl = as(ancestorDecl)) { // The declaration is nested inside a generic. // Does it already have a specialization for that generic? - if(auto specGenericSubst = substsToSpecialize.As()) + if(auto specGenericSubst = substsToSpecialize.as()) { if(specGenericSubst->genericDecl == ancestorGenericDecl) { @@ -1722,7 +1720,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // for(auto s = substsToApply; s; s = s->outer) { - auto appGenericSubst = s.As(); + auto appGenericSubst = s.as(); if(!appGenericSubst) continue; @@ -1750,7 +1748,7 @@ void Type::accept(IValVisitor* visitor, void* extra) return firstSubst; } } - else if(auto ancestorInterfaceDecl = ancestorDecl->As()) + else if(auto ancestorInterfaceDecl = as(ancestorDecl)) { // The task is basically the same as for the generic case: // We want to see if there is any existing substitution that @@ -1758,7 +1756,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // The declaration is nested inside a generic. // Does it already have a specialization for that generic? - if(auto specThisTypeSubst = substsToSpecialize.As()) + if(auto specThisTypeSubst = substsToSpecialize.as()) { if(specThisTypeSubst->interfaceDecl == ancestorInterfaceDecl) { @@ -1787,7 +1785,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // for(auto s = substsToApply; s; s = s->outer) { - auto appThisTypeSubst = s.As(); + auto appThisTypeSubst = s.as(); if(!appThisTypeSubst) continue; @@ -1818,7 +1816,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // in either substitution. // // As an invariant, there should *not* be any generic or this-type - // substitutiosn in `substToSpecialize`, because otherwise they + // substitutions in `substToSpecialize`, because otherwise they // would be specializations that don't actually apply to the given // declaration. // @@ -1865,7 +1863,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // TODO: The old code here used to try to translate a decl-ref // to an associated type in a decl-ref for the concrete type - // in a paarticular implementation. + // in a particular implementation. // // I have only kept that logic in `DeclRefType::SubstituteImpl`, // but it may turn out it is needed here too. @@ -1907,7 +1905,7 @@ void Type::accept(IValVisitor* visitor, void* extra) // and there might be a this-type substitution in place. // A reference to the parent of the interface declaration // should not include that substitution. - if(auto thisTypeSubst = substToApply.As()) + if(auto thisTypeSubst = substToApply.as()) { if(thisTypeSubst->interfaceDecl == interfaceDecl) { @@ -1921,11 +1919,11 @@ void Type::accept(IValVisitor* visitor, void* extra) { // The parent of this declaration is a generic, which means // that the decl-ref to the current declaration might include - // substitutiosn that specialize the generic parameters. + // substitutions that specialize the generic parameters. // A decl-ref to the parent generic should *not* include // those substitutions. // - if(auto genericSubst = substToApply.As()) + if(auto genericSubst = substToApply.as()) { if(genericSubst->genericDecl == parentGenericDecl) { @@ -1963,7 +1961,7 @@ void Type::accept(IValVisitor* visitor, void* extra) IntegerLiteralValue GetIntVal(RefPtr val) { - if (auto constantVal = val.As()) + if (auto constantVal = as(val)) { return constantVal->value; } @@ -1975,7 +1973,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool ConstantIntVal::EqualsVal(Val* val) { - if (auto intVal = dynamic_cast(val)) + if (auto intVal = dynamicCast(val)) return value == intVal->value; return false; } @@ -2047,12 +2045,12 @@ void Type::accept(IValVisitor* visitor, void* extra) Type* HLSLPatchType::getElementType() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[0].As().Ptr(); + return dynamicCast(findInnerMostGenericSubstitution(declRef.substitutions)->args[0]); } IntVal* HLSLPatchType::getElementCount() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[1].As().Ptr(); + return dynamicCast(findInnerMostGenericSubstitution(declRef.substitutions)->args[1]); } // Constructors for types @@ -2083,7 +2081,7 @@ void Type::accept(IValVisitor* visitor, void* extra) Session* session, DeclRef const& declRef) { - DeclRef specializedDeclRef = createDefaultSubstitutionsIfNeeded(session, declRef).As(); + DeclRef specializedDeclRef = createDefaultSubstitutionsIfNeeded(session, declRef).as(); auto namedType = new NamedExpressionType(specializedDeclRef); namedType->setSession(session); @@ -2162,8 +2160,8 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr TypeEqualityWitness::SubstituteImpl(SubstitutionSet subst, int * ioDiff) { RefPtr rs = new TypeEqualityWitness(); - rs->sub = sub->SubstituteImpl(subst, ioDiff).As(); - rs->sup = sup->SubstituteImpl(subst, ioDiff).As(); + rs->sub = sub->SubstituteImpl(subst, ioDiff).dynamicCast(); + rs->sup = sup->SubstituteImpl(subst, ioDiff).dynamicCast(); return rs; } @@ -2194,7 +2192,7 @@ void Type::accept(IValVisitor* visitor, void* extra) { for(RefPtr s = substs; s; s = s->outer) { - auto thisTypeSubst = s.As(); + auto thisTypeSubst = s.dynamicCast(); if(!thisTypeSubst) continue; @@ -2209,14 +2207,14 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr DeclaredSubtypeWitness::SubstituteImpl(SubstitutionSet subst, int * ioDiff) { - if (auto genConstraintDeclRef = declRef.As()) + if (auto genConstraintDeclRef = declRef.as()) { auto genConstraintDecl = genConstraintDeclRef.getDecl(); // search for a substitution that might apply to us for(auto s = subst.substitutions; s; s = s->outer) { - if(auto genericSubst = s.As()) + if(auto genericSubst = s.as()) { // the generic decl associated with the substitution list must be // the generic decl that declared this parameter @@ -2228,7 +2226,7 @@ void Type::accept(IValVisitor* visitor, void* extra) UInt index = 0; for (auto m : genericDecl->Members) { - if (auto constraintParam = m.As()) + if (auto constraintParam = m.dynamicCast()) { if (constraintParam.Ptr() == declRef.getDecl()) { @@ -2247,7 +2245,7 @@ void Type::accept(IValVisitor* visitor, void* extra) return genericSubst->args[index + ordinaryParamCount]; } } - else if(auto globalGenericSubst = s.As()) + else if(auto globalGenericSubst = s.as()) { // check if the substitution is really about this global generic type parameter if (globalGenericSubst->paramDecl != genConstraintDecl->ParentDecl) @@ -2267,8 +2265,8 @@ void Type::accept(IValVisitor* visitor, void* extra) // Perform substitution on the constituent elements. int diff = 0; - auto substSub = sub->SubstituteImpl(subst, &diff).As(); - auto substSup = sup->SubstituteImpl(subst, &diff).As(); + auto substSub = sub->SubstituteImpl(subst, &diff).dynamicCast(); + auto substSup = sup->SubstituteImpl(subst, &diff).dynamicCast(); auto substDeclRef = declRef.SubstituteImpl(subst, &diff); if (!diff) return this; @@ -2285,11 +2283,11 @@ void Type::accept(IValVisitor* visitor, void* extra) // so we'll need to change this location in the code if we ever clean // up the hierarchy. // - if (auto substTypeConstraintDecl = substDeclRef.decl->As()) + if (auto substTypeConstraintDecl = as(substDeclRef.decl)) { - if (auto substAssocTypeDecl = substTypeConstraintDecl->ParentDecl->As()) + if (auto substAssocTypeDecl = as(substTypeConstraintDecl->ParentDecl)) { - if (auto interfaceDecl = substAssocTypeDecl->ParentDecl->As()) + if (auto interfaceDecl = as(substAssocTypeDecl->ParentDecl)) { // At this point we have a constraint decl for an associated type, // and we nee to see if we are dealing with a concrete substitution @@ -2362,9 +2360,9 @@ void Type::accept(IValVisitor* visitor, void* extra) { int diff = 0; - RefPtr substSub = sub->SubstituteImpl(subst, &diff).As(); - RefPtr substSup = sup->SubstituteImpl(subst, &diff).As(); - RefPtr substSubToMid = subToMid->SubstituteImpl(subst, &diff).As(); + RefPtr substSub = sub->SubstituteImpl(subst, &diff).dynamicCast(); + RefPtr substSup = sup->SubstituteImpl(subst, &diff).dynamicCast(); + RefPtr substSubToMid = subToMid->SubstituteImpl(subst, &diff).dynamicCast(); DeclRef substMidToSup = midToSup.SubstituteImpl(subst, &diff); // If nothing changed, then we can bail out early. @@ -2463,7 +2461,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool ExtractExistentialType::EqualsImpl(Type* type) { - if( auto extractExistential = type->As() ) + if( auto extractExistential = as(type) ) { return declRef.Equals(extractExistential->declRef); } @@ -2498,7 +2496,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool ExtractExistentialSubtypeWitness::EqualsVal(Val* val) { - if( auto extractWitness = val->dynamicCast() ) + if( auto extractWitness = dynamicCast(val) ) { return declRef.Equals(extractWitness->declRef); } @@ -2524,8 +2522,8 @@ void Type::accept(IValVisitor* visitor, void* extra) int diff = 0; auto substDeclRef = declRef.SubstituteImpl(subst, &diff); - auto substSub = sub->SubstituteImpl(subst, &diff).As(); - auto substSup = sup->SubstituteImpl(subst, &diff).As(); + auto substSub = sub->SubstituteImpl(subst, &diff).dynamicCast(); + auto substSup = sup->SubstituteImpl(subst, &diff).dynamicCast(); if(!diff) return this; @@ -2561,7 +2559,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool TaggedUnionType::EqualsImpl(Type* type) { - auto taggedUnion = type->As(); + auto taggedUnion = as(type); if(!taggedUnion) return false; @@ -2608,7 +2606,7 @@ void Type::accept(IValVisitor* visitor, void* extra) List> substCaseTypes; for( auto caseType : caseTypes ) { - substCaseTypes.Add(caseType->SubstituteImpl(subst, &diff).As()); + substCaseTypes.Add(caseType->SubstituteImpl(subst, &diff).dynamicCast()); } if(!diff) return this; @@ -2628,7 +2626,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool TaggedUnionSubtypeWitness::EqualsVal(Val* val) { - auto taggedUnionWitness = val->dynamicCast(); + auto taggedUnionWitness = dynamicCast(val); if(!taggedUnionWitness) return false; @@ -2674,8 +2672,8 @@ RefPtr TaggedUnionSubtypeWitness::SubstituteImpl(SubstitutionSet subst, int { int diff = 0; - auto substSub = sub->SubstituteImpl(subst, &diff).As(); - auto substSup = sup->SubstituteImpl(subst, &diff).As(); + auto substSub = sub->SubstituteImpl(subst, &diff).dynamicCast(); + auto substSup = sup->SubstituteImpl(subst, &diff).dynamicCast(); List> substCaseWitnesses; for( auto caseWitness : caseWitnesses ) -- cgit v1.2.3