• 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

66.67
/include/Ark/Compiler/NameResolution/StaticScope.hpp
1
/**
2
 * @file StaticScope.hpp
3
 * @author Alexandre 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/Platform.hpp>
22

23
namespace Ark::internal
24
{
25
    struct Declaration
111,631✔
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;
5,090✔
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
23,575✔
39
    {
23,575✔
40
        return std::hash<std::string> {}(x.original_name);
23,575✔
41
    }
42
};
43

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

51
        StaticScope() = default;
5,587✔
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 extensive_lookup unused in StaticScope
69
         * @return std::optional<Declaration> std::nullopt if the Declaration isn't in scope
70
         */
71
        [[nodiscard]] virtual std::optional<Declaration> get(const std::string& name, bool extensive_lookup);
72

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

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

88
        [[nodiscard]] virtual bool isNamespace() const;
UNCOV
89
        [[nodiscard]] inline virtual bool withPrefix() const { return false; }
×
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; }
×
93
        [[nodiscard]] inline virtual bool recursiveHasSymbol(const std::string&) { return false; }
×
94

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

99
    class ARK_API NamespaceScope final : public StaticScope
812✔
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 extensive_lookup if true, use the additional saved namespaces
120
         * @return std::optional<Declaration> std::nullopt if the Declaration isn't in scope
121
         */
122
        [[nodiscard]] std::optional<Declaration> get(const std::string& name, bool extensive_lookup) override;
123

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

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

139
        [[nodiscard]] bool isNamespace() const override;
UNCOV
140
        [[nodiscard]] inline bool withPrefix() const override { return m_with_prefix; }
×
141
        [[nodiscard]] inline bool isGlob() const override { return m_is_glob; }
86✔
142
        [[nodiscard]] inline std::string prefix() const override { return m_namespace; }
627✔
143
        [[nodiscard]] inline bool hasSymbol(const std::string& symbol) const override { return std::ranges::find(m_symbols, symbol) != m_symbols.end(); }
367,186✔
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