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

ArkScript-lang / Ark / 13445647490

20 Feb 2025 09:24PM UTC coverage: 79.091% (+0.2%) from 78.929%
13445647490

push

github

SuperFola
feat(tests): adding Rosetta Code solution for Calculating the value of e

5848 of 7394 relevant lines covered (79.09%)

49501.04 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
76,186✔
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;
2,977✔
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
13,526✔
40
    {
13,526✔
41
        return std::hash<std::string> {}(x.original_name);
13,526✔
42
    }
43
};
44

45
namespace Ark::internal
46
{
47
    class ARK_API StaticScope
6,452✔
48
    {
49
    public:
50
        virtual ~StaticScope() = default;
6,180✔
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;
83
        [[nodiscard]] inline virtual bool withPrefix() const { return false; }
×
84
        [[nodiscard]] inline virtual bool isGlob() const { return false; }
×
85
        [[nodiscard]] inline virtual std::string prefix() const { return ""; }
×
86
        [[nodiscard]] inline virtual bool hasSymbol(const std::string&) const { return false; }
×
87
        [[nodiscard]] inline virtual bool recursiveHasSymbol(const std::string&) { return false; }
×
88

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

93
    class ARK_API NamespaceScope final : public StaticScope
544✔
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;
129
        [[nodiscard]] inline bool withPrefix() const override { return m_with_prefix; }
×
130
        [[nodiscard]] inline bool isGlob() const override { return m_is_glob; }
69✔
131
        [[nodiscard]] inline std::string prefix() const override { return m_namespace; }
448✔
132
        [[nodiscard]] inline bool hasSymbol(const std::string& symbol) const override { return std::ranges::find(m_symbols, symbol) != m_symbols.end(); }
291,579✔
133
        [[nodiscard]] inline bool recursiveHasSymbol(const std::string& symbol) override
93✔
134
        {
93✔
135
            if (hasSymbol(symbol))
93✔
136
                return true;
24✔
137
            if (isGlob() && std::ranges::find(m_vars, fullyQualifiedName(symbol), &Declaration::name) != m_vars.end())
69✔
138
                return true;
14✔
139

140
            for (const auto& saved_scope : m_additional_namespaces)
108✔
141
            {
142
                if (saved_scope->recursiveHasSymbol(symbol))
53✔
143
                    return true;
40✔
144
            }
53✔
145
            return false;
15✔
146
        }
93✔
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