diff options
| author | Yong He <yonghe@outlook.com> | 2020-06-05 18:34:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-05 18:34:24 -0700 |
| commit | 52026c7c26e48921fdf18b3f8cdacad77a792643 (patch) | |
| tree | d439487223ee8ec4a2052d8855db310da878c001 /source | |
| parent | 92fc3aaa835315ff08750c7b5a7498b7228e2c33 (diff) | |
| parent | 43c146794aab638924d2ab838d10f8af2ebf02a7 (diff) | |
Merge branch 'master' into findtypebynamefix
Diffstat (limited to 'source')
44 files changed, 1658 insertions, 1564 deletions
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<Val> 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<Val> 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<Val> _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<Val> _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); bool _equalsValOverride(Val* val); bool _equalsImplOverride(Type* type); - RefPtr<Type> _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); protected: bool equalsImpl(Type* type); - RefPtr<Type> 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<Substitutions> outer; + Substitutions* outer = nullptr; // Apply a set of substitutions to the bindings in this substitution - RefPtr<Substitutions> applySubstitutionsShallow(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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<Substitutions> _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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<RefPtr<Val> > args; + List<Val* > args; // Overrides should be public so base classes can access - RefPtr<Substitutions> _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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<SubtypeWitness> 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<Substitutions> _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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<Type> actualType; + Type* actualType = nullptr; struct ConstraintArg { - RefPtr<Decl> decl; - RefPtr<Val> val; + Decl* decl = nullptr; + Val* val = nullptr; }; // the values that satisfy any constraints on the type parameter List<ConstraintArg> constraintArgs; // Overrides should be public so base classes can access - RefPtr<Substitutions> _applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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<Modifier> 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<typename T> - FilteredModifierList<T> getModifiersOfType() { return FilteredModifierList<T>(modifiers.first.Ptr()); } + FilteredModifierList<T> getModifiersOfType() { return FilteredModifierList<T>(modifiers.first); } // Find the first modifier of a given type, or return `nullptr` if none is found. template<typename T> 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<RefObject> SharedASTBuilder::findSyntaxClass(const UnownedStringSlice& slice) +SyntaxClass<NodeBase> SharedASTBuilder::findSyntaxClass(const UnownedStringSlice& slice) { const ReflectClassInfo* typeInfo; if (m_sliceToTypeMap.TryGetValue(slice, typeInfo)) { - return SyntaxClass<RefObject>(typeInfo); + return SyntaxClass<NodeBase>(typeInfo); } - return SyntaxClass<RefObject>(); + return SyntaxClass<NodeBase>(); } 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<RefObject> SharedASTBuilder::findSyntaxClass(Name* name) +SyntaxClass<NodeBase> SharedASTBuilder::findSyntaxClass(Name* name) { const ReflectClassInfo* typeInfo; if (m_nameToTypeMap.TryGetValue(name, typeInfo)) { - return SyntaxClass<RefObject>(typeInfo); + return SyntaxClass<NodeBase>(typeInfo); } - return SyntaxClass<RefObject>(); + return SyntaxClass<NodeBase>(); } 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> decl, RefPtr<BuiltinTypeModifier> modifier) +void SharedASTBuilder::registerBuiltinDecl(Decl* decl, BuiltinTypeModifier* modifier) { - auto type = DeclRefType::create(m_astBuilder, DeclRef<Decl>(decl.Ptr(), nullptr)); + auto type = DeclRefType::create(m_astBuilder, DeclRef<Decl>(decl, nullptr)); m_builtinTypes[Index(modifier->tag)] = type; } -void SharedASTBuilder::registerMagicDecl(RefPtr<Decl> decl, RefPtr<MagicTypeModifier> 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> decl, RefPtr<MagicTypeModi if (auto genericDecl = as<GenericDecl>(decl->parentDecl)) declToRegister = genericDecl; - m_magicDecls[modifier->name] = declToRegister.Ptr(); + m_magicDecls[modifier->name] = declToRegister; } -RefPtr<Decl> 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<PtrType> ASTBuilder::getPtrType(RefPtr<Type> valueType) +PtrType* ASTBuilder::getPtrType(Type* valueType) { - return getPtrType(valueType, "PtrType").dynamicCast<PtrType>(); + return dynamicCast<PtrType>(getPtrType(valueType, "PtrType")); } // Construct the type `Out<valueType>` -RefPtr<OutType> ASTBuilder::getOutType(RefPtr<Type> valueType) +OutType* ASTBuilder::getOutType(Type* valueType) { - return getPtrType(valueType, "OutType").dynamicCast<OutType>(); + return dynamicCast<OutType>(getPtrType(valueType, "OutType")); } -RefPtr<InOutType> ASTBuilder::getInOutType(RefPtr<Type> valueType) +InOutType* ASTBuilder::getInOutType(Type* valueType) { - return getPtrType(valueType, "InOutType").dynamicCast<InOutType>(); + return dynamicCast<InOutType>(getPtrType(valueType, "InOutType")); } -RefPtr<RefType> ASTBuilder::getRefType(RefPtr<Type> valueType) +RefType* ASTBuilder::getRefType(Type* valueType) { - return getPtrType(valueType, "RefType").dynamicCast<RefType>(); + return dynamicCast<RefType>(getPtrType(valueType, "RefType")); } -RefPtr<PtrTypeBase> ASTBuilder::getPtrType(RefPtr<Type> valueType, char const* ptrTypeName) +PtrTypeBase* ASTBuilder::getPtrType(Type* valueType, char const* ptrTypeName) { - auto genericDecl = m_sharedASTBuilder->findMagicDecl(ptrTypeName).dynamicCast<GenericDecl>(); + auto genericDecl = dynamicCast<GenericDecl>(m_sharedASTBuilder->findMagicDecl(ptrTypeName)); return getPtrType(valueType, genericDecl); } -RefPtr<PtrTypeBase> ASTBuilder::getPtrType(RefPtr<Type> valueType, GenericDecl* genericDecl) +PtrTypeBase* ASTBuilder::getPtrType(Type* valueType, GenericDecl* genericDecl) { auto typeDecl = genericDecl->inner; @@ -187,38 +202,38 @@ RefPtr<PtrTypeBase> ASTBuilder::getPtrType(RefPtr<Type> valueType, GenericDecl* substitutions->genericDecl = genericDecl; substitutions->args.add(valueType); - auto declRef = DeclRef<Decl>(typeDecl.Ptr(), substitutions); + auto declRef = DeclRef<Decl>(typeDecl, substitutions); auto rsType = DeclRefType::create(this, declRef); return as<PtrTypeBase>(rsType); } -RefPtr<ArrayExpressionType> ASTBuilder::getArrayType(Type* elementType, IntVal* elementCount) +ArrayExpressionType* ASTBuilder::getArrayType(Type* elementType, IntVal* elementCount) { - RefPtr<ArrayExpressionType> arrayType = create<ArrayExpressionType>(); + ArrayExpressionType* arrayType = create<ArrayExpressionType>(); arrayType->baseType = elementType; arrayType->arrayLength = elementCount; return arrayType; } -RefPtr<VectorExpressionType> ASTBuilder::getVectorType( - RefPtr<Type> elementType, - RefPtr<IntVal> elementCount) +VectorExpressionType* ASTBuilder::getVectorType( + Type* elementType, + IntVal* elementCount) { - auto vectorGenericDecl = m_sharedASTBuilder->findMagicDecl("Vector").as<GenericDecl>(); + auto vectorGenericDecl = as<GenericDecl>(m_sharedASTBuilder->findMagicDecl("Vector")); auto vectorTypeDecl = vectorGenericDecl->inner; auto substitutions = create<GenericSubstitution>(); - substitutions->genericDecl = vectorGenericDecl.Ptr(); + substitutions->genericDecl = vectorGenericDecl; substitutions->args.add(elementType); substitutions->args.add(elementCount); - auto declRef = DeclRef<Decl>(vectorTypeDecl.Ptr(), substitutions); + auto declRef = DeclRef<Decl>(vectorTypeDecl, substitutions); - return DeclRefType::create(this, declRef).as<VectorExpressionType>(); + return as<VectorExpressionType>(DeclRefType::create(this, declRef)); } -RefPtr<TypeType> ASTBuilder::getTypeType(Type* type) +TypeType* ASTBuilder::getTypeType(Type* type) { return create<TypeType>(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 <type_traits> + #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> decl, RefPtr<BuiltinTypeModifier> modifier); - void registerMagicDecl(RefPtr<Decl> decl, RefPtr<MagicTypeModifier> 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<RefObject> findSyntaxClass(Name* name); + SyntaxClass<NodeBase> findSyntaxClass(Name* name); const ReflectClassInfo* findClassInfo(const UnownedStringSlice& slice); - SyntaxClass<RefObject> findSyntaxClass(const UnownedStringSlice& slice); + SyntaxClass<NodeBase> findSyntaxClass(const UnownedStringSlice& slice); // Look up a magic declaration by its name - RefPtr<Decl> 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<Type> m_errorType; - RefPtr<Type> m_initializerListType; - RefPtr<Type> 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<Type> m_stringType; - RefPtr<Type> m_enumTypeType; + Type* m_stringType = nullptr; + Type* m_enumTypeType = nullptr; - RefPtr<Type> m_builtinTypes[Index(BaseType::CountOf)]; + Type* m_builtinTypes[Index(BaseType::CountOf)]; Dictionary<String, Decl*> 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 <typename T> - T* create() { SLANG_COMPILE_TIME_ASSERT(IsValidType<T>::Value); T* node = new T; node->init(T::kType, this); return node; } + /// Create AST types + template <typename T> + T* create() { return _initAndAdd(new (m_arena.allocate(sizeof(T))) T); } template<typename T, typename P0> - T* create(const P0& p0) { SLANG_COMPILE_TIME_ASSERT(IsValidType<T>::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<typename T, typename P0, typename P1> - T* create(const P0& p0, const P1& p1) { SLANG_COMPILE_TIME_ASSERT(IsValidType<T>::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<valueType>`, where `Ptr` // is looked up as a builtin type. - RefPtr<PtrType> getPtrType(RefPtr<Type> valueType); + PtrType* getPtrType(Type* valueType); // Construct the type `Out<valueType>` - RefPtr<OutType> getOutType(RefPtr<Type> valueType); + OutType* getOutType(Type* valueType); // Construct the type `InOut<valueType>` - RefPtr<InOutType> getInOutType(RefPtr<Type> valueType); + InOutType* getInOutType(Type* valueType); // Construct the type `Ref<valueType>` - RefPtr<RefType> getRefType(RefPtr<Type> valueType); + RefType* getRefType(Type* valueType); // Construct a pointer type like `Ptr<valueType>`, but where // the actual type name for the pointer type is given by `ptrTypeName` - RefPtr<PtrTypeBase> getPtrType(RefPtr<Type> valueType, char const* ptrTypeName); + PtrTypeBase* getPtrType(Type* valueType, char const* ptrTypeName); // Construct a pointer type like `Ptr<valueType>`, but where // the generic declaration for the pointer type is `genericDecl` - RefPtr<PtrTypeBase> getPtrType(RefPtr<Type> valueType, GenericDecl* genericDecl); + PtrTypeBase* getPtrType(Type* valueType, GenericDecl* genericDecl); - RefPtr<ArrayExpressionType> getArrayType(Type* elementType, IntVal* elementCount); + ArrayExpressionType* getArrayType(Type* elementType, IntVal* elementCount); - RefPtr<VectorExpressionType> getVectorType(RefPtr<Type> elementType, RefPtr<IntVal> elementCount); + VectorExpressionType* getVectorType(Type* elementType, IntVal* elementCount); - RefPtr<TypeType> 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<RefObject> findSyntaxClass(const UnownedStringSlice& slice) { return m_sharedASTBuilder->findSyntaxClass(slice); } + SyntaxClass<NodeBase> findSyntaxClass(const UnownedStringSlice& slice) { return m_sharedASTBuilder->findSyntaxClass(slice); } const ReflectClassInfo* findClassInfo(Name* name) { return m_sharedASTBuilder->findClassInfo(name); } - SyntaxClass<RefObject> findSyntaxClass(Name* name) { return m_sharedASTBuilder->findSyntaxClass(name); } + SyntaxClass<NodeBase> 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 <typename T> + SLANG_FORCE_INLINE T* _initAndAdd(T* node) + { + SLANG_COMPILE_TIME_ASSERT(IsValidType<T>::Value); + + node->init(T::kType, this); + + // Only add it if it has a dtor that does some work + if (!std::is_trivially_destructible<T>::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<NodeBase*> 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<RefPtr<Decl>> decls; + List<Decl*> decls; }; @@ -22,7 +22,7 @@ class ContainerDecl: public Decl { SLANG_ABSTRACT_CLASS(ContainerDecl) - List<RefPtr<Decl>> members; + List<Decl*> members; template<typename T> FilteredMemberList<T> 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<Expr> 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<Type> 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<Expr> 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<Stmt> body; + Stmt* body = nullptr; }; // A constructor/initializer to create instances of a type @@ -376,7 +376,7 @@ class ImportDecl : public Decl RefPtr<Scope> scope; // The module that actually got imported - RefPtr<ModuleDecl> 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<Decl> 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<RefObject> syntaxClass; + SyntaxClass<NodeBase> 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<RefObject> syntaxClass; + SyntaxClass<NodeBase> 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<RefObject*, Index> m_objectMap; ///< Object index + Dictionary<NodeBase*, Index> m_objectMap; ///< Object index List<ObjectInfo> 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<Expr> 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<Expr> base; + Expr* base = nullptr; // The lookup result that was ambiguous - List<RefPtr<Expr>> candidiateExprs; + List<Expr*> candidiateExprs; }; class LiteralExpr : public Expr @@ -103,7 +103,7 @@ class StringLiteralExpr : public LiteralExpr class InitializerListExpr : public Expr { SLANG_CLASS(InitializerListExpr) - List<RefPtr<Expr>> args; + List<Expr*> args; }; // A base class for expressions with arguments @@ -111,7 +111,7 @@ class ExprWithArgsBase : public Expr { SLANG_ABSTRACT_CLASS(ExprWithArgsBase) - List<RefPtr<Expr>> arguments; + List<Expr*> arguments; }; // An aggregate type constructor @@ -129,7 +129,7 @@ class AppExprBase : public ExprWithArgsBase { SLANG_ABSTRACT_CLASS(AppExprBase) - RefPtr<Expr> functionExpr; + Expr* functionExpr = nullptr; }; class InvokeExpr: public AppExprBase @@ -159,21 +159,21 @@ class IndexExpr: public Expr { SLANG_CLASS(IndexExpr) - RefPtr<Expr> baseExpression; - RefPtr<Expr> indexExpression; + Expr* baseExpression = nullptr; + Expr* indexExpression = nullptr; }; class MemberExpr: public DeclRefExpr { SLANG_CLASS(MemberExpr) - RefPtr<Expr> baseExpression; + Expr* baseExpression = nullptr; }; // Member looked up on a type, rather than a value class StaticMemberExpr: public DeclRefExpr { SLANG_CLASS(StaticMemberExpr) - RefPtr<Expr> baseExpression; + Expr* baseExpression = nullptr; }; struct MatrixCoord @@ -188,7 +188,7 @@ struct MatrixCoord class MatrixSwizzleExpr : public Expr { SLANG_CLASS(MatrixSwizzleExpr) - RefPtr<Expr> 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<Expr> 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<Expr> base; + Expr* base = nullptr; }; // Any operation that performs type-casting @@ -213,7 +213,7 @@ class TypeCastExpr: public InvokeExpr { SLANG_CLASS(TypeCastExpr) // TypeExp TargetType; -// RefPtr<Expr> 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<Expr> 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<Val> 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<Expr> left; - RefPtr<Expr> 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<Expr> 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<VarDecl> decl; - RefPtr<Expr> 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<RefObject> syntaxClass; + SyntaxClass<NodeBase> syntaxClass; }; // Base class for checked and unchecked `[name(arg0, ...)]` style attribute. @@ -519,7 +519,7 @@ class AttributeBase : public Modifier { SLANG_CLASS(AttributeBase) - List<RefPtr<Expr>> args; + List<Expr*> args; }; // A `[name(...)]` attribute that hasn't undergone any semantic analysis. @@ -549,7 +549,7 @@ class AttributeUsageAttribute : public Attribute { SLANG_CLASS(AttributeUsageAttribute) - SyntaxClass<RefObject> targetSyntaxClass; + SyntaxClass<NodeBase> targetSyntaxClass; }; // An `[unroll]` or `[unroll(count)]` attribute @@ -668,7 +668,7 @@ class PatchConstantFuncAttribute : public Attribute { SLANG_CLASS(PatchConstantFuncAttribute) - RefPtr<FuncDecl> 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 <typename T> - struct CreateImpl + struct Impl { - static void* create(ASTBuilder* astBuilder) { return astBuilder->create<T>(); } + static void* create(ASTBuilder* astBuilder) + { + return astBuilder->create<T>(); + } + static void destroy(void* ptr) + { + // Needed because if type has non dtor, Visual Studio claims ptr not used + SLANG_UNUSED(ptr); + reinterpret_cast<T*>(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<NAME>::create - -#define SLANG_GET_CREATE_FUNC_NON_VISITOR_ABSTRACT(NAME) nullptr -#define SLANG_GET_CREATE_FUNC_NON_VISITOR(NAME) &ASTConstructAccess::CreateImpl<NAME>::create +#define SLANG_GET_CREATE_FUNC_NONE(NAME) &ASTConstructAccess::Impl<NAME>::create +#define SLANG_GET_DESTROY_FUNC_ABSTRACT(NAME) nullptr +#define SLANG_GET_DESTROY_FUNC_NONE(NAME) &ASTConstructAccess::Impl<NAME>::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* scopeDecl = nullptr; }; // A sequence of statements, treated as a single statement @@ -20,7 +20,7 @@ class SeqStmt : public Stmt { SLANG_CLASS(SeqStmt) - List<RefPtr<Stmt>> stmts; + List<Stmt*> stmts; }; // The simplest kind of scope statement: just a `{...}` block @@ -28,7 +28,7 @@ class BlockStmt : public ScopeStmt { SLANG_CLASS(BlockStmt) - RefPtr<Stmt> 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<DeclBase> decl; + DeclBase* decl = nullptr; }; class IfStmt : public Stmt { SLANG_CLASS(IfStmt) - RefPtr<Expr> predicate; - RefPtr<Stmt> positiveStatement; - RefPtr<Stmt> 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<Expr> condition; - RefPtr<Stmt> 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* expr = nullptr; }; // a `default` statement inside a `switch` @@ -129,10 +129,10 @@ class ForStmt : public LoopStmt { SLANG_CLASS(ForStmt) - RefPtr<Stmt> initialStatement; - RefPtr<Expr> sideEffectExpression; - RefPtr<Expr> predicateExpression; - RefPtr<Stmt> 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<Expr> predicate; - RefPtr<Stmt> statement; + Expr* predicate = nullptr; + Stmt* statement = nullptr; }; class DoWhileStmt : public LoopStmt { SLANG_CLASS(DoWhileStmt) - RefPtr<Stmt> statement; - RefPtr<Expr> 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> varDecl; - RefPtr<Expr> rangeBeginExpr; - RefPtr<Expr> rangeEndExpr; - RefPtr<Stmt> body; - RefPtr<IntVal> rangeBeginVal; - RefPtr<IntVal> 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<Expr> expression; + Expr* expression = nullptr; }; class ExpressionStmt : public Stmt { SLANG_CLASS(ExpressionStmt) - RefPtr<Expr> 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> Substitutions::applySubstitutionsShallow(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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> Substitutions::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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<Substitutions>(); + //return Substitutions*(); } bool Substitutions::_equalsOverride(Substitutions* subst) @@ -48,13 +48,13 @@ HashCode Substitutions::_getHashCodeOverride() const // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GenericSubstitution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -RefPtr<Substitutions> GenericSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> substOuter, int* ioDiff) +Substitutions* GenericSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, Substitutions* substOuter, int* ioDiff) { int diff = 0; if (substOuter != outer) diff++; - List<RefPtr<Val>> substArgs; + List<Val*> 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<Substitutions> ThisTypeSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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<SubtypeWitness>(); + auto substWitness = as<SubtypeWitness>(witness->substituteImpl(astBuilder, substSet, &diff)); if (!diff) return this; @@ -165,7 +165,7 @@ HashCode ThisTypeSubstitution::_getHashCodeOverride() const // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GlobalGenericParamSubstitution !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -RefPtr<Substitutions> GlobalGenericParamSubstitution::_applySubstitutionsShallowOverride(ASTBuilder* astBuilder, SubstitutionSet substSet, RefPtr<Substitutions> 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<Substitutions> GlobalGenericParamSubstitution::_applySubstitutionsShallow if (substOuter != outer) diff++; - auto substActualType = actualType->substituteImpl(astBuilder, substSet, &diff).as<Type>(); + auto substActualType = as<Type>(actualType->substituteImpl(astBuilder, substSet, &diff)); List<ConstraintArg> substConstraintArgs; for (auto constraintArg : constraintArgs) @@ -190,7 +190,7 @@ RefPtr<Substitutions> GlobalGenericParamSubstitution::_applySubstitutionsShallow (*ioDiff)++; - RefPtr<GlobalGenericParamSubstitution> substSubst = astBuilder->create<GlobalGenericParamSubstitution>(); + GlobalGenericParamSubstitution* substSubst = astBuilder->create<GlobalGenericParamSubstitution>(); 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 <typename T> + T* as(NodeBase* node); + + template <typename T> + 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<RefObject> (*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<Modifier> first; + Modifier* first = nullptr; template<typename T> - FilteredModifierList<T> getModifiersOfType() { return FilteredModifierList<T>(first.Ptr()); } + FilteredModifierList<T> getModifiersOfType() { return FilteredModifierList<T>(first); } // Find the first modifier of a given type, or return `nullptr` if none is found. template<typename T> @@ -286,7 +295,7 @@ namespace Slang template<typename T> bool hasModifier() { return findModifier<T>() != nullptr; } - FilteredModifierList<Modifier>::Iterator begin() { return FilteredModifierList<Modifier>::Iterator(first.Ptr()); } + FilteredModifierList<Modifier>::Iterator begin() { return FilteredModifierList<Modifier>::Iterator(first); } FilteredModifierList<Modifier>::Iterator end() { return FilteredModifierList<Modifier>::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<IntVal> 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<ModifiableSyntaxNode> syntax, - RefPtr<Modifier> modifier); + ModifiableSyntaxNode* syntax, + Modifier* modifier); struct QualType { - RefPtr<Type> 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<Type>() { return type; } - RefPtr<Type> 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* substitutions = nullptr; operator Substitutions*() const { return substitutions; } SubstitutionSet() {} - SubstitutionSet(RefPtr<Substitutions> subst) + SubstitutionSet(Substitutions* subst) : substitutions(subst) { } @@ -618,18 +628,18 @@ namespace Slang substitutions(subst) {} - DeclRefBase(Decl* decl, RefPtr<Substitutions> subst) + DeclRefBase(Decl* decl, Substitutions* subst) : decl(decl) , substitutions(subst) {} // Apply substitutions to a type or declaration - RefPtr<Type> substitute(ASTBuilder* astBuilder, RefPtr<Type> type) const; + Type* substitute(ASTBuilder* astBuilder, Type* type) const; DeclRefBase substitute(ASTBuilder* astBuilder, DeclRefBase declRef) const; // Apply substitutions to an expression - RefPtr<Expr> substitute(ASTBuilder* astBuilder, RefPtr<Expr> 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<Substitutions> subst) + DeclRef(T* decl, Substitutions* subst) : DeclRefBase(decl, SubstitutionSet(subst)) {} @@ -699,11 +709,11 @@ namespace Slang return DeclRef<T>((T*) declRef.decl, declRef.substitutions); } - RefPtr<Type> substitute(ASTBuilder* astBuilder, RefPtr<Type> type) const + Type* substitute(ASTBuilder* astBuilder, Type* type) const { return DeclRefBase::substitute(astBuilder, type); } - RefPtr<Expr> substitute(ASTBuilder* astBuilder, RefPtr<Expr> 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<Decl>* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* end); - const RefPtr<Decl>* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* end, Index index); - Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* 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 <typename T> - const RefPtr<Decl>* adjustFilterCursor(MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* 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 <typename T> - const RefPtr<Decl>* getFilterCursorByIndex(MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* 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 <typename T> - Index getFilterCount(MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* end) + Index getFilterCount(MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { return getFilterCountImpl(T::kReflectClassInfo, filterStyle, ptr, end); } template <typename T> - bool isFilterNonEmpty(MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* 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<typename T> struct FilteredMemberList { - typedef RefPtr<Decl> Element; + typedef Decl* Element; FilteredMemberList() : m_begin(nullptr) @@ -807,7 +817,7 @@ namespace Slang void operator++() { m_cursor = adjustFilterCursor<T>(m_filterStyle, m_cursor + 1, m_end); } - const RefPtr<T>& operator*() { return *(RefPtr<T>*)(m_cursor); } + T* operator*() { return static_cast<T*>(*m_cursor); } }; Iterator begin() @@ -827,11 +837,11 @@ namespace Slang const RefPtr<T>& getFirst() { return *begin(); } Index getCount() { return getFilterCount<T>(m_filterStyle, m_begin, m_end); } - RefPtr<T> operator[](Index index) const + T* operator[](Index index) const { - const RefPtr<Decl>* ptr = getFilterCursorByIndex<T>(m_filterStyle, m_begin, m_end, index); + Decl*const* ptr = getFilterCursorByIndex<T>(m_filterStyle, m_begin, m_end, index); SLANG_ASSERT(ptr); - return *(RefPtr<T>*)(ptr); + return static_cast<T*>(*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<typename T> struct FilteredMemberRefList { - List<RefPtr<Decl>> const& m_decls; + List<Decl*> const& m_decls; SubstitutionSet m_substitutions; MemberFilterStyle m_filterStyle; FilteredMemberRefList( - List<RefPtr<Decl>> const& decls, + List<Decl*> const& decls, SubstitutionSet substitutions, MemberFilterStyle filterStyle = MemberFilterStyle::All) : m_decls(decls) @@ -889,9 +899,9 @@ namespace Slang DeclRef<T> operator[](Index index) const { - const RefPtr<Decl>* decl = getFilterCursorByIndex<T>(m_filterStyle, m_decls.begin(), m_decls.end(), index); + Decl*const* decl = getFilterCursorByIndex<T>(m_filterStyle, m_decls.begin(), m_decls.end(), index); SLANG_ASSERT(decl); - return DeclRef<T>((T*) decl->Ptr(), m_substitutions); + return DeclRef<T>((T*) *decl, m_substitutions); } List<DeclRef<T>> toArray() const @@ -905,15 +915,15 @@ namespace Slang struct Iterator { FilteredMemberRefList const* m_list; - const RefPtr<Decl>* m_ptr; - const RefPtr<Decl>* 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<Decl>* ptr, - const RefPtr<Decl>* end, + Decl*const* ptr, + Decl*const* end, MemberFilterStyle filterStyle ) : m_list(list) @@ -926,7 +936,7 @@ namespace Slang void operator++() { m_ptr = adjustFilterCursor<T>(m_filterStyle, m_ptr + 1, m_end); } - DeclRef<T> operator*() { return DeclRef<T>((T*) m_ptr->Ptr(), m_list->m_substitutions); } + DeclRef<T> operator*() { return DeclRef<T>((T*)*m_ptr, m_list->m_substitutions); } }; Iterator begin() const { return Iterator(this, adjustFilterCursor<T>(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<Expr> exp) + explicit TypeExp(Expr* exp) : exp(exp) {} - explicit TypeExp(RefPtr<Type> type) + explicit TypeExp(Type* type) : type(type) {} - TypeExp(RefPtr<Expr> exp, RefPtr<Type> type) + TypeExp(Expr* exp, Type* type) : exp(exp) , type(type) {} - RefPtr<Expr> exp; - RefPtr<Type> 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> val); + RequirementWitness(Val* val); RequirementWitness(RefPtr<WitnessTable> witnessTable); @@ -1256,10 +1266,10 @@ namespace Slang return m_declRef; } - RefPtr<Val> getVal() + Val* getVal() { SLANG_ASSERT(getFlavor() == Flavor::val); - return m_obj.as<Val>(); + return m_val; } RefPtr<WitnessTable> getWitnessTable(); @@ -1269,7 +1279,7 @@ namespace Slang Flavor m_flavor; DeclRef<Decl> m_declRef; RefPtr<RefObject> m_obj; - + Val* m_val = nullptr; }; typedef Dictionary<Decl*, RequirementWitness> RequirementDictionary; @@ -1279,7 +1289,7 @@ namespace Slang RequirementDictionary requirementDictionary; }; - typedef Dictionary<unsigned int, RefPtr<RefObject>> AttributeArgumentValueDict; + typedef Dictionary<unsigned int, NodeBase*> AttributeArgumentValueDict; struct SpecializationParam { @@ -1292,19 +1302,19 @@ namespace Slang }; Flavor flavor; SourceLoc loc; - RefPtr<NodeBase> object; + NodeBase* object = nullptr; }; typedef List<SpecializationParam> SpecializationParams; struct SpecializationArg { - RefPtr<Val> val; + Val* val = nullptr; }; typedef List<SpecializationArg> SpecializationArgs; struct ExpandedSpecializationArg : SpecializationArg { - RefPtr<Val> witness; + Val* witness = nullptr; }; typedef List<ExpandedSpecializationArg> 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> 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> Type::_createCanonicalTypeOverride() +Type* Type::_createCanonicalTypeOverride() { SLANG_UNEXPECTED("Type::_createCanonicalTypeOverride not overridden"); - //return RefPtr<Type>(); + //return Type*(); } bool Type::_equalsValOverride(Val* val) @@ -56,7 +46,7 @@ bool Type::_equalsValOverride(Val* val) return false; } -RefPtr<Val> 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<Type> OverloadGroupType::_createCanonicalTypeOverride() +Type* OverloadGroupType::_createCanonicalTypeOverride() { return this; } @@ -125,7 +109,7 @@ bool InitializerListType::_equalsImplOverride(Type * /*type*/) return false; } -RefPtr<Type> InitializerListType::_createCanonicalTypeOverride() +Type* InitializerListType::_createCanonicalTypeOverride() { return this; } @@ -149,12 +133,12 @@ bool ErrorType::_equalsImplOverride(Type* type) return false; } -RefPtr<Type> ErrorType::_createCanonicalTypeOverride() +Type* ErrorType::_createCanonicalTypeOverride() { return this; } -RefPtr<Val> 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<Type> DeclRefType::_createCanonicalTypeOverride() +Type* DeclRefType::_createCanonicalTypeOverride() { // A declaration reference is already canonical return this; } -RefPtr<Val> 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<Val> 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<GenericSubstitution>(); + auto genericSubst = as<GenericSubstitution>(s); if (!genericSubst) continue; @@ -215,7 +199,7 @@ RefPtr<Val> 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<Val> DeclRefType::_substituteImplOverride(ASTBuilder* astBuilder, Substit { for (auto s = substDeclRef.substitutions.substitutions; s; s = s->outer) { - auto thisSubst = s.as<ThisTypeSubstitution>(); + auto thisSubst = as<ThisTypeSubstitution>(s); if (!thisSubst) continue; @@ -325,7 +309,7 @@ bool BasicExpressionType::_equalsImplOverride(Type * type) return basicType && basicType->baseType == this->baseType; } -RefPtr<Type> 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<IntVal>(findInnerMostGenericSubstitution(declRef.substitutions)->args[2]); } -RefPtr<Type> MatrixExpressionType::getRowType() +Type* MatrixExpressionType::getRowType() { if (!rowType) { @@ -395,14 +379,14 @@ bool ArrayExpressionType::_equalsImplOverride(Type* type) auto arrType = as<ArrayExpressionType>(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<Val> 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<Type>(); - auto arrlen = arrayLength->substituteImpl(astBuilder, subst, &diff).as<IntVal>(); + auto elementType = as<Type>(baseType->substituteImpl(astBuilder, subst, &diff)); + auto arrlen = as<IntVal>(arrayLength->substituteImpl(astBuilder, subst, &diff)); SLANG_ASSERT(arrlen); if (diff) { @@ -416,7 +400,7 @@ RefPtr<Val> ArrayExpressionType::_substituteImplOverride(ASTBuilder* astBuilder, return this; } -RefPtr<Type> 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<Type> TypeType::_createCanonicalTypeOverride() +Type* TypeType::_createCanonicalTypeOverride() { return getASTBuilder()->getTypeType(type->getCanonicalType()); } @@ -492,7 +476,7 @@ HashCode GenericDeclRefType::_getHashCodeOverride() return declRef.getHashCode(); } -RefPtr<Type> GenericDeclRefType::_createCanonicalTypeOverride() +Type* GenericDeclRefType::_createCanonicalTypeOverride() { return this; } @@ -521,7 +505,7 @@ HashCode NamespaceType::_getHashCodeOverride() return declRef.getHashCode(); } -RefPtr<Type> NamespaceType::_createCanonicalTypeOverride() +Type* NamespaceType::_createCanonicalTypeOverride() { return this; } @@ -547,7 +531,7 @@ bool NamedExpressionType::_equalsImplOverride(Type * /*type*/) //return false; } -RefPtr<Type> NamedExpressionType::_createCanonicalTypeOverride() +Type* NamedExpressionType::_createCanonicalTypeOverride() { if (!innerType) innerType = getType(m_astBuilder, declRef); @@ -613,18 +597,18 @@ bool FuncType::_equalsImplOverride(Type * type) return false; } -RefPtr<Val> FuncType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* FuncType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; // result type - RefPtr<Type> substResultType = resultType->substituteImpl(astBuilder, subst, &diff).as<Type>(); + Type* substResultType = as<Type>(resultType->substituteImpl(astBuilder, subst, &diff)); // parameter types - List<RefPtr<Type>> substParamTypes; + List<Type*> substParamTypes; for (auto pp : paramTypes) { - substParamTypes.add(pp->substituteImpl(astBuilder, subst, &diff).as<Type>()); + substParamTypes.add(as<Type>(pp->substituteImpl(astBuilder, subst, &diff))); } // early exit for no change... @@ -632,26 +616,26 @@ RefPtr<Val> FuncType::_substituteImplOverride(ASTBuilder* astBuilder, Substituti return this; (*ioDiff)++; - RefPtr<FuncType> substType = astBuilder->create<FuncType>(); + FuncType* substType = astBuilder->create<FuncType>(); substType->resultType = substResultType; substType->paramTypes = substParamTypes; return substType; } -RefPtr<Type> FuncType::_createCanonicalTypeOverride() +Type* FuncType::_createCanonicalTypeOverride() { // result type - RefPtr<Type> canResultType = resultType->getCanonicalType(); + Type* canResultType = resultType->getCanonicalType(); // parameter types - List<RefPtr<Type>> canParamTypes; + List<Type*> canParamTypes; for (auto pp : paramTypes) { canParamTypes.add(pp->getCanonicalType()); } - RefPtr<FuncType> canType = getASTBuilder()->create<FuncType>(); - canType->resultType = resultType; + FuncType* canType = getASTBuilder()->create<FuncType>(); + canType->resultType = canResultType; canType->paramTypes = canParamTypes; return canType; @@ -695,12 +679,12 @@ HashCode ExtractExistentialType::_getHashCodeOverride() return declRef.getHashCode(); } -RefPtr<Type> ExtractExistentialType::_createCanonicalTypeOverride() +Type* ExtractExistentialType::_createCanonicalTypeOverride() { return this; } -RefPtr<Val> 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<Val> ExtractExistentialType::_substituteImplOverride(ASTBuilder* astBuild (*ioDiff)++; - RefPtr<ExtractExistentialType> substValue = astBuilder->create<ExtractExistentialType>(); + ExtractExistentialType* substValue = astBuilder->create<ExtractExistentialType>(); substValue->declRef = declRef; return substValue; } @@ -760,9 +744,9 @@ HashCode TaggedUnionType::_getHashCodeOverride() return hashCode; } -RefPtr<Type> TaggedUnionType::_createCanonicalTypeOverride() +Type* TaggedUnionType::_createCanonicalTypeOverride() { - RefPtr<TaggedUnionType> canType = m_astBuilder->create<TaggedUnionType>(); + TaggedUnionType* canType = m_astBuilder->create<TaggedUnionType>(); for (auto caseType : caseTypes) { @@ -773,21 +757,21 @@ RefPtr<Type> TaggedUnionType::_createCanonicalTypeOverride() return canType; } -RefPtr<Val> TaggedUnionType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +Val* TaggedUnionType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) { int diff = 0; - List<RefPtr<Type>> substCaseTypes; + List<Type*> substCaseTypes; for (auto caseType : caseTypes) { - substCaseTypes.add(caseType->substituteImpl(astBuilder, subst, &diff).as<Type>()); + substCaseTypes.add(as<Type>(caseType->substituteImpl(astBuilder, subst, &diff))); } if (!diff) return this; (*ioDiff)++; - RefPtr<TaggedUnionType> substType = astBuilder->create<TaggedUnionType>(); + TaggedUnionType* substType = astBuilder->create<TaggedUnionType>(); substType->caseTypes.swapWith(substCaseTypes); return substType; } @@ -848,7 +832,7 @@ HashCode ExistentialSpecializedType::_getHashCodeOverride() return hasher.getResult(); } -static RefPtr<Val> _getCanonicalValue(Val* val) +static Val* _getCanonicalValue(Val* val) { if (!val) return nullptr; @@ -861,9 +845,9 @@ static RefPtr<Val> _getCanonicalValue(Val* val) return val; } -RefPtr<Type> ExistentialSpecializedType::_createCanonicalTypeOverride() +Type* ExistentialSpecializedType::_createCanonicalTypeOverride() { - RefPtr<ExistentialSpecializedType> canType = m_astBuilder->create<ExistentialSpecializedType>(); + ExistentialSpecializedType* canType = m_astBuilder->create<ExistentialSpecializedType>(); canType->baseType = baseType->getCanonicalType(); for (auto arg : args) @@ -876,17 +860,17 @@ RefPtr<Type> ExistentialSpecializedType::_createCanonicalTypeOverride() return canType; } -static RefPtr<Val> _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<Val> 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<Type>(); + auto substBaseType = as<Type>(baseType->substituteImpl(astBuilder, subst, &diff)); ExpandedSpecializationArgs substArgs; for (auto arg : args) @@ -902,7 +886,7 @@ RefPtr<Val> ExistentialSpecializedType::_substituteImplOverride(ASTBuilder* astB (*ioDiff)++; - RefPtr<ExistentialSpecializedType> substType = astBuilder->create<ExistentialSpecializedType>(); + ExistentialSpecializedType* substType = astBuilder->create<ExistentialSpecializedType>(); substType->baseType = substBaseType; substType->args = substArgs; return substType; @@ -937,16 +921,16 @@ HashCode ThisType::_getHashCodeOverride() interfaceDeclRef.getHashCode()); } -RefPtr<Type> ThisType::_createCanonicalTypeOverride() +Type* ThisType::_createCanonicalTypeOverride() { - RefPtr<ThisType> canType = m_astBuilder->create<ThisType>(); + ThisType* canType = m_astBuilder->create<ThisType>(); // TODO: need to canonicalize the decl-ref canType->interfaceDeclRef = interfaceDeclRef; return canType; } -RefPtr<Val> 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<Val> ThisType::_substituteImplOverride(ASTBuilder* astBuilder, Substituti (*ioDiff)++; - RefPtr<ThisType> substType = m_astBuilder->create<ThisType>(); + ThisType* substType = m_astBuilder->create<ThisType>(); 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<Type> _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<Type> _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<Type> _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr<Val> _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<Decl> declRef; - static RefPtr<DeclRefType> create(ASTBuilder* astBuilder, DeclRef<Decl> declRef); + static DeclRefType* create(ASTBuilder* astBuilder, DeclRef<Decl> declRef); // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr<Type> _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr<Val> _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); protected: DeclRefType( DeclRef<Decl> declRef) @@ -88,7 +88,7 @@ class BasicExpressionType : public ArithmeticExpressionType BaseType baseType; // Overrides should be public so base classes can access - RefPtr<Type> _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<Type> 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<Type> 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<Type> 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<Type> elementType) + TextureSamplerType(TextureFlavor flavor, Type* elementType) : TextureTypeBase(flavor, elementType) {} }; @@ -170,7 +170,7 @@ class GLSLImageType : public TextureTypeBase protected: GLSLImageType( TextureFlavor flavor, - RefPtr<Type> elementType) + Type* elementType) : TextureTypeBase(flavor, elementType) {} }; @@ -188,7 +188,7 @@ class BuiltinGenericType : public BuiltinType { SLANG_CLASS(BuiltinGenericType) - RefPtr<Type> elementType; + Type* elementType = nullptr; Type* getElementType() { return elementType; } }; @@ -373,14 +373,14 @@ class ArrayExpressionType : public Type { SLANG_CLASS(ArrayExpressionType) - RefPtr<Type> baseType; - RefPtr<IntVal> arrayLength; + Type* baseType = nullptr; + IntVal* arrayLength = nullptr; // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr<Type> _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); - RefPtr<Val> _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* type = nullptr; // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr<Type> _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); protected: - TypeType(RefPtr<Type> 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<Type> elementType; + Type* elementType = nullptr; // The number of elements - RefPtr<IntVal> 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<Type> getRowType(); + Type* getRowType(); // Overrides should be public so base classes can access String _toStringOverride(); BasicExpressionType* _getScalarTypeOverride(); private: - RefPtr<Type> rowType; + Type* rowType = nullptr; }; // The built-in `String` type @@ -506,11 +506,11 @@ class NamedExpressionType : public Type SLANG_CLASS(NamedExpressionType) DeclRef<TypeDefDecl> declRef; - RefPtr<Type> innerType; + Type* innerType = nullptr; // Overrides should be public so base classes can access String _toStringOverride(); - RefPtr<Type> _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<RefPtr<Type>> paramTypes; - RefPtr<Type> resultType; + List<Type*> 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<Type> _createCanonicalTypeOverride(); - RefPtr<Val> _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<Type> _createCanonicalTypeOverride(); + Type* _createCanonicalTypeOverride(); protected: GenericDeclRefType( @@ -585,7 +585,7 @@ class NamespaceType : public Type String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr<Type> _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<Type> _createCanonicalTypeOverride(); - RefPtr<Val> _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<RefPtr<Type>> caseTypes; + List<Type*> caseTypes; // Overrides should be public so base classes can access String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr<Type> _createCanonicalTypeOverride(); - RefPtr<Val> _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<Type> baseType; + Type* baseType = nullptr; ExpandedSpecializationArgs args; // Overrides should be public so base classes can access String _toStringOverride(); bool _equalsImplOverride(Type* type); HashCode _getHashCodeOverride(); - RefPtr<Type> _createCanonicalTypeOverride(); - RefPtr<Val> _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<Type> _createCanonicalTypeOverride(); - RefPtr<Val> _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> 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> 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> 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<Val> 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<GenericSubstitution>(); + auto genSubst = as<GenericSubstitution>(s); if (!genSubst) continue; @@ -122,7 +122,7 @@ RefPtr<Val> 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<Val> 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<Val> TypeEqualityWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) +Val* TypeEqualityWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) { - RefPtr<TypeEqualityWitness> rs = astBuilder->create<TypeEqualityWitness>(); - rs->sub = sub->substituteImpl(astBuilder, subst, ioDiff).as<Type>(); - rs->sup = sup->substituteImpl(astBuilder, subst, ioDiff).as<Type>(); + TypeEqualityWitness* rs = astBuilder->create<TypeEqualityWitness>(); + rs->sub = as<Type>(sub->substituteImpl(astBuilder, subst, ioDiff)); + rs->sup = as<Type>(sup->substituteImpl(astBuilder, subst, ioDiff)); return rs; } @@ -218,7 +218,7 @@ bool DeclaredSubtypeWitness::_equalsValOverride(Val* val) && declRef.equals(otherWitness->declRef); } -RefPtr<Val> DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) +Val* DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) { if (auto genConstraintDeclRef = declRef.as<GenericTypeConstraintDecl>()) { @@ -258,7 +258,7 @@ RefPtr<Val> DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuild return genericSubst->args[index + ordinaryParamCount]; } } - else if (auto globalGenericSubst = s.as<GlobalGenericParamSubstitution>()) + else if (auto globalGenericSubst = as<GlobalGenericParamSubstitution>(s)) { // check if the substitution is really about this global generic type parameter if (globalGenericSubst->paramDecl != genConstraintDecl->parentDecl) @@ -266,7 +266,7 @@ RefPtr<Val> 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<Val> DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuild // Perform substitution on the constituent elements. int diff = 0; - auto substSub = sub->substituteImpl(astBuilder, subst, &diff).as<Type>(); - auto substSup = sup->substituteImpl(astBuilder, subst, &diff).as<Type>(); + auto substSub = as<Type>(sub->substituteImpl(astBuilder, subst, &diff)); + auto substSup = as<Type>(sup->substituteImpl(astBuilder, subst, &diff)); auto substDeclRef = declRef.substituteImpl(astBuilder, subst, &diff); if (!diff) return this; @@ -327,7 +327,7 @@ RefPtr<Val> DeclaredSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuild } } - RefPtr<DeclaredSubtypeWitness> rs = astBuilder->create<DeclaredSubtypeWitness>(); + DeclaredSubtypeWitness* rs = astBuilder->create<DeclaredSubtypeWitness>(); rs->sub = substSub; rs->sup = substSup; rs->declRef = substDeclRef; @@ -366,13 +366,13 @@ bool TransitiveSubtypeWitness::_equalsValOverride(Val* val) && midToSup.equals(otherWitness->midToSup); } -RefPtr<Val> TransitiveSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) +Val* TransitiveSubtypeWitness::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int * ioDiff) { int diff = 0; - RefPtr<Type> substSub = sub->substituteImpl(astBuilder, subst, &diff).as<Type>(); - RefPtr<Type> substSup = sup->substituteImpl(astBuilder, subst, &diff).as<Type>(); - RefPtr<SubtypeWitness> substSubToMid = subToMid->substituteImpl(astBuilder, subst, &diff).as<SubtypeWitness>(); + Type* substSub = as<Type>(sub->substituteImpl(astBuilder, subst, &diff)); + Type* substSup = as<Type>(sup->substituteImpl(astBuilder, subst, &diff)); + SubtypeWitness* substSubToMid = as<SubtypeWitness>(subToMid->substituteImpl(astBuilder, subst, &diff)); DeclRef<Decl> substMidToSup = midToSup.substituteImpl(astBuilder, subst, &diff); // If nothing changed, then we can bail out early. @@ -399,7 +399,7 @@ RefPtr<Val> TransitiveSubtypeWitness::_substituteImplOverride(ASTBuilder* astBui // In the simple case, we just construct a new transitive subtype // witness, and we move on with life. - RefPtr<TransitiveSubtypeWitness> result = astBuilder->create<TransitiveSubtypeWitness>(); + TransitiveSubtypeWitness* result = astBuilder->create<TransitiveSubtypeWitness>(); result->sub = substSub; result->sup = substSup; result->subToMid = substSubToMid; @@ -455,20 +455,20 @@ HashCode ExtractExistentialSubtypeWitness::_getHashCodeOverride() return declRef.getHashCode(); } -RefPtr<Val> 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<Type>(); - auto substSup = sup->substituteImpl(astBuilder, subst, &diff).as<Type>(); + auto substSub = as<Type>(sub->substituteImpl(astBuilder, subst, &diff)); + auto substSup = as<Type>(sup->substituteImpl(astBuilder, subst, &diff)); if (!diff) return this; (*ioDiff)++; - RefPtr<ExtractExistentialSubtypeWitness> substValue = astBuilder->create<ExtractExistentialSubtypeWitness>(); + ExtractExistentialSubtypeWitness* substValue = astBuilder->create<ExtractExistentialSubtypeWitness>(); substValue->declRef = declRef; substValue->sub = substSub; substValue->sup = substSup; @@ -522,14 +522,14 @@ HashCode TaggedUnionSubtypeWitness::_getHashCodeOverride() return hash; } -RefPtr<Val> 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<Type>(); - auto substSup = sup->substituteImpl(astBuilder, subst, &diff).as<Type>(); + auto substSub = as<Type>(sub->substituteImpl(astBuilder, subst, &diff)); + auto substSup = as<Type>(sup->substituteImpl(astBuilder, subst, &diff)); - List<RefPtr<Val>> substCaseWitnesses; + List<Val*> substCaseWitnesses; for (auto caseWitness : caseWitnesses) { substCaseWitnesses.add(caseWitness->substituteImpl(astBuilder, subst, &diff)); @@ -540,7 +540,7 @@ RefPtr<Val> TaggedUnionSubtypeWitness::_substituteImplOverride(ASTBuilder* astBu (*ioDiff)++; - RefPtr<TaggedUnionSubtypeWitness> substWitness = astBuilder->create<TaggedUnionSubtypeWitness>(); + TaggedUnionSubtypeWitness* substWitness = astBuilder->create<TaggedUnionSubtypeWitness>(); 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<Val> _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); protected: GenericParamIntVal(DeclRef<VarDeclBase> inDeclRef) @@ -65,7 +65,7 @@ class ErrorIntVal : public IntVal bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr<Val> _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<Type> sub; - RefPtr<Type> 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<Val> _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<Val> _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<SubtypeWitness> subToMid; + SubtypeWitness* subToMid = nullptr; // Witness that `mid : sup` DeclRef<Decl> midToSup; @@ -160,7 +160,7 @@ class TransitiveSubtypeWitness : public SubtypeWitness bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr<Val> _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<Val> _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<RefPtr<Val>> caseWitnesses; + List<Val*> caseWitnesses; // Overrides should be public so base classes can access bool _equalsValOverride(Val* val); String _toStringOverride(); HashCode _getHashCodeOverride(); - RefPtr<Val> _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<DeclaredSubtypeWitness> SemanticsVisitor::createSimpleSubtypeWitness( + DeclaredSubtypeWitness* SemanticsVisitor::createSimpleSubtypeWitness( TypeWitnessBreadcrumb* breadcrumb) { - RefPtr<DeclaredSubtypeWitness> witness = m_astBuilder->create<DeclaredSubtypeWitness>(); + DeclaredSubtypeWitness* witness = m_astBuilder->create<DeclaredSubtypeWitness>(); witness->sub = breadcrumb->sub; witness->sup = breadcrumb->sup; witness->declRef = breadcrumb->declRef; return witness; } - RefPtr<Val> SemanticsVisitor::createTypeWitness( - RefPtr<Type> subType, + Val* SemanticsVisitor::createTypeWitness( + Type* subType, DeclRef<AggTypeDecl> 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<SubtypeWitness> witness; + SubtypeWitness* witness = nullptr; // `link` will point at the remaining "hole" in the // data structure, to be filled in. - RefPtr<SubtypeWitness>* 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<TransitiveSubtypeWitness> transitiveWitness = m_astBuilder->create<TransitiveSubtypeWitness>(); + TransitiveSubtypeWitness* transitiveWitness = m_astBuilder->create<TransitiveSubtypeWitness>(); 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<DeclaredSubtypeWitness> 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<InterfaceDecl> interfaceDeclRef, DeclRef<Decl> requirementDeclRef) { + SLANG_UNUSED(interfaceDeclRef); + if(auto callableDeclRef = requirementDeclRef.as<CallableDecl>()) { // A `static` method requirement can't be satisfied by a @@ -146,10 +151,10 @@ namespace Slang } bool SemanticsVisitor::_isDeclaredSubtype( - RefPtr<Type> originalSubType, - RefPtr<Type> subType, + Type* originalSubType, + Type* subType, DeclRef<AggTypeDecl> superTypeDeclRef, - RefPtr<Val>* 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<RefPtr<Val>> caseWitnesses; + List<Val*> caseWitnesses; for(auto caseType : taggedUnionType->caseTypes) { - RefPtr<Val> caseWitness; + Val* caseWitness = nullptr; if(!_isDeclaredSubtype( caseType, @@ -316,7 +321,7 @@ namespace Slang // if(outWitness) { - RefPtr<TaggedUnionSubtypeWitness> taggedUnionWitness = m_astBuilder->create<TaggedUnionSubtypeWitness>(); + TaggedUnionSubtypeWitness* taggedUnionWitness = m_astBuilder->create<TaggedUnionSubtypeWitness>(); taggedUnionWitness->sub = taggedUnionType; taggedUnionWitness->sup = DeclRefType::create(m_astBuilder, superTypeDeclRef); taggedUnionWitness->caseWitnesses.swapWith(caseWitnesses); @@ -331,41 +336,40 @@ namespace Slang } bool SemanticsVisitor::isDeclaredSubtype( - RefPtr<Type> subType, + Type* subType, DeclRef<AggTypeDecl> superTypeDeclRef) { return _isDeclaredSubtype(subType, subType, superTypeDeclRef, nullptr, nullptr); } - RefPtr<Val> SemanticsVisitor::tryGetSubtypeWitness( - RefPtr<Type> subType, + Val* SemanticsVisitor::tryGetSubtypeWitness( + Type* subType, DeclRef<AggTypeDecl> superTypeDeclRef) { - RefPtr<Val> result; + Val* result = nullptr; _isDeclaredSubtype(subType, subType, superTypeDeclRef, &result, nullptr); return result; } - - RefPtr<Val> SemanticsVisitor::tryGetInterfaceConformanceWitness( - RefPtr<Type> type, + Val* SemanticsVisitor::tryGetInterfaceConformanceWitness( + Type* type, DeclRef<InterfaceDecl> interfaceDeclRef) { return tryGetSubtypeWitness(type, interfaceDeclRef); } - RefPtr<Val> SemanticsVisitor::createTypeEqualityWitness( + Val* SemanticsVisitor::createTypeEqualityWitness( Type* type) { - RefPtr<TypeEqualityWitness> rs = m_astBuilder->create<TypeEqualityWitness>(); + TypeEqualityWitness* rs = m_astBuilder->create<TypeEqualityWitness>(); rs->sub = type; rs->sup = type; return rs; } - RefPtr<Val> SemanticsVisitor::tryGetSubtypeWitness( - RefPtr<Type> sub, - RefPtr<Type> 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<Type> SemanticsVisitor::TryJoinVectorAndScalarType( - RefPtr<VectorExpressionType> vectorType, - RefPtr<BasicExpressionType> scalarType) + Type* SemanticsVisitor::TryJoinVectorAndScalarType( + VectorExpressionType* vectorType, + BasicExpressionType* scalarType) { // Join( vector<T,N>, S ) -> vetor<Join(T,S), N> // @@ -75,8 +75,8 @@ namespace Slang vectorType->elementCount); } - RefPtr<Type> SemanticsVisitor::TryJoinTypeWithInterface( - RefPtr<Type> type, + Type* SemanticsVisitor::TryJoinTypeWithInterface( + Type* type, DeclRef<InterfaceDecl> 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<Type> bestType; - if(auto basicType = type.dynamicCast<BasicExpressionType>()) + Type* bestType = nullptr; + if(auto basicType = dynamicCast<BasicExpressionType>(type)) { for(Int baseTypeFlavorIndex = 0; baseTypeFlavorIndex < Int(BaseType::CountOf); baseTypeFlavorIndex++) { @@ -173,9 +173,9 @@ namespace Slang return nullptr; } - RefPtr<Type> SemanticsVisitor::TryJoinTypes( - RefPtr<Type> left, - RefPtr<Type> 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<VectorExpressionType>(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<RefPtr<Val>> args; + List<Val*> args; for (auto m : getMembers(genericDeclRef)) { if (auto typeParam = m.as<GenericTypeParamDecl>()) { - RefPtr<Type> 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<IntVal> 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<GenericSubstitution> solvedSubst = m_astBuilder->create<GenericSubstitution>(); + GenericSubstitution* solvedSubst = m_astBuilder->create<GenericSubstitution>(); solvedSubst->genericDecl = genericDeclRef.getDecl(); solvedSubst->outer = genericDeclRef.substitutions.substitutions; solvedSubst->args = args; @@ -442,8 +442,8 @@ namespace Slang bool SemanticsVisitor::TryUnifyVals( ConstraintSystem& constraints, - RefPtr<Val> fst, - RefPtr<Val> snd) + Val* fst, + Val* snd) { // if both values are types, then unify types if (auto fstType = as<Type>(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<Substitutions> fst, - RefPtr<Substitutions> 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<GenericSubstitution> fst, - RefPtr<GenericSubstitution> snd) + GenericSubstitution* fst, + GenericSubstitution* snd) { SLANG_ASSERT(fst); SLANG_ASSERT(snd); @@ -568,13 +568,13 @@ namespace Slang bool SemanticsVisitor::TryUnifyTypeParam( ConstraintSystem& constraints, - RefPtr<GenericTypeParamDecl> typeParamDecl, - RefPtr<Type> 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<GenericValueParamDecl> paramDecl, - RefPtr<IntVal> 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<VarDeclBase> const& varRef, - RefPtr<IntVal> val) + IntVal* val) { if(auto genericValueParamRef = varRef.as<GenericValueParamDecl>()) { - return TryUnifyIntParam(constraints, RefPtr<GenericValueParamDecl>(genericValueParamRef.getDecl()), val); + return TryUnifyIntParam(constraints, genericValueParamRef.getDecl(), val); } else { @@ -622,8 +622,8 @@ namespace Slang bool SemanticsVisitor::TryUnifyTypesByStructuralMatch( ConstraintSystem& constraints, - RefPtr<Type> fst, - RefPtr<Type> snd) + Type* fst, + Type* snd) { if (auto fstDeclRefType = as<DeclRefType>(fst)) { @@ -661,8 +661,8 @@ namespace Slang bool SemanticsVisitor::TryUnifyTypes( ConstraintSystem& constraints, - RefPtr<Type> fst, - RefPtr<Type> 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* type) { if(as<ArrayExpressionType>(type)) return false; if(as<VectorExpressionType>(type)) return false; @@ -58,8 +58,8 @@ namespace Slang } bool SemanticsVisitor::shouldUseInitializerDirectly( - RefPtr<Type> toType, - RefPtr<Expr> fromExpr) + Type* toType, + Expr* fromExpr) { // A nested initializer list should always be used directly. // @@ -89,9 +89,9 @@ namespace Slang } bool SemanticsVisitor::_readValueFromInitializerList( - RefPtr<Type> toType, - RefPtr<Expr>* outToExpr, - RefPtr<InitializerListExpr> 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<Type> inToType, - RefPtr<Expr>* outToExpr, - RefPtr<InitializerListExpr> 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<RefPtr<Expr>> coercedArgs; + List<Expr*> coercedArgs; if(isEffectivelyScalarForInitializerLists(toType)) { @@ -215,7 +215,7 @@ namespace Slang for(UInt ee = 0; ee < elementCount; ++ee) { - RefPtr<Expr> 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<Expr> coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toElementType, outToExpr ? &coercedArg : nullptr, @@ -289,7 +289,7 @@ namespace Slang UInt elementCount = 0; while(ioArgIndex < argCount) { - RefPtr<Expr> 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<Expr> coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( toRowType, outToExpr ? &coercedArg : nullptr, @@ -380,7 +380,7 @@ namespace Slang // for(auto fieldDeclRef : getMembersOfType<VarDecl>(toStructDeclRef, MemberFilterStyle::Instance)) { - RefPtr<Expr> coercedArg; + Expr* coercedArg = nullptr; bool argResult = _readValueFromInitializerList( getType(m_astBuilder, fieldDeclRef), outToExpr ? &coercedArg : nullptr, @@ -429,9 +429,9 @@ namespace Slang } bool SemanticsVisitor::_coerceInitializerList( - RefPtr<Type> toType, - RefPtr<Expr>* outToExpr, - RefPtr<InitializerListExpr> 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<Type> toType, - RefPtr<Expr>* outToExpr, - RefPtr<Expr> fromExpr) + Type* toType, + Expr** outToExpr, + Expr* fromExpr) { if(outToExpr) { @@ -478,10 +478,10 @@ namespace Slang } bool SemanticsVisitor::_coerce( - RefPtr<Type> toType, - RefPtr<Expr>* outToExpr, - RefPtr<Type> fromType, - RefPtr<Expr> 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* derefExpr = nullptr; if(outToExpr) { derefExpr = m_astBuilder->create<DerefExpr>(); @@ -754,8 +754,8 @@ namespace Slang } bool SemanticsVisitor::canCoerce( - RefPtr<Type> toType, - RefPtr<Type> 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<TypeCastExpr> SemanticsVisitor::createImplicitCastExpr() + TypeCastExpr* SemanticsVisitor::createImplicitCastExpr() { return m_astBuilder->create<ImplicitCastExpr>(); } - RefPtr<Expr> SemanticsVisitor::CreateImplicitCastExpr( - RefPtr<Type> toType, - RefPtr<Expr> fromExpr) + Expr* SemanticsVisitor::CreateImplicitCastExpr( + Type* toType, + Expr* fromExpr) { - RefPtr<TypeCastExpr> castExpr = createImplicitCastExpr(); + TypeCastExpr* castExpr = createImplicitCastExpr(); auto typeType = m_astBuilder->getTypeType(toType); @@ -835,12 +835,12 @@ namespace Slang return castExpr; } - RefPtr<Expr> SemanticsVisitor::createCastToSuperTypeExpr( - RefPtr<Type> toType, - RefPtr<Expr> fromExpr, - RefPtr<Val> witness) + Expr* SemanticsVisitor::createCastToSuperTypeExpr( + Type* toType, + Expr* fromExpr, + Val* witness) { - RefPtr<CastToSuperTypeExpr> expr = m_astBuilder->create<CastToSuperTypeExpr>(); + CastToSuperTypeExpr* expr = m_astBuilder->create<CastToSuperTypeExpr>(); expr->loc = fromExpr->loc; expr->type = QualType(toType); expr->valueArg = fromExpr; @@ -848,16 +848,16 @@ namespace Slang return expr; } - RefPtr<Expr> SemanticsVisitor::coerce( - RefPtr<Type> toType, - RefPtr<Expr> fromExpr) + Expr* SemanticsVisitor::coerce( + Type* toType, + Expr* fromExpr) { - RefPtr<Expr> 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<Type> toType, - RefPtr<Type> 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<VarDeclBase> varDecl); + void checkVarDeclCommon(VarDeclBase* varDecl); void visitVarDecl(VarDecl* varDecl) { @@ -149,7 +149,7 @@ namespace Slang void visitDecl(Decl*) {} void visitDeclGroup(DeclGroup*) {} - void checkVarDeclCommon(RefPtr<VarDeclBase> varDecl); + void checkVarDeclCommon(VarDeclBase* varDecl); void visitVarDecl(VarDecl* varDecl) { @@ -290,7 +290,7 @@ namespace Slang SemanticsVisitor* sema, DiagnosticSink* sink, DeclRef<Decl> declRef, - RefPtr<Type>* outTypeResult, + Type** outTypeResult, SourceLoc loc) { if( sema ) @@ -452,14 +452,14 @@ namespace Slang DeclRef<Decl> declRef, SourceLoc loc) { - RefPtr<Type> typeResult; + Type* typeResult = nullptr; return getTypeForDeclRef(astBuilder, nullptr, nullptr, declRef, &typeResult, loc); } DeclRef<ExtensionDecl> ApplyExtensionToType( SemanticsVisitor* semantics, ExtensionDecl* extDecl, - RefPtr<Type> type) + Type* type) { if(!semantics) return DeclRef<ExtensionDecl>(); @@ -467,12 +467,12 @@ namespace Slang return semantics->ApplyExtensionToType(extDecl, type); } - RefPtr<GenericSubstitution> createDefaultSubstitutionsForGeneric( + GenericSubstitution* createDefaultSubstitutionsForGeneric( ASTBuilder* astBuilder, GenericDecl* genericDecl, - RefPtr<Substitutions> outerSubst) + Substitutions* outerSubst) { - RefPtr<GenericSubstitution> genericSubst = astBuilder->create<GenericSubstitution>(); + GenericSubstitution* genericSubst = astBuilder->create<GenericSubstitution>(); genericSubst->genericDecl = genericDecl; genericSubst->outer = outerSubst; @@ -493,7 +493,7 @@ namespace Slang { if (auto genericTypeConstraintDecl = as<GenericTypeConstraintDecl>(mm)) { - RefPtr<DeclaredSubtypeWitness> witness = astBuilder->create<DeclaredSubtypeWitness>(); + DeclaredSubtypeWitness* witness = astBuilder->create<DeclaredSubtypeWitness>(); witness->declRef = DeclRef<Decl>(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<GenericSubstitution> genericSubst = createDefaultSubstitutionsForGeneric( + GenericSubstitution* genericSubst = createDefaultSubstitutionsForGeneric( astBuilder, genericDecl, outerSubstSet.substitutions); @@ -775,7 +775,7 @@ namespace Slang return true; } - void SemanticsDeclHeaderVisitor::checkVarDeclCommon(RefPtr<VarDeclBase> 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<VarDeclBase> 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<ImportDecl>()) + for(auto importDecl : moduleDecl->getMembersOfType<ImportDecl>()) { ensureDecl(importDecl, DeclCheckState::Checked); } @@ -1263,13 +1263,13 @@ namespace Slang // be compared). return doesMemberSatisfyRequirement( - DeclRef<Decl>(genDecl.getDecl()->inner.Ptr(), genDecl.substitutions), - DeclRef<Decl>(requirementGenDecl.getDecl()->inner.Ptr(), requirementGenDecl.substitutions), + DeclRef<Decl>(genDecl.getDecl()->inner, genDecl.substitutions), + DeclRef<Decl>(requirementGenDecl.getDecl()->inner, requirementGenDecl.substitutions), witnessTable); } bool SemanticsVisitor::doesTypeSatisfyAssociatedTypeRequirement( - RefPtr<Type> satisfyingType, + Type* satisfyingType, DeclRef<AssocTypeDecl> requiredAssociatedTypeDeclRef, RefPtr<WitnessTable> witnessTable) { @@ -1426,6 +1426,8 @@ namespace Slang DeclRef<Decl> requiredMemberDeclRef, RefPtr<WitnessTable> 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<Type> 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<Type> tagType; - InheritanceDecl* tagTypeInheritanceDecl = nullptr; + + Type* tagType = nullptr; + InheritanceDecl* tagTypeInheritanceDecl = nullptr; for(auto inheritanceDecl : decl->getMembersOfType<InheritanceDecl>()) { 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<Type> enumTypeType = getASTBuilder()->getEnumTypeType(); + Type* enumTypeType = getASTBuilder()->getEnumTypeType(); - RefPtr<InheritanceDecl> enumConformanceDecl = m_astBuilder->create<InheritanceDecl>(); + InheritanceDecl* enumConformanceDecl = m_astBuilder->create<InheritanceDecl>(); 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<DeclRefType>()) + if(auto enumTypeTypeDeclRefType = dynamicCast<DeclRefType>(enumTypeType)) { if(auto enumTypeTypeInterfaceDecl = as<InterfaceDecl>(enumTypeTypeDeclRefType->declRef.getDecl())) { @@ -2174,7 +2177,7 @@ namespace Slang // the tag value for a successor case that doesn't // provide an explicit tag. - RefPtr<IntVal> explicitTagVal = TryConstantFoldExpr(explicitTagValExpr); + IntVal* explicitTagVal = TryConstantFoldExpr(explicitTagValExpr); if(explicitTagVal) { if(auto constIntVal = as<ConstantIntVal>(explicitTagVal)) @@ -2198,7 +2201,7 @@ namespace Slang { // This tag has no initializer, so it should use // the default tag value we are tracking. - RefPtr<IntegerLiteralExpr> tagValExpr = m_astBuilder->create<IntegerLiteralExpr>(); + IntegerLiteralExpr* tagValExpr = m_astBuilder->create<IntegerLiteralExpr>(); 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<GenericSubstitution>* 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<GenericSubstitution> SemanticsVisitor::createDummySubstitutions( + GenericSubstitution* SemanticsVisitor::createDummySubstitutions( GenericDecl* genericDecl) { - RefPtr<GenericSubstitution> subst = m_astBuilder->create<GenericSubstitution>(); + GenericSubstitution* subst = m_astBuilder->create<GenericSubstitution>(); 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<U>`. // - RefPtr<GenericSubstitution> 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<IntVal> val) + IntegerLiteralValue SemanticsVisitor::GetMinBound(IntVal* val) { if (auto constantVal = as<ConstantIntVal>(val)) return constantVal->value; @@ -3145,7 +3148,7 @@ namespace Slang } } - RefPtr<Type> SemanticsVisitor::calcThisType(DeclRef<Decl> declRef) + Type* SemanticsVisitor::calcThisType(DeclRef<Decl> declRef) { if( auto interfaceDeclRef = declRef.as<InterfaceDecl>() ) { @@ -3154,7 +3157,7 @@ namespace Slang // conform to the interface and fill in its // requirements. // - RefPtr<ThisType> thisType = m_astBuilder->create<ThisType>(); + ThisType* thisType = m_astBuilder->create<ThisType>(); thisType->interfaceDeclRef = interfaceDeclRef; return thisType; } @@ -3203,7 +3206,7 @@ namespace Slang } } - RefPtr<Type> SemanticsVisitor::calcThisType(Type* type) + Type* SemanticsVisitor::calcThisType(Type* type) { if( auto declRefType = as<DeclRefType>(type) ) { @@ -3215,7 +3218,7 @@ namespace Slang } } - RefPtr<Type> 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> getterDecl = m_astBuilder->create<GetterDecl>(); + GetterDecl* getterDecl = m_astBuilder->create<GetterDecl>(); getterDecl->loc = decl->loc; getterDecl->parentDecl = decl; @@ -3310,7 +3313,7 @@ namespace Slang DeclRef<ExtensionDecl> SemanticsVisitor::ApplyExtensionToType( ExtensionDecl* extDecl, - RefPtr<Type> type) + Type* type) { DeclRef<ExtensionDecl> extDeclRef = makeDeclRef(extDecl); @@ -3339,7 +3342,7 @@ namespace Slang } // Now extract the target type from our (possibly specialized) extension decl-ref. - RefPtr<Type> 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<ThisTypeSubstitution>()) + if(auto appThisTypeSubst = as<ThisTypeSubstitution>(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<ThisTypeSubstitution>()); + SLANG_ASSERT(!as<ThisTypeSubstitution>(targetInterfaceDeclRef.substitutions.substitutions)); // We will create a new substitution to apply to the target type. - RefPtr<ThisTypeSubstitution> newTargetSubst = m_astBuilder->create<ThisTypeSubstitution>(); + ThisTypeSubstitution* newTargetSubst = m_astBuilder->create<ThisTypeSubstitution>(); 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<ThisTypeSubstitution> newExtSubst = m_astBuilder->create<ThisTypeSubstitution>(); + ThisTypeSubstitution* newExtSubst = m_astBuilder->create<ThisTypeSubstitution>(); newExtSubst->interfaceDecl = appThisTypeSubst->interfaceDecl; newExtSubst->witness = appThisTypeSubst->witness; newExtSubst->outer = extDeclRef.substitutions.substitutions; @@ -3425,7 +3428,7 @@ namespace Slang QualType SemanticsVisitor::GetTypeForDeclRef(DeclRef<Decl> declRef, SourceLoc loc) { - RefPtr<Type> typeResult; + Type* typeResult = nullptr; return getTypeForDeclRef( m_astBuilder, this, @@ -3462,7 +3465,7 @@ namespace Slang if (!importDecl->hasModifier<ExportedModifier>()) 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<DeclRefType> SemanticsVisitor::getExprDeclRefType(Expr * expr) + DeclRefType* SemanticsVisitor::getExprDeclRefType(Expr * expr) { if (auto typetype = as<TypeType>(expr->type)) - return typetype->type.dynamicCast<DeclRefType>(); + return dynamicCast<DeclRefType>(typetype->type); else return as<DeclRefType>(expr->type); } @@ -29,18 +29,18 @@ namespace Slang /// the temporary, and the computation created by `func`. /// template<typename F> - RefPtr<Expr> SemanticsVisitor::moveTemp(RefPtr<Expr> const& expr, F const& func) + Expr* SemanticsVisitor::moveTemp(Expr* const& expr, F const& func) { - RefPtr<VarDecl> varDecl = m_astBuilder->create<VarDecl>(); + VarDecl* varDecl = m_astBuilder->create<VarDecl>(); 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> letExpr = m_astBuilder->create<LetExpr>(); + LetExpr* letExpr = m_astBuilder->create<LetExpr>(); letExpr->decl = varDecl; auto body = func(varDeclRef); @@ -58,7 +58,7 @@ namespace Slang /// a new variable to hold `expr`, using `moveTemp()`. /// template<typename F> - RefPtr<Expr> SemanticsVisitor::maybeMoveTemp(RefPtr<Expr> const& expr, F const& func) + Expr* SemanticsVisitor::maybeMoveTemp(Expr* const& expr, F const& func) { if(auto varExpr = as<VarExpr>(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<Expr> SemanticsVisitor::openExistential( - RefPtr<Expr> expr, + Expr* SemanticsVisitor::openExistential( + Expr* expr, DeclRef<InterfaceDecl> interfaceDeclRef) { // If `expr` refers to an immutable binding, @@ -102,15 +102,15 @@ namespace Slang auto interfaceDecl = interfaceDeclRef.getDecl(); return maybeMoveTemp(expr, [&](DeclRef<VarDeclBase> varDeclRef) { - RefPtr<ExtractExistentialType> openedType = m_astBuilder->create<ExtractExistentialType>(); + ExtractExistentialType* openedType = m_astBuilder->create<ExtractExistentialType>(); openedType->declRef = varDeclRef; - RefPtr<ExtractExistentialSubtypeWitness> openedWitness = m_astBuilder->create<ExtractExistentialSubtypeWitness>(); + ExtractExistentialSubtypeWitness* openedWitness = m_astBuilder->create<ExtractExistentialSubtypeWitness>(); openedWitness->sub = openedType; openedWitness->sup = expr->type.type; openedWitness->declRef = varDeclRef; - RefPtr<ThisTypeSubstitution> openedThisType = m_astBuilder->create<ThisTypeSubstitution>(); + ThisTypeSubstitution* openedThisType = m_astBuilder->create<ThisTypeSubstitution>(); openedThisType->outer = interfaceDeclRef.substitutions.substitutions; openedThisType->interfaceDecl = interfaceDecl; openedThisType->witness = openedWitness; @@ -118,7 +118,7 @@ namespace Slang DeclRef<InterfaceDecl> substDeclRef = DeclRef<InterfaceDecl>(interfaceDecl, openedThisType); auto substDeclRefType = DeclRefType::create(m_astBuilder, substDeclRef); - RefPtr<ExtractExistentialValueExpr> openedValue = m_astBuilder->create<ExtractExistentialValueExpr>(); + ExtractExistentialValueExpr* openedValue = m_astBuilder->create<ExtractExistentialValueExpr>(); 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<Expr> SemanticsVisitor::maybeOpenExistential(RefPtr<Expr> 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<ThisTypeSubstitution>(); + auto thisTypeSubst = as<ThisTypeSubstitution>(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<Expr> SemanticsVisitor::ConstructDeclRefExpr( + Expr* SemanticsVisitor::ConstructDeclRefExpr( DeclRef<Decl> declRef, - RefPtr<Expr> 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<SharedTypeExpr> baseTypeExpr = m_astBuilder->create<SharedTypeExpr>(); + SharedTypeExpr* baseTypeExpr = m_astBuilder->create<SharedTypeExpr>(); baseTypeExpr->base.type = baseExprType; baseTypeExpr->type.type = m_astBuilder->getTypeType(baseExprType); @@ -283,8 +283,8 @@ namespace Slang } } - RefPtr<Expr> SemanticsVisitor::ConstructDerefExpr( - RefPtr<Expr> base, + Expr* SemanticsVisitor::ConstructDerefExpr( + Expr* base, SourceLoc loc) { auto ptrLikeType = as<PointerLikeType>(base->type); @@ -300,9 +300,9 @@ namespace Slang return derefExpr; } - RefPtr<Expr> SemanticsVisitor::ConstructLookupResultExpr( + Expr* SemanticsVisitor::ConstructLookupResultExpr( LookupResultItem const& item, - RefPtr<Expr> 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<ThisExpr> expr = m_astBuilder->create<ThisExpr>(); + ThisExpr* expr = m_astBuilder->create<ThisExpr>(); expr->type.type = thisType; expr->loc = loc; @@ -411,10 +411,10 @@ namespace Slang return ConstructDeclRefExpr(item.declRef, bb, loc); } - RefPtr<Expr> SemanticsVisitor::createLookupResultExpr( + Expr* SemanticsVisitor::createLookupResultExpr( Name* name, LookupResult const& lookupResult, - RefPtr<Expr> baseExpr, + Expr* baseExpr, SourceLoc loc) { if (lookupResult.isOverloaded()) @@ -513,7 +513,7 @@ namespace Slang } } - RefPtr<Expr> SemanticsVisitor::_resolveOverloadedExprImpl(RefPtr<OverloadedExpr> 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<Expr> SemanticsVisitor::maybeResolveOverloadedExpr(RefPtr<Expr> expr, LookupMask mask, DiagnosticSink* diagSink) + Expr* SemanticsVisitor::maybeResolveOverloadedExpr(Expr* expr, LookupMask mask, DiagnosticSink* diagSink) { if( auto overloadedExpr = as<OverloadedExpr>(expr) ) { @@ -580,12 +580,12 @@ namespace Slang } } - RefPtr<Expr> SemanticsVisitor::resolveOverloadedExpr(RefPtr<OverloadedExpr> overloadedExpr, LookupMask mask) + Expr* SemanticsVisitor::resolveOverloadedExpr(OverloadedExpr* overloadedExpr, LookupMask mask) { return _resolveOverloadedExprImpl(overloadedExpr, mask, getSink()); } - RefPtr<Expr> SemanticsVisitor::CheckTerm(RefPtr<Expr> term) + Expr* SemanticsVisitor::CheckTerm(Expr* term) { if (!term) return nullptr; @@ -593,13 +593,13 @@ namespace Slang return exprVisitor.dispatch(term); } - RefPtr<Expr> SemanticsVisitor::CreateErrorExpr(Expr* expr) + Expr* SemanticsVisitor::CreateErrorExpr(Expr* expr) { expr->type = QualType(m_astBuilder->getErrorType()); return expr; } - bool SemanticsVisitor::IsErrorExpr(RefPtr<Expr> expr) + bool SemanticsVisitor::IsErrorExpr(Expr* expr) { // TODO: we may want other cases here... @@ -609,7 +609,7 @@ namespace Slang return false; } - RefPtr<Expr> SemanticsVisitor::GetBaseExpr(RefPtr<Expr> expr) + Expr* SemanticsVisitor::GetBaseExpr(Expr* expr) { if (auto memberExpr = as<MemberExpr>(expr)) { @@ -622,13 +622,13 @@ namespace Slang return nullptr; } - RefPtr<Expr> SemanticsExprVisitor::visitBoolLiteralExpr(BoolLiteralExpr* expr) + Expr* SemanticsExprVisitor::visitBoolLiteralExpr(BoolLiteralExpr* expr) { expr->type = m_astBuilder->getBoolType(); return expr; } - RefPtr<Expr> 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<Expr> SemanticsExprVisitor::visitFloatingPointLiteralExpr(FloatingPointLiteralExpr* expr) + Expr* SemanticsExprVisitor::visitFloatingPointLiteralExpr(FloatingPointLiteralExpr* expr) { if(!expr->type.type) { @@ -657,7 +657,7 @@ namespace Slang return expr; } - RefPtr<Expr> 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<ConstantIntVal>(expr->value); } - RefPtr<IntVal> 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<DeclRefExpr>(); + auto funcDeclRefExpr = as<DeclRefExpr>(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<IntVal> 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<IntVal> result = m_astBuilder->create<ConstantIntVal>(resultValue); + IntVal* result = m_astBuilder->create<ConstantIntVal>(resultValue); return result; } - RefPtr<IntVal> 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<TypeCastExpr>(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<IntVal> SemanticsVisitor::TryCheckIntegerConstantExpression(Expr* exp) + IntVal* SemanticsVisitor::TryCheckIntegerConstantExpression(Expr* exp) { // Check if type is acceptable for an integer constant expression if(auto basicType = as<BasicExpressionType>(exp->type.type)) @@ -883,7 +883,7 @@ namespace Slang return TryConstantFoldExpr(exp); } - RefPtr<IntVal> 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<IntVal> SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr) + IntVal* SemanticsVisitor::CheckIntegerConstantExpression(Expr* inExpr) { return CheckIntegerConstantExpression(inExpr, getSink()); } - RefPtr<IntVal> 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<Expr> SemanticsVisitor::CheckSimpleSubscriptExpr( - RefPtr<IndexExpr> subscriptExpr, - RefPtr<Type> 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<Expr> SemanticsExprVisitor::visitIndexExpr(IndexExpr* subscriptExpr) + Expr* SemanticsExprVisitor::visitIndexExpr(IndexExpr* subscriptExpr) { auto baseExpr = subscriptExpr->baseExpression; baseExpr = CheckExpr(baseExpr); - RefPtr<Expr> 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<IntVal> 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<Expr> subscriptFuncExpr = createLookupResultExpr( + Expr* subscriptFuncExpr = createLookupResultExpr( name, lookupResult, subscriptExpr->baseExpression, subscriptExpr->loc); - RefPtr<InvokeExpr> subscriptCallExpr = m_astBuilder->create<InvokeExpr>(); + InvokeExpr* subscriptCallExpr = m_astBuilder->create<InvokeExpr>(); 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<Expr> 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<Expr> e = expr; + Expr* e = expr; for(;;) { if(auto memberExpr = as<MemberExpr>(e)) @@ -1100,7 +1100,7 @@ namespace Slang } } - RefPtr<Expr> SemanticsExprVisitor::visitAssignExpr(AssignExpr* expr) + Expr* SemanticsExprVisitor::visitAssignExpr(AssignExpr* expr) { expr->left = CheckExpr(expr->left); @@ -1130,7 +1130,7 @@ namespace Slang return expr; } - RefPtr<Expr> SemanticsVisitor::CheckExpr(RefPtr<Expr> expr) + Expr* SemanticsVisitor::CheckExpr(Expr* expr) { auto term = CheckTerm(expr); @@ -1140,10 +1140,10 @@ namespace Slang return term; } - RefPtr<Expr> SemanticsVisitor::CheckInvokeExprWithCheckedOperands(InvokeExpr *expr) + Expr* SemanticsVisitor::CheckInvokeExprWithCheckedOperands(InvokeExpr *expr) { auto rs = ResolveInvoke(expr); - if (auto invoke = as<InvokeExpr>(rs.Ptr())) + if (auto invoke = as<InvokeExpr>(rs)) { // if this is still an invoke expression, test arguments passed to inout/out parameter are LValues if(auto funcType = as<FuncType>(invoke->functionExpr->type)) @@ -1212,7 +1212,7 @@ namespace Slang return rs; } - RefPtr<Expr> 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<Expr> 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<Expr> 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<DeclRefType>() ) + if( auto declRefType = as<DeclRefType>(typeExp.type) ) { - if(auto structDeclRef = declRefType->declRef.as<StructDecl>()) + if(auto structDeclRef = as<StructDecl>(declRefType->declRef)) { if( expr->arguments.getCount() == 1 ) { auto arg = expr->arguments[0]; - if( auto intLitArg = arg.as<IntegerLiteralExpr>() ) + if( auto intLitArg = as<IntegerLiteralExpr>(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<InitializerListExpr> initListExpr = m_astBuilder->create<InitializerListExpr>(); + InitializerListExpr* initListExpr = m_astBuilder->create<InitializerListExpr>(); 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<Expr> SemanticsVisitor::MaybeDereference(RefPtr<Expr> inExpr) + Expr* SemanticsVisitor::MaybeDereference(Expr* inExpr) { - RefPtr<Expr> expr = inExpr; + Expr* expr = inExpr; for (;;) { auto baseType = expr->type; @@ -1363,13 +1365,13 @@ namespace Slang } } - RefPtr<Expr> SemanticsVisitor::CheckMatrixSwizzleExpr( + Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr<Type> baseElementType, + Type* baseElementType, IntegerLiteralValue baseElementRowCount, IntegerLiteralValue baseElementColCount) { - RefPtr<MatrixSwizzleExpr> swizExpr = m_astBuilder->create<MatrixSwizzleExpr>(); + MatrixSwizzleExpr* swizExpr = m_astBuilder->create<MatrixSwizzleExpr>(); swizExpr->loc = memberRefExpr->loc; swizExpr->base = memberRefExpr->baseExpression; @@ -1503,11 +1505,11 @@ namespace Slang return swizExpr; } - RefPtr<Expr> SemanticsVisitor::CheckMatrixSwizzleExpr( + Expr* SemanticsVisitor::CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr<Type> baseElementType, - RefPtr<IntVal> baseRowCount, - RefPtr<IntVal> baseColCount) + Type* baseElementType, + IntVal* baseRowCount, + IntVal* baseColCount) { if (auto constantRowCount = as<ConstantIntVal>(baseRowCount)) { @@ -1521,12 +1523,12 @@ namespace Slang return CreateErrorExpr(memberRefExpr); } - RefPtr<Expr> SemanticsVisitor::CheckSwizzleExpr( + Expr* SemanticsVisitor::CheckSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr<Type> baseElementType, + Type* baseElementType, IntegerLiteralValue baseElementCount) { - RefPtr<SwizzleExpr> swizExpr = m_astBuilder->create<SwizzleExpr>(); + SwizzleExpr* swizExpr = m_astBuilder->create<SwizzleExpr>(); swizExpr->loc = memberRefExpr->loc; swizExpr->base = memberRefExpr->baseExpression; @@ -1615,10 +1617,10 @@ namespace Slang return swizExpr; } - RefPtr<Expr> SemanticsVisitor::CheckSwizzleExpr( + Expr* SemanticsVisitor::CheckSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr<Type> baseElementType, - RefPtr<IntVal> baseElementCount) + Type* baseElementType, + IntVal* baseElementCount) { if (auto constantElementCount = as<ConstantIntVal>(baseElementCount)) { @@ -1631,7 +1633,7 @@ namespace Slang } } - RefPtr<Expr> SemanticsVisitor::_lookupStaticMember(RefPtr<DeclRefExpr> expr, RefPtr<Expr> baseExpression) + Expr* SemanticsVisitor::_lookupStaticMember(DeclRefExpr* expr, Expr* baseExpression) { auto& baseType = baseExpression->type; @@ -1779,7 +1781,7 @@ namespace Slang return lookupMemberResultFailure(expr, baseType); } - RefPtr<Expr> 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<Expr> SemanticsVisitor::lookupMemberResultFailure( + Expr* SemanticsVisitor::lookupMemberResultFailure( DeclRefExpr* expr, QualType const& baseType) { @@ -1810,7 +1812,7 @@ namespace Slang return expr; } - RefPtr<Expr> SemanticsExprVisitor::visitMemberExpr(MemberExpr * expr) + Expr* SemanticsExprVisitor::visitMemberExpr(MemberExpr * expr) { expr->baseExpression = CheckExpr(expr->baseExpression); @@ -1897,7 +1899,7 @@ namespace Slang } } - RefPtr<Expr> 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<Expr> 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<Expr> 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<Type> 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<GenericDecl>(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<Type> 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<Substitutions> 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<Expr> TranslateTypeNodeImpl(const RefPtr<Expr> & node); - RefPtr<Type> ExtractTypeFromTypeRepr(const RefPtr<Expr>& typeRepr); - RefPtr<Type> TranslateTypeNode(const RefPtr<Expr> & node); + Expr* TranslateTypeNodeImpl(Expr* node); + Type* ExtractTypeFromTypeRepr(Expr* typeRepr); + Type* TranslateTypeNode(Expr* node); TypeExp TranslateTypeNodeForced(TypeExp const& typeExp); TypeExp TranslateTypeNode(TypeExp const& typeExp); - RefPtr<DeclRefType> 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<typename F> - RefPtr<Expr> moveTemp(RefPtr<Expr> 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<typename F> - RefPtr<Expr> maybeMoveTemp(RefPtr<Expr> 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<Expr> openExistential( - RefPtr<Expr> expr, + Expr* openExistential( + Expr* expr, DeclRef<InterfaceDecl> 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<Expr> maybeOpenExistential(RefPtr<Expr> expr); + Expr* maybeOpenExistential(Expr* expr); - RefPtr<Expr> ConstructDeclRefExpr( + Expr* ConstructDeclRefExpr( DeclRef<Decl> declRef, - RefPtr<Expr> baseExpr, + Expr* baseExpr, SourceLoc loc); - RefPtr<Expr> ConstructDerefExpr( - RefPtr<Expr> base, + Expr* ConstructDerefExpr( + Expr* base, SourceLoc loc); - RefPtr<Expr> ConstructLookupResultExpr( + Expr* ConstructLookupResultExpr( LookupResultItem const& item, - RefPtr<Expr> baseExpr, + Expr* baseExpr, SourceLoc loc); - RefPtr<Expr> createLookupResultExpr( + Expr* createLookupResultExpr( Name* name, LookupResult const& lookupResult, - RefPtr<Expr> 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<Expr> maybeResolveOverloadedExpr(RefPtr<Expr> 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<Expr> resolveOverloadedExpr(RefPtr<OverloadedExpr> overloadedExpr, LookupMask mask); + Expr* resolveOverloadedExpr(OverloadedExpr* overloadedExpr, LookupMask mask); /// Worker reoutine for `maybeResolveOverloadedExpr` and `resolveOverloadedExpr`. - RefPtr<Expr> _resolveOverloadedExprImpl(RefPtr<OverloadedExpr> 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<Expr> ExpectATypeRepr(RefPtr<Expr> expr); + Expr* ExpectATypeRepr(Expr* expr); - RefPtr<Type> ExpectAType(RefPtr<Expr> expr); + Type* ExpectAType(Expr* expr); - RefPtr<Type> ExtractGenericArgType(RefPtr<Expr> exp); + Type* ExtractGenericArgType(Expr* exp); - RefPtr<IntVal> ExtractGenericArgInteger(RefPtr<Expr> exp, DiagnosticSink* sink); - RefPtr<IntVal> ExtractGenericArgInteger(RefPtr<Expr> exp); + IntVal* ExtractGenericArgInteger(Expr* exp, DiagnosticSink* sink); + IntVal* ExtractGenericArgInteger(Expr* exp); - RefPtr<Val> ExtractGenericArgVal(RefPtr<Expr> 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<Type> InstantiateGenericType( + Type* InstantiateGenericType( DeclRef<GenericDecl> genericDeclRef, - List<RefPtr<Expr>> const& args); + List<Expr*> 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<float4>`). bool CoerceToProperTypeImpl( TypeExp const& typeExp, - RefPtr<Type>* 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<Expr> CheckTerm(RefPtr<Expr> term); + Expr* CheckTerm(Expr* term); - RefPtr<Expr> CreateErrorExpr(Expr* expr); + Expr* CreateErrorExpr(Expr* expr); - bool IsErrorExpr(RefPtr<Expr> expr); + bool IsErrorExpr(Expr* expr); // Capture the "base" expression in case this is a member reference - RefPtr<Expr> GetBaseExpr(RefPtr<Expr> expr); + Expr* GetBaseExpr(Expr* expr); public: bool ValuesAreEqual( - RefPtr<IntVal> left, - RefPtr<IntVal> 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* type); /// Should the provided expression (from an initializer list) be used directly to initialize `toType`? bool shouldUseInitializerDirectly( - RefPtr<Type> toType, - RefPtr<Expr> 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<Type> toType, - RefPtr<Expr>* outToExpr, - RefPtr<InitializerListExpr> 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<Type> inToType, - RefPtr<Expr>* outToExpr, - RefPtr<InitializerListExpr> 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<Type> toType, - RefPtr<Expr>* outToExpr, - RefPtr<InitializerListExpr> fromInitializerListExpr); + Type* toType, + Expr** outToExpr, + InitializerListExpr* fromInitializerListExpr); /// Report that implicit type coercion is not possible. bool _failedCoercion( - RefPtr<Type> toType, - RefPtr<Expr>* outToExpr, - RefPtr<Expr> 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<Type> toType, - RefPtr<Expr>* outToExpr, - RefPtr<Type> fromType, - RefPtr<Expr> 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<Type> toType, - RefPtr<Type> fromType, + Type* toType, + Type* fromType, ConversionCost* outCost = 0); - RefPtr<TypeCastExpr> createImplicitCastExpr(); + TypeCastExpr* createImplicitCastExpr(); - RefPtr<Expr> CreateImplicitCastExpr( - RefPtr<Type> toType, - RefPtr<Expr> 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<Expr> createCastToSuperTypeExpr( - RefPtr<Type> toType, - RefPtr<Expr> fromExpr, - RefPtr<Val> witness); + Expr* createCastToInterfaceExpr( + Type* toType, + Expr* fromExpr, + Val* witness); /// Implicitly coerce `fromExpr` to `toType` and diagnose errors if it isn't possible - RefPtr<Expr> coerce( - RefPtr<Type> toType, - RefPtr<Expr> 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<ConstantIntVal> checkConstantIntVal( - RefPtr<Expr> expr); + ConstantIntVal* checkConstantIntVal( + Expr* expr); - RefPtr<ConstantIntVal> checkConstantEnumVal( - RefPtr<Expr> 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* 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<RefObject> & cls, uint32_t typeFlags); + bool getAttributeTargetSyntaxClasses(SyntaxClass<NodeBase> & cls, uint32_t typeFlags); - bool validateAttribute(RefPtr<Attribute> attr, AttributeDecl* attribClassDecl); + bool validateAttribute(Attribute* attr, AttributeDecl* attribClassDecl); - RefPtr<AttributeBase> checkAttribute( + AttributeBase* checkAttribute( UncheckedAttribute* uncheckedAttr, ModifiableSyntaxNode* attrTarget); - RefPtr<Modifier> checkModifier( - RefPtr<Modifier> m, + Modifier* checkModifier( + Modifier* m, ModifiableSyntaxNode* syntaxNode); void checkModifiers(ModifiableSyntaxNode* syntaxNode); @@ -704,7 +704,7 @@ namespace Slang RefPtr<WitnessTable> witnessTable); bool doesTypeSatisfyAssociatedTypeRequirement( - RefPtr<Type> satisfyingType, + Type* satisfyingType, DeclRef<AssocTypeDecl> requiredAssociatedTypeDeclRef, RefPtr<WitnessTable> witnessTable); @@ -795,7 +795,7 @@ namespace Slang bool doGenericSignaturesMatch( GenericDecl* left, GenericDecl* right, - RefPtr<GenericSubstitution>* outSubstRightToLeft); + GenericSubstitution** outSubstRightToLeft); // Check if two functions have the same signature for the purposes // of overload resolution. @@ -803,18 +803,18 @@ namespace Slang DeclRef<FuncDecl> fst, DeclRef<FuncDecl> snd); - RefPtr<GenericSubstitution> createDummySubstitutions( + GenericSubstitution* createDummySubstitutions( GenericDecl* genericDecl); Result checkRedeclaration(Decl* newDecl, Decl* oldDecl); Result checkFuncRedeclaration(FuncDecl* newDecl, FuncDecl* oldDecl); void checkForRedeclaration(Decl* decl); - RefPtr<Expr> checkPredicateExpr(Expr* expr); + Expr* checkPredicateExpr(Expr* expr); - RefPtr<Expr> checkExpressionAndExpectIntegerConstant(RefPtr<Expr> expr, RefPtr<IntVal>* outIntVal); + Expr* checkExpressionAndExpectIntegerConstant(Expr* expr, IntVal** outIntVal); - IntegerLiteralValue GetMinBound(RefPtr<IntVal> val); + IntegerLiteralValue GetMinBound(IntVal* val); void maybeInferArraySizeForVariable(VarDeclBase* varDecl); @@ -827,26 +827,26 @@ namespace Slang return getNamePool()->getName(text); } - RefPtr<IntVal> TryConstantFoldExpr( + IntVal* TryConstantFoldExpr( InvokeExpr* invokeExpr); - RefPtr<IntVal> 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<IntVal> TryCheckIntegerConstantExpression(Expr* exp); + IntVal* TryCheckIntegerConstantExpression(Expr* exp); // Enforce that an expression resolves to an integer constant, and get its value - RefPtr<IntVal> CheckIntegerConstantExpression(Expr* inExpr); - RefPtr<IntVal> CheckIntegerConstantExpression(Expr* inExpr, DiagnosticSink* sink); + IntVal* CheckIntegerConstantExpression(Expr* inExpr); + IntVal* CheckIntegerConstantExpression(Expr* inExpr, DiagnosticSink* sink); - RefPtr<IntVal> CheckEnumConstantExpression(Expr* expr); + IntVal* CheckEnumConstantExpression(Expr* expr); - RefPtr<Expr> CheckSimpleSubscriptExpr( - RefPtr<IndexExpr> subscriptExpr, - RefPtr<Type> 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<T,N>` type // programmatically, so that it will work just like a type of // that form constructed by the user. - RefPtr<VectorExpressionType> createVectorType( - RefPtr<Type> elementType, - RefPtr<IntVal> 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<Type> findResultTypeForConstructorDecl(ConstructorDecl* decl); + Type* findResultTypeForConstructorDecl(ConstructorDecl* decl); /// Determine what type `This` should refer to in the context of the given parent `decl`. - RefPtr<Type> calcThisType(DeclRef<Decl> decl); + Type* calcThisType(DeclRef<Decl> decl); /// Determine what type `This` should refer to in an extension of `type`. - RefPtr<Type> calcThisType(Type* type); + Type* calcThisType(Type* type); // struct Constraint { - Decl* decl; // the declaration of the thing being constraints - RefPtr<Val> 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* genericDecl = nullptr; // Constraints we have accumulated, which constrain // the possible arguments for those parameters. List<Constraint> constraints; }; - RefPtr<Type> TryJoinVectorAndScalarType( - RefPtr<VectorExpressionType> vectorType, - RefPtr<BasicExpressionType> scalarType); + Type* TryJoinVectorAndScalarType( + VectorExpressionType* vectorType, + BasicExpressionType* scalarType); struct TypeWitnessBreadcrumb { TypeWitnessBreadcrumb* prev; - RefPtr<Type> sub; - RefPtr<Type> sup; + Type* sub = nullptr; + Type* sup = nullptr; DeclRef<Decl> declRef; }; // Create a subtype witness based on the declared relationship // found in a single breadcrumb - RefPtr<DeclaredSubtypeWitness> 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<Val> createTypeWitness( - RefPtr<Type> subType, - DeclRef<AggTypeDecl> 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<AggTypeDecl> 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<Type> originalSubType, - RefPtr<Type> subType, + Type* originalSubType, + Type* subType, DeclRef<AggTypeDecl> superTypeDeclRef, - RefPtr<Val>* outWitness, + Val** outWitness, TypeWitnessBreadcrumb* inBreadcrumbs); /// Check whether `subType` is a sub-type of `superTypeDeclRef`. bool isDeclaredSubtype( - RefPtr<Type> subType, + Type* subType, DeclRef<AggTypeDecl> 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<Val> tryGetSubtypeWitness( - RefPtr<Type> subType, + Val* tryGetSubtypeWitness( + Type* subType, DeclRef<AggTypeDecl> superTypeDeclRef); /// Check whether `type` conforms to `interfaceDeclRef`, @@ -995,23 +996,28 @@ namespace Slang /// /// This function is equivalent to `tryGetSubtypeWitness()`. /// - RefPtr<Val> tryGetInterfaceConformanceWitness( - RefPtr<Type> type, + Val* tryGetInterfaceConformanceWitness( + Type* type, DeclRef<InterfaceDecl> interfaceDeclRef); + Expr* createCastToSuperTypeExpr( + Type* toType, + Expr* fromExpr, + Val* witness); + /// Does there exist an implicit conversion from `fromType` to `toType`? bool canConvertImplicitly( - RefPtr<Type> toType, - RefPtr<Type> fromType); + Type* toType, + Type* fromType); - RefPtr<Type> TryJoinTypeWithInterface( - RefPtr<Type> type, + Type* TryJoinTypeWithInterface( + Type* type, DeclRef<InterfaceDecl> interfaceDeclRef); // Try to compute the "join" between two types - RefPtr<Type> TryJoinTypes( - RefPtr<Type> left, - RefPtr<Type> 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<Expr> 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<Expr>* args = nullptr; - RefPtr<Type>* argTypes = nullptr; + Expr** args = nullptr; + Type** argTypes = nullptr; Index getArgCount() { return argCount; } - RefPtr<Expr>& getArg(Index index) { return args[index]; } - RefPtr<Type>& 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<Expr> 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<Val> 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<Val> tryGetSubtypeWitness( - RefPtr<Type> sub, - RefPtr<Type> sup); + Val* tryGetSubtypeWitness( + Type* sub, + Type* sup); // In the case where we are explicitly applying a generic // to arguments (e.g., `G<A,B>`) check that the constraints @@ -1141,10 +1147,10 @@ namespace Slang OverloadCandidate& candidate); // Create the representation of a given generic applied to some arguments - RefPtr<Expr> createGenericDeclRef( - RefPtr<Expr> baseExpr, - RefPtr<Expr> originalExpr, - RefPtr<GenericSubstitution> 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<Expr> CompleteOverloadCandidate( + Expr* CompleteOverloadCandidate( OverloadResolveContext& context, OverloadCandidate& candidate); @@ -1191,17 +1197,17 @@ namespace Slang OverloadResolveContext& context); void AddFuncOverloadCandidate( - RefPtr<FuncType> /*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* type, DeclRef<ConstructorDecl> ctorDeclRef, OverloadResolveContext& context, - RefPtr<Type> 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<Val> fst, - RefPtr<Val> snd); + Val* fst, + Val* snd); bool tryUnifySubstitutions( ConstraintSystem& constraints, - RefPtr<Substitutions> fst, - RefPtr<Substitutions> snd); + Substitutions* fst, + Substitutions* snd); bool tryUnifyGenericSubstitutions( ConstraintSystem& constraints, - RefPtr<GenericSubstitution> fst, - RefPtr<GenericSubstitution> snd); + GenericSubstitution* fst, + GenericSubstitution* snd); bool TryUnifyTypeParam( ConstraintSystem& constraints, - RefPtr<GenericTypeParamDecl> typeParamDecl, - RefPtr<Type> type); + GenericTypeParamDecl* typeParamDecl, + Type* type); bool TryUnifyIntParam( ConstraintSystem& constraints, - RefPtr<GenericValueParamDecl> paramDecl, - RefPtr<IntVal> val); + GenericValueParamDecl* paramDecl, + IntVal* val); bool TryUnifyIntParam( ConstraintSystem& constraints, DeclRef<VarDeclBase> const& varRef, - RefPtr<IntVal> val); + IntVal* val); bool TryUnifyTypesByStructuralMatch( ConstraintSystem& constraints, - RefPtr<Type> fst, - RefPtr<Type> snd); + Type* fst, + Type* snd); bool TryUnifyTypes( ConstraintSystem& constraints, - RefPtr<Type> fst, - RefPtr<Type> snd); + Type* fst, + Type* snd); // Is the candidate extension declaration actually applicable to the given type DeclRef<ExtensionDecl> ApplyExtensionToType( ExtensionDecl* extDecl, - RefPtr<Type> 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* type, OverloadResolveContext& context); void AddDeclRefOverloadCandidates( @@ -1274,12 +1280,12 @@ namespace Slang OverloadResolveContext& context); void AddOverloadCandidates( - RefPtr<Expr> funcExpr, + Expr* funcExpr, OverloadResolveContext& context); - void formatType(StringBuilder& sb, RefPtr<Type> type); + void formatType(StringBuilder& sb, Type* type); - void formatVal(StringBuilder& sb, RefPtr<Val> val); + void formatVal(StringBuilder& sb, Val* val); void formatDeclPath(StringBuilder& sb, DeclRef<Decl> declRef); @@ -1296,22 +1302,22 @@ namespace Slang String getCallSignatureString( OverloadResolveContext& context); - RefPtr<Expr> ResolveInvoke(InvokeExpr * expr); + Expr* ResolveInvoke(InvokeExpr * expr); void AddGenericOverloadCandidate( LookupResultItem baseItem, OverloadResolveContext& context); void AddGenericOverloadCandidates( - RefPtr<Expr> baseExpr, + Expr* baseExpr, OverloadResolveContext& context); /// Check a generic application where the operands have already been checked. - RefPtr<Expr> checkGenericAppWithCheckedArgs(GenericAppExpr* genericAppExpr); + Expr* checkGenericAppWithCheckedArgs(GenericAppExpr* genericAppExpr); - RefPtr<Expr> CheckExpr(RefPtr<Expr> expr); + Expr* CheckExpr(Expr* expr); - RefPtr<Expr> CheckInvokeExprWithCheckedOperands(InvokeExpr *expr); + Expr* CheckInvokeExprWithCheckedOperands(InvokeExpr *expr); // Get the type to use when referencing a declaration QualType GetTypeForDeclRef(DeclRef<Decl> declRef, SourceLoc loc); @@ -1320,38 +1326,38 @@ namespace Slang // // - RefPtr<Expr> MaybeDereference(RefPtr<Expr> inExpr); + Expr* MaybeDereference(Expr* inExpr); - RefPtr<Expr> CheckMatrixSwizzleExpr( + Expr* CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr<Type> baseElementType, + Type* baseElementType, IntegerLiteralValue baseElementRowCount, IntegerLiteralValue baseElementColCount); - RefPtr<Expr> CheckMatrixSwizzleExpr( + Expr* CheckMatrixSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr<Type> baseElementType, - RefPtr<IntVal> baseElementRowCount, - RefPtr<IntVal> baseElementColCount); + Type* baseElementType, + IntVal* baseElementRowCount, + IntVal* baseElementColCount); - RefPtr<Expr> CheckSwizzleExpr( + Expr* CheckSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr<Type> baseElementType, + Type* baseElementType, IntegerLiteralValue baseElementCount); - RefPtr<Expr> CheckSwizzleExpr( + Expr* CheckSwizzleExpr( MemberExpr* memberRefExpr, - RefPtr<Type> baseElementType, - RefPtr<IntVal> 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<Expr> _lookupStaticMember(RefPtr<DeclRefExpr> expr, RefPtr<Expr> baseExpression); + Expr* _lookupStaticMember(DeclRefExpr* expr, Expr* baseExpression); - RefPtr<Expr> visitStaticMemberExpr(StaticMemberExpr* expr); + Expr* visitStaticMemberExpr(StaticMemberExpr* expr); - RefPtr<Expr> lookupMemberResultFailure( + Expr* lookupMemberResultFailure( DeclRefExpr* expr, QualType const& baseType); @@ -1365,35 +1371,35 @@ namespace Slang struct SemanticsExprVisitor : public SemanticsVisitor - , ExprVisitor<SemanticsExprVisitor, RefPtr<Expr>> + , ExprVisitor<SemanticsExprVisitor, Expr*> { public: SemanticsExprVisitor(SharedSemanticsContext* shared) : SemanticsVisitor(shared) {} - RefPtr<Expr> visitBoolLiteralExpr(BoolLiteralExpr* expr); - RefPtr<Expr> visitIntegerLiteralExpr(IntegerLiteralExpr* expr); - RefPtr<Expr> visitFloatingPointLiteralExpr(FloatingPointLiteralExpr* expr); - RefPtr<Expr> visitStringLiteralExpr(StringLiteralExpr* expr); + Expr* visitBoolLiteralExpr(BoolLiteralExpr* expr); + Expr* visitIntegerLiteralExpr(IntegerLiteralExpr* expr); + Expr* visitFloatingPointLiteralExpr(FloatingPointLiteralExpr* expr); + Expr* visitStringLiteralExpr(StringLiteralExpr* expr); - RefPtr<Expr> visitIndexExpr(IndexExpr* subscriptExpr); + Expr* visitIndexExpr(IndexExpr* subscriptExpr); - RefPtr<Expr> visitParenExpr(ParenExpr* expr); + Expr* visitParenExpr(ParenExpr* expr); - RefPtr<Expr> visitAssignExpr(AssignExpr* expr); + Expr* visitAssignExpr(AssignExpr* expr); - RefPtr<Expr> visitGenericAppExpr(GenericAppExpr* genericAppExpr); + Expr* visitGenericAppExpr(GenericAppExpr* genericAppExpr); - RefPtr<Expr> visitSharedTypeExpr(SharedTypeExpr* expr); + Expr* visitSharedTypeExpr(SharedTypeExpr* expr); - RefPtr<Expr> visitTaggedUnionTypeExpr(TaggedUnionTypeExpr* expr); + Expr* visitTaggedUnionTypeExpr(TaggedUnionTypeExpr* expr); - RefPtr<Expr> visitInvokeExpr(InvokeExpr *expr); + Expr* visitInvokeExpr(InvokeExpr *expr); - RefPtr<Expr> visitVarExpr(VarExpr *expr); + Expr* visitVarExpr(VarExpr *expr); - RefPtr<Expr> 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<Expr> 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<Expr> visitStaticMemberExpr(StaticMemberExpr* expr); + Expr* visitStaticMemberExpr(StaticMemberExpr* expr); - RefPtr<Expr> visitMemberExpr(MemberExpr * expr); + Expr* visitMemberExpr(MemberExpr * expr); - RefPtr<Expr> visitInitializerListExpr(InitializerListExpr* expr); + Expr* visitInitializerListExpr(InitializerListExpr* expr); - RefPtr<Expr> visitThisExpr(ThisExpr* expr); - RefPtr<Expr> 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<ConstantIntVal> SemanticsVisitor::checkConstantIntVal( - RefPtr<Expr> 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<ConstantIntVal> SemanticsVisitor::checkConstantEnumVal( - RefPtr<Expr> 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* 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<AttributeDecl> attrDecl = m_astBuilder->create<AttributeDecl>(); + AttributeDecl* attrDecl = m_astBuilder->create<AttributeDecl>(); attrDecl->nameAndLoc.name = attributeName; attrDecl->nameAndLoc.loc = structDecl->nameAndLoc.loc; attrDecl->loc = structDecl->loc; - RefPtr<AttributeTargetModifier> targetModifier = m_astBuilder->create<AttributeTargetModifier>(); + AttributeTargetModifier* targetModifier = m_astBuilder->create<AttributeTargetModifier>(); targetModifier->syntaxClass = attrUsageAttr->targetSyntaxClass; targetModifier->loc = attrUsageAttr->loc; addModifier(attrDecl, targetModifier); @@ -167,7 +167,7 @@ namespace Slang { ensureDecl(varMember, DeclCheckState::CanUseTypeOfValueDecl); - RefPtr<ParamDecl> paramDecl = m_astBuilder->create<ParamDecl>(); + ParamDecl* paramDecl = m_astBuilder->create<ParamDecl>(); paramDecl->nameAndLoc = member->nameAndLoc; paramDecl->type = varMember->type; paramDecl->loc = member->loc; @@ -230,7 +230,7 @@ namespace Slang return true; } - bool SemanticsVisitor::getAttributeTargetSyntaxClasses(SyntaxClass<RefObject> & cls, uint32_t typeFlags) + bool SemanticsVisitor::getAttributeTargetSyntaxClasses(SyntaxClass<NodeBase> & cls, uint32_t typeFlags) { if (typeFlags == (int)UserDefinedAttributeTargets::Struct) { @@ -250,7 +250,7 @@ namespace Slang return false; } - bool SemanticsVisitor::validateAttribute(RefPtr<Attribute> attr, AttributeDecl* attribClassDecl) + bool SemanticsVisitor::validateAttribute(Attribute* attr, AttributeDecl* attribClassDecl) { if(auto numThreadsAttr = as<NumThreadsAttribute>(attr)) { @@ -401,7 +401,7 @@ namespace Slang uint32_t targetClassId = (uint32_t)UserDefinedAttributeTargets::None; if (attr->args.getCount() == 1) { - RefPtr<IntVal> outIntVal; + //IntVal* outIntVal; if (auto cInt = checkConstantEnumVal(attr->args[0])) { targetClassId = (uint32_t)(cInt->value); @@ -522,7 +522,7 @@ namespace Slang return true; } - RefPtr<AttributeBase> SemanticsVisitor::checkAttribute( + AttributeBase* SemanticsVisitor::checkAttribute( UncheckedAttribute* uncheckedAttr, ModifiableSyntaxNode* attrTarget) { @@ -544,8 +544,8 @@ namespace Slang } // Manage scope - RefPtr<RefObject> attrInstance = attrDecl->syntaxClass.createInstance(m_astBuilder); - auto attr = attrInstance.as<Attribute>(); + NodeBase* attrInstance = attrDecl->syntaxClass.createInstance(m_astBuilder); + auto attr = as<Attribute>(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<Modifier> SemanticsVisitor::checkModifier( - RefPtr<Modifier> m, + Modifier* SemanticsVisitor::checkModifier( + Modifier* m, ModifiableSyntaxNode* syntaxNode) { if(auto hlslUncheckedAttribute = as<UncheckedAttribute>(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<Modifier> resultModifiers; - RefPtr<Modifier>* resultModifierLink = &resultModifiers; + Modifier* resultModifiers = nullptr; + Modifier** resultModifierLink = &resultModifiers; - RefPtr<Modifier> 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<Expr> 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* 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<GenericSubstitution>(); + auto subst = as<GenericSubstitution>(candidate.subst); SLANG_ASSERT(subst); subst->genericDecl = genericDeclRef.getDecl(); @@ -444,10 +442,10 @@ namespace Slang candidate.status = OverloadCandidate::Status::Applicable; } - RefPtr<Expr> SemanticsVisitor::createGenericDeclRef( - RefPtr<Expr> baseExpr, - RefPtr<Expr> originalExpr, - RefPtr<GenericSubstitution> subst) + Expr* SemanticsVisitor::createGenericDeclRef( + Expr* baseExpr, + Expr* originalExpr, + GenericSubstitution* subst) { auto baseDeclRefExpr = as<DeclRefExpr>(baseExpr); if (!baseDeclRefExpr) @@ -467,7 +465,7 @@ namespace Slang DeclRef<Decl> innerDeclRef(getInner(baseGenericRef), subst); - RefPtr<Expr> base; + Expr* base = nullptr; if (auto mbrExpr = as<MemberExpr>(baseExpr)) base = mbrExpr->baseExpression; @@ -477,7 +475,7 @@ namespace Slang originalExpr->loc); } - RefPtr<Expr> SemanticsVisitor::CompleteOverloadCandidate( + Expr* SemanticsVisitor::CompleteOverloadCandidate( OverloadResolveContext& context, OverloadCandidate& candidate) { @@ -520,7 +518,7 @@ namespace Slang { case OverloadCandidate::Flavor::Func: { - RefPtr<AppExprBase> callExpr = as<InvokeExpr>(context.originalExpr); + AppExprBase* callExpr = as<InvokeExpr>(context.originalExpr); if(!callExpr) { callExpr = m_astBuilder->create<InvokeExpr>(); @@ -555,7 +553,7 @@ namespace Slang return createGenericDeclRef( baseExpr, context.originalExpr, - candidate.subst.as<GenericSubstitution>()); + as<GenericSubstitution>(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* funcType, OverloadResolveContext& context) { SLANG_UNUSED(funcType); @@ -955,11 +953,13 @@ namespace Slang void SemanticsVisitor::AddCtorOverloadCandidate( LookupResultItem typeItem, - RefPtr<Type> type, + Type* type, DeclRef<ConstructorDecl> ctorDeclRef, OverloadResolveContext& context, - RefPtr<Type> 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* 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<Expr> funcExpr, + Expr* funcExpr, OverloadResolveContext& context) { // A call of the form `(<something>)(<args>)` should be @@ -1224,12 +1224,12 @@ namespace Slang } } - void SemanticsVisitor::formatType(StringBuilder& sb, RefPtr<Type> type) + void SemanticsVisitor::formatType(StringBuilder& sb, Type* type) { sb << type->toString(); } - void SemanticsVisitor::formatVal(StringBuilder& sb, RefPtr<Val> 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<GenericSubstitution>(); + auto genSubst = as<GenericSubstitution>(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<Expr> 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<OperatorExpr>(expr)) { if (key.fromOperatorExpr(opExpr)) @@ -1651,7 +1651,7 @@ namespace Slang } void SemanticsVisitor::AddGenericOverloadCandidates( - RefPtr<Expr> baseExpr, + Expr* baseExpr, OverloadResolveContext& context) { if(auto baseDeclRefExpr = as<DeclRefExpr>(baseExpr)) @@ -1674,7 +1674,7 @@ namespace Slang } } - RefPtr<Expr> 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<Expr> 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 69dbf133d..4af6a4328 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<VarDecl>()) + if(auto globalVar = as<VarDecl>(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<GlobalGenericParamDecl>(); + auto genericTypeParamDecl = as<GlobalGenericParamDecl>(param.object); SLANG_ASSERT(genericTypeParamDecl); - RefPtr<Type> argType = as<Type>(arg.val); + Type* argType = as<Type>(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<DeclRefType>() ) + if( auto argDeclRefType = as<DeclRefType>(argType) ) { auto argDeclRef = argDeclRefType->declRef; if(auto argGenericParamDeclRef = argDeclRef.as<GlobalGenericParamDecl>()) @@ -1060,10 +1060,10 @@ namespace Slang case SpecializationParam::Flavor::ExistentialType: { - auto interfaceType = param.object.as<Type>(); + auto interfaceType = as<Type>(param.object); SLANG_ASSERT(interfaceType); - RefPtr<Type> argType = as<Type>(arg.val); + Type* argType = as<Type>(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<GlobalGenericValueParamDecl>(); + auto paramDecl = as<GlobalGenericValueParamDecl>(param.object); SLANG_ASSERT(paramDecl); // Now we need to check that the argument `Val` has the // appropriate type expected by the parameter. - RefPtr<IntVal> intVal = as<IntVal>(arg.val); + IntVal* intVal = as<IntVal>(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<RefPtr<Expr>> const& argExprs, + List<Expr*> const& argExprs, List<SpecializationArg>& outArgs, DiagnosticSink* sink) { @@ -1175,7 +1175,7 @@ namespace Slang auto genericDeclRef = m_funcDeclRef.getParent().as<GenericDecl>(); SLANG_ASSERT(genericDeclRef); // otherwise we wouldn't have generic parameters - RefPtr<GenericSubstitution> genericSubst = getLinkage()->getASTBuilder()->create<GenericSubstitution>(); + GenericSubstitution* genericSubst = getLinkage()->getASTBuilder()->create<GenericSubstitution>(); 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<Type>(); - auto argType = specializationArg.val.as<Type>(); + auto paramType = as<Type>(param.object); + auto argType = as<Type>(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<ComponentType> createSpecializedEntryPoint( EntryPoint* unspecializedEntryPoint, - List<RefPtr<Expr>> const& argExprs, + List<Expr*> const& argExprs, DiagnosticSink* sink) { // We need to convert all of the `Expr` arguments @@ -1316,7 +1316,7 @@ namespace Slang void parseSpecializationArgStrings( EndToEndCompileRequest* endToEndReq, List<String> const& genericArgStrings, - List<RefPtr<Expr>>& outGenericArgs) + List<Expr*>& outGenericArgs) { auto unspecialiedProgram = endToEndReq->getUnspecializedGlobalComponentType(); @@ -1343,7 +1343,7 @@ namespace Slang // for(auto name : genericArgStrings) { - RefPtr<Expr> 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<Type>(); + auto paramType = as<Type>(specializationParams[aa].object); auto argType = args[aa]; ExpandedSpecializationArg arg; @@ -1387,7 +1387,7 @@ namespace Slang specializationArgs.add(arg); } - RefPtr<ExistentialSpecializedType> specializedType = m_astBuilder->create<ExistentialSpecializedType>(); + ExistentialSpecializedType* specializedType = m_astBuilder->create<ExistentialSpecializedType>(); specializedType->baseType = unspecializedType; specializedType->args = specializationArgs; @@ -1400,7 +1400,7 @@ namespace Slang static RefPtr<ComponentType> _createSpecializedProgramImpl( Linkage* linkage, ComponentType* unspecializedProgram, - List<RefPtr<Expr>> const& specializationArgExprs, + List<Expr*> 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<RefPtr<Expr>> specializationArgExprs; + List<Expr*> 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<RefPtr<Expr>> globalSpecializationArgs; + List<Expr*> 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<Expr> SemanticsVisitor::checkPredicateExpr(Expr* expr) + Expr* SemanticsVisitor::checkPredicateExpr(Expr* expr) { - RefPtr<Expr> 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<Expr> SemanticsVisitor::checkExpressionAndExpectIntegerConstant(RefPtr<Expr> expr, RefPtr<IntVal>* 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<ConstModifier>()); stmt->varDecl->setCheckState(DeclCheckState::Checked); - RefPtr<IntVal> rangeBeginVal; - RefPtr<IntVal> rangeEndVal; + IntVal* rangeBeginVal = nullptr; + IntVal* rangeEndVal = nullptr; if (stmt->rangeBeginExpr) { @@ -166,7 +166,7 @@ namespace Slang } else { - RefPtr<ConstantIntVal> rangeBeginConst = m_astBuilder->create<ConstantIntVal>(); + ConstantIntVal* rangeBeginConst = m_astBuilder->create<ConstantIntVal>(); 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<Type> checkProperType( + Type* checkProperType( Linkage* linkage, TypeExp typeExp, DiagnosticSink* sink) @@ -21,7 +21,7 @@ namespace Slang return typeOut.type; } - RefPtr<Expr> SemanticsVisitor::TranslateTypeNodeImpl(const RefPtr<Expr> & node) + Expr* SemanticsVisitor::TranslateTypeNodeImpl(Expr* node) { if (!node) return nullptr; @@ -30,7 +30,7 @@ namespace Slang return expr; } - RefPtr<Type> SemanticsVisitor::ExtractTypeFromTypeRepr(const RefPtr<Expr>& typeRepr) + Type* SemanticsVisitor::ExtractTypeFromTypeRepr(Expr* typeRepr) { if (!typeRepr) return nullptr; if (auto typeType = as<TypeType>(typeRepr->type)) @@ -40,7 +40,7 @@ namespace Slang return m_astBuilder->getErrorType(); } - RefPtr<Type> SemanticsVisitor::TranslateTypeNode(const RefPtr<Expr> & node) + Type* SemanticsVisitor::TranslateTypeNode(Expr* node) { if (!node) return nullptr; auto typeRepr = TranslateTypeNodeImpl(node); @@ -70,7 +70,7 @@ namespace Slang return TranslateTypeNodeForced(typeExp); } - RefPtr<Expr> SemanticsVisitor::ExpectATypeRepr(RefPtr<Expr> expr) + Expr* SemanticsVisitor::ExpectATypeRepr(Expr* expr) { if (auto overloadedExpr = as<OverloadedExpr>(expr)) { @@ -90,7 +90,7 @@ namespace Slang return CreateErrorExpr(expr); } - RefPtr<Type> SemanticsVisitor::ExpectAType(RefPtr<Expr> expr) + Type* SemanticsVisitor::ExpectAType(Expr* expr) { auto typeRepr = ExpectATypeRepr(expr); if (auto typeType = as<TypeType>(typeRepr->type)) @@ -100,14 +100,14 @@ namespace Slang return m_astBuilder->getErrorType(); } - RefPtr<Type> SemanticsVisitor::ExtractGenericArgType(RefPtr<Expr> exp) + Type* SemanticsVisitor::ExtractGenericArgType(Expr* exp) { return ExpectAType(exp); } - RefPtr<IntVal> SemanticsVisitor::ExtractGenericArgInteger(RefPtr<Expr> exp, DiagnosticSink* sink) + IntVal* SemanticsVisitor::ExtractGenericArgInteger(Expr* exp, DiagnosticSink* sink) { - RefPtr<IntVal> 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<IntVal> SemanticsVisitor::ExtractGenericArgInteger(RefPtr<Expr> exp) + IntVal* SemanticsVisitor::ExtractGenericArgInteger(Expr* exp) { return ExtractGenericArgInteger(exp, getSink()); } - RefPtr<Val> SemanticsVisitor::ExtractGenericArgVal(RefPtr<Expr> exp) + Val* SemanticsVisitor::ExtractGenericArgVal(Expr* exp) { if (auto overloadedExpr = as<OverloadedExpr>(exp)) { @@ -145,11 +145,11 @@ namespace Slang } } - RefPtr<Type> SemanticsVisitor::InstantiateGenericType( + Type* SemanticsVisitor::InstantiateGenericType( DeclRef<GenericDecl> genericDeclRef, - List<RefPtr<Expr>> const& args) + List<Expr*> const& args) { - RefPtr<GenericSubstitution> subst = m_astBuilder->create<GenericSubstitution>(); + GenericSubstitution* subst = m_astBuilder->create<GenericSubstitution>(); subst->genericDecl = genericDeclRef.getDecl(); subst->outer = genericDeclRef.substitutions.substitutions; @@ -167,10 +167,10 @@ namespace Slang bool SemanticsVisitor::CoerceToProperTypeImpl( TypeExp const& typeExp, - RefPtr<Type>* 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<RefPtr<Expr>> args; - for (RefPtr<Decl> member : genericDeclRef.getDecl()->members) + List<Expr*> args; + for (Decl* member : genericDeclRef.getDecl()->members) { if (auto typeParam = as<GenericTypeParamDecl>(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<BasicExpressionType>(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<IntVal> left, - RefPtr<IntVal> right) + IntVal* left, + IntVal* right) { if(left == right) return true; @@ -328,25 +328,25 @@ namespace Slang return false; } - RefPtr<VectorExpressionType> SemanticsVisitor::createVectorType( - RefPtr<Type> elementType, - RefPtr<IntVal> elementCount) + VectorExpressionType* SemanticsVisitor::createVectorType( + Type* elementType, + IntVal* elementCount) { - auto vectorGenericDecl = m_astBuilder->getSharedASTBuilder()->findMagicDecl("Vector").as<GenericDecl>(); + auto vectorGenericDecl = as<GenericDecl>(m_astBuilder->getSharedASTBuilder()->findMagicDecl("Vector")); auto vectorTypeDecl = vectorGenericDecl->inner; auto substitutions = m_astBuilder->create<GenericSubstitution>(); - substitutions->genericDecl = vectorGenericDecl.Ptr(); + substitutions->genericDecl = vectorGenericDecl; substitutions->args.add(elementType); substitutions->args.add(elementCount); - auto declRef = DeclRef<Decl>(vectorTypeDecl.Ptr(), substitutions); + auto declRef = DeclRef<Decl>(vectorTypeDecl, substitutions); - return DeclRefType::create(m_astBuilder, declRef).as<VectorExpressionType>(); + return as<VectorExpressionType>(DeclRefType::create(m_astBuilder, declRef)); } - RefPtr<Expr> SemanticsExprVisitor::visitSharedTypeExpr(SharedTypeExpr* expr) + Expr* SemanticsExprVisitor::visitSharedTypeExpr(SharedTypeExpr* expr) { if (!expr->type.Ptr()) { @@ -356,12 +356,12 @@ namespace Slang return expr; } - RefPtr<Expr> 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<TaggedUnionType> type = m_astBuilder->create<TaggedUnionType>(); + TaggedUnionType* type = m_astBuilder->create<TaggedUnionType>(); 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<String, RefPtr<Type>> m_types; + Dictionary<String, Type*> m_types; }; /// A component type built up from other component types. @@ -604,7 +604,7 @@ namespace Slang List<String> const& getFilePathDependencies() SLANG_OVERRIDE { return m_base->getFilePathDependencies(); } /// Get a list of tagged-union types referenced by the specialization parameters. - List<RefPtr<TaggedUnionType>> const& getTaggedUnionTypes() { return m_taggedUnionTypes; } + List<TaggedUnionType*> const& getTaggedUnionTypes() { return m_taggedUnionTypes; } RefPtr<IRModule> getIRModule() { return m_irModule; } @@ -632,7 +632,7 @@ namespace Slang List<String> m_entryPointMangledNames; // Any tagged union types that were referenced by the specialization arguments. - List<RefPtr<TaggedUnionType>> m_taggedUnionTypes; + List<TaggedUnionType*> m_taggedUnionTypes; }; @@ -711,7 +711,7 @@ namespace Slang DeclRef<FuncDecl> getFuncDeclRef() { return m_funcDeclRef; } /// Get the function declaration (without generic arguments). - RefPtr<FuncDecl> 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<Decl> paramDecl; - RefPtr<Val> argVal; + Decl* paramDecl = nullptr; + Val* argVal = nullptr; }; List<GenericArgInfo> genericArgs; @@ -1012,7 +1012,7 @@ namespace Slang private: // The AST for the module - RefPtr<ModuleDecl> m_moduleDecl; + ModuleDecl* m_moduleDecl = nullptr; // The IR for the module RefPtr<IRModule> m_irModule = nullptr; @@ -1092,7 +1092,7 @@ namespace Slang RefPtr<Module> module; Module* getModule() { return module; } - RefPtr<ModuleDecl> 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<ASTBuilder> 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<Expr> parseTermString(String str, RefPtr<Scope> scope); + Expr* parseTermString(String str, RefPtr<Scope> 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<RefPtr<Type>> m_specializedTypes; + List<Type*> 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<Scope> hlslLanguageScope; RefPtr<Scope> slangLanguageScope; - List<RefPtr<ModuleDecl>> loadedModuleCode; + ModuleDecl* baseModuleDecl = nullptr; + List<RefPtr<Module>> loadedModuleCode; SourceManager builtinSourceManager; @@ -2074,10 +2085,7 @@ namespace Slang RefPtr<SharedASTBuilder> 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<ModuleDecl*> m_modulesAlreadyEmitted; - ModuleDecl* m_program; + ModuleDecl* m_program = nullptr; UInt m_uniqueIDCounter = 1; Dictionary<IRInst*, UInt> 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<ExtensionDecl> ApplyExtensionToType( SemanticsVisitor* semantics, ExtensionDecl* extDecl, - RefPtr<Type> type); + Type* type); // @@ -268,7 +268,7 @@ LookupResult lookUpDirectAndTransparentMembers( } -static RefPtr<SubtypeWitness> _makeSubtypeWitness( +static SubtypeWitness* _makeSubtypeWitness( ASTBuilder* astBuilder, Type* subType, SubtypeWitness* subToMidWitness, @@ -277,7 +277,7 @@ static RefPtr<SubtypeWitness> _makeSubtypeWitness( { if(subToMidWitness) { - RefPtr<TransitiveSubtypeWitness> transitiveWitness = astBuilder->create<TransitiveSubtypeWitness>(); + TransitiveSubtypeWitness* transitiveWitness = astBuilder->create<TransitiveSubtypeWitness>(); transitiveWitness->subToMid = subToMidWitness; transitiveWitness->midToSup = midToSuperConstraint; transitiveWitness->sub = subType; @@ -286,7 +286,7 @@ static RefPtr<SubtypeWitness> _makeSubtypeWitness( } else { - RefPtr<DeclaredSubtypeWitness> declaredWitness = astBuilder->create<DeclaredSubtypeWitness>(); + DeclaredSubtypeWitness* declaredWitness = astBuilder->create<DeclaredSubtypeWitness>(); declaredWitness->declRef = midToSuperConstraint; declaredWitness->sub = subType; declaredWitness->sup = superType; @@ -295,7 +295,7 @@ static RefPtr<SubtypeWitness> _makeSubtypeWitness( } // Same as the above, but we are specializing a type instead of a decl-ref -static RefPtr<Type> _maybeSpecializeSuperType( +static Type* _maybeSpecializeSuperType( ASTBuilder* astBuilder, Type* superType, SubtypeWitness* subIsSuperWitness) @@ -304,7 +304,7 @@ static RefPtr<Type> _maybeSpecializeSuperType( { if (auto superInterfaceDeclRef = superDeclRefType->declRef.as<InterfaceDecl>()) { - RefPtr<ThisTypeSubstitution> thisTypeSubst = astBuilder->create<ThisTypeSubstitution>(); + ThisTypeSubstitution* thisTypeSubst = astBuilder->create<ThisTypeSubstitution>(); thisTypeSubst->interfaceDecl = superInterfaceDeclRef.getDecl(); thisTypeSubst->witness = subIsSuperWitness; thisTypeSubst->outer = superInterfaceDeclRef.substitutions.substitutions; @@ -322,7 +322,7 @@ static RefPtr<Type> _maybeSpecializeSuperType( static void _lookUpMembersInType( ASTBuilder* astBuilder, Name* name, - RefPtr<Type> 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* 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* type = nullptr; if(auto extDeclRef = aggTypeDeclBaseRef.as<ExtensionDecl>()) { 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<Decl> declRef, - RefPtr<Type>* 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<Modifier> mod : decl->modifiers) + for(Modifier* mod : decl->modifiers) { if(as<HLSLNoInterpolationModifier>(mod)) { @@ -1947,7 +1947,7 @@ DeclRef<D> createDefaultSpecializedDeclRef(IRGenContext* context, D* decl) /// includes things like function declarations themselves, which inherit the /// definition of `this` from their parent/outer declaration. /// -RefPtr<Type> getThisParamTypeForContainer( +Type* getThisParamTypeForContainer( IRGenContext* context, DeclRef<Decl> parentDeclRef) { @@ -1963,7 +1963,7 @@ RefPtr<Type> getThisParamTypeForContainer( return nullptr; } -RefPtr<Type> getThisParamTypeForCallable( +Type* getThisParamTypeForCallable( IRGenContext* context, DeclRef<Decl> callableDeclRef) { @@ -2537,7 +2537,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo> auto paramDirection = getParameterDirection(paramDecl); UInt argIndex = argCounter++; - RefPtr<Expr> argExpr; + Expr* argExpr = nullptr; if(argIndex < argCount) { argExpr = expr->arguments[argIndex]; @@ -2621,7 +2621,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo> // with some contextual information about the declaration // we are calling. bool tryResolveDeclRefForCall( - RefPtr<Expr> funcExpr, + Expr* funcExpr, ResolvedCallInfo* outInfo) { // TODO: unwrap any "identity" expressions that might @@ -2673,7 +2673,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo> { // 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<DeclLoweringVisitor, LoweredValInfo> // the inheritance declaration is on an `extension` declaration, // then we need to identify the type being extended. // - RefPtr<Type> subType; + Type* subType = nullptr; if (auto extParentDecl = as<ExtensionDecl>(parentDecl)) { subType = extParentDecl->targetType.type; @@ -4598,7 +4598,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> } // What is the super-type that we have declared we inherit from? - RefPtr<Type> superType = inheritanceDecl->base.type; + Type* superType = inheritanceDecl->base.type; if(auto superDeclRefType = as<DeclRefType>(superType)) { @@ -5504,14 +5504,14 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> struct ParameterInfo { // This AST-level type of the parameter - RefPtr<Type> 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> decl) +bool canDeclLowerToAGeneric(Decl* decl) { // A callable decl lowers to an `IRFunc`, and can be generic if(as<CallableDecl>(decl)) return true; @@ -6593,8 +6593,8 @@ bool canDeclLowerToAGeneric(RefPtr<Decl> decl) LoweredValInfo emitDeclRef( IRGenContext* context, - RefPtr<Decl> decl, - RefPtr<Substitutions> 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<GenericSubstitution>()) + if(auto genericSubst = as<GenericSubstitution>(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<ThisTypeSubstitution>()) + else if(auto thisTypeSubst = as<ThisTypeSubstitution>(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<FunctionDeclBase>()) @@ -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<typename T> static bool findLayoutArg( - RefPtr<ModifiableSyntaxNode> syntax, + ModifiableSyntaxNode* syntax, UInt* outVal) { for( auto modifier : syntax->getModifiersOfType<T>() ) @@ -674,7 +674,7 @@ struct EntryPointParameterState static RefPtr<TypeLayout> processEntryPointVaryingParameter( ParameterBindingContext* context, - RefPtr<Type> type, + Type* type, EntryPointParameterState const& state, RefPtr<VarLayout> 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<Type>(); + auto type = as<Type>(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<Decl> varDecl2(varDecl); + // Try to find `constant_id` binding - if(!findLayoutArg<GLSLConstantIDLayoutModifier>(varDecl, &semanticInfo.index)) + if(!findLayoutArg<GLSLConstantIDLayoutModifier>(varDecl2, &semanticInfo.index)) return; } @@ -1382,7 +1384,7 @@ SimpleSemanticInfo decomposeSimpleSemantic( static RefPtr<TypeLayout> processSimpleEntryPointParameter( ParameterBindingContext* context, - RefPtr<Type> type, + Type* type, EntryPointParameterState const& inState, RefPtr<VarLayout> varLayout, int semanticSlotCount = 1) @@ -1546,7 +1548,7 @@ static RefPtr<TypeLayout> processSimpleEntryPointParameter( static RefPtr<TypeLayout> processEntryPointVaryingParameterDecl( ParameterBindingContext* context, Decl* decl, - RefPtr<Type> type, + Type* type, EntryPointParameterState const& inState, RefPtr<VarLayout> varLayout) { @@ -1703,7 +1705,7 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameterDecl( static RefPtr<TypeLayout> processEntryPointVaryingParameter( ParameterBindingContext* context, - RefPtr<Type> type, + Type* type, EntryPointParameterState const& state, RefPtr<VarLayout> varLayout) { @@ -2712,7 +2714,7 @@ static void collectSpecializationParams( case SpecializationParam::Flavor::GenericValue: { RefPtr<GenericSpecializationParamLayout> paramLayout = new GenericSpecializationParamLayout(); - paramLayout->decl = specializationParam.object.as<Decl>(); + paramLayout->decl = as<Decl>(specializationParam.object); context->shared->programLayout->specializationParams.add(paramLayout); } break; @@ -2721,7 +2723,7 @@ static void collectSpecializationParams( case SpecializationParam::Flavor::ExistentialValue: { RefPtr<ExistentialSpecializationParamLayout> paramLayout = new ExistentialSpecializationParamLayout(); - paramLayout->type = specializationParam.object.as<Type>(); + paramLayout->type = as<Type>(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<T>() != nullptr; } - RefPtr<Modifier> getFirst() { return m_result; }; + Modifier* getFirst() { return m_result; }; protected: - RefPtr<Modifier> m_result; - RefPtr<Modifier>* 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<Decl> ParseStruct(); - RefPtr<ClassDecl> ParseClass(); - RefPtr<Stmt> ParseStatement(); - RefPtr<Stmt> parseBlockStatement(); - RefPtr<DeclStmt> parseVarDeclrStatement(Modifiers modifiers); - RefPtr<IfStmt> parseIfStatement(); - RefPtr<ForStmt> ParseForStatement(); - RefPtr<WhileStmt> ParseWhileStatement(); - RefPtr<DoWhileStmt> ParseDoWhileStatement(); - RefPtr<BreakStmt> ParseBreakStatement(); - RefPtr<ContinueStmt> ParseContinueStatement(); - RefPtr<ReturnStmt> ParseReturnStatement(); - RefPtr<ExpressionStmt> ParseExpressionStatement(); - RefPtr<Expr> 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<Expr> ParseInitExpr() { return ParseExpression(Precedence::Assignment); } - inline RefPtr<Expr> ParseArgExpr() { return ParseExpression(Precedence::Assignment); } + inline Expr* ParseInitExpr() { return ParseExpression(Precedence::Assignment); } + inline Expr* ParseArgExpr() { return ParseExpression(Precedence::Assignment); } - RefPtr<Expr> ParseLeafExpression(); - RefPtr<ParamDecl> ParseParameter(); - RefPtr<Expr> 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<Decl> parseEnumDecl(Parser* parser); + static Decl* parseEnumDecl(Parser* parser); - static RefPtr<Modifier> ParseOptSemantics( + static Modifier* ParseOptSemantics( Parser* parser); static void ParseOptSemantics( Parser* parser, Decl* decl); - static RefPtr<DeclBase> ParseDecl( + static DeclBase* ParseDecl( Parser* parser, ContainerDecl* containerDecl); - static RefPtr<Decl> ParseSingleDecl( + static Decl* ParseSingleDecl( Parser* parser, ContainerDecl* containerDecl); @@ -586,9 +586,9 @@ namespace Slang return false; } - RefPtr<RefObject> ParseTypeDef(Parser* parser, void* /*userData*/) + NodeBase* ParseTypeDef(Parser* parser, void* /*userData*/) { - RefPtr<TypeDefDecl> typeDefDecl = parser->astBuilder->create<TypeDefDecl>(); + TypeDefDecl* typeDefDecl = parser->astBuilder->create<TypeDefDecl>(); // 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<Modifier>** ioModifierLink, RefPtr<Modifier> modifier) + static void AddModifier(Modifier*** ioModifierLink, Modifier* modifier) { - RefPtr<Modifier>*& 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<Modifier> linkMod = *modifierLink; + Modifier* linkMod = *modifierLink; if(as<SharedModifiers>(linkMod)) { break; @@ -648,8 +648,8 @@ namespace Slang } void addModifier( - RefPtr<ModifiableSyntaxNode> syntax, - RefPtr<Modifier> 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<Modifier>** ioModifierLink) + static void ParseSquareBracketAttributes(Parser* parser, Modifier*** ioModifierLink) { parser->ReadToken(TokenType::LBracket); @@ -725,7 +725,7 @@ namespace Slang Token nameToken = parseAttributeName(parser); - RefPtr<UncheckedAttribute> modifier = parser->astBuilder->create<UncheckedAttribute>(); + UncheckedAttribute* modifier = parser->astBuilder->create<UncheckedAttribute>(); 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<T>* 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<RefObject> parsedObject = syntaxDecl->parseCallback(parser, syntaxDecl->parseUserData); + NodeBase* parsedObject = syntaxDecl->parseCallback(parser, syntaxDecl->parseUserData); if (!parsedObject) { return false; @@ -849,7 +849,7 @@ namespace Slang template<typename T> bool tryParseUsingSyntaxDecl( Parser* parser, - RefPtr<T>* outSyntax) + T** outSyntax) { if (peekTokenType(parser) != TokenType::Identifier) return false; @@ -868,7 +868,7 @@ namespace Slang static Modifiers ParseModifiers(Parser* parser) { Modifiers modifiers; - RefPtr<Modifier>* modifierLink = &modifiers.first; + Modifier** modifierLink = &modifiers.first; for (;;) { SourceLoc loc = parser->tokenReader.peekLoc(); @@ -887,7 +887,7 @@ namespace Slang Token nameToken = peekToken(parser); - RefPtr<Modifier> parsedModifier; + Modifier* parsedModifier = nullptr; if (tryParseUsingSyntaxDecl<Modifier>(parser, &parsedModifier)) { parsedModifier->name = nameToken.getName(); @@ -926,7 +926,7 @@ namespace Slang } - static RefPtr<RefObject> 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<Expr> elementCountExpr; + Expr* elementCountExpr = nullptr; }; // "Unwrapped" information about a declarator struct DeclaratorInfo { - RefPtr<Expr> typeSpec; + Expr* typeSpec = nullptr; NameLoc nameAndLoc; - RefPtr<Modifier> semantics; - RefPtr<Expr> 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<ContainerDecl> container, RefPtr<Decl> 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> scope, RefPtr<Decl> member) + static void AddMember(RefPtr<Scope> scope, Decl* member) { if (scope) { @@ -1091,9 +1091,9 @@ namespace Slang } } - static RefPtr<Decl> ParseGenericParamDecl( + static Decl* ParseGenericParamDecl( Parser* parser, - RefPtr<GenericDecl> 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<GenericTypeParamDecl> paramDecl = parser->astBuilder->create<GenericTypeParamDecl>(); + GenericTypeParamDecl* paramDecl = parser->astBuilder->create<GenericTypeParamDecl>(); parser->FillPosition(paramDecl); paramDecl->nameAndLoc = NameLoc(parser->ReadToken(TokenType::Identifier)); if (AdvanceIf(parser, TokenType::Colon)) @@ -1178,13 +1178,13 @@ namespace Slang } template<typename ParseFunc> - static RefPtr<Decl> parseOptGenericDecl( + static Decl* parseOptGenericDecl( Parser* parser, const ParseFunc& parseInner) { // TODO: may want more advanced disambiguation than this... if (parser->LookAheadToken(TokenType::OpLess)) { - RefPtr<GenericDecl> genericDecl = parser->astBuilder->create<GenericDecl>(); + GenericDecl* genericDecl = parser->astBuilder->create<GenericDecl>(); parser->FillPosition(genericDecl); parser->PushScope(genericDecl); ParseGenericDeclImpl(parser, genericDecl, parseInner); @@ -1197,19 +1197,19 @@ namespace Slang } } - static RefPtr<RefObject> ParseGenericDecl(Parser* parser, void*) + static NodeBase* ParseGenericDecl(Parser* parser, void*) { - RefPtr<GenericDecl> decl = parser->astBuilder->create<GenericDecl>(); - parser->FillPosition(decl.Ptr()); - parser->PushScope(decl.Ptr()); - ParseGenericDeclImpl(parser, decl.Ptr(), [=](GenericDecl* genDecl) {return ParseSingleDecl(parser, genDecl); }); + GenericDecl* decl = parser->astBuilder->create<GenericDecl>(); + 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<CallableDecl> 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<Stmt> 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<Decl> parseTraditionalFuncDecl( + static Decl* parseTraditionalFuncDecl( Parser* parser, DeclaratorInfo const& declaratorInfo) { - RefPtr<FuncDecl> decl = parser->astBuilder->create<FuncDecl>(); - parser->FillPosition(decl.Ptr()); + FuncDecl* decl = parser->astBuilder->create<FuncDecl>(); + 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<VarDeclBase> 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<Modifier> modifiers) + void AddModifiers(Decl* decl, Modifier* modifiers) { if (!modifiers) return; - RefPtr<Modifier>* 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<VarDeclBase> 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> declarator; - RefPtr<Modifier> semantics; - RefPtr<Expr> 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> decl; - RefPtr<DeclGroup> group; + Decl* decl = nullptr; + DeclGroup* group = nullptr; ASTBuilder* astBuilder = nullptr; // Add a new declaration to the potential group void addDecl( - RefPtr<Decl> newDecl) + Decl* newDecl) { SLANG_ASSERT(newDecl); @@ -1647,7 +1647,7 @@ namespace Slang } } - RefPtr<DeclBase> 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<Expr> ParseGenericArg(Parser* parser) + Expr* ParseGenericArg(Parser* parser) { return parser->ParseArgExpr(); } // Create a type expression that will refer to the given declaration - static RefPtr<Expr> - createDeclRefType(Parser* parser, RefPtr<Decl> 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* decl = nullptr; // Put the resulting expression (which should evaluate to a type) here - RefPtr<Expr> expr; + Expr* expr = nullptr; }; - static RefPtr<Expr> parseGenericApp( + static Expr* parseGenericApp( Parser* parser, - RefPtr<Expr> base) + Expr* base) { - RefPtr<GenericAppExpr> genericApp = parser->astBuilder->create<GenericAppExpr>(); + GenericAppExpr* genericApp = parser->astBuilder->create<GenericAppExpr>(); - 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<GenericDecl>(); } - static RefPtr<Expr> tryParseGenericApp( + static Expr* tryParseGenericApp( Parser* parser, - RefPtr<Expr> base) + Expr* base) { Name * baseName = nullptr; if (auto varExpr = as<VarExpr>(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<Expr> parseMemberType(Parser * parser, RefPtr<Expr> base) + static Expr* parseMemberType(Parser * parser, Expr* base) { // When called the :: or . have been consumed, so don't need to consume here. - RefPtr<MemberExpr> memberExpr = parser->astBuilder->create<MemberExpr>(); + MemberExpr* memberExpr = parser->astBuilder->create<MemberExpr>(); - 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<Expr> parsePostfixTypeSuffix( + static Expr* parsePostfixTypeSuffix( Parser* parser, - RefPtr<Expr> inTypeExpr) + Expr* inTypeExpr) { auto typeExpr = inTypeExpr; while (parser->LookAheadToken(TokenType::LBracket)) { - RefPtr<IndexExpr> arrType = parser->astBuilder->create<IndexExpr>(); + IndexExpr* arrType = parser->astBuilder->create<IndexExpr>(); arrType->loc = typeExpr->loc; arrType->baseExpression = typeExpr; parser->ReadToken(TokenType::LBracket); @@ -1805,9 +1807,9 @@ namespace Slang return typeExpr; } - static RefPtr<Expr> parseTaggedUnionType(Parser* parser) + static Expr* parseTaggedUnionType(Parser* parser) { - RefPtr<TaggedUnionTypeExpr> taggedUnionType = parser->astBuilder->create<TaggedUnionTypeExpr>(); + TaggedUnionTypeExpr* taggedUnionType = parser->astBuilder->create<TaggedUnionTypeExpr>(); parser->ReadToken(TokenType::LParent); while(!AdvanceIfMatch(parser, TokenType::RParent)) @@ -1824,20 +1826,20 @@ namespace Slang return taggedUnionType; } - static RefPtr<RefObject> parseTaggedUnionType(Parser* parser, void* /*unused*/) + static NodeBase* parseTaggedUnionType(Parser* parser, void* /*unused*/) { return parseTaggedUnionType(parser); } /// Parse a `This` type expression - static RefPtr<Expr> parseThisTypeExpr(Parser* parser) + static Expr* parseThisTypeExpr(Parser* parser) { - RefPtr<ThisTypeExpr> expr = parser->astBuilder->create<ThisTypeExpr>(); + ThisTypeExpr* expr = parser->astBuilder->create<ThisTypeExpr>(); expr->scope = parser->currentScope; return expr; } - static RefPtr<RefObject> 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<Expr> typeExpr = basicType; + Expr* typeExpr = basicType; bool shouldLoop = true; while (shouldLoop) @@ -1936,7 +1938,7 @@ namespace Slang return typeSpec; } - static RefPtr<DeclBase> 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<VarDeclBase> 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<VarDeclBase> 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<Modifier> ParseSemantic( + static Modifier* ParseSemantic( Parser* parser) { if (parser->LookAheadToken("register")) { - RefPtr<HLSLRegisterSemantic> semantic = parser->astBuilder->create<HLSLRegisterSemantic>(); + HLSLRegisterSemantic* semantic = parser->astBuilder->create<HLSLRegisterSemantic>(); parser->FillPosition(semantic); - parseHLSLRegisterSemantic(parser, semantic.Ptr()); + parseHLSLRegisterSemantic(parser, semantic); return semantic; } else if (parser->LookAheadToken("packoffset")) { - RefPtr<HLSLPackOffsetSemantic> semantic = parser->astBuilder->create<HLSLPackOffsetSemantic>(); + HLSLPackOffsetSemantic* semantic = parser->astBuilder->create<HLSLPackOffsetSemantic>(); parser->FillPosition(semantic); - parseHLSLPackOffsetSemantic(parser, semantic.Ptr()); + parseHLSLPackOffsetSemantic(parser, semantic); return semantic; } else if (parser->LookAheadToken(TokenType::Identifier)) { - RefPtr<HLSLSimpleSemantic> semantic = parser->astBuilder->create<HLSLSimpleSemantic>(); + HLSLSimpleSemantic* semantic = parser->astBuilder->create<HLSLSimpleSemantic>(); parser->FillPosition(semantic); semantic->name = parser->ReadToken(TokenType::Identifier); return semantic; @@ -2217,19 +2219,19 @@ namespace Slang // // opt-semantics ::= (':' semantic)* // - static RefPtr<Modifier> ParseOptSemantics( + static Modifier* ParseOptSemantics( Parser* parser) { if (!AdvanceIf(parser, TokenType::Colon)) return nullptr; - RefPtr<Modifier> result; - RefPtr<Modifier>* link = &result; + Modifier* result = nullptr; + Modifier** link = &result; SLANG_ASSERT(!*link); for (;;) { - RefPtr<Modifier> semantic = ParseSemantic(parser); + Modifier* semantic = ParseSemantic(parser); if (semantic) { *link = semantic; @@ -2268,7 +2270,7 @@ namespace Slang AddModifiers(decl, ParseOptSemantics(parser)); } - static RefPtr<Decl> 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<StructDecl> bufferDataTypeDecl = parser->astBuilder->create<StructDecl>(); - RefPtr<VarDecl> bufferVarDecl = parser->astBuilder->create<VarDecl>(); + StructDecl* bufferDataTypeDecl = parser->astBuilder->create<StructDecl>(); + VarDecl* bufferVarDecl = parser->astBuilder->create<VarDecl>(); // 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<RefObject> parseHLSLCBufferDecl( + static NodeBase* parseHLSLCBufferDecl( Parser* parser, void* /*userData*/) { return ParseHLSLBufferDecl(parser, "ConstantBuffer"); } - static RefPtr<RefObject> parseHLSLTBufferDecl( + static NodeBase* parseHLSLTBufferDecl( Parser* parser, void* /*userData*/) { return ParseHLSLBufferDecl(parser, "TextureBuffer"); @@ -2401,31 +2403,31 @@ namespace Slang } } - static RefPtr<RefObject> ParseExtensionDecl(Parser* parser, void* /*userData*/) + static NodeBase* ParseExtensionDecl(Parser* parser, void* /*userData*/) { - RefPtr<ExtensionDecl> decl = parser->astBuilder->create<ExtensionDecl>(); - parser->FillPosition(decl.Ptr()); + ExtensionDecl* decl = parser->astBuilder->create<ExtensionDecl>(); + 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<GenericTypeConstraintDecl> paramConstraint = parser->astBuilder->create<GenericTypeConstraintDecl>(); + GenericTypeConstraintDecl* paramConstraint = parser->astBuilder->create<GenericTypeConstraintDecl>(); parser->FillPosition(paramConstraint); // substitution needs to be filled during check - RefPtr<DeclRefType> paramType = DeclRefType::create(parser->astBuilder, DeclRef<Decl>(decl, nullptr)); + DeclRefType* paramType = DeclRefType::create(parser->astBuilder, DeclRef<Decl>(decl, nullptr)); - RefPtr<SharedTypeExpr> paramTypeExpr = parser->astBuilder->create<SharedTypeExpr>(); + SharedTypeExpr* paramTypeExpr = parser->astBuilder->create<SharedTypeExpr>(); paramTypeExpr->loc = decl->loc; paramTypeExpr->base.type = paramType; paramTypeExpr->type = QualType(parser->astBuilder->getTypeType(paramType)); @@ -2438,9 +2440,9 @@ namespace Slang } } - RefPtr<RefObject> parseAssocType(Parser* parser, void *) + static NodeBase* parseAssocType(Parser* parser, void *) { - RefPtr<AssocTypeDecl> assocTypeDecl = parser->astBuilder->create<AssocTypeDecl>(); + AssocTypeDecl* assocTypeDecl = parser->astBuilder->create<AssocTypeDecl>(); auto nameToken = parser->ReadToken(TokenType::Identifier); assocTypeDecl->nameAndLoc = NameLoc(nameToken); @@ -2450,9 +2452,9 @@ namespace Slang return assocTypeDecl; } - RefPtr<RefObject> parseGlobalGenericTypeParamDecl(Parser * parser, void *) + static NodeBase* parseGlobalGenericTypeParamDecl(Parser * parser, void *) { - RefPtr<GlobalGenericParamDecl> genParamDecl = parser->astBuilder->create<GlobalGenericParamDecl>(); + GlobalGenericParamDecl* genParamDecl = parser->astBuilder->create<GlobalGenericParamDecl>(); auto nameToken = parser->ReadToken(TokenType::Identifier); genParamDecl->nameAndLoc = NameLoc(nameToken); genParamDecl->loc = nameToken.loc; @@ -2461,9 +2463,9 @@ namespace Slang return genParamDecl; } - RefPtr<RefObject> parseGlobalGenericValueParamDecl(Parser * parser, void *) + static NodeBase* parseGlobalGenericValueParamDecl(Parser * parser, void *) { - RefPtr<GlobalGenericValueParamDecl> genericParamDecl = parser->astBuilder->create<GlobalGenericValueParamDecl>(); + GlobalGenericValueParamDecl* genericParamDecl = parser->astBuilder->create<GlobalGenericValueParamDecl>(); auto nameToken = parser->ReadToken(TokenType::Identifier); genericParamDecl->nameAndLoc = NameLoc(nameToken); genericParamDecl->loc = nameToken.loc; @@ -2482,20 +2484,20 @@ namespace Slang return genericParamDecl; } - static RefPtr<RefObject> parseInterfaceDecl(Parser* parser, void* /*userData*/) + static NodeBase* parseInterfaceDecl(Parser* parser, void* /*userData*/) { - RefPtr<InterfaceDecl> decl = parser->astBuilder->create<InterfaceDecl>(); - parser->FillPosition(decl.Ptr()); + InterfaceDecl* decl = parser->astBuilder->create<InterfaceDecl>(); + 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<RefObject> 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> namespaceDecl; - RefPtr<RefObject> 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<RefObject> parseConstructorDecl(Parser* parser, void* /*userData*/) + static NodeBase* parseConstructorDecl(Parser* parser, void* /*userData*/) { - RefPtr<ConstructorDecl> decl = parser->astBuilder->create<ConstructorDecl>(); - parser->FillPosition(decl.Ptr()); + ConstructorDecl* decl = parser->astBuilder->create<ConstructorDecl>(); + 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<AccessorDecl> parseAccessorDecl(Parser* parser) + static AccessorDecl* parseAccessorDecl(Parser* parser) { Modifiers modifiers = ParseModifiers(parser); - RefPtr<AccessorDecl> decl; + AccessorDecl* decl = nullptr; if( AdvanceIf(parser, "get") ) { decl = parser->astBuilder->create<GetterDecl>(); @@ -2675,10 +2677,10 @@ namespace Slang return decl; } - static RefPtr<RefObject> ParseSubscriptDecl(Parser* parser, void* /*userData*/) + static NodeBase* ParseSubscriptDecl(Parser* parser, void* /*userData*/) { - RefPtr<SubscriptDecl> decl = parser->astBuilder->create<SubscriptDecl>(); - parser->FillPosition(decl.Ptr()); + SubscriptDecl* decl = parser->astBuilder->create<SubscriptDecl>(); + 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<VarDeclBase> 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<VarDecl> decl) + VarDecl* decl) { parseModernVarDeclBaseCommon(parser, decl); expect(parser, TokenType::Semicolon); } - static RefPtr<RefObject> parseLetDecl( + static NodeBase* parseLetDecl( Parser* parser, void* /*userData*/) { - RefPtr<LetDecl> decl = parser->astBuilder->create<LetDecl>(); + LetDecl* decl = parser->astBuilder->create<LetDecl>(); parseModernVarDeclCommon(parser, decl); return decl; } - static RefPtr<RefObject> parseVarDecl( + static NodeBase* parseVarDecl( Parser* parser, void* /*userData*/) { - RefPtr<VarDecl> decl = parser->astBuilder->create<VarDecl>(); + VarDecl* decl = parser->astBuilder->create<VarDecl>(); parseModernVarDeclCommon(parser, decl); return decl; } - static RefPtr<ParamDecl> parseModernParamDecl( + static ParamDecl* parseModernParamDecl( Parser* parser) { - RefPtr<ParamDecl> decl = parser->astBuilder->create<ParamDecl>(); + ParamDecl* decl = parser->astBuilder->create<ParamDecl>(); // 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<CallableDecl> decl) + CallableDecl* decl) { parser->ReadToken(TokenType::LParent); @@ -2790,17 +2792,17 @@ namespace Slang } } - static RefPtr<RefObject> parseFuncDecl( + static NodeBase* parseFuncDecl( Parser* parser, void* /*userData*/) { - RefPtr<FuncDecl> decl = parser->astBuilder->create<FuncDecl>(); + FuncDecl* decl = parser->astBuilder->create<FuncDecl>(); - 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<RefObject> parseTypeAliasDecl( + static NodeBase* parseTypeAliasDecl( Parser* parser, void* /*userData*/) { - RefPtr<TypeAliasDecl> decl = parser->astBuilder->create<TypeAliasDecl>(); + TypeAliasDecl* decl = parser->astBuilder->create<TypeAliasDecl>(); - 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<RefObject> 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<RefObject> 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<RefObject> syntaxClass; + SyntaxClass<NodeBase> 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> syntaxDecl = parser->astBuilder->create<SyntaxDecl>(); + SyntaxDecl* syntaxDecl = parser->astBuilder->create<SyntaxDecl>(); 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<ParamDecl> parseAttributeParamDecl(Parser* parser) + static ParamDecl* parseAttributeParamDecl(Parser* parser) { auto nameAndLoc = expectIdentifier(parser); - RefPtr<ParamDecl> paramDecl = parser->astBuilder->create<ParamDecl>(); + ParamDecl* paramDecl = parser->astBuilder->create<ParamDecl>(); 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<RefObject> 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<AttributeDecl> attrDecl = parser->astBuilder->create<AttributeDecl>(); + AttributeDecl* attrDecl = parser->astBuilder->create<AttributeDecl>(); 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<RefObject> syntaxClass; + SyntaxClass<NodeBase> 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* 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<Decl> declToModify = decl; + Decl* declToModify = decl; if(auto genericDecl = as<GenericDecl>(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<DeclBase> ParseDeclWithModifiers( + static DeclBase* ParseDeclWithModifiers( Parser* parser, ContainerDecl* containerDecl, Modifiers modifiers ) { - RefPtr<DeclBase> 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<Decl> parsedDecl; + Decl* parsedDecl = nullptr; if (tryParseUsingSyntaxDecl<Decl>(parser, &parsedDecl)) { decl = parsedDecl; @@ -3129,7 +3131,7 @@ namespace Slang return decl; } - static RefPtr<DeclBase> ParseDecl( + static DeclBase* ParseDecl( Parser* parser, ContainerDecl* containerDecl) { @@ -3137,7 +3139,7 @@ namespace Slang return ParseDeclWithModifiers(parser, containerDecl, modifiers); } - static RefPtr<Decl> ParseSingleDecl( + static Decl* ParseSingleDecl( Parser* parser, ContainerDecl* containerDecl) { @@ -3218,10 +3220,10 @@ namespace Slang currentScope = nullptr; } - RefPtr<Decl> Parser::ParseStruct() + Decl* Parser::ParseStruct() { - RefPtr<StructDecl> rs = astBuilder->create<StructDecl>(); - FillPosition(rs.Ptr()); + StructDecl* rs = astBuilder->create<StructDecl>(); + 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<ClassDecl> Parser::ParseClass() + ClassDecl* Parser::ParseClass() { - RefPtr<ClassDecl> rs = astBuilder->create<ClassDecl>(); - FillPosition(rs.Ptr()); + ClassDecl* rs = astBuilder->create<ClassDecl>(); + 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<EnumCaseDecl> parseEnumCaseDecl(Parser* parser) + static EnumCaseDecl* parseEnumCaseDecl(Parser* parser) { - RefPtr<EnumCaseDecl> decl = parser->astBuilder->create<EnumCaseDecl>(); + EnumCaseDecl* decl = parser->astBuilder->create<EnumCaseDecl>(); decl->nameAndLoc = expectIdentifier(parser); if(AdvanceIf(parser, TokenType::OpAssign)) @@ -3263,9 +3265,9 @@ namespace Slang return decl; } - static RefPtr<Decl> parseEnumDecl(Parser* parser) + static Decl* parseEnumDecl(Parser* parser) { - RefPtr<EnumDecl> decl = parser->astBuilder->create<EnumDecl>(); + EnumDecl* decl = parser->astBuilder->create<EnumDecl>(); parser->FillPosition(decl); parser->ReadToken("enum"); @@ -3288,7 +3290,7 @@ namespace Slang while(!AdvanceIfMatch(parser, TokenType::RBrace)) { - RefPtr<EnumCaseDecl> caseDecl = parseEnumCaseDecl(parser); + EnumCaseDecl* caseDecl = parseEnumCaseDecl(parser); AddMember(decl, caseDecl); if(AdvanceIf(parser, TokenType::RBrace)) @@ -3300,10 +3302,10 @@ namespace Slang }); } - static RefPtr<Stmt> ParseSwitchStmt(Parser* parser) + static Stmt* ParseSwitchStmt(Parser* parser) { - RefPtr<SwitchStmt> stmt = parser->astBuilder->create<SwitchStmt>(); - parser->FillPosition(stmt.Ptr()); + SwitchStmt* stmt = parser->astBuilder->create<SwitchStmt>(); + parser->FillPosition(stmt); parser->ReadToken("switch"); parser->ReadToken(TokenType::LParent); stmt->condition = parser->ParseExpression(); @@ -3312,20 +3314,20 @@ namespace Slang return stmt; } - static RefPtr<Stmt> ParseCaseStmt(Parser* parser) + static Stmt* ParseCaseStmt(Parser* parser) { - RefPtr<CaseStmt> stmt = parser->astBuilder->create<CaseStmt>(); - parser->FillPosition(stmt.Ptr()); + CaseStmt* stmt = parser->astBuilder->create<CaseStmt>(); + parser->FillPosition(stmt); parser->ReadToken("case"); stmt->expr = parser->ParseExpression(); parser->ReadToken(TokenType::Colon); return stmt; } - static RefPtr<Stmt> ParseDefaultStmt(Parser* parser) + static Stmt* ParseDefaultStmt(Parser* parser) { - RefPtr<DefaultStmt> stmt = parser->astBuilder->create<DefaultStmt>(); - parser->FillPosition(stmt.Ptr()); + DefaultStmt* stmt = parser->astBuilder->create<DefaultStmt>(); + parser->FillPosition(stmt); parser->ReadToken("default"); parser->ReadToken(TokenType::Colon); return stmt; @@ -3365,11 +3367,11 @@ namespace Slang return isTypeName(parser, name); } - RefPtr<Stmt> parseCompileTimeForStmt( + Stmt* parseCompileTimeForStmt( Parser* parser) { - RefPtr<ScopeDecl> scopeDecl = parser->astBuilder->create<ScopeDecl>(); - RefPtr<CompileTimeForStmt> stmt = parser->astBuilder->create<CompileTimeForStmt>(); + ScopeDecl* scopeDecl = parser->astBuilder->create<ScopeDecl>(); + CompileTimeForStmt* stmt = parser->astBuilder->create<CompileTimeForStmt>(); stmt->scopeDecl = scopeDecl; @@ -3377,7 +3379,7 @@ namespace Slang parser->ReadToken(TokenType::LParent); NameLoc varNameAndLoc = expectIdentifier(parser); - RefPtr<VarDecl> varDecl = parser->astBuilder->create<VarDecl>(); + VarDecl* varDecl = parser->astBuilder->create<VarDecl>(); varDecl->nameAndLoc = varNameAndLoc; varDecl->loc = varNameAndLoc.loc; @@ -3387,8 +3389,8 @@ namespace Slang parser->ReadToken("Range"); parser->ReadToken(TokenType::LParent); - RefPtr<Expr> rangeBeginExpr; - RefPtr<Expr> 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<Stmt> parseCompileTimeStmt( + Stmt* parseCompileTimeStmt( Parser* parser) { parser->ReadToken(TokenType::Dollar); @@ -3426,11 +3428,11 @@ namespace Slang } } - RefPtr<Stmt> Parser::ParseStatement() + Stmt* Parser::ParseStatement() { auto modifiers = ParseModifiers(this); - RefPtr<Stmt> 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<DiscardStmt>(); - 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<Expr> 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<EmptyStmt>(); - FillPosition(statement.Ptr()); + FillPosition(statement); ReadToken(TokenType::Semicolon); } else @@ -3569,19 +3571,19 @@ namespace Slang return statement; } - RefPtr<Stmt> Parser::parseBlockStatement() + Stmt* Parser::parseBlockStatement() { - RefPtr<ScopeDecl> scopeDecl = astBuilder->create<ScopeDecl>(); - RefPtr<BlockStmt> blockStatement = astBuilder->create<BlockStmt>(); + ScopeDecl* scopeDecl = astBuilder->create<ScopeDecl>(); + BlockStmt* blockStatement = astBuilder->create<BlockStmt>(); blockStatement->scopeDecl = scopeDecl; - pushScopeAndSetParent(scopeDecl.Ptr()); + pushScopeAndSetParent(scopeDecl); ReadToken(TokenType::LBrace); - RefPtr<Stmt> 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<SeqStmt> newBody = astBuilder->create<SeqStmt>(); + SeqStmt* newBody = astBuilder->create<SeqStmt>(); newBody->loc = blockStatement->loc; newBody->stmts.add(body); newBody->stmts.add(stmt); @@ -3620,21 +3622,21 @@ namespace Slang return blockStatement; } - RefPtr<DeclStmt> Parser::parseVarDeclrStatement( + DeclStmt* Parser::parseVarDeclrStatement( Modifiers modifiers) { - RefPtr<DeclStmt>varDeclrStatement = astBuilder->create<DeclStmt>(); + DeclStmt*varDeclrStatement = astBuilder->create<DeclStmt>(); - FillPosition(varDeclrStatement.Ptr()); + FillPosition(varDeclrStatement); auto decl = ParseDeclWithModifiers(this, currentScope->containerDecl, modifiers); varDeclrStatement->decl = decl; return varDeclrStatement; } - RefPtr<IfStmt> Parser::parseIfStatement() + IfStmt* Parser::parseIfStatement() { - RefPtr<IfStmt> ifStatement = astBuilder->create<IfStmt>(); - FillPosition(ifStatement.Ptr()); + IfStmt* ifStatement = astBuilder->create<IfStmt>(); + FillPosition(ifStatement); ReadToken("if"); ReadToken(TokenType::LParent); ifStatement->predicate = ParseExpression(); @@ -3648,9 +3650,9 @@ namespace Slang return ifStatement; } - RefPtr<ForStmt> Parser::ParseForStatement() + ForStmt* Parser::ParseForStatement() { - RefPtr<ScopeDecl> scopeDecl = astBuilder->create<ScopeDecl>(); + ScopeDecl* scopeDecl = astBuilder->create<ScopeDecl>(); // 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<ForStmt> stmt; + ForStmt* stmt = nullptr; if (brokenScoping) { stmt = astBuilder->create<UnscopedForStmt>(); @@ -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<WhileStmt> Parser::ParseWhileStatement() + WhileStmt* Parser::ParseWhileStatement() { - RefPtr<WhileStmt> whileStatement = astBuilder->create<WhileStmt>(); - FillPosition(whileStatement.Ptr()); + WhileStmt* whileStatement = astBuilder->create<WhileStmt>(); + FillPosition(whileStatement); ReadToken("while"); ReadToken(TokenType::LParent); whileStatement->predicate = ParseExpression(); @@ -3721,10 +3723,10 @@ namespace Slang return whileStatement; } - RefPtr<DoWhileStmt> Parser::ParseDoWhileStatement() + DoWhileStmt* Parser::ParseDoWhileStatement() { - RefPtr<DoWhileStmt> doWhileStatement = astBuilder->create<DoWhileStmt>(); - FillPosition(doWhileStatement.Ptr()); + DoWhileStmt* doWhileStatement = astBuilder->create<DoWhileStmt>(); + FillPosition(doWhileStatement); ReadToken("do"); doWhileStatement->statement = ParseStatement(); ReadToken("while"); @@ -3735,28 +3737,28 @@ namespace Slang return doWhileStatement; } - RefPtr<BreakStmt> Parser::ParseBreakStatement() + BreakStmt* Parser::ParseBreakStatement() { - RefPtr<BreakStmt> breakStatement = astBuilder->create<BreakStmt>(); - FillPosition(breakStatement.Ptr()); + BreakStmt* breakStatement = astBuilder->create<BreakStmt>(); + FillPosition(breakStatement); ReadToken("break"); ReadToken(TokenType::Semicolon); return breakStatement; } - RefPtr<ContinueStmt> Parser::ParseContinueStatement() + ContinueStmt* Parser::ParseContinueStatement() { - RefPtr<ContinueStmt> continueStatement = astBuilder->create<ContinueStmt>(); - FillPosition(continueStatement.Ptr()); + ContinueStmt* continueStatement = astBuilder->create<ContinueStmt>(); + FillPosition(continueStatement); ReadToken("continue"); ReadToken(TokenType::Semicolon); return continueStatement; } - RefPtr<ReturnStmt> Parser::ParseReturnStatement() + ReturnStmt* Parser::ParseReturnStatement() { - RefPtr<ReturnStmt> returnStatement = astBuilder->create<ReturnStmt>(); - FillPosition(returnStatement.Ptr()); + ReturnStmt* returnStatement = astBuilder->create<ReturnStmt>(); + FillPosition(returnStatement); ReadToken("return"); if (!LookAheadToken(TokenType::Semicolon)) returnStatement->expression = ParseExpression(); @@ -3764,20 +3766,20 @@ namespace Slang return returnStatement; } - RefPtr<ExpressionStmt> Parser::ParseExpressionStatement() + ExpressionStmt* Parser::ParseExpressionStatement() { - RefPtr<ExpressionStmt> statement = astBuilder->create<ExpressionStmt>(); + ExpressionStmt* statement = astBuilder->create<ExpressionStmt>(); - FillPosition(statement.Ptr()); + FillPosition(statement); statement->expression = ParseExpression(); ReadToken(TokenType::Semicolon); return statement; } - RefPtr<ParamDecl> Parser::ParseParameter() + ParamDecl* Parser::ParseParameter() { - RefPtr<ParamDecl> parameter = astBuilder->create<ParamDecl>(); + ParamDecl* parameter = astBuilder->create<ParamDecl>(); parameter->modifiers = ParseModifiers(this); DeclaratorInfo declaratorInfo; @@ -3791,7 +3793,7 @@ namespace Slang return parameter; } - RefPtr<Expr> Parser::ParseType() + Expr* Parser::ParseType() { auto typeSpec = parseTypeSpec(this); if( typeSpec.decl ) @@ -3889,7 +3891,7 @@ namespace Slang } } - static RefPtr<Expr> parseOperator(Parser* parser) + static Expr* parseOperator(Parser* parser) { Token opToken; switch(parser->tokenReader.peekTokenType()) @@ -3913,13 +3915,13 @@ namespace Slang } - static RefPtr<Expr> createInfixExpr( + static Expr* createInfixExpr( Parser* parser, - RefPtr<Expr> left, - RefPtr<Expr> op, - RefPtr<Expr> right) + Expr* left, + Expr* op, + Expr* right) { - RefPtr<InfixExpr> expr = parser->astBuilder->create<InfixExpr>(); + InfixExpr* expr = parser->astBuilder->create<InfixExpr>(); expr->loc = op->loc; expr->functionExpr = op; expr->arguments.add(left); @@ -3927,9 +3929,9 @@ namespace Slang return expr; } - static RefPtr<Expr> parseInfixExprWithPrecedence( + static Expr* parseInfixExprWithPrecedence( Parser* parser, - RefPtr<Expr> 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<SelectExpr> select = parser->astBuilder->create<SelectExpr>(); + SelectExpr* select = parser->astBuilder->create<SelectExpr>(); select->loc = op->loc; select->functionExpr = op; @@ -3974,7 +3976,7 @@ namespace Slang if (opTokenType == TokenType::OpAssign) { - RefPtr<AssignExpr> assignExpr = parser->astBuilder->create<AssignExpr>(); + AssignExpr* assignExpr = parser->astBuilder->create<AssignExpr>(); assignExpr->loc = op->loc; assignExpr->left = expr; assignExpr->right = right; @@ -3989,7 +3991,7 @@ namespace Slang return expr; } - RefPtr<Expr> 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<SelectExpr> 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<OperatorExpr> 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<OperatorExpr> 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<Expr> maybeParseGenericApp( + static Expr* maybeParseGenericApp( Parser* parser, // TODO: need to support more general expressions here - RefPtr<Expr> base) + Expr* base) { if(peekTokenType(parser) != TokenType::OpLess) return base; return tryParseGenericApp(parser, base); } - static RefPtr<Expr> parsePrefixExpr(Parser* parser); + static Expr* parsePrefixExpr(Parser* parser); // Parse OOP `this` expression syntax - static RefPtr<RefObject> parseThisExpr(Parser* parser, void* /*userData*/) + static NodeBase* parseThisExpr(Parser* parser, void* /*userData*/) { - RefPtr<ThisExpr> expr = parser->astBuilder->create<ThisExpr>(); + ThisExpr* expr = parser->astBuilder->create<ThisExpr>(); expr->scope = parser->currentScope; return expr; } - static RefPtr<Expr> parseBoolLitExpr(Parser* parser, bool value) + static Expr* parseBoolLitExpr(Parser* parser, bool value) { - RefPtr<BoolLiteralExpr> expr = parser->astBuilder->create<BoolLiteralExpr>(); + BoolLiteralExpr* expr = parser->astBuilder->create<BoolLiteralExpr>(); expr->value = value; return expr; } - static RefPtr<RefObject> parseTrueExpr(Parser* parser, void* /*userData*/) + static NodeBase* parseTrueExpr(Parser* parser, void* /*userData*/) { return parseBoolLitExpr(parser, true); } - static RefPtr<RefObject> 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<Expr> 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<TypeCastExpr> tcexpr = parser->astBuilder->create<ExplicitCastExpr>(); - parser->FillPosition(tcexpr.Ptr()); + TypeCastExpr* tcexpr = parser->astBuilder->create<ExplicitCastExpr>(); + parser->FillPosition(tcexpr); tcexpr->functionExpr = parser->ParseType(); parser->ReadToken(TokenType::RParent); @@ -4295,10 +4297,10 @@ namespace Slang } else { - RefPtr<Expr> base = parser->ParseExpression(); + Expr* base = parser->ParseExpression(); parser->ReadToken(TokenType::RParent); - RefPtr<ParenExpr> parenExpr = parser->astBuilder->create<ParenExpr>(); + ParenExpr* parenExpr = parser->astBuilder->create<ParenExpr>(); parenExpr->loc = openParen.loc; parenExpr->base = base; return parenExpr; @@ -4308,13 +4310,13 @@ namespace Slang // An initializer list `{ expr, ... }` case TokenType::LBrace: { - RefPtr<InitializerListExpr> initExpr = parser->astBuilder->create<InitializerListExpr>(); - parser->FillPosition(initExpr.Ptr()); + InitializerListExpr* initExpr = parser->astBuilder->create<InitializerListExpr>(); + parser->FillPosition(initExpr); // Initializer list parser->ReadToken(TokenType::LBrace); - List<RefPtr<Expr>> exprs; + List<Expr*> exprs; for(;;) { @@ -4338,8 +4340,8 @@ namespace Slang case TokenType::IntegerLiteral: { - RefPtr<IntegerLiteralExpr> constExpr = parser->astBuilder->create<IntegerLiteralExpr>(); - parser->FillPosition(constExpr.Ptr()); + IntegerLiteralExpr* constExpr = parser->astBuilder->create<IntegerLiteralExpr>(); + parser->FillPosition(constExpr); auto token = parser->tokenReader.advanceToken(); constExpr->token = token; @@ -4427,8 +4429,8 @@ namespace Slang case TokenType::FloatingPointLiteral: { - RefPtr<FloatingPointLiteralExpr> constExpr = parser->astBuilder->create<FloatingPointLiteralExpr>(); - parser->FillPosition(constExpr.Ptr()); + FloatingPointLiteralExpr* constExpr = parser->astBuilder->create<FloatingPointLiteralExpr>(); + parser->FillPosition(constExpr); auto token = parser->tokenReader.advanceToken(); constExpr->token = token; @@ -4541,10 +4543,10 @@ namespace Slang case TokenType::StringLiteral: { - RefPtr<StringLiteralExpr> constExpr = parser->astBuilder->create<StringLiteralExpr>(); + StringLiteralExpr* constExpr = parser->astBuilder->create<StringLiteralExpr>(); 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<Expr> parsedExpr; + Expr* parsedExpr = nullptr; if (tryParseUsingSyntaxDecl<Expr>(parser, &parsedExpr)) { if (!parsedExpr->loc.isValid()) @@ -4583,9 +4585,9 @@ namespace Slang } // Default behavior is just to create a name expression - RefPtr<VarExpr> varExpr = parser->astBuilder->create<VarExpr>(); - varExpr->scope = parser->currentScope.Ptr(); - parser->FillPosition(varExpr.Ptr()); + VarExpr* varExpr = parser->astBuilder->create<VarExpr>(); + varExpr->scope = parser->currentScope; + parser->FillPosition(varExpr); auto nameAndLoc = expectIdentifier(parser); varExpr->name = nameAndLoc.name; @@ -4600,7 +4602,7 @@ namespace Slang } } - static RefPtr<Expr> 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<OperatorExpr> postfixExpr = parser->astBuilder->create<PostfixExpr>(); - parser->FillPosition(postfixExpr.Ptr()); + OperatorExpr* postfixExpr = parser->astBuilder->create<PostfixExpr>(); + 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> indexExpr = parser->astBuilder->create<IndexExpr>(); + IndexExpr* indexExpr = parser->astBuilder->create<IndexExpr>(); 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> invokeExpr = parser->astBuilder->create<InvokeExpr>(); + InvokeExpr* invokeExpr = parser->astBuilder->create<InvokeExpr>(); 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> staticMemberExpr = parser->astBuilder->create<StaticMemberExpr>(); + StaticMemberExpr* staticMemberExpr = parser->astBuilder->create<StaticMemberExpr>(); // 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> memberExpr = parser->astBuilder->create<MemberExpr>(); + MemberExpr* memberExpr = parser->astBuilder->create<MemberExpr>(); // 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<Expr> 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> prefixExpr = parser->astBuilder->create<PrefixExpr>(); - parser->FillPosition(prefixExpr.Ptr()); + PrefixExpr* prefixExpr = parser->astBuilder->create<PrefixExpr>(); + 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> prefixExpr = parser->astBuilder->create<PrefixExpr>(); - parser->FillPosition(prefixExpr.Ptr()); + PrefixExpr* prefixExpr = parser->astBuilder->create<PrefixExpr>(); + parser->FillPosition(prefixExpr); prefixExpr->functionExpr = parseOperator(parser); auto arg = parsePrefixExpr(parser); if (auto intLit = as<IntegerLiteralExpr>(arg)) { - RefPtr<IntegerLiteralExpr> newLiteral = parser->astBuilder->create<IntegerLiteralExpr>(*intLit); + IntegerLiteralExpr* newLiteral = parser->astBuilder->create<IntegerLiteralExpr>(*intLit); IRIntegerValue value = _foldIntegerPrefixOp(tokenType, newLiteral->value); @@ -4786,7 +4788,7 @@ namespace Slang } else if (auto floatLit = as<FloatingPointLiteralExpr>(arg)) { - RefPtr<FloatingPointLiteralExpr> newLiteral = parser->astBuilder->create<FloatingPointLiteralExpr>(*floatLit); + FloatingPointLiteralExpr* newLiteral = parser->astBuilder->create<FloatingPointLiteralExpr>(*floatLit); newLiteral->value = _foldFloatPrefixOp(tokenType, floatLit->value); return newLiteral; } @@ -4799,12 +4801,12 @@ namespace Slang } } - RefPtr<Expr> Parser::ParseLeafExpression() + Expr* Parser::ParseLeafExpression() { return parsePrefixExpr(this); } - RefPtr<Expr> parseTermFromSourceFile( + Expr* parseTermFromSourceFile( ASTBuilder* astBuilder, TokenSpan const& tokens, DiagnosticSink* sink, @@ -4840,13 +4842,13 @@ namespace Slang char const* nameText, SyntaxParseCallback callback, void* userData, - SyntaxClass<RefObject> syntaxClass) + SyntaxClass<NodeBase> syntaxClass) { Name* name = session->getNamePool()->getName(nameText); ASTBuilder* globalASTBuilder = session->getGlobalASTBuilder(); - RefPtr<SyntaxDecl> syntaxDecl = globalASTBuilder->create<SyntaxDecl>(); + SyntaxDecl* syntaxDecl = globalASTBuilder->create<SyntaxDecl>(); 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<T>()); } - static RefPtr<RefObject> parseIntrinsicOpModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseIntrinsicOpModifier(Parser* parser, void* /*userData*/) { - RefPtr<IntrinsicOpModifier> modifier = parser->astBuilder->create<IntrinsicOpModifier>(); + IntrinsicOpModifier* modifier = parser->astBuilder->create<IntrinsicOpModifier>(); // We allow a few difference forms here: // @@ -4924,7 +4926,7 @@ namespace Slang return modifier; } - static RefPtr<RefObject> parseTargetIntrinsicModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseTargetIntrinsicModifier(Parser* parser, void* /*userData*/) { auto modifier = parser->astBuilder->create<TargetIntrinsicModifier>(); @@ -4950,7 +4952,7 @@ namespace Slang return modifier; } - static RefPtr<RefObject> parseSpecializedForTargetModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseSpecializedForTargetModifier(Parser* parser, void* /*userData*/) { auto modifier = parser->astBuilder->create<SpecializedForTargetModifier>(); if (AdvanceIf(parser, TokenType::LParent)) @@ -4961,7 +4963,7 @@ namespace Slang return modifier; } - static RefPtr<RefObject> parseGLSLExtensionModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseGLSLExtensionModifier(Parser* parser, void* /*userData*/) { auto modifier = parser->astBuilder->create<RequiredGLSLExtensionModifier>(); @@ -4972,7 +4974,7 @@ namespace Slang return modifier; } - static RefPtr<RefObject> parseGLSLVersionModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseGLSLVersionModifier(Parser* parser, void* /*userData*/) { auto modifier = parser->astBuilder->create<RequiredGLSLVersionModifier>(); @@ -5013,7 +5015,7 @@ namespace Slang return SemanticVersion::parse(content, outVersion); } - static RefPtr<RefObject> 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<RefObject>(); + return nullptr; } - static RefPtr<RefObject> 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<RefObject>(); + return nullptr; } - static RefPtr<RefObject> parseLayoutModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseLayoutModifier(Parser* parser, void* /*userData*/) { ModifierListBuilder listBuilder; - RefPtr<UncheckedAttribute> numThreadsAttrib; + UncheckedAttribute* numThreadsAttrib = nullptr; listBuilder.add(parser->astBuilder->create<GLSLLayoutModifierGroupBegin>()); @@ -5121,7 +5123,7 @@ namespace Slang } else { - RefPtr<Modifier> modifier; + Modifier* modifier = nullptr; #define CASE(key, type) if (nameText == #key) { modifier = parser->astBuilder->create<type>(); } else CASE(push_constant, PushConstantAttribute) @@ -5164,9 +5166,9 @@ namespace Slang return listBuilder.getFirst(); } - static RefPtr<RefObject> parseBuiltinTypeModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseBuiltinTypeModifier(Parser* parser, void* /*userData*/) { - RefPtr<BuiltinTypeModifier> modifier = parser->astBuilder->create<BuiltinTypeModifier>(); + BuiltinTypeModifier* modifier = parser->astBuilder->create<BuiltinTypeModifier>(); 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<RefObject> parseMagicTypeModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseMagicTypeModifier(Parser* parser, void* /*userData*/) { - RefPtr<MagicTypeModifier> modifier = parser->astBuilder->create<MagicTypeModifier>(); + MagicTypeModifier* modifier = parser->astBuilder->create<MagicTypeModifier>(); 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<RefObject> parseIntrinsicTypeModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseIntrinsicTypeModifier(Parser* parser, void* /*userData*/) { - RefPtr<IntrinsicTypeModifier> modifier = parser->astBuilder->create<IntrinsicTypeModifier>(); + IntrinsicTypeModifier* modifier = parser->astBuilder->create<IntrinsicTypeModifier>(); 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<RefObject> parseImplicitConversionModifier(Parser* parser, void* /*userData*/) + static NodeBase* parseImplicitConversionModifier(Parser* parser, void* /*userData*/) { - RefPtr<ImplicitConversionModifier> modifier = parser->astBuilder->create<ImplicitConversionModifier>(); + ImplicitConversionModifier* modifier = parser->astBuilder->create<ImplicitConversionModifier>(); ConversionCost cost = kConversionCost_Default; if( AdvanceIf(parser, TokenType::LParent) ) @@ -5216,7 +5218,7 @@ namespace Slang return modifier; } - static RefPtr<RefObject> 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<AttributeTargetModifier> modifier = parser->astBuilder->create<AttributeTargetModifier>(); + AttributeTargetModifier* modifier = parser->astBuilder->create<AttributeTargetModifier>(); modifier->syntaxClass = syntaxClass; return modifier; } - RefPtr<ModuleDecl> populateBaseLanguageModule( + ModuleDecl* populateBaseLanguageModule( ASTBuilder* astBuilder, RefPtr<Scope> scope) { Session* session = astBuilder->getGlobalSession(); - RefPtr<ModuleDecl> moduleDecl = astBuilder->create<ModuleDecl>(); + ModuleDecl* moduleDecl = astBuilder->create<ModuleDecl>(); 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<Scope> const& outerScope); - RefPtr<Expr> parseTermFromSourceFile( + Expr* parseTermFromSourceFile( ASTBuilder* astBuilder, TokenSpan const& tokens, DiagnosticSink* sink, @@ -23,7 +23,7 @@ namespace Slang NamePool* namePool, SourceLanguage sourceLanguage); - RefPtr<ModuleDecl> populateBaseLanguageModule( + ModuleDecl* populateBaseLanguageModule( ASTBuilder* astBuilder, RefPtr<Scope> 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<RefObject> val; + NodeBase* val = nullptr; if (userAttr->intArgVals.TryGetValue(index, val)) { *rs = (int)as<ConstantIntVal>(val)->value; @@ -356,15 +356,15 @@ SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionTy if(auto arrayType = as<ArrayExpressionType>(type)) { - return (SlangReflectionType*) arrayType->baseType.Ptr(); + return (SlangReflectionType*) arrayType->baseType; } else if( auto parameterGroupType = as<ParameterGroupType>(type)) { - return convert(parameterGroupType->elementType.Ptr()); + return convert(parameterGroupType->elementType); } else if( auto vectorType = as<VectorExpressionType>(type)) { - return convert(vectorType->elementType.Ptr()); + return convert(vectorType->elementType); } else if( auto matrixType = as<MatrixExpressionType>(type)) { @@ -427,7 +427,7 @@ SLANG_API SlangScalarType spReflectionType_GetScalarType(SlangReflectionType* in } else if(auto vectorType = as<VectorExpressionType>(type)) { - type = vectorType->elementType.Ptr(); + type = vectorType->elementType; } if(auto basicType = as<BasicExpressionType>(type)) @@ -504,7 +504,7 @@ SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionTy while(auto arrayType = as<ArrayExpressionType>(type)) { - type = arrayType->baseType.Ptr(); + type = arrayType->baseType; } if(auto textureType = as<TextureTypeBase>(type)) @@ -540,7 +540,7 @@ SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflection while(auto arrayType = as<ArrayExpressionType>(type)) { - type = arrayType->baseType.Ptr(); + type = arrayType->baseType; } if(auto textureType = as<TextureTypeBase>(type)) @@ -604,8 +604,8 @@ SLANG_API SlangReflectionType * spReflection_FindTypeByName(SlangReflection * re try { - RefPtr<Type> 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<ArrayExpressionType>(type)) { - type = arrayType->baseType.Ptr(); + type = arrayType->baseType; } if (auto textureType = as<TextureTypeBase>(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>(type)) do { \ - return convert(as<TYPE>(type)->elementType.Ptr()); \ + return convert(as<TYPE>(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<Decl>* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* end) +Decl*const* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, Decl*const* ptr, Decl*const* end) { switch (filterStyle) { @@ -99,7 +99,7 @@ const RefPtr<Decl>* adjustFilterCursorImpl(const ReflectClassInfo& clsInfo, Memb return end; } -const RefPtr<Decl>* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* 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<Decl>* getFilterCursorByIndexImpl(const ReflectClassInfo& clsInfo, return nullptr; } -Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filterStyle, const RefPtr<Decl>* ptr, const RefPtr<Decl>* 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> 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<Type> ExtractGenericArgType(RefPtr<Val> val) + static Type* ExtractGenericArgType(Val* val) { - auto type = val.as<Type>(); - SLANG_RELEASE_ASSERT(type.Ptr()); + auto type = as<Type>(val); + SLANG_RELEASE_ASSERT(type); return type; } - static RefPtr<IntVal> ExtractGenericArgInteger(RefPtr<Val> val) + static IntVal* ExtractGenericArgInteger(Val* val) { - auto intVal = val.as<IntVal>(); - SLANG_RELEASE_ASSERT(intVal.Ptr()); + auto intVal = as<IntVal>(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<Substitutions> substsToApply; - RefPtr<Substitutions>* link = &substsToApply; + Substitutions* substsToApply = nullptr; + Substitutions** link = &substsToApply; - RefPtr<Decl> dd = declRef.getDecl(); + Decl* dd = declRef.getDecl(); for(;;) { - RefPtr<Decl> childDecl = dd; - RefPtr<Decl> parentDecl = dd->parentDecl; + Decl* childDecl = dd; + Decl* parentDecl = dd->parentDecl; if(!parentDecl) break; dd = parentDecl; - if(auto genericParentDecl = parentDecl.as<GenericDecl>()) + if(auto genericParentDecl = as<GenericDecl>(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<GenericSubstitution> foundSubst; + GenericSubstitution* foundSubst = nullptr; for(auto s = declRef.substitutions.substitutions; s; s = s->outer) { - auto genSubst = s.as<GenericSubstitution>(); + auto genSubst = as<GenericSubstitution>(s); if(!genSubst) continue; @@ -397,7 +397,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(!foundSubst) { - RefPtr<Substitutions> 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> DeclRefType::create( + DeclRefType* DeclRefType::create( ASTBuilder* astBuilder, DeclRef<Decl> 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<GenericSubstitution>()) + if(auto genericSubst = as<GenericSubstitution>(s)) { subst = genericSubst; break; @@ -561,7 +561,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt SLANG_UNEXPECTED("unhandled type"); } - RefPtr<RefObject> 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<GenericSubstitution> findInnerMostGenericSubstitution(Substitutions* subst) + GenericSubstitution* findInnerMostGenericSubstitution(Substitutions* subst) { - for(RefPtr<Substitutions> s = subst; s; s = s->outer) + for(Substitutions* s = subst; s; s = s->outer) { if(auto genericSubst = as<GenericSubstitution>(s)) return genericSubst; @@ -597,7 +597,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // DeclRefBase - RefPtr<Type> DeclRefBase::substitute(ASTBuilder* astBuilder, RefPtr<Type> 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<Type>(); + return Slang::as<Type>(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<Expr> DeclRefBase::substitute(ASTBuilder* /* astBuilder*/, RefPtr<Expr> 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<GlobalGenericParamSubstitution> findGlobalGenericSubst( - RefPtr<Substitutions> substs, + GlobalGenericParamSubstitution* findGlobalGenericSubst( + Substitutions* substs, GlobalGenericParamDecl* paramDecl) { for(auto s = substs; s; s = s->outer) { - auto gSubst = s.as<GlobalGenericParamSubstitution>(); + auto gSubst = as<GlobalGenericParamSubstitution>(s); if(!gSubst) continue; @@ -666,22 +666,22 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return nullptr; } - RefPtr<Substitutions> specializeSubstitutionsShallow( + Substitutions* specializeSubstitutionsShallow( ASTBuilder* astBuilder, - RefPtr<Substitutions> substToSpecialize, - RefPtr<Substitutions> substsToApply, - RefPtr<Substitutions> restSubst, + Substitutions* substToSpecialize, + Substitutions* substsToApply, + Substitutions* restSubst, int* ioDiff) { SLANG_ASSERT(substToSpecialize); return substToSpecialize->applySubstitutionsShallow(astBuilder, substsToApply, restSubst, ioDiff); } - RefPtr<Substitutions> specializeGlobalGenericSubstitutions( + Substitutions* specializeGlobalGenericSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr<Substitutions> substsToSpecialize, - RefPtr<Substitutions> substsToApply, + Substitutions* substsToSpecialize, + Substitutions* substsToApply, int* ioDiff, HashSet<GlobalGenericParamDecl*>& 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<GlobalGenericParamSubstitution>(); + auto specGlobalGenericSubst = as<GlobalGenericParamSubstitution>(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<Substitutions> appGlobalGenericSubsts = substsToApply; - while(appGlobalGenericSubsts && !appGlobalGenericSubsts.as<GlobalGenericParamSubstitution>()) + Substitutions* appGlobalGenericSubsts = substsToApply; + while(appGlobalGenericSubsts && !as<GlobalGenericParamSubstitution>(appGlobalGenericSubsts)) appGlobalGenericSubsts = appGlobalGenericSubsts->outer; @@ -738,11 +738,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(ioParametersFound.Count() == 0) return appGlobalGenericSubsts; - RefPtr<Substitutions> resultSubst; - RefPtr<Substitutions>* link = &resultSubst; + Substitutions* resultSubst = nullptr; + Substitutions** link = &resultSubst; for(auto appSubst = appGlobalGenericSubsts; appSubst; appSubst = appSubst->outer) { - auto appGlobalGenericSubst = appSubst.as<GlobalGenericParamSubstitution>(); + auto appGlobalGenericSubst = as<GlobalGenericParamSubstitution>(appSubst); if(!appSubst) continue; @@ -750,7 +750,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt if(ioParametersFound.Contains(appGlobalGenericSubst->paramDecl)) continue; - RefPtr<GlobalGenericParamSubstitution> newSubst = astBuilder->create<GlobalGenericParamSubstitution>(); + GlobalGenericParamSubstitution* newSubst = astBuilder->create<GlobalGenericParamSubstitution>(); 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<Substitutions> specializeGlobalGenericSubstitutions( + Substitutions* specializeGlobalGenericSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr<Substitutions> substsToSpecialize, - RefPtr<Substitutions> 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<Substitutions> specializeSubstitutions( + Substitutions* specializeSubstitutions( ASTBuilder* astBuilder, Decl* declToSpecialize, - RefPtr<Substitutions> substsToSpecialize, - RefPtr<Substitutions> 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<GenericSubstitution> firstSubst = astBuilder->create<GenericSubstitution>(); + GenericSubstitution* firstSubst = astBuilder->create<GenericSubstitution>(); 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<ThisTypeSubstitution>(); + auto appThisTypeSubst = as<ThisTypeSubstitution>(s); if(!appThisTypeSubst) continue; @@ -924,7 +924,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt substsToApply, &diff); - RefPtr<ThisTypeSubstitution> firstSubst = astBuilder->create<ThisTypeSubstitution>(); + ThisTypeSubstitution* firstSubst = astBuilder->create<ThisTypeSubstitution>(); 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<Substitutions> substToApply = substitutions.substitutions; + Substitutions* substToApply = substitutions.substitutions; if(auto interfaceDecl = as<InterfaceDecl>(decl)) { @@ -1079,14 +1079,14 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt // IntVal - IntegerLiteralValue getIntVal(RefPtr<IntVal> val) + IntegerLiteralValue getIntVal(IntVal* val) { if (auto constantVal = as<ConstantIntVal>(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<ArrayExpressionType> getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType, IntVal* elementCount) @@ -1116,7 +1116,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return arrayType; } - RefPtr<ArrayExpressionType> getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType) { @@ -1125,7 +1125,7 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return arrayType; } - RefPtr<NamedExpressionType> getNamedType( + NamedExpressionType* getNamedType( ASTBuilder* astBuilder, DeclRef<TypeDefDecl> const& declRef) { @@ -1135,11 +1135,11 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt } - RefPtr<FuncType> getFuncType( + FuncType* getFuncType( ASTBuilder* astBuilder, DeclRef<CallableDecl> const& declRef) { - RefPtr<FuncType> funcType = astBuilder->create<FuncType>(); + FuncType* funcType = astBuilder->create<FuncType>(); funcType->resultType = getResultType(astBuilder, declRef); for (auto paramDeclRef : getParameters(declRef)) @@ -1167,14 +1167,14 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return funcType; } - RefPtr<GenericDeclRefType> getGenericDeclRefType( + GenericDeclRefType* getGenericDeclRefType( ASTBuilder* astBuilder, DeclRef<GenericDecl> const& declRef) { return astBuilder->create<GenericDeclRefType>(declRef); } - RefPtr<NamespaceType> getNamespaceType( + NamespaceType* getNamespaceType( ASTBuilder* astBuilder, DeclRef<NamespaceDeclBase> const& declRef) { @@ -1183,17 +1183,17 @@ Index getFilterCountImpl(const ReflectClassInfo& clsInfo, MemberFilterStyle filt return type; } - RefPtr<SamplerStateType> getSamplerStateType( + SamplerStateType* getSamplerStateType( ASTBuilder* astBuilder) { return astBuilder->create<SamplerStateType>(); } - RefPtr<ThisTypeSubstitution> findThisTypeSubstitution( + ThisTypeSubstitution* findThisTypeSubstitution( Substitutions* substs, InterfaceDecl* interfaceDecl) { - for(RefPtr<Substitutions> s = substs; s; s = s->outer) + for(Substitutions* s = substs; s; s = s->outer) { auto thisTypeSubst = as<ThisTypeSubstitution>(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<Type> getSub(ASTBuilder* astBuilder, DeclRef<GenericTypeConstraintDecl> const& declRef) + inline Type* getSub(ASTBuilder* astBuilder, DeclRef<GenericTypeConstraintDecl> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->sub.Ptr()); } - inline RefPtr<Type> getSup(ASTBuilder* astBuilder, DeclRef<TypeConstraintDecl> const& declRef) + inline Type* getSup(ASTBuilder* astBuilder, DeclRef<TypeConstraintDecl> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->getSup().type); } @@ -95,27 +95,27 @@ namespace Slang /// Name* getReflectionName(VarDeclBase* varDecl); - inline RefPtr<Type> getType(ASTBuilder* astBuilder, DeclRef<VarDeclBase> const& declRef) + inline Type* getType(ASTBuilder* astBuilder, DeclRef<VarDeclBase> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->type.Ptr()); } - inline RefPtr<Expr> getInitExpr(ASTBuilder* astBuilder, DeclRef<VarDeclBase> const& declRef) + inline Expr* getInitExpr(ASTBuilder* astBuilder, DeclRef<VarDeclBase> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->initExpr); } - inline RefPtr<Type> getType(ASTBuilder* astBuilder, DeclRef<EnumCaseDecl> const& declRef) + inline Type* getType(ASTBuilder* astBuilder, DeclRef<EnumCaseDecl> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->type.Ptr()); } - inline RefPtr<Expr> getTagExpr(ASTBuilder* astBuilder, DeclRef<EnumCaseDecl> const& declRef) + inline Expr* getTagExpr(ASTBuilder* astBuilder, DeclRef<EnumCaseDecl> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->tagExpr); } - inline RefPtr<Type> getTargetType(ASTBuilder* astBuilder, DeclRef<ExtensionDecl> const& declRef) + inline Type* getTargetType(ASTBuilder* astBuilder, DeclRef<ExtensionDecl> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->targetType.Ptr()); } @@ -127,19 +127,19 @@ namespace Slang - inline RefPtr<Type> getBaseType(ASTBuilder* astBuilder, DeclRef<InheritanceDecl> const& declRef) + inline Type* getBaseType(ASTBuilder* astBuilder, DeclRef<InheritanceDecl> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->base.type); } - inline RefPtr<Type> getType(ASTBuilder* astBuilder, DeclRef<TypeDefDecl> const& declRef) + inline Type* getType(ASTBuilder* astBuilder, DeclRef<TypeDefDecl> const& declRef) { return declRef.substitute(astBuilder, declRef.getDecl()->type.Ptr()); } - inline RefPtr<Type> getResultType(ASTBuilder* astBuilder, DeclRef<CallableDecl> const& declRef) + inline Type* getResultType(ASTBuilder* astBuilder, DeclRef<CallableDecl> const& declRef) { - return declRef.substitute(astBuilder, declRef.getDecl()->returnType.type.Ptr()); + return declRef.substitute(astBuilder, declRef.getDecl()->returnType.type); } inline FilteredMemberRefList<ParamDecl> getParameters(DeclRef<CallableDecl> const& declRef) @@ -151,38 +151,38 @@ namespace Slang { // TODO: Should really return a `DeclRef<Decl>` for the inner // declaration, and not just a raw pointer - return declRef.getDecl()->inner.Ptr(); + return declRef.getDecl()->inner; } // - RefPtr<ArrayExpressionType> getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType, IntVal* elementCount); - RefPtr<ArrayExpressionType> getArrayType( + ArrayExpressionType* getArrayType( ASTBuilder* astBuilder, Type* elementType); - RefPtr<NamedExpressionType> getNamedType( + NamedExpressionType* getNamedType( ASTBuilder* astBuilder, DeclRef<TypeDefDecl> const& declRef); - RefPtr<FuncType> getFuncType( + FuncType* getFuncType( ASTBuilder* astBuilder, DeclRef<CallableDecl> const& declRef); - RefPtr<GenericDeclRefType> getGenericDeclRefType( + GenericDeclRefType* getGenericDeclRefType( ASTBuilder* astBuilder, DeclRef<GenericDecl> const& declRef); - RefPtr<NamespaceType> getNamespaceType( + NamespaceType* getNamespaceType( ASTBuilder* astBuilder, DeclRef<NamespaceDeclBase> const& declRef); - RefPtr<SamplerStateType> getSamplerStateType( + SamplerStateType* getSamplerStateType( ASTBuilder* astBuilder); @@ -192,7 +192,7 @@ namespace Slang template<typename T> void FilteredModifierList<T>::Iterator::operator++() { - current = adjust(current->next.Ptr()); + current = adjust(current->next); } // template<typename T> @@ -206,13 +206,13 @@ namespace Slang { return m; } - m = m->next.Ptr(); + m = m->next; } } // - RefPtr<ThisTypeSubstitution> findThisTypeSubstitution( + ThisTypeSubstitution* findThisTypeSubstitution( Substitutions* substs, InterfaceDecl* interfaceDecl); @@ -235,12 +235,12 @@ namespace Slang ASTBuilder* astBuilder, DeclRef<Decl> declRef); - RefPtr<GenericSubstitution> createDefaultSubstitutionsForGeneric( + GenericSubstitution* createDefaultSubstitutionsForGeneric( ASTBuilder* astBuilder, GenericDecl* genericDecl, - RefPtr<Substitutions> outerSubst); + Substitutions* outerSubst); - RefPtr<GenericSubstitution> 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<IntVal> 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* type, LayoutRulesImpl* rules) { RefPtr<TypeLayout> typeLayout = new TypeLayout(); @@ -1381,7 +1381,7 @@ static TypeLayoutResult createSimpleTypeLayout( } static SimpleLayoutInfo getParameterGroupLayoutInfo( - RefPtr<ParameterGroupType> type, + ParameterGroupType* type, LayoutRulesImpl* rules) { if( as<ConstantBufferType>(type) ) @@ -1861,7 +1861,7 @@ static void _addUnmaskedResourceUsage( static RefPtr<TypeLayout> _createParameterGroupTypeLayout( TypeLayoutContext const& context, - RefPtr<ParameterGroupType> parameterGroupType, + ParameterGroupType* parameterGroupType, RefPtr<TypeLayout> rawElementTypeLayout) { // We are being asked to create a layout for a parameter group, @@ -2325,8 +2325,8 @@ RefPtr<TypeLayout> createConstantBufferTypeLayoutIfNeeded( static RefPtr<TypeLayout> _createParameterGroupTypeLayout( TypeLayoutContext const& context, - RefPtr<ParameterGroupType> parameterGroupType, - RefPtr<Type> elementType, + ParameterGroupType* parameterGroupType, + Type* elementType, LayoutRulesImpl* elementTypeRules) { // We will first compute a layout for the element type of @@ -2346,7 +2346,7 @@ static RefPtr<TypeLayout> _createParameterGroupTypeLayout( } LayoutRulesImpl* getParameterBufferElementTypeLayoutRules( - RefPtr<ParameterGroupType> parameterGroupType, + ParameterGroupType* parameterGroupType, LayoutRulesImpl* rules) { if( as<ConstantBufferType>(parameterGroupType) ) @@ -2376,13 +2376,13 @@ LayoutRulesImpl* getParameterBufferElementTypeLayoutRules( else { SLANG_UNEXPECTED("uhandled parameter block type"); - return nullptr; + //return nullptr; } } RefPtr<TypeLayout> createParameterGroupTypeLayout( TypeLayoutContext const& context, - RefPtr<ParameterGroupType> parameterGroupType) + ParameterGroupType* parameterGroupType) { auto parameterGroupRules = context.rules; @@ -2405,7 +2405,7 @@ RefPtr<StructuredBufferTypeLayout> createStructuredBufferTypeLayout( TypeLayoutContext const& context, ShaderParameterKind kind, - RefPtr<Type> structuredBufferType, + Type* structuredBufferType, RefPtr<TypeLayout> elementTypeLayout) { auto rules = context.rules; @@ -2437,8 +2437,8 @@ RefPtr<StructuredBufferTypeLayout> createStructuredBufferTypeLayout( TypeLayoutContext const& context, ShaderParameterKind kind, - RefPtr<Type> structuredBufferType, - RefPtr<Type> 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<Type> findGlobalGenericSpecializationArg( +Type* findGlobalGenericSpecializationArg( TypeLayoutContext const& context, GlobalGenericParamDecl* decl) { - RefPtr<Val> arg; + Val* arg = nullptr; context.programLayout->globalGenericArgs.TryGetValue(decl, arg); - return arg.as<Type>(); + return as<Type>(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<Type> concreteType = specializationArg.val.as<Type>(); + Type* concreteType = as<Type>(specializationArg.val); SLANG_ASSERT(concreteType); RefPtr<TypeLayout> concreteTypeLayout = createTypeLayout(context, concreteType); @@ -3944,7 +3944,7 @@ RefPtr<TypeLayout> TypeLayout::unwrapArray() } -RefPtr<GlobalGenericParamDecl> GenericParamTypeLayout::getGlobalGenericParamDecl() +GlobalGenericParamDecl* GenericParamTypeLayout::getGlobalGenericParamDecl() { auto declRefType = as<DeclRefType>(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; - 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<GlobalGenericParamDecl> 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* 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* 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<GlobalGenericParamDecl*, RefPtr<Val>> globalGenericArgs; + Dictionary<GlobalGenericParamDecl*, Val*> globalGenericArgs; /// Layouts for all tagged union types required by this program /// @@ -1118,7 +1118,7 @@ RefPtr<TypeLayout> createTypeLayout( /// Create a layout for a parameter-group type (a `ConstantBuffer` or `ParameterBlock`). RefPtr<TypeLayout> createParameterGroupTypeLayout( TypeLayoutContext const& context, - RefPtr<ParameterGroupType> parameterGroupType); + ParameterGroupType* parameterGroupType); /// Create a wrapper constant buffer type layout, if needed. /// @@ -1140,8 +1140,8 @@ RefPtr<StructuredBufferTypeLayout> createStructuredBufferTypeLayout( TypeLayoutContext const& context, ShaderParameterKind kind, - RefPtr<Type> structuredBufferType, - RefPtr<Type> elementType); + Type* structuredBufferType, + Type* elementType); /// Create a type layout for an unspecialized `globalGenericParamDecl`. RefPtr<TypeLayout> createTypeLayoutForGlobalGenericTypeParam( @@ -1150,7 +1150,7 @@ RefPtr<TypeLayout> createTypeLayoutForGlobalGenericTypeParam( GlobalGenericParamDecl* globalGenericParamDecl); /// Find the concrete type (if any) that was plugged in for the global generic type parameter `decl`. -RefPtr<Type> 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 <typeinfo> @@ -123,10 +125,11 @@ void Session::init() m_sharedASTBuilder->init(this); // Use to create a ASTBuilder - RefPtr<ASTBuilder> builtinAstBuilder(new ASTBuilder(m_sharedASTBuilder)); + RefPtr<ASTBuilder> 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> astBuilder(new ASTBuilder(m_sharedASTBuilder)); + RefPtr<ASTBuilder> astBuilder(new ASTBuilder(m_sharedASTBuilder, "Session::astBuilder")); RefPtr<Linkage> 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<Expr> Linkage::parseTermString(String typeStr, RefPtr<Scope> scope) +Expr* Linkage::parseTermString(String typeStr, RefPtr<Scope> 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<Expr> Linkage::parseTermString(String typeStr, RefPtr<Scope> scope) tokens, &sink, scope, getNamePool(), SourceLanguage::Slang); } -RefPtr<Type> 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* type = nullptr; if(m_types.TryGetValue(typeStr, type)) return type; @@ -891,7 +914,7 @@ Type* ComponentType::getTypeFromString( RefPtr<Scope> scope = _createScopeForLegacyLookup(); auto linkage = getLinkage(); - RefPtr<Expr> 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<ModuleDecl> translationUnitSyntax = astBuilder->create<ModuleDecl>(); + //ASTBuilder* astBuilder = linkage->getASTBuilder(); + + ModuleDecl* translationUnitSyntax = astBuilder->create<ModuleDecl>(); + 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> astBuilder(new ASTBuilder(session->m_sharedASTBuilder)); + RefPtr<ASTBuilder> 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; } |
