Christopher Wiley | 89e3586 | 2015-08-30 10:57:07 -0700 | [diff] [blame] | 1 | #ifndef AIDL_AIDL_LANGUAGE_H_ |
Christopher Wiley | e9351cc | 2016-01-21 15:56:30 -0800 | [diff] [blame] | 2 | #define AIDL_AIDL_LANGUAGE_H_ |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 3 | |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 4 | #include <memory> |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 5 | #include <string> |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 6 | #include <vector> |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 7 | |
Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 8 | #include <android-base/macros.h> |
| 9 | #include <android-base/strings.h> |
Casey Dahlin | 73d46b0 | 2015-09-11 02:47:54 +0000 | [diff] [blame] | 10 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 11 | #include <io_delegate.h> |
| 12 | |
Casey Dahlin | 89d4484 | 2015-09-24 18:45:54 -0700 | [diff] [blame] | 13 | struct yy_buffer_state; |
| 14 | typedef yy_buffer_state* YY_BUFFER_STATE; |
| 15 | |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 16 | class AidlToken { |
| 17 | public: |
| 18 | AidlToken(const std::string& text, const std::string& comments); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 19 | |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 20 | const std::string& GetText() const { return text_; } |
| 21 | const std::string& GetComments() const { return comments_; } |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 22 | |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 23 | private: |
| 24 | std::string text_; |
| 25 | std::string comments_; |
Casey Dahlin | 082f1d1 | 2015-09-21 14:06:25 -0700 | [diff] [blame] | 26 | |
Casey Dahlin | cdbbc8c | 2015-10-14 15:31:04 -0700 | [diff] [blame] | 27 | DISALLOW_COPY_AND_ASSIGN(AidlToken); |
Casey Dahlin | 0a2f8be | 2015-09-28 16:15:29 -0700 | [diff] [blame] | 28 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 29 | |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 30 | class AidlNode { |
| 31 | public: |
| 32 | AidlNode() = default; |
| 33 | virtual ~AidlNode() = default; |
| 34 | |
| 35 | private: |
| 36 | DISALLOW_COPY_AND_ASSIGN(AidlNode); |
| 37 | }; |
| 38 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 39 | namespace android { |
| 40 | namespace aidl { |
| 41 | |
| 42 | class ValidatableType; |
| 43 | |
| 44 | } // namespace aidl |
| 45 | } // namespace android |
| 46 | |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 47 | class AidlAnnotatable : public AidlNode { |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 48 | public: |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 49 | enum Annotation : uint32_t { |
| 50 | AnnotationNone = 0, |
| 51 | AnnotationNullable = 1 << 0, |
| 52 | AnnotationUtf8 = 1 << 1, |
| 53 | AnnotationUtf8InCpp = 1 << 2, |
| 54 | }; |
| 55 | |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 56 | 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 | |
| 79 | class AidlType : public AidlAnnotatable { |
| 80 | public: |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 81 | AidlType(const std::string& name, unsigned line, |
Casey Dahlin | f7a421c | 2015-10-05 17:24:28 -0700 | [diff] [blame] | 82 | const std::string& comments, bool is_array); |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 83 | virtual ~AidlType() = default; |
| 84 | |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 85 | const std::string& GetName() const { return name_; } |
| 86 | unsigned GetLine() const { return line_; } |
Casey Dahlin | f7a421c | 2015-10-05 17:24:28 -0700 | [diff] [blame] | 87 | bool IsArray() const { return is_array_; } |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 88 | const std::string& GetComments() const { return comments_; } |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 89 | |
Casey Dahlin | 70078e6 | 2015-09-30 17:01:30 -0700 | [diff] [blame] | 90 | std::string ToString() const; |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 91 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 92 | 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 Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 101 | private: |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 102 | std::string name_; |
| 103 | unsigned line_; |
Casey Dahlin | f7a421c | 2015-10-05 17:24:28 -0700 | [diff] [blame] | 104 | bool is_array_; |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 105 | std::string comments_; |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 106 | const android::aidl::ValidatableType* language_type_ = nullptr; |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 107 | |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 108 | DISALLOW_COPY_AND_ASSIGN(AidlType); |
| 109 | }; |
| 110 | |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 111 | class AidlArgument : public AidlNode { |
| 112 | public: |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 113 | enum Direction { IN_DIR = 1, OUT_DIR = 2, INOUT_DIR = 3 }; |
| 114 | |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 115 | AidlArgument(AidlArgument::Direction direction, AidlType* type, |
Casey Dahlin | 308f9d4 | 2015-10-05 18:48:42 -0700 | [diff] [blame] | 116 | std::string name, unsigned line); |
Casey Dahlin | 42727f8 | 2015-10-12 19:23:40 -0700 | [diff] [blame] | 117 | AidlArgument(AidlType* type, std::string name, unsigned line); |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 118 | virtual ~AidlArgument() = default; |
| 119 | |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 120 | Direction GetDirection() const { return direction_; } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 121 | bool IsOut() const { return direction_ & OUT_DIR; } |
| 122 | bool IsIn() const { return direction_ & IN_DIR; } |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 123 | bool DirectionWasSpecified() const { return direction_specified_; } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 124 | |
Casey Dahlin | d127b50 | 2015-09-30 12:51:08 -0700 | [diff] [blame] | 125 | std::string GetName() const { return name_; } |
| 126 | int GetLine() const { return line_; } |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 127 | const AidlType& GetType() const { return *type_; } |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 128 | AidlType* GetMutableType() { return type_.get(); } |
Casey Dahlin | d127b50 | 2015-09-30 12:51:08 -0700 | [diff] [blame] | 129 | |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 130 | std::string ToString() const; |
| 131 | |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 132 | private: |
Casey Dahlin | 0ee3758 | 2015-09-30 16:31:55 -0700 | [diff] [blame] | 133 | std::unique_ptr<AidlType> type_; |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 134 | Direction direction_; |
| 135 | bool direction_specified_; |
Casey Dahlin | d127b50 | 2015-09-30 12:51:08 -0700 | [diff] [blame] | 136 | std::string name_; |
Casey Dahlin | 308f9d4 | 2015-10-05 18:48:42 -0700 | [diff] [blame] | 137 | unsigned line_; |
Casey Dahlin | c378c99 | 2015-09-29 16:50:40 -0700 | [diff] [blame] | 138 | |
Casey Dahlin | bc7a50a | 2015-09-28 19:20:50 -0700 | [diff] [blame] | 139 | DISALLOW_COPY_AND_ASSIGN(AidlArgument); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 140 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 141 | |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 142 | class AidlMethod; |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 143 | class AidlIntConstant; |
| 144 | class AidlStringConstant; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 145 | class AidlMember : public AidlNode { |
| 146 | public: |
| 147 | AidlMember() = default; |
| 148 | virtual ~AidlMember() = default; |
| 149 | |
| 150 | virtual AidlMethod* AsMethod() { return nullptr; } |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 151 | virtual AidlIntConstant* AsIntConstant() { return nullptr; } |
| 152 | virtual AidlStringConstant* AsStringConstant() { return nullptr; } |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 153 | |
| 154 | private: |
| 155 | DISALLOW_COPY_AND_ASSIGN(AidlMember); |
| 156 | }; |
| 157 | |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 158 | class AidlIntConstant : public AidlMember { |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 159 | public: |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 160 | AidlIntConstant(std::string name, int32_t value); |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 161 | AidlIntConstant(std::string name, std::string value, unsigned line_number); |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 162 | virtual ~AidlIntConstant() = default; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 163 | |
| 164 | const std::string& GetName() const { return name_; } |
| 165 | int GetValue() const { return value_; } |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 166 | bool IsValid() const { return is_valid_; } |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 167 | |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 168 | AidlIntConstant* AsIntConstant() override { return this; } |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 169 | |
| 170 | private: |
| 171 | std::string name_; |
| 172 | int32_t value_; |
Roshan Pius | 3b2203d | 2016-07-22 16:13:20 -0700 | [diff] [blame] | 173 | bool is_valid_; |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 174 | |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 175 | DISALLOW_COPY_AND_ASSIGN(AidlIntConstant); |
| 176 | }; |
| 177 | |
| 178 | class 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 Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | class AidlMethod : public AidlMember { |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 198 | public: |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 199 | AidlMethod(bool oneway, AidlType* type, std::string name, |
| 200 | std::vector<std::unique_ptr<AidlArgument>>* args, |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 201 | unsigned line, const std::string& comments); |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 202 | AidlMethod(bool oneway, AidlType* type, std::string name, |
| 203 | std::vector<std::unique_ptr<AidlArgument>>* args, |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 204 | unsigned line, const std::string& comments, int id); |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 205 | virtual ~AidlMethod() = default; |
| 206 | |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 207 | AidlMethod* AsMethod() override { return this; } |
| 208 | |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 209 | const std::string& GetComments() const { return comments_; } |
| 210 | const AidlType& GetType() const { return *type_; } |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 211 | AidlType* GetMutableType() { return type_.get(); } |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 212 | 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 Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 218 | |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 219 | const std::vector<std::unique_ptr<AidlArgument>>& GetArguments() const { |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 220 | 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 Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 230 | } |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 231 | |
| 232 | private: |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 233 | bool oneway_; |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 234 | std::string comments_; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 235 | std::unique_ptr<AidlType> type_; |
| 236 | std::string name_; |
| 237 | unsigned line_; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 238 | const std::vector<std::unique_ptr<AidlArgument>> arguments_; |
| 239 | std::vector<const AidlArgument*> in_arguments_; |
| 240 | std::vector<const AidlArgument*> out_arguments_; |
Casey Dahlin | f4a9311 | 2015-10-05 16:58:09 -0700 | [diff] [blame] | 241 | bool has_id_; |
| 242 | int id_; |
Casey Dahlin | f2d23f7 | 2015-10-02 16:19:19 -0700 | [diff] [blame] | 243 | |
Casey Dahlin | 5c69deb | 2015-10-01 14:44:12 -0700 | [diff] [blame] | 244 | DISALLOW_COPY_AND_ASSIGN(AidlMethod); |
Casey Dahlin | 0a2f8be | 2015-09-28 16:15:29 -0700 | [diff] [blame] | 245 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 246 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 247 | class AidlParcelable; |
| 248 | class AidlInterface; |
| 249 | class AidlDocument : public AidlNode { |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 250 | public: |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 251 | AidlDocument() = default; |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 252 | explicit AidlDocument(AidlInterface* interface); |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 253 | virtual ~AidlDocument() = default; |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 254 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 255 | 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 Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 265 | |
| 266 | private: |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 267 | std::vector<std::unique_ptr<AidlParcelable>> parcelables_; |
| 268 | std::unique_ptr<AidlInterface> interface_; |
| 269 | |
| 270 | DISALLOW_COPY_AND_ASSIGN(AidlDocument); |
Casey Dahlin | 0a2f8be | 2015-09-28 16:15:29 -0700 | [diff] [blame] | 271 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 272 | |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 273 | class 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 Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 281 | std::string GetColonName() const { return android::base::Join(terms_, "::"); } |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 282 | |
Chih-Hung Hsieh | f05cc26 | 2016-07-27 11:42:51 -0700 | [diff] [blame] | 283 | void AddTerm(const std::string& term); |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 284 | |
| 285 | private: |
| 286 | std::vector<std::string> terms_; |
| 287 | std::string comments_; |
| 288 | |
| 289 | DISALLOW_COPY_AND_ASSIGN(AidlQualifiedName); |
| 290 | }; |
| 291 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 292 | class AidlParcelable : public AidlNode { |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 293 | public: |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 294 | AidlParcelable(AidlQualifiedName* name, unsigned line, |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 295 | const std::vector<std::string>& package, |
| 296 | const std::string& cpp_header = ""); |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 297 | virtual ~AidlParcelable() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 298 | |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 299 | std::string GetName() const { return name_->GetDotName(); } |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 300 | // C++ uses "::" instead of "." to refer to a inner class. |
| 301 | std::string GetCppName() const { return name_->GetColonName(); } |
Casey Dahlin | 59401da | 2015-10-09 18:16:45 -0700 | [diff] [blame] | 302 | unsigned GetLine() const { return line_; } |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 303 | std::string GetPackage() const; |
| 304 | const std::vector<std::string>& GetSplitPackage() const { return package_; } |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 305 | std::string GetCppHeader() const { return cpp_header_; } |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 306 | std::string GetCanonicalName() const; |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 307 | |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 308 | private: |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 309 | std::unique_ptr<AidlQualifiedName> name_; |
Casey Dahlin | 59401da | 2015-10-09 18:16:45 -0700 | [diff] [blame] | 310 | unsigned line_; |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 311 | const std::vector<std::string> package_; |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 312 | std::string cpp_header_; |
Casey Dahlin | 59401da | 2015-10-09 18:16:45 -0700 | [diff] [blame] | 313 | |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 314 | DISALLOW_COPY_AND_ASSIGN(AidlParcelable); |
Casey Dahlin | 0a2f8be | 2015-09-28 16:15:29 -0700 | [diff] [blame] | 315 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 316 | |
Casey Dahlin | e792293 | 2016-02-29 17:23:01 -0800 | [diff] [blame] | 317 | class AidlInterface : public AidlAnnotatable { |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 318 | public: |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 319 | AidlInterface(const std::string& name, unsigned line, |
| 320 | const std::string& comments, bool oneway_, |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 321 | std::vector<std::unique_ptr<AidlMember>>* members, |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 322 | const std::vector<std::string>& package); |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 323 | virtual ~AidlInterface() = default; |
| 324 | |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 325 | 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 Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 331 | 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 Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 335 | std::string GetPackage() const; |
| 336 | std::string GetCanonicalName() const; |
| 337 | const std::vector<std::string>& GetSplitPackage() const { return package_; } |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 338 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 339 | void SetLanguageType(const android::aidl::ValidatableType* language_type) { |
| 340 | language_type_ = language_type; |
| 341 | } |
| 342 | |
| 343 | template<typename T> |
Christopher Wiley | ec31a05 | 2016-01-25 07:28:51 -0800 | [diff] [blame] | 344 | const T* GetLanguageType() const { |
| 345 | return reinterpret_cast<const T*>(language_type_); |
| 346 | } |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 347 | |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 348 | private: |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 349 | std::string name_; |
| 350 | std::string comments_; |
| 351 | unsigned line_; |
| 352 | bool oneway_; |
| 353 | std::vector<std::unique_ptr<AidlMethod>> methods_; |
Christopher Wiley | d6bdd8d | 2016-05-03 11:23:13 -0700 | [diff] [blame] | 354 | std::vector<std::unique_ptr<AidlIntConstant>> int_constants_; |
| 355 | std::vector<std::unique_ptr<AidlStringConstant>> string_constants_; |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 356 | std::vector<std::string> package_; |
Casey Dahlin | fb7da2e | 2015-10-08 17:26:09 -0700 | [diff] [blame] | 357 | |
Casey Dahlin | a2f77c4 | 2015-12-01 18:26:02 -0800 | [diff] [blame] | 358 | const android::aidl::ValidatableType* language_type_ = nullptr; |
| 359 | |
Casey Dahlin | 1ae2bc5 | 2015-10-07 18:49:10 -0700 | [diff] [blame] | 360 | DISALLOW_COPY_AND_ASSIGN(AidlInterface); |
Casey Dahlin | 0a2f8be | 2015-09-28 16:15:29 -0700 | [diff] [blame] | 361 | }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 362 | |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 363 | class 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 Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 373 | |
| 374 | void SetFilename(const std::string& filename) { filename_ = filename; } |
| 375 | |
| 376 | private: |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 377 | std::string from_; |
| 378 | std::string filename_; |
| 379 | std::string needed_class_; |
| 380 | unsigned line_; |
| 381 | |
| 382 | DISALLOW_COPY_AND_ASSIGN(AidlImport); |
Casey Dahlin | e250749 | 2015-09-14 17:11:20 -0700 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | class Parser { |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 386 | public: |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 387 | explicit Parser(const android::aidl::IoDelegate& io_delegate); |
Casey Dahlin | e250749 | 2015-09-14 17:11:20 -0700 | [diff] [blame] | 388 | ~Parser(); |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 389 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 390 | // Parse contents of file |filename|. |
| 391 | bool ParseFile(const std::string& filename); |
Casey Dahlin | 89d4484 | 2015-09-24 18:45:54 -0700 | [diff] [blame] | 392 | |
Casey Dahlin | 98a544b | 2015-10-14 14:22:55 -0700 | [diff] [blame] | 393 | void ReportError(const std::string& err, unsigned line); |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 394 | |
Casey Dahlin | 3c6df36 | 2015-10-06 15:48:35 -0700 | [diff] [blame] | 395 | bool FoundNoErrors() const { return error_ == 0; } |
| 396 | const std::string& FileName() const { return filename_; } |
Casey Dahlin | 42727f8 | 2015-10-12 19:23:40 -0700 | [diff] [blame] | 397 | void* Scanner() const { return scanner_; } |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 398 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 399 | void SetDocument(AidlDocument* doc) { document_.reset(doc); }; |
Casey Dahlin | e250749 | 2015-09-14 17:11:20 -0700 | [diff] [blame] | 400 | |
Casey Dahlin | 2b2879b | 2015-10-13 16:59:44 -0700 | [diff] [blame] | 401 | void AddImport(AidlQualifiedName* name, unsigned line); |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 402 | |
| 403 | std::vector<std::string> Package() const; |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 404 | void SetPackage(AidlQualifiedName* name) { package_.reset(name); } |
Casey Dahlin | 3c6df36 | 2015-10-06 15:48:35 -0700 | [diff] [blame] | 405 | |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 406 | AidlDocument* GetDocument() const { return document_.get(); } |
| 407 | AidlDocument* ReleaseDocument() { return document_.release(); } |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 408 | const std::vector<std::unique_ptr<AidlImport>>& GetImports() { |
| 409 | return imports_; |
| 410 | } |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 411 | |
| 412 | void ReleaseImports(std::vector<std::unique_ptr<AidlImport>>* ret) { |
| 413 | *ret = std::move(imports_); |
| 414 | imports_.clear(); |
| 415 | } |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 416 | |
| 417 | private: |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 418 | const android::aidl::IoDelegate& io_delegate_; |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 419 | int error_ = 0; |
| 420 | std::string filename_; |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 421 | std::unique_ptr<AidlQualifiedName> package_; |
Casey Dahlin | 42727f8 | 2015-10-12 19:23:40 -0700 | [diff] [blame] | 422 | void* scanner_ = nullptr; |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 423 | std::unique_ptr<AidlDocument> document_; |
Casey Dahlin | 0edf342 | 2015-10-07 12:34:59 -0700 | [diff] [blame] | 424 | std::vector<std::unique_ptr<AidlImport>> imports_; |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 425 | std::unique_ptr<std::string> raw_buffer_; |
Casey Dahlin | 89d4484 | 2015-09-24 18:45:54 -0700 | [diff] [blame] | 426 | YY_BUFFER_STATE buffer_; |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 427 | |
Casey Dahlin | e250749 | 2015-09-14 17:11:20 -0700 | [diff] [blame] | 428 | DISALLOW_COPY_AND_ASSIGN(Parser); |
Casey Dahlin | dd69181 | 2015-09-09 17:59:06 -0700 | [diff] [blame] | 429 | }; |
| 430 | |
Christopher Wiley | 89e3586 | 2015-08-30 10:57:07 -0700 | [diff] [blame] | 431 | #endif // AIDL_AIDL_LANGUAGE_H_ |