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-mangle.cpp | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'source/slang/slang-mangle.cpp') diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp index 0ecc12b45..5e141228d 100644 --- a/source/slang/slang-mangle.cpp +++ b/source/slang/slang-mangle.cpp @@ -7,6 +7,11 @@ namespace Slang { struct ManglingContext { + ManglingContext(ASTBuilder* inAstBuilder): + astBuilder(inAstBuilder) + { + } + ASTBuilder* astBuilder; StringBuilder sb; }; @@ -130,7 +135,7 @@ namespace Slang } else if( auto namedType = dynamicCast(type) ) { - emitType(context, GetType(namedType->declRef)); + emitType(context, GetType(context->astBuilder, namedType->declRef)); } else if( auto declRefType = dynamicCast(type) ) { @@ -246,7 +251,7 @@ namespace Slang if(auto inheritanceDeclRef = declRef.as()) { emit(context, "I"); - emitType(context, GetSup(inheritanceDeclRef)); + emitType(context, GetSup(context->astBuilder, inheritanceDeclRef)); return; } @@ -259,7 +264,7 @@ namespace Slang // that is in the same module as the type it extends should // be treated as equivalent to the type itself. emit(context, "X"); - emitType(context, GetTargetType(extensionDeclRef)); + emitType(context, GetTargetType(context->astBuilder, extensionDeclRef)); return; } @@ -334,7 +339,7 @@ namespace Slang else if(auto genericValueParamDecl = mm.as()) { emitRaw(context, "v"); - emitType(context, GetType(genericValueParamDecl)); + emitType(context, GetType(context->astBuilder, genericValueParamDecl)); } else if(mm.as()) { @@ -366,14 +371,14 @@ namespace Slang for(auto paramDeclRef : parameters) { - emitType(context, GetType(paramDeclRef)); + emitType(context, GetType(context->astBuilder, paramDeclRef)); } // Don't print result type for an initializer/constructor, // since it is implicit in the qualified name. if (!callableDeclRef.is()) { - emitType(context, GetResultType(callableDeclRef)); + emitType(context, GetResultType(context->astBuilder, callableDeclRef)); } } } @@ -419,29 +424,30 @@ namespace Slang emitQualifiedName(context, declRef); } - String getMangledName(DeclRef const& declRef) + String getMangledName(ASTBuilder* astBuilder, DeclRef const& declRef) { - ManglingContext context; + ManglingContext context(astBuilder); mangleName(&context, declRef); return context.sb.ProduceString(); } - String getMangledName(DeclRefBase const & declRef) + String getMangledName(ASTBuilder* astBuilder, DeclRefBase const & declRef) { - return getMangledName( + return getMangledName(astBuilder, DeclRef(declRef.decl, declRef.substitutions)); } - String getMangledName(Decl* decl) + String getMangledName(ASTBuilder* astBuilder, Decl* decl) { - return getMangledName(makeDeclRef(decl)); + return getMangledName(astBuilder, makeDeclRef(decl)); } String getMangledNameForConformanceWitness( + ASTBuilder* astBuilder, DeclRef sub, DeclRef sup) { - ManglingContext context; + ManglingContext context(astBuilder); emitRaw(&context, "_SW"); emitQualifiedName(&context, sub); emitQualifiedName(&context, sup); @@ -449,6 +455,7 @@ namespace Slang } String getMangledNameForConformanceWitness( + ASTBuilder* astBuilder, DeclRef sub, Type* sup) { @@ -457,7 +464,7 @@ namespace Slang // // {Conforms(sub,sup)} => _SW{sub}{sup} // - ManglingContext context; + ManglingContext context(astBuilder); emitRaw(&context, "_SW"); emitQualifiedName(&context, sub); emitType(&context, sup); @@ -465,6 +472,7 @@ namespace Slang } String getMangledNameForConformanceWitness( + ASTBuilder* astBuilder, Type* sub, Type* sup) { @@ -473,16 +481,16 @@ namespace Slang // // {Conforms(sub,sup)} => _SW{sub}{sup} // - ManglingContext context; + ManglingContext context(astBuilder); emitRaw(&context, "_SW"); emitType(&context, sub); emitType(&context, sup); return context.sb.ProduceString(); } - String getMangledTypeName(Type* type) + String getMangledTypeName(ASTBuilder* astBuilder, Type* type) { - ManglingContext context; + ManglingContext context(astBuilder); emitType(&context, type); return context.sb.ProduceString(); } -- cgit v1.2.3