blob: 6638e0e9ae7091ccfe52d43e38070cc93830b152 [file] [log] [blame]
Will McVickerd7d18df2019-09-12 13:40:50 -07001/*
2 * Copyright (C) 2019, 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
Christopher Wileyec31a052016-01-25 07:28:51 -080018
Jiyong Park1deecc32018-07-17 01:14:41 +090019#include "aidl_typenames.h"
Jiyong Park02da7422018-07-16 16:00:26 +090020#include "code_writer.h"
Jiyong Park1deecc32018-07-17 01:14:41 +090021#include "io_delegate.h"
Jeongik Cha047c5ee2019-08-07 23:16:49 +090022#include "options.h"
Jiyong Park1deecc32018-07-17 01:14:41 +090023
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070024#include <memory>
Jeongik Cha997281d2020-01-16 15:23:59 +090025#include <regex>
Casey Dahlindd691812015-09-09 17:59:06 -070026#include <string>
Jeongik Chadf76dc72019-11-28 00:08:47 +090027#include <unordered_set>
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070028#include <vector>
Casey Dahlindd691812015-09-09 17:59:06 -070029
Elliott Hughes0a620672015-12-04 13:53:18 -080030#include <android-base/strings.h>
Casey Dahlin73d46b02015-09-11 02:47:54 +000031
Jiyong Parkb034bf02018-07-30 17:44:33 +090032using android::aidl::AidlTypenames;
Jiyong Park02da7422018-07-16 16:00:26 +090033using android::aidl::CodeWriter;
Jeongik Cha047c5ee2019-08-07 23:16:49 +090034using android::aidl::Options;
Steven Moreland3f658cf2018-08-20 13:40:54 -070035using std::shared_ptr;
Jiyong Park1deecc32018-07-17 01:14:41 +090036using std::string;
37using std::unique_ptr;
38using std::vector;
Andrei Onea8714b022019-02-01 18:55:54 +000039class AidlNode;
40
41namespace android {
42namespace aidl {
43namespace mappings {
44std::string dump_location(const AidlNode& method);
45} // namespace mappings
Mathew Inwoodadb74672019-11-29 14:01:53 +000046namespace java {
47std::string dump_location(const AidlNode& method);
48} // namespace java
Andrei Onea8714b022019-02-01 18:55:54 +000049} // namespace aidl
50} // namespace android
51
Steven Moreland46e9da82018-07-27 15:45:29 -070052class AidlLocation {
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070053 public:
Steven Moreland46e9da82018-07-27 15:45:29 -070054 struct Point {
Dan Willemsen609ba6d2019-12-30 10:44:00 -080055 int line;
56 int column;
Steven Moreland46e9da82018-07-27 15:45:29 -070057 };
58
Devin Mooredf93ebb2020-03-25 14:03:35 -070059 enum class Source {
60 // From internal aidl source code
61 INTERNAL = 0,
62 // From a parsed file
63 EXTERNAL = 1
64 };
65
66 AidlLocation(const std::string& file, Point begin, Point end, Source source);
Devin Moore5de18ed2020-04-02 13:52:29 -070067 AidlLocation(const std::string& file, Source source)
68 : AidlLocation(file, {0, 0}, {0, 0}, source) {}
Devin Mooredf93ebb2020-03-25 14:03:35 -070069
70 bool IsInternal() const { return source_ == Source::INTERNAL; }
Steven Moreland46e9da82018-07-27 15:45:29 -070071
Devin Moore5de18ed2020-04-02 13:52:29 -070072 // The first line of a file is line 1.
73 bool LocationKnown() const { return begin_.line != 0; }
74
Steven Moreland46e9da82018-07-27 15:45:29 -070075 friend std::ostream& operator<<(std::ostream& os, const AidlLocation& l);
Andrei Onea8714b022019-02-01 18:55:54 +000076 friend class AidlNode;
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070077
78 private:
Steven Moreland541788d2020-05-21 22:05:52 +000079 // INTENTIONALLY HIDDEN: only operator<< should access details here.
80 // Otherwise, locations should only ever be copied around to construct new
81 // objects.
Steven Moreland46e9da82018-07-27 15:45:29 -070082 const std::string file_;
83 Point begin_;
84 Point end_;
Devin Mooredf93ebb2020-03-25 14:03:35 -070085 Source source_;
Steven Moreland46e9da82018-07-27 15:45:29 -070086};
87
Devin Mooredf93ebb2020-03-25 14:03:35 -070088#define AIDL_LOCATION_HERE \
Steven Moreland21780812020-09-11 01:29:45 +000089 (AidlLocation{__FILE__, {__LINE__, 0}, {__LINE__, 0}, AidlLocation::Source::INTERNAL})
Steven Moreland02e012e2018-08-02 14:58:10 -070090
Steven Moreland46e9da82018-07-27 15:45:29 -070091std::ostream& operator<<(std::ostream& os, const AidlLocation& l);
92
93// Anything that is locatable in a .aidl file.
94class AidlNode {
95 public:
96 AidlNode(const AidlLocation& location);
Steven Moreland3f658cf2018-08-20 13:40:54 -070097
98 AidlNode(const AidlNode&) = default;
Steven Moreland46e9da82018-07-27 15:45:29 -070099 virtual ~AidlNode() = default;
100
Jiyong Parkd800fef2020-07-22 18:09:43 +0900101 AidlNode(AidlNode&&) = delete;
102 AidlNode& operator=(AidlNode&&) = delete;
103
Devin Mooredf93ebb2020-03-25 14:03:35 -0700104 // To be able to print AidlLocation
Steven Morelandb0d15a52020-03-31 14:03:47 -0700105 friend class AidlErrorLog;
Andrei Onea8714b022019-02-01 18:55:54 +0000106 friend std::string android::aidl::mappings::dump_location(const AidlNode&);
Mathew Inwoodadb74672019-11-29 14:01:53 +0000107 friend std::string android::aidl::java::dump_location(const AidlNode&);
Steven Moreland46e9da82018-07-27 15:45:29 -0700108
Devin Mooredf93ebb2020-03-25 14:03:35 -0700109 const AidlLocation& GetLocation() const { return location_; }
110
Steven Moreland46e9da82018-07-27 15:45:29 -0700111 private:
Mathew Inwoodadb74672019-11-29 14:01:53 +0000112 std::string PrintLine() const;
Andrei Onea8714b022019-02-01 18:55:54 +0000113 std::string PrintLocation() const;
Steven Moreland46e9da82018-07-27 15:45:29 -0700114 const AidlLocation location_;
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700115};
116
Casey Dahlina2f77c42015-12-01 18:26:02 -0800117namespace android {
118namespace aidl {
119
Jiyong Park1deecc32018-07-17 01:14:41 +0900120class AidlTypenames;
Casey Dahlina2f77c42015-12-01 18:26:02 -0800121
122} // namespace aidl
123} // namespace android
124
Jeongik Chadf76dc72019-11-28 00:08:47 +0900125// unique_ptr<AidlTypeSpecifier> for type arugment,
126// std::string for type parameter(T, U, and so on).
127template <typename T>
128class AidlParameterizable {
129 public:
130 AidlParameterizable(std::vector<T>* type_params) : type_params_(type_params) {}
131 virtual ~AidlParameterizable() = default;
132 bool IsGeneric() const { return type_params_ != nullptr; }
133 const std::vector<T>& GetTypeParameters() const { return *type_params_; }
134 bool CheckValid() const;
135
Steven Moreland6c07b832020-10-29 23:39:53 +0000136 __attribute__((warn_unused_result)) bool SetTypeParameters(std::vector<T>* type_params) {
137 if (type_params_) return false;
138 type_params_.reset(type_params);
139 return true;
140 }
141
Jeongik Chadf76dc72019-11-28 00:08:47 +0900142 virtual const AidlNode& AsAidlNode() const = 0;
143
144 protected:
145 AidlParameterizable(const AidlParameterizable&);
146
147 private:
Steven Moreland6c07b832020-10-29 23:39:53 +0000148 unique_ptr<std::vector<T>> type_params_;
Jeongik Chadf76dc72019-11-28 00:08:47 +0900149 static_assert(std::is_same<T, unique_ptr<AidlTypeSpecifier>>::value ||
150 std::is_same<T, std::string>::value);
151};
152template <>
153bool AidlParameterizable<std::string>::CheckValid() const;
154
Andrei Onea9445fc62019-06-27 18:11:59 +0100155class AidlConstantValue;
156class AidlConstantDeclaration;
157
158// Transforms a value string into a language specific form. Raw value as produced by
159// AidlConstantValue.
160using ConstantValueDecorator =
161 std::function<std::string(const AidlTypeSpecifier& type, const std::string& raw_value)>;
162
Jiyong Park68bc77a2018-07-19 19:00:45 +0900163class AidlAnnotation : public AidlNode {
164 public:
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700165 enum class Type {
166 BACKING = 1,
167 HIDE,
168 JAVA_STABLE_PARCELABLE,
169 UNSUPPORTED_APP_USAGE,
170 VINTF_STABILITY,
171 NULLABLE,
172 UTF8_IN_CPP,
Steven Morelanda7764e52020-10-27 17:29:29 +0000173 SENSITIVE_DATA,
Jiyong Parkbf5fd5c2020-06-05 19:48:05 +0900174 JAVA_PASSTHROUGH,
Jooyung Han90345002020-10-23 15:28:53 +0900175 JAVA_DERIVE,
Jeongik Chad0a10272020-08-06 16:33:36 +0900176 JAVA_ONLY_IMMUTABLE,
Devin Moorec7e47a32020-08-07 10:55:25 -0700177 FIXED_SIZE,
Jiyong Park27fd7fd2020-08-27 16:25:09 +0900178 DESCRIPTOR,
Andrei Homescue61feb52020-08-18 15:44:24 -0700179 RUST_DERIVE,
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700180 };
181 static std::string TypeToString(Type type);
182
Andrei Onea9445fc62019-06-27 18:11:59 +0100183 static AidlAnnotation* Parse(
184 const AidlLocation& location, const string& name,
185 std::map<std::string, std::shared_ptr<AidlConstantValue>>* parameter_list);
Steven Moreland46e9da82018-07-27 15:45:29 -0700186
Steven Moreland3f658cf2018-08-20 13:40:54 -0700187 AidlAnnotation(const AidlAnnotation&) = default;
Steven Moreland3be75772018-08-20 13:27:43 -0700188 AidlAnnotation(AidlAnnotation&&) = default;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900189 virtual ~AidlAnnotation() = default;
Andrei Onea9445fc62019-06-27 18:11:59 +0100190 bool CheckValid() const;
Steven Moreland3be75772018-08-20 13:27:43 -0700191
Jooyung Hand902a972020-10-23 17:32:44 +0900192 const string& GetName() const { return schema_.name; }
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700193 const Type& GetType() const { return schema_.type; }
Jooyung Hand902a972020-10-23 17:32:44 +0900194 bool Repeatable() const { return schema_.repeatable; }
Jooyung Han965e31d2020-11-27 12:30:16 +0900195
196 // ToString is for dumping AIDL.
197 // Returns string representation of this annotation.
198 // e.g) "@RustDerive(Clone=true, Copy=true)"
199 string ToString() const;
200
Andrei Onea9445fc62019-06-27 18:11:59 +0100201 std::map<std::string, std::string> AnnotationParams(
202 const ConstantValueDecorator& decorator) const;
Jiyong Parka6605ab2018-11-11 14:30:21 +0900203 const string& GetComments() const { return comments_; }
204 void SetComments(const string& comments) { comments_ = comments; }
Jiyong Park68bc77a2018-07-19 19:00:45 +0900205
206 private:
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700207 struct Schema {
208 AidlAnnotation::Type type;
209
210 // text name in .aidl file, e.g. "nullable"
211 std::string name;
212
213 // map from param name -> value type
214 std::map<std::string, std::string> supported_parameters;
Jooyung Hand902a972020-10-23 17:32:44 +0900215
216 bool repeatable;
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700217 };
218 static const std::vector<Schema>& AllSchemas();
219
220 AidlAnnotation(const AidlLocation& location, const Schema& schema,
Andrei Onea9445fc62019-06-27 18:11:59 +0100221 std::map<std::string, std::shared_ptr<AidlConstantValue>>&& parameters);
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700222
223 const Schema& schema_;
Jiyong Parka6605ab2018-11-11 14:30:21 +0900224 string comments_;
Andrei Onea9445fc62019-06-27 18:11:59 +0100225 std::map<std::string, std::shared_ptr<AidlConstantValue>> parameters_;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900226};
227
Steven Moreland3be75772018-08-20 13:27:43 -0700228static inline bool operator<(const AidlAnnotation& lhs, const AidlAnnotation& rhs) {
229 return lhs.GetName() < rhs.GetName();
230}
231static inline bool operator==(const AidlAnnotation& lhs, const AidlAnnotation& rhs) {
232 return lhs.GetName() == rhs.GetName();
233}
Jiyong Park3656c3c2018-08-01 20:02:01 +0900234
Casey Dahline7922932016-02-29 17:23:01 -0800235class AidlAnnotatable : public AidlNode {
Casey Dahlin0ee37582015-09-30 16:31:55 -0700236 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700237 AidlAnnotatable(const AidlLocation& location);
Steven Moreland3f658cf2018-08-20 13:40:54 -0700238
239 AidlAnnotatable(const AidlAnnotatable&) = default;
240 AidlAnnotatable(AidlAnnotatable&&) = default;
Casey Dahline7922932016-02-29 17:23:01 -0800241 virtual ~AidlAnnotatable() = default;
242
Artur Satayev91fe8712019-07-29 13:06:01 +0100243 void Annotate(vector<AidlAnnotation>&& annotations) {
244 for (auto& annotation : annotations) {
245 annotations_.emplace_back(std::move(annotation));
246 }
247 }
Jiyong Park68bc77a2018-07-19 19:00:45 +0900248 bool IsNullable() const;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900249 bool IsUtf8InCpp() const;
Steven Morelanda7764e52020-10-27 17:29:29 +0000250 bool IsSensitiveData() const;
Steven Morelanda57d0a62019-07-30 09:41:14 -0700251 bool IsVintfStability() const;
Jeongik Chad0a10272020-08-06 16:33:36 +0900252 bool IsJavaOnlyImmutable() const;
Devin Moorec7e47a32020-08-07 10:55:25 -0700253 bool IsFixedSize() const;
Jeongik Cha88f95a82020-01-15 13:02:16 +0900254 bool IsStableApiParcelable(Options::Language lang) const;
Makoto Onuki78a1c1c2020-03-04 16:57:23 -0800255 bool IsHide() const;
Jooyung Han829ec7c2020-12-02 12:07:36 +0900256 bool JavaDerive(const std::string& method) const;
Jiyong Park27fd7fd2020-08-27 16:25:09 +0900257 std::string GetDescriptor() const;
Andrei Onea9445fc62019-06-27 18:11:59 +0100258
Steven Moreland7e4b9502020-02-20 18:10:42 -0800259 void DumpAnnotations(CodeWriter* writer) const;
260
Andrei Onea9445fc62019-06-27 18:11:59 +0100261 const AidlAnnotation* UnsupportedAppUsage() const;
Andrei Homescue61feb52020-08-18 15:44:24 -0700262 const AidlAnnotation* RustDerive() const;
Daniel Norman716d3112019-09-10 13:11:56 -0700263 const AidlTypeSpecifier* BackingType(const AidlTypenames& typenames) const;
Jooyung Han965e31d2020-11-27 12:30:16 +0900264
265 // ToString is for dumping AIDL.
266 // Returns string representation of annotations.
267 // e.g) "@JavaDerive(toString=true) @RustDerive(Clone=true, Copy=true)"
Jiyong Park68bc77a2018-07-19 19:00:45 +0900268 std::string ToString() const;
Casey Dahline7922932016-02-29 17:23:01 -0800269
Jiyong Parka6605ab2018-11-11 14:30:21 +0900270 const vector<AidlAnnotation>& GetAnnotations() const { return annotations_; }
Devin Moore24f68572020-02-26 13:20:59 -0800271 virtual bool CheckValid(const AidlTypenames&) const;
Jiyong Park3656c3c2018-08-01 20:02:01 +0900272
Steven Moreland181144c2020-04-20 19:57:56 -0700273 protected:
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700274 virtual std::set<AidlAnnotation::Type> GetSupportedAnnotations() const = 0;
Steven Moreland181144c2020-04-20 19:57:56 -0700275
Casey Dahline7922932016-02-29 17:23:01 -0800276 private:
Jiyong Parka6605ab2018-11-11 14:30:21 +0900277 vector<AidlAnnotation> annotations_;
Casey Dahline7922932016-02-29 17:23:01 -0800278};
279
Jiyong Park1deecc32018-07-17 01:14:41 +0900280// AidlTypeSpecifier represents a reference to either a built-in type,
281// a defined type, or a variant (e.g., array of generic) of a type.
Jeongik Chadf76dc72019-11-28 00:08:47 +0900282class AidlTypeSpecifier final : public AidlAnnotatable,
283 public AidlParameterizable<unique_ptr<AidlTypeSpecifier>> {
Casey Dahline7922932016-02-29 17:23:01 -0800284 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700285 AidlTypeSpecifier(const AidlLocation& location, const string& unresolved_name, bool is_array,
286 vector<unique_ptr<AidlTypeSpecifier>>* type_params, const string& comments);
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900287 virtual ~AidlTypeSpecifier() = default;
Casey Dahlin0ee37582015-09-30 16:31:55 -0700288
Steven Moreland3f658cf2018-08-20 13:40:54 -0700289 // Copy of this type which is not an array.
Jooyung Hand2fa0232020-10-19 02:51:41 +0900290 const AidlTypeSpecifier& ArrayBase() const;
Steven Moreland3f658cf2018-08-20 13:40:54 -0700291
Jiyong Park1deecc32018-07-17 01:14:41 +0900292 // Returns the full-qualified name of the base type.
293 // int -> int
294 // int[] -> int
295 // List<String> -> List
296 // IFoo -> foo.bar.IFoo (if IFoo is in package foo.bar)
297 const string& GetName() const {
298 if (IsResolved()) {
299 return fully_qualified_name_;
300 } else {
301 return GetUnresolvedName();
302 }
303 }
Casey Dahlin0ee37582015-09-30 16:31:55 -0700304
Jooyung Han965e31d2020-11-27 12:30:16 +0900305 // ToString is for dumping AIDL.
306 // Returns string representation of this type specifier including annotations.
307 // This is "annotations type_name type_params? array_marker?".
308 // e.g) "@utf8InCpp String[]";
309 std::string ToString() const;
Jiyong Park1deecc32018-07-17 01:14:41 +0900310
Jooyung Han965e31d2020-11-27 12:30:16 +0900311 // Signature is for comparing AIDL types.
312 // Returns string representation of this type specifier.
313 // This is "type_name type_params? array_marker?".
314 // e.g.) "String[]" (even if it is annotated with @utf8InCpp)
Jiyong Park02da7422018-07-16 16:00:26 +0900315 std::string Signature() const;
316
Jiyong Park1deecc32018-07-17 01:14:41 +0900317 const string& GetUnresolvedName() const { return unresolved_name_; }
318
Jeongik Cha997281d2020-01-16 15:23:59 +0900319 bool IsHidden() const;
320
Jiyong Park1deecc32018-07-17 01:14:41 +0900321 const string& GetComments() const { return comments_; }
322
Jeongik Cha1a7ab642019-07-29 17:31:02 +0900323 const std::vector<std::string> GetSplitName() const { return split_name_; }
324
Jiyong Parka6605ab2018-11-11 14:30:21 +0900325 void SetComments(const string& comment) { comments_ = comment; }
326
Jiyong Park1deecc32018-07-17 01:14:41 +0900327 bool IsResolved() const { return fully_qualified_name_ != ""; }
328
329 bool IsArray() const { return is_array_; }
330
Steven Moreland6c07b832020-10-29 23:39:53 +0000331 __attribute__((warn_unused_result)) bool SetArray() {
332 if (is_array_) return false;
333 is_array_ = true;
334 return true;
335 }
336
Jiyong Park1deecc32018-07-17 01:14:41 +0900337 // Resolve the base type name to a fully-qualified name. Return false if the
338 // resolution fails.
Daniel Norman716d3112019-09-10 13:11:56 -0700339 bool Resolve(const AidlTypenames& typenames);
Casey Dahlin0ee37582015-09-30 16:31:55 -0700340
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700341 std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override;
Devin Moore24f68572020-02-26 13:20:59 -0800342 bool CheckValid(const AidlTypenames& typenames) const override;
Steven Morelandd59e3172020-05-11 16:42:09 -0700343 bool LanguageSpecificCheckValid(const AidlTypenames& typenames, Options::Language lang) const;
Jeongik Chadf76dc72019-11-28 00:08:47 +0900344 const AidlNode& AsAidlNode() const override { return *this; }
Jiyong Park1d2df7d2018-07-23 15:22:50 +0900345
Jooyung Hane9bb9de2020-11-01 22:16:57 +0900346 const AidlDefinedType* GetDefinedType() const;
347
Casey Dahlin0ee37582015-09-30 16:31:55 -0700348 private:
Steven Moreland3f658cf2018-08-20 13:40:54 -0700349 AidlTypeSpecifier(const AidlTypeSpecifier&) = default;
350
Jiyong Park1deecc32018-07-17 01:14:41 +0900351 const string unresolved_name_;
352 string fully_qualified_name_;
Steven Moreland3f658cf2018-08-20 13:40:54 -0700353 bool is_array_;
Jiyong Parka6605ab2018-11-11 14:30:21 +0900354 string comments_;
Jeongik Cha1a7ab642019-07-29 17:31:02 +0900355 vector<string> split_name_;
Jooyung Han690f5842020-12-04 13:02:04 +0900356 const AidlDefinedType* defined_type_ = nullptr; // set when Resolve() for defined types
Jooyung Hand2fa0232020-10-19 02:51:41 +0900357 mutable shared_ptr<AidlTypeSpecifier> array_base_;
Casey Dahlin0ee37582015-09-30 16:31:55 -0700358};
359
Steven Moreland860b1942018-08-16 14:59:28 -0700360// Returns the universal value unaltered.
361std::string AidlConstantValueDecorator(const AidlTypeSpecifier& type, const std::string& raw_value);
362
Steven Moreland9ea10e32018-07-19 15:26:09 -0700363class AidlConstantValue;
Jooyung Han3f347ca2020-12-01 12:41:50 +0900364class AidlMethod;
365class AidlConstantDeclaration;
366class AidlVariableDeclaration;
367
368class AidlMember : public AidlNode {
369 public:
370 AidlMember(const AidlLocation& location);
371 virtual ~AidlMember() = default;
372
373 // non-copyable, non-movable
374 AidlMember(const AidlMember&) = delete;
375 AidlMember(AidlMember&&) = delete;
376 AidlMember& operator=(const AidlMember&) = delete;
377 AidlMember& operator=(AidlMember&&) = delete;
378
Jooyung Han829ec7c2020-12-02 12:07:36 +0900379 virtual const AidlMethod* AsMethod() const { return nullptr; }
380 virtual const AidlConstantDeclaration* AsConstantDeclaration() const { return nullptr; }
381 virtual const AidlVariableDeclaration* AsVariableDeclaration() const { return nullptr; }
382
383 AidlMethod* AsMethod() {
384 return const_cast<AidlMethod*>(const_cast<const AidlMember*>(this)->AsMethod());
385 }
386 AidlConstantDeclaration* AsConstantDeclaration() {
387 return const_cast<AidlConstantDeclaration*>(
388 const_cast<const AidlMember*>(this)->AsConstantDeclaration());
389 }
390 AidlVariableDeclaration* AsVariableDeclaration() {
391 return const_cast<AidlVariableDeclaration*>(
392 const_cast<const AidlMember*>(this)->AsVariableDeclaration());
393 }
Jooyung Han3f347ca2020-12-01 12:41:50 +0900394};
395
Steven Moreland541788d2020-05-21 22:05:52 +0000396// TODO: This class is used for method arguments and also parcelable fields,
397// and it should be split up since default values don't apply to method
398// arguments
Jooyung Han3f347ca2020-12-01 12:41:50 +0900399class AidlVariableDeclaration : public AidlMember {
Steven Moreland5557f1c2018-07-02 13:50:23 -0700400 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700401 AidlVariableDeclaration(const AidlLocation& location, AidlTypeSpecifier* type,
402 const std::string& name);
403 AidlVariableDeclaration(const AidlLocation& location, AidlTypeSpecifier* type,
404 const std::string& name, AidlConstantValue* default_value);
Steven Moreland5557f1c2018-07-02 13:50:23 -0700405 virtual ~AidlVariableDeclaration() = default;
406
Jiyong Parkd800fef2020-07-22 18:09:43 +0900407 // non-copyable, non-movable
408 AidlVariableDeclaration(const AidlVariableDeclaration&) = delete;
409 AidlVariableDeclaration(AidlVariableDeclaration&&) = delete;
410 AidlVariableDeclaration& operator=(const AidlVariableDeclaration&) = delete;
411 AidlVariableDeclaration& operator=(AidlVariableDeclaration&&) = delete;
412
Jooyung Han829ec7c2020-12-02 12:07:36 +0900413 const AidlVariableDeclaration* AsVariableDeclaration() const override { return this; }
Jooyung Han3f347ca2020-12-01 12:41:50 +0900414
Steven Moreland5557f1c2018-07-02 13:50:23 -0700415 std::string GetName() const { return name_; }
Jooyung Hanacae85d2020-10-28 16:39:09 +0900416 std::string GetCapitalizedName() const;
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900417 const AidlTypeSpecifier& GetType() const { return *type_; }
Steven Moreland541788d2020-05-21 22:05:52 +0000418 // if this was constructed explicitly with a default value
419 bool IsDefaultUserSpecified() const { return default_user_specified_; }
420 // will return the default value this is constructed with or a default value
421 // if one is available
Steven Moreland9ea10e32018-07-19 15:26:09 -0700422 const AidlConstantValue* GetDefaultValue() const { return default_value_.get(); }
423
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900424 AidlTypeSpecifier* GetMutableType() { return type_.get(); }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700425
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900426 bool CheckValid(const AidlTypenames& typenames) const;
Jooyung Han965e31d2020-11-27 12:30:16 +0900427
428 // ToString is for dumping AIDL.
429 // Returns string representation of this variable decl including default value.
430 // This is "annotations type name default_value?".
431 // e.g) "@utf8InCpp String[] names = {"hello"}"
Steven Moreland5557f1c2018-07-02 13:50:23 -0700432 std::string ToString() const;
Jooyung Han965e31d2020-11-27 12:30:16 +0900433
434 // Signature is for comparing AIDL types.
435 // Returns string representation of this variable decl.
436 // This is "type name".
437 // e.g) "String[] name" (even if it is annotated with @utf8InCpp and has a default value.)
Jiyong Park02da7422018-07-16 16:00:26 +0900438 std::string Signature() const;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700439
Steven Moreland860b1942018-08-16 14:59:28 -0700440 std::string ValueString(const ConstantValueDecorator& decorator) const;
Steven Moreland25294322018-08-07 18:13:55 -0700441
Steven Moreland5557f1c2018-07-02 13:50:23 -0700442 private:
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900443 std::unique_ptr<AidlTypeSpecifier> type_;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700444 std::string name_;
Steven Moreland541788d2020-05-21 22:05:52 +0000445 bool default_user_specified_;
Steven Moreland9ea10e32018-07-19 15:26:09 -0700446 std::unique_ptr<AidlConstantValue> default_value_;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700447};
448
449class AidlArgument : public AidlVariableDeclaration {
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700450 public:
Casey Dahlinc378c992015-09-29 16:50:40 -0700451 enum Direction { IN_DIR = 1, OUT_DIR = 2, INOUT_DIR = 3 };
452
Steven Moreland46e9da82018-07-27 15:45:29 -0700453 AidlArgument(const AidlLocation& location, AidlArgument::Direction direction,
454 AidlTypeSpecifier* type, const std::string& name);
455 AidlArgument(const AidlLocation& location, AidlTypeSpecifier* type, const std::string& name);
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700456 virtual ~AidlArgument() = default;
457
Jiyong Parkd800fef2020-07-22 18:09:43 +0900458 // non-copyable, non-movable
459 AidlArgument(const AidlArgument&) = delete;
460 AidlArgument(AidlArgument&&) = delete;
461 AidlArgument& operator=(const AidlArgument&) = delete;
462 AidlArgument& operator=(AidlArgument&&) = delete;
463
Casey Dahlinc378c992015-09-29 16:50:40 -0700464 Direction GetDirection() const { return direction_; }
Christopher Wileyad339272015-10-05 19:11:58 -0700465 bool IsOut() const { return direction_ & OUT_DIR; }
466 bool IsIn() const { return direction_ & IN_DIR; }
Casey Dahlinc378c992015-09-29 16:50:40 -0700467 bool DirectionWasSpecified() const { return direction_specified_; }
Jiyong Park3656c3c2018-08-01 20:02:01 +0900468 string GetDirectionSpecifier() const;
Christopher Wileyad339272015-10-05 19:11:58 -0700469
Jooyung Han965e31d2020-11-27 12:30:16 +0900470 // ToString is for dumping AIDL.
471 // Returns string representation of this argument including direction
472 // This is "direction annotations type name".
473 // e.g) "in @utf8InCpp String[] names"
Casey Dahlinc378c992015-09-29 16:50:40 -0700474 std::string ToString() const;
475
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700476 private:
Casey Dahlinc378c992015-09-29 16:50:40 -0700477 Direction direction_;
478 bool direction_specified_;
Casey Dahlina834dd42015-09-23 11:52:15 -0700479};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800480
Will McVickerd7d18df2019-09-12 13:40:50 -0700481class AidlUnaryConstExpression;
482class AidlBinaryConstExpression;
Jooyung Han690f5842020-12-04 13:02:04 +0900483class AidlConstantReference;
Will McVickerd7d18df2019-09-12 13:40:50 -0700484
Steven Moreland693640b2018-07-19 13:46:27 -0700485class AidlConstantValue : public AidlNode {
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800486 public:
Will McVickerd7d18df2019-09-12 13:40:50 -0700487 enum class Type {
488 // WARNING: Don't change this order! The order is used to determine type
489 // promotion during a binary expression.
490 BOOLEAN,
491 INT8,
492 INT32,
493 INT64,
494 ARRAY,
495 CHARACTER,
496 STRING,
Jooyung Han690f5842020-12-04 13:02:04 +0900497 REF,
Will McVickerd7d18df2019-09-12 13:40:50 -0700498 FLOATING,
499 UNARY,
500 BINARY,
501 ERROR,
502 };
503
Jooyung Han690f5842020-12-04 13:02:04 +0900504 struct Visitor {
505 virtual ~Visitor() {}
506 virtual void Visit(AidlConstantValue&) = 0;
507 virtual void Visit(AidlConstantReference&) = 0;
508 virtual void Visit(AidlUnaryConstExpression&) = 0;
509 virtual void Visit(AidlBinaryConstExpression&) = 0;
510 };
511
Will McVickerd7d18df2019-09-12 13:40:50 -0700512 /*
513 * Return the value casted to the given type.
514 */
515 template <typename T>
516 T cast() const;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800517
Steven Moreland693640b2018-07-19 13:46:27 -0700518 virtual ~AidlConstantValue() = default;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800519
Jiyong Parkd800fef2020-07-22 18:09:43 +0900520 // non-copyable, non-movable
521 AidlConstantValue(const AidlConstantValue&) = delete;
522 AidlConstantValue(AidlConstantValue&&) = delete;
523 AidlConstantValue& operator=(const AidlConstantValue&) = delete;
524 AidlConstantValue& operator=(AidlConstantValue&&) = delete;
525
Steven Moreland541788d2020-05-21 22:05:52 +0000526 // creates default value, when one isn't specified
527 // nullptr if no default available
528 static AidlConstantValue* Default(const AidlTypeSpecifier& specifier);
529
Steven Moreland25294322018-08-07 18:13:55 -0700530 static AidlConstantValue* Boolean(const AidlLocation& location, bool value);
531 static AidlConstantValue* Character(const AidlLocation& location, char value);
Steven Moreland25294322018-08-07 18:13:55 -0700532 // example: 123, -5498, maybe any size
Will McVickerd7d18df2019-09-12 13:40:50 -0700533 static AidlConstantValue* Integral(const AidlLocation& location, const string& value);
534 static AidlConstantValue* Floating(const AidlLocation& location, const std::string& value);
Steven Moreland860b1942018-08-16 14:59:28 -0700535 static AidlConstantValue* Array(const AidlLocation& location,
Will McVickerd7d18df2019-09-12 13:40:50 -0700536 std::unique_ptr<vector<unique_ptr<AidlConstantValue>>> values);
Steven Moreland693640b2018-07-19 13:46:27 -0700537 // example: "\"asdf\""
Will McVickerd7d18df2019-09-12 13:40:50 -0700538 static AidlConstantValue* String(const AidlLocation& location, const string& value);
Steven Moreland693640b2018-07-19 13:46:27 -0700539
Daniel Normanf0ca44f2019-10-25 09:59:44 -0700540 // Construct an AidlConstantValue by evaluating the other integral constant's
541 // value string. This does not preserve the structure of the copied constant.
Steven Moreland59e53e42019-11-26 20:38:08 -0800542 // Returns nullptr and logs if value cannot be copied.
Daniel Normanf0ca44f2019-10-25 09:59:44 -0700543 static AidlConstantValue* ShallowIntegralCopy(const AidlConstantValue& other);
Daniel Normanb28684e2019-10-17 15:31:39 -0700544
Will McVickerd7d18df2019-09-12 13:40:50 -0700545 Type GetType() const { return final_type_; }
Steven Moreland25294322018-08-07 18:13:55 -0700546
Will McVickerd7d18df2019-09-12 13:40:50 -0700547 virtual bool CheckValid() const;
Steven Moreland860b1942018-08-16 14:59:28 -0700548
549 // Raw value of type (currently valid in C++ and Java). Empty string on error.
Steven Moreland4bcb05c2019-11-27 18:57:47 -0800550 string ValueString(const AidlTypeSpecifier& type, const ConstantValueDecorator& decorator) const;
Jooyung Han690f5842020-12-04 13:02:04 +0900551 virtual void Accept(Visitor& visitor) { visitor.Visit(*this); }
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800552
553 private:
Will McVickerd7d18df2019-09-12 13:40:50 -0700554 AidlConstantValue(const AidlLocation& location, Type parsed_type, int64_t parsed_value,
555 const string& checked_value);
556 AidlConstantValue(const AidlLocation& location, Type type, const string& checked_value);
Steven Moreland860b1942018-08-16 14:59:28 -0700557 AidlConstantValue(const AidlLocation& location, Type type,
Will McVickerd7d18df2019-09-12 13:40:50 -0700558 std::unique_ptr<vector<unique_ptr<AidlConstantValue>>> values);
Steven Moreland25294322018-08-07 18:13:55 -0700559 static string ToString(Type type);
Will McVickerd7d18df2019-09-12 13:40:50 -0700560 static bool ParseIntegral(const string& value, int64_t* parsed_value, Type* parsed_type);
561 static bool IsHex(const string& value);
Steven Moreland4bcb05c2019-11-27 18:57:47 -0800562
Will McVickerd7d18df2019-09-12 13:40:50 -0700563 virtual bool evaluate(const AidlTypeSpecifier& type) const;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800564
Steven Moreland693640b2018-07-19 13:46:27 -0700565 const Type type_ = Type::ERROR;
Will McVickerd7d18df2019-09-12 13:40:50 -0700566 const vector<unique_ptr<AidlConstantValue>> values_; // if type_ == ARRAY
567 const string value_; // otherwise
568
569 // State for tracking evaluation of expressions
Steven Moreland4bcb05c2019-11-27 18:57:47 -0800570 mutable bool is_valid_ = false; // cache of CheckValid, but may be marked false in evaluate
571 mutable bool is_evaluated_ = false; // whether evaluate has been called
Will McVickerd7d18df2019-09-12 13:40:50 -0700572 mutable Type final_type_;
573 mutable int64_t final_value_;
574 mutable string final_string_value_ = "";
Steven Moreland693640b2018-07-19 13:46:27 -0700575
Will McVickerd7d18df2019-09-12 13:40:50 -0700576 friend AidlUnaryConstExpression;
577 friend AidlBinaryConstExpression;
Jooyung Han690f5842020-12-04 13:02:04 +0900578 friend AidlConstantReference;
579};
580
581// Represents "<type>.<field>" which resolves to a constant which is one of
582// - constant declartion
583// - enumerator
584// When a <type> is missing, <field> is of the enclosing type.
585class AidlConstantReference : public AidlConstantValue {
586 public:
587 AidlConstantReference(const AidlLocation& location, const std::string& value,
588 const std::string& comments);
589
590 const std::unique_ptr<AidlTypeSpecifier>& GetRefType() const { return ref_type_; }
591 void SetRefType(std::unique_ptr<AidlTypeSpecifier> type) { ref_type_ = std::move(type); }
592 const std::string& GetFieldName() const { return field_name_; }
593 const std::string& GetComments() const { return comments_; }
594
595 bool CheckValid() const override;
596 void Accept(Visitor& visitor) override { visitor.Visit(*this); }
597
598 private:
599 bool evaluate(const AidlTypeSpecifier& type) const override;
600
601 std::unique_ptr<AidlTypeSpecifier> ref_type_;
602 std::string field_name_;
603 const std::string comments_;
Will McVickerd7d18df2019-09-12 13:40:50 -0700604};
605
606class AidlUnaryConstExpression : public AidlConstantValue {
607 public:
608 AidlUnaryConstExpression(const AidlLocation& location, const string& op,
609 std::unique_ptr<AidlConstantValue> rval);
610
611 static bool IsCompatibleType(Type type, const string& op);
612 bool CheckValid() const override;
Jooyung Han690f5842020-12-04 13:02:04 +0900613 void Accept(Visitor& visitor) override {
614 visitor.Visit(*this);
615 unary_->Accept(visitor);
616 }
617
Will McVickerd7d18df2019-09-12 13:40:50 -0700618 private:
619 bool evaluate(const AidlTypeSpecifier& type) const override;
620
621 std::unique_ptr<AidlConstantValue> unary_;
622 const string op_;
623};
624
625class AidlBinaryConstExpression : public AidlConstantValue {
626 public:
627 AidlBinaryConstExpression(const AidlLocation& location, std::unique_ptr<AidlConstantValue> lval,
628 const string& op, std::unique_ptr<AidlConstantValue> rval);
629
630 bool CheckValid() const override;
Will McVickerd7d18df2019-09-12 13:40:50 -0700631
632 static bool AreCompatibleTypes(Type t1, Type t2);
633 // Returns the promoted kind for both operands
634 static Type UsualArithmeticConversion(Type left, Type right);
635 // Returns the promoted integral type where INT32 is the smallest type
636 static Type IntegralPromotion(Type in);
Jooyung Han690f5842020-12-04 13:02:04 +0900637 void Accept(Visitor& visitor) override {
638 visitor.Visit(*this);
639 left_val_->Accept(visitor);
640 right_val_->Accept(visitor);
641 }
Will McVickerd7d18df2019-09-12 13:40:50 -0700642
643 private:
644 bool evaluate(const AidlTypeSpecifier& type) const override;
645
646 std::unique_ptr<AidlConstantValue> left_val_;
647 std::unique_ptr<AidlConstantValue> right_val_;
648 const string op_;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700649};
650
Andrei Onea9445fc62019-06-27 18:11:59 +0100651struct AidlAnnotationParameter {
652 std::string name;
653 std::unique_ptr<AidlConstantValue> value;
654};
655
Steven Moreland693640b2018-07-19 13:46:27 -0700656class AidlConstantDeclaration : public AidlMember {
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700657 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700658 AidlConstantDeclaration(const AidlLocation& location, AidlTypeSpecifier* specifier,
Will McVickerd7d18df2019-09-12 13:40:50 -0700659 const string& name, AidlConstantValue* value);
Steven Moreland693640b2018-07-19 13:46:27 -0700660 virtual ~AidlConstantDeclaration() = default;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700661
Jiyong Parkd800fef2020-07-22 18:09:43 +0900662 // non-copyable, non-movable
663 AidlConstantDeclaration(const AidlConstantDeclaration&) = delete;
664 AidlConstantDeclaration(AidlConstantDeclaration&&) = delete;
665 AidlConstantDeclaration& operator=(const AidlConstantDeclaration&) = delete;
666 AidlConstantDeclaration& operator=(AidlConstantDeclaration&&) = delete;
667
Steven Moreland693640b2018-07-19 13:46:27 -0700668 const AidlTypeSpecifier& GetType() const { return *type_; }
Steven Moreland4d12f9a2018-10-31 14:30:55 -0700669 AidlTypeSpecifier* GetMutableType() { return type_.get(); }
Will McVickerd7d18df2019-09-12 13:40:50 -0700670 const string& GetName() const { return name_; }
Steven Moreland693640b2018-07-19 13:46:27 -0700671 const AidlConstantValue& GetValue() const { return *value_; }
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900672 bool CheckValid(const AidlTypenames& typenames) const;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700673
Jooyung Han965e31d2020-11-27 12:30:16 +0900674 // ToString is for dumping AIDL.
675 // Returns string representation of this const decl including a const value.
676 // This is "`const` annotations type name value".
677 // e.g) "const @utf8InCpp String[] names = { "hello" }"
Will McVickerd7d18df2019-09-12 13:40:50 -0700678 string ToString() const;
Jooyung Han965e31d2020-11-27 12:30:16 +0900679
680 // Signature is for comparing types.
681 // Returns string representation of this const decl.
682 // This is "direction annotations type name".
683 // e.g) "String[] names"
Will McVickerd7d18df2019-09-12 13:40:50 -0700684 string Signature() const;
Jooyung Han965e31d2020-11-27 12:30:16 +0900685
Steven Moreland860b1942018-08-16 14:59:28 -0700686 string ValueString(const ConstantValueDecorator& decorator) const {
Will McVickerd7d18df2019-09-12 13:40:50 -0700687 return value_->ValueString(GetType(), decorator);
Steven Moreland860b1942018-08-16 14:59:28 -0700688 }
Steven Moreland25294322018-08-07 18:13:55 -0700689
Jooyung Han829ec7c2020-12-02 12:07:36 +0900690 const AidlConstantDeclaration* AsConstantDeclaration() const override { return this; }
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700691
692 private:
Steven Moreland693640b2018-07-19 13:46:27 -0700693 const unique_ptr<AidlTypeSpecifier> type_;
Will McVickerd7d18df2019-09-12 13:40:50 -0700694 const string name_;
695 unique_ptr<AidlConstantValue> value_;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800696};
697
698class AidlMethod : public AidlMember {
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700699 public:
Will McVickerd7d18df2019-09-12 13:40:50 -0700700 AidlMethod(const AidlLocation& location, bool oneway, AidlTypeSpecifier* type, const string& name,
701 vector<unique_ptr<AidlArgument>>* args, const string& comments);
702 AidlMethod(const AidlLocation& location, bool oneway, AidlTypeSpecifier* type, const string& name,
703 vector<unique_ptr<AidlArgument>>* args, const string& comments, int id,
704 bool is_user_defined = true);
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700705 virtual ~AidlMethod() = default;
706
Jiyong Parkd800fef2020-07-22 18:09:43 +0900707 // non-copyable, non-movable
708 AidlMethod(const AidlMethod&) = delete;
709 AidlMethod(AidlMethod&&) = delete;
710 AidlMethod& operator=(const AidlMethod&) = delete;
711 AidlMethod& operator=(AidlMethod&&) = delete;
712
Jooyung Han829ec7c2020-12-02 12:07:36 +0900713 const AidlMethod* AsMethod() const override { return this; }
Jeongik Cha997281d2020-01-16 15:23:59 +0900714 bool IsHidden() const;
Will McVickerd7d18df2019-09-12 13:40:50 -0700715 const string& GetComments() const { return comments_; }
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900716 const AidlTypeSpecifier& GetType() const { return *type_; }
717 AidlTypeSpecifier* GetMutableType() { return type_.get(); }
Steven Morelandacd53472018-12-14 10:17:26 -0800718
Steven Moreland8c70ba92018-12-17 10:20:31 -0800719 // set if this method is part of an interface that is marked oneway
720 void ApplyInterfaceOneway(bool oneway) { oneway_ = oneway_ || oneway; }
Casey Dahlinf4a93112015-10-05 16:58:09 -0700721 bool IsOneway() const { return oneway_; }
Steven Morelandacd53472018-12-14 10:17:26 -0800722
Casey Dahlinf4a93112015-10-05 16:58:09 -0700723 const std::string& GetName() const { return name_; }
Casey Dahlinf4a93112015-10-05 16:58:09 -0700724 bool HasId() const { return has_id_; }
Jiyong Parked65bf42018-08-28 15:43:27 +0900725 int GetId() const { return id_; }
Casey Dahlinf4a93112015-10-05 16:58:09 -0700726 void SetId(unsigned id) { id_ = id; }
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700727
Jiyong Park309668e2018-07-28 16:55:44 +0900728 bool IsUserDefined() const { return is_user_defined_; }
729
Casey Dahlinf4a93112015-10-05 16:58:09 -0700730 const std::vector<std::unique_ptr<AidlArgument>>& GetArguments() const {
Christopher Wileyad339272015-10-05 19:11:58 -0700731 return arguments_;
732 }
733 // An inout parameter will appear in both GetInArguments()
734 // and GetOutArguments(). AidlMethod retains ownership of the argument
735 // pointers returned in this way.
736 const std::vector<const AidlArgument*>& GetInArguments() const {
737 return in_arguments_;
738 }
739 const std::vector<const AidlArgument*>& GetOutArguments() const {
740 return out_arguments_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700741 }
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700742
Jooyung Han965e31d2020-11-27 12:30:16 +0900743 // ToString is for dumping AIDL.
744 // Returns string representation of this method including everything.
745 // This is "ret_type name ( arg_list ) = id".
746 // e.g) "boolean foo(int, @Nullable String) = 1"
Jiyong Park309668e2018-07-28 16:55:44 +0900747 std::string ToString() const;
748
Jooyung Han965e31d2020-11-27 12:30:16 +0900749 // Signature is for comparing AIDL types.
750 // Returns string representation of this method's name & type.
751 // e.g) "foo(int, String)"
752 std::string Signature() const;
753
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700754 private:
Casey Dahlinf4a93112015-10-05 16:58:09 -0700755 bool oneway_;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700756 std::string comments_;
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900757 std::unique_ptr<AidlTypeSpecifier> type_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700758 std::string name_;
Christopher Wileyad339272015-10-05 19:11:58 -0700759 const std::vector<std::unique_ptr<AidlArgument>> arguments_;
760 std::vector<const AidlArgument*> in_arguments_;
761 std::vector<const AidlArgument*> out_arguments_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700762 bool has_id_;
763 int id_;
Jiyong Park309668e2018-07-28 16:55:44 +0900764 bool is_user_defined_ = true;
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700765};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800766
Steven Morelandc258abc2018-07-10 14:03:38 -0700767class AidlDefinedType;
Jiyong Parkb034bf02018-07-30 17:44:33 +0900768class AidlInterface;
769class AidlParcelable;
770class AidlStructuredParcelable;
Jooyung Han2946afc2020-10-05 20:29:16 +0900771class AidlUnionDecl;
Jooyung Han3f347ca2020-12-01 12:41:50 +0900772
Daniel Norman85aed542019-08-21 12:01:14 -0700773// AidlDefinedType represents either an interface, parcelable, or enum that is
Jiyong Park1deecc32018-07-17 01:14:41 +0900774// defined in the source file.
775class AidlDefinedType : public AidlAnnotatable {
Steven Moreland787b0432018-07-03 09:00:58 -0700776 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700777 AidlDefinedType(const AidlLocation& location, const std::string& name,
Jooyung Han829ec7c2020-12-02 12:07:36 +0900778 const std::string& comments, const std::string& package,
779 std::vector<std::unique_ptr<AidlMember>>* members);
Steven Moreland787b0432018-07-03 09:00:58 -0700780 virtual ~AidlDefinedType() = default;
781
Jiyong Parkd800fef2020-07-22 18:09:43 +0900782 // non-copyable, non-movable
783 AidlDefinedType(const AidlDefinedType&) = delete;
784 AidlDefinedType(AidlDefinedType&&) = delete;
785 AidlDefinedType& operator=(const AidlDefinedType&) = delete;
786 AidlDefinedType& operator=(AidlDefinedType&&) = delete;
787
Jiyong Park1deecc32018-07-17 01:14:41 +0900788 const std::string& GetName() const { return name_; };
Jeongik Cha997281d2020-01-16 15:23:59 +0900789 bool IsHidden() const;
Jiyong Park1deecc32018-07-17 01:14:41 +0900790 const std::string& GetComments() const { return comments_; }
Jiyong Parka6605ab2018-11-11 14:30:21 +0900791 void SetComments(const std::string comments) { comments_ = comments; }
Jiyong Park1deecc32018-07-17 01:14:41 +0900792
Steven Moreland787b0432018-07-03 09:00:58 -0700793 /* dot joined package, example: "android.package.foo" */
Jiyong Park18132182020-06-08 20:24:40 +0900794 std::string GetPackage() const { return package_; }
Steven Moreland787b0432018-07-03 09:00:58 -0700795 /* dot joined package and name, example: "android.package.foo.IBar" */
796 std::string GetCanonicalName() const;
Jiyong Park18132182020-06-08 20:24:40 +0900797 const std::vector<std::string>& GetSplitPackage() const { return split_package_; }
Steven Moreland787b0432018-07-03 09:00:58 -0700798
Steven Morelanded83a282018-07-17 13:27:29 -0700799 virtual std::string GetPreprocessDeclarationName() const = 0;
Steven Morelandc258abc2018-07-10 14:03:38 -0700800
Steven Moreland5557f1c2018-07-02 13:50:23 -0700801 virtual const AidlStructuredParcelable* AsStructuredParcelable() const { return nullptr; }
Steven Morelandc258abc2018-07-10 14:03:38 -0700802 virtual const AidlParcelable* AsParcelable() const { return nullptr; }
Daniel Norman85aed542019-08-21 12:01:14 -0700803 virtual const AidlEnumDeclaration* AsEnumDeclaration() const { return nullptr; }
Jooyung Han2946afc2020-10-05 20:29:16 +0900804 virtual const AidlUnionDecl* AsUnionDeclaration() const { return nullptr; }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700805 virtual const AidlInterface* AsInterface() const { return nullptr; }
Jeongik Chadf76dc72019-11-28 00:08:47 +0900806 virtual const AidlParameterizable<std::string>* AsParameterizable() const { return nullptr; }
Devin Moore24f68572020-02-26 13:20:59 -0800807 bool CheckValid(const AidlTypenames& typenames) const override;
Steven Morelandd59e3172020-05-11 16:42:09 -0700808 virtual bool LanguageSpecificCheckValid(const AidlTypenames& typenames,
809 Options::Language lang) const = 0;
Steven Morelandc258abc2018-07-10 14:03:38 -0700810 AidlStructuredParcelable* AsStructuredParcelable() {
811 return const_cast<AidlStructuredParcelable*>(
812 const_cast<const AidlDefinedType*>(this)->AsStructuredParcelable());
813 }
814 AidlParcelable* AsParcelable() {
815 return const_cast<AidlParcelable*>(const_cast<const AidlDefinedType*>(this)->AsParcelable());
816 }
Daniel Norman85aed542019-08-21 12:01:14 -0700817 AidlEnumDeclaration* AsEnumDeclaration() {
818 return const_cast<AidlEnumDeclaration*>(
819 const_cast<const AidlDefinedType*>(this)->AsEnumDeclaration());
820 }
Jooyung Han2946afc2020-10-05 20:29:16 +0900821 AidlUnionDecl* AsUnionDeclaration() {
822 return const_cast<AidlUnionDecl*>(
823 const_cast<const AidlDefinedType*>(this)->AsUnionDeclaration());
824 }
Steven Morelandc258abc2018-07-10 14:03:38 -0700825 AidlInterface* AsInterface() {
826 return const_cast<AidlInterface*>(const_cast<const AidlDefinedType*>(this)->AsInterface());
827 }
828
Jeongik Chadf76dc72019-11-28 00:08:47 +0900829 AidlParameterizable<std::string>* AsParameterizable() {
830 return const_cast<AidlParameterizable<std::string>*>(
831 const_cast<const AidlDefinedType*>(this)->AsParameterizable());
832 }
833
Steven Moreland6cee3482018-07-18 14:39:58 -0700834 const AidlParcelable* AsUnstructuredParcelable() const {
835 if (this->AsStructuredParcelable() != nullptr) return nullptr;
Jooyung Han2946afc2020-10-05 20:29:16 +0900836 if (this->AsUnionDeclaration() != nullptr) return nullptr;
Steven Moreland6cee3482018-07-18 14:39:58 -0700837 return this->AsParcelable();
838 }
839 AidlParcelable* AsUnstructuredParcelable() {
840 return const_cast<AidlParcelable*>(
841 const_cast<const AidlDefinedType*>(this)->AsUnstructuredParcelable());
842 }
843
Jeongik Cha997281d2020-01-16 15:23:59 +0900844 virtual void Dump(CodeWriter* writer) const = 0;
Steven Morelanda5d9c5c2020-02-21 16:01:09 -0800845 void DumpHeader(CodeWriter* writer) const;
Jiyong Park02da7422018-07-16 16:00:26 +0900846
Jooyung Han829ec7c2020-12-02 12:07:36 +0900847 const std::vector<std::unique_ptr<AidlVariableDeclaration>>& GetFields() const {
848 return variables_;
849 }
850 const std::vector<std::unique_ptr<AidlConstantDeclaration>>& GetConstantDeclarations() const {
851 return constants_;
852 }
853 const std::vector<std::unique_ptr<AidlMethod>>& GetMethods() const { return methods_; }
854 void AddMethod(std::unique_ptr<AidlMethod> method) { methods_.push_back(std::move(method)); }
855 const std::vector<const AidlMember*>& GetMembers() const { return members_; }
856
857 protected:
858 // utility for subclasses with getter names
859 bool CheckValidForGetterNames() const;
860
Steven Moreland787b0432018-07-03 09:00:58 -0700861 private:
Jooyung Han829ec7c2020-12-02 12:07:36 +0900862 bool CheckValidWithMembers(const AidlTypenames& typenames) const;
863
Jiyong Park1deecc32018-07-17 01:14:41 +0900864 std::string name_;
Jiyong Park1deecc32018-07-17 01:14:41 +0900865 std::string comments_;
Jiyong Park18132182020-06-08 20:24:40 +0900866 const std::string package_;
867 const std::vector<std::string> split_package_;
Jooyung Han829ec7c2020-12-02 12:07:36 +0900868 std::vector<std::unique_ptr<AidlVariableDeclaration>> variables_;
869 std::vector<std::unique_ptr<AidlConstantDeclaration>> constants_;
870 std::vector<std::unique_ptr<AidlMethod>> methods_;
871 std::vector<const AidlMember*> members_; // keep members in order of appearance.
Steven Moreland787b0432018-07-03 09:00:58 -0700872};
873
Jeongik Chadf76dc72019-11-28 00:08:47 +0900874class AidlParcelable : public AidlDefinedType, public AidlParameterizable<std::string> {
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700875 public:
Jiyong Park18132182020-06-08 20:24:40 +0900876 AidlParcelable(const AidlLocation& location, const std::string& name, const std::string& package,
877 const std::string& comments, const std::string& cpp_header = "",
Jooyung Han829ec7c2020-12-02 12:07:36 +0900878 std::vector<std::string>* type_params = nullptr,
879 std::vector<std::unique_ptr<AidlMember>>* members = nullptr);
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700880 virtual ~AidlParcelable() = default;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800881
Jiyong Parkd800fef2020-07-22 18:09:43 +0900882 // non-copyable, non-movable
883 AidlParcelable(const AidlParcelable&) = delete;
884 AidlParcelable(AidlParcelable&&) = delete;
885 AidlParcelable& operator=(const AidlParcelable&) = delete;
886 AidlParcelable& operator=(AidlParcelable&&) = delete;
887
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800888 std::string GetCppHeader() const { return cpp_header_; }
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800889
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700890 std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override;
Jeongik Cha82317dd2019-02-27 20:26:11 +0900891 bool CheckValid(const AidlTypenames& typenames) const override;
Steven Morelandd59e3172020-05-11 16:42:09 -0700892 bool LanguageSpecificCheckValid(const AidlTypenames& typenames,
893 Options::Language lang) const override;
Steven Morelandc258abc2018-07-10 14:03:38 -0700894 const AidlParcelable* AsParcelable() const override { return this; }
Jeongik Chadf76dc72019-11-28 00:08:47 +0900895 const AidlParameterizable<std::string>* AsParameterizable() const override { return this; }
896 const AidlNode& AsAidlNode() const override { return *this; }
Steven Morelanded83a282018-07-17 13:27:29 -0700897 std::string GetPreprocessDeclarationName() const override { return "parcelable"; }
Steven Morelandc258abc2018-07-10 14:03:38 -0700898
Jeongik Cha997281d2020-01-16 15:23:59 +0900899 void Dump(CodeWriter* writer) const override;
Jiyong Park02da7422018-07-16 16:00:26 +0900900
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700901 private:
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800902 std::string cpp_header_;
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700903};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800904
Jooyung Han829ec7c2020-12-02 12:07:36 +0900905class AidlStructuredParcelable : public AidlParcelable {
Steven Moreland5557f1c2018-07-02 13:50:23 -0700906 public:
Jiyong Park18132182020-06-08 20:24:40 +0900907 AidlStructuredParcelable(const AidlLocation& location, const std::string& name,
908 const std::string& package, const std::string& comments,
Jooyung Han829ec7c2020-12-02 12:07:36 +0900909 std::vector<std::string>* type_params,
910 std::vector<std::unique_ptr<AidlMember>>* members);
Jiyong Parkd800fef2020-07-22 18:09:43 +0900911 virtual ~AidlStructuredParcelable() = default;
912
913 // non-copyable, non-movable
914 AidlStructuredParcelable(const AidlStructuredParcelable&) = delete;
915 AidlStructuredParcelable(AidlStructuredParcelable&&) = delete;
916 AidlStructuredParcelable& operator=(const AidlStructuredParcelable&) = delete;
917 AidlStructuredParcelable& operator=(AidlStructuredParcelable&&) = delete;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700918
Steven Morelandc258abc2018-07-10 14:03:38 -0700919 const AidlStructuredParcelable* AsStructuredParcelable() const override { return this; }
Steven Morelanded83a282018-07-17 13:27:29 -0700920 std::string GetPreprocessDeclarationName() const override { return "structured_parcelable"; }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700921
Jeongik Cha997281d2020-01-16 15:23:59 +0900922 void Dump(CodeWriter* writer) const override;
Jiyong Park02da7422018-07-16 16:00:26 +0900923
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700924 std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override;
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900925 bool CheckValid(const AidlTypenames& typenames) const override;
Steven Morelandd59e3172020-05-11 16:42:09 -0700926 bool LanguageSpecificCheckValid(const AidlTypenames& typenames,
927 Options::Language lang) const override;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700928};
929
Daniel Norman85aed542019-08-21 12:01:14 -0700930class AidlEnumerator : public AidlNode {
931 public:
Daniel Norman2e4112d2019-10-03 10:22:35 -0700932 AidlEnumerator(const AidlLocation& location, const std::string& name, AidlConstantValue* value,
933 const std::string& comments);
Daniel Norman85aed542019-08-21 12:01:14 -0700934 virtual ~AidlEnumerator() = default;
935
Jiyong Parkd800fef2020-07-22 18:09:43 +0900936 // non-copyable, non-movable
937 AidlEnumerator(const AidlEnumerator&) = delete;
938 AidlEnumerator(AidlEnumerator&&) = delete;
939 AidlEnumerator& operator=(const AidlEnumerator&) = delete;
940 AidlEnumerator& operator=(AidlEnumerator&&) = delete;
941
Daniel Norman85aed542019-08-21 12:01:14 -0700942 const std::string& GetName() const { return name_; }
Will McVickerd7d18df2019-09-12 13:40:50 -0700943 AidlConstantValue* GetValue() const { return value_.get(); }
Daniel Norman2e4112d2019-10-03 10:22:35 -0700944 const std::string& GetComments() const { return comments_; }
Daniel Norman85aed542019-08-21 12:01:14 -0700945 bool CheckValid(const AidlTypeSpecifier& enum_backing_type) const;
946
947 string ValueString(const AidlTypeSpecifier& backing_type,
948 const ConstantValueDecorator& decorator) const;
949
Daniel Normanb28684e2019-10-17 15:31:39 -0700950 void SetValue(std::unique_ptr<AidlConstantValue> value) { value_ = std::move(value); }
951
Daniel Norman85aed542019-08-21 12:01:14 -0700952 private:
953 const std::string name_;
Will McVickerd7d18df2019-09-12 13:40:50 -0700954 unique_ptr<AidlConstantValue> value_;
Daniel Norman2e4112d2019-10-03 10:22:35 -0700955 const std::string comments_;
Daniel Norman85aed542019-08-21 12:01:14 -0700956};
957
958class AidlEnumDeclaration : public AidlDefinedType {
959 public:
Will McVickerd7d18df2019-09-12 13:40:50 -0700960 AidlEnumDeclaration(const AidlLocation& location, const string& name,
Daniel Norman85aed542019-08-21 12:01:14 -0700961 std::vector<std::unique_ptr<AidlEnumerator>>* enumerators,
Jiyong Park18132182020-06-08 20:24:40 +0900962 const std::string& package, const std::string& comments);
Daniel Norman85aed542019-08-21 12:01:14 -0700963 virtual ~AidlEnumDeclaration() = default;
964
Jiyong Parkd800fef2020-07-22 18:09:43 +0900965 // non-copyable, non-movable
966 AidlEnumDeclaration(const AidlEnumDeclaration&) = delete;
967 AidlEnumDeclaration(AidlEnumDeclaration&&) = delete;
968 AidlEnumDeclaration& operator=(const AidlEnumDeclaration&) = delete;
969 AidlEnumDeclaration& operator=(AidlEnumDeclaration&&) = delete;
970
Daniel Norman85aed542019-08-21 12:01:14 -0700971 void SetBackingType(std::unique_ptr<const AidlTypeSpecifier> type);
972 const AidlTypeSpecifier& GetBackingType() const { return *backing_type_; }
973 const std::vector<std::unique_ptr<AidlEnumerator>>& GetEnumerators() const {
974 return enumerators_;
975 }
Steven Moreland59e53e42019-11-26 20:38:08 -0800976 bool Autofill();
Steven Moreland0cea4aa2020-04-20 21:06:02 -0700977 std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override;
Daniel Norman85aed542019-08-21 12:01:14 -0700978 bool CheckValid(const AidlTypenames& typenames) const override;
Steven Morelandd59e3172020-05-11 16:42:09 -0700979 bool LanguageSpecificCheckValid(const AidlTypenames& /*typenames*/,
980 Options::Language) const override {
981 return true;
982 }
Daniel Norman85aed542019-08-21 12:01:14 -0700983 std::string GetPreprocessDeclarationName() const override { return "enum"; }
Jeongik Cha997281d2020-01-16 15:23:59 +0900984 void Dump(CodeWriter* writer) const override;
Daniel Norman85aed542019-08-21 12:01:14 -0700985
986 const AidlEnumDeclaration* AsEnumDeclaration() const override { return this; }
987
988 private:
989 const std::string name_;
990 const std::vector<std::unique_ptr<AidlEnumerator>> enumerators_;
991 std::unique_ptr<const AidlTypeSpecifier> backing_type_;
Daniel Norman85aed542019-08-21 12:01:14 -0700992};
993
Jooyung Han829ec7c2020-12-02 12:07:36 +0900994class AidlUnionDecl : public AidlParcelable {
Jooyung Han2946afc2020-10-05 20:29:16 +0900995 public:
996 AidlUnionDecl(const AidlLocation& location, const std::string& name, const std::string& package,
Jooyung Han829ec7c2020-12-02 12:07:36 +0900997 const std::string& comments, std::vector<std::string>* type_params,
998 std::vector<std::unique_ptr<AidlMember>>* members);
Jooyung Han2946afc2020-10-05 20:29:16 +0900999 virtual ~AidlUnionDecl() = default;
1000
1001 // non-copyable, non-movable
1002 AidlUnionDecl(const AidlUnionDecl&) = delete;
1003 AidlUnionDecl(AidlUnionDecl&&) = delete;
1004 AidlUnionDecl& operator=(const AidlUnionDecl&) = delete;
1005 AidlUnionDecl& operator=(AidlUnionDecl&&) = delete;
1006
1007 std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override;
1008
1009 const AidlNode& AsAidlNode() const override { return *this; }
1010
Jooyung Hanfe89f122020-10-14 03:49:18 +09001011 bool CheckValid(const AidlTypenames& typenames) const override;
1012 bool LanguageSpecificCheckValid(const AidlTypenames& typenames,
1013 Options::Language lang) const override;
Jooyung Han2946afc2020-10-05 20:29:16 +09001014 std::string GetPreprocessDeclarationName() const override { return "union"; }
1015
1016 void Dump(CodeWriter* writer) const override;
1017 const AidlUnionDecl* AsUnionDeclaration() const override { return this; }
Jooyung Han2946afc2020-10-05 20:29:16 +09001018};
1019
Jiyong Park1deecc32018-07-17 01:14:41 +09001020class AidlInterface final : public AidlDefinedType {
Casey Dahlin1ae2bc52015-10-07 18:49:10 -07001021 public:
Steven Moreland46e9da82018-07-27 15:45:29 -07001022 AidlInterface(const AidlLocation& location, const std::string& name, const std::string& comments,
Jooyung Han829ec7c2020-12-02 12:07:36 +09001023 bool oneway_, const std::string& package,
1024 std::vector<std::unique_ptr<AidlMember>>* members);
Casey Dahlin1ae2bc52015-10-07 18:49:10 -07001025 virtual ~AidlInterface() = default;
1026
Jiyong Parkd800fef2020-07-22 18:09:43 +09001027 // non-copyable, non-movable
1028 AidlInterface(const AidlInterface&) = delete;
1029 AidlInterface(AidlInterface&&) = delete;
1030 AidlInterface& operator=(const AidlInterface&) = delete;
1031 AidlInterface& operator=(AidlInterface&&) = delete;
1032
Steven Morelandc258abc2018-07-10 14:03:38 -07001033 const AidlInterface* AsInterface() const override { return this; }
Steven Morelanded83a282018-07-17 13:27:29 -07001034 std::string GetPreprocessDeclarationName() const override { return "interface"; }
Steven Moreland5557f1c2018-07-02 13:50:23 -07001035
Jeongik Cha997281d2020-01-16 15:23:59 +09001036 void Dump(CodeWriter* writer) const override;
Jiyong Park02da7422018-07-16 16:00:26 +09001037
Steven Moreland0cea4aa2020-04-20 21:06:02 -07001038 std::set<AidlAnnotation::Type> GetSupportedAnnotations() const override;
Jeongik Chadb0f59e2018-11-01 18:11:21 +09001039 bool CheckValid(const AidlTypenames& typenames) const override;
Steven Morelandd59e3172020-05-11 16:42:09 -07001040 bool LanguageSpecificCheckValid(const AidlTypenames& typenames,
1041 Options::Language lang) const override;
Jeongik Chadb0f59e2018-11-01 18:11:21 +09001042
Jiyong Park27fd7fd2020-08-27 16:25:09 +09001043 std::string GetDescriptor() const;
Casey Dahlin0a2f8be2015-09-28 16:15:29 -07001044};
Adam Lesinskiffa16862014-01-23 18:17:42 -08001045
Casey Dahlin0edf3422015-10-07 12:34:59 -07001046class AidlImport : public AidlNode {
1047 public:
Steven Moreland46e9da82018-07-27 15:45:29 -07001048 AidlImport(const AidlLocation& location, const std::string& needed_class);
Casey Dahlin0edf3422015-10-07 12:34:59 -07001049 virtual ~AidlImport() = default;
1050
Jiyong Parkd800fef2020-07-22 18:09:43 +09001051 // non-copyable, non-movable
1052 AidlImport(const AidlImport&) = delete;
1053 AidlImport(AidlImport&&) = delete;
1054 AidlImport& operator=(const AidlImport&) = delete;
1055 AidlImport& operator=(AidlImport&&) = delete;
1056
Casey Dahlin0edf3422015-10-07 12:34:59 -07001057 const std::string& GetNeededClass() const { return needed_class_; }
Casey Dahlin0edf3422015-10-07 12:34:59 -07001058
1059 private:
Casey Dahlin0edf3422015-10-07 12:34:59 -07001060 std::string needed_class_;
Casey Dahline2507492015-09-14 17:11:20 -07001061};
1062
Jiyong Park62515512020-06-08 15:57:11 +09001063// AidlDocument models an AIDL file
1064class AidlDocument : public AidlNode {
1065 public:
1066 AidlDocument(const AidlLocation& location, std::vector<std::unique_ptr<AidlImport>>& imports,
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001067 std::vector<std::unique_ptr<AidlDefinedType>>&& defined_types)
1068 : AidlNode(location),
1069 imports_(std::move(imports)),
1070 defined_types_(std::move(defined_types)) {}
Jiyong Parkd800fef2020-07-22 18:09:43 +09001071 ~AidlDocument() = default;
1072
1073 // non-copyable, non-movable
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001074 AidlDocument(const AidlDocument&) = delete;
1075 AidlDocument(AidlDocument&&) = delete;
1076 AidlDocument& operator=(const AidlDocument&) = delete;
1077 AidlDocument& operator=(AidlDocument&&) = delete;
Jiyong Parkd800fef2020-07-22 18:09:43 +09001078
1079 const std::vector<std::unique_ptr<AidlImport>>& Imports() const { return imports_; }
1080 const std::vector<std::unique_ptr<AidlDefinedType>>& DefinedTypes() const {
1081 return defined_types_;
1082 }
Jiyong Park62515512020-06-08 15:57:11 +09001083
1084 private:
1085 const std::vector<std::unique_ptr<AidlImport>> imports_;
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001086 const std::vector<std::unique_ptr<AidlDefinedType>> defined_types_;
Jiyong Park62515512020-06-08 15:57:11 +09001087};