• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 14823373998

04 May 2025 05:03PM UTC coverage: 86.442% (+0.03%) from 86.409%
14823373998

push

github

SuperFola
fix: change the color of the function name inside runtime typechecking errors from blue to cyan to be easier to read inside dark terminals

0 of 1 new or added line in 1 file covered. (0.0%)

195 existing lines in 22 files now uncovered.

6835 of 7907 relevant lines covered (86.44%)

79668.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.41
/src/arkreactor/Compiler/NameResolution/StaticScope.cpp
1
#include <Ark/Compiler/NameResolution/StaticScope.hpp>
2

3
#include <utility>
4
#include <ranges>
5
#include <fmt/format.h>
6

7
namespace Ark::internal
8
{
9
    std::string StaticScope::add(const std::string& name, bool is_mutable)
10,635✔
10
    {
10,635✔
11
        m_vars.emplace(name, name, is_mutable);
10,635✔
12
        return name;
10,635✔
13
    }
14

15
    std::optional<Declaration> StaticScope::get(const std::string& name, [[maybe_unused]] const bool extensive_lookup)
92,413✔
16
    {
92,413✔
17
        if (const auto it = std::ranges::find(m_vars, name, &Declaration::name); it != m_vars.end())
121,852✔
18
            return *it;
29,439✔
19
        return std::nullopt;
62,974✔
20
    }
92,413✔
21

22
    std::string StaticScope::fullyQualifiedName(const std::string& name) const
×
23
    {
×
UNCOV
24
        return name;
×
25
    }
26

27
    bool StaticScope::saveNamespace([[maybe_unused]] std::unique_ptr<StaticScope>&)
×
UNCOV
28
    {
×
29
        // the scope can not be saved on a static scope
UNCOV
30
        return false;
×
31
    }
32

33
    bool StaticScope::isNamespace() const
586✔
34
    {
586✔
35
        return false;
586✔
36
    }
37

38
    NamespaceScope::NamespaceScope(std::string name, const bool with_prefix, const bool is_glob, const std::vector<std::string>& symbols) :
812✔
39
        StaticScope(),
406✔
40
        m_namespace(std::move(name)),
406✔
41
        m_with_prefix(with_prefix),
406✔
42
        m_is_glob(is_glob),
406✔
43
        m_symbols(symbols)
406✔
44
    {}
812✔
45

46
    std::string NamespaceScope::add(const std::string& name, bool is_mutable)
3,519✔
47
    {
3,519✔
48
        // Since we do multiple passes on namespaces, we need to check if the given name is already hidden,
49
        // so that we can save the name as it was on the first pass
50
        if (name.ends_with("#hidden"))
3,519✔
51
        {
52
            std::string std_name = name.substr(0, name.find_first_of('#'));
1,179✔
53
            return m_vars.emplace(name, std_name, is_mutable).first->name;
1,179✔
54
        }
1,179✔
55

56
        // Otherwise, we also have to check for the presence of a namespace prefix,
57
        // and remove it when checking against the symbols list, to determine if we
58
        // need to hide the name or not
59
        const bool starts_with_prefix = !m_namespace.empty() && name.starts_with(m_namespace + ":");
2,340✔
60
        std::string fqn = fullyQualifiedName(name);
2,340✔
61
        std::string unprefixed_name = starts_with_prefix ? name.substr(name.find_first_of(':') + 1) : name;
2,340✔
62

63
        if (!m_symbols.empty() && !hasSymbol(unprefixed_name) && !m_with_prefix && !m_is_glob)
2,340✔
64
            return m_vars.emplace(fqn + "#hidden", fqn, is_mutable).first->name;
499✔
65
        return m_vars.emplace(fqn, fqn, is_mutable).first->name;
1,841✔
66
    }
3,519✔
67

68
    std::optional<Declaration> NamespaceScope::get(const std::string& name, const bool extensive_lookup)
458,964✔
69
    {
458,964✔
70
        const bool starts_with_prefix = !m_namespace.empty() && name.starts_with(m_namespace + ":");
458,964✔
71
        // If the name starts with the namespace and we imported the namespace with prefix
72
        // search for name in the namespace
73
        if (starts_with_prefix && m_with_prefix)
458,964✔
74
        {
75
            if (const auto it = std::ranges::find(m_vars, name, &Declaration::name); it != m_vars.end())
20,715✔
76
                return *it;
9,745✔
77
        }
1,225✔
78
        // If the name does not start with the prefix, and we import through either glob or symbol list
79
        // search for the name in the namespace
80
        // If the name does not start with the prefix, in a namespace with a symbol list but can be resolved,
81
        // modify it to hide it to the end user
82
        // If the name wasn't qualified, in a prefixed namespace, look up for it but by qualifying the name
83
        else if (!starts_with_prefix)
447,994✔
84
        {
85
            auto it = std::ranges::find(m_vars, fullyQualifiedName(name), &Declaration::name);
444,136✔
86
            auto it_original = std::ranges::find(m_vars, fullyQualifiedName(name), &Declaration::original_name);
444,136✔
87
            if ((m_is_glob || hasSymbol(name) || m_with_prefix) && it != m_vars.end())
444,136✔
88
                return *it;
1,205✔
89
            if (!m_symbols.empty() && it_original != m_vars.end())
442,931✔
90
                return *it_original;
212✔
91
        }
444,136✔
92
        // lookup in the additional saved namespaces
93
        if (extensive_lookup)
447,802✔
94
        {
95
            std::optional<Declaration> decl;
444,943✔
96
            for (const auto& scope : m_additional_namespaces)
759,597✔
97
            {
98
                if (auto maybe_decl = scope->get(name, extensive_lookup); maybe_decl.has_value())
327,539✔
99
                {
100
                    // prioritize non-hidden declarations
101
                    if ((decl.has_value() && decl.value().name.ends_with("#hidden")) || !decl.has_value())
12,885✔
102
                        decl = maybe_decl;
8,138✔
103
                }
12,885✔
104
            }
314,654✔
105
            return decl;
444,943✔
106
        }
444,943✔
107
        // otherwise we didn't find the name in the namespace
108
        return std::nullopt;
2,859✔
109
    }
458,964✔
110

111
    std::string NamespaceScope::fullyQualifiedName(const std::string& name) const
890,668✔
112
    {
890,668✔
113
        const bool starts_with_prefix = !m_namespace.empty() && name.starts_with(m_namespace + ":");
890,668✔
114
        if (!m_namespace.empty() && !starts_with_prefix)
890,668✔
115
            return fmt::format("{}:{}", m_namespace, name);
781,843✔
116
        return name;
108,825✔
117
    }
890,668✔
118

119
    bool NamespaceScope::saveNamespace(std::unique_ptr<StaticScope>& scope)
134✔
120
    {
134✔
121
        m_additional_namespaces.push_back(std::move(scope));
134✔
122
        return true;
134✔
123
    }
124

125
    bool NamespaceScope::isNamespace() const
627✔
126
    {
627✔
127
        return true;
627✔
128
    }
129

130
    bool NamespaceScope::recursiveHasSymbol(const std::string& symbol)
124✔
131
    {
124✔
132
        if (hasSymbol(symbol))
124✔
133
            return true;
38✔
134
        if (isGlob() && std::ranges::find(m_vars, fullyQualifiedName(symbol), &Declaration::name) != m_vars.end())
86✔
135
            return true;
14✔
136

137
        return std::ranges::any_of(
144✔
138
            m_additional_namespaces,
72✔
139
            [&symbol](const auto& saved_scope) {
142✔
140
                return saved_scope->recursiveHasSymbol(symbol);
70✔
141
            });
142
    }
124✔
143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc