PageRenderTime 20ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/src/tools/semantics/types/delayed_resolver/liberty_delayed_type_definition.e

http://github.com/tybor/Liberty
Specman e | 138 lines | 105 code | 16 blank | 17 comment | 4 complexity | c60481f87ce7390e664d0e2880155551 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_DELAYED_TYPE_DEFINITION
 16
 17inherit
 18   LIBERTY_DELAYED_RESOLVER
 19
 20insert
 21   EIFFEL_NODE_HANDLER
 22      redefine out_in_tagged_out_memory, is_equal
 23      end
 24
 25creation {LIBERTY_TYPE_RESOLVER, LIBERTY_DELAYED_TYPE_DEFINITION}
 26   make
 27
 28feature {ANY}
 29   out_in_tagged_out_memory is
 30      do
 31         if can_resolve then
 32            resolved.out_in_tagged_out_memory
 33         else
 34            tagged_out_memory.extend('"')
 35            full_name_memory.out_in_tagged_out_memory
 36            tagged_out_memory.append(once "%" using ")
 37            resolver.out_in_tagged_out_memory
 38         end
 39      end
 40
 41   hash_code: INTEGER is
 42      do
 43         Result := full_name_memory.hash_code
 44      end
 45
 46   is_equal (other: like Current): BOOLEAN is
 47      do
 48         Result := other = Current
 49      end
 50
 51feature {LIBERTY_DELAYED_TYPE}
 52   can_resolve: BOOLEAN is
 53      do
 54         if type_memory /= Void then
 55            Result := True
 56         else
 57            type_memory ::= resolver.undelayed_type(type_definition)
 58            Result := type_memory /= Void
 59            debug
 60               if Result then
 61                  log.trace.put_string(once " >>> Resolved ")
 62                  log.trace.put_string(full_name_memory)
 63                  log.trace.put_string(once " => ")
 64                  log.trace.put_line(type_memory.out)
 65               end
 66            end
 67         end
 68      ensure
 69         Result implies type_memory /= Void
 70      end
 71
 72   resolved: LIBERTY_KNOWN_TYPE is
 73      local
 74         ok: BOOLEAN
 75      do
 76         ok := can_resolve
 77         check
 78            ok
 79            type_memory /= Void
 80         end
 81         Result := type_memory
 82      end
 83
 84   full_name: FIXED_STRING is
 85      do
 86         Result := full_name_memory
 87      end
 88
 89   specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
 90      local
 91         r: like resolver
 92      do
 93         r := resolver.specialized_in(a_type)
 94         if r = resolver then
 95            Result := Current
 96         else
 97            --|*** TODO: ??? Not sure about that. Maybe we should keep track of the original type to find the
 98            --| good entity (esp. in case of renamings).
 99            --| Then again, maybe the resolver should do that.
100            create Result.make(type_definition, r)
101         end
102      end
103
104feature {}
105   make (a_type_definition: like type_definition; a_resolver: like resolver) is
106      require
107         a_type_definition /= Void
108         a_resolver /= Void
109      do
110         type_definition := a_type_definition
111         resolver := a_resolver
112         create_full_name_memory
113      ensure
114         type_definition = a_type_definition
115         resolver = a_resolver
116      end
117
118   type_definition: LIBERTY_AST_TYPE_DEFINITION
119   resolver: LIBERTY_TYPE_RESOLVER
120   type_memory: LIBERTY_ACTUAL_TYPE
121
122   create_full_name_memory is
123      do
124         buffer_stream.clear
125         type_definition.generate(buffer_stream)
126         full_name_memory := buffer_stream.to_string.intern
127      ensure
128         full_name_memory /= Void
129      end
130
131   buffer_stream: STRING_OUTPUT_STREAM is
132      once
133         create Result.make
134      end
135
136   full_name_memory: FIXED_STRING
137
138end -- class LIBERTY_DELAYED_TYPE_DEFINITION