diff --git a/.github/bin/check-potential-problems.sh b/.github/bin/check-potential-problems.sh index ac70e2d0f..cda23523d 100755 --- a/.github/bin/check-potential-problems.sh +++ b/.github/bin/check-potential-problems.sh @@ -19,17 +19,12 @@ EXIT_CODE=0 -# std::string_view::iterator is a const char* in gcc, clang, and absl C++ libs. -# This resulted into the assumption that it is in many places in this code base. -# -# On Windows the iterator is a wrapping object, so breaking that assumption. -# -# So, until these assumptions are fixed, we need to use absl::string_view that -# comes with the same implementation everywhere. +# absl has a string_view but there is also std::string_view. +# Use the std::string_view throughout. find verible -name "*.h" -o -name "*.cc" | \ - xargs grep -n "std::string_view" + xargs grep -n "absl::string_view" if [ $? -eq 0 ]; then - echo "::error:: use absl::string_view instead of std::string_view" + echo "::error:: use std::string_view instead of absl::string_view" echo EXIT_CODE=1 fi diff --git a/external_libs/BUILD b/external_libs/BUILD index c12312811..cd94f38f1 100644 --- a/external_libs/BUILD +++ b/external_libs/BUILD @@ -22,7 +22,6 @@ cc_test( deps = [ ":editscript", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/external_libs/editscript_test.cc b/external_libs/editscript_test.cc index c55780524..f680d6281 100644 --- a/external_libs/editscript_test.cc +++ b/external_libs/editscript_test.cc @@ -20,10 +20,10 @@ #include #include #include +#include #include #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace diff { @@ -168,8 +168,8 @@ TEST(DiffTest, CheckNonConstStringVectorDiffResults) { } TEST(DiffTest, CompleteDeletion) { - const std::vector tokens1{"the", "fox"}; - const std::vector tokens2; + const std::vector tokens1{"the", "fox"}; + const std::vector tokens2; const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(), tokens2.begin(), tokens2.end()); @@ -182,8 +182,8 @@ TEST(DiffTest, CompleteDeletion) { } TEST(DiffTest, CompleteInsertion) { - const std::vector tokens1; - const std::vector tokens2{"jumped", "over", "me"}; + const std::vector tokens1; + const std::vector tokens2{"jumped", "over", "me"}; const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(), tokens2.begin(), tokens2.end()); @@ -196,8 +196,8 @@ TEST(DiffTest, CompleteInsertion) { } TEST(DiffTest, ReplaceFromOneDifferentElement) { - const std::vector tokens1{"fox"}; - const std::vector tokens2{"jumped", "over", "me"}; + const std::vector tokens1{"fox"}; + const std::vector tokens2{"jumped", "over", "me"}; const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(), tokens2.begin(), tokens2.end()); @@ -211,8 +211,8 @@ TEST(DiffTest, ReplaceFromOneDifferentElement) { } TEST(DiffTest, ReplaceToOneDifferentElement) { - const std::vector tokens1{"jumped", "over", "me"}; - const std::vector tokens2{"fox"}; + const std::vector tokens1{"jumped", "over", "me"}; + const std::vector tokens2{"fox"}; const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(), tokens2.begin(), tokens2.end()); @@ -226,8 +226,8 @@ TEST(DiffTest, ReplaceToOneDifferentElement) { } TEST(DiffTest, CompleteReplacement) { - const std::vector tokens1{"the", "fox"}; - const std::vector tokens2{"jumped", "over", "me"}; + const std::vector tokens1{"the", "fox"}; + const std::vector tokens2{"jumped", "over", "me"}; const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(), tokens2.begin(), tokens2.end()); @@ -241,9 +241,9 @@ TEST(DiffTest, CompleteReplacement) { } TEST(DiffTest, StrictSubsequence) { - const std::vector tokens1{"the", "fox", "jumped", "over", - "the", "dog", "."}; - const std::vector tokens2{"fox", "jumped", "over"}; + const std::vector tokens1{"the", "fox", "jumped", "over", + "the", "dog", "."}; + const std::vector tokens2{"fox", "jumped", "over"}; const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(), tokens2.begin(), tokens2.end()); @@ -258,9 +258,9 @@ TEST(DiffTest, StrictSubsequence) { } TEST(DiffTest, StrictSupersequence) { - const std::vector tokens1{"fox", "jumped", "over"}; - const std::vector tokens2{"the", "fox", "jumped", "over", - "the", "dog", "."}; + const std::vector tokens1{"fox", "jumped", "over"}; + const std::vector tokens2{"the", "fox", "jumped", "over", + "the", "dog", "."}; const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(), tokens2.begin(), tokens2.end()); diff --git a/verible/common/analysis/BUILD b/verible/common/analysis/BUILD index e41a4452c..e777c0b0a 100644 --- a/verible/common/analysis/BUILD +++ b/verible/common/analysis/BUILD @@ -19,10 +19,7 @@ cc_library( name = "citation", srcs = ["citation.cc"], hdrs = ["citation.h"], - deps = [ - "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["@abseil-cpp//absl/strings"], ) cc_library( @@ -40,7 +37,6 @@ cc_library( "//verible/common/util:logging", "//verible/common/util:spacer", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -50,7 +46,6 @@ cc_library( deps = [ ":lint-rule-status", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -81,7 +76,6 @@ cc_library( "//verible/common/text:token-stream-view", "//verible/common/util:iterator-range", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -97,7 +91,6 @@ cc_library( "//verible/common/util:user-interaction", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -111,7 +104,6 @@ cc_test( "//verible/common/text:constants", "//verible/common/text:token-info", "//verible/common/text:token-info-test-util", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -138,7 +130,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], ) @@ -160,7 +151,6 @@ cc_library( "//verible/common/util:logging", "//verible/common/util:spacer", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -177,7 +167,6 @@ cc_library( "//verible/common/util:logging", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", # for library testonly ], ) @@ -195,7 +184,6 @@ cc_library( "//verible/common/text:tree-utils", "//verible/common/util:algorithm", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -207,7 +195,6 @@ cc_library( ":line-lint-rule", ":lint-rule-status", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -222,17 +209,13 @@ cc_library( ":linter-test-utils", "//verible/common/text:text-structure", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) cc_library( name = "line-lint-rule", hdrs = ["line-lint-rule.h"], - deps = [ - ":lint-rule", - "@abseil-cpp//absl/strings:string_view", - ], + deps = [":lint-rule"], ) cc_library( @@ -261,7 +244,6 @@ cc_library( ":syntax-tree-linter", "//verible/common/text:text-structure", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -301,7 +283,6 @@ cc_library( ":text-structure-lint-rule", "//verible/common/text:text-structure", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -316,7 +297,6 @@ cc_library( ":text-structure-linter", "//verible/common/text:text-structure", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -326,7 +306,6 @@ cc_library( deps = [ ":lint-rule", "//verible/common/text:text-structure", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -353,7 +332,6 @@ cc_library( ":token-stream-linter", "//verible/common/text:text-structure", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -375,7 +353,6 @@ cc_test( "//verible/common/text:token-info", "//verible/common/text:tree-builder-test-util", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -391,7 +368,6 @@ cc_test( "//verible/common/text:token-info", "//verible/common/text:token-stream-view", "//verible/common/util:iterator-range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -407,7 +383,6 @@ cc_test( "//verible/common/text:token-info", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -421,7 +396,6 @@ cc_test( ":linter-test-utils", "//verible/common/util:range", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -435,7 +409,6 @@ cc_test( ":line-linter", ":lint-rule-status", "//verible/common/text:token-info", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -455,7 +428,6 @@ cc_test( "//verible/common/text:token-info", "//verible/common/text:tree-builder-test-util", "//verible/common/util:casts", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -485,7 +457,6 @@ cc_test( "//verible/common/text:tree-builder-test-util", "//verible/common/util:range", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -501,7 +472,6 @@ cc_test( "//verible/common/text:text-structure", "//verible/common/text:token-info", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -516,7 +486,6 @@ cc_test( ":token-stream-linter", "//verible/common/text:token-info", "//verible/common/text:token-stream-view", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/common/analysis/citation.cc b/verible/common/analysis/citation.cc index ef8d23f2b..6b1b0dbad 100644 --- a/verible/common/analysis/citation.cc +++ b/verible/common/analysis/citation.cc @@ -15,12 +15,12 @@ #include "verible/common/analysis/citation.h" #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" namespace verible { -std::string GetStyleGuideCitation(absl::string_view topic) { +std::string GetStyleGuideCitation(std::string_view topic) { return absl::StrCat("[Style: ", topic, "]"); } } // namespace verible diff --git a/verible/common/analysis/citation.h b/verible/common/analysis/citation.h index 5f415fa5e..355889133 100644 --- a/verible/common/analysis/citation.h +++ b/verible/common/analysis/citation.h @@ -16,13 +16,12 @@ #define VERIBLE_COMMON_ANALYSIS_CITATION_H_ #include - -#include "absl/strings/string_view.h" +#include namespace verible { // Given a styleguide topic, return a reference to some styleguide // citation for the given topic (e.g. just the topic-name or an URL). -std::string GetStyleGuideCitation(absl::string_view topic); +std::string GetStyleGuideCitation(std::string_view topic); } // namespace verible #endif // VERIBLE_COMMON_ANALYSIS_CITATION_H_ diff --git a/verible/common/analysis/command-file-lexer.cc b/verible/common/analysis/command-file-lexer.cc index bf6086658..fe789eb59 100644 --- a/verible/common/analysis/command-file-lexer.cc +++ b/verible/common/analysis/command-file-lexer.cc @@ -15,9 +15,9 @@ #include "verible/common/analysis/command-file-lexer.h" #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/lexer/token-stream-adapter.h" #include "verible/common/text/token-info.h" #include "verible/common/text/token-stream-view.h" @@ -26,7 +26,7 @@ namespace verible { -CommandFileLexer::CommandFileLexer(absl::string_view config) +CommandFileLexer::CommandFileLexer(std::string_view config) : parent_lexer_type(config) { const auto lex_status = MakeTokenSequence( this, config, &tokens_, [&](const TokenInfo &error_token) { diff --git a/verible/common/analysis/command-file-lexer.h b/verible/common/analysis/command-file-lexer.h index 619c4ff35..cca080d86 100644 --- a/verible/common/analysis/command-file-lexer.h +++ b/verible/common/analysis/command-file-lexer.h @@ -15,10 +15,9 @@ #ifndef VERIBLE_CONFIG_FILE_LEXER_H_ #define VERIBLE_CONFIG_FILE_LEXER_H_ +#include #include -#include "absl/strings/string_view.h" - // lint_waiver_config.lex has "%prefix=verible", meaning the class flex // creates is veribleFlexLexer. Unfortunately, FlexLexer.h doesn't have proper // ifdefs around its inclusion, so we have to put a bar around it here. @@ -55,7 +54,7 @@ class CommandFileLexer : public FlexLexerAdapter { kError, }; - explicit CommandFileLexer(absl::string_view config); + explicit CommandFileLexer(std::string_view config); // Returns true if token is invalid. bool TokenIsError(const verible::TokenInfo &) const final; diff --git a/verible/common/analysis/command-file-lexer_test.cc b/verible/common/analysis/command-file-lexer_test.cc index 4e79643e2..4f5b6a8be 100644 --- a/verible/common/analysis/command-file-lexer_test.cc +++ b/verible/common/analysis/command-file-lexer_test.cc @@ -15,9 +15,9 @@ #include "verible/common/analysis/command-file-lexer.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/lexer/lexer-test-util.h" #include "verible/common/text/constants.h" @@ -30,7 +30,7 @@ namespace { // Removes non-essential tokens from token output stream, such as spaces. class FilteredCommandFileLexer : public CommandFileLexer { public: - explicit FilteredCommandFileLexer(absl::string_view code) + explicit FilteredCommandFileLexer(std::string_view code) : CommandFileLexer(code) {} bool KeepSyntaxTreeTokens(const verible::TokenInfo &t) { diff --git a/verible/common/analysis/file-analyzer.cc b/verible/common/analysis/file-analyzer.cc index 53ea775c5..2d623640c 100644 --- a/verible/common/analysis/file-analyzer.cc +++ b/verible/common/analysis/file-analyzer.cc @@ -20,10 +20,10 @@ #include #include // IWYU pragma: keep // for ostringstream #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/lexer/lexer.h" #include "verible/common/lexer/token-stream-adapter.h" #include "verible/common/parser/parse.h" @@ -143,7 +143,7 @@ void FileAnalyzer::ExtractLinterTokenErrorDetail( const RejectedToken &error_token, const ReportLinterErrorFunction &error_report) const { const LineColumnRange range = Data().GetRangeForToken(error_token.token_info); - absl::string_view context_line; + std::string_view context_line; const auto &lines = Data().Lines(); if (range.start.line < static_cast(lines.size())) { context_line = lines[range.start.line]; @@ -162,7 +162,7 @@ std::string FileAnalyzer::LinterTokenErrorMessage( error_token, [&](const std::string &filename, LineColumnRange range, ErrorSeverity severity, AnalysisPhase phase, - absl::string_view token_text, absl::string_view context_line, + std::string_view token_text, std::string_view context_line, const std::string &message) { out << filename_ << ':' << range << " " << phase << " " << severity; if (error_token.token_info.isEOF()) { diff --git a/verible/common/analysis/file-analyzer.h b/verible/common/analysis/file-analyzer.h index 220849db8..9d0117ae9 100644 --- a/verible/common/analysis/file-analyzer.h +++ b/verible/common/analysis/file-analyzer.h @@ -43,11 +43,11 @@ #include #include #include +#include #include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/lexer/lexer.h" #include "verible/common/parser/parse.h" #include "verible/common/strings/line-column-map.h" @@ -93,12 +93,12 @@ std::ostream &operator<<(std::ostream &, const RejectedToken &); // FileAnalyzer holds the results of lexing and parsing. class FileAnalyzer { public: - FileAnalyzer(std::shared_ptr contents, absl::string_view filename) + FileAnalyzer(std::shared_ptr contents, std::string_view filename) : text_structure_(new TextStructure(std::move(contents))), filename_(filename) {} // Legacy constructor. - FileAnalyzer(absl::string_view contents, absl::string_view filename) + FileAnalyzer(std::string_view contents, std::string_view filename) : text_structure_(new TextStructure(contents)), filename_(filename) {} virtual ~FileAnalyzer() = default; @@ -131,8 +131,8 @@ class FileAnalyzer { // TODO(hzeller): these are a lot of parameters, maybe a struct would be good. using ReportLinterErrorFunction = std::function; + ErrorSeverity severity, AnalysisPhase phase, std::string_view token_text, + std::string_view context_line, const std::string &message)>; // Extract detailed diagnostic information for rejected token. void ExtractLinterTokenErrorDetail( diff --git a/verible/common/analysis/file-analyzer_test.cc b/verible/common/analysis/file-analyzer_test.cc index 9cebd72f8..25301f13f 100644 --- a/verible/common/analysis/file-analyzer_test.cc +++ b/verible/common/analysis/file-analyzer_test.cc @@ -18,10 +18,10 @@ #include #include +#include #include "absl/status/status.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/strings/line-column-map.h" #include "verible/common/text/text-structure.h" @@ -76,7 +76,7 @@ TEST(FileAnalyzerTest, TokenErrorMessageSameLine) { {error_token, AnalysisPhase::kParsePhase}, [](const std::string &filename, LineColumnRange range, ErrorSeverity severity, AnalysisPhase phase, - absl::string_view token_text, absl::string_view context_line, + std::string_view token_text, std::string_view context_line, const std::string &message) { EXPECT_EQ(filename, "hello.txt"); EXPECT_EQ(range.start.line, 1); @@ -114,7 +114,7 @@ TEST(FileAnalyzerTest, TokenErrorMessageSameLineWithContext) { {error_token, AnalysisPhase::kParsePhase}, [](const std::string &filename, LineColumnRange range, ErrorSeverity severity, AnalysisPhase phase, - absl::string_view token_text, absl::string_view context_line, + std::string_view token_text, std::string_view context_line, const std::string &message) { EXPECT_EQ(filename, "hello.txt"); EXPECT_EQ(range.start.line, 1); @@ -150,7 +150,7 @@ TEST(FileAnalyzerTest, TokenErrorMessageOneChar) { {error_token, AnalysisPhase::kParsePhase}, [](const std::string &filename, LineColumnRange range, ErrorSeverity severity, AnalysisPhase phase, - absl::string_view token_text, absl::string_view context_line, + std::string_view token_text, std::string_view context_line, const std::string &message) { EXPECT_EQ(filename, "hello.txt"); EXPECT_EQ(range.start.line, 0); @@ -207,7 +207,7 @@ TEST(FileAnalyzerTest, TokenErrorMessageDifferentLine) { {error_token, AnalysisPhase::kParsePhase}, [](const std::string &filename, LineColumnRange range, ErrorSeverity severity, AnalysisPhase phase, - absl::string_view token_text, absl::string_view context_line, + std::string_view token_text, std::string_view context_line, const std::string &message) { EXPECT_EQ(filename, "hello.txt"); EXPECT_EQ(range.start.line, 0); @@ -285,7 +285,7 @@ TEST(FileAnalyzerTest, TokenErrorMessageEOFWithContext) { {error_token, AnalysisPhase::kParsePhase}, [](const std::string &filename, LineColumnRange range, ErrorSeverity severity, AnalysisPhase phase, - absl::string_view token_text, absl::string_view context_line, + std::string_view token_text, std::string_view context_line, const std::string &message) { EXPECT_EQ(filename, "unbalanced.txt"); EXPECT_EQ(range.start.line, 2); diff --git a/verible/common/analysis/line-lint-rule.h b/verible/common/analysis/line-lint-rule.h index e3b6d3de0..a433db59c 100644 --- a/verible/common/analysis/line-lint-rule.h +++ b/verible/common/analysis/line-lint-rule.h @@ -19,7 +19,8 @@ #ifndef VERIBLE_COMMON_ANALYSIS_LINE_LINT_RULE_H_ #define VERIBLE_COMMON_ANALYSIS_LINE_LINT_RULE_H_ -#include "absl/strings/string_view.h" +#include + #include "verible/common/analysis/lint-rule.h" namespace verible { @@ -29,7 +30,7 @@ class LineLintRule : public LintRule { ~LineLintRule() override = default; // not yet final // Scans a single line during analysis. - virtual void HandleLine(absl::string_view line) = 0; + virtual void HandleLine(std::string_view line) = 0; // Analyze the final state of the rule, after the last line has been read. virtual void Finalize() {} diff --git a/verible/common/analysis/line-linter-test-utils.h b/verible/common/analysis/line-linter-test-utils.h index ab7a0d13f..f2b6e3ef2 100644 --- a/verible/common/analysis/line-linter-test-utils.h +++ b/verible/common/analysis/line-linter-test-utils.h @@ -16,10 +16,10 @@ #define VERIBLE_COMMON_ANALYSIS_LINE_LINTER_TEST_UTILS_H_ #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/line-lint-rule.h" #include "verible/common/analysis/line-linter.h" #include "verible/common/analysis/lint-rule-status.h" @@ -37,7 +37,7 @@ class LintRunner { } LintRuleStatus Run(const TextStructureView &text_structure, - absl::string_view) { + std::string_view) { linter_.Lint(text_structure.Lines()); // Looking for one type of rule violation at a time. CHECK_EQ(linter_.ReportStatus().size(), 1); diff --git a/verible/common/analysis/line-linter.cc b/verible/common/analysis/line-linter.cc index 35ef12300..6bbf69968 100644 --- a/verible/common/analysis/line-linter.cc +++ b/verible/common/analysis/line-linter.cc @@ -15,16 +15,16 @@ #include "verible/common/analysis/line-linter.h" #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/line-lint-rule.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/util/logging.h" namespace verible { -void LineLinter::Lint(const std::vector &lines) { +void LineLinter::Lint(const std::vector &lines) { VLOG(1) << "LineLinter analyzing lines with " << rules_.size() << " rules."; for (const auto &line : lines) { for (const auto &rule : rules_) { diff --git a/verible/common/analysis/line-linter.h b/verible/common/analysis/line-linter.h index 4c7a3d4c3..f767ec8f3 100644 --- a/verible/common/analysis/line-linter.h +++ b/verible/common/analysis/line-linter.h @@ -20,10 +20,10 @@ #define VERIBLE_COMMON_ANALYSIS_LINE_LINTER_H_ #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/line-lint-rule.h" #include "verible/common/analysis/lint-rule-status.h" @@ -32,7 +32,7 @@ namespace verible { class LineLinter { public: // Analyzes a sequence of lines. - void Lint(const std::vector &lines); + void Lint(const std::vector &lines); // Transfers ownership of rule into this Linter void AddRule(std::unique_ptr rule) { diff --git a/verible/common/analysis/line-linter_test.cc b/verible/common/analysis/line-linter_test.cc index 07348f30c..f2f609a3b 100644 --- a/verible/common/analysis/line-linter_test.cc +++ b/verible/common/analysis/line-linter_test.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/analysis/line-lint-rule.h" @@ -38,7 +38,7 @@ class BlankLineRule : public LineLintRule { public: BlankLineRule() = default; - void HandleLine(absl::string_view line) final { + void HandleLine(std::string_view line) final { if (line.empty()) { const TokenInfo token(0, line); violations_.insert(LintViolation(token, "some reason")); @@ -57,7 +57,7 @@ std::unique_ptr MakeBlankLineRule() { // This test verifies that LineLinter works with no rules. TEST(LineLinterTest, NoRules) { - std::vector lines; + std::vector lines; LineLinter linter; linter.Lint(lines); std::vector statuses = linter.ReportStatus(); @@ -66,7 +66,7 @@ TEST(LineLinterTest, NoRules) { // This test verifies that LineLinter works with a single rule. TEST(LineLinterTest, OneRuleAcceptsLines) { - std::vector lines{"abc", "def"}; + std::vector lines{"abc", "def"}; LineLinter linter; linter.AddRule(MakeBlankLineRule()); linter.Lint(lines); @@ -78,7 +78,7 @@ TEST(LineLinterTest, OneRuleAcceptsLines) { // This test verifies that LineLinter can find violations. TEST(LineLinterTest, OneRuleRejectsLine) { - std::vector lines{"abc", "", "def"}; + std::vector lines{"abc", "", "def"}; LineLinter linter; linter.AddRule(MakeBlankLineRule()); linter.Lint(lines); @@ -93,7 +93,7 @@ class EmptyFileRule : public LineLintRule { public: EmptyFileRule() = default; - void HandleLine(absl::string_view line) final { ++lines_; } + void HandleLine(std::string_view line) final { ++lines_; } void Finalize() final { if (lines_ == 0) { @@ -116,7 +116,7 @@ std::unique_ptr MakeEmptyFileRule() { // This test verifies that LineLinter calls Finalize without error. TEST(LineLinterTest, FinalizeAccepts) { - std::vector lines{"x"}; + std::vector lines{"x"}; LineLinter linter; linter.AddRule(MakeEmptyFileRule()); linter.Lint(lines); @@ -128,7 +128,7 @@ TEST(LineLinterTest, FinalizeAccepts) { // This test verifies that LineLinter can report an error during Finalize. TEST(LineLinterTest, FinalizeRejects) { - std::vector lines; + std::vector lines; LineLinter linter; linter.AddRule(MakeEmptyFileRule()); linter.Lint(lines); diff --git a/verible/common/analysis/lint-rule-status.cc b/verible/common/analysis/lint-rule-status.cc index 6486e0680..eb36ab6b1 100644 --- a/verible/common/analysis/lint-rule-status.cc +++ b/verible/common/analysis/lint-rule-status.cc @@ -23,11 +23,11 @@ #include #include #include +#include #include #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/line-column-map.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/symbol.h" @@ -39,21 +39,21 @@ namespace verible { -std::string AutoFix::Apply(absl::string_view base) const { +std::string AutoFix::Apply(std::string_view base) const { std::string result; auto prev_start = base.cbegin(); for (const auto &edit : edits_) { CHECK(base.cbegin() <= edit.fragment.cbegin()); CHECK(base.cend() >= edit.fragment.cend()); - const absl::string_view text_before( + const std::string_view text_before( &*prev_start, std::distance(prev_start, edit.fragment.cbegin())); absl::StrAppend(&result, text_before, edit.replacement); prev_start = edit.fragment.cend(); } - const absl::string_view text_after(&*prev_start, - std::distance(prev_start, base.cend())); + const std::string_view text_after(&*prev_start, + std::distance(prev_start, base.cend())); return absl::StrCat(result, text_after); } @@ -77,7 +77,7 @@ static TokenInfo SymbolToToken(const Symbol &root) { return TokenInfo::EOFToken(); } -LintViolation::LintViolation(const Symbol &root, absl::string_view reason, +LintViolation::LintViolation(const Symbol &root, std::string_view reason, const SyntaxTreeContext &context, const std::vector &autofixes, const std::vector &related_tokens) @@ -90,8 +90,8 @@ LintViolation::LintViolation(const Symbol &root, absl::string_view reason, void LintStatusFormatter::FormatLintRuleStatus(std::ostream *stream, const LintRuleStatus &status, - absl::string_view base, - absl::string_view path) const { + std::string_view base, + std::string_view path) const { for (const auto &violation : status.violations) { FormatViolation(stream, violation, base, path, status.url, status.lint_rule_name); @@ -100,8 +100,8 @@ void LintStatusFormatter::FormatLintRuleStatus(std::ostream *stream, } std::string LintStatusFormatter::FormatWithRelatedTokens( - const std::vector &tokens, absl::string_view message, - absl::string_view path, absl::string_view base) const { + const std::vector &tokens, std::string_view message, + std::string_view path, std::string_view base) const { if (tokens.empty()) { return std::string(message); } @@ -109,7 +109,7 @@ std::string LintStatusFormatter::FormatWithRelatedTokens( size_t end_pos = message.find('@', beg_pos); std::ostringstream s; for (const auto &token : tokens) { - if (end_pos == absl::string_view::npos) { + if (end_pos == std::string_view::npos) { s << message.substr(beg_pos); break; } @@ -130,8 +130,8 @@ std::string LintStatusFormatter::FormatWithRelatedTokens( void LintStatusFormatter::FormatLintRuleStatuses( std::ostream *stream, const std::vector &statuses, - absl::string_view base, absl::string_view path, - const std::vector &lines) const { + std::string_view base, std::string_view path, + const std::vector &lines) const { std::set violations; // TODO(fangism): rewrite as a linear time merge of pre-ordered sub-sequences @@ -161,10 +161,10 @@ void LintStatusFormatter::FormatLintRuleStatuses( // Path is file path of original file and url is a link to violated rule void LintStatusFormatter::FormatViolation(std::ostream *stream, const LintViolation &violation, - absl::string_view base, - absl::string_view path, - absl::string_view url, - absl::string_view rule_name) const { + std::string_view base, + std::string_view path, + std::string_view url, + std::string_view rule_name) const { // TODO(fangism): Use the context member to print which named construct or // design element the violation appears in (or full stack thereof). const verible::LineColumnRange range{ @@ -180,9 +180,8 @@ void LintStatusFormatter::FormatViolation(std::ostream *stream, // Formats and outputs violation to a file stream in a syntax accepted by // --waiver_files flag. Path is file path of original file void LintStatusFormatter::FormatViolationWaiver( - std::ostream *stream, const LintViolation &violation, - absl::string_view base, absl::string_view path, - absl::string_view rule_name) const { + std::ostream *stream, const LintViolation &violation, std::string_view base, + std::string_view path, std::string_view rule_name) const { const verible::LineColumnRange range{ line_column_map_.GetLineColAtOffset(base, violation.token.left(base)), line_column_map_.GetLineColAtOffset(base, violation.token.right(base))}; diff --git a/verible/common/analysis/lint-rule-status.h b/verible/common/analysis/lint-rule-status.h index 18e6a133a..e4bed7fab 100644 --- a/verible/common/analysis/lint-rule-status.h +++ b/verible/common/analysis/lint-rule-status.h @@ -22,9 +22,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/citation.h" #include "verible/common/strings/line-column-map.h" #include "verible/common/text/symbol.h" @@ -42,7 +42,7 @@ namespace verible { // ReplacementEdit differs from editscript's Edit in that it stores a // replacement string, so it doesn't need the "after" text to be useful. struct ReplacementEdit { - ReplacementEdit(absl::string_view fragment, const std::string &replacement) + ReplacementEdit(std::string_view fragment, const std::string &replacement) : fragment(fragment), replacement(replacement) {} ReplacementEdit(const TokenInfo &token, const std::string &replacement) @@ -55,7 +55,7 @@ struct ReplacementEdit { return (fragment.data() + fragment.size()) <= other.fragment.data(); } - absl::string_view fragment; + std::string_view fragment; std::string replacement; }; @@ -66,17 +66,17 @@ class AutoFix { AutoFix(const AutoFix &other) = default; AutoFix(AutoFix &&other) = default; - AutoFix(absl::string_view description, + AutoFix(std::string_view description, std::initializer_list edits) : description_(description), edits_(edits) { CHECK_EQ(edits_.size(), edits.size()) << "Edits must not overlap."; } - AutoFix(absl::string_view description, const ReplacementEdit &edit) + AutoFix(std::string_view description, const ReplacementEdit &edit) : AutoFix(description, {edit}) {} // Applies the fix on a `base` and returns modified text. - std::string Apply(absl::string_view base) const; + std::string Apply(std::string_view base) const; bool AddEdits(const std::set &new_edits); @@ -91,7 +91,7 @@ class AutoFix { // LintViolation is a class that represents a single rule violation. struct LintViolation { // This construct records a token stream lint violation. - LintViolation(const TokenInfo &token, absl::string_view reason, + LintViolation(const TokenInfo &token, std::string_view reason, const std::vector &autofixes = {}, const std::vector &related_tokens = {}) : token(token), @@ -102,13 +102,13 @@ struct LintViolation { // This construct records a token stream lint violation. // with additional tokens that might be related somehow with vulnerable token - LintViolation(const TokenInfo &token, absl::string_view reason, + LintViolation(const TokenInfo &token, std::string_view reason, const std::vector &tokens) : token(token), reason(reason), context(), related_tokens(tokens) {} // This construct records a syntax tree lint violation. // Use this variation when the violation can be localized to a single token. - LintViolation(const TokenInfo &token, absl::string_view reason, + LintViolation(const TokenInfo &token, std::string_view reason, const SyntaxTreeContext &context, const std::vector &autofixes = {}, const std::vector &related_tokens = {}) @@ -122,7 +122,7 @@ struct LintViolation { // Use this variation when the range of violation is a subtree that spans // multiple tokens. The violation will be reported at the location of // the left-most leaf of the subtree. - LintViolation(const Symbol &root, absl::string_view reason, + LintViolation(const Symbol &root, std::string_view reason, const SyntaxTreeContext &context, const std::vector &autofixes = {}, const std::vector &related_tokens = {}); @@ -158,7 +158,7 @@ struct LintViolation { struct LintRuleStatus { LintRuleStatus() = default; - LintRuleStatus(const std::set &vs, absl::string_view rule_name, + LintRuleStatus(const std::set &vs, std::string_view rule_name, const std::string &url) : lint_rule_name(rule_name), url(url), violations(vs) {} @@ -181,7 +181,7 @@ struct LintRuleStatus { void WaiveViolations(std::function &&is_waived); // Name of the lint rule that produced this status. - absl::string_view lint_rule_name; + std::string_view lint_rule_name; // Hold link to engdoc summary of violated rule std::string url; @@ -215,7 +215,7 @@ class LintStatusFormatter { public: // Constructor takes a reference to the original text in order to setup // line_column_map - explicit LintStatusFormatter(absl::string_view text) + explicit LintStatusFormatter(std::string_view text) : line_column_map_(text) {} // Formats and outputs status to stream. @@ -224,8 +224,7 @@ class LintStatusFormatter { // Base is the string_view of the entire contents, used only for byte offset // calculation. void FormatLintRuleStatus(std::ostream *stream, const LintRuleStatus &status, - absl::string_view base, - absl::string_view path) const; + std::string_view base, std::string_view path) const; // Formats, sorts and outputs status to stream with additional vulnerable code // line printed when enabled. @@ -235,10 +234,10 @@ class LintStatusFormatter { // contained in status. // Base is the string_view of the entire contents, used only for byte offset // calculation. - void FormatLintRuleStatuses( - std::ostream *stream, const std::vector &statuses, - absl::string_view base, absl::string_view path, - const std::vector &lines) const; + void FormatLintRuleStatuses(std::ostream *stream, + const std::vector &statuses, + std::string_view base, std::string_view path, + const std::vector &lines) const; // Formats and outputs violation on stream. // Path is file path of original file and url is a link to the ratified rule @@ -246,9 +245,8 @@ class LintStatusFormatter { // Base is the string_view of the entire contents, used only for byte offset // calculation. void FormatViolation(std::ostream *stream, const LintViolation &violation, - absl::string_view base, absl::string_view path, - absl::string_view url, - absl::string_view rule_name) const; + std::string_view base, std::string_view path, + std::string_view url, std::string_view rule_name) const; // Formats and outputs violation to a file stream in a syntax accepted by // --waiver_files flag. Path is file path of original file that is being @@ -256,16 +254,16 @@ class LintStatusFormatter { // byte offset calculation. void FormatViolationWaiver(std::ostream *stream, const LintViolation &violation, - absl::string_view base, absl::string_view path, - absl::string_view rule_name) const; + std::string_view base, std::string_view path, + std::string_view rule_name) const; // Substitute the markers \@ with tokens location // this allows us to create custom reason msg // with different token location that are related to found // vulnerable token. It is important to note that all the tokens // must come from the same file. std::string FormatWithRelatedTokens( - const std::vector &tokens, absl::string_view message, - absl::string_view path, absl::string_view base) const; + const std::vector &tokens, std::string_view message, + std::string_view path, std::string_view base) const; private: // Translates byte offsets, which are supplied by LintViolations via diff --git a/verible/common/analysis/lint-rule-status_test.cc b/verible/common/analysis/lint-rule-status_test.cc index ad9eeaf2e..79cf66006 100644 --- a/verible/common/analysis/lint-rule-status_test.cc +++ b/verible/common/analysis/lint-rule-status_test.cc @@ -19,11 +19,11 @@ #include #include // IWYU pragma: keep // for ostringstream #include +#include #include #include #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/token-info.h" @@ -82,10 +82,10 @@ struct LintViolationTest { // TODO(b/136092807): leverage SynthesizedLexerTestData to produce // expected findings. struct LintStatusTest { - absl::string_view rule_name; + std::string_view rule_name; std::string url; - absl::string_view path; - absl::string_view text; + std::string_view path; + std::string_view text; std::vector violations; }; @@ -118,7 +118,7 @@ void RunLintStatusTest(const LintStatusTest &test) { TEST(LintRuleStatusFormatterTest, SimpleOutput) { SymbolPtr root = Node(); static const int dont_care_tag = 0; - constexpr absl::string_view text( + constexpr std::string_view text( "This is some code\n" "That you are looking at right now\n" "It is nice code, make no mistake\n" @@ -140,7 +140,7 @@ TEST(LintRuleStatusFormatterTest, SimpleOutput) { TEST(LintRuleStatusFormatterTest, HelperTokensReplacmentWithTokensLocation) { SymbolPtr root = Node(); static const int dont_care_tag = 0; - constexpr absl::string_view text( + constexpr std::string_view text( "This is some code\n" "That you are looking at right now\n" "It is nice code, make no mistake\n" @@ -220,7 +220,7 @@ void RunLintStatusesTest(const LintStatusTest &test, bool show_context) { std::ostringstream ss; LintStatusFormatter formatter(test.text); - const std::vector lines; + const std::vector lines; if (!show_context) { formatter.FormatLintRuleStatuses(&ss, statuses, test.text, test.path, {}); } else { @@ -246,7 +246,7 @@ void RunLintStatusesTest(const LintStatusTest &test, bool show_context) { TEST(LintRuleStatusFormatterTest, MultipleStatusesSimpleOutput) { SymbolPtr root = Node(); static const int dont_care_tag = 0; - constexpr absl::string_view text( + constexpr std::string_view text( "This is some code\n" "That you are looking at right now\n" "It is nice code, make no mistake\n" @@ -268,7 +268,7 @@ TEST(LintRuleStatusFormatterTest, MultipleStatusesSimpleOutput) { TEST(LintRuleStatusFormatterTestWithContext, MultipleStatusesSimpleOutput) { SymbolPtr root = Node(); static const int dont_care_tag = 0; - constexpr absl::string_view text( + constexpr std::string_view text( "This is some code\n" "That you are looking at right now\n" "It is nice code, make no mistake\n" @@ -290,7 +290,7 @@ TEST(LintRuleStatusFormatterTestWithContext, MultipleStatusesSimpleOutput) { TEST(LintRuleStatusFormatterTestWithContext, PointToCorrectUtf8Char) { SymbolPtr root = Node(); static const int dont_care_tag = 0; - constexpr absl::string_view text("äöüß\n"); + constexpr std::string_view text("äöüß\n"); // ^ä^ü LintStatusTest test = { "rule", @@ -308,7 +308,7 @@ TEST(LintRuleStatusFormatterTestWithContext, PointToCorrectUtf8Char) { TEST(AutoFixTest, ValidUseCases) { // 0123456789abcdef - static constexpr absl::string_view text("This is an image"); + static constexpr std::string_view text("This is an image"); // AutoFix(ReplacementEdit) const AutoFix singleEdit("e", {text.substr(5, 2), "isn't"}); @@ -369,7 +369,7 @@ TEST(AutoFixTest, ValidUseCases) { TEST(AutoFixTest, ConflictingEdits) { // 0123456789abcdef - static constexpr absl::string_view text("This is an image"); + static constexpr std::string_view text("This is an image"); AutoFix fixesCollection; EXPECT_TRUE(fixesCollection.AddEdits({{text.substr(8, 8), "a text"}})); @@ -392,7 +392,7 @@ TEST(AutoFixTest, ConflictingEdits) { } TEST(LintViolationTest, ViolationWithAutoFix) { - static constexpr absl::string_view text("This is an image"); + static constexpr std::string_view text("This is an image"); static const int dont_care_tag = 0; const TokenInfo an_image_token(dont_care_tag, text.substr(8, 5)); diff --git a/verible/common/analysis/lint-rule.h b/verible/common/analysis/lint-rule.h index c0e835eac..7cbc586a4 100644 --- a/verible/common/analysis/lint-rule.h +++ b/verible/common/analysis/lint-rule.h @@ -18,8 +18,9 @@ #ifndef VERIBLE_COMMON_ANALYSIS_LINT_RULE_H_ #define VERIBLE_COMMON_ANALYSIS_LINT_RULE_H_ +#include + #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" namespace verible { @@ -37,7 +38,7 @@ class LintRule { // on failure, the Error-status will contain a message. // By default, rules don't accept any configuration, so only an empty // configuration is valid. - virtual absl::Status Configure(absl::string_view configuration) { + virtual absl::Status Configure(std::string_view configuration) { if (configuration.empty()) return absl::OkStatus(); return absl::InvalidArgumentError("Rule does not support configuration."); } diff --git a/verible/common/analysis/lint-waiver.cc b/verible/common/analysis/lint-waiver.cc index 60a851484..d3db6b053 100644 --- a/verible/common/analysis/lint-waiver.cc +++ b/verible/common/analysis/lint-waiver.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -30,7 +31,6 @@ #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/command-file-lexer.h" #include "verible/common/strings/comment-utils.h" @@ -47,17 +47,17 @@ namespace verible { -void LintWaiver::WaiveOneLine(absl::string_view rule_name, int line_number) { +void LintWaiver::WaiveOneLine(std::string_view rule_name, int line_number) { WaiveLineRange(rule_name, line_number, line_number + 1); } -void LintWaiver::WaiveLineRange(absl::string_view rule_name, int line_begin, +void LintWaiver::WaiveLineRange(std::string_view rule_name, int line_begin, int line_end) { LineNumberSet &line_set = waiver_map_[rule_name]; line_set.Add({line_begin, line_end}); } -const RE2 *LintWaiver::GetOrCreateCachedRegex(absl::string_view regex_str) { +const RE2 *LintWaiver::GetOrCreateCachedRegex(std::string_view regex_str) { auto found = regex_cache_.find(regex_str); if (found != regex_cache_.end()) { return found->second.get(); @@ -68,8 +68,8 @@ const RE2 *LintWaiver::GetOrCreateCachedRegex(absl::string_view regex_str) { return inserted.first->second.get(); } -absl::Status LintWaiver::WaiveWithRegex(absl::string_view rule_name, - absl::string_view regex_str) { +absl::Status LintWaiver::WaiveWithRegex(std::string_view rule_name, + std::string_view regex_str) { const std::string regex_as_group = absl::StrCat("(", regex_str, ")"); const RE2 *regex = GetOrCreateCachedRegex(regex_as_group); if (!regex->ok()) { @@ -81,12 +81,12 @@ absl::Status LintWaiver::WaiveWithRegex(absl::string_view rule_name, return absl::OkStatus(); } -void LintWaiver::RegexToLines(absl::string_view contents, +void LintWaiver::RegexToLines(std::string_view contents, const LineColumnMap &line_map) { for (const auto &rule : waiver_re_map_) { for (const RE2 *re : rule.second) { - absl::string_view walk = contents; - absl::string_view match; + std::string_view walk = contents; + std::string_view match; while (RE2::FindAndConsume(&walk, *re, &match)) { const size_t pos = match.begin() - contents.begin(); WaiveOneLine(rule.first, line_map.LineAtOffset(pos)); @@ -99,7 +99,7 @@ void LintWaiver::RegexToLines(absl::string_view contents, } } -bool LintWaiver::RuleIsWaivedOnLine(absl::string_view rule_name, +bool LintWaiver::RuleIsWaivedOnLine(std::string_view rule_name, int line_number) const { const auto *line_set = verible::container::FindOrNull(waiver_map_, rule_name); return line_set != nullptr && LineNumberSetContains(*line_set, line_number); @@ -114,9 +114,9 @@ bool LintWaiver::Empty() const { return true; } -absl::string_view LintWaiverBuilder::ExtractWaivedRuleFromComment( - absl::string_view comment_text, - std::vector *comment_tokens) const { +std::string_view LintWaiverBuilder::ExtractWaivedRuleFromComment( + std::string_view comment_text, + std::vector *comment_tokens) const { // Look for directives of the form: // Addition text beyond the last argument is ignored, so it could // contain more comment text. @@ -141,7 +141,7 @@ void LintWaiverBuilder::ProcessLine(const TokenRange &tokens, int line_number) { // TODO(fangism): [optimization] Use a SmallVector, or function-local // static to avoid re-allocation in every call. This method does not // need to be re-entrant. - std::vector lint_directives; + std::vector lint_directives; // Determine whether line is blank, where whitespace still counts as blank. const bool line_is_blank = @@ -166,15 +166,15 @@ void LintWaiverBuilder::ProcessLine(const TokenRange &tokens, int line_number) { } // Find all directives on this line. - std::vector comment_tokens; // Re-use in loop. + std::vector comment_tokens; // Re-use in loop. for (const auto &token : tokens) { if (is_token_comment_(token)) { // Lex the comment text. - const absl::string_view comment_text = + const std::string_view comment_text = StripCommentAndSpacePadding(token.text()); comment_tokens = absl::StrSplit(comment_text, ' ', absl::SkipEmpty()); // TODO(fangism): Support different waiver lexers. - const absl::string_view waived_rule = + const std::string_view waived_rule = ExtractWaivedRuleFromComment(comment_text, &comment_tokens); if (!waived_rule.empty()) { // If there are any significant tokens on this line, apply to this @@ -238,30 +238,29 @@ void LintWaiverBuilder::ProcessTokenRangesByLine( template static std::string WaiveCommandErrorFmt(LineColumn pos, - absl::string_view filename, - absl::string_view msg, + std::string_view filename, + std::string_view msg, const T &...args) { return absl::StrCat(filename, ":", pos.line + 1, ":", pos.column + 1, ": command error: ", msg, args...); } template -static absl::Status WaiveCommandError(LineColumn pos, - absl::string_view filename, - absl::string_view msg, const T &...args) { +static absl::Status WaiveCommandError(LineColumn pos, std::string_view filename, + std::string_view msg, const T &...args) { return absl::InvalidArgumentError( WaiveCommandErrorFmt(pos, filename, msg, args...)); } static absl::Status WaiveCommandHandler( - const TokenRange &tokens, absl::string_view waive_file, - absl::string_view waive_content, absl::string_view lintee_filename, + const TokenRange &tokens, std::string_view waive_file, + std::string_view waive_content, std::string_view lintee_filename, const LineColumnMap &line_map, LintWaiver *waiver, - const std::set &active_rules) { - absl::string_view rule; + const std::set &active_rules) { + std::string_view rule; - absl::string_view option; - absl::string_view val; + std::string_view option; + std::string_view val; int line_start = -1; int line_end = -1; @@ -316,7 +315,7 @@ static absl::Status WaiveCommandHandler( if (option == "line") { size_t range = val.find(':'); - if (range != absl::string_view::npos) { + if (range != std::string_view::npos) { // line range if (!absl::SimpleAtoi(val.substr(0, range), &line_start) || !absl::SimpleAtoi(val.substr(range + 1, val.length() - range), @@ -420,12 +419,12 @@ static absl::Status WaiveCommandHandler( } using HandlerFun = std::function &)>; -static const std::map &GetCommandHandlers() { + const TokenRange &, std::string_view waive_file, + std::string_view waive_content, std::string_view lintee_filename, + const LineColumnMap &, LintWaiver *, const std::set &)>; +static const std::map &GetCommandHandlers() { // allocated once, never freed - static const auto *handlers = new std::map{ + static const auto *handlers = new std::map{ // Right now, we only have one handler {"waive", WaiveCommandHandler}, }; @@ -433,9 +432,9 @@ static const std::map &GetCommandHandlers() { } absl::Status LintWaiverBuilder::ApplyExternalWaivers( - const std::set &active_rules, - absl::string_view lintee_filename, absl::string_view waiver_filename, - absl::string_view waivers_config_content) { + const std::set &active_rules, + std::string_view lintee_filename, std::string_view waiver_filename, + std::string_view waivers_config_content) { if (waivers_config_content.empty()) { return {absl::StatusCode::kInternal, "Broken waiver config handle"}; } diff --git a/verible/common/analysis/lint-waiver.h b/verible/common/analysis/lint-waiver.h index e7c92da2b..bcb28e124 100644 --- a/verible/common/analysis/lint-waiver.h +++ b/verible/common/analysis/lint-waiver.h @@ -19,12 +19,12 @@ #include #include #include +#include #include #include #include "absl/container/flat_hash_map.h" #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/strings/line-column-map.h" #include "verible/common/strings/position.h" @@ -54,29 +54,28 @@ class LintWaiver { // Waiver comments on lines with other tokens will only waive that line. // Adds a single line to the set of waived lines for a single rule. - void WaiveOneLine(absl::string_view rule_name, int line_number); + void WaiveOneLine(std::string_view rule_name, int line_number); // Adds a range [line_begin, line_end) over which a waiver applies. - void WaiveLineRange(absl::string_view rule_name, int line_begin, - int line_end); + void WaiveLineRange(std::string_view rule_name, int line_begin, int line_end); // Adds a regular expression which will be used to apply a waiver. - absl::Status WaiveWithRegex(absl::string_view rule_name, - absl::string_view regex); + absl::Status WaiveWithRegex(std::string_view rule_name, + std::string_view regex); // Converts the prepared regular expressions to line numbers and applies the // waivers. - void RegexToLines(absl::string_view content, const LineColumnMap &line_map); + void RegexToLines(std::string_view content, const LineColumnMap &line_map); // Returns true if `line_number` should be waived for a particular rule. - bool RuleIsWaivedOnLine(absl::string_view rule_name, int line_number) const; + bool RuleIsWaivedOnLine(std::string_view rule_name, int line_number) const; // Returns true if there are no lines waived for any rules. bool Empty() const; // TODO(hzeller): The following methods break abstraction and are only // for performance. Reconsider if this is worth it. - const LineNumberSet *LookupLineNumberSet(absl::string_view rule_name) const { + const LineNumberSet *LookupLineNumberSet(std::string_view rule_name) const { return verible::container::FindOrNull(waiver_map_, rule_name); } @@ -86,14 +85,14 @@ class LintWaiver { } private: - const RE2 *GetOrCreateCachedRegex(absl::string_view regex_str); + const RE2 *GetOrCreateCachedRegex(std::string_view regex_str); // Keys in the maps below are the names of the waived rules. They can be // string_view because the static strings for each lint rule class exist, // and will outlive all LintWaiver objects. This applies to both waiver_map_ // and waiver_re_map_. - absl::flat_hash_map waiver_map_; - absl::flat_hash_map waiver_re_map_; + absl::flat_hash_map waiver_map_; + absl::flat_hash_map waiver_re_map_; absl::flat_hash_map> regex_cache_; }; @@ -124,10 +123,10 @@ class LintWaiverBuilder { // 'waive_command' is the second argument after the trigger, and is the // command for 'waive-one-line'. LintWaiverBuilder(TokenFilterPredicate &&is_comment, - TokenFilterPredicate &&is_space, absl::string_view trigger, - absl::string_view waive_line_command, - absl::string_view waive_start_command, - absl::string_view waive_stop_command) + TokenFilterPredicate &&is_space, std::string_view trigger, + std::string_view waive_line_command, + std::string_view waive_start_command, + std::string_view waive_stop_command) : waiver_trigger_keyword_(trigger), waive_one_line_keyword_(waive_line_command), waive_range_start_keyword_(waive_start_command), @@ -147,9 +146,9 @@ class LintWaiverBuilder { // Takes a set of active linter rules and the affected filename to be linted, // and applies waivers from waiver_filename and its content. absl::Status ApplyExternalWaivers( - const std::set &active_rules, - absl::string_view lintee_filename, absl::string_view waiver_filename, - absl::string_view waivers_config_content); + const std::set &active_rules, + std::string_view lintee_filename, std::string_view waiver_filename, + std::string_view waivers_config_content); const LintWaiver &GetLintWaiver() const { return lint_waiver_; } @@ -157,22 +156,22 @@ class LintWaiverBuilder { // Parses a comment and extracts a waived rule name. // If text does not match the waived form, then return an empty string. // `comment_tokens` is just re-used memory to avoid re-allocation. - absl::string_view ExtractWaivedRuleFromComment( - absl::string_view comment_text, - std::vector *comment_tokens) const; + std::string_view ExtractWaivedRuleFromComment( + std::string_view comment_text, + std::vector *comment_tokens) const; // Special string that leads a comment that is a waiver directive // Typically, name of linter tool is used here. - absl::string_view waiver_trigger_keyword_; + std::string_view waiver_trigger_keyword_; // Command to waive one line, either the current line if there are tokens // on the current line or the next non-comment-non-blank-line. - absl::string_view waive_one_line_keyword_; // e.g. "waive" + std::string_view waive_one_line_keyword_; // e.g. "waive" // Command pair to start and stop waiving ranges of lines. // e.g. "waive-start", "waive-stop" - absl::string_view waive_range_start_keyword_; - absl::string_view waive_range_stop_keyword_; + std::string_view waive_range_start_keyword_; + std::string_view waive_range_stop_keyword_; // Returns true if token is a comment. TokenFilterPredicate is_token_comment_; @@ -182,12 +181,12 @@ class LintWaiverBuilder { // This holds the set of to-be-applied lint waivers. // Element string_views point to string memory that outlives this builder. - std::set unapplied_oneline_waivers_; + std::set unapplied_oneline_waivers_; // This holds the set of open ranges of lines, keyed by rule name. // Value is the lower-bound of each encountered waiver range. // string_view keys point to string memory that outlives this builder. - std::map waiver_open_ranges_; + std::map waiver_open_ranges_; // Set of waived lines per rule. LintWaiver lint_waiver_; diff --git a/verible/common/analysis/lint-waiver_test.cc b/verible/common/analysis/lint-waiver_test.cc index aa710ada4..808723059 100644 --- a/verible/common/analysis/lint-waiver_test.cc +++ b/verible/common/analysis/lint-waiver_test.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/strings/line-column-map.h" #include "verible/common/text/text-structure-test-utils.h" @@ -631,65 +631,65 @@ TEST_F(LintWaiverBuilderTest, FromTextStructureOneWaiverRangeOpened) { } TEST_F(LintWaiverBuilderTest, ApplyExternalWaiversInvalidCases) { - std::set active_rules; - const absl::string_view user_file = "filename"; - const absl::string_view cfg_file = "waive_file.config"; + std::set active_rules; + const std::string_view user_file = "filename"; + const std::string_view cfg_file = "waive_file.config"; // Completely invalid config - const absl::string_view cfg_inv = "inv config"; + const std::string_view cfg_inv = "inv config"; EXPECT_NOK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_inv)); - const absl::string_view cfg_inv_2 = "--line=1"; + const std::string_view cfg_inv_2 = "--line=1"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_inv_2)); // Valid command, invalid parameters - const absl::string_view cfg_inv_params = "waive --something"; + const std::string_view cfg_inv_params = "waive --something"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_inv_params)); // Non-registered rule name - const absl::string_view cfg_inv_rule = "waive --rule=abc --line=1"; + const std::string_view cfg_inv_rule = "waive --rule=abc --line=1"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_inv_rule)); // register rule - const absl::string_view abc_rule = "abc"; + const std::string_view abc_rule = "abc"; active_rules.insert(abc_rule); // Valid rule, missing params - const absl::string_view cfg_no_param = "waive --rule=abc"; + const std::string_view cfg_no_param = "waive --rule=abc"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_no_param)); // Valid rule, invalid line number - const absl::string_view cfg_inv_lineno = "waive --rule=abc --line=0"; + const std::string_view cfg_inv_lineno = "waive --rule=abc --line=0"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_inv_lineno)); // Valid rule, invalid line range - const absl::string_view cfg_inv_range = "waive --rule=abc --line=1:0"; + const std::string_view cfg_inv_range = "waive --rule=abc --line=1:0"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_inv_range)); // Valid rule, invalid regex - const absl::string_view cfg_inv_regex = "waive --rule=abc --regex=\"(\""; + const std::string_view cfg_inv_regex = "waive --rule=abc --regex=\"(\""; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_inv_regex)); // Valid rule, both regex and lines specified - const absl::string_view cfg_conflict = + const std::string_view cfg_conflict = "waive --rule=abc --regex=\".*\" --line=1"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_conflict)); // Missing rulename - const absl::string_view cfg_no_rule = "waive --line=1"; + const std::string_view cfg_no_rule = "waive --line=1"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_no_rule)); // Check that even though some rules are invalid, the consecutive ones // are still parsed and applied - const absl::string_view cfg_mixed = + const std::string_view cfg_mixed = "waive --line=1\ndasdasda\nwaive --rule=abc --line=10"; EXPECT_NOK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_mixed)); @@ -699,30 +699,30 @@ TEST_F(LintWaiverBuilderTest, ApplyExternalWaiversInvalidCases) { } TEST_F(LintWaiverBuilderTest, ApplyExternalWaiversValidCases) { - const std::set active_rules{"abc"}; - const absl::string_view user_file = "filename"; - const absl::string_view cfg_file = "waive_file.config"; + const std::set active_rules{"abc"}; + const std::string_view user_file = "filename"; + const std::string_view cfg_file = "waive_file.config"; - const absl::string_view cfg_line = "waive --rule=abc --line=1"; + const std::string_view cfg_line = "waive --rule=abc --line=1"; EXPECT_OK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_line)); EXPECT_TRUE(lint_waiver_.RuleIsWaivedOnLine("abc", 0)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 1)); - const absl::string_view cfg_line_inv_ord = "waive --line=3 --rule=abc"; + const std::string_view cfg_line_inv_ord = "waive --line=3 --rule=abc"; EXPECT_OK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_line_inv_ord)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 1)); EXPECT_TRUE(lint_waiver_.RuleIsWaivedOnLine("abc", 2)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 3)); - const absl::string_view cfg_quotes = "waive --rule=\"abc\" --line=5"; + const std::string_view cfg_quotes = "waive --rule=\"abc\" --line=5"; EXPECT_OK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_quotes)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 3)); EXPECT_TRUE(lint_waiver_.RuleIsWaivedOnLine("abc", 4)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 5)); - const absl::string_view cfg_line_range = "waive --rule=abc --line=7:9"; + const std::string_view cfg_line_range = "waive --rule=abc --line=7:9"; EXPECT_OK( ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_line_range)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 5)); @@ -731,28 +731,28 @@ TEST_F(LintWaiverBuilderTest, ApplyExternalWaiversValidCases) { EXPECT_TRUE(lint_waiver_.RuleIsWaivedOnLine("abc", 8)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 9)); - const absl::string_view cfg_line_range_i = "waive --rule=abc --line=11:11"; + const std::string_view cfg_line_range_i = "waive --rule=abc --line=11:11"; EXPECT_OK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_line_range_i)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 9)); EXPECT_TRUE(lint_waiver_.RuleIsWaivedOnLine("abc", 10)); EXPECT_FALSE(lint_waiver_.RuleIsWaivedOnLine("abc", 11)); - const absl::string_view cfg_regex = "waive --rule=abc --regex=abc"; + const std::string_view cfg_regex = "waive --rule=abc --regex=abc"; EXPECT_OK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_regex)); - const absl::string_view cfg_regex_complex = + const std::string_view cfg_regex_complex = "waive --rule=abc --regex=\"abc .*\""; EXPECT_OK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_regex_complex)); } TEST_F(LintWaiverBuilderTest, LocationOptionNarrowsTestedFile) { - const std::set active_rules{"abc"}; - const absl::string_view user_file = "some_fancy_fileName.sv"; - const absl::string_view cfg_file = "waive_file.config"; + const std::set active_rules{"abc"}; + const std::string_view user_file = "some_fancy_fileName.sv"; + const std::string_view cfg_file = "waive_file.config"; - absl::string_view cfg_line = R"( + std::string_view cfg_line = R"( waive --rule=abc --line=100 waive --rule=abc --line=200 --location=".*foo.*" waive --rule=abc --line=300 --location=".*_fancy_.*" @@ -766,14 +766,14 @@ TEST_F(LintWaiverBuilderTest, LocationOptionNarrowsTestedFile) { } TEST_F(LintWaiverBuilderTest, RegexToLinesSimple) { - const std::set active_rules{"rule-1"}; - const absl::string_view user_file = "filename"; - const absl::string_view cfg_file = "waive_file.config"; + const std::set active_rules{"rule-1"}; + const std::string_view user_file = "filename"; + const std::string_view cfg_file = "waive_file.config"; - const absl::string_view cfg_regex = "waive --rule=rule-1 --regex=def"; + const std::string_view cfg_regex = "waive --rule=rule-1 --regex=def"; EXPECT_OK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_regex)); - const absl::string_view file = "abc\ndef\nghi\n"; + const std::string_view file = "abc\ndef\nghi\n"; const LineColumnMap line_map(file); lint_waiver_.RegexToLines(file, line_map); @@ -785,14 +785,14 @@ TEST_F(LintWaiverBuilderTest, RegexToLinesSimple) { } TEST_F(LintWaiverBuilderTest, RegexToLinesCatchAll) { - const std::set active_rules{"rule-1"}; - const absl::string_view user_file = "filename"; - const absl::string_view cfg_file = "waive_file.config"; + const std::set active_rules{"rule-1"}; + const std::string_view user_file = "filename"; + const std::string_view cfg_file = "waive_file.config"; - const absl::string_view cfg_regex = "waive --rule=rule-1 --regex=\".*\""; + const std::string_view cfg_regex = "waive --rule=rule-1 --regex=\".*\""; EXPECT_OK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_regex)); - const absl::string_view file = "abc\ndef\nghi\n\n"; + const std::string_view file = "abc\ndef\nghi\n\n"; const LineColumnMap line_map(file); lint_waiver_.RegexToLines(file, line_map); @@ -808,14 +808,14 @@ TEST_F(LintWaiverBuilderTest, RegexToLinesCatchAll) { } TEST_F(LintWaiverBuilderTest, RegexToLinesMultipleMatches) { - const std::set active_rules{"rule-1"}; - const absl::string_view user_file = "filename"; - const absl::string_view cfg_file = "waive_file.config"; + const std::set active_rules{"rule-1"}; + const std::string_view user_file = "filename"; + const std::string_view cfg_file = "waive_file.config"; - const absl::string_view cfg_regex = "waive --rule=rule-1 --regex=\"[0-9]\""; + const std::string_view cfg_regex = "waive --rule=rule-1 --regex=\"[0-9]\""; EXPECT_OK(ApplyExternalWaivers(active_rules, user_file, cfg_file, cfg_regex)); - const absl::string_view file = "abc1\ndef\ng2hi\n"; + const std::string_view file = "abc1\ndef\ng2hi\n"; const LineColumnMap line_map(file); lint_waiver_.RegexToLines(file, line_map); diff --git a/verible/common/analysis/linter-test-utils.cc b/verible/common/analysis/linter-test-utils.cc index 17f8b0dd5..015e8b7f2 100644 --- a/verible/common/analysis/linter-test-utils.cc +++ b/verible/common/analysis/linter-test-utils.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/token-info.h" #include "verible/common/util/algorithm.h" @@ -51,7 +51,7 @@ static int CompareViolation(const LintViolation &lhs, const TokenInfo &rhs) { // TODO(b/151371397): refactor this for re-use for multi-findings style tests. bool LintTestCase::ExactMatchFindings( - const std::set &found_violations, absl::string_view base, + const std::set &found_violations, std::string_view base, std::ostream *diffstream) const { // Due to the order in which violations are visited, we can assert that // the reported violations are thus ordered. diff --git a/verible/common/analysis/linter-test-utils.h b/verible/common/analysis/linter-test-utils.h index 6d04a5602..b1870af52 100644 --- a/verible/common/analysis/linter-test-utils.h +++ b/verible/common/analysis/linter-test-utils.h @@ -22,10 +22,10 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/token-info-test-util.h" @@ -53,7 +53,7 @@ struct LintTestCase : public TokenInfoTestData { // TODO(b/141875806): Take a symbol translator function to produce a // human-readable, language-specific enum name. bool ExactMatchFindings(const std::set &found_violations, - absl::string_view base, + std::string_view base, std::ostream *diffstream) const; }; @@ -70,7 +70,7 @@ class LintRunner; template void RunLintTestCase(const LintTestCase &test, const LintRuleGenerator &make_rule, - absl::string_view filename) { + std::string_view filename) { // All linters start by parsing to yield a TextStructure. // TODO(hzeller): make preprocessor configurable. Right now, preprocessor // is specific in verilog, no such concept in common. @@ -83,7 +83,7 @@ void RunLintTestCase(const LintTestCase &test, const auto &violations(rule_status.violations); // Report detailed differences, if any. - const absl::string_view base_text = analyzer.Data().Contents(); + const std::string_view base_text = analyzer.Data().Contents(); std::ostringstream diffs; EXPECT_TRUE(test.ExactMatchFindings(violations, base_text, &diffs)) << absl::StrCat("code:\n", test.code, "\nDiffs:\n", diffs.str(), "\n"); @@ -92,9 +92,9 @@ void RunLintTestCase(const LintTestCase &test, // Accepts an array of LintTestCases and tests them all on a linter containing // rule generated by make_rule with a particular configuration. template -void RunConfiguredLintTestCases( - std::initializer_list tests, absl::string_view configuration, - absl::string_view filename = "<>") { +void RunConfiguredLintTestCases(std::initializer_list tests, + std::string_view configuration, + std::string_view filename = "<>") { using rule_type = typename RuleClass::rule_type; auto rule_generator = [&configuration]() -> std::unique_ptr { std::unique_ptr instance(new RuleClass()); @@ -109,13 +109,13 @@ void RunConfiguredLintTestCases( template void RunLintTestCases(std::initializer_list tests, - absl::string_view filename = "<>") { + std::string_view filename = "<>") { RunConfiguredLintTestCases(tests, "", filename); } struct AutoFixInOut { - absl::string_view code; - absl::string_view expected_output; + std::string_view code; + std::string_view expected_output; int fix_alternative = 0; // Some rules provide alternative fixes }; @@ -124,7 +124,7 @@ struct AutoFixInOut { template void RunLintAutoFixCase(const AutoFixInOut &test, const LintRuleGenerator &make_rule, - absl::string_view filename = "") { + std::string_view filename = "") { // All linters start by parsing to yield a TextStructure. AnalyzerType analyzer(test.code, filename); absl::Status unused_parser_status = analyzer.Analyze(); @@ -145,8 +145,8 @@ void RunLintAutoFixCase(const AutoFixInOut &test, template void RunApplyFixCases(std::initializer_list tests, - absl::string_view configuration = "", - absl::string_view filename = "") { + std::string_view configuration = "", + std::string_view filename = "") { using rule_type = typename RuleClass::rule_type; auto rule_generator = [&configuration]() -> std::unique_ptr { std::unique_ptr instance(new RuleClass()); diff --git a/verible/common/analysis/linter-test-utils_test.cc b/verible/common/analysis/linter-test-utils_test.cc index b608a13c0..4757f49b2 100644 --- a/verible/common/analysis/linter-test-utils_test.cc +++ b/verible/common/analysis/linter-test-utils_test.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/util/range.h" @@ -30,7 +30,7 @@ namespace { TEST(LintTestCaseExactMatchFindingsTest, AllEmpty) { const LintTestCase test{}; const std::set found_violations; - const absl::string_view text; + const std::string_view text; std::ostringstream diffstream; EXPECT_TRUE(test.ExactMatchFindings(found_violations, text, &diffstream)); } @@ -43,12 +43,12 @@ TEST(LintTestCaseExactMatchFindingsTest, OneMatchingViolation) { "ghi", }; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(3, 3); + const std::string_view bad_text = text_view.substr(3, 3); const std::set found_violations{ {{kToken, bad_text}, "some reason"}, }; @@ -67,13 +67,13 @@ TEST(LintTestCaseExactMatchFindingsTest, MultipleMatchingViolations) { {kToken, "jkl"}, }; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text1 = text_view.substr(3, 3); - const absl::string_view bad_text2 = text_view.substr(9, 3); + const std::string_view bad_text1 = text_view.substr(3, 3); + const std::string_view bad_text2 = text_view.substr(9, 3); const std::set found_violations{ // must be sorted on location {{kToken, bad_text1}, "some reason"}, @@ -85,21 +85,21 @@ TEST(LintTestCaseExactMatchFindingsTest, MultipleMatchingViolations) { EXPECT_TRUE(diffstream.str().empty()); } -constexpr absl::string_view kFoundNotExpectedMessage( +constexpr std::string_view kFoundNotExpectedMessage( "FOUND these violations, but did not match the expected ones"); -constexpr absl::string_view kExpectedNotFoundMessage( +constexpr std::string_view kExpectedNotFoundMessage( "EXPECTED these violations, but did not match the ones found"); TEST(LintTestCaseExactMatchFindingsTest, OneFoundNotExpected) { constexpr int kToken = 42; const LintTestCase test{"abcdefghi"}; // no expected violations const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(3, 3); + const std::string_view bad_text = text_view.substr(3, 3); const std::set found_violations{ {{kToken, bad_text}, "some reason"}, }; @@ -115,12 +115,12 @@ TEST(LintTestCaseExactMatchFindingsTest, OneExpectedNotFound) { constexpr int kToken = 42; const LintTestCase test{"abc", {kToken, "def"}, "ghi"}; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(3, 3); + const std::string_view bad_text = text_view.substr(3, 3); const std::set found_violations; // none expected std::ostringstream diffstream; EXPECT_FALSE( @@ -134,12 +134,12 @@ TEST(LintTestCaseExactMatchFindingsTest, OneMismatchEach) { constexpr int kToken = 42; const LintTestCase test{"abc", {kToken, "def"}, "ghi"}; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(4, 3); // "efg" + const std::string_view bad_text = text_view.substr(4, 3); // "efg" const std::set found_violations{ {{kToken, bad_text}, "some reason"}, }; diff --git a/verible/common/analysis/matcher/BUILD b/verible/common/analysis/matcher/BUILD index 511e19081..d4a1715b6 100644 --- a/verible/common/analysis/matcher/BUILD +++ b/verible/common/analysis/matcher/BUILD @@ -160,7 +160,6 @@ cc_library( "//verible/common/text:tree-utils", "//verible/common/text:visitors", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", # for library testonly ], ) diff --git a/verible/common/analysis/matcher/matcher-test-utils.cc b/verible/common/analysis/matcher/matcher-test-utils.cc index 312f59fe3..9c9869a46 100644 --- a/verible/common/analysis/matcher/matcher-test-utils.cc +++ b/verible/common/analysis/matcher/matcher-test-utils.cc @@ -15,9 +15,9 @@ #include "verible/common/analysis/matcher/matcher-test-utils.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -83,7 +83,7 @@ class MatchCounter : public TreeVisitorRecursive { }; void ExpectMatchesInAST(const Symbol &tree, const Matcher &matcher, - int num_matches, absl::string_view code) { + int num_matches, std::string_view code) { MatchCounter counter(matcher); EXPECT_EQ(num_matches, counter.Count(tree)) << "code:\n" << code << "\ntree:\n" diff --git a/verible/common/analysis/matcher/matcher-test-utils.h b/verible/common/analysis/matcher/matcher-test-utils.h index 282c79eee..3b0c795e1 100644 --- a/verible/common/analysis/matcher/matcher-test-utils.h +++ b/verible/common/analysis/matcher/matcher-test-utils.h @@ -17,9 +17,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/matcher/matcher.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -42,7 +42,7 @@ struct RawMatcherTestCase { }; void ExpectMatchesInAST(const Symbol &tree, const Matcher &matcher, - int num_matches, absl::string_view code); + int num_matches, std::string_view code); // Runs a raw test case. Expects test.code to be correctly parsed by // analyzer A. diff --git a/verible/common/analysis/syntax-tree-linter-test-utils.h b/verible/common/analysis/syntax-tree-linter-test-utils.h index 329e64822..7fd5b9a79 100644 --- a/verible/common/analysis/syntax-tree-linter-test-utils.h +++ b/verible/common/analysis/syntax-tree-linter-test-utils.h @@ -16,10 +16,10 @@ #define VERIBLE_COMMON_ANALYSIS_SYNTAX_TREE_LINTER_TEST_UTILS_H_ #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" // IWYU pragma: export @@ -37,7 +37,7 @@ class LintRunner { } LintRuleStatus Run(const TextStructureView &text_structure, - absl::string_view) { + std::string_view) { linter_.Lint(*ABSL_DIE_IF_NULL(text_structure.SyntaxTree())); // Looking for one type of rule violation at a time. CHECK_EQ(linter_.ReportStatus().size(), 1); diff --git a/verible/common/analysis/syntax-tree-linter_test.cc b/verible/common/analysis/syntax-tree-linter_test.cc index eb6383e50..995211c60 100644 --- a/verible/common/analysis/syntax-tree-linter_test.cc +++ b/verible/common/analysis/syntax-tree-linter_test.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" @@ -93,7 +93,7 @@ TEST(SyntaxTreeLinterTest, BasicUsageFailure) { } TEST(SyntaxTreeLinterTest, MultipleRules) { - constexpr absl::string_view text("abcd"); + constexpr std::string_view text("abcd"); SymbolPtr root = Node(Leaf(2, text.substr(0, 1)), Leaf(2, text.substr(1, 1)), Node(Leaf(2, text.substr(2, 1))), Leaf(2, text.substr(3, 1))); @@ -151,7 +151,7 @@ std::unique_ptr MakeAscending() { } TEST(SyntaxTreeLinterTest, AscendingSuccess) { - constexpr absl::string_view text("abcde"); + constexpr std::string_view text("abcde"); SymbolPtr root = Node(Leaf(1, text.substr(0, 1)), Leaf(4, text.substr(1, 1)), Node(Leaf(2, text.substr(2, 1)), Leaf(10, text.substr(3, 1))), @@ -167,7 +167,7 @@ TEST(SyntaxTreeLinterTest, AscendingSuccess) { } TEST(SyntaxTreeLinterTest, AscendingFailsOnce) { - constexpr absl::string_view text("abcde"); + constexpr std::string_view text("abcde"); SymbolPtr root = Node(Leaf(1, text.substr(0, 1)), Leaf(4, text.substr(1, 1)), Node(Leaf(2, text.substr(2, 1)), Leaf(10, text.substr(3, 1))), @@ -184,7 +184,7 @@ TEST(SyntaxTreeLinterTest, AscendingFailsOnce) { } TEST(SyntaxTreeLinterTest, AscendingFailsTwice) { - constexpr absl::string_view text("abcde"); + constexpr std::string_view text("abcde"); SymbolPtr root = Node(Leaf(1, text.substr(0, 1)), Leaf(4, text.substr(1, 1)), Node(Leaf(210, text.substr(2, 1)), Leaf(10, text.substr(3, 1))), @@ -201,7 +201,7 @@ TEST(SyntaxTreeLinterTest, AscendingFailsTwice) { } TEST(SyntaxTreeLinterTest, HeterogenousTests) { - constexpr absl::string_view text("abcde"); + constexpr std::string_view text("abcde"); SymbolPtr root = Node(Leaf(1, text.substr(0, 1)), Leaf(4, text.substr(1, 1)), Node(Leaf(210, text.substr(2, 1)), Leaf(10, text.substr(3, 1))), @@ -246,7 +246,7 @@ std::unique_ptr MakeDepth() { } TEST(SyntaxTreeLinterTest, DepthFails) { - constexpr absl::string_view text("abcde"); + constexpr std::string_view text("abcde"); SymbolPtr root = Node(Leaf(1, text.substr(0, 1)), Leaf(4, text.substr(1, 1)), Node(Leaf(210, text.substr(2, 1)), Leaf(10, text.substr(3, 1))), @@ -263,7 +263,7 @@ TEST(SyntaxTreeLinterTest, DepthFails) { } TEST(SyntaxTreeLinterTest, DepthSuccess) { - constexpr absl::string_view text("abcde"); + constexpr std::string_view text("abcde"); SymbolPtr root = Node(Leaf(1, text.substr(0, 1)), Leaf(1, text.substr(1, 1)), Node(Leaf(2, text.substr(2, 1)), Leaf(2, text.substr(3, 1))), diff --git a/verible/common/analysis/syntax-tree-search-test-utils.cc b/verible/common/analysis/syntax-tree-search-test-utils.cc index eaea4ebaa..234bdc4ed 100644 --- a/verible/common/analysis/syntax-tree-search-test-utils.cc +++ b/verible/common/analysis/syntax-tree-search-test-utils.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/text/token-info.h" #include "verible/common/text/tree-utils.h" @@ -32,8 +32,7 @@ namespace verible { // negative if left is 'less' than right, // positive if left is 'greater' than right. // Compares lower bounds, and then upper bounds. -static int CompareStringRanges(absl::string_view left, - absl::string_view right) { +static int CompareStringRanges(std::string_view left, std::string_view right) { // tuple-compare the bounds of the string_view ranges (lexicographical) { const int delta = std::distance(right.begin(), left.begin()); @@ -53,16 +52,16 @@ static int CompareStringRanges(absl::string_view left, } struct LessStringRanges { - bool operator()(absl::string_view left, absl::string_view right) const { + bool operator()(std::string_view left, std::string_view right) const { return CompareStringRanges(left, right) < 0; } }; -using StringRangeSet = std::set; +using StringRangeSet = std::set; // This function helps find symmetric differences between two sets // of findings (actual vs. expected) based on locations. -static int CompareFindingLocation(absl::string_view lhs, const TokenInfo &rhs) { +static int CompareFindingLocation(std::string_view lhs, const TokenInfo &rhs) { const int delta = CompareStringRanges(lhs, rhs.text()); // Then compare enums, where we only care about equality. return delta; @@ -70,14 +69,14 @@ static int CompareFindingLocation(absl::string_view lhs, const TokenInfo &rhs) { // TODO(b/151371397): refactor this for re-use for multi-findings style tests. bool SyntaxTreeSearchTestCase::ExactMatchFindings( - const std::vector &actual_findings, absl::string_view base, + const std::vector &actual_findings, std::string_view base, std::ostream *diffstream) const { // Convert actual_findings into string ranges. Ignore matches' context. StringRangeSet actual_findings_ranges; for (const auto &finding : actual_findings) { if (finding.match == nullptr) continue; const auto &match_symbol(*finding.match); - const absl::string_view spanned_text = StringSpanOfSymbol(match_symbol); + const std::string_view spanned_text = StringSpanOfSymbol(match_symbol); // Spanned text can be empty when a subtree is devoid of leaves. if (spanned_text.empty()) continue; actual_findings_ranges.insert(spanned_text); @@ -91,7 +90,7 @@ bool SyntaxTreeSearchTestCase::ExactMatchFindings( // Thus, we can use an algorithm like std::set_symmetric_difference(). // These containers will catch unmatched differences found. - std::vector unmatched_actual_findings; + std::vector unmatched_actual_findings; std::vector unmatched_expected_findings; set_symmetric_difference_split( diff --git a/verible/common/analysis/syntax-tree-search-test-utils.h b/verible/common/analysis/syntax-tree-search-test-utils.h index 641f3a5ee..f8f3eee5b 100644 --- a/verible/common/analysis/syntax-tree-search-test-utils.h +++ b/verible/common/analysis/syntax-tree-search-test-utils.h @@ -17,9 +17,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/lexer/lexer-test-util.h" #include "verible/common/text/token-info-test-util.h" @@ -46,7 +46,7 @@ struct SyntaxTreeSearchTestCase : public SynthesizedLexerTestData { // TODO(b/141875806): Take a symbol translator function to produce a // human-readable, language-specific enum name. bool ExactMatchFindings(const std::vector &actual_findings, - absl::string_view base, + std::string_view base, std::ostream *diffstream) const; }; diff --git a/verible/common/analysis/syntax-tree-search-test-utils_test.cc b/verible/common/analysis/syntax-tree-search-test-utils_test.cc index 076c47f76..dd4b4006e 100644 --- a/verible/common/analysis/syntax-tree-search-test-utils_test.cc +++ b/verible/common/analysis/syntax-tree-search-test-utils_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/text/tree-builder-test-util.h" @@ -31,7 +31,7 @@ namespace { TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, AllEmpty) { const SyntaxTreeSearchTestCase test{}; const std::vector actual_findings; - const absl::string_view text; + const std::string_view text; std::ostringstream diffstream; EXPECT_TRUE(test.ExactMatchFindings(actual_findings, text, &diffstream)); } @@ -44,12 +44,12 @@ TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, OneMatchingViolation) { "ghi", }; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(3, 3); + const std::string_view bad_text = text_view.substr(3, 3); constexpr int kTag = -1; auto leaf = Leaf(kTag, bad_text); const std::vector actual_findings{ @@ -68,12 +68,12 @@ TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, IgnoreEmptyStringSpan) { "ghi", }; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(3, 3); + const std::string_view bad_text = text_view.substr(3, 3); constexpr int kTag = -1; auto leaf = Leaf(kTag, bad_text); auto ignored_leaf = Leaf(kTag, bad_text.substr(0, 0)); @@ -94,12 +94,12 @@ TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, IgnoreNullptrSymbol) { "ghi", }; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(3, 3); + const std::string_view bad_text = text_view.substr(3, 3); constexpr int kTag = -1; auto leaf = Leaf(kTag, bad_text); const std::vector actual_findings{ @@ -121,10 +121,10 @@ TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, {kToken, "jkl"}, }; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); const auto bad_text1 = Leaf(kToken, text_view.substr(3, 3)); const auto bad_text2 = Leaf(kToken, text_view.substr(9, 3)); @@ -138,21 +138,21 @@ TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, EXPECT_TRUE(diffstream.str().empty()); } -constexpr absl::string_view kFoundNotExpectedMessage( +constexpr std::string_view kFoundNotExpectedMessage( "actual findings did not match the expected"); -constexpr absl::string_view kExpectedNotFoundMessage( +constexpr std::string_view kExpectedNotFoundMessage( "expected findings did not match the ones found"); TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, OneFoundNotExpected) { constexpr int kToken = 42; const SyntaxTreeSearchTestCase test{"abcdefghi"}; // no expected violations const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(3, 3); + const std::string_view bad_text = text_view.substr(3, 3); const auto leaf = Leaf(kToken, bad_text); const std::vector actual_findings{ {leaf.get(), {/* context ignored */}}, @@ -169,12 +169,12 @@ TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, OneExpectedNotFound) { constexpr int kToken = 42; const SyntaxTreeSearchTestCase test{"abc", {kToken, "def"}, "ghi"}; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(3, 3); + const std::string_view bad_text = text_view.substr(3, 3); const std::vector actual_findings; // none expected std::ostringstream diffstream; EXPECT_FALSE( @@ -188,12 +188,12 @@ TEST(SyntaxTreeSearchTestCaseExactMatchFindingsTest, OneMismatchEach) { constexpr int kToken = 42; const SyntaxTreeSearchTestCase test{"abc", {kToken, "def"}, "ghi"}; const std::string text_copy(test.code); - const absl::string_view text_view(text_copy); + const std::string_view text_view(text_copy); // string buffers are in different memory - EXPECT_FALSE(BoundsEqual(absl::string_view(test.code), text_view)); + EXPECT_FALSE(BoundsEqual(std::string_view(test.code), text_view)); - const absl::string_view bad_text = text_view.substr(4, 3); // "efg" + const std::string_view bad_text = text_view.substr(4, 3); // "efg" const auto leaf = Leaf(kToken, bad_text); const std::vector actual_findings{ {leaf.get(), {/* context ignored */}}, diff --git a/verible/common/analysis/text-structure-lint-rule.h b/verible/common/analysis/text-structure-lint-rule.h index 9263ab8d7..26a37c8a6 100644 --- a/verible/common/analysis/text-structure-lint-rule.h +++ b/verible/common/analysis/text-structure-lint-rule.h @@ -30,7 +30,8 @@ #ifndef VERIBLE_COMMON_ANALYSIS_TEXT_STRUCTURE_LINT_RULE_H_ #define VERIBLE_COMMON_ANALYSIS_TEXT_STRUCTURE_LINT_RULE_H_ -#include "absl/strings/string_view.h" +#include + #include "verible/common/analysis/lint-rule.h" #include "verible/common/text/text-structure.h" @@ -42,7 +43,7 @@ class TextStructureLintRule : public LintRule { // Analyze text structure for violations. virtual void Lint(const TextStructureView &text_structure, - absl::string_view filename) = 0; + std::string_view filename) = 0; }; } // namespace verible diff --git a/verible/common/analysis/text-structure-linter-test-utils.h b/verible/common/analysis/text-structure-linter-test-utils.h index 4b65f9173..3e5e241d1 100644 --- a/verible/common/analysis/text-structure-linter-test-utils.h +++ b/verible/common/analysis/text-structure-linter-test-utils.h @@ -16,10 +16,10 @@ #define VERIBLE_COMMON_ANALYSIS_TEXT_STRUCTURE_LINTER_TEST_UTILS_H_ #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/text-structure-lint-rule.h" @@ -37,7 +37,7 @@ class LintRunner { } LintRuleStatus Run(const TextStructureView &text_structure, - absl::string_view filename) { + std::string_view filename) { linter_.Lint(text_structure, filename); // Looking for one type of rule violation at a time. CHECK_EQ(linter_.ReportStatus().size(), 1); diff --git a/verible/common/analysis/text-structure-linter.cc b/verible/common/analysis/text-structure-linter.cc index b4472e034..d559c3ff1 100644 --- a/verible/common/analysis/text-structure-linter.cc +++ b/verible/common/analysis/text-structure-linter.cc @@ -14,9 +14,9 @@ #include "verible/common/analysis/text-structure-linter.h" +#include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/text-structure-lint-rule.h" #include "verible/common/text/text-structure.h" @@ -25,7 +25,7 @@ namespace verible { void TextStructureLinter::Lint(const TextStructureView &text_structure, - absl::string_view filename) { + std::string_view filename) { VLOG(1) << "TextStructureLinter analyzing text with " << rules_.size() << " rules."; for (const auto &rule : rules_) { diff --git a/verible/common/analysis/text-structure-linter.h b/verible/common/analysis/text-structure-linter.h index 88ac86cb8..bb5214354 100644 --- a/verible/common/analysis/text-structure-linter.h +++ b/verible/common/analysis/text-structure-linter.h @@ -20,10 +20,10 @@ #define VERIBLE_COMMON_ANALYSIS_TEXT_STRUCTURE_LINTER_H_ #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/text-structure-lint-rule.h" #include "verible/common/text/text-structure.h" @@ -33,7 +33,7 @@ namespace verible { class TextStructureLinter { public: // Analyzes a sequence of tokens. - void Lint(const TextStructureView &, absl::string_view); + void Lint(const TextStructureView &, std::string_view); // Transfers ownership of rule into this Linter void AddRule(std::unique_ptr rule) { diff --git a/verible/common/analysis/text-structure-linter_test.cc b/verible/common/analysis/text-structure-linter_test.cc index f3b5132c6..94e7f5b99 100644 --- a/verible/common/analysis/text-structure-linter_test.cc +++ b/verible/common/analysis/text-structure-linter_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/analysis/lint-rule-status.h" @@ -39,9 +39,9 @@ class RequireHelloRule : public TextStructureLintRule { RequireHelloRule() = default; void Lint(const TextStructureView &text_structure, - absl::string_view filename) final { + std::string_view filename) final { const auto &lines = text_structure.Lines(); - const absl::string_view contents = text_structure.Contents(); + const std::string_view contents = text_structure.Contents(); if (!lines.empty() && !absl::StartsWith(contents, "Hello")) { const TokenInfo token(1, lines[0]); violations_.emplace(token, "Text must begin with Hello"); diff --git a/verible/common/analysis/token-stream-linter-test-utils.h b/verible/common/analysis/token-stream-linter-test-utils.h index ab54919ee..e57e11b3a 100644 --- a/verible/common/analysis/token-stream-linter-test-utils.h +++ b/verible/common/analysis/token-stream-linter-test-utils.h @@ -16,10 +16,10 @@ #define VERIBLE_COMMON_ANALYSIS_TOKEN_STREAM_LINTER_TEST_UTILS_H_ #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/token-stream-lint-rule.h" @@ -37,7 +37,7 @@ class LintRunner { } LintRuleStatus Run(const TextStructureView &text_structure, - absl::string_view) { + std::string_view) { linter_.Lint(text_structure.TokenStream()); // Looking for one type of rule violation at a time. CHECK_EQ(linter_.ReportStatus().size(), 1); diff --git a/verible/common/analysis/token-stream-linter_test.cc b/verible/common/analysis/token-stream-linter_test.cc index 7129bd84c..d5d9a8926 100644 --- a/verible/common/analysis/token-stream-linter_test.cc +++ b/verible/common/analysis/token-stream-linter_test.cc @@ -16,9 +16,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/analysis/lint-rule-status.h" @@ -77,7 +77,7 @@ TEST(TokenStreamLinterTest, OneRuleAcceptsEmptyStream) { // This test verifies that TokenStreamLinter can find violations. TEST(TokenStreamLinterTest, OneRuleRejectsTokenStream) { - const absl::string_view text; + const std::string_view text; const TokenSequence tokens = {TokenInfo(1, text), TokenInfo(4, text), TokenInfo(2, text), TokenInfo::EOFToken()}; // EOF token only diff --git a/verible/common/analysis/violation-handler.cc b/verible/common/analysis/violation-handler.cc index 11cd38551..596502ba7 100644 --- a/verible/common/analysis/violation-handler.cc +++ b/verible/common/analysis/violation-handler.cc @@ -20,11 +20,11 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/strings/diff.h" #include "verible/common/util/file-util.h" @@ -34,7 +34,7 @@ namespace verible { namespace { -void PrintFix(std::ostream &stream, absl::string_view text, +void PrintFix(std::ostream &stream, std::string_view text, const verible::AutoFix &fix) { std::string after = fix.Apply(text); verible::LineDiffs diff(text, after); @@ -42,7 +42,7 @@ void PrintFix(std::ostream &stream, absl::string_view text, verible::LineDiffsToUnifiedDiff(stream, diff, 1); } -void PrintFixAlternatives(std::ostream &stream, absl::string_view text, +void PrintFixAlternatives(std::ostream &stream, std::string_view text, const std::vector &fixes) { const bool print_alternative_number = fixes.size() > 1; for (size_t i = 0; i < fixes.size(); ++i) { @@ -61,8 +61,8 @@ void PrintFixAlternatives(std::ostream &stream, absl::string_view text, } // namespace void ViolationPrinter::HandleViolations( - const std::set &violations, absl::string_view base, - absl::string_view path) { + const std::set &violations, std::string_view base, + std::string_view path) { verible::LintStatusFormatter formatter(base); for (auto violation : violations) { formatter.FormatViolation(stream_, *violation.violation, base, path, @@ -73,8 +73,8 @@ void ViolationPrinter::HandleViolations( } void ViolationWaiverPrinter::HandleViolations( - const std::set &violations, absl::string_view base, - absl::string_view path) { + const std::set &violations, std::string_view base, + std::string_view path) { verible::LintStatusFormatter formatter(base); for (auto violation : violations) { formatter.FormatViolation(message_stream_, *violation.violation, base, path, @@ -88,8 +88,8 @@ void ViolationWaiverPrinter::HandleViolations( } } -void ViolationFixer::CommitFixes(absl::string_view source_content, - absl::string_view source_path, +void ViolationFixer::CommitFixes(std::string_view source_content, + std::string_view source_path, const verible::AutoFix &fix) const { if (fix.Edits().empty()) { return; @@ -111,8 +111,8 @@ void ViolationFixer::CommitFixes(absl::string_view source_content, } void ViolationFixer::HandleViolations( - const std::set &violations, absl::string_view base, - absl::string_view path) { + const std::set &violations, std::string_view base, + std::string_view path) { verible::AutoFix fix; verible::LintStatusFormatter formatter(base); for (auto violation : violations) { @@ -124,8 +124,8 @@ void ViolationFixer::HandleViolations( } void ViolationFixer::HandleViolation( - const verible::LintViolation &violation, absl::string_view base, - absl::string_view path, absl::string_view url, absl::string_view rule_name, + const verible::LintViolation &violation, std::string_view base, + std::string_view path, std::string_view url, std::string_view rule_name, const verible::LintStatusFormatter &formatter, verible::AutoFix *fix) { std::stringstream violation_message; formatter.FormatViolation(&violation_message, violation, base, path, url, @@ -136,7 +136,7 @@ void ViolationFixer::HandleViolation( return; } - static absl::string_view previous_fix_conflict = + static std::string_view previous_fix_conflict = "The fix conflicts with " "previously applied fixes, rejecting.\n"; @@ -198,8 +198,8 @@ void ViolationFixer::HandleViolation( } ViolationFixer::Answer ViolationFixer::InteractiveAnswerChooser( - const verible::LintViolation &violation, absl::string_view rule_name) { - static absl::string_view fixed_help_message = + const verible::LintViolation &violation, std::string_view rule_name) { + static std::string_view fixed_help_message = "n - reject fix\n" "a - apply this and all remaining fixes for violations of this rule\n" "d - reject this and all remaining fixes for violations of this rule\n" diff --git a/verible/common/analysis/violation-handler.h b/verible/common/analysis/violation-handler.h index 4925aeae4..deb8281b4 100644 --- a/verible/common/analysis/violation-handler.h +++ b/verible/common/analysis/violation-handler.h @@ -20,8 +20,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" namespace verible { @@ -40,7 +40,7 @@ class ViolationHandler { // from different files. `base` contains source code from the file. virtual void HandleViolations( const std::set &violations, - absl::string_view base, absl::string_view path) = 0; + std::string_view base, std::string_view path) = 0; }; // ViolationHandler that prints all violations in a form of user-friendly @@ -51,7 +51,7 @@ class ViolationPrinter : public ViolationHandler { void HandleViolations( const std::set &violations, - absl::string_view base, absl::string_view path) final; + std::string_view base, std::string_view path) final; protected: std::ostream *const stream_; @@ -68,7 +68,7 @@ class ViolationWaiverPrinter : public ViolationHandler { void HandleViolations( const std::set &violations, - absl::string_view base, absl::string_view path) final; + std::string_view base, std::string_view path) final; protected: std::ostream *const message_stream_; @@ -117,7 +117,7 @@ class ViolationFixer : public verible::ViolationHandler { }; using AnswerChooser = - std::function; + std::function; // Violation fixer with user-chosen answer chooser. ViolationFixer(std::ostream *message_stream, std::ostream *patch_stream, @@ -131,7 +131,7 @@ class ViolationFixer : public verible::ViolationHandler { void HandleViolations( const std::set &violations, - absl::string_view base, absl::string_view path) final; + std::string_view base, std::string_view path) final; private: ViolationFixer(std::ostream *message_stream, std::ostream *patch_stream, @@ -143,16 +143,16 @@ class ViolationFixer : public verible::ViolationHandler { ultimate_answer_({AnswerChoice::kUnknown, 0}) {} void HandleViolation(const verible::LintViolation &violation, - absl::string_view base, absl::string_view path, - absl::string_view url, absl::string_view rule_name, + std::string_view base, std::string_view path, + std::string_view url, std::string_view rule_name, const verible::LintStatusFormatter &formatter, verible::AutoFix *fix); static Answer InteractiveAnswerChooser( - const verible::LintViolation &violation, absl::string_view rule_name); + const verible::LintViolation &violation, std::string_view rule_name); - void CommitFixes(absl::string_view source_content, - absl::string_view source_path, + void CommitFixes(std::string_view source_content, + std::string_view source_path, const verible::AutoFix &fix) const; std::ostream *const message_stream_; @@ -161,7 +161,7 @@ class ViolationFixer : public verible::ViolationHandler { const bool is_interactive_; Answer ultimate_answer_; - std::map rule_answers_; + std::map rule_answers_; }; } // namespace verible diff --git a/verible/common/formatting/BUILD b/verible/common/formatting/BUILD index 7ae0df4b0..6cf7e38d1 100644 --- a/verible/common/formatting/BUILD +++ b/verible/common/formatting/BUILD @@ -34,7 +34,6 @@ cc_library( "//verible/common/util:vector-tree", "//verible/common/util:vector-tree-iterators", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -60,7 +59,6 @@ cc_test( "//verible/common/util:spacer", "//verible/common/util:value-saver", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -70,10 +68,7 @@ cc_library( name = "basic-format-style", srcs = ["basic-format-style.cc"], hdrs = ["basic-format-style.h"], - deps = [ - "//verible/common/util:enum-flags", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["//verible/common/util:enum-flags"], ) cc_library( @@ -114,7 +109,6 @@ cc_library( "//verible/common/util:spacer", "@abseil-cpp//absl/base:core_headers", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -127,7 +121,6 @@ cc_test( "//verible/common/strings:position", "//verible/common/text:token-info", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -154,7 +147,6 @@ cc_library( "@abseil-cpp//absl/container:fixed_array", "@abseil-cpp//absl/log", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -181,7 +173,6 @@ cc_test( "//verible/common/util:vector-tree", "@abseil-cpp//absl/container:fixed_array", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -210,7 +201,6 @@ cc_library( "//verible/common/util:top-n", "//verible/common/util:tree-operations", "//verible/common/util:vector-tree", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -247,7 +237,6 @@ cc_test( "//verible/common/util:tree-operations", "//verible/common/util:vector-tree", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -283,7 +272,6 @@ cc_library( ":unwrapped-line", "//verible/common/text:constants", "//verible/common/text:token-info", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -298,7 +286,6 @@ cc_test( "//verible/common/text:token-info", "//verible/common/text:tree-builder-test-util", "//verible/common/util:container-iterator-range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -332,7 +319,6 @@ cc_test( "//verible/common/text:tree-builder-test-util", "//verible/common/util:iterator-range", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -359,7 +345,6 @@ cc_library( "//verible/common/util:tree-operations", "//verible/common/util:value-saver", "//verible/common/util:vector-tree", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -379,7 +364,6 @@ cc_test( "//verible/common/util:container-iterator-range", "//verible/common/util:range", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -401,7 +385,6 @@ cc_library( "//verible/common/util:iterator-adaptors", "//verible/common/util:iterator-range", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -431,7 +414,6 @@ cc_test( ":unwrapped-line-test-utils", "//verible/common/text:token-info", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -462,7 +444,6 @@ cc_library( "//verible/common/strings:position", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/common/formatting/align.cc b/verible/common/formatting/align.cc index cafc53ec0..6f69ef39f 100644 --- a/verible/common/formatting/align.cc +++ b/verible/common/formatting/align.cc @@ -25,12 +25,12 @@ #include #include #include +#include #include #include #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/token-partition-tree.h" #include "verible/common/formatting/unwrapped-line.h" @@ -68,7 +68,7 @@ std::ostream &operator<<(std::ostream &stream, AlignmentPolicy policy) { return AlignmentPolicyNameMap().Unparse(policy, stream); } -bool AbslParseFlag(absl::string_view text, AlignmentPolicy *policy, +bool AbslParseFlag(std::string_view text, AlignmentPolicy *policy, std::string *error) { return AlignmentPolicyNameMap().Parse(text, policy, error, "AlignmentPolicy"); } @@ -195,7 +195,7 @@ static void ColumnsTreeFormatter( const CellLabelGetterFunc &get_cell_label) { if (root.Children().empty()) return; - static constexpr absl::string_view kCellSeparator = "|"; + static constexpr std::string_view kCellSeparator = "|"; struct Cell { std::string text; @@ -265,8 +265,7 @@ static void ColumnsTreeFormatter( } } - const std::vector parts = - absl::StrSplit(cell.text, '\t'); + const std::vector parts = absl::StrSplit(cell.text, '\t'); const auto width = cell.width - kCellSeparator.size(); @@ -1189,7 +1188,7 @@ void FormatUsingOriginalSpacing(TokenPartitionRange partition_range) { int spacing = whitespace.size(); std::size_t last_newline_pos = whitespace.find_last_of('\n'); - if (last_newline_pos != absl::string_view::npos) { + if (last_newline_pos != std::string_view::npos) { // Update end of current line. partition.Children().back().Value().SpanUpToToken(it); // Start a new line. @@ -1273,7 +1272,7 @@ void AlignablePartitionGroup::Align(int column_limit) const { } void TabularAlignTokens( - int column_limit, absl::string_view full_text, + int column_limit, std::string_view full_text, const ByteOffsetSet &disabled_byte_ranges, const ExtractAlignmentGroupsFunction &extract_alignment_groups, TokenPartitionTree *partition_ptr) { diff --git a/verible/common/formatting/align.h b/verible/common/formatting/align.h index af9a53ddf..d042ae0b8 100644 --- a/verible/common/formatting/align.h +++ b/verible/common/formatting/align.h @@ -19,9 +19,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/token-partition-tree.h" #include "verible/common/formatting/unwrapped-line.h" @@ -250,7 +250,7 @@ enum class AlignmentPolicy { std::ostream &operator<<(std::ostream &, AlignmentPolicy); -bool AbslParseFlag(absl::string_view text, AlignmentPolicy *policy, +bool AbslParseFlag(std::string_view text, AlignmentPolicy *policy, std::string *error); std::string AbslUnparseFlag(const AlignmentPolicy &policy); @@ -538,7 +538,7 @@ void FormatUsingOriginalSpacing(TokenPartitionRange partition_range); // ccc[33] dd [444] // void TabularAlignTokens( - int column_limit, absl::string_view full_text, + int column_limit, std::string_view full_text, const ByteOffsetSet &disabled_byte_ranges, const ExtractAlignmentGroupsFunction &extract_alignment_groups, TokenPartitionTree *partition_ptr); diff --git a/verible/common/formatting/align_test.cc b/verible/common/formatting/align_test.cc index d2c19cfc5..f9a3e3e1f 100644 --- a/verible/common/formatting/align_test.cc +++ b/verible/common/formatting/align_test.cc @@ -20,12 +20,12 @@ #include #include #include +#include #include #include #include "absl/strings/match.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/formatting/format-token.h" @@ -68,7 +68,7 @@ TEST(AlignmentPolicyTest, InvalidEnum) { class AlignmentTestFixture : public ::testing::Test, public UnwrappedLineMemoryHandler { public: - explicit AlignmentTestFixture(absl::string_view text) + explicit AlignmentTestFixture(std::string_view text) : sample_backing_(text), sample_(sample_backing_), tokens_(absl::StrSplit(sample_, absl::ByAnyChar(" \n"), @@ -82,8 +82,8 @@ class AlignmentTestFixture : public ::testing::Test, protected: const std::string sample_backing_; - const absl::string_view sample_; - const std::vector tokens_; + const std::string_view sample_; + const std::vector tokens_; std::vector ftokens_; }; @@ -171,7 +171,7 @@ TEST_F(TabularAlignTokenTest, EmptyPartitionRange) { class MatrixTreeAlignmentTestFixture : public AlignmentTestFixture { public: - explicit MatrixTreeAlignmentTestFixture(absl::string_view text) + explicit MatrixTreeAlignmentTestFixture(std::string_view text) : AlignmentTestFixture(text), syntax_tree_(nullptr), // for subclasses to initialize partition_(/* temporary */ UnwrappedLine()) {} @@ -200,7 +200,7 @@ class MatrixTreeAlignmentTestFixture : public AlignmentTestFixture { class Sparse3x3MatrixAlignmentTest : public MatrixTreeAlignmentTestFixture { public: explicit Sparse3x3MatrixAlignmentTest( - absl::string_view text = "one two three four five six") + std::string_view text = "one two three four five six") : MatrixTreeAlignmentTestFixture(text) { // From the sample_ text, each pair of tokens will span a subpartition. // Construct a 2-level partition that looks like this: @@ -607,7 +607,7 @@ class MultiAlignmentGroupTest : public AlignmentTestFixture { std::string Render() { std::ostringstream stream; int position = 0; - const absl::string_view text(sample_); + const std::string_view text(sample_); for (auto &child : partition_.Children()) { const auto policy = child.Value().PartitionPolicy(); if (policy == PartitionPolicyEnum::kAlreadyFormatted) { @@ -617,7 +617,7 @@ class MultiAlignmentGroupTest : public AlignmentTestFixture { // emulate preserving vertical spacing const auto tokens_range = child.Value().TokensRange(); const auto front_offset = tokens_range.front().token->left(text); - const absl::string_view spaces = + const std::string_view spaces = text.substr(position, front_offset - position); const auto newlines = std::max(std::count(spaces.begin(), spaces.end(), '\n') - 1, 0); @@ -713,7 +713,7 @@ class GetPartitionAlignmentSubrangesTestFixture : public AlignmentTestFixture { protected: static AlignmentGroupAction PartitionSelector( const TokenPartitionTree &partition) { - const absl::string_view text = + const std::string_view text = partition.Value().TokensRange().front().Text(); if (text == "match") { return AlignmentGroupAction::kMatch; @@ -813,12 +813,12 @@ class GetPartitionAlignmentSubrangesSubtypedTestFixture protected: static AlignedPartitionClassification PartitionSelector( const TokenPartitionTree &partition) { - const absl::string_view text = + const std::string_view text = partition.Value().TokensRange().front().Text(); if (absl::StartsWith(text, "match")) { const auto toks = absl::StrSplit(text, absl::ByChar(':')); CHECK(toks.begin() != toks.end()); - absl::string_view last = *std::next(toks.begin()); + std::string_view last = *std::next(toks.begin()); // Use the first character after the : as the subtype, so 'X', 'Y', 'Z'. return {AlignmentGroupAction::kMatch, static_cast(last.front())}; } @@ -862,7 +862,7 @@ TEST_F(GetPartitionAlignmentSubrangesSubtypedTestFixture, VariousRanges) { class Dense2x2MatrixAlignmentTest : public MatrixTreeAlignmentTestFixture { public: explicit Dense2x2MatrixAlignmentTest( - absl::string_view text = "one two three four") + std::string_view text = "one two three four") : MatrixTreeAlignmentTestFixture(text) { CHECK_EQ(tokens_.size(), 4); @@ -1041,7 +1041,7 @@ class SyntaxTreeColumnizer : public ColumnSchemaScanner { class SubcolumnsTreeAlignmentTest : public MatrixTreeAlignmentTestFixture { public: explicit SubcolumnsTreeAlignmentTest( - absl::string_view text = + std::string_view text = "zero\n" "( one two three )\n" "( four ( five six ) seven )\n" @@ -1272,7 +1272,7 @@ TEST_F(SubcolumnsTreeAlignmentTest, class MultiSubcolumnsTreeAlignmentTest : public SubcolumnsTreeAlignmentTest { public: explicit MultiSubcolumnsTreeAlignmentTest( - absl::string_view text = + std::string_view text = "zero\n" "( one two three )\n" "( four ( five six ) seven )\n" @@ -1284,7 +1284,7 @@ class MultiSubcolumnsTreeAlignmentTest : public SubcolumnsTreeAlignmentTest { std::string Render() { std::ostringstream stream; int position = 0; - const absl::string_view text(sample_); + const std::string_view text(sample_); for (auto &child : partition_.Children()) { const auto policy = child.Value().PartitionPolicy(); if (policy == PartitionPolicyEnum::kAlreadyFormatted) { @@ -1294,7 +1294,7 @@ class MultiSubcolumnsTreeAlignmentTest : public SubcolumnsTreeAlignmentTest { // emulate preserving vertical spacing const auto tokens_range = child.Value().TokensRange(); const auto front_offset = tokens_range.front().token->left(text); - const absl::string_view spaces = + const std::string_view spaces = text.substr(position, front_offset - position); const auto newlines = std::max(std::count(spaces.begin(), spaces.end(), '\n') - 1, 0); @@ -1326,7 +1326,7 @@ TEST_F(MultiSubcolumnsTreeAlignmentTest, BlankLineSeparatedGroups) { class InferSubcolumnsTreeAlignmentTest : public SubcolumnsTreeAlignmentTest { public: explicit InferSubcolumnsTreeAlignmentTest( - absl::string_view text = + std::string_view text = "zero\n" "( one two three )\n" "( four ( five six ) seven )\n" @@ -1367,7 +1367,7 @@ TEST_F(InferSubcolumnsTreeAlignmentTest, InferUserIntent) { class SubcolumnsTreeWithDelimitersTest : public SubcolumnsTreeAlignmentTest { public: - explicit SubcolumnsTreeWithDelimitersTest(absl::string_view text = + explicit SubcolumnsTreeWithDelimitersTest(std::string_view text = "( One Two , )\n" "( Three Four )\n" "\n" @@ -1390,7 +1390,7 @@ TEST_F(SubcolumnsTreeWithDelimitersTest, ContainsDelimiterTest) { template struct ColumnsTreeFormatterTestCase { Tree input; - absl::string_view expected; + std::string_view expected; }; TEST(ColumnsTreeFormatter, ColumnPositionTreePrinter) { @@ -1465,20 +1465,20 @@ class OutsideCharPairs { explicit OutsideCharPairs(char start, char stop) : start_(start), stop_(stop) {} - absl::string_view Find(absl::string_view text, size_t pos) const { + std::string_view Find(std::string_view text, size_t pos) const { if (text[pos] == start_) { const size_t stop_pos = text.find(stop_, pos + 1); - if (stop_pos == absl::string_view::npos) { - return absl::string_view(text.data() + text.size(), 0); + if (stop_pos == std::string_view::npos) { + return std::string_view(text.data() + text.size(), 0); } const size_t start_pos = text.find(start_, stop_pos + 1); - if (start_pos == absl::string_view::npos) { + if (start_pos == std::string_view::npos) { return text.substr(stop_pos + 1); } return text.substr(stop_pos + 1, start_pos - stop_pos - 1); } const size_t start_pos = text.find(start_, pos); - if (start_pos == absl::string_view::npos) return text.substr(pos); + if (start_pos == std::string_view::npos) return text.substr(pos); return text.substr(pos, start_pos - pos); } @@ -1491,7 +1491,7 @@ class FormatUsingOriginalSpacingTest : public ::testing::Test, public UnwrappedLineMemoryHandler { public: explicit FormatUsingOriginalSpacingTest( - absl::string_view text = + std::string_view text = "" " <1Space> <1space>" " <4Spaces> <4spaces>" @@ -1522,8 +1522,8 @@ class FormatUsingOriginalSpacingTest : public ::testing::Test, } const std::string sample_backing_; - const absl::string_view sample_; - const std::vector tokens_; + const std::string_view sample_; + const std::vector tokens_; std::vector ftokens_; }; diff --git a/verible/common/formatting/basic-format-style.cc b/verible/common/formatting/basic-format-style.cc index 979d54b20..5c1d7f109 100644 --- a/verible/common/formatting/basic-format-style.cc +++ b/verible/common/formatting/basic-format-style.cc @@ -17,8 +17,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/util/enum-flags.h" namespace verible { @@ -37,7 +37,7 @@ std::ostream &operator<<(std::ostream &stream, IndentationStyle p) { return IndentationStyleStrings().Unparse(p, stream); } -bool AbslParseFlag(absl::string_view text, IndentationStyle *mode, +bool AbslParseFlag(std::string_view text, IndentationStyle *mode, std::string *error) { return IndentationStyleStrings().Parse(text, mode, error, "IndentationStyle"); } diff --git a/verible/common/formatting/basic-format-style.h b/verible/common/formatting/basic-format-style.h index 2812122c4..58a73ea03 100644 --- a/verible/common/formatting/basic-format-style.h +++ b/verible/common/formatting/basic-format-style.h @@ -17,8 +17,7 @@ #include #include - -#include "absl/strings/string_view.h" +#include namespace verible { @@ -60,7 +59,7 @@ enum class IndentationStyle { std::ostream &operator<<(std::ostream &, IndentationStyle); -bool AbslParseFlag(absl::string_view, IndentationStyle *, std::string *); +bool AbslParseFlag(std::string_view, IndentationStyle *, std::string *); std::string AbslUnparseFlag(const IndentationStyle &); diff --git a/verible/common/formatting/format-token.cc b/verible/common/formatting/format-token.cc index f5f0f6104..b4a8afa86 100644 --- a/verible/common/formatting/format-token.cc +++ b/verible/common/formatting/format-token.cc @@ -19,12 +19,12 @@ #include #include // pragma IWYU: keep // for ostringstream #include +#include #include #include #include "absl/base/attributes.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/display-utils.h" #include "verible/common/strings/position.h" #include "verible/common/strings/range.h" @@ -143,9 +143,9 @@ InterTokenDecision::InterTokenDecision(const InterTokenInfo &info) action(ConvertSpacing(info.break_decision)), preserved_space_start(info.preserved_space_start) {} -static absl::string_view OriginalLeadingSpacesRange( - absl::string_view::const_iterator begin, - absl::string_view::const_iterator end) { +static std::string_view OriginalLeadingSpacesRange( + std::string_view::const_iterator begin, + std::string_view::const_iterator end) { if (begin == string_view_null_iterator()) { VLOG(4) << "no original space range"; return make_string_view_range(end, end); // empty range @@ -156,7 +156,7 @@ static absl::string_view OriginalLeadingSpacesRange( return make_string_view_range(begin, end); } -absl::string_view FormattedToken::OriginalLeadingSpaces() const { +std::string_view FormattedToken::OriginalLeadingSpaces() const { return OriginalLeadingSpacesRange(before.preserved_space_start, token->text().begin()); } @@ -190,7 +190,7 @@ std::ostream &operator<<(std::ostream &stream, const FormattedToken &token) { return token.FormattedText(stream); } -absl::string_view PreFormatToken::OriginalLeadingSpaces() const { +std::string_view PreFormatToken::OriginalLeadingSpaces() const { return OriginalLeadingSpacesRange(before.preserved_space_start, token->text().begin()); } @@ -206,7 +206,7 @@ size_t PreFormatToken::LeadingSpacesLength() const { int PreFormatToken::ExcessSpaces() const { if (before.preserved_space_start == string_view_null_iterator()) return 0; - const absl::string_view leading_spaces = OriginalLeadingSpaces(); + const std::string_view leading_spaces = OriginalLeadingSpaces(); int delta = 0; if (!absl::StrContains(leading_spaces, "\n")) { delta = static_cast(leading_spaces.length()) - before.spaces_required; @@ -229,7 +229,7 @@ std::ostream &operator<<(std::ostream &stream, const PreFormatToken &t) { } void ConnectPreFormatTokensPreservedSpaceStarts( - absl::string_view::const_iterator buffer_start, + std::string_view::const_iterator buffer_start, std::vector *format_tokens) { VLOG(4) << __FUNCTION__; CHECK(buffer_start != string_view_null_iterator()); @@ -246,7 +246,7 @@ void ConnectPreFormatTokensPreservedSpaceStarts( static MutableFormatTokenRange FindFormatTokensInByteOffsetRange( std::vector::iterator begin, std::vector::iterator end, - const std::pair &byte_offset_range, absl::string_view base_text) { + const std::pair &byte_offset_range, std::string_view base_text) { const auto tokens_begin = std::lower_bound(begin, end, byte_offset_range.first, [=](const PreFormatToken &t, int position) { @@ -262,7 +262,7 @@ static MutableFormatTokenRange FindFormatTokensInByteOffsetRange( void PreserveSpacesOnDisabledTokenRanges( std::vector *ftokens, - const ByteOffsetSet &disabled_byte_ranges, absl::string_view base_text) { + const ByteOffsetSet &disabled_byte_ranges, std::string_view base_text) { VLOG(2) << __FUNCTION__; // saved_iter: shrink bounds of binary search with every iteration, // due to monotonic, non-overlapping intervals. @@ -288,7 +288,7 @@ void PreserveSpacesOnDisabledTokenRanges( VLOG(3) << "checking whether first ftoken in range is a must-wrap."; if (first.before.break_decision == SpacingOptions::kMustWrap) { VLOG(3) << "checking if spaces before first ftoken starts with \\n."; - const absl::string_view leading_space = first.OriginalLeadingSpaces(); + const std::string_view leading_space = first.OriginalLeadingSpaces(); // consume the first '\n' from the preceding inter-token spaces if (absl::StartsWith(leading_space, "\n")) { VLOG(3) << "consuming leading \\n."; diff --git a/verible/common/formatting/format-token.h b/verible/common/formatting/format-token.h index 8a6071160..994b8881e 100644 --- a/verible/common/formatting/format-token.h +++ b/verible/common/formatting/format-token.h @@ -18,9 +18,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/strings/position.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/token-info.h" @@ -31,8 +31,8 @@ namespace verible { // TODO: find something platform independent that is less ugly. // Or maybe revisit the place where we need this and see if they could // be actually represented by a const char * nullptr. -inline absl::string_view::const_iterator string_view_null_iterator() { - return absl::string_view::const_iterator{}; +inline std::string_view::const_iterator string_view_null_iterator() { + return std::string_view::const_iterator{}; } // Enumeration for options for formatting spaces between tokens. @@ -83,7 +83,7 @@ struct InterTokenInfo { // tokens, for the sake of preserving space. // Together with the current token, they can form a string_view representing // pre-existing space from the original buffer. - absl::string_view::const_iterator preserved_space_start = + std::string_view::const_iterator preserved_space_start = string_view_null_iterator(); InterTokenInfo() = default; @@ -137,13 +137,13 @@ struct PreFormatToken { int Length() const { return token->text().length(); } // Returns the text of the TokenInfo token held by this PreFormatToken - absl::string_view Text() const { return token->text(); } + std::string_view Text() const { return token->text(); } // Returns the enum of the TokenInfo token held by this PreFormatToken int TokenEnum() const { return token->token_enum(); } // Reconstructs the original spacing that preceded this token. - absl::string_view OriginalLeadingSpaces() const; + std::string_view OriginalLeadingSpaces() const; // Returns OriginalLeadingSpaces().length() - before.spaces_required. // If there is no leading spaces text, return 0. @@ -166,7 +166,7 @@ std::ostream &operator<<(std::ostream &stream, const PreFormatToken &token); // inter-token (space) text. // Note that this does not cover the space between the last token and EOF. void ConnectPreFormatTokensPreservedSpaceStarts( - absl::string_view::const_iterator buffer_start, + std::string_view::const_iterator buffer_start, std::vector *format_tokens); // Marks formatting-disabled ranges of tokens so that their original spacing is @@ -176,7 +176,7 @@ void ConnectPreFormatTokensPreservedSpaceStarts( // as the base reference for 'disabled_byte_ranges' offsets. void PreserveSpacesOnDisabledTokenRanges( std::vector *ftokens, - const ByteOffsetSet &disabled_byte_ranges, absl::string_view base_text); + const ByteOffsetSet &disabled_byte_ranges, std::string_view base_text); using FormatTokenRange = container_iterator_range::const_iterator>; @@ -207,7 +207,7 @@ struct InterTokenDecision { SpacingDecision action = SpacingDecision::kPreserve; // When preserving spaces before this token, start from this offset. - absl::string_view::const_iterator preserved_space_start = + std::string_view::const_iterator preserved_space_start = string_view_null_iterator(); InterTokenDecision() = default; @@ -227,7 +227,7 @@ struct FormattedToken { : token(ftoken.token), before(ftoken.before) {} // Reconstructs the original spacing that preceded this token. - absl::string_view OriginalLeadingSpaces() const; + std::string_view OriginalLeadingSpaces() const; // Print out formatted result after formatting decision optimization. std::ostream &FormattedText(std::ostream &) const; diff --git a/verible/common/formatting/format-token_test.cc b/verible/common/formatting/format-token_test.cc index 8dffc9dbe..d261cf9d2 100644 --- a/verible/common/formatting/format-token_test.cc +++ b/verible/common/formatting/format-token_test.cc @@ -16,9 +16,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/formatting/unwrapped-line-test-utils.h" #include "verible/common/strings/position.h" @@ -130,7 +130,7 @@ TEST(PreFormatTokenTest, VectorResizeable) { } TEST(PreFormatTokenTest, OriginalLeadingSpaces) { - const absl::string_view text("abcdefgh"); + const std::string_view text("abcdefgh"); const TokenInfo tok1(1, text.substr(1, 3)), tok2(2, text.substr(5, 2)); { PreFormatToken p1(&tok1), p2(&tok2); @@ -149,7 +149,7 @@ TEST(PreFormatTokenTest, OriginalLeadingSpaces) { } TEST(PreFormatTokenTest, ExcessSpacesNoNewline) { - const absl::string_view text("abcdefgh"); + const std::string_view text("abcdefgh"); const TokenInfo tok(1, text.substr(1, 3)); PreFormatToken p(&tok); // before.preserved_space_start == nullptr EXPECT_EQ(p.ExcessSpaces(), 0); @@ -163,7 +163,7 @@ TEST(PreFormatTokenTest, ExcessSpacesNoNewline) { } TEST(PreFormatTokenTest, ExcessSpacesNewline) { - const absl::string_view text("\nbcdefgh"); + const std::string_view text("\nbcdefgh"); const TokenInfo tok(1, text.substr(1, 3)); PreFormatToken p(&tok); // before.preserved_space_start == nullptr EXPECT_EQ(p.ExcessSpaces(), 0); @@ -177,7 +177,7 @@ TEST(PreFormatTokenTest, ExcessSpacesNewline) { } TEST(PreFormatTokenTest, LeadingSpacesLength) { - const absl::string_view text("abcdefgh"); + const std::string_view text("abcdefgh"); const TokenInfo tok1(1, text.substr(1, 3)), tok2(2, text.substr(5, 2)); { PreFormatToken p1(&tok1), p2(&tok2); @@ -221,14 +221,14 @@ TEST_F(ConnectPreFormatTokensPreservedSpaceStartsTest, Empty) { // We do want to initialize the text, otherwise string_view wraps a nulllptr // that is checked against downstream. // NOLINTNEXTLINE(readability-redundant-string-init) - constexpr absl::string_view text(""); + constexpr std::string_view text(""); CreateTokenInfosExternalStringBuffer({}); ConnectPreFormatTokensPreservedSpaceStarts(text.begin(), &pre_format_tokens_); EXPECT_TRUE(pre_format_tokens_.empty()); } TEST_F(ConnectPreFormatTokensPreservedSpaceStartsTest, OneToken) { - constexpr absl::string_view text("xyz"); + constexpr std::string_view text("xyz"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 3)}, }); @@ -238,7 +238,7 @@ TEST_F(ConnectPreFormatTokensPreservedSpaceStartsTest, OneToken) { } TEST_F(ConnectPreFormatTokensPreservedSpaceStartsTest, OneTokenLeadingSpace) { - constexpr absl::string_view text(" xyz"); + constexpr std::string_view text(" xyz"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(2, 3)}, // "xyz" }); @@ -248,7 +248,7 @@ TEST_F(ConnectPreFormatTokensPreservedSpaceStartsTest, OneTokenLeadingSpace) { } TEST_F(ConnectPreFormatTokensPreservedSpaceStartsTest, MultipleTokens) { - constexpr absl::string_view text(" xyz\t\t\nabc"); + constexpr std::string_view text(" xyz\t\t\nabc"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(2, 3)}, // "xyz" {2, text.substr(8, 3)}, // "abc" @@ -265,7 +265,7 @@ class PreserveSpacesOnDisabledTokenRangesTest public UnwrappedLineMemoryHandler {}; TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableNone) { - constexpr absl::string_view text("a b c d e"); + constexpr std::string_view text("a b c d e"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 1)}, {2, text.substr(2, 1)}, @@ -282,7 +282,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableNone) { } TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpaceBeforeText) { - constexpr absl::string_view text("a b c d e"); + constexpr std::string_view text("a b c d e"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 1)}, {2, text.substr(2, 1)}, @@ -303,7 +303,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpaceBeforeText) { } TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpaceAfterText) { - constexpr absl::string_view text("a b c d e"); + constexpr std::string_view text("a b c d e"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 1)}, {2, text.substr(2, 1)}, @@ -324,7 +324,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpaceAfterText) { } TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpanningTwoTokens) { - constexpr absl::string_view text("a b c d e"); + constexpr std::string_view text("a b c d e"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 1)}, {2, text.substr(2, 1)}, @@ -345,7 +345,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpanningTwoTokens) { } TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpanningMustWrap) { - constexpr absl::string_view text("a b c d e"); + constexpr std::string_view text("a b c d e"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 1)}, {2, text.substr(2, 1)}, @@ -378,7 +378,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpanningMustWrap) { TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpanningMustWrapWithNewline) { - constexpr absl::string_view text("a\nb\nc d e"); + constexpr std::string_view text("a\nb\nc d e"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 1)}, {2, text.substr(2, 1)}, @@ -392,7 +392,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, PreserveSpacesOnDisabledTokenRanges(&pre_format_tokens_, disabled_bytes, text); const auto &ftokens = pre_format_tokens_; - auto indices = [&text](const absl::string_view &range) { + auto indices = [&text](const std::string_view &range) { return SubRangeIndices(range, text); }; EXPECT_EQ(ftokens[0].before.break_decision, SpacingOptions::kUndecided); @@ -414,7 +414,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, TEST_F(PreserveSpacesOnDisabledTokenRangesTest, DisableSpanningMustWrapWithNewlineKeepIndentation) { - constexpr absl::string_view text("a\n b\n c d e"); + constexpr std::string_view text("a\n b\n c d e"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 1)}, {2, text.substr(4, 1)}, @@ -428,7 +428,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, PreserveSpacesOnDisabledTokenRanges(&pre_format_tokens_, disabled_bytes, text); const auto &ftokens = pre_format_tokens_; - auto indices = [&text](const absl::string_view &range) { + auto indices = [&text](const std::string_view &range) { return SubRangeIndices(range, text); }; EXPECT_EQ(ftokens[0].before.break_decision, SpacingOptions::kUndecided); @@ -449,7 +449,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, } TEST_F(PreserveSpacesOnDisabledTokenRangesTest, MultipleOffsetRanges) { - constexpr absl::string_view text("a\nb\nc d e ff gg"); + constexpr std::string_view text("a\nb\nc d e ff gg"); CreateTokenInfosExternalStringBuffer({ {1, text.substr(0, 1)}, {2, text.substr(2, 1)}, @@ -465,7 +465,7 @@ TEST_F(PreserveSpacesOnDisabledTokenRangesTest, MultipleOffsetRanges) { PreserveSpacesOnDisabledTokenRanges(&pre_format_tokens_, disabled_bytes, text); const auto &ftokens = pre_format_tokens_; - auto indices = [&text](const absl::string_view &range) { + auto indices = [&text](const std::string_view &range) { return SubRangeIndices(range, text); }; EXPECT_EQ(ftokens[0].before.break_decision, SpacingOptions::kUndecided); @@ -526,7 +526,7 @@ TEST(FormattedTokenTest, FormattedText) { } TEST(FormattedTokenTest, OriginalLeadingSpaces) { - const absl::string_view text("abcdefgh"); + const std::string_view text("abcdefgh"); const TokenInfo tok1(1, text.substr(1, 3)), tok2(2, text.substr(5, 2)); const PreFormatToken p1(&tok1), p2(&tok2); { @@ -546,7 +546,7 @@ TEST(FormattedTokenTest, OriginalLeadingSpaces) { } TEST(FormattedTokenTest, PreservedSpaces) { - const absl::string_view text("abcdefgh"); + const std::string_view text("abcdefgh"); const TokenInfo tok1(1, text.substr(1, 3)), tok2(2, text.substr(5, 2)); const PreFormatToken p1(&tok1), p2(&tok2); { @@ -656,7 +656,7 @@ TEST(PreFormatTokenTest, StringRep) { TokenInfo token_info(1, "Hello"); PreFormatToken format_token(&token_info); std::string str(format_token.ToString()); - absl::string_view strv(str); + std::string_view strv(str); EXPECT_NE(strv.find("TokenInfo:"), strv.npos); EXPECT_NE(strv.find("before:"), strv.npos); EXPECT_NE(strv.find("break_decision:"), strv.npos); diff --git a/verible/common/formatting/layout-optimizer-internal.h b/verible/common/formatting/layout-optimizer-internal.h index 39e2deef6..cd489f7d0 100644 --- a/verible/common/formatting/layout-optimizer-internal.h +++ b/verible/common/formatting/layout-optimizer-internal.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include "absl/container/fixed_array.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "verible/common/formatting/basic-format-style.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/token-partition-tree.h" @@ -143,7 +143,7 @@ class LayoutItem { // TODO (mglb): support all possible break_decisions len += token.before.spaces_required; if (const auto line_break_pos = token.Text().find('\n'); - line_break_pos != absl::string_view::npos) { + line_break_pos != std::string_view::npos) { // Multiline tokens are not really supported. // Use number of characters up to the first line break. len += line_break_pos; diff --git a/verible/common/formatting/layout-optimizer_test.cc b/verible/common/formatting/layout-optimizer_test.cc index 54f87c603..ab8b91b13 100644 --- a/verible/common/formatting/layout-optimizer_test.cc +++ b/verible/common/formatting/layout-optimizer_test.cc @@ -21,12 +21,12 @@ #include #include #include +#include #include #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/formatting/basic-format-style.h" #include "verible/common/formatting/format-token.h" @@ -52,7 +52,7 @@ std::string ToString(const T &value) { return s.str(); } -std::ostream &PrintIndented(std::ostream &stream, absl::string_view str, +std::ostream &PrintIndented(std::ostream &stream, std::string_view str, int indentation) { for (const auto &line : verible::SplitLinesKeepLineTerminator(str)) { stream << verible::Spacer(indentation) << line; @@ -61,10 +61,9 @@ std::ostream &PrintIndented(std::ostream &stream, absl::string_view str, } template -void PrintInvalidValueMessage(std::ostream &stream, - absl::string_view value_name, const Value &actual, - const Value &expected, int indentation = 0, - bool multiline = false) { +void PrintInvalidValueMessage(std::ostream &stream, std::string_view value_name, + const Value &actual, const Value &expected, + int indentation = 0, bool multiline = false) { using ::testing::PrintToString; using verible::Spacer; @@ -165,7 +164,7 @@ class LayoutTest : public ::testing::Test, public UnwrappedLineMemoryHandler { protected: const std::string sample_; - const std::vector tokens_; + const std::vector tokens_; std::vector ftokens_; }; @@ -701,8 +700,8 @@ class LayoutFunctionFactoryTest : public ::testing::Test, // Setup pointers for OriginalLeadingSpaces() auto must_wrap_token = must_wrap_pre_format_tokens.begin(); auto joinable_token = joinable_pre_format_tokens.begin(); - absl::string_view sample_view(sample_); - absl::string_view::const_iterator buffer_start = sample_view.begin(); + std::string_view sample_view(sample_); + std::string_view::const_iterator buffer_start = sample_view.begin(); for (size_t i = 0; i < number_of_tokens_in_set; ++i) { must_wrap_token->before.preserved_space_start = buffer_start; joinable_token->before.preserved_space_start = buffer_start; @@ -739,7 +738,7 @@ class LayoutFunctionFactoryTest : public ::testing::Test, // Count spaces preceding the token and set spaces_required accordingly auto last_non_space_offset = leading_spaces.find_last_not_of(' '); - if (last_non_space_offset != absl::string_view::npos) { + if (last_non_space_offset != std::string_view::npos) { token->before.spaces_required = leading_spaces.size() - 1 - last_non_space_offset; } else { @@ -769,7 +768,7 @@ class LayoutFunctionFactoryTest : public ::testing::Test, }; const std::string sample_; - const std::vector tokens_; + const std::vector tokens_; std::vector ftokens_; NamedUnwrappedLines lines_; @@ -1982,7 +1981,7 @@ class TreeReconstructorTest : public ::testing::Test, protected: const std::string sample_; - const std::vector tokens_; + const std::vector tokens_; std::vector ftokens_; }; @@ -2340,7 +2339,7 @@ class OptimizeTokenPartitionTreeTest : public ::testing::Test, protected: const std::string sample_; - const std::vector tokens_; + const std::vector tokens_; std::vector ftokens_; }; @@ -2412,7 +2411,7 @@ class TokenPartitionsLayoutOptimizerTest : public ::testing::Test, if (absl::StrContains(leading_spaces, '\n')) { token.before.break_decision = SpacingOptions::kMustWrap; auto last_non_space_offset = leading_spaces.find_last_not_of(' '); - if (last_non_space_offset != absl::string_view::npos) { + if (last_non_space_offset != std::string_view::npos) { token.before.spaces_required = leading_spaces.size() - 1 - last_non_space_offset; } @@ -2426,8 +2425,8 @@ class TokenPartitionsLayoutOptimizerTest : public ::testing::Test, protected: const std::string sample_backing_; - const absl::string_view sample_; - const std::vector tokens_; + const std::string_view sample_; + const std::vector tokens_; std::vector ftokens_; const BasicFormatStyle style_; const LayoutFunctionFactory factory_; diff --git a/verible/common/formatting/state-node.cc b/verible/common/formatting/state-node.cc index 7bba9322c..30ab38644 100644 --- a/verible/common/formatting/state-node.cc +++ b/verible/common/formatting/state-node.cc @@ -18,9 +18,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/basic-format-style.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/unwrapped-line.h" @@ -32,7 +32,7 @@ namespace verible { -static constexpr absl::string_view kNotForAlignment = +static constexpr std::string_view kNotForAlignment = "Aligned tokens should never use line-wrap optimization!"; static SpacingDecision FrontTokenSpacing(const FormatTokenRange range) { @@ -145,7 +145,7 @@ int StateNode::UpdateColumnPosition() { // overflow the previous line (and should be penalized accordingly). const auto text = current_format_token.Text(); const auto last_newline_pos = text.find_last_of('\n'); - if (last_newline_pos != absl::string_view::npos) { + if (last_newline_pos != std::string_view::npos) { // There was a newline, it doesn't matter what the wrapping decision was. // The position is the length of the text after the last newline. current_column = text.length() - last_newline_pos - 1; @@ -193,7 +193,7 @@ int StateNode::UpdateColumnPosition() { } break; case SpacingDecision::kPreserve: { - const absl::string_view original_spacing_text = + const std::string_view original_spacing_text = current_format_token.OriginalLeadingSpaces(); // prev_state is null when the first token of the unwrapped line was // marked as SpacingOptions::Preserve, which indicates that formatting diff --git a/verible/common/formatting/state-node_test.cc b/verible/common/formatting/state-node_test.cc index 4b5e22f50..b9ed17a9c 100644 --- a/verible/common/formatting/state-node_test.cc +++ b/verible/common/formatting/state-node_test.cc @@ -19,9 +19,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/formatting/basic-format-style.h" #include "verible/common/formatting/format-token.h" @@ -183,7 +183,7 @@ TEST_F(StateNodeTestFixture, ConstructionAppendingPrevState) { // Tests that preserving spaces results in correct column position. TEST_F(StateNodeTestFixture, ConstructionPreserveSpacesFromPrevStateNoGap) { - const absl::string_view text("aaabbb"); // no gap between "aaa" and "bbb" + const std::string_view text("aaabbb"); // no gap between "aaa" and "bbb" const int kInitialIndent = 1; const std::vector tokens = {{0, text.substr(0, 3)}, {1, text.substr(3, 3)}}; @@ -215,7 +215,7 @@ TEST_F(StateNodeTestFixture, ConstructionPreserveSpacesFromPrevStateNoGap) { // Tests that preserving spaces results in correct column position. TEST_F(StateNodeTestFixture, ConstructionPreserveSpacesFromPrevStateSpaces) { - const absl::string_view text( + const std::string_view text( "aaa bbb"); // 4 spaces between "aaa" and "bbb" const int kInitialIndent = 1; const std::vector tokens = {{1, text.substr(0, 3)}, @@ -250,7 +250,7 @@ TEST_F(StateNodeTestFixture, ConstructionPreserveSpacesFromPrevStateSpaces) { // Tests that preserving spaces results in correct column position. TEST_F(StateNodeTestFixture, ConstructionPreserveSpacesFromPrevStateNewline) { - const absl::string_view text("aaa \n bbb"); // newline in between + const std::string_view text("aaa \n bbb"); // newline in between const int kInitialIndent = 1; const std::vector tokens = {{1, text.substr(0, 3)}, {2, text.substr(7, 3)}}; diff --git a/verible/common/formatting/token-partition-tree.cc b/verible/common/formatting/token-partition-tree.cc index 08667e2ce..f44b78f90 100644 --- a/verible/common/formatting/token-partition-tree.cc +++ b/verible/common/formatting/token-partition-tree.cc @@ -19,10 +19,10 @@ #include #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/basic-format-style.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/line-wrap-searcher.h" @@ -203,7 +203,7 @@ class BlankLineSeparatorDetector { private: // Keeps track of the end of the previous partition, which is the start // of each inter-partition gap (string_view). - absl::string_view::const_iterator previous_end_; + std::string_view::const_iterator previous_end_; }; // Subdivides the 'bounds' range into sub-ranges broken up by blank lines. @@ -245,7 +245,7 @@ std::vector GetSubpartitionsBetweenBlankLines( return result; } -static absl::string_view StringSpanOfPartitionRange( +static std::string_view StringSpanOfPartitionRange( const TokenPartitionRange &range) { CHECK(!range.empty()); const auto front_range = range.front().Value().TokensRange(); @@ -257,10 +257,10 @@ static absl::string_view StringSpanOfPartitionRange( } bool AnyPartitionSubRangeIsDisabled(TokenPartitionRange range, - absl::string_view full_text, + std::string_view full_text, const ByteOffsetSet &disabled_byte_ranges) { if (range.empty()) return false; - const absl::string_view span = StringSpanOfPartitionRange(range); + const std::string_view span = StringSpanOfPartitionRange(range); VLOG(4) << "text spanned: " << AutoTruncate{span, 40}; const std::pair span_offsets = SubstringOffsets(span, full_text); ByteOffsetSet diff(disabled_byte_ranges); // copy @@ -283,19 +283,18 @@ void AdjustIndentationAbsolute(TokenPartitionTree *tree, int amount) { AdjustIndentationRelative(tree, indent_diff); } -absl::string_view StringSpanOfTokenRange(const FormatTokenRange &range) { +std::string_view StringSpanOfTokenRange(const FormatTokenRange &range) { if (range.empty()) return {}; return make_string_view_range(range.front().Text().begin(), range.back().Text().end()); } void IndentButPreserveOtherSpacing(TokenPartitionRange partition_range, - absl::string_view full_text, + std::string_view full_text, std::vector *ftokens) { for (const auto &partition : partition_range) { const auto token_range = partition.Value().TokensRange(); - const absl::string_view partition_text = - StringSpanOfTokenRange(token_range); + const std::string_view partition_text = StringSpanOfTokenRange(token_range); std::pair byte_range = SubstringOffsets(partition_text, full_text); // Tweak byte range to allow the first token to still obey indentation. diff --git a/verible/common/formatting/token-partition-tree.h b/verible/common/formatting/token-partition-tree.h index 92c7b292b..1738b454d 100644 --- a/verible/common/formatting/token-partition-tree.h +++ b/verible/common/formatting/token-partition-tree.h @@ -17,10 +17,10 @@ #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/basic-format-style.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/unwrapped-line.h" @@ -100,7 +100,7 @@ std::ostream &operator<<(std::ostream &stream, // 'full_text' is the original string_view that spans the text from which // tokens were lexed, and is used in byte-offset calculation. bool AnyPartitionSubRangeIsDisabled(TokenPartitionRange range, - absl::string_view full_text, + std::string_view full_text, const ByteOffsetSet &disabled_byte_ranges); // Return ranges of subpartitions separated by blank lines. @@ -121,13 +121,13 @@ void AdjustIndentationRelative(TokenPartitionTree *tree, int amount); void AdjustIndentationAbsolute(TokenPartitionTree *tree, int amount); // Returns the range of text spanned by tokens range. -absl::string_view StringSpanOfTokenRange(const FormatTokenRange &range); +std::string_view StringSpanOfTokenRange(const FormatTokenRange &range); // Mark ranges of tokens (corresponding to formatting-disabled lines) to // have their original spacing preserved, except allow the first token // to follow the formatter's calculated indentation. void IndentButPreserveOtherSpacing(TokenPartitionRange partition_range, - absl::string_view full_text, + std::string_view full_text, std::vector *ftokens); // Finalizes formatting of a partition with kAlreadyFormatted policy and diff --git a/verible/common/formatting/token-partition-tree_test.cc b/verible/common/formatting/token-partition-tree_test.cc index 4255a8125..19b6a168d 100644 --- a/verible/common/formatting/token-partition-tree_test.cc +++ b/verible/common/formatting/token-partition-tree_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/formatting/basic-format-style.h" @@ -55,7 +55,7 @@ class TokenPartitionTreeTestFixture : public ::testing::Test, protected: const std::string sample_; - const std::vector tokens_; + const std::vector tokens_; std::vector ftokens_; }; @@ -1235,7 +1235,7 @@ class GetSubpartitionsBetweenBlankLinesTest : public ::testing::Test, public UnwrappedLineMemoryHandler { public: - explicit GetSubpartitionsBetweenBlankLinesTest(absl::string_view text) + explicit GetSubpartitionsBetweenBlankLinesTest(std::string_view text) : sample_(text), tokens_( absl::StrSplit(sample_, absl::ByAnyChar(" \n"), absl::SkipEmpty())), @@ -1274,7 +1274,7 @@ class GetSubpartitionsBetweenBlankLinesTest protected: const std::string sample_; - const std::vector tokens_; + const std::vector tokens_; std::vector ftokens_; TokenPartitionTree partition_; }; @@ -2712,7 +2712,7 @@ class ReshapeFittingSubpartitionsTestFixture protected: const std::string sample_; - const std::vector tokens_; + const std::vector tokens_; std::vector ftokens_; }; diff --git a/verible/common/formatting/tree-annotator_test.cc b/verible/common/formatting/tree-annotator_test.cc index 3d0b6af4c..75befaca1 100644 --- a/verible/common/formatting/tree-annotator_test.cc +++ b/verible/common/formatting/tree-annotator_test.cc @@ -14,9 +14,9 @@ #include "verible/common/formatting/tree-annotator.h" +#include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/formatting/format-token.h" @@ -67,7 +67,7 @@ iterator_range ExcludeFirst(const T &t) { } TEST(AnnotateFormatTokensUsingSyntaxContextTest, UnusedContext) { - const absl::string_view text("abc"); + const std::string_view text("abc"); const TokenInfo tokens[] = { {4, text.substr(0, 1)}, {5, text.substr(1, 1)}, @@ -96,7 +96,7 @@ void LeftIsB(const PreFormatToken &left, PreFormatToken *right, } TEST(AnnotateFormatTokensUsingSyntaxContextTest, UnusedContextBasedOnLeft) { - const absl::string_view text("abc"); + const std::string_view text("abc"); const TokenInfo tokens[] = { {4, text.substr(0, 1)}, {5, text.substr(1, 1)}, @@ -125,7 +125,7 @@ void RightContextDirectParentIsNine(const PreFormatToken &, } TEST(AnnotateFormatTokensUsingSyntaxContextTest, UsingRightContext) { - const absl::string_view text("abc"); + const std::string_view text("abc"); const TokenInfo tokens[] = { {4, text.substr(0, 1)}, {5, text.substr(1, 1)}, @@ -160,7 +160,7 @@ void LeftContextDirectParentIsSeven(const PreFormatToken &, } TEST(AnnotateFormatTokensUsingSyntaxContextTest, UsingLeftContext) { - const absl::string_view text("abc"); + const std::string_view text("abc"); const TokenInfo tokens[] = { {4, text.substr(0, 1)}, {5, text.substr(1, 1)}, @@ -184,7 +184,7 @@ TEST(AnnotateFormatTokensUsingSyntaxContextTest, UsingLeftContext) { } TEST(AnnotateFormatTokensUsingSyntaxContextTest, VerifySlidingContexts) { - const absl::string_view text("abcdefgh"); + const std::string_view text("abcdefgh"); const TokenInfo tokens[] = { {4, text.substr(0, 1)}, {5, text.substr(1, 1)}, {6, text.substr(2, 1)}, {4, text.substr(3, 1)}, diff --git a/verible/common/formatting/tree-unwrapper.h b/verible/common/formatting/tree-unwrapper.h index 9492e3b5d..76e89855a 100644 --- a/verible/common/formatting/tree-unwrapper.h +++ b/verible/common/formatting/tree-unwrapper.h @@ -17,9 +17,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/token-partition-tree.h" #include "verible/common/formatting/unwrapped-line.h" @@ -82,7 +82,7 @@ class TreeUnwrapper : public TreeContextVisitor { } // Returns text spanned by the syntax tree being traversed. - absl::string_view FullText() const { return text_structure_view_.Contents(); } + std::string_view FullText() const { return text_structure_view_.Contents(); } // Transformation diff --git a/verible/common/formatting/tree-unwrapper_test.cc b/verible/common/formatting/tree-unwrapper_test.cc index 676912f91..4166122f8 100644 --- a/verible/common/formatting/tree-unwrapper_test.cc +++ b/verible/common/formatting/tree-unwrapper_test.cc @@ -18,10 +18,10 @@ #include #include #include +#include #include #include "absl/strings/ascii.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/unwrapped-line.h" @@ -37,7 +37,7 @@ namespace verible { static bool KeepNonWhitespace(const TokenInfo &token) { - const absl::string_view text(absl::StripAsciiWhitespace(token.text())); + const std::string_view text(absl::StripAsciiWhitespace(token.text())); return !text.empty(); } diff --git a/verible/common/formatting/unwrapped-line-test-utils.h b/verible/common/formatting/unwrapped-line-test-utils.h index acbba3f2c..6c4bfbbac 100644 --- a/verible/common/formatting/unwrapped-line-test-utils.h +++ b/verible/common/formatting/unwrapped-line-test-utils.h @@ -16,9 +16,9 @@ #define VERIBLE_COMMON_FORMATTING_UNWRAPPED_LINE_TEST_UTILS_H_ #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/unwrapped-line.h" #include "verible/common/text/constants.h" @@ -58,7 +58,7 @@ class UnwrappedLineMemoryHandler { TokenInfo EOFToken() const { return TokenInfo( verible::TK_EOF, - absl::string_view( // NOLINT might be easier with c++20 + std::string_view( // NOLINT might be easier with c++20 joined_token_text_.data() + joined_token_text_.length(), 0)); } diff --git a/verible/common/formatting/unwrapped-line_test.cc b/verible/common/formatting/unwrapped-line_test.cc index cd88ab659..9f3eb3acf 100644 --- a/verible/common/formatting/unwrapped-line_test.cc +++ b/verible/common/formatting/unwrapped-line_test.cc @@ -16,9 +16,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/unwrapped-line-test-utils.h" @@ -355,7 +355,7 @@ TEST_F(UnwrappedLineTest, FormattedTextPreserveSpacesNoTokens) { } TEST_F(UnwrappedLineTest, StreamFormatting) { - const absl::string_view text(" aaa bbb cc"); + const std::string_view text(" aaa bbb cc"); const std::vector tokens = {// "aaa", "bbb", "cc" {0, text.substr(2, 3)}, {1, text.substr(7, 3)}, @@ -381,7 +381,7 @@ TEST_F(UnwrappedLineTest, StreamFormatting) { } TEST_F(UnwrappedLineTest, FormattedTextPreserveSpacesWithTokens) { - const absl::string_view text(" aaa bbb cc"); + const std::string_view text(" aaa bbb cc"); const std::vector tokens = {// "aaa", "bbb", "cc" {0, text.substr(2, 3)}, {1, text.substr(7, 3)}, @@ -409,7 +409,7 @@ TEST_F(UnwrappedLineTest, FormattedTextPreserveSpacesWithTokens) { } TEST_F(UnwrappedLineTest, FormattedTextPreserveNewlines) { - const absl::string_view text("\n\naaa\n\nbbb\n\n\ncc"); + const std::string_view text("\n\naaa\n\nbbb\n\n\ncc"); const std::vector tokens = { {0, text.substr(2, 3)}, {1, text.substr(7, 3)}, {2, text.substr(13, 2)}}; CreateTokenInfosExternalStringBuffer(tokens); // use 'text' buffer @@ -432,7 +432,7 @@ TEST_F(UnwrappedLineTest, FormattedTextPreserveNewlines) { } TEST_F(UnwrappedLineTest, FormattedTextPreserveNewlinesDropSpaces) { - const absl::string_view text(" \n aaa bbb cc"); + const std::string_view text(" \n aaa bbb cc"); const std::vector tokens = { {0, text.substr(7, 3)}, {1, text.substr(12, 3)}, {2, text.substr(18, 2)}}; CreateTokenInfosExternalStringBuffer(tokens); // use 'text' buffer @@ -516,7 +516,7 @@ TEST_F(UnwrappedLineTest, AsCodeTextIndent) { } TEST_F(UnwrappedLineTest, AsCodeCustomOriginPrinter) { - const absl::string_view text(" aaa bbb cc"); + const std::string_view text(" aaa bbb cc"); const std::vector tokens = {// "aaa", "bbb", "cc" {0, text.substr(2, 3)}, {1, text.substr(7, 3)}, diff --git a/verible/common/formatting/verification.cc b/verible/common/formatting/verification.cc index 5ff9a5ad5..3973184d8 100644 --- a/verible/common/formatting/verification.cc +++ b/verible/common/formatting/verification.cc @@ -15,19 +15,19 @@ #include "verible/common/formatting/verification.h" #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/diff.h" #include "verible/common/strings/position.h" namespace verible { -absl::Status ReformatMustMatch(absl::string_view original_text, +absl::Status ReformatMustMatch(std::string_view original_text, const LineNumberSet &lines, - absl::string_view formatted_text, - absl::string_view reformatted_text) { + std::string_view formatted_text, + std::string_view reformatted_text) { if (reformatted_text != formatted_text) { const verible::LineDiffs formatting_diffs(formatted_text, reformatted_text); std::ostringstream diff_stream; diff --git a/verible/common/formatting/verification.h b/verible/common/formatting/verification.h index 0fc15281c..061c506cf 100644 --- a/verible/common/formatting/verification.h +++ b/verible/common/formatting/verification.h @@ -15,8 +15,9 @@ #ifndef VERIBLE_COMMON_FORMATTING_VERIFICATION_H_ #define VERIBLE_COMMON_FORMATTING_VERIFICATION_H_ +#include + #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/position.h" namespace verible { @@ -26,10 +27,10 @@ namespace verible { // The following parameters are only used for diagnostics: // 'original_text' is the text before any formatting was done. // 'lines' is the set of lines requested if incrementally formatting. -absl::Status ReformatMustMatch(absl::string_view original_text, +absl::Status ReformatMustMatch(std::string_view original_text, const LineNumberSet &lines, - absl::string_view formatted_text, - absl::string_view reformatted_text); + std::string_view formatted_text, + std::string_view reformatted_text); } // namespace verible diff --git a/verible/common/lexer/BUILD b/verible/common/lexer/BUILD index 08d628a55..a03a5b3d6 100644 --- a/verible/common/lexer/BUILD +++ b/verible/common/lexer/BUILD @@ -29,7 +29,6 @@ cc_library( "//verible/common/text:token-info", "//verible/common/text:token-stream-view", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -41,17 +40,13 @@ cc_library( "//verible/common/text:token-info", "//verible/common/util:logging", "@abseil-cpp//absl/log:check", - "@abseil-cpp//absl/strings:string_view", ], ) cc_library( name = "lexer", hdrs = ["lexer.h"], - deps = [ - "//verible/common/text:token-info", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["//verible/common/text:token-info"], ) cc_library( @@ -64,7 +59,6 @@ cc_library( "//verible/common/text:token-info", "//verible/common/text:token-info-test-util", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", # for library testonly ], ) @@ -77,7 +71,6 @@ cc_test( "//verible/common/text:constants", "//verible/common/text:token-info", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -94,7 +87,6 @@ cc_test( "//verible/common/text:token-info", "//verible/common/text:token-stream-view", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/common/lexer/flex-lexer-adapter.h b/verible/common/lexer/flex-lexer-adapter.h index e847b98a2..b4c4c0d7c 100644 --- a/verible/common/lexer/flex-lexer-adapter.h +++ b/verible/common/lexer/flex-lexer-adapter.h @@ -35,9 +35,9 @@ #include #include // IWYU pragma: keep // for ostringstream #include +#include #include "absl/log/check.h" -#include "absl/strings/string_view.h" #include "verible/common/lexer/lexer.h" #include "verible/common/text/token-info.h" #include "verible/common/util/logging.h" @@ -64,7 +64,7 @@ class CodeStreamHolder { template class FlexLexerAdapter : private CodeStreamHolder, protected L, public Lexer { public: - explicit FlexLexerAdapter(absl::string_view code) + explicit FlexLexerAdapter(std::string_view code) : L(&code_stream_), code_(code), // last_token_ points to the beginning of the code_ buffer @@ -108,7 +108,7 @@ class FlexLexerAdapter : private CodeStreamHolder, protected L, public Lexer { } // Restart lexer by pointing to new input stream, and reset all state. - void Restart(absl::string_view code) override { // not yet final + void Restart(std::string_view code) override { // not yet final at_eof_ = false; code_ = code; code_stream_.str(std::string(code_)); @@ -150,7 +150,7 @@ class FlexLexerAdapter : private CodeStreamHolder, protected L, public Lexer { private: // A read-only view of the entire text to be scanned. - absl::string_view code_; + std::string_view code_; // Contains the enumeration and the substring slice of the last lexed token. TokenInfo last_token_; diff --git a/verible/common/lexer/lexer-test-util.cc b/verible/common/lexer/lexer-test-util.cc index b8f0f228a..dd9c2877b 100644 --- a/verible/common/lexer/lexer-test-util.cc +++ b/verible/common/lexer/lexer-test-util.cc @@ -15,9 +15,9 @@ #include "verible/common/lexer/lexer-test-util.h" #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" #include "verible/common/util/logging.h" diff --git a/verible/common/lexer/lexer-test-util.h b/verible/common/lexer/lexer-test-util.h index f3aa4926b..c1aac7511 100644 --- a/verible/common/lexer/lexer-test-util.h +++ b/verible/common/lexer/lexer-test-util.h @@ -25,9 +25,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/constants.h" #include "verible/common/text/token-info-test-util.h" @@ -54,7 +54,7 @@ class FakeLexer { // Usage: stream << ShowCode{text}; // Consider this private, only intended for use in this library. struct ShowCode { - absl::string_view text; + std::string_view text; }; std::ostream &operator<<(std::ostream &, const ShowCode &); @@ -140,8 +140,7 @@ struct SynthesizedLexerTestData : public TokenInfoTestData { // A single expected_text can span multiple tokens, when we're only checking // string contents, and not checking *how* this excerpt is tokenized. template - void DontCareMultiTokens(Lexer *lexer, - absl::string_view expected_text) const { + void DontCareMultiTokens(Lexer *lexer, std::string_view expected_text) const { // Consume tokens and compare string fragments against the // expected_text until the text is fully matched. while (!expected_text.empty()) { diff --git a/verible/common/lexer/lexer-test-util_test.cc b/verible/common/lexer/lexer-test-util_test.cc index 6f393a9b3..ba0a16f82 100644 --- a/verible/common/lexer/lexer-test-util_test.cc +++ b/verible/common/lexer/lexer-test-util_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/constants.h" #include "verible/common/text/token-info.h" @@ -37,7 +37,7 @@ TEST(ShowCodeStreamableTest, ContainsCode) { // For use with TestDriverTokenInfos only class TestDriverTokenInfosFakeLexer : public FakeLexer { public: - explicit TestDriverTokenInfosFakeLexer(absl::string_view code) + explicit TestDriverTokenInfosFakeLexer(std::string_view code) : joined_text_(code) { static const std::initializer_list driver_data = { // TokenInfo: enum, text @@ -49,7 +49,7 @@ class TestDriverTokenInfosFakeLexer : public FakeLexer { } private: - absl::string_view joined_text_; + std::string_view joined_text_; }; TEST(SynthesizedLexerTestDataTest, TestDriverTokenInfos) { @@ -65,7 +65,7 @@ TEST(SynthesizedLexerTestDataTest, TestDriverTokenInfos) { // For use with TestDriverDontCares only class TestDriverDontCaresFakeLexer : public FakeLexer { public: - explicit TestDriverDontCaresFakeLexer(absl::string_view code) + explicit TestDriverDontCaresFakeLexer(std::string_view code) : joined_text_(code) { static const std::initializer_list driver_data = { // TokenInfo: enum, left, text @@ -81,7 +81,7 @@ class TestDriverDontCaresFakeLexer : public FakeLexer { } private: - absl::string_view joined_text_; + std::string_view joined_text_; }; TEST(SynthesizedLexerTestDataTest, TestDriverDontCares) { diff --git a/verible/common/lexer/lexer.h b/verible/common/lexer/lexer.h index 7b85f227b..00322959d 100644 --- a/verible/common/lexer/lexer.h +++ b/verible/common/lexer/lexer.h @@ -17,7 +17,8 @@ #ifndef VERIBLE_COMMON_LEXER_LEXER_H_ #define VERIBLE_COMMON_LEXER_LEXER_H_ -#include "absl/strings/string_view.h" +#include + #include "verible/common/text/token-info.h" namespace verible { @@ -36,7 +37,7 @@ class Lexer { virtual const TokenInfo &DoNextToken() = 0; // Reset lexer to new input. Overrides should discard all previous state. - virtual void Restart(absl::string_view) = 0; + virtual void Restart(std::string_view) = 0; // Return true if token is a lexical error. virtual bool TokenIsError(const TokenInfo &) const = 0; diff --git a/verible/common/lexer/token-stream-adapter.cc b/verible/common/lexer/token-stream-adapter.cc index d739182a3..50ae25765 100644 --- a/verible/common/lexer/token-stream-adapter.cc +++ b/verible/common/lexer/token-stream-adapter.cc @@ -15,9 +15,9 @@ #include "verible/common/lexer/token-stream-adapter.h" #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/lexer/lexer.h" #include "verible/common/lexer/token-generator.h" #include "verible/common/text/token-info.h" @@ -30,7 +30,7 @@ TokenGenerator MakeTokenGenerator(Lexer *l) { } absl::Status MakeTokenSequence( - Lexer *lexer, absl::string_view text, TokenSequence *tokens, + Lexer *lexer, std::string_view text, TokenSequence *tokens, const std::function &error_token_handler) { // TODO(fangism): provide a Lexer interface to grab all tokens en masse, // which would save virtual function dispatch overhead. diff --git a/verible/common/lexer/token-stream-adapter.h b/verible/common/lexer/token-stream-adapter.h index 23e0f52a8..0598de32e 100644 --- a/verible/common/lexer/token-stream-adapter.h +++ b/verible/common/lexer/token-stream-adapter.h @@ -19,10 +19,10 @@ #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/lexer/lexer.h" #include "verible/common/lexer/token-generator.h" #include "verible/common/text/token-info.h" @@ -35,7 +35,7 @@ TokenGenerator MakeTokenGenerator(Lexer *l); // Populates a TokenSequence with lexed tokens. absl::Status MakeTokenSequence( - Lexer *lexer, absl::string_view text, TokenSequence *tokens, + Lexer *lexer, std::string_view text, TokenSequence *tokens, const std::function &error_token_handler); // Generic container-to-iterator-generator adapter. diff --git a/verible/common/lexer/token-stream-adapter_test.cc b/verible/common/lexer/token-stream-adapter_test.cc index e63c5f77a..a5ff96857 100644 --- a/verible/common/lexer/token-stream-adapter_test.cc +++ b/verible/common/lexer/token-stream-adapter_test.cc @@ -15,9 +15,9 @@ #include "verible/common/lexer/token-stream-adapter.h" #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/lexer/lexer-test-util.h" #include "verible/common/lexer/lexer.h" @@ -36,7 +36,7 @@ class FakeTokenSequenceLexer : public Lexer, public FakeLexer { const TokenInfo &DoNextToken() final { return FakeLexer::DoNextToken(); } - void Restart(absl::string_view) final {} + void Restart(std::string_view) final {} bool TokenIsError(const TokenInfo &) const override { // not yet final. return false; @@ -44,8 +44,8 @@ class FakeTokenSequenceLexer : public Lexer, public FakeLexer { }; TEST(MakeTokenGeneratorTest, Generate) { - static constexpr absl::string_view abc("abc"); - static constexpr absl::string_view xyz("xyz"); + static constexpr std::string_view abc("abc"); + static constexpr std::string_view xyz("xyz"); FakeTokenSequenceLexer lexer; std::initializer_list tokens = { {1, abc}, @@ -62,7 +62,7 @@ TEST(MakeTokenGeneratorTest, Generate) { TEST(MakeTokenSequenceTest, Sequencer) { FakeTokenSequenceLexer lexer; - constexpr absl::string_view text("abcxyz"); + constexpr std::string_view text("abcxyz"); std::initializer_list tokens = { {1, text.substr(0, 3)}, {2, text.substr(3, 3)}, @@ -84,7 +84,7 @@ class TheNumberTwoIsErrorLexer : public FakeTokenSequenceLexer { TEST(MakeTokenSequenceTest, SequencerWithError) { TheNumberTwoIsErrorLexer lexer; - constexpr absl::string_view text("abcxyz"); + constexpr std::string_view text("abcxyz"); std::initializer_list tokens = { {1, text.substr(0, 3)}, {2, text.substr(3, 3)}, // error token diff --git a/verible/common/lsp/BUILD b/verible/common/lsp/BUILD index aa814eed8..0a87bf00f 100644 --- a/verible/common/lsp/BUILD +++ b/verible/common/lsp/BUILD @@ -28,7 +28,6 @@ cc_library( "//verible/common/util:status-macros", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -39,7 +38,6 @@ cc_test( ":message-stream-splitter", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -57,7 +55,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", "@nlohmann_json//:singleheader-json", ], ) @@ -72,7 +69,6 @@ cc_test( features = ["-use_header_modules"], # precompiled headers incompatible with -fexceptions. deps = [ ":json-rpc-dispatcher", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", "@nlohmann_json//:singleheader-json", @@ -129,7 +125,6 @@ cc_library( "//verible/common/strings:utf8", "@abseil-cpp//absl/container:flat_hash_map", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -141,7 +136,6 @@ cc_test( ":lsp-protocol", ":lsp-text-buffer", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -152,10 +146,7 @@ cc_library( srcs = ["lsp-file-utils.cc"], hdrs = ["lsp-file-utils.h"], visibility = ["//visibility:public"], - deps = [ - "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["@abseil-cpp//absl/strings"], ) cc_test( @@ -176,7 +167,6 @@ cc_binary( ":message-stream-splitter", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@nlohmann_json//:singleheader-json", ], ) @@ -190,7 +180,6 @@ cc_binary( ":lsp-text-buffer", ":message-stream-splitter", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@nlohmann_json//:singleheader-json", ], ) diff --git a/verible/common/lsp/dummy-ls.cc b/verible/common/lsp/dummy-ls.cc index 9daef9a93..95d8c76a4 100644 --- a/verible/common/lsp/dummy-ls.cc +++ b/verible/common/lsp/dummy-ls.cc @@ -17,9 +17,9 @@ // This is merely to test that the json-rpc plumbing is working. #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" #include "verible/common/lsp/json-rpc-dispatcher.h" #include "verible/common/lsp/lsp-protocol.h" @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) { // Input and output is stdin and stdout constexpr int kInputFD = 0; // STDIN_FILENO, but Win does not have that macro - JsonRpcDispatcher::WriteFun write_fun = [](absl::string_view reply) { + JsonRpcDispatcher::WriteFun write_fun = [](std::string_view reply) { // Output formatting as header/body chunk as required by LSP spec. std::cout << "Content-Length: " << reply.size() << "\r\n\r\n"; std::cout << reply << std::flush; @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) { // All bodies the stream splitter extracts are pushed to the json dispatcher MessageStreamSplitter stream_splitter; stream_splitter.SetMessageProcessor( - [&dispatcher](absl::string_view /*header*/, absl::string_view body) { + [&dispatcher](std::string_view /*header*/, std::string_view body) { dispatcher.DispatchMessage(body); }); diff --git a/verible/common/lsp/json-rpc-dispatcher.cc b/verible/common/lsp/json-rpc-dispatcher.cc index 957c1ec15..d1a9e66df 100644 --- a/verible/common/lsp/json-rpc-dispatcher.cc +++ b/verible/common/lsp/json-rpc-dispatcher.cc @@ -17,14 +17,14 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" #include "verible/common/util/logging.h" namespace verible { namespace lsp { -void JsonRpcDispatcher::DispatchMessage(absl::string_view data) { +void JsonRpcDispatcher::DispatchMessage(std::string_view data) { nlohmann::json request; try { request = nlohmann::json::parse(data); @@ -115,7 +115,7 @@ void JsonRpcDispatcher::SendNotification(const std::string &method, } /*static*/ nlohmann::json JsonRpcDispatcher::CreateError( - const nlohmann::json &request, int code, absl::string_view message) { + const nlohmann::json &request, int code, std::string_view message) { nlohmann::json result = { {"jsonrpc", "2.0"}, }; diff --git a/verible/common/lsp/json-rpc-dispatcher.h b/verible/common/lsp/json-rpc-dispatcher.h index 37cb0af81..c9c464569 100644 --- a/verible/common/lsp/json-rpc-dispatcher.h +++ b/verible/common/lsp/json-rpc-dispatcher.h @@ -18,10 +18,10 @@ #include #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" namespace verible { @@ -69,7 +69,7 @@ class JsonRpcDispatcher { // A function of type WriteFun is called by the dispatcher to send the // string-formatted json response. The user of the JsonRpcDispatcher then // can wire that to the underlying transport. - using WriteFun = std::function; + using WriteFun = std::function; // Some statistical counters of method calls or exceptions encountered. using StatsMap = std::map; @@ -95,7 +95,7 @@ class JsonRpcDispatcher { // Dispatch incoming message, a string view with json data. // Call this with the content of exactly one message. // If this is an RPC call, response will call WriteFun. - void DispatchMessage(absl::string_view data); + void DispatchMessage(std::string_view data); // Send a notification to the client side. Parameters will be wrapped // in a JSON-RPC message and pushed out to the WriteFun @@ -118,7 +118,7 @@ class JsonRpcDispatcher { void SendReply(const nlohmann::json &response); static nlohmann::json CreateError(const nlohmann::json &request, int code, - absl::string_view message); + std::string_view message); static nlohmann::json MakeResponse(const nlohmann::json &request, const nlohmann::json &call_result); diff --git a/verible/common/lsp/json-rpc-dispatcher_test.cc b/verible/common/lsp/json-rpc-dispatcher_test.cc index 25bdd3579..01d2ee719 100644 --- a/verible/common/lsp/json-rpc-dispatcher_test.cc +++ b/verible/common/lsp/json-rpc-dispatcher_test.cc @@ -17,8 +17,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "nlohmann/json.hpp" @@ -30,7 +30,7 @@ TEST(JsonRpcDispatcherTest, Call_GarbledInputRequest) { int write_fun_called = 0; // If the input can't even be parsed, it is reported back to the client - JsonRpcDispatcher dispatcher([&](absl::string_view s) { + JsonRpcDispatcher dispatcher([&](std::string_view s) { const json j = json::parse(s); EXPECT_TRUE(j.find("error") != j.end()); EXPECT_EQ(j["error"]["code"], JsonRpcDispatcher::kParseError) << s; @@ -48,7 +48,7 @@ TEST(JsonRpcDispatcherTest, Call_MissingMethodInRequest) { int write_fun_called = 0; int notification_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { + JsonRpcDispatcher dispatcher([&](std::string_view s) { const json j = json::parse(s); EXPECT_TRUE(j.find("error") != j.end()); EXPECT_EQ(j["error"]["code"], JsonRpcDispatcher::kMethodNotFound) << s; @@ -69,7 +69,7 @@ TEST(JsonRpcDispatcherTest, CallNotification) { int write_fun_called = 0; int notification_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { + JsonRpcDispatcher dispatcher([&](std::string_view s) { std::cerr << s; ++write_fun_called; }); @@ -94,7 +94,7 @@ TEST(JsonRpcDispatcherTest, CallNotification) { TEST(JsonRpcDispatcherTest, CallNotification_WithoutParamsShouldBeBenign) { int notification_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { std::cerr << s; }); + JsonRpcDispatcher dispatcher([&](std::string_view s) { std::cerr << s; }); const bool registered = dispatcher.AddNotificationHandler("foo", [&](const json &j) { EXPECT_TRUE(j.empty()); @@ -113,8 +113,7 @@ TEST(JsonRpcDispatcherTest, CallNotification_NotReportInternalError) { int write_fun_called = 0; int notification_fun_called = 0; - JsonRpcDispatcher dispatcher( - [&](absl::string_view s) { ++write_fun_called; }); + JsonRpcDispatcher dispatcher([&](std::string_view s) { ++write_fun_called; }); // This method does not complete but throws an exception. dispatcher.AddNotificationHandler("foo", [&](const json &j) -> json { @@ -135,7 +134,7 @@ TEST(JsonRpcDispatcherTest, CallNotification_MissingMethodImplemented) { // No response with error. int write_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { // + JsonRpcDispatcher dispatcher([&](std::string_view s) { // ++write_fun_called; }); @@ -150,7 +149,7 @@ TEST(JsonRpcDispatcherTest, CallRpcHandler) { int write_fun_called = 0; int rpc_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { + JsonRpcDispatcher dispatcher([&](std::string_view s) { const json j = json::parse(s); EXPECT_EQ(std::string(j["result"]["some"]), "response"); EXPECT_TRUE(j.find("error") == j.end()); @@ -180,7 +179,7 @@ TEST(JsonRpcDispatcherTest, CallRpcHandler_WithoutParamsShouldBeBenign) { int write_fun_called = 0; int rpc_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { + JsonRpcDispatcher dispatcher([&](std::string_view s) { const json j = json::parse(s); EXPECT_EQ(std::string(j["result"]["some"]), "response"); EXPECT_TRUE(j.find("error") == j.end()); @@ -206,7 +205,7 @@ TEST(JsonRpcDispatcherTest, CallRpcHandler_ReportInternalError) { int write_fun_called = 0; int rpc_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { + JsonRpcDispatcher dispatcher([&](std::string_view s) { const json j = json::parse(s); EXPECT_TRUE(j.find("error") != j.end()); EXPECT_EQ(j["error"]["code"], JsonRpcDispatcher::kInternalError) << s; @@ -230,7 +229,7 @@ TEST(JsonRpcDispatcherTest, CallRpcHandler_ReportInternalError) { TEST(JsonRpcDispatcherTest, CallRpcHandler_MissingMethodImplemented) { int write_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { + JsonRpcDispatcher dispatcher([&](std::string_view s) { const json j = json::parse(s); EXPECT_TRUE(j.find("error") != j.end()); EXPECT_EQ(j["error"]["code"], JsonRpcDispatcher::kMethodNotFound) << s; @@ -246,7 +245,7 @@ TEST(JsonRpcDispatcherTest, CallRpcHandler_MissingMethodImplemented) { TEST(JsonRpcDispatcherTest, SendNotificationToClient) { int write_fun_called = 0; - JsonRpcDispatcher dispatcher([&](absl::string_view s) { + JsonRpcDispatcher dispatcher([&](std::string_view s) { const json j = json::parse(s); EXPECT_EQ(j["method"], "greeting_method"); EXPECT_EQ(j["params"], "Hi, y'all"); diff --git a/verible/common/lsp/json-rpc-expect.cc b/verible/common/lsp/json-rpc-expect.cc index deb0f00eb..117858c10 100644 --- a/verible/common/lsp/json-rpc-expect.cc +++ b/verible/common/lsp/json-rpc-expect.cc @@ -20,10 +20,10 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" #include "verible/common/lsp/message-stream-splitter.h" @@ -147,8 +147,8 @@ int main(int argc, char *argv[]) { int first_error = -1; size_t expect_pos = 0; stream_splitter.SetMessageProcessor( - [&expect_data, &expect_pos, &first_error](absl::string_view, - absl::string_view body) { + [&expect_data, &expect_pos, &first_error](std::string_view, + std::string_view body) { std::cerr << "Got: " << body << std::endl; const json received = json::parse(body); const json &expected = expect_data[expect_pos]; diff --git a/verible/common/lsp/lsp-file-utils.cc b/verible/common/lsp/lsp-file-utils.cc index 4c1777397..72a373349 100644 --- a/verible/common/lsp/lsp-file-utils.cc +++ b/verible/common/lsp/lsp-file-utils.cc @@ -19,15 +19,15 @@ #include #include #include +#include #include "absl/strings/escaping.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" namespace verible::lsp { -static constexpr absl::string_view kFileSchemePrefix = "file://"; +static constexpr std::string_view kFileSchemePrefix = "file://"; namespace { @@ -46,10 +46,10 @@ bool NeedsEscape(char c) { } } -std::string DecodeURI(absl::string_view uri) { +std::string DecodeURI(std::string_view uri) { std::string result; result.reserve(uri.size() - 2 * std::count(uri.begin(), uri.end(), '%')); - absl::string_view::size_type pos = 0; + std::string_view::size_type pos = 0; while (pos < uri.size()) { if (uri[pos] == '%') { @@ -63,18 +63,18 @@ std::string DecodeURI(absl::string_view uri) { absl::StrAppend(&result, "%"); } } - absl::string_view::size_type nextpos = uri.find('%', pos); - if (nextpos > absl::string_view::npos) nextpos = uri.size(); + std::string_view::size_type nextpos = uri.find('%', pos); + if (nextpos > std::string_view::npos) nextpos = uri.size(); absl::StrAppend(&result, uri.substr(pos, nextpos - pos)); pos = nextpos; } return result; } -std::string EncodeURI(absl::string_view uri) { +std::string EncodeURI(std::string_view uri) { std::string result; - absl::string_view::size_type pos = 0; + std::string_view::size_type pos = 0; int prevpos = 0; while (pos < uri.size()) { @@ -91,7 +91,7 @@ std::string EncodeURI(absl::string_view uri) { } } // namespace -std::string LSPUriToPath(absl::string_view uri) { +std::string LSPUriToPath(std::string_view uri) { if (!absl::StartsWith(uri, kFileSchemePrefix)) return ""; std::string path = DecodeURI(uri.substr(kFileSchemePrefix.size())); // In Windows, paths in URIs are represented as @@ -108,7 +108,7 @@ std::string LSPUriToPath(absl::string_view uri) { return path; } -std::string PathToLSPUri(absl::string_view path) { +std::string PathToLSPUri(std::string_view path) { std::filesystem::path p(path.begin(), path.end()); std::string normalized_path; normalized_path = std::filesystem::absolute(p).string(); diff --git a/verible/common/lsp/lsp-file-utils.h b/verible/common/lsp/lsp-file-utils.h index 6d82682c3..8a9b311e2 100644 --- a/verible/common/lsp/lsp-file-utils.h +++ b/verible/common/lsp/lsp-file-utils.h @@ -17,18 +17,17 @@ #define VERIBLE_COMMON_LSP_LSP_FILE_UTILS_H #include - -#include "absl/strings/string_view.h" +#include namespace verible::lsp { // Converts file:// scheme entries to actual system paths. // If other scheme is provided, method returns empty string_view. // TODO (glatosinski) current resolving of LSP URIs is very naive // and supports only narrow use cases of file:// specifier. -std::string LSPUriToPath(absl::string_view uri); +std::string LSPUriToPath(std::string_view uri); // Converts filesystem paths to file:// scheme entries. -std::string PathToLSPUri(absl::string_view path); +std::string PathToLSPUri(std::string_view path); } // namespace verible::lsp #endif // VERIBLE_COMMON_LSP_LSP_FILE_UTILS_H diff --git a/verible/common/lsp/lsp-text-buffer.cc b/verible/common/lsp/lsp-text-buffer.cc index 8704969c7..9cf7b80d4 100644 --- a/verible/common/lsp/lsp-text-buffer.cc +++ b/verible/common/lsp/lsp-text-buffer.cc @@ -16,18 +16,18 @@ #include #include +#include #include #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/lsp/json-rpc-dispatcher.h" #include "verible/common/lsp/lsp-protocol.h" #include "verible/common/strings/utf8.h" namespace verible { namespace lsp { -EditTextBuffer::EditTextBuffer(absl::string_view initial_text) { +EditTextBuffer::EditTextBuffer(std::string_view initial_text) { ReplaceDocument(initial_text); } @@ -54,9 +54,9 @@ bool EditTextBuffer::ApplyChange(const TextDocumentContentChangeEvent &c) { } /*static*/ EditTextBuffer::LineVector EditTextBuffer::GenerateLines( - absl::string_view content) { + std::string_view content) { LineVector result; - for (const absl::string_view s : absl::StrSplit(content, '\n')) { + for (const std::string_view s : absl::StrSplit(content, '\n')) { result.emplace_back(new std::string(s)); result.back()->append("\n"); } @@ -71,7 +71,7 @@ bool EditTextBuffer::ApplyChange(const TextDocumentContentChangeEvent &c) { return result; } -void EditTextBuffer::ReplaceDocument(absl::string_view content) { +void EditTextBuffer::ReplaceDocument(std::string_view content) { document_length_ = content.length(); if (content.empty()) return; lines_ = GenerateLines(content); @@ -90,7 +90,7 @@ bool EditTextBuffer::LineEdit(const TextDocumentContentChangeEvent &c, if (end_char < c.range.start.character) return false; document_length_ -= str->length(); - const absl::string_view assembly = *str; + const std::string_view assembly = *str; const auto before = utf8_substr(assembly, 0, c.range.start.character); const auto after = utf8_substr(assembly, end_char); *str = absl::StrCat(before, c.text, after); @@ -100,10 +100,10 @@ bool EditTextBuffer::LineEdit(const TextDocumentContentChangeEvent &c, // Returns success (always succeeds); bool EditTextBuffer::MultiLineEdit(const TextDocumentContentChangeEvent &c) { - const absl::string_view start_line = *lines_[c.range.start.line]; + const std::string_view start_line = *lines_[c.range.start.line]; const auto before = utf8_substr(start_line, 0, c.range.start.character); - const absl::string_view end_line = *lines_[c.range.end.line]; + const std::string_view end_line = *lines_[c.range.end.line]; const auto after = utf8_substr(end_line, c.range.end.character); // Assemble the full content to replace the range of lines with including diff --git a/verible/common/lsp/lsp-text-buffer.h b/verible/common/lsp/lsp-text-buffer.h index f13199150..20eaeadbb 100644 --- a/verible/common/lsp/lsp-text-buffer.h +++ b/verible/common/lsp/lsp-text-buffer.h @@ -20,10 +20,10 @@ #include #include #include +#include #include #include "absl/container/flat_hash_map.h" -#include "absl/strings/string_view.h" #include "verible/common/lsp/json-rpc-dispatcher.h" #include "verible/common/lsp/lsp-protocol.h" @@ -36,9 +36,9 @@ namespace lsp { // process it. class EditTextBuffer { public: - using ContentProcessFun = std::function; + using ContentProcessFun = std::function; - explicit EditTextBuffer(absl::string_view initial_text); + explicit EditTextBuffer(std::string_view initial_text); EditTextBuffer(const EditTextBuffer &) = delete; EditTextBuffer(EditTextBuffer &&) = delete; @@ -73,8 +73,8 @@ class EditTextBuffer { // will not work. Needs to be formulated with something something std::move ? using LineVector = std::vector>; - static LineVector GenerateLines(absl::string_view content); - void ReplaceDocument(absl::string_view content); + static LineVector GenerateLines(std::string_view content); + void ReplaceDocument(std::string_view content); bool LineEdit(const TextDocumentContentChangeEvent &c, std::string *str); bool MultiLineEdit(const TextDocumentContentChangeEvent &c); diff --git a/verible/common/lsp/lsp-text-buffer_test.cc b/verible/common/lsp/lsp-text-buffer_test.cc index 4c2178394..79541fc15 100644 --- a/verible/common/lsp/lsp-text-buffer_test.cc +++ b/verible/common/lsp/lsp-text-buffer_test.cc @@ -16,9 +16,9 @@ #include #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/lsp/json-rpc-dispatcher.h" #include "verible/common/lsp/lsp-protocol.h" @@ -29,7 +29,7 @@ TEST(TextBufferTest, RecreateEmptyFile) { EditTextBuffer buffer(""); EXPECT_EQ(buffer.lines(), 0); EXPECT_EQ(buffer.document_length(), 0); - buffer.RequestContent([](absl::string_view s) { // + buffer.RequestContent([](std::string_view s) { // EXPECT_TRUE(s.empty()); }); } @@ -37,34 +37,34 @@ TEST(TextBufferTest, RecreateEmptyFile) { TEST(TextBufferTest, RequestParticularLine) { EditTextBuffer buffer("foo\nbar\nbaz\n"); ASSERT_EQ(buffer.lines(), 3); - buffer.RequestLine(0, [](absl::string_view s) { // + buffer.RequestLine(0, [](std::string_view s) { // EXPECT_EQ(std::string(s), "foo\n"); }); - buffer.RequestLine(1, [](absl::string_view s) { // + buffer.RequestLine(1, [](std::string_view s) { // EXPECT_EQ(std::string(s), "bar\n"); }); // Be graceful with out-of-range requests. - buffer.RequestLine(-1, [](absl::string_view s) { // + buffer.RequestLine(-1, [](std::string_view s) { // EXPECT_TRUE(s.empty()); }); - buffer.RequestLine(100, [](absl::string_view s) { // + buffer.RequestLine(100, [](std::string_view s) { // EXPECT_TRUE(s.empty()); }); } TEST(TextBufferTest, RecreateFileWithAndWithoutNewlineAtEOF) { - static constexpr absl::string_view kBaseFile = + static constexpr std::string_view kBaseFile = "Hello World\n" "\n" "Foo"; - for (const absl::string_view append : {"", "\n", "\r\n"}) { + for (const std::string_view append : {"", "\n", "\r\n"}) { const std::string &content = absl::StrCat(kBaseFile, append); EditTextBuffer buffer(content); EXPECT_EQ(buffer.lines(), 3); - buffer.RequestContent([&](absl::string_view s) { // + buffer.RequestContent([&](std::string_view s) { // EXPECT_EQ(std::string(s), content); }); } @@ -73,9 +73,8 @@ TEST(TextBufferTest, RecreateFileWithAndWithoutNewlineAtEOF) { TEST(TextBufferTest, RecreateCRLFFiles) { EditTextBuffer buffer("Foo\r\nBar\r\n"); EXPECT_EQ(buffer.lines(), 2); - buffer.RequestContent([&](absl::string_view s) { - EXPECT_EQ("Foo\r\nBar\r\n", std::string(s)); - }); + buffer.RequestContent( + [&](std::string_view s) { EXPECT_EQ("Foo\r\nBar\r\n", std::string(s)); }); } TEST(TextBufferTest, ChangeApplyFullContent) { @@ -86,7 +85,7 @@ TEST(TextBufferTest, ChangeApplyFullContent) { .text = "NewFile", }; EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { // + buffer.RequestContent([&](std::string_view s) { // EXPECT_EQ("NewFile", std::string(s)); }); } @@ -104,7 +103,7 @@ TEST(TextBufferTest, ChangeApplySingleLine_Insert) { }; EXPECT_TRUE(buffer.ApplyChange(change)); EXPECT_EQ(buffer.document_length(), 17); - buffer.RequestContent([&](absl::string_view s) { + buffer.RequestContent([&](std::string_view s) { EXPECT_EQ("Hello brave World", std::string(s)); }); } @@ -122,7 +121,7 @@ TEST(TextBufferTest, ChangeApplySingleLineWithUTF8Characters_Insert) { }; EXPECT_TRUE(buffer.ApplyChange(change)); EXPECT_EQ(buffer.document_length(), 19); - buffer.RequestContent([&](absl::string_view s) { + buffer.RequestContent([&](std::string_view s) { EXPECT_EQ("Hëllö brave World", std::string(s)); }); } @@ -139,7 +138,7 @@ TEST(TextBufferTest, ChangeApplySingleLine_InsertFromEmptyFile) { .text = "New File!", }; EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { // + buffer.RequestContent([&](std::string_view s) { // EXPECT_EQ("New File!", std::string(s)); }); } @@ -156,9 +155,8 @@ TEST(TextBufferTest, ChangeApplySingleLine_Replace) { .text = "Planet", }; EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { - EXPECT_EQ("Hello Planet\n", std::string(s)); - }); + buffer.RequestContent( + [&](std::string_view s) { EXPECT_EQ("Hello Planet\n", std::string(s)); }); } TEST(TextBufferTest, ChangeApplySingleLineWihtUTF8Characters_Replace) { @@ -173,7 +171,7 @@ TEST(TextBufferTest, ChangeApplySingleLineWihtUTF8Characters_Replace) { .text = "brandgefahr", }; EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { + buffer.RequestContent([&](std::string_view s) { EXPECT_EQ("Heizölbrandgefahrabdämpfung\n", std::string(s)); }); } @@ -191,7 +189,7 @@ TEST(TextBufferTest, ChangeApplySingleLine_ReplaceNotFirstLine) { .text = "Bar", }; EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { + buffer.RequestContent([&](std::string_view s) { EXPECT_EQ("Hello World\nBar\n", std::string(s)); }); } @@ -209,7 +207,7 @@ TEST(TextBufferTest, ChangeApplySingleLine_Erase) { }; EXPECT_TRUE(buffer.ApplyChange(change)); EXPECT_EQ(buffer.document_length(), 6); - buffer.RequestContent([&](absl::string_view s) { // + buffer.RequestContent([&](std::string_view s) { // EXPECT_EQ("Hello\n", std::string(s)); }); } @@ -227,7 +225,7 @@ TEST(TextBufferTest, ChangeApplySingleLine_ReplaceCorrectOverlongEnd) { { EditTextBuffer buffer("Hello World\n"); EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { + buffer.RequestContent([&](std::string_view s) { EXPECT_EQ("Hello Planet\n", std::string(s)); }); } @@ -235,9 +233,8 @@ TEST(TextBufferTest, ChangeApplySingleLine_ReplaceCorrectOverlongEnd) { { EditTextBuffer buffer("Hello World"); EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { - EXPECT_EQ("Hello Planet", std::string(s)); - }); + buffer.RequestContent( + [&](std::string_view s) { EXPECT_EQ("Hello Planet", std::string(s)); }); } } @@ -253,7 +250,7 @@ TEST(TextBufferTest, ChangeApplyMultiLine_EraseBetweenLines) { .text = "y ", }; EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { // + buffer.RequestContent([&](std::string_view s) { // EXPECT_EQ("Hey World\n", std::string(s)); }); EXPECT_EQ(buffer.document_length(), 10); @@ -271,7 +268,7 @@ TEST(TextBufferTest, ChangeApplyMultiLineWithUTF8Characters_Modify) { .text = "brand-\ngefahr", }; EXPECT_TRUE(buffer.ApplyChange(change)); - buffer.RequestContent([&](absl::string_view s) { // + buffer.RequestContent([&](std::string_view s) { // EXPECT_EQ("Heizölbrand-\ngefahrabdämpfung\n", std::string(s)); }); } @@ -290,9 +287,9 @@ TEST(TextBufferTest, ChangeApplyMultiLine_InsertMoreLines) { EXPECT_EQ(buffer.lines(), 2); EXPECT_TRUE(buffer.ApplyChange(change)); EXPECT_EQ(buffer.lines(), 3); - static constexpr absl::string_view kExpected = + static constexpr std::string_view kExpected = "Hey!\nThis will be a new line\nand more in this World\n"; - buffer.RequestContent([&](absl::string_view s) { // + buffer.RequestContent([&](std::string_view s) { // EXPECT_EQ(kExpected, std::string(s)); }); EXPECT_EQ(buffer.document_length(), kExpected.length()); @@ -312,7 +309,7 @@ TEST(TextBufferTest, ChangeApplyMultiLine_InsertFromStart) { EXPECT_EQ(buffer.lines(), 0); EXPECT_TRUE(buffer.ApplyChange(change)); EXPECT_EQ(buffer.lines(), 3); - buffer.RequestContent([&](absl::string_view s) { + buffer.RequestContent([&](std::string_view s) { EXPECT_EQ("This is now\na multiline\nfile\n", std::string(s)); }); EXPECT_EQ(buffer.document_length(), change.text.length()); @@ -332,7 +329,7 @@ TEST(TextBufferTest, ChangeApplyMultiLine_RemoveLines) { EXPECT_EQ(buffer.lines(), 4); EXPECT_TRUE(buffer.ApplyChange(change)); EXPECT_EQ(buffer.lines(), 2); - buffer.RequestContent([&](absl::string_view s) { // + buffer.RequestContent([&](std::string_view s) { // EXPECT_EQ("Foo\nQuux", std::string(s)); }); EXPECT_EQ(buffer.document_length(), 8); @@ -346,7 +343,7 @@ TEST(BufferCollection, SimulateDocumentLifecycleThroughRPC) { // we expect. // Notifications don't send any responses; write function not relevant. - JsonRpcDispatcher rpc_dispatcher([](absl::string_view) {}); + JsonRpcDispatcher rpc_dispatcher([](std::string_view) {}); BufferCollection collection(&rpc_dispatcher); EXPECT_EQ(collection.size(), 0); @@ -359,7 +356,7 @@ TEST(BufferCollection, SimulateDocumentLifecycleThroughRPC) { collection.SetChangeListener( [&](const std::string &uri, const EditTextBuffer *buffer) { EXPECT_EQ(uri, "file:///foo.cc"); - buffer->RequestContent([](absl::string_view s) { + buffer->RequestContent([](std::string_view s) { EXPECT_EQ(std::string(s), "Hello\nworld"); }); change_callback_called++; @@ -390,7 +387,7 @@ TEST(BufferCollection, SimulateDocumentLifecycleThroughRPC) { [&](const std::string &uri, const EditTextBuffer *buffer) { EXPECT_EQ(uri, "file:///foo.cc"); buffer->RequestContent( - [](absl::string_view s) { EXPECT_EQ(std::string(s), "Hey"); }); + [](std::string_view s) { EXPECT_EQ(std::string(s), "Hey"); }); change_callback_called++; }); diff --git a/verible/common/lsp/message-stream-splitter.cc b/verible/common/lsp/message-stream-splitter.cc index 9d9b603a7..3daf86403 100644 --- a/verible/common/lsp/message-stream-splitter.cc +++ b/verible/common/lsp/message-stream-splitter.cc @@ -17,12 +17,12 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/escaping.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/util/status-macros.h" namespace verible { @@ -42,25 +42,25 @@ absl::Status MessageStreamSplitter::PullFrom(const ReadFun &read_fun) { // On success, returns the offset to the body and its size in "body_size" static constexpr int kIncompleteHeader = -1; static constexpr int kGarbledHeader = -2; -int MessageStreamSplitter::ParseHeaderGetBodyOffset(absl::string_view data, +int MessageStreamSplitter::ParseHeaderGetBodyOffset(std::string_view data, int *body_size) { // TODO(hzeller): Make this more robust. Parse each \r\n section separately. - static constexpr absl::string_view kEndHeaderMarker = "\r\n\r\n"; - static constexpr absl::string_view kContentLengthHeader = "Content-Length: "; + static constexpr std::string_view kEndHeaderMarker = "\r\n\r\n"; + static constexpr std::string_view kContentLengthHeader = "Content-Length: "; int header_marker_len = kEndHeaderMarker.length(); auto end_of_header = data.find(kEndHeaderMarker); - if (end_of_header == absl::string_view::npos) return kIncompleteHeader; + if (end_of_header == std::string_view::npos) return kIncompleteHeader; // Very dirty search for header - we don't check if starts with line. - const absl::string_view header_content(data.data(), end_of_header); + const std::string_view header_content(data.data(), end_of_header); auto found_ContentLength_header = header_content.find(kContentLengthHeader); - if (found_ContentLength_header == absl::string_view::npos) { + if (found_ContentLength_header == std::string_view::npos) { return kGarbledHeader; } size_t end_key = found_ContentLength_header + kContentLengthHeader.size(); - absl::string_view header_value = header_content.substr(end_key); + std::string_view header_value = header_content.substr(end_key); auto end_of_digit = std::find_if(header_value.begin(), header_value.end(), [](char c) { return c < '0' || c > '9'; }); header_value = header_value.substr(0, end_of_digit - header_value.begin()); @@ -75,12 +75,12 @@ int MessageStreamSplitter::ParseHeaderGetBodyOffset(absl::string_view data, // Updates "data" to return the remaining unprocessed data. // Returns ok() status encountered a corrupted header. absl::Status MessageStreamSplitter::ProcessContainedMessages( - absl::string_view *data) { + std::string_view *data) { while (!data->empty()) { int body_size = 0; const int body_offset = ParseHeaderGetBodyOffset(*data, &body_size); if (body_offset == kGarbledHeader) { - absl::string_view limited_view( + std::string_view limited_view( data->data(), std::min(data->size(), static_cast(256))); return absl::InvalidArgumentError( absl::StrCat("No `Content-Length:` header. '", @@ -93,8 +93,8 @@ absl::Status MessageStreamSplitter::ProcessContainedMessages( return absl::OkStatus(); // Only insufficient partial buffer available. } - absl::string_view header(data->data(), body_offset); - absl::string_view body(data->data() + body_offset, body_size); + std::string_view header(data->data(), body_offset); + std::string_view body(data->data() + body_offset, body_size); message_processor_(header, body); stats_largest_body_ = std::max(stats_largest_body_, body.size()); @@ -137,7 +137,7 @@ absl::Status MessageStreamSplitter::ReadInput(const ReadFun &read_fun) { } stats_total_bytes_read_ += bytes_read; - absl::string_view data(read_buffer_.data(), write_offset + bytes_read); + std::string_view data(read_buffer_.data(), write_offset + bytes_read); RETURN_IF_ERROR(ProcessContainedMessages(&data)); pending_data_ = data; // Remember for next round. diff --git a/verible/common/lsp/message-stream-splitter.h b/verible/common/lsp/message-stream-splitter.h index 20247bf7b..709ae15db 100644 --- a/verible/common/lsp/message-stream-splitter.h +++ b/verible/common/lsp/message-stream-splitter.h @@ -17,10 +17,10 @@ #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" namespace verible { namespace lsp { @@ -50,7 +50,7 @@ class MessageStreamSplitter { // Function called with each complete message that has been extracted from // the stream. using MessageProcessFun = - std::function; + std::function; // Optional parameter is "initial_read_buffer_size" for the initial // internal buffer size (will be realloc'ed when needed). @@ -89,12 +89,12 @@ class MessageStreamSplitter { size_t StatTotalBytesRead() const { return stats_total_bytes_read_; } private: - int ParseHeaderGetBodyOffset(absl::string_view data, int *body_size); - absl::Status ProcessContainedMessages(absl::string_view *data); + int ParseHeaderGetBodyOffset(std::string_view data, int *body_size); + absl::Status ProcessContainedMessages(std::string_view *data); absl::Status ReadInput(const ReadFun &read_fun); std::vector read_buffer_; - absl::string_view pending_data_; + std::string_view pending_data_; MessageProcessFun message_processor_; diff --git a/verible/common/lsp/message-stream-splitter_test.cc b/verible/common/lsp/message-stream-splitter_test.cc index 5551929d7..d70f1010b 100644 --- a/verible/common/lsp/message-stream-splitter_test.cc +++ b/verible/common/lsp/message-stream-splitter_test.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -41,7 +41,7 @@ TEST(MessageStreamSplitterTest, NotRegisteredMessageProcessor) { // simulate partial reads. class DataStreamSimulator { public: - explicit DataStreamSimulator(absl::string_view content, int max_chunk = -1) + explicit DataStreamSimulator(std::string_view content, int max_chunk = -1) : content_(content), max_chunk_(max_chunk) {} int read(char *buf, int size) { @@ -62,7 +62,7 @@ TEST(MessageStreamSplitterTest, IgnoreHeadersNotNeeded) { MessageStreamSplitter header_test(256); int count_call = 0; header_test.SetMessageProcessor( - [&count_call](absl::string_view, absl::string_view body) { + [&count_call](std::string_view, std::string_view body) { EXPECT_EQ(std::string(body), "x"); ++count_call; }); @@ -89,13 +89,13 @@ TEST(MessageStreamSplitterTest, IgnoreHeadersNotNeeded) { } TEST(MessageStreamSplitterTest, CompleteReadValidMessage) { - static constexpr absl::string_view kHeader = "Content-Length: 3\r\n\r\n"; - static constexpr absl::string_view kBody = "foo"; + static constexpr std::string_view kHeader = "Content-Length: 3\r\n\r\n"; + static constexpr std::string_view kBody = "foo"; DataStreamSimulator stream(absl::StrCat(kHeader, kBody)); MessageStreamSplitter s(4096); int processor_call_count = 0; - s.SetMessageProcessor([&](absl::string_view header, absl::string_view body) { + s.SetMessageProcessor([&](std::string_view header, std::string_view body) { ++processor_call_count; EXPECT_EQ(std::string(header), kHeader); EXPECT_EQ(std::string(body), kBody); @@ -118,13 +118,13 @@ TEST(MessageStreamSplitterTest, CompleteReadValidMessage) { } TEST(MessageStreamSplitterTest, BufferSizeReallocated) { - static constexpr absl::string_view kHeader = "Content-Length: 3\r\n\r\n"; - static constexpr absl::string_view kBody = "foo"; + static constexpr std::string_view kHeader = "Content-Length: 3\r\n\r\n"; + static constexpr std::string_view kBody = "foo"; DataStreamSimulator stream(absl::StrCat(kHeader, kBody)); MessageStreamSplitter s(2); // Start with way too small buffer int processor_call_count = 0; - s.SetMessageProcessor([&](absl::string_view header, absl::string_view body) { + s.SetMessageProcessor([&](std::string_view header, std::string_view body) { EXPECT_EQ(std::string(body), "foo"); ++processor_call_count; }); @@ -141,14 +141,14 @@ TEST(MessageStreamSplitterTest, BufferSizeReallocated) { } TEST(MessageStreamSplitterTest, StreamDoesNotContainCompleteData) { - static constexpr absl::string_view kHeader = "Content-Length: 3\r\n\r\n"; - static constexpr absl::string_view kBody = "fo"; // <- too short + static constexpr std::string_view kHeader = "Content-Length: 3\r\n\r\n"; + static constexpr std::string_view kBody = "fo"; // <- too short DataStreamSimulator stream(absl::StrCat(kHeader, kBody)); MessageStreamSplitter s(4096); int processor_call_count = 0; s.SetMessageProcessor( - [&](absl::string_view, absl::string_view) { ++processor_call_count; }); + [&](std::string_view, std::string_view) { ++processor_call_count; }); absl::Status status = absl::OkStatus(); while (status.ok()) { @@ -164,15 +164,15 @@ TEST(MessageStreamSplitterTest, StreamDoesNotContainCompleteData) { } TEST(MessageStreamSplitterTest, CompleteReadMultipleMessages) { - static constexpr absl::string_view kHeader = "Content-Length: 3\r\n\r\n"; - static constexpr absl::string_view kBody[2] = {"foo", "bar"}; + static constexpr std::string_view kHeader = "Content-Length: 3\r\n\r\n"; + static constexpr std::string_view kBody[2] = {"foo", "bar"}; DataStreamSimulator stream( absl::StrCat(kHeader, kBody[0], kHeader, kBody[1])); MessageStreamSplitter s(4096); int processor_call_count = 0; // We expect one call per complete header/body pair. - s.SetMessageProcessor([&](absl::string_view header, absl::string_view body) { + s.SetMessageProcessor([&](std::string_view header, std::string_view body) { EXPECT_EQ(std::string(header), kHeader); EXPECT_EQ(std::string(body), kBody[processor_call_count]); ++processor_call_count; @@ -185,15 +185,15 @@ TEST(MessageStreamSplitterTest, CompleteReadMultipleMessages) { // Simulate short reads. Each read call only trickles out a few bytes. TEST(MessageStreamSplitterTest, CompleteReadMultipleMessagesShortRead) { - static constexpr absl::string_view kHeader = "Content-Length: 3\r\n\r\n"; - static constexpr absl::string_view kBody[2] = {"foo", "bar"}; + static constexpr std::string_view kHeader = "Content-Length: 3\r\n\r\n"; + static constexpr std::string_view kBody[2] = {"foo", "bar"}; static constexpr int kTrickleReadSize = 2; DataStreamSimulator stream(absl::StrCat(kHeader, kBody[0], kHeader, kBody[1]), kTrickleReadSize); MessageStreamSplitter s(4096); int processor_call_count = 0; - s.SetMessageProcessor([&](absl::string_view header, absl::string_view body) { + s.SetMessageProcessor([&](std::string_view header, std::string_view body) { EXPECT_EQ(std::string(header), kHeader); EXPECT_EQ(std::string(body), kBody[processor_call_count]); ++processor_call_count; @@ -214,13 +214,13 @@ TEST(MessageStreamSplitterTest, CompleteReadMultipleMessagesShortRead) { } TEST(MessageStreamSplitterTest, NotAvailableContentHeaderReadError) { - static constexpr absl::string_view kHeader = "not-content-length: 3\r\n\r\n"; - static constexpr absl::string_view kBody = "foo"; + static constexpr std::string_view kHeader = "not-content-length: 3\r\n\r\n"; + static constexpr std::string_view kBody = "foo"; DataStreamSimulator stream(absl::StrCat(kHeader, kBody)); MessageStreamSplitter s(4096); int processor_call_count = 0; - s.SetMessageProcessor([&](absl::string_view header, absl::string_view body) { + s.SetMessageProcessor([&](std::string_view header, std::string_view body) { ++processor_call_count; }); auto status = @@ -232,13 +232,13 @@ TEST(MessageStreamSplitterTest, NotAvailableContentHeaderReadError) { } TEST(MessageStreamSplitterTest, GarbledSizeInContentHeader) { - static constexpr absl::string_view kHeader = "Content-Length: xyz\r\n\r\n"; - static constexpr absl::string_view kBody = "foo"; + static constexpr std::string_view kHeader = "Content-Length: xyz\r\n\r\n"; + static constexpr std::string_view kBody = "foo"; DataStreamSimulator stream(absl::StrCat(kHeader, kBody)); MessageStreamSplitter s(4096); int processor_call_count = 0; - s.SetMessageProcessor([&](absl::string_view header, absl::string_view body) { + s.SetMessageProcessor([&](std::string_view header, std::string_view body) { ++processor_call_count; }); auto status = diff --git a/verible/common/parser/BUILD b/verible/common/parser/BUILD index 4223f349b..adefabbea 100644 --- a/verible/common/parser/BUILD +++ b/verible/common/parser/BUILD @@ -21,7 +21,6 @@ cc_library( "//verible/common/text:token-info", "//verible/common/util:logging", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -60,7 +59,6 @@ cc_library( "//verible/common/text:token-info", "//verible/common/util:casts", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -75,7 +73,6 @@ cc_library( "//verible/common/text:token-info-test-util", "//verible/common/util:logging", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", # for library testonly ], ) @@ -93,7 +90,6 @@ cc_test( "//verible/common/text:symbol", "//verible/common/text:token-info", "//verible/common/util:casts", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/common/parser/bison-parser-adapter.h b/verible/common/parser/bison-parser-adapter.h index 33ade5331..4fae8e7da 100644 --- a/verible/common/parser/bison-parser-adapter.h +++ b/verible/common/parser/bison-parser-adapter.h @@ -25,10 +25,10 @@ #define VERIBLE_COMMON_PARSER_BISON_PARSER_ADAPTER_H_ #include // for size_t +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/lexer/token-generator.h" #include "verible/common/parser/parse.h" #include "verible/common/parser/parser-param.h" @@ -43,8 +43,7 @@ template class BisonParserAdapter : public Parser { public: // Filename purely FYI. - BisonParserAdapter(TokenGenerator *token_generator, - absl::string_view filename) + BisonParserAdapter(TokenGenerator *token_generator, std::string_view filename) : Parser(), param_(token_generator, filename) {} absl::Status Parse() final { diff --git a/verible/common/parser/bison-parser-common_test.cc b/verible/common/parser/bison-parser-common_test.cc index acd54d9a7..c5fe1eaa1 100644 --- a/verible/common/parser/bison-parser-common_test.cc +++ b/verible/common/parser/bison-parser-common_test.cc @@ -17,8 +17,8 @@ #include "verible/common/parser/bison-parser-common.h" #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/lexer/lexer.h" #include "verible/common/lexer/token-stream-adapter.h" @@ -41,7 +41,7 @@ class MockLexer : public Lexer { const TokenInfo &DoNextToken() final { return token_; } - void Restart(absl::string_view) final {} + void Restart(std::string_view) final {} bool TokenIsError(const TokenInfo &) const final { return false; } diff --git a/verible/common/parser/parser-param.cc b/verible/common/parser/parser-param.cc index 6068b7069..ae91dba2f 100644 --- a/verible/common/parser/parser-param.cc +++ b/verible/common/parser/parser-param.cc @@ -18,10 +18,10 @@ #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/lexer/token-generator.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -32,7 +32,7 @@ namespace verible { ParserParam::ParserParam(TokenGenerator *token_stream, - absl::string_view filename) + std::string_view filename) : token_stream_(token_stream), filename_(filename), last_token_(TokenInfo::EOFToken()), diff --git a/verible/common/parser/parser-param.h b/verible/common/parser/parser-param.h index 6ef62cacb..72dd70ebb 100644 --- a/verible/common/parser/parser-param.h +++ b/verible/common/parser/parser-param.h @@ -22,10 +22,10 @@ #include #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/lexer/token-generator.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/token-info.h" @@ -46,7 +46,7 @@ class ParserParam { public: // The "filename" is merely to have better error messages, it is purely // FYI, does not change processing. - ParserParam(TokenGenerator *token_stream, absl::string_view filename); + ParserParam(TokenGenerator *token_stream, std::string_view filename); ~ParserParam(); @@ -59,7 +59,7 @@ class ParserParam { void RecordSyntaxError(const SymbolPtr &symbol_ptr); // Filename being processed, if known. - absl::string_view filename() const { return filename_; } + std::string_view filename() const { return filename_; } const std::vector &RecoveredSyntaxErrors() const { return recovered_syntax_errors_; diff --git a/verible/common/parser/parser-test-util.h b/verible/common/parser/parser-test-util.h index ee58b3f82..50ca7322e 100644 --- a/verible/common/parser/parser-test-util.h +++ b/verible/common/parser/parser-test-util.h @@ -18,10 +18,10 @@ #define VERIBLE_COMMON_PARSER_PARSER_TEST_UTIL_H_ #include // for string +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/matcher/descent-path.h" #include "verible/common/text/parser-verifier.h" @@ -35,7 +35,7 @@ namespace verible { // class AnalyzerType is any class with a absl::Status AnalyzerType::Analyze() // method. template -void TestParserAcceptValid(absl::string_view code, int i) { +void TestParserAcceptValid(std::string_view code, int i) { VLOG(1) << "test_data[" << i << "] = '" << code << "'\n"; AnalyzerType analyzer(code, "<>"); absl::Status status = analyzer.Analyze(); @@ -71,7 +71,7 @@ void TestParserRejectInvalid(const TokenInfoTestData &test, int i) { const auto &rejected_tokens = analyzer.GetRejectedTokens(); ASSERT_FALSE(rejected_tokens.empty()); - const absl::string_view base_text = analyzer.Data().Contents(); + const std::string_view base_text = analyzer.Data().Contents(); const auto expected_error_tokens = test.FindImportantTokens(base_text); ASSERT_FALSE(expected_error_tokens.empty()); // Only check the first rejected token, ignore the rest. @@ -117,7 +117,7 @@ void TestParserErrorRecovered(const ErrorRecoveryTestCase &test, int i) { } template -void TestParserAllMatched(absl::string_view code, int i) { +void TestParserAllMatched(std::string_view code, int i) { VLOG(1) << "test_data[" << i << "] = '" << code << "'\n"; AnalyzerType analyzer(code, "<>"); diff --git a/verible/common/strings/BUILD b/verible/common/strings/BUILD index a9190e0cc..d85f036a3 100644 --- a/verible/common/strings/BUILD +++ b/verible/common/strings/BUILD @@ -11,7 +11,6 @@ package( cc_library( name = "compare", hdrs = ["compare.h"], - deps = ["@abseil-cpp//absl/strings:string_view"], ) cc_test( @@ -19,7 +18,6 @@ cc_test( srcs = ["compare_test.cc"], deps = [ ":compare", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -33,7 +31,6 @@ cc_library( "//verible/common/util:logging", "//verible/common/util:range", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -43,7 +40,6 @@ cc_test( deps = [ ":comment-utils", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -58,7 +54,6 @@ cc_library( ":split", "//external_libs:editscript", "//verible/common/util:iterator-range", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -69,7 +64,6 @@ cc_test( ":diff", ":position", "//external_libs:editscript", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -79,10 +73,7 @@ cc_library( name = "display-utils", srcs = ["display-utils.cc"], hdrs = ["display-utils.h"], - deps = [ - "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["@abseil-cpp//absl/strings"], ) cc_test( @@ -90,7 +81,6 @@ cc_test( srcs = ["display-utils_test.cc"], deps = [ ":display-utils", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -106,7 +96,6 @@ cc_library( "//verible/common/util:logging", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -119,7 +108,6 @@ cc_test( "//verible/common/util:bijective-map", "//verible/common/util:logging", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -128,17 +116,13 @@ cc_test( cc_library( name = "mem-block", hdrs = ["mem-block.h"], - deps = ["@abseil-cpp//absl/strings:string_view"], ) cc_library( name = "naming-utils", srcs = ["naming-utils.cc"], hdrs = ["naming-utils.h"], - deps = [ - "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["@abseil-cpp//absl/strings"], ) cc_test( @@ -171,7 +155,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -184,7 +167,6 @@ cc_test( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -197,7 +179,6 @@ cc_library( deps = [ "//verible/common/util:interval", "//verible/common/util:interval-set", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -206,7 +187,6 @@ cc_test( srcs = ["position_test.cc"], deps = [ ":position", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -220,7 +200,6 @@ cc_library( "//verible/common/util:interval-set", "//verible/common/util:iterator-range", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -241,7 +220,6 @@ cc_library( deps = [ "//verible/common/util:logging", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -251,7 +229,6 @@ cc_test( deps = [ ":range", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -261,10 +238,7 @@ cc_library( name = "split", srcs = ["split.cc"], hdrs = ["split.h"], - deps = [ - "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["@abseil-cpp//absl/strings"], ) cc_test( @@ -274,7 +248,6 @@ cc_test( ":range", ":split", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -284,10 +257,7 @@ cc_library( name = "rebase", srcs = ["rebase.cc"], hdrs = ["rebase.h"], - deps = [ - "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["//verible/common/util:logging"], ) cc_test( @@ -296,7 +266,6 @@ cc_test( deps = [ ":rebase", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -305,7 +274,6 @@ cc_test( cc_library( name = "utf8", hdrs = ["utf8.h"], - deps = ["@abseil-cpp//absl/strings:string_view"], ) cc_library( @@ -319,10 +287,7 @@ cc_library( "//verible/verilog/formatting:__pkg__", "//verible/verilog/tools/ls:__pkg__", ], - deps = [ - ":utf8", - "@abseil-cpp//absl/strings:string_view", - ], + deps = [":utf8"], ) cc_test( @@ -341,7 +306,6 @@ cc_test( deps = [ ":line-column-map", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -355,7 +319,6 @@ cc_library( "//verible/common/util:interval-map", "//verible/common/util:interval-set", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -367,7 +330,6 @@ cc_test( ":string-memory-map", "//verible/common/util:logging", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/common/strings/comment-utils.cc b/verible/common/strings/comment-utils.cc index 7afdad184..6a6486b40 100644 --- a/verible/common/strings/comment-utils.cc +++ b/verible/common/strings/comment-utils.cc @@ -17,23 +17,23 @@ #include #include #include +#include #include "absl/strings/ascii.h" -#include "absl/strings/string_view.h" #include "verible/common/util/logging.h" #include "verible/common/util/range.h" namespace verible { // Returns the number of occurences of a character c in the text's prefix. -static size_t CountLeadingChars(absl::string_view text, char c) { +static size_t CountLeadingChars(std::string_view text, char c) { const auto rpos = text.find_first_not_of(c); - if (rpos == absl::string_view::npos) return text.length(); + if (rpos == std::string_view::npos) return text.length(); return rpos; } // Returns the number of occurences of a character c in the text's suffix. -static size_t CountTrailingChars(absl::string_view text, char c) { +static size_t CountTrailingChars(std::string_view text, char c) { const auto rpos = std::find_if(text.rbegin(), text.rend(), [=](const char ch) { return ch != c; }); // if rpos == text.rend(), then return == text.length(). @@ -49,7 +49,7 @@ static size_t CountTrailingChars(absl::string_view text, char c) { // * and this // **/ // Returns a substring within text, even if it is equivalent to empty. -static absl::string_view StripBlockComment(absl::string_view text) { +static std::string_view StripBlockComment(std::string_view text) { // Adjust for multiple *'s like /**** and ****/ . // Strip off /* and */ first and then remove leading/trailing *'s. const size_t lpos = CountLeadingChars(text.substr(2), '*') + 2; @@ -69,10 +69,10 @@ static absl::string_view StripBlockComment(absl::string_view text) { return text.substr(lpos, rpos - lpos); } -absl::string_view StripComment(absl::string_view text) { +std::string_view StripComment(std::string_view text) { if (text.length() < 2) return text; // cannot be an endline comment - const absl::string_view start = text.substr(0, 2); - const absl::string_view end = text.substr(text.length() - 2); + const std::string_view start = text.substr(0, 2); + const std::string_view end = text.substr(text.length() - 2); if (start == "//") { const auto ltrim = CountLeadingChars(text.substr(2), '/') + 2; return text.substr(ltrim); @@ -84,7 +84,7 @@ absl::string_view StripComment(absl::string_view text) { return text; } -absl::string_view StripCommentAndSpacePadding(absl::string_view text) { +std::string_view StripCommentAndSpacePadding(std::string_view text) { const auto stripped_text = StripComment(text); CHECK(verible::IsSubRange(stripped_text, text)); const auto return_text = absl::StripAsciiWhitespace(stripped_text); diff --git a/verible/common/strings/comment-utils.h b/verible/common/strings/comment-utils.h index 1c4408af7..c8ffd73b8 100644 --- a/verible/common/strings/comment-utils.h +++ b/verible/common/strings/comment-utils.h @@ -15,7 +15,7 @@ #ifndef VERIBLE_COMMON_STRINGS_COMMENT_UTILS_H_ #define VERIBLE_COMMON_STRINGS_COMMENT_UTILS_H_ -#include "absl/strings/string_view.h" +#include namespace verible { @@ -24,10 +24,10 @@ namespace verible { // If text is not a comment, it is returned unmodified, but in general, do not // rely on any specific behavior for non-comments. // Result is always a substring of the original (bounds may be equal). -absl::string_view StripComment(absl::string_view); +std::string_view StripComment(std::string_view); // Same as StripComment, but also removes leading and trailing whitespace. -absl::string_view StripCommentAndSpacePadding(absl::string_view); +std::string_view StripCommentAndSpacePadding(std::string_view); } // namespace verible diff --git a/verible/common/strings/comment-utils_test.cc b/verible/common/strings/comment-utils_test.cc index 8f64979d4..58d5483d7 100644 --- a/verible/common/strings/comment-utils_test.cc +++ b/verible/common/strings/comment-utils_test.cc @@ -14,7 +14,8 @@ #include "verible/common/strings/comment-utils.h" -#include "absl/strings/string_view.h" +#include + #include "gtest/gtest.h" #include "verible/common/util/range.h" @@ -22,13 +23,13 @@ namespace verible { namespace { struct TestData { - absl::string_view input; + std::string_view input; const char *expect; }; // Test that non-comments are left unmodified. TEST(StripCommentTest, NotComment) { - constexpr absl::string_view test_cases[] = { + constexpr std::string_view test_cases[] = { "", "/", // too short to be a comment "foo", diff --git a/verible/common/strings/compare.h b/verible/common/strings/compare.h index 2945b52ce..d0d73d8c9 100644 --- a/verible/common/strings/compare.h +++ b/verible/common/strings/compare.h @@ -15,7 +15,7 @@ #ifndef VERIBLE_COMMON_STRINGS_COMPARE_H_ #define VERIBLE_COMMON_STRINGS_COMPARE_H_ -#include "absl/strings/string_view.h" +#include namespace verible { @@ -29,7 +29,7 @@ struct StringViewCompare { using is_transparent = void; // Works on anything that is implicitly convertible to string_view. - bool operator()(absl::string_view a, absl::string_view b) const { + bool operator()(std::string_view a, std::string_view b) const { return a < b; } }; diff --git a/verible/common/strings/compare_test.cc b/verible/common/strings/compare_test.cc index b817b924a..abc748b8f 100644 --- a/verible/common/strings/compare_test.cc +++ b/verible/common/strings/compare_test.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -36,8 +36,8 @@ TEST(StringViewCompareTest, ConstCharPointers) { } TEST(StringViewCompareTest, StringViews) { - const absl::string_view a("aaa"); - const absl::string_view b("bbb"); + const std::string_view a("aaa"); + const std::string_view b("bbb"); StringViewCompare comp; EXPECT_TRUE(comp(a, b)); EXPECT_FALSE(comp(b, a)); @@ -54,7 +54,7 @@ TEST(StringViewCompareTest, StdStrings) { TEST(StringViewCompareTest, HeterogeneousStrings) { const char a[] = "aaa"; const std::string b("bbb"); - const absl::string_view c("ccc"); + const std::string_view c("ccc"); StringViewCompare comp; EXPECT_TRUE(comp(a, b)); EXPECT_FALSE(comp(b, a)); @@ -77,7 +77,7 @@ TEST(StringViewCompareTest, MapStdStringKey) { } TEST(StringViewCompareTest, MapStringViewKey) { - const std::map numbers{ + const std::map numbers{ {"one", 1}, {"two", 2}, {"three", 3}, diff --git a/verible/common/strings/diff.cc b/verible/common/strings/diff.cc index c9fea7b05..3f274d84b 100644 --- a/verible/common/strings/diff.cc +++ b/verible/common/strings/diff.cc @@ -16,9 +16,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "external_libs/editscript.h" #include "verible/common/strings/position.h" #include "verible/common/strings/split.h" @@ -43,7 +43,7 @@ static char EditOperationToLineMarker(Operation op) { } } -LineDiffs::LineDiffs(absl::string_view before, absl::string_view after) +LineDiffs::LineDiffs(std::string_view before, std::string_view after) : before_text(before), after_text(after), before_lines(SplitLinesKeepLineTerminator(before_text)), @@ -158,8 +158,8 @@ std::vector DiffEditsToPatchHunks(const diff::Edits &edits, } void LineDiffsToUnifiedDiff(std::ostream &stream, const LineDiffs &linediffs, - unsigned common_context, absl::string_view file_a, - absl::string_view file_b) { + unsigned common_context, std::string_view file_a, + std::string_view file_b) { const std::vector chunks = DiffEditsToPatchHunks(linediffs.edits, common_context); diff --git a/verible/common/strings/diff.h b/verible/common/strings/diff.h index 8af1e1d0b..d8c084022 100644 --- a/verible/common/strings/diff.h +++ b/verible/common/strings/diff.h @@ -16,9 +16,9 @@ #define VERIBLE_COMMON_STRINGS_DIFF_H_ #include +#include #include -#include "absl/strings/string_view.h" #include "external_libs/editscript.h" #include "verible/common/strings/position.h" @@ -33,14 +33,14 @@ namespace verible { // LineDiffs diffs(old_text, new_text); // struct LineDiffs { - const absl::string_view before_text; - const absl::string_view after_text; - const std::vector before_lines; // lines - const std::vector after_lines; // lines + const std::string_view before_text; + const std::string_view after_text; + const std::vector before_lines; // lines + const std::vector after_lines; // lines const diff::Edits edits; // line difference/edit-sequence between texts. // Computes the line-difference between before_text and after_text. - LineDiffs(absl::string_view before_text, absl::string_view after_text); + LineDiffs(std::string_view before_text, std::string_view after_text); std::ostream &PrintEdit(std::ostream &, const diff::Edit &) const; }; @@ -80,8 +80,8 @@ std::vector DiffEditsToPatchHunks(const diff::Edits &edits, void LineDiffsToUnifiedDiff(std::ostream &stream, const LineDiffs &linediffs, unsigned common_context, - absl::string_view file_a = {}, - absl::string_view file_b = {}); + std::string_view file_a = {}, + std::string_view file_b = {}); } // namespace verible diff --git a/verible/common/strings/diff_test.cc b/verible/common/strings/diff_test.cc index dcaec1c0f..5d7510867 100644 --- a/verible/common/strings/diff_test.cc +++ b/verible/common/strings/diff_test.cc @@ -19,9 +19,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "external_libs/editscript.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -68,9 +68,9 @@ using diff::Operation; using ::testing::ElementsAreArray; struct DiffTestCase { - absl::string_view before; - absl::string_view after; - absl::string_view expected; + std::string_view before; + std::string_view after; + std::string_view expected; }; TEST(LineDiffsTest, Various) { @@ -524,12 +524,12 @@ TEST(DiffEditsToPatchHunksTest, Various) { } struct LineDiffsToUnifiedDiffTestCase { - absl::string_view before_text; - absl::string_view after_text; - absl::string_view file_a; - absl::string_view file_b; + std::string_view before_text; + std::string_view after_text; + std::string_view file_a; + std::string_view file_b; int common_context; - absl::string_view expected_diff_text; + std::string_view expected_diff_text; }; TEST(LineDiffsToUnifiedDiffTest, Various) { diff --git a/verible/common/strings/display-utils.cc b/verible/common/strings/display-utils.cc index 4f68d6ddf..6797644ed 100644 --- a/verible/common/strings/display-utils.cc +++ b/verible/common/strings/display-utils.cc @@ -16,12 +16,11 @@ #include #include - -#include "absl/strings/string_view.h" +#include namespace verible { -static constexpr absl::string_view kEllipses = "..."; +static constexpr std::string_view kEllipses = "..."; std::ostream &operator<<(std::ostream &stream, const AutoTruncate &trunc) { const auto text = trunc.text; diff --git a/verible/common/strings/display-utils.h b/verible/common/strings/display-utils.h index d29ea1380..3a1b55157 100644 --- a/verible/common/strings/display-utils.h +++ b/verible/common/strings/display-utils.h @@ -16,9 +16,9 @@ #define VERIBLE_COMMON_STRINGS_DISPLAY_UTILS_H_ #include +#include #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" namespace verible { @@ -30,7 +30,7 @@ namespace verible { // // example output (limit: 9): "abc...xyz" struct AutoTruncate { - const absl::string_view text; + const std::string_view text; // Maximum number of characters to show, including "..." const int max_chars; }; @@ -43,9 +43,9 @@ std::ostream &operator<<(std::ostream &, const AutoTruncate &trunc); // // usage: stream << EscapeString(text); struct EscapeString { - const absl::string_view text; // original text to be printed + const std::string_view text; // original text to be printed - explicit EscapeString(absl::string_view text) : text(text) {} + explicit EscapeString(std::string_view text) : text(text) {} }; std::ostream &operator<<(std::ostream &, const EscapeString &vis); @@ -56,16 +56,16 @@ std::ostream &operator<<(std::ostream &, const EscapeString &vis); // // usage: stream << VisualizeWhitespace(text_with_lots_of_spaces); struct VisualizeWhitespace { - const absl::string_view text; // original text to be printed + const std::string_view text; // original text to be printed - const char space_alt; // spaces replacement - const absl::string_view newline_alt; // newline replacement - const absl::string_view tab_alt; // tab replacement + const char space_alt; // spaces replacement + const std::string_view newline_alt; // newline replacement + const std::string_view tab_alt; // tab replacement // constructor needed for C++11 - explicit VisualizeWhitespace(absl::string_view text, char space_alt = '.', - absl::string_view newline_alt = "\\\n", - absl::string_view tab_alt = "#") + explicit VisualizeWhitespace(std::string_view text, char space_alt = '.', + std::string_view newline_alt = "\\\n", + std::string_view tab_alt = "#") : text(text), space_alt(space_alt), newline_alt(newline_alt), @@ -88,9 +88,9 @@ std::ostream &operator<<(std::ostream &, const VisualizeWhitespace &vis); template struct SequenceStreamFormatter { const T &sequence; // binds to object that is to be printed - absl::string_view separator; - absl::string_view prefix; - absl::string_view suffix; + std::string_view separator; + std::string_view prefix; + std::string_view suffix; // TODO(fangism): pass in custom formatter object, and be able to nest // multiple levels of formatters. }; @@ -136,9 +136,9 @@ std::ostream &operator<<(std::ostream &stream, // template SequenceStreamFormatter SequenceFormatter(const T &t, - absl::string_view sep = ", ", - absl::string_view prefix = "", - absl::string_view suffix = "") { + std::string_view sep = ", ", + std::string_view prefix = "", + std::string_view suffix = "") { return SequenceStreamFormatter{t, sep, prefix, suffix}; } diff --git a/verible/common/strings/display-utils_test.cc b/verible/common/strings/display-utils_test.cc index 3b905b922..7fd3c28ac 100644 --- a/verible/common/strings/display-utils_test.cc +++ b/verible/common/strings/display-utils_test.cc @@ -15,19 +15,19 @@ #include "verible/common/strings/display-utils.h" #include +#include #include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace verible { namespace { struct TruncateTestCase { - absl::string_view input; + std::string_view input; int max_chars; - absl::string_view expected; + std::string_view expected; }; TEST(AutoTruncateTest, Various) { @@ -53,7 +53,7 @@ TEST(AutoTruncateTest, Various) { } TEST(VisualizeWhitespaceTest, Various) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"", ""}, {"abc", "abc"}, {"ABC", "ABC"}, {"123", "123"}, {" ", "..."}, {"\n\n\n", "\\\n\\\n\\\n"}, @@ -67,7 +67,7 @@ TEST(VisualizeWhitespaceTest, Various) { } TEST(VisualizeWhitespaceTest, OtherSubstitutions) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"", ""}, {"abc", "abc"}, {"ABC", "ABC"}, {"123", "123"}, {" ", "---"}, {"\n\n\n", "NNN"}, @@ -81,7 +81,7 @@ TEST(VisualizeWhitespaceTest, OtherSubstitutions) { } TEST(EscapeStringTest, Various) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"", ""}, {"abc", "abc"}, {"ABC", "ABC"}, diff --git a/verible/common/strings/line-column-map.cc b/verible/common/strings/line-column-map.cc index 92d4ebb30..dd1ad94e2 100644 --- a/verible/common/strings/line-column-map.cc +++ b/verible/common/strings/line-column-map.cc @@ -19,9 +19,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/strings/utf8.h" namespace verible { @@ -55,12 +55,12 @@ std::ostream &operator<<(std::ostream &out, const LineColumnRange &r) { // offsets into line:column numbers. // Offsets are guaranteed to be monotonically increasing (sorted), and // thus, are binary-searchable. -LineColumnMap::LineColumnMap(absl::string_view text) { +LineColumnMap::LineColumnMap(std::string_view text) { // The column number after every line break is 0. // The first line always starts at offset 0. beginning_of_line_offsets_.push_back(0); auto offset = text.find('\n'); - while (offset != absl::string_view::npos) { + while (offset != std::string_view::npos) { beginning_of_line_offsets_.push_back(offset + 1); offset = text.find('\n', offset + 1); } @@ -70,7 +70,7 @@ LineColumnMap::LineColumnMap(absl::string_view text) { // Constructor that calculates line break offsets given an already-split // set of lines for a body of text. -LineColumnMap::LineColumnMap(const std::vector &lines) { +LineColumnMap::LineColumnMap(const std::vector &lines) { size_t offset = 0; for (const auto &line : lines) { beginning_of_line_offsets_.push_back(offset); @@ -78,7 +78,7 @@ LineColumnMap::LineColumnMap(const std::vector &lines) { } } -LineColumn LineColumnMap::GetLineColAtOffset(absl::string_view base, +LineColumn LineColumnMap::GetLineColAtOffset(std::string_view base, int bytes_offset) const { const auto begin = beginning_of_line_offsets_.begin(); const auto end = beginning_of_line_offsets_.end(); @@ -86,7 +86,7 @@ LineColumn LineColumnMap::GetLineColAtOffset(absl::string_view base, const auto line_at_offset = std::upper_bound(begin, end, bytes_offset) - 1; const int line_number = std::distance(begin, line_at_offset); const int len_within_line = bytes_offset - *line_at_offset; - absl::string_view line = base.substr(*line_at_offset, len_within_line); + std::string_view line = base.substr(*line_at_offset, len_within_line); return LineColumn{line_number, utf8_len(line)}; } diff --git a/verible/common/strings/line-column-map.h b/verible/common/strings/line-column-map.h index 54a041318..5ebaccec8 100644 --- a/verible/common/strings/line-column-map.h +++ b/verible/common/strings/line-column-map.h @@ -15,7 +15,7 @@ // LineColumnMap translates byte-offset into line-column. // // usage: -// absl::string_view text = ...; +// std::string_view text = ...; // LineColumnMap lcmap(text); // token_error_offset = ...; // some file diagnosis // LineColumn error_location = lcmap(token_error_offset); @@ -27,10 +27,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" - namespace verible { // Pair: line number and column number. @@ -72,13 +71,13 @@ class LineColumnMap { // Build line column map from pre-split contiguous blob of content. // The distance between consecutive string_views is expected to have // a gap of one character (the splitting '\n' character). - explicit LineColumnMap(const std::vector &lines); + explicit LineColumnMap(const std::vector &lines); // This constructor is only used in LintStatusFormatter and // LintWaiverBuilder. // TODO: If these already have access to pre-split lines, then this // constructor is not needed. - explicit LineColumnMap(absl::string_view); + explicit LineColumnMap(std::string_view); bool empty() const { return beginning_of_line_offsets_.empty(); } @@ -100,7 +99,7 @@ class LineColumnMap { // TODO(hzeller): technically, we don't need the base as we already got it // in the constructor, but change separately after lifetime questions have // been considered. - LineColumn GetLineColAtOffset(absl::string_view base, int bytes_offset) const; + LineColumn GetLineColAtOffset(std::string_view base, int bytes_offset) const; const std::vector &GetBeginningOfLineOffsets() const { return beginning_of_line_offsets_; diff --git a/verible/common/strings/line-column-map_test.cc b/verible/common/strings/line-column-map_test.cc index 7456f5cf2..547302cf6 100644 --- a/verible/common/strings/line-column-map_test.cc +++ b/verible/common/strings/line-column-map_test.cc @@ -18,10 +18,10 @@ #include #include // IWYU pragma: keep // for ostringstream +#include #include #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace verible { @@ -125,7 +125,7 @@ TEST(LineColumnMapTest, Offsets) { TEST(LineColumnMapTest, OffsetsFromLines) { for (const auto &test_case : map_test_data) { const LineColumnMap line_map(test_case.text); - std::vector lines = absl::StrSplit(test_case.text, '\n'); + std::vector lines = absl::StrSplit(test_case.text, '\n'); const LineColumnMap alt_line_map(lines); EXPECT_EQ(line_map.GetBeginningOfLineOffsets(), alt_line_map.GetBeginningOfLineOffsets()) @@ -134,13 +134,13 @@ TEST(LineColumnMapTest, OffsetsFromLines) { } TEST(LineColumnMapTest, EndOffsetNoLines) { - const std::vector lines; + const std::vector lines; const LineColumnMap map(lines); EXPECT_EQ(map.LastLineOffset(), 0); } struct EndOffsetTestCase { - absl::string_view text; + std::string_view text; int expected_offset; }; diff --git a/verible/common/strings/mem-block.h b/verible/common/strings/mem-block.h index 0261d53db..3957c659f 100644 --- a/verible/common/strings/mem-block.h +++ b/verible/common/strings/mem-block.h @@ -16,8 +16,7 @@ #define COMMON_STRINGS_MEM_BLOCK_H #include - -#include "absl/strings/string_view.h" +#include namespace verible { // A representation of a block of (readonly) memory that is owned by MemBlock. @@ -27,7 +26,7 @@ namespace verible { class MemBlock { public: virtual ~MemBlock() = default; - virtual absl::string_view AsStringView() const = 0; + virtual std::string_view AsStringView() const = 0; protected: MemBlock() = default; @@ -44,14 +43,14 @@ class StringMemBlock final : public MemBlock { public: StringMemBlock() = default; explicit StringMemBlock(std::string &&move_from) : content_(move_from) {} - explicit StringMemBlock(absl::string_view copy_from) + explicit StringMemBlock(std::string_view copy_from) : content_(copy_from.begin(), copy_from.end()) {} // Assign/modify content. Use sparingly, ideally only in initialization // as the expectation of the MemBlock is that it won't change later. std::string *mutable_content() { return &content_; } - absl::string_view AsStringView() const final { return content_; } + std::string_view AsStringView() const final { return content_; } private: std::string content_; diff --git a/verible/common/strings/naming-utils.cc b/verible/common/strings/naming-utils.cc index a280d9ae3..b71530ebe 100644 --- a/verible/common/strings/naming-utils.cc +++ b/verible/common/strings/naming-utils.cc @@ -15,31 +15,31 @@ #include "verible/common/strings/naming-utils.h" #include +#include #include "absl/strings/ascii.h" -#include "absl/strings/string_view.h" namespace verible { -bool IsNameAllCapsUnderscoresDigits(absl::string_view text) { +bool IsNameAllCapsUnderscoresDigits(std::string_view text) { return std::all_of(text.begin(), text.end(), [](char c) { return absl::ascii_isupper(c) || c == '_' || absl::ascii_isdigit(c); }); } -bool AllUnderscoresFollowedByDigits(absl::string_view text) { +bool AllUnderscoresFollowedByDigits(std::string_view text) { if (text.empty()) return true; // Return false if the underscore is the last character. if (text[text.length() - 1] == '_') return false; - for (absl::string_view::size_type i = 0; i < text.length() - 1; ++i) { + for (std::string_view::size_type i = 0; i < text.length() - 1; ++i) { if (text[i] == '_' && !absl::ascii_isdigit(text[i + 1])) return false; } return true; } -bool IsUpperCamelCaseWithDigits(absl::string_view text) { +bool IsUpperCamelCaseWithDigits(std::string_view text) { if (text.empty()) return true; // Check that the first letter is capital. Not allowing "_foo" cases. @@ -47,13 +47,13 @@ bool IsUpperCamelCaseWithDigits(absl::string_view text) { // Check for underscores followed by digits auto pos = text.find('_'); - if (pos != absl::string_view::npos) { + if (pos != std::string_view::npos) { return AllUnderscoresFollowedByDigits(text.substr(pos)); } return true; } -bool IsLowerSnakeCaseWithDigits(absl::string_view text) { +bool IsLowerSnakeCaseWithDigits(std::string_view text) { if (text.empty()) return true; // Check that the first letter is lowercase. Not allowing "_foo" cases. diff --git a/verible/common/strings/naming-utils.h b/verible/common/strings/naming-utils.h index 269d003c1..0c3872e13 100644 --- a/verible/common/strings/naming-utils.h +++ b/verible/common/strings/naming-utils.h @@ -15,23 +15,23 @@ #ifndef VERIBLE_COMMON_STRINGS_NAMING_UTILS_H_ #define VERIBLE_COMMON_STRINGS_NAMING_UTILS_H_ -#include "absl/strings/string_view.h" +#include namespace verible { // Returns true if the string contains only capital letters, digits, and // underscores. -bool IsNameAllCapsUnderscoresDigits(absl::string_view); +bool IsNameAllCapsUnderscoresDigits(std::string_view); // Returns true if the all the underscores in the string are followed by digits. -bool AllUnderscoresFollowedByDigits(absl::string_view); +bool AllUnderscoresFollowedByDigits(std::string_view); // Returns true if the string follows UpperCamelCase naming convention, where // underscores are allowed when separating a digit. -bool IsUpperCamelCaseWithDigits(absl::string_view); +bool IsUpperCamelCaseWithDigits(std::string_view); // Returns true if the string follows lower_snake_case naming convention. -bool IsLowerSnakeCaseWithDigits(absl::string_view); +bool IsLowerSnakeCaseWithDigits(std::string_view); } // namespace verible diff --git a/verible/common/strings/obfuscator.cc b/verible/common/strings/obfuscator.cc index 3213c2ccf..a655fa7c3 100644 --- a/verible/common/strings/obfuscator.cc +++ b/verible/common/strings/obfuscator.cc @@ -16,22 +16,22 @@ #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/util/logging.h" namespace verible { -bool Obfuscator::encode(absl::string_view key, absl::string_view value) { +bool Obfuscator::encode(std::string_view key, std::string_view value) { return translator_.insert(std::string(key), std::string(value)); } -absl::string_view Obfuscator::operator()(absl::string_view input) { +std::string_view Obfuscator::operator()(std::string_view input) { if (decode_mode_) { const auto *p = translator_.find_reverse(input); return (p != nullptr) ? *p : input; @@ -51,11 +51,11 @@ std::string Obfuscator::save() const { return stream.str(); } -absl::Status Obfuscator::load(absl::string_view mapping) { - const std::vector lines = +absl::Status Obfuscator::load(std::string_view mapping) { + const std::vector lines = absl::StrSplit(mapping, '\n', absl::SkipEmpty()); for (const auto &line : lines) { - const std::vector elements = + const std::vector elements = absl::StrSplit(absl::StripAsciiWhitespace(line), kPairSeparator); if (elements.size() < 2) { return absl::InvalidArgumentError( @@ -67,8 +67,8 @@ absl::Status Obfuscator::load(absl::string_view mapping) { return absl::OkStatus(); } -bool IdentifierObfuscator::encode(absl::string_view key, - absl::string_view value) { +bool IdentifierObfuscator::encode(std::string_view key, + std::string_view value) { CHECK_EQ(key.length(), value.length()); return parent_type::encode(key, value); } diff --git a/verible/common/strings/obfuscator.h b/verible/common/strings/obfuscator.h index 213799798..782fd8623 100644 --- a/verible/common/strings/obfuscator.h +++ b/verible/common/strings/obfuscator.h @@ -17,9 +17,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/compare.h" #include "verible/common/util/bijective-map.h" @@ -40,7 +40,7 @@ namespace verible { // substitutions written/read from a text file. class Obfuscator { public: - using generator_type = std::function; + using generator_type = std::function; using translator_type = BijectiveMap; @@ -50,7 +50,7 @@ class Obfuscator { // used in obfuscation. This is useful for applying previously used // translations. Returns true if key-value pair was successfully inserted, // else returns false if either key or value were already mapped. - bool encode(absl::string_view key, absl::string_view value); + bool encode(std::string_view key, std::string_view value); void set_decode_mode(bool decode) { decode_mode_ = decode; } @@ -58,7 +58,7 @@ class Obfuscator { // Obfuscates input string with a replacement, and records the substitution // for later re-use. Returns the replacement string. - absl::string_view operator()(absl::string_view input); + std::string_view operator()(std::string_view input); // Read-only view of string translation map. const translator_type &GetTranslator() const { return translator_; } @@ -66,7 +66,7 @@ class Obfuscator { // Parses a mapping dictionary, and pre-loads the translator map with it. // Format: one entry per line, each line is space-separated pair of // identifiers. - absl::Status load(absl::string_view); + absl::Status load(std::string_view); // Returns a string representation of the internal identifier map. // See format description for ::load(). @@ -93,7 +93,7 @@ class IdentifierObfuscator : public Obfuscator { explicit IdentifierObfuscator(const generator_type &g) : Obfuscator(g) {} // Same as inherited method, but verifies that key and value are equal length. - bool encode(absl::string_view key, absl::string_view value); + bool encode(std::string_view key, std::string_view value); }; } // namespace verible diff --git a/verible/common/strings/obfuscator_test.cc b/verible/common/strings/obfuscator_test.cc index 3d18128f2..8544c5995 100644 --- a/verible/common/strings/obfuscator_test.cc +++ b/verible/common/strings/obfuscator_test.cc @@ -15,9 +15,9 @@ #include "verible/common/strings/obfuscator.h" #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/strings/random.h" #include "verible/common/util/bijective-map.h" @@ -33,7 +33,7 @@ static char Rot13(char c) { } // Non-random generator, just for the sake of testing. -static std::string RotateGenerator(absl::string_view input) { +static std::string RotateGenerator(std::string_view input) { std::string s(input); for (auto &ch : s) ch = Rot13(ch); return s; diff --git a/verible/common/strings/patch.cc b/verible/common/strings/patch.cc index b0d426bfd..966307b35 100644 --- a/verible/common/strings/patch.cc +++ b/verible/common/strings/patch.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "absl/base/attributes.h" @@ -31,7 +32,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "verible/common/strings/position.h" #include "verible/common/strings/split.h" @@ -46,11 +46,11 @@ namespace verible { -static bool LineMarksOldFile(absl::string_view line) { +static bool LineMarksOldFile(std::string_view line) { return absl::StartsWith(line, "--- "); } -static bool IsValidMarkedLine(absl::string_view line) { +static bool IsValidMarkedLine(std::string_view line) { if (line.empty()) return false; switch (line.front()) { case ' ': @@ -77,7 +77,7 @@ static std::vector IteratorsToRanges(const std::vector &iters) { return result; } -absl::Status MarkedLine::Parse(absl::string_view text) { +absl::Status MarkedLine::Parse(std::string_view text) { // text is already a whole line if (!IsValidMarkedLine(text)) { return absl::InvalidArgumentError(absl::StrCat( @@ -98,11 +98,11 @@ std::string HunkIndices::FormatToString() const { return absl::StrCat(start, ",", count); } -absl::Status HunkIndices::Parse(absl::string_view text) { +absl::Status HunkIndices::Parse(std::string_view text) { // text is expected to look like "int,int" StringSpliterator splitter(text); - const absl::string_view start_text = splitter(','); - const absl::string_view count_text = splitter(','); + const std::string_view start_text = splitter(','); + const std::string_view count_text = splitter(','); if (!absl::SimpleAtoi(start_text, &start) || // !absl::SimpleAtoi(count_text, &count) || // splitter /* unexpected second ',' */) { @@ -116,11 +116,11 @@ std::ostream &operator<<(std::ostream &stream, const HunkIndices &indices) { return stream << indices.FormatToString(); } -absl::Status HunkHeader::Parse(absl::string_view text) { - constexpr absl::string_view kDelimiter("@@"); +absl::Status HunkHeader::Parse(std::string_view text) { + constexpr std::string_view kDelimiter("@@"); StringSpliterator tokenizer(text); { - absl::string_view first = tokenizer(kDelimiter); + std::string_view first = tokenizer(kDelimiter); // first token should be empty if (!first.empty() || !tokenizer) { return absl::InvalidArgumentError(absl::StrCat( @@ -130,7 +130,7 @@ absl::Status HunkHeader::Parse(absl::string_view text) { // Parse ranges between the "@@"s. { - const absl::string_view ranges = + const std::string_view ranges = absl::StripAsciiWhitespace(tokenizer(kDelimiter)); if (!tokenizer) { return absl::InvalidArgumentError(absl::StrCat( @@ -138,13 +138,13 @@ absl::Status HunkHeader::Parse(absl::string_view text) { } auto splitter = MakeStringSpliterator(ranges, ' '); - absl::string_view old_range_str(splitter()); + std::string_view old_range_str(splitter()); if (!absl::ConsumePrefix(&old_range_str, "-")) { return absl::InvalidArgumentError(absl::StrCat( "old-file range should start with '-', but got: ", old_range_str, "\".")); } - absl::string_view new_range_str(splitter()); + std::string_view new_range_str(splitter()); if (!absl::ConsumePrefix(&new_range_str, "+")) { return absl::InvalidArgumentError(absl::StrCat( "new-file range should start with '+', but got: ", new_range_str, @@ -155,7 +155,7 @@ absl::Status HunkHeader::Parse(absl::string_view text) { } // Text that follows the last "@@" provides context and is optional. - const absl::string_view trailing_text = tokenizer(kDelimiter); + const std::string_view trailing_text = tokenizer(kDelimiter); context.assign(trailing_text.begin(), trailing_text.end()); return absl::OkStatus(); @@ -225,7 +225,7 @@ LineNumberSet Hunk::AddedLines() const { } absl::Status Hunk::VerifyAgainstOriginalLines( - const std::vector &original_lines) const { + const std::vector &original_lines) const { int line_number = header_.old_range.start; // 1-indexed for (const MarkedLine &line : lines_) { if (line.IsAdded()) continue; // ignore added lines @@ -234,7 +234,7 @@ absl::Status Hunk::VerifyAgainstOriginalLines( "Patch hunk references line ", line_number, " in a file with only ", original_lines.size(), " lines")); } - const absl::string_view original_line = original_lines[line_number - 1]; + const std::string_view original_line = original_lines[line_number - 1]; if (line.Text() != original_line) { return absl::DataLossError(absl::StrCat( "Patch is inconsistent with original file!\nHunk at line ", @@ -332,10 +332,10 @@ std::ostream &operator<<(std::ostream &stream, const Hunk &hunk) { return hunk.Print(stream); } -absl::Status SourceInfo::Parse(absl::string_view text) { +absl::Status SourceInfo::Parse(std::string_view text) { StringSpliterator splitter(text); - absl::string_view token = splitter('\t'); + std::string_view token = splitter('\t'); path.assign(token.begin(), token.end()); if (path.empty()) { return absl::InvalidArgumentError(absl::StrCat( @@ -357,10 +357,9 @@ std::ostream &operator<<(std::ostream &stream, const SourceInfo &info) { } static absl::Status ParseSourceInfoWithMarker( - SourceInfo *info, absl::string_view line, - absl::string_view expected_marker) { + SourceInfo *info, std::string_view line, std::string_view expected_marker) { StringSpliterator splitter(line); - absl::string_view marker = splitter(' '); + std::string_view marker = splitter(' '); if (marker != expected_marker) { return absl::InvalidArgumentError( absl::StrCat("Expected old-file marker \"", expected_marker, @@ -396,7 +395,7 @@ static char PromptHunkAction(std::istream &ins, std::ostream &outs) { } absl::Status FilePatch::VerifyAgainstOriginalLines( - const std::vector &original_lines) const { + const std::vector &original_lines) const { for (const Hunk &hunk : hunks_) { RETURN_IF_ERROR(hunk.VerifyAgainstOriginalLines(original_lines)); } @@ -430,7 +429,7 @@ absl::Status FilePatch::PickApply(std::istream &ins, std::ostream &outs, term::Color::kCyan); } - const std::vector orig_lines(SplitLines(*orig_file_or)); + const std::vector orig_lines(SplitLines(*orig_file_or)); RETURN_IF_ERROR(VerifyAgainstOriginalLines(orig_lines)); // Accumulate lines to write here. @@ -453,7 +452,7 @@ absl::Status FilePatch::PickApply(std::istream &ins, std::ostream &outs, } for (; last_consumed_line < old_range.start - 1; ++last_consumed_line) { CHECK_LT(last_consumed_line, static_cast(orig_lines.size())); - const absl::string_view &line(orig_lines[last_consumed_line]); + const std::string_view &line(orig_lines[last_consumed_line]); output_lines.emplace_back(line.begin(), line.end()); // copy string } VLOG(1) << "copied up to (!including) line[" << last_consumed_line << "]."; @@ -475,7 +474,7 @@ absl::Status FilePatch::PickApply(std::istream &ins, std::ostream &outs, // accept this hunk, copy lines over for (const MarkedLine &marked_line : hunk.MarkedLines()) { if (!marked_line.IsDeleted()) { - const absl::string_view line(marked_line.Text()); + const std::string_view line(marked_line.Text()); output_lines.emplace_back(line.begin(), line.end()); // copy string } } @@ -522,7 +521,7 @@ absl::Status FilePatch::PickApply(std::istream &ins, std::ostream &outs, // Copy over remaining lines after the last hunk. for (; last_consumed_line < static_cast(orig_lines.size()); ++last_consumed_line) { - const absl::string_view &line(orig_lines[last_consumed_line]); + const std::string_view &line(orig_lines[last_consumed_line]); output_lines.emplace_back(line.begin(), line.end()); // copy string } VLOG(1) << "copied reamining lines up to [" << last_consumed_line << "]."; @@ -556,9 +555,8 @@ absl::Status FilePatch::Parse(const LineRange &lines) { // find hunk starts, and parse ranges of hunk texts std::vector hunk_starts; - find_all( - line_iter, lines.end(), std::back_inserter(hunk_starts), - [](absl::string_view line) { return absl::StartsWith(line, "@@ "); }); + find_all(line_iter, lines.end(), std::back_inserter(hunk_starts), + [](std::string_view line) { return absl::StartsWith(line, "@@ "); }); if (hunk_starts.empty()) { // Unusual, but degenerate case of no hunks is parseable and valid. @@ -596,14 +594,14 @@ std::ostream &operator<<(std::ostream &stream, const FilePatch &patch) { } // namespace internal -static bool LineBelongsToPreviousSection(absl::string_view line) { +static bool LineBelongsToPreviousSection(std::string_view line) { if (line.empty()) return true; return IsValidMarkedLine(line); } -absl::Status PatchSet::Parse(absl::string_view patch_contents) { +absl::Status PatchSet::Parse(std::string_view patch_contents) { // Split lines. The resulting lines will not include the \n delimiters. - std::vector lines( + std::vector lines( absl::StrSplit(patch_contents, absl::ByChar('\n'))); // Consider an empty patch file valid. @@ -625,7 +623,7 @@ absl::Status PatchSet::Parse(absl::string_view patch_contents) { for (auto &iter : file_patch_begins) { while (iter != lines_range.begin()) { const auto prev = std::prev(iter); - const absl::string_view &peek(*prev); + const std::string_view &peek(*prev); if (LineBelongsToPreviousSection(peek)) break; iter = prev; } diff --git a/verible/common/strings/patch.h b/verible/common/strings/patch.h index f6da20050..d00e9e960 100644 --- a/verible/common/strings/patch.h +++ b/verible/common/strings/patch.h @@ -19,11 +19,11 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/compare.h" #include "verible/common/strings/position.h" #include "verible/common/util/container-iterator-range.h" @@ -36,11 +36,11 @@ class FilePatch; // function interface like file::GetContentAsString() using FileReaderFunction = - std::function(absl::string_view filename)>; + std::function(std::string_view filename)>; // function interface like file::SetContents() using FileWriterFunction = std::function; + std::string_view filename, std::string_view contents)>; } // namespace internal using FileLineNumbersMap = @@ -55,7 +55,7 @@ class PatchSet { PatchSet() = default; // Parse a unified-diff patch file into internal representation. - absl::Status Parse(absl::string_view patch_contents); + absl::Status Parse(std::string_view patch_contents); // Prints a unified-diff formatted output. std::ostream &Render(std::ostream &stream) const; @@ -95,7 +95,7 @@ std::ostream &operator<<(std::ostream &, const PatchSet &); // Private implementation details follow. namespace internal { -using LineIterator = std::vector::const_iterator; +using LineIterator = std::vector::const_iterator; using LineRange = container_iterator_range; // A single line of a patch hunk. @@ -106,7 +106,7 @@ struct MarkedLine { // only used in manual test case construction // so ok to use CHECK here. - explicit MarkedLine(absl::string_view text) : line(text.begin(), text.end()) { + explicit MarkedLine(std::string_view text) : line(text.begin(), text.end()) { CHECK(!line.empty()) << "MarkedLine must start with a marker in [ -+]."; CHECK(Valid()) << "Unexpected marker '" << Marker() << "'."; } @@ -126,13 +126,13 @@ struct MarkedLine { bool IsAdded() const { return Marker() == '+'; } bool IsDeleted() const { return Marker() == '-'; } - absl::string_view Text() const { return {&line[1], line.length() - 1}; } + std::string_view Text() const { return {&line[1], line.length() - 1}; } // default equality operator bool operator==(const MarkedLine &other) const { return line == other.line; } bool operator!=(const MarkedLine &other) const { return !(*this == other); } - absl::Status Parse(absl::string_view); + absl::Status Parse(std::string_view); }; std::ostream &operator<<(std::ostream &, const MarkedLine &); @@ -149,7 +149,7 @@ struct HunkIndices { std::string FormatToString() const; - absl::Status Parse(absl::string_view); + absl::Status Parse(std::string_view); }; std::ostream &operator<<(std::ostream &, const HunkIndices &); @@ -168,7 +168,7 @@ struct HunkHeader { } bool operator!=(const HunkHeader &other) const { return !(*this == other); } - absl::Status Parse(absl::string_view); + absl::Status Parse(std::string_view); }; std::ostream &operator<<(std::ostream &, const HunkHeader &); @@ -209,7 +209,7 @@ class Hunk { // Verify consistency of lines in the patch (old-file) against the file that // is read in whole. absl::Status VerifyAgainstOriginalLines( - const std::vector &original_lines) const; + const std::vector &original_lines) const; // default structural comparison bool operator==(const Hunk &other) const { @@ -236,7 +236,7 @@ struct SourceInfo { std::string path; // location to patched file, absolute or relative std::string timestamp; // unspecified date format, not parsed, optional - absl::Status Parse(absl::string_view); + absl::Status Parse(std::string_view); }; std::ostream &operator<<(std::ostream &, const SourceInfo &); @@ -263,7 +263,7 @@ class FilePatch { // Verify consistency of lines in the patch (old-file) against the file that // is read in whole. absl::Status VerifyAgainstOriginalLines( - const std::vector &original_lines) const; + const std::vector &original_lines) const; absl::Status PickApplyInPlace(std::istream &ins, std::ostream &outs) const; diff --git a/verible/common/strings/patch_test.cc b/verible/common/strings/patch_test.cc index 258221fb7..42e7c513a 100644 --- a/verible/common/strings/patch_test.cc +++ b/verible/common/strings/patch_test.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,6 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/strings/position.h" @@ -40,7 +40,7 @@ namespace internal { namespace { static std::vector MakeMarkedLines( - const std::vector &lines) { + const std::vector &lines) { std::vector result; result.reserve(lines.size()); for (const auto &line : lines) { @@ -63,7 +63,7 @@ TEST(MarkedLineEquality, EqualityTests) { } TEST(MarkedLineParseTest, InvalidInputs) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { "", "x", "x213", "abc", "diff", "====", }; for (const auto &test : kTestCases) { @@ -73,9 +73,9 @@ TEST(MarkedLineParseTest, InvalidInputs) { } struct MarkedLineTestCase { - absl::string_view input; + std::string_view input; char expected_mark; - absl::string_view expected_text; + std::string_view expected_text; }; TEST(MarkedLineParseTest, ValidInputs) { @@ -94,7 +94,7 @@ TEST(MarkedLineParseTest, ValidInputs) { } TEST(MarkedLinePrintTest, Print) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { " ", "+", "-", " 1 2 3", "-xyz", "+\tabc", }; for (const auto &test : kTestCases) { @@ -116,7 +116,7 @@ TEST(HunkIndicesEqualityTest, Comparisons) { } TEST(HunkIndicesParseTest, InvalidInputs) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { "", ",", "4,", ",5", "2,b", "x,2", "4,5,", "1,2,3", }; for (const auto &test : kTestCases) { @@ -126,7 +126,7 @@ TEST(HunkIndicesParseTest, InvalidInputs) { } struct HunkIndicesTestCase { - absl::string_view input; + std::string_view input; int expected_start; int expected_count; }; @@ -161,7 +161,7 @@ TEST(HunkHeaderEqualityTest, Comparisons) { TEST(HunkHeaderParseTest, InvalidInputs) { // If any one character is deleted from this example, it becomes invalid. - constexpr absl::string_view kValidText = "@@ -4,8 +5,6 @@"; + constexpr std::string_view kValidText = "@@ -4,8 +5,6 @@"; for (size_t i = 0; i < kValidText.length(); ++i) { std::string deleted(kValidText); @@ -171,20 +171,20 @@ TEST(HunkHeaderParseTest, InvalidInputs) { } for (size_t i = 0; i < kValidText.length(); ++i) { - absl::string_view deleted(kValidText.substr(0, i)); + std::string_view deleted(kValidText.substr(0, i)); HunkHeader h; EXPECT_FALSE(h.Parse(deleted).ok()) << " input: \"" << deleted << '"'; } for (size_t i = 1; i < kValidText.length(); ++i) { - absl::string_view deleted(kValidText.substr(i)); + std::string_view deleted(kValidText.substr(i)); HunkHeader h; EXPECT_FALSE(h.Parse(deleted).ok()) << " input: \"" << deleted << '"'; } } TEST(HunkHeaderParseTest, MalformedOldRange) { - constexpr absl::string_view kInvalidText = "@@ 4,8 +5,6 @@"; + constexpr std::string_view kInvalidText = "@@ 4,8 +5,6 @@"; HunkHeader h; const auto status = h.Parse(kInvalidText); EXPECT_FALSE(status.ok()) << " input: \"" << kInvalidText << '"'; @@ -194,7 +194,7 @@ TEST(HunkHeaderParseTest, MalformedOldRange) { } TEST(HunkHeaderParseTest, MalformedNewRange) { - constexpr absl::string_view kInvalidText = "@@ -4,8 5,6 @@"; + constexpr std::string_view kInvalidText = "@@ -4,8 5,6 @@"; HunkHeader h; const auto status = h.Parse(kInvalidText); EXPECT_FALSE(status.ok()) << " input: \"" << kInvalidText << '"'; @@ -204,7 +204,7 @@ TEST(HunkHeaderParseTest, MalformedNewRange) { } TEST(HunkHeaderParseAndPrintTest, ValidInput) { - constexpr absl::string_view kValidText = "@@ -14,8 +5,16 @@"; + constexpr std::string_view kValidText = "@@ -14,8 +5,16 @@"; HunkHeader h; EXPECT_TRUE(h.Parse(kValidText).ok()) << " input: \"" << kValidText << '"'; EXPECT_EQ(h.old_range.start, 14); @@ -220,7 +220,7 @@ TEST(HunkHeaderParseAndPrintTest, ValidInput) { } TEST(HunkHeaderParseAndPrintTest, ValidInputWithContext) { - constexpr absl::string_view kValidText("@@ -4,28 +51,6 @@ void foo::bar() {"); + constexpr std::string_view kValidText("@@ -4,28 +51,6 @@ void foo::bar() {"); HunkHeader h; EXPECT_TRUE(h.Parse(kValidText).ok()) << " input: \"" << kValidText << '"'; EXPECT_EQ(h.old_range.start, 4); @@ -236,7 +236,7 @@ TEST(HunkHeaderParseAndPrintTest, ValidInputWithContext) { } TEST(SourceInfoParseTest, InvalidInputs) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { "", // path must be non-empty }; for (const auto &test : kTestCases) { @@ -246,7 +246,7 @@ TEST(SourceInfoParseTest, InvalidInputs) { } TEST(SourceInfoParseAndPrintTest, ValidInputsPathOnly) { - constexpr absl::string_view kPaths[] = { + constexpr std::string_view kPaths[] = { "a.txt", "p/q/a.txt", "/p/q/a.txt", @@ -265,12 +265,12 @@ TEST(SourceInfoParseAndPrintTest, ValidInputsPathOnly) { } TEST(SourceInfoParseAndPrintTest, ValidInputsWithTimestamps) { - constexpr absl::string_view kPaths[] = { + constexpr std::string_view kPaths[] = { "a.txt", "p/q/a.txt", "/p/q/a.txt", }; - constexpr absl::string_view kTimes[] = { + constexpr std::string_view kTimes[] = { "2020-02-02", "2020-02-02 20:22:02", "2020-02-02 20:22:02.000000", @@ -293,7 +293,7 @@ TEST(SourceInfoParseAndPrintTest, ValidInputsWithTimestamps) { } TEST(HunkEqualityTest, Comparisons) { - const std::vector lines{ + const std::vector lines{ " a", "-b", "+c", @@ -312,7 +312,7 @@ TEST(HunkEqualityTest, Comparisons) { } TEST(HunkParseTest, InvalidInputs) { - const std::vector kTestCases[] = { + const std::vector kTestCases[] = { // malformed headers: {"@@ -1,0 +2,0 @"}, {"@ -1,0 +2,0 @@"}, @@ -345,12 +345,12 @@ TEST(HunkParseTest, InvalidInputs) { } struct UpdateHeaderTestCase { - absl::string_view fixed_header; - std::vector payload; + std::string_view fixed_header; + std::vector payload; }; TEST(HunkUpdateHeaderTest, Various) { - constexpr absl::string_view kNonsenseHeader = "@@ -222,999 +333,999 @@"; + constexpr std::string_view kNonsenseHeader = "@@ -222,999 +333,999 @@"; const UpdateHeaderTestCase kTestCases[] = { {"@@ -222,0 +333,0 @@", {/* empty lines */}}, {"@@ -222,1 +333,0 @@", @@ -369,7 +369,7 @@ TEST(HunkUpdateHeaderTest, Various) { {" common", "-removed", "-removed2", "+added", " common again"}}, }; for (const auto &test : kTestCases) { - std::vector lines; + std::vector lines; lines.push_back(kNonsenseHeader); lines.insert(lines.end(), test.payload.begin(), test.payload.end()); const LineRange range(lines.begin(), lines.end()); @@ -387,7 +387,7 @@ TEST(HunkUpdateHeaderTest, Various) { } struct AddedLinesTestCase { - std::vector hunk_text; + std::vector hunk_text; LineNumberSet expected_added_lines; }; @@ -498,7 +498,7 @@ TEST(HunkAddedLinesTest, Various) { } TEST(HunkSplitTest, ExpectedSingletons) { - const std::vector kTestCases[] = { + const std::vector kTestCases[] = { {" no-change"}, {"+one addition"}, {"-one deletion"}, @@ -577,7 +577,7 @@ struct HunkSplitTestCase { std::vector expected_sub_hunks; HunkSplitTestCase(int old_starting_line, int new_starting_line, - const std::vector &lines, + const std::vector &lines, const std::vector &sub_hunks) : marked_lines(MakeMarkedLines(lines)), original_hunk(old_starting_line, new_starting_line, @@ -690,7 +690,7 @@ TEST(HunkSplitTest, MultipleSubHunks) { } TEST(HunkParseAndPrintTest, ValidInputs) { - const std::vector kTestCases[] = { + const std::vector kTestCases[] = { {"@@ -1,0 +2,0 @@"}, // 0 line counts, technically consistent {"@@ -1,2 +2,2 @@", // 2 lines of context, common to before/after " same1", // @@ -728,7 +728,7 @@ TEST(HunkParseAndPrintTest, ValidInputs) { } TEST(HunkVerifyAgainstOriginalLinesTest, LineNumberOutOfBounds) { - const std::vector kHunkText = { + const std::vector kHunkText = { { "@@ -2,3 +4,3 @@", // dont' care about position in new-file " line2", // @@ -737,7 +737,7 @@ TEST(HunkVerifyAgainstOriginalLinesTest, LineNumberOutOfBounds) { " line4", // this line doesn't exist in original }, }; - const std::vector kOriginal = { + const std::vector kOriginal = { "line1", "line2", "line3", // no line4 }; @@ -756,7 +756,7 @@ TEST(HunkVerifyAgainstOriginalLinesTest, LineNumberOutOfBounds) { } TEST(HunkVerifyAgainstOriginalLinesTest, InconsistentRetainedLine) { - const std::vector kHunkText = { + const std::vector kHunkText = { { "@@ -2,2 +4,2 @@", " line2", // @@ -764,7 +764,7 @@ TEST(HunkVerifyAgainstOriginalLinesTest, InconsistentRetainedLine) { "+line pi", // }, }; - const std::vector kOriginal = { + const std::vector kOriginal = { "line1", "line2 different", "line3", @@ -784,7 +784,7 @@ TEST(HunkVerifyAgainstOriginalLinesTest, InconsistentRetainedLine) { } TEST(HunkVerifyAgainstOriginalLinesTest, InconsistentDeletedLine) { - const std::vector kHunkText = { + const std::vector kHunkText = { { "@@ -2,2 +4,2 @@", " line2", // @@ -792,7 +792,7 @@ TEST(HunkVerifyAgainstOriginalLinesTest, InconsistentDeletedLine) { "+line pi", // }, }; - const std::vector kOriginal = { + const std::vector kOriginal = { "line1", "line2", "line3 different", @@ -812,7 +812,7 @@ TEST(HunkVerifyAgainstOriginalLinesTest, InconsistentDeletedLine) { } TEST(FilePatchParseTest, InvalidInputs) { - const std::vector kTestCases[] = { + const std::vector kTestCases[] = { {}, // empty range is invalid {""}, // no "---" marker for source info { @@ -846,7 +846,7 @@ TEST(FilePatchParseTest, InvalidInputs) { } TEST(FilePatchParseAndPrintTest, ValidInputs) { - const std::vector kTestCases[] = { + const std::vector kTestCases[] = { { "--- /path/to/file.txt\t2020-03-30", "+++ /path/to/file.txt\t2020-03-30", @@ -923,7 +923,7 @@ TEST(FilePatchParseAndPrintTest, ValidInputs) { } TEST(FilePatchIsNewFileTest, NewFile) { - const std::vector kInput = { + const std::vector kInput = { "--- /dev/null\t2020-03-30", "+++ /path/to/file.txt\t2020-03-30", "@@ -0,0 +1,2 @@", @@ -939,7 +939,7 @@ TEST(FilePatchIsNewFileTest, NewFile) { } TEST(FilePatchIsNewFileTest, ExistingFile) { - const std::vector kInput = { + const std::vector kInput = { "--- /path/to/file.txt\t2020-03-30", "+++ /path/to/file.txt\t2020-03-30", "@@ -12,1 +13,1 @@", @@ -954,7 +954,7 @@ TEST(FilePatchIsNewFileTest, ExistingFile) { } TEST(FilePatchIsDeletedFileTest, DeletedFile) { - const std::vector kInput = { + const std::vector kInput = { "--- /path/to/file.txt\t2020-03-30", "+++ /dev/null\t2020-03-30", "@@ -1,2 +0,0 @@", @@ -970,7 +970,7 @@ TEST(FilePatchIsDeletedFileTest, DeletedFile) { } TEST(FilePatchIsDeletedFileTest, ExistingFile) { - const std::vector kInput = { + const std::vector kInput = { "--- /path/to/file.txt\t2020-03-30", "+++ /path/to/file.txt\t2020-03-30", "@@ -12,2 +13,2 @@", @@ -1032,18 +1032,17 @@ TEST(FilePatchAddedLinesTest, Various) { class FilePatchPickApplyTest : public FilePatch, public ::testing::Test { protected: - absl::Status ParseLines(const std::vector &lines) { + absl::Status ParseLines(const std::vector &lines) { const LineRange range(lines.begin(), lines.end()); return Parse(range); } - static absl::StatusOr NullFileReader( - absl::string_view filename) { + static absl::StatusOr NullFileReader(std::string_view filename) { return ""; } - static absl::Status NullFileWriter(absl::string_view filename, - absl::string_view contents) { + static absl::Status NullFileWriter(std::string_view filename, + std::string_view contents) { return absl::OkStatus(); } }; @@ -1051,8 +1050,8 @@ class FilePatchPickApplyTest : public FilePatch, public ::testing::Test { // Takes the place of a real file on the filesystem. // TODO(fangism): move this to a "file_test_util" library. struct StringFile { - const absl::string_view path; - const absl::string_view contents; + const std::string_view path; + const std::string_view contents; }; class StringFileSequence { @@ -1077,7 +1076,7 @@ struct ReadStringFileSequence : public StringFileSequence { : StringFileSequence(files) {} // like file::GetContentAsString() - absl::StatusOr operator()(absl::string_view filename) { + absl::StatusOr operator()(std::string_view filename) { // ASSERT_LT(i, files_.size()); // can't use ASSERT_* which returns void if (index_ >= files_.size()) { return absl::OutOfRangeError( @@ -1100,7 +1099,7 @@ struct ExpectStringFileSequence : public StringFileSequence { : StringFileSequence(files) {} // like file::SetContents() - absl::Status operator()(absl::string_view filename, absl::string_view src) { + absl::Status operator()(std::string_view filename, std::string_view src) { // ASSERT_LT(i, files_.size()); // can't use ASSERT_* which returns void if (index_ >= files_.size()) { return absl::OutOfRangeError( @@ -1117,8 +1116,8 @@ struct ExpectStringFileSequence : public StringFileSequence { TEST_F(FilePatchPickApplyTest, ErrorReadingFile) { std::istringstream ins; std::ostringstream outs; - constexpr absl::string_view kErrorMessage = "File not found."; - auto error_file_reader = [=](absl::string_view filename) { + constexpr std::string_view kErrorMessage = "File not found."; + auto error_file_reader = [=](std::string_view filename) { return absl::StatusOr(absl::NotFoundError(kErrorMessage)); }; const auto status = PickApply(ins, outs, error_file_reader, &NullFileWriter); @@ -1129,7 +1128,7 @@ TEST_F(FilePatchPickApplyTest, ErrorReadingFile) { TEST_F(FilePatchPickApplyTest, IgnoreNewFile) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- /dev/null\t2012-01-01", "+++ foo.txt\t2012-01-01", }; @@ -1145,7 +1144,7 @@ TEST_F(FilePatchPickApplyTest, IgnoreNewFile) { TEST_F(FilePatchPickApplyTest, IgnoreDeletedFile) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- bar.txt\t2012-01-01", "+++ /dev/null\t2012-01-01", }; @@ -1161,7 +1160,7 @@ TEST_F(FilePatchPickApplyTest, IgnoreDeletedFile) { TEST_F(FilePatchPickApplyTest, EmptyPatchNoPrompt) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", }; @@ -1172,8 +1171,8 @@ TEST_F(FilePatchPickApplyTest, EmptyPatchNoPrompt) { std::istringstream ins; std::ostringstream outs; - constexpr absl::string_view kOriginal = "aaa\nbbb\nccc\n"; - constexpr absl::string_view kExpected = kOriginal; // no change + constexpr std::string_view kOriginal = "aaa\nbbb\nccc\n"; + constexpr std::string_view kExpected = kOriginal; // no change const auto status = PickApply(ins, outs, // @@ -1185,7 +1184,7 @@ TEST_F(FilePatchPickApplyTest, EmptyPatchNoPrompt) { TEST_F(FilePatchPickApplyTest, ErrorWritingFileInPlace) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", }; @@ -1196,10 +1195,10 @@ TEST_F(FilePatchPickApplyTest, ErrorWritingFileInPlace) { std::istringstream ins; std::ostringstream outs; - constexpr absl::string_view kOriginal = "aaa\nbbb\nccc\n"; - constexpr absl::string_view kErrorMessage = "Cannot write file."; + constexpr std::string_view kOriginal = "aaa\nbbb\nccc\n"; + constexpr std::string_view kErrorMessage = "Cannot write file."; - auto error_file_writer = [=](absl::string_view, absl::string_view) { + auto error_file_writer = [=](std::string_view, std::string_view) { return absl::PermissionDeniedError(kErrorMessage); }; @@ -1213,7 +1212,7 @@ TEST_F(FilePatchPickApplyTest, ErrorWritingFileInPlace) { TEST_F(FilePatchPickApplyTest, OneHunkNotApplied) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,2 @@", @@ -1228,13 +1227,13 @@ TEST_F(FilePatchPickApplyTest, OneHunkNotApplied) { std::istringstream ins("n\n"); // user declines patch hunk std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" "ddd\n" "eee\n"; - constexpr absl::string_view kExpected = kOriginal; + constexpr std::string_view kExpected = kOriginal; const auto status = PickApply(ins, outs, // @@ -1246,7 +1245,7 @@ TEST_F(FilePatchPickApplyTest, OneHunkNotApplied) { TEST_F(FilePatchPickApplyTest, PatchInconsistentWithOriginalText) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,2 @@", @@ -1261,13 +1260,13 @@ TEST_F(FilePatchPickApplyTest, PatchInconsistentWithOriginalText) { std::istringstream ins("y\n"); // user accepts hunk std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb-different\n" // inconsistent with patch "ccc\n" // deleted by hunk "ddd\n" "eee\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "ddd\n" @@ -1282,7 +1281,7 @@ TEST_F(FilePatchPickApplyTest, PatchInconsistentWithOriginalText) { TEST_F(FilePatchPickApplyTest, OneDeletionAccepted) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,2 @@", @@ -1297,13 +1296,13 @@ TEST_F(FilePatchPickApplyTest, OneDeletionAccepted) { std::istringstream ins("y\n"); // user accepts hunk std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // deleted by hunk "ddd\n" "eee\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "ddd\n" @@ -1319,7 +1318,7 @@ TEST_F(FilePatchPickApplyTest, OneDeletionAccepted) { TEST_F(FilePatchPickApplyTest, OneInsertionAccepted) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,2 +2,3 @@", @@ -1334,13 +1333,13 @@ TEST_F(FilePatchPickApplyTest, OneInsertionAccepted) { std::istringstream ins("y\n"); // user accepts hunk std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" "ddd\n" "eee\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "bbb.5\n" // inserted @@ -1358,7 +1357,7 @@ TEST_F(FilePatchPickApplyTest, OneInsertionAccepted) { TEST_F(FilePatchPickApplyTest, OneReplacementAccepted) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,3 @@", @@ -1374,13 +1373,13 @@ TEST_F(FilePatchPickApplyTest, OneReplacementAccepted) { std::istringstream ins("y\n"); // user accepts hunk std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // replaced "ddd\n" "eee\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "C++\n" // replaced @@ -1397,7 +1396,7 @@ TEST_F(FilePatchPickApplyTest, OneReplacementAccepted) { TEST_F(FilePatchPickApplyTest, HelpFirstThenAcceptHunk) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,3 @@", @@ -1413,13 +1412,13 @@ TEST_F(FilePatchPickApplyTest, HelpFirstThenAcceptHunk) { std::istringstream ins("?\ny\n"); // help, accept std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // replaced "ddd\n" "eee\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "C++\n" // replaced @@ -1437,7 +1436,7 @@ TEST_F(FilePatchPickApplyTest, HelpFirstThenAcceptHunk) { TEST_F(FilePatchPickApplyTest, HunksOutOfOrder) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -5,3 +5,3 @@", @@ -1458,7 +1457,7 @@ TEST_F(FilePatchPickApplyTest, HunksOutOfOrder) { std::istringstream ins("y\nn\n"); // accept, reject std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // replaced @@ -1466,7 +1465,7 @@ TEST_F(FilePatchPickApplyTest, HunksOutOfOrder) { "eee\n" "fff\n" "ggg\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "C++\n" // replaced @@ -1485,7 +1484,7 @@ TEST_F(FilePatchPickApplyTest, HunksOutOfOrder) { TEST_F(FilePatchPickApplyTest, AcceptOnlyFirstOfTwoHunks) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,3 @@", @@ -1506,7 +1505,7 @@ TEST_F(FilePatchPickApplyTest, AcceptOnlyFirstOfTwoHunks) { std::istringstream ins("y\nn\n"); // accept, reject std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // replaced @@ -1514,7 +1513,7 @@ TEST_F(FilePatchPickApplyTest, AcceptOnlyFirstOfTwoHunks) { "eee\n" "fff\n" "ggg\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "C++\n" // replaced @@ -1533,7 +1532,7 @@ TEST_F(FilePatchPickApplyTest, AcceptOnlyFirstOfTwoHunks) { TEST_F(FilePatchPickApplyTest, AcceptOnlySecondOfTwoHunks) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,3 @@", @@ -1554,7 +1553,7 @@ TEST_F(FilePatchPickApplyTest, AcceptOnlySecondOfTwoHunks) { std::istringstream ins("n\ny\n"); // reject, accept std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // kept @@ -1562,7 +1561,7 @@ TEST_F(FilePatchPickApplyTest, AcceptOnlySecondOfTwoHunks) { "eee\n" "fff\n" // changed "ggg\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "ccc\n" // kept @@ -1581,7 +1580,7 @@ TEST_F(FilePatchPickApplyTest, AcceptOnlySecondOfTwoHunks) { TEST_F(FilePatchPickApplyTest, SplitThenAcceptOnlyFirstOfTwoHunks) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,6 +2,6 @@", // one large splittable hunk @@ -1601,7 +1600,7 @@ TEST_F(FilePatchPickApplyTest, SplitThenAcceptOnlyFirstOfTwoHunks) { std::istringstream ins("s\ny\nn\n"); // split, accept, reject std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // replaced @@ -1609,7 +1608,7 @@ TEST_F(FilePatchPickApplyTest, SplitThenAcceptOnlyFirstOfTwoHunks) { "eee\n" "fff\n" "ggg\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "C++\n" // replaced @@ -1628,7 +1627,7 @@ TEST_F(FilePatchPickApplyTest, SplitThenAcceptOnlyFirstOfTwoHunks) { TEST_F(FilePatchPickApplyTest, SplitThenAcceptOnlySecondOfTwoHunks) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,6 +2,6 @@", // one large splittable hunk @@ -1648,7 +1647,7 @@ TEST_F(FilePatchPickApplyTest, SplitThenAcceptOnlySecondOfTwoHunks) { std::istringstream ins("s\nn\ny\n"); // split, reject, accept std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // kept @@ -1656,7 +1655,7 @@ TEST_F(FilePatchPickApplyTest, SplitThenAcceptOnlySecondOfTwoHunks) { "eee\n" "fff\n" // replaced "ggg\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "ccc\n" // kept @@ -1675,7 +1674,7 @@ TEST_F(FilePatchPickApplyTest, SplitThenAcceptOnlySecondOfTwoHunks) { TEST_F(FilePatchPickApplyTest, AbortRightAway) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,3 @@", @@ -1696,7 +1695,7 @@ TEST_F(FilePatchPickApplyTest, AbortRightAway) { std::istringstream ins("q\n"); // quit (abandon) std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" @@ -1704,7 +1703,7 @@ TEST_F(FilePatchPickApplyTest, AbortRightAway) { "eee\n" "fff\n" "ggg\n"; - constexpr absl::string_view kExpected = kOriginal; + constexpr std::string_view kExpected = kOriginal; const auto status = PickApply(ins, outs, // @@ -1716,7 +1715,7 @@ TEST_F(FilePatchPickApplyTest, AbortRightAway) { TEST_F(FilePatchPickApplyTest, TreatEndOfUserInputAsAbort) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,3 @@", @@ -1737,7 +1736,7 @@ TEST_F(FilePatchPickApplyTest, TreatEndOfUserInputAsAbort) { std::istringstream ins; // empty, end of user input std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" @@ -1745,7 +1744,7 @@ TEST_F(FilePatchPickApplyTest, TreatEndOfUserInputAsAbort) { "eee\n" "fff\n" "ggg\n"; - constexpr absl::string_view kExpected = kOriginal; + constexpr std::string_view kExpected = kOriginal; const auto status = PickApply(ins, outs, // @@ -1757,7 +1756,7 @@ TEST_F(FilePatchPickApplyTest, TreatEndOfUserInputAsAbort) { TEST_F(FilePatchPickApplyTest, AbortFileAfterAcceptingOneHunk) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,3 @@", @@ -1778,7 +1777,7 @@ TEST_F(FilePatchPickApplyTest, AbortFileAfterAcceptingOneHunk) { std::istringstream ins("y\nq\n"); // accept, quit (abandon) std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" // replaced @@ -1786,7 +1785,7 @@ TEST_F(FilePatchPickApplyTest, AbortFileAfterAcceptingOneHunk) { "eee\n" "fff\n" "ggg\n"; - constexpr absl::string_view kExpected = kOriginal; + constexpr std::string_view kExpected = kOriginal; const auto status = PickApply(ins, outs, // @@ -1798,7 +1797,7 @@ TEST_F(FilePatchPickApplyTest, AbortFileAfterAcceptingOneHunk) { TEST_F(FilePatchPickApplyTest, AcceptTwoDeletions) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,2 @@", @@ -1817,7 +1816,7 @@ TEST_F(FilePatchPickApplyTest, AcceptTwoDeletions) { std::istringstream ins("y\ny\n"); // accept, accept std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" @@ -1826,7 +1825,7 @@ TEST_F(FilePatchPickApplyTest, AcceptTwoDeletions) { "fff\n" "ggg\n" "hhh\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "ddd\n" @@ -1844,7 +1843,7 @@ TEST_F(FilePatchPickApplyTest, AcceptTwoDeletions) { TEST_F(FilePatchPickApplyTest, AcceptAllDeletions) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,2 @@", @@ -1863,7 +1862,7 @@ TEST_F(FilePatchPickApplyTest, AcceptAllDeletions) { std::istringstream ins("a\n"); // accept all std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" @@ -1872,7 +1871,7 @@ TEST_F(FilePatchPickApplyTest, AcceptAllDeletions) { "fff\n" "ggg\n" "hhh\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "ddd\n" @@ -1890,7 +1889,7 @@ TEST_F(FilePatchPickApplyTest, AcceptAllDeletions) { TEST_F(FilePatchPickApplyTest, RejectAllDeletions) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,3 +2,2 @@", @@ -1909,7 +1908,7 @@ TEST_F(FilePatchPickApplyTest, RejectAllDeletions) { std::istringstream ins("d\n"); // accept all std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ccc\n" @@ -1918,7 +1917,7 @@ TEST_F(FilePatchPickApplyTest, RejectAllDeletions) { "fff\n" "ggg\n" "hhh\n"; - constexpr absl::string_view kExpected = kOriginal; // no changes + constexpr std::string_view kExpected = kOriginal; // no changes const auto status = PickApply(ins, outs, // @@ -1930,7 +1929,7 @@ TEST_F(FilePatchPickApplyTest, RejectAllDeletions) { TEST_F(FilePatchPickApplyTest, AcceptTwoInsertions) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,2 +2,3 @@", @@ -1949,14 +1948,14 @@ TEST_F(FilePatchPickApplyTest, AcceptTwoInsertions) { std::istringstream ins("y\ny\n"); // accept, accept std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ddd\n" "eee\n" "fff\n" "hhh\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "ccc\n" @@ -1976,7 +1975,7 @@ TEST_F(FilePatchPickApplyTest, AcceptTwoInsertions) { TEST_F(FilePatchPickApplyTest, AcceptAllInsertions) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,2 +2,3 @@", @@ -1995,14 +1994,14 @@ TEST_F(FilePatchPickApplyTest, AcceptAllInsertions) { std::istringstream ins("a\n"); // accept all std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ddd\n" "eee\n" "fff\n" "hhh\n"; - constexpr absl::string_view kExpected = + constexpr std::string_view kExpected = "aaa\n" "bbb\n" "ccc\n" @@ -2022,7 +2021,7 @@ TEST_F(FilePatchPickApplyTest, AcceptAllInsertions) { TEST_F(FilePatchPickApplyTest, RejectAllInsertions) { { - const std::vector kHunkText{ + const std::vector kHunkText{ "--- foo.txt\t2012-01-01", "+++ foo-formatted.txt\t2012-01-01", "@@ -2,2 +2,3 @@", @@ -2041,14 +2040,14 @@ TEST_F(FilePatchPickApplyTest, RejectAllInsertions) { std::istringstream ins("d\n"); // reject all std::ostringstream outs; - constexpr absl::string_view kOriginal = + constexpr std::string_view kOriginal = "aaa\n" "bbb\n" "ddd\n" "eee\n" "fff\n" "hhh\n"; - constexpr absl::string_view kExpected = kOriginal; + constexpr std::string_view kExpected = kOriginal; const auto status = PickApply(ins, outs, // @@ -2065,7 +2064,7 @@ namespace { // public interface tests TEST(PatchSetParseTest, InvalidInputs) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { // no "+++" marker for source "--- /path/to/file.txt\t2020-03-30\n", // hunk line counts are inconsistent @@ -2091,7 +2090,7 @@ TEST(PatchSetParseTest, InvalidInputs) { } TEST(PatchSetParseAndPrintTest, ValidInputs) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { // no metadata here "--- /path/to/file.txt\t2020-03-30\n" "+++ /path/to/file.txt\t2020-03-30\n" @@ -2167,7 +2166,7 @@ TEST(PatchSetParseAndPrintTest, ValidInputs) { } TEST(PatchSetAddedLinesMapTest, NewAndExistingFile) { - constexpr absl::string_view patch_contents = // + constexpr std::string_view patch_contents = // "diff -u /dev/null local/path/to/file1.txt\n" "--- /dev/null\t2020-03-30\n" "+++ /path/to/file1.txt\t2020-03-30\n" // new file @@ -2205,7 +2204,7 @@ class PatchSetPickApplyTest : public PatchSet, public ::testing::Test {}; TEST_F(PatchSetPickApplyTest, EmptyFilePatchHunks) { { - constexpr absl::string_view patch_contents = // + constexpr std::string_view patch_contents = // "diff -u /dev/null local/path/to/file1.txt\n" "--- foo/bar.txt\t2020-03-30\n" "+++ foo/bar-formatted.txt\t2020-03-30\n"; @@ -2226,7 +2225,7 @@ TEST_F(PatchSetPickApplyTest, EmptyFilePatchHunks) { TEST_F(PatchSetPickApplyTest, MultipleEmptyFilePatchHunks) { { - constexpr absl::string_view patch_contents = // + constexpr std::string_view patch_contents = // "diff -u /dev/null local/path/to/file1.txt\n" "--- foo/bar.txt\t2020-03-30\n" "+++ foo/bar-formatted.txt\t2020-03-30\n" @@ -2254,7 +2253,7 @@ TEST_F(PatchSetPickApplyTest, MultipleEmptyFilePatchHunks) { TEST_F(PatchSetPickApplyTest, MultipleNonEmptyFilePatchHunks) { { - constexpr absl::string_view patch_contents = // + constexpr std::string_view patch_contents = // "diff -u /dev/null local/path/to/file1.txt\n" "--- foo/bar.txt\t2020-03-30\n" "+++ foo/bar-formatted.txt\t2020-03-30\n" @@ -2290,7 +2289,7 @@ TEST_F(PatchSetPickApplyTest, MultipleNonEmptyFilePatchHunks) { TEST_F(PatchSetPickApplyTest, FirstFilePatchOutOfOrder) { { - constexpr absl::string_view patch_contents = // + constexpr std::string_view patch_contents = // "diff -u /dev/null local/path/to/file1.txt\n" "--- foo/bar.txt\t2020-03-30\n" "+++ foo/bar-formatted.txt\t2020-03-30\n" diff --git a/verible/common/strings/position.cc b/verible/common/strings/position.cc index a23a874da..9bfcf50f4 100644 --- a/verible/common/strings/position.cc +++ b/verible/common/strings/position.cc @@ -14,14 +14,14 @@ #include "verible/common/strings/position.h" -#include "absl/strings/string_view.h" +#include namespace verible { int AdvancingTextNewColumnPosition(int old_column_position, - absl::string_view advancing_text) { + std::string_view advancing_text) { const auto last_newline = advancing_text.find_last_of('\n'); - if (last_newline == absl::string_view::npos) { + if (last_newline == std::string_view::npos) { // No newlines, so treat every character as one column position, // even tabs. return old_column_position + advancing_text.length(); diff --git a/verible/common/strings/position.h b/verible/common/strings/position.h index cee237e25..727e215f2 100644 --- a/verible/common/strings/position.h +++ b/verible/common/strings/position.h @@ -16,8 +16,8 @@ #define VERIBLE_COMMON_STRINGS_POSITION_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/util/interval-set.h" #include "verible/common/util/interval.h" @@ -28,7 +28,7 @@ namespace verible { // resets the column position back to zero. All non-newline characters count as // one space. int AdvancingTextNewColumnPosition(int old_column_position, - absl::string_view advancing_text); + std::string_view advancing_text); // Collection of ranges of byte offsets. // Intentionally defining a class instead of merely typedef-ing to diff --git a/verible/common/strings/position_test.cc b/verible/common/strings/position_test.cc index d6206d6a0..5b7b0ec7f 100644 --- a/verible/common/strings/position_test.cc +++ b/verible/common/strings/position_test.cc @@ -14,58 +14,59 @@ #include "verible/common/strings/position.h" -#include "absl/strings/string_view.h" +#include + #include "gtest/gtest.h" namespace verible { namespace { TEST(AdvancingTextNewColumnPositionTest, EmptyString) { - const absl::string_view text; + const std::string_view text; EXPECT_EQ(AdvancingTextNewColumnPosition(0, text), 0); EXPECT_EQ(AdvancingTextNewColumnPosition(1, text), 1); EXPECT_EQ(AdvancingTextNewColumnPosition(8, text), 8); } TEST(AdvancingTextNewColumnPositionTest, OneChar) { - const absl::string_view text("x"); + const std::string_view text("x"); EXPECT_EQ(AdvancingTextNewColumnPosition(0, text), 1); EXPECT_EQ(AdvancingTextNewColumnPosition(1, text), 2); EXPECT_EQ(AdvancingTextNewColumnPosition(8, text), 9); } TEST(AdvancingTextNewColumnPositionTest, MultiChar) { - const absl::string_view text("12345"); + const std::string_view text("12345"); EXPECT_EQ(AdvancingTextNewColumnPosition(0, text), 5); EXPECT_EQ(AdvancingTextNewColumnPosition(4, text), 9); } TEST(AdvancingTextNewColumnPositionTest, NewlineOnly) { - const absl::string_view text("\n"); + const std::string_view text("\n"); EXPECT_EQ(AdvancingTextNewColumnPosition(0, text), 0); EXPECT_EQ(AdvancingTextNewColumnPosition(4, text), 0); } TEST(AdvancingTextNewColumnPositionTest, EndsWithNewline) { - const absl::string_view text("asdfasdf\n"); + const std::string_view text("asdfasdf\n"); EXPECT_EQ(AdvancingTextNewColumnPosition(0, text), 0); EXPECT_EQ(AdvancingTextNewColumnPosition(77, text), 0); } TEST(AdvancingTextNewColumnPositionTest, StartsWithNewline) { - const absl::string_view text("\nasdf"); + const std::string_view text("\nasdf"); EXPECT_EQ(AdvancingTextNewColumnPosition(0, text), 4); EXPECT_EQ(AdvancingTextNewColumnPosition(7, text), 4); } TEST(AdvancingTextNewColumnPositionTest, MultipleNewlines) { - const absl::string_view text("as\ndfasdf\n"); + const std::string_view text("as\ndfasdf\n"); EXPECT_EQ(AdvancingTextNewColumnPosition(0, text), 0); EXPECT_EQ(AdvancingTextNewColumnPosition(77, text), 0); } TEST(AdvancingTextNewColumnPositionTest, NonNewlinesAfterMultipleNewlines) { - const absl::string_view text("as\ndfasdf\nqwerty"); + const std::string_view text("as\ndfasdf\nqwerty"); EXPECT_EQ(AdvancingTextNewColumnPosition(0, text), 6); EXPECT_EQ(AdvancingTextNewColumnPosition(11, text), 6); } diff --git a/verible/common/strings/random.cc b/verible/common/strings/random.cc index c6c45a380..0632d07df 100644 --- a/verible/common/strings/random.cc +++ b/verible/common/strings/random.cc @@ -15,8 +15,8 @@ #include "verible/common/strings/random.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/util/interval-set.h" #include "verible/common/util/iterator-range.h" #include "verible/common/util/logging.h" @@ -36,7 +36,7 @@ char RandomAlphaNumChar() { return generator(); } -std::string RandomEqualLengthIdentifier(absl::string_view input) { +std::string RandomEqualLengthIdentifier(std::string_view input) { CHECK(!input.empty()); std::string s(input.length(), '?'); s.front() = RandomAlphaChar(); diff --git a/verible/common/strings/random.h b/verible/common/strings/random.h index 4276e6a65..9e4b7cd4c 100644 --- a/verible/common/strings/random.h +++ b/verible/common/strings/random.h @@ -16,8 +16,7 @@ #define VERIBLE_COMMON_STRINGS_RANDOM_H_ #include - -#include "absl/strings/string_view.h" +#include namespace verible { @@ -28,7 +27,7 @@ char RandomAlphaChar(); char RandomAlphaNumChar(); // Returns an identifier ([alpha][alnum]*) of equal length to input. -std::string RandomEqualLengthIdentifier(absl::string_view input); +std::string RandomEqualLengthIdentifier(std::string_view input); } // namespace verible diff --git a/verible/common/strings/range.cc b/verible/common/strings/range.cc index 23322fe37..3c8bb2787 100644 --- a/verible/common/strings/range.cc +++ b/verible/common/strings/range.cc @@ -15,24 +15,23 @@ #include "verible/common/strings/range.h" #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/util/logging.h" #include "verible/common/util/range.h" namespace verible { -absl::string_view make_string_view_range( - absl::string_view::const_iterator begin, - absl::string_view::const_iterator end) { +std::string_view make_string_view_range(std::string_view::const_iterator begin, + std::string_view::const_iterator end) { const int length = std::distance(begin, end); CHECK_GE(length, 0) << "Malformed string bounds."; - return absl::string_view(&*begin, length); + return std::string_view(&*begin, length); } -std::pair SubstringOffsets(absl::string_view substring, - absl::string_view superstring) { +std::pair SubstringOffsets(std::string_view substring, + std::string_view superstring) { return SubRangeIndices(substring, superstring); } diff --git a/verible/common/strings/range.h b/verible/common/strings/range.h index b5dad6194..d0e5cfce0 100644 --- a/verible/common/strings/range.h +++ b/verible/common/strings/range.h @@ -15,24 +15,22 @@ #ifndef VERIBLE_COMMON_STRINGS_RANGE_H_ #define VERIBLE_COMMON_STRINGS_RANGE_H_ +#include #include -#include "absl/strings/string_view.h" - namespace verible { // Construct a string_view from two end-points. // string_view lacks the two-iterator constructor that (iterator) ranges and // containers do. // Note, this can go with c++20 built-in string_view constructor. -absl::string_view make_string_view_range( - absl::string_view::const_iterator begin, - absl::string_view::const_iterator end); +std::string_view make_string_view_range(std::string_view::const_iterator begin, + std::string_view::const_iterator end); // Returns [x,y] where superstring.substr(x, y-x) == substring. // Precondition: substring must be a sub-range of superstring. -std::pair SubstringOffsets(absl::string_view substring, - absl::string_view superstring); +std::pair SubstringOffsets(std::string_view substring, + std::string_view superstring); } // namespace verible diff --git a/verible/common/strings/range_test.cc b/verible/common/strings/range_test.cc index c34bc4611..8ccec1e06 100644 --- a/verible/common/strings/range_test.cc +++ b/verible/common/strings/range_test.cc @@ -15,9 +15,9 @@ #include "verible/common/strings/range.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/util/range.h" @@ -25,38 +25,38 @@ namespace verible { namespace { TEST(MakeStringViewRangeTest, Empty) { - absl::string_view text; + std::string_view text; auto copy_view = make_string_view_range(text.begin(), text.end()); EXPECT_TRUE(BoundsEqual(copy_view, text)); } TEST(MakeStringViewRangeTest, NonEmpty) { - absl::string_view text("I'm not empty!!!!"); + std::string_view text("I'm not empty!!!!"); auto copy_view = make_string_view_range(text.begin(), text.end()); EXPECT_TRUE(BoundsEqual(copy_view, text)); } TEST(MakeStringViewRangeTest, BadRange) { - absl::string_view text("backwards"); + std::string_view text("backwards"); EXPECT_DEATH(make_string_view_range(text.end(), text.begin()), "Malformed"); } using IntPair = std::pair; TEST(ByteOffsetRangeTest, EmptyInEmpty) { - const absl::string_view superstring(""); // NOLINT + const std::string_view superstring(""); // NOLINT const auto substring = superstring; EXPECT_EQ(SubstringOffsets(substring, superstring), IntPair(0, 0)); } TEST(ByteOffsetRangeTest, EmptyInNullptrEmpty) { - const absl::string_view superstring; // default constructor init with nullptr + const std::string_view superstring; // default constructor init with nullptr const auto substring = superstring; EXPECT_EQ(SubstringOffsets(substring, superstring), IntPair(0, 0)); } TEST(ByteOffsetRangeTest, RangeInvariant) { - const absl::string_view superstring("xxxxxxxx"); + const std::string_view superstring("xxxxxxxx"); for (size_t i = 0; i < superstring.length(); ++i) { for (size_t j = i; j < superstring.length(); ++j) { const auto substring = superstring.substr(i, j - i); @@ -68,7 +68,7 @@ TEST(ByteOffsetRangeTest, RangeInvariant) { // Tests that swapping substring with superstring fails. TEST(ByteOffsetRangeTest, InsideOut) { - const absl::string_view superstring("yyyyyyy"); + const std::string_view superstring("yyyyyyy"); for (size_t i = 0; i < superstring.length(); ++i) { for (size_t j = i; j < superstring.length(); ++j) { const auto substring = superstring.substr(i, j - i); @@ -83,7 +83,7 @@ TEST(ByteOffsetRangeTest, InsideOut) { } TEST(ByteOffsetRangeTest, PartialOverlap) { - const absl::string_view superstring("zzzz"); + const std::string_view superstring("zzzz"); for (size_t i = 0; i < superstring.length(); ++i) { for (size_t j = 1; j < superstring.length(); ++j) { const auto left = superstring.substr(0, i); diff --git a/verible/common/strings/rebase.cc b/verible/common/strings/rebase.cc index 56724d42c..d4ebc8dc5 100644 --- a/verible/common/strings/rebase.cc +++ b/verible/common/strings/rebase.cc @@ -14,19 +14,20 @@ #include "verible/common/strings/rebase.h" -#include "absl/strings/string_view.h" +#include + #include "verible/common/util/logging.h" namespace verible { -void RebaseStringView(absl::string_view *src, absl::string_view dest) { +void RebaseStringView(std::string_view *src, std::string_view dest) { CHECK_EQ(*src, dest) << "RebaseStringView() is only valid when the " "new text referenced matches the old text."; *src = dest; } -void RebaseStringView(absl::string_view *src, const char *dest) { - RebaseStringView(src, absl::string_view(dest, src->length())); +void RebaseStringView(std::string_view *src, const char *dest) { + RebaseStringView(src, std::string_view(dest, src->length())); } } // namespace verible diff --git a/verible/common/strings/rebase.h b/verible/common/strings/rebase.h index 44dcdf1c9..1cc853980 100644 --- a/verible/common/strings/rebase.h +++ b/verible/common/strings/rebase.h @@ -15,7 +15,7 @@ #ifndef VERIBLE_COMMON_STRINGS_REBASE_H_ #define VERIBLE_COMMON_STRINGS_REBASE_H_ -#include "absl/strings/string_view.h" +#include namespace verible { @@ -26,13 +26,13 @@ namespace verible { // This is a potentially dangerous operation, which can be validated // using a combination of object lifetime management and range-checking. // It is the caller's responsibility that it points to valid memory. -void RebaseStringView(absl::string_view *src, absl::string_view dest); +void RebaseStringView(std::string_view *src, std::string_view dest); // This overload assumes that the string of interest from other has the // same length as the current string_view. // string_view::iterator happens to be const char*, but do not rely on that // fact as it can be implementation-dependent. -void RebaseStringView(absl::string_view *src, const char *dest); +void RebaseStringView(std::string_view *src, const char *dest); } // namespace verible diff --git a/verible/common/strings/rebase_test.cc b/verible/common/strings/rebase_test.cc index c64dc1b4c..ed78d8b9f 100644 --- a/verible/common/strings/rebase_test.cc +++ b/verible/common/strings/rebase_test.cc @@ -17,8 +17,8 @@ #include "verible/common/strings/rebase.h" #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/util/range.h" @@ -34,8 +34,8 @@ TEST(RebaseStringViewTest, EmptyStringsZeroOffset) { substr.resize(0); // Force empty string such as 'text' but memory space ASSERT_NE(text.c_str(), substr.c_str()) << "Mismatch in memory assumption"; - absl::string_view text_view(text); - const absl::string_view substr_view(substr); + std::string_view text_view(text); + const std::string_view substr_view(substr); EXPECT_FALSE(BoundsEqual(text_view, substr_view)); RebaseStringView(&text_view, substr); EXPECT_TRUE(BoundsEqual(text_view, substr_view)); @@ -45,8 +45,8 @@ TEST(RebaseStringViewTest, EmptyStringsZeroOffset) { TEST(RebaseStringViewTest, IdenticalCopy) { const std::string text = "hello"; const std::string substr = "hello"; // different memory space - absl::string_view text_view(text); - const absl::string_view substr_view(substr); + std::string_view text_view(text); + const std::string_view substr_view(substr); EXPECT_FALSE(BoundsEqual(text_view, substr_view)); RebaseStringView(&text_view, substr); EXPECT_TRUE(BoundsEqual(text_view, substr_view)); @@ -54,27 +54,27 @@ TEST(RebaseStringViewTest, IdenticalCopy) { // Test that substring mismatch between new and old is checked. TEST(RebaseStringViewDeathTest, SubstringMismatch) { - const absl::string_view text = "hell0"; - const absl::string_view substr = "hello"; - absl::string_view text_view(text); + const std::string_view text = "hell0"; + const std::string_view substr = "hello"; + std::string_view text_view(text); EXPECT_DEATH(RebaseStringView(&text_view, substr), "only valid when the new text referenced matches the old text"); } TEST(RebaseStringViewDeathTest, SubstringMismatch2) { - const absl::string_view text = "hello"; - const absl::string_view substr = "Hello"; - absl::string_view text_view(text); + const std::string_view text = "hello"; + const std::string_view substr = "Hello"; + std::string_view text_view(text); EXPECT_DEATH(RebaseStringView(&text_view, substr), "only valid when the new text referenced matches the old text"); } // Test that substring in the middle of old string is rebased correctly. TEST(RebaseStringViewTest, NewSubstringNotAtFront) { - const absl::string_view text = "hello"; - const absl::string_view new_base = "xxxhelloyyy"; - const absl::string_view new_view(new_base.substr(3, 5)); - absl::string_view text_view(text); + const std::string_view text = "hello"; + const std::string_view new_base = "xxxhelloyyy"; + const std::string_view new_view(new_base.substr(3, 5)); + std::string_view text_view(text); EXPECT_FALSE(BoundsEqual(text_view, new_view)); RebaseStringView(&text_view, new_view); EXPECT_TRUE(BoundsEqual(text_view, new_view)); @@ -82,35 +82,35 @@ TEST(RebaseStringViewTest, NewSubstringNotAtFront) { // Test that substring in the middle of old string is rebased correctly. TEST(RebaseStringViewTest, UsingCharPointer) { - const absl::string_view text = "hello"; + const std::string_view text = "hello"; const char *new_base = "xxxhelloyyy"; const char *new_view_offset = new_base + 3; - absl::string_view text_view(text); + std::string_view text_view(text); RebaseStringView(&text_view, new_view_offset); // assume original length - const absl::string_view new_base_view(new_base); + const std::string_view new_base_view(new_base); EXPECT_TRUE(BoundsEqual(text_view, new_base_view.substr(3, 5))); } // Test integration with substr() function rebases correctly. TEST(RebaseStringViewTest, RelativeToOldBase) { - const absl::string_view full_text = "xxxxxxhelloyyyyy"; - absl::string_view substr = full_text.substr(6, 5); + const std::string_view full_text = "xxxxxxhelloyyyyy"; + std::string_view substr = full_text.substr(6, 5); EXPECT_EQ(substr, "hello"); - const absl::string_view new_base = "aahellobbb"; - const absl::string_view new_view(new_base.substr(2, substr.length())); + const std::string_view new_base = "aahellobbb"; + const std::string_view new_view(new_base.substr(2, substr.length())); RebaseStringView(&substr, new_view); EXPECT_TRUE(BoundsEqual(substr, new_view)); } // Test rebasing into middle of superstring. TEST(RebaseStringViewTest, MiddleOfSuperstring) { - const absl::string_view dest_text = "xxxxxxhell0yyyyy"; - const absl::string_view src_text = "ccchell0ddd"; + const std::string_view dest_text = "xxxxxxhell0yyyyy"; + const std::string_view src_text = "ccchell0ddd"; const int dest_offset = 6; - absl::string_view src_substr(src_text.substr(3, 5)); + std::string_view src_substr(src_text.substr(3, 5)); EXPECT_EQ(src_substr, "hell0"); // src_text[3] lines up with dest_text[6]. - const absl::string_view dest_view( + const std::string_view dest_view( dest_text.substr(dest_offset, src_substr.length())); RebaseStringView(&src_substr, dest_view); EXPECT_TRUE(BoundsEqual(src_substr, dest_view)); @@ -118,13 +118,13 @@ TEST(RebaseStringViewTest, MiddleOfSuperstring) { // Test rebasing into prefix superstring. TEST(RebaseStringViewTest, PrefixSuperstring) { - const absl::string_view dest_text = "xxxhell0yyyyyzzzzzzz"; - const absl::string_view src_text = "ccchell0ddd"; + const std::string_view dest_text = "xxxhell0yyyyyzzzzzzz"; + const std::string_view src_text = "ccchell0ddd"; const int dest_offset = 3; - absl::string_view src_substr = src_text.substr(3, 5); + std::string_view src_substr = src_text.substr(3, 5); EXPECT_EQ(src_substr, "hell0"); // src_text[3] lines up with dest_text[3]. - const absl::string_view dest_view( + const std::string_view dest_view( dest_text.substr(dest_offset, src_substr.length())); RebaseStringView(&src_substr, dest_view); EXPECT_TRUE(BoundsEqual(src_substr, dest_view)); diff --git a/verible/common/strings/split.cc b/verible/common/strings/split.cc index d8194762a..36e943beb 100644 --- a/verible/common/strings/split.cc +++ b/verible/common/strings/split.cc @@ -15,17 +15,16 @@ #include "verible/common/strings/split.h" #include +#include #include #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" namespace verible { -std::vector SplitLines(absl::string_view text) { +std::vector SplitLines(std::string_view text) { if (text.empty()) return {}; - std::vector lines( - absl::StrSplit(text, absl::ByChar('\n'))); + std::vector lines(absl::StrSplit(text, absl::ByChar('\n'))); // If text ends cleanly with a \n, omit the last blank split, // otherwise treat it as if the trailing text ends with a \n. if (text.back() == '\n') { @@ -40,9 +39,9 @@ class AfterCharDelimiter { public: explicit AfterCharDelimiter(char delimiter) : delimiter_(delimiter) {} - absl::string_view Find(absl::string_view text, size_t pos) const { + std::string_view Find(std::string_view text, size_t pos) const { const size_t found_pos = text.find(delimiter_, pos); - if (found_pos == absl::string_view::npos) { + if (found_pos == std::string_view::npos) { return {text.data() + text.size(), 0}; } return text.substr(found_pos + 1, 0); @@ -52,8 +51,8 @@ class AfterCharDelimiter { const char delimiter_; }; -std::vector SplitLinesKeepLineTerminator( - absl::string_view text) { +std::vector SplitLinesKeepLineTerminator( + std::string_view text) { if (text.empty()) return {}; return absl::StrSplit(text, AfterCharDelimiter('\n')); } diff --git a/verible/common/strings/split.h b/verible/common/strings/split.h index 8a20064ad..da88e527b 100644 --- a/verible/common/strings/split.h +++ b/verible/common/strings/split.h @@ -17,19 +17,18 @@ #include #include +#include #include -#include "absl/strings/string_view.h" - namespace verible { namespace internal { -inline size_t DelimiterSize(absl::string_view str) { return str.length(); } +inline size_t DelimiterSize(std::string_view str) { return str.length(); } inline size_t DelimiterSize(char c) { return 1; } } // namespace internal // Generator function that returns substrings between delimiters. -// Behaves like a std::function. +// Behaves like a std::function. // The delimiter could be different with each call. // This can serve as a quick lexer or tokenizer for some applications. // Compared to absl::StrSplit, the space needed to store results one at a time @@ -38,14 +37,14 @@ inline size_t DelimiterSize(char c) { return 1; } // Example usage: // StringSpliterator gen("some, text, ..."); // do { -// absl::string_view token = gen(','); +// std::string_view token = gen(','); // // do something with token // } while (gen); // // See also MakeStringSpliterator(). class StringSpliterator { public: - explicit StringSpliterator(absl::string_view original) + explicit StringSpliterator(std::string_view original) : remainder_(original) {} // Copy-able, movable, assignable. @@ -65,16 +64,16 @@ class StringSpliterator { // Delimiter type D can be a string_view or char (overloads of // string_view::find()). // The heterogenous operator() lets objects of this type work as a - // std::function and - // std::function. + // std::function and + // std::function. template - absl::string_view operator()(const D delimiter) { + std::string_view operator()(const D delimiter) { const size_t pos = remainder_.find(delimiter); - if (pos == absl::string_view::npos) { + if (pos == std::string_view::npos) { // This is the last partition. // If the remainder_ was already empty, this will continue // to return empty strings. - const absl::string_view result(remainder_); + const std::string_view result(remainder_); remainder_.remove_prefix(remainder_.length()); // empty end_ = true; return result; @@ -82,19 +81,19 @@ class StringSpliterator { // More text follows after the next occurrence of the delimiter. // If the text ends with the delimiter, then the last string // returned before the end() will be empty. - const absl::string_view result(remainder_.substr(0, pos)); + const std::string_view result(remainder_.substr(0, pos)); // Skip over the delimiter. remainder_.remove_prefix(pos + internal::DelimiterSize(delimiter)); return result; } // Returns the un-scanned portion of text. - absl::string_view Remainder() const { return remainder_; } + std::string_view Remainder() const { return remainder_; } private: // The remaining substring that has not been consumed. // With each call to operator(), this shrinks from the front. - absl::string_view remainder_; + std::string_view remainder_; // A split that fails to find a delimiter still returns one element, // the original string, thus end_ should always be initialized to false. @@ -104,8 +103,8 @@ class StringSpliterator { // Convenience function that returns a string_view generator using // StringSpliterator with the same delimiter on every split. template -std::function MakeStringSpliterator( - absl::string_view original, D delimiter) { +std::function MakeStringSpliterator( + std::string_view original, D delimiter) { // note: in-lambda initializers require c++14 auto splitter = StringSpliterator(original); return [=]() mutable /* splitter */ { return splitter(delimiter); }; @@ -115,14 +114,14 @@ std::function MakeStringSpliterator( // Each line in the returned vector excludes the trailing \n. // If original text did not terminate with a \n, interpret the final partial // line as a whole line. -std::vector SplitLines(absl::string_view text); +std::vector SplitLines(std::string_view text); // Returns line-based view of original text. Keeps the trailing \n. // Lines in the returned vector include the trailing \n. // If original text did not terminate with a \n, interpret the final partial // line as a whole line. -std::vector SplitLinesKeepLineTerminator( - absl::string_view text); +std::vector SplitLinesKeepLineTerminator( + std::string_view text); } // namespace verible diff --git a/verible/common/strings/split_test.cc b/verible/common/strings/split_test.cc index 81d753838..02552ca2d 100644 --- a/verible/common/strings/split_test.cc +++ b/verible/common/strings/split_test.cc @@ -15,10 +15,10 @@ #include "verible/common/strings/split.h" #include +#include #include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/strings/range.h" @@ -30,9 +30,9 @@ namespace { using ::testing::ElementsAre; static void AcceptFunctionChar( - const std::function &func) {} + const std::function &func) {} static void AcceptFunctionStringView( - const std::function &func) {} + const std::function &func) {} // This tests that StringSpliterator can be passed to a std::function. TEST(StringSpliteratorTest, CompileTimeAsFunction) { @@ -42,7 +42,7 @@ TEST(StringSpliteratorTest, CompileTimeAsFunction) { } TEST(StringSpliteratorTest, EmptyOriginal) { - constexpr absl::string_view empty; + constexpr std::string_view empty; StringSpliterator splitter(empty); EXPECT_TRUE(splitter); EXPECT_TRUE(BoundsEqual(splitter.Remainder(), empty)); @@ -56,7 +56,7 @@ TEST(StringSpliteratorTest, EmptyOriginal) { } TEST(StringSpliteratorTest, MyGodItsFullOfStars) { - constexpr absl::string_view stars("***"); + constexpr std::string_view stars("***"); const auto gen = MakeStringSpliterator(stars, '*'); // char delimiter EXPECT_TRUE(BoundsEqual(gen(), stars.substr(0, 0))); EXPECT_TRUE(BoundsEqual(gen(), stars.substr(1, 0))); @@ -65,7 +65,7 @@ TEST(StringSpliteratorTest, MyGodItsFullOfStars) { } TEST(StringSpliteratorTest, StringDelimiter) { - constexpr absl::string_view stars("xxx"); + constexpr std::string_view stars("xxx"); const auto gen = MakeStringSpliterator(stars, "x"); // string delimiter EXPECT_TRUE(BoundsEqual(gen(), stars.substr(0, 0))); EXPECT_TRUE(BoundsEqual(gen(), stars.substr(1, 0))); @@ -74,12 +74,12 @@ TEST(StringSpliteratorTest, StringDelimiter) { } TEST(StringSpliteratorTest, StarsAndStripes) { - constexpr absl::string_view space("==*===*=*===="); + constexpr std::string_view space("==*===*=*===="); StringSpliterator splitter(space); EXPECT_TRUE(splitter); EXPECT_TRUE(BoundsEqual(splitter.Remainder(), space)); - absl::string_view token = splitter('*'); + std::string_view token = splitter('*'); EXPECT_TRUE(splitter); EXPECT_TRUE(BoundsEqual(token, space.substr(0, 2))) << " got \"" << token << '"'; @@ -105,7 +105,7 @@ TEST(StringSpliteratorTest, StarsAndStripes) { } TEST(StringSpliteratorTest, InSpaceNoOneCanHearYouScream) { - constexpr absl::string_view space(" * * * "); + constexpr std::string_view space(" * * * "); const auto gen = MakeStringSpliterator(space, '*'); // char delimiter // expect to match the spaces between the stars EXPECT_TRUE(BoundsEqual(gen(), space.substr(0, 2))); @@ -115,7 +115,7 @@ TEST(StringSpliteratorTest, InSpaceNoOneCanHearYouScream) { } TEST(StringSpliteratorTest, CommaBabyCommaOverBaby) { - constexpr absl::string_view csv_row("abcd,,efg,hi"); + constexpr std::string_view csv_row("abcd,,efg,hi"); const auto gen = MakeStringSpliterator(csv_row, ","); // string delimiter // expect to match the spaces between the stars EXPECT_TRUE(BoundsEqual(gen(), csv_row.substr(0, 4))); @@ -128,7 +128,7 @@ using IntPair = std::pair; // For testing purposes, directly compare the substring indices, // which is a stronger check than string contents comparison. -static std::vector SplitLinesToOffsets(absl::string_view text) { +static std::vector SplitLinesToOffsets(std::string_view text) { std::vector offsets; for (const auto &line : SplitLines(text)) { offsets.push_back(SubstringOffsets(line, text)); @@ -137,46 +137,46 @@ static std::vector SplitLinesToOffsets(absl::string_view text) { } TEST(SplitLinesTest, Empty) { - constexpr absl::string_view text; + constexpr std::string_view text; const auto lines = SplitLines(text); EXPECT_TRUE(lines.empty()); } TEST(SplitLinesTest, OneSpace) { - constexpr absl::string_view text(" "); + constexpr std::string_view text(" "); EXPECT_THAT(SplitLines(text), ElementsAre(" ")); EXPECT_THAT(SplitLinesToOffsets(text), ElementsAre(IntPair(0, 1))); } TEST(SplitLinesTest, OneBlankLine) { - constexpr absl::string_view text("\n"); + constexpr std::string_view text("\n"); EXPECT_THAT(SplitLines(text), ElementsAre("")); EXPECT_THAT(SplitLinesToOffsets(text), ElementsAre(IntPair(0, 0))); } TEST(SplitLinesTest, BlankLines) { - constexpr absl::string_view text("\n\n\n"); + constexpr std::string_view text("\n\n\n"); EXPECT_THAT(SplitLines(text), ElementsAre("", "", "")); EXPECT_THAT(SplitLinesToOffsets(text), ElementsAre(IntPair(0, 0), IntPair(1, 1), IntPair(2, 2))); } TEST(SplitLinesTest, NonBlankLines) { - constexpr absl::string_view text("a\nbc\ndef\n"); + constexpr std::string_view text("a\nbc\ndef\n"); EXPECT_THAT(SplitLines(text), ElementsAre("a", "bc", "def")); EXPECT_THAT(SplitLinesToOffsets(text), ElementsAre(IntPair(0, 1), IntPair(2, 4), IntPair(5, 8))); } TEST(SplitLinesTest, NonBlankLinesUnterminated) { - constexpr absl::string_view text("abc\nde\nf"); // no \n at the end + constexpr std::string_view text("abc\nde\nf"); // no \n at the end EXPECT_THAT(SplitLines(text), ElementsAre("abc", "de", "f")); EXPECT_THAT(SplitLinesToOffsets(text), ElementsAre(IntPair(0, 3), IntPair(4, 6), IntPair(7, 8))); } static std::vector SplitLinesKeepLineTerminatorToOffsets( - absl::string_view text) { + std::string_view text) { std::vector offsets; for (const auto &line : SplitLinesKeepLineTerminator(text)) { offsets.push_back(SubstringOffsets(line, text)); @@ -185,27 +185,27 @@ static std::vector SplitLinesKeepLineTerminatorToOffsets( } TEST(SplitLinesKeepLineTerminatorTest, Empty) { - constexpr absl::string_view text; + constexpr std::string_view text; const auto lines = SplitLinesKeepLineTerminator(text); EXPECT_TRUE(lines.empty()); } TEST(SplitLinesKeepLineTerminatorTest, OneSpace) { - constexpr absl::string_view text(" "); + constexpr std::string_view text(" "); EXPECT_THAT(SplitLinesKeepLineTerminator(text), ElementsAre(" ")); EXPECT_THAT(SplitLinesKeepLineTerminatorToOffsets(text), ElementsAre(IntPair(0, 1))); } TEST(SplitLinesKeepLineTerminatorTest, OneBlankLine) { - constexpr absl::string_view text("\n"); + constexpr std::string_view text("\n"); EXPECT_THAT(SplitLinesKeepLineTerminator(text), ElementsAre("\n")); EXPECT_THAT(SplitLinesKeepLineTerminatorToOffsets(text), ElementsAre(IntPair(0, 1))); } TEST(SplitLinesKeepLineTerminatorTest, BlankLines) { - constexpr absl::string_view text("\n\n\n"); + constexpr std::string_view text("\n\n\n"); EXPECT_THAT(SplitLinesKeepLineTerminator(text), ElementsAre("\n", "\n", "\n")); EXPECT_THAT(SplitLinesKeepLineTerminatorToOffsets(text), @@ -213,7 +213,7 @@ TEST(SplitLinesKeepLineTerminatorTest, BlankLines) { } TEST(SplitLinesKeepLineTerminatorTest, NonBlankLines) { - constexpr absl::string_view text("a\nbc\ndef\n"); + constexpr std::string_view text("a\nbc\ndef\n"); EXPECT_THAT(SplitLinesKeepLineTerminator(text), ElementsAre("a\n", "bc\n", "def\n")); EXPECT_THAT(SplitLinesKeepLineTerminatorToOffsets(text), @@ -221,7 +221,7 @@ TEST(SplitLinesKeepLineTerminatorTest, NonBlankLines) { } TEST(SplitLinesKeepLineTerminatorTest, NonBlankLinesUnterminated) { - constexpr absl::string_view text("abc\nde\nf"); // no \n at the end + constexpr std::string_view text("abc\nde\nf"); // no \n at the end EXPECT_THAT(SplitLinesKeepLineTerminator(text), ElementsAre("abc\n", "de\n", "f")); EXPECT_THAT(SplitLinesKeepLineTerminatorToOffsets(text), diff --git a/verible/common/strings/string-memory-map.h b/verible/common/strings/string-memory-map.h index b60c007f1..cb532305b 100644 --- a/verible/common/strings/string-memory-map.h +++ b/verible/common/strings/string-memory-map.h @@ -15,9 +15,9 @@ #ifndef VERIBLE_COMMON_STRINGS_STRING_MEMORY_MAP_H_ #define VERIBLE_COMMON_STRINGS_STRING_MEMORY_MAP_H_ +#include #include -#include "absl/strings/string_view.h" #include "verible/common/strings/range.h" #include "verible/common/util/interval-map.h" #include "verible/common/util/interval-set.h" @@ -26,9 +26,9 @@ namespace verible { namespace internal { -inline std::pair -string_view_to_pair(absl::string_view sv) { +inline std::pair +string_view_to_pair(std::string_view sv) { return std::make_pair(sv.begin(), sv.end()); } } // namespace internal @@ -40,11 +40,11 @@ string_view_to_pair(absl::string_view sv) { // any of the referenced memory -- the user is responsible for maintaining // proper string lifetime, owning strings must outlive these objects. class StringViewSuperRangeMap { - using impl_type = DisjointIntervalSet; + using impl_type = DisjointIntervalSet; public: // This iterator dereferences to a std::pair of - // absl::string_view::const_iterator, which can be constructed into a + // std::string_view::const_iterator, which can be constructed into a // string_view. using const_iterator = impl_type::const_iterator; @@ -61,7 +61,7 @@ class StringViewSuperRangeMap { // Given a substring, return an iterator pointing to the superstring that // fully contains the substring, if it exists, else return end(). - const_iterator find(absl::string_view substring) const { + const_iterator find(std::string_view substring) const { return string_map_.find({substring.begin(), substring.end()}); } @@ -70,7 +70,7 @@ class StringViewSuperRangeMap { // Similar to find(), but asserts that a superstring range is found, // and converts the result directly to a string_view. - absl::string_view must_find(absl::string_view substring) const { + std::string_view must_find(std::string_view substring) const { const auto found(find(substring)); CHECK(found != string_map_.end()); return make_string_view_range(found->first, found->second); // superstring @@ -80,7 +80,7 @@ class StringViewSuperRangeMap { // inserted string range. This is suitable for string ranges that correspond // to allocated memory, because allocators only return non-overlapping memory // blocks. - const_iterator must_emplace(absl::string_view superstring) { + const_iterator must_emplace(std::string_view superstring) { return string_map_.must_emplace(superstring.begin(), superstring.end()); } @@ -105,9 +105,9 @@ class StringViewSuperRangeMap { // always return the same range for the same object. One way to ensure this is // to make the underlying storage a 'const std::string'. // -template +template class StringMemoryMap { - using key_type = absl::string_view::const_iterator; + using key_type = std::string_view::const_iterator; using map_type = DisjointIntervalMap; public: @@ -123,7 +123,7 @@ class StringMemoryMap { // Returns reference to the object in the set that owns the memory range of // string 's', or else nullptr if 's' does not fall entirely within one of the // intervals in the map. - const T *find(absl::string_view sv) const { + const T *find(std::string_view sv) const { const auto iter = memory_map_.find(internal::string_view_to_pair(sv)); if (iter == memory_map_.end()) return nullptr; return &iter->second; @@ -132,7 +132,7 @@ class StringMemoryMap { // Move-inserts an element into the set, keyed on the memory range owned // by the object. iterator insert(T &&t) { - const absl::string_view key = RangeOf(t); + const std::string_view key = RangeOf(t); return memory_map_.must_emplace(internal::string_view_to_pair(key), std::move(t)); } diff --git a/verible/common/strings/string-memory-map_test.cc b/verible/common/strings/string-memory-map_test.cc index 9023f5fa2..3cf0e92e8 100644 --- a/verible/common/strings/string-memory-map_test.cc +++ b/verible/common/strings/string-memory-map_test.cc @@ -17,8 +17,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/strings/range.h" #include "verible/common/util/logging.h" @@ -28,7 +28,7 @@ namespace verible { namespace { static void ForAllSubstringRanges( - absl::string_view sv, const std::function &func) { + std::string_view sv, const std::function &func) { for (auto start_iter = sv.begin(); start_iter != sv.end(); ++start_iter) { for (auto end_iter = start_iter; end_iter != sv.end(); ++end_iter) { if (start_iter == end_iter) continue; // skip empty ranges @@ -44,7 +44,7 @@ TEST(StringViewSuperRangeMapTest, Empty) { TEST(StringViewSuperRangeMapTest, OneString) { StringViewSuperRangeMap svmap; - constexpr absl::string_view text("text"); + constexpr std::string_view text("text"); const auto new_iter = svmap.must_emplace(text); EXPECT_NE(new_iter, svmap.end()); EXPECT_FALSE(svmap.empty()); @@ -52,35 +52,35 @@ TEST(StringViewSuperRangeMapTest, OneString) { make_string_view_range(new_iter->first, new_iter->second), text)); EXPECT_TRUE(BoundsEqual(svmap.must_find(text), text)); - ForAllSubstringRanges(text, [&svmap, text](absl::string_view subrange) { + ForAllSubstringRanges(text, [&svmap, text](std::string_view subrange) { EXPECT_TRUE(BoundsEqual(svmap.must_find(subrange), text)); }); } TEST(StringViewSuperRangeMapTest, Overlap) { StringViewSuperRangeMap svmap; - constexpr absl::string_view text("text"); + constexpr std::string_view text("text"); svmap.must_emplace(text); EXPECT_DEATH(svmap.must_emplace(text), "Failed to emplace"); } TEST(StringViewSuperRangeMapTest, OverlapSubstring) { StringViewSuperRangeMap svmap; - constexpr absl::string_view text("text"); + constexpr std::string_view text("text"); svmap.must_emplace(text); EXPECT_DEATH(svmap.must_emplace(text.substr(1)), "Failed to emplace"); } TEST(StringViewSuperRangeMapTest, SuperRangeNotInSet) { StringViewSuperRangeMap svmap; - constexpr absl::string_view text("text"); + constexpr std::string_view text("text"); svmap.must_emplace(text); - EXPECT_DEATH(svmap.must_find(absl::string_view("never-there")), ""); + EXPECT_DEATH(svmap.must_find(std::string_view("never-there")), ""); } TEST(StringViewSuperRangeMapTest, TwoStrings) { StringViewSuperRangeMap svmap; - constexpr absl::string_view text1("hello"), text2("world"); + constexpr std::string_view text1("hello"), text2("world"); { const auto new_iter = svmap.must_emplace(text1); EXPECT_NE(new_iter, svmap.end()); @@ -98,17 +98,17 @@ TEST(StringViewSuperRangeMapTest, TwoStrings) { EXPECT_TRUE(BoundsEqual(svmap.must_find(text2), text2)); } - ForAllSubstringRanges(text1, [&svmap, text1](absl::string_view subrange) { + ForAllSubstringRanges(text1, [&svmap, text1](std::string_view subrange) { EXPECT_TRUE(BoundsEqual(svmap.must_find(subrange), text1)); }); - ForAllSubstringRanges(text2, [&svmap, text2](absl::string_view subrange) { + ForAllSubstringRanges(text2, [&svmap, text2](std::string_view subrange) { EXPECT_TRUE(BoundsEqual(svmap.must_find(subrange), text2)); }); } TEST(StringViewSuperRangeMapTest, EraseString) { - constexpr absl::string_view text1("onestring"); - constexpr absl::string_view text2("another"); + constexpr std::string_view text1("onestring"); + constexpr std::string_view text2("another"); StringViewSuperRangeMap svmap; svmap.must_emplace(text1); svmap.must_emplace(text2); @@ -129,9 +129,9 @@ TEST(StringViewSuperRangeMapTest, EraseString) { } // Function to get the owned address range of the underlying string. -static absl::string_view StringViewKey( +static std::string_view StringViewKey( const std::unique_ptr &owned) { - return absl::string_view(*ABSL_DIE_IF_NULL(owned)); + return std::string_view(*ABSL_DIE_IF_NULL(owned)); } using StringSet = @@ -142,7 +142,7 @@ TEST(StringMemoryMapTest, EmptyOwnsNothing) { EXPECT_EQ(sset.find("not-owned-anywhere"), nullptr); } -static absl::string_view InsertStringCopy(StringSet *sset, const char *text) { +static std::string_view InsertStringCopy(StringSet *sset, const char *text) { const auto new_iter = sset->insert(std::make_unique(text)); // copy return make_string_view_range(new_iter->first.first, new_iter->first.second); @@ -150,13 +150,13 @@ static absl::string_view InsertStringCopy(StringSet *sset, const char *text) { TEST(StringMemoryMapTest, OneElement) { StringSet sset; - const absl::string_view sv(InsertStringCopy(&sset, "OWNED")); + const std::string_view sv(InsertStringCopy(&sset, "OWNED")); // Check all valid substring ranges - ForAllSubstringRanges(sv, [&sset, sv](absl::string_view subrange) { + ForAllSubstringRanges(sv, [&sset, sv](std::string_view subrange) { const auto *f = sset.find(subrange); ASSERT_NE(f, nullptr) << "subrange returned nullptr: " << subrange; - const absl::string_view fv(**f); + const std::string_view fv(**f); EXPECT_TRUE(BoundsEqual(fv, sv)) << "got: " << fv << " vs. " << sv; EXPECT_EQ(fv, "OWNED"); }); @@ -165,29 +165,29 @@ TEST(StringMemoryMapTest, OneElement) { TEST(StringMemoryMapTest, MultipleElements) { StringSet sset; // There's no telling where these allocated strings will reside in memory. - const absl::string_view sv1(InsertStringCopy(&sset, "AAA")); - const absl::string_view sv2(InsertStringCopy(&sset, "BBBB")); - const absl::string_view sv3(InsertStringCopy(&sset, "CCCCC")); + const std::string_view sv1(InsertStringCopy(&sset, "AAA")); + const std::string_view sv2(InsertStringCopy(&sset, "BBBB")); + const std::string_view sv3(InsertStringCopy(&sset, "CCCCC")); // Check all valid substring ranges - ForAllSubstringRanges(sv1, [&sset, sv1](absl::string_view subrange) { + ForAllSubstringRanges(sv1, [&sset, sv1](std::string_view subrange) { const auto *f = sset.find(subrange); ASSERT_NE(f, nullptr) << "subrange returned nullptr: " << subrange; - const absl::string_view fv(*ABSL_DIE_IF_NULL(*f)); + const std::string_view fv(*ABSL_DIE_IF_NULL(*f)); EXPECT_TRUE(BoundsEqual(fv, sv1)) << "got: " << fv << " vs. " << sv1; EXPECT_EQ(fv, "AAA"); }); - ForAllSubstringRanges(sv2, [&sset, sv2](absl::string_view subrange) { + ForAllSubstringRanges(sv2, [&sset, sv2](std::string_view subrange) { const auto *f = sset.find(subrange); ASSERT_NE(f, nullptr) << "subrange returned nullptr: " << subrange; - const absl::string_view fv(*ABSL_DIE_IF_NULL(*f)); + const std::string_view fv(*ABSL_DIE_IF_NULL(*f)); EXPECT_TRUE(BoundsEqual(fv, sv2)) << "got: " << fv << " vs. " << sv2; EXPECT_EQ(fv, "BBBB"); }); - ForAllSubstringRanges(sv3, [&sset, sv3](absl::string_view subrange) { + ForAllSubstringRanges(sv3, [&sset, sv3](std::string_view subrange) { const auto *f = sset.find(subrange); ASSERT_NE(f, nullptr) << "subrange returned nullptr: " << subrange; - const absl::string_view fv(*ABSL_DIE_IF_NULL(*f)); + const std::string_view fv(*ABSL_DIE_IF_NULL(*f)); EXPECT_TRUE(BoundsEqual(fv, sv3)) << "got: " << fv << " vs. " << sv3; EXPECT_EQ(fv, "CCCCC"); }); diff --git a/verible/common/strings/utf8.h b/verible/common/strings/utf8.h index e4ce34f9e..fcc5a1bd4 100644 --- a/verible/common/strings/utf8.h +++ b/verible/common/strings/utf8.h @@ -17,24 +17,23 @@ #include #include - -#include "absl/strings/string_view.h" +#include namespace verible { // Determine length in characters of an UTF8-encoded string. -inline int utf8_len(absl::string_view str) { +inline int utf8_len(std::string_view str) { return std::count_if(str.begin(), str.end(), [](char c) { return (c & 0xc0) != 0x80; }); } // Returns the substring starting from the given character // of the UTF8-encoded string. -inline absl::string_view utf8_substr(absl::string_view str, - size_t character_pos) { +inline std::string_view utf8_substr(std::string_view str, + size_t character_pos) { // Strategy: whenever we see a start of a utf8 codepoint bump the expected // remaining by number of expected bytes size_t remaining = character_pos; - absl::string_view::const_iterator it; + std::string_view::const_iterator it; for (it = str.begin(); remaining && it != str.end(); ++it, --remaining) { if ((*it & 0xE0) == 0xC0) { remaining += 1; @@ -47,11 +46,10 @@ inline absl::string_view utf8_substr(absl::string_view str, return str.substr(it - str.begin()); } -inline absl::string_view utf8_substr(absl::string_view str, - size_t character_pos, - size_t character_len) { - const absl::string_view prefix = utf8_substr(str, character_pos); - const absl::string_view chop_end = utf8_substr(prefix, character_len); +inline std::string_view utf8_substr(std::string_view str, size_t character_pos, + size_t character_len) { + const std::string_view prefix = utf8_substr(str, character_pos); + const std::string_view chop_end = utf8_substr(prefix, character_len); return {prefix.data(), prefix.length() - chop_end.length()}; } } // namespace verible diff --git a/verible/common/text/BUILD b/verible/common/text/BUILD index 2122be388..4629a21d2 100644 --- a/verible/common/text/BUILD +++ b/verible/common/text/BUILD @@ -27,7 +27,6 @@ cc_library( "//verible/common/util:logging", "//verible/common/util:range", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -49,7 +48,6 @@ cc_library( deps = [ ":token-info", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -60,7 +58,6 @@ cc_library( deps = [ ":token-info", "//verible/common/util:iterator-range", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -101,7 +98,6 @@ cc_test( deps = [ ":concrete-syntax-leaf", ":token-info", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -132,7 +128,6 @@ cc_library( "//verible/common/util:logging", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], ) @@ -144,7 +139,6 @@ cc_test( ":config-utils", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", "@re2", @@ -187,7 +181,6 @@ cc_test( ":concrete-syntax-tree", ":tree-builder-test-util", ":tree-compare", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -216,7 +209,6 @@ cc_test( ":syntax-tree-context", ":tree-builder-test-util", ":tree-context-visitor", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -240,7 +232,6 @@ cc_library( "//verible/common/util:value-saver", "@abseil-cpp//absl/log:check", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -255,7 +246,6 @@ cc_library( ":symbol", ":tree-utils", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -290,7 +280,6 @@ cc_library( "//verible/common/util:status-macros", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -307,7 +296,6 @@ cc_library( ":tree-builder-test-util", "//verible/common/util:logging", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -320,7 +308,6 @@ cc_library( "//verible/common/util:container-util", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -369,7 +356,6 @@ cc_test( "//verible/common/util:casts", "//verible/common/util:logging", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -398,7 +384,6 @@ cc_test( ":constants", ":token-info", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -411,7 +396,6 @@ cc_test( ":constants", ":token-info", ":token-info-json", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", "@nlohmann_json//:singleheader-json", @@ -424,7 +408,6 @@ cc_test( deps = [ ":token-info", ":token-info-test-util", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -439,7 +422,6 @@ cc_test( ":token-info", ":token-stream-view", "//verible/common/util:iterator-range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -477,7 +459,6 @@ cc_test( "//verible/common/util:range", "//verible/common/util:value-saver", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -505,7 +486,6 @@ cc_test( ":token-info", ":token-stream-view", ":tree-builder-test-util", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/common/text/concrete-syntax-leaf_test.cc b/verible/common/text/concrete-syntax-leaf_test.cc index 1cb288f0a..1c1e5c26f 100644 --- a/verible/common/text/concrete-syntax-leaf_test.cc +++ b/verible/common/text/concrete-syntax-leaf_test.cc @@ -16,7 +16,8 @@ #include "verible/common/text/concrete-syntax-leaf.h" -#include "absl/strings/string_view.h" +#include + #include "gtest/gtest.h" #include "verible/common/text/token-info.h" @@ -24,7 +25,7 @@ namespace verible { namespace { TEST(ValueSymbolTest, EqualityArity1Args) { - constexpr absl::string_view text("foo"); + constexpr std::string_view text("foo"); SyntaxTreeLeaf value1(10, text); TokenInfo info1(10, text); auto info2 = value1.get(); @@ -34,9 +35,9 @@ TEST(ValueSymbolTest, EqualityArity1Args) { TEST(ValueSymbolTest, InequalityDifferentStringLocations) { // Check that two tokens with the same text content but different // location are _not_ considered equal. - constexpr absl::string_view longtext("foofoo"); - constexpr absl::string_view first = longtext.substr(0, 3); - constexpr absl::string_view second = longtext.substr(3); + constexpr std::string_view longtext("foofoo"); + constexpr std::string_view first = longtext.substr(0, 3); + constexpr std::string_view second = longtext.substr(3); SyntaxTreeLeaf value1(10, first); TokenInfo info1(10, second); diff --git a/verible/common/text/config-utils.cc b/verible/common/text/config-utils.cc index 536e97192..d047de1bf 100644 --- a/verible/common/text/config-utils.cc +++ b/verible/common/text/config-utils.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -31,13 +32,12 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/util/logging.h" namespace verible { -using absl::string_view; using config::NVConfigSpec; +using std::string_view; // TODO(hzeller): consider using flex for a more readable tokenization that // can also much easier deal with whitespaces, strings etc. @@ -161,7 +161,7 @@ ConfigValueSetter SetStringOneOf(std::string* value, ConfigValueSetter SetNamedBits( uint32_t* value, - const std::vector& choices) { + const std::vector& choices) { CHECK(value) << "Must provide pointer to uint32_t to store."; CHECK_LE(choices.size(), 32) << "Too many choices for 32-bit bitmap"; return [value, choices](string_view v) { diff --git a/verible/common/text/config-utils.h b/verible/common/text/config-utils.h index a18d4ec34..1f40008bf 100644 --- a/verible/common/text/config-utils.h +++ b/verible/common/text/config-utils.h @@ -19,15 +19,15 @@ #include #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" namespace verible { namespace config { -using ConfigValueSetter = std::function; +using ConfigValueSetter = std::function; struct NVConfigSpec { const char *name; @@ -66,7 +66,7 @@ struct NVConfigSpec { // If none of the called setters returns an error (which otherwise is returned), // this function returns with an absl::OkStatus(). absl::Status ParseNameValues( - absl::string_view config_string, + std::string_view config_string, const std::initializer_list &spec); namespace config { @@ -85,7 +85,7 @@ ConfigValueSetter SetString(std::string *value); // set is provided as vector for simplicity and to allow the caller to // impose a particular importance order when returning an error. ConfigValueSetter SetStringOneOf(std::string *value, - const std::vector &allowed); + const std::vector &allowed); // Set a bitmap from the given values, a '|'-separated list of named bits // to be set. The bit-names provided in the configuration-string can come @@ -95,7 +95,7 @@ ConfigValueSetter SetStringOneOf(std::string *value, // named in choices[5] modifies (1<<5). Given the uint32 value, this allows // up to 32 choices. ConfigValueSetter SetNamedBits(uint32_t *value, - const std::vector &choices); + const std::vector &choices); // Set a Regex ConfigValueSetter SetRegex(std::unique_ptr *regex); diff --git a/verible/common/text/config-utils_test.cc b/verible/common/text/config-utils_test.cc index 9ebacf33e..8bb938267 100644 --- a/verible/common/text/config-utils_test.cc +++ b/verible/common/text/config-utils_test.cc @@ -17,12 +17,12 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "re2/re2.h" @@ -136,8 +136,8 @@ TEST(ConfigUtilsTest, ParseString) { } TEST(ConfigUtilsTest, ParseNamedBitmap) { - const std::vector kBitNames = {"ZERO", "ONE", "TWO"}; - const std::pair kTestCases[] = { + const std::vector kBitNames = {"ZERO", "ONE", "TWO"}; + const std::pair kTestCases[] = { {"baz:ONE", 1 << 1}, {"baz:", 0}, {"baz:ZERO|TWO", (1 << 0) | (1 << 2)}, diff --git a/verible/common/text/macro-definition.cc b/verible/common/text/macro-definition.cc index 6912ba23a..c80b1f026 100644 --- a/verible/common/text/macro-definition.cc +++ b/verible/common/text/macro-definition.cc @@ -16,11 +16,11 @@ #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" #include "verible/common/util/container-util.h" diff --git a/verible/common/text/macro-definition.h b/verible/common/text/macro-definition.h index 3128f5626..8f86a1f78 100644 --- a/verible/common/text/macro-definition.h +++ b/verible/common/text/macro-definition.h @@ -21,10 +21,10 @@ #include #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" namespace verible { @@ -78,7 +78,7 @@ class MacroDefinition { MacroDefinition(const TokenInfo &header, const TokenInfo &name) : header_(header), name_(name) {} - absl::string_view Name() const { return name_.text(); } + std::string_view Name() const { return name_.text(); } const TokenInfo &NameToken() const { return name_; } const TokenInfo &DefinitionText() const { return definition_text_; } @@ -100,7 +100,7 @@ class MacroDefinition { return parameter_info_array_; } - using substitution_map_type = std::map; + using substitution_map_type = std::map; // Create a text substitution map to be used for macro expansion. absl::Status PopulateSubstitutionMap(const std::vector &, diff --git a/verible/common/text/parser-verifier_test.cc b/verible/common/text/parser-verifier_test.cc index 986461254..1962332d3 100644 --- a/verible/common/text/parser-verifier_test.cc +++ b/verible/common/text/parser-verifier_test.cc @@ -15,9 +15,9 @@ #include "verible/common/text/parser-verifier.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/constants.h" #include "verible/common/text/token-info.h" @@ -29,7 +29,7 @@ namespace verible { constexpr int NOT_EOF = 1; // Fake Token Enumeration static_assert(NOT_EOF != TK_EOF, "NOT_EOF cannot be TK_EOF"); -static TokenInfo Token(absl::string_view s) { return TokenInfo(NOT_EOF, s); } +static TokenInfo Token(std::string_view s) { return TokenInfo(NOT_EOF, s); } static bool equal_text(TokenInfo t1, TokenInfo t2) { return t1.text() == t2.text(); @@ -91,8 +91,8 @@ TEST(ParserVerifierTest, AllUnmatched) { } TEST(ParserVerifierTest, PartialUnmatched) { - constexpr absl::string_view foo("foo"); - constexpr absl::string_view bar("bar"); + constexpr std::string_view foo("foo"); + constexpr std::string_view bar("bar"); auto root = Node(Leaf(NOT_EOF, foo)); TokenSequence stream = {Token(foo), Token(bar)}; TokenSequence unmatched_expected = {Token(bar)}; @@ -108,10 +108,10 @@ TEST(ParserVerifierTest, PartialUnmatched) { } TEST(ParserVerifierTest, SeveralPartialUnmatched) { - constexpr absl::string_view foo("foo"); - constexpr absl::string_view bar1("bar1"); - constexpr absl::string_view bar2("bar2"); - constexpr absl::string_view mee("mee"); + constexpr std::string_view foo("foo"); + constexpr std::string_view bar1("bar1"); + constexpr std::string_view bar2("bar2"); + constexpr std::string_view mee("mee"); auto root = Node(Leaf(NOT_EOF, foo), Node(Leaf(NOT_EOF, mee))); TokenSequence stream = {Token(foo), Token(bar1), Token(bar2), Token(mee)}; diff --git a/verible/common/text/text-structure-test-utils.cc b/verible/common/text/text-structure-test-utils.cc index b907572c4..d57633b00 100644 --- a/verible/common/text/text-structure-test-utils.cc +++ b/verible/common/text/text-structure-test-utils.cc @@ -18,11 +18,11 @@ #include #include #include +#include #include #include #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/text-structure.h" #include "verible/common/text/token-info.h" @@ -33,7 +33,7 @@ namespace verible { std::string JoinLinesOfTokensIntoString(const LinesOfTokens &lines_of_tokens) { - std::vector token_strings; + std::vector token_strings; std::vector line_strings; line_strings.reserve(lines_of_tokens.size()); // Concatenate string_views over all tokens and all lines. @@ -73,7 +73,7 @@ std::unique_ptr MakeTextStructureViewHelloWorld() { auto text_structure_view = std::make_unique("hello, world"); TokenSequence &tokens = text_structure_view->MutableTokenStream(); - const absl::string_view text_view = text_structure_view->Contents(); + const std::string_view text_view = text_structure_view->Contents(); tokens.push_back(TokenInfo(0, text_view.substr(0, 5))); // "hello" tokens.push_back(TokenInfo(1, text_view.substr(5, 1))); // "," tokens.push_back(TokenInfo(2, text_view.substr(6, 1))); // " " diff --git a/verible/common/text/text-structure.cc b/verible/common/text/text-structure.cc index a297d5929..54db8e4e8 100644 --- a/verible/common/text/text-structure.cc +++ b/verible/common/text/text-structure.cc @@ -22,13 +22,13 @@ #include #include #include // IWYU pragma: keep // for ostringstream +#include #include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/line-column-map.h" #include "verible/common/strings/mem-block.h" #include "verible/common/text/concrete-syntax-leaf.h" @@ -44,7 +44,7 @@ namespace verible { -TextStructureView::TextStructureView(absl::string_view contents) +TextStructureView::TextStructureView(std::string_view contents) : contents_(contents) { // more than sufficient memory as number-of-tokens <= bytes-in-file, // push_back() should never re-alloc because size <= initial capacity. @@ -72,7 +72,7 @@ void TextStructureView::Clear() { } static bool TokenLocationLess(const TokenInfo &token, - const absl::string_view::const_iterator offset) { + const std::string_view::const_iterator offset) { return token.text().begin() < offset; } @@ -148,7 +148,7 @@ LineColumnRange TextStructureView::GetRangeForToken( } LineColumnRange TextStructureView::GetRangeForText( - absl::string_view text) const { + std::string_view text) const { const auto from = std::distance(Contents().begin(), text.begin()); const auto to = std::distance(Contents().begin(), text.end()); CHECK_GE(from, 0) << '"' << text << '"'; @@ -156,7 +156,7 @@ LineColumnRange TextStructureView::GetRangeForText( return {GetLineColAtOffset(from), GetLineColAtOffset(to)}; } -bool TextStructureView::ContainsText(absl::string_view text) const { +bool TextStructureView::ContainsText(std::string_view text) const { return IsSubRange(text, Contents()); } @@ -222,7 +222,7 @@ void TextStructureView::FocusOnSubtreeSpanningSubstring(int left_offset, // Discards nodes outside of the referenced subtree. void TextStructureView::TrimSyntaxTree(int first_token_offset, int last_token_offset) { - const absl::string_view text_range(Contents().substr( + const std::string_view text_range(Contents().substr( first_token_offset, last_token_offset - first_token_offset)); verible::TrimSyntaxTree(&syntax_tree_, text_range); } @@ -253,13 +253,13 @@ void TextStructureView::TrimTokensToSubstring(int left_offset, // If the last token straddles the end-of-range, (possibly due to lexical // error), then trim its tail, bounded by right_offset. if (!trimmed_stream.empty()) { - const absl::string_view substr( + const std::string_view substr( contents_.substr(left_offset, right_offset - left_offset)); TokenInfo &last(trimmed_stream.back()); const int overhang = std::distance(substr.end(), last.text().end()); if (!IsSubRange(last.text(), substr)) { VLOG(2) << "last token overhangs end by " << overhang << ": " << last; - absl::string_view trimmed_tail_token(last.text()); + std::string_view trimmed_tail_token(last.text()); trimmed_tail_token.remove_suffix(overhang); last.set_text(trimmed_tail_token); // TODO(fangism): Should the token enum be set to some error value, @@ -291,7 +291,7 @@ void TextStructureView::TrimContents(int left_offset, int length) { } const TextStructureView::LinesInfo &TextStructureView::LinesInfo::Get( - absl::string_view contents) { + std::string_view contents) { if (valid) return *this; lines = absl::StrSplit(contents, '\n'); @@ -301,8 +301,8 @@ const TextStructureView::LinesInfo &TextStructureView::LinesInfo::Get( return *this; } -void TextStructureView::RebaseTokensToSuperstring(absl::string_view superstring, - absl::string_view src_base, +void TextStructureView::RebaseTokensToSuperstring(std::string_view superstring, + std::string_view src_base, int offset) { MutateTokens([&](TokenInfo *token) { const int delta = token->left(src_base); @@ -409,8 +409,8 @@ absl::Status TextStructureView::SyntaxTreeConsistencyCheck() const { VLOG(2) << __FUNCTION__; // Check that first and last token in syntax_tree_ point to text // inside contents_. - const absl::string_view::const_iterator lower_bound = contents_.begin(); - const absl::string_view::const_iterator upper_bound = + const std::string_view::const_iterator lower_bound = contents_.begin(); + const std::string_view::const_iterator upper_bound = lower_bound + contents_.length(); if (syntax_tree_ != nullptr) { const SyntaxTreeLeaf *left = GetLeftmostLeaf(*syntax_tree_); @@ -473,20 +473,20 @@ void TextStructureView::ConsumeDeferredExpansion( TokenStreamView::const_iterator *next_token_view_iter, DeferredExpansion *expansion, TokenSequence *combined_tokens, std::vector *token_view_indices, - absl::string_view::const_iterator offset) { + std::string_view::const_iterator offset) { auto token_iter = *next_token_iter; auto token_view_iter = *next_token_view_iter; // Find the position up to each expansion point. *next_token_iter = std::lower_bound( token_iter, tokens_.cend(), offset, - [](const TokenInfo &token, absl::string_view::const_iterator target) { + [](const TokenInfo &token, std::string_view::const_iterator target) { return std::distance(target, token.text().begin()) < 0; }); CHECK(*next_token_iter != tokens_.cend()); *next_token_view_iter = std::lower_bound( token_view_iter, tokens_view_.cend(), offset, [](TokenStreamView::const_reference token_ref, - absl::string_view::const_iterator target) { + std::string_view::const_iterator target) { return std::distance(target, token_ref->text().begin()) < 0; }); CHECK(*next_token_view_iter != tokens_view_.cend()); @@ -500,9 +500,9 @@ void TextStructureView::ConsumeDeferredExpansion( // into the original text (contents_). std::unique_ptr &subanalysis = expansion->subanalysis; TextStructureView &sub_data = ABSL_DIE_IF_NULL(subanalysis)->MutableData(); - const absl::string_view sub_data_text(sub_data.Contents()); + const std::string_view sub_data_text(sub_data.Contents()); CHECK(!IsSubRange(sub_data_text, contents_)); - CHECK_EQ(sub_data_text, absl::string_view(&*offset, sub_data_text.length())); + CHECK_EQ(sub_data_text, std::string_view(&*offset, sub_data_text.length())); CHECK(offset >= contents_.begin()); sub_data.RebaseTokensToSuperstring(contents_, sub_data_text, std::distance(contents_.begin(), offset)); @@ -532,7 +532,7 @@ TextStructure::TextStructure(std::shared_ptr contents) CHECK(status.ok()) << status.message() << " (in ctor)"; } -TextStructure::TextStructure(absl::string_view contents) +TextStructure::TextStructure(std::string_view contents) : TextStructure(std::make_shared(contents)) {} TextStructure::~TextStructure() { @@ -576,7 +576,7 @@ void TextStructureView::ExpandSubtrees(NodeExpansionMap *expansions) { } absl::Status TextStructure::StringViewConsistencyCheck() const { - const absl::string_view contents = data_.Contents(); + const std::string_view contents = data_.Contents(); if (!contents.empty() && !IsSubRange(contents, contents_->AsStringView())) { return absl::InternalError( "string_view contents_ is not a substring of contents_, " diff --git a/verible/common/text/text-structure.h b/verible/common/text/text-structure.h index 1606bd9ec..df6616fe6 100644 --- a/verible/common/text/text-structure.h +++ b/verible/common/text/text-structure.h @@ -29,10 +29,10 @@ #include #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/line-column-map.h" #include "verible/common/strings/mem-block.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -73,7 +73,7 @@ class TextStructureView { // expansion is encountered. using NodeExpansionMap = std::map; - explicit TextStructureView(absl::string_view contents); + explicit TextStructureView(std::string_view contents); ~TextStructureView(); @@ -81,9 +81,9 @@ class TextStructureView { TextStructureView(const TextStructureView &) = delete; TextStructureView &operator=(const TextStructureView &) = delete; - absl::string_view Contents() const { return contents_; } + std::string_view Contents() const { return contents_; } - const std::vector &Lines() const { + const std::vector &Lines() const { return lazy_lines_info_.Get(contents_).lines; } @@ -118,10 +118,10 @@ class TextStructureView { // Convenience function: Given a text snippet, that needs to be a substring // of Contents(), return the range it covers. - LineColumnRange GetRangeForText(absl::string_view text) const; + LineColumnRange GetRangeForText(std::string_view text) const; // checks if a given text belongs to the TextStructure - bool ContainsText(absl::string_view text) const; + bool ContainsText(std::string_view text) const; const std::vector &GetLineTokenMap() const; @@ -156,8 +156,8 @@ class TextStructureView { // Update tokens to point their text into new (superstring) owner. // This is done to prepare for transfer of ownership of syntax_tree_ // to a new owner. - void RebaseTokensToSuperstring(absl::string_view superstring, - absl::string_view src_base, int offset); + void RebaseTokensToSuperstring(std::string_view superstring, + std::string_view src_base, int offset); // Narrows the view of text, tokens, and syntax tree to the node that starts // at left_offset. The resulting state looks as if only a snippet of @@ -180,7 +180,7 @@ class TextStructureView { // This is required for calculating byte offsets to substrings contained // within this structure. Pass this (via Contents()) to TokenInfo::left() and // TokenInfo::right() to calculate byte offsets, useful for diagnostics. - absl::string_view contents_; + std::string_view contents_; // TODO(hzeller): These lazily generated elements are good candidates // for breaking out into their own abstraction. @@ -188,12 +188,12 @@ class TextStructureView { bool valid = false; // Line-by-line view of contents_. - std::vector lines; + std::vector lines; // Map to translate byte-offsets to line and column for diagnostics. std::unique_ptr line_column_map; - const LinesInfo &Get(absl::string_view contents); + const LinesInfo &Get(std::string_view contents); }; // Mutable as we fill it lazily on request; conceptually the data is const. mutable LinesInfo lazy_lines_info_; @@ -223,7 +223,7 @@ class TextStructureView { TokenStreamView::const_iterator *next_token_view_iter, DeferredExpansion *expansion, TokenSequence *combined_tokens, std::vector *token_view_indices, - absl::string_view::const_iterator offset); + std::string_view::const_iterator offset); // Resets all fields. Only needed in tests. void Clear(); @@ -273,7 +273,7 @@ class TextStructure { explicit TextStructure(std::shared_ptr contents); // Convenience constructor in case our input is a string. - explicit TextStructure(absl::string_view contents); + explicit TextStructure(std::string_view contents); public: TextStructure(const TextStructure &) = delete; diff --git a/verible/common/text/text-structure_test.cc b/verible/common/text/text-structure_test.cc index f5ce8cd3a..3e6b6650c 100644 --- a/verible/common/text/text-structure_test.cc +++ b/verible/common/text/text-structure_test.cc @@ -19,11 +19,11 @@ #include #include #include +#include #include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/strings/line-column-map.h" @@ -95,7 +95,7 @@ void MultiTokenTextStructureViewNoTree(TextStructureView *view) { // Test that filtering can keep tokens. TEST(FilterTokensTest, OneTokenKept) { - const absl::string_view text = "blah"; + const std::string_view text = "blah"; TextStructureView test_view(text); // Pretend to lex and parse text. OneTokenTextStructureView(&test_view); @@ -106,7 +106,7 @@ TEST(FilterTokensTest, OneTokenKept) { // Test that filtering can remove tokens. TEST(FilterTokensTest, OneTokenRemoved) { - const absl::string_view text = "blah"; + const std::string_view text = "blah"; TextStructureView test_view(text); // Pretend to lex and parse text. OneTokenTextStructureView(&test_view); @@ -139,7 +139,7 @@ TEST(TokenStreamReferenceViewTest, ShiftRight) { // Test that EOFToken is properly constructed to the correct range. TEST(EOFTokenTest, TokenRange) { - const absl::string_view kTestCases[] = { + const std::string_view kTestCases[] = { "", "\n", "foobar", @@ -158,8 +158,8 @@ TEST(EOFTokenTest, TokenRange) { // Test that string_views can point to memory owned in new location, // where new location is a superstring of the original. TEST(RebaseTokensToSuperstringTest, NewOwner) { - const absl::string_view superstring = "abcdefgh"; - const absl::string_view substring = "cdef"; + const std::string_view superstring = "abcdefgh"; + const std::string_view substring = "cdef"; EXPECT_FALSE(IsSubRange(substring, superstring)); TextStructureView test_view(substring); OneTokenTextStructureView(&test_view); @@ -248,7 +248,7 @@ TEST_F(TokenRangeTest, GetRangeForTokenOrText) { TEST_F(TokenRangeTest, CheckContainsText) { const TokenInfo &token = data_.FindTokenAt({0, 7}); - const absl::string_view other_string = "other_string"; + const std::string_view other_string = "other_string"; EXPECT_TRUE(data_.ContainsText(token.text())); EXPECT_FALSE(data_.ContainsText(other_string)); } @@ -560,7 +560,7 @@ TEST_F(TextStructureViewPublicTest, ExpandSubtreesMultipleLeaves) { // Test that FastLineRangeConsistencyCheck catches text mismatch at first line. TEST_F(TextStructureViewInternalsTest, LineConsistencyFailsBeginning) { - const ValueSaver save_contents(&contents_); + const ValueSaver save_contents(&contents_); contents_ = contents_.substr(1); EXPECT_FALSE(FastLineRangeConsistencyCheck().ok()); EXPECT_FALSE(InternalConsistencyCheck().ok()); @@ -568,7 +568,7 @@ TEST_F(TextStructureViewInternalsTest, LineConsistencyFailsBeginning) { // Test that FastLineRangeConsistencyCheck catches text mismatch at last line. TEST_F(TextStructureViewInternalsTest, LineConsistencyFailsEnd) { - const ValueSaver save_contents(&contents_); + const ValueSaver save_contents(&contents_); contents_ = contents_.substr(0, contents_.length() - 1); EXPECT_FALSE(FastLineRangeConsistencyCheck().ok()); EXPECT_FALSE(InternalConsistencyCheck().ok()); @@ -576,7 +576,7 @@ TEST_F(TextStructureViewInternalsTest, LineConsistencyFailsEnd) { // Test that FastTokenRangeConsistencyCheck catches location past end. TEST_F(TextStructureViewInternalsTest, RangeConsistencyFailPastContentsEnd) { - const ValueSaver save_contents(&contents_); + const ValueSaver save_contents(&contents_); contents_ = contents_.substr(0, contents_.length() - 1); EXPECT_FALSE(FastTokenRangeConsistencyCheck().ok()); EXPECT_FALSE(InternalConsistencyCheck().ok()); @@ -584,7 +584,7 @@ TEST_F(TextStructureViewInternalsTest, RangeConsistencyFailPastContentsEnd) { // Test that FastTokenRangeConsistencyCheck catches location past begin. TEST_F(TextStructureViewInternalsTest, RangeConsistencyFailPastContentsBegin) { - const ValueSaver save_contents(&contents_); + const ValueSaver save_contents(&contents_); contents_ = contents_.substr(1); EXPECT_FALSE(FastTokenRangeConsistencyCheck().ok()); EXPECT_FALSE(InternalConsistencyCheck().ok()); @@ -643,7 +643,7 @@ TEST_F(TextStructureViewInternalsTest, // located past the begin. TEST_F(TextStructureViewInternalsTest, SyntaxTreeConsistencyFailViewRightmostLeafPastBegin) { - const ValueSaver save_contents(&contents_); + const ValueSaver save_contents(&contents_); contents_ = contents_.substr(1); EXPECT_FALSE(SyntaxTreeConsistencyCheck().ok()); EXPECT_FALSE(InternalConsistencyCheck().ok()); @@ -653,7 +653,7 @@ TEST_F(TextStructureViewInternalsTest, // located past the end. TEST_F(TextStructureViewInternalsTest, SyntaxTreeConsistencyFailViewRightmostLeafPastEnd) { - const ValueSaver save_contents(&contents_); + const ValueSaver save_contents(&contents_); contents_ = contents_.substr(0, contents_.length() - 1); EXPECT_FALSE(SyntaxTreeConsistencyCheck().ok()); EXPECT_FALSE(InternalConsistencyCheck().ok()); diff --git a/verible/common/text/token-info-json_test.cc b/verible/common/text/token-info-json_test.cc index 6c2b15724..7a9f738e4 100644 --- a/verible/common/text/token-info-json_test.cc +++ b/verible/common/text/token-info-json_test.cc @@ -15,8 +15,8 @@ #include "verible/common/text/token-info-json.h" #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "nlohmann/json.hpp" #include "verible/common/text/constants.h" @@ -26,7 +26,7 @@ namespace verible { namespace { TEST(TokenInfoToJsonTest, ToJsonEOF) { - constexpr absl::string_view base; // empty + constexpr std::string_view base; // empty const TokenInfo::Context context(base); const TokenInfo token_info(TK_EOF, base); @@ -45,7 +45,7 @@ TEST(TokenInfoToJsonTest, ToJsonEOF) { } TEST(TokenInfoToJsonTest, ToJsonWithBase) { - constexpr absl::string_view base("basement cat"); + constexpr std::string_view base("basement cat"); const TokenInfo::Context context(base); const TokenInfo token_info(7, base.substr(9, 3)); @@ -64,7 +64,7 @@ TEST(TokenInfoToJsonTest, ToJsonWithBase) { } TEST(TokenInfoToJsonTest, ToJsonWithTokenEnumTranslator) { - constexpr absl::string_view text("string of length 19"); + constexpr std::string_view text("string of length 19"); const TokenInfo token_info(143, text); const verible::TokenInfo::Context context( diff --git a/verible/common/text/token-info-test-util.cc b/verible/common/text/token-info-test-util.cc index 5b68fe258..667cb4432 100644 --- a/verible/common/text/token-info-test-util.cc +++ b/verible/common/text/token-info-test-util.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" #include "verible/common/util/logging.h" @@ -35,12 +35,12 @@ ExpectedTokenInfo::ExpectedTokenInfo(char token_enum_and_text) // address) at offset 0 or sizeof(int) -1. // Note: This constructor using a self-pointer makes this struct // non-default-copy/move/assign-able. - absl::string_view(reinterpret_cast(&token_enum_) + std::string_view(reinterpret_cast(&token_enum_) #ifdef IS_BIG_ENDIAN - + (sizeof(typeid(token_enum_)) - 1) + + (sizeof(typeid(token_enum_)) - 1) #endif - , - 1)) { + , + 1)) { } static std::vector ComposeExpectedTokensFromFragments( @@ -78,21 +78,21 @@ std::vector TokenInfoTestData::FindImportantTokens() const { } std::vector TokenInfoTestData::FindImportantTokens( - absl::string_view base) const { + std::string_view base) const { std::vector return_tokens = FindImportantTokens(); RebaseToCodeCopy(&return_tokens, base); return return_tokens; } void TokenInfoTestData::RebaseToCodeCopy(std::vector *tokens, - absl::string_view base) const { + std::string_view base) const { CHECK_EQ(code, base); // verify content match // Another analyzer object may have made its own copy of 'code', so // we need to translate the expected error token into a rebased version // before directly comparing against the rejected tokens. for (TokenInfo &token : *tokens) { const auto offset = - std::distance(absl::string_view(code).begin(), token.text().begin()); + std::distance(std::string_view(code).begin(), token.text().begin()); token.RebaseStringView(base.begin() + offset); } } diff --git a/verible/common/text/token-info-test-util.h b/verible/common/text/token-info-test-util.h index b3fc4288b..5e106c4c1 100644 --- a/verible/common/text/token-info-test-util.h +++ b/verible/common/text/token-info-test-util.h @@ -17,9 +17,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" namespace verible { @@ -45,7 +45,7 @@ struct ExpectedTokenInfo : public TokenInfo { // the token enum of the string. // Implicit construction intentional. ExpectedTokenInfo( // NOLINT(google-explicit-constructor) - absl::string_view token_text) + std::string_view token_text) : TokenInfo(kDontCare, token_text) {} // Arbitrary text constructor for cases where one does not care about @@ -54,7 +54,7 @@ struct ExpectedTokenInfo : public TokenInfo { // Implicit construction intentional. ExpectedTokenInfo( // NOLINT(google-explicit-constructor) const char *token_text) - : ExpectedTokenInfo(absl::string_view(token_text)) {} // delegating + : ExpectedTokenInfo(std::string_view(token_text)) {} // delegating // Single-character token constructor, for the cases where the // only character of the text **is** the token enum. @@ -66,7 +66,7 @@ struct ExpectedTokenInfo : public TokenInfo { ExpectedTokenInfo( // NOLINT(google-explicit-constructor) char token_enum_and_text); - ExpectedTokenInfo(int expected_token_enum, absl::string_view expected_text) + ExpectedTokenInfo(int expected_token_enum, std::string_view expected_text) : TokenInfo(expected_token_enum, expected_text) {} // Deleted interfaces. @@ -111,12 +111,12 @@ struct TokenInfoTestData { // This variant rebases tokens to a copy of the same 'code' that lives // in a different buffer. This combines FindImportantTokens() with // RebaseToCodeCopy(). - std::vector FindImportantTokens(absl::string_view base) const; + std::vector FindImportantTokens(std::string_view base) const; // Moves the locations of tokens into the range spanned by the 'base' buffer. // 'base' is another copy of (this) 'code' (content match is verified). void RebaseToCodeCopy(std::vector *tokens, - absl::string_view base) const; + std::string_view base) const; }; } // namespace verible diff --git a/verible/common/text/token-info-test-util_test.cc b/verible/common/text/token-info-test-util_test.cc index 316bad8a3..6aac2f619 100644 --- a/verible/common/text/token-info-test-util_test.cc +++ b/verible/common/text/token-info-test-util_test.cc @@ -14,9 +14,9 @@ #include "verible/common/text/token-info-test-util.h" +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/token-info.h" @@ -175,7 +175,7 @@ TEST(TokenInfoTestDataTest, FindImportantTokensTest) { TEST(TokenInfoTestDataTest, RebaseToCodeCopyEmpty) { std::vector tokens; const TokenInfoTestData test_data{}; - constexpr absl::string_view other_text; + constexpr std::string_view other_text; EXPECT_EQ(test_data.code, other_text); test_data.RebaseToCodeCopy(&tokens, other_text); EXPECT_TRUE(tokens.empty()); @@ -186,7 +186,7 @@ TEST(TokenInfoTestDataTest, RebaseToCodeCopyMoved) { {3, "text"}, {4, "book"}, }; - constexpr absl::string_view other_text("textbook"); // separate copy + constexpr std::string_view other_text("textbook"); // separate copy std::vector tokens = test_data.expected_tokens; // copy EXPECT_EQ(test_data.code, other_text); EXPECT_EQ(tokens.size(), 2); @@ -215,7 +215,7 @@ TEST(TokenInfoTestDataTest, FindImportantTokensRebased) { {3, "text"}, {4, "book"}, }; - constexpr absl::string_view other_text("textbook"); // separate copy + constexpr std::string_view other_text("textbook"); // separate copy std::vector tokens = test_data.FindImportantTokens(other_text); EXPECT_EQ(test_data.code, other_text); EXPECT_EQ(tokens.size(), 2); diff --git a/verible/common/text/token-info.cc b/verible/common/text/token-info.cc index 485fe1076..b78569d67 100644 --- a/verible/common/text/token-info.cc +++ b/verible/common/text/token-info.cc @@ -18,10 +18,10 @@ #include #include // IWYU pragma: keep // for ostringstream #include +#include #include #include "absl/strings/escaping.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/rebase.h" #include "verible/common/text/constants.h" #include "verible/common/util/logging.h" @@ -30,12 +30,12 @@ namespace verible { TokenInfo TokenInfo::EOFToken() { - static constexpr absl::string_view null_text; + static constexpr std::string_view null_text; return {TK_EOF, null_text}; } -TokenInfo TokenInfo::EOFToken(absl::string_view buffer) { - return {TK_EOF, absl::string_view(buffer.data() + buffer.length(), 0)}; +TokenInfo TokenInfo::EOFToken(std::string_view buffer) { + return {TK_EOF, std::string_view(buffer.data() + buffer.length(), 0)}; } bool TokenInfo::operator==(const TokenInfo &token) const { @@ -44,7 +44,7 @@ bool TokenInfo::operator==(const TokenInfo &token) const { BoundsEqual(text_, token.text_)); } -TokenInfo::Context::Context(absl::string_view b) +TokenInfo::Context::Context(std::string_view b) : base(b), // By default, just print the enum integer value, un-translated. token_enum_translator([](std::ostream &stream, int e) { stream << e; }) {} @@ -77,7 +77,7 @@ std::string TokenInfo::ToString() const { return output_stream.str(); } -void TokenInfo::RebaseStringView(absl::string_view new_text) { +void TokenInfo::RebaseStringView(std::string_view new_text) { verible::RebaseStringView(&text_, new_text); } diff --git a/verible/common/text/token-info.h b/verible/common/text/token-info.h index 0f23ea531..02c55de5a 100644 --- a/verible/common/text/token-info.h +++ b/verible/common/text/token-info.h @@ -21,10 +21,10 @@ #include #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/text/constants.h" #include "verible/common/util/iterator-range.h" @@ -45,13 +45,13 @@ class TokenInfo { static TokenInfo EOFToken(); // Construct an EOF token that points to the end of a string buffer. - static TokenInfo EOFToken(absl::string_view); + static TokenInfo EOFToken(std::string_view); // Hide default constructor, force explicit initialization or call to // EOFToken(). TokenInfo() = delete; - TokenInfo(int token_enum, absl::string_view text) + TokenInfo(int token_enum, std::string_view text) : token_enum_(token_enum), text_(text) {} TokenInfo(const TokenInfo &) = default; @@ -63,30 +63,30 @@ class TokenInfo { struct Context { // Full range of text in which a token appears. // This is used to calculate byte offsets. - absl::string_view base; + std::string_view base; // Prints a human-readable interpretation form of a token enumeration. std::function token_enum_translator; - explicit Context(absl::string_view b); + explicit Context(std::string_view b); - Context(absl::string_view b, + Context(std::string_view b, std::function translator) : base(b), token_enum_translator(std::move(translator)) {} }; int token_enum() const { return token_enum_; } void set_token_enum(int t) { token_enum_ = t; } - absl::string_view text() const { return text_; } - void set_text(absl::string_view t) { text_ = t; } + std::string_view text() const { return text_; } + void set_text(std::string_view t) { text_ = t; } // Return position of this token's text start relative to a base buffer. - int left(absl::string_view base) const { + int left(std::string_view base) const { return std::distance(base.begin(), text_.begin()); } // Return position of this token's text end relative to a base buffer. - int right(absl::string_view base) const { + int right(std::string_view base) const { return std::distance(base.begin(), text_.end()); } @@ -95,7 +95,7 @@ class TokenInfo { // a series of abutting substring ranges. Useful for lexer operation. void AdvanceText(int token_length) { // The end of the previous token is the beginning of the next. - text_ = absl::string_view(text_.data() + text_.length(), token_length); + text_ = std::string_view(text_.data() + text_.length(), token_length); } // Writes a human-readable string representation of the token. @@ -117,14 +117,14 @@ class TokenInfo { // This is a potentially dangerous operation, which can be validated // using a combination of object lifetime management and range-checking. // It is the caller's responsibility that it points to valid memory. - void RebaseStringView(absl::string_view new_text); + void RebaseStringView(std::string_view new_text); // This overload assumes that the string of interest from other has the // same length as the current string_view. // string_view::iterator happens to be const char*, but don't rely on that // fact as it can be implementation-dependent. - void RebaseStringView(absl::string_view::const_iterator new_text) { - RebaseStringView(absl::string_view(&*new_text, text_.length())); + void RebaseStringView(std::string_view::const_iterator new_text) { + RebaseStringView(std::string_view(&*new_text, text_.length())); } // Joins the text from a sequence of (text-disjoint) tokens, and also @@ -162,7 +162,7 @@ class TokenInfo { int token_enum_; // The substring of a larger text that this token represents. - absl::string_view text_; + std::string_view text_; }; std::ostream &operator<<(std::ostream &, const TokenInfo &); @@ -192,7 +192,7 @@ void ConcatenateTokenInfos(std::string *out, TokenIter begin, TokenIter end) { total_length += token.text().length(); } out->resize(total_length); - const absl::string_view out_view(*out); + const std::string_view out_view(*out); // Copy text into new buffer. auto code_iter = out->begin(); // writeable iterator (like char*) diff --git a/verible/common/text/token-info_test.cc b/verible/common/text/token-info_test.cc index ad651d8e5..6607b9aa3 100644 --- a/verible/common/text/token-info_test.cc +++ b/verible/common/text/token-info_test.cc @@ -20,9 +20,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/constants.h" #include "verible/common/util/range.h" @@ -32,7 +32,7 @@ namespace { // Test construction with a token enum and text. TEST(TokenInfoTest, EnumTextConstruction) { - constexpr absl::string_view text("string of length 19"); + constexpr std::string_view text("string of length 19"); TokenInfo token_info(143, text); EXPECT_EQ(token_info.token_enum(), 143); EXPECT_EQ(token_info.left(text), 0); @@ -42,7 +42,7 @@ TEST(TokenInfoTest, EnumTextConstruction) { // Test updating text. TEST(TokenInfoTest, AdvanceText) { - constexpr absl::string_view text = "This quick brown fox..."; + constexpr std::string_view text = "This quick brown fox..."; TokenInfo token_info(1, text.substr(0, 0)); EXPECT_TRUE(BoundsEqual(token_info.text(), text.substr(0, 0))); token_info.AdvanceText(3); @@ -76,7 +76,7 @@ TEST(TokenInfoTest, EOFEquality) { } TEST(TokenInfoTest, EOFWithBuffer) { - constexpr absl::string_view text("string of length 21"); + constexpr std::string_view text("string of length 21"); TokenInfo token_info = TokenInfo::EOFToken(text); EXPECT_EQ(token_info.token_enum(), TK_EOF); EXPECT_EQ(token_info.text().begin(), text.end()); @@ -85,7 +85,7 @@ TEST(TokenInfoTest, EOFWithBuffer) { // Test operator !=. TEST(TokenInfoTest, Inequality) { - constexpr absl::string_view text("string of length 21"); + constexpr std::string_view text("string of length 21"); const std::vector token_infos = { TokenInfo(143, text), TokenInfo(43, text), @@ -102,7 +102,7 @@ TEST(TokenInfoTest, Inequality) { } TEST(TokenInfoTest, EquivalentWithoutLocation) { - const absl::string_view foo1("foo"), foo2("foo"); + const std::string_view foo1("foo"), foo2("foo"); TokenInfo token_0(1, foo1); // reference token TokenInfo token_1(1, "bar"); // different text TokenInfo token_2(1, foo2); // different location @@ -174,14 +174,14 @@ TEST(TokenInfoTest, IsEOFAnyString) { // Test string representation of token_info. TEST(TokenInfoTest, ToStringEOF) { - const absl::string_view base; // empty + const std::string_view base; // empty const TokenInfo::Context context(base); TokenInfo token_info(TK_EOF, base); EXPECT_EQ(token_info.ToString(context), "(#0 @0-0: \"\")"); } TEST(TokenInfoTest, ToStringWithBase) { - const absl::string_view base("basement cat"); + const std::string_view base("basement cat"); const TokenInfo::Context context(base); TokenInfo token_info(7, base.substr(9, 3)); EXPECT_EQ(token_info.ToString(context), "(#7 @9-12: \"cat\")"); @@ -198,14 +198,14 @@ void TokenTranslator(std::ostream &stream, int e) { } TEST(TokenInfoTest, ToStringWithBaseAndTranslator) { - const absl::string_view base("basement cat"); + const std::string_view base("basement cat"); const TokenInfo::Context context(base, TokenTranslator); TokenInfo token_info(7, base.substr(9, 3)); EXPECT_EQ(token_info.ToString(context), "(#lucky-seven @9-12: \"cat\")"); } TEST(TokenWithContextTest, StreamOutput) { - const absl::string_view base("basement cat"); + const std::string_view base("basement cat"); const TokenInfo::Context context(base, TokenTranslator); TokenInfo token_info(7, base.substr(9, 3)); std::ostringstream stream; @@ -246,8 +246,8 @@ TEST(RebaseStringViewTest, IdenticalCopy) { // Test that substring mismatch between new and old is checked. TEST(RebaseStringViewDeathTest, SubstringMismatch) { - const absl::string_view text = "hell0"; - const absl::string_view substr = "hello"; + const std::string_view text = "hell0"; + const std::string_view substr = "hello"; TokenInfo token(1, text); EXPECT_EQ(token.left(text), 0); EXPECT_DEATH(token.RebaseStringView(substr), @@ -255,8 +255,8 @@ TEST(RebaseStringViewDeathTest, SubstringMismatch) { } TEST(RebaseStringViewDeathTest, SubstringMismatch2) { - const absl::string_view text = "hello"; - const absl::string_view substr = "Hello"; + const std::string_view text = "hello"; + const std::string_view substr = "Hello"; TokenInfo token(1, text); EXPECT_EQ(token.left(text), 0); EXPECT_DEATH(token.RebaseStringView(substr), @@ -265,8 +265,8 @@ TEST(RebaseStringViewDeathTest, SubstringMismatch2) { // Test that substring in the middle of old string is rebased correctly. TEST(RebaseStringViewTest, NewSubstringNotAtFront) { - const absl::string_view text = "hello"; - const absl::string_view new_base = "xxxhelloyyy"; + const std::string_view text = "hello"; + const std::string_view new_base = "xxxhelloyyy"; TokenInfo token(1, text); token.RebaseStringView(new_base.substr(3, 5)); EXPECT_EQ(token.left(new_base), 3); @@ -276,8 +276,8 @@ TEST(RebaseStringViewTest, NewSubstringNotAtFront) { // Test that substring in the middle of old string is rebased correctly. TEST(RebaseStringViewTest, UsingCharPointer) { - const absl::string_view text = "hello"; - const absl::string_view new_base = "xxxhelloyyy"; + const std::string_view text = "hello"; + const std::string_view new_base = "xxxhelloyyy"; TokenInfo token(1, text); token.RebaseStringView(new_base.begin() + 3); // assume original length EXPECT_EQ(token.left(new_base), 3); @@ -287,13 +287,13 @@ TEST(RebaseStringViewTest, UsingCharPointer) { // Test integration with substr() function rebases correctly. TEST(RebaseStringViewTest, RelativeToOldBase) { - const absl::string_view full_text = "xxxxxxhelloyyyyy"; - const absl::string_view substr = full_text.substr(6, 5); + const std::string_view full_text = "xxxxxxhelloyyyyy"; + const std::string_view substr = full_text.substr(6, 5); EXPECT_EQ(substr, "hello"); TokenInfo token(1, substr); EXPECT_EQ(token.left(full_text), 6); EXPECT_EQ(token.text(), substr); - const absl::string_view new_base = "aahellobbb"; + const std::string_view new_base = "aahellobbb"; token.RebaseStringView(new_base.substr(2, substr.length())); EXPECT_EQ(token.left(new_base), 2); EXPECT_EQ(token.right(new_base), 7); @@ -302,10 +302,10 @@ TEST(RebaseStringViewTest, RelativeToOldBase) { // Test rebasing into middle of superstring. TEST(RebaseStringViewTest, MiddleOfSuperstring) { - const absl::string_view dest_text = "xxxxxxhell0yyyyy"; - const absl::string_view src_text = "ccchell0ddd"; + const std::string_view dest_text = "xxxxxxhell0yyyyy"; + const std::string_view src_text = "ccchell0ddd"; const int dest_offset = 6; - const absl::string_view src_substr = src_text.substr(3, 5); + const std::string_view src_substr = src_text.substr(3, 5); EXPECT_EQ(src_substr, "hell0"); TokenInfo token(2, src_substr); // src_text[3] lines up with dest_text[6]. @@ -316,10 +316,10 @@ TEST(RebaseStringViewTest, MiddleOfSuperstring) { // Test rebasing into prefix superstring. TEST(RebaseStringViewTest, PrefixSuperstring) { - const absl::string_view dest_text = "xxxhell0yyyyyzzzzzzz"; - const absl::string_view src_text = "ccchell0ddd"; + const std::string_view dest_text = "xxxhell0yyyyyzzzzzzz"; + const std::string_view src_text = "ccchell0ddd"; const int dest_offset = 3; - const absl::string_view src_substr = src_text.substr(3, 5); + const std::string_view src_substr = src_text.substr(3, 5); EXPECT_EQ(src_substr, "hell0"); TokenInfo token(1, src_substr); // src_text[3] lines up with dest_text[3]. diff --git a/verible/common/text/token-stream-view.cc b/verible/common/text/token-stream-view.cc index 419d02c38..6cbf30f6a 100644 --- a/verible/common/text/token-stream-view.cc +++ b/verible/common/text/token-stream-view.cc @@ -15,9 +15,9 @@ #include "verible/common/text/token-stream-view.h" #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" #include "verible/common/util/iterator-range.h" @@ -52,12 +52,12 @@ void FilterTokenStreamViewInPlace(const TokenFilterPredicate &keep, } static bool TokenLocationLess(const TokenSequence::const_iterator &token_iter, - absl::string_view::const_iterator offset) { + std::string_view::const_iterator offset) { return token_iter->text().begin() < offset; } TokenViewRange TokenViewRangeSpanningOffsets(const TokenStreamView &view, - absl::string_view range) { + std::string_view range) { const auto lower = range.begin(); const auto upper = range.end(); const auto left = diff --git a/verible/common/text/token-stream-view.h b/verible/common/text/token-stream-view.h index 7a08ddf98..d5f9b1706 100644 --- a/verible/common/text/token-stream-view.h +++ b/verible/common/text/token-stream-view.h @@ -18,9 +18,9 @@ #define VERIBLE_COMMON_TEXT_TOKEN_STREAM_VIEW_H_ #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" #include "verible/common/util/iterator-range.h" @@ -62,7 +62,7 @@ void FilterTokenStreamViewInPlace(const TokenFilterPredicate &keep, // Returns iterator range of TokenSequence iterators that span the given file // offsets. The second iterator points 1-past-the-end of the range. TokenViewRange TokenViewRangeSpanningOffsets(const TokenStreamView &view, - absl::string_view range); + std::string_view range); } // namespace verible diff --git a/verible/common/text/token-stream-view_test.cc b/verible/common/text/token-stream-view_test.cc index 2f9b4bddf..071de8c31 100644 --- a/verible/common/text/token-stream-view_test.cc +++ b/verible/common/text/token-stream-view_test.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/text-structure-test-utils.h" #include "verible/common/text/text-structure.h" @@ -103,7 +103,7 @@ TEST_F(TokenViewRangeTest, TokenViewRangeSpanningOffsetsNonEmpty) { }; for (const auto &test_case : test_cases) { const int length = test_case.right_offset - test_case.left_offset; - const absl::string_view text_range( + const std::string_view text_range( data_.Contents().substr(test_case.left_offset, length)); const auto token_view_range = TokenViewRangeSpanningOffsets(view_, text_range); diff --git a/verible/common/text/tree-builder-test-util.cc b/verible/common/text/tree-builder-test-util.cc index 9914e25e7..de2726863 100644 --- a/verible/common/text/tree-builder-test-util.cc +++ b/verible/common/text/tree-builder-test-util.cc @@ -16,15 +16,15 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/text/symbol.h" #include "verible/common/text/tree-utils.h" #include "verible/common/util/logging.h" namespace verible { -constexpr absl::string_view kDontCareText; +constexpr std::string_view kDontCareText; SymbolPtr XLeaf(int token_enum) { return Leaf(token_enum, kDontCareText); } diff --git a/verible/common/text/tree-compare_test.cc b/verible/common/text/tree-compare_test.cc index 311f2e0cf..fc668e7b7 100644 --- a/verible/common/text/tree-compare_test.cc +++ b/verible/common/text/tree-compare_test.cc @@ -14,7 +14,8 @@ #include "verible/common/text/tree-compare.h" -#include "absl/strings/string_view.h" +#include + #include "gtest/gtest.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/tree-builder-test-util.h" @@ -136,7 +137,7 @@ TEST(TreeEqualityTest, NonEmptyNodesEqualByEnumString) { } TEST(TreeEqualityTest, NonEmptyNodesNotEqualByEnum) { - constexpr absl::string_view foo; + constexpr std::string_view foo; SymbolPtr tree1 = Node(Leaf(1, foo), Leaf(2, foo)); SymbolPtr tree2 = Node(Leaf(1, foo), Leaf(2, foo), Leaf(3, foo)); SymbolPtr tree3 = Node(Leaf(3, foo), Leaf(1, foo), Leaf(2, foo)); @@ -150,7 +151,7 @@ TEST(TreeEqualityTest, NonEmptyNodesNotEqualByEnum) { } TEST(TreeEqualityTest, NonEmptyNodesNotEqualByEnumString) { - constexpr absl::string_view foo("Foo"), bar("Bar"); + constexpr std::string_view foo("Foo"), bar("Bar"); SymbolPtr tree1 = Node(Leaf(1, bar), Leaf(2, foo)); SymbolPtr tree2 = Node(Leaf(1, foo), Leaf(2, bar)); SymbolPtr tree3 = Node(Leaf(3, foo), Leaf(1, foo), Leaf(2, bar)); @@ -203,7 +204,7 @@ TEST(TreeEqualityTest, SubTreeNotEqual) { // Test exact token-by-token equality. TEST(TreeEqualityTest, ExactEqualPerfectMatch) { - constexpr absl::string_view foo("foo"), bar("bar"); + constexpr std::string_view foo("foo"), bar("bar"); SymbolPtr tree1 = Node(Leaf(1, bar), Leaf(2, foo)); SymbolPtr tree2 = Node(Leaf(1, bar), Leaf(2, foo)); EXPECT_TRUE(EqualTrees(tree1.get(), tree2.get())); @@ -212,7 +213,7 @@ TEST(TreeEqualityTest, ExactEqualPerfectMatch) { // Test for mismatch on different leaf tag. TEST(TreeEqualityTest, ExactEqualMismatchLeafTag) { - constexpr absl::string_view foo("foo"), bar("bar"); + constexpr std::string_view foo("foo"), bar("bar"); SymbolPtr tree1 = Node(Leaf(1, bar), Leaf(2, foo)); SymbolPtr tree2 = Node(Leaf(1, bar), Leaf(3, foo)); EXPECT_FALSE(EqualTrees(tree1.get(), tree2.get())); @@ -221,9 +222,9 @@ TEST(TreeEqualityTest, ExactEqualMismatchLeafTag) { // Test for mismatch on different token location. TEST(TreeEqualityTest, ExactEqualMismatchTokenLocation) { - constexpr absl::string_view bar("barbar"), foo("foo"); + constexpr std::string_view bar("barbar"), foo("foo"); // guarantee different ranges - const absl::string_view bar1(bar.substr(0, 3)), bar2(bar.substr(3, 3)); + const std::string_view bar1(bar.substr(0, 3)), bar2(bar.substr(3, 3)); SymbolPtr tree1 = Node(Leaf(1, bar1), Leaf(2, foo)); SymbolPtr tree2 = Node(Leaf(1, bar2), Leaf(2, foo)); EXPECT_FALSE(EqualTrees(tree1.get(), tree2.get())); @@ -232,7 +233,7 @@ TEST(TreeEqualityTest, ExactEqualMismatchTokenLocation) { // Test for mismatch on different token text. TEST(TreeEqualityTest, ExactEqualMismatchTokenText) { - constexpr absl::string_view bar("bar"), foo1("foo"), foo2("f00"); + constexpr std::string_view bar("bar"), foo1("foo"), foo2("f00"); SymbolPtr tree1 = Node(Leaf(1, bar), Leaf(2, foo1)); SymbolPtr tree2 = Node(Leaf(1, bar), Leaf(2, foo2)); EXPECT_FALSE(EqualTrees(tree1.get(), tree2.get())); diff --git a/verible/common/text/tree-context-visitor_test.cc b/verible/common/text/tree-context-visitor_test.cc index 6301f7f46..496c53182 100644 --- a/verible/common/text/tree-context-visitor_test.cc +++ b/verible/common/text/tree-context-visitor_test.cc @@ -15,10 +15,10 @@ #include "verible/common/text/tree-context-visitor.h" #include +#include #include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/text/concrete-syntax-leaf.h" @@ -331,7 +331,7 @@ TEST(NextSiblingPathTest, Various) { } TEST(TreePathFormatterTest, Various) { - const std::pair kTestCases[] = { + const std::pair kTestCases[] = { {{}, "[]"}, // {{0}, "[0]"}, // {{1}, "[1]"}, // diff --git a/verible/common/text/tree-utils.cc b/verible/common/text/tree-utils.cc index b15e59d21..cadd313f9 100644 --- a/verible/common/text/tree-utils.cc +++ b/verible/common/text/tree-utils.cc @@ -19,11 +19,11 @@ #include #include #include +#include #include #include "absl/log/check.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/symbol.h" @@ -89,18 +89,18 @@ const SyntaxTreeLeaf *GetLeftmostLeaf(const Symbol &symbol) { return nullptr; } -absl::string_view StringSpanOfSymbol(const Symbol &symbol) { +std::string_view StringSpanOfSymbol(const Symbol &symbol) { return StringSpanOfSymbol(symbol, symbol); } -absl::string_view StringSpanOfSymbol(const Symbol &lsym, const Symbol &rsym) { +std::string_view StringSpanOfSymbol(const Symbol &lsym, const Symbol &rsym) { const auto *left = GetLeftmostLeaf(lsym); const auto *right = GetRightmostLeaf(rsym); if (left != nullptr && right != nullptr) { const auto range_begin = left->get().text().begin(); const auto range_end = right->get().text().end(); - return absl::string_view(&*range_begin, - std::distance(range_begin, range_end)); + return std::string_view(&*range_begin, + std::distance(range_begin, range_end)); } return ""; } @@ -271,7 +271,7 @@ const Symbol *FindLastSubtree(const Symbol *tree, const TreePredicate &pred) { ConcreteSyntaxTree *FindSubtreeStartingAtOffset( ConcreteSyntaxTree *tree, - absl::string_view::const_iterator first_token_offset) { + std::string_view::const_iterator first_token_offset) { auto predicate = [=](const Symbol &s) { const SyntaxTreeLeaf *leftmost = GetLeftmostLeaf(s); if (leftmost != nullptr) { @@ -294,7 +294,7 @@ ConcreteSyntaxTree *FindSubtreeStartingAtOffset( namespace { // Returns true if this node should be deleted by parent (pop_back). bool PruneTreeFromRight(ConcreteSyntaxTree *tree, - absl::string_view::const_iterator offset) { + std::string_view::const_iterator offset) { const auto kind = (*ABSL_DIE_IF_NULL(tree))->Kind(); switch (kind) { case SymbolKind::kLeaf: { @@ -332,14 +332,14 @@ bool PruneTreeFromRight(ConcreteSyntaxTree *tree, } // namespace void PruneSyntaxTreeAfterOffset(ConcreteSyntaxTree *tree, - absl::string_view::const_iterator offset) { + std::string_view::const_iterator offset) { PruneTreeFromRight(tree, offset); } // Helper functions for ZoomSyntaxTree namespace { // Return the upper bound offset of the rightmost token in the tree. -absl::string_view::const_iterator RightmostOffset(const Symbol &symbol) { +std::string_view::const_iterator RightmostOffset(const Symbol &symbol) { const SyntaxTreeLeaf *leaf_ptr = verible::GetRightmostLeaf(symbol); return ABSL_DIE_IF_NULL(leaf_ptr)->get().text().end(); } @@ -359,7 +359,7 @@ ConcreteSyntaxTree *LeftSubtree(ConcreteSyntaxTree *tree) { } // namespace ConcreteSyntaxTree *ZoomSyntaxTree(ConcreteSyntaxTree *tree, - absl::string_view trim_range) { + std::string_view trim_range) { if (*tree == nullptr) return nullptr; const auto left_offset = trim_range.begin(); @@ -376,7 +376,7 @@ ConcreteSyntaxTree *ZoomSyntaxTree(ConcreteSyntaxTree *tree, return match; } -void TrimSyntaxTree(ConcreteSyntaxTree *tree, absl::string_view trim_range) { +void TrimSyntaxTree(ConcreteSyntaxTree *tree, std::string_view trim_range) { auto *replacement = ZoomSyntaxTree(tree, trim_range); if (replacement == nullptr || *replacement == nullptr) { *tree = nullptr; diff --git a/verible/common/text/tree-utils.h b/verible/common/text/tree-utils.h index 3fb72812c..a69cfaa01 100644 --- a/verible/common/text/tree-utils.h +++ b/verible/common/text/tree-utils.h @@ -20,8 +20,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/symbol.h" @@ -41,10 +41,10 @@ const SyntaxTreeLeaf *GetLeftmostLeaf(const Symbol &symbol); const SyntaxTreeLeaf *GetRightmostLeaf(const Symbol &symbol); // Returns the range of text spanned by a Symbol, which could be a subtree. -absl::string_view StringSpanOfSymbol(const Symbol &symbol); +std::string_view StringSpanOfSymbol(const Symbol &symbol); // Variant that takes the left-bound of lsym, and right-bound of rsym. -absl::string_view StringSpanOfSymbol(const Symbol &lsym, const Symbol &rsym); +std::string_view StringSpanOfSymbol(const Symbol &lsym, const Symbol &rsym); // Returns a SyntaxTreeNode down_casted from a Symbol. const SyntaxTreeNode &SymbolCastToNode(const Symbol &); @@ -268,7 +268,7 @@ const Symbol *FindLastSubtree(const Symbol *, const TreePredicate &); // Both the tree and the returned tree are intended to be mutable. ConcreteSyntaxTree *FindSubtreeStartingAtOffset( ConcreteSyntaxTree *tree, - absl::string_view::const_iterator first_token_offset); + std::string_view::const_iterator first_token_offset); // Cuts out all nodes and leaves that start at or past the given offset. // This only looks at leaves' location offsets, and not actual text. @@ -277,7 +277,7 @@ ConcreteSyntaxTree *FindSubtreeStartingAtOffset( // tree must not be null. // This will never prune away the root node. void PruneSyntaxTreeAfterOffset(ConcreteSyntaxTree *tree, - absl::string_view::const_iterator offset); + std::string_view::const_iterator offset); // Returns the pointer to the largest subtree wholly contained // inside the text range spanned by trim_range. @@ -285,10 +285,10 @@ void PruneSyntaxTreeAfterOffset(ConcreteSyntaxTree *tree, // If there are multiple eligible subtrees in range, then this chooses the // first one. ConcreteSyntaxTree *ZoomSyntaxTree(ConcreteSyntaxTree *tree, - absl::string_view trim_range); + std::string_view trim_range); // Same as ZoomSyntaxTree(), except that it modifies 'tree' in-place. -void TrimSyntaxTree(ConcreteSyntaxTree *tree, absl::string_view trim_range); +void TrimSyntaxTree(ConcreteSyntaxTree *tree, std::string_view trim_range); using LeafMutator = std::function; diff --git a/verible/common/text/tree-utils_test.cc b/verible/common/text/tree-utils_test.cc index b22bbdc28..ace228482 100644 --- a/verible/common/text/tree-utils_test.cc +++ b/verible/common/text/tree-utils_test.cc @@ -18,8 +18,8 @@ #include #include #include // IWYU pragma: keep // for ostringstream +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -119,7 +119,7 @@ TEST(DescendThroughSingletonsTest, NodeFirstChildNodeSecondChildNull) { EXPECT_EQ(node.get(), DescendThroughSingletons(*node)); } -static constexpr absl::string_view kTestToken[] = { +static constexpr std::string_view kTestToken[] = { "test_token1", "test_token2", "test_token3", @@ -225,7 +225,7 @@ TEST(StringSpanOfSymbolTest, DeepEmptyTree) { } TEST(StringSpanOfSymbolTest, LeafOnlyEmptyText) { - constexpr absl::string_view text; + constexpr std::string_view text; SymbolPtr symbol = Leaf(1, text); const auto range = StringSpanOfSymbol(*symbol); EXPECT_TRUE(range.empty()); @@ -233,21 +233,21 @@ TEST(StringSpanOfSymbolTest, LeafOnlyEmptyText) { } TEST(StringSpanOfSymbolTest, LeafOnlyNonemptyText) { - constexpr absl::string_view text("asdfg"); + constexpr std::string_view text("asdfg"); SymbolPtr symbol = Leaf(1, text); const auto range = StringSpanOfSymbol(*symbol); EXPECT_TRUE(BoundsEqual(range, text)); } TEST(StringSpanOfSymbolTest, DeepLeafOnlyEmptyText) { - constexpr absl::string_view text; + constexpr std::string_view text; SymbolPtr symbol = Node(Node(Leaf(1, text))); const auto range = StringSpanOfSymbol(*symbol); EXPECT_TRUE(BoundsEqual(range, text)); } TEST(StringSpanOfSymbolTest, TwoLeavesOneTree) { - constexpr absl::string_view text("aaabbb"); + constexpr std::string_view text("aaabbb"); SymbolPtr symbol = Node(Node(Leaf(1, text.substr(0, 3))), Node(Leaf(2, text.substr(3, 3)))); const auto range = StringSpanOfSymbol(*symbol); @@ -255,7 +255,7 @@ TEST(StringSpanOfSymbolTest, TwoLeavesOneTree) { } TEST(StringSpanOfSymbolTest, TwoAbuttingLeavesTwoTrees) { - constexpr absl::string_view text("aaabbb"); + constexpr std::string_view text("aaabbb"); SymbolPtr lsymbol = Node(Node(Leaf(1, text.substr(0, 3)))); SymbolPtr rsymbol = Node(Node(Leaf(1, text.substr(3, 3)))); const auto range = StringSpanOfSymbol(*lsymbol, *rsymbol); @@ -263,7 +263,7 @@ TEST(StringSpanOfSymbolTest, TwoAbuttingLeavesTwoTrees) { } TEST(StringSpanOfSymbolTest, TwoDisjointLeavesTwoTrees) { - constexpr absl::string_view text("aaabbb"); + constexpr std::string_view text("aaabbb"); SymbolPtr lsymbol = Node(Node(Leaf(1, text.substr(0, 2)))); SymbolPtr rsymbol = Node(Node(Leaf(1, text.substr(4, 2)))); const auto range = StringSpanOfSymbol(*lsymbol, *rsymbol); @@ -271,14 +271,14 @@ TEST(StringSpanOfSymbolTest, TwoDisjointLeavesTwoTrees) { } TEST(TreePrintTest, RawPrint) { - constexpr absl::string_view text("leaf 1 leaf 2 leaf 3 leaf 4"); + constexpr std::string_view text("leaf 1 leaf 2 leaf 3 leaf 4"); SymbolPtr tree = Node(Leaf(0, text.substr(0, 6)), // Node( // Leaf(1, text.substr(7, 6)), // Leaf(2, text.substr(14, 6))), // Leaf(3, text.substr(21, 6))); // Output excludes byte offsets. - constexpr absl::string_view expected = + constexpr std::string_view expected = "Node @0 {\n" " Leaf @0 (#0: \"leaf 1\")\n" " Node @1 {\n" @@ -293,7 +293,7 @@ TEST(TreePrintTest, RawPrint) { } TEST(TreePrintTest, RawPrintNullptrPrinting) { - constexpr absl::string_view text("leaf 1 leaf 2 leaf 3 leaf 4"); + constexpr std::string_view text("leaf 1 leaf 2 leaf 3 leaf 4"); SymbolPtr tree = Node(nullptr, // Leaf(0, text.substr(0, 6)), // nullptr, // @@ -306,7 +306,7 @@ TEST(TreePrintTest, RawPrintNullptrPrinting) { nullptr); { // Output excludes byte offsets. - constexpr absl::string_view expected = + constexpr std::string_view expected = "Node @0 {\n" " Leaf @1 (#0: \"leaf 1\")\n" " Node @3 {\n" @@ -321,7 +321,7 @@ TEST(TreePrintTest, RawPrintNullptrPrinting) { } { // Now the same, but with nullptr printing enabled. - constexpr absl::string_view expected = + constexpr std::string_view expected = "Node @0 {\n" " NULL @0\n" " Leaf @1 (#0: \"leaf 1\")\n" @@ -342,7 +342,7 @@ TEST(TreePrintTest, RawPrintNullptrPrinting) { } TEST(TreePrintTest, PrettyPrint) { - constexpr absl::string_view text("leaf 1 leaf 2 leaf 3 leaf 4"); + constexpr std::string_view text("leaf 1 leaf 2 leaf 3 leaf 4"); SymbolPtr tree = Node( // Leaf(0, text.substr(0, 6)), // Node( // @@ -350,7 +350,7 @@ TEST(TreePrintTest, PrettyPrint) { Leaf(2, text.substr(14, 6))), // Leaf(3, text.substr(21, 6))); // Output includes byte offsets. - constexpr absl::string_view expected = + constexpr std::string_view expected = "Node @0 {\n" " Leaf @0 (#0 @0-6: \"leaf 1\")\n" " Node @1 {\n" @@ -374,7 +374,7 @@ TEST(TreePrintTest, PrettyPrint) { } TEST(TreePrintTest, PrettyPrintSkipNullptrs) { - constexpr absl::string_view text("leaf 1 leaf 2 leaf 3 leaf 4"); + constexpr std::string_view text("leaf 1 leaf 2 leaf 3 leaf 4"); SymbolPtr tree = Node( // Leaf(0, text.substr(0, 6)), // nullptr, // @@ -388,7 +388,7 @@ TEST(TreePrintTest, PrettyPrintSkipNullptrs) { nullptr, // Leaf(3, text.substr(21, 6))); // Output includes byte offsets. - constexpr absl::string_view expected = + constexpr std::string_view expected = "Node @0 {\n" " Leaf @0 (#0 @0-6: \"leaf 1\")\n" " Node @3 {\n" @@ -809,8 +809,8 @@ TEST(FindLastSubtreeTest, MatchLeaf) { // FindSubtreeStartingAtOffset tests -constexpr absl::string_view kFindSubtreeTestText("abcdef"); -const absl::string_view kFindSubtreeTestSubstring( +constexpr std::string_view kFindSubtreeTestText("abcdef"); +const std::string_view kFindSubtreeTestSubstring( kFindSubtreeTestText.substr(1, 3)); struct FindSubtreeStartingAtOffsetTest : public testing::Test { @@ -841,9 +841,9 @@ TEST_F(FindSubtreeStartingAtOffsetTest, LeafOnlyOffsetGreaterThan) { } // Allow to look beyond kBaseText by cutting it out of a larger string. -constexpr absl::string_view kBaseTextPadded("_abcdefghijklmnopqrst_"); -constexpr absl::string_view kBaseText = {kBaseTextPadded.data() + 1, - kBaseTextPadded.length() - 2}; +constexpr std::string_view kBaseTextPadded("_abcdefghijklmnopqrst_"); +constexpr std::string_view kBaseText = {kBaseTextPadded.data() + 1, + kBaseTextPadded.length() - 2}; // Return a tree with monotonically increasing token locations. // This is suitable for tests that require only location offsets, @@ -1007,7 +1007,7 @@ TEST(MutateLeavesTest, NodeAndLeaves) { // Test that a leafless root node is not pruned. TEST(PruneSyntaxTreeAfterOffsetTest, LeaflessRootNode) { - constexpr absl::string_view text; + constexpr std::string_view text; SymbolPtr tree = Node(); SymbolPtr expect = Node(); // distinct copy PruneSyntaxTreeAfterOffset(&tree, text.begin()); @@ -1016,7 +1016,7 @@ TEST(PruneSyntaxTreeAfterOffsetTest, LeaflessRootNode) { // Test that a root leaf is never pruned. TEST(PruneSyntaxTreeAfterOffsetTest, RootLeafNeverRemoved) { - constexpr absl::string_view text("baz"); + constexpr std::string_view text("baz"); SymbolPtr tree = Leaf(1, text); SymbolPtr expect = Leaf(1, text); // distinct copy PruneSyntaxTreeAfterOffset(&tree, text.begin()); @@ -1025,7 +1025,7 @@ TEST(PruneSyntaxTreeAfterOffsetTest, RootLeafNeverRemoved) { // Test that a leafless tree is pruned down to the root. TEST(PruneSyntaxTreeAfterOffsetTest, EmptyNodes) { - constexpr absl::string_view text("baz"); + constexpr std::string_view text("baz"); SymbolPtr tree = Node(TNode(1), TNode(1, TNode(0), TNode(3)), TNode(2)); SymbolPtr expect = Node(); PruneSyntaxTreeAfterOffset(&tree, text.begin()); @@ -1042,8 +1042,8 @@ TEST(PruneSyntaxTreeAfterOffsetTest, AtEndPrunesNothing) { // Test that trailing nullptr nodes are pruned. TEST(PruneSyntaxTreeAfterOffsetTest, PruneTrailingNullNodes) { - constexpr absl::string_view text("foo bar"); - const absl::string_view foo(text.substr(0, 3)), bar(text.substr(4, 3)); + constexpr std::string_view text("foo bar"); + const std::string_view foo(text.substr(0, 3)), bar(text.substr(4, 3)); SymbolPtr tree = TNode(0, // noformat nullptr, // noformat Leaf(1, foo), // noformat @@ -1061,8 +1061,8 @@ TEST(PruneSyntaxTreeAfterOffsetTest, PruneTrailingNullNodes) { // Test that trailing nullptr nodes are pruned recursively. TEST(PruneSyntaxTreeAfterOffsetTest, PruneTrailingNullNodesRecursive) { - constexpr absl::string_view text("foo bar BQ"); - const absl::string_view foo(text.substr(0, 3)), bar(text.substr(4, 3)), + constexpr std::string_view text("foo bar BQ"); + const std::string_view foo(text.substr(0, 3)), bar(text.substr(4, 3)), bq(text.substr(8, 2)); SymbolPtr tree = TNode(0, // noformat nullptr, // noformat @@ -1168,7 +1168,7 @@ TEST(PruneSyntaxTreeAfterOffsetTest, DeleteAll) { // Test that root node without leaves is cleared because no locations match. TEST(TrimSyntaxTreeTest, RootNodeOnly) { - constexpr absl::string_view range; + constexpr std::string_view range; SymbolPtr tree = Node(); TrimSyntaxTree(&tree, range); EXPECT_EQ(tree, nullptr); @@ -1176,7 +1176,7 @@ TEST(TrimSyntaxTreeTest, RootNodeOnly) { // Test that tree without leaves is cleared because no locations match. TEST(TrimSyntaxTreeTest, TreeNoLeaves) { - constexpr absl::string_view range; + constexpr std::string_view range; SymbolPtr tree = Node(TNode(4), TNode(3, TNode(1), TNode(2)), TNode(0)); TrimSyntaxTree(&tree, range); EXPECT_EQ(tree, nullptr); @@ -1184,8 +1184,8 @@ TEST(TrimSyntaxTreeTest, TreeNoLeaves) { // Test that tree with one leaf is preserved in the enclosing range. TEST(TrimSyntaxTreeTest, OneLeafNotTrimmed) { - constexpr absl::string_view text("ddddddddddddddd"); - const absl::string_view token(text.substr(5, 5)); + constexpr std::string_view text("ddddddddddddddd"); + const std::string_view token(text.substr(5, 5)); const SymbolPtr expect = Node(TNode(3, Leaf(1, token))); for (int left = 4; left <= 5; ++left) { for (int right = 10; right <= 11; ++right) { @@ -1198,8 +1198,8 @@ TEST(TrimSyntaxTreeTest, OneLeafNotTrimmed) { // Test that tree with one leaf is trimmed correctly (right bound). TEST(TrimSyntaxTreeTest, OneLeafTrimmedFromRight) { - constexpr absl::string_view text("ddddddddddddddd"); - const absl::string_view token(text.substr(5, 5)); + constexpr std::string_view text("ddddddddddddddd"); + const std::string_view token(text.substr(5, 5)); for (int left = 4; left <= 5; ++left) { SymbolPtr tree = Node(TNode(3, Leaf(1, token))); TrimSyntaxTree(&tree, text.substr(left, 9 - left)); @@ -1209,8 +1209,8 @@ TEST(TrimSyntaxTreeTest, OneLeafTrimmedFromRight) { // Test that tree with one leaf is trimmed correctly (left bound). TEST(TrimSyntaxTreeTest, OneLeafTrimmedFromLeft) { - constexpr absl::string_view text("ddddddddddddddd"); - const absl::string_view token(text.substr(5, 5)); + constexpr std::string_view text("ddddddddddddddd"); + const std::string_view token(text.substr(5, 5)); for (int right = 10; right <= 11; ++right) { SymbolPtr tree = Node(TNode(3, Leaf(1, token))); TrimSyntaxTree(&tree, text.substr(6, right - 6)); @@ -1229,7 +1229,7 @@ TEST(TrimSyntaxTreeTest, OutOfRangeLeft) { // Test that out-of-range (on right) yields a null tree. TEST(TrimSyntaxTreeTest, OutOfRangeRight) { - constexpr absl::string_view text("dddddddddddddddddddddddddd"); + constexpr std::string_view text("dddddddddddddddddddddddddd"); SymbolPtr tree = FakeSyntaxTree(); // Can't test right beyond 17, because string_view raises a bounds // check error. diff --git a/verible/common/tools/BUILD b/verible/common/tools/BUILD index 7f0b1e6bf..61b4d445a 100644 --- a/verible/common/tools/BUILD +++ b/verible/common/tools/BUILD @@ -30,7 +30,6 @@ cc_binary( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/common/tools/patch-tool.cc b/verible/common/tools/patch-tool.cc index 37b167eb6..22c9bc961 100644 --- a/verible/common/tools/patch-tool.cc +++ b/verible/common/tools/patch-tool.cc @@ -15,13 +15,13 @@ #include #include #include +#include #include #include "absl/flags/usage.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/patch.h" #include "verible/common/util/file-util.h" #include "verible/common/util/init-command-line.h" @@ -39,7 +39,7 @@ static absl::Status ChangedLines(const SubcommandArgsRange &args, return absl::InvalidArgumentError( "Missing patchfile argument. Use '-' for stdin."); } - const absl::string_view patchfile = args[0]; + const std::string_view patchfile = args[0]; auto patch_content_or = verible::file::GetContentAsString(patchfile); if (!patch_content_or.ok()) return patch_content_or.status(); @@ -64,7 +64,7 @@ static absl::Status ApplyPick(const SubcommandArgsRange &args, if (args.empty()) { return absl::InvalidArgumentError("Missing patchfile argument."); } - const absl::string_view patchfile = args[0]; + const std::string_view patchfile = args[0]; absl::StatusOr patch_contents_or; patch_contents_or = verible::file::GetContentAsString(patchfile); if (!patch_contents_or.ok()) return patch_contents_or.status(); @@ -120,7 +120,7 @@ static absl::Status CatTest(const SubcommandArgsRange &args, std::istream &ins, return absl::OkStatus(); } -static const std::pair kCommands[] = { +static const std::pair kCommands[] = { {"changed-lines", // {&ChangedLines, // R"(changed-lines patchfile diff --git a/verible/common/util/BUILD b/verible/common/util/BUILD index ca7f62e2e..945fea3bf 100644 --- a/verible/common/util/BUILD +++ b/verible/common/util/BUILD @@ -49,7 +49,6 @@ cc_library( "//verible/common/strings:compare", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -74,7 +73,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -114,7 +112,6 @@ cc_library( "@abseil-cpp//absl/base:log_severity", "@abseil-cpp//absl/log:initialize", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@abseil-cpp//absl/time", ], ) @@ -125,7 +122,6 @@ cc_library( deps = [ ":forward", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -148,7 +144,6 @@ cc_library( ":logging", "@abseil-cpp//absl/random", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -235,7 +230,6 @@ cc_library( ":bijective-map", "//verible/common/strings:compare", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -285,7 +279,6 @@ cc_library( deps = [ ":tree-operations", ":vector-tree", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", # for library testonly ], ) @@ -318,7 +311,6 @@ cc_library( name = "user-interaction", srcs = ["user-interaction.cc"], hdrs = ["user-interaction.h"], - deps = ["@abseil-cpp//absl/strings:string_view"], ) cc_library( @@ -332,7 +324,6 @@ cc_test( deps = [ ":algorithm", ":iterator-range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -367,7 +358,6 @@ cc_test( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -389,7 +379,6 @@ cc_test( deps = [ ":interval-map", ":range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -402,7 +391,6 @@ cc_test( ":interval", ":interval-set", ":logging", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -413,7 +401,6 @@ cc_test( srcs = ["forward_test.cc"], deps = [ ":forward", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -425,7 +412,6 @@ cc_test( deps = [ ":iterator-range", ":range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -496,7 +482,6 @@ cc_test( ":subcommand", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -538,7 +523,6 @@ cc_test( deps = [ ":enum-flags", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -551,7 +535,6 @@ cc_test( ":bijective-map", ":logging", "//verible/common/strings:compare", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -566,7 +549,6 @@ cc_test( ":vector-tree", ":vector-tree-test-util", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -608,7 +590,6 @@ cc_test( ":vector-tree", ":vector-tree-test-util", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -637,7 +618,6 @@ cc_test( deps = [ ":map-tree", ":spacer", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -693,7 +673,6 @@ cc_test( deps = [ ":file-util", ":simple-zip", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -703,10 +682,7 @@ cc_library( name = "sha256", srcs = ["sha256.cc"], hdrs = ["sha256.h"], - deps = [ - "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", - ], + deps = ["@abseil-cpp//absl/strings"], ) cc_test( @@ -715,7 +691,6 @@ cc_test( deps = [ ":sha256", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/common/util/algorithm_test.cc b/verible/common/util/algorithm_test.cc index 21389eb95..e75b43f58 100644 --- a/verible/common/util/algorithm_test.cc +++ b/verible/common/util/algorithm_test.cc @@ -18,9 +18,9 @@ #include // for std::back_inserter #include #include +#include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/util/iterator-range.h" @@ -41,7 +41,7 @@ int CharCompare(int i, char c) { TEST(SetSymmetricDifferenceSplitTest, EmptyInputs) { std::vector seq1, diff1; - absl::string_view seq2; + std::string_view seq2; std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -52,7 +52,7 @@ TEST(SetSymmetricDifferenceSplitTest, EmptyInputs) { TEST(SetSymmetricDifferenceSplitTest, EmptyInputsPreallocatedOutput) { std::vector seq1, diff1(3); - absl::string_view seq2; + std::string_view seq2; std::string diff2(3, 'x'); auto p = set_symmetric_difference_split( seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), diff1.begin(), @@ -63,7 +63,7 @@ TEST(SetSymmetricDifferenceSplitTest, EmptyInputsPreallocatedOutput) { TEST(SetSymmetricDifferenceSplitTest, FirstSequenceEmpty) { std::vector seq1, diff1; - absl::string_view seq2("ace"); + std::string_view seq2("ace"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -74,7 +74,7 @@ TEST(SetSymmetricDifferenceSplitTest, FirstSequenceEmpty) { TEST(SetSymmetricDifferenceSplitTest, FirstSequenceEmptyPreallocatedOutput) { std::vector seq1, diff1(3); - absl::string_view seq2("ace"); + std::string_view seq2("ace"); std::string diff2(4, 'x'); auto p = set_symmetric_difference_split( seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), diff1.begin(), @@ -86,7 +86,7 @@ TEST(SetSymmetricDifferenceSplitTest, FirstSequenceEmptyPreallocatedOutput) { TEST(SetSymmetricDifferenceSplitTest, SecondSequenceEmpty) { std::vector seq1({2, 4, 6}), diff1; - absl::string_view seq2; + std::string_view seq2; std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -97,7 +97,7 @@ TEST(SetSymmetricDifferenceSplitTest, SecondSequenceEmpty) { TEST(SetSymmetricDifferenceSplitTest, SecondSequenceEmptyPreallocatedOutput) { std::vector seq1({2, 4, 6}), diff1(3); - absl::string_view seq2; + std::string_view seq2; std::string diff2(3, 'x'); auto p = set_symmetric_difference_split( seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), diff1.begin(), @@ -109,7 +109,7 @@ TEST(SetSymmetricDifferenceSplitTest, SecondSequenceEmptyPreallocatedOutput) { TEST(SetSymmetricDifferenceSplitTest, CompleteMatch) { std::vector seq1({2, 4, 6}), diff1; - absl::string_view seq2("bdf"); + std::string_view seq2("bdf"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -120,7 +120,7 @@ TEST(SetSymmetricDifferenceSplitTest, CompleteMatch) { TEST(SetSymmetricDifferenceSplitTest, CompleteMatchPreallocatedOutput) { std::vector seq1({2, 4, 6}), diff1(3); - absl::string_view seq2("bdf"); + std::string_view seq2("bdf"); std::string diff2(3, 'x'); auto p = set_symmetric_difference_split( seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), diff1.begin(), @@ -131,7 +131,7 @@ TEST(SetSymmetricDifferenceSplitTest, CompleteMatchPreallocatedOutput) { TEST(SetSymmetricDifferenceSplitTest, CompleteMismatchInterleaved) { std::vector seq1({3, 5, 7}), diff1; - absl::string_view seq2("bdf"); + std::string_view seq2("bdf"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -142,7 +142,7 @@ TEST(SetSymmetricDifferenceSplitTest, CompleteMismatchInterleaved) { TEST(SetSymmetricDifferenceSplitTest, CompleteMismatchNonoverlapping1) { std::vector seq1({7, 8, 9}), diff1; - absl::string_view seq2("bdf"); + std::string_view seq2("bdf"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -153,7 +153,7 @@ TEST(SetSymmetricDifferenceSplitTest, CompleteMismatchNonoverlapping1) { TEST(SetSymmetricDifferenceSplitTest, CompleteMismatchNonoverlapping2) { std::vector seq1({1, 2, 4}), diff1; - absl::string_view seq2("xyz"); + std::string_view seq2("xyz"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -164,7 +164,7 @@ TEST(SetSymmetricDifferenceSplitTest, CompleteMismatchNonoverlapping2) { TEST(SetSymmetricDifferenceSplitTest, PartialMatch1) { std::vector seq1({2, 3, 6}), diff1; - absl::string_view seq2("bdf"); + std::string_view seq2("bdf"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -175,7 +175,7 @@ TEST(SetSymmetricDifferenceSplitTest, PartialMatch1) { TEST(SetSymmetricDifferenceSplitTest, PartialMatch1PreallocatedOutput) { std::vector seq1({2, 3, 6}), diff1(3); - absl::string_view seq2("bdf"); + std::string_view seq2("bdf"); std::string diff2(3, 'x'); auto p = set_symmetric_difference_split( seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), diff1.begin(), @@ -188,7 +188,7 @@ TEST(SetSymmetricDifferenceSplitTest, PartialMatch1PreallocatedOutput) { TEST(SetSymmetricDifferenceSplitTest, PartialMatch2) { std::vector seq1({1, 4, 5}), diff1; - absl::string_view seq2("bdf"); + std::string_view seq2("bdf"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -199,7 +199,7 @@ TEST(SetSymmetricDifferenceSplitTest, PartialMatch2) { TEST(SetSymmetricDifferenceSplitTest, CompleteSubset) { std::vector seq1({2, 4, 6}), diff1; - absl::string_view seq2("bcdf"); + std::string_view seq2("bcdf"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -210,7 +210,7 @@ TEST(SetSymmetricDifferenceSplitTest, CompleteSubset) { TEST(SetSymmetricDifferenceSplitTest, CompleteSubset2) { std::vector seq1({2, 4, 5, 6}), diff1; - absl::string_view seq2("bdf"); + std::string_view seq2("bdf"); std::string diff2; set_symmetric_difference_split(seq1.begin(), seq1.end(), seq2.begin(), seq2.end(), std::back_inserter(diff1), @@ -295,8 +295,8 @@ TEST(FindAllTest, PartitionAfterEveryZero2) { } TEST(FindAllTest, StrSplitAtEqual) { - const absl::string_view seq("aa=b=cc"); - std::vector bounds; + const std::string_view seq("aa=b=cc"); + std::vector bounds; find_all(seq.begin(), seq.end(), std::back_inserter(bounds), [](char i) { return i == '='; }); const auto b = seq.begin(); @@ -304,8 +304,8 @@ TEST(FindAllTest, StrSplitAtEqual) { } TEST(FindAllTest, StrSplitAfterEqual) { - const absl::string_view seq("aa=b=cd"); - std::vector bounds; + const std::string_view seq("aa=b=cd"); + std::vector bounds; char prev = 0; find_all(seq.begin(), seq.end(), std::back_inserter(bounds), [&](char i) { // Split *after* each '='. @@ -337,8 +337,8 @@ class EveryN { }; TEST(FindAllTest, StrSplitEveryN) { - const absl::string_view seq("xxxxyyyyaaaabbb"); - std::vector bounds; + const std::string_view seq("xxxxyyyyaaaabbb"); + std::vector bounds; find_all(seq.begin(), seq.end(), std::back_inserter(bounds), EveryN(4)); const auto b = seq.begin(); EXPECT_THAT(bounds, ElementsAre(b + 4, b + 8, b + 12)); diff --git a/verible/common/util/bijective-map_test.cc b/verible/common/util/bijective-map_test.cc index 8f283a73e..e4a614eaa 100644 --- a/verible/common/util/bijective-map_test.cc +++ b/verible/common/util/bijective-map_test.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/strings/compare.h" #include "verible/common/util/logging.h" @@ -159,7 +159,7 @@ TEST(BijectiveMapTest, InsertRandom) { } // Testing heterogenous lookup: internally stored std::string, supporting -// copy-less lookup with absl::string_view. +// copy-less lookup with std::string_view. using StringMapType = BijectiveMap; @@ -167,12 +167,12 @@ TEST(BijectiveMapTest, HeterogeneousStringLookup) { StringMapType m; EXPECT_TRUE(m.insert("a", "G")); EXPECT_TRUE(m.insert("z", "Q")); - EXPECT_EQ(*ABSL_DIE_IF_NULL(m.find_forward(absl::string_view("a"))), "G"); - EXPECT_EQ(*ABSL_DIE_IF_NULL(m.find_reverse(absl::string_view("G"))), "a"); - EXPECT_EQ(*ABSL_DIE_IF_NULL(m.find_forward(absl::string_view("z"))), "Q"); - EXPECT_EQ(*ABSL_DIE_IF_NULL(m.find_reverse(absl::string_view("Q"))), "z"); - EXPECT_EQ(m.find_forward(absl::string_view("b")), nullptr); - EXPECT_EQ(m.find_reverse(absl::string_view("3")), nullptr); + EXPECT_EQ(*ABSL_DIE_IF_NULL(m.find_forward(std::string_view("a"))), "G"); + EXPECT_EQ(*ABSL_DIE_IF_NULL(m.find_reverse(std::string_view("G"))), "a"); + EXPECT_EQ(*ABSL_DIE_IF_NULL(m.find_forward(std::string_view("z"))), "Q"); + EXPECT_EQ(*ABSL_DIE_IF_NULL(m.find_reverse(std::string_view("Q"))), "z"); + EXPECT_EQ(m.find_forward(std::string_view("b")), nullptr); + EXPECT_EQ(m.find_reverse(std::string_view("3")), nullptr); } } // namespace diff --git a/verible/common/util/enum-flags.h b/verible/common/util/enum-flags.h index 0a8dd0c2b..d50563b27 100644 --- a/verible/common/util/enum-flags.h +++ b/verible/common/util/enum-flags.h @@ -19,10 +19,10 @@ #include #include #include +#include #include #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/compare.h" #include "verible/common/util/bijective-map.h" @@ -63,7 +63,7 @@ enum class MyEnumType { ... }; std::ostream& operator<<(std::ostream& stream, MyEnumType p); // If making this usable as an absl flag, provide the following overloads: -bool AbslParseFlag(absl::string_view text, MyEnumType* mode, +bool AbslParseFlag(std::string_view text, MyEnumType* mode, std::string* error); std::string AbslUnparseFlag(const MyEnumType& mode); @@ -79,7 +79,7 @@ std::ostream& operator<<(std::ostream& stream, MyEnumType p) { return MyEnumTypeNames.Unparse(p, stream); } -bool AbslParseFlag(absl::string_view text, MyEnumType* mode, +bool AbslParseFlag(std::string_view text, MyEnumType* mode, std::string* error) { return kLanguageModeStringMap.Parse(text, mode, error, "MyEnumType"); } @@ -96,7 +96,7 @@ class EnumNameMap { // Using a string_view is safe when the string-memory owned elsewhere is // guaranteed to outlive objects of this class. // String-literals are acceptable sources of string_views for this purpose. - using key_type = absl::string_view; + using key_type = std::string_view; // Storage type for mapping information. // StringViewCompare gives the benefit of copy-free heterogeneous lookup. @@ -116,7 +116,7 @@ class EnumNameMap { EnumNameMap &operator=(EnumNameMap &&) = delete; // Print a list of string representations of the enums. - std::ostream &ListNames(std::ostream &stream, absl::string_view sep) const { + std::ostream &ListNames(std::ostream &stream, std::string_view sep) const { return stream << absl::StrJoin(enum_name_map_.forward_view(), sep, internal::FirstElementFormatter()); } @@ -126,7 +126,7 @@ class EnumNameMap { // This variant write diagnostics to the 'errstream' stream. // Returns true if successful. bool Parse(key_type text, EnumType *enum_value, std::ostream &errstream, - absl::string_view type_name) const { + std::string_view type_name) const { const EnumType *found_value = enum_name_map_.find_forward(text); if (found_value != nullptr) { *enum_value = *found_value; @@ -141,7 +141,7 @@ class EnumNameMap { // Converts the name of an enum to its corresponding value. // This variant write diagnostics to the 'error' string. bool Parse(key_type text, EnumType *enum_value, std::string *error, - absl::string_view type_name) const { + std::string_view type_name) const { std::ostringstream stream; const bool success = Parse(text, enum_value, stream, type_name); *error += stream.str(); @@ -149,7 +149,7 @@ class EnumNameMap { } // Returns the string representation of an enum. - absl::string_view EnumName(EnumType value) const { + std::string_view EnumName(EnumType value) const { const auto *key = enum_name_map_.find_reverse(value); if (key == nullptr) return "???"; return *key; diff --git a/verible/common/util/enum-flags_test.cc b/verible/common/util/enum-flags_test.cc index 63c369f34..c66b20472 100644 --- a/verible/common/util/enum-flags_test.cc +++ b/verible/common/util/enum-flags_test.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace verible { @@ -60,7 +60,7 @@ std::ostream &operator<<(std::ostream &stream, MyFakeEnum p) { // Testing using the absl::flags API, but we're only testing this particular // overload, and thus, don't actually need to depend on their library. -bool AbslParseFlag(absl::string_view text, MyFakeEnum *mode, +bool AbslParseFlag(std::string_view text, MyFakeEnum *mode, std::string *error) { return test_map.Parse(text, mode, error, "MyFakeEnum"); } @@ -84,7 +84,7 @@ TEST_F(EnumNameMapTest, ParseFlagValueValues) { TEST_F(EnumNameMapTest, ParseFlagTestInvalidValue) { MyFakeEnum e; std::string error; - constexpr absl::string_view bad_value("invalidEnumName"); + constexpr std::string_view bad_value("invalidEnumName"); EXPECT_FALSE(AbslParseFlag(bad_value, &e, &error)); // Make sure error message names the offending value, and lists all valid // values (map keys). diff --git a/verible/common/util/expandable-tree-view_test.cc b/verible/common/util/expandable-tree-view_test.cc index 1d1c5db2b..c926306e2 100644 --- a/verible/common/util/expandable-tree-view_test.cc +++ b/verible/common/util/expandable-tree-view_test.cc @@ -15,10 +15,10 @@ #include "verible/common/util/expandable-tree-view.h" #include +#include #include #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/util/vector-tree-test-util.h" @@ -249,11 +249,11 @@ TEST(ExpandableTreeViewTest, FamilyTreeApplyPreOrder) { const auto tree = verible::testing::MakeExampleFamilyTree(); ExpandableTreeViewTestType tree_view(tree); - std::vector visit_order; + std::vector visit_order; tree_view.ApplyPreOrder( [=, &visit_order]( VectorTree>> &node) { - const absl::string_view name = node.Value().Value().name; + const std::string_view name = node.Value().Value().name; visit_order.push_back(name); if (name[0] == 'p') { node.Value().Unexpand(); @@ -282,11 +282,11 @@ TEST(ExpandableTreeViewTest, FamilyTreeApplyPostOrder) { const auto tree = verible::testing::MakeExampleFamilyTree(); ExpandableTreeViewTestType tree_view(tree); - std::vector visit_order; + std::vector visit_order; tree_view.ApplyPostOrder( [=, &visit_order]( VectorTree>> &node) { - const absl::string_view name = node.Value().Value().name; + const std::string_view name = node.Value().Value().name; visit_order.push_back(name); if (name[0] == 'p' && name.back() == '1') { node.Value().Unexpand(); diff --git a/verible/common/util/file-util.cc b/verible/common/util/file-util.cc index ca98e384a..bd94cf651 100644 --- a/verible/common/util/file-util.cc +++ b/verible/common/util/file-util.cc @@ -25,13 +25,13 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/mem-block.h" #include "verible/common/util/logging.h" @@ -47,26 +47,26 @@ namespace fs = std::filesystem; namespace verible { namespace file { -absl::string_view Basename(absl::string_view filename) { +std::string_view Basename(std::string_view filename) { auto last_slash_pos = filename.find_last_of("/\\"); - return last_slash_pos == absl::string_view::npos + return last_slash_pos == std::string_view::npos ? filename : filename.substr(last_slash_pos + 1); } -absl::string_view Dirname(absl::string_view filename) { +std::string_view Dirname(std::string_view filename) { auto last_slash_pos = filename.find_last_of("/\\"); - return last_slash_pos == absl::string_view::npos + return last_slash_pos == std::string_view::npos ? filename : filename.substr(0, last_slash_pos); } -absl::string_view Stem(absl::string_view filename) { +std::string_view Stem(std::string_view filename) { auto last_dot_pos = filename.find_last_of('.'); - return last_dot_pos == absl::string_view::npos + return last_dot_pos == std::string_view::npos ? filename : filename.substr(0, last_dot_pos); } @@ -76,7 +76,7 @@ absl::string_view Stem(absl::string_view filename) { // If "sys_error" can not be resolved, creates an UNKNOWN message. // The "filename" and "fallback_msg" will be copied, no need for them to // stay alive after the call. -static absl::Status CreateErrorStatusFromSysError(absl::string_view filename, +static absl::Status CreateErrorStatusFromSysError(std::string_view filename, int sys_error, const char *fallback_msg) { const char *const system_msg = @@ -101,11 +101,11 @@ static absl::Status CreateErrorStatusFromSysError(absl::string_view filename, } } -static absl::Status CreateErrorStatusFromErrno(absl::string_view filename, +static absl::Status CreateErrorStatusFromErrno(std::string_view filename, const char *fallback_msg) { return CreateErrorStatusFromSysError(filename, errno, fallback_msg); } -static absl::Status CreateErrorStatusFromErr(absl::string_view filename, +static absl::Status CreateErrorStatusFromErr(std::string_view filename, const std::error_code &err, const char *fallback_msg) { // TODO: this assumes that err.value() returns errno-like values. Might not @@ -113,8 +113,8 @@ static absl::Status CreateErrorStatusFromErr(absl::string_view filename, return CreateErrorStatusFromSysError(filename, err.value(), fallback_msg); } -absl::Status UpwardFileSearch(absl::string_view start, - absl::string_view filename, std::string *result) { +absl::Status UpwardFileSearch(std::string_view start, std::string_view filename, + std::string *result) { std::error_code err; const std::string search_file(filename); fs::path absolute_path = fs::absolute(std::string(start), err); @@ -155,7 +155,7 @@ absl::Status FileExists(const std::string &filename) { absl::StrCat(filename, ": not a regular file.")); } -absl::StatusOr GetContentAsString(absl::string_view filename) { +absl::StatusOr GetContentAsString(std::string_view filename) { std::string content; FILE *stream = nullptr; const bool use_stdin = IsStdin(filename); @@ -189,13 +189,13 @@ absl::StatusOr GetContentAsString(absl::string_view filename) { } static absl::StatusOr> AttemptMemMapFile( - absl::string_view filename) { + std::string_view filename) { #ifndef _WIN32 class MemMapBlock final : public MemBlock { public: MemMapBlock(char *buffer, size_t size) : buffer_(buffer), size_(size) {} ~MemMapBlock() final { munmap(buffer_, size_); } - absl::string_view AsStringView() const final { return {buffer_, size_}; } + std::string_view AsStringView() const final { return {buffer_, size_}; } private: char *const buffer_; @@ -233,7 +233,7 @@ static absl::StatusOr> AttemptMemMapFile( } absl::StatusOr> GetContentAsMemBlock( - absl::string_view filename) { + std::string_view filename) { auto mmap_result = AttemptMemMapFile(filename); if (mmap_result.status().ok()) { return mmap_result; @@ -245,8 +245,7 @@ absl::StatusOr> GetContentAsMemBlock( return std::make_unique(std::move(*content_or)); } -absl::Status SetContents(absl::string_view filename, - absl::string_view content) { +absl::Status SetContents(std::string_view filename, std::string_view content) { VLOG(1) << __FUNCTION__ << ": Writing file: " << filename; FILE *out = fopen(std::string(filename).c_str(), "wb"); if (!out) return CreateErrorStatusFromErrno(filename, "can't write."); @@ -264,12 +263,12 @@ absl::Status SetContents(absl::string_view filename, return absl::OkStatus(); } -std::string JoinPath(absl::string_view base, absl::string_view name) { +std::string JoinPath(std::string_view base, std::string_view name) { fs::path p = fs::path(std::string(base)) / fs::path(std::string(name)); return p.lexically_normal().string(); } -absl::Status CreateDir(absl::string_view dir) { +absl::Status CreateDir(std::string_view dir) { const std::string path(dir); std::error_code err; if (fs::create_directory(path, err) || err.value() == 0) { @@ -278,7 +277,7 @@ absl::Status CreateDir(absl::string_view dir) { return CreateErrorStatusFromErr(dir, err, "can't create directory"); } -absl::StatusOr ListDir(absl::string_view dir) { +absl::StatusOr ListDir(std::string_view dir) { std::error_code err; Directory d; @@ -306,20 +305,20 @@ absl::StatusOr ListDir(absl::string_view dir) { return d; } -bool IsStdin(absl::string_view filename) { - static constexpr absl::string_view kStdinFilename = "-"; +bool IsStdin(std::string_view filename) { + static constexpr std::string_view kStdinFilename = "-"; return filename == kStdinFilename; } namespace testing { -std::string RandomFileBasename(absl::string_view prefix) { +std::string RandomFileBasename(std::string_view prefix) { return absl::StrCat(prefix, "-", rand()); } -ScopedTestFile::ScopedTestFile(absl::string_view base_dir, - absl::string_view content, - absl::string_view use_this_filename) +ScopedTestFile::ScopedTestFile(std::string_view base_dir, + std::string_view content, + std::string_view use_this_filename) // There is no secrecy needed for test files, // file name just need to be unique enough. : filename_(JoinPath(base_dir, use_this_filename.empty() diff --git a/verible/common/util/file-util.h b/verible/common/util/file-util.h index 17ac418b5..f70f633e7 100644 --- a/verible/common/util/file-util.h +++ b/verible/common/util/file-util.h @@ -19,11 +19,11 @@ #include #include +#include #include #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/mem-block.h" // TODO(hzeller): All file interfaces are using a strings to represent @@ -38,7 +38,7 @@ namespace file { // Convention: honor "-" as stdin // Added to avoid performing lint filename rules such as // {package,module}_filename_rule -bool IsStdin(absl::string_view filename); +bool IsStdin(std::string_view filename); // A representation of a filesystem directory. struct Directory { @@ -55,58 +55,58 @@ struct Directory { // Note that this function's behavior differs from the Unix basename // command if path ends with "/". For such paths, this function returns the // empty string. -absl::string_view Basename(absl::string_view filename); +std::string_view Basename(std::string_view filename); // Returns the the directory that contains the file. If there is no // "/" in the path, the result is the same as the input. // If no "/" is found the result is the same as the input. -absl::string_view Dirname(absl::string_view filename); +std::string_view Dirname(std::string_view filename); // Returns the part of the basename of path prior to the final ".". If // there is no "." in the basename, this is equivalent to file::Basename(path). -absl::string_view Stem(absl::string_view filename); +std::string_view Stem(std::string_view filename); // Search for 'filename' file starting at 'start' (can be file or directory) // and going upwards the directory tree. Returns true if anything is found and // puts the found file in 'result'. -absl::Status UpwardFileSearch(absl::string_view start, - absl::string_view filename, std::string *result); +absl::Status UpwardFileSearch(std::string_view start, std::string_view filename, + std::string *result); // Determines whether the given filename exists and is a regular file or pipe. absl::Status FileExists(const std::string &filename); // Read file "filename" and return its content as string. -absl::StatusOr GetContentAsString(absl::string_view filename); +absl::StatusOr GetContentAsString(std::string_view filename); // Read file "filename" and store its content in MemBlock. Attempts to MemMap // first; if that fails, reads file regularly. absl::StatusOr> GetContentAsMemBlock( - absl::string_view filename); + std::string_view filename); // Create file "filename" and store given content in it. -absl::Status SetContents(absl::string_view filename, absl::string_view content); +absl::Status SetContents(std::string_view filename, std::string_view content); // Join directory + filename and lightly canonicalize. // The canonicalization step unifies ./ and ../ path elements lexically // without looking at the underlying file-system. // // If "filename" is already absolute, "base" is not prepended. -std::string JoinPath(absl::string_view base, absl::string_view name); +std::string JoinPath(std::string_view base, std::string_view name); // Create directory with given name, return success. -absl::Status CreateDir(absl::string_view dir); +absl::Status CreateDir(std::string_view dir); // Returns the content of the directory. POSIX only. Ignores symlinks and // unknown nodes which it fails to resolve to a file or a directory. Returns an // error status on any read error (doesn't allow partial results) except // resolving symlinks and unknown nodes. // TODO (after bump to c++17) rewrite this function to use std::filesystem -absl::StatusOr ListDir(absl::string_view dir); +absl::StatusOr ListDir(std::string_view dir); namespace testing { // Generate a random file name (no directory). This does not create any file. -std::string RandomFileBasename(absl::string_view prefix); +std::string RandomFileBasename(std::string_view prefix); // Useful for testing: a temporary file with a randomly generated name // that is pre-populated with a particular content. @@ -117,8 +117,8 @@ class ScopedTestFile { // 'base_dir' needs to already exist, and will not be automatically created. // If 'use_this_filename' is provided as a base name, that will be used, // otherwise, a file name will be randomly generated. - ScopedTestFile(absl::string_view base_dir, absl::string_view content, - absl::string_view use_this_filename = ""); + ScopedTestFile(std::string_view base_dir, std::string_view content, + std::string_view use_this_filename = ""); ~ScopedTestFile(); // not copy-able diff --git a/verible/common/util/file-util_test.cc b/verible/common/util/file-util_test.cc index cf6932063..1a9074097 100644 --- a/verible/common/util/file-util_test.cc +++ b/verible/common/util/file-util_test.cc @@ -18,13 +18,13 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -91,7 +91,7 @@ TEST(FileUtil, GetContentAsMemBlock) { EXPECT_FALSE(result.status().ok()); const std::string test_file = file::JoinPath(testing::TempDir(), "blockfile"); - constexpr absl::string_view kTestContent = "Some file content\nbaz\r\n"; + constexpr std::string_view kTestContent = "Some file content\nbaz\r\n"; EXPECT_OK(file::SetContents(test_file, kTestContent)); result = file::GetContentAsMemBlock(test_file); @@ -140,7 +140,7 @@ TEST(FileUtil, JoinPath) { TEST(FileUtil, CreateDir) { const std::string test_dir = file::JoinPath(testing::TempDir(), "test_dir"); const std::string test_file = file::JoinPath(test_dir, "foo"); - const absl::string_view test_content = "directory create test"; + const std::string_view test_content = "directory create test"; EXPECT_OK(file::CreateDir(test_dir)); EXPECT_OK(file::CreateDir(test_dir)); // Creating twice should succeed @@ -168,7 +168,7 @@ TEST(FileUtil, StatusErrorReporting) { unlink(test_file.c_str()); // Remove file if left from previous test. // Add a bunch of text 'special' characcters to make sure even on Windows // they roundtrip correctly. - constexpr absl::string_view kTestContent = "foo\nbar\r\nbaz\rquux"; + constexpr std::string_view kTestContent = "foo\nbar\r\nbaz\rquux"; EXPECT_OK(file::SetContents(test_file, kTestContent)); // Writing again, should not append, but re-write. @@ -222,14 +222,14 @@ TEST(FileUtil, StatusErrorReporting) { } TEST(FileUtil, ScopedTestFile) { - const absl::string_view test_content = "Hello World!"; + const std::string_view test_content = "Hello World!"; ScopedTestFile test_file(testing::TempDir(), test_content); auto read_back_content_or = file::GetContentAsString(test_file.filename()); ASSERT_TRUE(read_back_content_or.ok()); EXPECT_EQ(test_content, *read_back_content_or); } -static ScopedTestFile TestFileGenerator(absl::string_view content) { +static ScopedTestFile TestFileGenerator(std::string_view content) { return ScopedTestFile(testing::TempDir(), content); } @@ -275,9 +275,9 @@ TEST(FileUtil, FileExistsDirectoryErrorMessage) { EXPECT_THAT(s.message(), HasSubstr("is a directory")); } -static bool CreateFsStructure(absl::string_view base_dir, - const std::vector &tree) { - for (absl::string_view path : tree) { +static bool CreateFsStructure(std::string_view base_dir, + const std::vector &tree) { + for (std::string_view path : tree) { const std::string full_path = file::JoinPath(base_dir, path); if (absl::EndsWith(path, "/")) { if (!file::CreateDir(full_path).ok()) return false; @@ -364,7 +364,7 @@ TEST(FileUtil, ReadDirectory) { ASSERT_TRUE(file::CreateDir(test_subdir1).ok()); ASSERT_TRUE(file::CreateDir(test_subdir2).ok()); - const absl::string_view test_content = "Hello World!"; + const std::string_view test_content = "Hello World!"; file::testing::ScopedTestFile test_file1(test_dir, test_content); file::testing::ScopedTestFile test_file2(test_dir, test_content); file::testing::ScopedTestFile test_file3(test_dir, test_content); diff --git a/verible/common/util/forward_test.cc b/verible/common/util/forward_test.cc index bb69369d4..a310a05a7 100644 --- a/verible/common/util/forward_test.cc +++ b/verible/common/util/forward_test.cc @@ -15,9 +15,9 @@ #include "verible/common/util/forward.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace verible { @@ -51,16 +51,16 @@ TEST(ForwardReferenceElseConstructTest, Construct) { } TEST(ForwardReferenceElseConstructTest, ForwardStringView) { - const absl::string_view a("hello"); - const auto &ref = ForwardReferenceElseConstruct()(a); + const std::string_view a("hello"); + const auto &ref = ForwardReferenceElseConstruct()(a); EXPECT_EQ(&ref, &a); // same object forwarded } TEST(ForwardReferenceElseConstructTest, ConstructString) { - const absl::string_view a("hello"); + const std::string_view a("hello"); const auto &ref = ForwardReferenceElseConstruct()(a); - static_assert(!std::is_same_v, - "!std::is_same::value"); + static_assert(!std::is_same_v, + "!std::is_same::value"); } TEST(ForwardReferenceElseConstructTest, ForwardString) { @@ -71,7 +71,7 @@ TEST(ForwardReferenceElseConstructTest, ForwardString) { TEST(ForwardReferenceElseConstructTest, ConstructStringView) { const std::string a("hello"); - const auto &ref = ForwardReferenceElseConstruct()(a); + const auto &ref = ForwardReferenceElseConstruct()(a); static_assert(!std::is_same_v, "!std::is_same::value"); } diff --git a/verible/common/util/init-command-line.cc b/verible/common/util/init-command-line.cc index 16f41d64a..cda06bcd7 100644 --- a/verible/common/util/init-command-line.cc +++ b/verible/common/util/init-command-line.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "absl/base/log_severity.h" @@ -28,7 +29,6 @@ #include "absl/log/globals.h" #include "absl/log/initialize.h" #include "absl/strings/numbers.h" -#include "absl/strings/string_view.h" #include "absl/time/time.h" #include "verible/common/util/generated-verible-build-version.h" @@ -83,8 +83,8 @@ void SetLoggingLevelsFromEnvironment() { } // We might want to have argc edited in the future, hence non-const param. -std::vector InitCommandLine( - absl::string_view usage, +std::vector InitCommandLine( + std::string_view usage, int *argc, // NOLINT(readability-non-const-parameter) char ***argv) { absl::InitializeSymbolizer(*argv[0]); diff --git a/verible/common/util/init-command-line.h b/verible/common/util/init-command-line.h index ba14fa680..afcef5b64 100644 --- a/verible/common/util/init-command-line.h +++ b/verible/common/util/init-command-line.h @@ -16,10 +16,9 @@ #define VERIBLE_COMMON_UTIL_INIT_COMMAND_LINE_H_ #include +#include #include -#include "absl/strings/string_view.h" - namespace verible { // Get a one-line build version string that based on the repository version. @@ -37,8 +36,8 @@ void SetLoggingLevelsFromEnvironment(); // Positional parameters after `--` are returned as-is and not interpreted // as flags. // Returns positional arguments, where element[0] is the program name. -std::vector InitCommandLine(absl::string_view usage, - int *argc, char ***argv); +std::vector InitCommandLine(std::string_view usage, int *argc, + char ***argv); } // namespace verible diff --git a/verible/common/util/interval-map_test.cc b/verible/common/util/interval-map_test.cc index d3a176892..72149cf84 100644 --- a/verible/common/util/interval-map_test.cc +++ b/verible/common/util/interval-map_test.cc @@ -17,11 +17,11 @@ #include #include #include +#include #include #include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/util/range.h" @@ -54,12 +54,12 @@ TEST(DisjointIntervalMapTest, EmplaceOne) { TEST(DisjointIntervalMapTest, EmplaceOneEnsureMove) { StringIntervalMap imap; auto s = std::make_unique("Gruetzi!"); - const absl::string_view sv(*s); + const std::string_view sv(*s); const auto p = imap.emplace({3, 7}, std::move(s)); EXPECT_TRUE(p.second); EXPECT_EQ(p.first->first, std::make_pair(3, 7)); // ownership transferred, string_view range is still valid - const absl::string_view new_sv(*p.first->second); + const std::string_view new_sv(*p.first->second); EXPECT_TRUE(BoundsEqual(new_sv, sv)) << "got: " << new_sv << " vs. " << sv; } diff --git a/verible/common/util/interval-set.h b/verible/common/util/interval-set.h index 4f819654e..2d48277c2 100644 --- a/verible/common/util/interval-set.h +++ b/verible/common/util/interval-set.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -30,7 +31,6 @@ #include "absl/strings/numbers.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/util/auto-iterator.h" #include "verible/common/util/interval.h" #include "verible/common/util/iterator-range.h" @@ -542,7 +542,7 @@ std::ostream &operator<<(std::ostream &stream, const IntervalSet &iset) { template bool ParseInclusiveRanges(IntervalSet *iset, Iter begin, Iter end, std::ostream *errstream, const char sep = '-') { - std::vector bounds; // re-use allocated memory + std::vector bounds; // re-use allocated memory for (const auto &range : verible::make_range(begin, end)) { bounds = absl::StrSplit(range, sep); if (bounds.size() == 1) { diff --git a/verible/common/util/interval-set_test.cc b/verible/common/util/interval-set_test.cc index c36e6f1d4..0d4ef796b 100644 --- a/verible/common/util/interval-set_test.cc +++ b/verible/common/util/interval-set_test.cc @@ -18,10 +18,10 @@ #include #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/util/interval.h" @@ -811,7 +811,7 @@ TEST(IntervalSetTest, StreamOutputNonEmpty) { } TEST(ParseInclusivesRangesTest, Empty) { - const std::initializer_list kRanges{}; + const std::initializer_list kRanges{}; interval_set_type iset; std::ostringstream errstream; EXPECT_TRUE( @@ -821,7 +821,7 @@ TEST(ParseInclusivesRangesTest, Empty) { } TEST(ParseInclusivesRangesTest, ParseErrorSingle) { - const std::initializer_list kRanges{"yyy"}; + const std::initializer_list kRanges{"yyy"}; interval_set_type iset; std::ostringstream errstream; EXPECT_FALSE( @@ -831,7 +831,7 @@ TEST(ParseInclusivesRangesTest, ParseErrorSingle) { } TEST(ParseInclusivesRangesTest, ParseErrorRange) { - const std::initializer_list kRanges{"1-x"}; + const std::initializer_list kRanges{"1-x"}; interval_set_type iset; std::ostringstream errstream; EXPECT_FALSE( @@ -842,7 +842,7 @@ TEST(ParseInclusivesRangesTest, ParseErrorRange) { TEST(ParseInclusivesRangesTest, EmptyString) { // Empty string can come from splitting. - const std::initializer_list kRanges{""}; + const std::initializer_list kRanges{""}; interval_set_type iset; std::ostringstream errstream; EXPECT_TRUE( @@ -854,7 +854,7 @@ TEST(ParseInclusivesRangesTest, EmptyString) { } TEST(ParseInclusivesRangesTest, SingleValues) { - const std::initializer_list kRanges{"1", "3", "4", "5"}; + const std::initializer_list kRanges{"1", "3", "4", "5"}; interval_set_type iset; std::ostringstream errstream; EXPECT_TRUE( @@ -865,7 +865,7 @@ TEST(ParseInclusivesRangesTest, SingleValues) { } TEST(ParseInclusivesRangesTest, SingleValuesAndEmpty) { - const std::initializer_list kRanges{"1", "", "4", "5"}; + const std::initializer_list kRanges{"1", "", "4", "5"}; interval_set_type iset; std::ostringstream errstream; EXPECT_TRUE( @@ -876,8 +876,8 @@ TEST(ParseInclusivesRangesTest, SingleValuesAndEmpty) { } TEST(ParseInclusivesRangesTest, PairValues) { - const std::initializer_list kRanges{"1-10", "3-11", - "41-52"}; + const std::initializer_list kRanges{"1-10", "3-11", + "41-52"}; interval_set_type iset; std::ostringstream errstream; EXPECT_TRUE( @@ -888,8 +888,8 @@ TEST(ParseInclusivesRangesTest, PairValues) { } TEST(ParseInclusivesRangesTest, PairValuesCustomSeparator) { - const std::initializer_list kRanges{"1:10", "3:11", - "41:52"}; + const std::initializer_list kRanges{"1:10", "3:11", + "41:52"}; interval_set_type iset; std::ostringstream errstream; EXPECT_TRUE(ParseInclusiveRanges(&iset, kRanges.begin(), kRanges.end(), @@ -900,8 +900,8 @@ TEST(ParseInclusivesRangesTest, PairValuesCustomSeparator) { } TEST(ParseInclusivesRangesTest, MixedValues) { - const std::initializer_list kRanges{"2-10", "11-3", "41", - "42-52"}; + const std::initializer_list kRanges{"2-10", "11-3", "41", + "42-52"}; interval_set_type iset; std::ostringstream errstream; EXPECT_TRUE( diff --git a/verible/common/util/interval.h b/verible/common/util/interval.h index 5e12dc165..78d703b52 100644 --- a/verible/common/util/interval.h +++ b/verible/common/util/interval.h @@ -16,10 +16,10 @@ #define VERIBLE_COMMON_UTIL_INTERVAL_H_ #include +#include #include #include "absl/strings/numbers.h" -#include "absl/strings/string_view.h" #include "verible/common/util/forward.h" namespace verible { @@ -114,8 +114,8 @@ std::ostream &operator<<(std::ostream &stream, const Interval &interval) { // Returns true on success, false on parse error. // This is the reverse of Interval::FormatInclusive(). template -bool ParseInclusiveRange(Interval *interval, absl::string_view first_str, - absl::string_view last_str, std::ostream *errstream) { +bool ParseInclusiveRange(Interval *interval, std::string_view first_str, + std::string_view last_str, std::ostream *errstream) { T first, last; if (!absl::SimpleAtoi(first_str, &first)) { *errstream << "Expected number, but got: \"" << first_str << "\"." diff --git a/verible/common/util/map-tree_test.cc b/verible/common/util/map-tree_test.cc index 5f20db377..e650dfcd2 100644 --- a/verible/common/util/map-tree_test.cc +++ b/verible/common/util/map-tree_test.cc @@ -18,9 +18,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/util/spacer.h" @@ -126,9 +126,9 @@ TEST(MapTreeTest, EmplaceOneChild) { } struct NonCopyable { - absl::string_view text; + std::string_view text; - explicit NonCopyable(absl::string_view text) : text(text) {} + explicit NonCopyable(std::string_view text) : text(text) {} // move-only, no copy NonCopyable(const NonCopyable &) = delete; diff --git a/verible/common/util/range_test.cc b/verible/common/util/range_test.cc index e8fafc50a..d64f33b5d 100644 --- a/verible/common/util/range_test.cc +++ b/verible/common/util/range_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/util/iterator-range.h" @@ -28,24 +28,23 @@ namespace { // Test that IsSubRange matches same empty string. TEST(IsSubRangeTest, SameEmptyString) { - const absl::string_view substring; + const std::string_view substring; EXPECT_TRUE(IsSubRange(substring, substring)); } // Test that IsSubRange matches same nonempty string. TEST(IsSubRangeTest, SameNonEmptyString) { - const absl::string_view substring = "nonempty"; + const std::string_view substring = "nonempty"; EXPECT_TRUE(IsSubRange(substring, substring)); } // Test that IsSubRange works on string and string_view. TEST(IsSubRangeTest, MixedStringViewStdString) { const std::string superstring("nonempty"); - const absl::string_view substring = - absl::string_view(superstring).substr(1, 3); - // Note: std::string and absl::string_view iterators are not directly + const std::string_view substring = std::string_view(superstring).substr(1, 3); + // Note: std::string and std::string_view iterators are not directly // comparable to each other. - EXPECT_TRUE(IsSubRange(substring, absl::string_view(superstring))); + EXPECT_TRUE(IsSubRange(substring, std::string_view(superstring))); } // Test that IsSubRange works on string iterators. @@ -58,8 +57,8 @@ TEST(IsSubRangeTest, StringAndIterator) { // Test that IsSubRange is false on completely different string_views. TEST(IsSubRangeTest, DifferentStringViews) { - const absl::string_view a = "twiddle-dee"; - const absl::string_view b = "twiddle-dum"; + const std::string_view a = "twiddle-dee"; + const std::string_view b = "twiddle-dum"; EXPECT_FALSE(IsSubRange(a, b)); EXPECT_FALSE(IsSubRange(b, a)); } @@ -78,7 +77,7 @@ TEST(IsSubRangeTest, IdenticalSeparateStrings) { // Test that IsSubRange matches sub-string_view. TEST(IsSubRangeTest, SubStringView) { - const absl::string_view superstring = "not-empty"; + const std::string_view superstring = "not-empty"; EXPECT_TRUE(IsSubRange(superstring.substr(0, 0), superstring)); // empty EXPECT_TRUE(IsSubRange(superstring.substr(3, 0), superstring)); // empty EXPECT_TRUE(IsSubRange(superstring.substr(0), superstring)); @@ -89,14 +88,14 @@ TEST(IsSubRangeTest, SubStringView) { // Test that IsSubRange is false on superstring views (converse). TEST(IsSubRangeTest, SuperStringView) { - const absl::string_view superstring = "also-nonempty"; + const std::string_view superstring = "also-nonempty"; EXPECT_FALSE(IsSubRange(superstring, superstring.substr(1))); EXPECT_FALSE(IsSubRange(superstring, superstring.substr(1, 3))); } // Test that IsSubRange works on substring ranges. TEST(IsSubRangeTest, DerivedSubStringView) { - const absl::string_view str = "qwertyuiop"; + const std::string_view str = "qwertyuiop"; EXPECT_FALSE(IsSubRange(str.substr(0, 0), str.substr(1, 0))); // empty EXPECT_FALSE(IsSubRange(str.substr(1, 0), str.substr(0, 0))); // empty EXPECT_TRUE(IsSubRange(str.substr(1, 0), str.substr(0, 1))); @@ -112,20 +111,20 @@ TEST(IsSubRangeTest, DerivedSubStringView) { // Test that BoundsEqual matches same empty string. TEST(BoundsEqualTest, SameEmptyString) { - const absl::string_view substring; + const std::string_view substring; EXPECT_TRUE(BoundsEqual(substring, substring)); } // Test that BoundsEqual matches same nonempty string. TEST(BoundsEqualTest, SameNonEmptyString) { - const absl::string_view substring = "nonempty"; + const std::string_view substring = "nonempty"; EXPECT_TRUE(BoundsEqual(substring, substring)); } // Test that BoundsEqual is false on completely different string_views. TEST(BoundsEqualTest, DifferentStringViews) { - const absl::string_view a = "twiddle-dee"; - const absl::string_view b = "twiddle-dum"; + const std::string_view a = "twiddle-dee"; + const std::string_view b = "twiddle-dum"; EXPECT_FALSE(BoundsEqual(a, b)); EXPECT_FALSE(BoundsEqual(b, a)); } @@ -140,7 +139,7 @@ TEST(BoundsEqualTest, IdenticalSeparateStrings) { // Test that BoundsEqual matches sub-string_view. TEST(BoundsEqualTest, SubStringView) { - const absl::string_view superstring = "not-empty"; + const std::string_view superstring = "not-empty"; EXPECT_FALSE(BoundsEqual(superstring.substr(0, 0), superstring)); // empty EXPECT_FALSE(BoundsEqual(superstring.substr(3, 0), superstring)); // empty EXPECT_TRUE(BoundsEqual(superstring.substr(0), superstring)); @@ -151,14 +150,14 @@ TEST(BoundsEqualTest, SubStringView) { // Test that BoundsEqual is false on superstring views (converse). TEST(BoundsEqualTest, SuperStringView) { - const absl::string_view superstring = "also-nonempty"; + const std::string_view superstring = "also-nonempty"; EXPECT_FALSE(BoundsEqual(superstring, superstring.substr(1))); EXPECT_FALSE(BoundsEqual(superstring, superstring.substr(1, 3))); } // Test that BoundsEqual works on substring ranges. TEST(BoundsEqualTest, DerivedSubStringView) { - const absl::string_view str = "qwertyuiop"; + const std::string_view str = "qwertyuiop"; EXPECT_FALSE(BoundsEqual(str.substr(0, 0), str.substr(1, 0))); // empty EXPECT_FALSE(BoundsEqual(str.substr(1, 0), str.substr(0, 0))); // empty EXPECT_FALSE(BoundsEqual(str.substr(1, 0), str.substr(0, 1))); diff --git a/verible/common/util/sha256.cc b/verible/common/util/sha256.cc index a7f065b59..2c4a5bbd1 100644 --- a/verible/common/util/sha256.cc +++ b/verible/common/util/sha256.cc @@ -39,9 +39,9 @@ #include #include #include +#include #include "absl/strings/escaping.h" -#include "absl/strings/string_view.h" namespace verible { namespace { @@ -117,7 +117,7 @@ bool Sha256Context::AddLength(unsigned int length) { // Adds an array of octets as the next portion of the message. Returns false if // the accumulated message is too large (>2 Exabytes). -bool Sha256Context::AddInput(absl::string_view message) { +bool Sha256Context::AddInput(std::string_view message) { if (overflowed_) return false; for (const char c : message) { @@ -251,7 +251,7 @@ std::array Sha256Context::BuildAndReset() { return message_digest; } -std::array Sha256(absl::string_view content) { +std::array Sha256(std::string_view content) { Sha256Context context; context.AddInput(content); if (context.IsOverflowed()) { @@ -260,12 +260,12 @@ std::array Sha256(absl::string_view content) { return context.BuildAndReset(); } -std::string Sha256Hex(absl::string_view content) { +std::string Sha256Hex(std::string_view content) { auto sha256bytes = Sha256(content); if (sha256bytes.empty()) { return ""; } - return absl::BytesToHexString(absl::string_view( + return absl::BytesToHexString(std::string_view( reinterpret_cast(sha256bytes.data()), sha256bytes.size())); } diff --git a/verible/common/util/sha256.h b/verible/common/util/sha256.h index 86dd1ee1d..1b775b83b 100644 --- a/verible/common/util/sha256.h +++ b/verible/common/util/sha256.h @@ -53,8 +53,7 @@ #include #include #include - -#include "absl/strings/string_view.h" +#include namespace verible { @@ -77,7 +76,7 @@ class Sha256Context { // Adds an array of octets as the next portion of the message. Returns false // if the accumulated message is too large (>2 Exabytes). Can be called // multiple times to incrementally build the digest. - bool AddInput(absl::string_view message); + bool AddInput(std::string_view message); // Returns true if the accumulated message is too large (>2 Exabytes). bool IsOverflowed() const { return overflowed_; } @@ -129,10 +128,10 @@ class Sha256Context { }; // Returns the SHA256 hash of the given content. -std::array Sha256(absl::string_view content); +std::array Sha256(std::string_view content); // Returns the HEX string representation of SHA256 hash of the given content. -std::string Sha256Hex(absl::string_view content); +std::string Sha256Hex(std::string_view content); } // namespace verible diff --git a/verible/common/util/sha256_test.cc b/verible/common/util/sha256_test.cc index 0953c77a1..93d03cd6f 100644 --- a/verible/common/util/sha256_test.cc +++ b/verible/common/util/sha256_test.cc @@ -16,9 +16,9 @@ #include #include +#include #include "absl/strings/escaping.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace verible { @@ -30,11 +30,11 @@ namespace { // // #include "openssl/sha.h" // -// std::string SslSHA256Digest(absl::string_view content) { +// std::string SslSHA256Digest(std::string_view content) { // std::array buf; // ::SHA256(reinterpret_cast(content.data()), // content.size(), buf.data()); -// return absl::BytesToHexString(absl::string_view( +// return absl::BytesToHexString(std::string_view( // reinterpret_cast(buf.data()), buf.size())); // } // @@ -42,19 +42,19 @@ namespace { // Alternative: `printf "banana" | sha256sum` TEST(Sha256, DigestsAreEqual) { - static constexpr absl::string_view kOpenSslSha256BananaDigest = + static constexpr std::string_view kOpenSslSha256BananaDigest = "b493d48364afe44d11c0165cf470a4164d1e2609911ef998be868d46ade3de4e"; EXPECT_EQ(Sha256Hex("banana"), kOpenSslSha256BananaDigest); } TEST(Sha256, NonAsciiDigestsAreEqual) { - static constexpr absl::string_view kOpenSslSha256JaBananaDigest = + static constexpr std::string_view kOpenSslSha256JaBananaDigest = "787bcc7042939ad9607bc8ca87332e4178716be0f0b890cbf673884d39d8ff79"; EXPECT_EQ(Sha256Hex("バナナ"), kOpenSslSha256JaBananaDigest); } TEST(Sha256, LargeInputDigestsAreEqual) { - static constexpr absl::string_view kLargeText = R"( + static constexpr std::string_view kLargeText = R"( Internet Engineering Task Force (IETF) D. Eastlake 3rd Request for Comments: 6234 Huawei Obsoletes: 4634 T. Hansen @@ -81,19 +81,19 @@ Abstract HMAC-based extract-and-expand Key Derivation Function, HKDF (RFC 5869). As with RFC 4634, code to perform SHA-based Hashed Message Authentication Codes (HMACs) is also included.)"; - static constexpr absl::string_view kOpenSslSha256LargeTextDigest = + static constexpr std::string_view kOpenSslSha256LargeTextDigest = "11fc4b5feb7b63ddcc15cfb05d1f969da2e0d537ec8eded8370e12811f7ab1a8"; EXPECT_EQ(Sha256Hex(kLargeText), kOpenSslSha256LargeTextDigest); } TEST(Sha256, EmptyInputDigestsAreEqual) { - static constexpr absl::string_view kOpenSslSha256EmptyStringDigest = + static constexpr std::string_view kOpenSslSha256EmptyStringDigest = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; EXPECT_EQ(Sha256Hex(""), kOpenSslSha256EmptyStringDigest); } TEST(Sha256, IncrementallyAddedDigestsAreEqual) { - static constexpr absl::string_view kOpenSslSha256BananaDigest = + static constexpr std::string_view kOpenSslSha256BananaDigest = "b493d48364afe44d11c0165cf470a4164d1e2609911ef998be868d46ade3de4e"; Sha256Context context; context.AddInput("b"); @@ -102,7 +102,7 @@ TEST(Sha256, IncrementallyAddedDigestsAreEqual) { context.AddInput("a"); auto digest = context.BuildAndReset(); - std::string actual = absl::BytesToHexString(absl::string_view( + std::string actual = absl::BytesToHexString(std::string_view( reinterpret_cast(digest.data()), digest.size())); EXPECT_EQ(actual, kOpenSslSha256BananaDigest); } diff --git a/verible/common/util/simple-zip.cc b/verible/common/util/simple-zip.cc index fdf669505..873a96a45 100644 --- a/verible/common/util/simple-zip.cc +++ b/verible/common/util/simple-zip.cc @@ -20,18 +20,18 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "third_party/portable_endian/portable_endian.h" #include "zlib/include/zlib.h" namespace verible { namespace zip { -ByteSource MemoryByteSource(absl::string_view input) { +ByteSource MemoryByteSource(std::string_view input) { auto is_called = std::make_shared(false); - return [is_called, input]() -> absl::string_view { + return [is_called, input]() -> std::string_view { if (!*is_called) { *is_called = true; return input; @@ -50,7 +50,7 @@ ByteSource FileByteSource(const char *filename) { char buffer[65536]; }; auto state = std::make_shared(f); // capture req. copy-constructable - return [state]() -> absl::string_view { + return [state]() -> std::string_view { size_t r = fread(state->buffer, 1, sizeof(State::buffer), state->file); return {state->buffer, r}; }; @@ -75,7 +75,7 @@ class HeaderWriter { pos_ += 4; return *this; } - HeaderWriter &AddLiteral(absl::string_view str) { + HeaderWriter &AddLiteral(std::string_view str) { memcpy(pos_, str.data(), str.size()); pos_ += str.size(); return *this; @@ -104,13 +104,12 @@ struct Encoder::Impl { Impl(int compression_level, ByteSink out) : compression_level_(std::clamp(compression_level, 0, 9)), delegate_write_(std::move(out)), - out_([this](absl::string_view s) { + out_([this](std::string_view s) { output_file_offset_ += s.size(); // Keep track of offsets. return delegate_write_(s); }) {} - bool AddFile(absl::string_view filename, - const ByteSource &content_generator) { + bool AddFile(std::string_view filename, const ByteSource &content_generator) { if (is_finished_) return false; // Can't add more files. if (!content_generator) return false; @@ -183,7 +182,7 @@ struct Encoder::Impl { } // End of central directory record - constexpr absl::string_view comment("Created with Verible simple zip"); + constexpr std::string_view comment("Created with Verible simple zip"); return HeaderWriter(scratch_space_) .AddLiteral("PK\x05\x06") // End of central directory signature .AddInt16(0) // our disk number @@ -200,7 +199,7 @@ struct Encoder::Impl { CompressResult CopyDataToOutput(const ByteSource &generator) { uint32_t crc = 0; size_t processed_size = 0; - absl::string_view chunk; + std::string_view chunk; while (!(chunk = generator()).empty()) { crc = crc32(crc, reinterpret_cast(chunk.data()), chunk.size()); @@ -212,7 +211,7 @@ struct Encoder::Impl { CompressResult CompressDataToOutput(const ByteSource &generator) { uint32_t crc = 0; - absl::string_view chunk; + std::string_view chunk; z_stream stream; memset(&stream, 0x00, sizeof(stream)); @@ -262,7 +261,7 @@ Encoder::Encoder(int compression_level, ByteSink out) Encoder::~Encoder() { Finish(); } -bool Encoder::AddFile(absl::string_view filename, +bool Encoder::AddFile(std::string_view filename, const ByteSource &content_generator) { return impl_->AddFile(filename, content_generator); } diff --git a/verible/common/util/simple-zip.h b/verible/common/util/simple-zip.h index 6acb7e1dd..e46e68082 100644 --- a/verible/common/util/simple-zip.h +++ b/verible/common/util/simple-zip.h @@ -18,8 +18,7 @@ #include #include - -#include "absl/strings/string_view.h" +#include namespace verible { namespace zip { @@ -35,15 +34,15 @@ namespace zip { // The fact that ByteSource returns different results on each call implies that // it has a state (e.g. successive read() calls); implementations need to make // sure that even partial reads don't result in leaked resources. -using ByteSource = std::function; +using ByteSource = std::function; // A function that receives bytes. Consecutive calls concatenate. Return // value 'true' indicates operation succeeded. -using ByteSink = std::function; +using ByteSink = std::function; // Utility function that wraps a string_view and provides a ByteSource. Use // this if you have an in-memory representation of your content. -ByteSource MemoryByteSource(absl::string_view input); +ByteSource MemoryByteSource(std::string_view input); // Utility function that reads the content of a file and provides a ByteSource. // May return an empty function if file could not be opened @@ -62,7 +61,7 @@ class Encoder { ~Encoder(); // Add a file with given filename and content from the generator function. - bool AddFile(absl::string_view filename, const ByteSource &content_generator); + bool AddFile(std::string_view filename, const ByteSource &content_generator); // Finalize container. // After this, no new files can be added. diff --git a/verible/common/util/simple-zip_test.cc b/verible/common/util/simple-zip_test.cc index afa9c3fa2..f76946119 100644 --- a/verible/common/util/simple-zip_test.cc +++ b/verible/common/util/simple-zip_test.cc @@ -15,8 +15,8 @@ #include "verible/common/util/simple-zip.h" #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/util/file-util.h" @@ -24,10 +24,10 @@ // is actually unzippable (we don't have the reverse functionality), so we // just probe that the generated file looks right. -static int CountSubstr(absl::string_view needle, absl::string_view haystack) { +static int CountSubstr(std::string_view needle, std::string_view haystack) { int count = 0; - absl::string_view::size_type pos = 0; - while ((pos = haystack.find(needle, pos)) != absl::string_view::npos) { + std::string_view::size_type pos = 0; + while ((pos = haystack.find(needle, pos)) != std::string_view::npos) { count++; pos += needle.length(); } @@ -36,7 +36,7 @@ static int CountSubstr(absl::string_view needle, absl::string_view haystack) { TEST(SimpleZip, NoCompress) { std::string result; - verible::zip::Encoder zipper(0, [&result](absl::string_view out) { + verible::zip::Encoder zipper(0, [&result](std::string_view out) { result.append(out.begin(), out.end()); return true; }); @@ -57,7 +57,7 @@ TEST(SimpleZip, NoCompress) { TEST(SimpleZip, WithCompression) { std::string result; - verible::zip::Encoder zipper(9, [&result](absl::string_view out) { + verible::zip::Encoder zipper(9, [&result](std::string_view out) { result.append(out.begin(), out.end()); return true; }); @@ -77,7 +77,7 @@ TEST(SimpleZip, WithCompression) { TEST(SimpleZip, ReadFromFileByteSource) { std::string result; - verible::zip::Encoder zipper(0, [&result](absl::string_view out) { + verible::zip::Encoder zipper(0, [&result](std::string_view out) { result.append(out.begin(), out.end()); return true; }); @@ -102,7 +102,7 @@ TEST(SimpleZip, ImplicitFinishOnDestruction) { std::string result; { - verible::zip::Encoder zipper(0, [&result](absl::string_view out) { + verible::zip::Encoder zipper(0, [&result](std::string_view out) { result.append(out.begin(), out.end()); return true; }); diff --git a/verible/common/util/subcommand.cc b/verible/common/util/subcommand.cc index 40c370425..f138303dd 100644 --- a/verible/common/util/subcommand.cc +++ b/verible/common/util/subcommand.cc @@ -16,11 +16,11 @@ #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" namespace verible { @@ -50,7 +50,7 @@ SubcommandRegistry::SubcommandRegistry() } const SubcommandEntry &SubcommandRegistry::GetSubcommandEntry( - absl::string_view command) const { + std::string_view command) const { const SubcommandMap &commands(subcommand_map_); const auto iter = commands.find(command); if (iter == commands.end()) { @@ -61,7 +61,7 @@ const SubcommandEntry &SubcommandRegistry::GetSubcommandEntry( } absl::Status SubcommandRegistry::RegisterCommand( - absl::string_view name, const SubcommandEntry &command) { + std::string_view name, const SubcommandEntry &command) { const auto p = subcommand_map_.emplace(name, command); if (!p.second) { return absl::InvalidArgumentError(absl::StrCat( diff --git a/verible/common/util/subcommand.h b/verible/common/util/subcommand.h index 9c99a1d68..432afcaf4 100644 --- a/verible/common/util/subcommand.h +++ b/verible/common/util/subcommand.h @@ -19,11 +19,11 @@ #include #include #include +#include #include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/compare.h" #include "verible/common/util/container-iterator-range.h" @@ -31,7 +31,7 @@ namespace verible { // This should be the same type returned by InitCommandLine in // common/util/init_command_line.h -using SubcommandArgs = std::vector; +using SubcommandArgs = std::vector; using SubcommandArgsIterator = SubcommandArgs::const_iterator; using SubcommandArgsRange = verible::container_iterator_range; @@ -44,7 +44,7 @@ using SubcommandFunction = // Represents a function selected by the user. struct SubcommandEntry { - SubcommandEntry(SubcommandFunction fun, absl::string_view usage, + SubcommandEntry(SubcommandFunction fun, std::string_view usage, bool show_in_help = true) : main(std::move(fun)), usage(usage), show_in_help(show_in_help) {} @@ -74,10 +74,10 @@ class SubcommandRegistry { // Add a function to this map. // Returned status is an error if a function already exists with the given // name. - absl::Status RegisterCommand(absl::string_view name, const SubcommandEntry &); + absl::Status RegisterCommand(std::string_view name, const SubcommandEntry &); // Lookup a function in this map by name. - const SubcommandEntry &GetSubcommandEntry(absl::string_view command) const; + const SubcommandEntry &GetSubcommandEntry(std::string_view command) const; // Print a help summary of all registered commands. std::string ListCommands() const; diff --git a/verible/common/util/subcommand_test.cc b/verible/common/util/subcommand_test.cc index 6ebfc0f7a..6a8a0e243 100644 --- a/verible/common/util/subcommand_test.cc +++ b/verible/common/util/subcommand_test.cc @@ -17,11 +17,11 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace verible { @@ -41,7 +41,7 @@ TEST(SubcommandRegistryTest, HelpNoArgsTest) { const SubcommandEntry &help(registry.GetSubcommandEntry("help")); std::istringstream ins; std::ostringstream outs, errs; - std::vector args; + std::vector args; const SubcommandArgsRange range(args.begin(), args.end()); const auto status = help.main(range, ins, outs, errs); EXPECT_TRUE(status.ok()) << "Unexpected error:\n" << status.message(); @@ -55,7 +55,7 @@ TEST(SubcommandRegistryTest, HelpHelpCommand) { const SubcommandEntry &help(registry.GetSubcommandEntry("help")); std::istringstream ins; std::ostringstream outs, errs; - std::vector args{"help"}; + std::vector args{"help"}; const SubcommandArgsRange range(args.begin(), args.end()); const auto status = help.main(range, ins, outs, errs); @@ -82,7 +82,7 @@ TEST(SubcommandRegistryTest, RegisterCommandPublicOk) { EXPECT_TRUE(absl::StrContains(registry.ListCommands(), "fizz")); } - std::vector args; + std::vector args; const SubcommandArgsRange range(args.begin(), args.end()); const SubcommandEntry &fizz_entry(registry.GetSubcommandEntry("fizz")); @@ -102,7 +102,7 @@ TEST(SubcommandRegistryTest, ShowRegisteredCommandsOnWrongCommandRequest) { const SubcommandEntry &cmd(registry.GetSubcommandEntry("wrong_command")); - std::vector args{"foo", "bar"}; + std::vector args{"foo", "bar"}; const SubcommandArgsRange range(args.begin(), args.end()); std::istringstream ins; std::ostringstream outs, errs; @@ -130,7 +130,7 @@ TEST(SubcommandRegistryTest, RegisterCommandHiddenOk) { EXPECT_FALSE(absl::StrContains(registry.ListCommands(), "buzz")); } - std::vector args; + std::vector args; const SubcommandArgsRange range(args.begin(), args.end()); const SubcommandEntry &buzz_entry(registry.GetSubcommandEntry("buzz")); @@ -167,7 +167,7 @@ TEST(SubcommandRegistryTest, RegisterCommandMultipleCommands) { } // Run each subcommand once. - std::vector args; + std::vector args; const SubcommandArgsRange range(args.begin(), args.end()); { const SubcommandEntry &fizz_entry(registry.GetSubcommandEntry("fizz")); diff --git a/verible/common/util/tree-operations_test.cc b/verible/common/util/tree-operations_test.cc index 912a1cefc..ed15738e2 100644 --- a/verible/common/util/tree-operations_test.cc +++ b/verible/common/util/tree-operations_test.cc @@ -20,13 +20,13 @@ #include #include #include +#include #include #include #include "absl/strings/str_cat.h" // IWYU pragma: keep (not in all pp-branches) #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" // IWYU pragma: keep #include "gtest/gtest.h" #include "verible/common/util/logging.h" @@ -133,7 +133,7 @@ class SimpleNode { public: using ChildrenType = Container; - explicit SimpleNode(absl::string_view id, ChildrenType &&children = {}) + explicit SimpleNode(std::string_view id, ChildrenType &&children = {}) : children_(std::move(children)), id_(id) { Relink(); } @@ -941,7 +941,7 @@ TYPED_TEST(NodeWithParentTest, Path) { template void TestNodePath(TestSuite *test_suite, std::initializer_list node_path, - absl::string_view expected_string) { + std::string_view expected_string) { auto &node = test_suite->NodeAt(node_path); std::ostringstream output; output << NodePath(node); @@ -987,7 +987,7 @@ TYPED_TEST(NodeWithValueTest, PrintTreeWithCustomPrinter) { [](std::ostream &stream, const std::string &value) -> std::ostream & { return stream << "value=" << value; }); - static const absl::string_view expected_output = + static const std::string_view expected_output = "{ (value=root)\n" " { (value=0) }\n" " { (value=1)\n" @@ -1037,7 +1037,7 @@ TYPED_TEST(NodeWithValueTest, PrintTreeWithCustomPrinter) { [](std::ostream &stream, const std::string &value) -> std::ostream & { return stream << "value=" << value; }); - static const absl::string_view expected_output = + static const std::string_view expected_output = "{ (value=3.1)\n" " { (value=3.1.0)\n" " { (value=3.1.0.0) }\n" @@ -1056,7 +1056,7 @@ TYPED_TEST(NodeWithValueTest, PrintTree) { { std::ostringstream output; PrintTree(this->root, &output); - static const absl::string_view expected_output = + static const std::string_view expected_output = "{ (root)\n" " { (0) }\n" " { (1)\n" @@ -1102,7 +1102,7 @@ TYPED_TEST(NodeWithValueTest, PrintTree) { { std::ostringstream output; PrintTree(this->NodeAt({3, 1}), &output); - static const absl::string_view expected_output = + static const std::string_view expected_output = "{ (3.1)\n" " { (3.1.0)\n" " { (3.1.0.0) }\n" diff --git a/verible/common/util/user-interaction.cc b/verible/common/util/user-interaction.cc index 401a79d56..f1e6fe85d 100644 --- a/verible/common/util/user-interaction.cc +++ b/verible/common/util/user-interaction.cc @@ -17,8 +17,7 @@ #include #include #include - -#include "absl/strings/string_view.h" +#include #ifndef _WIN32 #include // for isatty @@ -41,7 +40,7 @@ bool IsInteractiveTerminalSession(const std::ostream &s) { } char ReadCharFromUser(std::istream &input, std::ostream &output, - bool input_is_terminal, absl::string_view prompt) { + bool input_is_terminal, std::string_view prompt) { if (input_is_terminal) { // Terminal input: print prompt, read whole line and return first character. term::bold(output, prompt) << std::flush; @@ -66,12 +65,12 @@ char ReadCharFromUser(std::istream &input, std::ostream &output, namespace term { // TODO(hzeller): assumption here that basic ANSI codes work on all // platforms, but if not, change this with ifdef. -static constexpr absl::string_view kBoldEscape("\033[1m"); -static constexpr absl::string_view kInverseEscape("\033[7m"); -static constexpr absl::string_view kNormalEscape("\033[0m"); +static constexpr std::string_view kBoldEscape("\033[1m"); +static constexpr std::string_view kInverseEscape("\033[7m"); +static constexpr std::string_view kNormalEscape("\033[0m"); // clang-format off -static constexpr absl::string_view kColorsStart[static_cast(Color::kNumColors)] = { +static constexpr std::string_view kColorsStart[static_cast(Color::kNumColors)] = { "\033[1;32m", // GREEN "\033[1;36m", // CYAN "\033[1;31m", // RED @@ -79,7 +78,7 @@ static constexpr absl::string_view kColorsStart[static_cast(Color::kNu }; // clang-format on -std::ostream &bold(std::ostream &out, absl::string_view s) { +std::ostream &bold(std::ostream &out, std::string_view s) { if (IsInteractiveTerminalSession(out)) { out << kBoldEscape << s << kNormalEscape; } else { @@ -87,7 +86,7 @@ std::ostream &bold(std::ostream &out, absl::string_view s) { } return out; } -std::ostream &inverse(std::ostream &out, absl::string_view s) { +std::ostream &inverse(std::ostream &out, std::string_view s) { if (IsInteractiveTerminalSession(out)) { out << kInverseEscape << s << kNormalEscape; } else { @@ -95,7 +94,7 @@ std::ostream &inverse(std::ostream &out, absl::string_view s) { } return out; } -std::ostream &Colored(std::ostream &out, absl::string_view s, Color c) { +std::ostream &Colored(std::ostream &out, std::string_view s, Color c) { if (IsInteractiveTerminalSession(out) && c != Color::kNone) { out << kColorsStart[static_cast(c)] << s << kNormalEscape; } else { diff --git a/verible/common/util/user-interaction.h b/verible/common/util/user-interaction.h index 5189a453c..53d24ef65 100644 --- a/verible/common/util/user-interaction.h +++ b/verible/common/util/user-interaction.h @@ -16,15 +16,14 @@ #define VERIBLE_COMMON_UTIL_USER_INTERACTION_H_ #include - -#include "absl/strings/string_view.h" +#include namespace verible { namespace term { // Convenience functions: Print bold or inverse if and only if this // is an interactive session connected to a terminal. Otherwise just plain. -std::ostream &bold(std::ostream &out, absl::string_view s); -std::ostream &inverse(std::ostream &out, absl::string_view s); +std::ostream &bold(std::ostream &out, std::string_view s); +std::ostream &inverse(std::ostream &out, std::string_view s); enum class Color { kGreen = 0, @@ -36,7 +35,7 @@ enum class Color { // Print the `s` string to `out` ostream colored with color `c`. // This will only apply if we're in an interactive terminal session -std::ostream &Colored(std::ostream &out, absl::string_view s, Color c); +std::ostream &Colored(std::ostream &out, std::string_view s, Color c); } // namespace term @@ -62,7 +61,7 @@ bool IsInteractiveTerminalSession(const std::ostream &s); // IsInteractiveTerminalSession(std::cout), // "Type a letter and confirm with ENTER: "); char ReadCharFromUser(std::istream &input, std::ostream &output, - bool input_is_terminal, absl::string_view prompt); + bool input_is_terminal, std::string_view prompt); } // namespace verible diff --git a/verible/common/util/vector-tree-test-util.cc b/verible/common/util/vector-tree-test-util.cc index 4fd407bfd..63ef67a21 100644 --- a/verible/common/util/vector-tree-test-util.cc +++ b/verible/common/util/vector-tree-test-util.cc @@ -15,8 +15,8 @@ #include "verible/common/util/vector-tree-test-util.h" #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/util/vector-tree.h" diff --git a/verible/common/util/vector-tree-test-util.h b/verible/common/util/vector-tree-test-util.h index 29ea473c8..5e62bb69c 100644 --- a/verible/common/util/vector-tree-test-util.h +++ b/verible/common/util/vector-tree-test-util.h @@ -17,9 +17,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/util/tree-operations.h" #include "verible/common/util/vector-tree.h" @@ -30,9 +30,9 @@ namespace testing { struct NamedInterval { int left; int right; - absl::string_view name; + std::string_view name; - NamedInterval(int l, int r, absl::string_view n) + NamedInterval(int l, int r, std::string_view n) : left(l), right(r), name(n) {} NamedInterval(const NamedInterval &) = default; diff --git a/verible/common/util/vector-tree_test.cc b/verible/common/util/vector-tree_test.cc index beed7cfdf..78c539d40 100644 --- a/verible/common/util/vector-tree_test.cc +++ b/verible/common/util/vector-tree_test.cc @@ -17,12 +17,12 @@ #include #include #include +#include #include #include #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/util/logging.h" @@ -38,7 +38,7 @@ using verible::testing::NamedInterval; using verible::testing::VectorTreeTestType; template -void ExpectPath(const Tree &tree, absl::string_view expect) { +void ExpectPath(const Tree &tree, std::string_view expect) { std::ostringstream stream; stream << NodePath(tree); EXPECT_EQ(stream.str(), expect); @@ -343,7 +343,7 @@ TEST(VectorTreeTest, DeepEqualRootToRootValueDifferent) { } struct NameOnly { - absl::string_view name; + std::string_view name; explicit NameOnly(const NamedInterval &v) : name(v.name) {} }; @@ -1154,7 +1154,7 @@ TEST(VectorTreeTest, ApplyPreOrderTransformValue) { auto tree = verible::testing::MakeExampleFamilyTree(); // Transform intervals. - std::vector visit_order; + std::vector visit_order; const int shift = 2; ApplyPreOrder(tree, [=, &visit_order](NamedInterval &interval) { visit_order.push_back(interval.name); @@ -1188,7 +1188,7 @@ TEST(VectorTreeTest, ApplyPreOrderTransformNode) { auto tree = verible::testing::MakeExampleFamilyTree(); // Transform intervals. - std::vector visit_order; + std::vector visit_order; const int shift = 2; ApplyPreOrder(tree, [=, &visit_order](VectorTreeTestType &node) { auto &interval = node.Value(); @@ -1223,7 +1223,7 @@ TEST(VectorTreeTest, ApplyPostOrderTransformValue) { auto tree = verible::testing::MakeExampleFamilyTree(); // Transform intervals. - std::vector visit_order; + std::vector visit_order; const int shift = 1; ApplyPostOrder(tree, [=, &visit_order](NamedInterval &interval) { visit_order.push_back(interval.name); @@ -1256,7 +1256,7 @@ TEST(VectorTreeTest, ApplyPostOrderTransformNode) { auto tree = verible::testing::MakeExampleFamilyTree(); // Transform intervals. - std::vector visit_order; + std::vector visit_order; const int shift = 1; ApplyPostOrder(tree, [=, &visit_order](VectorTreeTestType &node) { auto &interval = node.Value(); diff --git a/verible/verilog/CST/BUILD b/verible/verilog/CST/BUILD index 51befe0d4..a2ecea29c 100644 --- a/verible/verilog/CST/BUILD +++ b/verible/verilog/CST/BUILD @@ -100,7 +100,6 @@ cc_library( "//verible/common/text:token-info", "//verible/common/util:logging", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -126,7 +125,6 @@ cc_library( "//verible/common/analysis:syntax-tree-search-test-utils", "//verible/common/text:text-structure", "//verible/verilog/analysis:verilog-analyzer", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", # for library testonly ], ) @@ -159,7 +157,6 @@ cc_test( "//verible/common/text:text-structure", "//verible/common/text:token-info", "//verible/verilog/analysis:verilog-analyzer", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -289,7 +286,6 @@ cc_library( "//verible/verilog/parser:verilog-token-classifications", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -351,7 +347,6 @@ cc_test( "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -388,7 +383,6 @@ cc_test( "//verible/common/text:text-structure", "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -426,7 +420,6 @@ cc_test( "//verible/common/util:logging", "//verible/common/util:range", "//verible/verilog/analysis:verilog-analyzer", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -460,7 +453,6 @@ cc_test( "//verible/common/text:text-structure", "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -644,7 +636,6 @@ cc_test( "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -684,7 +675,6 @@ cc_test( "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -760,7 +750,6 @@ cc_test( "//verible/common/text:tree-utils", "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -801,7 +790,6 @@ cc_test( "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -841,7 +829,6 @@ cc_test( "//verible/common/text:tree-utils", "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -863,7 +850,6 @@ cc_library( deps = [ "//verible/common/util:logging", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -881,7 +867,6 @@ cc_library( "//verible/common/util:value-saver", "//verible/verilog/parser:verilog-parser", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -901,7 +886,6 @@ cc_library( "//verible/verilog/parser:verilog-token", "//verible/verilog/parser:verilog-token-classifications", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", "@nlohmann_json//:singleheader-json", ], ) @@ -927,7 +911,6 @@ cc_test( srcs = ["numbers_test.cc"], deps = [ ":numbers", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/verilog/CST/class_test.cc b/verible/verilog/CST/class_test.cc index b0a5eb532..fce1c5be4 100644 --- a/verible/verilog/CST/class_test.cc +++ b/verible/verilog/CST/class_test.cc @@ -23,9 +23,9 @@ #include "verible/verilog/CST/class.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" @@ -115,7 +115,7 @@ TEST(GetClassNameTest, ClassEndLabel) { } TEST(GetClassNameTest, NoClassEndLabelTest) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { {"class foo; endclass"}, }; for (const auto &test : kTestCases) { diff --git a/verible/verilog/CST/constraints_test.cc b/verible/verilog/CST/constraints_test.cc index dba682329..d09e0476d 100644 --- a/verible/verilog/CST/constraints_test.cc +++ b/verible/verilog/CST/constraints_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" @@ -69,7 +69,7 @@ TEST(FindAllConstraintDeclarationsTest, BasicTests) { } TEST(IsOutOfLineConstraintDefinitionTest, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"class foo; rand logic a; constraint Bar { a < 16; } endclass", false}, {"constraint classname::constraint_c { a <= b; }", true}, }; @@ -91,7 +91,7 @@ TEST(IsOutOfLineConstraintDefinitionTest, BasicTests) { // Tests that GetSymbolIdentifierFromConstraintDeclaration correctly returns // the token of the symbol identifier. TEST(GetSymbolIdentifierFromConstraintDeclarationTest, BasicTests) { - const std::pair kTestCases[] = { + const std::pair kTestCases[] = { {"class foo; rand logic a; constraint Bar { a < 16; } endclass", "Bar"}, {"class foo; rand logic a; constraint b { a >= 16; } endclass", "b"}, {"class foo; rand logic a; constraint stH { a == 16; } endclass", "stH"}, diff --git a/verible/verilog/CST/expression.cc b/verible/verilog/CST/expression.cc index 9afb15170..2deab55a6 100644 --- a/verible/verilog/CST/expression.cc +++ b/verible/verilog/CST/expression.cc @@ -15,10 +15,10 @@ #include "verible/verilog/CST/expression.h" #include +#include #include #include "absl/strings/numbers.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" diff --git a/verible/verilog/CST/functions_test.cc b/verible/verilog/CST/functions_test.cc index 7df0fc1d4..3b4609925 100644 --- a/verible/verilog/CST/functions_test.cc +++ b/verible/verilog/CST/functions_test.cc @@ -15,9 +15,9 @@ #include "verible/verilog/CST/functions.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" diff --git a/verible/verilog/CST/identifier_test.cc b/verible/verilog/CST/identifier_test.cc index a52b3c7bc..d1c38aaae 100644 --- a/verible/verilog/CST/identifier_test.cc +++ b/verible/verilog/CST/identifier_test.cc @@ -15,10 +15,10 @@ #include "verible/verilog/CST/identifier.h" #include +#include #include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" @@ -41,7 +41,7 @@ using verible::TreeSearchMatch; // Finds all qualified ids are found. TEST(IdIsQualifiedTest, VariousIds) { // Each test should have only 1 id, qualified or unqualified - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"function foo(); endfunction", 0 /* foo */}, {"function myclass::foo(); endfunction", 1 /* myclass::foo */}, {"task goo(); endtask", 0 /* goo */}, diff --git a/verible/verilog/CST/macro_test.cc b/verible/verilog/CST/macro_test.cc index 6abcf6a35..835278222 100644 --- a/verible/verilog/CST/macro_test.cc +++ b/verible/verilog/CST/macro_test.cc @@ -14,9 +14,9 @@ #include "verible/verilog/CST/macro.h" +#include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" @@ -43,7 +43,7 @@ using verible::TextStructureView; using verible::TreeSearchMatch; struct FindAllTestCase { - absl::string_view code; + std::string_view code; int expected_matches; }; @@ -79,8 +79,8 @@ TEST(FindAllMacroCallsTest, Various) { } struct MatchIdTestCase { - absl::string_view code; - std::vector expected_names; + std::string_view code; + std::vector expected_names; }; TEST(GetMacroCallIdsTest, Various) { @@ -102,7 +102,7 @@ TEST(GetMacroCallIdsTest, Various) { EXPECT_OK(analyzer.Analyze()); const auto &root = analyzer.Data().SyntaxTree(); const auto macro_calls = FindAllMacroCalls(*ABSL_DIE_IF_NULL(root)); - std::vector found_names; + std::vector found_names; found_names.reserve(macro_calls.size()); for (const auto &match : macro_calls) { found_names.push_back(GetMacroCallId(*match.match)->text()); @@ -115,7 +115,7 @@ TEST(GetMacroCallIdsTest, Various) { } struct CallArgsTestCase { - absl::string_view code; + std::string_view code; bool expect_empty; }; @@ -156,9 +156,9 @@ TEST(GetFunctionFormalPortsGroupTest, WithFormalPorts) { {"module m;\n", {kTag, "`FOO"}, "\nendmodule\n"}, }; for (const auto &test : kTestCases) { - const absl::string_view code(test.code); + const std::string_view code(test.code); VerilogAnalyzer analyzer(code, "test-file"); - const absl::string_view code_copy(analyzer.Data().Contents()); + const std::string_view code_copy(analyzer.Data().Contents()); ASSERT_OK(analyzer.Analyze()) << "failed on:\n" << code; const auto &root = analyzer.Data().SyntaxTree(); @@ -166,7 +166,7 @@ TEST(GetFunctionFormalPortsGroupTest, WithFormalPorts) { ASSERT_EQ(macro_items.size(), 1); const auto ¯o_item = *macro_items.front().match; const auto &id = GetMacroGenericItemId(macro_item); - const absl::string_view id_text = id->text(); + const std::string_view id_text = id->text(); // TODO(b/151371397): Refactor this test code along with // common/analysis/linter_test_util.h to be able to compare set-symmetric diff --git a/verible/verilog/CST/match-test-utils.cc b/verible/verilog/CST/match-test-utils.cc index ae91ace05..098495618 100644 --- a/verible/verilog/CST/match-test-utils.cc +++ b/verible/verilog/CST/match-test-utils.cc @@ -16,9 +16,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" @@ -35,14 +35,14 @@ using verible::TextStructureView; using verible::TreeSearchMatch; void TestVerilogSyntaxRangeMatches( - absl::string_view test_name, const SyntaxTreeSearchTestCase &test_case, + std::string_view test_name, const SyntaxTreeSearchTestCase &test_case, const std::function(const TextStructureView &)> &match_collector) { - const absl::string_view code(test_case.code); + const std::string_view code(test_case.code); // Parse Verilog source code into syntax tree. VerilogAnalyzer analyzer(code, "test-file"); const TextStructureView &text_structure(analyzer.Data()); - const absl::string_view code_copy = text_structure.Contents(); + const std::string_view code_copy = text_structure.Contents(); ASSERT_OK(analyzer.Analyze()) << test_name << " failed on:\n" << code; // Run the match collector to gather results. diff --git a/verible/verilog/CST/match-test-utils.h b/verible/verilog/CST/match-test-utils.h index fbb21be7d..5bcc0c4a8 100644 --- a/verible/verilog/CST/match-test-utils.h +++ b/verible/verilog/CST/match-test-utils.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_CST_MATCH_TEST_UTILS_H_ #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/text/text-structure.h" @@ -30,7 +30,7 @@ namespace verilog { // 'test_case'. // Test will terminate early if there are lexical or syntax errors. void TestVerilogSyntaxRangeMatches( - absl::string_view test_name, + std::string_view test_name, const verible::SyntaxTreeSearchTestCase &test_case, const std::function( const verible::TextStructureView &)> &match_collector); diff --git a/verible/verilog/CST/numbers.cc b/verible/verilog/CST/numbers.cc index 3d9c055e0..3602d45a5 100644 --- a/verible/verilog/CST/numbers.cc +++ b/verible/verilog/CST/numbers.cc @@ -19,9 +19,9 @@ #include #include #include +#include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "verible/common/util/logging.h" @@ -38,7 +38,7 @@ std::ostream &operator<<(std::ostream &stream, const BasedNumber &number) { return stream; } -BasedNumber::BasedNumber(absl::string_view base_sign, absl::string_view digits) +BasedNumber::BasedNumber(std::string_view base_sign, std::string_view digits) : ok(false) { // See definition of 'based_number' nonterminal rule in verilog.y. if (!absl::ConsumePrefix(&base_sign, "\'")) return; @@ -50,7 +50,7 @@ BasedNumber::BasedNumber(absl::string_view base_sign, absl::string_view digits) // Next character is the base: [bBdDhHoO]. CHECK_EQ(base_sign.length(), 1); base = std::tolower(base_sign[0]); - static const absl::string_view valid_bases("bdho"); + static const std::string_view valid_bases("bdho"); if (!absl::StrContains(valid_bases, base)) return; // Filter out underscores. diff --git a/verible/verilog/CST/numbers.h b/verible/verilog/CST/numbers.h index f49ea1567..0c20a4ff8 100644 --- a/verible/verilog/CST/numbers.h +++ b/verible/verilog/CST/numbers.h @@ -17,8 +17,7 @@ #include #include - -#include "absl/strings/string_view.h" +#include namespace verilog { namespace analysis { @@ -45,9 +44,9 @@ struct BasedNumber { // Construct parses a literal string based on // '{Dec|Bin|Oct|Hex}{Base|Digits}' from verilog.lex. // base_sign is lexed as one token, e.g. 'b, 'sb (signed). - BasedNumber(absl::string_view base_sign, absl::string_view digits); + BasedNumber(std::string_view base_sign, std::string_view digits); - BasedNumber(char base_, bool sign_, absl::string_view text) + BasedNumber(char base_, bool sign_, std::string_view text) : base(base_), signedness(sign_), literal(text), ok(true) {} bool operator==(const BasedNumber &rhs) const { diff --git a/verible/verilog/CST/numbers_test.cc b/verible/verilog/CST/numbers_test.cc index 92c75b039..ce31a13a5 100644 --- a/verible/verilog/CST/numbers_test.cc +++ b/verible/verilog/CST/numbers_test.cc @@ -15,9 +15,9 @@ #include "verible/verilog/CST/numbers.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace verilog { @@ -25,8 +25,8 @@ namespace analysis { namespace { struct BasedNumberTestCase { - absl::string_view base; - absl::string_view digits; + std::string_view base; + std::string_view digits; BasedNumber expected; }; @@ -60,7 +60,7 @@ TEST(BasedNumberTest, ParseLiteral) { // Tests that invalid inputs are marked as not OK. TEST(BasedNumberTest, ParseInvalidLiterals) { - const std::pair test_cases[] = { + const std::pair test_cases[] = { {"", ""}, {"xx", ""}, {"", "96"}, diff --git a/verible/verilog/CST/parameters_test.cc b/verible/verilog/CST/parameters_test.cc index 4eb2bc62a..ab466f95c 100644 --- a/verible/verilog/CST/parameters_test.cc +++ b/verible/verilog/CST/parameters_test.cc @@ -15,10 +15,10 @@ #include "verible/verilog/CST/parameters.h" #include +#include #include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" @@ -79,7 +79,7 @@ TEST(FindAllParamDeclarationsTest, BasicParams) { // Tests that GetParamKeyword correctly returns that the parameter type is // localparam. TEST(GetParamKeywordTest, LocalParamDeclared) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"module foo; localparam int Bar = 1; endmodule", 1}, {"class foo; localparam int Bar = 1; endclass", 1}, {"module foo; localparam Bar = 1; endmodule", 1}, @@ -100,7 +100,7 @@ TEST(GetParamKeywordTest, LocalParamDeclared) { // Tests that GetParamKeyword correctly returns that the parameter type is // parameter. TEST(GetParamKeywordTest, ParameterDeclared) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"module foo; parameter int Bar = 1; endmodule", 1}, {"module foo #(parameter int Bar = 1); endmodule", 1}, {"module foo #(int Bar = 1); endmodule", 1}, @@ -128,7 +128,7 @@ TEST(GetParamKeywordTest, ParameterDeclared) { // Tests that GetParamKeyword correctly returns the parameter type when multiple // parameters are defined. TEST(GetParamKeywordTest, MultipleParamsDeclared) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { {"module foo; parameter int Bar = 1; localparam int Bar_2 = 2; " "endmodule"}, {"class foo; parameter int Bar = 1; localparam int Bar_2 = 2; endclass"}, @@ -156,7 +156,7 @@ TEST(GetParamKeywordTest, MultipleParamsDeclared) { // Tests that GetParameterToken correctly returns the token of the // parameter. TEST(GetParameterTokenTest, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"module foo; parameter Bar = 1; endmodule", "parameter"}, {"module foo; localparam Bar_1 = 1; endmodule", "localparam"}, {"module foo; localparam int HelloWorld = 1; endmodule", "localparam"}, @@ -183,7 +183,7 @@ TEST(GetParameterTokenTest, BasicTests) { // Tests that GetParamTypeSymbol correctly returns the kParamType node. TEST(GetParamTypeSymbolTest, BasicTests) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { {"module foo; parameter Bar = 1; endmodule"}, {"module foo; parameter int Bar = 1; endmodule"}, {"module foo #(parameter int Bar = 1); endmodule"}, @@ -209,7 +209,7 @@ TEST(GetParamTypeSymbolTest, BasicTests) { // Tests that GetParameterNameToken correctly returns the token of the // parameter. TEST(GetParameterNameTokenTest, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"module foo; parameter Bar = 1; endmodule", "Bar"}, {"module foo; localparam Bar_1 = 1; endmodule", "Bar_1"}, {"module foo; localparam int HelloWorld = 1; endmodule", "HelloWorld"}, @@ -234,7 +234,7 @@ TEST(GetParameterNameTokenTest, BasicTests) { // Test that GetAllParameterNameTokens correctly returns all tokens TEST(GetAllParameterNameTokensTest, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"module foo; parameter Bar = 1; endmodule", 1}, {"module foo; localparam Bar_1 = 1; endmodule", 1}, {"module foo; localparam int HelloWorld = 1; endmodule", 1}, @@ -266,7 +266,7 @@ TEST(GetAllParameterNameTokensTest, BasicTests) { // Tests that GetAllAssignedParameterSymbols correctly returns all the // symbols for each kParameterAssign node TEST(GetAllAssignedParameterSymbolsTest, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"module foo; parameter Bar = 1; endmodule", 0}, {"module foo; localparam Bar_1 = 1; endmodule", 0}, {"module foo; localparam int HelloWorld = 1; endmodule", 0}, @@ -296,7 +296,7 @@ TEST(GetAllAssignedParameterSymbolsTest, BasicTests) { } TEST(GetAssignedParameterNameToken, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"parameter int Bar = 1, Foo = 1;", "Foo"}, {"module foo; parameter int Bar = 1, Fox = 1; endmodule;", "Fox"}, }; @@ -319,7 +319,7 @@ TEST(GetAssignedParameterNameToken, BasicTests) { // Tests that GetSymbolIdentifierFromParamDeclaration correctly returns the // token of the symbol identifier. TEST(GetSymbolIdentifierFromParamDeclarationTest, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"module foo; parameter type Bar; endmodule", "Bar"}, {"module foo; localparam type Bar_1; endmodule", "Bar_1"}, {"module foo #(parameter type HelloWorld1); endmodule", "HelloWorld1"}, @@ -343,7 +343,7 @@ TEST(GetSymbolIdentifierFromParamDeclarationTest, BasicTests) { // Tests that IsParamTypeDeclaration correctly returns true if the parameter is // a parameter type declaration. TEST(IsParamTypeDeclarationTest, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"module foo; parameter type Bar; endmodule", true}, {"module foo; localparam type Bar_1; endmodule", true}, {"module foo #(parameter type HelloWorld1); endmodule", true}, @@ -373,7 +373,7 @@ TEST(IsParamTypeDeclarationTest, BasicTests) { // Tests that GetTypeAssignmentFromParamDeclaration correctly returns the // kTypeAssignment node. TEST(GetTypeAssignmentFromParamDeclarationTests, BasicTests) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { {"module foo; parameter type Bar = 1; endmodule"}, {"module foo #(parameter type Bar = 1); endmodule"}, {"module foo; localparam type Bar = 1; endmodule"}, @@ -434,7 +434,7 @@ TEST(GetIdentifierLeafFromTypeAssignmentTest, BasicTests) { // Tests that GetParamTypeInfoSymbol correctly returns the kTypeInfo node. TEST(GetParamTypeInfoSymbolTest, BasicTests) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { {"module foo; parameter Bar = 1; endmodule"}, {"module foo; parameter int Bar = 1; endmodule"}, {"module foo #(parameter int Bar = 1); endmodule"}, @@ -458,7 +458,7 @@ TEST(GetParamTypeInfoSymbolTest, BasicTests) { } TEST(IsTypeInfoEmptyTest, EmptyTests) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { {"module foo; parameter Bar = 1; endmodule"}, {"module foo #(parameter Bar = 1); endmodule"}, {"module foo; localparam Bar = 1; endmodule"}, @@ -482,7 +482,7 @@ TEST(IsTypeInfoEmptyTest, EmptyTests) { } TEST(IsTypeInfoEmptyTest, NonEmptyTests) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { {"module foo; localparam bit Bar = 1; endmodule"}, {"module foo #(parameter int Bar = 1); endmodule"}, {"module foo; parameter int Bar = 1; endmodule"}, diff --git a/verible/verilog/CST/port_test.cc b/verible/verilog/CST/port_test.cc index 3e291de6c..c7fd3c52c 100644 --- a/verible/verilog/CST/port_test.cc +++ b/verible/verilog/CST/port_test.cc @@ -25,10 +25,10 @@ #include #include #include +#include #include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" @@ -318,8 +318,8 @@ TEST(FindAllTaskFunctionPortDeclarationsTest, ExpectNoTaskFunctionPorts) { } struct ExpectedPort { - absl::string_view id; // name of port - bool have_type; // is type specified? + std::string_view id; // name of port + bool have_type; // is type specified? }; struct TaskFunctionTestCase { diff --git a/verible/verilog/CST/statement_test.cc b/verible/verilog/CST/statement_test.cc index e0c7f2d3a..3d27f259d 100644 --- a/verible/verilog/CST/statement_test.cc +++ b/verible/verilog/CST/statement_test.cc @@ -15,9 +15,9 @@ #include "verible/verilog/CST/statement.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/matcher/matcher-builders.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" @@ -828,7 +828,7 @@ TEST(GetAnyConditionalElseClauseTest, NoElseClause) { "endtask\n"}}, }; for (const auto &test : kTestCases) { - const absl::string_view code(test.token_data.code); + const std::string_view code(test.token_data.code); VerilogAnalyzer analyzer(code, "test-file"); ASSERT_OK(analyzer.Analyze()) << "failed on:\n" << code; const auto &root = analyzer.Data().SyntaxTree(); diff --git a/verible/verilog/CST/tasks_test.cc b/verible/verilog/CST/tasks_test.cc index fd95d4ebb..1d1130463 100644 --- a/verible/verilog/CST/tasks_test.cc +++ b/verible/verilog/CST/tasks_test.cc @@ -15,9 +15,9 @@ #include "verible/verilog/CST/tasks.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" diff --git a/verible/verilog/CST/type_test.cc b/verible/verilog/CST/type_test.cc index 41836427e..a72e4412f 100644 --- a/verible/verilog/CST/type_test.cc +++ b/verible/verilog/CST/type_test.cc @@ -15,10 +15,10 @@ #include "verible/verilog/CST/type.h" #include +#include #include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/analysis/syntax-tree-search.h" @@ -45,7 +45,7 @@ using verible::TreeSearchMatch; // Tests that the correct amount of node kDataType declarations are found. TEST(FindAllDataTypeDeclarationsTest, BasicTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"", 0}, {"class foo; endclass", 0}, {"function foo; endfunction", 1}, @@ -205,7 +205,7 @@ TEST(FindAllUnionTypesTest, BasicTests) { // Tests that IsStorageTypeOfDataTypeSpecified correctly returns true if the // node kDataType has declared a storage type. TEST(IsStorageTypeOfDataTypeSpecifiedTest, AcceptTests) { - constexpr std::pair kTestCases[] = { + constexpr std::pair kTestCases[] = { {"function foo(int bar); endfunction", 2}, {"function foo(int foo, bit bar); endfunction", 3}, {"function foo (bit [10:0] bar); endfunction", 2}, @@ -231,7 +231,7 @@ TEST(IsStorageTypeOfDataTypeSpecifiedTest, AcceptTests) { // Tests that IsStorageTypeOfDataTypeSpecified correctly returns false if the // node kDataType has not declared a storage type. TEST(IsStorageTypeOfDataTypeSpecifiedTest, RejectTests) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { {"function foo (bar); endfunction"}, {"function foo(foo, ref bar); endfunction"}, {"function foo(input foo, inout bar); endfunction"}, diff --git a/verible/verilog/CST/verilog-tree-json.cc b/verible/verilog/CST/verilog-tree-json.cc index ad3b05951..a7ad12147 100644 --- a/verible/verilog/CST/verilog-tree-json.cc +++ b/verible/verilog/CST/verilog-tree-json.cc @@ -15,9 +15,9 @@ #include "verible/verilog/CST/verilog-tree-json.h" #include +#include #include -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -37,7 +37,7 @@ namespace verilog { class VerilogTreeToJsonConverter : public verible::SymbolVisitor { public: - explicit VerilogTreeToJsonConverter(absl::string_view base); + explicit VerilogTreeToJsonConverter(std::string_view base); void Visit(const verible::SyntaxTreeLeaf &) final; void Visit(const verible::SyntaxTreeNode &) final; @@ -56,7 +56,7 @@ class VerilogTreeToJsonConverter : public verible::SymbolVisitor { json *value_; }; -VerilogTreeToJsonConverter::VerilogTreeToJsonConverter(absl::string_view base) +VerilogTreeToJsonConverter::VerilogTreeToJsonConverter(std::string_view base) : context_(base, [](std::ostream &stream, int e) { stream << TokenTypeToString(static_cast(e)); @@ -66,7 +66,7 @@ VerilogTreeToJsonConverter::VerilogTreeToJsonConverter(absl::string_view base) void VerilogTreeToJsonConverter::Visit(const verible::SyntaxTreeLeaf &leaf) { const verilog_tokentype tokentype = static_cast(leaf.Tag().tag); - absl::string_view type_str = TokenTypeToString(tokentype); + std::string_view type_str = TokenTypeToString(tokentype); // Don't include token's text for operators, keywords, or anything that is a // part of Verilog syntax. For such types, TokenTypeToString() is equal to // token's text. Exception has to be made for identifiers, because things like @@ -94,7 +94,7 @@ void VerilogTreeToJsonConverter::Visit(const verible::SyntaxTreeNode &node) { } json ConvertVerilogTreeToJson(const verible::Symbol &root, - absl::string_view base) { + std::string_view base) { VerilogTreeToJsonConverter converter(base); root.Accept(&converter); return converter.TakeJsonValue(); diff --git a/verible/verilog/CST/verilog-tree-json.h b/verible/verilog/CST/verilog-tree-json.h index 704f5f209..970a9b284 100644 --- a/verible/verilog/CST/verilog-tree-json.h +++ b/verible/verilog/CST/verilog-tree-json.h @@ -15,7 +15,8 @@ #ifndef VERIBLE_VERILOG_CST_VERILOG_TREE_JSON_H_ #define VERIBLE_VERILOG_CST_VERILOG_TREE_JSON_H_ -#include "absl/strings/string_view.h" +#include + #include "nlohmann/json.hpp" #include "verible/common/text/symbol.h" @@ -23,7 +24,7 @@ namespace verilog { // Returns a JSON representation of tree contained at root. nlohmann::json ConvertVerilogTreeToJson(const verible::Symbol &root, - absl::string_view base); + std::string_view base); } // namespace verilog diff --git a/verible/verilog/CST/verilog-tree-print.cc b/verible/verilog/CST/verilog-tree-print.cc index d3f15befc..4fcf4116c 100644 --- a/verible/verilog/CST/verilog-tree-print.cc +++ b/verible/verilog/CST/verilog-tree-print.cc @@ -19,9 +19,9 @@ #include #include #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/symbol.h" @@ -34,7 +34,7 @@ namespace verilog { VerilogPrettyPrinter::VerilogPrettyPrinter(std::ostream *output_stream, - absl::string_view base) + std::string_view base) : verible::PrettyPrinter( output_stream, verible::TokenInfo::Context(base, [](std::ostream &stream, int e) { @@ -65,7 +65,7 @@ void VerilogPrettyPrinter::Visit(const verible::SyntaxTreeNode &node) { auto_indent() << "}" << std::endl; } -void PrettyPrintVerilogTree(const verible::Symbol &root, absl::string_view base, +void PrettyPrintVerilogTree(const verible::Symbol &root, std::string_view base, std::ostream *stream) { VerilogPrettyPrinter printer(stream, base); root.Accept(&printer); diff --git a/verible/verilog/CST/verilog-tree-print.h b/verible/verilog/CST/verilog-tree-print.h index 01b54f07c..1357149e5 100644 --- a/verible/verilog/CST/verilog-tree-print.h +++ b/verible/verilog/CST/verilog-tree-print.h @@ -18,8 +18,8 @@ #define VERIBLE_VERILOG_CST_VERILOG_TREE_PRINT_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/symbol.h" @@ -30,7 +30,7 @@ namespace verilog { class VerilogPrettyPrinter : public verible::PrettyPrinter { public: explicit VerilogPrettyPrinter(std::ostream *output_stream, - absl::string_view base); + std::string_view base); void Visit(const verible::SyntaxTreeLeaf &) final; void Visit(const verible::SyntaxTreeNode &) final; @@ -39,7 +39,7 @@ class VerilogPrettyPrinter : public verible::PrettyPrinter { }; // Prints tree contained at root to stream -void PrettyPrintVerilogTree(const verible::Symbol &root, absl::string_view base, +void PrettyPrintVerilogTree(const verible::Symbol &root, std::string_view base, std::ostream *stream); } // namespace verilog diff --git a/verible/verilog/CST/verilog-treebuilder-utils.cc b/verible/verilog/CST/verilog-treebuilder-utils.cc index ead680e58..00af7e6e2 100644 --- a/verible/verilog/CST/verilog-treebuilder-utils.cc +++ b/verible/verilog/CST/verilog-treebuilder-utils.cc @@ -15,9 +15,9 @@ #include "verible/verilog/CST/verilog-treebuilder-utils.h" #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/symbol.h" @@ -29,25 +29,24 @@ namespace verilog { using verible::down_cast; // Set of utility functions for embedded a statement into a certain context. -std::string EmbedInClass(absl::string_view text) { +std::string EmbedInClass(std::string_view text) { return absl::StrCat("class test_class;\n", text, "\nendclass\n"); } -std::string EmbedInModule(absl::string_view text) { +std::string EmbedInModule(std::string_view text) { return absl::StrCat("module test_module;\n", text, "\nendmodule\n"); } -std::string EmbedInFunction(absl::string_view text) { +std::string EmbedInFunction(std::string_view text) { return absl::StrCat("function integer test_function;\n", text, "\nendfunction\n"); } -std::string EmbedInClassMethod(absl::string_view text) { +std::string EmbedInClassMethod(std::string_view text) { return EmbedInClass(EmbedInFunction(text)); } -void ExpectString(const verible::SymbolPtr &symbol, - absl::string_view expected) { +void ExpectString(const verible::SymbolPtr &symbol, std::string_view expected) { const auto *leaf = down_cast(symbol.get()); CHECK(leaf != nullptr) << "expected: " << expected; CHECK_EQ(leaf->get().text(), expected); diff --git a/verible/verilog/CST/verilog-treebuilder-utils.h b/verible/verilog/CST/verilog-treebuilder-utils.h index a105f9d5a..f69626138 100644 --- a/verible/verilog/CST/verilog-treebuilder-utils.h +++ b/verible/verilog/CST/verilog-treebuilder-utils.h @@ -35,23 +35,23 @@ #define VERIBLE_VERILOG_CST_VERILOG_TREEBUILDER_UTILS_H_ #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/verilog/CST/verilog-nonterminals.h" namespace verilog { // Set of utility functions for embedding a statement into a certain context. -std::string EmbedInModule(absl::string_view text); -std::string EmbedInClass(absl::string_view text); -std::string EmbedInFunction(absl::string_view text); -std::string EmbedInClassMethod(absl::string_view text); +std::string EmbedInModule(std::string_view text); +std::string EmbedInClass(std::string_view text); +std::string EmbedInFunction(std::string_view text); +std::string EmbedInClassMethod(std::string_view text); // Checks that symbol is symbol is a leaf and its text matches expected // Uses gunit's CHECK to raise error -void ExpectString(const verible::SymbolPtr &symbol, absl::string_view expected); +void ExpectString(const verible::SymbolPtr &symbol, std::string_view expected); template verible::SymbolPtr MakeParenGroup(T1 &&left_paren, T2 &&contents, diff --git a/verible/verilog/analysis/BUILD b/verible/verilog/analysis/BUILD index 4740fd3ec..30b52c3ba 100644 --- a/verible/verilog/analysis/BUILD +++ b/verible/verilog/analysis/BUILD @@ -34,7 +34,6 @@ cc_test( cc_library( name = "descriptions", hdrs = ["descriptions.h"], - deps = ["@abseil-cpp//absl/strings:string_view"], alwayslink = 1, ) @@ -50,7 +49,6 @@ cc_library( "//verible/verilog/CST:module", "//verible/verilog/preprocessor:verilog-preprocess", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -60,7 +58,6 @@ cc_test( deps = [ ":extractors", "//verible/verilog/preprocessor:verilog-preprocess", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -74,7 +71,6 @@ cc_library( ":verilog-analyzer", "//verible/common/analysis:file-analyzer", "//verible/common/strings:line-column-map", - "@abseil-cpp//absl/strings:string_view", "@nlohmann_json//:singleheader-json", ], ) @@ -88,7 +84,6 @@ cc_library( "//verible/common/util:logging", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -100,7 +95,6 @@ cc_test( "//verible/common/text:token-stream-view", "//verible/verilog/parser:verilog-lexer", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -154,7 +148,6 @@ cc_test( "//verible/common/text:token-info", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -195,7 +188,6 @@ cc_library( "@abseil-cpp//absl/log", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -213,7 +205,6 @@ cc_library( "//verible/verilog/parser:verilog-parser", "//verible/verilog/parser:verilog-token-classifications", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -237,14 +228,12 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) cc_library( name = "verilog-linter-constants", hdrs = ["verilog-linter-constants.h"], - deps = ["@abseil-cpp//absl/strings:string_view"], ) cc_library( @@ -279,7 +268,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -302,7 +290,6 @@ cc_test( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -330,7 +317,6 @@ cc_test( "//verible/common/text:token-info", "//verible/common/text:tree-builder-test-util", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -351,7 +337,6 @@ cc_test( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -363,7 +348,6 @@ cc_test( deps = [ ":verilog-equivalence", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@abseil-cpp//absl/types:span", "@googletest//:gtest", "@googletest//:gtest_main", @@ -379,7 +363,6 @@ cc_library( "//verible/common/util:iterator-range", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -389,7 +372,6 @@ cc_test( deps = [ ":verilog-filelist", "//verible/common/util:file-util", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -409,7 +391,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@abseil-cpp//absl/time", "@abseil-cpp//absl/types:optional", ], @@ -428,7 +409,6 @@ cc_test( "//verible/verilog/CST:module", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -477,7 +457,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@abseil-cpp//absl/time", ], ) @@ -496,7 +475,6 @@ cc_test( "//verible/common/util:tree-operations", "@abseil-cpp//absl/base:core_headers", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -512,7 +490,6 @@ cc_library( "//verible/common/strings:compare", "//verible/common/strings:display-utils", "//verible/common/util:logging", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -526,7 +503,6 @@ cc_test( "//verible/common/util:file-util", "//verible/common/util:logging", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/verilog/analysis/checkers/BUILD b/verible/verilog/analysis/checkers/BUILD index 46e94444a..98178d92c 100644 --- a/verible/verilog/analysis/checkers/BUILD +++ b/verible/verilog/analysis/checkers/BUILD @@ -96,7 +96,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -126,7 +125,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -157,7 +155,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -193,7 +190,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -224,7 +220,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -265,7 +260,6 @@ cc_library( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -301,7 +295,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -338,7 +331,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -373,7 +365,6 @@ cc_library( "//verible/verilog/CST:verilog-matchers", # fixdeps: keep "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -406,7 +397,6 @@ cc_library( "//verible/verilog/CST:verilog-matchers", # fixdeps: keep "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -446,7 +436,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -460,7 +449,6 @@ cc_test( "//verible/common/analysis:text-structure-linter-test-utils", "//verible/verilog/analysis:verilog-analyzer", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -483,7 +471,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -497,7 +484,6 @@ cc_test( "//verible/common/analysis:text-structure-linter-test-utils", "//verible/verilog/analysis:verilog-analyzer", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -525,7 +511,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -559,7 +544,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -591,7 +575,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -625,7 +608,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -663,7 +645,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], alwayslink = 1, @@ -701,7 +682,6 @@ cc_library( "//verible/verilog/CST:verilog-matchers", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -723,7 +703,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -808,7 +787,6 @@ cc_library( "//verible/verilog/CST:verilog-matchers", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -846,7 +824,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -882,7 +859,6 @@ cc_library( "//verible/verilog/CST:verilog-matchers", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -922,7 +898,6 @@ cc_library( "//verible/verilog/CST:verilog-matchers", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -963,7 +938,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1003,7 +977,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/numeric:int128", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1018,7 +991,6 @@ cc_test( "//verible/verilog/analysis:verilog-analyzer", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -1046,7 +1018,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1083,7 +1054,6 @@ cc_library( "//verible/verilog/CST:verilog-matchers", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1119,7 +1089,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1155,7 +1124,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1194,7 +1162,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1235,7 +1202,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1269,7 +1235,6 @@ cc_library( "@abseil-cpp//absl/base:core_headers", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1309,7 +1274,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1348,7 +1312,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1388,7 +1351,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1429,7 +1391,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1467,7 +1428,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1504,7 +1464,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1542,7 +1501,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], alwayslink = 1, @@ -1580,7 +1538,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1615,7 +1572,6 @@ cc_library( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], alwayslink = 1, @@ -1649,7 +1605,6 @@ cc_library( "//verible/verilog/parser:verilog-lexer", "//verible/verilog/parser:verilog-token-classifications", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1682,7 +1637,6 @@ cc_library( "//verible/verilog/parser:verilog-token-classifications", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1721,7 +1675,6 @@ cc_library( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], alwayslink = 1, @@ -1738,7 +1691,6 @@ cc_test( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -1762,7 +1714,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1801,7 +1752,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1837,7 +1787,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1874,7 +1823,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1915,7 +1863,6 @@ cc_library( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1953,7 +1900,6 @@ cc_library( "//verible/verilog/CST:verilog-matchers", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -1995,7 +1941,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], alwayslink = 1, @@ -2034,7 +1979,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -2050,7 +1994,6 @@ cc_test( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -2076,7 +2019,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], alwayslink = 1, @@ -2116,7 +2058,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -2133,7 +2074,6 @@ cc_test( "//verible/verilog/analysis:verilog-analyzer", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -2154,7 +2094,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -2190,7 +2129,6 @@ cc_library( "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -2227,7 +2165,6 @@ cc_library( "//verible/verilog/analysis:lint-rule-registry", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -2261,7 +2198,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/analysis:descriptions", "//verible/verilog/analysis:lint-rule-registry", - "@abseil-cpp//absl/strings:string_view", ], alwayslink = 1, ) @@ -2305,7 +2241,6 @@ cc_library( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], alwayslink = 1, @@ -2321,7 +2256,6 @@ cc_test( "//verible/verilog/analysis:verilog-analyzer", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/log:check", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/verilog/analysis/checkers/always-comb-blocking-rule.cc b/verible/verilog/analysis/checkers/always-comb-blocking-rule.cc index 26776e7bb..0988b8dae 100644 --- a/verible/verilog/analysis/checkers/always-comb-blocking-rule.cc +++ b/verible/verilog/analysis/checkers/always-comb-blocking-rule.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -48,7 +48,7 @@ using verible::matcher::Matcher; // Register AlwaysCombBlockingRule VERILOG_REGISTER_LINT_RULE(AlwaysCombBlockingRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Use only blocking assignments in \'always_comb\' combinational blocks."; const LintRuleDescriptor &AlwaysCombBlockingRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/always-comb-rule.cc b/verible/verilog/analysis/checkers/always-comb-rule.cc index 0771b3818..c169c8ba0 100644 --- a/verible/verilog/analysis/checkers/always-comb-rule.cc +++ b/verible/verilog/analysis/checkers/always-comb-rule.cc @@ -16,9 +16,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -44,7 +44,7 @@ using verible::matcher::Matcher; // Register AlwaysCombRule VERILOG_REGISTER_LINT_RULE(AlwaysCombRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Use 'always_comb' instead of 'always @*'."; const LintRuleDescriptor &AlwaysCombRule::GetDescriptor() { @@ -87,7 +87,7 @@ void AlwaysCombRule::HandleSymbol(const verible::Symbol &symbol, return; } - const absl::string_view fix_message = + const std::string_view fix_message = always_paren ? "Substitute 'always @(*)' for 'always_comb'" : "Substitute 'always @*' for 'always_comb'"; @@ -109,7 +109,7 @@ void AlwaysCombRule::HandleSymbol(const verible::Symbol &symbol, // always_str will cover the 'always @(*)' (or similar), which we'll // substitute for plain 'always_comb' - absl::string_view always_str = + std::string_view always_str = verible::StringSpanOfSymbol(*always_leaf, *event_ctrl); std::vector autofixes{ diff --git a/verible/verilog/analysis/checkers/always-ff-non-blocking-rule.cc b/verible/verilog/analysis/checkers/always-ff-non-blocking-rule.cc index 2d7ef57aa..3b0a4db96 100644 --- a/verible/verilog/analysis/checkers/always-ff-non-blocking-rule.cc +++ b/verible/verilog/analysis/checkers/always-ff-non-blocking-rule.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -49,7 +49,7 @@ using verible::matcher::Matcher; // Register AlwaysFFNonBlockingRule VERILOG_REGISTER_LINT_RULE(AlwaysFFNonBlockingRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Use blocking assignments, at most, for locals inside " "'always_ff' sequential blocks."; @@ -72,7 +72,7 @@ LintRuleStatus AlwaysFFNonBlockingRule::Report() const { //- Configuration ----------------------------------------------------------- absl::Status AlwaysFFNonBlockingRule::Configure( - const absl::string_view configuration) { + const std::string_view configuration) { using verible::config::SetBool; return verible::ParseNameValues( configuration, { @@ -215,7 +215,7 @@ bool AlwaysFFNonBlockingRule::LocalDeclaration(const verible::Symbol &symbol) { if (const auto *const ident = verible::down_cast( node->front().get())) { - const absl::string_view name = ident->get().text(); + const std::string_view name = ident->get().text(); VLOG(4) << "Registering '" << name << '\'' << std::endl; locals_.emplace_back(name); count++; diff --git a/verible/verilog/analysis/checkers/always-ff-non-blocking-rule.h b/verible/verilog/analysis/checkers/always-ff-non-blocking-rule.h index 2693c3725..f2a200818 100644 --- a/verible/verilog/analysis/checkers/always-ff-non-blocking-rule.h +++ b/verible/verilog/analysis/checkers/always-ff-non-blocking-rule.h @@ -18,10 +18,10 @@ #include #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/text/symbol.h" @@ -37,7 +37,7 @@ class AlwaysFFNonBlockingRule : public verible::SyntaxTreeLintRule { static const LintRuleDescriptor &GetDescriptor(); - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; void HandleSymbol(const verible::Symbol &symbol, const verible::SyntaxTreeContext &context) final; @@ -71,7 +71,7 @@ class AlwaysFFNonBlockingRule : public verible::SyntaxTreeLintRule { }; // In-order stack of local variable names - std::vector locals_; + std::vector locals_; }; } // namespace analysis diff --git a/verible/verilog/analysis/checkers/banned-declared-name-patterns-rule.cc b/verible/verilog/analysis/checkers/banned-declared-name-patterns-rule.cc index dadcdf60c..7ed082905 100644 --- a/verible/verilog/analysis/checkers/banned-declared-name-patterns-rule.cc +++ b/verible/verilog/analysis/checkers/banned-declared-name-patterns-rule.cc @@ -15,9 +15,9 @@ #include "verible/verilog/analysis/checkers/banned-declared-name-patterns-rule.h" #include +#include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/symbol.h" #include "verible/common/text/syntax-tree-context.h" @@ -36,7 +36,7 @@ VERILOG_REGISTER_LINT_RULE(BannedDeclaredNamePatternsRule); using verible::LintRuleStatus; using verible::LintViolation; -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Check banned declared name patterns"; const LintRuleDescriptor &BannedDeclaredNamePatternsRule::GetDescriptor() { @@ -58,7 +58,7 @@ void BannedDeclaredNamePatternsRule::HandleNode( case NodeEnum::kModuleDeclaration: { const auto *module_match = GetModuleName(node); if (module_match) { - const absl::string_view module_id = module_match->get().text(); + const std::string_view module_id = module_match->get().text(); if (absl::EqualsIgnoreCase(module_id, "ILLEGALNAME")) { violations_.insert(LintViolation(module_match->get(), kMessage)); @@ -69,7 +69,7 @@ void BannedDeclaredNamePatternsRule::HandleNode( case NodeEnum::kPackageDeclaration: { const verible::TokenInfo *pack_match = GetPackageNameToken(node); if (pack_match) { - absl::string_view pack_id = pack_match->text(); + std::string_view pack_id = pack_match->text(); if (absl::EqualsIgnoreCase(pack_id, "ILLEGALNAME")) { violations_.insert(LintViolation(*pack_match, kMessage)); } diff --git a/verible/verilog/analysis/checkers/case-missing-default-rule.cc b/verible/verilog/analysis/checkers/case-missing-default-rule.cc index 53cc6e37e..c401cd664 100644 --- a/verible/verilog/analysis/checkers/case-missing-default-rule.cc +++ b/verible/verilog/analysis/checkers/case-missing-default-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/case-missing-default-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher-builders.h" @@ -40,7 +40,7 @@ using verible::matcher::Matcher; // Register CaseMissingDefaultRule VERILOG_REGISTER_LINT_RULE(CaseMissingDefaultRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Explicitly define a default case for every case statement or add `unique` " "qualifier to the case statement."; diff --git a/verible/verilog/analysis/checkers/constraint-name-style-rule.cc b/verible/verilog/analysis/checkers/constraint-name-style-rule.cc index 83272570c..c6be316ff 100644 --- a/verible/verilog/analysis/checkers/constraint-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/constraint-name-style-rule.cc @@ -16,10 +16,10 @@ #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" @@ -57,7 +57,7 @@ const LintRuleDescriptor &ConstraintNameStyleRule::GetDescriptor() { } absl::Status ConstraintNameStyleRule::Configure( - absl::string_view configuration) { + std::string_view configuration) { return verible::ParseNameValues( configuration, {{"pattern", verible::config::SetRegex(®ex)}}); } @@ -83,7 +83,7 @@ void ConstraintNameStyleRule::HandleSymbol(const verible::Symbol &symbol, GetSymbolIdentifierFromConstraintDeclaration(symbol); if (!identifier_token) return; - const absl::string_view constraint_name = identifier_token->text(); + const std::string_view constraint_name = identifier_token->text(); if (!RE2::FullMatch(constraint_name, *regex)) { violations_.insert( diff --git a/verible/verilog/analysis/checkers/constraint-name-style-rule.h b/verible/verilog/analysis/checkers/constraint-name-style-rule.h index a049ad21b..6039676db 100644 --- a/verible/verilog/analysis/checkers/constraint-name-style-rule.h +++ b/verible/verilog/analysis/checkers/constraint-name-style-rule.h @@ -18,9 +18,9 @@ #include #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" @@ -45,7 +45,7 @@ class ConstraintNameStyleRule : public verible::SyntaxTreeLintRule { static const LintRuleDescriptor &GetDescriptor(); - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; void HandleSymbol(const verible::Symbol &symbol, const verible::SyntaxTreeContext &context) final; @@ -55,7 +55,7 @@ class ConstraintNameStyleRule : public verible::SyntaxTreeLintRule { private: // Lower snake case, ends with `_c` - static constexpr absl::string_view kSuffix = "([a-z0-9]+_)+c"; + static constexpr std::string_view kSuffix = "([a-z0-9]+_)+c"; std::set violations_; std::unique_ptr regex = std::make_unique(kSuffix); diff --git a/verible/verilog/analysis/checkers/create-object-name-match-rule.cc b/verible/verilog/analysis/checkers/create-object-name-match-rule.cc index 0675f631b..9e5fed951 100644 --- a/verible/verilog/analysis/checkers/create-object-name-match-rule.cc +++ b/verible/verilog/analysis/checkers/create-object-name-match-rule.cc @@ -18,9 +18,9 @@ #include #include #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -85,7 +85,7 @@ static const Matcher &CreateAssignmentMatcher() { // TODO(fangism): This function will be useful to many other analyses. // Make public and refactor. static bool UnqualifiedIdEquals(const SyntaxTreeNode &node, - absl::string_view name) { + std::string_view name) { if (node.MatchesTag(NodeEnum::kUnqualifiedId)) { if (!node.empty()) { // The one-and-only child is the SymbolIdentifier token @@ -123,7 +123,7 @@ static bool QualifiedCallIsTypeIdCreate( // Returns string_view of `text` with outermost double-quotes removed. // If `text` is not wrapped in quotes, return it as-is. -static absl::string_view StripOuterQuotes(absl::string_view text) { +static std::string_view StripOuterQuotes(std::string_view text) { if (!text.empty() && text[0] == '\"') { return text.substr(1, text.length() - 2); } @@ -167,8 +167,8 @@ static const SyntaxTreeNode *GetFirstExpressionFromArgs( } // Returns a diagnostic message for this lint violation. -static std::string FormatReason(absl::string_view decl_name, - absl::string_view name_text) { +static std::string FormatReason(std::string_view decl_name, + std::string_view name_text) { return absl::StrCat( "The \'name\' argument of type_id::create() must match the name of " "the variable to which it is assigned: ", diff --git a/verible/verilog/analysis/checkers/dff-name-style-rule.cc b/verible/verilog/analysis/checkers/dff-name-style-rule.cc index 7c0401280..cbace14a9 100644 --- a/verible/verilog/analysis/checkers/dff-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/dff-name-style-rule.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -31,7 +32,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" @@ -116,7 +116,7 @@ void DffNameStyleRule::HandleBlockingAssignments( driven_variable = GetIncrementDecrementOperand(symbol); } - absl::string_view lhs_str = verible::StringSpanOfSymbol(*driven_variable); + std::string_view lhs_str = verible::StringSpanOfSymbol(*driven_variable); const bool found_id = std::any_of(valid_output_suffixes.cbegin(), valid_output_suffixes.cend(), @@ -145,8 +145,8 @@ void DffNameStyleRule::HandleNonBlockingAssignments( const verible::Symbol &lhs = *GetNonBlockingAssignmentLhs(node); const verible::SyntaxTreeNode &rhs_expr = *GetNonBlockingAssignmentRhs(node); - absl::string_view lhs_str = verible::StringSpanOfSymbol(lhs); - absl::string_view rhs_str = verible::StringSpanOfSymbol(rhs_expr); + std::string_view lhs_str = verible::StringSpanOfSymbol(lhs); + std::string_view rhs_str = verible::StringSpanOfSymbol(rhs_expr); // If this variable matches the waive regex, ignore it. if (waive_lhs_regex && RE2::FullMatch(lhs_str, *waive_lhs_regex)) { @@ -156,7 +156,7 @@ void DffNameStyleRule::HandleNonBlockingAssignments( auto [clean_lhs_str, lhs_pipe_stage] = ExtractPipelineStage(lhs_str); // Check if the string without the pipeline number has a valid format - absl::string_view lhs_base = + std::string_view lhs_base = CheckSuffix(context, lhs, clean_lhs_str, valid_output_suffixes); // If the base is empty, lhs is wrongly formatted. Stop making more checks if (lhs_base.empty()) return; @@ -186,7 +186,7 @@ void DffNameStyleRule::HandleNonBlockingAssignments( return; } - absl::string_view rhs_base = + std::string_view rhs_base = CheckSuffix(context, rhs_expr, rhs_str, valid_input_suffixes); // If the rhs is wrongly formatted, there is no need to check that the @@ -244,7 +244,7 @@ void DffNameStyleRule::HandleSymbol(const verible::Symbol &symbol, const verible::Symbol *s = GetIfHeaderExpression(*if_header); if (!s) return false; - absl::string_view paren_str = + std::string_view paren_str = absl::StripAsciiWhitespace(verible::StringSpanOfSymbol(*s)); // EXACT matching w.r.t waive_ifs_with_conditions. Substring checking @@ -262,12 +262,12 @@ void DffNameStyleRule::HandleSymbol(const verible::Symbol &symbol, HandleNonBlockingAssignments(symbol, context); } -absl::string_view DffNameStyleRule::CheckSuffix( +std::string_view DffNameStyleRule::CheckSuffix( const verible::SyntaxTreeContext &context, const verible::Symbol &root, - absl::string_view id, const std::vector &suffixes) { + std::string_view id, const std::vector &suffixes) { // Identifier is split between base and suffix: // "myid_q" => {"myid", "_q"} - absl::string_view base; + std::string_view base; // If there are no patterns to check against, everything passes the check if (suffixes.empty()) return base; @@ -290,12 +290,12 @@ absl::string_view DffNameStyleRule::CheckSuffix( return base; } - absl::string_view suffix_match; + std::string_view suffix_match; // Check if id conforms to any valid suffix const bool id_ok = std::any_of(suffixes.cbegin(), suffixes.cend(), [&](const std::string &suffix) -> bool { if (absl::EndsWith(id, suffix)) { - base = absl::string_view( + base = std::string_view( id.data(), id.size() - suffix.size()); suffix_match = suffix; return true; @@ -320,7 +320,7 @@ absl::string_view DffNameStyleRule::CheckSuffix( return base; } -absl::Status DffNameStyleRule::Configure(absl::string_view configuration) { +absl::Status DffNameStyleRule::Configure(std::string_view configuration) { // If configuration is empty, stick to the default if (configuration.empty()) return absl::OkStatus(); @@ -356,16 +356,16 @@ absl::Status DffNameStyleRule::Configure(absl::string_view configuration) { } std::vector DffNameStyleRule::ProcessSuffixes( - absl::string_view config) { + std::string_view config) { // Split input string: "q,ff,reg" => {"q", "ff", "reg"} - std::vector split_suffixes = + std::vector split_suffixes = absl::StrSplit(config, ',', absl::SkipEmpty()); std::vector result(split_suffixes.size()); // Prepend an underscore to the suffixes to check against them // {"q", "ff", "reg"} => {"_q", "_ff", "_reg"} - const auto prepend_underscore = [](absl::string_view str) -> std::string { + const auto prepend_underscore = [](std::string_view str) -> std::string { return absl::StrCat("_", str); }; std::transform(split_suffixes.cbegin(), split_suffixes.cend(), result.begin(), @@ -374,10 +374,10 @@ std::vector DffNameStyleRule::ProcessSuffixes( return result; } -std::pair > -DffNameStyleRule::ExtractPipelineStage(absl::string_view id) { +std::pair > +DffNameStyleRule::ExtractPipelineStage(std::string_view id) { // Find the number of trailing digits inside the identifier - absl::string_view::const_reverse_iterator last_non_num = std::find_if( + std::string_view::const_reverse_iterator last_non_num = std::find_if( id.rbegin(), id.rend(), [](unsigned char c) { return !std::isdigit(c); }); uint64_t num_digits = static_cast(std::distance(id.rbegin(), last_non_num)); @@ -387,7 +387,7 @@ DffNameStyleRule::ExtractPipelineStage(absl::string_view id) { if (num_digits == 0 || num_digits == id.size()) return {id, {}}; // Extract the integer value for the pipeline stage - const absl::string_view pipe_stage_str = id.substr(id.size() - num_digits); + const std::string_view pipe_stage_str = id.substr(id.size() - num_digits); uint64_t pipe_stage; if (!absl::SimpleAtoi(pipe_stage_str, &pipe_stage) || pipe_stage < kFirstValidPipeStage) { diff --git a/verible/verilog/analysis/checkers/dff-name-style-rule.h b/verible/verilog/analysis/checkers/dff-name-style-rule.h index 40d7c75ee..b570000af 100644 --- a/verible/verilog/analysis/checkers/dff-name-style-rule.h +++ b/verible/verilog/analysis/checkers/dff-name-style-rule.h @@ -20,12 +20,12 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" @@ -85,10 +85,10 @@ namespace analysis { class DffNameStyleRule : public verible::SyntaxTreeLintRule { public: using rule_type = verible::SyntaxTreeLintRule; - static constexpr absl::string_view kDefaultInputSuffixes = "next,n,d"; - static constexpr absl::string_view kDefaultOutputSuffixes = "reg,r,ff,q"; - static constexpr absl::string_view kDefaultWaiveRegex = "(?i)mem.*"; - static constexpr absl::string_view kDefaultWaiveConditions = + static constexpr std::string_view kDefaultInputSuffixes = "next,n,d"; + static constexpr std::string_view kDefaultOutputSuffixes = "reg,r,ff,q"; + static constexpr std::string_view kDefaultWaiveRegex = "(?i)mem.*"; + static constexpr std::string_view kDefaultWaiveConditions = "!rst_ni,flush_i,!rst_ni || flush_i,flush_i || !rst_ni"; static const LintRuleDescriptor &GetDescriptor(); @@ -98,7 +98,7 @@ class DffNameStyleRule : public verible::SyntaxTreeLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view) final; + absl::Status Configure(std::string_view) final; // Identifiers can optionally include a trailing number // indicating the pipeline stage where the signal originates from. @@ -111,14 +111,13 @@ class DffNameStyleRule : public verible::SyntaxTreeLintRule { // ExtractPipelineStage("data_q1") => {"data_q1", {})} // ExtractPipelineStage("data_q2") => {"data_q", 2)} // https://github.com/lowRISC/style-guides/blob/9b47bff75b19696e23a43f38ee7161112705e1e3/VerilogCodingStyle.md#suffixes-for-signals-and-types - static std::pair> - ExtractPipelineStage(absl::string_view id); + static std::pair> + ExtractPipelineStage(std::string_view id); private: - absl::string_view CheckSuffix(const verible::SyntaxTreeContext &context, - const verible::Symbol &root, - absl::string_view id, - const std::vector &suffixes); + std::string_view CheckSuffix(const verible::SyntaxTreeContext &context, + const verible::Symbol &root, std::string_view id, + const std::vector &suffixes); void HandleBlockingAssignments(const verible::Symbol &symbol, const verible::SyntaxTreeContext &context); @@ -132,7 +131,7 @@ class DffNameStyleRule : public verible::SyntaxTreeLintRule { // "q,ff,reg" => { "q", "ff", "reg" } // // Used to initialize `valid_input_suffixes` and `valid_output_suffixes` - static std::vector ProcessSuffixes(absl::string_view config); + static std::vector ProcessSuffixes(std::string_view config); std::set violations_; diff --git a/verible/verilog/analysis/checkers/dff-name-style-rule_test.cc b/verible/verilog/analysis/checkers/dff-name-style-rule_test.cc index ba45137bf..a7410b959 100644 --- a/verible/verilog/analysis/checkers/dff-name-style-rule_test.cc +++ b/verible/verilog/analysis/checkers/dff-name-style-rule_test.cc @@ -16,11 +16,11 @@ #include #include +#include #include #include #include "absl/log/check.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/syntax-tree-linter-test-utils.h" @@ -215,8 +215,8 @@ TEST(DffNameStyleRuleTest, Reject) { TEST(DffNameStyleRuleTest, ExtractPipelineStage) { struct Test { - absl::string_view str; - std::pair> expected; + std::string_view str; + std::pair> expected; }; const std::vector kTestCases = { {"data_q0", {"data_q0", {}}}, {"data_q1", {"data_q", {1}}}, diff --git a/verible/verilog/analysis/checkers/disable-statement-rule.cc b/verible/verilog/analysis/checkers/disable-statement-rule.cc index 7ce06812b..d817a784c 100644 --- a/verible/verilog/analysis/checkers/disable-statement-rule.cc +++ b/verible/verilog/analysis/checkers/disable-statement-rule.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -41,10 +41,10 @@ using verible::matcher::Matcher; VERILOG_REGISTER_LINT_RULE(DisableStatementNoLabelsRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Invalid usage of disable statement. Preferred construction is: disable " "fork;"; -static constexpr absl::string_view kMessageSeqBlock = +static constexpr std::string_view kMessageSeqBlock = "Invalid usage of disable statement. Preferred construction is: disable " "label_of_seq_block;"; @@ -72,7 +72,7 @@ void DisableStatementNoLabelsRule::HandleSymbol( if (!DisableMatcher().Matches(symbol, &manager)) { return; } - absl::string_view message_final = kMessage; + std::string_view message_final = kMessage; // if no kDisable label, return, nothing to be checked const auto &disableLabels = FindAllSymbolIdentifierLeafs(symbol); if (disableLabels.empty()) { diff --git a/verible/verilog/analysis/checkers/endif-comment-rule.cc b/verible/verilog/analysis/checkers/endif-comment-rule.cc index 2fd02ce70..70beef218 100644 --- a/verible/verilog/analysis/checkers/endif-comment-rule.cc +++ b/verible/verilog/analysis/checkers/endif-comment-rule.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/token-stream-lint-rule.h" #include "verible/common/strings/comment-utils.h" @@ -40,7 +40,7 @@ using verible::TokenStreamLintRule; // Register the lint rule VERILOG_REGISTER_LINT_RULE(EndifCommentRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "`endif should be followed on the same line by a comment that matches the " "opening `ifdef/`ifndef."; @@ -95,7 +95,7 @@ void EndifCommentRule::HandleToken(const TokenInfo &token) { if (conditional_scopes_.empty()) break; // unbalanced // Checking for comment immediately following `endif. // Matching comment must be on the same line as the `endif - const absl::string_view expect = conditional_scopes_.top().text(); + const std::string_view expect = conditional_scopes_.top().text(); switch (token.token_enum()) { case TK_SPACE: // stay in the same state break; @@ -103,7 +103,7 @@ void EndifCommentRule::HandleToken(const TokenInfo &token) { case TK_EOL_COMMENT: { // check comment text, unwrap comment, unpad whitespace. // allow either // COND or /* COND */ - const absl::string_view contents = + const std::string_view contents = verible::StripCommentAndSpacePadding(token.text()); if (contents != expect) { violations_.insert(LintViolation( diff --git a/verible/verilog/analysis/checkers/enum-name-style-rule.cc b/verible/verilog/analysis/checkers/enum-name-style-rule.cc index 6a3df72a6..13c878c79 100644 --- a/verible/verilog/analysis/checkers/enum-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/enum-name-style-rule.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" @@ -44,7 +44,7 @@ using verible::LintViolation; using verible::SyntaxTreeContext; using verible::matcher::Matcher; -static constexpr absl::string_view kDefaultStyleRegex = "[a-z_0-9]+(_t|_e)"; +static constexpr std::string_view kDefaultStyleRegex = "[a-z_0-9]+(_t|_e)"; EnumNameStyleRule::EnumNameStyleRule() : style_regex_( @@ -97,7 +97,7 @@ void EnumNameStyleRule::HandleSymbol(const verible::Symbol &symbol, } } -absl::Status EnumNameStyleRule::Configure(absl::string_view configuration) { +absl::Status EnumNameStyleRule::Configure(std::string_view configuration) { using verible::config::SetRegex; absl::Status s = verible::ParseNameValues( configuration, {{"style_regex", SetRegex(&style_regex_)}}); diff --git a/verible/verilog/analysis/checkers/enum-name-style-rule.h b/verible/verilog/analysis/checkers/enum-name-style-rule.h index 258159383..d05e65f5a 100644 --- a/verible/verilog/analysis/checkers/enum-name-style-rule.h +++ b/verible/verilog/analysis/checkers/enum-name-style-rule.h @@ -18,9 +18,9 @@ #include #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" @@ -48,7 +48,7 @@ class EnumNameStyleRule : public verible::SyntaxTreeLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; private: std::set violations_; diff --git a/verible/verilog/analysis/checkers/explicit-begin-rule.cc b/verible/verilog/analysis/checkers/explicit-begin-rule.cc index 57637ed66..af303748f 100644 --- a/verible/verilog/analysis/checkers/explicit-begin-rule.cc +++ b/verible/verilog/analysis/checkers/explicit-begin-rule.cc @@ -15,11 +15,11 @@ #include "verible/verilog/analysis/checkers/explicit-begin-rule.h" #include +#include #include "absl/base/attributes.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/token-stream-lint-rule.h" #include "verible/common/text/config-utils.h" @@ -81,7 +81,7 @@ const LintRuleDescriptor &ExplicitBeginRule::GetDescriptor() { return d; } -absl::Status ExplicitBeginRule::Configure(absl::string_view configuration) { +absl::Status ExplicitBeginRule::Configure(std::string_view configuration) { using verible::config::SetBool; return verible::ParseNameValues( configuration, diff --git a/verible/verilog/analysis/checkers/explicit-begin-rule.h b/verible/verilog/analysis/checkers/explicit-begin-rule.h index cd034854d..07bc6403d 100644 --- a/verible/verilog/analysis/checkers/explicit-begin-rule.h +++ b/verible/verilog/analysis/checkers/explicit-begin-rule.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_EXPLICIT_BEGIN_RULE_H_ #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/token-stream-lint-rule.h" #include "verible/common/text/token-info.h" @@ -37,7 +37,7 @@ class ExplicitBeginRule : public verible::TokenStreamLintRule { static const LintRuleDescriptor &GetDescriptor(); - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; void HandleToken(const verible::TokenInfo &token) final; diff --git a/verible/verilog/analysis/checkers/explicit-function-lifetime-rule.cc b/verible/verilog/analysis/checkers/explicit-function-lifetime-rule.cc index 676362fb4..581836387 100644 --- a/verible/verilog/analysis/checkers/explicit-function-lifetime-rule.cc +++ b/verible/verilog/analysis/checkers/explicit-function-lifetime-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/explicit-function-lifetime-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -44,7 +44,7 @@ using Matcher = verible::matcher::Matcher; // Register ExplicitFunctionLifetimeRule VERILOG_REGISTER_LINT_RULE(ExplicitFunctionLifetimeRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Explicitly define static or automatic lifetime for non-class functions"; const LintRuleDescriptor &ExplicitFunctionLifetimeRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/explicit-function-task-parameter-type-rule.cc b/verible/verilog/analysis/checkers/explicit-function-task-parameter-type-rule.cc index 261ce843f..b35400dae 100644 --- a/verible/verilog/analysis/checkers/explicit-function-task-parameter-type-rule.cc +++ b/verible/verilog/analysis/checkers/explicit-function-task-parameter-type-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/explicit-function-task-parameter-type-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -40,7 +40,7 @@ using Matcher = verible::matcher::Matcher; // Register ExplicitFunctionTaskParameterTypeRule VERILOG_REGISTER_LINT_RULE(ExplicitFunctionTaskParameterTypeRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Explicitly define a storage type for every function parameter."; const LintRuleDescriptor & diff --git a/verible/verilog/analysis/checkers/explicit-parameter-storage-type-rule.cc b/verible/verilog/analysis/checkers/explicit-parameter-storage-type-rule.cc index 6901a9011..04911f1b7 100644 --- a/verible/verilog/analysis/checkers/explicit-parameter-storage-type-rule.cc +++ b/verible/verilog/analysis/checkers/explicit-parameter-storage-type-rule.cc @@ -16,11 +16,11 @@ #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -47,7 +47,7 @@ using Matcher = verible::matcher::Matcher; // Register ExplicitParameterStorageTypeRule VERILOG_REGISTER_LINT_RULE(ExplicitParameterStorageTypeRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Explicitly define a storage type for every parameter and localparam, "; const LintRuleDescriptor &ExplicitParameterStorageTypeRule::GetDescriptor() { @@ -99,8 +99,8 @@ void ExplicitParameterStorageTypeRule::HandleSymbol( // The only allowed exemption right now is 'string', as this is // a common type that can't be handled well in some old tools. absl::Status ExplicitParameterStorageTypeRule::Configure( - absl::string_view configuration) { - static const std::vector allowed = {"", "string"}; + std::string_view configuration) { + static const std::vector allowed = {"", "string"}; using verible::config::SetStringOneOf; std::string value; auto s = verible::ParseNameValues( diff --git a/verible/verilog/analysis/checkers/explicit-parameter-storage-type-rule.h b/verible/verilog/analysis/checkers/explicit-parameter-storage-type-rule.h index 9d513f611..492782e12 100644 --- a/verible/verilog/analysis/checkers/explicit-parameter-storage-type-rule.h +++ b/verible/verilog/analysis/checkers/explicit-parameter-storage-type-rule.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_EXPLICIT_PARAMETER_STORAGE_TYPE_RULE_H_ #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/text/symbol.h" @@ -41,7 +41,7 @@ class ExplicitParameterStorageTypeRule : public verible::SyntaxTreeLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; private: // TODO(hzeller): would other exempt types be interesting? diff --git a/verible/verilog/analysis/checkers/explicit-task-lifetime-rule.cc b/verible/verilog/analysis/checkers/explicit-task-lifetime-rule.cc index d771c8dbc..c958f6437 100644 --- a/verible/verilog/analysis/checkers/explicit-task-lifetime-rule.cc +++ b/verible/verilog/analysis/checkers/explicit-task-lifetime-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/explicit-task-lifetime-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -43,7 +43,7 @@ using Matcher = verible::matcher::Matcher; // Register ExplicitTaskLifetimeRule VERILOG_REGISTER_LINT_RULE(ExplicitTaskLifetimeRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Explicitly define static or automatic lifetime for non-class tasks"; const LintRuleDescriptor &ExplicitTaskLifetimeRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/forbid-consecutive-null-statements-rule.cc b/verible/verilog/analysis/checkers/forbid-consecutive-null-statements-rule.cc index 41032ad76..5133ba1e3 100644 --- a/verible/verilog/analysis/checkers/forbid-consecutive-null-statements-rule.cc +++ b/verible/verilog/analysis/checkers/forbid-consecutive-null-statements-rule.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/symbol.h" @@ -37,7 +37,7 @@ using verible::SyntaxTreeContext; // Register ForbidConsecutiveNullStatementsRule VERILOG_REGISTER_LINT_RULE(ForbidConsecutiveNullStatementsRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Do not use consecutive null statements like \';;\'."; const LintRuleDescriptor &ForbidConsecutiveNullStatementsRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/forbid-defparam-rule.cc b/verible/verilog/analysis/checkers/forbid-defparam-rule.cc index 9e5f96f95..3cca4cd0a 100644 --- a/verible/verilog/analysis/checkers/forbid-defparam-rule.cc +++ b/verible/verilog/analysis/checkers/forbid-defparam-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/forbid-defparam-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -39,7 +39,7 @@ using verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(ForbidDefparamRule); -static constexpr absl::string_view kMessage = "Do not use defparam."; +static constexpr std::string_view kMessage = "Do not use defparam."; const LintRuleDescriptor &ForbidDefparamRule::GetDescriptor() { static const LintRuleDescriptor d{ diff --git a/verible/verilog/analysis/checkers/forbid-line-continuations-rule.cc b/verible/verilog/analysis/checkers/forbid-line-continuations-rule.cc index 1b5fea762..33835765f 100644 --- a/verible/verilog/analysis/checkers/forbid-line-continuations-rule.cc +++ b/verible/verilog/analysis/checkers/forbid-line-continuations-rule.cc @@ -16,9 +16,9 @@ #include #include +#include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -41,7 +41,7 @@ using verible::matcher::Matcher; // Register ForbidLineContinuationsRule VERILOG_REGISTER_LINT_RULE(ForbidLineContinuationsRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "The lines can't be continued with \'\\\', use concatenation operator with " "braces"; diff --git a/verible/verilog/analysis/checkers/forbid-negative-array-dim.cc b/verible/verilog/analysis/checkers/forbid-negative-array-dim.cc index 94280347b..ba68105fe 100644 --- a/verible/verilog/analysis/checkers/forbid-negative-array-dim.cc +++ b/verible/verilog/analysis/checkers/forbid-negative-array-dim.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/forbid-negative-array-dim.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -39,7 +39,7 @@ using verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(ForbidNegativeArrayDim); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Avoid using negative constant literals for array dimensions."; const LintRuleDescriptor &ForbidNegativeArrayDim::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/forbidden-anonymous-enums-rule.cc b/verible/verilog/analysis/checkers/forbidden-anonymous-enums-rule.cc index ed0004c20..f7b2189c1 100644 --- a/verible/verilog/analysis/checkers/forbidden-anonymous-enums-rule.cc +++ b/verible/verilog/analysis/checkers/forbidden-anonymous-enums-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/forbidden-anonymous-enums-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -37,7 +37,7 @@ using Matcher = verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(ForbiddenAnonymousEnumsRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "enum types always should be named using typedef."; const LintRuleDescriptor &ForbiddenAnonymousEnumsRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.cc b/verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.cc index 8dd9e1692..5fa0ac683 100644 --- a/verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.cc +++ b/verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.cc @@ -15,9 +15,9 @@ #include "verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.h" #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -39,9 +39,9 @@ using verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(ForbiddenAnonymousStructsUnionsRule); -static constexpr absl::string_view kMessageStruct = +static constexpr std::string_view kMessageStruct = "struct definitions always should be named using typedef."; -static constexpr absl::string_view kMessageUnion = +static constexpr std::string_view kMessageUnion = "union definitions always should be named using typedef."; const LintRuleDescriptor &ForbiddenAnonymousStructsUnionsRule::GetDescriptor() { @@ -58,7 +58,7 @@ const LintRuleDescriptor &ForbiddenAnonymousStructsUnionsRule::GetDescriptor() { } absl::Status ForbiddenAnonymousStructsUnionsRule::Configure( - absl::string_view configuration) { + std::string_view configuration) { using verible::config::SetBool; return verible::ParseNameValues( configuration, diff --git a/verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.h b/verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.h index 75ec2479a..466137088 100644 --- a/verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.h +++ b/verible/verilog/analysis/checkers/forbidden-anonymous-structs-unions-rule.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_FORBIDDEN_ANONYMOUS_STRUCTS_UNIONS_RULE_H_ // NOLINT #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/text/symbol.h" @@ -58,7 +58,7 @@ class ForbiddenAnonymousStructsUnionsRule : public verible::SyntaxTreeLintRule { static const LintRuleDescriptor &GetDescriptor(); - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; void HandleSymbol(const verible::Symbol &symbol, const verible::SyntaxTreeContext &context) final; diff --git a/verible/verilog/analysis/checkers/forbidden-macro-rule.cc b/verible/verilog/analysis/checkers/forbidden-macro-rule.cc index e252e2b32..ff95b46f9 100644 --- a/verible/verilog/analysis/checkers/forbidden-macro-rule.cc +++ b/verible/verilog/analysis/checkers/forbidden-macro-rule.cc @@ -17,8 +17,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/citation.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" diff --git a/verible/verilog/analysis/checkers/generate-label-prefix-rule.cc b/verible/verilog/analysis/checkers/generate-label-prefix-rule.cc index f442ebf90..c8822ce56 100644 --- a/verible/verilog/analysis/checkers/generate-label-prefix-rule.cc +++ b/verible/verilog/analysis/checkers/generate-label-prefix-rule.cc @@ -14,8 +14,9 @@ #include "verible/verilog/analysis/checkers/generate-label-prefix-rule.h" +#include + #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -37,7 +38,7 @@ using verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(GenerateLabelPrefixRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "All generate block labels must start with g_ or gen_"; // TODO(fangism): and be lower_snake_case? diff --git a/verible/verilog/analysis/checkers/generate-label-rule.cc b/verible/verilog/analysis/checkers/generate-label-rule.cc index d16a51467..514de1c0e 100644 --- a/verible/verilog/analysis/checkers/generate-label-rule.cc +++ b/verible/verilog/analysis/checkers/generate-label-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/generate-label-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/core-matchers.h" @@ -35,7 +35,7 @@ using verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(GenerateLabelRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "All generate block statements must have a label"; const LintRuleDescriptor &GenerateLabelRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/instance-shadow-rule.cc b/verible/verilog/analysis/checkers/instance-shadow-rule.cc index 0229bb1e4..f66ad398d 100644 --- a/verible/verilog/analysis/checkers/instance-shadow-rule.cc +++ b/verible/verilog/analysis/checkers/instance-shadow-rule.cc @@ -17,8 +17,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/citation.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" @@ -46,7 +46,7 @@ using verible::matcher::Matcher; // Register InstanceShadowRule VERILOG_REGISTER_LINT_RULE(InstanceShadowRule); -absl::string_view InstanceShadowRule::Name() { return "instance-shadowing"; } +std::string_view InstanceShadowRule::Name() { return "instance-shadowing"; } const char InstanceShadowRule::kTopic[] = "mark-shadowed-instances"; const char InstanceShadowRule::kMessage[] = "Instance shadows the already declared variable"; diff --git a/verible/verilog/analysis/checkers/instance-shadow-rule.h b/verible/verilog/analysis/checkers/instance-shadow-rule.h index 81d289368..556be8272 100644 --- a/verible/verilog/analysis/checkers/instance-shadow-rule.h +++ b/verible/verilog/analysis/checkers/instance-shadow-rule.h @@ -16,8 +16,8 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_INSTANCE_SHADOW_RULE_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/text/symbol.h" @@ -32,7 +32,7 @@ namespace analysis { class InstanceShadowRule : public verible::SyntaxTreeLintRule { public: using rule_type = verible::SyntaxTreeLintRule; - static absl::string_view Name(); + static std::string_view Name(); // Returns the description of the rule implemented formatted for either the // helper flag or markdown depending on the parameter type. diff --git a/verible/verilog/analysis/checkers/instance-shadow-rule_test.cc b/verible/verilog/analysis/checkers/instance-shadow-rule_test.cc index 7f9df1e35..e00710412 100644 --- a/verible/verilog/analysis/checkers/instance-shadow-rule_test.cc +++ b/verible/verilog/analysis/checkers/instance-shadow-rule_test.cc @@ -16,9 +16,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/syntax-tree-linter-test-utils.h" @@ -179,9 +179,9 @@ TEST(InstanceShadowingTest, CorrectLocationTest) { CHECK_EQ(linter_.ReportStatus()[0].violations.size(), 1); // Report detailed differences, if any. - const absl::string_view base_text = analyzer.Data().Contents(); - absl::string_view foo = test.FindImportantTokens(base_text)[0].text(); - absl::string_view bar = + const std::string_view base_text = analyzer.Data().Contents(); + std::string_view foo = test.FindImportantTokens(base_text)[0].text(); + std::string_view bar = linter_.ReportStatus()[0].violations.begin()->token.text(); ASSERT_TRUE(foo == bar); } diff --git a/verible/verilog/analysis/checkers/interface-name-style-rule.cc b/verible/verilog/analysis/checkers/interface-name-style-rule.cc index c0985fcb7..434653dbf 100644 --- a/verible/verilog/analysis/checkers/interface-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/interface-name-style-rule.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" @@ -45,9 +45,9 @@ using verible::LintViolation; using verible::SyntaxTreeContext; using verible::matcher::Matcher; -static constexpr absl::string_view kLowerSnakeCaseWithSuffixRegex = +static constexpr std::string_view kLowerSnakeCaseWithSuffixRegex = "[a-z_0-9]+(_if)"; -static constexpr absl::string_view kDefaultStyleRegex = +static constexpr std::string_view kDefaultStyleRegex = kLowerSnakeCaseWithSuffixRegex; InterfaceNameStyleRule::InterfaceNameStyleRule() @@ -82,7 +82,7 @@ std::string InterfaceNameStyleRule::CreateViolationMessage() { void InterfaceNameStyleRule::HandleSymbol(const verible::Symbol &symbol, const SyntaxTreeContext &context) { verible::matcher::BoundSymbolManager manager; - absl::string_view name; + std::string_view name; const verible::TokenInfo *identifier_token; if (InterfaceMatcher().Matches(symbol, &manager)) { identifier_token = GetInterfaceNameToken(symbol); @@ -95,8 +95,7 @@ void InterfaceNameStyleRule::HandleSymbol(const verible::Symbol &symbol, } } -absl::Status InterfaceNameStyleRule::Configure( - absl::string_view configuration) { +absl::Status InterfaceNameStyleRule::Configure(std::string_view configuration) { using verible::config::SetRegex; absl::Status s = verible::ParseNameValues( configuration, {{"style_regex", SetRegex(&style_regex_)}}); diff --git a/verible/verilog/analysis/checkers/interface-name-style-rule.h b/verible/verilog/analysis/checkers/interface-name-style-rule.h index 517ab28ee..baaca7f77 100644 --- a/verible/verilog/analysis/checkers/interface-name-style-rule.h +++ b/verible/verilog/analysis/checkers/interface-name-style-rule.h @@ -18,9 +18,9 @@ #include #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" @@ -48,7 +48,7 @@ class InterfaceNameStyleRule : public verible::SyntaxTreeLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; private: std::set violations_; diff --git a/verible/verilog/analysis/checkers/legacy-generate-region-rule.cc b/verible/verilog/analysis/checkers/legacy-generate-region-rule.cc index e311d6681..9f862c1e0 100644 --- a/verible/verilog/analysis/checkers/legacy-generate-region-rule.cc +++ b/verible/verilog/analysis/checkers/legacy-generate-region-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/legacy-generate-region-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/matcher-builders.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -39,7 +39,7 @@ using verible::LintRuleStatus; using verible::LintViolation; using verible::matcher::EqualTagPredicate; -static constexpr absl::string_view kMessage = "Do not use generate regions."; +static constexpr std::string_view kMessage = "Do not use generate regions."; const LintRuleDescriptor &LegacyGenerateRegionRule::GetDescriptor() { static const LintRuleDescriptor d{ diff --git a/verible/verilog/analysis/checkers/legacy-genvar-declaration-rule.cc b/verible/verilog/analysis/checkers/legacy-genvar-declaration-rule.cc index ba48a6f5b..45ec4a609 100644 --- a/verible/verilog/analysis/checkers/legacy-genvar-declaration-rule.cc +++ b/verible/verilog/analysis/checkers/legacy-genvar-declaration-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/legacy-genvar-declaration-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/symbol.h" @@ -35,7 +35,7 @@ VERILOG_REGISTER_LINT_RULE(LegacyGenvarDeclarationRule); using verible::LintRuleStatus; using verible::LintViolation; -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Do not use separate genvar declaration."; const LintRuleDescriptor &LegacyGenvarDeclarationRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/line-length-rule.cc b/verible/verilog/analysis/checkers/line-length-rule.cc index 96b735b54..1bbeb3597 100644 --- a/verible/verilog/analysis/checkers/line-length-rule.cc +++ b/verible/verilog/analysis/checkers/line-length-rule.cc @@ -17,11 +17,11 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/strings/comment-utils.h" #include "verible/common/strings/utf8.h" @@ -49,10 +49,10 @@ using verible::TokenSequence; // Register the lint rule VERILOG_REGISTER_LINT_RULE(LineLengthRule); -static constexpr absl::string_view kMessage = "Line length exceeds max: "; +static constexpr std::string_view kMessage = "Line length exceeds max: "; #if 0 // See comment below about comment-reflowing being implemented -static bool ContainsAnyWhitespace(absl::string_view s) { +static bool ContainsAnyWhitespace(std::string_view s) { for (char c : s) { if (absl::ascii_isspace(c)) return true; } @@ -112,7 +112,7 @@ static bool AllowLongLineException(TokenSequence::const_iterator token_begin, // Once comment-reflowing is implemented, re-enable the following: // If comment consist of more than one token, it should be split. - // const absl::string_view comment_contents = + // const std::string_view comment_contents = // verible::StripCommentAndSpacePadding(token_begin->text); // return !ContainsAnyWhitespace(comment_contents); } @@ -145,7 +145,7 @@ static bool AllowLongLineException(TokenSequence::const_iterator token_begin, if (IsComment(verilog_tokentype(last_token->token_enum()))) { // Check for end-of-line comment that contain lint waivers. - const absl::string_view text = + const std::string_view text = verible::StripCommentAndSpacePadding(last_token->text()); if (absl::StartsWith(text, "ri lint_check_waive")) { // TODO(fangism): Could make this pattern more space-insensitive @@ -163,7 +163,7 @@ static bool AllowLongLineException(TokenSequence::const_iterator token_begin, } void LineLengthRule::Lint(const TextStructureView &text_structure, - absl::string_view) { + std::string_view) { size_t lineno = 0; for (const auto &line : text_structure.Lines()) { const int observed_line_length = verible::utf8_len(line); @@ -183,7 +183,7 @@ void LineLengthRule::Lint(const TextStructureView &text_structure, } } -absl::Status LineLengthRule::Configure(absl::string_view configuration) { +absl::Status LineLengthRule::Configure(std::string_view configuration) { using verible::config::SetInt; return verible::ParseNameValues( configuration, {{"length", SetInt(&line_length_limit_, kMinimumLineLength, diff --git a/verible/verilog/analysis/checkers/line-length-rule.h b/verible/verilog/analysis/checkers/line-length-rule.h index 38d4796a3..9ce8937e5 100644 --- a/verible/verilog/analysis/checkers/line-length-rule.h +++ b/verible/verilog/analysis/checkers/line-length-rule.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_LINE_LENGTH_RULE_H_ #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/text-structure-lint-rule.h" #include "verible/common/text/text-structure.h" @@ -46,9 +46,9 @@ class LineLengthRule : public verible::TextStructureLintRule { LineLengthRule() = default; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; - void Lint(const verible::TextStructureView &, absl::string_view) final; + void Lint(const verible::TextStructureView &, std::string_view) final; verible::LintRuleStatus Report() const final; diff --git a/verible/verilog/analysis/checkers/macro-name-style-rule.cc b/verible/verilog/analysis/checkers/macro-name-style-rule.cc index 3ff7ddbce..370d1bd8c 100644 --- a/verible/verilog/analysis/checkers/macro-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/macro-name-style-rule.cc @@ -17,11 +17,11 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/config-utils.h" @@ -41,14 +41,14 @@ using verible::LintRuleStatus; using verible::LintViolation; using verible::TokenInfo; -static constexpr absl::string_view kUVMLowerCaseMessage = +static constexpr std::string_view kUVMLowerCaseMessage = "'uvm_*' named macros must follow 'lower_snake_case' format."; -static constexpr absl::string_view kUVMUpperCaseMessage = +static constexpr std::string_view kUVMUpperCaseMessage = "'UVM_*' named macros must follow 'UPPER_SNAKE_CASE' format."; -static constexpr absl::string_view kLowerSnakeCaseRegex = "[a-z_0-9]+"; -static constexpr absl::string_view kUpperSnakeCaseRegex = "[A-Z_0-9]+"; +static constexpr std::string_view kLowerSnakeCaseRegex = "[a-z_0-9]+"; +static constexpr std::string_view kUpperSnakeCaseRegex = "[A-Z_0-9]+"; MacroNameStyleRule::MacroNameStyleRule() : style_regex_( @@ -83,7 +83,7 @@ std::string MacroNameStyleRule::CreateViolationMessage() { void MacroNameStyleRule::HandleToken(const TokenInfo &token) { const auto token_enum = static_cast(token.token_enum()); - const absl::string_view text(token.text()); + const std::string_view text(token.text()); if (IsUnlexed(verilog_tokentype(token.token_enum()))) { // recursively lex to examine inside macro definition bodies, etc. RecursiveLexText( @@ -136,7 +136,7 @@ void MacroNameStyleRule::HandleToken(const TokenInfo &token) { } // switch (state_) } -absl::Status MacroNameStyleRule::Configure(absl::string_view configuration) { +absl::Status MacroNameStyleRule::Configure(std::string_view configuration) { using verible::config::SetRegex; absl::Status s = verible::ParseNameValues( configuration, {{"style_regex", SetRegex(&style_regex_)}}); diff --git a/verible/verilog/analysis/checkers/macro-name-style-rule.h b/verible/verilog/analysis/checkers/macro-name-style-rule.h index 33e3724ba..9a767ba03 100644 --- a/verible/verilog/analysis/checkers/macro-name-style-rule.h +++ b/verible/verilog/analysis/checkers/macro-name-style-rule.h @@ -18,9 +18,9 @@ #include #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/token-stream-lint-rule.h" @@ -47,7 +47,7 @@ class MacroNameStyleRule : public verible::TokenStreamLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; private: // States of the internal token-based analysis. diff --git a/verible/verilog/analysis/checkers/macro-string-concatenation-rule.cc b/verible/verilog/analysis/checkers/macro-string-concatenation-rule.cc index e773fc1b3..d38f7b4d8 100644 --- a/verible/verilog/analysis/checkers/macro-string-concatenation-rule.cc +++ b/verible/verilog/analysis/checkers/macro-string-concatenation-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/macro-string-concatenation-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/token-info.h" #include "verible/common/util/value-saver.h" @@ -36,7 +36,7 @@ using verible::TokenInfo; // Register the lint rule VERILOG_REGISTER_LINT_RULE(MacroStringConcatenationRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Token concatenation (``) used inside plain string literal."; const LintRuleDescriptor &MacroStringConcatenationRule::GetDescriptor() { @@ -51,7 +51,7 @@ const LintRuleDescriptor &MacroStringConcatenationRule::GetDescriptor() { void MacroStringConcatenationRule::HandleToken(const TokenInfo &token) { const auto token_enum = static_cast(token.token_enum()); - const absl::string_view text(token.text()); + const std::string_view text(token.text()); // Search only in `define tokens. Ignore state as `defines can be nested. if (token_enum == PP_define_body) { @@ -63,7 +63,7 @@ void MacroStringConcatenationRule::HandleToken(const TokenInfo &token) { } else if (state_ == State::kInsideDefineBody && token_enum == TK_StringLiteral) { size_t pos = 0; - while ((pos = text.find("``", pos)) != absl::string_view::npos) { + while ((pos = text.find("``", pos)) != std::string_view::npos) { violations_.insert( LintViolation(TokenInfo(token_enum, text.substr(pos, 2)), kMessage)); pos += 2; diff --git a/verible/verilog/analysis/checkers/mismatched-labels-rule.cc b/verible/verilog/analysis/checkers/mismatched-labels-rule.cc index 6a553705f..a36db8c25 100644 --- a/verible/verilog/analysis/checkers/mismatched-labels-rule.cc +++ b/verible/verilog/analysis/checkers/mismatched-labels-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/mismatched-labels-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -36,9 +36,9 @@ using verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(MismatchedLabelsRule); -static constexpr absl::string_view kMessageMismatch = +static constexpr std::string_view kMessageMismatch = "Begin/end block labels must match."; -static constexpr absl::string_view kMessageMissing = +static constexpr std::string_view kMessageMissing = "Matching begin label is missing."; const LintRuleDescriptor &MismatchedLabelsRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/module-begin-block-rule.cc b/verible/verilog/analysis/checkers/module-begin-block-rule.cc index b80d8c955..8b47fea2a 100644 --- a/verible/verilog/analysis/checkers/module-begin-block-rule.cc +++ b/verible/verilog/analysis/checkers/module-begin-block-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/module-begin-block-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -34,7 +34,7 @@ using verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(ModuleBeginBlockRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Module-level begin-end blocks are not LRM-valid syntax."; const LintRuleDescriptor &ModuleBeginBlockRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/module-filename-rule.cc b/verible/verilog/analysis/checkers/module-filename-rule.cc index 9ff7124da..99aea260a 100644 --- a/verible/verilog/analysis/checkers/module-filename-rule.cc +++ b/verible/verilog/analysis/checkers/module-filename-rule.cc @@ -19,12 +19,12 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/text/concrete-syntax-leaf.h" @@ -48,7 +48,7 @@ using verible::TextStructureView; // Register the lint rule VERILOG_REGISTER_LINT_RULE(ModuleFilenameRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Declared module does not match the first dot-delimited component " "of file name: "; @@ -68,14 +68,13 @@ const LintRuleDescriptor &ModuleFilenameRule::GetDescriptor() { return d; } -static bool ModuleNameMatches(const verible::Symbol &s, - absl::string_view name) { +static bool ModuleNameMatches(const verible::Symbol &s, std::string_view name) { const auto *module_leaf = GetModuleName(s); return module_leaf && module_leaf->get().text() == name; } void ModuleFilenameRule::Lint(const TextStructureView &text_structure, - absl::string_view filename) { + std::string_view filename) { if (verible::file::IsStdin(filename)) { return; } @@ -100,9 +99,9 @@ void ModuleFilenameRule::Lint(const TextStructureView &text_structure, }); // See if any names match the stem of the filename. - const absl::string_view basename = verible::file::Basename(filename); + const std::string_view basename = verible::file::Basename(filename); - std::vector basename_components = + std::vector basename_components = absl::StrSplit(basename, '.'); std::string unitname(basename_components[0].begin(), basename_components[0].end()); @@ -150,7 +149,7 @@ LintRuleStatus ModuleFilenameRule::Report() const { return LintRuleStatus(violations_, GetDescriptor()); } -absl::Status ModuleFilenameRule::Configure(absl::string_view configuration) { +absl::Status ModuleFilenameRule::Configure(std::string_view configuration) { using verible::config::SetBool; return verible::ParseNameValues( configuration, diff --git a/verible/verilog/analysis/checkers/module-filename-rule.h b/verible/verilog/analysis/checkers/module-filename-rule.h index 46ee6d953..e552ea479 100644 --- a/verible/verilog/analysis/checkers/module-filename-rule.h +++ b/verible/verilog/analysis/checkers/module-filename-rule.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_MODULE_FILENAME_RULE_H_ #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/text-structure-lint-rule.h" #include "verible/common/text/text-structure.h" @@ -36,8 +36,8 @@ class ModuleFilenameRule : public verible::TextStructureLintRule { ModuleFilenameRule() = default; - absl::Status Configure(absl::string_view configuration) final; - void Lint(const verible::TextStructureView &, absl::string_view) final; + absl::Status Configure(std::string_view configuration) final; + void Lint(const verible::TextStructureView &, std::string_view) final; verible::LintRuleStatus Report() const final; diff --git a/verible/verilog/analysis/checkers/module-filename-rule_test.cc b/verible/verilog/analysis/checkers/module-filename-rule_test.cc index 0b8ed74e0..51165b506 100644 --- a/verible/verilog/analysis/checkers/module-filename-rule_test.cc +++ b/verible/verilog/analysis/checkers/module-filename-rule_test.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/text-structure-linter-test-utils.h" @@ -71,7 +71,7 @@ TEST(ModuleFilenameRuleTest, DashAllowedWhenConfigured) { const std::string f_with_dash = "/path/to/multi-word-module.sv"; { // With dashes not allowed, we only accept the underscore name - constexpr absl::string_view config = "allow-dash-for-underscore:off"; + constexpr std::string_view config = "allow-dash-for-underscore:off"; RunConfiguredLintTestCases( kOkCases, config, f_with_underscore); RunConfiguredLintTestCases( @@ -80,7 +80,7 @@ TEST(ModuleFilenameRuleTest, DashAllowedWhenConfigured) { { // ... But with dashes allowed, dashes are also an ok case. - constexpr absl::string_view config = "allow-dash-for-underscore:on"; + constexpr std::string_view config = "allow-dash-for-underscore:on"; // With dashes not allowed, we only accept the underscore name RunConfiguredLintTestCases( kOkCases, config, f_with_underscore); diff --git a/verible/verilog/analysis/checkers/module-instantiation-rules.cc b/verible/verilog/analysis/checkers/module-instantiation-rules.cc index 847173628..1639ef222 100644 --- a/verible/verilog/analysis/checkers/module-instantiation-rules.cc +++ b/verible/verilog/analysis/checkers/module-instantiation-rules.cc @@ -18,8 +18,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -114,7 +114,7 @@ static bool IsAnyPort(const verible::Symbol *symbol) { void ModuleParameterRule::HandleSymbol( const verible::Symbol &symbol, const verible::SyntaxTreeContext &context) { - static constexpr absl::string_view kMessage = + static constexpr std::string_view kMessage = "Pass named parameters for parameterized module instantiations with " "more than one parameter"; @@ -152,7 +152,7 @@ verible::LintRuleStatus ModuleParameterRule::Report() const { void ModulePortRule::HandleSymbol(const verible::Symbol &symbol, const verible::SyntaxTreeContext &context) { - static constexpr absl::string_view kMessage = + static constexpr std::string_view kMessage = "Use named ports for module instantiation with " "more than one port"; diff --git a/verible/verilog/analysis/checkers/no-tabs-rule.cc b/verible/verilog/analysis/checkers/no-tabs-rule.cc index 0d552748e..921187af8 100644 --- a/verible/verilog/analysis/checkers/no-tabs-rule.cc +++ b/verible/verilog/analysis/checkers/no-tabs-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/no-tabs-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/token-info.h" #include "verible/verilog/analysis/descriptions.h" @@ -33,7 +33,7 @@ using verible::TokenInfo; // Register the lint rule VERILOG_REGISTER_LINT_RULE(NoTabsRule); -static constexpr absl::string_view kMessage = "Use spaces, not tabs."; +static constexpr std::string_view kMessage = "Use spaces, not tabs."; const LintRuleDescriptor &NoTabsRule::GetDescriptor() { static const LintRuleDescriptor d{ @@ -46,11 +46,11 @@ const LintRuleDescriptor &NoTabsRule::GetDescriptor() { return d; } -void NoTabsRule::HandleLine(absl::string_view line) { +void NoTabsRule::HandleLine(std::string_view line) { // Finds first tab in each line, if there is one. // This reports only the first violation on each line. const auto tab_pos = line.find('\t'); - if (tab_pos != absl::string_view::npos) { + if (tab_pos != std::string_view::npos) { TokenInfo token(TK_SPACE, line.substr(tab_pos, 1)); violations_.insert(LintViolation(token, kMessage)); } diff --git a/verible/verilog/analysis/checkers/no-tabs-rule.h b/verible/verilog/analysis/checkers/no-tabs-rule.h index ca9653651..82cceea66 100644 --- a/verible/verilog/analysis/checkers/no-tabs-rule.h +++ b/verible/verilog/analysis/checkers/no-tabs-rule.h @@ -16,8 +16,8 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_NO_TABS_RULE_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/line-lint-rule.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/verilog/analysis/descriptions.h" @@ -34,7 +34,7 @@ class NoTabsRule : public verible::LineLintRule { NoTabsRule() = default; - void HandleLine(absl::string_view line) final; + void HandleLine(std::string_view line) final; verible::LintRuleStatus Report() const final; diff --git a/verible/verilog/analysis/checkers/no-trailing-spaces-rule.cc b/verible/verilog/analysis/checkers/no-trailing-spaces-rule.cc index c093315c7..99a2f0e73 100644 --- a/verible/verilog/analysis/checkers/no-trailing-spaces-rule.cc +++ b/verible/verilog/analysis/checkers/no-trailing-spaces-rule.cc @@ -19,8 +19,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/token-info.h" @@ -39,7 +39,7 @@ using verible::TokenInfo; // Register the lint rule VERILOG_REGISTER_LINT_RULE(NoTrailingSpacesRule); -static constexpr absl::string_view kMessage = "Remove trailing spaces."; +static constexpr std::string_view kMessage = "Remove trailing spaces."; const LintRuleDescriptor &NoTrailingSpacesRule::GetDescriptor() { static const LintRuleDescriptor d{ @@ -50,7 +50,7 @@ const LintRuleDescriptor &NoTrailingSpacesRule::GetDescriptor() { return d; } -void NoTrailingSpacesRule::HandleLine(absl::string_view line) { +void NoTrailingSpacesRule::HandleLine(std::string_view line) { // Lines may end with \n or \r\n. '\n' is already excluded. // Exclude '\r' absl::ConsumeSuffix(&line, "\r"); diff --git a/verible/verilog/analysis/checkers/no-trailing-spaces-rule.h b/verible/verilog/analysis/checkers/no-trailing-spaces-rule.h index d16b63f1a..c19f8e4f2 100644 --- a/verible/verilog/analysis/checkers/no-trailing-spaces-rule.h +++ b/verible/verilog/analysis/checkers/no-trailing-spaces-rule.h @@ -16,8 +16,8 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_NO_TRAILING_SPACES_RULE_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/line-lint-rule.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/verilog/analysis/descriptions.h" @@ -34,7 +34,7 @@ class NoTrailingSpacesRule : public verible::LineLintRule { NoTrailingSpacesRule() = default; - void HandleLine(absl::string_view line) final; + void HandleLine(std::string_view line) final; verible::LintRuleStatus Report() const final; diff --git a/verible/verilog/analysis/checkers/numeric-format-string-style-rule.cc b/verible/verilog/analysis/checkers/numeric-format-string-style-rule.cc index 08eccc690..c64d2f627 100644 --- a/verible/verilog/analysis/checkers/numeric-format-string-style-rule.cc +++ b/verible/verilog/analysis/checkers/numeric-format-string-style-rule.cc @@ -18,9 +18,9 @@ #include #include #include +#include #include "absl/strings/ascii.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/token-stream-lint-rule.h" #include "verible/common/text/token-info.h" @@ -41,7 +41,7 @@ using verible::TokenStreamLintRule; // Register the lint rule VERILOG_REGISTER_LINT_RULE(NumericFormatStringStyleRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Formatting string must contain proper style-compilant numeric specifiers."; const LintRuleDescriptor &NumericFormatStringStyleRule::GetDescriptor() { @@ -62,7 +62,7 @@ class TD; void NumericFormatStringStyleRule::CheckAndReportViolation( const TokenInfo &token, size_t pos, size_t len, std::initializer_list prefixes) { - const absl::string_view text(token.text()); + const std::string_view text(token.text()); // Check for prefix if (pos >= 2 && (text[pos - 2] == '0' || text[pos - 2] == '\'')) { @@ -83,7 +83,7 @@ void NumericFormatStringStyleRule::CheckAndReportViolation( void NumericFormatStringStyleRule::HandleToken(const TokenInfo &token) { const auto token_enum = static_cast(token.token_enum()); - const absl::string_view text(token.text()); + const std::string_view text(token.text()); if (IsUnlexed(verilog_tokentype(token.token_enum()))) { // recursively lex to examine inside macro definition bodies, etc. diff --git a/verible/verilog/analysis/checkers/one-module-per-file-rule.cc b/verible/verilog/analysis/checkers/one-module-per-file-rule.cc index b29161a48..0e9654474 100644 --- a/verible/verilog/analysis/checkers/one-module-per-file-rule.cc +++ b/verible/verilog/analysis/checkers/one-module-per-file-rule.cc @@ -18,10 +18,10 @@ #include #include #include +#include #include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/text/text-structure.h" @@ -40,7 +40,7 @@ using verible::TextStructureView; // Register the lint rule VERILOG_REGISTER_LINT_RULE(OneModulePerFileRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Each file should have only one module declaration. Found: "; const LintRuleDescriptor &OneModulePerFileRule::GetDescriptor() { @@ -53,7 +53,7 @@ const LintRuleDescriptor &OneModulePerFileRule::GetDescriptor() { } void OneModulePerFileRule::Lint(const TextStructureView &text_structure, - absl::string_view) { + std::string_view) { const auto &tree = text_structure.SyntaxTree(); if (tree == nullptr) return; diff --git a/verible/verilog/analysis/checkers/one-module-per-file-rule.h b/verible/verilog/analysis/checkers/one-module-per-file-rule.h index 7ec5590bd..d7dd363d7 100644 --- a/verible/verilog/analysis/checkers/one-module-per-file-rule.h +++ b/verible/verilog/analysis/checkers/one-module-per-file-rule.h @@ -16,8 +16,8 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_ONE_MODULE_PER_FILE_RULE_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/text-structure-lint-rule.h" #include "verible/common/text/text-structure.h" @@ -35,7 +35,7 @@ class OneModulePerFileRule : public verible::TextStructureLintRule { OneModulePerFileRule() = default; - void Lint(const verible::TextStructureView &, absl::string_view) final; + void Lint(const verible::TextStructureView &, std::string_view) final; verible::LintRuleStatus Report() const final; diff --git a/verible/verilog/analysis/checkers/package-filename-rule.cc b/verible/verilog/analysis/checkers/package-filename-rule.cc index 75fe573e4..ad3bac878 100644 --- a/verible/verilog/analysis/checkers/package-filename-rule.cc +++ b/verible/verilog/analysis/checkers/package-filename-rule.cc @@ -18,12 +18,12 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/text/config-utils.h" @@ -43,9 +43,9 @@ using verible::TextStructureView; // Register the lint rule VERILOG_REGISTER_LINT_RULE(PackageFilenameRule); -static constexpr absl::string_view kOptionalSuffix = "_pkg"; +static constexpr std::string_view kOptionalSuffix = "_pkg"; -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Package declaration name must match the file name " "(ignoring optional \"_pkg\" file name suffix). "; @@ -65,7 +65,7 @@ const LintRuleDescriptor &PackageFilenameRule::GetDescriptor() { } void PackageFilenameRule::Lint(const TextStructureView &text_structure, - absl::string_view filename) { + std::string_view filename) { if (verible::file::IsStdin(filename)) { return; } @@ -87,9 +87,9 @@ void PackageFilenameRule::Lint(const TextStructureView &text_structure, // foo | foo-pkg.sv | yes, iff allow-dash-for-underscore // foo_pkg | foo_pkg.sv | yes // foo_pkg | foo.sv | NO. - const absl::string_view basename = + const std::string_view basename = verible::file::Basename(verible::file::Stem(filename)); - std::vector basename_components = + std::vector basename_components = absl::StrSplit(basename, '.'); if (basename_components.empty() || basename_components[0].empty()) return; std::string unitname(basename_components[0].begin(), @@ -105,7 +105,7 @@ void PackageFilenameRule::Lint(const TextStructureView &text_structure, const verible::TokenInfo *package_name_token = GetPackageNameToken(*package_match.match); if (!package_name_token) continue; - absl::string_view package_id = package_name_token->text(); + std::string_view package_id = package_name_token->text(); auto package_id_plus_suffix = absl::StrCat(package_id, kOptionalSuffix); if ((package_id != unitname) && (package_id_plus_suffix != unitname)) { violations_.insert(verible::LintViolation( @@ -120,7 +120,7 @@ LintRuleStatus PackageFilenameRule::Report() const { return LintRuleStatus(violations_, GetDescriptor()); } -absl::Status PackageFilenameRule::Configure(absl::string_view configuration) { +absl::Status PackageFilenameRule::Configure(std::string_view configuration) { using verible::config::SetBool; return verible::ParseNameValues( configuration, diff --git a/verible/verilog/analysis/checkers/package-filename-rule.h b/verible/verilog/analysis/checkers/package-filename-rule.h index 48f1c0060..52d730993 100644 --- a/verible/verilog/analysis/checkers/package-filename-rule.h +++ b/verible/verilog/analysis/checkers/package-filename-rule.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_PACKAGE_FILENAME_RULE_H_ #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/text-structure-lint-rule.h" #include "verible/common/text/text-structure.h" @@ -37,8 +37,8 @@ class PackageFilenameRule : public verible::TextStructureLintRule { PackageFilenameRule() = default; - absl::Status Configure(absl::string_view configuration) final; - void Lint(const verible::TextStructureView &, absl::string_view) final; + absl::Status Configure(std::string_view configuration) final; + void Lint(const verible::TextStructureView &, std::string_view) final; verible::LintRuleStatus Report() const final; diff --git a/verible/verilog/analysis/checkers/package-filename-rule_test.cc b/verible/verilog/analysis/checkers/package-filename-rule_test.cc index b3d06ef70..501bada5e 100644 --- a/verible/verilog/analysis/checkers/package-filename-rule_test.cc +++ b/verible/verilog/analysis/checkers/package-filename-rule_test.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/text-structure-linter-test-utils.h" @@ -205,7 +205,7 @@ TEST(PackageFilenameRuleTest, DashAllowedWhenConfigured) { { // With dashes not allowed, we only accept the underscore name - constexpr absl::string_view config = "allow-dash-for-underscore:off"; + constexpr std::string_view config = "allow-dash-for-underscore:off"; RunConfiguredLintTestCases( kOkCases, config, f_with_underscore); RunConfiguredLintTestCases( @@ -216,7 +216,7 @@ TEST(PackageFilenameRuleTest, DashAllowedWhenConfigured) { { // ... But with dashes allowed, dashes are also an ok case. - constexpr absl::string_view config = "allow-dash-for-underscore:on"; + constexpr std::string_view config = "allow-dash-for-underscore:on"; // With dashes not allowed, we only accept the underscore name RunConfiguredLintTestCases( kOkCases, config, f_with_underscore); diff --git a/verible/verilog/analysis/checkers/packed-dimensions-rule.cc b/verible/verilog/analysis/checkers/packed-dimensions-rule.cc index 8ec0ddb9e..c6ec3ac0e 100644 --- a/verible/verilog/analysis/checkers/packed-dimensions-rule.cc +++ b/verible/verilog/analysis/checkers/packed-dimensions-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/packed-dimensions-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -42,7 +42,7 @@ using verible::matcher::Matcher; VERILOG_REGISTER_LINT_RULE(PackedDimensionsRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Declare packed dimension range in little-endian (decreasing) order, " "e.g. [N-1:0]."; diff --git a/verible/verilog/analysis/checkers/parameter-name-style-rule.cc b/verible/verilog/analysis/checkers/parameter-name-style-rule.cc index 930e14270..9c0b5b32b 100644 --- a/verible/verilog/analysis/checkers/parameter-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/parameter-name-style-rule.cc @@ -18,11 +18,11 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" @@ -48,13 +48,13 @@ using verible::SyntaxTreeContext; using Matcher = verible::matcher::Matcher; // Upper Camel Case (may end in _[0-9]+) -static constexpr absl::string_view kUpperCamelCaseRegex = +static constexpr std::string_view kUpperCamelCaseRegex = "([A-Z0-9]+[a-z0-9]*)+(_[0-9]+)?"; // ALL_CAPS -static constexpr absl::string_view kAllCapsRegex = "[A-Z_0-9]+"; +static constexpr std::string_view kAllCapsRegex = "[A-Z_0-9]+"; -static constexpr absl::string_view kLocalparamDefaultRegex; -static constexpr absl::string_view kParameterDefaultRegex; +static constexpr std::string_view kLocalparamDefaultRegex; +static constexpr std::string_view kParameterDefaultRegex; ParameterNameStyleRule::ParameterNameStyleRule() : localparam_style_regex_(std::make_unique( @@ -137,7 +137,7 @@ void ParameterNameStyleRule::HandleSymbol(const verible::Symbol &symbol, } absl::Status ParameterNameStyleRule::AppendRegex( - std::unique_ptr *rule_regex, absl::string_view regex_str) { + std::unique_ptr *rule_regex, std::string_view regex_str) { if (*rule_regex == nullptr) { *rule_regex = std::make_unique(absl::StrCat("(", regex_str, ")"), re2::RE2::Quiet); @@ -197,11 +197,10 @@ absl::Status ParameterNameStyleRule::ConfigureRegex( return s; } -absl::Status ParameterNameStyleRule::Configure( - absl::string_view configuration) { +absl::Status ParameterNameStyleRule::Configure(std::string_view configuration) { // same sequence as enum StyleChoicesBits - static const std::vector choices = {"CamelCase", - "ALL_CAPS"}; + static const std::vector choices = {"CamelCase", + "ALL_CAPS"}; uint32_t localparam_style = kUpperCamelCase; uint32_t parameter_style = kUpperCamelCase | kAllCaps; diff --git a/verible/verilog/analysis/checkers/parameter-name-style-rule.h b/verible/verilog/analysis/checkers/parameter-name-style-rule.h index 001d2317f..1f941f9af 100644 --- a/verible/verilog/analysis/checkers/parameter-name-style-rule.h +++ b/verible/verilog/analysis/checkers/parameter-name-style-rule.h @@ -19,9 +19,9 @@ #include #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" @@ -50,7 +50,7 @@ class ParameterNameStyleRule : public verible::SyntaxTreeLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; const RE2 *localparam_style_regex() const { return localparam_style_regex_.get(); @@ -61,7 +61,7 @@ class ParameterNameStyleRule : public verible::SyntaxTreeLintRule { private: absl::Status AppendRegex(std::unique_ptr *rule_regex, - absl::string_view regex_str); + std::string_view regex_str); absl::Status ConfigureRegex(std::unique_ptr *rule_regex, uint32_t config_style, std::unique_ptr *config_style_regex); diff --git a/verible/verilog/analysis/checkers/parameter-name-style-rule_test.cc b/verible/verilog/analysis/checkers/parameter-name-style-rule_test.cc index 1086af87e..5af2432a6 100644 --- a/verible/verilog/analysis/checkers/parameter-name-style-rule_test.cc +++ b/verible/verilog/analysis/checkers/parameter-name-style-rule_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/syntax-tree-linter-test-utils.h" @@ -225,10 +225,10 @@ TEST(ParameterNameStyleRuleTest, ConfigurationPass) { absl::Status status; // Upper Camel Case (may end in _[0-9]+) - constexpr absl::string_view kUpperCamelCaseRegex = + constexpr std::string_view kUpperCamelCaseRegex = "(([A-Z0-9]+[a-z0-9]*)+(_[0-9]+)?)"; // ALL_CAPS - constexpr absl::string_view kAllCapsRegex = "([A-Z_0-9]+)"; + constexpr std::string_view kAllCapsRegex = "([A-Z_0-9]+)"; const std::string default_localparam_regex = std::string(kUpperCamelCaseRegex); diff --git a/verible/verilog/analysis/checkers/parameter-type-name-style-rule.cc b/verible/verilog/analysis/checkers/parameter-type-name-style-rule.cc index d0e36681a..7d95b7f25 100644 --- a/verible/verilog/analysis/checkers/parameter-type-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/parameter-type-name-style-rule.cc @@ -15,9 +15,9 @@ #include "verible/verilog/analysis/checkers/parameter-type-name-style-rule.h" #include +#include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -41,7 +41,7 @@ using verible::matcher::Matcher; // Register ParameterTypeNameStyleRule. VERILOG_REGISTER_LINT_RULE(ParameterTypeNameStyleRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Parameter type names must use the lower_snake_case naming convention" " and end with _t."; diff --git a/verible/verilog/analysis/checkers/plusarg-assignment-rule.cc b/verible/verilog/analysis/checkers/plusarg-assignment-rule.cc index c80a374df..bcae10b28 100644 --- a/verible/verilog/analysis/checkers/plusarg-assignment-rule.cc +++ b/verible/verilog/analysis/checkers/plusarg-assignment-rule.cc @@ -16,9 +16,9 @@ #include #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -37,8 +37,8 @@ using verible::matcher::Matcher; VERILOG_REGISTER_LINT_RULE(PlusargAssignmentRule); -static constexpr absl::string_view kForbiddenFunctionName = "$test$plusargs"; -static constexpr absl::string_view kCorrectFunctionName = "$value$plusargs"; +static constexpr std::string_view kForbiddenFunctionName = "$test$plusargs"; +static constexpr std::string_view kCorrectFunctionName = "$value$plusargs"; const LintRuleDescriptor &PlusargAssignmentRule::GetDescriptor() { static const LintRuleDescriptor d{ diff --git a/verible/verilog/analysis/checkers/port-name-suffix-rule.cc b/verible/verilog/analysis/checkers/port-name-suffix-rule.cc index f96e5dcac..1d4235fb4 100644 --- a/verible/verilog/analysis/checkers/port-name-suffix-rule.cc +++ b/verible/verilog/analysis/checkers/port-name-suffix-rule.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -46,11 +46,11 @@ using verible::matcher::Matcher; // Register PortNameSuffixRule. VERILOG_REGISTER_LINT_RULE(PortNameSuffixRule); -static constexpr absl::string_view kMessageIn = +static constexpr std::string_view kMessageIn = "input port names must end with _i, _ni or _pi"; -static constexpr absl::string_view kMessageOut = +static constexpr std::string_view kMessageOut = "output port names must end with _o, _no, or _po"; -static constexpr absl::string_view kMessageInOut = +static constexpr std::string_view kMessageInOut = "inout port names must end with _io, _nio or _pio"; const LintRuleDescriptor &PortNameSuffixRule::GetDescriptor() { @@ -71,7 +71,7 @@ static const Matcher &PortMatcher() { return matcher; } -void PortNameSuffixRule::Violation(absl::string_view direction, +void PortNameSuffixRule::Violation(std::string_view direction, const TokenInfo &token, const SyntaxTreeContext &context) { if (direction == "input") { @@ -83,12 +83,12 @@ void PortNameSuffixRule::Violation(absl::string_view direction, } } -bool PortNameSuffixRule::IsSuffixCorrect(absl::string_view suffix, - absl::string_view direction) { - static const std::map> - suffixes = {{"input", {"i", "ni", "pi"}}, - {"output", {"o", "no", "po"}}, - {"inout", {"io", "nio", "pio"}}}; +bool PortNameSuffixRule::IsSuffixCorrect(std::string_view suffix, + std::string_view direction) { + static const std::map> suffixes = + {{"input", {"i", "ni", "pi"}}, + {"output", {"o", "no", "po"}}, + {"inout", {"io", "nio", "pio"}}}; // At this point it is guaranteed that the direction will be set to // one of the expected values (used as keys in the map above). @@ -98,7 +98,7 @@ bool PortNameSuffixRule::IsSuffixCorrect(absl::string_view suffix, void PortNameSuffixRule::HandleSymbol(const Symbol &symbol, const SyntaxTreeContext &context) { - constexpr absl::string_view implicit_direction = "input"; + constexpr std::string_view implicit_direction = "input"; verible::matcher::BoundSymbolManager manager; if (PortMatcher().Matches(symbol, &manager)) { const auto *identifier_leaf = GetIdentifierFromPortDeclaration(symbol); diff --git a/verible/verilog/analysis/checkers/port-name-suffix-rule.h b/verible/verilog/analysis/checkers/port-name-suffix-rule.h index 7a28d13bd..604c7284a 100644 --- a/verible/verilog/analysis/checkers/port-name-suffix-rule.h +++ b/verible/verilog/analysis/checkers/port-name-suffix-rule.h @@ -16,8 +16,8 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_PORT_NAME_SUFFIX_RULE_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/text/symbol.h" @@ -45,10 +45,10 @@ class PortNameSuffixRule : public verible::SyntaxTreeLintRule { private: // Helper functions - void Violation(absl::string_view direction, const verible::TokenInfo &token, + void Violation(std::string_view direction, const verible::TokenInfo &token, const verible::SyntaxTreeContext &context); - static bool IsSuffixCorrect(absl::string_view suffix, - absl::string_view direction); + static bool IsSuffixCorrect(std::string_view suffix, + std::string_view direction); // Violations std::set violations_; diff --git a/verible/verilog/analysis/checkers/positive-meaning-parameter-name-rule.cc b/verible/verilog/analysis/checkers/positive-meaning-parameter-name-rule.cc index d843779c0..3050daaae 100644 --- a/verible/verilog/analysis/checkers/positive-meaning-parameter-name-rule.cc +++ b/verible/verilog/analysis/checkers/positive-meaning-parameter-name-rule.cc @@ -15,10 +15,10 @@ #include "verible/verilog/analysis/checkers/positive-meaning-parameter-name-rule.h" #include +#include #include "absl/strings/match.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -41,7 +41,7 @@ using verible::matcher::Matcher; // Register PositiveMeaningParameterNameRule. VERILOG_REGISTER_LINT_RULE(PositiveMeaningParameterNameRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Use positive naming for parameters, start the name with 'enable' instead."; const LintRuleDescriptor &PositiveMeaningParameterNameRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/posix-eof-rule.cc b/verible/verilog/analysis/checkers/posix-eof-rule.cc index 94dbe9cca..855e69e70 100644 --- a/verible/verilog/analysis/checkers/posix-eof-rule.cc +++ b/verible/verilog/analysis/checkers/posix-eof-rule.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/text-structure.h" #include "verible/common/text/token-info.h" @@ -37,7 +37,7 @@ using verible::TokenInfo; // Register the lint rule VERILOG_REGISTER_LINT_RULE(PosixEOFRule); -static constexpr absl::string_view kMessage = "File must end with a newline."; +static constexpr std::string_view kMessage = "File must end with a newline."; const LintRuleDescriptor &PosixEOFRule::GetDescriptor() { static const LintRuleDescriptor d{ @@ -49,7 +49,7 @@ const LintRuleDescriptor &PosixEOFRule::GetDescriptor() { } void PosixEOFRule::Lint(const TextStructureView &text_structure, - absl::string_view) { + std::string_view) { if (!text_structure.Contents().empty()) { const auto &last_line = text_structure.Lines().back(); if (!last_line.empty()) { diff --git a/verible/verilog/analysis/checkers/posix-eof-rule.h b/verible/verilog/analysis/checkers/posix-eof-rule.h index 343e9db53..aaeae4cb8 100644 --- a/verible/verilog/analysis/checkers/posix-eof-rule.h +++ b/verible/verilog/analysis/checkers/posix-eof-rule.h @@ -16,8 +16,8 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_POSIX_EOF_RULE_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/text-structure-lint-rule.h" #include "verible/common/text/text-structure.h" @@ -42,7 +42,7 @@ class PosixEOFRule : public verible::TextStructureLintRule { PosixEOFRule() = default; - void Lint(const verible::TextStructureView &, absl::string_view) final; + void Lint(const verible::TextStructureView &, std::string_view) final; verible::LintRuleStatus Report() const final; diff --git a/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.cc b/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.cc index f58dbda3e..a2433bd3a 100644 --- a/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.cc +++ b/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.cc @@ -15,9 +15,9 @@ #include "verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h" #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -43,22 +43,22 @@ using verible::matcher::Matcher; // Register ProperParameterDeclarationRule VERILOG_REGISTER_LINT_RULE(ProperParameterDeclarationRule); -static constexpr absl::string_view kParameterNotInPackageMessage = +static constexpr std::string_view kParameterNotInPackageMessage = "\'parameter\' declarations should only be in the formal parameter list of " "modules/classes."; -static constexpr absl::string_view kParameterAllowPackageMessage = +static constexpr std::string_view kParameterAllowPackageMessage = "\'parameter\' declarations should only be in the formal parameter list of " "modules and classes or in package definition bodies."; -static constexpr absl::string_view kLocalParamNotInPackageMessage = +static constexpr std::string_view kLocalParamNotInPackageMessage = "\'localparam\' declarations should only be within modules or class " "definition bodies."; -static constexpr absl::string_view kLocalParamAllowPackageMessage = +static constexpr std::string_view kLocalParamAllowPackageMessage = "\'localparam\' declarations should only be within modules, packages or " "class definition bodies."; -static constexpr absl::string_view kAutoFixReplaceParameterWithLocalparam = +static constexpr std::string_view kAutoFixReplaceParameterWithLocalparam = "Replace 'parameter' with 'localparam'"; -static constexpr absl::string_view kAutoFixReplaceLocalparamWithParameter = +static constexpr std::string_view kAutoFixReplaceLocalparamWithParameter = "Replace 'localparam' with 'parameter'"; const LintRuleDescriptor &ProperParameterDeclarationRule::GetDescriptor() { @@ -100,7 +100,7 @@ void ProperParameterDeclarationRule::ChooseMessagesForConfiguration() { } absl::Status ProperParameterDeclarationRule::Configure( - absl::string_view configuration) { + std::string_view configuration) { using verible::config::SetBool; auto status = verible::ParseNameValues( configuration, diff --git a/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h b/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h index e115a168d..ba03db097 100644 --- a/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h +++ b/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_PROPER_PARAMETER_DECLARATION_RULE_H_ #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/text/symbol.h" @@ -50,7 +50,7 @@ class ProperParameterDeclarationRule : public verible::SyntaxTreeLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; private: void ChooseMessagesForConfiguration(); @@ -60,8 +60,8 @@ class ProperParameterDeclarationRule : public verible::SyntaxTreeLintRule { bool package_allow_parameter_ = false; bool package_allow_localparam_ = true; - absl::string_view parameter_message_; - absl::string_view local_parameter_message_; + std::string_view parameter_message_; + std::string_view local_parameter_message_; }; } // namespace analysis diff --git a/verible/verilog/analysis/checkers/signal-name-style-rule.cc b/verible/verilog/analysis/checkers/signal-name-style-rule.cc index 8f1f8a9af..92d18b73f 100644 --- a/verible/verilog/analysis/checkers/signal-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/signal-name-style-rule.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" @@ -48,7 +48,7 @@ using verible::LintViolation; using verible::SyntaxTreeContext; using verible::matcher::Matcher; -static constexpr absl::string_view kDefaultStyleRegex = "[a-z_0-9]+"; +static constexpr std::string_view kDefaultStyleRegex = "[a-z_0-9]+"; SignalNameStyleRule::SignalNameStyleRule() : style_regex_( @@ -122,7 +122,7 @@ void SignalNameStyleRule::HandleSymbol(const verible::Symbol &symbol, } } -absl::Status SignalNameStyleRule::Configure(absl::string_view configuration) { +absl::Status SignalNameStyleRule::Configure(std::string_view configuration) { using verible::config::SetRegex; absl::Status s = verible::ParseNameValues( configuration, {{"style_regex", SetRegex(&style_regex_)}}); diff --git a/verible/verilog/analysis/checkers/signal-name-style-rule.h b/verible/verilog/analysis/checkers/signal-name-style-rule.h index 2e047ce1e..863fcc3e7 100644 --- a/verible/verilog/analysis/checkers/signal-name-style-rule.h +++ b/verible/verilog/analysis/checkers/signal-name-style-rule.h @@ -18,9 +18,9 @@ #include #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" @@ -50,7 +50,7 @@ class SignalNameStyleRule : public verible::SyntaxTreeLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; private: std::set violations_; diff --git a/verible/verilog/analysis/checkers/struct-union-name-style-rule.cc b/verible/verilog/analysis/checkers/struct-union-name-style-rule.cc index c18c7d3b3..2ab0d9e04 100644 --- a/verible/verilog/analysis/checkers/struct-union-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/struct-union-name-style-rule.cc @@ -17,13 +17,13 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -46,8 +46,8 @@ using verible::LintViolation; using verible::SyntaxTreeContext; using verible::matcher::Matcher; -static constexpr absl::string_view kMessageStruct = "Struct names"; -static constexpr absl::string_view kMessageUnion = "Union names"; +static constexpr std::string_view kMessageStruct = "Struct names"; +static constexpr std::string_view kMessageUnion = "Union names"; const LintRuleDescriptor &StructUnionNameStyleRule::GetDescriptor() { static const LintRuleDescriptor d{ @@ -76,7 +76,7 @@ void StructUnionNameStyleRule::HandleSymbol(const verible::Symbol &symbol, // have consistent shape for all kTypeDeclaration nodes. const bool is_struct = !FindAllStructTypes(symbol).empty(); if (!is_struct && FindAllUnionTypes(symbol).empty()) return; - const absl::string_view msg = is_struct ? kMessageStruct : kMessageUnion; + const std::string_view msg = is_struct ? kMessageStruct : kMessageUnion; const auto *identifier_leaf = GetIdentifierFromTypeDeclaration(symbol); const auto name = ABSL_DIE_IF_NULL(identifier_leaf)->get().text(); @@ -124,7 +124,7 @@ void StructUnionNameStyleRule::HandleSymbol(const verible::Symbol &symbol, } absl::Status StructUnionNameStyleRule::Configure( - absl::string_view configuration) { + std::string_view configuration) { using verible::config::SetString; std::string raw_tokens; auto status = verible::ParseNameValues( diff --git a/verible/verilog/analysis/checkers/struct-union-name-style-rule.h b/verible/verilog/analysis/checkers/struct-union-name-style-rule.h index 864fda721..c2595c064 100644 --- a/verible/verilog/analysis/checkers/struct-union-name-style-rule.h +++ b/verible/verilog/analysis/checkers/struct-union-name-style-rule.h @@ -17,9 +17,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/text/symbol.h" @@ -40,7 +40,7 @@ class StructUnionNameStyleRule : public verible::SyntaxTreeLintRule { void HandleSymbol(const verible::Symbol &symbol, const verible::SyntaxTreeContext &context) final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; verible::LintRuleStatus Report() const final; diff --git a/verible/verilog/analysis/checkers/struct-union-name-style-rule_test.cc b/verible/verilog/analysis/checkers/struct-union-name-style-rule_test.cc index 2f0b8f9ed..80aa9c611 100644 --- a/verible/verilog/analysis/checkers/struct-union-name-style-rule_test.cc +++ b/verible/verilog/analysis/checkers/struct-union-name-style-rule_test.cc @@ -15,10 +15,10 @@ #include "verible/verilog/analysis/checkers/struct-union-name-style-rule.h" #include +#include #include "absl/status/status.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/syntax-tree-linter-test-utils.h" @@ -89,7 +89,7 @@ TEST(StructUnionNameStyleRuleTest, ValidStructNames) { } TEST(StructUnionNameStyleRuleTestConfigured, ValidStructNames) { - const absl::string_view exceptions = "exceptions:12B,11GiB,KJ,Kg"; + const std::string_view exceptions = "exceptions:12B,11GiB,KJ,Kg"; const std::initializer_list kTestCases = { {""}, {"typedef struct {logic foo; logic bar;} b_a_z_t;"}, @@ -105,7 +105,7 @@ TEST(StructUnionNameStyleRuleTestConfigured, ValidStructNames) { } TEST(StructUnionNameStyleRuleTestConfigured, InvalidStructNames) { - const absl::string_view exceptions = "exceptions:12B,KJ,Kg,t"; + const std::string_view exceptions = "exceptions:12B,KJ,Kg,t"; constexpr int kToken = SymbolIdentifier; const std::initializer_list kTestCases = { {""}, @@ -169,7 +169,7 @@ TEST(StructUnionNameStyleRuleTest, ValidUnionNames) { } TEST(StructUnionNameStyleRuleTestConfigured, ValidUnionNames) { - const absl::string_view exceptions = "exceptions:12B,11GiB,KJ,Kg"; + const std::string_view exceptions = "exceptions:12B,11GiB,KJ,Kg"; const std::initializer_list kTestCases = { {""}, {"typedef union {logic foo; logic bar;} b_a_z_t;"}, @@ -220,7 +220,7 @@ TEST(StructUnionNameStyleRuleTest, InvalidUnionNames) { } TEST(StructUnionNameStyleRuleTestConfigured, InvalidUnionNames) { - const absl::string_view exceptions = "exceptions:12B,KJ,Kg,t"; + const std::string_view exceptions = "exceptions:12B,KJ,Kg,t"; constexpr int kToken = SymbolIdentifier; const std::initializer_list kTestCases = { {""}, diff --git a/verible/verilog/analysis/checkers/suggest-parentheses-rule.cc b/verible/verilog/analysis/checkers/suggest-parentheses-rule.cc index d88d2e1c3..8cbaa1587 100644 --- a/verible/verilog/analysis/checkers/suggest-parentheses-rule.cc +++ b/verible/verilog/analysis/checkers/suggest-parentheses-rule.cc @@ -14,7 +14,8 @@ #include "verible/verilog/analysis/checkers/suggest-parentheses-rule.h" -#include "absl/strings/string_view.h" +#include + #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/concrete-syntax-tree.h" #include "verible/common/text/symbol.h" @@ -36,7 +37,7 @@ using verible::AutoFix; using verible::LintRuleStatus; using verible::LintViolation; -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Parenthesize condition expressions that appear in the true-clause of " "another condition expression."; diff --git a/verible/verilog/analysis/checkers/suspicious-semicolon-rule.cc b/verible/verilog/analysis/checkers/suspicious-semicolon-rule.cc index c05925825..39ea649b3 100644 --- a/verible/verilog/analysis/checkers/suspicious-semicolon-rule.cc +++ b/verible/verilog/analysis/checkers/suspicious-semicolon-rule.cc @@ -14,7 +14,8 @@ #include "verible/verilog/analysis/checkers/suspicious-semicolon-rule.h" -#include "absl/strings/string_view.h" +#include + #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -33,8 +34,7 @@ using verible::matcher::Matcher; VERILOG_REGISTER_LINT_RULE(SuspiciousSemicolon); -static constexpr absl::string_view kMessage = - "Potentially unintended semicolon"; +static constexpr std::string_view kMessage = "Potentially unintended semicolon"; const LintRuleDescriptor &SuspiciousSemicolon::GetDescriptor() { static const LintRuleDescriptor d{ diff --git a/verible/verilog/analysis/checkers/truncated-numeric-literal-rule.cc b/verible/verilog/analysis/checkers/truncated-numeric-literal-rule.cc index 4ae52365b..8c241631e 100644 --- a/verible/verilog/analysis/checkers/truncated-numeric-literal-rule.cc +++ b/verible/verilog/analysis/checkers/truncated-numeric-literal-rule.cc @@ -20,11 +20,11 @@ #include #include #include +#include #include "absl/numeric/int128.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -82,8 +82,8 @@ static int digitBits(char digit, bool *is_lower_bound) { return 1; } -static absl::string_view StripLeadingZeroes(absl::string_view str) { - const absl::string_view::const_iterator it = +static std::string_view StripLeadingZeroes(std::string_view str) { + const std::string_view::const_iterator it = std::find_if_not(str.begin(), str.end(), [](char c) { return c == '0'; }); return str.substr(it - str.begin()); } @@ -91,7 +91,7 @@ static absl::string_view StripLeadingZeroes(absl::string_view str) { // Return count of bits the given number occupies. Sometims we can only make // a lower bound estimate, return that in "is_lower_bound". static size_t GetBitWidthOfNumber(const BasedNumber &n, bool *is_lower_bound) { - const absl::string_view literal = StripLeadingZeroes(n.literal); + const std::string_view literal = StripLeadingZeroes(n.literal); *is_lower_bound = true; // Can only estimate for the following two if (literal.empty()) return 1; // all zeroes diff --git a/verible/verilog/analysis/checkers/truncated-numeric-literal-rule_test.cc b/verible/verilog/analysis/checkers/truncated-numeric-literal-rule_test.cc index 54d43e3e7..c0041fc92 100644 --- a/verible/verilog/analysis/checkers/truncated-numeric-literal-rule_test.cc +++ b/verible/verilog/analysis/checkers/truncated-numeric-literal-rule_test.cc @@ -16,9 +16,9 @@ #include #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/linter-test-utils.h" #include "verible/common/analysis/syntax-tree-linter-test-utils.h" @@ -66,7 +66,7 @@ TEST(TruncatedNumericLiteralRuleTest, TooShortHexNumbers) { constexpr int kToken = TK_HexDigits; const std::string superlong(1001, 'F'); const std::string exp = absl::StrCat("localparam x = 4004'h", superlong, ";"); - const absl::string_view good_long_expression = exp; + const std::string_view good_long_expression = exp; const std::initializer_list kTestCases = { {"localparam x = 1'h1;"}, @@ -136,7 +136,7 @@ TEST(TruncatedNumericLiteralRuleTest, TruncatedDecimalNumbers) { // A number longer than can be parsed as double to force fallback of fallback. const std::string superlong(500, '9'); const std::string exp = absl::StrCat("localparam x = 1661'd", superlong, ";"); - const absl::string_view good_long_expression = exp; + const std::string_view good_long_expression = exp; const std::initializer_list kTestCases = { {"localparam x = 1'd1;"}, diff --git a/verible/verilog/analysis/checkers/undersized-binary-literal-rule.cc b/verible/verilog/analysis/checkers/undersized-binary-literal-rule.cc index f0f4b5986..2269fff1c 100644 --- a/verible/verilog/analysis/checkers/undersized-binary-literal-rule.cc +++ b/verible/verilog/analysis/checkers/undersized-binary-literal-rule.cc @@ -18,12 +18,12 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -172,9 +172,9 @@ void UndersizedBinaryLiteralRule::HandleSymbol( // Generate string representation of why lint error occurred at leaf std::string UndersizedBinaryLiteralRule::FormatReason( - absl::string_view width, absl::string_view base_text, char base, - absl::string_view literal) { - absl::string_view base_describe; + std::string_view width, std::string_view base_text, char base, + std::string_view literal) { + std::string_view base_describe; switch (base) { case 'b': base_describe = "Binary"; @@ -193,7 +193,7 @@ std::string UndersizedBinaryLiteralRule::FormatReason( } absl::Status UndersizedBinaryLiteralRule::Configure( - absl::string_view configuration) { + std::string_view configuration) { using verible::config::SetBool; return verible::ParseNameValues(configuration, {{"bin", SetBool(&check_bin_numbers_)}, diff --git a/verible/verilog/analysis/checkers/undersized-binary-literal-rule.h b/verible/verilog/analysis/checkers/undersized-binary-literal-rule.h index b74aa6b9c..7ab93e3dc 100644 --- a/verible/verilog/analysis/checkers/undersized-binary-literal-rule.h +++ b/verible/verilog/analysis/checkers/undersized-binary-literal-rule.h @@ -17,9 +17,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/text/symbol.h" @@ -44,13 +44,13 @@ class UndersizedBinaryLiteralRule : public verible::SyntaxTreeLintRule { verible::LintRuleStatus Report() const final; - absl::Status Configure(absl::string_view configuration) final; + absl::Status Configure(std::string_view configuration) final; private: // Generate string representation of why lint error occurred at leaf - static std::string FormatReason(absl::string_view width, - absl::string_view base_text, char base, - absl::string_view literal); + static std::string FormatReason(std::string_view width, + std::string_view base_text, char base, + std::string_view literal); bool check_bin_numbers_ = true; bool check_hex_numbers_ = false; diff --git a/verible/verilog/analysis/checkers/unpacked-dimensions-rule.cc b/verible/verilog/analysis/checkers/unpacked-dimensions-rule.cc index 45c07a99c..a17e723bd 100644 --- a/verible/verilog/analysis/checkers/unpacked-dimensions-rule.cc +++ b/verible/verilog/analysis/checkers/unpacked-dimensions-rule.cc @@ -15,8 +15,8 @@ #include "verible/verilog/analysis/checkers/unpacked-dimensions-rule.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -43,13 +43,13 @@ using verible::matcher::Matcher; VERILOG_REGISTER_LINT_RULE(UnpackedDimensionsRule); -static constexpr absl::string_view kMessageScalarInOrder = +static constexpr std::string_view kMessageScalarInOrder = "When an unpacked dimension range is zero-based ([0:N-1]), " "declare size as [N] instead."; -static constexpr absl::string_view kMessageScalarReversed = +static constexpr std::string_view kMessageScalarReversed = "Unpacked dimension range must be declared in big-endian ([0:N-1]) order. " "Declare zero-based big-endian unpacked dimensions sized as [N]."; -static constexpr absl::string_view kMessageReorder = +static constexpr std::string_view kMessageReorder = "Declare unpacked dimension range in big-endian (increasing) order, " "e.g. [N:N+M]."; diff --git a/verible/verilog/analysis/checkers/uvm-macro-semicolon-rule.cc b/verible/verilog/analysis/checkers/uvm-macro-semicolon-rule.cc index c4903f8fa..77a5f65a4 100644 --- a/verible/verilog/analysis/checkers/uvm-macro-semicolon-rule.cc +++ b/verible/verilog/analysis/checkers/uvm-macro-semicolon-rule.cc @@ -15,10 +15,10 @@ #include "verible/verilog/analysis/checkers/uvm-macro-semicolon-rule.h" #include +#include #include "absl/strings/match.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/symbol.h" @@ -58,7 +58,7 @@ static std::string FormatReason(const verible::TokenInfo ¯o_id) { // Returns true if leaf is a macro and matches `uvm_ static bool IsUvmMacroId(const verible::SyntaxTreeLeaf &leaf) { - const absl::string_view text = leaf.get().text(); + const std::string_view text = leaf.get().text(); const bool starts_with_uvm = absl::StartsWithIgnoreCase(text, "`uvm_"); if (leaf.Tag().tag == verilog_tokentype::MacroCallId || diff --git a/verible/verilog/analysis/checkers/v2001-generate-begin-rule.cc b/verible/verilog/analysis/checkers/v2001-generate-begin-rule.cc index 7654320ab..ad7cd046f 100644 --- a/verible/verilog/analysis/checkers/v2001-generate-begin-rule.cc +++ b/verible/verilog/analysis/checkers/v2001-generate-begin-rule.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/matcher.h" @@ -39,7 +39,7 @@ using verible::matcher::Matcher; // Register the lint rule VERILOG_REGISTER_LINT_RULE(V2001GenerateBeginRule); -static constexpr absl::string_view kMessage = +static constexpr std::string_view kMessage = "Do not begin a generate block inside a generate region."; const LintRuleDescriptor &V2001GenerateBeginRule::GetDescriptor() { diff --git a/verible/verilog/analysis/checkers/void-cast-rule.cc b/verible/verilog/analysis/checkers/void-cast-rule.cc index a7b61a59f..c2ad03ece 100644 --- a/verible/verilog/analysis/checkers/void-cast-rule.cc +++ b/verible/verilog/analysis/checkers/void-cast-rule.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/matcher/bound-symbol-manager.h" #include "verible/common/analysis/matcher/core-matchers.h" diff --git a/verible/verilog/analysis/dependencies.cc b/verible/verilog/analysis/dependencies.cc index ddd046e15..a142973b4 100644 --- a/verible/verilog/analysis/dependencies.cc +++ b/verible/verilog/analysis/dependencies.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/strings/display-utils.h" #include "verible/common/util/logging.h" #include "verible/verilog/analysis/symbol-table.h" @@ -36,7 +36,7 @@ static FileDependencies::symbol_index_type CreateSymbolMapFromSymbolTable( // Collect definers of root-level symbols. for (const SymbolTableNode::key_value_type &child : root) { - const absl::string_view symbol_name(child.first); + const std::string_view symbol_name(child.first); const VerilogSourceFile *file_origin = child.second.Value().file_origin; if (file_origin == nullptr) continue; @@ -55,7 +55,7 @@ static FileDependencies::symbol_index_type CreateSymbolMapFromSymbolTable( symbol_info.local_references_to_bind) { // Only look at the root reference node, which is unqualified. const ReferenceComponent &ref_comp(ref.components->Value()); - const absl::string_view ref_id(ref_comp.identifier); + const std::string_view ref_id(ref_comp.identifier); VLOG(2) << " referenced id: " << ref_id; const VerilogSourceFile *ref_file_origin = @@ -98,7 +98,7 @@ CreateFileDependenciesFromSymbolMap( VLOG(1) << __FUNCTION__; FileDependencies::file_deps_graph_type file_deps; for (const auto &symbol_entry : symbol_map) { - const absl::string_view symbol_name(symbol_entry.first); + const std::string_view symbol_name(symbol_entry.first); const FileDependencies::SymbolData &symbol_info(symbol_entry.second); const VerilogSourceFile *def = symbol_info.definer; // If no definition is found, then do not create any edges for it. diff --git a/verible/verilog/analysis/dependencies.h b/verible/verilog/analysis/dependencies.h index 02616e66c..e60c775d9 100644 --- a/verible/verilog/analysis/dependencies.h +++ b/verible/verilog/analysis/dependencies.h @@ -19,8 +19,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/strings/compare.h" #include "verible/verilog/analysis/symbol-table.h" #include "verible/verilog/analysis/verilog-project.h" @@ -41,7 +41,7 @@ struct FileDependencies { using node_type = const VerilogSourceFile *; // A set of strings, whose memory is owned outside of this data structure. - using SymbolNameSet = std::set; + using SymbolNameSet = std::set; // Sort by referenced file name. using FileCompare = VerilogSourceFile::Less; @@ -70,7 +70,7 @@ struct FileDependencies { // objects. Typically, this is owned by VerilogSourceFile inside // VerilogProject. using symbol_index_type = - std::map; + std::map; // === Fields (in order of initialization and computation) // All fields are const-initialized and public. diff --git a/verible/verilog/analysis/dependencies_test.cc b/verible/verilog/analysis/dependencies_test.cc index a9a8fd1ef..32207f0ad 100644 --- a/verible/verilog/analysis/dependencies_test.cc +++ b/verible/verilog/analysis/dependencies_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/util/file-util.h" @@ -66,7 +66,7 @@ TEST(FileDependenciesTest, OneFileNoDeps) { ASSERT_TRUE(CreateDir(sources_dir).ok()); // None of these test cases will yield any inter-file deps. - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { "", // one module "module mmm;\n" diff --git a/verible/verilog/analysis/descriptions.h b/verible/verilog/analysis/descriptions.h index 973e28a3f..b7b7905bc 100644 --- a/verible/verilog/analysis/descriptions.h +++ b/verible/verilog/analysis/descriptions.h @@ -20,25 +20,24 @@ #define VERIBLE_VERILOG_ANALYSIS_DESCRIPTIONS_H_ #include +#include #include -#include "absl/strings/string_view.h" - namespace verilog { namespace analysis { -using LintRuleId = absl::string_view; +using LintRuleId = std::string_view; struct LintConfigParameterDescriptor { - absl::string_view name; + std::string_view name; std::string default_value; std::string description; }; struct LintRuleDescriptor { - LintRuleId name; // ID/name of the rule. - absl::string_view topic; // section in style-guide - std::string desc; // Detailed description. + LintRuleId name; // ID/name of the rule. + std::string_view topic; // section in style-guide + std::string desc; // Detailed description. std::vector param; }; diff --git a/verible/verilog/analysis/extractors.cc b/verible/verilog/analysis/extractors.cc index 08b4c38d5..530f938f8 100644 --- a/verible/verilog/analysis/extractors.cc +++ b/verible/verilog/analysis/extractors.cc @@ -16,9 +16,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/text/tree-utils.h" #include "verible/common/util/logging.h" #include "verible/verilog/CST/identifier.h" @@ -31,7 +31,7 @@ namespace analysis { // Find all modules and collect interface names absl::Status CollectInterfaceNames( - absl::string_view content, std::set *if_names, + std::string_view content, std::set *if_names, const VerilogPreprocess::Config &preprocess_config) { VLOG(1) << __FUNCTION__; @@ -56,8 +56,8 @@ absl::Status CollectInterfaceNames( const auto if_leafs = FindAllSymbolIdentifierLeafs(*mod_header.match); for (const auto &if_leaf_match : if_leafs) { const auto &if_leaf = SymbolCastToLeaf(*if_leaf_match.match); - absl::string_view if_name = if_leaf.get().text(); - if_names->insert(std::string(if_name)); // TODO: use absl::string_view + std::string_view if_name = if_leaf.get().text(); + if_names->insert(std::string(if_name)); // TODO: use std::string_view } } return absl::OkStatus(); diff --git a/verible/verilog/analysis/extractors.h b/verible/verilog/analysis/extractors.h index f12812bda..bde2b60b9 100644 --- a/verible/verilog/analysis/extractors.h +++ b/verible/verilog/analysis/extractors.h @@ -21,9 +21,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/verilog/preprocessor/verilog-preprocess.h" namespace verilog { @@ -33,7 +33,7 @@ namespace analysis { // This could be useful when interface names are required to be // preserved. absl::Status CollectInterfaceNames( - absl::string_view content, std::set *if_names, + std::string_view content, std::set *if_names, const verilog::VerilogPreprocess::Config &preprocess_config); } // namespace analysis diff --git a/verible/verilog/analysis/extractors_test.cc b/verible/verilog/analysis/extractors_test.cc index f1bc7b566..acff74ec3 100644 --- a/verible/verilog/analysis/extractors_test.cc +++ b/verible/verilog/analysis/extractors_test.cc @@ -16,9 +16,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/verilog/preprocessor/verilog-preprocess.h" @@ -34,7 +34,7 @@ namespace { static constexpr VerilogPreprocess::Config kDefaultPreprocess; TEST(CollectInterfaceNamesTest, NonModuleTests) { - const std::pair> kTestCases[] = { + const std::pair> kTestCases[] = { {"", {}}, {"class cls;\nendclass", {}}, {"function f;\nendfunction", {}}, @@ -49,7 +49,7 @@ TEST(CollectInterfaceNamesTest, NonModuleTests) { } TEST(CollectInterfaceNamesTest, MinimalistModuleTests) { - const std::pair> kTestCases[] = { + const std::pair> kTestCases[] = { {"module mod;\nendmodule", {"mod"}}, {"module mod2(input foo);\nendmodule", {"mod2", "foo"}}, {"module top\nimport pkg::*;\n(input a);\nendmodule", @@ -67,7 +67,7 @@ TEST(CollectInterfaceNamesTest, MinimalistModuleTests) { // Tests that serveral instances with many identifiers are working as expected TEST(CollectInterfaceNamesTest, BiggerModuleTests) { - const std::pair> kTestCases[] = { + const std::pair> kTestCases[] = { {"interface TheBus(input clk);\n" " logic [7:0] addr, wdata, rdata;\n" " logic write_en;\n" diff --git a/verible/verilog/analysis/flow-tree.cc b/verible/verilog/analysis/flow-tree.cc index 60cb7bc5e..c5e2c23ba 100644 --- a/verible/verilog/analysis/flow-tree.cc +++ b/verible/verilog/analysis/flow-tree.cc @@ -18,7 +18,6 @@ #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/util/logging.h" #include "verible/verilog/parser/verilog-token-enum.h" diff --git a/verible/verilog/analysis/flow-tree.h b/verible/verilog/analysis/flow-tree.h index 49223ba3e..d099bae26 100644 --- a/verible/verilog/analysis/flow-tree.h +++ b/verible/verilog/analysis/flow-tree.h @@ -18,11 +18,11 @@ #include #include #include +#include #include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/text/token-stream-view.h" namespace verilog { @@ -147,7 +147,7 @@ class FlowTree { // Mapping each conditional macro to an integer ID, // to use it later as a bit offset. - std::map conditional_macro_id_; + std::map conditional_macro_id_; // A vector containing all the macros used placed by their given ID. std::vector conditional_macros_; diff --git a/verible/verilog/analysis/flow-tree_test.cc b/verible/verilog/analysis/flow-tree_test.cc index 4c43b6dc1..cdd1f4b30 100644 --- a/verible/verilog/analysis/flow-tree_test.cc +++ b/verible/verilog/analysis/flow-tree_test.cc @@ -14,10 +14,10 @@ #include "verible/verilog/analysis/flow-tree.h" +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/text/token-stream-view.h" @@ -29,7 +29,7 @@ namespace { using testing::StartsWith; // Lexes a SystemVerilog source code, and returns a TokenSequence. -verible::TokenSequence LexToSequence(absl::string_view source_contents) { +verible::TokenSequence LexToSequence(std::string_view source_contents) { verible::TokenSequence lexed_sequence; VerilogLexer lexer(source_contents); for (lexer.DoNextToken(); !lexer.GetLastToken().isEOF(); @@ -42,7 +42,7 @@ verible::TokenSequence LexToSequence(absl::string_view source_contents) { } TEST(FlowTree, MultipleConditionalsSameMacro) { - const absl::string_view test_case = + const std::string_view test_case = R"( `ifdef A A_TRUE_1 @@ -92,7 +92,7 @@ TEST(FlowTree, MultipleConditionalsSameMacro) { } TEST(FlowTree, UnmatchedElses) { - const absl::string_view test_cases[] = { + const std::string_view test_cases[] = { R"( `elsif A A_TRUE @@ -132,7 +132,7 @@ TEST(FlowTree, UnmatchedElses) { } TEST(FlowTree, UnvalidConditionals) { - const absl::string_view test_cases[] = { + const std::string_view test_cases[] = { R"( `ifdef A A_TRUE @@ -162,7 +162,7 @@ TEST(FlowTree, UnvalidConditionals) { } TEST(FlowTree, UncompletedConditionals) { - const absl::string_view test_cases[] = { + const std::string_view test_cases[] = { R"( `ifdef A A_TRUE @@ -189,7 +189,7 @@ TEST(FlowTree, UncompletedConditionals) { } TEST(FlowTree, NestedConditionals) { - const absl::string_view test_cases[] = { + const std::string_view test_cases[] = { R"( `ifdef A `ifdef B @@ -229,7 +229,7 @@ TEST(FlowTree, NestedConditionals) { } TEST(FlowTree, MultipleElseIfs) { - const absl::string_view test_case = + const std::string_view test_case = R"( `ifdef A A_TRUE @@ -275,7 +275,7 @@ TEST(FlowTree, MultipleElseIfs) { } TEST(FlowTree, SwappedNegatedIfs) { - const absl::string_view test_case = + const std::string_view test_case = R"( `ifndef A A_FALSE @@ -316,7 +316,7 @@ TEST(FlowTree, SwappedNegatedIfs) { } TEST(FlowTree, CompleteConditional) { - const absl::string_view test_case = + const std::string_view test_case = R"( `ifdef A A_TRUE diff --git a/verible/verilog/analysis/json-diagnostics.cc b/verible/verilog/analysis/json-diagnostics.cc index c137b8db9..3be0c8e14 100644 --- a/verible/verilog/analysis/json-diagnostics.cc +++ b/verible/verilog/analysis/json-diagnostics.cc @@ -16,9 +16,9 @@ #include #include +#include #include -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" #include "verible/common/analysis/file-analyzer.h" #include "verible/common/strings/line-column-map.h" @@ -60,7 +60,7 @@ json GetLinterTokenErrorsAsJson(const verilog::VerilogAnalyzer *analyzer, rejected_token, [&error](const std::string &filename, LineColumnRange range, ErrorSeverity severity, AnalysisPhase phase, - absl::string_view token_text, absl::string_view context_line, + std::string_view token_text, std::string_view context_line, const std::string &message) { // TODO: should this do something different for severity = kWarning ? error["line"] = range.start.line; // NB: zero based index diff --git a/verible/verilog/analysis/lint-rule-registry.h b/verible/verilog/analysis/lint-rule-registry.h index 8f818fd33..da082d3ba 100644 --- a/verible/verilog/analysis/lint-rule-registry.h +++ b/verible/verilog/analysis/lint-rule-registry.h @@ -77,7 +77,7 @@ using LintRuleDescriptionsMap = // class MyLintRule : LintRuleType { // public: // using rule_type = LintRuleType; -// static absl::string_view Name(); +// static std::string_view Name(); // static std::string GetDescription(DescriptionType); // ... implement internals ... // } @@ -90,7 +90,7 @@ using LintRuleDescriptionsMap = // initialization, when registration happens), and must be backed by string // memory with guaranteed lifetime. e.g. // -// absl::string_view MyLintRule::Name() { +// std::string_view MyLintRule::Name() { // return "my-lint-rule"; // safely initialized function-local string literal // } // diff --git a/verible/verilog/analysis/lint-rule-registry_test.cc b/verible/verilog/analysis/lint-rule-registry_test.cc index 543edd9c5..75fc130f4 100644 --- a/verible/verilog/analysis/lint-rule-registry_test.cc +++ b/verible/verilog/analysis/lint-rule-registry_test.cc @@ -16,11 +16,11 @@ #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/line-lint-rule.h" #include "verible/common/analysis/lint-rule-status.h" @@ -182,7 +182,7 @@ class LineRule1 : public LineLintRule { return d; } - void HandleLine(absl::string_view) final {} + void HandleLine(std::string_view) final {} verible::LintRuleStatus Report() const final { return verible::LintRuleStatus(); } @@ -231,7 +231,7 @@ class TextRule1 : public TextStructureLintRule { return d; } - void Lint(const verible::TextStructureView &, absl::string_view) final {} + void Lint(const verible::TextStructureView &, std::string_view) final {} verible::LintRuleStatus Report() const final { return verible::LintRuleStatus(); } diff --git a/verible/verilog/analysis/symbol-table.cc b/verible/verilog/analysis/symbol-table.cc index fcaad2570..32f095105 100644 --- a/verible/verilog/analysis/symbol-table.cc +++ b/verible/verilog/analysis/symbol-table.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,6 @@ #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "absl/time/clock.h" #include "absl/time/time.h" @@ -77,7 +77,7 @@ using verible::ValueSaver; // Returns string_view of `text` with outermost double-quotes removed. // If `text` is not wrapped in quotes, return it as-is. -static absl::string_view StripOuterQuotes(absl::string_view text) { +static std::string_view StripOuterQuotes(std::string_view text) { return absl::StripSuffix(absl::StripPrefix(text, "\""), "\""); } @@ -107,12 +107,12 @@ std::ostream &operator<<(std::ostream &stream, SymbolMetaType symbol_type) { return SymbolMetaTypeNames().Unparse(symbol_type, stream); } -absl::string_view SymbolMetaTypeAsString(SymbolMetaType type) { +std::string_view SymbolMetaTypeAsString(SymbolMetaType type) { return SymbolMetaTypeNames().EnumName(type); } // Root SymbolTableNode has no key, but we identify it as "$root" -static constexpr absl::string_view kRoot("$root"); +static constexpr std::string_view kRoot("$root"); std::ostream &SymbolTableNodeFullPath(std::ostream &stream, const SymbolTableNode &node) { @@ -170,8 +170,8 @@ static ReferenceComponentNode *CheckedNewChildReferenceNode( } static absl::Status DiagnoseMemberSymbolResolutionFailure( - absl::string_view name, const SymbolTableNode &context) { - const absl::string_view context_name = + std::string_view name, const SymbolTableNode &context) { + const std::string_view context_name = context.Parent() == nullptr ? kRoot : *context.Key(); return absl::NotFoundError( absl::StrCat("No member symbol \"", name, "\" in parent scope (", @@ -180,7 +180,7 @@ static absl::Status DiagnoseMemberSymbolResolutionFailure( } static const SymbolTableNode *LookupSymbolUpwards( - const SymbolTableNode &context, absl::string_view symbol); + const SymbolTableNode &context, std::string_view symbol); class SymbolTable::Builder : public TreeContextVisitor { public: @@ -497,7 +497,7 @@ class SymbolTable::Builder : public TreeContextVisitor { CHECK(struct_type.MatchesTag(NodeEnum::kStructType)); // Structs do not inherently have names, so they are all anonymous. // Type declarations (typedefs) create named alias elsewhere. - const absl::string_view anon_name = + const std::string_view anon_name = current_scope_->Value().CreateAnonymousScope("struct"); SymbolTableNode *new_struct = DeclareScopedElementAndDescend( struct_type, anon_name, SymbolMetaType::kStruct); @@ -522,7 +522,7 @@ class SymbolTable::Builder : public TreeContextVisitor { void DescendEnumType(const SyntaxTreeNode &enum_type) { CHECK(enum_type.MatchesTag(NodeEnum::kEnumType)); - const absl::string_view anon_name = + const std::string_view anon_name = current_scope_->Value().CreateAnonymousScope("enum"); SymbolTableNode *new_enum = DeclareScopedElementAndDescend( enum_type, anon_name, SymbolMetaType::kEnumType); @@ -611,7 +611,7 @@ class SymbolTable::Builder : public TreeContextVisitor { } void HandleIdentifier(const SyntaxTreeLeaf &leaf) { - const absl::string_view text = leaf.get().text(); + const std::string_view text = leaf.get().text(); VLOG(2) << __FUNCTION__ << ": " << text; VLOG(2) << "current context: " << CurrentScopeFullPath(); if (Context().DirectParentIs(NodeEnum::kParamType)) { @@ -1016,7 +1016,7 @@ class SymbolTable::Builder : public TreeContextVisitor { // Suitable for SystemVerilog language elements: functions, tasks, packages, // classes, modules, etc... SymbolTableNode *EmplaceElementInCurrentScope(const verible::Symbol &element, - absl::string_view name, + std::string_view name, SymbolMetaType metatype) { const auto [kv, did_emplace] = current_scope_->TryEmplace( name, SymbolInfo{metatype, source_, &element}); @@ -1141,7 +1141,7 @@ class SymbolTable::Builder : public TreeContextVisitor { // Checks potential multiline declaration of port // against correctness void CheckMultilinePortDeclarationCorrectness(SymbolTableNode *existing_node, - absl::string_view name) { + std::string_view name) { DeclarationTypeInfo &new_decl_info = *ABSL_DIE_IF_NULL(declaration_type_info_); DeclarationTypeInfo &old_decl_info = existing_node->Value().declared_type; @@ -1176,7 +1176,7 @@ class SymbolTable::Builder : public TreeContextVisitor { // Suitable for SystemVerilog language elements: nets, parameter, variables, // instances, functions (using their return types). SymbolTableNode &EmplaceTypedElementInCurrentScope( - const verible::Symbol &element, absl::string_view name, + const verible::Symbol &element, std::string_view name, SymbolMetaType metatype) { VLOG(2) << __FUNCTION__ << ": " << name << " in " << CurrentScopeFullPath(); VLOG(3) << " type info: " << *ABSL_DIE_IF_NULL(declaration_type_info_); @@ -1202,7 +1202,7 @@ class SymbolTable::Builder : public TreeContextVisitor { // Suitable for SystemVerilog module port declarations, where // there are multiple lines defining the symbol. SymbolTableNode &EmplacePortIdentifierInCurrentScope( - const verible::Symbol &element, absl::string_view name, + const verible::Symbol &element, std::string_view name, SymbolMetaType metatype) { VLOG(2) << __FUNCTION__ << ": " << name << " in " << CurrentScopeFullPath(); VLOG(3) << " type info: " << *ABSL_DIE_IF_NULL(declaration_type_info_); @@ -1226,7 +1226,7 @@ class SymbolTable::Builder : public TreeContextVisitor { // inside the new element's scope. // Returns the new scope. SymbolTableNode *DeclareScopedElementAndDescend(const SyntaxTreeNode &element, - absl::string_view name, + std::string_view name, SymbolMetaType type) { SymbolTableNode *enter_scope = EmplaceElementInCurrentScope(element, name, type); @@ -1241,7 +1241,7 @@ class SymbolTable::Builder : public TreeContextVisitor { SymbolMetaType::kModule); } - absl::string_view GetScopeNameFromGenerateBody(const SyntaxTreeNode &body) { + std::string_view GetScopeNameFromGenerateBody(const SyntaxTreeNode &body) { if (body.MatchesTag(NodeEnum::kGenerateBlock)) { const SyntaxTreeNode *gen_block = GetGenerateBlockBegin(body); const TokenInfo *label = @@ -1437,7 +1437,7 @@ class SymbolTable::Builder : public TreeContextVisitor { const verible::TokenInfo *instance_name_token = GetModuleInstanceNameTokenInfoFromGateInstance(instance); if (!instance_name_token) return; - const absl::string_view instance_name(instance_name_token->text()); + const std::string_view instance_name(instance_name_token->text()); const SymbolTableNode &new_instance(EmplaceTypedElementInCurrentScope( instance, instance_name, SymbolMetaType::kDataNetVariableInstance)); @@ -1467,7 +1467,7 @@ class SymbolTable::Builder : public TreeContextVisitor { const SyntaxTreeLeaf *net_variable_name = GetNameLeafOfNetVariable(net_variable); if (!net_variable_name) return; - const absl::string_view net_name(net_variable_name->get().text()); + const std::string_view net_name(net_variable_name->get().text()); EmplaceTypedElementInCurrentScope(net_variable, net_name, SymbolMetaType::kDataNetVariableInstance); Descend(net_variable); @@ -1477,7 +1477,7 @@ class SymbolTable::Builder : public TreeContextVisitor { const SyntaxTreeLeaf *register_variable_name = GetNameLeafOfRegisterVariable(reg_variable); if (!register_variable_name) return; - const absl::string_view net_name(register_variable_name->get().text()); + const std::string_view net_name(register_variable_name->get().text()); EmplaceTypedElementInCurrentScope(reg_variable, net_name, SymbolMetaType::kDataNetVariableInstance); Descend(reg_variable); @@ -1487,14 +1487,14 @@ class SymbolTable::Builder : public TreeContextVisitor { const SyntaxTreeLeaf *unqualified_id = GetUnqualifiedIdFromVariableDeclarationAssignment(variable); if (unqualified_id) { - const absl::string_view var_name(unqualified_id->get().text()); + const std::string_view var_name(unqualified_id->get().text()); EmplaceTypedElementInCurrentScope( variable, var_name, SymbolMetaType::kDataNetVariableInstance); } Descend(variable); } - void DiagnoseSymbolAlreadyExists(absl::string_view name, + void DiagnoseSymbolAlreadyExists(std::string_view name, const SymbolTableNode &previous_symbol) { std::ostringstream here_print; here_print << source_->GetTextStructure()->GetRangeForText(name); @@ -1536,7 +1536,7 @@ class SymbolTable::Builder : public TreeContextVisitor { // Lookup inner symbol in outer_scope, but also allow injection of the // inner symbol name into the outer_scope (with diagnostic). ReferenceComponent &inner_ref = ref.components->Children().front().Value(); - const absl::string_view inner_key = inner_ref.identifier; + const std::string_view inner_key = inner_ref.identifier; const auto p = outer_scope->TryEmplace( inner_key, SymbolInfo{metatype, source_, definition_syntax}); @@ -1617,10 +1617,10 @@ class SymbolTable::Builder : public TreeContextVisitor { GetFileFromPreprocessorInclude(preprocessor_include); if (included_filename == nullptr) return; - const absl::string_view filename_text = included_filename->get().text(); + const std::string_view filename_text = included_filename->get().text(); // Remove the double quotes from the filename. - const absl::string_view filename_unquoted = StripOuterQuotes(filename_text); + const std::string_view filename_unquoted = StripOuterQuotes(filename_text); VLOG(3) << "got: `include \"" << filename_unquoted << "\""; // Opening included file requires a VerilogProject. @@ -1876,7 +1876,7 @@ static const SymbolTableNode *CanonicalizeTypeForMemberLookup( // Search through base class's scopes for a symbol. static const SymbolTableNode *LookupSymbolThroughInheritedScopes( - const SymbolTableNode &context, absl::string_view symbol) { + const SymbolTableNode &context, std::string_view symbol) { const SymbolTableNode *current_context = &context; do { // Look directly in current scope. @@ -1904,7 +1904,7 @@ static const SymbolTableNode *LookupSymbolThroughInheritedScopes( // Search up-scope, stopping at the first symbol found in the nearest scope. static const SymbolTableNode *LookupSymbolUpwards( - const SymbolTableNode &context, absl::string_view symbol) { + const SymbolTableNode &context, std::string_view symbol) { const SymbolTableNode *current_context = &context; do { const SymbolTableNode *found = @@ -1918,7 +1918,7 @@ static const SymbolTableNode *LookupSymbolUpwards( } static absl::Status DiagnoseUnqualifiedSymbolResolutionFailure( - absl::string_view name, const SymbolTableNode &context) { + std::string_view name, const SymbolTableNode &context) { return absl::NotFoundError(absl::StrCat("Unable to resolve symbol \"", name, "\" from context ", ContextFullPath(context), ".")); @@ -1930,7 +1930,7 @@ static void ResolveReferenceComponentNodeLocal(ReferenceComponentNode *node, VLOG(2) << __FUNCTION__ << ": " << component; // If already resolved, skip. if (component.resolved_symbol != nullptr) return; // already bound - const absl::string_view key(component.identifier); + const std::string_view key(component.identifier); CHECK(node->Parent() == nullptr); // is root // root node: lookup this symbol from its context upward CHECK_EQ(component.ref_type, ReferenceType::kUnqualified); @@ -1947,7 +1947,7 @@ static void ResolveUnqualifiedName(ReferenceComponent *component, const SymbolTableNode &context, std::vector *diagnostics) { VLOG(2) << __FUNCTION__ << ": " << component; - const absl::string_view key(component->identifier); + const std::string_view key(component->identifier); // Find the first symbol whose name matches, without regard to its metatype. const SymbolTableNode *resolved = LookupSymbolUpwards(context, key); if (resolved == nullptr) { @@ -1969,7 +1969,7 @@ static void ResolveImmediateMember(ReferenceComponent *component, const SymbolTableNode &context, std::vector *diagnostics) { VLOG(2) << __FUNCTION__ << ": " << component; - const absl::string_view key(component->identifier); + const std::string_view key(component->identifier); const auto found = context.Find(key); if (found == context.end()) { diagnostics->emplace_back( @@ -2001,7 +2001,7 @@ static void ResolveDirectMember(ReferenceComponent *component, return; } - const absl::string_view key(component->identifier); + const std::string_view key(component->identifier); const auto *found = LookupSymbolThroughInheritedScopes(*canonical_context, key); if (found == nullptr) { @@ -2137,7 +2137,7 @@ absl::StatusOr DependentReferences::ResolveOnlyBaseLocally( CHECK(base.ref_type == ReferenceType::kUnqualified || base.ref_type == ReferenceType::kImmediate) << "Inconsistent reference type: " << base.ref_type; - const absl::string_view key(base.identifier); + const std::string_view key(base.identifier); const auto found = context->Find(key); if (found == context->end()) { return DiagnoseMemberSymbolResolutionFailure(key, *context); @@ -2193,7 +2193,7 @@ void DeclarationTypeInfo::VerifySymbolTableRoot( } } -absl::string_view SymbolInfo::CreateAnonymousScope(absl::string_view base) { +std::string_view SymbolInfo::CreateAnonymousScope(std::string_view base) { const size_t n = anonymous_scope_names.size(); anonymous_scope_names.emplace_back(std::make_unique( // Starting with a non-alpha character guarantees it cannot collide with @@ -2357,7 +2357,7 @@ void SymbolTable::Build(std::vector *diagnostics) { } void SymbolTable::BuildSingleTranslationUnit( - absl::string_view referenced_file_name, + std::string_view referenced_file_name, std::vector *diagnostics) { const auto translation_unit_or_status = project_->OpenTranslationUnit(referenced_file_name); diff --git a/verible/verilog/analysis/symbol-table.h b/verible/verilog/analysis/symbol-table.h index 09862b8a0..6632b81fb 100644 --- a/verible/verilog/analysis/symbol-table.h +++ b/verible/verilog/analysis/symbol-table.h @@ -22,12 +22,12 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/compare.h" #include "verible/common/text/symbol.h" #include "verible/common/util/map-tree.h" @@ -44,7 +44,7 @@ struct SymbolInfo; // forward declaration, defined below // substring owned by a VerilogSourceFile (which must outlive the symbol table), // and can be used to look up file origin and position within file. using SymbolTableNode = - verible::MapTree; + verible::MapTree; std::ostream &SymbolTableNodeFullPath(std::ostream &, const SymbolTableNode &); @@ -74,7 +74,7 @@ enum class SymbolMetaType { std::ostream &operator<<(std::ostream &, SymbolMetaType); -absl::string_view SymbolMetaTypeAsString(SymbolMetaType type); +std::string_view SymbolMetaTypeAsString(SymbolMetaType type); // This classifies the type of reference that a single identifier is. enum class ReferenceType { @@ -118,7 +118,7 @@ struct ReferenceComponent { // locate the originating VerilogSourceFile via // VerilogProject::LookupFileOrigin() and in-file position from the file's // LineColumnMap. - const absl::string_view identifier; + const std::string_view identifier; // What kind of reference is this, and how should it be resolved? // See enum definition above. @@ -175,7 +175,7 @@ std::ostream &ReferenceNodeFullPath(std::ostream &, // arbitrarily chosen to be included in the map, while the others are dropped. // Primarily for debugging and visualization. using ReferenceComponentMap = - std::map; ReferenceComponentMap ReferenceComponentNodeMapView( const ReferenceComponentNode &); @@ -241,7 +241,7 @@ struct DeclarationTypeInfo { const verible::Symbol *syntax_origin = nullptr; // holds optional string_view describing direction of the port - absl::string_view direction; + std::string_view direction; // holds additional type specifications, used mostly in multiline definitions // of ports @@ -300,7 +300,7 @@ struct SymbolInfo { // TODO (glatosinski): I guess we should include more information here rather // than just string_view pointing to the symbol, or add string_view pointing // to the symbol in the Symbol class - std::vector supplement_definitions; + std::vector supplement_definitions; // bool telling if the given symbol is a port identifier bool is_port_identifier = false; @@ -365,7 +365,7 @@ struct SymbolInfo { // Generate a scope name whose string memory lives and moves with this object. // 'base' is used as part of the generated name. - absl::string_view CreateAnonymousScope(absl::string_view base); + std::string_view CreateAnonymousScope(std::string_view base); // Attempt to resolve all symbol references. void Resolve(const SymbolTableNode &context, @@ -387,14 +387,14 @@ struct SymbolInfo { struct StringAddressCompare { using is_transparent = void; // heterogeneous lookup - static absl::string_view ToString(absl::string_view s) { return s; } - static absl::string_view ToString(const DependentReferences *ref) { + static std::string_view ToString(std::string_view s) { return s; } + static std::string_view ToString(const DependentReferences *ref) { return ref->components->Value().identifier; } template bool operator()(L l, R r) const { - static constexpr std::less + static constexpr std::less compare_address; return compare_address(ToString(l).begin(), ToString(r).begin()); } @@ -404,7 +404,7 @@ struct SymbolInfo { std::set; using references_map_view_type = - std::map; // For testing only, quickly find reference candidates by name, and positional @@ -422,7 +422,7 @@ struct SymbolInfo { // TODO(fangism): This should come from a preprocessor and possibly maintained // per translation-unit in multi-file compilation mode. using MacroSymbolMap = - std::map; + std::map; // SymbolTable maintains a named hierarchy of named symbols and scopes for // SystemVerilog. This can be built up separately per translation unit, @@ -474,7 +474,7 @@ class SymbolTable { // It is safe to build the same unit multiple times, subsequent invocations // will not change the symbol table structure, but will give duplicate symbol // diagnostics. - void BuildSingleTranslationUnit(absl::string_view referenced_file_name, + void BuildSingleTranslationUnit(std::string_view referenced_file_name, std::vector *diagnostics); // Construct symbol table definitions and references hierarchically, but do diff --git a/verible/verilog/analysis/symbol-table_test.cc b/verible/verilog/analysis/symbol-table_test.cc index e8f7e1f47..21ef001eb 100644 --- a/verible/verilog/analysis/symbol-table_test.cc +++ b/verible/verilog/analysis/symbol-table_test.cc @@ -20,11 +20,11 @@ #include #include #include +#include #include #include "absl/base/attributes.h" #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/text/tree-utils.h" @@ -92,7 +92,7 @@ static std::ostream &operator<<(std::ostream &stream, const auto &dest(*container.begin()); // Shorthand for asserting that a symbol table lookup from -// (const SymbolTableNode& scope) using (absl::string_view key) must succeed, +// (const SymbolTableNode& scope) using (std::string_view key) must succeed, // and is captured as (const SymbolTableNode& dest). // Most of the time, the tester is not interested in the found_* iterator. // This also defines 'dest##_info' as the SymbolInfo value attached to the @@ -432,7 +432,7 @@ TEST(BuildSymbolTableTest, IntegrityCheckDeclaredType) { } TEST(BuildSymbolTableTest, InvalidSyntax) { - constexpr absl::string_view invalid_codes[] = { + constexpr std::string_view invalid_codes[] = { "module;\nendmodule\n", }; for (const auto &code : invalid_codes) { @@ -458,7 +458,7 @@ TEST(BuildSymbolTableTest, InvalidSyntax) { TEST(BuildSymbolTableTest, AvoidCrashFromFuzzer) { // All that matters is that these test cases do not trigger crashes. - constexpr absl::string_view codes[] = { + constexpr std::string_view codes[] = { // some of these test cases come from fuzz testing // and may contain syntax errors "`e(C*C);\n", // expect two distinct reference trees @@ -527,7 +527,7 @@ TEST(BuildSymbolTableTest, ModuleDeclarationLocalNetsVariables) { nullptr); // there is no module meta-type EXPECT_EMPTY_STATUSES(build_diagnostics); - static constexpr absl::string_view members[] = {"w1", "w2", "l1", "l2"}; + static constexpr std::string_view members[] = {"w1", "w2", "l1", "l2"}; for (const auto &member : members) { MUST_ASSIGN_LOOKUP_SYMBOL(member_node, module_node, member); EXPECT_EQ(member_node_info.metatype, @@ -575,7 +575,7 @@ TEST(BuildSymbolTableTest, ModuleDeclarationLocalDuplicateNets) { } TEST(BuildSymbolTableTest, ModuleDeclarationConditionalGenerateAnonymous) { - constexpr absl::string_view source_variants[] = { + constexpr std::string_view source_variants[] = { // with begin/end "module m;\n" " if (1) begin\n" @@ -720,7 +720,7 @@ TEST(BuildSymbolTableTest, ModuleDeclarationWithPorts) { EXPECT_EQ(module_node_info.declared_type.syntax_origin, nullptr); // there is no module meta-type - static constexpr absl::string_view members[] = {"clk", "q"}; + static constexpr std::string_view members[] = {"clk", "q"}; for (const auto &member : members) { MUST_ASSIGN_LOOKUP_SYMBOL(member_node, module_node, member); EXPECT_EQ(member_node_info.metatype, @@ -748,7 +748,7 @@ TEST(BuildSymbolTableTest, ModuleDeclarationMultiple) { const auto build_diagnostics = BuildSymbolTable(src, &symbol_table); EXPECT_EMPTY_STATUSES(build_diagnostics); - const absl::string_view expected_modules[] = {"m1", "m2"}; + const std::string_view expected_modules[] = {"m1", "m2"}; for (const auto &expected_module : expected_modules) { MUST_ASSIGN_LOOKUP_SYMBOL(module_node, root_symbol, expected_module); EXPECT_EQ(module_node_info.metatype, SymbolMetaType::kModule); @@ -888,7 +888,7 @@ TEST(BuildSymbolTableTest, ModuleDeclarationNestedDuplicate) { TEST(BuildSymbolTableTest, ModuleInstance) { // The following code variants should yield the same symbol table results: - static constexpr absl::string_view source_variants[] = { + static constexpr std::string_view source_variants[] = { // pp defined earlier in file "module pp;\n" "endmodule\n" @@ -1033,7 +1033,7 @@ TEST(BuildSymbolTableTest, ModuleInstanceUndefined) { } TEST(BuildSymbolTableTest, ModuleInstanceTwoInSameDecl) { - static constexpr absl::string_view source_variants[] = { + static constexpr std::string_view source_variants[] = { // The following all yield equivalent symbol tables bindings. "module pp;\n" "endmodule\n" @@ -1090,7 +1090,7 @@ TEST(BuildSymbolTableTest, ModuleInstanceTwoInSameDecl) { } // "r1" and "r2" are both instances of type "pp" - static constexpr absl::string_view pp_instances[] = {"r1", "r2"}; + static constexpr std::string_view pp_instances[] = {"r1", "r2"}; for (const auto &pp_inst : pp_instances) { MUST_ASSIGN_LOOKUP_SYMBOL(rr, qq, pp_inst); EXPECT_TRUE(rr_info.local_references_to_bind.empty()); @@ -8107,7 +8107,7 @@ TEST(BuildSymbolTableTest, ModuleInstancesFromProjectOneFileAtATime) { VerilogProject project(sources_dir, {/* no include path */}); // Linear dependency chain between 3 files. Order arbitrarily chosen. - constexpr absl::string_view // + constexpr std::string_view // text1( "module ss;\n" " qq qq_inst();\n" // instance @@ -8263,7 +8263,7 @@ TEST(BuildSymbolTableTest, ModuleInstancesFromProjectFilesGood) { VerilogProject project(sources_dir, {/* no include path */}); // Linear dependency chain between 3 files. Order arbitrarily chosen. - constexpr absl::string_view // + constexpr std::string_view // text1( "module ss;\n" " qq qq_inst();\n" // instance @@ -9270,7 +9270,7 @@ TEST(BuildSymbolTableTest, InterfaceDeclarationLocalNetsVariables) { nullptr); // there is no interface meta-type EXPECT_EMPTY_STATUSES(build_diagnostics); - static constexpr absl::string_view members[] = {"l1", "l2"}; + static constexpr std::string_view members[] = {"l1", "l2"}; for (const auto &member : members) { MUST_ASSIGN_LOOKUP_SYMBOL(member_node, interface_node, member); EXPECT_EQ(member_node_info.metatype, @@ -9315,7 +9315,7 @@ TEST(BuildSymbolTableTest, InterfaceDeclarationWithPorts) { EXPECT_EQ(interface_node_info.declared_type.syntax_origin, nullptr); // there is no interface meta-type - static constexpr absl::string_view members[] = {"clk", "reset", "d", "q"}; + static constexpr std::string_view members[] = {"clk", "reset", "d", "q"}; for (const auto &member : members) { MUST_ASSIGN_LOOKUP_SYMBOL(member_node, interface_node, member); EXPECT_EQ(member_node_info.metatype, @@ -9343,7 +9343,7 @@ TEST(BuildSymbolTableTest, InterfaceDeclarationMultiple) { const auto build_diagnostics = BuildSymbolTable(src, &symbol_table); EXPECT_EMPTY_STATUSES(build_diagnostics); - const absl::string_view expected_interfaces[] = {"foobar1_if", "foobar2_if"}; + const std::string_view expected_interfaces[] = {"foobar1_if", "foobar2_if"}; for (const auto &expected_interface : expected_interfaces) { MUST_ASSIGN_LOOKUP_SYMBOL(interface_node, root_symbol, expected_interface); EXPECT_EQ(interface_node_info.metatype, SymbolMetaType::kInterface); @@ -9422,8 +9422,8 @@ TEST(BuildSymbolTableTest, InterfaceDeclarationDuplicateSeparateFiles) { } struct FileListTestCase { - absl::string_view contents; - std::vector expected_files; + std::string_view contents; + std::vector expected_files; }; TEST(ParseSourceFileListFromFileTest, FileNotFound) { diff --git a/verible/verilog/analysis/verilog-analyzer.cc b/verible/verilog/analysis/verilog-analyzer.cc index 95a638746..54d26b100 100644 --- a/verible/verilog/analysis/verilog-analyzer.cc +++ b/verible/verilog/analysis/verilog-analyzer.cc @@ -19,13 +19,13 @@ #include #include +#include #include #include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/file-analyzer.h" #include "verible/common/lexer/token-stream-adapter.h" #include "verible/common/strings/comment-utils.h" @@ -63,14 +63,14 @@ absl::Status VerilogAnalyzer::Tokenize() { return lex_status_; } -absl::string_view VerilogAnalyzer::ScanParsingModeDirective( +std::string_view VerilogAnalyzer::ScanParsingModeDirective( const TokenSequence &raw_tokens) { for (const auto &token : raw_tokens) { const auto vtoken_enum = verilog_tokentype(token.token_enum()); if (IsComment(vtoken_enum)) { - const absl::string_view comment_text = + const std::string_view comment_text = verible::StripCommentAndSpacePadding(token.text()); - const std::vector comment_tokens = + const std::vector comment_tokens = absl::StrSplit(comment_text, ' ', absl::SkipEmpty()); if (comment_tokens.size() >= 2 && comment_tokens[0] == kParseDirectiveName) { @@ -89,7 +89,7 @@ absl::string_view VerilogAnalyzer::ScanParsingModeDirective( // Return a secondary parsing mode to attempt, depending on the token type of // the first rejected token from parsing as top-level. -static absl::string_view FailingTokenKeywordToParsingMode( +static std::string_view FailingTokenKeywordToParsingMode( verilog_tokentype token_type) { switch (token_type) { // For starting keywords that uniquely identify a parsing context, @@ -127,17 +127,17 @@ static absl::string_view FailingTokenKeywordToParsingMode( } std::unique_ptr VerilogAnalyzer::AnalyzeAutomaticMode( - const std::shared_ptr &text, absl::string_view name, + const std::shared_ptr &text, std::string_view name, const VerilogPreprocess::Config &preprocess_config) { VLOG(2) << __FUNCTION__; auto analyzer = std::make_unique(text, name, preprocess_config); if (analyzer == nullptr) return analyzer; - const absl::string_view text_base = analyzer->Data().Contents(); + const std::string_view text_base = analyzer->Data().Contents(); // If there is any lexical error, stop right away. const auto lex_status = analyzer->Tokenize(); if (!lex_status.ok()) return analyzer; - const absl::string_view parse_mode = + const std::string_view parse_mode = ScanParsingModeDirective(analyzer->Data().TokenStream()); if (!parse_mode.empty()) { // Invoke alternate parser, and use its results. @@ -161,14 +161,14 @@ std::unique_ptr VerilogAnalyzer::AnalyzeAutomaticMode( const auto &rejected_tokens = analyzer->GetRejectedTokens(); if (!rejected_tokens.empty()) { const auto &first_reject = rejected_tokens.front(); - const absl::string_view retry_parse_mode = + const std::string_view retry_parse_mode = FailingTokenKeywordToParsingMode( verilog_tokentype(first_reject.token_info.token_enum())); VLOG(1) << "Retrying parsing in mode: \"" << retry_parse_mode << "\"."; if (!retry_parse_mode.empty()) { auto retry_analyzer = AnalyzeVerilogWithMode( text->AsStringView(), name, retry_parse_mode, preprocess_config); - const absl::string_view retry_text_base = + const std::string_view retry_text_base = retry_analyzer->Data().Contents(); VLOG(1) << "Retrying to parse:\n" << retry_text_base; if (retry_analyzer->ParseStatus().ok()) { @@ -202,15 +202,15 @@ std::unique_ptr VerilogAnalyzer::AnalyzeAutomaticMode( } std::unique_ptr VerilogAnalyzer::AnalyzeAutomaticMode( - absl::string_view text, absl::string_view name, + std::string_view text, std::string_view name, const VerilogPreprocess::Config &preprocess_config) { return AnalyzeAutomaticMode(std::make_shared(text), name, preprocess_config); } std::unique_ptr -VerilogAnalyzer::AnalyzeAutomaticPreprocessFallback(absl::string_view text, - absl::string_view name) { +VerilogAnalyzer::AnalyzeAutomaticPreprocessFallback(std::string_view text, + std::string_view name) { std::unique_ptr parser; for (bool preprocess_expand_macros : {false, true}) { bool expand_macro_status = false; @@ -312,7 +312,7 @@ using verible::TokenInfo; // Helper class to replace macro call argument nodes with expression trees. class MacroCallArgExpander : public MutableTreeVisitorRecursive { public: - MacroCallArgExpander(absl::string_view outer_filename, absl::string_view text, + MacroCallArgExpander(std::string_view outer_filename, std::string_view text, const VerilogPreprocess::Config &pre_config) : outer_filename_(outer_filename), full_text_(text), @@ -392,10 +392,10 @@ class MacroCallArgExpander : public MutableTreeVisitorRecursive { TextStructureView::NodeExpansionMap subtrees_to_splice_; // Filename we're processing. Purely FYI. - const absl::string_view outer_filename_; + const std::string_view outer_filename_; // Full text from which tokens were lexed, for calculating byte offsets. - const absl::string_view full_text_; + const std::string_view full_text_; const VerilogPreprocess::Config &preprocess_config_; }; diff --git a/verible/verilog/analysis/verilog-analyzer.h b/verible/verilog/analysis/verilog-analyzer.h index f64d04a60..9ee8778f1 100644 --- a/verible/verilog/analysis/verilog-analyzer.h +++ b/verible/verilog/analysis/verilog-analyzer.h @@ -17,10 +17,10 @@ #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/file-analyzer.h" #include "verible/common/strings/mem-block.h" #include "verible/common/text/token-stream-view.h" @@ -32,20 +32,20 @@ namespace verilog { class VerilogAnalyzer : public verible::FileAnalyzer { public: VerilogAnalyzer(std::shared_ptr text, - absl::string_view name, + std::string_view name, const VerilogPreprocess::Config &preprocess_config) : verible::FileAnalyzer(std::move(text), name), preprocess_config_(preprocess_config) {} // Legacy constructor. - VerilogAnalyzer(absl::string_view text, absl::string_view name, + VerilogAnalyzer(std::string_view text, std::string_view name, const VerilogPreprocess::Config &preprocess_config) : verible::FileAnalyzer(text, name), preprocess_config_(preprocess_config) {} // Legacy constructor. // TODO(hzeller): Remove once every instantiation sets preprocessor config. - VerilogAnalyzer(absl::string_view text, absl::string_view name) + VerilogAnalyzer(std::string_view text, std::string_view name) : VerilogAnalyzer(text, name, VerilogPreprocess::Config()) {} VerilogAnalyzer(const VerilogAnalyzer &) = delete; @@ -72,11 +72,11 @@ class VerilogAnalyzer : public verible::FileAnalyzer { // Automatically analyze with the correct parsing mode, as detected // by parser directive comments. static std::unique_ptr AnalyzeAutomaticMode( - const std::shared_ptr &text, absl::string_view name, + const std::shared_ptr &text, std::string_view name, const VerilogPreprocess::Config &preprocess_config); static std::unique_ptr AnalyzeAutomaticMode( - absl::string_view text, absl::string_view name, + std::string_view text, std::string_view name, const VerilogPreprocess::Config &preprocess_config); // Automatically analyze with correct parsing mode like AnalyzeAutomaticMode() @@ -84,7 +84,7 @@ class VerilogAnalyzer : public verible::FileAnalyzer { // possible parse tree; if this yields to syntax errors, fall back to // enabling preprocess branches. static std::unique_ptr AnalyzeAutomaticPreprocessFallback( - absl::string_view text, absl::string_view name); + std::string_view text, std::string_view name); const VerilogPreprocessData &PreprocessorData() const { return preprocessor_data_; @@ -102,11 +102,11 @@ class VerilogAnalyzer : public verible::FileAnalyzer { // Returns a string that is first argument of the directive, e.g.: // // verilog_syntax: mode-x // results in "mode-x". - static absl::string_view ScanParsingModeDirective( + static std::string_view ScanParsingModeDirective( const verible::TokenSequence &raw_tokens); // Special string inside a comment that triggers setting parsing mode. - static constexpr absl::string_view kParseDirectiveName = "verilog_syntax:"; + static constexpr std::string_view kParseDirectiveName = "verilog_syntax:"; private: // Attempt to parse all macro arguments as expressions. Where parsing as an diff --git a/verible/verilog/analysis/verilog-analyzer_test.cc b/verible/verilog/analysis/verilog-analyzer_test.cc index cf8bf5c7a..0f0ef49f9 100644 --- a/verible/verilog/analysis/verilog-analyzer_test.cc +++ b/verible/verilog/analysis/verilog-analyzer_test.cc @@ -16,12 +16,12 @@ #include #include +#include #include #include #include "absl/status/status.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/analysis/file-analyzer.h" @@ -70,7 +70,7 @@ bool TreeContainsToken(const ConcreteSyntaxTree &tree, const TokenInfo &token) { } void DiagnosticMessagesContainFilename(const VerilogAnalyzer &analyzer, - absl::string_view filename, + std::string_view filename, bool with_diagnostic_context) { const std::vector syntax_error_messages( analyzer.LinterTokenErrorMessages(with_diagnostic_context)); @@ -446,7 +446,7 @@ TEST(AnalyzeVerilogAutomaticMode, ModuleBodyMode) { } TEST(AnalyzeVerilogAutomaticMode, ModuleBodyModeSyntaxError) { - const absl::string_view filename = "wirefile.sv"; + const std::string_view filename = "wirefile.sv"; std::unique_ptr analyzer_ptr = VerilogAnalyzer::AnalyzeAutomaticMode( "// verilog_syntax: parse-as-module-body\n" @@ -512,7 +512,7 @@ TEST(AnalyzeVerilogAutomaticMode, AutomaticWithFallback) { }; // Test cases that are known to syntax error without branch filter enabled. - constexpr absl::string_view test_cases[] = { + constexpr std::string_view test_cases[] = { R"( module foo(); always @(*) begin @@ -524,7 +524,7 @@ module foo(); end endmodule )"}; - for (const absl::string_view code : test_cases) { + for (const std::string_view code : test_cases) { const auto should_fail = VerilogAnalyzer::AnalyzeAutomaticMode(code, "", kNoBranchFilter); const auto should_succeed = VerilogAnalyzer::AnalyzeAutomaticMode( @@ -857,7 +857,7 @@ class VerilogAnalyzerInternalsTest : public testing::Test, // Tests that parser-selection directive is properly detected. TEST_F(VerilogAnalyzerInternalsTest, ScanParsingModeDirective) { - const std::pair test_cases[] = { + const std::pair test_cases[] = { // code, expected parsing mode {"", ""}, {"\n", ""}, @@ -908,7 +908,7 @@ TEST_F(VerilogAnalyzerInternalsTest, ScanParsingModeDirective) { VerilogAnalyzer analyzer(test.first, "", kDefaultPreprocess); const auto lexer_status = analyzer.Tokenize(); EXPECT_OK(lexer_status); - absl::string_view mode = + std::string_view mode = ScanParsingModeDirective(analyzer.Data().TokenStream()); EXPECT_EQ(mode, test.second) << " mismatched mode with input:\n" << test.first; diff --git a/verible/verilog/analysis/verilog-equivalence.cc b/verible/verilog/analysis/verilog-equivalence.cc index 67d9a5053..f8a47d066 100644 --- a/verible/verilog/analysis/verilog-equivalence.cc +++ b/verible/verilog/analysis/verilog-equivalence.cc @@ -22,8 +22,8 @@ #include #include #include +#include -#include "absl/strings/string_view.h" #include "verible/common/lexer/token-stream-adapter.h" #include "verible/common/text/token-info.h" #include "verible/common/text/token-stream-view.h" @@ -59,7 +59,7 @@ std::ostream &operator<<(std::ostream &stream, DiffStatus status) { // Lex a token into smaller substrings/subtokens. // Lexical errors are reported to errstream. // Returns true if lexing succeeded, false on error. -static bool LexText(absl::string_view text, TokenSequence *subtokens, +static bool LexText(std::string_view text, TokenSequence *subtokens, std::ostream *errstream) { VLOG(1) << __FUNCTION__; VerilogLexer lexer(text); @@ -90,7 +90,7 @@ static bool ShouldRecursivelyAnalyzeToken(const TokenInfo &token) { } DiffStatus VerilogLexicallyEquivalent( - absl::string_view left, absl::string_view right, + std::string_view left, std::string_view right, const std::function &remove_predicate, const std::function &equal_comparator, @@ -98,7 +98,7 @@ DiffStatus VerilogLexicallyEquivalent( // Bind some Verilog-specific parameters. return LexicallyEquivalent( left, right, - [=](absl::string_view text, TokenSequence *tokens) { + [=](std::string_view text, TokenSequence *tokens) { return LexText(text, tokens, errstream); }, ShouldRecursivelyAnalyzeToken, // @@ -109,8 +109,8 @@ DiffStatus VerilogLexicallyEquivalent( } DiffStatus LexicallyEquivalent( - absl::string_view left_text, absl::string_view right_text, - const std::function &lexer, + std::string_view left_text, std::string_view right_text, + const std::function &lexer, const std::function &recursion_predicate, const std::function &remove_predicate, const std::function #include +#include -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" #include "verible/common/text/token-stream-view.h" @@ -45,8 +45,8 @@ std::ostream &operator<<(std::ostream &, DiffStatus); // If errstream is provided, print detailed error message to that stream. // TODO(fangism): move this to language-agnostic common/analysis library. DiffStatus LexicallyEquivalent( - absl::string_view left, absl::string_view right, - const std::function + std::string_view left, std::string_view right, + const std::function &lexer, const std::function &recursion_predicate, const std::function &remove_predicate, @@ -60,7 +60,7 @@ DiffStatus LexicallyEquivalent( // out by remove_predicate, and using the equal_comparator binary predicate. // If errstream is provided, print detailed error message to that stream. DiffStatus VerilogLexicallyEquivalent( - absl::string_view left, absl::string_view right, + std::string_view left, std::string_view right, const std::function &remove_predicate, const std::function &equal_comparator, @@ -68,7 +68,7 @@ DiffStatus VerilogLexicallyEquivalent( // Returns true if both token sequences are equivalent, ignoring whitespace. // If errstream is provided, print detailed error message to that stream. -DiffStatus FormatEquivalent(absl::string_view left, absl::string_view right, +DiffStatus FormatEquivalent(std::string_view left, std::string_view right, std::ostream *errstream = nullptr); // Similar to FormatEquivalent except that: @@ -76,8 +76,7 @@ DiffStatus FormatEquivalent(absl::string_view left, absl::string_view right, // 2) identifiers only need to match in length and not string content to be // considered equal. // Such equivalence is good for formatter test cases. -DiffStatus ObfuscationEquivalent(absl::string_view left, - absl::string_view right, +DiffStatus ObfuscationEquivalent(std::string_view left, std::string_view right, std::ostream *errstream = nullptr); } // namespace verilog diff --git a/verible/verilog/analysis/verilog-equivalence_test.cc b/verible/verilog/analysis/verilog-equivalence_test.cc index 10ad3e7d4..90b0ee11b 100644 --- a/verible/verilog/analysis/verilog-equivalence_test.cc +++ b/verible/verilog/analysis/verilog-equivalence_test.cc @@ -18,10 +18,10 @@ #include #include #include +#include #include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "absl/types/span.h" #include "gtest/gtest.h" @@ -60,9 +60,9 @@ static DiffStatus FlipStatus(DiffStatus status) { } static void ExpectCompareWithErrstream( - const std::function &func, - DiffStatus expect_compare, absl::string_view left, absl::string_view right, + DiffStatus expect_compare, std::string_view left, std::string_view right, std::ostream *errstream = &std::cout) { EXPECT_EQ(func(left, right, errstream), expect_compare) << "left:\n" @@ -357,8 +357,8 @@ TEST(FormatEquivalentTest, LexErrorOnRightInMacroDefinitionBody) { } struct ObfuscationTestCase { - absl::string_view before; - absl::string_view after; + std::string_view before; + std::string_view after; DiffStatus expect_match; }; diff --git a/verible/verilog/analysis/verilog-excerpt-parse.cc b/verible/verilog/analysis/verilog-excerpt-parse.cc index 6a7951302..8c5735231 100644 --- a/verible/verilog/analysis/verilog-excerpt-parse.cc +++ b/verible/verilog/analysis/verilog-excerpt-parse.cc @@ -18,11 +18,11 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/text/text-structure.h" #include "verible/common/util/container-util.h" #include "verible/common/util/logging.h" @@ -48,8 +48,8 @@ using verible::container::FindOrNull; // The returned analyzer's text structure will discard parsed information // about the prolog and epilog, leaving only the substructure of interest. static std::unique_ptr AnalyzeVerilogConstruct( - absl::string_view prolog, absl::string_view text, absl::string_view epilog, - absl::string_view filename, + std::string_view prolog, std::string_view text, std::string_view epilog, + std::string_view filename, const VerilogPreprocess::Config &preprocess_config) { VLOG(2) << __FUNCTION__; CHECK(epilog.empty() || absl::ascii_isspace(epilog[0])) @@ -79,7 +79,7 @@ static std::unique_ptr AnalyzeVerilogConstruct( } std::unique_ptr AnalyzeVerilogPropertySpec( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config) { return AnalyzeVerilogConstruct("module foo;\nproperty p;\n", text, "\nendproperty;\nendmodule;\n", filename, @@ -87,14 +87,14 @@ std::unique_ptr AnalyzeVerilogPropertySpec( } std::unique_ptr AnalyzeVerilogStatements( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config) { return AnalyzeVerilogConstruct("function foo();\n", text, "\nendfunction\n", filename, preprocess_config); } std::unique_ptr AnalyzeVerilogExpression( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config) { return AnalyzeVerilogConstruct("module foo;\nif (", text, " ) $error;\nendmodule\n", filename, @@ -106,28 +106,28 @@ std::unique_ptr AnalyzeVerilogExpression( } std::unique_ptr AnalyzeVerilogModuleBody( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config) { return AnalyzeVerilogConstruct("module foo;\n", text, "\nendmodule\n", filename, preprocess_config); } std::unique_ptr AnalyzeVerilogClassBody( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config) { return AnalyzeVerilogConstruct("class foo;\n", text, "\nendclass\n", filename, preprocess_config); } std::unique_ptr AnalyzeVerilogPackageBody( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config) { return AnalyzeVerilogConstruct("package foo;\n", text, "\nendpackage\n", filename, preprocess_config); } std::unique_ptr AnalyzeVerilogLibraryMap( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config) { // The prolog/epilog strings come from verilog.lex as token enums: // PD_LIBRARY_SYNTAX_BEGIN and PD_LIBRARY_SYNTAX_END. @@ -139,12 +139,12 @@ std::unique_ptr AnalyzeVerilogLibraryMap( } std::unique_ptr AnalyzeVerilogWithMode( - absl::string_view text, absl::string_view filename, absl::string_view mode, + std::string_view text, std::string_view filename, std::string_view mode, const VerilogPreprocess::Config &preprocess_config) { static const auto *func_map = - new std::map( - absl::string_view, absl::string_view, + std::string_view, std::string_view, const VerilogPreprocess::Config &)>>{ {"parse-as-statements", &AnalyzeVerilogStatements}, {"parse-as-expression", &AnalyzeVerilogExpression}, diff --git a/verible/verilog/analysis/verilog-excerpt-parse.h b/verible/verilog/analysis/verilog-excerpt-parse.h index d9d4c64a6..c60fd5b17 100644 --- a/verible/verilog/analysis/verilog-excerpt-parse.h +++ b/verible/verilog/analysis/verilog-excerpt-parse.h @@ -21,59 +21,59 @@ #define VERIBLE_VERILOG_ANALYSIS_VERILOG_EXCERPT_PARSE_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/verilog/analysis/verilog-analyzer.h" #include "verible/verilog/preprocessor/verilog-preprocess.h" namespace verilog { // The interface for these functions should all be: -// std::unique_ptr (absl::string_view text, -// absl::string_view filename, +// std::unique_ptr (std::string_view text, +// std::string_view filename, // const VerilogPreprocess::Config& config); // ); // Analyzes test as Verilog property_spec std::unique_ptr AnalyzeVerilogPropertySpec( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config); // Analyzes text as Verilog statements. std::unique_ptr AnalyzeVerilogStatements( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config); // Analyzes text as any Verilog expression. std::unique_ptr AnalyzeVerilogExpression( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config); // Analyzes text as any Verilog module body. std::unique_ptr AnalyzeVerilogModuleBody( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config); // Analyzes text as any Verilog class body. std::unique_ptr AnalyzeVerilogClassBody( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config); // Analyzes text as any Verilog package body. std::unique_ptr AnalyzeVerilogPackageBody( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config); // TODO(fangism): analogous functions for: function, task, ... // Analyzes text as any Verilog library map. std::unique_ptr AnalyzeVerilogLibraryMap( - absl::string_view text, absl::string_view filename, + std::string_view text, std::string_view filename, const VerilogPreprocess::Config &preprocess_config); // Analyzes text in the selected parsing `mode`. std::unique_ptr AnalyzeVerilogWithMode( - absl::string_view text, absl::string_view filename, absl::string_view mode, + std::string_view text, std::string_view filename, std::string_view mode, const VerilogPreprocess::Config &preprocess_config); } // namespace verilog diff --git a/verible/verilog/analysis/verilog-filelist.cc b/verible/verilog/analysis/verilog-filelist.cc index dd5a665ee..4fe13f54c 100644 --- a/verible/verilog/analysis/verilog-filelist.cc +++ b/verible/verilog/analysis/verilog-filelist.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -25,17 +26,16 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "verible/common/util/file-util.h" #include "verible/common/util/iterator-range.h" namespace verilog { -absl::Status AppendFileListFromContent(absl::string_view file_list_path, +absl::Status AppendFileListFromContent(std::string_view file_list_path, const std::string &file_list_content, FileList *append_to) { - constexpr absl::string_view kIncludeDirPrefix = "+incdir+"; - constexpr absl::string_view kDefineMacroPrefix = "+define+"; + constexpr std::string_view kIncludeDirPrefix = "+incdir+"; + constexpr std::string_view kDefineMacroPrefix = "+define+"; append_to->preprocessing.include_dirs.emplace_back( "."); // Should we do that? std::string file_path; @@ -59,7 +59,7 @@ absl::Status AppendFileListFromContent(absl::string_view file_list_path, if (absl::StartsWith(file_path, kDefineMacroPrefix)) { // Handle defines - absl::string_view definition = + std::string_view definition = absl::StripPrefix(file_path, kDefineMacroPrefix); std::pair define_value = absl::StrSplit( definition, absl::MaxSplits('=', 1), absl::SkipEmpty()); @@ -81,7 +81,7 @@ absl::Status AppendFileListFromContent(absl::string_view file_list_path, return absl::OkStatus(); } -absl::Status AppendFileListFromFile(absl::string_view file_list_file, +absl::Status AppendFileListFromFile(std::string_view file_list_file, FileList *append_to) { auto content_or = verible::file::GetContentAsString(file_list_file); if (!content_or.ok()) return content_or.status(); @@ -89,8 +89,8 @@ absl::Status AppendFileListFromFile(absl::string_view file_list_file, } absl::Status AppendFileListFromCommandline( - const std::vector &cmdline, FileList *append_to) { - for (absl::string_view argument : cmdline) { + const std::vector &cmdline, FileList *append_to) { + for (std::string_view argument : cmdline) { if (argument.empty()) continue; if (argument[0] != '+') { // Then "argument" is a SV file name. @@ -98,7 +98,7 @@ absl::Status AppendFileListFromCommandline( continue; } // It should be either a define or incdir. - std::vector argument_plus_splitted = + std::vector argument_plus_splitted = absl::StrSplit(argument, absl::ByChar('+'), absl::SkipEmpty()); if (argument_plus_splitted.size() < 2) { return absl::InvalidArgumentError( @@ -106,9 +106,9 @@ absl::Status AppendFileListFromCommandline( "followed by the parameter but got '", argument, "'")); } - absl::string_view plus_argument_type = argument_plus_splitted[0]; + std::string_view plus_argument_type = argument_plus_splitted[0]; if (plus_argument_type == "define") { - for (const absl::string_view define_argument : + for (const std::string_view define_argument : verible::make_range(argument_plus_splitted.begin() + 1, argument_plus_splitted.end())) { // argument_plus_splitted[0] is 'define' so it is safe to skip it. @@ -126,7 +126,7 @@ absl::Status AppendFileListFromCommandline( macro_pair.second); } } else if (plus_argument_type == "incdir") { - for (const absl::string_view incdir_argument : + for (const std::string_view incdir_argument : verible::make_range(argument_plus_splitted.begin() + 1, argument_plus_splitted.end())) { // argument_plus_splitted[0] is 'incdir' so it is safe to skip it. @@ -147,10 +147,10 @@ std::string FileList::ToString() const { for (const auto &definition : preprocessing.defines) { buffer << "+define+" << definition.name << "=" << definition.value << '\n'; } - for (absl::string_view include : preprocessing.include_dirs) { + for (std::string_view include : preprocessing.include_dirs) { buffer << "+incdir+" << include << '\n'; } - for (absl::string_view path : file_paths) { + for (std::string_view path : file_paths) { buffer << path << '\n'; } return buffer.str(); diff --git a/verible/verilog/analysis/verilog-filelist.h b/verible/verilog/analysis/verilog-filelist.h index 11af3cb08..0bb474a1c 100644 --- a/verible/verilog/analysis/verilog-filelist.h +++ b/verible/verilog/analysis/verilog-filelist.h @@ -16,11 +16,11 @@ #define VERIBLE_VERILOG_ANALYSIS_VERILOG_FILELIST_H_ #include +#include #include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" namespace verilog { @@ -75,12 +75,12 @@ struct FileList { // we can replace std::string in FileList with string_views; that way, it is // always possible to pinpoint back to the owning string view in case we want // to provide detailed error messages. -absl::Status AppendFileListFromFile(absl::string_view file_list_file, +absl::Status AppendFileListFromFile(std::string_view file_list_file, FileList *append_to); // Reads in a list of files line-by-line from the given string. The include // directories are prefixed by "+incdir+" (TODO: +define+) -absl::Status AppendFileListFromContent(absl::string_view file_list_path, +absl::Status AppendFileListFromContent(std::string_view file_list_path, const std::string &file_list_content, FileList *append_to); @@ -88,7 +88,7 @@ absl::Status AppendFileListFromContent(absl::string_view file_list_path, // +incdir+ and +define+ and appends to FileList. // TODO: Also support --file_list_path (and -f), --file_list_root absl::Status AppendFileListFromCommandline( - const std::vector &cmdline, FileList *append_to); + const std::vector &cmdline, FileList *append_to); } // namespace verilog #endif // VERIBLE_VERILOG_ANALYSIS_VERILOG_FILELIST_H_ diff --git a/verible/verilog/analysis/verilog-filelist_test.cc b/verible/verilog/analysis/verilog-filelist_test.cc index 3a8c4a29b..cc10806ac 100644 --- a/verible/verilog/analysis/verilog-filelist_test.cc +++ b/verible/verilog/analysis/verilog-filelist_test.cc @@ -15,9 +15,9 @@ #include "verible/verilog/analysis/verilog-filelist.h" #include +#include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/util/file-util.h" @@ -57,7 +57,7 @@ TEST(FileListTest, AppendFileListFromFile) { } TEST(FileListTest, AppendFileListFromInvalidCommandline) { - std::vector> test_cases = { + std::vector> test_cases = { {"+define+macro1="}, {"+define+"}, {"+not_valid_define+"}, @@ -70,7 +70,7 @@ TEST(FileListTest, AppendFileListFromInvalidCommandline) { } TEST(FileListTest, AppendFileListFromCommandline) { - std::vector cmdline = { + std::vector cmdline = { "+define+macro1=text1+macro2+macro3=text3", "file1", "+define+macro4", diff --git a/verible/verilog/analysis/verilog-linter-configuration.cc b/verible/verilog/analysis/verilog-linter-configuration.cc index ff121eb75..489059a17 100644 --- a/verible/verilog/analysis/verilog-linter-configuration.cc +++ b/verible/verilog/analysis/verilog-linter-configuration.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "absl/status/status.h" @@ -31,7 +32,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/line-lint-rule.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/analysis/text-structure-lint-rule.h" @@ -54,7 +54,7 @@ using verible::TokenStreamLintRule; using verible::container::FindOrNull; template -static const char *MatchesAnyItem(absl::string_view filename, +static const char *MatchesAnyItem(std::string_view filename, const List &items) { for (const auto item : items) { if (absl::StrContains(filename, item)) { @@ -64,12 +64,12 @@ static const char *MatchesAnyItem(absl::string_view filename, return nullptr; } -const char *ProjectPolicy::MatchesAnyPath(absl::string_view filename) const { +const char *ProjectPolicy::MatchesAnyPath(std::string_view filename) const { return MatchesAnyItem(filename, path_substrings); } const char *ProjectPolicy::MatchesAnyExclusions( - absl::string_view filename) const { + std::string_view filename) const { return MatchesAnyItem(filename, path_exclusions); } @@ -85,18 +85,18 @@ bool ProjectPolicy::IsValid() const { std::string ProjectPolicy::ListPathGlobs() const { return absl::StrJoin(path_substrings.begin(), path_substrings.end(), " | ", - [](std::string *out, absl::string_view pattern) { + [](std::string *out, std::string_view pattern) { absl::StrAppend(out, "*", pattern, "*"); }); } -bool RuleBundle::ParseConfiguration(absl::string_view text, char separator, +bool RuleBundle::ParseConfiguration(std::string_view text, char separator, std::string *error) { // Clear the vector to overwrite any existing value. rules.clear(); bool parsed_correctly = true; - for (absl::string_view part : + for (std::string_view part : absl::StrSplit(text, separator, absl::SkipEmpty())) { if (separator == '\n') { // In configuration files, we can ignore #-comments @@ -105,7 +105,7 @@ bool RuleBundle::ParseConfiguration(absl::string_view text, char separator, // case we need to expand this to parse out 'within # quotes' parts. // ... then this will finally become a more complex lexer. const auto comment_pos = part.find('#'); - if (comment_pos != absl::string_view::npos) { + if (comment_pos != std::string_view::npos) { part = part.substr(0, comment_pos); } } @@ -132,7 +132,7 @@ bool RuleBundle::ParseConfiguration(absl::string_view text, char separator, // Independent of the enabled-ness: extract a configuration string // if there is any assignment. const auto equals_pos = rule_name_with_config.find('='); - if (equals_pos != absl::string_view::npos) { + if (equals_pos != std::string_view::npos) { auto config = rule_name_with_config.substr(equals_pos + 1); // https://github.com/chipsalliance/verible/issues/1121 @@ -243,7 +243,7 @@ void LinterConfiguration::UseRuleBundle(const RuleBundle &rule_bundle) { } void LinterConfiguration::UseProjectPolicy(const ProjectPolicy &policy, - absl::string_view filename) { + std::string_view filename) { if (const char *matched_path = policy.MatchesAnyPath(filename)) { VLOG(1) << "File \"" << filename << "\" matches path \"" << matched_path << "\" from project policy [" << policy.name << "], applying it."; @@ -333,7 +333,7 @@ bool LinterConfiguration::operator==(const LinterConfiguration &config) const { } absl::Status LinterConfiguration::AppendFromFile( - absl::string_view config_filename) { + std::string_view config_filename) { // Read local configuration file absl::StatusOr config_or = verible::file::GetContentAsString(config_filename); @@ -371,7 +371,7 @@ absl::Status LinterConfiguration::ConfigureFromOptions( } else if (options.rules_config_search) { // Search upward if search is enabled and no configuration file is // specified - static constexpr absl::string_view linter_config = ".rules.verible_lint"; + static constexpr std::string_view linter_config = ".rules.verible_lint"; std::string resolved_config_file; if (verible::file::UpwardFileSearch(options.linting_start_file, linter_config, &resolved_config_file) @@ -425,7 +425,7 @@ std::string AbslUnparseFlag(const RuleSet &rules) { return stream.str(); } -bool AbslParseFlag(absl::string_view text, RuleSet *rules, std::string *error) { +bool AbslParseFlag(std::string_view text, RuleSet *rules, std::string *error) { return RuleSetEnumStringMap().Parse(text, rules, error, "--ruleset value"); } @@ -433,7 +433,7 @@ std::string AbslUnparseFlag(const RuleBundle &bundle) { return bundle.UnparseConfiguration(','); } -bool AbslParseFlag(absl::string_view text, RuleBundle *bundle, +bool AbslParseFlag(std::string_view text, RuleBundle *bundle, std::string *error) { return bundle->ParseConfiguration(text, ',', error); } diff --git a/verible/verilog/analysis/verilog-linter-configuration.h b/verible/verilog/analysis/verilog-linter-configuration.h index 014e0e02f..5b18983b2 100644 --- a/verible/verilog/analysis/verilog-linter-configuration.h +++ b/verible/verilog/analysis/verilog-linter-configuration.h @@ -20,11 +20,11 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/line-lint-rule.h" #include "verible/common/analysis/syntax-tree-lint-rule.h" #include "verible/common/analysis/text-structure-lint-rule.h" @@ -41,17 +41,17 @@ struct RuleSetting { // Error to be shown when an invalid flag is // encountered while parsing a configuration -inline constexpr absl::string_view kInvalidFlagMessage = "[ERR] Invalid flag"; +inline constexpr std::string_view kInvalidFlagMessage = "[ERR] Invalid flag"; // Warning to be shown when we parse a configuration file that configures the // same rule more than once. -inline constexpr absl::string_view kRepeatedFlagMessage = +inline constexpr std::string_view kRepeatedFlagMessage = "[WARN] Repeated flag in the configuration. Last provided value will be " "used"; // Warning to be shown when an stray comma is // encountered while parsing a configuration -inline constexpr absl::string_view kStrayCommaWarning = +inline constexpr std::string_view kStrayCommaWarning = "[WARN] Ignoring stray comma at the end of configuration"; // Enum denoting a ruleset @@ -71,16 +71,16 @@ std::string AbslUnparseFlag(const RuleSet &rules); // It attempts to parse text into a RuleSet and put that RuleSet into rules // If successful, returns true. // Otherwise, sets string error to the a error message and returns false. -bool AbslParseFlag(absl::string_view text, RuleSet *rules, std::string *error); +bool AbslParseFlag(std::string_view text, RuleSet *rules, std::string *error); // Container class for parse/unparse flags // Keys must be the exact string_views in registered maps (not just string // equivalent) for the lifetime guarantee. struct RuleBundle { - std::map rules; + std::map rules; // Parse configuration from input. Separator between rules is 'separator', // typically that would be a comma or newline. - bool ParseConfiguration(absl::string_view text, char separator, + bool ParseConfiguration(std::string_view text, char separator, std::string *error); // Unparse the rules structure back to a string. Separator between rules // is 'separator', typically that would be a comma or newline. The String @@ -104,7 +104,7 @@ std::string AbslUnparseFlag(const RuleBundle &bundle); // If all rules are parsed successfully, returns true. // Otherwise, sets string error to the a error message containing the // invalid lint rule and returns false. -bool AbslParseFlag(absl::string_view text, RuleBundle *bundle, +bool AbslParseFlag(std::string_view text, RuleBundle *bundle, std::string *error); // ProjectPolicy is needed in a transitional period when new rules are @@ -114,7 +114,7 @@ bool AbslParseFlag(absl::string_view text, RuleBundle *bundle, // the full set of rules to take effect on new projects. struct ProjectPolicy { // A short name for policy, for diagnostic purposes. - absl::string_view name; + std::string_view name; // Raw string to check for being part of the path. Not a regex pattern. // Apply this exemption only if substring occurs in the file path. @@ -137,11 +137,11 @@ struct ProjectPolicy { // Returns a path if filename matches any of path_substrings, // otherwise nullptr. - const char *MatchesAnyPath(absl::string_view filename) const; + const char *MatchesAnyPath(std::string_view filename) const; // Returns a path if filename matches any of path_exclusions, // otherwise nullptr. - const char *MatchesAnyExclusions(absl::string_view filename) const; + const char *MatchesAnyExclusions(std::string_view filename) const; // Returns true if all disabled_rules and enabled_rules refer to registered // rules. This helps catch typos. @@ -217,8 +217,7 @@ class LinterConfiguration { void GetRuleBundle(RuleBundle *rule_bundle) const; // Adjust set of active rules based on the filename. - void UseProjectPolicy(const ProjectPolicy &policy, - absl::string_view filename); + void UseProjectPolicy(const ProjectPolicy &policy, std::string_view filename); // Return the keys of enabled lint rules, sorted. std::set ActiveRuleIds() const; @@ -248,7 +247,7 @@ class LinterConfiguration { bool operator!=(const LinterConfiguration &r) const { return !(*this == r); } // Appends linter rules configuration from a file - absl::Status AppendFromFile(absl::string_view filename); + absl::Status AppendFromFile(std::string_view filename); // Generates configuration forn LinterOptions absl::Status ConfigureFromOptions(const LinterOptions &options); diff --git a/verible/verilog/analysis/verilog-linter-configuration_test.cc b/verible/verilog/analysis/verilog-linter-configuration_test.cc index be7eceafb..bc491ce5d 100644 --- a/verible/verilog/analysis/verilog-linter-configuration_test.cc +++ b/verible/verilog/analysis/verilog-linter-configuration_test.cc @@ -17,12 +17,12 @@ #include #include #include +#include #include #include #include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/analysis/line-lint-rule.h" @@ -119,7 +119,7 @@ class TestRule4 : public LineLintRule { return d; } - void HandleLine(absl::string_view) final {} + void HandleLine(std::string_view) final {} verible::LintRuleStatus Report() const final { return verible::LintRuleStatus(); @@ -137,7 +137,7 @@ class TestRule5 : public TextStructureLintRule { return d; } - void Lint(const TextStructureView &, absl::string_view) final {} + void Lint(const TextStructureView &, std::string_view) final {} verible::LintRuleStatus Report() const final { return verible::LintRuleStatus(); @@ -162,12 +162,12 @@ class FakeTextStructureView : public TextStructureView { static const verible::LineColumnMap dummy_map(""); // Don't care about file name for these tests. -static constexpr absl::string_view filename; +static constexpr std::string_view filename; TEST(ProjectPolicyTest, MatchesAnyPath) { struct TestCase { ProjectPolicy policy; - absl::string_view filename; + std::string_view filename; const char *expected_match; }; const TestCase kTestCases[] = { @@ -182,7 +182,7 @@ TEST(ProjectPolicyTest, MatchesAnyPath) { for (const auto &test : kTestCases) { const char *match = test.policy.MatchesAnyPath(test.filename); if (test.expected_match != nullptr) { - EXPECT_EQ(absl::string_view(match), test.expected_match); + EXPECT_EQ(std::string_view(match), test.expected_match); } else { EXPECT_EQ(match, nullptr); } @@ -192,7 +192,7 @@ TEST(ProjectPolicyTest, MatchesAnyPath) { TEST(ProjectPolicyTest, MatchesAnyExclusions) { struct TestCase { ProjectPolicy policy; - absl::string_view filename; + std::string_view filename; const char *expected_match; }; const TestCase kTestCases[] = { @@ -207,7 +207,7 @@ TEST(ProjectPolicyTest, MatchesAnyExclusions) { for (const auto &test : kTestCases) { const char *match = test.policy.MatchesAnyExclusions(test.filename); if (test.expected_match != nullptr) { - EXPECT_EQ(absl::string_view(match), test.expected_match); + EXPECT_EQ(std::string_view(match), test.expected_match); } else { EXPECT_EQ(match, nullptr); } @@ -243,7 +243,7 @@ TEST(ProjectPolicyTest, IsValid) { } TEST(ProjectPolicyTest, ListPathGlobs) { - const std::pair kTestCases[] = { + const std::pair kTestCases[] = { {{"policyX", {}, {}, {}, {}, {}}, ""}, {{"policyX", {"path"}, {}, {}, {}, {}}, "*path*"}, {{"policyX", {"path1", "path2"}, {}, {}, {}, {}}, "*path1* | *path2*"}, @@ -645,7 +645,7 @@ TEST(RuleBundleTest, UnparseRuleBundleEmpty) { } TEST(RuleBundleTest, ParseRuleBundleEmpty) { - constexpr absl::string_view text; + constexpr std::string_view text; RuleBundle bundle; std::string error; bool success = bundle.ParseConfiguration(text, ',', &error); @@ -656,7 +656,7 @@ TEST(RuleBundleTest, ParseRuleBundleEmpty) { TEST(RuleBundleTest, ParseRuleBundleAcceptSeveral) { // Allow for an optional '+' to enable a rule for symmetry with '-' disable - constexpr absl::string_view text = "test-rule-1,test-rule-2,+test-rule-3"; + constexpr std::string_view text = "test-rule-1,test-rule-2,+test-rule-3"; RuleBundle bundle; std::string error; bool success = bundle.ParseConfiguration(text, ',', &error); @@ -669,7 +669,7 @@ TEST(RuleBundleTest, ParseRuleBundleAcceptSeveral) { } TEST(RuleBundleTest, ParseRuleBundleAcceptConfiguration) { - constexpr absl::string_view text = + constexpr std::string_view text = "test-rule-1=foo,test-rule-2=,test-rule-3,-test-rule-4=bar"; RuleBundle bundle; std::string error; @@ -692,7 +692,7 @@ TEST(RuleBundleTest, ParseRuleBundleAcceptConfiguration) { } TEST(RuleBundleTest, ParseRuleBundleWithQuotationMarks) { - constexpr absl::string_view text = + constexpr std::string_view text = "test-rule-1=\"foo\",test-rule-2=\"\",test-rule-3,-test-rule-4=\"bar\""; RuleBundle bundle; std::string error; @@ -715,7 +715,7 @@ TEST(RuleBundleTest, ParseRuleBundleWithQuotationMarks) { } TEST(RuleBundleTest, ParseRuleBundleAcceptOne) { - constexpr absl::string_view text = "test-rule-1"; + constexpr std::string_view text = "test-rule-1"; RuleBundle bundle; std::string error; bool success = bundle.ParseConfiguration(text, ',', &error); @@ -726,7 +726,7 @@ TEST(RuleBundleTest, ParseRuleBundleAcceptOne) { } TEST(RuleBundleTest, ParseRuleWhitespaceAroundAllowed) { - constexpr absl::string_view text = + constexpr std::string_view text = "\t test-rule-1 \t, +test-rule-2=foo:bar \t"; RuleBundle bundle; std::string error; @@ -740,7 +740,7 @@ TEST(RuleBundleTest, ParseRuleWhitespaceAroundAllowed) { } TEST(RuleBundleTest, ParseRuleBundleAcceptSeveralTurnOff) { - constexpr absl::string_view text = "test-rule-1,-test-rule-2"; + constexpr std::string_view text = "test-rule-1,-test-rule-2"; RuleBundle bundle; std::string error; bool success = bundle.ParseConfiguration(text, ',', &error); @@ -752,7 +752,7 @@ TEST(RuleBundleTest, ParseRuleBundleAcceptSeveralTurnOff) { } TEST(RuleBundleTest, ParseRuleBundleAcceptOneTurnOff) { - constexpr absl::string_view text = "-test-rule-1"; + constexpr std::string_view text = "-test-rule-1"; RuleBundle bundle; std::string error; bool success = bundle.ParseConfiguration(text, ',', &error); @@ -763,7 +763,7 @@ TEST(RuleBundleTest, ParseRuleBundleAcceptOneTurnOff) { } TEST(RuleBundleTest, ParseRuleBundleReject) { - constexpr absl::string_view text = "test-rule-1,bad-flag"; + constexpr std::string_view text = "test-rule-1,bad-flag"; RuleBundle bundle; std::string error; bool success = bundle.ParseConfiguration(text, ',', &error); @@ -772,7 +772,7 @@ TEST(RuleBundleTest, ParseRuleBundleReject) { } TEST(RuleBundleTest, ParseRuleBundleAcceptGoodRulesEvenWhenRejecting) { - constexpr absl::string_view text = "test-rule-unknown-rules\ntest-rule-1"; + constexpr std::string_view text = "test-rule-unknown-rules\ntest-rule-1"; { RuleBundle bundle; std::string error; @@ -786,7 +786,7 @@ TEST(RuleBundleTest, ParseRuleBundleAcceptGoodRulesEvenWhenRejecting) { } TEST(RuleBundleTest, ParseRuleBundleAcceptMultiline) { - constexpr absl::string_view text = "test-rule-1\n-test-rule-2"; + constexpr std::string_view text = "test-rule-1\n-test-rule-2"; RuleBundle bundle; std::string error; bool success = bundle.ParseConfiguration(text, '\n', &error); @@ -798,7 +798,7 @@ TEST(RuleBundleTest, ParseRuleBundleAcceptMultiline) { } TEST(RuleBundleTest, ParseRuleBundleRejectMultiline) { - constexpr absl::string_view text = "test-rule-1\nbad-flag\n-test-rule-2"; + constexpr std::string_view text = "test-rule-1\nbad-flag\n-test-rule-2"; RuleBundle bundle; std::string error; bool success = bundle.ParseConfiguration(text, '\n', &error); @@ -807,7 +807,7 @@ TEST(RuleBundleTest, ParseRuleBundleRejectMultiline) { } TEST(RuleBundleTest, ParseRuleBundleSkipComments) { - constexpr absl::string_view text = + constexpr std::string_view text = " # some comment after whitespace\n" "# more comment\n" "test-rule-1\n" @@ -830,7 +830,7 @@ TEST(RuleBundleTest, ParseRuleBundleSkipComments) { TEST(RuleBundleTest, ParseRuleBundleIgnoreExtraComma) { // Multiline rules might still have a comma from the one-line // rule configuration. They shouldn't harm. - constexpr absl::string_view text = + constexpr std::string_view text = "test-rule-1,,, \n" "-test-rule-2=a:b,\n" "+test-rule-3=bar:baz, # config-comment\n"; @@ -850,7 +850,7 @@ TEST(RuleBundleTest, ParseRuleBundleIgnoreExtraComma) { } TEST(RuleBundleTest, ParseRuleBundleDontWarnIfNoConfig) { - constexpr absl::string_view text = "test-rule-1,\ntest-rule-1"; + constexpr std::string_view text = "test-rule-1,\ntest-rule-1"; { RuleBundle bundle; std::string error; @@ -863,7 +863,7 @@ TEST(RuleBundleTest, ParseRuleBundleDontWarnIfNoConfig) { } TEST(RuleBundleTest, ParseRuleBundleWarnConfigOverride) { - constexpr absl::string_view text = "test-rule-1=a,\ntest-rule-1=b"; + constexpr std::string_view text = "test-rule-1=a,\ntest-rule-1=b"; { RuleBundle bundle; std::string error; diff --git a/verible/verilog/analysis/verilog-linter-constants.h b/verible/verilog/analysis/verilog-linter-constants.h index b16f038a0..159af4145 100644 --- a/verible/verilog/analysis/verilog-linter-constants.h +++ b/verible/verilog/analysis/verilog-linter-constants.h @@ -15,21 +15,21 @@ #ifndef VERIBLE_VERILOG_ANALYSIS_VERILOG_LINTER_CONSTANTS_H_ #define VERIBLE_VERILOG_ANALYSIS_VERILOG_LINTER_CONSTANTS_H_ -#include "absl/strings/string_view.h" +#include namespace verilog { // This is the leading string that makes a comment a lint waiver. -inline constexpr absl::string_view kLinterTrigger = "verilog_lint:"; +inline constexpr std::string_view kLinterTrigger = "verilog_lint:"; // This command says to waive one line (this or next applicable). -inline constexpr absl::string_view kLinterWaiveLineCommand = "waive"; +inline constexpr std::string_view kLinterWaiveLineCommand = "waive"; // This command says to start waiving a rule from this line... -inline constexpr absl::string_view kLinterWaiveStartCommand = "waive-start"; +inline constexpr std::string_view kLinterWaiveStartCommand = "waive-start"; // ... and stop waiving at this line. -inline constexpr absl::string_view kLinterWaiveStopCommand = "waive-stop"; +inline constexpr std::string_view kLinterWaiveStopCommand = "waive-stop"; } // namespace verilog diff --git a/verible/verilog/analysis/verilog-linter.cc b/verible/verilog/analysis/verilog-linter.cc index 84d4431e1..4d36b08c0 100644 --- a/verible/verilog/analysis/verilog-linter.cc +++ b/verible/verilog/analysis/verilog-linter.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -31,7 +32,6 @@ #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/citation.h" #include "verible/common/analysis/line-linter.h" #include "verible/common/analysis/lint-rule-status.h" @@ -99,7 +99,7 @@ std::set GetSortedViolations( // 0: success // 1: linting error (if parse_fatal == true) // 2..: other fatal issues such as file not found. -int LintOneFile(std::ostream *stream, absl::string_view filename, +int LintOneFile(std::ostream *stream, std::string_view filename, const LinterConfiguration &config, verible::ViolationHandler *violation_handler, bool check_syntax, bool parse_fatal, bool lint_fatal, bool show_context) { @@ -159,7 +159,7 @@ int LintOneFile(std::ostream *stream, absl::string_view filename, } else { VLOG(1) << "Lint Violations (" << total_violations << "): " << std::endl; - absl::string_view text_base = text_structure.Contents(); + std::string_view text_base = text_structure.Contents(); const std::set violations = GetSortedViolations(linter_statuses); @@ -184,7 +184,7 @@ VerilogLinter::VerilogLinter() kLinterWaiveStopCommand) {} absl::Status VerilogLinter::Configure(const LinterConfiguration &configuration, - absl::string_view lintee_filename) { + std::string_view lintee_filename) { if (VLOG_IS_ON(2)) { for (const auto &name : configuration.ActiveRuleIds()) { LOG(INFO) << "active rule: '" << name << '\''; @@ -228,7 +228,7 @@ absl::Status VerilogLinter::Configure(const LinterConfiguration &configuration, } void VerilogLinter::Lint(const TextStructureView &text_structure, - absl::string_view filename) { + std::string_view filename) { // Collect all lint waivers in an initial pass. lint_waiver_.ProcessTokenRangesByLine(text_structure); @@ -251,7 +251,7 @@ void VerilogLinter::Lint(const TextStructureView &text_structure, static void AppendLintRuleStatuses( const std::vector &new_statuses, const verible::LintWaiver &waivers, const LineColumnMap &line_map, - absl::string_view text_base, + std::string_view text_base, std::vector *cumulative_statuses) { for (const auto &status : new_statuses) { cumulative_statuses->push_back(status); @@ -276,7 +276,7 @@ static void AppendLintRuleStatuses( } std::vector VerilogLinter::ReportStatus( - const LineColumnMap &line_map, absl::string_view text_base) { + const LineColumnMap &line_map, std::string_view text_base) { std::vector statuses; const verible::LintWaiver &waivers = lint_waiver_.GetLintWaiver(); AppendLintRuleStatuses(line_linter_.ReportStatus(), waivers, line_map, @@ -291,7 +291,7 @@ std::vector VerilogLinter::ReportStatus( } absl::StatusOr LinterConfigurationFromFlags( - absl::string_view linting_start_file) { + std::string_view linting_start_file) { LinterConfiguration config; const verilog::LinterOptions options = { @@ -309,7 +309,7 @@ absl::StatusOr LinterConfigurationFromFlags( } absl::StatusOr> VerilogLintTextStructure( - absl::string_view filename, const LinterConfiguration &config, + std::string_view filename, const LinterConfiguration &config, const TextStructureView &text_structure) { // Create the linter, add rules, and run it. VerilogLinter linter; @@ -319,14 +319,14 @@ absl::StatusOr> VerilogLintTextStructure( linter.Lint(text_structure, filename); - absl::string_view text_base = text_structure.Contents(); + std::string_view text_base = text_structure.Contents(); // Each enabled lint rule yields a collection of violations. return linter.ReportStatus(text_structure.GetLineColumnMap(), text_base); } absl::Status PrintRuleInfo(std::ostream *os, const analysis::LintRuleDescriptionsMap &rule_map, - absl::string_view rule_name) { + std::string_view rule_name) { constexpr int kRuleWidth = 35; constexpr int kParamIndent = kRuleWidth + 4; constexpr char kFill = ' '; @@ -360,7 +360,7 @@ absl::Status PrintRuleInfo(std::ostream *os, } void GetLintRuleDescriptionsHelpFlag(std::ostream *os, - absl::string_view flag_value) { + std::string_view flag_value) { // Set up the map. auto rule_map = analysis::GetAllRuleDescriptions(); for (const auto &rule_id : analysis::kDefaultRuleSet) { diff --git a/verible/verilog/analysis/verilog-linter.h b/verible/verilog/analysis/verilog-linter.h index 72c300fec..aea82d266 100644 --- a/verible/verilog/analysis/verilog-linter.h +++ b/verible/verilog/analysis/verilog-linter.h @@ -17,12 +17,12 @@ #include #include +#include #include #include "absl/flags/declare.h" #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/line-linter.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/lint-waiver.h" @@ -63,7 +63,7 @@ std::set GetSortedViolations( // TODO(hzeller): the options to this function are a lot and many of them // the same type does not help. Make at least the bool options a struct with // names parameters. -int LintOneFile(std::ostream *stream, absl::string_view filename, +int LintOneFile(std::ostream *stream, std::string_view filename, const LinterConfiguration &config, verible::ViolationHandler *violation_handler, bool check_syntax, bool parse_fatal, bool lint_fatal, bool show_context = false); @@ -76,15 +76,15 @@ class VerilogLinter { // Configures the internal linters, enabling select rules. absl::Status Configure(const LinterConfiguration &configuration, - absl::string_view lintee_filename); + std::string_view lintee_filename); // Analyzes text structure. void Lint(const verible::TextStructureView &text_structure, - absl::string_view filename); + std::string_view filename); // Reports lint findings. std::vector ReportStatus( - const verible::LineColumnMap &, absl::string_view text_base); + const verible::LineColumnMap &, std::string_view text_base); private: // Line based linter. @@ -107,11 +107,11 @@ class VerilogLinter { // If --rules_config_search is configured, uses the given // start file to look up the directory chain. absl::StatusOr LinterConfigurationFromFlags( - absl::string_view linting_start_file = "."); + std::string_view linting_start_file = "."); // Expands linter configuration from a text file absl::Status AppendLinterConfigurationFromFile( - LinterConfiguration *config, absl::string_view config_filename); + LinterConfiguration *config, std::string_view config_filename); // VerilogLintTextStructure analyzes Verilog syntax tree for style violations // and syntactically detectable pitfalls. @@ -130,18 +130,18 @@ absl::Status AppendLinterConfigurationFromFile( // Returns: // Vector of LintRuleStatuses on success, otherwise error code. absl::StatusOr> VerilogLintTextStructure( - absl::string_view filename, const LinterConfiguration &config, + std::string_view filename, const LinterConfiguration &config, const verible::TextStructureView &text_structure); // Prints the rule, description and default_enabled. absl::Status PrintRuleInfo(std::ostream *, const analysis::LintRuleDescriptionsMap &, - absl::string_view); + std::string_view); // Outputs the descriptions for every rule for the --help_rules flag. // TODO(sconwayaus): These are really printers and not getters. Consider // renaming -void GetLintRuleDescriptionsHelpFlag(std::ostream *, absl::string_view); +void GetLintRuleDescriptionsHelpFlag(std::ostream *, std::string_view); // Outputs the descriptions for every rule, formatted for markdown. // TODO(sconwayaus): These are really printers and not getters. Consider diff --git a/verible/verilog/analysis/verilog-linter_test.cc b/verible/verilog/analysis/verilog-linter_test.cc index b99f5063e..a82a41104 100644 --- a/verible/verilog/analysis/verilog-linter_test.cc +++ b/verible/verilog/analysis/verilog-linter_test.cc @@ -30,6 +30,7 @@ #include #include // IWYU pragma: keep // for ostringstream #include +#include #include #include @@ -37,7 +38,6 @@ #include "absl/status/statusor.h" #include "absl/strings/ascii.h" #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/analysis/lint-rule-status.h" @@ -85,7 +85,7 @@ TEST_F(LintOneFileTest, FileNotFound) { // Tests that clean code exits 0 (success). TEST_F(LintOneFileTest, LintCleanFiles) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { "", // empty file "\n", "class foo;\n" @@ -116,7 +116,7 @@ TEST_F(LintOneFileTest, LintCleanFiles) { // Tests that invalid code is handled according to 'parse_fatal' parameter. TEST_F(LintOneFileTest, SyntaxError) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { "class foo;\n", // no endclass "endclass : foo\n", // no begin class "module 444bad_name; endmodule\n", // lexical error @@ -163,7 +163,7 @@ TEST_F(LintOneFileTest, SyntaxError) { } TEST_F(LintOneFileTest, LintError) { - constexpr absl::string_view kTestCases[] = { + constexpr std::string_view kTestCases[] = { "task automatic foo;\n" " $psprintf(\"blah\");\n" // forbidden function "endtask\n", @@ -200,7 +200,7 @@ class VerilogLinterTest : public DefaultLinterConfigTestFixture, protected: // Returns diagnostic text from analyzing source code. std::pair LintAnalyzeText( - absl::string_view filename, absl::string_view content) const { + std::string_view filename, std::string_view content) const { // Run the analyzer to produce a syntax tree from source code. const auto analyzer = std::make_unique(content, filename); const absl::Status status = ABSL_DIE_IF_NULL(analyzer)->Analyze(); @@ -496,7 +496,7 @@ class ViolationFixerTest : public testing::Test { protected: LinterConfiguration config_; - absl::Status LintAnalyzeFixText(absl::string_view content, + absl::Status LintAnalyzeFixText(std::string_view content, ViolationFixer *violation_fixer, std::string *fixed_content) const { const ScopedTestFile temp_file(testing::TempDir(), content); @@ -525,8 +525,8 @@ class ViolationFixerTest : public testing::Test { void DoFixerTest( std::initializer_list choices, - std::initializer_list expected_fixed_sources) const { - static constexpr std::array input_sources{ + std::initializer_list expected_fixed_sources) const { + static constexpr std::array input_sources{ // Input source 0: // :2:10: no-trailing-spaces // :3:10: forbid-consecutive-null-statements @@ -560,7 +560,7 @@ class ViolationFixerTest : public testing::Test { std::initializer_list::iterator choice_it; const ViolationFixer::AnswerChooser answer_chooser = [&choice_it, &choices](const verible::LintViolation &, - absl::string_view) { + std::string_view) { EXPECT_NE(choice_it, choices.end()) << "AnswerChooser called more times than expected."; return *choice_it++; @@ -575,7 +575,7 @@ class ViolationFixerTest : public testing::Test { std::vector fixed_sources(input_sources.size()); for (size_t i = 0; i < input_sources.size(); ++i) { - const absl::string_view input_source = input_sources[i]; + const std::string_view input_source = input_sources[i]; std::string &fixed_source = fixed_sources[i]; const absl::Status status = @@ -588,7 +588,7 @@ class ViolationFixerTest : public testing::Test { for (size_t i = 0; i < input_sources.size(); ++i) { const std::string &fixed_source = fixed_sources[i]; - const absl::string_view expected_fixed_source = + const std::string_view expected_fixed_source = *(expected_fixed_sources.begin() + i); EXPECT_EQ(fixed_source, expected_fixed_source); @@ -605,7 +605,7 @@ class ViolationFixerTest : public testing::Test { std::vector fixed_sources(input_sources.size()); for (size_t i = 0; i < input_sources.size(); ++i) { - const absl::string_view input_source = input_sources[i]; + const std::string_view input_source = input_sources[i]; std::string &fixed_source = fixed_sources[i]; const absl::Status status = @@ -619,9 +619,9 @@ class ViolationFixerTest : public testing::Test { bool expect_empty_patch = true; for (size_t i = 0; i < input_sources.size(); ++i) { - const absl::string_view input_source = input_sources[i]; + const std::string_view input_source = input_sources[i]; const std::string &fixed_source = fixed_sources[i]; - const absl::string_view expected_fixed_source = + const std::string_view expected_fixed_source = *(expected_fixed_sources.begin() + i); EXPECT_EQ(input_source, fixed_source); diff --git a/verible/verilog/analysis/verilog-project.cc b/verible/verilog/analysis/verilog-project.cc index 1a4bfd88b..a9357ecc4 100644 --- a/verible/verilog/analysis/verilog-project.cc +++ b/verible/verilog/analysis/verilog-project.cc @@ -18,13 +18,13 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "absl/types/optional.h" @@ -43,7 +43,7 @@ static constexpr verilog::VerilogPreprocess::Config kPreprocessConfig{ .filter_branches = true, }; -VerilogSourceFile::VerilogSourceFile(absl::string_view referenced_path, +VerilogSourceFile::VerilogSourceFile(std::string_view referenced_path, const absl::Status &status) : referenced_path_(referenced_path), status_(status) {} @@ -62,7 +62,7 @@ absl::Status VerilogSourceFile::Open() { return status_; // status_ is Ok here. } -absl::string_view VerilogSourceFile::GetContent() const { +std::string_view VerilogSourceFile::GetContent() const { return content_ ? content_->AsStringView() : ""; } @@ -121,7 +121,7 @@ std::ostream &operator<<(std::ostream &stream, void VerilogProject::ContentToFileIndex::Register( const VerilogSourceFile *file) { CHECK(file); - const absl::string_view content = file->GetContent(); + const std::string_view content = file->GetContent(); string_view_map_.must_emplace(content); const auto map_inserted = buffer_to_analyzer_map_.emplace(content.begin(), file); @@ -131,7 +131,7 @@ void VerilogProject::ContentToFileIndex::Register( void VerilogProject::ContentToFileIndex::Unregister( const VerilogSourceFile *file) { CHECK(file); - const absl::string_view content = file->GetContent(); + const std::string_view content = file->GetContent(); auto full_content_found = string_view_map_.find(content); if (full_content_found != string_view_map_.end()) { string_view_map_.erase(full_content_found); @@ -140,11 +140,11 @@ void VerilogProject::ContentToFileIndex::Unregister( } const VerilogSourceFile *VerilogProject::ContentToFileIndex::Lookup( - absl::string_view content_substring) const { + std::string_view content_substring) const { // Look for corresponding source text (superstring) buffer start. const auto found_superstring = string_view_map_.find(content_substring); if (found_superstring == string_view_map_.end()) return nullptr; - const absl::string_view::const_iterator buffer_start = + const std::string_view::const_iterator buffer_start = found_superstring->first; // Reverse-lookup originating file based on buffer start. @@ -155,8 +155,8 @@ const VerilogSourceFile *VerilogProject::ContentToFileIndex::Lookup( } absl::StatusOr VerilogProject::OpenFile( - absl::string_view referenced_filename, absl::string_view resolved_filename, - absl::string_view corpus) { + std::string_view referenced_filename, std::string_view resolved_filename, + std::string_view corpus) { const auto inserted = files_.emplace( referenced_filename, std::make_unique( referenced_filename, resolved_filename, corpus)); @@ -184,7 +184,7 @@ bool VerilogProject::RemoveByName(const std::string &filename) { // TODO: explain better in the header what happens with includes. bool VerilogProject::RemoveRegisteredFile( - absl::string_view referenced_filename) { + std::string_view referenced_filename) { if (RemoveByName(std::string(referenced_filename))) { LOG(INFO) << "Removed " << referenced_filename << " from the project."; return true; @@ -201,7 +201,7 @@ bool VerilogProject::RemoveRegisteredFile( } std::string VerilogProject::GetRelativePathToSource( - const absl::string_view absolute_filepath) { + const std::string_view absolute_filepath) { // TODO add check if the absolute_filepath is out of the VerilogProject std::filesystem::path absolutepath{absolute_filepath.begin(), absolute_filepath.end()}; @@ -212,8 +212,8 @@ std::string VerilogProject::GetRelativePathToSource( } void VerilogProject::UpdateFileContents( - absl::string_view path, const verilog::VerilogAnalyzer *parsed) { - constexpr absl::string_view kCorpus; + std::string_view path, const verilog::VerilogAnalyzer *parsed) { + constexpr std::string_view kCorpus; const std::string projectpath = GetRelativePathToSource(path); // If we get a non-null parsed file, use that, otherwise fall back to @@ -245,7 +245,7 @@ void VerilogProject::UpdateFileContents( } VerilogSourceFile *VerilogProject::LookupRegisteredFileInternal( - absl::string_view referenced_filename) const { + std::string_view referenced_filename) const { const auto opened_file = FindOpenedFile(referenced_filename); if (opened_file) { if (!opened_file->ok()) { @@ -267,7 +267,7 @@ VerilogSourceFile *VerilogProject::LookupRegisteredFileInternal( } absl::optional> -VerilogProject::FindOpenedFile(absl::string_view filename) const { +VerilogProject::FindOpenedFile(std::string_view filename) const { const auto found = files_.find(filename); if (found != files_.end()) { if (absl::Status status = found->second->Status(); !status.ok()) { @@ -279,7 +279,7 @@ VerilogProject::FindOpenedFile(absl::string_view filename) const { } absl::StatusOr VerilogProject::OpenTranslationUnit( - absl::string_view referenced_filename) { + std::string_view referenced_filename) { // Check for a pre-existing entry to avoid duplicate files. { const auto opened_file = FindOpenedFile(referenced_filename); @@ -303,14 +303,14 @@ absl::StatusOr VerilogProject::OpenTranslationUnit( } absl::Status VerilogProject::IncludeFileNotFoundError( - absl::string_view referenced_filename) const { + std::string_view referenced_filename) const { return absl::NotFoundError( absl::StrCat("'", referenced_filename, "' not in any of the ", include_paths_.size(), " include paths")); } absl::StatusOr VerilogProject::OpenIncludedFile( - absl::string_view referenced_filename) { + std::string_view referenced_filename) { VLOG(2) << __FUNCTION__ << ", referenced: " << referenced_filename; // Check for a pre-existing entry to avoid duplicate files. { @@ -351,8 +351,8 @@ absl::StatusOr VerilogProject::OpenIncludedFile( return inserted.first->second->Status(); } -void VerilogProject::AddVirtualFile(absl::string_view resolved_filename, - absl::string_view content) { +void VerilogProject::AddVirtualFile(std::string_view resolved_filename, + std::string_view content) { const auto inserted = files_.emplace( resolved_filename, std::make_unique( @@ -367,7 +367,7 @@ void VerilogProject::AddVirtualFile(absl::string_view resolved_filename, } const VerilogSourceFile *VerilogProject::LookupFileOrigin( - absl::string_view content_substring) const { + std::string_view content_substring) const { CHECK(content_index_) << "LookupFileOrigin() not enabled in constructor"; return content_index_->Lookup(content_substring); } diff --git a/verible/verilog/analysis/verilog-project.h b/verible/verilog/analysis/verilog-project.h index 992b4ce4c..d5f061fcb 100644 --- a/verible/verilog/analysis/verilog-project.h +++ b/verible/verilog/analysis/verilog-project.h @@ -21,12 +21,12 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "verible/common/strings/mem-block.h" #include "verible/common/strings/string-memory-map.h" @@ -40,15 +40,15 @@ class VerilogProject; // A read-only view of a single Verilog source file. class VerilogSourceFile { public: - VerilogSourceFile(absl::string_view referenced_path, - absl::string_view resolved_path, absl::string_view corpus) + VerilogSourceFile(std::string_view referenced_path, + std::string_view resolved_path, std::string_view corpus) : referenced_path_(referenced_path), resolved_path_(resolved_path), corpus_(corpus) {} // When a file is not found among a set of paths, remember it with an // error status. - VerilogSourceFile(absl::string_view referenced_path, + VerilogSourceFile(std::string_view referenced_path, const absl::Status &status); VerilogSourceFile(const VerilogSourceFile &) = delete; @@ -65,7 +65,7 @@ class VerilogSourceFile { virtual absl::Status Open(); // After successful Open(), the content is filled; empty otherwise. - virtual absl::string_view GetContent() const; + virtual std::string_view GetContent() const; // Attempts to lex and parse the file. // Will Open() if the file is not already opened. @@ -89,14 +89,14 @@ class VerilogSourceFile { std::vector ErrorMessages() const; // Returns the name used to reference the file. - absl::string_view ReferencedPath() const { return referenced_path_; } + std::string_view ReferencedPath() const { return referenced_path_; } // Returns the corpus to which this file belongs (e.g., // github.com/chipsalliance/verible). - absl::string_view Corpus() const { return corpus_; } + std::string_view Corpus() const { return corpus_; } // Returns a (possibly more qualified) path to the file. - absl::string_view ResolvedPath() const { return resolved_path_; } + std::string_view ResolvedPath() const { return resolved_path_; } // Comparator for ordering files for internal storage. // Known limitation: this comparator won't work if you have multiple files @@ -104,16 +104,16 @@ class VerilogSourceFile { struct Less { using is_transparent = void; // hetergenous compare - static absl::string_view to_string_view(absl::string_view s) { return s; } - static absl::string_view to_string_view(const VerilogSourceFile &f) { + static std::string_view to_string_view(std::string_view s) { return s; } + static std::string_view to_string_view(const VerilogSourceFile &f) { return f.ReferencedPath(); } - static absl::string_view to_string_view(const VerilogSourceFile *f) { + static std::string_view to_string_view(const VerilogSourceFile *f) { return f->ReferencedPath(); } // T1/T2 could be any combination of: - // {const VerilogSourceFile&, absl::string_view}. + // {const VerilogSourceFile&, std::string_view}. template bool operator()(T1 left, T2 right) const { return to_string_view(left) < to_string_view(right); @@ -150,7 +150,7 @@ class VerilogSourceFile { // The corpus to which this file belongs to (e.g., // github.com/chipsalliance/verible). - const absl::string_view corpus_; + const std::string_view corpus_; // Linear progression of analysis. ProcessingState processing_state_ = ProcessingState::kInitialized; @@ -173,9 +173,9 @@ std::ostream &operator<<(std::ostream &, const VerilogSourceFile &); class InMemoryVerilogSourceFile final : public VerilogSourceFile { public: // filename can be fake, it is not used to open any file. - InMemoryVerilogSourceFile(absl::string_view filename, + InMemoryVerilogSourceFile(std::string_view filename, std::shared_ptr content, - absl::string_view corpus = "") + std::string_view corpus = "") : VerilogSourceFile(filename, filename, corpus) { content_ = std::move(content); processing_state_ = ProcessingState::kOpened; // Advance state @@ -183,9 +183,9 @@ class InMemoryVerilogSourceFile final : public VerilogSourceFile { } // Legacy - InMemoryVerilogSourceFile(absl::string_view filename, - absl::string_view contents, - absl::string_view corpus = "") + InMemoryVerilogSourceFile(std::string_view filename, + std::string_view contents, + std::string_view corpus = "") : InMemoryVerilogSourceFile( filename, std::make_shared(contents), corpus) {} @@ -203,10 +203,10 @@ class ParsedVerilogSourceFile final : public VerilogSourceFile { // Construct with an already existing VerilogAnalyzer that already // parsed its content. // Ownership if "analyzer" is not taken over, must outlive this objet. - ParsedVerilogSourceFile(absl::string_view referenced_path, - absl::string_view resolved_path, + ParsedVerilogSourceFile(std::string_view referenced_path, + std::string_view resolved_path, const verilog::VerilogAnalyzer &analyzer, - absl::string_view corpus = "") + std::string_view corpus = "") : VerilogSourceFile(referenced_path, resolved_path, corpus), not_owned_analyzer_(&analyzer) { processing_state_ = ProcessingState::kParsed; // Advance to full parsed. @@ -225,7 +225,7 @@ class ParsedVerilogSourceFile final : public VerilogSourceFile { } // Return string-view content range of text structure. - absl::string_view GetContent() const final { + std::string_view GetContent() const final { return not_owned_analyzer_->Data().Contents(); } @@ -252,9 +252,9 @@ class VerilogProject { // Construct VerilogProject with a choice of allowing to look up file // origin. - VerilogProject(absl::string_view root, + VerilogProject(std::string_view root, const std::vector &include_paths, - absl::string_view corpus = "", + std::string_view corpus = "", bool provide_lookup_file_origin = true) : translation_unit_root_(root), corpus_(corpus), @@ -274,52 +274,52 @@ class VerilogProject { iterator end() { return files_.end(); } // Returns the directory to which translation units are referenced relatively. - absl::string_view TranslationUnitRoot() const { + std::string_view TranslationUnitRoot() const { return translation_unit_root_; } // Returns the corpus to which this project belongs to. - absl::string_view Corpus() const { return corpus_; } + std::string_view Corpus() const { return corpus_; } // Opens a single top-level file, known as a "translation unit". // This uses translation_unit_root_ directory to calculate the file's path. // If the file was previously opened, that data is returned. absl::StatusOr OpenTranslationUnit( - absl::string_view referenced_filename); + std::string_view referenced_filename); // Opens a file that was `included. // If the file was previously opened, that data is returned. absl::StatusOr OpenIncludedFile( - absl::string_view referenced_filename); + std::string_view referenced_filename); // Adds an already opened file by directly passing its content. // This is needed in external kythe backends. - void AddVirtualFile(absl::string_view resolved_filename, - absl::string_view content); + void AddVirtualFile(std::string_view resolved_filename, + std::string_view content); // Returns a previously referenced file, or else nullptr. VerilogSourceFile *LookupRegisteredFile( - absl::string_view referenced_filename) { + std::string_view referenced_filename) { return LookupRegisteredFileInternal(referenced_filename); } // Removes the file from project and releases the resources. Returns true if // the file was removed. - bool RemoveRegisteredFile(absl::string_view referenced_filename); + bool RemoveRegisteredFile(std::string_view referenced_filename); // Non-modifying variant of lookup. const VerilogSourceFile *LookupRegisteredFile( - absl::string_view referenced_filename) const { + std::string_view referenced_filename) const { return LookupRegisteredFileInternal(referenced_filename); } // Find the source file that a particular string_view came from. // Returns nullptr if lookup failed for any reason. const VerilogSourceFile *LookupFileOrigin( - absl::string_view content_substring) const; + std::string_view content_substring) const; // Returns relative path to the VerilogProject - std::string GetRelativePathToSource(absl::string_view absolute_filepath); + std::string GetRelativePathToSource(std::string_view absolute_filepath); // Updates file from external source with an already parsed content. // (e.g. Language Server). @@ -328,11 +328,11 @@ class VerilogProject { // If "parsed" is nullptr, the old parsed file is removed and replaced // with a standard VerilogSourceFile, reading from a filesystem. // (TODO: this is a fairly specific functionality; make this composed). - void UpdateFileContents(absl::string_view path, + void UpdateFileContents(std::string_view path, const verilog::VerilogAnalyzer *parsed); // Adds include directory to the project - void AddIncludePath(absl::string_view includepath) { + void AddIncludePath(std::string_view includepath) { std::string path = {includepath.begin(), includepath.end()}; if (std::find(include_paths_.begin(), include_paths_.end(), path) == include_paths_.end()) { @@ -342,21 +342,21 @@ class VerilogProject { private: absl::StatusOr OpenFile( - absl::string_view referenced_filename, - absl::string_view resolved_filename, absl::string_view corpus); + std::string_view referenced_filename, std::string_view resolved_filename, + std::string_view corpus); // Error status factory, when include file is not found. absl::Status IncludeFileNotFoundError( - absl::string_view referenced_filename) const; + std::string_view referenced_filename) const; // Returns a previously referenced file, or else nullptr. VerilogSourceFile *LookupRegisteredFileInternal( - absl::string_view referenced_filename) const; + std::string_view referenced_filename) const; // Returns the opened file or parse/not found error. If the file is not // opened, returns nullopt. absl::optional> FindOpenedFile( - absl::string_view filename) const; + std::string_view filename) const; // Attempt to remove file and metadata if it exists. Return 'true' on success. bool RemoveByName(const std::string &filename); @@ -389,7 +389,7 @@ class VerilogProject { // Given a memory subrange of any of the indexed files, return the // corresponding file or nullptr if none of the files contains that range. - const VerilogSourceFile *Lookup(absl::string_view content_substring) const; + const VerilogSourceFile *Lookup(std::string_view content_substring) const; private: // Maps any string_view (substring) to its full source file text @@ -399,7 +399,7 @@ class VerilogProject { // Maps start of text buffer to its corresponding analyzer object. // key: the starting address of a string buffer belonging to an opened file. // This can come from the .begin() of any entry in string_view_map_. - std::map + std::map buffer_to_analyzer_map_; }; diff --git a/verible/verilog/analysis/verilog-project_test.cc b/verible/verilog/analysis/verilog-project_test.cc index c136644a5..c4d34cbf8 100644 --- a/verible/verilog/analysis/verilog-project_test.cc +++ b/verible/verilog/analysis/verilog-project_test.cc @@ -17,12 +17,12 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/text-structure.h" #include "verible/common/util/file-util.h" @@ -42,7 +42,7 @@ using verible::file::testing::ScopedTestFile; class TempDirFile : public ScopedTestFile { public: - explicit TempDirFile(absl::string_view content) + explicit TempDirFile(std::string_view content) : ScopedTestFile(::testing::TempDir(), content) {} }; @@ -56,15 +56,15 @@ TEST(VerilogSourceFileTest, Initialization) { } TEST(VerilogSourceFileTest, OpenExistingFile) { - constexpr absl::string_view text("localparam int p = 1;\n"); + constexpr std::string_view text("localparam int p = 1;\n"); TempDirFile tf(text); - const absl::string_view basename(Basename(tf.filename())); + const std::string_view basename(Basename(tf.filename())); VerilogSourceFile file(basename, tf.filename(), ""); EXPECT_TRUE(file.Open().ok()); EXPECT_TRUE(file.Status().ok()); EXPECT_EQ(file.ReferencedPath(), basename); EXPECT_EQ(file.ResolvedPath(), tf.filename()); - const absl::string_view owned_string_range(file.GetContent()); + const std::string_view owned_string_range(file.GetContent()); EXPECT_EQ(owned_string_range, text); // Re-opening doesn't change anything @@ -85,16 +85,16 @@ TEST(VerilogSourceFileTest, NonExistingFile) { } TEST(VerilogSourceFileTest, ParseValidFile) { - constexpr absl::string_view text("localparam int p = 1;\n"); + constexpr std::string_view text("localparam int p = 1;\n"); TempDirFile tf(text); - const absl::string_view basename(Basename(tf.filename())); + const std::string_view basename(Basename(tf.filename())); VerilogSourceFile file(basename, tf.filename(), ""); // Parse automatically opens. EXPECT_TRUE(file.Parse().ok()); EXPECT_TRUE(file.Status().ok()); const TextStructureView *text_structure = ABSL_DIE_IF_NULL(file.GetTextStructure()); - const absl::string_view owned_string_range(text_structure->Contents()); + const std::string_view owned_string_range(text_structure->Contents()); EXPECT_EQ(owned_string_range, text); const auto *tokens = &text_structure->TokenStream(); EXPECT_NE(tokens, nullptr); @@ -110,16 +110,16 @@ TEST(VerilogSourceFileTest, ParseValidFile) { } TEST(VerilogSourceFileTest, ParseInvalidFile) { - constexpr absl::string_view text("localparam 1 = p;\n"); + constexpr std::string_view text("localparam 1 = p;\n"); TempDirFile tf(text); - const absl::string_view basename(Basename(tf.filename())); + const std::string_view basename(Basename(tf.filename())); VerilogSourceFile file(basename, tf.filename(), ""); // Parse automatically opens. EXPECT_FALSE(file.Parse().ok()); EXPECT_FALSE(file.Status().ok()); const TextStructureView *text_structure = ABSL_DIE_IF_NULL(file.GetTextStructure()); - const absl::string_view owned_string_range(text_structure->Contents()); + const std::string_view owned_string_range(text_structure->Contents()); EXPECT_EQ(owned_string_range, text); const auto *tokens = &text_structure->TokenStream(); EXPECT_NE(tokens, nullptr); @@ -136,9 +136,9 @@ TEST(VerilogSourceFileTest, ParseInvalidFile) { } TEST(VerilogSourceFileTest, StreamPrint) { - constexpr absl::string_view text("localparam foo = bar;\n"); + constexpr std::string_view text("localparam foo = bar;\n"); TempDirFile tf(text); - const absl::string_view basename(Basename(tf.filename())); + const std::string_view basename(Basename(tf.filename())); VerilogSourceFile file(basename, tf.filename(), ""); { @@ -163,14 +163,14 @@ TEST(VerilogSourceFileTest, StreamPrint) { } TEST(InMemoryVerilogSourceFileTest, ParseValidFile) { - constexpr absl::string_view text("localparam int p = 1;\n"); + constexpr std::string_view text("localparam int p = 1;\n"); InMemoryVerilogSourceFile file("/not/using/file/system.v", text); // Parse automatically opens. EXPECT_TRUE(file.Parse().ok()); EXPECT_TRUE(file.Status().ok()); const TextStructureView *text_structure = ABSL_DIE_IF_NULL(file.GetTextStructure()); - const absl::string_view owned_string_range(text_structure->Contents()); + const std::string_view owned_string_range(text_structure->Contents()); EXPECT_EQ(owned_string_range, text); const auto *tokens = &text_structure->TokenStream(); EXPECT_NE(tokens, nullptr); @@ -186,14 +186,14 @@ TEST(InMemoryVerilogSourceFileTest, ParseValidFile) { } TEST(InMemoryVerilogSourceFileTest, ParseInvalidFile) { - constexpr absl::string_view text("class \"dismissed\"!\n"); + constexpr std::string_view text("class \"dismissed\"!\n"); InMemoryVerilogSourceFile file("/not/using/file/system.v", text); // Parse automatically opens. EXPECT_FALSE(file.Parse().ok()); EXPECT_FALSE(file.Status().ok()); const TextStructureView *text_structure = ABSL_DIE_IF_NULL(file.GetTextStructure()); - const absl::string_view owned_string_range(text_structure->Contents()); + const std::string_view owned_string_range(text_structure->Contents()); EXPECT_EQ(owned_string_range, text); const auto *tokens = &text_structure->TokenStream(); EXPECT_NE(tokens, nullptr); @@ -210,7 +210,7 @@ TEST(InMemoryVerilogSourceFileTest, ParseInvalidFile) { } TEST(ParsedVerilogSourceFileTest, PreparsedValidFile) { - constexpr absl::string_view text("localparam int p = 1;\n"); + constexpr std::string_view text("localparam int p = 1;\n"); std::unique_ptr analyzed_structure = std::make_unique(text, "internal"); absl::Status status = analyzed_structure->Analyze(); @@ -223,7 +223,7 @@ TEST(ParsedVerilogSourceFileTest, PreparsedValidFile) { const TextStructureView *text_structure = ABSL_DIE_IF_NULL(file.GetTextStructure()); EXPECT_EQ(&analyzed_structure->Data(), text_structure); - const absl::string_view owned_string_range(text_structure->Contents()); + const std::string_view owned_string_range(text_structure->Contents()); EXPECT_EQ(owned_string_range, text); const auto *tokens = &text_structure->TokenStream(); EXPECT_NE(tokens, nullptr); @@ -239,7 +239,7 @@ TEST(ParsedVerilogSourceFileTest, PreparsedValidFile) { } TEST(ParsedVerilogSourceFileTest, PreparsedInvalidValidFile) { - constexpr absl::string_view text("localp_TYPO_aram int p = 1;\n"); + constexpr std::string_view text("localp_TYPO_aram int p = 1;\n"); std::unique_ptr analyzed_structure = std::make_unique(text, "internal"); absl::Status status = analyzed_structure->Analyze(); @@ -252,7 +252,7 @@ TEST(ParsedVerilogSourceFileTest, PreparsedInvalidValidFile) { const TextStructureView *text_structure = ABSL_DIE_IF_NULL(file.GetTextStructure()); EXPECT_EQ(&analyzed_structure->Data(), text_structure); - const absl::string_view owned_string_range(text_structure->Contents()); + const std::string_view owned_string_range(text_structure->Contents()); EXPECT_EQ(owned_string_range, text); } @@ -299,15 +299,15 @@ TEST(VerilogProjectTest, UpdateFileContents) { VerilogProject project(project_root_dir, {}); // Prepare file to be auto-loaded later - constexpr absl::string_view file_content("module foo();\nendmodule\n"); + constexpr std::string_view file_content("module foo();\nendmodule\n"); const ScopedTestFile tf(project_root_dir, file_content); - const absl::string_view reference_name = Basename(tf.filename()); + const std::string_view reference_name = Basename(tf.filename()); VerilogSourceFile *from_file; - absl::string_view search_substring; + std::string_view search_substring; // Push a local analyzed name under the name of the file. - constexpr absl::string_view external_content("localparam int p = 1;\n"); + constexpr std::string_view external_content("localparam int p = 1;\n"); std::unique_ptr analyzed_structure = std::make_unique(external_content, "internal"); project.UpdateFileContents(tf.filename(), analyzed_structure.get()); @@ -348,17 +348,17 @@ TEST(VerilogProjectTest, UpdateFileContentsEmptyFile) { // Prepare file to be auto-loaded later const ScopedTestFile tf(project_root_dir, ""); - const absl::string_view reference_name = Basename(tf.filename()); + const std::string_view reference_name = Basename(tf.filename()); // Push a local analyzed name under the name of the file. - constexpr absl::string_view external_content("localparam int p = 1;\n"); + constexpr std::string_view external_content("localparam int p = 1;\n"); std::unique_ptr analyzed_structure = std::make_unique(external_content, "internal"); project.UpdateFileContents(tf.filename(), analyzed_structure.get()); // Look up the file and see that content is the external content VerilogSourceFile *from_file; - absl::string_view search_substring; + std::string_view search_substring; from_file = *project.OpenTranslationUnit(reference_name); EXPECT_EQ(from_file->GetContent(), external_content); @@ -367,10 +367,9 @@ TEST(VerilogProjectTest, UpdateFileContentsEmptyFile) { EXPECT_EQ(project.LookupFileOrigin(search_substring), from_file); // Prepare an empty file - constexpr absl::string_view empty_file_content; + constexpr std::string_view empty_file_content; const ScopedTestFile empty_file(project_root_dir, empty_file_content); - const absl::string_view empty_file_reference = - Basename(empty_file.filename()); + const std::string_view empty_file_reference = Basename(empty_file.filename()); // Push the empty file into the project std::unique_ptr analyzed_empty_structure = @@ -404,7 +403,7 @@ TEST(VerilogProjectTest, LookupFileOriginTest) { // no files yet { - constexpr absl::string_view foreign_text("not from any file"); + constexpr std::string_view foreign_text("not from any file"); EXPECT_EQ(project.LookupFileOrigin(foreign_text), nullptr); } @@ -413,10 +412,10 @@ TEST(VerilogProjectTest, LookupFileOriginTest) { const auto status_or_file = project.OpenTranslationUnit(Basename(tf.filename())); VerilogSourceFile *verilog_source_file = *status_or_file; - const absl::string_view content1(verilog_source_file->GetContent()); + const std::string_view content1(verilog_source_file->GetContent()); { - constexpr absl::string_view foreign_text("still not from any file"); + constexpr std::string_view foreign_text("still not from any file"); EXPECT_EQ(project.LookupFileOrigin(foreign_text), nullptr); } @@ -429,7 +428,7 @@ TEST(VerilogProjectTest, LookupFileOriginTest) { const auto status_or_file2 = project.OpenTranslationUnit(Basename(tf2.filename())); VerilogSourceFile *verilog_source_file2 = *status_or_file2; - const absl::string_view content2(verilog_source_file2->GetContent()); + const std::string_view content2(verilog_source_file2->GetContent()); // Pick substrings known to come from those files. EXPECT_EQ(project.LookupFileOrigin(content1.substr(5, 5)), @@ -446,7 +445,7 @@ TEST(VerilogProjectTest, LookupFileOriginTestMoreFiles) { VerilogProject project(sources_dir, {}); // no files yet - constexpr absl::string_view foreign_text("not from any file"); + constexpr std::string_view foreign_text("not from any file"); // WArning: Test size is quadratic in N, but linear in memory in N. constexpr int N = 50; @@ -479,7 +478,7 @@ TEST(VerilogProjectTest, ValidTranslationUnit) { EXPECT_TRUE(CreateDir(includes_dir).ok()); VerilogProject project(sources_dir, {includes_dir}); - constexpr absl::string_view text("module m;\nendmodule\n"); + constexpr std::string_view text("module m;\nendmodule\n"); const ScopedTestFile tf(sources_dir, text); const auto status_or_file = project.OpenTranslationUnit(Basename(tf.filename())); @@ -489,7 +488,7 @@ TEST(VerilogProjectTest, ValidTranslationUnit) { EXPECT_EQ(verilog_source_file->ResolvedPath(), tf.filename()); EXPECT_EQ(project.LookupRegisteredFile(Basename(tf.filename())), verilog_source_file); - const absl::string_view content(verilog_source_file->GetContent()); + const std::string_view content(verilog_source_file->GetContent()); { // const-lookup overload const VerilogProject &cproject(project); EXPECT_EQ(cproject.LookupRegisteredFile(Basename(tf.filename())), @@ -536,9 +535,9 @@ TEST(VerilogProjectTest, ValidIncludeFile) { EXPECT_TRUE(CreateDir(includes_dir).ok()); VerilogProject project(sources_dir, {includes_dir}); - constexpr absl::string_view text("`define FOO 1\n"); + constexpr std::string_view text("`define FOO 1\n"); const ScopedTestFile tf(includes_dir, text); - const absl::string_view basename(Basename(tf.filename())); + const std::string_view basename(Basename(tf.filename())); const auto status_or_file = project.OpenIncludedFile(basename); VerilogSourceFile *verilog_source_file = *status_or_file; EXPECT_TRUE(verilog_source_file->Status().ok()); @@ -577,7 +576,7 @@ TEST(VerilogProjectTest, OpenVirtualIncludeFile) { EXPECT_TRUE(CreateDir(includes_dir).ok()); VerilogProject project(sources_dir, {includes_dir}); - constexpr absl::string_view text("`define FOO 1\n"); + constexpr std::string_view text("`define FOO 1\n"); const std::string basename = "virtual_include_file1"; const std::string full_path = JoinPath(includes_dir, basename); // The virtual file is added by its full path. But the include is opened by @@ -620,7 +619,7 @@ TEST(VerilogProjectTest, TranslationUnitNotFound) { EXPECT_TRUE(CreateDir(includes_dir).ok()); VerilogProject project(sources_dir, {includes_dir}); - constexpr absl::string_view text("module m;\nendmodule\n"); + constexpr std::string_view text("module m;\nendmodule\n"); // deliberately plant this file in the includes dir != sources dir const ScopedTestFile tf(includes_dir, text); { @@ -643,7 +642,7 @@ TEST(VerilogProjectTest, IncludeFileNotFound) { EXPECT_TRUE(CreateDir(includes_dir).ok()); VerilogProject project(sources_dir, {includes_dir}); - constexpr absl::string_view text("module m;\nendmodule\n"); + constexpr std::string_view text("module m;\nendmodule\n"); // deliberately plant this file in the sources dir != include dir const ScopedTestFile tf(sources_dir, text); { diff --git a/verible/verilog/formatting/BUILD b/verible/verilog/formatting/BUILD index 7860192d9..e6654b593 100644 --- a/verible/verilog/formatting/BUILD +++ b/verible/verilog/formatting/BUILD @@ -38,7 +38,6 @@ cc_library( "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/parser:verilog-token-classifications", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -78,7 +77,6 @@ cc_library( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/base:core_headers", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -100,7 +98,6 @@ cc_test( "//verible/verilog/analysis:verilog-analyzer", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -175,7 +172,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -195,7 +191,6 @@ cc_test( "//verible/verilog/analysis:verilog-analyzer", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -210,7 +205,6 @@ cc_test( "//verible/common/strings:position", "//verible/common/util:logging", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -234,7 +228,6 @@ cc_library( "//verible/verilog/parser:verilog-token-classifications", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -248,7 +241,6 @@ cc_test( "//verible/common/text:token-info-test-util", "//verible/verilog/analysis:verilog-analyzer", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -296,7 +288,6 @@ cc_library( "//verible/verilog/parser:verilog-parser", "//verible/verilog/parser:verilog-token-classifications", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -321,7 +312,6 @@ cc_test( "//verible/common/util:logging", "//verible/verilog/CST:verilog-nonterminals", "//verible/verilog/parser:verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/verilog/formatting/align.cc b/verible/verilog/formatting/align.cc index 05a3ca7d4..96aba27d9 100644 --- a/verible/verilog/formatting/align.cc +++ b/verible/verilog/formatting/align.cc @@ -18,9 +18,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/align.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/token-partition-tree.h" @@ -1541,7 +1541,7 @@ static std::vector AlignDistItems( } void TabularAlignTokenPartitions(const FormatStyle &style, - absl::string_view full_text, + std::string_view full_text, const ByteOffsetSet &disabled_byte_ranges, TokenPartitionTree *partition_ptr) { VLOG(1) << __FUNCTION__; diff --git a/verible/verilog/formatting/align.h b/verible/verilog/formatting/align.h index 9b17b115b..166b49f31 100644 --- a/verible/verilog/formatting/align.h +++ b/verible/verilog/formatting/align.h @@ -15,7 +15,8 @@ #ifndef VERIBLE_VERILOG_FORMATTING_ALIGN_H_ #define VERIBLE_VERILOG_FORMATTING_ALIGN_H_ -#include "absl/strings/string_view.h" +#include + #include "verible/common/formatting/token-partition-tree.h" #include "verible/common/strings/position.h" // for ByteOffsetSet #include "verible/verilog/formatting/format-style.h" @@ -27,7 +28,7 @@ namespace formatter { // tokens by inserting padding-spaces. // TODO(fangism): pass in disabled formatting ranges void TabularAlignTokenPartitions( - const FormatStyle &style, absl::string_view full_text, + const FormatStyle &style, std::string_view full_text, const verible::ByteOffsetSet &disabled_byte_ranges, verible::TokenPartitionTree *partition_ptr); diff --git a/verible/verilog/formatting/comment-controls.cc b/verible/verilog/formatting/comment-controls.cc index ce195f423..8cc43623e 100644 --- a/verible/verilog/formatting/comment-controls.cc +++ b/verible/verilog/formatting/comment-controls.cc @@ -18,10 +18,10 @@ #include #include #include +#include #include #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "verible/common/strings/comment-utils.h" #include "verible/common/strings/display-utils.h" @@ -42,9 +42,9 @@ namespace formatter { using verible::ByteOffsetSet; using verible::EscapeString; -ByteOffsetSet DisableFormattingRanges(absl::string_view text, +ByteOffsetSet DisableFormattingRanges(std::string_view text, const verible::TokenSequence &tokens) { - static constexpr absl::string_view kTrigger = "verilog_format:"; + static constexpr std::string_view kTrigger = "verilog_format:"; static const auto kDelimiters = absl::ByAnyChar(" \t"); static constexpr int kNullOffset = -1; const verible::TokenInfo::Context context( @@ -61,7 +61,7 @@ ByteOffsetSet DisableFormattingRanges(absl::string_view text, // Focus on the space-delimited tokens in the comment text. auto commands = verible::StripCommentAndSpacePadding(token.text()); if (absl::ConsumePrefix(&commands, kTrigger)) { - const std::vector comment_tokens( + const std::vector comment_tokens( absl::StrSplit(commands, kDelimiters, absl::SkipEmpty())); if (!comment_tokens.empty()) { // "off" marks the start of a disabling range, at end of comment. @@ -114,12 +114,12 @@ ByteOffsetSet EnabledLinesToDisabledByteRanges( return byte_offsets; } -static size_t NewlineCount(absl::string_view s) { +static size_t NewlineCount(std::string_view s) { return std::count(s.begin(), s.end(), '\n'); } void FormatWhitespaceWithDisabledByteRanges( - absl::string_view text_base, absl::string_view space_text, + std::string_view text_base, std::string_view space_text, const ByteOffsetSet &disabled_ranges, bool include_disabled_ranges, std::ostream &stream) { VLOG(3) << __FUNCTION__; @@ -148,14 +148,14 @@ void FormatWhitespaceWithDisabledByteRanges( for (const auto &range : enabled_ranges) { if (include_disabled_ranges) { // for disabled intervals, print the // original spacing - const absl::string_view disabled( + const std::string_view disabled( text_base.substr(next_start, range.first - next_start)); VLOG(3) << "output: \"" << EscapeString{disabled} << "\" (preserved)"; stream << disabled; total_enabled_newlines += NewlineCount(disabled); } { // for enabled intervals, preserve only newlines - const absl::string_view enabled( + const std::string_view enabled( text_base.substr(range.first, range.second - range.first)); const size_t newline_count = NewlineCount(enabled); VLOG(3) << "output: " << newline_count << "*\"\\n\" (formatted)"; @@ -167,7 +167,7 @@ void FormatWhitespaceWithDisabledByteRanges( } if (include_disabled_ranges) { // If there is a disabled interval left over, print that. - const absl::string_view final_disabled( + const std::string_view final_disabled( text_base.substr(next_start, end - next_start)); VLOG(3) << "output: \"" << EscapeString(final_disabled) << "\" (remaining disabled)"; diff --git a/verible/verilog/formatting/comment-controls.h b/verible/verilog/formatting/comment-controls.h index f357ce2dc..ed2347914 100644 --- a/verible/verilog/formatting/comment-controls.h +++ b/verible/verilog/formatting/comment-controls.h @@ -16,8 +16,8 @@ #define VERIBLE_VERILOG_FORMATTING_COMMENT_CONTROLS_H_ #include +#include -#include "absl/strings/string_view.h" #include "verible/common/strings/line-column-map.h" #include "verible/common/strings/position.h" // for ByteOffsetSet, LineNumberSet #include "verible/common/text/token-stream-view.h" @@ -28,7 +28,7 @@ namespace formatter { // Returns a representation of byte offsets where true (membership) means // formatting is disabled. verible::ByteOffsetSet DisableFormattingRanges( - absl::string_view text, const verible::TokenSequence &tokens); + std::string_view text, const verible::TokenSequence &tokens); // TODO(fangism): Move these next functions into common/formatting. // Same with the above types. @@ -46,7 +46,7 @@ verible::ByteOffsetSet EnabledLinesToDisabledByteRanges( // preserve. // Output is written to 'stream'. void FormatWhitespaceWithDisabledByteRanges( - absl::string_view text_base, absl::string_view space_text, + std::string_view text_base, std::string_view space_text, const verible::ByteOffsetSet &disabled_ranges, bool include_disabled_ranges, std::ostream &stream); diff --git a/verible/verilog/formatting/comment-controls_test.cc b/verible/verilog/formatting/comment-controls_test.cc index 8db9b5a2d..39fada2fa 100644 --- a/verible/verilog/formatting/comment-controls_test.cc +++ b/verible/verilog/formatting/comment-controls_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/strings/line-column-map.h" @@ -67,7 +67,7 @@ struct DisableRangeTestData : public TokenInfoTestData { : TokenInfoTestData{fragments} { // convert expected_tokens into expected ranges const auto tokens = FindImportantTokens(); - const absl::string_view base(code); + const std::string_view base(code); for (const auto &t : tokens) { expected.Add({t.left(base), t.right(base)}); } @@ -215,7 +215,7 @@ TEST(DisableFormattingRangesTest, FormatOffVarious) { } struct DisabledBytesTestCase { - absl::string_view text; + std::string_view text; LineNumberSet enabled_lines; ByteOffsetSet expected_bytes; }; @@ -318,14 +318,14 @@ TEST(EnabledLinesToDisabledByteRangesTest, AllCases) { } struct FormatWhitespaceTestCase { - absl::string_view full_text; + std::string_view full_text; std::pair substring_range; ByteOffsetSet disabled_ranges; - absl::string_view expected; + std::string_view expected; }; TEST(FormatWhitespaceWithDisabledByteRangesTest, InvalidSubstring) { - const absl::string_view foo("foo"), bar("bar"); + const std::string_view foo("foo"), bar("bar"); std::ostringstream stream; EXPECT_DEATH( FormatWhitespaceWithDisabledByteRanges(foo, bar, {}, true, stream), diff --git a/verible/verilog/formatting/formatter-tuning_test.cc b/verible/verilog/formatting/formatter-tuning_test.cc index d05d99366..a1e9c20dd 100644 --- a/verible/verilog/formatting/formatter-tuning_test.cc +++ b/verible/verilog/formatting/formatter-tuning_test.cc @@ -17,9 +17,9 @@ // prevent header re-ordering #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/strings/position.h" #include "verible/common/util/logging.h" @@ -36,8 +36,8 @@ namespace formatter { namespace { struct FormatterTestCase { - absl::string_view input; - absl::string_view expected; + std::string_view input; + std::string_view expected; }; static const verible::LineNumberSet kEnableAllLines; diff --git a/verible/verilog/formatting/formatter.cc b/verible/verilog/formatting/formatter.cc index ccc1c7a2b..8a99a0397 100644 --- a/verible/verilog/formatting/formatter.cc +++ b/verible/verilog/formatting/formatter.cc @@ -22,13 +22,13 @@ #include #include #include +#include #include #include "absl/base/attributes.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/layout-optimizer.h" #include "verible/common/formatting/line-wrap-searcher.h" @@ -116,8 +116,8 @@ class Formatter { // TODO(b/148482625): make this public/re-usable for general content comparison. Status VerifyFormatting(const verible::TextStructureView &text_structure, - absl::string_view formatted_output, - absl::string_view filename) { + std::string_view formatted_output, + std::string_view filename) { // Verify that the formatted output creates the same lexical // stream (filtered) as the original. If any tokens were lost, fall back to // printing the original source unformatted. @@ -163,9 +163,9 @@ Status VerifyFormatting(const verible::TextStructureView &text_structure, return absl::OkStatus(); } -static Status ReformatVerilogIncrementally(absl::string_view original_text, - absl::string_view formatted_text, - absl::string_view filename, +static Status ReformatVerilogIncrementally(std::string_view original_text, + std::string_view formatted_text, + std::string_view filename, const FormatStyle &style, std::ostream &reformat_stream, const ExecutionControl &control) { @@ -184,9 +184,9 @@ static Status ReformatVerilogIncrementally(absl::string_view original_text, formatted_lines, control); } -static Status ReformatVerilog(absl::string_view original_text, - absl::string_view formatted_text, - absl::string_view filename, +static Status ReformatVerilog(std::string_view original_text, + std::string_view formatted_text, + std::string_view filename, const FormatStyle &style, std::ostream &reformat_stream, const LineNumberSet &lines, @@ -207,7 +207,7 @@ static Status ReformatVerilog(absl::string_view original_text, } static absl::StatusOr> ParseWithStatus( - absl::string_view text, absl::string_view filename) { + std::string_view text, std::string_view filename) { std::unique_ptr analyzer = VerilogAnalyzer::AnalyzeAutomaticMode( text, filename, verilog::VerilogPreprocess::Config()); @@ -231,7 +231,7 @@ static absl::StatusOr> ParseWithStatus( } absl::Status FormatVerilog(const verible::TextStructureView &text_structure, - absl::string_view filename, const FormatStyle &style, + std::string_view filename, const FormatStyle &style, std::string *formatted_text, const verible::LineNumberSet &lines, const ExecutionControl &control) { @@ -269,7 +269,7 @@ absl::Status FormatVerilog(const verible::TextStructureView &text_structure, return format_status; } -Status FormatVerilog(absl::string_view text, absl::string_view filename, +Status FormatVerilog(std::string_view text, std::string_view filename, const FormatStyle &style, std::ostream &formatted_stream, const LineNumberSet &lines, const ExecutionControl &control) { @@ -349,8 +349,8 @@ absl::Status FormatVerilogRange(const verible::TextStructureView &structure, return absl::OkStatus(); } -absl::Status FormatVerilogRange(absl::string_view full_content, - absl::string_view filename, +absl::Status FormatVerilogRange(std::string_view full_content, + std::string_view filename, const FormatStyle &style, std::string *formatted_text, const verible::Interval &line_range, @@ -362,7 +362,7 @@ absl::Status FormatVerilogRange(absl::string_view full_content, } static verible::Interval DisableByteOffsetRange( - absl::string_view substring, absl::string_view superstring) { + std::string_view substring, std::string_view superstring) { CHECK(!substring.empty()); auto range = verible::SubstringOffsets(substring, superstring); // +1 so that formatting can still occur on the space before the start @@ -375,7 +375,7 @@ static verible::Interval DisableByteOffsetRange( static void DeterminePartitionExpansion( partition_node_type *node, std::vector *preformatted_tokens, - absl::string_view full_text, const ByteOffsetSet &disabled_ranges, + std::string_view full_text, const ByteOffsetSet &disabled_ranges, const FormatStyle &style) { auto &node_view = node->Value(); const UnwrappedLine &uwline = node_view.Value(); @@ -558,7 +558,7 @@ static void DeterminePartitionExpansion( // Produce a worklist of independently formattable UnwrappedLines. static std::vector MakeUnwrappedLinesWorklist( - const FormatStyle &style, absl::string_view full_text, + const FormatStyle &style, std::string_view full_text, const ByteOffsetSet &disabled_ranges, const TokenPartitionTree &format_tokens_partitions, std::vector *preformatted_tokens) { @@ -588,7 +588,7 @@ static std::vector MakeUnwrappedLinesWorklist( static void PrintLargestPartitions( std::ostream &stream, const TokenPartitionTree &token_partitions, size_t max_partitions, const verible::LineColumnMap &line_column_map, - absl::string_view base_text) { + std::string_view base_text) { stream << "Showing the " << max_partitions << " largest (leaf) token partitions:" << std::endl; const auto ranked_partitions = @@ -623,7 +623,7 @@ void Formatter::SelectLines(const LineNumberSet &lines) { static void DisableSyntaxBasedRanges(ByteOffsetSet *disabled_ranges, const verible::Symbol &root, const FormatStyle &style, - absl::string_view full_text) { + std::string_view full_text) { /** // Basic template: if (!style.controlling_flag) { @@ -657,7 +657,7 @@ class ContinuationCommentAligner { public: ContinuationCommentAligner(const verible::LineColumnMap &line_column_map, - const absl::string_view base_text) + const std::string_view base_text) : line_column_map_(line_column_map), base_text_(base_text) {} // Takes the next line that has to be formatted and a vector of already @@ -784,7 +784,7 @@ class ContinuationCommentAligner { } const verible::LineColumnMap &line_column_map_; - const absl::string_view base_text_; + const std::string_view base_text_; // Used when the most recenly handled line can't have a continuation comment. static constexpr int kInvalidColumn = -1; @@ -796,7 +796,7 @@ class ContinuationCommentAligner { }; Status Formatter::Format(const ExecutionControl &control) { - const absl::string_view full_text(text_structure_.Contents()); + const std::string_view full_text(text_structure_.Contents()); const auto &token_stream(text_structure_.TokenStream()); // Initialize auxiliary data needed for TreeUnwrapper. @@ -970,7 +970,7 @@ Status Formatter::Format(const ExecutionControl &control) { } void Formatter::Emit(bool include_disabled, std::ostream &stream) const { - const absl::string_view full_text(text_structure_.Contents()); + const std::string_view full_text(text_structure_.Contents()); std::function include_token_p; if (include_disabled) { include_token_p = [](const verible::TokenInfo &) { return true; }; @@ -988,7 +988,7 @@ void Formatter::Emit(bool include_disabled, std::ostream &stream) const { const auto front_offset = line.Tokens().empty() ? position : line.Tokens().front().token->left(full_text); - const absl::string_view leading_whitespace( + const std::string_view leading_whitespace( full_text.substr(position, front_offset - position)); FormatWhitespaceWithDisabledByteRanges(full_text, leading_whitespace, disabled_ranges_, include_disabled, @@ -1006,7 +1006,7 @@ void Formatter::Emit(bool include_disabled, std::ostream &stream) const { } // Handle trailing spaces after last token. - const absl::string_view trailing_whitespace(full_text.substr(position)); + const std::string_view trailing_whitespace(full_text.substr(position)); FormatWhitespaceWithDisabledByteRanges(full_text, trailing_whitespace, disabled_ranges_, include_disabled, stream); diff --git a/verible/verilog/formatting/formatter.h b/verible/verilog/formatting/formatter.h index 1651a7fe5..f2efe34b6 100644 --- a/verible/verilog/formatting/formatter.h +++ b/verible/verilog/formatting/formatter.h @@ -17,9 +17,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/position.h" #include "verible/common/text/text-structure.h" #include "verible/common/util/interval.h" @@ -73,7 +73,7 @@ struct ExecutionControl { // If this is empty, interpret as all lines enabled for formatting. // Does verification of the resulting format (re-parse and compare) and // convergence test (if enabled in "control") -absl::Status FormatVerilog(absl::string_view text, absl::string_view filename, +absl::Status FormatVerilog(std::string_view text, std::string_view filename, const FormatStyle &style, std::ostream &formatted_stream, const verible::LineNumberSet &lines = {}, @@ -81,7 +81,7 @@ absl::Status FormatVerilog(absl::string_view text, absl::string_view filename, // Ditto, but with TextStructureView as input and std::string as output. // This does verification of the resulting format, but _no_ convergence test. absl::Status FormatVerilog(const verible::TextStructureView &text_structure, - absl::string_view filename, const FormatStyle &style, + std::string_view filename, const FormatStyle &style, std::string *formatted_text, const verible::LineNumberSet &lines = {}, const ExecutionControl &control = {}); @@ -91,8 +91,8 @@ absl::Status FormatVerilog(const verible::TextStructureView &text_structure, // to "formatted_stream". // Used for interactive formatting, e.g. in editors and does not do convergence // tests. -absl::Status FormatVerilogRange(absl::string_view full_content, - absl::string_view filename, +absl::Status FormatVerilogRange(std::string_view full_content, + std::string_view filename, const FormatStyle &style, std::string *formatted_text, const verible::Interval &line_range, diff --git a/verible/verilog/formatting/formatter_test.cc b/verible/verilog/formatting/formatter_test.cc index df4b846ca..0150add93 100644 --- a/verible/verilog/formatting/formatter_test.cc +++ b/verible/verilog/formatting/formatter_test.cc @@ -25,12 +25,12 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/formatting/align.h" @@ -54,8 +54,8 @@ namespace formatter { // private, extern function in formatter.cc, directly tested here. absl::Status VerifyFormatting(const verible::TextStructureView &text_structure, - absl::string_view formatted_output, - absl::string_view filename); + std::string_view formatted_output, + std::string_view filename); namespace { @@ -69,7 +69,7 @@ using verible::LineNumberSet; // Tests that clean output passes. TEST(VerifyFormattingTest, NoError) { - const absl::string_view code("class c;endclass\n"); + const std::string_view code("class c;endclass\n"); const std::unique_ptr analyzer = VerilogAnalyzer::AnalyzeAutomaticMode(code, "", kDefaultPreprocess); const auto &text_structure = ABSL_DIE_IF_NULL(analyzer)->Data(); @@ -79,11 +79,11 @@ TEST(VerifyFormattingTest, NoError) { // Tests that un-lexable outputs are caught as errors. TEST(VerifyFormattingTest, LexError) { - const absl::string_view code("class c;endclass\n"); + const std::string_view code("class c;endclass\n"); const std::unique_ptr analyzer = VerilogAnalyzer::AnalyzeAutomaticMode(code, "", kDefaultPreprocess); const auto &text_structure = ABSL_DIE_IF_NULL(analyzer)->Data(); - const absl::string_view bad_code("1class c;endclass\n"); // lexical error + const std::string_view bad_code("1class c;endclass\n"); // lexical error const auto status = VerifyFormatting(text_structure, bad_code, ""); EXPECT_FALSE(status.ok()); EXPECT_EQ(status.code(), StatusCode::kDataLoss); @@ -91,11 +91,11 @@ TEST(VerifyFormattingTest, LexError) { // Tests that un-parseable outputs are caught as errors. TEST(VerifyFormattingTest, ParseError) { - const absl::string_view code("class c;endclass\n"); + const std::string_view code("class c;endclass\n"); const std::unique_ptr analyzer = VerilogAnalyzer::AnalyzeAutomaticMode(code, "", kDefaultPreprocess); const auto &text_structure = ABSL_DIE_IF_NULL(analyzer)->Data(); - const absl::string_view bad_code("classc;endclass\n"); // syntax error + const std::string_view bad_code("classc;endclass\n"); // syntax error const auto status = VerifyFormatting(text_structure, bad_code, ""); EXPECT_FALSE(status.ok()); EXPECT_EQ(status.code(), StatusCode::kDataLoss); @@ -103,19 +103,19 @@ TEST(VerifyFormattingTest, ParseError) { // Tests that lexical differences are caught as errors. TEST(VerifyFormattingTest, LexicalDifference) { - const absl::string_view code("class c;endclass\n"); + const std::string_view code("class c;endclass\n"); const std::unique_ptr analyzer = VerilogAnalyzer::AnalyzeAutomaticMode(code, "", kDefaultPreprocess); const auto &text_structure = ABSL_DIE_IF_NULL(analyzer)->Data(); - const absl::string_view bad_code("class c;;endclass\n"); // different tokens + const std::string_view bad_code("class c;;endclass\n"); // different tokens const auto status = VerifyFormatting(text_structure, bad_code, ""); EXPECT_FALSE(status.ok()); EXPECT_EQ(status.code(), StatusCode::kDataLoss); } struct FormatterTestCase { - absl::string_view input; - absl::string_view expected; + std::string_view input; + std::string_view expected; }; static const LineNumberSet kEnableAllLines; @@ -17147,9 +17147,9 @@ TEST(FormatterEndToEndTest, NamedParametersIndentNotWrap) { } struct SelectLinesTestCase { - absl::string_view input; + std::string_view input; LineNumberSet lines; // explicit set of lines to enable formatting - absl::string_view expected; + std::string_view expected; }; // Tests that formatter honors selected line numbers. @@ -17990,7 +17990,7 @@ TEST(FormatterEndToEndTest, UnfinishedLineWrapSearching) { style.indentation_spaces = 2; style.wrap_spaces = 4; - const absl::string_view code("parameter int x = 1+1;\n"); + const std::string_view code("parameter int x = 1+1;\n"); std::ostringstream stream, debug_stream; ExecutionControl control; @@ -18161,8 +18161,8 @@ TEST(FormatterEndToEndTest, OnelineFormatExpandTest) { } struct DimensionsAlignmentTestCase { - absl::string_view input; - absl::string_view expected[4]; + std::string_view input; + std::string_view expected[4]; }; static constexpr DimensionsAlignmentTestCase @@ -18620,10 +18620,10 @@ TEST(FormatterEndToEndTest, FunctionCallsWithComments) { // Extracts the first non-whitespace token and prepends it with number of // of newlines seen in front of it. So "\n \n\n foo" -> "3foo" -std::string NLCountAndfirstWord(absl::string_view str) { +std::string NLCountAndfirstWord(std::string_view str) { std::string result; int newline_count = 0; - absl::string_view::const_iterator begin = str.begin(); + std::string_view::const_iterator begin = str.begin(); for (/**/; begin < str.end(); ++begin) { if (!isspace(*begin)) break; newline_count += (*begin == '\n'); @@ -18631,7 +18631,7 @@ std::string NLCountAndfirstWord(absl::string_view str) { // Emit number of newlines seen up to first token. result.append(1, static_cast(newline_count + '0')); // single digit itoa - absl::string_view::const_iterator end_str = begin; + std::string_view::const_iterator end_str = begin; for (/**/; end_str < str.end() && !isspace(*end_str); ++end_str) { } result.append(begin, end_str); @@ -18640,16 +18640,16 @@ std::string NLCountAndfirstWord(absl::string_view str) { // Similar to NLCountAndfirstWord() but looking at the last token and trailing // newlines. -std::string lastWordAndNLCount(absl::string_view str) { +std::string lastWordAndNLCount(std::string_view str) { std::string result; int newline_count = 0; - absl::string_view::const_iterator back = str.end() - 1; + std::string_view::const_iterator back = str.end() - 1; for (/**/; back >= str.begin(); --back) { if (!isspace(*back)) break; newline_count += (*back == '\n'); } - absl::string_view::const_iterator start_str = back; + std::string_view::const_iterator start_str = back; for (/**/; start_str >= str.begin() && !isspace(*start_str); --start_str) { } result.append(&*(start_str + 1), back - start_str); @@ -18661,7 +18661,7 @@ std::string lastWordAndNLCount(absl::string_view str) { // Testing the tester... TEST(FormatterTestInternal, TokenExtractorAndLineCounterTestFixtureTest) { - absl::string_view str = "\n \nhello world \n \n"; + std::string_view str = "\n \nhello world \n \n"; ASSERT_EQ(NLCountAndfirstWord(str), "2hello"); ASSERT_EQ(NLCountAndfirstWord(str.substr(1)), "1hello"); ASSERT_EQ(NLCountAndfirstWord(str.substr(3)), "0hello"); @@ -18677,7 +18677,7 @@ TEST(FormatterTestInternal, TokenExtractorAndLineCounterTestFixtureTest) { TEST(FormatterEndToEndTest, RangeFormattingOnlyEmittingRelevantLines) { // Including some empty lines to make sure the formatting - static constexpr absl::string_view unformatted = + static constexpr std::string_view unformatted = R"( module foo (// non-port comment // some comment @@ -18690,7 +18690,7 @@ foobar, input bit [4] foobaz, ); endmodule )"; - std::vector lines = absl::StrSplit(unformatted, '\n'); + std::vector lines = absl::StrSplit(unformatted, '\n'); const int kLineCount = lines.size(); FormatStyle style; @@ -18722,8 +18722,8 @@ foobar, input bit [4] foobaz, // Area we cover in the input (include the final newline); const auto source_begin = lines[start_line].begin(); const auto source_end = lines[end_line - 1].end() + 1; // include \n - const absl::string_view range_unformatted(&*source_begin, - source_end - source_begin); + const std::string_view range_unformatted(&*source_begin, + source_end - source_begin); // To compare that we indeed formatted the requested reqgion, we make // sure that the first and last token (simplified: non-whitespace word) @@ -18753,14 +18753,14 @@ foobar, input bit [4] foobaz, // Creates a string_view spanning a whole string literal. // Works correctly with strings containing null bytes. template -constexpr absl::string_view string_view_from_literal(const char (&s)[N]) { - return absl::string_view(s, N - 1); +constexpr std::string_view string_view_from_literal(const char (&s)[N]) { + return std::string_view(s, N - 1); } // The following regressions have been found by a fuzzer, so the input might // look a bit 'funny'. Nevertheless, they expose real bugs in the code. -[[maybe_unused]] void TestForNonCrash(absl::string_view input) { +[[maybe_unused]] void TestForNonCrash(std::string_view input) { using verible::EscapeString; FormatStyle style; std::ostringstream stream; diff --git a/verible/verilog/formatting/token-annotator.cc b/verible/verilog/formatting/token-annotator.cc index 5ad544a39..7a4a063fd 100644 --- a/verible/verilog/formatting/token-annotator.cc +++ b/verible/verilog/formatting/token-annotator.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/tree-annotator.h" #include "verible/common/strings/range.h" @@ -764,7 +764,7 @@ static WithReason BreakDecisionBetween( if (right.TokenEnum() == PP_define_body) { // TODO(b/141517267): reflow macro definition text with flexible // line-continuations. - const absl::string_view text = right.Text(); + const std::string_view text = right.Text(); if (std::count(text.begin(), text.end(), '\n') >= 2) { return {SpacingOptions::kPreserve, "Preserve spacing before a multi-line macro definition body."}; @@ -789,7 +789,7 @@ static WithReason BreakDecisionBetween( left.token->text().end(), right.token->text().begin()); auto pos = preceding_whitespace.find_first_of('\n', 0); - if (pos == absl::string_view::npos) { + if (pos == std::string_view::npos) { // There are other tokens on this line return {SpacingOptions::kMustAppend, "EOL comment cannot break from " @@ -803,7 +803,7 @@ static WithReason BreakDecisionBetween( left.token->text().end(), right.token->text().begin()); auto pos = preceding_whitespace.find_first_of('\n', 0); - if (pos != absl::string_view::npos) { + if (pos != std::string_view::npos) { // TODO(mglb): Preserve would be more suitable, but it doesn't work // correctly yet. // Add support for "Preserve" in Layout Optimizer. @@ -907,7 +907,7 @@ static WithReason BreakDecisionBetween( if (left.TokenEnum() == ',' && right.TokenEnum() == verilog_tokentype::MacroArg) { - const absl::string_view text(right.Text()); + const std::string_view text(right.Text()); if (std::find(text.begin(), text.end(), '\n') != text.end()) { return {SpacingOptions::kMustWrap, "Multi-line unlexed macro arguments start on their own line."}; @@ -957,7 +957,7 @@ void AnnotateFormattingInformation( } void AnnotateFormattingInformation( - const FormatStyle &style, absl::string_view::const_iterator buffer_start, + const FormatStyle &style, std::string_view::const_iterator buffer_start, const verible::Symbol *syntax_tree_root, const verible::TokenInfo &eof_token, std::vector *format_tokens) { diff --git a/verible/verilog/formatting/token-annotator.h b/verible/verilog/formatting/token-annotator.h index abd60d10b..f26f44e4d 100644 --- a/verible/verilog/formatting/token-annotator.h +++ b/verible/verilog/formatting/token-annotator.h @@ -15,9 +15,9 @@ #ifndef VERIBLE_VERILOG_FORMATTING_TOKEN_ANNOTATOR_H_ #define VERIBLE_VERILOG_FORMATTING_TOKEN_ANNOTATOR_H_ +#include #include -#include "absl/strings/string_view.h" #include "verible/common/formatting/format-token.h" #include "verible/common/text/symbol.h" #include "verible/common/text/text-structure.h" @@ -43,7 +43,7 @@ void AnnotateFormattingInformation( // syntax_tree_root: syntax tree used for context-sensitive behavior. // eof_token: EOF token pointing to the end of the unformatted string. void AnnotateFormattingInformation( - const FormatStyle &style, absl::string_view::const_iterator buffer_start, + const FormatStyle &style, std::string_view::const_iterator buffer_start, const verible::Symbol *syntax_tree_root, const verible::TokenInfo &eof_token, std::vector *format_tokens); diff --git a/verible/verilog/formatting/token-annotator_test.cc b/verible/verilog/formatting/token-annotator_test.cc index e76da37cd..826f7764d 100644 --- a/verible/verilog/formatting/token-annotator_test.cc +++ b/verible/verilog/formatting/token-annotator_test.cc @@ -18,9 +18,9 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/unwrapped-line-test-utils.h" @@ -4722,14 +4722,14 @@ struct OriginalSpacingSensitiveTestCase { // TODO(fangism): group this into a TokenInfo. int left_token_enum; - absl::string_view left_token_string; + std::string_view left_token_string; // This spacing may influence token-annotation behavior. - absl::string_view whitespace_between; + std::string_view whitespace_between; // TODO(fangism): group this into a TokenInfo. int right_token_enum; - absl::string_view right_token_string; + std::string_view right_token_string; InitializedSyntaxTreeContext left_context; InitializedSyntaxTreeContext right_context; diff --git a/verible/verilog/formatting/tree-unwrapper.cc b/verible/verilog/formatting/tree-unwrapper.cc index 04e2728ed..6bac8c48f 100644 --- a/verible/verilog/formatting/tree-unwrapper.cc +++ b/verible/verilog/formatting/tree-unwrapper.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,6 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/token-partition-tree.h" #include "verible/common/formatting/tree-unwrapper.h" @@ -1573,7 +1573,7 @@ static void AttachSeparatorToPreviousOrNextPartition( if (!previous_partition->Value().TokensRange().empty()) { const auto &previous_token = previous_partition->Value().TokensRange().back(); - absl::string_view original_text_between = verible::make_string_view_range( + std::string_view original_text_between = verible::make_string_view_range( previous_token.Text().end(), separator->Text().begin()); if (!absl::StrContains(original_text_between, '\n')) { VLOG(5) << " merge into previous partition."; @@ -1589,7 +1589,7 @@ static void AttachSeparatorToPreviousOrNextPartition( if (next_partition != nullptr) { if (!next_partition->Value().TokensRange().empty()) { const auto &next_token = next_partition->Value().TokensRange().front(); - absl::string_view original_text_between = verible::make_string_view_range( + std::string_view original_text_between = verible::make_string_view_range( separator->Text().end(), next_token.Text().begin()); if (!absl::StrContains(original_text_between, '\n')) { VLOG(5) << " merge into next partition."; diff --git a/verible/verilog/formatting/tree-unwrapper_test.cc b/verible/verilog/formatting/tree-unwrapper_test.cc index ca2c58650..d7a53ae97 100644 --- a/verible/verilog/formatting/tree-unwrapper_test.cc +++ b/verible/verilog/formatting/tree-unwrapper_test.cc @@ -20,12 +20,12 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/formatting/format-token.h" #include "verible/common/formatting/token-partition-tree.h" @@ -51,12 +51,12 @@ using verible::UnwrappedLine; // Contains the expected token sequence and indentation for an UnwrappedLine struct ExpectedUnwrappedLine { int indentation_spaces; - std::vector tokens; // includes comments + std::vector tokens; // includes comments explicit ExpectedUnwrappedLine(int s) : indentation_spaces(s) {} - ExpectedUnwrappedLine( - int s, std::initializer_list expected_tokens) + ExpectedUnwrappedLine(int s, + std::initializer_list expected_tokens) : indentation_spaces(s), tokens(expected_tokens) {} void ShowUnwrappedLineDifference(std::ostream *stream, @@ -132,8 +132,8 @@ bool ExpectedUnwrappedLine::EqualsUnwrappedLine( // fields. Stops at first unmatched token // TODO(fangism): rewrite this using std::mismatch for (size_t i = 0; i < uwline.Size(); i++) { - absl::string_view uwline_token = uwline.TokensRange()[i].Text(); - absl::string_view expected_token = tokens[i]; + std::string_view uwline_token = uwline.TokensRange()[i].Text(); + std::string_view expected_token = tokens[i]; if (uwline_token != expected_token) { *stream << "error: unwrapped line token #" << i + 1 << " does not match expected token" << std::endl; @@ -168,13 +168,13 @@ struct TreeUnwrapperTestData { const char *test_name; // The source code for testing must be syntactically correct. - absl::string_view source_code; + std::string_view source_code; // The reference values and structure of UnwrappedLines to expect. ExpectedUnwrappedLineTree expected_unwrapped_lines; template - TreeUnwrapperTestData(const char *name, absl::string_view code, + TreeUnwrapperTestData(const char *name, std::string_view code, Args &&...nodes) : test_name(name), source_code(code), @@ -232,7 +232,7 @@ class TreeUnwrapperTest : public ::testing::Test { // Takes a string representation of a verilog file and creates a // VerilogAnalyzer which holds a concrete syntax tree and token stream view // of the file. - void MakeTree(absl::string_view content) { + void MakeTree(std::string_view content) { analyzer_ = std::make_unique(content, "TEST_FILE"); absl::Status status = ABSL_DIE_IF_NULL(analyzer_)->Analyze(); EXPECT_OK(status) << "Rejected code: " << std::endl << content; @@ -251,7 +251,7 @@ class TreeUnwrapperTest : public ::testing::Test { // Creates a TreeUnwrapper populated with a concrete syntax tree and // token stream view from the file input std::unique_ptr CreateTreeUnwrapper( - absl::string_view source_code) { + std::string_view source_code) { MakeTree(source_code); const verible::TextStructureView &text_structure_view = analyzer_->Data(); unwrapper_data_ = @@ -274,7 +274,7 @@ class TreeUnwrapperTest : public ::testing::Test { // Test that TreeUnwrapper produces the correct UnwrappedLines from an empty // file TEST_F(TreeUnwrapperTest, UnwrapEmptyFile) { - const absl::string_view source_code; + const std::string_view source_code; auto tree_unwrapper = CreateTreeUnwrapper(source_code); tree_unwrapper->Unwrap(); @@ -287,7 +287,7 @@ TEST_F(TreeUnwrapperTest, UnwrapEmptyFile) { // Test that TreeUnwrapper produces the correct UnwrappedLines from a blank // line. TEST_F(TreeUnwrapperTest, UnwrapBlankLineOnly) { - const absl::string_view source_code = "\n"; + const std::string_view source_code = "\n"; auto tree_unwrapper = CreateTreeUnwrapper(source_code); tree_unwrapper->Unwrap(); @@ -311,7 +311,7 @@ ExpectedUnwrappedLineTree N(int spaces, Args &&...nodes) { // L is for leaf, which is the only type of node that should list tokens ExpectedUnwrappedLineTree L(int spaces, - std::initializer_list tokens) { + std::initializer_list tokens) { return ExpectedUnwrappedLineTree(ExpectedUnwrappedLine(spaces, tokens)); } diff --git a/verible/verilog/parser/BUILD b/verible/verilog/parser/BUILD index 7f9dae0d4..29c00cad9 100644 --- a/verible/verilog/parser/BUILD +++ b/verible/verilog/parser/BUILD @@ -41,7 +41,6 @@ cc_library( "//bazel:flex", "//verible/common/lexer:flex-lexer-adapter", "//verible/common/text:token-info", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -54,7 +53,6 @@ cc_test( ":verilog-token-enum", "//verible/common/lexer:lexer-test-util", "//verible/common/text:token-info", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -202,7 +200,6 @@ cc_test( "//verible/verilog/preprocessor:verilog-preprocess", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -221,7 +218,6 @@ cc_test( "//verible/common/util:logging", "//verible/verilog/analysis:verilog-analyzer", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -254,6 +250,5 @@ cc_library( deps = [ ":verilog-parser", ":verilog-token-enum", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/verilog/parser/verilog-lexer.cc b/verible/verilog/parser/verilog-lexer.cc index 88f611333..b26273005 100644 --- a/verible/verilog/parser/verilog-lexer.cc +++ b/verible/verilog/parser/verilog-lexer.cc @@ -15,8 +15,8 @@ #include "verible/verilog/parser/verilog-lexer.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" #include "verible/verilog/parser/verilog-token-enum.h" @@ -24,9 +24,9 @@ namespace verilog { using verible::TokenInfo; -VerilogLexer::VerilogLexer(absl::string_view code) : parent_lexer_type(code) {} +VerilogLexer::VerilogLexer(std::string_view code) : parent_lexer_type(code) {} -void VerilogLexer::Restart(absl::string_view code) { +void VerilogLexer::Restart(std::string_view code) { parent_lexer_type::Restart(code); balance_ = 0; macro_id_length_ = 0; @@ -54,7 +54,7 @@ bool VerilogLexer::KeepSyntaxTreeTokens(const TokenInfo &t) { } } -void RecursiveLexText(absl::string_view text, +void RecursiveLexText(std::string_view text, const std::function &func) { VerilogLexer lexer(text); for (;;) { diff --git a/verible/verilog/parser/verilog-lexer.h b/verible/verilog/parser/verilog-lexer.h index 31b648001..28d4b66d1 100644 --- a/verible/verilog/parser/verilog-lexer.h +++ b/verible/verilog/parser/verilog-lexer.h @@ -33,8 +33,7 @@ // clang-format on #include - -#include "absl/strings/string_view.h" +#include namespace verilog { @@ -42,10 +41,10 @@ class VerilogLexer : public verible::FlexLexerAdapter { using parent_lexer_type = verible::FlexLexerAdapter; public: - explicit VerilogLexer(absl::string_view code); + explicit VerilogLexer(std::string_view code); // Restart lexer with new input stream. - void Restart(absl::string_view) final; + void Restart(std::string_view) final; // Returns true if token is invalid. bool TokenIsError(const verible::TokenInfo &) const final; @@ -73,7 +72,7 @@ class VerilogLexer : public verible::FlexLexerAdapter { // Recursively lex the given 'text', and apply 'func' to each subtoken. void RecursiveLexText( - absl::string_view text, + std::string_view text, const std::function &func); } // namespace verilog diff --git a/verible/verilog/parser/verilog-lexer_test.cc b/verible/verilog/parser/verilog-lexer_test.cc index 7978dccb9..b1f378884 100644 --- a/verible/verilog/parser/verilog-lexer_test.cc +++ b/verible/verilog/parser/verilog-lexer_test.cc @@ -16,10 +16,10 @@ #include "verible/verilog/parser/verilog-lexer.h" #include +#include #include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/lexer/lexer-test-util.h" @@ -35,7 +35,7 @@ using verible::TokenInfo; // Removes non-essential tokens from token output stream, such as spaces. class FilteredVerilogLexer : public VerilogLexer { public: - explicit FilteredVerilogLexer(absl::string_view code) : VerilogLexer(code) {} + explicit FilteredVerilogLexer(std::string_view code) : VerilogLexer(code) {} const TokenInfo &DoNextToken() final { do { @@ -2355,7 +2355,7 @@ TEST(VerilogLexerTest, DirectivesUnfiltered) { TEST(VerilogLexerTest, Library) { TestLexer(kLibraryTests); } TEST(RecursiveLexTextTest, Basic) { - constexpr absl::string_view text("hello;"); + constexpr std::string_view text("hello;"); std::vector tokens; RecursiveLexText(text, [&tokens](const TokenInfo &t) { tokens.push_back(t); }); @@ -2366,8 +2366,8 @@ TEST(RecursiveLexTextTest, Basic) { TEST(VerilogLexerTest, StrayNulCharacterHandledCorrectly) { { // baseline - FilteredVerilogLexer lexer(absl::string_view("foo bar baz", 11)); - for (absl::string_view expected : {"foo", "bar", "baz"}) { + FilteredVerilogLexer lexer(std::string_view("foo bar baz", 11)); + for (std::string_view expected : {"foo", "bar", "baz"}) { auto token = lexer.DoNextToken(); EXPECT_EQ(token.text(), expected); EXPECT_EQ(token.token_enum(), SymbolIdentifier); @@ -2375,8 +2375,8 @@ TEST(VerilogLexerTest, StrayNulCharacterHandledCorrectly) { EXPECT_TRUE(lexer.DoNextToken().isEOF()); } { // Stray nul character in text should just be skipped as space - FilteredVerilogLexer lexer(absl::string_view("foo bar\0baz", 11)); - for (absl::string_view expected : {"foo", "bar", "baz"}) { + FilteredVerilogLexer lexer(std::string_view("foo bar\0baz", 11)); + for (std::string_view expected : {"foo", "bar", "baz"}) { auto token = lexer.DoNextToken(); EXPECT_EQ(token.text(), expected); EXPECT_EQ(token.token_enum(), SymbolIdentifier); diff --git a/verible/verilog/parser/verilog-lexical-context_test.cc b/verible/verilog/parser/verilog-lexical-context_test.cc index 31b48b30f..733186b14 100644 --- a/verible/verilog/parser/verilog-lexical-context_test.cc +++ b/verible/verilog/parser/verilog-lexical-context_test.cc @@ -30,10 +30,10 @@ #include #include #include +#include #include #include "absl/strings/match.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/text/text-structure.h" #include "verible/common/text/token-info.h" @@ -61,13 +61,13 @@ using verible::TokenStreamReferenceView; // If this were a function, its signature would be: // template // inline void EXPECT_EQ_REASON(const verible::WithReason& r, const T& -// expected, absl::string_view pattern); +// expected, std::string_view pattern); #define EXPECT_EQ_REASON(expr, expected, pattern) \ { \ const auto &r = expr; /* evaluate expr once, auto-extend lifetime */ \ EXPECT_EQ(r.value, expected) << r.reason; \ /* value could be correct, but reason could be wrong. */ \ - EXPECT_TRUE(absl::StrContains(absl::string_view(r.reason), pattern)) \ + EXPECT_TRUE(absl::StrContains(std::string_view(r.reason), pattern)) \ << "value: " << r.value << "\nreason: " << r.reason; \ } @@ -201,7 +201,7 @@ TEST_F(LastSemicolonStateMachineTest, LifeCycleOneSemicolon) { // Purely synthesized token sequence for testing: // Only enums matter, not text. - constexpr absl::string_view text("don't care"); + constexpr std::string_view text("don't care"); TokenInfo tokens[] = { TokenInfo(TK_module, text), TokenInfo(SymbolIdentifier, text), @@ -254,7 +254,7 @@ TEST_F(LastSemicolonStateMachineTest, LifeCycleFinalSemicolon) { // Purely synthesized token sequence for testing: // Only enums matter, not text. - constexpr absl::string_view text("don't care"); + constexpr std::string_view text("don't care"); TokenInfo tokens[] = { TokenInfo(TK_module, text), TokenInfo(SymbolIdentifier, text), diff --git a/verible/verilog/parser/verilog-parser_test.cc b/verible/verilog/parser/verilog-parser_test.cc index ee93ce962..c63054b9e 100644 --- a/verible/verilog/parser/verilog-parser_test.cc +++ b/verible/verilog/parser/verilog-parser_test.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/parser/bison-parser-common.h" #include "verible/common/parser/parser-test-util.h" @@ -6416,7 +6416,7 @@ TEST(VerilogParserTest, InternalStackRealloc) { // Tests that Tokenize() properly sets the range of the EOF token. TEST(VerilogParserTest, TokenizeTerimnatesEOFRange) { - constexpr absl::string_view kCode[] = { + constexpr std::string_view kCode[] = { "", "\t", "\n", "\n\n", "module", "module\n", "module foo;", "module foo;\n", }; diff --git a/verible/verilog/parser/verilog-token.cc b/verible/verilog/parser/verilog-token.cc index 2827c1571..5316ac9e8 100644 --- a/verible/verilog/parser/verilog-token.cc +++ b/verible/verilog/parser/verilog-token.cc @@ -15,8 +15,8 @@ #include "verible/verilog/parser/verilog-token.h" #include +#include -#include "absl/strings/string_view.h" #include "verible/verilog/parser/verilog-parser.h" #include "verible/verilog/parser/verilog-token-enum.h" @@ -26,7 +26,7 @@ namespace verilog { // in verible-verilog-syntax' JSON output. Changing them might // break third-party code. -absl::string_view TokenTypeToString(size_t tokentype) { +std::string_view TokenTypeToString(size_t tokentype) { switch (tokentype) { // Returns stringified symbol name #define CASE_STRINGIFY(val) \ @@ -55,7 +55,7 @@ absl::string_view TokenTypeToString(size_t tokentype) { // Returns token type name or its alias (if available) as used in verilog.y default: { - absl::string_view symbol_name(verilog_symbol_name(tokentype)); + std::string_view symbol_name(verilog_symbol_name(tokentype)); if (symbol_name.size() >= 2 && (symbol_name[0] == '"' || symbol_name[0] == '\'')) { // Strip quotes diff --git a/verible/verilog/parser/verilog-token.h b/verible/verilog/parser/verilog-token.h index 0ef96812b..222fbe55f 100644 --- a/verible/verilog/parser/verilog-token.h +++ b/verible/verilog/parser/verilog-token.h @@ -16,8 +16,7 @@ #define VERIBLE_VERILOG_TOKEN_VERILOG_TOKEN_H_ #include - -#include "absl/strings/string_view.h" +#include namespace verilog { @@ -31,7 +30,7 @@ namespace verilog { // "SymbolIdentifier", "TK_DecNumber", "TK_EOL_COMMENT", "TK_NEWLINE" // // See also: verilog_symbol_name() in verilog_parser.h -absl::string_view TokenTypeToString(size_t tokentype); +std::string_view TokenTypeToString(size_t tokentype); } // namespace verilog diff --git a/verible/verilog/preprocessor/BUILD b/verible/verilog/preprocessor/BUILD index aa74c0b2d..cfe276173 100644 --- a/verible/verilog/preprocessor/BUILD +++ b/verible/verilog/preprocessor/BUILD @@ -30,7 +30,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -53,7 +52,6 @@ cc_test( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/verilog/preprocessor/verilog-preprocess.cc b/verible/verilog/preprocessor/verilog-preprocess.cc index 049c07a52..2f7711142 100644 --- a/verible/verilog/preprocessor/verilog-preprocess.cc +++ b/verible/verilog/preprocessor/verilog-preprocess.cc @@ -19,13 +19,13 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/lexer/token-generator.h" #include "verible/common/lexer/token-stream-adapter.h" #include "verible/common/text/macro-definition.h" @@ -227,7 +227,7 @@ absl::Status VerilogPreprocess::ConsumeAndParseMacroCall( const StreamIteratorGenerator &generator, verible::MacroCall *macro_call, const verible::MacroDefinition ¯o_definition) { // Parsing the macro . - const absl::string_view macro_name_str = (*iter)->text().substr(1); + const std::string_view macro_name_str = (*iter)->text().substr(1); verible::TokenInfo macro_name_token(MacroCallId, macro_name_str); macro_call->macro_name = macro_name_token; @@ -288,7 +288,7 @@ absl::Status VerilogPreprocess::HandleMacroIdentifier( // true. // Finding the macro definition. - const absl::string_view sv = (*iter)->text(); + const std::string_view sv = (*iter)->text(); const auto *found = FindOrNull(preprocess_data_.macro_definitions, sv.substr(1)); if (!found) { @@ -333,7 +333,7 @@ void VerilogPreprocess::RegisterMacroDefinition( // preprocess_data_.lexed_macros_backup Can be accessed directly after expansion // as: preprocess_data_.lexed_macros_backup.back() absl::Status VerilogPreprocess::ExpandText( - const absl::string_view &definition_text) { + const std::string_view &definition_text) { VerilogLexer lexer(definition_text); verible::TokenSequence lexed_sequence; verible::TokenSequence expanded_lexed_sequence; @@ -382,7 +382,7 @@ absl::Status VerilogPreprocess::ExpandMacro( const verible::MacroDefinition *macro_definition) { const auto &actual_parameters = macro_call.positional_arguments; - std::map subs_map; + std::map subs_map; if (macro_definition->IsCallable()) { RETURN_IF_ERROR(macro_definition->PopulateSubstitutionMap(actual_parameters, &subs_map)); @@ -609,7 +609,7 @@ absl::Status VerilogPreprocess::HandleInclude( **token_iter, std::string(status_or_file.status().message())); return status_or_file.status(); } - const absl::string_view source_contents = *status_or_file; + const std::string_view source_contents = *status_or_file; // Creating a new "VerilogPreprocess" object for the included file, // With the same configuration and preprocessing info (defines, incdirs) as diff --git a/verible/verilog/preprocessor/verilog-preprocess.h b/verible/verilog/preprocessor/verilog-preprocess.h index a770d1350..568ed5e1b 100644 --- a/verible/verilog/preprocessor/verilog-preprocess.h +++ b/verible/verilog/preprocessor/verilog-preprocess.h @@ -40,11 +40,11 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "verible/common/text/macro-definition.h" #include "verible/common/text/text-structure.h" #include "verible/common/text/token-info.h" @@ -69,7 +69,7 @@ struct VerilogPreprocessError { // Information that results from preprocessing. struct VerilogPreprocessData { using MacroDefinition = verible::MacroDefinition; - using MacroDefinitionRegistry = std::map; + using MacroDefinitionRegistry = std::map; using TokenSequence = std::vector; // Resulting token stream after preprocessing @@ -98,7 +98,7 @@ class VerilogPreprocess { public: using FileOpener = - std::function(absl::string_view)>; + std::function(std::string_view)>; struct Config { // Filter out non-matching `ifdef and `ifndef branches depending on // which defines are set. @@ -179,7 +179,7 @@ class VerilogPreprocess { TokenStreamView::const_iterator *, MacroParameterInfo *); void RegisterMacroDefinition(const MacroDefinition &); - absl::Status ExpandText(const absl::string_view &); + absl::Status ExpandText(const std::string_view &); absl::Status ExpandMacro(const verible::MacroCall &, const verible::MacroDefinition *); absl::Status HandleInclude(TokenStreamView::const_iterator, diff --git a/verible/verilog/preprocessor/verilog-preprocess_test.cc b/verible/verilog/preprocessor/verilog-preprocess_test.cc index 0505d7757..ae335679a 100644 --- a/verible/verilog/preprocessor/verilog-preprocess_test.cc +++ b/verible/verilog/preprocessor/verilog-preprocess_test.cc @@ -17,13 +17,13 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/common/text/macro-definition.h" @@ -52,7 +52,7 @@ using FileOpener = VerilogPreprocess::FileOpener; class LexerTester { public: - explicit LexerTester(absl::string_view text) : lexer_(text) { + explicit LexerTester(std::string_view text) : lexer_(text) { for (lexer_.DoNextToken(); !lexer_.GetLastToken().isEOF(); lexer_.DoNextToken()) { lexed_sequence_.push_back(lexer_.GetLastToken()); @@ -70,12 +70,12 @@ class LexerTester { class PreprocessorTester { public: - PreprocessorTester(absl::string_view text, + PreprocessorTester(std::string_view text, const VerilogPreprocess::Config &config) : analyzer_(text, "<>", config), status_(analyzer_.Analyze()) {} - explicit PreprocessorTester(absl::string_view text) + explicit PreprocessorTester(std::string_view text) : PreprocessorTester(text, VerilogPreprocess::Config()) {} const VerilogPreprocessData &PreprocessorData() const { @@ -94,7 +94,7 @@ class PreprocessorTester { }; struct FailTest { - absl::string_view input; + std::string_view input; int offset; }; TEST(VerilogPreprocessTest, InvalidPreprocessorInputs) { @@ -148,7 +148,7 @@ TEST(VerilogPreprocessTest, InvalidPreprocessorInputs) { // Verify that VerilogPreprocess works without any directives. TEST(VerilogPreprocessTest, WorksWithoutDefinitions) { - absl::string_view test_cases[] = { + std::string_view test_cases[] = { "", "\n", "module foo;\nendmodule\n", @@ -164,7 +164,7 @@ TEST(VerilogPreprocessTest, WorksWithoutDefinitions) { } TEST(VerilogPreprocessTest, OneMacroDefinitionNoParamsNoValue) { - absl::string_view test_cases[] = { + std::string_view test_cases[] = { "`define FOOOO\n", "`define FOOOO\n", "module foo;\nendmodule\n" @@ -322,9 +322,9 @@ TEST(VerilogPreprocessTest, DefaultPreprocessorKeepsDefineInStream) { } struct BranchFailTest { - absl::string_view input; + std::string_view input; int offset; - absl::string_view expected_error; + std::string_view expected_error; }; TEST(VerilogPreprocessTest, IncompleteOrUnbalancedIfdef) { const BranchFailTest test_cases[] = { @@ -357,9 +357,9 @@ TEST(VerilogPreprocessTest, IncompleteOrUnbalancedIfdef) { } struct RawAndFiltered { - absl::string_view description; - absl::string_view pp_input; - absl::string_view equivalent; + std::string_view description; + std::string_view pp_input; + std::string_view equivalent; }; TEST(VerilogPreprocess, FilterPPBranches) { const RawAndFiltered test_cases[] = { @@ -887,9 +887,9 @@ static void IncludeFileTestWithIncludeBracket(const char *start_inc, const char *end_inc) { const auto tempdir = testing::TempDir(); const std::string includes_dir = JoinPath(tempdir, "includes"); - constexpr absl::string_view included_content( + constexpr std::string_view included_content( "module included_file(); endmodule"); - const absl::string_view included_filename = "included_file.sv"; + const std::string_view included_filename = "included_file.sv"; const std::string included_absolute_path = JoinPath(includes_dir, included_filename); @@ -901,7 +901,7 @@ static void IncludeFileTestWithIncludeBracket(const char *start_inc, FileOpener file_opener = [included_absolute_path, included_content]( - absl::string_view filename) -> absl::StatusOr { + std::string_view filename) -> absl::StatusOr { if (filename == included_absolute_path) return included_content; return absl::NotFoundError(absl::StrCat(filename, " is not found")); }; @@ -947,9 +947,9 @@ TEST(VerilogPreprocessTest, IncludingFileWithRelativePath) { const auto tempdir = testing::TempDir(); const std::string includes_dir = JoinPath(tempdir, "includes"); EXPECT_TRUE(CreateDir(includes_dir).ok()); - constexpr absl::string_view included_content( + constexpr std::string_view included_content( "module included_file(); endmodule"); - const absl::string_view included_filename = "included_file.sv"; + const std::string_view included_filename = "included_file.sv"; const ScopedTestFile tf(includes_dir, included_content, included_filename); const std::string src_content = absl::StrCat("`include \"", included_filename, @@ -962,7 +962,7 @@ TEST(VerilogPreprocessTest, IncludingFileWithRelativePath) { verilog::VerilogProject project(".", {"/", includes_dir}); FileOpener file_opener = [&project]( - absl::string_view filename) -> absl::StatusOr { + std::string_view filename) -> absl::StatusOr { auto result = project.OpenIncludedFile(filename); if (!result.status().ok()) return result.status(); return (*result)->GetContent(); @@ -1003,9 +1003,9 @@ TEST(VerilogPreprocessTest, const auto tempdir = testing::TempDir(); const std::string includes_dir = JoinPath(tempdir, "includes"); EXPECT_TRUE(CreateDir(includes_dir).ok()); - constexpr absl::string_view included_content( + constexpr std::string_view included_content( "module included_file(); endmodule\n"); - const absl::string_view included_filename = "included_file.sv"; + const std::string_view included_filename = "included_file.sv"; const ScopedTestFile tf(includes_dir, included_content, included_filename); const std::string src_content = absl::StrCat("`include \"", included_filename, "\"\nmodule src(); endmodule\n"); @@ -1015,7 +1015,7 @@ TEST(VerilogPreprocessTest, verilog::VerilogProject project(".", {"/"}); FileOpener file_opener = [&project]( - absl::string_view filename) -> absl::StatusOr { + std::string_view filename) -> absl::StatusOr { auto result = project.OpenIncludedFile(filename); if (!result.status().ok()) return result.status(); return (*result)->GetContent(); diff --git a/verible/verilog/tools/diff/BUILD b/verible/verilog/tools/diff/BUILD index 30a5c132b..78fb08779 100644 --- a/verible/verilog/tools/diff/BUILD +++ b/verible/verilog/tools/diff/BUILD @@ -23,7 +23,6 @@ cc_binary( "//verible/verilog/analysis:verilog-equivalence", "@abseil-cpp//absl/flags:flag", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/verilog/tools/diff/verilog-diff.cc b/verible/verilog/tools/diff/verilog-diff.cc index e93306b35..9e4a29ab3 100644 --- a/verible/verilog/tools/diff/verilog-diff.cc +++ b/verible/verilog/tools/diff/verilog-diff.cc @@ -26,10 +26,10 @@ #include #include // IWYU pragma: keep // for ostringstream #include // for string, allocator, etc +#include #include "absl/flags/flag.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/util/enum-flags.h" #include "verible/common/util/file-util.h" #include "verible/common/util/init-command-line.h" @@ -56,7 +56,7 @@ std::ostream &operator<<(std::ostream &stream, DiffMode p) { return DiffModeStringMap().Unparse(p, stream); } -bool AbslParseFlag(absl::string_view text, DiffMode *mode, std::string *error) { +bool AbslParseFlag(std::string_view text, DiffMode *mode, std::string *error) { return DiffModeStringMap().Parse(text, mode, error, "--mode value"); } @@ -75,7 +75,7 @@ ABSL_FLAG(DiffMode, mode, DiffMode::kFormat, )"); using EquivalenceFunctionType = std::function; + std::string_view, std::string_view, std::ostream *)>; static const std::map diff_func_map({ {DiffMode::kFormat, verilog::FormatEquivalent}, diff --git a/verible/verilog/tools/formatter/BUILD b/verible/verilog/tools/formatter/BUILD index 5eafca595..976c703a3 100644 --- a/verible/verilog/tools/formatter/BUILD +++ b/verible/verilog/tools/formatter/BUILD @@ -29,7 +29,6 @@ cc_binary( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/verilog/tools/formatter/verilog-format.cc b/verible/verilog/tools/formatter/verilog-format.cc index 9c262b62b..0e76de25b 100644 --- a/verible/verilog/tools/formatter/verilog-format.cc +++ b/verible/verilog/tools/formatter/verilog-format.cc @@ -25,6 +25,7 @@ #include #include // IWYU pragma: keep // for ostringstream #include // for string, allocator, etc +#include #include #include "absl/flags/flag.h" @@ -34,7 +35,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/position.h" #include "verible/common/util/file-util.h" #include "verible/common/util/init-command-line.h" @@ -60,14 +60,14 @@ struct LineRanges { LineRanges::storage_type LineRanges::values; // global initializer -bool AbslParseFlag(absl::string_view flag_arg, LineRanges * /* unused */, +bool AbslParseFlag(std::string_view flag_arg, LineRanges * /* unused */, std::string *error) { auto &values = LineRanges::values; // Pre-split strings, so that "--flag v1,v2" and "--flag v1 --flag v2" are // equivalent. - const std::vector tokens = absl::StrSplit(flag_arg, ','); + const std::vector tokens = absl::StrSplit(flag_arg, ','); values.reserve(values.size() + tokens.size()); - for (const absl::string_view &token : tokens) { + for (const std::string_view &token : tokens) { // need to copy string, cannot just use string_view values.emplace_back(token.begin(), token.end()); } @@ -124,13 +124,13 @@ ABSL_FLAG(int, max_search_states, 100000, "Limits the number of search states explored during " "line wrap optimization."); -static std::ostream &FileMsg(absl::string_view filename) { +static std::ostream &FileMsg(std::string_view filename) { std::cerr << filename << ": "; return std::cerr; } // TODO: Refactor and simplify -static bool formatOneFile(absl::string_view filename, +static bool formatOneFile(std::string_view filename, const LineNumberSet &lines_to_format, bool *any_changes) { const bool inplace = absl::GetFlag(FLAGS_inplace); @@ -283,7 +283,7 @@ int main(int argc, char **argv) { bool all_success = true; bool any_changes = false; // All positional arguments are file names. Exclude program name. - for (const absl::string_view filename : + for (const std::string_view filename : verible::make_range(file_args.begin() + 1, file_args.end())) { all_success &= formatOneFile(filename, lines_to_format, &any_changes); } diff --git a/verible/verilog/tools/kythe/BUILD b/verible/verilog/tools/kythe/BUILD index a8ae06940..036758e62 100644 --- a/verible/verilog/tools/kythe/BUILD +++ b/verible/verilog/tools/kythe/BUILD @@ -32,7 +32,6 @@ cc_library( "@abseil-cpp//absl/hash", "@abseil-cpp//absl/log:check", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -57,7 +56,6 @@ cc_library( "@abseil-cpp//absl/container:flat_hash_set", "@abseil-cpp//absl/container:node_hash_map", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -67,7 +65,6 @@ cc_test( deps = [ ":kythe-facts", ":scope-resolver", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -86,7 +83,6 @@ cc_library( cc_library( name = "kythe-schema-constants", hdrs = ["kythe-schema-constants.h"], - deps = ["@abseil-cpp//absl/strings:string_view"], ) cc_library( @@ -107,7 +103,6 @@ cc_library( "@abseil-cpp//absl/container:node_hash_set", "@abseil-cpp//absl/hash", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@abseil-cpp//absl/time", ], ) @@ -137,7 +132,6 @@ cc_library( "//verible/common/util:tree-operations", "//verible/common/util:vector-tree", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -148,7 +142,6 @@ cc_test( ":indexing-facts-tree", ":verilog-extractor-indexing-fact-type", "//verible/common/util:range", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -188,7 +181,6 @@ cc_library( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -206,7 +198,6 @@ cc_test( "//verible/verilog/analysis:verilog-project", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -247,7 +238,6 @@ cc_binary( "@abseil-cpp//absl/flags:flag", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -284,7 +274,6 @@ cc_library( "//verible/common/util:sha256", "//verible/common/util:simple-zip", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -305,6 +294,5 @@ cc_binary( "@abseil-cpp//absl/flags:flag", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/verilog/tools/kythe/indexing-facts-tree-extractor.cc b/verible/verilog/tools/kythe/indexing-facts-tree-extractor.cc index 22b1e3a1e..9c3d495a9 100644 --- a/verible/verilog/tools/kythe/indexing-facts-tree-extractor.cc +++ b/verible/verilog/tools/kythe/indexing-facts-tree-extractor.cc @@ -17,12 +17,12 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -84,7 +84,7 @@ class IndexingFactsTreeExtractor : public verible::TreeContextVisitor { source_file_(source_file), extraction_state_(extraction_state), errors_(errors) { - const absl::string_view base = source_file_.GetTextStructure()->Contents(); + const std::string_view base = source_file_.GetTextStructure()->Contents(); root_.Value().AppendAnchor( // Create the Anchor for file path node. Anchor(source_file_.ResolvedPath()), @@ -286,7 +286,7 @@ class IndexingFactsTreeExtractor : public verible::TreeContextVisitor { // extracted node. void MoveAndDeleteLastExtractedNode(IndexingFactNode *new_node); - absl::string_view FileContent() { + std::string_view FileContent() { return source_file_.GetTextStructure()->Contents(); } @@ -342,13 +342,13 @@ IndexingFactNode BuildIndexingFactsTree( } // namespace -IndexingFactNode ExtractFiles(absl::string_view file_list_path, +IndexingFactNode ExtractFiles(std::string_view file_list_path, VerilogProject *project, const std::vector &file_names, std::vector *errors) { VLOG(1) << __FUNCTION__; // Open all of the translation units. - for (absl::string_view file_name : file_names) { + for (std::string_view file_name : file_names) { const auto status_or_file = project->OpenTranslationUnit(file_name); if (!status_or_file.ok()) { if (errors != nullptr) { @@ -373,7 +373,7 @@ IndexingFactNode ExtractFiles(absl::string_view file_list_path, // pre-allocate file nodes with the number of translation units file_list_facts_tree.Children().reserve(file_names.size()); - for (absl::string_view file_name : file_names) { + for (std::string_view file_name : file_names) { auto *translation_unit = project->LookupRegisteredFile(file_name); if (translation_unit == nullptr) continue; const auto parse_status = translation_unit->Parse(); @@ -1040,12 +1040,12 @@ void IndexingFactsTreeExtractor::ExtractMacroDefinition( } Anchor GetMacroAnchorFromTokenInfo(const TokenInfo ¯o_token_info, - absl::string_view file_content) { + std::string_view file_content) { // Strip the prefix "`". // e.g. // `define TEN 0 // `TEN --> removes the ` - const absl::string_view macro_name = + const std::string_view macro_name = absl::StripPrefix(macro_token_info.text(), "`"); int begin = std::distance(file_content.begin(), macro_name.begin()); return Anchor(macro_name, begin, macro_name.size()); @@ -1788,7 +1788,7 @@ void IndexingFactsTreeExtractor::ExtractForInitialization( // Returns string_view of `text` with outermost double-quotes removed. // If `text` is not wrapped in quotes, return it as-is. -absl::string_view StripOuterQuotes(absl::string_view text) { +std::string_view StripOuterQuotes(std::string_view text) { return absl::StripSuffix(absl::StripPrefix(text, "\""), "\""); } @@ -1801,10 +1801,10 @@ void IndexingFactsTreeExtractor::ExtractInclude( return; } - const absl::string_view filename_text = included_filename->get().text(); + const std::string_view filename_text = included_filename->get().text(); // Remove the double quotes from the filesname. - const absl::string_view filename_unquoted = StripOuterQuotes(filename_text); + const std::string_view filename_unquoted = StripOuterQuotes(filename_text); VLOG(1) << "got: `include \"" << filename_unquoted << "\""; VerilogProject *const project = extraction_state_->project; diff --git a/verible/verilog/tools/kythe/indexing-facts-tree-extractor.h b/verible/verilog/tools/kythe/indexing-facts-tree-extractor.h index 6cbf4d6b4..0df3ae038 100644 --- a/verible/verilog/tools/kythe/indexing-facts-tree-extractor.h +++ b/verible/verilog/tools/kythe/indexing-facts-tree-extractor.h @@ -16,10 +16,10 @@ #define VERIBLE_VERILOG_TOOLS_KYTHE_INDEXING_FACTS_TREE_EXTRACTOR_H_ #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/verilog/analysis/verilog-project.h" #include "verible/verilog/tools/kythe/indexing-facts-tree.h" @@ -30,7 +30,7 @@ namespace kythe { // IndexingFactsTree for the given files. // The returned tree will have the files as children and they will retain their // original ordering from the file list. -IndexingFactNode ExtractFiles(absl::string_view file_list_path, +IndexingFactNode ExtractFiles(std::string_view file_list_path, VerilogProject *project, const std::vector &file_names, std::vector *errors = nullptr); diff --git a/verible/verilog/tools/kythe/indexing-facts-tree-extractor_test.cc b/verible/verilog/tools/kythe/indexing-facts-tree-extractor_test.cc index 539cb546a..70e3cd219 100644 --- a/verible/verilog/tools/kythe/indexing-facts-tree-extractor_test.cc +++ b/verible/verilog/tools/kythe/indexing-facts-tree-extractor_test.cc @@ -16,11 +16,11 @@ #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/analysis/syntax-tree-search-test-utils.h" #include "verible/common/util/file-util.h" @@ -57,7 +57,7 @@ class TempDir { // Groups information for a single temporary source file together. struct TestFileEntry { // The original source code of the translation. - const absl::string_view origin_text; + const std::string_view origin_text; // One file in project, will be given randomly generated name. const ScopedTestFile temp_file; @@ -66,18 +66,17 @@ struct TestFileEntry { // opened as a translation unit. const VerilogSourceFile *const source_file = nullptr; - TestFileEntry( - absl::string_view code_text, absl::string_view temp_dir, - const std::function - &file_opener, - absl::string_view override_basename = "") + TestFileEntry(std::string_view code_text, std::string_view temp_dir, + const std::function + &file_opener, + std::string_view override_basename = "") : origin_text(code_text), temp_file(temp_dir, origin_text, override_basename), // Open this file from inside 'project', save pointer here. source_file(file_opener(temp_file.filename())) {} // Returns the string_view of text owned by this->source_file. - absl::string_view SourceText() const { + std::string_view SourceText() const { CHECK(source_file != nullptr); return source_file->GetContent(); } @@ -97,13 +96,13 @@ struct TestFileEntry { class SimpleTestProject : public TempDir, public VerilogProject { public: // 'code_text' is the contents of the single translation unit in this project - explicit SimpleTestProject(absl::string_view code_text, + explicit SimpleTestProject(std::string_view code_text, const std::vector &include_paths = {}) : VerilogProject(temp_dir_, include_paths, /*corpus=*/"unittest", /*provide_lookup_file_origin=*/false), code_text_(code_text), translation_unit_(code_text, temp_dir_, - [this](absl::string_view full_file_name) + [this](std::string_view full_file_name) -> const VerilogSourceFile * { /* VerilogProject base class is already fully * initialized */ @@ -113,7 +112,7 @@ class SimpleTestProject : public TempDir, public VerilogProject { const TestFileEntry &XUnit() const { return translation_unit_; } - absl::string_view OnlyFileName() const { + std::string_view OnlyFileName() const { return translation_unit_.temp_file.filename(); } @@ -128,7 +127,7 @@ class SimpleTestProject : public TempDir, public VerilogProject { T::value_type ExpectedFileListData() const { return { IndexingFactType::kFileList, // - Anchor(absl::string_view(temp_dir_)), + Anchor(std::string_view(temp_dir_)), // file_list is co-located with the files it references Anchor(TranslationUnitRoot()), // TranslationUnitRoot() == verible::file::Dirname(OnlyFileName()) @@ -158,15 +157,15 @@ class IncludeTestProject : protected SimpleTestProject { public: // 'code_text' is the contents of the single translation unit in this project. // 'include_text' is the contents of the single included file in this project. - IncludeTestProject(absl::string_view code_text, - absl::string_view include_file_basename, - absl::string_view include_text, + IncludeTestProject(std::string_view code_text, + std::string_view include_file_basename, + std::string_view include_text, const std::vector &include_paths = {}) : SimpleTestProject(code_text, include_paths), include_file_( include_text, temp_dir_, [this]( - absl::string_view full_file_name) -> const VerilogSourceFile * { + std::string_view full_file_name) -> const VerilogSourceFile * { /* VerilogProject base class is already fully initialized */ return *OpenIncludedFile(verible::file::Basename(full_file_name)); }, @@ -185,9 +184,9 @@ class IncludeTestProject : protected SimpleTestProject { }; TEST(FactsTreeExtractor, EqualOperatorTest) { - constexpr absl::string_view code_text = "some other code"; - constexpr absl::string_view file_name = "verilog.v"; - constexpr absl::string_view file_name_other = "other.v"; + constexpr std::string_view code_text = "some other code"; + constexpr std::string_view file_name = "verilog.v"; + constexpr std::string_view file_name_other = "other.v"; const IndexingFactNode expected(D{ IndexingFactType::kFile, @@ -221,8 +220,8 @@ TEST(FactsTreeExtractor, EqualOperatorTest) { }, T(D{ IndexingFactType::kModule, - Anchor(absl::string_view("foo")), - Anchor(absl::string_view("foo")), + Anchor(std::string_view("foo")), + Anchor(std::string_view("foo")), })); const auto P = [&code_text](const IndexingFactNode &n) { @@ -251,7 +250,7 @@ TEST(FactsTreeExtractor, EqualOperatorTest) { } TEST(FactsTreeExtractor, EmptyCSTTest) { - constexpr absl::string_view code_text; + constexpr std::string_view code_text; SimpleTestProject project(code_text); @@ -269,7 +268,7 @@ TEST(FactsTreeExtractor, EmptyCSTTest) { TEST(FactsTreeExtractor, ParseErrorTest) { // These inputs are lexically or syntactically invalid. - constexpr absl::string_view code_texts[] = { + constexpr std::string_view code_texts[] = { "9badid foo;\n", // lexical error "final v;\n", // syntax error "module unfinished", // syntax error diff --git a/verible/verilog/tools/kythe/indexing-facts-tree.h b/verible/verilog/tools/kythe/indexing-facts-tree.h index 37da3a2b5..42efd2f31 100644 --- a/verible/verilog/tools/kythe/indexing-facts-tree.h +++ b/verible/verilog/tools/kythe/indexing-facts-tree.h @@ -19,10 +19,10 @@ #include #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/text/token-info.h" #include "verible/common/util/vector-tree.h" #include "verible/verilog/tools/kythe/verilog-extractor-indexing-fact-type.h" @@ -43,9 +43,9 @@ struct AnchorRange { // Anchor class represents the location and value of some token. class Anchor { public: - explicit Anchor(absl::string_view value) : content_(value) {} + explicit Anchor(std::string_view value) : content_(value) {} - explicit Anchor(absl::string_view value, size_t begin, size_t length) + explicit Anchor(std::string_view value, size_t begin, size_t length) : content_(value) { source_text_range_.emplace(begin, length); } @@ -54,7 +54,7 @@ class Anchor { // Recall the TokenInfo's string point to substrings of memory owned // elsewhere. explicit Anchor(const verible::TokenInfo &token, - absl::string_view source_content) + std::string_view source_content) : content_(token.text()) { const int token_left = token.left(source_content); const int token_right = token.right(source_content); @@ -69,7 +69,7 @@ class Anchor { // Returns human readable view of this Anchor. std::string DebugString() const; - absl::string_view Text() const { return content_; } + std::string_view Text() const { return content_; } // Returns the location of the Anchor's content in the original string. const std::optional &SourceTextRange() const { @@ -156,10 +156,9 @@ std::ostream &operator<<(std::ostream &, const IndexingNodeData &); struct PrintableIndexingNodeData { const IndexingNodeData &data; // The superstring of which all string_views in this subtree is a substring. - const absl::string_view base; + const std::string_view base; - PrintableIndexingNodeData(const IndexingNodeData &data, - absl::string_view base) + PrintableIndexingNodeData(const IndexingNodeData &data, std::string_view base) : data(data), base(base) {} }; @@ -174,10 +173,9 @@ using IndexingFactNode = verible::VectorTree; struct PrintableIndexingFactNode { const IndexingFactNode &data; // The superstring of which all string_views in this subtree is a substring. - const absl::string_view base; + const std::string_view base; - PrintableIndexingFactNode(const IndexingFactNode &data, - absl::string_view base) + PrintableIndexingFactNode(const IndexingFactNode &data, std::string_view base) : data(data), base(base) {} }; diff --git a/verible/verilog/tools/kythe/indexing-facts-tree_test.cc b/verible/verilog/tools/kythe/indexing-facts-tree_test.cc index 3d80f5c64..ead3678cb 100644 --- a/verible/verilog/tools/kythe/indexing-facts-tree_test.cc +++ b/verible/verilog/tools/kythe/indexing-facts-tree_test.cc @@ -16,8 +16,8 @@ #include #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/util/range.h" #include "verible/verilog/tools/kythe/verilog-extractor-indexing-fact-type.h" @@ -34,15 +34,15 @@ class TestAnchor : public Anchor { }; TEST(AnchorTest, DebugStringUsingOffsets) { - constexpr absl::string_view text("abcdefghij"); + constexpr std::string_view text("abcdefghij"); const Anchor anchor(text.substr(4, 3), /*begin=*/4, /*length=*/3); const std::string debug_string(anchor.DebugString()); EXPECT_EQ(debug_string, "{efg @4-7}"); } TEST(AnchorTest, EqualityNotOwned) { - constexpr absl::string_view text1("abcd"); - constexpr absl::string_view text2("defg"); + constexpr std::string_view text1("abcd"); + constexpr std::string_view text2("defg"); EXPECT_EQ(Anchor(text1), Anchor(text1)); EXPECT_EQ(Anchor(text2), Anchor(text2)); EXPECT_NE(Anchor(text1), Anchor(text2)); @@ -67,12 +67,12 @@ TEST(AnchorTest, EqualityOwned) { TEST(AnchorTest, EqualityMixed) { const Anchor anchor1("PWNED"); - const Anchor anchor2(absl::string_view("PWNED")); + const Anchor anchor2(std::string_view("PWNED")); EXPECT_EQ(anchor1, anchor2); EXPECT_EQ(anchor2, anchor1); const Anchor anchor3("stoned"); - const Anchor anchor4(absl::string_view("STONED")); + const Anchor anchor4(std::string_view("STONED")); EXPECT_NE(anchor1, anchor3); EXPECT_NE(anchor3, anchor1); EXPECT_NE(anchor1, anchor4); @@ -90,8 +90,8 @@ TEST(IndexingNodeDataTest, ConstructionNoAnchor) { } TEST(IndexingNodeDataTest, ConstructionVariadicAnchors) { - constexpr absl::string_view text1("abc"); - constexpr absl::string_view text2("xyzzy"); + constexpr std::string_view text1("abc"); + constexpr std::string_view text2("xyzzy"); { const IndexingNodeData indexing_data(IndexingFactType::kFile, Anchor(text1)); @@ -110,8 +110,8 @@ TEST(IndexingNodeDataTest, ConstructionVariadicAnchors) { } TEST(IndexingNodeDataTest, SwapAnchors) { - constexpr absl::string_view text1("abc"); - constexpr absl::string_view text2("xyzzy"); + constexpr std::string_view text1("abc"); + constexpr std::string_view text2("xyzzy"); IndexingNodeData indexing_data1(IndexingFactType::kFile, Anchor(text1)); IndexingNodeData indexing_data2(IndexingFactType::kFile, Anchor(text2)); indexing_data1.SwapAnchors(&indexing_data2); @@ -132,26 +132,26 @@ TEST(IndexingNodeDataTest, Equality) { EXPECT_NE(data2, data1); const IndexingNodeData data3(IndexingFactType::kFile, - Anchor(absl::string_view("fgh"))); + Anchor(std::string_view("fgh"))); EXPECT_EQ(data3, data3); // different number of anchors EXPECT_NE(data1, data3); EXPECT_NE(data3, data1); const IndexingNodeData data4(IndexingFactType::kFile, - Anchor(absl::string_view("ijk"))); + Anchor(std::string_view("ijk"))); // same number of anchors, different text contents EXPECT_NE(data1, data4); EXPECT_NE(data4, data1); } TEST(IndexingNodeDataTest, DebugStringUsingOffsets) { - constexpr absl::string_view text("abcdefghij"); + constexpr std::string_view text("abcdefghij"); const IndexingNodeData data( IndexingFactType::kClass, Anchor(text.substr(1, 2), /*begin=*/1, /*length=*/2), Anchor(text.substr(4, 3), /*begin=*/4, /*length=*/3)); - constexpr absl::string_view expected("kClass: [{bc @1-3}, {efg @4-7}]"); + constexpr std::string_view expected("kClass: [{bc @1-3}, {efg @4-7}]"); { std::ostringstream stream; data.DebugString(&stream); @@ -165,7 +165,7 @@ TEST(IndexingNodeDataTest, DebugStringUsingOffsets) { } TEST(IndexingFactNodeTest, StreamPrint) { - constexpr absl::string_view text("abcdefghij"); + constexpr std::string_view text("abcdefghij"); using Node = IndexingFactNode; const Node node( IndexingNodeData(IndexingFactType::kClass, @@ -174,7 +174,7 @@ TEST(IndexingFactNodeTest, StreamPrint) { Node(IndexingNodeData( IndexingFactType::kClass, Anchor(text.substr(3, 5), /*begin=*/3, /*length=*/5)))); - constexpr absl::string_view expected( + constexpr std::string_view expected( "{ (kClass: [{bc @1-3}, {efg @4-7}])\n" " { (kClass: [{defgh @3-8}]) }\n" "}"); diff --git a/verible/verilog/tools/kythe/kythe-facts-extractor.cc b/verible/verilog/tools/kythe/kythe-facts-extractor.cc index 35d69a348..47263ca37 100644 --- a/verible/verilog/tools/kythe/kythe-facts-extractor.cc +++ b/verible/verilog/tools/kythe/kythe-facts-extractor.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,6 @@ #include "absl/container/node_hash_set.h" #include "absl/hash/hash.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "verible/common/util/auto-pop-stack.h" @@ -45,7 +45,7 @@ namespace { // Returns the file path of the file from the given indexing facts tree node // tagged with kFile. -absl::string_view GetFilePathFromRoot(const IndexingFactNode &root) { +std::string_view GetFilePathFromRoot(const IndexingFactNode &root) { CHECK_EQ(root.Value().GetIndexingFactType(), IndexingFactType::kFile); return root.Value().Anchors()[0].Text(); } @@ -59,7 +59,7 @@ absl::string_view GetFilePathFromRoot(const IndexingFactNode &root) { // the last iteration. class KytheFactsExtractor { public: - KytheFactsExtractor(absl::string_view file_path, absl::string_view corpus, + KytheFactsExtractor(std::string_view file_path, std::string_view corpus, KytheOutput *facts_output, ScopeResolver *previous_files_scopes) : file_path_(file_path), @@ -91,10 +91,10 @@ class KytheFactsExtractor { }; // Returns the full path of the current source file. - absl::string_view FilePath() { return file_path_; } + std::string_view FilePath() { return file_path_; } // Returns the corpus to which this file belongs. - absl::string_view Corpus() const { return corpus_; } + std::string_view Corpus() const { return corpus_; } public: // Extracts kythe facts from the given IndexingFactsTree root. The result is @@ -223,28 +223,28 @@ class KytheFactsExtractor { // Appends the signatures of previous containing scope vname to make // signatures unique relative to scopes. - Signature CreateScopeRelativeSignature(absl::string_view) const; + Signature CreateScopeRelativeSignature(std::string_view) const; // Generates fact strings for Kythe facts. // Schema for this fact can be found here: // https://kythe.io/docs/schema/writing-an-indexer.html - void CreateFact(const VName &vname, absl::string_view name, - absl::string_view value); + void CreateFact(const VName &vname, std::string_view name, + std::string_view value); // Generates edge strings for Kythe edges. // Schema for this edge can be found here: // https://kythe.io/docs/schema/writing-an-indexer.html - void CreateEdge(const VName &source, absl::string_view name, + void CreateEdge(const VName &source, std::string_view name, const VName &target); // Holds the hashes of the output Kythe facts and edges (for deduplication). absl::flat_hash_set seen_kythe_hashes_; // The full path of the current source file. - absl::string_view file_path_; + std::string_view file_path_; // The corpus to which this file belongs. - absl::string_view corpus_; + std::string_view corpus_; // Output for produced Kythe facts. Not owned. KytheOutput *const facts_output_; @@ -282,7 +282,7 @@ void StreamKytheFactsEntries(KytheOutput *kythe_output, const absl::Time extraction_start = absl::Now(); // 'root' corresponds to the fact tree for a particular file. // 'file_path' is path-resolved. - const absl::string_view file_path(GetFilePathFromRoot(root)); + const std::string_view file_path(GetFilePathFromRoot(root)); VLOG(1) << "child file resolved path: " << file_path; // Create facts and edges. @@ -310,7 +310,7 @@ void KytheFactsExtractor::ExtractFile(const IndexingFactNode &root) { std::optional KytheFactsExtractor::GetParentTypeScope( const IndexingFactNode &node) const { - absl::string_view node_name = node.Value().Anchors()[0].Text(); + std::string_view node_name = node.Value().Anchors()[0].Text(); if (node.Parent() == nullptr) { return std::nullopt; } @@ -576,8 +576,7 @@ VName KytheFactsExtractor::DeclareFile(const IndexingFactNode &file_fact_node) { .language = kEmptyKytheLanguage}; const auto &anchors(file_fact_node.Value().Anchors()); CHECK_GE(anchors.size(), 2); - const absl::string_view code_text = - file_fact_node.Value().Anchors()[1].Text(); + const std::string_view code_text = file_fact_node.Value().Anchors()[1].Text(); CreateFact(file_vname, kFactNodeKind, kNodeFile); CreateFact(file_vname, kFactText, code_text); @@ -1158,14 +1157,14 @@ VName KytheFactsExtractor::CreateAnchor(const Anchor &anchor) { } Signature KytheFactsExtractor::CreateScopeRelativeSignature( - absl::string_view signature) const { + std::string_view signature) const { // Append the given signature to the signature of the parent. return Signature(vnames_context_.top().signature, signature); } void KytheFactsExtractor::CreateFact(const VName &vname, - absl::string_view fact_name, - absl::string_view fact_value) { + std::string_view fact_name, + std::string_view fact_value) { Fact fact(vname, fact_name, fact_value); auto hash = absl::HashOf(fact); if (!seen_kythe_hashes_.contains(hash)) { @@ -1175,7 +1174,7 @@ void KytheFactsExtractor::CreateFact(const VName &vname, } void KytheFactsExtractor::CreateEdge(const VName &source_node, - absl::string_view edge_name, + std::string_view edge_name, const VName &target_node) { Edge edge(source_node, edge_name, target_node); auto hash = absl::HashOf(edge); diff --git a/verible/verilog/tools/kythe/kythe-facts.cc b/verible/verilog/tools/kythe/kythe-facts.cc index 2c52cd0bf..3880d91f6 100644 --- a/verible/verilog/tools/kythe/kythe-facts.cc +++ b/verible/verilog/tools/kythe/kythe-facts.cc @@ -17,13 +17,13 @@ #include #include #include +#include #include #include "absl/hash/hash.h" #include "absl/log/check.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/util/spacer.h" namespace verilog { @@ -47,7 +47,7 @@ size_t CombineHash(size_t existing, size_t addition) { // res[2] = hash(0, name[0], name[1]) // ... // res[N] = hash(0, name[0], name[1], ..., name[N]) -std::vector RollingHash(const std::vector &names) { +std::vector RollingHash(const std::vector &names) { if (names.size() <= 1) { return {0}; // Global scope } @@ -68,7 +68,7 @@ std::vector RollingHash(const std::vector &names) { std::string Signature::ToString() const { std::string signature; - for (absl::string_view name : names_) { + for (std::string_view name : names_) { if (name.empty()) continue; absl::StrAppend(&signature, name, "#"); } diff --git a/verible/verilog/tools/kythe/kythe-facts.h b/verible/verilog/tools/kythe/kythe-facts.h index cdb3e4cbd..f7b0b3d64 100644 --- a/verible/verilog/tools/kythe/kythe-facts.h +++ b/verible/verilog/tools/kythe/kythe-facts.h @@ -18,15 +18,14 @@ #include #include #include +#include #include -#include "absl/strings/string_view.h" - namespace verilog { namespace kythe { -inline constexpr absl::string_view kDefaultKytheLanguage = "verilog"; -inline constexpr absl::string_view kEmptyKytheLanguage; +inline constexpr std::string_view kDefaultKytheLanguage = "verilog"; +inline constexpr std::string_view kEmptyKytheLanguage; // Hash-based form of signature for fast and lightweight comparision. struct SignatureDigest { @@ -52,9 +51,9 @@ H AbslHashValue(H state, const SignatureDigest &d) { // Unique identifier for Kythe facts. class Signature { public: - explicit Signature(absl::string_view name = "") : names_({name}) {} + explicit Signature(std::string_view name = "") : names_({name}) {} - Signature(const Signature &parent, absl::string_view name) + Signature(const Signature &parent, std::string_view name) : names_(parent.Names()) { names_.push_back(name); } @@ -70,7 +69,7 @@ class Signature { // Returns the signature concatenated as a string in base 64. std::string ToBase64() const; - const std::vector &Names() const { return names_; } + const std::vector &Names() const { return names_; } // Returns signature's short form for fast and lightweight comparision. SignatureDigest Digest() const; @@ -86,7 +85,7 @@ class Signature { // // for "m" ==> ["m"] // for "x" ==> ["m", "x"] - std::vector names_; + std::vector names_; }; template H AbslHashValue(H state, const Signature &v) { @@ -100,19 +99,19 @@ struct VName { std::ostream &FormatJSON(std::ostream &, bool debug, int indentation = 0) const; // Path for the file the VName is extracted from. - absl::string_view path; + std::string_view path; // A directory path or project identifier inside the Corpus. - absl::string_view root; + std::string_view root; // Unique identifier for this VName. Signature signature; // The corpus of source code this VName belongs to. - absl::string_view corpus; + std::string_view corpus; // The language this VName belongs to. - absl::string_view language = kDefaultKytheLanguage; + std::string_view language = kDefaultKytheLanguage; }; template H AbslHashValue(H state, const VName &v) { @@ -126,7 +125,7 @@ std::ostream &operator<<(std::ostream &, const VName &); // https://www.kythe.io/docs/kythe-storage.html#_a_id_termfact_a_fact // https://www.kythe.io/docs/schema/writing-an-indexer.html#_modeling_kythe_entries struct Fact { - Fact(const VName &vname, absl::string_view name, absl::string_view value) + Fact(const VName &vname, std::string_view name, std::string_view value) : node_vname(vname), fact_name(name), fact_value(value) {} bool operator==(const Fact &other) const; @@ -139,7 +138,7 @@ struct Fact { // The name identifying this fact. // This is one of the constant strings in "kythe_schema_constants.h" - const absl::string_view fact_name; + const std::string_view fact_name; // The given value to this fact. const std::string fact_value; @@ -155,7 +154,7 @@ std::ostream &operator<<(std::ostream &, const Fact &); // For more information: // https://www.kythe.io/docs/schema/writing-an-indexer.html#_modeling_kythe_entries struct Edge { - Edge(const VName &source, absl::string_view name, const VName &target) + Edge(const VName &source, std::string_view name, const VName &target) : source_node(source), edge_name(name), target_node(target) {} bool operator==(const Edge &other) const; @@ -169,7 +168,7 @@ struct Edge { // The edge name which identifies the edge kind. // This is one of the constant strings from "kythe_schema_constants.h" - const absl::string_view edge_name; + const std::string_view edge_name; // The VName of the target node of this edge. const VName target_node; diff --git a/verible/verilog/tools/kythe/kythe-schema-constants.h b/verible/verilog/tools/kythe/kythe-schema-constants.h index 5ce2fa880..3faf8ef53 100644 --- a/verible/verilog/tools/kythe/kythe-schema-constants.h +++ b/verible/verilog/tools/kythe/kythe-schema-constants.h @@ -15,50 +15,49 @@ #ifndef VERIBLE_VERILOG_TOOLS_KYTHE_KYTHE_SCHEMA_CONSTANTS_H_ #define VERIBLE_VERILOG_TOOLS_KYTHE_KYTHE_SCHEMA_CONSTANTS_H_ -#include "absl/strings/string_view.h" +#include namespace verilog { namespace kythe { // Kythe Nodes. -inline constexpr absl::string_view kNodeAnchor = "anchor"; -inline constexpr absl::string_view kNodeRecord = "record"; -inline constexpr absl::string_view kNodeInterface = "interface"; -inline constexpr absl::string_view kNodePackage = "package"; -inline constexpr absl::string_view kNodeMacro = "macro"; -inline constexpr absl::string_view kNodeConstant = "constant"; -inline constexpr absl::string_view kNodeFile = "file"; -inline constexpr absl::string_view kNodeBuiltin = "tbuiltin"; -inline constexpr absl::string_view kSubkindModule = "module"; -inline constexpr absl::string_view kSubkindConstructor = "constructor"; -inline constexpr absl::string_view kSubkindProgram = "program"; -inline constexpr absl::string_view kCompleteDefinition = "definition"; -inline constexpr absl::string_view kInComplete = "incomplete"; -inline constexpr absl::string_view kNodeVariable = "variable"; -inline constexpr absl::string_view kNodeFunction = "function"; -inline constexpr absl::string_view kNodeTAlias = "talias"; +inline constexpr std::string_view kNodeAnchor = "anchor"; +inline constexpr std::string_view kNodeRecord = "record"; +inline constexpr std::string_view kNodeInterface = "interface"; +inline constexpr std::string_view kNodePackage = "package"; +inline constexpr std::string_view kNodeMacro = "macro"; +inline constexpr std::string_view kNodeConstant = "constant"; +inline constexpr std::string_view kNodeFile = "file"; +inline constexpr std::string_view kNodeBuiltin = "tbuiltin"; +inline constexpr std::string_view kSubkindModule = "module"; +inline constexpr std::string_view kSubkindConstructor = "constructor"; +inline constexpr std::string_view kSubkindProgram = "program"; +inline constexpr std::string_view kCompleteDefinition = "definition"; +inline constexpr std::string_view kInComplete = "incomplete"; +inline constexpr std::string_view kNodeVariable = "variable"; +inline constexpr std::string_view kNodeFunction = "function"; +inline constexpr std::string_view kNodeTAlias = "talias"; // Facts for kythe. -inline constexpr absl::string_view kFactText = "/kythe/text"; -inline constexpr absl::string_view kFactNodeKind = "/kythe/node/kind"; -inline constexpr absl::string_view kFactSubkind = "/kythe/subkind"; -inline constexpr absl::string_view kFactComplete = "/kythe/complete"; -inline constexpr absl::string_view kFactAnchorEnd = "/kythe/loc/end"; -inline constexpr absl::string_view kFactAnchorStart = "/kythe/loc/start"; +inline constexpr std::string_view kFactText = "/kythe/text"; +inline constexpr std::string_view kFactNodeKind = "/kythe/node/kind"; +inline constexpr std::string_view kFactSubkind = "/kythe/subkind"; +inline constexpr std::string_view kFactComplete = "/kythe/complete"; +inline constexpr std::string_view kFactAnchorEnd = "/kythe/loc/end"; +inline constexpr std::string_view kFactAnchorStart = "/kythe/loc/start"; // Edges for kythe. -inline constexpr absl::string_view kEdgeDefinesBinding = +inline constexpr std::string_view kEdgeDefinesBinding = "/kythe/edge/defines/binding"; -inline constexpr absl::string_view kEdgeChildOf = "/kythe/edge/childof"; -inline constexpr absl::string_view kEdgeRef = "/kythe/edge/ref"; -inline constexpr absl::string_view kEdgeRefExpands = "/kythe/edge/ref/expands"; -inline constexpr absl::string_view kEdgeRefCall = "/kythe/edge/ref/call"; -inline constexpr absl::string_view kEdgeRefImports = "/kythe/edge/ref/imports"; -inline constexpr absl::string_view kEdgeExtends = "/kythe/edge/extends"; -inline constexpr absl::string_view kEdgeRefIncludes = - "/kythe/edge/ref/includes"; -inline constexpr absl::string_view kEdgeTyped = "/kythe/edge/typed"; -inline constexpr absl::string_view kEdgeOverrides = "/kythe/edge/overrides"; +inline constexpr std::string_view kEdgeChildOf = "/kythe/edge/childof"; +inline constexpr std::string_view kEdgeRef = "/kythe/edge/ref"; +inline constexpr std::string_view kEdgeRefExpands = "/kythe/edge/ref/expands"; +inline constexpr std::string_view kEdgeRefCall = "/kythe/edge/ref/call"; +inline constexpr std::string_view kEdgeRefImports = "/kythe/edge/ref/imports"; +inline constexpr std::string_view kEdgeExtends = "/kythe/edge/extends"; +inline constexpr std::string_view kEdgeRefIncludes = "/kythe/edge/ref/includes"; +inline constexpr std::string_view kEdgeTyped = "/kythe/edge/typed"; +inline constexpr std::string_view kEdgeOverrides = "/kythe/edge/overrides"; } // namespace kythe } // namespace verilog diff --git a/verible/verilog/tools/kythe/kzip-creator.cc b/verible/verilog/tools/kythe/kzip-creator.cc index 3d41a85c2..3453d9a1c 100644 --- a/verible/verilog/tools/kythe/kzip-creator.cc +++ b/verible/verilog/tools/kythe/kzip-creator.cc @@ -16,9 +16,9 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "third_party/proto/kythe/analysis.pb.h" #include "verible/common/util/file-util.h" #include "verible/common/util/sha256.h" @@ -28,16 +28,16 @@ namespace verilog { namespace kythe { namespace { -constexpr absl::string_view kProtoUnitRoot = "root/pbunits/"; -constexpr absl::string_view kFileRoot = "root/files/"; +constexpr std::string_view kProtoUnitRoot = "root/pbunits/"; +constexpr std::string_view kFileRoot = "root/files/"; constexpr int kKZipCompressionLevel = 9; } // namespace -KzipCreator::KzipCreator(absl::string_view output_path) +KzipCreator::KzipCreator(std::string_view output_path) : zip_file_(fopen(std::string(output_path).c_str(), "wb")), - archive_(kKZipCompressionLevel, [this](absl::string_view s) { + archive_(kKZipCompressionLevel, [this](std::string_view s) { return fwrite(s.data(), 1, s.size(), zip_file_.get()) == s.size(); }) { // Create the directory structure. @@ -46,8 +46,8 @@ KzipCreator::KzipCreator(absl::string_view output_path) archive_.AddFile(kProtoUnitRoot, verible::zip::MemoryByteSource("")); } -std::string KzipCreator::AddSourceFile(absl::string_view path, - absl::string_view content) { +std::string KzipCreator::AddSourceFile(std::string_view path, + std::string_view content) { std::string digest = verible::Sha256Hex(content); const std::string archive_path = verible::file::JoinPath(kFileRoot, digest); archive_.AddFile(archive_path, verible::zip::MemoryByteSource(content)); diff --git a/verible/verilog/tools/kythe/kzip-creator.h b/verible/verilog/tools/kythe/kzip-creator.h index 89fc254e0..4ec627555 100644 --- a/verible/verilog/tools/kythe/kzip-creator.h +++ b/verible/verilog/tools/kythe/kzip-creator.h @@ -18,9 +18,9 @@ #include #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "third_party/proto/kythe/analysis.pb.h" #include "verible/common/util/simple-zip.h" @@ -32,10 +32,10 @@ namespace kythe { class KzipCreator final { public: // Initializes the archive. Crashes if initialization fails. - explicit KzipCreator(absl::string_view output_path); + explicit KzipCreator(std::string_view output_path); // Adds source code file to the Kzip. Returns its digest. - std::string AddSourceFile(absl::string_view path, absl::string_view content); + std::string AddSourceFile(std::string_view path, std::string_view content); // Adds compilation unit to the Kzip. absl::Status AddCompilationUnit( diff --git a/verible/verilog/tools/kythe/scope-resolver.cc b/verible/verilog/tools/kythe/scope-resolver.cc index 388f239e5..e4f5c9048 100644 --- a/verible/verilog/tools/kythe/scope-resolver.cc +++ b/verible/verilog/tools/kythe/scope-resolver.cc @@ -16,11 +16,11 @@ #include #include +#include #include #include "absl/container/flat_hash_set.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/util/logging.h" #include "verible/verilog/tools/kythe/kythe-facts.h" @@ -40,7 +40,7 @@ void ScopeResolver::SetCurrentScope(const Signature &scope) { } void ScopeResolver::RemoveDefinitionFromCurrentScope(const VName &vname) { - absl::string_view name = vname.signature.Names().back(); + std::string_view name = vname.signature.Names().back(); auto scopes = variable_to_scoped_vname_.find(name); if (scopes == variable_to_scoped_vname_.end()) { VLOG(1) << "No definition for '" << name << "'. Nothing to remove."; @@ -121,7 +121,7 @@ void ScopeResolver::AddDefinitionToCurrentScope( } std::optional ScopeResolver::FindScopeAndDefinition( - absl::string_view name, const SignatureDigest &scope_focus) { + std::string_view name, const SignatureDigest &scope_focus) { VLOG(2) << "Find definition for '" << name << "' within scope " << ScopeDebug(scope_focus); auto scope = variable_to_scoped_vname_.find(name); @@ -158,7 +158,7 @@ std::optional ScopeResolver::FindScopeAndDefinition( } std::optional ScopeResolver::FindScopeAndDefinition( - absl::string_view name) { + std::string_view name) { return FindScopeAndDefinition(name, CurrentScopeDigest()); } diff --git a/verible/verilog/tools/kythe/scope-resolver.h b/verible/verilog/tools/kythe/scope-resolver.h index 0805cbc52..7550b528b 100644 --- a/verible/verilog/tools/kythe/scope-resolver.h +++ b/verible/verilog/tools/kythe/scope-resolver.h @@ -17,12 +17,12 @@ #include #include +#include #include #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/container/node_hash_map.h" -#include "absl/strings/string_view.h" #include "verible/verilog/tools/kythe/kythe-facts.h" namespace verilog { @@ -92,12 +92,12 @@ class ScopeResolver { // Returns the scope and definition of the symbol under the given name. The // search is restricted to the current scope. - std::optional FindScopeAndDefinition(absl::string_view name); + std::optional FindScopeAndDefinition(std::string_view name); // Returns the scope and definition of the symbol under the given name. The // search is restricted to the provided scope. std::optional FindScopeAndDefinition( - absl::string_view name, const SignatureDigest &scope); + std::string_view name, const SignatureDigest &scope); static SignatureDigest GlobalScope() { return Signature("").Digest(); } diff --git a/verible/verilog/tools/kythe/scope-resolver_test.cc b/verible/verilog/tools/kythe/scope-resolver_test.cc index 951ec8a6c..454c39cfa 100644 --- a/verible/verilog/tools/kythe/scope-resolver_test.cc +++ b/verible/verilog/tools/kythe/scope-resolver_test.cc @@ -14,9 +14,9 @@ #include "verible/verilog/tools/kythe/scope-resolver.h" +#include #include -#include "absl/strings/string_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "verible/verilog/tools/kythe/kythe-facts.h" @@ -27,7 +27,7 @@ namespace { using ::testing::UnorderedElementsAreArray; -constexpr absl::string_view names[] = { +constexpr std::string_view names[] = { "signature0", "signature1", "signature2", "signature3", "signature4", "signature5", "signature6", "signature7", "signature8", "signature9", "", @@ -99,7 +99,7 @@ TEST(ScopeResolverTests, FindDefinitionInDifferentScope) { scope_resolver.AddDefinitionToCurrentScope(vnames[0]); scope_resolver.SetCurrentScope(signatures[0]); - absl::string_view name = vnames[0].signature.Names().back(); + std::string_view name = vnames[0].signature.Names().back(); const auto def_in_current_scope = scope_resolver.FindScopeAndDefinition(name); EXPECT_FALSE(def_in_current_scope.has_value()); @@ -112,7 +112,7 @@ TEST(ScopeResolverTests, RemoveDefinition) { ScopeResolver scope_resolver(signatures[5]); scope_resolver.AddDefinitionToCurrentScope(vnames[0]); - absl::string_view name = vnames[0].signature.Names().back(); + std::string_view name = vnames[0].signature.Names().back(); const auto def_in_current_scope = scope_resolver.FindScopeAndDefinition(name); EXPECT_TRUE(def_in_current_scope.has_value()); @@ -122,7 +122,7 @@ TEST(ScopeResolverTests, RemoveDefinition) { } TEST(ScopeResolverTests, SameNameVariableInMultipleScopes) { - constexpr absl::string_view name = "a"; + constexpr std::string_view name = "a"; Signature sig1(signatures[0], name); VName var1{.path = "", .root = "", .signature = sig1, .corpus = ""}; Signature sig2(signatures[5], name); @@ -173,7 +173,7 @@ TEST(ScopeResolverTests, AppendScope) { scope_resolver.AddDefinitionToCurrentScope(vnames[0]); scope_resolver.SetCurrentScope(signatures[0]); - absl::string_view name = vnames[0].signature.Names().back(); + std::string_view name = vnames[0].signature.Names().back(); const auto def_in_current_scope = scope_resolver.FindScopeAndDefinition(name); EXPECT_FALSE(def_in_current_scope.has_value()); diff --git a/verible/verilog/tools/kythe/verilog-kythe-extractor.cc b/verible/verilog/tools/kythe/verilog-kythe-extractor.cc index b35501f68..df43e5271 100644 --- a/verible/verilog/tools/kythe/verilog-kythe-extractor.cc +++ b/verible/verilog/tools/kythe/verilog-kythe-extractor.cc @@ -15,12 +15,12 @@ #include #include #include +#include #include #include "absl/flags/flag.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/util/enum-flags.h" #include "verible/common/util/init-command-line.h" #include "verible/common/util/logging.h" @@ -62,7 +62,7 @@ static std::ostream &operator<<(std::ostream &stream, PrintMode mode) { return PrintModeStringMap().Unparse(mode, stream); } -static bool AbslParseFlag(absl::string_view text, PrintMode *mode, +static bool AbslParseFlag(std::string_view text, PrintMode *mode, std::string *error) { return PrintModeStringMap().Parse(text, mode, error, "--print_kythe_facts value"); @@ -133,7 +133,7 @@ static void KytheFactsNullPrinter(const IndexingFactNode &file_list_facts_tree, } static std::vector ExtractTranslationUnits( - absl::string_view file_list_path, VerilogProject *project, + std::string_view file_list_path, VerilogProject *project, const std::vector &file_names) { std::vector errors; const verilog::kythe::IndexingFactNode file_list_facts_tree( diff --git a/verible/verilog/tools/kythe/verilog-kythe-kzip-writer.cc b/verible/verilog/tools/kythe/verilog-kythe-kzip-writer.cc index ee959a445..107905b24 100644 --- a/verible/verilog/tools/kythe/verilog-kythe-kzip-writer.cc +++ b/verible/verilog/tools/kythe/verilog-kythe-kzip-writer.cc @@ -13,12 +13,12 @@ // limitations under the License. #include +#include #include #include "absl/flags/flag.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "third_party/proto/kythe/analysis.pb.h" #include "verible/common/util/file-util.h" #include "verible/common/util/init-command-line.h" @@ -80,7 +80,7 @@ Output: Produces Kythe KZip (https://kythe.io/docs/kythe-kzip.html). return 1; } // Normalize the file list - absl::string_view filelist_root = verible::file::Dirname(filelist_path); + std::string_view filelist_root = verible::file::Dirname(filelist_path); for (std::string &file_path : filelist.file_paths) { file_path = verible::file::JoinPath(filelist_root, file_path); } diff --git a/verible/verilog/tools/lint/BUILD b/verible/verilog/tools/lint/BUILD index f7164308d..9ed4f3de2 100644 --- a/verible/verilog/tools/lint/BUILD +++ b/verible/verilog/tools/lint/BUILD @@ -40,7 +40,6 @@ cc_binary( "@abseil-cpp//absl/flags:flag", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/verilog/tools/lint/verilog-lint.cc b/verible/verilog/tools/lint/verilog-lint.cc index 02e5406b0..d7e4f6a5b 100644 --- a/verible/verilog/tools/lint/verilog-lint.cc +++ b/verible/verilog/tools/lint/verilog-lint.cc @@ -24,12 +24,12 @@ #include #include // IWYU pragma: keep // for ostringstream #include // for string, allocator, etc +#include #include #include "absl/flags/flag.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/analysis/violation-handler.h" #include "verible/common/util/enum-flags.h" @@ -71,7 +71,7 @@ std::string AbslUnparseFlag(const AutofixMode &mode) { return stream.str(); } -bool AbslParseFlag(absl::string_view text, AutofixMode *mode, +bool AbslParseFlag(std::string_view text, AutofixMode *mode, std::string *error) { return AutofixModeEnumStringMap().Parse(text, mode, error, "--autofix value"); } @@ -169,7 +169,7 @@ int main(int argc, char **argv) { const verible::ViolationFixer::AnswerChooser applyAllFixes = [](const verible::LintViolation &, - absl::string_view) -> verible::ViolationFixer::Answer { + std::string_view) -> verible::ViolationFixer::Answer { return {verible::ViolationFixer::AnswerChoice::kApplyAll, 0}; }; @@ -217,7 +217,7 @@ int main(int argc, char **argv) { } // All positional arguments are file names. Exclude program name. - for (const absl::string_view filename : + for (const std::string_view filename : verible::make_range(args.begin() + 1, args.end())) { // Copy configuration, so that it can be locally modified per file. auto config_status = verilog::LinterConfigurationFromFlags(filename); diff --git a/verible/verilog/tools/ls/BUILD b/verible/verilog/tools/ls/BUILD index e71a2f124..f2d239e3a 100644 --- a/verible/verilog/tools/ls/BUILD +++ b/verible/verilog/tools/ls/BUILD @@ -44,7 +44,6 @@ cc_library( "@abseil-cpp//absl/container:node_hash_map", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@re2", ], ) @@ -63,7 +62,6 @@ cc_library( "//verible/verilog/analysis:verilog-linter-configuration", "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -105,7 +103,6 @@ cc_library( "//verible/verilog/formatting:formatter", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@nlohmann_json//:singleheader-json", ], ) @@ -163,7 +160,6 @@ cc_library( "//verible/verilog/analysis:symbol-table", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -194,7 +190,6 @@ cc_library( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings:str_format", - "@abseil-cpp//absl/strings:string_view", "@abseil-cpp//absl/time", "@abseil-cpp//absl/types:optional", ], @@ -212,7 +207,6 @@ cc_test( "//verible/common/util:file-util", "//verible/verilog/analysis:verilog-project", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -238,7 +232,6 @@ cc_library( "//verible/verilog/analysis:verilog-project", "@abseil-cpp//absl/flags:flag", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@nlohmann_json//:singleheader-json", ], ) @@ -257,7 +250,6 @@ cc_test( "@abseil-cpp//absl/flags:flag", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", "@nlohmann_json//:singleheader-json", @@ -273,7 +265,6 @@ cc_binary( ":verilog-language-server", "//verible/common/util:init-command-line", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -309,7 +300,6 @@ cc_test( "//verible/verilog/formatting:formatter", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", "@nlohmann_json//:singleheader-json", diff --git a/verible/verilog/tools/ls/autoexpand.cc b/verible/verilog/tools/ls/autoexpand.cc index 992975df6..c1ab6b385 100644 --- a/verible/verilog/tools/ls/autoexpand.cc +++ b/verible/verilog/tools/ls/autoexpand.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -35,7 +36,6 @@ #include "absl/status/status.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "re2/re2.h" #include "verible/common/analysis/syntax-tree-search.h" #include "verible/common/lsp/lsp-protocol.h" @@ -102,14 +102,14 @@ class AutoExpander { // An AUTO matched in the buffer text struct Match { - absl::string_view auto_span; // Span of the entire AUTO - absl::string_view comment_span; // Span of the AUTO pragma comment + std::string_view auto_span; // Span of the entire AUTO + std::string_view comment_span; // Span of the AUTO pragma comment }; // A single AUTO expansion in terms of the replaced span and expanded text struct Expansion { - absl::string_view replaced_span; // Span that is to be replaced - std::string new_text; // Text to replace the span with + std::string_view replaced_span; // Span that is to be replaced + std::string new_text; // Text to replace the span with }; // Represents a port connection @@ -121,9 +121,9 @@ class AutoExpander { // Stores information about the instance the port is connected to struct ConnectedInstance { - std::optional instance; // Name of the instance a port - // is connected to - absl::string_view type; // Type of the instance a port is connected to + std::optional instance; // Name of the instance a port + // is connected to + std::string_view type; // Type of the instance a port is connected to }; // A SystemVerilog range [msb:lsb] @@ -134,7 +134,7 @@ class AutoExpander { // A dimension can be a range, an unsigned integer, or, if it cannot be // interpreted as one of these, a string - using Dimension = std::variant; + using Dimension = std::variant; // Iterates through the given dimension vectors and returns a new one with // each element being the maximum of corresponding original dimensions. @@ -177,8 +177,8 @@ class AutoExpander { Direction direction; // Direction of the port Declaration declaration; // Is it user-declared or autogenerated - absl::string_view::const_iterator it; // Location of the port's declaration - // in the source file + std::string_view::const_iterator it; // Location of the port's declaration + // in the source file // Writes the port's direction to the output stream void EmitDirection(std::ostream &output) const; @@ -195,14 +195,14 @@ class AutoExpander { // Represents an AUTO_TEMPLATE struct Template { - using Map = absl::flat_hash_map>; + using Map = absl::flat_hash_map>; - absl::string_view::const_iterator it; // Location of the template in the + std::string_view::const_iterator it; // Location of the template in the // source file std::shared_ptr instance_name_re; // Regex for matching the instance // name. Shared between templates // declared at the same place - absl::flat_hash_map + absl::flat_hash_map connections; // Map of instance ports ports to connected module ports }; @@ -224,14 +224,14 @@ class AutoExpander { // Writes all port names that match the predicate to the output stream, // under the specified heading comment void EmitNonAnsiPortList( - std::ostream &output, absl::string_view heading, + std::ostream &output, std::string_view heading, const std::function &pred) const; // Writes port connections to all ports to the output stream, under the // specified heading comment void EmitPortConnections(std::ostream &output, - absl::string_view instance_name, - absl::string_view header, + std::string_view instance_name, + std::string_view header, const std::function &pred, const Template *tmpl) const; @@ -244,18 +244,18 @@ class AutoExpander { // Writes wire declarations of undeclared output ports to the output stream, // with the provided span defining which existing wires were autogenerated void EmitUndeclaredWireDeclarations(std::ostream &output, - absl::string_view auto_span) const; + std::string_view auto_span) const; // Writes reg declarations of unconnected output ports to the output stream, // with the provided span defining which existing regs were autogenerated - void EmitUnconnectedOutputRegDeclarations( - std::ostream &output, absl::string_view auto_span) const; + void EmitUnconnectedOutputRegDeclarations(std::ostream &output, + std::string_view auto_span) const; // Calls the closure on each port and the name of the port that should be // connected to it. If a template is given, the connected port name is taken // from the template, otherwise it's the same as the port name. void GenerateConnections( - absl::string_view instance_name, const Template *tmpl, + std::string_view instance_name, const Template *tmpl, const std::function &fun) const; // Set an existing port's connection, or create a new port with the given @@ -274,12 +274,12 @@ class AutoExpander { // Gets all dependencies of the module (modules instantiated within it) void RetrieveDependencies( - const absl::node_hash_map &modules); + const absl::node_hash_map &modules); // Retrieves the matching template from a typename -> template map const Template *GetAutoTemplate( - absl::string_view type_id, absl::string_view instance_name, - absl::string_view::const_iterator instance_it) const; + std::string_view type_id, std::string_view instance_name, + std::string_view::const_iterator instance_it) const; // Returns true if the module depends on (uses) a given module bool DependsOn(const Module *module) const { @@ -308,7 +308,7 @@ class AutoExpander { const verible::Symbol &Symbol() const { return symbol_; } // Returns the module name - absl::string_view Name() const { return name_; } + std::string_view Name() const { return name_; } private: // Gets ports from the header of the module @@ -334,7 +334,7 @@ class AutoExpander { const verible::Symbol &symbol_; // The name of this module - const absl::string_view name_; + const std::string_view name_; // This module's ports std::vector ports_; @@ -369,7 +369,7 @@ class AutoExpander { const auto begin = text_structure.Lines()[min].begin(); const auto end = text_structure.Lines()[max].end(); const size_t length = static_cast(std::distance(begin, end)); - expand_span_ = absl::string_view(&*begin, length); + expand_span_ = std::string_view(&*begin, length); } AutoExpander(const TextStructureView &text_structure, @@ -380,13 +380,13 @@ class AutoExpander { } // Retrieves port names from a module declared before the given location - absl::flat_hash_set GetPortsListedBefore( - const Symbol &module, absl::string_view::const_iterator it) const; + absl::flat_hash_set GetPortsListedBefore( + const Symbol &module, std::string_view::const_iterator it) const; // Retrieves port names from a module instance connected before the given // location - absl::flat_hash_set GetPortsConnectedBefore( - const Symbol &instance, absl::string_view::const_iterator it) const; + absl::flat_hash_set GetPortsConnectedBefore( + const Symbol &instance, std::string_view::const_iterator it) const; // Expands AUTOARG for the given module std::optional ExpandAutoarg(const Module &module) const; @@ -394,13 +394,13 @@ class AutoExpander { // Expands AUTOINST for the given module instance std::optional ExpandAutoinst(Module *module, const Symbol &instance, - absl::string_view type_id); + std::string_view type_id); // Expands AUTO for the given module // Limitation: this only detects ports from AUTOINST. This limitation is also // present in the original Emacs Verilog-mode. std::optional ExpandAutoDeclarations( - const Module &module, Match match, absl::string_view description, + const Module &module, Match match, std::string_view description, const std::function &emit) const; // Expands AUTOINPUT/AUTOINOUT/AUTOOUTPUT for the given module @@ -429,8 +429,8 @@ class AutoExpander { // Finds the span that should be replaced in the symbol (from the start of // the comment span to the end of the symbol span. Used by AUTOARG and // AUTOINST) - std::optional FindSpanToReplace( - const Symbol &symbol, absl::string_view auto_span) const; + std::optional FindSpanToReplace( + const Symbol &symbol, std::string_view auto_span) const; // Checks if the given AUTO kind should be expanded bool ShouldExpand(const AutoKind kind) const { @@ -438,7 +438,7 @@ class AutoExpander { } // Span in which expansions are allowed - absl::string_view expand_span_; + std::string_view expand_span_; // Kinds of AUTOs that can be expanded (all if this set is empty) absl::flat_hash_set allowed_autos_; @@ -450,7 +450,7 @@ class AutoExpander { SymbolTableHandler *symbol_table_handler_; // Gathered module information (module name -> module info) - absl::node_hash_map modules_; + absl::node_hash_map modules_; // Regex for finding any AUTOs static const LazyRE2 auto_re_; @@ -640,7 +640,7 @@ void AutoExpander::Port::EmitConnectionComment(std::ostream &output) const { if (conn_inst.empty()) return; const auto &instance = conn_inst[0].instance; if (!instance) return; - const absl::string_view type = conn_inst[0].type; + const std::string_view type = conn_inst[0].type; switch (direction) { case Direction::kInput: output << " // To " << *instance << " of " << type; @@ -669,7 +669,7 @@ void AutoExpander::Wire::EmitConnectionComment(std::ostream &output) const { } void AutoExpander::Module::EmitNonAnsiPortList( - std::ostream &output, const absl::string_view heading, + std::ostream &output, const std::string_view heading, const std::function &pred) const { bool first = true; for (const Port &port : ports_) { @@ -686,8 +686,8 @@ void AutoExpander::Module::EmitNonAnsiPortList( } void AutoExpander::Module::EmitPortConnections( - std::ostream &output, const absl::string_view instance_name, - const absl::string_view header, + std::ostream &output, const std::string_view instance_name, + const std::string_view header, const std::function &pred, const Template *tmpl) const { bool first = true; GenerateConnections( @@ -726,18 +726,18 @@ void AutoExpander::Module::EmitPortConnections( } // Checks if two string spans are overlapping -bool SpansOverlapping(const absl::string_view first, - const absl::string_view second) { +bool SpansOverlapping(const std::string_view first, + const std::string_view second) { return first.end() > second.begin() && first.begin() < second.end(); } void AutoExpander::Module::EmitUndeclaredWireDeclarations( - std::ostream &output, const absl::string_view auto_span) const { - absl::flat_hash_set declared_wires; + std::ostream &output, const std::string_view auto_span) const { + absl::flat_hash_set declared_wires; for (const auto ® : FindAllNetVariables(symbol_)) { const SyntaxTreeLeaf *const net_name_leaf = GetNameLeafOfNetVariable(*reg.match); - const absl::string_view net_name = net_name_leaf->get().text(); + const std::string_view net_name = net_name_leaf->get().text(); if (!SpansOverlapping(net_name, auto_span)) { declared_wires.insert(net_name); } @@ -764,12 +764,12 @@ void AutoExpander::Module::EmitUndeclaredWireDeclarations( } void AutoExpander::Module::EmitUnconnectedOutputRegDeclarations( - std::ostream &output, const absl::string_view auto_span) const { - absl::flat_hash_set declared_regs; + std::ostream &output, const std::string_view auto_span) const { + absl::flat_hash_set declared_regs; for (const auto ® : FindAllRegisterVariables(symbol_)) { const SyntaxTreeLeaf *const reg_name_leaf = GetNameLeafOfRegisterVariable(*reg.match); - const absl::string_view reg_name = reg_name_leaf->get().text(); + const std::string_view reg_name = reg_name_leaf->get().text(); if (!SpansOverlapping(reg_name, auto_span)) { declared_regs.insert(reg_name); } @@ -787,7 +787,7 @@ void AutoExpander::Module::EmitUnconnectedOutputRegDeclarations( } void AutoExpander::Module::GenerateConnections( - absl::string_view instance_name, const Template *tmpl, + std::string_view instance_name, const Template *tmpl, const std::function &fun) const { for (const Port &port : ports_) { Connection connected{.port_name = port.name, .emit_dimensions = true}; @@ -861,9 +861,9 @@ void AutoExpander::Module::SortPortsByLocation() { } void AutoExpander::Module::RetrieveAutoTemplates() { - absl::string_view autotmpl_search_span = StringSpanOfSymbol(symbol_); - absl::string_view autotmpl_span; - absl::string_view autotmpl_inst_name; + std::string_view autotmpl_search_span = StringSpanOfSymbol(symbol_); + std::string_view autotmpl_span; + std::string_view autotmpl_inst_name; while (RE2::FindAndConsume(&autotmpl_search_span, *autotemplate_re_, &autotmpl_span, &autotmpl_inst_name)) { Template tmpl{.it = autotmpl_span.begin()}; @@ -875,10 +875,10 @@ void AutoExpander::Module::RetrieveAutoTemplates() { } } - absl::string_view autotmpl_conn_search_span = autotmpl_span; - absl::string_view instance_port_name; - absl::string_view module_port_name; - absl::string_view dimensions; + std::string_view autotmpl_conn_search_span = autotmpl_span; + std::string_view instance_port_name; + std::string_view module_port_name; + std::string_view dimensions; while (RE2::FindAndConsume(&autotmpl_conn_search_span, *autotemplate_conn_re_, &instance_port_name, &module_port_name, &dimensions)) { @@ -888,8 +888,8 @@ void AutoExpander::Module::RetrieveAutoTemplates() { .emit_dimensions = !dimensions.empty()})); } - absl::string_view autotmpl_type_search_span = autotmpl_span; - absl::string_view instance_type_name; + std::string_view autotmpl_type_search_span = autotmpl_span; + std::string_view instance_type_name; while (RE2::FindAndConsume(&autotmpl_type_search_span, *autotemplate_type_re_, &instance_type_name)) { templates_[instance_type_name].push_back(tmpl); @@ -898,13 +898,13 @@ void AutoExpander::Module::RetrieveAutoTemplates() { } void AutoExpander::Module::RetrieveDependencies( - const absl::node_hash_map &modules) { + const absl::node_hash_map &modules) { for (const auto &data : FindAllDataDeclarations(symbol_)) { const verible::Symbol *const type_id_node = GetTypeIdentifierFromDataDeclaration(*data.match); // Some data declarations do not have a type id, ignore those if (!type_id_node) continue; - const absl::string_view dependency_name = StringSpanOfSymbol(*type_id_node); + const std::string_view dependency_name = StringSpanOfSymbol(*type_id_node); const auto it = modules.find(dependency_name); if (it != modules.end()) { dependencies_.insert(&it->second); @@ -913,8 +913,8 @@ void AutoExpander::Module::RetrieveDependencies( } const AutoExpander::Template *AutoExpander::Module::GetAutoTemplate( - const absl::string_view type_id, const absl::string_view instance_name, - const absl::string_view::const_iterator instance_it) const { + const std::string_view type_id, const std::string_view instance_name, + const std::string_view::const_iterator instance_it) const { const auto it = templates_.find(type_id); if (it == templates_.end()) return nullptr; const Template *matching_tmpl = nullptr; @@ -980,7 +980,7 @@ std::vector GetDimensionsFromNodes( SearchSyntaxTree(*dimension.match, NodekDimensionScalar())) { size_t size; const Symbol &scalar_value = *SymbolCastToNode(*scalar.match)[1]; - const absl::string_view span = StringSpanOfSymbol(scalar_value); + const std::string_view span = StringSpanOfSymbol(scalar_value); const bool result = absl::SimpleAtoi(span, &size); dimensions.push_back(result ? Dimension{size} : Dimension{span}); } @@ -997,9 +997,9 @@ std::vector GetDimensionsFromNodes( dimensions.push_back( AutoExpander::DimensionRange{.msb = msb, .lsb = lsb}); } else { - const absl::string_view left_span = StringSpanOfSymbol(*left); - const absl::string_view right_span = StringSpanOfSymbol(*right); - dimensions.push_back(absl::string_view{ + const std::string_view left_span = StringSpanOfSymbol(*left); + const std::string_view right_span = StringSpanOfSymbol(*right); + dimensions.push_back(std::string_view{ &*left_span.begin(), static_cast(std::distance( left_span.begin(), right_span.end()))}); } @@ -1019,7 +1019,7 @@ void AutoExpander::Module::PutDeclaredPort(const SyntaxTreeNode &port_node) { ? GetIdentifierFromPortDeclaration(port_node) : GetIdentifierFromModulePortDeclaration(port_node); if (!dir_leaf || !id_leaf) return; - const absl::string_view dir_span = dir_leaf->get().text(); + const std::string_view dir_span = dir_leaf->get().text(); const std::string name{id_leaf->get().text()}; std::vector packed_dimensions = GetDimensionsFromNodes(FindAllPackedDimensions(port_node)); @@ -1062,9 +1062,9 @@ bool AutoExpander::Module::DependsOn( return false; } -absl::flat_hash_set AutoExpander::GetPortsListedBefore( - const Symbol &module, const absl::string_view::const_iterator it) const { - absl::flat_hash_set ports_before; +absl::flat_hash_set AutoExpander::GetPortsListedBefore( + const Symbol &module, const std::string_view::const_iterator it) const { + absl::flat_hash_set ports_before; const auto all_ports = GetModulePortDeclarationList(module); if (!all_ports) return {}; @@ -1097,9 +1097,9 @@ absl::flat_hash_set AutoExpander::GetPortsListedBefore( return ports_before; } -absl::flat_hash_set AutoExpander::GetPortsConnectedBefore( - const Symbol &instance, const absl::string_view::const_iterator it) const { - absl::flat_hash_set ports_before; +absl::flat_hash_set AutoExpander::GetPortsConnectedBefore( + const Symbol &instance, const std::string_view::const_iterator it) const { + absl::flat_hash_set ports_before; for (const auto &port : FindAllActualNamedPort(instance)) { const SyntaxTreeLeaf *const id_node = GetActualNamedPortName(*port.match); if (!id_node) { @@ -1117,9 +1117,9 @@ absl::flat_hash_set AutoExpander::GetPortsConnectedBefore( // Does a regex search in the span of the given symbol, returns match std::optional FindMatchInSymbol(const Symbol &symbol, const RE2 &re) { - const absl::string_view symbol_span = StringSpanOfSymbol(symbol); - absl::string_view match; - absl::string_view comment; + const std::string_view symbol_span = StringSpanOfSymbol(symbol); + std::string_view match; + std::string_view comment; if (RE2::PartialMatch(symbol_span, re, &match, &comment)) { return AutoExpander::Match{.auto_span = match, .comment_span = comment}; } @@ -1127,10 +1127,10 @@ std::optional FindMatchInSymbol(const Symbol &symbol, } // Does a regex search in the span of the given symbol, returns matched span -std::optional FindSpanInSymbol(const Symbol &symbol, - const RE2 &re) { - const absl::string_view symbol_span = StringSpanOfSymbol(symbol); - absl::string_view match; +std::optional FindSpanInSymbol(const Symbol &symbol, + const RE2 &re) { + const std::string_view symbol_span = StringSpanOfSymbol(symbol); + std::string_view match; if (RE2::PartialMatch(symbol_span, re, &match)) { return match; } @@ -1139,7 +1139,7 @@ std::optional FindSpanInSymbol(const Symbol &symbol, // Returns the deepest node that contains the given span const Symbol *FindNodeContainingSpan(const Symbol &root, - const absl::string_view span) { + const std::string_view span) { return FindLastSubtree(&root, [span](const Symbol &sym) { auto sym_span = StringSpanOfSymbol(sym); return span.begin() >= sym_span.begin() && sym_span.end() >= span.end(); @@ -1149,7 +1149,7 @@ const Symbol *FindNodeContainingSpan(const Symbol &root, // Returns true if the given span is directly under the port declaration list // (or the port paren group if there is no port declaration list) bool IsSpanDirectlyUnderPortDeclarationList(const Symbol &port_parens, - const absl::string_view span) { + const std::string_view span) { if (const Symbol *symbol = FindNodeContainingSpan(port_parens, span)) { return symbol == &port_parens || NodeEnum(symbol->Tag().tag) == NodeEnum::kPortDeclarationList; @@ -1197,7 +1197,7 @@ std::optional AutoExpander::ExpandAutoarg( // Returns true if the given span is directly under the port actual list (or // instance paren group if there is no port actual list) bool IsSpanDirectlyUnderPortActualList(const Symbol &instance_parens, - const absl::string_view span) { + const std::string_view span) { if (const Symbol *symbol = FindNodeContainingSpan(instance_parens, span)) { return symbol == &instance_parens || NodeEnum(symbol->Tag().tag) == NodeEnum::kPortActualList; @@ -1206,7 +1206,7 @@ bool IsSpanDirectlyUnderPortActualList(const Symbol &instance_parens, } std::optional AutoExpander::ExpandAutoinst( - Module *module, const Symbol &instance, absl::string_view type_id) { + Module *module, const Symbol &instance, std::string_view type_id) { if (!ShouldExpand(AutoKind::kAutoinst)) return std::nullopt; const SyntaxTreeNode *parens = GetParenGroupFromModuleInstantiation(instance); @@ -1243,7 +1243,7 @@ std::optional AutoExpander::ExpandAutoinst( LOG(ERROR) << "AUTOINST: Instance with no name, aborting"; return std::nullopt; } - const absl::string_view instance_name = instance_name_token->text(); + const std::string_view instance_name = instance_name_token->text(); const Template *const tmpl = module->GetAutoTemplate( inst_module.Name(), instance_name, StringSpanOfSymbol(instance).begin()); @@ -1294,8 +1294,7 @@ std::optional AutoExpander::ExpandAutoinst( } std::optional AutoExpander::ExpandAutoDeclarations( - const Module &module, const Match match, - const absl::string_view description, + const Module &module, const Match match, const std::string_view description, const std::function &emit) const { std::stringstream new_text; new_text << match.comment_span << "\n// Beginning of automatic " @@ -1317,7 +1316,7 @@ std::optional AutoExpander::ExpandAutoDeclarations( // Returns true if the span is directly under the module item list (or the // module if there is no module item list) bool IsSpanDirectlyUnderModule(const Symbol &module, - const absl::string_view span) { + const std::string_view span) { if (const Symbol *symbol = FindNodeContainingSpan(module, span)) { return symbol == &module || NodeEnum(symbol->Tag().tag) == NodeEnum::kModuleItemList; @@ -1329,7 +1328,7 @@ std::optional AutoExpander::ExpandAutoPorts( Module *module, const std::optional match, const Port::Direction direction) const { if (!match) return std::nullopt; - const absl::string_view module_span = StringSpanOfSymbol(module->Symbol()); + const std::string_view module_span = StringSpanOfSymbol(module->Symbol()); const auto begin = match->auto_span.end(); auto end = module_span.end(); const SyntaxTreeNode *const port_parens = @@ -1352,11 +1351,11 @@ std::optional AutoExpander::ExpandAutoPorts( in_header ? last ? PortDeclStyle::kCommaSeparatorExceptLast : PortDeclStyle::kCommaSeparator : PortDeclStyle::kColonSeparator; - const absl::string_view description = direction == Port::Direction::kInput - ? "inputs (from autoinst inputs)" - : direction == Port::Direction::kInout - ? "inouts (from autoinst inouts)" - : "outputs (from autoinst outputs)"; + const std::string_view description = direction == Port::Direction::kInput + ? "inputs (from autoinst inputs)" + : direction == Port::Direction::kInout + ? "inouts (from autoinst inouts)" + : "outputs (from autoinst outputs)"; if (!SpansOverlapping(match->auto_span, expand_span_)) return std::nullopt; auto result = ExpandAutoDeclarations( @@ -1488,7 +1487,7 @@ std::vector AutoExpander::Expand() { GetTypeIdentifierFromDataDeclaration(*data.match); // Some data declarations do not have a type id, ignore those if (!type_id_node) continue; - const absl::string_view type_id = StringSpanOfSymbol(*type_id_node); + const std::string_view type_id = StringSpanOfSymbol(*type_id_node); for (const auto &instance : FindAllGateInstances(*data.match)) { if (const auto expansion = ExpandAutoinst(module, *instance.match, type_id)) { @@ -1542,8 +1541,8 @@ std::vector AutoExpander::Expand() { absl::flat_hash_set AutoExpander::FindAutoKinds() { absl::flat_hash_set kinds; - absl::string_view search_span = expand_span_; - absl::string_view auto_str; + std::string_view search_span = expand_span_; + std::string_view auto_str; while (RE2::FindAndConsume(&search_span, *auto_re_, &auto_str)) { if (auto_str == "AUTOARG") { kinds.insert(AutoKind::kAutoarg); @@ -1566,12 +1565,12 @@ absl::flat_hash_set AutoExpander::FindAutoKinds() { return kinds; } -std::optional AutoExpander::FindSpanToReplace( - const Symbol &symbol, const absl::string_view auto_span) const { - const absl::string_view symbol_span = StringSpanOfSymbol(symbol); +std::optional AutoExpander::FindSpanToReplace( + const Symbol &symbol, const std::string_view auto_span) const { + const std::string_view symbol_span = StringSpanOfSymbol(symbol); const size_t replaced_length = static_cast( std::distance(auto_span.begin(), symbol_span.end() - 1)); - const absl::string_view replaced_span{&*auto_span.begin(), replaced_length}; + const std::string_view replaced_span{&*auto_span.begin(), replaced_length}; if (!SpansOverlapping(replaced_span, expand_span_)) { return std::nullopt; } diff --git a/verible/verilog/tools/ls/autoexpand_test.cc b/verible/verilog/tools/ls/autoexpand_test.cc index 3cdfcf713..4b313a0e4 100644 --- a/verible/verilog/tools/ls/autoexpand_test.cc +++ b/verible/verilog/tools/ls/autoexpand_test.cc @@ -21,11 +21,11 @@ #include #include #include +#include #include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "nlohmann/json.hpp" #include "verible/common/lsp/lsp-protocol.h" @@ -52,7 +52,7 @@ using verible::lsp::TextEdit; // Generate a specific code action and extract text edits from it std::vector AutoExpandCodeActionToTextEdits( SymbolTableHandler *symbol_table_handler, const BufferTracker *tracker, - Range range, absl::string_view title) { + Range range, std::string_view title) { CodeActionParams p = {.textDocument = {tracker->current()->uri()}, .range = range}; nlohmann::json changes; @@ -100,16 +100,15 @@ struct TestRun { }; // Checks if the given Verilog source has correct syntax -void CheckSyntax(const absl::string_view filename, - const absl::string_view text) { +void CheckSyntax(const std::string_view filename, const std::string_view text) { verilog::VerilogAnalyzer analyzer(text, filename); const absl::Status status = analyzer.Analyze(); ASSERT_TRUE(status.ok()); } // Helper function that formats the given Verilog string -std::string Format(const absl::string_view filename, - const absl::string_view text_before_formatting) { +std::string Format(const std::string_view filename, + const std::string_view text_before_formatting) { std::stringstream strstr; formatter::FormatStyle format_style; formatter::InitializeFromFlags(&format_style); @@ -124,8 +123,8 @@ std::string Format(const absl::string_view filename, // effect void TestTextEditsWithProject( - const std::vector &project_file_contents, - absl::string_view text_before, const absl::string_view text_golden, + const std::vector &project_file_contents, + std::string_view text_before, const std::string_view text_golden, std::deque runs = TestRun::defaultRuns()) { if (runs.empty()) return; const auto &run = runs.front(); @@ -134,7 +133,7 @@ void TestTextEditsWithProject( const std::shared_ptr proj = std::make_shared(".", std::vector()); size_t i = 0; - for (const absl::string_view file_contents : project_file_contents) { + for (const std::string_view file_contents : project_file_contents) { const std::string filename = absl::StrCat("<>"); proj->AddVirtualFile(filename, Format(filename, file_contents)); i++; @@ -174,7 +173,7 @@ void TestTextEditsWithProject( .range = edit.range, .has_range = true, .text = edit.newText}); } // Check the result and (possibly) test again to check idempotence - buffer.RequestContent([&](const absl::string_view text_after) { + buffer.RequestContent([&](const std::string_view text_after) { if (run.check_golden) { if (run.check_formatting) { // TODO: Check multiple formatting styles @@ -195,8 +194,8 @@ void TestTextEditsWithProject( } // Same as above, without the project file parameter -void TestTextEdits(const absl::string_view text_before, - const absl::string_view text_golden, +void TestTextEdits(const std::string_view text_before, + const std::string_view text_golden, const std::deque &runs = TestRun::defaultRuns()) { TestTextEditsWithProject({}, text_before, text_golden, runs); } diff --git a/verible/verilog/tools/ls/hover.cc b/verible/verilog/tools/ls/hover.cc index 036a35a77..817fee039 100644 --- a/verible/verilog/tools/ls/hover.cc +++ b/verible/verilog/tools/ls/hover.cc @@ -17,9 +17,9 @@ #include #include +#include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/lsp/lsp-protocol.h" #include "verible/common/text/concrete-syntax-leaf.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -50,9 +50,9 @@ class FindBeginLabel : public TreeContextVisitor { public: // Performs search of the label for end entry, based on its location in // string and tags - absl::string_view LabelSearch(const verible::ConcreteSyntaxTree &tree, - absl::string_view substring, NodeEnum endtag, - NodeEnum begintag) { + std::string_view LabelSearch(const verible::ConcreteSyntaxTree &tree, + std::string_view substring, NodeEnum endtag, + NodeEnum begintag) { substring_ = substring; begintag_ = begintag; endtag_ = endtag; @@ -99,10 +99,10 @@ class FindBeginLabel : public TreeContextVisitor { } } - absl::string_view substring_; + std::string_view substring_; NodeEnum endtag_; NodeEnum begintag_; - absl::string_view label_; + std::string_view label_; bool substring_found_; bool finished_; }; @@ -145,7 +145,7 @@ class HoverBuilder { parsedbuffer->parser().SyntaxTree(); if (!tree) return; FindBeginLabel search; - absl::string_view label = search.LabelSearch( + std::string_view label = search.LabelSearch( tree, token.text(), NodeEnum::kEnd, NodeEnum::kBegin); if (label.empty()) return; response->contents.value = "### End of block\n\n"; @@ -155,7 +155,7 @@ class HoverBuilder { void HoverInfoIdentifier(verible::lsp::Hover *response, const verible::TokenInfo &token) { - absl::string_view symbol = token.text(); + std::string_view symbol = token.text(); const SymbolTableNode *node = symbol_table_handler_->FindDefinitionNode(symbol); if (!node) return; diff --git a/verible/verilog/tools/ls/lsp-parse-buffer.cc b/verible/verilog/tools/ls/lsp-parse-buffer.cc index 7d9328f23..be082192c 100644 --- a/verible/verilog/tools/ls/lsp-parse-buffer.cc +++ b/verible/verilog/tools/ls/lsp-parse-buffer.cc @@ -19,12 +19,12 @@ #include #include #include +#include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/lsp/lsp-file-utils.h" #include "verible/common/lsp/lsp-text-buffer.h" @@ -35,7 +35,7 @@ namespace verilog { static absl::StatusOr> RunLinter( - absl::string_view filename, const verilog::VerilogAnalyzer &parser) { + std::string_view filename, const verilog::VerilogAnalyzer &parser) { const auto &text_structure = parser.Data(); verilog::LinterConfiguration config; @@ -50,8 +50,8 @@ static absl::StatusOr> RunLinter( return VerilogLintTextStructure(filename, config, text_structure); } -ParsedBuffer::ParsedBuffer(int64_t version, absl::string_view uri, - absl::string_view content) +ParsedBuffer::ParsedBuffer(int64_t version, std::string_view uri, + std::string_view content) : version_(version), uri_(uri), parser_(verilog::VerilogAnalyzer::AnalyzeAutomaticPreprocessFallback( @@ -70,7 +70,7 @@ void BufferTracker::Update(const std::string &uri, LOG(DFATAL) << "Testing: Forgot to update version number ?"; return; // Nothing to do (we don't really expect this to happen) } - txt.RequestContent([&txt, &uri, this](absl::string_view content) { + txt.RequestContent([&txt, &uri, this](std::string_view content) { current_.reset(new ParsedBuffer(txt.last_global_version(), uri, content)); }); if (current_->parsed_successfully()) { diff --git a/verible/verilog/tools/ls/lsp-parse-buffer.h b/verible/verilog/tools/ls/lsp-parse-buffer.h index 586ad9d95..c675f7441 100644 --- a/verible/verilog/tools/ls/lsp-parse-buffer.h +++ b/verible/verilog/tools/ls/lsp-parse-buffer.h @@ -20,10 +20,10 @@ #include #include #include +#include #include #include -#include "absl/strings/string_view.h" #include "verible/common/analysis/lint-rule-status.h" #include "verible/common/lsp/lsp-text-buffer.h" #include "verible/common/util/logging.h" @@ -43,8 +43,7 @@ namespace verilog { // std::future<>s evaluated in separate threads. class ParsedBuffer { public: - ParsedBuffer(int64_t version, absl::string_view uri, - absl::string_view content); + ParsedBuffer(int64_t version, std::string_view uri, std::string_view content); bool parsed_successfully() const { return parser_->LexStatus().ok() && parser_->ParseStatus().ok(); diff --git a/verible/verilog/tools/ls/symbol-table-handler.cc b/verible/verilog/tools/ls/symbol-table-handler.cc index ef8bee5c7..68f5a6ec8 100644 --- a/verible/verilog/tools/ls/symbol-table-handler.cc +++ b/verible/verilog/tools/ls/symbol-table-handler.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "absl/container/flat_hash_map.h" @@ -29,7 +30,6 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "verible/common/lsp/lsp-file-utils.h" @@ -79,7 +79,7 @@ static void LogFullIfVLog(const std::vector &statuses) { LOG(WARNING) << "skipped remaining; switch VLOG(2) on for all " << statuses.size() << " statuses."; LOG(INFO) << "Here a summary"; - std::map sort_by_count; + std::map sort_by_count; for (const auto &stat : status_counts) { sort_by_count.emplace(stat.second, stat.first); } @@ -89,7 +89,7 @@ static void LogFullIfVLog(const std::vector &statuses) { } } -std::string FindFileList(absl::string_view current_dir) { +std::string FindFileList(std::string_view current_dir) { // search for FileList file up the directory hierarchy std::string projectpath; if (auto status = verible::file::UpwardFileSearch( @@ -149,7 +149,7 @@ std::vector SymbolTableHandler::BuildProjectSymbolTable() { return buildstatus; } -bool SymbolTableHandler::LoadProjectFileList(absl::string_view current_dir) { +bool SymbolTableHandler::LoadProjectFileList(std::string_view current_dir) { VLOG(1) << __FUNCTION__; if (!curr_project_) return false; if (filelist_path_.empty()) { @@ -186,7 +186,7 @@ bool SymbolTableHandler::LoadProjectFileList(absl::string_view current_dir) { // add directory containing filelist to includes // TODO (glatosinski): should we do this? - const absl::string_view filelist_dir = verible::file::Dirname(filelist_path_); + const std::string_view filelist_dir = verible::file::Dirname(filelist_path_); curr_project_->AddIncludePath(filelist_dir); VLOG(1) << "Adding \"" << filelist_dir << "\" to include directories"; // update include directories in project @@ -224,7 +224,7 @@ bool SymbolTableHandler::LoadProjectFileList(absl::string_view current_dir) { } const SymbolTableNode *ScanSymbolTreeForDefinitionReferenceComponents( - const ReferenceComponentNode *ref, absl::string_view symbol) { + const ReferenceComponentNode *ref, std::string_view symbol) { if (verible::IsSubRange(symbol, ref->Value().identifier)) { return ref->Value().resolved_symbol; } @@ -237,7 +237,7 @@ const SymbolTableNode *ScanSymbolTreeForDefinitionReferenceComponents( } const SymbolTableNode *SymbolTableHandler::ScanSymbolTreeForDefinition( - const SymbolTableNode *context, absl::string_view symbol) { + const SymbolTableNode *context, std::string_view symbol) { if (!context) { return nullptr; } @@ -345,7 +345,7 @@ SymbolTableHandler::GetTokenRangeAtTextDocumentPosition( } std::optional SymbolTableHandler::GetLocationFromSymbolName( - absl::string_view symbol_name, const VerilogSourceFile *file_origin) { + std::string_view symbol_name, const VerilogSourceFile *file_origin) { // TODO (glatosinski) add iterating over multiple definitions if (!file_origin && curr_project_) { file_origin = curr_project_->LookupFileOrigin(symbol_name); @@ -371,7 +371,7 @@ std::vector SymbolTableHandler::FindDefinitionLocation( std::optional token = GetTokenAtTextDocumentPosition(params, parsed_buffers); if (!token) return {}; - absl::string_view symbol = token->text(); + std::string_view symbol = token->text(); VLOG(1) << "Looking for symbol: " << symbol; VerilogSourceFile *reffile = @@ -399,13 +399,13 @@ std::vector SymbolTableHandler::FindDefinitionLocation( } const SymbolTableNode *SymbolTableHandler::FindDefinitionNode( - absl::string_view symbol) { + std::string_view symbol) { Prepare(); return ScanSymbolTreeForDefinition(&symbol_table_->Root(), symbol); } const verible::Symbol *SymbolTableHandler::FindDefinitionSymbol( - absl::string_view symbol) { + std::string_view symbol) { const SymbolTableNode *symbol_table_node = FindDefinitionNode(symbol); if (symbol_table_node) return symbol_table_node->Value().syntax_origin; return nullptr; @@ -418,7 +418,7 @@ std::vector SymbolTableHandler::FindReferencesLocations( std::optional token = GetTokenAtTextDocumentPosition(params, parsed_buffers); if (!token) return {}; - const absl::string_view symbol = token->text(); + const std::string_view symbol = token->text(); const SymbolTableNode &root = symbol_table_->Root(); const SymbolTableNode *node = ScanSymbolTreeForDefinition(&root, symbol); if (!node) { @@ -457,7 +457,7 @@ SymbolTableHandler::FindRenameLocationsAndCreateEdits( std::optional token = GetTokenAtTextDocumentPosition(params, parsed_buffers); if (!token) return {}; - absl::string_view symbol = token->text(); + std::string_view symbol = token->text(); const SymbolTableNode &root = symbol_table_->Root(); const SymbolTableNode *node = ScanSymbolTreeForDefinition(&root, symbol); if (!node) return {}; @@ -469,7 +469,7 @@ SymbolTableHandler::FindRenameLocationsAndCreateEdits( std::vector textedits; CollectReferences(&root, node, &locations); if (locations.empty()) return {}; - std::map> + std::map> file_edit_pairs; for (const auto &loc : locations) { file_edit_pairs[loc.uri].reserve(locations.size()); @@ -528,7 +528,7 @@ void SymbolTableHandler::CollectReferences( } void SymbolTableHandler::UpdateFileContent( - absl::string_view path, const verilog::VerilogAnalyzer *parsed) { + std::string_view path, const verilog::VerilogAnalyzer *parsed) { files_dirty_ = true; curr_project_->UpdateFileContents(path, parsed); } diff --git a/verible/verilog/tools/ls/symbol-table-handler.h b/verible/verilog/tools/ls/symbol-table-handler.h index 75cb6bde2..6dd4a2a2d 100644 --- a/verible/verilog/tools/ls/symbol-table-handler.h +++ b/verible/verilog/tools/ls/symbol-table-handler.h @@ -20,10 +20,10 @@ #include #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "verible/common/lsp/lsp-protocol.h" #include "verible/common/strings/line-column-map.h" @@ -37,7 +37,7 @@ namespace verilog { // Looks for FileList file for SymbolTableHandler -std::string FindFileList(absl::string_view current_dir); +std::string FindFileList(std::string_view current_dir); // A class interfacing the SymbolTable with the LSP messages. // It manages the SymbolTable and its necessary components, @@ -62,10 +62,10 @@ class SymbolTableHandler { const verilog::BufferTrackerContainer &parsed_buffers); // Finds the node of the symbol table with definition for a given symbol. - const SymbolTableNode *FindDefinitionNode(absl::string_view symbol); + const SymbolTableNode *FindDefinitionNode(std::string_view symbol); // Finds the symbol of the definition for the given identifier. - const verible::Symbol *FindDefinitionSymbol(absl::string_view symbol); + const verible::Symbol *FindDefinitionSymbol(std::string_view symbol); // Finds references of a symbol provided in the ReferenceParams // message delivered in textDocument/references message. @@ -93,7 +93,7 @@ class SymbolTableHandler { // Provide new parsed content for the given path. If "content" is nullptr, // opens the given file instead. - void UpdateFileContent(absl::string_view path, + void UpdateFileContent(std::string_view path, const verilog::VerilogAnalyzer *parsed); // Create a listener to be wired up to a buffer tracker. Whenever we @@ -126,12 +126,12 @@ class SymbolTableHandler { // pointed by the file_origin. // If given symbol name is not found, std::nullopt is returned. std::optional GetLocationFromSymbolName( - absl::string_view symbol_name, const VerilogSourceFile *file_origin); + std::string_view symbol_name, const VerilogSourceFile *file_origin); // Scans the symbol table tree to find a given symbol. // returns pointer to table node with the symbol on success, else nullptr. const SymbolTableNode *ScanSymbolTreeForDefinition( - const SymbolTableNode *context, absl::string_view symbol); + const SymbolTableNode *context, std::string_view symbol); // Internal function for CollectReferences that iterates over // ReferenceComponentNodes @@ -148,7 +148,7 @@ class SymbolTableHandler { // Looks for verible.filelist file down in directory structure and loads // data to project. It is meant to be executed once per VerilogProject setup - bool LoadProjectFileList(absl::string_view current_dir); + bool LoadProjectFileList(std::string_view current_dir); // Parse all the files in the project. void ParseProjectFiles(); diff --git a/verible/verilog/tools/ls/symbol-table-handler_test.cc b/verible/verilog/tools/ls/symbol-table-handler_test.cc index 8591684e6..19b636fe2 100644 --- a/verible/verilog/tools/ls/symbol-table-handler_test.cc +++ b/verible/verilog/tools/ls/symbol-table-handler_test.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/lsp/lsp-file-utils.h" #include "verible/common/lsp/lsp-protocol.h" @@ -32,7 +32,7 @@ namespace verilog { namespace { -static constexpr absl::string_view // +static constexpr std::string_view // kSampleModuleA( R"(module a; assign var1 = 1'b0; @@ -40,7 +40,7 @@ static constexpr absl::string_view // endmodule )"); -static constexpr absl::string_view // +static constexpr std::string_view // kSampleModuleB( R"(module b; assign var1 = 1'b0; @@ -106,7 +106,7 @@ TEST(SymbolTableHandlerTest, LoadFileList) { verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content = + std::string_view filelist_content = "a.sv\n" "b.sv\n"; @@ -134,7 +134,7 @@ TEST(SymbolTableHandlerTest, FileListWithNonExistingFile) { verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content = + std::string_view filelist_content = "a.sv\n" "b.sv\n"; @@ -182,7 +182,7 @@ TEST(SymbolTableHandlerTest, DefinitionNotTrackedFile) { verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content = + std::string_view filelist_content = "a.sv\n" "b.sv\n"; @@ -225,7 +225,7 @@ TEST(SymbolTableHandlerTest, verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content = "b.sv\n"; + std::string_view filelist_content = "b.sv\n"; const verible::file::testing::ScopedTestFile filelist( sources_dir, filelist_content, "verible.filelist"); @@ -274,7 +274,7 @@ TEST(SymbolTableHandlerTest, verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content = "b.sv\n"; + std::string_view filelist_content = "b.sv\n"; const verible::file::testing::ScopedTestFile filelist( sources_dir, filelist_content, "verible.filelist"); @@ -321,7 +321,7 @@ TEST(SymbolTableHandlerTest, FindRenamableRangeAtCursorReturnsLocation) { verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content = + std::string_view filelist_content = "a.sv\n" "b.sv\n"; @@ -371,7 +371,7 @@ TEST(SymbolTableHandlerTest, verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content = + std::string_view filelist_content = "a.sv\n" "b.sv\n"; @@ -423,7 +423,7 @@ TEST(SymbolTableHandlerTest, verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content = + std::string_view filelist_content = "a.sv\n" "b.sv\n"; @@ -484,7 +484,7 @@ TEST(SymbolTableHandlerTest, UpdateWithUnparseableEditorContentRegression) { verible::file::JoinPath(tempdir, __FUNCTION__); ASSERT_TRUE(verible::file::CreateDir(sources_dir).ok()); - absl::string_view filelist_content; + std::string_view filelist_content; const verible::file::testing::ScopedTestFile filelist( sources_dir, filelist_content, "verible.filelist"); const std::string uri = verible::lsp::PathToLSPUri(sources_dir + "/a.sv"); diff --git a/verible/verilog/tools/ls/verible-lsp-adapter.cc b/verible/verilog/tools/ls/verible-lsp-adapter.cc index ceeb6ebaa..84c27d18e 100644 --- a/verible/verilog/tools/ls/verible-lsp-adapter.cc +++ b/verible/verilog/tools/ls/verible-lsp-adapter.cc @@ -17,10 +17,10 @@ #include #include +#include #include #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" #include "verible/common/analysis/file-analyzer.h" #include "verible/common/analysis/lint-rule-status.h" @@ -99,7 +99,7 @@ std::vector CreateDiagnostics( [&result, &rejected_token]( const std::string &filename, verible::LineColumnRange range, verible::ErrorSeverity severity, verible::AnalysisPhase phase, - absl::string_view token_text, absl::string_view context_line, + std::string_view token_text, std::string_view context_line, const std::string &msg) { std::string message(AnalysisPhaseName(phase)); absl::StrAppend(&message, " ", ErrorSeverityDescription(severity)); @@ -146,7 +146,7 @@ static std::vector AutofixToTextEdits( std::vector result; // TODO(hzeller): figure out if edits are stacking or are all based // on the same start status. - const absl::string_view base = text.Contents(); + const std::string_view base = text.Contents(); for (const verible::ReplacementEdit &edit : fix.Edits()) { verible::LineColumn start = text.GetLineColAtOffset(edit.fragment.begin() - base.begin()); diff --git a/verible/verilog/tools/ls/verible-verilog-ls.cc b/verible/verilog/tools/ls/verible-verilog-ls.cc index 53c893535..76242e38c 100644 --- a/verible/verilog/tools/ls/verible-verilog-ls.cc +++ b/verible/verilog/tools/ls/verible-verilog-ls.cc @@ -14,9 +14,9 @@ // #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/util/init-command-line.h" #include "verible/verilog/tools/ls/verilog-language-server.h" @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) { // -- Input and output is stdin and stdout. // Output: provided write-function is called with entire response messages. - verilog::VerilogLanguageServer server([](absl::string_view reply) { + verilog::VerilogLanguageServer server([](std::string_view reply) { // Output formatting as header/body chunk as required by LSP spec to stdout. std::cout << "Content-Length: " << reply.size() << "\r\n\r\n"; std::cout << reply << std::flush; diff --git a/verible/verilog/tools/ls/verilog-language-server.cc b/verible/verilog/tools/ls/verilog-language-server.cc index df4fc2a05..8bec1859e 100644 --- a/verible/verilog/tools/ls/verilog-language-server.cc +++ b/verible/verilog/tools/ls/verilog-language-server.cc @@ -20,11 +20,11 @@ #include #include #include +#include #include #include "absl/flags/flag.h" #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" #include "verible/common/lsp/lsp-file-utils.h" #include "verible/common/lsp/lsp-protocol.h" @@ -46,7 +46,7 @@ VerilogLanguageServer::VerilogLanguageServer(const WriteFun &write_fun) : dispatcher_(write_fun), text_buffers_(&dispatcher_) { // All bodies the stream splitter extracts are pushed to the json dispatcher stream_splitter_.SetMessageProcessor( - [this](absl::string_view header, absl::string_view body) { + [this](std::string_view header, std::string_view body) { dispatcher_.DispatchMessage(body); }); @@ -236,7 +236,7 @@ verible::lsp::InitializeResult VerilogLanguageServer::InitializeRequestHandler( return GetCapabilities(); } -void VerilogLanguageServer::ConfigureProject(absl::string_view project_root) { +void VerilogLanguageServer::ConfigureProject(std::string_view project_root) { LOG(INFO) << "Initializing with project-root '" << project_root << "'"; std::string proj_root = {project_root.begin(), project_root.end()}; if (proj_root.empty()) { diff --git a/verible/verilog/tools/ls/verilog-language-server.h b/verible/verilog/tools/ls/verilog-language-server.h index 31aed2236..1e912b526 100644 --- a/verible/verilog/tools/ls/verilog-language-server.h +++ b/verible/verilog/tools/ls/verilog-language-server.h @@ -16,9 +16,9 @@ #define VERILOG_TOOLS_LS_LS_WRAPPER_H #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/lsp/json-rpc-dispatcher.h" #include "verible/common/lsp/lsp-protocol.h" #include "verible/common/lsp/lsp-text-buffer.h" @@ -68,7 +68,7 @@ class VerilogLanguageServer { // updating VerilogProject views for edited files // if "project_root" is an empty string, set to either current directory // or directory containing verible.filelist - void ConfigureProject(absl::string_view project_root); + void ConfigureProject(std::string_view project_root); // Publish a diagnostic sent to the server. void SendDiagnostics(const std::string &uri, diff --git a/verible/verilog/tools/ls/verilog-language-server_test.cc b/verible/verilog/tools/ls/verilog-language-server_test.cc index 4652c8af3..ed53bde5d 100644 --- a/verible/verilog/tools/ls/verilog-language-server_test.cc +++ b/verible/verilog/tools/ls/verilog-language-server_test.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "absl/flags/flag.h" @@ -26,7 +27,6 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "nlohmann/json.hpp" #include "verible/common/lsp/lsp-file-utils.h" @@ -52,14 +52,14 @@ using nlohmann::json; using verible::lsp::PathToLSPUri; // TODO (glatosinski) use better sample modules -static constexpr absl::string_view // +static constexpr std::string_view // kSampleModuleA( R"(module a; assign var1 = 1'b0; assign var2 = var1 | 1'b1; endmodule )"); -static constexpr absl::string_view // +static constexpr std::string_view // kSampleModuleB( R"(module b; assign var1 = 1'b0; @@ -75,7 +75,7 @@ class VerilogLanguageServerTest : public ::testing::Test { // It does not parse the response nor fetch it in any way (for other // tests to check e.g. server/client capabilities). virtual absl::Status InitializeCommunication() { - const absl::string_view initialize = + const std::string_view initialize = R"({ "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": null })"; SetRequest(initialize); @@ -85,7 +85,7 @@ class VerilogLanguageServerTest : public ::testing::Test { // Runs SetRequest and ServerStep, returning the status from the // Language Server // TODO: accept nlohmann::json object directly ? - absl::Status SendRequest(absl::string_view request) { + absl::Status SendRequest(std::string_view request) { SetRequest(request); return ServerStep(); } @@ -106,7 +106,7 @@ class VerilogLanguageServerTest : public ::testing::Test { protected: // Wraps request for the Language Server in RPC header - void SetRequest(absl::string_view request) { + void SetRequest(std::string_view request) { request_stream_.clear(); request_stream_.str( absl::StrCat("Content-Length: ", request.size(), "\r\n\r\n", request)); @@ -125,7 +125,7 @@ class VerilogLanguageServerTest : public ::testing::Test { // It stores the response in initialize_response field for further processing void SetUp() override { // not yet final server_ = std::make_unique( - [this](absl::string_view response) { response_stream_ << response; }); + [this](std::string_view response) { response_stream_ << response; }); absl::Status status = InitializeCommunication(); EXPECT_TRUE(status.ok()) << "Failed to read request: " << status; @@ -185,8 +185,8 @@ TEST_F(VerilogLanguageServerTest, InitializeRequest) { << "Invalid Language Server name"; } -static std::string DidOpenRequest(absl::string_view name, - absl::string_view content) { +static std::string DidOpenRequest(std::string_view name, + std::string_view content) { return nlohmann::json{// {"jsonrpc", "2.0"}, {"method", "textDocument/didOpen"}, @@ -216,7 +216,7 @@ TEST_F(VerilogLanguageServerTest, SyntaxError) { << "No syntax error found"; // query diagnostics explicitly - const absl::string_view diagnostic_request = R"( + const std::string_view diagnostic_request = R"( { "jsonrpc": "2.0", "id": 2, "method": "textDocument/diagnostic", "params": @@ -260,7 +260,7 @@ TEST_F(VerilogLanguageServerTest, LintErrorDetection) { 9); // Secondly, request a code action at the EOF error message position - const absl::string_view action_request = + const std::string_view action_request = R"({"jsonrpc":"2.0", "id":10, "method":"textDocument/codeAction","params":{"textDocument":{"uri":"file://mini.sv"},"range":{"start":{"line":1,"character":9},"end":{"line":1,"character":9}}}})"; ASSERT_OK(SendRequest(action_request)); @@ -270,7 +270,7 @@ TEST_F(VerilogLanguageServerTest, LintErrorDetection) { action["result"][0]["edit"]["changes"]["file://mini.sv"][0]["newText"], "\n"); // Thirdly, apply change suggested by a code action and check diagnostics - const absl::string_view apply_fix = + const std::string_view apply_fix = R"({"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file://mini.sv"},"contentChanges":[{"range":{"start":{"character":9,"line":1},"end":{"character":9,"line":1}},"text":"\n"}]}})"; ASSERT_OK(SendRequest(apply_fix)); @@ -314,7 +314,7 @@ endmodule << "textDocument/publishDiagnostics not received"; // Request a document symbol - const absl::string_view document_symbol_request = + const std::string_view document_symbol_request = R"({"jsonrpc":"2.0", "id":11, "method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file://mini_pkg.sv"}}})"; ASSERT_OK(SendRequest(document_symbol_request)); @@ -398,7 +398,7 @@ endmodule << "textDocument/publishDiagnostics not received"; // Request a document symbol - const absl::string_view document_symbol_request = + const std::string_view document_symbol_request = R"({"jsonrpc":"2.0", "id":11, "method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file://mini_pkg.sv"}}})"; ASSERT_OK(SendRequest(document_symbol_request)); @@ -450,7 +450,7 @@ TEST_F(VerilogLanguageServerTest, GetResponse(); // ignore response. // Close the file from the Language Server perspective - const absl::string_view closing_request = R"( + const std::string_view closing_request = R"( { "jsonrpc":"2.0", "method":"textDocument/didClose", @@ -464,7 +464,7 @@ TEST_F(VerilogLanguageServerTest, // Try to request document symbol for closed file (server should return empty // response gracefully) - const absl::string_view document_symbol_request = + const std::string_view document_symbol_request = R"({"jsonrpc":"2.0", "id":13, "method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file://mini.sv"}}})"; ASSERT_OK(SendRequest(document_symbol_request)); @@ -487,7 +487,7 @@ TEST_F(VerilogLanguageServerTest, SymbolHighlightingTest) { << "Diagnostics for invalid file"; EXPECT_EQ(diagnostics["params"]["diagnostics"].size(), 0) << "The test file has errors"; - const absl::string_view highlight_request1 = + const std::string_view highlight_request1 = R"({"jsonrpc":"2.0", "id":20, "method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file://sym.sv"},"position":{"line":1,"character":7}}})"; ASSERT_OK(SendRequest(highlight_request1)); @@ -503,7 +503,7 @@ TEST_F(VerilogLanguageServerTest, SymbolHighlightingTest) { json::parse( R"({"range":{"start":{"line":1, "character": 20}, "end":{"line":1, "character": 21}}})")); - const absl::string_view highlight_request2 = + const std::string_view highlight_request2 = R"({"jsonrpc":"2.0", "id":21, "method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file://sym.sv"},"position":{"line":1,"character":2}}})"; ASSERT_OK(SendRequest(highlight_request2)); @@ -516,7 +516,7 @@ TEST_F(VerilogLanguageServerTest, SymbolHighlightingTest) { struct FormattingRequestParams { FormattingRequestParams(int id, int start_line, int start_character, int end_line, int end_character, - absl::string_view new_text, int new_text_start_line, + std::string_view new_text, int new_text_start_line, int new_text_start_character, int new_text_end_line, int new_text_end_character) : id(id), @@ -536,7 +536,7 @@ struct FormattingRequestParams { int end_line; int end_character; - absl::string_view new_text; + std::string_view new_text; int new_text_start_line; int new_text_start_character; int new_text_end_line; @@ -545,7 +545,7 @@ struct FormattingRequestParams { // Creates a textDocument/rangeFormatting request from FormattingRequestParams // structure -std::string FormattingRequest(absl::string_view file, +std::string FormattingRequest(std::string_view file, const FormattingRequestParams ¶ms) { json formattingrequest = { {"jsonrpc", "2.0"}, @@ -627,7 +627,7 @@ TEST_F(VerilogLanguageServerTest, FormattingTest) { EXPECT_EQ(diagnostics["params"]["diagnostics"].size(), 0) << "The test file has errors"; - const absl::string_view formatting_request = + const std::string_view formatting_request = R"({"jsonrpc":"2.0", "id":34, "method":"textDocument/formatting","params":{"textDocument":{"uri":"file://fmt.sv"}}})"; ASSERT_OK(SendRequest(formatting_request)); @@ -651,7 +651,7 @@ TEST_F(VerilogLanguageServerTest, FormattingFileWithEmptyNewline_issue1667) { GetResponse(); // Ignore diagnostics. - const absl::string_view formatting_request = R"( + const std::string_view formatting_request = R"( {"jsonrpc":"2.0", "id":1, "method": "textDocument/formatting", "params": {"textDocument":{"uri":"file://fmt.sv"}}})"; @@ -679,7 +679,7 @@ TEST_F(VerilogLanguageServerTest, FormattingFileWithSyntaxErrors_issue1843) { GetResponse(); // Ignore diagnostics. - const absl::string_view formatting_request = R"( + const std::string_view formatting_request = R"( {"jsonrpc":"2.0", "id":1, "method": "textDocument/formatting", "params": {"textDocument":{"uri":"file://fmt.sv"}}})"; @@ -690,8 +690,8 @@ TEST_F(VerilogLanguageServerTest, FormattingFileWithSyntaxErrors_issue1843) { } // Creates a request based on TextDocumentPosition parameters -std::string TextDocumentPositionBasedRequest(absl::string_view method, - absl::string_view file, int id, +std::string TextDocumentPositionBasedRequest(std::string_view method, + std::string_view file, int id, int line, int character) { verible::lsp::TextDocumentPositionParams params{ .textDocument = {.uri = {file.begin(), file.end()}}, @@ -702,14 +702,14 @@ std::string TextDocumentPositionBasedRequest(absl::string_view method, } // Creates a textDocument/definition request -std::string DefinitionRequest(absl::string_view file, int id, int line, +std::string DefinitionRequest(std::string_view file, int id, int line, int character) { return TextDocumentPositionBasedRequest("textDocument/definition", file, id, line, character); } // Creates a textDocument/references request -std::string ReferencesRequest(absl::string_view file, int id, int line, +std::string ReferencesRequest(std::string_view file, int id, int line, int character) { return TextDocumentPositionBasedRequest("textDocument/references", file, id, line, character); @@ -737,7 +737,7 @@ void CheckDefinitionResponseSingleDefinition(const json &response, int id, } // Creates a textDocument/hover request -std::string HoverRequest(absl::string_view file, int id, int line, +std::string HoverRequest(std::string_view file, int id, int line, int character) { return TextDocumentPositionBasedRequest("textDocument/hover", file, id, line, character); @@ -747,8 +747,8 @@ std::string HoverRequest(absl::string_view file, int id, int line, // In this test the hover for "sum" symbol in assign // is checked TEST_F(VerilogLanguageServerSymbolTableTest, HoverOverSymbol) { - absl::string_view filelist_content = "mod.v\n"; - static constexpr absl::string_view // + std::string_view filelist_content = "mod.v\n"; + static constexpr std::string_view // module_content( R"(module mod( input clk, @@ -786,8 +786,8 @@ endmodule // Checks if the hover appears on "end" token when block name is available TEST_F(VerilogLanguageServerSymbolTableTest, HoverOverEnd) { - absl::string_view filelist_content = "mod.v\n"; - static constexpr absl::string_view // + std::string_view filelist_content = "mod.v\n"; + static constexpr std::string_view // module_content( R"(module mod( input clk, @@ -835,7 +835,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestNoProjectTest) { // Performs simple textDocument/definition request TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestTest) { - absl::string_view filelist_content = "a.sv\n"; + std::string_view filelist_content = "a.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -866,7 +866,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestTest) { // name (variable name), but in different modules TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestSameVariablesDifferentModules) { - absl::string_view filelist_content = "a.sv\nb.sv\n"; + std::string_view filelist_content = "a.sv\nb.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -913,7 +913,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, // inside other module edited in buffer TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestSymbolFromDifferentOpenedModule) { - absl::string_view filelist_content = "a.sv\nb.sv\n"; + std::string_view filelist_content = "a.sv\nb.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -950,7 +950,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, // inside other module that is not edited in buffer TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestSymbolFromDifferentNotOpenedModule) { - absl::string_view filelist_content = "a.sv\nb.sv\n"; + std::string_view filelist_content = "a.sv\nb.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -984,7 +984,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, // inside other module which was opened and closed TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestSymbolFromDifferentOpenedAndClosedModule) { - absl::string_view filelist_content = "a.sv\nb.sv\n"; + std::string_view filelist_content = "a.sv\nb.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1041,9 +1041,9 @@ TEST_F(VerilogLanguageServerSymbolTableTest, // when there are incorrect files in the project TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestInvalidFileInWorkspace) { - absl::string_view filelist_content = "a.sv\nb.sv\n"; + std::string_view filelist_content = "a.sv\nb.sv\n"; - static constexpr absl::string_view // + static constexpr std::string_view // sample_module_b_with_error( R"(module b; assign var1 = 1'b0; @@ -1083,9 +1083,9 @@ endmodule // Check textDocument/definition request where we want definition of a symbol // inside incorrect file TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestInInvalidFile) { - absl::string_view filelist_content = "a.sv\nb.sv\n"; + std::string_view filelist_content = "a.sv\nb.sv\n"; - static constexpr absl::string_view // + static constexpr std::string_view // sample_module_b_with_error( R"(module b; assign var1 = 1'b0; @@ -1126,7 +1126,7 @@ endmodule // Check textDocument/definition request when URI is not supported TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestUnsupportedURI) { - absl::string_view filelist_content = "a.sv"; + std::string_view filelist_content = "a.sv"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1155,7 +1155,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestUnsupportedURI) { // Check textDocument/definition when the cursor points at definition TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestCursorAtDefinition) { - absl::string_view filelist_content = "a.sv"; + std::string_view filelist_content = "a.sv"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1185,7 +1185,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, // Check textDocument/definition when the cursor points at nothing TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestCursorAtNoSymbol) { - absl::string_view filelist_content = "a.sv"; + std::string_view filelist_content = "a.sv"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1214,7 +1214,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, // Check textDocument/definition when the cursor points at nothing TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestCursorAtUnknownSymbol) { - absl::string_view filelist_content = "b.sv"; + std::string_view filelist_content = "b.sv"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1300,20 +1300,20 @@ TEST_F(VerilogLanguageServerSymbolTableTest, } TEST_F(VerilogLanguageServerSymbolTableTest, MultipleDefinitionsOfSameSymbol) { - static constexpr absl::string_view filelist_content = + static constexpr std::string_view filelist_content = "bar_1.sv\nbar_2.sv\nfoo.sv"; - static constexpr absl::string_view // + static constexpr std::string_view // bar_1( R"(module bar(); endmodule )"); - static constexpr absl::string_view // + static constexpr std::string_view // bar_2( R"(module bar(); endmodule )"); - static constexpr absl::string_view // + static constexpr std::string_view // foo( R"(module foo(); bar x; @@ -1350,14 +1350,14 @@ endmodule } // Sample of badly styled module -constexpr static absl::string_view badly_styled_module = +constexpr static std::string_view badly_styled_module = "module my_module(input logic in, output logic out);\n\tassign out = in; " "\nendmodule"; // Checks if a given substring (lint rule type) is present // in linter diagnostics. bool CheckDiagnosticsContainLinterIssue(const json &diagnostics, - absl::string_view lint_issue_type) { + std::string_view lint_issue_type) { for (const auto &d : diagnostics) { if (absl::StrContains(d["message"].get(), lint_issue_type)) { return true; @@ -1394,7 +1394,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, DefaultConfigurationTest) { // Checks the work of linter in language server when // configuration file with "-no-tabs" file is present TEST_F(VerilogLanguageServerSymbolTableTest, ParsingLinterNoTabs) { - constexpr absl::string_view lint_config = "-no-tabs"; + constexpr std::string_view lint_config = "-no-tabs"; const verible::file::testing::ScopedTestFile module_mod( root_dir, badly_styled_module, "my_mod.sv"); const verible::file::testing::ScopedTestFile lint_file(root_dir, lint_config, @@ -1423,7 +1423,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, ParsingLinterNoTabs) { // rules TEST_F(VerilogLanguageServerSymbolTableTest, ParsingLinterNoTabsIgnoreModuleName) { - constexpr absl::string_view lint_config = + constexpr std::string_view lint_config = "-module-filename\n-posix-eof\n-no-tabs"; const verible::file::testing::ScopedTestFile module_mod( root_dir, badly_styled_module, "my_mod.sv"); @@ -1473,7 +1473,7 @@ json ReferenceEntry(verible::LineColumn start, verible::LineColumn end, // name (variable name) in two modules TEST_F(VerilogLanguageServerSymbolTableTest, ReferencesRequestSameVariablesDifferentModules) { - absl::string_view filelist_content = "a.sv\nb.sv\n"; + std::string_view filelist_content = "a.sv\nb.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1552,7 +1552,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, // Check textDocument/references behavior when pointing to an invalid space TEST_F(VerilogLanguageServerSymbolTableTest, CheckReferenceInvalidLocation) { - absl::string_view filelist_content = "a.sv\n"; + std::string_view filelist_content = "a.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1580,7 +1580,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, CheckReferenceInvalidLocation) { // Check textDocument/references behavior when pointing to a keyword TEST_F(VerilogLanguageServerSymbolTableTest, CheckReferenceKeyword) { - absl::string_view filelist_content = "a.sv\n"; + std::string_view filelist_content = "a.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1608,7 +1608,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, CheckReferenceKeyword) { // Check textDocument/references behavior when pointing to an unknown symbol TEST_F(VerilogLanguageServerSymbolTableTest, CheckReferenceUnknownSymbol) { - absl::string_view filelist_content = "b.sv\n"; + std::string_view filelist_content = "b.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -1636,7 +1636,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, CheckReferenceUnknownSymbol) { // Checks the definition request for module type in different module TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestModule) { - static constexpr absl::string_view // + static constexpr std::string_view // instmodule( R"(module InstModule ( o, @@ -1684,7 +1684,7 @@ endmodule // Checks the go-to definition when pointing to the definition of the symbol TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestSelf) { - static constexpr absl::string_view // + static constexpr std::string_view // instmodule( R"(module InstModule ( o, @@ -1734,7 +1734,7 @@ endmodule // This check verifies ports with types defined inside port list TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestPortTypesInsideList) { - static constexpr absl::string_view // + static constexpr std::string_view // instmodule( R"(module InstModule ( output logic [31:0] o, @@ -1768,7 +1768,7 @@ endmodule // This check verifies ports with types defined outside port list TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestPortTypesOutsideList) { - static constexpr absl::string_view // + static constexpr std::string_view // instmodule( R"(module InstModule ( o, @@ -1808,7 +1808,7 @@ endmodule // * simple port TEST_F(VerilogLanguageServerSymbolTableTest, DefinitionRequestPortPortIdentifierVariant) { - static constexpr absl::string_view // + static constexpr std::string_view // port_identifier( R"(module port_identifier(a, rst, clk, out); input logic [15:0] a; @@ -1882,7 +1882,7 @@ endmodule)"); // definition of the symbol is split into multiple lines, // e.g. for port module declarations. TEST_F(VerilogLanguageServerSymbolTableTest, MultilinePortDefinitions) { - static constexpr absl::string_view // + static constexpr std::string_view // port_identifier( R"(module port_identifier(i, o, trigger); input trigger; @@ -1932,7 +1932,7 @@ endmodule // Verifies the work of the go-to definition request when // definition of the symbol later in the definition list is requested TEST_F(VerilogLanguageServerSymbolTableTest, MultilinePortDefinitionsWithList) { - static constexpr absl::string_view // + static constexpr std::string_view // port_identifier( R"(module port_identifier(a, b, o, trigger); input trigger; @@ -1998,7 +1998,7 @@ std::string PrepareRenameRequest( TEST_F(VerilogLanguageServerSymbolTableTest, PrepareRenameReturnsRangeOfEditableSymbol) { // Create sample file and make sure diagnostics do not have errors - std::string file_uri = PathToLSPUri(absl::string_view(root_dir + "/fmt.sv")); + std::string file_uri = PathToLSPUri(std::string_view(root_dir + "/fmt.sv")); verible::lsp::PrepareRenameParams params; params.position.line = 2; params.position.character = 1; @@ -2032,7 +2032,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, TEST_F(VerilogLanguageServerSymbolTableTest, PrepareRenameReturnsNull) { // Create sample file and make sure diagnostics do not have errors - std::string file_uri = PathToLSPUri(absl::string_view(root_dir + "/fmt.sv")); + std::string file_uri = PathToLSPUri(std::string_view(root_dir + "/fmt.sv")); verible::lsp::PrepareRenameParams params; params.position.line = 1; params.position.character = 1; @@ -2061,14 +2061,14 @@ TEST_F(VerilogLanguageServerSymbolTableTest, PrepareRenameReturnsNull) { TEST_F(VerilogLanguageServerSymbolTableTest, RenameTestSymbolSingleFile) { // Create sample file and make sure diagnostics do not have errors std::string file_uri = - PathToLSPUri(absl::string_view(root_dir + "/rename.sv")); + PathToLSPUri(std::string_view(root_dir + "/rename.sv")); verible::lsp::RenameParams params; params.position.line = 2; params.position.character = 1; params.textDocument.uri = file_uri; params.newName = "foo"; - absl::string_view filelist_content = "rename.sv\n"; + std::string_view filelist_content = "rename.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -2106,8 +2106,8 @@ TEST_F(VerilogLanguageServerSymbolTableTest, RenameTestSymbolSingleFile) { TEST_F(VerilogLanguageServerSymbolTableTest, RenameTestSymbolMultipleFiles) { // Create sample file and make sure diagnostics do not have errors - std::string top_uri = PathToLSPUri(absl::string_view(root_dir + "/top.sv")); - std::string foo_uri = PathToLSPUri(absl::string_view(root_dir + "/foo.sv")); + std::string top_uri = PathToLSPUri(std::string_view(root_dir + "/top.sv")); + std::string foo_uri = PathToLSPUri(std::string_view(root_dir + "/foo.sv")); verible::lsp::RenameParams params; params.position.line = 2; params.position.character = 9; @@ -2123,7 +2123,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, RenameTestSymbolMultipleFiles) { "module top;\n" " foo::foobar bar;\n" "endmodule;\n"; - absl::string_view filelist_content = "./foo.sv\n./top.sv\n"; + std::string_view filelist_content = "./foo.sv\n./top.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -2170,7 +2170,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, RenameTestSymbolMultipleFiles) { TEST_F(VerilogLanguageServerSymbolTableTest, RenameTestPackageDistinction) { // Create sample file and make sure diagnostics do not have errors std::string file_uri = - PathToLSPUri(absl::string_view(root_dir + "/rename.sv")); + PathToLSPUri(std::string_view(root_dir + "/rename.sv")); verible::lsp::RenameParams params; params.position.line = 7; params.position.character = 15; @@ -2187,7 +2187,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, RenameTestPackageDistinction) { " foo::foobar baz;\n" " endclass;\n" "endpackage;\n"; - absl::string_view filelist_content = "rename.sv\n"; + std::string_view filelist_content = "rename.sv\n"; const verible::file::testing::ScopedTestFile filelist( root_dir, filelist_content, "verible.filelist"); @@ -2219,7 +2219,7 @@ TEST_F(VerilogLanguageServerSymbolTableTest, RenameTestPackageDistinction) { // Tests correctness of Language Server shutdown request TEST_F(VerilogLanguageServerTest, ShutdownTest) { - const absl::string_view shutdown_request = + const std::string_view shutdown_request = R"({"jsonrpc":"2.0", "id":100, "method":"shutdown","params":{}})"; ASSERT_OK(SendRequest(shutdown_request)); diff --git a/verible/verilog/tools/obfuscator/BUILD b/verible/verilog/tools/obfuscator/BUILD index 63f5f786e..e3a2d219d 100644 --- a/verible/verilog/tools/obfuscator/BUILD +++ b/verible/verilog/tools/obfuscator/BUILD @@ -26,7 +26,6 @@ cc_binary( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/verilog/tools/obfuscator/verilog-obfuscate.cc b/verible/verilog/tools/obfuscator/verilog-obfuscate.cc index 4f7472c65..612a5541f 100644 --- a/verible/verilog/tools/obfuscator/verilog-obfuscate.cc +++ b/verible/verilog/tools/obfuscator/verilog-obfuscate.cc @@ -30,11 +30,12 @@ #include #endif +#include + #include "absl/flags/flag.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/obfuscator.h" #include "verible/common/util/file-util.h" #include "verible/common/util/init-command-line.h" @@ -68,7 +69,7 @@ ABSL_FLAG( // bool, preserve_builtin_functions, true, // "If true, preserve built-in function names such as sin(), ceil().."); -static constexpr absl::string_view kBuiltinFunctions[] = { +static constexpr std::string_view kBuiltinFunctions[] = { "abs", "acos", "acosh", "asin", "asinh", "atan", "atan2", "atanh", "ceil", "cos", "cosh", "exp", "floor", "hypot", "ln", "log", "pow", "sin", "sinh", "sqrt", "tan", "tanh", @@ -142,7 +143,7 @@ Output is written to stdout. } if (absl::GetFlag(FLAGS_preserve_builtin_functions)) { - for (const absl::string_view f : kBuiltinFunctions) { + for (const std::string_view f : kBuiltinFunctions) { subst.encode(f, f); } } diff --git a/verible/verilog/tools/preprocessor/BUILD b/verible/verilog/tools/preprocessor/BUILD index 7a33365e7..ddf509c2b 100644 --- a/verible/verilog/tools/preprocessor/BUILD +++ b/verible/verilog/tools/preprocessor/BUILD @@ -32,7 +32,6 @@ cc_binary( "@abseil-cpp//absl/status", "@abseil-cpp//absl/status:statusor", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/verilog/tools/preprocessor/verilog-preprocessor.cc b/verible/verilog/tools/preprocessor/verilog-preprocessor.cc index c6bc67449..c23fdf7ff 100644 --- a/verible/verilog/tools/preprocessor/verilog-preprocessor.cc +++ b/verible/verilog/tools/preprocessor/verilog-preprocessor.cc @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -22,7 +23,6 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/text/token-stream-view.h" #include "verible/common/util/file-util.h" #include "verible/common/util/init-command-line.h" @@ -46,7 +46,7 @@ static absl::Status StripComments(const SubcommandArgsRange &args, std::istream &, std::ostream &outs, std::ostream &) { // Parse the arguments into a FileList. - std::vector cmdline_args(args.begin(), args.end()); + std::vector cmdline_args(args.begin(), args.end()); verilog::FileList file_list; RETURN_IF_ERROR( verilog::AppendFileListFromCommandline(cmdline_args, &file_list)); @@ -56,7 +56,7 @@ static absl::Status StripComments(const SubcommandArgsRange &args, return absl::InvalidArgumentError( "Missing file argument. Use '-' for stdin."); } - const absl::string_view source_file = files[0]; + const std::string_view source_file = files[0]; absl::StatusOr source_contents_or = verible::file::GetContentAsString(source_file); if (!source_contents_or.ok()) { @@ -66,7 +66,7 @@ static absl::Status StripComments(const SubcommandArgsRange &args, if (args.size() == 1) { replace_char = ' '; } else if (args.size() == 2) { - absl::string_view replace_str(args[1]); + std::string_view replace_str(args[1]); if (replace_str.empty()) { replace_char = '\0'; } else if (replace_str.length() == 1) { @@ -85,7 +85,7 @@ static absl::Status StripComments(const SubcommandArgsRange &args, } static absl::Status PreprocessSingleFile( - absl::string_view source_file, + std::string_view source_file, const verilog::FileList::PreprocessingInfo &preprocessing_info, std::ostream &outs, std::ostream &message_stream) { absl::StatusOr source_contents_or = @@ -103,7 +103,7 @@ static absl::Status PreprocessSingleFile( FileOpener file_opener = [&project]( - absl::string_view filename) -> absl::StatusOr { + std::string_view filename) -> absl::StatusOr { auto result = project.OpenIncludedFile(filename); if (!result.status().ok()) return result.status(); return (*result)->GetContent(); @@ -140,7 +140,7 @@ static absl::Status MultipleCU(const SubcommandArgsRange &args, std::istream &, std::ostream &outs, std::ostream &message_stream) { // Parse the arguments into a FileList. - std::vector cmdline_args(args.begin(), args.end()); + std::vector cmdline_args(args.begin(), args.end()); verilog::FileList file_list; RETURN_IF_ERROR( verilog::AppendFileListFromCommandline(cmdline_args, &file_list)); @@ -154,7 +154,7 @@ static absl::Status MultipleCU(const SubcommandArgsRange &args, std::istream &, if (files.empty()) { return absl::InvalidArgumentError("ERROR: Missing file argument."); } - for (const absl::string_view source_file : files) { + for (const std::string_view source_file : files) { RETURN_IF_ERROR(PreprocessSingleFile(source_file, preprocessing_info, outs, message_stream)); } @@ -165,7 +165,7 @@ static absl::Status GenerateVariants(const SubcommandArgsRange &args, std::istream &, std::ostream &outs, std::ostream &message_stream) { // Parse the arguments into a FileList. - std::vector cmdline_args(args.begin(), args.end()); + std::vector cmdline_args(args.begin(), args.end()); verilog::FileList file_list; RETURN_IF_ERROR( verilog::AppendFileListFromCommandline(cmdline_args, &file_list)); @@ -220,7 +220,7 @@ static absl::Status GenerateVariants(const SubcommandArgsRange &args, }); } -static const std::pair kCommands[] = { +static const std::pair kCommands[] = { {"preprocess", {&MultipleCU, R"(preprocess [define-include-flags] file [file...] diff --git a/verible/verilog/tools/project/BUILD b/verible/verilog/tools/project/BUILD index 2e6ebc87a..386ebdd1a 100644 --- a/verible/verilog/tools/project/BUILD +++ b/verible/verilog/tools/project/BUILD @@ -28,7 +28,6 @@ cc_binary( "@abseil-cpp//absl/flags:usage", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) diff --git a/verible/verilog/tools/project/project-tool.cc b/verible/verilog/tools/project/project-tool.cc index 029146347..46d70f7aa 100644 --- a/verible/verilog/tools/project/project-tool.cc +++ b/verible/verilog/tools/project/project-tool.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -23,7 +24,6 @@ #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" #include "verible/common/util/init-command-line.h" #include "verible/common/util/logging.h" #include "verible/common/util/status-macros.h" @@ -67,7 +67,7 @@ struct VerilogProjectConfig { std::string file_list_root; absl::Status LoadFromCommandline(const SubcommandArgsRange &args) { - const std::vector cmdline{args.begin(), args.end()}; + const std::vector cmdline{args.begin(), args.end()}; auto status = AppendFileListFromCommandline(cmdline, &file_list); if (!status.ok()) return status; @@ -250,7 +250,7 @@ static absl::Status ShowFileDependencies(const SubcommandArgsRange &args, return absl::OkStatus(); } -static const std::pair kCommands[] = { +static const std::pair kCommands[] = { {"symbol-table-defs", // {&BuildAndShowSymbolTable, // R"(symbol-table-defs [project args] diff --git a/verible/verilog/tools/syntax/BUILD b/verible/verilog/tools/syntax/BUILD index ed70faea2..98557bc62 100644 --- a/verible/verilog/tools/syntax/BUILD +++ b/verible/verilog/tools/syntax/BUILD @@ -38,7 +38,6 @@ cc_binary( "@abseil-cpp//absl/flags:flag", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", "@nlohmann_json//:singleheader-json", ], ) diff --git a/verible/verilog/tools/syntax/verilog-syntax.cc b/verible/verilog/tools/syntax/verilog-syntax.cc index efa8acd74..004876fe0 100644 --- a/verible/verilog/tools/syntax/verilog-syntax.cc +++ b/verible/verilog/tools/syntax/verilog-syntax.cc @@ -25,13 +25,13 @@ #include #include // IWYU pragma: keep // for ostringstream #include // for string, allocator, etc +#include #include #include #include "absl/flags/flag.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "nlohmann/json.hpp" #include "verible/common/strings/mem-block.h" #include "verible/common/text/concrete-syntax-tree.h" @@ -77,7 +77,7 @@ static std::ostream &operator<<(std::ostream &stream, LanguageMode mode) { return LanguageModeStringMap().Unparse(mode, stream); } -static bool AbslParseFlag(absl::string_view text, LanguageMode *mode, +static bool AbslParseFlag(std::string_view text, LanguageMode *mode, std::string *error) { return LanguageModeStringMap().Parse(text, mode, error, "--flag value"); } @@ -122,7 +122,7 @@ using verilog::VerilogAnalyzer; static std::unique_ptr ParseWithLanguageMode( const std::shared_ptr &content, - absl::string_view filename, + std::string_view filename, const verilog::VerilogPreprocess::Config &preprocess_config) { switch (absl::GetFlag(FLAGS_lang)) { case LanguageMode::kAutoDetect: @@ -163,7 +163,7 @@ static void VerifyParseTree(const TextStructureView &text_structure) { static bool ShouldIncludeTokenText(const verible::TokenInfo &token) { const verilog_tokentype tokentype = static_cast(token.token_enum()); - absl::string_view type_str = verilog::TokenTypeToString(tokentype); + std::string_view type_str = verilog::TokenTypeToString(tokentype); // Don't include token's text for operators, keywords, or anything that is a // part of Verilog syntax. For such types, TokenTypeToString() is equal to // token's text. Exception has to be made for identifiers, because things like @@ -174,7 +174,7 @@ static bool ShouldIncludeTokenText(const verible::TokenInfo &token) { static int AnalyzeOneFile( const std::shared_ptr &content, - absl::string_view filename, + std::string_view filename, const verilog::VerilogPreprocess::Config &preprocess_config, json *json_out) { int exit_status = 0; @@ -293,7 +293,7 @@ int main(int argc, char **argv) { int exit_status = 0; // All positional arguments are file names. Exclude program name. - for (absl::string_view filename : + for (std::string_view filename : verible::make_range(args.begin() + 1, args.end())) { auto content_status = verible::file::GetContentAsMemBlock(filename); if (!content_status.status().ok()) { diff --git a/verible/verilog/transform/BUILD b/verible/verilog/transform/BUILD index 5633aa63c..2cf15a590 100644 --- a/verible/verilog/transform/BUILD +++ b/verible/verilog/transform/BUILD @@ -26,7 +26,6 @@ cc_library( "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -37,7 +36,6 @@ cc_test( ":obfuscate", "//verible/common/strings:obfuscator", "@abseil-cpp//absl/status", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -58,7 +56,6 @@ cc_library( "//verible/verilog/parser:verilog-parser", "//verible/verilog/parser:verilog-token-enum", "@abseil-cpp//absl/strings", - "@abseil-cpp//absl/strings:string_view", ], ) @@ -67,7 +64,6 @@ cc_test( srcs = ["strip-comments_test.cc"], deps = [ ":strip-comments", - "@abseil-cpp//absl/strings:string_view", "@googletest//:gtest", "@googletest//:gtest_main", ], diff --git a/verible/verilog/transform/obfuscate.cc b/verible/verilog/transform/obfuscate.cc index 100ce2f7c..0c70d5eb1 100644 --- a/verible/verilog/transform/obfuscate.cc +++ b/verible/verilog/transform/obfuscate.cc @@ -17,10 +17,10 @@ #include #include #include +#include #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/obfuscator.h" #include "verible/common/strings/random.h" #include "verible/common/text/token-info.h" @@ -34,7 +34,7 @@ namespace verilog { using verible::IdentifierObfuscator; -std::string RandomEqualLengthSymbolIdentifier(absl::string_view in) { +std::string RandomEqualLengthSymbolIdentifier(std::string_view in) { verilog::VerilogLexer lexer(""); // Oracle to check identifier-ness. // In rare case we accidentally generate a keyword, try again. for (;;) { @@ -50,7 +50,7 @@ std::string RandomEqualLengthSymbolIdentifier(absl::string_view in) { // TODO(fangism): single-char identifiers don't need to be obfuscated. // or use a shuffle/permutation to guarantee collision-free reversibility. -static void ObfuscateVerilogCodeInternal(absl::string_view content, +static void ObfuscateVerilogCodeInternal(std::string_view content, std::ostream *output, IdentifierObfuscator *subst) { VLOG(1) << __FUNCTION__; @@ -90,17 +90,17 @@ static void ObfuscateVerilogCodeInternal(absl::string_view content, VLOG(1) << "end of " << __FUNCTION__; } -static absl::Status ObfuscationError(absl::string_view message, - absl::string_view original, - absl::string_view encoded) { +static absl::Status ObfuscationError(std::string_view message, + std::string_view original, + std::string_view encoded) { return absl::InternalError(absl::StrCat(message, "\nORIGINAL:\n", original, "\nENCODED:\n", encoded, "\n*** Please file a bug. ***\n")); } -static absl::Status ReversibilityError(absl::string_view original, - absl::string_view encoded, - absl::string_view decoded) { +static absl::Status ReversibilityError(std::string_view original, + std::string_view encoded, + std::string_view decoded) { return absl::InternalError(absl::StrCat( "Internal error: decode(encode) != original\nORIGINAL:\n", original, "\nENCODED:\n", encoded, "\nDECODED:\n", decoded, @@ -109,8 +109,8 @@ static absl::Status ReversibilityError(absl::string_view original, } // Internal consistency check that decoding restores original text. -static absl::Status VerifyDecoding(absl::string_view original, - absl::string_view encoded, +static absl::Status VerifyDecoding(std::string_view original, + std::string_view encoded, const verible::Obfuscator &subst) { VLOG(1) << __FUNCTION__; // Skip if original transformation was already decoding. @@ -133,8 +133,8 @@ static absl::Status VerifyDecoding(absl::string_view original, } // Verify that obfuscated output is lexically equivalent to original. -static absl::Status VerifyEquivalence(absl::string_view original, - absl::string_view encoded) { +static absl::Status VerifyEquivalence(std::string_view original, + std::string_view encoded) { VLOG(1) << __FUNCTION__; std::ostringstream errstream; const auto diff_status = @@ -157,7 +157,7 @@ static absl::Status VerifyEquivalence(absl::string_view original, return absl::OkStatus(); } -absl::Status ObfuscateVerilogCode(absl::string_view content, +absl::Status ObfuscateVerilogCode(std::string_view content, std::ostream *output, IdentifierObfuscator *subst) { VLOG(1) << __FUNCTION__; diff --git a/verible/verilog/transform/obfuscate.h b/verible/verilog/transform/obfuscate.h index ab2f2c88f..53e3b19a4 100644 --- a/verible/verilog/transform/obfuscate.h +++ b/verible/verilog/transform/obfuscate.h @@ -17,16 +17,16 @@ #include #include +#include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/obfuscator.h" namespace verilog { // Returns an identifier ([alpha][alnum]*) of equal length to input, and // makes sure that it is a valid symbol identifier, not another Verilog keyword. -std::string RandomEqualLengthSymbolIdentifier(absl::string_view in); +std::string RandomEqualLengthSymbolIdentifier(std::string_view in); // Obfuscates Verilog code. Identifiers are randomized as equal length // replacements, and transformations are recorded (in subst) and re-applied @@ -34,7 +34,7 @@ std::string RandomEqualLengthSymbolIdentifier(absl::string_view in); // not necessary syntactically valid. Transformations apply to macro // arguments and macro definition bodies. // Returned status signals success or possible an internal error. -absl::Status ObfuscateVerilogCode(absl::string_view content, +absl::Status ObfuscateVerilogCode(std::string_view content, std::ostream *output, verible::IdentifierObfuscator *subst); diff --git a/verible/verilog/transform/obfuscate_test.cc b/verible/verilog/transform/obfuscate_test.cc index 1003e44fc..56d26abb9 100644 --- a/verible/verilog/transform/obfuscate_test.cc +++ b/verible/verilog/transform/obfuscate_test.cc @@ -16,10 +16,10 @@ #include #include +#include #include #include "absl/status/status.h" -#include "absl/strings/string_view.h" #include "gtest/gtest.h" #include "verible/common/strings/obfuscator.h" @@ -28,7 +28,7 @@ namespace { using verible::IdentifierObfuscator; -static std::string ExpectNeverToBeCalled(absl::string_view) { +static std::string ExpectNeverToBeCalled(std::string_view) { ADD_FAILURE() << "This identifier generator should've never been called"; return ""; } @@ -44,7 +44,7 @@ TEST(ObfuscateVerilogCodeTest, PreloadedSubstitutions) { for (const auto &sub : subs) { ASSERT_TRUE(ob.encode(sub.first, sub.second)); } - const std::pair kTestCases[] = { + const std::pair kTestCases[] = { {"", ""}, // empty file {"\n", "\n"}, {"//comments unchanged\n", "//comments unchanged\n"}, @@ -109,7 +109,7 @@ TEST(ObfuscateVerilogCodeTest, PreloadedSubstitutions) { } TEST(ObfuscateVerilogCodeTest, InputLexicalError) { - const absl::string_view kTestCases[] = { + const std::string_view kTestCases[] = { "789badid", "`FOO(8911badid)\n", "`define FOO 911badid\n", diff --git a/verible/verilog/transform/strip-comments.cc b/verible/verilog/transform/strip-comments.cc index 6244d7400..9cc9ef474 100644 --- a/verible/verilog/transform/strip-comments.cc +++ b/verible/verilog/transform/strip-comments.cc @@ -15,10 +15,10 @@ #include "verible/verilog/transform/strip-comments.h" #include +#include #include #include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" #include "verible/common/strings/comment-utils.h" #include "verible/common/strings/range.h" #include "verible/common/text/token-info.h" @@ -38,10 +38,10 @@ using verible::TokenInfo; // Replace non-newline characters with a single char, like . // Tabs are considered non-newline characters. -static void ReplaceNonNewlines(absl::string_view text, std::ostream *output, +static void ReplaceNonNewlines(std::string_view text, std::ostream *output, char replacement) { if (text.empty()) return; - const std::vector lines( + const std::vector lines( absl::StrSplit(text, absl::ByChar('\n'))); // no newline before first element *output << Spacer(lines.front().size(), replacement); @@ -50,7 +50,7 @@ static void ReplaceNonNewlines(absl::string_view text, std::ostream *output, } } -void StripVerilogComments(absl::string_view content, std::ostream *output, +void StripVerilogComments(std::string_view content, std::ostream *output, char replacement) { VLOG(1) << __FUNCTION__; verilog::VerilogLexer lexer(content); @@ -64,7 +64,7 @@ void StripVerilogComments(absl::string_view content, std::ostream *output, if (token.isEOF()) break; VLOG(2) << "token: " << verible::TokenWithContext{token, context}; - const absl::string_view text = token.text(); + const std::string_view text = token.text(); switch (token.token_enum()) { case verilog_tokentype::TK_EOL_COMMENT: switch (replacement) { @@ -78,8 +78,8 @@ void StripVerilogComments(absl::string_view content, std::ostream *output, break; default: { // Retain the "//" but erase everything thereafter. - const absl::string_view body(StripComment(text)); - const absl::string_view head( + const std::string_view body(StripComment(text)); + const std::string_view head( make_string_view_range(text.begin(), body.begin())); *output << head << Spacer(body.length(), replacement); break; @@ -100,10 +100,10 @@ void StripVerilogComments(absl::string_view content, std::ostream *output, break; default: { // Retain the "/*" and "*/" but erase everything in between. - const absl::string_view body(StripComment(text)); - const absl::string_view head( + const std::string_view body(StripComment(text)); + const std::string_view head( make_string_view_range(text.begin(), body.begin())); - const absl::string_view tail( + const std::string_view tail( make_string_view_range(body.end(), text.end())); *output << head; diff --git a/verible/verilog/transform/strip-comments.h b/verible/verilog/transform/strip-comments.h index d6513049b..4c034d11f 100644 --- a/verible/verilog/transform/strip-comments.h +++ b/verible/verilog/transform/strip-comments.h @@ -16,8 +16,7 @@ #define VERIBLE_VERILOG_TRANSFORM_STRIP_COMMENTS_H_ #include - -#include "absl/strings/string_view.h" +#include namespace verilog { @@ -33,7 +32,7 @@ namespace verilog { // This preserves byte offsets and line numbers of all unchanged text. // This option is good for visibility. // All lexical errors are ignored. -void StripVerilogComments(absl::string_view content, std::ostream *output, +void StripVerilogComments(std::string_view content, std::ostream *output, char replacement = '\0'); } // namespace verilog diff --git a/verible/verilog/transform/strip-comments_test.cc b/verible/verilog/transform/strip-comments_test.cc index 117986b94..76014d73e 100644 --- a/verible/verilog/transform/strip-comments_test.cc +++ b/verible/verilog/transform/strip-comments_test.cc @@ -15,18 +15,18 @@ #include "verible/verilog/transform/strip-comments.h" #include +#include -#include "absl/strings/string_view.h" #include "gtest/gtest.h" namespace verilog { namespace { struct StripCommentsTestCase { - absl::string_view input; - absl::string_view expect_deleted; - absl::string_view expect_spaced; - absl::string_view expect_otherchar; + std::string_view input; + std::string_view expect_deleted; + std::string_view expect_spaced; + std::string_view expect_otherchar; }; TEST(StripVerilogCommentsTest, Various) {