| 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 | |
| 17 | #ifndef AIDL_AST_JAVA_H_ |
| 18 | #define AIDL_AST_JAVA_H_ |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 19 | |
| Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 20 | #include <memory> |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 23 | #include <string> |
| 24 | #include <vector> |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 25 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 26 | enum { |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 27 | PACKAGE_PRIVATE = 0x00000000, |
| 28 | PUBLIC = 0x00000001, |
| 29 | PRIVATE = 0x00000002, |
| 30 | PROTECTED = 0x00000003, |
| 31 | SCOPE_MASK = 0x00000003, |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 32 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 33 | STATIC = 0x00000010, |
| 34 | FINAL = 0x00000020, |
| 35 | ABSTRACT = 0x00000040, |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 36 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 37 | OVERRIDE = 0x00000100, |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 38 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 39 | ALL_MODIFIERS = 0xffffffff |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 42 | namespace android { |
| 43 | namespace aidl { |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 44 | class CodeWriter; |
| Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 45 | } // namespace aidl |
| 46 | } // namespace android |
| 47 | |
| 48 | namespace android { |
| 49 | namespace aidl { |
| 50 | namespace java { |
| 51 | |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 52 | class Type; |
| 53 | |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 54 | // Write the modifiers that are set in both mod and mask |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 55 | void WriteModifiers(CodeWriter* to, int mod, int mask); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 56 | |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 57 | struct AstNode { |
| 58 | AstNode() = default; |
| 59 | virtual ~AstNode() = default; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 60 | virtual void Write(CodeWriter* to) const = 0; |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 61 | std::string ToString(); |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 64 | struct ClassElement : public AstNode { |
| 65 | ClassElement() = default; |
| 66 | virtual ~ClassElement() = default; |
| 67 | }; |
| 68 | |
| 69 | struct Expression : public AstNode { |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 70 | virtual ~Expression() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 73 | struct LiteralExpression : public Expression { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 74 | std::string value; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 75 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 76 | explicit LiteralExpression(const std::string& value); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 77 | virtual ~LiteralExpression() = default; |
| 78 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | // TODO: also escape the contents. not needed for now |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 82 | struct StringLiteralExpression : public Expression { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 83 | std::string value; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 84 | |
| Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 85 | explicit StringLiteralExpression(const std::string& value); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 86 | virtual ~StringLiteralExpression() = default; |
| 87 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 90 | struct Variable : public Expression { |
| 91 | const Type* type = nullptr; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 92 | std::string name; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 93 | int dimension = 0; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 94 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 95 | Variable() = default; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 96 | Variable(const Type* type, const std::string& name); |
| 97 | Variable(const Type* type, const std::string& name, int dimension); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 98 | virtual ~Variable() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 99 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 100 | void WriteDeclaration(CodeWriter* to) const; |
| 101 | void Write(CodeWriter* to) const; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 104 | struct FieldVariable : public Expression { |
| 105 | Expression* object; |
| 106 | const Type* clazz; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 107 | std::string name; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 108 | |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 109 | FieldVariable(Expression* object, const std::string& name); |
| 110 | FieldVariable(const Type* clazz, const std::string& name); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 111 | virtual ~FieldVariable() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 112 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 113 | void Write(CodeWriter* to) const; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 116 | struct Field : public ClassElement { |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 117 | std::string comment; |
| 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, |
| 253 | const Type* cast = NULL); |
| 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; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 328 | int modifiers = 0; |
| 329 | const Type* returnType = nullptr; // nullptr means constructor |
| 330 | size_t returnTypeDimension = 0; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 331 | std::string name; |
| 332 | std::vector<Variable*> parameters; |
| 333 | std::vector<const Type*> exceptions; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 334 | StatementBlock* statements = nullptr; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 335 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 336 | Method() = default; |
| 337 | virtual ~Method() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 338 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 339 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 340 | }; |
| 341 | |
| Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 342 | struct LiteralClassElement : public ClassElement { |
| 343 | std::string element; |
| 344 | |
| 345 | LiteralClassElement(std::string e) : element(e) {} |
| 346 | virtual ~LiteralClassElement() = default; |
| 347 | |
| 348 | void Write(CodeWriter* to) const override; |
| 349 | }; |
| 350 | |
| Christopher Wiley | 69b44cf | 2016-05-03 13:43:33 -0700 | [diff] [blame] | 351 | struct IntConstant : public ClassElement { |
| 352 | const std::string name; |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 353 | const std::string value; |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 354 | |
| Steven Moreland | 693640b | 2018-07-19 13:46:27 -0700 | [diff] [blame] | 355 | 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] | 356 | virtual ~IntConstant() = default; |
| 357 | |
| 358 | void Write(CodeWriter* to) const override; |
| 359 | }; |
| 360 | |
| 361 | struct StringConstant : public ClassElement { |
| 362 | const std::string name; |
| 363 | const std::string value; |
| 364 | |
| 365 | StringConstant(std::string name, std::string value) |
| 366 | : name(name), value(value) {} |
| 367 | ~StringConstant() override = default; |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 368 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 369 | void Write(CodeWriter* to) const override; |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 370 | }; |
| 371 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 372 | struct Class : public ClassElement { |
| 373 | enum { CLASS, INTERFACE }; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 374 | |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 375 | std::string comment; |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 376 | int modifiers = 0; |
| 377 | int what = CLASS; // CLASS or INTERFACE |
| 378 | const Type* type = nullptr; |
| 379 | const Type* extends = nullptr; |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 380 | std::vector<const Type*> interfaces; |
| 381 | std::vector<ClassElement*> elements; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 382 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 383 | Class() = default; |
| 384 | virtual ~Class() = default; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 385 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 386 | void Write(CodeWriter* to) const override; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 387 | }; |
| 388 | |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 389 | class Document : public AstNode { |
| Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 390 | public: |
| 391 | Document(const std::string& comment, |
| 392 | const std::string& package, |
| 393 | const std::string& original_src, |
| 394 | std::unique_ptr<Class> clazz); |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 395 | virtual ~Document() = default; |
| Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 396 | void Write(CodeWriter* to) const override; |
| Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 397 | |
| 398 | private: |
| 399 | std::string comment_; |
| 400 | std::string package_; |
| 401 | std::string original_src_; |
| 402 | std::unique_ptr<Class> clazz_; |
| Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 403 | }; |
| 404 | |
| Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 405 | } // namespace java |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 406 | } // namespace aidl |
| 407 | } // namespace android |
| 408 | |
| Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 409 | #endif // AIDL_AST_JAVA_H_ |