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/type-layout.cpp | 81 ++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 41 deletions(-) (limited to 'source/slang/type-layout.cpp') diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index 05c61e706..b902db826 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -845,11 +845,11 @@ static LayoutSize GetElementCount(RefPtr val) if(!val) return LayoutSize::infinite(); - if (auto constantVal = val.As()) + if (auto constantVal = as(val)) { return LayoutSize(LayoutSize::RawValue(constantVal->value)); } - else if( auto varRefVal = val.As() ) + else if( auto varRefVal = as(val) ) { // TODO: We want to treat the case where the number of // elements in an array depends on a generic parameter @@ -905,19 +905,19 @@ static SimpleLayoutInfo getParameterGroupLayoutInfo( RefPtr type, LayoutRulesImpl* rules) { - if( type->As() ) + if( as(type) ) { return rules->GetObjectLayout(ShaderParameterKind::ConstantBuffer); } - else if( type->As() ) + else if( as(type) ) { return rules->GetObjectLayout(ShaderParameterKind::TextureUniformBuffer); } - else if( type->As() ) + else if( as(type) ) { return rules->GetObjectLayout(ShaderParameterKind::ShaderStorageBuffer); } - else if (type->As()) + else if (as(type)) { // Note: we default to consuming zero register spces here, because // a parameter block might not contain anything (or all it contains @@ -935,11 +935,11 @@ static SimpleLayoutInfo getParameterGroupLayoutInfo( // TODO: the vertex-input and fragment-output cases should // only actually apply when we are at the appropriate stage in // the pipeline... - else if( type->As() ) + else if( as(type) ) { return SimpleLayoutInfo(LayoutResourceKind::VertexInput, 0); } - else if( type->As() ) + else if( as(type) ) { return SimpleLayoutInfo(LayoutResourceKind::FragmentOutput, 0); } @@ -1093,7 +1093,7 @@ RefPtr applyOffsetToTypeLayout( return oldTypeLayout; RefPtr newTypeLayout; - if (auto oldStructTypeLayout = oldTypeLayout.As()) + if (auto oldStructTypeLayout = oldTypeLayout.as()) { RefPtr newStructTypeLayout = new StructTypeLayout(); newStructTypeLayout->type = oldStructTypeLayout->type; @@ -1212,15 +1212,14 @@ createParameterGroupTypeLayout( // in HLSL or not. // Check if we are working with a parameter block... - auto parameterBlockType = parameterGroupType ? parameterGroupType->As() : nullptr; - - + auto parameterBlockType = as(parameterGroupType); + // Check if we have a parameter block *and* it should be // allocated into its own register space(s) bool ownRegisterSpace = false; if (parameterBlockType) { - // Should we allocate this block its own regsiter space? + // Should we allocate this block its own register space? if( shouldAllocateRegisterSpaceForParameterBlock(context) ) { ownRegisterSpace = true; @@ -1419,27 +1418,27 @@ LayoutRulesImpl* getParameterBufferElementTypeLayoutRules( RefPtr parameterGroupType, LayoutRulesImpl* rules) { - if( parameterGroupType->As() ) + if( as(parameterGroupType) ) { return rules->getLayoutRulesFamily()->getConstantBufferRules(); } - else if( parameterGroupType->As() ) + else if( as(parameterGroupType) ) { return rules->getLayoutRulesFamily()->getTextureBufferRules(); } - else if( parameterGroupType->As() ) + else if( as(parameterGroupType) ) { return rules->getLayoutRulesFamily()->getVaryingInputRules(); } - else if( parameterGroupType->As() ) + else if( as(parameterGroupType) ) { return rules->getLayoutRulesFamily()->getVaryingOutputRules(); } - else if( parameterGroupType->As() ) + else if( as(parameterGroupType) ) { return rules->getLayoutRulesFamily()->getShaderStorageBufferRules(); } - else if (parameterGroupType->As()) + else if (as(parameterGroupType)) { return rules->getLayoutRulesFamily()->getParameterBlockRules(); } @@ -1668,7 +1667,7 @@ static RefPtr maybeAdjustLayoutForArrayElementType( // Let's look at the type layout we have, and see if there is anything // that we need to do with it. // - if( auto originalArrayTypeLayout = originalTypeLayout.As() ) + if( auto originalArrayTypeLayout = originalTypeLayout.as() ) { // The element type is itself an array, so we'll need to adjust // *its* element type accordingly. @@ -1696,7 +1695,7 @@ static RefPtr maybeAdjustLayoutForArrayElementType( return adjustedArrayTypeLayout; } - else if(auto originalParameterGroupTypeLayout = originalTypeLayout.As() ) + else if(auto originalParameterGroupTypeLayout = originalTypeLayout.as() ) { auto originalInnerElementTypeLayout = originalParameterGroupTypeLayout->elementVarLayout->typeLayout; auto adjustedInnerElementTypeLayout = maybeAdjustLayoutForArrayElementType( @@ -1715,7 +1714,7 @@ static RefPtr maybeAdjustLayoutForArrayElementType( SLANG_UNIMPLEMENTED_X("array of parameter group"); UNREACHABLE_RETURN(originalTypeLayout); } - else if(auto originalStructTypeLayout = originalTypeLayout.As() ) + else if(auto originalStructTypeLayout = originalTypeLayout.as() ) { UInt fieldCount = originalStructTypeLayout->fields.Count(); @@ -1782,7 +1781,7 @@ static RefPtr maybeAdjustLayoutForArrayElementType( { // If we are making an unbounded array, then a `struct` // field with resource type will turn into its own space, - // and it will start at regsiter zero in that space. + // and it will start at register zero in that space. // resInfo.index = 0; resInfo.space = spaceOffsetForField.getFiniteValue(); @@ -1831,7 +1830,7 @@ SimpleLayoutInfo GetLayoutImpl( { auto rules = context.rules; - if (auto parameterGroupType = type->As()) + if (auto parameterGroupType = as(type)) { // If the user is just interested in uniform layout info, // then this is easy: a `ConstantBuffer` is really no @@ -1860,7 +1859,7 @@ SimpleLayoutInfo GetLayoutImpl( return info; } - else if (auto samplerStateType = type->As()) + else if (auto samplerStateType = as(type)) { return GetSimpleLayoutImpl( rules->GetObjectLayout(ShaderParameterKind::SamplerState), @@ -1868,7 +1867,7 @@ SimpleLayoutInfo GetLayoutImpl( rules, outTypeLayout); } - else if (auto textureType = type->As()) + else if (auto textureType = as(type)) { // TODO: the logic here should really be defined by the rules, // and not at this top level... @@ -1890,7 +1889,7 @@ SimpleLayoutInfo GetLayoutImpl( rules, outTypeLayout); } - else if (auto imageType = type->As()) + else if (auto imageType = as(type)) { // TODO: the logic here should really be defined by the rules, // and not at this top level... @@ -1912,7 +1911,7 @@ SimpleLayoutInfo GetLayoutImpl( rules, outTypeLayout); } - else if (auto textureSamplerType = type->As()) + else if (auto textureSamplerType = as(type)) { // TODO: the logic here should really be defined by the rules, // and not at this top level... @@ -1937,7 +1936,7 @@ SimpleLayoutInfo GetLayoutImpl( // TODO: need a better way to handle this stuff... #define CASE(TYPE, KIND) \ - else if(auto type_##TYPE = type->As()) do { \ + else if(auto type_##TYPE = as(type)) do { \ auto info = rules->GetObjectLayout(ShaderParameterKind::KIND); \ if (outTypeLayout) \ { \ @@ -1961,7 +1960,7 @@ SimpleLayoutInfo GetLayoutImpl( // TODO: need a better way to handle this stuff... #define CASE(TYPE, KIND) \ - else if(type->As()) do { \ + else if(as(type)) do { \ return GetSimpleLayoutImpl( \ rules->GetObjectLayout(ShaderParameterKind::KIND), \ type, rules, outTypeLayout); \ @@ -1981,7 +1980,7 @@ SimpleLayoutInfo GetLayoutImpl( // // TODO(tfoley): Need to recognize any UAV types here // - else if(auto basicType = type->As()) + else if(auto basicType = as(type)) { return GetSimpleLayoutImpl( rules->GetScalarLayout(basicType->baseType), @@ -1989,7 +1988,7 @@ SimpleLayoutInfo GetLayoutImpl( rules, outTypeLayout); } - else if(auto vecType = type->As()) + else if(auto vecType = as(type)) { return GetSimpleLayoutImpl( rules->GetVectorLayout( @@ -1999,7 +1998,7 @@ SimpleLayoutInfo GetLayoutImpl( rules, outTypeLayout); } - else if(auto matType = type->As()) + else if(auto matType = as(type)) { // The `GetMatrixLayout` implementation in the layout rules // currently defaults to assuming column-major layout, @@ -2040,7 +2039,7 @@ SimpleLayoutInfo GetLayoutImpl( return info; } - else if (auto arrayType = type->As()) + else if (auto arrayType = as(type)) { RefPtr elementTypeLayout; auto elementInfo = GetLayoutImpl( @@ -2192,11 +2191,11 @@ SimpleLayoutInfo GetLayoutImpl( } return arrayUniformInfo; } - 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 typeLayout; if (outTypeLayout) @@ -2316,7 +2315,7 @@ SimpleLayoutInfo GetLayoutImpl( return info; } - else if (auto globalGenParam = declRef.As()) + else if (auto globalGenParam = declRef.as()) { SimpleLayoutInfo info; info.alignment = 0; @@ -2336,7 +2335,7 @@ SimpleLayoutInfo GetLayoutImpl( return info; } } - else if (auto errorType = type->As()) + else if (auto errorType = as(type)) { // An error type means that we encountered something we don't understand. // @@ -2349,7 +2348,7 @@ SimpleLayoutInfo GetLayoutImpl( rules, outTypeLayout); } - else if( auto taggedUnionType = type->As() ) + else if( auto taggedUnionType = as(type) ) { // A tagged union type needs to be laid out as the maximum // size of any constituent type. @@ -2493,9 +2492,9 @@ RefPtr TypeLayout::unwrapArray() RefPtr GenericParamTypeLayout::getGlobalGenericParamDecl() { - auto declRefType = type->AsDeclRefType(); + auto declRefType = as(type); SLANG_ASSERT(declRefType); - auto rsDeclRef = declRefType->declRef.As(); + auto rsDeclRef = declRefType->declRef.as(); return rsDeclRef.getDecl(); } -- cgit v1.2.3