Skip to content

Commit 92ddcaf

Browse files
committed
fixed bug 97
http://bug.modelicacommunity.org/show_bug.cgi?id=97 implemented elseif within if expression by constructing IFEXPs within else part. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2517 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent d0834b0 commit 92ddcaf

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Compiler/absyn_builder/walker.g

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,25 @@ tokens {
152152
}
153153
return l;
154154
}
155+
156+
void* fix_elseif(l_stack& s, void* elsePart)
157+
{
158+
// the stack SHOULD NOT BE EMPTY here!
159+
void *l = elsePart;
160+
161+
while (!s.empty())
162+
{
163+
void *cond = 0;
164+
void *then = 0;
165+
struct rml_struct* p = (struct rml_struct*)RML_UNTAGPTR(s.top());
166+
cond = p->data[0];
167+
then = p->data[1];
168+
l = Absyn__IFEXP(cond, then, l, mk_nil());
169+
free(p);
170+
s.pop();
171+
}
172+
return l;
173+
}
155174
156175
157176
struct type_prefix_t
@@ -1596,8 +1615,11 @@ if_expression returns [void* ast]
15961615
#(IF cond = expression
15971616
thenPart = expression (e=elseif_expression {el_stack.push(e);} )* elsePart = expression
15981617
{
1599-
elseifPart = make_rml_list_from_stack(el_stack);
1600-
ast = Absyn__IFEXP(cond,thenPart,elsePart,elseifPart);
1618+
elseifPart = mk_nil();
1619+
if (el_stack.empty()) // if stack is empty no elseif is there
1620+
ast = Absyn__IFEXP(cond,thenPart,elsePart,elseifPart);
1621+
else // if stack is NON empty then transform to if cond then if cond ... else expr
1622+
ast = Absyn__IFEXP(cond,thenPart,fix_elseif(el_stack, elsePart), elseifPart);
16011623
}
16021624
)
16031625
;

0 commit comments

Comments
 (0)