2525#include " platform.h"
2626#include " preprocessor.h"
2727#include " settings.h"
28+ #include " standards.h"
2829#include " suppressions.h"
2930#include " tokenlist.h"
3031#include " fixture.h"
@@ -54,7 +55,7 @@ class TestPreprocessor : public TestFixture {
5455 simplecpp::OutputList outputList;
5556 std::vector<std::string> files;
5657 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 ) );
5859 simplecpp::TokenList tokens2 = p.preprocess (tokens1, " " , files, true );
5960 p.reportOutput (outputList, true );
6061 return tokens2.stringify ();
@@ -87,7 +88,7 @@ class TestPreprocessor : public TestFixture {
8788 std::istringstream istr (code);
8889 const simplecpp::TokenList tokens1 (istr, files, " test.cpp" );
8990
90- const Preprocessor preprocessor (settingsDefault, errorLogger);
91+ const Preprocessor preprocessor (settingsDefault, errorLogger, Path::identify (tokens1. getFiles ()[ 0 ], false ) );
9192 return preprocessor.getRemarkComments (tokens1);
9293 }
9394
@@ -301,11 +302,12 @@ class TestPreprocessor : public TestFixture {
301302 settings.userDefines = arg + 2 ;
302303 if (arg && std::strncmp (arg," -U" ,2 )==0 )
303304 settings.userUndefs .insert (arg+2 );
304- Preprocessor preprocessor (settings, *this );
305305 std::vector<std::string> files;
306306 std::istringstream istr (filedata);
307+ // TODO: this adds an empty filename
307308 simplecpp::TokenList tokens (istr,files);
308309 tokens.removeComments ();
310+ Preprocessor preprocessor (settings, *this , Standards::Language::C); // TODO: do we need to consider #file?
309311 const std::set<std::string> configs = preprocessor.getConfigs (tokens);
310312 std::string ret;
311313 for (const std::string & config : configs)
@@ -314,11 +316,12 @@ class TestPreprocessor : public TestFixture {
314316 }
315317
316318 std::size_t getHash (const char filedata[]) {
317- Preprocessor preprocessor (settingsDefault, *this );
318319 std::vector<std::string> files;
319320 std::istringstream istr (filedata);
321+ // TODO: this adds an empty filename
320322 simplecpp::TokenList tokens (istr,files);
321323 tokens.removeComments ();
324+ Preprocessor preprocessor (settingsDefault, *this , Standards::Language::C); // TODO: do we need to consider #file?
322325 return preprocessor.calculateHash (tokens, " " );
323326 }
324327
@@ -478,15 +481,15 @@ class TestPreprocessor : public TestFixture {
478481 {
479482 const Settings settings = settingsBuilder ().platform (Platform::Type::Unix32).build ();
480483 Preprocessor::setPlatformInfo (tokens, settings);
481- Preprocessor preprocessor (settings, *this );
484+ Preprocessor preprocessor (settings, *this , Path::identify (tokens. getFiles ()[ 0 ], false ) );
482485 ASSERT_EQUALS (" \n 1" , preprocessor.getcode (tokens, " " , files, false ));
483486 }
484487
485488 // preprocess code with unix64 platform..
486489 {
487490 const Settings settings = settingsBuilder ().platform (Platform::Type::Unix64).build ();
488491 Preprocessor::setPlatformInfo (tokens, settings);
489- Preprocessor preprocessor (settings, *this );
492+ Preprocessor preprocessor (settings, *this , Path::identify (tokens. getFiles ()[ 0 ], false ) );
490493 ASSERT_EQUALS (" \n\n\n 2" , preprocessor.getcode (tokens, " " , files, false ));
491494 }
492495 }
@@ -1211,7 +1214,7 @@ class TestPreprocessor : public TestFixture {
12111214 " #undef z\n "
12121215 " int z;\n "
12131216 " 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 " ));
12151218 }
12161219 }
12171220
@@ -1629,14 +1632,14 @@ class TestPreprocessor : public TestFixture {
16291632 " #if A\n "
16301633 " FOO\n "
16311634 " #endif" ;
1632- ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings0, *this , filedata," " ," " ));
1635+ ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings0, *this , filedata," " ," test.c " ));
16331636 }
16341637 {
16351638 const char filedata[] = " #define A 1\n "
16361639 " #if A==1\n "
16371640 " FOO\n "
16381641 " #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 " ));
16401643 }
16411644 }
16421645
@@ -1646,23 +1649,23 @@ class TestPreprocessor : public TestFixture {
16461649 " #if (B==A) || (B==C)\n "
16471650 " FOO\n "
16481651 " #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 " ));
16501653 }
16511654
16521655 void define_if3 () {
16531656 const char filedata[] = " #define A 0\n "
16541657 " #if (A==0)\n "
16551658 " FOO\n "
16561659 " #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 " ));
16581661 }
16591662
16601663 void define_if4 () {
16611664 const char filedata[] = " #define X +123\n "
16621665 " #if X==123\n "
16631666 " FOO\n "
16641667 " #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 " ));
16661669 }
16671670
16681671 void define_if5 () { // #4516 - #define B (A & 0x00f0)
@@ -1672,7 +1675,7 @@ class TestPreprocessor : public TestFixture {
16721675 " #if B==0x0010\n "
16731676 " FOO\n "
16741677 " #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 " ));
16761679 }
16771680 {
16781681 const char filedata[] = " #define A 0x00f0\n "
@@ -1681,14 +1684,14 @@ class TestPreprocessor : public TestFixture {
16811684 " #if C==0x0010\n "
16821685 " FOO\n "
16831686 " #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 " ));
16851688 }
16861689 {
16871690 const char filedata[] = " #define A (1+A)\n " // don't hang for recursive macros
16881691 " #if A==1\n "
16891692 " FOO\n "
16901693 " #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 " ));
16921695 }
16931696 }
16941697
0 commit comments