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 | |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 23 | namespace android { |
| 24 | namespace aidl { |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 25 | class CodeWriter; |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 26 | } // namespace aidl |
| 27 | } // namespace android |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 28 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 29 | namespace android { |
| 30 | namespace aidl { |
| 31 | namespace cpp { |
| 32 | |
| 33 | class AstNode { |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 34 | public: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 35 | AstNode() = default; |
| 36 | virtual ~AstNode() = default; |
Jiyong Park | d800fef | 2020-07-22 18:09:43 +0900 | [diff] [blame] | 37 | |
| 38 | // All ast nodes are non-copyable and non-movable |
| 39 | AstNode(const AstNode&) = delete; |
| 40 | AstNode(AstNode&&) = delete; |
| 41 | AstNode& operator=(const AstNode&) = delete; |
| 42 | AstNode& operator=(AstNode&&) = delete; |
| 43 | |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 44 | virtual void Write(CodeWriter* to) const = 0; |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 45 | std::string ToString(); |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 46 | }; // class AstNode |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 47 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 48 | class Declaration : public AstNode { |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 49 | public: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 50 | Declaration() = default; |
| 51 | virtual ~Declaration() = default; |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 52 | }; // class Declaration |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 53 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 54 | class LiteralDecl : public Declaration { |
| 55 | public: |
| 56 | explicit LiteralDecl(const std::string& expression); |
| 57 | ~LiteralDecl() = default; |
| 58 | void Write(CodeWriter* to) const override; |
| 59 | |
| 60 | private: |
| 61 | const std::string expression_; |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 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: |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 66 | ClassDecl(const std::string& name, const std::string& parent, |
| 67 | const std::vector<std::string>& template_params); |
| 68 | ClassDecl(const std::string& name, const std::string& parent, |
| 69 | const std::vector<std::string>& template_params, |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 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_; |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 82 | std::vector<std::string> template_params_; |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 83 | std::vector<std::unique_ptr<Declaration>> public_members_; |
| 84 | std::vector<std::unique_ptr<Declaration>> private_members_; |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 85 | }; // class ClassDecl |
Casey Dahlin | 60a4916 | 2015-09-17 14:23:10 -0700 | [diff] [blame] | 86 | |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 87 | class Enum : public Declaration { |
| 88 | public: |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 89 | 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] | 90 | virtual ~Enum() = default; |
| 91 | |
Christopher Wiley | fd7dc03 | 2016-02-02 17:58:39 -0800 | [diff] [blame] | 92 | bool HasValues() const { return !fields_.empty(); } |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 93 | void Write(CodeWriter* to) const override; |
| 94 | |
| 95 | void AddValue(const std::string& key, const std::string& value); |
| 96 | |
| 97 | private: |
| 98 | struct EnumField { |
| 99 | EnumField(const std::string& k, const std::string& v); |
| 100 | const std::string key; |
| 101 | const std::string value; |
| 102 | }; |
| 103 | |
| 104 | std::string enum_name_; |
Christopher Wiley | fd7dc03 | 2016-02-02 17:58:39 -0800 | [diff] [blame] | 105 | std::string underlying_type_; |
Daniel Norman | 85aed54 | 2019-08-21 12:01:14 -0700 | [diff] [blame] | 106 | bool is_class_; |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 107 | std::vector<EnumField> fields_; |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 108 | }; // class Enum |
| 109 | |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 110 | class ArgList : public AstNode { |
| 111 | public: |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 112 | ArgList() = default; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 113 | explicit ArgList(const std::string& single_argument); |
| 114 | explicit ArgList(const std::vector<std::string>& arg_list); |
Christopher Wiley | f02facf | 2015-11-12 08:54:08 -0800 | [diff] [blame] | 115 | explicit ArgList(std::vector<std::unique_ptr<AstNode>> arg_list); |
Chih-Hung Hsieh | f5cbb68 | 2018-09-25 13:43:32 -0700 | [diff] [blame] | 116 | ArgList(ArgList&& arg_list) noexcept; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 117 | virtual ~ArgList() = default; |
| 118 | |
| 119 | void Write(CodeWriter* to) const override; |
| 120 | |
| 121 | private: |
Christopher Wiley | f02facf | 2015-11-12 08:54:08 -0800 | [diff] [blame] | 122 | std::vector<std::unique_ptr<AstNode>> arguments_; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 123 | }; // class ArgList |
| 124 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 125 | class ConstructorDecl : public Declaration { |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 126 | public: |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 127 | enum Modifiers { |
| 128 | IS_VIRTUAL = 1 << 0, |
| 129 | IS_DEFAULT = 1 << 1, |
| 130 | IS_EXPLICIT = 1 << 2, |
| 131 | }; |
| 132 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 133 | ConstructorDecl(const std::string& name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 134 | ArgList&& arg_list); |
Christopher Wiley | a7a5c10 | 2015-09-29 16:26:52 -0700 | [diff] [blame] | 135 | ConstructorDecl(const std::string& name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 136 | ArgList&& arg_list, |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 137 | uint32_t modifiers); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 138 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 139 | virtual ~ConstructorDecl() = default; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 140 | |
| 141 | void Write(CodeWriter* to) const override; |
| 142 | |
| 143 | private: |
| 144 | const std::string name_; |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 145 | const ArgList arguments_; |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 146 | const uint32_t modifiers_; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 147 | }; // class ConstructorDecl |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 148 | |
Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame] | 149 | class MacroDecl : public Declaration { |
| 150 | public: |
| 151 | MacroDecl(const std::string& name, ArgList&& arg_list); |
| 152 | virtual ~MacroDecl() = default; |
| 153 | |
| 154 | void Write(CodeWriter* to) const override; |
| 155 | |
| 156 | private: |
| 157 | const std::string name_; |
| 158 | const ArgList arguments_; |
Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame] | 159 | }; // class MacroDecl |
| 160 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 161 | class MethodDecl : public Declaration { |
Casey Dahlin | 88924d6 | 2015-09-17 16:28:24 -0700 | [diff] [blame] | 162 | public: |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 163 | enum Modifiers { |
| 164 | IS_CONST = 1 << 0, |
| 165 | IS_VIRTUAL = 1 << 1, |
| 166 | IS_OVERRIDE = 1 << 2, |
| 167 | IS_PURE_VIRTUAL = 1 << 3, |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 168 | IS_STATIC = 1 << 4, |
Jeongik Cha | a2ada0c | 2018-11-17 15:11:45 +0900 | [diff] [blame] | 169 | IS_FINAL = 1 << 5, |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | MethodDecl(const std::string& return_type, |
| 173 | const std::string& name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 174 | ArgList&& arg_list); |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 175 | MethodDecl(const std::string& return_type, |
| 176 | const std::string& name, |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 177 | ArgList&& arg_list, |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 178 | uint32_t modifiers); |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 179 | virtual ~MethodDecl() = default; |
Casey Dahlin | 88924d6 | 2015-09-17 16:28:24 -0700 | [diff] [blame] | 180 | |
| 181 | void Write(CodeWriter* to) const override; |
| 182 | |
| 183 | private: |
| 184 | const std::string return_type_; |
| 185 | const std::string name_; |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 186 | const ArgList arguments_; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 187 | bool is_const_ = false; |
| 188 | bool is_virtual_ = false; |
| 189 | bool is_override_ = false; |
| 190 | bool is_pure_virtual_ = false; |
Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 191 | bool is_static_ = true; |
Jeongik Cha | a2ada0c | 2018-11-17 15:11:45 +0900 | [diff] [blame] | 192 | bool is_final_ = false; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 193 | }; // class MethodDecl |
| 194 | |
| 195 | class StatementBlock : public Declaration { |
| 196 | public: |
| 197 | StatementBlock() = default; |
| 198 | virtual ~StatementBlock() = default; |
| 199 | |
| 200 | void AddStatement(std::unique_ptr<AstNode> statement); |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 201 | void AddStatement(AstNode* statement); // Takes ownership |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 202 | void AddLiteral(const std::string& expression, bool add_semicolon = true); |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 203 | bool Empty() const { return statements_.empty(); } |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 204 | |
| 205 | void Write(CodeWriter* to) const override; |
| 206 | |
| 207 | private: |
| 208 | std::vector<std::unique_ptr<AstNode>> statements_; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 209 | }; // class StatementBlock |
| 210 | |
Christopher Wiley | f9688b0 | 2015-10-08 17:17:50 -0700 | [diff] [blame] | 211 | class ConstructorImpl : public Declaration { |
| 212 | public: |
| 213 | ConstructorImpl(const std::string& class_name, |
| 214 | ArgList&& arg_list, |
| 215 | const std::vector<std::string>& initializer_list); |
| 216 | virtual ~ConstructorImpl() = default; |
| 217 | |
Steven Moreland | a57d0a6 | 2019-07-30 09:41:14 -0700 | [diff] [blame] | 218 | // ConstructorImpl retains ownership of the statement block. |
| 219 | StatementBlock* GetStatementBlock(); |
| 220 | |
Christopher Wiley | f9688b0 | 2015-10-08 17:17:50 -0700 | [diff] [blame] | 221 | void Write(CodeWriter* to) const override; |
| 222 | |
| 223 | private: |
| 224 | std::string class_name_; |
| 225 | ArgList arguments_; |
| 226 | std::vector<std::string> initializer_list_; |
| 227 | StatementBlock body_; |
Christopher Wiley | f9688b0 | 2015-10-08 17:17:50 -0700 | [diff] [blame] | 228 | }; // class ConstructorImpl |
| 229 | |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 230 | class MethodImpl : public Declaration { |
| 231 | public: |
| 232 | // Passing an empty class name causes the method to be declared as a normal |
| 233 | // function (ie. no ClassName:: qualifier). |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 234 | MethodImpl(const std::string& return_type, const std::string& class_name, |
| 235 | const std::string& method_name, const std::vector<std::string>& template_params, |
| 236 | ArgList&& arg_list, bool is_const_method = false); |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 237 | virtual ~MethodImpl() = default; |
| 238 | |
Christopher Wiley | f9688b0 | 2015-10-08 17:17:50 -0700 | [diff] [blame] | 239 | // MethodImpl retains ownership of the statement block. |
| 240 | StatementBlock* GetStatementBlock(); |
| 241 | |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 242 | void Write(CodeWriter* to) const override; |
| 243 | |
| 244 | private: |
| 245 | std::string return_type_; |
| 246 | std::string method_name_; |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 247 | const ArgList arguments_; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 248 | StatementBlock statements_; |
| 249 | bool is_const_method_ = false; |
Devin Moore | 53fc99c | 2020-08-12 08:07:52 -0700 | [diff] [blame] | 250 | std::vector<std::string> template_params_; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 251 | }; // class MethodImpl |
| 252 | |
| 253 | class SwitchStatement : public AstNode { |
| 254 | public: |
| 255 | explicit SwitchStatement(const std::string& expression); |
| 256 | virtual ~SwitchStatement() = default; |
| 257 | |
| 258 | // Add a case statement and return a pointer code block corresponding |
| 259 | // to the case. The switch statement will add a break statement |
| 260 | // after the code block by default to prevent accidental fall-through. |
| 261 | // Returns nullptr on duplicate value expressions (by strcmp, not value |
| 262 | // equivalence). |
| 263 | StatementBlock* AddCase(const std::string& value_expression); |
| 264 | void Write(CodeWriter* to) const override; |
| 265 | |
| 266 | private: |
| 267 | const std::string switch_expression_; |
| 268 | std::vector<std::string> case_values_; |
| 269 | std::vector<std::unique_ptr<StatementBlock>> case_logic_; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 270 | }; // class SwitchStatement |
| 271 | |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 272 | class Assignment : public AstNode { |
| 273 | public: |
| 274 | Assignment(const std::string& left, const std::string& right); |
| 275 | Assignment(const std::string& left, AstNode* right); |
| 276 | ~Assignment() = default; |
| 277 | void Write(CodeWriter* to) const override; |
| 278 | |
| 279 | private: |
| 280 | const std::string lhs_; |
| 281 | std::unique_ptr<AstNode> rhs_; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 282 | }; // class Assignment |
| 283 | |
| 284 | class MethodCall : public AstNode { |
| 285 | public: |
| 286 | MethodCall(const std::string& method_name, |
| 287 | const std::string& single_argument); |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 288 | MethodCall(const std::string& method_name, ArgList&& arg_list); |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 289 | ~MethodCall() = default; |
| 290 | void Write(CodeWriter* to) const override; |
| 291 | |
| 292 | private: |
| 293 | const std::string method_name_; |
Christopher Wiley | ade4b45 | 2015-10-10 11:06:03 -0700 | [diff] [blame] | 294 | const ArgList arguments_; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 295 | }; // class MethodCall |
| 296 | |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 297 | class IfStatement : public AstNode { |
| 298 | public: |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 299 | explicit IfStatement(AstNode* expression, |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 300 | bool invert_expression = false); |
| 301 | virtual ~IfStatement() = default; |
| 302 | StatementBlock* OnTrue() { return &on_true_; } |
| 303 | StatementBlock* OnFalse() { return &on_false_; } |
| 304 | void Write(CodeWriter* to) const override; |
| 305 | |
| 306 | private: |
| 307 | std::unique_ptr<AstNode> expression_; |
| 308 | bool invert_expression_ = false; |
| 309 | StatementBlock on_true_; |
| 310 | StatementBlock on_false_; |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 311 | }; // class IfStatement |
| 312 | |
Christopher Wiley | 3c5d28d | 2015-10-21 09:53:46 -0700 | [diff] [blame] | 313 | class Statement : public AstNode { |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 314 | public: |
Christopher Wiley | 3c5d28d | 2015-10-21 09:53:46 -0700 | [diff] [blame] | 315 | explicit Statement(std::unique_ptr<AstNode> expression); |
| 316 | explicit Statement(AstNode* expression); // Takes possession. |
| 317 | explicit Statement(const std::string& expression); |
| 318 | ~Statement() = default; |
Christopher Wiley | da69599 | 2015-10-05 11:31:41 -0700 | [diff] [blame] | 319 | void Write(CodeWriter* to) const override; |
| 320 | |
| 321 | private: |
Christopher Wiley | 3c5d28d | 2015-10-21 09:53:46 -0700 | [diff] [blame] | 322 | std::unique_ptr<AstNode> expression_; |
Christopher Wiley | 3c5d28d | 2015-10-21 09:53:46 -0700 | [diff] [blame] | 323 | }; // class Statement |
Casey Dahlin | 88924d6 | 2015-09-17 16:28:24 -0700 | [diff] [blame] | 324 | |
Christopher Wiley | d55db28 | 2015-10-20 18:16:47 -0700 | [diff] [blame] | 325 | class Comparison : public AstNode { |
| 326 | public: |
| 327 | Comparison(AstNode* lhs, const std::string& comparison, AstNode* rhs); |
| 328 | ~Comparison() = default; |
| 329 | void Write(CodeWriter* to) const override; |
| 330 | |
| 331 | private: |
| 332 | std::unique_ptr<AstNode> left_; |
| 333 | std::unique_ptr<AstNode> right_; |
| 334 | const std::string operator_; |
Christopher Wiley | d55db28 | 2015-10-20 18:16:47 -0700 | [diff] [blame] | 335 | }; // class Comparison |
| 336 | |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 337 | class LiteralExpression : public AstNode { |
| 338 | public: |
| 339 | explicit LiteralExpression(const std::string& expression); |
| 340 | ~LiteralExpression() = default; |
| 341 | void Write(CodeWriter* to) const override; |
| 342 | |
| 343 | private: |
| 344 | const std::string expression_; |
Christopher Wiley | 2328526 | 2015-10-09 15:06:14 -0700 | [diff] [blame] | 345 | }; // class LiteralExpression |
| 346 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 347 | class CppNamespace : public Declaration { |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 348 | public: |
| 349 | CppNamespace(const std::string& name, |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 350 | std::vector<std::unique_ptr<Declaration>> declarations); |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 351 | CppNamespace(const std::string& name, |
| 352 | std::unique_ptr<Declaration> declaration); |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 353 | explicit CppNamespace(const std::string& name); |
Casey Dahlin | b7d0f7f | 2015-09-22 17:21:08 -0700 | [diff] [blame] | 354 | virtual ~CppNamespace() = default; |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 355 | |
| 356 | void Write(CodeWriter* to) const override; |
| 357 | |
| 358 | private: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 359 | std::vector<std::unique_ptr<Declaration>> declarations_; |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 360 | std::string name_; |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 361 | }; // class CppNamespace |
| 362 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 363 | class Document : public AstNode { |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 364 | public: |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 365 | Document(const std::vector<std::string>& include_list, |
Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 366 | std::vector<std::unique_ptr<Declaration>> declarations); |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 367 | |
| 368 | void Write(CodeWriter* to) const override; |
| 369 | |
| 370 | private: |
| 371 | std::vector<std::string> include_list_; |
Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 372 | std::vector<std::unique_ptr<Declaration>> declarations_; |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 373 | }; // class Document |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 374 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 375 | class CppHeader final : public Document { |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 376 | public: |
Devin Moore | 7aaa9cb | 2020-08-13 14:53:01 -0700 | [diff] [blame] | 377 | CppHeader(const std::vector<std::string>& include_list, |
Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 378 | std::vector<std::unique_ptr<Declaration>> declarations); |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 379 | void Write(CodeWriter* to) const override; |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 380 | }; // class CppHeader |
| 381 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 382 | class CppSource final : public Document { |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 383 | public: |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 384 | CppSource(const std::vector<std::string>& include_list, |
Steven Moreland | f3da089 | 2018-10-05 14:52:01 -0700 | [diff] [blame] | 385 | std::vector<std::unique_ptr<Declaration>> declarations); |
Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame] | 386 | }; // class CppSource |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 387 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 388 | } // namespace cpp |
Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 389 | } // namespace aidl |
| 390 | } // namespace android |