/src/tools/wrappers-generator/c_typedef.e
Specman e | 143 lines | 109 code | 14 blank | 20 comment | 13 complexity | aa79cf031ec37350931265cf2e796ef5 MD5 | raw file
1class C_TYPEDEF 2 3inherit 4 C_TYPE 5 IDENTIFIED_NODE 6 MOVABLE_NODE 7 -- Hence a NAMED_NODE and FILED_NODE 8 -- using the definition made in WRAPPER_CLASS 9 undefine compute_eiffel_name 10 end 11 TYPED_NODE 12 CONTEXTED_NODE 13 STORABLE_NODE 14 WRAPPER_CLASS 15 16create {GCCXML_TREE} 17 make 18 19feature {ANY} 20 store 21 do 22 -- if not standard_typedefs.has(c_string_name) then 23 -- Current typedef is not a standard one and requires a query for anchored declarations. 24 typedefs.add_first(Current) 25 -- end 26 types.fast_put(Current, id) 27 check 28 is_named 29 end 30 symbols.put(Current, c_string_name) 31 end 32 33 standard_typedefs: SET[STRING] 34 -- The standard typedefs defined by the C language. 35 once 36 Result := {HASHED_SET[STRING] << "long int", "int8_t", "uint8_t", "int16_t", "uint16_t", "int32_t", "uint32_t", "int64_t", "uint64_t", "intptr_t", "uintptr_t", "int_least8_t", "uint_least8_t", "int_least16_t", "uint_least16_t", "int_least32_t", "uint_least32_t", "int_least64_t", "uint_least64_t", "int_fast8_t", "uint_fast8_t", "int_fast16_t", "uint_fast16_t", "int_fast32_t", "uint_fast32_t", "int_fast64_t", "uint_fast64_t", "intmax_t", "uintmax_t", "size_t", "ssize_t", "ptrdiff_t" >> } 37 end 38 39 wrapper_type: STRING 40 do 41 if not settings.are_standard_typedefs_emitted and then standard_typedefs.has(c_string_name) then 42 Result := once "like " + c_string_name 43 else 44 if referree.has_wrapper then 45 Result := referree.wrapper_type 46 else 47 log("C typedef #(1) at line #(2) is not wrappable" # c_string_name # &line) 48 end 49 end 50 end 51 52 is_fundamental: BOOLEAN 53 local 54 a_type: C_TYPE 55 do 56 a_type := types.at(type) 57 if a_type /= Void then 58 Result := a_type.is_fundamental 59 else 60 raise("unknown type") 61 end 62 end 63 64 is_void: BOOLEAN False 65 66 has_wrapper: BOOLEAN 67 do 68 Result := types.at(type).has_wrapper 69 end 70 71 is_to_be_emitted: BOOLEAN 72 do 73 Result := is_public and then (global or else headers.has(c_file.c_string_name)) 74 end 75 76 wrap_on (a_stream: OUTPUT_STREAM) 77 -- If Current ultimately refers to a fundamental type then put an empty query on `a_stream', otherwise nothing is done. 78 local 79 query_name: STRING 80 do 81 if is_to_be_emitted then 82 if is_fundamental then 83 if has_wrapper then 84 query_name := eiffel_feature(c_string_name) 85 log(once "Anchored query #(2) for typedef #(1)%N" # c_string_name # query_name) 86 87 buffer.append(once " #(1): #(2)%N% 88 % -- typedef #(3) from #(4)%N% 89 % -- Empty by design, used for anchored declarations.%N% 90 % do%N% 91 % ensure Result.is_default%N% 92 % end%N% 93 %%N" # query_name # wrapper_type # c_string_name 94 # c_file.c_string_name ) 95 else 96 buffer.append(once "%T-- #(1) unwrappable: no wrapper type.%N" # c_string_name) 97 -- TODO: add the case of typedef to void 98 end 99 buffer.print_on(a_stream) 100 else 101 -- It refers to something else; let's assign it a name 102 referree.set_name(eiffel_feature(c_string_name)) 103 end 104 end 105 end -- invariant name.is_equal(once U"Typedef") 106 107feature {ANY} 108 emit_wrapper 109 local a_composed_type: COMPOSED_NODE 110 do 111 if a_composed_type ?:= referree then 112 log("Emitting wrapper for typedef #(1)%N" # c_string_name) 113 a_composed_type ::= referree 114 if a_composed_type /=Void then 115 if not a_composed_type.is_named then 116 log("Referred #(1) is anonymous, forcingly setting its name to #(2)%N" # 117 a_composed_type.c_type # c_string_name) 118 a_composed_type.set_name(c_string_name) 119 end 120 a_composed_type.emit_wrapper 121 else 122 log(" typedef #(1) has no referree node%N" # c_string_name) 123 end 124 else 125 log("No wrapper for typedef #(1)%N" # c_string_name) 126 end 127 emitted := True 128 end 129 130 suffix: STRING "" 131 132end -- class C_TYPEDEF 133-- Copyright (C) 2008-2017: Paolo Redaelli 134-- wrappers-generator is free software: you can redistribute it and/or modify it 135-- under the terms of the GNU General Public License as publhed by the Free 136-- Software Foundation, either version 2 of the License, or (at your option) 137-- any later version. 138-- wrappers-generator is distributed in the hope that it will be useful, but 139-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 140-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 141-- more details. 142-- You should have received a copy of the GNU General Public License along with 143-- th program. If not, see <http://www.gnu.org/licenses/>.