Skip to content

Commit

Permalink
Added named arguments in functions to parser and absyn
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@788 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed May 8, 2002
1 parent ce2aa29 commit cf725c7
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
10 changes: 9 additions & 1 deletion modeq/absyn.rml
Expand Up @@ -200,7 +200,7 @@ module Absyn:
| LUNARY of Operator * Exp
| RELATION of Exp * Operator * Exp
| IFEXP of Exp * Exp * Exp
| CALL of ComponentRef * Exp list
| CALL of ComponentRef * FunctionArgs
(* | ARRAY of Exp list *)

(*P.R ARRAY consists of an vector of the dimension sizes and an vector consiting of the vector data.*)
Expand All @@ -212,6 +212,14 @@ module Absyn:

(** The `Exp' datatype is the container of a Modelica expression. *)

datatype FunctionArgs = FUNCTIONARGS of Exp list * NamedArg list
(** The `FunctionArgs' datatype consists of a list of positional arguments *)
(** followed by a list of named arguments (Modelica v2.0) *)

datatype NamedArg = NAMEDARG of Ident * Exp
(** The `NamedArg' datatype consist of an Identifier for the argument and an expression *)
(** giving the value of the argument *)

datatype Operator = ADD | SUB | MUL | DIV | POW
| UPLUS | UMINUS
| AND | OR
Expand Down
35 changes: 26 additions & 9 deletions modeq/absyn_builder/walker.g
Expand Up @@ -1356,26 +1356,43 @@ function_call returns [void* ast]

function_arguments returns [void* ast]
{
ast = 0;
l_stack el_stack;
void* e=0;
void* elist=0;
void* namel=0;
}
:
( ast = expression_list
| named_arguments // TODO: fix Absyn to handle named arguments
)?
(e = expression { el_stack.push(e); } )* (namel = named_arguments)?
{
if (!ast) ast = mk_nil();

elist = make_rml_list_from_stack(el_stack);
if (!namel) namel = mk_nil();
ast = Absyn__FUNCTIONARGS(elist,namel);
}
;

named_arguments :
named_argument (named_argument)*;
named_arguments returns [void* ast]
{
l_stack el_stack;
void* n;
}
:
(n = named_argument { el_stack.push(n); }) (n = named_argument { el_stack.push(n); } )*
{
ast = make_rml_list_from_stack(el_stack);
}
;

named_argument
named_argument returns [void* ast]
{
void* temp;
}
:
#(eq:EQUALS i:IDENT temp = expression);
#(eq:EQUALS i:IDENT temp = expression)
{
ast = Absyn__NAMEDARG(to_rml_str(i),temp);
}
;

expression_list returns [void* ast]
{
Expand Down
24 changes: 22 additions & 2 deletions modeq/dump.rml
Expand Up @@ -725,7 +725,8 @@ relation print_exp : Absyn.Exp => () =
print_exp(Absyn.IFEXP(c,t,f))

rule print_component_ref(fcn) &
print "(" & print_list_debug("print_exp",args,print_exp,",") & print ")"
print "(" &
print_function_args(args) & print ")"
---------------------------------------------
print_exp(Absyn.CALL(fcn, args))

Expand Down Expand Up @@ -763,7 +764,26 @@ relation print_exp : Absyn.Exp => () =
print_exp (_)
end

relation print_function_args: Absyn.FunctionArgs => () =

rule print "FUNCTIONARGS(" &
print_list_debug("print_exp",expargs,print_exp,", ")
print ", " &
print_list_debug("print_namedarg",nargs,print_named_arg,", ") &
print ")"
-------------------
print_function_args Absyn.FUNCTIONARGS(expargs,nargs)
end

relation print_named_arg: Absyn.NamedArg => () =
rule print ident &
print "=" &
print_exp(e)
------------
print_named_arg Absyn.NAMEDARG(ident,e)
end



(**)

Expand Down Expand Up @@ -853,7 +873,7 @@ relation print_exp_str : Absyn.Exp => string =
print_exp_str(Absyn.IFEXP(c,t,f)) => s''''

rule print_component_ref_str(fcn) => fs &
print_list_str(args,print_exp_str,",") => argstr &
let argstr = "not implemented yet" &
string_append(fs, "(") => s &
string_append(s, argstr) => s' &
string_append(s', ")") => s''
Expand Down
2 changes: 1 addition & 1 deletion modeq/inst.rml
Expand Up @@ -1199,7 +1199,7 @@ relation inst_equation : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
--------------------------------------------------------------
inst_equation(env,mods,pre,csets, ci_state,
SCode.EQ_EXPR(Absyn.CALL(Absyn.CREF_IDENT("assert",[]),
[e,Absyn.STRING(d)])))
Absyn.FUNCTIONARGS([e,Absyn.STRING(d)],[]))))
=> (dae,env,csets,ci_state')

(** Normal equations *)
Expand Down
15 changes: 12 additions & 3 deletions modeq/interactive.rml
Expand Up @@ -85,8 +85,12 @@ relation evaluate_graphical_api: (InteractiveStmts, InteractiveSymbolTable) =>
let newst = SYMBOLTABLE(newp,s,ic,iv) &
string_append(name,"\n") => resstr
---------------------------------------------------
evaluate_graphical_api(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("newModel",_),[Absyn.STRING(name)]))]),st as SYMBOLTABLE(p,s,ic,iv))
=> (resstr,newst)
evaluate_graphical_api(
ISTMTS([IEXP(Absyn.CALL(
Absyn.CREF_IDENT("newModel",_),
Absyn.FUNCTIONARGS([Absyn.STRING(name)],[])))]
),
st as SYMBOLTABLE(p,s,ic,iv)) => (resstr,newst)

rule componentref_to_path(cr) => path &
Absyn.update_program(
Expand All @@ -95,7 +99,12 @@ relation evaluate_graphical_api: (InteractiveStmts, InteractiveSymbolTable) =>
let newst = SYMBOLTABLE(newp,s,ic,iv) &
string_append(name,"\n") => resstr
---------------------------------------------------
evaluate_graphical_api(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("newModel",_),[Absyn.STRING(name),Absyn.CREF(cr)]))]), st as SYMBOLTABLE(p,s,ic,iv)) => (resstr,newst)
evaluate_graphical_api(
ISTMTS([IEXP(Absyn.CALL(
Absyn.CREF_IDENT("newModel",_),
Absyn.FUNCTIONARGS([Absyn.STRING(name),Absyn.CREF(cr)],[])))]
),
st as SYMBOLTABLE(p,s,ic,iv)) => (resstr,newst)

end

Expand Down
7 changes: 3 additions & 4 deletions modeq/staticexp.rml
Expand Up @@ -212,15 +212,14 @@ relation elab_exp : (Env.Env, Absyn.Exp) => (Exp.Exp, Properties) =
elab_exp (env,Absyn.IFEXP(e1,e2,e3)) => (e,prop)

(** Function calls *)
(** PA. Only positional arguments are elaborated for now.*)
(** TODO: Implement elaboration of named arguments. *)

rule Dump.print_component_ref_str fn => fnstr &
Debug.fprintl("setr", ["elab_exp_call: ",fnstr,"\n"]) &
elab_call(env,fn,args) => (e,prop)
-------------------------------------
elab_exp (env,Absyn.CALL(fn,args)) => (e,prop)



elab_exp (env,Absyn.CALL(fn,Absyn.FUNCTIONARGS(args,nargs))) => (e,prop)

(*PR. Get the properties for each expression in the tuple.
* Each expression has its own constflag.
Expand Down

0 comments on commit cf725c7

Please sign in to comment.