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

ArkScript-lang / Ark / 12206460859

06 Dec 2024 09:32PM UTC coverage: 77.864% (+0.05%) from 77.815%
12206460859

push

github

SuperFola
refactor(name resolution): removing dead code and refactoring code when assigning names to symbols in namespaces

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

24 existing lines in 5 files now uncovered.

5438 of 6984 relevant lines covered (77.86%)

9338.42 hits per line

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

65.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
namespace Ark::internal
23
{
24
    struct Declaration
12,133✔
25
    {
26
        std::string name;           ///< End name, can be modified to be hidden
27
        std::string original_name;  ///< Original name, with the prefix, without hidden namespaces
28
        bool is_mutable;
29

30
        bool operator==(const Declaration& other) const = default;
765✔
31
    };
32
}
33

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

43
namespace Ark::internal
44
{
45
    class StaticScope
1,164✔
46
    {
47
    public:
48
        virtual ~StaticScope() = default;
1,021✔
49

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

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

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

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

80
        [[nodiscard]] virtual bool isNamespace() const;
81
        [[nodiscard]] inline virtual bool withPrefix() const { return false; }
×
82
        [[nodiscard]] inline virtual bool isGlob() const { return false; }
×
83
        [[nodiscard]] inline virtual std::string prefix() const { return ""; }
×
UNCOV
84
        [[nodiscard]] inline virtual bool hasSymbol(const std::string&) const { return false; }
×
UNCOV
85
        [[nodiscard]] inline virtual const std::vector<std::unique_ptr<StaticScope>>& savedScopes() { return m_empty; }
×
86

87
    private:
88
        std::unordered_set<Declaration> m_vars {};
582✔
89
        const std::vector<std::unique_ptr<StaticScope>> m_empty {};
582✔
90
    };
91

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

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

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

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

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

127
        [[nodiscard]] bool isNamespace() const override;
128
        [[nodiscard]] inline bool withPrefix() const override { return m_with_prefix; }
×
UNCOV
129
        [[nodiscard]] inline bool isGlob() const override { return m_is_glob; }
×
130
        [[nodiscard]] inline std::string prefix() const override { return m_namespace; }
209✔
131
        [[nodiscard]] inline bool hasSymbol(const std::string& symbol) const override { return std::ranges::find(m_symbols, symbol) != m_symbols.end(); }
35,896✔
132
        [[nodiscard]] inline const std::vector<std::unique_ptr<StaticScope>>& savedScopes() override { return m_additional_namespaces; }
3✔
133

134
    private:
135
        std::string m_namespace;
136
        bool m_with_prefix;
137
        bool m_is_glob;
138
        std::vector<std::string> m_symbols;
139
        std::unordered_set<Declaration> m_vars {};
140
        std::vector<std::unique_ptr<StaticScope>> m_additional_namespaces;
141
    };
142
}
143

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