change name of enum:ast_hashmember->ast_pair, ast_new_iter->ast_iter
change ast_hashmember to ast_pair is because this type in fact is the same as std::pair<std::string,nasal_ref> in C++
This commit is contained in:
parent
baa4f5a258
commit
eaa54035ff
|
@ -14,7 +14,7 @@ enum ast_node
|
||||||
ast_func, // func keyword
|
ast_func, // func keyword
|
||||||
ast_hash, // hash, basic value type
|
ast_hash, // hash, basic value type
|
||||||
ast_vec, // vector, basic value type
|
ast_vec, // vector, basic value type
|
||||||
ast_hashmember, // elements in hashmap
|
ast_pair, // pair of key and value in hashmap
|
||||||
ast_call, // mark a sub-tree of calling an identifier
|
ast_call, // mark a sub-tree of calling an identifier
|
||||||
ast_callh, // id.name
|
ast_callh, // id.name
|
||||||
ast_callv, // id[index]
|
ast_callv, // id[index]
|
||||||
|
@ -49,7 +49,7 @@ enum ast_node
|
||||||
ast_forindex, // forindex keyword
|
ast_forindex, // forindex keyword
|
||||||
ast_foreach, // foreach keyword
|
ast_foreach, // foreach keyword
|
||||||
ast_while, // while
|
ast_while, // while
|
||||||
ast_new_iter, // iterator, used in forindex/foreach
|
ast_iter, // iterator, used in forindex/foreach
|
||||||
ast_conditional, // mark a sub-tree of conditional expression
|
ast_conditional, // mark a sub-tree of conditional expression
|
||||||
ast_if, // if keyword
|
ast_if, // if keyword
|
||||||
ast_elsif, // elsif keyword
|
ast_elsif, // elsif keyword
|
||||||
|
|
|
@ -294,7 +294,7 @@ void nasal_codegen::find_symbol(const nasal_ast& node)
|
||||||
find_symbol(node[1]);
|
find_symbol(node[1]);
|
||||||
}
|
}
|
||||||
// find iterator(foreach, forindex), check
|
// find iterator(foreach, forindex), check
|
||||||
else if(node.type()==ast_new_iter)
|
else if(node.type()==ast_iter)
|
||||||
add_sym(node[0].str());
|
add_sym(node[0].str());
|
||||||
// check children
|
// check children
|
||||||
else
|
else
|
||||||
|
@ -528,7 +528,7 @@ void nasal_codegen::call_func(const nasal_ast& ast)
|
||||||
{
|
{
|
||||||
if(!ast.size())
|
if(!ast.size())
|
||||||
gen(op_callfv,0,ast.line());
|
gen(op_callfv,0,ast.line());
|
||||||
else if(ast[0].type()==ast_hashmember)
|
else if(ast[0].type()==ast_pair)
|
||||||
{
|
{
|
||||||
hash_gen(ast);
|
hash_gen(ast);
|
||||||
gen(op_callfh,0,ast.line());
|
gen(op_callfh,0,ast.line());
|
||||||
|
@ -847,7 +847,7 @@ void nasal_codegen::forindex_gen(const nasal_ast& ast)
|
||||||
gen(op_cnt,0,ast[1].line());
|
gen(op_cnt,0,ast[1].line());
|
||||||
int ptr=code.size();
|
int ptr=code.size();
|
||||||
gen(op_findex,0,ast.line());
|
gen(op_findex,0,ast.line());
|
||||||
if(ast[0].type()==ast_new_iter)
|
if(ast[0].type()==ast_iter)
|
||||||
{
|
{
|
||||||
const std::string& str=ast[0][0].str();
|
const std::string& str=ast[0][0].str();
|
||||||
local.empty()?
|
local.empty()?
|
||||||
|
@ -875,7 +875,7 @@ void nasal_codegen::foreach_gen(const nasal_ast& ast)
|
||||||
gen(op_cnt,0,ast.line());
|
gen(op_cnt,0,ast.line());
|
||||||
int ptr=code.size();
|
int ptr=code.size();
|
||||||
gen(op_feach,0,ast.line());
|
gen(op_feach,0,ast.line());
|
||||||
if(ast[0].type()==ast_new_iter)
|
if(ast[0].type()==ast_iter)
|
||||||
{
|
{
|
||||||
const std::string& str=ast[0][0].str();
|
const std::string& str=ast[0][0].str();
|
||||||
local.empty()?
|
local.empty()?
|
||||||
|
|
|
@ -67,10 +67,8 @@ public:
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
if(!line)
|
if(!line)
|
||||||
{
|
|
||||||
std::cerr<<"["<<stage<<"] "<<file<<": "<<info<<'\n';
|
std::cerr<<"["<<stage<<"] "<<file<<": "<<info<<'\n';
|
||||||
return;
|
else
|
||||||
}
|
|
||||||
std::cerr<<"["<<stage<<"] "<<file<<":"<<line<<" "<<info<<"\n"<<res[line-1]<<'\n';
|
std::cerr<<"["<<stage<<"] "<<file<<":"<<line<<" "<<info<<"\n"<<res[line-1]<<'\n';
|
||||||
}
|
}
|
||||||
void chkerr(){if(error)std::exit(1);}
|
void chkerr(){if(error)std::exit(1);}
|
||||||
|
|
|
@ -22,9 +22,9 @@ bool nasal_import::check_import(const nasal_ast& node)
|
||||||
/*
|
/*
|
||||||
only this kind of node can be recognized as 'import':
|
only this kind of node can be recognized as 'import':
|
||||||
call
|
call
|
||||||
id:import
|
|_id:import
|
||||||
call_func
|
|_call_func
|
||||||
string:'filename'
|
|_string:'filename'
|
||||||
*/
|
*/
|
||||||
return (
|
return (
|
||||||
node.type()==ast_call &&
|
node.type()==ast_call &&
|
||||||
|
|
16
nasal_opt.h
16
nasal_opt.h
|
@ -20,14 +20,14 @@ void calc_const_num(nasal_ast& root)
|
||||||
double res;
|
double res;
|
||||||
switch(root.type())
|
switch(root.type())
|
||||||
{
|
{
|
||||||
case ast_add:res=vec[0].num()+vec[1].num();break;
|
case ast_add: res=vec[0].num()+vec[1].num(); break;
|
||||||
case ast_sub:res=vec[0].num()-vec[1].num();break;
|
case ast_sub: res=vec[0].num()-vec[1].num(); break;
|
||||||
case ast_mult:res=vec[0].num()*vec[1].num();break;
|
case ast_mult:res=vec[0].num()*vec[1].num(); break;
|
||||||
case ast_div:res=vec[0].num()/vec[1].num();break;
|
case ast_div: res=vec[0].num()/vec[1].num(); break;
|
||||||
case ast_less:res=vec[0].num()<vec[1].num();break;
|
case ast_less:res=vec[0].num()<vec[1].num(); break;
|
||||||
case ast_leq:res=vec[0].num()<=vec[1].num();break;
|
case ast_leq: res=vec[0].num()<=vec[1].num();break;
|
||||||
case ast_grt:res=vec[0].num()>vec[1].num();break;
|
case ast_grt: res=vec[0].num()>vec[1].num(); break;
|
||||||
case ast_geq:res=vec[0].num()>=vec[1].num();break;
|
case ast_geq: res=vec[0].num()>=vec[1].num();break;
|
||||||
}
|
}
|
||||||
if(std::isinf(res) || std::isnan(res)) // inf and nan will cause number hashmap error in codegen
|
if(std::isinf(res) || std::isnan(res)) // inf and nan will cause number hashmap error in codegen
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -63,7 +63,7 @@ private:
|
||||||
nasal_ast id();
|
nasal_ast id();
|
||||||
nasal_ast vec();
|
nasal_ast vec();
|
||||||
nasal_ast hash();
|
nasal_ast hash();
|
||||||
nasal_ast hmem();
|
nasal_ast pair();
|
||||||
nasal_ast func();
|
nasal_ast func();
|
||||||
nasal_ast args();
|
nasal_ast args();
|
||||||
nasal_ast lcurve_expr();
|
nasal_ast lcurve_expr();
|
||||||
|
@ -305,7 +305,7 @@ nasal_ast nasal_parse::hash()
|
||||||
match(tok_lbrace);
|
match(tok_lbrace);
|
||||||
while(tokens[ptr].type!=tok_rbrace)
|
while(tokens[ptr].type!=tok_rbrace)
|
||||||
{
|
{
|
||||||
node.add(hmem());
|
node.add(pair());
|
||||||
if(tokens[ptr].type==tok_comma)
|
if(tokens[ptr].type==tok_comma)
|
||||||
match(tok_comma);
|
match(tok_comma);
|
||||||
else if(tokens[ptr].type==tok_id || tokens[ptr].type==tok_str)// first set of hashmember
|
else if(tokens[ptr].type==tok_id || tokens[ptr].type==tok_str)// first set of hashmember
|
||||||
|
@ -316,9 +316,9 @@ nasal_ast nasal_parse::hash()
|
||||||
match(tok_rbrace,"expected \'}\' when generating hash");
|
match(tok_rbrace,"expected \'}\' when generating hash");
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::hmem()
|
nasal_ast nasal_parse::pair()
|
||||||
{
|
{
|
||||||
nasal_ast node(tokens[ptr].line,ast_hashmember);
|
nasal_ast node(tokens[ptr].line,ast_pair);
|
||||||
if(tokens[ptr].type==tok_id)
|
if(tokens[ptr].type==tok_id)
|
||||||
{
|
{
|
||||||
node.add(id());
|
node.add(id());
|
||||||
|
@ -715,7 +715,7 @@ nasal_ast nasal_parse::callf()
|
||||||
match(tok_lcurve);
|
match(tok_lcurve);
|
||||||
while(tokens[ptr].type!=tok_rcurve)
|
while(tokens[ptr].type!=tok_rcurve)
|
||||||
{
|
{
|
||||||
node.add(special_call?hmem():calc());
|
node.add(special_call?pair():calc());
|
||||||
if(tokens[ptr].type==tok_comma)
|
if(tokens[ptr].type==tok_comma)
|
||||||
match(tok_comma);
|
match(tok_comma);
|
||||||
else if(tokens[ptr].type==tok_eof)
|
else if(tokens[ptr].type==tok_eof)
|
||||||
|
@ -935,7 +935,7 @@ nasal_ast nasal_parse::iter_gen()
|
||||||
if(tokens[ptr].type==tok_var)
|
if(tokens[ptr].type==tok_var)
|
||||||
{
|
{
|
||||||
match(tok_var);
|
match(tok_var);
|
||||||
node.set_type(ast_new_iter);
|
node.set_type(ast_iter);
|
||||||
node.add(id());
|
node.add(id());
|
||||||
match(tok_id);
|
match(tok_id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue