GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 94.6% 1098 / 16 / 1177
Functions: 100.0% 96 / 0 / 96
Branches: 58.2% 1487 / 4 / 2561

src/ast/ASTBuilder.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 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 1253 ASTBuilder::ASTBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile, antlr4::ANTLRInputStream *inputStream)
17
1/2
✓ Branch 4 → 5 taken 1253 times.
✗ Branch 4 → 6 not taken.
1253 : CompilerPass(resourceManager, sourceFile), inputStream(inputStream) {}
18
19 1251 std::any ASTBuilder::visitEntry(SpiceParser::EntryContext *ctx) {
20 1251 const auto entryNode = createNode<EntryNode>(ctx);
21
22 // Visit children
23
2/2
✓ Branch 127 → 5 taken 19889 times.
✓ Branch 127 → 128 taken 1245 times.
21134 for (ParserRuleContext::ParseTree *child : ctx->children) {
24
3/4
✓ Branch 6 → 7 taken 19889 times.
✗ Branch 6 → 8 not taken.
✓ Branch 9 → 10 taken 445 times.
✓ Branch 9 → 15 taken 19444 times.
19889 if (auto *mainFctDefCtx = dynamic_cast<SpiceParser::MainFunctionDefContext *>(child))
25
4/6
✓ Branch 10 → 11 taken 441 times.
✓ Branch 10 → 140 taken 4 times.
✓ Branch 11 → 12 taken 441 times.
✗ Branch 11 → 138 not taken.
✓ Branch 12 → 13 taken 441 times.
✗ Branch 12 → 138 not taken.
445 entryNode->topLevelDefs.push_back(std::any_cast<MainFctDefNode *>(visit(mainFctDefCtx)));
26
3/4
✓ Branch 15 → 16 taken 19444 times.
✗ Branch 15 → 17 not taken.
✓ Branch 18 → 19 taken 8410 times.
✓ Branch 18 → 24 taken 11034 times.
19444 else if (auto *fctDefCtx = dynamic_cast<SpiceParser::FunctionDefContext *>(child))
27
3/6
✓ Branch 19 → 20 taken 8410 times.
✗ Branch 19 → 144 not taken.
✓ Branch 20 → 21 taken 8410 times.
✗ Branch 20 → 142 not taken.
✓ Branch 21 → 22 taken 8410 times.
✗ Branch 21 → 142 not taken.
8410 entryNode->topLevelDefs.push_back(std::any_cast<FctDefNode *>(visit(fctDefCtx)));
28
3/4
✓ Branch 24 → 25 taken 11034 times.
✗ Branch 24 → 26 not taken.
✓ Branch 27 → 28 taken 4338 times.
✓ Branch 27 → 33 taken 6696 times.
11034 else if (auto *procDefCtx = dynamic_cast<SpiceParser::ProcedureDefContext *>(child))
29
3/6
✓ Branch 28 → 29 taken 4338 times.
✗ Branch 28 → 148 not taken.
✓ Branch 29 → 30 taken 4338 times.
✗ Branch 29 → 146 not taken.
✓ Branch 30 → 31 taken 4338 times.
✗ Branch 30 → 146 not taken.
4338 entryNode->topLevelDefs.push_back(std::any_cast<ProcDefNode *>(visit(procDefCtx)));
30
3/4
✓ Branch 33 → 34 taken 6696 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 756 times.
✓ Branch 36 → 42 taken 5940 times.
6696 else if (auto *structDefCtx = dynamic_cast<SpiceParser::StructDefContext *>(child))
31
4/6
✓ Branch 37 → 38 taken 755 times.
✓ Branch 37 → 152 taken 1 time.
✓ Branch 38 → 39 taken 755 times.
✗ Branch 38 → 150 not taken.
✓ Branch 39 → 40 taken 755 times.
✗ Branch 39 → 150 not taken.
756 entryNode->topLevelDefs.push_back(std::any_cast<StructDefNode *>(visit(structDefCtx)));
32
3/4
✓ Branch 42 → 43 taken 5940 times.
✗ Branch 42 → 44 not taken.
✓ Branch 45 → 46 taken 107 times.
✓ Branch 45 → 51 taken 5833 times.
5940 else if (auto *interfaceDefCtx = dynamic_cast<SpiceParser::InterfaceDefContext *>(child))
33
3/6
✓ Branch 46 → 47 taken 107 times.
✗ Branch 46 → 156 not taken.
✓ Branch 47 → 48 taken 107 times.
✗ Branch 47 → 154 not taken.
✓ Branch 48 → 49 taken 107 times.
✗ Branch 48 → 154 not taken.
107 entryNode->topLevelDefs.push_back(std::any_cast<InterfaceDefNode *>(visit(interfaceDefCtx)));
34
3/4
✓ Branch 51 → 52 taken 5833 times.
✗ Branch 51 → 53 not taken.
✓ Branch 54 → 55 taken 78 times.
✓ Branch 54 → 60 taken 5755 times.
5833 else if (auto *enumDefCtx = dynamic_cast<SpiceParser::EnumDefContext *>(child))
35
3/6
✓ Branch 55 → 56 taken 78 times.
✗ Branch 55 → 160 not taken.
✓ Branch 56 → 57 taken 78 times.
✗ Branch 56 → 158 not taken.
✓ Branch 57 → 58 taken 78 times.
✗ Branch 57 → 158 not taken.
78 entryNode->topLevelDefs.push_back(std::any_cast<EnumDefNode *>(visit(enumDefCtx)));
36
3/4
✓ Branch 60 → 61 taken 5755 times.
✗ Branch 60 → 62 not taken.
✓ Branch 63 → 64 taken 1006 times.
✓ Branch 63 → 69 taken 4749 times.
5755 else if (auto *genericTypeDefCtx = dynamic_cast<SpiceParser::GenericTypeDefContext *>(child))
37
3/6
✓ Branch 64 → 65 taken 1006 times.
✗ Branch 64 → 164 not taken.
✓ Branch 65 → 66 taken 1006 times.
✗ Branch 65 → 162 not taken.
✓ Branch 66 → 67 taken 1006 times.
✗ Branch 66 → 162 not taken.
1006 entryNode->topLevelDefs.push_back(std::any_cast<GenericTypeDefNode *>(visit(genericTypeDefCtx)));
38
3/4
✓ Branch 69 → 70 taken 4749 times.
✗ Branch 69 → 71 not taken.
✓ Branch 72 → 73 taken 109 times.
✓ Branch 72 → 78 taken 4640 times.
4749 else if (auto *aliasDefCtx = dynamic_cast<SpiceParser::AliasDefContext *>(child))
39
3/6
✓ Branch 73 → 74 taken 109 times.
✗ Branch 73 → 168 not taken.
✓ Branch 74 → 75 taken 109 times.
✗ Branch 74 → 166 not taken.
✓ Branch 75 → 76 taken 109 times.
✗ Branch 75 → 166 not taken.
109 entryNode->topLevelDefs.push_back(std::any_cast<AliasDefNode *>(visit(aliasDefCtx)));
40
3/4
✓ Branch 78 → 79 taken 4640 times.
✗ Branch 78 → 80 not taken.
✓ Branch 81 → 82 taken 1262 times.
✓ Branch 81 → 87 taken 3378 times.
4640 else if (auto *globalVarDefCtx = dynamic_cast<SpiceParser::GlobalVarDefContext *>(child))
41
3/6
✓ Branch 82 → 83 taken 1262 times.
✗ Branch 82 → 172 not taken.
✓ Branch 83 → 84 taken 1262 times.
✗ Branch 83 → 170 not taken.
✓ Branch 84 → 85 taken 1262 times.
✗ Branch 84 → 170 not taken.
1262 entryNode->topLevelDefs.push_back(std::any_cast<GlobalVarDefNode *>(visit(globalVarDefCtx)));
42
3/4
✓ Branch 87 → 88 taken 3378 times.
✗ Branch 87 → 89 not taken.
✓ Branch 90 → 91 taken 650 times.
✓ Branch 90 → 96 taken 2728 times.
3378 else if (auto *importDefCtx = dynamic_cast<SpiceParser::ImportDefContext *>(child))
43
3/6
✓ Branch 91 → 92 taken 650 times.
✗ Branch 91 → 176 not taken.
✓ Branch 92 → 93 taken 650 times.
✗ Branch 92 → 174 not taken.
✓ Branch 93 → 94 taken 650 times.
✗ Branch 93 → 174 not taken.
650 entryNode->importDefs.push_back(std::any_cast<ImportDefNode *>(visit(importDefCtx)));
44
3/4
✓ Branch 96 → 97 taken 2728 times.
✗ Branch 96 → 98 not taken.
✓ Branch 99 → 100 taken 1102 times.
✓ Branch 99 → 105 taken 1626 times.
2728 else if (auto *extDeclCtx = dynamic_cast<SpiceParser::ExtDeclContext *>(child))
45
3/6
✓ Branch 100 → 101 taken 1102 times.
✗ Branch 100 → 180 not taken.
✓ Branch 101 → 102 taken 1102 times.
✗ Branch 101 → 178 not taken.
✓ Branch 102 → 103 taken 1102 times.
✗ Branch 102 → 178 not taken.
1102 entryNode->topLevelDefs.push_back(std::any_cast<ExtDeclNode *>(visit(extDeclCtx)));
46
3/4
✓ Branch 105 → 106 taken 1626 times.
✗ Branch 105 → 107 not taken.
✓ Branch 108 → 109 taken 381 times.
✓ Branch 108 → 114 taken 1245 times.
1626 else if (auto *modAttrCtx = dynamic_cast<SpiceParser::ModAttrContext *>(child))
47
4/6
✓ Branch 109 → 110 taken 380 times.
✓ Branch 109 → 184 taken 1 time.
✓ Branch 110 → 111 taken 380 times.
✗ Branch 110 → 182 not taken.
✓ Branch 111 → 112 taken 380 times.
✗ Branch 111 → 182 not taken.
381 entryNode->modAttrs.push_back(std::any_cast<ModAttrNode *>(visit(modAttrCtx)));
48
1/2
✓ Branch 114 → 115 taken 1245 times.
✗ Branch 114 → 116 not taken.
1245 else if (const auto *eofCtx = dynamic_cast<TerminalNode *>(child);
49
5/10
✓ Branch 117 → 118 taken 1245 times.
✗ Branch 117 → 121 not taken.
✓ Branch 118 → 119 taken 1245 times.
✗ Branch 118 → 186 not taken.
✓ Branch 119 → 120 taken 1245 times.
✗ Branch 119 → 186 not taken.
✗ Branch 120 → 121 not taken.
✓ Branch 120 → 122 taken 1245 times.
✗ Branch 123 → 124 not taken.
✓ Branch 123 → 125 taken 1245 times.
1245 !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 1245 times.
✗ Branch 134 → 187 not taken.
1245 return concludeNode(entryNode);
54 }
55
56 445 std::any ASTBuilder::visitMainFunctionDef(SpiceParser::MainFunctionDefContext *ctx) {
57 445 const auto mainFctDefNode = createNode<MainFctDefNode>(ctx);
58
59 // Visit children
60
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 10 taken 444 times.
445 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 6 times.
✓ Branch 11 → 17 taken 439 times.
445 if (ctx->paramLst()) {
63 6 mainFctDefNode->takesArgs = true;
64
3/6
✓ Branch 12 → 13 taken 6 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 6 times.
✗ Branch 14 → 34 not taken.
6 mainFctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
65 }
66
4/6
✓ Branch 17 → 18 taken 445 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 441 times.
✓ Branch 18 → 39 taken 4 times.
✓ Branch 19 → 20 taken 441 times.
✗ Branch 19 → 37 not taken.
445 mainFctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
67
68
1/2
✓ Branch 27 → 28 taken 441 times.
✗ Branch 27 → 40 not taken.
441 return concludeNode(mainFctDefNode);
69 }
70
71 8410 std::any ASTBuilder::visitFunctionDef(SpiceParser::FunctionDefContext *ctx) {
72 8410 const auto fctDefNode = createNode<FctDefNode>(ctx);
73
74 // Visit children
75
2/2
✓ Branch 4 → 5 taken 344 times.
✓ Branch 4 → 16 taken 8066 times.
8410 if (ctx->topLevelDefAttr()) {
76
3/6
✓ Branch 5 → 6 taken 344 times.
✗ Branch 5 → 62 not taken.
✓ Branch 6 → 7 taken 344 times.
✗ Branch 6 → 62 not taken.
✓ Branch 7 → 8 taken 344 times.
✗ Branch 7 → 60 not taken.
344 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 349 times.
✓ Branch 14 → 15 taken 344 times.
693 for (AttrNode *attr : fctDefNode->attrs->attrLst->attributes)
79 349 attr->target = AttrNode::TARGET_FCT_PROC;
80 }
81
2/2
✓ Branch 17 → 18 taken 8209 times.
✓ Branch 17 → 23 taken 201 times.
8410 if (ctx->qualifierLst())
82
3/6
✓ Branch 18 → 19 taken 8209 times.
✗ Branch 18 → 65 not taken.
✓ Branch 19 → 20 taken 8209 times.
✗ Branch 19 → 65 not taken.
✓ Branch 20 → 21 taken 8209 times.
✗ Branch 20 → 63 not taken.
8209 fctDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
83
3/6
✓ Branch 23 → 24 taken 8410 times.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 8410 times.
✗ Branch 24 → 68 not taken.
✓ Branch 25 → 26 taken 8410 times.
✗ Branch 25 → 66 not taken.
8410 fctDefNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
84 8410 fctDefNode->returnType->isReturnType = true;
85
3/6
✓ Branch 27 → 28 taken 8410 times.
✗ Branch 27 → 71 not taken.
✓ Branch 28 → 29 taken 8410 times.
✗ Branch 28 → 71 not taken.
✓ Branch 29 → 30 taken 8410 times.
✗ Branch 29 → 69 not taken.
8410 fctDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName()));
86 8410 fctDefNode->isMethod = fctDefNode->name->nameFragments.size() > 1;
87
2/2
✓ Branch 33 → 34 taken 1122 times.
✓ Branch 33 → 39 taken 7288 times.
8410 if (ctx->typeLst()) {
88 1122 fctDefNode->hasTemplateTypes = true;
89
3/6
✓ Branch 34 → 35 taken 1122 times.
✗ Branch 34 → 74 not taken.
✓ Branch 35 → 36 taken 1122 times.
✗ Branch 35 → 74 not taken.
✓ Branch 36 → 37 taken 1122 times.
✗ Branch 36 → 72 not taken.
1122 fctDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
90 }
91
2/2
✓ Branch 40 → 41 taken 6503 times.
✓ Branch 40 → 46 taken 1907 times.
8410 if (ctx->paramLst()) {
92 6503 fctDefNode->hasParams = true;
93
3/6
✓ Branch 41 → 42 taken 6503 times.
✗ Branch 41 → 77 not taken.
✓ Branch 42 → 43 taken 6503 times.
✗ Branch 42 → 77 not taken.
✓ Branch 43 → 44 taken 6503 times.
✗ Branch 43 → 75 not taken.
6503 fctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
94 }
95
3/6
✓ Branch 46 → 47 taken 8410 times.
✗ Branch 46 → 80 not taken.
✓ Branch 47 → 48 taken 8410 times.
✗ Branch 47 → 80 not taken.
✓ Branch 48 → 49 taken 8410 times.
✗ Branch 48 → 78 not taken.
8410 fctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
96
97
1/2
✓ Branch 56 → 57 taken 8410 times.
✗ Branch 56 → 81 not taken.
8410 return concludeNode(fctDefNode);
98 }
99
100 4338 std::any ASTBuilder::visitProcedureDef(SpiceParser::ProcedureDefContext *ctx) {
101 4338 const auto procDefNode = createNode<ProcDefNode>(ctx);
102
103 // Visit children
104
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 16 taken 4337 times.
4338 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 3756 times.
✓ Branch 17 → 23 taken 582 times.
4338 if (ctx->qualifierLst())
111
3/6
✓ Branch 18 → 19 taken 3756 times.
✗ Branch 18 → 61 not taken.
✓ Branch 19 → 20 taken 3756 times.
✗ Branch 19 → 61 not taken.
✓ Branch 20 → 21 taken 3756 times.
✗ Branch 20 → 59 not taken.
3756 procDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
112
3/6
✓ Branch 23 → 24 taken 4338 times.
✗ Branch 23 → 64 not taken.
✓ Branch 24 → 25 taken 4338 times.
✗ Branch 24 → 64 not taken.
✓ Branch 25 → 26 taken 4338 times.
✗ Branch 25 → 62 not taken.
4338 procDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName()));
113 4338 procDefNode->isMethod = procDefNode->name->nameFragments.size() > 1;
114
2/2
✓ Branch 29 → 30 taken 1205 times.
✓ Branch 29 → 35 taken 3133 times.
4338 if (ctx->typeLst()) {
115 1205 procDefNode->hasTemplateTypes = true;
116
3/6
✓ Branch 30 → 31 taken 1205 times.
✗ Branch 30 → 67 not taken.
✓ Branch 31 → 32 taken 1205 times.
✗ Branch 31 → 67 not taken.
✓ Branch 32 → 33 taken 1205 times.
✗ Branch 32 → 65 not taken.
1205 procDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
117 }
118
2/2
✓ Branch 36 → 37 taken 3212 times.
✓ Branch 36 → 42 taken 1126 times.
4338 if (ctx->paramLst()) {
119 3212 procDefNode->hasParams = true;
120
3/6
✓ Branch 37 → 38 taken 3212 times.
✗ Branch 37 → 70 not taken.
✓ Branch 38 → 39 taken 3212 times.
✗ Branch 38 → 70 not taken.
✓ Branch 39 → 40 taken 3212 times.
✗ Branch 39 → 68 not taken.
3212 procDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
121 }
122
3/6
✓ Branch 42 → 43 taken 4338 times.
✗ Branch 42 → 73 not taken.
✓ Branch 43 → 44 taken 4338 times.
✗ Branch 43 → 73 not taken.
✓ Branch 44 → 45 taken 4338 times.
✗ Branch 44 → 71 not taken.
4338 procDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
123
124
1/2
✓ Branch 52 → 53 taken 4338 times.
✗ Branch 52 → 74 not taken.
4338 return concludeNode(procDefNode);
125 }
126
127 12748 std::any ASTBuilder::visitFctName(SpiceParser::FctNameContext *ctx) {
128 12748 const auto fctNameNode = createNode<FctNameNode>(ctx);
129
130 // Extract function name
131
2/2
✓ Branch 4 → 5 taken 6932 times.
✓ Branch 4 → 14 taken 5816 times.
12748 if (ctx->TYPE_IDENTIFIER()) {
132
2/4
✓ Branch 5 → 6 taken 6932 times.
✗ Branch 5 → 42 not taken.
✓ Branch 6 → 7 taken 6932 times.
✗ Branch 6 → 42 not taken.
6932 const std::string typeIdentifier = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
133
1/2
✓ Branch 7 → 8 taken 6932 times.
✗ Branch 7 → 40 not taken.
6932 fctNameNode->structName = typeIdentifier;
134
1/2
✓ Branch 8 → 9 taken 6932 times.
✗ Branch 8 → 39 not taken.
6932 fctNameNode->fqName = typeIdentifier + MEMBER_ACCESS_TOKEN;
135
1/2
✓ Branch 11 → 12 taken 6932 times.
✗ Branch 11 → 40 not taken.
6932 fctNameNode->nameFragments.push_back(typeIdentifier);
136 6932 }
137
2/2
✓ Branch 15 → 16 taken 10891 times.
✓ Branch 15 → 23 taken 1857 times.
12748 if (ctx->IDENTIFIER()) {
138
2/4
✓ Branch 16 → 17 taken 10891 times.
✗ Branch 16 → 45 not taken.
✓ Branch 17 → 18 taken 10891 times.
✗ Branch 17 → 45 not taken.
10891 const std::string fctIdentifier = getIdentifier(ctx->IDENTIFIER(), false);
139
1/2
✓ Branch 18 → 19 taken 10891 times.
✗ Branch 18 → 43 not taken.
10891 fctNameNode->name = fctIdentifier;
140
1/2
✓ Branch 19 → 20 taken 10891 times.
✗ Branch 19 → 43 not taken.
10891 fctNameNode->fqName += fctIdentifier;
141
1/2
✓ Branch 20 → 21 taken 10891 times.
✗ Branch 20 → 43 not taken.
10891 fctNameNode->nameFragments.push_back(fctIdentifier);
142 10891 }
143
144 // Visit children
145
2/2
✓ Branch 24 → 25 taken 1857 times.
✓ Branch 24 → 29 taken 10891 times.
12748 if (ctx->overloadableOp())
146
2/4
✓ Branch 25 → 26 taken 1857 times.
✗ Branch 25 → 46 not taken.
✓ Branch 26 → 27 taken 1857 times.
✗ Branch 26 → 46 not taken.
1857 visit(ctx->overloadableOp());
147
148
1/2
✓ Branch 35 → 36 taken 12748 times.
✗ Branch 35 → 47 not taken.
12748 return concludeNode(fctNameNode);
149 }
150
151 756 std::any ASTBuilder::visitStructDef(SpiceParser::StructDefContext *ctx) {
152 756 const auto structDefNode = createNode<StructDefNode>(ctx);
153
154 // Enrich
155
3/4
✓ Branch 3 → 4 taken 756 times.
✗ Branch 3 → 87 not taken.
✓ Branch 4 → 5 taken 755 times.
✓ Branch 4 → 87 taken 1 time.
756 structDefNode->structName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
156 755 structDefNode->typeId = resourceManager.getNextCustomTypeId();
157
158 // Visit children
159
2/2
✓ Branch 9 → 10 taken 65 times.
✓ Branch 9 → 41 taken 690 times.
755 if (ctx->topLevelDefAttr()) {
160
3/6
✓ Branch 10 → 11 taken 65 times.
✗ Branch 10 → 90 not taken.
✓ Branch 11 → 12 taken 65 times.
✗ Branch 11 → 90 not taken.
✓ Branch 12 → 13 taken 65 times.
✗ Branch 12 → 88 not taken.
65 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 65 times.
✓ Branch 19 → 20 taken 65 times.
130 for (AttrNode *attr : structDefNode->attrs->attrLst->attributes)
164 65 attr->target = AttrNode::TARGET_STRUCT;
165
166 // Check if a custom type id was set
167
7/18
✓ Branch 20 → 21 taken 65 times.
✗ Branch 20 → 27 not taken.
✓ Branch 23 → 24 taken 65 times.
✗ Branch 23 → 91 not taken.
✓ Branch 24 → 25 taken 65 times.
✗ Branch 24 → 91 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 65 times.
✓ Branch 28 → 29 taken 65 times.
✗ Branch 28 → 30 not taken.
✓ Branch 30 → 31 taken 65 times.
✗ Branch 30 → 33 not taken.
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 41 taken 65 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 98 not taken.
195 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 587 times.
✓ Branch 42 → 48 taken 168 times.
755 if (ctx->qualifierLst())
171
3/6
✓ Branch 43 → 44 taken 587 times.
✗ Branch 43 → 108 not taken.
✓ Branch 44 → 45 taken 587 times.
✗ Branch 44 → 108 not taken.
✓ Branch 45 → 46 taken 587 times.
✗ Branch 45 → 106 not taken.
587 structDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
172
2/2
✓ Branch 49 → 50 taken 258 times.
✓ Branch 49 → 55 taken 497 times.
755 if (ctx->LESS()) {
173 258 structDefNode->hasTemplateTypes = true;
174
3/6
✓ Branch 50 → 51 taken 258 times.
✗ Branch 50 → 111 not taken.
✓ Branch 51 → 52 taken 258 times.
✗ Branch 51 → 111 not taken.
✓ Branch 52 → 53 taken 258 times.
✗ Branch 52 → 109 not taken.
258 structDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0)));
175 }
176
2/2
✓ Branch 56 → 57 taken 142 times.
✓ Branch 56 → 65 taken 613 times.
755 if (ctx->COLON()) {
177 142 structDefNode->hasInterfaces = true;
178
5/8
✓ Branch 57 → 58 taken 119 times.
✓ Branch 57 → 59 taken 23 times.
✓ Branch 60 → 61 taken 142 times.
✗ Branch 60 → 114 not taken.
✓ Branch 61 → 62 taken 142 times.
✗ Branch 61 → 114 not taken.
✓ Branch 62 → 63 taken 142 times.
✗ Branch 62 → 112 not taken.
142 structDefNode->interfaceTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(structDefNode->hasTemplateTypes ? 1 : 0)));
179 }
180
3/4
✓ Branch 65 → 66 taken 755 times.
✗ Branch 65 → 121 not taken.
✓ Branch 75 → 68 taken 1587 times.
✓ Branch 75 → 76 taken 755 times.
2342 for (SpiceParser::FieldContext *field : ctx->field())
181
3/6
✓ Branch 69 → 70 taken 1587 times.
✗ Branch 69 → 117 not taken.
✓ Branch 70 → 71 taken 1587 times.
✗ Branch 70 → 115 not taken.
✓ Branch 71 → 72 taken 1587 times.
✗ Branch 71 → 115 not taken.
2342 structDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field)));
182
183
1/2
✓ Branch 83 → 84 taken 755 times.
✗ Branch 83 → 122 not taken.
755 return concludeNode(structDefNode);
184 }
185
186 107 std::any ASTBuilder::visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) {
187 107 const auto interfaceDefNode = createNode<InterfaceDefNode>(ctx);
188
189 // Enrich
190
2/4
✓ Branch 3 → 4 taken 107 times.
✗ Branch 3 → 77 not taken.
✓ Branch 4 → 5 taken 107 times.
✗ Branch 4 → 77 not taken.
107 interfaceDefNode->interfaceName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
191 107 interfaceDefNode->typeId = resourceManager.getNextCustomTypeId();
192
193 // Visit children
194
2/2
✓ Branch 9 → 10 taken 77 times.
✓ Branch 9 → 41 taken 30 times.
107 if (ctx->topLevelDefAttr()) {
195
3/6
✓ Branch 10 → 11 taken 77 times.
✗ Branch 10 → 80 not taken.
✓ Branch 11 → 12 taken 77 times.
✗ Branch 11 → 80 not taken.
✓ Branch 12 → 13 taken 77 times.
✗ Branch 12 → 78 not taken.
77 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 77 times.
✓ Branch 19 → 20 taken 77 times.
154 for (AttrNode *attr : interfaceDefNode->attrs->attrLst->attributes)
199 77 attr->target = AttrNode::TARGET_INTERFACE;
200
201 // Check if a custom type id was set
202
7/18
✓ Branch 20 → 21 taken 77 times.
✗ Branch 20 → 27 not taken.
✓ Branch 23 → 24 taken 77 times.
✗ Branch 23 → 81 not taken.
✓ Branch 24 → 25 taken 77 times.
✗ Branch 24 → 81 not taken.
✓ Branch 25 → 26 taken 77 times.
✗ Branch 25 → 27 not taken.
✓ Branch 28 → 29 taken 77 times.
✗ Branch 28 → 30 not taken.
✓ Branch 30 → 31 taken 77 times.
✗ Branch 30 → 33 not taken.
✓ Branch 33 → 34 taken 77 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.
231 if (interfaceDefNode->attrs && interfaceDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID))
203
2/4
✓ Branch 36 → 37 taken 77 times.
✗ Branch 36 → 92 not taken.
✓ Branch 37 → 38 taken 77 times.
✗ Branch 37 → 90 not taken.
231 interfaceDefNode->typeId = interfaceDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue;
204 }
205
2/2
✓ Branch 42 → 43 taken 89 times.
✓ Branch 42 → 48 taken 18 times.
107 if (ctx->qualifierLst())
206
3/6
✓ Branch 43 → 44 taken 89 times.
✗ Branch 43 → 98 not taken.
✓ Branch 44 → 45 taken 89 times.
✗ Branch 44 → 98 not taken.
✓ Branch 45 → 46 taken 89 times.
✗ Branch 45 → 96 not taken.
89 interfaceDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
207
2/2
✓ Branch 49 → 50 taken 80 times.
✓ Branch 49 → 55 taken 27 times.
107 if (ctx->LESS()) {
208 80 interfaceDefNode->hasTemplateTypes = true;
209
3/6
✓ Branch 50 → 51 taken 80 times.
✗ Branch 50 → 101 not taken.
✓ Branch 51 → 52 taken 80 times.
✗ Branch 51 → 101 not taken.
✓ Branch 52 → 53 taken 80 times.
✗ Branch 52 → 99 not taken.
80 interfaceDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
210 }
211
3/4
✓ Branch 55 → 56 taken 107 times.
✗ Branch 55 → 108 not taken.
✓ Branch 65 → 58 taken 243 times.
✓ Branch 65 → 66 taken 107 times.
350 for (SpiceParser::SignatureContext *signature : ctx->signature())
212
3/6
✓ Branch 59 → 60 taken 243 times.
✗ Branch 59 → 104 not taken.
✓ Branch 60 → 61 taken 243 times.
✗ Branch 60 → 102 not taken.
✓ Branch 61 → 62 taken 243 times.
✗ Branch 61 → 102 not taken.
350 interfaceDefNode->signatures.push_back(std::any_cast<SignatureNode *>(visit(signature)));
213
214
1/2
✓ Branch 73 → 74 taken 107 times.
✗ Branch 73 → 109 not taken.
107 return concludeNode(interfaceDefNode);
215 }
216
217 78 std::any ASTBuilder::visitEnumDef(SpiceParser::EnumDefContext *ctx) {
218 78 const auto enumDefNode = createNode<EnumDefNode>(ctx);
219
220 // Enrich
221
2/4
✓ Branch 3 → 4 taken 78 times.
✗ Branch 3 → 35 not taken.
✓ Branch 4 → 5 taken 78 times.
✗ Branch 4 → 35 not taken.
78 enumDefNode->enumName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
222 78 enumDefNode->typeId = resourceManager.getNextCustomTypeId();
223
224 // Visit children
225
2/2
✓ Branch 9 → 10 taken 60 times.
✓ Branch 9 → 15 taken 18 times.
78 if (ctx->qualifierLst())
226
3/6
✓ Branch 10 → 11 taken 60 times.
✗ Branch 10 → 38 not taken.
✓ Branch 11 → 12 taken 60 times.
✗ Branch 11 → 38 not taken.
✓ Branch 12 → 13 taken 60 times.
✗ Branch 12 → 36 not taken.
60 enumDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
227
3/6
✓ Branch 15 → 16 taken 78 times.
✗ Branch 15 → 41 not taken.
✓ Branch 16 → 17 taken 78 times.
✗ Branch 16 → 41 not taken.
✓ Branch 17 → 18 taken 78 times.
✗ Branch 17 → 39 not taken.
78 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 1186 times.
✓ Branch 24 → 25 taken 78 times.
1264 for (EnumItemNode *enumItem : enumDefNode->itemLst->items)
231 1186 enumItem->enumDef = enumDefNode;
232
233
1/2
✓ Branch 31 → 32 taken 78 times.
✗ Branch 31 → 42 not taken.
78 return concludeNode(enumDefNode);
234 }
235
236 1006 std::any ASTBuilder::visitGenericTypeDef(SpiceParser::GenericTypeDefContext *ctx) {
237 1006 const auto genericTypeDefNode = createNode<GenericTypeDefNode>(ctx);
238
239 // Enrich
240
2/4
✓ Branch 3 → 4 taken 1006 times.
✗ Branch 3 → 21 not taken.
✓ Branch 4 → 5 taken 1006 times.
✗ Branch 4 → 21 not taken.
1006 genericTypeDefNode->typeName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
241
242 // Visit children
243
3/6
✓ Branch 7 → 8 taken 1006 times.
✗ Branch 7 → 24 not taken.
✓ Branch 8 → 9 taken 1006 times.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 1006 times.
✗ Branch 9 → 22 not taken.
1006 genericTypeDefNode->typeAltsLst = std::any_cast<TypeAltsLstNode *>(visit(ctx->typeAltsLst()));
244
245
1/2
✓ Branch 17 → 18 taken 1006 times.
✗ Branch 17 → 25 not taken.
1006 return concludeNode(genericTypeDefNode);
246 }
247
248 109 std::any ASTBuilder::visitAliasDef(SpiceParser::AliasDefContext *ctx) {
249 109 const auto aliasDefNode = createNode<AliasDefNode>(ctx);
250
251 // Enrich
252
2/4
✓ Branch 3 → 4 taken 109 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 109 times.
✗ Branch 4 → 33 not taken.
109 aliasDefNode->aliasName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
253
2/4
✓ Branch 7 → 8 taken 109 times.
✗ Branch 7 → 34 not taken.
✓ Branch 8 → 9 taken 109 times.
✗ Branch 8 → 34 not taken.
109 aliasDefNode->dataTypeString = ctx->dataType()->getText();
254 109 aliasDefNode->typeId = resourceManager.getNextCustomTypeId();
255
256 // Visit children
257
2/2
✓ Branch 13 → 14 taken 31 times.
✓ Branch 13 → 19 taken 78 times.
109 if (ctx->qualifierLst())
258
3/6
✓ Branch 14 → 15 taken 31 times.
✗ Branch 14 → 37 not taken.
✓ Branch 15 → 16 taken 31 times.
✗ Branch 15 → 37 not taken.
✓ Branch 16 → 17 taken 31 times.
✗ Branch 16 → 35 not taken.
31 aliasDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
259
3/6
✓ Branch 19 → 20 taken 109 times.
✗ Branch 19 → 40 not taken.
✓ Branch 20 → 21 taken 109 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 109 times.
✗ Branch 21 → 38 not taken.
109 aliasDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
260
261
1/2
✓ Branch 29 → 30 taken 109 times.
✗ Branch 29 → 41 not taken.
109 return concludeNode(aliasDefNode);
262 }
263
264 1262 std::any ASTBuilder::visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) {
265 1262 const auto globalVarDefNode = createNode<GlobalVarDefNode>(ctx);
266
267 // Enrich
268
2/4
✓ Branch 3 → 4 taken 1262 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 1262 times.
✗ Branch 4 → 28 not taken.
1262 globalVarDefNode->varName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
269
270 // Visit children
271
3/6
✓ Branch 7 → 8 taken 1262 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 1262 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 1262 times.
✗ Branch 9 → 29 not taken.
1262 globalVarDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
272 1262 globalVarDefNode->dataType->isGlobalType = true;
273
2/2
✓ Branch 12 → 13 taken 1260 times.
✓ Branch 12 → 18 taken 2 times.
1262 if (ctx->constant()) {
274 1260 globalVarDefNode->hasValue = true;
275
3/6
✓ Branch 13 → 14 taken 1260 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 1260 times.
✗ Branch 14 → 34 not taken.
✓ Branch 15 → 16 taken 1260 times.
✗ Branch 15 → 32 not taken.
1260 globalVarDefNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
276 }
277
278
1/2
✓ Branch 24 → 25 taken 1262 times.
✗ Branch 24 → 35 not taken.
1262 return concludeNode(globalVarDefNode);
279 }
280
281 1102 std::any ASTBuilder::visitExtDecl(SpiceParser::ExtDeclContext *ctx) {
282 1102 const auto extDeclNode = createNode<ExtDeclNode>(ctx);
283
284 // Enrich
285
6/10
✓ Branch 3 → 4 taken 1102 times.
✗ Branch 3 → 49 not taken.
✓ Branch 4 → 5 taken 850 times.
✓ Branch 4 → 7 taken 252 times.
✓ Branch 5 → 6 taken 850 times.
✗ Branch 5 → 49 not taken.
✓ Branch 7 → 8 taken 252 times.
✗ Branch 7 → 49 not taken.
✓ Branch 9 → 10 taken 1102 times.
✗ Branch 9 → 49 not taken.
1102 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 1101 times.
1102 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 711 times.
✓ Branch 26 → 32 taken 391 times.
1102 if (ctx->F()) {
296
3/6
✓ Branch 27 → 28 taken 711 times.
✗ Branch 27 → 55 not taken.
✓ Branch 28 → 29 taken 711 times.
✗ Branch 28 → 55 not taken.
✓ Branch 29 → 30 taken 711 times.
✗ Branch 29 → 53 not taken.
711 extDeclNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
297 711 extDeclNode->returnType->isReturnType = true;
298 }
299
2/2
✓ Branch 33 → 34 taken 1060 times.
✓ Branch 33 → 39 taken 42 times.
1102 if (ctx->typeLstWithEllipsis()) {
300 1060 extDeclNode->hasArgs = true;
301
3/6
✓ Branch 34 → 35 taken 1060 times.
✗ Branch 34 → 58 not taken.
✓ Branch 35 → 36 taken 1060 times.
✗ Branch 35 → 58 not taken.
✓ Branch 36 → 37 taken 1060 times.
✗ Branch 36 → 56 not taken.
1060 extDeclNode->argTypeLst = std::any_cast<TypeLstWithEllipsisNode *>(visit(ctx->typeLstWithEllipsis()));
302 }
303
304
1/2
✓ Branch 45 → 46 taken 1102 times.
✗ Branch 45 → 59 not taken.
1102 return concludeNode(extDeclNode);
305 }
306
307 650 std::any ASTBuilder::visitImportDef(SpiceParser::ImportDefContext *ctx) {
308
1/2
✓ Branch 2 → 3 taken 650 times.
✗ Branch 2 → 32 not taken.
650 const auto importDefNode = createNode<ImportDefNode>(ctx);
309
310 // Extract path
311
2/4
✓ Branch 3 → 4 taken 650 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 650 times.
✗ Branch 4 → 32 not taken.
650 const std::string pathStr = ctx->STRING_LIT()->getText();
312
1/2
✓ Branch 6 → 7 taken 650 times.
✗ Branch 6 → 27 not taken.
650 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 650 times.
✗ Branch 9 → 28 not taken.
✓ Branch 10 → 11 taken 33 times.
✓ Branch 10 → 13 taken 617 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 617 times.
✗ Branch 13 → 28 not taken.
650 importDefNode->importName = ctx->AS() ? getIdentifier(ctx->IDENTIFIER(), false) : importDefNode->importPath;
316
317
1/2
✓ Branch 22 → 23 taken 650 times.
✗ Branch 22 → 29 not taken.
1300 return concludeNode(importDefNode);
318 650 }
319
320 2741 std::any ASTBuilder::visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) {
321 2741 const auto unsafeBlockDefNode = createNode<UnsafeBlockNode>(ctx);
322
323 // Visit children
324
3/6
✓ Branch 3 → 4 taken 2741 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 2741 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 2741 times.
✗ Branch 5 → 17 not taken.
2741 unsafeBlockDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
325
326
1/2
✓ Branch 13 → 14 taken 2741 times.
✗ Branch 13 → 20 not taken.
2741 return concludeNode(unsafeBlockDefNode);
327 }
328
329 1473 std::any ASTBuilder::visitForLoop(SpiceParser::ForLoopContext *ctx) {
330 1473 const auto forLoopNode = createNode<ForLoopNode>(ctx);
331
332
2/4
✓ Branch 3 → 4 taken 1473 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 1473 times.
✗ Branch 4 → 20 not taken.
1473 visit(ctx->forHead());
333
3/6
✓ Branch 6 → 7 taken 1473 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 1473 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 1473 times.
✗ Branch 8 → 21 not taken.
1473 forLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
334
335
1/2
✓ Branch 16 → 17 taken 1473 times.
✗ Branch 16 → 24 not taken.
1473 return concludeNode(forLoopNode);
336 }
337
338 1473 std::any ASTBuilder::visitForHead(SpiceParser::ForHeadContext *ctx) {
339 1473 const auto forLoopNode = resumeForExpansion<ForLoopNode>();
340
341 // Visit children
342
3/6
✓ Branch 12 → 13 taken 1473 times.
✗ Branch 12 → 29 not taken.
✓ Branch 13 → 14 taken 1473 times.
✗ Branch 13 → 29 not taken.
✓ Branch 14 → 15 taken 1473 times.
✗ Branch 14 → 27 not taken.
1473 forLoopNode->initDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt()));
343
3/6
✓ Branch 16 → 17 taken 1473 times.
✗ Branch 16 → 32 not taken.
✓ Branch 17 → 18 taken 1473 times.
✗ Branch 17 → 32 not taken.
✓ Branch 18 → 19 taken 1473 times.
✗ Branch 18 → 30 not taken.
1473 forLoopNode->condAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(0)));
344
3/6
✓ Branch 20 → 21 taken 1473 times.
✗ Branch 20 → 35 not taken.
✓ Branch 21 → 22 taken 1473 times.
✗ Branch 21 → 35 not taken.
✓ Branch 22 → 23 taken 1473 times.
✗ Branch 22 → 33 not taken.
1473 forLoopNode->incAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(1)));
345
346
1/2
✓ Branch 24 → 25 taken 1473 times.
✗ Branch 24 → 36 not taken.
1473 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<ExprNode *>(visit(ctx->assignExpr()));
375
376
1/2
✓ Branch 39 → 40 taken 124 times.
✗ Branch 39 → 56 not taken.
124 return nullptr;
377 }
378
379 839 std::any ASTBuilder::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) {
380 839 const auto whileLoopNode = createNode<WhileLoopNode>(ctx);
381
382 // Visit children
383
3/6
✓ Branch 3 → 4 taken 839 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 839 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 839 times.
✗ Branch 5 → 21 not taken.
839 whileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
384
3/6
✓ Branch 7 → 8 taken 839 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 839 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 839 times.
✗ Branch 9 → 24 not taken.
839 whileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
385
386
1/2
✓ Branch 17 → 18 taken 839 times.
✗ Branch 17 → 27 not taken.
839 return concludeNode(whileLoopNode);
387 }
388
389 8 std::any ASTBuilder::visitDoWhileLoop(SpiceParser::DoWhileLoopContext *ctx) {
390 8 const auto doWhileLoopNode = createNode<DoWhileLoopNode>(ctx);
391
392 // Visit children
393
3/6
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 21 not taken.
8 doWhileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
394
3/6
✓ Branch 7 → 8 taken 8 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 8 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 8 times.
✗ Branch 9 → 24 not taken.
8 doWhileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
395
396
1/2
✓ Branch 17 → 18 taken 8 times.
✗ Branch 17 → 27 not taken.
8 return concludeNode(doWhileLoopNode);
397 }
398
399 4450 std::any ASTBuilder::visitIfStmt(SpiceParser::IfStmtContext *ctx) {
400 4450 const auto ifStmtNode = createNode<IfStmtNode>(ctx);
401
402 // Visit children
403
3/6
✓ Branch 3 → 4 taken 4450 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 4450 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 4450 times.
✗ Branch 5 → 28 not taken.
4450 ifStmtNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
404
3/6
✓ Branch 7 → 8 taken 4450 times.
✗ Branch 7 → 33 not taken.
✓ Branch 8 → 9 taken 4450 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 4450 times.
✗ Branch 9 → 31 not taken.
4450 ifStmtNode->thenBody = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
405
2/2
✓ Branch 12 → 13 taken 250 times.
✓ Branch 12 → 18 taken 4200 times.
4450 if (ctx->elseStmt())
406
3/6
✓ Branch 13 → 14 taken 250 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 250 times.
✗ Branch 14 → 36 not taken.
✓ Branch 15 → 16 taken 250 times.
✗ Branch 15 → 34 not taken.
250 ifStmtNode->elseStmt = std::any_cast<ElseStmtNode *>(visit(ctx->elseStmt()));
407
408
1/2
✓ Branch 24 → 25 taken 4450 times.
✗ Branch 24 → 37 not taken.
4450 return concludeNode(ifStmtNode);
409 }
410
411 250 std::any ASTBuilder::visitElseStmt(SpiceParser::ElseStmtContext *ctx) {
412 250 const auto elseStmtNode = createNode<ElseStmtNode>(ctx);
413
414 // Visit children
415
2/2
✓ Branch 4 → 5 taken 73 times.
✓ Branch 4 → 10 taken 177 times.
250 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 177 times.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 177 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 177 times.
✗ Branch 12 → 28 not taken.
177 elseStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
420 }
421
422
1/2
✓ Branch 21 → 22 taken 250 times.
✗ Branch 21 → 31 not taken.
250 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<ExprNode *>(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 33 std::any ASTBuilder::visitAnonymousBlockStmt(SpiceParser::AnonymousBlockStmtContext *ctx) {
459 33 const auto anonymousBlockStmtNode = createNode<AnonymousBlockStmtNode>(ctx);
460
461 // Visit children
462
3/6
✓ Branch 3 → 4 taken 33 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 33 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 33 times.
✗ Branch 5 → 17 not taken.
33 anonymousBlockStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
463
464
1/2
✓ Branch 13 → 14 taken 33 times.
✗ Branch 13 → 20 not taken.
33 return concludeNode(anonymousBlockStmtNode);
465 }
466
467 23133 std::any ASTBuilder::visitStmtLst(SpiceParser::StmtLstContext *ctx) {
468 23133 const auto stmtLstNode = createNode<StmtLstNode>(ctx);
469
470 // Enrich
471
2/4
✓ Branch 3 → 4 taken 23133 times.
✗ Branch 3 → 116 not taken.
✓ Branch 4 → 5 taken 23133 times.
✗ Branch 4 → 116 not taken.
23133 stmtLstNode->closingBraceCodeLoc = CodeLoc(ctx->getStop(), sourceFile);
472
473 // Visit children
474
2/2
✓ Branch 105 → 7 taken 88681 times.
✓ Branch 105 → 106 taken 23129 times.
111810 for (ParserRuleContext::ParseTree *stmt : ctx->children) {
475
3/4
✓ Branch 8 → 9 taken 88681 times.
✗ Branch 8 → 10 not taken.
✓ Branch 11 → 12 taken 32032 times.
✓ Branch 11 → 17 taken 56649 times.
88681 if (auto *stmtCtx = dynamic_cast<SpiceParser::StmtContext *>(stmt))
476
4/6
✓ Branch 12 → 13 taken 32028 times.
✓ Branch 12 → 119 taken 4 times.
✓ Branch 13 → 14 taken 32028 times.
✗ Branch 13 → 117 not taken.
✓ Branch 14 → 15 taken 32028 times.
✗ Branch 14 → 117 not taken.
32032 stmtLstNode->statements.push_back(std::any_cast<StmtNode *>(visit(stmtCtx)));
477
3/4
✓ Branch 17 → 18 taken 56649 times.
✗ Branch 17 → 19 not taken.
✓ Branch 20 → 21 taken 1473 times.
✓ Branch 20 → 26 taken 55176 times.
56649 else if (auto *forLoopCtx = dynamic_cast<SpiceParser::ForLoopContext *>(stmt))
478
3/6
✓ Branch 21 → 22 taken 1473 times.
✗ Branch 21 → 123 not taken.
✓ Branch 22 → 23 taken 1473 times.
✗ Branch 22 → 121 not taken.
✓ Branch 23 → 24 taken 1473 times.
✗ Branch 23 → 121 not taken.
1473 stmtLstNode->statements.push_back(std::any_cast<ForLoopNode *>(visit(forLoopCtx)));
479
3/4
✓ Branch 26 → 27 taken 55176 times.
✗ Branch 26 → 28 not taken.
✓ Branch 29 → 30 taken 124 times.
✓ Branch 29 → 35 taken 55052 times.
55176 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 55052 times.
✗ Branch 35 → 37 not taken.
✓ Branch 38 → 39 taken 839 times.
✓ Branch 38 → 44 taken 54213 times.
55052 else if (auto *whileLoopCtx = dynamic_cast<SpiceParser::WhileLoopContext *>(stmt))
482
3/6
✓ Branch 39 → 40 taken 839 times.
✗ Branch 39 → 131 not taken.
✓ Branch 40 → 41 taken 839 times.
✗ Branch 40 → 129 not taken.
✓ Branch 41 → 42 taken 839 times.
✗ Branch 41 → 129 not taken.
839 stmtLstNode->statements.push_back(std::any_cast<WhileLoopNode *>(visit(whileLoopCtx)));
483
3/4
✓ Branch 44 → 45 taken 54213 times.
✗ Branch 44 → 46 not taken.
✓ Branch 47 → 48 taken 8 times.
✓ Branch 47 → 53 taken 54205 times.
54213 else if (auto *doWhileLoopCtx = dynamic_cast<SpiceParser::DoWhileLoopContext *>(stmt))
484
3/6
✓ Branch 48 → 49 taken 8 times.
✗ Branch 48 → 135 not taken.
✓ Branch 49 → 50 taken 8 times.
✗ Branch 49 → 133 not taken.
✓ Branch 50 → 51 taken 8 times.
✗ Branch 50 → 133 not taken.
8 stmtLstNode->statements.push_back(std::any_cast<DoWhileLoopNode *>(visit(doWhileLoopCtx)));
485
3/4
✓ Branch 53 → 54 taken 54205 times.
✗ Branch 53 → 55 not taken.
✓ Branch 56 → 57 taken 4377 times.
✓ Branch 56 → 62 taken 49828 times.
54205 else if (auto *ifStmtCtx = dynamic_cast<SpiceParser::IfStmtContext *>(stmt))
486
3/6
✓ Branch 57 → 58 taken 4377 times.
✗ Branch 57 → 139 not taken.
✓ Branch 58 → 59 taken 4377 times.
✗ Branch 58 → 137 not taken.
✓ Branch 59 → 60 taken 4377 times.
✗ Branch 59 → 137 not taken.
4377 stmtLstNode->statements.push_back(std::any_cast<IfStmtNode *>(visit(ifStmtCtx)));
487
3/4
✓ Branch 62 → 63 taken 49828 times.
✗ Branch 62 → 64 not taken.
✓ Branch 65 → 66 taken 12 times.
✓ Branch 65 → 71 taken 49816 times.
49828 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 49816 times.
✗ Branch 71 → 73 not taken.
✓ Branch 74 → 75 taken 780 times.
✓ Branch 74 → 80 taken 49036 times.
49816 else if (auto *assetStmtCtx = dynamic_cast<SpiceParser::AssertStmtContext *>(stmt))
490
3/6
✓ Branch 75 → 76 taken 780 times.
✗ Branch 75 → 147 not taken.
✓ Branch 76 → 77 taken 780 times.
✗ Branch 76 → 145 not taken.
✓ Branch 77 → 78 taken 780 times.
✗ Branch 77 → 145 not taken.
780 stmtLstNode->statements.push_back(std::any_cast<AssertStmtNode *>(visit(assetStmtCtx)));
491
3/4
✓ Branch 80 → 81 taken 49036 times.
✗ Branch 80 → 82 not taken.
✓ Branch 83 → 84 taken 2741 times.
✓ Branch 83 → 89 taken 46295 times.
49036 else if (auto *unsafeBlockCtx = dynamic_cast<SpiceParser::UnsafeBlockContext *>(stmt))
492
3/6
✓ Branch 84 → 85 taken 2741 times.
✗ Branch 84 → 151 not taken.
✓ Branch 85 → 86 taken 2741 times.
✗ Branch 85 → 149 not taken.
✓ Branch 86 → 87 taken 2741 times.
✗ Branch 86 → 149 not taken.
2741 stmtLstNode->statements.push_back(std::any_cast<UnsafeBlockNode *>(visit(unsafeBlockCtx)));
493
3/4
✓ Branch 89 → 90 taken 46295 times.
✗ Branch 89 → 91 not taken.
✓ Branch 92 → 93 taken 33 times.
✓ Branch 92 → 98 taken 46262 times.
46295 else if (auto *anonymousScopeCtx = dynamic_cast<SpiceParser::AnonymousBlockStmtContext *>(stmt))
494
3/6
✓ Branch 93 → 94 taken 33 times.
✗ Branch 93 → 155 not taken.
✓ Branch 94 → 95 taken 33 times.
✗ Branch 94 → 153 not taken.
✓ Branch 95 → 96 taken 33 times.
✗ Branch 95 → 153 not taken.
33 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 23129 times.
✗ Branch 112 → 158 not taken.
23129 return concludeNode(stmtLstNode);
500 }
501
502 8152 std::any ASTBuilder::visitTypeLst(SpiceParser::TypeLstContext *ctx) {
503 8152 const auto typeLstNode = createNode<TypeLstNode>(ctx);
504
505 // Visit children
506
2/4
✓ Branch 3 → 4 taken 8152 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 8152 times.
✗ Branch 4 → 16 not taken.
8152 fetchChildrenIntoVector(typeLstNode->dataTypes, ctx->dataType());
507
508
1/2
✓ Branch 12 → 13 taken 8152 times.
✗ Branch 12 → 19 not taken.
8152 return concludeNode(typeLstNode);
509 }
510
511 1060 std::any ASTBuilder::visitTypeLstWithEllipsis(SpiceParser::TypeLstWithEllipsisContext *ctx) {
512 1060 const auto typeLstWithEllipsisNode = createNode<TypeLstWithEllipsisNode>(ctx);
513
514 // Visit children
515
3/6
✓ Branch 3 → 4 taken 1060 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 1060 times.
✗ Branch 4 → 20 not taken.
✓ Branch 5 → 6 taken 1060 times.
✗ Branch 5 → 18 not taken.
1060 typeLstWithEllipsisNode->typeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
516
517 // Set some flags
518 1060 typeLstWithEllipsisNode->hasEllipsis = ctx->ELLIPSIS() != nullptr;
519
520
1/2
✓ Branch 14 → 15 taken 1060 times.
✗ Branch 14 → 21 not taken.
1060 return concludeNode(typeLstWithEllipsisNode);
521 }
522
523 1006 std::any ASTBuilder::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ctx) {
524 1006 const auto typeAltsLstNode = createNode<TypeAltsLstNode>(ctx);
525
526 // Visit children
527
2/4
✓ Branch 3 → 4 taken 1006 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 1006 times.
✗ Branch 4 → 16 not taken.
1006 fetchChildrenIntoVector(typeAltsLstNode->dataTypes, ctx->dataType());
528
529
1/2
✓ Branch 12 → 13 taken 1006 times.
✗ Branch 12 → 19 not taken.
1006 return concludeNode(typeAltsLstNode);
530 }
531
532 9745 std::any ASTBuilder::visitParamLst(SpiceParser::ParamLstContext *ctx) {
533 9745 const auto paramLstNode = createNode<ParamLstNode>(ctx);
534
535 // Visit children
536
2/4
✓ Branch 3 → 4 taken 9745 times.
✗ Branch 3 → 24 not taken.
✓ Branch 4 → 5 taken 9745 times.
✗ Branch 4 → 22 not taken.
9745 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 14816 times.
✓ Branch 11 → 12 taken 9745 times.
24561 for (DeclStmtNode *declStmt : paramLstNode->params) {
540 14816 declStmt->isFctParam = true;
541 14816 declStmt->dataType->isParamType = true;
542 }
543
544
1/2
✓ Branch 18 → 19 taken 9745 times.
✗ Branch 18 → 25 not taken.
9745 return concludeNode(paramLstNode);
545 }
546
547 16109 std::any ASTBuilder::visitArgLst(SpiceParser::ArgLstContext *ctx) {
548 16109 const auto argLstNode = createNode<ArgLstNode>(ctx);
549
550 // Visit children
551
2/4
✓ Branch 3 → 4 taken 16109 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 16109 times.
✗ Branch 4 → 18 not taken.
16109 fetchChildrenIntoVector(argLstNode->args, ctx->assignExpr());
552 16109 argLstNode->argInfos.reserve(argLstNode->args.size());
553
554
1/2
✓ Branch 14 → 15 taken 16109 times.
✗ Branch 14 → 21 not taken.
16109 return concludeNode(argLstNode);
555 }
556
557 78 std::any ASTBuilder::visitEnumItemLst(SpiceParser::EnumItemLstContext *ctx) {
558 78 const auto enumItemLstNode = createNode<EnumItemLstNode>(ctx);
559
560 // Visit children
561
2/4
✓ Branch 3 → 4 taken 78 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 78 times.
✗ Branch 4 → 16 not taken.
78 fetchChildrenIntoVector(enumItemLstNode->items, ctx->enumItem());
562
563
1/2
✓ Branch 12 → 13 taken 78 times.
✗ Branch 12 → 19 not taken.
78 return concludeNode(enumItemLstNode);
564 }
565
566 1186 std::any ASTBuilder::visitEnumItem(SpiceParser::EnumItemContext *ctx) {
567 1186 const auto enumItemNode = createNode<EnumItemNode>(ctx);
568
569 // Enrich
570
2/4
✓ Branch 3 → 4 taken 1186 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 1186 times.
✗ Branch 4 → 22 not taken.
1186 enumItemNode->itemName = getIdentifier(ctx->TYPE_IDENTIFIER(), false);
571
2/2
✓ Branch 8 → 9 taken 856 times.
✓ Branch 8 → 12 taken 330 times.
1186 if (ctx->ASSIGN()) {
572 856 enumItemNode->itemValue = parseInt(ctx->INT_LIT());
573 856 enumItemNode->hasValue = true;
574 }
575
576
1/2
✓ Branch 18 → 19 taken 1186 times.
✗ Branch 18 → 23 not taken.
1186 return concludeNode(enumItemNode);
577 }
578
579 1587 std::any ASTBuilder::visitField(SpiceParser::FieldContext *ctx) {
580 1587 const auto fieldNode = createNode<FieldNode>(ctx);
581
582 // Enrich
583
2/4
✓ Branch 3 → 4 taken 1587 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 1587 times.
✗ Branch 4 → 29 not taken.
1587 fieldNode->fieldName = getIdentifier(ctx->IDENTIFIER(), false);
584
585 // Visit children
586
3/6
✓ Branch 7 → 8 taken 1587 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 1587 times.
✗ Branch 8 → 32 not taken.
✓ Branch 9 → 10 taken 1587 times.
✗ Branch 9 → 30 not taken.
1587 fieldNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
587 1587 fieldNode->dataType->setFieldTypeRecursive();
588
2/2
✓ Branch 13 → 14 taken 224 times.
✓ Branch 13 → 19 taken 1363 times.
1587 if (ctx->ternaryExpr())
589
3/6
✓ Branch 14 → 15 taken 224 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 224 times.
✗ Branch 15 → 35 not taken.
✓ Branch 16 → 17 taken 224 times.
✗ Branch 16 → 33 not taken.
224 fieldNode->defaultValue = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr()));
590
591
1/2
✓ Branch 25 → 26 taken 1587 times.
✗ Branch 25 → 36 not taken.
1587 return concludeNode(fieldNode);
592 }
593
594 243 std::any ASTBuilder::visitSignature(SpiceParser::SignatureContext *ctx) {
595 243 const auto signatureNode = createNode<SignatureNode>(ctx);
596
597 // Extract method name
598
2/4
✓ Branch 3 → 4 taken 243 times.
✗ Branch 3 → 73 not taken.
✓ Branch 4 → 5 taken 243 times.
✗ Branch 4 → 73 not taken.
243 signatureNode->methodName = getIdentifier(ctx->IDENTIFIER(), false);
599
600 // Visit children
601
2/2
✓ Branch 8 → 9 taken 14 times.
✓ Branch 8 → 14 taken 229 times.
243 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 189 times.
✓ Branch 15 → 22 taken 54 times.
243 if (ctx->F()) {
605 189 signatureNode->hasReturnType = true;
606 189 signatureNode->signatureType = SignatureNode::SignatureType::TYPE_FUNCTION;
607 189 signatureNode->signatureQualifiers = TypeQualifiers::of(TY_FUNCTION);
608
3/6
✓ Branch 17 → 18 taken 189 times.
✗ Branch 17 → 79 not taken.
✓ Branch 18 → 19 taken 189 times.
✗ Branch 18 → 79 not taken.
✓ Branch 19 → 20 taken 189 times.
✗ Branch 19 → 77 not taken.
189 signatureNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
609 } else {
610 54 signatureNode->signatureType = SignatureNode::SignatureType::TYPE_PROCEDURE;
611 54 signatureNode->signatureQualifiers = TypeQualifiers::of(TY_PROCEDURE);
612 }
613
10/16
✓ Branch 24 → 25 taken 189 times.
✓ Branch 24 → 28 taken 54 times.
✓ Branch 25 → 26 taken 189 times.
✗ Branch 25 → 80 not taken.
✓ Branch 28 → 29 taken 54 times.
✗ Branch 28 → 80 not taken.
✓ Branch 31 → 32 taken 54 times.
✓ Branch 31 → 33 taken 189 times.
✓ Branch 33 → 34 taken 189 times.
✓ Branch 33 → 35 taken 54 times.
✓ Branch 35 → 36 taken 123 times.
✓ Branch 35 → 41 taken 120 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
243 if (ctx->F() ? ctx->LESS().size() == 2 : ctx->LESS().size() == 1) {
614 123 signatureNode->hasTemplateTypes = true;
615
3/6
✓ Branch 36 → 37 taken 123 times.
✗ Branch 36 → 90 not taken.
✓ Branch 37 → 38 taken 123 times.
✗ Branch 37 → 90 not taken.
✓ Branch 38 → 39 taken 123 times.
✗ Branch 38 → 88 not taken.
123 signatureNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0)));
616 }
617
13/20
✓ Branch 41 → 42 taken 243 times.
✗ Branch 41 → 91 not taken.
✓ Branch 43 → 44 taken 241 times.
✓ Branch 43 → 48 taken 2 times.
✓ Branch 44 → 45 taken 241 times.
✗ Branch 44 → 91 not taken.
✓ Branch 46 → 47 taken 128 times.
✓ Branch 46 → 49 taken 113 times.
✓ Branch 47 → 48 taken 7 times.
✓ Branch 47 → 49 taken 121 times.
✓ Branch 50 → 51 taken 241 times.
✓ Branch 50 → 52 taken 2 times.
✓ Branch 52 → 53 taken 243 times.
✗ Branch 52 → 54 not taken.
✓ Branch 54 → 55 taken 9 times.
✓ Branch 54 → 63 taken 234 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
243 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 243 times.
✗ Branch 69 → 102 not taken.
243 return concludeNode(signatureNode);
623 }
624
625 32032 std::any ASTBuilder::visitStmt(SpiceParser::StmtContext *ctx) {
626
2/2
✓ Branch 3 → 4 taken 5729 times.
✓ Branch 3 → 11 taken 26303 times.
32032 if (ctx->declStmt())
627
5/8
✓ Branch 4 → 5 taken 5729 times.
✗ Branch 4 → 60 not taken.
✓ Branch 5 → 6 taken 5725 times.
✓ Branch 5 → 60 taken 4 times.
✓ Branch 6 → 7 taken 5725 times.
✗ Branch 6 → 58 not taken.
✓ Branch 7 → 8 taken 5725 times.
✗ Branch 7 → 58 not taken.
5729 return static_cast<StmtNode *>(std::any_cast<DeclStmtNode *>(visit(ctx->declStmt())));
628
2/2
✓ Branch 12 → 13 taken 15778 times.
✓ Branch 12 → 20 taken 10525 times.
26303 if (ctx->exprStmt())
629
4/8
✓ Branch 13 → 14 taken 15778 times.
✗ Branch 13 → 64 not taken.
✓ Branch 14 → 15 taken 15778 times.
✗ Branch 14 → 64 not taken.
✓ Branch 15 → 16 taken 15778 times.
✗ Branch 15 → 62 not taken.
✓ Branch 16 → 17 taken 15778 times.
✗ Branch 16 → 62 not taken.
15778 return static_cast<StmtNode *>(std::any_cast<ExprStmtNode *>(visit(ctx->exprStmt())));
630
2/2
✓ Branch 21 → 22 taken 10179 times.
✓ Branch 21 → 29 taken 346 times.
10525 if (ctx->returnStmt())
631
4/8
✓ Branch 22 → 23 taken 10179 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 10179 times.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 10179 times.
✗ Branch 24 → 66 not taken.
✓ Branch 25 → 26 taken 10179 times.
✗ Branch 25 → 66 not taken.
10179 return static_cast<StmtNode *>(std::any_cast<ReturnStmtNode *>(visit(ctx->returnStmt())));
632
2/2
✓ Branch 30 → 31 taken 127 times.
✓ Branch 30 → 38 taken 219 times.
346 if (ctx->breakStmt())
633
4/8
✓ Branch 31 → 32 taken 127 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 127 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 127 times.
✗ Branch 33 → 70 not taken.
✓ Branch 34 → 35 taken 127 times.
✗ Branch 34 → 70 not taken.
127 return static_cast<StmtNode *>(std::any_cast<BreakStmtNode *>(visit(ctx->breakStmt())));
634
2/2
✓ Branch 39 → 40 taken 213 times.
✓ Branch 39 → 47 taken 6 times.
219 if (ctx->continueStmt())
635
4/8
✓ Branch 40 → 41 taken 213 times.
✗ Branch 40 → 76 not taken.
✓ Branch 41 → 42 taken 213 times.
✗ Branch 41 → 76 not taken.
✓ Branch 42 → 43 taken 213 times.
✗ Branch 42 → 74 not taken.
✓ Branch 43 → 44 taken 213 times.
✗ Branch 43 → 74 not taken.
213 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 22148 std::any ASTBuilder::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) {
643 22148 const auto declStmtNode = createNode<DeclStmtNode>(ctx);
644
645 // Enrich
646
3/4
✓ Branch 3 → 4 taken 22148 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 22147 times.
✓ Branch 4 → 28 taken 1 time.
22148 declStmtNode->varName = getIdentifier(ctx->IDENTIFIER(), false);
647
648 // Visit children
649
4/6
✓ Branch 7 → 8 taken 22147 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 22146 times.
✓ Branch 8 → 31 taken 1 time.
✓ Branch 9 → 10 taken 22146 times.
✗ Branch 9 → 29 not taken.
22147 declStmtNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
650
2/2
✓ Branch 12 → 13 taken 7915 times.
✓ Branch 12 → 18 taken 14231 times.
22146 if (ctx->assignExpr()) {
651 7915 declStmtNode->hasAssignment = true;
652
4/6
✓ Branch 13 → 14 taken 7915 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 7913 times.
✓ Branch 14 → 34 taken 2 times.
✓ Branch 15 → 16 taken 7913 times.
✗ Branch 15 → 32 not taken.
7915 declStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
653 }
654
655
1/2
✓ Branch 24 → 25 taken 22144 times.
✗ Branch 24 → 35 not taken.
22144 return concludeNode(declStmtNode);
656 }
657
658 15778 std::any ASTBuilder::visitExprStmt(SpiceParser::ExprStmtContext *ctx) {
659 15778 const auto exprStmtNode = createNode<ExprStmtNode>(ctx);
660
661 // Enrich
662
3/6
✓ Branch 3 → 4 taken 15778 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 15778 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 15778 times.
✗ Branch 5 → 17 not taken.
15778 exprStmtNode->expr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
663
664
1/2
✓ Branch 13 → 14 taken 15778 times.
✗ Branch 13 → 20 not taken.
15778 return concludeNode(exprStmtNode);
665 }
666
667 32976 std::any ASTBuilder::visitQualifierLst(SpiceParser::QualifierLstContext *ctx) {
668 32976 const auto qualifierLstNode = createNode<QualifierLstNode>(ctx);
669
670 // Visit children
671
2/4
✓ Branch 3 → 4 taken 32976 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 32976 times.
✗ Branch 4 → 35 not taken.
32976 fetchChildrenIntoVector(qualifierLstNode->qualifiers, ctx->qualifier());
672
673 // Check if qualifier combination is invalid
674 32976 bool seenSignedOrUnsigned = false;
675
2/2
✓ Branch 24 → 8 taken 39688 times.
✓ Branch 24 → 25 taken 32975 times.
72663 for (const QualifierNode *qualifier : qualifierLstNode->qualifiers) {
676 // Check if we have both, signed and unsigned qualifier
677
2/2
✓ Branch 9 → 10 taken 39681 times.
✓ Branch 9 → 12 taken 7 times.
39688 if (qualifier->type != QualifierNode::QualifierType::TY_SIGNED &&
678
2/2
✓ Branch 10 → 11 taken 29833 times.
✓ Branch 10 → 12 taken 9848 times.
39681 qualifier->type != QualifierNode::QualifierType::TY_UNSIGNED)
679 29833 continue;
680
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 21 taken 9854 times.
9855 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 9854 seenSignedOrUnsigned = true;
683 }
684
685
1/2
✓ Branch 31 → 32 taken 32975 times.
✗ Branch 31 → 48 not taken.
32975 return concludeNode(qualifierLstNode);
686 }
687
688 39688 std::any ASTBuilder::visitQualifier(SpiceParser::QualifierContext *ctx) {
689 39688 const auto qualifierNode = createNode<QualifierNode>(ctx);
690
691
3/4
✓ Branch 6 → 7 taken 39688 times.
✗ Branch 6 → 8 not taken.
✓ Branch 32 → 5 taken 39688 times.
✓ Branch 32 → 33 taken 39688 times.
79376 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
692 39688 const auto token = spice_pointer_cast<TerminalNode *>(subTree);
693
2/4
✓ Branch 13 → 14 taken 39688 times.
✗ Branch 13 → 43 not taken.
✓ Branch 14 → 15 taken 39688 times.
✗ Branch 14 → 43 not taken.
39688 const size_t symbolType = token->getSymbol()->getType();
694
2/2
✓ Branch 15 → 16 taken 8442 times.
✓ Branch 15 → 17 taken 31246 times.
39688 if (symbolType == SpiceParser::CONST)
695 8442 qualifierNode->type = QualifierNode::QualifierType::TY_CONST;
696
2/2
✓ Branch 17 → 18 taken 7 times.
✓ Branch 17 → 19 taken 31239 times.
31246 else if (symbolType == SpiceParser::SIGNED)
697 7 qualifierNode->type = QualifierNode::QualifierType::TY_SIGNED;
698
2/2
✓ Branch 19 → 20 taken 9848 times.
✓ Branch 19 → 21 taken 21391 times.
31239 else if (symbolType == SpiceParser::UNSIGNED)
699 9848 qualifierNode->type = QualifierNode::QualifierType::TY_UNSIGNED;
700
2/2
✓ Branch 21 → 22 taken 3446 times.
✓ Branch 21 → 23 taken 17945 times.
21391 else if (symbolType == SpiceParser::INLINE)
701 3446 qualifierNode->type = QualifierNode::QualifierType::TY_INLINE;
702
2/2
✓ Branch 23 → 24 taken 13598 times.
✓ Branch 23 → 25 taken 4347 times.
17945 else if (symbolType == SpiceParser::PUBLIC)
703 13598 qualifierNode->type = QualifierNode::QualifierType::TY_PUBLIC;
704
2/2
✓ Branch 25 → 26 taken 4334 times.
✓ Branch 25 → 27 taken 13 times.
4347 else if (symbolType == SpiceParser::HEAP)
705 4334 qualifierNode->type = QualifierNode::QualifierType::TY_HEAP;
706
1/2
✓ Branch 27 → 28 taken 13 times.
✗ Branch 27 → 29 not taken.
13 else if (symbolType == SpiceParser::COMPOSE)
707 13 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 39688 times.
✗ Branch 39 → 44 not taken.
39688 return concludeNode(qualifierNode);
713 }
714
715 381 std::any ASTBuilder::visitModAttr(SpiceParser::ModAttrContext *ctx) {
716 381 const auto modAttrNode = createNode<ModAttrNode>(ctx);
717
718 // Visit children
719
4/6
✓ Branch 3 → 4 taken 381 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 380 times.
✓ Branch 4 → 25 taken 1 time.
✓ Branch 5 → 6 taken 380 times.
✗ Branch 5 → 23 not taken.
381 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 668 times.
✓ Branch 12 → 13 taken 380 times.
1048 for (AttrNode *attr : modAttrNode->attrLst->attributes)
723 668 attr->target = AttrNode::TARGET_MODULE;
724
725
1/2
✓ Branch 19 → 20 taken 380 times.
✗ Branch 19 → 26 not taken.
380 return concludeNode(modAttrNode);
726 }
727
728 489 std::any ASTBuilder::visitTopLevelDefAttr(SpiceParser::TopLevelDefAttrContext *ctx) {
729 489 const auto fctAttrNode = createNode<TopLevelDefinitionAttrNode>(ctx);
730
731 // Visit children
732
3/6
✓ Branch 3 → 4 taken 489 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 489 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 489 times.
✗ Branch 5 → 17 not taken.
489 fctAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
733
734
1/2
✓ Branch 13 → 14 taken 489 times.
✗ Branch 13 → 20 not taken.
489 return concludeNode(fctAttrNode);
735 }
736
737 5 std::any ASTBuilder::visitLambdaAttr(SpiceParser::LambdaAttrContext *ctx) {
738 5 const auto lambdaAttrNode = createNode<LambdaAttrNode>(ctx);
739
740 // Visit children
741
3/6
✓ Branch 3 → 4 taken 5 times.
✗ Branch 3 → 25 not taken.
✓ Branch 4 → 5 taken 5 times.
✗ Branch 4 → 25 not taken.
✓ Branch 5 → 6 taken 5 times.
✗ Branch 5 → 23 not taken.
5 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 5 times.
✓ Branch 12 → 13 taken 5 times.
10 for (AttrNode *attr : lambdaAttrNode->attrLst->attributes)
745 5 attr->target = AttrNode::TARGET_LAMBDA;
746
747
1/2
✓ Branch 19 → 20 taken 5 times.
✗ Branch 19 → 26 not taken.
5 return concludeNode(lambdaAttrNode);
748 }
749
750 875 std::any ASTBuilder::visitAttrLst(SpiceParser::AttrLstContext *ctx) {
751 875 const auto attrLstNode = createNode<AttrLstNode>(ctx);
752
753 // Visit children
754
3/4
✓ Branch 3 → 4 taken 875 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 874 times.
✓ Branch 4 → 16 taken 1 time.
876 fetchChildrenIntoVector(attrLstNode->attributes, ctx->attr());
755
756
1/2
✓ Branch 12 → 13 taken 874 times.
✗ Branch 12 → 19 not taken.
874 return concludeNode(attrLstNode);
757 }
758
759 1168 std::any ASTBuilder::visitAttr(SpiceParser::AttrContext *ctx) {
760 1168 const auto attrNode = createNode<AttrNode>(ctx);
761
762 // Extract key
763
3/4
✓ Branch 3 → 4 taken 1168 times.
✗ Branch 3 → 66 not taken.
✓ Branch 16 → 6 taken 2863 times.
✓ Branch 16 → 17 taken 1168 times.
4031 for (const TerminalNode *keyFragment : ctx->IDENTIFIER()) {
764
2/2
✓ Branch 8 → 9 taken 1695 times.
✓ Branch 8 → 10 taken 1168 times.
2863 if (!attrNode->key.empty())
765
1/2
✓ Branch 9 → 10 taken 1695 times.
✗ Branch 9 → 64 not taken.
1695 attrNode->key += MEMBER_ACCESS_TOKEN;
766
3/6
✓ Branch 10 → 11 taken 2863 times.
✗ Branch 10 → 63 not taken.
✓ Branch 11 → 12 taken 2863 times.
✗ Branch 11 → 63 not taken.
✓ Branch 12 → 13 taken 2863 times.
✗ Branch 12 → 61 not taken.
2863 attrNode->key += keyFragment->getSymbol()->getText();
767 1168 }
768
769 // Visit children
770
2/2
✓ Branch 19 → 20 taken 815 times.
✓ Branch 19 → 50 taken 353 times.
1168 if (ctx->constant()) {
771
3/6
✓ Branch 20 → 21 taken 815 times.
✗ Branch 20 → 69 not taken.
✓ Branch 21 → 22 taken 815 times.
✗ Branch 21 → 69 not taken.
✓ Branch 22 → 23 taken 815 times.
✗ Branch 22 → 67 not taken.
815 attrNode->value = std::any_cast<ConstantNode *>(visit(ctx->constant()));
772
773
2/2
✓ Branch 26 → 27 taken 301 times.
✓ Branch 26 → 28 taken 514 times.
815 if (ctx->constant()->STRING_LIT())
774 301 attrNode->type = AttrNode::AttrType::TYPE_STRING;
775
2/2
✓ Branch 30 → 31 taken 78 times.
✓ Branch 30 → 32 taken 436 times.
514 else if (ctx->constant()->INT_LIT())
776 78 attrNode->type = AttrNode::AttrType::TYPE_INT;
777
6/6
✓ Branch 34 → 35 taken 5 times.
✓ Branch 34 → 38 taken 431 times.
✓ Branch 37 → 38 taken 4 times.
✓ Branch 37 → 39 taken 1 time.
✓ Branch 40 → 41 taken 435 times.
✓ Branch 40 → 42 taken 1 time.
436 else if (ctx->constant()->TRUE() || ctx->constant()->FALSE())
778 435 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 353 attrNode->type = AttrNode::AttrType::TYPE_BOOL;
784 }
785
786
1/2
✓ Branch 57 → 58 taken 1167 times.
✗ Branch 57 → 79 not taken.
1167 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 10179 std::any ASTBuilder::visitReturnStmt(SpiceParser::ReturnStmtContext *ctx) {
823 10179 const auto returnStmtNode = createNode<ReturnStmtNode>(ctx);
824
825 // Visit children
826
2/2
✓ Branch 4 → 5 taken 9930 times.
✓ Branch 4 → 10 taken 249 times.
10179 if (ctx->assignExpr()) {
827 9930 returnStmtNode->hasReturnValue = true;
828
3/6
✓ Branch 5 → 6 taken 9930 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 9930 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 9930 times.
✗ Branch 7 → 20 not taken.
9930 returnStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
829 }
830
831
1/2
✓ Branch 16 → 17 taken 10179 times.
✗ Branch 16 → 23 not taken.
10179 return concludeNode(returnStmtNode);
832 }
833
834 127 std::any ASTBuilder::visitBreakStmt(SpiceParser::BreakStmtContext *ctx) {
835 127 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 121 times.
127 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 127 times.
✗ Branch 10 → 25 not taken.
127 visitChildren(ctx);
843
844
1/2
✓ Branch 18 → 19 taken 127 times.
✗ Branch 18 → 26 not taken.
127 return concludeNode(breakStmtNode);
845 }
846
847 213 std::any ASTBuilder::visitContinueStmt(SpiceParser::ContinueStmtContext *ctx) {
848 213 const auto continueStmtNode = createNode<ContinueStmtNode>(ctx);
849
850 // Extract number of continues
851
2/2
✓ Branch 4 → 5 taken 212 times.
✓ Branch 4 → 10 taken 1 time.
213 if (ctx->INT_LIT())
852
3/6
✓ Branch 5 → 6 taken 212 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 212 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 212 times.
✗ Branch 7 → 22 not taken.
212 continueStmtNode->continueTimes = std::stoi(ctx->INT_LIT()->toString());
853
854 // Visit children
855
1/2
✓ Branch 10 → 11 taken 213 times.
✗ Branch 10 → 25 not taken.
213 visitChildren(ctx);
856
857
1/2
✓ Branch 18 → 19 taken 213 times.
✗ Branch 18 → 26 not taken.
213 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 780 std::any ASTBuilder::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) {
870
1/2
✓ Branch 2 → 3 taken 780 times.
✗ Branch 2 → 30 not taken.
780 const auto assertStmtNode = createNode<AssertStmtNode>(ctx);
871
872 // Enrich
873
5/10
✓ Branch 3 → 4 taken 780 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 780 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 780 times.
✗ Branch 5 → 30 not taken.
✓ Branch 6 → 7 taken 780 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 780 times.
✗ Branch 7 → 30 not taken.
780 const antlr4::misc::Interval interval(ctx->assignExpr()->start->getStartIndex(), ctx->assignExpr()->stop->getStopIndex());
874
1/2
✓ Branch 8 → 9 taken 780 times.
✗ Branch 8 → 25 not taken.
780 assertStmtNode->expressionString = inputStream->getText(interval);
875
876 // Visit children
877
3/6
✓ Branch 11 → 12 taken 780 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 13 taken 780 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 780 times.
✗ Branch 13 → 26 not taken.
780 assertStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
878
879
1/2
✓ Branch 21 → 22 taken 780 times.
✗ Branch 21 → 29 not taken.
780 return concludeNode(assertStmtNode);
880 }
881
882 84778 std::any ASTBuilder::visitAssignExpr(SpiceParser::AssignExprContext *ctx) {
883
2/2
✓ Branch 3 → 4 taken 76586 times.
✓ Branch 3 → 6 taken 8192 times.
84778 if (!ctx->assignOp())
884 76586 return visit(ctx->ternaryExpr());
885
886 8192 const auto assignExprNode = createNode<AssignExprNode>(ctx);
887
888 // Visit children
889
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 8192 times.
8192 if (ctx->ternaryExpr()) {
890 assignExprNode->ternaryExpr = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr()));
891
1/2
✓ Branch 15 → 16 taken 8192 times.
✗ Branch 15 → 28 not taken.
8192 } else if (ctx->prefixUnaryExpr()) {
892
3/6
✓ Branch 16 → 17 taken 8192 times.
✗ Branch 16 → 44 not taken.
✓ Branch 17 → 18 taken 8192 times.
✗ Branch 17 → 44 not taken.
✓ Branch 18 → 19 taken 8192 times.
✗ Branch 18 → 42 not taken.
8192 assignExprNode->lhs = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr()));
893
2/4
✓ Branch 20 → 21 taken 8192 times.
✗ Branch 20 → 45 not taken.
✓ Branch 21 → 22 taken 8192 times.
✗ Branch 21 → 45 not taken.
8192 visit(ctx->assignOp());
894
3/6
✓ Branch 23 → 24 taken 8192 times.
✗ Branch 23 → 48 not taken.
✓ Branch 24 → 25 taken 8192 times.
✗ Branch 24 → 48 not taken.
✓ Branch 25 → 26 taken 8192 times.
✗ Branch 25 → 46 not taken.
8192 assignExprNode->rhs = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
895 } else {
896 assert_fail("Invalid assign expression"); // GCOV_EXCL_LINE
897 }
898
899
1/2
✓ Branch 35 → 36 taken 8192 times.
✗ Branch 35 → 49 not taken.
8192 return concludeExprNode(assignExprNode);
900 }
901
902 76810 std::any ASTBuilder::visitTernaryExpr(SpiceParser::TernaryExprContext *ctx) {
903
3/4
✓ Branch 2 → 3 taken 76810 times.
✗ Branch 2 → 45 not taken.
✓ Branch 5 → 6 taken 76316 times.
✓ Branch 5 → 8 taken 494 times.
76810 if (ctx->logicalOrExpr().size() == 1)
904 76316 return visit(ctx->logicalOrExpr(0));
905
906 494 const auto ternaryExprNode = createNode<TernaryExprNode>(ctx);
907
908
3/6
✓ Branch 9 → 10 taken 494 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 494 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 494 times.
✗ Branch 11 → 46 not taken.
494 ternaryExprNode->condition = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(0)));
909
3/4
✓ Branch 13 → 14 taken 494 times.
✗ Branch 13 → 49 not taken.
✓ Branch 16 → 17 taken 493 times.
✓ Branch 16 → 26 taken 1 time.
494 if (ctx->logicalOrExpr().size() == 3) {
910
3/6
✓ Branch 17 → 18 taken 493 times.
✗ Branch 17 → 52 not taken.
✓ Branch 18 → 19 taken 493 times.
✗ Branch 18 → 52 not taken.
✓ Branch 19 → 20 taken 493 times.
✗ Branch 19 → 50 not taken.
493 ternaryExprNode->trueExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(1)));
911
3/6
✓ Branch 21 → 22 taken 493 times.
✗ Branch 21 → 55 not taken.
✓ Branch 22 → 23 taken 493 times.
✗ Branch 22 → 55 not taken.
✓ Branch 23 → 24 taken 493 times.
✗ Branch 23 → 53 not taken.
493 ternaryExprNode->falseExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(2)));
912
2/4
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 56 not taken.
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 35 not taken.
1 } else if (ctx->logicalOrExpr().size() == 2) {
913 1 ternaryExprNode->isShortened = true;
914
3/6
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 59 not taken.
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 59 not taken.
✓ Branch 32 → 33 taken 1 time.
✗ Branch 32 → 57 not taken.
1 ternaryExprNode->falseExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(1)));
915 }
916
917
1/2
✓ Branch 41 → 42 taken 494 times.
✗ Branch 41 → 60 not taken.
494 return concludeExprNode(ternaryExprNode);
918 }
919
920 77797 std::any ASTBuilder::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext *ctx) {
921
3/4
✓ Branch 2 → 3 taken 77797 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 76737 times.
✓ Branch 5 → 8 taken 1060 times.
77797 if (ctx->logicalAndExpr().size() == 1)
922 76737 return visit(ctx->logicalAndExpr(0));
923
924 1060 const auto logicalOrExprNode = createNode<LogicalOrExprNode>(ctx);
925
926 // Visit children
927
2/4
✓ Branch 9 → 10 taken 1060 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 1060 times.
✗ Branch 10 → 23 not taken.
1060 fetchChildrenIntoVector(logicalOrExprNode->operands, ctx->logicalAndExpr());
928
929
1/2
✓ Branch 18 → 19 taken 1060 times.
✗ Branch 18 → 26 not taken.
1060 return concludeExprNode(logicalOrExprNode);
930 }
931
932 79164 std::any ASTBuilder::visitLogicalAndExpr(SpiceParser::LogicalAndExprContext *ctx) {
933
3/4
✓ Branch 2 → 3 taken 79164 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 78897 times.
✓ Branch 5 → 8 taken 267 times.
79164 if (ctx->bitwiseOrExpr().size() == 1)
934 78897 return visit(ctx->bitwiseOrExpr(0));
935
936 267 const auto logicalAndExprNode = createNode<LogicalAndExprNode>(ctx);
937
938 // Visit children
939
2/4
✓ Branch 9 → 10 taken 267 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 267 times.
✗ Branch 10 → 23 not taken.
267 fetchChildrenIntoVector(logicalAndExprNode->operands, ctx->bitwiseOrExpr());
940
941
1/2
✓ Branch 18 → 19 taken 267 times.
✗ Branch 18 → 26 not taken.
267 return concludeExprNode(logicalAndExprNode);
942 }
943
944 79465 std::any ASTBuilder::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext *ctx) {
945
3/4
✓ Branch 2 → 3 taken 79465 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 79379 times.
✓ Branch 5 → 8 taken 86 times.
79465 if (ctx->bitwiseXorExpr().size() == 1)
946 79379 return visit(ctx->bitwiseXorExpr(0));
947
948 86 const auto bitwiseOrExprNode = createNode<BitwiseOrExprNode>(ctx);
949
950 // Visit children
951
2/4
✓ Branch 9 → 10 taken 86 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 86 times.
✗ Branch 10 → 23 not taken.
86 fetchChildrenIntoVector(bitwiseOrExprNode->operands, ctx->bitwiseXorExpr());
952
953
1/2
✓ Branch 18 → 19 taken 86 times.
✗ Branch 18 → 26 not taken.
86 return concludeExprNode(bitwiseOrExprNode);
954 }
955
956 79552 std::any ASTBuilder::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprContext *ctx) {
957
3/4
✓ Branch 2 → 3 taken 79552 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 79541 times.
✓ Branch 5 → 8 taken 11 times.
79552 if (ctx->bitwiseAndExpr().size() == 1)
958 79541 return visit(ctx->bitwiseAndExpr(0));
959
960 11 const auto bitwiseXorExprNode = createNode<BitwiseXorExprNode>(ctx);
961
962 // Visit children
963
2/4
✓ Branch 9 → 10 taken 11 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 11 times.
✗ Branch 10 → 23 not taken.
11 fetchChildrenIntoVector(bitwiseXorExprNode->operands, ctx->bitwiseAndExpr());
964
965
1/2
✓ Branch 18 → 19 taken 11 times.
✗ Branch 18 → 26 not taken.
11 return concludeExprNode(bitwiseXorExprNode);
966 }
967
968 79564 std::any ASTBuilder::visitBitwiseAndExpr(SpiceParser::BitwiseAndExprContext *ctx) {
969
3/4
✓ Branch 2 → 3 taken 79564 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 79530 times.
✓ Branch 5 → 8 taken 34 times.
79564 if (ctx->equalityExpr().size() == 1)
970 79530 return visit(ctx->equalityExpr(0));
971
972 34 const auto bitwiseAndExprNode = createNode<BitwiseAndExprNode>(ctx);
973
974 // Visit children
975
2/4
✓ Branch 9 → 10 taken 34 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 34 times.
✗ Branch 10 → 23 not taken.
34 fetchChildrenIntoVector(bitwiseAndExprNode->operands, ctx->equalityExpr());
976
977
1/2
✓ Branch 18 → 19 taken 34 times.
✗ Branch 18 → 26 not taken.
34 return concludeExprNode(bitwiseAndExprNode);
978 }
979
980 79599 std::any ASTBuilder::visitEqualityExpr(SpiceParser::EqualityExprContext *ctx) {
981
3/4
✓ Branch 2 → 3 taken 79599 times.
✗ Branch 2 → 28 not taken.
✓ Branch 5 → 6 taken 74058 times.
✓ Branch 5 → 8 taken 5541 times.
79599 if (ctx->relationalExpr().size() == 1)
982 74058 return visit(ctx->relationalExpr(0));
983
984 5541 const auto equalityExprNode = createNode<EqualityExprNode>(ctx);
985
986 // Visit children
987
2/4
✓ Branch 9 → 10 taken 5541 times.
✗ Branch 9 → 31 not taken.
✓ Branch 10 → 11 taken 5541 times.
✗ Branch 10 → 29 not taken.
5541 fetchChildrenIntoVector(equalityExprNode->operands, ctx->relationalExpr());
988
989 // Extract operator
990
2/2
✓ Branch 13 → 14 taken 4084 times.
✓ Branch 13 → 15 taken 1457 times.
5541 if (ctx->EQUAL())
991 4084 equalityExprNode->op = EqualityExprNode::EqualityOp::OP_EQUAL;
992
1/2
✓ Branch 16 → 17 taken 1457 times.
✗ Branch 16 → 18 not taken.
1457 else if (ctx->NOT_EQUAL())
993 1457 equalityExprNode->op = EqualityExprNode::EqualityOp::OP_NOT_EQUAL;
994
995
1/2
✓ Branch 24 → 25 taken 5541 times.
✗ Branch 24 → 32 not taken.
5541 return concludeExprNode(equalityExprNode);
996 }
997
998 85140 std::any ASTBuilder::visitRelationalExpr(SpiceParser::RelationalExprContext *ctx) {
999
3/4
✓ Branch 2 → 3 taken 85140 times.
✗ Branch 2 → 34 not taken.
✓ Branch 5 → 6 taken 80944 times.
✓ Branch 5 → 8 taken 4196 times.
85140 if (ctx->shiftExpr().size() == 1)
1000 80944 return visit(ctx->shiftExpr(0));
1001
1002 4196 const auto relationalExprNode = createNode<RelationalExprNode>(ctx);
1003
1004 // Visit children
1005
2/4
✓ Branch 9 → 10 taken 4196 times.
✗ Branch 9 → 37 not taken.
✓ Branch 10 → 11 taken 4196 times.
✗ Branch 10 → 35 not taken.
4196 fetchChildrenIntoVector(relationalExprNode->operands, ctx->shiftExpr());
1006
1007 // Extract operator
1008
2/2
✓ Branch 13 → 14 taken 2213 times.
✓ Branch 13 → 15 taken 1983 times.
4196 if (ctx->LESS())
1009 2213 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS;
1010
2/2
✓ Branch 16 → 17 taken 731 times.
✓ Branch 16 → 18 taken 1252 times.
1983 else if (ctx->GREATER())
1011 731 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER;
1012
2/2
✓ Branch 19 → 20 taken 367 times.
✓ Branch 19 → 21 taken 885 times.
1252 else if (ctx->LESS_EQUAL())
1013 367 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS_EQUAL;
1014
1/2
✓ Branch 22 → 23 taken 885 times.
✗ Branch 22 → 24 not taken.
885 else if (ctx->GREATER_EQUAL())
1015 885 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER_EQUAL;
1016
1017
1/2
✓ Branch 30 → 31 taken 4196 times.
✗ Branch 30 → 38 not taken.
4196 return concludeExprNode(relationalExprNode);
1018 }
1019
1020 89336 std::any ASTBuilder::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) {
1021
3/4
✓ Branch 2 → 3 taken 89336 times.
✗ Branch 2 → 52 not taken.
✓ Branch 5 → 6 taken 89235 times.
✓ Branch 5 → 8 taken 101 times.
89336 if (ctx->additiveExpr().size() == 1)
1022 89235 return visit(ctx->additiveExpr(0));
1023
1024 101 const auto shiftExprNode = createNode<ShiftExprNode>(ctx);
1025
1026 // Visit children
1027
2/4
✓ Branch 9 → 10 taken 101 times.
✗ Branch 9 → 55 not taken.
✓ Branch 10 → 11 taken 101 times.
✗ Branch 10 → 53 not taken.
101 fetchChildrenIntoVector(shiftExprNode->operands, ctx->additiveExpr());
1028
1029 101 bool seenFirstLess = false;
1030 101 bool seenFirstGreater = false;
1031
2/2
✓ Branch 37 → 14 taken 500 times.
✓ Branch 37 → 38 taken 101 times.
601 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1032
1/2
✓ Branch 15 → 16 taken 500 times.
✗ Branch 15 → 17 not taken.
500 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1033
2/2
✓ Branch 18 → 19 taken 234 times.
✓ Branch 18 → 20 taken 266 times.
500 if (!terminal)
1034 234 continue;
1035
1036
4/6
✓ Branch 20 → 21 taken 266 times.
✗ Branch 20 → 60 not taken.
✓ Branch 21 → 22 taken 266 times.
✗ Branch 21 → 60 not taken.
✓ Branch 22 → 23 taken 156 times.
✓ Branch 22 → 27 taken 110 times.
266 if (terminal->getSymbol()->getType() == SpiceParser::LESS) {
1037
2/2
✓ Branch 23 → 24 taken 78 times.
✓ Branch 23 → 26 taken 78 times.
156 if (seenFirstLess)
1038
1/2
✓ Branch 24 → 25 taken 78 times.
✗ Branch 24 → 56 not taken.
78 shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_LEFT, TY_INVALID);
1039 156 seenFirstLess = !seenFirstLess;
1040 156 continue;
1041 }
1042
1043
3/6
✓ Branch 27 → 28 taken 110 times.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 110 times.
✗ Branch 28 → 60 not taken.
✓ Branch 29 → 30 taken 110 times.
✗ Branch 29 → 34 not taken.
110 if (terminal->getSymbol()->getType() == SpiceParser::GREATER) {
1044
2/2
✓ Branch 30 → 31 taken 55 times.
✓ Branch 30 → 33 taken 55 times.
110 if (seenFirstGreater)
1045
1/2
✓ Branch 31 → 32 taken 55 times.
✗ Branch 31 → 58 not taken.
55 shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT, TY_INVALID);
1046 110 seenFirstGreater = !seenFirstGreater;
1047 110 continue;
1048 }
1049
1050 assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE
1051 }
1052
2/4
✓ Branch 38 → 39 taken 101 times.
✗ Branch 38 → 41 not taken.
✓ Branch 39 → 40 taken 101 times.
✗ Branch 39 → 41 not taken.
101 assert(!seenFirstLess && !seenFirstGreater);
1053
1054
1/2
✓ Branch 48 → 49 taken 101 times.
✗ Branch 48 → 61 not taken.
101 return concludeExprNode(shiftExprNode);
1055 }
1056
1057 89469 std::any ASTBuilder::visitAdditiveExpr(SpiceParser::AdditiveExprContext *ctx) {
1058
3/4
✓ Branch 2 → 3 taken 89469 times.
✗ Branch 2 → 44 not taken.
✓ Branch 5 → 6 taken 85503 times.
✓ Branch 5 → 8 taken 3966 times.
89469 if (ctx->multiplicativeExpr().size() == 1)
1059 85503 return visit(ctx->multiplicativeExpr(0));
1060
1061 3966 const auto additiveExprNode = createNode<AdditiveExprNode>(ctx);
1062
1063 // Visit children
1064
2/4
✓ Branch 9 → 10 taken 3966 times.
✗ Branch 9 → 47 not taken.
✓ Branch 10 → 11 taken 3966 times.
✗ Branch 10 → 45 not taken.
3966 fetchChildrenIntoVector(additiveExprNode->operands, ctx->multiplicativeExpr());
1065
1066
2/2
✓ Branch 33 → 14 taken 12796 times.
✓ Branch 33 → 34 taken 3966 times.
16762 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1067
1/2
✓ Branch 15 → 16 taken 12796 times.
✗ Branch 15 → 17 not taken.
12796 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1068
2/2
✓ Branch 18 → 19 taken 8381 times.
✓ Branch 18 → 20 taken 4415 times.
12796 if (!terminal)
1069 8381 continue;
1070
1071
4/6
✓ Branch 20 → 21 taken 4415 times.
✗ Branch 20 → 52 not taken.
✓ Branch 21 → 22 taken 4415 times.
✗ Branch 21 → 52 not taken.
✓ Branch 22 → 23 taken 2670 times.
✓ Branch 22 → 25 taken 1745 times.
4415 if (terminal->getSymbol()->getType() == SpiceParser::PLUS)
1072
1/2
✓ Branch 23 → 24 taken 2670 times.
✗ Branch 23 → 48 not taken.
2670 additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_PLUS, TY_INVALID);
1073
3/6
✓ Branch 25 → 26 taken 1745 times.
✗ Branch 25 → 52 not taken.
✓ Branch 26 → 27 taken 1745 times.
✗ Branch 26 → 52 not taken.
✓ Branch 27 → 28 taken 1745 times.
✗ Branch 27 → 30 not taken.
1745 else if (terminal->getSymbol()->getType() == SpiceParser::MINUS)
1074
1/2
✓ Branch 28 → 29 taken 1745 times.
✗ Branch 28 → 50 not taken.
1745 additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_MINUS, TY_INVALID);
1075 else
1076 assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE
1077 }
1078
1079
1/2
✓ Branch 40 → 41 taken 3966 times.
✗ Branch 40 → 53 not taken.
3966 return concludeExprNode(additiveExprNode);
1080 }
1081
1082 93884 std::any ASTBuilder::visitMultiplicativeExpr(SpiceParser::MultiplicativeExprContext *ctx) {
1083
3/4
✓ Branch 2 → 3 taken 93884 times.
✗ Branch 2 → 49 not taken.
✓ Branch 5 → 6 taken 92478 times.
✓ Branch 5 → 8 taken 1406 times.
93884 if (ctx->castExpr().size() == 1)
1084 92478 return visit(ctx->castExpr(0));
1085
1086 1406 const auto multiplicativeExprNode = createNode<MultiplicativeExprNode>(ctx);
1087
1088 // Visit children
1089
2/4
✓ Branch 9 → 10 taken 1406 times.
✗ Branch 9 → 52 not taken.
✓ Branch 10 → 11 taken 1406 times.
✗ Branch 10 → 50 not taken.
1406 fetchChildrenIntoVector(multiplicativeExprNode->operands, ctx->castExpr());
1090
1091
2/2
✓ Branch 38 → 14 taken 4258 times.
✓ Branch 38 → 39 taken 1406 times.
5664 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1092
1/2
✓ Branch 15 → 16 taken 4258 times.
✗ Branch 15 → 17 not taken.
4258 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1093
2/2
✓ Branch 18 → 19 taken 2832 times.
✓ Branch 18 → 20 taken 1426 times.
4258 if (!terminal)
1094 2832 continue;
1095
1096
4/6
✓ Branch 20 → 21 taken 1426 times.
✗ Branch 20 → 59 not taken.
✓ Branch 21 → 22 taken 1426 times.
✗ Branch 21 → 59 not taken.
✓ Branch 22 → 23 taken 1061 times.
✓ Branch 22 → 25 taken 365 times.
1426 if (terminal->getSymbol()->getType() == SpiceParser::MUL)
1097
1/2
✓ Branch 23 → 24 taken 1061 times.
✗ Branch 23 → 53 not taken.
1061 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_MUL, TY_INVALID);
1098
4/6
✓ Branch 25 → 26 taken 365 times.
✗ Branch 25 → 59 not taken.
✓ Branch 26 → 27 taken 365 times.
✗ Branch 26 → 59 not taken.
✓ Branch 27 → 28 taken 152 times.
✓ Branch 27 → 30 taken 213 times.
365 else if (terminal->getSymbol()->getType() == SpiceParser::DIV)
1099
1/2
✓ Branch 28 → 29 taken 152 times.
✗ Branch 28 → 55 not taken.
152 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_DIV, TY_INVALID);
1100
3/6
✓ Branch 30 → 31 taken 213 times.
✗ Branch 30 → 59 not taken.
✓ Branch 31 → 32 taken 213 times.
✗ Branch 31 → 59 not taken.
✓ Branch 32 → 33 taken 213 times.
✗ Branch 32 → 35 not taken.
213 else if (terminal->getSymbol()->getType() == SpiceParser::REM)
1101
1/2
✓ Branch 33 → 34 taken 213 times.
✗ Branch 33 → 57 not taken.
213 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_REM, TY_INVALID);
1102 else
1103 assert_fail("Invalid terminal symbol for multiplicative expression"); // GCOV_EXCL_LINE
1104 }
1105
1106
1/2
✓ Branch 45 → 46 taken 1406 times.
✗ Branch 45 → 60 not taken.
1406 return concludeExprNode(multiplicativeExprNode);
1107 }
1108
1109 95310 std::any ASTBuilder::visitCastExpr(SpiceParser::CastExprContext *ctx) {
1110
2/2
✓ Branch 3 → 4 taken 92352 times.
✓ Branch 3 → 6 taken 2958 times.
95310 if (!ctx->CAST())
1111 92352 return visit(ctx->prefixUnaryExpr());
1112
1113 2958 const auto castExprNode = createNode<CastExprNode>(ctx);
1114
1115 // Visit children
1116
1/2
✓ Branch 8 → 9 taken 2958 times.
✗ Branch 8 → 18 not taken.
2958 if (ctx->dataType()) {
1117
3/6
✓ Branch 9 → 10 taken 2958 times.
✗ Branch 9 → 35 not taken.
✓ Branch 10 → 11 taken 2958 times.
✗ Branch 10 → 35 not taken.
✓ Branch 11 → 12 taken 2958 times.
✗ Branch 11 → 33 not taken.
2958 castExprNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1118
3/6
✓ Branch 13 → 14 taken 2958 times.
✗ Branch 13 → 38 not taken.
✓ Branch 14 → 15 taken 2958 times.
✗ Branch 14 → 38 not taken.
✓ Branch 15 → 16 taken 2958 times.
✗ Branch 15 → 36 not taken.
2958 castExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
1119 2958 castExprNode->isCast = true;
1120 } else {
1121 castExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr()));
1122 }
1123
1124
1/2
✓ Branch 29 → 30 taken 2958 times.
✗ Branch 29 → 42 not taken.
2958 return concludeExprNode(castExprNode);
1125 }
1126
1127 102052 std::any ASTBuilder::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprContext *ctx) {
1128
2/2
✓ Branch 3 → 4 taken 100544 times.
✓ Branch 3 → 6 taken 1508 times.
102052 if (!ctx->prefixUnaryExpr())
1129 100544 return visit(ctx->postfixUnaryExpr());
1130
1131 1508 const auto prefixUnaryExprNode = createNode<PrefixUnaryExprNode>(ctx);
1132
1133 // Visit children
1134
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 1508 times.
1508 if (ctx->postfixUnaryExpr()) {
1135 prefixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr()));
1136
1/2
✓ Branch 15 → 16 taken 1508 times.
✗ Branch 15 → 42 not taken.
1508 } else if (ctx->prefixUnaryExpr()) {
1137 // Extract operator
1138
2/2
✓ Branch 17 → 18 taken 82 times.
✓ Branch 17 → 19 taken 1426 times.
1508 if (ctx->MINUS())
1139 82 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS;
1140
2/2
✓ Branch 20 → 21 taken 22 times.
✓ Branch 20 → 22 taken 1404 times.
1426 else if (ctx->PLUS_PLUS())
1141 22 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS;
1142
2/2
✓ Branch 23 → 24 taken 10 times.
✓ Branch 23 → 25 taken 1394 times.
1404 else if (ctx->MINUS_MINUS())
1143 10 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS;
1144
2/2
✓ Branch 26 → 27 taken 881 times.
✓ Branch 26 → 28 taken 513 times.
1394 else if (ctx->NOT())
1145 881 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT;
1146
2/2
✓ Branch 29 → 30 taken 2 times.
✓ Branch 29 → 31 taken 511 times.
513 else if (ctx->BITWISE_NOT())
1147 2 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT;
1148
2/2
✓ Branch 32 → 33 taken 255 times.
✓ Branch 32 → 34 taken 256 times.
511 else if (ctx->MUL())
1149 255 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE;
1150
1/2
✓ Branch 35 → 36 taken 256 times.
✗ Branch 35 → 37 not taken.
256 else if (ctx->BITWISE_AND())
1151 256 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF;
1152
1153
3/6
✓ Branch 37 → 38 taken 1508 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 1508 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 1508 times.
✗ Branch 39 → 56 not taken.
1508 prefixUnaryExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr()));
1154 } else {
1155 assert_fail("Unknown prefix unary expression type"); // GCOV_EXCL_LINE
1156 }
1157
1158
1/2
✓ Branch 49 → 50 taken 1508 times.
✗ Branch 49 → 59 not taken.
1508 return concludeExprNode(prefixUnaryExprNode);
1159 }
1160
1161 126758 std::any ASTBuilder::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprContext *ctx) {
1162
2/2
✓ Branch 3 → 4 taken 100544 times.
✓ Branch 3 → 6 taken 26214 times.
126758 if (!ctx->postfixUnaryExpr())
1163 100544 return visit(ctx->atomicExpr());
1164
1165 26214 const auto postfixUnaryExprNode = createNode<PostfixUnaryExprNode>(ctx);
1166
1167
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 26214 times.
26214 if (ctx->atomicExpr()) {
1168 postfixUnaryExprNode->atomicExpr = std::any_cast<ExprNode *>(visit(ctx->atomicExpr()));
1169
1/2
✓ Branch 15 → 16 taken 26214 times.
✗ Branch 15 → 40 not taken.
26214 } else if (ctx->postfixUnaryExpr()) {
1170
3/6
✓ Branch 16 → 17 taken 26214 times.
✗ Branch 16 → 56 not taken.
✓ Branch 17 → 18 taken 26214 times.
✗ Branch 17 → 56 not taken.
✓ Branch 18 → 19 taken 26214 times.
✗ Branch 18 → 54 not taken.
26214 postfixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr()));
1171
1172 // Extract operator
1173
2/2
✓ Branch 21 → 22 taken 4418 times.
✓ Branch 21 → 27 taken 21796 times.
26214 if (ctx->assignExpr()) {
1174 4418 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT;
1175
3/6
✓ Branch 22 → 23 taken 4418 times.
✗ Branch 22 → 59 not taken.
✓ Branch 23 → 24 taken 4418 times.
✗ Branch 23 → 59 not taken.
✓ Branch 24 → 25 taken 4418 times.
✗ Branch 24 → 57 not taken.
4418 postfixUnaryExprNode->subscriptIndexExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
1176
2/2
✓ Branch 28 → 29 taken 19245 times.
✓ Branch 28 → 34 taken 2551 times.
21796 } else if (ctx->IDENTIFIER()) {
1177 19245 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS;
1178
2/4
✓ Branch 29 → 30 taken 19245 times.
✗ Branch 29 → 60 not taken.
✓ Branch 30 → 31 taken 19245 times.
✗ Branch 30 → 60 not taken.
19245 postfixUnaryExprNode->identifier = getIdentifier(ctx->IDENTIFIER(), false);
1179
2/2
✓ Branch 35 → 36 taken 2016 times.
✓ Branch 35 → 37 taken 535 times.
2551 } else if (ctx->PLUS_PLUS()) {
1180 2016 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS;
1181
1/2
✓ Branch 38 → 39 taken 535 times.
✗ Branch 38 → 41 not taken.
535 } else if (ctx->MINUS_MINUS()) {
1182 535 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS;
1183 }
1184 } else {
1185 assert_fail("Unknown postfix unary expression type"); // GCOV_EXCL_LINE
1186 }
1187
1188
1/2
✓ Branch 47 → 48 taken 26214 times.
✗ Branch 47 → 61 not taken.
26214 return concludeExprNode(postfixUnaryExprNode);
1189 }
1190
1191 100544 std::any ASTBuilder::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) {
1192 100544 const auto atomicExprNode = createNode<AtomicExprNode>(ctx);
1193
1194 // Visit children
1195
2/2
✓ Branch 4 → 5 taken 19673 times.
✓ Branch 4 → 10 taken 80871 times.
100544 if (ctx->constant()) {
1196
4/6
✓ Branch 5 → 6 taken 19673 times.
✗ Branch 5 → 84 not taken.
✓ Branch 6 → 7 taken 19671 times.
✓ Branch 6 → 84 taken 2 times.
✓ Branch 7 → 8 taken 19671 times.
✗ Branch 7 → 82 not taken.
19673 atomicExprNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
1197
2/2
✓ Branch 11 → 12 taken 22036 times.
✓ Branch 11 → 17 taken 58835 times.
80871 } else if (ctx->value()) {
1198
3/6
✓ Branch 12 → 13 taken 22036 times.
✗ Branch 12 → 87 not taken.
✓ Branch 13 → 14 taken 22036 times.
✗ Branch 13 → 87 not taken.
✓ Branch 14 → 15 taken 22036 times.
✗ Branch 14 → 85 not taken.
22036 atomicExprNode->value = std::any_cast<ValueNode *>(visit(ctx->value()));
1199
11/18
✓ Branch 17 → 18 taken 58835 times.
✗ Branch 17 → 88 not taken.
✓ Branch 19 → 20 taken 2596 times.
✓ Branch 19 → 23 taken 56239 times.
✓ Branch 20 → 21 taken 2596 times.
✗ Branch 20 → 88 not taken.
✓ Branch 22 → 23 taken 1885 times.
✓ Branch 22 → 24 taken 711 times.
✓ Branch 25 → 26 taken 2596 times.
✓ Branch 25 → 27 taken 56239 times.
✓ Branch 27 → 28 taken 58835 times.
✗ Branch 27 → 29 not taken.
✓ Branch 29 → 30 taken 58124 times.
✓ Branch 29 → 64 taken 711 times.
✗ Branch 88 → 89 not taken.
✗ Branch 88 → 90 not taken.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 94 not taken.
58835 } else if (!ctx->IDENTIFIER().empty() || !ctx->TYPE_IDENTIFIER().empty()) {
1200
2/2
✓ Branch 62 → 32 taken 58776 times.
✓ Branch 62 → 63 taken 58124 times.
116900 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1201
1/2
✓ Branch 33 → 34 taken 58776 times.
✗ Branch 33 → 35 not taken.
58776 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1202
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 58776 times.
58776 if (!terminal)
1203 continue;
1204
1205
4/6
✓ Branch 38 → 39 taken 58776 times.
✗ Branch 38 → 102 not taken.
✓ Branch 39 → 40 taken 58776 times.
✗ Branch 39 → 102 not taken.
✓ Branch 40 → 41 taken 56239 times.
✓ Branch 40 → 49 taken 2537 times.
58776 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1206
1/2
✓ Branch 41 → 42 taken 56239 times.
✗ Branch 41 → 98 not taken.
56239 std::string fragment = getIdentifier(terminal, false);
1207
1/2
✓ Branch 42 → 43 taken 56239 times.
✗ Branch 42 → 96 not taken.
56239 atomicExprNode->identifierFragments.push_back(fragment);
1208
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 56239 times.
56239 if (!atomicExprNode->fqIdentifier.empty())
1209 atomicExprNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
1210
1/2
✓ Branch 46 → 47 taken 56239 times.
✗ Branch 46 → 96 not taken.
56239 atomicExprNode->fqIdentifier += fragment;
1211
4/6
✓ Branch 49 → 50 taken 2537 times.
✗ Branch 49 → 102 not taken.
✓ Branch 50 → 51 taken 2537 times.
✗ Branch 50 → 102 not taken.
✓ Branch 51 → 52 taken 2211 times.
✓ Branch 51 → 60 taken 326 times.
58776 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1212
1/2
✓ Branch 52 → 53 taken 2211 times.
✗ Branch 52 → 101 not taken.
2211 std::string fragment = getIdentifier(terminal, false);
1213
1/2
✓ Branch 53 → 54 taken 2211 times.
✗ Branch 53 → 99 not taken.
2211 atomicExprNode->identifierFragments.push_back(fragment);
1214
2/2
✓ Branch 55 → 56 taken 326 times.
✓ Branch 55 → 57 taken 1885 times.
2211 if (!atomicExprNode->fqIdentifier.empty())
1215
1/2
✓ Branch 56 → 57 taken 326 times.
✗ Branch 56 → 99 not taken.
326 atomicExprNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
1216
1/2
✓ Branch 57 → 58 taken 2211 times.
✗ Branch 57 → 99 not taken.
2211 atomicExprNode->fqIdentifier += fragment;
1217 2211 }
1218 }
1219
1/2
✓ Branch 65 → 66 taken 711 times.
✗ Branch 65 → 71 not taken.
711 } else if (ctx->assignExpr()) {
1220
3/6
✓ Branch 66 → 67 taken 711 times.
✗ Branch 66 → 105 not taken.
✓ Branch 67 → 68 taken 711 times.
✗ Branch 67 → 105 not taken.
✓ Branch 68 → 69 taken 711 times.
✗ Branch 68 → 103 not taken.
711 atomicExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
1221 } else {
1222 assert_fail("Unknown atomic expression type"); // GCOV_EXCL_LINE
1223 }
1224
1225
1/2
✓ Branch 78 → 79 taken 100542 times.
✗ Branch 78 → 106 not taken.
100542 return concludeExprNode(atomicExprNode);
1226 }
1227
1228 22036 std::any ASTBuilder::visitValue(SpiceParser::ValueContext *ctx) {
1229 22036 const auto valueNode = createNode<ValueNode>(ctx);
1230
1231 // Visit children
1232
2/2
✓ Branch 4 → 5 taken 20132 times.
✓ Branch 4 → 10 taken 1904 times.
22036 if (ctx->fctCall()) {
1233
3/6
✓ Branch 5 → 6 taken 20132 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 20132 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 20132 times.
✗ Branch 7 → 63 not taken.
20132 valueNode->fctCall = std::any_cast<FctCallNode *>(visit(ctx->fctCall()));
1234
2/2
✓ Branch 11 → 12 taken 75 times.
✓ Branch 11 → 17 taken 1829 times.
1904 } else if (ctx->arrayInitialization()) {
1235
3/6
✓ Branch 12 → 13 taken 75 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 75 times.
✗ Branch 13 → 68 not taken.
✓ Branch 14 → 15 taken 75 times.
✗ Branch 14 → 66 not taken.
75 valueNode->arrayInitialization = std::any_cast<ArrayInitializationNode *>(visit(ctx->arrayInitialization()));
1236
2/2
✓ Branch 18 → 19 taken 233 times.
✓ Branch 18 → 24 taken 1596 times.
1829 } else if (ctx->structInstantiation()) {
1237
3/6
✓ Branch 19 → 20 taken 233 times.
✗ Branch 19 → 71 not taken.
✓ Branch 20 → 21 taken 233 times.
✗ Branch 20 → 71 not taken.
✓ Branch 21 → 22 taken 233 times.
✗ Branch 21 → 69 not taken.
233 valueNode->structInstantiation = std::any_cast<StructInstantiationNode *>(visit(ctx->structInstantiation()));
1238
2/2
✓ Branch 25 → 26 taken 16 times.
✓ Branch 25 → 31 taken 1580 times.
1596 } else if (ctx->lambdaFunc()) {
1239
3/6
✓ Branch 26 → 27 taken 16 times.
✗ Branch 26 → 74 not taken.
✓ Branch 27 → 28 taken 16 times.
✗ Branch 27 → 74 not taken.
✓ Branch 28 → 29 taken 16 times.
✗ Branch 28 → 72 not taken.
16 valueNode->lambdaFunc = std::any_cast<LambdaFuncNode *>(visit(ctx->lambdaFunc()));
1240
2/2
✓ Branch 32 → 33 taken 20 times.
✓ Branch 32 → 38 taken 1560 times.
1580 } else if (ctx->lambdaProc()) {
1241
3/6
✓ Branch 33 → 34 taken 20 times.
✗ Branch 33 → 77 not taken.
✓ Branch 34 → 35 taken 20 times.
✗ Branch 34 → 77 not taken.
✓ Branch 35 → 36 taken 20 times.
✗ Branch 35 → 75 not taken.
20 valueNode->lambdaProc = std::any_cast<LambdaProcNode *>(visit(ctx->lambdaProc()));
1242
2/2
✓ Branch 39 → 40 taken 1 time.
✓ Branch 39 → 45 taken 1559 times.
1560 } else if (ctx->lambdaExpr()) {
1243
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()));
1244
1/2
✓ Branch 46 → 47 taken 1559 times.
✗ Branch 46 → 52 not taken.
1559 } else if (ctx->dataType()) {
1245 1559 valueNode->isNil = true;
1246
3/6
✓ Branch 47 → 48 taken 1559 times.
✗ Branch 47 → 83 not taken.
✓ Branch 48 → 49 taken 1559 times.
✗ Branch 48 → 83 not taken.
✓ Branch 49 → 50 taken 1559 times.
✗ Branch 49 → 81 not taken.
1559 valueNode->nilType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1247 } else {
1248 assert_fail("Unknown value type"); // GCOV_EXCL_LINE
1249 }
1250
1251
1/2
✓ Branch 59 → 60 taken 22036 times.
✗ Branch 59 → 84 not taken.
22036 return concludeNode(valueNode);
1252 }
1253
1254 21766 std::any ASTBuilder::visitConstant(SpiceParser::ConstantContext *ctx) {
1255 21766 const auto constantNode = createNode<ConstantNode>(ctx);
1256
1257 // Enrich
1258
2/2
✓ Branch 4 → 5 taken 693 times.
✓ Branch 4 → 10 taken 21073 times.
21766 if (ctx->DOUBLE_LIT()) {
1259 693 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_DOUBLE;
1260
3/6
✓ Branch 5 → 6 taken 693 times.
✗ Branch 5 → 59 not taken.
✓ Branch 6 → 7 taken 693 times.
✗ Branch 6 → 59 not taken.
✓ Branch 7 → 8 taken 693 times.
✗ Branch 7 → 57 not taken.
693 constantNode->compileTimeValue.doubleValue = std::stod(ctx->DOUBLE_LIT()->toString());
1261
2/2
✓ Branch 11 → 12 taken 4679 times.
✓ Branch 11 → 15 taken 16394 times.
21073 } else if (ctx->INT_LIT()) {
1262 4679 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_INT;
1263 4679 constantNode->compileTimeValue.intValue = parseInt(ctx->INT_LIT());
1264
2/2
✓ Branch 16 → 17 taken 882 times.
✓ Branch 16 → 20 taken 15512 times.
16394 } else if (ctx->SHORT_LIT()) {
1265 882 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_SHORT;
1266 882 constantNode->compileTimeValue.shortValue = parseShort(ctx->SHORT_LIT());
1267
2/2
✓ Branch 21 → 22 taken 6504 times.
✓ Branch 21 → 25 taken 9008 times.
15512 } else if (ctx->LONG_LIT()) {
1268 6504 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_LONG;
1269 6504 constantNode->compileTimeValue.longValue = parseLong(ctx->LONG_LIT());
1270
2/2
✓ Branch 26 → 27 taken 3027 times.
✓ Branch 26 → 30 taken 5981 times.
9008 } else if (ctx->CHAR_LIT()) {
1271 3027 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_CHAR;
1272 3027 constantNode->compileTimeValue.charValue = parseChar(ctx->CHAR_LIT());
1273
2/2
✓ Branch 31 → 32 taken 3670 times.
✓ Branch 31 → 40 taken 2311 times.
5981 } else if (ctx->STRING_LIT()) {
1274 // Save a pointer to the string in the compile time value
1275 3670 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_STRING;
1276 3670 constantNode->compileTimeValue.stringValueOffset = resourceManager.compileTimeStringValues.size();
1277 // Add the string to the global compile time string list
1278
4/8
✓ Branch 33 → 34 taken 3670 times.
✗ Branch 33 → 64 not taken.
✓ Branch 34 → 35 taken 3670 times.
✗ Branch 34 → 64 not taken.
✓ Branch 35 → 36 taken 3670 times.
✗ Branch 35 → 62 not taken.
✓ Branch 36 → 37 taken 3670 times.
✗ Branch 36 → 60 not taken.
3670 resourceManager.compileTimeStringValues.push_back(parseString(ctx->STRING_LIT()->toString()));
1279
2/2
✓ Branch 41 → 42 taken 1189 times.
✓ Branch 41 → 43 taken 1122 times.
2311 } else if (ctx->TRUE()) {
1280 1189 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL;
1281 1189 constantNode->compileTimeValue.boolValue = true;
1282
1/2
✓ Branch 44 → 45 taken 1122 times.
✗ Branch 44 → 46 not taken.
1122 } else if (ctx->FALSE()) {
1283 1122 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL;
1284 1122 constantNode->compileTimeValue.boolValue = false;
1285 } else {
1286 assert_fail("Unknown constant type"); // GCOV_EXCL_LINE
1287 }
1288
1289
1/2
✓ Branch 53 → 54 taken 21764 times.
✗ Branch 53 → 66 not taken.
21764 return concludeNode(constantNode);
1290 }
1291
1292 20132 std::any ASTBuilder::visitFctCall(SpiceParser::FctCallContext *ctx) {
1293 20132 const auto fctCallNode = createNode<FctCallNode>(ctx);
1294
1295
2/2
✓ Branch 37 → 5 taken 97283 times.
✓ Branch 37 → 38 taken 20132 times.
117415 for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) {
1296
1/2
✓ Branch 6 → 7 taken 97283 times.
✗ Branch 6 → 8 not taken.
97283 const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree);
1297
2/2
✓ Branch 9 → 10 taken 17239 times.
✓ Branch 9 → 11 taken 80044 times.
97283 if (!terminal)
1298 17239 continue;
1299
1300
4/6
✓ Branch 11 → 12 taken 80044 times.
✗ Branch 11 → 68 not taken.
✓ Branch 12 → 13 taken 80044 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 25423 times.
✓ Branch 13 → 19 taken 54621 times.
80044 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1301
1/2
✓ Branch 14 → 15 taken 25423 times.
✗ Branch 14 → 64 not taken.
25423 const std::string fragment = terminal->toString();
1302
1/2
✓ Branch 15 → 16 taken 25423 times.
✗ Branch 15 → 62 not taken.
25423 fctCallNode->functionNameFragments.push_back(fragment);
1303
1/2
✓ Branch 16 → 17 taken 25423 times.
✗ Branch 16 → 62 not taken.
25423 fctCallNode->fqFunctionName += fragment;
1304
4/6
✓ Branch 19 → 20 taken 54621 times.
✗ Branch 19 → 68 not taken.
✓ Branch 20 → 21 taken 54621 times.
✗ Branch 20 → 68 not taken.
✓ Branch 21 → 22 taken 3113 times.
✓ Branch 21 → 27 taken 51508 times.
80044 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1305
1/2
✓ Branch 22 → 23 taken 3113 times.
✗ Branch 22 → 67 not taken.
3113 const std::string fragment = terminal->toString();
1306
1/2
✓ Branch 23 → 24 taken 3113 times.
✗ Branch 23 → 65 not taken.
3113 fctCallNode->functionNameFragments.push_back(fragment);
1307
1/2
✓ Branch 24 → 25 taken 3113 times.
✗ Branch 24 → 65 not taken.
3113 fctCallNode->fqFunctionName += fragment;
1308
4/6
✓ Branch 27 → 28 taken 51508 times.
✗ Branch 27 → 68 not taken.
✓ Branch 28 → 29 taken 51508 times.
✗ Branch 28 → 68 not taken.
✓ Branch 29 → 30 taken 62 times.
✓ Branch 29 → 31 taken 51446 times.
54621 } else if (terminal->getSymbol()->getType() == SpiceParser::SCOPE_ACCESS) {
1309
1/2
✓ Branch 30 → 35 taken 62 times.
✗ Branch 30 → 68 not taken.
62 fctCallNode->fqFunctionName += SCOPE_ACCESS_TOKEN;
1310
4/6
✓ Branch 31 → 32 taken 51446 times.
✗ Branch 31 → 68 not taken.
✓ Branch 32 → 33 taken 51446 times.
✗ Branch 32 → 68 not taken.
✓ Branch 33 → 34 taken 8342 times.
✓ Branch 33 → 35 taken 43104 times.
51446 } else if (terminal->getSymbol()->getType() == SpiceParser::DOT) {
1311
1/2
✓ Branch 34 → 35 taken 8342 times.
✗ Branch 34 → 68 not taken.
8342 fctCallNode->fqFunctionName += MEMBER_ACCESS_TOKEN;
1312 }
1313 }
1314
1315 // Visit children
1316
2/2
✓ Branch 39 → 40 taken 1420 times.
✓ Branch 39 → 45 taken 18712 times.
20132 if (ctx->typeLst()) {
1317 1420 fctCallNode->hasTemplateTypes = true;
1318
3/6
✓ Branch 40 → 41 taken 1420 times.
✗ Branch 40 → 71 not taken.
✓ Branch 41 → 42 taken 1420 times.
✗ Branch 41 → 71 not taken.
✓ Branch 42 → 43 taken 1420 times.
✗ Branch 42 → 69 not taken.
1420 fctCallNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1319 }
1320
2/2
✓ Branch 46 → 47 taken 15819 times.
✓ Branch 46 → 52 taken 4313 times.
20132 if (ctx->argLst()) {
1321 15819 fctCallNode->hasArgs = true;
1322
3/6
✓ Branch 47 → 48 taken 15819 times.
✗ Branch 47 → 74 not taken.
✓ Branch 48 → 49 taken 15819 times.
✗ Branch 48 → 74 not taken.
✓ Branch 49 → 50 taken 15819 times.
✗ Branch 49 → 72 not taken.
15819 fctCallNode->argLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1323 }
1324
1325
1/2
✓ Branch 58 → 59 taken 20132 times.
✗ Branch 58 → 75 not taken.
20132 return concludeNode(fctCallNode);
1326 }
1327
1328 75 std::any ASTBuilder::visitArrayInitialization(SpiceParser::ArrayInitializationContext *ctx) {
1329 75 const auto arrayInitializationNode = createNode<ArrayInitializationNode>(ctx);
1330
1331 // Visit children
1332
2/2
✓ Branch 4 → 5 taken 74 times.
✓ Branch 4 → 10 taken 1 time.
75 if (ctx->argLst())
1333
3/6
✓ Branch 5 → 6 taken 74 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 74 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 74 times.
✗ Branch 7 → 20 not taken.
74 arrayInitializationNode->itemLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1334
1335
1/2
✓ Branch 16 → 17 taken 75 times.
✗ Branch 16 → 23 not taken.
75 return concludeNode(arrayInitializationNode);
1336 }
1337
1338 233 std::any ASTBuilder::visitStructInstantiation(SpiceParser::StructInstantiationContext *ctx) {
1339 233 const auto structInstantiationNode = createNode<StructInstantiationNode>(ctx);
1340
1341 // Enrich
1342
2/2
✓ Branch 31 → 5 taken 981 times.
✓ Branch 31 → 32 taken 233 times.
1214 for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) {
1343
1/2
✓ Branch 6 → 7 taken 981 times.
✗ Branch 6 → 8 not taken.
981 const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree);
1344
2/2
✓ Branch 9 → 10 taken 236 times.
✓ Branch 9 → 11 taken 745 times.
981 if (!terminal)
1345 236 continue;
1346
1347
4/6
✓ Branch 11 → 12 taken 745 times.
✗ Branch 11 → 65 not taken.
✓ Branch 12 → 13 taken 745 times.
✗ Branch 12 → 65 not taken.
✓ Branch 13 → 14 taken 3 times.
✓ Branch 13 → 21 taken 742 times.
745 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1348
1/2
✓ Branch 14 → 15 taken 3 times.
✗ Branch 14 → 61 not taken.
3 const std::string fragment = terminal->toString();
1349
1/2
✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 59 not taken.
3 structInstantiationNode->structNameFragments.push_back(fragment);
1350
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;
1351
4/6
✓ Branch 21 → 22 taken 742 times.
✗ Branch 21 → 65 not taken.
✓ Branch 22 → 23 taken 742 times.
✗ Branch 22 → 65 not taken.
✓ Branch 23 → 24 taken 233 times.
✓ Branch 23 → 29 taken 509 times.
745 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1352
1/2
✓ Branch 24 → 25 taken 233 times.
✗ Branch 24 → 64 not taken.
233 const std::string fragment = terminal->toString();
1353
1/2
✓ Branch 25 → 26 taken 233 times.
✗ Branch 25 → 62 not taken.
233 structInstantiationNode->structNameFragments.push_back(fragment);
1354
1/2
✓ Branch 26 → 27 taken 233 times.
✗ Branch 26 → 62 not taken.
233 structInstantiationNode->fqStructName += fragment;
1355 233 }
1356 }
1357
1358 // Visit children
1359
2/2
✓ Branch 33 → 34 taken 20 times.
✓ Branch 33 → 39 taken 213 times.
233 if (ctx->typeLst()) {
1360 20 structInstantiationNode->hasTemplateTypes = true;
1361
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()));
1362 }
1363
2/2
✓ Branch 40 → 41 taken 216 times.
✓ Branch 40 → 46 taken 17 times.
233 if (ctx->argLst())
1364
3/6
✓ Branch 41 → 42 taken 216 times.
✗ Branch 41 → 71 not taken.
✓ Branch 42 → 43 taken 216 times.
✗ Branch 42 → 71 not taken.
✓ Branch 43 → 44 taken 216 times.
✗ Branch 43 → 69 not taken.
216 structInstantiationNode->fieldLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1365
1366
1/2
✓ Branch 52 → 53 taken 233 times.
✗ Branch 52 → 72 not taken.
233 return concludeNode(structInstantiationNode);
1367 }
1368
1369 16 std::any ASTBuilder::visitLambdaFunc(SpiceParser::LambdaFuncContext *ctx) {
1370 16 const auto lambdaFuncNode = createNode<LambdaFuncNode>(ctx);
1371
1372 // Visit children
1373
3/6
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 16 times.
✗ Branch 4 → 37 not taken.
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 35 not taken.
16 lambdaFuncNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1374
2/2
✓ Branch 8 → 9 taken 12 times.
✓ Branch 8 → 14 taken 4 times.
16 if (ctx->paramLst()) {
1375 12 lambdaFuncNode->hasParams = true;
1376
3/6
✓ Branch 9 → 10 taken 12 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 12 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 12 times.
✗ Branch 11 → 38 not taken.
12 lambdaFuncNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1377 }
1378
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 21 taken 16 times.
16 if (ctx->lambdaAttr())
1379 lambdaFuncNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr()));
1380
3/6
✓ Branch 21 → 22 taken 16 times.
✗ Branch 21 → 46 not taken.
✓ Branch 22 → 23 taken 16 times.
✗ Branch 22 → 46 not taken.
✓ Branch 23 → 24 taken 16 times.
✗ Branch 23 → 44 not taken.
16 lambdaFuncNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
1381
1382
1/2
✓ Branch 31 → 32 taken 16 times.
✗ Branch 31 → 47 not taken.
16 return concludeNode(lambdaFuncNode);
1383 }
1384
1385 20 std::any ASTBuilder::visitLambdaProc(SpiceParser::LambdaProcContext *ctx) {
1386 20 const auto lambdaProcNode = createNode<LambdaProcNode>(ctx);
1387
1388 // Visit children
1389
2/2
✓ Branch 4 → 5 taken 11 times.
✓ Branch 4 → 10 taken 9 times.
20 if (ctx->paramLst()) {
1390 11 lambdaProcNode->hasParams = true;
1391
3/6
✓ Branch 5 → 6 taken 11 times.
✗ Branch 5 → 33 not taken.
✓ Branch 6 → 7 taken 11 times.
✗ Branch 6 → 33 not taken.
✓ Branch 7 → 8 taken 11 times.
✗ Branch 7 → 31 not taken.
11 lambdaProcNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1392 }
1393
2/2
✓ Branch 11 → 12 taken 5 times.
✓ Branch 11 → 17 taken 15 times.
20 if (ctx->lambdaAttr())
1394
3/6
✓ Branch 12 → 13 taken 5 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 5 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 5 times.
✗ Branch 14 → 34 not taken.
5 lambdaProcNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr()));
1395
3/6
✓ Branch 17 → 18 taken 20 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 20 times.
✗ Branch 18 → 39 not taken.
✓ Branch 19 → 20 taken 20 times.
✗ Branch 19 → 37 not taken.
20 lambdaProcNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
1396
1397
1/2
✓ Branch 27 → 28 taken 20 times.
✗ Branch 27 → 40 not taken.
20 return concludeNode(lambdaProcNode);
1398 }
1399
1400 1 std::any ASTBuilder::visitLambdaExpr(SpiceParser::LambdaExprContext *ctx) {
1401 1 const auto lambdaExprNode = createNode<LambdaExprNode>(ctx);
1402
1403 // Visit children
1404
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 10 not taken.
1 if (ctx->paramLst()) {
1405 1 lambdaExprNode->hasParams = true;
1406
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()));
1407 }
1408
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<ExprNode *>(visit(ctx->assignExpr()));
1409
1410
1/2
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 30 not taken.
1 return concludeNode(lambdaExprNode);
1411 }
1412
1413 52181 std::any ASTBuilder::visitDataType(SpiceParser::DataTypeContext *ctx) {
1414 52181 const auto dataTypeNode = createNode<DataTypeNode>(ctx);
1415
1416 // Visit children
1417
2/2
✓ Branch 4 → 5 taken 20230 times.
✓ Branch 4 → 10 taken 31951 times.
52181 if (ctx->qualifierLst())
1418
4/6
✓ Branch 5 → 6 taken 20230 times.
✗ Branch 5 → 74 not taken.
✓ Branch 6 → 7 taken 20229 times.
✓ Branch 6 → 74 taken 1 time.
✓ Branch 7 → 8 taken 20229 times.
✗ Branch 7 → 72 not taken.
20230 dataTypeNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
1419
3/6
✓ Branch 10 → 11 taken 52180 times.
✗ Branch 10 → 77 not taken.
✓ Branch 11 → 12 taken 52180 times.
✗ Branch 11 → 77 not taken.
✓ Branch 12 → 13 taken 52180 times.
✗ Branch 12 → 75 not taken.
52180 dataTypeNode->baseDataType = std::any_cast<BaseDataTypeNode *>(visit(ctx->baseDataType()));
1420
1421 // Enrich
1422
2/2
✓ Branch 61 → 15 taken 84780 times.
✓ Branch 61 → 62 taken 52180 times.
136960 for (size_t i = 0; i < ctx->children.size(); i++) {
1423 84780 antlr4::tree::ParseTree *subTree = ctx->children.at(i);
1424
1/2
✓ Branch 16 → 17 taken 84780 times.
✗ Branch 16 → 18 not taken.
84780 auto terminal = dynamic_cast<TerminalNode *>(subTree);
1425
2/2
✓ Branch 19 → 20 taken 72409 times.
✓ Branch 19 → 21 taken 12371 times.
84780 if (!terminal)
1426 72409 continue;
1427
1428
2/2
✓ Branch 23 → 24 taken 6511 times.
✓ Branch 23 → 26 taken 5860 times.
12371 if (terminal->getSymbol()->getType() == SpiceParser::MUL) {
1429
1/2
✓ Branch 24 → 25 taken 6511 times.
✗ Branch 24 → 78 not taken.
6511 dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_PTR, false, 0);
1430
2/2
✓ Branch 28 → 29 taken 5749 times.
✓ Branch 28 → 31 taken 111 times.
5860 } else if (terminal->getSymbol()->getType() == SpiceParser::BITWISE_AND) {
1431
1/2
✓ Branch 29 → 30 taken 5749 times.
✗ Branch 29 → 81 not taken.
5749 dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_REF, false, 0);
1432
1/2
✓ Branch 33 → 34 taken 111 times.
✗ Branch 33 → 59 not taken.
111 } else if (terminal->getSymbol()->getType() == SpiceParser::LBRACKET) {
1433 111 i++; // Consume LBRACKET
1434
1/2
✓ Branch 34 → 35 taken 111 times.
✗ Branch 34 → 93 not taken.
111 subTree = ctx->children.at(i);
1435
1/2
✓ Branch 35 → 36 taken 111 times.
✗ Branch 35 → 37 not taken.
111 terminal = dynamic_cast<TerminalNode *>(subTree);
1436 111 bool hasSize = false;
1437 111 unsigned int hardCodedSize = 0;
1438 111 std::string sizeVarName;
1439
4/6
✓ Branch 39 → 40 taken 111 times.
✗ Branch 39 → 91 not taken.
✓ Branch 40 → 41 taken 111 times.
✗ Branch 40 → 91 not taken.
✓ Branch 41 → 42 taken 51 times.
✓ Branch 41 → 47 taken 60 times.
111 if (terminal->getSymbol()->getType() == SpiceParser::INT_LIT) {
1440 51 hasSize = true;
1441
3/6
✓ Branch 42 → 43 taken 51 times.
✗ Branch 42 → 86 not taken.
✓ Branch 43 → 44 taken 51 times.
✗ Branch 43 → 86 not taken.
✓ Branch 44 → 45 taken 51 times.
✗ Branch 44 → 84 not taken.
51 hardCodedSize = std::stoi(terminal->getSymbol()->getText());
1442 51 i++; // Consume INT_LIT
1443
4/6
✓ Branch 47 → 48 taken 60 times.
✗ Branch 47 → 91 not taken.
✓ Branch 48 → 49 taken 60 times.
✗ Branch 48 → 91 not taken.
✓ Branch 49 → 50 taken 24 times.
✓ Branch 49 → 54 taken 36 times.
60 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1444 24 hasSize = true;
1445
1/2
✓ Branch 50 → 51 taken 24 times.
✗ Branch 50 → 87 not taken.
24 sizeVarName = getIdentifier(terminal, true);
1446 24 i++; // Consume TYPE_IDENTIFIER
1447 }
1448
1/2
✓ Branch 55 → 56 taken 111 times.
✗ Branch 55 → 88 not taken.
111 dataTypeNode->tmQueue.push({DataTypeNode::TypeModifierType::TYPE_ARRAY, hasSize, hardCodedSize, sizeVarName});
1449 111 }
1450 }
1451
1452
1/2
✓ Branch 68 → 69 taken 52180 times.
✗ Branch 68 → 94 not taken.
52180 return concludeNode(dataTypeNode);
1453
1/2
✓ Branch 54 → 55 taken 111 times.
✗ Branch 54 → 90 not taken.
111 }
1454
1455 52180 std::any ASTBuilder::visitBaseDataType(SpiceParser::BaseDataTypeContext *ctx) {
1456 52180 const auto baseDataTypeNode = createNode<BaseDataTypeNode>(ctx);
1457
1458 // Enrich
1459
2/2
✓ Branch 4 → 5 taken 628 times.
✓ Branch 4 → 6 taken 51552 times.
52180 if (ctx->TYPE_DOUBLE()) {
1460 628 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DOUBLE;
1461
2/2
✓ Branch 7 → 8 taken 3521 times.
✓ Branch 7 → 9 taken 48031 times.
51552 } else if (ctx->TYPE_INT()) {
1462 3521 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_INT;
1463
2/2
✓ Branch 10 → 11 taken 1210 times.
✓ Branch 10 → 12 taken 46821 times.
48031 } else if (ctx->TYPE_SHORT()) {
1464 1210 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_SHORT;
1465
2/2
✓ Branch 13 → 14 taken 9833 times.
✓ Branch 13 → 15 taken 36988 times.
46821 } else if (ctx->TYPE_LONG()) {
1466 9833 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_LONG;
1467
2/2
✓ Branch 16 → 17 taken 2888 times.
✓ Branch 16 → 18 taken 34100 times.
36988 } else if (ctx->TYPE_BYTE()) {
1468 2888 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BYTE;
1469
2/2
✓ Branch 19 → 20 taken 5623 times.
✓ Branch 19 → 21 taken 28477 times.
34100 } else if (ctx->TYPE_CHAR()) {
1470 5623 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CHAR;
1471
2/2
✓ Branch 22 → 23 taken 4392 times.
✓ Branch 22 → 24 taken 24085 times.
28477 } else if (ctx->TYPE_STRING()) {
1472 4392 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_STRING;
1473
2/2
✓ Branch 25 → 26 taken 4223 times.
✓ Branch 25 → 27 taken 19862 times.
24085 } else if (ctx->TYPE_BOOL()) {
1474 4223 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BOOL;
1475
2/2
✓ Branch 28 → 29 taken 496 times.
✓ Branch 28 → 30 taken 19366 times.
19862 } else if (ctx->TYPE_DYN()) {
1476 496 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DYN;
1477
2/2
✓ Branch 31 → 32 taken 19264 times.
✓ Branch 31 → 37 taken 102 times.
19366 } else if (ctx->customDataType()) {
1478 19264 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CUSTOM;
1479
3/6
✓ Branch 32 → 33 taken 19264 times.
✗ Branch 32 → 57 not taken.
✓ Branch 33 → 34 taken 19264 times.
✗ Branch 33 → 57 not taken.
✓ Branch 34 → 35 taken 19264 times.
✗ Branch 34 → 55 not taken.
19264 baseDataTypeNode->customDataType = std::any_cast<CustomDataTypeNode *>(visit(ctx->customDataType()));
1480
1/2
✓ Branch 38 → 39 taken 102 times.
✗ Branch 38 → 44 not taken.
102 } else if (ctx->functionDataType()) {
1481 102 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_FUNCTION;
1482
3/6
✓ Branch 39 → 40 taken 102 times.
✗ Branch 39 → 60 not taken.
✓ Branch 40 → 41 taken 102 times.
✗ Branch 40 → 60 not taken.
✓ Branch 41 → 42 taken 102 times.
✗ Branch 41 → 58 not taken.
102 baseDataTypeNode->functionDataType = std::any_cast<FunctionDataTypeNode *>(visit(ctx->functionDataType()));
1483 } else {
1484 assert_fail("Unknown base data type");
1485 }
1486
1487
1/2
✓ Branch 51 → 52 taken 52180 times.
✗ Branch 51 → 61 not taken.
52180 return concludeNode(baseDataTypeNode);
1488 }
1489
1490 19264 std::any ASTBuilder::visitCustomDataType(SpiceParser::CustomDataTypeContext *ctx) {
1491 19264 const auto customDataTypeNode = createNode<CustomDataTypeNode>(ctx);
1492
1493 // Enrich
1494
2/2
✓ Branch 31 → 5 taken 27241 times.
✓ Branch 31 → 32 taken 19264 times.
46505 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1495
1/2
✓ Branch 6 → 7 taken 27241 times.
✗ Branch 6 → 8 not taken.
27241 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1496
2/2
✓ Branch 9 → 10 taken 2641 times.
✓ Branch 9 → 11 taken 24600 times.
27241 if (!terminal)
1497 2641 continue;
1498
1499
4/6
✓ Branch 11 → 12 taken 24600 times.
✗ Branch 11 → 58 not taken.
✓ Branch 12 → 13 taken 24600 times.
✗ Branch 12 → 58 not taken.
✓ Branch 13 → 14 taken 27 times.
✓ Branch 13 → 21 taken 24573 times.
24600 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1500
1/2
✓ Branch 14 → 15 taken 27 times.
✗ Branch 14 → 54 not taken.
27 const std::string fragment = terminal->toString();
1501
1/2
✓ Branch 15 → 16 taken 27 times.
✗ Branch 15 → 52 not taken.
27 customDataTypeNode->typeNameFragments.push_back(fragment);
1502
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;
1503
4/6
✓ Branch 21 → 22 taken 24573 times.
✗ Branch 21 → 58 not taken.
✓ Branch 22 → 23 taken 24573 times.
✗ Branch 22 → 58 not taken.
✓ Branch 23 → 24 taken 19264 times.
✓ Branch 23 → 29 taken 5309 times.
24600 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1504
1/2
✓ Branch 24 → 25 taken 19264 times.
✗ Branch 24 → 57 not taken.
19264 const std::string fragment = terminal->toString();
1505
1/2
✓ Branch 25 → 26 taken 19264 times.
✗ Branch 25 → 55 not taken.
19264 customDataTypeNode->typeNameFragments.push_back(fragment);
1506
1/2
✓ Branch 26 → 27 taken 19264 times.
✗ Branch 26 → 55 not taken.
19264 customDataTypeNode->fqTypeName += fragment;
1507 19264 }
1508 }
1509
1510 // Visit children
1511
2/2
✓ Branch 33 → 34 taken 2641 times.
✓ Branch 33 → 39 taken 16623 times.
19264 if (ctx->typeLst())
1512
3/6
✓ Branch 34 → 35 taken 2641 times.
✗ Branch 34 → 61 not taken.
✓ Branch 35 → 36 taken 2641 times.
✗ Branch 35 → 61 not taken.
✓ Branch 36 → 37 taken 2641 times.
✗ Branch 36 → 59 not taken.
2641 customDataTypeNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1513
1514
1/2
✓ Branch 45 → 46 taken 19264 times.
✗ Branch 45 → 62 not taken.
19264 return concludeNode(customDataTypeNode);
1515 }
1516
1517 102 std::any ASTBuilder::visitFunctionDataType(SpiceParser::FunctionDataTypeContext *ctx) {
1518 102 const auto functionDataTypeNode = createNode<FunctionDataTypeNode>(ctx);
1519
1520 // Enrich
1521
2/2
✓ Branch 4 → 5 taken 32 times.
✓ Branch 4 → 11 taken 70 times.
102 if (ctx->dataType()) {
1522 32 functionDataTypeNode->isFunction = ctx->dataType();
1523
3/6
✓ Branch 6 → 7 taken 32 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 32 times.
✗ Branch 7 → 30 not taken.
✓ Branch 8 → 9 taken 32 times.
✗ Branch 8 → 28 not taken.
32 functionDataTypeNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1524 }
1525
2/2
✓ Branch 12 → 13 taken 72 times.
✓ Branch 12 → 18 taken 30 times.
102 if (ctx->typeLst())
1526
3/6
✓ Branch 13 → 14 taken 72 times.
✗ Branch 13 → 33 not taken.
✓ Branch 14 → 15 taken 72 times.
✗ Branch 14 → 33 not taken.
✓ Branch 15 → 16 taken 72 times.
✗ Branch 15 → 31 not taken.
72 functionDataTypeNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1527
1528
1/2
✓ Branch 24 → 25 taken 102 times.
✗ Branch 24 → 34 not taken.
102 return concludeNode(functionDataTypeNode);
1529 }
1530
1531 8192 std::any ASTBuilder::visitAssignOp(SpiceParser::AssignOpContext *ctx) {
1532 8192 const auto assignExprNode = resumeForExpansion<AssignExprNode>();
1533
1534 // Extract assign operator
1535
2/2
✓ Branch 13 → 14 taken 7252 times.
✓ Branch 13 → 15 taken 940 times.
8192 if (ctx->ASSIGN())
1536 7252 assignExprNode->op = AssignExprNode::AssignOp::OP_ASSIGN;
1537
2/2
✓ Branch 16 → 17 taken 402 times.
✓ Branch 16 → 18 taken 538 times.
940 else if (ctx->PLUS_EQUAL())
1538 402 assignExprNode->op = AssignExprNode::AssignOp::OP_PLUS_EQUAL;
1539
2/2
✓ Branch 19 → 20 taken 70 times.
✓ Branch 19 → 21 taken 468 times.
538 else if (ctx->MINUS_EQUAL())
1540 70 assignExprNode->op = AssignExprNode::AssignOp::OP_MINUS_EQUAL;
1541
2/2
✓ Branch 22 → 23 taken 46 times.
✓ Branch 22 → 24 taken 422 times.
468 else if (ctx->MUL_EQUAL())
1542 46 assignExprNode->op = AssignExprNode::AssignOp::OP_MUL_EQUAL;
1543
2/2
✓ Branch 25 → 26 taken 44 times.
✓ Branch 25 → 27 taken 378 times.
422 else if (ctx->DIV_EQUAL())
1544 44 assignExprNode->op = AssignExprNode::AssignOp::OP_DIV_EQUAL;
1545
2/2
✓ Branch 28 → 29 taken 8 times.
✓ Branch 28 → 30 taken 370 times.
378 else if (ctx->REM_EQUAL())
1546 8 assignExprNode->op = AssignExprNode::AssignOp::OP_REM_EQUAL;
1547
2/2
✓ Branch 31 → 32 taken 3 times.
✓ Branch 31 → 33 taken 367 times.
370 else if (ctx->SHL_EQUAL())
1548 3 assignExprNode->op = AssignExprNode::AssignOp::OP_SHL_EQUAL;
1549
2/2
✓ Branch 34 → 35 taken 4 times.
✓ Branch 34 → 36 taken 363 times.
367 else if (ctx->SHR_EQUAL())
1550 4 assignExprNode->op = AssignExprNode::AssignOp::OP_SHR_EQUAL;
1551
2/2
✓ Branch 37 → 38 taken 2 times.
✓ Branch 37 → 39 taken 361 times.
363 else if (ctx->AND_EQUAL())
1552 2 assignExprNode->op = AssignExprNode::AssignOp::OP_AND_EQUAL;
1553
2/2
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 42 taken 359 times.
361 else if (ctx->OR_EQUAL())
1554 2 assignExprNode->op = AssignExprNode::AssignOp::OP_OR_EQUAL;
1555
1/2
✓ Branch 43 → 44 taken 359 times.
✗ Branch 43 → 45 not taken.
359 else if (ctx->XOR_EQUAL())
1556 359 assignExprNode->op = AssignExprNode::AssignOp::OP_XOR_EQUAL;
1557 else
1558 assert_fail("Unknown assign operator");
1559
1560
1/2
✓ Branch 46 → 47 taken 8192 times.
✗ Branch 46 → 49 not taken.
8192 return nullptr;
1561 }
1562
1563 1857 std::any ASTBuilder::visitOverloadableOp(SpiceParser::OverloadableOpContext *ctx) {
1564 1857 const auto fctNameNode = resumeForExpansion<FctNameNode>();
1565
1566 // Enrich
1567
2/2
✓ Branch 13 → 14 taken 99 times.
✓ Branch 13 → 15 taken 1758 times.
1857 if (ctx->PLUS())
1568 99 fctNameNode->name = OP_FCT_PLUS;
1569
2/2
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 18 taken 1757 times.
1758 else if (ctx->MINUS())
1570 1 fctNameNode->name = OP_FCT_MINUS;
1571
2/2
✓ Branch 19 → 20 taken 197 times.
✓ Branch 19 → 21 taken 1560 times.
1757 else if (ctx->MUL())
1572 197 fctNameNode->name = OP_FCT_MUL;
1573
2/2
✓ Branch 22 → 23 taken 22 times.
✓ Branch 22 → 24 taken 1538 times.
1560 else if (ctx->DIV())
1574 22 fctNameNode->name = OP_FCT_DIV;
1575
2/2
✓ Branch 25 → 26 taken 442 times.
✓ Branch 25 → 27 taken 1096 times.
1538 else if (ctx->EQUAL())
1576 442 fctNameNode->name = OP_FCT_EQUAL;
1577
2/2
✓ Branch 28 → 29 taken 439 times.
✓ Branch 28 → 30 taken 657 times.
1096 else if (ctx->NOT_EQUAL())
1578 439 fctNameNode->name = OP_FCT_NOT_EQUAL;
1579
3/4
✓ Branch 30 → 31 taken 657 times.
✗ Branch 30 → 67 not taken.
✓ Branch 33 → 34 taken 13 times.
✓ Branch 33 → 35 taken 644 times.
657 else if (ctx->LESS().size() == 2)
1580 13 fctNameNode->name = OP_FCT_SHL;
1581
3/4
✓ Branch 35 → 36 taken 644 times.
✗ Branch 35 → 68 not taken.
✓ Branch 38 → 39 taken 1 time.
✓ Branch 38 → 40 taken 643 times.
644 else if (ctx->GREATER().size() == 2)
1582 1 fctNameNode->name = OP_FCT_SHR;
1583
2/2
✓ Branch 41 → 42 taken 140 times.
✓ Branch 41 → 43 taken 503 times.
643 else if (ctx->PLUS_EQUAL())
1584 140 fctNameNode->name = OP_FCT_PLUS_EQUAL;
1585
2/2
✓ Branch 44 → 45 taken 42 times.
✓ Branch 44 → 46 taken 461 times.
503 else if (ctx->MINUS_EQUAL())
1586 42 fctNameNode->name = OP_FCT_MINUS_EQUAL;
1587
2/2
✓ Branch 47 → 48 taken 99 times.
✓ Branch 47 → 49 taken 362 times.
461 else if (ctx->MUL_EQUAL())
1588 99 fctNameNode->name = OP_FCT_MUL_EQUAL;
1589
2/2
✓ Branch 50 → 51 taken 22 times.
✓ Branch 50 → 52 taken 340 times.
362 else if (ctx->DIV_EQUAL())
1590 22 fctNameNode->name = OP_FCT_DIV_EQUAL;
1591
2/2
✓ Branch 53 → 54 taken 52 times.
✓ Branch 53 → 55 taken 288 times.
340 else if (ctx->PLUS_PLUS())
1592 52 fctNameNode->name = OP_FCT_POSTFIX_PLUS_PLUS;
1593
2/2
✓ Branch 56 → 57 taken 42 times.
✓ Branch 56 → 58 taken 246 times.
288 else if (ctx->MINUS_MINUS())
1594 42 fctNameNode->name = OP_FCT_POSTFIX_MINUS_MINUS;
1595
1/2
✓ Branch 59 → 60 taken 246 times.
✗ Branch 59 → 61 not taken.
246 else if (ctx->LBRACKET())
1596 246 fctNameNode->name = OP_FCT_SUBSCRIPT;
1597 else
1598 assert_fail("Unsupported overloadable operator"); // GCOV_EXCL_LINE
1599
1600 1857 fctNameNode->fqName = fctNameNode->name;
1601 1857 fctNameNode->nameFragments.push_back(fctNameNode->name);
1602
1603
1/2
✓ Branch 64 → 65 taken 1857 times.
✗ Branch 64 → 69 not taken.
1857 return nullptr;
1604 }
1605
1606 5535 int32_t ASTBuilder::parseInt(TerminalNode *terminal) {
1607 11070 const NumericParserCallback<int32_t> cb = [](const std::string &substr, short base, bool isSigned) -> int32_t {
1608 // Prepare limits
1609
2/2
✓ Branch 2 → 3 taken 5527 times.
✓ Branch 2 → 4 taken 8 times.
5535 const int64_t upperLimit = isSigned ? INT32_MAX : UINT32_MAX;
1610
2/2
✓ Branch 5 → 6 taken 5527 times.
✓ Branch 5 → 7 taken 8 times.
5535 const int64_t lowerLimit = isSigned ? INT32_MIN : 0;
1611 // Parse number and check for limits
1612 5535 const int64_t number = std::stoll(substr, nullptr, base);
1613
2/4
✓ Branch 9 → 10 taken 5534 times.
✗ Branch 9 → 11 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 5534 times.
5534 if (number < lowerLimit || number > upperLimit)
1614 throw std::out_of_range("Number out of range");
1615 5534 return static_cast<int32_t>(number);
1616 5535 };
1617
2/2
✓ Branch 3 → 4 taken 5534 times.
✓ Branch 3 → 8 taken 1 time.
11069 return parseNumeric(terminal, cb);
1618 5535 }
1619
1620 882 int16_t ASTBuilder::parseShort(TerminalNode *terminal) {
1621 1764 const NumericParserCallback<int16_t> cb = [](const std::string &substr, short base, bool isSigned) -> int16_t {
1622 // Prepare limits
1623
2/2
✓ Branch 2 → 3 taken 548 times.
✓ Branch 2 → 4 taken 334 times.
882 const int64_t upperLimit = isSigned ? INT16_MAX : UINT16_MAX;
1624
2/2
✓ Branch 5 → 6 taken 548 times.
✓ Branch 5 → 7 taken 334 times.
882 const int64_t lowerLimit = isSigned ? INT16_MIN : 0;
1625 // Parse number and check for limits
1626 882 const int64_t number = std::stoll(substr, nullptr, base);
1627
2/4
✓ Branch 9 → 10 taken 882 times.
✗ Branch 9 → 11 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 882 times.
882 if (number < lowerLimit || number > upperLimit)
1628 throw std::out_of_range("Number out of range");
1629 882 return static_cast<int16_t>(number);
1630 882 };
1631
1/2
✓ Branch 3 → 4 taken 882 times.
✗ Branch 3 → 8 not taken.
1764 return parseNumeric(terminal, cb);
1632 882 }
1633
1634 6504 int64_t ASTBuilder::parseLong(TerminalNode *terminal) {
1635 13008 const NumericParserCallback<int64_t> cb = [](const std::string &substr, short base, bool isSigned) -> int64_t {
1636
2/2
✓ Branch 2 → 3 taken 6350 times.
✓ Branch 2 → 5 taken 154 times.
6504 return isSigned ? std::stoll(substr, nullptr, base) : static_cast<int64_t>(std::stoull(substr, nullptr, base));
1637 6504 };
1638
1/2
✓ Branch 3 → 4 taken 6504 times.
✗ Branch 3 → 8 not taken.
13008 return parseNumeric(terminal, cb);
1639 6504 }
1640
1641 3027 int8_t ASTBuilder::parseChar(TerminalNode *terminal) const {
1642
1/2
✓ Branch 2 → 3 taken 3027 times.
✗ Branch 2 → 59 not taken.
3027 const std::string input = terminal->toString();
1643
2/2
✓ Branch 4 → 5 taken 1913 times.
✓ Branch 4 → 7 taken 1114 times.
3027 if (input.length() == 3) // Normal char literals
1644 1913 return input[1];
1645
1646
3/6
✓ Branch 8 → 9 taken 1114 times.
✗ Branch 8 → 12 not taken.
✓ Branch 10 → 11 taken 1114 times.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 1114 times.
✗ Branch 13 → 34 not taken.
1114 if (input.length() == 4 && input[1] == '\\') { // Char literals with escape sequence
1647
7/11
✓ Branch 15 → 16 taken 5 times.
✗ Branch 15 → 17 not taken.
✓ Branch 15 → 18 taken 11 times.
✓ Branch 15 → 19 taken 115 times.
✓ Branch 15 → 20 taken 98 times.
✓ Branch 15 → 21 taken 98 times.
✗ Branch 15 → 22 not taken.
✗ Branch 15 → 23 not taken.
✗ Branch 15 → 24 not taken.
✓ Branch 15 → 25 taken 786 times.
✓ Branch 15 → 26 taken 1 time.
1114 switch (input[2]) {
1648 5 case '\'':
1649 5 return '\'';
1650 case '"':
1651 return '\"';
1652 11 case '\\':
1653 11 return '\\';
1654 115 case 'n':
1655 115 return '\n';
1656 98 case 'r':
1657 98 return '\r';
1658 98 case 't':
1659 98 return '\t';
1660 case 'b':
1661 return '\b';
1662 case 'f':
1663 return '\f';
1664 case 'v':
1665 return '\v';
1666 786 case '0':
1667 786 return '\0';
1668 1 default:
1669
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);
1670
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);
1671 }
1672 }
1673
1674 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1675 throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid char literal " + input);
1676 3027 }
1677
1678 3670 std::string ASTBuilder::parseString(std::string input) {
1679
1/2
✓ Branch 3 → 4 taken 3670 times.
✗ Branch 3 → 9 not taken.
3670 input = input.substr(1, input.size() - 2);
1680 3670 replaceEscapeChars(input);
1681 3670 return input;
1682 }
1683
1684 12921 template <typename T> T ASTBuilder::parseNumeric(TerminalNode *terminal, const NumericParserCallback<T> &cb) {
1685
3/6
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 5535 times.
✗ Branch 2 → 87 not taken.
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 6504 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 882 times.
✗ Branch 2 → 87 not taken.
12921 const std::string input = terminal->toString();
1686
1687 // Set to signed if the input string does not end with 'u'
1688
12/18
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 5527 times.
✓ Branch 4 → 9 taken 8 times.
✓ Branch 6 → 7 taken 5527 times.
✗ Branch 6 → 9 not taken.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 5527 times.
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 6504 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 6504 times.
✗ Branch 6 → 9 not taken.
✓ Branch 8 → 9 taken 154 times.
✓ Branch 8 → 10 taken 6350 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 882 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 548 times.
✓ Branch 6 → 9 taken 334 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 548 times.
12921 const bool isUnsigned = input.ends_with('u') || input.ends_with("us") || input.ends_with("ul");
1689
1690 try {
1691
6/6
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 959 times.
✓ Branch 12 → 30 taken 4576 times.
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 1617 times.
✓ Branch 12 → 30 taken 4887 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 684 times.
✓ Branch 12 → 30 taken 198 times.
12921 if (input.length() >= 3) {
1692
6/6
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 219 times.
✓ Branch 14 → 30 taken 740 times.
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 52 times.
✓ Branch 14 → 30 taken 1565 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 121 times.
✓ Branch 14 → 30 taken 563 times.
3260 if (input[0] == '0') {
1693
3/6
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 219 times.
✗ Branch 15 → 37 not taken.
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 52 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 121 times.
✗ Branch 15 → 37 not taken.
392 const std::string subStr = input.substr(2);
1694
5/15
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 219 times.
✗ Branch 17 → 26 not taken.
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 14 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 120 times.
✓ Branch 17 → 26 taken 1 time.
392 switch (input[1]) {
1695 case 'd': // fall-through
1696 case 'D':
1697 return cb(subStr, 10, !isUnsigned);
1698 case 'b': // fall-through
1699 case 'B':
1700 return cb(subStr, 2, !isUnsigned);
1701 38 case 'h': // fall-through
1702 case 'H': // fall-through
1703 case 'x': // fall-through
1704 case 'X':
1705
1/6
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.
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.
38 return cb(subStr, 16, !isUnsigned);
1706 339 case 'o': // fall-through
1707 case 'O':
1708
2/6
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 219 times.
✗ Branch 24 → 35 not taken.
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 120 times.
✗ Branch 24 → 35 not taken.
339 return cb(subStr, 8, !isUnsigned);
1709 15 default: // default is decimal
1710
2/6
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.
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 14 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.
15 return cb(input, 10, !isUnsigned);
1711 }
1712 392 }
1713 }
1714
4/6
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 5315 times.
✓ Branch 30 → 38 taken 1 time.
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 6452 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 761 times.
✗ Branch 30 → 38 not taken.
12529 return cb(input, 10, !isUnsigned);
1715
1/9
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.
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.
2 } catch (std::out_of_range &) {
1716
2/12
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.
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.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1717
2/12
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.
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.
3 throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "The provided number is out of range");
1718 } catch (std::invalid_argument &) {
1719 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1720 throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "You tried to parse '" + input + "' as an integer, but it was no integer");
1721 }
1722 12921 }
1723
1724 3670 void ASTBuilder::replaceEscapeChars(std::string &input) {
1725 const std::unordered_map<char, char> escapeMap = {
1726 {'a', '\a'}, {'b', '\b'}, {'f', '\f'}, {'n', '\n'}, {'r', '\r'}, {'t', '\t'},
1727 {'v', '\v'}, {'\\', '\\'}, {'?', '\?'}, {'\'', '\''}, {'"', '\"'},
1728
1/2
✓ Branch 4 → 5 taken 3670 times.
✗ Branch 4 → 40 not taken.
7340 };
1729
1730 3670 size_t writeIndex = 0;
1731 3670 size_t readIndex = 0;
1732 3670 const size_t len = input.length();
1733
1734
2/2
✓ Branch 36 → 8 taken 55607 times.
✓ Branch 36 → 37 taken 3670 times.
59277 while (readIndex < len) {
1735 55607 const char c = input[readIndex];
1736
3/4
✓ Branch 9 → 10 taken 713 times.
✓ Branch 9 → 33 taken 54894 times.
✓ Branch 10 → 11 taken 713 times.
✗ Branch 10 → 33 not taken.
55607 if (c == '\\' && readIndex + 1 < len) {
1737 713 char next = input[readIndex + 1];
1738
1/2
✓ Branch 12 → 13 taken 713 times.
✗ Branch 12 → 45 not taken.
713 auto it = escapeMap.find(next);
1739
2/2
✓ Branch 15 → 16 taken 704 times.
✓ Branch 15 → 19 taken 9 times.
713 if (it != escapeMap.end()) {
1740 704 input[writeIndex++] = it->second;
1741 704 readIndex += 2;
1742 710 continue;
1743 }
1744
1745 // Handle octal escape sequences (up to 3 digits)
1746
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') {
1747 6 int value = 0;
1748 6 size_t octalDigits = 0;
1749
1750 // Look ahead up to 3 digits
1751
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) {
1752 18 const char oc = input[readIndex + i];
1753
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') {
1754 18 value = value << 3 | (oc - '0'); // multiply by 8 and add digit
1755 18 octalDigits++;
1756 } else {
1757 break;
1758 }
1759 }
1760
1761
1/2
✓ Branch 28 → 29 taken 6 times.
✗ Branch 28 → 31 not taken.
6 if (octalDigits > 0) {
1762 6 input[writeIndex++] = static_cast<char>(value);
1763 6 readIndex += 1 + octalDigits; // backslash + octal digits
1764 6 continue;
1765 }
1766 }
1767 }
1768
1769 // Copy current character
1770 54897 input[writeIndex++] = c;
1771 54897 readIndex++;
1772 }
1773
1774
1/2
✓ Branch 37 → 38 taken 3670 times.
✗ Branch 37 → 46 not taken.
3670 input.resize(writeIndex);
1775 3670 }
1776
1777 125248 std::string ASTBuilder::getIdentifier(TerminalNode *terminal, bool isTypeIdentifier) const {
1778 125248 const std::string identifier = terminal->getText();
1779
1780 // Check if the list of reserved keywords contains the given identifier
1781
3/4
✓ Branch 3 → 4 taken 125248 times.
✗ Branch 3 → 56 not taken.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 16 taken 125247 times.
250496 if (std::ranges::find(RESERVED_KEYWORDS, identifier) != std::end(RESERVED_KEYWORDS)) {
1782
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);
1783
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");
1784 }
1785
1786 // Check if the identifier is a type identifier and is reserved
1787
6/6
✓ Branch 16 → 17 taken 10274 times.
✓ Branch 16 → 23 taken 114973 times.
✓ Branch 17 → 18 taken 466 times.
✓ Branch 17 → 23 taken 9808 times.
✓ Branch 24 → 25 taken 1 time.
✓ Branch 24 → 34 taken 125246 times.
125713 if (isTypeIdentifier && !sourceFile->isStdFile &&
1788
3/4
✓ Branch 18 → 19 taken 466 times.
✗ Branch 18 → 56 not taken.
✓ Branch 21 → 22 taken 1 time.
✓ Branch 21 → 23 taken 465 times.
932 std::ranges::find(RESERVED_TYPE_NAMES, identifier) != std::end(RESERVED_TYPE_NAMES)) {
1789
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);
1790
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");
1791 }
1792
1793 125246 return identifier;
1794 2 }
1795
1796 } // namespace spice::compiler
1797