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 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | using namespace GLSL; |
11 | |
12 | Argument::Argument(Function *scope) |
13 | : Symbol(scope) |
14 | , _type(nullptr) |
15 | { |
16 | } |
17 | |
18 | const Type *Argument::type() const |
19 | { |
20 | return _type; |
21 | } |
22 | |
23 | void Argument::setType(const Type *type) |
24 | { |
25 | _type = type; |
26 | } |
27 | |
28 | Block::Block(Scope *enclosingScope) |
29 | : Scope(enclosingScope) |
30 | { |
31 | } |
32 | |
33 | QList<Symbol *> Block::members() const |
34 | { |
35 | return _members.values(); |
36 | } |
37 | |
38 | void Block::add(Symbol *symbol) |
39 | { |
40 | _members.insert(key: symbol->name(), value: symbol); |
41 | } |
42 | |
43 | const Type *Block::type() const |
44 | { |
45 | // ### assert? |
46 | return nullptr; |
47 | } |
48 | |
49 | Symbol *Block::find(const QString &name) const |
50 | { |
51 | return _members.value(key: name); |
52 | } |
53 | |
54 | Variable::Variable(Scope *scope) |
55 | : Symbol(scope) |
56 | , _type(nullptr) |
57 | , _qualifiers(0) |
58 | { |
59 | } |
60 | |
61 | const Type *Variable::type() const |
62 | { |
63 | return _type; |
64 | } |
65 | |
66 | void Variable::setType(const Type *type) |
67 | { |
68 | _type = type; |
69 | } |
70 | |
71 | Namespace::Namespace() |
72 | { |
73 | } |
74 | |
75 | Namespace::~Namespace() |
76 | { |
77 | qDeleteAll(c: _overloadSets); |
78 | } |
79 | |
80 | QList<Symbol *> Namespace::members() const |
81 | { |
82 | return _members.values(); |
83 | } |
84 | |
85 | void 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 | |
108 | const Type *Namespace::type() const |
109 | { |
110 | return nullptr; |
111 | } |
112 | |
113 | Symbol *Namespace::find(const QString &name) const |
114 | { |
115 | return _members.value(key: name); |
116 | } |
117 | |
118 | QT_END_NAMESPACE |
119 |