PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/src/tools/semantics/code/feature_local_context/liberty_inline_agent_context.e

http://github.com/tybor/Liberty
Specman e | 192 lines | 152 code | 26 blank | 14 comment | 8 complexity | e6bc53be76c1af02e27fef85f5ab258b MD5 | raw file
  1-- This file is part of Liberty Eiffel.
  2--
  3-- Liberty Eiffel is free software: you can redistribute it and/or modify
  4-- it under the terms of the GNU General Public License as published by
  5-- the Free Software Foundation, version 3 of the License.
  6--
  7-- Liberty Eiffel is distributed in the hope that it will be useful,
  8-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 10-- GNU General Public License for more details.
 11--
 12-- You should have received a copy of the GNU General Public License
 13-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
 14--
 15class LIBERTY_INLINE_AGENT_CONTEXT
 16
 17inherit
 18   LIBERTY_FEATURE_LOCAL_CONTEXT
 19
 20insert
 21   LIBERTY_AST_HANDLER
 22
 23create {LIBERTY_BUILDER_TOOLS}
 24   make
 25
 26feature {ANY}
 27   current_type: LIBERTY_ACTUAL_TYPE is
 28      do
 29         Result := current_entity.result_type
 30      end
 31
 32   result_type: LIBERTY_TYPE is
 33      do
 34         if result_entity /= Void then
 35            Result := result_entity.result_type
 36         end
 37      end
 38
 39   parameters: TRAVERSABLE[LIBERTY_PARAMETER] is
 40      do
 41         Result := parameters_list
 42      ensure then
 43         definition: Result = parameters_list
 44      end
 45
 46   locals: TRAVERSABLE[LIBERTY_LOCAL] is
 47      do
 48         Result := locals_list
 49      ensure then
 50         definition: Result = locals_list
 51      end
 52
 53   is_parameter (name: ABSTRACT_STRING): BOOLEAN is
 54      do
 55         Result := parameters_map.has(name.intern)
 56      end
 57
 58   parameter (name: ABSTRACT_STRING): LIBERTY_PARAMETER is
 59      do
 60         Result := parameters_map.reference_at(name.intern)
 61      end
 62
 63   is_local (name: ABSTRACT_STRING): BOOLEAN is
 64      do
 65         Result := locals_map.has(name.intern)
 66      end
 67
 68   local_var (name: ABSTRACT_STRING): LIBERTY_LOCAL is
 69      do
 70         Result := locals_map.reference_at(name.intern)
 71      end
 72
 73   current_entity: LIBERTY_CURRENT
 74   result_entity: LIBERTY_RESULT
 75
 76   can_retry: BOOLEAN is False
 77
 78   retry_instruction (a_position: LIBERTY_POSITION): LIBERTY_RETRY is
 79      do
 80         check False end
 81      end
 82
 83feature {LIBERTY_BUILDER_TOOLS, LIBERTY_FEATURE_LOCAL_CONTEXT}
 84   add_parameter (a_parameter: LIBERTY_PARAMETER) is
 85      do
 86         parameters_list.add_last(a_parameter)
 87         parameters_map.add(a_parameter, a_parameter.name)
 88      end
 89
 90   add_local (a_local: LIBERTY_LOCAL) is
 91      do
 92         locals_list.add_last(a_local)
 93         locals_map.add(a_local, a_local.name)
 94      end
 95
 96   reconcile_retry_instructions (a_feature: LIBERTY_FEATURE) is
 97      do
 98         check False end
 99      end
100
101   set_result_type (a_result_type: like result_type) is
102      do
103         result_entity := a_result_type.result_entity
104      end
105
106feature {LIBERTY_INLINE_AGENT, LIBERTY_SEMANTICS_BUILDER}
107   specialized_in (a_type: like current_type): like Current is
108      do
109         Result := twin
110         Result.set_specialized_in(a_type)
111      end
112
113feature {LIBERTY_INLINE_AGENT_CONTEXT}
114   set_specialized_in (a_type: like current_type) is
115      local
116         i: INTEGER; p: LIBERTY_PARAMETER; l: LIBERTY_LOCAL
117         pl: like parameters_list; pm: like parameters_map
118         ll: like locals_list; lm: like locals_map
119      do
120         current_entity := a_type.current_entity
121
122         if result_entity /= Void then
123            set_result_type(result_type.specialized_in(a_type))
124         end
125
126         from
127            pl := parameters_list
128            pm := parameters_map
129            i := pl.lower
130         until
131            i > pl.upper
132         loop
133            p := pl.item(i).specialized_in(a_type)
134            if p /= pl.item(i) then
135               if pl = parameters_list then
136                  pl := pl.twin
137                  pm := pm.twin
138               end
139               pl.put(p, i)
140               pm.put(p, p.name)
141            end
142            i := i + 1
143         end
144         if pl /= parameters_list then
145            parameters_list := pl
146            parameters_map := pm
147         end
148
149         from
150            ll := locals_list
151            lm := locals_map
152            i := ll.lower
153         until
154            i > ll.upper
155         loop
156            l := ll.item(i).specialized_in(a_type)
157            if l /= ll.item(i) then
158               if ll = locals_list then
159                  ll := ll.twin
160                  lm := lm.twin
161               end
162               ll.put(l, i)
163               lm.put(l, l.name)
164            end
165            i := i + 1
166         end
167         if ll /= locals_list then
168            locals_list := ll
169            locals_map := lm
170         end
171      end
172
173feature {}
174   parameters_map: DICTIONARY[LIBERTY_PARAMETER, FIXED_STRING]
175   parameters_list: COLLECTION[LIBERTY_PARAMETER]
176   locals_map: DICTIONARY[LIBERTY_LOCAL, FIXED_STRING]
177   locals_list: COLLECTION[LIBERTY_LOCAL]
178
179   make (a_parent_context: LIBERTY_FEATURE_LOCAL_CONTEXT) is
180      require
181         a_parent_context /= Void
182      do
183         current_entity := a_parent_context.current_type.current_entity
184         create {FAST_ARRAY[LIBERTY_PARAMETER]} parameters_list.make(0)
185         create {HASHED_DICTIONARY[LIBERTY_PARAMETER, FIXED_STRING]} parameters_map.with_capacity(a_parent_context.parameters.count + 3)
186         create {FAST_ARRAY[LIBERTY_LOCAL]} locals_list.make(0)
187         create {HASHED_DICTIONARY[LIBERTY_LOCAL, FIXED_STRING]} locals_map.with_capacity(a_parent_context.locals.count + 3)
188         a_parent_context.parameters.do_all(agent add_parameter)
189         a_parent_context.locals.do_all(agent add_local)
190      end
191
192end