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,7 +767,7 @@ class TestPreprocessor : public TestFixture {
769767 }
770768
771769 void if_macro_eq_macro () {
772- const char * code = " #define A B\n "
770+ const char code[] = " #define A B\n "
773771 " #define B 1\n "
774772 " #define C 1\n "
775773 " #if A == C\n "
@@ -781,7 +779,7 @@ class TestPreprocessor : public TestFixture {
781779 }
782780
783781 void ticket_3675 () {
784- const char * code = " #ifdef YYSTACKSIZE\n "
782+ const char code[] = " #ifdef YYSTACKSIZE\n "
785783 " #define YYMAXDEPTH YYSTACKSIZE\n "
786784 " #else\n "
787785 " #define YYSTACKSIZE YYMAXDEPTH\n "
@@ -794,7 +792,7 @@ class TestPreprocessor : public TestFixture {
794792 }
795793
796794 void ticket_3699 () {
797- const char * code = " #define INLINE __forceinline\n "
795+ const char code[] = " #define INLINE __forceinline\n "
798796 " #define inline __forceinline\n "
799797 " #define __forceinline inline\n "
800798 " #if !defined(_WIN32)\n "
@@ -807,7 +805,7 @@ class TestPreprocessor : public TestFixture {
807805 }
808806
809807 void ticket_4922 () { // #4922
810- const char * code = " __asm__ \n "
808+ const char code[] = " __asm__ \n "
811809 " { int extern __value) 0; (double return (\"\" } extern\n "
812810 " __typeof __finite (__finite) __finite __inline \" __GI___finite\" );" ;
813811 (void )PreprocessorHelper::getcode (settings0, *this , code);
@@ -2229,7 +2227,7 @@ class TestPreprocessor : public TestFixture {
22292227 }
22302228
22312229 void if_sizeof () { // #4071
2232- static const char * code = " #if sizeof(unsigned short) == 2\n "
2230+ const char code[] = " #if sizeof(unsigned short) == 2\n "
22332231 " Fred & Wilma\n "
22342232 " #elif sizeof(unsigned short) == 4\n "
22352233 " Fred & Wilma\n "
0 commit comments