Skip to content

Commit

Permalink
Fixed static analysis and constant propagation of expressions.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@237 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x97davka committed Mar 31, 1998
1 parent 7216d61 commit 643deb8
Show file tree
Hide file tree
Showing 13 changed files with 819 additions and 352 deletions.
1 change: 1 addition & 0 deletions modeq/Makefile
Expand Up @@ -24,6 +24,7 @@ SRCRML= exp.rml \
builtin.rml \
connect.rml \
classinf.rml \
staticexp.rml \
inst.rml \
main.rml
SRCC= $(SRCRML:.rml=.c)
Expand Down
8 changes: 6 additions & 2 deletions modeq/ast/attrib.c
Expand Up @@ -8,7 +8,9 @@ int zzcr_attr(Attrib *attr, int type, char *text)
attr->type = type;
switch (type)
{
case UNSIGNED_NUMBER:
case UNSIGNED_INTEGER:
attr->u.ival = atoi(text); break;
case UNSIGNED_REAL:
attr->u.floatval = atof(text); break;
case IDENT:
attr->u.stringval = strdup(text);
Expand Down Expand Up @@ -62,7 +64,9 @@ void print_attr(Attrib *attr, FILE *f)
{
switch (attr->type)
{
case UNSIGNED_NUMBER:
case UNSIGNED_INTEGER:
fprintf(f, "%d", attr->u.ival); break;
case UNSIGNED_REAL:
fprintf(f, "%.2f", attr->u.floatval); break;
case IDENT:
fprintf(f, "'%s'", attr->u.stringval); break;
Expand Down
6 changes: 4 additions & 2 deletions modeq/ast/modgram.g
Expand Up @@ -169,7 +169,8 @@ extern void *sibling_list(AST *ast);

#token STRING "\"(~[\"])*\""

#token UNSIGNED_NUMBER "[0-9]+{\.[0-9]*}{[eE]{[\+\-]}[0-9]+}"
#token UNSIGNED_INTEGER "[0-9]+"
#token UNSIGNED_REAL "[0-9]+{\.[0-9]*}{[eE]{[\+\-]}[0-9]+}"

#token "[\ \t]+" << zzskip(); >>
#token "\n" << zzskip(); newline(); >>
Expand Down Expand Up @@ -680,7 +681,8 @@ primary : << bool is_matrix; >>
>>
RBRACK!

| nr:UNSIGNED_NUMBER << #nr->rml = Exp__NUMBER(mk_rcon($nr.u.floatval)); >>
| ni:UNSIGNED_INTEGER << #ni->rml = Exp__INTEGER(mk_icon($ni.u.ival)); >>
| nr:UNSIGNED_REAL << #nr->rml = Exp__REAL(mk_rcon($nr.u.floatval)); >>
| f:FALS/*E*/ << #f->rml = Exp__BOOL(RML_FALSE); >>
| t:TRU/*E*/ << #t->rml = Exp__BOOL(RML_TRUE); >>
| (name_path_function_arguments)?
Expand Down
69 changes: 33 additions & 36 deletions modeq/builtin.rml
Expand Up @@ -11,9 +11,12 @@ module Builtin:
val str_type : Explode.Class
val bool_type : Explode.Class

val real_type : Explode.Class

end

with "exp.rml"
with "types.rml"
with "mod.rml"
with "classinf.rml"

Expand All @@ -26,39 +29,33 @@ val str_type = Explode.CLASS("StringType",false,ClassInf.R_PREDEFINED,
val bool_type = Explode.CLASS("BooleanType",false,ClassInf.R_PREDEFINED,
Explode.PARTS([],[],[]))

(*
val real_type = Absyn.CLASS("Real",false,ClassInf.R_PREDEFINED,
Absyn.PARTS(
[Absyn.PUBLIC(
[Absyn.ELEMENT(true,"value",
Absyn.COMPONENTS(false, true, false,
false, false,
Exp.IDENT("RealType"),
[Absyn.COMPONENT("value",
NONE,
NONE)])),
Absyn.ELEMENT(true,"quantity",
Absyn.COMPONENTS(false, true, false,
false, false,
Exp.IDENT("StringType"),
[Absyn.COMPONENT("quantity",
NONE,
NONE)])),
Absyn.ELEMENT(true,"unit",
Absyn.COMPONENTS(false, true, false,
false, false,
Exp.IDENT("StringType"),
[Absyn.COMPONENT("unit",
NONE,
NONE)])),
Absyn.ELEMENT(true,"displayUnit",
Absyn.COMPONENTS(false, true, false,
false, false,
Exp.IDENT("StringType"),
[Absyn.COMPONENT("displayUnit",
NONE,
NONE)]))])]))
val real_type =
Explode.CLASS("Real",false,ClassInf.R_PREDEFINED,
Explode.PARTS
([Explode.ELEMENT(true,
false,
"value",
Explode.COMPONENT("value",
Types.ATTR(Types.NODIM,
false,
Types.VAR,
Types.BIDIR),
Exp.IDENT("RealType"),
Mod.NOMOD)),
(* quantity *)
Explode.ELEMENT(true,false,"unit",
Explode.COMPONENT("unit",
Types.ATTR(Types.NODIM,
false,
Types.VAR,
Types.BIDIR),
Exp.IDENT("StringType"),
Mod.NOMOD))],
(* displayUnit *)
[],
[]))

(*
val integer_type = Absyn.CLASS("Integer",false,ClassInf.R_PREDEFINED,
Absyn.PARTS(
[Absyn.PUBLIC(
Expand Down Expand Up @@ -108,11 +105,11 @@ relation initial_env =
Env.extend_frame_c(env, rl_type, Mod.NOMOD) => env' &
Env.extend_frame_c(env', int_type, Mod.NOMOD) => env'' &
Env.extend_frame_c(env'', str_type, Mod.NOMOD) => env''' &
Env.extend_frame_c(env'', bool_type, Mod.NOMOD) => env''''
(* Env.extend_frame_c(env, real_type) => env'''' &
Env.extend_frame_c(env, integer_type) => env''''' &
Env.extend_frame_c(env''', bool_type, Mod.NOMOD) => env'''' &
Env.extend_frame_c(env'''', real_type, Mod.NOMOD) => env'''''
(* Env.extend_frame_c(env, integer_type) => env''''' &
Env.extend_frame_c(env, string_type) => env'''''' *)
----------------------------------------------
initial_env () => env''''
initial_env () => env'''''

end
11 changes: 10 additions & 1 deletion modeq/classinf.rml
Expand Up @@ -41,6 +41,7 @@ module ClassInf :
relation start : (Restriction, string) => State
relation trans : (State, Event) => State
relation valid : (State, Restriction) => ()
relation assert_valid : (State, Restriction) => ()

end

Expand Down Expand Up @@ -223,9 +224,17 @@ relation valid : (State, Restriction) => () =
axiom valid(IS_NEW(s), R_FUNCTION)
axiom valid(FUNCTION(s), R_FUNCTION)

end

relation assert_valid : (State, Restriction) => () =

rule valid(st,re)
------------
assert_valid(st,re)

rule print "# Restriction violation: " & print_state st &
print " is not a " & print_restr re & print "\n"
-------------------------------------------
valid(st,re) => fail
assert_valid(st,re) => fail

end
2 changes: 1 addition & 1 deletion modeq/connect.rml
Expand Up @@ -284,7 +284,7 @@ relation flow_equations : (Exp.ComponentRef * Face) list => DAE.DAEcomp list =
------------------
flow_equations cs => [DAE.EQUATION(Exp.RELATION(sum,
Exp.EQUAL,
Exp.NUMBER(0.0)))]
Exp.REAL(0.0)))]

end

Expand Down
106 changes: 4 additions & 102 deletions modeq/dump.rml
Expand Up @@ -59,111 +59,13 @@ end

(* Exp *)

relation binop_symbol: Exp.BinOp => string =
axiom binop_symbol(Exp.ADD) => " + "
axiom binop_symbol(Exp.SUB) => " - "
axiom binop_symbol(Exp.MUL) => "*"
axiom binop_symbol(Exp.DIV) => "/"
axiom binop_symbol(Exp.POW) => "^"
end

relation unaryop_symbol: Exp.UnaryOp => string =
axiom unaryop_symbol(Exp.UMINUS) => "-"
axiom unaryop_symbol(Exp.UPLUS) => "+"
end

relation lbinop_symbol: Exp.LBinOp => string =
axiom lbinop_symbol(Exp.AND) => " AND "
axiom lbinop_symbol(Exp.OR) => " OR "
end

relation lunaryop_symbol: Exp.LUnaryOp => string =
axiom lunaryop_symbol(Exp.NOT) => "NOT "
end

relation relop_symbol: Exp.RelOp => string =
axiom relop_symbol(Exp.LESS) => " < "
axiom relop_symbol(Exp.LESSEQ) => " <= "
axiom relop_symbol(Exp.GREATER) => " > "
axiom relop_symbol(Exp.GREATEREQ) => " >= "
axiom relop_symbol(Exp.EQUAL) => " == "
axiom relop_symbol(Exp.NEQUAL) => " <> "
end

relation dump_exp: Exp.Exp => () =
rule real_string(x) => s &
print s
--------------
dump_exp(Exp.NUMBER(x))

rule dump_component_ref(c)
---------------------
dump_exp(Exp.CREF(c))

rule print "\"" & print s & print "\""
---------------------------------
dump_exp(Exp.STRING(s))
rule Exp.dump_exp e
--------------
dump_exp e

rule print "FALSE"
-------------
dump_exp(Exp.BOOL(false))

rule print "TRUE"
-------------
dump_exp(Exp.BOOL(true))

rule binop_symbol(op) => sym &
dump_exp e1 & print sym & dump_exp e2
----------------------------
dump_exp(Exp.BINARY(e1, op, e2))

rule unaryop_symbol(op) => sym &
print sym & dump_exp e
----------------------------
dump_exp(Exp.UNARY(op, e))

rule lbinop_symbol(op) => sym &
dump_exp e1 & print sym & dump_exp e2
----------------------------
dump_exp(Exp.LBINARY(e1, op, e2))

rule lunaryop_symbol(op) => sym &
print sym & dump_exp e
----------------------------
dump_exp(Exp.LUNARY(op, e))

rule relop_symbol(op) => sym &
dump_exp(e1) & print sym & dump_exp(e2)
---------------------------------------
dump_exp(Exp.RELATION(e1, op, e2))

rule print "IF " & dump_exp(c) &
print " THEN " & dump_exp(t) &
print " ELSE " & dump_exp(f)
----------------------------
dump_exp(Exp.IFEXP(c,t,f))

rule Exp.path_string(fcn) => fs &
print fs & print "(" & dump_list(args,dump_exp,",") & print ")"
---------------------------------------------
dump_exp(Exp.CALL(fcn, args))

(*
rule print "EQUATION " &
dump_exp lhs &
print " = " &
dump_exp rhs
------------------------
dump_exp(Exp.EQU(lhs, rhs))
*)
rule print "TIME"
------------------
dump_exp(Exp.TIME)

rule print "#UNKNOWN EXPRESSION#"
----------------------------------
dump_exp (_)
end
end

(* Class *)

Expand Down

0 comments on commit 643deb8

Please sign in to comment.