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