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