Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::string_view instead of absl::string_view. #2326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 4 additions & 9 deletions .github/bin/check-potential-problems.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion external_libs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ cc_test(
deps = [
":editscript",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:string_view",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
Expand Down
34 changes: 17 additions & 17 deletions external_libs/editscript_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include <iterator>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>

#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include "gtest/gtest.h"

namespace diff {
Expand Down Expand Up @@ -168,8 +168,8 @@ TEST(DiffTest, CheckNonConstStringVectorDiffResults) {
}

TEST(DiffTest, CompleteDeletion) {
const std::vector<absl::string_view> tokens1{"the", "fox"};
const std::vector<absl::string_view> tokens2;
const std::vector<std::string_view> tokens1{"the", "fox"};
const std::vector<std::string_view> tokens2;

const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
tokens2.begin(), tokens2.end());
Expand All @@ -182,8 +182,8 @@ TEST(DiffTest, CompleteDeletion) {
}

TEST(DiffTest, CompleteInsertion) {
const std::vector<absl::string_view> tokens1;
const std::vector<absl::string_view> tokens2{"jumped", "over", "me"};
const std::vector<std::string_view> tokens1;
const std::vector<std::string_view> tokens2{"jumped", "over", "me"};

const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
tokens2.begin(), tokens2.end());
Expand All @@ -196,8 +196,8 @@ TEST(DiffTest, CompleteInsertion) {
}

TEST(DiffTest, ReplaceFromOneDifferentElement) {
const std::vector<absl::string_view> tokens1{"fox"};
const std::vector<absl::string_view> tokens2{"jumped", "over", "me"};
const std::vector<std::string_view> tokens1{"fox"};
const std::vector<std::string_view> tokens2{"jumped", "over", "me"};

const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
tokens2.begin(), tokens2.end());
Expand All @@ -211,8 +211,8 @@ TEST(DiffTest, ReplaceFromOneDifferentElement) {
}

TEST(DiffTest, ReplaceToOneDifferentElement) {
const std::vector<absl::string_view> tokens1{"jumped", "over", "me"};
const std::vector<absl::string_view> tokens2{"fox"};
const std::vector<std::string_view> tokens1{"jumped", "over", "me"};
const std::vector<std::string_view> tokens2{"fox"};

const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
tokens2.begin(), tokens2.end());
Expand All @@ -226,8 +226,8 @@ TEST(DiffTest, ReplaceToOneDifferentElement) {
}

TEST(DiffTest, CompleteReplacement) {
const std::vector<absl::string_view> tokens1{"the", "fox"};
const std::vector<absl::string_view> tokens2{"jumped", "over", "me"};
const std::vector<std::string_view> tokens1{"the", "fox"};
const std::vector<std::string_view> tokens2{"jumped", "over", "me"};

const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
tokens2.begin(), tokens2.end());
Expand All @@ -241,9 +241,9 @@ TEST(DiffTest, CompleteReplacement) {
}

TEST(DiffTest, StrictSubsequence) {
const std::vector<absl::string_view> tokens1{"the", "fox", "jumped", "over",
"the", "dog", "."};
const std::vector<absl::string_view> tokens2{"fox", "jumped", "over"};
const std::vector<std::string_view> tokens1{"the", "fox", "jumped", "over",
"the", "dog", "."};
const std::vector<std::string_view> tokens2{"fox", "jumped", "over"};

const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
tokens2.begin(), tokens2.end());
Expand All @@ -258,9 +258,9 @@ TEST(DiffTest, StrictSubsequence) {
}

TEST(DiffTest, StrictSupersequence) {
const std::vector<absl::string_view> tokens1{"fox", "jumped", "over"};
const std::vector<absl::string_view> tokens2{"the", "fox", "jumped", "over",
"the", "dog", "."};
const std::vector<std::string_view> tokens1{"fox", "jumped", "over"};
const std::vector<std::string_view> tokens2{"the", "fox", "jumped", "over",
"the", "dog", "."};

const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
tokens2.begin(), tokens2.end());
Expand Down
35 changes: 2 additions & 33 deletions verible/common/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -40,7 +37,6 @@ cc_library(
"//verible/common/util:logging",
"//verible/common/util:spacer",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:string_view",
],
)

Expand All @@ -50,7 +46,6 @@ cc_library(
deps = [
":lint-rule-status",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings:string_view",
],
)

Expand Down Expand Up @@ -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",
],
)

Expand All @@ -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",
],
)

Expand All @@ -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",
],
Expand All @@ -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",
],
)
Expand All @@ -160,7 +151,6 @@ cc_library(
"//verible/common/util:logging",
"//verible/common/util:spacer",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings:string_view",
],
)

Expand All @@ -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
],
)
Expand All @@ -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",
],
)

Expand All @@ -207,7 +195,6 @@ cc_library(
":line-lint-rule",
":lint-rule-status",
"//verible/common/util:logging",
"@abseil-cpp//absl/strings:string_view",
],
)

Expand All @@ -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(
Expand Down Expand Up @@ -261,7 +244,6 @@ cc_library(
":syntax-tree-linter",
"//verible/common/text:text-structure",
"//verible/common/util:logging",
"@abseil-cpp//absl/strings:string_view",
],
)

Expand Down Expand Up @@ -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",
],
)

Expand All @@ -316,7 +297,6 @@ cc_library(
":text-structure-linter",
"//verible/common/text:text-structure",
"//verible/common/util:logging",
"@abseil-cpp//absl/strings:string_view",
],
)

Expand All @@ -326,7 +306,6 @@ cc_library(
deps = [
":lint-rule",
"//verible/common/text:text-structure",
"@abseil-cpp//absl/strings:string_view",
],
)

Expand All @@ -353,7 +332,6 @@ cc_library(
":token-stream-linter",
"//verible/common/text:text-structure",
"//verible/common/util:logging",
"@abseil-cpp//absl/strings:string_view",
],
)

Expand All @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand Down Expand Up @@ -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",
],
Expand All @@ -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",
],
Expand All @@ -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",
],
Expand Down
4 changes: 2 additions & 2 deletions verible/common/analysis/citation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include "verible/common/analysis/citation.h"

#include <string>
#include <string_view>

#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
5 changes: 2 additions & 3 deletions verible/common/analysis/citation.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
#define VERIBLE_COMMON_ANALYSIS_CITATION_H_

#include <string>

#include "absl/strings/string_view.h"
#include <string_view>

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_
4 changes: 2 additions & 2 deletions verible/common/analysis/command-file-lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "verible/common/analysis/command-file-lexer.h"

#include <algorithm>
#include <string_view>
#include <vector>

#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"
Expand All @@ -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) {
Expand Down
Loading
Loading