/** * Flattens the Call function to simplify the formula * * @param[in] form: traversed Call node */ AST* Flattener::visit(ASTForm_Call* form) { int calledNumber = form->n; PredLibEntry* called = predicateLib.lookup(calledNumber); /* So far, we will treat predicate and macro the same */ return unfoldFormula(called, form->args); }
/** * Unfolds formal parameters to real parameters in called function * * @param fParams: list of formal parameters * @param rParams: list of real parameters * @return: unfolded macro */ ASTForm* unfoldCall(ASTForm* form, IdentList* fParams, ASTList* rParams) { assert(form->kind == aCall); ASTForm_Call* callForm = static_cast<ASTForm_Call*>(form); PredLibEntry* called = predicateLib.lookup(callForm->n); ASTList* realParams = static_cast<ASTList*>(callForm->args->copy()); for(AST** ast = realParams->begin(); ast != realParams->end(); ++ast) { (*ast) = (*ast)->unfoldMacro(fParams, rParams); } ASTForm* clonnedFormula = (called->ast)->clone(); ASTForm* unfoldedFormula = _unfoldCore(clonnedFormula, called->formals, realParams); // Fixme: this is segfaulting something i guess? //delete realParams; callForm->detach(); //delete callForm; return unfoldedFormula; }