[flang] Clean out obsolete parsing code. Handle !cdir$ fixed and free in parser.
Work on scanning compiler directive lines.
Fix glitch in earlier change to parse-state.h.
Add ClassifyLine(), simplify some token sequence data lifetimes and interfaces.
Handle continued directives. Obey !DIR$ FIXED and FREE in prescanner.
Some refactoring of TokenSequence API, then support initial directives (FIXED, FREE, IGNORE_TKR).
Fix !DIR$ IGNORE_TKR syntax, manual was wrong.
Debugging directive scanning & parsing.
Profiling-directed speed-up - do not map cooked source locations to Provenance until a Message is emitted. Turn some non-nullable pointers into references.
Debugging.
Handle !DIR$ IVDEP too, it is in a test.
Accept directives in the execution part.
Original-commit: flang-compiler/f18@fb2ff367ec0609b7307771f927f22fd7bab5e180
Reviewed-on: https://github.com/flang-compiler/f18/pull/34
Tree-same-pre-rewrite: false
diff --git a/flang/lib/parser/preprocessor.h b/flang/lib/parser/preprocessor.h
index 2a67944..e0a50c7 100644
--- a/flang/lib/parser/preprocessor.h
+++ b/flang/lib/parser/preprocessor.h
@@ -28,7 +28,7 @@
Definition(const TokenSequence &, std::size_t firstToken, std::size_t tokens);
Definition(const std::vector<std::string> &argNames, const TokenSequence &,
std::size_t firstToken, std::size_t tokens, bool isVariadic = false);
- Definition(const std::string &predefined, AllSources *);
+ Definition(const std::string &predefined, AllSources &);
bool isFunctionLike() const { return isFunctionLike_; }
std::size_t argumentCount() const { return argumentCount_; }
@@ -39,7 +39,7 @@
bool set_isDisabled(bool disable);
- TokenSequence Apply(const std::vector<TokenSequence> &args, AllSources *);
+ TokenSequence Apply(const std::vector<TokenSequence> &args, AllSources &);
private:
static TokenSequence Tokenize(const std::vector<std::string> &argNames,
@@ -56,17 +56,13 @@
// Preprocessing state
class Preprocessor {
public:
- explicit Preprocessor(AllSources *);
+ explicit Preprocessor(AllSources &);
void Define(std::string macro, std::string value);
void Undefine(std::string macro);
- // When the input contains macros to be replaced, the new token sequence
- // is appended to the output and the returned value is true. When
- // no macro replacement is necessary, the output is unmodified and the
- // return value is false.
- bool MacroReplacement(
- const TokenSequence &, const Prescanner &, TokenSequence *);
+ std::optional<TokenSequence> MacroReplacement(
+ const TokenSequence &, const Prescanner &);
// Implements a preprocessor directive.
void Directive(const TokenSequence &, Prescanner *);
@@ -83,7 +79,7 @@
bool IsIfPredicateTrue(const TokenSequence &expr, std::size_t first,
std::size_t exprTokens, Prescanner *);
- AllSources *allSources_;
+ AllSources &allSources_;
std::list<std::string> names_;
std::unordered_map<CharBlock, Definition> definitions_;
std::stack<CanDeadElseAppear> ifStack_;