FaceRegistry: Support referencing a named face from a parent scope

This commit is contained in:
Maxime Coste 2018-04-10 19:57:16 +10:00
parent a2978bff25
commit 9c82f6586c

View File

@ -98,27 +98,27 @@ void FaceRegistry::add_face(StringView name, StringView facedesc, bool override)
if (name == facedesc) if (name == facedesc)
throw runtime_error(format("cannot alias face '{}' to itself", name)); throw runtime_error(format("cannot alias face '{}' to itself", name));
FaceOrAlias& face = m_faces[name]; for (auto it = m_faces.find(facedesc);
auto it = m_faces.find(facedesc); it != m_faces.end() and not it->value.alias.empty();
if (it != m_faces.end()) it = m_faces.find(it->value.alias))
{ {
while (it != m_faces.end())
{
if (it->value.alias.empty())
break;
if (it->value.alias == name) if (it->value.alias == name)
throw runtime_error("face cycle detected"); throw runtime_error("face cycle detected");
it = m_faces.find(it->value.alias);
} }
face.alias = facedesc.str(); FaceOrAlias& face = m_faces[name];
}
else for (auto* registry = this; registry != nullptr; registry = registry->m_parent.get())
{ {
if (not registry->m_faces.contains(facedesc))
continue;
face.alias = facedesc.str(); // This is referencing another face
return;
}
face.alias = ""; face.alias = "";
face.face = parse_face(facedesc); face.face = parse_face(facedesc);
} }
}
void FaceRegistry::remove_face(StringView name) void FaceRegistry::remove_face(StringView name)
{ {