3333#include < list>
3434#include < map>
3535#include < set>
36- #include < sstream>
3736#include < string>
3837#include < vector>
3938
@@ -48,11 +47,11 @@ class TestPreprocessor : public TestFixture {
4847 class OurPreprocessor : public Preprocessor {
4948 public:
5049
51- static std::string expandMacros ( const char code[], ErrorLogger *errorLogger = nullptr ) {
52- std::istringstream istr ( code);
50+ template < size_t size>
51+ static std::string expandMacros ( const char (& code)[size], ErrorLogger *errorLogger = nullptr) {
5352 simplecpp::OutputList outputList;
5453 std::vector<std::string> files;
55- const simplecpp::TokenList tokens1 = simplecpp::TokenList (istr , files, " file.cpp" , &outputList);
54+ const simplecpp::TokenList tokens1 = simplecpp::TokenList (code, size- 1 , files, " file.cpp" , &outputList);
5655 std::map<std::string, simplecpp::TokenList*> filedata;
5756 simplecpp::TokenList tokens2 (files);
5857 simplecpp::preprocess (tokens2, tokens1, files, filedata, simplecpp::DUI (), &outputList);
@@ -270,16 +269,16 @@ class TestPreprocessor : public TestFixture {
270269 TEST_CASE (standard);
271270 }
272271
273- std::string getConfigsStr (const char filedata[], const char *arg = nullptr ) {
272+ template <size_t size>
273+ std::string getConfigsStr (const char (&code)[size], const char *arg = nullptr) {
274274 Settings settings;
275275 if (arg && std::strncmp (arg," -D" ,2 )==0 )
276276 settings.userDefines = arg + 2 ;
277277 if (arg && std::strncmp (arg," -U" ,2 )==0 )
278278 settings.userUndefs .insert (arg+2 );
279279 Preprocessor preprocessor (settings, *this );
280280 std::vector<std::string> files;
281- std::istringstream istr (filedata);
282- simplecpp::TokenList tokens (istr,files);
281+ simplecpp::TokenList tokens (code,size-1 ,files);
283282 tokens.removeComments ();
284283 const std::set<std::string> configs = preprocessor.getConfigs (tokens);
285284 std::string ret;
@@ -288,12 +287,12 @@ class TestPreprocessor : public TestFixture {
288287 return ret;
289288 }
290289
291- std::size_t getHash (const char filedata[]) {
290+ template <size_t size>
291+ std::size_t getHash (const char (&code)[size]) {
292292 Settings settings;
293293 Preprocessor preprocessor (settings, *this );
294294 std::vector<std::string> files;
295- std::istringstream istr (filedata);
296- simplecpp::TokenList tokens (istr,files);
295+ simplecpp::TokenList tokens (code,size-1 ,files);
297296 tokens.removeComments ();
298297 return preprocessor.calculateHash (tokens, " " );
299298 }
@@ -446,9 +445,8 @@ class TestPreprocessor : public TestFixture {
446445 " #else\n "
447446 " 2\n "
448447 " #endif\n " ;
449- std::istringstream istr (filedata);
450448 std::vector<std::string> files;
451- simplecpp::TokenList tokens (istr , files, " test.c" );
449+ simplecpp::TokenList tokens (filedata, sizeof (filedata) , files, " test.c" );
452450
453451 // preprocess code with unix32 platform..
454452 {
@@ -771,47 +769,47 @@ class TestPreprocessor : public TestFixture {
771769 }
772770
773771 void if_macro_eq_macro () {
774- const char * code = " #define A B\n "
775- " #define B 1\n "
776- " #define C 1\n "
777- " #if A == C\n "
778- " Wilma\n "
779- " #else\n "
780- " Betty\n "
781- " #endif\n " ;
772+ const char code[] = " #define A B\n "
773+ " #define B 1\n "
774+ " #define C 1\n "
775+ " #if A == C\n "
776+ " Wilma\n "
777+ " #else\n "
778+ " Betty\n "
779+ " #endif\n " ;
782780 ASSERT_EQUALS (" \n " , getConfigsStr (code));
783781 }
784782
785783 void ticket_3675 () {
786- const char * code = " #ifdef YYSTACKSIZE\n "
787- " #define YYMAXDEPTH YYSTACKSIZE\n "
788- " #else\n "
789- " #define YYSTACKSIZE YYMAXDEPTH\n "
790- " #endif\n "
791- " #if YYDEBUG\n "
792- " #endif\n " ;
784+ const char code[] = " #ifdef YYSTACKSIZE\n "
785+ " #define YYMAXDEPTH YYSTACKSIZE\n "
786+ " #else\n "
787+ " #define YYSTACKSIZE YYMAXDEPTH\n "
788+ " #endif\n "
789+ " #if YYDEBUG\n "
790+ " #endif\n " ;
793791 (void )PreprocessorHelper::getcode (settings0, *this , code);
794792
795793 // There's nothing to assert. It just needs to not hang.
796794 }
797795
798796 void ticket_3699 () {
799- const char * code = " #define INLINE __forceinline\n "
800- " #define inline __forceinline\n "
801- " #define __forceinline inline\n "
802- " #if !defined(_WIN32)\n "
803- " #endif\n "
804- " INLINE inline __forceinline\n " ;
797+ const char code[] = " #define INLINE __forceinline\n "
798+ " #define inline __forceinline\n "
799+ " #define __forceinline inline\n "
800+ " #if !defined(_WIN32)\n "
801+ " #endif\n "
802+ " INLINE inline __forceinline\n " ;
805803 const std::map<std::string, std::string> actual = PreprocessorHelper::getcode (settings0, *this , code);
806804
807805 // First, it must not hang. Second, inline must becomes inline, and __forceinline must become __forceinline.
808806 ASSERT_EQUALS (" \n\n\n\n\n $__forceinline $inline $__forceinline" , actual.at (" " ));
809807 }
810808
811809 void ticket_4922 () { // #4922
812- const char * code = " __asm__ \n "
813- " { int extern __value) 0; (double return (\"\" } extern\n "
814- " __typeof __finite (__finite) __finite __inline \" __GI___finite\" );" ;
810+ const char code[] = " __asm__ \n "
811+ " { int extern __value) 0; (double return (\"\" } extern\n "
812+ " __typeof __finite (__finite) __finite __inline \" __GI___finite\" );" ;
815813 (void )PreprocessorHelper::getcode (settings0, *this , code);
816814 }
817815
@@ -2231,12 +2229,12 @@ class TestPreprocessor : public TestFixture {
22312229 }
22322230
22332231 void if_sizeof () { // #4071
2234- static const char * code = " #if sizeof(unsigned short) == 2\n "
2235- " Fred & Wilma\n "
2236- " #elif sizeof(unsigned short) == 4\n "
2237- " Fred & Wilma\n "
2238- " #else\n "
2239- " #endif" ;
2232+ const char code[] = " #if sizeof(unsigned short) == 2\n "
2233+ " Fred & Wilma\n "
2234+ " #elif sizeof(unsigned short) == 4\n "
2235+ " Fred & Wilma\n "
2236+ " #else\n "
2237+ " #endif" ;
22402238
22412239 const std::map<std::string, std::string> actual = PreprocessorHelper::getcode (settings0, *this , code);
22422240 ASSERT_EQUALS (" \n Fred & Wilma" , actual.at (" " ));
0 commit comments