Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
10
11static const char *error_msg = nullptr;
12
29void 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, msg.data());
39 } else {
40 QByteArray formatString = "%s: " + formatStringSuffix;
41 fprintf(stderr, formatString.constData(),
42 currentFilenames.top().constData(), msg.data());
43 }
44}
45
47{
48 if (sym.lineNum != -1)
49 printMsg("error: Parse error at \"%s\"\n", sym.lexem().data(), sym);
50 else
51 printMsg("error: could not parse file\n", "", sym);
52}
53
54void Parser::error(const Symbol &sym)
55{
56 defaultErrorMsg(sym);
57 exit(EXIT_FAILURE);
58}
59
60void Parser::error(const char *msg)
61{
62 if (msg || error_msg)
63 printMsg("error: %s\n",
64 msg ? msg : error_msg,
65 index > 0 ? symbol() : Symbol{});
66 else
68
69 exit(EXIT_FAILURE);
70}
71
73{
75 printMsg("warning: %s\n", msg, sym);
76}
77
78void Parser::warning(const char *msg) {
79 warning(index > 0 ? symbol() : Symbol{}, msg);
80}
81
82void Parser::note(const char *msg) {
83 if (displayNotes && msg)
84 printMsg("note: %s\n", msg, index > 0 ? symbol() : Symbol{});
85}
86
bool displayNotes
Definition parser.h:21
void warning(const char *=nullptr)
Definition parser.cpp:78
Q_NORETURN void error(const Symbol &symbol)
Definition parser.cpp:54
const Symbol & symbol()
Definition parser.h:46
void printMsg(QByteArrayView formatStringSuffix, QByteArrayView msg, const Symbol &sym)
Definition parser.cpp:29
std::stack< QByteArray, QByteArrayList > currentFilenames
Definition parser.h:32
void defaultErrorMsg(const Symbol &sym)
Definition parser.cpp:46
void note(const char *=nullptr)
Definition parser.cpp:82
bool displayWarnings
Definition parser.h:20
constexpr const_pointer data() const noexcept
\inmodule QtCore
Definition qbytearray.h:57
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
Definition qbytearray.h:611
static QT_BEGIN_NAMESPACE const char * error_msg
Definition parser.cpp:11
Combined button and popup list for selecting options.
GLuint index
[2]
int lineNum
Definition symbols.h:58
QByteArray lexem() const
Definition symbols.h:60