Skip to content

Commit 4924382

Browse files
committed
- Add parentheses around subscripted expressions in ExpressionDump when needed.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14923 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 179b3e8 commit 4924382

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

Compiler/FrontEnd/NFLookup.mo

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ algorithm
148148
SOME(Error.LOOKUP_FUNCTION_ERROR));
149149
end lookupFunctionName;
150150

151+
public function lookupUnresolvedSimpleName
152+
"Looks up a name and returns the unresolved entry from the environment."
153+
input String inName;
154+
input Env inEnv;
155+
output Entry outEntry;
156+
algorithm
157+
outEntry := matchcontinue(inName, inEnv)
158+
local
159+
Entry entry;
160+
Env env;
161+
162+
case (_, _)
163+
equation
164+
entry = NFEnv.lookupEntry(inName, inEnv);
165+
then
166+
entry;
167+
168+
else
169+
equation
170+
true = NFEnv.isScopeEncapsulated(inEnv);
171+
env = NFEnv.builtinScope(inEnv);
172+
entry = lookupUnresolvedSimpleName(inName, env);
173+
then
174+
entry;
175+
176+
end matchcontinue;
177+
end lookupUnresolvedSimpleName;
178+
151179
protected function lookupBuiltinType
152180
input String inName;
153181
input Env inEnv;
@@ -236,7 +264,7 @@ algorithm
236264
then
237265
(entry, env);
238266

239-
case (_, _)
267+
else
240268
equation
241269
true = NFEnv.isScopeEncapsulated(inEnv);
242270
env = NFEnv.builtinScope(inEnv);
@@ -259,7 +287,7 @@ algorithm
259287
(outEntry, outEnv) := lookupNameInPackage(inName, inEnv);
260288
end lookupFullyQualified;
261289

262-
protected function lookupInLocalScope
290+
public function lookupInLocalScope
263291
input String inName;
264292
input Env inEnv;
265293
output Entry outEntry;

Compiler/Template/ExpressionDumpTpl.tpl

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,18 @@ match exp
7575
let ty_str = dumpType(ty)
7676
'/*<%ty_str%>*/(<%exp_str%>)'
7777
case ASUB(__) then
78+
let needs_paren = parenthesizeSubExp(exp)
79+
let lparen = if needs_paren then "("
80+
let rparen = if needs_paren then ")"
7881
let exp_str = dumpExp(exp, stringDelimiter)
7982
let sub_str = dumpExpList(sub, stringDelimiter, ", ")
80-
'<%exp_str%>[<%sub_str%>]'
83+
'<%lparen%><%exp_str%><%rparen%>[<%sub_str%>]'
8184
case TSUB(__) then
85+
let needs_paren = parenthesizeSubExp(exp)
86+
let lparen = if needs_paren then "("
87+
let rparen = if needs_paren then ")"
8288
let exp_str = dumpExp(exp, stringDelimiter)
83-
'<%exp_str%>[<%ix%>]'
89+
'<%lparen%><%exp_str%><%rparen%>[<%ix%>]'
8490
case SIZE(__) then
8591
let exp_str = dumpExp(exp, stringDelimiter)
8692
let dim_str = match sz case SOME(dim) then ', <%dumpExp(dim, stringDelimiter)%>'
@@ -132,6 +138,25 @@ match exp
132138
else errorMsg("ExpressionDumpTpl.dumpExp: Unknown expression.")
133139
end dumpExp;
134140
141+
template parenthesizeSubExp(DAE.Exp exp)
142+
::=
143+
match exp
144+
case ICONST(__) then ""
145+
case RCONST(__) then ""
146+
case SCONST(__) then ""
147+
case BCONST(__) then ""
148+
case ENUM_LITERAL(__) then ""
149+
case CREF(__) then ""
150+
case CALL(__) then ""
151+
case ARRAY(__) then ""
152+
case MATRIX(__) then ""
153+
case TUPLE(__) then ""
154+
case CAST(__) then ""
155+
case SIZE(__) then ""
156+
case REDUCTION(__) then ""
157+
else "y"
158+
end parenthesizeSubExp;
159+
135160
template dumpExpList(list<DAE.Exp> expl, String stringDelimiter, String expDelimiter)
136161
::= (expl |> exp => dumpExp(exp, stringDelimiter) ;separator=expDelimiter)
137162
end dumpExpList;

0 commit comments

Comments
 (0)