PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/src/wrappers/llvm/library/types/llvm_struct_type.e

http://github.com/tybor/Liberty
Specman e | 93 lines | 52 code | 12 blank | 29 comment | 0 complexity | 55827509519628653b605278437f28ad MD5 | raw file
 1class LLVM_STRUCT_TYPE
 2-- A type representing a structure in LLVM.
 3
 4-- It is also a COLLECTION of LLVM_TYPEs, the types of its fields.
 5
 6inherit
 7   LLVM_COMPOSITE_TYPE
 8      --undefine fill_tagged_out_memory
 9      redefine copy end
10      LLVM_TYPE_FACTORY
11      -- TODO: evolve the primitive array-like features into a proper heir of C_ARRAY[LLVM_TYPE]
12      --      undefine is_equal -- use is_equal from LLVM_TYPE
13      --      redefine copy
14      --      end
15      ARRAYED_COLLECTION_HANDLER
16
17create {ANY} make, in_context, from_external_pointer
18
19feature {ANY} -- Creation
20   make (some_elements: COLLECTION[LLVM_TYPE]; packed: BOOLEAN)
21      require
22         some_elements/=Void
23         not some_elements.is_empty
24      do
25         handle := llvmstruct_type(collection_to_c_array(some_elements).storage.to_external, some_elements.count.to_natural_32, packed.to_integer)
26         refresh_storage
27      end
28
29   in_context (a_context: LLVM_CONTEXT; some_elements: COLLECTION[LLVM_TYPE]; packed: BOOLEAN)
30      require
31         a_context/=Void
32         some_elements/=Void
33         not some_elements.is_empty
34      do
35         handle := llvmstruct_type_in_context(a_context.handle, collection_to_c_array(some_elements).storage.to_external, some_elements.count.to_natural_32, packed.to_integer)
36         refresh_storage
37      end
38
39   copy (another: like Current)
40      do
41         handle:=another.handle
42         refresh_storage
43      end
44
45feature {ANY} -- Packing
46   is_packed: BOOLEAN
47      do
48         Result:=llvmis_packed_struct(handle).to_boolean
49      end
50feature {ANY} -- Element access
51   elements_count: INTEGER_32
52   element (an_index: INTEGER_32): LLVM_TYPE
53      require valid_index: an_index.in_range(0,elements_count-1)
54      do
55         Result:=type_wrapper(storage.item(an_index))
56      end
57
58feature {} -- Implementation
59   storage: NATIVE_ARRAY[POINTER]
60         -- The addresses of Current's elements
61
62   refresh_storage
63         -- Initialize `storage' with the field types of the structure
64      do
65         elements_count := llvmcount_struct_element_types(handle).to_integer_32
66         storage := storage.calloc(elements_count)
67         llvmget_struct_element_types(handle, storage.to_pointer)
68      end
69   -- An LLVMStruct will (mostly) not change its elements, allowing to cache
70   -- the result of an llvmget_struct_element_types.  Types are generally
71   -- immutable, the one exception is when type refinement happens Check out
72   -- LLVM's ProgrammersManual in the cyclic types section. refine type
73   -- feature shalle be redefined.
74
75invariant type_kind.is_struct_type_kind
76end -- class LLVM_STRUCT_TYPE
77
78-- Copyright (C) 2009-2017: Paolo Redaelli
79
80-- This file is part of LLVM wrappers for Liberty Eiffel.
81--
82-- This library is free software: you can redistribute it and/or modify
83-- it under the terms of the GNU Lesser General Public License as published by
84-- the Free Software Foundation, version 3 of the License.
85--
86-- Liberty Eiffel is distributed in the hope that it will be useful,
87-- but WITHOUT ANY WARRANTY; without even the implied warranty of
88-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
89-- GNU General Public License for more details.
90--
91-- You should have received a copy of the GNU General Public License
92-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
93--