1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSG_GLSLENGINE_H
5#define QSSG_GLSLENGINE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3DGlslParser/private/glsl_p.h>
19#include <QtQuick3DGlslParser/private/glslmemorypool_p.h>
20#include <QtQuick3DGlslParser/private/glsltypes_p.h>
21#include <qstring.h>
22
23#include <functional>
24#include <set>
25#include <unordered_set>
26
27QT_BEGIN_NAMESPACE
28
29namespace GLSL {
30
31class Q_QUICK3DGLSLPARSER_EXPORT DiagnosticMessage
32{
33public:
34 enum Kind {
35 Warning,
36 Error
37 };
38
39 DiagnosticMessage();
40
41 Kind kind() const;
42 void setKind(Kind kind);
43
44 bool isError() const;
45 bool isWarning() const;
46
47 QString fileName() const;
48 void setFileName(const QString &fileName);
49
50 int line() const;
51 void setLine(int line);
52
53 QString message() const;
54 void setMessage(const QString &message);
55
56private:
57 QString _fileName;
58 QString _message;
59 Kind _kind;
60 int _line;
61};
62
63template <typename Type>
64class TypeTable
65{
66public:
67 struct Compare {
68 bool operator()(const Type &value, const Type &other) const {
69 return value.isLessThan(&other);
70 }
71 };
72
73 const Type *intern(const Type &ty) { return &*_entries.insert(ty).first; }
74
75private:
76 std::set<Type, Compare> _entries;
77};
78
79class Q_QUICK3DGLSLPARSER_EXPORT Engine
80{
81public:
82 Engine();
83 ~Engine();
84
85 const QString *identifier(const QString &s);
86 const QString *identifier(const char *s, int n);
87 std::unordered_set<QString> identifiers() const;
88
89 const QString *number(const QString &s);
90 const QString *number(const char *s, int n);
91 std::unordered_set<QString> numbers() const;
92
93 // types
94 const UndefinedType *undefinedType();
95 const VoidType *voidType();
96 const BoolType *boolType();
97 const IntType *intType();
98 const UIntType *uintType();
99 const FloatType *floatType();
100 const DoubleType *doubleType();
101 const SamplerType *samplerType(int kind);
102 const VectorType *vectorType(const Type *elementType, int dimension);
103 const MatrixType *matrixType(const Type *elementType, int columns, int rows);
104 const ArrayType *arrayType(const Type *elementType);
105
106 // symbols
107 Namespace *newNamespace();
108 Struct *newStruct(Scope *scope = nullptr);
109 Block *newBlock(Scope *scope = nullptr);
110 Function *newFunction(Scope *scope = nullptr);
111 Argument *newArgument(Function *function, const QString &name, const Type *type);
112 Variable *newVariable(Scope *scope, const QString &name, const Type *type, int qualifiers = 0);
113
114 MemoryPool *pool();
115
116 bool blockDiagnosticMessages(bool block);
117 QList<DiagnosticMessage> diagnosticMessages() const;
118 void clearDiagnosticMessages();
119 void addDiagnosticMessage(const DiagnosticMessage &m);
120 void warning(int line, const QString &message);
121 void error(int line, const QString &message);
122
123private:
124 std::unordered_set<QString> _identifiers;
125 std::unordered_set<QString> _numbers;
126 TypeTable<VectorType> _vectorTypes;
127 TypeTable<MatrixType> _matrixTypes;
128 TypeTable<ArrayType> _arrayTypes;
129 TypeTable<SamplerType> _samplerTypes;
130 MemoryPool _pool;
131 QList<DiagnosticMessage> _diagnosticMessages;
132 QList<Symbol *> _symbols;
133 bool _blockDiagnosticMessages;
134};
135
136} // namespace GLSL
137
138QT_END_NAMESPACE
139
140#endif // QSSG_GLSLENGINE_H
141

source code of qtquick3d/src/glslparser/glslengine_p.h