Skip to content

Commit

Permalink
Added external functions to Absyn. Added type convert of vector const…
Browse files Browse the repository at this point in the history
…ructors (RANGE)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@858 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Oct 4, 2002
1 parent e252e7d commit 22ea4a3
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 12 deletions.
13 changes: 11 additions & 2 deletions modeq/absyn.rml
Expand Up @@ -78,10 +78,12 @@ module Absyn:
| PROTECTED of ElementItem list
| EQUATIONS of EquationItem list
| ALGORITHMS of Algorithm list
| EXTERNAL of ExternalDecl
(** A class definition contains several parts. There are public and *)
(** protected component declarations, type definitions and `extends' *)
(** clauses, collectively called elements. There are also equation *)
(** sections and algorithm sections. *)
(** sections and algorithm sections. The EXTERNAL part is used only by functions *)
(** which can be declared as external C or FORTRAN functions. *)
(** - ElementList *)

datatype ElementItem = ELEMENTITEM of Element
Expand Down Expand Up @@ -280,7 +282,14 @@ module Absyn:
(** Annotation *)
datatype Annotation = ANNOTATION of ElementArg list
(** An Annotation is a class_modification. *)


(* ExternalDecl *)
datatype ExternalDecl = EXTERNALDECL of
Ident * (* The name of the external function *)
string option * (* Lanugage of the external function *)
ComponentRef option * (* ouput parameter as return value*)
Exp list (* only positional arguments, i.e. expression list*)

relation element_spec_name : ElementSpec => Ident
relation cref_to_path : ComponentRef => Path
relation path_to_cref : Path => ComponentRef
Expand Down
35 changes: 25 additions & 10 deletions modeq/absyn_builder/walker.g
Expand Up @@ -243,9 +243,12 @@ composition returns [void* ast]
el_stack.push(el);
}
)*
( EXTERNAL ( language_specification )?
( external_function_call )?
( EXTERNAL
( el = external_function_call )?
( ann = annotation)?
{
el_stack.push(el);
}
)?
{
ast = make_rml_list_from_stack(el_stack);
Expand Down Expand Up @@ -280,19 +283,31 @@ protected_element_list returns [void* ast]
}
;

language_specification :
s:STRING ;

external_function_call :
external_function_call returns [void* ast]
{
void* temp;
void* temp2;
void* temp3;
void* temp=0;
void* temp2=0;
void* temp3=0;
void *lang;
}
:
(s:STRING)?
#(EXTERNAL_FUNCTION_CALL
(
(i:IDENT (temp = expression_list)?)
|#(e:EQUALS temp2 = component_reference i2:IDENT ( temp3 = expression_list)?)
{
if (s != NULL) { lang = mk_some(to_rml_str(s)); }
else { lang = mk_none(); }
if (!temp) { temp = mk_nil(); }
ast = Absyn__EXTERNAL(Absyn__EXTERNALDECL(to_rml_str(i),lang,mk_none(),temp));
}
| #(e:EQUALS temp2 = component_reference i2:IDENT ( temp3 = expression_list)?)
{
if (s != NULL) { lang = mk_some(to_rml_str(s)); }
else { lang = mk_none(); }
if (!temp2) { temp2 = mk_nil(); }
ast = Absyn__EXTERNAL(Absyn__EXTERNALDECL(to_rml_str(i2),lang,mk_some(temp2),temp3));
}
)
)
;
Expand Down
22 changes: 22 additions & 0 deletions modeq/dump.rml
Expand Up @@ -77,6 +77,7 @@ end
with "classinf.rml"
with "rtopts.rml"
with "print.rml"
with "util.rml"

(* Relations *)

Expand Down Expand Up @@ -351,6 +352,23 @@ relation unparse_class_part_str: Absyn.ClassPart => string =
string_append("public \n",s1) => str
--------------------------------------
unparse_class_part_str(Absyn.ALGORITHMS(eqs)) => str

rule get_option_str(lang,identity) => langstr &
print_component_ref_str output => outputstr &
print_list_str(expl,print_exp_str,",") => expstr &
string_append(langstr," ") => s1 &
Util.string_append_list(["\nexternal ",langstr," ", outputstr, "=",ident,"(",expstr,");\n"]) => str
--------------------------------------
unparse_class_part_str(Absyn.EXTERNAL(Absyn.EXTERNALDECL(ident,lang,SOME(output),expl)))
=> str

rule get_option_str(lang,identity) => langstr &
print_list_str(expl,print_exp_str,",") => expstr &
string_append(langstr," ") => s1 &
Util.string_append_list(["\nexternal ", langstr," ",ident,"(",expstr,");\n"]) => str
--------------------------------------
unparse_class_part_str(Absyn.EXTERNAL(Absyn.EXTERNALDECL(ident,lang,NONE,expl)))
=> str
end

(**)
Expand Down Expand Up @@ -1570,6 +1588,10 @@ relation get_option_str: ('a option, 'a => string) => string =
axiom get_option_str(NONE,_) => ""
end

relation identity: ('a) => 'a =
axiom identity(x) => x
end

relation print_bool_str : bool => string =

rule select_string (b, "true", "false") => s
Expand Down
6 changes: 6 additions & 0 deletions modeq/interactive.rml
Expand Up @@ -139,6 +139,12 @@ relation evaluate: (InteractiveStmts, InteractiveSymbolTable) => (string,Intera
evaluate(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("setCompilerFlags",_),Absyn.FUNCTIONARGS([ Absyn.STRING(str)],[])))]),st as SYMBOLTABLE(p,_,_,_))
=> ("Ok\n",st)

rule Print.get_string() => str &
Print.clear_buf() => ()
--------------------------
evaluate(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("getErrorMsg",_),Absyn.FUNCTIONARGS([],[])))]),st as SYMBOLTABLE(p,_,_,_))
=> (str,st)

rule evaluate_graphical_api(stmts,st) => (str,newst)
----------------------------------------------------
evaluate(stmts as ISTMTS([IEXP(Absyn.CALL(_,_))]),st) => (str,newst)
Expand Down
23 changes: 23 additions & 0 deletions modeq/staticexp.rml
Expand Up @@ -2584,6 +2584,29 @@ relation type_convert : (Exp.Exp, Types.Type, Types.Type) => (Exp.Exp, Types.Typ
Types.T_ARRAY(Types.DIM(SOME(dim2)), ty2))
=> (Exp.ARRAY(at,a,elist'),Types.T_ARRAY(Types.DIM(SOME(dim1)),ty2))

rule int_eq (dim1, dim2) => true &
type_convert(begin,ty1,ty2) => (begin',_) &
type_convert(step,ty1,ty2) => (step',_) &
type_convert(stop,ty1,ty2) => (stop',_) &
elab_type ty2 => at &
Types.is_array ty2 => a
------------------------------------------
type_convert(Exp.RANGE(t,begin,SOME(step),stop),
Types.T_ARRAY(Types.DIM(SOME(dim1)), ty1),
Types.T_ARRAY(Types.DIM(SOME(dim2)), ty2))
=> (Exp.RANGE(at,begin',SOME(step'),stop'),Types.T_ARRAY(Types.DIM(SOME(dim1)),ty2))

rule int_eq (dim1, dim2) => true &
type_convert(begin,ty1,ty2) => (begin',_) &
type_convert(stop,ty1,ty2) => (stop',_) &
elab_type ty2 => at &
Types.is_array ty2 => a
------------------------------------------
type_convert(Exp.RANGE(t,begin,NONE,stop),
Types.T_ARRAY(Types.DIM(SOME(dim1)), ty1),
Types.T_ARRAY(Types.DIM(SOME(dim2)), ty2))
=> (Exp.RANGE(at,begin',NONE,stop'),Types.T_ARRAY(Types.DIM(SOME(dim1)),ty2))

rule int_eq (dim1, dim2) => true &
int_eq (dim11,dim22) => true &
type_convert_matrix (ell, t1, t2) => ell' &
Expand Down

0 comments on commit 22ea4a3

Please sign in to comment.