13bool UndefinedType::isEqualTo(
const Type *other)
const
15 if (other && other->asUndefinedType() !=
nullptr)
20bool UndefinedType::isLessThan(
const Type *other)
const
23 Q_ASSERT(other !=
nullptr);
24 Q_ASSERT(other->asUndefinedType() !=
nullptr);
28bool VoidType::isEqualTo(
const Type *other)
const
30 if (other && other->asVoidType() !=
nullptr)
35bool VoidType::isLessThan(
const Type *other)
const
38 Q_ASSERT(other !=
nullptr);
39 Q_ASSERT(other->asVoidType() !=
nullptr);
43bool BoolType::isEqualTo(
const Type *other)
const
45 if (other && other->asBoolType() !=
nullptr)
50bool BoolType::isLessThan(
const Type *other)
const
53 Q_ASSERT(other !=
nullptr);
54 Q_ASSERT(other->asBoolType() !=
nullptr);
58bool IntType::isEqualTo(
const Type *other)
const
60 if (other && other->asIntType() !=
nullptr)
65bool IntType::isLessThan(
const Type *other)
const
68 Q_ASSERT(other !=
nullptr);
69 Q_ASSERT(other->asIntType() !=
nullptr);
73bool UIntType::isEqualTo(
const Type *other)
const
75 if (other && other->asUIntType() !=
nullptr)
80bool UIntType::isLessThan(
const Type *other)
const
83 Q_ASSERT(other !=
nullptr);
84 Q_ASSERT(other->asUIntType() !=
nullptr);
88bool FloatType::isEqualTo(
const Type *other)
const
90 if (other && other->asFloatType() !=
nullptr)
95bool FloatType::isLessThan(
const Type *other)
const
98 Q_ASSERT(other !=
nullptr);
99 Q_ASSERT(other->asFloatType() !=
nullptr);
103bool DoubleType::isEqualTo(
const Type *other)
const
105 if (other && other->asDoubleType() !=
nullptr)
110bool DoubleType::isLessThan(
const Type *other)
const
113 Q_ASSERT(other !=
nullptr);
114 Q_ASSERT(other->asDoubleType() !=
nullptr);
118QString VectorType::toString()
const
120 const char *prefix =
"";
121 if (elementType()->asBoolType() !=
nullptr)
123 else if (elementType()->asIntType() !=
nullptr)
125 else if (elementType()->asUIntType() !=
nullptr)
127 else if (elementType()->asDoubleType() !=
nullptr)
129 return QString::fromLatin1(
"%1vec%2").arg(QLatin1String(prefix)).arg(_dimension);
132void VectorType::add(Symbol *symbol)
134 _members.insert(symbol->name(), symbol);
137Symbol *VectorType::find(
const QString &name)
const
139 return _members.value(name);
142void VectorType::populateMembers(Engine *engine)
144 if (_members.isEmpty()) {
145 populateMembers(engine,
"xyzw");
146 populateMembers(engine,
"rgba");
147 populateMembers(engine,
"stpq");
151void VectorType::populateMembers(Engine *engine,
const char *components)
154 for (
int x = 0; x < _dimension; ++x) {
155 const QString *name = engine->identifier(components + x, 1);
156 add(engine->newVariable(
this, *name, elementType()));
160 const Type *vec2Type;
164 vec2Type = engine->vectorType(elementType(), 2);
165 for (
int x = 0; x < _dimension; ++x) {
166 for (
int y = 0; y < _dimension; ++y) {
168 name += QLatin1Char(components[x]);
169 name += QLatin1Char(components[y]);
170 add(engine->newVariable
171 (
this, *engine->identifier(name), vec2Type));
176 const Type *vec3Type;
179 else if (_dimension < 3)
182 vec3Type = engine->vectorType(elementType(), 3);
183 for (
int x = 0; x < _dimension; ++x) {
184 for (
int y = 0; y < _dimension; ++y) {
185 for (
int z = 0; z < _dimension; ++z) {
187 name += QLatin1Char(components[x]);
188 name += QLatin1Char(components[y]);
189 name += QLatin1Char(components[z]);
190 add(engine->newVariable
191 (
this, *engine->identifier(name), vec3Type));
199 for (
int x = 0; x < _dimension; ++x) {
200 for (
int y = 0; y < _dimension; ++y) {
201 for (
int z = 0; z < _dimension; ++z) {
202 for (
int w = 0; w < _dimension; ++w) {
204 name += QLatin1Char(components[x]);
205 name += QLatin1Char(components[y]);
206 name += QLatin1Char(components[z]);
207 name += QLatin1Char(components[w]);
208 add(engine->newVariable
209 (
this, *engine->identifier(name),
this));
216bool VectorType::isEqualTo(
const Type *other)
const
219 if (
const VectorType *v = other->asVectorType()) {
220 if (_dimension != v->dimension())
222 else if (elementType() != v->elementType())
230bool VectorType::isLessThan(
const Type *other)
const
232 Q_ASSERT(other !=
nullptr);
233 const VectorType *vec = other->asVectorType();
234 Q_ASSERT(vec !=
nullptr);
235 if (_dimension < vec->dimension())
237 else if (_dimension == vec->dimension() && elementType() < vec->elementType())
242QString MatrixType::toString()
const
244 const char *prefix =
"";
245 if (elementType()->asBoolType() !=
nullptr)
247 else if (elementType()->asIntType() !=
nullptr)
249 else if (elementType()->asUIntType() !=
nullptr)
251 else if (elementType()->asDoubleType() !=
nullptr)
253 return QString::fromLatin1(
"%1mat%2x%3").arg(QLatin1String(prefix)).arg(_columns).arg(_rows);
256bool MatrixType::isEqualTo(
const Type *other)
const
259 if (
const MatrixType *v = other->asMatrixType()) {
260 if (_columns != v->columns())
262 else if (_rows != v->rows())
264 else if (_elementType != v->elementType())
272bool MatrixType::isLessThan(
const Type *other)
const
274 Q_ASSERT(other !=
nullptr);
275 const MatrixType *mat = other->asMatrixType();
276 Q_ASSERT(mat !=
nullptr);
277 if (_columns < mat->columns()) {
279 }
else if (_columns == mat->columns()) {
280 if (_rows < mat->rows())
282 else if (_rows == mat->rows() && _elementType < mat->elementType())
288QString ArrayType::toString()
const
290 return elementType()->toString() + QLatin1String(
"[]");
293bool ArrayType::isEqualTo(
const Type *other)
const
296 if (
const ArrayType *array = other->asArrayType())
297 return elementType()->isEqualTo(array->elementType());
302bool ArrayType::isLessThan(
const Type *other)
const
304 Q_ASSERT(other !=
nullptr);
305 const ArrayType *array = other->asArrayType();
306 Q_ASSERT(array !=
nullptr);
307 return elementType() < array->elementType();
310QList<Symbol *> Struct::members()
const
313 for (Symbol *s : _members) {
314 if (! s->name().isEmpty())
320void Struct::add(Symbol *member)
322 _members.append(member);
325Symbol *Struct::find(
const QString &name)
const
327 for (Symbol *s : _members) {
328 if (s->name() == name)
334bool Struct::isEqualTo(
const Type *other)
const
340bool Struct::isLessThan(
const Type *other)
const
347QString Function::toString()
const
349 return prettyPrint();
352QString Function::prettyPrint()
const
355 proto += _returnType->toString();
356 proto += QLatin1Char(
' ');
358 proto += QLatin1Char(
'(');
359 for (
int i = 0; i < _arguments.size(); ++i) {
361 proto += QLatin1String(
", ");
362 Argument *arg = _arguments.at(i);
363 proto += arg->type()->toString();
364 proto += QLatin1Char(
' ');
365 proto += arg->name();
367 proto += QLatin1Char(
')');
371const Type *Function::returnType()
const
376void Function::setReturnType(
const Type *returnType)
378 _returnType = returnType;
381QVector<Argument *> Function::arguments()
const
386void Function::addArgument(Argument *arg)
388 _arguments.append(arg);
391int Function::argumentCount()
const
393 return _arguments.size();
396Argument *Function::argumentAt(
int index)
const
398 return _arguments.at(index);
401bool Function::isEqualTo(
const Type *other)
const
407bool Function::isLessThan(
const Type *other)
const
413QList<Symbol *> Function::members()
const
416 for (Argument *arg : _arguments) {
417 if (! arg->name().isEmpty())
423Symbol *Function::find(
const QString &name)
const
425 for (Argument *arg : _arguments) {
426 if (arg->name() == name)
432QString SamplerType::toString()
const
434 return QLatin1String(Parser::spell[_kind]);
437bool SamplerType::isEqualTo(
const Type *other)
const
440 if (
const SamplerType *samp = other->asSamplerType())
441 return _kind == samp->kind();
446bool SamplerType::isLessThan(
const Type *other)
const
448 Q_ASSERT(other !=
nullptr);
449 const SamplerType *samp = other->asSamplerType();
450 Q_ASSERT(samp !=
nullptr);
451 return _kind < samp->kind();
454OverloadSet::OverloadSet(Scope *enclosingScope)
455 : Scope(enclosingScope)
459QVector<Function *> OverloadSet::functions()
const
464void OverloadSet::addFunction(Function *function)
466 _functions.append(function);
469const Type *OverloadSet::type()
const
474Symbol *OverloadSet::find(
const QString &)
const
479void OverloadSet::add(Symbol *symbol)
482 if (Function *fun = symbol->asFunction())
487bool OverloadSet::isEqualTo(
const Type *other)
const
493bool OverloadSet::isLessThan(
const Type *other)
const