Skip to content

Commit d2a2592

Browse files
committed
more format work, debug heap checking (msvc)
1 parent 73b53de commit d2a2592

File tree

11 files changed

+319
-90
lines changed

11 files changed

+319
-90
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ endif()
4141

4242
if (WIN32)
4343
add_definitions(
44-
-D_WIN32_WINNT=0x0601
4544
-D_CRT_SECURE_NO_WARNINGS
4645
-D_SILENCE_CXX20_CISO646_REMOVED_WARNING)
4746
if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32") # 32-bit

include/mrdox/Debug.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Vinnie Falco ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#ifndef MRDOX_DEBUG_HPP
12+
#define MRDOX_DEBUG_HPP
13+
14+
// Some nice odds and ends such as leak checking
15+
// and redirection to the Visual Studio output window.
16+
17+
namespace clang {
18+
namespace mrdox {
19+
20+
/** Enable output window redirection for standard streams.
21+
22+
This will only take effect if a debugger
23+
is attached at the time of the call.
24+
*/
25+
void
26+
debugEnableRedirecton();
27+
28+
/** Enable debug heap checking.
29+
*/
30+
void
31+
debugEnableHeapChecking();
32+
33+
} // mrdox
34+
} // clang
35+
36+
#endif

source/lib/Debug.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Vinnie Falco ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#include <mrdox/Debug.hpp>
12+
13+
#if defined(_MSC_VER) && ! defined(NDEBUG)
14+
15+
#include <iostream>
16+
#include <sstream>
17+
18+
#define WIN32_LEAN_AND_MEAN
19+
#include <windows.h>
20+
21+
namespace clang {
22+
namespace mrdox {
23+
24+
namespace {
25+
26+
class debug_streambuf
27+
: public std::stringbuf
28+
{
29+
std::ostream& os_;
30+
bool dbg_;
31+
32+
void
33+
write(char const* s)
34+
{
35+
if(dbg_)
36+
::OutputDebugStringA(s);
37+
os_ << s;
38+
}
39+
40+
public:
41+
explicit
42+
debug_streambuf(
43+
std::ostream& os)
44+
: os_(os)
45+
, dbg_(::IsDebuggerPresent() != 0)
46+
{
47+
}
48+
49+
~debug_streambuf()
50+
{
51+
sync();
52+
}
53+
54+
int sync() override
55+
{
56+
write(this->str().c_str());
57+
this->str("");
58+
return 0;
59+
}
60+
};
61+
62+
} // (anon)
63+
64+
void
65+
debugEnableRedirecton()
66+
{
67+
static debug_streambuf out(std::cout);
68+
static debug_streambuf err(std::cerr);
69+
70+
std::cout.rdbuf(&out);
71+
std::cerr.rdbuf(&err);
72+
}
73+
74+
void
75+
debugEnableHeapChecking()
76+
{
77+
#if defined(_MSC_VER) && ! defined(NDEBUG)
78+
int flags = _CrtSetDbgFlag(
79+
_CRTDBG_REPORT_FLAG);
80+
flags |= _CRTDBG_LEAK_CHECK_DF;
81+
_CrtSetDbgFlag(flags);
82+
#endif
83+
}
84+
85+
} // mrdox
86+
} // clang
87+
88+
#else
89+
90+
//------------------------------------------------
91+
92+
namespace clang {
93+
namespace mrdox {
94+
95+
void debugEnableRedirecton()
96+
{
97+
}
98+
99+
void debugEnableHeapChecking()
100+
{
101+
}
102+
103+
} // mrdox
104+
} // clang
105+
106+
#endif

source/lib/ast/ParseJavadoc.cpp

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,13 @@ class JavadocVisitor
129129
return s;
130130
}
131131

