issue #98 renaming of fields for consistency

pull/168/head
Dibyendu Majumdar 5 years ago
parent e2f91553b6
commit 5d03214477

@ -143,7 +143,7 @@ struct ast_node {
enum ast_node_type type; enum ast_node_type type;
union { union {
struct { struct {
struct ast_node_list *exprlist; struct ast_node_list *expr_list;
} return_stmt; } return_stmt;
struct { struct {
struct lua_symbol *symbol; struct lua_symbol *symbol;
@ -153,17 +153,17 @@ struct ast_node {
struct ast_node *label_stmt; /* Initially this will be NULL; set by a separate pass */ struct ast_node *label_stmt; /* Initially this will be NULL; set by a separate pass */
} goto_stmt; } goto_stmt;
struct { struct {
struct lua_symbol_list *vars; struct lua_symbol_list *var_list;
struct ast_node_list *exprlist; struct ast_node_list *expr_list;
} local_stmt; } local_stmt;
struct { struct {
struct ast_node_list *var_expr_list; /* Optional var expressions, comma separated */ struct ast_node_list *var_expr_list; /* Optional var expressions, comma separated */
struct ast_node_list *exr_list; /* Comma separated expressions */ struct ast_node_list *expr_list; /* Comma separated expressions */
} expression_stmt; /* Also covers assignments*/ } expression_stmt; /* Also covers assignments*/
struct { struct {
struct ast_node *name; /* base symbol to be looked up */ struct ast_node *name; /* base symbol to be looked up */
struct ast_node_list *selectors; /* Optional */ struct ast_node_list *selectors; /* Optional */
struct ast_node *methodname; /* Optional */ struct ast_node *method_name; /* Optional */
struct ast_node *function_expr; /* Function's AST */ struct ast_node *function_expr; /* Function's AST */
} function_stmt; } function_stmt;
struct { struct {
@ -187,7 +187,7 @@ struct ast_node {
} while_or_repeat_stmt; } while_or_repeat_stmt;
struct { struct {
struct lua_symbol_list *symbols; struct lua_symbol_list *symbols;
struct ast_node_list *expressions; struct ast_node_list *expr_list;
struct block_scope *for_body; struct block_scope *for_body;
struct ast_node_list *for_statement_list; /* statements in this block */ struct ast_node_list *for_statement_list; /* statements in this block */
} for_stmt; /* Used for both generic and numeric for loops */ } for_stmt; /* Used for both generic and numeric for loops */
@ -218,8 +218,8 @@ struct ast_node {
struct { struct {
struct var_type type; struct var_type type;
BinOpr binary_op; BinOpr binary_op;
struct ast_node *exprleft; struct ast_node *expr_left;
struct ast_node *exprright; struct ast_node *expr_right;
} binary_expr; } binary_expr;
struct { struct {
struct var_type type; struct var_type type;
@ -250,7 +250,7 @@ struct ast_node {
} suffixed_expr; } suffixed_expr;
struct { struct {
struct var_type type; struct var_type type;
TString *methodname; /* Optional methodname */ TString *method_name; /* Optional method_name */
struct ast_node_list *arg_list; /* Call arguments */ struct ast_node_list *arg_list; /* Call arguments */
} function_call_expr; } function_call_expr;
}; };

@ -622,7 +622,7 @@ static struct ast_node *parse_function_call(struct parser_state *parser, TString
LexState *ls = parser->ls; LexState *ls = parser->ls;
struct ast_node *call_expr = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0); struct ast_node *call_expr = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0);
call_expr->type = AST_FUNCTION_CALL_EXPR; call_expr->type = AST_FUNCTION_CALL_EXPR;
call_expr->function_call_expr.methodname = methodname; call_expr->function_call_expr.method_name = methodname;
call_expr->function_call_expr.arg_list = NULL; call_expr->function_call_expr.arg_list = NULL;
set_type(call_expr->function_call_expr.type, RAVI_TANY); set_type(call_expr->function_call_expr.type, RAVI_TANY);
switch (ls->t.token) { switch (ls->t.token) {
@ -940,8 +940,8 @@ static struct ast_node *parse_sub_expression(struct parser_state *parser, int li
struct ast_node *binexpr = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0); struct ast_node *binexpr = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0);
binexpr->type = AST_BINARY_EXPR; binexpr->type = AST_BINARY_EXPR;
binexpr->binary_expr.exprleft = expr; binexpr->binary_expr.expr_left = expr;
binexpr->binary_expr.exprright = exprright; binexpr->binary_expr.expr_right = exprright;
binexpr->binary_expr.binary_op = op; binexpr->binary_expr.binary_op = op;
expr = binexpr; // Becomes the left expr for next iteration expr = binexpr; // Becomes the left expr for next iteration
op = nextop; op = nextop;
@ -1071,11 +1071,11 @@ static void parse_fornum_statement(struct parser_state *parser, struct ast_node
add_symbol(parser->container, &stmt->for_stmt.symbols, new_local_symbol(parser, varname, RAVI_TANY, NULL)); add_symbol(parser->container, &stmt->for_stmt.symbols, new_local_symbol(parser, varname, RAVI_TANY, NULL));
checknext(ls, '='); checknext(ls, '=');
/* get the type of each expression */ /* get the type of each expression */
add_ast_node(parser->container, &stmt->for_stmt.expressions, parse_expression(parser)); /* initial value */ add_ast_node(parser->container, &stmt->for_stmt.expr_list, parse_expression(parser)); /* initial value */
checknext(ls, ','); checknext(ls, ',');
add_ast_node(parser->container, &stmt->for_stmt.expressions, parse_expression(parser)); /* limit */ add_ast_node(parser->container, &stmt->for_stmt.expr_list, parse_expression(parser)); /* limit */
if (testnext(ls, ',')) { if (testnext(ls, ',')) {
add_ast_node(parser->container, &stmt->for_stmt.expressions, parse_expression(parser)); /* optional step */ add_ast_node(parser->container, &stmt->for_stmt.expr_list, parse_expression(parser)); /* optional step */
} }
parse_forbody(parser, stmt, line, 1, 1); parse_forbody(parser, stmt, line, 1, 1);
} }
@ -1093,7 +1093,7 @@ static void parse_for_list(struct parser_state *parser, struct ast_node *stmt, T
nvars++; nvars++;
} }
checknext(ls, TK_IN); checknext(ls, TK_IN);
parse_expression_list(parser, &stmt->for_stmt.expressions); parse_expression_list(parser, &stmt->for_stmt.expr_list);
int line = ls->linenumber; int line = ls->linenumber;
parse_forbody(parser, stmt, line, nvars - 3, 0); parse_forbody(parser, stmt, line, nvars - 3, 0);
} }
@ -1106,7 +1106,7 @@ static struct ast_node *parse_for_statement(struct parser_state *parser, int lin
struct ast_node *stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0); struct ast_node *stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0);
stmt->type = AST_NONE; stmt->type = AST_NONE;
stmt->for_stmt.symbols = NULL; stmt->for_stmt.symbols = NULL;
stmt->for_stmt.expressions = NULL; stmt->for_stmt.expr_list = NULL;
stmt->for_stmt.for_body = NULL; stmt->for_stmt.for_body = NULL;
stmt->for_stmt.for_statement_list = NULL; stmt->for_stmt.for_statement_list = NULL;
new_scope(parser); // For the loop variables new_scope(parser); // For the loop variables
@ -1191,10 +1191,10 @@ static struct ast_node *parse_local_function_statement(struct parser_state *pars
end_function(parser); end_function(parser);
struct ast_node *stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0); struct ast_node *stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0);
stmt->type = AST_LOCAL_STMT; stmt->type = AST_LOCAL_STMT;
stmt->local_stmt.vars = NULL; stmt->local_stmt.var_list = NULL;
stmt->local_stmt.exprlist = NULL; stmt->local_stmt.expr_list = NULL;
add_symbol(parser->container, &stmt->local_stmt.vars, symbol); add_symbol(parser->container, &stmt->local_stmt.var_list, symbol);
add_ast_node(parser->container, &stmt->local_stmt.exprlist, function_ast); add_ast_node(parser->container, &stmt->local_stmt.expr_list, function_ast);
return stmt; return stmt;
} }
@ -1203,19 +1203,19 @@ static struct ast_node *parse_local_statement(struct parser_state *parser) {
/* stat -> LOCAL NAME {',' NAME} ['=' explist] */ /* stat -> LOCAL NAME {',' NAME} ['=' explist] */
struct ast_node *node = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0); struct ast_node *node = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0);
node->type = AST_LOCAL_STMT; node->type = AST_LOCAL_STMT;
node->local_stmt.vars = NULL; node->local_stmt.var_list = NULL;
node->local_stmt.exprlist = NULL; node->local_stmt.expr_list = NULL;
int nvars = 0; int nvars = 0;
do { do {
/* local name : type = value */ /* local name : type = value */
struct lua_symbol *symbol = declare_local_variable(parser); struct lua_symbol *symbol = declare_local_variable(parser);
add_symbol(parser->container, &node->local_stmt.vars, symbol); add_symbol(parser->container, &node->local_stmt.var_list, symbol);
nvars++; nvars++;
if (nvars >= MAXVARS) if (nvars >= MAXVARS)
luaX_syntaxerror(ls, "too many local variables"); luaX_syntaxerror(ls, "too many local variables");
} while (testnext(ls, ',')); } while (testnext(ls, ','));
if (testnext(ls, '=')) /* nexps = */ if (testnext(ls, '=')) /* nexps = */
parse_expression_list(parser, &node->local_stmt.exprlist); parse_expression_list(parser, &node->local_stmt.expr_list);
else { else {
/* nexps = 0; */ /* nexps = 0; */
; ;
@ -1231,14 +1231,14 @@ static struct ast_node *parse_function_name(struct parser_state *parser) {
struct ast_node *function_stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0); struct ast_node *function_stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0);
function_stmt->type = AST_FUNCTION_STMT; function_stmt->type = AST_FUNCTION_STMT;
function_stmt->function_stmt.function_expr = NULL; function_stmt->function_stmt.function_expr = NULL;
function_stmt->function_stmt.methodname = NULL; function_stmt->function_stmt.method_name = NULL;
function_stmt->function_stmt.selectors = NULL; function_stmt->function_stmt.selectors = NULL;
function_stmt->function_stmt.name = new_symbol_reference(parser); function_stmt->function_stmt.name = new_symbol_reference(parser);
while (ls->t.token == '.') { while (ls->t.token == '.') {
add_ast_node(parser->container, &function_stmt->function_stmt.selectors, parse_field_selector(parser)); add_ast_node(parser->container, &function_stmt->function_stmt.selectors, parse_field_selector(parser));
} }
if (ls->t.token == ':') { if (ls->t.token == ':') {
function_stmt->function_stmt.methodname = parse_field_selector(parser); function_stmt->function_stmt.method_name = parse_field_selector(parser);
} }
return function_stmt; return function_stmt;
} }
@ -1248,7 +1248,7 @@ static struct ast_node *parse_function_statement(struct parser_state *parser, in
/* funcstat -> FUNCTION funcname body */ /* funcstat -> FUNCTION funcname body */
luaX_next(ls); /* skip FUNCTION */ luaX_next(ls); /* skip FUNCTION */
struct ast_node *function_stmt = parse_function_name(parser); struct ast_node *function_stmt = parse_function_name(parser);
int ismethod = function_stmt->function_stmt.methodname != NULL; int ismethod = function_stmt->function_stmt.method_name != NULL;
struct ast_node *function_ast = new_function(parser); struct ast_node *function_ast = new_function(parser);
parse_function_body(parser, function_ast, ismethod, line); parse_function_body(parser, function_ast, ismethod, line);
end_function(parser); end_function(parser);
@ -1261,7 +1261,7 @@ static struct ast_node *parse_expression_statement(struct parser_state *parser)
struct ast_node *stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0); struct ast_node *stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0);
stmt->type = AST_EXPR_STMT; stmt->type = AST_EXPR_STMT;
stmt->expression_stmt.var_expr_list = NULL; stmt->expression_stmt.var_expr_list = NULL;
stmt->expression_stmt.exr_list = NULL; stmt->expression_stmt.expr_list = NULL;
LexState *ls = parser->ls; LexState *ls = parser->ls;
/* stat -> func | assignment */ /* stat -> func | assignment */
/* Until we see '=' we do not know if this is an assignment or expr list*/ /* Until we see '=' we do not know if this is an assignment or expr list*/
@ -1276,7 +1276,7 @@ static struct ast_node *parse_expression_statement(struct parser_state *parser)
current_list = NULL; current_list = NULL;
parse_expression_list(parser, &current_list); parse_expression_list(parser, &current_list);
} }
stmt->expression_stmt.exr_list = current_list; stmt->expression_stmt.expr_list = current_list;
// TODO Check that if not assignment then it is a function call // TODO Check that if not assignment then it is a function call
return stmt; return stmt;
} }
@ -1286,12 +1286,12 @@ static struct ast_node *parse_return_statement(struct parser_state *parser) {
/* stat -> RETURN [explist] [';'] */ /* stat -> RETURN [explist] [';'] */
struct ast_node *return_stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0); struct ast_node *return_stmt = dmrC_allocator_allocate(&parser->container->ast_node_allocator, 0);
return_stmt->type = AST_RETURN_STMT; return_stmt->type = AST_RETURN_STMT;
return_stmt->return_stmt.exprlist = NULL; return_stmt->return_stmt.expr_list = NULL;
if (block_follow(ls, 1) || ls->t.token == ';') if (block_follow(ls, 1) || ls->t.token == ';')
/* nret = 0*/; /* return no values */ /* nret = 0*/; /* return no values */
else { else {
/*nret = */ /*nret = */
parse_expression_list(parser, &return_stmt->return_stmt.exprlist); /* optional return values */ parse_expression_list(parser, &return_stmt->return_stmt.expr_list); /* optional return values */
} }
testnext(ls, ';'); /* skip optional semicolon */ testnext(ls, ';'); /* skip optional semicolon */
return return_stmt; return return_stmt;

