GCC Code Coverage Report


Directory: ../
File: src/ast/ASTBuilder.cpp
Date: 2025-11-11 23:26:16
Coverage Exec Excl Total
Lines: 95.1% 1133 17 1209
Functions: 100.0% 104 0 104
Branches: 58.9% 1567 4 2663

Line Branch Exec Source
1 // Copyright (c) 2021-2025 ChilliBits. All rights reserved.
2
3 #include "ASTBuilder.h"
4
5 #include <regex>
6
7 #include <SourceFile.h>
8 #include <ast/ASTNodes.h>
9 #include <ast/Attributes.h>
10 #include <exception/ParserError.h>
11 #include <typechecker/OpRuleManager.h>
12 #include <util/GlobalDefinitions.h>
13
14 namespace spice::compiler {
15
16 1192 ASTBuilder::ASTBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile, antlr4::ANTLRInputStream *inputStream)
17
1/2
✓ Branch 4 → 5 taken 1192 times.
✗ Branch 4 → 6 not taken.
1192 : CompilerPass(resourceManager, sourceFile), inputStream(inputStream) {}
18
19 1190 std::any ASTBuilder::visitEntry(SpiceParser::EntryContext *ctx) {
20 1190 const auto entryNode = createNode<EntryNode>(ctx);
21
22 // Visit children
23
2/2
✓ Branch 127 → 5 taken 18720 times.
✓ Branch 127 → 128 taken 1184 times.
19904 for (ParserRuleContext::ParseTree *child : ctx->children) {
24
3/4
✓ Branch 6 → 7 taken 18720 times.
✗ Branch 6 → 8 not taken.
✓ Branch 9 → 10 taken 418 times.
✓ Branch 9 → 15 taken 18302 times.
18720 if (auto *mainFctDefCtx = dynamic_cast<SpiceParser::MainFunctionDefContext *>(child))
25
4/6
✓ Branch 10 → 11 taken 414 times.
✓ Branch 10 → 140 taken 4 times.
✓ Branch 11 → 12 taken 414 times.
✗ Branch 11 → 138 not taken.
✓ Branch 12 → 13 taken 414 times.
✗ Branch 12 → 138 not taken.
418 entryNode->topLevelDefs.push_back(std::any_cast<MainFctDefNode *>(visit(mainFctDefCtx)));
26
3/4
✓ Branch 15 → 16 taken 18302 times.
✗ Branch 15 → 17 not taken.
✓ Branch 18 → 19 taken 7974 times.
✓ Branch 18 → 24 taken 10328 times.
18302 else if (auto *fctDefCtx = dynamic_cast<SpiceParser::FunctionDefContext *>(child))
27
3/6
✓ Branch 19 → 20 taken 7974 times.
✗ Branch 19 → 144 not taken.
✓ Branch 20 → 21 taken 7974 times.
✗ Branch 20 → 142 not taken.
✓ Branch 21 → 22 taken 7974 times.
✗ Branch 21 → 142 not taken.
7974 entryNode->topLevelDefs.push_back(std::any_cast<FctDefNode *>(visit(fctDefCtx)));
28
3/4
✓ Branch 24 → 25 taken 10328 times.
✗ Branch 24 → 26 not taken.
✓ Branch 27 → 28 taken 4026 times.
✓ Branch 27 → 33 taken 6302 times.
10328 else if (auto *procDefCtx = dynamic_cast<SpiceParser::ProcedureDefContext *>(child))
29
3/6
✓ Branch 28 → 29 taken 4026 times.
✗ Branch 28 → 148 not taken.
✓ Branch 29 → 30 taken 4026 times.
✗ Branch 29 → 146 not taken.
✓ Branch 30 → 31 taken 4026 times.
✗ Branch 30 → 146 not taken.
4026 entryNode->topLevelDefs.push_back(std::any_cast<ProcDefNode *>(visit(procDefCtx)));
30
3/4
✓ Branch 33 → 34 taken 6302 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 712 times.
✓ Branch 36 → 42 taken 5590 times.
6302 else if (auto *structDefCtx = dynamic_cast<SpiceParser::StructDefContext *>(child))
31
4/6
✓ Branch 37 → 38 taken 711 times.
✓ Branch 37 → 152 taken 1 time.
✓ Branch 38 → 39 taken 711 times.
✗ Branch 38 → 150 not taken.
✓ Branch 39 → 40 taken 711 times.
✗ Branch 39 → 150 not taken.
712 entryNode->topLevelDefs.push_back(std::any_cast<StructDefNode *>(visit(structDefCtx)));
32
3/4
✓ Branch 42 → 43 taken 5590 times.
✗ Branch 42 → 44 not taken.
✓ Branch 45 → 46 taken 103 times.
✓ Branch 45 → 51 taken 5487 times.
5590 else if (auto *interfaceDefCtx = dynamic_cast<SpiceParser::InterfaceDefContext *>(child))
33
3/6
✓ Branch 46 → 47 taken 103 times.
✗ Branch 46 → 156 not taken.
✓ Branch 47 → 48 taken 103 times.
✗ Branch 47 → 154 not taken.
✓ Branch 48 → 49 taken 103 times.
✗ Branch 48 → 154 not taken.
103 entryNode->topLevelDefs.push_back(std::any_cast<InterfaceDefNode *>(visit(interfaceDefCtx)));
34
3/4
✓ Branch 51 → 52 taken 5487 times.
✗ Branch 51 → 53 not taken.
✓ Branch 54 → 55 taken 68 times.
✓ Branch 54 → 60 taken 5419 times.
5487 else if (auto *enumDefCtx = dynamic_cast<SpiceParser::EnumDefContext *>(child))
35
3/6
✓ Branch 55 → 56 taken 68 times.
✗ Branch 55 → 160 not taken.
✓ Branch 56 → 57 taken 68 times.
✗ Branch 56 → 158 not taken.
✓ Branch 57 → 58 taken 68 times.
✗ Branch 57 → 158 not taken.
68 entryNode->topLevelDefs.push_back(std::any_cast<EnumDefNode *>(visit(enumDefCtx)));
36
3/4
✓ Branch 60 → 61 taken 5419 times.
✗ Branch 60 → 62 not taken.
✓ Branch 63 → 64 taken 957 times.
✓ Branch 63 → 69 taken 4462 times.
5419 else if (auto *genericTypeDefCtx = dynamic_cast<SpiceParser::GenericTypeDefContext *>(child))
37
3/6
✓ Branch 64 → 65 taken 957 times.
✗ Branch 64 → 164 not taken.
✓ Branch 65 → 66 taken 957 times.
✗ Branch 65 → 162 not taken.
✓ Branch 66 → 67 taken 957 times.
✗ Branch 66 → 162 not taken.
957 entryNode->topLevelDefs.push_back(std::any_cast<GenericTypeDefNode *>(visit(genericTypeDefCtx)));
38
3/4
✓ Branch 69 → 70 taken 4462 times.
✗ Branch 69 → 71 not taken.
✓ Branch 72 → 73 taken 71 times.
✓ Branch 72 → 78 taken 4391 times.
4462 else if (auto *aliasDefCtx = dynamic_cast<SpiceParser::AliasDefContext *>(child))
39
3/6
✓ Branch 73 → 74 taken 71 times.
✗ Branch 73 → 168 not taken.
✓ Branch 74 → 75 taken 71 times.
✗ Branch 74 → 166 not taken.
✓ Branch 75 → 76 taken 71 times.
✗ Branch 75 → 166 not taken.
71 entryNode->topLevelDefs.push_back(std::any_cast<AliasDefNode *>(visit(aliasDefCtx)));
40
3/4
✓ Branch 78 → 79 taken 4391 times.
✗ Branch 78 → 80 not taken.
✓ Branch 81 → 82 taken 1191 times.
✓ Branch 81 → 87 taken 3200 times.
4391 else if (auto *globalVarDefCtx = dynamic_cast<SpiceParser::GlobalVarDefContext *>(child))
41
3/6
✓ Branch 82 → 83 taken 1191 times.
✗ Branch 82 → 172 not taken.
✓ Branch 83 → 84 taken 1191 times.
✗ Branch 83 → 170 not taken.
✓ Branch 84 → 85 taken 1191 times.
✗ Branch 84 → 170 not taken.
1191 entryNode->topLevelDefs.push_back(std::any_cast<GlobalVarDefNode *>(visit(globalVarDefCtx)));
42
3/4
✓ Branch 87 → 88 taken 3200 times.
✗ Branch 87 → 89 not taken.
✓ Branch 90 → 91 taken 640 times.
✓ Branch 90 → 96 taken 2560 times.
3200 else if (auto *importDefCtx = dynamic_cast<SpiceParser::ImportDefContext *>(child))
43
3/6
✓ Branch 91 → 92 taken 640 times.
✗ Branch 91 → 176 not taken.
✓ Branch 92 → 93 taken 640 times.
✗ Branch 92 → 174 not taken.
✓ Branch 93 → 94 taken 640 times.
✗ Branch 93 → 174 not taken.
640 entryNode->importDefs.push_back(std::any_cast<ImportDefNode *>(visit(importDefCtx)));
44
3/4
✓ Branch 96 → 97 taken 2560 times.
✗ Branch 96 → 98 not taken.
✓ Branch 99 → 100 taken 1020 times.
✓ Branch 99 → 105 taken 1540 times.
2560 else if (auto *extDeclCtx = dynamic_cast<SpiceParser::ExtDeclContext *>(child))
45
3/6
✓ Branch 100 → 101 taken 1020 times.
✗ Branch 100 → 180 not taken.
✓ Branch 101 → 102 taken 1020 times.
✗ Branch 101 → 178 not taken.
✓ Branch 102 → 103 taken 1020 times.
✗ Branch 102 → 178 not taken.
1020 entryNode->topLevelDefs.push_back(std::any_cast<ExtDeclNode *>(visit(extDeclCtx)));
46
3/4
✓ Branch 105 → 106 taken 1540 times.
✗ Branch 105 → 107 not taken.
✓ Branch 108 → 109 taken 356 times.
✓ Branch 108 → 114 taken 1184 times.
1540 else if (auto *modAttrCtx = dynamic_cast<SpiceParser::ModAttrContext *>(child))
47
4/6
✓ Branch 109 → 110 taken 355 times.
✓ Branch 109 → 184 taken 1 time.
✓ Branch 110 → 111 taken 355 times.
✗ Branch 110 → 182 not taken.
✓ Branch 111 → 112 taken 355 times.
✗ Branch 111 → 182 not taken.
356 entryNode->modAttrs.push_back(std::any_cast<ModAttrNode *>(visit(modAttrCtx)));
48
1/2
✓ Branch 114 → 115 taken 1184 times.
✗ Branch 114 → 116 not taken.
1184 else if (const auto *eofCtx = dynamic_cast<TerminalNode *>(child);
49
5/10
✓ Branch 117 → 118 taken 1184 times.
✗ Branch 117 → 121 not taken.
✓ Branch 118 → 119 taken 1184 times.
✗ Branch 118 → 186 not taken.
✓ Branch 119 → 120 taken 1184 times.
✗ Branch 119 → 186 not taken.
✗ Branch 120 → 121 not taken.
✓ Branch 120 → 122 taken 1184 times.
✗ Branch 123 → 124 not taken.
✓ Branch 123 → 125 taken 1184 times.
1184 !eofCtx || eofCtx->getSymbol()->getType() != SpiceParser::EOF)
50 assert_fail("Unknown top level definition type"); // GCOV_EXCL_LINE
51 }
52
53
1/2
✓ Branch 134 → 135 taken 1184 times.
✗ Branch 134 → 187 not taken.
1184 return concludeNode(entryNode);
54 }
55
56 418 std::any ASTBuilder::visitMainFunctionDef(SpiceParser::MainFunctionDefContext *ctx) {
57 418 const auto mainFctDefNode = createNode<MainFctDefNode>(ctx);
58
59 // Visit children
60
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 10 taken 417 times.
418 if (ctx->topLevelDefAttr())
61
3/6
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 33 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 33 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 31 not taken.
1 mainFctDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
62
2/2
✓ Branch 11 → 12 taken 4 times.
✓ Branch 11 → 17 taken 414 times.
418 if (ctx->paramLst()) {
63 4 mainFctDefNode->takesArgs = true;
64
3/6
✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 4 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 4 times.
✗ Branch 14 → 34 not taken.
4 mainFctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
65 }
66
4/6
✓ Branch 17 → 18 taken 418 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 414 times.
✓ Branch 18 → 39 taken 4 times.
✓ Branch 19 → 20 taken 414 times.
✗ Branch 19 → 37 not taken.
418 mainFctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
67
68
1/2
✓ Branch 27 → 28 taken 414 times.
✗ Branch 27 → 40 not taken.
414 return concludeNode(mainFctDefNode);
69 }
70
71 7974 std::any ASTBuilder::visitFunctionDef(SpiceParser::FunctionDefContext *ctx) {
72 7974 const auto fctDefNode = createNode<FctDefNode>(ctx);
73
74 // Visit children
75
2/2
✓ Branch 4 → 5 taken 321 times.
✓ Branch 4 → 16 taken 7653 times.
7974 if (ctx->topLevelDefAttr()) {
76
3/6
✓ Branch 5 → 6 taken 321 times.
✗ Branch 5 → 62 not taken.
✓ Branch 6 → 7 taken 321 times.
✗ Branch 6 → 62 not taken.
✓ Branch 7 → 8 taken 321 times.
✗ Branch 7 → 60 not taken.
321 fctDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
77 // Tell the attributes that they are function attributes
78
2/2
✓ Branch 14 → 11 taken 326 times.
✓ Branch 14 → 15 taken 321 times.
647 for (AttrNode *attr : fctDefNode->attrs->attrLst->attributes)
79 326 attr->target = AttrNode::TARGET_FCT_PROC;
80 }
81
2/2
✓ Branch 17 → 18 taken 7793 times.
✓ Branch 17 → 23 taken 181 times.
7974 if (ctx->qualifierLst())
82
3/6
✓ Branch 18 → 19 taken 7793 times.
✗ Branch 18 → 65 not taken.
✓ Branch 19 → 20 taken 7793 times.
✗ Branch 19 → 65 not taken.
✓ Branch 20 → 21 taken 7793 times.
✗ Branch 20 → 63 not taken.
7793 fctDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
83
3/6
✓ Branch 23 → 24 taken 7974 times.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 7974 times.
✗ Branch 24 → 68 not taken.
✓ Branch 25 → 26 taken 7974 times.
✗ Branch 25 → 66 not taken.
7974 fctDefNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
84 7974 fctDefNode->returnType->isReturnType = true;
85
3/6
✓ Branch 27 → 28 taken 7974 times.
✗ Branch 27 → 71 not taken.
✓ Branch 28 → 29 taken 7974 times.
✗ Branch 28 → 71 not taken.
✓ Branch 29 → 30 taken 7974 times.
✗ Branch 29 → 69 not taken.
7974 fctDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName()));
86 7974 fctDefNode->isMethod = fctDefNode->name->nameFragments.size() > 1;
87
2/2
✓ Branch 33 → 34 taken 1088 times.
✓ Branch 33 → 39 taken 6886 times.
7974 if (ctx->typeLst()) {
88 1088 fctDefNode->hasTemplateTypes = true;
89
3/6
✓ Branch 34 → 35 taken 1088 times.
✗ Branch 34 → 74 not taken.
✓ Branch 35 → 36 taken 1088 times.
✗ Branch 35 → 74 not taken.
✓ Branch 36 → 37 taken 1088 times.
✗ Branch 36 → 72 not taken.
1088 fctDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
90 }
91
2/2
✓ Branch 40 → 41 taken 6128 times.
✓ Branch 40 → 46 taken 1846 times.
7974 if (ctx->paramLst()) {
92 6128 fctDefNode->hasParams = true;
93
3/6
✓ Branch 41 → 42 taken 6128 times.
✗ Branch 41 → 77 not taken.
✓ Branch 42 → 43 taken 6128 times.
✗ Branch 42 → 77 not taken.
✓ Branch 43 → 44 taken 6128 times.
✗ Branch 43 → 75 not taken.
6128 fctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
94 }
95
3/6
✓ Branch 46 → 47 taken 7974 times.
✗ Branch 46 → 80 not taken.
✓ Branch 47 → 48 taken 7974 times.
✗ Branch 47 → 80 not taken.
✓ Branch 48 → 49 taken 7974 times.
✗ Branch 48 → 78 not taken.
7974 fctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
96
97
1/2
✓ Branch 56 → 57 taken 7974 times.
✗ Branch 56 → 81 not taken.
7974 return concludeNode(fctDefNode);
98 }
99
100 4026 std::any ASTBuilder::visitProcedureDef(SpiceParser::ProcedureDefContext *ctx) {
101 4026 const auto procDefNode = createNode<ProcDefNode>(ctx);
102
103 // Visit children
104
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 16 taken 4025 times.
4026 if (ctx->topLevelDefAttr()) {
105
3/6
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 58 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 58 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 56 not taken.
1 procDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
106 // Tell the attributes that they are function attributes
107
2/2
✓ Branch 14 → 11 taken 1 time.
✓ Branch 14 → 15 taken 1 time.
2 for (AttrNode *attr : procDefNode->attrs->attrLst->attributes)
108 1 attr->target = AttrNode::TARGET_FCT_PROC;
109 }
110
2/2
✓ Branch 17 → 18 taken 3584 times.
✓ Branch 17 → 23 taken 442 times.
4026 if (ctx->qualifierLst())
111
3/6
✓ Branch 18 → 19 taken 3584 times.
✗ Branch 18 → 61 not taken.
✓ Branch 19 → 20 taken 3584 times.
✗ Branch 19 → 61 not taken.
✓ Branch 20 → 21 taken 3584 times.
✗ Branch 20 → 59 not taken.
3584 procDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
112
3/6
✓ Branch 23 → 24 taken 4026 times.
✗ Branch 23 → 64 not taken.
✓ Branch 24 → 25 taken 4026 times.
✗ Branch 24 → 64 not taken.
✓ Branch 25 → 26 taken 4026 times.
✗ Branch 25 → 62 not taken.
4026 procDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName()));
113 4026 procDefNode->isMethod = procDefNode->name->nameFragments.size() > 1;
114
2/2
✓ Branch 29 → 30 taken 1093 times.
✓ Branch 29 → 35 taken 2933 times.
4026 if (ctx->typeLst()) {
115 1093 procDefNode->hasTemplateTypes = true;
116
3/6
✓ Branch 30 → 31 taken 1093 times.
✗ Branch 30 → 67 not taken.
✓ Branch 31 → 32 taken 1093 times.
✗ Branch 31 → 67 not taken.
✓ Branch 32 → 33 taken 1093 times.
✗ Branch 32 → 65 not taken.
1093 procDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
117 }
118
2/2
✓ Branch 36 → 37 taken 2994 times.
✓ Branch 36 → 42 taken 1032 times.
4026 if (ctx->paramLst()) {
119 2994 procDefNode->hasParams = true;
120
3/6
✓ Branch 37 → 38 taken 2994 times.
✗ Branch 37 → 70 not taken.
✓ Branch 38 → 39 taken 2994 times.
✗ Branch 38 → 70 not taken.
✓ Branch 39 → 40 taken 2994 times.
✗ Branch 39 → 68 not taken.
2994 procDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
121 }
122
3/6
✓ Branch 42 → 43 taken 4026 times.
✗ Branch 42 → 73 not taken.
✓ Branch 43 → 44 taken 4026 times.
✗ Branch 43 → 73 not taken.
✓ Branch 44 → 45 taken 4026 times.
✗ Branch 44 → 71 not taken.
4026 procDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
123
124
1/2
✓ Branch 52 → 53 taken 4026 times.
✗ Branch 52 → 74 not taken.
4026 return concludeNode(procDefNode);
125 }
126
127 12000 std::any ASTBuilder::visitFctName(SpiceParser::FctNameContext *ctx) {
128 12000 const auto fctNameNode = createNode<FctNameNode>(ctx);
129
130 // Extract function name
131
2/2
✓ Branch 4 → 5 taken 6577 times.
✓ Branch 4 → 14 taken 5423 times.
12000 if (ctx->TYPE_IDENTIFIER()) {
132
2/4
✓ Branch 5 → 6 taken 6577 times.
✗ Branch 5 → 42 not taken.
✓ Branch 6 → 7 taken 6577 times.
✗ Branch 6 → 42 not taken.
6577 const std::string typeIdentifier = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
133
1/2
✓ Branch 7 → 8 taken 6577 times.
✗ Branch 7 → 40 not taken.
6577 fctNameNode->structName = typeIdentifier;
134
1/2
✓ Branch 8 → 9 taken 6577 times.
✗ Branch 8 → 39 not taken.
6577 fctNameNode->fqName = typeIdentifier + MEMBER_ACCESS_TOKEN;
135
1/2
✓ Branch 11 → 12 taken 6577 times.
✗ Branch 11 → 40 not taken.
6577 fctNameNode->nameFragments.push_back(typeIdentifier);
136 6577 }
137
2/2
✓ Branch 15 → 16 taken 10233 times.
✓ Branch 15 → 23 taken 1767 times.
12000 if (ctx->IDENTIFIER()) {
138
2/4
✓ Branch 16 → 17 taken 10233 times.
✗ Branch 16 → 45 not taken.
✓ Branch 17 → 18 taken 10233 times.
✗ Branch 17 → 45 not taken.
10233 const std::string fctIdentifier = getIdentifier(ctx->IDENTIFIER(), false);
139
1/2
✓ Branch 18 → 19 taken 10233 times.
✗ Branch 18 → 43 not taken.
10233 fctNameNode->name = fctIdentifier;
140
1/2
✓ Branch 19 → 20 taken 10233 times.
✗ Branch 19 → 43 not taken.
10233 fctNameNode->fqName += fctIdentifier;
141
1/2
✓ Branch 20 → 21 taken 10233 times.
✗ Branch 20 → 43 not taken.
10233 fctNameNode->nameFragments.push_back(fctIdentifier);
142 10233 }
143
144 // Visit children
145
2/2
✓ Branch 24 → 25 taken 1767 times.
✓ Branch 24 → 29 taken 10233 times.
12000 if (ctx->overloadableOp())
146
2/4
✓ Branch 25 → 26 taken 1767 times.
✗ Branch 25 → 46 not taken.
✓ Branch 26 → 27 taken 1767 times.
✗ Branch 26 → 46 not taken.
1767 visit(ctx->overloadableOp());
147
148
1/2
✓ Branch 35 → 36 taken 12000 times.
✗ Branch 35 → 47 not taken.
12000 return concludeNode(fctNameNode);
149 }
150
151 712 std::any ASTBuilder::visitStructDef(SpiceParser::StructDefContext *ctx) {
152 712 const auto structDefNode = createNode<StructDefNode>(ctx);
153
154 // Enrich
155
3/4
✓ Branch 3 → 4 taken 712 times.
✗ Branch 3 → 87 not taken.
✓ Branch 4 → 5 taken 711 times.
✓ Branch 4 → 87 taken 1 time.
712 structDefNode->structName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
156 711 structDefNode->typeId = resourceManager.getNextCustomTypeId();
157
158 // Visit children
159
2/2
✓ Branch 9 → 10 taken 62 times.
✓ Branch 9 → 41 taken 649 times.
711 if (ctx->topLevelDefAttr()) {
160
3/6
✓ Branch 10 → 11 taken 62 times.
✗ Branch 10 → 90 not taken.
✓ Branch 11 → 12 taken 62 times.
✗ Branch 11 → 90 not taken.
✓ Branch 12 → 13 taken 62 times.
✗ Branch 12 → 88 not taken.
62 structDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
161
162 // Tell the attributes that they are struct attributes
163
2/2
✓ Branch 19 → 16 taken 62 times.
✓ Branch 19 → 20 taken 62 times.
124 for (AttrNode *attr : structDefNode->attrs->attrLst->attributes)
164 62 attr->target = AttrNode::TARGET_STRUCT;
165
166 // Check if a custom type id was set
167
7/18
✓ Branch 20 → 21 taken 62 times.
✗ Branch 20 → 27 not taken.
✓ Branch 23 → 24 taken 62 times.
✗ Branch 23 → 91 not taken.
✓ Branch 24 → 25 taken 62 times.
✗ Branch 24 → 91 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 62 times.
✓ Branch 28 → 29 taken 62 times.
✗ Branch 28 → 30 not taken.
✓ Branch 30 → 31 taken 62 times.
✗ Branch 30 → 33 not taken.
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 41 taken 62 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 98 not taken.
186 if (structDefNode->attrs && structDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID))
168 structDefNode->typeId = structDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue;
169 }
170
2/2
✓ Branch 42 → 43 taken 558 times.
✓ Branch 42 → 48 taken 153 times.
711 if (ctx->qualifierLst())
171
3/6
✓ Branch 43 → 44 taken 558 times.
✗ Branch 43 → 108 not taken.
✓ Branch 44 → 45 taken 558 times.
✗ Branch 44 → 108 not taken.
✓ Branch 45 → 46 taken 558 times.
✗ Branch 45 → 106 not taken.
558 structDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
172
2/2
✓ Branch 49 → 50 taken 257 times.
✓ Branch 49 → 55 taken 454 times.
711 if (ctx->LESS()) {
173 257 structDefNode->hasTemplateTypes = true;
174
3/6
✓ Branch 50 → 51 taken 257 times.
✗ Branch 50 → 111 not taken.
✓ Branch 51 → 52 taken 257 times.
✗ Branch 51 → 111 not taken.
✓ Branch 52 → 53 taken 257 times.
✗ Branch 52 → 109 not taken.
257 structDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0)));
175 }
176
2/2
✓ Branch 56 → 57 taken 138 times.
✓ Branch 56 → 65 taken 573 times.
711 if (ctx->COLON()) {
177 138 structDefNode->hasInterfaces = true;
178
5/8
✓ Branch 57 → 58 taken 119 times.
✓ Branch 57 → 59 taken 19 times.
✓ Branch 60 → 61 taken 138 times.
✗ Branch 60 → 114 not taken.
✓ Branch 61 → 62 taken 138 times.
✗ Branch 61 → 114 not taken.
✓ Branch 62 → 63 taken 138 times.
✗ Branch 62 → 112 not taken.
138 structDefNode->interfaceTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(structDefNode->hasTemplateTypes ? 1 : 0)));
179 }
180
3/4
✓ Branch 65 → 66 taken 711 times.
✗ Branch 65 → 121 not taken.
✓ Branch 75 → 68 taken 1533 times.
✓ Branch 75 → 76 taken 711 times.
2244 for (SpiceParser::FieldContext *field : ctx->field())
181
3/6
✓ Branch 69 → 70 taken 1533 times.
✗ Branch 69 → 117 not taken.
✓ Branch 70 → 71 taken 1533 times.
✗ Branch 70 → 115 not taken.
✓ Branch 71 → 72 taken 1533 times.
✗ Branch 71 → 115 not taken.
2244 structDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field)));
182
183
1/2
✓ Branch 83 → 84 taken 711 times.
✗ Branch 83 → 122 not taken.
711 return concludeNode(structDefNode);
184 }
185
186 103 std::any ASTBuilder::visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) {
187 103 const auto interfaceDefNode = createNode<InterfaceDefNode>(ctx);
188
189 // Enrich
190
2/4
✓ Branch 3 → 4 taken 103 times.
✗ Branch 3 → 77 not taken.
✓ Branch 4 → 5 taken 103 times.
✗ Branch 4 → 77 not taken.
103 interfaceDefNode->interfaceName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
191 103 interfaceDefNode->typeId = resourceManager.getNextCustomTypeId();
192
193 // Visit children
194
2/2
✓ Branch 9 → 10 taken 75 times.
✓ Branch 9 → 41 taken 28 times.
103 if (ctx->topLevelDefAttr()) {
195
3/6
✓ Branch 10 → 11 taken 75 times.
✗ Branch 10 → 80 not taken.
✓ Branch 11 → 12 taken 75 times.
✗ Branch 11 → 80 not taken.
✓ Branch 12 → 13 taken 75 times.
✗ Branch 12 → 78 not taken.
75 interfaceDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
196
197 // Tell the attributes that they are struct attributes
198
2/2
✓ Branch 19 → 16 taken 75 times.
✓ Branch 19 → 20 taken 75 times.
150 for (AttrNode *attr : interfaceDefNode->attrs->attrLst->attributes)
199 75 attr->target = AttrNode::TARGET_INTERFACE;
200
201 // Check if a custom type id was set
202
7/18
✓ Branch 20 → 21 taken 75 times.
✗ Branch 20 → 27 not taken.
✓ Branch 23 → 24 taken 75 times.
✗ Branch 23 → 81 not taken.
✓ Branch 24 → 25 taken 75 times.
✗ Branch 24 → 81 not taken.
✓ Branch 25 → 26 taken 75 times.
✗ Branch 25 → 27 not taken.
✓ Branch 28 → 29 taken 75 times.
✗ Branch 28 → 30 not taken.
✓ Branch 30 → 31 taken 75 times.
✗ Branch 30 → 33 not taken.
✓ Branch 33 → 34 taken 75 times.
✗ Branch 33 → 41 not taken.
✗ Branch 81 → 82 not taken.
✗ Branch 81 → 83 not taken.
✗ Branch 85 → 86 not taken.
✗ Branch 85 → 88 not taken.
225 if (interfaceDefNode->attrs && interfaceDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID))
203
2/4
✓ Branch 36 → 37 taken 75 times.
✗ Branch 36 → 92 not taken.
✓ Branch 37 → 38 taken 75 times.
✗ Branch 37 → 90 not taken.
225 interfaceDefNode->typeId = interfaceDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue;
204 }
205
2/2
✓ Branch 42 → 43 taken 87 times.
✓ Branch 42 → 48 taken 16 times.
103 if (ctx->qualifierLst())
206
3/6
✓ Branch 43 → 44 taken 87 times.
✗ Branch 43 → 98 not taken.
✓ Branch 44 → 45 taken 87 times.
✗ Branch 44 → 98 not taken.
✓ Branch 45 → 46 taken 87 times.
✗ Branch 45 → 96 not taken.
87 interfaceDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
207
2/2
✓ Branch 49 → 50 taken 78 times.
✓ Branch 49 → 55 taken 25 times.
103 if (ctx->LESS()) {
208 78 interfaceDefNode->hasTemplateTypes = true;
209
3/6
✓ Branch 50 → 51 taken 78 times.
✗ Branch 50 → 101 not taken.
✓ Branch 51 → 52 taken 78 times.
✗ Branch 51 → 101 not taken.
✓ Branch 52 → 53 taken 78 times.
✗ Branch 52 → 99 not taken.
78 interfaceDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
210 }
211
3/4
✓ Branch 55 → 56 taken 103 times.
✗ Branch 55 → 108 not taken.
✓ Branch 65 → 58 taken 236 times.
✓ Branch 65 → 66 taken 103 times.
339 for (SpiceParser::SignatureContext *signature : ctx->signature())
212
3/6
✓ Branch 59 → 60 taken 236 times.
✗ Branch 59 → 104 not taken.
✓ Branch 60 → 61 taken 236 times.
✗ Branch 60 → 102 not taken.
✓ Branch 61 → 62 taken 236 times.
✗ Branch 61 → 102 not taken.
339 interfaceDefNode->signatures.push_back(std::any_cast<SignatureNode *>(visit(signature)));
213
214
1/2
✓ Branch 73 → 74 taken 103 times.
✗ Branch 73 → 109 not taken.
103 return concludeNode(interfaceDefNode);
215 }
216
217 68 std::any ASTBuilder::visitEnumDef(SpiceParser::EnumDefContext *ctx) {
218 68 const auto enumDefNode = createNode<EnumDefNode>(ctx);
219
220 // Enrich
221
2/4
✓ Branch 3 → 4 taken 68 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 68 times.
✗ Branch 4 → 35 not taken.
68 enumDefNode->enumName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
222 68 enumDefNode->typeId = resourceManager.getNextCustomTypeId();
223
224 // Visit children
225
2/2
✓ Branch 9 → 10 taken 52 times.
✓ Branch 9 → 15 taken 16 times.
68 if (ctx->qualifierLst())
226
3/6
✓ Branch 10 → 11 taken 52 times.
✗ Branch 10 → 38 not taken.
✓ Branch 11 → 12 taken 52 times.
✗ Branch 11 → 38 not taken.
✓ Branch 12 → 13 taken 52 times.
✗ Branch 12 → 36 not taken.
52 enumDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
227
3/6
✓ Branch 15 → 16 taken 68 times.
✗ Branch 15 → 41 not taken.
✓ Branch 16 → 17 taken 68 times.
✗ Branch 16 → 41 not taken.
✓ Branch 17 → 18 taken 68 times.
✗ Branch 17 → 39 not taken.
68 enumDefNode->itemLst = std::any_cast<EnumItemLstNode *>(visit(ctx->enumItemLst()));
228
229 // Tell all items about the enum def
230
2/2
✓ Branch 24 → 21 taken 746 times.
✓ Branch 24 → 25 taken 68 times.
814 for (EnumItemNode *enumItem : enumDefNode->itemLst->items)
231 746 enumItem->enumDef = enumDefNode;
232
233
1/2
✓ Branch 31 → 32 taken 68 times.
✗ Branch 31 → 42 not taken.
68 return concludeNode(enumDefNode);
234 }
235
236 957 std::any ASTBuilder::visitGenericTypeDef(SpiceParser::GenericTypeDefContext *ctx) {
237 957 const auto genericTypeDefNode = createNode<GenericTypeDefNode>(ctx);
238
239 // Enrich
240
2/4
✓ Branch 3 → 4 taken 957 times.
✗ Branch 3 → 21 not taken.
✓ Branch 4 → 5 taken 957 times.
✗ Branch 4 → 21 not taken.
957 genericTypeDefNode->typeName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
241
242 // Visit children
243
3/6
✓ Branch 7 → 8 taken 957 times.
✗ Branch 7 → 24 not taken.
✓ Branch 8 → 9 taken 957 times.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 957 times.
✗ Branch 9 → 22 not taken.
957 genericTypeDefNode->typeAltsLst = std::any_cast<TypeAltsLstNode *>(visit(ctx->typeAltsLst()));
244
245
1/2
✓ Branch 17 → 18 taken 957 times.
✗ Branch 17 → 25 not taken.
957 return concludeNode(genericTypeDefNode);
246 }
247
248 71 std::any ASTBuilder::visitAliasDef(SpiceParser::AliasDefContext *ctx) {
249 71 const auto aliasDefNode = createNode<AliasDefNode>(ctx);
250
251 // Enrich
252
2/4
✓ Branch 3 → 4 taken 71 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 71 times.
✗ Branch 4 → 33 not taken.
71 aliasDefNode->aliasName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
253
2/4
✓ Branch 7 → 8 taken 71 times.
✗ Branch 7 → 34 not taken.
✓ Branch 8 → 9 taken 71 times.
✗ Branch 8 → 34 not taken.
71 aliasDefNode->dataTypeString = ctx->dataType()->getText();
254 71 aliasDefNode->typeId = resourceManager.getNextCustomTypeId();
255
256 // Visit children
257
2/2
✓ Branch 13 → 14 taken 21 times.
✓ Branch 13 → 19 taken 50 times.
71 if (ctx->qualifierLst())
258
3/6
✓ Branch 14 → 15 taken 21 times.
✗ Branch 14 → 37 not taken.
✓ Branch 15 → 16 taken 21 times.
✗ Branch 15 → 37 not taken.
✓ Branch 16 → 17 taken 21 times.
✗ Branch 16 → 35 not taken.
21 aliasDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
259
3/6
✓ Branch 19 → 20 taken 71 times.
✗ Branch 19 → 40 not taken.
✓ Branch 20 → 21 taken 71 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 71 times.
✗ Branch 21 → 38 not taken.
71 aliasDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
260
261
1/2
✓ Branch 29 → 30 taken 71 times.
✗ Branch 29 → 41 not taken.
71 return concludeNode(aliasDefNode);
262 }
263
264 1191 std::any ASTBuilder::visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) {
265 1191 const auto globalVarDefNode = createNode<GlobalVarDefNode>(ctx);
266
267 // Enrich
268
2/4
✓ Branch 3 → 4 taken 1191 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 1191 times.
✗ Branch 4 → 28 not taken.
1191 globalVarDefNode->varName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
269
270 // Visit children
271
3/6
✓ Branch 7 → 8 taken 1191 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 1191 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 1191 times.
✗ Branch 9 → 29 not taken.
1191 globalVarDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
272 1191 globalVarDefNode->dataType->isGlobalType = true;
273
2/2
✓ Branch 12 → 13 taken 1189 times.
✓ Branch 12 → 18 taken 2 times.
1191 if (ctx->constant()) {
274 1189 globalVarDefNode->hasValue = true;
275
3/6
✓ Branch 13 → 14 taken 1189 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 1189 times.
✗ Branch 14 → 34 not taken.
✓ Branch 15 → 16 taken 1189 times.
✗ Branch 15 → 32 not taken.
1189 globalVarDefNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
276 }
277
278
1/2
✓ Branch 24 → 25 taken 1191 times.
✗ Branch 24 → 35 not taken.
1191 return concludeNode(globalVarDefNode);
279 }
280
281 1020 std::any ASTBuilder::visitExtDecl(SpiceParser::ExtDeclContext *ctx) {
282 1020 const auto extDeclNode = createNode<ExtDeclNode>(ctx);
283
284 // Enrich
285
6/10
✓ Branch 3 → 4 taken 1020 times.
✗ Branch 3 → 49 not taken.
✓ Branch 4 → 5 taken 768 times.
✓ Branch 4 → 7 taken 252 times.
✓ Branch 5 → 6 taken 768 times.
✗ Branch 5 → 49 not taken.
✓ Branch 7 → 8 taken 252 times.
✗ Branch 7 → 49 not taken.
✓ Branch 9 → 10 taken 1020 times.
✗ Branch 9 → 49 not taken.
1020 extDeclNode->extFunctionName = getIdentifier(ctx->IDENTIFIER() ? ctx->IDENTIFIER() : ctx->TYPE_IDENTIFIER(), false);
286
287 // Visit children
288
2/2
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 25 taken 1019 times.
1020 if (ctx->topLevelDefAttr()) {
289
3/6
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 52 not taken.
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 52 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 50 not taken.
1 extDeclNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
290
291 // Tell the attributes that they are ext decl attributes
292
2/2
✓ Branch 23 → 20 taken 1 time.
✓ Branch 23 → 24 taken 1 time.
2 for (AttrNode *attr : extDeclNode->attrs->attrLst->attributes)
293 1 attr->target = AttrNode::TARGET_EXT_DECL;
294 }
295
2/2
✓ Branch 26 → 27 taken 670 times.
✓ Branch 26 → 32 taken 350 times.
1020 if (ctx->F()) {
296
3/6
✓ Branch 27 → 28 taken 670 times.
✗ Branch 27 → 55 not taken.
✓ Branch 28 → 29 taken 670 times.
✗ Branch 28 → 55 not taken.
✓ Branch 29 → 30 taken 670 times.
✗ Branch 29 → 53 not taken.
670 extDeclNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
297 670 extDeclNode->returnType->isReturnType = true;
298 }
299
2/2
✓ Branch 33 → 34 taken 978 times.
✓ Branch 33 → 39 taken 42 times.
1020 if (ctx->typeLstWithEllipsis()) {
300 978 extDeclNode->hasArgs = true;
301
3/6
✓ Branch 34 → 35 taken 978 times.
✗ Branch 34 → 58 not taken.
✓ Branch 35 → 36 taken 978 times.
✗ Branch 35 → 58 not taken.
✓ Branch 36 → 37 taken 978 times.
✗ Branch 36 → 56 not taken.
978 extDeclNode->argTypeLst = std::any_cast<TypeLstWithEllipsisNode *>(visit(ctx->typeLstWithEllipsis()));
302 }
303
304
1/2
✓ Branch 45 → 46 taken 1020 times.
✗ Branch 45 → 59 not taken.
1020 return concludeNode(extDeclNode);
305 }
306
307 640 std::any ASTBuilder::visitImportDef(SpiceParser::ImportDefContext *ctx) {
308
1/2
✓ Branch 2 → 3 taken 640 times.
✗ Branch 2 → 32 not taken.
640 const auto importDefNode = createNode<ImportDefNode>(ctx);
309
310 // Extract path
311
2/4
✓ Branch 3 → 4 taken 640 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 640 times.
✗ Branch 4 → 32 not taken.
640 const std::string pathStr = ctx->STRING_LIT()->getText();
312
1/2
✓ Branch 6 → 7 taken 640 times.
✗ Branch 6 → 27 not taken.
640 importDefNode->importPath = pathStr.substr(1, pathStr.size() - 2);
313
314 // If no name is given, use the path as name
315
6/10
✓ Branch 9 → 10 taken 640 times.
✗ Branch 9 → 28 not taken.
✓ Branch 10 → 11 taken 33 times.
✓ Branch 10 → 13 taken 607 times.
✓ Branch 11 → 12 taken 33 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 14 taken 33 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 607 times.
✗ Branch 13 → 28 not taken.
640 importDefNode->importName = ctx->AS() ? getIdentifier(ctx->IDENTIFIER(), false) : importDefNode->importPath;
316
317
1/2
✓ Branch 22 → 23 taken 640 times.
✗ Branch 22 → 29 not taken.
1280 return concludeNode(importDefNode);
318 640 }
319
320 2585 std::any ASTBuilder::visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) {
321 2585 const auto unsafeBlockDefNode = createNode<UnsafeBlockNode>(ctx);
322
323 // Visit children
324
3/6
✓ Branch 3 → 4 taken 2585 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 2585 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 2585 times.
✗ Branch 5 → 17 not taken.
2585 unsafeBlockDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
325
326
1/2
✓ Branch 13 → 14 taken 2585 times.
✗ Branch 13 → 20 not taken.
2585 return concludeNode(unsafeBlockDefNode);
327 }
328
329 1385 std::any ASTBuilder::visitForLoop(SpiceParser::ForLoopContext *ctx) {
330 1385 const auto forLoopNode = createNode<ForLoopNode>(ctx);
331
332
2/4
✓ Branch 3 → 4 taken 1385 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 1385 times.
✗ Branch 4 → 20 not taken.
1385 visit(ctx->forHead());
333
3/6
✓ Branch 6 → 7 taken 1385 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 1385 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 1385 times.
✗ Branch 8 → 21 not taken.
1385 forLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
334
335
1/2
✓ Branch 16 → 17 taken 1385 times.
✗ Branch 16 → 24 not taken.
1385 return concludeNode(forLoopNode);
336 }
337
338 1385 std::any ASTBuilder::visitForHead(SpiceParser::ForHeadContext *ctx) {
339 1385 const auto forLoopNode = resumeForExpansion<ForLoopNode>();
340
341 // Visit children
342
3/6
✓ Branch 12 → 13 taken 1385 times.
✗ Branch 12 → 29 not taken.
✓ Branch 13 → 14 taken 1385 times.
✗ Branch 13 → 29 not taken.
✓ Branch 14 → 15 taken 1385 times.
✗ Branch 14 → 27 not taken.
1385 forLoopNode->initDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt()));
343
3/6
✓ Branch 16 → 17 taken 1385 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 1385 times.
✗ Branch 17 → 32 not taken.
✓ Branch 18 → 19 taken 1385 times.
✗ Branch 18 → 30 not taken.
1385 forLoopNode->condAssign = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr(0)));
344
3/6
✓ Branch 20 → 21 taken 1385 times.
✗ Branch 20 → 35 not taken.
✓ Branch 21 → 22 taken 1385 times.
✗ Branch 21 → 35 not taken.
✓ Branch 22 → 23 taken 1385 times.
✗ Branch 22 → 33 not taken.
1385 forLoopNode->incAssign = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr(1)));
345
346
1/2
✓ Branch 24 → 25 taken 1385 times.
✗ Branch 24 → 36 not taken.
1385 return nullptr;
347 }
348
349 124 std::any ASTBuilder::visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) {
350 124 const auto foreachLoopNode = createNode<ForeachLoopNode>(ctx);
351
352 // Visit children
353
2/4
✓ Branch 3 → 4 taken 124 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 124 times.
✗ Branch 4 → 20 not taken.
124 visit(ctx->foreachHead());
354
3/6
✓ Branch 6 → 7 taken 124 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 124 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 124 times.
✗ Branch 8 → 21 not taken.
124 foreachLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
355
356 // Tell the foreach item that it is one
357 124 foreachLoopNode->itemVarDecl->isForEachItem = true;
358
359
1/2
✓ Branch 16 → 17 taken 124 times.
✗ Branch 16 → 24 not taken.
124 return concludeNode(foreachLoopNode);
360 }
361
362 124 std::any ASTBuilder::visitForeachHead(SpiceParser::ForeachHeadContext *ctx) {
363 124 const auto foreachLoopNode = resumeForExpansion<ForeachLoopNode>();
364
365 // Visit children
366
3/4
✓ Branch 12 → 13 taken 124 times.
✗ Branch 12 → 42 not taken.
✓ Branch 15 → 16 taken 118 times.
✓ Branch 15 → 21 taken 6 times.
124 if (ctx->declStmt().size() == 1) {
367
3/6
✓ Branch 16 → 17 taken 118 times.
✗ Branch 16 → 45 not taken.
✓ Branch 17 → 18 taken 118 times.
✗ Branch 17 → 45 not taken.
✓ Branch 18 → 19 taken 118 times.
✗ Branch 18 → 43 not taken.
118 foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0)));
368
2/4
✓ Branch 21 → 22 taken 6 times.
✗ Branch 21 → 46 not taken.
✓ Branch 24 → 25 taken 6 times.
✗ Branch 24 → 34 not taken.
6 } else if (ctx->declStmt().size() == 2) {
369
3/6
✓ Branch 25 → 26 taken 6 times.
✗ Branch 25 → 49 not taken.
✓ Branch 26 → 27 taken 6 times.
✗ Branch 26 → 49 not taken.
✓ Branch 27 → 28 taken 6 times.
✗ Branch 27 → 47 not taken.
6 foreachLoopNode->idxVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0)));
370
3/6
✓ Branch 29 → 30 taken 6 times.
✗ Branch 29 → 52 not taken.
✓ Branch 30 → 31 taken 6 times.
✗ Branch 30 → 52 not taken.
✓ Branch 31 → 32 taken 6 times.
✗ Branch 31 → 50 not taken.
6 foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(1)));
371 } else {
372 assert_fail("Invalid number of decl statements in foreach loop"); // GCOV_EXCL_LINE
373 }
374
3/6
✓ Branch 35 → 36 taken 124 times.
✗ Branch 35 → 55 not taken.
✓ Branch 36 → 37 taken 124 times.
✗ Branch 36 → 55 not taken.
✓ Branch 37 → 38 taken 124 times.
✗ Branch 37 → 53 not taken.
124 foreachLoopNode->iteratorAssign = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
375
376
1/2
✓ Branch 39 → 40 taken 124 times.
✗ Branch 39 → 56 not taken.
124 return nullptr;
377 }
378
379 786 std::any ASTBuilder::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) {
380 786 const auto whileLoopNode = createNode<WhileLoopNode>(ctx);
381
382 // Visit children
383
3/6
✓ Branch 3 → 4 taken 786 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 786 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 786 times.
✗ Branch 5 → 21 not taken.
786 whileLoopNode->condition = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
384
3/6
✓ Branch 7 → 8 taken 786 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 786 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 786 times.
✗ Branch 9 → 24 not taken.
786 whileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
385
386
1/2
✓ Branch 17 → 18 taken 786 times.
✗ Branch 17 → 27 not taken.
786 return concludeNode(whileLoopNode);
387 }
388
389 9 std::any ASTBuilder::visitDoWhileLoop(SpiceParser::DoWhileLoopContext *ctx) {
390 9 const auto doWhileLoopNode = createNode<DoWhileLoopNode>(ctx);
391
392 // Visit children
393
3/6
✓ Branch 3 → 4 taken 9 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 9 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 9 times.
✗ Branch 5 → 21 not taken.
9 doWhileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
394
3/6
✓ Branch 7 → 8 taken 9 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 9 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 9 times.
✗ Branch 9 → 24 not taken.
9 doWhileLoopNode->condition = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
395
396
1/2
✓ Branch 17 → 18 taken 9 times.
✗ Branch 17 → 27 not taken.
9 return concludeNode(doWhileLoopNode);
397 }
398
399 4263 std::any ASTBuilder::visitIfStmt(SpiceParser::IfStmtContext *ctx) {
400 4263 const auto ifStmtNode = createNode<IfStmtNode>(ctx);
401
402 // Visit children
403
3/6
✓ Branch 3 → 4 taken 4263 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 4263 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 4263 times.
✗ Branch 5 → 28 not taken.
4263 ifStmtNode->condition = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
404
3/6
✓ Branch 7 → 8 taken 4263 times.
✗ Branch 7 → 33 not taken.
✓ Branch 8 → 9 taken 4263 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 4263 times.
✗ Branch 9 → 31 not taken.
4263 ifStmtNode->thenBody = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
405
2/2
✓ Branch 12 → 13 taken 249 times.
✓ Branch 12 → 18 taken 4014 times.
4263 if (ctx->elseStmt())
406
3/6
✓ Branch 13 → 14 taken 249 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 249 times.
✗ Branch 14 → 36 not taken.
✓ Branch 15 → 16 taken 249 times.
✗ Branch 15 → 34 not taken.
249 ifStmtNode->elseStmt = std::any_cast<ElseStmtNode *>(visit(ctx->elseStmt()));
407
408
1/2
✓ Branch 24 → 25 taken 4263 times.
✗ Branch 24 → 37 not taken.
4263 return concludeNode(ifStmtNode);
409 }
410
411 249 std::any ASTBuilder::visitElseStmt(SpiceParser::ElseStmtContext *ctx) {
412 249 const auto elseStmtNode = createNode<ElseStmtNode>(ctx);
413
414 // Visit children
415
2/2
✓ Branch 4 → 5 taken 73 times.
✓ Branch 4 → 10 taken 176 times.
249 if (ctx->ifStmt()) {
416 73 elseStmtNode->isElseIf = true;
417
3/6
✓ Branch 5 → 6 taken 73 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 73 times.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 73 times.
✗ Branch 7 → 25 not taken.
73 elseStmtNode->ifStmt = std::any_cast<IfStmtNode *>(visit(ctx->ifStmt()));
418 } else {
419
3/6
✓ Branch 10 → 11 taken 176 times.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 176 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 176 times.
✗ Branch 12 → 28 not taken.
176 elseStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
420 }
421
422
1/2
✓ Branch 21 → 22 taken 249 times.
✗ Branch 21 → 31 not taken.
249 return concludeNode(elseStmtNode);
423 }
424
425 12 std::any ASTBuilder::visitSwitchStmt(SpiceParser::SwitchStmtContext *ctx) {
426 12 const auto switchStmtNode = createNode<SwitchStmtNode>(ctx);
427
428 // Visit children
429
3/6
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 29 not taken.
✓ Branch 5 → 6 taken 12 times.
✗ Branch 5 → 27 not taken.
12 switchStmtNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
430
2/4
✓ Branch 7 → 8 taken 12 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 12 times.
✗ Branch 8 → 30 not taken.
12 fetchChildrenIntoVector(switchStmtNode->caseBranches, ctx->caseBranch());
431
2/2
✓ Branch 11 → 12 taken 6 times.
✓ Branch 11 → 17 taken 6 times.
12 if (ctx->defaultBranch()) {
432 6 switchStmtNode->hasDefaultBranch = true;
433
3/6
✓ Branch 12 → 13 taken 6 times.
✗ Branch 12 → 35 not taken.
✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 35 not taken.
✓ Branch 14 → 15 taken 6 times.
✗ Branch 14 → 33 not taken.
6 switchStmtNode->defaultBranch = std::any_cast<DefaultBranchNode *>(visit(ctx->defaultBranch()));
434 }
435
436
1/2
✓ Branch 23 → 24 taken 12 times.
✗ Branch 23 → 36 not taken.
12 return concludeNode(switchStmtNode);
437 }
438
439 53 std::any ASTBuilder::visitCaseBranch(SpiceParser::CaseBranchContext *ctx) {
440 53 const auto caseBranchNode = createNode<CaseBranchNode>(ctx);
441
442 // Visit children
443
2/4
✓ Branch 3 → 4 taken 53 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 53 times.
✗ Branch 4 → 20 not taken.
53 fetchChildrenIntoVector(caseBranchNode->caseConstants, ctx->caseConstant());
444
3/6
✓ Branch 6 → 7 taken 53 times.
✗ Branch 6 → 25 not taken.
✓ Branch 7 → 8 taken 53 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 53 times.
✗ Branch 8 → 23 not taken.
53 caseBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
445
446
1/2
✓ Branch 16 → 17 taken 53 times.
✗ Branch 16 → 26 not taken.
53 return concludeNode(caseBranchNode);
447 }
448
449 6 std::any ASTBuilder::visitDefaultBranch(SpiceParser::DefaultBranchContext *ctx) {
450 6 const auto defaultBranchNode = createNode<DefaultBranchNode>(ctx);
451
452 // Visit children
453
3/6
✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 6 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 6 times.
✗ Branch 5 → 17 not taken.
6 defaultBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
454
455
1/2
✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 20 not taken.
6 return concludeNode(defaultBranchNode);
456 }
457
458 30 std::any ASTBuilder::visitAnonymousBlockStmt(SpiceParser::AnonymousBlockStmtContext *ctx) {
459 30 const auto anonymousBlockStmtNode = createNode<AnonymousBlockStmtNode>(ctx);
460
461 // Visit children
462
3/6
✓ Branch 3 → 4 taken 30 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 30 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 30 times.
✗ Branch 5 → 17 not taken.
30 anonymousBlockStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
463
464
1/2
✓ Branch 13 → 14 taken 30 times.
✗ Branch 13 → 20 not taken.
30 return concludeNode(anonymousBlockStmtNode);
465 }
466
467 21874 std::any ASTBuilder::visitStmtLst(SpiceParser::StmtLstContext *ctx) {
468 21874 const auto stmtLstNode = createNode<StmtLstNode>(ctx);
469
470 // Enrich
471
2/4
✓ Branch 3 → 4 taken 21874 times.
✗ Branch 3 → 116 not taken.
✓ Branch 4 → 5 taken 21874 times.
✗ Branch 4 → 116 not taken.
21874 stmtLstNode->closingBraceCodeLoc = CodeLoc(ctx->getStop(), sourceFile);
472
473 // Visit children
474
2/2
✓ Branch 105 → 7 taken 83348 times.
✓ Branch 105 → 106 taken 21870 times.
105218 for (ParserRuleContext::ParseTree *stmt : ctx->children) {
475
3/4
✓ Branch 8 → 9 taken 83348 times.
✗ Branch 8 → 10 not taken.
✓ Branch 11 → 12 taken 29767 times.
✓ Branch 11 → 17 taken 53581 times.
83348 if (auto *stmtCtx = dynamic_cast<SpiceParser::StmtContext *>(stmt))
476
4/6
✓ Branch 12 → 13 taken 29763 times.
✓ Branch 12 → 119 taken 4 times.
✓ Branch 13 → 14 taken 29763 times.
✗ Branch 13 → 117 not taken.
✓ Branch 14 → 15 taken 29763 times.
✗ Branch 14 → 117 not taken.
29767 stmtLstNode->statements.push_back(std::any_cast<StmtNode *>(visit(stmtCtx)));
477
3/4
✓ Branch 17 → 18 taken 53581 times.
✗ Branch 17 → 19 not taken.
✓ Branch 20 → 21 taken 1385 times.
✓ Branch 20 → 26 taken 52196 times.
53581 else if (auto *forLoopCtx = dynamic_cast<SpiceParser::ForLoopContext *>(stmt))
478
3/6
✓ Branch 21 → 22 taken 1385 times.
✗ Branch 21 → 123 not taken.
✓ Branch 22 → 23 taken 1385 times.
✗ Branch 22 → 121 not taken.
✓ Branch 23 → 24 taken 1385 times.
✗ Branch 23 → 121 not taken.
1385 stmtLstNode->statements.push_back(std::any_cast<ForLoopNode *>(visit(forLoopCtx)));
479
3/4
✓ Branch 26 → 27 taken 52196 times.
✗ Branch 26 → 28 not taken.
✓ Branch 29 → 30 taken 124 times.
✓ Branch 29 → 35 taken 52072 times.
52196 else if (auto *foreachLoopCtx = dynamic_cast<SpiceParser::ForeachLoopContext *>(stmt))
480
3/6
✓ Branch 30 → 31 taken 124 times.
✗ Branch 30 → 127 not taken.
✓ Branch 31 → 32 taken 124 times.
✗ Branch 31 → 125 not taken.
✓ Branch 32 → 33 taken 124 times.
✗ Branch 32 → 125 not taken.
124 stmtLstNode->statements.push_back(std::any_cast<ForeachLoopNode *>(visit(foreachLoopCtx)));
481
3/4
✓ Branch 35 → 36 taken 52072 times.
✗ Branch 35 → 37 not taken.
✓ Branch 38 → 39 taken 786 times.
✓ Branch 38 → 44 taken 51286 times.
52072 else if (auto *whileLoopCtx = dynamic_cast<SpiceParser::WhileLoopContext *>(stmt))
482
3/6
✓ Branch 39 → 40 taken 786 times.
✗ Branch 39 → 131 not taken.
✓ Branch 40 → 41 taken 786 times.
✗ Branch 40 → 129 not taken.
✓ Branch 41 → 42 taken 786 times.
✗ Branch 41 → 129 not taken.
786 stmtLstNode->statements.push_back(std::any_cast<WhileLoopNode *>(visit(whileLoopCtx)));
483
3/4
✓ Branch 44 → 45 taken 51286 times.
✗ Branch 44 → 46 not taken.
✓ Branch 47 → 48 taken 9 times.
✓ Branch 47 → 53 taken 51277 times.
51286 else if (auto *doWhileLoopCtx = dynamic_cast<SpiceParser::DoWhileLoopContext *>(stmt))
484
3/6
✓ Branch 48 → 49 taken 9 times.
✗ Branch 48 → 135 not taken.
✓ Branch 49 → 50 taken 9 times.
✗ Branch 49 → 133 not taken.
✓ Branch 50 → 51 taken 9 times.
✗ Branch 50 → 133 not taken.
9 stmtLstNode->statements.push_back(std::any_cast<DoWhileLoopNode *>(visit(doWhileLoopCtx)));
485
3/4
✓ Branch 53 → 54 taken 51277 times.
✗ Branch 53 → 55 not taken.
✓ Branch 56 → 57 taken 4190 times.
✓ Branch 56 → 62 taken 47087 times.
51277 else if (auto *ifStmtCtx = dynamic_cast<SpiceParser::IfStmtContext *>(stmt))
486
3/6
✓ Branch 57 → 58 taken 4190 times.
✗ Branch 57 → 139 not taken.
✓ Branch 58 → 59 taken 4190 times.
✗ Branch 58 → 137 not taken.
✓ Branch 59 → 60 taken 4190 times.
✗ Branch 59 → 137 not taken.
4190 stmtLstNode->statements.push_back(std::any_cast<IfStmtNode *>(visit(ifStmtCtx)));
487
3/4
✓ Branch 62 → 63 taken 47087 times.
✗ Branch 62 → 64 not taken.
✓ Branch 65 → 66 taken 12 times.
✓ Branch 65 → 71 taken 47075 times.
47087 else if (auto *switchStmtCtx = dynamic_cast<SpiceParser::SwitchStmtContext *>(stmt))
488
3/6
✓ Branch 66 → 67 taken 12 times.
✗ Branch 66 → 143 not taken.
✓ Branch 67 → 68 taken 12 times.
✗ Branch 67 → 141 not taken.
✓ Branch 68 → 69 taken 12 times.
✗ Branch 68 → 141 not taken.
12 stmtLstNode->statements.push_back(std::any_cast<SwitchStmtNode *>(visit(switchStmtCtx)));
489
3/4
✓ Branch 71 → 72 taken 47075 times.
✗ Branch 71 → 73 not taken.
✓ Branch 74 → 75 taken 716 times.
✓ Branch 74 → 80 taken 46359 times.
47075 else if (auto *assetStmtCtx = dynamic_cast<SpiceParser::AssertStmtContext *>(stmt))
490
3/6
✓ Branch 75 → 76 taken 716 times.
✗ Branch 75 → 147 not taken.
✓ Branch 76 → 77 taken 716 times.
✗ Branch 76 → 145 not taken.
✓ Branch 77 → 78 taken 716 times.
✗ Branch 77 → 145 not taken.
716 stmtLstNode->statements.push_back(std::any_cast<AssertStmtNode *>(visit(assetStmtCtx)));
491
3/4
✓ Branch 80 → 81 taken 46359 times.
✗ Branch 80 → 82 not taken.
✓ Branch 83 → 84 taken 2585 times.
✓ Branch 83 → 89 taken 43774 times.
46359 else if (auto *unsafeBlockCtx = dynamic_cast<SpiceParser::UnsafeBlockContext *>(stmt))
492
3/6
✓ Branch 84 → 85 taken 2585 times.
✗ Branch 84 → 151 not taken.
✓ Branch 85 → 86 taken 2585 times.
✗ Branch 85 → 149 not taken.
✓ Branch 86 → 87 taken 2585 times.
✗ Branch 86 → 149 not taken.
2585 stmtLstNode->statements.push_back(std::any_cast<UnsafeBlockNode *>(visit(unsafeBlockCtx)));
493
3/4
✓ Branch 89 → 90 taken 43774 times.
✗ Branch 89 → 91 not taken.
✓ Branch 92 → 93 taken 30 times.
✓ Branch 92 → 98 taken 43744 times.
43774 else if (auto *anonymousScopeCtx = dynamic_cast<SpiceParser::AnonymousBlockStmtContext *>(stmt))
494
3/6
✓ Branch 93 → 94 taken 30 times.
✗ Branch 93 → 155 not taken.
✓ Branch 94 → 95 taken 30 times.
✗ Branch 94 → 153 not taken.
✓ Branch 95 → 96 taken 30 times.
✗ Branch 95 → 153 not taken.
30 stmtLstNode->statements.push_back(std::any_cast<AnonymousBlockStmtNode *>(visit(anonymousScopeCtx)));
495 else
496 assert(dynamic_cast<TerminalNode *>(stmt) != nullptr); // GCOV_EXCL_LINE
497 }
498
499
1/2
✓ Branch 112 → 113 taken 21870 times.
✗ Branch 112 → 158 not taken.
21870 return concludeNode(stmtLstNode);
500 }
501
502 7119 std::any ASTBuilder::visitTypeLst(SpiceParser::TypeLstContext *ctx) {
503 7119 const auto typeLstNode = createNode<TypeLstNode>(ctx);
504
505 // Visit children
506
2/4
✓ Branch 3 → 4 taken 7119 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 7119 times.
✗ Branch 4 → 16 not taken.
7119 fetchChildrenIntoVector(typeLstNode->dataTypes, ctx->dataType());
507
508
1/2
✓ Branch 12 → 13 taken 7119 times.
✗ Branch 12 → 19 not taken.
7119 return concludeNode(typeLstNode);
509 }
510
511 978 std::any ASTBuilder::visitTypeLstWithEllipsis(SpiceParser::TypeLstWithEllipsisContext *ctx) {
512 978 const auto typeLstWithEllipsisNode = createNode<TypeLstWithEllipsisNode>(ctx);
513
514 // Visit children
515
3/6
✓ Branch 3 → 4 taken 978 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 978 times.
✗ Branch 4 → 20 not taken.
✓ Branch 5 → 6 taken 978 times.
✗ Branch 5 → 18 not taken.
978 typeLstWithEllipsisNode->typeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
516
517 // Set some flags
518 978 typeLstWithEllipsisNode->hasEllipsis = ctx->ELLIPSIS() != nullptr;
519
520
1/2
✓ Branch 14 → 15 taken 978 times.
✗ Branch 14 → 21 not taken.
978 return concludeNode(typeLstWithEllipsisNode);
521 }
522
523 957 std::any ASTBuilder::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ctx) {
524 957 const auto typeAltsLstNode = createNode<TypeAltsLstNode>(ctx);
525
526 // Visit children
527
2/4
✓ Branch 3 → 4 taken 957 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 957 times.
✗ Branch 4 → 16 not taken.
957 fetchChildrenIntoVector(typeAltsLstNode->dataTypes, ctx->dataType());
528
529
1/2
✓ Branch 12 → 13 taken 957 times.
✗ Branch 12 → 19 not taken.
957 return concludeNode(typeAltsLstNode);
530 }
531
532 9142 std::any ASTBuilder::visitParamLst(SpiceParser::ParamLstContext *ctx) {
533 9142 const auto paramLstNode = createNode<ParamLstNode>(ctx);
534
535 // Visit children
536
2/4
✓ Branch 3 → 4 taken 9142 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 9142 times.
✗ Branch 4 → 22 not taken.
9142 fetchChildrenIntoVector(paramLstNode->params, ctx->declStmt());
537
538 // Set some flags to later detect that the decl statements are parameters
539
2/2
✓ Branch 11 → 8 taken 13772 times.
✓ Branch 11 → 12 taken 9142 times.
22914 for (DeclStmtNode *declStmt : paramLstNode->params) {
540 13772 declStmt->isFctParam = true;
541 13772 declStmt->dataType->isParamType = true;
542 }
543
544
1/2
✓ Branch 18 → 19 taken 9142 times.
✗ Branch 18 → 25 not taken.
9142 return concludeNode(paramLstNode);
545 }
546
547 12808 std::any ASTBuilder::visitArgLst(SpiceParser::ArgLstContext *ctx) {
548 12808 const auto argLstNode = createNode<ArgLstNode>(ctx);
549
550 // Visit children
551
2/4
✓ Branch 3 → 4 taken 12808 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 12808 times.
✗ Branch 4 → 18 not taken.
12808 fetchChildrenIntoVector(argLstNode->args, ctx->assignExpr());
552 12808 argLstNode->argInfos.reserve(argLstNode->args.size());
553
554
1/2
✓ Branch 14 → 15 taken 12808 times.
✗ Branch 14 → 21 not taken.
12808 return concludeNode(argLstNode);
555 }
556
557 68 std::any ASTBuilder::visitEnumItemLst(SpiceParser::EnumItemLstContext *ctx) {
558 68 const auto enumItemLstNode = createNode<EnumItemLstNode>(ctx);
559
560 // Visit children
561
2/4
✓ Branch 3 → 4 taken 68 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 68 times.
✗ Branch 4 → 16 not taken.
68 fetchChildrenIntoVector(enumItemLstNode->items, ctx->enumItem());
562
563
1/2
✓ Branch 12 → 13 taken 68 times.
✗ Branch 12 → 19 not taken.
68 return concludeNode(enumItemLstNode);
564 }
565
566 746 std::any ASTBuilder::visitEnumItem(SpiceParser::EnumItemContext *ctx) {
567 746 const auto enumItemNode = createNode<EnumItemNode>(ctx);
568
569 // Enrich
570
2/4
✓ Branch 3 → 4 taken 746 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 746 times.
✗ Branch 4 → 22 not taken.
746 enumItemNode->itemName = getIdentifier(ctx->TYPE_IDENTIFIER(), false);
571
2/2
✓ Branch 8 → 9 taken 409 times.
✓ Branch 8 → 12 taken 337 times.
746 if (ctx->ASSIGN()) {
572 409 enumItemNode->itemValue = parseInt(ctx->INT_LIT());
573 409 enumItemNode->hasValue = true;
574 }
575
576
1/2
✓ Branch 18 → 19 taken 746 times.
✗ Branch 18 → 23 not taken.
746 return concludeNode(enumItemNode);
577 }
578
579 1533 std::any ASTBuilder::visitField(SpiceParser::FieldContext *ctx) {
580 1533 const auto fieldNode = createNode<FieldNode>(ctx);
581
582 // Enrich
583
2/4
✓ Branch 3 → 4 taken 1533 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 1533 times.
✗ Branch 4 → 29 not taken.
1533 fieldNode->fieldName = getIdentifier(ctx->IDENTIFIER(), false);
584
585 // Visit children
586
3/6
✓ Branch 7 → 8 taken 1533 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 1533 times.
✗ Branch 8 → 32 not taken.
✓ Branch 9 → 10 taken 1533 times.
✗ Branch 9 → 30 not taken.
1533 fieldNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
587 1533 fieldNode->dataType->setFieldTypeRecursive();
588
2/2
✓ Branch 13 → 14 taken 225 times.
✓ Branch 13 → 19 taken 1308 times.
1533 if (ctx->ternaryExpr())
589
3/6
✓ Branch 14 → 15 taken 225 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 225 times.
✗ Branch 15 → 35 not taken.
✓ Branch 16 → 17 taken 225 times.
✗ Branch 16 → 33 not taken.
225 fieldNode->defaultValue = std::any_cast<TernaryExprNode *>(visit(ctx->ternaryExpr()));
590
591
1/2
✓ Branch 25 → 26 taken 1533 times.
✗ Branch 25 → 36 not taken.
1533 return concludeNode(fieldNode);
592 }
593
594 236 std::any ASTBuilder::visitSignature(SpiceParser::SignatureContext *ctx) {
595 236 const auto signatureNode = createNode<SignatureNode>(ctx);
596
597 // Extract method name
598
2/4
✓ Branch 3 → 4 taken 236 times.
✗ Branch 3 → 73 not taken.
✓ Branch 4 → 5 taken 236 times.
✗ Branch 4 → 73 not taken.
236 signatureNode->methodName = getIdentifier(ctx->IDENTIFIER(), false);
599
600 // Visit children
601
2/2
✓ Branch 8 → 9 taken 14 times.
✓ Branch 8 → 14 taken 222 times.
236 if (ctx->qualifierLst()) {
602
3/6
✓ Branch 9 → 10 taken 14 times.
✗ Branch 9 → 76 not taken.
✓ Branch 10 → 11 taken 14 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 14 times.
✗ Branch 11 → 74 not taken.
14 signatureNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
603 }
604
2/2
✓ Branch 15 → 16 taken 185 times.
✓ Branch 15 → 22 taken 51 times.
236 if (ctx->F()) {
605 185 signatureNode->hasReturnType = true;
606 185 signatureNode->signatureType = SignatureNode::SignatureType::TYPE_FUNCTION;
607 185 signatureNode->signatureQualifiers = TypeQualifiers::of(TY_FUNCTION);
608
3/6
✓ Branch 17 → 18 taken 185 times.
✗ Branch 17 → 79 not taken.
✓ Branch 18 → 19 taken 185 times.
✗ Branch 18 → 79 not taken.
✓ Branch 19 → 20 taken 185 times.
✗ Branch 19 → 77 not taken.
185 signatureNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
609 } else {
610 51 signatureNode->signatureType = SignatureNode::SignatureType::TYPE_PROCEDURE;
611 51 signatureNode->signatureQualifiers = TypeQualifiers::of(TY_PROCEDURE);
612 }
613
10/16
✓ Branch 24 → 25 taken 185 times.
✓ Branch 24 → 28 taken 51 times.
✓ Branch 25 → 26 taken 185 times.
✗ Branch 25 → 80 not taken.
✓ Branch 28 → 29 taken 51 times.
✗ Branch 28 → 80 not taken.
✓ Branch 31 → 32 taken 51 times.
✓ Branch 31 → 33 taken 185 times.
✓ Branch 33 → 34 taken 185 times.
✓ Branch 33 → 35 taken 51 times.
✓ Branch 35 → 36 taken 120 times.
✓ Branch 35 → 41 taken 116 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
236 if (ctx->F() ? ctx->LESS().size() == 2 : ctx->LESS().size() == 1) {
614 120 signatureNode->hasTemplateTypes = true;
615
3/6
✓ Branch 36 → 37 taken 120 times.
✗ Branch 36 → 90 not taken.
✓ Branch 37 → 38 taken 120 times.
✗ Branch 37 → 90 not taken.
✓ Branch 38 → 39 taken 120 times.
✗ Branch 38 → 88 not taken.
120 signatureNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0)));
616 }
617
13/20
✓ Branch 41 → 42 taken 236 times.
✗ Branch 41 → 91 not taken.
✓ Branch 43 → 44 taken 234 times.
✓ Branch 43 → 48 taken 2 times.
✓ Branch 44 → 45 taken 234 times.
✗ Branch 44 → 91 not taken.
✓ Branch 46 → 47 taken 125 times.
✓ Branch 46 → 49 taken 109 times.
✓ Branch 47 → 48 taken 7 times.
✓ Branch 47 → 49 taken 118 times.
✓ Branch 50 → 51 taken 234 times.
✓ Branch 50 → 52 taken 2 times.
✓ Branch 52 → 53 taken 236 times.
✗ Branch 52 → 54 not taken.
✓ Branch 54 → 55 taken 9 times.
✓ Branch 54 → 63 taken 227 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
236 if (ctx->typeLst().size() == 2 || (ctx->typeLst().size() == 1 && !signatureNode->hasTemplateTypes)) {
618 9 signatureNode->hasParams = true;
619
5/8
✓ Branch 55 → 56 taken 2 times.
✓ Branch 55 → 57 taken 7 times.
✓ Branch 58 → 59 taken 9 times.
✗ Branch 58 → 101 not taken.
✓ Branch 59 → 60 taken 9 times.
✗ Branch 59 → 101 not taken.
✓ Branch 60 → 61 taken 9 times.
✗ Branch 60 → 99 not taken.
9 signatureNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(signatureNode->hasTemplateTypes ? 1 : 0)));
620 }
621
622
1/2
✓ Branch 69 → 70 taken 236 times.
✗ Branch 69 → 102 not taken.
236 return concludeNode(signatureNode);
623 }
624
625 29767 std::any ASTBuilder::visitStmt(SpiceParser::StmtContext *ctx) {
626
2/2
✓ Branch 3 → 4 taken 5326 times.
✓ Branch 3 → 11 taken 24441 times.
29767 if (ctx->declStmt())
627
5/8
✓ Branch 4 → 5 taken 5326 times.
✗ Branch 4 → 60 not taken.
✓ Branch 5 → 6 taken 5322 times.
✓ Branch 5 → 60 taken 4 times.
✓ Branch 6 → 7 taken 5322 times.
✗ Branch 6 → 58 not taken.
✓ Branch 7 → 8 taken 5322 times.
✗ Branch 7 → 58 not taken.
5326 return static_cast<StmtNode *>(std::any_cast<DeclStmtNode *>(visit(ctx->declStmt())));
628
2/2
✓ Branch 12 → 13 taken 14480 times.
✓ Branch 12 → 20 taken 9961 times.
24441 if (ctx->exprStmt())
629
4/8
✓ Branch 13 → 14 taken 14480 times.
✗ Branch 13 → 64 not taken.
✓ Branch 14 → 15 taken 14480 times.
✗ Branch 14 → 64 not taken.
✓ Branch 15 → 16 taken 14480 times.
✗ Branch 15 → 62 not taken.
✓ Branch 16 → 17 taken 14480 times.
✗ Branch 16 → 62 not taken.
14480 return static_cast<StmtNode *>(std::any_cast<ExprStmtNode *>(visit(ctx->exprStmt())));
630
2/2
✓ Branch 21 → 22 taken 9637 times.
✓ Branch 21 → 29 taken 324 times.
9961 if (ctx->returnStmt())
631
4/8
✓ Branch 22 → 23 taken 9637 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 9637 times.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 9637 times.
✗ Branch 24 → 66 not taken.
✓ Branch 25 → 26 taken 9637 times.
✗ Branch 25 → 66 not taken.
9637 return static_cast<StmtNode *>(std::any_cast<ReturnStmtNode *>(visit(ctx->returnStmt())));
632
2/2
✓ Branch 30 → 31 taken 119 times.
✓ Branch 30 → 38 taken 205 times.
324 if (ctx->breakStmt())
633
4/8
✓ Branch 31 → 32 taken 119 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 119 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 119 times.
✗ Branch 33 → 70 not taken.
✓ Branch 34 → 35 taken 119 times.
✗ Branch 34 → 70 not taken.
119 return static_cast<StmtNode *>(std::any_cast<BreakStmtNode *>(visit(ctx->breakStmt())));
634
2/2
✓ Branch 39 → 40 taken 199 times.
✓ Branch 39 → 47 taken 6 times.
205 if (ctx->continueStmt())
635
4/8
✓ Branch 40 → 41 taken 199 times.
✗ Branch 40 → 76 not taken.
✓ Branch 41 → 42 taken 199 times.
✗ Branch 41 → 76 not taken.
✓ Branch 42 → 43 taken 199 times.
✗ Branch 42 → 74 not taken.
✓ Branch 43 → 44 taken 199 times.
✗ Branch 43 → 74 not taken.
199 return static_cast<StmtNode *>(std::any_cast<ContinueStmtNode *>(visit(ctx->continueStmt())));
636
1/2
✓ Branch 48 → 49 taken 6 times.
✗ Branch 48 → 56 not taken.
6 if (ctx->fallthroughStmt())
637
4/8
✓ Branch 49 → 50 taken 6 times.
✗ Branch 49 → 80 not taken.
✓ Branch 50 → 51 taken 6 times.
✗ Branch 50 → 80 not taken.
✓ Branch 51 → 52 taken 6 times.
✗ Branch 51 → 78 not taken.
✓ Branch 52 → 53 taken 6 times.
✗ Branch 52 → 78 not taken.
6 return static_cast<StmtNode *>(std::any_cast<FallthroughStmtNode *>(visit(ctx->fallthroughStmt())));
638 assert_fail("Unknown statement type"); // GCOV_EXCL_LINE
639 return nullptr; // GCOV_EXCL_LINE
640 }
641
642 20613 std::any ASTBuilder::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) {
643 20613 const auto declStmtNode = createNode<DeclStmtNode>(ctx);
644
645 // Enrich
646
3/4
✓ Branch 3 → 4 taken 20613 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 20612 times.
✓ Branch 4 → 28 taken 1 time.
20613 declStmtNode->varName = getIdentifier(ctx->IDENTIFIER(), false);
647
648 // Visit children
649
4/6
✓ Branch 7 → 8 taken 20612 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 20611 times.
✓ Branch 8 → 31 taken 1 time.
✓ Branch 9 → 10 taken 20611 times.
✗ Branch 9 → 29 not taken.
20612 declStmtNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
650
2/2
✓ Branch 12 → 13 taken 7382 times.
✓ Branch 12 → 18 taken 13229 times.
20611 if (ctx->assignExpr()) {
651 7382 declStmtNode->hasAssignment = true;
652
4/6
✓ Branch 13 → 14 taken 7382 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 7380 times.
✓ Branch 14 → 34 taken 2 times.
✓ Branch 15 → 16 taken 7380 times.
✗ Branch 15 → 32 not taken.
7382 declStmtNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
653 }
654
655
1/2
✓ Branch 24 → 25 taken 20609 times.
✗ Branch 24 → 35 not taken.
20609 return concludeNode(declStmtNode);
656 }
657
658 14480 std::any ASTBuilder::visitExprStmt(SpiceParser::ExprStmtContext *ctx) {
659 14480 const auto exprStmtNode = createNode<ExprStmtNode>(ctx);
660
661 // Enrich
662
3/6
✓ Branch 3 → 4 taken 14480 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 14480 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 14480 times.
✗ Branch 5 → 17 not taken.
14480 exprStmtNode->expr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
663
664
1/2
✓ Branch 13 → 14 taken 14480 times.
✗ Branch 13 → 20 not taken.
14480 return concludeNode(exprStmtNode);
665 }
666
667 31309 std::any ASTBuilder::visitQualifierLst(SpiceParser::QualifierLstContext *ctx) {
668 31309 const auto qualifierLstNode = createNode<QualifierLstNode>(ctx);
669
670 // Visit children
671
2/4
✓ Branch 3 → 4 taken 31309 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 31309 times.
✗ Branch 4 → 35 not taken.
31309 fetchChildrenIntoVector(qualifierLstNode->qualifiers, ctx->qualifier());
672
673 // Check if qualifier combination is invalid
674 31309 bool seenSignedOrUnsigned = false;
675
2/2
✓ Branch 24 → 8 taken 37678 times.
✓ Branch 24 → 25 taken 31308 times.
68986 for (const QualifierNode *qualifier : qualifierLstNode->qualifiers) {
676 // Check if we have both, signed and unsigned qualifier
677
2/2
✓ Branch 9 → 10 taken 37671 times.
✓ Branch 9 → 12 taken 7 times.
37678 if (qualifier->type != QualifierNode::QualifierType::TY_SIGNED &&
678
2/2
✓ Branch 10 → 11 taken 28310 times.
✓ Branch 10 → 12 taken 9361 times.
37671 qualifier->type != QualifierNode::QualifierType::TY_UNSIGNED)
679 28310 continue;
680
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 21 taken 9367 times.
9368 if (seenSignedOrUnsigned)
681
2/4
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 41 not taken.
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 38 not taken.
3 throw ParserError(qualifier->codeLoc, INVALID_QUALIFIER_COMBINATION, "A variable can not be signed and unsigned");
682 9367 seenSignedOrUnsigned = true;
683 }
684
685
1/2
✓ Branch 31 → 32 taken 31308 times.
✗ Branch 31 → 48 not taken.
31308 return concludeNode(qualifierLstNode);
686 }
687
688 37678 std::any ASTBuilder::visitQualifier(SpiceParser::QualifierContext *ctx) {
689 37678 const auto qualifierNode = createNode<QualifierNode>(ctx);
690
691
3/4
✓ Branch 6 → 7 taken 37678 times.
✗ Branch 6 → 8 not taken.
✓ Branch 32 → 5 taken 37678 times.
✓ Branch 32 → 33 taken 37678 times.
75356 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
692 37678 const auto token = spice_pointer_cast<TerminalNode *>(subTree);
693
2/4
✓ Branch 13 → 14 taken 37678 times.
✗ Branch 13 → 43 not taken.
✓ Branch 14 → 15 taken 37678 times.
✗ Branch 14 → 43 not taken.
37678 const size_t symbolType = token->getSymbol()->getType();
694
2/2
✓ Branch 15 → 16 taken 7798 times.
✓ Branch 15 → 17 taken 29880 times.
37678 if (symbolType == SpiceParser::CONST)
695 7798 qualifierNode->type = QualifierNode::QualifierType::TY_CONST;
696
2/2
✓ Branch 17 → 18 taken 7 times.
✓ Branch 17 → 19 taken 29873 times.
29880 else if (symbolType == SpiceParser::SIGNED)
697 7 qualifierNode->type = QualifierNode::QualifierType::TY_SIGNED;
698
2/2
✓ Branch 19 → 20 taken 9361 times.
✓ Branch 19 → 21 taken 20512 times.
29873 else if (symbolType == SpiceParser::UNSIGNED)
699 9361 qualifierNode->type = QualifierNode::QualifierType::TY_UNSIGNED;
700
2/2
✓ Branch 21 → 22 taken 3275 times.
✓ Branch 21 → 23 taken 17237 times.
20512 else if (symbolType == SpiceParser::INLINE)
701 3275 qualifierNode->type = QualifierNode::QualifierType::TY_INLINE;
702
2/2
✓ Branch 23 → 24 taken 12915 times.
✓ Branch 23 → 25 taken 4322 times.
17237 else if (symbolType == SpiceParser::PUBLIC)
703 12915 qualifierNode->type = QualifierNode::QualifierType::TY_PUBLIC;
704
2/2
✓ Branch 25 → 26 taken 4315 times.
✓ Branch 25 → 27 taken 7 times.
4322 else if (symbolType == SpiceParser::HEAP)
705 4315 qualifierNode->type = QualifierNode::QualifierType::TY_HEAP;
706
1/2
✓ Branch 27 → 28 taken 7 times.
✗ Branch 27 → 29 not taken.
7 else if (symbolType == SpiceParser::COMPOSE)
707 7 qualifierNode->type = QualifierNode::QualifierType::TY_COMPOSITION;
708 else
709 assert_fail("Unknown qualifier type"); // GCOV_EXCL_LINE
710 }
711
712
1/2
✓ Branch 39 → 40 taken 37678 times.
✗ Branch 39 → 44 not taken.
37678 return concludeNode(qualifierNode);
713 }
714
715 356 std::any ASTBuilder::visitModAttr(SpiceParser::ModAttrContext *ctx) {
716 356 const auto modAttrNode = createNode<ModAttrNode>(ctx);
717
718 // Visit children
719
4/6
✓ Branch 3 → 4 taken 356 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 355 times.
✓ Branch 4 → 25 taken 1 time.
✓ Branch 5 → 6 taken 355 times.
✗ Branch 5 → 23 not taken.
356 modAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
720
721 // Tell the attributes that they are module attributes
722
2/2
✓ Branch 12 → 9 taken 625 times.
✓ Branch 12 → 13 taken 355 times.
980 for (AttrNode *attr : modAttrNode->attrLst->attributes)
723 625 attr->target = AttrNode::TARGET_MODULE;
724
725
1/2
✓ Branch 19 → 20 taken 355 times.
✗ Branch 19 → 26 not taken.
355 return concludeNode(modAttrNode);
726 }
727
728 461 std::any ASTBuilder::visitTopLevelDefAttr(SpiceParser::TopLevelDefAttrContext *ctx) {
729 461 const auto fctAttrNode = createNode<TopLevelDefinitionAttrNode>(ctx);
730
731 // Visit children
732
3/6
✓ Branch 3 → 4 taken 461 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 461 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 461 times.
✗ Branch 5 → 17 not taken.
461 fctAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
733
734
1/2
✓ Branch 13 → 14 taken 461 times.
✗ Branch 13 → 20 not taken.
461 return concludeNode(fctAttrNode);
735 }
736
737 16 std::any ASTBuilder::visitLambdaAttr(SpiceParser::LambdaAttrContext *ctx) {
738 16 const auto lambdaAttrNode = createNode<LambdaAttrNode>(ctx);
739
740 // Visit children
741
3/6
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 16 times.
✗ Branch 4 → 25 not taken.
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 23 not taken.
16 lambdaAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
742
743 // Tell the attributes that they are module attributes
744
2/2
✓ Branch 12 → 9 taken 16 times.
✓ Branch 12 → 13 taken 16 times.
32 for (AttrNode *attr : lambdaAttrNode->attrLst->attributes)
745 16 attr->target = AttrNode::TARGET_LAMBDA;
746
747
1/2
✓ Branch 19 → 20 taken 16 times.
✗ Branch 19 → 26 not taken.
16 return concludeNode(lambdaAttrNode);
748 }
749
750 833 std::any ASTBuilder::visitAttrLst(SpiceParser::AttrLstContext *ctx) {
751 833 const auto attrLstNode = createNode<AttrLstNode>(ctx);
752
753 // Visit children
754
3/4
✓ Branch 3 → 4 taken 833 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 832 times.
✓ Branch 4 → 16 taken 1 time.
834 fetchChildrenIntoVector(attrLstNode->attributes, ctx->attr());
755
756
1/2
✓ Branch 12 → 13 taken 832 times.
✗ Branch 12 → 19 not taken.
832 return concludeNode(attrLstNode);
757 }
758
759 1108 std::any ASTBuilder::visitAttr(SpiceParser::AttrContext *ctx) {
760 1108 const auto attrNode = createNode<AttrNode>(ctx);
761
762 // Extract key
763
3/4
✓ Branch 3 → 4 taken 1108 times.
✗ Branch 3 → 66 not taken.
✓ Branch 16 → 6 taken 2693 times.
✓ Branch 16 → 17 taken 1108 times.
3801 for (const TerminalNode *keyFragment : ctx->IDENTIFIER()) {
764
2/2
✓ Branch 8 → 9 taken 1585 times.
✓ Branch 8 → 10 taken 1108 times.
2693 if (!attrNode->key.empty())
765
1/2
✓ Branch 9 → 10 taken 1585 times.
✗ Branch 9 → 64 not taken.
1585 attrNode->key += MEMBER_ACCESS_TOKEN;
766
3/6
✓ Branch 10 → 11 taken 2693 times.
✗ Branch 10 → 63 not taken.
✓ Branch 11 → 12 taken 2693 times.
✗ Branch 11 → 63 not taken.
✓ Branch 12 → 13 taken 2693 times.
✗ Branch 12 → 61 not taken.
2693 attrNode->key += keyFragment->getSymbol()->getText();
767 1108 }
768
769 // Visit children
770
2/2
✓ Branch 19 → 20 taken 769 times.
✓ Branch 19 → 50 taken 339 times.
1108 if (ctx->constant()) {
771
3/6
✓ Branch 20 → 21 taken 769 times.
✗ Branch 20 → 69 not taken.
✓ Branch 21 → 22 taken 769 times.
✗ Branch 21 → 69 not taken.
✓ Branch 22 → 23 taken 769 times.
✗ Branch 22 → 67 not taken.
769 attrNode->value = std::any_cast<ConstantNode *>(visit(ctx->constant()));
772
773
2/2
✓ Branch 26 → 27 taken 280 times.
✓ Branch 26 → 28 taken 489 times.
769 if (ctx->constant()->STRING_LIT())
774 280 attrNode->type = AttrNode::AttrType::TYPE_STRING;
775
2/2
✓ Branch 30 → 31 taken 76 times.
✓ Branch 30 → 32 taken 413 times.
489 else if (ctx->constant()->INT_LIT())
776 76 attrNode->type = AttrNode::AttrType::TYPE_INT;
777
6/6
✓ Branch 34 → 35 taken 4 times.
✓ Branch 34 → 38 taken 409 times.
✓ Branch 37 → 38 taken 3 times.
✓ Branch 37 → 39 taken 1 time.
✓ Branch 40 → 41 taken 412 times.
✓ Branch 40 → 42 taken 1 time.
413 else if (ctx->constant()->TRUE() || ctx->constant()->FALSE())
778 412 attrNode->type = AttrNode::AttrType::TYPE_BOOL;
779 else
780
2/4
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 73 not taken.
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 70 not taken.
3 throw ParserError(attrNode->value->codeLoc, INVALID_ATTR_VALUE_TYPE, "Invalid attribute value type");
781 } else {
782 // If no value is given, use the bool type
783 339 attrNode->type = AttrNode::AttrType::TYPE_BOOL;
784 }
785
786
1/2
✓ Branch 57 → 58 taken 1107 times.
✗ Branch 57 → 79 not taken.
1107 return concludeNode(attrNode);
787 }
788
789 70 std::any ASTBuilder::visitCaseConstant(SpiceParser::CaseConstantContext *ctx) {
790 70 const auto caseConstantNode = createNode<CaseConstantNode>(ctx);
791
792 // Visit children
793
2/2
✓ Branch 4 → 5 taken 18 times.
✓ Branch 4 → 10 taken 52 times.
70 if (ctx->constant()) {
794
3/6
✓ Branch 5 → 6 taken 18 times.
✗ Branch 5 → 61 not taken.
✓ Branch 6 → 7 taken 18 times.
✗ Branch 6 → 61 not taken.
✓ Branch 7 → 8 taken 18 times.
✗ Branch 7 → 59 not taken.
18 caseConstantNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
795
2/4
✓ Branch 10 → 11 taken 52 times.
✗ Branch 10 → 62 not taken.
✓ Branch 13 → 14 taken 52 times.
✗ Branch 13 → 48 not taken.
52 } else if (!ctx->TYPE_IDENTIFIER().empty()) {
796
2/2
✓ Branch 46 → 16 taken 126 times.
✓ Branch 46 → 47 taken 52 times.
178 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
797
1/2
✓ Branch 17 → 18 taken 126 times.
✗ Branch 17 → 19 not taken.
126 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
798
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 126 times.
126 if (!terminal)
799 continue;
800
801
3/6
✓ Branch 22 → 23 taken 126 times.
✗ Branch 22 → 69 not taken.
✓ Branch 23 → 24 taken 126 times.
✗ Branch 23 → 69 not taken.
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 33 taken 126 times.
126 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
802 const std::string fragment = getIdentifier(terminal, false);
803 caseConstantNode->identifierFragments.push_back(fragment);
804 if (!caseConstantNode->fqIdentifier.empty())
805 caseConstantNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
806 caseConstantNode->fqIdentifier += fragment;
807
4/6
✓ Branch 33 → 34 taken 126 times.
✗ Branch 33 → 69 not taken.
✓ Branch 34 → 35 taken 126 times.
✗ Branch 34 → 69 not taken.
✓ Branch 35 → 36 taken 89 times.
✓ Branch 35 → 44 taken 37 times.
126 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
808
1/2
✓ Branch 36 → 37 taken 89 times.
✗ Branch 36 → 68 not taken.
89 const std::string fragment = getIdentifier(terminal, false);
809
1/2
✓ Branch 37 → 38 taken 89 times.
✗ Branch 37 → 66 not taken.
89 caseConstantNode->identifierFragments.push_back(fragment);
810
2/2
✓ Branch 39 → 40 taken 37 times.
✓ Branch 39 → 41 taken 52 times.
89 if (!caseConstantNode->fqIdentifier.empty())
811
1/2
✓ Branch 40 → 41 taken 37 times.
✗ Branch 40 → 66 not taken.
37 caseConstantNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
812
1/2
✓ Branch 41 → 42 taken 89 times.
✗ Branch 41 → 66 not taken.
89 caseConstantNode->fqIdentifier += fragment;
813 89 }
814 }
815 } else {
816 assert_fail("Unknown case constant type"); // GCOV_EXCL_LINE
817 }
818
819
1/2
✓ Branch 55 → 56 taken 70 times.
✗ Branch 55 → 70 not taken.
70 return concludeNode(caseConstantNode);
820 }
821
822 9637 std::any ASTBuilder::visitReturnStmt(SpiceParser::ReturnStmtContext *ctx) {
823 9637 const auto returnStmtNode = createNode<ReturnStmtNode>(ctx);
824
825 // Visit children
826
2/2
✓ Branch 4 → 5 taken 9392 times.
✓ Branch 4 → 10 taken 245 times.
9637 if (ctx->assignExpr()) {
827 9392 returnStmtNode->hasReturnValue = true;
828
3/6
✓ Branch 5 → 6 taken 9392 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 9392 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 9392 times.
✗ Branch 7 → 20 not taken.
9392 returnStmtNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
829 }
830
831
1/2
✓ Branch 16 → 17 taken 9637 times.
✗ Branch 16 → 23 not taken.
9637 return concludeNode(returnStmtNode);
832 }
833
834 119 std::any ASTBuilder::visitBreakStmt(SpiceParser::BreakStmtContext *ctx) {
835 119 const auto breakStmtNode = createNode<BreakStmtNode>(ctx);
836
837 // Extract number of breaks
838
2/2
✓ Branch 4 → 5 taken 6 times.
✓ Branch 4 → 10 taken 113 times.
119 if (ctx->INT_LIT())
839
3/6
✓ Branch 5 → 6 taken 6 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 6 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 6 times.
✗ Branch 7 → 22 not taken.
6 breakStmtNode->breakTimes = std::stoi(ctx->INT_LIT()->toString());
840
841 // Visit children
842
1/2
✓ Branch 10 → 11 taken 119 times.
✗ Branch 10 → 25 not taken.
119 visitChildren(ctx);
843
844
1/2
✓ Branch 18 → 19 taken 119 times.
✗ Branch 18 → 26 not taken.
119 return concludeNode(breakStmtNode);
845 }
846
847 199 std::any ASTBuilder::visitContinueStmt(SpiceParser::ContinueStmtContext *ctx) {
848 199 const auto continueStmtNode = createNode<ContinueStmtNode>(ctx);
849
850 // Extract number of continues
851
2/2
✓ Branch 4 → 5 taken 198 times.
✓ Branch 4 → 10 taken 1 time.
199 if (ctx->INT_LIT())
852
3/6
✓ Branch 5 → 6 taken 198 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 198 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 198 times.
✗ Branch 7 → 22 not taken.
198 continueStmtNode->continueTimes = std::stoi(ctx->INT_LIT()->toString());
853
854 // Visit children
855
1/2
✓ Branch 10 → 11 taken 199 times.
✗ Branch 10 → 25 not taken.
199 visitChildren(ctx);
856
857
1/2
✓ Branch 18 → 19 taken 199 times.
✗ Branch 18 → 26 not taken.
199 return concludeNode(continueStmtNode);
858 }
859
860 6 std::any ASTBuilder::visitFallthroughStmt(SpiceParser::FallthroughStmtContext *ctx) {
861 6 const auto fallthroughStmtNode = createNode<FallthroughStmtNode>(ctx);
862
863 // Visit children
864
1/2
✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 15 not taken.
6 visitChildren(ctx);
865
866
1/2
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 16 not taken.
6 return concludeNode(fallthroughStmtNode);
867 }
868
869 716 std::any ASTBuilder::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) {
870
1/2
✓ Branch 2 → 3 taken 716 times.
✗ Branch 2 → 30 not taken.
716 const auto assertStmtNode = createNode<AssertStmtNode>(ctx);
871
872 // Enrich
873
5/10
✓ Branch 3 → 4 taken 716 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 716 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 716 times.
✗ Branch 5 → 30 not taken.
✓ Branch 6 → 7 taken 716 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 716 times.
✗ Branch 7 → 30 not taken.
716 const antlr4::misc::Interval interval(ctx->assignExpr()->start->getStartIndex(), ctx->assignExpr()->stop->getStopIndex());
874
1/2
✓ Branch 8 → 9 taken 716 times.
✗ Branch 8 → 25 not taken.
716 assertStmtNode->expressionString = inputStream->getText(interval);
875
876 // Visit children
877
3/6
✓ Branch 11 → 12 taken 716 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 13 taken 716 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 716 times.
✗ Branch 13 → 26 not taken.
716 assertStmtNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
878
879
1/2
✓ Branch 21 → 22 taken 716 times.
✗ Branch 21 → 29 not taken.
716 return concludeNode(assertStmtNode);
880 }
881
882 2280 std::any ASTBuilder::visitBuiltinCall(SpiceParser::BuiltinCallContext *ctx) {
883 2280 const auto builtinCallNode = createNode<BuiltinCallNode>(ctx);
884
885
2/2
✓ Branch 4 → 5 taken 856 times.
✓ Branch 4 → 10 taken 1424 times.
2280 if (ctx->printfCall()) {
886
3/6
✓ Branch 5 → 6 taken 856 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 856 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 856 times.
✗ Branch 7 → 63 not taken.
856 builtinCallNode->printfCall = std::any_cast<PrintfCallNode *>(visit(ctx->printfCall()));
887
2/2
✓ Branch 11 → 12 taken 281 times.
✓ Branch 11 → 17 taken 1143 times.
1424 } else if (ctx->sizeOfCall()) {
888
3/6
✓ Branch 12 → 13 taken 281 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 281 times.
✗ Branch 13 → 68 not taken.
✓ Branch 14 → 15 taken 281 times.
✗ Branch 14 → 66 not taken.
281 builtinCallNode->sizeofCall = std::any_cast<SizeofCallNode *>(visit(ctx->sizeOfCall()));
889
2/2
✓ Branch 18 → 19 taken 11 times.
✓ Branch 18 → 24 taken 1132 times.
1143 } else if (ctx->alignOfCall()) {
890
3/6
✓ Branch 19 → 20 taken 11 times.
✗ Branch 19 → 71 not taken.
✓ Branch 20 → 21 taken 11 times.
✗ Branch 20 → 71 not taken.
✓ Branch 21 → 22 taken 11 times.
✗ Branch 21 → 69 not taken.
11 builtinCallNode->alignofCall = std::any_cast<AlignofCallNode *>(visit(ctx->alignOfCall()));
891
2/2
✓ Branch 25 → 26 taken 2 times.
✓ Branch 25 → 31 taken 1130 times.
1132 } else if (ctx->typeIdCall()) {
892
3/6
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 74 not taken.
✓ Branch 27 → 28 taken 2 times.
✗ Branch 27 → 74 not taken.
✓ Branch 28 → 29 taken 2 times.
✗ Branch 28 → 72 not taken.
2 builtinCallNode->typeidCall = std::any_cast<TypeidCallNode *>(visit(ctx->typeIdCall()));
893
2/2
✓ Branch 32 → 33 taken 137 times.
✓ Branch 32 → 38 taken 993 times.
1130 } else if (ctx->lenCall()) {
894
3/6
✓ Branch 33 → 34 taken 137 times.
✗ Branch 33 → 77 not taken.
✓ Branch 34 → 35 taken 137 times.
✗ Branch 34 → 77 not taken.
✓ Branch 35 → 36 taken 137 times.
✗ Branch 35 → 75 not taken.
137 builtinCallNode->lenCall = std::any_cast<LenCallNode *>(visit(ctx->lenCall()));
895
2/2
✓ Branch 39 → 40 taken 992 times.
✓ Branch 39 → 45 taken 1 time.
993 } else if (ctx->panicCall()) {
896
3/6
✓ Branch 40 → 41 taken 992 times.
✗ Branch 40 → 80 not taken.
✓ Branch 41 → 42 taken 992 times.
✗ Branch 41 → 80 not taken.
✓ Branch 42 → 43 taken 992 times.
✗ Branch 42 → 78 not taken.
992 builtinCallNode->panicCall = std::any_cast<PanicCallNode *>(visit(ctx->panicCall()));
897
1/2
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 52 not taken.
1 } else if (ctx->sysCall()) {
898
3/6
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 83 not taken.
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 83 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 81 not taken.
1 builtinCallNode->sysCall = std::any_cast<SysCallNode *>(visit(ctx->sysCall()));
899 } else {
900 assert_fail("Unknown builtin call"); // GCOV_EXCL_LINE
901 }
902
903
1/2
✓ Branch 59 → 60 taken 2280 times.
✗ Branch 59 → 84 not taken.
2280 return concludeNode(builtinCallNode);
904 }
905
906 856 std::any ASTBuilder::visitPrintfCall(SpiceParser::PrintfCallContext *ctx) {
907
1/2
✓ Branch 2 → 3 taken 856 times.
✗ Branch 2 → 32 not taken.
856 const auto printfCallNode = createNode<PrintfCallNode>(ctx);
908
909 // Enrich
910
2/4
✓ Branch 3 → 4 taken 856 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 856 times.
✗ Branch 4 → 32 not taken.
856 std::string templatedString = ctx->STRING_LIT()->getText();
911
1/2
✓ Branch 6 → 7 taken 856 times.
✗ Branch 6 → 25 not taken.
856 templatedString = templatedString.substr(1, templatedString.size() - 2);
912
1/2
✓ Branch 9 → 10 taken 856 times.
✗ Branch 9 → 30 not taken.
856 replaceEscapeChars(templatedString);
913
1/2
✓ Branch 10 → 11 taken 856 times.
✗ Branch 10 → 30 not taken.
856 printfCallNode->templatedString = templatedString;
914
915 // Visit children
916
2/4
✓ Branch 11 → 12 taken 856 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 13 taken 856 times.
✗ Branch 12 → 26 not taken.
856 fetchChildrenIntoVector(printfCallNode->args, ctx->assignExpr());
917
918
1/2
✓ Branch 20 → 21 taken 856 times.
✗ Branch 20 → 29 not taken.
1712 return concludeNode(printfCallNode);
919 856 }
920
921 281 std::any ASTBuilder::visitSizeOfCall(SpiceParser::SizeOfCallContext *ctx) {
922 281 const auto sizeofCallNode = createNode<SizeofCallNode>(ctx);
923
924 // Visit children
925
2/2
✓ Branch 4 → 5 taken 20 times.
✓ Branch 4 → 10 taken 261 times.
281 if (ctx->assignExpr()) {
926
3/6
✓ Branch 5 → 6 taken 20 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 20 times.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 20 times.
✗ Branch 7 → 25 not taken.
20 sizeofCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
927 } else {
928 261 sizeofCallNode->isType = true;
929
3/6
✓ Branch 10 → 11 taken 261 times.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 261 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 261 times.
✗ Branch 12 → 28 not taken.
261 sizeofCallNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
930 }
931
932
1/2
✓ Branch 21 → 22 taken 281 times.
✗ Branch 21 → 31 not taken.
281 return concludeNode(sizeofCallNode);
933 }
934
935 11 std::any ASTBuilder::visitAlignOfCall(SpiceParser::AlignOfCallContext *ctx) {
936 11 const auto alignofCallNode = createNode<AlignofCallNode>(ctx);
937
938 // Visit children
939
2/2
✓ Branch 4 → 5 taken 10 times.
✓ Branch 4 → 10 taken 1 time.
11 if (ctx->assignExpr()) {
940
3/6
✓ Branch 5 → 6 taken 10 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 10 times.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 10 times.
✗ Branch 7 → 25 not taken.
10 alignofCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
941 } else {
942 1 alignofCallNode->isType = true;
943
3/6
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 28 not taken.
1 alignofCallNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
944 }
945
946
1/2
✓ Branch 21 → 22 taken 11 times.
✗ Branch 21 → 31 not taken.
11 return concludeNode(alignofCallNode);
947 }
948
949 2 std::any ASTBuilder::visitTypeIdCall(SpiceParser::TypeIdCallContext *ctx) {
950 2 const auto typeidCallNode = createNode<TypeidCallNode>(ctx);
951
952 // Visit children
953
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 10 taken 1 time.
2 if (ctx->assignExpr()) {
954
3/6
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 25 not taken.
1 typeidCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
955 } else {
956 1 typeidCallNode->isType = true;
957
3/6
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 28 not taken.
1 typeidCallNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
958 }
959
960
1/2
✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 31 not taken.
2 return concludeNode(typeidCallNode);
961 }
962
963 137 std::any ASTBuilder::visitLenCall(SpiceParser::LenCallContext *ctx) {
964 137 const auto lenCallNode = createNode<LenCallNode>(ctx);
965
966 // Visit children
967
3/6
✓ Branch 3 → 4 taken 137 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 137 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 137 times.
✗ Branch 5 → 17 not taken.
137 lenCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
968
969
1/2
✓ Branch 13 → 14 taken 137 times.
✗ Branch 13 → 20 not taken.
137 return concludeNode(lenCallNode);
970 }
971
972 992 std::any ASTBuilder::visitPanicCall(SpiceParser::PanicCallContext *ctx) {
973 992 const auto panicCallNode = createNode<PanicCallNode>(ctx);
974
975 // Visit children
976
3/6
✓ Branch 3 → 4 taken 992 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 992 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 992 times.
✗ Branch 5 → 17 not taken.
992 panicCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
977
978
1/2
✓ Branch 13 → 14 taken 992 times.
✗ Branch 13 → 20 not taken.
992 return concludeNode(panicCallNode);
979 }
980
981 1 std::any ASTBuilder::visitSysCall(SpiceParser::SysCallContext *ctx) {
982 1 const auto sysCallNode = createNode<SysCallNode>(ctx);
983
984 // Visit children
985
2/4
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 16 not taken.
1 fetchChildrenIntoVector(sysCallNode->args, ctx->assignExpr());
986
987
1/2
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 19 not taken.
1 return concludeNode(sysCallNode);
988 }
989
990 76647 std::any ASTBuilder::visitAssignExpr(SpiceParser::AssignExprContext *ctx) {
991 76647 const auto assignExprNode = createNode<AssignExprNode>(ctx);
992
993 // Visit children
994
2/2
✓ Branch 4 → 5 taken 68877 times.
✓ Branch 4 → 10 taken 7770 times.
76647 if (ctx->ternaryExpr()) {
995
4/6
✓ Branch 5 → 6 taken 68877 times.
✗ Branch 5 → 37 not taken.
✓ Branch 6 → 7 taken 68875 times.
✓ Branch 6 → 37 taken 2 times.
✓ Branch 7 → 8 taken 68875 times.
✗ Branch 7 → 35 not taken.
68877 assignExprNode->ternaryExpr = std::any_cast<TernaryExprNode *>(visit(ctx->ternaryExpr()));
996
1/2
✓ Branch 11 → 12 taken 7770 times.
✗ Branch 11 → 24 not taken.
7770 } else if (ctx->prefixUnaryExpr()) {
997
3/6
✓ Branch 12 → 13 taken 7770 times.
✗ Branch 12 → 40 not taken.
✓ Branch 13 → 14 taken 7770 times.
✗ Branch 13 → 40 not taken.
✓ Branch 14 → 15 taken 7770 times.
✗ Branch 14 → 38 not taken.
7770 assignExprNode->lhs = std::any_cast<PrefixUnaryExprNode *>(visit(ctx->prefixUnaryExpr()));
998
2/4
✓ Branch 16 → 17 taken 7770 times.
✗ Branch 16 → 41 not taken.
✓ Branch 17 → 18 taken 7770 times.
✗ Branch 17 → 41 not taken.
7770 visit(ctx->assignOp());
999
3/6
✓ Branch 19 → 20 taken 7770 times.
✗ Branch 19 → 44 not taken.
✓ Branch 20 → 21 taken 7770 times.
✗ Branch 20 → 44 not taken.
✓ Branch 21 → 22 taken 7770 times.
✗ Branch 21 → 42 not taken.
7770 assignExprNode->rhs = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
1000 } else {
1001 assert_fail("Invalid assign expression"); // GCOV_EXCL_LINE
1002 }
1003
1004
1/2
✓ Branch 31 → 32 taken 76645 times.
✗ Branch 31 → 45 not taken.
76645 return concludeNode(assignExprNode);
1005 }
1006
1007 69102 std::any ASTBuilder::visitTernaryExpr(SpiceParser::TernaryExprContext *ctx) {
1008 69102 const auto ternaryExprNode = createNode<TernaryExprNode>(ctx);
1009
1010
4/6
✓ Branch 3 → 4 taken 69102 times.
✗ Branch 3 → 41 not taken.
✓ Branch 4 → 5 taken 69100 times.
✓ Branch 4 → 41 taken 2 times.
✓ Branch 5 → 6 taken 69100 times.
✗ Branch 5 → 39 not taken.
69102 ternaryExprNode->condition = std::any_cast<LogicalOrExprNode *>(visit(ctx->logicalOrExpr(0)));
1011
3/4
✓ Branch 7 → 8 taken 69100 times.
✗ Branch 7 → 42 not taken.
✓ Branch 10 → 11 taken 462 times.
✓ Branch 10 → 20 taken 68638 times.
69100 if (ctx->logicalOrExpr().size() == 3) {
1012
3/6
✓ Branch 11 → 12 taken 462 times.
✗ Branch 11 → 45 not taken.
✓ Branch 12 → 13 taken 462 times.
✗ Branch 12 → 45 not taken.
✓ Branch 13 → 14 taken 462 times.
✗ Branch 13 → 43 not taken.
462 ternaryExprNode->trueExpr = std::any_cast<LogicalOrExprNode *>(visit(ctx->logicalOrExpr(1)));
1013
3/6
✓ Branch 15 → 16 taken 462 times.
✗ Branch 15 → 48 not taken.
✓ Branch 16 → 17 taken 462 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 462 times.
✗ Branch 17 → 46 not taken.
462 ternaryExprNode->falseExpr = std::any_cast<LogicalOrExprNode *>(visit(ctx->logicalOrExpr(2)));
1014
3/4
✓ Branch 20 → 21 taken 68638 times.
✗ Branch 20 → 49 not taken.
✓ Branch 23 → 24 taken 1 time.
✓ Branch 23 → 29 taken 68637 times.
68638 } else if (ctx->logicalOrExpr().size() == 2) {
1015 1 ternaryExprNode->isShortened = true;
1016
3/6
✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 52 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 52 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 50 not taken.
1 ternaryExprNode->falseExpr = std::any_cast<LogicalOrExprNode *>(visit(ctx->logicalOrExpr(1)));
1017 }
1018
1019
1/2
✓ Branch 35 → 36 taken 69100 times.
✗ Branch 35 → 53 not taken.
69100 return concludeNode(ternaryExprNode);
1020 }
1021
1022 70027 std::any ASTBuilder::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext *ctx) {
1023 70027 const auto logicalOrExprNode = createNode<LogicalOrExprNode>(ctx);
1024
1025 // Visit children
1026
3/4
✓ Branch 3 → 4 taken 70027 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 70025 times.
✓ Branch 4 → 16 taken 2 times.
70029 fetchChildrenIntoVector(logicalOrExprNode->operands, ctx->logicalAndExpr());
1027
1028
1/2
✓ Branch 12 → 13 taken 70025 times.
✗ Branch 12 → 19 not taken.
70025 return concludeNode(logicalOrExprNode);
1029 }
1030
1031 71312 std::any ASTBuilder::visitLogicalAndExpr(SpiceParser::LogicalAndExprContext *ctx) {
1032 71312 const auto logicalAndExprNode = createNode<LogicalAndExprNode>(ctx);
1033
1034 // Visit children
1035
3/4
✓ Branch 3 → 4 taken 71312 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 71310 times.
✓ Branch 4 → 16 taken 2 times.
71314 fetchChildrenIntoVector(logicalAndExprNode->operands, ctx->bitwiseOrExpr());
1036
1037
1/2
✓ Branch 12 → 13 taken 71310 times.
✗ Branch 12 → 19 not taken.
71310 return concludeNode(logicalAndExprNode);
1038 }
1039
1040 71605 std::any ASTBuilder::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext *ctx) {
1041 71605 const auto bitwiseOrExprNode = createNode<BitwiseOrExprNode>(ctx);
1042
1043 // Visit children
1044
3/4
✓ Branch 3 → 4 taken 71605 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 71603 times.
✓ Branch 4 → 16 taken 2 times.
71607 fetchChildrenIntoVector(bitwiseOrExprNode->operands, ctx->bitwiseXorExpr());
1045
1046
1/2
✓ Branch 12 → 13 taken 71603 times.
✗ Branch 12 → 19 not taken.
71603 return concludeNode(bitwiseOrExprNode);
1047 }
1048
1049 71693 std::any ASTBuilder::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprContext *ctx) {
1050 71693 const auto bitwiseXorExprNode = createNode<BitwiseXorExprNode>(ctx);
1051
1052 // Visit children
1053
3/4
✓ Branch 3 → 4 taken 71693 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 71691 times.
✓ Branch 4 → 16 taken 2 times.
71695 fetchChildrenIntoVector(bitwiseXorExprNode->operands, ctx->bitwiseAndExpr());
1054
1055
1/2
✓ Branch 12 → 13 taken 71691 times.
✗ Branch 12 → 19 not taken.
71691 return concludeNode(bitwiseXorExprNode);
1056 }
1057
1058 71704 std::any ASTBuilder::visitBitwiseAndExpr(SpiceParser::BitwiseAndExprContext *ctx) {
1059 71704 const auto bitwiseAndExprNode = createNode<BitwiseAndExprNode>(ctx);
1060
1061 // Visit children
1062
3/4
✓ Branch 3 → 4 taken 71704 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 71702 times.
✓ Branch 4 → 16 taken 2 times.
71706 fetchChildrenIntoVector(bitwiseAndExprNode->operands, ctx->equalityExpr());
1063
1064
1/2
✓ Branch 12 → 13 taken 71702 times.
✗ Branch 12 → 19 not taken.
71702 return concludeNode(bitwiseAndExprNode);
1065 }
1066
1067 71740 std::any ASTBuilder::visitEqualityExpr(SpiceParser::EqualityExprContext *ctx) {
1068 71740 const auto equalityExprNode = createNode<EqualityExprNode>(ctx);
1069
1070 // Visit children
1071
3/4
✓ Branch 3 → 4 taken 71740 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 71738 times.
✓ Branch 4 → 22 taken 2 times.
71742 fetchChildrenIntoVector(equalityExprNode->operands, ctx->relationalExpr());
1072
1073 // Extract operator
1074
2/2
✓ Branch 7 → 8 taken 3865 times.
✓ Branch 7 → 9 taken 67873 times.
71738 if (ctx->EQUAL())
1075 3865 equalityExprNode->op = EqualityExprNode::EqualityOp::OP_EQUAL;
1076
2/2
✓ Branch 10 → 11 taken 1382 times.
✓ Branch 10 → 12 taken 66491 times.
67873 else if (ctx->NOT_EQUAL())
1077 1382 equalityExprNode->op = EqualityExprNode::EqualityOp::OP_NOT_EQUAL;
1078
1079
1/2
✓ Branch 18 → 19 taken 71738 times.
✗ Branch 18 → 25 not taken.
71738 return concludeNode(equalityExprNode);
1080 }
1081
1082 76987 std::any ASTBuilder::visitRelationalExpr(SpiceParser::RelationalExprContext *ctx) {
1083 76987 const auto relationalExprNode = createNode<RelationalExprNode>(ctx);
1084
1085 // Visit children
1086
3/4
✓ Branch 3 → 4 taken 76987 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 76985 times.
✓ Branch 4 → 28 taken 2 times.
76989 fetchChildrenIntoVector(relationalExprNode->operands, ctx->shiftExpr());
1087
1088 // Extract operator
1089
2/2
✓ Branch 7 → 8 taken 2089 times.
✓ Branch 7 → 9 taken 74896 times.
76985 if (ctx->LESS())
1090 2089 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS;
1091
2/2
✓ Branch 10 → 11 taken 690 times.
✓ Branch 10 → 12 taken 74206 times.
74896 else if (ctx->GREATER())
1092 690 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER;
1093
2/2
✓ Branch 13 → 14 taken 343 times.
✓ Branch 13 → 15 taken 73863 times.
74206 else if (ctx->LESS_EQUAL())
1094 343 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS_EQUAL;
1095
2/2
✓ Branch 16 → 17 taken 840 times.
✓ Branch 16 → 18 taken 73023 times.
73863 else if (ctx->GREATER_EQUAL())
1096 840 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER_EQUAL;
1097
1098
1/2
✓ Branch 24 → 25 taken 76985 times.
✗ Branch 24 → 31 not taken.
76985 return concludeNode(relationalExprNode);
1099 }
1100
1101 80949 std::any ASTBuilder::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) {
1102 80949 const auto shiftExprNode = createNode<ShiftExprNode>(ctx);
1103
1104 // Visit children
1105
3/4
✓ Branch 3 → 4 taken 80949 times.
✗ Branch 3 → 48 not taken.
✓ Branch 4 → 5 taken 80947 times.
✓ Branch 4 → 46 taken 2 times.
80951 fetchChildrenIntoVector(shiftExprNode->operands, ctx->additiveExpr());
1106
1107 80947 bool seenFirstLess = false;
1108 80947 bool seenFirstGreater = false;
1109
2/2
✓ Branch 31 → 8 taken 81340 times.
✓ Branch 31 → 32 taken 80947 times.
162287 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1110
1/2
✓ Branch 9 → 10 taken 81340 times.
✗ Branch 9 → 11 not taken.
81340 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1111
2/2
✓ Branch 12 → 13 taken 81078 times.
✓ Branch 12 → 14 taken 262 times.
81340 if (!terminal)
1112 81078 continue;
1113
1114
4/6
✓ Branch 14 → 15 taken 262 times.
✗ Branch 14 → 53 not taken.
✓ Branch 15 → 16 taken 262 times.
✗ Branch 15 → 53 not taken.
✓ Branch 16 → 17 taken 154 times.
✓ Branch 16 → 21 taken 108 times.
262 if (terminal->getSymbol()->getType() == SpiceParser::LESS) {
1115
2/2
✓ Branch 17 → 18 taken 77 times.
✓ Branch 17 → 20 taken 77 times.
154 if (seenFirstLess)
1116
1/2
✓ Branch 18 → 19 taken 77 times.
✗ Branch 18 → 49 not taken.
77 shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_LEFT, TY_INVALID);
1117 154 seenFirstLess = !seenFirstLess;
1118 154 continue;
1119 }
1120
1121
3/6
✓ Branch 21 → 22 taken 108 times.
✗ Branch 21 → 53 not taken.
✓ Branch 22 → 23 taken 108 times.
✗ Branch 22 → 53 not taken.
✓ Branch 23 → 24 taken 108 times.
✗ Branch 23 → 28 not taken.
108 if (terminal->getSymbol()->getType() == SpiceParser::GREATER) {
1122
2/2
✓ Branch 24 → 25 taken 54 times.
✓ Branch 24 → 27 taken 54 times.
108 if (seenFirstGreater)
1123
1/2
✓ Branch 25 → 26 taken 54 times.
✗ Branch 25 → 51 not taken.
54 shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT, TY_INVALID);
1124 108 seenFirstGreater = !seenFirstGreater;
1125 108 continue;
1126 }
1127
1128 assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE
1129 }
1130
2/4
✓ Branch 32 → 33 taken 80947 times.
✗ Branch 32 → 35 not taken.
✓ Branch 33 → 34 taken 80947 times.
✗ Branch 33 → 35 not taken.
80947 assert(!seenFirstLess && !seenFirstGreater);
1131
1132
1/2
✓ Branch 42 → 43 taken 80947 times.
✗ Branch 42 → 54 not taken.
80947 return concludeNode(shiftExprNode);
1133 }
1134
1135 81080 std::any ASTBuilder::visitAdditiveExpr(SpiceParser::AdditiveExprContext *ctx) {
1136 81080 const auto additiveExprNode = createNode<AdditiveExprNode>(ctx);
1137
1138 // Visit children
1139
3/4
✓ Branch 3 → 4 taken 81080 times.
✗ Branch 3 → 40 not taken.
✓ Branch 4 → 5 taken 81078 times.
✓ Branch 4 → 38 taken 2 times.
81082 fetchChildrenIntoVector(additiveExprNode->operands, ctx->multiplicativeExpr());
1140
1141
2/2
✓ Branch 27 → 8 taken 89336 times.
✓ Branch 27 → 28 taken 81078 times.
170414 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1142
1/2
✓ Branch 9 → 10 taken 89336 times.
✗ Branch 9 → 11 not taken.
89336 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1143
2/2
✓ Branch 12 → 13 taken 85207 times.
✓ Branch 12 → 14 taken 4129 times.
89336 if (!terminal)
1144 85207 continue;
1145
1146
4/6
✓ Branch 14 → 15 taken 4129 times.
✗ Branch 14 → 45 not taken.
✓ Branch 15 → 16 taken 4129 times.
✗ Branch 15 → 45 not taken.
✓ Branch 16 → 17 taken 2496 times.
✓ Branch 16 → 19 taken 1633 times.
4129 if (terminal->getSymbol()->getType() == SpiceParser::PLUS)
1147
1/2
✓ Branch 17 → 18 taken 2496 times.
✗ Branch 17 → 41 not taken.
2496 additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_PLUS, TY_INVALID);
1148
3/6
✓ Branch 19 → 20 taken 1633 times.
✗ Branch 19 → 45 not taken.
✓ Branch 20 → 21 taken 1633 times.
✗ Branch 20 → 45 not taken.
✓ Branch 21 → 22 taken 1633 times.
✗ Branch 21 → 24 not taken.
1633 else if (terminal->getSymbol()->getType() == SpiceParser::MINUS)
1149
1/2
✓ Branch 22 → 23 taken 1633 times.
✗ Branch 22 → 43 not taken.
1633 additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_MINUS, TY_INVALID);
1150 else
1151 assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE
1152 }
1153
1154
1/2
✓ Branch 34 → 35 taken 81078 times.
✗ Branch 34 → 46 not taken.
81078 return concludeNode(additiveExprNode);
1155 }
1156
1157 85209 std::any ASTBuilder::visitMultiplicativeExpr(SpiceParser::MultiplicativeExprContext *ctx) {
1158 85209 const auto multiplicativeExprNode = createNode<MultiplicativeExprNode>(ctx);
1159
1160 // Visit children
1161
3/4
✓ Branch 3 → 4 taken 85209 times.
✗ Branch 3 → 45 not taken.
✓ Branch 4 → 5 taken 85207 times.
✓ Branch 4 → 43 taken 2 times.
85211 fetchChildrenIntoVector(multiplicativeExprNode->operands, ctx->castExpr());
1162
1163
2/2
✓ Branch 32 → 8 taken 87857 times.
✓ Branch 32 → 33 taken 85207 times.
173064 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1164
1/2
✓ Branch 9 → 10 taken 87857 times.
✗ Branch 9 → 11 not taken.
87857 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1165
2/2
✓ Branch 12 → 13 taken 86532 times.
✓ Branch 12 → 14 taken 1325 times.
87857 if (!terminal)
1166 86532 continue;
1167
1168
4/6
✓ Branch 14 → 15 taken 1325 times.
✗ Branch 14 → 52 not taken.
✓ Branch 15 → 16 taken 1325 times.
✗ Branch 15 → 52 not taken.
✓ Branch 16 → 17 taken 994 times.
✓ Branch 16 → 19 taken 331 times.
1325 if (terminal->getSymbol()->getType() == SpiceParser::MUL)
1169
1/2
✓ Branch 17 → 18 taken 994 times.
✗ Branch 17 → 46 not taken.
994 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_MUL, TY_INVALID);
1170
4/6
✓ Branch 19 → 20 taken 331 times.
✗ Branch 19 → 52 not taken.
✓ Branch 20 → 21 taken 331 times.
✗ Branch 20 → 52 not taken.
✓ Branch 21 → 22 taken 134 times.
✓ Branch 21 → 24 taken 197 times.
331 else if (terminal->getSymbol()->getType() == SpiceParser::DIV)
1171
1/2
✓ Branch 22 → 23 taken 134 times.
✗ Branch 22 → 48 not taken.
134 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_DIV, TY_INVALID);
1172
3/6
✓ Branch 24 → 25 taken 197 times.
✗ Branch 24 → 52 not taken.
✓ Branch 25 → 26 taken 197 times.
✗ Branch 25 → 52 not taken.
✓ Branch 26 → 27 taken 197 times.
✗ Branch 26 → 29 not taken.
197 else if (terminal->getSymbol()->getType() == SpiceParser::REM)
1173
1/2
✓ Branch 27 → 28 taken 197 times.
✗ Branch 27 → 50 not taken.
197 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_REM, TY_INVALID);
1174 else
1175 assert_fail("Invalid terminal symbol for multiplicative expression"); // GCOV_EXCL_LINE
1176 }
1177
1178
1/2
✓ Branch 39 → 40 taken 85207 times.
✗ Branch 39 → 53 not taken.
85207 return concludeNode(multiplicativeExprNode);
1179 }
1180
1181 86534 std::any ASTBuilder::visitCastExpr(SpiceParser::CastExprContext *ctx) {
1182 86534 const auto castExprNode = createNode<CastExprNode>(ctx);
1183
1184
2/2
✓ Branch 4 → 5 taken 2729 times.
✓ Branch 4 → 14 taken 83805 times.
86534 if (ctx->dataType()) {
1185
3/6
✓ Branch 5 → 6 taken 2729 times.
✗ Branch 5 → 31 not taken.
✓ Branch 6 → 7 taken 2729 times.
✗ Branch 6 → 31 not taken.
✓ Branch 7 → 8 taken 2729 times.
✗ Branch 7 → 29 not taken.
2729 castExprNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1186
3/6
✓ Branch 9 → 10 taken 2729 times.
✗ Branch 9 → 34 not taken.
✓ Branch 10 → 11 taken 2729 times.
✗ Branch 10 → 34 not taken.
✓ Branch 11 → 12 taken 2729 times.
✗ Branch 11 → 32 not taken.
2729 castExprNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
1187 2729 castExprNode->isCast = true;
1188 } else {
1189
4/6
✓ Branch 14 → 15 taken 83805 times.
✗ Branch 14 → 37 not taken.
✓ Branch 15 → 16 taken 83803 times.
✓ Branch 15 → 37 taken 2 times.
✓ Branch 16 → 17 taken 83803 times.
✗ Branch 16 → 35 not taken.
83805 castExprNode->prefixUnaryExpr = std::any_cast<PrefixUnaryExprNode *>(visit(ctx->prefixUnaryExpr()));
1190 }
1191
1192
1/2
✓ Branch 25 → 26 taken 86532 times.
✗ Branch 25 → 38 not taken.
86532 return concludeNode(castExprNode);
1193 }
1194
1195 92873 std::any ASTBuilder::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprContext *ctx) {
1196 92873 const auto prefixUnaryExprNode = createNode<PrefixUnaryExprNode>(ctx);
1197
1198 // Visit children
1199
2/2
✓ Branch 4 → 5 taken 91575 times.
✓ Branch 4 → 10 taken 1298 times.
92873 if (ctx->postfixUnaryExpr()) {
1200
4/6
✓ Branch 5 → 6 taken 91575 times.
✗ Branch 5 → 51 not taken.
✓ Branch 6 → 7 taken 91573 times.
✓ Branch 6 → 51 taken 2 times.
✓ Branch 7 → 8 taken 91573 times.
✗ Branch 7 → 49 not taken.
91575 prefixUnaryExprNode->postfixUnaryExpr = std::any_cast<PostfixUnaryExprNode *>(visit(ctx->postfixUnaryExpr()));
1201
1/2
✓ Branch 11 → 12 taken 1298 times.
✗ Branch 11 → 38 not taken.
1298 } else if (ctx->prefixUnaryExpr()) {
1202 // Extract operator
1203
2/2
✓ Branch 13 → 14 taken 12 times.
✓ Branch 13 → 15 taken 1286 times.
1298 if (ctx->MINUS())
1204 12 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS;
1205
2/2
✓ Branch 16 → 17 taken 21 times.
✓ Branch 16 → 18 taken 1265 times.
1286 else if (ctx->PLUS_PLUS())
1206 21 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS;
1207
2/2
✓ Branch 19 → 20 taken 9 times.
✓ Branch 19 → 21 taken 1256 times.
1265 else if (ctx->MINUS_MINUS())
1208 9 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS;
1209
2/2
✓ Branch 22 → 23 taken 844 times.
✓ Branch 22 → 24 taken 412 times.
1256 else if (ctx->NOT())
1210 844 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT;
1211
2/2
✓ Branch 25 → 26 taken 1 time.
✓ Branch 25 → 27 taken 411 times.
412 else if (ctx->BITWISE_NOT())
1212 1 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT;
1213
2/2
✓ Branch 28 → 29 taken 241 times.
✓ Branch 28 → 30 taken 170 times.
411 else if (ctx->MUL())
1214 241 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE;
1215
1/2
✓ Branch 31 → 32 taken 170 times.
✗ Branch 31 → 33 not taken.
170 else if (ctx->BITWISE_AND())
1216 170 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF;
1217
1218
3/6
✓ Branch 33 → 34 taken 1298 times.
✗ Branch 33 → 54 not taken.
✓ Branch 34 → 35 taken 1298 times.
✗ Branch 34 → 54 not taken.
✓ Branch 35 → 36 taken 1298 times.
✗ Branch 35 → 52 not taken.
1298 prefixUnaryExprNode->prefixUnaryExpr = std::any_cast<PrefixUnaryExprNode *>(visit(ctx->prefixUnaryExpr()));
1219 } else {
1220 assert_fail("Unknown prefix unary expression type"); // GCOV_EXCL_LINE
1221 }
1222
1223
1/2
✓ Branch 45 → 46 taken 92871 times.
✗ Branch 45 → 55 not taken.
92871 return concludeNode(prefixUnaryExprNode);
1224 }
1225
1226 116408 std::any ASTBuilder::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprContext *ctx) {
1227 116408 const auto postfixUnaryExprNode = createNode<PostfixUnaryExprNode>(ctx);
1228
1229
2/2
✓ Branch 4 → 5 taken 91575 times.
✓ Branch 4 → 10 taken 24833 times.
116408 if (ctx->atomicExpr()) {
1230
4/6
✓ Branch 5 → 6 taken 91575 times.
✗ Branch 5 → 49 not taken.
✓ Branch 6 → 7 taken 91573 times.
✓ Branch 6 → 49 taken 2 times.
✓ Branch 7 → 8 taken 91573 times.
✗ Branch 7 → 47 not taken.
91575 postfixUnaryExprNode->atomicExpr = std::any_cast<AtomicExprNode *>(visit(ctx->atomicExpr()));
1231
1/2
✓ Branch 11 → 12 taken 24833 times.
✗ Branch 11 → 36 not taken.
24833 } else if (ctx->postfixUnaryExpr()) {
1232
3/6
✓ Branch 12 → 13 taken 24833 times.
✗ Branch 12 → 52 not taken.
✓ Branch 13 → 14 taken 24833 times.
✗ Branch 13 → 52 not taken.
✓ Branch 14 → 15 taken 24833 times.
✗ Branch 14 → 50 not taken.
24833 postfixUnaryExprNode->postfixUnaryExpr = std::any_cast<PostfixUnaryExprNode *>(visit(ctx->postfixUnaryExpr()));
1233
1234 // Extract operator
1235
2/2
✓ Branch 17 → 18 taken 4095 times.
✓ Branch 17 → 23 taken 20738 times.
24833 if (ctx->assignExpr()) {
1236 4095 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT;
1237
3/6
✓ Branch 18 → 19 taken 4095 times.
✗ Branch 18 → 55 not taken.
✓ Branch 19 → 20 taken 4095 times.
✗ Branch 19 → 55 not taken.
✓ Branch 20 → 21 taken 4095 times.
✗ Branch 20 → 53 not taken.
4095 postfixUnaryExprNode->subscriptIndexExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
1238
2/2
✓ Branch 24 → 25 taken 18324 times.
✓ Branch 24 → 30 taken 2414 times.
20738 } else if (ctx->IDENTIFIER()) {
1239 18324 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS;
1240
2/4
✓ Branch 25 → 26 taken 18324 times.
✗ Branch 25 → 56 not taken.
✓ Branch 26 → 27 taken 18324 times.
✗ Branch 26 → 56 not taken.
18324 postfixUnaryExprNode->identifier = getIdentifier(ctx->IDENTIFIER(), false);
1241
2/2
✓ Branch 31 → 32 taken 1906 times.
✓ Branch 31 → 33 taken 508 times.
2414 } else if (ctx->PLUS_PLUS()) {
1242 1906 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS;
1243
1/2
✓ Branch 34 → 35 taken 508 times.
✗ Branch 34 → 37 not taken.
508 } else if (ctx->MINUS_MINUS()) {
1244 508 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS;
1245 }
1246 } else {
1247 assert_fail("Unknown postfix unary expression type"); // GCOV_EXCL_LINE
1248 }
1249
1250
1/2
✓ Branch 43 → 44 taken 116406 times.
✗ Branch 43 → 57 not taken.
116406 return concludeNode(postfixUnaryExprNode);
1251 }
1252
1253 91575 std::any ASTBuilder::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) {
1254 91575 const auto atomicExprNode = createNode<AtomicExprNode>(ctx);
1255
1256 // Visit children
1257
2/2
✓ Branch 4 → 5 taken 15887 times.
✓ Branch 4 → 10 taken 75688 times.
91575 if (ctx->constant()) {
1258
4/6
✓ Branch 5 → 6 taken 15887 times.
✗ Branch 5 → 91 not taken.
✓ Branch 6 → 7 taken 15885 times.
✓ Branch 6 → 91 taken 2 times.
✓ Branch 7 → 8 taken 15885 times.
✗ Branch 7 → 89 not taken.
15887 atomicExprNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
1259
2/2
✓ Branch 11 → 12 taken 18245 times.
✓ Branch 11 → 17 taken 57443 times.
75688 } else if (ctx->value()) {
1260
3/6
✓ Branch 12 → 13 taken 18245 times.
✗ Branch 12 → 94 not taken.
✓ Branch 13 → 14 taken 18245 times.
✗ Branch 13 → 94 not taken.
✓ Branch 14 → 15 taken 18245 times.
✗ Branch 14 → 92 not taken.
18245 atomicExprNode->value = std::any_cast<ValueNode *>(visit(ctx->value()));
1261
11/18
✓ Branch 17 → 18 taken 57443 times.
✗ Branch 17 → 95 not taken.
✓ Branch 19 → 20 taken 4731 times.
✓ Branch 19 → 23 taken 52712 times.
✓ Branch 20 → 21 taken 4731 times.
✗ Branch 20 → 95 not taken.
✓ Branch 22 → 23 taken 1773 times.
✓ Branch 22 → 24 taken 2958 times.
✓ Branch 25 → 26 taken 4731 times.
✓ Branch 25 → 27 taken 52712 times.
✓ Branch 27 → 28 taken 57443 times.
✗ Branch 27 → 29 not taken.
✓ Branch 29 → 30 taken 54485 times.
✓ Branch 29 → 64 taken 2958 times.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
✗ Branch 99 → 100 not taken.
✗ Branch 99 → 101 not taken.
57443 } else if (!ctx->IDENTIFIER().empty() || !ctx->TYPE_IDENTIFIER().empty()) {
1262
2/2
✓ Branch 62 → 32 taken 55107 times.
✓ Branch 62 → 63 taken 54485 times.
109592 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1263
1/2
✓ Branch 33 → 34 taken 55107 times.
✗ Branch 33 → 35 not taken.
55107 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1264
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 55107 times.
55107 if (!terminal)
1265 continue;
1266
1267
4/6
✓ Branch 38 → 39 taken 55107 times.
✗ Branch 38 → 109 not taken.
✓ Branch 39 → 40 taken 55107 times.
✗ Branch 39 → 109 not taken.
✓ Branch 40 → 41 taken 52712 times.
✓ Branch 40 → 49 taken 2395 times.
55107 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1268
1/2
✓ Branch 41 → 42 taken 52712 times.
✗ Branch 41 → 105 not taken.
52712 std::string fragment = getIdentifier(terminal, false);
1269
1/2
✓ Branch 42 → 43 taken 52712 times.
✗ Branch 42 → 103 not taken.
52712 atomicExprNode->identifierFragments.push_back(fragment);
1270
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 52712 times.
52712 if (!atomicExprNode->fqIdentifier.empty())
1271 atomicExprNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
1272
1/2
✓ Branch 46 → 47 taken 52712 times.
✗ Branch 46 → 103 not taken.
52712 atomicExprNode->fqIdentifier += fragment;
1273
4/6
✓ Branch 49 → 50 taken 2395 times.
✗ Branch 49 → 109 not taken.
✓ Branch 50 → 51 taken 2395 times.
✗ Branch 50 → 109 not taken.
✓ Branch 51 → 52 taken 2084 times.
✓ Branch 51 → 60 taken 311 times.
55107 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1274
1/2
✓ Branch 52 → 53 taken 2084 times.
✗ Branch 52 → 108 not taken.
2084 std::string fragment = getIdentifier(terminal, false);
1275
1/2
✓ Branch 53 → 54 taken 2084 times.
✗ Branch 53 → 106 not taken.
2084 atomicExprNode->identifierFragments.push_back(fragment);
1276
2/2
✓ Branch 55 → 56 taken 311 times.
✓ Branch 55 → 57 taken 1773 times.
2084 if (!atomicExprNode->fqIdentifier.empty())
1277
1/2
✓ Branch 56 → 57 taken 311 times.
✗ Branch 56 → 106 not taken.
311 atomicExprNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
1278
1/2
✓ Branch 57 → 58 taken 2084 times.
✗ Branch 57 → 106 not taken.
2084 atomicExprNode->fqIdentifier += fragment;
1279 2084 }
1280 }
1281
2/2
✓ Branch 65 → 66 taken 2280 times.
✓ Branch 65 → 71 taken 678 times.
2958 } else if (ctx->builtinCall()) {
1282
3/6
✓ Branch 66 → 67 taken 2280 times.
✗ Branch 66 → 112 not taken.
✓ Branch 67 → 68 taken 2280 times.
✗ Branch 67 → 112 not taken.
✓ Branch 68 → 69 taken 2280 times.
✗ Branch 68 → 110 not taken.
2280 atomicExprNode->builtinCall = std::any_cast<BuiltinCallNode *>(visit(ctx->builtinCall()));
1283
1/2
✓ Branch 72 → 73 taken 678 times.
✗ Branch 72 → 78 not taken.
678 } else if (ctx->assignExpr()) {
1284
3/6
✓ Branch 73 → 74 taken 678 times.
✗ Branch 73 → 115 not taken.
✓ Branch 74 → 75 taken 678 times.
✗ Branch 74 → 115 not taken.
✓ Branch 75 → 76 taken 678 times.
✗ Branch 75 → 113 not taken.
678 atomicExprNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
1285 } else {
1286 assert_fail("Unknown atomic expression type"); // GCOV_EXCL_LINE
1287 }
1288
1289
1/2
✓ Branch 85 → 86 taken 91573 times.
✗ Branch 85 → 116 not taken.
91573 return concludeNode(atomicExprNode);
1290 }
1291
1292 18245 std::any ASTBuilder::visitValue(SpiceParser::ValueContext *ctx) {
1293 18245 const auto valueNode = createNode<ValueNode>(ctx);
1294
1295 // Visit children
1296
2/2
✓ Branch 4 → 5 taken 16399 times.
✓ Branch 4 → 10 taken 1846 times.
18245 if (ctx->fctCall()) {
1297
3/6
✓ Branch 5 → 6 taken 16399 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 16399 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 16399 times.
✗ Branch 7 → 63 not taken.
16399 valueNode->fctCall = std::any_cast<FctCallNode *>(visit(ctx->fctCall()));
1298
2/2
✓ Branch 11 → 12 taken 70 times.
✓ Branch 11 → 17 taken 1776 times.
1846 } else if (ctx->arrayInitialization()) {
1299
3/6
✓ Branch 12 → 13 taken 70 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 70 times.
✗ Branch 13 → 68 not taken.
✓ Branch 14 → 15 taken 70 times.
✗ Branch 14 → 66 not taken.
70 valueNode->arrayInitialization = std::any_cast<ArrayInitializationNode *>(visit(ctx->arrayInitialization()));
1300
2/2
✓ Branch 18 → 19 taken 223 times.
✓ Branch 18 → 24 taken 1553 times.
1776 } else if (ctx->structInstantiation()) {
1301
3/6
✓ Branch 19 → 20 taken 223 times.
✗ Branch 19 → 71 not taken.
✓ Branch 20 → 21 taken 223 times.
✗ Branch 20 → 71 not taken.
✓ Branch 21 → 22 taken 223 times.
✗ Branch 21 → 69 not taken.
223 valueNode->structInstantiation = std::any_cast<StructInstantiationNode *>(visit(ctx->structInstantiation()));
1302
2/2
✓ Branch 25 → 26 taken 12 times.
✓ Branch 25 → 31 taken 1541 times.
1553 } else if (ctx->lambdaFunc()) {
1303
3/6
✓ Branch 26 → 27 taken 12 times.
✗ Branch 26 → 74 not taken.
✓ Branch 27 → 28 taken 12 times.
✗ Branch 27 → 74 not taken.
✓ Branch 28 → 29 taken 12 times.
✗ Branch 28 → 72 not taken.
12 valueNode->lambdaFunc = std::any_cast<LambdaFuncNode *>(visit(ctx->lambdaFunc()));
1304
2/2
✓ Branch 32 → 33 taken 27 times.
✓ Branch 32 → 38 taken 1514 times.
1541 } else if (ctx->lambdaProc()) {
1305
3/6
✓ Branch 33 → 34 taken 27 times.
✗ Branch 33 → 77 not taken.
✓ Branch 34 → 35 taken 27 times.
✗ Branch 34 → 77 not taken.
✓ Branch 35 → 36 taken 27 times.
✗ Branch 35 → 75 not taken.
27 valueNode->lambdaProc = std::any_cast<LambdaProcNode *>(visit(ctx->lambdaProc()));
1306
2/2
✓ Branch 39 → 40 taken 1 time.
✓ Branch 39 → 45 taken 1513 times.
1514 } else if (ctx->lambdaExpr()) {
1307
3/6
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 80 not taken.
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 80 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 78 not taken.
1 valueNode->lambdaExpr = std::any_cast<LambdaExprNode *>(visit(ctx->lambdaExpr()));
1308
1/2
✓ Branch 46 → 47 taken 1513 times.
✗ Branch 46 → 52 not taken.
1513 } else if (ctx->dataType()) {
1309 1513 valueNode->isNil = true;
1310
3/6
✓ Branch 47 → 48 taken 1513 times.
✗ Branch 47 → 83 not taken.
✓ Branch 48 → 49 taken 1513 times.
✗ Branch 48 → 83 not taken.
✓ Branch 49 → 50 taken 1513 times.
✗ Branch 49 → 81 not taken.
1513 valueNode->nilType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1311 } else {
1312 assert_fail("Unknown value type"); // GCOV_EXCL_LINE
1313 }
1314
1315
1/2
✓ Branch 59 → 60 taken 18245 times.
✗ Branch 59 → 84 not taken.
18245 return concludeNode(valueNode);
1316 }
1317
1318 17863 std::any ASTBuilder::visitConstant(SpiceParser::ConstantContext *ctx) {
1319 17863 const auto constantNode = createNode<ConstantNode>(ctx);
1320
1321 // Enrich
1322
2/2
✓ Branch 4 → 5 taken 410 times.
✓ Branch 4 → 10 taken 17453 times.
17863 if (ctx->DOUBLE_LIT()) {
1323 410 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_DOUBLE;
1324
3/6
✓ Branch 5 → 6 taken 410 times.
✗ Branch 5 → 59 not taken.
✓ Branch 6 → 7 taken 410 times.
✗ Branch 6 → 59 not taken.
✓ Branch 7 → 8 taken 410 times.
✗ Branch 7 → 57 not taken.
410 constantNode->compileTimeValue.doubleValue = std::stod(ctx->DOUBLE_LIT()->toString());
1325
2/2
✓ Branch 11 → 12 taken 3970 times.
✓ Branch 11 → 15 taken 13483 times.
17453 } else if (ctx->INT_LIT()) {
1326 3970 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_INT;
1327 3970 constantNode->compileTimeValue.intValue = parseInt(ctx->INT_LIT());
1328
2/2
✓ Branch 16 → 17 taken 569 times.
✓ Branch 16 → 20 taken 12914 times.
13483 } else if (ctx->SHORT_LIT()) {
1329 569 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_SHORT;
1330 569 constantNode->compileTimeValue.shortValue = parseShort(ctx->SHORT_LIT());
1331
2/2
✓ Branch 21 → 22 taken 5744 times.
✓ Branch 21 → 25 taken 7170 times.
12914 } else if (ctx->LONG_LIT()) {
1332 5744 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_LONG;
1333 5744 constantNode->compileTimeValue.longValue = parseLong(ctx->LONG_LIT());
1334
2/2
✓ Branch 26 → 27 taken 2788 times.
✓ Branch 26 → 30 taken 4382 times.
7170 } else if (ctx->CHAR_LIT()) {
1335 2788 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_CHAR;
1336 2788 constantNode->compileTimeValue.charValue = parseChar(ctx->CHAR_LIT());
1337
2/2
✓ Branch 31 → 32 taken 2669 times.
✓ Branch 31 → 40 taken 1713 times.
4382 } else if (ctx->STRING_LIT()) {
1338 // Save a pointer to the string in the compile time value
1339 2669 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_STRING;
1340 2669 constantNode->compileTimeValue.stringValueOffset = resourceManager.compileTimeStringValues.size();
1341 // Add the string to the global compile time string list
1342
4/8
✓ Branch 33 → 34 taken 2669 times.
✗ Branch 33 → 64 not taken.
✓ Branch 34 → 35 taken 2669 times.
✗ Branch 34 → 64 not taken.
✓ Branch 35 → 36 taken 2669 times.
✗ Branch 35 → 62 not taken.
✓ Branch 36 → 37 taken 2669 times.
✗ Branch 36 → 60 not taken.
2669 resourceManager.compileTimeStringValues.push_back(parseString(ctx->STRING_LIT()->toString()));
1343
2/2
✓ Branch 41 → 42 taken 883 times.
✓ Branch 41 → 43 taken 830 times.
1713 } else if (ctx->TRUE()) {
1344 883 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL;
1345 883 constantNode->compileTimeValue.boolValue = true;
1346
1/2
✓ Branch 44 → 45 taken 830 times.
✗ Branch 44 → 46 not taken.
830 } else if (ctx->FALSE()) {
1347 830 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL;
1348 830 constantNode->compileTimeValue.boolValue = false;
1349 } else {
1350 assert_fail("Unknown constant type"); // GCOV_EXCL_LINE
1351 }
1352
1353
1/2
✓ Branch 53 → 54 taken 17861 times.
✗ Branch 53 → 66 not taken.
17861 return concludeNode(constantNode);
1354 }
1355
1356 16399 std::any ASTBuilder::visitFctCall(SpiceParser::FctCallContext *ctx) {
1357 16399 const auto fctCallNode = createNode<FctCallNode>(ctx);
1358
1359
2/2
✓ Branch 37 → 5 taken 79935 times.
✓ Branch 37 → 38 taken 16399 times.
96334 for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) {
1360
1/2
✓ Branch 6 → 7 taken 79935 times.
✗ Branch 6 → 8 not taken.
79935 const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree);
1361
2/2
✓ Branch 9 → 10 taken 13184 times.
✓ Branch 9 → 11 taken 66751 times.
79935 if (!terminal)
1362 13184 continue;
1363
1364
4/6
✓ Branch 11 → 12 taken 66751 times.
✗ Branch 11 → 68 not taken.
✓ Branch 12 → 13 taken 66751 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 21507 times.
✓ Branch 13 → 19 taken 45244 times.
66751 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1365
1/2
✓ Branch 14 → 15 taken 21507 times.
✗ Branch 14 → 64 not taken.
21507 const std::string fragment = terminal->toString();
1366
1/2
✓ Branch 15 → 16 taken 21507 times.
✗ Branch 15 → 62 not taken.
21507 fctCallNode->functionNameFragments.push_back(fragment);
1367
1/2
✓ Branch 16 → 17 taken 21507 times.
✗ Branch 16 → 62 not taken.
21507 fctCallNode->fqFunctionName += fragment;
1368
4/6
✓ Branch 19 → 20 taken 45244 times.
✗ Branch 19 → 68 not taken.
✓ Branch 20 → 21 taken 45244 times.
✗ Branch 20 → 68 not taken.
✓ Branch 21 → 22 taken 3017 times.
✓ Branch 21 → 27 taken 42227 times.
66751 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1369
1/2
✓ Branch 22 → 23 taken 3017 times.
✗ Branch 22 → 67 not taken.
3017 const std::string fragment = terminal->toString();
1370
1/2
✓ Branch 23 → 24 taken 3017 times.
✗ Branch 23 → 65 not taken.
3017 fctCallNode->functionNameFragments.push_back(fragment);
1371
1/2
✓ Branch 24 → 25 taken 3017 times.
✗ Branch 24 → 65 not taken.
3017 fctCallNode->fqFunctionName += fragment;
1372
4/6
✓ Branch 27 → 28 taken 42227 times.
✗ Branch 27 → 68 not taken.
✓ Branch 28 → 29 taken 42227 times.
✗ Branch 28 → 68 not taken.
✓ Branch 29 → 30 taken 62 times.
✓ Branch 29 → 31 taken 42165 times.
45244 } else if (terminal->getSymbol()->getType() == SpiceParser::SCOPE_ACCESS) {
1373
1/2
✓ Branch 30 → 35 taken 62 times.
✗ Branch 30 → 68 not taken.
62 fctCallNode->fqFunctionName += SCOPE_ACCESS_TOKEN;
1374
4/6
✓ Branch 31 → 32 taken 42165 times.
✗ Branch 31 → 68 not taken.
✓ Branch 32 → 33 taken 42165 times.
✗ Branch 32 → 68 not taken.
✓ Branch 33 → 34 taken 8063 times.
✓ Branch 33 → 35 taken 34102 times.
42165 } else if (terminal->getSymbol()->getType() == SpiceParser::DOT) {
1375
1/2
✓ Branch 34 → 35 taken 8063 times.
✗ Branch 34 → 68 not taken.
8063 fctCallNode->fqFunctionName += MEMBER_ACCESS_TOKEN;
1376 }
1377 }
1378
1379 // Visit children
1380
2/2
✓ Branch 39 → 40 taken 652 times.
✓ Branch 39 → 45 taken 15747 times.
16399 if (ctx->typeLst()) {
1381 652 fctCallNode->hasTemplateTypes = true;
1382
3/6
✓ Branch 40 → 41 taken 652 times.
✗ Branch 40 → 71 not taken.
✓ Branch 41 → 42 taken 652 times.
✗ Branch 41 → 71 not taken.
✓ Branch 42 → 43 taken 652 times.
✗ Branch 42 → 69 not taken.
652 fctCallNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1383 }
1384
2/2
✓ Branch 46 → 47 taken 12532 times.
✓ Branch 46 → 52 taken 3867 times.
16399 if (ctx->argLst()) {
1385 12532 fctCallNode->hasArgs = true;
1386
3/6
✓ Branch 47 → 48 taken 12532 times.
✗ Branch 47 → 74 not taken.
✓ Branch 48 → 49 taken 12532 times.
✗ Branch 48 → 74 not taken.
✓ Branch 49 → 50 taken 12532 times.
✗ Branch 49 → 72 not taken.
12532 fctCallNode->argLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1387 }
1388
1389
1/2
✓ Branch 58 → 59 taken 16399 times.
✗ Branch 58 → 75 not taken.
16399 return concludeNode(fctCallNode);
1390 }
1391
1392 70 std::any ASTBuilder::visitArrayInitialization(SpiceParser::ArrayInitializationContext *ctx) {
1393 70 const auto arrayInitializationNode = createNode<ArrayInitializationNode>(ctx);
1394
1395 // Visit children
1396
2/2
✓ Branch 4 → 5 taken 69 times.
✓ Branch 4 → 10 taken 1 time.
70 if (ctx->argLst())
1397
3/6
✓ Branch 5 → 6 taken 69 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 69 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 69 times.
✗ Branch 7 → 20 not taken.
69 arrayInitializationNode->itemLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1398
1399
1/2
✓ Branch 16 → 17 taken 70 times.
✗ Branch 16 → 23 not taken.
70 return concludeNode(arrayInitializationNode);
1400 }
1401
1402 223 std::any ASTBuilder::visitStructInstantiation(SpiceParser::StructInstantiationContext *ctx) {
1403 223 const auto structInstantiationNode = createNode<StructInstantiationNode>(ctx);
1404
1405 // Enrich
1406
2/2
✓ Branch 31 → 5 taken 942 times.
✓ Branch 31 → 32 taken 223 times.
1165 for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) {
1407
1/2
✓ Branch 6 → 7 taken 942 times.
✗ Branch 6 → 8 not taken.
942 const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree);
1408
2/2
✓ Branch 9 → 10 taken 227 times.
✓ Branch 9 → 11 taken 715 times.
942 if (!terminal)
1409 227 continue;
1410
1411
4/6
✓ Branch 11 → 12 taken 715 times.
✗ Branch 11 → 65 not taken.
✓ Branch 12 → 13 taken 715 times.
✗ Branch 12 → 65 not taken.
✓ Branch 13 → 14 taken 3 times.
✓ Branch 13 → 21 taken 712 times.
715 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1412
1/2
✓ Branch 14 → 15 taken 3 times.
✗ Branch 14 → 61 not taken.
3 const std::string fragment = terminal->toString();
1413
1/2
✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 59 not taken.
3 structInstantiationNode->structNameFragments.push_back(fragment);
1414
2/4
✓ Branch 16 → 17 taken 3 times.
✗ Branch 16 → 58 not taken.
✓ Branch 17 → 18 taken 3 times.
✗ Branch 17 → 56 not taken.
3 structInstantiationNode->fqStructName += fragment + SCOPE_ACCESS_TOKEN;
1415
4/6
✓ Branch 21 → 22 taken 712 times.
✗ Branch 21 → 65 not taken.
✓ Branch 22 → 23 taken 712 times.
✗ Branch 22 → 65 not taken.
✓ Branch 23 → 24 taken 223 times.
✓ Branch 23 → 29 taken 489 times.
715 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1416
1/2
✓ Branch 24 → 25 taken 223 times.
✗ Branch 24 → 64 not taken.
223 const std::string fragment = terminal->toString();
1417
1/2
✓ Branch 25 → 26 taken 223 times.
✗ Branch 25 → 62 not taken.
223 structInstantiationNode->structNameFragments.push_back(fragment);
1418
1/2
✓ Branch 26 → 27 taken 223 times.
✗ Branch 26 → 62 not taken.
223 structInstantiationNode->fqStructName += fragment;
1419 223 }
1420 }
1421
1422 // Visit children
1423
2/2
✓ Branch 33 → 34 taken 20 times.
✓ Branch 33 → 39 taken 203 times.
223 if (ctx->typeLst()) {
1424 20 structInstantiationNode->hasTemplateTypes = true;
1425
3/6
✓ Branch 34 → 35 taken 20 times.
✗ Branch 34 → 68 not taken.
✓ Branch 35 → 36 taken 20 times.
✗ Branch 35 → 68 not taken.
✓ Branch 36 → 37 taken 20 times.
✗ Branch 36 → 66 not taken.
20 structInstantiationNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1426 }
1427
2/2
✓ Branch 40 → 41 taken 207 times.
✓ Branch 40 → 46 taken 16 times.
223 if (ctx->argLst())
1428
3/6
✓ Branch 41 → 42 taken 207 times.
✗ Branch 41 → 71 not taken.
✓ Branch 42 → 43 taken 207 times.
✗ Branch 42 → 71 not taken.
✓ Branch 43 → 44 taken 207 times.
✗ Branch 43 → 69 not taken.
207 structInstantiationNode->fieldLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1429
1430
1/2
✓ Branch 52 → 53 taken 223 times.
✗ Branch 52 → 72 not taken.
223 return concludeNode(structInstantiationNode);
1431 }
1432
1433 12 std::any ASTBuilder::visitLambdaFunc(SpiceParser::LambdaFuncContext *ctx) {
1434 12 const auto lambdaFuncNode = createNode<LambdaFuncNode>(ctx);
1435
1436 // Visit children
1437
3/6
✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 12 times.
✗ Branch 4 → 37 not taken.
✓ Branch 5 → 6 taken 12 times.
✗ Branch 5 → 35 not taken.
12 lambdaFuncNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1438
2/2
✓ Branch 8 → 9 taken 8 times.
✓ Branch 8 → 14 taken 4 times.
12 if (ctx->paramLst()) {
1439 8 lambdaFuncNode->hasParams = true;
1440
3/6
✓ Branch 9 → 10 taken 8 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 8 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 8 times.
✗ Branch 11 → 38 not taken.
8 lambdaFuncNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1441 }
1442
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 21 taken 12 times.
12 if (ctx->lambdaAttr())
1443 lambdaFuncNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr()));
1444
3/6
✓ Branch 21 → 22 taken 12 times.
✗ Branch 21 → 46 not taken.
✓ Branch 22 → 23 taken 12 times.
✗ Branch 22 → 46 not taken.
✓ Branch 23 → 24 taken 12 times.
✗ Branch 23 → 44 not taken.
12 lambdaFuncNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
1445
1446
1/2
✓ Branch 31 → 32 taken 12 times.
✗ Branch 31 → 47 not taken.
12 return concludeNode(lambdaFuncNode);
1447 }
1448
1449 27 std::any ASTBuilder::visitLambdaProc(SpiceParser::LambdaProcContext *ctx) {
1450 27 const auto lambdaProcNode = createNode<LambdaProcNode>(ctx);
1451
1452 // Visit children
1453
2/2
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 10 taken 20 times.
27 if (ctx->paramLst()) {
1454 7 lambdaProcNode->hasParams = true;
1455
3/6
✓ Branch 5 → 6 taken 7 times.
✗ Branch 5 → 33 not taken.
✓ Branch 6 → 7 taken 7 times.
✗ Branch 6 → 33 not taken.
✓ Branch 7 → 8 taken 7 times.
✗ Branch 7 → 31 not taken.
7 lambdaProcNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1456 }
1457
2/2
✓ Branch 11 → 12 taken 16 times.
✓ Branch 11 → 17 taken 11 times.
27 if (ctx->lambdaAttr())
1458
3/6
✓ Branch 12 → 13 taken 16 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 16 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 16 times.
✗ Branch 14 → 34 not taken.
16 lambdaProcNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr()));
1459
3/6
✓ Branch 17 → 18 taken 27 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 27 times.
✗ Branch 18 → 39 not taken.
✓ Branch 19 → 20 taken 27 times.
✗ Branch 19 → 37 not taken.
27 lambdaProcNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
1460
1461
1/2
✓ Branch 27 → 28 taken 27 times.
✗ Branch 27 → 40 not taken.
27 return concludeNode(lambdaProcNode);
1462 }
1463
1464 1 std::any ASTBuilder::visitLambdaExpr(SpiceParser::LambdaExprContext *ctx) {
1465 1 const auto lambdaExprNode = createNode<LambdaExprNode>(ctx);
1466
1467 // Visit children
1468
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 10 not taken.
1 if (ctx->paramLst()) {
1469 1 lambdaExprNode->hasParams = true;
1470
3/6
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 26 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 26 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 24 not taken.
1 lambdaExprNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1471 }
1472
3/6
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 29 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 27 not taken.
1 lambdaExprNode->lambdaExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
1473
1474
1/2
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 30 not taken.
1 return concludeNode(lambdaExprNode);
1475 }
1476
1477 48155 std::any ASTBuilder::visitDataType(SpiceParser::DataTypeContext *ctx) {
1478 48155 const auto dataTypeNode = createNode<DataTypeNode>(ctx);
1479
1480 // Visit children
1481
2/2
✓ Branch 4 → 5 taken 19200 times.
✓ Branch 4 → 10 taken 28955 times.
48155 if (ctx->qualifierLst())
1482
4/6
✓ Branch 5 → 6 taken 19200 times.
✗ Branch 5 → 74 not taken.
✓ Branch 6 → 7 taken 19199 times.
✓ Branch 6 → 74 taken 1 time.
✓ Branch 7 → 8 taken 19199 times.
✗ Branch 7 → 72 not taken.
19200 dataTypeNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
1483
3/6
✓ Branch 10 → 11 taken 48154 times.
✗ Branch 10 → 77 not taken.
✓ Branch 11 → 12 taken 48154 times.
✗ Branch 11 → 77 not taken.
✓ Branch 12 → 13 taken 48154 times.
✗ Branch 12 → 75 not taken.
48154 dataTypeNode->baseDataType = std::any_cast<BaseDataTypeNode *>(visit(ctx->baseDataType()));
1484
1485 // Enrich
1486
2/2
✓ Branch 61 → 15 taken 79336 times.
✓ Branch 61 → 62 taken 48154 times.
127490 for (size_t i = 0; i < ctx->children.size(); i++) {
1487 79336 antlr4::tree::ParseTree *subTree = ctx->children.at(i);
1488
1/2
✓ Branch 16 → 17 taken 79336 times.
✗ Branch 16 → 18 not taken.
79336 auto terminal = dynamic_cast<TerminalNode *>(subTree);
1489
2/2
✓ Branch 19 → 20 taken 67353 times.
✓ Branch 19 → 21 taken 11983 times.
79336 if (!terminal)
1490 67353 continue;
1491
1492
2/2
✓ Branch 23 → 24 taken 6304 times.
✓ Branch 23 → 26 taken 5679 times.
11983 if (terminal->getSymbol()->getType() == SpiceParser::MUL) {
1493
1/2
✓ Branch 24 → 25 taken 6304 times.
✗ Branch 24 → 78 not taken.
6304 dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_PTR, false, 0);
1494
2/2
✓ Branch 28 → 29 taken 5578 times.
✓ Branch 28 → 31 taken 101 times.
5679 } else if (terminal->getSymbol()->getType() == SpiceParser::BITWISE_AND) {
1495
1/2
✓ Branch 29 → 30 taken 5578 times.
✗ Branch 29 → 81 not taken.
5578 dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_REF, false, 0);
1496
1/2
✓ Branch 33 → 34 taken 101 times.
✗ Branch 33 → 59 not taken.
101 } else if (terminal->getSymbol()->getType() == SpiceParser::LBRACKET) {
1497 101 i++; // Consume LBRACKET
1498
1/2
✓ Branch 34 → 35 taken 101 times.
✗ Branch 34 → 93 not taken.
101 subTree = ctx->children.at(i);
1499
1/2
✓ Branch 35 → 36 taken 101 times.
✗ Branch 35 → 37 not taken.
101 terminal = dynamic_cast<TerminalNode *>(subTree);
1500 101 bool hasSize = false;
1501 101 unsigned int hardCodedSize = 0;
1502 101 std::string sizeVarName;
1503
4/6
✓ Branch 39 → 40 taken 101 times.
✗ Branch 39 → 91 not taken.
✓ Branch 40 → 41 taken 101 times.
✗ Branch 40 → 91 not taken.
✓ Branch 41 → 42 taken 47 times.
✓ Branch 41 → 47 taken 54 times.
101 if (terminal->getSymbol()->getType() == SpiceParser::INT_LIT) {
1504 47 hasSize = true;
1505
3/6
✓ Branch 42 → 43 taken 47 times.
✗ Branch 42 → 86 not taken.
✓ Branch 43 → 44 taken 47 times.
✗ Branch 43 → 86 not taken.
✓ Branch 44 → 45 taken 47 times.
✗ Branch 44 → 84 not taken.
47 hardCodedSize = std::stoi(terminal->getSymbol()->getText());
1506 47 i++; // Consume INT_LIT
1507
4/6
✓ Branch 47 → 48 taken 54 times.
✗ Branch 47 → 91 not taken.
✓ Branch 48 → 49 taken 54 times.
✗ Branch 48 → 91 not taken.
✓ Branch 49 → 50 taken 24 times.
✓ Branch 49 → 54 taken 30 times.
54 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1508 24 hasSize = true;
1509
1/2
✓ Branch 50 → 51 taken 24 times.
✗ Branch 50 → 87 not taken.
24 sizeVarName = getIdentifier(terminal, true);
1510 24 i++; // Consume TYPE_IDENTIFIER
1511 }
1512
1/2
✓ Branch 55 → 56 taken 101 times.
✗ Branch 55 → 88 not taken.
101 dataTypeNode->tmQueue.push({DataTypeNode::TypeModifierType::TYPE_ARRAY, hasSize, hardCodedSize, sizeVarName});
1513 101 }
1514 }
1515
1516
1/2
✓ Branch 68 → 69 taken 48154 times.
✗ Branch 68 → 94 not taken.
48154 return concludeNode(dataTypeNode);
1517
1/2
✓ Branch 54 → 55 taken 101 times.
✗ Branch 54 → 90 not taken.
101 }
1518
1519 48154 std::any ASTBuilder::visitBaseDataType(SpiceParser::BaseDataTypeContext *ctx) {
1520 48154 const auto baseDataTypeNode = createNode<BaseDataTypeNode>(ctx);
1521
1522 // Enrich
1523
2/2
✓ Branch 4 → 5 taken 411 times.
✓ Branch 4 → 6 taken 47743 times.
48154 if (ctx->TYPE_DOUBLE()) {
1524 411 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DOUBLE;
1525
2/2
✓ Branch 7 → 8 taken 3032 times.
✓ Branch 7 → 9 taken 44711 times.
47743 } else if (ctx->TYPE_INT()) {
1526 3032 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_INT;
1527
2/2
✓ Branch 10 → 11 taken 977 times.
✓ Branch 10 → 12 taken 43734 times.
44711 } else if (ctx->TYPE_SHORT()) {
1528 977 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_SHORT;
1529
2/2
✓ Branch 13 → 14 taken 9101 times.
✓ Branch 13 → 15 taken 34633 times.
43734 } else if (ctx->TYPE_LONG()) {
1530 9101 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_LONG;
1531
2/2
✓ Branch 16 → 17 taken 2765 times.
✓ Branch 16 → 18 taken 31868 times.
34633 } else if (ctx->TYPE_BYTE()) {
1532 2765 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BYTE;
1533
2/2
✓ Branch 19 → 20 taken 5186 times.
✓ Branch 19 → 21 taken 26682 times.
31868 } else if (ctx->TYPE_CHAR()) {
1534 5186 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CHAR;
1535
2/2
✓ Branch 22 → 23 taken 4038 times.
✓ Branch 22 → 24 taken 22644 times.
26682 } else if (ctx->TYPE_STRING()) {
1536 4038 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_STRING;
1537
2/2
✓ Branch 25 → 26 taken 3874 times.
✓ Branch 25 → 27 taken 18770 times.
22644 } else if (ctx->TYPE_BOOL()) {
1538 3874 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BOOL;
1539
2/2
✓ Branch 28 → 29 taken 462 times.
✓ Branch 28 → 30 taken 18308 times.
18770 } else if (ctx->TYPE_DYN()) {
1540 462 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DYN;
1541
2/2
✓ Branch 31 → 32 taken 18220 times.
✓ Branch 31 → 37 taken 88 times.
18308 } else if (ctx->customDataType()) {
1542 18220 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CUSTOM;
1543
3/6
✓ Branch 32 → 33 taken 18220 times.
✗ Branch 32 → 57 not taken.
✓ Branch 33 → 34 taken 18220 times.
✗ Branch 33 → 57 not taken.
✓ Branch 34 → 35 taken 18220 times.
✗ Branch 34 → 55 not taken.
18220 baseDataTypeNode->customDataType = std::any_cast<CustomDataTypeNode *>(visit(ctx->customDataType()));
1544
1/2
✓ Branch 38 → 39 taken 88 times.
✗ Branch 38 → 44 not taken.
88 } else if (ctx->functionDataType()) {
1545 88 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_FUNCTION;
1546
3/6
✓ Branch 39 → 40 taken 88 times.
✗ Branch 39 → 60 not taken.
✓ Branch 40 → 41 taken 88 times.
✗ Branch 40 → 60 not taken.
✓ Branch 41 → 42 taken 88 times.
✗ Branch 41 → 58 not taken.
88 baseDataTypeNode->functionDataType = std::any_cast<FunctionDataTypeNode *>(visit(ctx->functionDataType()));
1547 } else {
1548 assert_fail("Unknown base data type");
1549 }
1550
1551
1/2
✓ Branch 51 → 52 taken 48154 times.
✗ Branch 51 → 61 not taken.
48154 return concludeNode(baseDataTypeNode);
1552 }
1553
1554 18220 std::any ASTBuilder::visitCustomDataType(SpiceParser::CustomDataTypeContext *ctx) {
1555 18220 const auto customDataTypeNode = createNode<CustomDataTypeNode>(ctx);
1556
1557 // Enrich
1558
2/2
✓ Branch 31 → 5 taken 26182 times.
✓ Branch 31 → 32 taken 18220 times.
44402 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1559
1/2
✓ Branch 6 → 7 taken 26182 times.
✗ Branch 6 → 8 not taken.
26182 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1560
2/2
✓ Branch 9 → 10 taken 2636 times.
✓ Branch 9 → 11 taken 23546 times.
26182 if (!terminal)
1561 2636 continue;
1562
1563
4/6
✓ Branch 11 → 12 taken 23546 times.
✗ Branch 11 → 58 not taken.
✓ Branch 12 → 13 taken 23546 times.
✗ Branch 12 → 58 not taken.
✓ Branch 13 → 14 taken 27 times.
✓ Branch 13 → 21 taken 23519 times.
23546 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1564
1/2
✓ Branch 14 → 15 taken 27 times.
✗ Branch 14 → 54 not taken.
27 const std::string fragment = terminal->toString();
1565
1/2
✓ Branch 15 → 16 taken 27 times.
✗ Branch 15 → 52 not taken.
27 customDataTypeNode->typeNameFragments.push_back(fragment);
1566
2/4
✓ Branch 16 → 17 taken 27 times.
✗ Branch 16 → 51 not taken.
✓ Branch 17 → 18 taken 27 times.
✗ Branch 17 → 49 not taken.
27 customDataTypeNode->fqTypeName += fragment + SCOPE_ACCESS_TOKEN;
1567
4/6
✓ Branch 21 → 22 taken 23519 times.
✗ Branch 21 → 58 not taken.
✓ Branch 22 → 23 taken 23519 times.
✗ Branch 22 → 58 not taken.
✓ Branch 23 → 24 taken 18220 times.
✓ Branch 23 → 29 taken 5299 times.
23546 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1568
1/2
✓ Branch 24 → 25 taken 18220 times.
✗ Branch 24 → 57 not taken.
18220 const std::string fragment = terminal->toString();
1569
1/2
✓ Branch 25 → 26 taken 18220 times.
✗ Branch 25 → 55 not taken.
18220 customDataTypeNode->typeNameFragments.push_back(fragment);
1570
1/2
✓ Branch 26 → 27 taken 18220 times.
✗ Branch 26 → 55 not taken.
18220 customDataTypeNode->fqTypeName += fragment;
1571 18220 }
1572 }
1573
1574 // Visit children
1575
2/2
✓ Branch 33 → 34 taken 2636 times.
✓ Branch 33 → 39 taken 15584 times.
18220 if (ctx->typeLst())
1576
3/6
✓ Branch 34 → 35 taken 2636 times.
✗ Branch 34 → 61 not taken.
✓ Branch 35 → 36 taken 2636 times.
✗ Branch 35 → 61 not taken.
✓ Branch 36 → 37 taken 2636 times.
✗ Branch 36 → 59 not taken.
2636 customDataTypeNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1577
1578
1/2
✓ Branch 45 → 46 taken 18220 times.
✗ Branch 45 → 62 not taken.
18220 return concludeNode(customDataTypeNode);
1579 }
1580
1581 88 std::any ASTBuilder::visitFunctionDataType(SpiceParser::FunctionDataTypeContext *ctx) {
1582 88 const auto functionDataTypeNode = createNode<FunctionDataTypeNode>(ctx);
1583
1584 // Enrich
1585
2/2
✓ Branch 4 → 5 taken 24 times.
✓ Branch 4 → 11 taken 64 times.
88 if (ctx->dataType()) {
1586 24 functionDataTypeNode->isFunction = ctx->dataType();
1587
3/6
✓ Branch 6 → 7 taken 24 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 24 times.
✗ Branch 7 → 30 not taken.
✓ Branch 8 → 9 taken 24 times.
✗ Branch 8 → 28 not taken.
24 functionDataTypeNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1588 }
1589
2/2
✓ Branch 12 → 13 taken 50 times.
✓ Branch 12 → 18 taken 38 times.
88 if (ctx->typeLst())
1590
3/6
✓ Branch 13 → 14 taken 50 times.
✗ Branch 13 → 33 not taken.
✓ Branch 14 → 15 taken 50 times.
✗ Branch 14 → 33 not taken.
✓ Branch 15 → 16 taken 50 times.
✗ Branch 15 → 31 not taken.
50 functionDataTypeNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1591
1592
1/2
✓ Branch 24 → 25 taken 88 times.
✗ Branch 24 → 34 not taken.
88 return concludeNode(functionDataTypeNode);
1593 }
1594
1595 7770 std::any ASTBuilder::visitAssignOp(SpiceParser::AssignOpContext *ctx) {
1596 7770 const auto assignExprNode = resumeForExpansion<AssignExprNode>();
1597
1598 // Extract assign operator
1599
2/2
✓ Branch 13 → 14 taken 6895 times.
✓ Branch 13 → 15 taken 875 times.
7770 if (ctx->ASSIGN())
1600 6895 assignExprNode->op = AssignExprNode::AssignOp::OP_ASSIGN;
1601
2/2
✓ Branch 16 → 17 taken 375 times.
✓ Branch 16 → 18 taken 500 times.
875 else if (ctx->PLUS_EQUAL())
1602 375 assignExprNode->op = AssignExprNode::AssignOp::OP_PLUS_EQUAL;
1603
2/2
✓ Branch 19 → 20 taken 65 times.
✓ Branch 19 → 21 taken 435 times.
500 else if (ctx->MINUS_EQUAL())
1604 65 assignExprNode->op = AssignExprNode::AssignOp::OP_MINUS_EQUAL;
1605
2/2
✓ Branch 22 → 23 taken 41 times.
✓ Branch 22 → 24 taken 394 times.
435 else if (ctx->MUL_EQUAL())
1606 41 assignExprNode->op = AssignExprNode::AssignOp::OP_MUL_EQUAL;
1607
2/2
✓ Branch 25 → 26 taken 43 times.
✓ Branch 25 → 27 taken 351 times.
394 else if (ctx->DIV_EQUAL())
1608 43 assignExprNode->op = AssignExprNode::AssignOp::OP_DIV_EQUAL;
1609
2/2
✓ Branch 28 → 29 taken 7 times.
✓ Branch 28 → 30 taken 344 times.
351 else if (ctx->REM_EQUAL())
1610 7 assignExprNode->op = AssignExprNode::AssignOp::OP_REM_EQUAL;
1611
2/2
✓ Branch 31 → 32 taken 2 times.
✓ Branch 31 → 33 taken 342 times.
344 else if (ctx->SHL_EQUAL())
1612 2 assignExprNode->op = AssignExprNode::AssignOp::OP_SHL_EQUAL;
1613
2/2
✓ Branch 34 → 35 taken 3 times.
✓ Branch 34 → 36 taken 339 times.
342 else if (ctx->SHR_EQUAL())
1614 3 assignExprNode->op = AssignExprNode::AssignOp::OP_SHR_EQUAL;
1615
2/2
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 39 taken 338 times.
339 else if (ctx->AND_EQUAL())
1616 1 assignExprNode->op = AssignExprNode::AssignOp::OP_AND_EQUAL;
1617
2/2
✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 42 taken 337 times.
338 else if (ctx->OR_EQUAL())
1618 1 assignExprNode->op = AssignExprNode::AssignOp::OP_OR_EQUAL;
1619
1/2
✓ Branch 43 → 44 taken 337 times.
✗ Branch 43 → 45 not taken.
337 else if (ctx->XOR_EQUAL())
1620 337 assignExprNode->op = AssignExprNode::AssignOp::OP_XOR_EQUAL;
1621 else
1622 assert_fail("Unknown assign operator");
1623
1624
1/2
✓ Branch 46 → 47 taken 7770 times.
✗ Branch 46 → 49 not taken.
7770 return nullptr;
1625 }
1626
1627 1767 std::any ASTBuilder::visitOverloadableOp(SpiceParser::OverloadableOpContext *ctx) {
1628 1767 const auto fctNameNode = resumeForExpansion<FctNameNode>();
1629
1630 // Enrich
1631
2/2
✓ Branch 13 → 14 taken 92 times.
✓ Branch 13 → 15 taken 1675 times.
1767 if (ctx->PLUS())
1632 92 fctNameNode->name = OP_FCT_PLUS;
1633
2/2
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 18 taken 1674 times.
1675 else if (ctx->MINUS())
1634 1 fctNameNode->name = OP_FCT_MINUS;
1635
2/2
✓ Branch 19 → 20 taken 183 times.
✓ Branch 19 → 21 taken 1491 times.
1674 else if (ctx->MUL())
1636 183 fctNameNode->name = OP_FCT_MUL;
1637
2/2
✓ Branch 22 → 23 taken 22 times.
✓ Branch 22 → 24 taken 1469 times.
1491 else if (ctx->DIV())
1638 22 fctNameNode->name = OP_FCT_DIV;
1639
2/2
✓ Branch 25 → 26 taken 419 times.
✓ Branch 25 → 27 taken 1050 times.
1469 else if (ctx->EQUAL())
1640 419 fctNameNode->name = OP_FCT_EQUAL;
1641
2/2
✓ Branch 28 → 29 taken 416 times.
✓ Branch 28 → 30 taken 634 times.
1050 else if (ctx->NOT_EQUAL())
1642 416 fctNameNode->name = OP_FCT_NOT_EQUAL;
1643
3/4
✓ Branch 30 → 31 taken 634 times.
✗ Branch 30 → 67 not taken.
✓ Branch 33 → 34 taken 13 times.
✓ Branch 33 → 35 taken 621 times.
634 else if (ctx->LESS().size() == 2)
1644 13 fctNameNode->name = OP_FCT_SHL;
1645
3/4
✓ Branch 35 → 36 taken 621 times.
✗ Branch 35 → 68 not taken.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 38 → 40 taken 620 times.
621 else if (ctx->GREATER().size() == 2)
1646 1 fctNameNode->name = OP_FCT_SHR;
1647
2/2
✓ Branch 41 → 42 taken 134 times.
✓ Branch 41 → 43 taken 486 times.
620 else if (ctx->PLUS_EQUAL())
1648 134 fctNameNode->name = OP_FCT_PLUS_EQUAL;
1649
2/2
✓ Branch 44 → 45 taken 43 times.
✓ Branch 44 → 46 taken 443 times.
486 else if (ctx->MINUS_EQUAL())
1650 43 fctNameNode->name = OP_FCT_MINUS_EQUAL;
1651
2/2
✓ Branch 47 → 48 taken 92 times.
✓ Branch 47 → 49 taken 351 times.
443 else if (ctx->MUL_EQUAL())
1652 92 fctNameNode->name = OP_FCT_MUL_EQUAL;
1653
2/2
✓ Branch 50 → 51 taken 22 times.
✓ Branch 50 → 52 taken 329 times.
351 else if (ctx->DIV_EQUAL())
1654 22 fctNameNode->name = OP_FCT_DIV_EQUAL;
1655
2/2
✓ Branch 53 → 54 taken 52 times.
✓ Branch 53 → 55 taken 277 times.
329 else if (ctx->PLUS_PLUS())
1656 52 fctNameNode->name = OP_FCT_POSTFIX_PLUS_PLUS;
1657
2/2
✓ Branch 56 → 57 taken 43 times.
✓ Branch 56 → 58 taken 234 times.
277 else if (ctx->MINUS_MINUS())
1658 43 fctNameNode->name = OP_FCT_POSTFIX_MINUS_MINUS;
1659
1/2
✓ Branch 59 → 60 taken 234 times.
✗ Branch 59 → 61 not taken.
234 else if (ctx->LBRACKET())
1660 234 fctNameNode->name = OP_FCT_SUBSCRIPT;
1661 else
1662 assert_fail("Unsupported overloadable operator"); // GCOV_EXCL_LINE
1663
1664 1767 fctNameNode->fqName = fctNameNode->name;
1665 1767 fctNameNode->nameFragments.push_back(fctNameNode->name);
1666
1667
1/2
✓ Branch 64 → 65 taken 1767 times.
✗ Branch 64 → 69 not taken.
1767 return nullptr;
1668 }
1669
1670 4379 int32_t ASTBuilder::parseInt(TerminalNode *terminal) {
1671 8758 const NumericParserCallback<int32_t> cb = [](const std::string &substr, short base, bool isSigned) -> int32_t {
1672 // Prepare limits
1673
2/2
✓ Branch 2 → 3 taken 4372 times.
✓ Branch 2 → 4 taken 7 times.
4379 const int64_t upperLimit = isSigned ? INT32_MAX : UINT32_MAX;
1674
2/2
✓ Branch 5 → 6 taken 4372 times.
✓ Branch 5 → 7 taken 7 times.
4379 const int64_t lowerLimit = isSigned ? INT32_MIN : 0;
1675 // Parse number and check for limits
1676 4379 const int64_t number = std::stoll(substr, nullptr, base);
1677
2/4
✓ Branch 9 → 10 taken 4378 times.
✗ Branch 9 → 11 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 4378 times.
4378 if (number < lowerLimit || number > upperLimit)
1678 throw std::out_of_range("Number out of range");
1679 4378 return static_cast<int32_t>(number);
1680 4379 };
1681
2/2
✓ Branch 3 → 4 taken 4378 times.
✓ Branch 3 → 8 taken 1 time.
8757 return parseNumeric(terminal, cb);
1682 4379 }
1683
1684 569 int16_t ASTBuilder::parseShort(TerminalNode *terminal) {
1685 1138 const NumericParserCallback<int16_t> cb = [](const std::string &substr, short base, bool isSigned) -> int16_t {
1686 // Prepare limits
1687
2/2
✓ Branch 2 → 3 taken 235 times.
✓ Branch 2 → 4 taken 334 times.
569 const int64_t upperLimit = isSigned ? INT16_MAX : UINT16_MAX;
1688
2/2
✓ Branch 5 → 6 taken 235 times.
✓ Branch 5 → 7 taken 334 times.
569 const int64_t lowerLimit = isSigned ? INT16_MIN : 0;
1689 // Parse number and check for limits
1690 569 const int64_t number = std::stoll(substr, nullptr, base);
1691
2/4
✓ Branch 9 → 10 taken 569 times.
✗ Branch 9 → 11 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 569 times.
569 if (number < lowerLimit || number > upperLimit)
1692 throw std::out_of_range("Number out of range");
1693 569 return static_cast<int16_t>(number);
1694 569 };
1695
1/2
✓ Branch 3 → 4 taken 569 times.
✗ Branch 3 → 8 not taken.
1138 return parseNumeric(terminal, cb);
1696 569 }
1697
1698 5744 int64_t ASTBuilder::parseLong(TerminalNode *terminal) {
1699 11488 const NumericParserCallback<int64_t> cb = [](const std::string &substr, short base, bool isSigned) -> int64_t {
1700
2/2
✓ Branch 2 → 3 taken 5602 times.
✓ Branch 2 → 5 taken 142 times.
5744 return isSigned ? std::stoll(substr, nullptr, base) : static_cast<int64_t>(std::stoull(substr, nullptr, base));
1701 5744 };
1702
1/2
✓ Branch 3 → 4 taken 5744 times.
✗ Branch 3 → 8 not taken.
11488 return parseNumeric(terminal, cb);
1703 5744 }
1704
1705 2788 int8_t ASTBuilder::parseChar(TerminalNode *terminal) const {
1706
1/2
✓ Branch 2 → 3 taken 2788 times.
✗ Branch 2 → 59 not taken.
2788 const std::string input = terminal->toString();
1707
2/2
✓ Branch 4 → 5 taken 1752 times.
✓ Branch 4 → 7 taken 1036 times.
2788 if (input.length() == 3) // Normal char literals
1708 1752 return input[1];
1709
1710
3/6
✓ Branch 8 → 9 taken 1036 times.
✗ Branch 8 → 12 not taken.
✓ Branch 10 → 11 taken 1036 times.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 1036 times.
✗ Branch 13 → 34 not taken.
1036 if (input.length() == 4 && input[1] == '\\') { // Char literals with escape sequence
1711
7/11
✓ Branch 15 → 16 taken 5 times.
✗ Branch 15 → 17 not taken.
✓ Branch 15 → 18 taken 11 times.
✓ Branch 15 → 19 taken 107 times.
✓ Branch 15 → 20 taken 91 times.
✓ Branch 15 → 21 taken 91 times.
✗ Branch 15 → 22 not taken.
✗ Branch 15 → 23 not taken.
✗ Branch 15 → 24 not taken.
✓ Branch 15 → 25 taken 730 times.
✓ Branch 15 → 26 taken 1 time.
1036 switch (input[2]) {
1712 5 case '\'':
1713 5 return '\'';
1714 case '"':
1715 return '\"';
1716 11 case '\\':
1717 11 return '\\';
1718 107 case 'n':
1719 107 return '\n';
1720 91 case 'r':
1721 91 return '\r';
1722 91 case 't':
1723 91 return '\t';
1724 case 'b':
1725 return '\b';
1726 case 'f':
1727 return '\f';
1728 case 'v':
1729 return '\v';
1730 730 case '0':
1731 730 return '\0';
1732 1 default:
1733
2/4
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 50 not taken.
✓ Branch 27 → 28 taken 1 time.
✗ Branch 27 → 50 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1734
2/4
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 47 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 44 not taken.
1 throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid escape sequence " + input);
1735 }
1736 }
1737
1738 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1739 throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid char literal " + input);
1740 2788 }
1741
1742 2669 std::string ASTBuilder::parseString(std::string input) {
1743
1/2
✓ Branch 3 → 4 taken 2669 times.
✗ Branch 3 → 9 not taken.
2669 input = input.substr(1, input.size() - 2);
1744 2669 replaceEscapeChars(input);
1745 2669 return input;
1746 }
1747
1748 10692 template <typename T> T ASTBuilder::parseNumeric(TerminalNode *terminal, const NumericParserCallback<T> &cb) {
1749
3/6
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 5744 times.
✗ Branch 2 → 87 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 569 times.
✗ Branch 2 → 87 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 4379 times.
✗ Branch 2 → 87 not taken.
10692 const std::string input = terminal->toString();
1750
1751 // Set to signed if the input string does not end with 'u'
1752
12/18
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 4 → 5 taken 5744 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 5744 times.
✗ Branch 6 → 9 not taken.
✓ Branch 8 → 9 taken 142 times.
✓ Branch 8 → 10 taken 5602 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 4 → 5 taken 569 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 235 times.
✓ Branch 6 → 9 taken 334 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 235 times.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 4 → 5 taken 4372 times.
✓ Branch 4 → 9 taken 7 times.
✓ Branch 6 → 7 taken 4372 times.
✗ Branch 6 → 9 not taken.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 4372 times.
10692 const bool isUnsigned = input.ends_with('u') || input.ends_with("us") || input.ends_with("ul");
1753
1754 try {
1755
6/6
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 12 → 13 taken 1198 times.
✓ Branch 12 → 30 taken 4546 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 12 → 13 taken 485 times.
✓ Branch 12 → 30 taken 84 times.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 12 → 13 taken 511 times.
✓ Branch 12 → 30 taken 3868 times.
10692 if (input.length() >= 3) {
1756
6/6
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 14 → 15 taken 46 times.
✓ Branch 14 → 30 taken 1152 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 14 → 15 taken 109 times.
✓ Branch 14 → 30 taken 376 times.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 14 → 15 taken 199 times.
✓ Branch 14 → 30 taken 312 times.
2194 if (input[0] == '0') {
1757
3/6
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 15 → 16 taken 46 times.
✗ Branch 15 → 37 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 15 → 16 taken 109 times.
✗ Branch 15 → 37 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 15 → 16 taken 199 times.
✗ Branch 15 → 37 not taken.
354 const std::string subStr = input.substr(2);
1758
5/15
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✓ Branch 17 → 22 taken 38 times.
✗ Branch 17 → 24 not taken.
✓ Branch 17 → 26 taken 8 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✗ Branch 17 → 22 not taken.
✓ Branch 17 → 24 taken 108 times.
✓ Branch 17 → 26 taken 1 time.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✗ Branch 17 → 22 not taken.
✓ Branch 17 → 24 taken 199 times.
✗ Branch 17 → 26 not taken.
354 switch (input[1]) {
1759 case 'd': // fall-through
1760 case 'D':
1761 return cb(subStr, 10, !isUnsigned);
1762 case 'b': // fall-through
1763 case 'B':
1764 return cb(subStr, 2, !isUnsigned);
1765 38 case 'h': // fall-through
1766 case 'H': // fall-through
1767 case 'x': // fall-through
1768 case 'X':
1769
1/6
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 22 → 23 taken 38 times.
✗ Branch 22 → 35 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 35 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 35 not taken.
38 return cb(subStr, 16, !isUnsigned);
1770 307 case 'o': // fall-through
1771 case 'O':
1772
2/6
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 35 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 24 → 25 taken 108 times.
✗ Branch 24 → 35 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 24 → 25 taken 199 times.
✗ Branch 24 → 35 not taken.
307 return cb(subStr, 8, !isUnsigned);
1773 9 default: // default is decimal
1774
2/6
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 26 → 27 taken 8 times.
✗ Branch 26 → 35 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 35 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 35 not taken.
9 return cb(input, 10, !isUnsigned);
1775 }
1776 354 }
1777 }
1778
4/6
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 30 → 31 taken 5698 times.
✗ Branch 30 → 38 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 30 → 31 taken 460 times.
✗ Branch 30 → 38 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 30 → 31 taken 4179 times.
✓ Branch 30 → 38 taken 1 time.
10338 return cb(input, 10, !isUnsigned);
1779
1/9
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 38 → 51 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 38 → 51 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 1 time.
✗ Branch 38 → 51 not taken.
2 } catch (std::out_of_range &) {
1780
2/12
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 70 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 70 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 70 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 70 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 70 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 70 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1781
2/12
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 64 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 61 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 64 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 61 not taken.
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 64 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 61 not taken.
3 throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "The provided number is out of range");
1782 } catch (std::invalid_argument &) {
1783 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1784 throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "You tried to parse '" + input + "' as an integer, but it was no integer");
1785 }
1786 10692 }
1787
1788 3525 void ASTBuilder::replaceEscapeChars(std::string &input) {
1789 const std::unordered_map<char, char> escapeMap = {
1790 {'a', '\a'}, {'b', '\b'}, {'f', '\f'}, {'n', '\n'}, {'r', '\r'}, {'t', '\t'},
1791 {'v', '\v'}, {'\\', '\\'}, {'?', '\?'}, {'\'', '\''}, {'"', '\"'},
1792
1/2
✓ Branch 4 → 5 taken 3525 times.
✗ Branch 4 → 40 not taken.
7050 };
1793
1794 3525 size_t writeIndex = 0;
1795 3525 size_t readIndex = 0;
1796 3525 const size_t len = input.length();
1797
1798
2/2
✓ Branch 36 → 8 taken 53709 times.
✓ Branch 36 → 37 taken 3525 times.
57234 while (readIndex < len) {
1799 53709 const char c = input[readIndex];
1800
3/4
✓ Branch 9 → 10 taken 697 times.
✓ Branch 9 → 33 taken 53012 times.
✓ Branch 10 → 11 taken 697 times.
✗ Branch 10 → 33 not taken.
53709 if (c == '\\' && readIndex + 1 < len) {
1801 697 char next = input[readIndex + 1];
1802
1/2
✓ Branch 12 → 13 taken 697 times.
✗ Branch 12 → 45 not taken.
697 auto it = escapeMap.find(next);
1803
2/2
✓ Branch 15 → 16 taken 688 times.
✓ Branch 15 → 19 taken 9 times.
697 if (it != escapeMap.end()) {
1804 688 input[writeIndex++] = it->second;
1805 688 readIndex += 2;
1806 694 continue;
1807 }
1808
1809 // Handle octal escape sequences (up to 3 digits)
1810
3/4
✓ Branch 19 → 20 taken 9 times.
✗ Branch 19 → 31 not taken.
✓ Branch 20 → 21 taken 6 times.
✓ Branch 20 → 31 taken 3 times.
9 if (next >= '0' && next <= '7') {
1811 6 int value = 0;
1812 6 size_t octalDigits = 0;
1813
1814 // Look ahead up to 3 digits
1815
3/4
✓ Branch 26 → 27 taken 18 times.
✓ Branch 26 → 28 taken 6 times.
✓ Branch 27 → 22 taken 18 times.
✗ Branch 27 → 28 not taken.
24 for (size_t i = 1; i <= 3 && readIndex + i < len; ++i) {
1816 18 const char oc = input[readIndex + i];
1817
2/4
✓ Branch 23 → 24 taken 18 times.
✗ Branch 23 → 28 not taken.
✓ Branch 24 → 25 taken 18 times.
✗ Branch 24 → 28 not taken.
18 if (oc >= '0' && oc <= '7') {
1818 18 value = value << 3 | (oc - '0'); // multiply by 8 and add digit
1819 18 octalDigits++;
1820 } else {
1821 break;
1822 }
1823 }
1824
1825
1/2
✓ Branch 28 → 29 taken 6 times.
✗ Branch 28 → 31 not taken.
6 if (octalDigits > 0) {
1826 6 input[writeIndex++] = static_cast<char>(value);
1827 6 readIndex += 1 + octalDigits; // backslash + octal digits
1828 6 continue;
1829 }
1830 }
1831 }
1832
1833 // Copy current character
1834 53015 input[writeIndex++] = c;
1835 53015 readIndex++;
1836 }
1837
1838
1/2
✓ Branch 37 → 38 taken 3525 times.
✗ Branch 37 → 46 not taken.
3525 input.resize(writeIndex);
1839 3525 }
1840
1841 117326 std::string ASTBuilder::getIdentifier(TerminalNode *terminal, bool isTypeIdentifier) const {
1842 117326 const std::string identifier = terminal->getText();
1843
1844 // Check if the list of reserved keywords contains the given identifier
1845
3/4
✓ Branch 3 → 4 taken 117326 times.
✗ Branch 3 → 56 not taken.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 16 taken 117325 times.
234652 if (std::ranges::find(RESERVED_KEYWORDS, identifier) != std::end(RESERVED_KEYWORDS)) {
1846
2/4
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 45 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 45 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1847
3/6
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 41 not taken.
✓ Branch 11 → 12 taken 1 time.
✗ Branch 11 → 39 not taken.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 36 not taken.
1 throw ParserError(codeLoc, RESERVED_KEYWORD, "'" + identifier + "' is a reserved keyword. Please use another name instead");
1848 }
1849
1850 // Check if the identifier is a type identifier and is reserved
1851
6/6
✓ Branch 16 → 17 taken 9703 times.
✓ Branch 16 → 23 taken 107622 times.
✓ Branch 17 → 18 taken 788 times.
✓ Branch 17 → 23 taken 8915 times.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 34 taken 117324 times.
118113 if (isTypeIdentifier && !sourceFile->isStdFile &&
1852
3/4
✓ Branch 18 → 19 taken 788 times.
✗ Branch 18 → 56 not taken.
✓ Branch 21 → 22 taken 1 time.
✓ Branch 21 → 23 taken 787 times.
1576 std::ranges::find(RESERVED_TYPE_NAMES, identifier) != std::end(RESERVED_TYPE_NAMES)) {
1853
2/4
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 55 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 55 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1854
3/6
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 51 not taken.
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 49 not taken.
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 46 not taken.
1 throw ParserError(codeLoc, RESERVED_TYPENAME, "'" + identifier + "' is a reserved type name. Please use another one instead");
1855 }
1856
1857 117324 return identifier;
1858 2 }
1859
1860 } // namespace spice::compiler
1861