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 @@ -18,6 +18,7 @@ int main(int argc, char **argv)
18
18
const char *filename = nullptr ;
19
19
bool use_istream = false ;
20
20
bool fail_on_error = false ;
21
+ bool linenrs = false ;
21
22
22
23
// Settings..
23
24
simplecpp::DUI dui;
@@ -74,6 +75,10 @@ int main(int argc, char **argv)
74
75
fail_on_error = true ;
75
76
found = true ;
76
77
break ;
78
+ case ' l' :
79
+ linenrs = true ;
80
+ found = true ;
81
+ break ;
77
82
}
78
83
if (!found) {
79
84
std::cout << " error: option '" << arg << " ' is unknown." << std::endl;
@@ -107,6 +112,7 @@ int main(int argc, char **argv)
107
112
std::cout << " -is Use std::istream interface." << std::endl;
108
113
std::cout << " -e Output errors only." << std::endl;
109
114
std::cout << " -f Fail when errors were encountered (exitcode 1)." << std::endl;
115
+ std::cout << " -l Print lines numbers." << std::endl;
110
116
std::exit (0 );
111
117
}
112
118
@@ -137,7 +143,7 @@ int main(int argc, char **argv)
137
143
// Output
138
144
if (!quiet) {
139
145
if (!error_only)
140
- std::cout << outputTokens.stringify () << std::endl;
146
+ std::cout << outputTokens.stringify (linenrs ) << std::endl;
141
147
142
148
for (const simplecpp::Output &output : outputList) {
143
149
std::cerr << output.location .file () << ' :' << output.location .line << " : " ;
Original file line number Diff line number Diff line change @@ -546,24 +546,33 @@ void simplecpp::TokenList::push_back(Token *tok)
546
546
backToken = tok;
547
547
}
548
548
549
- void simplecpp::TokenList::dump () const
549
+ void simplecpp::TokenList::dump (bool linenrs ) const
550
550
{
551
- std::cout << stringify () << std::endl;
551
+ std::cout << stringify (linenrs ) << std::endl;
552
552
}
553
553
554
- std::string simplecpp::TokenList::stringify () const
554
+ std::string simplecpp::TokenList::stringify (bool linenrs ) const
555
555
{
556
556
std::ostringstream ret;
557
557
Location loc (files);
558
+ bool filechg = true ;
558
559
for (const Token *tok = cfront (); tok; tok = tok->next ) {
559
560
if (tok->location .line < loc.line || tok->location .fileIndex != loc.fileIndex ) {
560
561
ret << " \n #line " << tok->location .line << " \" " << tok->location .file () << " \"\n " ;
561
562
loc = tok->location ;
563
+ filechg = true ;
564
+ }
565
+
566
+ if (linenrs && filechg) {
567
+ ret << loc.line << " : " ;
568
+ filechg = false ;
562
569
}
563
570
564
571
while (tok->location .line > loc.line ) {
565
572
ret << ' \n ' ;
566
573
loc.line ++;
574
+ if (linenrs)
575
+ ret << loc.line << " : " ;
567
576
}
568
577
569
578
if (sameline (tok->previous , tok))
Original file line number Diff line number Diff line change @@ -288,8 +288,8 @@ namespace simplecpp {
288
288
}
289
289
void push_back (Token *tok);
290
290
291
- void dump () const ;
292
- std::string stringify () const ;
291
+ void dump (bool linenrs = false ) const ;
292
+ std::string stringify (bool linenrs = false ) const ;
293
293
294
294
void readfile (Stream &stream, const std::string &filename=std::string(), OutputList *outputList = nullptr);
295
295
void constFold ();
You can’t perform that action at this time.
0 commit comments