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

ArkScript-lang / Ark / 17410180849

02 Sep 2025 04:42PM UTC coverage: 90.848% (-0.005%) from 90.853%
17410180849

push

github

SuperFola
feat(vm): adding new super instruction AT_SYM_INDEX_CONST, to load a value from a container using a constant as the index

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

6 existing lines in 3 files now uncovered.

7931 of 8730 relevant lines covered (90.85%)

156927.33 hits per line

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

75.0
/include/Ark/Compiler/NameResolution/StaticScope.hpp
1
/**
2
 * @file StaticScope.hpp
3
 * @author Lex Plateau (lexplt.dev@gmail.com)
4
 * @brief Static scopes (for functions, loops) and namespace scopes (for packages) definitions, used at compile time
5
 * @date 2024-11-30
6
 *
7
 * @copyright Copyright (c) 2024-2025
8
 *
9
 */
10

11
#ifndef ARK_COMPILER_NAMERESOLUTION_STATICSCOPE_HPP
12
#define ARK_COMPILER_NAMERESOLUTION_STATICSCOPE_HPP
13

14
#include <string>
15
#include <optional>
16
#include <memory>
17
#include <vector>
18
#include <ranges>
19
#include <unordered_set>
20

21
#include <Ark/Utils/Platform.hpp>
22

23
namespace Ark::internal
24
{
25
    struct Declaration
221,673✔
26
    {
27
        std::string name;           ///< End name, can be modified to be hidden
28
        std::string original_name;  ///< Original name, with the prefix, without hidden namespaces
29
        bool is_mutable;
30

31
        bool operator==(const Declaration& other) const = default;
14,833✔
32
    };
33
}
34

35
template <>
36
struct std::hash<Ark::internal::Declaration>
37
{
38
    inline size_t operator()(const Ark::internal::Declaration& x) const noexcept
51,504✔
39
    {
51,504✔
40
        return std::hash<std::string> {}(x.original_name);
51,504✔
41
    }
42
};
43

44
namespace Ark::internal
45
{
46
    class ARK_API StaticScope
47
    {
48
    public:
49
        virtual ~StaticScope() = default;
22,317✔
50

51
        StaticScope() = default;
11,420✔
52

53
        StaticScope(const StaticScope&) = delete;
54
        StaticScope& operator=(const StaticScope&) = delete;
55
        StaticScope(StaticScope&&) = default;
56
        StaticScope& operator=(StaticScope&&) = default;
57

58
        /**
59
         * @brief Add a Declaration to the scope, given a mutability status
60
         * @param name
61
         * @param is_mutable
62
         */
63
        virtual std::string add(const std::string& name, bool is_mutable);
64

65
        /**
66
         * @brief Try to return a Declaration from this scope with a given name.
67
         * @param name
68
         * @param origin_namespace unused in StaticScope
69
         * @param extensive_lookup unused in StaticScope
70
         * @return std::optional<Declaration> std::nullopt if the Declaration isn't in scope
71
         */
72
        [[nodiscard]] virtual std::optional<Declaration> get(const std::string& name, const std::string& origin_namespace, bool extensive_lookup);
73

74
        /**
75
         * @brief Given a Declaration name, compute its fully qualified name
76
         * @param name
77
         * @return std::string fully qualified name in the scope
78
         */
79
        [[nodiscard]] virtual std::string fullyQualifiedName(const std::string& name) const;
80

81
        /**
82
         * @brief Save a namespace scope to help with lookup
83
         *
84
         * @return true if the scope was saved, on NamespaceScope
85
         * @return false on StaticScope
86
         */
87
        virtual bool saveNamespace(std::unique_ptr<StaticScope>&);
88

89
        [[nodiscard]] virtual bool isNamespace() const;
90
        [[nodiscard]] inline virtual bool isGlob() const { return false; }
×
91
        [[nodiscard]] inline virtual std::string prefix() const { return ""; }
×
92
        [[nodiscard]] inline virtual bool hasSymbol(const std::string&) const { return false; }
×
UNCOV
93
        [[nodiscard]] inline virtual bool recursiveHasSymbol(const std::string&) { return false; }
×
94

95
    private:
96
        std::unordered_set<Declaration> m_vars {};
11,420✔
97
    };
98

99
    class ARK_API NamespaceScope final : public StaticScope
1,046✔
100
    {
101
    public:
102
        NamespaceScope(std::string name, bool with_prefix, bool is_glob, const std::vector<std::string>& symbols);
103

104
        NamespaceScope(const NamespaceScope&) = delete;
105
        NamespaceScope& operator=(const NamespaceScope&) = delete;
106
        NamespaceScope(NamespaceScope&&) = default;
107
        NamespaceScope& operator=(NamespaceScope&&) = default;
108

109
        /**
110
         * @brief Add a Declaration to the scope, given a mutability status
111
         * @param name
112
         * @param is_mutable
113
         */
114
        std::string add(const std::string& name, bool is_mutable) override;
115

116
        /**
117
         * @brief Try to return a Declaration from this scope with a given name.
118
         * @param name
119
         * @param origin_namespace namespace's name of the variable we are trying to find
120
         * @param extensive_lookup if true, use the additional saved namespaces
121
         * @return std::optional<Declaration> std::nullopt if the Declaration isn't in scope
122
         */
123
        [[nodiscard]] std::optional<Declaration> get(const std::string& name, const std::string& origin_namespace, bool extensive_lookup) override;
124

125
        /**
126
         * @brief Given a Declaration name, compute its fully qualified name
127
         * @param name
128
         * @return std::string fully qualified name in the namespace
129
         */
130
        [[nodiscard]] std::string fullyQualifiedName(const std::string& name) const override;
131

132
        /**
133
         * @brief Save a namespace scope to help with lookup
134
         *
135
         * @return true if the scope was saved, on NamespaceScope
136
         * @return false on StaticScope
137
         */
138
        bool saveNamespace(std::unique_ptr<StaticScope>&) override;
139

140
        [[nodiscard]] bool isNamespace() const override;
141
        [[nodiscard]] inline bool isGlob() const override { return m_is_glob; }
162✔
142
        [[nodiscard]] inline std::string prefix() const override { return m_namespace; }
129,071✔
143
        [[nodiscard]] inline bool hasSymbol(const std::string& symbol) const override { return std::ranges::find(m_symbols, symbol) != m_symbols.end(); }
763,843✔
144
        [[nodiscard]] bool recursiveHasSymbol(const std::string& symbol) override;
145

146
    private:
147
        std::string m_namespace;
148
        bool m_with_prefix;
149
        bool m_is_glob;
150
        std::vector<std::string> m_symbols;
151
        std::unordered_set<Declaration> m_vars {};
152
        std::vector<std::unique_ptr<StaticScope>> m_additional_namespaces;
153
    };
154
}
155

156
#endif  // ARK_COMPILER_NAMERESOLUTION_STATICSCOPE_HPP
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