chromium/third_party/skia/src/sksl/ir/SkSLFunctionCall.cpp

/*
 * Copyright 2021 Google LLC
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "src/sksl/ir/SkSLFunctionCall.h"

#include "include/core/SkSpan.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkEnumBitMask.h"
#include "src/base/SkHalf.h"
#include "src/core/SkMatrixInvert.h"
#include "src/sksl/SkSLAnalysis.h"
#include "src/sksl/SkSLBuiltinTypes.h"
#include "src/sksl/SkSLConstantFolder.h"
#include "src/sksl/SkSLContext.h"
#include "src/sksl/SkSLErrorReporter.h"
#include "src/sksl/SkSLIntrinsicList.h"
#include "src/sksl/SkSLOperator.h"
#include "src/sksl/SkSLProgramSettings.h"
#include "src/sksl/SkSLString.h"
#include "src/sksl/ir/SkSLChildCall.h"
#include "src/sksl/ir/SkSLConstructor.h"
#include "src/sksl/ir/SkSLConstructorCompound.h"
#include "src/sksl/ir/SkSLFunctionDeclaration.h"
#include "src/sksl/ir/SkSLFunctionReference.h"
#include "src/sksl/ir/SkSLLayout.h"
#include "src/sksl/ir/SkSLLiteral.h"
#include "src/sksl/ir/SkSLMethodReference.h"
#include "src/sksl/ir/SkSLModifierFlags.h"
#include "src/sksl/ir/SkSLType.h"
#include "src/sksl/ir/SkSLTypeReference.h"
#include "src/sksl/ir/SkSLVariable.h"
#include "src/sksl/ir/SkSLVariableReference.h"

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <optional>
#include <string_view>

namespace SkSL {

IntrinsicArguments;

static bool has_compile_time_constant_arguments(const ExpressionArray& arguments) {}

template <typename T>
static void type_check_expression(const Expression& expr);

template <>
void type_check_expression<float>(const Expression& expr) {}

template <>
void type_check_expression<SKSL_INT>(const Expression& expr) {}

template <>
void type_check_expression<bool>(const Expression& expr) {}

CoalesceFn;
FinalizeFn;

static std::unique_ptr<Expression> coalesce_n_way_vector(const Expression* arg0,
                                                         const Expression* arg1,
                                                         double startingState,
                                                         const Type& returnType,
                                                         CoalesceFn coalesce,
                                                         FinalizeFn finalize) {}

template <typename T>
static std::unique_ptr<Expression> coalesce_vector(const IntrinsicArguments& arguments,
                                                   double startingState,
                                                   const Type& returnType,
                                                   CoalesceFn coalesce,
                                                   FinalizeFn finalize) {}

template <typename T>
static std::unique_ptr<Expression> coalesce_pairwise_vectors(const IntrinsicArguments& arguments,
                                                             double startingState,
                                                             const Type& returnType,
                                                             CoalesceFn coalesce,
                                                             FinalizeFn finalize) {}

CompareFn;

static std::unique_ptr<Expression> optimize_comparison(const Context& context,
                                                       const IntrinsicArguments& arguments,
                                                       CompareFn compare) {}

EvaluateFn;

static std::unique_ptr<Expression> evaluate_n_way_intrinsic(const Context& context,
                                                            const Expression* arg0,
                                                            const Expression* arg1,
                                                            const Expression* arg2,
                                                            const Type& returnType,
                                                            EvaluateFn eval) {}

template <typename T>
static std::unique_ptr<Expression> evaluate_intrinsic(const Context& context,
                                                      const IntrinsicArguments& arguments,
                                                      const Type& returnType,
                                                      EvaluateFn eval) {}

static std::unique_ptr<Expression> evaluate_intrinsic_numeric(const Context& context,
                                                              const IntrinsicArguments& arguments,
                                                              const Type& returnType,
                                                              EvaluateFn eval) {}

static std::unique_ptr<Expression> evaluate_pairwise_intrinsic(const Context& context,
                                                               const IntrinsicArguments& arguments,
                                                               const Type& returnType,
                                                               EvaluateFn eval) {}

static std::unique_ptr<Expression> evaluate_3_way_intrinsic(const Context& context,
                                                            const IntrinsicArguments& arguments,
                                                            const Type& returnType,
                                                            EvaluateFn eval) {}

template <typename T1, typename T2>
static double pun_value(double val) {}

// Helper functions for optimizing all of our intrinsics.
namespace Intrinsics {
namespace {

double coalesce_length(double a, double b, double)     {}
double finalize_length(double a)                       {}

double coalesce_distance(double a, double b, double c) {}
double finalize_distance(double a)                     {}

double coalesce_dot(double a, double b, double c)      {}
double coalesce_any(double a, double b, double)        {}
double coalesce_all(double a, double b, double)        {}

bool compare_lessThan(double a, double b)              {}
bool compare_lessThanEqual(double a, double b)         {}
bool compare_greaterThan(double a, double b)           {}
bool compare_greaterThanEqual(double a, double b)      {}
bool compare_equal(double a, double b)                 {}
bool compare_notEqual(double a, double b)              {}

double evaluate_radians(double a, double, double)      {}
double evaluate_degrees(double a, double, double)      {}
double evaluate_sin(double a, double, double)          {}
double evaluate_cos(double a, double, double)          {}
double evaluate_tan(double a, double, double)          {}
double evaluate_asin(double a, double, double)         {}
double evaluate_acos(double a, double, double)         {}
double evaluate_atan(double a, double, double)         {}
double evaluate_atan2(double a, double b, double)      {}
double evaluate_asinh(double a, double, double)        {}
double evaluate_acosh(double a, double, double)        {}
double evaluate_atanh(double a, double, double)        {}

double evaluate_pow(double a, double b, double)        {}
double evaluate_exp(double a, double, double)          {}
double evaluate_log(double a, double, double)          {}
double evaluate_exp2(double a, double, double)         {}
double evaluate_log2(double a, double, double)         {}
double evaluate_sqrt(double a, double, double)         {}
double evaluate_inversesqrt(double a, double, double) {}

double evaluate_add(double a, double b, double)        {}
double evaluate_sub(double a, double b, double)        {}
double evaluate_mul(double a, double b, double)        {}
double evaluate_div(double a, double b, double)        {}
double evaluate_abs(double a, double, double)          {}
double evaluate_sign(double a, double, double)         {}
double evaluate_opposite_sign(double a,double, double) {}
double evaluate_floor(double a, double, double)        {}
double evaluate_ceil(double a, double, double)         {}
double evaluate_fract(double a, double, double)        {}
double evaluate_min(double a, double b, double)        {}
double evaluate_max(double a, double b, double)        {}
double evaluate_clamp(double x, double l, double h)    {}
double evaluate_fma(double a, double b, double c)      {}
double evaluate_saturate(double a, double, double)     {}
double evaluate_mix(double x, double y, double a)      {}
double evaluate_step(double e, double x, double)       {}
double evaluate_mod(double a, double b, double) {}
double evaluate_smoothstep(double edge0, double edge1, double x) {}

double evaluate_matrixCompMult(double x, double y, double) {}

double evaluate_not(double a, double, double)          {}
double evaluate_sinh(double a, double, double)         {}
double evaluate_cosh(double a, double, double)         {}
double evaluate_tanh(double a, double, double)         {}
double evaluate_trunc(double a, double, double)        {}
double evaluate_round(double a, double, double) {}
double evaluate_floatBitsToInt(double a, double, double)  {}
double evaluate_floatBitsToUint(double a, double, double) {}
double evaluate_intBitsToFloat(double a, double, double)  {}
double evaluate_uintBitsToFloat(double a, double, double) {}

std::unique_ptr<Expression> evaluate_length(const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_distance(const IntrinsicArguments& arguments) {}
std::unique_ptr<Expression> evaluate_dot(const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_sign(const Context& context,
                                          const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_opposite_sign(const Context& context,
                                                   const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_add(const Context& context,
                                         const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_sub(const Context& context,
                                         const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_mul(const Context& context,
                                         const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_div(const Context& context,
                                         const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_normalize(const Context& context,
                                               const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_faceforward(const Context& context,
                                                 const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_reflect(const Context& context,
                                             const IntrinsicArguments& arguments) {}

std::unique_ptr<Expression> evaluate_refract(const Context& context,
                                             const IntrinsicArguments& arguments) {}

}  // namespace
}  // namespace Intrinsics

static void extract_matrix(const Expression* expr, float mat[16]) {}

static std::unique_ptr<Expression> optimize_intrinsic_call(const Context& context,
                                                           Position pos,
                                                           IntrinsicKind intrinsic,
                                                           const ExpressionArray& argArray,
                                                           const Type& returnType) {}

std::unique_ptr<Expression> FunctionCall::clone(Position pos) const {}

std::string FunctionCall::description(OperatorPrecedence) const {}

static bool argument_and_parameter_flags_match(const Expression& argument,
                                               const Variable& parameter) {}

/**
 * Used to determine the best overload for a function call by calculating the cost of coercing the
 * arguments of the function to the required types. Cost has no particular meaning other than "lower
 * costs are preferred". Returns CoercionCost::Impossible() if the call is not valid. This is never
 * called for functions with only one definition.
 */
static CoercionCost call_cost(const Context& context,
                              const FunctionDeclaration& function,
                              const ExpressionArray& arguments) {}

const FunctionDeclaration* FunctionCall::FindBestFunctionForCall(
        const Context& context,
        const FunctionDeclaration* overloadChain,
        const ExpressionArray& arguments) {}

static std::string build_argument_type_list(SkSpan<const std::unique_ptr<Expression>> arguments) {}

std::unique_ptr<Expression> FunctionCall::Convert(const Context& context,
                                                  Position pos,
                                                  std::unique_ptr<Expression> functionValue,
                                                  ExpressionArray arguments) {}

std::unique_ptr<Expression> FunctionCall::Convert(const Context& context,
                                                  Position pos,
                                                  const FunctionDeclaration& function,
                                                  ExpressionArray arguments) {}

std::unique_ptr<Expression> FunctionCall::Make(const Context& context,
                                               Position pos,
                                               const Type* returnType,
                                               const FunctionDeclaration& function,
                                               ExpressionArray arguments) {}

}  // namespace SkSL