1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
37 #include <QtCore/qstring.h>
38 #include <QtCore/qstringlist.h>
42 class GLSL_EXPORT Token
48 int line; // ### remove
52 int i; // integer value
53 const QString *string; // string value
58 : kind(0), position(0), length(0), line(0), ptr(0) {}
60 bool is(int k) const { return k == kind; }
61 bool isNot(int k) const { return k != kind; }
63 int begin() const { return position; }
64 int end() const { return position + length; }
67 class GLSL_EXPORT Lexer
70 Lexer(Engine *engine, const char *source, unsigned size);
75 // Extra flag bits added to tokens by Lexer::classify() that
76 // indicate which variant of GLSL the keyword belongs to.
77 Variant_GLSL_120 = 0x00010000, // 1.20 and higher
78 Variant_GLSL_150 = 0x00020000, // 1.50 and higher
79 Variant_GLSL_400 = 0x00040000, // 4.00 and higher
80 Variant_GLSL_ES_100 = 0x00080000, // ES 1.00 and higher
81 Variant_VertexShader = 0x00200000,
82 Variant_FragmentShader = 0x00400000,
83 Variant_Reserved = 0x80000000,
84 Variant_Mask = 0xFFFF0000,
85 Variant_All = 0xFFFF0000
90 const QString *string;
94 Engine *engine() const { return _engine; }
96 int state() const { return _state; }
97 void setState(int state) { _state = state; }
99 int variant() const { return _variant; }
100 void setVariant(int flags) { _variant = flags; }
102 bool scanKeywords() const { return _scanKeywords; }
103 void setScanKeywords(bool scanKeywords) { _scanKeywords = scanKeywords; }
105 bool scanComments() const { return _scanComments; }
106 void setScanComments(bool scanComments) { _scanComments = scanComments; }
108 int yylex(Token *tk);
109 int findKeyword(const char *word, int length) const;
111 void *yyval() const { return _yyval.ptr; }
113 static QStringList keywords(int variant);
116 static int classify(const char *s, int len);
119 int yylex_helper(const char **position, int *line);
121 void warning(int line, const QString &message);
122 void error(int line, const QString &message);
133 unsigned _scanKeywords: 1;
134 unsigned _scanComments: 1;
140 #endif // GLSLLEXER_H