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

vla5924-practice / compiler-project / 13871393984

15 Mar 2025 09:03AM UTC coverage: 76.643% (+1.7%) from 74.945%
13871393984

Pull #208

github

web-flow
Merge d26e91b61 into 640b4d135
Pull Request #208: Support dynamically sized lists

54 of 68 new or added lines in 6 files covered. (79.41%)

1 existing line in 1 file now uncovered.

4246 of 5540 relevant lines covered (76.64%)

222.61 hits per line

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

79.41
/compiler/lib/ast/node.cpp
1
#include "node.hpp"
2

3
#include <iostream>
4
#include <sstream>
5

6
#include "node_type.hpp"
7
#include "types.hpp"
8

9
using namespace ast;
10

11
namespace {
12

13
const char *const binaryOperationToString(BinaryOperation binOp) {
162✔
14
    switch (binOp) {
162✔
15
    case BinaryOperation::Add:
37✔
16
        return "Add";
37✔
17
    case BinaryOperation::And:
4✔
18
        return "And";
4✔
19
    case BinaryOperation::Assign:
75✔
20
        return "Assign";
75✔
21
    case BinaryOperation::Div:
4✔
22
        return "Div";
4✔
23
    case BinaryOperation::Equal:
8✔
24
        return "Equal";
8✔
25
    case BinaryOperation::FAdd:
10✔
26
        return "FAdd";
10✔
27
    case BinaryOperation::FDiv:
×
28
        return "FDiv";
×
29
    case BinaryOperation::FMult:
×
30
        return "FMult";
×
31
    case BinaryOperation::FSub:
×
32
        return "FSub";
×
33
    case BinaryOperation::Greater:
1✔
34
        return "Greater";
1✔
35
    case BinaryOperation::GreaterEqual:
×
36
        return "GreaterEqual";
×
37
    case BinaryOperation::Less:
×
38
        return "Less";
×
39
    case BinaryOperation::LessEqual:
×
40
        return "LessEqual";
×
41
    case BinaryOperation::Mult:
16✔
42
        return "Mult";
16✔
43
    case BinaryOperation::NotEqual:
×
44
        return "NotEqual";
×
45
    case BinaryOperation::Or:
2✔
46
        return "Or";
2✔
47
    case BinaryOperation::Sub:
1✔
48
        return "Sub";
1✔
49
    case BinaryOperation::FGreater:
3✔
50
        return "FGreater";
3✔
51
    case BinaryOperation::FGreaterEqual:
×
52
        return "FGreaterEqual";
×
53
    case BinaryOperation::FLess:
1✔
54
        return "FLess";
1✔
55
    case BinaryOperation::FLessEqual:
×
56
        return "FLessEqual";
×
57
    case BinaryOperation::FNotEqual:
×
58
        return "FNotEqual";
×
59
    case BinaryOperation::FOr:
×
60
        return "FOr";
×
61
    case BinaryOperation::Unknown:
×
62
        return "Unknown";
×
63
    default:
×
64
        return "";
×
65
    }
66
}
67

68
const char *const unaryOperationToString(UnaryOperation unOp) {
43✔
69
    switch (unOp) {
43✔
70
    case UnaryOperation::Not:
9✔
71
        return "Not";
9✔
72
    case UnaryOperation::Negative:
34✔
73
        return "Negative";
34✔
74
    case UnaryOperation::Unknown:
×
75
        return "Unknown";
×
76
    }
77
    return "";
×
78
}
79

80
const char *const typeIdToString(TypeId typeId) {
450✔
81
    switch (typeId) {
450✔
82
    case IntType:
211✔
83
        return "IntType";
211✔
84
    case FloatType:
134✔
85
        return "FloatType";
134✔
86
    case BoolType:
3✔
87
        return "BoolType";
3✔
88
    case StrType:
×
89
        return "StrType";
×
90
    case ListType:
4✔
91
        return "ListType";
4✔
92
    case NoneType:
98✔
93
        return "NoneType";
98✔
94
    }
95
    return "";
×
96
}
97

98
void dumpVariablesTable(std::ostream &stream, const VariablesTable &table) {
78✔
99
    for (const auto &[name, variable] : table)
170✔
100
        stream << " " << name << ":" << typeIdToString(variable.type);
92✔
101
}
78✔
102

103
} // namespace
104

