TypeChecker

- Pass in the type of the variable being declared to the `VariableDeclaration` instruction

VariableDeclaration

- Emitted code now contains the type of the variable being declared
This commit is contained in:
Tristan B. Velloza Kildaire 2022-12-11 18:46:05 +02:00
parent c39bc20d1c
commit 57a9e86d5f
2 changed files with 7 additions and 5 deletions

View File

@ -74,20 +74,22 @@ public final class VariableDeclaration : StorageDeclaration
/* Length */ /* Length */
public byte length; public byte length;
/* Type of the variable being declared */
public string varType;
//TODO: This must take in type information //TODO: This must take in type information
this(string varName, byte len) this(string varName, byte len, string varType)
{ {
this.varName = varName; this.varName = varName;
this.length = len; this.length = len;
this.varType = varType;
addInfo = "varName: "~varName; addInfo = "varName: "~varName;
} }
public override string emit() public override string emit()
{ {
// TODO: This should change string type = varType;
// TODO: We should be having a type pushed into this thing (lookup via Context?)
string type = "<type: TODO>";
string fullEntityName = context.tc.getResolver().generateName(context.getContainer(), context.tc.getResolver().resolveBest(context.getContainer(), varName)); string fullEntityName = context.tc.getResolver().generateName(context.getContainer(), context.tc.getResolver().resolveBest(context.getContainer(), varName));
return type~" "~fullEntityName~";"; return type~" "~fullEntityName~";";

View File

@ -655,7 +655,7 @@ public final class TypeChecker
Variable variablePNode = cast(Variable)dnode.getEntity(); Variable variablePNode = cast(Variable)dnode.getEntity();
gprintln("HELLO FELLA"); gprintln("HELLO FELLA");
string variableName = resolver.generateName(modulle, variablePNode); string variableName = resolver.generateName(modulle, variablePNode);
VariableDeclaration varDecInstr = new VariableDeclaration(variableName, 4); VariableDeclaration varDecInstr = new VariableDeclaration(variableName, 4, variablePNode.getType());
/* NEW CODE (9th November 2021) Set the context */ /* NEW CODE (9th November 2021) Set the context */
varDecInstr.context = variablePNode.context; varDecInstr.context = variablePNode.context;