Commit e865e93c authored by John van Groningen's avatar John van Groningen
Browse files

allow 'else fail' for all if nodes on root or in

then or else part of such an if node, and not just for
if nodes on root or in else part of such if nodes
parent 14cb3e3f
...@@ -3668,6 +3668,25 @@ static int generate_code_for_push_node (NodeP node,int asp,int bsp,struct esc *e ...@@ -3668,6 +3668,25 @@ static int generate_code_for_push_node (NodeP node,int asp,int bsp,struct esc *e
#endif #endif
} }
#ifdef CLEAN2
int contains_fail (NodeP node_p)
{
while (node_p->node_kind==IfNode){
NodeP else_node_p;
else_node_p=node_p->node_arguments->arg_next->arg_next->arg_node;
while (else_node_p->node_kind==IfNode)
else_node_p=else_node_p->node_arguments->arg_next->arg_next->arg_node;
if (else_node_p->node_kind==NormalNode && else_node_p->node_symbol->symb_kind==fail_symb)
return 1;
node_p=node_p->node_arguments->arg_next->arg_node;
}
return 0;
}
#endif
int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,NodeDefP defs,StateP result_state_p, int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,NodeDefP defs,StateP result_state_p,
SavedNidStateS **save_states_p,AbNodeIdsP ab_node_ids_p) SavedNidStateS **save_states_p,AbNodeIdsP ab_node_ids_p)
{ {
...@@ -3719,11 +3738,13 @@ int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,No ...@@ -3719,11 +3738,13 @@ int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,No
return generate_code_for_root_node (node,asp,bsp,esc_p,defs,result_state_p,save_states_p,ab_node_ids_p); return generate_code_for_root_node (node,asp,bsp,esc_p,defs,result_state_p,save_states_p,ab_node_ids_p);
default: default:
{ {
#ifndef CLEAN2
NodeP else_node; NodeP else_node;
else_node=node; else_node=node;
while (else_node->node_kind==IfNode) while (else_node->node_kind==IfNode)
else_node=else_node->node_arguments->arg_next->arg_next->arg_node; else_node=else_node->node_arguments->arg_next->arg_next->arg_node;
#endif
return CodeRhsNodeDefs (node,defs,asp,bsp,save_states_p,*result_state_p,esc_p,ab_node_ids_p->a_node_ids, return CodeRhsNodeDefs (node,defs,asp,bsp,save_states_p,*result_state_p,esc_p,ab_node_ids_p->a_node_ids,
ab_node_ids_p->b_node_ids, ab_node_ids_p->b_node_ids,
...@@ -3732,7 +3753,11 @@ int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,No ...@@ -3732,7 +3753,11 @@ int generate_code_for_root_node (NodeP node,int asp,int bsp,struct esc *esc_p,No
#else #else
NULL, NULL,
#endif #endif
#ifdef CLEAN2
!contains_fail (node));
#else
!(else_node->node_kind==NormalNode && else_node->node_symbol->symb_kind==fail_symb)); !(else_node->node_kind==NormalNode && else_node->node_symbol->symb_kind==fail_symb));
#endif
} }
} }
} }
...@@ -1130,6 +1130,10 @@ static void CodeRootUpdateNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN ...@@ -1130,6 +1130,10 @@ static void CodeRootUpdateNode (Node root,NodeId rootid,int asp,int bsp,CodeGenN
} }
} }
#ifdef CLEAN2
extern int contains_fail (NodeP node_p);
#endif
static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP code_gen_node_ids_p,StateS resultstate,struct esc *esc_p) static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP code_gen_node_ids_p,StateS resultstate,struct esc *esc_p)
{ {
switch (root->node_kind){ switch (root->node_kind){
...@@ -1166,11 +1170,20 @@ static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP ...@@ -1166,11 +1170,20 @@ static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP
if (thenlab.lab_mod==NULL) if (thenlab.lab_mod==NULL)
GenLabelDefinition (&thenlab); GenLabelDefinition (&thenlab);
#ifdef CLEAN2
{
int needs_next_alt;
needs_next_alt=
#endif
CodeRhsNodeDefsAndRestoreNodeIdStates (then_arg->arg_node,root->node_then_node_defs,asp,bsp,resultstate,esc_p, CodeRhsNodeDefsAndRestoreNodeIdStates (then_arg->arg_node,root->node_then_node_defs,asp,bsp,resultstate,esc_p,
code_gen_node_ids_p->a_node_ids,code_gen_node_ids_p->b_node_ids, code_gen_node_ids_p->a_node_ids,code_gen_node_ids_p->b_node_ids,
root->node_else_node_id_ref_counts, root->node_else_node_id_ref_counts,
#ifdef CLEAN2
!contains_fail (then_arg->arg_node)
#else
True True
#endif
/* /*
code_gen_node_ids_p->doesnt_fail code_gen_node_ids_p->doesnt_fail
*/ */
...@@ -1186,9 +1199,18 @@ static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP ...@@ -1186,9 +1199,18 @@ static int CodeRootNode (Node root,NodeId rootid,int asp,int bsp,CodeGenNodeIdsP
return 1; return 1;
} else } else
return CodeRhsNodeDefsAndRestoreNodeIdStates (else_node,root->node_else_node_defs,asp,bsp,resultstate,esc_p, #ifdef CLEAN2
needs_next_alt = needs_next_alt |
#else
return
#endif
CodeRhsNodeDefsAndRestoreNodeIdStates (else_node,root->node_else_node_defs,asp,bsp,resultstate,esc_p,
code_gen_node_ids_p->a_node_ids,code_gen_node_ids_p->b_node_ids, code_gen_node_ids_p->a_node_ids,code_gen_node_ids_p->b_node_ids,
NULL,code_gen_node_ids_p->doesnt_fail); NULL,code_gen_node_ids_p->doesnt_fail);
#ifdef CLEAN2
return needs_next_alt;
}
#endif
} }
case NodeIdNode: case NodeIdNode:
if (rootid==NULL){ if (rootid==NULL){
......
...@@ -1719,6 +1719,10 @@ static NodeIdRefCountListP duplicate_node_id_ref_count_list (NodeIdRefCountListP ...@@ -1719,6 +1719,10 @@ static NodeIdRefCountListP duplicate_node_id_ref_count_list (NodeIdRefCountListP
return new_node_id_ref_count_list; return new_node_id_ref_count_list;
} }
#ifdef CLEAN2
extern int contains_fail (NodeP node_p);
#endif
static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCountListP *node_id_ref_count_list_p) static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCountListP *node_id_ref_count_list_p)
{ {
switch (node->node_kind){ switch (node->node_kind){
...@@ -1864,6 +1868,9 @@ static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCo ...@@ -1864,6 +1868,9 @@ static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCo
case GuardNode: case GuardNode:
return determine_failing_cases_and_adjust_ref_counts (node->node_arguments->arg_next->arg_node,node_id_ref_count_list_p); return determine_failing_cases_and_adjust_ref_counts (node->node_arguments->arg_next->arg_node,node_id_ref_count_list_p);
case IfNode: case IfNode:
#ifdef CLEAN2
return contains_fail (node);
#else
{ {
NodeP else_node; NodeP else_node;
...@@ -1873,6 +1880,7 @@ static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCo ...@@ -1873,6 +1880,7 @@ static int determine_failing_cases_and_adjust_ref_counts (NodeP node,NodeIdRefCo
return else_node->node_kind==NormalNode && else_node->node_symbol->symb_kind==fail_symb; return else_node->node_kind==NormalNode && else_node->node_symbol->symb_kind==fail_symb;
} }
#endif
default: default:
return False; return False;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment