25
25
#include " platform.h"
26
26
#include " preprocessor.h"
27
27
#include " settings.h"
28
+ #include " standards.h"
28
29
#include " suppressions.h"
29
30
#include " tokenlist.h"
30
31
#include " fixture.h"
@@ -54,7 +55,7 @@ class TestPreprocessor : public TestFixture {
54
55
simplecpp::OutputList outputList;
55
56
std::vector<std::string> files;
56
57
const simplecpp::TokenList tokens1 = simplecpp::TokenList (istr, files, " file.cpp" , &outputList);
57
- Preprocessor p (settingsDefault, errorLogger);
58
+ Preprocessor p (settingsDefault, errorLogger, Path::identify (tokens1. getFiles ()[ 0 ], false ) );
58
59
simplecpp::TokenList tokens2 = p.preprocess (tokens1, " " , files, true );
59
60
p.reportOutput (outputList, true );
60
61
return tokens2.stringify ();
@@ -87,7 +88,7 @@ class TestPreprocessor : public TestFixture {
87
88
std::istringstream istr (code);
88
89
const simplecpp::TokenList tokens1 (istr, files, " test.cpp" );
89
90
90
- const Preprocessor preprocessor (settingsDefault, errorLogger);
91
+ const Preprocessor preprocessor (settingsDefault, errorLogger, Path::identify (tokens1. getFiles ()[ 0 ], false ) );
91
92
return preprocessor.getRemarkComments (tokens1);
92
93
}
93
94
@@ -301,11 +302,12 @@ class TestPreprocessor : public TestFixture {
301
302
settings.userDefines = arg + 2 ;
302
303
if (arg && std::strncmp (arg," -U" ,2 )==0 )
303
304
settings.userUndefs .insert (arg+2 );
304
- Preprocessor preprocessor (settings, *this );
305
305
std::vector<std::string> files;
306
306
std::istringstream istr (filedata);
307
+ // TODO: this adds an empty filename
307
308
simplecpp::TokenList tokens (istr,files);
308
309
tokens.removeComments ();
310
+ Preprocessor preprocessor (settings, *this , Standards::Language::C); // TODO: do we need to consider #file?
309
311
const std::set<std::string> configs = preprocessor.getConfigs (tokens);
310
312
std::string ret;
311
313
for (const std::string & config : configs)
@@ -314,11 +316,12 @@ class TestPreprocessor : public TestFixture {
314
316
}
315
317
316
318
std::size_t getHash (const char filedata[]) {
317
- Preprocessor preprocessor (settingsDefault, *this );
318
319
std::vector<std::string> files;
319
320
std::istringstream istr (filedata);
321
+ // TODO: this adds an empty filename
320
322
simplecpp::TokenList tokens (istr,files);
321
323
tokens.removeComments ();
324
+ Preprocessor preprocessor (settingsDefault, *this , Standards::Language::C); // TODO: do we need to consider #file?
322
325
return preprocessor.calculateHash (tokens, " " );
323
326
}
324
327
@@ -478,15 +481,15 @@ class TestPreprocessor : public TestFixture {
478
481
{
479
482
const Settings settings = settingsBuilder ().platform (Platform::Type::Unix32).build ();
480
483
Preprocessor::setPlatformInfo (tokens, settings);
481
- Preprocessor preprocessor (settings, *this );
484
+ Preprocessor preprocessor (settings, *this , Path::identify (tokens. getFiles ()[ 0 ], false ) );
482
485
ASSERT_EQUALS (" \n 1" , preprocessor.getcode (tokens, " " , files, false ));
483
486
}
484
487
485
488
// preprocess code with unix64 platform..
486
489
{
487
490
const Settings settings = settingsBuilder ().platform (Platform::Type::Unix64).build ();
488
491
Preprocessor::setPlatformInfo (tokens, settings);
489
- Preprocessor preprocessor (settings, *this );
492
+ Preprocessor preprocessor (settings, *this , Path::identify (tokens. getFiles ()[ 0 ], false ) );
490
493
ASSERT_EQUALS (" \n\n\n 2" , preprocessor.getcode (tokens, " " , files, false ));
491
494
}
492
495
}
@@ -1211,7 +1214,7 @@ class TestPreprocessor : public TestFixture {
1211
1214
" #undef z\n "
1212
1215
" int z;\n "
1213
1216
" z = 0;\n " ;
1214
- ASSERT_EQUALS (" \n\n int z ;\n z = 0 ;" , PreprocessorHelper::getcode (settings0, *this , filedata, " " , " " ));
1217
+ ASSERT_EQUALS (" \n\n int z ;\n z = 0 ;" , PreprocessorHelper::getcode (settings0, *this , filedata, " " , " test.c " ));
1215
1218
}
1216
1219
}
1217
1220
@@ -1629,14 +1632,14 @@ class TestPreprocessor : public TestFixture {
1629
1632
" #if A\n "
1630
1633
" FOO\n "
1631
1634
" #endif" ;
1632
- ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1635
+ ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
1633
1636
}
1634
1637
{
1635
1638
const char filedata[] = " #define A 1\n "
1636
1639
" #if A==1\n "
1637
1640
" FOO\n "
1638
1641
" #endif" ;
1639
- ASSERT_EQUALS (" \n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1642
+ ASSERT_EQUALS (" \n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
1640
1643
}
1641
1644
}
1642
1645
@@ -1646,23 +1649,23 @@ class TestPreprocessor : public TestFixture {
1646
1649
" #if (B==A) || (B==C)\n "
1647
1650
" FOO\n "
1648
1651
" #endif" ;
1649
- ASSERT_EQUALS (" \n\n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1652
+ ASSERT_EQUALS (" \n\n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
1650
1653
}
1651
1654
1652
1655
void define_if3 () {
1653
1656
const char filedata[] = " #define A 0\n "
1654
1657
" #if (A==0)\n "
1655
1658
" FOO\n "
1656
1659
" #endif" ;
1657
- ASSERT_EQUALS (" \n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1660
+ ASSERT_EQUALS (" \n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
1658
1661
}
1659
1662
1660
1663
void define_if4 () {
1661
1664
const char filedata[] = " #define X +123\n "
1662
1665
" #if X==123\n "
1663
1666
" FOO\n "
1664
1667
" #endif" ;
1665
- ASSERT_EQUALS (" \n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1668
+ ASSERT_EQUALS (" \n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
1666
1669
}
1667
1670
1668
1671
void define_if5 () { // #4516 - #define B (A & 0x00f0)
@@ -1672,7 +1675,7 @@ class TestPreprocessor : public TestFixture {
1672
1675
" #if B==0x0010\n "
1673
1676
" FOO\n "
1674
1677
" #endif" ;
1675
- ASSERT_EQUALS (" \n\n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1678
+ ASSERT_EQUALS (" \n\n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
1676
1679
}
1677
1680
{
1678
1681
const char filedata[] = " #define A 0x00f0\n "
@@ -1681,14 +1684,14 @@ class TestPreprocessor : public TestFixture {
1681
1684
" #if C==0x0010\n "
1682
1685
" FOO\n "
1683
1686
" #endif" ;
1684
- ASSERT_EQUALS (" \n\n\n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1687
+ ASSERT_EQUALS (" \n\n\n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
1685
1688
}
1686
1689
{
1687
1690
const char filedata[] = " #define A (1+A)\n " // don't hang for recursive macros
1688
1691
" #if A==1\n "
1689
1692
" FOO\n "
1690
1693
" #endif" ;
1691
- ASSERT_EQUALS (" \n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1694
+ ASSERT_EQUALS (" \n\n FOO" , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
1692
1695
}
1693
1696
}
1694
1697
0 commit comments