From 643aaa13d2c6e0c4994437aa9fba6716787608ce Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 7 Jul 2023 14:26:37 -0700 Subject: Make DeclRefBase a Val, and DeclRef a helper class. (#2967) * Make DeclRefBase a Val, and DeclRef a helper class. * Fixes. * Workaround gcc parser issue. * Revert NodeOperand change. * Fix. * Fix clang incomplete class complains. * Fix code review. * Small cleanups and improvements. --------- Co-authored-by: Yong He --- source/slang/slang-ast-builder.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'source/slang/slang-ast-builder.cpp') diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp index d914b4568..33bd23f43 100644 --- a/source/slang/slang-ast-builder.cpp +++ b/source/slang/slang-ast-builder.cpp @@ -167,7 +167,7 @@ SharedASTBuilder::~SharedASTBuilder() void SharedASTBuilder::registerBuiltinDecl(Decl* decl, BuiltinTypeModifier* modifier) { - auto type = DeclRefType::create(m_astBuilder, DeclRef(decl)); + auto type = DeclRefType::create(m_astBuilder, makeDeclRef(decl)); m_builtinTypes[Index(modifier->tag)] = type; } @@ -294,7 +294,7 @@ ArrayExpressionType* ASTBuilder::getArrayType(Type* elementType, IntVal* element elementCount = getIntVal(getIntType(), kUnsizedArrayMagicLength); auto result = getOrCreate(elementType, elementCount); - if (!result->declRef.decl) + if (!result->declRef.getDecl()) { auto arrayGenericDecl = as(m_sharedASTBuilder->findMagicDecl("ArrayType")); auto arrayTypeDecl = arrayGenericDecl->inner; @@ -309,7 +309,7 @@ VectorExpressionType* ASTBuilder::getVectorType( IntVal* elementCount) { auto result = getOrCreate(elementType, elementCount); - if (!result->declRef.decl) + if (!result->declRef.getDecl()) { auto vectorGenericDecl = as(m_sharedASTBuilder->findMagicDecl("Vector")); auto vectorTypeDecl = vectorGenericDecl->inner; @@ -340,8 +340,7 @@ DifferentialPairType* ASTBuilder::getDifferentialPairType( DeclRef ASTBuilder::getDifferentiableInterface() { - DeclRef declRef; - declRef.decl = dynamicCast(m_sharedASTBuilder->findMagicDecl("DifferentiableType")); + DeclRef declRef = DeclRef(getBuiltinDeclRef("DifferentiableType", nullptr)); return declRef; } @@ -381,22 +380,22 @@ MeshOutputType* ASTBuilder::getMeshOutputTypeFromModifier( DeclRef ASTBuilder::getBuiltinDeclRef(const char* builtinMagicTypeName, Val* genericArg) { - DeclRef declRef; - declRef.decl = m_sharedASTBuilder->findMagicDecl(builtinMagicTypeName); - if (auto genericDecl = as(declRef.decl)) + auto decl = m_sharedASTBuilder->findMagicDecl(builtinMagicTypeName); + if (auto genericDecl = as(decl)) { + decl = genericDecl->inner; + Substitutions* subst = nullptr; if (genericArg) { - auto substitutions = getOrCreate(genericDecl, genericArg); - declRef.substitutions = substitutions; + subst = getOrCreate(genericDecl, genericArg); } - declRef.decl = genericDecl->inner; + return getSpecializedDeclRef(decl, subst); } else { SLANG_ASSERT(!genericArg); } - return declRef; + return makeDeclRef(decl); } Type* ASTBuilder::getAndType(Type* left, Type* right) @@ -458,8 +457,7 @@ bool ASTBuilder::NodeDesc::operator==(NodeDesc const& that) const // via a `NodeDesc` *should* all be going through the // deduplication path anyway, as should their operands. // - if (operands[i].values.nodeOperand[0] != that.operands[i].values.nodeOperand[0]) return false; - if (operands[i].values.nodeOperand[1] != that.operands[i].values.nodeOperand[1]) return false; + if (operands[i].values.nodeOperand != that.operands[i].values.nodeOperand) return false; } return true; } @@ -474,8 +472,7 @@ HashCode ASTBuilder::NodeDesc::getHashCode() const // to match the semantics implemented for `==` on // `NodeDesc`. // - hasher.hashValue(operands[i].values.nodeOperand[0]); - hasher.hashValue(operands[i].values.nodeOperand[1]); + hasher.hashValue(operands[i].values.nodeOperand); } return hasher.getResult(); } -- cgit v1.2.3