📄 symbol.cc
字号:
#include <stdio.h>#include "Symbol.h"#include "Globals.h"#include "Symbol_table.h"#include "Item.h"#include "Var_symbol.h"#include "Problem.h"#include "Problem_handler.h"Symbol::Symbol(Symb_type i_type, string i_name, const Globals * glob) { globals = glob; type = i_type; name = i_name; line_of_decl = -1; line_of_first_use = -1; computable_order = -1;}bool Symbol::is_used() const { return line_of_first_use != -1;}string Symbol::to_matlab() const { return name;}Symb_type Symbol::get_type() const { return type;}void Symbol::set_declared(int line_no) const { globals->symbol_table->symb_set_declared(this, line_no);}void Symbol::set_declared_nonconst(int line_no) { assert(line_of_decl = -1); //fine line_of_decl = line_no;}void Symbol::set_used(int line_no) const { globals->symbol_table->symb_set_used(this, line_no);}void Symbol::set_used_nonconst(int line_no) { if (line_of_first_use == -1) line_of_first_use = line_no;}void Symbol::semantic_checks() { if (!is_default_symbol() && get_kind()!=OUTPUT_KIND) { assert(line_of_decl != -1); //fine if (!is_used() && name != string("MLD_epsilon")) { string msg; char buf[70]; if (is_param_symbol()) msg += string("Parameter "); else msg += string("Variable "); msg += get_name(); msg += string(" is never used (") + get_name() + string(" was declared at line "); sprintf(buf, "%d", line_of_decl); msg += string(buf); if (is_var_symbol() && ((Var_symbol *) this)->is_defined()) { sprintf(buf, ", defined at line %d", ((Var_symbol *) this)->get_definition()->get_source_line()); msg += string(buf); } msg += string(")"); globals->problem_handler->process( new Problem(WARNING, msg, SYMBOL_NOT_USED)); } }}/*boolSymbol::is_required(const Symbol *s) const{list<const Symbol*> req;req=get_required();for (list<const Symbol*>::const_iterator iter=req.begin();iter!=req.end(); iter++){if ( (*iter)==s )return true;}return false;}*/string Symbol::status_matlab(string prefix) const { string res; char buf[100]; res += prefix + string("name = \'") + name + string("\';\n"); if (type == REAL_TYPE) res += prefix + string("type = \'r\';\n"); else res += prefix + string("type = \'b\';\n"); sprintf(buf, "line_of_declaration = %d;\n", line_of_decl); res += prefix + buf; sprintf(buf, "line_of_first_use = %d;\n", line_of_first_use); res += prefix + buf; sprintf(buf, "computable_order = %d;\n", computable_order); res += prefix + buf; return res;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -