Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
parser.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4
#
include
"parser.h"
5
#
include
"utils.h"
6
#
include
<
stdio
.
h
>
7
#
include
<
stdlib
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
static
const
char
*
error_msg
=
nullptr
;
12
13
/*! \internal
14
Base implementation for printing diagnostic messages.
15
16
For example:
17
"/path/to/file:line:column: error: %s\n"
18
'%s' is replaced by \a msg. (Currently "column" is always 1).
19
20
If sym.lineNum is -1, the line and column parts aren't printed:
21
"/path/to/file: error: %s\n"
22
23
\a formatStringSuffix specifies the type of the message e.g.:
24
"error: %s\n"
25
"warning: %s\n"
26
"note: %s\n"
27
"Parse error at %s\n" (from defaultErrorMsg())
28
*/
29
void
Parser::printMsg(QByteArrayView formatStringSuffix, QByteArrayView msg,
const
Symbol
&sym)
30
{
31
if
(sym
.
lineNum
!= -1) {
32
#
ifdef
Q_CC_MSVC
33
QByteArray formatString =
"%s(%d:%d): "
+ formatStringSuffix;
34
#
else
35
QByteArray formatString =
"%s:%d:%d: "
+ formatStringSuffix;
36
#
endif
37
fprintf(stderr, formatString.constData(),
38
currentFilenames.top().constData(), sym
.
lineNum
, 1,
39
int
(msg.size()), msg.data());
40
}
else
{
41
QByteArray formatString =
"%s: "
+ formatStringSuffix;
42
fprintf(stderr, formatString.constData(),
43
currentFilenames.top().constData(),
44
int
(msg.size()), msg.data());
45
}
46
}
47
48
void
Parser::defaultErrorMsg(
const
Symbol
&sym)
49
{
50
if
(sym.lineNum != -1)
51
printMsg(
"error: Parse error at \"%.*s\"\n"
, sym.lexem(), sym);
52
else
53
printMsg(
"error: could not parse file\n"
,
""
, sym);
54
}
55
56
void
Parser::error(
const
Symbol
&sym)
57
{
58
defaultErrorMsg(sym);
59
exit(EXIT_FAILURE);
60
}
61
62
void
Parser::error(
const
char
*msg)
63
{
64
if
(msg || error_msg)
65
printMsg(
"error: %.*s\n"
,
66
msg ? msg : error_msg,
67
index > 0 ? symbol() : Symbol{});
68
else
69
defaultErrorMsg(symbol());
70
71
exit(EXIT_FAILURE);
72
}
73
74
void
Parser::error(
const
Symbol
& symbol,
const
char
*msg)
75
{
76
printMsg(
"error: %.*s\n"
, msg, symbol);
77
exit(EXIT_FAILURE);
78
}
79
80
void
Parser::warning(
const
Symbol
&sym, QByteArrayView msg)
81
{
82
if
(displayWarnings)
83
printMsg(
"warning: %.*s\n"
, msg, sym);
84
}
85
86
void
Parser::warning(
const
char
*msg) {
87
warning(index > 0 ? symbol() : Symbol{}, msg);
88
}
89
90
void
Parser::note(
const
char
*msg) {
91
if
(displayNotes && msg)
92
printMsg(
"note: %.*s\n"
, msg, index > 0 ? symbol() : Symbol{});
93
}
94
95
QT_END_NAMESPACE
error_msg
static QT_BEGIN_NAMESPACE const char * error_msg
Definition
parser.cpp:11
Symbol
Definition
symbols.h:46
Symbol::lineNum
int lineNum
Definition
symbols.h:57
qtbase
src
tools
moc
parser.cpp
Generated on
for Qt by
1.18.0