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/emit.cpp | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 887a62974..e4662e3c4 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -4237,11 +4237,11 @@ struct EmitVisitor if(auto layoutDecoration = inst->findDecoration()) { auto layout = layoutDecoration->getLayout(); - if(auto varLayout = layout->dynamicCast()) + if(auto varLayout = dynamicCast(layout)) { emitIRSemantics(ctx, varLayout); } - else if (auto entryPointLayout = layout->dynamicCast()) + else if (auto entryPointLayout = dynamicCast(layout)) { if(auto resultLayout = entryPointLayout->resultLayout) { @@ -4603,7 +4603,7 @@ struct EmitVisitor Expr* expr = attrib->args[0]; - auto stringLitExpr = expr->As(); + auto stringLitExpr = as(expr); if (!stringLitExpr) { SLANG_DIAGNOSE_UNEXPECTED(getSink(), entryPoint->loc, "Attribute parameter expecting to be a string "); @@ -4630,7 +4630,7 @@ struct EmitVisitor Expr* expr = attrib->args[0]; - auto intLitExpr = expr->As(); + auto intLitExpr = as(expr); if (!intLitExpr) { SLANG_DIAGNOSE_UNEXPECTED(getSink(), entryPoint->loc, "Attribute expects an int"); @@ -4840,39 +4840,39 @@ struct EmitVisitor { if(auto inputPrimitiveTypeModifier = pp->FindModifier()) { - if(inputPrimitiveTypeModifier->As()) + if(as(inputPrimitiveTypeModifier)) { emit("layout(triangles) in;\n"); } - else if(inputPrimitiveTypeModifier->As()) + else if(as(inputPrimitiveTypeModifier)) { emit("layout(lines) in;\n"); } - else if(inputPrimitiveTypeModifier->As()) + else if(as(inputPrimitiveTypeModifier)) { emit("layout(lines_adjacency) in;\n"); } - else if(inputPrimitiveTypeModifier->As()) + else if(as(inputPrimitiveTypeModifier)) { emit("layout(points) in;\n"); } - else if(inputPrimitiveTypeModifier->As()) + else if(as(inputPrimitiveTypeModifier)) { emit("layout(triangles_adjacency) in;\n"); } } - if(auto outputStreamType = pp->type->As()) + if(auto outputStreamType = as(pp->type)) { - if(outputStreamType->As()) + if(as(outputStreamType)) { emit("layout(triangle_strip) out;\n"); } - else if(outputStreamType->As()) + else if(as(outputStreamType)) { emit("layout(line_strip) out;\n"); } - else if(outputStreamType->As()) + else if(as(outputStreamType)) { emit("layout(points) out;\n"); } @@ -5158,7 +5158,7 @@ struct EmitVisitor { if( auto layoutDecoration = func->findDecoration() ) { - return layoutDecoration->getLayout()->dynamicCast(); + return dynamicCast(layoutDecoration->getLayout()); } return nullptr; } @@ -5167,7 +5167,7 @@ struct EmitVisitor { if (auto layoutDecoration = func->findDecoration()) { - if (auto entryPointLayout = layoutDecoration->getLayout()->dynamicCast()) + if (auto entryPointLayout = dynamicCast(layoutDecoration->getLayout())) { return entryPointLayout; } @@ -5291,10 +5291,10 @@ struct EmitVisitor // auto typeLayout = layout->typeLayout; - while(auto arrayTypeLayout = typeLayout.As()) + while(auto arrayTypeLayout = as(typeLayout)) typeLayout = arrayTypeLayout->elementTypeLayout; - if (auto matrixTypeLayout = typeLayout.As()) + if (auto matrixTypeLayout = typeLayout.as()) { auto target = ctx->shared->target; @@ -5707,7 +5707,7 @@ struct EmitVisitor EmitVarChain elementChain = blockChain; auto typeLayout = varLayout->typeLayout; - if( auto parameterGroupTypeLayout = typeLayout.As() ) + if( auto parameterGroupTypeLayout = as(typeLayout) ) { containerChain = EmitVarChain(parameterGroupTypeLayout->containerVarLayout, &blockChain); elementChain = EmitVarChain(parameterGroupTypeLayout->elementVarLayout, &blockChain); @@ -5797,7 +5797,7 @@ struct EmitVisitor EmitVarChain elementChain = blockChain; auto typeLayout = varLayout->typeLayout->unwrapArray(); - if( auto parameterGroupTypeLayout = typeLayout.As() ) + if( auto parameterGroupTypeLayout = as(typeLayout) ) { containerChain = EmitVarChain(parameterGroupTypeLayout->containerVarLayout, &blockChain); elementChain = EmitVarChain(parameterGroupTypeLayout->elementVarLayout, &blockChain); @@ -6523,11 +6523,11 @@ StructTypeLayout* getGlobalStructLayout( ProgramLayout* programLayout) { auto globalScopeLayout = programLayout->globalScopeLayout->typeLayout; - if( auto gs = globalScopeLayout.As() ) + if( auto gs = as(globalScopeLayout) ) { - return gs.Ptr(); + return gs; } - else if( auto globalConstantBufferLayout = globalScopeLayout.As() ) + else if( auto globalConstantBufferLayout = as(globalScopeLayout) ) { // TODO: the `cbuffer` case really needs to be emitted very // carefully, but that is beyond the scope of what a simple rewriter @@ -6539,19 +6539,19 @@ StructTypeLayout* getGlobalStructLayout( // so that we can give it an explicit location. The fields in that // declaration might use various type declarations, so we'd really // need to emit all the type declarations first, and that involves - // some large scale reorderings. + // some large scale re orderings. // // For now we will punt and just emit the declarations normally, // and hope that the global-scope block (`$Globals`) gets auto-assigned - // the same location that we manually asigned it. + // the same location that we manually assigned it. auto elementTypeLayout = globalConstantBufferLayout->offsetElementTypeLayout; - auto elementTypeStructLayout = elementTypeLayout.As(); + auto elementTypeStructLayout = as(elementTypeLayout); // We expect all constant buffers to contain `struct` types for now SLANG_RELEASE_ASSERT(elementTypeStructLayout); - return elementTypeStructLayout.Ptr(); + return elementTypeStructLayout; } else { -- cgit v1.2.3