PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/semantics/types/liberty_type_resolver.e

http://github.com/tybor/Liberty
Specman e | 134 lines | 96 code | 16 blank | 22 comment | 7 complexity | a4fbcf62a16225aef0b49e7b970788cd 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--
 15deferred class LIBERTY_TYPE_RESOLVER
 16
 17insert
 18   LIBERTY_AST_HANDLER
 19      undefine out_in_tagged_out_memory
 20      end
 21   LOGGING
 22      undefine out_in_tagged_out_memory
 23      end
 24
 25feature {ANY}
 26   parent: LIBERTY_TYPE_RESOLVER
 27
 28   type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
 29         -- Try to find a class using the resolver context. Depending on the resolver, anchors may be resolved
 30         -- or not.
 31      do
 32         Result := undelayed_type(type_definition)
 33         if Result = Void then
 34            Result := delayed_type(type_definition)
 35         end
 36      end
 37
 38   export_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
 39         -- More lenient version, reserved for exports. If the class is not found and is not used anywhere but
 40         -- in export clauses then there will not be any error (a dummy object will be returned).
 41      require
 42         not type_definition.is_anchor
 43      do
 44         Result := lookup_export_type(type_definition)
 45         if Result = Void and then parent /= Void then
 46            Result := parent.export_type(type_definition)
 47         end
 48         if Result = Void then
 49            create {LIBERTY_UNKNOWN_TYPE} Result.make(type_definition.type_name.image.image.intern)
 50         end
 51      ensure
 52         Result /= Void
 53      end
 54
 55   position (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_POSITION is
 56         -- Try to find the position of the type definition. Useful for error reporting.
 57      do
 58         Result := lookup_position(type_definition)
 59         if Result = Void and then parent /= Void then
 60            Result := parent.position(type_definition)
 61         end
 62         if Result = Void then
 63            Result := errors.unknown_position
 64         end
 65      ensure
 66         Result /= Void
 67      end
 68
 69   specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
 70      require
 71         a_type /= Void
 72      deferred
 73      ensure
 74         Result /= Void
 75      end
 76
 77feature {LIBERTY_DELAYED_TYPE_DEFINITION, LIBERTY_TYPE_RESOLVER}
 78   undelayed_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
 79      do
 80         Result := lookup_type(type_definition)
 81         if Result = Void and then parent /= Void then
 82            Result := parent.undelayed_type(type_definition)
 83         end
 84      end
 85
 86feature {LIBERTY_UNIVERSE, LIBERTY_DELAYED_TYPE}
 87   delayed_types: COLLECTION[LIBERTY_DELAYED_TYPE] is
 88      once
 89         create {RING_ARRAY[LIBERTY_DELAYED_TYPE]} Result.with_capacity(1024, 0)
 90      end
 91
 92feature {}
 93   delayed_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_DELAYED_TYPE is
 94      do
 95         create Result.make(create {LIBERTY_DELAYED_TYPE_DEFINITION}.make(type_definition, Current))
 96      end
 97
 98feature {LIBERTY_TYPE_LOOKUP}
 99   set_parent (a_parent: like parent) is
100      require
101         dont_change_parent: parent = Void or else parent = a_parent
102      do
103         parent := a_parent
104      ensure
105         parent = a_parent
106      end
107
108feature {}
109   lookup_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
110         -- May be Void if the type is not resolved.
111      require
112         type_definition /= Void
113      deferred
114      end
115
116   lookup_export_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
117         -- May be Void if the type is not resolved.
118      require
119         not type_definition.is_anchor
120      deferred
121      end
122
123   lookup_position (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_POSITION is
124         -- May be Void if the position cannot be calculated.
125      deferred
126      end
127
128feature {}
129   errors: LIBERTY_ERRORS
130
131invariant
132   delayed_types /= Void
133
134end -- class LIBERTY_TYPE_RESOLVER