Skip to content

Commit aab7f1f

Browse files
committed
run clang-format over file
Change-Id: I3ca0cdc66479ad753c5bf57a7b7507487e025b77
1 parent 0f85449 commit aab7f1f

1 file changed

Lines changed: 122 additions & 65 deletions

File tree

generator/generator.cpp

Lines changed: 122 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,49 @@
2020
****************************************************************************/
2121

2222
#include "generator.h"
23-
#include "stringbuilder.h"
2423
#include "filesystem.h"
24+
#include "stringbuilder.h"
2525

2626
#include "../global.h"
2727

28+
#include <clang/Basic/Version.h>
2829
#include <fstream>
2930
#include <iostream>
30-
#include <llvm/Support/raw_ostream.h>
31-
#include <llvm/Support/FileSystem.h>
3231
#include <llvm/ADT/StringExtras.h>
33-
#include <clang/Basic/Version.h>
32+
#include <llvm/Support/FileSystem.h>
33+
#include <llvm/Support/raw_ostream.h>
3434

3535
template<int N>
36-
static void bufferAppend(llvm::SmallVectorImpl<char> &buffer, const char (&val)[N]) {
36+
static void bufferAppend(llvm::SmallVectorImpl<char> &buffer, const char (&val)[N])
37+
{
3738
buffer.append(val, val + N - 1);
3839
}
3940

40-
llvm::StringRef Generator::escapeAttr(llvm::StringRef s, llvm::SmallVectorImpl< char >& buffer)
41+
llvm::StringRef Generator::escapeAttr(llvm::StringRef s, llvm::SmallVectorImpl<char> &buffer)
4142
{
4243
buffer.clear();
4344
unsigned len = s.size();
44-
for (unsigned i = 0 ; i < len; ++i) {
45+
for (unsigned i = 0; i < len; ++i) {
4546
char c = s[i];
4647
switch (c) {
47-
default: buffer.push_back(c); break;
48-
case '<': bufferAppend(buffer, "&lt;"); break;
49-
case '>': bufferAppend(buffer, "&gt;"); break;
50-
case '&': bufferAppend(buffer, "&amp;"); break;
51-
case '\"': bufferAppend(buffer, "&quot;"); break;
52-
case '\'': bufferAppend(buffer, "&apos;"); break;
48+
default:
49+
buffer.push_back(c);
50+
break;
51+
case '<':
52+
bufferAppend(buffer, "&lt;");
53+
break;
54+
case '>':
55+
bufferAppend(buffer, "&gt;");
56+
break;
57+
case '&':
58+
bufferAppend(buffer, "&amp;");
59+
break;
60+
case '\"':
61+
bufferAppend(buffer, "&quot;");
62+
break;
63+
case '\'':
64+
bufferAppend(buffer, "&apos;");
65+
break;
5366
}
5467
}
5568
return llvm::StringRef(buffer.begin(), buffer.size());
@@ -58,32 +71,48 @@ llvm::StringRef Generator::escapeAttr(llvm::StringRef s, llvm::SmallVectorImpl<
5871
void Generator::escapeAttr(llvm::raw_ostream &os, llvm::StringRef s)
5972
{
6073
unsigned len = s.size();
61-
for (unsigned i = 0 ; i < len; ++i) {
74+
for (unsigned i = 0; i < len; ++i) {
6275
char c = s[i];
6376
switch (c) {
64-
default:
65-
os << c; break;
66-
67-
case '<': os << "&lt;"; break;
68-
case '>': os << "&gt;"; break;
69-
case '&': os << "&amp;"; break;
70-
case '\"': os << "&quot;"; break;
71-
case '\'': os << "&apos;"; break;
77+
default:
78+
os << c;
79+
break;
80+
81+
case '<':
82+
os << "&lt;";
83+
break;
84+
case '>':
85+
os << "&gt;";
86+
break;
87+
case '&':
88+
os << "&amp;";
89+
break;
90+
case '\"':
91+
os << "&quot;";
92+
break;
93+
case '\'':
94+
os << "&apos;";
95+
break;
7296
}
7397
}
74-
7598
}
7699

77-
// ATTENTION: Keep in sync with `replace_invalid_filename_chars` functions in filesystem.cpp and in .js files
78-
llvm::StringRef Generator::escapeAttrForFilename(llvm::StringRef s, llvm::SmallVectorImpl< char >& buffer)
100+
// ATTENTION: Keep in sync with `replace_invalid_filename_chars` functions in filesystem.cpp and in
101+
// .js files
102+
llvm::StringRef Generator::escapeAttrForFilename(llvm::StringRef s,
103+
llvm::SmallVectorImpl<char> &buffer)
79104
{
80105
buffer.clear();
81106
unsigned len = s.size();
82-
for (unsigned i = 0 ; i < len; ++i) {
107+
for (unsigned i = 0; i < len; ++i) {
83108
char c = s[i];
84109
switch (c) {
85-
default: buffer.push_back(c); break;
86-
case ':': bufferAppend(buffer, "."); break;
110+
default:
111+
buffer.push_back(c);
112+
break;
113+
case ':':
114+
bufferAppend(buffer, ".");
115+
break;
87116
}
88117
}
89118
return llvm::StringRef(buffer.begin(), buffer.size());
@@ -100,7 +129,8 @@ void Generator::Tag::open(llvm::raw_ostream &myfile) const
100129
if (!innerHtml.empty())
101130
myfile << innerHtml;
102131
} else {
103-
// Unfortunately, html5 won't allow <a /> or <span /> tags, they need to be explicitly closed
132+
// Unfortunately, html5 won't allow <a /> or <span /> tags, they need to be explicitly
133+
// closed
104134
// myfile << "/>";
105135
if (!innerHtml.empty())
106136
myfile << ">" << innerHtml << "</" << name << ">";
@@ -114,8 +144,9 @@ void Generator::Tag::close(llvm::raw_ostream &myfile) const
114144
myfile << "</" << name << ">";
115145
}
116146

117-
void Generator::generate(llvm::StringRef outputPrefix, std::string dataPath, const std::string &filename,
118-
const char* begin, const char* end, llvm::StringRef footer, llvm::StringRef warningMessage,
147+
void Generator::generate(llvm::StringRef outputPrefix, std::string dataPath,
148+
const std::string &filename, const char *begin, const char *end,
149+
llvm::StringRef footer, llvm::StringRef warningMessage,
119150
const std::set<std::string> &interestingDefinitions)
120151
{
121152
std::string real_filename = outputPrefix % "/" % filename % ".html";
@@ -140,32 +171,42 @@ void Generator::generate(llvm::StringRef outputPrefix, std::string dataPath, con
140171
dataPath = root_path % "/" % dataPath;
141172

142173
myfile << "<!doctype html>\n" // Use HTML 5 doctype
143-
"<html>\n<head>\n";
174+
"<html>\n<head>\n";
144175
myfile << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">";
145-
myfile << "<title>" << llvm::StringRef(filename).rsplit('/').second.str() << " source code [" << filename << "] - Woboq Code Browser</title>\n";
176+
myfile << "<title>" << llvm::StringRef(filename).rsplit('/').second.str() << " source code ["
177+
<< filename << "] - Woboq Code Browser</title>\n";
146178
if (interestingDefinitions.size() > 0) {
147-
std::string interestingDefitionsStr = llvm::join(interestingDefinitions.begin(), interestingDefinitions.end(), ",");
148-
myfile << "<meta name=\"woboq:interestingDefinitions\" content=\"" << interestingDefitionsStr << " \"/>\n";
179+
std::string interestingDefitionsStr =
180+
llvm::join(interestingDefinitions.begin(), interestingDefinitions.end(), ",");
181+
myfile << "<meta name=\"woboq:interestingDefinitions\" content=\""
182+
<< interestingDefitionsStr << " \"/>\n";
149183
}
150-
myfile << "<link rel=\"stylesheet\" href=\"" << dataPath << "/qtcreator.css\" title=\"QtCreator\"/>\n";
151-
myfile << "<link rel=\"alternate stylesheet\" href=\"" << dataPath << "/kdevelop.css\" title=\"KDevelop\"/>\n";
152-
myfile << "<script type=\"text/javascript\" src=\"" << dataPath << "/jquery/jquery.min.js\"></script>\n";
153-
myfile << "<script type=\"text/javascript\" src=\"" << dataPath << "/jquery/jquery-ui.min.js\"></script>\n";
154-
myfile << "<script>var file = '"<< filename <<"'; var root_path = '"<< root_path <<"'; var data_path = '"<< dataPath <<"'; var ecma_script_api_version = 2;";
184+
myfile << "<link rel=\"stylesheet\" href=\"" << dataPath
185+
<< "/qtcreator.css\" title=\"QtCreator\"/>\n";
186+
myfile << "<link rel=\"alternate stylesheet\" href=\"" << dataPath
187+
<< "/kdevelop.css\" title=\"KDevelop\"/>\n";
188+
myfile << "<script type=\"text/javascript\" src=\"" << dataPath
189+
<< "/jquery/jquery.min.js\"></script>\n";
190+
myfile << "<script type=\"text/javascript\" src=\"" << dataPath
191+
<< "/jquery/jquery-ui.min.js\"></script>\n";
192+
myfile << "<script>var file = '" << filename << "'; var root_path = '" << root_path
193+
<< "'; var data_path = '" << dataPath << "'; var ecma_script_api_version = 2;";
155194
if (!projects.empty()) {
156195
myfile << "var projects = {";
157196
bool first = true;
158-
for (auto it: projects) {
159-
if (!first) myfile << ", ";
197+
for (auto it : projects) {
198+
if (!first)
199+
myfile << ", ";
160200
first = false;
161-
myfile << "\"" << it.first << "\" : \"" << it.second << "\"";
201+
myfile << "\"" << it.first << "\" : \"" << it.second << "\"";
162202
}
163203
myfile << "};";
164204
}
165205
myfile << "</script>\n";
166206
myfile << "<script src='" << dataPath << "/codebrowser.js'></script>\n";
167207

168-
myfile << "</head>\n<body><div id='header'><h1 id='breadcrumb'><span>Browse the source code of </span>";
208+
myfile << "</head>\n<body><div id='header'><h1 id='breadcrumb'><span>Browse the source code of "
209+
"</span>";
169210
// FIXME: If interestingDefitions has only 1 class, add it to the h1
170211

171212
{
@@ -214,9 +255,9 @@ void Generator::generate(llvm::StringRef outputPrefix, std::string dataPath, con
214255
bufferStart = c;
215256
};
216257

217-
myfile << "<tr><th id=\"1\">"<< 1 << "</th><td>";
258+
myfile << "<tr><th id=\"1\">" << 1 << "</th><td>";
218259

219-
std::deque<const Tag*> stack;
260+
std::deque<const Tag *> stack;
220261

221262

222263
while (true) {
@@ -240,33 +281,47 @@ void Generator::generate(llvm::StringRef outputPrefix, std::string dataPath, con
240281
tags_it->open(myfile);
241282
if (tags_it->len) {
242283
stack.push_back(&(*tags_it));
243-
next_end = c + tags_it->len;
284+
next_end = c + tags_it->len;
244285
}
245286

246287
tags_it++;
247288
next_start = tags_it != tags.cend() ? (begin + tags_it->pos) : end;
248289
};
249290

250291
next = std::min(next_end, next_start);
251-
//next = std::min(end, next);
292+
// next = std::min(end, next);
252293
}
253294

254295
switch (*c) {
255-
case '\n':
256-
flush();
257-
++bufferStart; //skip the new line
258-
++line;
259-
for (auto it = stack.crbegin(); it != stack.crend(); ++it)
260-
(*it)->close(myfile);
261-
myfile << "</td></tr>\n"
262-
"<tr><th id=\"" << line << "\">"<< line << "</th><td>";
263-
for (auto it = stack.cbegin(); it != stack.cend(); ++it)
264-
(*it)->open(myfile);
265-
break;
266-
case '&': flush(); ++bufferStart; myfile << "&amp;"; break;
267-
case '<': flush(); ++bufferStart; myfile << "&lt;"; break;
268-
case '>': flush(); ++bufferStart; myfile << "&gt;"; break;
269-
default: break;
296+
case '\n':
297+
flush();
298+
++bufferStart; // skip the new line
299+
++line;
300+
for (auto it = stack.crbegin(); it != stack.crend(); ++it)
301+
(*it)->close(myfile);
302+
myfile << "</td></tr>\n"
303+
"<tr><th id=\""
304+
<< line << "\">" << line << "</th><td>";
305+
for (auto it = stack.cbegin(); it != stack.cend(); ++it)
306+
(*it)->open(myfile);
307+
break;
308+
case '&':
309+
flush();
310+
++bufferStart;
311+
myfile << "&amp;";
312+
break;
313+
case '<':
314+
flush();
315+
++bufferStart;
316+
myfile << "&lt;";
317+
break;
318+
case '>':
319+
flush();
320+
++bufferStart;
321+
myfile << "&gt;";
322+
break;
323+
default:
324+
break;
270325
}
271326
++c;
272327
}
@@ -286,6 +341,8 @@ void Generator::generate(llvm::StringRef outputPrefix, std::string dataPath, con
286341

287342
myfile.write(footer.begin(), footer.size());
288343

289-
myfile << "<br />Powered by <a href='https://woboq.com'><img alt='Woboq' src='https://code.woboq.org/woboq-16.png' width='41' height='16' /></a> <a href='https://code.woboq.org'>Code Browser</a> "
290-
CODEBROWSER_VERSION "\n<br/>Generator usage only permitted with license.</p>\n</div></body></html>\n";
344+
myfile << "<br />Powered by <a href='https://woboq.com'><img alt='Woboq' "
345+
"src='https://code.woboq.org/woboq-16.png' width='41' height='16' /></a> <a "
346+
"href='https://code.woboq.org'>Code Browser</a> " CODEBROWSER_VERSION
347+
"\n<br/>Generator usage only permitted with license.</p>\n</div></body></html>\n";
291348
}

0 commit comments

Comments
 (0)