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);
@@ -268,16 +267,16 @@ class TestPreprocessor : public TestFixture {
268267 TEST_CASE (hashCalculation);
269268 }
270269
271- std::string getConfigsStr (const char filedata[], const char *arg = nullptr ) {
270+ template <size_t size>
271+ std::string getConfigsStr (const char (&code)[size], const char *arg = nullptr) {
272272 Settings settings;
273273 if (arg && std::strncmp (arg," -D" ,2 )==0 )
274274 settings.userDefines = arg + 2 ;
275275 if (arg && std::strncmp (arg," -U" ,2 )==0 )
276276 settings.userUndefs .insert (arg+2 );
277277 Preprocessor preprocessor (settings, *this );
278278 std::vector<std::string> files;
279- std::istringstream istr (filedata);
280- simplecpp::TokenList tokens (istr,files);
279+ simplecpp::TokenList tokens (code,size-1 ,files);
281280 tokens.removeComments ();
282281 const std::set<std::string> configs = preprocessor.getConfigs (tokens);
283282 std::string ret;
@@ -286,12 +285,12 @@ class TestPreprocessor : public TestFixture {
286285 return ret;
287286 }
288287
289- std::size_t getHash (const char filedata[]) {
288+ template <size_t size>
289+ std::size_t getHash (const char (&code)[size]) {
290290 Settings settings;
291291 Preprocessor preprocessor (settings, *this );
292292 std::vector<std::string> files;
293- std::istringstream istr (filedata);
294- simplecpp::TokenList tokens (istr,files);
293+ simplecpp::TokenList tokens (code,size-1 ,files);
295294 tokens.removeComments ();
296295 return preprocessor.calculateHash (tokens, " " );
297296 }
@@ -444,9 +443,8 @@ class TestPreprocessor : public TestFixture {
444443 " #else\n "
445444 " 2\n "
446445 " #endif\n " ;
447- std::istringstream istr (filedata);
448446 std::vector<std::string> files;
449- simplecpp::TokenList tokens (istr , files, " test.c" );
447+ simplecpp::TokenList tokens (filedata, sizeof (filedata) , files, " test.c" );
450448
451449 // preprocess code with unix32 platform..
452450 {
@@ -769,47 +767,47 @@ class TestPreprocessor : public TestFixture {
769767 }
770768
771769 void if_macro_eq_macro () {
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 " ;
770+ const char code[] = " #define A B\n "
771+ " #define B 1\n "
772+ " #define C 1\n "
773+ " #if A == C\n "
774+ " Wilma\n "
775+ " #else\n "
776+ " Betty\n "
777+ " #endif\n " ;
780778 ASSERT_EQUALS (" \n " , getConfigsStr (code));
781779 }
782780
783781 void ticket_3675 () {
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 " ;
782+ const char code[] = " #ifdef YYSTACKSIZE\n "
783+ " #define YYMAXDEPTH YYSTACKSIZE\n "
784+ " #else\n "
785+ " #define YYSTACKSIZE YYMAXDEPTH\n "
786+ " #endif\n "
787+ " #if YYDEBUG\n "
788+ " #endif\n " ;
791789 (void )PreprocessorHelper::getcode (settings0, *this , code);
792790
793791 // There's nothing to assert. It just needs to not hang.
794792 }
795793
796794 void ticket_3699 () {
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 " ;
795+ const char code[] = " #define INLINE __forceinline\n "
796+ " #define inline __forceinline\n "
797+ " #define __forceinline inline\n "
798+ " #if !defined(_WIN32)\n "
799+ " #endif\n "
800+ " INLINE inline __forceinline\n " ;
803801 const std::map<std::string, std::string> actual = PreprocessorHelper::getcode (settings0, *this , code);
804802
805803 // First, it must not hang. Second, inline must becomes inline, and __forceinline must become __forceinline.
806804 ASSERT_EQUALS (" \n\n\n\n\n $__forceinline $inline $__forceinline" , actual.at (" " ));
807805 }
808806
809807 void ticket_4922 () { // #4922
810- const char * code = " __asm__ \n "
811- " { int extern __value) 0; (double return (\"\" } extern\n "
812- " __typeof __finite (__finite) __finite __inline \" __GI___finite\" );" ;
808+ const char code[] = " __asm__ \n "
809+ " { int extern __value) 0; (double return (\"\" } extern\n "
810+ " __typeof __finite (__finite) __finite __inline \" __GI___finite\" );" ;
813811 (void )PreprocessorHelper::getcode (settings0, *this , code);
814812 }
815813
@@ -2229,12 +2227,12 @@ class TestPreprocessor : public TestFixture {
22292227 }
22302228
22312229 void if_sizeof () { // #4071
2232- static 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" ;
2230+ const char code[] = " #if sizeof(unsigned short) == 2\n "
2231+ " Fred & Wilma\n "
2232+ " #elif sizeof(unsigned short) == 4\n "
2233+ " Fred & Wilma\n "
2234+ " #else\n "
2235+ " #endif" ;
22382236
22392237 const std::map<std::string, std::string> actual = PreprocessorHelper::getcode (settings0, *this , code);
22402238 ASSERT_EQUALS (" \n Fred & Wilma" , actual.at (" " ));
0 commit comments