From 43c146794aab638924d2ab838d10f8af2ebf02a7 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 5 Jun 2020 18:20:09 -0400 Subject: ASTNodes use MemoryArena (#1376) * Add a ASTBuilder to a Module Only construct on valid ASTBuilder (was being called on nullptr on occassion) * Add nodes to ASTBuilder. * Compiles with RefPtr removed from AST node types. * Initialize all AST node pointer variables in headers to nullptr; * Initialize AST node variables as nullptr. Make ASTBuilder keep a ref on node types. Make SyntaxParseCallback returns a NodeBase * Don't release canonicalType on dtor (managed by ASTBuilder). * Give ASTBuilders a name and id, to help in debugging. For now destroy the session TypeCache, to stop it holding things released when the compile request destroys ASTBuilders. * Moved the TypeCheckingCache over to Linkage from Session. * NodeBase no longer derived from RefObject. * Only add/dtor nodes that need destruction. First pass compile on linux. --- source/slang/slang-ast-base.h | 50 +-- source/slang/slang-ast-builder.cpp | 91 ++-- source/slang/slang-ast-builder.h | 91 ++-- source/slang/slang-ast-decl.h | 24 +- source/slang/slang-ast-dump.cpp | 20 +- source/slang/slang-ast-expr.h | 52 +-- source/slang/slang-ast-modifier.h | 8 +- source/slang/slang-ast-reflect.cpp | 22 +- source/slang/slang-ast-reflect.h | 8 +- source/slang/slang-ast-stmt.h | 52 +-- source/slang/slang-ast-substitutions.cpp | 24 +- source/slang/slang-ast-support-types.h | 130 +++--- source/slang/slang-ast-type.cpp | 124 +++--- source/slang/slang-ast-type.h | 86 ++-- source/slang/slang-ast-val.cpp | 62 +-- source/slang/slang-ast-val.h | 22 +- source/slang/slang-check-conformance.cpp | 56 +-- source/slang/slang-check-constraint.cpp | 68 +-- source/slang/slang-check-conversion.cpp | 98 ++--- source/slang/slang-check-decl.cpp | 89 ++-- source/slang/slang-check-expr.cpp | 196 ++++----- source/slang/slang-check-impl.h | 436 +++++++++---------- source/slang/slang-check-modifier.cpp | 42 +- source/slang/slang-check-overload.cpp | 58 +-- source/slang/slang-check-shader.cpp | 48 ++- source/slang/slang-check-stmt.cpp | 12 +- source/slang/slang-check-type.cpp | 68 +-- source/slang/slang-check.cpp | 13 - source/slang/slang-compiler.h | 40 +- source/slang/slang-emit-c-like.h | 2 +- source/slang/slang-ir.cpp | 2 +- source/slang/slang-lookup.cpp | 18 +- source/slang/slang-lookup.h | 2 +- source/slang/slang-lower-to-ir.cpp | 32 +- source/slang/slang-mangle.cpp | 4 +- source/slang/slang-parameter-binding.cpp | 20 +- source/slang/slang-parser.cpp | 708 ++++++++++++++++--------------- source/slang/slang-parser.h | 4 +- source/slang/slang-reflection.cpp | 28 +- source/slang/slang-syntax.cpp | 134 +++--- source/slang/slang-syntax.h | 50 +-- source/slang/slang-type-layout.cpp | 46 +- source/slang/slang-type-layout.h | 20 +- source/slang/slang.cpp | 62 ++- 44 files changed, 1658 insertions(+), 1564 deletions(-) (limited to 'source') diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h index 05d2ded69..27ac8a437 100644 --- a/source/slang/slang-ast-base.h +++ b/source/slang/slang-ast-base.h @@ -14,14 +14,12 @@ namespace Slang { -// Signals to C++ extractor that RefObject is a base class, that isn't reflected to C++ extractor -SLANG_REFLECT_BASE_CLASS(RefObject) - struct ReflectClassInfo; -class NodeBase : public RefObject +class NodeBase { SLANG_ABSTRACT_CLASS(NodeBase) + SLANG_CLASS_ROOT // MUST be called before used. Called automatically via the ASTBuilder. // Note that the astBuilder is not stored in the NodeBase derived types by default. @@ -91,14 +89,14 @@ class Val : public NodeBase // construct a new value by applying a set of parameter // substitutions to this one - RefPtr substitute(ASTBuilder* astBuilder, SubstitutionSet subst); + Val* substitute(ASTBuilder* astBuilder, SubstitutionSet subst); // Lower-level interface for substitution. Like the basic // `Substitute` above, but also takes a by-reference // integer parameter that should be incremented when // returning a modified value (this can help the caller // decide whether they need to do anything). - RefPtr substituteImpl(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* substituteImpl(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); bool equalsVal(Val* val); String toString(); @@ -109,7 +107,7 @@ class Val : public NodeBase } // Overrides should be public so base classes can access - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); @@ -154,17 +152,15 @@ class Type: public Val Type* getCanonicalType(); - ~Type(); - // Overrides should be public so base classes can access - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); bool _equalsValOverride(Val* val); bool _equalsImplOverride(Type* type); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); protected: bool equalsImpl(Type* type); - RefPtr createCanonicalType(); + Type* createCanonicalType(); Type* canonicalType = nullptr; @@ -184,17 +180,17 @@ class Substitutions: public NodeBase SLANG_ABSTRACT_CLASS(Substitutions) // The next outer that this one refines. - RefPtr outer; + Substitutions* outer = nullptr; // Apply a set of substitutions to the bindings in this substitution - RefPtr applySubstitutionsShallow(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff); + Substitutions* applySubstitutionsShallow(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff); // Check if these are equivalent substitutions to another set bool equals(Substitutions* subst); HashCode getHashCode() const; // Overrides should be public so base classes can access - RefPtr _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff); + Substitutions* _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff); bool _equalsOverride(Substitutions* subst); HashCode _getHashCodeOverride() const; }; @@ -205,13 +201,13 @@ class GenericSubstitution : public Substitutions // The generic declaration that defines the // parameters we are binding to arguments - GenericDecl* genericDecl; + GenericDecl* genericDecl = nullptr; // The actual values of the arguments - List > args; + List args; // Overrides should be public so base classes can access - RefPtr _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff); + Substitutions* _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff); bool _equalsOverride(Substitutions* subst); HashCode _getHashCodeOverride() const; }; @@ -225,11 +221,11 @@ class ThisTypeSubstitution : public Substitutions // A witness that shows that the concrete type used to // specialize the interface conforms to the interface. - RefPtr witness; + SubtypeWitness* witness = nullptr; // Overrides should be public so base classes can access // The actual type that provides the lookup scope for an associated type - RefPtr _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff); + Substitutions* _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff); bool _equalsOverride(Substitutions* subst); HashCode _getHashCodeOverride() const; }; @@ -238,22 +234,22 @@ class GlobalGenericParamSubstitution : public Substitutions { SLANG_CLASS(GlobalGenericParamSubstitution) // the type_param decl to be substituted - GlobalGenericParamDecl* paramDecl; + GlobalGenericParamDecl* paramDecl = nullptr; // the actual type to substitute in - RefPtr actualType; + Type* actualType = nullptr; struct ConstraintArg { - RefPtr decl; - RefPtr val; + Decl* decl = nullptr; + Val* val = nullptr; }; // the values that satisfy any constraints on the type parameter List constraintArgs; // Overrides should be public so base classes can access - RefPtr _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff); + Substitutions* _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff); bool _equalsOverride(Substitutions* subst); HashCode _getHashCodeOverride() const; }; @@ -276,7 +272,7 @@ class Modifier : public SyntaxNode void accept(IModifierVisitor* visitor, void* extra); // Next modifier in linked list of modifiers on same piece of syntax - RefPtr next; + Modifier* next = nullptr; // The keyword that was used to introduce t that was used to name this modifier. Name* name; @@ -293,7 +289,7 @@ class ModifiableSyntaxNode : public SyntaxNode Modifiers modifiers; template - FilteredModifierList getModifiersOfType() { return FilteredModifierList(modifiers.first.Ptr()); } + FilteredModifierList getModifiersOfType() { return FilteredModifierList(modifiers.first); } // Find the first modifier of a given type, or return `nullptr` if none is found. template diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp index 67ce80120..048ba7437 100644 --- a/source/slang/slang-ast-builder.cpp +++ b/source/slang/slang-ast-builder.cpp @@ -12,7 +12,6 @@ SharedASTBuilder::SharedASTBuilder() { } - void SharedASTBuilder::init(Session* session) { m_namePool = session->getNamePool(); @@ -55,14 +54,14 @@ const ReflectClassInfo* SharedASTBuilder::findClassInfo(const UnownedStringSlice return m_sliceToTypeMap.TryGetValue(slice, typeInfo) ? typeInfo : nullptr; } -SyntaxClass SharedASTBuilder::findSyntaxClass(const UnownedStringSlice& slice) +SyntaxClass SharedASTBuilder::findSyntaxClass(const UnownedStringSlice& slice) { const ReflectClassInfo* typeInfo; if (m_sliceToTypeMap.TryGetValue(slice, typeInfo)) { - return SyntaxClass(typeInfo); + return SyntaxClass(typeInfo); } - return SyntaxClass(); + return SyntaxClass(); } const ReflectClassInfo* SharedASTBuilder::findClassInfo(Name* name) @@ -71,14 +70,14 @@ const ReflectClassInfo* SharedASTBuilder::findClassInfo(Name* name) return m_nameToTypeMap.TryGetValue(name, typeInfo) ? typeInfo : nullptr; } -SyntaxClass SharedASTBuilder::findSyntaxClass(Name* name) +SyntaxClass SharedASTBuilder::findSyntaxClass(Name* name) { const ReflectClassInfo* typeInfo; if (m_nameToTypeMap.TryGetValue(name, typeInfo)) { - return SyntaxClass(typeInfo); + return SyntaxClass(typeInfo); } - return SyntaxClass(); + return SyntaxClass(); } Type* SharedASTBuilder::getStringType() @@ -106,7 +105,7 @@ SharedASTBuilder::~SharedASTBuilder() // Release built in types.. for (Index i = 0; i < SLANG_COUNT_OF(m_builtinTypes); ++i) { - m_builtinTypes[i].setNull(); + m_builtinTypes[i] = nullptr; } if (m_astBuilder) @@ -115,13 +114,13 @@ SharedASTBuilder::~SharedASTBuilder() } } -void SharedASTBuilder::registerBuiltinDecl(RefPtr decl, RefPtr modifier) +void SharedASTBuilder::registerBuiltinDecl(Decl* decl, BuiltinTypeModifier* modifier) { - auto type = DeclRefType::create(m_astBuilder, DeclRef(decl.Ptr(), nullptr)); + auto type = DeclRefType::create(m_astBuilder, DeclRef(decl, nullptr)); m_builtinTypes[Index(modifier->tag)] = type; } -void SharedASTBuilder::registerMagicDecl(RefPtr decl, RefPtr modifier) +void SharedASTBuilder::registerMagicDecl(Decl* decl, MagicTypeModifier* modifier) { // In some cases the modifier will have been applied to the // "inner" declaration of a `GenericDecl`, but what we @@ -131,55 +130,71 @@ void SharedASTBuilder::registerMagicDecl(RefPtr decl, RefPtr(decl->parentDecl)) declToRegister = genericDecl; - m_magicDecls[modifier->name] = declToRegister.Ptr(); + m_magicDecls[modifier->name] = declToRegister; } -RefPtr SharedASTBuilder::findMagicDecl(const String& name) +Decl* SharedASTBuilder::findMagicDecl(const String& name) { return m_magicDecls[name].GetValue(); } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ASTBuilder !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -ASTBuilder::ASTBuilder(SharedASTBuilder* sharedASTBuilder): - m_sharedASTBuilder(sharedASTBuilder) +ASTBuilder::ASTBuilder(SharedASTBuilder* sharedASTBuilder, const String& name): + m_sharedASTBuilder(sharedASTBuilder), + m_name(name), + m_id(sharedASTBuilder->m_id++), + m_arena(2048) { SLANG_ASSERT(sharedASTBuilder); } ASTBuilder::ASTBuilder(): - m_sharedASTBuilder(nullptr) + m_sharedASTBuilder(nullptr), + m_id(-1), + m_arena(2048) +{ + m_name = "ShadedASTBuilder::m_astBuilder"; +} + +ASTBuilder::~ASTBuilder() { + for (NodeBase* node : m_nodes) + { + const ReflectClassInfo* info = ReflectClassInfo::getInfo(node->astNodeType); + SLANG_ASSERT(info->m_destroyFunc); + info->m_destroyFunc(node); + } } -RefPtr ASTBuilder::getPtrType(RefPtr valueType) +PtrType* ASTBuilder::getPtrType(Type* valueType) { - return getPtrType(valueType, "PtrType").dynamicCast(); + return dynamicCast(getPtrType(valueType, "PtrType")); } // Construct the type `Out` -RefPtr ASTBuilder::getOutType(RefPtr valueType) +OutType* ASTBuilder::getOutType(Type* valueType) { - return getPtrType(valueType, "OutType").dynamicCast(); + return dynamicCast(getPtrType(valueType, "OutType")); } -RefPtr ASTBuilder::getInOutType(RefPtr valueType) +InOutType* ASTBuilder::getInOutType(Type* valueType) { - return getPtrType(valueType, "InOutType").dynamicCast(); + return dynamicCast(getPtrType(valueType, "InOutType")); } -RefPtr ASTBuilder::getRefType(RefPtr valueType) +RefType* ASTBuilder::getRefType(Type* valueType) { - return getPtrType(valueType, "RefType").dynamicCast(); + return dynamicCast(getPtrType(valueType, "RefType")); } -RefPtr ASTBuilder::getPtrType(RefPtr valueType, char const* ptrTypeName) +PtrTypeBase* ASTBuilder::getPtrType(Type* valueType, char const* ptrTypeName) { - auto genericDecl = m_sharedASTBuilder->findMagicDecl(ptrTypeName).dynamicCast(); + auto genericDecl = dynamicCast(m_sharedASTBuilder->findMagicDecl(ptrTypeName)); return getPtrType(valueType, genericDecl); } -RefPtr ASTBuilder::getPtrType(RefPtr valueType, GenericDecl* genericDecl) +PtrTypeBase* ASTBuilder::getPtrType(Type* valueType, GenericDecl* genericDecl) { auto typeDecl = genericDecl->inner; @@ -187,38 +202,38 @@ RefPtr ASTBuilder::getPtrType(RefPtr valueType, GenericDecl* substitutions->genericDecl = genericDecl; substitutions->args.add(valueType); - auto declRef = DeclRef(typeDecl.Ptr(), substitutions); + auto declRef = DeclRef(typeDecl, substitutions); auto rsType = DeclRefType::create(this, declRef); return as(rsType); } -RefPtr ASTBuilder::getArrayType(Type* elementType, IntVal* elementCount) +ArrayExpressionType* ASTBuilder::getArrayType(Type* elementType, IntVal* elementCount) { - RefPtr arrayType = create(); + ArrayExpressionType* arrayType = create(); arrayType->baseType = elementType; arrayType->arrayLength = elementCount; return arrayType; } -RefPtr ASTBuilder::getVectorType( - RefPtr elementType, - RefPtr elementCount) +VectorExpressionType* ASTBuilder::getVectorType( + Type* elementType, + IntVal* elementCount) { - auto vectorGenericDecl = m_sharedASTBuilder->findMagicDecl("Vector").as(); + auto vectorGenericDecl = as(m_sharedASTBuilder->findMagicDecl("Vector")); auto vectorTypeDecl = vectorGenericDecl->inner; auto substitutions = create(); - substitutions->genericDecl = vectorGenericDecl.Ptr(); + substitutions->genericDecl = vectorGenericDecl; substitutions->args.add(elementType); substitutions->args.add(elementCount); - auto declRef = DeclRef(vectorTypeDecl.Ptr(), substitutions); + auto declRef = DeclRef(vectorTypeDecl, substitutions); - return DeclRefType::create(this, declRef).as(); + return as(DeclRefType::create(this, declRef)); } -RefPtr ASTBuilder::getTypeType(Type* type) +TypeType* ASTBuilder::getTypeType(Type* type) { return create(type); } diff --git a/source/slang/slang-ast-builder.h b/source/slang/slang-ast-builder.h index bb423c4a4..b6aa83a8c 100644 --- a/source/slang/slang-ast-builder.h +++ b/source/slang/slang-ast-builder.h @@ -2,10 +2,13 @@ #ifndef SLANG_AST_BUILDER_H #define SLANG_AST_BUILDER_H +#include + #include "slang-ast-support-types.h" #include "slang-ast-all.h" #include "../core/slang-type-traits.h" +#include "../core/slang-memory-arena.h" namespace Slang { @@ -15,8 +18,8 @@ class SharedASTBuilder : public RefObject friend class ASTBuilder; public: - void registerBuiltinDecl(RefPtr decl, RefPtr modifier); - void registerMagicDecl(RefPtr decl, RefPtr modifier); + void registerBuiltinDecl(Decl* decl, BuiltinTypeModifier* modifier); + void registerMagicDecl(Decl* decl, MagicTypeModifier* modifier); /// Get the string type Type* getStringType(); @@ -24,13 +27,13 @@ public: Type* getEnumTypeType(); const ReflectClassInfo* findClassInfo(Name* name); - SyntaxClass findSyntaxClass(Name* name); + SyntaxClass findSyntaxClass(Name* name); const ReflectClassInfo* findClassInfo(const UnownedStringSlice& slice); - SyntaxClass findSyntaxClass(const UnownedStringSlice& slice); + SyntaxClass findSyntaxClass(const UnownedStringSlice& slice); // Look up a magic declaration by its name - RefPtr findMagicDecl(String const& name); + Decl* findMagicDecl(String const& name); /// A name pool that can be used for lookup for findClassInfo etc. It is the same pool as the Session. NamePool* getNamePool() { return m_namePool; } @@ -45,9 +48,9 @@ public: protected: // State shared between ASTBuilders - RefPtr m_errorType; - RefPtr m_initializerListType; - RefPtr m_overloadedType; + Type* m_errorType = nullptr; + Type* m_initializerListType = nullptr; + Type* m_overloadedType = nullptr; // The following types are created lazily, such that part of their definition // can be in the standard library @@ -57,10 +60,10 @@ protected: // // TODO(tfoley): These should really belong to the compilation context! // - RefPtr m_stringType; - RefPtr m_enumTypeType; + Type* m_stringType = nullptr; + Type* m_enumTypeType = nullptr; - RefPtr m_builtinTypes[Index(BaseType::CountOf)]; + Type* m_builtinTypes[Index(BaseType::CountOf)]; Dictionary m_magicDecls; @@ -72,6 +75,8 @@ protected: // This is a private builder used for these shared types ASTBuilder* m_astBuilder = nullptr; Session* m_session = nullptr; + + Index m_id = 1; }; class ASTBuilder : public RefObject @@ -89,15 +94,14 @@ public: }; }; - /// Create AST type. - template - T* create() { SLANG_COMPILE_TIME_ASSERT(IsValidType::Value); T* node = new T; node->init(T::kType, this); return node; } + /// Create AST types + template + T* create() { return _initAndAdd(new (m_arena.allocate(sizeof(T))) T); } template - T* create(const P0& p0) { SLANG_COMPILE_TIME_ASSERT(IsValidType::Value); T* node = new T(p0); node->init(T::kType, this); return node;} - + T* create(const P0& p0) { return _initAndAdd(new (m_arena.allocate(sizeof(T))) T(p0)); } template - T* create(const P0& p0, const P1& p1) { SLANG_COMPILE_TIME_ASSERT(IsValidType::Value); T* node = new T(p0, p1); node->init(T::kType, this); return node; } + T* create(const P0& p0, const P1& p1) { return _initAndAdd(new (m_arena.allocate(sizeof(T))) T(p0, p1));} /// Get the built in types SLANG_FORCE_INLINE Type* getBoolType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Bool)]; } @@ -121,37 +125,39 @@ public: // Construct the type `Ptr`, where `Ptr` // is looked up as a builtin type. - RefPtr getPtrType(RefPtr valueType); + PtrType* getPtrType(Type* valueType); // Construct the type `Out` - RefPtr getOutType(RefPtr valueType); + OutType* getOutType(Type* valueType); // Construct the type `InOut` - RefPtr getInOutType(RefPtr valueType); + InOutType* getInOutType(Type* valueType); // Construct the type `Ref` - RefPtr getRefType(RefPtr valueType); + RefType* getRefType(Type* valueType); // Construct a pointer type like `Ptr`, but where // the actual type name for the pointer type is given by `ptrTypeName` - RefPtr getPtrType(RefPtr valueType, char const* ptrTypeName); + PtrTypeBase* getPtrType(Type* valueType, char const* ptrTypeName); // Construct a pointer type like `Ptr`, but where // the generic declaration for the pointer type is `genericDecl` - RefPtr getPtrType(RefPtr valueType, GenericDecl* genericDecl); + PtrTypeBase* getPtrType(Type* valueType, GenericDecl* genericDecl); - RefPtr getArrayType(Type* elementType, IntVal* elementCount); + ArrayExpressionType* getArrayType(Type* elementType, IntVal* elementCount); - RefPtr getVectorType(RefPtr elementType, RefPtr elementCount); + VectorExpressionType* getVectorType(Type* elementType, IntVal* elementCount); - RefPtr getTypeType(Type* type); + TypeType* getTypeType(Type* type); /// Helpers to get type info from the SharedASTBuilder const ReflectClassInfo* findClassInfo(const UnownedStringSlice& slice) { return m_sharedASTBuilder->findClassInfo(slice); } - SyntaxClass findSyntaxClass(const UnownedStringSlice& slice) { return m_sharedASTBuilder->findSyntaxClass(slice); } + SyntaxClass findSyntaxClass(const UnownedStringSlice& slice) { return m_sharedASTBuilder->findSyntaxClass(slice); } const ReflectClassInfo* findClassInfo(Name* name) { return m_sharedASTBuilder->findClassInfo(name); } - SyntaxClass findSyntaxClass(Name* name) { return m_sharedASTBuilder->findSyntaxClass(name); } + SyntaxClass findSyntaxClass(Name* name) { return m_sharedASTBuilder->findSyntaxClass(name); } + + MemoryArena& getMemoryArena() { return m_arena; } /// Get the shared AST builder SharedASTBuilder* getSharedASTBuilder() { return m_sharedASTBuilder; } @@ -160,13 +166,40 @@ public: Session* getGlobalSession() { return m_sharedASTBuilder->m_session; } /// Ctor - ASTBuilder(SharedASTBuilder* sharedASTBuilder); + ASTBuilder(SharedASTBuilder* sharedASTBuilder, const String& name); + + /// Dtor + ~ASTBuilder(); protected: // Special default Ctor that can only be used by SharedASTBuilder ASTBuilder(); + template + SLANG_FORCE_INLINE T* _initAndAdd(T* node) + { + SLANG_COMPILE_TIME_ASSERT(IsValidType::Value); + + node->init(T::kType, this); + + // Only add it if it has a dtor that does some work + if (!std::is_trivially_destructible::value) + { + // Keep such that dtor can be run on ASTBuilder being dtored + m_nodes.add(node); + } + return node; + } + + String m_name; + Index m_id; + + /// All of the nodes constructed on this builder + List m_nodes; + SharedASTBuilder* m_sharedASTBuilder; + + MemoryArena m_arena; }; } // namespace Slang diff --git a/source/slang/slang-ast-decl.h b/source/slang/slang-ast-decl.h index bdb9b8ad8..428ea8dc3 100644 --- a/source/slang/slang-ast-decl.h +++ b/source/slang/slang-ast-decl.h @@ -13,7 +13,7 @@ class DeclGroup: public DeclBase { SLANG_CLASS(DeclGroup) - List> decls; + List decls; }; @@ -22,7 +22,7 @@ class ContainerDecl: public Decl { SLANG_ABSTRACT_CLASS(ContainerDecl) - List> members; + List members; template FilteredMemberList getMembersOfType() @@ -59,10 +59,10 @@ class VarDeclBase : public Decl // type of the variable TypeExp type; - Type* getType() { return (Type*)type.type.Ptr(); } + Type* getType() { return type.type; } // Initializer expression (optional) - RefPtr initExpr; + Expr* initExpr = nullptr; }; // Ordinary potentially-mutable variables (locals, globals, and member variables) @@ -135,7 +135,7 @@ class EnumDecl : public AggTypeDecl { SLANG_CLASS(EnumDecl) - RefPtr tagType; + Type* tagType = nullptr; }; // A single case in an enum. @@ -155,10 +155,10 @@ class EnumCaseDecl : public Decl // type of the parent `enum` TypeExp type; - Type* getType() { return type.type.Ptr(); } + Type* getType() { return type.type; } // Tag value - RefPtr tagExpr; + Expr* tagExpr = nullptr; }; // An interface which other types can conform to @@ -294,7 +294,7 @@ class FunctionDeclBase : public CallableDecl { SLANG_ABSTRACT_CLASS(FunctionDeclBase) - RefPtr body; + Stmt* body = nullptr; }; // A constructor/initializer to create instances of a type @@ -376,7 +376,7 @@ class ImportDecl : public Decl RefPtr scope; // The module that actually got imported - RefPtr importedModuleDecl; + ModuleDecl* importedModuleDecl = nullptr; }; // A generic declaration, parameterized on types/values @@ -384,7 +384,7 @@ class GenericDecl : public ContainerDecl { SLANG_CLASS(GenericDecl) // The decl that is genericized... - RefPtr inner; + Decl* inner = nullptr; }; class GenericTypeParamDecl : public SimpleTypeDecl @@ -441,7 +441,7 @@ class SyntaxDecl : public Decl SLANG_CLASS(SyntaxDecl) // What type of syntax node will be produced when parsing with this keyword? - SyntaxClass syntaxClass; + SyntaxClass syntaxClass; SLANG_UNREFLECTED @@ -456,7 +456,7 @@ class AttributeDecl : public ContainerDecl { SLANG_CLASS(AttributeDecl) // What type of syntax node will be produced to represent this attribute. - SyntaxClass syntaxClass; + SyntaxClass syntaxClass; }; } // namespace Slang diff --git a/source/slang/slang-ast-dump.cpp b/source/slang/slang-ast-dump.cpp index d0b2497bb..1ae51615f 100644 --- a/source/slang/slang-ast-dump.cpp +++ b/source/slang/slang-ast-dump.cpp @@ -17,7 +17,7 @@ struct Context struct ObjectInfo { const ReflectClassInfo* m_typeInfo; - RefObject* m_object; + NodeBase* m_object; bool m_isDumped; }; @@ -48,10 +48,10 @@ struct Context Context* m_context; }; - void dumpObject(const ReflectClassInfo& type, RefObject* obj); + void dumpObject(const ReflectClassInfo& type, NodeBase* obj); - void dumpObjectFull(const ReflectClassInfo& type, RefObject* obj, Index objIndex); - void dumpObjectReference(const ReflectClassInfo& type, RefObject* obj, Index objIndex); + void dumpObjectFull(const ReflectClassInfo& type, NodeBase* obj, Index objIndex); + void dumpObjectReference(const ReflectClassInfo& type, NodeBase* obj, Index objIndex); void dump(NodeBase* node) { @@ -264,7 +264,7 @@ struct Context m_writer->emit(" }"); } - Index getObjectIndex(const ReflectClassInfo& typeInfo, RefObject* obj) + Index getObjectIndex(const ReflectClassInfo& typeInfo, NodeBase* obj) { Index* indexPtr = m_objectMap.TryGetValueOrAdd(obj, m_objects.getCount()); if (indexPtr) @@ -576,7 +576,7 @@ struct Context // Using the SourceWriter, for automatic indentation. SourceWriter* m_writer; - Dictionary m_objectMap; ///< Object index + Dictionary m_objectMap; ///< Object index List m_objects; StringBuilder m_buf; @@ -605,7 +605,7 @@ SLANG_ALL_ASTNode_NodeBase(SLANG_AST_DUMP_FIELDS_IMPL, _) #define SLANG_AST_GET_DUMP_FUNC(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) m_funcs[Index(ASTNodeType::NAME)] = (DumpFieldsFunc)&ASTDumpAccess::dumpFields_##NAME; -typedef void (*DumpFieldsFunc)(RefObject* obj, Context& context); +typedef void (*DumpFieldsFunc)(NodeBase* obj, Context& context); struct DumpFieldFuncs { @@ -620,13 +620,13 @@ struct DumpFieldFuncs static const DumpFieldFuncs s_funcs; -void Context::dumpObjectReference(const ReflectClassInfo& type, RefObject* obj, Index objIndex) +void Context::dumpObjectReference(const ReflectClassInfo& type, NodeBase* obj, Index objIndex) { SLANG_UNUSED(obj); ScopeWrite(this).getBuf() << type.m_name << ":" << objIndex; } -void Context::dumpObjectFull(const ReflectClassInfo& type, RefObject* obj, Index objIndex) +void Context::dumpObjectFull(const ReflectClassInfo& type, NodeBase* obj, Index objIndex) { ObjectInfo& info = m_objects[objIndex]; SLANG_ASSERT(info.m_isDumped == false); @@ -662,7 +662,7 @@ void Context::dumpObjectFull(const ReflectClassInfo& type, RefObject* obj, Index m_writer->emit("}\n"); } -void Context::dumpObject(const ReflectClassInfo& typeInfo, RefObject* obj) +void Context::dumpObject(const ReflectClassInfo& typeInfo, NodeBase* obj) { Index index = getObjectIndex(typeInfo, obj); diff --git a/source/slang/slang-ast-expr.h b/source/slang/slang-ast-expr.h index 96e90ae02..364bbe2d1 100644 --- a/source/slang/slang-ast-expr.h +++ b/source/slang/slang-ast-expr.h @@ -39,7 +39,7 @@ class OverloadedExpr : public Expr // Optional: the base expression is this overloaded result // arose from a member-reference expression. - RefPtr base; + Expr* base = nullptr; // The lookup result that was ambiguous LookupResult lookupResult2; @@ -53,10 +53,10 @@ class OverloadedExpr2: public Expr // Optional: the base expression is this overloaded result // arose from a member-reference expression. - RefPtr base; + Expr* base = nullptr; // The lookup result that was ambiguous - List> candidiateExprs; + List candidiateExprs; }; class LiteralExpr : public Expr @@ -103,7 +103,7 @@ class StringLiteralExpr : public LiteralExpr class InitializerListExpr : public Expr { SLANG_CLASS(InitializerListExpr) - List> args; + List args; }; // A base class for expressions with arguments @@ -111,7 +111,7 @@ class ExprWithArgsBase : public Expr { SLANG_ABSTRACT_CLASS(ExprWithArgsBase) - List> arguments; + List arguments; }; // An aggregate type constructor @@ -129,7 +129,7 @@ class AppExprBase : public ExprWithArgsBase { SLANG_ABSTRACT_CLASS(AppExprBase) - RefPtr functionExpr; + Expr* functionExpr = nullptr; }; class InvokeExpr: public AppExprBase @@ -159,21 +159,21 @@ class IndexExpr: public Expr { SLANG_CLASS(IndexExpr) - RefPtr baseExpression; - RefPtr indexExpression; + Expr* baseExpression = nullptr; + Expr* indexExpression = nullptr; }; class MemberExpr: public DeclRefExpr { SLANG_CLASS(MemberExpr) - RefPtr baseExpression; + Expr* baseExpression = nullptr; }; // Member looked up on a type, rather than a value class StaticMemberExpr: public DeclRefExpr { SLANG_CLASS(StaticMemberExpr) - RefPtr baseExpression; + Expr* baseExpression = nullptr; }; struct MatrixCoord @@ -188,7 +188,7 @@ struct MatrixCoord class MatrixSwizzleExpr : public Expr { SLANG_CLASS(MatrixSwizzleExpr) - RefPtr base; + Expr* base = nullptr; int elementCount; MatrixCoord elementCoords[4]; }; @@ -196,7 +196,7 @@ class MatrixSwizzleExpr : public Expr class SwizzleExpr: public Expr { SLANG_CLASS(SwizzleExpr) - RefPtr base; + Expr* base = nullptr; int elementCount; int elementIndices[4]; }; @@ -205,7 +205,7 @@ class SwizzleExpr: public Expr class DerefExpr: public Expr { SLANG_CLASS(DerefExpr) - RefPtr base; + Expr* base = nullptr; }; // Any operation that performs type-casting @@ -213,7 +213,7 @@ class TypeCastExpr: public InvokeExpr { SLANG_CLASS(TypeCastExpr) // TypeExp TargetType; -// RefPtr Expression; +// Expr* Expression = nullptr; }; // An explicit type-cast that appear in the user's code with `(type) expr` syntax @@ -236,14 +236,14 @@ class CastToSuperTypeExpr: public Expr { SLANG_CLASS(CastToSuperTypeExpr) - /// The value being cast to a super type - /// - /// The type being case from is `valueArg->type`. - /// - RefPtr valueArg; + /// The value being cast to a super type + /// + /// The type being case from is `valueArg->type`. + /// + Expr* valueArg = nullptr; - /// A witness showing that `valueArg`'s type is a sub-type of this expression's `type` - RefPtr witnessArg; + /// A witness showing that `valueArg`'s type is a sub-type of this expression's `type` + Val* witnessArg = nullptr; }; class SelectExpr: public OperatorExpr @@ -268,8 +268,8 @@ class SharedTypeExpr: public Expr class AssignExpr: public Expr { SLANG_CLASS(AssignExpr) - RefPtr left; - RefPtr right; + Expr* left = nullptr; + Expr* right = nullptr; }; // Just an expression inside parentheses `(exp)` @@ -279,7 +279,7 @@ class AssignExpr: public Expr class ParenExpr: public Expr { SLANG_CLASS(ParenExpr) - RefPtr base; + Expr* base = nullptr; }; // An object-oriented `this` expression, used to @@ -294,8 +294,8 @@ class ThisExpr: public Expr class LetExpr: public Expr { SLANG_CLASS(LetExpr) - RefPtr decl; - RefPtr body; + VarDecl* decl = nullptr; + Expr* body = nullptr; }; class ExtractExistentialValueExpr: public Expr diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h index 4badbd02a..30ef1f921 100644 --- a/source/slang/slang-ast-modifier.h +++ b/source/slang/slang-ast-modifier.h @@ -511,7 +511,7 @@ class AttributeTargetModifier : public Modifier SLANG_CLASS(AttributeTargetModifier) // A class to which the declared attribute type is applicable - SyntaxClass syntaxClass; + SyntaxClass syntaxClass; }; // Base class for checked and unchecked `[name(arg0, ...)]` style attribute. @@ -519,7 +519,7 @@ class AttributeBase : public Modifier { SLANG_CLASS(AttributeBase) - List> args; + List args; }; // A `[name(...)]` attribute that hasn't undergone any semantic analysis. @@ -549,7 +549,7 @@ class AttributeUsageAttribute : public Attribute { SLANG_CLASS(AttributeUsageAttribute) - SyntaxClass targetSyntaxClass; + SyntaxClass targetSyntaxClass; }; // An `[unroll]` or `[unroll(count)]` attribute @@ -668,7 +668,7 @@ class PatchConstantFuncAttribute : public Attribute { SLANG_CLASS(PatchConstantFuncAttribute) - RefPtr patchConstantFuncDecl; + FuncDecl* patchConstantFuncDecl = nullptr; }; class DomainAttribute : public Attribute { diff --git a/source/slang/slang-ast-reflect.cpp b/source/slang/slang-ast-reflect.cpp index 689d9d93f..7d4fd0c1a 100644 --- a/source/slang/slang-ast-reflect.cpp +++ b/source/slang/slang-ast-reflect.cpp @@ -46,9 +46,18 @@ bool ReflectClassInfo::isSubClassOfSlow(const ThisType& super) const struct ASTConstructAccess { template - struct CreateImpl + struct Impl { - static void* create(ASTBuilder* astBuilder) { return astBuilder->create(); } + static void* create(ASTBuilder* astBuilder) + { + return astBuilder->create(); + } + static void destroy(void* ptr) + { + // Needed because if type has non dtor, Visual Studio claims ptr not used + SLANG_UNUSED(ptr); + reinterpret_cast(ptr)->~T(); + } }; }; @@ -57,14 +66,13 @@ struct ASTConstructAccess #define SLANG_GET_SUPER_LEAF(SUPER) &SUPER::kReflectClassInfo #define SLANG_GET_CREATE_FUNC_ABSTRACT(NAME) nullptr -#define SLANG_GET_CREATE_FUNC_NONE(NAME) &ASTConstructAccess::CreateImpl::create - -#define SLANG_GET_CREATE_FUNC_NON_VISITOR_ABSTRACT(NAME) nullptr -#define SLANG_GET_CREATE_FUNC_NON_VISITOR(NAME) &ASTConstructAccess::CreateImpl::create +#define SLANG_GET_CREATE_FUNC_NONE(NAME) &ASTConstructAccess::Impl::create +#define SLANG_GET_DESTROY_FUNC_ABSTRACT(NAME) nullptr +#define SLANG_GET_DESTROY_FUNC_NONE(NAME) &ASTConstructAccess::Impl::destroy #define SLANG_REFLECT_CLASS_INFO(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \ - /* static */const ReflectClassInfo NAME::kReflectClassInfo = { uint32_t(ASTNodeType::NAME), uint32_t(ASTNodeType::LAST), SLANG_GET_SUPER_##TYPE(SUPER), #NAME, SLANG_GET_CREATE_FUNC_##MARKER(NAME) }; + /* static */const ReflectClassInfo NAME::kReflectClassInfo = { uint32_t(ASTNodeType::NAME), uint32_t(ASTNodeType::LAST), SLANG_GET_SUPER_##TYPE(SUPER), #NAME, SLANG_GET_CREATE_FUNC_##MARKER(NAME), SLANG_GET_DESTROY_FUNC_##MARKER(NAME) }; SLANG_ALL_ASTNode_NodeBase(SLANG_REFLECT_CLASS_INFO, _) diff --git a/source/slang/slang-ast-reflect.h b/source/slang/slang-ast-reflect.h index 82fb80b22..8df8dbc38 100644 --- a/source/slang/slang-ast-reflect.h +++ b/source/slang/slang-ast-reflect.h @@ -5,16 +5,20 @@ #include "slang-ast-generated.h" +#define SLANG_CLASS_REFLECT_SUPER_BASE(SUPER) +#define SLANG_CLASS_REFLECT_SUPER_INNER(SUPER) typedef SUPER Super; +#define SLANG_CLASS_REFLECT_SUPER_LEAF(SUPER) typedef SUPER Super; + // Implementation for SLANG_ABSTRACT_CLASS(x) using reflection from C++ extractor in slang-ast-generated.h #define SLANG_CLASS_REFLECT_IMPL(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \ protected: \ NAME() = default; \ public: \ typedef NAME This; \ - typedef SUPER Super; \ static const ASTNodeType kType = ASTNodeType::NAME; \ static const ReflectClassInfo kReflectClassInfo; \ SLANG_FORCE_INLINE static bool isDerivedFrom(ASTNodeType type) { return int(type) >= int(kType) && int(type) <= int(ASTNodeType::LAST); } \ + SLANG_CLASS_REFLECT_SUPER_##TYPE(SUPER) \ friend class ASTBuilder; \ friend struct ASTConstructAccess; @@ -28,6 +32,8 @@ #define SLANG_REFLECTED #define SLANG_UNREFLECTED +#define SLANG_CLASS_ROOT + // Macros for simulating virtual methods without virtual methods #define SLANG_AST_NODE_INVOKE(method, methodParams) _##method##Override methodParams diff --git a/source/slang/slang-ast-stmt.h b/source/slang/slang-ast-stmt.h index 9f7f8aa4d..e9e5ea4f3 100644 --- a/source/slang/slang-ast-stmt.h +++ b/source/slang/slang-ast-stmt.h @@ -12,7 +12,7 @@ class ScopeStmt : public Stmt { SLANG_ABSTRACT_CLASS(ScopeStmt) - RefPtr scopeDecl; + ScopeDecl* scopeDecl = nullptr; }; // A sequence of statements, treated as a single statement @@ -20,7 +20,7 @@ class SeqStmt : public Stmt { SLANG_CLASS(SeqStmt) - List> stmts; + List stmts; }; // The simplest kind of scope statement: just a `{...}` block @@ -28,7 +28,7 @@ class BlockStmt : public ScopeStmt { SLANG_CLASS(BlockStmt) - RefPtr body; + Stmt* body = nullptr; }; // A statement that we aren't going to parse or check, because @@ -55,16 +55,16 @@ class DeclStmt : public Stmt { SLANG_CLASS(DeclStmt) - RefPtr decl; + DeclBase* decl = nullptr; }; class IfStmt : public Stmt { SLANG_CLASS(IfStmt) - RefPtr predicate; - RefPtr positiveStatement; - RefPtr negativeStatement; + Expr* predicate = nullptr; + Stmt* positiveStatement = nullptr; + Stmt* negativeStatement = nullptr; }; // A statement that can be escaped with a `break` @@ -78,8 +78,8 @@ class SwitchStmt : public BreakableStmt { SLANG_CLASS(SwitchStmt) - RefPtr condition; - RefPtr body; + Expr* condition = nullptr; + Stmt* body = nullptr; }; // A statement that is expected to appear lexically nested inside @@ -108,7 +108,7 @@ class CaseStmt : public CaseStmtBase { SLANG_CLASS(CaseStmt) - RefPtr expr; + Expr* expr = nullptr; }; // a `default` statement inside a `switch` @@ -129,10 +129,10 @@ class ForStmt : public LoopStmt { SLANG_CLASS(ForStmt) - RefPtr initialStatement; - RefPtr sideEffectExpression; - RefPtr predicateExpression; - RefPtr statement; + Stmt* initialStatement = nullptr; + Expr* sideEffectExpression = nullptr; + Expr* predicateExpression = nullptr; + Stmt* statement = nullptr; }; // A `for` statement in a language that doesn't restrict the scope @@ -147,16 +147,16 @@ class WhileStmt : public LoopStmt { SLANG_CLASS(WhileStmt) - RefPtr predicate; - RefPtr statement; + Expr* predicate = nullptr; + Stmt* statement = nullptr; }; class DoWhileStmt : public LoopStmt { SLANG_CLASS(DoWhileStmt) - RefPtr statement; - RefPtr predicate; + Stmt* statement = nullptr; + Expr* predicate = nullptr; }; // A compile-time, range-based `for` loop, which will not appear in the output code @@ -164,12 +164,12 @@ class CompileTimeForStmt : public ScopeStmt { SLANG_CLASS(CompileTimeForStmt) - RefPtr varDecl; - RefPtr rangeBeginExpr; - RefPtr rangeEndExpr; - RefPtr body; - RefPtr rangeBeginVal; - RefPtr rangeEndVal; + VarDecl* varDecl = nullptr; + Expr* rangeBeginExpr = nullptr; + Expr* rangeEndExpr = nullptr; + Stmt* body = nullptr; + IntVal* rangeBeginVal = nullptr; + IntVal* rangeEndVal = nullptr; }; // The case of child statements that do control flow relative @@ -193,14 +193,14 @@ class ReturnStmt : public Stmt { SLANG_CLASS(ReturnStmt) - RefPtr expression; + Expr* expression = nullptr; }; class ExpressionStmt : public Stmt { SLANG_CLASS(ExpressionStmt) - RefPtr expression; + Expr* expression = nullptr; }; } // namespace Slang diff --git a/source/slang/slang-ast-substitutions.cpp b/source/slang/slang-ast-substitutions.cpp index 05865fe8f..8a54a1d74 100644 --- a/source/slang/slang-ast-substitutions.cpp +++ b/source/slang/slang-ast-substitutions.cpp @@ -8,7 +8,7 @@ namespace Slang { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Substitutions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -RefPtr Substitutions::applySubstitutionsShallow(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff) +Substitutions* Substitutions::applySubstitutionsShallow(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) { SLANG_AST_NODE_VIRTUAL_CALL(Substitutions, applySubstitutionsShallow, (astBuilder, substSet, substOuter, ioDiff)) } @@ -23,14 +23,14 @@ HashCode Substitutions::getHashCode() const SLANG_AST_NODE_CONST_VIRTUAL_CALL(Substitutions, getHashCode, ()) } -RefPtr Substitutions::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff) +Substitutions* Substitutions::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) { SLANG_UNUSED(astBuilder); SLANG_UNUSED(substSet); SLANG_UNUSED(substOuter); SLANG_UNUSED(ioDiff); SLANG_UNEXPECTED("Substitutions::_applySubstitutionsShallowOverride not overridden"); - //return RefPtr(); + //return Substitutions*(); } bool Substitutions::_equalsOverride(Substitutions* subst) @@ -48,13 +48,13 @@ HashCode Substitutions::_getHashCodeOverride() const // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GenericSubstitution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -RefPtr GenericSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff) +Substitutions* GenericSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) { int diff = 0; if (substOuter != outer) diff++; - List> substArgs; + List substArgs; for (auto a : args) { substArgs.add(a->substituteImpl(astBuilder, substSet, &diff)); @@ -88,14 +88,14 @@ bool GenericSubstitution::_equalsOverride(Substitutions* subst) SLANG_RELEASE_ASSERT(args.getCount() == genericSubst->args.getCount()); for (Index aa = 0; aa < argCount; ++aa) { - if (!args[aa]->equalsVal(genericSubst->args[aa].Ptr())) + if (!args[aa]->equalsVal(genericSubst->args[aa])) return false; } if (!outer) return !genericSubst->outer; - if (!outer->equals(genericSubst->outer.Ptr())) + if (!outer->equals(genericSubst->outer)) return false; return true; @@ -114,14 +114,14 @@ HashCode GenericSubstitution::_getHashCodeOverride() const // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ThisTypeSubstitution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -RefPtr ThisTypeSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff) +Substitutions* ThisTypeSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) { int diff = 0; if (substOuter != outer) diff++; // NOTE: Must use .as because we must have a smart pointer here to keep in scope. - auto substWitness = witness->substituteImpl(astBuilder, substSet, &diff).as(); + auto substWitness = as(witness->substituteImpl(astBuilder, substSet, &diff)); if (!diff) return this; @@ -165,7 +165,7 @@ HashCode ThisTypeSubstitution::_getHashCodeOverride() const // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GlobalGenericParamSubstitution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -RefPtr GlobalGenericParamSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr substOuter, int* ioDiff) +Substitutions* GlobalGenericParamSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) { // if we find a GlobalGenericParamSubstitution in subst that references the same type_param decl // return a copy of that GlobalGenericParamSubstitution @@ -173,7 +173,7 @@ RefPtr GlobalGenericParamSubstitution::_applySubstitutionsShallow if (substOuter != outer) diff++; - auto substActualType = actualType->substituteImpl(astBuilder, substSet, &diff).as(); + auto substActualType = as(actualType->substituteImpl(astBuilder, substSet, &diff)); List substConstraintArgs; for (auto constraintArg : constraintArgs) @@ -190,7 +190,7 @@ RefPtr GlobalGenericParamSubstitution::_applySubstitutionsShallow (*ioDiff)++; - RefPtr substSubst = astBuilder->create(); + GlobalGenericParamSubstitution* substSubst = astBuilder->create(); substSubst->paramDecl = paramDecl; substSubst->actualType = substActualType; substSubst->constraintArgs = substConstraintArgs; diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h index 99b94f0e4..50182d56d 100644 --- a/source/slang/slang-ast-support-types.h +++ b/source/slang/slang-ast-support-types.h @@ -43,6 +43,15 @@ namespace Slang struct TypeExp; class Val; + class NodeBase; + + + template + T* as(NodeBase* node); + + template + const T* as(const NodeBase* node); + void printDiagnosticArg(StringBuilder& sb, Decl* decl); void printDiagnosticArg(StringBuilder& sb, Type* type); void printDiagnosticArg(StringBuilder& sb, TypeExp const& type); @@ -53,7 +62,7 @@ namespace Slang SourceLoc const& getDiagnosticPos(SyntaxNode const* syntax); SourceLoc const& getDiagnosticPos(TypeExp const& typeExp); - typedef RefPtr (*SyntaxParseCallback)(Parser* parser, void* userData); + typedef NodeBase* (*SyntaxParseCallback)(Parser* parser, void* userData); typedef unsigned int ConversionCost; enum : ConversionCost @@ -184,7 +193,7 @@ namespace Slang { struct Iterator { - Modifier* current; + Modifier* current = nullptr; Modifier* operator*() { @@ -218,7 +227,7 @@ namespace Slang Iterator begin() { return Iterator(modifiers); } Iterator end() { return Iterator(nullptr); } - Modifier* modifiers; + Modifier* modifiers = nullptr; }; // Helper class for iterating over heap-allocated modifiers @@ -228,7 +237,7 @@ namespace Slang { struct Iterator { - Modifier* current; + Modifier* current = nullptr; T* operator*() { @@ -264,17 +273,17 @@ namespace Slang static Modifier* adjust(Modifier* modifier); - Modifier* modifiers; + Modifier* modifiers = nullptr; }; // A set of modifiers attached to a syntax node struct Modifiers { // The first modifier in the linked list of heap-allocated modifiers - RefPtr first; + Modifier* first = nullptr; template - FilteredModifierList getModifiersOfType() { return FilteredModifierList(first.Ptr()); } + FilteredModifierList getModifiersOfType() { return FilteredModifierList(first); } // Find the first modifier of a given type, or return `nullptr` if none is found. template @@ -286,7 +295,7 @@ namespace Slang template bool hasModifier() { return findModifier() != nullptr; } - FilteredModifierList::Iterator begin() { return FilteredModifierList::Iterator(first.Ptr()); } + FilteredModifierList::Iterator begin() { return FilteredModifierList::Iterator(first); } FilteredModifierList::Iterator end() { return FilteredModifierList::Iterator(nullptr); } }; @@ -296,7 +305,7 @@ namespace Slang // Try to extract a simple integer value from an `IntVal`. // This fill assert-fail if the object doesn't represent a literal value. - IntegerLiteralValue getIntVal(RefPtr val); + IntegerLiteralValue getIntVal(IntVal* val); /// Represents how much checking has been applied to a declaration. enum class DeclCheckState : uint8_t @@ -424,12 +433,12 @@ namespace Slang }; void addModifier( - RefPtr syntax, - RefPtr modifier); + ModifiableSyntaxNode* syntax, + Modifier* modifier); struct QualType { - RefPtr type; + Type* type = nullptr; bool isLeftValue; QualType() @@ -441,11 +450,10 @@ namespace Slang , isLeftValue(false) {} - Type* Ptr() { return type.Ptr(); } + Type* Ptr() { return type; } operator Type*() { return type; } - operator RefPtr() { return type; } - RefPtr operator->() { return type; } + Type* operator->() { return type; } }; class ASTBuilder; @@ -455,6 +463,7 @@ namespace Slang typedef ReflectClassInfo ThisType; typedef void* (*CreateFunc)(ASTBuilder* astBuilder); + typedef void (*DestroyFunc)(void* ptr); /// A constant time implementation of isSubClassOf SLANG_FORCE_INLINE bool isSubClassOf(const ThisType& super) const @@ -485,6 +494,7 @@ namespace Slang const ReflectClassInfo* m_superClass; ///< The super class of this class, or nullptr if has no super class. const char* m_name; ///< Textual class name, for debugging CreateFunc m_createFunc; ///< Callback to use when creating instances + DestroyFunc m_destroyFunc; ///< Called to inplace destroy (ie not backing memory) of this type struct Infos { @@ -573,14 +583,14 @@ namespace Slang struct SubstitutionSet { - RefPtr substitutions; + Substitutions* substitutions = nullptr; operator Substitutions*() const { return substitutions; } SubstitutionSet() {} - SubstitutionSet(RefPtr subst) + SubstitutionSet(Substitutions* subst) : substitutions(subst) { } @@ -618,18 +628,18 @@ namespace Slang substitutions(subst) {} - DeclRefBase(Decl* decl, RefPtr subst) + DeclRefBase(Decl* decl, Substitutions* subst) : decl(decl) , substitutions(subst) {} // Apply substitutions to a type or declaration - RefPtr substitute(ASTBuilder* astBuilder, RefPtr type) const; + Type* substitute(ASTBuilder* astBuilder, Type* type) const; DeclRefBase substitute(ASTBuilder* astBuilder, DeclRefBase declRef) const; // Apply substitutions to an expression - RefPtr substitute(ASTBuilder* astBuilder, RefPtr expr) const; + Expr* substitute(ASTBuilder* astBuilder, Expr* expr) const; // Apply substitutions to this declaration reference DeclRefBase substituteImpl(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); @@ -672,7 +682,7 @@ namespace Slang : DeclRefBase(decl, subst) {} - DeclRef(T* decl, RefPtr subst) + DeclRef(T* decl, Substitutions* subst) : DeclRefBase(decl, SubstitutionSet(subst)) {} @@ -699,11 +709,11 @@ namespace Slang return DeclRef((T*) declRef.decl, declRef.substitutions); } - RefPtr substitute(ASTBuilder* astBuilder, RefPtr type) const + Type* substitute(ASTBuilder* astBuilder, Type* type) const { return DeclRefBase::substitute(astBuilder, type); } - RefPtr substitute(ASTBuilder* astBuilder, RefPtr expr) const + Expr* substitute(ASTBuilder* astBuilder, Expr* expr) const { return DeclRefBase::substitute(astBuilder, expr); } @@ -749,32 +759,32 @@ namespace Slang Static, ///< Only static (ie non instance) members }; - const RefPtr* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end); - const RefPtr* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end, Index index); - Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end); + Decl*const* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end); + Decl*const* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end, Index index); + Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end); template - const RefPtr* adjustFilterCursor(MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end) + Decl*const* adjustFilterCursor(MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { return adjustFilterCursorImpl(T::kReflectClassInfo, filterStyle, ptr, end); } /// Finds the element at index. If there is no element at the index (for example has too few elements), returns nullptr. template - const RefPtr* getFilterCursorByIndex(MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end, Index index) + Decl*const* getFilterCursorByIndex(MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end, Index index) { return getFilterCursorByIndexImpl(T::kReflectClassInfo, filterStyle, ptr, end, index); } template - Index getFilterCount(MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end) + Index getFilterCount(MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { return getFilterCountImpl(T::kReflectClassInfo, filterStyle, ptr, end); } template - bool isFilterNonEmpty(MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end) + bool isFilterNonEmpty(MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { return adjustFilterCursorImpl(T::kReflectClassInfo, filterStyle, ptr, end) != end; } @@ -782,7 +792,7 @@ namespace Slang template struct FilteredMemberList { - typedef RefPtr Element; + typedef Decl* Element; FilteredMemberList() : m_begin(nullptr) @@ -807,7 +817,7 @@ namespace Slang void operator++() { m_cursor = adjustFilterCursor(m_filterStyle, m_cursor + 1, m_end); } - const RefPtr& operator*() { return *(RefPtr*)(m_cursor); } + T* operator*() { return static_cast(*m_cursor); } }; Iterator begin() @@ -827,11 +837,11 @@ namespace Slang const RefPtr& getFirst() { return *begin(); } Index getCount() { return getFilterCount(m_filterStyle, m_begin, m_end); } - RefPtr operator[](Index index) const + T* operator[](Index index) const { - const RefPtr* ptr = getFilterCursorByIndex(m_filterStyle, m_begin, m_end, index); + Decl*const* ptr = getFilterCursorByIndex(m_filterStyle, m_begin, m_end, index); SLANG_ASSERT(ptr); - return *(RefPtr*)(ptr); + return static_cast(*ptr); } /// Returns true if empty (equivalent to getCount() == 0) @@ -861,18 +871,18 @@ namespace Slang struct TransparentMemberInfo { // The declaration of the transparent member - Decl* decl; + Decl* decl = nullptr; }; template struct FilteredMemberRefList { - List> const& m_decls; + List const& m_decls; SubstitutionSet m_substitutions; MemberFilterStyle m_filterStyle; FilteredMemberRefList( - List> const& decls, + List const& decls, SubstitutionSet substitutions, MemberFilterStyle filterStyle = MemberFilterStyle::All) : m_decls(decls) @@ -889,9 +899,9 @@ namespace Slang DeclRef operator[](Index index) const { - const RefPtr* decl = getFilterCursorByIndex(m_filterStyle, m_decls.begin(), m_decls.end(), index); + Decl*const* decl = getFilterCursorByIndex(m_filterStyle, m_decls.begin(), m_decls.end(), index); SLANG_ASSERT(decl); - return DeclRef((T*) decl->Ptr(), m_substitutions); + return DeclRef((T*) *decl, m_substitutions); } List> toArray() const @@ -905,15 +915,15 @@ namespace Slang struct Iterator { FilteredMemberRefList const* m_list; - const RefPtr* m_ptr; - const RefPtr* m_end; + Decl*const* m_ptr; + Decl*const* m_end; MemberFilterStyle m_filterStyle; Iterator() : m_list(nullptr), m_ptr(nullptr), m_filterStyle(MemberFilterStyle::All) {} Iterator( FilteredMemberRefList const* list, - const RefPtr* ptr, - const RefPtr* end, + Decl*const* ptr, + Decl*const* end, MemberFilterStyle filterStyle ) : m_list(list) @@ -926,7 +936,7 @@ namespace Slang void operator++() { m_ptr = adjustFilterCursor(m_filterStyle, m_ptr + 1, m_end); } - DeclRef operator*() { return DeclRef((T*) m_ptr->Ptr(), m_list->m_substitutions); } + DeclRef operator*() { return DeclRef((T*)*m_ptr, m_list->m_substitutions); } }; Iterator begin() const { return Iterator(this, adjustFilterCursor(m_filterStyle, m_decls.begin(), m_decls.end()), m_decls.end(), m_filterStyle); } @@ -948,23 +958,23 @@ namespace Slang : exp(other.exp) , type(other.type) {} - explicit TypeExp(RefPtr exp) + explicit TypeExp(Expr* exp) : exp(exp) {} - explicit TypeExp(RefPtr type) + explicit TypeExp(Type* type) : type(type) {} - TypeExp(RefPtr exp, RefPtr type) + TypeExp(Expr* exp, Type* type) : exp(exp) , type(type) {} - RefPtr exp; - RefPtr type; + Expr* exp = nullptr; + Type* type = nullptr; bool equals(Type* other); - Type* Ptr() { return type.Ptr(); } + Type* Ptr() { return type; } operator Type*() { return type; @@ -994,7 +1004,7 @@ namespace Slang // Note(tfoley): This is kept as an unowned pointer // so that a scope can't keep parts of the AST alive, // but the opposite it allowed. - ContainerDecl* containerDecl; + ContainerDecl* containerDecl = nullptr; }; // Masks to be applied when lookup up declarations @@ -1233,7 +1243,7 @@ namespace Slang , m_declRef(declRef) {} - RequirementWitness(RefPtr val); + RequirementWitness(Val* val); RequirementWitness(RefPtr witnessTable); @@ -1256,10 +1266,10 @@ namespace Slang return m_declRef; } - RefPtr getVal() + Val* getVal() { SLANG_ASSERT(getFlavor() == Flavor::val); - return m_obj.as(); + return m_val; } RefPtr getWitnessTable(); @@ -1269,7 +1279,7 @@ namespace Slang Flavor m_flavor; DeclRef m_declRef; RefPtr m_obj; - + Val* m_val = nullptr; }; typedef Dictionary RequirementDictionary; @@ -1279,7 +1289,7 @@ namespace Slang RequirementDictionary requirementDictionary; }; - typedef Dictionary> AttributeArgumentValueDict; + typedef Dictionary AttributeArgumentValueDict; struct SpecializationParam { @@ -1292,19 +1302,19 @@ namespace Slang }; Flavor flavor; SourceLoc loc; - RefPtr object; + NodeBase* object = nullptr; }; typedef List SpecializationParams; struct SpecializationArg { - RefPtr val; + Val* val = nullptr; }; typedef List SpecializationArgs; struct ExpandedSpecializationArg : SpecializationArg { - RefPtr witness; + Val* witness = nullptr; }; typedef List ExpandedSpecializationArgs; diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp index 48e95562e..f5feb4d64 100644 --- a/source/slang/slang-ast-type.cpp +++ b/source/slang/slang-ast-type.cpp @@ -11,17 +11,7 @@ namespace Slang { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Type !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -Type::~Type() -{ - // If the canonicalType !=nullptr AND it is not set to this (ie the canonicalType is another object) - // then it needs to be released because it's owned by this object. - if (canonicalType && canonicalType != this) - { - canonicalType->releaseReference(); - } -} - -RefPtr Type::createCanonicalType() +Type* Type::createCanonicalType() { SLANG_AST_NODE_VIRTUAL_CALL(Type, createCanonicalType, ()) } @@ -43,10 +33,10 @@ bool Type::_equalsImplOverride(Type* type) //return false; } -RefPtr Type::_createCanonicalTypeOverride() +Type* Type::_createCanonicalTypeOverride() { SLANG_UNEXPECTED("Type::_createCanonicalTypeOverride not overridden"); - //return RefPtr(); + //return Type*(); } bool Type::_equalsValOverride(Val* val) @@ -56,7 +46,7 @@ bool Type::_equalsValOverride(Val* val) return false; } -RefPtr Type::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* Type::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; auto canSubst = getCanonicalType()->substituteImpl(astBuilder, subst, &diff); @@ -80,12 +70,6 @@ Type* Type::getCanonicalType() auto canType = et->createCanonicalType(); et->canonicalType = canType; - // TODO(js): That this detachs when canType == this is a little surprising. It would seem - // as if this would create a circular reference on the object, but in practice there are - // no leaks so appears correct. - // That the dtor only releases if != this, also makes it surprising. - canType.detach(); - SLANG_ASSERT(et->canonicalType); } return et->canonicalType; @@ -103,7 +87,7 @@ bool OverloadGroupType::_equalsImplOverride(Type * /*type*/) return false; } -RefPtr OverloadGroupType::_createCanonicalTypeOverride() +Type* OverloadGroupType::_createCanonicalTypeOverride() { return this; } @@ -125,7 +109,7 @@ bool InitializerListType::_equalsImplOverride(Type * /*type*/) return false; } -RefPtr InitializerListType::_createCanonicalTypeOverride() +Type* InitializerListType::_createCanonicalTypeOverride() { return this; } @@ -149,12 +133,12 @@ bool ErrorType::_equalsImplOverride(Type* type) return false; } -RefPtr ErrorType::_createCanonicalTypeOverride() +Type* ErrorType::_createCanonicalTypeOverride() { return this; } -RefPtr ErrorType::_substituteImplOverride(ASTBuilder* /* astBuilder */, SubstitutionSet /*subst*/, int* /*ioDiff*/) +Val* ErrorType::_substituteImplOverride(ASTBuilder* /* astBuilder */, SubstitutionSet /*subst*/, int* /*ioDiff*/) { return this; } @@ -185,13 +169,13 @@ bool DeclRefType::_equalsImplOverride(Type * type) return false; } -RefPtr DeclRefType::_createCanonicalTypeOverride() +Type* DeclRefType::_createCanonicalTypeOverride() { // A declaration reference is already canonical return this; } -RefPtr DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { if (!subst) return this; @@ -202,7 +186,7 @@ RefPtr DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, Substit // search for a substitution that might apply to us for (auto s = subst.substitutions; s; s = s->outer) { - auto genericSubst = s.as(); + auto genericSubst = as(s); if (!genericSubst) continue; @@ -215,7 +199,7 @@ RefPtr DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, Substit int index = 0; for (auto m : genericDecl->members) { - if (m.Ptr() == genericTypeParamDecl) + if (m == genericTypeParamDecl) { // We've found it, so return the corresponding specialization argument (*ioDiff)++; @@ -269,7 +253,7 @@ RefPtr DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, Substit { for (auto s = substDeclRef.substitutions.substitutions; s; s = s->outer) { - auto thisSubst = s.as(); + auto thisSubst = as(s); if (!thisSubst) continue; @@ -325,7 +309,7 @@ bool BasicExpressionType::_equalsImplOverride(Type * type) return basicType && basicType->baseType == this->baseType; } -RefPtr BasicExpressionType::_createCanonicalTypeOverride() +Type* BasicExpressionType::_createCanonicalTypeOverride() { // A basic type is already canonical, in our setup return this; @@ -379,7 +363,7 @@ IntVal* MatrixExpressionType::getColumnCount() return as(findInnerMostGenericSubstitution(declRef.substitutions)->args[2]); } -RefPtr MatrixExpressionType::getRowType() +Type* MatrixExpressionType::getRowType() { if (!rowType) { @@ -395,14 +379,14 @@ bool ArrayExpressionType::_equalsImplOverride(Type* type) auto arrType = as(type); if (!arrType) return false; - return (areValsEqual(arrayLength, arrType->arrayLength) && baseType->equals(arrType->baseType.Ptr())); + return (areValsEqual(arrayLength, arrType->arrayLength) && baseType->equals(arrType->baseType)); } -RefPtr ArrayExpressionType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* ArrayExpressionType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; - auto elementType = baseType->substituteImpl(astBuilder, subst, &diff).as(); - auto arrlen = arrayLength->substituteImpl(astBuilder, subst, &diff).as(); + auto elementType = as(baseType->substituteImpl(astBuilder, subst, &diff)); + auto arrlen = as(arrayLength->substituteImpl(astBuilder, subst, &diff)); SLANG_ASSERT(arrlen); if (diff) { @@ -416,7 +400,7 @@ RefPtr ArrayExpressionType::_substituteImplOverride(ASTBuilder* astBuilder, return this; } -RefPtr ArrayExpressionType::_createCanonicalTypeOverride() +Type* ArrayExpressionType::_createCanonicalTypeOverride() { auto canonicalElementType = baseType->getCanonicalType(); auto canonicalArrayType = getASTBuilder()->getArrayType( @@ -459,7 +443,7 @@ bool TypeType::_equalsImplOverride(Type * t) return false; } -RefPtr TypeType::_createCanonicalTypeOverride() +Type* TypeType::_createCanonicalTypeOverride() { return getASTBuilder()->getTypeType(type->getCanonicalType()); } @@ -492,7 +476,7 @@ HashCode GenericDeclRefType::_getHashCodeOverride() return declRef.getHashCode(); } -RefPtr GenericDeclRefType::_createCanonicalTypeOverride() +Type* GenericDeclRefType::_createCanonicalTypeOverride() { return this; } @@ -521,7 +505,7 @@ HashCode NamespaceType::_getHashCodeOverride() return declRef.getHashCode(); } -RefPtr NamespaceType::_createCanonicalTypeOverride() +Type* NamespaceType::_createCanonicalTypeOverride() { return this; } @@ -547,7 +531,7 @@ bool NamedExpressionType::_equalsImplOverride(Type * /*type*/) //return false; } -RefPtr NamedExpressionType::_createCanonicalTypeOverride() +Type* NamedExpressionType::_createCanonicalTypeOverride() { if (!innerType) innerType = getType(m_astBuilder, declRef); @@ -613,18 +597,18 @@ bool FuncType::_equalsImplOverride(Type * type) return false; } -RefPtr FuncType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* FuncType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; // result type - RefPtr substResultType = resultType->substituteImpl(astBuilder, subst, &diff).as(); + Type* substResultType = as(resultType->substituteImpl(astBuilder, subst, &diff)); // parameter types - List> substParamTypes; + List substParamTypes; for (auto pp : paramTypes) { - substParamTypes.add(pp->substituteImpl(astBuilder, subst, &diff).as()); + substParamTypes.add(as(pp->substituteImpl(astBuilder, subst, &diff))); } // early exit for no change... @@ -632,26 +616,26 @@ RefPtr FuncType::_substituteImplOverride(ASTBuilder* astBuilder, Substituti return this; (*ioDiff)++; - RefPtr substType = astBuilder->create(); + FuncType* substType = astBuilder->create(); substType->resultType = substResultType; substType->paramTypes = substParamTypes; return substType; } -RefPtr FuncType::_createCanonicalTypeOverride() +Type* FuncType::_createCanonicalTypeOverride() { // result type - RefPtr canResultType = resultType->getCanonicalType(); + Type* canResultType = resultType->getCanonicalType(); // parameter types - List> canParamTypes; + List canParamTypes; for (auto pp : paramTypes) { canParamTypes.add(pp->getCanonicalType()); } - RefPtr canType = getASTBuilder()->create(); - canType->resultType = resultType; + FuncType* canType = getASTBuilder()->create(); + canType->resultType = canResultType; canType->paramTypes = canParamTypes; return canType; @@ -695,12 +679,12 @@ HashCode ExtractExistentialType::_getHashCodeOverride() return declRef.getHashCode(); } -RefPtr ExtractExistentialType::_createCanonicalTypeOverride() +Type* ExtractExistentialType::_createCanonicalTypeOverride() { return this; } -RefPtr ExtractExistentialType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* ExtractExistentialType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; auto substDeclRef = declRef.substituteImpl(astBuilder, subst, &diff); @@ -709,7 +693,7 @@ RefPtr ExtractExistentialType::_substituteImplOverride(ASTBuilder* astBuild (*ioDiff)++; - RefPtr substValue = astBuilder->create(); + ExtractExistentialType* substValue = astBuilder->create(); substValue->declRef = declRef; return substValue; } @@ -760,9 +744,9 @@ HashCode TaggedUnionType::_getHashCodeOverride() return hashCode; } -RefPtr TaggedUnionType::_createCanonicalTypeOverride() +Type* TaggedUnionType::_createCanonicalTypeOverride() { - RefPtr canType = m_astBuilder->create(); + TaggedUnionType* canType = m_astBuilder->create(); for (auto caseType : caseTypes) { @@ -773,21 +757,21 @@ RefPtr TaggedUnionType::_createCanonicalTypeOverride() return canType; } -RefPtr TaggedUnionType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* TaggedUnionType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; - List> substCaseTypes; + List substCaseTypes; for (auto caseType : caseTypes) { - substCaseTypes.add(caseType->substituteImpl(astBuilder, subst, &diff).as()); + substCaseTypes.add(as(caseType->substituteImpl(astBuilder, subst, &diff))); } if (!diff) return this; (*ioDiff)++; - RefPtr substType = astBuilder->create(); + TaggedUnionType* substType = astBuilder->create(); substType->caseTypes.swapWith(substCaseTypes); return substType; } @@ -848,7 +832,7 @@ HashCode ExistentialSpecializedType::_getHashCodeOverride() return hasher.getResult(); } -static RefPtr _getCanonicalValue(Val* val) +static Val* _getCanonicalValue(Val* val) { if (!val) return nullptr; @@ -861,9 +845,9 @@ static RefPtr _getCanonicalValue(Val* val) return val; } -RefPtr ExistentialSpecializedType::_createCanonicalTypeOverride() +Type* ExistentialSpecializedType::_createCanonicalTypeOverride() { - RefPtr canType = m_astBuilder->create(); + ExistentialSpecializedType* canType = m_astBuilder->create(); canType->baseType = baseType->getCanonicalType(); for (auto arg : args) @@ -876,17 +860,17 @@ RefPtr ExistentialSpecializedType::_createCanonicalTypeOverride() return canType; } -static RefPtr _substituteImpl(ASTBuilder* astBuilder, Val* val, SubstitutionSet subst, int* ioDiff) +static Val* _substituteImpl(ASTBuilder* astBuilder, Val* val, SubstitutionSet subst, int* ioDiff) { if (!val) return nullptr; return val->substituteImpl(astBuilder, subst, ioDiff); } -RefPtr ExistentialSpecializedType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* ExistentialSpecializedType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; - auto substBaseType = baseType->substituteImpl(astBuilder, subst, &diff).as(); + auto substBaseType = as(baseType->substituteImpl(astBuilder, subst, &diff)); ExpandedSpecializationArgs substArgs; for (auto arg : args) @@ -902,7 +886,7 @@ RefPtr ExistentialSpecializedType::_substituteImplOverride(ASTBuilder* astB (*ioDiff)++; - RefPtr substType = astBuilder->create(); + ExistentialSpecializedType* substType = astBuilder->create(); substType->baseType = substBaseType; substType->args = substArgs; return substType; @@ -937,16 +921,16 @@ HashCode ThisType::_getHashCodeOverride() interfaceDeclRef.getHashCode()); } -RefPtr ThisType::_createCanonicalTypeOverride() +Type* ThisType::_createCanonicalTypeOverride() { - RefPtr canType = m_astBuilder->create(); + ThisType* canType = m_astBuilder->create(); // TODO: need to canonicalize the decl-ref canType->interfaceDeclRef = interfaceDeclRef; return canType; } -RefPtr ThisType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* ThisType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; @@ -963,7 +947,7 @@ RefPtr ThisType::_substituteImplOverride(ASTBuilder* astBuilder, Substituti (*ioDiff)++; - RefPtr substType = m_astBuilder->create(); + ThisType* substType = m_astBuilder->create(); substType->interfaceDeclRef = substInterfaceDeclRef; return substType; } diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h index 14028eff6..10fd1ea34 100644 --- a/source/slang/slang-ast-type.h +++ b/source/slang/slang-ast-type.h @@ -15,7 +15,7 @@ class OverloadGroupType : public Type // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); }; @@ -29,7 +29,7 @@ class InitializerListType : public Type // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); }; @@ -41,10 +41,10 @@ class ErrorType : public Type // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; // A type that takes the form of a reference to some declaration @@ -55,14 +55,14 @@ class DeclRefType : public Type DeclRef declRef; - static RefPtr create(ASTBuilder* astBuilder, DeclRef declRef); + static DeclRefType* create(ASTBuilder* astBuilder, DeclRef declRef); // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); protected: DeclRefType( DeclRef declRef) @@ -88,7 +88,7 @@ class BasicExpressionType : public ArithmeticExpressionType BaseType baseType; // Overrides should be public so base classes can access - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); BasicExpressionType* _getScalarTypeOverride(); @@ -113,7 +113,7 @@ class ResourceType : public BuiltinType SLANG_ABSTRACT_CLASS(ResourceType) // The type that results from fetching an element from this resource - RefPtr elementType; + Type* elementType = nullptr; // Shape and access level information for this resource type TextureFlavor flavor; @@ -133,7 +133,7 @@ class TextureTypeBase : public ResourceType SLANG_ABSTRACT_CLASS(TextureTypeBase) protected: - TextureTypeBase(TextureFlavor inFlavor, RefPtr inElementType) + TextureTypeBase(TextureFlavor inFlavor, Type* inElementType) { elementType = inElementType; flavor = inFlavor; @@ -145,7 +145,7 @@ class TextureType : public TextureTypeBase SLANG_CLASS(TextureType) protected: - TextureType(TextureFlavor flavor, RefPtr elementType) + TextureType(TextureFlavor flavor, Type* elementType) : TextureTypeBase(flavor, elementType) {} }; @@ -157,7 +157,7 @@ class TextureSamplerType : public TextureTypeBase SLANG_CLASS(TextureSamplerType) protected: - TextureSamplerType(TextureFlavor flavor, RefPtr elementType) + TextureSamplerType(TextureFlavor flavor, Type* elementType) : TextureTypeBase(flavor, elementType) {} }; @@ -170,7 +170,7 @@ class GLSLImageType : public TextureTypeBase protected: GLSLImageType( TextureFlavor flavor, - RefPtr elementType) + Type* elementType) : TextureTypeBase(flavor, elementType) {} }; @@ -188,7 +188,7 @@ class BuiltinGenericType : public BuiltinType { SLANG_CLASS(BuiltinGenericType) - RefPtr elementType; + Type* elementType = nullptr; Type* getElementType() { return elementType; } }; @@ -373,14 +373,14 @@ class ArrayExpressionType : public Type { SLANG_CLASS(ArrayExpressionType) - RefPtr baseType; - RefPtr arrayLength; + Type* baseType = nullptr; + IntVal* arrayLength = nullptr; // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); HashCode _getHashCodeOverride(); }; @@ -392,16 +392,16 @@ class TypeType : public Type SLANG_CLASS(TypeType) // The type that this is the type of... - RefPtr type; + Type* type = nullptr; // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); protected: - TypeType(RefPtr type) + TypeType(Type* type) : type(type) {} @@ -415,10 +415,10 @@ class VectorExpressionType : public ArithmeticExpressionType // The type of vector elements. // As an invariant, this should be a basic type or an alias. - RefPtr elementType; + Type* elementType = nullptr; // The number of elements - RefPtr elementCount; + IntVal* elementCount = nullptr; // Overrides should be public so base classes can access String _toStringOverride(); @@ -434,14 +434,14 @@ class MatrixExpressionType : public ArithmeticExpressionType IntVal* getRowCount(); IntVal* getColumnCount(); - RefPtr getRowType(); + Type* getRowType(); // Overrides should be public so base classes can access String _toStringOverride(); BasicExpressionType* _getScalarTypeOverride(); private: - RefPtr rowType; + Type* rowType = nullptr; }; // The built-in `String` type @@ -506,11 +506,11 @@ class NamedExpressionType : public Type SLANG_CLASS(NamedExpressionType) DeclRef declRef; - RefPtr innerType; + Type* innerType = nullptr; // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); @@ -535,8 +535,8 @@ class FuncType : public Type // type, even if they don't affect the actual // semantic type underneath. - List> paramTypes; - RefPtr resultType; + List paramTypes; + Type* resultType = nullptr; UInt getParamCount() { return paramTypes.getCount(); } Type* getParamType(UInt index) { return paramTypes[index]; } @@ -544,8 +544,8 @@ class FuncType : public Type // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr _createCanonicalTypeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Type* _createCanonicalTypeOverride(); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); }; @@ -563,7 +563,7 @@ class GenericDeclRefType : public Type String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); protected: GenericDeclRefType( @@ -585,7 +585,7 @@ class NamespaceType : public Type String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); }; // The concrete type for a value wrapped in an existential, accessible @@ -600,8 +600,8 @@ class ExtractExistentialType : public Type String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr _createCanonicalTypeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Type* _createCanonicalTypeOverride(); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; /// A tagged union of zero or more other types. @@ -614,29 +614,29 @@ class TaggedUnionType : public Type /// For each type in this array, the array index is the /// tag value for that case. /// - List> caseTypes; + List caseTypes; // Overrides should be public so base classes can access String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr _createCanonicalTypeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Type* _createCanonicalTypeOverride(); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; class ExistentialSpecializedType : public Type { SLANG_CLASS(ExistentialSpecializedType) - RefPtr baseType; + Type* baseType = nullptr; ExpandedSpecializationArgs args; // Overrides should be public so base classes can access String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr _createCanonicalTypeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Type* _createCanonicalTypeOverride(); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; /// The type of `this` within a polymorphic declaration @@ -650,8 +650,8 @@ class ThisType : public Type String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr _createCanonicalTypeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Type* _createCanonicalTypeOverride(); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; } // namespace Slang diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index cb711a653..f2c466ba6 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -9,14 +9,14 @@ namespace Slang { -RefPtr Val::substitute(ASTBuilder* astBuilder, SubstitutionSet subst) +Val* Val::substitute(ASTBuilder* astBuilder, SubstitutionSet subst) { if (!subst) return this; int diff = 0; return substituteImpl(astBuilder, subst, &diff); } -RefPtr Val::substituteImpl(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* Val::substituteImpl(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { SLANG_AST_NODE_VIRTUAL_CALL(Val, substituteImpl, (astBuilder, subst, ioDiff)) } @@ -36,7 +36,7 @@ HashCode Val::getHashCode() SLANG_AST_NODE_VIRTUAL_CALL(Val, getHashCode, ()) } -RefPtr Val::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* Val::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { SLANG_UNUSED(astBuilder); SLANG_UNUSED(subst); @@ -104,12 +104,12 @@ HashCode GenericParamIntVal::_getHashCodeOverride() return declRef.getHashCode() ^ HashCode(0xFFFF); } -RefPtr GenericParamIntVal::_substituteImplOverride(ASTBuilder* /* astBuilder */, SubstitutionSet subst, int* ioDiff) +Val* GenericParamIntVal::_substituteImplOverride(ASTBuilder* /* astBuilder */, SubstitutionSet subst, int* ioDiff) { // search for a substitution that might apply to us for (auto s = subst.substitutions; s; s = s->outer) { - auto genSubst = s.as(); + auto genSubst = as(s); if (!genSubst) continue; @@ -122,7 +122,7 @@ RefPtr GenericParamIntVal::_substituteImplOverride(ASTBuilder* /* astBuilde int index = 0; for (auto m : genericDecl->members) { - if (m.Ptr() == declRef.getDecl()) + if (m == declRef.getDecl()) { // We've found it, so return the corresponding specialization argument (*ioDiff)++; @@ -167,7 +167,7 @@ HashCode ErrorIntVal::_getHashCodeOverride() return HashCode(typeid(this).hash_code()); } -RefPtr ErrorIntVal::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* ErrorIntVal::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { SLANG_UNUSED(astBuilder); SLANG_UNUSED(subst); @@ -187,11 +187,11 @@ bool TypeEqualityWitness::_equalsValOverride(Val* val) return sub->equals(otherWitness->sub); } -RefPtr TypeEqualityWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) +Val* TypeEqualityWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) { - RefPtr rs = astBuilder->create(); - rs->sub = sub->substituteImpl(astBuilder, subst, ioDiff).as(); - rs->sup = sup->substituteImpl(astBuilder, subst, ioDiff).as(); + TypeEqualityWitness* rs = astBuilder->create(); + rs->sub = as(sub->substituteImpl(astBuilder, subst, ioDiff)); + rs->sup = as(sup->substituteImpl(astBuilder, subst, ioDiff)); return rs; } @@ -218,7 +218,7 @@ bool DeclaredSubtypeWitness::_equalsValOverride(Val* val) && declRef.equals(otherWitness->declRef); } -RefPtr DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) +Val* DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) { if (auto genConstraintDeclRef = declRef.as()) { @@ -258,7 +258,7 @@ RefPtr DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuild return genericSubst->args[index + ordinaryParamCount]; } } - else if (auto globalGenericSubst = s.as()) + else if (auto globalGenericSubst = as(s)) { // check if the substitution is really about this global generic type parameter if (globalGenericSubst->paramDecl != genConstraintDecl->parentDecl) @@ -266,7 +266,7 @@ RefPtr DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuild for (auto constraintArg : globalGenericSubst->constraintArgs) { - if (constraintArg.decl.Ptr() != genConstraintDecl) + if (constraintArg.decl != genConstraintDecl) continue; (*ioDiff)++; @@ -278,8 +278,8 @@ RefPtr DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuild // Perform substitution on the constituent elements. int diff = 0; - auto substSub = sub->substituteImpl(astBuilder, subst, &diff).as(); - auto substSup = sup->substituteImpl(astBuilder, subst, &diff).as(); + auto substSub = as(sub->substituteImpl(astBuilder, subst, &diff)); + auto substSup = as(sup->substituteImpl(astBuilder, subst, &diff)); auto substDeclRef = declRef.substituteImpl(astBuilder, subst, &diff); if (!diff) return this; @@ -327,7 +327,7 @@ RefPtr DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuild } } - RefPtr rs = astBuilder->create(); + DeclaredSubtypeWitness* rs = astBuilder->create(); rs->sub = substSub; rs->sup = substSup; rs->declRef = substDeclRef; @@ -366,13 +366,13 @@ bool TransitiveSubtypeWitness::_equalsValOverride(Val* val) && midToSup.equals(otherWitness->midToSup); } -RefPtr TransitiveSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) +Val* TransitiveSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) { int diff = 0; - RefPtr substSub = sub->substituteImpl(astBuilder, subst, &diff).as(); - RefPtr substSup = sup->substituteImpl(astBuilder, subst, &diff).as(); - RefPtr substSubToMid = subToMid->substituteImpl(astBuilder, subst, &diff).as(); + Type* substSub = as(sub->substituteImpl(astBuilder, subst, &diff)); + Type* substSup = as(sup->substituteImpl(astBuilder, subst, &diff)); + SubtypeWitness* substSubToMid = as(subToMid->substituteImpl(astBuilder, subst, &diff)); DeclRef substMidToSup = midToSup.substituteImpl(astBuilder, subst, &diff); // If nothing changed, then we can bail out early. @@ -399,7 +399,7 @@ RefPtr TransitiveSubtypeWitness::_substituteImplOverride(ASTBuilder* astBui // In the simple case, we just construct a new transitive subtype // witness, and we move on with life. - RefPtr result = astBuilder->create(); + TransitiveSubtypeWitness* result = astBuilder->create(); result->sub = substSub; result->sup = substSup; result->subToMid = substSubToMid; @@ -455,20 +455,20 @@ HashCode ExtractExistentialSubtypeWitness::_getHashCodeOverride() return declRef.getHashCode(); } -RefPtr ExtractExistentialSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* ExtractExistentialSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; auto substDeclRef = declRef.substituteImpl(astBuilder, subst, &diff); - auto substSub = sub->substituteImpl(astBuilder, subst, &diff).as(); - auto substSup = sup->substituteImpl(astBuilder, subst, &diff).as(); + auto substSub = as(sub->substituteImpl(astBuilder, subst, &diff)); + auto substSup = as(sup->substituteImpl(astBuilder, subst, &diff)); if (!diff) return this; (*ioDiff)++; - RefPtr substValue = astBuilder->create(); + ExtractExistentialSubtypeWitness* substValue = astBuilder->create(); substValue->declRef = declRef; substValue->sub = substSub; substValue->sup = substSup; @@ -522,14 +522,14 @@ HashCode TaggedUnionSubtypeWitness::_getHashCodeOverride() return hash; } -RefPtr TaggedUnionSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* TaggedUnionSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; - auto substSub = sub->substituteImpl(astBuilder, subst, &diff).as(); - auto substSup = sup->substituteImpl(astBuilder, subst, &diff).as(); + auto substSub = as(sub->substituteImpl(astBuilder, subst, &diff)); + auto substSup = as(sup->substituteImpl(astBuilder, subst, &diff)); - List> substCaseWitnesses; + List substCaseWitnesses; for (auto caseWitness : caseWitnesses) { substCaseWitnesses.add(caseWitness->substituteImpl(astBuilder, subst, &diff)); @@ -540,7 +540,7 @@ RefPtr TaggedUnionSubtypeWitness::_substituteImplOverride(ASTBuilder* astBu (*ioDiff)++; - RefPtr substWitness = astBuilder->create(); + TaggedUnionSubtypeWitness* substWitness = astBuilder->create(); substWitness->sub = substSub; substWitness->sup = substSup; substWitness->caseWitnesses.swapWith(substCaseWitnesses); diff --git a/source/slang/slang-ast-val.h b/source/slang/slang-ast-val.h index 91c20e3b2..547bb303b 100644 --- a/source/slang/slang-ast-val.h +++ b/source/slang/slang-ast-val.h @@ -44,7 +44,7 @@ class GenericParamIntVal : public IntVal bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); protected: GenericParamIntVal(DeclRef inDeclRef) @@ -65,7 +65,7 @@ class ErrorIntVal : public IntVal bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; // A witness to the fact that some proposition is true, encoded @@ -115,8 +115,8 @@ class SubtypeWitness : public Witness { SLANG_ABSTRACT_CLASS(SubtypeWitness) - RefPtr sub; - RefPtr sup; + Type* sub = nullptr; + Type* sup = nullptr; }; class TypeEqualityWitness : public SubtypeWitness @@ -127,7 +127,7 @@ class TypeEqualityWitness : public SubtypeWitness bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; // A witness that one type is a subtype of another @@ -142,7 +142,7 @@ class DeclaredSubtypeWitness : public SubtypeWitness bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; // A witness that `sub : sup` because `sub : mid` and `mid : sup` @@ -151,7 +151,7 @@ class TransitiveSubtypeWitness : public SubtypeWitness SLANG_CLASS(TransitiveSubtypeWitness) // Witness that `sub : mid` - RefPtr subToMid; + SubtypeWitness* subToMid = nullptr; // Witness that `mid : sup` DeclRef midToSup; @@ -160,7 +160,7 @@ class TransitiveSubtypeWitness : public SubtypeWitness bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; // A witness taht `sub : sup` because `sub` was wrapped into @@ -176,7 +176,7 @@ class ExtractExistentialSubtypeWitness : public SubtypeWitness bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; // A witness that `sub : sup`, because `sub` is a tagged union @@ -190,14 +190,14 @@ class TaggedUnionSubtypeWitness : public SubtypeWitness // Witnesses that each of the "case" types in the union // is a subtype of `sup`. // - List> caseWitnesses; + List caseWitnesses; // Overrides should be public so base classes can access bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); }; } // namespace Slang diff --git a/source/slang/slang-check-conformance.cpp b/source/slang/slang-check-conformance.cpp index f57e7cb38..2a0e661a3 100644 --- a/source/slang/slang-check-conformance.cpp +++ b/source/slang/slang-check-conformance.cpp @@ -7,21 +7,24 @@ namespace Slang { - RefPtr SemanticsVisitor::createSimpleSubtypeWitness( + DeclaredSubtypeWitness* SemanticsVisitor::createSimpleSubtypeWitness( TypeWitnessBreadcrumb* breadcrumb) { - RefPtr witness = m_astBuilder->create(); + DeclaredSubtypeWitness* witness = m_astBuilder->create(); witness->sub = breadcrumb->sub; witness->sup = breadcrumb->sup; witness->declRef = breadcrumb->declRef; return witness; } - RefPtr SemanticsVisitor::createTypeWitness( - RefPtr subType, + Val* SemanticsVisitor::createTypeWitness( + Type* subType, DeclRef superTypeDeclRef, TypeWitnessBreadcrumb* inBreadcrumbs) { + SLANG_UNUSED(subType); + SLANG_UNUSED(superTypeDeclRef); + if(!inBreadcrumbs) { // We need to construct a witness to the fact @@ -58,11 +61,11 @@ namespace Slang // `witness` here will hold the first (outer-most) object // we create, which is the overall result. - RefPtr witness; + SubtypeWitness* witness = nullptr; // `link` will point at the remaining "hole" in the // data structure, to be filled in. - RefPtr* link = &witness; + SubtypeWitness** link = &witness; // As long as there is more than one breadcrumb, we // need to be creating transitive witnesses. @@ -79,7 +82,7 @@ namespace Slang // where `[...]` represents the "hole" we leave // open to fill in next. // - RefPtr transitiveWitness = m_astBuilder->create(); + TransitiveSubtypeWitness* transitiveWitness = m_astBuilder->create(); transitiveWitness->sub = bb->sub; transitiveWitness->sup = bb->sup; transitiveWitness->midToSup = bb->declRef; @@ -97,7 +100,7 @@ namespace Slang // In our running example this would be `{ A : B }`. We create // a simple (declared) subtype witness for it, and plug the // final hole, after which there shouldn't be a hole to deal with. - RefPtr declaredWitness = createSimpleSubtypeWitness(bb); + DeclaredSubtypeWitness* declaredWitness = createSimpleSubtypeWitness(bb); *link = declaredWitness; // We now know that our original `witness` variable has been @@ -121,6 +124,8 @@ namespace Slang DeclRef interfaceDeclRef, DeclRef requirementDeclRef) { + SLANG_UNUSED(interfaceDeclRef); + if(auto callableDeclRef = requirementDeclRef.as()) { // A `static` method requirement can't be satisfied by a @@ -146,10 +151,10 @@ namespace Slang } bool SemanticsVisitor::_isDeclaredSubtype( - RefPtr originalSubType, - RefPtr subType, + Type* originalSubType, + Type* subType, DeclRef superTypeDeclRef, - RefPtr* outWitness, + Val** outWitness, TypeWitnessBreadcrumb* inBreadcrumbs) { // for now look up a conformance member... @@ -271,10 +276,10 @@ namespace Slang // value for the tagged union itself (that is, if // `outWitness` is non-null). // - List> caseWitnesses; + List caseWitnesses; for(auto caseType : taggedUnionType->caseTypes) { - RefPtr caseWitness; + Val* caseWitness = nullptr; if(!_isDeclaredSubtype( caseType, @@ -316,7 +321,7 @@ namespace Slang // if(outWitness) { - RefPtr taggedUnionWitness = m_astBuilder->create(); + TaggedUnionSubtypeWitness* taggedUnionWitness = m_astBuilder->create(); taggedUnionWitness->sub = taggedUnionType; taggedUnionWitness->sup = DeclRefType::create(m_astBuilder, superTypeDeclRef); taggedUnionWitness->caseWitnesses.swapWith(caseWitnesses); @@ -331,41 +336,40 @@ namespace Slang } bool SemanticsVisitor::isDeclaredSubtype( - RefPtr subType, + Type* subType, DeclRef superTypeDeclRef) { return _isDeclaredSubtype(subType, subType, superTypeDeclRef, nullptr, nullptr); } - RefPtr SemanticsVisitor::tryGetSubtypeWitness( - RefPtr subType, + Val* SemanticsVisitor::tryGetSubtypeWitness( + Type* subType, DeclRef superTypeDeclRef) { - RefPtr result; + Val* result = nullptr; _isDeclaredSubtype(subType, subType, superTypeDeclRef, &result, nullptr); return result; } - - RefPtr SemanticsVisitor::tryGetInterfaceConformanceWitness( - RefPtr type, + Val* SemanticsVisitor::tryGetInterfaceConformanceWitness( + Type* type, DeclRef interfaceDeclRef) { return tryGetSubtypeWitness(type, interfaceDeclRef); } - RefPtr SemanticsVisitor::createTypeEqualityWitness( + Val* SemanticsVisitor::createTypeEqualityWitness( Type* type) { - RefPtr rs = m_astBuilder->create(); + TypeEqualityWitness* rs = m_astBuilder->create(); rs->sub = type; rs->sup = type; return rs; } - RefPtr SemanticsVisitor::tryGetSubtypeWitness( - RefPtr sub, - RefPtr sup) + Val* SemanticsVisitor::tryGetSubtypeWitness( + Type* sub, + Type* sup) { if(sub->equals(sup)) { diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index c37af8892..4d1379016 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -56,9 +56,9 @@ namespace Slang { - RefPtr SemanticsVisitor::TryJoinVectorAndScalarType( - RefPtr vectorType, - RefPtr scalarType) + Type* SemanticsVisitor::TryJoinVectorAndScalarType( + VectorExpressionType* vectorType, + BasicExpressionType* scalarType) { // Join( vector, S ) -> vetor // @@ -75,8 +75,8 @@ namespace Slang vectorType->elementCount); } - RefPtr SemanticsVisitor::TryJoinTypeWithInterface( - RefPtr type, + Type* SemanticsVisitor::TryJoinTypeWithInterface( + Type* type, DeclRef interfaceDeclRef) { // The most basic test here should be: does the type declare conformance to the trait. @@ -104,8 +104,8 @@ namespace Slang // the search process if `type` is a builtin scalar type, and then we only search // through types `X` that are also builtin scalar types. // - RefPtr bestType; - if(auto basicType = type.dynamicCast()) + Type* bestType = nullptr; + if(auto basicType = dynamicCast(type)) { for(Int baseTypeFlavorIndex = 0; baseTypeFlavorIndex < Int(BaseType::CountOf); baseTypeFlavorIndex++) { @@ -173,9 +173,9 @@ namespace Slang return nullptr; } - RefPtr SemanticsVisitor::TryJoinTypes( - RefPtr left, - RefPtr right) + Type* SemanticsVisitor::TryJoinTypes( + Type* left, + Type* right) { // Easy case: they are the same type! if (left->equals(right)) @@ -217,7 +217,7 @@ namespace Slang if(auto rightVector = as(right)) { // Check if the vector sizes match - if(!leftVector->elementCount->equalsVal(rightVector->elementCount.Ptr())) + if(!leftVector->elementCount->equalsVal(rightVector->elementCount)) return nullptr; // Try to join the element types @@ -293,12 +293,12 @@ namespace Slang // We will loop over the generic parameters, and for // each we will try to find a way to satisfy all // the constraints for that parameter - List> args; + List args; for (auto m : getMembers(genericDeclRef)) { if (auto typeParam = m.as()) { - RefPtr type = nullptr; + Type* type = nullptr; for (auto& c : system->constraints) { if (c.decl != typeParam.getDecl()) @@ -337,7 +337,7 @@ namespace Slang // TODO(tfoley): maybe support more than integers some day? // TODO(tfoley): figure out how this needs to interact with // compile-time integers that aren't just constants... - RefPtr val = nullptr; + IntVal* val = nullptr; for (auto& c : system->constraints) { if (c.decl != valParam.getDecl()) @@ -391,7 +391,7 @@ namespace Slang // search for a conformance `Robin : ISidekick`, which involved // apply the substitutions we already know... - RefPtr solvedSubst = m_astBuilder->create(); + GenericSubstitution* solvedSubst = m_astBuilder->create(); solvedSubst->genericDecl = genericDeclRef.getDecl(); solvedSubst->outer = genericDeclRef.substitutions.substitutions; solvedSubst->args = args; @@ -442,8 +442,8 @@ namespace Slang bool SemanticsVisitor::TryUnifyVals( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd) + Val* fst, + Val* snd) { // if both values are types, then unify types if (auto fstType = as(fst)) @@ -503,13 +503,13 @@ namespace Slang SLANG_UNIMPLEMENTED_X("value unification case"); // default: fail - return false; + //return false; } bool SemanticsVisitor::tryUnifySubstitutions( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd) + Substitutions* fst, + Substitutions* snd) { // They must both be NULL or non-NULL if (!fst || !snd) @@ -533,8 +533,8 @@ namespace Slang bool SemanticsVisitor::tryUnifyGenericSubstitutions( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd) + GenericSubstitution* fst, + GenericSubstitution* snd) { SLANG_ASSERT(fst); SLANG_ASSERT(snd); @@ -568,13 +568,13 @@ namespace Slang bool SemanticsVisitor::TryUnifyTypeParam( ConstraintSystem& constraints, - RefPtr typeParamDecl, - RefPtr type) + GenericTypeParamDecl* typeParamDecl, + Type* type) { // We want to constrain the given type parameter // to equal the given type. Constraint constraint; - constraint.decl = typeParamDecl.Ptr(); + constraint.decl = typeParamDecl; constraint.val = type; constraints.constraints.add(constraint); @@ -584,8 +584,8 @@ namespace Slang bool SemanticsVisitor::TryUnifyIntParam( ConstraintSystem& constraints, - RefPtr paramDecl, - RefPtr val) + GenericValueParamDecl* paramDecl, + IntVal* val) { // We only want to accumulate constraints on // the parameters of the declarations being @@ -597,7 +597,7 @@ namespace Slang // We want to constrain the given parameter to equal the given value. Constraint constraint; - constraint.decl = paramDecl.Ptr(); + constraint.decl = paramDecl; constraint.val = val; constraints.constraints.add(constraint); @@ -608,11 +608,11 @@ namespace Slang bool SemanticsVisitor::TryUnifyIntParam( ConstraintSystem& constraints, DeclRef const& varRef, - RefPtr val) + IntVal* val) { if(auto genericValueParamRef = varRef.as()) { - return TryUnifyIntParam(constraints, RefPtr(genericValueParamRef.getDecl()), val); + return TryUnifyIntParam(constraints, genericValueParamRef.getDecl(), val); } else { @@ -622,8 +622,8 @@ namespace Slang bool SemanticsVisitor::TryUnifyTypesByStructuralMatch( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd) + Type* fst, + Type* snd) { if (auto fstDeclRefType = as(fst)) { @@ -661,8 +661,8 @@ namespace Slang bool SemanticsVisitor::TryUnifyTypes( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd) + Type* fst, + Type* snd) { if (fst->equals(snd)) return true; diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index c4e809025..ba4a9b8d9 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -24,7 +24,7 @@ namespace Slang } bool SemanticsVisitor::isEffectivelyScalarForInitializerLists( - RefPtr type) + Type* type) { if(as(type)) return false; if(as(type)) return false; @@ -58,8 +58,8 @@ namespace Slang } bool SemanticsVisitor::shouldUseInitializerDirectly( - RefPtr toType, - RefPtr fromExpr) + Type* toType, + Expr* fromExpr) { // A nested initializer list should always be used directly. // @@ -89,9 +89,9 @@ namespace Slang } bool SemanticsVisitor::_readValueFromInitializerList( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr, + Type* toType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr, UInt &ioInitArgIndex) { // First, we will check if we have run out of arguments @@ -152,9 +152,9 @@ namespace Slang } bool SemanticsVisitor::_readAggregateValueFromInitializerList( - RefPtr inToType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr, + Type* inToType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr, UInt &ioArgIndex) { auto toType = inToType; @@ -162,7 +162,7 @@ namespace Slang // In the case where we need to build a result expression, // we will collect the new arguments here - List> coercedArgs; + List coercedArgs; if(isEffectivelyScalarForInitializerLists(toType)) { @@ -215,7 +215,7 @@ namespace Slang for(UInt ee = 0; ee < elementCount; ++ee) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toElementType, outToExpr ? &coercedArg : nullptr, @@ -263,7 +263,7 @@ namespace Slang for(UInt ee = 0; ee < elementCount; ++ee) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toElementType, outToExpr ? &coercedArg : nullptr, @@ -289,7 +289,7 @@ namespace Slang UInt elementCount = 0; while(ioArgIndex < argCount) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toElementType, outToExpr ? &coercedArg : nullptr, @@ -352,7 +352,7 @@ namespace Slang for(UInt rr = 0; rr < rowCount; ++rr) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toRowType, outToExpr ? &coercedArg : nullptr, @@ -380,7 +380,7 @@ namespace Slang // for(auto fieldDeclRef : getMembersOfType(toStructDeclRef, MemberFilterStyle::Instance)) { - RefPtr coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( getType(m_astBuilder, fieldDeclRef), outToExpr ? &coercedArg : nullptr, @@ -429,9 +429,9 @@ namespace Slang } bool SemanticsVisitor::_coerceInitializerList( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr) + Type* toType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr) { UInt argCount = fromInitializerListExpr->args.getCount(); UInt argIndex = 0; @@ -454,9 +454,9 @@ namespace Slang } bool SemanticsVisitor::_failedCoercion( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromExpr) + Type* toType, + Expr** outToExpr, + Expr* fromExpr) { if(outToExpr) { @@ -478,10 +478,10 @@ namespace Slang } bool SemanticsVisitor::_coerce( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromType, - RefPtr fromExpr, + Type* toType, + Expr** outToExpr, + Type* fromType, + Expr* fromExpr, ConversionCost* outCost) { // An important and easy case is when the "to" and "from" types are equal. @@ -571,7 +571,7 @@ namespace Slang // ConversionCost subCost = kConversionCost_None; - RefPtr derefExpr; + DerefExpr* derefExpr = nullptr; if(outToExpr) { derefExpr = m_astBuilder->create(); @@ -754,8 +754,8 @@ namespace Slang } bool SemanticsVisitor::canCoerce( - RefPtr toType, - RefPtr fromType, + Type* toType, + Type* fromType, ConversionCost* outCost) { // As an optimization, we will maintain a cache of conversion results @@ -764,11 +764,11 @@ namespace Slang bool shouldAddToCache = false; ConversionCost cost; - TypeCheckingCache* typeCheckingCache = getSession()->getTypeCheckingCache(); + TypeCheckingCache* typeCheckingCache = getLinkage()->getTypeCheckingCache(); BasicTypeKeyPair cacheKey; - cacheKey.type1 = makeBasicTypeKey(toType.Ptr()); - cacheKey.type2 = makeBasicTypeKey(fromType.Ptr()); + cacheKey.type1 = makeBasicTypeKey(toType); + cacheKey.type2 = makeBasicTypeKey(fromType); if( cacheKey.isValid()) { @@ -811,16 +811,16 @@ namespace Slang return rs; } - RefPtr SemanticsVisitor::createImplicitCastExpr() + TypeCastExpr* SemanticsVisitor::createImplicitCastExpr() { return m_astBuilder->create(); } - RefPtr SemanticsVisitor::CreateImplicitCastExpr( - RefPtr toType, - RefPtr fromExpr) + Expr* SemanticsVisitor::CreateImplicitCastExpr( + Type* toType, + Expr* fromExpr) { - RefPtr castExpr = createImplicitCastExpr(); + TypeCastExpr* castExpr = createImplicitCastExpr(); auto typeType = m_astBuilder->getTypeType(toType); @@ -835,12 +835,12 @@ namespace Slang return castExpr; } - RefPtr SemanticsVisitor::createCastToSuperTypeExpr( - RefPtr toType, - RefPtr fromExpr, - RefPtr witness) + Expr* SemanticsVisitor::createCastToSuperTypeExpr( + Type* toType, + Expr* fromExpr, + Val* witness) { - RefPtr expr = m_astBuilder->create(); + CastToSuperTypeExpr* expr = m_astBuilder->create(); expr->loc = fromExpr->loc; expr->type = QualType(toType); expr->valueArg = fromExpr; @@ -848,16 +848,16 @@ namespace Slang return expr; } - RefPtr SemanticsVisitor::coerce( - RefPtr toType, - RefPtr fromExpr) + Expr* SemanticsVisitor::coerce( + Type* toType, + Expr* fromExpr) { - RefPtr expr; + Expr* expr = nullptr; if (!_coerce( toType, &expr, - fromExpr->type.Ptr(), - fromExpr.Ptr(), + fromExpr->type, + fromExpr, nullptr)) { // Note(tfoley): We don't call `CreateErrorExpr` here, because that would @@ -872,8 +872,8 @@ namespace Slang } bool SemanticsVisitor::canConvertImplicitly( - RefPtr toType, - RefPtr fromType) + Type* toType, + Type* fromType) { // Can we convert at all? ConversionCost conversionCost; diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 8486bf107..b69c8cf0d 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -42,7 +42,7 @@ namespace Slang void visitDecl(Decl*) {} void visitDeclGroup(DeclGroup*) {} - void checkVarDeclCommon(RefPtr varDecl); + void checkVarDeclCommon(VarDeclBase* varDecl); void visitVarDecl(VarDecl* varDecl) { @@ -149,7 +149,7 @@ namespace Slang void visitDecl(Decl*) {} void visitDeclGroup(DeclGroup*) {} - void checkVarDeclCommon(RefPtr varDecl); + void checkVarDeclCommon(VarDeclBase* varDecl); void visitVarDecl(VarDecl* varDecl) { @@ -290,7 +290,7 @@ namespace Slang SemanticsVisitor* sema, DiagnosticSink* sink, DeclRef declRef, - RefPtr* outTypeResult, + Type** outTypeResult, SourceLoc loc) { if( sema ) @@ -452,14 +452,14 @@ namespace Slang DeclRef declRef, SourceLoc loc) { - RefPtr typeResult; + Type* typeResult = nullptr; return getTypeForDeclRef(astBuilder, nullptr, nullptr, declRef, &typeResult, loc); } DeclRef ApplyExtensionToType( SemanticsVisitor* semantics, ExtensionDecl* extDecl, - RefPtr type) + Type* type) { if(!semantics) return DeclRef(); @@ -467,12 +467,12 @@ namespace Slang return semantics->ApplyExtensionToType(extDecl, type); } - RefPtr createDefaultSubstitutionsForGeneric( + GenericSubstitution* createDefaultSubstitutionsForGeneric( ASTBuilder* astBuilder, GenericDecl* genericDecl, - RefPtr outerSubst) + Substitutions* outerSubst) { - RefPtr genericSubst = astBuilder->create(); + GenericSubstitution* genericSubst = astBuilder->create(); genericSubst->genericDecl = genericDecl; genericSubst->outer = outerSubst; @@ -493,7 +493,7 @@ namespace Slang { if (auto genericTypeConstraintDecl = as(mm)) { - RefPtr witness = astBuilder->create(); + DeclaredSubtypeWitness* witness = astBuilder->create(); witness->declRef = DeclRef(genericTypeConstraintDecl, outerSubst); witness->sub = genericTypeConstraintDecl->sub.type; witness->sup = genericTypeConstraintDecl->sup.type; @@ -521,7 +521,7 @@ namespace Slang if(decl != genericDecl->inner) return outerSubstSet; - RefPtr genericSubst = createDefaultSubstitutionsForGeneric( + GenericSubstitution* genericSubst = createDefaultSubstitutionsForGeneric( astBuilder, genericDecl, outerSubstSet.substitutions); @@ -775,7 +775,7 @@ namespace Slang return true; } - void SemanticsDeclHeaderVisitor::checkVarDeclCommon(RefPtr varDecl) + void SemanticsDeclHeaderVisitor::checkVarDeclCommon(VarDeclBase* varDecl) { // A variable that didn't have an explicit type written must // have its type inferred from the initial-value expression. @@ -851,7 +851,7 @@ namespace Slang } } - void SemanticsDeclBodyVisitor::checkVarDeclCommon(RefPtr varDecl) + void SemanticsDeclBodyVisitor::checkVarDeclCommon(VarDeclBase* varDecl) { if (auto initExpr = varDecl->initExpr) { @@ -1093,7 +1093,7 @@ namespace Slang // TODO: This could be factored into another visitor pass // that fits more with the standard checking below. // - for(auto& importDecl : moduleDecl->getMembersOfType()) + for(auto importDecl : moduleDecl->getMembersOfType()) { ensureDecl(importDecl, DeclCheckState::Checked); } @@ -1263,13 +1263,13 @@ namespace Slang // be compared). return doesMemberSatisfyRequirement( - DeclRef(genDecl.getDecl()->inner.Ptr(), genDecl.substitutions), - DeclRef(requirementGenDecl.getDecl()->inner.Ptr(), requirementGenDecl.substitutions), + DeclRef(genDecl.getDecl()->inner, genDecl.substitutions), + DeclRef(requirementGenDecl.getDecl()->inner, requirementGenDecl.substitutions), witnessTable); } bool SemanticsVisitor::doesTypeSatisfyAssociatedTypeRequirement( - RefPtr satisfyingType, + Type* satisfyingType, DeclRef requiredAssociatedTypeDeclRef, RefPtr witnessTable) { @@ -1426,6 +1426,8 @@ namespace Slang DeclRef requiredMemberDeclRef, RefPtr witnessTable) { + SLANG_UNUSED(interfaceDeclRef) + // The goal of this function is to find a suitable // value to satisfy the requirement. // @@ -1608,7 +1610,7 @@ namespace Slang // // TODO: need to decide if a this-type substitution is needed here. // It probably it. - RefPtr targetType = DeclRefType::create(m_astBuilder, interfaceDeclRef); + Type* targetType = DeclRefType::create(m_astBuilder, interfaceDeclRef); auto extDeclRef = ApplyExtensionToType(candidateExt, targetType); if(!extDeclRef) continue; @@ -1992,8 +1994,9 @@ namespace Slang // * come first in the list of base types // Index inheritanceClauseCounter = 0; - RefPtr tagType; - InheritanceDecl* tagTypeInheritanceDecl = nullptr; + + Type* tagType = nullptr; + InheritanceDecl* tagTypeInheritanceDecl = nullptr; for(auto inheritanceDecl : decl->getMembersOfType()) { Index inheritanceClauseIndex = inheritanceClauseCounter++; @@ -2088,9 +2091,9 @@ namespace Slang // seems like the best place to do it. { // First, look up the type of the `__EnumType` interface. - RefPtr enumTypeType = getASTBuilder()->getEnumTypeType(); + Type* enumTypeType = getASTBuilder()->getEnumTypeType(); - RefPtr enumConformanceDecl = m_astBuilder->create(); + InheritanceDecl* enumConformanceDecl = m_astBuilder->create(); enumConformanceDecl->parentDecl = decl; enumConformanceDecl->loc = decl->loc; enumConformanceDecl->base.type = getASTBuilder()->getEnumTypeType(); @@ -2106,7 +2109,7 @@ namespace Slang Name* tagAssociatedTypeName = getSession()->getNameObj("__Tag"); Decl* tagAssociatedTypeDecl = nullptr; - if(auto enumTypeTypeDeclRefType = enumTypeType.dynamicCast()) + if(auto enumTypeTypeDeclRefType = dynamicCast(enumTypeType)) { if(auto enumTypeTypeInterfaceDecl = as(enumTypeTypeDeclRefType->declRef.getDecl())) { @@ -2174,7 +2177,7 @@ namespace Slang // the tag value for a successor case that doesn't // provide an explicit tag. - RefPtr explicitTagVal = TryConstantFoldExpr(explicitTagValExpr); + IntVal* explicitTagVal = TryConstantFoldExpr(explicitTagValExpr); if(explicitTagVal) { if(auto constIntVal = as(explicitTagVal)) @@ -2198,7 +2201,7 @@ namespace Slang { // This tag has no initializer, so it should use // the default tag value we are tracking. - RefPtr tagValExpr = m_astBuilder->create(); + IntegerLiteralExpr* tagValExpr = m_astBuilder->create(); tagValExpr->loc = caseDecl->loc; tagValExpr->type = QualType(tagType); tagValExpr->value = defaultTag; @@ -2315,7 +2318,7 @@ namespace Slang bool SemanticsVisitor::doGenericSignaturesMatch( GenericDecl* left, GenericDecl* right, - RefPtr* outSubstRightToLeft) + GenericSubstitution** outSubstRightToLeft) { // Our first goal here is to determine if `left` and // `right` have equivalent lists of explicit @@ -2577,10 +2580,10 @@ namespace Slang return true; } - RefPtr SemanticsVisitor::createDummySubstitutions( + GenericSubstitution* SemanticsVisitor::createDummySubstitutions( GenericDecl* genericDecl) { - RefPtr subst = m_astBuilder->create(); + GenericSubstitution* subst = m_astBuilder->create(); subst->genericDecl = genericDecl; for (auto dd : genericDecl->members) { @@ -2703,7 +2706,7 @@ namespace Slang // Then we will compare the parameter types of `foo2` // against the specialization `foo1`. // - RefPtr subst; + GenericSubstitution* subst = nullptr; if(!doGenericSignaturesMatch(newGenericDecl, oldGenericDecl, &subst)) return SLANG_OK; @@ -2982,7 +2985,7 @@ namespace Slang void SemanticsDeclHeaderVisitor::checkCallableDeclCommon(CallableDecl* decl) { - for(auto& paramDecl : decl->getParameters()) + for(auto paramDecl : decl->getParameters()) { ensureDecl(paramDecl, DeclCheckState::ReadyForReference); } @@ -3004,7 +3007,7 @@ namespace Slang checkCallableDeclCommon(funcDecl); } - IntegerLiteralValue SemanticsVisitor::GetMinBound(RefPtr val) + IntegerLiteralValue SemanticsVisitor::GetMinBound(IntVal* val) { if (auto constantVal = as(val)) return constantVal->value; @@ -3145,7 +3148,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::calcThisType(DeclRef declRef) + Type* SemanticsVisitor::calcThisType(DeclRef declRef) { if( auto interfaceDeclRef = declRef.as() ) { @@ -3154,7 +3157,7 @@ namespace Slang // conform to the interface and fill in its // requirements. // - RefPtr thisType = m_astBuilder->create(); + ThisType* thisType = m_astBuilder->create(); thisType->interfaceDeclRef = interfaceDeclRef; return thisType; } @@ -3203,7 +3206,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::calcThisType(Type* type) + Type* SemanticsVisitor::calcThisType(Type* type) { if( auto declRefType = as(type) ) { @@ -3215,7 +3218,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::findResultTypeForConstructorDecl(ConstructorDecl* decl) + Type* SemanticsVisitor::findResultTypeForConstructorDecl(ConstructorDecl* decl) { // We want to look at the parent of the declaration, // but if the declaration is generic, the parent will be @@ -3269,7 +3272,7 @@ namespace Slang if(!anyAccessors) { - RefPtr getterDecl = m_astBuilder->create(); + GetterDecl* getterDecl = m_astBuilder->create(); getterDecl->loc = decl->loc; getterDecl->parentDecl = decl; @@ -3310,7 +3313,7 @@ namespace Slang DeclRef SemanticsVisitor::ApplyExtensionToType( ExtensionDecl* extDecl, - RefPtr type) + Type* type) { DeclRef extDeclRef = makeDeclRef(extDecl); @@ -3339,7 +3342,7 @@ namespace Slang } // Now extract the target type from our (possibly specialized) extension decl-ref. - RefPtr targetType = getTargetType(m_astBuilder, extDeclRef); + Type* targetType = getTargetType(m_astBuilder, extDeclRef); // As a bit of a kludge here, if the target type of the extension is // an interface, and the `type` we are trying to match up has a this-type @@ -3360,17 +3363,17 @@ namespace Slang { // Looks like we have a match in the types, // now let's see if we have a this-type substitution. - if(auto appThisTypeSubst = appInterfaceDeclRef.substitutions.substitutions.as()) + if(auto appThisTypeSubst = as(appInterfaceDeclRef.substitutions.substitutions)) { if(appThisTypeSubst->interfaceDecl == appInterfaceDeclRef.getDecl()) { // The type we want to apply to has a this-type substitution, // and (by construction) the target type currently does not. // - SLANG_ASSERT(!targetInterfaceDeclRef.substitutions.substitutions.as()); + SLANG_ASSERT(!as(targetInterfaceDeclRef.substitutions.substitutions)); // We will create a new substitution to apply to the target type. - RefPtr newTargetSubst = m_astBuilder->create(); + ThisTypeSubstitution* newTargetSubst = m_astBuilder->create(); newTargetSubst->interfaceDecl = appThisTypeSubst->interfaceDecl; newTargetSubst->witness = appThisTypeSubst->witness; newTargetSubst->outer = targetInterfaceDeclRef.substitutions.substitutions; @@ -3385,7 +3388,7 @@ namespace Slang // references to the target type of the extension // declaration have a chance to resolve the way we want them to. - RefPtr newExtSubst = m_astBuilder->create(); + ThisTypeSubstitution* newExtSubst = m_astBuilder->create(); newExtSubst->interfaceDecl = appThisTypeSubst->interfaceDecl; newExtSubst->witness = appThisTypeSubst->witness; newExtSubst->outer = extDeclRef.substitutions.substitutions; @@ -3425,7 +3428,7 @@ namespace Slang QualType SemanticsVisitor::GetTypeForDeclRef(DeclRef declRef, SourceLoc loc) { - RefPtr typeResult; + Type* typeResult = nullptr; return getTypeForDeclRef( m_astBuilder, this, @@ -3462,7 +3465,7 @@ namespace Slang if (!importDecl->hasModifier()) continue; - importModuleIntoScope(scope, importDecl->importedModuleDecl.Ptr()); + importModuleIntoScope(scope, importDecl->importedModuleDecl); } } diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index c0beb8262..307ec6316 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -15,10 +15,10 @@ namespace Slang { - RefPtr SemanticsVisitor::getExprDeclRefType(Expr * expr) + DeclRefType* SemanticsVisitor::getExprDeclRefType(Expr * expr) { if (auto typetype = as(expr->type)) - return typetype->type.dynamicCast(); + return dynamicCast(typetype->type); else return as(expr->type); } @@ -29,18 +29,18 @@ namespace Slang /// the temporary, and the computation created by `func`. /// template - RefPtr SemanticsVisitor::moveTemp(RefPtr const& expr, F const& func) + Expr* SemanticsVisitor::moveTemp(Expr* const& expr, F const& func) { - RefPtr varDecl = m_astBuilder->create(); + VarDecl* varDecl = m_astBuilder->create(); varDecl->parentDecl = nullptr; // TODO: need to fill this in somehow! varDecl->checkState = DeclCheckState::Checked; varDecl->nameAndLoc.loc = expr->loc; varDecl->initExpr = expr; varDecl->type.type = expr->type.type; - auto varDeclRef = makeDeclRef(varDecl.Ptr()); + auto varDeclRef = makeDeclRef(varDecl); - RefPtr letExpr = m_astBuilder->create(); + LetExpr* letExpr = m_astBuilder->create(); letExpr->decl = varDecl; auto body = func(varDeclRef); @@ -58,7 +58,7 @@ namespace Slang /// a new variable to hold `expr`, using `moveTemp()`. /// template - RefPtr SemanticsVisitor::maybeMoveTemp(RefPtr const& expr, F const& func) + Expr* SemanticsVisitor::maybeMoveTemp(Expr* const& expr, F const& func) { if(auto varExpr = as(expr)) { @@ -88,8 +88,8 @@ namespace Slang /// returns an expression that logically corresponds to `v`: an expression /// of type `X`, where the type carries the knowledge that `X` implements `IMover`. /// - RefPtr SemanticsVisitor::openExistential( - RefPtr expr, + Expr* SemanticsVisitor::openExistential( + Expr* expr, DeclRef interfaceDeclRef) { // If `expr` refers to an immutable binding, @@ -102,15 +102,15 @@ namespace Slang auto interfaceDecl = interfaceDeclRef.getDecl(); return maybeMoveTemp(expr, [&](DeclRef varDeclRef) { - RefPtr openedType = m_astBuilder->create(); + ExtractExistentialType* openedType = m_astBuilder->create(); openedType->declRef = varDeclRef; - RefPtr openedWitness = m_astBuilder->create(); + ExtractExistentialSubtypeWitness* openedWitness = m_astBuilder->create(); openedWitness->sub = openedType; openedWitness->sup = expr->type.type; openedWitness->declRef = varDeclRef; - RefPtr openedThisType = m_astBuilder->create(); + ThisTypeSubstitution* openedThisType = m_astBuilder->create(); openedThisType->outer = interfaceDeclRef.substitutions.substitutions; openedThisType->interfaceDecl = interfaceDecl; openedThisType->witness = openedWitness; @@ -118,7 +118,7 @@ namespace Slang DeclRef substDeclRef = DeclRef(interfaceDecl, openedThisType); auto substDeclRefType = DeclRefType::create(m_astBuilder, substDeclRef); - RefPtr openedValue = m_astBuilder->create(); + ExtractExistentialValueExpr* openedValue = m_astBuilder->create(); openedValue->declRef = varDeclRef; openedValue->type = QualType(substDeclRefType); @@ -134,7 +134,7 @@ namespace Slang /// See `openExistential` for a discussion of what "opening" an /// existential-type value means. /// - RefPtr SemanticsVisitor::maybeOpenExistential(RefPtr expr) + Expr* SemanticsVisitor::maybeOpenExistential(Expr* expr) { auto exprType = expr->type.type; @@ -151,7 +151,7 @@ namespace Slang // to the chosen interface decl must be the first substitution on // the list (which is a linked list from the "inside" out). // - auto thisTypeSubst = interfaceDeclRef.substitutions.substitutions.as(); + auto thisTypeSubst = as(interfaceDeclRef.substitutions.substitutions); if(thisTypeSubst && thisTypeSubst->interfaceDecl == interfaceDeclRef.decl) { // This isn't really an existential type, because somebody @@ -170,9 +170,9 @@ namespace Slang return expr; } - RefPtr SemanticsVisitor::ConstructDeclRefExpr( + Expr* SemanticsVisitor::ConstructDeclRefExpr( DeclRef declRef, - RefPtr baseExpr, + Expr* baseExpr, SourceLoc loc) { // Compute the type that this declaration reference will have in context. @@ -230,7 +230,7 @@ namespace Slang { // Extract the type of the baseExpr auto baseExprType = baseExpr->type.type; - RefPtr baseTypeExpr = m_astBuilder->create(); + SharedTypeExpr* baseTypeExpr = m_astBuilder->create(); baseTypeExpr->base.type = baseExprType; baseTypeExpr->type.type = m_astBuilder->getTypeType(baseExprType); @@ -283,8 +283,8 @@ namespace Slang } } - RefPtr SemanticsVisitor::ConstructDerefExpr( - RefPtr base, + Expr* SemanticsVisitor::ConstructDerefExpr( + Expr* base, SourceLoc loc) { auto ptrLikeType = as(base->type); @@ -300,9 +300,9 @@ namespace Slang return derefExpr; } - RefPtr SemanticsVisitor::ConstructLookupResultExpr( + Expr* SemanticsVisitor::ConstructLookupResultExpr( LookupResultItem const& item, - RefPtr baseExpr, + Expr* baseExpr, SourceLoc loc) { // If we collected any breadcrumbs, then these represent @@ -387,7 +387,7 @@ namespace Slang // refernece to `this.someStaticMember` will be translated // over to `This.someStaticMember`. // - RefPtr expr = m_astBuilder->create(); + ThisExpr* expr = m_astBuilder->create(); expr->type.type = thisType; expr->loc = loc; @@ -411,10 +411,10 @@ namespace Slang return ConstructDeclRefExpr(item.declRef, bb, loc); } - RefPtr SemanticsVisitor::createLookupResultExpr( + Expr* SemanticsVisitor::createLookupResultExpr( Name* name, LookupResult const& lookupResult, - RefPtr baseExpr, + Expr* baseExpr, SourceLoc loc) { if (lookupResult.isOverloaded()) @@ -513,7 +513,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::_resolveOverloadedExprImpl(RefPtr overloadedExpr, LookupMask mask, DiagnosticSink* diagSink) + Expr* SemanticsVisitor::_resolveOverloadedExprImpl(OverloadedExpr* overloadedExpr, LookupMask mask, DiagnosticSink* diagSink) { auto lookupResult = overloadedExpr->lookupResult2; SLANG_RELEASE_ASSERT(lookupResult.isValid() && lookupResult.isOverloaded()); @@ -568,7 +568,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::maybeResolveOverloadedExpr(RefPtr expr, LookupMask mask, DiagnosticSink* diagSink) + Expr* SemanticsVisitor::maybeResolveOverloadedExpr(Expr* expr, LookupMask mask, DiagnosticSink* diagSink) { if( auto overloadedExpr = as(expr) ) { @@ -580,12 +580,12 @@ namespace Slang } } - RefPtr SemanticsVisitor::resolveOverloadedExpr(RefPtr overloadedExpr, LookupMask mask) + Expr* SemanticsVisitor::resolveOverloadedExpr(OverloadedExpr* overloadedExpr, LookupMask mask) { return _resolveOverloadedExprImpl(overloadedExpr, mask, getSink()); } - RefPtr SemanticsVisitor::CheckTerm(RefPtr term) + Expr* SemanticsVisitor::CheckTerm(Expr* term) { if (!term) return nullptr; @@ -593,13 +593,13 @@ namespace Slang return exprVisitor.dispatch(term); } - RefPtr SemanticsVisitor::CreateErrorExpr(Expr* expr) + Expr* SemanticsVisitor::CreateErrorExpr(Expr* expr) { expr->type = QualType(m_astBuilder->getErrorType()); return expr; } - bool SemanticsVisitor::IsErrorExpr(RefPtr expr) + bool SemanticsVisitor::IsErrorExpr(Expr* expr) { // TODO: we may want other cases here... @@ -609,7 +609,7 @@ namespace Slang return false; } - RefPtr SemanticsVisitor::GetBaseExpr(RefPtr expr) + Expr* SemanticsVisitor::GetBaseExpr(Expr* expr) { if (auto memberExpr = as(expr)) { @@ -622,13 +622,13 @@ namespace Slang return nullptr; } - RefPtr SemanticsExprVisitor::visitBoolLiteralExpr(BoolLiteralExpr* expr) + Expr* SemanticsExprVisitor::visitBoolLiteralExpr(BoolLiteralExpr* expr) { expr->type = m_astBuilder->getBoolType(); return expr; } - RefPtr SemanticsExprVisitor::visitIntegerLiteralExpr(IntegerLiteralExpr* expr) + Expr* SemanticsExprVisitor::visitIntegerLiteralExpr(IntegerLiteralExpr* expr) { // The expression might already have a type, determined by its suffix. // It it doesn't, we will give it a default type. @@ -648,7 +648,7 @@ namespace Slang return expr; } - RefPtr SemanticsExprVisitor::visitFloatingPointLiteralExpr(FloatingPointLiteralExpr* expr) + Expr* SemanticsExprVisitor::visitFloatingPointLiteralExpr(FloatingPointLiteralExpr* expr) { if(!expr->type.type) { @@ -657,7 +657,7 @@ namespace Slang return expr; } - RefPtr SemanticsExprVisitor::visitStringLiteralExpr(StringLiteralExpr* expr) + Expr* SemanticsExprVisitor::visitStringLiteralExpr(StringLiteralExpr* expr) { expr->type = m_astBuilder->getStringType(); return expr; @@ -669,7 +669,7 @@ namespace Slang return m_astBuilder->create(expr->value); } - RefPtr SemanticsVisitor::TryConstantFoldExpr( + IntVal* SemanticsVisitor::TryConstantFoldExpr( InvokeExpr* invokeExpr) { // We need all the operands to the expression @@ -678,7 +678,7 @@ namespace Slang // // For right now we will look for calls to intrinsic functions, and then inspect // their names (this is bad and slow). - auto funcDeclRefExpr = invokeExpr->functionExpr.as(); + auto funcDeclRefExpr = as(invokeExpr->functionExpr); if (!funcDeclRefExpr) return nullptr; auto funcDeclRef = funcDeclRefExpr->declRef; @@ -701,13 +701,13 @@ namespace Slang return nullptr; // Before checking the operation name, let's look at the arguments - RefPtr argVals[kMaxArgs]; + IntVal* argVals[kMaxArgs]; IntegerLiteralValue constArgVals[kMaxArgs]; int argCount = 0; bool allConst = true; for (auto argExpr : invokeExpr->arguments) { - auto argVal = TryCheckIntegerConstantExpression(argExpr.Ptr()); + auto argVal = TryCheckIntegerConstantExpression(argExpr); if (!argVal) return nullptr; @@ -791,11 +791,11 @@ namespace Slang return nullptr; } - RefPtr result = m_astBuilder->create(resultValue); + IntVal* result = m_astBuilder->create(resultValue); return result; } - RefPtr SemanticsVisitor::TryConstantFoldExpr( + IntVal* SemanticsVisitor::TryConstantFoldExpr( Expr* expr) { // Unwrap any "identity" expressions @@ -835,7 +835,7 @@ namespace Slang // HLSL `static const` can be used as a constant expression if(auto initExpr = getInitExpr(m_astBuilder, varRef)) { - return TryConstantFoldExpr(initExpr.Ptr()); + return TryConstantFoldExpr(initExpr); } } } @@ -845,14 +845,14 @@ namespace Slang // The cases in an `enum` declaration can also be used as constant expressions, if(auto tagExpr = getTagExpr(m_astBuilder, enumRef)) { - return TryConstantFoldExpr(tagExpr.Ptr()); + return TryConstantFoldExpr(tagExpr); } } } if(auto castExpr = as(expr)) { - auto val = TryConstantFoldExpr(castExpr->arguments[0].Ptr()); + auto val = TryConstantFoldExpr(castExpr->arguments[0]); if(val) return val; } @@ -866,7 +866,7 @@ namespace Slang return nullptr; } - RefPtr SemanticsVisitor::TryCheckIntegerConstantExpression(Expr* exp) + IntVal* SemanticsVisitor::TryCheckIntegerConstantExpression(Expr* exp) { // Check if type is acceptable for an integer constant expression if(auto basicType = as(exp->type.type)) @@ -883,7 +883,7 @@ namespace Slang return TryConstantFoldExpr(exp); } - RefPtr SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr, DiagnosticSink* sink) + IntVal* SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr, DiagnosticSink* sink) { // No need to issue further errors if the expression didn't even type-check. if(IsErrorExpr(inExpr)) return nullptr; @@ -894,7 +894,7 @@ namespace Slang // No need to issue further errors if the type coercion failed. if(IsErrorExpr(expr)) return nullptr; - auto result = TryCheckIntegerConstantExpression(expr.Ptr()); + auto result = TryCheckIntegerConstantExpression(expr); if (!result && sink) { sink->diagnose(expr, Diagnostics::expectedIntegerConstantNotConstant); @@ -902,12 +902,12 @@ namespace Slang return result; } - RefPtr SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr) + IntVal* SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr) { return CheckIntegerConstantExpression(inExpr, getSink()); } - RefPtr SemanticsVisitor::CheckEnumConstantExpression(Expr* expr) + IntVal* SemanticsVisitor::CheckEnumConstantExpression(Expr* expr) { // No need to issue further errors if the expression didn't even type-check. if(IsErrorExpr(expr)) return nullptr; @@ -923,9 +923,9 @@ namespace Slang return result; } - RefPtr SemanticsVisitor::CheckSimpleSubscriptExpr( - RefPtr subscriptExpr, - RefPtr elementType) + Expr* SemanticsVisitor::CheckSimpleSubscriptExpr( + IndexExpr* subscriptExpr, + Type* elementType) { auto baseExpr = subscriptExpr->baseExpression; auto indexExpr = subscriptExpr->indexExpression; @@ -934,7 +934,7 @@ namespace Slang !indexExpr->type->equals(m_astBuilder->getUIntType())) { getSink()->diagnose(indexExpr, Diagnostics::subscriptIndexNonInteger); - return CreateErrorExpr(subscriptExpr.Ptr()); + return CreateErrorExpr(subscriptExpr); } subscriptExpr->type = QualType(elementType); @@ -945,12 +945,12 @@ namespace Slang return subscriptExpr; } - RefPtr SemanticsExprVisitor::visitIndexExpr(IndexExpr* subscriptExpr) + Expr* SemanticsExprVisitor::visitIndexExpr(IndexExpr* subscriptExpr) { auto baseExpr = subscriptExpr->baseExpression; baseExpr = CheckExpr(baseExpr); - RefPtr indexExpr = subscriptExpr->indexExpression; + Expr* indexExpr = subscriptExpr->indexExpression; if (indexExpr) { indexExpr = CheckExpr(indexExpr); @@ -972,10 +972,10 @@ namespace Slang // We are trying to "index" into a type, so we have an expression like `float[2]` // which should be interpreted as resolving to an array type. - RefPtr elementCount = nullptr; + IntVal* elementCount = nullptr; if (indexExpr) { - elementCount = CheckIntegerConstantExpression(indexExpr.Ptr()); + elementCount = CheckIntegerConstantExpression(indexExpr); } auto elementType = CoerceToUsableType(TypeExp(baseExpr, baseTypeType->type)); @@ -1033,17 +1033,17 @@ namespace Slang // Note: the expression may be an `OverloadedExpr`, in which // case the attempt to call it will trigger overload // resolution. - RefPtr subscriptFuncExpr = createLookupResultExpr( + Expr* subscriptFuncExpr = createLookupResultExpr( name, lookupResult, subscriptExpr->baseExpression, subscriptExpr->loc); - RefPtr subscriptCallExpr = m_astBuilder->create(); + InvokeExpr* subscriptCallExpr = m_astBuilder->create(); subscriptCallExpr->loc = subscriptExpr->loc; subscriptCallExpr->functionExpr = subscriptFuncExpr; // TODO(tfoley): This path can support multiple arguments easily subscriptCallExpr->arguments.add(subscriptExpr->indexExpression); - return CheckInvokeExprWithCheckedOperands(subscriptCallExpr.Ptr()); + return CheckInvokeExprWithCheckedOperands(subscriptCallExpr); } fail: @@ -1053,7 +1053,7 @@ namespace Slang } } - RefPtr SemanticsExprVisitor::visitParenExpr(ParenExpr* expr) + Expr* SemanticsExprVisitor::visitParenExpr(ParenExpr* expr) { auto base = expr->base; base = CheckTerm(base); @@ -1072,7 +1072,7 @@ namespace Slang // | e [ expr ] // // We will unwrap the `e.name` and `e[expr]` cases in a loop. - RefPtr e = expr; + Expr* e = expr; for(;;) { if(auto memberExpr = as(e)) @@ -1100,7 +1100,7 @@ namespace Slang } } - RefPtr SemanticsExprVisitor::visitAssignExpr(AssignExpr* expr) + Expr* SemanticsExprVisitor::visitAssignExpr(AssignExpr* expr) { expr->left = CheckExpr(expr->left); @@ -1130,7 +1130,7 @@ namespace Slang return expr; } - RefPtr SemanticsVisitor::CheckExpr(RefPtr expr) + Expr* SemanticsVisitor::CheckExpr(Expr* expr) { auto term = CheckTerm(expr); @@ -1140,10 +1140,10 @@ namespace Slang return term; } - RefPtr SemanticsVisitor::CheckInvokeExprWithCheckedOperands(InvokeExpr *expr) + Expr* SemanticsVisitor::CheckInvokeExprWithCheckedOperands(InvokeExpr *expr) { auto rs = ResolveInvoke(expr); - if (auto invoke = as(rs.Ptr())) + if (auto invoke = as(rs)) { // if this is still an invoke expression, test arguments passed to inout/out parameter are LValues if(auto funcType = as(invoke->functionExpr->type)) @@ -1212,7 +1212,7 @@ namespace Slang return rs; } - RefPtr SemanticsExprVisitor::visitInvokeExpr(InvokeExpr *expr) + Expr* SemanticsExprVisitor::visitInvokeExpr(InvokeExpr *expr) { // check the base expression first expr->functionExpr = CheckExpr(expr->functionExpr); @@ -1225,7 +1225,7 @@ namespace Slang return CheckInvokeExprWithCheckedOperands(expr); } - RefPtr SemanticsExprVisitor::visitVarExpr(VarExpr *expr) + Expr* SemanticsExprVisitor::visitVarExpr(VarExpr *expr) { // If we've already resolved this expression, don't try again. if (expr->declRef) @@ -1249,7 +1249,7 @@ namespace Slang return expr; } - RefPtr SemanticsExprVisitor::visitTypeCastExpr(TypeCastExpr * expr) + Expr* SemanticsExprVisitor::visitTypeCastExpr(TypeCastExpr * expr) { // Check the term we are applying first auto funcExpr = expr->functionExpr; @@ -1274,14 +1274,14 @@ namespace Slang // from a literal zero, with the semantics of default // initialization. // - if( auto declRefType = typeExp.type.as() ) + if( auto declRefType = as(typeExp.type) ) { - if(auto structDeclRef = declRefType->declRef.as()) + if(auto structDeclRef = as(declRefType->declRef)) { if( expr->arguments.getCount() == 1 ) { auto arg = expr->arguments[0]; - if( auto intLitArg = arg.as() ) + if( auto intLitArg = as(arg) ) { if(getIntegerLiteralValue(intLitArg->token) == 0) { @@ -1324,9 +1324,11 @@ namespace Slang // of explicit default initializers for `struct` fields to // make this a major concern (since they aren't supported in HLSL). // - RefPtr initListExpr = m_astBuilder->create(); + InitializerListExpr* initListExpr = m_astBuilder->create(); auto checkedInitListExpr = visitInitializerListExpr(initListExpr); - return coerce(typeExp.type, initListExpr); + + // TODO(JS): I changed this to checkInitListExpr form initListExpr + return coerce(typeExp.type, checkedInitListExpr); } } } @@ -1339,9 +1341,9 @@ namespace Slang return CheckInvokeExprWithCheckedOperands(expr); } - RefPtr SemanticsVisitor::MaybeDereference(RefPtr inExpr) + Expr* SemanticsVisitor::MaybeDereference(Expr* inExpr) { - RefPtr expr = inExpr; + Expr* expr = inExpr; for (;;) { auto baseType = expr->type; @@ -1363,13 +1365,13 @@ namespace Slang } } - RefPtr SemanticsVisitor::CheckMatrixSwizzleExpr( + Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr baseElementType, + Type* baseElementType, IntegerLiteralValue baseElementRowCount, IntegerLiteralValue baseElementColCount) { - RefPtr swizExpr = m_astBuilder->create(); + MatrixSwizzleExpr* swizExpr = m_astBuilder->create(); swizExpr->loc = memberRefExpr->loc; swizExpr->base = memberRefExpr->baseExpression; @@ -1503,11 +1505,11 @@ namespace Slang return swizExpr; } - RefPtr SemanticsVisitor::CheckMatrixSwizzleExpr( + Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr baseElementType, - RefPtr baseRowCount, - RefPtr baseColCount) + Type* baseElementType, + IntVal* baseRowCount, + IntVal* baseColCount) { if (auto constantRowCount = as(baseRowCount)) { @@ -1521,12 +1523,12 @@ namespace Slang return CreateErrorExpr(memberRefExpr); } - RefPtr SemanticsVisitor::CheckSwizzleExpr( + Expr* SemanticsVisitor::CheckSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr baseElementType, + Type* baseElementType, IntegerLiteralValue baseElementCount) { - RefPtr swizExpr = m_astBuilder->create(); + SwizzleExpr* swizExpr = m_astBuilder->create(); swizExpr->loc = memberRefExpr->loc; swizExpr->base = memberRefExpr->baseExpression; @@ -1615,10 +1617,10 @@ namespace Slang return swizExpr; } - RefPtr SemanticsVisitor::CheckSwizzleExpr( + Expr* SemanticsVisitor::CheckSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr baseElementType, - RefPtr baseElementCount) + Type* baseElementType, + IntVal* baseElementCount) { if (auto constantElementCount = as(baseElementCount)) { @@ -1631,7 +1633,7 @@ namespace Slang } } - RefPtr SemanticsVisitor::_lookupStaticMember(RefPtr expr, RefPtr baseExpression) + Expr* SemanticsVisitor::_lookupStaticMember(DeclRefExpr* expr, Expr* baseExpression) { auto& baseType = baseExpression->type; @@ -1779,7 +1781,7 @@ namespace Slang return lookupMemberResultFailure(expr, baseType); } - RefPtr SemanticsExprVisitor::visitStaticMemberExpr(StaticMemberExpr* expr) + Expr* SemanticsExprVisitor::visitStaticMemberExpr(StaticMemberExpr* expr) { expr->baseExpression = CheckExpr(expr->baseExpression); @@ -1798,7 +1800,7 @@ namespace Slang return _lookupStaticMember(expr, expr->baseExpression); } - RefPtr SemanticsVisitor::lookupMemberResultFailure( + Expr* SemanticsVisitor::lookupMemberResultFailure( DeclRefExpr* expr, QualType const& baseType) { @@ -1810,7 +1812,7 @@ namespace Slang return expr; } - RefPtr SemanticsExprVisitor::visitMemberExpr(MemberExpr * expr) + Expr* SemanticsExprVisitor::visitMemberExpr(MemberExpr * expr) { expr->baseExpression = CheckExpr(expr->baseExpression); @@ -1897,7 +1899,7 @@ namespace Slang } } - RefPtr SemanticsExprVisitor::visitInitializerListExpr(InitializerListExpr* expr) + Expr* SemanticsExprVisitor::visitInitializerListExpr(InitializerListExpr* expr) { // When faced with an initializer list, we first just check the sub-expressions blindly. // Actually making them conform to a desired type will wait for when we know the desired @@ -1915,7 +1917,7 @@ namespace Slang // Perform semantic checking of an object-oriented `this` // expression. - RefPtr SemanticsExprVisitor::visitThisExpr(ThisExpr* expr) + Expr* SemanticsExprVisitor::visitThisExpr(ThisExpr* expr) { // A `this` expression will default to immutable. expr->type.isLeftValue = false; @@ -1979,7 +1981,7 @@ namespace Slang return CreateErrorExpr(expr); } - RefPtr SemanticsExprVisitor::visitThisTypeExpr(ThisTypeExpr* expr) + Expr* SemanticsExprVisitor::visitThisTypeExpr(ThisTypeExpr* expr) { auto scope = expr->scope; while (scope) diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index c316dd820..b6e0264be 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -16,7 +16,7 @@ namespace Slang bool isEffectivelyStatic( Decl* decl); - RefPtr checkProperType( + Type* checkProperType( Linkage* linkage, TypeExp typeExp, DiagnosticSink* sink); @@ -129,7 +129,7 @@ namespace Slang // Decl* funcDecl = overloadedBase->lookupResult2.item.declRef.decl; if (auto genDecl = as(funcDecl)) - funcDecl = genDecl->inner.Ptr(); + funcDecl = genDecl->inner; // Reject definitions that have the wrong fixity. // @@ -175,7 +175,7 @@ namespace Slang LookupResultItem item; // The type of the result expression if this candidate is selected - RefPtr resultType; + Type* resultType = nullptr; // A system for tracking constraints introduced on generic parameters // ConstraintSystem constraintSystem; @@ -187,7 +187,7 @@ namespace Slang // When required, a candidate can store a pre-checked list of // arguments so that we don't have to repeat work across checking // phases. Currently this is only needed for generics. - RefPtr subst; + Substitutions* subst = nullptr; }; struct TypeCheckingCache @@ -268,7 +268,7 @@ namespace Slang /// struct OuterStmtInfo { - Stmt* stmt; + Stmt* stmt = nullptr; OuterStmtInfo* next; }; @@ -276,13 +276,13 @@ namespace Slang // Translate Types - RefPtr TranslateTypeNodeImpl(const RefPtr & node); - RefPtr ExtractTypeFromTypeRepr(const RefPtr& typeRepr); - RefPtr TranslateTypeNode(const RefPtr & node); + Expr* TranslateTypeNodeImpl(Expr* node); + Type* ExtractTypeFromTypeRepr(Expr* typeRepr); + Type* TranslateTypeNode(Expr* node); TypeExp TranslateTypeNodeForced(TypeExp const& typeExp); TypeExp TranslateTypeNode(TypeExp const& typeExp); - RefPtr getExprDeclRefType(Expr * expr); + DeclRefType* getExprDeclRefType(Expr * expr); /// Is `decl` usable as a static member? bool isDeclUsableAsStaticMember( @@ -298,7 +298,7 @@ namespace Slang /// the temporary, and the computation created by `func`. /// template - RefPtr moveTemp(RefPtr const& expr, F const& func); + Expr* moveTemp(Expr* const& expr, F const& func); /// Execute `func` on a variable with the value of `expr`. /// @@ -307,7 +307,7 @@ namespace Slang /// a new variable to hold `expr`, using `moveTemp()`. /// template - RefPtr maybeMoveTemp(RefPtr const& expr, F const& func); + Expr* maybeMoveTemp(Expr* const& expr, F const& func); /// Return an expression that represents "opening" the existential `expr`. /// @@ -327,8 +327,8 @@ namespace Slang /// returns an expression that logically corresponds to `v`: an expression /// of type `X`, where the type carries the knowledge that `X` implements `IMover`. /// - RefPtr openExistential( - RefPtr expr, + Expr* openExistential( + Expr* expr, DeclRef interfaceDeclRef); /// If `expr` has existential type, then open it. @@ -339,26 +339,26 @@ namespace Slang /// See `openExistential` for a discussion of what "opening" an /// existential-type value means. /// - RefPtr maybeOpenExistential(RefPtr expr); + Expr* maybeOpenExistential(Expr* expr); - RefPtr ConstructDeclRefExpr( + Expr* ConstructDeclRefExpr( DeclRef declRef, - RefPtr baseExpr, + Expr* baseExpr, SourceLoc loc); - RefPtr ConstructDerefExpr( - RefPtr base, + Expr* ConstructDerefExpr( + Expr* base, SourceLoc loc); - RefPtr ConstructLookupResultExpr( + Expr* ConstructLookupResultExpr( LookupResultItem const& item, - RefPtr baseExpr, + Expr* baseExpr, SourceLoc loc); - RefPtr createLookupResultExpr( + Expr* createLookupResultExpr( Name* name, LookupResult const& lookupResult, - RefPtr baseExpr, + Expr* baseExpr, SourceLoc loc); /// Attempt to "resolve" an overloaded `LookupResult` to only include the "best" results @@ -373,38 +373,38 @@ namespace Slang /// appropriate "ambiguous reference" error will be reported, and an error expression will be returned. /// Otherwise, the original expression is returned if resolution fails. /// - RefPtr maybeResolveOverloadedExpr(RefPtr expr, LookupMask mask, DiagnosticSink* diagSink); + Expr* maybeResolveOverloadedExpr(Expr* expr, LookupMask mask, DiagnosticSink* diagSink); /// Attempt to resolve `overloadedExpr` into an expression that refers to a single declaration/value. /// /// Equivalent to `maybeResolveOverloadedExpr` with `diagSink` bound to the sink for the `SemanticsVisitor`. - RefPtr resolveOverloadedExpr(RefPtr overloadedExpr, LookupMask mask); + Expr* resolveOverloadedExpr(OverloadedExpr* overloadedExpr, LookupMask mask); /// Worker reoutine for `maybeResolveOverloadedExpr` and `resolveOverloadedExpr`. - RefPtr _resolveOverloadedExprImpl(RefPtr overloadedExpr, LookupMask mask, DiagnosticSink* diagSink); + Expr* _resolveOverloadedExprImpl(OverloadedExpr* overloadedExpr, LookupMask mask, DiagnosticSink* diagSink); void diagnoseAmbiguousReference(OverloadedExpr* overloadedExpr, LookupResult const& lookupResult); void diagnoseAmbiguousReference(Expr* overloadedExpr); - RefPtr ExpectATypeRepr(RefPtr expr); + Expr* ExpectATypeRepr(Expr* expr); - RefPtr ExpectAType(RefPtr expr); + Type* ExpectAType(Expr* expr); - RefPtr ExtractGenericArgType(RefPtr exp); + Type* ExtractGenericArgType(Expr* exp); - RefPtr ExtractGenericArgInteger(RefPtr exp, DiagnosticSink* sink); - RefPtr ExtractGenericArgInteger(RefPtr exp); + IntVal* ExtractGenericArgInteger(Expr* exp, DiagnosticSink* sink); + IntVal* ExtractGenericArgInteger(Expr* exp); - RefPtr ExtractGenericArgVal(RefPtr exp); + Val* ExtractGenericArgVal(Expr* exp); // Construct a type representing the instantiation of // the given generic declaration for the given arguments. // The arguments should already be checked against // the declaration. - RefPtr InstantiateGenericType( + Type* InstantiateGenericType( DeclRef genericDeclRef, - List> const& args); + List const& args); // These routines are bottlenecks for semantic checking, // so that we can add some quality-of-life features for users @@ -459,7 +459,7 @@ namespace Slang // given type `Texture2D` will actually have type `Texture2D`). bool CoerceToProperTypeImpl( TypeExp const& typeExp, - RefPtr* outProperType, + Type** outProperType, DiagnosticSink* diagSink); TypeExp CoerceToProperType(TypeExp const& typeExp); @@ -482,20 +482,20 @@ namespace Slang // Check a type, and coerce it to be usable TypeExp CheckUsableType(TypeExp typeExp); - RefPtr CheckTerm(RefPtr term); + Expr* CheckTerm(Expr* term); - RefPtr CreateErrorExpr(Expr* expr); + Expr* CreateErrorExpr(Expr* expr); - bool IsErrorExpr(RefPtr expr); + bool IsErrorExpr(Expr* expr); // Capture the "base" expression in case this is a member reference - RefPtr GetBaseExpr(RefPtr expr); + Expr* GetBaseExpr(Expr* expr); public: bool ValuesAreEqual( - RefPtr left, - RefPtr right); + IntVal* left, + IntVal* right); // Compute the cost of using a particular declaration to // perform implicit type conversion. @@ -503,12 +503,12 @@ namespace Slang Decl* decl); bool isEffectivelyScalarForInitializerLists( - RefPtr type); + Type* type); /// Should the provided expression (from an initializer list) be used directly to initialize `toType`? bool shouldUseInitializerDirectly( - RefPtr toType, - RefPtr fromExpr); + Type* toType, + Expr* fromExpr); /// Read a value from an initializer list expression. /// @@ -534,9 +534,9 @@ namespace Slang /// then a suitable diagnostic will be emitted. /// bool _readValueFromInitializerList( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr, + Type* toType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr, UInt &ioInitArgIndex); /// Read an aggregate value from an initializer list expression. @@ -559,9 +559,9 @@ namespace Slang /// then a suitable diagnostic will be emitted. /// bool _readAggregateValueFromInitializerList( - RefPtr inToType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr, + Type* inToType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr, UInt &ioArgIndex); /// Coerce an initializer-list expression to a specific type. @@ -584,15 +584,15 @@ namespace Slang /// then a suitable diagnostic will be emitted. /// bool _coerceInitializerList( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromInitializerListExpr); + Type* toType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr); /// Report that implicit type coercion is not possible. bool _failedCoercion( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromExpr); + Type* toType, + Expr** outToExpr, + Expr* fromExpr); /// Central engine for implementing implicit coercion logic /// @@ -615,10 +615,10 @@ namespace Slang /// should be emitted on failure. /// bool _coerce( - RefPtr toType, - RefPtr* outToExpr, - RefPtr fromType, - RefPtr fromExpr, + Type* toType, + Expr** outToExpr, + Type* fromType, + Expr* fromExpr, ConversionCost* outCost); /// Check whether implicit type coercion from `fromType` to `toType` is possible. @@ -629,15 +629,15 @@ namespace Slang /// If conversion is not possible, returns `false`. /// bool canCoerce( - RefPtr toType, - RefPtr fromType, + Type* toType, + Type* fromType, ConversionCost* outCost = 0); - RefPtr createImplicitCastExpr(); + TypeCastExpr* createImplicitCastExpr(); - RefPtr CreateImplicitCastExpr( - RefPtr toType, - RefPtr fromExpr); + Expr* CreateImplicitCastExpr( + Type* toType, + Expr* fromExpr); /// Create an "up-cast" from a value to an interface type /// @@ -645,31 +645,31 @@ namespace Slang /// which packages up the value, its type, and the witness /// of its conformance to the interface. /// - RefPtr createCastToSuperTypeExpr( - RefPtr toType, - RefPtr fromExpr, - RefPtr witness); + Expr* createCastToInterfaceExpr( + Type* toType, + Expr* fromExpr, + Val* witness); /// Implicitly coerce `fromExpr` to `toType` and diagnose errors if it isn't possible - RefPtr coerce( - RefPtr toType, - RefPtr fromExpr); + Expr* coerce( + Type* toType, + Expr* fromExpr); // Fill in default substitutions for the 'subtype' part of a type constraint decl void CheckConstraintSubType(TypeExp& typeExp); void checkGenericDeclHeader(GenericDecl* genericDecl); - RefPtr checkConstantIntVal( - RefPtr expr); + ConstantIntVal* checkConstantIntVal( + Expr* expr); - RefPtr checkConstantEnumVal( - RefPtr expr); + ConstantIntVal* checkConstantEnumVal( + Expr* expr); // Check an expression, coerce it to the `String` type, and then // ensure that it has a literal (not just compile-time constant) value. bool checkLiteralStringVal( - RefPtr expr, + Expr* expr, String* outVal); void visitModifier(Modifier*); @@ -679,16 +679,16 @@ namespace Slang bool hasIntArgs(Attribute* attr, int numArgs); bool hasStringArgs(Attribute* attr, int numArgs); - bool getAttributeTargetSyntaxClasses(SyntaxClass & cls, uint32_t typeFlags); + bool getAttributeTargetSyntaxClasses(SyntaxClass & cls, uint32_t typeFlags); - bool validateAttribute(RefPtr attr, AttributeDecl* attribClassDecl); + bool validateAttribute(Attribute* attr, AttributeDecl* attribClassDecl); - RefPtr checkAttribute( + AttributeBase* checkAttribute( UncheckedAttribute* uncheckedAttr, ModifiableSyntaxNode* attrTarget); - RefPtr checkModifier( - RefPtr m, + Modifier* checkModifier( + Modifier* m, ModifiableSyntaxNode* syntaxNode); void checkModifiers(ModifiableSyntaxNode* syntaxNode); @@ -704,7 +704,7 @@ namespace Slang RefPtr witnessTable); bool doesTypeSatisfyAssociatedTypeRequirement( - RefPtr satisfyingType, + Type* satisfyingType, DeclRef requiredAssociatedTypeDeclRef, RefPtr witnessTable); @@ -795,7 +795,7 @@ namespace Slang bool doGenericSignaturesMatch( GenericDecl* left, GenericDecl* right, - RefPtr* outSubstRightToLeft); + GenericSubstitution** outSubstRightToLeft); // Check if two functions have the same signature for the purposes // of overload resolution. @@ -803,18 +803,18 @@ namespace Slang DeclRef fst, DeclRef snd); - RefPtr createDummySubstitutions( + GenericSubstitution* createDummySubstitutions( GenericDecl* genericDecl); Result checkRedeclaration(Decl* newDecl, Decl* oldDecl); Result checkFuncRedeclaration(FuncDecl* newDecl, FuncDecl* oldDecl); void checkForRedeclaration(Decl* decl); - RefPtr checkPredicateExpr(Expr* expr); + Expr* checkPredicateExpr(Expr* expr); - RefPtr checkExpressionAndExpectIntegerConstant(RefPtr expr, RefPtr* outIntVal); + Expr* checkExpressionAndExpectIntegerConstant(Expr* expr, IntVal** outIntVal); - IntegerLiteralValue GetMinBound(RefPtr val); + IntegerLiteralValue GetMinBound(IntVal* val); void maybeInferArraySizeForVariable(VarDeclBase* varDecl); @@ -827,26 +827,26 @@ namespace Slang return getNamePool()->getName(text); } - RefPtr TryConstantFoldExpr( + IntVal* TryConstantFoldExpr( InvokeExpr* invokeExpr); - RefPtr TryConstantFoldExpr( + IntVal* TryConstantFoldExpr( Expr* expr); // Try to check an integer constant expression, either returning the value, // or NULL if the expression isn't recognized as a constant. - RefPtr TryCheckIntegerConstantExpression(Expr* exp); + IntVal* TryCheckIntegerConstantExpression(Expr* exp); // Enforce that an expression resolves to an integer constant, and get its value - RefPtr CheckIntegerConstantExpression(Expr* inExpr); - RefPtr CheckIntegerConstantExpression(Expr* inExpr, DiagnosticSink* sink); + IntVal* CheckIntegerConstantExpression(Expr* inExpr); + IntVal* CheckIntegerConstantExpression(Expr* inExpr, DiagnosticSink* sink); - RefPtr CheckEnumConstantExpression(Expr* expr); + IntVal* CheckEnumConstantExpression(Expr* expr); - RefPtr CheckSimpleSubscriptExpr( - RefPtr subscriptExpr, - RefPtr elementType); + Expr* CheckSimpleSubscriptExpr( + IndexExpr* subscriptExpr, + Type* elementType); // The way that we have designed out type system, pretyt much *every* // type is a reference to some declaration in the standard library. @@ -858,9 +858,9 @@ namespace Slang // This function is used to construct a `vector` type // programmatically, so that it will work just like a type of // that form constructed by the user. - RefPtr createVectorType( - RefPtr elementType, - RefPtr elementCount); + VectorExpressionType* createVectorType( + Type* elementType, + IntVal* elementCount); // @@ -872,21 +872,21 @@ namespace Slang // Figure out what type an initializer/constructor declaration // is supposed to return. In most cases this is just the type // declaration that its declaration is nested inside. - RefPtr findResultTypeForConstructorDecl(ConstructorDecl* decl); + Type* findResultTypeForConstructorDecl(ConstructorDecl* decl); /// Determine what type `This` should refer to in the context of the given parent `decl`. - RefPtr calcThisType(DeclRef decl); + Type* calcThisType(DeclRef decl); /// Determine what type `This` should refer to in an extension of `type`. - RefPtr calcThisType(Type* type); + Type* calcThisType(Type* type); // struct Constraint { - Decl* decl; // the declaration of the thing being constraints - RefPtr val; // the value to which we are constraining it + Decl* decl = nullptr; // the declaration of the thing being constraints + Val* val = nullptr; // the value to which we are constraining it bool satisfied = false; // Has this constraint been met? }; @@ -899,42 +899,43 @@ namespace Slang // The generic declaration whose parameters we // are trying to solve for. - RefPtr genericDecl; + GenericDecl* genericDecl = nullptr; // Constraints we have accumulated, which constrain // the possible arguments for those parameters. List constraints; }; - RefPtr TryJoinVectorAndScalarType( - RefPtr vectorType, - RefPtr scalarType); + Type* TryJoinVectorAndScalarType( + VectorExpressionType* vectorType, + BasicExpressionType* scalarType); struct TypeWitnessBreadcrumb { TypeWitnessBreadcrumb* prev; - RefPtr sub; - RefPtr sup; + Type* sub = nullptr; + Type* sup = nullptr; DeclRef declRef; }; // Create a subtype witness based on the declared relationship // found in a single breadcrumb - RefPtr createSimpleSubtypeWitness( + DeclaredSubtypeWitness* createSimpleSubtypeWitness( TypeWitnessBreadcrumb* breadcrumb); - /// Create a withness that `subType` is a sub-type of `superTypeDeclRef`. - /// - /// The `inBreadcrumbs` parameter represents a linked list of steps - /// in the process that validated the sub-type relationship, which - /// will be used to inform the construction of the witness. - /// - RefPtr createTypeWitness( - RefPtr subType, - DeclRef superTypeDeclRef, - TypeWitnessBreadcrumb* inBreadcrumbs); + /// Create a withness that `subType` is a sub-type of `superTypeDeclRef`. + /// + /// The `inBreadcrumbs` parameter represents a linked list of steps + /// in the process that validated the sub-type relationship, which + /// will be used to inform the construction of the witness. + /// + Val* createTypeWitness( + Type* subType, + DeclRef superTypeDeclRef, + TypeWitnessBreadcrumb* inBreadcrumbs); + /// Is the given interface one that a tagged-union type can conform to? /// /// If a tagged union type `__TaggedUnion(A,B)` is going to be @@ -970,23 +971,23 @@ namespace Slang /// used to construct a witness for `A : C` from the `A : B` and `B : C` witnesses. /// bool _isDeclaredSubtype( - RefPtr originalSubType, - RefPtr subType, + Type* originalSubType, + Type* subType, DeclRef superTypeDeclRef, - RefPtr* outWitness, + Val** outWitness, TypeWitnessBreadcrumb* inBreadcrumbs); /// Check whether `subType` is a sub-type of `superTypeDeclRef`. bool isDeclaredSubtype( - RefPtr subType, + Type* subType, DeclRef superTypeDeclRef); /// Check whether `subType` is a sub-type of `superTypeDeclRef`, /// and return a witness to the sub-type relationship if it holds /// (return null otherwise). /// - RefPtr tryGetSubtypeWitness( - RefPtr subType, + Val* tryGetSubtypeWitness( + Type* subType, DeclRef superTypeDeclRef); /// Check whether `type` conforms to `interfaceDeclRef`, @@ -995,23 +996,28 @@ namespace Slang /// /// This function is equivalent to `tryGetSubtypeWitness()`. /// - RefPtr tryGetInterfaceConformanceWitness( - RefPtr type, + Val* tryGetInterfaceConformanceWitness( + Type* type, DeclRef interfaceDeclRef); + Expr* createCastToSuperTypeExpr( + Type* toType, + Expr* fromExpr, + Val* witness); + /// Does there exist an implicit conversion from `fromType` to `toType`? bool canConvertImplicitly( - RefPtr toType, - RefPtr fromType); + Type* toType, + Type* fromType); - RefPtr TryJoinTypeWithInterface( - RefPtr type, + Type* TryJoinTypeWithInterface( + Type* type, DeclRef interfaceDeclRef); // Try to compute the "join" between two types - RefPtr TryJoinTypes( - RefPtr left, - RefPtr right); + Type* TryJoinTypes( + Type* left, + Type* right); // Try to solve a system of generic constraints. // The `system` argument provides the constraints. @@ -1042,19 +1048,19 @@ namespace Slang SourceLoc loc; // The original expression (if any) that triggered things - RefPtr originalExpr; + Expr* originalExpr = nullptr; // Source location of the "function" part of the expression, if any SourceLoc funcLoc; // The original arguments to the call Index argCount = 0; - RefPtr* args = nullptr; - RefPtr* argTypes = nullptr; + Expr** args = nullptr; + Type** argTypes = nullptr; Index getArgCount() { return argCount; } - RefPtr& getArg(Index index) { return args[index]; } - RefPtr& getArgType(Index index) + Expr*& getArg(Index index) { return args[index]; } + Type*& getArgType(Index index) { if(argTypes) return argTypes[index]; @@ -1064,7 +1070,7 @@ namespace Slang bool disallowNestedConversions = false; - RefPtr baseExpr; + Expr* baseExpr = nullptr; // Are we still trying out candidates, or are we // checking the chosen one for real? @@ -1113,14 +1119,14 @@ namespace Slang // Create a witness that attests to the fact that `type` // is equal to itself. - RefPtr createTypeEqualityWitness( + Val* createTypeEqualityWitness( Type* type); // If `sub` is a subtype of `sup`, then return a value that // can serve as a "witness" for that fact. - RefPtr tryGetSubtypeWitness( - RefPtr sub, - RefPtr sup); + Val* tryGetSubtypeWitness( + Type* sub, + Type* sup); // In the case where we are explicitly applying a generic // to arguments (e.g., `G`) check that the constraints @@ -1141,10 +1147,10 @@ namespace Slang OverloadCandidate& candidate); // Create the representation of a given generic applied to some arguments - RefPtr createGenericDeclRef( - RefPtr baseExpr, - RefPtr originalExpr, - RefPtr subst); + Expr* createGenericDeclRef( + Expr* baseExpr, + Expr* originalExpr, + GenericSubstitution* subst); // Take an overload candidate that previously got through // `TryCheckOverloadCandidate` above, and try to finish @@ -1152,7 +1158,7 @@ namespace Slang // // If the candidate isn't actually applicable, this is // where we'd start reporting the issue(s). - RefPtr CompleteOverloadCandidate( + Expr* CompleteOverloadCandidate( OverloadResolveContext& context, OverloadCandidate& candidate); @@ -1191,17 +1197,17 @@ namespace Slang OverloadResolveContext& context); void AddFuncOverloadCandidate( - RefPtr /*funcType*/, + FuncType* /*funcType*/, OverloadResolveContext& /*context*/); // Add a candidate callee for overload resolution, based on // calling a particular `ConstructorDecl`. void AddCtorOverloadCandidate( LookupResultItem typeItem, - RefPtr type, + Type* type, DeclRef ctorDeclRef, OverloadResolveContext& context, - RefPtr resultType); + Type* resultType); // If the given declaration has generic parameters, then // return the corresponding `GenericDecl` that holds the @@ -1211,48 +1217,48 @@ namespace Slang // Try to find a unification for two values bool TryUnifyVals( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd); + Val* fst, + Val* snd); bool tryUnifySubstitutions( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd); + Substitutions* fst, + Substitutions* snd); bool tryUnifyGenericSubstitutions( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd); + GenericSubstitution* fst, + GenericSubstitution* snd); bool TryUnifyTypeParam( ConstraintSystem& constraints, - RefPtr typeParamDecl, - RefPtr type); + GenericTypeParamDecl* typeParamDecl, + Type* type); bool TryUnifyIntParam( ConstraintSystem& constraints, - RefPtr paramDecl, - RefPtr val); + GenericValueParamDecl* paramDecl, + IntVal* val); bool TryUnifyIntParam( ConstraintSystem& constraints, DeclRef const& varRef, - RefPtr val); + IntVal* val); bool TryUnifyTypesByStructuralMatch( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd); + Type* fst, + Type* snd); bool TryUnifyTypes( ConstraintSystem& constraints, - RefPtr fst, - RefPtr snd); + Type* fst, + Type* snd); // Is the candidate extension declaration actually applicable to the given type DeclRef ApplyExtensionToType( ExtensionDecl* extDecl, - RefPtr type); + Type* type); // Take a generic declaration and try to specialize its parameters // so that the resulting inner declaration can be applicable in @@ -1262,7 +1268,7 @@ namespace Slang OverloadResolveContext& context); void AddTypeOverloadCandidates( - RefPtr type, + Type* type, OverloadResolveContext& context); void AddDeclRefOverloadCandidates( @@ -1274,12 +1280,12 @@ namespace Slang OverloadResolveContext& context); void AddOverloadCandidates( - RefPtr funcExpr, + Expr* funcExpr, OverloadResolveContext& context); - void formatType(StringBuilder& sb, RefPtr type); + void formatType(StringBuilder& sb, Type* type); - void formatVal(StringBuilder& sb, RefPtr val); + void formatVal(StringBuilder& sb, Val* val); void formatDeclPath(StringBuilder& sb, DeclRef declRef); @@ -1296,22 +1302,22 @@ namespace Slang String getCallSignatureString( OverloadResolveContext& context); - RefPtr ResolveInvoke(InvokeExpr * expr); + Expr* ResolveInvoke(InvokeExpr * expr); void AddGenericOverloadCandidate( LookupResultItem baseItem, OverloadResolveContext& context); void AddGenericOverloadCandidates( - RefPtr baseExpr, + Expr* baseExpr, OverloadResolveContext& context); /// Check a generic application where the operands have already been checked. - RefPtr checkGenericAppWithCheckedArgs(GenericAppExpr* genericAppExpr); + Expr* checkGenericAppWithCheckedArgs(GenericAppExpr* genericAppExpr); - RefPtr CheckExpr(RefPtr expr); + Expr* CheckExpr(Expr* expr); - RefPtr CheckInvokeExprWithCheckedOperands(InvokeExpr *expr); + Expr* CheckInvokeExprWithCheckedOperands(InvokeExpr *expr); // Get the type to use when referencing a declaration QualType GetTypeForDeclRef(DeclRef declRef, SourceLoc loc); @@ -1320,38 +1326,38 @@ namespace Slang // // - RefPtr MaybeDereference(RefPtr inExpr); + Expr* MaybeDereference(Expr* inExpr); - RefPtr CheckMatrixSwizzleExpr( + Expr* CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr baseElementType, + Type* baseElementType, IntegerLiteralValue baseElementRowCount, IntegerLiteralValue baseElementColCount); - RefPtr CheckMatrixSwizzleExpr( + Expr* CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr baseElementType, - RefPtr baseElementRowCount, - RefPtr baseElementColCount); + Type* baseElementType, + IntVal* baseElementRowCount, + IntVal* baseElementColCount); - RefPtr CheckSwizzleExpr( + Expr* CheckSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr baseElementType, + Type* baseElementType, IntegerLiteralValue baseElementCount); - RefPtr CheckSwizzleExpr( + Expr* CheckSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr baseElementType, - RefPtr baseElementCount); + Type* baseElementType, + IntVal* baseElementCount); // Look up a static member // @param expr Can be StaticMemberExpr or MemberExpr // @param baseExpression Is the underlying type expression determined from resolving expr - RefPtr _lookupStaticMember(RefPtr expr, RefPtr baseExpression); + Expr* _lookupStaticMember(DeclRefExpr* expr, Expr* baseExpression); - RefPtr visitStaticMemberExpr(StaticMemberExpr* expr); + Expr* visitStaticMemberExpr(StaticMemberExpr* expr); - RefPtr lookupMemberResultFailure( + Expr* lookupMemberResultFailure( DeclRefExpr* expr, QualType const& baseType); @@ -1365,35 +1371,35 @@ namespace Slang struct SemanticsExprVisitor : public SemanticsVisitor - , ExprVisitor> + , ExprVisitor { public: SemanticsExprVisitor(SharedSemanticsContext* shared) : SemanticsVisitor(shared) {} - RefPtr visitBoolLiteralExpr(BoolLiteralExpr* expr); - RefPtr visitIntegerLiteralExpr(IntegerLiteralExpr* expr); - RefPtr visitFloatingPointLiteralExpr(FloatingPointLiteralExpr* expr); - RefPtr visitStringLiteralExpr(StringLiteralExpr* expr); + Expr* visitBoolLiteralExpr(BoolLiteralExpr* expr); + Expr* visitIntegerLiteralExpr(IntegerLiteralExpr* expr); + Expr* visitFloatingPointLiteralExpr(FloatingPointLiteralExpr* expr); + Expr* visitStringLiteralExpr(StringLiteralExpr* expr); - RefPtr visitIndexExpr(IndexExpr* subscriptExpr); + Expr* visitIndexExpr(IndexExpr* subscriptExpr); - RefPtr visitParenExpr(ParenExpr* expr); + Expr* visitParenExpr(ParenExpr* expr); - RefPtr visitAssignExpr(AssignExpr* expr); + Expr* visitAssignExpr(AssignExpr* expr); - RefPtr visitGenericAppExpr(GenericAppExpr* genericAppExpr); + Expr* visitGenericAppExpr(GenericAppExpr* genericAppExpr); - RefPtr visitSharedTypeExpr(SharedTypeExpr* expr); + Expr* visitSharedTypeExpr(SharedTypeExpr* expr); - RefPtr visitTaggedUnionTypeExpr(TaggedUnionTypeExpr* expr); + Expr* visitTaggedUnionTypeExpr(TaggedUnionTypeExpr* expr); - RefPtr visitInvokeExpr(InvokeExpr *expr); + Expr* visitInvokeExpr(InvokeExpr *expr); - RefPtr visitVarExpr(VarExpr *expr); + Expr* visitVarExpr(VarExpr *expr); - RefPtr visitTypeCastExpr(TypeCastExpr * expr); + Expr* visitTypeCastExpr(TypeCastExpr * expr); // // Some syntax nodes should not occur in the concrete input syntax, @@ -1402,7 +1408,7 @@ namespace Slang // #define CASE(NAME) \ - RefPtr visit##NAME(NAME* expr) \ + Expr* visit##NAME(NAME* expr) \ { \ SLANG_DIAGNOSE_UNEXPECTED(getSink(), expr, \ "should not appear in input syntax"); \ @@ -1421,14 +1427,14 @@ namespace Slang #undef CASE - RefPtr visitStaticMemberExpr(StaticMemberExpr* expr); + Expr* visitStaticMemberExpr(StaticMemberExpr* expr); - RefPtr visitMemberExpr(MemberExpr * expr); + Expr* visitMemberExpr(MemberExpr * expr); - RefPtr visitInitializerListExpr(InitializerListExpr* expr); + Expr* visitInitializerListExpr(InitializerListExpr* expr); - RefPtr visitThisExpr(ThisExpr* expr); - RefPtr visitThisTypeExpr(ThisTypeExpr* expr); + Expr* visitThisExpr(ThisExpr* expr); + Expr* visitThisTypeExpr(ThisTypeExpr* expr); }; struct SemanticsStmtVisitor diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp index 75a75ad69..d8877b9d1 100644 --- a/source/slang/slang-check-modifier.cpp +++ b/source/slang/slang-check-modifier.cpp @@ -11,13 +11,13 @@ namespace Slang { - RefPtr SemanticsVisitor::checkConstantIntVal( - RefPtr expr) + ConstantIntVal* SemanticsVisitor::checkConstantIntVal( + Expr* expr) { // First type-check the expression as normal expr = CheckExpr(expr); - auto intVal = CheckIntegerConstantExpression(expr.Ptr()); + auto intVal = CheckIntegerConstantExpression(expr); if(!intVal) return nullptr; @@ -30,13 +30,13 @@ namespace Slang return constIntVal; } - RefPtr SemanticsVisitor::checkConstantEnumVal( - RefPtr expr) + ConstantIntVal* SemanticsVisitor::checkConstantEnumVal( + Expr* expr) { // First type-check the expression as normal expr = CheckExpr(expr); - auto intVal = CheckEnumConstantExpression(expr.Ptr()); + auto intVal = CheckEnumConstantExpression(expr); if(!intVal) return nullptr; @@ -52,7 +52,7 @@ namespace Slang // Check an expression, coerce it to the `String` type, and then // ensure that it has a literal (not just compile-time constant) value. bool SemanticsVisitor::checkLiteralStringVal( - RefPtr expr, + Expr* expr, String* outVal) { // TODO: This should actually perform semantic checking, etc., @@ -138,12 +138,12 @@ namespace Slang // We will now synthesize a new `AttributeDecl` to mirror // what was declared on the `struct` type. // - RefPtr attrDecl = m_astBuilder->create(); + AttributeDecl* attrDecl = m_astBuilder->create(); attrDecl->nameAndLoc.name = attributeName; attrDecl->nameAndLoc.loc = structDecl->nameAndLoc.loc; attrDecl->loc = structDecl->loc; - RefPtr targetModifier = m_astBuilder->create(); + AttributeTargetModifier* targetModifier = m_astBuilder->create(); targetModifier->syntaxClass = attrUsageAttr->targetSyntaxClass; targetModifier->loc = attrUsageAttr->loc; addModifier(attrDecl, targetModifier); @@ -167,7 +167,7 @@ namespace Slang { ensureDecl(varMember, DeclCheckState::CanUseTypeOfValueDecl); - RefPtr paramDecl = m_astBuilder->create(); + ParamDecl* paramDecl = m_astBuilder->create(); paramDecl->nameAndLoc = member->nameAndLoc; paramDecl->type = varMember->type; paramDecl->loc = member->loc; @@ -230,7 +230,7 @@ namespace Slang return true; } - bool SemanticsVisitor::getAttributeTargetSyntaxClasses(SyntaxClass & cls, uint32_t typeFlags) + bool SemanticsVisitor::getAttributeTargetSyntaxClasses(SyntaxClass & cls, uint32_t typeFlags) { if (typeFlags == (int)UserDefinedAttributeTargets::Struct) { @@ -250,7 +250,7 @@ namespace Slang return false; } - bool SemanticsVisitor::validateAttribute(RefPtr attr, AttributeDecl* attribClassDecl) + bool SemanticsVisitor::validateAttribute(Attribute* attr, AttributeDecl* attribClassDecl) { if(auto numThreadsAttr = as(attr)) { @@ -401,7 +401,7 @@ namespace Slang uint32_t targetClassId = (uint32_t)UserDefinedAttributeTargets::None; if (attr->args.getCount() == 1) { - RefPtr outIntVal; + //IntVal* outIntVal; if (auto cInt = checkConstantEnumVal(attr->args[0])) { targetClassId = (uint32_t)(cInt->value); @@ -522,7 +522,7 @@ namespace Slang return true; } - RefPtr SemanticsVisitor::checkAttribute( + AttributeBase* SemanticsVisitor::checkAttribute( UncheckedAttribute* uncheckedAttr, ModifiableSyntaxNode* attrTarget) { @@ -544,8 +544,8 @@ namespace Slang } // Manage scope - RefPtr attrInstance = attrDecl->syntaxClass.createInstance(m_astBuilder); - auto attr = attrInstance.as(); + NodeBase* attrInstance = attrDecl->syntaxClass.createInstance(m_astBuilder); + auto attr = as(attrInstance); if(!attr) { SLANG_DIAGNOSE_UNEXPECTED(getSink(), attrDecl, "attribute class did not yield an attribute object"); @@ -637,8 +637,8 @@ namespace Slang return attr; } - RefPtr SemanticsVisitor::checkModifier( - RefPtr m, + Modifier* SemanticsVisitor::checkModifier( + Modifier* m, ModifiableSyntaxNode* syntaxNode) { if(auto hlslUncheckedAttribute = as(m)) @@ -673,10 +673,10 @@ namespace Slang // The process of checking a modifier may produce a new modifier in its place, // so we will build up a new linked list of modifiers that will replace // the old list. - RefPtr resultModifiers; - RefPtr* resultModifierLink = &resultModifiers; + Modifier* resultModifiers = nullptr; + Modifier** resultModifierLink = &resultModifiers; - RefPtr modifier = syntaxNode->modifiers.first; + Modifier* modifier = syntaxNode->modifiers.first; while(modifier) { // Because we are rewriting the list in place, we need to extract diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 0bfb4ccaa..69baf9f75 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -138,8 +138,6 @@ namespace Slang { return true; } - - return false; } bool SemanticsVisitor::TryCheckGenericOverloadCandidateTypes( @@ -239,7 +237,7 @@ namespace Slang // The case for a generic value parameter is similar to that // for a generic type parameter. // - RefPtr arg; + Expr* arg = nullptr; if( aa >= context.argCount ) { // If there are no arguments left to consume, then @@ -276,7 +274,7 @@ namespace Slang // generalize in order to support generic value parameters // with types other than `int`. // - RefPtr val; + Val* val = nullptr; if( arg ) { val = ExtractGenericArgInteger(arg, context.mode == OverloadResolveContext::Mode::JustTrying ? nullptr : getSink()); @@ -383,7 +381,7 @@ namespace Slang // We should have the existing arguments to the generic // handy, so that we can construct a substitution list. - auto subst = candidate.subst.as(); + auto subst = as(candidate.subst); SLANG_ASSERT(subst); subst->genericDecl = genericDeclRef.getDecl(); @@ -444,10 +442,10 @@ namespace Slang candidate.status = OverloadCandidate::Status::Applicable; } - RefPtr SemanticsVisitor::createGenericDeclRef( - RefPtr baseExpr, - RefPtr originalExpr, - RefPtr subst) + Expr* SemanticsVisitor::createGenericDeclRef( + Expr* baseExpr, + Expr* originalExpr, + GenericSubstitution* subst) { auto baseDeclRefExpr = as(baseExpr); if (!baseDeclRefExpr) @@ -467,7 +465,7 @@ namespace Slang DeclRef innerDeclRef(getInner(baseGenericRef), subst); - RefPtr base; + Expr* base = nullptr; if (auto mbrExpr = as(baseExpr)) base = mbrExpr->baseExpression; @@ -477,7 +475,7 @@ namespace Slang originalExpr->loc); } - RefPtr SemanticsVisitor::CompleteOverloadCandidate( + Expr* SemanticsVisitor::CompleteOverloadCandidate( OverloadResolveContext& context, OverloadCandidate& candidate) { @@ -520,7 +518,7 @@ namespace Slang { case OverloadCandidate::Flavor::Func: { - RefPtr callExpr = as(context.originalExpr); + AppExprBase* callExpr = as(context.originalExpr); if(!callExpr) { callExpr = m_astBuilder->create(); @@ -555,7 +553,7 @@ namespace Slang return createGenericDeclRef( baseExpr, context.originalExpr, - candidate.subst.as()); + as(candidate.subst)); break; default: @@ -569,7 +567,7 @@ namespace Slang if(context.originalExpr) { - return CreateErrorExpr(context.originalExpr.Ptr()); + return CreateErrorExpr(context.originalExpr); } else { @@ -615,7 +613,7 @@ namespace Slang // parent generic (and not somthing like a generic // parameter). // - if( parentGeneric.getDecl()->inner.Ptr() != declRef.getDecl()) + if( parentGeneric.getDecl()->inner != declRef.getDecl()) return 0; return CountParameters(parentGeneric).required; @@ -946,7 +944,7 @@ namespace Slang } void SemanticsVisitor::AddFuncOverloadCandidate( - RefPtr funcType, + FuncType* funcType, OverloadResolveContext& context) { SLANG_UNUSED(funcType); @@ -955,11 +953,13 @@ namespace Slang void SemanticsVisitor::AddCtorOverloadCandidate( LookupResultItem typeItem, - RefPtr type, + Type* type, DeclRef ctorDeclRef, OverloadResolveContext& context, - RefPtr resultType) + Type* resultType) { + SLANG_UNUSED(type) + ensureDecl(ctorDeclRef, DeclCheckState::CanUseFuncSignature); // `typeItem` refers to the type being constructed (the thing @@ -1060,7 +1060,7 @@ namespace Slang } void SemanticsVisitor::AddTypeOverloadCandidates( - RefPtr type, + Type* type, OverloadResolveContext& context) { // The code being checked is trying to apply `type` like a function. @@ -1172,7 +1172,7 @@ namespace Slang } void SemanticsVisitor::AddOverloadCandidates( - RefPtr funcExpr, + Expr* funcExpr, OverloadResolveContext& context) { // A call of the form `()()` should be @@ -1224,12 +1224,12 @@ namespace Slang } } - void SemanticsVisitor::formatType(StringBuilder& sb, RefPtr type) + void SemanticsVisitor::formatType(StringBuilder& sb, Type* type) { sb << type->toString(); } - void SemanticsVisitor::formatVal(StringBuilder& sb, RefPtr val) + void SemanticsVisitor::formatVal(StringBuilder& sb, Val* val) { sb << val->toString(); } @@ -1276,7 +1276,7 @@ namespace Slang // signature if( parentGenericDeclRef ) { - auto genSubst = declRef.substitutions.substitutions.as(); + auto genSubst = as(declRef.substitutions.substitutions); SLANG_RELEASE_ASSERT(genSubst); SLANG_RELEASE_ASSERT(genSubst->genericDecl == parentGenericDeclRef.getDecl()); @@ -1294,7 +1294,7 @@ namespace Slang bool first = true; for(auto arg : genSubst->args) { - // When printing the representation of a sepcialized + // When printing the representation of a specialized // generic declaration we don't want to include the // argument values for subtype witnesses since these // do not correspond to parameters of the generic @@ -1431,14 +1431,14 @@ namespace Slang return argsListBuilder.ProduceString(); } - RefPtr SemanticsVisitor::ResolveInvoke(InvokeExpr * expr) + Expr* SemanticsVisitor::ResolveInvoke(InvokeExpr * expr) { OverloadResolveContext context; // check if this is a stdlib operator call, if so we want to use cached results // to speed up compilation bool shouldAddToCache = false; OperatorOverloadCacheKey key; - TypeCheckingCache* typeCheckingCache = getSession()->getTypeCheckingCache(); + TypeCheckingCache* typeCheckingCache = getLinkage()->getTypeCheckingCache(); if (auto opExpr = as(expr)) { if (key.fromOperatorExpr(opExpr)) @@ -1651,7 +1651,7 @@ namespace Slang } void SemanticsVisitor::AddGenericOverloadCandidates( - RefPtr baseExpr, + Expr* baseExpr, OverloadResolveContext& context) { if(auto baseDeclRefExpr = as(baseExpr)) @@ -1674,7 +1674,7 @@ namespace Slang } } - RefPtr SemanticsExprVisitor::visitGenericAppExpr(GenericAppExpr* genericAppExpr) + Expr* SemanticsExprVisitor::visitGenericAppExpr(GenericAppExpr* genericAppExpr) { // Start by checking the base expression and arguments. auto& baseExpr = genericAppExpr->functionExpr; @@ -1689,7 +1689,7 @@ namespace Slang } /// Check a generic application where the operands have already been checked. - RefPtr SemanticsVisitor::checkGenericAppWithCheckedArgs(GenericAppExpr* genericAppExpr) + Expr* SemanticsVisitor::checkGenericAppWithCheckedArgs(GenericAppExpr* genericAppExpr) { // We are applying a generic to arguments, but there might be multiple generic // declarations with the same name, so this becomes a specialized case of diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp index 80860074d..fcb9b1618 100644 --- a/source/slang/slang-check-shader.cpp +++ b/source/slang/slang-check-shader.cpp @@ -604,7 +604,7 @@ namespace Slang for( auto globalDecl : moduleDecl->members ) { - if(auto globalVar = globalDecl.as()) + if(auto globalVar = as(globalDecl)) { // We do not want to consider global variable declarations // that don't represents shader parameters. This includes @@ -616,7 +616,7 @@ namespace Slang // At this point we know we have a global shader parameter. ShaderParamInfo shaderParamInfo; - shaderParamInfo.paramDeclRef = makeDeclRef(globalVar.Ptr()); + shaderParamInfo.paramDeclRef = makeDeclRef(globalVar); // We need to consider what specialization parameters // are introduced by this shader parameter. This step @@ -628,7 +628,7 @@ namespace Slang getLinkage()->getASTBuilder(), shaderParamInfo, m_specializationParams, - makeDeclRef(globalVar.Ptr())); + makeDeclRef(globalVar)); m_shaderParams.add(shaderParamInfo); } @@ -968,10 +968,10 @@ namespace Slang { case SpecializationParam::Flavor::GenericType: { - auto genericTypeParamDecl = param.object.as(); + auto genericTypeParamDecl = as(param.object); SLANG_ASSERT(genericTypeParamDecl); - RefPtr argType = as(arg.val); + Type* argType = as(arg.val); if(!argType) { sink->diagnose(param.loc, Diagnostics::expectedTypeForSpecializationArg, genericTypeParamDecl); @@ -999,7 +999,7 @@ namespace Slang // global generic type parameter is a reference to *another* global generic // type parameter, since that should always be an error. // - if( auto argDeclRefType = argType.as() ) + if( auto argDeclRefType = as(argType) ) { auto argDeclRef = argDeclRefType->declRef; if(auto argGenericParamDeclRef = argDeclRef.as()) @@ -1060,10 +1060,10 @@ namespace Slang case SpecializationParam::Flavor::ExistentialType: { - auto interfaceType = param.object.as(); + auto interfaceType = as(param.object); SLANG_ASSERT(interfaceType); - RefPtr argType = as(arg.val); + Type* argType = as(arg.val); if(!argType) { sink->diagnose(param.loc, Diagnostics::expectedTypeForSpecializationArg, interfaceType); @@ -1091,13 +1091,13 @@ namespace Slang case SpecializationParam::Flavor::GenericValue: { - auto paramDecl = param.object.as(); + auto paramDecl = as(param.object); SLANG_ASSERT(paramDecl); // Now we need to check that the argument `Val` has the // appropriate type expected by the parameter. - RefPtr intVal = as(arg.val); + IntVal* intVal = as(arg.val); if(!intVal) { sink->diagnose(param.loc, Diagnostics::expectedValueOfTypeForSpecializationArg, paramDecl->getType(), paramDecl); @@ -1123,7 +1123,7 @@ namespace Slang static void _extractSpecializationArgs( ComponentType* componentType, - List> const& argExprs, + List const& argExprs, List& outArgs, DiagnosticSink* sink) { @@ -1175,7 +1175,7 @@ namespace Slang auto genericDeclRef = m_funcDeclRef.getParent().as(); SLANG_ASSERT(genericDeclRef); // otherwise we wouldn't have generic parameters - RefPtr genericSubst = getLinkage()->getASTBuilder()->create(); + GenericSubstitution* genericSubst = getLinkage()->getASTBuilder()->create(); genericSubst->outer = genericDeclRef.substitutions.substitutions; genericSubst->genericDecl = genericDeclRef.getDecl(); @@ -1235,8 +1235,8 @@ namespace Slang // TODO: We need to handle all the cases of "flavor" for the `param`s (not just types) - auto paramType = param.object.as(); - auto argType = specializationArg.val.as(); + auto paramType = as(param.object); + auto argType = as(specializationArg.val); auto witness = visitor.tryGetSubtypeWitness(argType, paramType); if (!witness) @@ -1260,7 +1260,7 @@ namespace Slang /// Create a specialization an existing entry point based on specialization argument expressions. RefPtr createSpecializedEntryPoint( EntryPoint* unspecializedEntryPoint, - List> const& argExprs, + List const& argExprs, DiagnosticSink* sink) { // We need to convert all of the `Expr` arguments @@ -1316,7 +1316,7 @@ namespace Slang void parseSpecializationArgStrings( EndToEndCompileRequest* endToEndReq, List const& genericArgStrings, - List>& outGenericArgs) + List& outGenericArgs) { auto unspecialiedProgram = endToEndReq->getUnspecializedGlobalComponentType(); @@ -1343,7 +1343,7 @@ namespace Slang // for(auto name : genericArgStrings) { - RefPtr argExpr = linkage->parseTermString(name, scope); + Expr* argExpr = linkage->parseTermString(name, scope); argExpr = semantics.CheckTerm(argExpr); if(!argExpr) @@ -1378,7 +1378,7 @@ namespace Slang ExpandedSpecializationArgs specializationArgs; for( Int aa = 0; aa < argCount; ++aa ) { - auto paramType = specializationParams[aa].object.as(); + auto paramType = as(specializationParams[aa].object); auto argType = args[aa]; ExpandedSpecializationArg arg; @@ -1387,7 +1387,7 @@ namespace Slang specializationArgs.add(arg); } - RefPtr specializedType = m_astBuilder->create(); + ExistentialSpecializedType* specializedType = m_astBuilder->create(); specializedType->baseType = unspecializedType; specializedType->args = specializationArgs; @@ -1400,7 +1400,7 @@ namespace Slang static RefPtr _createSpecializedProgramImpl( Linkage* linkage, ComponentType* unspecializedProgram, - List> const& specializationArgExprs, + List const& specializationArgExprs, DiagnosticSink* sink) { // If there are no specialization arguments, @@ -1455,12 +1455,14 @@ namespace Slang EndToEndCompileRequest::EntryPointInfo const& entryPointInfo) { auto sink = endToEndReq->getSink(); - auto entryPointFuncDecl = unspecializedEntryPoint->getFuncDecl(); + + // TODO(JS): Not used + //auto entryPointFuncDecl = unspecializedEntryPoint->getFuncDecl(); // If the user specified generic arguments for the entry point, // then we will need to parse the arguments first. // - List> specializationArgExprs; + List specializationArgExprs; parseSpecializationArgStrings( endToEndReq, entryPointInfo.specializationArgStrings, @@ -1504,7 +1506,7 @@ namespace Slang // provided via the API, so that we can match them // against what was declared in the program. // - List> globalSpecializationArgs; + List globalSpecializationArgs; parseSpecializationArgStrings( endToEndReq, endToEndReq->globalSpecializationArgStrings, diff --git a/source/slang/slang-check-stmt.cpp b/source/slang/slang-check-stmt.cpp index 71cf97396..2d01086f1 100644 --- a/source/slang/slang-check-stmt.cpp +++ b/source/slang/slang-check-stmt.cpp @@ -108,9 +108,9 @@ namespace Slang stmt->parentStmt = outer; } - RefPtr SemanticsVisitor::checkPredicateExpr(Expr* expr) + Expr* SemanticsVisitor::checkPredicateExpr(Expr* expr) { - RefPtr e = expr; + Expr* e = expr; e = CheckTerm(e); e = coerce(m_astBuilder->getBoolType(), e); return e; @@ -140,7 +140,7 @@ namespace Slang subContext.checkStmt(stmt->statement); } - RefPtr SemanticsVisitor::checkExpressionAndExpectIntegerConstant(RefPtr expr, RefPtr* outIntVal) + Expr* SemanticsVisitor::checkExpressionAndExpectIntegerConstant(Expr* expr, IntVal** outIntVal) { expr = CheckExpr(expr); auto intVal = CheckIntegerConstantExpression(expr); @@ -157,8 +157,8 @@ namespace Slang addModifier(stmt->varDecl, m_astBuilder->create()); stmt->varDecl->setCheckState(DeclCheckState::Checked); - RefPtr rangeBeginVal; - RefPtr rangeEndVal; + IntVal* rangeBeginVal = nullptr; + IntVal* rangeEndVal = nullptr; if (stmt->rangeBeginExpr) { @@ -166,7 +166,7 @@ namespace Slang } else { - RefPtr rangeBeginConst = m_astBuilder->create(); + ConstantIntVal* rangeBeginConst = m_astBuilder->create(); rangeBeginConst->value = 0; rangeBeginVal = rangeBeginConst; } diff --git a/source/slang/slang-check-type.cpp b/source/slang/slang-check-type.cpp index bdb043413..98b376a69 100644 --- a/source/slang/slang-check-type.cpp +++ b/source/slang/slang-check-type.cpp @@ -6,7 +6,7 @@ namespace Slang { - RefPtr checkProperType( + Type* checkProperType( Linkage* linkage, TypeExp typeExp, DiagnosticSink* sink) @@ -21,7 +21,7 @@ namespace Slang return typeOut.type; } - RefPtr SemanticsVisitor::TranslateTypeNodeImpl(const RefPtr & node) + Expr* SemanticsVisitor::TranslateTypeNodeImpl(Expr* node) { if (!node) return nullptr; @@ -30,7 +30,7 @@ namespace Slang return expr; } - RefPtr SemanticsVisitor::ExtractTypeFromTypeRepr(const RefPtr& typeRepr) + Type* SemanticsVisitor::ExtractTypeFromTypeRepr(Expr* typeRepr) { if (!typeRepr) return nullptr; if (auto typeType = as(typeRepr->type)) @@ -40,7 +40,7 @@ namespace Slang return m_astBuilder->getErrorType(); } - RefPtr SemanticsVisitor::TranslateTypeNode(const RefPtr & node) + Type* SemanticsVisitor::TranslateTypeNode(Expr* node) { if (!node) return nullptr; auto typeRepr = TranslateTypeNodeImpl(node); @@ -70,7 +70,7 @@ namespace Slang return TranslateTypeNodeForced(typeExp); } - RefPtr SemanticsVisitor::ExpectATypeRepr(RefPtr expr) + Expr* SemanticsVisitor::ExpectATypeRepr(Expr* expr) { if (auto overloadedExpr = as(expr)) { @@ -90,7 +90,7 @@ namespace Slang return CreateErrorExpr(expr); } - RefPtr SemanticsVisitor::ExpectAType(RefPtr expr) + Type* SemanticsVisitor::ExpectAType(Expr* expr) { auto typeRepr = ExpectATypeRepr(expr); if (auto typeType = as(typeRepr->type)) @@ -100,14 +100,14 @@ namespace Slang return m_astBuilder->getErrorType(); } - RefPtr SemanticsVisitor::ExtractGenericArgType(RefPtr exp) + Type* SemanticsVisitor::ExtractGenericArgType(Expr* exp) { return ExpectAType(exp); } - RefPtr SemanticsVisitor::ExtractGenericArgInteger(RefPtr exp, DiagnosticSink* sink) + IntVal* SemanticsVisitor::ExtractGenericArgInteger(Expr* exp, DiagnosticSink* sink) { - RefPtr val = CheckIntegerConstantExpression(exp.Ptr(), sink); + IntVal* val = CheckIntegerConstantExpression(exp, sink); if(val) return val; // If the argument expression could not be coerced to an integer @@ -118,12 +118,12 @@ namespace Slang return val; } - RefPtr SemanticsVisitor::ExtractGenericArgInteger(RefPtr exp) + IntVal* SemanticsVisitor::ExtractGenericArgInteger(Expr* exp) { return ExtractGenericArgInteger(exp, getSink()); } - RefPtr SemanticsVisitor::ExtractGenericArgVal(RefPtr exp) + Val* SemanticsVisitor::ExtractGenericArgVal(Expr* exp) { if (auto overloadedExpr = as(exp)) { @@ -145,11 +145,11 @@ namespace Slang } } - RefPtr SemanticsVisitor::InstantiateGenericType( + Type* SemanticsVisitor::InstantiateGenericType( DeclRef genericDeclRef, - List> const& args) + List const& args) { - RefPtr subst = m_astBuilder->create(); + GenericSubstitution* subst = m_astBuilder->create(); subst->genericDecl = genericDeclRef.getDecl(); subst->outer = genericDeclRef.substitutions.substitutions; @@ -167,10 +167,10 @@ namespace Slang bool SemanticsVisitor::CoerceToProperTypeImpl( TypeExp const& typeExp, - RefPtr* outProperType, + Type** outProperType, DiagnosticSink* diagSink) { - Type* type = typeExp.type.Ptr(); + Type* type = typeExp.type; if(!type && typeExp.exp) { auto expr = typeExp.exp; @@ -204,8 +204,8 @@ namespace Slang auto genericDeclRef = genericDeclRefType->getDeclRef(); ensureDecl(genericDeclRef, DeclCheckState::CanSpecializeGeneric); - List> args; - for (RefPtr member : genericDeclRef.getDecl()->members) + List args; + for (Decl* member : genericDeclRef.getDecl()->members) { if (auto typeParam = as(member)) { @@ -213,7 +213,7 @@ namespace Slang { if (diagSink) { - diagSink->diagnose(typeExp.exp.Ptr(), Diagnostics::genericTypeNeedsArgs, typeExp); + diagSink->diagnose(typeExp.exp, Diagnostics::genericTypeNeedsArgs, typeExp); *outProperType = m_astBuilder->getErrorType(); } return false; @@ -229,7 +229,7 @@ namespace Slang { if (diagSink) { - diagSink->diagnose(typeExp.exp.Ptr(), Diagnostics::unimplemented, "can't fill in default for generic type parameter"); + diagSink->diagnose(typeExp.exp, Diagnostics::unimplemented, "can't fill in default for generic type parameter"); *outProperType = m_astBuilder->getErrorType(); } return false; @@ -283,14 +283,14 @@ namespace Slang TypeExp SemanticsVisitor::CoerceToUsableType(TypeExp const& typeExp) { TypeExp result = CoerceToProperType(typeExp); - Type* type = result.type.Ptr(); + Type* type = result.type; if (auto basicType = as(type)) { // TODO: `void` shouldn't be a basic type, to make this easier to avoid if (basicType->baseType == BaseType::Void) { // TODO(tfoley): pick the right diagnostic message - getSink()->diagnose(result.exp.Ptr(), Diagnostics::invalidTypeVoid); + getSink()->diagnose(result.exp, Diagnostics::invalidTypeVoid); result.type = m_astBuilder->getErrorType(); return result; } @@ -304,8 +304,8 @@ namespace Slang } bool SemanticsVisitor::ValuesAreEqual( - RefPtr left, - RefPtr right) + IntVal* left, + IntVal* right) { if(left == right) return true; @@ -328,25 +328,25 @@ namespace Slang return false; } - RefPtr SemanticsVisitor::createVectorType( - RefPtr elementType, - RefPtr elementCount) + VectorExpressionType* SemanticsVisitor::createVectorType( + Type* elementType, + IntVal* elementCount) { - auto vectorGenericDecl = m_astBuilder->getSharedASTBuilder()->findMagicDecl("Vector").as(); + auto vectorGenericDecl = as(m_astBuilder->getSharedASTBuilder()->findMagicDecl("Vector")); auto vectorTypeDecl = vectorGenericDecl->inner; auto substitutions = m_astBuilder->create(); - substitutions->genericDecl = vectorGenericDecl.Ptr(); + substitutions->genericDecl = vectorGenericDecl; substitutions->args.add(elementType); substitutions->args.add(elementCount); - auto declRef = DeclRef(vectorTypeDecl.Ptr(), substitutions); + auto declRef = DeclRef(vectorTypeDecl, substitutions); - return DeclRefType::create(m_astBuilder, declRef).as(); + return as(DeclRefType::create(m_astBuilder, declRef)); } - RefPtr SemanticsExprVisitor::visitSharedTypeExpr(SharedTypeExpr* expr) + Expr* SemanticsExprVisitor::visitSharedTypeExpr(SharedTypeExpr* expr) { if (!expr->type.Ptr()) { @@ -356,12 +356,12 @@ namespace Slang return expr; } - RefPtr SemanticsExprVisitor::visitTaggedUnionTypeExpr(TaggedUnionTypeExpr* expr) + Expr* SemanticsExprVisitor::visitTaggedUnionTypeExpr(TaggedUnionTypeExpr* expr) { // We have an expression of the form `__TaggedUnion(A, B, ...)` // which will evaluate to a tagged-union type over `A`, `B`, etc. // - RefPtr type = m_astBuilder->create(); + TaggedUnionType* type = m_astBuilder->create(); expr->type = QualType(m_astBuilder->getTypeType(type)); for( auto& caseTypeExpr : expr->caseTypes ) diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp index 5b2b2b132..b86d90cec 100644 --- a/source/slang/slang-check.cpp +++ b/source/slang/slang-check.cpp @@ -196,19 +196,6 @@ namespace Slang return func; } - TypeCheckingCache* Session::getTypeCheckingCache() - { - if (!typeCheckingCache) - typeCheckingCache = new TypeCheckingCache(); - return typeCheckingCache; - } - - void Session::destroyTypeCheckingCache() - { - delete typeCheckingCache; - typeCheckingCache = nullptr; - } - void checkTranslationUnit( TranslationUnitRequest* translationUnit) { diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index d5de51ac4..f8843fadc 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -483,7 +483,7 @@ namespace Slang // // TODO: Remove this. Type lookup should only be supported on `Module`s. // - Dictionary> m_types; + Dictionary m_types; }; /// A component type built up from other component types. @@ -604,7 +604,7 @@ namespace Slang List const& getFilePathDependencies() SLANG_OVERRIDE { return m_base->getFilePathDependencies(); } /// Get a list of tagged-union types referenced by the specialization parameters. - List> const& getTaggedUnionTypes() { return m_taggedUnionTypes; } + List const& getTaggedUnionTypes() { return m_taggedUnionTypes; } RefPtr getIRModule() { return m_irModule; } @@ -632,7 +632,7 @@ namespace Slang List m_entryPointMangledNames; // Any tagged union types that were referenced by the specialization arguments. - List> m_taggedUnionTypes; + List m_taggedUnionTypes; }; @@ -711,7 +711,7 @@ namespace Slang DeclRef getFuncDeclRef() { return m_funcDeclRef; } /// Get the function declaration (without generic arguments). - RefPtr getFuncDecl() { return m_funcDeclRef.getDecl(); } + FuncDecl* getFuncDecl() { return m_funcDeclRef.getDecl(); } /// Get the name of the entry point Name* getName() { return m_name; } @@ -989,8 +989,8 @@ namespace Slang public: struct GenericArgInfo { - RefPtr paramDecl; - RefPtr argVal; + Decl* paramDecl = nullptr; + Val* argVal = nullptr; }; List genericArgs; @@ -1012,7 +1012,7 @@ namespace Slang private: // The AST for the module - RefPtr m_moduleDecl; + ModuleDecl* m_moduleDecl = nullptr; // The IR for the module RefPtr m_irModule = nullptr; @@ -1092,7 +1092,7 @@ namespace Slang RefPtr module; Module* getModule() { return module; } - RefPtr getModuleDecl() { return module->getModuleDecl(); } + ModuleDecl* getModuleDecl() { return module->getModuleDecl(); } Session* getSession(); NamePool* getNamePool(); @@ -1193,6 +1193,7 @@ namespace Slang /// Given a target returns the required downstream compiler PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target); + struct TypeCheckingCache; /// A context for loading and re-using code modules. class Linkage : public RefObject, public slang::ISession @@ -1237,6 +1238,9 @@ namespace Slang /// Create an initially-empty linkage Linkage(Session* session, ASTBuilder* astBuilder); + /// Dtor + ~Linkage(); + /// Get the parent session for this linkage Session* getSessionImpl() { return m_session; } @@ -1265,8 +1269,15 @@ namespace Slang ASTBuilder* getASTBuilder() { return m_astBuilder; } + RefPtr m_astBuilder; + // cache used by type checking, implemented in check.cpp + TypeCheckingCache* getTypeCheckingCache(); + void destroyTypeCheckingCache(); + + TypeCheckingCache* m_typeCheckingCache = nullptr; + // Modules that have been dynamically loaded via `import` // // This is a list of unique modules loaded, in the order they were encountered. @@ -1308,7 +1319,7 @@ namespace Slang /// SlangResult loadFile(String const& path, PathInfo& outPathInfo, ISlangBlob** outBlob); - RefPtr parseTermString(String str, RefPtr scope); + Expr* parseTermString(String str, RefPtr scope); Type* specializeType( Type* unspecializedType, @@ -1426,7 +1437,7 @@ namespace Slang /// Is the given module in the middle of being imported? bool isBeingImported(Module* module); - List> m_specializedTypes; + List m_specializedTypes; }; @@ -1952,7 +1963,6 @@ namespace Slang EndToEndCompileRequest* endToEndReq, SourceResult& outSource); - struct TypeCheckingCache; // // Information about BaseType that's useful for checking literals @@ -2037,7 +2047,8 @@ namespace Slang RefPtr hlslLanguageScope; RefPtr slangLanguageScope; - List> loadedModuleCode; + ModuleDecl* baseModuleDecl = nullptr; + List> loadedModuleCode; SourceManager builtinSourceManager; @@ -2074,10 +2085,7 @@ namespace Slang RefPtr m_sharedASTBuilder; - // cache used by type checking, implemented in check.cpp - TypeCheckingCache* typeCheckingCache = nullptr; - TypeCheckingCache* getTypeCheckingCache(); - void destroyTypeCheckingCache(); + // void setSharedLibraryLoader(ISlangSharedLibraryLoader* loader); diff --git a/source/slang/slang-emit-c-like.h b/source/slang/slang-emit-c-like.h index 212e90019..e1106ea76 100644 --- a/source/slang/slang-emit-c-like.h +++ b/source/slang/slang-emit-c-like.h @@ -373,7 +373,7 @@ public: // we maintain a set of already-emitted modules. HashSet m_modulesAlreadyEmitted; - ModuleDecl* m_program; + ModuleDecl* m_program = nullptr; UInt m_uniqueIDCounter = 1; Dictionary m_mapIRValueToID; diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 41d10b289..136bf322f 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3543,7 +3543,7 @@ namespace Slang void IRBuilder::addHighLevelDeclDecoration(IRInst* inst, Decl* decl) { - auto ptrConst = getPtrValue(addRefObjectToFree(decl)); + auto ptrConst = getPtrValue(decl); addDecoration(inst, kIROp_HighLevelDeclDecoration, ptrConst); } diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index fae00c6a2..19cd4cafe 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -11,7 +11,7 @@ void ensureDecl(SemanticsVisitor* visitor, Decl* decl, DeclCheckState state); DeclRef ApplyExtensionToType( SemanticsVisitor* semantics, ExtensionDecl* extDecl, - RefPtr type); + Type* type); // @@ -268,7 +268,7 @@ LookupResult lookUpDirectAndTransparentMembers( } -static RefPtr _makeSubtypeWitness( +static SubtypeWitness* _makeSubtypeWitness( ASTBuilder* astBuilder, Type* subType, SubtypeWitness* subToMidWitness, @@ -277,7 +277,7 @@ static RefPtr _makeSubtypeWitness( { if(subToMidWitness) { - RefPtr transitiveWitness = astBuilder->create(); + TransitiveSubtypeWitness* transitiveWitness = astBuilder->create(); transitiveWitness->subToMid = subToMidWitness; transitiveWitness->midToSup = midToSuperConstraint; transitiveWitness->sub = subType; @@ -286,7 +286,7 @@ static RefPtr _makeSubtypeWitness( } else { - RefPtr declaredWitness = astBuilder->create(); + DeclaredSubtypeWitness* declaredWitness = astBuilder->create(); declaredWitness->declRef = midToSuperConstraint; declaredWitness->sub = subType; declaredWitness->sup = superType; @@ -295,7 +295,7 @@ static RefPtr _makeSubtypeWitness( } // Same as the above, but we are specializing a type instead of a decl-ref -static RefPtr _maybeSpecializeSuperType( +static Type* _maybeSpecializeSuperType( ASTBuilder* astBuilder, Type* superType, SubtypeWitness* subIsSuperWitness) @@ -304,7 +304,7 @@ static RefPtr _maybeSpecializeSuperType( { if (auto superInterfaceDeclRef = superDeclRefType->declRef.as()) { - RefPtr thisTypeSubst = astBuilder->create(); + ThisTypeSubstitution* thisTypeSubst = astBuilder->create(); thisTypeSubst->interfaceDecl = superInterfaceDeclRef.getDecl(); thisTypeSubst->witness = subIsSuperWitness; thisTypeSubst->outer = superInterfaceDeclRef.substitutions.substitutions; @@ -322,7 +322,7 @@ static RefPtr _maybeSpecializeSuperType( static void _lookUpMembersInType( ASTBuilder* astBuilder, Name* name, - RefPtr type, + Type* type, LookupRequest const& request, LookupResult& ioResult, BreadcrumbInfo* breadcrumbs); @@ -584,7 +584,7 @@ static void _lookUpMembersInSuperTypeImpl( static void _lookUpMembersInType( ASTBuilder* astBuilder, Name* name, - RefPtr type, + Type* type, LookupRequest const& request, LookupResult& ioResult, BreadcrumbInfo* breadcrumbs) @@ -679,7 +679,7 @@ static void _lookUpInScopes( breadcrumb.declRef = aggTypeDeclBaseRef; breadcrumb.prev = nullptr; - RefPtr type; + Type* type = nullptr; if(auto extDeclRef = aggTypeDeclBaseRef.as()) { if( request.semantics ) diff --git a/source/slang/slang-lookup.h b/source/slang/slang-lookup.h index 253355d7b..1402918ad 100644 --- a/source/slang/slang-lookup.h +++ b/source/slang/slang-lookup.h @@ -47,7 +47,7 @@ QualType getTypeForDeclRef( SemanticsVisitor* sema, DiagnosticSink* sink, DeclRef declRef, - RefPtr* outTypeResult, + Type** outTypeResult, SourceLoc loc); QualType getTypeForDeclRef( diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index ecec6f2ec..a1089b537 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -1606,7 +1606,7 @@ void addVarDecorations( Decl* decl) { auto builder = context->irBuilder; - for(RefPtr mod : decl->modifiers) + for(Modifier* mod : decl->modifiers) { if(as(mod)) { @@ -1947,7 +1947,7 @@ DeclRef createDefaultSpecializedDeclRef(IRGenContext* context, D* decl) /// includes things like function declarations themselves, which inherit the /// definition of `this` from their parent/outer declaration. /// -RefPtr getThisParamTypeForContainer( +Type* getThisParamTypeForContainer( IRGenContext* context, DeclRef parentDeclRef) { @@ -1963,7 +1963,7 @@ RefPtr getThisParamTypeForContainer( return nullptr; } -RefPtr getThisParamTypeForCallable( +Type* getThisParamTypeForCallable( IRGenContext* context, DeclRef callableDeclRef) { @@ -2537,7 +2537,7 @@ struct ExprLoweringVisitorBase : ExprVisitor auto paramDirection = getParameterDirection(paramDecl); UInt argIndex = argCounter++; - RefPtr argExpr; + Expr* argExpr = nullptr; if(argIndex < argCount) { argExpr = expr->arguments[argIndex]; @@ -2621,7 +2621,7 @@ struct ExprLoweringVisitorBase : ExprVisitor // with some contextual information about the declaration // we are calling. bool tryResolveDeclRefForCall( - RefPtr funcExpr, + Expr* funcExpr, ResolvedCallInfo* outInfo) { // TODO: unwrap any "identity" expressions that might @@ -2673,7 +2673,7 @@ struct ExprLoweringVisitorBase : ExprVisitor { // Seems to be a case of declaration-reference we don't know about. SLANG_UNEXPECTED("unknown declaration reference kind"); - return false; + //return false; } } @@ -4587,7 +4587,7 @@ struct DeclLoweringVisitor : DeclVisitor // the inheritance declaration is on an `extension` declaration, // then we need to identify the type being extended. // - RefPtr subType; + Type* subType = nullptr; if (auto extParentDecl = as(parentDecl)) { subType = extParentDecl->targetType.type; @@ -4598,7 +4598,7 @@ struct DeclLoweringVisitor : DeclVisitor } // What is the super-type that we have declared we inherit from? - RefPtr superType = inheritanceDecl->base.type; + Type* superType = inheritanceDecl->base.type; if(auto superDeclRefType = as(superType)) { @@ -5504,14 +5504,14 @@ struct DeclLoweringVisitor : DeclVisitor struct ParameterInfo { // This AST-level type of the parameter - RefPtr type; + Type* type = nullptr; // The direction (`in` vs `out` vs `in out`) ParameterDirection direction; // The variable/parameter declaration for // this parameter (if any) - VarDeclBase* decl; + VarDeclBase* decl = nullptr; // Is this the representation of a `this` parameter? bool isThisParam = false; @@ -6573,7 +6573,7 @@ IRInst* lowerSubstitutionArg( } // Can the IR lowered version of this declaration ever be an `IRGeneric`? -bool canDeclLowerToAGeneric(RefPtr decl) +bool canDeclLowerToAGeneric(Decl* decl) { // A callable decl lowers to an `IRFunc`, and can be generic if(as(decl)) return true; @@ -6593,8 +6593,8 @@ bool canDeclLowerToAGeneric(RefPtr decl) LoweredValInfo emitDeclRef( IRGenContext* context, - RefPtr decl, - RefPtr subst, + Decl* decl, + Substitutions* subst, IRType* type) { // We need to proceed by considering the specializations that @@ -6624,7 +6624,7 @@ LoweredValInfo emitDeclRef( } // Otherwise, we look at the kind of substitution, and let it guide us. - if(auto genericSubst = subst.as()) + if(auto genericSubst = as(subst)) { // A generic substitution means we will need to output // a `specialize` instruction to specialize the generic. @@ -6673,9 +6673,9 @@ LoweredValInfo emitDeclRef( return LoweredValInfo::simple(irSpecializedVal); } - else if(auto thisTypeSubst = subst.as()) + else if(auto thisTypeSubst = as(subst)) { - if(decl.Ptr() == thisTypeSubst->interfaceDecl) + if(decl == thisTypeSubst->interfaceDecl) { // This is a reference to the interface type itself, // through the this-type substitution, so it is really diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp index 758e1d6f1..ab90f4bc2 100644 --- a/source/slang/slang-mangle.cpp +++ b/source/slang/slang-mangle.cpp @@ -225,7 +225,7 @@ namespace Slang if( parentDeclRef ) { // In certain cases we want to skip emitting the parent - if(parentGenericDeclRef && (parentGenericDeclRef.getDecl()->inner.Ptr() != declRef.getDecl())) + if(parentGenericDeclRef && (parentGenericDeclRef.getDecl()->inner != declRef.getDecl())) { } else if(parentDeclRef.as()) @@ -287,7 +287,7 @@ namespace Slang // Are we the "inner" declaration beneath a generic decl? - if(parentGenericDeclRef && (parentGenericDeclRef.getDecl()->inner.Ptr() == declRef.getDecl())) + if(parentGenericDeclRef && (parentGenericDeclRef.getDecl()->inner == declRef.getDecl())) { // There are two cases here: either we have specializations // in place for the parent generic declaration, or we don't. diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index 58ce76c45..ea45612ec 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -584,7 +584,7 @@ LayoutSemanticInfo ExtractLayoutSemanticInfo( // a particular sub-argument and extract its value if present. template static bool findLayoutArg( - RefPtr syntax, + ModifiableSyntaxNode* syntax, UInt* outVal) { for( auto modifier : syntax->getModifiersOfType() ) @@ -674,7 +674,7 @@ struct EntryPointParameterState static RefPtr processEntryPointVaryingParameter( ParameterBindingContext* context, - RefPtr type, + Type* type, EntryPointParameterState const& state, RefPtr varLayout); @@ -707,7 +707,7 @@ static void collectGlobalScopeParameter( auto varDeclRef = shaderParamInfo.paramDeclRef; // We apply any substitutions for global generic parameters here. - auto type = getType(astBuilder, varDeclRef)->substitute(astBuilder, globalGenericSubst).as(); + auto type = as(getType(astBuilder, varDeclRef)->substitute(astBuilder, globalGenericSubst)); // We use a single operation to both check whether the // variable represents a shader parameter, and to compute @@ -1014,8 +1014,10 @@ static void addExplicitParameterBindings_GLSL( } else if( (resInfo = typeLayout->FindResourceInfo(LayoutResourceKind::SpecializationConstant)) != nullptr ) { + DeclRef varDecl2(varDecl); + // Try to find `constant_id` binding - if(!findLayoutArg(varDecl, &semanticInfo.index)) + if(!findLayoutArg(varDecl2, &semanticInfo.index)) return; } @@ -1382,7 +1384,7 @@ SimpleSemanticInfo decomposeSimpleSemantic( static RefPtr processSimpleEntryPointParameter( ParameterBindingContext* context, - RefPtr type, + Type* type, EntryPointParameterState const& inState, RefPtr varLayout, int semanticSlotCount = 1) @@ -1546,7 +1548,7 @@ static RefPtr processSimpleEntryPointParameter( static RefPtr processEntryPointVaryingParameterDecl( ParameterBindingContext* context, Decl* decl, - RefPtr type, + Type* type, EntryPointParameterState const& inState, RefPtr varLayout) { @@ -1703,7 +1705,7 @@ static RefPtr processEntryPointVaryingParameterDecl( static RefPtr processEntryPointVaryingParameter( ParameterBindingContext* context, - RefPtr type, + Type* type, EntryPointParameterState const& state, RefPtr varLayout) { @@ -2712,7 +2714,7 @@ static void collectSpecializationParams( case SpecializationParam::Flavor::GenericValue: { RefPtr paramLayout = new GenericSpecializationParamLayout(); - paramLayout->decl = specializationParam.object.as(); + paramLayout->decl = as(specializationParam.object); context->shared->programLayout->specializationParams.add(paramLayout); } break; @@ -2721,7 +2723,7 @@ static void collectSpecializationParams( case SpecializationParam::Flavor::ExistentialValue: { RefPtr paramLayout = new ExistentialSpecializationParamLayout(); - paramLayout->type = specializationParam.object.as(); + paramLayout->type = as(specializationParam.object); context->shared->programLayout->specializationParams.add(paramLayout); } break; diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 6fd51bea2..c939e0a38 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -50,11 +50,11 @@ namespace Slang { return find() != nullptr; } - RefPtr getFirst() { return m_result; }; + Modifier* getFirst() { return m_result; }; protected: - RefPtr m_result; - RefPtr* m_next; + Modifier* m_result = nullptr; + Modifier** m_next; }; enum Precedence : int @@ -151,28 +151,28 @@ namespace Slang bool LookAheadToken(TokenType type, int offset = 0); bool LookAheadToken(const char * string, int offset = 0); void parseSourceFile(ModuleDecl* program); - RefPtr ParseStruct(); - RefPtr ParseClass(); - RefPtr ParseStatement(); - RefPtr parseBlockStatement(); - RefPtr parseVarDeclrStatement(Modifiers modifiers); - RefPtr parseIfStatement(); - RefPtr ParseForStatement(); - RefPtr ParseWhileStatement(); - RefPtr ParseDoWhileStatement(); - RefPtr ParseBreakStatement(); - RefPtr ParseContinueStatement(); - RefPtr ParseReturnStatement(); - RefPtr ParseExpressionStatement(); - RefPtr ParseExpression(Precedence level = Precedence::Comma); + Decl* ParseStruct(); + ClassDecl* ParseClass(); + Stmt* ParseStatement(); + Stmt* parseBlockStatement(); + DeclStmt* parseVarDeclrStatement(Modifiers modifiers); + IfStmt* parseIfStatement(); + ForStmt* ParseForStatement(); + WhileStmt* ParseWhileStatement(); + DoWhileStmt* ParseDoWhileStatement(); + BreakStmt* ParseBreakStatement(); + ContinueStmt* ParseContinueStatement(); + ReturnStmt* ParseReturnStatement(); + ExpressionStmt* ParseExpressionStatement(); + Expr* ParseExpression(Precedence level = Precedence::Comma); // Parse an expression that might be used in an initializer or argument context, so we should avoid operator-comma - inline RefPtr ParseInitExpr() { return ParseExpression(Precedence::Assignment); } - inline RefPtr ParseArgExpr() { return ParseExpression(Precedence::Assignment); } + inline Expr* ParseInitExpr() { return ParseExpression(Precedence::Assignment); } + inline Expr* ParseArgExpr() { return ParseExpression(Precedence::Assignment); } - RefPtr ParseLeafExpression(); - RefPtr ParseParameter(); - RefPtr ParseType(); + Expr* ParseLeafExpression(); + ParamDecl* ParseParameter(); + Expr* ParseType(); TypeExp ParseTypeExp(); Parser & operator = (const Parser &) = delete; @@ -191,20 +191,20 @@ namespace Slang Parser* parser, ContainerDecl* parent); - static RefPtr parseEnumDecl(Parser* parser); + static Decl* parseEnumDecl(Parser* parser); - static RefPtr ParseOptSemantics( + static Modifier* ParseOptSemantics( Parser* parser); static void ParseOptSemantics( Parser* parser, Decl* decl); - static RefPtr ParseDecl( + static DeclBase* ParseDecl( Parser* parser, ContainerDecl* containerDecl); - static RefPtr ParseSingleDecl( + static Decl* ParseSingleDecl( Parser* parser, ContainerDecl* containerDecl); @@ -586,9 +586,9 @@ namespace Slang return false; } - RefPtr ParseTypeDef(Parser* parser, void* /*userData*/) + NodeBase* ParseTypeDef(Parser* parser, void* /*userData*/) { - RefPtr typeDefDecl = parser->astBuilder->create(); + TypeDefDecl* typeDefDecl = parser->astBuilder->create(); // TODO(tfoley): parse an actual declarator auto type = parser->ParseTypeExp(); @@ -603,9 +603,9 @@ namespace Slang } // Add a modifier to a list of modifiers being built - static void AddModifier(RefPtr** ioModifierLink, RefPtr modifier) + static void AddModifier(Modifier*** ioModifierLink, Modifier* modifier) { - RefPtr*& modifierLink = *ioModifierLink; + Modifier**& modifierLink = *ioModifierLink; // We'd like to add the modifier to the end of the list, // but we need to be careful, in case there is a "shared" @@ -620,7 +620,7 @@ namespace Slang break; // About to look at shared modifiers? Done. - RefPtr linkMod = *modifierLink; + Modifier* linkMod = *modifierLink; if(as(linkMod)) { break; @@ -648,8 +648,8 @@ namespace Slang } void addModifier( - RefPtr syntax, - RefPtr modifier) + ModifiableSyntaxNode* syntax, + Modifier* modifier) { auto modifierLink = &syntax->modifiers.first; AddModifier(&modifierLink, modifier); @@ -706,7 +706,7 @@ namespace Slang } // Parse HLSL-style `[name(arg, ...)]` style "attribute" modifiers - static void ParseSquareBracketAttributes(Parser* parser, RefPtr** ioModifierLink) + static void ParseSquareBracketAttributes(Parser* parser, Modifier*** ioModifierLink) { parser->ReadToken(TokenType::LBracket); @@ -725,7 +725,7 @@ namespace Slang Token nameToken = parseAttributeName(parser); - RefPtr modifier = parser->astBuilder->create(); + UncheckedAttribute* modifier = parser->astBuilder->create(); modifier->name = nameToken.getName(); modifier->loc = nameToken.getLoc(); modifier->scope = parser->currentScope; @@ -811,7 +811,7 @@ namespace Slang bool tryParseUsingSyntaxDecl( Parser* parser, SyntaxDecl* syntaxDecl, - RefPtr* outSyntax) + T** outSyntax) { if (!syntaxDecl) return false; @@ -822,7 +822,7 @@ namespace Slang // Consume the token that specified the keyword auto keywordToken = advanceToken(parser); - RefPtr parsedObject = syntaxDecl->parseCallback(parser, syntaxDecl->parseUserData); + NodeBase* parsedObject = syntaxDecl->parseCallback(parser, syntaxDecl->parseUserData); if (!parsedObject) { return false; @@ -849,7 +849,7 @@ namespace Slang template bool tryParseUsingSyntaxDecl( Parser* parser, - RefPtr* outSyntax) + T** outSyntax) { if (peekTokenType(parser) != TokenType::Identifier) return false; @@ -868,7 +868,7 @@ namespace Slang static Modifiers ParseModifiers(Parser* parser) { Modifiers modifiers; - RefPtr* modifierLink = &modifiers.first; + Modifier** modifierLink = &modifiers.first; for (;;) { SourceLoc loc = parser->tokenReader.peekLoc(); @@ -887,7 +887,7 @@ namespace Slang Token nameToken = peekToken(parser); - RefPtr parsedModifier; + Modifier* parsedModifier = nullptr; if (tryParseUsingSyntaxDecl(parser, &parsedModifier)) { parsedModifier->name = nameToken.getName(); @@ -926,7 +926,7 @@ namespace Slang } - static RefPtr parseImportDecl( + static NodeBase* parseImportDecl( Parser* parser, void* /*userData*/) { parser->haveSeenAnyImportDecls = true; @@ -1060,30 +1060,30 @@ namespace Slang SourceLoc openBracketLoc; // The expression that yields the element count, or NULL - RefPtr elementCountExpr; + Expr* elementCountExpr = nullptr; }; // "Unwrapped" information about a declarator struct DeclaratorInfo { - RefPtr typeSpec; + Expr* typeSpec = nullptr; NameLoc nameAndLoc; - RefPtr semantics; - RefPtr initializer; + Modifier* semantics = nullptr; + Expr* initializer = nullptr; }; // Add a member declaration to its container, and ensure that its // parent link is set up correctly. - static void AddMember(RefPtr container, RefPtr member) + static void AddMember(ContainerDecl* container, Decl* member) { if (container) { - member->parentDecl = container.Ptr(); + member->parentDecl = container; container->members.add(member); } } - static void AddMember(RefPtr scope, RefPtr member) + static void AddMember(RefPtr scope, Decl* member) { if (scope) { @@ -1091,9 +1091,9 @@ namespace Slang } } - static RefPtr ParseGenericParamDecl( + static Decl* ParseGenericParamDecl( Parser* parser, - RefPtr genericDecl) + GenericDecl* genericDecl) { // simple syntax to introduce a value parameter if (AdvanceIf(parser, "let")) @@ -1114,7 +1114,7 @@ namespace Slang else { // default case is a type parameter - RefPtr paramDecl = parser->astBuilder->create(); + GenericTypeParamDecl* paramDecl = parser->astBuilder->create(); parser->FillPosition(paramDecl); paramDecl->nameAndLoc = NameLoc(parser->ReadToken(TokenType::Identifier)); if (AdvanceIf(parser, TokenType::Colon)) @@ -1178,13 +1178,13 @@ namespace Slang } template - static RefPtr parseOptGenericDecl( + static Decl* parseOptGenericDecl( Parser* parser, const ParseFunc& parseInner) { // TODO: may want more advanced disambiguation than this... if (parser->LookAheadToken(TokenType::OpLess)) { - RefPtr genericDecl = parser->astBuilder->create(); + GenericDecl* genericDecl = parser->astBuilder->create(); parser->FillPosition(genericDecl); parser->PushScope(genericDecl); ParseGenericDeclImpl(parser, genericDecl, parseInner); @@ -1197,19 +1197,19 @@ namespace Slang } } - static RefPtr ParseGenericDecl(Parser* parser, void*) + static NodeBase* ParseGenericDecl(Parser* parser, void*) { - RefPtr decl = parser->astBuilder->create(); - parser->FillPosition(decl.Ptr()); - parser->PushScope(decl.Ptr()); - ParseGenericDeclImpl(parser, decl.Ptr(), [=](GenericDecl* genDecl) {return ParseSingleDecl(parser, genDecl); }); + GenericDecl* decl = parser->astBuilder->create(); + parser->FillPosition(decl); + parser->PushScope(decl); + ParseGenericDeclImpl(parser, decl, [=](GenericDecl* genDecl) {return ParseSingleDecl(parser, genDecl); }); parser->PopScope(); return decl; } static void parseParameterList( Parser* parser, - RefPtr decl) + CallableDecl* decl) { parser->ReadToken(TokenType::LParent); @@ -1270,7 +1270,7 @@ namespace Slang }; /// Parse an optional body statement for a declaration that can have a body. - static RefPtr parseOptBody(Parser* parser) + static Stmt* parseOptBody(Parser* parser) { if (AdvanceIf(parser, TokenType::Semicolon)) { @@ -1284,12 +1284,12 @@ namespace Slang } /// Complete parsing of a function using traditional (C-like) declarator syntax - static RefPtr parseTraditionalFuncDecl( + static Decl* parseTraditionalFuncDecl( Parser* parser, DeclaratorInfo const& declaratorInfo) { - RefPtr decl = parser->astBuilder->create(); - parser->FillPosition(decl.Ptr()); + FuncDecl* decl = parser->astBuilder->create(); + parser->FillPosition(decl); decl->loc = declaratorInfo.nameAndLoc.loc; decl->nameAndLoc = declaratorInfo.nameAndLoc; @@ -1315,7 +1315,7 @@ namespace Slang parser->PushScope(decl); parseParameterList(parser, decl); - ParseOptSemantics(parser, decl.Ptr()); + ParseOptSemantics(parser, decl); decl->body = parseOptBody(parser); parser->PopScope(); @@ -1324,7 +1324,7 @@ namespace Slang }); } - static RefPtr CreateVarDeclForContext( + static VarDeclBase* CreateVarDeclForContext( ASTBuilder* astBuilder, ContainerDecl* containerDecl ) { @@ -1343,12 +1343,12 @@ namespace Slang } // Add modifiers to the end of the modifier list for a declaration - void AddModifiers(Decl* decl, RefPtr modifiers) + void AddModifiers(Decl* decl, Modifier* modifiers) { if (!modifiers) return; - RefPtr* link = &decl->modifiers.first; + Modifier** link = &decl->modifiers.first; while (*link) { link = &(*link)->next; @@ -1371,10 +1371,10 @@ namespace Slang // Set up a variable declaration based on what we saw in its declarator... static void CompleteVarDecl( Parser* parser, - RefPtr decl, + VarDeclBase* decl, DeclaratorInfo const& declaratorInfo) { - parser->FillPosition(decl.Ptr()); + parser->FillPosition(decl); if( !declaratorInfo.nameAndLoc.name ) { @@ -1388,7 +1388,7 @@ namespace Slang } decl->type = TypeExp(declaratorInfo.typeSpec); - AddModifiers(decl.Ptr(), declaratorInfo.semantics); + AddModifiers(decl, declaratorInfo.semantics); decl->initExpr = declaratorInfo.initializer; } @@ -1527,8 +1527,8 @@ namespace Slang struct InitDeclarator { RefPtr declarator; - RefPtr semantics; - RefPtr initializer; + Modifier* semantics = nullptr; + Expr* initializer = nullptr; }; // Parse a declarator plus optional semantics @@ -1619,13 +1619,13 @@ namespace Slang struct DeclGroupBuilder { SourceLoc startPosition; - RefPtr decl; - RefPtr group; + Decl* decl = nullptr; + DeclGroup* group = nullptr; ASTBuilder* astBuilder = nullptr; // Add a new declaration to the potential group void addDecl( - RefPtr newDecl) + Decl* newDecl) { SLANG_ASSERT(newDecl); @@ -1647,7 +1647,7 @@ namespace Slang } } - RefPtr getResult() + DeclBase* getResult() { if(group) return group; return decl; @@ -1655,14 +1655,14 @@ namespace Slang }; // Pares an argument to an application of a generic - RefPtr ParseGenericArg(Parser* parser) + Expr* ParseGenericArg(Parser* parser) { return parser->ParseArgExpr(); } // Create a type expression that will refer to the given declaration - static RefPtr - createDeclRefType(Parser* parser, RefPtr decl) + static Expr* + createDeclRefType(Parser* parser, Decl* decl) { // For now we just construct an expression that // will look up the given declaration by name. @@ -1681,19 +1681,19 @@ namespace Slang struct TypeSpec { // If the type-spec declared something, then put it here - RefPtr decl; + Decl* decl = nullptr; // Put the resulting expression (which should evaluate to a type) here - RefPtr expr; + Expr* expr = nullptr; }; - static RefPtr parseGenericApp( + static Expr* parseGenericApp( Parser* parser, - RefPtr base) + Expr* base) { - RefPtr genericApp = parser->astBuilder->create(); + GenericAppExpr* genericApp = parser->astBuilder->create(); - parser->FillPosition(genericApp.Ptr()); // set up scope for lookup + parser->FillPosition(genericApp); // set up scope for lookup genericApp->functionExpr = base; parser->ReadToken(TokenType::OpLess); parser->genericDepth++; @@ -1730,9 +1730,9 @@ namespace Slang return lookupResult.item.declRef.is(); } - static RefPtr tryParseGenericApp( + static Expr* tryParseGenericApp( Parser* parser, - RefPtr base) + Expr* base) { Name * baseName = nullptr; if (auto varExpr = as(base)) @@ -1748,7 +1748,9 @@ namespace Slang DiagnosticSink newSink(parser->sink->getSourceManager()); Parser newParser(*parser); newParser.sink = &newSink; - auto speculateParseRs = parseGenericApp(&newParser, base); + + /* auto speculateParseRs = */parseGenericApp(&newParser, base); + if (newSink.getErrorCount() == 0) { // disambiguate based on FOLLOW set @@ -1771,27 +1773,27 @@ namespace Slang } return base; } - static RefPtr parseMemberType(Parser * parser, RefPtr base) + static Expr* parseMemberType(Parser * parser, Expr* base) { // When called the :: or . have been consumed, so don't need to consume here. - RefPtr memberExpr = parser->astBuilder->create(); + MemberExpr* memberExpr = parser->astBuilder->create(); - parser->FillPosition(memberExpr.Ptr()); + parser->FillPosition(memberExpr); memberExpr->baseExpression = base; memberExpr->name = expectIdentifier(parser).name; return memberExpr; } // Parse option `[]` braces after a type expression, that indicate an array type - static RefPtr parsePostfixTypeSuffix( + static Expr* parsePostfixTypeSuffix( Parser* parser, - RefPtr inTypeExpr) + Expr* inTypeExpr) { auto typeExpr = inTypeExpr; while (parser->LookAheadToken(TokenType::LBracket)) { - RefPtr arrType = parser->astBuilder->create(); + IndexExpr* arrType = parser->astBuilder->create(); arrType->loc = typeExpr->loc; arrType->baseExpression = typeExpr; parser->ReadToken(TokenType::LBracket); @@ -1805,9 +1807,9 @@ namespace Slang return typeExpr; } - static RefPtr parseTaggedUnionType(Parser* parser) + static Expr* parseTaggedUnionType(Parser* parser) { - RefPtr taggedUnionType = parser->astBuilder->create(); + TaggedUnionTypeExpr* taggedUnionType = parser->astBuilder->create(); parser->ReadToken(TokenType::LParent); while(!AdvanceIfMatch(parser, TokenType::RParent)) @@ -1824,20 +1826,20 @@ namespace Slang return taggedUnionType; } - static RefPtr parseTaggedUnionType(Parser* parser, void* /*unused*/) + static NodeBase* parseTaggedUnionType(Parser* parser, void* /*unused*/) { return parseTaggedUnionType(parser); } /// Parse a `This` type expression - static RefPtr parseThisTypeExpr(Parser* parser) + static Expr* parseThisTypeExpr(Parser* parser) { - RefPtr expr = parser->astBuilder->create(); + ThisTypeExpr* expr = parser->astBuilder->create(); expr->scope = parser->currentScope; return expr; } - static RefPtr parseThisTypeExpr(Parser* parser, void* /*userData*/) + static NodeBase* parseThisTypeExpr(Parser* parser, void* /*userData*/) { return parseThisTypeExpr(parser); } @@ -1909,7 +1911,7 @@ namespace Slang basicType->loc = typeName.loc; basicType->name = typeName.getNameOrNull(); - RefPtr typeExpr = basicType; + Expr* typeExpr = basicType; bool shouldLoop = true; while (shouldLoop) @@ -1936,7 +1938,7 @@ namespace Slang return typeSpec; } - static RefPtr ParseDeclaratorDecl( + static DeclBase* ParseDeclaratorDecl( Parser* parser, ContainerDecl* containerDecl) { @@ -2045,7 +2047,7 @@ namespace Slang { // easy case: we only had a single declaration! UnwrapDeclarator(parser->astBuilder, initDeclarator, &declaratorInfo); - RefPtr firstDecl = CreateVarDeclForContext(parser->astBuilder, containerDecl); + VarDeclBase* firstDecl = CreateVarDeclForContext(parser->astBuilder, containerDecl); CompleteVarDecl(parser, firstDecl, declaratorInfo); declGroupBuilder.addDecl(firstDecl); @@ -2068,7 +2070,7 @@ namespace Slang declaratorInfo.typeSpec = sharedTypeSpec; UnwrapDeclarator(parser->astBuilder, initDeclarator, &declaratorInfo); - RefPtr varDecl = CreateVarDeclForContext(parser->astBuilder, containerDecl); + VarDeclBase* varDecl = CreateVarDeclForContext(parser->astBuilder, containerDecl); CompleteVarDecl(parser, varDecl, declaratorInfo); declGroupBuilder.addDecl(varDecl); @@ -2182,26 +2184,26 @@ namespace Slang // // semantic ::= identifier ( '(' args ')' )? // - static RefPtr ParseSemantic( + static Modifier* ParseSemantic( Parser* parser) { if (parser->LookAheadToken("register")) { - RefPtr semantic = parser->astBuilder->create(); + HLSLRegisterSemantic* semantic = parser->astBuilder->create(); parser->FillPosition(semantic); - parseHLSLRegisterSemantic(parser, semantic.Ptr()); + parseHLSLRegisterSemantic(parser, semantic); return semantic; } else if (parser->LookAheadToken("packoffset")) { - RefPtr semantic = parser->astBuilder->create(); + HLSLPackOffsetSemantic* semantic = parser->astBuilder->create(); parser->FillPosition(semantic); - parseHLSLPackOffsetSemantic(parser, semantic.Ptr()); + parseHLSLPackOffsetSemantic(parser, semantic); return semantic; } else if (parser->LookAheadToken(TokenType::Identifier)) { - RefPtr semantic = parser->astBuilder->create(); + HLSLSimpleSemantic* semantic = parser->astBuilder->create(); parser->FillPosition(semantic); semantic->name = parser->ReadToken(TokenType::Identifier); return semantic; @@ -2217,19 +2219,19 @@ namespace Slang // // opt-semantics ::= (':' semantic)* // - static RefPtr ParseOptSemantics( + static Modifier* ParseOptSemantics( Parser* parser) { if (!AdvanceIf(parser, TokenType::Colon)) return nullptr; - RefPtr result; - RefPtr* link = &result; + Modifier* result = nullptr; + Modifier** link = &result; SLANG_ASSERT(!*link); for (;;) { - RefPtr semantic = ParseSemantic(parser); + Modifier* semantic = ParseSemantic(parser); if (semantic) { *link = semantic; @@ -2268,7 +2270,7 @@ namespace Slang AddModifiers(decl, ParseOptSemantics(parser)); } - static RefPtr ParseHLSLBufferDecl( + static Decl* ParseHLSLBufferDecl( Parser* parser, String bufferWrapperTypeName) { @@ -2291,12 +2293,12 @@ namespace Slang // We are going to represent each buffer as a pair of declarations. // The first is a type declaration that holds all the members, while // the second is a variable declaration that uses the buffer type. - RefPtr bufferDataTypeDecl = parser->astBuilder->create(); - RefPtr bufferVarDecl = parser->astBuilder->create(); + StructDecl* bufferDataTypeDecl = parser->astBuilder->create(); + VarDecl* bufferVarDecl = parser->astBuilder->create(); // Both declarations will have a location that points to the name - parser->FillPosition(bufferDataTypeDecl.Ptr()); - parser->FillPosition(bufferVarDecl.Ptr()); + parser->FillPosition(bufferDataTypeDecl); + parser->FillPosition(bufferVarDecl); auto reflectionNameToken = parser->ReadToken(TokenType::Identifier); @@ -2343,10 +2345,10 @@ namespace Slang // Any semantics applied to the buffer declaration are taken as applying // to the variable instead. - ParseOptSemantics(parser, bufferVarDecl.Ptr()); + ParseOptSemantics(parser, bufferVarDecl); // The declarations in the body belong to the data type. - parseDeclBody(parser, bufferDataTypeDecl.Ptr()); + parseDeclBody(parser, bufferDataTypeDecl); // All HLSL buffer declarations are "transparent" in that their // members are implicitly made visible in the parent scope. @@ -2370,13 +2372,13 @@ namespace Slang return bufferVarDecl; } - static RefPtr parseHLSLCBufferDecl( + static NodeBase* parseHLSLCBufferDecl( Parser* parser, void* /*userData*/) { return ParseHLSLBufferDecl(parser, "ConstantBuffer"); } - static RefPtr parseHLSLTBufferDecl( + static NodeBase* parseHLSLTBufferDecl( Parser* parser, void* /*userData*/) { return ParseHLSLBufferDecl(parser, "TextureBuffer"); @@ -2401,31 +2403,31 @@ namespace Slang } } - static RefPtr ParseExtensionDecl(Parser* parser, void* /*userData*/) + static NodeBase* ParseExtensionDecl(Parser* parser, void* /*userData*/) { - RefPtr decl = parser->astBuilder->create(); - parser->FillPosition(decl.Ptr()); + ExtensionDecl* decl = parser->astBuilder->create(); + parser->FillPosition(decl); decl->targetType = parser->ParseTypeExp(); parseOptionalInheritanceClause(parser, decl); - parseDeclBody(parser, decl.Ptr()); + parseDeclBody(parser, decl); return decl; } - void parseOptionalGenericConstraints(Parser* parser, ContainerDecl* decl) + static void parseOptionalGenericConstraints(Parser* parser, ContainerDecl* decl) { if (AdvanceIf(parser, TokenType::Colon)) { do { - RefPtr paramConstraint = parser->astBuilder->create(); + GenericTypeConstraintDecl* paramConstraint = parser->astBuilder->create(); parser->FillPosition(paramConstraint); // substitution needs to be filled during check - RefPtr paramType = DeclRefType::create(parser->astBuilder, DeclRef(decl, nullptr)); + DeclRefType* paramType = DeclRefType::create(parser->astBuilder, DeclRef(decl, nullptr)); - RefPtr paramTypeExpr = parser->astBuilder->create(); + SharedTypeExpr* paramTypeExpr = parser->astBuilder->create(); paramTypeExpr->loc = decl->loc; paramTypeExpr->base.type = paramType; paramTypeExpr->type = QualType(parser->astBuilder->getTypeType(paramType)); @@ -2438,9 +2440,9 @@ namespace Slang } } - RefPtr parseAssocType(Parser* parser, void *) + static NodeBase* parseAssocType(Parser* parser, void *) { - RefPtr assocTypeDecl = parser->astBuilder->create(); + AssocTypeDecl* assocTypeDecl = parser->astBuilder->create(); auto nameToken = parser->ReadToken(TokenType::Identifier); assocTypeDecl->nameAndLoc = NameLoc(nameToken); @@ -2450,9 +2452,9 @@ namespace Slang return assocTypeDecl; } - RefPtr parseGlobalGenericTypeParamDecl(Parser * parser, void *) + static NodeBase* parseGlobalGenericTypeParamDecl(Parser * parser, void *) { - RefPtr genParamDecl = parser->astBuilder->create(); + GlobalGenericParamDecl* genParamDecl = parser->astBuilder->create(); auto nameToken = parser->ReadToken(TokenType::Identifier); genParamDecl->nameAndLoc = NameLoc(nameToken); genParamDecl->loc = nameToken.loc; @@ -2461,9 +2463,9 @@ namespace Slang return genParamDecl; } - RefPtr parseGlobalGenericValueParamDecl(Parser * parser, void *) + static NodeBase* parseGlobalGenericValueParamDecl(Parser * parser, void *) { - RefPtr genericParamDecl = parser->astBuilder->create(); + GlobalGenericValueParamDecl* genericParamDecl = parser->astBuilder->create(); auto nameToken = parser->ReadToken(TokenType::Identifier); genericParamDecl->nameAndLoc = NameLoc(nameToken); genericParamDecl->loc = nameToken.loc; @@ -2482,20 +2484,20 @@ namespace Slang return genericParamDecl; } - static RefPtr parseInterfaceDecl(Parser* parser, void* /*userData*/) + static NodeBase* parseInterfaceDecl(Parser* parser, void* /*userData*/) { - RefPtr decl = parser->astBuilder->create(); - parser->FillPosition(decl.Ptr()); + InterfaceDecl* decl = parser->astBuilder->create(); + parser->FillPosition(decl); decl->nameAndLoc = NameLoc(parser->ReadToken(TokenType::Identifier)); - parseOptionalInheritanceClause(parser, decl.Ptr()); + parseOptionalInheritanceClause(parser, decl); - parseDeclBody(parser, decl.Ptr()); + parseDeclBody(parser, decl); return decl; } - static RefPtr parseNamespaceDecl(Parser* parser, void* /*userData*/) + static NodeBase* parseNamespaceDecl(Parser* parser, void* /*userData*/) { // We start by parsing the name of the namespace that is being opened. // @@ -2535,8 +2537,8 @@ namespace Slang // a declaration to the caller (since they will try to add // any non-null pointer we return to the AST). // - RefPtr namespaceDecl; - RefPtr result; + NamespaceDecl* namespaceDecl = nullptr; + NodeBase* result = nullptr; // // In order to find out what case we are in, we start by looking // for a namespace declaration of the same name in the parent @@ -2609,15 +2611,15 @@ namespace Slang // `{}`-enclosed body to add declarations as children // of the namespace. // - parseDeclBody(parser, namespaceDecl.Ptr()); + parseDeclBody(parser, namespaceDecl); return result; } - static RefPtr parseConstructorDecl(Parser* parser, void* /*userData*/) + static NodeBase* parseConstructorDecl(Parser* parser, void* /*userData*/) { - RefPtr decl = parser->astBuilder->create(); - parser->FillPosition(decl.Ptr()); + ConstructorDecl* decl = parser->astBuilder->create(); + parser->FillPosition(decl); parser->PushScope(decl); // TODO: we need to make sure that all initializers have @@ -2638,11 +2640,11 @@ namespace Slang return decl; } - static RefPtr parseAccessorDecl(Parser* parser) + static AccessorDecl* parseAccessorDecl(Parser* parser) { Modifiers modifiers = ParseModifiers(parser); - RefPtr decl; + AccessorDecl* decl = nullptr; if( AdvanceIf(parser, "get") ) { decl = parser->astBuilder->create(); @@ -2675,10 +2677,10 @@ namespace Slang return decl; } - static RefPtr ParseSubscriptDecl(Parser* parser, void* /*userData*/) + static NodeBase* ParseSubscriptDecl(Parser* parser, void* /*userData*/) { - RefPtr decl = parser->astBuilder->create(); - parser->FillPosition(decl.Ptr()); + SubscriptDecl* decl = parser->astBuilder->create(); + parser->FillPosition(decl); parser->PushScope(decl); // TODO: the use of this name here is a bit magical... @@ -2718,9 +2720,9 @@ namespace Slang static void parseModernVarDeclBaseCommon( Parser* parser, - RefPtr decl) + VarDeclBase* decl) { - parser->FillPosition(decl.Ptr()); + parser->FillPosition(decl); decl->nameAndLoc = NameLoc(parser->ReadToken(TokenType::Identifier)); if(AdvanceIf(parser, TokenType::Colon)) @@ -2736,32 +2738,32 @@ namespace Slang static void parseModernVarDeclCommon( Parser* parser, - RefPtr decl) + VarDecl* decl) { parseModernVarDeclBaseCommon(parser, decl); expect(parser, TokenType::Semicolon); } - static RefPtr parseLetDecl( + static NodeBase* parseLetDecl( Parser* parser, void* /*userData*/) { - RefPtr decl = parser->astBuilder->create(); + LetDecl* decl = parser->astBuilder->create(); parseModernVarDeclCommon(parser, decl); return decl; } - static RefPtr parseVarDecl( + static NodeBase* parseVarDecl( Parser* parser, void* /*userData*/) { - RefPtr decl = parser->astBuilder->create(); + VarDecl* decl = parser->astBuilder->create(); parseModernVarDeclCommon(parser, decl); return decl; } - static RefPtr parseModernParamDecl( + static ParamDecl* parseModernParamDecl( Parser* parser) { - RefPtr decl = parser->astBuilder->create(); + ParamDecl* decl = parser->astBuilder->create(); // TODO: "modern" parameters should not accept keyword-based // modifiers and should only accept `[attribute]` syntax for @@ -2777,7 +2779,7 @@ namespace Slang static void parseModernParamList( Parser* parser, - RefPtr decl) + CallableDecl* decl) { parser->ReadToken(TokenType::LParent); @@ -2790,17 +2792,17 @@ namespace Slang } } - static RefPtr parseFuncDecl( + static NodeBase* parseFuncDecl( Parser* parser, void* /*userData*/) { - RefPtr decl = parser->astBuilder->create(); + FuncDecl* decl = parser->astBuilder->create(); - parser->FillPosition(decl.Ptr()); + parser->FillPosition(decl); decl->nameAndLoc = NameLoc(parser->ReadToken(TokenType::Identifier)); return parseOptGenericDecl(parser, [&](GenericDecl*) { - parser->PushScope(decl.Ptr()); + parser->PushScope(decl); parseModernParamList(parser, decl); if(AdvanceIf(parser, TokenType::RightArrow)) { @@ -2812,12 +2814,12 @@ namespace Slang }); } - static RefPtr parseTypeAliasDecl( + static NodeBase* parseTypeAliasDecl( Parser* parser, void* /*userData*/) { - RefPtr decl = parser->astBuilder->create(); + TypeAliasDecl* decl = parser->astBuilder->create(); - parser->FillPosition(decl.Ptr()); + parser->FillPosition(decl); decl->nameAndLoc = NameLoc(parser->ReadToken(TokenType::Identifier)); return parseOptGenericDecl(parser, [&](GenericDecl*) @@ -2834,14 +2836,14 @@ namespace Slang // This is a catch-all syntax-construction callback to handle cases where // a piece of syntax is fully defined by the keyword to use, along with // the class of AST node to construct. - static RefPtr parseSimpleSyntax(Parser* parser, void* userData) + static NodeBase* parseSimpleSyntax(Parser* parser, void* userData) { SyntaxClassBase syntaxClass((ReflectClassInfo*) userData); - return (RefObject*) syntaxClass.createInstanceImpl(parser->astBuilder); + return (NodeBase*)syntaxClass.createInstanceImpl(parser->astBuilder); } // Parse a declaration of a keyword that can be used to define further syntax. - static RefPtr parseSyntaxDecl(Parser* parser, void* /*userData*/) + static NodeBase* parseSyntaxDecl(Parser* parser, void* /*userData*/) { // Right now the basic form is: // @@ -2857,7 +2859,7 @@ namespace Slang auto nameAndLoc = expectIdentifier(parser); // Next we look for a clause that specified the AST node class. - SyntaxClass syntaxClass; + SyntaxClass syntaxClass; if (AdvanceIf(parser, TokenType::Colon)) { // User is specifying the class that should be construted @@ -2914,7 +2916,7 @@ namespace Slang // TODO: skip creating the declaration if anything failed, just to not screw things // up for downstream code? - RefPtr syntaxDecl = parser->astBuilder->create(); + SyntaxDecl* syntaxDecl = parser->astBuilder->create(); syntaxDecl->nameAndLoc = nameAndLoc; syntaxDecl->loc = nameAndLoc.loc; syntaxDecl->syntaxClass = syntaxClass; @@ -2928,11 +2930,11 @@ namespace Slang // We are going to use `name: type` syntax just for simplicty, and let the type // be optional, because we don't actually need it in all cases. // - static RefPtr parseAttributeParamDecl(Parser* parser) + static ParamDecl* parseAttributeParamDecl(Parser* parser) { auto nameAndLoc = expectIdentifier(parser); - RefPtr paramDecl = parser->astBuilder->create(); + ParamDecl* paramDecl = parser->astBuilder->create(); paramDecl->nameAndLoc = nameAndLoc; if(AdvanceIf(parser, TokenType::Colon)) @@ -2957,7 +2959,7 @@ namespace Slang // using the default attribute-parsing logic and then all specialized behavior takes // place during semantic checking. // - static RefPtr parseAttributeSyntaxDecl(Parser* parser, void* /*userData*/) + static NodeBase* parseAttributeSyntaxDecl(Parser* parser, void* /*userData*/) { // Right now the basic form is: // @@ -2974,7 +2976,7 @@ namespace Slang // First we parse the attribute name. auto nameAndLoc = expectIdentifier(parser); - RefPtr attrDecl = parser->astBuilder->create(); + AttributeDecl* attrDecl = parser->astBuilder->create(); if(AdvanceIf(parser, TokenType::LParent)) { while(!AdvanceIfMatch(parser, TokenType::RParent)) @@ -2996,7 +2998,7 @@ namespace Slang // on the amount of per-attribute-type logic that has to occur later. // Next we look for a clause that specified the AST node class. - SyntaxClass syntaxClass; + SyntaxClass syntaxClass; if (AdvanceIf(parser, TokenType::Colon)) { // User is specifying the class that should be construted @@ -3027,7 +3029,7 @@ namespace Slang // Finish up work on a declaration that was parsed static void CompleteDecl( Parser* /*parser*/, - RefPtr decl, + Decl* decl, ContainerDecl* containerDecl, Modifiers modifiers) { @@ -3037,10 +3039,10 @@ namespace Slang // We need to be careful, because if `decl` is a generic declaration, // then we really want the modifiers to apply to the inner declaration. // - RefPtr declToModify = decl; + Decl* declToModify = decl; if(auto genericDecl = as(decl)) declToModify = genericDecl->inner; - AddModifiers(declToModify.Ptr(), modifiers.first); + AddModifiers(declToModify, modifiers.first); // Make sure the decl is properly nested inside its lexical parent if (containerDecl) @@ -3049,12 +3051,12 @@ namespace Slang } } - static RefPtr ParseDeclWithModifiers( + static DeclBase* ParseDeclWithModifiers( Parser* parser, ContainerDecl* containerDecl, Modifiers modifiers ) { - RefPtr decl; + DeclBase* decl = nullptr; auto loc = parser->tokenReader.peekLoc(); @@ -3070,7 +3072,7 @@ namespace Slang // First we will check whether we can use the identifier token // as a declaration keyword and parse a declaration using // its associated callback: - RefPtr parsedDecl; + Decl* parsedDecl = nullptr; if (tryParseUsingSyntaxDecl(parser, &parsedDecl)) { decl = parsedDecl; @@ -3129,7 +3131,7 @@ namespace Slang return decl; } - static RefPtr ParseDecl( + static DeclBase* ParseDecl( Parser* parser, ContainerDecl* containerDecl) { @@ -3137,7 +3139,7 @@ namespace Slang return ParseDeclWithModifiers(parser, containerDecl, modifiers); } - static RefPtr ParseSingleDecl( + static Decl* ParseSingleDecl( Parser* parser, ContainerDecl* containerDecl) { @@ -3218,10 +3220,10 @@ namespace Slang currentScope = nullptr; } - RefPtr Parser::ParseStruct() + Decl* Parser::ParseStruct() { - RefPtr rs = astBuilder->create(); - FillPosition(rs.Ptr()); + StructDecl* rs = astBuilder->create(); + FillPosition(rs); ReadToken("struct"); // TODO: support `struct` declaration without tag @@ -3231,28 +3233,28 @@ namespace Slang { // We allow for an inheritance clause on a `struct` // so that it can conform to interfaces. - parseOptionalInheritanceClause(this, rs.Ptr()); - parseDeclBody(this, rs.Ptr()); + parseOptionalInheritanceClause(this, rs); + parseDeclBody(this, rs); return rs; }); } - RefPtr Parser::ParseClass() + ClassDecl* Parser::ParseClass() { - RefPtr rs = astBuilder->create(); - FillPosition(rs.Ptr()); + ClassDecl* rs = astBuilder->create(); + FillPosition(rs); ReadToken("class"); rs->nameAndLoc = expectIdentifier(this); - parseOptionalInheritanceClause(this, rs.Ptr()); + parseOptionalInheritanceClause(this, rs); - parseDeclBody(this, rs.Ptr()); + parseDeclBody(this, rs); return rs; } - static RefPtr parseEnumCaseDecl(Parser* parser) + static EnumCaseDecl* parseEnumCaseDecl(Parser* parser) { - RefPtr decl = parser->astBuilder->create(); + EnumCaseDecl* decl = parser->astBuilder->create(); decl->nameAndLoc = expectIdentifier(parser); if(AdvanceIf(parser, TokenType::OpAssign)) @@ -3263,9 +3265,9 @@ namespace Slang return decl; } - static RefPtr parseEnumDecl(Parser* parser) + static Decl* parseEnumDecl(Parser* parser) { - RefPtr decl = parser->astBuilder->create(); + EnumDecl* decl = parser->astBuilder->create(); parser->FillPosition(decl); parser->ReadToken("enum"); @@ -3288,7 +3290,7 @@ namespace Slang while(!AdvanceIfMatch(parser, TokenType::RBrace)) { - RefPtr caseDecl = parseEnumCaseDecl(parser); + EnumCaseDecl* caseDecl = parseEnumCaseDecl(parser); AddMember(decl, caseDecl); if(AdvanceIf(parser, TokenType::RBrace)) @@ -3300,10 +3302,10 @@ namespace Slang }); } - static RefPtr ParseSwitchStmt(Parser* parser) + static Stmt* ParseSwitchStmt(Parser* parser) { - RefPtr stmt = parser->astBuilder->create(); - parser->FillPosition(stmt.Ptr()); + SwitchStmt* stmt = parser->astBuilder->create(); + parser->FillPosition(stmt); parser->ReadToken("switch"); parser->ReadToken(TokenType::LParent); stmt->condition = parser->ParseExpression(); @@ -3312,20 +3314,20 @@ namespace Slang return stmt; } - static RefPtr ParseCaseStmt(Parser* parser) + static Stmt* ParseCaseStmt(Parser* parser) { - RefPtr stmt = parser->astBuilder->create(); - parser->FillPosition(stmt.Ptr()); + CaseStmt* stmt = parser->astBuilder->create(); + parser->FillPosition(stmt); parser->ReadToken("case"); stmt->expr = parser->ParseExpression(); parser->ReadToken(TokenType::Colon); return stmt; } - static RefPtr ParseDefaultStmt(Parser* parser) + static Stmt* ParseDefaultStmt(Parser* parser) { - RefPtr stmt = parser->astBuilder->create(); - parser->FillPosition(stmt.Ptr()); + DefaultStmt* stmt = parser->astBuilder->create(); + parser->FillPosition(stmt); parser->ReadToken("default"); parser->ReadToken(TokenType::Colon); return stmt; @@ -3365,11 +3367,11 @@ namespace Slang return isTypeName(parser, name); } - RefPtr parseCompileTimeForStmt( + Stmt* parseCompileTimeForStmt( Parser* parser) { - RefPtr scopeDecl = parser->astBuilder->create(); - RefPtr stmt = parser->astBuilder->create(); + ScopeDecl* scopeDecl = parser->astBuilder->create(); + CompileTimeForStmt* stmt = parser->astBuilder->create(); stmt->scopeDecl = scopeDecl; @@ -3377,7 +3379,7 @@ namespace Slang parser->ReadToken(TokenType::LParent); NameLoc varNameAndLoc = expectIdentifier(parser); - RefPtr varDecl = parser->astBuilder->create(); + VarDecl* varDecl = parser->astBuilder->create(); varDecl->nameAndLoc = varNameAndLoc; varDecl->loc = varNameAndLoc.loc; @@ -3387,8 +3389,8 @@ namespace Slang parser->ReadToken("Range"); parser->ReadToken(TokenType::LParent); - RefPtr rangeBeginExpr; - RefPtr rangeEndExpr = parser->ParseArgExpr(); + Expr* rangeBeginExpr = nullptr; + Expr* rangeEndExpr = parser->ParseArgExpr(); if (AdvanceIf(parser, TokenType::Comma)) { rangeBeginExpr = rangeEndExpr; @@ -3411,7 +3413,7 @@ namespace Slang return stmt; } - RefPtr parseCompileTimeStmt( + Stmt* parseCompileTimeStmt( Parser* parser) { parser->ReadToken(TokenType::Dollar); @@ -3426,11 +3428,11 @@ namespace Slang } } - RefPtr Parser::ParseStatement() + Stmt* Parser::ParseStatement() { auto modifiers = ParseModifiers(this); - RefPtr statement; + Stmt* statement = nullptr; if (LookAheadToken(TokenType::LBrace)) statement = parseBlockStatement(); else if (LookAheadToken("if")) @@ -3450,7 +3452,7 @@ namespace Slang else if (LookAheadToken("discard")) { statement = astBuilder->create(); - FillPosition(statement.Ptr()); + FillPosition(statement); ReadToken("discard"); ReadToken(TokenType::Semicolon); } @@ -3492,7 +3494,7 @@ namespace Slang // isn't a keyword should we fall back to the approach // here. // - RefPtr type = ParseType(); + Expr* type = ParseType(); // We don't actually care about the type, though, so // don't retain it @@ -3547,7 +3549,7 @@ namespace Slang else if (LookAheadToken(TokenType::Semicolon)) { statement = astBuilder->create(); - FillPosition(statement.Ptr()); + FillPosition(statement); ReadToken(TokenType::Semicolon); } else @@ -3569,19 +3571,19 @@ namespace Slang return statement; } - RefPtr Parser::parseBlockStatement() + Stmt* Parser::parseBlockStatement() { - RefPtr scopeDecl = astBuilder->create(); - RefPtr blockStatement = astBuilder->create(); + ScopeDecl* scopeDecl = astBuilder->create(); + BlockStmt* blockStatement = astBuilder->create(); blockStatement->scopeDecl = scopeDecl; - pushScopeAndSetParent(scopeDecl.Ptr()); + pushScopeAndSetParent(scopeDecl); ReadToken(TokenType::LBrace); - RefPtr body; + Stmt* body = nullptr; if(!tokenReader.isAtEnd()) { - FillPosition(blockStatement.Ptr()); + FillPosition(blockStatement); } while (!AdvanceIfMatch(this, TokenType::RBrace)) { @@ -3598,7 +3600,7 @@ namespace Slang } else { - RefPtr newBody = astBuilder->create(); + SeqStmt* newBody = astBuilder->create(); newBody->loc = blockStatement->loc; newBody->stmts.add(body); newBody->stmts.add(stmt); @@ -3620,21 +3622,21 @@ namespace Slang return blockStatement; } - RefPtr Parser::parseVarDeclrStatement( + DeclStmt* Parser::parseVarDeclrStatement( Modifiers modifiers) { - RefPtrvarDeclrStatement = astBuilder->create(); + DeclStmt*varDeclrStatement = astBuilder->create(); - FillPosition(varDeclrStatement.Ptr()); + FillPosition(varDeclrStatement); auto decl = ParseDeclWithModifiers(this, currentScope->containerDecl, modifiers); varDeclrStatement->decl = decl; return varDeclrStatement; } - RefPtr Parser::parseIfStatement() + IfStmt* Parser::parseIfStatement() { - RefPtr ifStatement = astBuilder->create(); - FillPosition(ifStatement.Ptr()); + IfStmt* ifStatement = astBuilder->create(); + FillPosition(ifStatement); ReadToken("if"); ReadToken(TokenType::LParent); ifStatement->predicate = ParseExpression(); @@ -3648,9 +3650,9 @@ namespace Slang return ifStatement; } - RefPtr Parser::ParseForStatement() + ForStmt* Parser::ParseForStatement() { - RefPtr scopeDecl = astBuilder->create(); + ScopeDecl* scopeDecl = astBuilder->create(); // HLSL implements the bad approach to scoping a `for` loop // variable, and we want to respect that, but *only* when @@ -3663,7 +3665,7 @@ namespace Slang // case, just so that we can correctly handle it in downstream // logic. // - RefPtr stmt; + ForStmt* stmt = nullptr; if (brokenScoping) { stmt = astBuilder->create(); @@ -3676,8 +3678,8 @@ namespace Slang stmt->scopeDecl = scopeDecl; if(!brokenScoping) - pushScopeAndSetParent(scopeDecl.Ptr()); - FillPosition(stmt.Ptr()); + pushScopeAndSetParent(scopeDecl); + FillPosition(stmt); ReadToken("for"); ReadToken(TokenType::LParent); if (peekTypeName(this)) @@ -3709,10 +3711,10 @@ namespace Slang return stmt; } - RefPtr Parser::ParseWhileStatement() + WhileStmt* Parser::ParseWhileStatement() { - RefPtr whileStatement = astBuilder->create(); - FillPosition(whileStatement.Ptr()); + WhileStmt* whileStatement = astBuilder->create(); + FillPosition(whileStatement); ReadToken("while"); ReadToken(TokenType::LParent); whileStatement->predicate = ParseExpression(); @@ -3721,10 +3723,10 @@ namespace Slang return whileStatement; } - RefPtr Parser::ParseDoWhileStatement() + DoWhileStmt* Parser::ParseDoWhileStatement() { - RefPtr doWhileStatement = astBuilder->create(); - FillPosition(doWhileStatement.Ptr()); + DoWhileStmt* doWhileStatement = astBuilder->create(); + FillPosition(doWhileStatement); ReadToken("do"); doWhileStatement->statement = ParseStatement(); ReadToken("while"); @@ -3735,28 +3737,28 @@ namespace Slang return doWhileStatement; } - RefPtr Parser::ParseBreakStatement() + BreakStmt* Parser::ParseBreakStatement() { - RefPtr breakStatement = astBuilder->create(); - FillPosition(breakStatement.Ptr()); + BreakStmt* breakStatement = astBuilder->create(); + FillPosition(breakStatement); ReadToken("break"); ReadToken(TokenType::Semicolon); return breakStatement; } - RefPtr Parser::ParseContinueStatement() + ContinueStmt* Parser::ParseContinueStatement() { - RefPtr continueStatement = astBuilder->create(); - FillPosition(continueStatement.Ptr()); + ContinueStmt* continueStatement = astBuilder->create(); + FillPosition(continueStatement); ReadToken("continue"); ReadToken(TokenType::Semicolon); return continueStatement; } - RefPtr Parser::ParseReturnStatement() + ReturnStmt* Parser::ParseReturnStatement() { - RefPtr returnStatement = astBuilder->create(); - FillPosition(returnStatement.Ptr()); + ReturnStmt* returnStatement = astBuilder->create(); + FillPosition(returnStatement); ReadToken("return"); if (!LookAheadToken(TokenType::Semicolon)) returnStatement->expression = ParseExpression(); @@ -3764,20 +3766,20 @@ namespace Slang return returnStatement; } - RefPtr Parser::ParseExpressionStatement() + ExpressionStmt* Parser::ParseExpressionStatement() { - RefPtr statement = astBuilder->create(); + ExpressionStmt* statement = astBuilder->create(); - FillPosition(statement.Ptr()); + FillPosition(statement); statement->expression = ParseExpression(); ReadToken(TokenType::Semicolon); return statement; } - RefPtr Parser::ParseParameter() + ParamDecl* Parser::ParseParameter() { - RefPtr parameter = astBuilder->create(); + ParamDecl* parameter = astBuilder->create(); parameter->modifiers = ParseModifiers(this); DeclaratorInfo declaratorInfo; @@ -3791,7 +3793,7 @@ namespace Slang return parameter; } - RefPtr Parser::ParseType() + Expr* Parser::ParseType() { auto typeSpec = parseTypeSpec(this); if( typeSpec.decl ) @@ -3889,7 +3891,7 @@ namespace Slang } } - static RefPtr parseOperator(Parser* parser) + static Expr* parseOperator(Parser* parser) { Token opToken; switch(parser->tokenReader.peekTokenType()) @@ -3913,13 +3915,13 @@ namespace Slang } - static RefPtr createInfixExpr( + static Expr* createInfixExpr( Parser* parser, - RefPtr left, - RefPtr op, - RefPtr right) + Expr* left, + Expr* op, + Expr* right) { - RefPtr expr = parser->astBuilder->create(); + InfixExpr* expr = parser->astBuilder->create(); expr->loc = op->loc; expr->functionExpr = op; expr->arguments.add(left); @@ -3927,9 +3929,9 @@ namespace Slang return expr; } - static RefPtr parseInfixExprWithPrecedence( + static Expr* parseInfixExprWithPrecedence( Parser* parser, - RefPtr inExpr, + Expr* inExpr, Precedence prec) { auto expr = inExpr; @@ -3946,7 +3948,7 @@ namespace Slang // one non-binary case we need to deal with. if(opTokenType == TokenType::QuestionMark) { - RefPtr select = parser->astBuilder->create(); + SelectExpr* select = parser->astBuilder->create(); select->loc = op->loc; select->functionExpr = op; @@ -3974,7 +3976,7 @@ namespace Slang if (opTokenType == TokenType::OpAssign) { - RefPtr assignExpr = parser->astBuilder->create(); + AssignExpr* assignExpr = parser->astBuilder->create(); assignExpr->loc = op->loc; assignExpr->left = expr; assignExpr->right = right; @@ -3989,7 +3991,7 @@ namespace Slang return expr; } - RefPtr Parser::ParseExpression(Precedence level) + Expr* Parser::ParseExpression(Precedence level) { auto expr = ParseLeafExpression(); return parseInfixExprWithPrecedence(this, expr, level); @@ -4004,7 +4006,7 @@ namespace Slang auto condition = ParseExpression(Precedence(level + 1)); if (LookAheadToken(TokenType::QuestionMark)) { - RefPtr select = new SelectExpr(); + SelectExpr* select = new SelectExpr(); FillPosition(select.Ptr()); select->Arguments.Add(condition); @@ -4026,7 +4028,7 @@ namespace Slang auto left = ParseExpression(Precedence(level + 1)); while (GetOpLevel(this, tokenReader.PeekTokenType()) == level) { - RefPtr tmp = new InfixExpr(); + OperatorExpr* tmp = new InfixExpr(); tmp->FunctionExpr = parseOperator(this); tmp->Arguments.Add(left); @@ -4041,7 +4043,7 @@ namespace Slang auto left = ParseExpression(Precedence(level + 1)); if (GetOpLevel(this, tokenReader.PeekTokenType()) == level) { - RefPtr tmp = new InfixExpr(); + OperatorExpr* tmp = new InfixExpr(); tmp->Arguments.Add(left); FillPosition(tmp.Ptr()); tmp->FunctionExpr = parseOperator(this); @@ -4056,40 +4058,40 @@ namespace Slang // We *might* be looking at an application of a generic to arguments, // but we need to disambiguate to make sure. - static RefPtr maybeParseGenericApp( + static Expr* maybeParseGenericApp( Parser* parser, // TODO: need to support more general expressions here - RefPtr base) + Expr* base) { if(peekTokenType(parser) != TokenType::OpLess) return base; return tryParseGenericApp(parser, base); } - static RefPtr parsePrefixExpr(Parser* parser); + static Expr* parsePrefixExpr(Parser* parser); // Parse OOP `this` expression syntax - static RefPtr parseThisExpr(Parser* parser, void* /*userData*/) + static NodeBase* parseThisExpr(Parser* parser, void* /*userData*/) { - RefPtr expr = parser->astBuilder->create(); + ThisExpr* expr = parser->astBuilder->create(); expr->scope = parser->currentScope; return expr; } - static RefPtr parseBoolLitExpr(Parser* parser, bool value) + static Expr* parseBoolLitExpr(Parser* parser, bool value) { - RefPtr expr = parser->astBuilder->create(); + BoolLiteralExpr* expr = parser->astBuilder->create(); expr->value = value; return expr; } - static RefPtr parseTrueExpr(Parser* parser, void* /*userData*/) + static NodeBase* parseTrueExpr(Parser* parser, void* /*userData*/) { return parseBoolLitExpr(parser, true); } - static RefPtr parseFalseExpr(Parser* parser, void* /*userData*/) + static NodeBase* parseFalseExpr(Parser* parser, void* /*userData*/) { return parseBoolLitExpr(parser, false); } @@ -4261,7 +4263,7 @@ namespace Slang return value; } - static RefPtr parseAtomicExpr(Parser* parser) + static Expr* parseAtomicExpr(Parser* parser) { switch( peekTokenType(parser) ) { @@ -4283,8 +4285,8 @@ namespace Slang if (peekTypeName(parser) && parser->LookAheadToken(TokenType::RParent, 1)) { - RefPtr tcexpr = parser->astBuilder->create(); - parser->FillPosition(tcexpr.Ptr()); + TypeCastExpr* tcexpr = parser->astBuilder->create(); + parser->FillPosition(tcexpr); tcexpr->functionExpr = parser->ParseType(); parser->ReadToken(TokenType::RParent); @@ -4295,10 +4297,10 @@ namespace Slang } else { - RefPtr base = parser->ParseExpression(); + Expr* base = parser->ParseExpression(); parser->ReadToken(TokenType::RParent); - RefPtr parenExpr = parser->astBuilder->create(); + ParenExpr* parenExpr = parser->astBuilder->create(); parenExpr->loc = openParen.loc; parenExpr->base = base; return parenExpr; @@ -4308,13 +4310,13 @@ namespace Slang // An initializer list `{ expr, ... }` case TokenType::LBrace: { - RefPtr initExpr = parser->astBuilder->create(); - parser->FillPosition(initExpr.Ptr()); + InitializerListExpr* initExpr = parser->astBuilder->create(); + parser->FillPosition(initExpr); // Initializer list parser->ReadToken(TokenType::LBrace); - List> exprs; + List exprs; for(;;) { @@ -4338,8 +4340,8 @@ namespace Slang case TokenType::IntegerLiteral: { - RefPtr constExpr = parser->astBuilder->create(); - parser->FillPosition(constExpr.Ptr()); + IntegerLiteralExpr* constExpr = parser->astBuilder->create(); + parser->FillPosition(constExpr); auto token = parser->tokenReader.advanceToken(); constExpr->token = token; @@ -4427,8 +4429,8 @@ namespace Slang case TokenType::FloatingPointLiteral: { - RefPtr constExpr = parser->astBuilder->create(); - parser->FillPosition(constExpr.Ptr()); + FloatingPointLiteralExpr* constExpr = parser->astBuilder->create(); + parser->FillPosition(constExpr); auto token = parser->tokenReader.advanceToken(); constExpr->token = token; @@ -4541,10 +4543,10 @@ namespace Slang case TokenType::StringLiteral: { - RefPtr constExpr = parser->astBuilder->create(); + StringLiteralExpr* constExpr = parser->astBuilder->create(); auto token = parser->tokenReader.advanceToken(); constExpr->token = token; - parser->FillPosition(constExpr.Ptr()); + parser->FillPosition(constExpr); if (!parser->LookAheadToken(TokenType::StringLiteral)) { @@ -4572,7 +4574,7 @@ namespace Slang // keywords registered for use as expressions. Token nameToken = peekToken(parser); - RefPtr parsedExpr; + Expr* parsedExpr = nullptr; if (tryParseUsingSyntaxDecl(parser, &parsedExpr)) { if (!parsedExpr->loc.isValid()) @@ -4583,9 +4585,9 @@ namespace Slang } // Default behavior is just to create a name expression - RefPtr varExpr = parser->astBuilder->create(); - varExpr->scope = parser->currentScope.Ptr(); - parser->FillPosition(varExpr.Ptr()); + VarExpr* varExpr = parser->astBuilder->create(); + varExpr->scope = parser->currentScope; + parser->FillPosition(varExpr); auto nameAndLoc = expectIdentifier(parser); varExpr->name = nameAndLoc.name; @@ -4600,7 +4602,7 @@ namespace Slang } } - static RefPtr parsePostfixExpr(Parser* parser) + static Expr* parsePostfixExpr(Parser* parser) { auto expr = parseAtomicExpr(parser); for(;;) @@ -4614,8 +4616,8 @@ namespace Slang case TokenType::OpInc: case TokenType::OpDec: { - RefPtr postfixExpr = parser->astBuilder->create(); - parser->FillPosition(postfixExpr.Ptr()); + OperatorExpr* postfixExpr = parser->astBuilder->create(); + parser->FillPosition(postfixExpr); postfixExpr->functionExpr = parseOperator(parser); postfixExpr->arguments.add(expr); @@ -4626,9 +4628,9 @@ namespace Slang // Subscript operation `a[i]` case TokenType::LBracket: { - RefPtr indexExpr = parser->astBuilder->create(); + IndexExpr* indexExpr = parser->astBuilder->create(); indexExpr->baseExpression = expr; - parser->FillPosition(indexExpr.Ptr()); + parser->FillPosition(indexExpr); parser->ReadToken(TokenType::LBracket); // TODO: eventually we may want to support multiple arguments inside the `[]` if (!parser->LookAheadToken(TokenType::RBracket)) @@ -4644,9 +4646,9 @@ namespace Slang // Call oepration `f(x)` case TokenType::LParent: { - RefPtr invokeExpr = parser->astBuilder->create(); + InvokeExpr* invokeExpr = parser->astBuilder->create(); invokeExpr->functionExpr = expr; - parser->FillPosition(invokeExpr.Ptr()); + parser->FillPosition(invokeExpr); parser->ReadToken(TokenType::LParent); while (!parser->tokenReader.isAtEnd()) { @@ -4669,12 +4671,12 @@ namespace Slang // Scope access `x::m` case TokenType::Scope: { - RefPtr staticMemberExpr = parser->astBuilder->create(); + StaticMemberExpr* staticMemberExpr = parser->astBuilder->create(); // TODO(tfoley): why would a member expression need this? - staticMemberExpr->scope = parser->currentScope.Ptr(); + staticMemberExpr->scope = parser->currentScope; - parser->FillPosition(staticMemberExpr.Ptr()); + parser->FillPosition(staticMemberExpr); staticMemberExpr->baseExpression = expr; parser->ReadToken(TokenType::Scope); staticMemberExpr->name = expectIdentifier(parser).name; @@ -4689,12 +4691,12 @@ namespace Slang // Member access `x.m` case TokenType::Dot: { - RefPtr memberExpr = parser->astBuilder->create(); + MemberExpr* memberExpr = parser->astBuilder->create(); // TODO(tfoley): why would a member expression need this? memberExpr->scope = parser->currentScope.Ptr(); - parser->FillPosition(memberExpr.Ptr()); + parser->FillPosition(memberExpr); memberExpr->baseExpression = expr; parser->ReadToken(TokenType::Dot); memberExpr->name = expectIdentifier(parser).name; @@ -4738,7 +4740,7 @@ namespace Slang } } - static RefPtr parsePrefixExpr(Parser* parser) + static Expr* parsePrefixExpr(Parser* parser) { auto tokenType = peekTokenType(parser); switch( tokenType ) @@ -4750,8 +4752,8 @@ namespace Slang case TokenType::OpInc: case TokenType::OpDec: { - RefPtr prefixExpr = parser->astBuilder->create(); - parser->FillPosition(prefixExpr.Ptr()); + PrefixExpr* prefixExpr = parser->astBuilder->create(); + parser->FillPosition(prefixExpr); prefixExpr->functionExpr = parseOperator(parser); auto arg = parsePrefixExpr(parser); @@ -4763,15 +4765,15 @@ namespace Slang case TokenType::OpAdd: case TokenType::OpSub: { - RefPtr prefixExpr = parser->astBuilder->create(); - parser->FillPosition(prefixExpr.Ptr()); + PrefixExpr* prefixExpr = parser->astBuilder->create(); + parser->FillPosition(prefixExpr); prefixExpr->functionExpr = parseOperator(parser); auto arg = parsePrefixExpr(parser); if (auto intLit = as(arg)) { - RefPtr newLiteral = parser->astBuilder->create(*intLit); + IntegerLiteralExpr* newLiteral = parser->astBuilder->create(*intLit); IRIntegerValue value = _foldIntegerPrefixOp(tokenType, newLiteral->value); @@ -4786,7 +4788,7 @@ namespace Slang } else if (auto floatLit = as(arg)) { - RefPtr newLiteral = parser->astBuilder->create(*floatLit); + FloatingPointLiteralExpr* newLiteral = parser->astBuilder->create(*floatLit); newLiteral->value = _foldFloatPrefixOp(tokenType, floatLit->value); return newLiteral; } @@ -4799,12 +4801,12 @@ namespace Slang } } - RefPtr Parser::ParseLeafExpression() + Expr* Parser::ParseLeafExpression() { return parsePrefixExpr(this); } - RefPtr parseTermFromSourceFile( + Expr* parseTermFromSourceFile( ASTBuilder* astBuilder, TokenSpan const& tokens, DiagnosticSink* sink, @@ -4840,13 +4842,13 @@ namespace Slang char const* nameText, SyntaxParseCallback callback, void* userData, - SyntaxClass syntaxClass) + SyntaxClass syntaxClass) { Name* name = session->getNamePool()->getName(nameText); ASTBuilder* globalASTBuilder = session->getGlobalASTBuilder(); - RefPtr syntaxDecl = globalASTBuilder->create(); + SyntaxDecl* syntaxDecl = globalASTBuilder->create(); syntaxDecl->nameAndLoc = NameLoc(name); syntaxDecl->syntaxClass = syntaxClass; syntaxDecl->parseCallback = callback; @@ -4876,9 +4878,9 @@ namespace Slang addBuiltinSyntaxImpl(session, scope, name, &parseSimpleSyntax, (void*) syntaxClass.classInfo, getClass()); } - static RefPtr parseIntrinsicOpModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseIntrinsicOpModifier(Parser* parser, void* /*userData*/) { - RefPtr modifier = parser->astBuilder->create(); + IntrinsicOpModifier* modifier = parser->astBuilder->create(); // We allow a few difference forms here: // @@ -4924,7 +4926,7 @@ namespace Slang return modifier; } - static RefPtr parseTargetIntrinsicModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseTargetIntrinsicModifier(Parser* parser, void* /*userData*/) { auto modifier = parser->astBuilder->create(); @@ -4950,7 +4952,7 @@ namespace Slang return modifier; } - static RefPtr parseSpecializedForTargetModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseSpecializedForTargetModifier(Parser* parser, void* /*userData*/) { auto modifier = parser->astBuilder->create(); if (AdvanceIf(parser, TokenType::LParent)) @@ -4961,7 +4963,7 @@ namespace Slang return modifier; } - static RefPtr parseGLSLExtensionModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseGLSLExtensionModifier(Parser* parser, void* /*userData*/) { auto modifier = parser->astBuilder->create(); @@ -4972,7 +4974,7 @@ namespace Slang return modifier; } - static RefPtr parseGLSLVersionModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseGLSLVersionModifier(Parser* parser, void* /*userData*/) { auto modifier = parser->astBuilder->create(); @@ -5013,7 +5015,7 @@ namespace Slang return SemanticVersion::parse(content, outVersion); } - static RefPtr parseSPIRVVersionModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseSPIRVVersionModifier(Parser* parser, void* /*userData*/) { Token token; SemanticVersion version; @@ -5024,10 +5026,10 @@ namespace Slang return modifier; } parser->sink->diagnose(token, Diagnostics::invalidSPIRVVersion); - return RefPtr(); + return nullptr; } - static RefPtr parseCUDASMVersionModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseCUDASMVersionModifier(Parser* parser, void* /*userData*/) { Token token; SemanticVersion version; @@ -5038,14 +5040,14 @@ namespace Slang return modifier; } parser->sink->diagnose(token, Diagnostics::invalidCUDASMVersion); - return RefPtr(); + return nullptr; } - static RefPtr parseLayoutModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseLayoutModifier(Parser* parser, void* /*userData*/) { ModifierListBuilder listBuilder; - RefPtr numThreadsAttrib; + UncheckedAttribute* numThreadsAttrib = nullptr; listBuilder.add(parser->astBuilder->create()); @@ -5121,7 +5123,7 @@ namespace Slang } else { - RefPtr modifier; + Modifier* modifier = nullptr; #define CASE(key, type) if (nameText == #key) { modifier = parser->astBuilder->create(); } else CASE(push_constant, PushConstantAttribute) @@ -5164,9 +5166,9 @@ namespace Slang return listBuilder.getFirst(); } - static RefPtr parseBuiltinTypeModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseBuiltinTypeModifier(Parser* parser, void* /*userData*/) { - RefPtr modifier = parser->astBuilder->create(); + BuiltinTypeModifier* modifier = parser->astBuilder->create(); parser->ReadToken(TokenType::LParent); modifier->tag = BaseType(StringToInt(parser->ReadToken(TokenType::IntegerLiteral).getContent())); parser->ReadToken(TokenType::RParent); @@ -5174,9 +5176,9 @@ namespace Slang return modifier; } - static RefPtr parseMagicTypeModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseMagicTypeModifier(Parser* parser, void* /*userData*/) { - RefPtr modifier = parser->astBuilder->create(); + MagicTypeModifier* modifier = parser->astBuilder->create(); parser->ReadToken(TokenType::LParent); modifier->name = parser->ReadToken(TokenType::Identifier).getContent(); if (AdvanceIf(parser, TokenType::Comma)) @@ -5188,9 +5190,9 @@ namespace Slang return modifier; } - static RefPtr parseIntrinsicTypeModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseIntrinsicTypeModifier(Parser* parser, void* /*userData*/) { - RefPtr modifier = parser->astBuilder->create(); + IntrinsicTypeModifier* modifier = parser->astBuilder->create(); parser->ReadToken(TokenType::LParent); modifier->irOp = uint32_t(StringToInt(parser->ReadToken(TokenType::IntegerLiteral).getContent())); while( AdvanceIf(parser, TokenType::Comma) ) @@ -5202,9 +5204,9 @@ namespace Slang return modifier; } - static RefPtr parseImplicitConversionModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseImplicitConversionModifier(Parser* parser, void* /*userData*/) { - RefPtr modifier = parser->astBuilder->create(); + ImplicitConversionModifier* modifier = parser->astBuilder->create(); ConversionCost cost = kConversionCost_Default; if( AdvanceIf(parser, TokenType::LParent) ) @@ -5216,7 +5218,7 @@ namespace Slang return modifier; } - static RefPtr parseAttributeTargetModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseAttributeTargetModifier(Parser* parser, void* /*userData*/) { expect(parser, TokenType::LParent); auto syntaxClassNameAndLoc = expectIdentifier(parser); @@ -5224,19 +5226,19 @@ namespace Slang auto syntaxClass = parser->astBuilder->findSyntaxClass(syntaxClassNameAndLoc.name); - RefPtr modifier = parser->astBuilder->create(); + AttributeTargetModifier* modifier = parser->astBuilder->create(); modifier->syntaxClass = syntaxClass; return modifier; } - RefPtr populateBaseLanguageModule( + ModuleDecl* populateBaseLanguageModule( ASTBuilder* astBuilder, RefPtr scope) { Session* session = astBuilder->getGlobalSession(); - RefPtr moduleDecl = astBuilder->create(); + ModuleDecl* moduleDecl = astBuilder->create(); scope->containerDecl = moduleDecl; // Add syntax for declaration keywords diff --git a/source/slang/slang-parser.h b/source/slang/slang-parser.h index f3587793e..bcc0fb6e9 100644 --- a/source/slang/slang-parser.h +++ b/source/slang/slang-parser.h @@ -15,7 +15,7 @@ namespace Slang DiagnosticSink* sink, RefPtr const& outerScope); - RefPtr parseTermFromSourceFile( + Expr* parseTermFromSourceFile( ASTBuilder* astBuilder, TokenSpan const& tokens, DiagnosticSink* sink, @@ -23,7 +23,7 @@ namespace Slang NamePool* namePool, SourceLanguage sourceLanguage); - RefPtr populateBaseLanguageModule( + ModuleDecl* populateBaseLanguageModule( ASTBuilder* astBuilder, RefPtr scope); } diff --git a/source/slang/slang-reflection.cpp b/source/slang/slang-reflection.cpp index 23831d498..c1e533140 100644 --- a/source/slang/slang-reflection.cpp +++ b/source/slang/slang-reflection.cpp @@ -148,14 +148,14 @@ SlangReflectionType* spReflectionUserAttribute_GetArgumentType(SlangReflectionUs { auto userAttr = convert(attrib); if (!userAttr) return nullptr; - return convert(userAttr->args[index]->type.type.Ptr()); + return convert(userAttr->args[index]->type.type); } SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueInt(SlangReflectionUserAttribute* attrib, unsigned int index, int * rs) { auto userAttr = convert(attrib); if (!userAttr) return SLANG_ERROR_INVALID_PARAMETER; if (index >= (unsigned int)userAttr->args.getCount()) return SLANG_ERROR_INVALID_PARAMETER; - RefPtr val; + NodeBase* val = nullptr; if (userAttr->intArgVals.TryGetValue(index, val)) { *rs = (int)as(val)->value; @@ -356,15 +356,15 @@ SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionTy if(auto arrayType = as(type)) { - return (SlangReflectionType*) arrayType->baseType.Ptr(); + return (SlangReflectionType*) arrayType->baseType; } else if( auto parameterGroupType = as(type)) { - return convert(parameterGroupType->elementType.Ptr()); + return convert(parameterGroupType->elementType); } else if( auto vectorType = as(type)) { - return convert(vectorType->elementType.Ptr()); + return convert(vectorType->elementType); } else if( auto matrixType = as(type)) { @@ -427,7 +427,7 @@ SLANG_API SlangScalarType spReflectionType_GetScalarType(SlangReflectionType* in } else if(auto vectorType = as(type)) { - type = vectorType->elementType.Ptr(); + type = vectorType->elementType; } if(auto basicType = as(type)) @@ -504,7 +504,7 @@ SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionTy while(auto arrayType = as(type)) { - type = arrayType->baseType.Ptr(); + type = arrayType->baseType; } if(auto textureType = as(type)) @@ -540,7 +540,7 @@ SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflection while(auto arrayType = as(type)) { - type = arrayType->baseType.Ptr(); + type = arrayType->baseType; } if(auto textureType = as(type)) @@ -604,8 +604,8 @@ SLANG_API SlangReflectionType * spReflection_FindTypeByName(SlangReflection * re try { - RefPtr result = program->getTypeFromString(name, &sink); - return (SlangReflectionType*)result.Ptr(); + Type* result = program->getTypeFromString(name, &sink); + return (SlangReflectionType*)result; } catch( ... ) { @@ -633,18 +633,18 @@ SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangRefle while(auto arrayType = as(type)) { - type = arrayType->baseType.Ptr(); + type = arrayType->baseType; } if (auto textureType = as(type)) { - return convert(textureType->elementType.Ptr()); + return convert(textureType->elementType); } // TODO: need a better way to handle this stuff... #define CASE(TYPE, SHAPE, ACCESS) \ else if(as(type)) do { \ - return convert(as(type)->elementType.Ptr()); \ + return convert(as(type)->elementType); \ } while(0) // TODO: structured buffer needs to expose type layout! @@ -666,7 +666,7 @@ SLANG_API SlangReflectionType* spReflectionTypeLayout_GetType(SlangReflectionTyp auto typeLayout = convert(inTypeLayout); if(!typeLayout) return nullptr; - return (SlangReflectionType*) typeLayout->type.Ptr(); + return (SlangReflectionType*) typeLayout->type; } namespace diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index c78de91a5..06603547f 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -54,7 +54,7 @@ SourceLoc const& getDiagnosticPos(TypeExp const& typeExp) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Free functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -const RefPtr* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end) +Decl*const* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { switch (filterStyle) { @@ -99,7 +99,7 @@ const RefPtr* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, Memb return end; } -const RefPtr* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end, Index index) +Decl*const* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end, Index index) { switch (filterStyle) { @@ -156,7 +156,7 @@ const RefPtr* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, return nullptr; } -Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr* ptr, const RefPtr* end) +Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { Index count = 0; switch (filterStyle) @@ -204,9 +204,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // RequirementWitness // - RequirementWitness::RequirementWitness(RefPtr val) + RequirementWitness::RequirementWitness(Val* val) : m_flavor(Flavor::val) - , m_obj(val) + , m_val(val) {} @@ -324,17 +324,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt - static RefPtr ExtractGenericArgType(RefPtr val) + static Type* ExtractGenericArgType(Val* val) { - auto type = val.as(); - SLANG_RELEASE_ASSERT(type.Ptr()); + auto type = as(val); + SLANG_RELEASE_ASSERT(type); return type; } - static RefPtr ExtractGenericArgInteger(RefPtr val) + static IntVal* ExtractGenericArgInteger(Val* val) { - auto intVal = val.as(); - SLANG_RELEASE_ASSERT(intVal.Ptr()); + auto intVal = as(val); + SLANG_RELEASE_ASSERT(intVal); return intVal; } @@ -359,30 +359,30 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // We are going to build up a list of substitutions that need // to be applied to the decl-ref to make it specialized. - RefPtr substsToApply; - RefPtr* link = &substsToApply; + Substitutions* substsToApply = nullptr; + Substitutions** link = &substsToApply; - RefPtr dd = declRef.getDecl(); + Decl* dd = declRef.getDecl(); for(;;) { - RefPtr childDecl = dd; - RefPtr parentDecl = dd->parentDecl; + Decl* childDecl = dd; + Decl* parentDecl = dd->parentDecl; if(!parentDecl) break; dd = parentDecl; - if(auto genericParentDecl = parentDecl.as()) + if(auto genericParentDecl = as(parentDecl)) { // Don't specialize any parameters of a generic. if(childDecl != genericParentDecl->inner) break; // We have a generic ancestor, but do we have an substitutions for it? - RefPtr foundSubst; + GenericSubstitution* foundSubst = nullptr; for(auto s = declRef.substitutions.substitutions; s; s = s->outer) { - auto genSubst = s.as(); + auto genSubst = as(s); if(!genSubst) continue; @@ -397,7 +397,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(!foundSubst) { - RefPtr newSubst = createDefaultSubstitutionsForGeneric( + Substitutions* newSubst = createDefaultSubstitutionsForGeneric( astBuilder, genericParentDecl, nullptr); @@ -417,7 +417,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // TODO: need to figure out how to unify this with the logic // in the generic case... - RefPtr DeclRefType::create( + DeclRefType* DeclRefType::create( ASTBuilder* astBuilder, DeclRef declRef) { @@ -434,7 +434,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt GenericSubstitution* subst = nullptr; for(auto s = declRef.substitutions.substitutions; s; s = s->outer) { - if(auto genericSubst = s.as()) + if(auto genericSubst = as(s)) { subst = genericSubst; break; @@ -561,7 +561,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt SLANG_UNEXPECTED("unhandled type"); } - RefPtr type = classInfo.createInstance(astBuilder); + NodeBase* type = classInfo.createInstance(astBuilder); if (!type) { SLANG_UNEXPECTED("constructor failure"); @@ -584,9 +584,9 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // - RefPtr findInnerMostGenericSubstitution(Substitutions* subst) + GenericSubstitution* findInnerMostGenericSubstitution(Substitutions* subst) { - for(RefPtr s = subst; s; s = s->outer) + for(Substitutions* s = subst; s; s = s->outer) { if(auto genericSubst = as(s)) return genericSubst; @@ -597,7 +597,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // DeclRefBase - RefPtr DeclRefBase::substitute(ASTBuilder* astBuilder, RefPtr type) const + Type* DeclRefBase::substitute(ASTBuilder* astBuilder, Type* type) const { // Note that type can be nullptr, and so this function can return nullptr (although only correctly when no substitutions) @@ -609,7 +609,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Otherwise we need to recurse on the type structure // and apply substitutions where it makes sense - return type->substitute(astBuilder, substitutions).as(); + return Slang::as(type->substitute(astBuilder, substitutions)); } DeclRefBase DeclRefBase::substitute(ASTBuilder* astBuilder, DeclRefBase declRef) const @@ -621,7 +621,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return declRef.substituteImpl(astBuilder, substitutions, &diff); } - RefPtr DeclRefBase::substitute(ASTBuilder* /* astBuilder*/, RefPtr expr) const + Expr* DeclRefBase::substitute(ASTBuilder* /* astBuilder*/, Expr* expr) const { // No substitutions? Easy. if (!substitutions) @@ -647,13 +647,13 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return nullptr; } - RefPtr findGlobalGenericSubst( - RefPtr substs, + GlobalGenericParamSubstitution* findGlobalGenericSubst( + Substitutions* substs, GlobalGenericParamDecl* paramDecl) { for(auto s = substs; s; s = s->outer) { - auto gSubst = s.as(); + auto gSubst = as(s); if(!gSubst) continue; @@ -666,22 +666,22 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return nullptr; } - RefPtr specializeSubstitutionsShallow( + Substitutions* specializeSubstitutionsShallow( ASTBuilder* astBuilder, - RefPtr substToSpecialize, - RefPtr substsToApply, - RefPtr restSubst, + Substitutions* substToSpecialize, + Substitutions* substsToApply, + Substitutions* restSubst, int* ioDiff) { SLANG_ASSERT(substToSpecialize); return substToSpecialize->applySubstitutionsShallow(astBuilder, substsToApply, restSubst, ioDiff); } - RefPtr specializeGlobalGenericSubstitutions( + Substitutions* specializeGlobalGenericSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr substsToSpecialize, - RefPtr substsToApply, + Substitutions* substsToSpecialize, + Substitutions* substsToApply, int* ioDiff, HashSet& ioParametersFound) { @@ -689,7 +689,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // a recursive case that skips the rest of the function. for(auto specSubst = substsToSpecialize; specSubst; specSubst = specSubst->outer) { - auto specGlobalGenericSubst = specSubst.as(); + auto specGlobalGenericSubst = as(specSubst); if(!specGlobalGenericSubst) continue; @@ -721,8 +721,8 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // We expect global generic substitutions to come at // the end of the list in all cases, so lets advance // until we see them. - RefPtr appGlobalGenericSubsts = substsToApply; - while(appGlobalGenericSubsts && !appGlobalGenericSubsts.as()) + Substitutions* appGlobalGenericSubsts = substsToApply; + while(appGlobalGenericSubsts && !as(appGlobalGenericSubsts)) appGlobalGenericSubsts = appGlobalGenericSubsts->outer; @@ -738,11 +738,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(ioParametersFound.Count() == 0) return appGlobalGenericSubsts; - RefPtr resultSubst; - RefPtr* link = &resultSubst; + Substitutions* resultSubst = nullptr; + Substitutions** link = &resultSubst; for(auto appSubst = appGlobalGenericSubsts; appSubst; appSubst = appSubst->outer) { - auto appGlobalGenericSubst = appSubst.as(); + auto appGlobalGenericSubst = as(appSubst); if(!appSubst) continue; @@ -750,7 +750,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(ioParametersFound.Contains(appGlobalGenericSubst->paramDecl)) continue; - RefPtr newSubst = astBuilder->create(); + GlobalGenericParamSubstitution* newSubst = astBuilder->create(); newSubst->paramDecl = appGlobalGenericSubst->paramDecl; newSubst->actualType = appGlobalGenericSubst->actualType; newSubst->constraintArgs = appGlobalGenericSubst->constraintArgs; @@ -762,11 +762,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return resultSubst; } - RefPtr specializeGlobalGenericSubstitutions( + Substitutions* specializeGlobalGenericSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr substsToSpecialize, - RefPtr substsToApply, + Substitutions* substsToSpecialize, + Substitutions* substsToApply, int* ioDiff) { // Keep track of any parameters already present in the @@ -778,11 +778,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Construct new substitutions to apply to a declaration, // based on a provided substitution set to be applied - RefPtr specializeSubstitutions( + Substitutions* specializeSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr substsToSpecialize, - RefPtr substsToApply, + Substitutions* substsToSpecialize, + Substitutions* substsToApply, int* ioDiff) { // No declaration? Then nothing to specialize. @@ -861,7 +861,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt substsToApply, &diff); - RefPtr firstSubst = astBuilder->create(); + GenericSubstitution* firstSubst = astBuilder->create(); firstSubst->genericDecl = ancestorGenericDecl; firstSubst->args = appGenericSubst->args; firstSubst->outer = restSubst; @@ -909,7 +909,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // for(auto s = substsToApply; s; s = s->outer) { - auto appThisTypeSubst = s.as(); + auto appThisTypeSubst = as(s); if(!appThisTypeSubst) continue; @@ -924,7 +924,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt substsToApply, &diff); - RefPtr firstSubst = astBuilder->create(); + ThisTypeSubstitution* firstSubst = astBuilder->create(); firstSubst->interfaceDecl = ancestorInterfaceDecl; firstSubst->witness = appThisTypeSubst->witness; firstSubst->outer = restSubst; @@ -1033,7 +1033,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Default is to apply the same set of substitutions/specializations // to the parent declaration as were applied to the child. - RefPtr substToApply = substitutions.substitutions; + Substitutions* substToApply = substitutions.substitutions; if(auto interfaceDecl = as(decl)) { @@ -1079,14 +1079,14 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // IntVal - IntegerLiteralValue getIntVal(RefPtr val) + IntegerLiteralValue getIntVal(IntVal* val) { if (auto constantVal = as(val)) { return constantVal->value; } SLANG_UNEXPECTED("needed a known integer value"); - return 0; + //return 0; } // @@ -1105,7 +1105,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // Constructors for types - RefPtr getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType, IntVal* elementCount) @@ -1116,7 +1116,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return arrayType; } - RefPtr getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType) { @@ -1125,7 +1125,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return arrayType; } - RefPtr getNamedType( + NamedExpressionType* getNamedType( ASTBuilder* astBuilder, DeclRef const& declRef) { @@ -1135,11 +1135,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt } - RefPtr getFuncType( + FuncType* getFuncType( ASTBuilder* astBuilder, DeclRef const& declRef) { - RefPtr funcType = astBuilder->create(); + FuncType* funcType = astBuilder->create(); funcType->resultType = getResultType(astBuilder, declRef); for (auto paramDeclRef : getParameters(declRef)) @@ -1167,14 +1167,14 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return funcType; } - RefPtr getGenericDeclRefType( + GenericDeclRefType* getGenericDeclRefType( ASTBuilder* astBuilder, DeclRef const& declRef) { return astBuilder->create(declRef); } - RefPtr getNamespaceType( + NamespaceType* getNamespaceType( ASTBuilder* astBuilder, DeclRef const& declRef) { @@ -1183,17 +1183,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return type; } - RefPtr getSamplerStateType( + SamplerStateType* getSamplerStateType( ASTBuilder* astBuilder) { return astBuilder->create(); } - RefPtr findThisTypeSubstitution( + ThisTypeSubstitution* findThisTypeSubstitution( Substitutions* substs, InterfaceDecl* interfaceDecl) { - for(RefPtr s = substs; s; s = s->outer) + for(Substitutions* s = substs; s; s = s->outer) { auto thisTypeSubst = as(s); if(!thisTypeSubst) diff --git a/source/slang/slang-syntax.h b/source/slang/slang-syntax.h index 53ec57daa..37901e447 100644 --- a/source/slang/slang-syntax.h +++ b/source/slang/slang-syntax.h @@ -6,12 +6,12 @@ namespace Slang { - inline RefPtr getSub(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Type* getSub(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->sub.Ptr()); } - inline RefPtr getSup(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Type* getSup(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->getSup().type); } @@ -95,27 +95,27 @@ namespace Slang /// Name* getReflectionName(VarDeclBase* varDecl); - inline RefPtr getType(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Type* getType(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->type.Ptr()); } - inline RefPtr getInitExpr(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Expr* getInitExpr(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->initExpr); } - inline RefPtr getType(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Type* getType(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->type.Ptr()); } - inline RefPtr getTagExpr(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Expr* getTagExpr(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->tagExpr); } - inline RefPtr getTargetType(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Type* getTargetType(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->targetType.Ptr()); } @@ -127,19 +127,19 @@ namespace Slang - inline RefPtr getBaseType(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Type* getBaseType(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->base.type); } - inline RefPtr getType(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Type* getType(ASTBuilder* astBuilder, DeclRef const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->type.Ptr()); } - inline RefPtr getResultType(ASTBuilder* astBuilder, DeclRef const& declRef) + inline Type* getResultType(ASTBuilder* astBuilder, DeclRef const& declRef) { - return declRef.substitute(astBuilder, declRef.getDecl()->returnType.type.Ptr()); + return declRef.substitute(astBuilder, declRef.getDecl()->returnType.type); } inline FilteredMemberRefList getParameters(DeclRef const& declRef) @@ -151,38 +151,38 @@ namespace Slang { // TODO: Should really return a `DeclRef` for the inner // declaration, and not just a raw pointer - return declRef.getDecl()->inner.Ptr(); + return declRef.getDecl()->inner; } // - RefPtr getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType, IntVal* elementCount); - RefPtr getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType); - RefPtr getNamedType( + NamedExpressionType* getNamedType( ASTBuilder* astBuilder, DeclRef const& declRef); - RefPtr getFuncType( + FuncType* getFuncType( ASTBuilder* astBuilder, DeclRef const& declRef); - RefPtr getGenericDeclRefType( + GenericDeclRefType* getGenericDeclRefType( ASTBuilder* astBuilder, DeclRef const& declRef); - RefPtr getNamespaceType( + NamespaceType* getNamespaceType( ASTBuilder* astBuilder, DeclRef const& declRef); - RefPtr getSamplerStateType( + SamplerStateType* getSamplerStateType( ASTBuilder* astBuilder); @@ -192,7 +192,7 @@ namespace Slang template void FilteredModifierList::Iterator::operator++() { - current = adjust(current->next.Ptr()); + current = adjust(current->next); } // template @@ -206,13 +206,13 @@ namespace Slang { return m; } - m = m->next.Ptr(); + m = m->next; } } // - RefPtr findThisTypeSubstitution( + ThisTypeSubstitution* findThisTypeSubstitution( Substitutions* substs, InterfaceDecl* interfaceDecl); @@ -235,12 +235,12 @@ namespace Slang ASTBuilder* astBuilder, DeclRef declRef); - RefPtr createDefaultSubstitutionsForGeneric( + GenericSubstitution* createDefaultSubstitutionsForGeneric( ASTBuilder* astBuilder, GenericDecl* genericDecl, - RefPtr outerSubst); + Substitutions* outerSubst); - RefPtr findInnerMostGenericSubstitution(Substitutions* subst); + GenericSubstitution* findInnerMostGenericSubstitution(Substitutions* subst); enum class UserDefinedAttributeTargets { diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index f26b8bda4..3b30e6ee0 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -1318,7 +1318,7 @@ TypeLayoutContext getInitialLayoutContextForTarget(TargetRequest* targetReq, Pro } -static LayoutSize GetElementCount(RefPtr val) +static LayoutSize GetElementCount(IntVal* val) { // Lack of a size indicates an unbounded array. if(!val) @@ -1365,7 +1365,7 @@ bool IsResourceKind(LayoutResourceKind kind) /// static TypeLayoutResult createSimpleTypeLayout( SimpleLayoutInfo info, - RefPtr type, + Type* type, LayoutRulesImpl* rules) { RefPtr typeLayout = new TypeLayout(); @@ -1381,7 +1381,7 @@ static TypeLayoutResult createSimpleTypeLayout( } static SimpleLayoutInfo getParameterGroupLayoutInfo( - RefPtr type, + ParameterGroupType* type, LayoutRulesImpl* rules) { if( as(type) ) @@ -1861,7 +1861,7 @@ static void _addUnmaskedResourceUsage( static RefPtr _createParameterGroupTypeLayout( TypeLayoutContext const& context, - RefPtr parameterGroupType, + ParameterGroupType* parameterGroupType, RefPtr rawElementTypeLayout) { // We are being asked to create a layout for a parameter group, @@ -2325,8 +2325,8 @@ RefPtr createConstantBufferTypeLayoutIfNeeded( static RefPtr _createParameterGroupTypeLayout( TypeLayoutContext const& context, - RefPtr parameterGroupType, - RefPtr elementType, + ParameterGroupType* parameterGroupType, + Type* elementType, LayoutRulesImpl* elementTypeRules) { // We will first compute a layout for the element type of @@ -2346,7 +2346,7 @@ static RefPtr _createParameterGroupTypeLayout( } LayoutRulesImpl* getParameterBufferElementTypeLayoutRules( - RefPtr parameterGroupType, + ParameterGroupType* parameterGroupType, LayoutRulesImpl* rules) { if( as(parameterGroupType) ) @@ -2376,13 +2376,13 @@ LayoutRulesImpl* getParameterBufferElementTypeLayoutRules( else { SLANG_UNEXPECTED("uhandled parameter block type"); - return nullptr; + //return nullptr; } } RefPtr createParameterGroupTypeLayout( TypeLayoutContext const& context, - RefPtr parameterGroupType) + ParameterGroupType* parameterGroupType) { auto parameterGroupRules = context.rules; @@ -2405,7 +2405,7 @@ RefPtr createStructuredBufferTypeLayout( TypeLayoutContext const& context, ShaderParameterKind kind, - RefPtr structuredBufferType, + Type* structuredBufferType, RefPtr elementTypeLayout) { auto rules = context.rules; @@ -2437,8 +2437,8 @@ RefPtr createStructuredBufferTypeLayout( TypeLayoutContext const& context, ShaderParameterKind kind, - RefPtr structuredBufferType, - RefPtr elementType) + Type* structuredBufferType, + Type* elementType) { // look up the appropriate rules via the `LayoutRulesFamily` auto structuredBufferLayoutRules = context.getRulesFamily()->getStructuredBufferRules(); @@ -2446,7 +2446,7 @@ createStructuredBufferTypeLayout( // Create and save type layout for the buffer contents. auto elementTypeLayout = createTypeLayout( context.with(structuredBufferLayoutRules), - elementType.Ptr()); + elementType); return createStructuredBufferTypeLayout( context, @@ -2504,13 +2504,13 @@ static TypeLayoutResult _createTypeLayout( return _createTypeLayout(subContext, type); } -RefPtr findGlobalGenericSpecializationArg( +Type* findGlobalGenericSpecializationArg( TypeLayoutContext const& context, GlobalGenericParamDecl* decl) { - RefPtr arg; + Val* arg = nullptr; context.programLayout->globalGenericArgs.TryGetValue(decl, arg); - return arg.as(); + return as(arg); } Index findGlobalGenericSpecializationParamIndex( @@ -2523,7 +2523,7 @@ Index findGlobalGenericSpecializationParamIndex( auto param = type->getSpecializationParam(pp); if(param.flavor != SpecializationParam::Flavor::GenericType) continue; - if(param.object.Ptr() != decl) + if(param.object != decl) continue; return pp; @@ -3128,7 +3128,7 @@ static TypeLayoutResult _createTypeLayout( context, \ ShaderParameterKind::KIND, \ type_##TYPE, \ - type_##TYPE->elementType.Ptr()); \ + type_##TYPE->elementType); \ return TypeLayoutResult(typeLayout, info); \ } while(0) @@ -3257,7 +3257,7 @@ static TypeLayoutResult _createTypeLayout( colStride = minorStride; } - rowTypeLayout->type = type; + rowTypeLayout->type = rowType; rowTypeLayout->rules = rules; rowTypeLayout->uniformAlignment = elementInfo.getUniformLayout().alignment; @@ -3283,7 +3283,7 @@ static TypeLayoutResult _createTypeLayout( { auto elementResult = _createTypeLayout( context, - arrayType->baseType.Ptr()); + arrayType->baseType); auto elementInfo = elementResult.info; auto elementTypeLayout = elementResult.layout; @@ -3463,7 +3463,7 @@ static TypeLayoutResult _createTypeLayout( TypeLayoutResult fieldResult = _createTypeLayout( fieldLayoutContext, - getType(context.astBuilder, field).Ptr(), + getType(context.astBuilder, field), field.getDecl()); auto fieldTypeLayout = fieldResult.layout; @@ -3574,7 +3574,7 @@ static TypeLayoutResult _createTypeLayout( if( context.specializationArgCount ) { auto& specializationArg = context.specializationArgs[0]; - RefPtr concreteType = specializationArg.val.as(); + Type* concreteType = as(specializationArg.val); SLANG_ASSERT(concreteType); RefPtr concreteTypeLayout = createTypeLayout(context, concreteType); @@ -3944,7 +3944,7 @@ RefPtr TypeLayout::unwrapArray() } -RefPtr GenericParamTypeLayout::getGlobalGenericParamDecl() +GlobalGenericParamDecl* GenericParamTypeLayout::getGlobalGenericParamDecl() { auto declRefType = as(type); SLANG_ASSERT(declRefType); diff --git a/source/slang/slang-type-layout.h b/source/slang/slang-type-layout.h index fbe95608e..6298219f0 100644 --- a/source/slang/slang-type-layout.h +++ b/source/slang/slang-type-layout.h @@ -304,8 +304,8 @@ class TypeLayout : public Layout { public: // The type that was laid out - RefPtr type; - Type* getType() { return type.Ptr(); } + Type* type = nullptr; + Type* getType() { return type; } // The layout rules that were used to produce this type LayoutRulesImpl* rules; @@ -593,7 +593,7 @@ public: class GenericParamTypeLayout : public TypeLayout { public: - RefPtr getGlobalGenericParamDecl(); + GlobalGenericParamDecl* getGlobalGenericParamDecl(); Index paramIndex = 0; }; @@ -691,7 +691,7 @@ public: /// The declaration of the generic parameter. /// /// Could be any subclass of `Decl` that represents a generic value or type parameter. - RefPtr decl; + Decl* decl = nullptr; }; /// Reflection/layout information about an existential/interface specialization parameter. @@ -703,7 +703,7 @@ public: /// Currently, this will be an `interface` type that any concrete /// type argument getting plugged in must conform to. /// - RefPtr type; + Type* type = nullptr; }; // Layout information for the global scope of a program @@ -751,7 +751,7 @@ public: /// /// Not useful for reflection, but valuable for code generation. /// - Dictionary> globalGenericArgs; + Dictionary globalGenericArgs; /// Layouts for all tagged union types required by this program /// @@ -1118,7 +1118,7 @@ RefPtr createTypeLayout( /// Create a layout for a parameter-group type (a `ConstantBuffer` or `ParameterBlock`). RefPtr createParameterGroupTypeLayout( TypeLayoutContext const& context, - RefPtr parameterGroupType); + ParameterGroupType* parameterGroupType); /// Create a wrapper constant buffer type layout, if needed. /// @@ -1140,8 +1140,8 @@ RefPtr createStructuredBufferTypeLayout( TypeLayoutContext const& context, ShaderParameterKind kind, - RefPtr structuredBufferType, - RefPtr elementType); + Type* structuredBufferType, + Type* elementType); /// Create a type layout for an unspecialized `globalGenericParamDecl`. RefPtr createTypeLayoutForGlobalGenericTypeParam( @@ -1150,7 +1150,7 @@ RefPtr createTypeLayoutForGlobalGenericTypeParam( GlobalGenericParamDecl* globalGenericParamDecl); /// Find the concrete type (if any) that was plugged in for the global generic type parameter `decl`. -RefPtr findGlobalGenericSpecializationArg( +Type* findGlobalGenericSpecializationArg( TypeLayoutContext const& context, GlobalGenericParamDecl* decl); diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 331277bf3..1710359bf 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -26,6 +26,8 @@ #include "slang-ir-serialize.h" +#include "slang-check-impl.h" + // Used to print exception type names in internal-compiler-error messages #include @@ -123,10 +125,11 @@ void Session::init() m_sharedASTBuilder->init(this); // Use to create a ASTBuilder - RefPtr builtinAstBuilder(new ASTBuilder(m_sharedASTBuilder)); + RefPtr builtinAstBuilder(new ASTBuilder(m_sharedASTBuilder, "m_builtInLinkage::m_astBuilder")); // And the global ASTBuilder - globalAstBuilder = new ASTBuilder(m_sharedASTBuilder); + globalAstBuilder = new ASTBuilder(m_sharedASTBuilder, "globalAstBuilder"); + // Make sure our source manager is initialized builtinSourceManager.initialize(nullptr, nullptr); @@ -153,10 +156,10 @@ void Session::init() baseLanguageScope = new Scope(); - auto baseModuleDecl = populateBaseLanguageModule( + // Will stay in scope as long as ASTBuilder + baseModuleDecl = populateBaseLanguageModule( m_builtinLinkage->getASTBuilder(), baseLanguageScope); - loadedModuleCode.add(baseModuleDecl); coreLanguageScope = new Scope(); coreLanguageScope->nextSibling = baseLanguageScope; @@ -192,7 +195,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::createSession( slang::SessionDesc const& desc, slang::ISession** outSession) { - RefPtr astBuilder(new ASTBuilder(m_sharedASTBuilder)); + RefPtr astBuilder(new ASTBuilder(m_sharedASTBuilder, "Session::astBuilder")); RefPtr linkage = new Linkage(this, astBuilder); Int targetCount = desc.targetCount; @@ -523,6 +526,26 @@ ISlangUnknown* Linkage::getInterface(const Guid& guid) return nullptr; } +Linkage::~Linkage() +{ + destroyTypeCheckingCache(); +} + +TypeCheckingCache* Linkage::getTypeCheckingCache() +{ + if (!m_typeCheckingCache) + { + m_typeCheckingCache = new TypeCheckingCache(); + } + return m_typeCheckingCache; +} + +void Linkage::destroyTypeCheckingCache() +{ + delete m_typeCheckingCache; + m_typeCheckingCache = nullptr; +} + SLANG_NO_THROW slang::IGlobalSession* SLANG_MCALL Linkage::getGlobalSession() { return asExternal(getSessionImpl()); @@ -820,7 +843,7 @@ SlangResult Linkage::loadFile(String const& path, PathInfo& outPathInfo, ISlangB return SLANG_OK; } -RefPtr Linkage::parseTermString(String typeStr, RefPtr scope) +Expr* Linkage::parseTermString(String typeStr, RefPtr scope) { // Create a SourceManager on the stack, so any allocations for 'SourceFile'/'SourceView' etc will be cleaned up SourceManager localSourceManager; @@ -868,7 +891,7 @@ RefPtr Linkage::parseTermString(String typeStr, RefPtr scope) tokens, &sink, scope, getNamePool(), SourceLanguage::Slang); } -RefPtr checkProperType( +Type* checkProperType( Linkage* linkage, TypeExp typeExp, DiagnosticSink* sink); @@ -880,7 +903,7 @@ Type* ComponentType::getTypeFromString( // If we've looked up this type name before, // then we can re-use it. // - RefPtr type; + Type* type = nullptr; if(m_types.TryGetValue(typeStr, type)) return type; @@ -891,7 +914,7 @@ Type* ComponentType::getTypeFromString( RefPtr scope = _createScopeForLegacyLookup(); auto linkage = getLinkage(); - RefPtr typeExpr = linkage->parseTermString( + Expr* typeExpr = linkage->parseTermString( typeStr, scope); type = checkProperType(linkage, TypeExp(typeExpr), sink); @@ -959,7 +982,10 @@ void FrontEndCompileRequest::parseTranslationUnit( ASTBuilder* astBuilder = module->getASTBuilder(); - RefPtr translationUnitSyntax = astBuilder->create(); + //ASTBuilder* astBuilder = linkage->getASTBuilder(); + + ModuleDecl* translationUnitSyntax = astBuilder->create(); + translationUnitSyntax->nameAndLoc.name = translationUnit->moduleName; translationUnitSyntax->module = module; module->setModuleDecl(translationUnitSyntax); @@ -1214,7 +1240,7 @@ EndToEndCompileRequest::EndToEndCompileRequest( : m_session(session) , m_sink(nullptr) { - RefPtr astBuilder(new ASTBuilder(session->m_sharedASTBuilder)); + RefPtr astBuilder(new ASTBuilder(session->m_sharedASTBuilder, "EndToEnd::Linkage::astBuilder")); m_linkage = new Linkage(session, astBuilder); init(); } @@ -1780,7 +1806,7 @@ void FilePathDependencyList::addDependency(Module* module) Module::Module(Linkage* linkage) : ComponentType(linkage) - , m_astBuilder(linkage->getASTBuilder()->getSharedASTBuilder()) + , m_astBuilder(linkage->getASTBuilder()->getSharedASTBuilder(), "Module") { addModuleDependency(this); } @@ -2597,32 +2623,31 @@ void Session::addBuiltinSource( } // Extract the AST for the code we just parsed - auto syntax = compileRequest->translationUnits[translationUnitIndex]->getModuleDecl(); + auto module = compileRequest->translationUnits[translationUnitIndex]->getModule(); + auto moduleDecl = module->getModuleDecl(); // Add the resulting code to the appropriate scope if (!scope->containerDecl) { // We are the first chunk of code to be loaded for this scope - scope->containerDecl = syntax.Ptr(); + scope->containerDecl = moduleDecl; } else { // We need to create a new scope to link into the whole thing auto subScope = new Scope(); - subScope->containerDecl = syntax.Ptr(); + subScope->containerDecl = moduleDecl; subScope->nextSibling = scope->nextSibling; scope->nextSibling = subScope; } // We need to retain this AST so that we can use it in other code // (Note that the `Scope` type does not retain the AST it points to) - loadedModuleCode.add(syntax); + loadedModuleCode.add(module); } Session::~Session() { - destroyTypeCheckingCache(); - // destroy modules next loadedModuleCode = decltype(loadedModuleCode)(); } @@ -2734,6 +2759,7 @@ SLANG_API void spDestroyCompileRequest( { if(!request) return; auto req = Slang::asInternal(request); + delete req; } -- cgit v1.2.3