void Operands::solveMatch(struct s_match m, struct s_operand *op, Labels labels, struct s_status *status) { op->name = m.element; op->operation = m.operation; op->aritOperand = m.operand; op->aritOperandType = TYPE_NONE; op->type = TYPE_LABEL; // if the operand is a label if((m.subtype[TYPE_ADDRESS] || m.subtype[TYPE_LABEL]) && labels.exists(op->name)) op->value = Number::toBin(labels.value(op->name)); // if not, it might be a number else if (Number::exists(op->name)) op->value == Number::toBin(op->name); else throw(eUndefinedLabel); // checks if there is an operation if(op->operation.compare("") != 0) Operands::solveOperation(op, labels, status); }
/** * resolve a operacao aritmetica presente no operando, escrevendo o valor em o->value */ void Operands::solveOperation(t_operand *op,Labels labels,t_status *status) { if(op->operation.compare("") == 0) return; bool opPotentialLabel = false; Number *operand = NULL; if(status != NULL) status->label = (char *)op->aritOperand.c_str(); if(labels.exists(op->aritOperand)) { operand = new Number(Number::toBin(labels.value(op->aritOperand))); } else { try { operand = new Number(op->aritOperand); } catch(e_exception e) { opPotentialLabel = true; } } if(!opPotentialLabel) { Number result(op->value); result.operate(op->operation[0],*operand); op->value = result.toBin(); delete operand; } else { op->aritOperandType = TYPE_LABEL; throw(eUndefinedLabel); } }