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

ArkScript-lang / Ark / 12304789397

10 Dec 2024 10:04PM UTC coverage: 77.378% (-0.5%) from 77.864%
12304789397

push

github

SuperFola
fix(parser): fixing row/col computation while backtracking in the parser, leading to finally correct symbol underlined in errors

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

258 existing lines in 6 files now uncovered.

5490 of 7095 relevant lines covered (77.38%)

9291.12 hits per line

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

75.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
11,993✔
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;
779✔
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,950✔
38
    {
2,950✔
39
        return std::hash<std::string> {}(x.original_name);
2,950✔
40
    }
41
};
42

43
namespace Ark::internal
44
{
45
    class StaticScope
1,192✔
46
    {
47
    public:
48
        virtual ~StaticScope() = default;
1,045✔
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 ""; }
×
84
        [[nodiscard]] inline virtual bool hasSymbol(const std::string&) const { return false; }
×
85
        [[nodiscard]] inline virtual bool recursiveHasSymbol(const std::string&) const { return false; }
×
86

87
    private:
88
        std::unordered_set<Declaration> m_vars {};
596✔
89
    };
90

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

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

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

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

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

126
        [[nodiscard]] bool isNamespace() const override;
UNCOV
127
        [[nodiscard]] inline bool withPrefix() const override { return m_with_prefix; }
×
128
        [[nodiscard]] inline bool isGlob() const override { return m_is_glob; }
×
129
        [[nodiscard]] inline std::string prefix() const override { return m_namespace; }
208✔
130
        [[nodiscard]] inline bool hasSymbol(const std::string& symbol) const override { return std::ranges::find(m_symbols, symbol) != m_symbols.end(); }
36,206✔
131
        [[nodiscard]] inline bool recursiveHasSymbol(const std::string& symbol) const override
15✔
132
        {
15✔
133
            if (hasSymbol(symbol))
15✔
134
                return true;
4✔
135
            for (const auto& saved_scope : m_additional_namespaces)
20✔
136
            {
137
                if (saved_scope->recursiveHasSymbol(symbol))
9✔
138
                    return true;
5✔
139
            }
9✔
140
            return false;
6✔
141
        }
15✔
142

143
    private:
144
        std::string m_namespace;
145
        bool m_with_prefix;
146
        bool m_is_glob;
147
        std::vector<std::string> m_symbols;
148
        std::unordered_set<Declaration> m_vars {};
149
        std::vector<std::unique_ptr<StaticScope>> m_additional_namespaces;
150
    };
151
}
152

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