feat: 语法树的访问者和类型检测访问者 (#56)

Reviewed-on: PostGuard/Canon#56
This commit is contained in:
2024-04-26 10:18:49 +08:00
parent b20c3234c5
commit 17dbcccb59
63 changed files with 2757 additions and 704 deletions

View File

@@ -1,6 +1,6 @@
using Canon.Core.Abstractions;
using Canon.Core.CodeGenerators;
using Canon.Core.LexicalParser;
using Canon.Core.SemanticParser;
using Canon.Core.SyntaxNodes;
using Canon.Server.DataTransferObjects;
using Canon.Server.Entities;
@@ -12,6 +12,7 @@ namespace Canon.Server.Services;
public class CompilerService(
ILexer lexer,
IGrammarParser grammarParser,
SyntaxTreeTraveller traveller,
CompileDbContext dbContext,
GridFsService gridFsService,
SyntaxTreePresentationService syntaxTreePresentationService,
@@ -38,14 +39,14 @@ public class CompilerService(
await using Stream imageStream = syntaxTreePresentationService.Present(root);
string filename = await gridFsService.UploadStream(imageStream, "image/png");
CCodeBuilder builder = new();
root.GenerateCCode(builder);
CCodeGenerateVisitor visitor = new();
traveller.Travel(root, visitor);
CompileResult result = new()
{
SourceCode = sourceCode.Code,
CompileId = Guid.NewGuid().ToString(),
CompiledCode = builder.Build(),
CompiledCode = visitor.Builder.Build(),
SytaxTreeImageFilename = filename,
CompileTime = DateTime.Now
};