diff options
| author | Yong He <yonghe@outlook.com> | 2019-01-31 13:35:03 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-31 13:35:03 -0800 |
| commit | bcb361db7c5a6f8baa9b2012b9ee9778421f1386 (patch) | |
| tree | 9e5e1703e3b06e109bae6db136bbc2e816f96a2f /source/slang/syntax.cpp | |
| parent | c1fe5f295e843d10e24ae0d053fc3813a29aec89 (diff) | |
| parent | f20c64c348393602ed2a9c873386345cc4b493e8 (diff) | |
Merge branch 'master' into crashfix
Diffstat (limited to 'source/slang/syntax.cpp')
| -rw-r--r-- | source/slang/syntax.cpp | 200 |
1 files changed, 99 insertions, 101 deletions
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<NamedExpressionType*>(this); - } - RefPtr<Val> 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<DeclRefType>(this); if (!declRefType) return false; - auto structDeclRef = declRefType->declRef.As<StructDecl>(); + auto structDeclRef = declRefType->declRef.as<StructDecl>(); if (!structDeclRef) return false; return true; } @@ -276,29 +272,29 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<PtrType> Session::getPtrType( RefPtr<Type> valueType) { - return getPtrType(valueType, "PtrType").As<PtrType>(); + return getPtrType(valueType, "PtrType").dynamicCast<PtrType>(); } // Construct the type `Out<valueType>` RefPtr<OutType> Session::getOutType(RefPtr<Type> valueType) { - return getPtrType(valueType, "OutType").As<OutType>(); + return getPtrType(valueType, "OutType").dynamicCast<OutType>(); } RefPtr<InOutType> Session::getInOutType(RefPtr<Type> valueType) { - return getPtrType(valueType, "InOutType").As<InOutType>(); + return getPtrType(valueType, "InOutType").dynamicCast<InOutType>(); } RefPtr<RefType> Session::getRefType(RefPtr<Type> valueType) { - return getPtrType(valueType, "RefType").As<RefType>(); + return getPtrType(valueType, "RefType").dynamicCast<RefType>(); } RefPtr<PtrTypeBase> Session::getPtrType(RefPtr<Type> valueType, char const* ptrTypeName) { auto genericDecl = findMagicDecl( - this, ptrTypeName).As<GenericDecl>(); + this, ptrTypeName).dynamicCast<GenericDecl>(); return getPtrType(valueType, genericDecl); } @@ -314,7 +310,7 @@ void Type::accept(IValVisitor* visitor, void* extra) auto rsType = DeclRefType::Create( this, declRef); - return rsType->As<PtrTypeBase>(); + return as<PtrTypeBase>( rsType); } RefPtr<ArrayExpressionType> 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<ArrayExpressionType>(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<Val> ArrayExpressionType::SubstituteImpl(SubstitutionSet subst, int* ioDiff) { int diff = 0; - auto elementType = baseType->SubstituteImpl(subst, &diff).As<Type>(); - auto arrlen = ArrayLength->SubstituteImpl(subst, &diff).As<IntVal>(); + auto elementType = baseType->SubstituteImpl(subst, &diff).dynamicCast<Type>(); + auto arrlen = ArrayLength->SubstituteImpl(subst, &diff).dynamicCast<IntVal>(); 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<DeclRefType>(type)) { return declRef.Equals(declRefType->declRef); } @@ -432,7 +428,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<WitnessTable> RequirementWitness::getWitnessTable() { SLANG_ASSERT(getFlavor() == Flavor::witnessTable); - return m_obj.As<WitnessTable>(); + return m_obj.dynamicCast<WitnessTable>(); } @@ -464,7 +460,7 @@ void Type::accept(IValVisitor* visitor, void* extra) { if(auto declaredSubtypeWitness = dynamic_cast<DeclaredSubtypeWitness*>(subtypeWitness)) { - if(auto inheritanceDeclRef = declaredSubtypeWitness->declRef.As<InheritanceDecl>()) + if(auto inheritanceDeclRef = declaredSubtypeWitness->declRef.as<InheritanceDecl>()) { // 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<Sidekick<Batman>>` + // The front-end will expand the generic application `followHero<Sidekick<Batman>>` // to `followHero<Sidekick<Batman>, {Sidekick<H>:ISidekick}[H->Batman]>` // (that is, the hidden second parameter will reference the inheritance // clause on `Sidekick<H>`, 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<GenericSubstitution>(); + auto genericSubst = s.dynamicCast<GenericSubstitution>(); 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<GenericTypeParamDecl>()) + else if (auto typeParam = as<GenericTypeParamDecl>(m)) { index++; } - else if (auto valParam = m.As<GenericValueParamDecl>()) + else if (auto valParam = as<GenericValueParamDecl>(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<GlobalGenericParamSubstitution>(); + auto genericSubst = as<GlobalGenericParamSubstitution>(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<AssocTypeDecl>()) + if(auto substAssocTypeDecl = as<AssocTypeDecl>(substDeclRef.decl)) { for(auto s = substDeclRef.substitutions.substitutions; s; s = s->outer) { - auto thisSubst = s.As<ThisTypeSubstitution>(); + auto thisSubst = s.as<ThisTypeSubstitution>(); if(!thisSubst) continue; - if(auto interfaceDecl = substAssocTypeDecl->ParentDecl->As<InterfaceDecl>()) + if(auto interfaceDecl = as<InterfaceDecl>(substAssocTypeDecl->ParentDecl)) { if(thisSubst->interfaceDecl == interfaceDecl) { @@ -644,14 +640,14 @@ void Type::accept(IValVisitor* visitor, void* extra) static RefPtr<Type> ExtractGenericArgType(RefPtr<Val> val) { - auto type = val.As<Type>(); + auto type = val.dynamicCast<Type>(); SLANG_RELEASE_ASSERT(type.Ptr()); return type; } static RefPtr<IntVal> ExtractGenericArgInteger(RefPtr<Val> val) { - auto intVal = val.As<IntVal>(); + auto intVal = val.as<IntVal>(); 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<GenericDecl>()) + if(auto genericParentDecl = parentDecl.as<GenericDecl>()) { // Don't specialize any parameters of a generic. if(childDecl != genericParentDecl->inner) @@ -700,7 +696,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<GenericSubstitution> foundSubst; for(auto s = declRef.substitutions.substitutions; s; s = s->outer) { - auto genSubst = s.As<GenericSubstitution>(); + auto genSubst = s.as<GenericSubstitution>(); 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<GenericSubstitution>()) + if(auto genericSubst = s.as<GenericSubstitution>()) { subst = genericSubst; break; @@ -967,7 +963,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool ErrorType::EqualsImpl(Type* type) { - if (auto errorType = type->As<ErrorType>()) + if (auto errorType = as<ErrorType>(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<FuncType>()) + if (auto funcType = as<FuncType>(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<Type> substResultType = resultType->SubstituteImpl(subst, &diff).As<Type>(); + RefPtr<Type> substResultType = resultType->SubstituteImpl(subst, &diff).dynamicCast<Type>(); // parameter types List<RefPtr<Type>> substParamTypes; for( auto pp : paramTypes ) { - substParamTypes.Add(pp->SubstituteImpl(subst, &diff).As<Type>()); + substParamTypes.Add(pp->SubstituteImpl(subst, &diff).dynamicCast<Type>()); } // 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<TypeType>()) + if (auto typeType = as<TypeType>(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<GenericDeclRefType>()) + if (auto genericDeclRefType = as<GenericDeclRefType>(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<BasicExpressionType>(elementType); } // @@ -1206,7 +1202,7 @@ void Type::accept(IValVisitor* visitor, void* extra) { for(RefPtr<Substitutions> s = subst; s; s = s->outer) { - if(auto genericSubst = s.As<GenericSubstitution>()) + if(auto genericSubst = as<GenericSubstitution>(s)) return genericSubst; } return nullptr; @@ -1223,22 +1219,22 @@ void Type::accept(IValVisitor* visitor, void* extra) BasicExpressionType* MatrixExpressionType::GetScalarType() { - return getElementType()->AsBasicType(); + return as<BasicExpressionType>(getElementType()); } Type* MatrixExpressionType::getElementType() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[0].As<Type>().Ptr(); + return dynamicCast<Type>(findInnerMostGenericSubstitution(declRef.substitutions)->args[0]); } IntVal* MatrixExpressionType::getRowCount() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[1].As<IntVal>().Ptr(); + return dynamicCast<IntVal>(findInnerMostGenericSubstitution(declRef.substitutions)->args[1]); } IntVal* MatrixExpressionType::getColumnCount() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[2].As<IntVal>().Ptr(); + return dynamicCast<IntVal>(findInnerMostGenericSubstitution(declRef.substitutions)->args[2]); } RefPtr<Type> MatrixExpressionType::getRowType() @@ -1255,7 +1251,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<IntVal> elementCount) { auto vectorGenericDecl = findMagicDecl( - this, "Vector").As<GenericDecl>(); + this, "Vector").as<GenericDecl>(); auto vectorTypeDecl = vectorGenericDecl->inner; auto substitutions = new GenericSubstitution(); @@ -1265,9 +1261,9 @@ void Type::accept(IValVisitor* visitor, void* extra) auto declRef = DeclRef<Decl>(vectorTypeDecl.Ptr(), substitutions); - return DeclRefType::Create( + return as<VectorExpressionType>(DeclRefType::Create( this, - declRef)->As<VectorExpressionType>(); + declRef)); } @@ -1275,7 +1271,7 @@ void Type::accept(IValVisitor* visitor, void* extra) Type* PtrTypeBase::getValueType() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[0].As<Type>().Ptr(); + return dynamicCast<Type>(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<GenericSubstitution>(); + auto genSubst = s.as<GenericSubstitution>(); 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<GenericTypeParamDecl>()) + else if (auto typeParam = as<GenericTypeParamDecl>(m)) { index++; } - else if (auto valParam = m.As<GenericValueParamDecl>()) + else if (auto valParam = as<GenericValueParamDecl>(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<SubtypeWitness>(); + // NOTE: Must use .as because we must have a smart pointer here to keep in scope. + auto substWitness = witness->SubstituteImpl(substSet, &diff).as<SubtypeWitness>(); + 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<Type>(); + auto substActualType = actualType->SubstituteImpl(substSet, &diff).dynamicCast<Type>(); List<ConstraintArg> 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<Type>(); + return type->Substitute(substitutions).dynamicCast<Type>(); } 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<InterfaceDecl>()) + if(auto interfaceDecl = as<InterfaceDecl>(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<GlobalGenericParamSubstitution>(); + auto gSubst = s.as<GlobalGenericParamSubstitution>(); 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<GlobalGenericParamSubstitution>(); + auto specGlobalGenericSubst = specSubst.as<GlobalGenericParamSubstitution>(); 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<Substitutions> appGlobalGenericSubsts = substsToApply; - while(appGlobalGenericSubsts && !appGlobalGenericSubsts.As<GlobalGenericParamSubstitution>()) + while(appGlobalGenericSubsts && !appGlobalGenericSubsts.as<GlobalGenericParamSubstitution>()) appGlobalGenericSubsts = appGlobalGenericSubsts->outer; @@ -1627,7 +1625,7 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<Substitutions>* link = &resultSubst; for(auto appSubst = appGlobalGenericSubsts; appSubst; appSubst = appSubst->outer) { - auto appGlobalGenericSubst = appSubst.As<GlobalGenericParamSubstitution>(); + auto appGlobalGenericSubst = appSubst.as<GlobalGenericParamSubstitution>(); 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<Substitutions> specializeSubstitutions( Decl* declToSpecialize, RefPtr<Substitutions> 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<GenericDecl>()) + if(auto ancestorGenericDecl = as<GenericDecl>(ancestorDecl)) { // The declaration is nested inside a generic. // Does it already have a specialization for that generic? - if(auto specGenericSubst = substsToSpecialize.As<GenericSubstitution>()) + if(auto specGenericSubst = substsToSpecialize.as<GenericSubstitution>()) { 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<GenericSubstitution>(); + auto appGenericSubst = s.as<GenericSubstitution>(); if(!appGenericSubst) continue; @@ -1750,7 +1748,7 @@ void Type::accept(IValVisitor* visitor, void* extra) return firstSubst; } } - else if(auto ancestorInterfaceDecl = ancestorDecl->As<InterfaceDecl>()) + else if(auto ancestorInterfaceDecl = as<InterfaceDecl>(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<ThisTypeSubstitution>()) + if(auto specThisTypeSubst = substsToSpecialize.as<ThisTypeSubstitution>()) { 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<ThisTypeSubstitution>(); + auto appThisTypeSubst = s.as<ThisTypeSubstitution>(); 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<ThisTypeSubstitution>()) + if(auto thisTypeSubst = substToApply.as<ThisTypeSubstitution>()) { 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<GenericSubstitution>()) + if(auto genericSubst = substToApply.as<GenericSubstitution>()) { if(genericSubst->genericDecl == parentGenericDecl) { @@ -1963,7 +1961,7 @@ void Type::accept(IValVisitor* visitor, void* extra) IntegerLiteralValue GetIntVal(RefPtr<IntVal> val) { - if (auto constantVal = val.As<ConstantIntVal>()) + if (auto constantVal = as<ConstantIntVal>(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<ConstantIntVal*>(val)) + if (auto intVal = dynamicCast<ConstantIntVal>(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<Type>().Ptr(); + return dynamicCast<Type>(findInnerMostGenericSubstitution(declRef.substitutions)->args[0]); } IntVal* HLSLPatchType::getElementCount() { - return findInnerMostGenericSubstitution(declRef.substitutions)->args[1].As<IntVal>().Ptr(); + return dynamicCast<IntVal>(findInnerMostGenericSubstitution(declRef.substitutions)->args[1]); } // Constructors for types @@ -2083,7 +2081,7 @@ void Type::accept(IValVisitor* visitor, void* extra) Session* session, DeclRef<TypeDefDecl> const& declRef) { - DeclRef<TypeDefDecl> specializedDeclRef = createDefaultSubstitutionsIfNeeded(session, declRef).As<TypeDefDecl>(); + DeclRef<TypeDefDecl> specializedDeclRef = createDefaultSubstitutionsIfNeeded(session, declRef).as<TypeDefDecl>(); auto namedType = new NamedExpressionType(specializedDeclRef); namedType->setSession(session); @@ -2162,8 +2160,8 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<Val> TypeEqualityWitness::SubstituteImpl(SubstitutionSet subst, int * ioDiff) { RefPtr<TypeEqualityWitness> rs = new TypeEqualityWitness(); - rs->sub = sub->SubstituteImpl(subst, ioDiff).As<Type>(); - rs->sup = sup->SubstituteImpl(subst, ioDiff).As<Type>(); + rs->sub = sub->SubstituteImpl(subst, ioDiff).dynamicCast<Type>(); + rs->sup = sup->SubstituteImpl(subst, ioDiff).dynamicCast<Type>(); return rs; } @@ -2194,7 +2192,7 @@ void Type::accept(IValVisitor* visitor, void* extra) { for(RefPtr<Substitutions> s = substs; s; s = s->outer) { - auto thisTypeSubst = s.As<ThisTypeSubstitution>(); + auto thisTypeSubst = s.dynamicCast<ThisTypeSubstitution>(); if(!thisTypeSubst) continue; @@ -2209,14 +2207,14 @@ void Type::accept(IValVisitor* visitor, void* extra) RefPtr<Val> DeclaredSubtypeWitness::SubstituteImpl(SubstitutionSet subst, int * ioDiff) { - if (auto genConstraintDeclRef = declRef.As<GenericTypeConstraintDecl>()) + if (auto genConstraintDeclRef = declRef.as<GenericTypeConstraintDecl>()) { 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<GenericSubstitution>()) + if(auto genericSubst = s.as<GenericSubstitution>()) { // 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<GenericTypeConstraintDecl>()) + if (auto constraintParam = m.dynamicCast<GenericTypeConstraintDecl>()) { 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<GlobalGenericParamSubstitution>()) + else if(auto globalGenericSubst = s.as<GlobalGenericParamSubstitution>()) { // 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<Type>(); - auto substSup = sup->SubstituteImpl(subst, &diff).As<Type>(); + auto substSub = sub->SubstituteImpl(subst, &diff).dynamicCast<Type>(); + auto substSup = sup->SubstituteImpl(subst, &diff).dynamicCast<Type>(); 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<GenericTypeConstraintDecl>()) + if (auto substTypeConstraintDecl = as<GenericTypeConstraintDecl>(substDeclRef.decl)) { - if (auto substAssocTypeDecl = substTypeConstraintDecl->ParentDecl->As<AssocTypeDecl>()) + if (auto substAssocTypeDecl = as<AssocTypeDecl>(substTypeConstraintDecl->ParentDecl)) { - if (auto interfaceDecl = substAssocTypeDecl->ParentDecl->As<InterfaceDecl>()) + if (auto interfaceDecl = as<InterfaceDecl>(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<Type> substSub = sub->SubstituteImpl(subst, &diff).As<Type>(); - RefPtr<Type> substSup = sup->SubstituteImpl(subst, &diff).As<Type>(); - RefPtr<SubtypeWitness> substSubToMid = subToMid->SubstituteImpl(subst, &diff).As<SubtypeWitness>(); + RefPtr<Type> substSub = sub->SubstituteImpl(subst, &diff).dynamicCast<Type>(); + RefPtr<Type> substSup = sup->SubstituteImpl(subst, &diff).dynamicCast<Type>(); + RefPtr<SubtypeWitness> substSubToMid = subToMid->SubstituteImpl(subst, &diff).dynamicCast<SubtypeWitness>(); DeclRef<Decl> 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<ExtractExistentialType>() ) + if( auto extractExistential = as<ExtractExistentialType>(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<ExtractExistentialSubtypeWitness>() ) + if( auto extractWitness = dynamicCast<ExtractExistentialSubtypeWitness>(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<Type>(); - auto substSup = sup->SubstituteImpl(subst, &diff).As<Type>(); + auto substSub = sub->SubstituteImpl(subst, &diff).dynamicCast<Type>(); + auto substSup = sup->SubstituteImpl(subst, &diff).dynamicCast<Type>(); if(!diff) return this; @@ -2561,7 +2559,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool TaggedUnionType::EqualsImpl(Type* type) { - auto taggedUnion = type->As<TaggedUnionType>(); + auto taggedUnion = as<TaggedUnionType>(type); if(!taggedUnion) return false; @@ -2608,7 +2606,7 @@ void Type::accept(IValVisitor* visitor, void* extra) List<RefPtr<Type>> substCaseTypes; for( auto caseType : caseTypes ) { - substCaseTypes.Add(caseType->SubstituteImpl(subst, &diff).As<Type>()); + substCaseTypes.Add(caseType->SubstituteImpl(subst, &diff).dynamicCast<Type>()); } if(!diff) return this; @@ -2628,7 +2626,7 @@ void Type::accept(IValVisitor* visitor, void* extra) bool TaggedUnionSubtypeWitness::EqualsVal(Val* val) { - auto taggedUnionWitness = val->dynamicCast<TaggedUnionSubtypeWitness>(); + auto taggedUnionWitness = dynamicCast<TaggedUnionSubtypeWitness>(val); if(!taggedUnionWitness) return false; @@ -2674,8 +2672,8 @@ RefPtr<Val> TaggedUnionSubtypeWitness::SubstituteImpl(SubstitutionSet subst, int { int diff = 0; - auto substSub = sub->SubstituteImpl(subst, &diff).As<Type>(); - auto substSup = sup->SubstituteImpl(subst, &diff).As<Type>(); + auto substSub = sub->SubstituteImpl(subst, &diff).dynamicCast<Type>(); + auto substSup = sup->SubstituteImpl(subst, &diff).dynamicCast<Type>(); List<RefPtr<Val>> substCaseWitnesses; for( auto caseWitness : caseWitnesses ) |
