| Christopher Wiley | 038485e | 2015-09-12 11:14:14 -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 |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 18 | |
| Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 19 | #include <memory> |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 20 | #include <stdarg.h> |
| 21 | #include <stdio.h> |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <vector> |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 24 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 25 | enum { |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 26 | PACKAGE_PRIVATE = 0x00000000, |
| 27 | PUBLIC = 0x00000001, |
| 28 | PRIVATE = 0x00000002, |
| 29 | PROTECTED = 0x00000003, |
| 30 | SCOPE_MASK = 0x00000003, |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 31 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 32 | STATIC = 0x00000010, |
| 33 | FINAL = 0x00000020, |
| 34 | ABSTRACT = 0x00000040, |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 35 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 36 | OVERRIDE = 0x00000100, |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 37 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 38 | ALL_MODIFIERS = 0xffffffff |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 39 | }; |
| 40 | |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 41 | namespace android { |
| 42 | namespace aidl { |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 43 | class CodeWriter; |
| Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 44 | } // namespace aidl |
| 45 | } // namespace android |
| 46 | |
| 47 | namespace android { |
| 48 | namespace aidl { |
| 49 | namespace java { |
| 50 | |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 51 | class Type; |
| 52 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 53 | // Write the modifiers that are set in both mod and mask |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 54 | void WriteModifiers(CodeWriter* to, int mod, int mask); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 55 | |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 56 | struct AstNode { |
| 57 | AstNode() = default; |
| 58 | virtual ~AstNode() = default; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 59 | virtual void Write(CodeWriter* to) const = 0; |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 60 | std::string ToString(); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 63 | struct ClassElement : public AstNode { |
| 64 | ClassElement() = default; |
| 65 | virtual ~ClassElement() = default; |
| 66 | }; |
| 67 | |
| 68 | struct Expression : public AstNode { |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 69 | virtual ~Expression() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 72 | struct LiteralExpression : public Expression { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 73 | std::string value; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 74 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 75 | explicit LiteralExpression(const std::string& value); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 76 | virtual ~LiteralExpression() = default; |
| 77 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | // TODO: also escape the contents. not needed for now |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 81 | struct StringLiteralExpression : public Expression { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 82 | std::string value; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 83 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 84 | explicit StringLiteralExpression(const std::string& value); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 85 | virtual ~StringLiteralExpression() = default; |
| 86 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 89 | struct Variable : public Expression { |
| 90 | const Type* type = nullptr; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 91 | std::string name; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 92 | int dimension = 0; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 93 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 94 | Variable() = default; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 95 | Variable(const Type* type, const std::string& name); |
| 96 | Variable(const Type* type, const std::string& name, int dimension); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 97 | virtual ~Variable() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 98 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 99 | void WriteDeclaration(CodeWriter* to) const; |
| 100 | void Write(CodeWriter* to) const; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 103 | struct FieldVariable : public Expression { |
| 104 | Expression* object; |
| 105 | const Type* clazz; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 106 | std::string name; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 107 | |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 108 | FieldVariable(Expression* object, const std::string& name); |
| 109 | FieldVariable(const Type* clazz, const std::string& name); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 110 | virtual ~FieldVariable() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 111 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 112 | void Write(CodeWriter* to) const; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 115 | struct Field : public ClassElement { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 116 | std::string comment; |
| Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 117 | std::vector<std::string> annotations; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 118 | int modifiers = 0; |
| 119 | Variable* variable = nullptr; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 120 | std::string value; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 121 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 122 | Field() = default; |
| 123 | Field(int modifiers, Variable* variable); |
| 124 | virtual ~Field() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 125 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 126 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 127 | }; |
| 128 | |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 129 | struct Statement : public AstNode { |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 130 | virtual ~Statement() = default; |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | struct LiteralStatement : public Statement { |
| 134 | public: |
| 135 | LiteralStatement(const std::string& value); |
| 136 | virtual ~LiteralStatement() = default; |
| 137 | void Write(CodeWriter* to) const override; |
| 138 | |
| 139 | private: |
| 140 | const std::string value_; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 141 | }; |
| 142 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 143 | struct StatementBlock : public Statement { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 144 | std::vector<Statement*> statements; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 145 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 146 | StatementBlock() = default; |
| 147 | virtual ~StatementBlock() = default; |
| 148 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 149 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 150 | void Add(Statement* statement); |
| 151 | void Add(Expression* expression); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 152 | }; |
| 153 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 154 | struct ExpressionStatement : public Statement { |
| 155 | Expression* expression; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 156 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 157 | explicit ExpressionStatement(Expression* expression); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 158 | virtual ~ExpressionStatement() = default; |
| 159 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 162 | struct Assignment : public Expression { |
| 163 | Variable* lvalue; |
| 164 | Expression* rvalue; |
| 165 | const Type* cast; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 166 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 167 | Assignment(Variable* lvalue, Expression* rvalue); |
| 168 | Assignment(Variable* lvalue, Expression* rvalue, const Type* cast); |
| 169 | virtual ~Assignment() = default; |
| 170 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 171 | }; |
| 172 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 173 | struct MethodCall : public Expression { |
| 174 | Expression* obj = nullptr; |
| 175 | const Type* clazz = nullptr; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 176 | std::string name; |
| 177 | std::vector<Expression*> arguments; |
| 178 | std::vector<std::string> exceptions; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 179 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 180 | explicit MethodCall(const std::string& name); |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 181 | MethodCall(const std::string& name, int argc, ...); |
| 182 | MethodCall(Expression* obj, const std::string& name); |
| 183 | MethodCall(const Type* clazz, const std::string& name); |
| 184 | MethodCall(Expression* obj, const std::string& name, int argc, ...); |
| 185 | MethodCall(const Type* clazz, const std::string& name, int argc, ...); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 186 | virtual ~MethodCall() = default; |
| 187 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 188 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 189 | private: |
| 190 | void init(int n, va_list args); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 191 | }; |
| 192 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 193 | struct Comparison : public Expression { |
| 194 | Expression* lvalue; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 195 | std::string op; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 196 | Expression* rvalue; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 197 | |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 198 | Comparison(Expression* lvalue, const std::string& op, Expression* rvalue); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 199 | virtual ~Comparison() = default; |
| 200 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 201 | }; |
| 202 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 203 | struct NewExpression : public Expression { |
| 204 | const Type* type; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 205 | std::vector<Expression*> arguments; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 206 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 207 | explicit NewExpression(const Type* type); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 208 | NewExpression(const Type* type, int argc, ...); |
| 209 | virtual ~NewExpression() = default; |
| 210 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 211 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 212 | private: |
| 213 | void init(int n, va_list args); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 214 | }; |
| 215 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 216 | struct NewArrayExpression : public Expression { |
| 217 | const Type* type; |
| 218 | Expression* size; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 219 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 220 | NewArrayExpression(const Type* type, Expression* size); |
| 221 | virtual ~NewArrayExpression() = default; |
| 222 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 223 | }; |
| 224 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 225 | struct Ternary : public Expression { |
| 226 | Expression* condition = nullptr; |
| 227 | Expression* ifpart = nullptr; |
| 228 | Expression* elsepart = nullptr; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 229 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 230 | Ternary() = default; |
| 231 | Ternary(Expression* condition, Expression* ifpart, Expression* elsepart); |
| 232 | virtual ~Ternary() = default; |
| 233 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 234 | }; |
| 235 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 236 | struct Cast : public Expression { |
| 237 | const Type* type = nullptr; |
| 238 | Expression* expression = nullptr; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 239 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 240 | Cast() = default; |
| 241 | Cast(const Type* type, Expression* expression); |
| 242 | virtual ~Cast() = default; |
| 243 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 244 | }; |
| 245 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 246 | struct VariableDeclaration : public Statement { |
| 247 | Variable* lvalue = nullptr; |
| 248 | const Type* cast = nullptr; |
| 249 | Expression* rvalue = nullptr; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 250 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 251 | explicit VariableDeclaration(Variable* lvalue); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 252 | VariableDeclaration(Variable* lvalue, Expression* rvalue, |
| Yi Kong | 894d6ba | 2018-07-24 11:27:38 -0700 | [diff] [blame] | 253 | const Type* cast = nullptr); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 254 | virtual ~VariableDeclaration() = default; |
| 255 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 256 | }; |
| 257 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 258 | struct IfStatement : public Statement { |
| 259 | Expression* expression = nullptr; |
| 260 | StatementBlock* statements = new StatementBlock; |
| 261 | IfStatement* elseif = nullptr; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 262 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 263 | IfStatement() = default; |
| 264 | virtual ~IfStatement() = default; |
| 265 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 266 | }; |
| 267 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 268 | struct ReturnStatement : public Statement { |
| 269 | Expression* expression; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 270 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 271 | explicit ReturnStatement(Expression* expression); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 272 | virtual ~ReturnStatement() = default; |
| 273 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 274 | }; |
| 275 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 276 | struct TryStatement : public Statement { |
| 277 | StatementBlock* statements = new StatementBlock; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 278 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 279 | TryStatement() = default; |
| 280 | virtual ~TryStatement() = default; |
| 281 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 282 | }; |
| 283 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 284 | struct CatchStatement : public Statement { |
| 285 | StatementBlock* statements; |
| 286 | Variable* exception; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 287 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 288 | explicit CatchStatement(Variable* exception); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 289 | virtual ~CatchStatement() = default; |
| 290 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 291 | }; |
| 292 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 293 | struct FinallyStatement : public Statement { |
| 294 | StatementBlock* statements = new StatementBlock; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 295 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 296 | FinallyStatement() = default; |
| 297 | virtual ~FinallyStatement() = default; |
| 298 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 299 | }; |
| 300 | |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 301 | struct Case : public AstNode { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 302 | std::vector<std::string> cases; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 303 | StatementBlock* statements = new StatementBlock; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 304 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 305 | Case() = default; |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 306 | explicit Case(const std::string& c); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 307 | virtual ~Case() = default; |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 308 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 309 | }; |
| 310 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 311 | struct SwitchStatement : public Statement { |
| 312 | Expression* expression; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 313 | std::vector<Case*> cases; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 314 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 315 | explicit SwitchStatement(Expression* expression); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 316 | virtual ~SwitchStatement() = default; |
| 317 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 318 | }; |
| 319 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 320 | struct Break : public Statement { |
| 321 | Break() = default; |
| 322 | virtual ~Break() = default; |
| 323 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 324 | }; |
| 325 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 326 | struct Method : public ClassElement { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 327 | std::string comment; |
| Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 328 | std::vector<std::string> annotations; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 329 | int modifiers = 0; |
| 330 | const Type* returnType = nullptr; // nullptr means constructor |
| 331 | size_t returnTypeDimension = 0; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 332 | std::string name; |
| 333 | std::vector<Variable*> parameters; |
| 334 | std::vector<const Type*> exceptions; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 335 | StatementBlock* statements = nullptr; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 336 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 337 | Method() = default; |
| 338 | virtual ~Method() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 339 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 340 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 341 | }; |
| 342 | |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 343 | struct LiteralClassElement : public ClassElement { |
| 344 | std::string element; |
| 345 | |
| 346 | LiteralClassElement(std::string e) : element(e) {} |
| 347 | virtual ~LiteralClassElement() = default; |
| 348 | |
| 349 | void Write(CodeWriter* to) const override; |
| 350 | }; |
| 351 | |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 352 | struct IntConstant : public ClassElement { |
| 353 | const std::string name; |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 354 | const std::string value; |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 355 | |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 356 | IntConstant(const std::string& name, const std::string& value) : name(name), value(value) {} |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 357 | virtual ~IntConstant() = default; |
| 358 | |
| 359 | void Write(CodeWriter* to) const override; |
| 360 | }; |
| 361 | |
| 362 | struct StringConstant : public ClassElement { |
| 363 | const std::string name; |
| 364 | const std::string value; |
| 365 | |
| 366 | StringConstant(std::string name, std::string value) |
| 367 | : name(name), value(value) {} |
| 368 | ~StringConstant() override = default; |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 369 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 370 | void Write(CodeWriter* to) const override; |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 371 | }; |
| 372 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 373 | struct Class : public ClassElement { |
| 374 | enum { CLASS, INTERFACE }; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 375 | |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 376 | std::string comment; |
| Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 377 | std::vector<std::string> annotations; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 378 | int modifiers = 0; |
| 379 | int what = CLASS; // CLASS or INTERFACE |
| 380 | const Type* type = nullptr; |
| 381 | const Type* extends = nullptr; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 382 | std::vector<const Type*> interfaces; |
| 383 | std::vector<ClassElement*> elements; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 384 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 385 | Class() = default; |
| 386 | virtual ~Class() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 387 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 388 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 389 | }; |
| 390 | |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 391 | class Document : public AstNode { |
| Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 392 | public: |
| 393 | Document(const std::string& comment, |
| 394 | const std::string& package, |
| 395 | const std::string& original_src, |
| 396 | std::unique_ptr<Class> clazz); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 397 | virtual ~Document() = default; |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 398 | void Write(CodeWriter* to) const override; |
| Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 399 | |
| 400 | private: |
| 401 | std::string comment_; |
| 402 | std::string package_; |
| 403 | std::string original_src_; |
| 404 | std::unique_ptr<Class> clazz_; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 405 | }; |
| 406 | |
| Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 407 | } // namespace java |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 408 | } // namespace aidl |
| 409 | } // namespace android |