81 {
83
84
85 SkASSERT(std::all_of(
args.begin(),
args.end(), [&](
const std::unique_ptr<Expression>& arg) {
86 const Type& argType = arg->type();
87 return (argType.isScalar() || argType.isVector() || argType.isMatrix()) &&
88 (argType.componentType().matches(type.componentType()));
89 }));
90
91
93 std::accumulate(
args.begin(),
args.end(), (
size_t)0,
94 [](size_t n, const std::unique_ptr<Expression>& arg) {
95 return n + arg->type().slotCount();
96 }));
97
98
99
100
103 return std::move(
args.front());
104 }
105
107
108 if (context.fConfig->fSettings.fOptimize) {
109
110
111
112
113
114
115 int fields = 0;
116 for (
const std::unique_ptr<Expression>& arg :
args) {
119 : 1;
120 }
121
122
123
124 if (fields >
args.size()) {
125 ExpressionArray flattened;
126 flattened.reserve_exact(fields);
127 for (std::unique_ptr<Expression>& arg :
args) {
128
130 flattened.push_back(std::move(arg));
131 continue;
132 }
133
135 for (std::unique_ptr<Expression>& innerArg : compositeCtor.arguments()) {
136 flattened.push_back(std::move(innerArg));
137 }
138 }
139 args = std::move(flattened);
140 }
141 }
142
143
144
145 for (std::unique_ptr<Expression>& arg :
args) {
147 }
148
149 if (context.fConfig->fSettings.fOptimize) {
150
153 }
154 }
155
156 return std::make_unique<ConstructorCompound>(
pos,
type, std::move(
args));
157}
static std::unique_ptr< Expression > MakeConstantValueForVariable(Position pos, std::unique_ptr< Expression > expr)
ConstructorCompound(Position pos, const Type &type, ExpressionArray args)
static std::unique_ptr< Expression > Make(const Context &context, Position pos, const Type &type, std::unique_ptr< Expression > arg)
Expression(Position pos, Kind kind, const Type *type)
virtual bool isVector() const
bool isAllowedInES2(const Context &context) const
virtual bool isMatrix() const
virtual size_t slotCount() const
const Type * clone(const Context &context, SymbolTable *symbolTable) const
static const Expression * make_splat_from_arguments(const Type &type, const ExpressionArray &args)
static bool is_safe_to_eliminate(const Type &type, const Expression &arg)