Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Steven Moreland | 9fccf58 | 2018-08-27 20:36:27 -0700 | [diff] [blame] | 17 | #pragma once |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 18 | |
Casey Dahlin | 60a4916 | 2015-09-17 14:23:10 -0700 | [diff] [blame] | 19 | #include <memory> |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 23 | #include <android-base/macros.h> |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace aidl { |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 27 | class CodeWriter; |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 28 | } // namespace aidl |
| 29 | } // namespace android |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 30 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 31 | namespace android { |
| 32 | namespace aidl { |
| 33 | namespace cpp { |
| 34 | |
| 35 | class AstNode { |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 36 | public: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 37 | AstNode() = default; |
| 38 | virtual ~AstNode() = default; |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 39 | virtual void Write(CodeWriter* to) const = 0; |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 40 | std::string ToString(); |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 41 | }; // class AstNode |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 42 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 43 | class Declaration : public AstNode { |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 44 | public: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 45 | Declaration() = default; |
| 46 | virtual ~Declaration() = default; |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 47 | |
| 48 | private: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 49 | DISALLOW_COPY_AND_ASSIGN(Declaration); |
| 50 | }; // class Declaration |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 51 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 52 | class LiteralDecl : public Declaration { |
| 53 | public: |
| 54 | explicit LiteralDecl(const std::string& expression); |
| 55 | ~LiteralDecl() = default; |
| 56 | void Write(CodeWriter* to) const override; |
| 57 | |
| 58 | private: |
| 59 | const std::string expression_; |
| 60 | |
| 61 | DISALLOW_COPY_AND_ASSIGN(LiteralDecl); |
| 62 | }; // class LiteralDecl |
| 63 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 64 | class ClassDecl : public Declaration { |
Casey Dahlin | 60a4916 | 2015-09-17 14:23:10 -0700 | [diff] [blame] | 65 | public: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 66 | ClassDecl(const std::string& name, |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 67 | const std::string& parent); |
| 68 | ClassDecl(const std::string& name, |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 69 | const std::string& parent, |
| 70 | std::vector<std::unique_ptr<Declaration>> public_members, |
| 71 | std::vector<std::unique_ptr<Declaration>> private_members); |
| 72 | virtual ~ClassDecl() = default; |
Casey Dahlin | 60a4916 | 2015-09-17 14:23:10 -0700 | [diff] [blame] | 73 | |
| 74 | void Write(CodeWriter* to) const override; |
| 75 | |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 76 | void AddPublic(std::unique_ptr<Declaration> member); |
| 77 | void AddPrivate(std::unique_ptr<Declaration> member); |
| 78 | |
Casey Dahlin | 60a4916 | 2015-09-17 14:23:10 -0700 | [diff] [blame] | 79 | private: |
| 80 | std::string name_; |
| 81 | std::string parent_; |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 82 | std::vector<std::unique_ptr<Declaration>> public_members_; |
| 83 | std::vector<std::unique_ptr<Declaration>> private_members_; |
Casey Dahlin | 60a4916 | 2015-09-17 14:23:10 -0700 | [diff] [blame] | 84 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(ClassDecl); |
| 86 | }; // class ClassDecl |
Casey Dahlin | 60a4916 | 2015-09-17 14:23:10 -0700 | [diff] [blame] | 87 | |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 88 | class Enum : public Declaration { |
| 89 | public: |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 90 | Enum(const std::string& name, const std::string& base_type, bool is_class); |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 91 | virtual ~Enum() = default; |
| 92 | |
Christopher Wiley | fd7dc03 | 2016-02-02 17:58:39 -0800 | [diff] [blame] | 93 | bool HasValues() const { return !fields_.empty(); } |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 94 | void Write(CodeWriter* to) const override; |
| 95 | |
| 96 | void AddValue(const std::string& key, const std::string& value); |
| 97 | |
| 98 | private: |
| 99 | struct EnumField { |
| 100 | EnumField(const std::string& k, const std::string& v); |
| 101 | const std::string key; |
| 102 | const std::string value; |
| 103 | }; |
| 104 | |
| 105 | std::string enum_name_; |
Christopher Wiley | fd7dc03 | 2016-02-02 17:58:39 -0800 | [diff] [blame] | 106 | std::string underlying_type_; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 107 | bool is_class_; |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 108 | std::vector<EnumField> fields_; |
| 109 | |
| 110 | DISALLOW_COPY_AND_ASSIGN(Enum); |
| 111 | }; // class Enum |
| 112 | |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 113 | class ArgList : public AstNode { |
| 114 | public: |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 115 | ArgList() = default; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 116 | explicit ArgList(const std::string& single_argument); |
| 117 | explicit ArgList(const std::vector<std::string>& arg_list); |
Christopher Wiley | f02facf | 2015-11-12 08:54:08 -0800 | [diff] [blame] | 118 | explicit ArgList(std::vector<std::unique_ptr<AstNode>> arg_list); |
Chih-Hung Hsieh | f5cbb68 | 2018-09-25 13:43:32 -0700 | [diff] [blame] | 119 | ArgList(ArgList&& arg_list) noexcept; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 120 | virtual ~ArgList() = default; |
| 121 | |
| 122 | void Write(CodeWriter* to) const override; |
| 123 | |
| 124 | private: |
Christopher Wiley | f02facf | 2015-11-12 08:54:08 -0800 | [diff] [blame] | 125 | std::vector<std::unique_ptr<AstNode>> arguments_; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 126 | |
| 127 | DISALLOW_COPY_AND_ASSIGN(ArgList); |
| 128 | }; // class ArgList |
| 129 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 130 | class ConstructorDecl : public Declaration { |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 131 | public: |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 132 | enum Modifiers { |
| 133 | IS_VIRTUAL = 1 << 0, |
| 134 | IS_DEFAULT = 1 << 1, |
| 135 | IS_EXPLICIT = 1 << 2, |
| 136 | }; |
| 137 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 138 | ConstructorDecl(const std::string& name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 139 | ArgList&& arg_list); |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 140 | ConstructorDecl(const std::string& name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 141 | ArgList&& arg_list, |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 142 | uint32_t modifiers); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 143 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 144 | virtual ~ConstructorDecl() = default; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 145 | |
| 146 | void Write(CodeWriter* to) const override; |
| 147 | |
| 148 | private: |
| 149 | const std::string name_; |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 150 | const ArgList arguments_; |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 151 | const uint32_t modifiers_; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 152 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 153 | DISALLOW_COPY_AND_ASSIGN(ConstructorDecl); |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 154 | }; // class ConstructorDecl |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 155 | |
Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame] | 156 | class MacroDecl : public Declaration { |
| 157 | public: |
| 158 | MacroDecl(const std::string& name, ArgList&& arg_list); |
| 159 | virtual ~MacroDecl() = default; |
| 160 | |
| 161 | void Write(CodeWriter* to) const override; |
| 162 | |
| 163 | private: |
| 164 | const std::string name_; |
| 165 | const ArgList arguments_; |
| 166 | |
| 167 | DISALLOW_COPY_AND_ASSIGN(MacroDecl); |
| 168 | }; // class MacroDecl |
| 169 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 170 | class MethodDecl : public Declaration { |
Casey Dahlin | 88924d6 | 2015-09-17 16:28:24 -0700 | [diff] [blame] | 171 | public: |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 172 | enum Modifiers { |
| 173 | IS_CONST = 1 << 0, |
| 174 | IS_VIRTUAL = 1 << 1, |
| 175 | IS_OVERRIDE = 1 << 2, |
| 176 | IS_PURE_VIRTUAL = 1 << 3, |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 177 | IS_STATIC = 1 << 4, |
Jeongik Cha | a2ada0c | 2018-11-17 15:11:45 +0900 | [diff] [blame] | 178 | IS_FINAL = 1 << 5, |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | MethodDecl(const std::string& return_type, |
| 182 | const std::string& name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 183 | ArgList&& arg_list); |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 184 | MethodDecl(const std::string& return_type, |
| 185 | const std::string& name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 186 | ArgList&& arg_list, |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 187 | uint32_t modifiers); |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 188 | virtual ~MethodDecl() = default; |
Casey Dahlin | 88924d6 | 2015-09-17 16:28:24 -0700 | [diff] [blame] | 189 | |
| 190 | void Write(CodeWriter* to) const override; |
| 191 | |
| 192 | private: |
| 193 | const std::string return_type_; |
| 194 | const std::string name_; |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 195 | const ArgList arguments_; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 196 | bool is_const_ = false; |
| 197 | bool is_virtual_ = false; |
| 198 | bool is_override_ = false; |
| 199 | bool is_pure_virtual_ = false; |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 200 | bool is_static_ = true; |
Jeongik Cha | a2ada0c | 2018-11-17 15:11:45 +0900 | [diff] [blame] | 201 | bool is_final_ = false; |
Casey Dahlin | 88924d6 | 2015-09-17 16:28:24 -0700 | [diff] [blame] | 202 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 203 | DISALLOW_COPY_AND_ASSIGN(MethodDecl); |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 204 | }; // class MethodDecl |
| 205 | |
| 206 | class StatementBlock : public Declaration { |
| 207 | public: |
| 208 | StatementBlock() = default; |
| 209 | virtual ~StatementBlock() = default; |
| 210 | |
| 211 | void AddStatement(std::unique_ptr<AstNode> statement); |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 212 | void AddStatement(AstNode* statement); // Takes ownership |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 213 | void AddLiteral(const std::string& expression, bool add_semicolon = true); |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 214 | bool Empty() const { return statements_.empty(); } |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 215 | |
| 216 | void Write(CodeWriter* to) const override; |
| 217 | |
| 218 | private: |
| 219 | std::vector<std::unique_ptr<AstNode>> statements_; |
| 220 | |
| 221 | DISALLOW_COPY_AND_ASSIGN(StatementBlock); |
| 222 | }; // class StatementBlock |
| 223 | |
Christopher Wiley | f9688b0 | 2015-10-08 17:17:50 -0700 | [diff] [blame] | 224 | class ConstructorImpl : public Declaration { |
| 225 | public: |
| 226 | ConstructorImpl(const std::string& class_name, |
| 227 | ArgList&& arg_list, |
| 228 | const std::vector<std::string>& initializer_list); |
| 229 | virtual ~ConstructorImpl() = default; |
| 230 | |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 231 | // ConstructorImpl retains ownership of the statement block. |
| 232 | StatementBlock* GetStatementBlock(); |
| 233 | |
Christopher Wiley | f9688b0 | 2015-10-08 17:17:50 -0700 | [diff] [blame] | 234 | void Write(CodeWriter* to) const override; |
| 235 | |
| 236 | private: |
| 237 | std::string class_name_; |
| 238 | ArgList arguments_; |
| 239 | std::vector<std::string> initializer_list_; |
| 240 | StatementBlock body_; |
| 241 | |
| 242 | DISALLOW_COPY_AND_ASSIGN(ConstructorImpl); |
| 243 | }; // class ConstructorImpl |
| 244 | |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 245 | class MethodImpl : public Declaration { |
| 246 | public: |
| 247 | // Passing an empty class name causes the method to be declared as a normal |
| 248 | // function (ie. no ClassName:: qualifier). |
| 249 | MethodImpl(const std::string& return_type, |
| 250 | const std::string& class_name, |
| 251 | const std::string& method_name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 252 | ArgList&& arg_list, |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 253 | bool is_const_method = false); |
| 254 | virtual ~MethodImpl() = default; |
| 255 | |
Christopher Wiley | f9688b0 | 2015-10-08 17:17:50 -0700 | [diff] [blame] | 256 | // MethodImpl retains ownership of the statement block. |
| 257 | StatementBlock* GetStatementBlock(); |
| 258 | |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 259 | void Write(CodeWriter* to) const override; |
| 260 | |
| 261 | private: |
| 262 | std::string return_type_; |
| 263 | std::string method_name_; |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 264 | const ArgList arguments_; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 265 | StatementBlock statements_; |
| 266 | bool is_const_method_ = false; |
| 267 | |
| 268 | DISALLOW_COPY_AND_ASSIGN(MethodImpl); |
| 269 | }; // class MethodImpl |
| 270 | |
| 271 | class SwitchStatement : public AstNode { |
| 272 | public: |
| 273 | explicit SwitchStatement(const std::string& expression); |
| 274 | virtual ~SwitchStatement() = default; |
| 275 | |
| 276 | // Add a case statement and return a pointer code block corresponding |
| 277 | // to the case. The switch statement will add a break statement |
| 278 | // after the code block by default to prevent accidental fall-through. |
| 279 | // Returns nullptr on duplicate value expressions (by strcmp, not value |
| 280 | // equivalence). |
| 281 | StatementBlock* AddCase(const std::string& value_expression); |
| 282 | void Write(CodeWriter* to) const override; |
| 283 | |
| 284 | private: |
| 285 | const std::string switch_expression_; |
| 286 | std::vector<std::string> case_values_; |
| 287 | std::vector<std::unique_ptr<StatementBlock>> case_logic_; |
| 288 | |
| 289 | DISALLOW_COPY_AND_ASSIGN(SwitchStatement); |
| 290 | }; // class SwitchStatement |
| 291 | |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 292 | class Assignment : public AstNode { |
| 293 | public: |
| 294 | Assignment(const std::string& left, const std::string& right); |
| 295 | Assignment(const std::string& left, AstNode* right); |
| 296 | ~Assignment() = default; |
| 297 | void Write(CodeWriter* to) const override; |
| 298 | |
| 299 | private: |
| 300 | const std::string lhs_; |
| 301 | std::unique_ptr<AstNode> rhs_; |
| 302 | |
| 303 | DISALLOW_COPY_AND_ASSIGN(Assignment); |
| 304 | }; // class Assignment |
| 305 | |
| 306 | class MethodCall : public AstNode { |
| 307 | public: |
| 308 | MethodCall(const std::string& method_name, |
| 309 | const std::string& single_argument); |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 310 | MethodCall(const std::string& method_name, ArgList&& arg_list); |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 311 | ~MethodCall() = default; |
| 312 | void Write(CodeWriter* to) const override; |
| 313 | |
| 314 | private: |
| 315 | const std::string method_name_; |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 316 | const ArgList arguments_; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 317 | |
| 318 | DISALLOW_COPY_AND_ASSIGN(MethodCall); |
| 319 | }; // class MethodCall |
| 320 | |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 321 | class IfStatement : public AstNode { |
| 322 | public: |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 323 | explicit IfStatement(AstNode* expression, |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 324 | bool invert_expression = false); |
| 325 | virtual ~IfStatement() = default; |
| 326 | StatementBlock* OnTrue() { return &on_true_; } |
| 327 | StatementBlock* OnFalse() { return &on_false_; } |
| 328 | void Write(CodeWriter* to) const override; |
| 329 | |
| 330 | private: |
| 331 | std::unique_ptr<AstNode> expression_; |
| 332 | bool invert_expression_ = false; |
| 333 | StatementBlock on_true_; |
| 334 | StatementBlock on_false_; |
| 335 | |
| 336 | DISALLOW_COPY_AND_ASSIGN(IfStatement); |
| 337 | }; // class IfStatement |
| 338 | |
Christopher Wiley | 3c5d28d | 2015-10-21 09:53:46 -0700 | [diff] [blame] | 339 | class Statement : public AstNode { |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 340 | public: |
Christopher Wiley | 3c5d28d | 2015-10-21 09:53:46 -0700 | [diff] [blame] | 341 | explicit Statement(std::unique_ptr<AstNode> expression); |
| 342 | explicit Statement(AstNode* expression); // Takes possession. |
| 343 | explicit Statement(const std::string& expression); |
| 344 | ~Statement() = default; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 345 | void Write(CodeWriter* to) const override; |
| 346 | |
| 347 | private: |
Christopher Wiley | 3c5d28d | 2015-10-21 09:53:46 -0700 | [diff] [blame] | 348 | std::unique_ptr<AstNode> expression_; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 349 | |
Christopher Wiley | 3c5d28d | 2015-10-21 09:53:46 -0700 | [diff] [blame] | 350 | DISALLOW_COPY_AND_ASSIGN(Statement); |
| 351 | }; // class Statement |
Casey Dahlin | 88924d6 | 2015-09-17 16:28:24 -0700 | [diff] [blame] | 352 | |
Christopher Wiley | d55db28 | 2015-10-20 18:16:47 -0700 | [diff] [blame] | 353 | class Comparison : public AstNode { |
| 354 | public: |
| 355 | Comparison(AstNode* lhs, const std::string& comparison, AstNode* rhs); |
| 356 | ~Comparison() = default; |
| 357 | void Write(CodeWriter* to) const override; |
| 358 | |
| 359 | private: |
| 360 | std::unique_ptr<AstNode> left_; |
| 361 | std::unique_ptr<AstNode> right_; |
| 362 | const std::string operator_; |
| 363 | |
| 364 | DISALLOW_COPY_AND_ASSIGN(Comparison); |
| 365 | }; // class Comparison |
| 366 | |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 367 | class LiteralExpression : public AstNode { |
| 368 | public: |
| 369 | explicit LiteralExpression(const std::string& expression); |
| 370 | ~LiteralExpression() = default; |
| 371 | void Write(CodeWriter* to) const override; |
| 372 | |
| 373 | private: |
| 374 | const std::string expression_; |
| 375 | |
| 376 | DISALLOW_COPY_AND_ASSIGN(LiteralExpression); |
| 377 | }; // class LiteralExpression |
| 378 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 379 | class CppNamespace : public Declaration { |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 380 | public: |
| 381 | CppNamespace(const std::string& name, |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 382 | std::vector<std::unique_ptr<Declaration>> declarations); |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 383 | CppNamespace(const std::string& name, |
| 384 | std::unique_ptr<Declaration> declaration); |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 385 | explicit CppNamespace(const std::string& name); |
Casey Dahlin | b7d0f7f | 2015-09-22 17:21:08 -0700 | [diff] [blame] | 386 | virtual ~CppNamespace() = default; |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 387 | |
| 388 | void Write(CodeWriter* to) const override; |
| 389 | |
| 390 | private: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 391 | std::vector<std::unique_ptr<Declaration>> declarations_; |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 392 | std::string name_; |
| 393 | |
| 394 | DISALLOW_COPY_AND_ASSIGN(CppNamespace); |
| 395 | }; // class CppNamespace |
| 396 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 397 | class Document : public AstNode { |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 398 | public: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 399 | Document(const std::vector<std::string>& include_list, |
Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 400 | std::vector<std::unique_ptr<Declaration>> declarations); |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 401 | |
| 402 | void Write(CodeWriter* to) const override; |
| 403 | |
| 404 | private: |
| 405 | std::vector<std::string> include_list_; |
Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 406 | std::vector<std::unique_ptr<Declaration>> declarations_; |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 407 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 408 | DISALLOW_COPY_AND_ASSIGN(Document); |
| 409 | }; // class Document |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 410 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 411 | class CppHeader final : public Document { |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 412 | public: |
Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 413 | CppHeader(const std::string& include_guard, const std::vector<std::string>& include_list, |
| 414 | std::vector<std::unique_ptr<Declaration>> declarations); |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 415 | void Write(CodeWriter* to) const override; |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 416 | |
| 417 | private: |
| 418 | const std::string include_guard_; |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 419 | |
| 420 | DISALLOW_COPY_AND_ASSIGN(CppHeader); |
| 421 | }; // class CppHeader |
| 422 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 423 | class CppSource final : public Document { |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 424 | public: |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 425 | CppSource(const std::vector<std::string>& include_list, |
Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 426 | std::vector<std::unique_ptr<Declaration>> declarations); |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 427 | |
| 428 | private: |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 429 | DISALLOW_COPY_AND_ASSIGN(CppSource); |
| 430 | }; // class CppSource |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 431 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 432 | } // namespace cpp |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 433 | } // namespace aidl |
| 434 | } // namespace android |