1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:57:45 +00:00

LibIDL+LibWeb: Resolve distinguishing argument index at build time

Aside from the obvious performance benefits, this will allow us to
properly handle dictionary types. (whose dictionary-ness is only known
at build-time)

Much of the rest of the overload resolution algorithm steps can (and
should) be evaluated at build-time as well, but this is a good first
step.
This commit is contained in:
Idan Horowitz 2023-11-10 23:38:59 +02:00 committed by Andreas Kling
parent 048e179572
commit f837f02eea
4 changed files with 44 additions and 43 deletions

View file

@ -293,30 +293,6 @@ bool Type::is_json(Interface const& interface) const
return false;
}
// https://webidl.spec.whatwg.org/#dfn-distinguishing-argument-index
int EffectiveOverloadSet::distinguishing_argument_index()
{
for (auto argument_index = 0u; argument_index < m_argument_count; ++argument_index) {
bool found_indistinguishable = false;
for (auto first_item_index = 0u; first_item_index < m_items.size(); ++first_item_index) {
for (auto second_item_index = first_item_index + 1; second_item_index < m_items.size(); ++second_item_index) {
if (!m_items[first_item_index].types[argument_index]->is_distinguishable_from(m_items[second_item_index].types[argument_index])) {
found_indistinguishable = true;
break;
}
}
if (found_indistinguishable)
break;
}
if (!found_indistinguishable)
return argument_index;
}
VERIFY_NOT_REACHED();
}
void EffectiveOverloadSet::remove_all_other_entries()
{
Vector<Item> new_items;

View file

@ -415,9 +415,9 @@ public:
Vector<Optionality> optionality_values;
};
EffectiveOverloadSet(Vector<Item> items)
EffectiveOverloadSet(Vector<Item> items, size_t distinguishing_argument_index)
: m_items(move(items))
, m_argument_count(m_items.is_empty() ? 0 : m_items.first().types.size())
, m_distinguishing_argument_index(distinguishing_argument_index)
{
}
@ -433,7 +433,7 @@ public:
bool is_empty() const { return m_items.is_empty(); }
size_t size() const { return m_items.size(); }
int distinguishing_argument_index();
size_t distinguishing_argument_index() const { return m_distinguishing_argument_index; }
template<typename Matches>
bool has_overload_with_matching_argument_at_index(size_t index, Matches matches)
@ -454,7 +454,7 @@ public:
private:
// FIXME: This should be an "ordered set".
Vector<Item> m_items;
size_t m_argument_count;
size_t m_distinguishing_argument_index { 0 };
Optional<size_t> m_last_matching_item_index;
};