Skip to content

Commit

Permalink
reference type variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiguti committed Jul 29, 2012
1 parent a052427 commit 45cfb71
Show file tree
Hide file tree
Showing 12 changed files with 583 additions and 9,160 deletions.
113 changes: 81 additions & 32 deletions pxc/checktype.cpp
Expand Up @@ -29,6 +29,7 @@
#define DBG_LV(x) #define DBG_LV(x)
#define DBG_SLICE(x) #define DBG_SLICE(x)
#define DBG_ASGN(x) #define DBG_ASGN(x)
#define DBG_STT(x)


namespace pxc { namespace pxc {


Expand Down Expand Up @@ -689,51 +690,67 @@ void expr_extval::check_type(symbol_table *lookup)
/* type_of_this_expr */ /* type_of_this_expr */
} }


static void build_asgnstmt_list(asgnstmt_list& lst, expr_i *top, expr_i *e) static int get_next_bid(asgnstmt_list& lst)
{
if (lst.empty()) {
return 0;
}
return lst.back().blockcond_id + 1;
}

static void build_asgnstmt_list(asgnstmt_list& lst, int bid, expr_i *top,
expr_i *e)
{ {
if (e == 0) { if (e == 0) {
return; return;
} }
if (e->get_esort() == expr_e_block) { if (!e->has_expr_to_emit()) {
return; return;
} }
const int num_children = e->get_num_children(); if (!e->single_asgnstmt()) {
for (int i = 0; i < num_children; ++i) { const int num_children = e->get_num_children();
build_asgnstmt_list(lst, top, e->get_child(i)); for (int i = 0; i < num_children; ++i) {
} build_asgnstmt_list(lst, bid, top, e->get_child(i));
if (e->asgnstmt_top) { }
return; /* set by a child */ if (e->get_esort() == expr_e_var) {
} expr_i *p = e->parent_expr;
if (e->get_esort() == expr_e_var) { assert(p);
expr_i *p = e->parent_expr; expr_op *op = dynamic_cast<expr_op *>(p);
assert(p); if (op != 0 && op->op == '=' && op->arg0 == e) {
expr_op *op = dynamic_cast<expr_op *>(p); /* e is the lhs of var x = ... */
if (op != 0 && op->op == '=' && op->arg0 == e) { } else {
/* e is the lhs of var x = ... */ /* e is a var definithion without explicit initialization */
p->asgnstmt_top = true; /* set parent's asgnstmt_top */ e->asgnstmt_top = true;
asgnstmt ast(p, asgnstmt_e_var_defset); asgnstmt ast(e, asgnstmt_e_var_def, bid);
lst.push_back(ast); lst.push_back(ast);
DBG_ASGN(fprintf(stderr, "asgn var_defset %s\n", p->dump(0).c_str())); DBG_ASGN(fprintf(stderr, "asgn var_def %s\n", e->dump(0).c_str()));
} else { }
/* e is a var definithion without explicit initialization */ }
if (e->get_esort() == expr_e_op) {
expr_op *op = ptr_down_cast<expr_op>(e);
if (op->op == '=' && op->arg0->get_esort() == expr_e_var) {
/* var x = ... */
e->asgnstmt_top = true; /* set parent's asgnstmt_top */
asgnstmt ast(e, asgnstmt_e_var_defset, bid);
lst.push_back(ast);
DBG_ASGN(fprintf(stderr, "asgn var_defset %s\n", e->dump(0).c_str()));
}
}
if (e->tempvar_id >= 0) {
e->asgnstmt_top = true; e->asgnstmt_top = true;
asgnstmt ast(e, asgnstmt_e_var_def); asgnstmt ast(e, e->tempvar_varinfo.scope_block
? asgnstmt_e_blockscope_tempvar : asgnstmt_e_stmtscope_tempvar,
bid);
lst.push_back(ast); lst.push_back(ast);
DBG_ASGN(fprintf(stderr, "asgn var_def %s\n", e->dump(0).c_str())); DBG_ASGN(fprintf(stderr, "asgn var_tmpvar %s\n", e->dump(0).c_str()));
} }
return;
} }
if (e->tempvar_id >= 0) { if (e->asgnstmt_top) {
e->asgnstmt_top = true;
asgnstmt ast(e, e->tempvar_varinfo.scope_block
? asgnstmt_e_blockscope_tempvar : asgnstmt_e_stmtscope_tempvar);
lst.push_back(ast);
DBG_ASGN(fprintf(stderr, "asgn var_tmpvar %s\n", e->dump(0).c_str()));
return; return;
} }
if (e == top) { if (e == top) {
e->asgnstmt_top = true; e->asgnstmt_top = true;
asgnstmt ast(e, asgnstmt_e_other); asgnstmt ast(e, asgnstmt_e_other, bid);
lst.push_back(ast); lst.push_back(ast);
DBG_ASGN(fprintf(stderr, "asgn var_other %s\n", e->dump(0).c_str())); DBG_ASGN(fprintf(stderr, "asgn var_other %s\n", e->dump(0).c_str()));
} }
Expand All @@ -743,7 +760,17 @@ void expr_stmts::check_type(symbol_table *lookup)
{ {
fn_check_type(head, lookup); fn_check_type(head, lookup);
fn_check_type(rest, lookup); fn_check_type(rest, lookup);
build_asgnstmt_list(this->asts, head, head); const int bids = head->get_num_blockcond();
if (bids == 0) {
build_asgnstmt_list(this->asts, -1, head, head);
#if 0
} else {
for (int i = 0; i < bids; ++i) {
expr_i *const c = head->get_child(i);
build_asgnstmt_list(this->asts, i, c, c);
}
#endif
}
switch (head->get_esort()) { switch (head->get_esort()) {
case expr_e_int_literal: case expr_e_int_literal:
case expr_e_float_literal: case expr_e_float_literal:
Expand Down Expand Up @@ -910,6 +937,9 @@ static void store_tempvar(expr_i *e, passby_e passby, bool blockscope_flag,
// } // }
abort(); // FIXME FIXME FIXME HERE HERE HERE abort(); // FIXME FIXME FIXME HERE HERE HERE
} }
DBG_STT(fprintf(stderr, "store_tempvar passby=%d blocksc=%d g=%d %s\n",
(int)passby, (int)blockscope_flag, (int)guard_elements,
e->dump(0).c_str()));
if (e->tempvar_id < 0) { if (e->tempvar_id < 0) {
symbol_table *lookup = find_current_symbol_table(e); symbol_table *lookup = find_current_symbol_table(e);
assert(lookup); assert(lookup);
Expand Down Expand Up @@ -1824,6 +1854,11 @@ void expr_if::check_type(symbol_table *lookup)
rest = 0; rest = 0;
} }
} }
expr_stmts *const stmts = ptr_down_cast<expr_stmts>(
find_parent(this, expr_e_stmts));
this->bid_offset = get_next_bid(stmts->asts);
/* nonzero if there is an else-if */
build_asgnstmt_list(stmts->asts, this->bid_offset, cond, cond);
fn_check_type(block1, lookup); fn_check_type(block1, lookup);
fn_check_type(block2, lookup); fn_check_type(block2, lookup);
fn_check_type(rest, lookup); fn_check_type(rest, lookup);
Expand All @@ -1833,6 +1868,10 @@ void expr_while::check_type(symbol_table *lookup)
{ {
fn_check_type(cond, lookup); fn_check_type(cond, lookup);
check_bool_expr(0, cond); check_bool_expr(0, cond);
expr_stmts *const stmts = ptr_down_cast<expr_stmts>(
find_parent(this, expr_e_stmts));
this->bid_offset = get_next_bid(stmts->asts); /* always 0 */
build_asgnstmt_list(stmts->asts, this->bid_offset, cond, cond);
fn_check_type(block, lookup); fn_check_type(block, lookup);
} }


Expand All @@ -1841,6 +1880,12 @@ void expr_for::check_type(symbol_table *lookup)
fn_check_type(e0, lookup); fn_check_type(e0, lookup);
fn_check_type(e1, lookup); fn_check_type(e1, lookup);
fn_check_type(e2, lookup); fn_check_type(e2, lookup);
expr_stmts *const stmts = ptr_down_cast<expr_stmts>(
find_parent(this, expr_e_stmts));
this->bid_offset = get_next_bid(stmts->asts); /* always 0 */
build_asgnstmt_list(stmts->asts, this->bid_offset + 0, e0, e0);
build_asgnstmt_list(stmts->asts, this->bid_offset + 1, e1, e1);
build_asgnstmt_list(stmts->asts, this->bid_offset + 2, e2, e2);
fn_check_type(block, lookup); fn_check_type(block, lookup);
} }


Expand Down Expand Up @@ -1878,6 +1923,10 @@ void expr_feach::check_type(symbol_table *lookup)
} else { } else {
root_expr_reference_or_value(ce); root_expr_reference_or_value(ce);
} }
expr_stmts *const stmts = ptr_down_cast<expr_stmts>(
find_parent(this, expr_e_stmts));
this->bid_offset = get_next_bid(stmts->asts); /* always 0 */
build_asgnstmt_list(stmts->asts, this->bid_offset, ce, ce);
} }


static expr_i *deep_clone_expr(expr_i *e) static expr_i *deep_clone_expr(expr_i *e)
Expand Down

0 comments on commit 45cfb71

Please sign in to comment.