Skip to content

Commit

Permalink
getConnectionCount completed.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@799 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed May 29, 2002
1 parent 24facd4 commit f6257aa
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
74 changes: 73 additions & 1 deletion modeq/interactive.rml
Expand Up @@ -168,6 +168,16 @@ relation evaluate_graphical_api: (InteractiveStmts, InteractiveSymbolTable) =>
Absyn.FUNCTIONARGS([Absyn.CREF(cr),Absyn.INTEGER(n)],_)))]
),
st as SYMBOLTABLE(p,s,ic,iv)) => (resstr,st)

rule get_connection_count(cr,p) => s1 &
string_append(s1,"\n") => resstr
-----------------------
evaluate_graphical_api(
ISTMTS([IEXP(Absyn.CALL(
Absyn.CREF_IDENT("getConnectionCount",_),
Absyn.FUNCTIONARGS([Absyn.CREF(cr)],_)))]
),
st as SYMBOLTABLE(p,s,ic,iv)) => (resstr,st)
end

relation componentref_to_path: Absyn.ComponentRef => Absyn.Path =
Expand Down Expand Up @@ -321,6 +331,69 @@ relation get_nth_component_annotation: (Absyn.ComponentRef,Absyn.Program, int) =
axiom get_nth_component_annotation(_,_,_) => "-1"
end

(** relation: get_connection_count
** This relation takes a `ComponentRef' and a `Program' and returns a string containing
** the number of connections in the model identified by the `ComponentRef'.
**)
relation get_connection_count: (Absyn.ComponentRef, Absyn.Program) => string =

rule Absyn.cref_to_path(model) => modelpath &
get_pathed_class_in_program(modelpath,p) => cdef &
count_connections cdef => numconn &
int_string numconn => res
-------------------------
get_connection_count (model,p) => res

axiom get_connection_count(_,_) => "-1"
end

(** relation: count_connections
** This relation takes a `Class' and returns an int with the number of connections
** in the `Class'.
**)
relation count_connections: Absyn.Class => int =

rule count_connections_in_classparts(parts) => count
-----------------------------------------------
count_connections Absyn.CLASS(_,_,_,Absyn.PARTS(parts)) => count
end

(** relation: count_connections_in_classparts
** This relation takes a `ClassPart' list and returns an int with the number of connections in that list.
**)
relation count_connections_in_classparts: Absyn.ClassPart list => int =

rule count_connections_in_equations(eqlist) => r1 &
count_connections_in_classparts(xs) => r2 &
int_add (r1,r2) => res
----------------------
count_connections_in_classparts( Absyn.EQUATIONS(eqlist)::xs) => res

rule count_connections_in_classparts(xs) => res
------------------------------------------
count_connections_in_classparts( _::xs) => res

axiom count_connections_in_classparts([]) => 0
end

(** relation: count_connections_in_equations
** This relation takes an `Equation' list and returns an int
** with the number of connect statements in that list.
**)
relation count_connections_in_equations: Absyn.Equation list => int =

rule count_connections_in_equations(xs) => r1 &
int_add(r1,1) => res
---------------------
count_connections_in_equations(Absyn.EQ_CONNECT(_,_)::xs) => res

rule count_connections_in_equations(xs) => res
-----------------------------------------
count_connections_in_equations(_::xs) => res

axiom count_connections_in_equations([]) => 0
end

(** relation: get_component_annotation
** This relation takes an `Element' and returns a comma separated string of values
** corresponding to the flat record for a component annotation. If several components are declared
Expand Down Expand Up @@ -378,7 +451,6 @@ relation get_annotation_string: Absyn.Annotation => string =
SCode.elab_class(placementc) => placementclass &
Mod.elab_mod (env,Prefix.NOPRE,mod') => mod'' &
Inst.inst_class(env,mod'',Prefix.NOPRE,[],placementclass,[]) => (dae,cs,t,state) &
DAE.dump DAE.DAE([DAE.COMP("placement",DAE.DAE(dae))]) &
(* Put bindings of variables as expressions inside variable elements of the dae instead of equations *)
Inst.init_vars_modelica_output dae => dae' &
DAE.get_variable_bindings_str dae' => str
Expand Down
9 changes: 5 additions & 4 deletions modeq/interactive_api.txt
Expand Up @@ -13,6 +13,7 @@ by using scripts, but also by for instance a model editor who wants to
interact with the symbol table for adding/changing/removing models and
components, etc.

When a function fails to perform its action the string "-1" is returned.


Definitions:
Expand Down Expand Up @@ -49,12 +50,12 @@ updateComponent(<ident>,<cref>, Updates an already existing component.
<cref>,annotate=<expr>)

getComponentCount(<cref>) Returns the number of
components of a class.
components in a class.

getNthComponent(<cref>,<int>) Returns the belonging class,
component name and type name
of the nth component of a class.
e.g. "A.B.C, R2, Resistor"
e.g. "A.B.C,R2,Resistor"


getNthComponentAnnotation(<cref>,<int>) Returns the flattened
Expand All @@ -80,12 +81,12 @@ getConnectorCount(<cref>) Returns the number of
connectors of a class.

getNthConnector(<cref>,<int>) Returns the name of the nth
connector, e.g "n"
connector, e.g "n".

getNthConnectorAnnotation(<cref>,<int> Returns the nth connector
annotation as comma separated
list of values of a flat
record, see Annotation below
record, see Annotation below.

Error Handling
==============
Expand Down

0 comments on commit f6257aa

Please sign in to comment.