33
33
#include < list>
34
34
#include < map>
35
35
#include < set>
36
- #include < sstream>
37
36
#include < string>
38
37
#include < vector>
39
38
@@ -48,11 +47,11 @@ class TestPreprocessor : public TestFixture {
48
47
class OurPreprocessor : public Preprocessor {
49
48
public:
50
49
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) {
53
52
simplecpp::OutputList outputList;
54
53
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);
56
55
std::map<std::string, simplecpp::TokenList*> filedata;
57
56
simplecpp::TokenList tokens2 (files);
58
57
simplecpp::preprocess (tokens2, tokens1, files, filedata, simplecpp::DUI (), &outputList);
@@ -268,16 +267,16 @@ class TestPreprocessor : public TestFixture {
268
267
TEST_CASE (hashCalculation);
269
268
}
270
269
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) {
272
272
Settings settings;
273
273
if (arg && std::strncmp (arg," -D" ,2 )==0 )
274
274
settings.userDefines = arg + 2 ;
275
275
if (arg && std::strncmp (arg," -U" ,2 )==0 )
276
276
settings.userUndefs .insert (arg+2 );
277
277
Preprocessor preprocessor (settings, *this );
278
278
std::vector<std::string> files;
279
- std::istringstream istr (filedata);
280
- simplecpp::TokenList tokens (istr,files);
279
+ simplecpp::TokenList tokens (code,size-1 ,files);
281
280
tokens.removeComments ();
282
281
const std::set<std::string> configs = preprocessor.getConfigs (tokens);
283
282
std::string ret;
@@ -286,12 +285,12 @@ class TestPreprocessor : public TestFixture {
286
285
return ret;
287
286
}
288
287
289
- std::size_t getHash (const char filedata[]) {
288
+ template <size_t size>
289
+ std::size_t getHash (const char (&code)[size]) {
290
290
Settings settings;
291
291
Preprocessor preprocessor (settings, *this );
292
292
std::vector<std::string> files;
293
- std::istringstream istr (filedata);
294
- simplecpp::TokenList tokens (istr,files);
293
+ simplecpp::TokenList tokens (code,size-1 ,files);
295
294
tokens.removeComments ();
296
295
return preprocessor.calculateHash (tokens, " " );
297
296
}
@@ -444,9 +443,8 @@ class TestPreprocessor : public TestFixture {
444
443
" #else\n "
445
444
" 2\n "
446
445
" #endif\n " ;
447
- std::istringstream istr (filedata);
448
446
std::vector<std::string> files;
449
- simplecpp::TokenList tokens (istr , files, " test.c" );
447
+ simplecpp::TokenList tokens (filedata, sizeof (filedata) , files, " test.c" );
450
448
451
449
// preprocess code with unix32 platform..
452
450
{
@@ -769,7 +767,7 @@ class TestPreprocessor : public TestFixture {
769
767
}
770
768
771
769
void if_macro_eq_macro () {
772
- const char * code = " #define A B\n "
770
+ const char code[] = " #define A B\n "
773
771
" #define B 1\n "
774
772
" #define C 1\n "
775
773
" #if A == C\n "
@@ -781,7 +779,7 @@ class TestPreprocessor : public TestFixture {
781
779
}
782
780
783
781
void ticket_3675 () {
784
- const char * code = " #ifdef YYSTACKSIZE\n "
782
+ const char code[] = " #ifdef YYSTACKSIZE\n "
785
783
" #define YYMAXDEPTH YYSTACKSIZE\n "
786
784
" #else\n "
787
785
" #define YYSTACKSIZE YYMAXDEPTH\n "
@@ -794,7 +792,7 @@ class TestPreprocessor : public TestFixture {
794
792
}
795
793
796
794
void ticket_3699 () {
797
- const char * code = " #define INLINE __forceinline\n "
795
+ const char code[] = " #define INLINE __forceinline\n "
798
796
" #define inline __forceinline\n "
799
797
" #define __forceinline inline\n "
800
798
" #if !defined(_WIN32)\n "
@@ -807,7 +805,7 @@ class TestPreprocessor : public TestFixture {
807
805
}
808
806
809
807
void ticket_4922 () { // #4922
810
- const char * code = " __asm__ \n "
808
+ const char code[] = " __asm__ \n "
811
809
" { int extern __value) 0; (double return (\"\" } extern\n "
812
810
" __typeof __finite (__finite) __finite __inline \" __GI___finite\" );" ;
813
811
(void )PreprocessorHelper::getcode (settings0, *this , code);
@@ -2229,7 +2227,7 @@ class TestPreprocessor : public TestFixture {
2229
2227
}
2230
2228
2231
2229
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 "
2233
2231
" Fred & Wilma\n "
2234
2232
" #elif sizeof(unsigned short) == 4\n "
2235
2233
" Fred & Wilma\n "
0 commit comments