From 3726194fbe3da234eb30b6371e5b4ab1ea388f93 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Sat, 2 Feb 2019 11:58:54 -0500 Subject: Feature/as refactor review (#821) * Replace dynamicCast with as where does not change behavior (ie not Type derived). Use free function where scoping is clear. * Replace uses of dynamicCast with as when there is no difference in behavior. * Remove the IsXXXX methods from Type. * Don't have separate smart pointer to store canonicalType on Type. * Simplify Slang.FilteredMemberRefList.Adjust, such does the cast directly. * Use free as where appropriate. * Use free function version of casts where appropriate. * Fix text in casting.md * Fix typos in decl-refs.md * Remove the uses of free function as on RefDecl. Add 'canAs' to RefDecl as a way to test if a cast is possible. Moved 'as' into RefDeclBase. * Use 'is' to test for as cast on smart pointers. Fix small scope issue. * * Cache stringType and enumTypeType on the Session * Make DeclRefType::Create return a RefPtr * Make casting of result use the *method* .as (cos using free function would mean objects being wrongly destroyed) * Make results from createInstance ref'd to avoid possible leaks. * Fix typo in template parameter for is on RefPtr. --- source/slang/emit.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 224fa3a28..3be6c59cd 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -4238,11 +4238,11 @@ struct EmitVisitor if(auto layoutDecoration = inst->findDecoration()) { auto layout = layoutDecoration->getLayout(); - if(auto varLayout = dynamicCast(layout)) + if(auto varLayout = as(layout)) { emitIRSemantics(ctx, varLayout); } - else if (auto entryPointLayout = dynamicCast(layout)) + else if (auto entryPointLayout = as(layout)) { if(auto resultLayout = entryPointLayout->resultLayout) { @@ -5159,7 +5159,7 @@ struct EmitVisitor { if( auto layoutDecoration = func->findDecoration() ) { - return dynamicCast(layoutDecoration->getLayout()); + return as(layoutDecoration->getLayout()); } return nullptr; } @@ -5168,7 +5168,7 @@ struct EmitVisitor { if (auto layoutDecoration = func->findDecoration()) { - if (auto entryPointLayout = dynamicCast(layoutDecoration->getLayout())) + if (auto entryPointLayout = as(layoutDecoration->getLayout())) { return entryPointLayout; } -- cgit v1.2.3