mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Code cleanup.
This commit is contained in:
parent
e8ca00acb5
commit
9d5b5027e3
@ -396,7 +396,7 @@ struct Environment
|
||||
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 {
|
||||
if (properties->find(name) == properties->end()) {
|
||||
@ -538,7 +538,7 @@ struct Eval
|
||||
if (debugger_) {
|
||||
if (ast.original_tag == "STATEMENT"_) {
|
||||
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
|
||||
{
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((command_ == "n" && env->level <= level_) ||
|
||||
if ((command_ == "n" && env.level <= level_) ||
|
||||
(command_ == "s") ||
|
||||
(command_ == "o" && env->level < level_)) {
|
||||
(command_ == "o" && env.level < level_)) {
|
||||
force_to_break = true;
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ struct CommandLineDebugger
|
||||
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()) {
|
||||
print_all(ast, env);
|
||||
} else if (env->has(symbol)) {
|
||||
cout << symbol << ": " << env->get(symbol).str() << endl;
|
||||
} else if (env.has(symbol)) {
|
||||
cout << symbol << ": " << env.get(symbol).str() << endl;
|
||||
} else {
|
||||
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);
|
||||
set<string> references;
|
||||
enum_identifiers(*node, references);
|
||||
for (const auto& symbol: references) {
|
||||
const auto& val = env->get(symbol);
|
||||
const auto& val = env.get(symbol);
|
||||
cout << symbol << ": " << val.str() << endl;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user