1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
38 #include <QtCore/qstring.h>
39 #include <QtCore/qstringlist.h>
43 class GLSL_EXPORT Token
49 int line; // ### remove
53 int i; // integer value
54 const QString *string; // string value
59 : kind(0), position(0), length(0), line(0), ptr(0) {}
61 bool is(int k) const { return k == kind; }
62 bool isNot(int k) const { return k != kind; }
64 int begin() const { return position; }
65 int end() const { return position + length; }
68 class GLSL_EXPORT Lexer
71 Lexer(Engine *engine, const char *source, unsigned size);
76 // Extra flag bits added to tokens by Lexer::classify() that
77 // indicate which variant of GLSL the keyword belongs to.
78 Variant_GLSL_120 = 0x00010000, // 1.20 and higher
79 Variant_GLSL_150 = 0x00020000, // 1.50 and higher
80 Variant_GLSL_400 = 0x00040000, // 4.00 and higher
81 Variant_GLSL_ES_100 = 0x00080000, // ES 1.00 and higher
82 Variant_VertexShader = 0x00200000,
83 Variant_FragmentShader = 0x00400000,
84 Variant_Reserved = 0x80000000,
85 Variant_Mask = 0xFFFF0000,
86 Variant_All = 0xFFFF0000
91 const QString *string;
95 Engine *engine() const { return _engine; }
97 int state() const { return _state; }
98 void setState(int state) { _state = state; }
100 int variant() const { return _variant; }
101 void setVariant(int flags) { _variant = flags; }
103 bool scanKeywords() const { return _scanKeywords; }
104 void setScanKeywords(bool scanKeywords) { _scanKeywords = scanKeywords; }
106 bool scanComments() const { return _scanComments; }
107 void setScanComments(bool scanComments) { _scanComments = scanComments; }
109 int yylex(Token *tk);
110 int findKeyword(const char *word, int length) const;
112 void *yyval() const { return _yyval.ptr; }
114 static QStringList keywords(int variant);
117 static int classify(const char *s, int len);
120 int yylex_helper(const char **position, int *line);
122 void warning(int line, const QString &message);
123 void error(int line, const QString &message);
134 unsigned _scanKeywords: 1;
135 unsigned _scanComments: 1;
139 } // end of namespace GLSL
141 #endif // GLSLLEXER_H