@@ -50,11 +50,11 @@ class TestPreprocessor : public TestFixture {
5050 TestPreprocessor () : TestFixture(" TestPreprocessor" ) {}
5151
5252private:
53- std::string expandMacros ( const char code[], ErrorLogger &errorLogger) const {
54- std::istringstream istr ( code);
53+ template < size_t size>
54+ std::string expandMacros ( const char (& code)[size], ErrorLogger &errorLogger) {
5555 simplecpp::OutputList outputList;
5656 std::vector<std::string> files;
57- const simplecpp::TokenList tokens1 = simplecpp::TokenList (istr , files, " file.cpp" , &outputList);
57+ const simplecpp::TokenList tokens1 = simplecpp::TokenList (code, size- 1 , files, " file.cpp" , &outputList);
5858 Preprocessor p (settingsDefault, errorLogger, Path::identify (tokens1.getFiles ()[0 ], false ));
5959 simplecpp::TokenList tokens2 = p.preprocess (tokens1, " " , files, true );
6060 p.reportOutput (outputList, true );
@@ -301,16 +301,16 @@ class TestPreprocessor : public TestFixture {
301301 TEST_CASE (standard);
302302 }
303303
304- std::string getConfigsStr (const char filedata[], const char *arg = nullptr ) {
304+ template <size_t size>
305+ std::string getConfigsStr (const char (&code)[size], const char *arg = nullptr) {
305306 Settings settings;
306307 if (arg && std::strncmp (arg," -D" ,2 )==0 )
307308 settings.userDefines = arg + 2 ;
308309 if (arg && std::strncmp (arg," -U" ,2 )==0 )
309310 settings.userUndefs .insert (arg+2 );
310311 std::vector<std::string> files;
311- std::istringstream istr (filedata);
312312 // TODO: this adds an empty filename
313- simplecpp::TokenList tokens (istr ,files);
313+ simplecpp::TokenList tokens (code,size- 1 ,files);
314314 tokens.removeComments ();
315315 Preprocessor preprocessor (settings, *this , Standards::Language::C); // TODO: do we need to consider #file?
316316 const std::set<std::string> configs = preprocessor.getConfigs (tokens);
@@ -320,11 +320,11 @@ class TestPreprocessor : public TestFixture {
320320 return ret;
321321 }
322322
323- std::size_t getHash (const char filedata[]) {
323+ template <size_t size>
324+ std::size_t getHash (const char (&code)[size]) {
324325 std::vector<std::string> files;
325- std::istringstream istr (filedata);
326326 // TODO: this adds an empty filename
327- simplecpp::TokenList tokens (istr ,files);
327+ simplecpp::TokenList tokens (code,size- 1 ,files);
328328 tokens.removeComments ();
329329 Preprocessor preprocessor (settingsDefault, *this , Standards::Language::C); // TODO: do we need to consider #file?
330330 return preprocessor.calculateHash (tokens, " " );
@@ -478,9 +478,8 @@ class TestPreprocessor : public TestFixture {
478478 " #else\n "
479479 " 2\n "
480480 " #endif\n " ;
481- std::istringstream istr (filedata);
482481 std::vector<std::string> files;
483- simplecpp::TokenList tokens (istr , files, " test.c" );
482+ simplecpp::TokenList tokens (filedata, sizeof (filedata) , files, " test.c" );
484483
485484 // preprocess code with unix32 platform..
486485 {
@@ -803,47 +802,47 @@ class TestPreprocessor : public TestFixture {
803802 }
804803
805804 void if_macro_eq_macro () {
806- const char * code = " #define A B\n "
807- " #define B 1\n "
808- " #define C 1\n "
809- " #if A == C\n "
810- " Wilma\n "
811- " #else\n "
812- " Betty\n "
813- " #endif\n " ;
805+ const char code[] = " #define A B\n "
806+ " #define B 1\n "
807+ " #define C 1\n "
808+ " #if A == C\n "
809+ " Wilma\n "
810+ " #else\n "
811+ " Betty\n "
812+ " #endif\n " ;
814813 ASSERT_EQUALS (" \n " , getConfigsStr (code));
815814 }
816815
817816 void ticket_3675 () {
818- const char * code = " #ifdef YYSTACKSIZE\n "
819- " #define YYMAXDEPTH YYSTACKSIZE\n "
820- " #else\n "
821- " #define YYSTACKSIZE YYMAXDEPTH\n "
822- " #endif\n "
823- " #if YYDEBUG\n "
824- " #endif\n " ;
817+ const char code[] = " #ifdef YYSTACKSIZE\n "
818+ " #define YYMAXDEPTH YYSTACKSIZE\n "
819+ " #else\n "
820+ " #define YYSTACKSIZE YYMAXDEPTH\n "
821+ " #endif\n "
822+ " #if YYDEBUG\n "
823+ " #endif\n " ;
825824 (void )PreprocessorHelper::getcode (settings0, *this , code);
826825
827826 // There's nothing to assert. It just needs to not hang.
828827 }
829828
830829 void ticket_3699 () {
831- const char * code = " #define INLINE __forceinline\n "
832- " #define inline __forceinline\n "
833- " #define __forceinline inline\n "
834- " #if !defined(_WIN32)\n "
835- " #endif\n "
836- " INLINE inline __forceinline\n " ;
830+ const char code[] = " #define INLINE __forceinline\n "
831+ " #define inline __forceinline\n "
832+ " #define __forceinline inline\n "
833+ " #if !defined(_WIN32)\n "
834+ " #endif\n "
835+ " INLINE inline __forceinline\n " ;
837836 const std::map<std::string, std::string> actual = PreprocessorHelper::getcode (settings0, *this , code);
838837
839838 // First, it must not hang. Second, inline must becomes inline, and __forceinline must become __forceinline.
840839 ASSERT_EQUALS (" \n\n\n\n\n $__forceinline $inline $__forceinline" , actual.at (" " ));
841840 }
842841
843842 void ticket_4922 () { // #4922
844- const char * code = " __asm__ \n "
845- " { int extern __value) 0; (double return (\"\" } extern\n "
846- " __typeof __finite (__finite) __finite __inline \" __GI___finite\" );" ;
843+ const char code[] = " __asm__ \n "
844+ " { int extern __value) 0; (double return (\"\" } extern\n "
845+ " __typeof __finite (__finite) __finite __inline \" __GI___finite\" );" ;
847846 (void )PreprocessorHelper::getcode (settings0, *this , code);
848847 }
849848
@@ -2286,12 +2285,12 @@ class TestPreprocessor : public TestFixture {
22862285 }
22872286
22882287 void if_sizeof () { // #4071
2289- static const char * code = " #if sizeof(unsigned short) == 2\n "
2290- " Fred & Wilma\n "
2291- " #elif sizeof(unsigned short) == 4\n "
2292- " Fred & Wilma\n "
2293- " #else\n "
2294- " #endif" ;
2288+ const char code[] = " #if sizeof(unsigned short) == 2\n "
2289+ " Fred & Wilma\n "
2290+ " #elif sizeof(unsigned short) == 4\n "
2291+ " Fred & Wilma\n "
2292+ " #else\n "
2293+ " #endif" ;
22952294
22962295 const std::map<std::string, std::string> actual = PreprocessorHelper::getcode (settings0, *this , code);
22972296 ASSERT_EQUALS (" \n Fred & Wilma" , actual.at (" " ));
0 commit comments