summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ast-builder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ast-builder.cpp')
-rw-r--r--source/slang/slang-ast-builder.cpp29
1 files changed, 13 insertions, 16 deletions
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>(decl));
+ auto type = DeclRefType::create(m_astBuilder, makeDeclRef<Decl>(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<ArrayExpressionType>(elementType, elementCount);
- if (!result->declRef.decl)
+ if (!result->declRef.getDecl())
{
auto arrayGenericDecl = as<GenericDecl>(m_sharedASTBuilder->findMagicDecl("ArrayType"));
auto arrayTypeDecl = arrayGenericDecl->inner;
@@ -309,7 +309,7 @@ VectorExpressionType* ASTBuilder::getVectorType(
IntVal* elementCount)
{
auto result = getOrCreate<VectorExpressionType>(elementType, elementCount);
- if (!result->declRef.decl)
+ if (!result->declRef.getDecl())
{
auto vectorGenericDecl = as<GenericDecl>(m_sharedASTBuilder->findMagicDecl("Vector"));
auto vectorTypeDecl = vectorGenericDecl->inner;
@@ -340,8 +340,7 @@ DifferentialPairType* ASTBuilder::getDifferentialPairType(
DeclRef<InterfaceDecl> ASTBuilder::getDifferentiableInterface()
{
- DeclRef<InterfaceDecl> declRef;
- declRef.decl = dynamicCast<InterfaceDecl>(m_sharedASTBuilder->findMagicDecl("DifferentiableType"));
+ DeclRef<InterfaceDecl> declRef = DeclRef<InterfaceDecl>(getBuiltinDeclRef("DifferentiableType", nullptr));
return declRef;
}
@@ -381,22 +380,22 @@ MeshOutputType* ASTBuilder::getMeshOutputTypeFromModifier(
DeclRef<Decl> ASTBuilder::getBuiltinDeclRef(const char* builtinMagicTypeName, Val* genericArg)
{
- DeclRef<Decl> declRef;
- declRef.decl = m_sharedASTBuilder->findMagicDecl(builtinMagicTypeName);
- if (auto genericDecl = as<GenericDecl>(declRef.decl))
+ auto decl = m_sharedASTBuilder->findMagicDecl(builtinMagicTypeName);
+ if (auto genericDecl = as<GenericDecl>(decl))
{
+ decl = genericDecl->inner;
+ Substitutions* subst = nullptr;
if (genericArg)
{
- auto substitutions = getOrCreate<GenericSubstitution>(genericDecl, genericArg);
- declRef.substitutions = substitutions;
+ subst = getOrCreate<GenericSubstitution>(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();
}