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

ArkScript-lang / Ark / 12164232004

04 Dec 2024 04:37PM UTC coverage: 77.815% (+0.6%) from 77.19%
12164232004

push

github

SuperFola
feat(name resolution): allow fqn if the scope is only exporting symbols

1 of 3 new or added lines in 2 files covered. (33.33%)

256 existing lines in 11 files now uncovered.

5412 of 6955 relevant lines covered (77.81%)

9300.67 hits per line

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

58.82
/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 <unordered_set>
20

21
namespace Ark::internal
22
{
23
    struct Declaration
12,455✔
24
    {
25
        std::string name;
26
        bool is_mutable;
27

28
        bool operator==(const Declaration& other) const = default;
498✔
29
    };
30
}
31

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

41
namespace Ark::internal
42
{
43
    class StaticScope
1,152✔
44
    {
45
    public:
46
        virtual ~StaticScope() = default;
1,011✔
47

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

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

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

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

78
        [[nodiscard]] virtual bool isNamespace() const;
79
        [[nodiscard]] inline virtual bool withPrefix() const { return false; }
×
80
        [[nodiscard]] inline virtual bool isGlob() const { return false; }
×
81
        [[nodiscard]] inline virtual std::string prefix() const { return ""; }
×
NEW
82
        [[nodiscard]] inline virtual bool hasSymbol(const std::string&) const { return false; }
×
83

84
    private:
85
        std::unordered_set<Declaration> m_vars {};
576✔
86
    };
87

88
    class NamespaceScope final : public StaticScope
282✔
89
    {
90
    public:
91
        NamespaceScope(std::string name, bool with_prefix, bool is_glob, const std::vector<std::string>& symbols);
92

93
        /**
94
         * @brief Add a Declaration to the scope, given a mutability status
95
         * @param name
96
         * @param is_mutable
97
         */
98
        void add(const std::string& name, bool is_mutable) override;
99

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

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

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

123
        [[nodiscard]] bool isNamespace() const override;
124
        [[nodiscard]] inline bool withPrefix() const override { return m_with_prefix; }
×
125
        [[nodiscard]] inline bool isGlob() const override { return m_is_glob; }
×
126
        [[nodiscard]] inline std::string prefix() const override { return m_namespace; }
201✔
NEW
127
        [[nodiscard]] inline bool hasSymbol(const std::string& symbol) const override { return std::ranges::find(m_symbols, symbol) != m_symbols.end(); }
×
128

129
    private:
130
        std::string m_namespace;
131
        bool m_with_prefix;
132
        bool m_is_glob;
133
        std::vector<std::string> m_symbols;
134
        std::unordered_set<Declaration> m_vars {};
135
        std::vector<std::unique_ptr<StaticScope>> m_additional_namespaces;
136
    };
137
}
138

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