Christopher Wiley | 038485e | 2015-09-12 11:14:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Steven Moreland | 9fccf58 | 2018-08-27 20:36:27 -0700 | [diff] [blame] | 17 | #pragma once |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 18 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 19 | #include <stdarg.h> |
| 20 | #include <stdio.h> |
Jeongik Cha | aabc144 | 2019-02-12 17:44:48 +0900 | [diff] [blame] | 21 | #include <memory> |
| 22 | #include <optional> |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 23 | #include <string> |
Jeongik Cha | 439f2c4 | 2019-02-13 12:38:30 +0900 | [diff] [blame] | 24 | #include <variant> |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 25 | #include <vector> |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 26 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 27 | enum { |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 28 | PACKAGE_PRIVATE = 0x00000000, |
| 29 | PUBLIC = 0x00000001, |
| 30 | PRIVATE = 0x00000002, |
| 31 | PROTECTED = 0x00000003, |
| 32 | SCOPE_MASK = 0x00000003, |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 33 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 34 | STATIC = 0x00000010, |
| 35 | FINAL = 0x00000020, |
| 36 | ABSTRACT = 0x00000040, |
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 | OVERRIDE = 0x00000100, |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 39 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 40 | ALL_MODIFIERS = 0xffffffff |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 41 | }; |
| 42 | |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 43 | namespace android { |
| 44 | namespace aidl { |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 45 | class CodeWriter; |
Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 46 | } // namespace aidl |
| 47 | } // namespace android |
| 48 | |
| 49 | namespace android { |
| 50 | namespace aidl { |
| 51 | namespace java { |
| 52 | |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 53 | // Write the modifiers that are set in both mod and mask |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 54 | void WriteModifiers(CodeWriter* to, int mod, int mask); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 55 | |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 56 | struct AstNode { |
| 57 | AstNode() = default; |
| 58 | virtual ~AstNode() = default; |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 59 | virtual void Write(CodeWriter* to) const = 0; |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 60 | std::string ToString(); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 63 | struct ClassElement : public AstNode { |
| 64 | ClassElement() = default; |
| 65 | virtual ~ClassElement() = default; |
| 66 | }; |
| 67 | |
| 68 | struct Expression : public AstNode { |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 69 | virtual ~Expression() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 72 | struct LiteralExpression : public Expression { |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 73 | std::string value; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 74 | |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 75 | explicit LiteralExpression(const std::string& value); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 76 | virtual ~LiteralExpression() = default; |
| 77 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 80 | struct StringLiteralExpression : public Expression { |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 81 | std::string value; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 82 | |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 83 | explicit StringLiteralExpression(const std::string& value); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 84 | virtual ~StringLiteralExpression() = default; |
| 85 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 88 | struct Variable : public Expression { |
Jiyong Park | bf5fd5c | 2020-06-05 19:48:05 +0900 | [diff] [blame] | 89 | std::vector<std::string> annotations; |
Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 90 | const std::string type; |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 91 | std::string name; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 92 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 93 | Variable() = default; |
Jeongik Cha | dc77c1b | 2019-02-12 16:13:25 +0900 | [diff] [blame] | 94 | Variable(const std::string& type, const std::string& name); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 95 | virtual ~Variable() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 96 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 97 | void WriteDeclaration(CodeWriter* to) const; |
| 98 | void Write(CodeWriter* to) const; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 101 | struct FieldVariable : public Expression { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 102 | std::variant<std::shared_ptr<Expression>, std::string> receiver; |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 103 | std::string name; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 104 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 105 | FieldVariable(std::shared_ptr<Expression> object, const std::string& name); |
Jeongik Cha | 439f2c4 | 2019-02-13 12:38:30 +0900 | [diff] [blame] | 106 | FieldVariable(const std::string& clazz, const std::string& name); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 107 | virtual ~FieldVariable() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 108 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 109 | void Write(CodeWriter* to) const; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 112 | struct Field : public ClassElement { |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 113 | std::string comment; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 114 | std::vector<std::string> annotations; |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 115 | int modifiers = 0; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 116 | std::shared_ptr<Variable> variable = nullptr; |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 117 | std::string value; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 118 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 119 | Field() = default; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 120 | Field(int modifiers, std::shared_ptr<Variable> variable); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 121 | virtual ~Field() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 122 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 123 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 126 | struct Statement : public AstNode { |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 127 | virtual ~Statement() = default; |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | struct LiteralStatement : public Statement { |
| 131 | public: |
| 132 | LiteralStatement(const std::string& value); |
| 133 | virtual ~LiteralStatement() = default; |
| 134 | void Write(CodeWriter* to) const override; |
| 135 | |
| 136 | private: |
| 137 | const std::string value_; |
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 StatementBlock : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 141 | std::vector<std::shared_ptr<Statement>> statements; |
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 | StatementBlock() = default; |
| 144 | virtual ~StatementBlock() = default; |
| 145 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 146 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 147 | void Add(std::shared_ptr<Statement> statement); |
| 148 | void Add(std::shared_ptr<Expression> expression); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 149 | }; |
| 150 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 151 | struct ExpressionStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 152 | std::shared_ptr<Expression> expression; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 153 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 154 | explicit ExpressionStatement(std::shared_ptr<Expression> expression); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 155 | virtual ~ExpressionStatement() = 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 Assignment : public Expression { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 160 | std::shared_ptr<Variable> lvalue; |
| 161 | std::shared_ptr<Expression> rvalue; |
Jeongik Cha | 439f2c4 | 2019-02-13 12:38:30 +0900 | [diff] [blame] | 162 | std::optional<std::string> cast = std::nullopt; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 163 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 164 | Assignment(std::shared_ptr<Variable> lvalue, std::shared_ptr<Expression> rvalue); |
| 165 | Assignment(std::shared_ptr<Variable> lvalue, std::shared_ptr<Expression> rvalue, |
| 166 | std::string cast); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 167 | virtual ~Assignment() = default; |
| 168 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 169 | }; |
| 170 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 171 | struct MethodCall : public Expression { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 172 | std::variant<std::monostate, std::shared_ptr<Expression>, std::string> receiver; |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 173 | std::string name; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 174 | std::vector<std::shared_ptr<Expression>> arguments; |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 175 | std::vector<std::string> exceptions; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 176 | |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 177 | explicit MethodCall(const std::string& name); |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 178 | MethodCall(const std::string& name, const std::vector<std::shared_ptr<Expression>>& args); |
| 179 | MethodCall(std::shared_ptr<Expression> obj, const std::string& name); |
Jeongik Cha | 439f2c4 | 2019-02-13 12:38:30 +0900 | [diff] [blame] | 180 | MethodCall(const std::string& clazz, const std::string& name); |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 181 | MethodCall(std::shared_ptr<Expression> obj, const std::string& name, |
| 182 | const std::vector<std::shared_ptr<Expression>>& args); |
| 183 | MethodCall(const std::string&, const std::string& name, |
| 184 | const std::vector<std::shared_ptr<Expression>>& args); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 185 | virtual ~MethodCall() = 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 Comparison : public Expression { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 190 | std::shared_ptr<Expression> lvalue; |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 191 | std::string op; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 192 | std::shared_ptr<Expression> rvalue; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 193 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 194 | Comparison(std::shared_ptr<Expression> lvalue, const std::string& op, |
| 195 | std::shared_ptr<Expression> rvalue); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 196 | virtual ~Comparison() = default; |
| 197 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 198 | }; |
| 199 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 200 | struct NewExpression : public Expression { |
Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 201 | const std::string instantiableName; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 202 | std::vector<std::shared_ptr<Expression>> arguments; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 203 | |
Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 204 | explicit NewExpression(const std::string& name); |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 205 | NewExpression(const std::string& name, const std::vector<std::shared_ptr<Expression>>& args); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 206 | virtual ~NewExpression() = default; |
| 207 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 208 | }; |
| 209 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 210 | struct Cast : public Expression { |
Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 211 | const std::string type; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 212 | std::shared_ptr<Expression> expression = nullptr; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 213 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 214 | Cast() = default; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 215 | Cast(const std::string& type, std::shared_ptr<Expression> expression); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 216 | virtual ~Cast() = default; |
| 217 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 218 | }; |
| 219 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 220 | struct VariableDeclaration : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 221 | std::shared_ptr<Variable> lvalue = nullptr; |
| 222 | std::shared_ptr<Expression> rvalue = nullptr; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 223 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 224 | explicit VariableDeclaration(std::shared_ptr<Variable> lvalue); |
| 225 | VariableDeclaration(std::shared_ptr<Variable> lvalue, std::shared_ptr<Expression> rvalue); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 226 | virtual ~VariableDeclaration() = default; |
| 227 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 228 | }; |
| 229 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 230 | struct IfStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 231 | std::shared_ptr<Expression> expression = nullptr; |
| 232 | std::shared_ptr<StatementBlock> statements = std::make_shared<StatementBlock>(); |
| 233 | std::shared_ptr<IfStatement> elseif = nullptr; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 234 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 235 | IfStatement() = default; |
| 236 | virtual ~IfStatement() = default; |
| 237 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 238 | }; |
| 239 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 240 | struct ReturnStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 241 | std::shared_ptr<Expression> expression; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 242 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 243 | explicit ReturnStatement(std::shared_ptr<Expression> expression); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 244 | virtual ~ReturnStatement() = default; |
| 245 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
Kevin Jeon | f2551d8 | 2021-07-27 16:06:07 +0000 | [diff] [blame] | 248 | struct BreakStatement : public Statement { |
| 249 | BreakStatement() = default; |
| 250 | virtual ~BreakStatement() = default; |
| 251 | void Write(CodeWriter* to) const override; |
| 252 | }; |
| 253 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 254 | struct TryStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 255 | std::shared_ptr<StatementBlock> statements = std::make_shared<StatementBlock>(); |
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 | TryStatement() = default; |
| 258 | virtual ~TryStatement() = 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 FinallyStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 263 | std::shared_ptr<StatementBlock> statements = std::make_shared<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 | FinallyStatement() = default; |
| 266 | virtual ~FinallyStatement() = default; |
| 267 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 268 | }; |
| 269 | |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 270 | struct Case : public AstNode { |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 271 | std::vector<std::string> cases; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 272 | std::shared_ptr<StatementBlock> statements = std::make_shared<StatementBlock>(); |
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 | Case() = default; |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 275 | explicit Case(const std::string& c); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 276 | virtual ~Case() = default; |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 277 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 278 | }; |
| 279 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 280 | struct SwitchStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 281 | std::shared_ptr<Expression> expression; |
| 282 | std::vector<std::shared_ptr<Case>> cases; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 283 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 284 | explicit SwitchStatement(std::shared_ptr<Expression> expression); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 285 | virtual ~SwitchStatement() = default; |
| 286 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 287 | }; |
| 288 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 289 | struct Method : public ClassElement { |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 290 | std::string comment; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 291 | std::vector<std::string> annotations; |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 292 | int modifiers = 0; |
Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 293 | std::optional<std::string> returnType = std::nullopt; // nullopt means constructor |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 294 | std::string name; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 295 | std::vector<std::shared_ptr<Variable>> parameters; |
Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 296 | std::vector<std::string> exceptions; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 297 | std::shared_ptr<StatementBlock> statements = nullptr; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 298 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 299 | Method() = default; |
| 300 | virtual ~Method() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 301 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 302 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 303 | }; |
| 304 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 305 | struct LiteralClassElement : public ClassElement { |
| 306 | std::string element; |
| 307 | |
| 308 | LiteralClassElement(std::string e) : element(e) {} |
| 309 | virtual ~LiteralClassElement() = default; |
| 310 | |
| 311 | void Write(CodeWriter* to) const override; |
| 312 | }; |
| 313 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 314 | struct Class : public ClassElement { |
| 315 | enum { CLASS, INTERFACE }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 316 | |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 317 | std::string comment; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 318 | std::vector<std::string> annotations; |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 319 | int modifiers = 0; |
| 320 | int what = CLASS; // CLASS or INTERFACE |
Jeongik Cha | aabc144 | 2019-02-12 17:44:48 +0900 | [diff] [blame] | 321 | std::string type; |
| 322 | std::optional<std::string> extends = std::nullopt; |
| 323 | std::vector<std::string> interfaces; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 324 | std::vector<std::shared_ptr<ClassElement>> elements; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 325 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 326 | Class() = default; |
| 327 | virtual ~Class() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 328 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 329 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 330 | }; |
| 331 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 332 | extern std::shared_ptr<Expression> NULL_VALUE; |
| 333 | extern std::shared_ptr<Expression> THIS_VALUE; |
| 334 | extern std::shared_ptr<Expression> SUPER_VALUE; |
| 335 | extern std::shared_ptr<Expression> TRUE_VALUE; |
| 336 | extern std::shared_ptr<Expression> FALSE_VALUE; |
Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 337 | } // namespace java |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 338 | } // namespace aidl |
| 339 | } // namespace android |