1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "glslsymbols_p.h"
5#include "glsltypes_p.h"
6#include <QDebug>
7
8QT_BEGIN_NAMESPACE
9
10using namespace GLSL;
11
12Argument::Argument(Function *scope)
13 : Symbol(scope)
14 , _type(nullptr)
15{
16}
17
18const Type *Argument::type() const
19{
20 return _type;
21}
22
23void Argument::setType(const Type *type)
24{
25 _type = type;
26}
27
28Block::Block(Scope *enclosingScope)
29 : Scope(enclosingScope)
30{
31}
32
33QList<Symbol *> Block::members() const
34{
35 return _members.values();
36}
37
38void Block::add(Symbol *symbol)
39{
40 _members.insert(key: symbol->name(), value: symbol);
41}
42
43const Type *Block::type() const
44{
45 // ### assert?
46 return nullptr;
47}
48
49Symbol *Block::find(const QString &name) const
50{
51 return _members.value(key: name);
52}
53
54Variable::Variable(Scope *scope)
55 : Symbol(scope)
56 , _type(nullptr)
57 , _qualifiers(0)
58{
59}
60
61const Type *Variable::type() const
62{
63 return _type;
64}
65
66void Variable::setType(const Type *type)
67{
68 _type = type;
69}
70
71Namespace::Namespace()
72{
73}
74
75Namespace::~Namespace()
76{
77 qDeleteAll(c: _overloadSets);
78}
79
80QList<Symbol *> Namespace::members() const
81{
82 return _members.values();
83}
84
85void Namespace::add(Symbol *symbol)
86{
87 Symbol *&sym = _members[symbol->name()];
88 if (! sym) {
89 sym = symbol;
90 } else if (Function *fun = symbol->asFunction()) {
91 if (OverloadSet *o = sym->asOverloadSet()) {
92 o->addFunction(function: fun);
93 } else if (Function *firstFunction = sym->asFunction()) {
94 o = new OverloadSet(this);
95 _overloadSets.append(t: o);
96 o->setName(symbol->name());
97 o->addFunction(function: firstFunction);
98 o->addFunction(function: fun);
99 sym = o;
100 } else {
101 // ### warning? return false?
102 }
103 } else {
104 // ### warning? return false?
105 }
106}
107
108const Type *Namespace::type() const
109{
110 return nullptr;
111}
112
113Symbol *Namespace::find(const QString &name) const
114{
115 return _members.value(key: name);
116}
117
118QT_END_NAMESPACE
119

source code of qtquick3d/src/glslparser/glslsymbols.cpp