diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-05-28 14:01:51 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-28 14:01:51 -0400 |
| commit | c2d31347ea06c768045e7c503ef0188e0e5356de (patch) | |
| tree | 1a4ee67aafca0a709ae691104023431bb6829825 /source/slang/slang-check-type.cpp | |
| parent | e5d0f3360f44a4cdd2390e7817db17bb3cc0dd04 (diff) | |
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.
Diffstat (limited to 'source/slang/slang-check-type.cpp')
| -rw-r--r-- | source/slang/slang-check-type.cpp | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/source/slang/slang-check-type.cpp b/source/slang/slang-check-type.cpp index e6c924be8..db5d555cd 100644 --- a/source/slang/slang-check-type.cpp +++ b/source/slang/slang-check-type.cpp @@ -37,7 +37,7 @@ namespace Slang { return typeType->type; } - return getSession()->getErrorType(); + return m_astBuilder->getErrorType(); } RefPtr<Type> SemanticsVisitor::TranslateTypeNode(const RefPtr<Expr> & node) @@ -97,7 +97,7 @@ namespace Slang { return typeType->type; } - return getSession()->getErrorType(); + return m_astBuilder->getErrorType(); } RefPtr<Type> SemanticsVisitor::ExtractGenericArgType(RefPtr<Expr> exp) @@ -114,7 +114,7 @@ namespace Slang // constant expression in context, then we will instead construct // a dummy "error" value to represent the result. // - val = new ErrorIntVal(); + val = m_astBuilder->create<ErrorIntVal>(); return val; } @@ -149,7 +149,7 @@ namespace Slang DeclRef<GenericDecl> genericDeclRef, List<RefPtr<Expr>> const& args) { - RefPtr<GenericSubstitution> subst = new GenericSubstitution(); + RefPtr<GenericSubstitution> subst = m_astBuilder->create<GenericSubstitution>(); subst->genericDecl = genericDeclRef.getDecl(); subst->outer = genericDeclRef.substitutions.substitutions; @@ -162,9 +162,7 @@ namespace Slang innerDeclRef.decl = GetInner(genericDeclRef); innerDeclRef.substitutions = SubstitutionSet(subst); - return DeclRefType::Create( - getSession(), - innerDeclRef); + return DeclRefType::create(m_astBuilder, innerDeclRef); } bool SemanticsVisitor::CoerceToProperTypeImpl( @@ -216,7 +214,7 @@ namespace Slang if (diagSink) { diagSink->diagnose(typeExp.exp.Ptr(), Diagnostics::genericTypeNeedsArgs, typeExp); - *outProperType = getSession()->getErrorType(); + *outProperType = m_astBuilder->getErrorType(); } return false; } @@ -232,7 +230,7 @@ namespace Slang if (diagSink) { diagSink->diagnose(typeExp.exp.Ptr(), Diagnostics::unimplemented, "can't fill in default for generic type parameter"); - *outProperType = getSession()->getErrorType(); + *outProperType = m_astBuilder->getErrorType(); } return false; } @@ -293,7 +291,7 @@ namespace Slang { // TODO(tfoley): pick the right diagnostic message getSink()->diagnose(result.exp.Ptr(), Diagnostics::invalidTypeVoid); - result.type = getSession()->getErrorType(); + result.type = m_astBuilder->getErrorType(); return result; } } @@ -334,21 +332,18 @@ namespace Slang RefPtr<Type> elementType, RefPtr<IntVal> elementCount) { - auto session = getSession(); - auto vectorGenericDecl = findMagicDecl( - session, "Vector").as<GenericDecl>(); + auto vectorGenericDecl = m_astBuilder->getSharedASTBuilder()->findMagicDecl("Vector").as<GenericDecl>(); + auto vectorTypeDecl = vectorGenericDecl->inner; - auto substitutions = new GenericSubstitution(); + auto substitutions = m_astBuilder->create<GenericSubstitution>(); substitutions->genericDecl = vectorGenericDecl.Ptr(); substitutions->args.add(elementType); substitutions->args.add(elementCount); auto declRef = DeclRef<Decl>(vectorTypeDecl.Ptr(), substitutions); - return DeclRefType::Create( - session, - declRef).as<VectorExpressionType>(); + return DeclRefType::create(m_astBuilder, declRef).as<VectorExpressionType>(); } RefPtr<Expr> SemanticsExprVisitor::visitSharedTypeExpr(SharedTypeExpr* expr) @@ -366,8 +361,8 @@ namespace Slang // 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 = new TaggedUnionType(); - expr->type = QualType(getTypeType(type)); + RefPtr<TaggedUnionType> type = m_astBuilder->create<TaggedUnionType>(); + expr->type = QualType(m_astBuilder->getTypeType(type)); for( auto& caseTypeExpr : expr->caseTypes ) { |
