1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtXmlPatterns 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 <QtGlobal> |
41 | |
42 | #include "qexpression_p.h" |
43 | #include "qstaticcontext_p.h" |
44 | #include "qtokenizer_p.h" |
45 | |
46 | #include "qparsercontext_p.h" |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | using namespace QPatternist; |
51 | |
52 | ParserContext::ParserContext(const StaticContext::Ptr &context, |
53 | const QXmlQuery::QueryLanguage lang, |
54 | Tokenizer *const tokener) : staticContext(context) |
55 | , tokenizer(tokener) |
56 | , languageAccent(lang) |
57 | , nodeTestSource(BuiltinTypes::element) |
58 | , moduleNamespace(StandardNamespaces::empty) |
59 | , isPreviousEnclosedExpr(false) |
60 | , elementConstructorDepth(0) |
61 | , hasSecondPrologPart(false) |
62 | , preserveNamespacesMode(true) |
63 | , inheritNamespacesMode(true) |
64 | , isParsingPattern(false) |
65 | , currentImportPrecedence(1) |
66 | , m_evaluationCacheSlot(-1) |
67 | , m_expressionSlot(0) |
68 | , m_positionSlot(-1) |
69 | , m_globalVariableSlot(-1) |
70 | , m_currentTemplateID(InitialTemplateID) |
71 | { |
72 | resolvers.push(t: context->namespaceBindings()); |
73 | Q_ASSERT(tokenizer); |
74 | Q_ASSERT(context); |
75 | m_isParsingWithParam.push(t: false); |
76 | isBackwardsCompat.push(t: false); |
77 | } |
78 | |
79 | void ParserContext::finalizePushedVariable(const int amount, |
80 | const bool shouldPop) |
81 | { |
82 | for(int i = 0; i < amount; ++i) |
83 | { |
84 | const VariableDeclaration::Ptr var(shouldPop ? variables.pop() : variables.top()); |
85 | Q_ASSERT(var); |
86 | |
87 | if(var->isUsed()) |
88 | continue; |
89 | else |
90 | { |
91 | staticContext->warning(message: QtXmlPatterns::tr(sourceText: "The variable %1 is unused" ) |
92 | .arg(a: formatKeyword(var, np: staticContext->namePool()))); |
93 | } |
94 | } |
95 | } |
96 | |
97 | void ParserContext::handleStackOverflow(const char *, short **yyss, size_t, |
98 | TokenValue **yyvs, size_t, |
99 | XPATHLTYPE **yyls, size_t, |
100 | size_t *yystacksize) |
101 | { |
102 | bool isFirstTime = parserStack_yyvs.isEmpty(); |
103 | Q_ASSERT(*yystacksize < INT_MAX - 50); |
104 | int new_yystacksize = static_cast<int>(*yystacksize) + 50; |
105 | parserStack_yyss.resize(asize: new_yystacksize); |
106 | parserStack_yyvs.resize(asize: new_yystacksize); |
107 | parserStack_yyls.resize(asize: new_yystacksize); |
108 | if (isFirstTime) { |
109 | for (int i = 0, ei = static_cast<int>(*yystacksize); i != ei; ++i) { |
110 | parserStack_yyss[i] = (*yyss)[i]; |
111 | parserStack_yyvs[i] = (*yyvs)[i]; |
112 | parserStack_yyls[i] = (*yyls)[i]; |
113 | } |
114 | } |
115 | *yyss = parserStack_yyss.data(); |
116 | *yyvs = parserStack_yyvs.data(); |
117 | *yyls = parserStack_yyls.data(); |
118 | *yystacksize = new_yystacksize; |
119 | } |
120 | |
121 | QT_END_NAMESPACE |
122 | |
123 | |