Skip to content

Commit 5786252

Browse files
committed
pass FileWithDetails into TokenList functions
1 parent 0771203 commit 5786252

16 files changed

Lines changed: 93 additions & 82 deletions

Makefile

Lines changed: 51 additions & 51 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"
@@ -518,7 +519,7 @@ void clangimport::AstNode::setLocations(TokenList &tokenList, int file, int line
518519
const bool windowsPath = colon == 2 && ext.size() > 3 && ext[2] == ':';
519520
const std::string::size_type sep1 = windowsPath ? ext.find(':', 4) : colon;
520521
const std::string::size_type sep2 = ext.find(':', sep1 + 1);
521-
file = tokenList.appendFileIfNew(ext.substr(1, sep1 - 1));
522+
file = tokenList.appendFileIfNew(FileWithDetails(ext.substr(1, sep1 - 1)));
522523
line = strToInt<int>(ext.substr(sep1 + 1, sep2 - sep1 - 1));
523524
}
524525
}

lib/cppcheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
508508

509509
try {
510510
Tokenizer tokenizer(mSettings, *this);
511-
tokenizer.list.appendFileIfNew(file.spath());
511+
tokenizer.list.appendFileIfNew(file);
512512
std::istringstream ast(output2);
513513
clangimport::parseClangAstDump(tokenizer, ast);
514514
ValueFlow::setValues(tokenizer.list,
@@ -668,11 +668,11 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
668668
// enforce the language since markup files are special and do not adhere to the enforced language
669669
tokenizer.list.setLang(Standards::Language::C, true);
670670
if (fileStream) {
671-
tokenizer.list.createTokens(*fileStream, file.spath());
671+
tokenizer.list.createTokens(*fileStream, file);
672672
}
673673
else {
674674
std::ifstream in(file.spath());
675-
tokenizer.list.createTokens(in, file.spath());
675+
tokenizer.list.createTokens(in, file);
676676
}
677677
mUnusedFunctionsCheck->parseTokens(tokenizer, mSettings);
678678
// TODO: set analyzer information

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"
@@ -109,15 +110,15 @@ void TokenList::determineCppC()
109110
}
110111
}
111112

