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