diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 4c851e1c44..59f367c3fd 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -361,6 +361,7 @@ libtint_source_set("libtint_syntax_tree_src") { "sem/expression.h", "sem/for_loop_statement.h", "sem/function.h", + "sem/function_expression.h", "sem/if_statement.h", "sem/index_accessor_expression.h", "sem/info.h", @@ -741,6 +742,8 @@ libtint_source_set("libtint_sem_src") { "sem/for_loop_statement.h", "sem/function.cc", "sem/function.h", + "sem/function_expression.cc", + "sem/function_expression.h", "sem/if_statement.cc", "sem/if_statement.h", "sem/index_accessor_expression.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index e80e1f8598..92c3bb64fe 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -316,6 +316,8 @@ list(APPEND TINT_LIB_SRCS sem/expression.h sem/for_loop_statement.cc sem/for_loop_statement.h + sem/function_expression.cc + sem/function_expression.h sem/function.cc sem/if_statement.cc sem/if_statement.h diff --git a/src/tint/sem/function_expression.cc b/src/tint/sem/function_expression.cc new file mode 100644 index 0000000000..86956556e4 --- /dev/null +++ b/src/tint/sem/function_expression.cc @@ -0,0 +1,28 @@ +// Copyright 2023 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/tint/sem/function_expression.h" + +TINT_INSTANTIATE_TYPEINFO(tint::sem::FunctionExpression); + +namespace tint::sem { + +FunctionExpression::FunctionExpression(const ast::Expression* declaration, + const Statement* statement, + const sem::Function* function) + : Base(declaration, statement), function_(function) {} + +FunctionExpression::~FunctionExpression() = default; + +} // namespace tint::sem diff --git a/src/tint/sem/function_expression.h b/src/tint/sem/function_expression.h new file mode 100644 index 0000000000..de5ac5ad23 --- /dev/null +++ b/src/tint/sem/function_expression.h @@ -0,0 +1,51 @@ +// Copyright 2023 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_TINT_SEM_FUNCTION_EXPRESSION_H_ +#define SRC_TINT_SEM_FUNCTION_EXPRESSION_H_ + +#include "src/tint/sem/expression.h" + +// Forward declarations +namespace tint::sem { +class Function; +} // namespace tint::sem + +namespace tint::sem { + +/// FunctionExpression holds the semantic information for expression nodes that resolve to +/// functions. +class FunctionExpression : public Castable { + public: + /// Constructor + /// @param declaration the AST node + /// @param statement the statement that owns this expression + /// @param function the function that the expression resolved to + FunctionExpression(const ast::Expression* declaration, + const Statement* statement, + const sem::Function* function); + + /// Destructor + ~FunctionExpression() override; + + /// @return the function that the expression resolved to + const sem::Function* Function() const { return function_; } + + private: + sem::Function const* const function_; +}; + +} // namespace tint::sem + +#endif // SRC_TINT_SEM_FUNCTION_EXPRESSION_H_