112-
int TokenList::appendFileIfNew(std::string fileName)
113+
int TokenList::appendFileIfNew(const FileWithDetails& file)
113114
{
114115
// Has this file been tokenized already?
115116
for (int i = 0; i < mFiles.size(); ++i)
116-
if (Path::sameFileName(mFiles[i], fileName))
117+
if (Path::sameFileName(mFiles[i], file.spath()))
117118
return i;
118119

119120
// The "mFiles" vector remembers what files have been tokenized..
120-
mFiles.push_back(std::move(fileName));
121+
mFiles.push_back(file.spath());
121122

122123
// Update mIsC and mIsCpp properties
123124
if (mFiles.size() == 1) { // Update only useful if first file added to _files
@@ -336,13 +337,13 @@ void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n)
336337
// Tokenize - tokenizes a given file.
337338
//---------------------------------------------------------------------------
338339

339-
bool TokenList::createTokens(std::istream &code, const std::string& file0)
340+
bool TokenList::createTokens(std::istream &code, const FileWithDetails& file0)
340341
{
341-
ASSERT_LANG(!file0.empty());
342+
ASSERT_LANG(!file0.spath().empty());
342343

343344
appendFileIfNew(file0);
344345

345-
return createTokensInternal(code, file0);
346+
return createTokensInternal(code, file0.spath());
346347
}
347348

348349
//---------------------------------------------------------------------------

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
@@ -275,7 +275,7 @@ $(libcppdir)/checkunusedvar.o: ../lib/checkunusedvar.cpp ../lib/addoninfo.h ../l
275275
$(libcppdir)/checkvaarg.o: ../lib/checkvaarg.cpp ../lib/addoninfo.h ../lib/astutils.h ../lib/check.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/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
276276
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkvaarg.cpp
277277

278-
$(libcppdir)/clangimport.o: ../lib/clangimport.cpp ../lib/addoninfo.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/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
278+
$(libcppdir)/clangimport.o: ../lib/clangimport.cpp ../lib/addoninfo.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/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
279279
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/clangimport.cpp
280280

281281
$(libcppdir)/color.o: ../lib/color.cpp ../lib/color.h ../lib/config.h
@@ -356,7 +356,7 @@ $(libcppdir)/timer.o: ../lib/timer.cpp ../lib/config.h ../lib/timer.h ../lib/uti
356356
$(libcppdir)/token.o: ../lib/token.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/astutils.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/suppressions.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
357357
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/token.cpp
358358

359-
$(libcppdir)/tokenlist.o: ../lib/tokenlist.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/astutils.h ../lib/color.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/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
359+
$(libcppdir)/tokenlist.o: ../lib/tokenlist.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/astutils.h ../lib/color.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/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
360360
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/tokenlist.cpp
361361

362362
$(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
@@ -20,6 +20,7 @@
2020
#define helpersH
2121

2222
#include "config.h"
23+
#include "filesettings.h"
2324
#include "library.h"
2425
#include "preprocessor.h"
2526
#include "settings.h"
@@ -45,6 +46,8 @@ namespace tinyxml2 {
4546
class XMLDocument;
4647
}
4748

49+
FileWithDetails createFileWithDetails(std::string filename);
50+
4851
// TODO: make Tokenizer private
4952
class SimpleTokenizer : public Tokenizer {
5053
public:
@@ -83,7 +86,7 @@ class SimpleTokenizer : public Tokenizer {
8386
const std::string &configuration = emptyString)
8487
{
8588
std::istringstream istr(code);
86-
if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c"))
89+
if (!list.createTokens(istr, createFileWithDetails(cpp ? "test.cpp" : "test.c")))
8790
return false;
8891

8992
return simplifyTokens1(configuration);
@@ -95,7 +98,7 @@ class SimpleTokenizer : public Tokenizer {
9598
const std::string &configuration = emptyString)
9699
{
97100
std::istringstream istr(code);
98-
if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c"))
101+
if (!list.createTokens(istr, createFileWithDetails(cpp ? "test.cpp" : "test.c")))
99102
return false;
100103

101104
return simplifyTokens1(configuration);

test/testclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8941,7 +8941,7 @@ class TestClass : public TestFixture {
89418941
Tokenizer tokenizer(settingsDefault, *this);
89428942
std::istringstream istr(c);
89438943
const std::string filename = std::to_string(fileInfo.size()) + ".cpp";
8944-
ASSERT(tokenizer.list.createTokens(istr, filename));
8944+
ASSERT(tokenizer.list.createTokens(istr, createFileWithDetails(filename)));
89458945
ASSERT(tokenizer.simplifyTokens1(""));
89468946
fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault));
89478947
}

test/testsimplifytemplate.cpp

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

53085308
std::istringstream istr(code);
5309-
if (!tokenizer.list.createTokens(istr, "test.cpp"))
5309+
if (!tokenizer.list.createTokens(istr, createFileWithDetails("test.cpp")))
53105310
return false;
53115311
tokenizer.createLinks();
53125312
tokenizer.splitTemplateRightAngleBrackets(false);
@@ -5374,7 +5374,7 @@ class TestSimplifyTemplate : public TestFixture {
53745374
Tokenizer tokenizer(settings, *this);
53755375

53765376
std::istringstream istr(code);
5377-
if (!tokenizer.list.createTokens(istr, "test.cpp"))
5377+
if (!tokenizer.list.createTokens(istr, createFileWithDetails("test.cpp")))
53785378
return false;
53795379
tokenizer.createLinks();
53805380
tokenizer.splitTemplateRightAngleBrackets(false);
@@ -5445,7 +5445,7 @@ class TestSimplifyTemplate : public TestFixture {
54455445
Tokenizer tokenizer(settings, *this);
54465446

54475447
std::istringstream istr(code);
5448-
if (!tokenizer.list.createTokens(istr, "test.cpp"))
5448+
if (!tokenizer.list.createTokens(istr, createFileWithDetails("test.cpp")))
54495449
return false;
54505450
tokenizer.createLinks();
54515451
tokenizer.splitTemplateRightAngleBrackets(false);
@@ -5475,7 +5475,7 @@ class TestSimplifyTemplate : public TestFixture {
54755475
Tokenizer tokenizer(settings, *this);
54765476

54775477
std::istringstream istr(code);
5478-
if (!tokenizer.list.createTokens(istr, "test.cpp"))
5478+
if (!tokenizer.list.createTokens(istr, createFileWithDetails("test.cpp")))
54795479
return false;
54805480
tokenizer.createLinks();
54815481
tokenizer.splitTemplateRightAngleBrackets(false);

0 commit comments

Comments
 (0)