Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
debug.cpp
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2020 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
* Documents produced by Doxygen are derivative works derived from the
12
* input used in their production; they are not affected by this license.
13
*
14
*/
15
16
#include <stdarg.h>
17
#include <algorithm>
18
#include <stdio.h>
19
#include <map>
20
#include <string>
21
#include <chrono>
22
23
#include "
debug.h
"
24
#include "
message.h
"
25
#include "
qcstring.h
"
26
27
//------------------------------------------------------------------------
28
29
static
std::map< std::string, Debug::DebugMask >
s_labels
=
30
{
31
{
"preprocessor"
,
Debug::Preprocessor
},
32
{
"nolineno"
,
Debug::NoLineNo
},
33
{
"commentcnv"
,
Debug::CommentCnv
},
34
{
"commentscan"
,
Debug::CommentScan
},
35
{
"formula"
,
Debug::Formula
},
36
{
"printtree"
,
Debug::PrintTree
},
37
{
"time"
,
Debug::Time
},
38
{
"extcmd"
,
Debug::ExtCmd
},
39
{
"markdown"
,
Debug::Markdown
},
40
{
"filteroutput"
,
Debug::FilterOutput
},
41
{
"plantuml"
,
Debug::Plantuml
},
42
{
"fortranfixed2free"
,
Debug::FortranFixed2Free
},
43
{
"cite"
,
Debug::Cite
},
44
{
"rtf"
,
Debug::Rtf
},
45
{
"qhp"
,
Debug::Qhp
},
46
{
"tag"
,
Debug::Tag
},
47
{
"alias"
,
Debug::Alias
},
48
{
"entries"
,
Debug::Entries
},
49
{
"sections"
,
Debug::Sections
},
50
{
"stderr"
,
Debug::Stderr
},
51
{
"layout"
,
Debug::Layout
},
52
{
"lex"
,
Debug::Lex
},
53
{
"lex:code"
,
Debug::Lex_code
},
54
{
"lex:commentcnv"
,
Debug::Lex_commentcnv
},
55
{
"lex:commentscan"
,
Debug::Lex_commentscan
},
56
{
"lex:configimpl"
,
Debug::Lex_configimpl
},
57
{
"lex:constexp"
,
Debug::Lex_constexp
},
58
{
"lex:declinfo"
,
Debug::Lex_declinfo
},
59
{
"lex:defargs"
,
Debug::Lex_defargs
},
60
{
"lex:doctokenizer"
,
Debug::Lex_doctokenizer
},
61
{
"lex:fortrancode"
,
Debug::Lex_fortrancode
},
62
{
"lex:fortranscanner"
,
Debug::Lex_fortranscanner
},
63
{
"lex:lexcode"
,
Debug::Lex_lexcode
},
64
{
"lex:lexscanner"
,
Debug::Lex_lexscanner
},
65
{
"lex:pre"
,
Debug::Lex_pre
},
66
{
"lex:pycode"
,
Debug::Lex_pycode
},
67
{
"lex:pyscanner"
,
Debug::Lex_pyscanner
},
68
{
"lex:scanner"
,
Debug::Lex_scanner
},
69
{
"lex:sqlcode"
,
Debug::Lex_sqlcode
},
70
{
"lex:vhdlcode"
,
Debug::Lex_vhdlcode
},
71
{
"lex:xml"
,
Debug::Lex_xml
},
72
{
"lex:xmlcode"
,
Debug::Lex_xmlcode
},
73
};
74
75
//------------------------------------------------------------------------
76
static
FILE *
g_debugFile
= stdout;
77
78
Debug::DebugMask
Debug::curMask
=
Debug::Quiet
;
79
int
Debug::curPrio
= 0;
80
81
void
Debug::print_
(
DebugMask
mask,
int
prio, fmt::string_view
fmt
, fmt::format_args args)
82
{
83
if
((
curMask
&mask) && prio<=
curPrio
)
84
{
85
fmt::print(
g_debugFile
,
"{}"
,fmt::vformat(
fmt
,args));
86
}
87
}
88
89
static
char
asciiToLower
(
char
in) {
90
if
(in <=
'Z'
&& in >=
'A'
)
91
return
in -
'A'
+
'a'
;
92
return
in;
93
}
94
95
static
uint64_t
labelToEnumValue
(
const
QCString
&l)
96
{
97
std::string s = l.
str
();
98
std::transform(s.begin(),s.end(),s.begin(),
asciiToLower
);
99
auto
it =
s_labels
.find(s);
100
return
(it!=
s_labels
.end()) ? it->second :
Debug::DebugMask::Quiet
;
101
}
102
103
bool
Debug::setFlagStr
(
const
QCString
&lab)
104
{
105
uint64_t retVal =
labelToEnumValue
(lab);
106
if
(retVal ==
Debug::Stderr
)
107
{
108
g_debugFile
= stderr;
109
}
110
else
111
{
112
curMask
=
static_cast<
DebugMask
>
(
curMask
| retVal);
113
}
114
return
retVal!=0;
115
}
116
117
void
Debug::setFlag
(
const
DebugMask
mask)
118
{
119
curMask
=
static_cast<
DebugMask
>
(
curMask
| mask);
120
}
121
122
void
Debug::clearFlag
(
const
DebugMask
mask)
123
{
124
curMask
=
static_cast<
DebugMask
>
(
curMask
& ~mask);
125
}
126
127
void
Debug::setPriority
(
int
p)
128
{
129
curPrio
= p;
130
}
131
132
bool
Debug::isFlagSet
(
const
DebugMask
mask)
133
{
134
return
(
curMask
& mask)!=0;
135
}
136
137
void
Debug::printFlags
()
138
{
139
for
(
const
auto
&v :
s_labels
)
140
{
141
msg
(
"\t{}\n"
,v.first);
142
}
143
}
144
145
//------------------------------------------------------------------------
146
DebugLex::DebugLex
(
Debug::DebugMask
mask,
const
char
*lexName,
const
char
*fileName) :
m_mask
(mask),
m_lexName
(lexName),
m_fileName
(fileName)
147
{
148
print
(
m_mask
,
"Entering"
,
qPrint
(
m_lexName
),
qPrint
(
m_fileName
));
149
}
150
151
DebugLex::~DebugLex
()
152
{
153
print
(
m_mask
,
"Finished"
,
qPrint
(
m_lexName
),
qPrint
(
m_fileName
));
154
}
155
156
void
DebugLex::print
(
Debug::DebugMask
mask,
157
const
char
*state,
158
const
char
*lexName,
159
const
char
*fileName)
160
{
161
if
(!
Debug::isFlagSet
(mask))
return
;
162
163
if
(fileName && *fileName)
164
{
165
fprintf(stderr,
"%s lexical analyzer: %s (for: %s)\n"
, state, lexName, fileName);
166
}
167
else
168
{
169
fprintf(stderr,
"%s lexical analyzer: %s\n"
, state, lexName);
170
}
171
}
172
173
//------------------------------------------------------------------------
174
175
class
Timer
176
{
177
public
:
178
void
start
()
179
{
180
m_startTime
= std::chrono::steady_clock::now();
181
}
182
double
elapsedTimeS
()
183
{
184
return
static_cast<
double
>
(
185
std::chrono::duration_cast<
186
std::chrono::microseconds>(
187
std::chrono::steady_clock::now() -
m_startTime
).count()) / 1000000.0;
188
}
189
private
:
190
std::chrono::time_point<std::chrono::steady_clock>
m_startTime
;
191
};
192
193
static
Timer
g_runningTime
;
194
195
void
Debug::startTimer
()
196
{
197
g_runningTime
.start();
198
}
199
200
double
Debug::elapsedTime
()
201
{
202
return
g_runningTime
.elapsedTimeS();
203
}
204
Debug::DebugMask
DebugMask
Definition
debug.h:28
Debug::Lex_fortranscanner
@ Lex_fortranscanner
Definition
debug.h:61
Debug::Lex_doctokenizer
@ Lex_doctokenizer
Definition
debug.h:59
Debug::Lex
@ Lex
Definition
debug.h:51
Debug::Rtf
@ Rtf
Definition
debug.h:43
Debug::NoLineNo
@ NoLineNo
Definition
debug.h:42
Debug::Lex_pre
@ Lex_pre
Definition
debug.h:64
Debug::Lex_defargs
@ Lex_defargs
Definition
debug.h:58
Debug::Alias
@ Alias
Definition
debug.h:46
Debug::Lex_pycode
@ Lex_pycode
Definition
debug.h:65
Debug::Layout
@ Layout
Definition
debug.h:50
Debug::Markdown
@ Markdown
Definition
debug.h:37
Debug::Lex_declinfo
@ Lex_declinfo
Definition
debug.h:57
Debug::Tag
@ Tag
Definition
debug.h:45
Debug::Lex_lexscanner
@ Lex_lexscanner
Definition
debug.h:63
Debug::FilterOutput
@ FilterOutput
Definition
debug.h:38
Debug::Lex_sqlcode
@ Lex_sqlcode
Definition
debug.h:68
Debug::Lex_code
@ Lex_code
Definition
debug.h:52
Debug::Lex_pyscanner
@ Lex_pyscanner
Definition
debug.h:66
Debug::Cite
@ Cite
Definition
debug.h:41
Debug::ExtCmd
@ ExtCmd
Definition
debug.h:36
Debug::Sections
@ Sections
Definition
debug.h:48
Debug::PrintTree
@ PrintTree
Definition
debug.h:34
Debug::Time
@ Time
Definition
debug.h:35
Debug::Quiet
@ Quiet
Definition
debug.h:29
Debug::Lex_xml
@ Lex_xml
Definition
debug.h:70
Debug::Stderr
@ Stderr
Definition
debug.h:49
Debug::Plantuml
@ Plantuml
Definition
debug.h:39
Debug::Formula
@ Formula
Definition
debug.h:33
Debug::Lex_commentcnv
@ Lex_commentcnv
Definition
debug.h:53
Debug::Lex_vhdlcode
@ Lex_vhdlcode
Definition
debug.h:69
Debug::Lex_constexp
@ Lex_constexp
Definition
debug.h:56
Debug::Lex_xmlcode
@ Lex_xmlcode
Definition
debug.h:71
Debug::Lex_fortrancode
@ Lex_fortrancode
Definition
debug.h:60
Debug::Lex_commentscan
@ Lex_commentscan
Definition
debug.h:54
Debug::Lex_lexcode
@ Lex_lexcode
Definition
debug.h:62
Debug::Qhp
@ Qhp
Definition
debug.h:44
Debug::Entries
@ Entries
Definition
debug.h:47
Debug::Lex_configimpl
@ Lex_configimpl
Definition
debug.h:55
Debug::Preprocessor
@ Preprocessor
Definition
debug.h:30
Debug::Lex_scanner
@ Lex_scanner
Definition
debug.h:67
Debug::CommentCnv
@ CommentCnv
Definition
debug.h:31
Debug::FortranFixed2Free
@ FortranFixed2Free
Definition
debug.h:40
Debug::CommentScan
@ CommentScan
Definition
debug.h:32
Debug::printFlags
static void printFlags()
Definition
debug.cpp:137
Debug::curMask
static DebugMask curMask
Definition
debug.h:92
Debug::setPriority
static void setPriority(int p)
Definition
debug.cpp:127
Debug::curPrio
static int curPrio
Definition
debug.h:93
Debug::clearFlag
static void clearFlag(const DebugMask mask)
Definition
debug.cpp:122
Debug::isFlagSet
static bool isFlagSet(const DebugMask mask)
Definition
debug.cpp:132
Debug::elapsedTime
static double elapsedTime()
Definition
debug.cpp:200
Debug::startTimer
static void startTimer()
Definition
debug.cpp:195
Debug::setFlagStr
static bool setFlagStr(const QCString &label)
Definition
debug.cpp:103
Debug::print_
static void print_(DebugMask mask, int prio, fmt::string_view fmt, fmt::format_args args)
Definition
debug.cpp:81
Debug::setFlag
static void setFlag(const DebugMask mask)
Definition
debug.cpp:117
DebugLex::DebugLex
DebugLex(Debug::DebugMask mask, const char *lexName, const char *fileName)
Definition
debug.cpp:146
DebugLex::~DebugLex
~DebugLex()
Definition
debug.cpp:151
DebugLex::m_mask
Debug::DebugMask m_mask
Definition
debug.h:105
DebugLex::m_fileName
QCString m_fileName
Definition
debug.h:107
DebugLex::print
static void print(Debug::DebugMask mask, const char *state, const char *lexName, const char *fileName)
Definition
debug.cpp:156
DebugLex::m_lexName
QCString m_lexName
Definition
debug.h:106
QCString
This is an alternative implementation of QCString.
Definition
qcstring.h:101
QCString::str
const std::string & str() const
Definition
qcstring.h:552
Timer
Definition
debug.cpp:176
Timer::start
void start()
Definition
debug.cpp:178
Timer::m_startTime
std::chrono::time_point< std::chrono::steady_clock > m_startTime
Definition
debug.cpp:190
Timer::elapsedTimeS
double elapsedTimeS()
Definition
debug.cpp:182
g_debugFile
static FILE * g_debugFile
Definition
debug.cpp:76
g_runningTime
static Timer g_runningTime
Definition
debug.cpp:193
s_labels
static std::map< std::string, Debug::DebugMask > s_labels
Definition
debug.cpp:29
labelToEnumValue
static uint64_t labelToEnumValue(const QCString &l)
Definition
debug.cpp:95
asciiToLower
static char asciiToLower(char in)
Definition
debug.cpp:89
debug.h
message.h
msg
#define msg(fmt,...)
Definition
message.h:94
fmt
Definition
message.h:144
qcstring.h
qPrint
const char * qPrint(const char *s)
Definition
qcstring.h:687
src
debug.cpp
Generated by
1.17.0