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

ArkScript-lang / Ark / 13496887929

24 Feb 2025 11:24AM UTC coverage: 79.091%. Remained the same
13496887929

Pull #512

github

web-flow
Merge f9542b7ee into f8b7f8a8c
Pull Request #512: Fix/exported symbols

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

6 existing lines in 1 file now uncovered.

5848 of 7394 relevant lines covered (79.09%)

59710.23 hits per line

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

80.0
/include/Ark/Compiler/NameResolution/StaticScope.hpp
1
/**
2
 * @file StaticScope.hpp
3
 * @author Alexandre Plateau (lexplt.dev@gmail.com)
4
 * @brief
5
 * @version 0.1
6
 * @date 2024-11-30
7
 *
8
 * @copyright Copyright (c) 2024
9
 *
10
 */
11

12
#ifndef ARK_COMPILER_NAMERESOLUTION_STATICSCOPE_HPP
13
#define ARK_COMPILER_NAMERESOLUTION_STATICSCOPE_HPP
14

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

22
#include <Ark/Platform.hpp>
23

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

32
        bool operator==(const Declaration& other) const = default;
3,700✔
33
    };
34
}
35

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

45
namespace Ark::internal
46
{
47
    class ARK_API StaticScope
8,084✔
48
    {
49
    public:
50
        virtual ~StaticScope() = default;
7,789✔
51

52
        /**
53
         * @brief Add a Declaration to the scope, given a mutability status
54
         * @param name
55
         * @param is_mutable
56
         */
57
        virtual std::string add(const std::string& name, bool is_mutable);
58

59
        /**
60
         * @brief Try to return a Declaration from this scope with a given name.
61
         * @param name
62
         * @param extensive_lookup unused in StaticScope
63
         * @return std::optional<Declaration> std::nullopt if the Declaration isn't in scope
64
         */
65
        [[nodiscard]] virtual std::optional<Declaration> get(const std::string& name, bool extensive_lookup);
66

67
        /**
68
         * @brief Given a Declaration name, compute its fully qualified name
69
         * @param name
70
         * @return std::string fully qualified name in the scope
71
         */
72
        [[nodiscard]] virtual std::string fullyQualifiedName(const std::string& name) const;
73

74
        /**
75
         * @brief Save a namespace scope to help with lookup
76
         *
77
         * @return true if the scope was saved, on NamespaceScope
78
         * @return false on StaticScope
79
         */
80
        virtual bool saveNamespace(std::unique_ptr<StaticScope>&);
81

82
        [[nodiscard]] virtual bool isNamespace() const;
UNCOV
83
        [[nodiscard]] inline virtual bool withPrefix() const { return false; }
×
UNCOV
84
        [[nodiscard]] inline virtual bool isGlob() const { return false; }
×
UNCOV
85
        [[nodiscard]] inline virtual std::string prefix() const { return ""; }
×
UNCOV
86
        [[nodiscard]] inline virtual bool hasSymbol(const std::string&) const { return false; }
×
UNCOV
87
        [[nodiscard]] inline virtual bool recursiveHasSymbol(const std::string&) { return false; }
×
88

89
    private:
90
        std::unordered_set<Declaration> m_vars {};
4,042✔
91
    };
92

93
    class ARK_API NamespaceScope final : public StaticScope
590✔
94
    {
95
    public:
96
        NamespaceScope(std::string name, bool with_prefix, bool is_glob, const std::vector<std::string>& symbols);
97

98
        /**
99
         * @brief Add a Declaration to the scope, given a mutability status
100
         * @param name
101
         * @param is_mutable
102
         */
103
        std::string add(const std::string& name, bool is_mutable) override;
104

105
        /**
106
         * @brief Try to return a Declaration from this scope with a given name.
107
         * @param name
108
         * @param extensive_lookup if true, use the additional saved namespaces
109
         * @return std::optional<Declaration> std::nullopt if the Declaration isn't in scope
110
         */
111
        [[nodiscard]] std::optional<Declaration> get(const std::string& name, bool extensive_lookup) override;
112

113
        /**
114
         * @brief Given a Declaration name, compute its fully qualified name
115
         * @param name
116
         * @return std::string fully qualified name in the namespace
117
         */
118
        [[nodiscard]] std::string fullyQualifiedName(const std::string& name) const override;
119

120
        /**
121
         * @brief Save a namespace scope to help with lookup
122
         *
123
         * @return true if the scope was saved, on NamespaceScope
124
         * @return false on StaticScope
125
         */
126
        bool saveNamespace(std::unique_ptr<StaticScope>&) override;
127

128
        [[nodiscard]] bool isNamespace() const override;
UNCOV
129
        [[nodiscard]] inline bool withPrefix() const override { return m_with_prefix; }
×
130
        [[nodiscard]] inline bool isGlob() const override { return m_is_glob; }
80✔
131
        [[nodiscard]] inline std::string prefix() const override { return m_namespace; }
517✔
132
        [[nodiscard]] inline bool hasSymbol(const std::string& symbol) const override { return std::ranges::find(m_symbols, symbol) != m_symbols.end(); }
309,779✔
133
        [[nodiscard]] inline bool recursiveHasSymbol(const std::string& symbol) override
112✔
134
        {
112✔
135
            if (hasSymbol(symbol))
112✔
136
                return true;
32✔
137
            if (isGlob() && std::ranges::find(m_vars, fullyQualifiedName(symbol), &Declaration::name) != m_vars.end())
80✔
138
                return true;
14✔
139

140
            for (const auto& saved_scope : m_additional_namespaces)
130✔
141
            {
142
                if (saved_scope->recursiveHasSymbol(symbol))
64✔
143
                    return true;
49✔
144
            }
64✔
145
            return false;
17✔
146
        }
112✔
147

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

158
#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