-// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
+// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
interval_.ExtendToCover(that.interval_);
}
- bool IsBlank() const {
+ char FirstNonBlank() const {
for (char ch : *this) {
if (ch != ' ' && ch != '\t') {
- return false;
+ return ch;
}
}
- return true;
+ return ' '; // non no-blank character
}
+ bool IsBlank() const { return FirstNonBlank() == ' '; }
+
std::string ToString() const {
return std::string{interval_.start(), interval_.size()};
}
NormalizeCompilerDirectiveCommentMarker(*preprocessed);
preprocessed->ToLowerCase();
SourceFormChange(preprocessed->ToString());
- preprocessed->Emit(cooked_);
+ preprocessed->ClipComment().Emit(cooked_);
break;
case LineClassification::Kind::Source:
if (inFixedForm_) {
preprocessed->RemoveRedundantBlanks();
}
}
- preprocessed->ToLowerCase().Emit(cooked_);
+ preprocessed->ToLowerCase().ClipComment().Emit(cooked_);
break;
}
} else {
-// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
+// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
return *this;
}
+TokenSequence &TokenSequence::ClipComment() {
+ std::size_t tokens{SizeInTokens()};
+ for (std::size_t j{0}; j < tokens; ++j) {
+ if (TokenAt(j).FirstNonBlank() == '!') {
+ TokenSequence result;
+ if (j > 0) {
+ result.Put(*this, 0, j - 1);
+ }
+ swap(result);
+ return *this;
+ }
+ }
+ return *this;
+}
+
void TokenSequence::Emit(CookedSource &cooked) const {
cooked.Put(&char_[0], char_.size());
cooked.PutProvenanceMappings(provenances_);
-// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
+// Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
void Put(const CharBlock &, Provenance);
void Put(const std::string &, Provenance);
void Put(const std::stringstream &, Provenance);
+
Provenance GetTokenProvenance(
std::size_t token, std::size_t offset = 0) const;
ProvenanceRange GetTokenProvenanceRange(
bool HasRedundantBlanks(std::size_t firstChar = 0) const;
TokenSequence &RemoveBlanks(std::size_t firstChar = 0);
TokenSequence &RemoveRedundantBlanks(std::size_t firstChar = 0);
+ TokenSequence &ClipComment();
void Emit(CookedSource &) const;
void Dump(std::ostream &) const;