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/syntax.h | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'source/slang/syntax.h') diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 5db762f11..076d62d71 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -1,5 +1,5 @@ -#ifndef RASTER_RENDERER_SYNTAX_H -#define RASTER_RENDERER_SYNTAX_H +#ifndef SLANG_SYNTAX_H +#define SLANG_SYNTAX_H #include "../core/basic.h" #include "ir.h" @@ -291,10 +291,7 @@ namespace Slang struct QualType { RefPtr type; - bool IsLeftValue; - - template - T* As(); + bool IsLeftValue; QualType() : IsLeftValue(false) @@ -307,6 +304,7 @@ namespace Slang Type* Ptr() { return type.Ptr(); } + operator Type*() { return type; } operator RefPtr() { return type; } RefPtr operator->() { return type; } }; @@ -432,7 +430,7 @@ namespace Slang Decl* decl = nullptr; Decl* getDecl() const { return decl; } - // Optionally, a chain of substititions to perform + // Optionally, a chain of substitutions to perform SubstitutionSet substitutions; DeclRefBase() @@ -452,7 +450,7 @@ namespace Slang , substitutions(subst) {} - // Apply substitutions to a type or ddeclaration + // Apply substitutions to a type or declaration RefPtr Substitute(RefPtr type) const; DeclRefBase Substitute(DeclRefBase declRef) const; @@ -506,10 +504,10 @@ namespace Slang // "dynamic cast" to a more specific declaration reference type template - DeclRef As() const + DeclRef as() const { DeclRef result; - result.decl = dynamic_cast(decl); + result.decl = Slang::as(decl); result.substitutions = substitutions; return result; } @@ -618,7 +616,7 @@ namespace Slang { while (cursor != end) { - if ((*cursor).As()) + if (dynamicCast(*cursor)) return cursor; cursor++; } @@ -728,7 +726,7 @@ namespace Slang while (ptr != end) { DeclRef declRef(ptr->Ptr(), substitutions); - if (declRef.As()) + if (declRef.as()) return ptr; ptr++; } @@ -1064,7 +1062,7 @@ namespace Slang RefPtr getVal() { SLANG_ASSERT(getFlavor() == Flavor::val); - return m_obj.As(); + return m_obj.dynamicCast(); } RefPtr getWitnessTable(); @@ -1116,13 +1114,6 @@ namespace Slang #include "object-meta-end.h" - - template - SLANG_FORCE_INLINE T* QualType::As() - { - return type ? type->As() : nullptr; - } - inline RefPtr GetSub(DeclRef const& declRef) { return declRef.Substitute(declRef.getDecl()->sub.Ptr()); @@ -1166,13 +1157,15 @@ namespace Slang // - inline BaseType GetVectorBaseType(VectorExpressionType* vecType) { - return vecType->elementType->AsBasicType()->baseType; + inline BaseType GetVectorBaseType(VectorExpressionType* vecType) + { + auto basicExprType = as(vecType->elementType); + return basicExprType->baseType; } inline int GetVectorSize(VectorExpressionType* vecType) { - auto constantVal = vecType->elementCount.As(); + auto constantVal = vecType->elementCount.dynamicCast(); if (constantVal) return (int) constantVal->value; // TODO: what to do in this case? @@ -1205,7 +1198,7 @@ namespace Slang List> rs; for (auto d : getMembersOfType(declRef)) rs.Add(d); - if (auto aggDeclRef = declRef.As()) + if (auto aggDeclRef = declRef.as()) { for (auto ext = GetCandidateExtensions(aggDeclRef); ext; ext = ext->nextCandidateExtension) { -- cgit v1.2.3