📄 logic_output_item.cc
字号:
/* HYSDEL Copyright (C) 1999-2002 Fabio D. Torrisi This file is part of HYSDEL. HYSDEL is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. HYSDEL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA CONTACT INFORMATION =================== Fabio D. Torrisi ETH Zentrum Physikstrasse. 3 ETL, CH-8032 Zurich Switzerland mailto:torrisi@aut.ee.ethz.ch (preferred)*/#include "Logic_output_item.h"#include "MLD_representation.h"#include "Symbol_table.h"#include "Number_expr.h"#include "Logic_item.h"#include "Var_symbol.h"#include "Variable_expr.h"#include "Row_information.h"//#include <stdlib.h>#include <stdio.h>#include "Globals.h"#include "Problem.h"#include "Problem_handler.h"Logic_output_item::Logic_output_item(const Var_symbol * lhs, Expr * e, const Globals * glob) : Output_item(lhs, glob) { logic = e; upd_var = NULL;}list < const Var_symbol * > Logic_output_item::get_required_simu() const { list < const Var_symbol * > req; if (upd_var && upd_var->is_var_symbol()) req.push_back((const Var_symbol *) upd_var); else add_required(req, logic); return req;}Logic_output_item::~Logic_output_item() { delete logic; this->Output_item::~Output_item();}list < Item * > Logic_output_item::unroll() { Logic_item * li; list < Item * > res; list < Item * >::iterator iter; Expr * upd_var_assign; res = logic->unroll(); construct_logic_eq(logic, & upd_var, & upd_var_assign, & const_value, globals->symbol_table); if (upd_var_assign) { li = new Logic_item((const Var_symbol *) upd_var, upd_var_assign, globals); res.push_back(li); } for (iter = res.begin(); iter != res.end(); iter++) (* iter)->set_unrolled_from(this); return res;}MLD_representation * Logic_output_item::translate_MLD() const { MLD_representation *mld; mld=new MLD_representation(globals); mld->set_info_eq(lhs_var, new Row_information(this, 0)); if (upd_var) { if (const_value) // in this case const_value says whether upd_var is positive or negated mld->set_coeff_eq(lhs_var, (const Var_symbol*)upd_var, new Number_expr(1.0, globals)); else { mld->set_coeff_eq(lhs_var, (const Var_symbol *) upd_var, new Number_expr(-1.0, globals)); mld->set_coeff_eq(lhs_var, NULL, new Number_expr(1.0, globals)); } } else // it was constant and const_value if (const_value) mld->set_coeff_eq(lhs_var, NULL, new Number_expr(1.0, globals)); return mld;}void Logic_output_item::semantic_checks() { string msg; char buf[20]; if (lhs_var->get_kind() != OUTPUT_KIND) { sprintf(buf, "line %d: ", get_source_line()); msg = buf; msg += string("left hand side variable ") + lhs_var->get_name() + string(" is not output"); msg += string(" (") + lhs_var->get_name() + string(" declared at line "); sprintf(buf, "%d)", lhs_var->get_line_of_decl()); msg += string(buf); globals->problem_handler->process(new Problem(ERROR, msg)); } if (lhs_var->get_type() != BOOL_TYPE) { sprintf(buf, "line %d: ", get_source_line()); msg = buf; msg += string("left hand side variable ") + lhs_var->get_name() + string(" is not Boolean"); msg += string(" {") + lhs_var->get_name() + string(" declared at line "); sprintf(buf, "%d)", lhs_var->get_line_of_decl()); msg += string(buf); globals->problem_handler->process(new Problem(ERROR, msg)); } logic->semantic_checks(); assert(logic->is_logic()); //fine}string Logic_output_item::matlab_simu() const { string res; res += string("% ") + get_source() + string("\n"); res += lhs_var->to_matlab() + string(" = "); if (upd_var) res += upd_var->to_matlab(); else { if (const_value) res += string("1"); else res += string("0"); } res += string(";\n"); res += string("\n"); return res;}string Logic_output_item::arg_range_check_matlab() const { string res; res += logic->arg_range_check_matlab(); return res;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -