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

ArkScript-lang / Ark / 12304789397

10 Dec 2024 10:04PM UTC coverage: 77.378% (-0.5%) from 77.864%
12304789397

push

github

SuperFola
fix(parser): fixing row/col computation while backtracking in the parser, leading to finally correct symbol underlined in errors

7 of 7 new or added lines in 2 files covered. (100.0%)

258 existing lines in 6 files now uncovered.

5490 of 7095 relevant lines covered (77.38%)

9291.12 hits per line

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

96.34
/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()
117✔
8
    {
117✔
9
        createNewNamespace("", /* with_prefix= */ false, /* is_glob= */ true, /* symbols= */ {});
117✔
10
    }
117✔
11

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

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

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

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

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

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

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

53
    bool ScopeResolver::isRegistered(const std::string& name) const
339✔
54
    {
339✔
55
        for (const auto& m_scope : std::ranges::reverse_view(m_scopes))
873✔
56
        {
57
            if (m_scope->get(name, true).has_value())
534✔
58
                return true;
334✔
59
        }
534✔
60
        return false;
5✔
61
    }
339✔
62

63
    bool ScopeResolver::isInScope(const std::string& name) const
1,178✔
64
    {
1,178✔
65
        return m_scopes.back()->get(name, false).has_value();
1,178✔
66
    }
67

68
    std::string ScopeResolver::getFullyQualifiedNameInNearestScope(const std::string& name) const
9,171✔
69
    {
9,171✔
70
        for (const auto& scope : std::ranges::reverse_view(m_scopes))
33,535✔
71
        {
72
            if (auto maybe_fqn = scope->get(name, true); maybe_fqn.has_value())
28,587✔
73
                return maybe_fqn.value().name;
4,223✔
74
        }
24,364✔
75
        return name;
4,948✔
76
    }
9,171✔
77

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

88
        if (maybe_fqn == name)
7,844✔
89
            return std::make_pair(true, maybe_fqn);
7,636✔
90

91
        const std::string prefix = maybe_fqn.substr(0, maybe_fqn.find_first_of(':'));
208✔
92
        const std::string unprefixed_name = maybe_fqn.substr(maybe_fqn.find_first_of(':') + 1);
208✔
93
        auto namespaces =
208✔
94
            std::ranges::reverse_view(m_scopes) | std::ranges::views::filter([](const auto& e) {
600✔
95
                return e->isNamespace();
392✔
96
            });
97
        bool top = true;
208✔
98
        for (auto& scope : namespaces)
416✔
99
        {
100
            if (top && prefix == scope->prefix())
208✔
101
                return std::make_pair(true, maybe_fqn);
202✔
102
            if (!top && prefix == scope->prefix() && (scope->isGlob() || scope->hasSymbol(name)))
6✔
UNCOV
103
                return std::make_pair(true, maybe_fqn);
×
104

105
            if (scope->recursiveHasSymbol(unprefixed_name))
6✔
106
                return std::make_pair(true, maybe_fqn);
4✔
107

108
            top = false;
2✔
109
        }
208✔
110

111
        return std::make_pair(false, maybe_fqn);
2✔
112
    }
7,844✔
113

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

© 2025 Coveralls, Inc