summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2022-02-11 16:50:54 -0800
committerGitHub <noreply@github.com>2022-02-11 16:50:54 -0800
commit30fe5551cf983eb9bd194117caa3f0f4f2bbe865 (patch)
tree03cef12603ea5010083f01263caf19ae94824d4f
parent09c40635207d42dd30ffaca22477fd3491dd9e7d (diff)
downloadwabt-30fe5551cf983eb9bd194117caa3f0f4f2bbe865.tar.gz
wabt-30fe5551cf983eb9bd194117caa3f0f4f2bbe865.tar.bz2
wabt-30fe5551cf983eb9bd194117caa3f0f4f2bbe865.zip
Use C++17 string_view (#1826)
Now that we have C++17 we don't need our own string_view class anymore. Depends on #1825
-rw-r--r--CMakeLists.txt6
-rw-r--r--src/apply-names.cc26
-rw-r--r--src/binary-reader-ir.cc134
-rw-r--r--src/binary-reader-logging.cc61
-rw-r--r--src/binary-reader-logging.h62
-rw-r--r--src/binary-reader-nop.h64
-rw-r--r--src/binary-reader-objdump.cc280
-rw-r--r--src/binary-reader-objdump.h8
-rw-r--r--src/binary-reader.cc40
-rw-r--r--src/binary-reader.h62
-rw-r--r--src/binary-writer-spec.cc37
-rw-r--r--src/binary-writer-spec.h12
-rw-r--r--src/binary-writer.cc32
-rw-r--r--src/binary-writer.h2
-rw-r--r--src/binding-hash.h6
-rw-r--r--src/c-writer.cc49
-rw-r--r--src/common.cc5
-rw-r--r--src/common.h11
-rw-r--r--src/decompiler-ls.h3
-rw-r--r--src/decompiler-naming.h27
-rw-r--r--src/decompiler.cc22
-rw-r--r--src/emscripten-helpers.cc5
-rw-r--r--src/error-formatter.cc2
-rw-r--r--src/error.h6
-rw-r--r--src/filenames.cc17
-rw-r--r--src/filenames.h6
-rw-r--r--src/hash-util.cc38
-rw-r--r--src/hash-util.h51
-rw-r--r--src/interp/binary-reader-interp.cc64
-rw-r--r--src/interp/binary-reader-interp.h2
-rw-r--r--src/interp/interp-util.cc2
-rw-r--r--src/interp/interp-util.h4
-rw-r--r--src/interp/interp.h2
-rw-r--r--src/ir.cc8
-rw-r--r--src/ir.h60
-rw-r--r--src/literal.h45
-rw-r--r--src/shared-validator.cc4
-rw-r--r--src/shared-validator.h2
-rw-r--r--src/stream.cc8
-rw-r--r--src/stream.h6
-rw-r--r--src/string-util.h81
-rw-r--r--src/string-view.cc195
-rw-r--r--src/string-view.h350
-rw-r--r--src/test-filenames.cc2
-rw-r--r--src/test-literal.cc11
-rw-r--r--src/test-string-view.cc415
-rw-r--r--src/token.cc6
-rw-r--r--src/token.h13
-rw-r--r--src/tools/spectest-interp.cc83
-rw-r--r--src/tools/wasm-opcodecnt.cc1
-rw-r--r--src/tools/wasm-strip.cc2
-rw-r--r--src/tools/wasm2c.cc15
-rw-r--r--src/tools/wast2json.cc4
-rw-r--r--src/tools/wat2wasm.cc4
-rw-r--r--src/wast-lexer.cc20
-rw-r--r--src/wast-lexer.h10
-rw-r--r--src/wast-parser.cc65
-rw-r--r--src/wat-writer.cc12
58 files changed, 823 insertions, 1747 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 84c57336..fcbf3dd5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -293,8 +293,6 @@ set(WABT_LIBRARY_SRC
src/filenames.cc
src/generate-names.h
src/generate-names.cc
- src/hash-util.h
- src/hash-util.cc
src/ir.h
src/ir.cc
src/ir-util.h
@@ -319,8 +317,7 @@ set(WABT_LIBRARY_SRC
src/shared-validator.cc
src/stream.h
src/stream.cc
- src/string-view.h
- src/string-view.cc
+ src/string-util.h
src/token.h
src/token.cc
src/tracing.h
@@ -602,7 +599,6 @@ if (BUILD_TESTS)
src/test-intrusive-list.cc
src/test-literal.cc
src/test-option-parser.cc
- src/test-string-view.cc
src/test-filenames.cc
src/test-utf8.cc
src/test-wast-parser.cc
diff --git a/src/apply-names.cc b/src/apply-names.cc
index b5b11c47..34b44ea1 100644
--- a/src/apply-names.cc
+++ b/src/apply-names.cc
@@ -18,12 +18,12 @@
#include <cassert>
#include <cstdio>
+#include <string_view>
#include <vector>
#include "src/cast.h"
#include "src/expr-visitor.h"
#include "src/ir.h"
-#include "src/string-view.h"
namespace wabt {
@@ -75,8 +75,8 @@ class NameApplier : public ExprVisitor::DelegateNop {
private:
void PushLabel(const std::string& label);
void PopLabel();
- string_view FindLabelByVar(Var* var);
- void UseNameForVar(string_view name, Var* var);
+ std::string_view FindLabelByVar(Var* var);
+ void UseNameForVar(std::string_view name, Var* var);
Result UseNameForFuncTypeVar(Var* var);
Result UseNameForFuncVar(Var* var);
Result UseNameForGlobalVar(Var* var);
@@ -111,7 +111,7 @@ void NameApplier::PopLabel() {
labels_.pop_back();
}
-string_view NameApplier::FindLabelByVar(Var* var) {
+std::string_view NameApplier::FindLabelByVar(Var* var) {
if (var->is_name()) {
for (int i = labels_.size() - 1; i >= 0; --i) {
const std::string& label = labels_[i];
@@ -119,16 +119,16 @@ string_view NameApplier::FindLabelByVar(Var* var) {
return label;
}
}
- return string_view();
+ return std::string_view();
} else {
if (var->index() >= labels_.size()) {
- return string_view();
+ return std::string_view();
}
return labels_[labels_.size() - 1 - var->index()];
}
}
-void NameApplier::UseNameForVar(string_view name, Var* var) {
+void NameApplier::UseNameForVar(std::string_view name, Var* var) {
if (var->is_name()) {
assert(name == var->name());
return;
@@ -302,24 +302,24 @@ Result NameApplier::OnTableFillExpr(TableFillExpr* expr) {
}
Result NameApplier::OnBrExpr(BrExpr* expr) {
- string_view label = FindLabelByVar(&expr->var);
+ std::string_view label = FindLabelByVar(&expr->var);
UseNameForVar(label, &expr->var);
return Result::Ok;
}
Result NameApplier::OnBrIfExpr(BrIfExpr* expr) {
- string_view label = FindLabelByVar(&expr->var);
+ std::string_view label = FindLabelByVar(&expr->var);
UseNameForVar(label, &expr->var);
return Result::Ok;
}
Result NameApplier::OnBrTableExpr(BrTableExpr* expr) {
for (Var& target : expr->targets) {
- string_view label = FindLabelByVar(&target);
+ std::string_view label = FindLabelByVar(&target);
UseNameForVar(label, &target);
}
- string_view label = FindLabelByVar(&expr->default_target);
+ std::string_view label = FindLabelByVar(&expr->default_target);
UseNameForVar(label, &expr->default_target);
return Result::Ok;
}
@@ -342,7 +342,7 @@ Result NameApplier::OnCatchExpr(TryExpr*, Catch* expr) {
}
Result NameApplier::OnDelegateExpr(TryExpr* expr) {
- string_view label = FindLabelByVar(&expr->delegate_target);
+ std::string_view label = FindLabelByVar(&expr->delegate_target);
UseNameForVar(label, &expr->delegate_target);
return Result::Ok;
}
@@ -353,7 +353,7 @@ Result NameApplier::OnThrowExpr(ThrowExpr* expr) {
}
Result NameApplier::OnRethrowExpr(RethrowExpr* expr) {
- string_view label = FindLabelByVar(&expr->var);
+ std::string_view label = FindLabelByVar(&expr->var);
UseNameForVar(label, &expr->var);
return Result::Ok;
}
diff --git a/src/binary-reader-ir.cc b/src/binary-reader-ir.cc
index 3722e4bd..fbb1b091 100644
--- a/src/binary-reader-ir.cc
+++ b/src/binary-reader-ir.cc
@@ -60,30 +60,30 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnImportCount(Index count) override;
Result OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) override;
Result OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) override;
Result OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) override;
Result OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) override;
Result OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) override;
@@ -107,7 +107,7 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) override;
+ std::string_view name) override;
Result OnStartFunction(Index func_index) override;
@@ -242,17 +242,17 @@ class BinaryReaderIR : public BinaryReaderNop {
const void* data,
Address size) override;
- Result OnModuleName(string_view module_name) override;
+ Result OnModuleName(std::string_view module_name) override;
Result OnFunctionNamesCount(Index num_functions) override;
Result OnFunctionName(Index function_index,
- string_view function_name) override;
+ std::string_view function_name) override;
Result OnLocalNameLocalCount(Index function_index, Index num_locals) override;
Result OnLocalName(Index function_index,
Index local_index,
- string_view local_name) override;
+ std::string_view local_name) override;
Result OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) override;
+ std::string_view name) override;
Result BeginTagSection(Offset size) override { return Result::Ok; }
Result OnTagCount(Index count) override { return Result::Ok; }
@@ -261,28 +261,28 @@ class BinaryReaderIR : public BinaryReaderNop {
Result OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) override;
Result OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index func_index) override;
Result OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) override;
Result OnSectionSymbol(Index index,
uint32_t flags,
Index section_index) override;
Result OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) override;
Result OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index table_index) override;
private:
@@ -301,13 +301,13 @@ class BinaryReaderIR : public BinaryReaderNop {
Result AppendCatch(Catch&& catch_);
void SetFuncDeclaration(FuncDeclaration* decl, Var var);
void SetBlockDeclaration(BlockDeclaration* decl, Type sig_type);
- Result SetMemoryName(Index index, string_view name);
- Result SetTableName(Index index, string_view name);
- Result SetFunctionName(Index index, string_view name);
- Result SetGlobalName(Index index, string_view name);
- Result SetDataSegmentName(Index index, string_view name);
- Result SetElemSegmentName(Index index, string_view name);
- Result SetTagName(Index index, string_view name);
+ Result SetMemoryName(Index index, std::string_view name);
+ Result SetTableName(Index index, std::string_view name);
+ Result SetFunctionName(Index index, std::string_view name);
+ Result SetGlobalName(Index index, std::string_view name);
+ Result SetDataSegmentName(Index index, std::string_view name);
+ Result SetElemSegmentName(Index index, std::string_view name);
+ Result SetTagName(Index index, std::string_view name);
std::string GetUniqueName(BindingHash* bindings,
const std::string& original_name);
@@ -474,13 +474,13 @@ Result BinaryReaderIR::OnImportCount(Index count) {
}
Result BinaryReaderIR::OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) {
auto import = MakeUnique<FuncImport>();
- import->module_name = module_name.to_string();
- import->field_name = field_name.to_string();
+ import->module_name = module_name;
+ import->field_name = field_name;
SetFuncDeclaration(&import->func.decl, Var(sig_index, GetLocation()));
module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
@@ -488,14 +488,14 @@ Result BinaryReaderIR::OnImportFunc(Index import_index,
}
Result BinaryReaderIR::OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) {
auto import = MakeUnique<TableImport>();
- import->module_name = module_name.to_string();
- import->field_name = field_name.to_string();
+ import->module_name = module_name;
+ import->field_name = field_name;
import->table.elem_limits = *elem_limits;
import->table.elem_type = elem_type;
module_->AppendField(
@@ -504,13 +504,13 @@ Result BinaryReaderIR::OnImportTable(Index import_index,
}
Result BinaryReaderIR::OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) {
auto import = MakeUnique<MemoryImport>();
- import->module_name = module_name.to_string();
- import->field_name = field_name.to_string();
+ import->module_name = module_name;
+ import->field_name = field_name;
import->memory.page_limits = *page_limits;
module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
@@ -518,14 +518,14 @@ Result BinaryReaderIR::OnImportMemory(Index import_index,
}
Result BinaryReaderIR::OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) {
auto import = MakeUnique<GlobalImport>();
- import->module_name = module_name.to_string();
- import->field_name = field_name.to_string();
+ import->module_name = module_name;
+ import->field_name = field_name;
import->global.type = type;
import->global.mutable_ = mutable_;
module_->AppendField(
@@ -534,13 +534,13 @@ Result BinaryReaderIR::OnImportGlobal(Index import_index,
}
Result BinaryReaderIR::OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) {
auto import = MakeUnique<TagImport>();
- import->module_name = module_name.to_string();
- import->field_name = field_name.to_string();
+ import->module_name = module_name;
+ import->field_name = field_name;
SetFuncDeclaration(&import->tag.decl, Var(sig_index, GetLocation()));
module_->AppendField(
MakeUnique<ImportModuleField>(std::move(import), GetLocation()));
@@ -631,10 +631,10 @@ Result BinaryReaderIR::OnExportCount(Index count) {
Result BinaryReaderIR::OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) {
+ std::string_view name) {
auto field = MakeUnique<ExportModuleField>(GetLocation());
Export& export_ = field->export_;
- export_.name = name.to_string();
+ export_.name = name;
export_.var = Var(item_index, GetLocation());
export_.kind = kind;
module_->AppendField(std::move(field));
@@ -1271,11 +1271,11 @@ Result BinaryReaderIR::OnFunctionNamesCount(Index count) {
return Result::Ok;
}
-static std::string MakeDollarName(string_view name) {
- return std::string("$") + name.to_string();
+static std::string MakeDollarName(std::string_view name) {
+ return std::string("$") + std::string(name);
}
-Result BinaryReaderIR::OnModuleName(string_view name) {
+Result BinaryReaderIR::OnModuleName(std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1284,7 +1284,7 @@ Result BinaryReaderIR::OnModuleName(string_view name) {
return Result::Ok;
}
-Result BinaryReaderIR::SetGlobalName(Index index, string_view name) {
+Result BinaryReaderIR::SetGlobalName(Index index, std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1300,7 +1300,7 @@ Result BinaryReaderIR::SetGlobalName(Index index, string_view name) {
return Result::Ok;
}
-Result BinaryReaderIR::SetFunctionName(Index index, string_view name) {
+Result BinaryReaderIR::SetFunctionName(Index index, std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1316,7 +1316,7 @@ Result BinaryReaderIR::SetFunctionName(Index index, string_view name) {
return Result::Ok;
}
-Result BinaryReaderIR::SetTableName(Index index, string_view name) {
+Result BinaryReaderIR::SetTableName(Index index, std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1332,7 +1332,7 @@ Result BinaryReaderIR::SetTableName(Index index, string_view name) {
return Result::Ok;
}
-Result BinaryReaderIR::SetDataSegmentName(Index index, string_view name) {
+Result BinaryReaderIR::SetDataSegmentName(Index index, std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1348,7 +1348,7 @@ Result BinaryReaderIR::SetDataSegmentName(Index index, string_view name) {
return Result::Ok;
}
-Result BinaryReaderIR::SetElemSegmentName(Index index, string_view name) {
+Result BinaryReaderIR::SetElemSegmentName(Index index, std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1364,7 +1364,7 @@ Result BinaryReaderIR::SetElemSegmentName(Index index, string_view name) {
return Result::Ok;
}
-Result BinaryReaderIR::SetMemoryName(Index index, string_view name) {
+Result BinaryReaderIR::SetMemoryName(Index index, std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1380,7 +1380,7 @@ Result BinaryReaderIR::SetMemoryName(Index index, string_view name) {
return Result::Ok;
}
-Result BinaryReaderIR::SetTagName(Index index, string_view name) {
+Result BinaryReaderIR::SetTagName(Index index, std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1396,13 +1396,13 @@ Result BinaryReaderIR::SetTagName(Index index, string_view name) {
return Result::Ok;
}
-Result BinaryReaderIR::OnFunctionName(Index index, string_view name) {
+Result BinaryReaderIR::OnFunctionName(Index index, std::string_view name) {
return SetFunctionName(index, name);
}
Result BinaryReaderIR::OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) {
+ std::string_view name) {
switch (type) {
// TODO(sbc): remove OnFunctionName in favor of just using
// OnNameEntry so that this works
@@ -1449,7 +1449,7 @@ Result BinaryReaderIR::OnLocalNameLocalCount(Index index, Index count) {
Result BinaryReaderIR::OnLocalName(Index func_index,
Index local_index,
- string_view name) {
+ std::string_view name) {
if (name.empty()) {
return Result::Ok;
}
@@ -1470,7 +1470,7 @@ Result BinaryReaderIR::OnTagType(Index index, Index sig_index) {
Result BinaryReaderIR::OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) {
@@ -1500,7 +1500,7 @@ Result BinaryReaderIR::OnDataSymbol(Index index,
Result BinaryReaderIR::OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index func_index) {
if (name.empty()) {
return Result::Ok;
@@ -1523,7 +1523,7 @@ Result BinaryReaderIR::OnFunctionSymbol(Index index,
Result BinaryReaderIR::OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) {
return SetGlobalName(global_index, name);
}
@@ -1536,7 +1536,7 @@ Result BinaryReaderIR::OnSectionSymbol(Index index,
Result BinaryReaderIR::OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) {
if (name.empty()) {
return Result::Ok;
@@ -1555,7 +1555,7 @@ Result BinaryReaderIR::OnTagSymbol(Index index,
Result BinaryReaderIR::OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index table_index) {
return SetTableName(index, name);
}
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc
index 459fca24..2e7cb41c 100644
--- a/src/binary-reader-logging.cc
+++ b/src/binary-reader-logging.cc
@@ -132,7 +132,7 @@ Result BinaryReaderLogging::BeginSection(Index section_index,
Result BinaryReaderLogging::BeginCustomSection(Index section_index,
Offset size,
- string_view section_name) {
+ std::string_view section_name) {
LOGF("BeginCustomSection('" PRIstringview "', size: %" PRIzd ")\n",
WABT_PRINTF_STRING_VIEW_ARG(section_name), size);
Indent();
@@ -177,8 +177,8 @@ Result BinaryReaderLogging::OnArrayType(Index index, TypeMut field) {
Result BinaryReaderLogging::OnImport(Index index,
ExternalKind kind,
- string_view module_name,
- string_view field_name) {
+ std::string_view module_name,
+ std::string_view field_name) {
LOGF("OnImport(index: %" PRIindex ", kind: %s, module: \"" PRIstringview
"\", field: \"" PRIstringview "\")\n",
index, GetKindName(kind), WABT_PRINTF_STRING_VIEW_ARG(module_name),
@@ -187,8 +187,8 @@ Result BinaryReaderLogging::OnImport(Index index,
}
Result BinaryReaderLogging::OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) {
LOGF("OnImportFunc(import_index: %" PRIindex ", func_index: %" PRIindex
@@ -199,8 +199,8 @@ Result BinaryReaderLogging::OnImportFunc(Index import_index,
}
Result BinaryReaderLogging::OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) {
@@ -214,8 +214,8 @@ Result BinaryReaderLogging::OnImportTable(Index import_index,
}
Result BinaryReaderLogging::OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) {
char buf[100];
@@ -228,8 +228,8 @@ Result BinaryReaderLogging::OnImportMemory(Index import_index,
}
Result BinaryReaderLogging::OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) {
@@ -243,8 +243,8 @@ Result BinaryReaderLogging::OnImportGlobal(Index import_index,
}
Result BinaryReaderLogging::OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) {
LOGF("OnImportTag(import_index: %" PRIindex ", tag_index: %" PRIindex
@@ -280,7 +280,7 @@ Result BinaryReaderLogging::BeginGlobal(Index index, Type type, bool mutable_) {
Result BinaryReaderLogging::OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) {
+ std::string_view name) {
LOGF("OnExport(index: %" PRIindex ", kind: %s, item_index: %" PRIindex
", name: \"" PRIstringview "\")\n",
index, GetKindName(kind), item_index, WABT_PRINTF_STRING_VIEW_ARG(name));
@@ -434,7 +434,7 @@ Result BinaryReaderLogging::OnModuleNameSubsection(Index index,
return reader_->OnModuleNameSubsection(index, name_type, subsection_size);
}
-Result BinaryReaderLogging::OnModuleName(string_view name) {
+Result BinaryReaderLogging::OnModuleName(std::string_view name) {
LOGF("OnModuleName(name: \"" PRIstringview "\")\n",
WABT_PRINTF_STRING_VIEW_ARG(name));
return reader_->OnModuleName(name);
@@ -449,7 +449,7 @@ Result BinaryReaderLogging::OnFunctionNameSubsection(Index index,
return reader_->OnFunctionNameSubsection(index, name_type, subsection_size);
}
-Result BinaryReaderLogging::OnFunctionName(Index index, string_view name) {
+Result BinaryReaderLogging::OnFunctionName(Index index, std::string_view name) {
LOGF("OnFunctionName(index: %" PRIindex ", name: \"" PRIstringview "\")\n",
index, WABT_PRINTF_STRING_VIEW_ARG(name));
return reader_->OnFunctionName(index, name);
@@ -466,7 +466,7 @@ Result BinaryReaderLogging::OnLocalNameSubsection(Index index,
Result BinaryReaderLogging::OnLocalName(Index func_index,
Index local_index,
- string_view name) {
+ std::string_view name) {
LOGF("OnLocalName(func_index: %" PRIindex ", local_index: %" PRIindex
", name: \"" PRIstringview "\")\n",
func_index, local_index, WABT_PRINTF_STRING_VIEW_ARG(name));
@@ -484,7 +484,7 @@ Result BinaryReaderLogging::OnNameSubsection(
Result BinaryReaderLogging::OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) {
+ std::string_view name) {
LOGF("OnNameEntry(type: %s, index: %" PRIindex ", name: \"" PRIstringview
"\")\n",
GetNameSectionSubsectionName(type), index,
@@ -503,20 +503,21 @@ Result BinaryReaderLogging::OnDylinkInfo(uint32_t mem_size,
return reader_->OnDylinkInfo(mem_size, mem_align, table_size, table_align);
}
-Result BinaryReaderLogging::OnDylinkNeeded(string_view so_name) {
+Result BinaryReaderLogging::OnDylinkNeeded(std::string_view so_name) {
LOGF("OnDylinkNeeded(name: " PRIstringview ")\n",
WABT_PRINTF_STRING_VIEW_ARG(so_name));
return reader_->OnDylinkNeeded(so_name);
}
-Result BinaryReaderLogging::OnDylinkExport(string_view name, uint32_t flags) {
+Result BinaryReaderLogging::OnDylinkExport(std::string_view name,
+ uint32_t flags) {
LOGF("OnDylinkExport(name: " PRIstringview ", flags: 0x%x)\n",
WABT_PRINTF_STRING_VIEW_ARG(name), flags);
return reader_->OnDylinkExport(name, flags);
}
-Result BinaryReaderLogging::OnDylinkImport(string_view module,
- string_view name,
+Result BinaryReaderLogging::OnDylinkImport(std::string_view module,
+ std::string_view name,
uint32_t flags) {
LOGF("OnDylinkImport(module: " PRIstringview ", name: " PRIstringview
", flags: 0x%x)\n",
@@ -542,7 +543,7 @@ Result BinaryReaderLogging::OnReloc(RelocType type,
return reader_->OnReloc(type, offset, index, addend);
}
-Result BinaryReaderLogging::OnFeature(uint8_t prefix, string_view name) {
+Result BinaryReaderLogging::OnFeature(uint8_t prefix, std::string_view name) {
LOGF("OnFeature(prefix: '%c', name: '" PRIstringview "')\n", prefix,
WABT_PRINTF_STRING_VIEW_ARG(name));
return reader_->OnFeature(prefix, name);
@@ -550,7 +551,7 @@ Result BinaryReaderLogging::OnFeature(uint8_t prefix, string_view name) {
Result BinaryReaderLogging::OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) {
@@ -561,7 +562,7 @@ Result BinaryReaderLogging::OnDataSymbol(Index index,
Result BinaryReaderLogging::OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index func_index) {
LOGF("OnFunctionSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
")\n",
@@ -571,7 +572,7 @@ Result BinaryReaderLogging::OnFunctionSymbol(Index index,
Result BinaryReaderLogging::OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) {
LOGF("OnGlobalSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
")\n",
@@ -589,7 +590,7 @@ Result BinaryReaderLogging::OnSectionSymbol(Index index,
Result BinaryReaderLogging::OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) {
LOGF("OnTagSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
")\n",
@@ -599,7 +600,7 @@ Result BinaryReaderLogging::OnTagSymbol(Index index,
Result BinaryReaderLogging::OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index table_index) {
LOGF("OnTableSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
")\n",
@@ -608,7 +609,7 @@ Result BinaryReaderLogging::OnTableSymbol(Index index,
}
Result BinaryReaderLogging::OnSegmentInfo(Index index,
- string_view name,
+ std::string_view name,
Address alignment,
uint32_t flags) {
LOGF("OnSegmentInfo(%d name: " PRIstringview ", alignment: %" PRIaddress
@@ -623,7 +624,7 @@ Result BinaryReaderLogging::OnInitFunction(uint32_t priority,
return reader_->OnInitFunction(priority, func_index);
}
-Result BinaryReaderLogging::OnComdatBegin(string_view name,
+Result BinaryReaderLogging::OnComdatBegin(std::string_view name,
uint32_t flags,
Index count) {
LOGF("OnComdatBegin(" PRIstringview ", flags: %d, count: %" PRIindex ")\n",
diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h
index 1c2f302a..740da63f 100644
--- a/src/binary-reader-logging.h
+++ b/src/binary-reader-logging.h
@@ -39,7 +39,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result BeginCustomSection(Index section_index,
Offset size,
- string_view section_name) override;
+ std::string_view section_name) override;
Result EndCustomSection() override;
Result BeginTypeSection(Offset size) override;
@@ -57,33 +57,33 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnImportCount(Index count) override;
Result OnImport(Index index,
ExternalKind kind,
- string_view module_name,
- string_view field_name) override;
+ std::string_view module_name,
+ std::string_view field_name) override;
Result OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) override;
Result OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) override;
Result OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) override;
Result OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) override;
Result OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) override;
Result EndImportSection() override;
@@ -118,7 +118,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) override;
+ std::string_view name) override;
Result EndExportSection() override;
Result BeginStartSection(Offset size) override;
@@ -288,13 +288,13 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnModuleNameSubsection(Index index,
uint32_t name_type,
Offset subsection_size) override;
- Result OnModuleName(string_view name) override;
+ Result OnModuleName(std::string_view name) override;
Result OnFunctionNameSubsection(Index index,
uint32_t name_type,
Offset subsection_size) override;
Result OnFunctionNamesCount(Index num_functions) override;
Result OnFunctionName(Index function_index,
- string_view function_name) override;
+ std::string_view function_name) override;
Result OnLocalNameSubsection(Index index,
uint32_t name_type,
Offset subsection_size) override;
@@ -302,13 +302,13 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnLocalNameLocalCount(Index function_index, Index num_locals) override;
Result OnLocalName(Index function_index,
Index local_index,
- string_view local_name) override;
+ std::string_view local_name) override;
Result OnNameSubsection(Index index,
NameSectionSubsection subsection_type,
Offset subsection_size) override;
Result OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) override;
+ std::string_view name) override;
Result OnNameCount(Index num_names) override;
Result EndNamesSection() override;
@@ -326,56 +326,58 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
uint32_t table_size,
uint32_t table_align) override;
Result OnDylinkNeededCount(Index count) override;
- Result OnDylinkNeeded(string_view needed) override;
+ Result OnDylinkNeeded(std::string_view needed) override;
Result OnDylinkImportCount(Index count) override;
Result OnDylinkExportCount(Index count) override;
- Result OnDylinkImport(string_view module,
- string_view name,
+ Result OnDylinkImport(std::string_view module,
+ std::string_view name,
uint32_t flags) override;
- Result OnDylinkExport(string_view name, uint32_t flags) override;
+ Result OnDylinkExport(std::string_view name, uint32_t flags) override;
Result EndDylinkSection() override;
Result BeginTargetFeaturesSection(Offset size) override;
Result OnFeatureCount(Index count) override;
- Result OnFeature(uint8_t prefix, string_view name) override;
+ Result OnFeature(uint8_t prefix, std::string_view name) override;
Result EndTargetFeaturesSection() override;
Result BeginLinkingSection(Offset size) override;
Result OnSymbolCount(Index count) override;
Result OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) override;
Result OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index func_index) override;
Result OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) override;
Result OnSectionSymbol(Index index,
uint32_t flags,
Index section_index) override;
Result OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) override;
Result OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) override;
Result OnSegmentInfoCount(Index count) override;
Result OnSegmentInfo(Index index,
- string_view name,
+ std::string_view name,
Address alignment,
uint32_t flags) override;
Result OnInitFunctionCount(Index count) override;
Result OnInitFunction(uint32_t priority, Index function_index) override;
Result OnComdatCount(Index count) override;
- Result OnComdatBegin(string_view name, uint32_t flags, Index count) override;
+ Result OnComdatBegin(std::string_view name,
+ uint32_t flags,
+ Index count) override;
Result OnComdatEntry(ComdatType kind, Index index) override;
Result EndLinkingSection() override;
diff --git a/src/binary-reader-nop.h b/src/binary-reader-nop.h
index d87ec922..4adde26a 100644
--- a/src/binary-reader-nop.h
+++ b/src/binary-reader-nop.h
@@ -38,7 +38,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
/* Custom section */
Result BeginCustomSection(Index section_index,
Offset size,
- string_view section_name) override {
+ std::string_view section_name) override {
return Result::Ok;
}
Result EndCustomSection() override { return Result::Ok; }
@@ -66,43 +66,43 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnImportCount(Index count) override { return Result::Ok; }
Result OnImport(Index index,
ExternalKind kind,
- string_view module_name,
- string_view field_name) override {
+ std::string_view module_name,
+ std::string_view field_name) override {
return Result::Ok;
}
Result OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) override {
return Result::Ok;
}
Result OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) override {
return Result::Ok;
}
Result OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) override {
return Result::Ok;
}
Result OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) override {
return Result::Ok;
}
Result OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) override {
return Result::Ok;
@@ -152,7 +152,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) override {
+ std::string_view name) override {
return Result::Ok;
}
Result EndExportSection() override { return Result::Ok; }
@@ -399,7 +399,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Offset subsection_size) override {
return Result::Ok;
}
- Result OnModuleName(string_view name) override { return Result::Ok; }
+ Result OnModuleName(std::string_view name) override { return Result::Ok; }
Result OnFunctionNameSubsection(Index index,
uint32_t name_type,
Offset subsection_size) override {
@@ -409,7 +409,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
return Result::Ok;
}
Result OnFunctionName(Index function_index,
- string_view function_name) override {
+ std::string_view function_name) override {
return Result::Ok;
}
Result OnLocalNameSubsection(Index index,
@@ -426,7 +426,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
}
Result OnLocalName(Index function_index,
Index local_index,
- string_view local_name) override {
+ std::string_view local_name) override {
return Result::Ok;
}
Result EndNamesSection() override { return Result::Ok; }
@@ -439,7 +439,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnNameCount(Index num_names) override { return Result::Ok; }
Result OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) override {
+ std::string_view name) override {
return Result::Ok;
}
@@ -471,15 +471,17 @@ class BinaryReaderNop : public BinaryReaderDelegate {
return Result::Ok;
}
Result OnDylinkNeededCount(Index count) override { return Result::Ok; }
- Result OnDylinkNeeded(string_view so_name) override { return Result::Ok; }
+ Result OnDylinkNeeded(std::string_view so_name) override {
+ return Result::Ok;
+ }
Result OnDylinkImportCount(Index count) override { return Result::Ok; }
Result OnDylinkExportCount(Index count) override { return Result::Ok; }
- Result OnDylinkImport(string_view module,
- string_view name,
+ Result OnDylinkImport(std::string_view module,
+ std::string_view name,
uint32_t flags) override {
return Result::Ok;
}
- Result OnDylinkExport(string_view name, uint32_t flags) override {
+ Result OnDylinkExport(std::string_view name, uint32_t flags) override {
return Result::Ok;
}
Result EndDylinkSection() override { return Result::Ok; }
@@ -487,7 +489,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
/* target_features section */
Result BeginTargetFeaturesSection(Offset size) override { return Result::Ok; }
Result OnFeatureCount(Index count) override { return Result::Ok; }
- Result OnFeature(uint8_t prefix, string_view name) override {
+ Result OnFeature(uint8_t prefix, std::string_view name) override {
return Result::Ok;
}
Result EndTargetFeaturesSection() override { return Result::Ok; }
@@ -497,7 +499,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnSymbolCount(Index count) override { return Result::Ok; }
Result OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) override {
@@ -505,13 +507,13 @@ class BinaryReaderNop : public BinaryReaderDelegate {
}
Result OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index func_index) override {
return Result::Ok;
}
Result OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) override {
return Result::Ok;
}
@@ -522,19 +524,19 @@ class BinaryReaderNop : public BinaryReaderDelegate {
}
Result OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) override {
return Result::Ok;
}
Result OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index table_index) override {
return Result::Ok;
}
Result OnSegmentInfoCount(Index count) override { return Result::Ok; }
Result OnSegmentInfo(Index index,
- string_view name,
+ std::string_view name,
Address alignment,
uint32_t flags) override {
return Result::Ok;
@@ -544,7 +546,9 @@ class BinaryReaderNop : public BinaryReaderDelegate {
return Result::Ok;
}
Result OnComdatCount(Index count) override { return Result::Ok; }
- Result OnComdatBegin(string_view name, uint32_t flags, Index count) override {
+ Result OnComdatBegin(std::string_view name,
+ uint32_t flags,
+ Index count) override {
return Result::Ok;
}
Result OnComdatEntry(ComdatType kind, Index index) override {
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index bf7028da..deb1167f 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -30,6 +30,7 @@
#include "src/binary-reader-nop.h"
#include "src/filenames.h"
#include "src/literal.h"
+#include "src/string-util.h"
namespace wabt {
@@ -52,14 +53,14 @@ class BinaryReaderObjdumpBase : public BinaryReaderNop {
Result OnRelocCount(Index count, Index section_index) override;
protected:
- string_view GetFunctionName(Index index) const;
- string_view GetGlobalName(Index index) const;
- string_view GetLocalName(Index function_index, Index local_index) const;
- string_view GetSectionName(Index index) const;
- string_view GetTagName(Index index) const;
- string_view GetSymbolName(Index index) const;
- string_view GetSegmentName(Index index) const;
- string_view GetTableName(Index index) const;
+ std::string_view GetFunctionName(Index index) const;
+ std::string_view GetGlobalName(Index index) const;
+ std::string_view GetLocalName(Index function_index, Index local_index) const;
+ std::string_view GetSectionName(Index index) const;
+ std::string_view GetTagName(Index index) const;
+ std::string_view GetSymbolName(Index index) const;
+ std::string_view GetSegmentName(Index index) const;
+ std::string_view GetTableName(Index index) const;
void PrintRelocation(const Reloc& reloc, Offset offset) const;
Offset GetPrintOffset(Offset offset) const;
Offset GetSectionStart(BinarySection section_code) const {
@@ -123,11 +124,11 @@ Result BinaryReaderObjdumpBase::BeginModule(uint32_t version) {
printf("Code Disassembly:\n\n");
break;
case ObjdumpMode::Prepass: {
- string_view basename = GetBasename(options_->filename);
+ std::string_view basename = GetBasename(options_->filename);
if (basename == "-") {
basename = "<stdin>";
}
- printf("%s:\tfile format wasm %#x\n", basename.to_string().c_str(),
+ printf("%s:\tfile format wasm %#x\n", std::string(basename).c_str(),
version);
break;
}
@@ -138,36 +139,38 @@ Result BinaryReaderObjdumpBase::BeginModule(uint32_t version) {
return Result::Ok;
}
-string_view BinaryReaderObjdumpBase::GetFunctionName(Index index) const {
+std::string_view BinaryReaderObjdumpBase::GetFunctionName(Index index) const {
return objdump_state_->function_names.Get(index);
}
-string_view BinaryReaderObjdumpBase::GetGlobalName(Index index) const {
+std::string_view BinaryReaderObjdumpBase::GetGlobalName(Index index) const {
return objdump_state_->global_names.Get(index);
}
-string_view BinaryReaderObjdumpBase::GetLocalName(Index function_index,
- Index local_index) const {
+std::string_view BinaryReaderObjdumpBase::GetLocalName(
+ Index function_index,
+ Index local_index) const {
return objdump_state_->local_names.Get(function_index, local_index);
}
-string_view BinaryReaderObjdumpBase::GetSectionName(Index index) const {
+std::string_view BinaryReaderObjdumpBase::GetSectionName(Index index) const {
return objdump_state_->section_names.Get(index);
}
-string_view BinaryReaderObjdumpBase::GetTagName(Index index) const {
+std::string_view BinaryReaderObjdumpBase::GetTagName(Index index) const {
return objdump_state_->tag_names.Get(index);
}
-string_view BinaryReaderObjdumpBase::GetSegmentName(Index index) const {
+std::string_view BinaryReaderObjdumpBase::GetSegmentName(Index index) const {
return objdump_state_->segment_names.Get(index);
}
-string_view BinaryReaderObjdumpBase::GetTableName(Index index) const {
+std::string_view BinaryReaderObjdumpBase::GetTableName(Index index) const {
return objdump_state_->table_names.Get(index);
}
-string_view BinaryReaderObjdumpBase::GetSymbolName(Index symbol_index) const {
+std::string_view BinaryReaderObjdumpBase::GetSymbolName(
+ Index symbol_index) const {
if (symbol_index >= objdump_state_->symtab.size())
return "<illegal_symbol_index>";
ObjdumpSymbol& sym = objdump_state_->symtab[symbol_index];
@@ -236,12 +239,12 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
Result BeginCustomSection(Index section_index,
Offset size,
- string_view section_name) override {
+ std::string_view section_name) override {
objdump_state_->section_names.Set(section_index, section_name);
return Result::Ok;
}
- Result OnFunctionName(Index index, string_view name) override {
+ Result OnFunctionName(Index index, std::string_view name) override {
SetFunctionName(index, name);
return Result::Ok;
}
@@ -257,7 +260,7 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
Result OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) override {
+ std::string_view name) override {
switch (type) {
// TODO(sbc): remove OnFunctionName in favor of just using
// OnNameEntry so that this works
@@ -286,7 +289,7 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
Result OnLocalName(Index function_index,
Index local_index,
- string_view local_name) override {
+ std::string_view local_name) override {
SetLocalName(function_index, local_index, local_name);
return Result::Ok;
}
@@ -298,34 +301,34 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
Result OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) override {
- objdump_state_->symtab[index] = {SymbolType::Data, name.to_string(), 0};
+ objdump_state_->symtab[index] = {SymbolType::Data, std::string(name), 0};
return Result::Ok;
}
Result OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index func_index) override {
if (!name.empty()) {
SetFunctionName(func_index, name);
}
- objdump_state_->symtab[index] = {SymbolType::Function, name.to_string(),
+ objdump_state_->symtab[index] = {SymbolType::Function, std::string(name),
func_index};
return Result::Ok;
}
Result OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) override {
if (!name.empty()) {
SetGlobalName(global_index, name);
}
- objdump_state_->symtab[index] = {SymbolType::Global, name.to_string(),
+ objdump_state_->symtab[index] = {SymbolType::Global, std::string(name),
global_index};
return Result::Ok;
}
@@ -341,74 +344,70 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
Result OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) override {
if (!name.empty()) {
SetTagName(tag_index, name);
}
- objdump_state_->symtab[index] = {SymbolType::Tag, name.to_string(),
+ objdump_state_->symtab[index] = {SymbolType::Tag, std::string(name),
tag_index};
return Result::Ok;
}
Result OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index table_index) override {
if (!name.empty()) {
SetTableName(table_index, name);
}
- objdump_state_->symtab[index] = {SymbolType::Table, name.to_string(),
+ objdump_state_->symtab[index] = {SymbolType::Table, std::string(name),
table_index};
return Result::Ok;
}
Result OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) override {
- SetFunctionName(func_index,
- module_name.to_string() + "." + field_name.to_string());
+ SetFunctionName(func_index, module_name + "." + field_name);
return Result::Ok;
}
Result OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) override {
- SetTagName(tag_index,
- module_name.to_string() + "." + field_name.to_string());
+ SetTagName(tag_index, module_name + "." + field_name);
return Result::Ok;
}
Result OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) override {
- SetGlobalName(global_index,
- module_name.to_string() + "." + field_name.to_string());
+ SetGlobalName(global_index, module_name + "." + field_name);
return Result::Ok;
}
Result OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) override {
- SetTableName(table_index,
- module_name.to_string() + "." + field_name.to_string());
+ SetTableName(table_index, module_name + "." + field_name);
return Result::Ok;
}
Result OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) override {
+ std::string_view name) override {
if (kind == ExternalKind::Func) {
SetFunctionName(item_index, name);
} else if (kind == ExternalKind::Global) {
@@ -422,7 +421,7 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
Index index,
uint32_t addend) override;
- Result OnModuleName(string_view name) override {
+ Result OnModuleName(std::string_view name) override {
if (options_->mode == ObjdumpMode::Prepass) {
printf("module name: <" PRIstringview ">\n",
WABT_PRINTF_STRING_VIEW_ARG(name));
@@ -431,7 +430,7 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
}
Result OnSegmentInfo(Index index,
- string_view name,
+ std::string_view name,
Address alignment_log2,
uint32_t flags) override {
SetSegmentName(index, name);
@@ -439,38 +438,44 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
}
protected:
- void SetFunctionName(Index index, string_view name);
- void SetGlobalName(Index index, string_view name);
- void SetLocalName(Index function_index, Index local_index, string_view name);
- void SetTagName(Index index, string_view name);
- void SetTableName(Index index, string_view name);
- void SetSegmentName(Index index, string_view name);
+ void SetFunctionName(Index index, std::string_view name);
+ void SetGlobalName(Index index, std::string_view name);
+ void SetLocalName(Index function_index,
+ Index local_index,
+ std::string_view name);
+ void SetTagName(Index index, std::string_view name);
+ void SetTableName(Index index, std::string_view name);
+ void SetSegmentName(Index index, std::string_view name);
};
void BinaryReaderObjdumpPrepass::SetFunctionName(Index index,
- string_view name) {
+ std::string_view name) {
objdump_state_->function_names.Set(index, name);
}
-void BinaryReaderObjdumpPrepass::SetGlobalName(Index index, string_view name) {
+void BinaryReaderObjdumpPrepass::SetGlobalName(Index index,
+ std::string_view name) {
objdump_state_->global_names.Set(index, name);
}
void BinaryReaderObjdumpPrepass::SetLocalName(Index function_index,
Index local_index,
- string_view name) {
+ std::string_view name) {
objdump_state_->local_names.Set(function_index, local_index, name);
}
-void BinaryReaderObjdumpPrepass::SetTagName(Index index, string_view name) {
+void BinaryReaderObjdumpPrepass::SetTagName(Index index,
+ std::string_view name) {
objdump_state_->tag_names.Set(index, name);
}
-void BinaryReaderObjdumpPrepass::SetTableName(Index index, string_view name) {
+void BinaryReaderObjdumpPrepass::SetTableName(Index index,
+ std::string_view name) {
objdump_state_->table_names.Set(index, name);
}
-void BinaryReaderObjdumpPrepass::SetSegmentName(Index index, string_view name) {
+void BinaryReaderObjdumpPrepass::SetSegmentName(Index index,
+ std::string_view name) {
objdump_state_->segment_names.Set(index, name);
}
@@ -701,7 +706,7 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeIndex(Index value) {
if (!in_function_body) {
return Result::Ok;
}
- string_view name;
+ std::string_view name;
if (current_opcode == Opcode::Call &&
!(name = GetFunctionName(value)).empty()) {
LogOpcode("%d <" PRIstringview ">", value,
@@ -739,7 +744,7 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeUint32(uint32_t value) {
if (!in_function_body) {
return Result::Ok;
}
- string_view name;
+ std::string_view name;
if (current_opcode == Opcode::DataDrop &&
!(name = GetSegmentName(value)).empty()) {
LogOpcode("%d <" PRIstringview ">", value,
@@ -754,7 +759,7 @@ Result BinaryReaderObjdumpDisassemble::OnOpcodeUint32Uint32(uint32_t value,
uint32_t value2) {
if (!in_function_body)
return Result::Ok;
- string_view name;
+ std::string_view name;
if (current_opcode == Opcode::MemoryInit &&
!(name = GetSegmentName(value)).empty()) {
LogOpcode("%u %u <" PRIstringview ">", value, value2,
@@ -942,7 +947,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Offset size) override;
Result BeginCustomSection(Index section_index,
Offset size,
- string_view section_name) override;
+ std::string_view section_name) override;
Result OnTypeCount(Index count) override;
Result OnFuncType(Index index,
@@ -955,30 +960,30 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Result OnImportCount(Index count) override;
Result OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) override;
Result OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) override;
Result OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) override;
Result OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) override;
Result OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) override;
@@ -1000,7 +1005,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Result OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) override;
+ std::string_view name) override;
Result OnStartFunction(Index func_index) override;
Result OnDataCount(Index count) override;
@@ -1056,28 +1061,28 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
const void* data,
Address size) override;
- Result OnModuleName(string_view name) override;
+ Result OnModuleName(std::string_view name) override;
Result OnFunctionName(Index function_index,
- string_view function_name) override;
+ std::string_view function_name) override;
Result OnLocalName(Index function_index,
Index local_index,
- string_view local_name) override;
+ std::string_view local_name) override;
Result OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) override;
+ std::string_view name) override;
Result OnDylinkInfo(uint32_t mem_size,
uint32_t mem_align_log2,
uint32_t table_size,
uint32_t table_align_log2) override;
Result OnDylinkNeededCount(Index count) override;
- Result OnDylinkNeeded(string_view so_name) override;
+ Result OnDylinkNeeded(std::string_view so_name) override;
Result OnDylinkImportCount(Index count) override;
Result OnDylinkExportCount(Index count) override;
- Result OnDylinkImport(string_view module,
- string_view name,
+ Result OnDylinkImport(std::string_view module,
+ std::string_view name,
uint32_t flags) override;
- Result OnDylinkExport(string_view name, uint32_t flags) override;
+ Result OnDylinkExport(std::string_view name, uint32_t flags) override;
Result OnRelocCount(Index count, Index section_index) override;
Result OnReloc(RelocType type,
@@ -1085,43 +1090,45 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Index index,
uint32_t addend) override;
- Result OnFeature(uint8_t prefix, string_view name) override;
+ Result OnFeature(uint8_t prefix, std::string_view name) override;
Result OnSymbolCount(Index count) override;
Result OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) override;
Result OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index func_index) override;
Result OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) override;
Result OnSectionSymbol(Index index,
uint32_t flags,
Index section_index) override;
Result OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) override;
Result OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index table_index) override;
Result OnSegmentInfoCount(Index count) override;
Result OnSegmentInfo(Index index,
- string_view name,
+ std::string_view name,
Address alignment_log2,
uint32_t flags) override;
Result OnInitFunctionCount(Index count) override;
Result OnInitFunction(uint32_t priority, Index function_index) override;
Result OnComdatCount(Index count) override;
- Result OnComdatBegin(string_view name, uint32_t flags, Index count) override;
+ Result OnComdatBegin(std::string_view name,
+ uint32_t flags,
+ Index count) override;
Result OnComdatEntry(ComdatType kind, Index index) override;
Result OnTagCount(Index count) override;
@@ -1173,7 +1180,7 @@ BinaryReaderObjdump::BinaryReaderObjdump(const uint8_t* data,
Result BinaryReaderObjdump::BeginCustomSection(Index section_index,
Offset size,
- string_view section_name) {
+ std::string_view section_name) {
PrintDetails(" - name: \"" PRIstringview "\"\n",
WABT_PRINTF_STRING_VIEW_ARG(section_name));
if (options_->mode == ObjdumpMode::Headers) {
@@ -1192,7 +1199,7 @@ Result BinaryReaderObjdump::BeginSection(Index section_index,
// custom sections, |section_name| is "Custom", but |match_name| is the name
// of the custom section.
const char* section_name = wabt::GetSectionName(section_code);
- std::string match_name = GetSectionName(section_index).to_string();
+ std::string match_name(GetSectionName(section_index));
bool section_match = !options_->section_name ||
!strcasecmp(options_->section_name, match_name.c_str());
@@ -1418,8 +1425,8 @@ Result BinaryReaderObjdump::OnImportCount(Index count) {
}
Result BinaryReaderObjdump::OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) {
PrintDetails(" - func[%" PRIindex "] sig=%" PRIindex, func_index, sig_index);
@@ -1434,8 +1441,8 @@ Result BinaryReaderObjdump::OnImportFunc(Index import_index,
}
Result BinaryReaderObjdump::OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) {
@@ -1451,8 +1458,8 @@ Result BinaryReaderObjdump::OnImportTable(Index import_index,
}
Result BinaryReaderObjdump::OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) {
PrintDetails(" - memory[%" PRIindex "] pages: initial=%" PRId64, memory_index,
@@ -1473,8 +1480,8 @@ Result BinaryReaderObjdump::OnImportMemory(Index import_index,
}
Result BinaryReaderObjdump::OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) {
@@ -1487,8 +1494,8 @@ Result BinaryReaderObjdump::OnImportGlobal(Index import_index,
}
Result BinaryReaderObjdump::OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) {
PrintDetails(" - tag[%" PRIindex "] sig=%" PRIindex, tag_index, sig_index);
@@ -1549,7 +1556,7 @@ Result BinaryReaderObjdump::OnExportCount(Index count) {
Result BinaryReaderObjdump::OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) {
+ std::string_view name) {
PrintDetails(" - %s[%" PRIindex "]", GetKindName(kind), item_index);
if (kind == ExternalKind::Func) {
auto name = GetFunctionName(item_index);
@@ -1622,7 +1629,7 @@ Result BinaryReaderObjdump::OnGlobalCount(Index count) {
Result BinaryReaderObjdump::BeginGlobal(Index index, Type type, bool mutable_) {
PrintDetails(" - global[%" PRIindex "] %s mutable=%d", index,
type.GetName().c_str(), mutable_);
- string_view name = GetGlobalName(index);
+ std::string_view name = GetGlobalName(index);
if (!name.empty()) {
PrintDetails(" <" PRIstringview ">", WABT_PRINTF_STRING_VIEW_ARG(name));
}
@@ -1657,7 +1664,7 @@ void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) {
}
case InitExprType::Global: {
PrintDetails(" - init global=%" PRIindex, expr.value.index);
- string_view name = GetGlobalName(expr.value.index);
+ std::string_view name = GetGlobalName(expr.value.index);
if (!name.empty()) {
PrintDetails(" <" PRIstringview ">", WABT_PRINTF_STRING_VIEW_ARG(name));
}
@@ -1666,7 +1673,7 @@ void BinaryReaderObjdump::PrintInitExpr(const InitExpr& expr) {
}
case InitExprType::FuncRef: {
PrintDetails(" - init ref.func:%" PRIindex, expr.value.index);
- string_view name = GetFunctionName(expr.value.index);
+ std::string_view name = GetFunctionName(expr.value.index);
if (!name.empty()) {
PrintDetails(" <" PRIstringview ">", WABT_PRINTF_STRING_VIEW_ARG(name));
}
@@ -1769,13 +1776,13 @@ Result BinaryReaderObjdump::OnGlobalGetExpr(Index global_index) {
return Result::Ok;
}
-Result BinaryReaderObjdump::OnModuleName(string_view name) {
+Result BinaryReaderObjdump::OnModuleName(std::string_view name) {
PrintDetails(" - module <" PRIstringview ">\n",
WABT_PRINTF_STRING_VIEW_ARG(name));
return Result::Ok;
}
-Result BinaryReaderObjdump::OnFunctionName(Index index, string_view name) {
+Result BinaryReaderObjdump::OnFunctionName(Index index, std::string_view name) {
PrintDetails(" - func[%" PRIindex "] <" PRIstringview ">\n", index,
WABT_PRINTF_STRING_VIEW_ARG(name));
return Result::Ok;
@@ -1783,7 +1790,7 @@ Result BinaryReaderObjdump::OnFunctionName(Index index, string_view name) {
Result BinaryReaderObjdump::OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) {
+ std::string_view name) {
PrintDetails(" - %s[%" PRIindex "] <" PRIstringview ">\n",
GetNameSectionSubsectionName(type), index,
WABT_PRINTF_STRING_VIEW_ARG(name));
@@ -1792,7 +1799,7 @@ Result BinaryReaderObjdump::OnNameEntry(NameSectionSubsection type,
Result BinaryReaderObjdump::OnLocalName(Index func_index,
Index local_index,
- string_view name) {
+ std::string_view name) {
if (!name.empty()) {
PrintDetails(" - func[%" PRIindex "] local[%" PRIindex "] <" PRIstringview
">\n",
@@ -1889,13 +1896,14 @@ Result BinaryReaderObjdump::OnDylinkExportCount(Index count) {
return Result::Ok;
}
-Result BinaryReaderObjdump::OnDylinkExport(string_view name, uint32_t flags) {
+Result BinaryReaderObjdump::OnDylinkExport(std::string_view name,
+ uint32_t flags) {
PrintDetails(" - " PRIstringview, WABT_PRINTF_STRING_VIEW_ARG(name));
return PrintSymbolFlags(flags);
}
-Result BinaryReaderObjdump::OnDylinkImport(string_view module,
- string_view name,
+Result BinaryReaderObjdump::OnDylinkImport(std::string_view module,
+ std::string_view name,
uint32_t flags) {
PrintDetails(" - " PRIstringview "." PRIstringview,
WABT_PRINTF_STRING_VIEW_ARG(module),
@@ -1903,7 +1911,7 @@ Result BinaryReaderObjdump::OnDylinkImport(string_view module,
return PrintSymbolFlags(flags);
}
-Result BinaryReaderObjdump::OnDylinkNeeded(string_view so_name) {
+Result BinaryReaderObjdump::OnDylinkNeeded(std::string_view so_name) {
PrintDetails(" - " PRIstringview "\n", WABT_PRINTF_STRING_VIEW_ARG(so_name));
return Result::Ok;
}
@@ -1945,7 +1953,7 @@ Result BinaryReaderObjdump::OnReloc(RelocType type,
return Result::Ok;
}
-Result BinaryReaderObjdump::OnFeature(uint8_t prefix, string_view name) {
+Result BinaryReaderObjdump::OnFeature(uint8_t prefix, std::string_view name) {
PrintDetails(" - [%c] " PRIstringview "\n", prefix,
WABT_PRINTF_STRING_VIEW_ARG(name));
return Result::Ok;
@@ -2042,7 +2050,7 @@ Result BinaryReaderObjdump::PrintSegmentFlags(uint32_t flags) {
Result BinaryReaderObjdump::OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) {
@@ -2056,7 +2064,7 @@ Result BinaryReaderObjdump::OnDataSymbol(Index index,
Result BinaryReaderObjdump::OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index func_index) {
if (name.empty()) {
name = GetFunctionName(func_index);
@@ -2068,7 +2076,7 @@ Result BinaryReaderObjdump::OnFunctionSymbol(Index index,
Result BinaryReaderObjdump::OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) {
if (name.empty()) {
name = GetGlobalName(global_index);
@@ -2090,7 +2098,7 @@ Result BinaryReaderObjdump::OnSectionSymbol(Index index,
Result BinaryReaderObjdump::OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) {
if (name.empty()) {
name = GetTagName(tag_index);
@@ -2102,7 +2110,7 @@ Result BinaryReaderObjdump::OnTagSymbol(Index index,
Result BinaryReaderObjdump::OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index table_index) {
if (name.empty()) {
name = GetTableName(table_index);
@@ -2118,7 +2126,7 @@ Result BinaryReaderObjdump::OnSegmentInfoCount(Index count) {
}
Result BinaryReaderObjdump::OnSegmentInfo(Index index,
- string_view name,
+ std::string_view name,
Address alignment_log2,
uint32_t flags) {
PrintDetails(" - %d: " PRIstringview " p2align=%" PRIaddress, index,
@@ -2141,7 +2149,7 @@ Result BinaryReaderObjdump::OnComdatCount(Index count) {
return Result::Ok;
}
-Result BinaryReaderObjdump::OnComdatBegin(string_view name,
+Result BinaryReaderObjdump::OnComdatBegin(std::string_view name,
uint32_t flags,
Index count) {
PrintDetails(" - " PRIstringview ": [count=%d]\n",
@@ -2186,30 +2194,30 @@ Result BinaryReaderObjdump::OnTagType(Index index, Index sig_index) {
} // end anonymous namespace
-string_view ObjdumpNames::Get(Index index) const {
+std::string_view ObjdumpNames::Get(Index index) const {
auto iter = names.find(index);
if (iter == names.end())
- return string_view();
+ return std::string_view();
return iter->second;
}
-void ObjdumpNames::Set(Index index, string_view name) {
- names[index] = name.to_string();
+void ObjdumpNames::Set(Index index, std::string_view name) {
+ names[index] = std::string(name);
}
-string_view ObjdumpLocalNames::Get(Index function_index,
- Index local_index) const {
+std::string_view ObjdumpLocalNames::Get(Index function_index,
+ Index local_index) const {
auto iter = names.find(std::pair<Index, Index>(function_index, local_index));
if (iter == names.end())
- return string_view();
+ return std::string_view();
return iter->second;
}
void ObjdumpLocalNames::Set(Index function_index,
Index local_index,
- string_view name) {
+ std::string_view name) {
names[std::pair<Index, Index>(function_index, local_index)] =
- name.to_string();
+ std::string(name);
}
Result ReadBinaryObjdump(const uint8_t* data,
diff --git a/src/binary-reader-objdump.h b/src/binary-reader-objdump.h
index 107b758d..43f34a1e 100644
--- a/src/binary-reader-objdump.h
+++ b/src/binary-reader-objdump.h
@@ -58,15 +58,15 @@ struct ObjdumpSymbol {
};
struct ObjdumpNames {
- string_view Get(Index index) const;
- void Set(Index index, string_view name);
+ std::string_view Get(Index index) const;
+ void Set(Index index, std::string_view name);
std::map<Index, std::string> names;
};
struct ObjdumpLocalNames {
- string_view Get(Index function_index, Index local_index) const;
- void Set(Index function_index, Index local_index, string_view name);
+ std::string_view Get(Index function_index, Index local_index) const;
+ void Set(Index function_index, Index local_index, std::string_view name);
std::map<std::pair<Index, Index>, std::string> names;
};
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index c584b018..0cef458d 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -103,7 +103,7 @@ class BinaryReader {
Result ReadRefType(Type* out_value, const char* desc) WABT_WARN_UNUSED;
Result ReadExternalKind(ExternalKind* out_value,
const char* desc) WABT_WARN_UNUSED;
- Result ReadStr(string_view* out_str, const char* desc) WABT_WARN_UNUSED;
+ Result ReadStr(std::string_view* out_str, const char* desc) WABT_WARN_UNUSED;
Result ReadBytes(const void** out_data,
Address* out_data_size,
const char* desc) WABT_WARN_UNUSED;
@@ -356,14 +356,14 @@ Result BinaryReader::ReadExternalKind(ExternalKind* out_value,
return Result::Ok;
}
-Result BinaryReader::ReadStr(string_view* out_str, const char* desc) {
+Result BinaryReader::ReadStr(std::string_view* out_str, const char* desc) {
uint32_t str_len = 0;
CHECK_RESULT(ReadU32Leb128(&str_len, "string length"));
ERROR_UNLESS(state_.offset + str_len <= read_end_,
"unable to read string: %s", desc);
- *out_str = string_view(
+ *out_str = std::string_view(
reinterpret_cast<const char*>(state_.data) + state_.offset, str_len);
state_.offset += str_len;
@@ -1815,7 +1815,7 @@ Result BinaryReader::ReadNameSection(Offset section_size) {
case NameSectionSubsection::Module:
CALLBACK(OnModuleNameSubsection, i, name_type, subsection_size);
if (subsection_size) {
- string_view name;
+ std::string_view name;
CHECK_RESULT(ReadStr(&name, "module name"));
CALLBACK(OnModuleName, name);
}
@@ -1830,7 +1830,7 @@ Result BinaryReader::ReadNameSection(Offset section_size) {
for (Index j = 0; j < num_names; ++j) {
Index function_index;
- string_view function_name;
+ std::string_view function_name;
CHECK_RESULT(ReadIndex(&function_index, "function index"));
ERROR_UNLESS(function_index != last_function_index,
@@ -1869,7 +1869,7 @@ Result BinaryReader::ReadNameSection(Offset section_size) {
Index last_local_index = kInvalidIndex;
for (Index k = 0; k < num_locals; ++k) {
Index local_index;
- string_view local_name;
+ std::string_view local_name;
CHECK_RESULT(ReadIndex(&local_index, "named index"));
ERROR_UNLESS(local_index != last_local_index,
@@ -1902,7 +1902,7 @@ Result BinaryReader::ReadNameSection(Offset section_size) {
CALLBACK(OnNameCount, num_names);
for (Index j = 0; j < num_names; ++j) {
Index index;
- string_view name;
+ std::string_view name;
CHECK_RESULT(ReadIndex(&index, "index"));
CHECK_RESULT(ReadStr(&name, "name"));
@@ -2012,7 +2012,7 @@ Result BinaryReader::ReadDylink0Section(Offset section_size) {
CHECK_RESULT(ReadU32Leb128(&count, "needed_dynlibs"));
CALLBACK(OnDylinkNeededCount, count);
while (count--) {
- string_view so_name;
+ std::string_view so_name;
CHECK_RESULT(ReadStr(&so_name, "dylib so_name"));
CALLBACK(OnDylinkNeeded, so_name);
}
@@ -2022,8 +2022,8 @@ Result BinaryReader::ReadDylink0Section(Offset section_size) {
CALLBACK(OnDylinkImportCount, count);
for (Index i = 0; i < count; ++i) {
uint32_t flags = 0;
- string_view module;
- string_view field;
+ std::string_view module;
+ std::string_view field;
CHECK_RESULT(ReadStr(&module, "module"));
CHECK_RESULT(ReadStr(&field, "field"));
CHECK_RESULT(ReadU32Leb128(&flags, "flags"));
@@ -2035,7 +2035,7 @@ Result BinaryReader::ReadDylink0Section(Offset section_size) {
CALLBACK(OnDylinkExportCount, count);
for (Index i = 0; i < count; ++i) {
uint32_t flags = 0;
- string_view name;
+ std::string_view name;
CHECK_RESULT(ReadStr(&name, "name"));
CHECK_RESULT(ReadU32Leb128(&flags, "flags"));
CALLBACK(OnDylinkExport, name, flags);
@@ -2072,7 +2072,7 @@ Result BinaryReader::ReadDylinkSection(Offset section_size) {
CHECK_RESULT(ReadU32Leb128(&count, "needed_dynlibs"));
CALLBACK(OnDylinkNeededCount, count);
while (count--) {
- string_view so_name;
+ std::string_view so_name;
CHECK_RESULT(ReadStr(&so_name, "dylib so_name"));
CALLBACK(OnDylinkNeeded, so_name);
}
@@ -2088,7 +2088,7 @@ Result BinaryReader::ReadTargetFeaturesSections(Offset section_size) {
CALLBACK(OnFeatureCount, count);
while (count--) {
uint8_t prefix;
- string_view name;
+ std::string_view name;
CHECK_RESULT(ReadU8(&prefix, "prefix"));
CHECK_RESULT(ReadStr(&name, "feature name"));
CALLBACK(OnFeature, prefix, name);
@@ -2119,7 +2119,7 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) {
CHECK_RESULT(ReadU32Leb128(&count, "sym count"));
CALLBACK(OnSymbolCount, count);
for (Index i = 0; i < count; ++i) {
- string_view name;
+ std::string_view name;
uint32_t flags = 0;
uint32_t kind = 0;
CHECK_RESULT(ReadU32Leb128(&kind, "sym type"));
@@ -2179,7 +2179,7 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) {
CHECK_RESULT(ReadU32Leb128(&count, "info count"));
CALLBACK(OnSegmentInfoCount, count);
for (Index i = 0; i < count; i++) {
- string_view name;
+ std::string_view name;
Address alignment_log2;
uint32_t flags;
CHECK_RESULT(ReadStr(&name, "segment name"));
@@ -2205,7 +2205,7 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) {
while (count--) {
uint32_t flags;
uint32_t entry_count;
- string_view name;
+ std::string_view name;
CHECK_RESULT(ReadStr(&name, "comdat name"));
CHECK_RESULT(ReadU32Leb128(&flags, "flags"));
CHECK_RESULT(ReadU32Leb128(&entry_count, "entry count"));
@@ -2260,7 +2260,7 @@ Result BinaryReader::ReadTagSection(Offset section_size) {
Result BinaryReader::ReadCustomSection(Index section_index,
Offset section_size) {
- string_view section_name;
+ std::string_view section_name;
CHECK_RESULT(ReadStr(&section_name, "section name"));
CALLBACK(BeginCustomSection, section_index, section_size, section_name);
ValueRestoreGuard<bool, &BinaryReader::reading_custom_section_> guard(this);
@@ -2384,9 +2384,9 @@ Result BinaryReader::ReadImportSection(Offset section_size) {
CHECK_RESULT(ReadCount(&num_imports, "import count"));
CALLBACK(OnImportCount, num_imports);
for (Index i = 0; i < num_imports; ++i) {
- string_view module_name;
+ std::string_view module_name;
CHECK_RESULT(ReadStr(&module_name, "import module name"));
- string_view field_name;
+ std::string_view field_name;
CHECK_RESULT(ReadStr(&field_name, "import field name"));
uint8_t kind;
@@ -2525,7 +2525,7 @@ Result BinaryReader::ReadExportSection(Offset section_size) {
CHECK_RESULT(ReadCount(&num_exports, "export count"));
CALLBACK(OnExportCount, num_exports);
for (Index i = 0; i < num_exports; ++i) {
- string_view name;
+ std::string_view name;
CHECK_RESULT(ReadStr(&name, "export item name"));
ExternalKind kind;
diff --git a/src/binary-reader.h b/src/binary-reader.h
index 10602e7c..978ce2f5 100644
--- a/src/binary-reader.h
+++ b/src/binary-reader.h
@@ -19,13 +19,13 @@
#include <stddef.h>
#include <stdint.h>
+#include <string_view>
#include "src/binary.h"
#include "src/common.h"
#include "src/error.h"
#include "src/feature.h"
#include "src/opcode.h"
-#include "src/string-view.h"
namespace wabt {
@@ -85,7 +85,7 @@ class BinaryReaderDelegate {
/* Custom section */
virtual Result BeginCustomSection(Index section_index,
Offset size,
- string_view section_name) = 0;
+ std::string_view section_name) = 0;
virtual Result EndCustomSection() = 0;
/* Type section */
@@ -107,33 +107,33 @@ class BinaryReaderDelegate {
virtual Result OnImportCount(Index count) = 0;
virtual Result OnImport(Index index,
ExternalKind kind,
- string_view module_name,
- string_view field_name) = 0;
+ std::string_view module_name,
+ std::string_view field_name) = 0;
virtual Result OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) = 0;
virtual Result OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) = 0;
virtual Result OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) = 0;
virtual Result OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) = 0;
virtual Result OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) = 0;
virtual Result EndImportSection() = 0;
@@ -173,7 +173,7 @@ class BinaryReaderDelegate {
virtual Result OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) = 0;
+ std::string_view name) = 0;
virtual Result EndExportSection() = 0;
/* Start section */
@@ -357,13 +357,13 @@ class BinaryReaderDelegate {
virtual Result OnModuleNameSubsection(Index index,
uint32_t name_type,
Offset subsection_size) = 0;
- virtual Result OnModuleName(string_view name) = 0;
+ virtual Result OnModuleName(std::string_view name) = 0;
virtual Result OnFunctionNameSubsection(Index index,
uint32_t name_type,
Offset subsection_size) = 0;
virtual Result OnFunctionNamesCount(Index num_functions) = 0;
virtual Result OnFunctionName(Index function_index,
- string_view function_name) = 0;
+ std::string_view function_name) = 0;
virtual Result OnLocalNameSubsection(Index index,
uint32_t name_type,
Offset subsection_size) = 0;
@@ -372,14 +372,14 @@ class BinaryReaderDelegate {
Index num_locals) = 0;
virtual Result OnLocalName(Index function_index,
Index local_index,
- string_view local_name) = 0;
+ std::string_view local_name) = 0;
virtual Result OnNameSubsection(Index index,
NameSectionSubsection subsection_type,
Offset subsection_size) = 0;
virtual Result OnNameCount(Index num_names) = 0;
virtual Result OnNameEntry(NameSectionSubsection type,
Index index,
- string_view name) = 0;
+ std::string_view name) = 0;
virtual Result EndNamesSection() = 0;
/* Reloc section */
@@ -399,18 +399,18 @@ class BinaryReaderDelegate {
uint32_t table_align_log2) = 0;
virtual Result OnDylinkImportCount(Index count) = 0;
virtual Result OnDylinkExportCount(Index count) = 0;
- virtual Result OnDylinkImport(string_view module,
- string_view name,
+ virtual Result OnDylinkImport(std::string_view module,
+ std::string_view name,
uint32_t flags) = 0;
- virtual Result OnDylinkExport(string_view name, uint32_t flags) = 0;
+ virtual Result OnDylinkExport(std::string_view name, uint32_t flags) = 0;
virtual Result OnDylinkNeededCount(Index count) = 0;
- virtual Result OnDylinkNeeded(string_view so_name) = 0;
+ virtual Result OnDylinkNeeded(std::string_view so_name) = 0;
virtual Result EndDylinkSection() = 0;
/* target_features section */
virtual Result BeginTargetFeaturesSection(Offset size) = 0;
virtual Result OnFeatureCount(Index count) = 0;
- virtual Result OnFeature(uint8_t prefix, string_view name) = 0;
+ virtual Result OnFeature(uint8_t prefix, std::string_view name) = 0;
virtual Result EndTargetFeaturesSection() = 0;
/* Linking section */
@@ -418,38 +418,38 @@ class BinaryReaderDelegate {
virtual Result OnSymbolCount(Index count) = 0;
virtual Result OnDataSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index segment,
uint32_t offset,
uint32_t size) = 0;
virtual Result OnFunctionSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index function_index) = 0;
virtual Result OnGlobalSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index global_index) = 0;
virtual Result OnSectionSymbol(Index index,
uint32_t flags,
Index section_index) = 0;
virtual Result OnTagSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index tag_index) = 0;
virtual Result OnTableSymbol(Index index,
uint32_t flags,
- string_view name,
+ std::string_view name,
Index table_index) = 0;
virtual Result OnSegmentInfoCount(Index count) = 0;
virtual Result OnSegmentInfo(Index index,
- string_view name,
+ std::string_view name,
Address alignment_log2,
uint32_t flags) = 0;
virtual Result OnInitFunctionCount(Index count) = 0;
virtual Result OnInitFunction(uint32_t priority, Index function_index) = 0;
virtual Result OnComdatCount(Index count) = 0;
- virtual Result OnComdatBegin(string_view name,
+ virtual Result OnComdatBegin(std::string_view name,
uint32_t flags,
Index count) = 0;
virtual Result OnComdatEntry(ComdatType kind, Index index) = 0;
diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc
index 96a2773b..97388e9b 100644
--- a/src/binary-writer-spec.cc
+++ b/src/binary-writer-spec.cc
@@ -18,6 +18,7 @@
#include <cassert>
#include <cinttypes>
+#include <string_view>
#include "config.h"
@@ -28,7 +29,6 @@
#include "src/ir.h"
#include "src/literal.h"
#include "src/stream.h"
-#include "src/string-view.h"
namespace wabt {
@@ -38,8 +38,8 @@ class BinaryWriterSpec {
public:
BinaryWriterSpec(Stream* json_stream,
WriteBinarySpecStreamFactory module_stream_factory,
- string_view source_filename,
- string_view module_filename_noext,
+ std::string_view source_filename,
+ std::string_view module_filename_noext,
const WriteBinaryOptions& options);
Result WriteScript(const Script& script);
@@ -49,7 +49,7 @@ class BinaryWriterSpec {
void WriteString(const char* s);
void WriteKey(const char* key);
void WriteSeparator();
- void WriteEscapedString(string_view);
+ void WriteEscapedString(std::string_view);
void WriteCommandType(const Command& command);
void WriteLocation(const Location& loc);
void WriteVar(const Var& var);
@@ -61,10 +61,10 @@ class BinaryWriterSpec {
void WriteConstVector(const ConstVector& consts);
void WriteAction(const Action& action);
void WriteActionResultType(const Action& action);
- void WriteModule(string_view filename, const Module& module);
- void WriteScriptModule(string_view filename,
+ void WriteModule(std::string_view filename, const Module& module);
+ void WriteScriptModule(std::string_view filename,
const ScriptModule& script_module);
- void WriteInvalidModule(const ScriptModule& module, string_view text);
+ void WriteInvalidModule(const ScriptModule& module, std::string_view text);
void WriteCommands();
const Script* script_ = nullptr;
@@ -80,8 +80,8 @@ class BinaryWriterSpec {
BinaryWriterSpec::BinaryWriterSpec(
Stream* json_stream,
WriteBinarySpecStreamFactory module_stream_factory,
- string_view source_filename,
- string_view module_filename_noext,
+ std::string_view source_filename,
+ std::string_view module_filename_noext,
const WriteBinaryOptions& options)
: json_stream_(json_stream),
module_stream_factory_(module_stream_factory),
@@ -110,7 +110,7 @@ void BinaryWriterSpec::WriteSeparator() {
json_stream_->Writef(", ");
}
-void BinaryWriterSpec::WriteEscapedString(string_view s) {
+void BinaryWriterSpec::WriteEscapedString(std::string_view s) {
json_stream_->WriteChar('"');
for (size_t i = 0; i < s.length(); ++i) {
uint8_t c = s[i];
@@ -381,12 +381,13 @@ void BinaryWriterSpec::WriteActionResultType(const Action& action) {
json_stream_->Writef("]");
}
-void BinaryWriterSpec::WriteModule(string_view filename, const Module& module) {
+void BinaryWriterSpec::WriteModule(std::string_view filename,
+ const Module& module) {
result_ |=
WriteBinaryModule(module_stream_factory_(filename), &module, options_);
}
-void BinaryWriterSpec::WriteScriptModule(string_view filename,
+void BinaryWriterSpec::WriteScriptModule(std::string_view filename,
const ScriptModule& script_module) {
switch (script_module.type()) {
case ScriptModuleType::Text:
@@ -406,7 +407,7 @@ void BinaryWriterSpec::WriteScriptModule(string_view filename,
}
void BinaryWriterSpec::WriteInvalidModule(const ScriptModule& module,
- string_view text) {
+ std::string_view text) {
const char* extension = "";
const char* module_type = "";
switch (module.type()) {
@@ -609,8 +610,8 @@ Result BinaryWriterSpec::WriteScript(const Script& script) {
Result WriteBinarySpecScript(Stream* json_stream,
WriteBinarySpecStreamFactory module_stream_factory,
Script* script,
- string_view source_filename,
- string_view module_filename_noext,
+ std::string_view source_filename,
+ std::string_view module_filename_noext,
const WriteBinaryOptions& options) {
BinaryWriterSpec binary_writer_spec(json_stream, module_stream_factory,
source_filename, module_filename_noext,
@@ -621,13 +622,13 @@ Result WriteBinarySpecScript(Stream* json_stream,
Result WriteBinarySpecScript(
Stream* json_stream,
Script* script,
- string_view source_filename,
- string_view module_filename_noext,
+ std::string_view source_filename,
+ std::string_view module_filename_noext,
const WriteBinaryOptions& options,
std::vector<FilenameMemoryStreamPair>* out_module_streams,
Stream* log_stream) {
WriteBinarySpecStreamFactory module_stream_factory =
- [&](string_view filename) {
+ [&](std::string_view filename) {
out_module_streams->emplace_back(filename,
MakeUnique<MemoryStream>(log_stream));
return out_module_streams->back().stream.get();
diff --git a/src/binary-writer-spec.h b/src/binary-writer-spec.h
index 197d6f2c..65c2460a 100644
--- a/src/binary-writer-spec.h
+++ b/src/binary-writer-spec.h
@@ -28,29 +28,29 @@
namespace wabt {
struct FilenameMemoryStreamPair {
- FilenameMemoryStreamPair(string_view filename,
+ FilenameMemoryStreamPair(std::string_view filename,
std::unique_ptr<MemoryStream> stream)
: filename(filename), stream(std::move(stream)) {}
std::string filename;
std::unique_ptr<MemoryStream> stream;
};
-typedef std::function<Stream*(string_view filename)>
+typedef std::function<Stream*(std::string_view filename)>
WriteBinarySpecStreamFactory;
Result WriteBinarySpecScript(Stream* json_stream,
WriteBinarySpecStreamFactory module_stream_factory,
Script*,
- string_view source_filename,
- string_view module_filename_noext,
+ std::string_view source_filename,
+ std::string_view module_filename_noext,
const WriteBinaryOptions&);
// Convenience function for producing MemoryStream outputs all modules.
Result WriteBinarySpecScript(
Stream* json_stream,
Script*,
- string_view source_filename,
- string_view module_filename_noext,
+ std::string_view source_filename,
+ std::string_view module_filename_noext,
const WriteBinaryOptions&,
std::vector<FilenameMemoryStreamPair>* out_module_streams,
Stream* log_stream = nullptr);
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index a633717f..76d0b765 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -22,6 +22,7 @@
#include <cstdint>
#include <cstdio>
#include <set>
+#include <string_view>
#include <vector>
#include "config.h"
@@ -31,7 +32,6 @@
#include "src/ir.h"
#include "src/leb128.h"
#include "src/stream.h"
-#include "src/string-view.h"
#define PRINT_HEADER_NO_INDEX -1
#define MAX_U32_LEB128_BYTES 5
@@ -39,7 +39,7 @@
namespace wabt {
void WriteStr(Stream* stream,
- string_view s,
+ std::string_view s,
const char* desc,
PrintChars print_chars) {
WriteU32Leb128(stream, s.length(), "string length");
@@ -81,8 +81,8 @@ void WriteLimits(Stream* stream, const Limits* limits) {
}
}
-void WriteDebugName(Stream* stream, string_view name, const char* desc) {
- string_view stripped_name = name;
+void WriteDebugName(Stream* stream, std::string_view name, const char* desc) {
+ std::string_view stripped_name = name;
if (!stripped_name.empty()) {
// Strip leading $ from name
assert(stripped_name.front() == '$');
@@ -140,7 +140,7 @@ class Symbol {
private:
SymbolType type_;
- string_view name_;
+ std::string_view name_;
uint8_t flags_;
union {
Function function_;
@@ -152,21 +152,21 @@ class Symbol {
};
public:
- Symbol(const string_view& name, uint8_t flags, const Function& f)
+ Symbol(const std::string_view& name, uint8_t flags, const Function& f)
: type_(Function::type), name_(name), flags_(flags), function_(f) {}
- Symbol(const string_view& name, uint8_t flags, const Data& d)
+ Symbol(const std::string_view& name, uint8_t flags, const Data& d)
: type_(Data::type), name_(name), flags_(flags), data_(d) {}
- Symbol(const string_view& name, uint8_t flags, const Global& g)
+ Symbol(const std::string_view& name, uint8_t flags, const Global& g)
: type_(Global::type), name_(name), flags_(flags), global_(g) {}
- Symbol(const string_view& name, uint8_t flags, const Section& s)
+ Symbol(const std::string_view& name, uint8_t flags, const Section& s)
: type_(Section::type), name_(name), flags_(flags), section_(s) {}
- Symbol(const string_view& name, uint8_t flags, const Tag& e)
+ Symbol(const std::string_view& name, uint8_t flags, const Tag& e)
: type_(Tag::type), name_(name), flags_(flags), tag_(e) {}
- Symbol(const string_view& name, uint8_t flags, const Table& t)
+ Symbol(const std::string_view& name, uint8_t flags, const Table& t)
: type_(Table::type), name_(name), flags_(flags), table_(t) {}
SymbolType type() const { return type_; }
- const string_view& name() const { return name_; }
+ const std::string_view& name() const { return name_; }
uint8_t flags() const { return flags_; }
SymbolVisibility visibility() const {
@@ -225,9 +225,9 @@ class SymbolTable {
std::vector<Index> tables_;
std::vector<Index> globals_;
- std::set<string_view> seen_names_;
+ std::set<std::string_view> seen_names_;
- Result EnsureUnique(const string_view& name) {
+ Result EnsureUnique(const std::string_view& name) {
if (seen_names_.count(name)) {
fprintf(stderr,
"error: duplicate symbol when writing relocatable "
@@ -241,7 +241,7 @@ class SymbolTable {
template <typename T>
Result AddSymbol(std::vector<Index>* map,
- string_view name,
+ std::string_view name,
bool imported,
bool exported,
T&& sym) {
@@ -251,7 +251,7 @@ class SymbolTable {
// Wabt currently has no way for a user to explicitly specify the name of
// an import, so never set the EXPLICIT_NAME flag, and ignore any display
// name fabricated by wabt.
- name = string_view();
+ name = std::string_view();
} else {
if (name.empty()) {
// Definitions without a name are local.
diff --git a/src/binary-writer.h b/src/binary-writer.h
index 4304a0a7..158ed2d3 100644
--- a/src/binary-writer.h
+++ b/src/binary-writer.h
@@ -49,7 +49,7 @@ Result WriteBinaryModule(Stream*, const Module*, const WriteBinaryOptions&);
void WriteType(Stream* stream, Type type, const char* desc = nullptr);
void WriteStr(Stream* stream,
- string_view s,
+ std::string_view s,
const char* desc,
PrintChars print_chars = PrintChars::No);
diff --git a/src/binding-hash.h b/src/binding-hash.h
index 07795270..1799ce54 100644
--- a/src/binding-hash.h
+++ b/src/binding-hash.h
@@ -19,11 +19,11 @@
#include <functional>
#include <string>
+#include <string_view>
#include <unordered_map>
#include <vector>
#include "src/common.h"
-#include "src/string-view.h"
namespace wabt {
@@ -54,8 +54,8 @@ class BindingHash : public std::unordered_multimap<std::string, Binding> {
return iter != end() ? iter->second.index : kInvalidIndex;
}
- Index FindIndex(string_view name) const {
- return FindIndex(name.to_string());
+ Index FindIndex(std::string_view name) const {
+ return FindIndex(std::string(name));
}
private:
diff --git a/src/c-writer.cc b/src/c-writer.cc
index 635334dd..c1336671 100644
--- a/src/c-writer.cc
+++ b/src/c-writer.cc
@@ -20,13 +20,14 @@
#include <cinttypes>
#include <map>
#include <set>
+#include <string_view>
#include "src/cast.h"
#include "src/common.h"
#include "src/ir.h"
#include "src/literal.h"
#include "src/stream.h"
-#include "src/string-view.h"
+#include "src/string-util.h"
#define INDENT_SIZE 2
@@ -162,20 +163,20 @@ class CWriter {
static char MangleType(Type);
static std::string MangleTypes(const TypeVector&);
static std::string MangleMultivalueTypes(const TypeVector&);
- static std::string MangleName(string_view);
- static std::string MangleFuncName(string_view,
+ static std::string MangleName(std::string_view);
+ static std::string MangleFuncName(std::string_view,
const TypeVector& param_types,
const TypeVector& result_types);
- static std::string MangleGlobalName(string_view, Type);
- static std::string LegalizeName(string_view);
- static std::string ExportName(string_view mangled_name);
- std::string DefineName(SymbolSet*, string_view);
+ static std::string MangleGlobalName(std::string_view, Type);
+ static std::string LegalizeName(std::string_view);
+ static std::string ExportName(std::string_view mangled_name);
+ std::string DefineName(SymbolSet*, std::string_view);
std::string DefineImportName(const std::string& name,
- string_view module_name,
- string_view mangled_field_name);
+ std::string_view module_name,
+ std::string_view mangled_field_name);
std::string DefineGlobalScopeName(const std::string&);
std::string DefineLocalScopeName(const std::string&);
- std::string DefineStackVarName(Index, Type, string_view);
+ std::string DefineStackVarName(Index, Type, std::string_view);
void Indent(int size = INDENT_SIZE);
void Dedent(int size = INDENT_SIZE);
@@ -203,7 +204,7 @@ class CWriter {
void Write(OpenBrace);
void Write(CloseBrace);
void Write(Index);
- void Write(string_view);
+ void Write(std::string_view);
void Write(const LocalName&);
void Write(const GlobalName&);
void Write(const ExternalPtr&);
@@ -417,7 +418,7 @@ std::string CWriter::MangleMultivalueTypes(const TypeVector& types) {
}
// static
-std::string CWriter::MangleName(string_view name) {
+std::string CWriter::MangleName(std::string_view name) {
const char kPrefix = 'Z';
std::string result = "Z_";
@@ -436,7 +437,7 @@ std::string CWriter::MangleName(string_view name) {
}
// static
-std::string CWriter::MangleFuncName(string_view name,
+std::string CWriter::MangleFuncName(std::string_view name,
const TypeVector& param_types,
const TypeVector& result_types) {
std::string sig = MangleTypes(result_types) + MangleTypes(param_types);
@@ -444,18 +445,18 @@ std::string CWriter::MangleFuncName(string_view name,
}
// static
-std::string CWriter::MangleGlobalName(string_view name, Type type) {
+std::string CWriter::MangleGlobalName(std::string_view name, Type type) {
std::string sig(1, MangleType(type));
return MangleName(name) + MangleName(sig);
}
// static
-std::string CWriter::ExportName(string_view mangled_name) {
- return "WASM_RT_ADD_PREFIX(" + mangled_name.to_string() + ")";
+std::string CWriter::ExportName(std::string_view mangled_name) {
+ return "WASM_RT_ADD_PREFIX(" + std::string(mangled_name) + ")";
}
// static
-std::string CWriter::LegalizeName(string_view name) {
+std::string CWriter::LegalizeName(std::string_view name) {
if (name.empty())
return "_";
@@ -473,7 +474,7 @@ std::string CWriter::LegalizeName(string_view name) {
return result;
}
-std::string CWriter::DefineName(SymbolSet* set, string_view name) {
+std::string CWriter::DefineName(SymbolSet* set, std::string_view name) {
std::string legal = LegalizeName(name);
if (set->find(legal) != set->end()) {
std::string base = legal + "_";
@@ -486,7 +487,7 @@ std::string CWriter::DefineName(SymbolSet* set, string_view name) {
return legal;
}
-string_view StripLeadingDollar(string_view name) {
+std::string_view StripLeadingDollar(std::string_view name) {
if (!name.empty() && name[0] == '$') {
name.remove_prefix(1);
}
@@ -494,9 +495,9 @@ string_view StripLeadingDollar(string_view name) {
}
std::string CWriter::DefineImportName(const std::string& name,
- string_view module,
- string_view mangled_field_name) {
- std::string mangled = MangleName(module) + mangled_field_name.to_string();
+ std::string_view module,
+ std::string_view mangled_field_name) {
+ std::string mangled = MangleName(module) + mangled_field_name;
import_syms_.insert(name);
global_syms_.insert(mangled);
global_sym_map_.insert(SymbolMap::value_type(name, mangled));
@@ -517,7 +518,7 @@ std::string CWriter::DefineLocalScopeName(const std::string& name) {
std::string CWriter::DefineStackVarName(Index index,
Type type,
- string_view name) {
+ std::string_view name) {
std::string unique = DefineName(&local_syms_, name);
StackTypePair stp = {index, type};
stack_var_sym_map_.insert(StackVarSymbolMap::value_type(stp, unique));
@@ -581,7 +582,7 @@ void CWriter::Write(Index index) {
Writef("%" PRIindex, index);
}
-void CWriter::Write(string_view s) {
+void CWriter::Write(std::string_view s) {
WriteData(s.data(), s.size());
}
diff --git a/src/common.cc b/src/common.cc
index 706a013f..a4c7a108 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -17,6 +17,7 @@
#include "src/common.h"
#include <cassert>
+#include <cerrno>
#include <climits>
#include <cstdint>
#include <cstdio>
@@ -76,8 +77,8 @@ static Result ReadStdin(std::vector<uint8_t>* out_data) {
}
}
-Result ReadFile(string_view filename, std::vector<uint8_t>* out_data) {
- std::string filename_str = filename.to_string();
+Result ReadFile(std::string_view filename, std::vector<uint8_t>* out_data) {
+ std::string filename_str(filename);
const char* filename_cstr = filename_str.c_str();
if (filename == "-") {
diff --git a/src/common.h b/src/common.h
index 505ec950..bcd17039 100644
--- a/src/common.h
+++ b/src/common.h
@@ -27,6 +27,7 @@
#include <cstring>
#include <memory>
#include <string>
+#include <string_view>
#include <type_traits>
#include <vector>
@@ -36,7 +37,6 @@
#include "src/make-unique.h"
#include "src/result.h"
#include "src/string-format.h"
-#include "src/string-view.h"
#include "src/type.h"
#define WABT_FATAL(...) fprintf(stderr, __VA_ARGS__), exit(1)
@@ -213,14 +213,17 @@ struct Location {
};
Location() : line(0), first_column(0), last_column(0) {}
- Location(string_view filename, int line, int first_column, int last_column)
+ Location(std::string_view filename,
+ int line,
+ int first_column,
+ int last_column)
: filename(filename),
line(line),
first_column(first_column),
last_column(last_column) {}
explicit Location(size_t offset) : offset(offset) {}
- string_view filename;
+ std::string_view filename;
union {
// For text files.
struct {
@@ -388,7 +391,7 @@ struct Limits {
enum { WABT_USE_NATURAL_ALIGNMENT = 0xFFFFFFFFFFFFFFFF };
-Result ReadFile(string_view filename, std::vector<uint8_t>* out_data);
+Result ReadFile(std::string_view filename, std::vector<uint8_t>* out_data);
void InitStdio();
diff --git a/src/decompiler-ls.h b/src/decompiler-ls.h
index ae692711..3e68dad3 100644
--- a/src/decompiler-ls.h
+++ b/src/decompiler-ls.h
@@ -18,6 +18,7 @@
#define WABT_DECOMPILER_LS_H_
#include "src/decompiler-ast.h"
+#include "src/string-util.h"
#include <map>
@@ -51,7 +52,7 @@ inline Type GetMemoryType(Type operand_type, Opcode opc) {
// from context, if not, we should probably represent that as a cast around
// the access, since it should not be part of the field type.
if (operand_type == Type::I32 || operand_type == Type::I64) {
- auto name = string_view(opc.GetName());
+ auto name = std::string_view(opc.GetName());
// FIXME: change into a new column in opcode.def instead?
auto is_unsigned = name.substr(name.size() - 2) == "_u";
switch (opc.GetMemorySize()) {
diff --git a/src/decompiler-naming.h b/src/decompiler-naming.h
index 155da009..91f841f8 100644
--- a/src/decompiler-naming.h
+++ b/src/decompiler-naming.h
@@ -26,7 +26,7 @@ namespace wabt {
inline void RenameToIdentifier(std::string& name,
Index i,
BindingHash& bh,
- const std::set<string_view>* filter) {
+ const std::set<std::string_view>* filter) {
// Filter out non-identifier characters, and try to reduce the size of
// gigantic C++ signature names.
std::string s;
@@ -67,7 +67,8 @@ inline void RenameToIdentifier(std::string& name,
word_end--;
}
assert(word_end > word_start);
- auto word = string_view(s.c_str() + word_start, word_end - word_start);
+ auto word =
+ std::string_view(s.c_str() + word_start, word_end - word_start);
if (filter->find(word) != filter->end()) {
s.resize(word_start);
}
@@ -107,7 +108,7 @@ inline void RenameToIdentifier(std::string& name,
template <typename T>
void RenameToIdentifiers(std::vector<T*>& things,
BindingHash& bh,
- const std::set<string_view>* filter) {
+ const std::set<std::string_view>* filter) {
Index i = 0;
for (auto thing : things) {
RenameToIdentifier(thing->name, i++, bh, filter);
@@ -174,22 +175,10 @@ void RenameAll(Module& module) {
// We also filter common C++ keywords/STL idents that make for huge
// identifiers.
// FIXME: this can obviously give bad results if the input is not C++..
- std::set<string_view> filter = {
- { "const" },
- { "std" },
- { "allocator" },
- { "char" },
- { "basic" },
- { "traits" },
- { "wchar" },
- { "t" },
- { "void" },
- { "int" },
- { "unsigned" },
- { "2" },
- { "cxxabiv1" },
- { "short" },
- { "4096ul" },
+ std::set<std::string_view> filter = {
+ {"const"}, {"std"}, {"allocator"}, {"char"}, {"basic"},
+ {"traits"}, {"wchar"}, {"t"}, {"void"}, {"int"},
+ {"unsigned"}, {"2"}, {"cxxabiv1"}, {"short"}, {"4096ul"},
};
RenameToIdentifiers(module.funcs, module.func_bindings, &filter);
// Also do this for some other kinds of names, but without the keyword
diff --git a/src/decompiler.cc b/src/decompiler.cc
index 1dd28868..1ddaedc3 100644
--- a/src/decompiler.cc
+++ b/src/decompiler.cc
@@ -97,19 +97,19 @@ struct Decompiler {
return s;
}
- void IndentValue(Value& val, size_t amount, string_view first_indent) {
+ void IndentValue(Value& val, size_t amount, std::string_view first_indent) {
auto indent = Indent(amount);
for (auto& stat : val.v) {
auto is = (&stat != &val.v[0] || first_indent.empty())
- ? string_view(indent)
+ ? std::string_view(indent)
: first_indent;
stat.insert(0, is.data(), is.size());
}
}
Value WrapChild(Value& child,
- string_view prefix,
- string_view postfix,
+ std::string_view prefix,
+ std::string_view postfix,
Precedence precedence) {
auto width = prefix.size() + postfix.size() + child.width();
auto& v = child.v;
@@ -144,7 +144,7 @@ struct Decompiler {
}
Value WrapBinary(std::vector<Value>& args,
- string_view infix,
+ std::string_view infix,
bool indent_right,
Precedence precedence) {
assert(args.size() == 2);
@@ -169,8 +169,8 @@ struct Decompiler {
}
Value WrapNAry(std::vector<Value>& args,
- string_view prefix,
- string_view postfix,
+ std::string_view prefix,
+ std::string_view postfix,
Precedence precedence) {
size_t total_width = 0;
size_t max_width = 0;
@@ -200,7 +200,7 @@ struct Decompiler {
size_t i = 0;
for (auto& child : args) {
IndentValue(child, ident_with_name ? prefix.size() : indent_amount,
- !i && ident_with_name ? prefix : string_view{});
+ !i && ident_with_name ? prefix : std::string_view{});
if (i < args.size() - 1) {
child.v.back() += ",";
}
@@ -215,7 +215,7 @@ struct Decompiler {
}
}
- string_view VarName(string_view name) {
+ std::string_view VarName(std::string_view name) {
assert(!name.empty());
return name[0] == '$' ? name.substr(1) : name;
}
@@ -512,7 +512,7 @@ struct Decompiler {
}
multiline = multiline || width > target_exp_width;
if (multiline) {
- auto if_start = string_view("if (");
+ auto if_start = std::string_view("if (");
IndentValue(ifs, if_start.size(), if_start);
ifs.v.back() += ") {";
IndentValue(thenp, indent_amount, {});
@@ -663,7 +663,7 @@ struct Decompiler {
bool CheckImportExport(std::string& s,
ExternalKind kind,
Index index,
- string_view name) {
+ std::string_view name) {
// Figure out if this thing is imported, exported, or neither.
auto is_import = mc.module.IsImport(kind, Var(index));
// TODO: is this the best way to check for export?
diff --git a/src/emscripten-helpers.cc b/src/emscripten-helpers.cc
index f7c3b459..4f5a0c4a 100644
--- a/src/emscripten-helpers.cc
+++ b/src/emscripten-helpers.cc
@@ -178,9 +178,8 @@ WabtWriteScriptResult* wabt_write_binary_spec_script(
std::vector<wabt::FilenameMemoryStreamPair> module_streams;
wabt::MemoryStream json_stream(log_stream_p);
- std::string module_filename_noext =
- wabt::StripExtension(out_filename ? out_filename : source_filename)
- .to_string();
+ std::string module_filename_noext(
+ wabt::StripExtension(out_filename ? out_filename : source_filename));
WabtWriteScriptResult* result = new WabtWriteScriptResult();
result->result = WriteBinarySpecScript(&json_stream, script, source_filename,
diff --git a/src/error-formatter.cc b/src/error-formatter.cc
index 14c5d921..aa4995a5 100644
--- a/src/error-formatter.cc
+++ b/src/error-formatter.cc
@@ -33,7 +33,7 @@ std::string FormatError(const Error& error,
const Location& loc = error.loc;
if (!loc.filename.empty()) {
- result += loc.filename.to_string();
+ result += loc.filename;
result += ":";
}
diff --git a/src/error.h b/src/error.h
index cffca1e5..4f3375ab 100644
--- a/src/error.h
+++ b/src/error.h
@@ -18,10 +18,10 @@
#define WABT_ERROR_H_
#include <string>
+#include <string_view>
#include <vector>
#include "src/common.h"
-#include "src/string-view.h"
namespace wabt {
@@ -43,8 +43,8 @@ static WABT_INLINE const char* GetErrorLevelName(ErrorLevel error_level) {
class Error {
public:
Error() : error_level(ErrorLevel::Error) {}
- Error(ErrorLevel error_level, Location loc, string_view message)
- : error_level(error_level), loc(loc), message(message.to_string()) {}
+ Error(ErrorLevel error_level, Location loc, std::string_view message)
+ : error_level(error_level), loc(loc), message(message) {}
ErrorLevel error_level;
Location loc;
diff --git a/src/filenames.cc b/src/filenames.cc
index 989453c7..3cb6fd1c 100644
--- a/src/filenames.cc
+++ b/src/filenames.cc
@@ -22,32 +22,33 @@ const char* kWasmExtension = ".wasm";
const char* kWatExtension = ".wat";
-string_view StripExtension(string_view filename) {
+std::string_view StripExtension(std::string_view filename) {
return filename.substr(0, filename.find_last_of('.'));
}
-string_view GetBasename(string_view filename) {
+std::string_view GetBasename(std::string_view filename) {
size_t last_slash = filename.find_last_of('/');
size_t last_backslash = filename.find_last_of('\\');
- if (last_slash == string_view::npos && last_backslash == string_view::npos) {
+ if (last_slash == std::string_view::npos &&
+ last_backslash == std::string_view::npos) {
return filename;
}
- if (last_slash == string_view::npos) {
- if (last_backslash == string_view::npos) {
+ if (last_slash == std::string_view::npos) {
+ if (last_backslash == std::string_view::npos) {
return filename;
}
last_slash = last_backslash;
- } else if (last_backslash != string_view::npos) {
+ } else if (last_backslash != std::string_view::npos) {
last_slash = std::max(last_slash, last_backslash);
}
return filename.substr(last_slash + 1);
}
-string_view GetExtension(string_view filename) {
+std::string_view GetExtension(std::string_view filename) {
size_t pos = filename.find_last_of('.');
- if (pos == string_view::npos) {
+ if (pos == std::string_view::npos) {
return "";
}
return filename.substr(pos);
diff --git a/src/filenames.h b/src/filenames.h
index 87529aa2..dc4719e7 100644
--- a/src/filenames.h
+++ b/src/filenames.h
@@ -29,7 +29,7 @@ extern const char* kWatExtension;
// "foo.txt", => ".txt"
// "foo" => ""
// "/foo/bar/foo.wasm" => ".wasm"
-string_view GetExtension(string_view filename);
+std::string_view GetExtension(std::string_view filename);
// Strip extension, e.g.:
//
@@ -37,14 +37,14 @@ string_view GetExtension(string_view filename);
// "foo.bar" => "foo"
// "/path/to/foo.bar" => "/path/to/foo"
// "\\path\\to\\foo.bar" => "\\path\\to\\foo"
-string_view StripExtension(string_view s);
+std::string_view StripExtension(std::string_view s);
// Strip everything up to and including the last slash, e.g.:
//
// "/foo/bar/baz", => "baz"
// "/usr/local/include/stdio.h", => "stdio.h"
// "foo.bar", => "foo.bar"
-string_view GetBasename(string_view filename);
+std::string_view GetBasename(std::string_view filename);
} // namespace wabt
diff --git a/src/hash-util.cc b/src/hash-util.cc
deleted file mode 100644
index efb84270..00000000
--- a/src/hash-util.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2017 WebAssembly Community Group participants
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "src/hash-util.h"
-
-#include "config.h"
-
-namespace wabt {
-
-// Hash combiner from:
-// http://stackoverflow.com/questions/4948780/magic-number-in-boosthash-combine
-
-hash_code HashCombine(hash_code seed, hash_code y) {
-#if SIZEOF_SIZE_T == 4
- constexpr hash_code magic = 0x9e3779b9;
-#elif SIZEOF_SIZE_T == 8
- constexpr hash_code magic = 0x9e3779b97f4a7c16;
-#else
-#error "weird sizeof size_t"
-#endif
- seed ^= y + magic + (seed << 6) + (seed >> 2);
- return seed;
-}
-
-} // namespace wabt
diff --git a/src/hash-util.h b/src/hash-util.h
deleted file mode 100644
index 0a135d5e..00000000
--- a/src/hash-util.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2017 WebAssembly Community Group participants
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef WABT_HASH_UTIL_H_
-#define WABT_HASH_UTIL_H_
-
-#include <cstdlib>
-#include <functional>
-
-namespace wabt {
-
-typedef std::size_t hash_code;
-
-inline hash_code HashCombine() {
- return 0;
-}
-inline hash_code HashCombine(hash_code seed) {
- return seed;
-}
-hash_code HashCombine(hash_code x, hash_code y);
-
-template <typename T, typename... U>
-inline hash_code HashCombine(const T& first, const U&... rest) {
- return HashCombine(HashCombine(rest...), std::hash<T>()(first));
-}
-
-template <typename It>
-inline hash_code HashRange(It first, It last) {
- hash_code result = 0;
- for (auto iter = first; iter != last; ++iter) {
- result = HashCombine(result, *iter);
- }
- return result;
-}
-
-} // namespace wabt
-
-#endif // WABT_HASH_UTIL_H_
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc
index 25f4d84f..62803fc7 100644
--- a/src/interp/binary-reader-interp.cc
+++ b/src/interp/binary-reader-interp.cc
@@ -74,7 +74,7 @@ struct FixupMap {
class BinaryReaderInterp : public BinaryReaderNop {
public:
BinaryReaderInterp(ModuleDesc* module,
- string_view filename,
+ std::string_view filename,
Errors* errors,
const Features& features);
@@ -93,30 +93,30 @@ class BinaryReaderInterp : public BinaryReaderNop {
Type* result_types) override;
Result OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) override;
Result OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) override;
Result OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) override;
Result OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) override;
Result OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) override;
@@ -142,7 +142,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
Result OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) override;
+ std::string_view name) override;
Result OnStartFunction(Index func_index) override;
@@ -338,7 +338,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
std::vector<TagType> tag_types_; // Includes imported and defined.
static const Index kMemoryIndex0 = 0;
- string_view filename_;
+ std::string_view filename_;
};
Location BinaryReaderInterp::GetLocation() const {
@@ -368,7 +368,7 @@ void FixupMap::Resolve(Istream& istream, Index index) {
}
BinaryReaderInterp::BinaryReaderInterp(ModuleDesc* module,
- string_view filename,
+ std::string_view filename,
Errors* errors,
const Features& features)
: errors_(errors),
@@ -503,69 +503,69 @@ Result BinaryReaderInterp::OnFuncType(Index index,
}
Result BinaryReaderInterp::OnImportFunc(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index func_index,
Index sig_index) {
CHECK_RESULT(validator_.OnFunction(GetLocation(), Var(sig_index)));
FuncType& func_type = module_.func_types[sig_index];
module_.imports.push_back(ImportDesc{ImportType(
- module_name.to_string(), field_name.to_string(), func_type.Clone())});
+ std::string(module_name), std::string(field_name), func_type.Clone())});
func_types_.push_back(func_type);
return Result::Ok;
}
Result BinaryReaderInterp::OnImportTable(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index table_index,
Type elem_type,
const Limits* elem_limits) {
CHECK_RESULT(validator_.OnTable(GetLocation(), elem_type, *elem_limits));
TableType table_type{elem_type, *elem_limits};
module_.imports.push_back(ImportDesc{ImportType(
- module_name.to_string(), field_name.to_string(), table_type.Clone())});
+ std::string(module_name), std::string(field_name), table_type.Clone())});
table_types_.push_back(table_type);
return Result::Ok;
}
Result BinaryReaderInterp::OnImportMemory(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index memory_index,
const Limits* page_limits) {
CHECK_RESULT(validator_.OnMemory(GetLocation(), *page_limits));
MemoryType memory_type{*page_limits};
module_.imports.push_back(ImportDesc{ImportType(
- module_name.to_string(), field_name.to_string(), memory_type.Clone())});
+ std::string(module_name), std::string(field_name), memory_type.Clone())});
memory_types_.push_back(memory_type);
return Result::Ok;
}
Result BinaryReaderInterp::OnImportGlobal(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index global_index,
Type type,
bool mutable_) {
CHECK_RESULT(validator_.OnGlobalImport(GetLocation(), type, mutable_));
GlobalType global_type{type, ToMutability(mutable_)};
module_.imports.push_back(ImportDesc{ImportType(
- module_name.to_string(), field_name.to_string(), global_type.Clone())});
+ std::string(module_name), std::string(field_name), global_type.Clone())});
global_types_.push_back(global_type);
return Result::Ok;
}
Result BinaryReaderInterp::OnImportTag(Index import_index,
- string_view module_name,
- string_view field_name,
+ std::string_view module_name,
+ std::string_view field_name,
Index tag_index,
Index sig_index) {
CHECK_RESULT(validator_.OnTag(GetLocation(), Var(sig_index)));
FuncType& func_type = module_.func_types[sig_index];
TagType tag_type{TagAttr::Exception, func_type.params};
module_.imports.push_back(ImportDesc{ImportType(
- module_name.to_string(), field_name.to_string(), tag_type.Clone())});
+ std::string(module_name), std::string(field_name), tag_type.Clone())});
tag_types_.push_back(tag_type);
return Result::Ok;
}
@@ -669,7 +669,7 @@ Result BinaryReaderInterp::OnTagType(Index index, Index sig_index) {
Result BinaryReaderInterp::OnExport(Index index,
ExternalKind kind,
Index item_index,
- string_view name) {
+ std::string_view name) {
CHECK_RESULT(validator_.OnExport(GetLocation(), kind, Var(item_index), name));
std::unique_ptr<ExternType> type;
@@ -681,7 +681,7 @@ Result BinaryReaderInterp::OnExport(Index index,
case ExternalKind::Tag: type = tag_types_[item_index].Clone(); break;
}
module_.exports.push_back(
- ExportDesc{ExportType(name.to_string(), std::move(type)), item_index});
+ ExportDesc{ExportType(std::string(name), std::move(type)), item_index});
return Result::Ok;
}
@@ -1585,7 +1585,7 @@ Result BinaryReaderInterp::OnDelegateExpr(Index depth) {
} // namespace
-Result ReadBinaryInterp(string_view filename,
+Result ReadBinaryInterp(std::string_view filename,
const void* data,
size_t size,
const ReadBinaryOptions& options,
diff --git a/src/interp/binary-reader-interp.h b/src/interp/binary-reader-interp.h
index 82b946e7..b3b7e46d 100644
--- a/src/interp/binary-reader-interp.h
+++ b/src/interp/binary-reader-interp.h
@@ -27,7 +27,7 @@ struct ReadBinaryOptions;
namespace interp {
-Result ReadBinaryInterp(string_view filename,
+Result ReadBinaryInterp(std::string_view filename,
const void* data,
size_t size,
const ReadBinaryOptions& options,
diff --git a/src/interp/interp-util.cc b/src/interp/interp-util.cc
index 82895e67..b4f53ba9 100644
--- a/src/interp/interp-util.cc
+++ b/src/interp/interp-util.cc
@@ -92,7 +92,7 @@ void WriteTrap(Stream* stream, const char* desc, const Trap::Ptr& trap) {
}
void WriteCall(Stream* stream,
- string_view name,
+ std::string_view name,
const FuncType& func_type,
const Values& params,
const Values& results,
diff --git a/src/interp/interp-util.h b/src/interp/interp-util.h
index bc94abc2..fabe1ced 100644
--- a/src/interp/interp-util.h
+++ b/src/interp/interp-util.h
@@ -18,10 +18,10 @@
#define WABT_INTERP_UTIL_H_
#include <string>
+#include <string_view>
#include <vector>
#include "src/interp/interp.h"
-#include "src/string-view.h"
namespace wabt {
@@ -38,7 +38,7 @@ void WriteValues(Stream* stream, const ValueTypes&, const Values&);
void WriteTrap(Stream* stream, const char* desc, const Trap::Ptr&);
void WriteCall(Stream* stream,
- string_view name,
+ std::string_view name,
const FuncType& func_type,
const Values& params,
const Values& results,
diff --git a/src/interp/interp.h b/src/interp/interp.h
index 270228f5..aa397f04 100644
--- a/src/interp/interp.h
+++ b/src/interp/interp.h
@@ -22,6 +22,7 @@
#include <memory>
#include <set>
#include <string>
+#include <string_view>
#include <type_traits>
#include <vector>
@@ -30,7 +31,6 @@
#include "src/feature.h"
#include "src/opcode.h"
#include "src/result.h"
-#include "src/string-view.h"
#include "src/interp/istream.h"
diff --git a/src/ir.cc b/src/ir.cc
index 96629751..82bead38 100644
--- a/src/ir.cc
+++ b/src/ir.cc
@@ -107,7 +107,7 @@ bool FuncSignature::operator==(const FuncSignature& rhs) const {
return param_types == rhs.param_types && result_types == rhs.result_types;
}
-const Export* Module::GetExport(string_view name) const {
+const Export* Module::GetExport(std::string_view name) const {
Index index = export_bindings.FindIndex(name);
if (index >= exports.size()) {
return nullptr;
@@ -583,7 +583,7 @@ void MakeTypeBindingReverseMapping(
Var::Var(Index index, const Location& loc)
: loc(loc), type_(VarType::Index), index_(index) {}
-Var::Var(string_view name, const Location& loc)
+Var::Var(std::string_view name, const Location& loc)
: loc(loc), type_(VarType::Name), name_(name) {}
Var::Var(Var&& rhs) : Var(kInvalidIndex) {
@@ -630,8 +630,8 @@ void Var::set_name(std::string&& name) {
Construct(name_, std::move(name));
}
-void Var::set_name(string_view name) {
- set_name(name.to_string());
+void Var::set_name(std::string_view name) {
+ set_name(std::string(name));
}
void Var::Destroy() {
diff --git a/src/ir.h b/src/ir.h
index eee59a32..5974f64f 100644
--- a/src/ir.h
+++ b/src/ir.h
@@ -22,6 +22,7 @@
#include <cstdint>
#include <memory>
#include <string>
+#include <string_view>
#include <type_traits>
#include <vector>
@@ -29,7 +30,6 @@
#include "src/common.h"
#include "src/intrusive-list.h"
#include "src/opcode.h"
-#include "src/string-view.h"
namespace wabt {
@@ -42,7 +42,7 @@ enum class VarType {
struct Var {
explicit Var(Index index = kInvalidIndex, const Location& loc = Location());
- explicit Var(string_view name, const Location& loc = Location());
+ explicit Var(std::string_view name, const Location& loc = Location());
Var(Var&&);
Var(const Var&);
Var& operator=(const Var&);
@@ -64,7 +64,7 @@ struct Var {
void set_index(Index);
void set_name(std::string&&);
- void set_name(string_view);
+ void set_name(std::string_view);
Location loc;
@@ -239,9 +239,9 @@ class TypeEntry {
protected:
explicit TypeEntry(TypeEntryKind kind,
- string_view name = string_view(),
+ std::string_view name = std::string_view(),
const Location& loc = Location())
- : loc(loc), name(name.to_string()), kind_(kind) {}
+ : loc(loc), name(name), kind_(kind) {}
TypeEntryKind kind_;
};
@@ -252,7 +252,7 @@ class FuncType : public TypeEntry {
return entry->kind() == TypeEntryKind::Func;
}
- explicit FuncType(string_view name = string_view())
+ explicit FuncType(std::string_view name = std::string_view())
: TypeEntry(TypeEntryKind::Func, name) {}
Index GetNumParams() const { return sig.GetNumParams(); }
@@ -275,7 +275,7 @@ class StructType : public TypeEntry {
return entry->kind() == TypeEntryKind::Struct;
}
- explicit StructType(string_view name = string_view())
+ explicit StructType(std::string_view name = std::string_view())
: TypeEntry(TypeEntryKind::Struct) {}
std::vector<Field> fields;
@@ -287,7 +287,7 @@ class ArrayType : public TypeEntry {
return entry->kind() == TypeEntryKind::Array;
}
- explicit ArrayType(string_view name = string_view())
+ explicit ArrayType(std::string_view name = std::string_view())
: TypeEntry(TypeEntryKind::Array) {}
Field field;
@@ -759,7 +759,7 @@ class AtomicFenceExpr : public ExprMixin<ExprType::AtomicFence> {
};
struct Tag {
- explicit Tag(string_view name) : name(name.to_string()) {}
+ explicit Tag(std::string_view name) : name(name) {}
std::string name;
FuncDeclaration decl;
@@ -827,7 +827,7 @@ inline bool operator!=(const LocalTypes::const_iterator& lhs,
}
struct Func {
- explicit Func(string_view name) : name(name.to_string()) {}
+ explicit Func(std::string_view name) : name(name) {}
Type GetParamType(Index index) const { return decl.GetParamType(index); }
Type GetResultType(Index index) const { return decl.GetResultType(index); }
@@ -849,7 +849,7 @@ struct Func {
};
struct Global {
- explicit Global(string_view name) : name(name.to_string()) {}
+ explicit Global(std::string_view name) : name(name) {}
std::string name;
Type type = Type::Void;
@@ -858,8 +858,8 @@ struct Global {
};
struct Table {
- explicit Table(string_view name)
- : name(name.to_string()), elem_type(Type::FuncRef) {}
+ explicit Table(std::string_view name)
+ : name(name), elem_type(Type::FuncRef) {}
std::string name;
Limits elem_limits;
@@ -869,7 +869,7 @@ struct Table {
typedef std::vector<ExprList> ExprListVector;
struct ElemSegment {
- explicit ElemSegment(string_view name) : name(name.to_string()) {}
+ explicit ElemSegment(std::string_view name) : name(name) {}
uint8_t GetFlags(const Module*) const;
SegmentKind kind = SegmentKind::Active;
@@ -881,14 +881,14 @@ struct ElemSegment {
};
struct Memory {
- explicit Memory(string_view name) : name(name.to_string()) {}
+ explicit Memory(std::string_view name) : name(name) {}
std::string name;
Limits page_limits;
};
struct DataSegment {
- explicit DataSegment(string_view name) : name(name.to_string()) {}
+ explicit DataSegment(std::string_view name) : name(name) {}
uint8_t GetFlags(const Module*) const;
SegmentKind kind = SegmentKind::Active;
@@ -927,7 +927,7 @@ class ImportMixin : public Import {
class FuncImport : public ImportMixin<ExternalKind::Func> {
public:
- explicit FuncImport(string_view name = string_view())
+ explicit FuncImport(std::string_view name = std::string_view())
: ImportMixin<ExternalKind::Func>(), func(name) {}
Func func;
@@ -935,7 +935,7 @@ class FuncImport : public ImportMixin<ExternalKind::Func> {
class TableImport : public ImportMixin<ExternalKind::Table> {
public:
- explicit TableImport(string_view name = string_view())
+ explicit TableImport(std::string_view name = std::string_view())
: ImportMixin<ExternalKind::Table>(), table(name) {}
Table table;
@@ -943,7 +943,7 @@ class TableImport : public ImportMixin<ExternalKind::Table> {
class MemoryImport : public ImportMixin<ExternalKind::Memory> {
public:
- explicit MemoryImport(string_view name = string_view())
+ explicit MemoryImport(std::string_view name = std::string_view())
: ImportMixin<ExternalKind::Memory>(), memory(name) {}
Memory memory;
@@ -951,7 +951,7 @@ class MemoryImport : public ImportMixin<ExternalKind::Memory> {
class GlobalImport : public ImportMixin<ExternalKind::Global> {
public:
- explicit GlobalImport(string_view name = string_view())
+ explicit GlobalImport(std::string_view name = std::string_view())
: ImportMixin<ExternalKind::Global>(), global(name) {}
Global global;
@@ -959,7 +959,7 @@ class GlobalImport : public ImportMixin<ExternalKind::Global> {
class TagImport : public ImportMixin<ExternalKind::Tag> {
public:
- explicit TagImport(string_view name = string_view())
+ explicit TagImport(std::string_view name = std::string_view())
: ImportMixin<ExternalKind::Tag>(), tag(name) {}
Tag tag;
@@ -1017,7 +1017,7 @@ class ModuleFieldMixin : public ModuleField {
class FuncModuleField : public ModuleFieldMixin<ModuleFieldType::Func> {
public:
explicit FuncModuleField(const Location& loc = Location(),
- string_view name = string_view())
+ std::string_view name = std::string_view())
: ModuleFieldMixin<ModuleFieldType::Func>(loc), func(name) {}
Func func;
@@ -1026,7 +1026,7 @@ class FuncModuleField : public ModuleFieldMixin<ModuleFieldType::Func> {
class GlobalModuleField : public ModuleFieldMixin<ModuleFieldType::Global> {
public:
explicit GlobalModuleField(const Location& loc = Location(),
- string_view name = string_view())
+ std::string_view name = std::string_view())
: ModuleFieldMixin<ModuleFieldType::Global>(loc), global(name) {}
Global global;
@@ -1063,7 +1063,7 @@ class TypeModuleField : public ModuleFieldMixin<ModuleFieldType::Type> {
class TableModuleField : public ModuleFieldMixin<ModuleFieldType::Table> {
public:
explicit TableModuleField(const Location& loc = Location(),
- string_view name = string_view())
+ std::string_view name = std::string_view())
: ModuleFieldMixin<ModuleFieldType::Table>(loc), table(name) {}
Table table;
@@ -1073,7 +1073,7 @@ class ElemSegmentModuleField
: public ModuleFieldMixin<ModuleFieldType::ElemSegment> {
public:
explicit ElemSegmentModuleField(const Location& loc = Location(),
- string_view name = string_view())
+ std::string_view name = std::string_view())
: ModuleFieldMixin<ModuleFieldType::ElemSegment>(loc),
elem_segment(name) {}
@@ -1083,7 +1083,7 @@ class ElemSegmentModuleField
class MemoryModuleField : public ModuleFieldMixin<ModuleFieldType::Memory> {
public:
explicit MemoryModuleField(const Location& loc = Location(),
- string_view name = string_view())
+ std::string_view name = std::string_view())
: ModuleFieldMixin<ModuleFieldType::Memory>(loc), memory(name) {}
Memory memory;
@@ -1093,7 +1093,7 @@ class DataSegmentModuleField
: public ModuleFieldMixin<ModuleFieldType::DataSegment> {
public:
explicit DataSegmentModuleField(const Location& loc = Location(),
- string_view name = string_view())
+ std::string_view name = std::string_view())
: ModuleFieldMixin<ModuleFieldType::DataSegment>(loc),
data_segment(name) {}
@@ -1103,7 +1103,7 @@ class DataSegmentModuleField
class TagModuleField : public ModuleFieldMixin<ModuleFieldType::Tag> {
public:
explicit TagModuleField(const Location& loc = Location(),
- string_view name = string_view())
+ std::string_view name = std::string_view())
: ModuleFieldMixin<ModuleFieldType::Tag>(loc), tag(name) {}
Tag tag;
@@ -1135,7 +1135,7 @@ struct Module {
Index GetGlobalIndex(const Var&) const;
const Global* GetGlobal(const Var&) const;
Global* GetGlobal(const Var&);
- const Export* GetExport(string_view) const;
+ const Export* GetExport(std::string_view) const;
Tag* GetTag(const Var&) const;
Index GetTagIndex(const Var&) const;
const DataSegment* GetDataSegment(const Var&) const;
@@ -1356,7 +1356,7 @@ typedef ActionCommandBase<CommandType::Action> ActionCommand;
class RegisterCommand : public CommandMixin<CommandType::Register> {
public:
- RegisterCommand(string_view module_name, const Var& var)
+ RegisterCommand(std::string_view module_name, const Var& var)
: module_name(module_name), var(var) {}
std::string module_name;
diff --git a/src/literal.h b/src/literal.h
index b6982613..ff5b2550 100644
--- a/src/literal.h
+++ b/src/literal.h
@@ -75,6 +75,51 @@ Result ParseDouble(LiteralType literal_type,
const char* end,
uint64_t* out_bits);
+// Same as above but taking a string_view
+inline Result ParseInt8(std::string_view v,
+ uint8_t* out,
+ ParseIntType parse_type) {
+ return ParseInt8(v.data(), v.data() + v.size(), out, parse_type);
+}
+
+inline Result ParseInt16(std::string_view v,
+ uint16_t* out,
+ ParseIntType parse_type) {
+ return ParseInt16(v.data(), v.data() + v.size(), out, parse_type);
+}
+
+inline Result ParseInt32(std::string_view v,
+ uint32_t* out,
+ ParseIntType parse_type) {
+ return ParseInt32(v.data(), v.data() + v.size(), out, parse_type);
+}
+
+inline Result ParseInt64(std::string_view v,
+ uint64_t* out,
+ ParseIntType parse_type) {
+ return ParseInt64(v.data(), v.data() + v.size(), out, parse_type);
+}
+
+inline Result ParseUint64(std::string_view v, uint64_t* out) {
+ return ParseUint64(v.data(), v.data() + v.size(), out);
+}
+
+inline Result ParseUint128(std::string_view v, v128* out) {
+ return ParseUint128(v.data(), v.data() + v.size(), out);
+}
+
+inline Result ParseFloat(LiteralType literal_type,
+ std::string_view v,
+ uint32_t* out_bits) {
+ return ParseFloat(literal_type, v.data(), v.data() + v.size(), out_bits);
+}
+
+inline Result ParseDouble(LiteralType literal_type,
+ std::string_view v,
+ uint64_t* out_bits) {
+ return ParseDouble(literal_type, v.data(), v.data() + v.size(), out_bits);
+}
+
void WriteFloatHex(char* buffer, size_t size, uint32_t bits);
void WriteDoubleHex(char* buffer, size_t size, uint64_t bits);
void WriteUint128(char* buffer, size_t size, v128 bits);
diff --git a/src/shared-validator.cc b/src/shared-validator.cc
index b61f1dee..8932012e 100644
--- a/src/shared-validator.cc
+++ b/src/shared-validator.cc
@@ -199,9 +199,9 @@ Result SharedValidator::OnTag(const Location& loc, Var sig_var) {
Result SharedValidator::OnExport(const Location& loc,
ExternalKind kind,
Var item_var,
- string_view name) {
+ std::string_view name) {
Result result = Result::Ok;
- auto name_str = name.to_string();
+ auto name_str = std::string(name);
if (export_names_.find(name_str) != export_names_.end()) {
result |= PrintError(loc, "duplicate export \"" PRIstringview "\"",
WABT_PRINTF_STRING_VIEW_ARG(name));
diff --git a/src/shared-validator.h b/src/shared-validator.h
index 0f422a8b..c84503ec 100644
--- a/src/shared-validator.h
+++ b/src/shared-validator.h
@@ -83,7 +83,7 @@ class SharedValidator {
Result OnExport(const Location&,
ExternalKind,
Var item_var,
- string_view name);
+ std::string_view name);
Result OnStart(const Location&, Var func_var);
diff --git a/src/stream.cc b/src/stream.cc
index cf6d17f2..95a25b1c 100644
--- a/src/stream.cc
+++ b/src/stream.cc
@@ -132,8 +132,8 @@ void Stream::WriteMemoryDump(const void* start,
}
}
-Result OutputBuffer::WriteToFile(string_view filename) const {
- std::string filename_str = filename.to_string();
+Result OutputBuffer::WriteToFile(std::string_view filename) const {
+ std::string filename_str(filename);
FILE* file = fopen(filename_str.c_str(), "wb");
if (!file) {
ERROR("unable to open %s for writing\n", filename_str.c_str());
@@ -217,9 +217,9 @@ Result MemoryStream::TruncateImpl(size_t size) {
return Result::Ok;
}
-FileStream::FileStream(string_view filename, Stream* log_stream)
+FileStream::FileStream(std::string_view filename, Stream* log_stream)
: Stream(log_stream), file_(nullptr), offset_(0), should_close_(false) {
- std::string filename_str = filename.to_string();
+ std::string filename_str(filename);
file_ = fopen(filename_str.c_str(), "wb");
// TODO(binji): this is pretty cheesy, should come up with a better API.
diff --git a/src/stream.h b/src/stream.h
index 66582fa6..23652c2f 100644
--- a/src/stream.h
+++ b/src/stream.h
@@ -158,7 +158,7 @@ class Stream {
};
struct OutputBuffer {
- Result WriteToFile(string_view filename) const;
+ Result WriteToFile(std::string_view filename) const;
void clear() { data.clear(); }
size_t size() const { return data.size(); }
@@ -178,7 +178,7 @@ class MemoryStream : public Stream {
void Clear();
- Result WriteToFile(string_view filename) {
+ Result WriteToFile(std::string_view filename) {
return buf_->WriteToFile(filename);
}
@@ -196,7 +196,7 @@ class MemoryStream : public Stream {
class FileStream : public Stream {
public:
WABT_DISALLOW_COPY_AND_ASSIGN(FileStream);
- explicit FileStream(string_view filename, Stream* log_stream = nullptr);
+ explicit FileStream(std::string_view filename, Stream* log_stream = nullptr);
explicit FileStream(FILE*, Stream* log_stream = nullptr);
FileStream(FileStream&&);
FileStream& operator=(FileStream&&);
diff --git a/src/string-util.h b/src/string-util.h
new file mode 100644
index 00000000..eed9112a
--- /dev/null
+++ b/src/string-util.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2017 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WABT_STRING_UTIL_H_
+#define WABT_STRING_UTIL_H_
+
+#include <string_view>
+
+namespace wabt {
+
+inline std::string& operator+=(std::string& x, std::string_view y) {
+ x.append(y.data(), y.size());
+ return x;
+}
+
+inline std::string operator+(std::string_view x, std::string_view y) {
+ std::string s;
+ s.reserve(x.size() + y.size());
+ s.append(x.data(), x.size());
+ s.append(y.data(), y.size());
+ return s;
+}
+
+inline std::string operator+(const std::string& x, std::string_view y) {
+ return std::string_view(x) + y;
+}
+
+inline std::string operator+(std::string_view x, const std::string& y) {
+ return x + std::string_view(y);
+}
+
+inline std::string operator+(const char* x, std::string_view y) {
+ return std::string_view(x) + y;
+}
+
+inline std::string operator+(std::string_view x, const char* y) {
+ return x + std::string_view(y);
+}
+
+inline void cat_concatenate(std::string&) {}
+
+template <typename T, typename... Ts>
+void cat_concatenate(std::string& s, const T& t, const Ts&... args) {
+ s += t;
+ cat_concatenate(s, args...);
+}
+
+inline size_t cat_compute_size() {
+ return 0;
+}
+
+template <typename T, typename... Ts>
+size_t cat_compute_size(const T& t, const Ts&... args) {
+ return std::string_view(t).size() + cat_compute_size(args...);
+}
+
+// Is able to concatenate any combination of string/string_view/char*
+template <typename... Ts>
+std::string cat(const Ts&... args) {
+ std::string s;
+ s.reserve(cat_compute_size(args...));
+ cat_concatenate(s, args...);
+ return s;
+}
+
+} // namespace wabt
+
+#endif // WABT_STRING_UTIL_H_
diff --git a/src/string-view.cc b/src/string-view.cc
deleted file mode 100644
index 68d2a7a3..00000000
--- a/src/string-view.cc
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright 2017 WebAssembly Community Group participants
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "src/string-view.h"
-
-#include <algorithm>
-#include <limits>
-
-namespace wabt {
-
-void string_view::remove_prefix(size_type n) {
- assert(n <= size_);
- data_ += n;
- size_ -= n;
-}
-
-void string_view::remove_suffix(size_type n) {
- assert(n <= size_);
- size_ -= n;
-}
-
-void string_view::swap(string_view& s) noexcept {
- std::swap(data_, s.data_);
- std::swap(size_, s.size_);
-}
-
-string_view::operator std::string() const {
- return std::string(data_, size_);
-}
-
-std::string string_view::to_string() const {
- return std::string(data_, size_);
-}
-
-constexpr string_view::size_type string_view::max_size() const noexcept {
- return std::numeric_limits<size_type>::max();
-}
-
-string_view::size_type string_view::copy(char* s,
- size_type n,
- size_type pos) const {
- assert(pos <= size_);
- size_t count = std::min(n, size_ - pos);
- traits_type::copy(s, data_ + pos, count);
- return count;
-}
-
-string_view string_view::substr(size_type pos, size_type n) const {
- assert(pos <= size_);
- size_t count = std::min(n, size_ - pos);
- return string_view(data_ + pos, count);
-}
-
-int string_view::compare(string_view s) const noexcept {
- size_type rlen = std::min(size_, s.size_);
- int result = traits_type::compare(data_, s.data_, rlen);
- if (result != 0 || size_ == s.size_) {
- return result;
- }
- return size_ < s.size_ ? -1 : 1;
-}
-
-int string_view::compare(size_type pos1, size_type n1, string_view s) const {
- return substr(pos1, n1).compare(s);
-}
-
-int string_view::compare(size_type pos1,
- size_type n1,
- string_view s,
- size_type pos2,
- size_type n2) const {
- return substr(pos1, n1).compare(s.substr(pos2, n2));
-}
-
-int string_view::compare(const char* s) const {
- return compare(string_view(s));
-}
-
-int string_view::compare(size_type pos1, size_type n1, const char* s) const {
- return substr(pos1, n1).compare(string_view(s));
-}
-
-int string_view::compare(size_type pos1,
- size_type n1,
- const char* s,
- size_type n2) const {
- return substr(pos1, n1).compare(string_view(s, n2));
-}
-
-string_view::size_type string_view::find(string_view s,
- size_type pos) const noexcept {
- pos = std::min(pos, size_);
- const_iterator iter = std::search(begin() + pos, end(), s.begin(), s.end());
- return iter == end() ? npos : iter - begin();
-}
-
-string_view::size_type string_view::find(char c, size_type pos) const noexcept {
- return find(string_view(&c, 1), pos);
-}
-
-string_view::size_type string_view::find(const char* s,
- size_type pos,
- size_type n) const {
- return find(string_view(s, n), pos);
-}
-
-string_view::size_type string_view::find(const char* s, size_type pos) const {
- return find(string_view(s), pos);
-}
-
-string_view::size_type string_view::rfind(string_view s,
- size_type pos) const noexcept {
- pos = std::min(std::min(pos, size_ - s.size_) + s.size_, size_);
- reverse_iterator iter = std::search(reverse_iterator(begin() + pos), rend(),
- s.rbegin(), s.rend());
- return iter == rend() ? npos : (rend() - iter - s.size_);
-}
-
-string_view::size_type string_view::rfind(char c,
- size_type pos) const noexcept {
- return rfind(string_view(&c, 1), pos);
-}
-
-string_view::size_type string_view::rfind(const char* s,
- size_type pos,
- size_type n) const {
- return rfind(string_view(s, n), pos);
-}
-
-string_view::size_type string_view::rfind(const char* s, size_type pos) const {
- return rfind(string_view(s), pos);
-}
-
-string_view::size_type string_view::find_first_of(string_view s, size_type pos)
- const noexcept {
- pos = std::min(pos, size_);
- const_iterator iter =
- std::find_first_of(begin() + pos, end(), s.begin(), s.end());
- return iter == end() ? npos : iter - begin();
-}
-
-string_view::size_type string_view::find_first_of(char c, size_type pos)
- const noexcept {
- return find_first_of(string_view(&c, 1), pos);
-}
-
-string_view::size_type string_view::find_first_of(const char* s,
- size_type pos,
- size_type n) const {
- return find_first_of(string_view(s, n), pos);
-}
-
-string_view::size_type string_view::find_first_of(const char* s,
- size_type pos) const {
- return find_first_of(string_view(s), pos);
-}
-
-string_view::size_type string_view::find_last_of(string_view s,
- size_type pos) const noexcept {
- pos = std::min(pos, size_ - 1);
- reverse_iterator iter = std::find_first_of(
- reverse_iterator(begin() + (pos + 1)), rend(), s.begin(), s.end());
- return iter == rend() ? npos : (rend() - iter - 1);
-}
-
-string_view::size_type string_view::find_last_of(char c,
- size_type pos) const noexcept {
- return find_last_of(string_view(&c, 1), pos);
-}
-
-string_view::size_type string_view::find_last_of(const char* s,
- size_type pos,
- size_type n) const {
- return find_last_of(string_view(s, n), pos);
-}
-
-string_view::size_type string_view::find_last_of(const char* s,
- size_type pos) const {
- return find_last_of(string_view(s), pos);
-}
-
-} // namespace wabt
diff --git a/src/string-view.h b/src/string-view.h
deleted file mode 100644
index 25cff41f..00000000
--- a/src/string-view.h
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * Copyright 2017 WebAssembly Community Group participants
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef WABT_STRING_VIEW_H_
-#define WABT_STRING_VIEW_H_
-
-#include <cassert>
-#include <functional>
-#include <iterator>
-#include <ostream>
-#include <string>
-
-#include "src/hash-util.h"
-
-namespace wabt {
-
-// This is a simplified implemention of C++17's basic_string_view template.
-//
-// Missing features:
-// * Not a template
-// * No allocator support
-// * Some functions are not implemented
-// * Asserts instead of exceptions
-// * Some functions are not constexpr because we don't compile in C++17 mode
-
-class string_view {
- public:
- typedef std::char_traits<char> traits_type;
- typedef char value_type;
- typedef char* pointer;
- typedef const char* const_pointer;
- typedef char& reference;
- typedef const char& const_reference;
- typedef const char* const_iterator;
- typedef const_iterator iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef const_reverse_iterator reverse_iterator;
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
- static const size_type npos = size_type(-1);
-
- // construction and assignment
- constexpr string_view() noexcept;
- constexpr string_view(const string_view&) noexcept = default;
- string_view& operator=(const string_view&) noexcept = default;
- string_view(const std::string& str) noexcept;
- /*constexpr*/ string_view(const char* str);
- constexpr string_view(const char* str, size_type len);
-
- // iterator support
- constexpr const_iterator begin() const noexcept;
- constexpr const_iterator end() const noexcept;
- constexpr const_iterator cbegin() const noexcept;
- constexpr const_iterator cend() const noexcept;
- const_reverse_iterator rbegin() const noexcept;
- const_reverse_iterator rend() const noexcept;
- const_reverse_iterator crbegin() const noexcept;
- const_reverse_iterator crend() const noexcept;
-
- // capacity
- constexpr size_type size() const noexcept;
- constexpr size_type length() const noexcept;
- constexpr size_type max_size() const noexcept;
- constexpr bool empty() const noexcept;
-
- // element access
- constexpr const_reference operator[](size_type pos) const;
- /*constexpr*/ const_reference at(size_type pos) const;
- /*constexpr*/ const_reference front() const;
- /*constexpr*/ const_reference back() const;
- constexpr const_pointer data() const noexcept;
-
- // modifiers
- /*constexpr*/ void remove_prefix(size_type n);
- /*constexpr*/ void remove_suffix(size_type n);
- /*constexpr*/ void swap(string_view& s) noexcept;
-
- // string operations
- explicit operator std::string() const;
- std::string to_string() const;
- size_type copy(char* s, size_type n, size_type pos = 0) const;
- /*constexpr*/ string_view substr(size_type pos = 0, size_type n = npos) const;
- /*constexpr*/ int compare(string_view s) const noexcept;
- /*constexpr*/ int compare(size_type pos1, size_type n1, string_view s) const;
- /*constexpr*/ int compare(size_type pos1,
- size_type n1,
- string_view s,
- size_type pos2,
- size_type n2) const;
- /*constexpr*/ int compare(const char* s) const;
- /*constexpr*/ int compare(size_type pos1, size_type n1, const char* s) const;
- /*constexpr*/ int compare(size_type pos1,
- size_type n1,
- const char* s,
- size_type n2) const;
- /*constexpr*/ size_type find(string_view s, size_type pos = 0) const noexcept;
- /*constexpr*/ size_type find(char c, size_type pos = 0) const noexcept;
- /*constexpr*/ size_type find(const char* s, size_type pos, size_type n) const;
- /*constexpr*/ size_type find(const char* s, size_type pos = 0) const;
- /*constexpr*/ size_type rfind(string_view s,
- size_type pos = npos) const noexcept;
- /*constexpr*/ size_type rfind(char c, size_type pos = npos) const noexcept;
- /*constexpr*/ size_type rfind(const char* s,
- size_type pos,
- size_type n) const;
- /*constexpr*/ size_type rfind(const char* s, size_type pos = npos) const;
- /*constexpr*/ size_type find_first_of(string_view s,
- size_type pos = 0) const noexcept;
- /*constexpr*/ size_type find_first_of(char c,
- size_type pos = 0) const noexcept;
- /*constexpr*/ size_type find_first_of(const char* s,
- size_type pos,
- size_type n) const;
- /*constexpr*/ size_type find_first_of(const char* s, size_type pos = 0) const;
- /*constexpr*/ size_type find_last_of(string_view s,
- size_type pos = npos) const noexcept;
- /*constexpr*/ size_type find_last_of(char c,
- size_type pos = npos) const noexcept;
- /*constexpr*/ size_type find_last_of(const char* s,
- size_type pos,
- size_type n) const;
- /*constexpr*/ size_type find_last_of(const char* s,
- size_type pos = npos) const;
-
-// TODO(binji): These are defined by C++17 basic_string_view but not
-// implemented here.
-#if 0
- constexpr size_type find_first_not_of(string_view s, size_type pos = 0) const
- noexcept;
- constexpr size_type find_first_not_of(char c, size_type pos = 0) const
- noexcept;
- constexpr size_type find_first_not_of(const char* s,
- size_type pos,
- size_type n) const;
- constexpr size_type find_first_not_of(const char* s, size_type pos = 0) const;
- constexpr size_type find_last_not_of(string_view s,
- size_type pos = npos) const noexcept;
- constexpr size_type find_last_not_of(char c, size_type pos = npos) const
- noexcept;
- constexpr size_type find_last_not_of(const char* s,
- size_type pos,
- size_type n) const;
- constexpr size_type find_last_not_of(const char* s,
- size_type pos = npos) const;
-#endif
-
- private:
- const char* data_;
- size_type size_;
-};
-
-// non-member comparison functions
-inline bool operator==(string_view x, string_view y) noexcept {
- return x.compare(y) == 0;
-}
-
-inline bool operator!=(string_view x, string_view y) noexcept {
- return x.compare(y) != 0;
-}
-
-inline bool operator<(string_view x, string_view y) noexcept {
- return x.compare(y) < 0;
-}
-
-inline bool operator>(string_view x, string_view y) noexcept {
- return x.compare(y) > 0;
-}
-
-inline bool operator<=(string_view x, string_view y) noexcept {
- return x.compare(y) <= 0;
-}
-
-inline bool operator>=(string_view x, string_view y) noexcept {
- return x.compare(y) >= 0;
-}
-
-// non-member append.
-inline std::string& operator+=(std::string& x, string_view y) {
- x.append(y.data(), y.size());
- return x;
-}
-
-inline std::string operator+(string_view x, string_view y) {
- std::string s;
- s.reserve(x.size() + y.size());
- s.append(x.data(), x.size());
- s.append(y.data(), y.size());
- return s;
-}
-
-inline std::string operator+(const std::string& x, string_view y) {
- return string_view(x) + y;
-}
-
-inline std::string operator+(string_view x, const std::string& y) {
- return x + string_view(y);
-}
-
-inline std::string operator+(const char* x, string_view y) {
- return string_view(x) + y;
-}
-
-inline std::string operator+(string_view x, const char* y) {
- return x + string_view(y);
-}
-
-inline void cat_concatenate(std::string&) {}
-
-template <typename T, typename... Ts>
-void cat_concatenate(std::string& s, const T& t, const Ts&... args) {
- s += t;
- cat_concatenate(s, args...);
-}
-
-inline size_t cat_compute_size() {
- return 0;
-}
-
-template <typename T, typename... Ts>
-size_t cat_compute_size(const T& t, const Ts&... args) {
- return string_view(t).size() + cat_compute_size(args...);
-}
-
-// Is able to concatenate any combination of string/string_view/char*
-template <typename... Ts>
-std::string cat(const Ts&... args) {
- std::string s;
- s.reserve(cat_compute_size(args...));
- cat_concatenate(s, args...);
- return s;
-}
-
-inline constexpr string_view::string_view() noexcept
- : data_(nullptr), size_(0) {}
-
-inline string_view::string_view(const std::string& str) noexcept
- : data_(str.data()), size_(str.size()) {}
-
-inline string_view::string_view(const char* str)
- : data_(str), size_(traits_type::length(str)) {}
-
-inline constexpr string_view::string_view(const char* str, size_type len)
- : data_(str), size_(len) {}
-
-inline constexpr string_view::const_iterator string_view::begin()
- const noexcept {
- return data_;
-}
-
-inline constexpr string_view::const_iterator string_view::end() const noexcept {
- return data_ + size_;
-}
-
-inline constexpr string_view::const_iterator string_view::cbegin()
- const noexcept {
- return data_;
-}
-
-inline constexpr string_view::const_iterator string_view::cend()
- const noexcept {
- return data_ + size_;
-}
-
-inline string_view::const_reverse_iterator string_view::rbegin()
- const noexcept {
- return const_reverse_iterator(end());
-}
-
-inline string_view::const_reverse_iterator string_view::rend() const noexcept {
- return const_reverse_iterator(begin());
-}
-
-inline string_view::const_reverse_iterator string_view::crbegin()
- const noexcept {
- return const_reverse_iterator(cend());
-}
-
-inline string_view::const_reverse_iterator string_view::crend() const noexcept {
- return const_reverse_iterator(cbegin());
-}
-
-constexpr inline string_view::size_type string_view::size() const noexcept {
- return size_;
-}
-
-constexpr inline string_view::size_type string_view::length() const noexcept {
- return size_;
-}
-
-constexpr inline bool string_view::empty() const noexcept {
- return size_ == 0;
-}
-
-constexpr inline string_view::const_reference string_view::operator[](
- size_type pos) const {
- return data_[pos];
-}
-
-inline string_view::const_reference string_view::at(size_type pos) const {
- assert(pos < size_);
- return data_[pos];
-}
-
-inline string_view::const_reference string_view::front() const {
- assert(!empty());
- return *data_;
-}
-
-inline string_view::const_reference string_view::back() const {
- assert(!empty());
- return data_[size_ - 1];
-}
-
-constexpr inline string_view::const_pointer string_view::data() const noexcept {
- return data_;
-}
-
-inline std::ostream& operator<<(std::ostream& os, string_view sv) {
- os.write(sv.data(), sv.size());
- return os;
-}
-
-} // namespace wabt
-
-namespace std {
-
-// hash support
-template <>
-struct hash<::wabt::string_view> {
- ::wabt::hash_code operator()(const ::wabt::string_view& sv) {
- return ::wabt::HashRange(sv.begin(), sv.end());
- }
-};
-
-} // namespace std
-
-#endif // WABT_STRING_VIEW_H_
diff --git a/src/test-filenames.cc b/src/test-filenames.cc
index 5b0282fc..a0552bf8 100644
--- a/src/test-filenames.cc
+++ b/src/test-filenames.cc
@@ -22,7 +22,7 @@ using namespace wabt;
namespace {
-void assert_string_view_eq(const char* s, string_view sv) {
+void assert_string_view_eq(const char* s, std::string_view sv) {
size_t len = std::strlen(s);
ASSERT_EQ(len, sv.size());
for (size_t i = 0; i < len; ++i) {
diff --git a/src/test-literal.cc b/src/test-literal.cc
index 4a309d6e..f1ed6313 100644
--- a/src/test-literal.cc
+++ b/src/test-literal.cc
@@ -33,11 +33,12 @@ enum ParseIntTypeCombo {
Both,
};
-template <typename T, typename F>
-void AssertIntEquals(T expected,
- const char* s,
- F&& parse_int,
- ParseIntTypeCombo parse_type = Both) {
+template <typename T>
+void AssertIntEquals(
+ T expected,
+ const char* s,
+ Result (*parse_int)(const char*, const char*, T*, ParseIntType),
+ ParseIntTypeCombo parse_type = Both) {
const char* const end = s + strlen(s);
T actual;
if (parse_type == UnsignedOnly || parse_type == Both) {
diff --git a/src/test-string-view.cc b/src/test-string-view.cc
deleted file mode 100644
index 4a4499dd..00000000
--- a/src/test-string-view.cc
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * Copyright 2017 WebAssembly Community Group participants
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "gtest/gtest.h"
-
-#include "src/string-view.h"
-
-#include <cstring>
-#include <functional>
-
-using namespace wabt;
-
-namespace {
-
-void assert_string_view_eq(const char* s, string_view sv) {
- size_t len = std::strlen(s);
- ASSERT_EQ(len, sv.size());
- for (size_t i = 0; i < len; ++i) {
- ASSERT_EQ(s[i], sv[i]);
- }
-}
-
-constexpr string_view::size_type npos = string_view::npos;
-
-} // end anonymous namespace
-
-TEST(string_view, default_constructor) {
- assert_string_view_eq("", string_view());
-}
-
-TEST(string_view, copy_constructor) {
- string_view sv1("copy");
- assert_string_view_eq("copy", string_view(sv1));
-
- string_view sv2;
- assert_string_view_eq("", string_view(sv2));
-}
-
-TEST(string_view, assignment_operator) {
- string_view sv1;
- sv1 = string_view("assign");
- assert_string_view_eq("assign", sv1);
-
- string_view sv2;
- sv2 = string_view();
- assert_string_view_eq("", sv2);
-}
-
-TEST(string_view, string_constructor) {
- assert_string_view_eq("", string_view(std::string()));
- assert_string_view_eq("string", string_view(std::string("string")));
-}
-
-TEST(string_view, cstr_constructor) {
- assert_string_view_eq("", string_view(""));
- assert_string_view_eq("cstr", string_view("cstr"));
-}
-
-TEST(string_view, cstr_len_constructor) {
- assert_string_view_eq("", string_view("foo-bar-baz", 0));
- assert_string_view_eq("foo", string_view("foo-bar-baz", 3));
- assert_string_view_eq("foo-bar", string_view("foo-bar-baz", 7));
-}
-
-TEST(string_view, begin_end) {
- string_view sv("012345");
-
- char count = 0;
- for (auto iter = sv.begin(), end = sv.end(); iter != end; ++iter) {
- ASSERT_EQ('0' + count, *iter);
- ++count;
- }
- ASSERT_EQ(6, count);
-}
-
-TEST(string_view, cbegin_cend) {
- const string_view sv("012345");
-
- char count = 0;
- for (auto iter = sv.cbegin(), end = sv.cend(); iter != end; ++iter) {
- ASSERT_EQ('0' + count, *iter);
- ++count;
- }
- ASSERT_EQ(6, count);
-}
-
-TEST(string_view, rbegin_rend) {
- string_view sv("012345");
-
- char count = 0;
- for (auto iter = sv.rbegin(), end = sv.rend(); iter != end; ++iter) {
- ASSERT_EQ('5' - count, *iter);
- ++count;
- }
- ASSERT_EQ(6, count);
-}
-
-TEST(string_view, crbegin_crend) {
- const string_view sv("012345");
-
- char count = 0;
- for (auto iter = sv.crbegin(), end = sv.crend(); iter != end; ++iter) {
- ASSERT_EQ('5' - count, *iter);
- ++count;
- }
- ASSERT_EQ(6, count);
-}
-
-TEST(string_view, size) {
- string_view sv1;
- ASSERT_EQ(0U, sv1.size());
-
- string_view sv2("");
- ASSERT_EQ(0U, sv2.size());
-
- string_view sv3("hello");
- ASSERT_EQ(5U, sv3.size());
-}
-
-TEST(string_view, length) {
- string_view sv1;
- ASSERT_EQ(0U, sv1.length());
-
- string_view sv2("hello");
- ASSERT_EQ(5U, sv2.length());
-}
-
-TEST(string_view, empty) {
- string_view sv1;
- ASSERT_TRUE(sv1.empty());
-
- string_view sv2("bye");
- ASSERT_FALSE(sv2.empty());
-}
-
-TEST(string_view, operator_bracket) {
- string_view sv("words");
- ASSERT_EQ('w', sv[0]);
- ASSERT_EQ('o', sv[1]);
- ASSERT_EQ('r', sv[2]);
- ASSERT_EQ('d', sv[3]);
- ASSERT_EQ('s', sv[4]);
-}
-
-TEST(string_view, at) {
- string_view sv("words");
- ASSERT_EQ('w', sv.at(0));
- ASSERT_EQ('o', sv.at(1));
- ASSERT_EQ('r', sv.at(2));
- ASSERT_EQ('d', sv.at(3));
- ASSERT_EQ('s', sv.at(4));
-}
-
-TEST(string_view, front) {
- string_view sv("words");
- ASSERT_EQ('w', sv.front());
-}
-
-TEST(string_view, back) {
- string_view sv("words");
- ASSERT_EQ('s', sv.back());
-}
-
-TEST(string_view, data) {
- const char* cstr = "words";
- string_view sv(cstr);
- ASSERT_EQ(cstr, sv.data());
-}
-
-TEST(string_view, remove_prefix) {
- string_view sv("words");
- sv.remove_prefix(2);
- assert_string_view_eq("rds", sv);
-}
-
-TEST(string_view, remove_suffix) {
- string_view sv("words");
- sv.remove_suffix(2);
- assert_string_view_eq("wor", sv);
-}
-
-TEST(string_view, swap) {
- string_view sv1("hello");
- string_view sv2("bye");
-
- sv1.swap(sv2);
-
- assert_string_view_eq("bye", sv1);
- assert_string_view_eq("hello", sv2);
-}
-
-TEST(string_view, operator_std_string) {
- string_view sv1("hi");
- std::string s(sv1);
-
- ASSERT_EQ(2U, s.size());
- ASSERT_EQ('h', s[0]);
- ASSERT_EQ('i', s[1]);
-}
-
-TEST(string_view, copy) {
- string_view sv("words");
- char buffer[10] = {0};
-
- sv.copy(buffer, 10, 2);
- ASSERT_EQ('r', buffer[0]);
- ASSERT_EQ('d', buffer[1]);
- ASSERT_EQ('s', buffer[2]);
- for (int i = 3; i < 10; ++i) {
- ASSERT_EQ(0, buffer[i]);
- }
-}
-
-TEST(string_view, substr) {
- string_view sv1("abcdefghij");
- string_view sv2 = sv1.substr(2, 3);
- assert_string_view_eq("cde", sv2);
-}
-
-TEST(string_view, compare0) {
- ASSERT_TRUE(string_view("meat").compare(string_view("meet")) < 0);
- ASSERT_TRUE(string_view("rest").compare(string_view("rate")) > 0);
- ASSERT_TRUE(string_view("equal").compare(string_view("equal")) == 0);
- ASSERT_TRUE(string_view("star").compare(string_view("start")) < 0);
- ASSERT_TRUE(string_view("finished").compare(string_view("fin")) > 0);
-}
-
-TEST(string_view, compare1) {
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, string_view("ca")) > 0);
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, string_view("cd")) == 0);
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, string_view("cz")) < 0);
-}
-
-TEST(string_view, compare2) {
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, string_view("_ca__"), 1, 2) >
- 0);
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, string_view("_cd__"), 1, 2) ==
- 0);
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, string_view("_cz__"), 1, 2) <
- 0);
-}
-
-TEST(string_view, compare3) {
- ASSERT_TRUE(string_view("abcdef").compare("aaaa") > 0);
- ASSERT_TRUE(string_view("abcdef").compare("abcdef") == 0);
- ASSERT_TRUE(string_view("abcdef").compare("zzzz") < 0);
-}
-
-TEST(string_view, compare4) {
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, "ca") > 0);
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, "cd") == 0);
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, "cz") < 0);
-}
-
-TEST(string_view, compare5) {
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, "ca____", 2) > 0);
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, "cd___", 2) == 0);
- ASSERT_TRUE(string_view("abcdef").compare(2, 2, "cz__", 2) < 0);
-}
-
-TEST(string_view, find0) {
- ASSERT_EQ(0U, string_view("find fins").find(string_view("fin")));
- ASSERT_EQ(5U, string_view("find fins").find(string_view("fin"), 1));
- ASSERT_EQ(npos, string_view("find fins").find(string_view("fin"), 6));
-}
-
-TEST(string_view, find1) {
- ASSERT_EQ(0U, string_view("012340123").find('0'));
- ASSERT_EQ(5U, string_view("012340123").find('0', 2));
- ASSERT_EQ(npos, string_view("012340123").find('0', 6));
-}
-
-TEST(string_view, find2) {
- ASSERT_EQ(1U, string_view("012340123").find("12345", 0, 2));
- ASSERT_EQ(6U, string_view("012340123").find("12345", 3, 2));
- ASSERT_EQ(npos, string_view("012340123").find("12345", 10, 2));
-}
-
-TEST(string_view, find3) {
- ASSERT_EQ(1U, string_view("012340123").find("12"));
- ASSERT_EQ(6U, string_view("012340123").find("12", 2));
- ASSERT_EQ(npos, string_view("012340123").find("12", 10));
-}
-
-TEST(string_view, rfind0) {
- ASSERT_EQ(5U, string_view("find fins").rfind(string_view("fin")));
- ASSERT_EQ(0U, string_view("find fins").rfind(string_view("fin"), 4));
- ASSERT_EQ(npos, string_view("find fins").rfind(string_view("no")));
- ASSERT_EQ(npos, string_view("foo").rfind(string_view("foobar")));
-}
-
-TEST(string_view, rfind1) {
- ASSERT_EQ(5U, string_view("012340123").rfind('0'));
- ASSERT_EQ(0U, string_view("012340123").rfind('0', 2));
- ASSERT_EQ(npos, string_view("012340123").rfind('9'));
-}
-
-TEST(string_view, rfind2) {
- ASSERT_EQ(6U, string_view("012340123").rfind("12345", npos, 2));
- ASSERT_EQ(1U, string_view("012340123").rfind("12345", 4, 2));
- ASSERT_EQ(npos, string_view("012340123").rfind("12345", npos, 5));
- ASSERT_EQ(npos, string_view("012").rfind("12345", npos, 5));
-}
-
-TEST(string_view, rfind3) {
- ASSERT_EQ(6U, string_view("012340123").rfind("12"));
- ASSERT_EQ(1U, string_view("012340123").rfind("12", 2));
- ASSERT_EQ(npos, string_view("012340123").rfind("12", 0));
- ASSERT_EQ(npos, string_view("012").rfind("12345"));
-}
-
-TEST(string_view, find_first_of0) {
- ASSERT_EQ(0U, string_view("0123abc").find_first_of(string_view("0a")));
- ASSERT_EQ(4U, string_view("0123abc").find_first_of(string_view("0a"), 1));
- ASSERT_EQ(npos, string_view("0123abc").find_first_of(string_view("xyz")));
-}
-
-TEST(string_view, find_first_of1) {
- ASSERT_EQ(1U, string_view("ahellohi").find_first_of('h'));
- ASSERT_EQ(6U, string_view("ahellohi").find_first_of('h', 2));
- ASSERT_EQ(npos, string_view("ahellohi").find_first_of('z', 2));
-}
-
-TEST(string_view, find_first_of2) {
- ASSERT_EQ(0U, string_view("0123abc").find_first_of("0a1b", 0, 2));
- ASSERT_EQ(4U, string_view("0123abc").find_first_of("0a1b", 1, 2));
- ASSERT_EQ(npos, string_view("0123abc").find_first_of("0a1b", 5, 2));
-}
-
-TEST(string_view, find_first_of3) {
- ASSERT_EQ(0U, string_view("0123abc").find_first_of("0a"));
- ASSERT_EQ(0U, string_view("0123abc").find_first_of("0a", 0));
- ASSERT_EQ(4U, string_view("0123abc").find_first_of("0a", 1));
- ASSERT_EQ(npos, string_view("0123abc").find_first_of("0a", 5));
-}
-
-TEST(string_view, find_last_of0) {
- ASSERT_EQ(4U, string_view("0123abc").find_last_of(string_view("0a")));
- ASSERT_EQ(0U, string_view("0123abc").find_last_of(string_view("0a"), 1));
- ASSERT_EQ(npos, string_view("0123abc").find_last_of(string_view("xyz")));
-}
-
-TEST(string_view, find_last_of1) {
- ASSERT_EQ(6U, string_view("ahellohi").find_last_of('h'));
- ASSERT_EQ(1U, string_view("ahellohi").find_last_of('h', 2));
- ASSERT_EQ(npos, string_view("ahellohi").find_last_of('z', 2));
-}
-
-TEST(string_view, find_last_of2) {
- ASSERT_EQ(4U, string_view("0123abc").find_last_of("0a1b", npos, 2));
- ASSERT_EQ(0U, string_view("0123abc").find_last_of("0a1b", 1, 2));
- ASSERT_EQ(npos, string_view("0123abc").find_last_of("a1b", 0, 2));
- ASSERT_EQ(npos, string_view("0123abc").find_last_of("xyz", npos, 0));
-}
-
-TEST(string_view, find_last_of3) {
- ASSERT_EQ(4U, string_view("0123abc").find_last_of("0a"));
- ASSERT_EQ(4U, string_view("0123abc").find_last_of("0a", npos));
- ASSERT_EQ(0U, string_view("0123abc").find_last_of("0a", 1));
- ASSERT_EQ(npos, string_view("0123abc").find_last_of("a1", 0));
-}
-
-TEST(string_view, operator_equal) {
- ASSERT_TRUE(string_view("this") == string_view("this"));
- ASSERT_FALSE(string_view("this") == string_view("that"));
-}
-
-TEST(string_view, operator_not_equal) {
- ASSERT_FALSE(string_view("here") != string_view("here"));
- ASSERT_TRUE(string_view("here") != string_view("there"));
-}
-
-TEST(string_view, operator_less_than) {
- ASSERT_TRUE(string_view("abc") < string_view("xyz"));
- ASSERT_FALSE(string_view("later") < string_view("earlier"));
- ASSERT_FALSE(string_view("one") < string_view("one"));
-}
-
-TEST(string_view, operator_greater_than) {
- ASSERT_TRUE(string_view("much") > string_view("little"));
- ASSERT_FALSE(string_view("future") > string_view("past"));
- ASSERT_FALSE(string_view("now") > string_view("now"));
-}
-
-TEST(string_view, operator_less_than_or_equal) {
- ASSERT_TRUE(string_view("abc") <= string_view("xyz"));
- ASSERT_FALSE(string_view("later") <= string_view("earlier"));
- ASSERT_TRUE(string_view("one") <= string_view("one"));
-}
-
-TEST(string_view, operator_greater_than_or_equal) {
- ASSERT_TRUE(string_view("much") >= string_view("little"));
- ASSERT_FALSE(string_view("future") >= string_view("past"));
- ASSERT_TRUE(string_view("now") >= string_view("now"));
-}
-
-TEST(string_view, hash) {
- std::hash<string_view> hasher;
-
- ASSERT_NE(hasher(string_view("hello")), hasher(string_view("goodbye")));
- ASSERT_EQ(hasher(string_view("same")), hasher(string_view("same")));
-}
diff --git a/src/token.cc b/src/token.cc
index 657d37be..cb1a19df 100644
--- a/src/token.cc
+++ b/src/token.cc
@@ -52,7 +52,7 @@ Token::Token(Location loc, TokenType token_type, Type type)
Construct(type_, type);
}
-Token::Token(Location loc, TokenType token_type, string_view text)
+Token::Token(Location loc, TokenType token_type, std::string_view text)
: loc(loc), token_type_(token_type) {
assert(HasText());
Construct(text_, text);
@@ -74,11 +74,11 @@ std::string Token::to_string() const {
if (IsTokenTypeBare(token_type_)) {
return GetTokenTypeName(token_type_);
} else if (HasLiteral()) {
- return literal_.text.to_string();
+ return std::string(literal_.text);
} else if (HasOpcode()) {
return opcode_.GetName();
} else if (HasText()) {
- return text_.to_string();
+ return std::string(text_);
} else if (IsTokenTypeRefKind(token_type_)) {
return type_.GetRefKindName();
} else {
diff --git a/src/token.h b/src/token.h
index 719e1aee..20c9c181 100644
--- a/src/token.h
+++ b/src/token.h
@@ -17,18 +17,19 @@
#ifndef WABT_TOKEN_H_
#define WABT_TOKEN_H_
+#include <string_view>
+
#include "src/literal.h"
#include "src/opcode.h"
-#include "src/string-view.h"
namespace wabt {
struct Literal {
Literal() = default;
- Literal(LiteralType type, string_view text) : type(type), text(text) {}
+ Literal(LiteralType type, std::string_view text) : type(type), text(text) {}
LiteralType type;
- string_view text;
+ std::string_view text;
};
enum class TokenType {
@@ -79,7 +80,7 @@ struct Token {
Token() : token_type_(TokenType::Invalid) {}
Token(Location, TokenType);
Token(Location, TokenType, Type);
- Token(Location, TokenType, string_view);
+ Token(Location, TokenType, std::string_view);
Token(Location, TokenType, Opcode);
Token(Location, TokenType, const Literal&);
@@ -94,7 +95,7 @@ struct Token {
bool HasOpcode() const { return IsTokenTypeOpcode(token_type_); }
bool HasLiteral() const { return IsTokenTypeLiteral(token_type_); }
- string_view text() const {
+ std::string_view text() const {
assert(HasText());
return text_;
}
@@ -121,7 +122,7 @@ struct Token {
TokenType token_type_;
union {
- string_view text_;
+ std::string_view text_;
Type type_;
Opcode opcode_;
Literal literal_;
diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc
index bf428424..97044010 100644
--- a/src/tools/spectest-interp.cc
+++ b/src/tools/spectest-interp.cc
@@ -35,6 +35,7 @@
#include "src/literal.h"
#include "src/option-parser.h"
#include "src/stream.h"
+#include "src/string-util.h"
#include "src/validator.h"
#include "src/wast-lexer.h"
#include "src/wast-parser.h"
@@ -324,7 +325,7 @@ class JSONParser {
public:
JSONParser() {}
- wabt::Result ReadFile(string_view spec_json_filename);
+ wabt::Result ReadFile(std::string_view spec_json_filename);
wabt::Result ParseScript(Script* out_script);
private:
@@ -349,25 +350,25 @@ class JSONParser {
wabt::Result ParseTypeObject(Type* out_type);
wabt::Result ParseTypeVector(TypeVector* out_types);
wabt::Result ParseConst(TypedValue* out_value);
- wabt::Result ParseI32Value(uint32_t* out_value, string_view value_str);
- wabt::Result ParseI64Value(uint64_t* out_value, string_view value_str);
+ wabt::Result ParseI32Value(uint32_t* out_value, std::string_view value_str);
+ wabt::Result ParseI64Value(uint64_t* out_value, std::string_view value_str);
wabt::Result ParseF32Value(uint32_t* out_value,
ExpectedNan* out_nan,
- string_view value_str,
+ std::string_view value_str,
AllowExpected);
wabt::Result ParseF64Value(uint64_t* out_value,
ExpectedNan* out_nan,
- string_view value_str,
+ std::string_view value_str,
AllowExpected);
wabt::Result ParseLaneConstValue(Type lane_type,
int lane,
ExpectedValue* out_value,
- string_view value_str,
+ std::string_view value_str,
AllowExpected);
wabt::Result ParseConstValue(Type type,
Value* out_value,
ExpectedNan* out_nan,
- string_view value_str,
+ std::string_view value_str,
AllowExpected);
wabt::Result ParseConstVector(ValueTypes* out_types, Values* out_values);
wabt::Result ParseExpectedValue(ExpectedValue* out_value, AllowExpected);
@@ -376,7 +377,7 @@ class JSONParser {
wabt::Result ParseActionResult();
wabt::Result ParseModuleType(ModuleType* out_type);
- std::string CreateModulePath(string_view filename);
+ std::string CreateModulePath(std::string_view filename);
wabt::Result ParseFilename(std::string* out_filename);
wabt::Result ParseCommand(CommandPtr* out_command);
@@ -393,7 +394,7 @@ class JSONParser {
#define PARSE_KEY_STRING_VALUE(key, value) \
CHECK_RESULT(ParseKeyStringValue(key, value))
-wabt::Result JSONParser::ReadFile(string_view spec_json_filename) {
+wabt::Result JSONParser::ReadFile(std::string_view spec_json_filename) {
loc_.filename = spec_json_filename;
loc_.line = 1;
loc_.first_column = 1;
@@ -403,7 +404,7 @@ wabt::Result JSONParser::ReadFile(string_view spec_json_filename) {
void JSONParser::PrintError(const char* format, ...) {
WABT_SNPRINTF_ALLOCA(buffer, length, format);
- fprintf(stderr, "%s:%d:%d: %s\n", loc_.filename.to_string().c_str(),
+ fprintf(stderr, "%s:%d:%d: %s\n", std::string(loc_.filename).c_str(),
loc_.line, loc_.first_column, buffer);
}
@@ -638,9 +639,8 @@ wabt::Result JSONParser::ParseConst(TypedValue* out_value) {
}
wabt::Result JSONParser::ParseI32Value(uint32_t* out_value,
- string_view value_str) {
- if (Failed(ParseInt32(value_str.begin(), value_str.end(), out_value,
- ParseIntType::UnsignedOnly))) {
+ std::string_view value_str) {
+ if (Failed(ParseInt32(value_str, out_value, ParseIntType::UnsignedOnly))) {
PrintError("invalid i32 literal");
return wabt::Result::Error;
}
@@ -648,9 +648,8 @@ wabt::Result JSONParser::ParseI32Value(uint32_t* out_value,
}
wabt::Result JSONParser::ParseI64Value(uint64_t* out_value,
- string_view value_str) {
- if (Failed(ParseInt64(value_str.begin(), value_str.end(), out_value,
- ParseIntType::UnsignedOnly))) {
+ std::string_view value_str) {
+ if (Failed(ParseInt64(value_str, out_value, ParseIntType::UnsignedOnly))) {
PrintError("invalid i64 literal");
return wabt::Result::Error;
}
@@ -659,7 +658,7 @@ wabt::Result JSONParser::ParseI64Value(uint64_t* out_value,
wabt::Result JSONParser::ParseF32Value(uint32_t* out_value,
ExpectedNan* out_nan,
- string_view value_str,
+ std::string_view value_str,
AllowExpected allow_expected) {
if (allow_expected == AllowExpected::Yes) {
*out_value = 0;
@@ -673,8 +672,7 @@ wabt::Result JSONParser::ParseF32Value(uint32_t* out_value,
}
*out_nan = ExpectedNan::None;
- if (Failed(ParseInt32(value_str.begin(), value_str.end(), out_value,
- ParseIntType::UnsignedOnly))) {
+ if (Failed(ParseInt32(value_str, out_value, ParseIntType::UnsignedOnly))) {
PrintError("invalid f32 literal");
return wabt::Result::Error;
}
@@ -683,7 +681,7 @@ wabt::Result JSONParser::ParseF32Value(uint32_t* out_value,
wabt::Result JSONParser::ParseF64Value(uint64_t* out_value,
ExpectedNan* out_nan,
- string_view value_str,
+ std::string_view value_str,
AllowExpected allow_expected) {
if (allow_expected == AllowExpected::Yes) {
*out_value = 0;
@@ -697,8 +695,7 @@ wabt::Result JSONParser::ParseF64Value(uint64_t* out_value,
}
*out_nan = ExpectedNan::None;
- if (Failed(ParseInt64(value_str.begin(), value_str.end(), out_value,
- ParseIntType::UnsignedOnly))) {
+ if (Failed(ParseInt64(value_str, out_value, ParseIntType::UnsignedOnly))) {
PrintError("invalid f64 literal");
return wabt::Result::Error;
}
@@ -708,7 +705,7 @@ wabt::Result JSONParser::ParseF64Value(uint64_t* out_value,
wabt::Result JSONParser::ParseLaneConstValue(Type lane_type,
int lane,
ExpectedValue* out_value,
- string_view value_str,
+ std::string_view value_str,
AllowExpected allow_expected) {
v128 v = out_value->value.value.Get<v128>();
@@ -773,7 +770,7 @@ wabt::Result JSONParser::ParseLaneConstValue(Type lane_type,
wabt::Result JSONParser::ParseConstValue(Type type,
Value* out_value,
ExpectedNan* out_nan,
- string_view value_str,
+ std::string_view value_str,
AllowExpected allow_expected) {
*out_nan = ExpectedNan::None;
@@ -966,7 +963,7 @@ wabt::Result JSONParser::ParseModuleType(ModuleType* out_type) {
}
}
-static string_view GetDirname(string_view path) {
+static std::string_view GetDirname(std::string_view path) {
// Strip everything after and including the last slash (or backslash), e.g.:
//
// s = "foo/bar/baz", => "foo/bar"
@@ -975,27 +972,25 @@ static string_view GetDirname(string_view path) {
// s = "some\windows\directory", => "some\windows"
size_t last_slash = path.find_last_of('/');
size_t last_backslash = path.find_last_of('\\');
- if (last_slash == string_view::npos) {
+ if (last_slash == std::string_view::npos) {
last_slash = 0;
}
- if (last_backslash == string_view::npos) {
+ if (last_backslash == std::string_view::npos) {
last_backslash = 0;
}
return path.substr(0, std::max(last_slash, last_backslash));
}
-std::string JSONParser::CreateModulePath(string_view filename) {
- string_view spec_json_filename = loc_.filename;
- string_view dirname = GetDirname(spec_json_filename);
+std::string JSONParser::CreateModulePath(std::string_view filename) {
+ std::string_view spec_json_filename = loc_.filename;
+ std::string_view dirname = GetDirname(spec_json_filename);
std::string path;
if (dirname.size() == 0) {
- path = filename.to_string();
+ path = std::string(filename);
} else {
- path = dirname.to_string();
- path += '/';
- path += filename.to_string();
+ path = dirname + "/" + filename;
}
ConvertBackslashToSlash(&path);
@@ -1177,7 +1172,8 @@ class CommandRunner {
const Action* action,
RunVerbosity verbose);
- interp::Module::Ptr ReadModule(string_view module_filename, Errors* errors);
+ interp::Module::Ptr ReadModule(std::string_view module_filename,
+ Errors* errors);
Extern::Ptr GetImport(const std::string&, const std::string&);
void PopulateImports(const interp::Module::Ptr&, RefVec*);
void PopulateExports(const Instance::Ptr&, ExportMap*);
@@ -1203,14 +1199,14 @@ class CommandRunner {
void TallyCommand(wabt::Result);
- wabt::Result ReadInvalidTextModule(string_view module_filename,
+ wabt::Result ReadInvalidTextModule(std::string_view module_filename,
const std::string& header);
wabt::Result ReadInvalidModule(int line_number,
- string_view module_filename,
+ std::string_view module_filename,
ModuleType module_type,
const char* desc);
wabt::Result ReadUnlinkableModule(int line_number,
- string_view module_filename,
+ std::string_view module_filename,
ModuleType module_type,
const char* desc);
@@ -1381,8 +1377,9 @@ ActionResult CommandRunner::RunAction(int line_number,
return result;
}
-wabt::Result CommandRunner::ReadInvalidTextModule(string_view module_filename,
- const std::string& header) {
+wabt::Result CommandRunner::ReadInvalidTextModule(
+ std::string_view module_filename,
+ const std::string& header) {
std::vector<uint8_t> file_data;
wabt::Result result = ReadFile(module_filename, &file_data);
std::unique_ptr<WastLexer> lexer = WastLexer::CreateBufferLexer(
@@ -1400,7 +1397,7 @@ wabt::Result CommandRunner::ReadInvalidTextModule(string_view module_filename,
return result;
}
-interp::Module::Ptr CommandRunner::ReadModule(string_view module_filename,
+interp::Module::Ptr CommandRunner::ReadModule(std::string_view module_filename,
Errors* errors) {
std::vector<uint8_t> file_data;
@@ -1428,7 +1425,7 @@ interp::Module::Ptr CommandRunner::ReadModule(string_view module_filename,
}
wabt::Result CommandRunner::ReadInvalidModule(int line_number,
- string_view module_filename,
+ std::string_view module_filename,
ModuleType module_type,
const char* desc) {
std::string header = StringPrintf(
@@ -1863,7 +1860,7 @@ void CommandRunner::TallyCommand(wabt::Result result) {
total_++;
}
-static int ReadAndRunSpecJSON(string_view spec_json_filename) {
+static int ReadAndRunSpecJSON(std::string_view spec_json_filename) {
JSONParser parser;
if (parser.ReadFile(spec_json_filename) == wabt::Result::Error) {
return 1;
diff --git a/src/tools/wasm-opcodecnt.cc b/src/tools/wasm-opcodecnt.cc
index 648a2636..f3abb868 100644
--- a/src/tools/wasm-opcodecnt.cc
+++ b/src/tools/wasm-opcodecnt.cc
@@ -20,6 +20,7 @@
#include <cinttypes>
#include <cstdio>
#include <cstdlib>
+#include <iterator>
#include <map>
#include <vector>
diff --git a/src/tools/wasm-strip.cc b/src/tools/wasm-strip.cc
index c8f3f83c..d80251f9 100644
--- a/src/tools/wasm-strip.cc
+++ b/src/tools/wasm-strip.cc
@@ -69,7 +69,7 @@ class BinaryReaderStrip : public BinaryReaderNop {
return Result::Ok;
}
- Result WriteToFile(string_view filename) {
+ Result WriteToFile(std::string_view filename) {
return stream_.WriteToFile(filename);
}
diff --git a/src/tools/wasm2c.cc b/src/tools/wasm2c.cc
index a20b7e4b..656e5312 100644
--- a/src/tools/wasm2c.cc
+++ b/src/tools/wasm2c.cc
@@ -97,9 +97,9 @@ static void ParseOptions(int argc, char** argv) {
}
// TODO(binji): copied from binary-writer-spec.cc, probably should share.
-static string_view strip_extension(string_view s) {
- string_view ext = s.substr(s.find_last_of('.'));
- string_view result = s;
+static std::string_view strip_extension(std::string_view s) {
+ std::string_view ext = s.substr(s.find_last_of('.'));
+ std::string_view result = s;
if (ext == ".c")
result.remove_suffix(ext.length());
@@ -141,12 +141,13 @@ int ProgramMain(int argc, char** argv) {
if (Succeeded(result)) {
if (!s_outfile.empty()) {
std::string header_name_full =
- strip_extension(s_outfile).to_string() + ".h";
+ std::string(strip_extension(s_outfile)) + ".h";
FileStream c_stream(s_outfile.c_str());
FileStream h_stream(header_name_full);
- string_view header_name = GetBasename(header_name_full);
- result = WriteC(&c_stream, &h_stream, header_name.to_string().c_str(),
- &module, s_write_c_options);
+ std::string_view header_name = GetBasename(header_name_full);
+ result =
+ WriteC(&c_stream, &h_stream, std::string(header_name).c_str(),
+ &module, s_write_c_options);
} else {
FileStream stream(stdout);
result =
diff --git a/src/tools/wast2json.cc b/src/tools/wast2json.cc
index 0418c9a7..1a79cfbc 100644
--- a/src/tools/wast2json.cc
+++ b/src/tools/wast2json.cc
@@ -89,7 +89,7 @@ static void ParseOptions(int argc, char* argv[]) {
parser.Parse(argc, argv);
}
-static std::string DefaultOuputName(string_view input_name) {
+static std::string DefaultOuputName(std::string_view input_name) {
// Strip existing extension and add .json
std::string result(StripExtension(GetBasename(input_name)));
result += ".json";
@@ -128,7 +128,7 @@ int ProgramMain(int argc, char** argv) {
std::vector<FilenameMemoryStreamPair> module_streams;
MemoryStream json_stream;
- std::string output_basename = StripExtension(s_outfile).to_string();
+ std::string output_basename(StripExtension(s_outfile));
s_write_binary_options.features = s_features;
result = WriteBinarySpecScript(&json_stream, script.get(), s_infile,
output_basename, s_write_binary_options,
diff --git a/src/tools/wat2wasm.cc b/src/tools/wat2wasm.cc
index 4a71b572..c0c25e64 100644
--- a/src/tools/wat2wasm.cc
+++ b/src/tools/wat2wasm.cc
@@ -98,7 +98,7 @@ static void ParseOptions(int argc, char* argv[]) {
parser.Parse(argc, argv);
}
-static void WriteBufferToFile(string_view filename,
+static void WriteBufferToFile(std::string_view filename,
const OutputBuffer& buffer) {
if (s_dump_module) {
std::unique_ptr<FileStream> stream = FileStream::CreateStdout();
@@ -113,7 +113,7 @@ static void WriteBufferToFile(string_view filename,
buffer.WriteToFile(filename);
}
-static std::string DefaultOuputName(string_view input_name) {
+static std::string DefaultOuputName(std::string_view input_name) {
// Strip existing extension and add .wasm
std::string result(StripExtension(GetBasename(input_name)));
result += kWasmExtension;
diff --git a/src/wast-lexer.cc b/src/wast-lexer.cc
index 05ac736a..b92b5cc1 100644
--- a/src/wast-lexer.cc
+++ b/src/wast-lexer.cc
@@ -34,7 +34,8 @@ namespace {
} // namespace
-WastLexer::WastLexer(std::unique_ptr<LexerSource> source, string_view filename)
+WastLexer::WastLexer(std::unique_ptr<LexerSource> source,
+ std::string_view filename)
: source_(std::move(source)),
filename_(filename),
line_(1),
@@ -45,9 +46,10 @@ WastLexer::WastLexer(std::unique_ptr<LexerSource> source, string_view filename)
cursor_(buffer_) {}
// static
-std::unique_ptr<WastLexer> WastLexer::CreateBufferLexer(string_view filename,
- const void* data,
- size_t size) {
+std::unique_ptr<WastLexer> WastLexer::CreateBufferLexer(
+ std::string_view filename,
+ const void* data,
+ size_t size) {
return MakeUnique<WastLexer>(MakeUnique<LexerSource>(data, size), filename);
}
@@ -181,8 +183,9 @@ Location WastLexer::GetLocation() {
return Location(filename_, line_, column(token_start_), column(cursor_));
}
-string_view WastLexer::GetText(size_t offset) {
- return string_view(token_start_ + offset, (cursor_ - token_start_) - offset);
+std::string_view WastLexer::GetText(size_t offset) {
+ return std::string_view(token_start_ + offset,
+ (cursor_ - token_start_) - offset);
}
Token WastLexer::BareToken(TokenType token_type) {
@@ -213,7 +216,7 @@ bool WastLexer::MatchChar(char c) {
return false;
}
-bool WastLexer::MatchString(string_view s) {
+bool WastLexer::MatchString(std::string_view s) {
const char* saved_cursor = cursor_;
for (char c : s) {
if (ReadChar() != c) {
@@ -510,7 +513,8 @@ Token WastLexer::GetNanToken() {
return GetKeywordToken();
}
-Token WastLexer::GetNameEqNumToken(string_view name, TokenType token_type) {
+Token WastLexer::GetNameEqNumToken(std::string_view name,
+ TokenType token_type) {
if (MatchString(name)) {
if (MatchString("0x")) {
if (ReadHexNum() && NoTrailingReservedChars()) {
diff --git a/src/wast-lexer.h b/src/wast-lexer.h
index 985fb8b5..ddb5b4a3 100644
--- a/src/wast-lexer.h
+++ b/src/wast-lexer.h
@@ -38,10 +38,10 @@ class WastLexer {
public:
WABT_DISALLOW_COPY_AND_ASSIGN(WastLexer);
- WastLexer(std::unique_ptr<LexerSource> source, string_view filename);
+ WastLexer(std::unique_ptr<LexerSource> source, std::string_view filename);
// Convenience functions.
- static std::unique_ptr<WastLexer> CreateBufferLexer(string_view filename,
+ static std::unique_ptr<WastLexer> CreateBufferLexer(std::string_view filename,
const void* data,
size_t size);
@@ -57,7 +57,7 @@ class WastLexer {
enum class CharClass { Reserved = 1, Keyword = 2, HexDigit = 4, Digit = 8 };
Location GetLocation();
- string_view GetText(size_t offset = 0);
+ std::string_view GetText(size_t offset = 0);
Token BareToken(TokenType);
Token LiteralToken(TokenType, LiteralType);
@@ -66,7 +66,7 @@ class WastLexer {
int PeekChar();
int ReadChar();
bool MatchChar(char);
- bool MatchString(string_view);
+ bool MatchString(std::string_view);
void Newline();
bool ReadBlockComment(WastParser*); // Returns false if EOF.
bool ReadLineComment(); // Returns false if EOF.
@@ -88,7 +88,7 @@ class WastLexer {
Token GetHexNumberToken(TokenType);
Token GetInfToken();
Token GetNanToken();
- Token GetNameEqNumToken(string_view name, TokenType);
+ Token GetNameEqNumToken(std::string_view name, TokenType);
Token GetIdToken();
Token GetKeywordToken();
Token GetReservedToken();
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 8264522b..99406786 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -42,7 +42,7 @@ bool IsPowerOfTwo(uint32_t x) {
}
template <typename OutputIter>
-void RemoveEscapes(string_view text, OutputIter dest) {
+void RemoveEscapes(std::string_view text, OutputIter dest) {
// Remove surrounding quotes; if any. This may be empty if the string was
// invalid (e.g. if it contained a bad escape sequence).
if (text.size() <= 2) {
@@ -98,11 +98,11 @@ void RemoveEscapes(string_view text, OutputIter dest) {
}
}
-typedef std::vector<string_view> TextVector;
+typedef std::vector<std::string_view> TextVector;
template <typename OutputIter>
void RemoveEscapes(const TextVector& texts, OutputIter out) {
- for (string_view text : texts)
+ for (std::string_view text : texts)
RemoveEscapes(text, out);
}
@@ -706,7 +706,7 @@ bool WastParser::ParseBindVarOpt(std::string* name) {
return false;
}
Token token = Consume();
- *name = token.text().to_string();
+ *name = std::string(token.text());
return true;
}
@@ -714,9 +714,9 @@ Result WastParser::ParseVar(Var* out_var) {
WABT_TRACE(ParseVar);
if (PeekMatch(TokenType::Nat)) {
Token token = Consume();
- string_view sv = token.literal().text;
+ std::string_view sv = token.literal().text;
uint64_t index = kInvalidIndex;
- if (Failed(ParseUint64(sv.begin(), sv.end(), &index))) {
+ if (Failed(ParseUint64(sv, &index))) {
// Print an error, but don't fail parsing.
Error(token.loc, "invalid int \"" PRIstringview "\"",
WABT_PRINTF_STRING_VIEW_ARG(sv));
@@ -986,9 +986,8 @@ bool WastParser::ParseOffsetOpt(Address* out_offset) {
if (PeekMatch(TokenType::OffsetEqNat)) {
Token token = Consume();
uint64_t offset64;
- string_view sv = token.text();
- if (Failed(ParseInt64(sv.begin(), sv.end(), &offset64,
- ParseIntType::SignedAndUnsigned))) {
+ std::string_view sv = token.text();
+ if (Failed(ParseInt64(sv, &offset64, ParseIntType::SignedAndUnsigned))) {
Error(token.loc, "invalid offset \"" PRIstringview "\"",
WABT_PRINTF_STRING_VIEW_ARG(sv));
}
@@ -1008,9 +1007,8 @@ bool WastParser::ParseAlignOpt(Address* out_align) {
WABT_TRACE(ParseAlignOpt);
if (PeekMatch(TokenType::AlignEqNat)) {
Token token = Consume();
- string_view sv = token.text();
- if (Failed(ParseInt64(sv.begin(), sv.end(), out_align,
- ParseIntType::UnsignedOnly))) {
+ std::string_view sv = token.text();
+ if (Failed(ParseInt64(sv, out_align, ParseIntType::UnsignedOnly))) {
Error(token.loc, "invalid alignment \"" PRIstringview "\"",
WABT_PRINTF_STRING_VIEW_ARG(sv));
}
@@ -1088,9 +1086,8 @@ Result WastParser::ParseNat(uint64_t* out_nat, bool is_64) {
}
Token token = Consume();
- string_view sv = token.literal().text;
- if (Failed(ParseUint64(sv.begin(), sv.end(), out_nat)) ||
- (!is_64 && *out_nat > 0xffffffffu)) {
+ std::string_view sv = token.literal().text;
+ if (Failed(ParseUint64(sv, out_nat)) || (!is_64 && *out_nat > 0xffffffffu)) {
Error(token.loc, "invalid int \"" PRIstringview "\"",
WABT_PRINTF_STRING_VIEW_ARG(sv));
}
@@ -2003,8 +2000,8 @@ Result WastParser::ParseSimdLane(Location loc, uint64_t* lane_idx) {
Literal literal = Consume().literal();
- Result result = ParseInt64(literal.text.begin(), literal.text.end(), lane_idx,
- ParseIntType::UnsignedOnly);
+ Result result =
+ ParseInt64(literal.text, lane_idx, ParseIntType::UnsignedOnly);
if (Failed(result)) {
Error(loc, "invalid literal \"" PRIstringview "\"",
@@ -2482,32 +2479,30 @@ Result WastParser::ParseSimdV128Const(Const* const_,
// For each type, parse the next literal, bound check it, and write it to
// the array of bytes:
if (integer) {
- string_view sv = Consume().literal().text;
- const char* s = sv.begin();
- const char* end = sv.end();
+ std::string_view sv = Consume().literal().text;
switch (lane_count) {
case 16: {
uint8_t value = 0;
- result = ParseInt8(s, end, &value, ParseIntType::SignedAndUnsigned);
+ result = ParseInt8(sv, &value, ParseIntType::SignedAndUnsigned);
const_->set_v128_u8(lane, value);
break;
}
case 8: {
uint16_t value = 0;
- result = ParseInt16(s, end, &value, ParseIntType::SignedAndUnsigned);
+ result = ParseInt16(sv, &value, ParseIntType::SignedAndUnsigned);
const_->set_v128_u16(lane, value);
break;
}
case 4: {
uint32_t value = 0;
- result = ParseInt32(s, end, &value, ParseIntType::SignedAndUnsigned);
+ result = ParseInt32(sv, &value, ParseIntType::SignedAndUnsigned);
const_->set_v128_u32(lane, value);
break;
}
case 2: {
uint64_t value = 0;
- result = ParseInt64(s, end, &value, ParseIntType::SignedAndUnsigned);
+ result = ParseInt64(sv, &value, ParseIntType::SignedAndUnsigned);
const_->set_v128_u64(lane, value);
break;
}
@@ -2570,8 +2565,7 @@ Result WastParser::ParseF32(Const* const_, ConstType const_type) {
auto literal = token.literal();
uint32_t f32_bits;
- Result result = ParseFloat(literal.type, literal.text.begin(),
- literal.text.end(), &f32_bits);
+ Result result = ParseFloat(literal.type, literal.text, &f32_bits);
const_->set_f32(f32_bits);
return result;
}
@@ -2591,8 +2585,7 @@ Result WastParser::ParseF64(Const* const_, ConstType const_type) {
auto literal = token.literal();
uint64_t f64_bits;
- Result result = ParseDouble(literal.type, literal.text.begin(),
- literal.text.end(), &f64_bits);
+ Result result = ParseDouble(literal.type, literal.text, &f64_bits);
const_->set_f64(f64_bits);
return result;
}
@@ -2629,8 +2622,7 @@ Result WastParser::ParseConst(Const* const_, ConstType const_type) {
}
auto sv = token.literal().text;
uint32_t u32;
- result = ParseInt32(sv.begin(), sv.end(), &u32,
- ParseIntType::SignedAndUnsigned);
+ result = ParseInt32(sv, &u32, ParseIntType::SignedAndUnsigned);
const_->set_u32(u32);
break;
}
@@ -2642,8 +2634,7 @@ Result WastParser::ParseConst(Const* const_, ConstType const_type) {
}
auto sv = token.literal().text;
uint64_t u64;
- result = ParseInt64(sv.begin(), sv.end(), &u64,
- ParseIntType::SignedAndUnsigned);
+ result = ParseInt64(sv, &u64, ParseIntType::SignedAndUnsigned);
const_->set_u64(u64);
break;
}
@@ -2690,9 +2681,7 @@ Result WastParser::ParseExternref(Const* const_) {
}
Literal literal;
- string_view sv;
- const char* s;
- const char* end;
+ std::string_view sv;
const_->loc = GetLocation();
TokenType token_type = Peek();
@@ -2701,8 +2690,6 @@ Result WastParser::ParseExternref(Const* const_) {
case TokenType::Int: {
literal = Consume().literal();
sv = literal.text;
- s = sv.begin();
- end = sv.end();
break;
}
default:
@@ -2710,7 +2697,7 @@ Result WastParser::ParseExternref(Const* const_) {
}
uint64_t ref_bits;
- Result result = ParseInt64(s, end, &ref_bits, ParseIntType::UnsignedOnly);
+ Result result = ParseInt64(sv, &ref_bits, ParseIntType::UnsignedOnly);
const_->set_externref(static_cast<uintptr_t>(ref_bits));
@@ -2846,7 +2833,7 @@ Result WastParser::ParseBlockInstr(std::unique_ptr<Expr>* out_expr) {
Result WastParser::ParseLabelOpt(std::string* out_label) {
WABT_TRACE(ParseLabelOpt);
if (PeekMatch(TokenType::Var)) {
- *out_label = Consume().text().to_string();
+ *out_label = std::string(Consume().text());
} else {
out_label->clear();
}
diff --git a/src/wat-writer.cc b/src/wat-writer.cc
index 701134ce..fd4a5f43 100644
--- a/src/wat-writer.cc
+++ b/src/wat-writer.cc
@@ -117,10 +117,10 @@ class WatWriter : ModuleContext {
void WriteCloseNewline();
void WriteCloseSpace();
void WriteString(const std::string& str, NextChar next_char);
- void WriteName(string_view str, NextChar next_char);
- void WriteNameOrIndex(string_view str, Index index, NextChar next_char);
+ void WriteName(std::string_view str, NextChar next_char);
+ void WriteNameOrIndex(std::string_view str, Index index, NextChar next_char);
void WriteQuotedData(const void* data, size_t length);
- void WriteQuotedString(string_view str, NextChar next_char);
+ void WriteQuotedString(std::string_view str, NextChar next_char);
void WriteVar(const Var& var, NextChar next_char);
void WriteVarUnlessZero(const Var& var, NextChar next_char);
void WriteMemoryVarUnlessZero(const Var& memidx, NextChar next_char);
@@ -311,7 +311,7 @@ void WatWriter::WriteString(const std::string& str, NextChar next_char) {
WritePuts(str.c_str(), next_char);
}
-void WatWriter::WriteName(string_view str, NextChar next_char) {
+void WatWriter::WriteName(std::string_view str, NextChar next_char) {
// Debug names must begin with a $ for for wast file to be valid
assert(!str.empty() && str.front() == '$');
bool has_invalid_chars = std::any_of(
@@ -329,7 +329,7 @@ void WatWriter::WriteName(string_view str, NextChar next_char) {
next_char_ = next_char;
}
-void WatWriter::WriteNameOrIndex(string_view str,
+void WatWriter::WriteNameOrIndex(std::string_view str,
Index index,
NextChar next_char) {
if (!str.empty()) {
@@ -358,7 +358,7 @@ void WatWriter::WriteQuotedData(const void* data, size_t length) {
next_char_ = NextChar::Space;
}
-void WatWriter::WriteQuotedString(string_view str, NextChar next_char) {
+void WatWriter::WriteQuotedString(std::string_view str, NextChar next_char) {
WriteQuotedData(str.data(), str.length());
next_char_ = next_char;
}