From c2d31347ea06c768045e7c503ef0188e0e5356de Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 28 May 2020 14:01:51 -0400 Subject: WIP: ASTBuilder (#1358) * Compiles. * Small tidy up around session/ASTBuilder. * Tests are now passing. * Fix Visual Studio project. * Fix using new X to use builder when protectedness of Ctor is not enough. Substitute->substitute * Add some missing ast nodes created outside of ASTBuilder. * Compile time check that ASTBuilder is making an AST type. * Moced findClasInfo and findSyntaxClass (essentially the same thing) to SharedASTBuilder from Session. --- source/slang/slang-check-modifier.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'source/slang/slang-check-modifier.cpp') diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp index b8b3846dc..42a9735af 100644 --- a/source/slang/slang-check-modifier.cpp +++ b/source/slang/slang-check-modifier.cpp @@ -80,15 +80,13 @@ namespace Slang AttributeDecl* SemanticsVisitor::lookUpAttributeDecl(Name* attributeName, Scope* scope) { - auto session = getSession(); - // We start by looking for an existing attribute matching // the name `attributeName`. // { // Look up the name and see what attributes we find. // - auto lookupResult = lookUp(session, this, attributeName, scope, LookupMask::Attribute); + auto lookupResult = lookUp(m_astBuilder, this, attributeName, scope, LookupMask::Attribute); // If the result was overloaded, then that means there // are multiple attributes matching the name, and we @@ -118,7 +116,7 @@ namespace Slang // If the attribute was `[Something(...)]` then we will // look for a `struct` named `SomethingAttribute`. // - LookupResult lookupResult = lookUp(session, this, session->getNameObj(attributeName->text + "Attribute"), scope, LookupMask::type); + LookupResult lookupResult = lookUp(m_astBuilder, this, m_astBuilder->getGlobalSession()->getNameObj(attributeName->text + "Attribute"), scope, LookupMask::type); // // If we didn't find a matching type name, then we give up. // @@ -140,12 +138,12 @@ namespace Slang // We will now synthesize a new `AttributeDecl` to mirror // what was declared on the `struct` type. // - RefPtr attrDecl = new AttributeDecl(); + RefPtr attrDecl = m_astBuilder->create(); attrDecl->nameAndLoc.name = attributeName; attrDecl->nameAndLoc.loc = structDecl->nameAndLoc.loc; attrDecl->loc = structDecl->loc; - RefPtr targetModifier = new AttributeTargetModifier(); + RefPtr targetModifier = m_astBuilder->create(); targetModifier->syntaxClass = attrUsageAttr->targetSyntaxClass; targetModifier->loc = attrUsageAttr->loc; addModifier(attrDecl, targetModifier); @@ -155,8 +153,8 @@ namespace Slang // // User-defined attributes create instances of // `UserDefinedAttribute`. - // - attrDecl->syntaxClass = session->findSyntaxClass(session->getNameObj("UserDefinedAttribute")); + // + attrDecl->syntaxClass = m_astBuilder->findSyntaxClass(UnownedStringSlice::fromLiteral("UserDefinedAttribute")); // The fields of the user-defined `struct` type become // the parameters of the new attribute. @@ -169,7 +167,7 @@ namespace Slang { ensureDecl(varMember, DeclCheckState::CanUseTypeOfValueDecl); - RefPtr paramDecl = new ParamDecl(); + RefPtr paramDecl = m_astBuilder->create(); paramDecl->nameAndLoc = member->nameAndLoc; paramDecl->type = varMember->type; paramDecl->loc = member->loc; @@ -236,17 +234,17 @@ namespace Slang { if (typeFlags == (int)UserDefinedAttributeTargets::Struct) { - cls = getSession()->findSyntaxClass(getSession()->getNameObj("StructDecl")); + cls = m_astBuilder->findSyntaxClass(UnownedStringSlice::fromLiteral("StructDecl")); return true; } if (typeFlags == (int)UserDefinedAttributeTargets::Var) { - cls = getSession()->findSyntaxClass(getSession()->getNameObj("VarDecl")); + cls = m_astBuilder->findSyntaxClass(UnownedStringSlice::fromLiteral("VarDecl")); return true; } if (typeFlags == (int)UserDefinedAttributeTargets::Function) { - cls = getSession()->findSyntaxClass(getSession()->getNameObj("FuncDecl")); + cls = m_astBuilder->findSyntaxClass(UnownedStringSlice::fromLiteral("FuncDecl")); return true; } return false; -- cgit v1.2.3