From fffcc953abe7aee5d8344f1b7a503a086a3bc06a Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Tue, 9 Nov 2021 19:00:23 +0200 Subject: [PATCH] Refactored Context class --- source/tlang/compiler/codegen/instruction.d | 4 +- source/tlang/compiler/symbols/data.d | 9 +-- source/tlang/compiler/typecheck/dependency.d | 72 +++++++++----------- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/source/tlang/compiler/codegen/instruction.d b/source/tlang/compiler/codegen/instruction.d index 36b3de78..a82ff773 100644 --- a/source/tlang/compiler/codegen/instruction.d +++ b/source/tlang/compiler/codegen/instruction.d @@ -1,12 +1,12 @@ module compiler.codegen.instruction; import std.conv : to; -import compiler.typecheck.dependency : DNodeGenerator; +import compiler.typecheck.dependency : Context; public class Instruction { /* Context for the Instruction (used in emitter for name resolution) */ - public DNodeGenerator.Context context; + public Context context; protected string addInfo; diff --git a/source/tlang/compiler/symbols/data.d b/source/tlang/compiler/symbols/data.d index 44750a93..5346a3bb 100644 --- a/source/tlang/compiler/symbols/data.d +++ b/source/tlang/compiler/symbols/data.d @@ -2,6 +2,7 @@ module compiler.symbols.data; public import compiler.symbols.check; import std.conv : to; +import compiler.typecheck.dependency : Context; /** @@ -86,14 +87,14 @@ public class Statement /* !!!! BEGIN TYPE CHECK ROUTINES AND DATA !!!! */ /* TODO: Used for type checking */ - import compiler.typecheck.dependency ; - public DNodeGenerator.Context context; - public void setContext(DNodeGenerator.Context context) + + public Context context; + public void setContext(Context context) { this.context = context; } - public DNodeGenerator.Context getContext() + public Context getContext() { return context; } diff --git a/source/tlang/compiler/typecheck/dependency.d b/source/tlang/compiler/typecheck/dependency.d index b979b388..b5dac067 100644 --- a/source/tlang/compiler/typecheck/dependency.d +++ b/source/tlang/compiler/typecheck/dependency.d @@ -16,10 +16,41 @@ import compiler.symbols.typing.builtins; /** -* December update +* Passed around * -* This is for future additions and +* 1. Contains containership (some Statements are not contained) so we need to track this +* 2. InitScope, STATIC or VIRTUAL permission +* 3. `allowUp`, when resolving names in this Context use +* resolveBest instead of resolveWithin (stay inside Context solely +* don't travel up parents) */ +public final class Context +{ + InitScope initScope; + Container container; + bool allowUp = true; + + this(Container container, InitScope initScope) + { + this.initScope = initScope; + this.container = container; + } + + public bool isAllowUp() + { + return allowUp; + } + + public void noAllowUp() + { + allowUp = false; + } + + public Container getContainer() + { + return container; + } +} /** * DNode @@ -272,42 +303,7 @@ public class DNodeGenerator } - /** - * Passed around - * - * 1. Contains containership (some Statements are not contained) so we need to track this - * 2. InitScope, STATIC or VIRTUAL permission - * 3. `allowUp`, when resolving names in this Context use - * resolveBest instead of resolveWithin (stay inside Context solely - * don't travel up parents) - */ - public final class Context - { - InitScope initScope; - Container container; - bool allowUp = true; - - this(Container container, InitScope initScope) - { - this.initScope = initScope; - this.container = container; - } - - public bool isAllowUp() - { - return allowUp; - } - - public void noAllowUp() - { - allowUp = false; - } - - public Container getContainer() - { - return container; - } - } + import compiler.typecheck.expression; import compiler.typecheck.classes.classObject;