namespace parser {
Prescanner::Prescanner(Messages *messages, AllSources *allSources)
- : messages_{messages}, allSources_{allSources}, preprocessor_{*this} {
- std::string compilerInserts{" ,\"01"};
+ : messages_{messages}, allSources_{allSources}, start_{&(*allSources)[0]},
+ limit_{start_ + allSources->size()}, preprocessor_{*this} {
+ std::string compilerInserts{" ,\"01\n"};
ProvenanceRange range{allSources->AddCompilerInsertion(compilerInserts)};
for (size_t j{0}; j < compilerInserts.size(); ++j) {
compilerInsertionProvenance_[compilerInserts[j]] = range.start + j;
}
+ newlineProvenance_ = CompilerInsertionProvenance('\n');
}
CookedSource Prescanner::Prescan() {
- startProvenance_ = 0;
- start_ = &(*allSources_)[0];
- limit_ = start_ + allSources_->size();
lineStart_ = start_;
BeginSourceLine(start_);
TokenSequence tokens, preprocessed;
while (NextToken(&tokens)) {
}
if (preprocessor_.MacroReplacement(tokens, &preprocessed)) {
- EmitChar(&preprocessed, '\n');
+ preprocessed.PutNextTokenChar('\n', newlineProvenance_);
preprocessed.CloseToken();
if (IsFixedFormCommentLine(preprocessed.data()) ||
IsFreeFormComment(preprocessed.data())) {
tokens.EmitWithCaseConversion(&cooked);
}
tokens.clear();
- cooked.Put('\n', 0);
+ cooked.Put('\n', newlineProvenance_);
PayNewlineDebt(&cooked);
}
PayNewlineDebt(&cooked);
}
void Prescanner::NextChar() {
- // CHECK(*at_ != '\n');
+ CHECK(*at_ != '\n'); // TODO pmk
++at_;
++column_;
if (inPreprocessorDirective_) {
}
bool Prescanner::NextToken(TokenSequence *tokens) {
+ CHECK(at_ > start_ && at_ < limit_); // TODO pmk
if (inFixedForm_) {
SkipSpaces();
} else if (*at_ == ' ' || *at_ == '\t') {
void Prescanner::PayNewlineDebt(CookedSource *cooked) {
for (; newlineDebt_ > 0; --newlineDebt_) {
- cooked->Put('\n', 0);
+ cooked->Put('\n', newlineProvenance_);
}
}
} // namespace parser
}
Provenance GetProvenance(const char *sourceChar) const {
- return startProvenance_ + sourceChar - start_;
+ return startProvenance_ /*TODO pmk rm?*/ + sourceChar - start_;
}
void EmitChar(TokenSequence *tokens, char ch) {
Messages *messages_;
AllSources *allSources_;
- Provenance startProvenance_;
+ Provenance startProvenance_{0};
const char *start_{nullptr}; // beginning of sourceFile_ content
const char *limit_{nullptr}; // first address after end of source
const char *at_{nullptr}; // next character to process; < lineStart_
int delimiterNesting_{0};
Preprocessor preprocessor_;
std::map<char, Provenance> compilerInsertionProvenance_;
+ Provenance newlineProvenance_{0};
};
} // namespace parser
} // namespace Fortran