1616 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19-
2019#include " astutils.h"
20+ #include " fixture.h"
21+ #include " helpers.h"
2122#include " library.h"
2223#include " settings.h"
23- #include " fixture.h"
2424#include " symboldatabase.h"
2525#include " token.h"
26- #include " tokenize.h"
2726#include " tokenlist.h"
2827
2928#include < cstring>
30- #include < sstream>
3129
3230class TestAstUtils : public TestFixture {
3331public:
@@ -54,9 +52,8 @@ class TestAstUtils : public TestFixture {
5452#define findLambdaEndToken (...) findLambdaEndToken_(__FILE__, __LINE__, __VA_ARGS__)
5553 bool findLambdaEndToken_ (const char * file, int line, const char code[], const char pattern[] = nullptr , bool checkNext = true ) {
5654 const Settings settings;
57- Tokenizer tokenizer (settings, this );
58- std::istringstream istr (code);
59- ASSERT_LOC (tokenizer.tokenize (istr, " test.cpp" ), file, line);
55+ SimpleTokenizer tokenizer (settings, *this );
56+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
6057 const Token* const tokStart = pattern ? Token::findsimplematch (tokenizer.tokens (), pattern, strlen (pattern)) : tokenizer.tokens ();
6158 const Token * const tokEnd = (::findLambdaEndToken)(tokStart);
6259 return tokEnd && (!checkNext || tokEnd->next () == nullptr );
@@ -92,9 +89,8 @@ class TestAstUtils : public TestFixture {
9289
9390#define findLambdaStartToken (code ) findLambdaStartToken_(code, __FILE__, __LINE__)
9491 bool findLambdaStartToken_ (const char code[], const char * file, int line) {
95- Tokenizer tokenizer (settingsDefault, this );
96- std::istringstream istr (code);
97- ASSERT_LOC (tokenizer.tokenize (istr, " test.cpp" ), file, line);
92+ SimpleTokenizer tokenizer (settingsDefault, *this );
93+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
9894 const Token * const tokStart = (::findLambdaStartToken)(tokenizer.list .back ());
9995 return tokStart && tokStart == tokenizer.list .front ();
10096 }
@@ -124,9 +120,8 @@ class TestAstUtils : public TestFixture {
124120
125121#define isNullOperand (code ) isNullOperand_(code, __FILE__, __LINE__)
126122 bool isNullOperand_ (const char code[], const char * file, int line) {
127- Tokenizer tokenizer (settingsDefault, this );
128- std::istringstream istr (code);
129- ASSERT_LOC (tokenizer.tokenize (istr, " test.cpp" ), file, line);
123+ SimpleTokenizer tokenizer (settingsDefault, *this );
124+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
130125 return (::isNullOperand)(tokenizer.tokens ());
131126 }
132127
@@ -145,9 +140,8 @@ class TestAstUtils : public TestFixture {
145140
146141#define isReturnScope (code, offset ) isReturnScope_(code, offset, __FILE__, __LINE__)
147142 bool isReturnScope_ (const char code[], int offset, const char * file, int line) {
148- Tokenizer tokenizer (settingsDefault, this );
149- std::istringstream istr (code);
150- ASSERT_LOC (tokenizer.tokenize (istr, " test.cpp" ), file, line);
143+ SimpleTokenizer tokenizer (settingsDefault, *this );
144+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
151145 const Token * const tok = (offset < 0 )
152146 ? tokenizer.list .back ()->tokAt (1 +offset)
153147 : tokenizer.tokens ()->tokAt (offset);
@@ -176,9 +170,8 @@ class TestAstUtils : public TestFixture {
176170#define isSameExpression (...) isSameExpression_(__FILE__, __LINE__, __VA_ARGS__)
177171 bool isSameExpression_ (const char * file, int line, const char code[], const char tokStr1[], const char tokStr2[], bool cpp) {
178172 Library library;
179- Tokenizer tokenizer (settingsDefault, this );
180- std::istringstream istr (code);
181- ASSERT_LOC (tokenizer.tokenize (istr, cpp ? " test.cpp" : " test.c" ), file, line);
173+ SimpleTokenizer tokenizer (settingsDefault, *this );
174+ ASSERT_LOC (tokenizer.tokenize (code, cpp), file, line);
182175 const Token * const tok1 = Token::findsimplematch (tokenizer.tokens (), tokStr1, strlen (tokStr1));
183176 const Token * const tok2 = Token::findsimplematch (tok1->next (), tokStr2, strlen (tokStr2));
184177 return (isSameExpression)(false , tok1, tok2, library, false , true , nullptr );
@@ -224,9 +217,8 @@ class TestAstUtils : public TestFixture {
224217
225218#define isVariableChanged (code, startPattern, endPattern ) isVariableChanged_(code, startPattern, endPattern, __FILE__, __LINE__)
226219 bool isVariableChanged_ (const char code[], const char startPattern[], const char endPattern[], const char * file, int line) {
227- Tokenizer tokenizer (settingsDefault, this );
228- std::istringstream istr (code);
229- ASSERT_LOC (tokenizer.tokenize (istr, " test.cpp" ), file, line);
220+ SimpleTokenizer tokenizer (settingsDefault, *this );
221+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
230222 const Token * const tok1 = Token::findsimplematch (tokenizer.tokens (), startPattern, strlen (startPattern));
231223 const Token * const tok2 = Token::findsimplematch (tokenizer.tokens (), endPattern, strlen (endPattern));
232224 return (isVariableChanged)(tok1, tok2, 1 , false , &settingsDefault);
@@ -258,9 +250,8 @@ class TestAstUtils : public TestFixture {
258250
259251#define isVariableChangedByFunctionCall (code, pattern, inconclusive ) isVariableChangedByFunctionCall_(code, pattern, inconclusive, __FILE__, __LINE__)
260252 bool isVariableChangedByFunctionCall_ (const char code[], const char pattern[], bool *inconclusive, const char * file, int line) {
261- Tokenizer tokenizer (settingsDefault, this );
262- std::istringstream istr (code);
263- ASSERT_LOC (tokenizer.tokenize (istr, " test.cpp" ), file, line);
253+ SimpleTokenizer tokenizer (settingsDefault, *this );
254+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
264255 const Token * const argtok = Token::findmatch (tokenizer.tokens (), pattern);
265256 ASSERT_LOC (argtok, file, line);
266257 int indirect = (argtok->variable () && argtok->variable ()->isArray ());
@@ -401,9 +392,8 @@ class TestAstUtils : public TestFixture {
401392 int line)
402393 {
403394 const Settings settings = settingsBuilder ().library (" std.cfg" ).build ();
404- Tokenizer tokenizer (settings, this );
405- std::istringstream istr (code);
406- ASSERT_LOC (tokenizer.tokenize (istr, " test.cpp" ), file, line);
395+ SimpleTokenizer tokenizer (settings, *this );
396+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
407397 const Token* const start = Token::findsimplematch (tokenizer.tokens (), startPattern, strlen (startPattern));
408398 const Token* const end = Token::findsimplematch (start, endPattern, strlen (endPattern));
409399 const Token* const expr = Token::findsimplematch (tokenizer.tokens (), var, strlen (var));
@@ -432,9 +422,8 @@ class TestAstUtils : public TestFixture {
432422
433423#define nextAfterAstRightmostLeaf (code, parentPattern, rightPattern ) nextAfterAstRightmostLeaf_(code, parentPattern, rightPattern, __FILE__, __LINE__)
434424 bool nextAfterAstRightmostLeaf_ (const char code[], const char parentPattern[], const char rightPattern[], const char * file, int line) {
435- Tokenizer tokenizer (settingsDefault, this );
436- std::istringstream istr (code);
437- ASSERT_LOC (tokenizer.tokenize (istr, " test.cpp" ), file, line);
425+ SimpleTokenizer tokenizer (settingsDefault, *this );
426+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
438427 const Token * tok = Token::findsimplematch (tokenizer.tokens (), parentPattern, strlen (parentPattern));
439428 return Token::simpleMatch ((::nextAfterAstRightmostLeaf)(tok), rightPattern, strlen (rightPattern));
440429 }
@@ -456,9 +445,8 @@ class TestAstUtils : public TestFixture {
456445 enum class Result {False, True, Fail};
457446
458447 Result isUsedAsBool (const char code[], const char pattern[]) {
459- Tokenizer tokenizer (settingsDefault, this );
460- std::istringstream istr (code);
461- if (!tokenizer.tokenize (istr, " test.cpp" ))
448+ SimpleTokenizer tokenizer (settingsDefault, *this );
449+ if (!tokenizer.tokenize (code))
462450 return Result::Fail;
463451 const Token * const argtok = Token::findmatch (tokenizer.tokens (), pattern);
464452 if (!argtok)
0 commit comments