Refactored Context class

This commit is contained in:
Tristan B. Velloza Kildaire 2021-11-09 19:00:23 +02:00
parent 7dd8f2df75
commit fffcc953ab
3 changed files with 41 additions and 44 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;