Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
olabetskyi committed Jun 19, 2024
1 parent b4618dc commit 4008784
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 97 deletions.
1 change: 1 addition & 0 deletions addons/cppcheckdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ def iterconfigurations(self):
# Iterating <typedef-info>
iter_typedef_info = False

# Iterating <directive>
iter_directive = False

# Use iterable objects to traverse XML tree for dump files incrementally.
Expand Down
22 changes: 14 additions & 8 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,22 @@ static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
return tok1 && tok2 && tok1->location.sameline(tok2->location);
}

Directive::Directive(std::string _file, const int _linenr, const std::string &_str) :
Directive::Directive(const simplecpp::Location & _loc, const std::string & _str) :
file(_loc.file()),
linenr(_loc.line),
str(_str)
{}

Directive::Directive(std::string _file, const int _linenr, const std::string & _str) :
file(std::move(_file)),
linenr(_linenr),
str(trim(_str))
str(_str)
{}

Directive::DirectiveToken::DirectiveToken(std::string _str, int _line, int _column) :
line(_line),
column(_column),
tokStr(std::move(_str))
Directive::DirectiveToken::DirectiveToken(const simplecpp::Token & _tok) :
line(_tok.location.line),
column(_tok.location.col),
tokStr(_tok.str())
{}

char Preprocessor::macroChar = char(1);
Expand Down Expand Up @@ -334,7 +340,7 @@ std::list<Directive> Preprocessor::createDirectives(const simplecpp::TokenList &
continue;
if (tok->next && tok->next->str() == "endfile")
continue;
Directive directive(tok->location.file(), tok->location.line, emptyString);
Directive directive(tok->location, emptyString);
for (const simplecpp::Token *tok2 = tok; tok2 && tok2->location.line == directive.linenr; tok2 = tok2->next) {
if (tok2->comment)
continue;
Expand All @@ -345,7 +351,7 @@ std::list<Directive> Preprocessor::createDirectives(const simplecpp::TokenList &
else
directive.str += tok2->str();

directive.strTokens.emplace_back(tok2->str(), tok2->location.line, tok2->location.col);
directive.strTokens.emplace_back(*tok2);
}
directives.push_back(std::move(directive));
}
Expand Down
3 changes: 2 additions & 1 deletion lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct CPPCHECKLIB Directive {
std::string str;

struct DirectiveToken {
explicit DirectiveToken(std::string _str, int _line, int _column);
explicit DirectiveToken(const simplecpp::Token & _tok);
int line;
int column;
std::string tokStr;
Expand All @@ -66,6 +66,7 @@ struct CPPCHECKLIB Directive {
std::vector<DirectiveToken> strTokens;

/** record a directive (possibly filtering src) */
Directive(const simplecpp::Location & _loc, const std::string & _str);
Directive(std::string _file, const int _linenr, const std::string &_str);
};

Expand Down
3 changes: 0 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5961,9 +5961,6 @@ void Tokenizer::dump(std::ostream &out) const
outs += '\n';
for (const auto & strToken : dir.strTokens) {
outs += " <token ";
outs += "line=\"";
outs += std::to_string(strToken.line);
outs += "\" ";
outs += "column=\"";
outs += std::to_string(strToken.column);
outs += "\" ";
Expand Down
Loading

0 comments on commit 4008784

Please sign in to comment.