The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | #include "Type.h" |
| 2 | |
| 3 | Namespace NAMES; |
| 4 | |
| 5 | Type* VOID_TYPE; |
| 6 | Type* BOOLEAN_TYPE; |
| 7 | Type* BYTE_TYPE; |
| 8 | Type* CHAR_TYPE; |
| 9 | Type* INT_TYPE; |
| 10 | Type* LONG_TYPE; |
| 11 | Type* FLOAT_TYPE; |
| 12 | Type* DOUBLE_TYPE; |
| 13 | Type* STRING_TYPE; |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 14 | Type* OBJECT_TYPE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | Type* CHAR_SEQUENCE_TYPE; |
| 16 | Type* TEXT_UTILS_TYPE; |
| 17 | Type* REMOTE_EXCEPTION_TYPE; |
| 18 | Type* RUNTIME_EXCEPTION_TYPE; |
| 19 | Type* IBINDER_TYPE; |
| 20 | Type* IINTERFACE_TYPE; |
| 21 | Type* BINDER_NATIVE_TYPE; |
| 22 | Type* BINDER_PROXY_TYPE; |
| 23 | Type* PARCEL_TYPE; |
| 24 | Type* PARCELABLE_INTERFACE_TYPE; |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 25 | Type* CONTEXT_TYPE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | Type* MAP_TYPE; |
| 27 | Type* LIST_TYPE; |
| 28 | Type* CLASSLOADER_TYPE; |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 29 | Type* RPC_SERVICE_BASE_TYPE; |
| 30 | Type* RPC_DATA_TYPE; |
| 31 | Type* RPC_BROKER_TYPE; |
| 32 | Type* RPC_ENDPOINT_INFO_TYPE; |
| 33 | Type* RPC_RESULT_HANDLER_TYPE; |
| 34 | Type* RPC_ERROR_TYPE; |
| 35 | Type* RPC_ERROR_LISTENER_TYPE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | Expression* NULL_VALUE; |
| 38 | Expression* THIS_VALUE; |
| 39 | Expression* SUPER_VALUE; |
| 40 | Expression* TRUE_VALUE; |
| 41 | Expression* FALSE_VALUE; |
| 42 | |
| 43 | void |
| 44 | register_base_types() |
| 45 | { |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 46 | VOID_TYPE = new BasicType("void", |
| 47 | "XXX", "XXX", "XXX", "XXX", "XXX", |
| 48 | "XXX", "XXX", "XXX", "XXX", "XXX"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | NAMES.Add(VOID_TYPE); |
| 50 | |
| 51 | BOOLEAN_TYPE = new BooleanType(); |
| 52 | NAMES.Add(BOOLEAN_TYPE); |
| 53 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 54 | BYTE_TYPE = new BasicType("byte", |
| 55 | "writeByte", "readByte", "writeByteArray", "createByteArray", "readByteArray", |
| 56 | "putByte", "getByte", "putByteArray", "createByteArray", "getByteArray"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | NAMES.Add(BYTE_TYPE); |
| 58 | |
| 59 | CHAR_TYPE = new CharType(); |
| 60 | NAMES.Add(CHAR_TYPE); |
| 61 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 62 | INT_TYPE = new BasicType("int", |
| 63 | "writeInt", "readInt", "writeIntArray", "createIntArray", "readIntArray", |
| 64 | "putInteger", "getInteger", "putIntegerArray", "createIntegerArray", "getIntegerArray"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | NAMES.Add(INT_TYPE); |
| 66 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 67 | LONG_TYPE = new BasicType("long", |
| 68 | "writeLong", "readLong", "writeLongArray", "createLongArray", "readLongArray", |
| 69 | "putLong", "getLong", "putLongArray", "createLongArray", "getLongArray"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | NAMES.Add(LONG_TYPE); |
| 71 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 72 | FLOAT_TYPE = new BasicType("float", |
| 73 | "writeFloat", "readFloat", "writeFloatArray", "createFloatArray", "readFloatArray", |
| 74 | "putFloat", "getFloat", "putFloatArray", "createFloatArray", "getFloatArray"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | NAMES.Add(FLOAT_TYPE); |
| 76 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 77 | DOUBLE_TYPE = new BasicType("double", |
| 78 | "writeDouble", "readDouble", "writeDoubleArray", "createDoubleArray", "readDoubleArray", |
| 79 | "putDouble", "getDouble", "putDoubleArray", "createDoubleArray", "getDoubleArray"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | NAMES.Add(DOUBLE_TYPE); |
| 81 | |
| 82 | STRING_TYPE = new StringType(); |
| 83 | NAMES.Add(STRING_TYPE); |
| 84 | |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 85 | OBJECT_TYPE = new Type("java.lang", "Object", |
| 86 | Type::BUILT_IN, false, false); |
| 87 | NAMES.Add(OBJECT_TYPE); |
| 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | CHAR_SEQUENCE_TYPE = new CharSequenceType(); |
| 90 | NAMES.Add(CHAR_SEQUENCE_TYPE); |
| 91 | |
| 92 | MAP_TYPE = new MapType(); |
| 93 | NAMES.Add(MAP_TYPE); |
| 94 | |
| 95 | LIST_TYPE = new ListType(); |
| 96 | NAMES.Add(LIST_TYPE); |
| 97 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 98 | TEXT_UTILS_TYPE = new Type("android.text", "TextUtils", Type::BUILT_IN, false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | NAMES.Add(TEXT_UTILS_TYPE); |
| 100 | |
| 101 | REMOTE_EXCEPTION_TYPE = new RemoteExceptionType(); |
| 102 | NAMES.Add(REMOTE_EXCEPTION_TYPE); |
| 103 | |
| 104 | RUNTIME_EXCEPTION_TYPE = new RuntimeExceptionType(); |
| 105 | NAMES.Add(RUNTIME_EXCEPTION_TYPE); |
| 106 | |
| 107 | IBINDER_TYPE = new IBinderType(); |
| 108 | NAMES.Add(IBINDER_TYPE); |
| 109 | |
| 110 | IINTERFACE_TYPE = new IInterfaceType(); |
| 111 | NAMES.Add(IINTERFACE_TYPE); |
| 112 | |
| 113 | BINDER_NATIVE_TYPE = new BinderType(); |
| 114 | NAMES.Add(BINDER_NATIVE_TYPE); |
| 115 | |
| 116 | BINDER_PROXY_TYPE = new BinderProxyType(); |
| 117 | NAMES.Add(BINDER_PROXY_TYPE); |
| 118 | |
| 119 | PARCEL_TYPE = new ParcelType(); |
| 120 | NAMES.Add(PARCEL_TYPE); |
| 121 | |
| 122 | PARCELABLE_INTERFACE_TYPE = new ParcelableInterfaceType(); |
| 123 | NAMES.Add(PARCELABLE_INTERFACE_TYPE); |
| 124 | |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 125 | CONTEXT_TYPE = new Type("android.content", "Context", |
| 126 | Type::BUILT_IN, false, false); |
| 127 | NAMES.Add(CONTEXT_TYPE); |
| 128 | |
| 129 | RPC_SERVICE_BASE_TYPE = new Type("com.android.athome.service", "AndroidAtHomeService", |
| 130 | Type::BUILT_IN, false, false); |
| 131 | NAMES.Add(RPC_SERVICE_BASE_TYPE); |
| 132 | |
Joe Onorato | 1eb7204 | 2011-09-06 11:01:17 -0700 | [diff] [blame^] | 133 | RPC_DATA_TYPE = new RpcDataType(); |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 134 | NAMES.Add(RPC_DATA_TYPE); |
| 135 | |
| 136 | RPC_BROKER_TYPE = new Type("com.android.athome.utils", "AndroidAtHomeBroker", |
| 137 | Type::BUILT_IN, false, false); |
| 138 | NAMES.Add(RPC_BROKER_TYPE); |
| 139 | |
| 140 | RPC_ENDPOINT_INFO_TYPE = new ParcelableType("com.android.athome.rpc", "EndpointInfo", |
| 141 | true, __FILE__, __LINE__); |
| 142 | NAMES.Add(RPC_ENDPOINT_INFO_TYPE); |
| 143 | |
| 144 | RPC_RESULT_HANDLER_TYPE = new ParcelableType("com.android.athome.rpc", "RpcResultHandler", |
| 145 | true, __FILE__, __LINE__); |
| 146 | NAMES.Add(RPC_RESULT_HANDLER_TYPE); |
| 147 | |
| 148 | RPC_ERROR_TYPE = new ParcelableType("com.android.athome.rpc", "RpcError", |
| 149 | true, __FILE__, __LINE__); |
| 150 | NAMES.Add(RPC_ERROR_TYPE); |
| 151 | |
| 152 | RPC_ERROR_LISTENER_TYPE = new Type("com.android.athome.rpc", "RpcErrorHandler", |
| 153 | Type::BUILT_IN, false, false); |
| 154 | NAMES.Add(RPC_ERROR_LISTENER_TYPE); |
| 155 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | CLASSLOADER_TYPE = new ClassLoaderType(); |
| 157 | NAMES.Add(CLASSLOADER_TYPE); |
| 158 | |
| 159 | NULL_VALUE = new LiteralExpression("null"); |
| 160 | THIS_VALUE = new LiteralExpression("this"); |
| 161 | SUPER_VALUE = new LiteralExpression("super"); |
| 162 | TRUE_VALUE = new LiteralExpression("true"); |
| 163 | FALSE_VALUE = new LiteralExpression("false"); |
| 164 | |
| 165 | NAMES.AddGenericType("java.util", "List", 1); |
| 166 | NAMES.AddGenericType("java.util", "Map", 2); |
| 167 | } |
| 168 | |
| 169 | static Type* |
| 170 | make_generic_type(const string& package, const string& name, |
| 171 | const vector<Type*>& args) |
| 172 | { |
| 173 | if (package == "java.util" && name == "List") { |
| 174 | return new GenericListType("java.util", "List", args); |
| 175 | } |
| 176 | return NULL; |
| 177 | //return new GenericType(package, name, args); |
| 178 | } |
| 179 | |
| 180 | // ================================================================ |
| 181 | |
| 182 | Type::Type(const string& name, int kind, bool canWriteToParcel, bool canBeOut) |
| 183 | :m_package(), |
| 184 | m_name(name), |
| 185 | m_declFile(""), |
| 186 | m_declLine(-1), |
| 187 | m_kind(kind), |
| 188 | m_canWriteToParcel(canWriteToParcel), |
| 189 | m_canBeOut(canBeOut) |
| 190 | { |
| 191 | m_qualifiedName = name; |
| 192 | } |
| 193 | |
| 194 | Type::Type(const string& package, const string& name, |
| 195 | int kind, bool canWriteToParcel, bool canBeOut, |
| 196 | const string& declFile, int declLine) |
| 197 | :m_package(package), |
| 198 | m_name(name), |
| 199 | m_declFile(declFile), |
| 200 | m_declLine(declLine), |
| 201 | m_kind(kind), |
| 202 | m_canWriteToParcel(canWriteToParcel), |
| 203 | m_canBeOut(canBeOut) |
| 204 | { |
| 205 | if (package.length() > 0) { |
| 206 | m_qualifiedName = package; |
| 207 | m_qualifiedName += '.'; |
| 208 | } |
| 209 | m_qualifiedName += name; |
| 210 | } |
| 211 | |
| 212 | Type::~Type() |
| 213 | { |
| 214 | } |
| 215 | |
| 216 | bool |
| 217 | Type::CanBeArray() const |
| 218 | { |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | string |
| 223 | Type::ImportType() const |
| 224 | { |
| 225 | return m_qualifiedName; |
| 226 | } |
| 227 | |
| 228 | string |
| 229 | Type::CreatorName() const |
| 230 | { |
| 231 | return ""; |
| 232 | } |
| 233 | |
| 234 | string |
| 235 | Type::InstantiableName() const |
| 236 | { |
| 237 | return QualifiedName(); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | void |
| 242 | Type::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 243 | { |
| 244 | fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%sn", |
| 245 | __FILE__, __LINE__, m_qualifiedName.c_str()); |
| 246 | addTo->Add(new LiteralExpression("/* WriteToParcel error " |
| 247 | + m_qualifiedName + " */")); |
| 248 | } |
| 249 | |
| 250 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 251 | Type::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | { |
| 253 | fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", |
| 254 | __FILE__, __LINE__, m_qualifiedName.c_str()); |
| 255 | addTo->Add(new LiteralExpression("/* CreateFromParcel error " |
| 256 | + m_qualifiedName + " */")); |
| 257 | } |
| 258 | |
| 259 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 260 | Type::ReadFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | { |
| 262 | fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", |
| 263 | __FILE__, __LINE__, m_qualifiedName.c_str()); |
| 264 | addTo->Add(new LiteralExpression("/* ReadFromParcel error " |
| 265 | + m_qualifiedName + " */")); |
| 266 | } |
| 267 | |
| 268 | void |
| 269 | Type::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 270 | { |
| 271 | fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", |
| 272 | __FILE__, __LINE__, m_qualifiedName.c_str()); |
| 273 | addTo->Add(new LiteralExpression("/* WriteArrayToParcel error " |
| 274 | + m_qualifiedName + " */")); |
| 275 | } |
| 276 | |
| 277 | void |
| 278 | Type::CreateArrayFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 279 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | { |
| 281 | fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", |
| 282 | __FILE__, __LINE__, m_qualifiedName.c_str()); |
| 283 | addTo->Add(new LiteralExpression("/* CreateArrayFromParcel error " |
| 284 | + m_qualifiedName + " */")); |
| 285 | } |
| 286 | |
| 287 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 288 | Type::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | { |
| 290 | fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", |
| 291 | __FILE__, __LINE__, m_qualifiedName.c_str()); |
| 292 | addTo->Add(new LiteralExpression("/* ReadArrayFromParcel error " |
| 293 | + m_qualifiedName + " */")); |
| 294 | } |
| 295 | |
| 296 | void |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 297 | Type::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 298 | Variable* data, int flags) |
| 299 | { |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 300 | fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 301 | __FILE__, __LINE__, m_qualifiedName.c_str()); |
| 302 | addTo->Add(new LiteralExpression("/* WriteToRpcData error " |
| 303 | + m_qualifiedName + " */")); |
| 304 | } |
| 305 | |
| 306 | void |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 307 | Type::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, |
| 308 | Variable** cl) |
| 309 | { |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 310 | fprintf(stderr, "aidl:internal error %s:%d qualifiedName=%s\n", |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 311 | __FILE__, __LINE__, m_qualifiedName.c_str()); |
| 312 | addTo->Add(new LiteralExpression("/* ReadFromRpcData error " |
| 313 | + m_qualifiedName + " */")); |
| 314 | } |
| 315 | |
| 316 | void |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | Type::SetQualifiedName(const string& qualified) |
| 318 | { |
| 319 | m_qualifiedName = qualified; |
| 320 | } |
| 321 | |
| 322 | Expression* |
| 323 | Type::BuildWriteToParcelFlags(int flags) |
| 324 | { |
| 325 | if (flags == 0) { |
| 326 | return new LiteralExpression("0"); |
| 327 | } |
| 328 | if ((flags&PARCELABLE_WRITE_RETURN_VALUE) != 0) { |
| 329 | return new FieldVariable(PARCELABLE_INTERFACE_TYPE, |
| 330 | "PARCELABLE_WRITE_RETURN_VALUE"); |
| 331 | } |
| 332 | return new LiteralExpression("0"); |
| 333 | } |
| 334 | |
| 335 | // ================================================================ |
| 336 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 337 | BasicType::BasicType(const string& name, const string& marshallParcel, |
| 338 | const string& unmarshallParcel, const string& writeArrayParcel, |
| 339 | const string& createArrayParcel, const string& readArrayParcel, |
| 340 | const string& marshallRpc, const string& unmarshallRpc, |
| 341 | const string& writeArrayRpc, const string& createArrayRpc, const string& readArrayRpc) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | :Type(name, BUILT_IN, true, false), |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 343 | m_marshallParcel(marshallParcel), |
| 344 | m_unmarshallParcel(unmarshallParcel), |
| 345 | m_writeArrayParcel(writeArrayParcel), |
| 346 | m_createArrayParcel(createArrayParcel), |
| 347 | m_readArrayParcel(readArrayParcel), |
| 348 | m_marshallRpc(marshallRpc), |
| 349 | m_unmarshallRpc(unmarshallRpc), |
| 350 | m_writeArrayRpc(writeArrayRpc), |
| 351 | m_createArrayRpc(createArrayRpc), |
| 352 | m_readArrayRpc(readArrayRpc) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | { |
| 354 | } |
| 355 | |
| 356 | void |
| 357 | BasicType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 358 | { |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 359 | addTo->Add(new MethodCall(parcel, m_marshallParcel, 1, v)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 363 | BasicType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | { |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 365 | addTo->Add(new Assignment(v, new MethodCall(parcel, m_unmarshallParcel))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | bool |
| 369 | BasicType::CanBeArray() const |
| 370 | { |
| 371 | return true; |
| 372 | } |
| 373 | |
| 374 | void |
| 375 | BasicType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 376 | { |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 377 | addTo->Add(new MethodCall(parcel, m_writeArrayParcel, 1, v)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void |
| 381 | BasicType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 382 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | { |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 384 | addTo->Add(new Assignment(v, new MethodCall(parcel, m_createArrayParcel))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 388 | BasicType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | { |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 390 | addTo->Add(new MethodCall(parcel, m_readArrayParcel, 1, v)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | } |
| 392 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 393 | void |
| 394 | BasicType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 395 | Variable* data, int flags) |
| 396 | { |
| 397 | addTo->Add(new MethodCall(data, m_marshallRpc, 2, k, v)); |
| 398 | } |
| 399 | |
| 400 | void |
| 401 | BasicType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, |
| 402 | Variable** cl) |
| 403 | { |
| 404 | addTo->Add(new Assignment(v, new MethodCall(data, m_unmarshallRpc, 1, k))); |
| 405 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | |
| 407 | // ================================================================ |
| 408 | |
| 409 | BooleanType::BooleanType() |
| 410 | :Type("boolean", BUILT_IN, true, false) |
| 411 | { |
| 412 | } |
| 413 | |
| 414 | void |
| 415 | BooleanType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 416 | { |
| 417 | addTo->Add(new MethodCall(parcel, "writeInt", 1, |
| 418 | new Ternary(v, new LiteralExpression("1"), |
| 419 | new LiteralExpression("0")))); |
| 420 | } |
| 421 | |
| 422 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 423 | BooleanType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | { |
| 425 | addTo->Add(new Assignment(v, new Comparison(new LiteralExpression("0"), |
| 426 | "!=", new MethodCall(parcel, "readInt")))); |
| 427 | } |
| 428 | |
| 429 | bool |
| 430 | BooleanType::CanBeArray() const |
| 431 | { |
| 432 | return true; |
| 433 | } |
| 434 | |
| 435 | void |
| 436 | BooleanType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 437 | { |
| 438 | addTo->Add(new MethodCall(parcel, "writeBooleanArray", 1, v)); |
| 439 | } |
| 440 | |
| 441 | void |
| 442 | BooleanType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 443 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | { |
| 445 | addTo->Add(new Assignment(v, new MethodCall(parcel, "createBooleanArray"))); |
| 446 | } |
| 447 | |
| 448 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 449 | BooleanType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | { |
| 451 | addTo->Add(new MethodCall(parcel, "readBooleanArray", 1, v)); |
| 452 | } |
| 453 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 454 | void |
| 455 | BooleanType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 456 | Variable* data, int flags) |
| 457 | { |
| 458 | addTo->Add(new MethodCall(data, "putBoolean", 2, k, v)); |
| 459 | } |
| 460 | |
| 461 | void |
| 462 | BooleanType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, |
| 463 | Variable** cl) |
| 464 | { |
| 465 | addTo->Add(new Assignment(v, new MethodCall(data, "getBoolean", 1, k))); |
| 466 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | |
| 468 | // ================================================================ |
| 469 | |
| 470 | CharType::CharType() |
| 471 | :Type("char", BUILT_IN, true, false) |
| 472 | { |
| 473 | } |
| 474 | |
| 475 | void |
| 476 | CharType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 477 | { |
| 478 | addTo->Add(new MethodCall(parcel, "writeInt", 1, |
| 479 | new Cast(INT_TYPE, v))); |
| 480 | } |
| 481 | |
| 482 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 483 | CharType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | { |
| 485 | addTo->Add(new Assignment(v, new MethodCall(parcel, "readInt"), this)); |
| 486 | } |
| 487 | |
| 488 | bool |
| 489 | CharType::CanBeArray() const |
| 490 | { |
| 491 | return true; |
| 492 | } |
| 493 | |
| 494 | void |
| 495 | CharType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 496 | { |
| 497 | addTo->Add(new MethodCall(parcel, "writeCharArray", 1, v)); |
| 498 | } |
| 499 | |
| 500 | void |
| 501 | CharType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 502 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | { |
| 504 | addTo->Add(new Assignment(v, new MethodCall(parcel, "createCharArray"))); |
| 505 | } |
| 506 | |
| 507 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 508 | CharType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | { |
| 510 | addTo->Add(new MethodCall(parcel, "readCharArray", 1, v)); |
| 511 | } |
| 512 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 513 | void |
| 514 | CharType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 515 | Variable* data, int flags) |
| 516 | { |
| 517 | addTo->Add(new MethodCall(data, "putChar", 2, k, v)); |
| 518 | } |
| 519 | |
| 520 | void |
| 521 | CharType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, |
| 522 | Variable** cl) |
| 523 | { |
| 524 | addTo->Add(new Assignment(v, new MethodCall(data, "getChar", 1, k))); |
| 525 | } |
| 526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | // ================================================================ |
| 528 | |
| 529 | StringType::StringType() |
| 530 | :Type("java.lang", "String", BUILT_IN, true, false) |
| 531 | { |
| 532 | } |
| 533 | |
| 534 | string |
| 535 | StringType::CreatorName() const |
| 536 | { |
| 537 | return "android.os.Parcel.STRING_CREATOR"; |
| 538 | } |
| 539 | |
| 540 | void |
| 541 | StringType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 542 | { |
| 543 | addTo->Add(new MethodCall(parcel, "writeString", 1, v)); |
| 544 | } |
| 545 | |
| 546 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 547 | StringType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | { |
| 549 | addTo->Add(new Assignment(v, new MethodCall(parcel, "readString"))); |
| 550 | } |
| 551 | |
| 552 | bool |
| 553 | StringType::CanBeArray() const |
| 554 | { |
| 555 | return true; |
| 556 | } |
| 557 | |
| 558 | void |
| 559 | StringType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 560 | { |
| 561 | addTo->Add(new MethodCall(parcel, "writeStringArray", 1, v)); |
| 562 | } |
| 563 | |
| 564 | void |
| 565 | StringType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 566 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | { |
| 568 | addTo->Add(new Assignment(v, new MethodCall(parcel, "createStringArray"))); |
| 569 | } |
| 570 | |
| 571 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 572 | StringType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | { |
| 574 | addTo->Add(new MethodCall(parcel, "readStringArray", 1, v)); |
| 575 | } |
| 576 | |
Joe Onorato | fdfe2ff | 2011-08-30 17:24:17 -0700 | [diff] [blame] | 577 | void |
| 578 | StringType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 579 | Variable* data, int flags) |
| 580 | { |
| 581 | addTo->Add(new MethodCall(data, "putString", 2, k, v)); |
| 582 | } |
| 583 | |
| 584 | void |
| 585 | StringType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 586 | Variable* data, Variable**) |
| 587 | { |
| 588 | addTo->Add(new Assignment(v, new MethodCall(data, "getString", 1, k))); |
| 589 | } |
| 590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | // ================================================================ |
| 592 | |
| 593 | CharSequenceType::CharSequenceType() |
| 594 | :Type("java.lang", "CharSequence", BUILT_IN, true, false) |
| 595 | { |
| 596 | } |
| 597 | |
| 598 | string |
| 599 | CharSequenceType::CreatorName() const |
| 600 | { |
| 601 | return "android.os.Parcel.STRING_CREATOR"; |
| 602 | } |
| 603 | |
| 604 | void |
| 605 | CharSequenceType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 606 | { |
| 607 | // if (v != null) { |
| 608 | // parcel.writeInt(1); |
| 609 | // v.writeToParcel(parcel); |
| 610 | // } else { |
| 611 | // parcel.writeInt(0); |
| 612 | // } |
| 613 | IfStatement* elsepart = new IfStatement(); |
| 614 | elsepart->statements->Add(new MethodCall(parcel, "writeInt", 1, |
| 615 | new LiteralExpression("0"))); |
| 616 | IfStatement* ifpart = new IfStatement; |
| 617 | ifpart->expression = new Comparison(v, "!=", NULL_VALUE); |
| 618 | ifpart->elseif = elsepart; |
| 619 | ifpart->statements->Add(new MethodCall(parcel, "writeInt", 1, |
| 620 | new LiteralExpression("1"))); |
| 621 | ifpart->statements->Add(new MethodCall(TEXT_UTILS_TYPE, "writeToParcel", |
| 622 | 3, v, parcel, BuildWriteToParcelFlags(flags))); |
| 623 | |
| 624 | addTo->Add(ifpart); |
| 625 | } |
| 626 | |
| 627 | void |
| 628 | CharSequenceType::CreateFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 629 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | { |
| 631 | // if (0 != parcel.readInt()) { |
| 632 | // v = TextUtils.createFromParcel(parcel) |
| 633 | // } else { |
| 634 | // v = null; |
| 635 | // } |
| 636 | IfStatement* elsepart = new IfStatement(); |
| 637 | elsepart->statements->Add(new Assignment(v, NULL_VALUE)); |
| 638 | |
| 639 | IfStatement* ifpart = new IfStatement(); |
| 640 | ifpart->expression = new Comparison(new LiteralExpression("0"), "!=", |
| 641 | new MethodCall(parcel, "readInt")); |
| 642 | ifpart->elseif = elsepart; |
| 643 | ifpart->statements->Add(new Assignment(v, |
| 644 | new MethodCall(TEXT_UTILS_TYPE, |
| 645 | "CHAR_SEQUENCE_CREATOR.createFromParcel", 1, parcel))); |
| 646 | |
| 647 | addTo->Add(ifpart); |
| 648 | } |
| 649 | |
| 650 | |
| 651 | // ================================================================ |
| 652 | |
| 653 | RemoteExceptionType::RemoteExceptionType() |
| 654 | :Type("android.os", "RemoteException", BUILT_IN, false, false) |
| 655 | { |
| 656 | } |
| 657 | |
| 658 | void |
| 659 | RemoteExceptionType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 660 | { |
| 661 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 662 | } |
| 663 | |
| 664 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 665 | RemoteExceptionType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | { |
| 667 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 668 | } |
| 669 | |
| 670 | // ================================================================ |
| 671 | |
| 672 | RuntimeExceptionType::RuntimeExceptionType() |
| 673 | :Type("java.lang", "RuntimeException", BUILT_IN, false, false) |
| 674 | { |
| 675 | } |
| 676 | |
| 677 | void |
| 678 | RuntimeExceptionType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 679 | { |
| 680 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 681 | } |
| 682 | |
| 683 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 684 | RuntimeExceptionType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | { |
| 686 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 687 | } |
| 688 | |
| 689 | |
| 690 | // ================================================================ |
| 691 | |
| 692 | IBinderType::IBinderType() |
| 693 | :Type("android.os", "IBinder", BUILT_IN, true, false) |
| 694 | { |
| 695 | } |
| 696 | |
| 697 | void |
| 698 | IBinderType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 699 | { |
| 700 | addTo->Add(new MethodCall(parcel, "writeStrongBinder", 1, v)); |
| 701 | } |
| 702 | |
| 703 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 704 | IBinderType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | { |
| 706 | addTo->Add(new Assignment(v, new MethodCall(parcel, "readStrongBinder"))); |
| 707 | } |
| 708 | |
| 709 | void |
| 710 | IBinderType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 711 | { |
| 712 | addTo->Add(new MethodCall(parcel, "writeBinderArray", 1, v)); |
| 713 | } |
| 714 | |
| 715 | void |
| 716 | IBinderType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 717 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | { |
| 719 | addTo->Add(new Assignment(v, new MethodCall(parcel, "createBinderArray"))); |
| 720 | } |
| 721 | |
| 722 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 723 | IBinderType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | { |
| 725 | addTo->Add(new MethodCall(parcel, "readBinderArray", 1, v)); |
| 726 | } |
| 727 | |
| 728 | |
| 729 | // ================================================================ |
| 730 | |
| 731 | IInterfaceType::IInterfaceType() |
| 732 | :Type("android.os", "IInterface", BUILT_IN, false, false) |
| 733 | { |
| 734 | } |
| 735 | |
| 736 | void |
| 737 | IInterfaceType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 738 | { |
| 739 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 740 | } |
| 741 | |
| 742 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 743 | IInterfaceType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | { |
| 745 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 746 | } |
| 747 | |
| 748 | |
| 749 | // ================================================================ |
| 750 | |
| 751 | BinderType::BinderType() |
| 752 | :Type("android.os", "Binder", BUILT_IN, false, false) |
| 753 | { |
| 754 | } |
| 755 | |
| 756 | void |
| 757 | BinderType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 758 | { |
| 759 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 760 | } |
| 761 | |
| 762 | void |
| 763 | BinderType::CreateFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 764 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | { |
| 766 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 767 | } |
| 768 | |
| 769 | |
| 770 | // ================================================================ |
| 771 | |
| 772 | BinderProxyType::BinderProxyType() |
| 773 | :Type("android.os", "BinderProxy", BUILT_IN, false, false) |
| 774 | { |
| 775 | } |
| 776 | |
| 777 | void |
| 778 | BinderProxyType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 779 | { |
| 780 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 781 | } |
| 782 | |
| 783 | void |
| 784 | BinderProxyType::CreateFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 785 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | { |
| 787 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 788 | } |
| 789 | |
| 790 | |
| 791 | // ================================================================ |
| 792 | |
| 793 | ParcelType::ParcelType() |
| 794 | :Type("android.os", "Parcel", BUILT_IN, false, false) |
| 795 | { |
| 796 | } |
| 797 | |
| 798 | void |
| 799 | ParcelType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 800 | { |
| 801 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 802 | } |
| 803 | |
| 804 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 805 | ParcelType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | { |
| 807 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 808 | } |
| 809 | |
| 810 | // ================================================================ |
| 811 | |
| 812 | ParcelableInterfaceType::ParcelableInterfaceType() |
| 813 | :Type("android.os", "Parcelable", BUILT_IN, false, false) |
| 814 | { |
| 815 | } |
| 816 | |
| 817 | void |
| 818 | ParcelableInterfaceType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 819 | { |
| 820 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 821 | } |
| 822 | |
| 823 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 824 | ParcelableInterfaceType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | { |
| 826 | fprintf(stderr, "aidl:internal error %s:%d\n", __FILE__, __LINE__); |
| 827 | } |
| 828 | |
| 829 | // ================================================================ |
| 830 | |
| 831 | MapType::MapType() |
| 832 | :Type("java.util", "Map", BUILT_IN, true, true) |
| 833 | { |
| 834 | } |
| 835 | |
| 836 | void |
| 837 | MapType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 838 | { |
| 839 | addTo->Add(new MethodCall(parcel, "writeMap", 1, v)); |
| 840 | } |
| 841 | |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 842 | static void EnsureClassLoader(StatementBlock* addTo, Variable** cl) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | { |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 844 | // We don't want to look up the class loader once for every |
| 845 | // collection argument, so ensure we do it at most once per method. |
| 846 | if (*cl == NULL) { |
| 847 | *cl = new Variable(CLASSLOADER_TYPE, "cl"); |
| 848 | addTo->Add(new VariableDeclaration(*cl, |
| 849 | new LiteralExpression("this.getClass().getClassLoader()"), |
| 850 | CLASSLOADER_TYPE)); |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | void |
| 855 | MapType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl) |
| 856 | { |
| 857 | EnsureClassLoader(addTo, cl); |
| 858 | addTo->Add(new Assignment(v, new MethodCall(parcel, "readHashMap", 1, *cl))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | void |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 862 | MapType::ReadFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | { |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 864 | EnsureClassLoader(addTo, cl); |
| 865 | addTo->Add(new MethodCall(parcel, "readMap", 2, v, *cl)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | |
| 869 | // ================================================================ |
| 870 | |
| 871 | ListType::ListType() |
| 872 | :Type("java.util", "List", BUILT_IN, true, true) |
| 873 | { |
| 874 | } |
| 875 | |
| 876 | string |
| 877 | ListType::InstantiableName() const |
| 878 | { |
| 879 | return "java.util.ArrayList"; |
| 880 | } |
| 881 | |
| 882 | void |
| 883 | ListType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 884 | { |
| 885 | addTo->Add(new MethodCall(parcel, "writeList", 1, v)); |
| 886 | } |
| 887 | |
| 888 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 889 | ListType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable** cl) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | { |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 891 | EnsureClassLoader(addTo, cl); |
| 892 | addTo->Add(new Assignment(v, new MethodCall(parcel, "readArrayList", 1, *cl))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | void |
| 896 | ListType::ReadFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 897 | Variable* parcel, Variable** cl) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | { |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 899 | EnsureClassLoader(addTo, cl); |
| 900 | addTo->Add(new MethodCall(parcel, "readList", 2, v, *cl)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | } |
| 902 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 903 | void |
| 904 | ListType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 905 | Variable* data, int flags) |
| 906 | { |
| 907 | addTo->Add(new MethodCall(data, "putList", 2, k, v)); |
| 908 | } |
| 909 | |
| 910 | void |
| 911 | ListType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, |
| 912 | Variable** cl) |
| 913 | { |
| 914 | addTo->Add(new Assignment(v, new MethodCall(data, "getList", 1, k))); |
| 915 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | |
| 917 | // ================================================================ |
| 918 | |
| 919 | ParcelableType::ParcelableType(const string& package, const string& name, |
| 920 | bool builtIn, const string& declFile, int declLine) |
| 921 | :Type(package, name, builtIn ? BUILT_IN : PARCELABLE, true, true, |
| 922 | declFile, declLine) |
| 923 | { |
| 924 | } |
| 925 | |
| 926 | string |
| 927 | ParcelableType::CreatorName() const |
| 928 | { |
| 929 | return QualifiedName() + ".CREATOR"; |
| 930 | } |
| 931 | |
| 932 | void |
| 933 | ParcelableType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 934 | { |
| 935 | // if (v != null) { |
| 936 | // parcel.writeInt(1); |
| 937 | // v.writeToParcel(parcel); |
| 938 | // } else { |
| 939 | // parcel.writeInt(0); |
| 940 | // } |
| 941 | IfStatement* elsepart = new IfStatement(); |
| 942 | elsepart->statements->Add(new MethodCall(parcel, "writeInt", 1, |
| 943 | new LiteralExpression("0"))); |
| 944 | IfStatement* ifpart = new IfStatement; |
| 945 | ifpart->expression = new Comparison(v, "!=", NULL_VALUE); |
| 946 | ifpart->elseif = elsepart; |
| 947 | ifpart->statements->Add(new MethodCall(parcel, "writeInt", 1, |
| 948 | new LiteralExpression("1"))); |
| 949 | ifpart->statements->Add(new MethodCall(v, "writeToParcel", 2, |
| 950 | parcel, BuildWriteToParcelFlags(flags))); |
| 951 | |
| 952 | addTo->Add(ifpart); |
| 953 | } |
| 954 | |
| 955 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 956 | ParcelableType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 957 | { |
| 958 | // if (0 != parcel.readInt()) { |
| 959 | // v = CLASS.CREATOR.createFromParcel(parcel) |
| 960 | // } else { |
| 961 | // v = null; |
| 962 | // } |
| 963 | IfStatement* elsepart = new IfStatement(); |
| 964 | elsepart->statements->Add(new Assignment(v, NULL_VALUE)); |
| 965 | |
| 966 | IfStatement* ifpart = new IfStatement(); |
| 967 | ifpart->expression = new Comparison(new LiteralExpression("0"), "!=", |
| 968 | new MethodCall(parcel, "readInt")); |
| 969 | ifpart->elseif = elsepart; |
| 970 | ifpart->statements->Add(new Assignment(v, |
| 971 | new MethodCall(v->type, "CREATOR.createFromParcel", 1, parcel))); |
| 972 | |
| 973 | addTo->Add(ifpart); |
| 974 | } |
| 975 | |
| 976 | void |
| 977 | ParcelableType::ReadFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 978 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | { |
| 980 | // TODO: really, we don't need to have this extra check, but we |
| 981 | // don't have two separate marshalling code paths |
| 982 | // if (0 != parcel.readInt()) { |
| 983 | // v.readFromParcel(parcel) |
| 984 | // } |
| 985 | IfStatement* ifpart = new IfStatement(); |
| 986 | ifpart->expression = new Comparison(new LiteralExpression("0"), "!=", |
| 987 | new MethodCall(parcel, "readInt")); |
| 988 | ifpart->statements->Add(new MethodCall(v, "readFromParcel", 1, parcel)); |
| 989 | addTo->Add(ifpart); |
| 990 | } |
| 991 | |
| 992 | bool |
| 993 | ParcelableType::CanBeArray() const |
| 994 | { |
| 995 | return true; |
| 996 | } |
| 997 | |
| 998 | void |
| 999 | ParcelableType::WriteArrayToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 1000 | { |
| 1001 | addTo->Add(new MethodCall(parcel, "writeTypedArray", 2, v, |
| 1002 | BuildWriteToParcelFlags(flags))); |
| 1003 | } |
| 1004 | |
| 1005 | void |
| 1006 | ParcelableType::CreateArrayFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 1007 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | { |
| 1009 | string creator = v->type->QualifiedName() + ".CREATOR"; |
| 1010 | addTo->Add(new Assignment(v, new MethodCall(parcel, |
| 1011 | "createTypedArray", 1, new LiteralExpression(creator)))); |
| 1012 | } |
| 1013 | |
| 1014 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 1015 | ParcelableType::ReadArrayFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | { |
| 1017 | string creator = v->type->QualifiedName() + ".CREATOR"; |
| 1018 | addTo->Add(new MethodCall(parcel, "readTypedArray", 2, |
| 1019 | v, new LiteralExpression(creator))); |
| 1020 | } |
| 1021 | |
| 1022 | |
| 1023 | // ================================================================ |
| 1024 | |
| 1025 | InterfaceType::InterfaceType(const string& package, const string& name, |
| 1026 | bool builtIn, bool oneway, |
| 1027 | const string& declFile, int declLine) |
| 1028 | :Type(package, name, builtIn ? BUILT_IN : INTERFACE, true, false, |
| 1029 | declFile, declLine) |
| 1030 | ,m_oneway(oneway) |
| 1031 | { |
| 1032 | } |
| 1033 | |
| 1034 | bool |
| 1035 | InterfaceType::OneWay() const |
| 1036 | { |
| 1037 | return m_oneway; |
| 1038 | } |
| 1039 | |
| 1040 | void |
| 1041 | InterfaceType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 1042 | { |
| 1043 | // parcel.writeStrongBinder(v != null ? v.asBinder() : null); |
| 1044 | addTo->Add(new MethodCall(parcel, "writeStrongBinder", 1, |
| 1045 | new Ternary( |
| 1046 | new Comparison(v, "!=", NULL_VALUE), |
| 1047 | new MethodCall(v, "asBinder"), |
| 1048 | NULL_VALUE))); |
| 1049 | } |
| 1050 | |
| 1051 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 1052 | InterfaceType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | { |
| 1054 | // v = Interface.asInterface(parcel.readStrongBinder()); |
| 1055 | string type = v->type->QualifiedName(); |
| 1056 | type += ".Stub"; |
| 1057 | addTo->Add(new Assignment(v, |
| 1058 | new MethodCall( NAMES.Find(type), "asInterface", 1, |
| 1059 | new MethodCall(parcel, "readStrongBinder")))); |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | // ================================================================ |
| 1064 | |
| 1065 | GenericType::GenericType(const string& package, const string& name, |
| 1066 | const vector<Type*>& args) |
| 1067 | :Type(package, name, BUILT_IN, true, true) |
| 1068 | { |
| 1069 | m_args = args; |
| 1070 | |
| 1071 | m_importName = package + '.' + name; |
| 1072 | |
| 1073 | string gen = "<"; |
| 1074 | int N = args.size(); |
| 1075 | for (int i=0; i<N; i++) { |
| 1076 | Type* t = args[i]; |
| 1077 | gen += t->QualifiedName(); |
| 1078 | if (i != N-1) { |
| 1079 | gen += ','; |
| 1080 | } |
| 1081 | } |
| 1082 | gen += '>'; |
| 1083 | m_genericArguments = gen; |
| 1084 | SetQualifiedName(m_importName + gen); |
| 1085 | } |
| 1086 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 1087 | const vector<Type*>& |
| 1088 | GenericType::GenericArgumentTypes() const |
| 1089 | { |
| 1090 | return m_args; |
| 1091 | } |
| 1092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | string |
| 1094 | GenericType::GenericArguments() const |
| 1095 | { |
| 1096 | return m_genericArguments; |
| 1097 | } |
| 1098 | |
| 1099 | string |
| 1100 | GenericType::ImportType() const |
| 1101 | { |
| 1102 | return m_importName; |
| 1103 | } |
| 1104 | |
| 1105 | void |
| 1106 | GenericType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 1107 | { |
| 1108 | fprintf(stderr, "implement GenericType::WriteToParcel\n"); |
| 1109 | } |
| 1110 | |
| 1111 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 1112 | GenericType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | { |
| 1114 | fprintf(stderr, "implement GenericType::CreateFromParcel\n"); |
| 1115 | } |
| 1116 | |
| 1117 | void |
| 1118 | GenericType::ReadFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 1119 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | { |
| 1121 | fprintf(stderr, "implement GenericType::ReadFromParcel\n"); |
| 1122 | } |
| 1123 | |
| 1124 | |
| 1125 | // ================================================================ |
| 1126 | |
| 1127 | GenericListType::GenericListType(const string& package, const string& name, |
| 1128 | const vector<Type*>& args) |
| 1129 | :GenericType(package, name, args), |
| 1130 | m_creator(args[0]->CreatorName()) |
| 1131 | { |
| 1132 | } |
| 1133 | |
| 1134 | string |
| 1135 | GenericListType::CreatorName() const |
| 1136 | { |
| 1137 | return "android.os.Parcel.arrayListCreator"; |
| 1138 | } |
| 1139 | |
| 1140 | string |
| 1141 | GenericListType::InstantiableName() const |
| 1142 | { |
| 1143 | return "java.util.ArrayList" + GenericArguments(); |
| 1144 | } |
| 1145 | |
| 1146 | void |
| 1147 | GenericListType::WriteToParcel(StatementBlock* addTo, Variable* v, Variable* parcel, int flags) |
| 1148 | { |
| 1149 | if (m_creator == STRING_TYPE->CreatorName()) { |
| 1150 | addTo->Add(new MethodCall(parcel, "writeStringList", 1, v)); |
| 1151 | } else if (m_creator == IBINDER_TYPE->CreatorName()) { |
| 1152 | addTo->Add(new MethodCall(parcel, "writeBinderList", 1, v)); |
| 1153 | } else { |
| 1154 | // parcel.writeTypedListXX(arg); |
| 1155 | addTo->Add(new MethodCall(parcel, "writeTypedList", 1, v)); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | void |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 1160 | GenericListType::CreateFromParcel(StatementBlock* addTo, Variable* v, Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | { |
| 1162 | if (m_creator == STRING_TYPE->CreatorName()) { |
| 1163 | addTo->Add(new Assignment(v, |
| 1164 | new MethodCall(parcel, "createStringArrayList", 0))); |
| 1165 | } else if (m_creator == IBINDER_TYPE->CreatorName()) { |
| 1166 | addTo->Add(new Assignment(v, |
| 1167 | new MethodCall(parcel, "createBinderArrayList", 0))); |
| 1168 | } else { |
| 1169 | // v = _data.readTypedArrayList(XXX.creator); |
| 1170 | addTo->Add(new Assignment(v, |
| 1171 | new MethodCall(parcel, "createTypedArrayList", 1, |
| 1172 | new LiteralExpression(m_creator)))); |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | void |
| 1177 | GenericListType::ReadFromParcel(StatementBlock* addTo, Variable* v, |
Elliott Hughes | b9eba86 | 2011-07-13 12:10:30 -0700 | [diff] [blame] | 1178 | Variable* parcel, Variable**) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | { |
| 1180 | if (m_creator == STRING_TYPE->CreatorName()) { |
| 1181 | addTo->Add(new MethodCall(parcel, "readStringList", 1, v)); |
| 1182 | } else if (m_creator == IBINDER_TYPE->CreatorName()) { |
| 1183 | addTo->Add(new MethodCall(parcel, "readBinderList", 1, v)); |
| 1184 | } else { |
| 1185 | // v = _data.readTypedList(v, XXX.creator); |
| 1186 | addTo->Add(new MethodCall(parcel, "readTypedList", 2, |
| 1187 | v, |
| 1188 | new LiteralExpression(m_creator))); |
| 1189 | } |
| 1190 | } |
| 1191 | |
Joe Onorato | 05ffbe7 | 2011-09-02 15:28:36 -0700 | [diff] [blame] | 1192 | void |
| 1193 | GenericListType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 1194 | Variable* data, int flags) |
| 1195 | { |
| 1196 | addTo->Add(new MethodCall(data, "putList", 2, k, v)); |
| 1197 | } |
| 1198 | |
| 1199 | void |
| 1200 | GenericListType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 1201 | Variable* data, Variable** cl) |
| 1202 | { |
| 1203 | string classArg = GenericArgumentTypes()[0]->QualifiedName(); |
| 1204 | classArg += ".class"; |
| 1205 | addTo->Add(new Assignment(v, new MethodCall(data, "getList", 2, k, |
| 1206 | new LiteralExpression(classArg)))); |
| 1207 | } |
| 1208 | |
Joe Onorato | 1eb7204 | 2011-09-06 11:01:17 -0700 | [diff] [blame^] | 1209 | |
| 1210 | // ================================================================ |
| 1211 | |
| 1212 | RpcDataType::RpcDataType() |
| 1213 | :Type("com.android.athome.rpc", "RpcData", Type::BUILT_IN, false, false) |
| 1214 | { |
| 1215 | } |
| 1216 | |
| 1217 | void |
| 1218 | RpcDataType::WriteToRpcData(StatementBlock* addTo, Expression* k, Variable* v, |
| 1219 | Variable* data, int flags) |
| 1220 | { |
| 1221 | addTo->Add(new MethodCall(data, "putRpcData", 2, k, v)); |
| 1222 | } |
| 1223 | |
| 1224 | void |
| 1225 | RpcDataType::CreateFromRpcData(StatementBlock* addTo, Expression* k, Variable* v, Variable* data, |
| 1226 | Variable** cl) |
| 1227 | { |
| 1228 | addTo->Add(new Assignment(v, new MethodCall(data, "getRpcData", 1, k))); |
| 1229 | } |
| 1230 | |
| 1231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | // ================================================================ |
| 1233 | |
| 1234 | ClassLoaderType::ClassLoaderType() |
| 1235 | :Type("java.lang", "ClassLoader", BUILT_IN, false, false) |
| 1236 | { |
| 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | // ================================================================ |
| 1241 | |
| 1242 | Namespace::Namespace() |
| 1243 | { |
| 1244 | } |
| 1245 | |
| 1246 | Namespace::~Namespace() |
| 1247 | { |
| 1248 | int N = m_types.size(); |
| 1249 | for (int i=0; i<N; i++) { |
| 1250 | delete m_types[i]; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | void |
| 1255 | Namespace::Add(Type* type) |
| 1256 | { |
| 1257 | Type* t = Find(type->QualifiedName()); |
| 1258 | if (t == NULL) { |
| 1259 | m_types.push_back(type); |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | void |
| 1264 | Namespace::AddGenericType(const string& package, const string& name, int args) |
| 1265 | { |
| 1266 | Generic g; |
| 1267 | g.package = package; |
| 1268 | g.name = name; |
| 1269 | g.qualified = package + '.' + name; |
| 1270 | g.args = args; |
| 1271 | m_generics.push_back(g); |
| 1272 | } |
| 1273 | |
| 1274 | Type* |
| 1275 | Namespace::Find(const string& name) const |
| 1276 | { |
| 1277 | int N = m_types.size(); |
| 1278 | for (int i=0; i<N; i++) { |
| 1279 | if (m_types[i]->QualifiedName() == name) { |
| 1280 | return m_types[i]; |
| 1281 | } |
| 1282 | } |
| 1283 | return NULL; |
| 1284 | } |
| 1285 | |
| 1286 | Type* |
| 1287 | Namespace::Find(const char* package, const char* name) const |
| 1288 | { |
| 1289 | string s; |
| 1290 | if (package != NULL) { |
| 1291 | s += package; |
| 1292 | s += '.'; |
| 1293 | } |
| 1294 | s += name; |
| 1295 | return Find(s); |
| 1296 | } |
| 1297 | |
| 1298 | static string |
| 1299 | normalize_generic(const string& s) |
| 1300 | { |
| 1301 | string r; |
| 1302 | int N = s.size(); |
| 1303 | for (int i=0; i<N; i++) { |
| 1304 | char c = s[i]; |
| 1305 | if (!isspace(c)) { |
| 1306 | r += c; |
| 1307 | } |
| 1308 | } |
| 1309 | return r; |
| 1310 | } |
| 1311 | |
| 1312 | Type* |
| 1313 | Namespace::Search(const string& name) |
| 1314 | { |
| 1315 | // an exact match wins |
| 1316 | Type* result = Find(name); |
| 1317 | if (result != NULL) { |
| 1318 | return result; |
| 1319 | } |
| 1320 | |
| 1321 | // try the class names |
| 1322 | // our language doesn't allow you to not specify outer classes |
| 1323 | // when referencing an inner class. that could be changed, and this |
| 1324 | // would be the place to do it, but I don't think the complexity in |
| 1325 | // scoping rules is worth it. |
| 1326 | int N = m_types.size(); |
| 1327 | for (int i=0; i<N; i++) { |
| 1328 | if (m_types[i]->Name() == name) { |
| 1329 | return m_types[i]; |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | // we got to here and it's not a generic, give up |
| 1334 | if (name.find('<') == name.npos) { |
| 1335 | return NULL; |
| 1336 | } |
| 1337 | |
| 1338 | // remove any whitespace |
| 1339 | string normalized = normalize_generic(name); |
| 1340 | |
| 1341 | // find the part before the '<', find a generic for it |
| 1342 | ssize_t baseIndex = normalized.find('<'); |
| 1343 | string base(normalized.c_str(), baseIndex); |
| 1344 | const Generic* g = search_generic(base); |
| 1345 | if (g == NULL) { |
| 1346 | return NULL; |
| 1347 | } |
| 1348 | |
| 1349 | // For each of the args, do a recursive search on it. We don't allow |
| 1350 | // generics within generics like Java does, because we're really limiting |
| 1351 | // them to just built-in container classes, at least for now. Our syntax |
| 1352 | // ensures this right now as well. |
| 1353 | vector<Type*> args; |
| 1354 | size_t start = baseIndex + 1; |
| 1355 | size_t end = start; |
| 1356 | while (normalized[start] != '\0') { |
| 1357 | end = normalized.find(',', start); |
| 1358 | if (end == normalized.npos) { |
| 1359 | end = normalized.find('>', start); |
| 1360 | } |
| 1361 | string s(normalized.c_str()+start, end-start); |
| 1362 | Type* t = this->Search(s); |
| 1363 | if (t == NULL) { |
| 1364 | // maybe we should print a warning here? |
| 1365 | return NULL; |
| 1366 | } |
| 1367 | args.push_back(t); |
| 1368 | start = end+1; |
| 1369 | } |
| 1370 | |
| 1371 | // construct a GenericType, add it to our name set so they always get |
| 1372 | // the same object, and return it. |
| 1373 | result = make_generic_type(g->package, g->name, args); |
| 1374 | if (result == NULL) { |
| 1375 | return NULL; |
| 1376 | } |
| 1377 | |
| 1378 | this->Add(result); |
| 1379 | return this->Find(result->QualifiedName()); |
| 1380 | } |
| 1381 | |
| 1382 | const Namespace::Generic* |
| 1383 | Namespace::search_generic(const string& name) const |
| 1384 | { |
| 1385 | int N = m_generics.size(); |
| 1386 | |
| 1387 | // first exact match |
| 1388 | for (int i=0; i<N; i++) { |
| 1389 | const Generic& g = m_generics[i]; |
| 1390 | if (g.qualified == name) { |
| 1391 | return &g; |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | // then name match |
| 1396 | for (int i=0; i<N; i++) { |
| 1397 | const Generic& g = m_generics[i]; |
| 1398 | if (g.name == name) { |
| 1399 | return &g; |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | return NULL; |
| 1404 | } |
| 1405 | |
| 1406 | void |
| 1407 | Namespace::Dump() const |
| 1408 | { |
| 1409 | int n = m_types.size(); |
| 1410 | for (int i=0; i<n; i++) { |
| 1411 | Type* t = m_types[i]; |
| 1412 | printf("type: package=%s name=%s qualifiedName=%s\n", |
| 1413 | t->Package().c_str(), t->Name().c_str(), |
| 1414 | t->QualifiedName().c_str()); |
| 1415 | } |
| 1416 | } |