Unwrap pointer arguments to imported methods.
Make sure we unwrap pointers in import determination so things like passing a member of a struct will determine the import correctly. Change-Id: Id4565351c45e7798664c3368e2dec19b1440492d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20341 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
9eab206e3f
commit
e6759029fb
|
@ -329,9 +329,11 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
|
||||||
auto* result_type = GetImportData(expr->source(), imp->path(),
|
auto* result_type = GetImportData(expr->source(), imp->path(),
|
||||||
ident->name(), expr->params(), &ext_id);
|
ident->name(), expr->params(), &ext_id);
|
||||||
if (result_type == nullptr) {
|
if (result_type == nullptr) {
|
||||||
|
if (error_.empty()) {
|
||||||
set_error(expr->source(),
|
set_error(expr->source(),
|
||||||
"Unable to determine result type for GLSL expression " +
|
"Unable to determine result type for GLSL expression " +
|
||||||
ident->name());
|
ident->name());
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,13 +646,14 @@ ast::type::Type* TypeDeterminer::GetImportData(
|
||||||
std::to_string(params.size()));
|
std::to_string(params.size()));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!params[0]->result_type()->is_float_scalar_or_vector()) {
|
|
||||||
|
auto* result_type = params[0]->result_type()->UnwrapPtrIfNeeded();
|
||||||
|
if (!result_type->is_float_scalar_or_vector()) {
|
||||||
set_error(source, "incorrect type for " + name +
|
set_error(source, "incorrect type for " + name +
|
||||||
". Requires a float scalar or a float vector");
|
". Requires a float scalar or a float vector");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* result_type = params[0]->result_type();
|
|
||||||
if (name == "round") {
|
if (name == "round") {
|
||||||
*id = GLSLstd450Round;
|
*id = GLSLstd450Round;
|
||||||
} else if (name == "roundeven") {
|
} else if (name == "roundeven") {
|
||||||
|
@ -726,18 +729,20 @@ ast::type::Type* TypeDeterminer::GetImportData(
|
||||||
". Expected 2 got " + std::to_string(params.size());
|
". Expected 2 got " + std::to_string(params.size());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!params[0]->result_type()->is_float_scalar_or_vector() ||
|
|
||||||
!params[1]->result_type()->is_float_scalar_or_vector()) {
|
auto* result_type_0 = params[0]->result_type()->UnwrapPtrIfNeeded();
|
||||||
|
auto* result_type_1 = params[1]->result_type()->UnwrapPtrIfNeeded();
|
||||||
|
if (!result_type_0->is_float_scalar_or_vector() ||
|
||||||
|
!result_type_1->is_float_scalar_or_vector()) {
|
||||||
error_ = "incorrect type for " + name +
|
error_ = "incorrect type for " + name +
|
||||||
". Requires float scalar or a float vector values";
|
". Requires float scalar or a float vector values";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (params[0]->result_type() != params[1]->result_type()) {
|
if (result_type_0 != result_type_1) {
|
||||||
error_ = "mismatched parameter types for " + name;
|
error_ = "mismatched parameter types for " + name;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* result_type = params[0]->result_type();
|
|
||||||
if (name == "atan2") {
|
if (name == "atan2") {
|
||||||
*id = GLSLstd450Atan2;
|
*id = GLSLstd450Atan2;
|
||||||
} else if (name == "pow") {
|
} else if (name == "pow") {
|
||||||
|
@ -758,11 +763,12 @@ ast::type::Type* TypeDeterminer::GetImportData(
|
||||||
*id = GLSLstd450Distance;
|
*id = GLSLstd450Distance;
|
||||||
|
|
||||||
// Distance returns a scalar of the same type as the parameter.
|
// Distance returns a scalar of the same type as the parameter.
|
||||||
return result_type->is_float_scalar() ? result_type
|
return result_type_0->is_float_scalar()
|
||||||
: result_type->AsVector()->type();
|
? result_type_0
|
||||||
|
: result_type_0->AsVector()->type();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_type;
|
return result_type_0;
|
||||||
} else if (name == "fclamp" || name == "fmix" || name == "smoothstep" ||
|
} else if (name == "fclamp" || name == "fmix" || name == "smoothstep" ||
|
||||||
name == "fma" || name == "nclamp" || name == "faceforward") {
|
name == "fma" || name == "nclamp" || name == "faceforward") {
|
||||||
if (params.size() != 3) {
|
if (params.size() != 3) {
|
||||||
|
@ -770,20 +776,22 @@ ast::type::Type* TypeDeterminer::GetImportData(
|
||||||
". Expected 3 got " + std::to_string(params.size());
|
". Expected 3 got " + std::to_string(params.size());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!params[0]->result_type()->is_float_scalar_or_vector() ||
|
|
||||||
!params[1]->result_type()->is_float_scalar_or_vector() ||
|
auto* result_type_0 = params[0]->result_type()->UnwrapPtrIfNeeded();
|
||||||
!params[2]->result_type()->is_float_scalar_or_vector()) {
|
auto* result_type_1 = params[1]->result_type()->UnwrapPtrIfNeeded();
|
||||||
|
auto* result_type_2 = params[2]->result_type()->UnwrapPtrIfNeeded();
|
||||||
|
if (!result_type_0->is_float_scalar_or_vector() ||
|
||||||
|
!result_type_1->is_float_scalar_or_vector() ||
|
||||||
|
!result_type_2->is_float_scalar_or_vector()) {
|
||||||
error_ = "incorrect type for " + name +
|
error_ = "incorrect type for " + name +
|
||||||
". Requires float scalar or a float vector values";
|
". Requires float scalar or a float vector values";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (params[0]->result_type() != params[1]->result_type() ||
|
if (result_type_0 != result_type_1 || result_type_0 != result_type_2) {
|
||||||
params[0]->result_type() != params[2]->result_type()) {
|
|
||||||
error_ = "mismatched parameter types for " + name;
|
error_ = "mismatched parameter types for " + name;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* result_type = params[0]->result_type();
|
|
||||||
if (name == "fclamp") {
|
if (name == "fclamp") {
|
||||||
*id = GLSLstd450FClamp;
|
*id = GLSLstd450FClamp;
|
||||||
} else if (name == "fmix") {
|
} else if (name == "fmix") {
|
||||||
|
@ -798,7 +806,7 @@ ast::type::Type* TypeDeterminer::GetImportData(
|
||||||
*id = GLSLstd450FaceForward;
|
*id = GLSLstd450FaceForward;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_type;
|
return result_type_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in New Issue