sem::Function: Add ReturnType()

This is the resolved, semantic, return type of the function.

Bug: tint:724
Change-Id: I4ef9f7874414a3ea48131d0102da776f6d82a729
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49526
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton
2021-04-30 19:24:29 +00:00
committed by Commit Bot service account
parent fa9af4b0ef
commit 3068dcb3d7
5 changed files with 61 additions and 42 deletions

View File

@@ -41,12 +41,13 @@ ParameterList GetParameters(ast::Function* ast) {
} // namespace
Function::Function(ast::Function* declaration,
Type* return_type,
std::vector<const Variable*> parameters,
std::vector<const Variable*> referenced_module_vars,
std::vector<const Variable*> local_referenced_module_vars,
std::vector<const ast::ReturnStatement*> return_statements,
std::vector<Symbol> ancestor_entry_points)
: Base(declaration->return_type(), GetParameters(declaration)),
: Base(return_type, GetParameters(declaration)),
declaration_(declaration),
parameters_(std::move(parameters)),
referenced_module_vars_(std::move(referenced_module_vars)),
@@ -138,8 +139,7 @@ Function::VariableBindings Function::ReferencedStorageTextureVariables() const {
VariableBindings ret;
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type =
var->Declaration()->declared_type()->UnwrapIfNeeded();
auto* unwrapped_type = var->Type()->UnwrapIfNeeded();
auto* storage_texture = unwrapped_type->As<sem::StorageTexture>();
if (storage_texture == nullptr) {
continue;
@@ -156,8 +156,7 @@ Function::VariableBindings Function::ReferencedDepthTextureVariables() const {
VariableBindings ret;
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type =
var->Declaration()->declared_type()->UnwrapIfNeeded();
auto* unwrapped_type = var->Type()->UnwrapIfNeeded();
auto* storage_texture = unwrapped_type->As<sem::DepthTexture>();
if (storage_texture == nullptr) {
continue;
@@ -184,8 +183,7 @@ Function::VariableBindings Function::ReferencedSamplerVariablesImpl(
VariableBindings ret;
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type =
var->Declaration()->declared_type()->UnwrapIfNeeded();
auto* unwrapped_type = var->Type()->UnwrapIfNeeded();
auto* sampler = unwrapped_type->As<sem::Sampler>();
if (sampler == nullptr || sampler->kind() != kind) {
continue;
@@ -203,8 +201,7 @@ Function::VariableBindings Function::ReferencedSampledTextureVariablesImpl(
VariableBindings ret;
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type =
var->Declaration()->declared_type()->UnwrapIfNeeded();
auto* unwrapped_type = var->Type()->UnwrapIfNeeded();
auto* texture = unwrapped_type->As<sem::Texture>();
if (texture == nullptr) {
continue;

View File

@@ -46,6 +46,7 @@ class Function : public Castable<Function, CallTarget> {
/// Constructor
/// @param declaration the ast::Function
/// @param return_type the return type of the function
/// @param parameters the parameters to the function
/// @param referenced_module_vars the referenced module variables
/// @param local_referenced_module_vars the locally referenced module
@@ -53,6 +54,7 @@ class Function : public Castable<Function, CallTarget> {
/// variables
/// @param ancestor_entry_points the ancestor entry points
Function(ast::Function* declaration,
Type* return_type,
std::vector<const Variable*> parameters,
std::vector<const Variable*> referenced_module_vars,
std::vector<const Variable*> local_referenced_module_vars,