summaryrefslogtreecommitdiff
path: root/src/resolve-names.cc
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2017-07-06 17:30:02 -0700
committerGitHub <noreply@github.com>2017-07-06 17:30:02 -0700
commit12d228447c7ffcdb0bdb9a2af828b0b374975623 (patch)
tree77b666c95589c96f19f2c76cbb6a83f9f5307479 /src/resolve-names.cc
parenta5066278b34021de22b150442cb7a94d62e22102 (diff)
downloadwabt-12d228447c7ffcdb0bdb9a2af828b0b374975623.tar.gz
wabt-12d228447c7ffcdb0bdb9a2af828b0b374975623.tar.bz2
wabt-12d228447c7ffcdb0bdb9a2af828b0b374975623.zip
Use std::string instead of StringSlice in Var (#556)
This change keeps the union, but hides it behind accessors. The implementation is a bit complex since std::string requires constructors and destructors to be called. As a result we have to use placement new and explicit destructors.
Diffstat (limited to 'src/resolve-names.cc')
-rw-r--r--src/resolve-names.cc32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/resolve-names.cc b/src/resolve-names.cc
index 1fdf81a7..ca31b73c 100644
--- a/src/resolve-names.cc
+++ b/src/resolve-names.cc
@@ -134,35 +134,31 @@ void NameResolver::CheckDuplicateBindings(const BindingHash* bindings,
}
void NameResolver::ResolveLabelVar(Var* var) {
- if (var->type == VarType::Name) {
+ if (var->is_name()) {
for (int i = labels_.size() - 1; i >= 0; --i) {
Label* label = labels_[i];
- if (string_slices_are_equal(label, &var->name)) {
- destroy_string_slice(&var->name);
- var->type = VarType::Index;
- var->index = labels_.size() - i - 1;
+ if (string_slice_to_string(*label) == var->name()) {
+ var->set_index(labels_.size() - i - 1);
return;
}
}
- PrintError(&var->loc, "undefined label variable \"" PRIstringslice "\"",
- WABT_PRINTF_STRING_SLICE_ARG(var->name));
+ PrintError(&var->loc, "undefined label variable \"%s\"",
+ var->name().c_str());
}
}
void NameResolver::ResolveVar(const BindingHash* bindings,
Var* var,
const char* desc) {
- if (var->type == VarType::Name) {
+ if (var->is_name()) {
Index index = bindings->FindIndex(*var);
if (index == kInvalidIndex) {
- PrintError(&var->loc, "undefined %s variable \"" PRIstringslice "\"",
- desc, WABT_PRINTF_STRING_SLICE_ARG(var->name));
+ PrintError(&var->loc, "undefined %s variable \"%s\"", desc,
+ var->name().c_str());
return;
}
- destroy_string_slice(&var->name);
- var->index = index;
- var->type = VarType::Index;
+ var->set_index(index);
}
}
@@ -191,20 +187,18 @@ void NameResolver::ResolveExceptionVar(Var* var) {
}
void NameResolver::ResolveLocalVar(Var* var) {
- if (var->type == VarType::Name) {
+ if (var->is_name()) {
if (!current_func_)
return;
Index index = current_func_->GetLocalIndex(*var);
if (index == kInvalidIndex) {
- PrintError(&var->loc, "undefined local variable \"" PRIstringslice "\"",
- WABT_PRINTF_STRING_SLICE_ARG(var->name));
+ PrintError(&var->loc, "undefined local variable \"%s\"",
+ var->name().c_str());
return;
}
- destroy_string_slice(&var->name);
- var->index = index;
- var->type = VarType::Index;
+ var->set_index(index);
}
}