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