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