Skip to content

Commit bacd5bd

Browse files
committed
runastyle
1 parent 78c34de commit bacd5bd

File tree

3 files changed

+85
-106
lines changed

3 files changed

+85
-106
lines changed

main.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,19 @@ int main(int argc, char **argv)
2929
bool found = false;
3030
const char c = arg[1];
3131
switch (c) {
32-
case 'D': // define symbol
33-
{
32+
case 'D': { // define symbol
3433
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
3534
dui.defines.push_back(value);
3635
found = true;
3736
break;
3837
}
39-
case 'U': // undefine symbol
40-
{
38+
case 'U': { // undefine symbol
4139
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
4240
dui.undefined.insert(value);
4341
found = true;
4442
break;
4543
}
46-
case 'I': // include path
47-
{
44+
case 'I': { // include path
4845
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
4946
dui.includePaths.push_back(value);
5047
found = true;
@@ -54,8 +51,7 @@ int main(int argc, char **argv)
5451
if (std::strncmp(arg, "-include=",9)==0) {
5552
dui.includes.push_back(arg+9);
5653
found = true;
57-
}
58-
else if (std::strncmp(arg, "-is",3)==0) {
54+
} else if (std::strncmp(arg, "-is",3)==0) {
5955
use_istream = true;
6056
found = true;
6157
}
@@ -122,8 +118,7 @@ int main(int argc, char **argv)
122118
std::exit(1);
123119
}
124120
rawtokens = new simplecpp::TokenList(f, files,filename,&outputList);
125-
}
126-
else {
121+
} else {
127122
rawtokens = new simplecpp::TokenList(filename,files,&outputList);
128123
}
129124
rawtokens->removeComments();

simplecpp.cpp

Lines changed: 61 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ class simplecpp::TokenList::Stream {
242242
virtual void unget() = 0;
243243
virtual bool good() = 0;
244244

245-
unsigned char readChar()
246-
{
245+
unsigned char readChar() {
247246
unsigned char ch = static_cast<unsigned char>(get());
248247

249248
// For UTF-16 encoded files the BOM is 0xfeff/0xfffe. If the
@@ -271,8 +270,7 @@ class simplecpp::TokenList::Stream {
271270
return ch;
272271
}
273272

274-
unsigned char peekChar()
275-
{
273+
unsigned char peekChar() {
276274
unsigned char ch = static_cast<unsigned char>(peek());
277275

278276
// For UTF-16 encoded files the BOM is 0xfeff/0xfffe. If the
@@ -292,8 +290,7 @@ class simplecpp::TokenList::Stream {
292290
return ch;
293291
}
294292

295-
void ungetChar()
296-
{
293+
void ungetChar() {
297294
unget();
298295
if (isUtf16)
299296
unget();
@@ -308,13 +305,11 @@ class simplecpp::TokenList::Stream {
308305
}
309306

310307
private:
311-
inline int makeUtf16Char(const unsigned char ch, const unsigned char ch2) const
312-
{
308+
inline int makeUtf16Char(const unsigned char ch, const unsigned char ch2) const {
313309
return (bom == 0xfeff) ? (ch<<8 | ch2) : (ch2<<8 | ch);
314310
}
315311

316-
unsigned short getAndSkipBOM()
317-
{
312+
unsigned short getAndSkipBOM() {
318313
const int ch1 = peek();
319314

320315
// The UTF-16 BOM is 0xfffe or 0xfeff.
@@ -353,8 +348,7 @@ class StdIStream : public simplecpp::TokenList::Stream {
353348
public:
354349
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
355350
EXPLICIT StdIStream(std::istream &istr)
356-
: istr(istr)
357-
{
351+
: istr(istr) {
358352
assert(istr.good());
359353
init();
360354
}
@@ -383,8 +377,7 @@ class StdCharBufStream : public simplecpp::TokenList::Stream {
383377
: str(str)
384378
, size(size)
385379
, pos(0)
386-
, lastStatus(0)
387-
{
380+
, lastStatus(0) {
388381
init();
389382
}
390383

@@ -418,8 +411,7 @@ class FileStream : public simplecpp::TokenList::Stream {
418411
EXPLICIT FileStream(const std::string &filename, std::vector<std::string> &files)
419412
: file(fopen(filename.c_str(), "rb"))
420413
, lastCh(0)
421-
, lastStatus(0)
422-
{
414+
, lastStatus(0) {
423415
if (!file) {
424416
files.push_back(filename);
425417
throw simplecpp::Output(files, simplecpp::Output::FILE_NOT_FOUND, "File is missing: " + filename);
@@ -455,8 +447,7 @@ class FileStream : public simplecpp::TokenList::Stream {
455447
// TODO: use ungetc() as well
456448
// UTF-16 has subsequent unget() calls
457449
fseek(file, -1, SEEK_CUR);
458-
}
459-
else
450+
} else
460451
ungetc(ch, file);
461452
}
462453

@@ -485,22 +476,19 @@ simplecpp::TokenList::TokenList(const unsigned char* data, std::size_t size, std
485476
}
486477

487478
simplecpp::TokenList::TokenList(const char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList)
488-
: frontToken(nullptr), backToken(nullptr), files(filenames)
479+
: frontToken(nullptr), backToken(nullptr), files(filenames)
489480
{
490481
StdCharBufStream stream(reinterpret_cast<const unsigned char*>(data), size);
491482
readfile(stream,filename,outputList);
492483
}
493484

494485
simplecpp::TokenList::TokenList(const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList)
495-
: frontToken(nullptr), backToken(nullptr), files(filenames)
486+
: frontToken(nullptr), backToken(nullptr), files(filenames)
496487
{
497-
try
498-
{
488+
try {
499489
FileStream stream(filename, filenames);
500490
readfile(stream,filename,outputList);
501-
}
502-
catch(const simplecpp::Output & e) // TODO handle extra type of errors
503-
{
491+
} catch (const simplecpp::Output & e) { // TODO handle extra type of errors
504492
outputList->push_back(e);
505493
}
506494
}
@@ -890,7 +878,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
890878
else
891879
back()->setstr(prefix + s);
892880

893-
if (newlines > 0 ) {
881+
if (newlines > 0) {
894882
const Token * const llTok = lastLineTok();
895883
if (llTok && llTok->op == '#' && llTok->next && (llTok->next->str() == "define" || llTok->next->str() == "pragma") && llTok->next->next) {
896884
multiline += newlines;
@@ -2009,14 +1997,14 @@ namespace simplecpp {
20091997
int paren = 1;
20101998
while (sameline(tok, tok->next)) {
20111999
if (tok->next->str() == "(")
2012-
++paren;
2000+
++paren;
20132001
else if (tok->next->str() == ")")
2014-
--paren;
2002+
--paren;
20152003
if (paren == 0)
2016-
return tok->next->next;
2004+
return tok->next->next;
20172005
tok = tok->next;
20182006
if (parametertokens.size() > args.size() && parametertokens.front()->next->str() != ")")
2019-
tok = expandToken(output, loc, tok, macros, expandedmacros, parametertokens)->previous;
2007+
tok = expandToken(output, loc, tok, macros, expandedmacros, parametertokens)->previous;
20202008
}
20212009
}
20222010
throw Error(tok->location, "Missing parenthesis for __VA_OPT__(content)");
@@ -2708,8 +2696,7 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
27082696
header += headerToken->str();
27092697
// cppcheck-suppress selfAssignment - platform-dependent implementation
27102698
header = realFilename(header);
2711-
}
2712-
else {
2699+
} else {
27132700
header = realFilename(tok1->str().substr(1U, tok1->str().size() - 2U));
27142701
}
27152702
std::ifstream f;
@@ -3625,8 +3612,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36253612
header = realFilename(header);
36263613
if (tok && tok->op == '>')
36273614
closingAngularBracket = true;
3628-
}
3629-
else {
3615+
} else {
36303616
header = realFilename(tok->str().substr(1U, tok->str().size() - 2U));
36313617
closingAngularBracket = true;
36323618
}
@@ -3799,25 +3785,24 @@ simplecpp::cstd_t simplecpp::getCStd(const std::string &std)
37993785

38003786
std::string simplecpp::getCStdString(cstd_t std)
38013787
{
3802-
switch (std)
3803-
{
3804-
case C89:
3805-
// __STDC_VERSION__ is not set for C90 although the macro was added in the 1994 amendments
3806-
return "";
3807-
case C99:
3808-
return "199901L";
3809-
case C11:
3810-
return "201112L";
3811-
case C17:
3812-
return "201710L";
3813-
case C23:
3814-
// supported by GCC 9+ and Clang 9+
3815-
// Clang 9, 10, 11, 12, 13 return "201710L"
3816-
// Clang 14, 15, 16, 17 return "202000L"
3817-
// Clang 9, 10, 11, 12, 13, 14, 15, 16, 17 do not support "c23" and "gnu23"
3818-
return "202311L";
3819-
case CUnknown:
3820-
return "";
3788+
switch (std) {
3789+
case C89:
3790+
// __STDC_VERSION__ is not set for C90 although the macro was added in the 1994 amendments
3791+
return "";
3792+
case C99:
3793+
return "199901L";
3794+
case C11:
3795+
return "201112L";
3796+
case C17:
3797+
return "201710L";
3798+
case C23:
3799+
// supported by GCC 9+ and Clang 9+
3800+
// Clang 9, 10, 11, 12, 13 return "201710L"
3801+
// Clang 14, 15, 16, 17 return "202000L"
3802+
// Clang 9, 10, 11, 12, 13, 14, 15, 16, 17 do not support "c23" and "gnu23"
3803+
return "202311L";
3804+
case CUnknown:
3805+
return "";
38213806
}
38223807
return "";
38233808
}
@@ -3848,30 +3833,29 @@ simplecpp::cppstd_t simplecpp::getCppStd(const std::string &std)
38483833

38493834
std::string simplecpp::getCppStdString(cppstd_t std)
38503835
{
3851-
switch (std)
3852-
{
3853-
case CPP03:
3854-
return "199711L";
3855-
case CPP11:
3856-
return "201103L";
3857-
case CPP14:
3858-
return "201402L";
3859-
case CPP17:
3860-
return "201703L";
3861-
case CPP20:
3862-
// GCC 10 returns "201703L" - correct in 11+
3863-
return "202002L";
3864-
case CPP23:
3865-
// supported by GCC 11+ and Clang 12+
3866-
// GCC 11, 12, 13 return "202100L"
3867-
// Clang 12, 13, 14, 15, 16 do not support "c++23" and "gnu++23" and return "202101L"
3868-
// Clang 17, 18 return "202302L"
3869-
return "202302L";
3870-
case CPP26:
3871-
// supported by Clang 17+
3872-
return "202400L";
3873-
case CPPUnknown:
3874-
return "";
3836+
switch (std) {
3837+
case CPP03:
3838+
return "199711L";
3839+
case CPP11:
3840+
return "201103L";
3841+
case CPP14:
3842+
return "201402L";
3843+
case CPP17:
3844+
return "201703L";
3845+
case CPP20:
3846+
// GCC 10 returns "201703L" - correct in 11+
3847+
return "202002L";
3848+
case CPP23:
3849+
// supported by GCC 11+ and Clang 12+
3850+
// GCC 11, 12, 13 return "202100L"
3851+
// Clang 12, 13, 14, 15, 16 do not support "c++23" and "gnu++23" and return "202101L"
3852+
// Clang 17, 18 return "202302L"
3853+
return "202302L";
3854+
case CPP26:
3855+
// supported by Clang 17+
3856+
return "202400L";
3857+
case CPPUnknown:
3858+
return "";
38753859
}
38763860
return "";
38773861
}

0 commit comments

Comments
 (0)