blob: 7982e761bb8e8aecdb3d01b280d1e24204dac6d2 [file] [log] [blame]
Christopher Wiley89e35862015-08-30 10:57:07 -07001#ifndef AIDL_AIDL_LANGUAGE_H_
Christopher Wileye9351cc2016-01-21 15:56:30 -08002#define AIDL_AIDL_LANGUAGE_H_
Christopher Wileyec31a052016-01-25 07:28:51 -08003
Casey Dahlinbc7a50a2015-09-28 19:20:50 -07004#include <memory>
Casey Dahlindd691812015-09-09 17:59:06 -07005#include <string>
Casey Dahlinbc7a50a2015-09-28 19:20:50 -07006#include <vector>
Casey Dahlindd691812015-09-09 17:59:06 -07007
Elliott Hughes0a620672015-12-04 13:53:18 -08008#include <android-base/macros.h>
9#include <android-base/strings.h>
Casey Dahlin73d46b02015-09-11 02:47:54 +000010
Christopher Wiley4a2884b2015-10-07 11:27:45 -070011#include <io_delegate.h>
12
Casey Dahlin89d44842015-09-24 18:45:54 -070013struct yy_buffer_state;
14typedef yy_buffer_state* YY_BUFFER_STATE;
15
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070016class AidlToken {
17 public:
18 AidlToken(const std::string& text, const std::string& comments);
Adam Lesinskiffa16862014-01-23 18:17:42 -080019
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070020 const std::string& GetText() const { return text_; }
21 const std::string& GetComments() const { return comments_; }
Adam Lesinskiffa16862014-01-23 18:17:42 -080022
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070023 private:
24 std::string text_;
25 std::string comments_;
Casey Dahlin082f1d12015-09-21 14:06:25 -070026
Casey Dahlincdbbc8c2015-10-14 15:31:04 -070027 DISALLOW_COPY_AND_ASSIGN(AidlToken);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -070028};
Adam Lesinskiffa16862014-01-23 18:17:42 -080029
Casey Dahlinbc7a50a2015-09-28 19:20:50 -070030class AidlNode {
31 public:
32 AidlNode() = default;
33 virtual ~AidlNode() = default;
34
35 private:
36 DISALLOW_COPY_AND_ASSIGN(AidlNode);
37};
38
Casey Dahlina2f77c42015-12-01 18:26:02 -080039namespace android {
40namespace aidl {
41
42class ValidatableType;
43
44} // namespace aidl
45} // namespace android
46
Casey Dahline7922932016-02-29 17:23:01 -080047class AidlAnnotatable : public AidlNode {
Casey Dahlin0ee37582015-09-30 16:31:55 -070048 public:
Christopher Wileyec31a052016-01-25 07:28:51 -080049 enum Annotation : uint32_t {
50 AnnotationNone = 0,
51 AnnotationNullable = 1 << 0,
52 AnnotationUtf8 = 1 << 1,
53 AnnotationUtf8InCpp = 1 << 2,
54 };
55
Casey Dahline7922932016-02-29 17:23:01 -080056 AidlAnnotatable() = default;
57 virtual ~AidlAnnotatable() = default;
58
59 void Annotate(AidlAnnotatable::Annotation annotation) {
60 annotations_ =
61 static_cast<AidlAnnotatable::Annotation>(annotations_ | annotation);
62 }
63 bool IsNullable() const {
64 return annotations_ & AnnotationNullable;
65 }
66 bool IsUtf8() const {
67 return annotations_ & AnnotationUtf8;
68 }
69 bool IsUtf8InCpp() const {
70 return annotations_ & AnnotationUtf8InCpp;
71 }
72
73 private:
74 Annotation annotations_ = AnnotationNone;
75
76 DISALLOW_COPY_AND_ASSIGN(AidlAnnotatable);
77};
78
79class AidlType : public AidlAnnotatable {
80 public:
Casey Dahlinf2d23f72015-10-02 16:19:19 -070081 AidlType(const std::string& name, unsigned line,
Casey Dahlinf7a421c2015-10-05 17:24:28 -070082 const std::string& comments, bool is_array);
Casey Dahlin0ee37582015-09-30 16:31:55 -070083 virtual ~AidlType() = default;
84
Casey Dahlinf2d23f72015-10-02 16:19:19 -070085 const std::string& GetName() const { return name_; }
86 unsigned GetLine() const { return line_; }
Casey Dahlinf7a421c2015-10-05 17:24:28 -070087 bool IsArray() const { return is_array_; }
Casey Dahlinf2d23f72015-10-02 16:19:19 -070088 const std::string& GetComments() const { return comments_; }
Casey Dahlin0ee37582015-09-30 16:31:55 -070089
Casey Dahlin70078e62015-09-30 17:01:30 -070090 std::string ToString() const;
Casey Dahlin0ee37582015-09-30 16:31:55 -070091
Casey Dahlina2f77c42015-12-01 18:26:02 -080092 void SetLanguageType(const android::aidl::ValidatableType* language_type) {
93 language_type_ = language_type;
94 }
95
96 template<typename T>
97 const T* GetLanguageType() const {
98 return reinterpret_cast<const T*>(language_type_);
99 }
100
Casey Dahlin0ee37582015-09-30 16:31:55 -0700101 private:
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700102 std::string name_;
103 unsigned line_;
Casey Dahlinf7a421c2015-10-05 17:24:28 -0700104 bool is_array_;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700105 std::string comments_;
Casey Dahlina2f77c42015-12-01 18:26:02 -0800106 const android::aidl::ValidatableType* language_type_ = nullptr;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700107
Casey Dahlin0ee37582015-09-30 16:31:55 -0700108 DISALLOW_COPY_AND_ASSIGN(AidlType);
109};
110
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700111class AidlArgument : public AidlNode {
112 public:
Casey Dahlinc378c992015-09-29 16:50:40 -0700113 enum Direction { IN_DIR = 1, OUT_DIR = 2, INOUT_DIR = 3 };
114
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700115 AidlArgument(AidlArgument::Direction direction, AidlType* type,
Casey Dahlin308f9d42015-10-05 18:48:42 -0700116 std::string name, unsigned line);
Casey Dahlin42727f82015-10-12 19:23:40 -0700117 AidlArgument(AidlType* type, std::string name, unsigned line);
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700118 virtual ~AidlArgument() = default;
119
Casey Dahlinc378c992015-09-29 16:50:40 -0700120 Direction GetDirection() const { return direction_; }
Christopher Wileyad339272015-10-05 19:11:58 -0700121 bool IsOut() const { return direction_ & OUT_DIR; }
122 bool IsIn() const { return direction_ & IN_DIR; }
Casey Dahlinc378c992015-09-29 16:50:40 -0700123 bool DirectionWasSpecified() const { return direction_specified_; }
Christopher Wileyad339272015-10-05 19:11:58 -0700124
Casey Dahlind127b502015-09-30 12:51:08 -0700125 std::string GetName() const { return name_; }
126 int GetLine() const { return line_; }
Casey Dahlin0ee37582015-09-30 16:31:55 -0700127 const AidlType& GetType() const { return *type_; }
Casey Dahlina2f77c42015-12-01 18:26:02 -0800128 AidlType* GetMutableType() { return type_.get(); }
Casey Dahlind127b502015-09-30 12:51:08 -0700129
Casey Dahlinc378c992015-09-29 16:50:40 -0700130 std::string ToString() const;
131
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700132 private:
Casey Dahlin0ee37582015-09-30 16:31:55 -0700133 std::unique_ptr<AidlType> type_;
Casey Dahlinc378c992015-09-29 16:50:40 -0700134 Direction direction_;
135 bool direction_specified_;
Casey Dahlind127b502015-09-30 12:51:08 -0700136 std::string name_;
Casey Dahlin308f9d42015-10-05 18:48:42 -0700137 unsigned line_;
Casey Dahlinc378c992015-09-29 16:50:40 -0700138
Casey Dahlinbc7a50a2015-09-28 19:20:50 -0700139 DISALLOW_COPY_AND_ASSIGN(AidlArgument);
Casey Dahlina834dd42015-09-23 11:52:15 -0700140};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800141
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800142class AidlMethod;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700143class AidlIntConstant;
144class AidlStringConstant;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800145class AidlMember : public AidlNode {
146 public:
147 AidlMember() = default;
148 virtual ~AidlMember() = default;
149
150 virtual AidlMethod* AsMethod() { return nullptr; }
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700151 virtual AidlIntConstant* AsIntConstant() { return nullptr; }
152 virtual AidlStringConstant* AsStringConstant() { return nullptr; }
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800153
154 private:
155 DISALLOW_COPY_AND_ASSIGN(AidlMember);
156};
157
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700158class AidlIntConstant : public AidlMember {
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800159 public:
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700160 AidlIntConstant(std::string name, int32_t value);
Roshan Pius3b2203d2016-07-22 16:13:20 -0700161 AidlIntConstant(std::string name, std::string value, unsigned line_number);
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700162 virtual ~AidlIntConstant() = default;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800163
164 const std::string& GetName() const { return name_; }
165 int GetValue() const { return value_; }
Roshan Pius3b2203d2016-07-22 16:13:20 -0700166 bool IsValid() const { return is_valid_; }
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800167
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700168 AidlIntConstant* AsIntConstant() override { return this; }
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800169
170 private:
171 std::string name_;
172 int32_t value_;
Roshan Pius3b2203d2016-07-22 16:13:20 -0700173 bool is_valid_;
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800174
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700175 DISALLOW_COPY_AND_ASSIGN(AidlIntConstant);
176};
177
178class AidlStringConstant : public AidlMember {
179 public:
180 AidlStringConstant(std::string name, std::string value, unsigned line_number);
181 virtual ~AidlStringConstant() = default;
182
183 const std::string& GetName() const { return name_; }
184 const std::string& GetValue() const { return value_; }
185 bool IsValid() const { return is_valid_; }
186
187 AidlStringConstant* AsStringConstant() override { return this; }
188
189 private:
190 std::string name_;
191 std::string value_;
192 bool is_valid_;
193
194 DISALLOW_COPY_AND_ASSIGN(AidlStringConstant);
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800195};
196
197class AidlMethod : public AidlMember {
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700198 public:
Casey Dahlinf4a93112015-10-05 16:58:09 -0700199 AidlMethod(bool oneway, AidlType* type, std::string name,
200 std::vector<std::unique_ptr<AidlArgument>>* args,
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700201 unsigned line, const std::string& comments);
Casey Dahlinf4a93112015-10-05 16:58:09 -0700202 AidlMethod(bool oneway, AidlType* type, std::string name,
203 std::vector<std::unique_ptr<AidlArgument>>* args,
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700204 unsigned line, const std::string& comments, int id);
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700205 virtual ~AidlMethod() = default;
206
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800207 AidlMethod* AsMethod() override { return this; }
208
Casey Dahlinf4a93112015-10-05 16:58:09 -0700209 const std::string& GetComments() const { return comments_; }
210 const AidlType& GetType() const { return *type_; }
Casey Dahlina2f77c42015-12-01 18:26:02 -0800211 AidlType* GetMutableType() { return type_.get(); }
Casey Dahlinf4a93112015-10-05 16:58:09 -0700212 bool IsOneway() const { return oneway_; }
213 const std::string& GetName() const { return name_; }
214 unsigned GetLine() const { return line_; }
215 bool HasId() const { return has_id_; }
216 int GetId() { return id_; }
217 void SetId(unsigned id) { id_ = id; }
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700218
Casey Dahlinf4a93112015-10-05 16:58:09 -0700219 const std::vector<std::unique_ptr<AidlArgument>>& GetArguments() const {
Christopher Wileyad339272015-10-05 19:11:58 -0700220 return arguments_;
221 }
222 // An inout parameter will appear in both GetInArguments()
223 // and GetOutArguments(). AidlMethod retains ownership of the argument
224 // pointers returned in this way.
225 const std::vector<const AidlArgument*>& GetInArguments() const {
226 return in_arguments_;
227 }
228 const std::vector<const AidlArgument*>& GetOutArguments() const {
229 return out_arguments_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700230 }
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700231
232 private:
Casey Dahlinf4a93112015-10-05 16:58:09 -0700233 bool oneway_;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700234 std::string comments_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700235 std::unique_ptr<AidlType> type_;
236 std::string name_;
237 unsigned line_;
Christopher Wileyad339272015-10-05 19:11:58 -0700238 const std::vector<std::unique_ptr<AidlArgument>> arguments_;
239 std::vector<const AidlArgument*> in_arguments_;
240 std::vector<const AidlArgument*> out_arguments_;
Casey Dahlinf4a93112015-10-05 16:58:09 -0700241 bool has_id_;
242 int id_;
Casey Dahlinf2d23f72015-10-02 16:19:19 -0700243
Casey Dahlin5c69deb2015-10-01 14:44:12 -0700244 DISALLOW_COPY_AND_ASSIGN(AidlMethod);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700245};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800246
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800247class AidlParcelable;
248class AidlInterface;
249class AidlDocument : public AidlNode {
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700250 public:
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800251 AidlDocument() = default;
Chih-Hung Hsieh156a57f2016-06-02 16:17:28 -0700252 explicit AidlDocument(AidlInterface* interface);
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800253 virtual ~AidlDocument() = default;
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700254
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800255 const AidlInterface* GetInterface() const { return interface_.get(); }
256 AidlInterface* ReleaseInterface() { return interface_.release(); }
257
258 const std::vector<std::unique_ptr<AidlParcelable>>& GetParcelables() const {
259 return parcelables_;
260 }
261
262 void AddParcelable(AidlParcelable* parcelable) {
263 parcelables_.push_back(std::unique_ptr<AidlParcelable>(parcelable));
264 }
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700265
266 private:
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800267 std::vector<std::unique_ptr<AidlParcelable>> parcelables_;
268 std::unique_ptr<AidlInterface> interface_;
269
270 DISALLOW_COPY_AND_ASSIGN(AidlDocument);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700271};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800272
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700273class AidlQualifiedName : public AidlNode {
274 public:
275 AidlQualifiedName(std::string term, std::string comments);
276 virtual ~AidlQualifiedName() = default;
277
278 const std::vector<std::string>& GetTerms() const { return terms_; }
279 const std::string& GetComments() const { return comments_; }
280 std::string GetDotName() const { return android::base::Join(terms_, '.'); }
Ningyuan Wangd17c58b2016-09-29 14:33:14 -0700281 std::string GetColonName() const { return android::base::Join(terms_, "::"); }
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700282
Chih-Hung Hsiehf05cc262016-07-27 11:42:51 -0700283 void AddTerm(const std::string& term);
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700284
285 private:
286 std::vector<std::string> terms_;
287 std::string comments_;
288
289 DISALLOW_COPY_AND_ASSIGN(AidlQualifiedName);
290};
291
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800292class AidlParcelable : public AidlNode {
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700293 public:
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700294 AidlParcelable(AidlQualifiedName* name, unsigned line,
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800295 const std::vector<std::string>& package,
296 const std::string& cpp_header = "");
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700297 virtual ~AidlParcelable() = default;
Adam Lesinskiffa16862014-01-23 18:17:42 -0800298
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800299 std::string GetName() const { return name_->GetDotName(); }
Ningyuan Wangd17c58b2016-09-29 14:33:14 -0700300 // C++ uses "::" instead of "." to refer to a inner class.
301 std::string GetCppName() const { return name_->GetColonName(); }
Casey Dahlin59401da2015-10-09 18:16:45 -0700302 unsigned GetLine() const { return line_; }
Christopher Wileyd76067c2015-10-19 17:00:13 -0700303 std::string GetPackage() const;
304 const std::vector<std::string>& GetSplitPackage() const { return package_; }
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800305 std::string GetCppHeader() const { return cpp_header_; }
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800306 std::string GetCanonicalName() const;
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800307
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700308 private:
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800309 std::unique_ptr<AidlQualifiedName> name_;
Casey Dahlin59401da2015-10-09 18:16:45 -0700310 unsigned line_;
Christopher Wileyd76067c2015-10-19 17:00:13 -0700311 const std::vector<std::string> package_;
Christopher Wiley8aa4d9f2015-11-16 19:10:45 -0800312 std::string cpp_header_;
Casey Dahlin59401da2015-10-09 18:16:45 -0700313
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700314 DISALLOW_COPY_AND_ASSIGN(AidlParcelable);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700315};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800316
Casey Dahline7922932016-02-29 17:23:01 -0800317class AidlInterface : public AidlAnnotatable {
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700318 public:
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700319 AidlInterface(const std::string& name, unsigned line,
320 const std::string& comments, bool oneway_,
Casey Dahlind40e2fe2015-11-24 14:06:52 -0800321 std::vector<std::unique_ptr<AidlMember>>* members,
Christopher Wileyd76067c2015-10-19 17:00:13 -0700322 const std::vector<std::string>& package);
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700323 virtual ~AidlInterface() = default;
324
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700325 const std::string& GetName() const { return name_; }
326 unsigned GetLine() const { return line_; }
327 const std::string& GetComments() const { return comments_; }
328 bool IsOneway() const { return oneway_; }
329 const std::vector<std::unique_ptr<AidlMethod>>& GetMethods() const
330 { return methods_; }
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700331 const std::vector<std::unique_ptr<AidlIntConstant>>& GetIntConstants() const
332 { return int_constants_; }
333 const std::vector<std::unique_ptr<AidlStringConstant>>&
334 GetStringConstants() const { return string_constants_; }
Christopher Wileyd76067c2015-10-19 17:00:13 -0700335 std::string GetPackage() const;
336 std::string GetCanonicalName() const;
337 const std::vector<std::string>& GetSplitPackage() const { return package_; }
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700338
Casey Dahlina2f77c42015-12-01 18:26:02 -0800339 void SetLanguageType(const android::aidl::ValidatableType* language_type) {
340 language_type_ = language_type;
341 }
342
343 template<typename T>
Christopher Wileyec31a052016-01-25 07:28:51 -0800344 const T* GetLanguageType() const {
345 return reinterpret_cast<const T*>(language_type_);
346 }
Casey Dahlina2f77c42015-12-01 18:26:02 -0800347
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700348 private:
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700349 std::string name_;
350 std::string comments_;
351 unsigned line_;
352 bool oneway_;
353 std::vector<std::unique_ptr<AidlMethod>> methods_;
Christopher Wileyd6bdd8d2016-05-03 11:23:13 -0700354 std::vector<std::unique_ptr<AidlIntConstant>> int_constants_;
355 std::vector<std::unique_ptr<AidlStringConstant>> string_constants_;
Christopher Wileyd76067c2015-10-19 17:00:13 -0700356 std::vector<std::string> package_;
Casey Dahlinfb7da2e2015-10-08 17:26:09 -0700357
Casey Dahlina2f77c42015-12-01 18:26:02 -0800358 const android::aidl::ValidatableType* language_type_ = nullptr;
359
Casey Dahlin1ae2bc52015-10-07 18:49:10 -0700360 DISALLOW_COPY_AND_ASSIGN(AidlInterface);
Casey Dahlin0a2f8be2015-09-28 16:15:29 -0700361};
Adam Lesinskiffa16862014-01-23 18:17:42 -0800362
Casey Dahlin0edf3422015-10-07 12:34:59 -0700363class AidlImport : public AidlNode {
364 public:
365 AidlImport(const std::string& from, const std::string& needed_class,
366 unsigned line);
367 virtual ~AidlImport() = default;
368
369 const std::string& GetFileFrom() const { return from_; }
370 const std::string& GetFilename() const { return filename_; }
371 const std::string& GetNeededClass() const { return needed_class_; }
372 unsigned GetLine() const { return line_; }
Casey Dahlin0edf3422015-10-07 12:34:59 -0700373
374 void SetFilename(const std::string& filename) { filename_ = filename; }
375
376 private:
Casey Dahlin0edf3422015-10-07 12:34:59 -0700377 std::string from_;
378 std::string filename_;
379 std::string needed_class_;
380 unsigned line_;
381
382 DISALLOW_COPY_AND_ASSIGN(AidlImport);
Casey Dahline2507492015-09-14 17:11:20 -0700383};
384
385class Parser {
Casey Dahlindd691812015-09-09 17:59:06 -0700386 public:
Christopher Wiley4a2884b2015-10-07 11:27:45 -0700387 explicit Parser(const android::aidl::IoDelegate& io_delegate);
Casey Dahline2507492015-09-14 17:11:20 -0700388 ~Parser();
Casey Dahlindd691812015-09-09 17:59:06 -0700389
Christopher Wiley4a2884b2015-10-07 11:27:45 -0700390 // Parse contents of file |filename|.
391 bool ParseFile(const std::string& filename);
Casey Dahlin89d44842015-09-24 18:45:54 -0700392
Casey Dahlin98a544b2015-10-14 14:22:55 -0700393 void ReportError(const std::string& err, unsigned line);
Casey Dahlindd691812015-09-09 17:59:06 -0700394
Casey Dahlin3c6df362015-10-06 15:48:35 -0700395 bool FoundNoErrors() const { return error_ == 0; }
396 const std::string& FileName() const { return filename_; }
Casey Dahlin42727f82015-10-12 19:23:40 -0700397 void* Scanner() const { return scanner_; }
Casey Dahlindd691812015-09-09 17:59:06 -0700398
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800399 void SetDocument(AidlDocument* doc) { document_.reset(doc); };
Casey Dahline2507492015-09-14 17:11:20 -0700400
Casey Dahlin2b2879b2015-10-13 16:59:44 -0700401 void AddImport(AidlQualifiedName* name, unsigned line);
Christopher Wiley90be4e32015-10-20 14:55:25 -0700402
403 std::vector<std::string> Package() const;
Christopher Wileyd76067c2015-10-19 17:00:13 -0700404 void SetPackage(AidlQualifiedName* name) { package_.reset(name); }
Casey Dahlin3c6df362015-10-06 15:48:35 -0700405
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800406 AidlDocument* GetDocument() const { return document_.get(); }
407 AidlDocument* ReleaseDocument() { return document_.release(); }
Christopher Wileyd76067c2015-10-19 17:00:13 -0700408 const std::vector<std::unique_ptr<AidlImport>>& GetImports() {
409 return imports_;
410 }
Casey Dahlin0edf3422015-10-07 12:34:59 -0700411
412 void ReleaseImports(std::vector<std::unique_ptr<AidlImport>>* ret) {
413 *ret = std::move(imports_);
414 imports_.clear();
415 }
Casey Dahlindd691812015-09-09 17:59:06 -0700416
417 private:
Christopher Wiley4a2884b2015-10-07 11:27:45 -0700418 const android::aidl::IoDelegate& io_delegate_;
Casey Dahlindd691812015-09-09 17:59:06 -0700419 int error_ = 0;
420 std::string filename_;
Christopher Wileyd76067c2015-10-19 17:00:13 -0700421 std::unique_ptr<AidlQualifiedName> package_;
Casey Dahlin42727f82015-10-12 19:23:40 -0700422 void* scanner_ = nullptr;
Casey Dahlinc1f39b42015-11-24 10:34:34 -0800423 std::unique_ptr<AidlDocument> document_;
Casey Dahlin0edf3422015-10-07 12:34:59 -0700424 std::vector<std::unique_ptr<AidlImport>> imports_;
Christopher Wiley4a2884b2015-10-07 11:27:45 -0700425 std::unique_ptr<std::string> raw_buffer_;
Casey Dahlin89d44842015-09-24 18:45:54 -0700426 YY_BUFFER_STATE buffer_;
Casey Dahlindd691812015-09-09 17:59:06 -0700427
Casey Dahline2507492015-09-14 17:11:20 -0700428 DISALLOW_COPY_AND_ASSIGN(Parser);
Casey Dahlindd691812015-09-09 17:59:06 -0700429};
430
Christopher Wiley89e35862015-08-30 10:57:07 -0700431#endif // AIDL_AIDL_LANGUAGE_H_