Commit 0bb21f11 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] allow Context as type for js-implicit context

Drive-by cleanup: improve prining of lists

Bug: v8:7793
Change-Id: I84d2d5c64ae3cb564acf53d93ea4f12a829b787d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1967328Reviewed-by: 's avatarJoshua Litt <joshualitt@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65451}
parent d1aaf9da
...@@ -460,13 +460,14 @@ void ImplementationVisitor::Visit(Builtin* builtin) { ...@@ -460,13 +460,14 @@ void ImplementationVisitor::Visit(Builtin* builtin) {
std::string generated_name = AddParameter( std::string generated_name = AddParameter(
i, builtin, &parameters, &parameter_types, &parameter_bindings, true); i, builtin, &parameters, &parameter_types, &parameter_bindings, true);
const Type* actual_type = signature.parameter_types.types[i]; const Type* actual_type = signature.parameter_types.types[i];
const Type* expected_type; std::vector<const Type*> expected_types;
if (param_name == "context") { if (param_name == "context") {
source_out() << " TNode<NativeContext> " << generated_name source_out() << " TNode<NativeContext> " << generated_name
<< " = UncheckedCast<NativeContext>(Parameter(" << " = UncheckedCast<NativeContext>(Parameter("
<< "Descriptor::kContext));\n"; << "Descriptor::kContext));\n";
source_out() << " USE(" << generated_name << ");\n"; source_out() << " USE(" << generated_name << ");\n";
expected_type = TypeOracle::GetNativeContextType(); expected_types = {TypeOracle::GetNativeContextType(),
TypeOracle::GetContextType()};
} else if (param_name == "receiver") { } else if (param_name == "receiver") {
source_out() source_out()
<< " TNode<Object> " << generated_name << " = " << " TNode<Object> " << generated_name << " = "
...@@ -475,31 +476,32 @@ void ImplementationVisitor::Visit(Builtin* builtin) { ...@@ -475,31 +476,32 @@ void ImplementationVisitor::Visit(Builtin* builtin) {
: "UncheckedCast<Object>(Parameter(Descriptor::kReceiver))") : "UncheckedCast<Object>(Parameter(Descriptor::kReceiver))")
<< ";\n"; << ";\n";
source_out() << "USE(" << generated_name << ");\n"; source_out() << "USE(" << generated_name << ");\n";
expected_type = TypeOracle::GetJSAnyType(); expected_types = {TypeOracle::GetJSAnyType()};
} else if (param_name == "newTarget") { } else if (param_name == "newTarget") {
source_out() << " TNode<Object> " << generated_name source_out() << " TNode<Object> " << generated_name
<< " = UncheckedCast<Object>(Parameter(" << " = UncheckedCast<Object>(Parameter("
<< "Descriptor::kJSNewTarget));\n"; << "Descriptor::kJSNewTarget));\n";
source_out() << "USE(" << generated_name << ");\n"; source_out() << "USE(" << generated_name << ");\n";
expected_type = TypeOracle::GetJSAnyType(); expected_types = {TypeOracle::GetJSAnyType()};
} else if (param_name == "target") { } else if (param_name == "target") {
source_out() << " TNode<JSFunction> " << generated_name source_out() << " TNode<JSFunction> " << generated_name
<< " = UncheckedCast<JSFunction>(Parameter(" << " = UncheckedCast<JSFunction>(Parameter("
<< "Descriptor::kJSTarget));\n"; << "Descriptor::kJSTarget));\n";
source_out() << "USE(" << generated_name << ");\n"; source_out() << "USE(" << generated_name << ");\n";
expected_type = TypeOracle::GetJSFunctionType(); expected_types = {TypeOracle::GetJSFunctionType()};
} else { } else {
Error( Error(
"Unexpected implicit parameter \"", param_name, "Unexpected implicit parameter \"", param_name,
"\" for JavaScript calling convention, " "\" for JavaScript calling convention, "
"expected \"context\", \"receiver\", \"target\", or \"newTarget\"") "expected \"context\", \"receiver\", \"target\", or \"newTarget\"")
.Position(param_pos); .Position(param_pos);
expected_type = actual_type; expected_types = {actual_type};
} }
if (actual_type != expected_type) { if (std::find(expected_types.begin(), expected_types.end(),
actual_type) == expected_types.end()) {
Error("According to JavaScript calling convention, expected parameter ", Error("According to JavaScript calling convention, expected parameter ",
param_name, " to have type ", *expected_type, " but found type ", param_name, " to have type ", PrintList(expected_types, " or "),
*actual_type) " but found type ", *actual_type)
.Position(param_pos); .Position(param_pos);
} }
} }
......
...@@ -118,47 +118,56 @@ class Deduplicator { ...@@ -118,47 +118,56 @@ class Deduplicator {
std::unordered_set<T, base::hash<T>> storage_; std::unordered_set<T, base::hash<T>> storage_;
}; };
template <class C, class T> template <class T>
void PrintCommaSeparatedList(std::ostream& os, const T& list, C transform) { T& DereferenceIfPointer(T* x) {
bool first = true; return *x;
for (auto& e : list) { }
if (first) { template <class T>
first = false; T&& DereferenceIfPointer(T&& x) {
} else { return std::forward<T>(x);
os << ", ";
}
os << transform(e);
}
} }
template <class T, template <class T, class L>
typename std::enable_if< struct ListPrintAdaptor {
std::is_pointer<typename T::value_type>::value, int>::type = 0> const T& list;
void PrintCommaSeparatedList(std::ostream& os, const T& list) { const std::string& separator;
L transformer;
friend std::ostream& operator<<(std::ostream& os, const ListPrintAdaptor& l) {
bool first = true; bool first = true;
for (auto& e : list) { for (auto& e : l.list) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
os << ", "; os << l.separator;
} }
os << *e; os << DereferenceIfPointer(l.transformer(e));
} }
return os;
}
};
template <class T>
auto PrintList(const T& list, const std::string& separator = ", ") {
using ElementType = decltype(*list.begin());
auto id = [](ElementType el) { return el; };
return ListPrintAdaptor<T, decltype(id)>{list, separator, id};
}
template <class T, class L>
auto PrintList(const T& list, const std::string& separator, L&& transformer) {
return ListPrintAdaptor<T, L&&>{list, separator,
std::forward<L>(transformer)};
}
template <class C, class T>
void PrintCommaSeparatedList(std::ostream& os, const T& list, C&& transform) {
os << PrintList(list, ", ", std::forward<C>(transform));
} }
template <class T, template <class T>
typename std::enable_if<
!std::is_pointer<typename T::value_type>::value, int>::type = 0>
void PrintCommaSeparatedList(std::ostream& os, const T& list) { void PrintCommaSeparatedList(std::ostream& os, const T& list) {
bool first = true; os << PrintList(list, ", ");
for (auto& e : list) {
if (first) {
first = false;
} else {
os << ", ";
}
os << e;
}
} }
struct BottomOffset { struct BottomOffset {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment