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) {
std::string generated_name = AddParameter(
i, builtin, &parameters, &parameter_types, &parameter_bindings, true);
const Type* actual_type = signature.parameter_types.types[i];
const Type* expected_type;
std::vector<const Type*> expected_types;
if (param_name == "context") {
source_out() << " TNode<NativeContext> " << generated_name
<< " = UncheckedCast<NativeContext>(Parameter("
<< "Descriptor::kContext));\n";
source_out() << " USE(" << generated_name << ");\n";
expected_type = TypeOracle::GetNativeContextType();
expected_types = {TypeOracle::GetNativeContextType(),
TypeOracle::GetContextType()};
} else if (param_name == "receiver") {
source_out()
<< " TNode<Object> " << generated_name << " = "
......@@ -475,31 +476,32 @@ void ImplementationVisitor::Visit(Builtin* builtin) {
: "UncheckedCast<Object>(Parameter(Descriptor::kReceiver))")
<< ";\n";
source_out() << "USE(" << generated_name << ");\n";
expected_type = TypeOracle::GetJSAnyType();
expected_types = {TypeOracle::GetJSAnyType()};
} else if (param_name == "newTarget") {
source_out() << " TNode<Object> " << generated_name
<< " = UncheckedCast<Object>(Parameter("
<< "Descriptor::kJSNewTarget));\n";
source_out() << "USE(" << generated_name << ");\n";
expected_type = TypeOracle::GetJSAnyType();
expected_types = {TypeOracle::GetJSAnyType()};
} else if (param_name == "target") {
source_out() << " TNode<JSFunction> " << generated_name
<< " = UncheckedCast<JSFunction>(Parameter("
<< "Descriptor::kJSTarget));\n";
source_out() << "USE(" << generated_name << ");\n";
expected_type = TypeOracle::GetJSFunctionType();
expected_types = {TypeOracle::GetJSFunctionType()};
} else {
Error(
"Unexpected implicit parameter \"", param_name,
"\" for JavaScript calling convention, "
"expected \"context\", \"receiver\", \"target\", or \"newTarget\"")
.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 ",
param_name, " to have type ", *expected_type, " but found type ",
*actual_type)
param_name, " to have type ", PrintList(expected_types, " or "),
" but found type ", *actual_type)
.Position(param_pos);
}
}
......
......@@ -118,47 +118,56 @@ class Deduplicator {
std::unordered_set<T, base::hash<T>> storage_;
};
template <class C, class T>
void PrintCommaSeparatedList(std::ostream& os, const T& list, C transform) {
bool first = true;
for (auto& e : list) {
if (first) {
first = false;
} else {
os << ", ";
}
os << transform(e);
}
template <class T>
T& DereferenceIfPointer(T* x) {
return *x;
}
template <class T>
T&& DereferenceIfPointer(T&& x) {
return std::forward<T>(x);
}
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) {
bool first = true;
for (auto& e : list) {
if (first) {
first = false;
} else {
os << ", ";
template <class T, class L>
struct ListPrintAdaptor {
const T& list;
const std::string& separator;
L transformer;
friend std::ostream& operator<<(std::ostream& os, const ListPrintAdaptor& l) {
bool first = true;
for (auto& e : l.list) {
if (first) {
first = false;
} else {
os << l.separator;
}
os << DereferenceIfPointer(l.transformer(e));
}
os << *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,
typename std::enable_if<
!std::is_pointer<typename T::value_type>::value, int>::type = 0>
template <class T>
void PrintCommaSeparatedList(std::ostream& os, const T& list) {
bool first = true;
for (auto& e : list) {
if (first) {
first = false;
} else {
os << ", ";
}
os << e;
}
os << PrintList(list, ", ");
}
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