VariableAssignmentInstr
- Removed now-completed TODO Value - Made the `type` field private and added a comment explaining it - Implemented `setInstrType(Type)` and `Type getInstrType()` TypeChecker - Switched to using `getInstrType()` and `setInstrType()` DGen TypeChecker - Switched to using `getInstrType()`
This commit is contained in:
parent
d97d1c9ce2
commit
eddd17775d
|
@ -129,10 +129,10 @@ public final class DCodeEmitter : CodeEmitter
|
||||||
auto typedEntityVariable = typeChecker.getResolver().resolveBest(context.getContainer(), varAs.varName); //TODO: Remove `auto`
|
auto typedEntityVariable = typeChecker.getResolver().resolveBest(context.getContainer(), varAs.varName); //TODO: Remove `auto`
|
||||||
gprintln("Hi"~to!(string)(varAs));
|
gprintln("Hi"~to!(string)(varAs));
|
||||||
gprintln("Hi"~to!(string)(varAs.data));
|
gprintln("Hi"~to!(string)(varAs.data));
|
||||||
gprintln("Hi"~to!(string)(varAs.data.type));
|
gprintln("Hi"~to!(string)(varAs.data.getInstrType()));
|
||||||
|
|
||||||
// NOTE: For tetsing issue #94 coercion (remove when done)
|
// NOTE: For tetsing issue #94 coercion (remove when done)
|
||||||
string typeName = (cast(Type)varAs.data.type).getName();
|
string typeName = (cast(Type)varAs.data.getInstrType()).getName();
|
||||||
gprintln("VariableAssignmentInstr: The data to assign's type is: "~typeName);
|
gprintln("VariableAssignmentInstr: The data to assign's type is: "~typeName);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,18 @@ public class FetchInst : Instruction
|
||||||
|
|
||||||
public class Value : Instruction
|
public class Value : Instruction
|
||||||
{
|
{
|
||||||
public Type type;
|
/* The type of the Value this instruction produces */
|
||||||
|
private Type type;
|
||||||
|
|
||||||
|
public final void setInstrType(Type type)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Type getInstrType()
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StorageDeclaration : Instruction
|
public class StorageDeclaration : Instruction
|
||||||
|
@ -59,7 +70,7 @@ public class VariableAssignmentInstr : Instruction
|
||||||
/* Name of variable being declared */
|
/* Name of variable being declared */
|
||||||
public string varName; /*TODO: Might not be needed */
|
public string varName; /*TODO: Might not be needed */
|
||||||
|
|
||||||
public const Value data; // TODO: Make `Value` to constrain
|
public Value data;
|
||||||
|
|
||||||
this(string varName, Value data)
|
this(string varName, Value data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -534,7 +534,7 @@ public final class TypeChecker
|
||||||
addInstr(fVV);
|
addInstr(fVV);
|
||||||
|
|
||||||
/* The type of a FetchValueInstruction is the type of the variable being fetched */
|
/* The type of a FetchValueInstruction is the type of the variable being fetched */
|
||||||
fVV.type = variableType;
|
fVV.setInstrType(variableType);
|
||||||
}
|
}
|
||||||
// else if(cast()) !!!! Continue here
|
// else if(cast()) !!!! Continue here
|
||||||
else if(cast(BinaryOperatorExpression)statement)
|
else if(cast(BinaryOperatorExpression)statement)
|
||||||
|
@ -558,8 +558,8 @@ public final class TypeChecker
|
||||||
Value vRhsInstr = cast(Value)popInstr();
|
Value vRhsInstr = cast(Value)popInstr();
|
||||||
Value vLhsInstr = cast(Value)popInstr();
|
Value vLhsInstr = cast(Value)popInstr();
|
||||||
|
|
||||||
Type vRhsType = vRhsInstr.type;
|
Type vRhsType = vRhsInstr.getInstrType();
|
||||||
Type vLhsType = vLhsInstr.type;
|
Type vLhsType = vLhsInstr.getInstrType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
|
@ -582,7 +582,7 @@ public final class TypeChecker
|
||||||
addInstr(addInst);
|
addInstr(addInst);
|
||||||
|
|
||||||
/* Set the Value instruction's type */
|
/* Set the Value instruction's type */
|
||||||
addInst.type = chosenType;
|
addInst.setInstrType(chosenType);
|
||||||
}
|
}
|
||||||
/* Unary operator expressions */
|
/* Unary operator expressions */
|
||||||
else if(cast(UnaryOperatorExpression)statement)
|
else if(cast(UnaryOperatorExpression)statement)
|
||||||
|
@ -598,7 +598,7 @@ public final class TypeChecker
|
||||||
* Typechecking (TODO)
|
* Typechecking (TODO)
|
||||||
*/
|
*/
|
||||||
Value expInstr = cast(Value)popInstr();
|
Value expInstr = cast(Value)popInstr();
|
||||||
Type expType = expInstr.type;
|
Type expType = expInstr.getInstrType();
|
||||||
|
|
||||||
/* TODO: Ad type check for operator */
|
/* TODO: Ad type check for operator */
|
||||||
|
|
||||||
|
@ -661,7 +661,7 @@ public final class TypeChecker
|
||||||
gprintln("Made unaryop instr: "~to!(string)(addInst));
|
gprintln("Made unaryop instr: "~to!(string)(addInst));
|
||||||
addInstr(addInst);
|
addInstr(addInst);
|
||||||
|
|
||||||
addInst.type = unaryOpType;
|
addInst.setInstrType(unaryOpType);
|
||||||
}
|
}
|
||||||
/* Function calls */
|
/* Function calls */
|
||||||
else if(cast(FunctionCall)statement)
|
else if(cast(FunctionCall)statement)
|
||||||
|
@ -706,7 +706,7 @@ public final class TypeChecker
|
||||||
gprintln("Yeah");
|
gprintln("Yeah");
|
||||||
gprintln(valueInstr);
|
gprintln(valueInstr);
|
||||||
// Type argType = popType(); // TODO: Remove with removal of typequeue
|
// Type argType = popType(); // TODO: Remove with removal of typequeue
|
||||||
Type argType = valueInstr.type;
|
Type argType = valueInstr.getInstrType();
|
||||||
// gprintln(argType);
|
// gprintln(argType);
|
||||||
|
|
||||||
Variable parameter = paremeters[parmCount];
|
Variable parameter = paremeters[parmCount];
|
||||||
|
@ -768,7 +768,7 @@ public final class TypeChecker
|
||||||
|
|
||||||
/* Set the Value instruction's type */
|
/* Set the Value instruction's type */
|
||||||
Type funcCallInstrType = getType(func.parentOf(), func.getType());
|
Type funcCallInstrType = getType(func.parentOf(), func.getType());
|
||||||
funcCallInstr.type = funcCallInstrType;
|
funcCallInstr.setInstrType(funcCallInstrType);
|
||||||
// addType(funcCallInstrType); // TODO: Remove me when the typequeue is removed
|
// addType(funcCallInstrType); // TODO: Remove me when the typequeue is removed
|
||||||
}
|
}
|
||||||
/* Type cast operator */
|
/* Type cast operator */
|
||||||
|
@ -800,7 +800,7 @@ public final class TypeChecker
|
||||||
assert(uncastedInstruction);
|
assert(uncastedInstruction);
|
||||||
|
|
||||||
/* Extract the type of the expression being casted */
|
/* Extract the type of the expression being casted */
|
||||||
typeBeingCasted = uncastedInstruction.type;
|
typeBeingCasted = uncastedInstruction.getInstrType();
|
||||||
gprintln("TypeCast [FromType: "~to!(string)(typeBeingCasted)~", ToType: "~to!(string)(castToType)~"]");
|
gprintln("TypeCast [FromType: "~to!(string)(typeBeingCasted)~", ToType: "~to!(string)(castToType)~"]");
|
||||||
|
|
||||||
|
|
||||||
|
@ -814,7 +814,7 @@ public final class TypeChecker
|
||||||
addInstr(castedValueInstruction);
|
addInstr(castedValueInstruction);
|
||||||
|
|
||||||
/* The type of the cats expression is that of the type it casts to */
|
/* The type of the cats expression is that of the type it casts to */
|
||||||
castedValueInstruction.type = castToType;
|
castedValueInstruction.setInstrType(castToType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* VariableAssigbmentDNode */
|
/* VariableAssigbmentDNode */
|
||||||
|
@ -855,7 +855,7 @@ public final class TypeChecker
|
||||||
|
|
||||||
|
|
||||||
Type rightHandType; //= popType(); // TODO: Remove with the removal of the typequeue
|
Type rightHandType; //= popType(); // TODO: Remove with the removal of the typequeue
|
||||||
rightHandType = valueInstr.type;
|
rightHandType = valueInstr.getInstrType();
|
||||||
gprintln("RightHandType (assignment): "~to!(string)(rightHandType));
|
gprintln("RightHandType (assignment): "~to!(string)(rightHandType));
|
||||||
|
|
||||||
|
|
||||||
|
@ -909,7 +909,7 @@ public final class TypeChecker
|
||||||
// ... along with said embedded instruction's type
|
// ... along with said embedded instruction's type
|
||||||
assert(assignmentInstr.data);
|
assert(assignmentInstr.data);
|
||||||
Value embeddedInstruction = cast(Value)assignmentInstr.data;
|
Value embeddedInstruction = cast(Value)assignmentInstr.data;
|
||||||
Type assignmentType = embeddedInstruction.type;
|
Type assignmentType = embeddedInstruction.getInstrType();
|
||||||
|
|
||||||
|
|
||||||
// TODO: We should add a typecheck here where we update the type of the valInstr if it is of
|
// TODO: We should add a typecheck here where we update the type of the valInstr if it is of
|
||||||
|
@ -939,7 +939,7 @@ public final class TypeChecker
|
||||||
// TODO: Coerce here by changing the embedded instruction's type (I think this makes sense)
|
// TODO: Coerce here by changing the embedded instruction's type (I think this makes sense)
|
||||||
// ... as during code emit that is what will be hoisted out and checked regarding its type
|
// ... as during code emit that is what will be hoisted out and checked regarding its type
|
||||||
// NOTE: Referrring to same type should not be a problem (see #96 Question 1)
|
// NOTE: Referrring to same type should not be a problem (see #96 Question 1)
|
||||||
embeddedInstruction.type = variableDeclarationType;
|
embeddedInstruction.setInstrType(variableDeclarationType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1020,7 +1020,7 @@ public final class TypeChecker
|
||||||
|
|
||||||
// TODO: A popType() should be done here techncially, IF we do this then it
|
// TODO: A popType() should be done here techncially, IF we do this then it
|
||||||
// ... must be pushed by VariableAssigmnetNode
|
// ... must be pushed by VariableAssigmnetNode
|
||||||
Type assignmentType = valueInstr.type;
|
Type assignmentType = valueInstr.getInstrType();
|
||||||
assert(assignmentType);
|
assert(assignmentType);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue