@@ -44,81 +44,55 @@ namespace tinyxml2 {
4444// TODO: make Tokenizer private
4545class SimpleTokenizer : public Tokenizer {
4646public:
47- template <size_t size>
48- SimpleTokenizer (ErrorLogger& errorlogger, const char (&code)[size], bool cpp = true)
47+ explicit SimpleTokenizer (ErrorLogger& errorlogger, bool cpp = true )
4948 : Tokenizer{s_settings, errorlogger}
5049 {
51- if (!tokenize (code, cpp))
52- throw std::runtime_error (" creating tokens failed" );
50+ list.setLang (cpp ? Standards::Language::CPP : Standards::Language::C, true );
5351 }
5452
55- SimpleTokenizer (const Settings& settings, ErrorLogger& errorlogger)
53+ SimpleTokenizer (const Settings& settings, ErrorLogger& errorlogger, bool cpp = true )
5654 : Tokenizer{settings, errorlogger}
57- {}
58-
59- /*
60- Token* tokens() {
61- return Tokenizer::tokens();
62- }
63-
64- const Token* tokens() const {
65- return Tokenizer::tokens();
66- }
67- */
68-
69- template <size_t size>
70- bool tokenize (const char (&code)[size],
71- const std::string& filename,
72- const std::string &configuration = "")
7355 {
74- std::istringstream istr (code);
75- return tokenize (istr, filename, configuration);
56+ list.setLang (cpp ? Standards::Language::CPP : Standards::Language::C, true );
7657 }
7758
78- template <size_t size>
79- bool tokenize (const char (&code)[size],
80- bool cpp = true,
81- const std::string &configuration = "")
59+ SimpleTokenizer (const Settings& settings, ErrorLogger& errorlogger, const std::string& filename)
60+ : Tokenizer{settings, errorlogger}
8261 {
83- std::istringstream istr (code );
84- return tokenize (istr, std::string (cpp ? " test.cpp " : " test.c " ), configuration );
62+ list. setLang ( Path::identify (filename, false ) );
63+ list. appendFileIfNew (filename );
8564 }
8665
87- bool tokenize (const std::string& code,
88- const std::string& filename,
89- const std::string &configuration = " " )
66+ template <size_t size>
67+ bool tokenize (const char (&code)[size])
9068 {
9169 std::istringstream istr (code);
92- return tokenize (istr, filename, configuration );
70+ return tokenize (istr, std::string (list. isCPP () ? " test.cpp " : " test.c " ) );
9371 }
9472
95- bool tokenize (const std::string& code,
96- bool cpp = true ,
97- const std::string &configuration = " " )
73+ bool tokenize (const std::string& code)
9874 {
9975 std::istringstream istr (code);
100- return tokenize (istr, std::string (cpp ? " test.cpp" : " test.c" ), configuration );
76+ return tokenize (istr, std::string (list. isCPP () ? " test.cpp" : " test.c" ));
10177 }
10278
10379private:
10480 /* *
10581 * Tokenize code
10682 * @param istr The code as stream
10783 * @param filename Indicates if the code is C++
108- * @param configuration E.g. "A" for code where "#ifdef A" is true
10984 * @return false if source code contains syntax errors
11085 */
11186 bool tokenize (std::istream& istr,
112- const std::string& filename,
113- const std::string &configuration = " " )
87+ const std::string& filename)
11488 {
11589 if (list.front ())
11690 throw std::runtime_error (" token list is not empty" );
11791 list.appendFileIfNew (filename);
11892 if (!list.createTokens (istr, Path::identify (filename, false )))
11993 return false ;
12094
121- return simplifyTokens1 (configuration );
95+ return simplifyTokens1 (" " );
12296 }
12397
12498 // TODO: find a better solution
0 commit comments