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