13 m_vars.emplace(name, name, is_mutable);
17 std::optional<Declaration>
StaticScope::get(
const std::string& name, [[maybe_unused]]
const std::string& origin_namespace, [[maybe_unused]]
const bool extensive_lookup)
42 m_namespace(
std::move(name)),
43 m_with_prefix(with_prefix),
54 std::string std_name = name.substr(0, name.find_first_of(
'#'));
55 return m_vars.emplace(name, std_name, is_mutable).first->name;
63 const std::string unprefixed_name = starts_with_prefix ? name.substr(name.find_first_of(
':') + 1) : name;
67 return m_vars.emplace(fqn, fqn, is_mutable).first->name;
70 std::optional<Declaration>
NamespaceScope::get(
const std::string& name,
const std::string& origin_namespace,
const bool extensive_lookup)
85 else if (!starts_with_prefix)
90 auto it_original =
m_vars.end();
91 for (
auto j =
m_vars.begin(), end =
m_vars.end(); j != end; ++j)
95 if (j->original_name == fqn)
98 if (it != end && it_original != end)
108 if (extensive_lookup)
110 std::optional<Declaration> decl;
113 if (
auto maybe_decl = scope->get(name, origin_namespace, extensive_lookup); maybe_decl.has_value())
116 if ((decl.has_value() && decl->name.ends_with(
HiddenSymbolSuffix)) || !decl.has_value())
152 return std::ranges::any_of(
154 [&symbol](
const auto& saved_scope) {
155 return saved_scope->recursiveHasSymbol(symbol);
Common code for the compiler.
Static scopes (for functions, loops) and namespace scopes (for packages) definitions,...
bool saveNamespace(std::unique_ptr< StaticScope > &) override
Save a namespace scope to help with lookup.
std::string fullyQualifiedName(const std::string &name) const override
Given a Declaration name, compute its fully qualified name.
std::unordered_set< Declaration > m_vars
bool isGlob() const override
bool hasSymbol(const std::string &symbol) const override
bool isNamespace() const override
NamespaceScope(std::string name, bool with_prefix, bool is_glob, const std::vector< std::string > &symbols)
std::vector< std::string > m_symbols
std::string add(const std::string &name, bool is_mutable) override
Add a Declaration to the scope, given a mutability status.
std::optional< Declaration > get(const std::string &name, const std::string &origin_namespace, bool extensive_lookup) override
Try to return a Declaration from this scope with a given name.
std::vector< std::unique_ptr< StaticScope > > m_additional_namespaces
bool recursiveHasSymbol(const std::string &symbol) override
std::unordered_set< Declaration > m_vars
virtual std::optional< Declaration > get(const std::string &name, const std::string &origin_namespace, bool extensive_lookup)
Try to return a Declaration from this scope with a given name.
virtual bool saveNamespace(std::unique_ptr< StaticScope > &)
Save a namespace scope to help with lookup.
virtual bool isNamespace() const
virtual std::string add(const std::string &name, bool is_mutable)
Add a Declaration to the scope, given a mutability status.
virtual std::string fullyQualifiedName(const std::string &name) const
Given a Declaration name, compute its fully qualified name.
constexpr std::string_view HiddenSymbolSuffix
std::string name
End name, can be modified to be hidden.