Skip to content

Commit 0c0444d

Browse files
committed
pass FileWithDetails into TokenList functions [skip ci]
1 parent 5ac33c8 commit 0c0444d

16 files changed

Lines changed: 90 additions & 79 deletions

Makefile

Lines changed: 50 additions & 50 deletions
Large diffs are not rendered by default.

lib/clangimport.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "clangimport.h"
2020

2121
#include "errortypes.h"
22+
#include "filesettings.h"
2223
#include "mathlib.h"
2324
#include "settings.h"
2425
#include "standards.h"
@@ -552,7 +553,7 @@ void clangimport::AstNode::setLocations(TokenList &tokenList, int file, int line
552553
const bool windowsPath = colon == 2 && ext.size() > 3 && ext[2] == ':';
553554
const std::string::size_type sep1 = windowsPath ? ext.find(':', 4) : colon;
554555
const std::string::size_type sep2 = ext.find(':', sep1 + 1);
555-
file = tokenList.appendFileIfNew(ext.substr(1, sep1 - 1));
556+
file = tokenList.appendFileIfNew(FileWithDetails(ext.substr(1, sep1 - 1)));
556557
line = strToInt<int>(ext.substr(sep1 + 1, sep2 - sep1 - 1));
557558
}
558559
else {

lib/cppcheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
717717

718718
try {
719719
Tokenizer tokenizer(mSettings, mErrorLogger);
720-
tokenizer.list.appendFileIfNew(file.spath());
720+
tokenizer.list.appendFileIfNew(file);
721721
std::istringstream ast(output2);
722722
clangimport::parseClangAstDump(tokenizer, ast);
723723
ValueFlow::setValues(tokenizer.list,

lib/tokenlist.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "astutils.h"
2424
#include "errorlogger.h"
2525
#include "errortypes.h"
26+
#include "filesettings.h"
2627
#include "keywords.h"
2728
#include "library.h"
2829
#include "path.h"
@@ -112,17 +113,17 @@ void TokenList::determineCppC()
112113
}
113114
}
114115

115-
int TokenList::appendFileIfNew(std::string fileName)
116+
int TokenList::appendFileIfNew(const FileWithDetails& file)
116117
{
117118
// Has this file been tokenized already?
118119
auto it = std::find_if(mFiles.cbegin(), mFiles.cend(), [&](const std::string& f) {
119-
return Path::sameFileName(f, fileName);
120+
return Path::sameFileName(f, file.spath());
120121
});
121122
if (it != mFiles.cend())
122123
return static_cast<int>(std::distance(mFiles.cbegin(), it));
123124

124125
// The "mFiles" vector remembers what files have been tokenized..
125-
mFiles.push_back(std::move(fileName));
126+
mFiles.push_back(file.spath());
126127

127128
// Update mIsC and mIsCpp properties
128129
if (mFiles.size() == 1) { // Update only useful if first file added to _files
@@ -344,13 +345,13 @@ void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n)
344345
// Tokenize - tokenizes a given file.
345346
//---------------------------------------------------------------------------
346347

347-
bool TokenList::createTokens(std::istream &code, const std::string& file0)
348+
bool TokenList::createTokens(std::istream &code, const FileWithDetails& file0)
348349
{
349-
ASSERT_LANG(!file0.empty());
350+
ASSERT_LANG(!file0.spath().empty());
350351

351352
appendFileIfNew(file0);
352353

353-
return createTokensInternal(code, file0);
354+
return createTokensInternal(code, file0.spath());
354355
}
355356

356357
//---------------------------------------------------------------------------

lib/tokenlist.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
class Token;
3333
class TokenList;
3434
class Settings;
35+
class FileWithDetails;
3536

3637
namespace simplecpp {
3738
class TokenList;
@@ -105,7 +106,7 @@ class CPPCHECKLIB TokenList {
105106
* @param code input stream for code
106107
* @param file0 source file name
107108
*/
108-
bool createTokens(std::istream &code, const std::string& file0);
109+
bool createTokens(std::istream &code, const FileWithDetails& file0);
109110
bool createTokens(std::istream &code, Standards::Language lang);
110111

111112
void createTokens(simplecpp::TokenList&& tokenList);
@@ -114,7 +115,7 @@ class CPPCHECKLIB TokenList {
114115
void deallocateTokens();
115116

116117
/** append file name if seen the first time; return its index in any case */
117-
int appendFileIfNew(std::string fileName);
118+
int appendFileIfNew(const FileWithDetails& file);
118119

119120
/** get first token of list */
120121
const Token *front() const {

oss-fuzz/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ $(libcppdir)/checkunusedvar.o: ../lib/checkunusedvar.cpp ../lib/addoninfo.h ../l
246246
$(libcppdir)/checkvaarg.o: ../lib/checkvaarg.cpp ../lib/addoninfo.h ../lib/astutils.h ../lib/check.h ../lib/checkers.h ../lib/checkvaarg.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
247247
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkvaarg.cpp
248248

249-
$(libcppdir)/clangimport.o: ../lib/clangimport.cpp ../lib/addoninfo.h ../lib/checkers.h ../lib/clangimport.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
249+
$(libcppdir)/clangimport.o: ../lib/clangimport.cpp ../lib/addoninfo.h ../lib/checkers.h ../lib/clangimport.h ../lib/config.h ../lib/errortypes.h ../lib/filesettings.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/settings.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
250250
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/clangimport.cpp
251251

252252
$(libcppdir)/color.o: ../lib/color.cpp ../lib/color.h ../lib/config.h
@@ -330,7 +330,7 @@ $(libcppdir)/timer.o: ../lib/timer.cpp ../lib/config.h ../lib/timer.h ../lib/uti
330330
$(libcppdir)/token.o: ../lib/token.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/astutils.h ../lib/checkers.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/tokenrange.h ../lib/utils.h ../lib/valueflow.h ../lib/vfvalue.h
331331
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/token.cpp
332332

333-
$(libcppdir)/tokenlist.o: ../lib/tokenlist.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/astutils.h ../lib/checkers.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/keywords.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/settings.h ../lib/smallvector.h ../lib/standards.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
333+
$(libcppdir)/tokenlist.o: ../lib/tokenlist.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/astutils.h ../lib/checkers.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/filesettings.h ../lib/keywords.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/settings.h ../lib/smallvector.h ../lib/standards.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
334334
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/tokenlist.cpp
335335

336336
$(libcppdir)/utils.o: ../lib/utils.cpp ../lib/config.h ../lib/utils.h

test/helpers.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,8 @@ Library::Error LibraryHelper::loadxmldoc(Library &lib, const tinyxml2::XMLDocume
233233
{
234234
return lib.load(doc);
235235
}
236+
237+
FileWithDetails createFileWithDetails(std::string filename)
238+
{
239+
return FileWithDetails(std::move(filename));
240+
}

test/helpers.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef helpersH
2020
#define helpersH
2121

22+
#include "filesettings.h"
2223
#include "library.h"
2324
#include "preprocessor.h"
2425
#include "settings.h"
@@ -44,6 +45,8 @@ namespace tinyxml2 {
4445
class XMLDocument;
4546
}
4647

48+
FileWithDetails createFileWithDetails(std::string filename);
49+
4750
// TODO: make Tokenizer private
4851
class SimpleTokenizer : public Tokenizer {
4952
public:
@@ -82,7 +85,7 @@ class SimpleTokenizer : public Tokenizer {
8285
const std::string &configuration = "")
8386
{
8487
std::istringstream istr(code);
85-
if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c"))
88+
if (!list.createTokens(istr, createFileWithDetails(cpp ? "test.cpp" : "test.c")))
8689
return false;
8790

8891
return simplifyTokens1(configuration);
@@ -94,7 +97,7 @@ class SimpleTokenizer : public Tokenizer {
9497
const std::string &configuration = "")
9598
{
9699
std::istringstream istr(code);
97-
if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c"))
100+
if (!list.createTokens(istr, createFileWithDetails(cpp ? "test.cpp" : "test.c")))
98101
return false;
99102

100103
return simplifyTokens1(configuration);

test/testclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9088,7 +9088,7 @@ class TestClass : public TestFixture {
90889088
Tokenizer tokenizer(settingsDefault, *this);
90899089
std::istringstream istr(c);
90909090
const std::string filename = std::to_string(fileInfo.size()) + ".cpp";
9091-
ASSERT(tokenizer.list.createTokens(istr, filename));
9091+
ASSERT(tokenizer.list.createTokens(istr, createFileWithDetails(filename)));
90929092
ASSERT(tokenizer.simplifyTokens1(""));
90939093
fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault));
90949094
}

test/testsimplifytemplate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5390,7 +5390,7 @@ class TestSimplifyTemplate : public TestFixture {
53905390
Tokenizer tokenizer(settings, *this);
53915391

53925392
std::istringstream istr(code);
5393-
if (!tokenizer.list.createTokens(istr, "test.cpp"))
5393+
if (!tokenizer.list.createTokens(istr, createFileWithDetails("test.cpp")))
53945394
return false;
53955395
tokenizer.createLinks();
53965396
tokenizer.splitTemplateRightAngleBrackets(false);
@@ -5458,7 +5458,7 @@ class TestSimplifyTemplate : public TestFixture {
54585458
Tokenizer tokenizer(settings, *this);
54595459

54605460
std::istringstream istr(code);
5461-
if (!tokenizer.list.createTokens(istr, "test.cpp"))
5461+
if (!tokenizer.list.createTokens(istr, createFileWithDetails("test.cpp")))
54625462
return false;
54635463
tokenizer.createLinks();
54645464
tokenizer.splitTemplateRightAngleBrackets(false);
@@ -5529,7 +5529,7 @@ class TestSimplifyTemplate : public TestFixture {
55295529
Tokenizer tokenizer(settings, *this);
55305530

55315531
std::istringstream istr(code);
5532-
if (!tokenizer.list.createTokens(istr, "test.cpp"))
5532+
if (!tokenizer.list.createTokens(istr, createFileWithDetails("test.cpp")))
55335533
return false;
55345534
tokenizer.createLinks();
55355535
tokenizer.splitTemplateRightAngleBrackets(false);
@@ -5559,7 +5559,7 @@ class TestSimplifyTemplate : public TestFixture {
55595559
Tokenizer tokenizer(settings, *this);
55605560

55615561
std::istringstream istr(code);
5562-
if (!tokenizer.list.createTokens(istr, "test.cpp"))
5562+
if (!tokenizer.list.createTokens(istr, createFileWithDetails("test.cpp")))
55635563
return false;
55645564
tokenizer.createLinks();
55655565
tokenizer.splitTemplateRightAngleBrackets(false);

0 commit comments

Comments
 (0)