132-
template<class T, class R, class... Args>
133-
static void visit_children(
134-
ConstCommentVisitor<T, R, Args...>* visitor,
132+
template<class... Args>
133+
void visitChildren(
135134
Comment const* C)
136135
{
137136
for(auto const* it = C->child_begin();
138137
it != C->child_end(); ++it)
139-
visitor->visit(*it);
138+
visit(*it);
140139
}
141140

142141
public:
@@ -163,29 +162,48 @@ class JavadocVisitor
163162
void visitComment(
164163
Comment const* C)
165164
{
166-
visit_children(this, C);
165+
visitChildren(C);
167166
}
168167

169168
void visitTextComment(
170169
TextComment const* C)
171170
{
172-
llvm::StringRef s;
171+
llvm::StringRef s = C->getText();
173172
// If this is the very first node, the
174173
// paragraph has no doxygen command,
175174
// so we will trim the leading space.
176175
// Otherwise just trim trailing space
176+
#if 0
177177
if(para_->children.empty())
178-
s = C->getText().ltrim().rtrim();
178+
s = s.ltrim().rtrim();
179179
else
180-
s = C->getText().rtrim();
181-
//s = C->getText().ltrim().rtrim();
180+
s = s.rtrim();
181+
//s = s.ltrim().rtrim();
182+
#endif
182183

183184
// VFALCO Figure out why we get empty TextComment
184-
if(! s.empty())
185+
//if(! s.empty())
185186
Javadoc::append(*para_,
186187
Javadoc::Text(ensureUTF8(s.str())));
187188
}
188189

190+
void visitHTMLTagComment(
191+
HTMLTagComment const* C)
192+
{
193+
visitChildren(C);
194+
}
195+
196+
void visitHTMLStartTagComment(
197+
HTMLStartTagComment const* C)
198+
{
199+
visitChildren(C);
200+
}
201+
202+
void HTMLEndTagComment(
203+
HTMLStartTagComment const* C)
204+
{
205+
}
206+
189207
void visitInlineCommandComment(
190208
InlineCommandComment const* C)
191209
{
@@ -236,10 +254,10 @@ class JavadocVisitor
236254
ParagraphComment const* C)
237255
{
238256
if(para_)
239-
return visit_children(this, C);
257+
return visitChildren(C);
240258
Javadoc::Paragraph para;
241259
Scope scope(para, para_);
242-
visit_children(this, C);
260+
visitChildren(C);
243261
// VFALCO Figure out why we get empty ParagraphComment
244262
if(! para.empty())
245263
Javadoc::append(blocks_, std::move(para));
@@ -262,29 +280,29 @@ class JavadocVisitor
262280
{
263281
Javadoc::Brief brief;
264282
Scope scope(brief, para_);
265-
visit_children(this, C->getParagraph());
283+
visitChildren(C->getParagraph());
266284
Javadoc::append(blocks_, std::move(brief));
267285
return;
268286
}
269287
if(cmd->IsReturnsCommand)
270288
{
271289
Scope scope(returns_, para_);
272-
visit_children(this, C->getParagraph());
290+
visitChildren(C->getParagraph());
273291
return;
274292
}
275293
if(cmd->getID() == CommandTraits::KCI_note)
276294
{
277295
Javadoc::Admonition para(Javadoc::Admonish::note);
278296
Scope scope(para, para_);
279-
visit_children(this, C->getParagraph());
297+
visitChildren(C->getParagraph());
280298
Javadoc::append(blocks_, std::move(para));
281299
return;
282300
}
283301
if(cmd->getID() == CommandTraits::KCI_warning)
284302
{
285303
Javadoc::Admonition para(Javadoc::Admonish::warning);
286304
Scope scope(para, para_);
287-
visit_children(this, C->getParagraph());
305+
visitChildren(C->getParagraph());
288306
Javadoc::append(blocks_, std::move(para));
289307
return;
290308
}
@@ -301,7 +319,7 @@ class JavadocVisitor
301319
name = "@anon";
302320
Scope scope(para, para_);
303321
//if(C->hasNonWhitespaceParagraph())
304-
visit_children(this, C->getParagraph());
322+
visitChildren(C->getParagraph());
305323
params_.emplace_back(Javadoc::Param(
306324
std::move(name), std::move(para)));
307325
}
@@ -317,7 +335,7 @@ class JavadocVisitor
317335
name = "@anon";
318336
Scope scope(para, para_);
319337
//if(C->hasNonWhitespaceParagraph())
320-
visit_children(this, C->getParagraph());
338+
visitChildren(C->getParagraph());
321339
tparams_.emplace_back(Javadoc::TParam(
322340
std::move(name), std::move(para)));
323341
}
@@ -328,7 +346,7 @@ class JavadocVisitor
328346
Javadoc::Code code;
329347
Scope scope(code, code_);
330348
//if(C->hasNonWhitespaceParagraph())
331-
visit_children(this, C);
349+
visitChildren(C);
332350
Javadoc::append(blocks_, std::move(code));
333351
}
334352

0 commit comments

Comments
 (0)