Skip to content

Commit 9e9b151

Browse files
committed
use file decl for findclassinfo
1 parent 27a5805 commit 9e9b151

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

kscr-compiler/CompilerRuntime.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void CompileSource(string source, string? basePackage = null)
4343
{
4444
var decl = MakeFileDecl(src);
4545
ctx = new CompilerContext
46-
{ Parent = ctx, Class = FindClassInfo(src), Imports = FindClassImports(decl.imports()) };
46+
{ Parent = ctx, Class = FindClassInfo(decl), Imports = FindClassImports(decl.imports()) };
4747
node = new FileNode(this, ctx, new PackageNode(this, ctx, src.DirectoryName!, pkg), src).CreateClassNode();
4848
var mc = (node as MemberNode)!.ReadMembers();
4949
Log<CompilerRuntime>.At(LogLevel.Debug, $"Loaded {mc} members");
@@ -90,9 +90,8 @@ public List<string> FindClassImports(KScrParser.ImportsContext ctx)
9090
return yields;
9191
}
9292

93-
public ClassInfo FindClassInfo(FileInfo file)
93+
public ClassInfo FindClassInfo(KScrParser.FileContext fileDecl)
9494
{
95-
var fileDecl = MakeFileDecl(new AntlrFileStream(file.FullName), file.FullName);
9695
var pkg = Package.RootPackage.GetOrCreatePackage(fileDecl.packageDecl().id().GetText());
9796
return new ClassInfoVisitor(this, new CompilerContext { Package = pkg }).Visit(fileDecl.classDecl(0));
9897
}

kscr-compiler/NodeCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ public FileNode(CompilerRuntime vm, CompilerContext ctx, PackageNode pkg, FileIn
170170
{
171171
Pkg = pkg;
172172
File = file;
173-
ClassInfo = vm.FindClassInfo(file);
174173
Decl = vm.MakeFileDecl(File);
174+
ClassInfo = vm.FindClassInfo(Decl);
175175
Imports = vm.FindClassImports(Decl.imports());
176176
Cls = Pkg.Package.GetOrCreateClass(ClassInfo.Name, vm, ClassInfo.Modifier, ClassInfo.ClassType)!;
177177
}

kscr-runtime/KScrStarter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ private static void WriteClasses(DirectoryInfo output, IEnumerable<FileInfo> sou
150150
{
151151
if (output.Exists)
152152
output.Delete(true);
153-
Package.RootPackage.Write(VM, output, sources.Select(f => VM.FindClassInfo(f)).ToArray(), new StringCache());
153+
Package.RootPackage.Write(VM, output, sources
154+
.Select(VM.MakeFileDecl)
155+
.Select(VM.FindClassInfo)
156+
.ToArray(), new StringCache());
154157
}
155158

156159
public static long Execute(out Stack stack, string? mainClassName = null)

0 commit comments

Comments
 (0)