Qt 6.x
The Qt SDK
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
11#ifdef USE_LEXEM_STORE
12Symbol::LexemStore Symbol::lexemStore;
13#endif
14
15static const char *error_msg = nullptr;
16
33void Parser::printMsg(QByteArrayView formatStringSuffix, QByteArrayView msg, const Symbol &sym)
34{
35 if (sym.lineNum != -1) {
36#ifdef Q_CC_MSVC
37 QByteArray formatString = "%s(%d:%d): " + formatStringSuffix;
38#else
39 QByteArray formatString = "%s:%d:%d: " + formatStringSuffix;
40#endif
41 fprintf(stderr, formatString.constData(),
42 currentFilenames.top().constData(), sym.lineNum, 1, msg.data());
43 } else {
44 QByteArray formatString = "%s: " + formatStringSuffix;
45 fprintf(stderr, formatString.constData(),
46 currentFilenames.top().constData(), msg.data());
47 }
48}
49
51{
52 if (sym.lineNum != -1)
53 printMsg("error: Parse error at \"%s\"\n", sym.lexem().data(), sym);
54 else
55 printMsg("error: could not parse file\n", "", sym);
56}
57
58void Parser::error(const Symbol &sym)
59{
60 defaultErrorMsg(sym);
61 exit(EXIT_FAILURE);
62}
63
64void Parser::error(const char *msg)
65{
66 if (msg || error_msg)
67 printMsg("error: %s\n",
68 msg ? msg : error_msg,
69 index > 0 ? symbol() : Symbol{});
70 else
72
73 exit(EXIT_FAILURE);
74}
75
77{
79 printMsg("warning: %s\n", msg, sym);
80}
81
82void Parser::warning(const char *msg) {
83 warning(index > 0 ? symbol() : Symbol{}, msg);
84}
85
86void Parser::note(const char *msg) {
87 if (displayNotes && msg)
88 printMsg("note: %s\n", msg, index > 0 ? symbol() : Symbol{});
89}
90
bool displayNotes
Definition parser.h:21
void warning(const char *=nullptr)
Definition parser.cpp:82
Q_NORETURN void error(const Symbol &symbol)
Definition parser.cpp:58
const Symbol & symbol()
Definition parser.h:46
void printMsg(QByteArrayView formatStringSuffix, QByteArrayView msg, const Symbol &sym)
Definition parser.cpp:33
std::stack< QByteArray, QByteArrayList > currentFilenames
Definition parser.h:32
void defaultErrorMsg(const Symbol &sym)
Definition parser.cpp:50
void note(const char *=nullptr)
Definition parser.cpp:86
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:534
static QT_BEGIN_NAMESPACE const char * error_msg
Definition parser.cpp:15
Combined button and popup list for selecting options.
GLuint index
[2]
int lineNum
Definition symbols.h:90
QByteArray lexem() const
Definition symbols.h:92