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 | |
| 80 | // TODO: also escape the contents. not needed for now |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 81 | struct StringLiteralExpression : public Expression { |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 82 | std::string value; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 83 | |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 84 | explicit StringLiteralExpression(const std::string& value); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 85 | virtual ~StringLiteralExpression() = default; |
| 86 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 89 | struct Variable : public Expression { |
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 NewArrayExpression : 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> size; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 213 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 214 | NewArrayExpression(const std::string& type, std::shared_ptr<Expression> size); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 215 | virtual ~NewArrayExpression() = default; |
| 216 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 217 | }; |
| 218 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 219 | struct Cast : public Expression { |
Jeongik Cha | 9a7f21f | 2019-02-13 14:42:47 +0900 | [diff] [blame] | 220 | const std::string type; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 221 | std::shared_ptr<Expression> expression = nullptr; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 222 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 223 | Cast() = default; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 224 | Cast(const std::string& type, std::shared_ptr<Expression> expression); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 225 | virtual ~Cast() = default; |
| 226 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 227 | }; |
| 228 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 229 | struct VariableDeclaration : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 230 | std::shared_ptr<Variable> lvalue = nullptr; |
| 231 | std::shared_ptr<Expression> rvalue = nullptr; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 232 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 233 | explicit VariableDeclaration(std::shared_ptr<Variable> lvalue); |
| 234 | VariableDeclaration(std::shared_ptr<Variable> lvalue, std::shared_ptr<Expression> rvalue); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 235 | virtual ~VariableDeclaration() = default; |
| 236 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 237 | }; |
| 238 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 239 | struct IfStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 240 | std::shared_ptr<Expression> expression = nullptr; |
| 241 | std::shared_ptr<StatementBlock> statements = std::make_shared<StatementBlock>(); |
| 242 | std::shared_ptr<IfStatement> elseif = nullptr; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 243 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 244 | IfStatement() = default; |
| 245 | virtual ~IfStatement() = default; |
| 246 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 247 | }; |
| 248 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 249 | struct ReturnStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 250 | std::shared_ptr<Expression> expression; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 251 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 252 | explicit ReturnStatement(std::shared_ptr<Expression> expression); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 253 | virtual ~ReturnStatement() = default; |
| 254 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 255 | }; |
| 256 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 257 | struct TryStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 258 | std::shared_ptr<StatementBlock> statements = std::make_shared<StatementBlock>(); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 259 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 260 | TryStatement() = default; |
| 261 | virtual ~TryStatement() = default; |
| 262 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 263 | }; |
| 264 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 265 | struct FinallyStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 266 | std::shared_ptr<StatementBlock> statements = std::make_shared<StatementBlock>(); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 267 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 268 | FinallyStatement() = default; |
| 269 | virtual ~FinallyStatement() = default; |
| 270 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 271 | }; |
| 272 | |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 273 | struct Case : public AstNode { |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 274 | std::vector<std::string> cases; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 275 | std::shared_ptr<StatementBlock> statements = std::make_shared<StatementBlock>(); |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 276 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 277 | Case() = default; |
Chih-Hung Hsieh | 156a57f | 2016-06-02 16:17:28 -0700 | [diff] [blame] | 278 | explicit Case(const std::string& c); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 279 | virtual ~Case() = default; |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 280 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 281 | }; |
| 282 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 283 | struct SwitchStatement : public Statement { |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 284 | std::shared_ptr<Expression> expression; |
| 285 | std::vector<std::shared_ptr<Case>> cases; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 286 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 287 | explicit SwitchStatement(std::shared_ptr<Expression> expression); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 288 | virtual ~SwitchStatement() = default; |
| 289 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 290 | }; |
| 291 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 292 | struct Method : public ClassElement { |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 293 | std::string comment; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 294 | std::vector<std::string> annotations; |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 295 | int modifiers = 0; |
Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 296 | std::optional<std::string> returnType = std::nullopt; // nullopt means constructor |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 297 | std::string name; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 298 | std::vector<std::shared_ptr<Variable>> parameters; |
Jeongik Cha | 6cadc21 | 2019-02-12 18:16:03 +0900 | [diff] [blame] | 299 | std::vector<std::string> exceptions; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 300 | std::shared_ptr<StatementBlock> statements = nullptr; |
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 | Method() = default; |
| 303 | virtual ~Method() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 304 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 305 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 306 | }; |
| 307 | |
Steven Moreland | 5557f1c | 2018-07-02 13:50:23 -0700 | [diff] [blame] | 308 | struct LiteralClassElement : public ClassElement { |
| 309 | std::string element; |
| 310 | |
| 311 | LiteralClassElement(std::string e) : element(e) {} |
| 312 | virtual ~LiteralClassElement() = default; |
| 313 | |
| 314 | void Write(CodeWriter* to) const override; |
| 315 | }; |
| 316 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 317 | struct Class : public ClassElement { |
| 318 | enum { CLASS, INTERFACE }; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 319 | |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 320 | std::string comment; |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 321 | std::vector<std::string> annotations; |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 322 | int modifiers = 0; |
| 323 | int what = CLASS; // CLASS or INTERFACE |
Jeongik Cha | aabc144 | 2019-02-12 17:44:48 +0900 | [diff] [blame] | 324 | std::string type; |
| 325 | std::optional<std::string> extends = std::nullopt; |
| 326 | std::vector<std::string> interfaces; |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 327 | std::vector<std::shared_ptr<ClassElement>> elements; |
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 | Class() = default; |
| 330 | virtual ~Class() = default; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 331 | |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 332 | void Write(CodeWriter* to) const override; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 333 | }; |
| 334 | |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 335 | class Document : public AstNode { |
Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 336 | public: |
| 337 | Document(const std::string& comment, |
| 338 | const std::string& package, |
Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 339 | std::unique_ptr<Class> clazz); |
Christopher Wiley | ae58997 | 2016-01-29 11:19:23 -0800 | [diff] [blame] | 340 | virtual ~Document() = default; |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 341 | void Write(CodeWriter* to) const override; |
Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 342 | |
| 343 | private: |
| 344 | std::string comment_; |
| 345 | std::string package_; |
Christopher Wiley | f76b59a | 2016-01-29 11:32:11 -0800 | [diff] [blame] | 346 | std::unique_ptr<Class> clazz_; |
Adam Lesinski | ffa1686 | 2014-01-23 18:17:42 -0800 | [diff] [blame] | 347 | }; |
| 348 | |
Steven Moreland | 48548e0 | 2019-09-18 15:10:22 -0700 | [diff] [blame] | 349 | extern std::shared_ptr<Expression> NULL_VALUE; |
| 350 | extern std::shared_ptr<Expression> THIS_VALUE; |
| 351 | extern std::shared_ptr<Expression> SUPER_VALUE; |
| 352 | extern std::shared_ptr<Expression> TRUE_VALUE; |
| 353 | extern std::shared_ptr<Expression> FALSE_VALUE; |
Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 354 | } // namespace java |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 355 | } // namespace aidl |
| 356 | } // namespace android |