comparison scripts/dgen.rb @ 13:4f583f7e242e

Added a constructor for every init method
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:21:59 +0200
parents 07194b026fa4
children 7ff919f595d5
comparison
equal deleted inserted replaced
12:9f0b49a2f64e 13:4f583f7e242e
1097 static = method.classMethod == "true" 1097 static = method.classMethod == "true"
1098 1098
1099 index = 0 1099 index = 0
1100 declaration = build_function(method, true, static)[0 ... -2].indent.nl(false) 1100 declaration = build_function(method, true, static)[0 ... -2].indent.nl(false)
1101 index = declaration.index_of(" ") if static 1101 index = declaration.index_of(" ") if static
1102 index = declaration.index_of(" ", index) 1102 index = declaration.index_of(" ", index)
1103 1103 name = get_method_name(method.selector)
1104 str << (declaration[0 .. index] + get_method_name(method["selector"]) + declaration[index .. -1]).gsub(/ +/, " ") 1104
1105 str << (declaration[0 .. index] + name + declaration[index .. -1]).gsub(/ +/, " ")
1105 str << "{".indent.nl(false) 1106 str << "{".indent.nl(false)
1106 str << "return invokeObjcSelf!(".indent(2) unless static 1107
1107 str << "return invokeObjcSelfClass!(".indent(2) if static 1108 if static
1108 str << return_type 1109 str << "return invokeObjcSelfClass!(".indent(2)
1110 str << return_type
1111 else
1112 if return_type == class_name
1113 str << "id result = invokeObjcSelf!(".indent(2)
1114 str << "id"
1115 else
1116 str << "return invokeObjcSelf!(".indent(2)
1117 str << return_type
1118 end
1119 end
1120
1109 str << ', "' 1121 str << ', "'
1110 str << method.selector 1122 str << method.selector
1111 str << '"' 1123 str << '"'
1112 1124
1113 method.arg.each do |arg| 1125 method.arg.each do |arg|
1121 end 1133 end
1122 1134
1123 method.arg.each_with_index do |arg, i| 1135 method.arg.each_with_index do |arg, i|
1124 str << get_identifier(arg.name) 1136 str << get_identifier(arg.name)
1125 str << ", " unless i == method.arg.length - 1 1137 str << ", " unless i == method.arg.length - 1
1126 end unless method.arg.nil? 1138 end unless method.arg.nil?
1127 1139
1128 str << ")".nl 1140 if return_type == class_name
1141 str << "return result is this.objcObject ? this : (result !is null ? new #{return_type}(result) : null);"
1142 else
1143 str << ")".nl
1144 end
1129 1145
1130 str << "}".indent.nl(false).nl(false) 1146 str << "}".indent.nl(false).nl(false)
1147
1148 if name.length >= 4 && name[0 ... 4] == "init" && name != "initialize"
1149 str << ("this" + declaration[index .. -1]).gsub(/ +/, " ").indent
1150 str << "{".indent.nl(false)
1151 str << 'objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass)'.indent(2).nl
1152 str << 'id result = Bridge.invokeObjcMethod!(id, "'.indent(2)
1153 str << method.selector
1154 str << '"'
1155
1156 method.arg.each do |arg|
1157 str << ", "
1158 str << get_type(arg.type, arg.type, arg.declaredType)
1159 end unless method.arg.nil?
1160
1161 str << ")(objcObject"
1162
1163 method.arg.each do |arg|
1164 str << ", "
1165 str << get_identifier(arg.name)
1166 end unless method.arg.nil?
1167
1168 str << ")".nl.nl(false)
1169
1170 str << "if (result)".indent(2).nl(false)
1171 str << "objcObject = ret".indent(3).nl.nl(false)
1172 str << "dObject = this".indent(2).nl
1173 str << "}".indent.nl(false).nl(false)
1174 end
1131 end 1175 end
1132 1176
1133 str.string[0 .. -2] 1177 str.string[0 .. -2]
1134 end 1178 end
1135 1179