• 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

96.3
/src/arkreactor/Compiler/NameResolution/ScopeResolver.cpp
1
#include <Ark/Compiler/NameResolution/ScopeResolver.hpp>
2

3
#include <ranges>
4

5
namespace Ark::internal
6
{
7
    ScopeResolver::ScopeResolver()
271✔
8
    {
271✔
9
        createNewNamespace("", /* with_prefix= */ false, /* is_glob= */ true, /* symbols= */ {});
271✔
10
    }
271✔
11

12
    void ScopeResolver::createNew()
5,181✔
13
    {
5,181✔
14
        m_scopes.emplace_back(std::make_unique<StaticScope>());
5,181✔
15
    }
5,181✔
16

17
    void ScopeResolver::removeLastScope()
5,179✔
18
    {
5,179✔
19
        m_scopes.pop_back();
5,179✔
20
    }
5,179✔
21

22
    void ScopeResolver::createNewNamespace(const std::string& name, bool with_prefix, bool is_glob, const std::vector<std::string>& symbols)
406✔
23
    {
406✔
24
        m_scopes.emplace_back(std::make_unique<NamespaceScope>(name, with_prefix, is_glob, symbols));
406✔
25
    }
406✔
26

27
    std::string ScopeResolver::registerInCurrent(const std::string& name, const bool is_mutable)
14,154✔
28
    {
14,154✔
29
        return m_scopes.back()->add(name, is_mutable);
14,154✔
30
    }
31

32
    void ScopeResolver::saveNamespaceAndRemove()
134✔
33
    {
134✔
34
        for (auto& m_scope : std::ranges::reverse_view(m_scopes) | std::ranges::views::drop(1))
268✔
35
        {
36
            if (m_scope->saveNamespace(m_scopes.back()))
134✔
37
                break;
134✔
38
        }
134✔
39

40
        m_scopes.pop_back();
134✔
41
    }
134✔
42

43
    std::optional<bool> ScopeResolver::isImmutable(const std::string& name) const
2,711✔
44
    {
2,711✔
45
        for (const auto& m_scope : std::ranges::reverse_view(m_scopes))
8,032✔
46
        {
47
            if (auto maybe = m_scope->get(name, true); maybe.has_value())
8,032✔
48
                return !maybe.value().is_mutable;
2,711✔
49
        }
5,321✔
50
        return std::nullopt;
×
51
    }
2,711✔
52

53
    bool ScopeResolver::isRegistered(const std::string& name) const
2,773✔
54
    {
2,773✔
55
        return std::ranges::any_of(std::ranges::reverse_view(m_scopes), [&name](const auto& scope) {
8,259✔
56
            return scope->get(name, true).has_value();
5,486✔
57
        });
58
    }
59

60
    bool ScopeResolver::isInScope(const std::string& name) const
9,818✔
61
    {
9,818✔
62
        return m_scopes.back()->get(name, false).has_value();
9,818✔
63
    }
64

65
    std::string ScopeResolver::getFullyQualifiedNameInNearestScope(const std::string& name) const
53,370✔
66
    {
53,370✔
67
        std::optional<std::string> maybe_name;
53,370✔
68
        for (const auto& scope : std::ranges::reverse_view(m_scopes))
269,323✔
69
        {
70
            if (auto maybe_fqn = scope->get(name, true); maybe_fqn.has_value())
245,318✔
71
            {
72
                // priorize non-hidden symbols
73
                if ((maybe_name.has_value() && maybe_name.value().ends_with("#hidden")) || !maybe_name.has_value())
29,365✔
74
                    maybe_name = maybe_fqn.value().name;
28,410✔
75
            }
29,365✔
76
        }
215,953✔
77
        return maybe_name.value_or(name);
53,370✔
78
    }
53,370✔
79

80
    std::pair<bool, std::string> ScopeResolver::canFullyQualifyName(const std::string& name)
46,595✔
81
    {
46,595✔
82
        // a given name can be fully qualified if
83
        // old == new
84
        // old != new and new has prefix
85
        //     if the prefix namespace is glob
86
        //     if the prefix namespace has name in its symbols
87
        //     if the prefix namespace is with_prefix && it is the top most scope
88
        const std::string maybe_fqn = getFullyQualifiedNameInNearestScope(name);
46,595✔
89

90
        if (maybe_fqn == name)
46,595✔
91
            return std::make_pair(true, maybe_fqn);
45,968✔
92

93
        const std::string prefix = maybe_fqn.substr(0, maybe_fqn.find_first_of(':'));
627✔
94
        const std::string unprefixed_name = name.substr(name.find_first_of(':') + 1);
627✔
95
        auto namespaces =
627✔
96
            std::ranges::reverse_view(m_scopes) | std::ranges::views::filter([](const auto& e) {
1,840✔
97
                return e->isNamespace();
1,213✔
98
            });
99
        bool top = true;
627✔
100
        for (auto& scope : namespaces)
1,254✔
101
        {
102
            if (top && prefix == scope->prefix())
627✔
103
                return std::make_pair(true, maybe_fqn);
573✔
104
            if (!top && prefix == scope->prefix() && (scope->isGlob() || scope->hasSymbol(name)))
54✔
UNCOV
105
                return std::make_pair(true, maybe_fqn);
×
106

107
            // check for the presence of the symbol in symbol imports and glob imports
108
            if (scope->recursiveHasSymbol(unprefixed_name))
54✔
109
                return std::make_pair(true, maybe_fqn);
52✔
110

111
            top = false;
2✔
112
        }
627✔
113

114
        return std::make_pair(false, maybe_fqn);
2✔
115
    }
46,595✔
116

117
    StaticScope* ScopeResolver::currentScope() const
135✔
118
    {
135✔
119
        if (!m_scopes.empty()) [[likely]]
135✔
120
            return m_scopes.back().get();
135✔
UNCOV
121
        return nullptr;
×
122
    }
135✔
123
}
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