blob: 49a4606e8053eaaf84f65cf0de92b6f44a2768c7 [file] [log] [blame]
Steven Moreland9fccf582018-08-27 20:36:27 -07001#pragma once
Christopher Wileyec31a052016-01-25 07:28:51 -08002
Jiyong Park1deecc32018-07-17 01:14:41 +09003#include "aidl_typenames.h"
Jiyong Park02da7422018-07-16 16:00:26 +09004#include "code_writer.h"
Jiyong Park1deecc32018-07-17 01:14:41 +09005#include "io_delegate.h"
6
7#include <cassert>
Casey Dahlinbc7a50a2015-09-28 19:20:50 -07008#include <memory>
Casey Dahlindd691812015-09-09 17:59:06 -07009#include <string>
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070010#include <vector>
Casey Dahlindd691812015-09-09 17:59:06 -070011
Elliott Hughes0a620672015-12-04 13:53:18 -080012#include <android-base/macros.h>
13#include <android-base/strings.h>
Casey Dahlin73d46b02015-09-11 02:47:54 +000014
Casey Dahlin89d44842015-09-24 18:45:54 -070015struct yy_buffer_state;
16typedef yy_buffer_state* YY_BUFFER_STATE;
17
Jiyong Parkb034bf02018-07-30 17:44:33 +090018using android::aidl::AidlTypenames;
Jiyong Park02da7422018-07-16 16:00:26 +090019using android::aidl::CodeWriter;
Steven Moreland3f658cf2018-08-20 13:40:54 -070020using std::shared_ptr;
Jiyong Park1deecc32018-07-17 01:14:41 +090021using std::string;
22using std::unique_ptr;
23using std::vector;
24
Andrei Onea8714b022019-02-01 18:55:54 +000025class AidlNode;
26
27namespace android {
28namespace aidl {
29namespace mappings {
30std::string dump_location(const AidlNode& method);
31} // namespace mappings
32} // namespace aidl
33} // namespace android
34
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070035class AidlToken {
36 public:
37 AidlToken(const std::string& text, const std::string& comments);
Adam Lesinskiffa16862014-01-23 18:17:42 -080038
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070039 const std::string& GetText() const { return text_; }
40 const std::string& GetComments() const { return comments_; }
Adam Lesinskiffa16862014-01-23 18:17:42 -080041
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070042 private:
43 std::string text_;
44 std::string comments_;
Casey Dahlin082f1d12015-09-21 14:06:25 -070045
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070046 DISALLOW_COPY_AND_ASSIGN(AidlToken);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -070047};
Adam Lesinskiffa16862014-01-23 18:17:42 -080048
Steven Moreland46e9da82018-07-27 15:45:29 -070049class AidlLocation {
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070050 public:
Steven Moreland46e9da82018-07-27 15:45:29 -070051 struct Point {
52 unsigned int line;
53 unsigned int column;
54 };
55
Steven Moreland46e9da82018-07-27 15:45:29 -070056 AidlLocation(const std::string& file, Point begin, Point end);
57
Steven Moreland46e9da82018-07-27 15:45:29 -070058 friend std::ostream& operator<<(std::ostream& os, const AidlLocation& l);
Andrei Onea8714b022019-02-01 18:55:54 +000059 friend class AidlNode;
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070060
61 private:
Steven Moreland46e9da82018-07-27 15:45:29 -070062 const std::string file_;
63 Point begin_;
64 Point end_;
65};
66
Steven Moreland02e012e2018-08-02 14:58:10 -070067#define AIDL_LOCATION_HERE \
68 AidlLocation { \
69 __FILE__, {__LINE__, 0}, { __LINE__, 0 } \
70 }
71
Steven Moreland46e9da82018-07-27 15:45:29 -070072std::ostream& operator<<(std::ostream& os, const AidlLocation& l);
73
74// Anything that is locatable in a .aidl file.
75class AidlNode {
76 public:
77 AidlNode(const AidlLocation& location);
Steven Moreland3f658cf2018-08-20 13:40:54 -070078
79 AidlNode(const AidlNode&) = default;
Steven Moreland3be75772018-08-20 13:27:43 -070080 AidlNode(AidlNode&&) = default;
Steven Moreland46e9da82018-07-27 15:45:29 -070081 virtual ~AidlNode() = default;
82
Steven Moreland46e9da82018-07-27 15:45:29 -070083 // DO NOT ADD. This is intentionally omitted. Nothing should refer to the location
84 // for a functional purpose. It is only for error messages.
85 // NO const AidlLocation& GetLocation() const { return location_; } NO
86
87 // To be able to print AidlLocation (nothing else should use this information)
88 friend class AidlError;
Andrei Onea8714b022019-02-01 18:55:54 +000089 friend std::string android::aidl::mappings::dump_location(const AidlNode&);
Steven Moreland46e9da82018-07-27 15:45:29 -070090
91 private:
Andrei Onea8714b022019-02-01 18:55:54 +000092 std::string PrintLocation() const;
Steven Moreland46e9da82018-07-27 15:45:29 -070093 const AidlLocation location_;
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070094};
95
Steven Moreland46e9da82018-07-27 15:45:29 -070096// Generic point for printing any error in the AIDL compiler.
97class AidlError {
98 public:
Steven Moreland92c55f12018-07-31 14:08:37 -070099 AidlError(bool fatal, const std::string& filename) : AidlError(fatal) { os_ << filename << ": "; }
100 AidlError(bool fatal, const AidlLocation& location) : AidlError(fatal) {
Steven Moreland46e9da82018-07-27 15:45:29 -0700101 os_ << location << ": ";
102 }
Steven Moreland92c55f12018-07-31 14:08:37 -0700103 AidlError(bool fatal, const AidlNode& node) : AidlError(fatal, node.location_) {}
104 AidlError(bool fatal, const AidlNode* node) : AidlError(fatal, *node) {}
105
106 template <typename T>
107 AidlError(bool fatal, const std::unique_ptr<T>& node) : AidlError(fatal, *node) {}
Steven Moreland46e9da82018-07-27 15:45:29 -0700108 ~AidlError() {
109 os_ << std::endl;
110 if (fatal_) abort();
111 }
112
113 std::ostream& os_;
114
115 private:
Steven Moreland92c55f12018-07-31 14:08:37 -0700116 AidlError(bool fatal);
Steven Moreland46e9da82018-07-27 15:45:29 -0700117
118 bool fatal_;
119
120 DISALLOW_COPY_AND_ASSIGN(AidlError);
121};
122
Steven Moreland92c55f12018-07-31 14:08:37 -0700123#define AIDL_ERROR(CONTEXT) ::AidlError(false /*fatal*/, (CONTEXT)).os_
124#define AIDL_FATAL(CONTEXT) ::AidlError(true /*fatal*/, (CONTEXT)).os_
Steven Moreland3f658cf2018-08-20 13:40:54 -0700125#define AIDL_FATAL_IF(CONDITION, CONTEXT) \
126 if (CONDITION) AIDL_FATAL(CONTEXT) << "Bad internal state: " << #CONDITION << ": "
Steven Moreland46e9da82018-07-27 15:45:29 -0700127
Casey Dahlina2f77c42015-12-01 18:26:02 -0800128namespace android {
129namespace aidl {
130
131class ValidatableType;
Jiyong Park1deecc32018-07-17 01:14:41 +0900132class AidlTypenames;
Casey Dahlina2f77c42015-12-01 18:26:02 -0800133
134} // namespace aidl
135} // namespace android
136
Jiyong Park68bc77a2018-07-19 19:00:45 +0900137class AidlAnnotation : public AidlNode {
138 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700139 static AidlAnnotation* Parse(const AidlLocation& location, const string& name);
140
Steven Moreland3f658cf2018-08-20 13:40:54 -0700141 AidlAnnotation(const AidlAnnotation&) = default;
Steven Moreland3be75772018-08-20 13:27:43 -0700142 AidlAnnotation(AidlAnnotation&&) = default;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900143 virtual ~AidlAnnotation() = default;
Steven Moreland3be75772018-08-20 13:27:43 -0700144
Jiyong Park68bc77a2018-07-19 19:00:45 +0900145 const string& GetName() const { return name_; }
146 string ToString() const { return "@" + name_; }
Jiyong Parka6605ab2018-11-11 14:30:21 +0900147 const string& GetComments() const { return comments_; }
148 void SetComments(const string& comments) { comments_ = comments; }
Jiyong Park68bc77a2018-07-19 19:00:45 +0900149
150 private:
Steven Moreland46e9da82018-07-27 15:45:29 -0700151 AidlAnnotation(const AidlLocation& location, const string& name);
Jiyong Park68bc77a2018-07-19 19:00:45 +0900152 const string name_;
Jiyong Parka6605ab2018-11-11 14:30:21 +0900153 string comments_;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900154};
155
Steven Moreland3be75772018-08-20 13:27:43 -0700156static inline bool operator<(const AidlAnnotation& lhs, const AidlAnnotation& rhs) {
157 return lhs.GetName() < rhs.GetName();
158}
159static inline bool operator==(const AidlAnnotation& lhs, const AidlAnnotation& rhs) {
160 return lhs.GetName() == rhs.GetName();
161}
Jiyong Park3656c3c2018-08-01 20:02:01 +0900162
Casey Dahline7922932016-02-29 17:23:01 -0800163class AidlAnnotatable : public AidlNode {
Casey Dahlin0ee37582015-09-30 16:31:55 -0700164 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700165 AidlAnnotatable(const AidlLocation& location);
Steven Moreland3f658cf2018-08-20 13:40:54 -0700166
167 AidlAnnotatable(const AidlAnnotatable&) = default;
168 AidlAnnotatable(AidlAnnotatable&&) = default;
Casey Dahline7922932016-02-29 17:23:01 -0800169 virtual ~AidlAnnotatable() = default;
170
Jiyong Parka6605ab2018-11-11 14:30:21 +0900171 void Annotate(vector<AidlAnnotation>&& annotations) { annotations_ = std::move(annotations); }
Jiyong Park68bc77a2018-07-19 19:00:45 +0900172 bool IsNullable() const;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900173 bool IsUtf8InCpp() const;
Jiyong Parka6605ab2018-11-11 14:30:21 +0900174 bool IsUnsupportedAppUsage() const;
Jeongik Cha698e6af2018-12-12 14:39:55 +0900175 bool IsSystemApi() const;
Jeongik Cha82317dd2019-02-27 20:26:11 +0900176 bool IsStableParcelable() const;
Jiyong Park68bc77a2018-07-19 19:00:45 +0900177 std::string ToString() const;
Casey Dahline7922932016-02-29 17:23:01 -0800178
Jiyong Parka6605ab2018-11-11 14:30:21 +0900179 const vector<AidlAnnotation>& GetAnnotations() const { return annotations_; }
Jiyong Park3656c3c2018-08-01 20:02:01 +0900180
Casey Dahline7922932016-02-29 17:23:01 -0800181 private:
Jiyong Parka6605ab2018-11-11 14:30:21 +0900182 vector<AidlAnnotation> annotations_;
Casey Dahline7922932016-02-29 17:23:01 -0800183};
184
Jiyong Park1deecc32018-07-17 01:14:41 +0900185class AidlQualifiedName;
186
187// AidlTypeSpecifier represents a reference to either a built-in type,
188// a defined type, or a variant (e.g., array of generic) of a type.
189class AidlTypeSpecifier final : public AidlAnnotatable {
Casey Dahline7922932016-02-29 17:23:01 -0800190 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700191 AidlTypeSpecifier(const AidlLocation& location, const string& unresolved_name, bool is_array,
192 vector<unique_ptr<AidlTypeSpecifier>>* type_params, const string& comments);
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900193 virtual ~AidlTypeSpecifier() = default;
Casey Dahlin0ee37582015-09-30 16:31:55 -0700194
Steven Moreland3f658cf2018-08-20 13:40:54 -0700195 // Copy of this type which is not an array.
196 AidlTypeSpecifier ArrayBase() const;
197
Jiyong Park1deecc32018-07-17 01:14:41 +0900198 // Returns the full-qualified name of the base type.
199 // int -> int
200 // int[] -> int
201 // List<String> -> List
202 // IFoo -> foo.bar.IFoo (if IFoo is in package foo.bar)
203 const string& GetName() const {
204 if (IsResolved()) {
205 return fully_qualified_name_;
206 } else {
207 return GetUnresolvedName();
208 }
209 }
Casey Dahlin0ee37582015-09-30 16:31:55 -0700210
Jiyong Park1deecc32018-07-17 01:14:41 +0900211 // Returns string representation of this type specifier.
212 // This is GetBaseTypeName() + array modifieir or generic type parameters
213 string ToString() const;
214
Jiyong Park02da7422018-07-16 16:00:26 +0900215 std::string Signature() const;
216
Jiyong Park1deecc32018-07-17 01:14:41 +0900217 const string& GetUnresolvedName() const { return unresolved_name_; }
218
219 const string& GetComments() const { return comments_; }
220
Jiyong Parka6605ab2018-11-11 14:30:21 +0900221 void SetComments(const string& comment) { comments_ = comment; }
222
Jiyong Park1deecc32018-07-17 01:14:41 +0900223 bool IsResolved() const { return fully_qualified_name_ != ""; }
224
225 bool IsArray() const { return is_array_; }
226
227 bool IsGeneric() const { return type_params_ != nullptr; }
228
Jiyong Park1deecc32018-07-17 01:14:41 +0900229 const vector<unique_ptr<AidlTypeSpecifier>>& GetTypeParameters() const { return *type_params_; }
230
231 // Resolve the base type name to a fully-qualified name. Return false if the
232 // resolution fails.
233 bool Resolve(android::aidl::AidlTypenames& typenames);
Casey Dahlin0ee37582015-09-30 16:31:55 -0700234
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900235 bool CheckValid(const AidlTypenames& typenames) const;
Jiyong Park1d2df7d2018-07-23 15:22:50 +0900236
Casey Dahlina2f77c42015-12-01 18:26:02 -0800237 void SetLanguageType(const android::aidl::ValidatableType* language_type) {
238 language_type_ = language_type;
239 }
240
241 template<typename T>
242 const T* GetLanguageType() const {
243 return reinterpret_cast<const T*>(language_type_);
244 }
Casey Dahlin0ee37582015-09-30 16:31:55 -0700245 private:
Steven Moreland3f658cf2018-08-20 13:40:54 -0700246 AidlTypeSpecifier(const AidlTypeSpecifier&) = default;
247
Jiyong Park1deecc32018-07-17 01:14:41 +0900248 const string unresolved_name_;
249 string fully_qualified_name_;
Steven Moreland3f658cf2018-08-20 13:40:54 -0700250 bool is_array_;
251 const shared_ptr<vector<unique_ptr<AidlTypeSpecifier>>> type_params_;
Jiyong Parka6605ab2018-11-11 14:30:21 +0900252 string comments_;
Casey Dahlina2f77c42015-12-01 18:26:02 -0800253 const android::aidl::ValidatableType* language_type_ = nullptr;
Casey Dahlin0ee37582015-09-30 16:31:55 -0700254};
255
Steven Moreland860b1942018-08-16 14:59:28 -0700256// Transforms a value string into a language specific form. Raw value as produced by
257// AidlConstantValue.
258using ConstantValueDecorator =
259 std::function<std::string(const AidlTypeSpecifier& type, const std::string& raw_value)>;
260
261// Returns the universal value unaltered.
262std::string AidlConstantValueDecorator(const AidlTypeSpecifier& type, const std::string& raw_value);
263
Steven Moreland9ea10e32018-07-19 15:26:09 -0700264class AidlConstantValue;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700265class AidlVariableDeclaration : public AidlNode {
266 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700267 AidlVariableDeclaration(const AidlLocation& location, AidlTypeSpecifier* type,
268 const std::string& name);
269 AidlVariableDeclaration(const AidlLocation& location, AidlTypeSpecifier* type,
270 const std::string& name, AidlConstantValue* default_value);
Steven Moreland5557f1c2018-07-02 13:50:23 -0700271 virtual ~AidlVariableDeclaration() = default;
272
273 std::string GetName() const { return name_; }
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900274 const AidlTypeSpecifier& GetType() const { return *type_; }
Steven Moreland9ea10e32018-07-19 15:26:09 -0700275 const AidlConstantValue* GetDefaultValue() const { return default_value_.get(); }
276
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900277 AidlTypeSpecifier* GetMutableType() { return type_.get(); }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700278
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900279 bool CheckValid(const AidlTypenames& typenames) const;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700280 std::string ToString() const;
Jiyong Park02da7422018-07-16 16:00:26 +0900281 std::string Signature() const;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700282
Steven Moreland860b1942018-08-16 14:59:28 -0700283 std::string ValueString(const ConstantValueDecorator& decorator) const;
Steven Moreland25294322018-08-07 18:13:55 -0700284
Steven Moreland5557f1c2018-07-02 13:50:23 -0700285 private:
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900286 std::unique_ptr<AidlTypeSpecifier> type_;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700287 std::string name_;
Steven Moreland9ea10e32018-07-19 15:26:09 -0700288 std::unique_ptr<AidlConstantValue> default_value_;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700289
290 DISALLOW_COPY_AND_ASSIGN(AidlVariableDeclaration);
291};
292
293class AidlArgument : public AidlVariableDeclaration {
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700294 public:
Casey Dahlinc378c992015-09-29 16:50:40 -0700295 enum Direction { IN_DIR = 1, OUT_DIR = 2, INOUT_DIR = 3 };
296
Steven Moreland46e9da82018-07-27 15:45:29 -0700297 AidlArgument(const AidlLocation& location, AidlArgument::Direction direction,
298 AidlTypeSpecifier* type, const std::string& name);
299 AidlArgument(const AidlLocation& location, AidlTypeSpecifier* type, const std::string& name);
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700300 virtual ~AidlArgument() = default;
301
Casey Dahlinc378c992015-09-29 16:50:40 -0700302 Direction GetDirection() const { return direction_; }
Christopher Wileyad339272015-10-05 19:11:58 -0700303 bool IsOut() const { return direction_ & OUT_DIR; }
304 bool IsIn() const { return direction_ & IN_DIR; }
Casey Dahlinc378c992015-09-29 16:50:40 -0700305 bool DirectionWasSpecified() const { return direction_specified_; }
Jiyong Park3656c3c2018-08-01 20:02:01 +0900306 string GetDirectionSpecifier() const;
Christopher Wileyad339272015-10-05 19:11:58 -0700307
Casey Dahlinc378c992015-09-29 16:50:40 -0700308 std::string ToString() const;
Jiyong Park02da7422018-07-16 16:00:26 +0900309 std::string Signature() const;
Casey Dahlinc378c992015-09-29 16:50:40 -0700310
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700311 private:
Casey Dahlinc378c992015-09-29 16:50:40 -0700312 Direction direction_;
313 bool direction_specified_;
314
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700315 DISALLOW_COPY_AND_ASSIGN(AidlArgument);
Casey Dahlina834dd42015-09-23 11:52:15 -0700316};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800317
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800318class AidlMethod;
Steven Moreland693640b2018-07-19 13:46:27 -0700319class AidlConstantDeclaration;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800320class AidlMember : public AidlNode {
321 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700322 AidlMember(const AidlLocation& location);
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800323 virtual ~AidlMember() = default;
324
325 virtual AidlMethod* AsMethod() { return nullptr; }
Steven Moreland693640b2018-07-19 13:46:27 -0700326 virtual AidlConstantDeclaration* AsConstantDeclaration() { return nullptr; }
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800327
328 private:
329 DISALLOW_COPY_AND_ASSIGN(AidlMember);
330};
331
Steven Moreland693640b2018-07-19 13:46:27 -0700332class AidlConstantValue : public AidlNode {
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800333 public:
Steven Moreland860b1942018-08-16 14:59:28 -0700334 enum class Type { ERROR, ARRAY, BOOLEAN, CHARACTER, FLOATING, HEXIDECIMAL, INTEGRAL, STRING };
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800335
Steven Moreland693640b2018-07-19 13:46:27 -0700336 virtual ~AidlConstantValue() = default;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800337
Steven Moreland25294322018-08-07 18:13:55 -0700338 static AidlConstantValue* Boolean(const AidlLocation& location, bool value);
339 static AidlConstantValue* Character(const AidlLocation& location, char value);
Steven Moreland693640b2018-07-19 13:46:27 -0700340 // example: "0x4f"
Steven Moreland1c4ba202018-08-09 10:49:54 -0700341 static AidlConstantValue* Floating(const AidlLocation& location, const std::string& value);
Steven Moreland25294322018-08-07 18:13:55 -0700342 static AidlConstantValue* Hex(const AidlLocation& location, const std::string& value);
343 // example: 123, -5498, maybe any size
344 static AidlConstantValue* Integral(const AidlLocation& location, const std::string& value);
Steven Moreland860b1942018-08-16 14:59:28 -0700345 static AidlConstantValue* Array(const AidlLocation& location,
346 std::vector<std::unique_ptr<AidlConstantValue>>* values);
Steven Moreland693640b2018-07-19 13:46:27 -0700347 // example: "\"asdf\""
Steven Moreland25294322018-08-07 18:13:55 -0700348 static AidlConstantValue* String(const AidlLocation& location, const std::string& value);
Steven Moreland693640b2018-07-19 13:46:27 -0700349
350 Type GetType() const { return type_; }
Steven Moreland25294322018-08-07 18:13:55 -0700351
352 bool CheckValid() const;
Steven Moreland860b1942018-08-16 14:59:28 -0700353
354 // Raw value of type (currently valid in C++ and Java). Empty string on error.
355 string As(const AidlTypeSpecifier& type, const ConstantValueDecorator& decorator) const;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800356
357 private:
Steven Moreland46e9da82018-07-27 15:45:29 -0700358 AidlConstantValue(const AidlLocation& location, Type type, const std::string& checked_value);
Steven Moreland860b1942018-08-16 14:59:28 -0700359 AidlConstantValue(const AidlLocation& location, Type type,
360 std::vector<std::unique_ptr<AidlConstantValue>>* values);
Steven Moreland25294322018-08-07 18:13:55 -0700361 static string ToString(Type type);
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800362
Steven Moreland693640b2018-07-19 13:46:27 -0700363 const Type type_ = Type::ERROR;
Steven Moreland860b1942018-08-16 14:59:28 -0700364 const std::vector<std::unique_ptr<AidlConstantValue>> values_; // if type_ == ARRAY
365 const std::string value_; // otherwise
Steven Moreland693640b2018-07-19 13:46:27 -0700366
367 DISALLOW_COPY_AND_ASSIGN(AidlConstantValue);
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700368};
369
Steven Moreland693640b2018-07-19 13:46:27 -0700370class AidlConstantDeclaration : public AidlMember {
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700371 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700372 AidlConstantDeclaration(const AidlLocation& location, AidlTypeSpecifier* specifier,
373 const std::string& name, AidlConstantValue* value);
Steven Moreland693640b2018-07-19 13:46:27 -0700374 virtual ~AidlConstantDeclaration() = default;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700375
Steven Moreland693640b2018-07-19 13:46:27 -0700376 const AidlTypeSpecifier& GetType() const { return *type_; }
Steven Moreland4d12f9a2018-10-31 14:30:55 -0700377 AidlTypeSpecifier* GetMutableType() { return type_.get(); }
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700378 const std::string& GetName() const { return name_; }
Steven Moreland693640b2018-07-19 13:46:27 -0700379 const AidlConstantValue& GetValue() const { return *value_; }
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900380 bool CheckValid(const AidlTypenames& typenames) const;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700381
Jiyong Parka428d212018-08-29 22:26:30 +0900382 std::string ToString() const;
383 std::string Signature() const;
Steven Moreland860b1942018-08-16 14:59:28 -0700384 string ValueString(const ConstantValueDecorator& decorator) const {
385 return GetValue().As(GetType(), decorator);
386 }
Steven Moreland25294322018-08-07 18:13:55 -0700387
Steven Moreland693640b2018-07-19 13:46:27 -0700388 AidlConstantDeclaration* AsConstantDeclaration() override { return this; }
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700389
390 private:
Steven Moreland693640b2018-07-19 13:46:27 -0700391 const unique_ptr<AidlTypeSpecifier> type_;
392 const std::string name_;
393 const unique_ptr<AidlConstantValue> value_;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700394
Steven Moreland693640b2018-07-19 13:46:27 -0700395 DISALLOW_COPY_AND_ASSIGN(AidlConstantDeclaration);
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800396};
397
398class AidlMethod : public AidlMember {
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700399 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700400 AidlMethod(const AidlLocation& location, bool oneway, AidlTypeSpecifier* type,
401 const std::string& name, std::vector<std::unique_ptr<AidlArgument>>* args,
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900402 const std::string& comments);
Steven Moreland46e9da82018-07-27 15:45:29 -0700403 AidlMethod(const AidlLocation& location, bool oneway, AidlTypeSpecifier* type,
404 const std::string& name, std::vector<std::unique_ptr<AidlArgument>>* args,
Jiyong Park5b708382018-08-03 18:08:26 +0900405 const std::string& comments, int id, bool is_user_defined = true);
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700406 virtual ~AidlMethod() = default;
407
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800408 AidlMethod* AsMethod() override { return this; }
409
Casey Dahlinf4a93112015-10-05 16:58:09 -0700410 const std::string& GetComments() const { return comments_; }
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900411 const AidlTypeSpecifier& GetType() const { return *type_; }
412 AidlTypeSpecifier* GetMutableType() { return type_.get(); }
Steven Morelandacd53472018-12-14 10:17:26 -0800413
Steven Moreland8c70ba92018-12-17 10:20:31 -0800414 // set if this method is part of an interface that is marked oneway
415 void ApplyInterfaceOneway(bool oneway) { oneway_ = oneway_ || oneway; }
Casey Dahlinf4a93112015-10-05 16:58:09 -0700416 bool IsOneway() const { return oneway_; }
Steven Morelandacd53472018-12-14 10:17:26 -0800417
Casey Dahlinf4a93112015-10-05 16:58:09 -0700418 const std::string& GetName() const { return name_; }
Casey Dahlinf4a93112015-10-05 16:58:09 -0700419 bool HasId() const { return has_id_; }
Jiyong Parked65bf42018-08-28 15:43:27 +0900420 int GetId() const { return id_; }
Casey Dahlinf4a93112015-10-05 16:58:09 -0700421 void SetId(unsigned id) { id_ = id; }
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700422
Jiyong Park309668e2018-07-28 16:55:44 +0900423 bool IsUserDefined() const { return is_user_defined_; }
424
Casey Dahlinf4a93112015-10-05 16:58:09 -0700425 const std::vector<std::unique_ptr<AidlArgument>>& GetArguments() const {
Christopher Wileyad339272015-10-05 19:11:58 -0700426 return arguments_;
427 }
428 // An inout parameter will appear in both GetInArguments()
429 // and GetOutArguments(). AidlMethod retains ownership of the argument
430 // pointers returned in this way.
431 const std::vector<const AidlArgument*>& GetInArguments() const {
432 return in_arguments_;
433 }
434 const std::vector<const AidlArgument*>& GetOutArguments() const {
435 return out_arguments_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700436 }
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700437
Jiyong Park309668e2018-07-28 16:55:44 +0900438 // name + type parameter types
439 // i.e, foo(int, String)
Jiyong Park02da7422018-07-16 16:00:26 +0900440 std::string Signature() const;
441
Jiyong Park309668e2018-07-28 16:55:44 +0900442 // return type + name + type parameter types + annotations
443 // i.e, boolean foo(int, @Nullable String)
444 std::string ToString() const;
445
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700446 private:
Casey Dahlinf4a93112015-10-05 16:58:09 -0700447 bool oneway_;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700448 std::string comments_;
Jiyong Parkd59a10d2018-07-18 11:12:55 +0900449 std::unique_ptr<AidlTypeSpecifier> type_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700450 std::string name_;
Christopher Wileyad339272015-10-05 19:11:58 -0700451 const std::vector<std::unique_ptr<AidlArgument>> arguments_;
452 std::vector<const AidlArgument*> in_arguments_;
453 std::vector<const AidlArgument*> out_arguments_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700454 bool has_id_;
455 int id_;
Jiyong Park309668e2018-07-28 16:55:44 +0900456 bool is_user_defined_ = true;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700457
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700458 DISALLOW_COPY_AND_ASSIGN(AidlMethod);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700459};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800460
Steven Morelandc258abc2018-07-10 14:03:38 -0700461class AidlDefinedType;
Jiyong Parkb034bf02018-07-30 17:44:33 +0900462class AidlInterface;
463class AidlParcelable;
464class AidlStructuredParcelable;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800465
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700466class AidlQualifiedName : public AidlNode {
467 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700468 AidlQualifiedName(const AidlLocation& location, const std::string& term,
469 const std::string& comments);
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700470 virtual ~AidlQualifiedName() = default;
471
472 const std::vector<std::string>& GetTerms() const { return terms_; }
473 const std::string& GetComments() const { return comments_; }
474 std::string GetDotName() const { return android::base::Join(terms_, '.'); }
Ningyuan Wangd17c58b2016-09-29 14:33:14 -0700475 std::string GetColonName() const { return android::base::Join(terms_, "::"); }
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700476
Chih-Hung Hsiehf05cc262016-07-27 11:42:51 -0700477 void AddTerm(const std::string& term);
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700478
479 private:
480 std::vector<std::string> terms_;
481 std::string comments_;
482
483 DISALLOW_COPY_AND_ASSIGN(AidlQualifiedName);
484};
485
Steven Moreland46e9da82018-07-27 15:45:29 -0700486class AidlInterface;
487class AidlParcelable;
488class AidlStructuredParcelable;
Jiyong Park1deecc32018-07-17 01:14:41 +0900489// AidlDefinedType represents either an interface or a parcelable that is
490// defined in the source file.
491class AidlDefinedType : public AidlAnnotatable {
Steven Moreland787b0432018-07-03 09:00:58 -0700492 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700493 AidlDefinedType(const AidlLocation& location, const std::string& name,
494 const std::string& comments, const std::vector<std::string>& package);
Steven Moreland787b0432018-07-03 09:00:58 -0700495 virtual ~AidlDefinedType() = default;
496
Jiyong Park1deecc32018-07-17 01:14:41 +0900497 const std::string& GetName() const { return name_; };
Jiyong Park1deecc32018-07-17 01:14:41 +0900498 const std::string& GetComments() const { return comments_; }
Jiyong Parka6605ab2018-11-11 14:30:21 +0900499 void SetComments(const std::string comments) { comments_ = comments; }
Jiyong Park1deecc32018-07-17 01:14:41 +0900500
Steven Moreland787b0432018-07-03 09:00:58 -0700501 /* dot joined package, example: "android.package.foo" */
502 std::string GetPackage() const;
503 /* dot joined package and name, example: "android.package.foo.IBar" */
504 std::string GetCanonicalName() const;
505 const std::vector<std::string>& GetSplitPackage() const { return package_; }
506
Steven Morelanded83a282018-07-17 13:27:29 -0700507 virtual std::string GetPreprocessDeclarationName() const = 0;
Steven Morelandc258abc2018-07-10 14:03:38 -0700508
Steven Moreland5557f1c2018-07-02 13:50:23 -0700509 virtual const AidlStructuredParcelable* AsStructuredParcelable() const { return nullptr; }
Steven Morelandc258abc2018-07-10 14:03:38 -0700510 virtual const AidlParcelable* AsParcelable() const { return nullptr; }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700511 virtual const AidlInterface* AsInterface() const { return nullptr; }
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900512 virtual bool CheckValid(const AidlTypenames&) const { return true; }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700513
Steven Morelandc258abc2018-07-10 14:03:38 -0700514 AidlStructuredParcelable* AsStructuredParcelable() {
515 return const_cast<AidlStructuredParcelable*>(
516 const_cast<const AidlDefinedType*>(this)->AsStructuredParcelable());
517 }
518 AidlParcelable* AsParcelable() {
519 return const_cast<AidlParcelable*>(const_cast<const AidlDefinedType*>(this)->AsParcelable());
520 }
521 AidlInterface* AsInterface() {
522 return const_cast<AidlInterface*>(const_cast<const AidlDefinedType*>(this)->AsInterface());
523 }
524
Steven Moreland6cee3482018-07-18 14:39:58 -0700525 const AidlParcelable* AsUnstructuredParcelable() const {
526 if (this->AsStructuredParcelable() != nullptr) return nullptr;
527 return this->AsParcelable();
528 }
529 AidlParcelable* AsUnstructuredParcelable() {
530 return const_cast<AidlParcelable*>(
531 const_cast<const AidlDefinedType*>(this)->AsUnstructuredParcelable());
532 }
533
Jiyong Park1deecc32018-07-17 01:14:41 +0900534 void SetLanguageType(const android::aidl::ValidatableType* language_type) {
535 language_type_ = language_type;
536 }
537
538 template <typename T>
539 const T* GetLanguageType() const {
540 return reinterpret_cast<const T*>(language_type_);
541 }
542
Jiyong Park02da7422018-07-16 16:00:26 +0900543 virtual void Write(CodeWriter* writer) const = 0;
544
Steven Moreland787b0432018-07-03 09:00:58 -0700545 private:
Jiyong Park1deecc32018-07-17 01:14:41 +0900546 std::string name_;
Jiyong Park1deecc32018-07-17 01:14:41 +0900547 std::string comments_;
548 const android::aidl::ValidatableType* language_type_ = nullptr;
Steven Moreland787b0432018-07-03 09:00:58 -0700549 const std::vector<std::string> package_;
Steven Moreland5557f1c2018-07-02 13:50:23 -0700550
551 DISALLOW_COPY_AND_ASSIGN(AidlDefinedType);
Steven Moreland787b0432018-07-03 09:00:58 -0700552};
553
554class AidlParcelable : public AidlDefinedType {
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700555 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700556 AidlParcelable(const AidlLocation& location, AidlQualifiedName* name,
Jiyong Parka6605ab2018-11-11 14:30:21 +0900557 const std::vector<std::string>& package, const std::string& comments,
558 const std::string& cpp_header = "");
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700559 virtual ~AidlParcelable() = default;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800560
Ningyuan Wangd17c58b2016-09-29 14:33:14 -0700561 // C++ uses "::" instead of "." to refer to a inner class.
562 std::string GetCppName() const { return name_->GetColonName(); }
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800563 std::string GetCppHeader() const { return cpp_header_; }
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800564
Jeongik Cha82317dd2019-02-27 20:26:11 +0900565 bool CheckValid(const AidlTypenames& typenames) const override;
566
Steven Morelandc258abc2018-07-10 14:03:38 -0700567 const AidlParcelable* AsParcelable() const override { return this; }
Steven Morelanded83a282018-07-17 13:27:29 -0700568 std::string GetPreprocessDeclarationName() const override { return "parcelable"; }
Steven Morelandc258abc2018-07-10 14:03:38 -0700569
Jiyong Park02da7422018-07-16 16:00:26 +0900570 void Write(CodeWriter* writer) const override;
571
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700572 private:
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800573 std::unique_ptr<AidlQualifiedName> name_;
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800574 std::string cpp_header_;
Casey Dahlin59401da2015-10-09 18:16:45 -0700575
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700576 DISALLOW_COPY_AND_ASSIGN(AidlParcelable);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700577};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800578
Steven Moreland5557f1c2018-07-02 13:50:23 -0700579class AidlStructuredParcelable : public AidlParcelable {
580 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700581 AidlStructuredParcelable(const AidlLocation& location, AidlQualifiedName* name,
Jiyong Parka6605ab2018-11-11 14:30:21 +0900582 const std::vector<std::string>& package, const std::string& comments,
Steven Moreland5557f1c2018-07-02 13:50:23 -0700583 std::vector<std::unique_ptr<AidlVariableDeclaration>>* variables);
584
585 const std::vector<std::unique_ptr<AidlVariableDeclaration>>& GetFields() const {
586 return variables_;
587 }
588
Steven Morelandc258abc2018-07-10 14:03:38 -0700589 const AidlStructuredParcelable* AsStructuredParcelable() const override { return this; }
Steven Morelanded83a282018-07-17 13:27:29 -0700590 std::string GetPreprocessDeclarationName() const override { return "structured_parcelable"; }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700591
Jiyong Park02da7422018-07-16 16:00:26 +0900592 void Write(CodeWriter* writer) const override;
593
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900594 bool CheckValid(const AidlTypenames& typenames) const override;
595
Steven Moreland5557f1c2018-07-02 13:50:23 -0700596 private:
597 const std::vector<std::unique_ptr<AidlVariableDeclaration>> variables_;
598
599 DISALLOW_COPY_AND_ASSIGN(AidlStructuredParcelable);
600};
601
Jiyong Park1deecc32018-07-17 01:14:41 +0900602class AidlInterface final : public AidlDefinedType {
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700603 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700604 AidlInterface(const AidlLocation& location, const std::string& name, const std::string& comments,
605 bool oneway_, std::vector<std::unique_ptr<AidlMember>>* members,
Christopher Wileyd76067c2015-10-19 17:00:13 -0700606 const std::vector<std::string>& package);
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700607 virtual ~AidlInterface() = default;
608
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700609 const std::vector<std::unique_ptr<AidlMethod>>& GetMethods() const
610 { return methods_; }
Jiyong Park309668e2018-07-28 16:55:44 +0900611 std::vector<std::unique_ptr<AidlMethod>>& GetMutableMethods() { return methods_; }
Steven Moreland693640b2018-07-19 13:46:27 -0700612 const std::vector<std::unique_ptr<AidlConstantDeclaration>>& GetConstantDeclarations() const {
613 return constants_;
614 }
Casey Dahlina2f77c42015-12-01 18:26:02 -0800615
Steven Morelandc258abc2018-07-10 14:03:38 -0700616 const AidlInterface* AsInterface() const override { return this; }
Steven Morelanded83a282018-07-17 13:27:29 -0700617 std::string GetPreprocessDeclarationName() const override { return "interface"; }
Steven Moreland5557f1c2018-07-02 13:50:23 -0700618
Jiyong Park02da7422018-07-16 16:00:26 +0900619 void Write(CodeWriter* writer) const override;
620
Jeongik Chadb0f59e2018-11-01 18:11:21 +0900621 bool CheckValid(const AidlTypenames& typenames) const override;
622
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700623 private:
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700624 std::vector<std::unique_ptr<AidlMethod>> methods_;
Steven Moreland693640b2018-07-19 13:46:27 -0700625 std::vector<std::unique_ptr<AidlConstantDeclaration>> constants_;
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700626
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700627 DISALLOW_COPY_AND_ASSIGN(AidlInterface);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700628};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800629
Casey Dahlin0edf3422015-10-07 12:34:59 -0700630class AidlImport : public AidlNode {
631 public:
Steven Moreland46e9da82018-07-27 15:45:29 -0700632 AidlImport(const AidlLocation& location, const std::string& needed_class);
Casey Dahlin0edf3422015-10-07 12:34:59 -0700633 virtual ~AidlImport() = default;
634
Casey Dahlin0edf3422015-10-07 12:34:59 -0700635 const std::string& GetFilename() const { return filename_; }
636 const std::string& GetNeededClass() const { return needed_class_; }
Casey Dahlin0edf3422015-10-07 12:34:59 -0700637
638 private:
Casey Dahlin0edf3422015-10-07 12:34:59 -0700639 std::string filename_;
640 std::string needed_class_;
Casey Dahlin0edf3422015-10-07 12:34:59 -0700641
642 DISALLOW_COPY_AND_ASSIGN(AidlImport);
Casey Dahline2507492015-09-14 17:11:20 -0700643};
644
645class Parser {
Casey Dahlindd691812015-09-09 17:59:06 -0700646 public:
Casey Dahline2507492015-09-14 17:11:20 -0700647 ~Parser();
Casey Dahlindd691812015-09-09 17:59:06 -0700648
Steven Moreland64e29be2018-08-08 18:52:19 -0700649 // Parse contents of file |filename|. Should only be called once.
650 static std::unique_ptr<Parser> Parse(const std::string& filename,
651 const android::aidl::IoDelegate& io_delegate,
652 AidlTypenames& typenames);
Casey Dahlin89d44842015-09-24 18:45:54 -0700653
Steven Moreland2ca4fcb2018-06-27 16:01:01 -0700654 void AddError() { error_++; }
Steven Moreland64e29be2018-08-08 18:52:19 -0700655 bool HasError() { return error_ != 0; }
Casey Dahlindd691812015-09-09 17:59:06 -0700656
Casey Dahlin3c6df362015-10-06 15:48:35 -0700657 const std::string& FileName() const { return filename_; }
Casey Dahlin42727f82015-10-12 19:23:40 -0700658 void* Scanner() const { return scanner_; }
Casey Dahlindd691812015-09-09 17:59:06 -0700659
Steven Moreland46e9da82018-07-27 15:45:29 -0700660 void AddImport(AidlImport* import);
Christopher Wileyd76067c2015-10-19 17:00:13 -0700661 const std::vector<std::unique_ptr<AidlImport>>& GetImports() {
662 return imports_;
663 }
Casey Dahlin0edf3422015-10-07 12:34:59 -0700664 void ReleaseImports(std::vector<std::unique_ptr<AidlImport>>* ret) {
Jiyong Parkb034bf02018-07-30 17:44:33 +0900665 *ret = std::move(imports_);
666 imports_.clear();
Casey Dahlin0edf3422015-10-07 12:34:59 -0700667 }
Casey Dahlindd691812015-09-09 17:59:06 -0700668
Jiyong Parkb034bf02018-07-30 17:44:33 +0900669 void SetPackage(unique_ptr<AidlQualifiedName> name) { package_ = std::move(name); }
670 std::vector<std::string> Package() const;
Jiyong Park1deecc32018-07-17 01:14:41 +0900671
672 void DeferResolution(AidlTypeSpecifier* typespec) {
673 unresolved_typespecs_.emplace_back(typespec);
674 }
675
Jiyong Parke59c3682018-09-11 23:10:25 +0900676 const vector<AidlTypeSpecifier*>& GetUnresolvedTypespecs() const { return unresolved_typespecs_; }
677
Jiyong Park1deecc32018-07-17 01:14:41 +0900678 bool Resolve();
679
Jiyong Parkb034bf02018-07-30 17:44:33 +0900680 void AddDefinedType(unique_ptr<AidlDefinedType> type) {
681 // Parser does NOT own AidlDefinedType, it just has references to the types
682 // that it encountered while parsing the input file.
683 defined_types_.emplace_back(type.get());
684
685 // AidlDefinedType IS owned by AidlTypenames
686 if (!typenames_.AddDefinedType(std::move(type))) {
687 AddError();
688 }
689 }
690
691 vector<AidlDefinedType*>& GetDefinedTypes() { return defined_types_; }
692
Casey Dahlindd691812015-09-09 17:59:06 -0700693 private:
Steven Moreland64e29be2018-08-08 18:52:19 -0700694 explicit Parser(const std::string& filename, std::string& raw_buffer,
695 android::aidl::AidlTypenames& typenames);
696
Casey Dahlindd691812015-09-09 17:59:06 -0700697 std::string filename_;
Christopher Wileyd76067c2015-10-19 17:00:13 -0700698 std::unique_ptr<AidlQualifiedName> package_;
Jiyong Parkb034bf02018-07-30 17:44:33 +0900699 AidlTypenames& typenames_;
Steven Moreland64e29be2018-08-08 18:52:19 -0700700
701 void* scanner_ = nullptr;
702 YY_BUFFER_STATE buffer_;
703 int error_ = 0;
704
705 std::vector<std::unique_ptr<AidlImport>> imports_;
Jiyong Parkb034bf02018-07-30 17:44:33 +0900706 vector<AidlDefinedType*> defined_types_;
Jiyong Park1deecc32018-07-17 01:14:41 +0900707 vector<AidlTypeSpecifier*> unresolved_typespecs_;
Casey Dahlindd691812015-09-09 17:59:06 -0700708
Casey Dahline2507492015-09-14 17:11:20 -0700709 DISALLOW_COPY_AND_ASSIGN(Parser);
Casey Dahlindd691812015-09-09 17:59:06 -0700710};