File tree Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,8 @@ class Preprocessor {
121
121
std::list<std::string> names_;
122
122
std::unordered_map<CharBlock, Definition> definitions_;
123
123
std::stack<CanDeadElseAppear> ifStack_;
124
+
125
+ unsigned int counter_val_{0 };
124
126
};
125
127
} // namespace Fortran::parser
126
128
#endif // FORTRAN_PARSER_PREPROCESSOR_H_
Original file line number Diff line number Diff line change 22
22
#include < memory>
23
23
#include < optional>
24
24
#include < set>
25
+ #include < string>
25
26
#include < utility>
26
27
#include < vector>
27
28
@@ -299,6 +300,7 @@ void Preprocessor::DefineStandardMacros() {
299
300
Define (" __FILE__" s, " __FILE__" s);
300
301
Define (" __LINE__" s, " __LINE__" s);
301
302
Define (" __TIMESTAMP__" s, " __TIMESTAMP__" s);
303
+ Define (" __COUNTER__" s, " __COUNTER__" s);
302
304
}
303
305
304
306
void Preprocessor::Define (const std::string ¯o, const std::string &value) {
@@ -421,6 +423,8 @@ std::optional<TokenSequence> Preprocessor::MacroReplacement(
421
423
repl = " \" " s + time + ' "' ;
422
424
}
423
425
}
426
+ } else if (name == " __COUNTER__" ) {
427
+ repl = std::to_string (counter_val_++);
424
428
}
425
429
if (!repl.empty ()) {
426
430
ProvenanceRange insert{allSources_.AddCompilerInsertion (repl)};
Original file line number Diff line number Diff line change
1
+ ! RUN: %flang -E %s | FileCheck %s
2
+ ! CHECK: print *, 0
3
+ ! CHECK: print *, 1
4
+ ! CHECK: print *, 2
5
+ ! Check incremental counter macro
6
+ #define foo bar
7
+ print * , __COUNTER__
8
+ print * , __COUNTER__
9
+ print * , __COUNTER__
You can’t perform that action at this time.
0 commit comments