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