15bool UndefinedType::isEqualTo(
const Type *other)
const
17 if (other && other->asUndefinedType() !=
nullptr)
22bool UndefinedType::isLessThan(
const Type *other)
const
25 Q_ASSERT(other !=
nullptr);
26 Q_ASSERT(other->asUndefinedType() !=
nullptr);
30bool VoidType::isEqualTo(
const Type *other)
const
32 if (other && other->asVoidType() !=
nullptr)
37bool VoidType::isLessThan(
const Type *other)
const
40 Q_ASSERT(other !=
nullptr);
41 Q_ASSERT(other->asVoidType() !=
nullptr);
45bool BoolType::isEqualTo(
const Type *other)
const
47 if (other && other->asBoolType() !=
nullptr)
52bool BoolType::isLessThan(
const Type *other)
const
55 Q_ASSERT(other !=
nullptr);
56 Q_ASSERT(other->asBoolType() !=
nullptr);
60bool IntType::isEqualTo(
const Type *other)
const
62 if (other && other->asIntType() !=
nullptr)
67bool IntType::isLessThan(
const Type *other)
const
70 Q_ASSERT(other !=
nullptr);
71 Q_ASSERT(other->asIntType() !=
nullptr);
75bool UIntType::isEqualTo(
const Type *other)
const
77 if (other && other->asUIntType() !=
nullptr)
82bool UIntType::isLessThan(
const Type *other)
const
85 Q_ASSERT(other !=
nullptr);
86 Q_ASSERT(other->asUIntType() !=
nullptr);
90bool FloatType::isEqualTo(
const Type *other)
const
92 if (other && other->asFloatType() !=
nullptr)
97bool FloatType::isLessThan(
const Type *other)
const
100 Q_ASSERT(other !=
nullptr);
101 Q_ASSERT(other->asFloatType() !=
nullptr);
105bool DoubleType::isEqualTo(
const Type *other)
const
107 if (other && other->asDoubleType() !=
nullptr)
112bool DoubleType::isLessThan(
const Type *other)
const
115 Q_ASSERT(other !=
nullptr);
116 Q_ASSERT(other->asDoubleType() !=
nullptr);
120QString VectorType::toString()
const
122 const char *prefix =
"";
123 if (elementType()->asBoolType() !=
nullptr)
125 else if (elementType()->asIntType() !=
nullptr)
127 else if (elementType()->asUIntType() !=
nullptr)
129 else if (elementType()->asDoubleType() !=
nullptr)
131 return QString::fromLatin1(
"%1vec%2").arg(QLatin1String(prefix)).arg(_dimension);
134void VectorType::add(Symbol *symbol)
136 _members.insert(symbol->name(), symbol);
139Symbol *VectorType::find(
const QString &name)
const
141 return _members.value(name);
144void VectorType::populateMembers(Engine *engine)
146 if (_members.isEmpty()) {
147 populateMembers(engine,
"xyzw");
148 populateMembers(engine,
"rgba");
149 populateMembers(engine,
"stpq");
153void VectorType::populateMembers(Engine *engine,
const char *components)
156 for (
int x = 0; x < _dimension; ++x) {
157 const QString *name = engine->identifier(components + x, 1);
158 add(engine->newVariable(
this, *name, elementType()));
162 const Type *vec2Type;
166 vec2Type = engine->vectorType(elementType(), 2);
167 for (
int x = 0; x < _dimension; ++x) {
168 for (
int y = 0; y < _dimension; ++y) {
170 name += QLatin1Char(components[x]);
171 name += QLatin1Char(components[y]);
172 add(engine->newVariable
173 (
this, *engine->identifier(name), vec2Type));
178 const Type *vec3Type;
181 else if (_dimension < 3)
184 vec3Type = engine->vectorType(elementType(), 3);
185 for (
int x = 0; x < _dimension; ++x) {
186 for (
int y = 0; y < _dimension; ++y) {
187 for (
int z = 0; z < _dimension; ++z) {
189 name += QLatin1Char(components[x]);
190 name += QLatin1Char(components[y]);
191 name += QLatin1Char(components[z]);
192 add(engine->newVariable
193 (
this, *engine->identifier(name), vec3Type));
201 for (
int x = 0; x < _dimension; ++x) {
202 for (
int y = 0; y < _dimension; ++y) {
203 for (
int z = 0; z < _dimension; ++z) {
204 for (
int w = 0; w < _dimension; ++w) {
206 name += QLatin1Char(components[x]);
207 name += QLatin1Char(components[y]);
208 name += QLatin1Char(components[z]);
209 name += QLatin1Char(components[w]);
210 add(engine->newVariable
211 (
this, *engine->identifier(name),
this));
218bool VectorType::isEqualTo(
const Type *other)
const
221 if (
const VectorType *v = other->asVectorType()) {
222 if (_dimension != v->dimension())
224 else if (elementType() != v->elementType())
232bool VectorType::isLessThan(
const Type *other)
const
234 Q_ASSERT(other !=
nullptr);
235 const VectorType *vec = other->asVectorType();
236 Q_ASSERT(vec !=
nullptr);
237 if (_dimension < vec->dimension())
239 else if (_dimension == vec->dimension() && elementType() < vec->elementType())
244QString MatrixType::toString()
const
246 const char *prefix =
"";
247 if (elementType()->asBoolType() !=
nullptr)
249 else if (elementType()->asIntType() !=
nullptr)
251 else if (elementType()->asUIntType() !=
nullptr)
253 else if (elementType()->asDoubleType() !=
nullptr)
255 return QString::fromLatin1(
"%1mat%2x%3").arg(QLatin1String(prefix)).arg(_columns).arg(_rows);
258bool MatrixType::isEqualTo(
const Type *other)
const
261 if (
const MatrixType *v = other->asMatrixType()) {
262 if (_columns != v->columns())
264 else if (_rows != v->rows())
266 else if (_elementType != v->elementType())
274bool MatrixType::isLessThan(
const Type *other)
const
276 Q_ASSERT(other !=
nullptr);
277 const MatrixType *mat = other->asMatrixType();
278 Q_ASSERT(mat !=
nullptr);
279 if (_columns < mat->columns()) {
281 }
else if (_columns == mat->columns()) {
282 if (_rows < mat->rows())
284 else if (_rows == mat->rows() && _elementType < mat->elementType())
290QString ArrayType::toString()
const
292 return elementType()->toString() + QLatin1String(
"[]");
295bool ArrayType::isEqualTo(
const Type *other)
const
298 if (
const ArrayType *array = other->asArrayType())
299 return elementType()->isEqualTo(array->elementType());
304bool ArrayType::isLessThan(
const Type *other)
const
306 Q_ASSERT(other !=
nullptr);
307 const ArrayType *array = other->asArrayType();
308 Q_ASSERT(array !=
nullptr);
309 return elementType() < array->elementType();
312QList<Symbol *> Struct::members()
const
315 for (Symbol *s : _members) {
316 if (! s->name().isEmpty())
322void Struct::add(Symbol *member)
324 _members.append(member);
327Symbol *Struct::find(
const QString &name)
const
329 for (Symbol *s : _members) {
330 if (s->name() == name)
336bool Struct::isEqualTo(
const Type *other)
const
342bool Struct::isLessThan(
const Type *other)
const
349QString Function::toString()
const
351 return prettyPrint();
354QString Function::prettyPrint()
const
357 proto += _returnType->toString();
358 proto += QLatin1Char(
' ');
360 proto += QLatin1Char(
'(');
361 for (
int i = 0; i < _arguments.size(); ++i) {
363 proto += QLatin1String(
", ");
364 Argument *arg = _arguments.at(i);
365 proto += arg->type()->toString();
366 proto += QLatin1Char(
' ');
367 proto += arg->name();
369 proto += QLatin1Char(
')');
373const Type *Function::returnType()
const
378void Function::setReturnType(
const Type *returnType)
380 _returnType = returnType;
383QVector<Argument *> Function::arguments()
const
388void Function::addArgument(Argument *arg)
390 _arguments.append(arg);
393int Function::argumentCount()
const
395 return _arguments.size();
398Argument *Function::argumentAt(
int index)
const
400 return _arguments.at(index);
403bool Function::isEqualTo(
const Type *other)
const
409bool Function::isLessThan(
const Type *other)
const
415QList<Symbol *> Function::members()
const
418 for (Argument *arg : _arguments) {
419 if (! arg->name().isEmpty())
425Symbol *Function::find(
const QString &name)
const
427 for (Argument *arg : _arguments) {
428 if (arg->name() == name)
434QString SamplerType::toString()
const
436 return QLatin1String(Parser::spell[_kind]);
439bool SamplerType::isEqualTo(
const Type *other)
const
442 if (
const SamplerType *samp = other->asSamplerType())
443 return _kind == samp->kind();
448bool SamplerType::isLessThan(
const Type *other)
const
450 Q_ASSERT(other !=
nullptr);
451 const SamplerType *samp = other->asSamplerType();
452 Q_ASSERT(samp !=
nullptr);
453 return _kind < samp->kind();
456OverloadSet::OverloadSet(Scope *enclosingScope)
457 : Scope(enclosingScope)
461QVector<Function *> OverloadSet::functions()
const
466void OverloadSet::addFunction(Function *function)
468 _functions.append(function);
471const Type *OverloadSet::type()
const
476Symbol *OverloadSet::find(
const QString &)
const
481void OverloadSet::add(Symbol *symbol)
484 if (Function *fun = symbol->asFunction())
489bool OverloadSet::isEqualTo(
const Type *other)
const
495bool OverloadSet::isLessThan(
const Type *other)
const