Skip to content

Commit

Permalink
Fixed bug in getNthComponent, etc.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1078 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jan 21, 2004
1 parent 5338095 commit b85d32a
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions modeq/interactive.rml
Expand Up @@ -1838,14 +1838,15 @@ end

relation get_nth_component2: (SCode.Class,Absyn.Class, int, Env.Env)
=> string =
rule (* First try without instantiating class, saves time *)
(*rule
get_nth_component_in_class(cdef,n) => comp &
get_component_name_and_type_and_comment (comp,env) => [s1] &
string_append("{",s1) => s2 &
string_append(s2,"}") => str
--------------------------
get_nth_component2 (c as SCode.CLASS(id,_,encflag,restr,_),cdef,n,env)
=> str
*)

rule (* If fails, instantiate class and search... *)
Env.open_scope(env,encflag,0) => env2 &
Expand Down Expand Up @@ -3133,7 +3134,9 @@ end

relation get_nth_component_in_class: (Absyn.Class,int) => Absyn.Element =

rule get_nth_component_in_elementitems(elt,n) => res
rule count_components_in_elts(elt) => count &
int_le(n,count) => true &
get_nth_component_in_elementitems(elt,n) => res
-----------------------------------------------
get_nth_component_in_class (Absyn.CLASS(a,b,c,d,e,Absyn.PARTS(Absyn.PUBLIC(elt)::lst,cmt)),n)
=> res
Expand All @@ -3142,6 +3145,8 @@ relation get_nth_component_in_class: (Absyn.Class,int) => Absyn.Element =
(* subtract and try next public list *)
rule count_components_in_elts(elt) => c1 &
int_sub(n,c1) => newn &
int_string(newn) => newnstr &
int_gt(newn,0) => true &
get_nth_component_in_class (Absyn.CLASS(a,b,c,d,e,Absyn.PARTS(rest,cmt)),newn) => res
------------------------------------------------------------------------------------
get_nth_component_in_class (Absyn.CLASS(a,b,c,d,e,Absyn.PARTS(Absyn.PUBLIC(elt)::rest,cmt)),n) => res
Expand All @@ -3155,6 +3160,7 @@ relation get_nth_component_in_class: (Absyn.Class,int) => Absyn.Element =
(* subtract and try next public list *)
rule count_components_in_elts(elt) => c1 &
int_sub(n,c1) => newn &
int_gt(newn,0) => true &
get_nth_component_in_class (Absyn.CLASS(a,b,c,d,e,Absyn.PARTS(rest,cmt)),newn) => res
------------------------------------------------------------------------------------
get_nth_component_in_class (Absyn.CLASS(a,b,c,d,e,Absyn.PARTS(Absyn.PROTECTED(elt)::rest,cmt)),n) => res
Expand All @@ -3172,20 +3178,11 @@ end
** This relation takes an `ElementItem' list and and integer and returns the nth component
** in the list
**)
relation get_nth_component_in_elementitems: (Absyn.ElementItem list, int) => Absyn.Element =

rule list_length(lst) => numcomps &
int_le(n,numcomps) => true &
int_sub(n,1) => n' &
list_nth(lst,n') => elt
-----------------------------
get_nth_component_in_elementitems(Absyn.ELEMENTITEM(elt as Absyn.ELEMENT(a,b,c,d,Absyn.COMPONENTS(e,f,lst),g))::rest,n)
=> Absyn.ELEMENT(a,b,c,d,Absyn.COMPONENTS(e,f,[elt]),g)
relation get_nth_component_in_elementitems: (Absyn.ElementItem list, int)
=> Absyn.Element =

rule get_nth_component_in_elementitems(rest,1) => res
-----------------------------------------
get_nth_component_in_elementitems(Absyn.ELEMENTITEM(elt)::rest,1)
=> res
axiom get_nth_component_in_elementitems(Absyn.ELEMENTITEM(Absyn.ELEMENT(a,b,c,d,Absyn.COMPONENTS(e,f,elt::_),g))::_,1)
=> Absyn.ELEMENT(a,b,c,d,Absyn.COMPONENTS(e,f,[elt]),g)

rule list_length(lst) => numcomps &
int_gt(n,numcomps) => true &
Expand All @@ -3194,10 +3191,19 @@ relation get_nth_component_in_elementitems: (Absyn.ElementItem list, int) => Abs
---------------------------------------------------
get_nth_component_in_elementitems(Absyn.ELEMENTITEM(Absyn.ELEMENT(_,_,_,_,Absyn.COMPONENTS(_,_,lst),_))::rest,n) => res

rule int_ge(n,1) => true &
rule list_length(lst) => numcomps &
int_le(n,numcomps) => true &
int_sub(n,1) => n' &
list_nth(lst,n') => elt
-----------------------------
get_nth_component_in_elementitems(Absyn.ELEMENTITEM(elt as Absyn.ELEMENT(a,b,c,d,Absyn.COMPONENTS(e,f,lst),g))::rest,n)
=> Absyn.ELEMENT(a,b,c,d,Absyn.COMPONENTS(e,f,[elt]),g)


(* rule int_ge(n,1) => true &
get_nth_component_in_elementitems(rest,n) => res
---------------------------------------------------
get_nth_component_in_elementitems(Absyn.ELEMENTITEM(elt)::rest,n) => res
get_nth_component_in_elementitems(Absyn.ELEMENTITEM(elt)::rest,n) => res*)

rule get_nth_component_in_elementitems(rest,n) => res
------------------------------------------------
Expand Down

0 comments on commit b85d32a

Please sign in to comment.