PageRenderTime 28ms CodeModel.GetById 21ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/semantics/types/type_builder/liberty_type_init.e

http://github.com/tybor/Liberty
Specman e | 123 lines | 99 code | 7 blank | 17 comment | 5 complexity | 68dca5cf96113510c5009b4cf325ef7b 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_TYPE_INIT
 16   --
 17   -- Initializes general type information such as obsolete, deferred, and so on
 18   --
 19
 20insert
 21   LIBERTY_TYPE_BUILDER_TOOLS
 22
 23creation {LIBERTY_TYPE_BUILDER}
 24   make
 25
 26feature {}
 27   make (a_builder: like builder; a_type: like type; a_universe: like universe; default_effective_generic_parameters: like effective_generic_parameters) is
 28      require
 29         a_builder /= Void
 30         a_type /= Void
 31         a_universe /= Void
 32      do
 33         builder := a_builder
 34         type := a_type
 35         universe := a_universe
 36         effective_generic_parameters := default_effective_generic_parameters
 37      ensure
 38         builder = a_builder
 39         type = a_type
 40         universe = a_universe
 41         effective_generic_parameters = default_effective_generic_parameters
 42      end
 43
 44   universe: LIBERTY_UNIVERSE
 45
 46feature {LIBERTY_TYPE_BUILDER}
 47   init_type_header is
 48      local
 49         class_header: LIBERTY_AST_CLASS_HEADER
 50         marker: LIBERTY_AST_CLASS_MARKER
 51         name: FIXED_STRING
 52         type_parameters: LIBERTY_AST_TYPE_PARAMETERS
 53         type_parameter: LIBERTY_AST_TYPE_PARAMETER
 54         effective_type: LIBERTY_ACTUAL_TYPE
 55         i, n: INTEGER
 56      do
 57         class_header := type.ast.class_header
 58         marker := class_header.class_marker
 59         if marker.is_deferred then
 60            type.set_deferred
 61         elseif marker.is_expanded then
 62            type.set_expanded
 63         elseif marker.is_separate then
 64            type.set_separate
 65         else
 66            type.set_reference
 67         end
 68         name := class_header.class_name.image.image.intern
 69         if name /= type.name then
 70            errors.set(level_fatal_error, once "Expected type " + type.name + once ", but got " + name)
 71         end
 72         type_parameters := class_header.type_parameters
 73         n := type_parameters.list_count
 74         if n /= type.parameters.count then
 75            errors.add_position(semantics_position_at(class_header.class_name))
 76            errors.add_position(type.descriptor_position)
 77            errors.set(level_error, once "Bad number of generic parameters")
 78         elseif n > 0 then
 79            check
 80               same_indexes: type_parameters.list_lower = type.parameters.lower
 81            end
 82            create {HASHED_DICTIONARY[LIBERTY_ACTUAL_TYPE, FIXED_STRING]} effective_generic_parameters.with_capacity(n)
 83            from
 84               i := type_parameters.list_lower
 85            until
 86               i > type_parameters.list_upper
 87            loop
 88               type_parameter := type_parameters.list_item(i)
 89               effective_type ::= type.parameters.item(i).known_type
 90               effective_generic_parameters.add(effective_type, type_parameter.class_name.image.image.intern)
 91               i := i + 1
 92            end
 93            builder.set_effective_generic_parameters(effective_generic_parameters)
 94         end
 95         torch.burn
 96      end
 97
 98   is_ready: BOOLEAN is
 99      local
100         i: INTEGER
101      do
102         from
103            Result := True
104            i := type.parameters.lower
105         until
106            not Result or else i > type.parameters.upper
107         loop
108            Result := type.parameters.item(i).is_known
109            debug ("type.building.internals")
110               if not Result then
111                  log.trace.put_string(type.full_name)
112                  log.trace.put_string(once ": not yet ready because the type parameter #")
113                  log.trace.put_integer(i)
114                  log.trace.put_string(once ", ")
115                  log.trace.put_string(type.parameters.item(i).full_name)
116                  log.trace.put_line(once " is not yet actually set")
117               end
118            end
119            i := i + 1
120         end
121      end
122
123end -- class LIBERTY_TYPE_INIT