File tree Expand file tree Collapse file tree 3 files changed +21
-6
lines changed Expand file tree Collapse file tree 3 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ int main(int argc, char **argv)
19
19
const char *filename = nullptr ;
20
20
bool use_istream = false ;
21
21
bool fail_on_error = false ;
22
+ bool linenrs = false ;
22
23
23
24
// Settings..
24
25
simplecpp::DUI dui;
@@ -102,6 +103,10 @@ int main(int argc, char **argv)
102
103
found = true ;
103
104
fail_on_error = true ;
104
105
break ;
106
+ case ' l' :
107
+ linenrs = true ;
108
+ found = true ;
109
+ break ;
105
110
}
106
111
if (!found) {
107
112
std::cout << " error: option '" << arg << " ' is unknown." << std::endl;
@@ -135,6 +140,7 @@ int main(int argc, char **argv)
135
140
std::cout << " -is Use std::istream interface." << std::endl;
136
141
std::cout << " -e Output errors only." << std::endl;
137
142
std::cout << " -f Fail when errors were encountered (exitcode 1)." << std::endl;
143
+ std::cout << " -l Print lines numbers." << std::endl;
138
144
std::exit (0 );
139
145
}
140
146
@@ -165,7 +171,7 @@ int main(int argc, char **argv)
165
171
// Output
166
172
if (!quiet) {
167
173
if (!error_only)
168
- std::cout << outputTokens.stringify () << std::endl;
174
+ std::cout << outputTokens.stringify (linenrs ) << std::endl;
169
175
170
176
for (const simplecpp::Output &output : outputList) {
171
177
std::cerr << output.location .file () << ' :' << output.location .line << " : " ;
Original file line number Diff line number Diff line change @@ -553,24 +553,33 @@ void simplecpp::TokenList::push_back(Token *tok)
553
553
backToken = tok;
554
554
}
555
555
556
- void simplecpp::TokenList::dump () const
556
+ void simplecpp::TokenList::dump (bool linenrs ) const
557
557
{
558
- std::cout << stringify () << std::endl;
558
+ std::cout << stringify (linenrs ) << std::endl;
559
559
}
560
560
561
- std::string simplecpp::TokenList::stringify () const
561
+ std::string simplecpp::TokenList::stringify (bool linenrs ) const
562
562
{
563
563
std::ostringstream ret;
564
564
Location loc (files);
565
+ bool filechg = true ;
565
566
for (const Token *tok = cfront (); tok; tok = tok->next ) {
566
567
if (tok->location .line < loc.line || tok->location .fileIndex != loc.fileIndex ) {
567
568
ret << " \n #line " << tok->location .line << " \" " << tok->location .file () << " \"\n " ;
568
569
loc = tok->location ;
570
+ filechg = true ;
571
+ }
572
+
573
+ if (linenrs && filechg) {
574
+ ret << loc.line << " : " ;
575
+ filechg = false ;
569
576
}
570
577
571
578
while (tok->location .line > loc.line ) {
572
579
ret << ' \n ' ;
573
580
loc.line ++;
581
+ if (linenrs)
582
+ ret << loc.line << " : " ;
574
583
}
575
584
576
585
if (sameline (tok->previous , tok))
Original file line number Diff line number Diff line change @@ -284,8 +284,8 @@ namespace simplecpp {
284
284
}
285
285
void push_back (Token *tok);
286
286
287
- void dump () const ;
288
- std::string stringify () const ;
287
+ void dump (bool linenrs = false ) const ;
288
+ std::string stringify (bool linenrs = false ) const ;
289
289
290
290
void readfile (Stream &stream, const std::string &filename=std::string(), OutputList *outputList = nullptr);
291
291
void constFold ();
You can’t perform that action at this time.
0 commit comments