105
void Node::dump(std::ostream &stream, int depth) const {
2,137✔
106
    for (int i = 0; i < depth; i++)
11,587✔
107
        stream << "  ";
9,450✔
108
    // stream << "0x" << this << " ";
109
    switch (type) {
2,137✔
110
    case NodeType::BinaryOperation:
162✔
111
        stream << "BinaryOperation: " << binaryOperationToString(binOp()) << "\n";
162✔
112
        break;
162✔
113
    case NodeType::BooleanLiteralValue:
4✔
114
        stream << "BooleanLiteralValue: " << (boolean() ? "True" : "False") << "\n";
4✔
115
        break;
4✔
116
    case NodeType::BranchRoot:
136✔
117
        stream << "BranchRoot";
136✔
118
        if (std::holds_alternative<VariablesTable>(value)) {
136✔
119
            stream << ':';
78✔
120
            dumpVariablesTable(stream, variables());
78✔
121
        }
122
        stream << '\n';
136✔
123
        break;
136✔
124
    case NodeType::ElifStatement:
2✔
125
        stream << "ElifStatement\n";
2✔
126
        break;
2✔
127
    case NodeType::ElseStatement:
1✔
128
        stream << "ElseStatement\n";
1✔
129
        break;
1✔
130
    case NodeType::Expression:
297✔
131
        stream << "Expression";
297✔
132
        if (std::holds_alternative<TypeId>(value)) {
297✔
133
            stream << ": " << typeIdToString(typeId());
101✔
134
        }
135
        stream << '\n';
297✔
136
        break;
297✔
137
    case NodeType::FloatingPointLiteralValue:
33✔
138
        stream << "FloatingPointLiteralValue: " << fpNum() << "\n";
33✔
139
        break;
33✔
140
    case NodeType::FunctionArgument:
20✔
141
        stream << "FunctionArgument\n";
20✔
142
        break;
20✔
143
    case NodeType::FunctionArguments:
132✔
144
        stream << "FunctionArguments\n";
132✔
145
        break;
132✔
146
    case NodeType::FunctionCall:
38✔
147
        stream << "FunctionCall\n";
38✔
148
        break;
38✔
149
    case NodeType::FunctionDefinition:
103✔
150
        stream << "FunctionDefinition\n";
103✔
151
        break;
103✔
152
    case NodeType::FunctionName:
141✔
153
        stream << "FunctionName: " << str() << "\n";
141✔
154
        break;
141✔
155
    case NodeType::FunctionReturnType:
104✔
156
        if (typeId() >= BuiltInTypesCount)
104✔
157
            stream << "FunctionReturnType: user-defined(" << typeId() << ")\n";
×
158
        else
159
            stream << "FunctionReturnType: " << typeIdToString(typeId()) << "\n";
104✔
160
        break;
104✔
161
    case NodeType::IfStatement:
11✔
162
        stream << "IfStatement\n";
11✔
163
        break;
11✔
164
    case NodeType::IntegerLiteralValue:
148✔
165
        stream << "IntegerLiteralValue: " << intNum() << "\n";
148✔
166
        break;
148✔
167
    case NodeType::ProgramRoot:
90✔
168
        stream << "ProgramRoot\n";
90✔
169
        break;
90✔
170
    case NodeType::ReturnStatement:
14✔
171
        stream << "ReturnStatement\n";
14✔
172
        break;
14✔
173
    case NodeType::StringLiteralValue:
×
174
        stream << "StringLiteralValue: " << str() << "\n";
×
175
        break;
×
176
    case NodeType::TypeConversion:
26✔
177
        stream << "TypeConversion\n";
26✔
178
        break;
26✔
179
    case NodeType::TypeName:
153✔
180
        if (typeId() >= BuiltInTypesCount)
153✔
181
            stream << "TypeName: user-defined(" << typeId() << ")\n";
×
182
        else
183
            stream << "TypeName: " << typeIdToString(typeId()) << "\n";
153✔
184
        break;
153✔
185
    case NodeType::UnaryOperation:
43✔
186
        stream << "UnaryOperation: " << unaryOperationToString(unOp()) << "\n";
43✔
187
        break;
43✔
188
    case NodeType::VariableDeclaration:
103✔
189
        stream << "VariableDeclaration\n";
103✔
190
        break;
103✔
191
    case NodeType::VariableName:
322✔
192
        stream << "VariableName: " << str() << "\n";
322✔
193
        break;
322✔
194
    case NodeType::WhileStatement:
3✔
195
        stream << "WhileStatement\n";
3✔
196
        break;
3✔
197
    case NodeType::ListStatement:
3✔
198
        stream << "ListStatement\n";
3✔
199
        break;
3✔
200
    case NodeType::ListAccessor:
19✔
201
        stream << "ListAccessor\n";
19✔
202
        break;
19✔
NEW
203
    case NodeType::ListDynamicSize:
×
NEW
204
        stream << "ListDynamicSize\n";
×
NEW
205
        break;
×
206
    case NodeType::ForStatement:
8✔
207
        stream << "ForStatement\n";
8✔
208
        break;
8✔
209
    case NodeType::ForIterable:
8✔
210
        stream << "ForIterable\n";
8✔
211
        break;
8✔
212
    case NodeType::ForTargets:
8✔
213
        stream << "ForTargets\n";
8✔
214
        break;
8✔
215
    case NodeType::BreakStatement:
1✔
216
        stream << "BreakStatement\n";
1✔
217
        break;
1✔
218
    case NodeType::ContinueStatement:
1✔
219
        stream << "ContinueStatement\n";
1✔
220
        break;
1✔
221
    case NodeType::PassStatement:
3✔
222
        stream << "PassStatement\n";
3✔
223
        break;
3✔
224
    default:
×
225
        stream << "Unknown\n";
×
226
    }
227
    for (const auto &child : children)
4,183✔
228
        child->dump(stream, depth + 1);
2,046✔
229
}
2,137✔
230

231
std::string Node::dump(int depth) const {
3✔
232
    std::stringstream str;
3✔
233
    dump(str, depth);
3✔
234
    return str.str();
6✔
235
}
3✔
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