Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 1 | // Copyright 2020 The Tint Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef SRC_AST_CALL_EXPRESSION_H_ |
| 16 | #define SRC_AST_CALL_EXPRESSION_H_ |
| 17 | |
| 18 | #include <memory> |
| 19 | #include <utility> |
| 20 | #include <vector> |
| 21 | |
| 22 | #include "src/ast/expression.h" |
| 23 | #include "src/ast/literal.h" |
| 24 | |
| 25 | namespace tint { |
| 26 | namespace ast { |
| 27 | |
| 28 | /// A call expression |
| 29 | class CallExpression : public Expression { |
| 30 | public: |
| 31 | /// Constructor |
Dan Sinclair | 00cf5a4 | 2020-03-05 20:35:57 +0000 | [diff] [blame] | 32 | CallExpression(); |
| 33 | /// Constructor |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 34 | /// @param func the function |
| 35 | /// @param params the parameters |
| 36 | CallExpression(std::unique_ptr<Expression> func, |
| 37 | std::vector<std::unique_ptr<Expression>> params); |
| 38 | /// Constructor |
dan sinclair | a322f5d | 2020-03-30 22:46:06 +0000 | [diff] [blame] | 39 | /// @param source the call expression source |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 40 | /// @param func the function |
| 41 | /// @param params the parameters |
| 42 | CallExpression(const Source& source, |
| 43 | std::unique_ptr<Expression> func, |
| 44 | std::vector<std::unique_ptr<Expression>> params); |
| 45 | /// Move constructor |
| 46 | CallExpression(CallExpression&&) = default; |
| 47 | ~CallExpression() override; |
| 48 | |
| 49 | /// Sets the func |
| 50 | /// @param func the func |
| 51 | void set_func(std::unique_ptr<Expression> func) { func_ = std::move(func); } |
| 52 | /// @returns the func |
| 53 | Expression* func() const { return func_.get(); } |
| 54 | |
| 55 | /// Sets the parameters |
| 56 | /// @param params the parameters |
| 57 | void set_params(std::vector<std::unique_ptr<Expression>> params) { |
| 58 | params_ = std::move(params); |
| 59 | } |
| 60 | /// @returns the parameters |
| 61 | const std::vector<std::unique_ptr<Expression>>& params() const { |
| 62 | return params_; |
| 63 | } |
| 64 | |
| 65 | /// @returns true if this is a call expression |
| 66 | bool IsCall() const override { return true; } |
| 67 | |
| 68 | /// @returns true if the node is valid |
| 69 | bool IsValid() const override; |
| 70 | |
| 71 | /// Writes a representation of the node to the output stream |
| 72 | /// @param out the stream to write to |
| 73 | /// @param indent number of spaces to indent the node when writing |
| 74 | void to_str(std::ostream& out, size_t indent) const override; |
| 75 | |
| 76 | private: |
| 77 | CallExpression(const CallExpression&) = delete; |
| 78 | |
| 79 | std::unique_ptr<Expression> func_; |
| 80 | std::vector<std::unique_ptr<Expression>> params_; |
| 81 | }; |
| 82 | |
| 83 | } // namespace ast |
| 84 | } // namespace tint |
| 85 | |
| 86 | #endif // SRC_AST_CALL_EXPRESSION_H_ |