blob: a5c1ff8e673fdfedcc24fe133f8737cbad310c87 [file] [log] [blame]
Christopher Wiley775fa1f2015-09-22 15:00:12 -07001/*
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
Steven Moreland9fccf582018-08-27 20:36:27 -070017#pragma once
Adam Lesinskiffa16862014-01-23 18:17:42 -080018
Adam Lesinskiffa16862014-01-23 18:17:42 -080019#include <string>
20#include <vector>
21
Christopher Wiley038485e2015-09-12 11:14:14 -070022#include "ast_java.h"
Christopher Wiley84c1eac2015-09-23 13:29:28 -070023#include "type_namespace.h"
Christopher Wiley038485e2015-09-12 11:14:14 -070024
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070025namespace android {
26namespace aidl {
Christopher Wileydb154a52015-09-28 16:32:25 -070027namespace java {
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070028
Christopher Wiley8b2d3ee2015-09-23 15:43:01 -070029class JavaTypeNamespace;
Christopher Wiley60b02ae2015-09-23 16:35:18 -070030
Christopher Wileyfb4b22d2015-09-25 15:16:13 -070031class Type : public ValidatableType {
Christopher Wileye6dee912015-09-22 14:50:23 -070032 public:
Christopher Wileye6dee912015-09-22 14:50:23 -070033 // WriteToParcel flags
34 enum { PARCELABLE_WRITE_RETURN_VALUE = 0x0001 };
Adam Lesinskiffa16862014-01-23 18:17:42 -080035
Jiyong Park75e1a742018-07-04 12:31:23 +090036 // defaultValue is by default set to "null" because that is the default value
37 // for most of the types like class and array. default values for built-in
38 // types like int, double, boolean, etc. are explicitly set via BasicType
Jiyong Park1d2df7d2018-07-23 15:22:50 +090039 Type(const JavaTypeNamespace* types, const std::string& name, int kind, bool canWriteToParcel);
Jiyong Park75e1a742018-07-04 12:31:23 +090040 Type(const JavaTypeNamespace* types, const std::string& package, const std::string& name,
Jiyong Park1d2df7d2018-07-23 15:22:50 +090041 int kind, bool canWriteToParcel, const std::string& declFile = "", int declLine = -1);
Christopher Wiley09af4692015-10-30 11:48:25 -070042 virtual ~Type() = default;
43
Christopher Wiley09af4692015-10-30 11:48:25 -070044 bool CanWriteToParcel() const override { return m_canWriteToParcel; }
Adam Lesinskiffa16862014-01-23 18:17:42 -080045
Casey Dahlina2f77c42015-12-01 18:26:02 -080046 const ValidatableType* ArrayType() const override { return m_array_type.get(); }
Casey Dahlin57dbe242015-12-04 11:44:02 -080047 const ValidatableType* NullableType() const override { return nullptr; }
Casey Dahlina2f77c42015-12-01 18:26:02 -080048
Christopher Wileyd21bfee2016-01-29 15:11:38 -080049 virtual std::string JavaType() const { return m_javaType; }
Christopher Wiley12e894a2016-01-29 11:55:07 -080050 virtual std::string InstantiableName() const;
Adam Lesinskiffa16862014-01-23 18:17:42 -080051
Jiyong Park75e1a742018-07-04 12:31:23 +090052 // The namespace where this type is defined in
53 const JavaTypeNamespace* GetTypeNamespace() const { return m_types; }
54
Christopher Wileye6dee912015-09-22 14:50:23 -070055 protected:
Christopher Wiley3637a4d2015-09-22 15:37:59 -070056 Expression* BuildWriteToParcelFlags(int flags) const;
Adam Lesinskiffa16862014-01-23 18:17:42 -080057
Christopher Wiley8b2d3ee2015-09-23 15:43:01 -070058 const JavaTypeNamespace* m_types;
59
Casey Dahlina2f77c42015-12-01 18:26:02 -080060 std::unique_ptr<Type> m_array_type;
61
Christopher Wileye6dee912015-09-22 14:50:23 -070062 private:
63 Type();
64 Type(const Type&);
Adam Lesinskiffa16862014-01-23 18:17:42 -080065
Christopher Wileyd21bfee2016-01-29 15:11:38 -080066 std::string m_javaType;
Christopher Wiley12e894a2016-01-29 11:55:07 -080067 std::string m_declFile;
Christopher Wileye6dee912015-09-22 14:50:23 -070068 bool m_canWriteToParcel;
Adam Lesinskiffa16862014-01-23 18:17:42 -080069};
70
Casey Dahlina2f77c42015-12-01 18:26:02 -080071class BasicArrayType : public Type {
72 public:
Christopher Wiley12e894a2016-01-29 11:55:07 -080073 BasicArrayType(const JavaTypeNamespace* types, const std::string& name,
74 const std::string& writeArrayParcel,
75 const std::string& createArrayParcel,
76 const std::string& readArrayParcel);
Casey Dahlina2f77c42015-12-01 18:26:02 -080077
Casey Dahlin57dbe242015-12-04 11:44:02 -080078 const ValidatableType* NullableType() const override { return this; }
Casey Dahlina2f77c42015-12-01 18:26:02 -080079
80 private:
Christopher Wiley12e894a2016-01-29 11:55:07 -080081 std::string m_writeArrayParcel;
82 std::string m_createArrayParcel;
83 std::string m_readArrayParcel;
Casey Dahlina2f77c42015-12-01 18:26:02 -080084};
85
Christopher Wileye6dee912015-09-22 14:50:23 -070086class BasicType : public Type {
87 public:
Christopher Wiley12e894a2016-01-29 11:55:07 -080088 BasicType(const JavaTypeNamespace* types, const std::string& name,
Jiyong Park75e1a742018-07-04 12:31:23 +090089 const std::string& marshallParcel, const std::string& unmarshallParcel,
90 const std::string& writeArrayParcel, const std::string& createArrayParcel,
Jiyong Park1d2df7d2018-07-23 15:22:50 +090091 const std::string& readArrayParcel);
Adam Lesinskiffa16862014-01-23 18:17:42 -080092
Christopher Wileye6dee912015-09-22 14:50:23 -070093 private:
Christopher Wiley12e894a2016-01-29 11:55:07 -080094 std::string m_marshallParcel;
95 std::string m_unmarshallParcel;
Casey Dahlina2f77c42015-12-01 18:26:02 -080096};
97
98class FileDescriptorArrayType : public Type {
99 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700100 explicit FileDescriptorArrayType(const JavaTypeNamespace* types);
Casey Dahlina2f77c42015-12-01 18:26:02 -0800101
Casey Dahlin57dbe242015-12-04 11:44:02 -0800102 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800103};
104
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800105class FileDescriptorType : public Type {
106 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700107 explicit FileDescriptorType(const JavaTypeNamespace* types);
Casey Dahlina2f77c42015-12-01 18:26:02 -0800108};
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800109
Jiyong Parke05195e2018-10-08 18:24:23 +0900110class ParcelFileDescriptorArrayType : public Type {
111 public:
112 explicit ParcelFileDescriptorArrayType(const JavaTypeNamespace* types);
113
114 const ValidatableType* NullableType() const override { return this; }
115};
116
117class ParcelFileDescriptorType : public Type {
118 public:
119 explicit ParcelFileDescriptorType(const JavaTypeNamespace* types);
120
121 const ValidatableType* NullableType() const override { return this; }
122};
123
Casey Dahlina2f77c42015-12-01 18:26:02 -0800124class BooleanArrayType : public Type {
125 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700126 explicit BooleanArrayType(const JavaTypeNamespace* types);
Casey Dahlin57dbe242015-12-04 11:44:02 -0800127 const ValidatableType* NullableType() const override { return this; }
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800128};
129
Christopher Wileye6dee912015-09-22 14:50:23 -0700130class BooleanType : public Type {
131 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700132 explicit BooleanType(const JavaTypeNamespace* types);
Casey Dahlina2f77c42015-12-01 18:26:02 -0800133};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800134
Casey Dahlina2f77c42015-12-01 18:26:02 -0800135class CharArrayType : public Type {
136 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700137 explicit CharArrayType(const JavaTypeNamespace* types);
Casey Dahlin57dbe242015-12-04 11:44:02 -0800138 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800139};
140
Christopher Wileye6dee912015-09-22 14:50:23 -0700141class CharType : public Type {
142 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700143 explicit CharType(const JavaTypeNamespace* types);
Casey Dahlina2f77c42015-12-01 18:26:02 -0800144};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800145
Casey Dahlina2f77c42015-12-01 18:26:02 -0800146class StringArrayType : public Type {
147 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700148 explicit StringArrayType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800149
Casey Dahlin57dbe242015-12-04 11:44:02 -0800150 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800151};
152
Christopher Wileye6dee912015-09-22 14:50:23 -0700153class StringType : public Type {
154 public:
Christopher Wiley9f403722016-01-27 16:04:11 -0800155 StringType(const JavaTypeNamespace* types, const std::string& package,
156 const std::string& class_name);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800157
Christopher Wileyd21bfee2016-01-29 15:11:38 -0800158 std::string JavaType() const override { return "java.lang.String"; }
Casey Dahlin57dbe242015-12-04 11:44:02 -0800159 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800160};
161
Christopher Wileye6dee912015-09-22 14:50:23 -0700162class CharSequenceType : public Type {
163 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700164 explicit CharSequenceType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800165};
166
Christopher Wileye6dee912015-09-22 14:50:23 -0700167class RemoteExceptionType : public Type {
168 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700169 explicit RemoteExceptionType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800170};
171
Christopher Wileye6dee912015-09-22 14:50:23 -0700172class RuntimeExceptionType : public Type {
173 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700174 explicit RuntimeExceptionType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800175};
176
Casey Dahlina2f77c42015-12-01 18:26:02 -0800177class IBinderArrayType : public Type {
178 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700179 explicit IBinderArrayType(const JavaTypeNamespace* types);
Casey Dahlin57dbe242015-12-04 11:44:02 -0800180 const ValidatableType* NullableType() const override { return this; }
Casey Dahlina2f77c42015-12-01 18:26:02 -0800181};
182
Christopher Wileye6dee912015-09-22 14:50:23 -0700183class IBinderType : public Type {
184 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700185 explicit IBinderType(const JavaTypeNamespace* types);
Christopher Wileyd646e0b2016-03-09 09:24:55 -0800186 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800187};
188
Christopher Wileye6dee912015-09-22 14:50:23 -0700189class IInterfaceType : public Type {
190 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700191 explicit IInterfaceType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800192};
193
Christopher Wileye6dee912015-09-22 14:50:23 -0700194class BinderType : public Type {
195 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700196 explicit BinderType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800197};
198
Christopher Wileye6dee912015-09-22 14:50:23 -0700199class BinderProxyType : public Type {
200 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700201 explicit BinderProxyType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800202};
203
Christopher Wileye6dee912015-09-22 14:50:23 -0700204class ParcelType : public Type {
205 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700206 explicit ParcelType(const JavaTypeNamespace* types);
Casey Dahlin57dbe242015-12-04 11:44:02 -0800207 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800208};
209
Christopher Wileye6dee912015-09-22 14:50:23 -0700210class ParcelableInterfaceType : public Type {
211 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700212 explicit ParcelableInterfaceType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800213};
214
Christopher Wileye6dee912015-09-22 14:50:23 -0700215class MapType : public Type {
216 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700217 explicit MapType(const JavaTypeNamespace* types);
Casey Dahlin57dbe242015-12-04 11:44:02 -0800218 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800219};
220
Christopher Wileye6dee912015-09-22 14:50:23 -0700221class ListType : public Type {
222 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700223 explicit ListType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800224
Christopher Wiley12e894a2016-01-29 11:55:07 -0800225 std::string InstantiableName() const override;
Casey Dahlin57dbe242015-12-04 11:44:02 -0800226 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800227};
228
Casey Dahlina2f77c42015-12-01 18:26:02 -0800229class UserDataArrayType : public Type {
230 public:
Christopher Wiley12e894a2016-01-29 11:55:07 -0800231 UserDataArrayType(const JavaTypeNamespace* types, const std::string& package,
232 const std::string& name, bool builtIn,
233 bool canWriteToParcel, const std::string& declFile = "",
234 int declLine = -1);
Casey Dahlina2f77c42015-12-01 18:26:02 -0800235
Casey Dahlin57dbe242015-12-04 11:44:02 -0800236 const ValidatableType* NullableType() const override { return this; }
Casey Dahlina2f77c42015-12-01 18:26:02 -0800237};
238
Christopher Wileye6dee912015-09-22 14:50:23 -0700239class UserDataType : public Type {
240 public:
Christopher Wiley12e894a2016-01-29 11:55:07 -0800241 UserDataType(const JavaTypeNamespace* types, const std::string& package,
242 const std::string& name, bool builtIn, bool canWriteToParcel,
243 const std::string& declFile = "", int declLine = -1);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800244
Casey Dahlin57dbe242015-12-04 11:44:02 -0800245 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800246};
247
Christopher Wileye6dee912015-09-22 14:50:23 -0700248class InterfaceType : public Type {
249 public:
Jiyong Park75e1a742018-07-04 12:31:23 +0900250 InterfaceType(const JavaTypeNamespace* types, const std::string& package, const std::string& name,
Steven Morelandacd53472018-12-14 10:17:26 -0800251 bool builtIn, const std::string& declFile, int declLine, const Type* stub,
252 const Type* proxy, const Type* defaultImpl);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800253
Christopher Wiley01235432016-07-15 11:15:56 -0700254 const ValidatableType* NullableType() const override { return this; }
Casey Dahlina2f77c42015-12-01 18:26:02 -0800255 const Type* GetStub() const { return stub_; }
256 const Type* GetProxy() const { return proxy_; }
Jiyong Park75e1a742018-07-04 12:31:23 +0900257 const Type* GetDefaultImpl() const { return defaultImpl_; }
Christopher Wileyf690be52015-09-14 15:19:10 -0700258
Christopher Wileye6dee912015-09-22 14:50:23 -0700259 private:
Casey Dahlina2f77c42015-12-01 18:26:02 -0800260 const Type* stub_;
261 const Type* proxy_;
Jiyong Park75e1a742018-07-04 12:31:23 +0900262 const Type* defaultImpl_;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800263};
264
Christopher Wileye6dee912015-09-22 14:50:23 -0700265class ClassLoaderType : public Type {
266 public:
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700267 explicit ClassLoaderType(const JavaTypeNamespace* types);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800268};
269
Christopher Wiley09af4692015-10-30 11:48:25 -0700270class GenericListType : public Type {
Christopher Wileye6dee912015-09-22 14:50:23 -0700271 public:
Christopher Wiley09af4692015-10-30 11:48:25 -0700272 GenericListType(const JavaTypeNamespace* types, const Type* arg);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800273
Christopher Wiley12e894a2016-01-29 11:55:07 -0800274 std::string InstantiableName() const override;
Christopher Wiley5d9bc932016-02-01 13:23:16 -0800275 std::string JavaType() const override {
276 return "java.util.List<" + m_contained_type->JavaType() + ">";
277 }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800278
Casey Dahlin57dbe242015-12-04 11:44:02 -0800279 const ValidatableType* NullableType() const override { return this; }
Adam Lesinskiffa16862014-01-23 18:17:42 -0800280
Christopher Wileye6dee912015-09-22 14:50:23 -0700281 private:
Christopher Wiley09af4692015-10-30 11:48:25 -0700282 const Type* m_contained_type;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800283};
284
Christopher Wiley09af4692015-10-30 11:48:25 -0700285class JavaTypeNamespace : public LanguageTypeNamespace<Type> {
Christopher Wileye6dee912015-09-22 14:50:23 -0700286 public:
Christopher Wiley56799522015-10-31 10:17:04 -0700287 JavaTypeNamespace() = default;
Christopher Wiley09af4692015-10-30 11:48:25 -0700288 virtual ~JavaTypeNamespace() = default;
Christopher Wiley84c1eac2015-09-23 13:29:28 -0700289
Christopher Wiley56799522015-10-31 10:17:04 -0700290 void Init() override;
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800291 bool AddParcelableType(const AidlParcelable& p,
Christopher Wiley12e894a2016-01-29 11:55:07 -0800292 const std::string& filename) override;
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800293 bool AddBinderType(const AidlInterface& b,
Christopher Wiley12e894a2016-01-29 11:55:07 -0800294 const std::string& filename) override;
Christopher Wileycd8e8972015-10-26 10:24:35 -0700295 bool AddListType(const std::string& contained_type_name) override;
296 bool AddMapType(const std::string& key_type_name,
297 const std::string& value_type_name) override;
Christopher Wiley4582ecb2015-09-25 13:27:45 -0700298
Christopher Wiley60b02ae2015-09-23 16:35:18 -0700299 const Type* BoolType() const { return m_bool_type; }
300 const Type* IntType() const { return m_int_type; }
301 const Type* StringType() const { return m_string_type; }
302 const Type* TextUtilsType() const { return m_text_utils_type; }
303 const Type* RemoteExceptionType() const { return m_remote_exception_type; }
304 const Type* RuntimeExceptionType() const { return m_runtime_exception_type; }
305 const Type* IBinderType() const { return m_ibinder_type; }
306 const Type* IInterfaceType() const { return m_iinterface_type; }
307 const Type* BinderNativeType() const { return m_binder_native_type; }
308 const Type* BinderProxyType() const { return m_binder_proxy_type; }
309 const Type* ParcelType() const { return m_parcel_type; }
310 const Type* ParcelableInterfaceType() const {
311 return m_parcelable_interface_type;
312 }
313 const Type* ContextType() const { return m_context_type; }
314 const Type* ClassLoaderType() const { return m_classloader_type; }
Christopher Wiley8b2d3ee2015-09-23 15:43:01 -0700315
Christopher Wileye6dee912015-09-22 14:50:23 -0700316 private:
Christopher Wiley60b02ae2015-09-23 16:35:18 -0700317 const Type* m_bool_type{nullptr};
318 const Type* m_int_type{nullptr};
319 const Type* m_string_type{nullptr};
320 const Type* m_text_utils_type{nullptr};
321 const Type* m_remote_exception_type{nullptr};
322 const Type* m_runtime_exception_type{nullptr};
323 const Type* m_ibinder_type{nullptr};
324 const Type* m_iinterface_type{nullptr};
325 const Type* m_binder_native_type{nullptr};
326 const Type* m_binder_proxy_type{nullptr};
327 const Type* m_parcel_type{nullptr};
328 const Type* m_parcelable_interface_type{nullptr};
329 const Type* m_context_type{nullptr};
330 const Type* m_classloader_type{nullptr};
Christopher Wiley8b2d3ee2015-09-23 15:43:01 -0700331
Christopher Wiley84c1eac2015-09-23 13:29:28 -0700332 DISALLOW_COPY_AND_ASSIGN(JavaTypeNamespace);
Adam Lesinskiffa16862014-01-23 18:17:42 -0800333};
334
Adam Lesinskiffa16862014-01-23 18:17:42 -0800335extern Expression* NULL_VALUE;
336extern Expression* THIS_VALUE;
337extern Expression* SUPER_VALUE;
338extern Expression* TRUE_VALUE;
339extern Expression* FALSE_VALUE;
340
Christopher Wileydb154a52015-09-28 16:32:25 -0700341} // namespace java
Christopher Wileyfdeb0f42015-09-11 15:38:22 -0700342} // namespace aidl
343} // namespace android