Code cleanup.

pull/3/head
yhirose 9 years ago
parent e8ca00acb5
commit 9d5b5027e3
  1. 4
      language/culebra.h
  2. 18
      language/main.cc

@ -396,7 +396,7 @@ struct Environment
std::map<std::string, Symbol> dictionary; std::map<std::string, Symbol> dictionary;
}; };
typedef std::function<void (const peglib::Ast& ast, std::shared_ptr<Environment> env, bool force_to_break)> Debugger; typedef std::function<void (const peglib::Ast& ast, Environment& env, bool force_to_break)> Debugger;
inline bool ObjectValue::has(const std::string& name) const { inline bool ObjectValue::has(const std::string& name) const {
if (properties->find(name) == properties->end()) { if (properties->find(name) == properties->end()) {
@ -538,7 +538,7 @@ struct Eval
if (debugger_) { if (debugger_) {
if (ast.original_tag == "STATEMENT"_) { if (ast.original_tag == "STATEMENT"_) {
auto force_to_break = ast.tag == "DEBUGGER"_; auto force_to_break = ast.tag == "DEBUGGER"_;
debugger_(ast, env, force_to_break); debugger_(ast, *env, force_to_break);
} }
} }

@ -28,14 +28,14 @@ bool read_file(const char* path, vector<char>& buff)
struct CommandLineDebugger struct CommandLineDebugger
{ {
void operator()(const Ast& ast, shared_ptr<Environment> env, bool force_to_break) { void operator()(const Ast& ast, Environment& env, bool force_to_break) {
if (quit) { if (quit) {
return; return;
} }
if ((command_ == "n" && env->level <= level_) || if ((command_ == "n" && env.level <= level_) ||
(command_ == "s") || (command_ == "s") ||
(command_ == "o" && env->level < level_)) { (command_ == "o" && env.level < level_)) {
force_to_break = true; force_to_break = true;
} }
@ -72,7 +72,7 @@ struct CommandLineDebugger
break; break;
} }
} }
level_ = env->level;; level_ = env.level;;
} }
} }
@ -123,22 +123,22 @@ struct CommandLineDebugger
} }
} }
void print(const Ast& ast, shared_ptr<Environment> env, const string& symbol) { void print(const Ast& ast, Environment& env, const string& symbol) {
if (symbol.empty()) { if (symbol.empty()) {
print_all(ast, env); print_all(ast, env);
} else if (env->has(symbol)) { } else if (env.has(symbol)) {
cout << symbol << ": " << env->get(symbol).str() << endl; cout << symbol << ": " << env.get(symbol).str() << endl;
} else { } else {
cout << "'" << symbol << "'" << "is not undefined." << endl; cout << "'" << symbol << "'" << "is not undefined." << endl;
} }
} }
void print_all(const Ast& ast, shared_ptr<Environment> env) { void print_all(const Ast& ast, Environment& env) {
auto node = find_function_node(ast); auto node = find_function_node(ast);
set<string> references; set<string> references;
enum_identifiers(*node, references); enum_identifiers(*node, references);
for (const auto& symbol: references) { for (const auto& symbol: references) {
const auto& val = env->get(symbol); const auto& val = env.get(symbol);
cout << symbol << ": " << val.str() << endl; cout << symbol << ": " << val.str() << endl;
} }
} }

Loading…
Cancel
Save