File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ int main(int argc, char **argv)
1818 const char *filename = nullptr ;
1919 bool use_istream = false ;
2020 bool fail_on_error = false ;
21+ bool linenrs = false ;
2122
2223 // Settings..
2324 simplecpp::DUI dui;
@@ -74,6 +75,10 @@ int main(int argc, char **argv)
7475 fail_on_error = true ;
7576 found = true ;
7677 break ;
78+ case ' l' :
79+ linenrs = true ;
80+ found = true ;
81+ break ;
7782 }
7883 if (!found) {
7984 std::cout << " error: option '" << arg << " ' is unknown." << std::endl;
@@ -106,6 +111,7 @@ int main(int argc, char **argv)
106111 std::cout << " -q Quiet mode (no output)." << std::endl;
107112 std::cout << " -is Use std::istream interface." << std::endl;
108113 std::cout << " -e Output errors only." << std::endl;
114+ std::cout << " -l Print lines numbers." << std::endl;
109115 std::exit (0 );
110116 }
111117
@@ -136,7 +142,7 @@ int main(int argc, char **argv)
136142 // Output
137143 if (!quiet) {
138144 if (!error_only)
139- std::cout << outputTokens.stringify () << std::endl;
145+ std::cout << outputTokens.stringify (linenrs ) << std::endl;
140146
141147 for (const simplecpp::Output &output : outputList) {
142148 std::cerr << output.location .file () << ' :' << output.location .line << " : " ;
Original file line number Diff line number Diff line change @@ -553,12 +553,12 @@ void simplecpp::TokenList::push_back(Token *tok)
553553 backToken = tok;
554554}
555555
556- void simplecpp::TokenList::dump () const
556+ void simplecpp::TokenList::dump (bool linenrs ) const
557557{
558- std::cout << stringify () << std::endl;
558+ std::cout << stringify (linenrs ) << std::endl;
559559}
560560
561- std::string simplecpp::TokenList::stringify () const
561+ std::string simplecpp::TokenList::stringify (bool linenrs ) const
562562{
563563 std::ostringstream ret;
564564 Location loc (files);
@@ -571,6 +571,8 @@ std::string simplecpp::TokenList::stringify() const
571571 while (tok->location .line > loc.line ) {
572572 ret << ' \n ' ;
573573 loc.line ++;
574+ if (linenrs)
575+ ret << loc.line << " : " ;
574576 }
575577
576578 if (sameline (tok->previous , tok))
Original file line number Diff line number Diff line change @@ -235,8 +235,8 @@ namespace simplecpp {
235235 }
236236 void push_back (Token *tok);
237237
238- void dump () const ;
239- std::string stringify () const ;
238+ void dump (bool linenrs = false ) const ;
239+ std::string stringify (bool linenrs = false ) const ;
240240
241241 void readfile (Stream &stream, const std::string &filename=std::string(), OutputList *outputList = nullptr);
242242 void constFold ();
You can’t perform that action at this time.
0 commit comments