diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-01-31 10:14:26 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-31 10:14:26 -0500 |
| commit | 11c547d1e94fa620f527c3590174e6e25ab21883 (patch) | |
| tree | 008ab5b447af351d2a30fb86c768c9e8e8d8030e /source/slang/emit.cpp | |
| parent | 4db0aba1edc5fd55b91457481bae119ef66dde89 (diff) | |
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
Diffstat (limited to 'source/slang/emit.cpp')
| -rw-r--r-- | source/slang/emit.cpp | 52 |
1 files changed, 26 insertions, 26 deletions
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<IRLayoutDecoration>()) { auto layout = layoutDecoration->getLayout(); - if(auto varLayout = layout->dynamicCast<VarLayout>()) + if(auto varLayout = dynamicCast<VarLayout>(layout)) { emitIRSemantics(ctx, varLayout); } - else if (auto entryPointLayout = layout->dynamicCast<EntryPointLayout>()) + else if (auto entryPointLayout = dynamicCast<EntryPointLayout>(layout)) { if(auto resultLayout = entryPointLayout->resultLayout) { @@ -4603,7 +4603,7 @@ struct EmitVisitor Expr* expr = attrib->args[0]; - auto stringLitExpr = expr->As<StringLiteralExpr>(); + auto stringLitExpr = as<StringLiteralExpr>(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<IntegerLiteralExpr>(); + auto intLitExpr = as<IntegerLiteralExpr>(expr); if (!intLitExpr) { SLANG_DIAGNOSE_UNEXPECTED(getSink(), entryPoint->loc, "Attribute expects an int"); @@ -4840,39 +4840,39 @@ struct EmitVisitor { if(auto inputPrimitiveTypeModifier = pp->FindModifier<HLSLGeometryShaderInputPrimitiveTypeModifier>()) { - if(inputPrimitiveTypeModifier->As<HLSLTriangleModifier>()) + if(as<HLSLTriangleModifier>(inputPrimitiveTypeModifier)) { emit("layout(triangles) in;\n"); } - else if(inputPrimitiveTypeModifier->As<HLSLLineModifier>()) + else if(as<HLSLLineModifier>(inputPrimitiveTypeModifier)) { emit("layout(lines) in;\n"); } - else if(inputPrimitiveTypeModifier->As<HLSLLineAdjModifier>()) + else if(as<HLSLLineAdjModifier>(inputPrimitiveTypeModifier)) { emit("layout(lines_adjacency) in;\n"); } - else if(inputPrimitiveTypeModifier->As<HLSLPointModifier>()) + else if(as<HLSLPointModifier>(inputPrimitiveTypeModifier)) { emit("layout(points) in;\n"); } - else if(inputPrimitiveTypeModifier->As<HLSLTriangleAdjModifier>()) + else if(as<HLSLTriangleAdjModifier>(inputPrimitiveTypeModifier)) { emit("layout(triangles_adjacency) in;\n"); } } - if(auto outputStreamType = pp->type->As<HLSLStreamOutputType>()) + if(auto outputStreamType = as<HLSLStreamOutputType>(pp->type)) { - if(outputStreamType->As<HLSLTriangleStreamType>()) + if(as<HLSLTriangleStreamType>(outputStreamType)) { emit("layout(triangle_strip) out;\n"); } - else if(outputStreamType->As<HLSLLineStreamType>()) + else if(as<HLSLLineStreamType>(outputStreamType)) { emit("layout(line_strip) out;\n"); } - else if(outputStreamType->As<HLSLPointStreamType>()) + else if(as<HLSLPointStreamType>(outputStreamType)) { emit("layout(points) out;\n"); } @@ -5158,7 +5158,7 @@ struct EmitVisitor { if( auto layoutDecoration = func->findDecoration<IRLayoutDecoration>() ) { - return layoutDecoration->getLayout()->dynamicCast<EntryPointLayout>(); + return dynamicCast<EntryPointLayout>(layoutDecoration->getLayout()); } return nullptr; } @@ -5167,7 +5167,7 @@ struct EmitVisitor { if (auto layoutDecoration = func->findDecoration<IRLayoutDecoration>()) { - if (auto entryPointLayout = layoutDecoration->getLayout()->dynamicCast<EntryPointLayout>()) + if (auto entryPointLayout = dynamicCast<EntryPointLayout>(layoutDecoration->getLayout())) { return entryPointLayout; } @@ -5291,10 +5291,10 @@ struct EmitVisitor // auto typeLayout = layout->typeLayout; - while(auto arrayTypeLayout = typeLayout.As<ArrayTypeLayout>()) + while(auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout)) typeLayout = arrayTypeLayout->elementTypeLayout; - if (auto matrixTypeLayout = typeLayout.As<MatrixTypeLayout>()) + if (auto matrixTypeLayout = typeLayout.as<MatrixTypeLayout>()) { auto target = ctx->shared->target; @@ -5707,7 +5707,7 @@ struct EmitVisitor EmitVarChain elementChain = blockChain; auto typeLayout = varLayout->typeLayout; - if( auto parameterGroupTypeLayout = typeLayout.As<ParameterGroupTypeLayout>() ) + if( auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(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<ParameterGroupTypeLayout>() ) + if( auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(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<StructTypeLayout>() ) + if( auto gs = as<StructTypeLayout>(globalScopeLayout) ) { - return gs.Ptr(); + return gs; } - else if( auto globalConstantBufferLayout = globalScopeLayout.As<ParameterGroupTypeLayout>() ) + else if( auto globalConstantBufferLayout = as<ParameterGroupTypeLayout>(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<StructTypeLayout>(); + auto elementTypeStructLayout = as<StructTypeLayout>(elementTypeLayout); // We expect all constant buffers to contain `struct` types for now SLANG_RELEASE_ASSERT(elementTypeStructLayout); - return elementTypeStructLayout.Ptr(); + return elementTypeStructLayout; } else { |
