⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 param_symbol.cc

📁 由matlab开发的hybrid系统的描述语言
💻 CC
字号:
#include "Param_symbol.h"#include "Var_symbol.h"#include "Expr.h"#include "Number.h"#include "Globals.h"#include "Symbol_table.h"#include "Variable_expr.h"#include "Parameter_expr.h"#include "Unary_expr.h"#include "Binary_expr.h"#include "Item.h"#include <stdio.h>#include "Problem.h"#include "Problem_handler.h"Param_symbol::Param_symbol(Symb_type i_type, int cnt, string i_name,	const Globals * glob) : Symbol(i_type, i_name, glob) {		constr_order = cnt;}Param_symbol::~Param_symbol() {	if (value) delete value;}int Param_symbol::get_count() const {	assert(0); //fine (don't ask Parameter for count)	return -1;}Symb_kind Param_symbol::get_kind() const {	return PARAM_KIND;}void Param_symbol::set_value(Expr * e) const {	globals->symbol_table->symb_set_value(this, e);}void Param_symbol::set_value_nonconst(Expr * e) {	value = e;}bool Param_symbol::is_symbolic() const {	if (!value) return true; else return value->is_symbolic();}
bool Param_symbol::is_terminal_symbolic() const {	return (!value);}
/** change behavior by commandline arguments */string Param_symbol::to_matlab() const {	if (!value || globals->all_params_symbolic)		return globals->symbol_table->param_prefix() + name; else		return value->to_matlab();}Number * Param_symbol::compute_number() const {	assert(value); //fine	return value->compute_number();}Expr * Param_symbol::get_value() const {	if (value) return value->clone(); else return NULL;}/** exatly same code as Item::add_required(const Expr *e) *//*voidParam_symbol::add_required(const Expr *e){const Symbol *s=NULL;if (e->is_variable_expr())s=((const Variable_expr*)e)->get_value();if (e->is_parameter_expr())s=((const Parameter_expr*)e)->get_value();if (s) {if (!is_required(s))required.push_back(s);}if (e->is_unary_expr())add_required( ((const Unary_expr*)e)->get_child() );if (e->is_binary_expr()) {add_required( ((const Binary_expr*)e)->get_left() );add_required( ((const Binary_expr*)e)->get_right() );}}*/void Param_symbol::semantic_checks() {	list < const Var_symbol * > var_req;	Symbol::semantic_checks();	if (value) {		value->semantic_checks();		if (type == REAL_TYPE) assert(value->is_real()); //fine		else assert(value->is_logic()); //fine		Item::add_required(var_req, value);		for (list < const Var_symbol * >::const_iterator iter =			var_req.begin(); iter != var_req.end(); iter++) {				string msg;				char buf[50];				sprintf(buf, "line %d: ", line_of_decl);				msg += string(buf);				msg += string("Parameter ") + get_name() +					string(" is defined using variable ");				msg += (* iter)->get_name();				globals->problem_handler->process(					new Problem(ERROR, msg));		}	}}string Param_symbol::status_matlab(string prefix) const {	string res;	res += Symbol::status_matlab(prefix);	res += prefix + string("kind = \'p\';\n");	//res+=prefix + string("index = NaN;\n");  ?????????????//	res += prefix + string("min = NaN;\n");//	res += prefix + string("max = NaN;\n");	res += prefix + string("value = ") + to_matlab() + string(";\n");	return res;}/*intParam_symbol::find_computable_order(const Item *originator, list<constParam_symbol*> path){list<const Param_symbol*>::iterator iter;	if (computable_order!=-1)return computable_order;if (value==NULL || value->is_number()) {computable_order=1;return computable_order;}		for (iter=path.begin(); iter!=path.end(); iter++) {if ( (*iter)==this ) {string msg;char buf[20];			sprintf(buf, "line %d: ", originator->get_source_line()); msg=buf;msg+=string("circular definition of parameter ") + get_name();path.reverse(); // better: use reverse iteratorfor (list<const Symbol*>::const_iterator iter2=path.begin();iter2!=path.end(); iter2++) {msg+=string("\nneeded in definition of variable ") + (*iter2)->get_name();if ( (*iter2)==this )break;}throw new Problem(ERROR, msg);}			}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -