diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-05-27 15:24:25 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-05-27 15:24:25 +0200 |
commit | 2e19434e09b819105055ddc8e58f69db98ec8669 (patch) | |
tree | e806e15f6e940a9135f0e7d8cf9ba08637512bd8 /unit-tests/cc/lexer/driver.cxx | |
parent | de417f02b2b1f3a02c5c9d206f399c574a93bf7f (diff) |
Handle #line directives in C/C++ lexer
This way the parser now reports logical rather than physical location in
diagnostics.
Diffstat (limited to 'unit-tests/cc/lexer/driver.cxx')
-rw-r--r-- | unit-tests/cc/lexer/driver.cxx | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/unit-tests/cc/lexer/driver.cxx b/unit-tests/cc/lexer/driver.cxx index db3f516..5803a88 100644 --- a/unit-tests/cc/lexer/driver.cxx +++ b/unit-tests/cc/lexer/driver.cxx @@ -16,38 +16,59 @@ namespace build2 { namespace cc { - // Usage: argv[0] [<file>] + // Usage: argv[0] [-l] [<file>] // int main (int argc, char* argv[]) { + bool loc (false); + const char* file (nullptr); + + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-l") + loc = true; + else + { + file = argv[i]; + break; + } + } + try { istream* is; - const char* in; // Reading from file is several times faster. // ifdstream ifs; - if (argc > 1) + if (file != nullptr) { - in = argv[1]; - ifs.open (in); + ifs.open (file); is = &ifs; } else { - in = "stdin"; + file = "stdin"; cin.exceptions (istream::failbit | istream::badbit); is = &cin; } - lexer l (*is, path (in)); + lexer l (*is, path (file)); // No use printing eos since we will either get it or loop forever. // for (token t; l.next (t) != token_type::eos; ) - cout << t << endl; + { + cout << t; + + if (loc) + cout << ' ' << t.file << ':' << t.line << ':' << t.column; + + cout << endl; + } } catch (const failed&) { |