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
{
"mermaid"
,
Debug::Mermaid
},
53
{
"lex"
,
Debug::Lex
},
54
{
"lex:code"
,
Debug::Lex_code
},
55
{
"lex:commentcnv"
,
Debug::Lex_commentcnv
},
56
{
"lex:commentscan"
,
Debug::Lex_commentscan
},
57
{
"lex:configimpl"
,
Debug::Lex_configimpl
},
58
{
"lex:constexp"
,
Debug::Lex_constexp
},
59
{
"lex:declinfo"
,
Debug::Lex_declinfo
},
60
{
"lex:defargs"
,
Debug::Lex_defargs
},
61
{
"lex:doctokenizer"
,
Debug::Lex_doctokenizer
},
62
{
"lex:fortrancode"
,
Debug::Lex_fortrancode
},
63
{
"lex:fortranscanner"
,
Debug::Lex_fortranscanner
},
64
{
"lex:lexcode"
,
Debug::Lex_lexcode
},
65
{
"lex:lexscanner"
,
Debug::Lex_lexscanner
},
66
{
"lex:pre"
,
Debug::Lex_pre
},
67
{
"lex:pycode"
,
Debug::Lex_pycode
},
68
{
"lex:pyscanner"
,
Debug::Lex_pyscanner
},
69
{
"lex:scanner"
,
Debug::Lex_scanner
},
70
{
"lex:sqlcode"
,
Debug::Lex_sqlcode
},
71
{
"lex:vhdlcode"
,
Debug::Lex_vhdlcode
},
72
{
"lex:xml"
,
Debug::Lex_xml
},
73
{
"lex:xmlcode"
,
Debug::Lex_xmlcode
},
74
};
75
76
//------------------------------------------------------------------------
77
static
FILE *
g_debugFile
= stdout;
78
79
Debug::DebugMask
Debug::curMask
=
Debug::Quiet
;
80
int
Debug::curPrio
= 0;
81
82
void
Debug::print_
(
DebugMask
mask,
int
prio, fmt::string_view
fmt
, fmt::format_args args)
83
{
84
if
((
curMask
&mask) && prio<=
curPrio
)
85
{
86
fmt::print(
g_debugFile
,
"{}"
,fmt::vformat(
fmt
,args));
87
}
88
}
89
90
static
char
asciiToLower
(
char
in) {
91
if
(in <=
'Z'
&& in >=
'A'
)
92
return
in -
'A'
+
'a'
;
93
return
in;
94
}
95
96
static
uint64_t
labelToEnumValue
(
const
QCString
&l)
97
{
98
std::string s = l.
str
();
99
std::transform(s.begin(),s.end(),s.begin(),
asciiToLower
);
100
auto
it =
s_labels
.find(s);
101
return
(it!=
s_labels
.end()) ? it->second :
Debug::DebugMask::Quiet
;
102
}
103
104
bool
Debug::setFlagStr
(
const
QCString
&lab)
105
{
106
uint64_t retVal =
labelToEnumValue
(lab);
107
if
(retVal ==
Debug::Stderr
)
108
{
109
g_debugFile
= stderr;
110
}
111
else
112
{
113
curMask
=
static_cast<
DebugMask
>
(
curMask
| retVal);
114
}
115
return
retVal!=0;
116
}
117
118
void
Debug::setFlag
(
const
DebugMask
mask)
119
{
120
curMask
=
static_cast<
DebugMask
>
(
curMask
| mask);
121
}
122
123
void
Debug::clearFlag
(
const
DebugMask
mask)
124
{
125
curMask
=
static_cast<
DebugMask
>
(
curMask
& ~mask);
126
}
127
128
void
Debug::setPriority
(
int
p)
129
{
130
curPrio
= p;
131
}
132
133
bool
Debug::isFlagSet
(
const
DebugMask
mask)
134
{
135
return
(
curMask
& mask)!=0;
136
}
137
138
void
Debug::printFlags
()
139
{
140
for
(
const
auto
&v :
s_labels
)
141
{
142
msg
(
"\t{}\n"
,v.first);
143
}
144
}
145
146
//------------------------------------------------------------------------
147
DebugLex::DebugLex
(
Debug::DebugMask
mask,
const
char
*lexName,
const
char
*fileName) :
m_mask
(mask),
m_lexName
(lexName),
m_fileName
(fileName)
148
{
149
print
(
m_mask
,
"Entering"
,
qPrint
(
m_lexName
),
qPrint
(
m_fileName
));
150
}
151
152
DebugLex::~DebugLex
()
153
{
154
print
(
m_mask
,
"Finished"
,
qPrint
(
m_lexName
),
qPrint
(
m_fileName
));
155
}
156
157
void
DebugLex::print
(
Debug::DebugMask
mask,
158
const
char
*state,
159
const
char
*lexName,
160
const
char
*fileName)
161
{
162
if
(!
Debug::isFlagSet
(mask))
return
;
163
164
if
(fileName && *fileName)
165
{
166
fprintf(stderr,
"%s lexical analyzer: %s (for: %s)\n"
, state, lexName, fileName);
167
}
168
else
169
{
170
fprintf(stderr,
"%s lexical analyzer: %s\n"
, state, lexName);
171
}
172
}
173
174
//------------------------------------------------------------------------
175
176
class
Timer
177
{
178
public
:
179
void
start
()
180
{
181
m_startTime
= std::chrono::steady_clock::now();
182
}
183
double
elapsedTimeS
()
184
{
185
return
static_cast<
double
>
(
186
std::chrono::duration_cast<
187
std::chrono::microseconds>(
188
std::chrono::steady_clock::now() -
m_startTime
).count()) / 1000000.0;
189
}
190
private
:
191
std::chrono::time_point<std::chrono::steady_clock>
m_startTime
;
192
};
193
194
static
Timer
g_runningTime
;
195
196
void
Debug::startTimer
()
197
{
198
g_runningTime
.start();
199
}
200
201
double
Debug::elapsedTime
()
202
{
203
return
g_runningTime
.elapsedTimeS();
204
}
205
Debug::DebugMask
DebugMask
Definition
debug.h:28
Debug::Lex_fortranscanner
@ Lex_fortranscanner
Definition
debug.h:62
Debug::Lex_doctokenizer
@ Lex_doctokenizer
Definition
debug.h:60
Debug::Lex
@ Lex
Definition
debug.h:52
Debug::Rtf
@ Rtf
Definition
debug.h:43
Debug::NoLineNo
@ NoLineNo
Definition
debug.h:42
Debug::Mermaid
@ Mermaid
Definition
debug.h:51
Debug::Lex_pre
@ Lex_pre
Definition
debug.h:65
Debug::Lex_defargs
@ Lex_defargs
Definition
debug.h:59
Debug::Alias
@ Alias
Definition
debug.h:46
Debug::Lex_pycode
@ Lex_pycode
Definition
debug.h:66
Debug::Layout
@ Layout
Definition
debug.h:50
Debug::Markdown
@ Markdown
Definition
debug.h:37
Debug::Lex_declinfo
@ Lex_declinfo
Definition
debug.h:58
Debug::Tag
@ Tag
Definition
debug.h:45
Debug::Lex_lexscanner
@ Lex_lexscanner
Definition
debug.h:64
Debug::FilterOutput
@ FilterOutput
Definition
debug.h:38
Debug::Lex_sqlcode
@ Lex_sqlcode
Definition
debug.h:69
Debug::Lex_code
@ Lex_code
Definition
debug.h:53
Debug::Lex_pyscanner
@ Lex_pyscanner
Definition
debug.h:67
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:71
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:54
Debug::Lex_vhdlcode
@ Lex_vhdlcode
Definition
debug.h:70
Debug::Lex_constexp
@ Lex_constexp
Definition
debug.h:57
Debug::Lex_xmlcode
@ Lex_xmlcode
Definition
debug.h:72
Debug::Lex_fortrancode
@ Lex_fortrancode
Definition
debug.h:61
Debug::Lex_commentscan
@ Lex_commentscan
Definition
debug.h:55
Debug::Lex_lexcode
@ Lex_lexcode
Definition
debug.h:63
Debug::Qhp
@ Qhp
Definition
debug.h:44
Debug::Entries
@ Entries
Definition
debug.h:47
Debug::Lex_configimpl
@ Lex_configimpl
Definition
debug.h:56
Debug::Preprocessor
@ Preprocessor
Definition
debug.h:30
Debug::Lex_scanner
@ Lex_scanner
Definition
debug.h:68
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:138
Debug::curMask
static DebugMask curMask
Definition
debug.h:93
Debug::setPriority
static void setPriority(int p)
Definition
debug.cpp:128
Debug::curPrio
static int curPrio
Definition
debug.h:94
Debug::clearFlag
static void clearFlag(const DebugMask mask)
Definition
debug.cpp:123
Debug::isFlagSet
static bool isFlagSet(const DebugMask mask)
Definition
debug.cpp:133
Debug::elapsedTime
static double elapsedTime()
Definition
debug.cpp:201
Debug::startTimer
static void startTimer()
Definition
debug.cpp:196
Debug::setFlagStr
static bool setFlagStr(const QCString &label)
Definition
debug.cpp:104
Debug::print_
static void print_(DebugMask mask, int prio, fmt::string_view fmt, fmt::format_args args)
Definition
debug.cpp:82
Debug::setFlag
static void setFlag(const DebugMask mask)
Definition
debug.cpp:118
DebugLex::DebugLex
DebugLex(Debug::DebugMask mask, const char *lexName, const char *fileName)
Definition
debug.cpp:147
DebugLex::~DebugLex
~DebugLex()
Definition
debug.cpp:152
DebugLex::m_mask
Debug::DebugMask m_mask
Definition
debug.h:106
DebugLex::m_fileName
QCString m_fileName
Definition
debug.h:108
DebugLex::print
static void print(Debug::DebugMask mask, const char *state, const char *lexName, const char *fileName)
Definition
debug.cpp:157
DebugLex::m_lexName
QCString m_lexName
Definition
debug.h:107
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:177
Timer::start
void start()
Definition
debug.cpp:179
Timer::m_startTime
std::chrono::time_point< std::chrono::steady_clock > m_startTime
Definition
debug.cpp:191
Timer::elapsedTimeS
double elapsedTimeS()
Definition
debug.cpp:183
g_debugFile
static FILE * g_debugFile
Definition
debug.cpp:77
g_runningTime
static Timer g_runningTime
Definition
debug.cpp:194
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:96
asciiToLower
static char asciiToLower(char in)
Definition
debug.cpp:90
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