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 tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef PARSER_H |
30 | #define PARSER_H |
31 | |
32 | #include "symbols.h" |
33 | |
34 | #include <stack> |
35 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | class Parser |
39 | { |
40 | public: |
41 | Parser():index(0), displayWarnings(true), displayNotes(true) {} |
42 | Symbols symbols; |
43 | int index; |
44 | bool displayWarnings; |
45 | bool displayNotes; |
46 | |
47 | struct IncludePath |
48 | { |
49 | inline explicit IncludePath(const QByteArray &_path) |
50 | : path(_path), isFrameworkPath(false) {} |
51 | QByteArray path; |
52 | bool isFrameworkPath; |
53 | }; |
54 | QList<IncludePath> includes; |
55 | |
56 | std::stack<QByteArray, QByteArrayList> currentFilenames; |
57 | |
58 | inline bool hasNext() const { return (index < symbols.size()); } |
59 | inline Token next() { if (index >= symbols.size()) return NOTOKEN; return symbols.at(i: index++).token; } |
60 | bool test(Token); |
61 | void next(Token); |
62 | void next(Token, const char *msg); |
63 | inline void prev() {--index;} |
64 | inline Token lookup(int k = 1); |
65 | inline const Symbol &symbol_lookup(int k = 1) { return symbols.at(i: index-1+k);} |
66 | inline Token token() { return symbols.at(i: index-1).token;} |
67 | inline QByteArray lexem() { return symbols.at(i: index-1).lexem();} |
68 | inline QByteArray unquotedLexem() { return symbols.at(i: index-1).unquotedLexem();} |
69 | inline const Symbol &symbol() { return symbols.at(i: index-1);} |
70 | |
71 | Q_NORETURN void error(int rollback); |
72 | Q_NORETURN void error(const char *msg = 0); |
73 | void warning(const char * = 0); |
74 | void note(const char * = 0); |
75 | |
76 | }; |
77 | |
78 | inline bool Parser::test(Token token) |
79 | { |
80 | if (index < symbols.size() && symbols.at(i: index).token == token) { |
81 | ++index; |
82 | return true; |
83 | } |
84 | return false; |
85 | } |
86 | |
87 | inline Token Parser::lookup(int k) |
88 | { |
89 | const int l = index - 1 + k; |
90 | return l < symbols.size() ? symbols.at(i: l).token : NOTOKEN; |
91 | } |
92 | |
93 | inline void Parser::next(Token token) |
94 | { |
95 | if (!test(token)) |
96 | error(); |
97 | } |
98 | |
99 | inline void Parser::next(Token token, const char *msg) |
100 | { |
101 | if (!test(token)) |
102 | error(msg); |
103 | } |
104 | |
105 | QT_END_NAMESPACE |
106 | |
107 | #endif |
108 |