[flang] WRF preprocessing tweaks

Original-commit: flang-compiler/f18@53f76e1c93
Reviewed-on: https://github.com/flang-compiler/f18/pull/333
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2019-03-14 13:53:35 -07:00
parent 3204a1c1b9
commit 3348b1691d
3 changed files with 20 additions and 5 deletions

View file

@ -40,6 +40,7 @@ Prescanner::Prescanner(const Prescanner &that)
inFixedForm_{that.inFixedForm_},
fixedFormColumnLimit_{that.fixedFormColumnLimit_},
encoding_{that.encoding_}, prescannerNesting_{that.prescannerNesting_ + 1},
skipLeadingAmpersand_{that.skipLeadingAmpersand_},
compilerDirectiveBloomFilter_{that.compilerDirectiveBloomFilter_},
compilerDirectiveSentinels_{that.compilerDirectiveSentinels_} {}
@ -145,6 +146,13 @@ void Prescanner::Statement() {
BeginSourceLineAndAdvance();
if (inFixedForm_) {
LabelField(tokens);
} else if (skipLeadingAmpersand_) {
skipLeadingAmpersand_ = false;
const char *p{SkipWhiteSpace(at_)};
if (p < limit_ && *p == '&') {
column_ += ++p - at_;
at_ = p;
}
} else {
SkipSpaces();
}
@ -679,7 +687,7 @@ bool Prescanner::SkipCommentLine(bool afterAmpersand) {
if (lineStart_ >= limit_) {
if (afterAmpersand && prescannerNesting_ > 0) {
// A continuation marker at the end of the last line in an
// include file inhibits the newline.
// include file inhibits the newline for that line.
SkipToEndOfLine();
omitNewline_ = true;
}
@ -702,6 +710,7 @@ bool Prescanner::SkipCommentLine(bool afterAmpersand) {
lineClass.kind == LineClassification::Kind::IncludeLine)) {
SkipToEndOfLine();
omitNewline_ = true;
skipLeadingAmpersand_ = true;
return false;
} else {
return false;
@ -841,8 +850,12 @@ bool Prescanner::FreeFormContinuation() {
if (ampersand) {
p = SkipWhiteSpace(p + 1);
}
if (*p != '\n' && (inCharLiteral_ || *p != '!')) {
return false;
if (*p != '\n') {
if (inCharLiteral_) {
return false;
} else if (*p != '!') {
Say(GetProvenance(p), "treated as comment after &"_en_US);
}
}
do {
if (const char *cont{FreeFormContinuationLine(ampersand)}) {

View file

@ -205,6 +205,7 @@ private:
// the line before. Also used when the & appears at the end of the last
// line in an include file.
bool omitNewline_{false};
bool skipLeadingAmpersand_{false};
const Provenance spaceProvenance_{
cooked_.allSources().CompilerInsertionProvenance(' ')};

View file

@ -190,6 +190,7 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
return {};
}
if (driver.dumpCookedChars) {
parsing.messages().Emit(std::cerr, parsing.cooked());
parsing.DumpCookedChars(std::cout);
return {};
}
@ -219,8 +220,8 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
}
// TODO: Change this predicate to just "if (!driver.debugNoSemantics)"
if (driver.debugSemantics || driver.debugResolveNames || driver.dumpSymbols ||
driver.dumpUnparseWithSymbols ||
driver.debugLinearFIR || driver.dumpGraph) {
driver.dumpUnparseWithSymbols || driver.debugLinearFIR ||
driver.dumpGraph) {
Fortran::semantics::Semantics semantics{
semanticsContext, parseTree, parsing.cooked()};
semantics.Perform();