@ -293,16 +293,16 @@ void raviA_print_ast_node(membuff_t *buf, struct ast_node *node, int level) {
break; break;
case AST_RETURN_STMT: { case AST_RETURN_STMT: {
printf_buf(buf, "%preturn\n", level); printf_buf(buf, "%preturn\n", level);
print_ast_node_list(buf, node->return_stmt.exprlist, level + 1, ","); print_ast_node_list(buf, node->return_stmt.expr_list, level + 1, ",");
break; break;
} }
case AST_LOCAL_STMT: { case AST_LOCAL_STMT: {
printf_buf(buf, "%plocal\n", level); printf_buf(buf, "%plocal\n", level);
printf_buf(buf, "%p%c\n", level, "[symbols]"); printf_buf(buf, "%p%c\n", level, "[symbols]");
print_symbol_list(buf, node->local_stmt.vars, level + 1, ","); print_symbol_list(buf, node->local_stmt.var_list, level + 1, ",");
if (node->local_stmt.exprlist) { if (node->local_stmt.expr_list) {
printf_buf(buf, "%p%c\n", level, "[expressions]"); printf_buf(buf, "%p%c\n", level, "[expressions]");
print_ast_node_list(buf, node->local_stmt.exprlist, level + 1, ","); print_ast_node_list(buf, node->local_stmt.expr_list, level + 1, ",");
} }
break; break;
} }
@ -312,9 +312,9 @@ void raviA_print_ast_node(membuff_t *buf, struct ast_node *node, int level) {
printf_buf(buf, "%p%c\n", level + 1, "[selectors]"); printf_buf(buf, "%p%c\n", level + 1, "[selectors]");
print_ast_node_list(buf, node->function_stmt.selectors, level + 2, NULL); print_ast_node_list(buf, node->function_stmt.selectors, level + 2, NULL);
} }
if (node->function_stmt.methodname) { if (node->function_stmt.method_name) {
printf_buf(buf, "%p%c\n", level + 1, "[method name]"); printf_buf(buf, "%p%c\n", level + 1, "[method name]");
raviA_print_ast_node(buf, node->function_stmt.methodname, level + 2); raviA_print_ast_node(buf, node->function_stmt.method_name, level + 2);
} }
printf_buf(buf, "%p=\n", level + 1); printf_buf(buf, "%p=\n", level + 1);
raviA_print_ast_node(buf, node->function_stmt.function_expr, level + 2); raviA_print_ast_node(buf, node->function_stmt.function_expr, level + 2);
@ -342,7 +342,7 @@ void raviA_print_ast_node(membuff_t *buf, struct ast_node *node, int level) {
printf_buf(buf, "%p= %c\n", level + 1, "[var list end]"); printf_buf(buf, "%p= %c\n", level + 1, "[var list end]");
} }
printf_buf(buf, "%p%c\n", level + 1, "[expression list start]"); printf_buf(buf, "%p%c\n", level + 1, "[expression list start]");
print_ast_node_list(buf, node->expression_stmt.exr_list, level + 2, ","); print_ast_node_list(buf, node->expression_stmt.expr_list, level + 2, ",");
printf_buf(buf, "%p%c\n", level + 1, "[expression list end]"); printf_buf(buf, "%p%c\n", level + 1, "[expression list end]");
printf_buf(buf, "%p%c\n", level, "[expression statement end]"); printf_buf(buf, "%p%c\n", level, "[expression statement end]");
break; break;
@ -389,7 +389,7 @@ void raviA_print_ast_node(membuff_t *buf, struct ast_node *node, int level) {
printf_buf(buf, "%pfor\n", level); printf_buf(buf, "%pfor\n", level);
print_symbol_list(buf, node->for_stmt.symbols, level + 1, ","); print_symbol_list(buf, node->for_stmt.symbols, level + 1, ",");
printf_buf(buf, "%pin\n", level); printf_buf(buf, "%pin\n", level);
print_ast_node_list(buf, node->for_stmt.expressions, level + 1, ","); print_ast_node_list(buf, node->for_stmt.expr_list, level + 1, ",");
printf_buf(buf, "%pdo\n", level); printf_buf(buf, "%pdo\n", level);
print_statement_list(buf, node->for_stmt.for_statement_list, level + 1); print_statement_list(buf, node->for_stmt.for_statement_list, level + 1);
printf_buf(buf, "%pend\n", level); printf_buf(buf, "%pend\n", level);
@ -399,7 +399,7 @@ void raviA_print_ast_node(membuff_t *buf, struct ast_node *node, int level) {
printf_buf(buf, "%pfor\n", level); printf_buf(buf, "%pfor\n", level);
print_symbol_list(buf, node->for_stmt.symbols, level + 1, NULL); print_symbol_list(buf, node->for_stmt.symbols, level + 1, NULL);
printf_buf(buf, "%p=\n", level); printf_buf(buf, "%p=\n", level);
print_ast_node_list(buf, node->for_stmt.expressions, level + 1, ","); print_ast_node_list(buf, node->for_stmt.expr_list, level + 1, ",");
printf_buf(buf, "%pdo\n", level); printf_buf(buf, "%pdo\n", level);
print_statement_list(buf, node->for_stmt.for_statement_list, level + 1); print_statement_list(buf, node->for_stmt.for_statement_list, level + 1);
printf_buf(buf, "%pend\n", level); printf_buf(buf, "%pend\n", level);
@ -420,8 +420,8 @@ void raviA_print_ast_node(membuff_t *buf, struct ast_node *node, int level) {
} }
case AST_FUNCTION_CALL_EXPR: { case AST_FUNCTION_CALL_EXPR: {
printf_buf(buf, "%p%c\n", level, "[function call start]"); printf_buf(buf, "%p%c\n", level, "[function call start]");
if (node->function_call_expr.methodname) { if (node->function_call_expr.method_name) {
printf_buf(buf, "%p: %t (\n", level + 1, node->function_call_expr.methodname); printf_buf(buf, "%p: %t (\n", level + 1, node->function_call_expr.method_name);
} }
else { else {
printf_buf(buf, "%p(\n", level + 1); printf_buf(buf, "%p(\n", level + 1);
@ -437,9 +437,9 @@ void raviA_print_ast_node(membuff_t *buf, struct ast_node *node, int level) {
} }
case AST_BINARY_EXPR: { case AST_BINARY_EXPR: {
printf_buf(buf, "%p%c %T\n", level, "[binary expr start]", &node->binary_expr.type); printf_buf(buf, "%p%c %T\n", level, "[binary expr start]", &node->binary_expr.type);
raviA_print_ast_node(buf, node->binary_expr.exprleft, level + 1); raviA_print_ast_node(buf, node->binary_expr.expr_left, level + 1);
printf_buf(buf, "%p%s\n", level, get_binary_opr_str(node->binary_expr.binary_op)); printf_buf(buf, "%p%s\n", level, get_binary_opr_str(node->binary_expr.binary_op));
raviA_print_ast_node(buf, node->binary_expr.exprright, level + 1); raviA_print_ast_node(buf, node->binary_expr.expr_right, level + 1);
printf_buf(buf, "%p%c\n", level, "[binary expr end]"); printf_buf(buf, "%p%c\n", level, "[binary expr end]");
break; break;
} }

@ -72,8 +72,8 @@ static void typecheck_unaryop(struct ast_node *function, struct ast_node *node)
/* Type checker - WIP */ /* Type checker - WIP */
static void typecheck_binaryop(struct ast_node *function, struct ast_node *node) { static void typecheck_binaryop(struct ast_node *function, struct ast_node *node) {
BinOpr op = node->binary_expr.binary_op; BinOpr op = node->binary_expr.binary_op;
struct ast_node *e1 = node->binary_expr.exprleft; struct ast_node *e1 = node->binary_expr.expr_left;
struct ast_node *e2 = node->binary_expr.exprright; struct ast_node *e2 = node->binary_expr.expr_right;
typecheck_ast_node(function, e1); typecheck_ast_node(function, e1);
typecheck_ast_node(function, e2); typecheck_ast_node(function, e2);
switch (op) { switch (op) {
@ -200,7 +200,7 @@ static void typecheck_ast_node(struct ast_node *function, struct ast_node *node)
case AST_NONE: case AST_NONE:
break; break;
case AST_RETURN_STMT: { case AST_RETURN_STMT: {
typecheck_ast_list(function, node->return_stmt.exprlist); typecheck_ast_list(function, node->return_stmt.expr_list);
break; break;
} }
case AST_LOCAL_STMT: { case AST_LOCAL_STMT: {
@ -247,7 +247,7 @@ static void typecheck_ast_node(struct ast_node *function, struct ast_node *node)
break; break;
} }
case AST_FUNCTION_CALL_EXPR: { case AST_FUNCTION_CALL_EXPR: {
if (node->function_call_expr.methodname) { if (node->function_call_expr.method_name) {
} }
else { else {
} }

Loading…
Cancel
Save