GCC Code Coverage Report


Directory: ../
File: src/ast/ASTBuilder.cpp
Date: 2025-10-27 22:48:14
Coverage Exec Excl Total
Lines: 95.1% 1133 17 1209
Functions: 100.0% 104 0 104
Branches: 58.9% 1567 4 2663

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