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