• 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

92.41
/src/arkreactor/Compiler/AST/Node.cpp
1
#include <Ark/Compiler/Common.hpp>
2
#include <Ark/Compiler/AST/Node.hpp>
3

4
#include <Ark/Exceptions.hpp>
5

6
#include <fmt/core.h>
7

8
namespace Ark::internal
9
{
10
    Node::Node(const NodeType node_type, const std::string& value) :
14,810✔
11
        m_type(node_type), m_value(value)
7,405✔
12
    {}
7,405✔
13

14
    Node::Node(const NodeType node_type) :
29,171✔
15
        m_type(node_type)
29,171✔
16
    {
29,171✔
17
        if (m_type == NodeType::List || m_type == NodeType::Macro || m_type == NodeType::Field)
29,171✔
18
            m_value = std::vector<Node>();
29,056✔
19
    }
29,171✔
20

21
    Node::Node(double value) :
1,056✔
22
        m_type(NodeType::Number), m_value(value)
1,056✔
23
    {}
2,112✔
24

25
    Node::Node(const long value) :
36✔
26
        m_type(NodeType::Number), m_value(static_cast<double>(value))
36✔
27
    {}
72✔
28

29
    Node::Node(Keyword value) :
1,343✔
30
        m_type(NodeType::Keyword), m_value(value)
1,343✔
31
    {}
2,686✔
32

33
    Node::Node(Namespace namespace_) :
40✔
34
        m_type(NodeType::Namespace), m_value(namespace_)
20✔
35
    {}
20✔
36

37
    const std::string& Node::string() const noexcept
601,341✔
38
    {
601,341✔
39
        return std::get<std::string>(m_value);
601,341✔
40
    }
41

42
    double Node::number() const noexcept
1,894✔
43
    {
1,894✔
44
        return std::get<double>(m_value);
1,894✔
45
    }
46

47
    Keyword Node::keyword() const noexcept
10,744✔
48
    {
10,744✔
49
        return std::get<Keyword>(m_value);
10,744✔
50
    }
51

52
    Namespace& Node::arkNamespace() noexcept
46✔
53
    {
46✔
54
        return std::get<Namespace>(m_value);
46✔
55
    }
56

57
    const Namespace& Node::constArkNamespace() const noexcept
19✔
58
    {
19✔
59
        return std::get<Namespace>(m_value);
19✔
60
    }
61

62
    void Node::push_back(const Node& node) noexcept
12,943✔
63
    {
12,943✔
64
        list().push_back(node);
12,943✔
65
    }
12,943✔
66

67
    std::vector<Node>& Node::list() noexcept
142,637✔
68
    {
142,637✔
69
        return std::get<std::vector<Node>>(m_value);
142,637✔
70
    }
71

72
    const std::vector<Node>& Node::constList() const noexcept
224,217✔
73
    {
224,217✔
74
        return std::get<std::vector<Node>>(m_value);
224,217✔
75
    }
76

77
    NodeType Node::nodeType() const noexcept
471,858✔
78
    {
471,858✔
79
        return m_type;
471,858✔
80
    }
81

82
    bool Node::isListLike() const noexcept
6,658✔
83
    {
6,658✔
84
        return m_type == NodeType::List || m_type == NodeType::Macro;
6,658✔
85
    }
86

UNCOV
87
    bool Node::isStringLike() const noexcept
×
UNCOV
88
    {
×
UNCOV
89
        return m_type == NodeType::Symbol || m_type == NodeType::String || m_type == NodeType::Spread;
×
90
    }
91

92
    void Node::updateValueAndType(const Node& source) noexcept
8,855✔
93
    {
8,855✔
94
        m_type = source.m_type;
8,855✔
95
        m_value = source.m_value;
8,855✔
96
    }
8,855✔
97

98
    void Node::setNodeType(const NodeType type) noexcept
148✔
99
    {
148✔
100
        m_type = type;
148✔
101
    }
148✔
102

103
    void Node::setString(const std::string& value) noexcept
12,216✔
104
    {
12,216✔
105
        m_value = value;
12,216✔
106
    }
12,216✔
107

108
    void Node::setPos(const std::size_t line, const std::size_t col) noexcept
31,557✔
109
    {
31,557✔
110
        m_line = line;
31,557✔
111
        m_col = col;
31,557✔
112
    }
31,557✔
113

114
    void Node::setFilename(const std::string& filename) noexcept
31,557✔
115
    {
31,557✔
116
        m_filename = filename;
31,557✔
117
    }
31,557✔
118

119
    Node& Node::attachNearestCommentBefore(const std::string& comment)
11,230✔
120
    {
11,230✔
121
        m_comment = comment;
11,230✔
122
        return *this;
11,230✔
123
    }
124

125
    Node& Node::attachCommentAfter(const std::string& comment)
1,850✔
126
    {
1,850✔
127
        if (!m_after_comment.empty())
1,850✔
128
            m_after_comment += "\n";
2✔
129
        m_after_comment += comment;
1,850✔
130
        if (!m_after_comment.empty() && m_after_comment.back() == '\n')
1,850✔
131
            m_after_comment.pop_back();
61✔
132
        return *this;
1,850✔
133
    }
134

135
    std::size_t Node::line() const noexcept
43,938✔
136
    {
43,938✔
137
        return m_line;
43,938✔
138
    }
139

140
    std::size_t Node::col() const noexcept
40,419✔
141
    {
40,419✔
142
        return m_col;
40,419✔
143
    }
144

145
    const std::string& Node::filename() const noexcept
5,195✔
146
    {
5,195✔
147
        return m_filename;
5,195✔
148
    }
149

150
    const std::string& Node::comment() const noexcept
3,267✔
151
    {
3,267✔
152
        return m_comment;
3,267✔
153
    }
154

155
    const std::string& Node::commentAfter() const noexcept
2,048✔
156
    {
2,048✔
157
        return m_after_comment;
2,048✔
158
    }
159

160
    std::string Node::repr() const noexcept
1,507✔
161
    {
1,507✔
162
        std::string data;
1,507✔
163
        switch (m_type)
1,507✔
164
        {
565✔
165
            case NodeType::Symbol:
166
                data += string();
565✔
167
                break;
567✔
168

169
            case NodeType::Capture:
170
                data += "&" + string();
2✔
171
                break;
29✔
172

173
            case NodeType::Keyword:
174
                data += keywords[static_cast<std::size_t>(keyword())];
27✔
175
                break;
167✔
176

177
            case NodeType::String:
178
                data += "\"" + string() + "\"";
140✔
179
                break;
556✔
180

181
            case NodeType::Number:
182
                data += fmt::format("{}", number());
416✔
183
                break;
745✔
184

185
            case NodeType::List:
186
                data += "(";
329✔
187
                for (std::size_t i = 0, end = constList().size(); i < end; ++i)
1,226✔
188
                {
189
                    data += constList()[i].repr();
897✔
190
                    if (i < end - 1)
897✔
191
                        data += " ";
568✔
192
                }
897✔
193
                data += ")";
329✔
194
                break;
338✔
195

196
            case NodeType::Field:
197
                for (std::size_t i = 0, end = constList().size(); i < end; ++i)
29✔
198
                {
199
                    data += constList()[i].repr();
20✔
200
                    if (i < end - 1)
20✔
201
                        data += ".";
11✔
202
                }
20✔
203
                break;
25✔
204

205
            case NodeType::Macro:
206
                data += "($ ";
16✔
207
                for (std::size_t i = 0, end = constList().size(); i < end; ++i)
77✔
208
                {
209
                    data += constList()[i].repr();
61✔
210
                    if (i < end - 1)
61✔
211
                        data += " ";
45✔
212
                }
61✔
213
                data += ")";
16✔
214
                break;
19✔
215

216
            case NodeType::Spread:
217
                data += "..." + string();
3✔
218
                break;
3✔
219

220
            // namespace node should not have a representation as it is purely internal,
221
            // and it can't be exploited by macros (unless you try passing an import node
222
            // to a macro, which should not happen?)
223
            case NodeType::Namespace:
UNCOV
224
                data += constArkNamespace().ast->repr();
×
225
                break;
39,031✔
226

227
            case NodeType::Unused:
UNCOV
228
                break;
×
229
        }
1,507✔
230
        return data;
1,507✔
231
    }
1,507✔
232

233
    std::ostream& Node::debugPrint(std::ostream& os) const noexcept
469✔
234
    {
469✔
235
        switch (m_type)
469✔
236
        {
143✔
237
            case NodeType::Symbol:
238
                os << "Symbol:" << string();
143✔
239
                break;
149✔
240

241
            case NodeType::Capture:
242
                os << "Capture:" << string();
6✔
243
                break;
84✔
244

245
            case NodeType::Keyword:
246
                os << "Keyword:";
78✔
247
                switch (keyword())
78✔
248
                {
14✔
249
                    case Keyword::Fun: os << "Fun"; break;
32✔
250
                    case Keyword::Let: os << "Let"; break;
21✔
251
                    case Keyword::Mut: os << "Mut"; break;
4✔
252
                    case Keyword::Set: os << "Set"; break;
16✔
253
                    case Keyword::If: os << "If"; break;
21✔
254
                    case Keyword::While: os << "While"; break;
15✔
255
                    case Keyword::Begin: os << "Begin"; break;
17✔
256
                    case Keyword::Import: os << "Import"; break;
12✔
257
                    case Keyword::Del: os << "Del"; break;
4✔
258
                }
78✔
259
                break;
86✔
260

261
            case NodeType::String:
262
                os << "String:" << string();
8✔
263
                break;
83✔
264

265
            case NodeType::Number:
266
                os << "Number:" << number();
75✔
267
                break;
215✔
268

269
            case NodeType::List:
270
                os << "( ";
140✔
271
                for (const auto& i : constList())
482✔
272
                    i.debugPrint(os) << " ";
342✔
273
                os << ")";
140✔
274
                break;
149✔
275

276
            case NodeType::Field:
277
                os << "( Field ";
9✔
278
                for (const auto& i : constList())
30✔
279
                    i.debugPrint(os) << " ";
21✔
280
                os << ")";
9✔
281
                break;
17✔
282

283
            case NodeType::Macro:
284
                os << "( Macro ";
8✔
285
                for (const auto& i : constList())
31✔
286
                    i.debugPrint(os) << " ";
23✔
287
                os << ")";
8✔
288
                break;
10✔
289

290
            case NodeType::Spread:
291
                os << "Spread:" << string();
2✔
292
                break;
2✔
293

294
            case NodeType::Namespace:
295
            {
UNCOV
296
                const auto details = constArkNamespace();
×
297
                os << "( Namespace:" << details.name << " ";
×
UNCOV
298
                details.ast->debugPrint(os) << " )";
×
299
                break;
UNCOV
300
            }
×
301

302
            case NodeType::Unused:
UNCOV
303
                os << "Unused:" << string();
×
UNCOV
304
                break;
×
305
        }
469✔
306
        return os;
469✔
307
    }
308

309
    const Node& getTrueNode()
29✔
310
    {
29✔
311
        static const Node TrueNode(NodeType::Symbol, "true");
29✔
312
        return TrueNode;
29✔
UNCOV
313
    }
×
314

315
    const Node& getFalseNode()
19✔
316
    {
19✔
317
        static const Node FalseNode(NodeType::Symbol, "false");
19✔
318
        return FalseNode;
19✔
UNCOV
319
    }
×
320

321
    const Node& getNilNode()
21✔
322
    {
21✔
323
        static const Node NilNode(NodeType::Symbol, "nil");
21✔
324
        return NilNode;
21✔
UNCOV
325
    }
×
326

327
    const Node& getListNode()
388✔
328
    {
388✔
329
        static const Node ListNode(NodeType::Symbol, "list");
388✔
330
        return ListNode;
388✔
UNCOV
331
    }
×
332

333
    bool operator==(const Node& A, const Node& B)
99✔
334
    {
99✔
335
        if (A.m_type != B.m_type)  // should have the same types
99✔
336
            return false;
9✔
337

338
        if (A.m_type != NodeType::List)
90✔
339
            return A.m_value == B.m_value;
90✔
UNCOV
340
        return false;
×
341
    }
99✔
342

343
    bool operator<(const Node& A, const Node& B)
21✔
344
    {
21✔
345
        if (A.nodeType() != B.nodeType())
21✔
UNCOV
346
            return (static_cast<int>(A.nodeType()) - static_cast<int>(B.nodeType())) < 0;
×
347

348
        switch (A.nodeType())
21✔
349
        {
21✔
350
            case NodeType::Number:
351
                [[fallthrough]];
352
            case NodeType::Symbol:
353
                [[fallthrough]];
354
            case NodeType::String:
355
                return A.m_value < B.m_value;
21✔
356

357
            default:
UNCOV
358
                return false;
×
359
        }
360
    }
21✔
361
}
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