Debian Codegraph @

src/script/parser/qscriptsyntaxchecker.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** 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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include "qscriptsyntaxchecker_p.h"cxx . . $ `<file>/src/script/parser/qscriptsyntaxchecker_p.h`/
41
42 #include "qscriptlexer_p.h"cxx . . $ `<file>/src/script/parser/qscriptlexer_p.h`/
43 #include "qscriptparser_p.h"cxx . . $ `<file>/src/script/parser/qscriptparser_p.h`/
44
45 #include <stdlib.h>
46
47 QT_BEGIN_NAMESPACEcxx . . $ `<external>/15045578679651060896/qglobal.h:148:10`!
48
49 namespace QScriptcxx . . $ QScript/ {
50
51
52 SyntaxCheckercxx . . $ QScript/SyntaxChecker#::SyntaxCheckercxx . . $ QScript/SyntaxChecker#SyntaxChecker(49f6e7a06ebc5aa8).():
53 toscxx . . $ QScript/SyntaxChecker#tos.(0),
54 stack_sizecxx . . $ QScript/SyntaxChecker#stack_size.(0),
55 state_stackcxx . . $ QScript/SyntaxChecker#state_stack.(0)
56 {
57 }
58
59 SyntaxCheckercxx . . $ QScript/SyntaxChecker#::~cxx . . $ QScript/SyntaxChecker#`~SyntaxChecker`(49f6e7a06ebc5aa8).SyntaxCheckercxx . . $ QScript/SyntaxChecker#()
60 {
61 if (stack_sizecxx . . $ QScript/SyntaxChecker#stack_size.) {
62 freecxx . . $ free(5d22bdacc48458e8).(state_stackcxx . . $ QScript/SyntaxChecker#state_stack.);
63 }
64 }
65
66 bool SyntaxCheckercxx . . $ QScript/SyntaxChecker#::automaticcxx . . $ QScript/SyntaxChecker#automatic(eb0312c6a213be5).(QScriptcxx . . $ QScript/::Lexercxx . . $ QScript/Lexer# *lexer, int token) const
67 {
68 return token == T_RBRACEcxx . . $ QScriptGrammar#T_RBRACE. || token == 0 || lexer->prevTerminatorcxx . . $ QScript/Lexer#prevTerminator(50ce9a9e25b4a850).();
69 }
70
71 SyntaxCheckercxx . . $ QScript/SyntaxChecker#::Resultcxx . . $ QScript/SyntaxChecker#Result# SyntaxCheckercxx . . $ QScript/SyntaxChecker#::checkSyntaxcxx . . $ QScript/SyntaxChecker#checkSyntax(d85f745830e75066).(const QStringcxx . . $ QString# &code)
72 {
73 const int INITIAL_STATE = 0;
74 QScriptcxx . . $ QScript/::Lexercxx . . $ QScript/Lexer# lexercxx . . $ QScript/Lexer#Lexer(db35ed4eaf341aaa). (/*engine=*/ 0);
75 lexer.setCodecxx . . $ QScript/Lexer#setCode(29ed8fcd127906b1).(code, /*lineNo*/ 1);
76
77 int yytoken = -1;
78 int saved_yytoken = -1;
79 QStringcxx . . $ QString# error_messagecxx . . $ QString#QString(49f6e7a06ebc5aa8).;
80 int error_lineno = -1;
81 int error_column = -1;
82 Statecxx . . $ QScript/SyntaxChecker#State# checkerState = Validcxx . . $ QScript/SyntaxChecker#Valid.;
83
84 reallocateStackcxx . . $ QScript/SyntaxChecker#reallocateStack(49f6e7a06ebc5aa8).();
85
86 toscxx . . $ QScript/SyntaxChecker#tos. = 0;
87 state_stackcxx . . $ QScript/SyntaxChecker#state_stack.[++toscxx . . $ QScript/SyntaxChecker#tos.] = INITIAL_STATE;
88
89 while (true)
90 {
91 const int state = state_stackcxx . . $ QScript/SyntaxChecker#state_stack. [toscxx . . $ QScript/SyntaxChecker#tos.];
92 if (yytoken == -1 && - TERMINAL_COUNTcxx . . $ QScriptGrammar#TERMINAL_COUNT. != action_indexcxx . . $ QScriptGrammar#action_index. [state])
93 {
94 if (saved_yytoken == -1)
95 yytoken = lexer.lexcxx . . $ QScript/Lexer#lex(b126dc7c1de90089).();
96 else
97 {
98 yytoken = saved_yytoken;
99 saved_yytoken = -1;
100 }
101 }
102
103 int act = t_actioncxx . . $ QScriptGrammar#t_action(9b79fb6aee4c0440). (state, yytoken);
104
105 if (act == ACCEPT_STATEcxx . . $ QScriptGrammar#ACCEPT_STATE.) {
106 if (lexer.errorcxx . . $ QScript/Lexer#error(980933249e9d8679).() == QScriptcxx . . $ QScript/::Lexercxx . . $ QScript/Lexer#::UnclosedCommentcxx . . $ QScript/Lexer#UnclosedComment.)
107 checkerState = Intermediatecxx . . $ QScript/SyntaxChecker#Intermediate.;
108 else
109 checkerState = Validcxx . . $ QScript/SyntaxChecker#Valid.;
110 break;
111 } else if (act > 0) {
112 if (++toscxx . . $ QScript/SyntaxChecker#tos. == stack_sizecxx . . $ QScript/SyntaxChecker#stack_size.)
113 reallocateStackcxx . . $ QScript/SyntaxChecker#reallocateStack(49f6e7a06ebc5aa8).();
114
115 state_stackcxx . . $ QScript/SyntaxChecker#state_stack. [toscxx . . $ QScript/SyntaxChecker#tos.] = act;
116 yytoken = -1;
117 }
118
119 else if (act < 0)
120 {
121 int r = - act - 1;
122
123 toscxx . . $ QScript/SyntaxChecker#tos. -= rhscxx . . $ QScriptGrammar#rhs. [r];
124 act = state_stackcxx . . $ QScript/SyntaxChecker#state_stack. [toscxx . . $ QScript/SyntaxChecker#tos.++];
125
126 if ((r == Q_SCRIPT_REGEXPLITERAL_RULE1cxx . . $ `src/script/parser/qscriptparser_p.h:158:9`!)
127 || (r == Q_SCRIPT_REGEXPLITERAL_RULE2cxx . . $ `src/script/parser/qscriptparser_p.h:160:9`!)) {
128 // Skip the rest of the RegExp literal
129 bool rx = lexer.scanRegExpcxx . . $ QScript/Lexer#scanRegExp(2cccee15db90ba46).();
130 if (!rx) {
131 checkerState = Intermediatecxx . . $ QScript/SyntaxChecker#Intermediate.;
132 break;
133 }
134 }
135
136 state_stackcxx . . $ QScript/SyntaxChecker#state_stack. [toscxx . . $ QScript/SyntaxChecker#tos.] = nt_actioncxx . . $ QScriptGrammar#nt_action(9b79fb6aee4c0440). (act, lhscxx . . $ QScriptGrammar#lhs. [r] - TERMINAL_COUNTcxx . . $ QScriptGrammar#TERMINAL_COUNT.);
137 }
138
139 else
140 {
141 if (saved_yytoken == -1 && automaticcxx . . $ QScript/SyntaxChecker#automatic(eb0312c6a213be5). (&lexer, yytoken) && t_actioncxx . . $ QScriptGrammar#t_action(9b79fb6aee4c0440). (state, T_AUTOMATIC_SEMICOLONcxx . . $ QScriptGrammar#T_AUTOMATIC_SEMICOLON.) > 0)
142 {
143 saved_yytoken = yytoken;
144 yytoken = T_SEMICOLONcxx . . $ QScriptGrammar#T_SEMICOLON.;
145 continue;
146 }
147
148 else if ((state == INITIAL_STATE) && (yytoken == 0)) {
149 // accept empty input
150 yytoken = T_SEMICOLONcxx . . $ QScriptGrammar#T_SEMICOLON.;
151 continue;
152 }
153
154 int ers = state;
155 int shifts = 0;
156 int reduces = 0;
157 int expected_tokens [3];
158 for (int tk = 0; tk < TERMINAL_COUNTcxx . . $ QScriptGrammar#TERMINAL_COUNT.; ++tk)
159 {
160 int k = t_actioncxx . . $ QScriptGrammar#t_action(9b79fb6aee4c0440). (ers, tk);
161
162 if (! k)
163 continue;
164 else if (k < 0)
165 ++reduces;
166 else if (spellcxx . . $ QScriptGrammar#spell. [tk])
167 {
168 if (shifts < 3)
169 expected_tokens [shifts] = tk;
170 ++shifts;
171 }
172 }
173
174 error_message.clearcxx . . $ QString#clear(49f6e7a06ebc5aa8). ();
175 if (shifts && shifts < 3)
176 {
177 bool first = true;
178
179 for (int s = 0; s < shifts; ++s)
180 {
181 if (first)
182 error_message +=cxx . . $ QString#`operator+=`(10913c921d46e09a). QLatin1Stringcxx . . $ QLatin1String#QLatin1String(85c52e162fed56f9). ("Expected ");
183 else
184 error_message +=cxx . . $ QString#`operator+=`(10913c921d46e09a). QLatin1Stringcxx . . $ QLatin1String#QLatin1String(85c52e162fed56f9). (", ");
185
186 first = false;
187 error_message +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). QLatin1Charcxx . . $ QChar#QChar(3c55a7a0aea1b63a).('`');
188 error_message +=cxx . . $ QString#`operator+=`(10913c921d46e09a). QLatin1Stringcxx . . $ QLatin1String#QLatin1String(85c52e162fed56f9). (spellcxx . . $ QScriptGrammar#spell. [expected_tokens [s]]);
189 error_message +=cxx . . $ QString#`operator+=`(3a2ffbdf8ecc25e2). QLatin1Charcxx . . $ QChar#QChar(3c55a7a0aea1b63a).('\'');
190 }
191 }
192
193 if (error_message.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).())
194 error_message =cxx . . $ QString#`operator=`(7b76e6691bca1027). lexer.errorMessagecxx . . $ QScript/Lexer#errorMessage(6ef7b6c27b00b43d).();
195
196 error_lineno = lexer.startLineNocxx . . $ QScript/Lexer#startLineNo(455f465bc33b4cdf).();
197 error_column = lexer.startColumnNocxx . . $ QScript/Lexer#startColumnNo(455f465bc33b4cdf).();
198 checkerState = Errorcxx . . $ QScript/SyntaxChecker#Error.;
199 break;
200 }
201 }
202
203 if (checkerState == Errorcxx . . $ QScript/SyntaxChecker#Error.) {
204 if (lexer.errorcxx . . $ QScript/Lexer#error(980933249e9d8679).() == QScriptcxx . . $ QScript/::Lexercxx . . $ QScript/Lexer#::UnclosedCommentcxx . . $ QScript/Lexer#UnclosedComment.)
205 checkerState = Intermediatecxx . . $ QScript/SyntaxChecker#Intermediate.;
206 else if (yytoken == 0)
207 checkerState = Intermediatecxx . . $ QScript/SyntaxChecker#Intermediate.;
208 }
209 return Resultcxx . . $ QScript/SyntaxChecker#Result#Result(3b6f3d3f1a8743f1).(checkerState, error_lineno, error_column, error_message);
210 }
211
212 } // namespace QScript
213
214 QT_END_NAMESPACEcxx . . $ `<external>/15045578679651060896/qglobal.h:149:10`!