🎨 add namespace
This commit is contained in:
parent
d89f290a8a
commit
cd4e0c1716
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
bool ast_dumper::visit_null_expr(null_expr* node) {
|
bool ast_dumper::visit_null_expr(null_expr* node) {
|
||||||
dump_indent();
|
dump_indent();
|
||||||
std::cout << "null" << format_location(node->get_location());
|
std::cout << "null" << format_location(node->get_location());
|
||||||
|
@ -478,4 +480,6 @@ bool ast_dumper::visit_return_expr(return_expr* node) {
|
||||||
pop_indent();
|
pop_indent();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
class ast_dumper:public ast_visitor {
|
class ast_dumper:public ast_visitor {
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> indent;
|
std::vector<std::string> indent;
|
||||||
|
@ -78,4 +80,6 @@ public:
|
||||||
void dump(code_block* root) {
|
void dump(code_block* root) {
|
||||||
root->accept(this);
|
root->accept(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "ast_visitor.h"
|
#include "ast_visitor.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
bool ast_visitor::visit_expr(expr* node) {
|
bool ast_visitor::visit_expr(expr* node) {
|
||||||
node->accept(this);
|
node->accept(this);
|
||||||
return true;
|
return true;
|
||||||
|
@ -231,4 +233,6 @@ bool ast_visitor::visit_return_expr(return_expr* node) {
|
||||||
node->get_value()->accept(this);
|
node->get_value()->accept(this);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "nasal_ast.h"
|
#include "nasal_ast.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
class ast_visitor {
|
class ast_visitor {
|
||||||
public:
|
public:
|
||||||
virtual bool visit_expr(expr*);
|
virtual bool visit_expr(expr*);
|
||||||
|
@ -40,4 +42,6 @@ public:
|
||||||
virtual bool visit_continue_expr(continue_expr*);
|
virtual bool visit_continue_expr(continue_expr*);
|
||||||
virtual bool visit_break_expr(break_expr*);
|
virtual bool visit_break_expr(break_expr*);
|
||||||
virtual bool visit_return_expr(return_expr*);
|
virtual bool visit_return_expr(return_expr*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -89,7 +89,7 @@ std::ostream& version(std::ostream& out) {
|
||||||
num = (num+rand())*(1.0/(RAND_MAX+1.0));
|
num = (num+rand())*(1.0/(RAND_MAX+1.0));
|
||||||
}
|
}
|
||||||
if (num<0.01) {
|
if (num<0.01) {
|
||||||
parse::easter_egg();
|
nasal::parse::easter_egg();
|
||||||
}
|
}
|
||||||
out << "nasal interpreter version " << __nasver;
|
out << "nasal interpreter version " << __nasver;
|
||||||
out << " (" << __DATE__ << " " << __TIME__ << ")\n";
|
out << " (" << __DATE__ << " " << __TIME__ << ")\n";
|
||||||
|
@ -112,10 +112,10 @@ void execute(
|
||||||
using clk = std::chrono::high_resolution_clock;
|
using clk = std::chrono::high_resolution_clock;
|
||||||
const auto den = clk::duration::period::den;
|
const auto den = clk::duration::period::den;
|
||||||
|
|
||||||
lexer lex;
|
nasal::lexer lex;
|
||||||
parse parse;
|
nasal::parse parse;
|
||||||
linker ld;
|
nasal::linker ld;
|
||||||
codegen gen;
|
nasal::codegen gen;
|
||||||
|
|
||||||
// lexer scans file to get tokens
|
// lexer scans file to get tokens
|
||||||
lex.scan(file).chkerr();
|
lex.scan(file).chkerr();
|
||||||
|
@ -123,7 +123,7 @@ void execute(
|
||||||
// parser gets lexer's token list to compile
|
// parser gets lexer's token list to compile
|
||||||
parse.compile(lex).chkerr();
|
parse.compile(lex).chkerr();
|
||||||
if (cmd&VM_RAW_AST) {
|
if (cmd&VM_RAW_AST) {
|
||||||
auto dumper = std::unique_ptr<ast_dumper>(new ast_dumper);
|
auto dumper = std::unique_ptr<nasal::ast_dumper>(new nasal::ast_dumper);
|
||||||
dumper->dump(parse.tree());
|
dumper->dump(parse.tree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +131,10 @@ void execute(
|
||||||
ld.link(parse, file, cmd&VM_DETAIL).chkerr();
|
ld.link(parse, file, cmd&VM_DETAIL).chkerr();
|
||||||
|
|
||||||
// optimizer does simple optimization on ast
|
// optimizer does simple optimization on ast
|
||||||
auto opt = std::unique_ptr<optimizer>(new optimizer);
|
auto opt = std::unique_ptr<nasal::optimizer>(new nasal::optimizer);
|
||||||
opt->do_optimization(parse.tree());
|
opt->do_optimization(parse.tree());
|
||||||
if (cmd&VM_AST) {
|
if (cmd&VM_AST) {
|
||||||
auto dumper = std::unique_ptr<ast_dumper>(new ast_dumper);
|
auto dumper = std::unique_ptr<nasal::ast_dumper>(new nasal::ast_dumper);
|
||||||
dumper->dump(parse.tree());
|
dumper->dump(parse.tree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,10 +150,10 @@ void execute(
|
||||||
// run
|
// run
|
||||||
auto start = clk::now();
|
auto start = clk::now();
|
||||||
if (cmd&VM_DEBUG) {
|
if (cmd&VM_DEBUG) {
|
||||||
auto debugger = std::unique_ptr<dbg>(new dbg);
|
auto debugger = std::unique_ptr<nasal::dbg>(new nasal::dbg);
|
||||||
debugger->run(gen, ld, argv, cmd&VM_PROFILE, cmd&VM_PROF_ALL);
|
debugger->run(gen, ld, argv, cmd&VM_PROFILE, cmd&VM_PROF_ALL);
|
||||||
} else if (cmd&VM_TIME || cmd&VM_EXEC) {
|
} else if (cmd&VM_TIME || cmd&VM_EXEC) {
|
||||||
auto runtime = std::unique_ptr<vm>(new vm);
|
auto runtime = std::unique_ptr<nasal::vm>(new nasal::vm);
|
||||||
runtime->run(gen, ld, argv, cmd&VM_DETAIL);
|
runtime->run(gen, ld, argv, cmd&VM_DETAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +180,8 @@ i32 main(i32 argc, const char* argv[]) {
|
||||||
} else if (s=="-v" || s=="--version") {
|
} else if (s=="-v" || s=="--version") {
|
||||||
std::clog << version;
|
std::clog << version;
|
||||||
} else if (s=="-r" || s=="--repl") {
|
} else if (s=="-r" || s=="--repl") {
|
||||||
auto repl_module = std::unique_ptr<repl::repl>(new repl::repl);
|
auto repl = std::unique_ptr<nasal::repl::repl>(new nasal::repl::repl);
|
||||||
repl_module->execute();
|
repl->execute();
|
||||||
} else if (s[0]!='-') {
|
} else if (s[0]!='-') {
|
||||||
execute(s, {}, VM_EXEC);
|
execute(s, {}, VM_EXEC);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "nasal_ast.h"
|
#include "nasal_ast.h"
|
||||||
#include "ast_visitor.h"
|
#include "ast_visitor.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
void expr::accept(ast_visitor* visitor) {
|
void expr::accept(ast_visitor* visitor) {
|
||||||
visitor->visit_expr(this);
|
visitor->visit_expr(this);
|
||||||
}
|
}
|
||||||
|
@ -365,4 +367,6 @@ return_expr::~return_expr() {
|
||||||
|
|
||||||
void return_expr::accept(ast_visitor* visitor) {
|
void return_expr::accept(ast_visitor* visitor) {
|
||||||
visitor->visit_return_expr(this);
|
visitor->visit_return_expr(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
enum class expr_type:u32 {
|
enum class expr_type:u32 {
|
||||||
ast_null = 0, // null node
|
ast_null = 0, // null node
|
||||||
ast_block, // code block
|
ast_block, // code block
|
||||||
|
@ -669,3 +671,5 @@ public:
|
||||||
expr* get_value() {return value;}
|
expr* get_value() {return value;}
|
||||||
void accept(ast_visitor*) override;
|
void accept(ast_visitor*) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "nasal_codegen.h"
|
#include "nasal_codegen.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
void codegen::init_file_map(const std::vector<std::string>& file_list) {
|
void codegen::init_file_map(const std::vector<std::string>& file_list) {
|
||||||
file_map = {};
|
file_map = {};
|
||||||
for(usize i = 0; i<file_list.size(); ++i) {
|
for(usize i = 0; i<file_list.size(); ++i) {
|
||||||
|
@ -1255,3 +1257,5 @@ void codegen::symbol_dump(std::ostream& out) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#pragma warning (disable:4267)
|
#pragma warning (disable:4267)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
class codegen {
|
class codegen {
|
||||||
private:
|
private:
|
||||||
error err;
|
error err;
|
||||||
|
@ -136,3 +138,5 @@ public:
|
||||||
void print(std::ostream&);
|
void print(std::ostream&);
|
||||||
void symbol_dump(std::ostream&) const;
|
void symbol_dump(std::ostream&) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "nasal_dbg.h"
|
#include "nasal_dbg.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
void debug_prof_data::init_counter() {
|
void debug_prof_data::init_counter() {
|
||||||
for(usize i = 0; i<debug_prof_data::operand_size; ++i) {
|
for(usize i = 0; i<debug_prof_data::operand_size; ++i) {
|
||||||
operand_counter[i] = 0;
|
operand_counter[i] = 0;
|
||||||
|
@ -276,3 +278,5 @@ void dbg::run(
|
||||||
imm.clear();
|
imm.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
class debug_prof_data {
|
class debug_prof_data {
|
||||||
private:
|
private:
|
||||||
static const usize operand_size = op_code_type::op_ret + 1;
|
static const usize operand_size = op_code_type::op_ret + 1;
|
||||||
|
@ -167,3 +169,5 @@ public:
|
||||||
bool
|
bool
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "nasal_err.h"
|
#include "nasal_err.h"
|
||||||
#include "repl.h"
|
#include "repl.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h> // use SetConsoleTextAttribute
|
#include <windows.h> // use SetConsoleTextAttribute
|
||||||
struct for_reset {
|
struct for_reset {
|
||||||
|
@ -184,4 +186,6 @@ void error::err(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cerr << "\n\n";
|
std::cerr << "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#include "nasal.h"
|
#include "nasal.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
struct span {
|
struct span {
|
||||||
u32 begin_line;
|
u32 begin_line;
|
||||||
u32 begin_column;
|
u32 begin_column;
|
||||||
|
@ -65,3 +67,5 @@ public:
|
||||||
}
|
}
|
||||||
u32 geterr() const {return cnt;}
|
u32 geterr() const {return cnt;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "nasal_import.h"
|
#include "nasal_import.h"
|
||||||
#include "symbol_finder.h"
|
#include "symbol_finder.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
linker::linker():
|
linker::linker():
|
||||||
show_path(false), lib_loaded(false),
|
show_path(false), lib_loaded(false),
|
||||||
this_file(""), lib_path("") {
|
this_file(""), lib_path("") {
|
||||||
|
@ -346,3 +348,5 @@ const error& linker::link(
|
||||||
delete old_tree_root;
|
delete old_tree_root;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,9 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class linker{
|
namespace nasal {
|
||||||
|
|
||||||
|
class linker {
|
||||||
private:
|
private:
|
||||||
bool show_path;
|
bool show_path;
|
||||||
bool lib_loaded;
|
bool lib_loaded;
|
||||||
|
@ -31,6 +33,7 @@ private:
|
||||||
std::vector<std::string> module_load_stack;
|
std::vector<std::string> module_load_stack;
|
||||||
std::vector<std::string> envpath;
|
std::vector<std::string> envpath;
|
||||||
|
|
||||||
|
private:
|
||||||
bool import_check(expr*);
|
bool import_check(expr*);
|
||||||
bool exist(const std::string&);
|
bool exist(const std::string&);
|
||||||
u16 find(const std::string&);
|
u16 find(const std::string&);
|
||||||
|
@ -53,3 +56,5 @@ public:
|
||||||
const auto& get_this_file() const {return this_file;}
|
const auto& get_this_file() const {return this_file;}
|
||||||
const auto& get_lib_path() const {return lib_path;}
|
const auto& get_lib_path() const {return lib_path;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "nasal_lexer.h"
|
#include "nasal_lexer.h"
|
||||||
#include "repl.h"
|
#include "repl.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
bool lexer::skip(char c) {
|
bool lexer::skip(char c) {
|
||||||
return c==' ' || c=='\n' || c=='\t' || c=='\r' || c==0;
|
return c==' ' || c=='\n' || c=='\t' || c=='\r' || c==0;
|
||||||
}
|
}
|
||||||
|
@ -372,3 +374,5 @@ const error& lexer::scan(const std::string& file) {
|
||||||
res = "";
|
res = "";
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#define S_ISREG(m) (((m)&0xF000)==0x8000)
|
#define S_ISREG(m) (((m)&0xF000)==0x8000)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
enum class tok:u32 {
|
enum class tok:u32 {
|
||||||
null=0, // null token (default token type)
|
null=0, // null token (default token type)
|
||||||
num, // number literal
|
num, // number literal
|
||||||
|
@ -182,3 +184,5 @@ public:
|
||||||
const error& scan(const std::string&);
|
const error& scan(const std::string&);
|
||||||
const std::vector<token>& result() const {return toks;}
|
const std::vector<token>& result() const {return toks;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "nasal_ast.h"
|
#include "nasal_ast.h"
|
||||||
#include "nasal_parse.h"
|
#include "nasal_parse.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
const error& parse::compile(const lexer& lexer) {
|
const error& parse::compile(const lexer& lexer) {
|
||||||
toks=lexer.result().data();
|
toks=lexer.result().data();
|
||||||
ptr=in_func=in_loop=0;
|
ptr=in_func=in_loop=0;
|
||||||
|
@ -1057,3 +1059,5 @@ return_expr* parse::return_expression() {
|
||||||
update_location(node);
|
update_location(node);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "nasal_lexer.h"
|
#include "nasal_lexer.h"
|
||||||
#include "nasal_err.h"
|
#include "nasal_err.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
class parse {
|
class parse {
|
||||||
|
|
||||||
#define thisspan (toks[ptr].loc)
|
#define thisspan (toks[ptr].loc)
|
||||||
|
@ -155,4 +157,6 @@ public:
|
||||||
}
|
}
|
||||||
const error& compile(const lexer&);
|
const error& compile(const lexer&);
|
||||||
static void easter_egg();
|
static void easter_egg();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "nasal_vm.h"
|
#include "nasal_vm.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
void vm::init(
|
void vm::init(
|
||||||
const std::vector<std::string>& strs,
|
const std::vector<std::string>& strs,
|
||||||
const std::vector<f64>& nums,
|
const std::vector<f64>& nums,
|
||||||
|
@ -442,3 +444,5 @@ mcallh: exec_nodie(o_mcallh); // -0
|
||||||
ret: exec_nodie(o_ret ); // -2
|
ret: exec_nodie(o_ret ); // -2
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#pragma warning (disable:4102)
|
#pragma warning (disable:4102)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
class vm {
|
class vm {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -954,4 +956,6 @@ inline void vm::o_ret() {
|
||||||
if (!ctx.pc) {
|
if (!ctx.pc) {
|
||||||
ngc.ctxreserve();
|
ngc.ctxreserve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "optimizer.h"
|
#include "optimizer.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
void optimizer::const_string(
|
void optimizer::const_string(
|
||||||
binary_operator* node,
|
binary_operator* node,
|
||||||
string_literal* left_node,
|
string_literal* left_node,
|
||||||
|
@ -129,4 +131,6 @@ bool optimizer::visit_unary_operator(unary_operator* node) {
|
||||||
|
|
||||||
void optimizer::do_optimization(code_block* root) {
|
void optimizer::do_optimization(code_block* root) {
|
||||||
root->accept(this);
|
root->accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include "nasal_ast.h"
|
#include "nasal_ast.h"
|
||||||
#include "ast_visitor.h"
|
#include "ast_visitor.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
class optimizer:public ast_visitor {
|
class optimizer:public ast_visitor {
|
||||||
private:
|
private:
|
||||||
void const_string(binary_operator*, string_literal*, string_literal*);
|
void const_string(binary_operator*, string_literal*, string_literal*);
|
||||||
|
@ -18,3 +20,5 @@ public:
|
||||||
public:
|
public:
|
||||||
void do_optimization(code_block*);
|
void do_optimization(code_block*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "nasal_codegen.h"
|
#include "nasal_codegen.h"
|
||||||
#include "nasal_vm.h"
|
#include "nasal_vm.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
namespace repl {
|
namespace repl {
|
||||||
|
|
||||||
std::string repl::readline(std::string prompt = ">>> ") {
|
std::string repl::readline(std::string prompt = ">>> ") {
|
||||||
|
@ -142,4 +143,5 @@ void repl::execute() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
namespace repl {
|
namespace repl {
|
||||||
|
|
||||||
struct info {
|
struct info {
|
||||||
|
@ -37,4 +38,5 @@ public:
|
||||||
void execute();
|
void execute();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "symbol_finder.h"
|
#include "symbol_finder.h"
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
bool symbol_finder::visit_definition_expr(definition_expr* node) {
|
bool symbol_finder::visit_definition_expr(definition_expr* node) {
|
||||||
if (node->get_variable_name()) {
|
if (node->get_variable_name()) {
|
||||||
symbols.push_back({
|
symbols.push_back({
|
||||||
|
@ -40,4 +42,6 @@ const std::vector<symbol_finder::symbol_info>& symbol_finder::do_find(code_block
|
||||||
symbols.clear();
|
symbols.clear();
|
||||||
root->accept(this);
|
root->accept(this);
|
||||||
return symbols;
|
return symbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace nasal {
|
||||||
|
|
||||||
class symbol_finder:public ast_visitor {
|
class symbol_finder:public ast_visitor {
|
||||||
public:
|
public:
|
||||||
struct symbol_info {
|
struct symbol_info {
|
||||||
|
@ -22,4 +24,6 @@ public:
|
||||||
bool visit_function(function*) override;
|
bool visit_function(function*) override;
|
||||||
bool visit_iter_expr(iter_expr*) override;
|
bool visit_iter_expr(iter_expr*) override;
|
||||||
const std::vector<symbol_finder::symbol_info>& do_find(code_block*);
|
const std::vector<symbol_finder::symbol_info>& do_find(code_block*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue