Remove redundant argument-list description code.
While reading through this code, I realized we implemented the same function-argument stringizing loop three times. (A fourth version in `description()` is similar, but prints the expressions, not types.) Change-Id: I78610cdf6412b2d08984ac701e6421c356f25a83 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/556076 Auto-Submit: John Stiles <johnstiles@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
68d6ff9222
commit
41a1d5f495
@ -7,6 +7,7 @@
|
||||
|
||||
#include "src/sksl/ir/SkSLFunctionCall.h"
|
||||
|
||||
#include "include/core/SkSpan.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/private/SkFloatingPoint.h"
|
||||
#include "include/private/SkSLModifiers.h"
|
||||
@ -815,7 +816,7 @@ std::unique_ptr<Expression> FunctionCall::clone(Position pos) const {
|
||||
|
||||
std::string FunctionCall::description() const {
|
||||
std::string result = std::string(this->function().name()) + "(";
|
||||
std::string separator;
|
||||
const char* separator = "";
|
||||
for (const std::unique_ptr<Expression>& arg : this->arguments()) {
|
||||
result += separator;
|
||||
result += arg->description();
|
||||
@ -870,6 +871,17 @@ const FunctionDeclaration* FunctionCall::FindBestFunctionForCall(
|
||||
return best;
|
||||
}
|
||||
|
||||
static std::string build_argument_type_list(SkSpan<const std::unique_ptr<Expression>> arguments) {
|
||||
std::string result = "(";
|
||||
const char* separator = "";
|
||||
for (const std::unique_ptr<Expression>& arg : arguments) {
|
||||
result += separator;
|
||||
separator = ", ";
|
||||
result += arg->type().displayName();
|
||||
}
|
||||
return result + ")";
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> FunctionCall::Convert(const Context& context,
|
||||
Position pos,
|
||||
std::unique_ptr<Expression> functionValue,
|
||||
@ -905,18 +917,12 @@ std::unique_ptr<Expression> FunctionCall::Convert(const Context& context,
|
||||
const FunctionReference& ref = functionValue->as<FunctionReference>();
|
||||
const std::vector<const FunctionDeclaration*>& functions = ref.functions();
|
||||
const FunctionDeclaration* best = FindBestFunctionForCall(context, functions,
|
||||
arguments);
|
||||
arguments);
|
||||
if (best) {
|
||||
return FunctionCall::Convert(context, pos, *best, std::move(arguments));
|
||||
}
|
||||
std::string msg = "no match for " + std::string(functions[0]->name()) + "(";
|
||||
std::string separator;
|
||||
for (size_t i = 0; i < arguments.size(); i++) {
|
||||
msg += separator;
|
||||
separator = ", ";
|
||||
msg += arguments[i]->type().displayName();
|
||||
}
|
||||
msg += ")";
|
||||
std::string msg = "no match for " + std::string(functions.front()->name()) +
|
||||
build_argument_type_list(arguments);
|
||||
context.fErrors->error(pos, msg);
|
||||
return nullptr;
|
||||
}
|
||||
@ -926,19 +932,14 @@ std::unique_ptr<Expression> FunctionCall::Convert(const Context& context,
|
||||
|
||||
const std::vector<const FunctionDeclaration*>& functions = ref.functions();
|
||||
const FunctionDeclaration* best = FindBestFunctionForCall(context, functions,
|
||||
arguments);
|
||||
arguments);
|
||||
if (best) {
|
||||
return FunctionCall::Convert(context, pos, *best, std::move(arguments));
|
||||
}
|
||||
std::string msg = "no match for " + arguments.back()->type().displayName() +
|
||||
"::" + std::string(functions[0]->name().substr(1)) + "(";
|
||||
std::string separator;
|
||||
for (size_t i = 0; i < arguments.size() - 1; i++) {
|
||||
msg += separator;
|
||||
separator = ", ";
|
||||
msg += arguments[i]->type().displayName();
|
||||
}
|
||||
msg += ")";
|
||||
std::string msg =
|
||||
"no match for " + arguments.back()->type().displayName() +
|
||||
"::" + std::string(functions.front()->name().substr(1)) +
|
||||
build_argument_type_list(SkSpan(arguments).first(arguments.size() - 1));
|
||||
context.fErrors->error(pos, msg);
|
||||
return nullptr;
|
||||
}
|
||||
@ -977,14 +978,8 @@ std::unique_ptr<Expression> FunctionCall::Convert(const Context& context,
|
||||
FunctionDeclaration::ParamTypes types;
|
||||
const Type* returnType;
|
||||
if (!function.determineFinalTypes(arguments, &types, &returnType)) {
|
||||
std::string msg = "no match for " + std::string(function.name()) + "(";
|
||||
std::string separator ;
|
||||
for (const std::unique_ptr<Expression>& arg : arguments) {
|
||||
msg += separator;
|
||||
msg += arg->type().displayName();
|
||||
separator = ", ";
|
||||
}
|
||||
msg += ")";
|
||||
std::string msg = "no match for " + std::string(function.name()) +
|
||||
build_argument_type_list(arguments);
|
||||
context.fErrors->error(pos, msg);
|
||||
return nullptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user