type.rb (3706B)
1 # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com> 2 # Copyright, 2014, by Masahiro Sano. 3 # 4 # Permission is hereby granted, free of charge, to any person obtaining a copy 5 # of this software and associated documentation files (the "Software"), to deal 6 # in the Software without restriction, including without limitation the rights 7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 # copies of the Software, and to permit persons to whom the Software is 9 # furnished to do so, subject to the following conditions: 10 # 11 # The above copyright notice and this permission notice shall be included in 12 # all copies or substantial portions of the Software. 13 # 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 # THE SOFTWARE. 21 22 module FFI 23 module Clang 24 class Type 25 attr_reader :type 26 27 def initialize(type, translation_unit) 28 @type = type 29 @translation_unit = translation_unit 30 end 31 32 def kind 33 @type[:kind] 34 end 35 36 def kind_spelling 37 Lib.extract_string Lib.get_type_kind_spelling @type[:kind] 38 end 39 40 def spelling 41 Lib.extract_string Lib.get_type_spelling(@type) 42 end 43 44 def variadic? 45 Lib.is_function_type_variadic(@type) != 0 46 end 47 48 def pod? 49 Lib.is_pod_type(@type) != 0 50 end 51 52 def num_arg_types 53 Lib.get_num_arg_types(@type) 54 end 55 56 def pointee 57 Type.new Lib.get_pointee_type(@type), @translation_unit 58 end 59 60 def canonical 61 Type.new Lib.get_canonical_type(@type), @translation_unit 62 end 63 64 def class_type 65 Type.new Lib.type_get_class_type(@type), @translation_unit 66 end 67 68 def const_qualified? 69 Lib.is_const_qualified_type(@type) != 0 70 end 71 72 def volatile_qualified? 73 Lib.is_volatile_qualified_type(@type) != 0 74 end 75 76 def restrict_qualified? 77 Lib.is_restrict_qualified_type(@type) != 0 78 end 79 80 def final_type? 81 Lib.is_final_type(@type) != 0 82 end 83 84 def abstract_type? 85 Lib.is_abstract_type(@type) != 0 86 end 87 88 def noexcept? 89 Lib.is_noexcept(@type) != 0 90 end 91 92 def num_template_arguments 93 Lib.get_num_template_arguments(@type) 94 end 95 96 def template_argument(i) 97 Type.new Lib.get_template_argument_as_type(@type, i), @translation_unit 98 end 99 100 def template_arguments 101 Lib.get_num_template_arguments(@type).times.map do |i| 102 template_argument(i) 103 end 104 end 105 106 def arg_type(i) 107 Type.new Lib.get_arg_type(@type, i), @translation_unit 108 end 109 110 def result_type 111 Type.new Lib.get_result_type(@type), @translation_unit 112 end 113 114 def element_type 115 Type.new Lib.get_element_type(@type), @translation_unit 116 end 117 118 def num_elements 119 Lib.get_num_elements(@type) 120 end 121 122 def array_element_type 123 Type.new Lib.get_array_element_type(@type), @translation_unit 124 end 125 126 def array_size 127 Lib.get_array_size(@type) 128 end 129 130 def alignof 131 Lib.type_get_align_of(@type) 132 end 133 134 def sizeof 135 Lib.type_get_size_of(@type) 136 end 137 138 def offsetof(field) 139 Lib.type_get_offset_of(@type, field) 140 end 141 142 def ref_qualifier 143 Lib.type_get_cxx_ref_qualifier(@type) 144 end 145 146 def calling_conv 147 Lib.get_fuction_type_calling_conv(@type) 148 end 149 150 def declaration 151 Cursor.new Lib.get_type_declaration(@type), @translation_unit 152 end 153 154 def ==(other) 155 Lib.equal_types(@type, other.type) != 0 156 end 157 end 158 end 159 end