OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / libs / glsl / glsllexer.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef GLSLLEXER_H
34 #define GLSLLEXER_H
35
36 #include "glsl.h"
37 #include <QtCore/qstring.h>
38 #include <QtCore/qstringlist.h>
39
40 namespace GLSL {
41
42 class GLSL_EXPORT Token
43 {
44 public:
45     int kind;
46     int position;
47     int length;
48     int line; // ### remove
49
50     union {
51         int matchingBrace;
52         int i; // integer value
53         const QString *string; // string value
54         void *ptr;
55     };
56
57     Token()
58         : kind(0), position(0), length(0), line(0), ptr(0) {}
59
60     bool is(int k) const { return k == kind; }
61     bool isNot(int k) const { return k != kind; }
62
63     int begin() const { return position; }
64     int end() const { return position + length; }
65 };
66
67 class GLSL_EXPORT Lexer
68 {
69 public:
70     Lexer(Engine *engine, const char *source, unsigned size);
71     ~Lexer();
72
73     enum
74     {
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
86     };
87
88     union Value {
89         int i;
90         const QString *string;
91         void *ptr;
92     };
93
94     Engine *engine() const { return _engine; }
95
96     int state() const { return _state; }
97     void setState(int state) { _state = state; }
98
99     int variant() const { return _variant; }
100     void setVariant(int flags) { _variant = flags; }
101
102     bool scanKeywords() const { return _scanKeywords; }
103     void setScanKeywords(bool scanKeywords) { _scanKeywords = scanKeywords; }
104
105     bool scanComments() const { return _scanComments; }
106     void setScanComments(bool scanComments) { _scanComments = scanComments; }
107
108     int yylex(Token *tk);
109     int findKeyword(const char *word, int length) const;
110
111     void *yyval() const { return _yyval.ptr; }
112
113     static QStringList keywords(int variant);
114
115 private:
116     static int classify(const char *s, int len);
117
118     void yyinp();
119     int yylex_helper(const char **position, int *line);
120
121     void warning(int line, const QString &message);
122     void error(int line, const QString &message);
123
124 private:
125     Engine *_engine;
126     const char *_source;
127     const char *_it;
128     int _size;
129     int _yychar;
130     int _lineno;
131     int _state;
132     int _variant;
133     unsigned _scanKeywords: 1;
134     unsigned _scanComments: 1;
135     Value _yyval;
136 };
137
138 } // namespace GLSL
139
140 #endif // GLSLLEXER_H