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/ir.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'source/slang/ir.h') diff --git a/source/slang/ir.h b/source/slang/ir.h index 343f5b79b..bbb68cdda 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -407,15 +407,35 @@ struct IRInst void _insertAt(IRInst* inPrev, IRInst* inNext, IRInst* inParent); }; -// `dynamic_cast` equivalent template -T* as(IRInst* inst, T* /* */ = nullptr) +T* dynamicCast(IRInst* inst) { if (inst && T::isaImpl(inst->op)) - return (T*) inst; + return static_cast(inst); return nullptr; } +template +const T* dynamicCast(const IRInst* inst) +{ + if (inst && T::isaImpl(inst->op)) + return static_cast(inst); + return nullptr; +} + +// `dynamic_cast` equivalent (we just use dynamicCast) +template +T* as(IRInst* inst) +{ + return dynamicCast(inst); +} + +template +const T* as(const IRInst* inst) +{ + return dynamicCast(inst); +} + // `static_cast` equivalent, with debug validation template T* cast(IRInst* inst, T* /* */ = nullptr) -- cgit v1.2.3