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/parameter-binding.cpp | 92 +++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'source/slang/parameter-binding.cpp') diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 6bb8749dd..076b29659 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -785,12 +785,12 @@ static bool validateSpecializationsMatch( for(;;) { // Skip any global generic substitutions. - if(auto leftGlobalGeneric = ll.As()) + if(auto leftGlobalGeneric = ll.as()) { ll = leftGlobalGeneric->outer; continue; } - if(auto rightGlobalGeneric = rr.As()) + if(auto rightGlobalGeneric = rr.as()) { rr = rightGlobalGeneric->outer; continue; @@ -806,9 +806,9 @@ static bool validateSpecializationsMatch( ll = ll->outer; rr = rr->outer; - if(auto leftGeneric = leftSubst.As()) + if(auto leftGeneric = leftSubst.as()) { - if(auto rightGeneric = rightSubst.As()) + if(auto rightGeneric = as(rightSubst)) { if(validateGenericSubstitutionsMatch(context, leftGeneric, rightGeneric, stack)) { @@ -816,9 +816,9 @@ static bool validateSpecializationsMatch( } } } - else if(auto leftThisType = leftSubst.As()) + else if(auto leftThisType = leftSubst.as()) { - if(auto rightThisType = rightSubst.As()) + if(auto rightThisType = rightSubst.as()) { if(validateThisTypeSubstitutionsMatch(context, leftThisType, rightThisType, stack)) { @@ -851,9 +851,9 @@ static bool validateTypesMatch( // are ever recursive types. We'd need a more refined system to // cache the matches we've already found. - if( auto leftDeclRefType = left->As() ) + if( auto leftDeclRefType = as(left) ) { - if( auto rightDeclRefType = right->As() ) + if( auto rightDeclRefType = as(right) ) { // Are they references to matching decl refs? auto leftDeclRef = leftDeclRefType->declRef; @@ -879,9 +879,9 @@ static bool validateTypesMatch( } // Check that any declared fields match too. - if( auto leftStructDeclRef = leftDeclRef.As() ) + if( auto leftStructDeclRef = leftDeclRef.as() ) { - if( auto rightStructDeclRef = rightDeclRef.As() ) + if( auto rightStructDeclRef = rightDeclRef.as() ) { List> leftFields; List> rightFields; @@ -931,9 +931,9 @@ static bool validateTypesMatch( // If we are looking at `T[N]` and `U[M]` we want to check that // `T` is structurally equivalent to `U` and `N` is the same as `M`. - else if( auto leftArrayType = left->As() ) + else if( auto leftArrayType = as(left) ) { - if( auto rightArrayType = right->As() ) + if( auto rightArrayType = as(right) ) { if(!validateTypesMatch(context, leftArrayType->baseType, rightArrayType->baseType, stack) ) return false; @@ -1029,7 +1029,7 @@ RefPtr tryGetEffectiveTypeForGLSLVaryingInput( return nullptr; auto type = varDecl->getType(); - if( varDecl->HasModifier() || type->As()) + if( varDecl->HasModifier() || as(type)) { // Special case to handle "arrayed" shader inputs, as used // for Geometry and Hull input @@ -1041,8 +1041,8 @@ RefPtr tryGetEffectiveTypeForGLSLVaryingInput( // Tessellation `patch` variables should stay as written if( !varDecl->HasModifier() ) { - // Unwrap array type, if prsent - if( auto arrayType = type->As() ) + // Unwrap array type, if present + if( auto arrayType = as(type) ) { type = arrayType->baseType.Ptr(); } @@ -1067,7 +1067,7 @@ RefPtr tryGetEffectiveTypeForGLSLVaryingOutput( return nullptr; auto type = varDecl->getType(); - if( varDecl->HasModifier() || type->As()) + if( varDecl->HasModifier() || as(type)) { // Special case to handle "arrayed" shader outputs, as used // for Hull Shader output @@ -1080,8 +1080,8 @@ RefPtr tryGetEffectiveTypeForGLSLVaryingOutput( // Tessellation `patch` variables should stay as written if( !varDecl->HasModifier() ) { - // Unwrap array type, if prsent - if( auto arrayType = type->As() ) + // Unwrap array type, if present + if( auto arrayType = as(type) ) { type = arrayType->baseType.Ptr(); } @@ -1118,7 +1118,7 @@ getTypeLayoutForGlobalShaderParameter_GLSL( // We want to check for a constant-buffer type with a `push_constant` layout // qualifier before we move on to anything else. - if( varDecl->HasModifier() && type->As() ) + if( varDecl->HasModifier() && as(type) ) { return CreateTypeLayout( layoutContext.with(rules->getPushConstantBufferRules()), @@ -1128,14 +1128,14 @@ getTypeLayoutForGlobalShaderParameter_GLSL( // TODO(tfoley): We have multiple variations of // the `uniform` modifier right now, and that // needs to get fixed... - if( varDecl->HasModifier() || type->As() ) + if( varDecl->HasModifier() || as(type) ) { return CreateTypeLayout( layoutContext.with(rules->getConstantBufferRules()), type); } - if( varDecl->HasModifier() || type->As() ) + if( varDecl->HasModifier() || as(type) ) { return CreateTypeLayout( layoutContext.with(rules->getShaderStorageBufferRules()), @@ -1184,7 +1184,7 @@ getTypeLayoutForGlobalShaderParameter_HLSL( auto rules = layoutContext.getRulesFamily(); auto type = varDecl->getType(); - if( varDecl->HasModifier() && type->As() ) + if( varDecl->HasModifier() && as(type) ) { return CreateTypeLayout( layoutContext.with(rules->getShaderRecordConstantBufferRules()), @@ -1193,7 +1193,7 @@ getTypeLayoutForGlobalShaderParameter_HLSL( // We want to check for a constant-buffer type with a `push_constant` layout // qualifier before we move on to anything else. - if (varDecl->HasModifier() && type->As()) + if (varDecl->HasModifier() && as(type)) { return CreateTypeLayout( layoutContext.with(rules->getPushConstantBufferRules()), @@ -1354,7 +1354,7 @@ static void collectGlobalScopeParameter( // Now create a variable layout that we can use RefPtr varLayout = new VarLayout(); varLayout->typeLayout = typeLayout; - varLayout->varDecl = DeclRef(varDecl.Ptr(), nullptr).As(); + varLayout->varDecl = DeclRef(varDecl.Ptr(), nullptr).as(); // This declaration may represent the same logical parameter // as a declaration that came from a different translation unit. @@ -1950,12 +1950,12 @@ static void collectGlobalScopeParameters( // for generic types in the second pass. for (auto decl : program->Members) { - if (auto genParamDecl = decl.As()) + if (auto genParamDecl = as(decl)) collectGlobalGenericParameter(context, genParamDecl); } for (auto decl : program->Members) { - if (auto varDecl = decl.As()) + if (auto varDecl = as(decl)) collectGlobalScopeParameter(context, varDecl); } @@ -2175,7 +2175,7 @@ static RefPtr processEntryPointParameter( // The default handling of varying parameters should not apply // to geometry shader output streams; they have their own special rules. - if( auto gsStreamType = type->As() ) + if( auto gsStreamType = as(type) ) { // @@ -2294,21 +2294,21 @@ static RefPtr processEntryPointParameter( } // Scalar and vector types are treated as outputs directly - if(auto basicType = type->As()) + if(auto basicType = as(type)) { return processSimpleEntryPointParameter(context, basicType, state, varLayout); } - else if(auto vectorType = type->As()) + else if(auto vectorType = as(type)) { return processSimpleEntryPointParameter(context, vectorType, state, varLayout); } // A matrix is processed as if it was an array of rows - else if( auto matrixType = type->As() ) + else if( auto matrixType = as(type) ) { auto rowCount = GetIntVal(matrixType->getRowCount()); return processSimpleEntryPointParameter(context, matrixType, state, varLayout, (int) rowCount); } - else if( auto arrayType = type->As() ) + else if( auto arrayType = as(type) ) { // Note: Bad Things will happen if we have an array input // without a semantic already being enforced. @@ -2337,16 +2337,16 @@ static RefPtr processEntryPointParameter( return arrayTypeLayout; } // Ignore a bunch of types that don't make sense here... - else if (auto textureType = type->As()) { return nullptr; } - else if(auto samplerStateType = type->As()) { return nullptr; } - else if(auto constantBufferType = type->As()) { return nullptr; } + else if (auto textureType = as(type)) { return nullptr; } + else if(auto samplerStateType = as(type)) { return nullptr; } + else if(auto constantBufferType = as(type)) { return nullptr; } // Catch declaration-reference types late in the sequence, since // otherwise they will include all of the above cases... - else if( auto declRefType = type->As() ) + else if( auto declRefType = as(type) ) { auto declRef = declRefType->declRef; - if (auto structDeclRef = declRef.As()) + if (auto structDeclRef = declRef.as()) { RefPtr structLayout = new StructTypeLayout(); structLayout->type = type; @@ -2384,7 +2384,7 @@ static RefPtr processEntryPointParameter( return structLayout; } - else if (auto globalGenericParam = declRef.As()) + else if (auto globalGenericParam = declRef.as()) { auto genParamTypeLayout = new GenericParamTypeLayout(); // we should have already populated ProgramLayout::genericEntryPointParams list at this point, @@ -2400,7 +2400,7 @@ static RefPtr processEntryPointParameter( } } // If we ran into an error in checking the user's code, then skip this parameter - else if( auto errorType = type->As() ) + else if( auto errorType = as(type) ) { return nullptr; } @@ -2432,13 +2432,13 @@ static void collectEntryPointParameters( context->shared->programLayout->entryPoints.Add(entryPointLayout); // Note: this isn't really the best place for this logic to sit, - // but it is the simplest place where we have a direct correspondance + // but it is the simplest place where we have a direct correspondence // between a single `EntryPointRequest` and its matching `EntryPointLayout`, // so we'll use it. // for( auto taggedUnionType : entryPoint->taggedUnionTypes ) { - auto substType = taggedUnionType->Substitute(typeSubst).As(); + auto substType = taggedUnionType->Substitute(typeSubst).dynamicCast(); auto typeLayout = CreateTypeLayout(context->layoutContext, substType); entryPointLayout->taggedUnionTypeLayouts.Add(typeLayout); } @@ -2460,7 +2460,7 @@ static void collectEntryPointParameters( for( auto m : entryPointFuncDecl->Members ) { - auto paramDecl = m.As(); + auto paramDecl = as(m); if(!paramDecl) continue; @@ -2486,12 +2486,12 @@ static void collectEntryPointParameters( } RefPtr paramVarLayout = new VarLayout(); - paramVarLayout->varDecl = makeDeclRef(paramDecl.Ptr()); + paramVarLayout->varDecl = makeDeclRef(paramDecl); auto paramTypeLayout = processEntryPointParameterDecl( context, - paramDecl.Ptr(), - paramDecl->type.type->Substitute(typeSubst).As(), + paramDecl, + paramDecl->type.type->Substitute(typeSubst).dynamicCast(), state, paramVarLayout); @@ -2525,7 +2525,7 @@ static void collectEntryPointParameters( auto resultTypeLayout = processEntryPointParameterDecl( context, entryPointFuncDecl, - resultType->Substitute(typeSubst).As(), + resultType->Substitute(typeSubst).dynamicCast(), state, resultLayout); @@ -3008,7 +3008,7 @@ RefPtr specializeProgramLayout( auto &varLayout = globalStructLayout->fields[varId]; if (varLayout->typeLayout->FindResourceInfo(LayoutResourceKind::GenericResource)) { - RefPtr newType = varLayout->typeLayout->type->Substitute(typeSubst).As(); + RefPtr newType = varLayout->typeLayout->type->Substitute(typeSubst).dynamicCast(); RefPtr newTypeLayout = CreateTypeLayout( layoutContext.with(constantBufferRules), newType); -- cgit v1.2.3