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