Potential fix for variable declarations and assignments (to them)
- The VarAssDNode processor on typechecker now adds to the back orf the code queue - We removed all weird swapping code in typechecker - Dependency wise, a variable declaration is depended-UPON its variable assignment which in turn a module depends ON. - In the case of no assignments we simpyl make the module depend on the variable declaration dnode directly - Added new test case to show this all
This commit is contained in:
parent
cbe40e7184
commit
31c52c0beb
|
@ -594,7 +594,7 @@ public final class TypeChecker
|
|||
Instruction valueInstr = popInstr();
|
||||
gprintln(valueInstr is null);/*TODO: FUnc calls not implemented? Then is null for simple_1.t */
|
||||
VariableAssignmentInstr varAssInstr = new VariableAssignmentInstr(variableName, valueInstr);
|
||||
addInstr(varAssInstr);
|
||||
addInstrB(varAssInstr);
|
||||
}
|
||||
/* TODO: Add support */
|
||||
/**
|
||||
|
@ -621,48 +621,7 @@ public final class TypeChecker
|
|||
varDecInstr.context = variablePNode.context;
|
||||
|
||||
|
||||
/* If it is a Module variable declaration */
|
||||
if(cast(Module)variablePNode.context.container)
|
||||
{
|
||||
/* Check if there is a VariableAssignmentInstruction */
|
||||
Instruction possibleInstr = popInstr();
|
||||
if(possibleInstr !is null)
|
||||
{
|
||||
VariableAssignmentInstr varAssInstr = cast(VariableAssignmentInstr)possibleInstr;
|
||||
if(varAssInstr)
|
||||
{
|
||||
/* Check if the assignment is to this variable */
|
||||
if(cmp(varAssInstr.varName, variableName) == 0)
|
||||
{
|
||||
/* If so, re-order (VarDec then VarAssign) */
|
||||
|
||||
addInstrB(varDecInstr);
|
||||
addInstrB(varAssInstr);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If not, then no re-order */
|
||||
addInstrB(varAssInstr);
|
||||
addInstrB(varDecInstr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Push it back if not a VariableAssignmentInstruction */
|
||||
|
||||
addInstr(possibleInstr);
|
||||
addInstrB(varDecInstr);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If it is a Class (static) variable declaration */
|
||||
else if(cast(Clazz)variablePNode.context.container)
|
||||
{
|
||||
/* TODO: Make sure this is correct */
|
||||
addInstr(varDecInstr);
|
||||
gprintln("Hello>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
||||
}
|
||||
addInstrB(varDecInstr);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1215,7 +1215,7 @@ public class DNodeGenerator
|
|||
|
||||
|
||||
/* Set this variable as a dependency of this module */
|
||||
node.needs(variableDNode);
|
||||
// node.needs(variableDNode);
|
||||
|
||||
/* Set as visited */
|
||||
variableDNode.markVisited();
|
||||
|
@ -1236,15 +1236,26 @@ public class DNodeGenerator
|
|||
/* If there is an assignment attached to this */
|
||||
if(variable.getAssignment())
|
||||
{
|
||||
/* (TODO) Process the assignment */
|
||||
/* Extract the assignment and pool it to get a DNode */
|
||||
VariableAssignment varAssign = variable.getAssignment();
|
||||
DNode expressionNode = expressionPass(varAssign.getExpression(), context);
|
||||
|
||||
DNode expression = expressionPass(varAssign.getExpression(), context);
|
||||
|
||||
/* This assignment depends on an expression being evaluated */
|
||||
VariableAssignmentNode varAssignNode = new VariableAssignmentNode(this, varAssign);
|
||||
varAssignNode.needs(expression);
|
||||
varAssignNode.needs(expressionNode);
|
||||
|
||||
variableDNode.needs(varAssignNode);
|
||||
/* This assignment is now dependent on the variable declaration */
|
||||
varAssignNode.needs(variableDNode);
|
||||
|
||||
/* The current container is dependent on this running */
|
||||
node.needs(varAssignNode);
|
||||
continue;
|
||||
}
|
||||
/* If there is no assignment */
|
||||
else
|
||||
{
|
||||
/* The current container is dependent on this variable declaration */
|
||||
node.needs(variableDNode);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
module simple_variables;
|
||||
|
||||
|
||||
int x = 1;
|
||||
int y = 2;
|
Loading…
Reference in New Issue