Fixed bugs with paramaters being passed to the wrong callsite

This commit is contained in:
Samuel D. Crow
2022-08-01 15:35:43 -05:00
parent 34f1abeda6
commit 820fb864bd
9 changed files with 64 additions and 29 deletions

View File

@@ -121,16 +121,28 @@ string operands::boxName()
}
}
void operands::assignment(expression *value)
void operands::assignment(expression *value, bool paramDef)
{
operands *op=value->evaluate();
enum TYPES t=op->getSimpleVarType();
stringstream dest;
string d;
if (paramDef)
{
dest << "sub" << callEnumerator << "->v" << this->getID();
}
else
{
dest << this->boxName();
}
d=dest.str();
dest.clear();
switch (this->getType())
{
case T_FLOATVAR:
if (t==T_INTVAR)
{
output_cpp << this->boxName() << "="
output_cpp << d << "="
<< "static_cast<double>("
<< op->boxName() << ");\n";
}
@@ -138,12 +150,12 @@ void operands::assignment(expression *value)
{
if (t!=T_FLOATVAR) error(E_TYPE_MISMATCH);
}
output_cpp << this->boxName() << "="
output_cpp << d << "="
<< op->boxName() << ";\n";
break;
default:
if (t!=this->getType()) error(E_TYPE_MISMATCH);
output_cpp << this->boxName() << "="
output_cpp << d << "="
<< op->boxName() << ";\n";
break;
}
@@ -530,12 +542,15 @@ variableType::variableType(enum SCOPES s, string &name, enum TYPES t, fn *fnHand
string variableType::boxName()
{
ostringstream ss;
if (myScope==S_LOCAL || myScope==S_PARAMETER)
switch (myScope)
{
ss << "sub" << this->handle->getID() << "->v" << this->getID();
return ss.str();
case S_LOCAL:
case S_PARAMETER:
ss << "sub" << this->handle->getID() << "->v" << this->getID();
break;
default:
ss << "v" << this->getID();
}
ss << "v" << this->getID();
return ss.str();
}