GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.7% 1148 / 16 / 1215
Functions: 100.0% 96 / 0 / 96
Branches: 58.5% 1579 / 2 / 2703

src/ast/ASTBuilder.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "ASTBuilder.h"
4
5 #include <regex>
6
7 #include <SourceFile.h>
8 #include <ast/ASTNodes.h>
9 #include <ast/Attributes.h>
10 #include <exception/ParserError.h>
11 #include <typechecker/OpRuleManager.h>
12 #include <util/GlobalDefinitions.h>
13
14 namespace spice::compiler {
15
16 2795 ASTBuilder::ASTBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile, antlr4::ANTLRInputStream *inputStream)
17
1/2
✓ Branch 4 → 5 taken 2795 times.
✗ Branch 4 → 6 not taken.
2795 : CompilerPass(resourceManager, sourceFile), inputStream(inputStream) {}
18
19 2793 std::any ASTBuilder::visitEntry(SpiceParser::EntryContext *ctx) {
20 2793 const auto entryNode = createNode<EntryNode>(ctx);
21
22 // Visit children
23
2/2
✓ Branch 135 → 5 taken 58055 times.
✓ Branch 135 → 136 taken 2787 times.
63635 for (ParserRuleContext::ParseTree *child : ctx->children) {
24
3/4
✓ Branch 7 → 8 taken 58055 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 607 times.
✓ Branch 10 → 16 taken 57448 times.
58055 if (auto *mainFctDefCtx = dynamic_cast<SpiceParser::MainFunctionDefContext *>(child))
25
4/6
✓ Branch 11 → 12 taken 603 times.
✓ Branch 11 → 148 taken 4 times.
✓ Branch 12 → 13 taken 603 times.
✗ Branch 12 → 146 not taken.
✓ Branch 13 → 14 taken 603 times.
✗ Branch 13 → 146 not taken.
607 entryNode->topLevelDefs.push_back(std::any_cast<MainFctDefNode *>(visit(mainFctDefCtx)));
26
3/4
✓ Branch 16 → 17 taken 57448 times.
✗ Branch 16 → 18 not taken.
✓ Branch 19 → 20 taken 24318 times.
✓ Branch 19 → 25 taken 33130 times.
57448 else if (auto *fctDefCtx = dynamic_cast<SpiceParser::FunctionDefContext *>(child))
27
3/6
✓ Branch 20 → 21 taken 24318 times.
✗ Branch 20 → 152 not taken.
✓ Branch 21 → 22 taken 24318 times.
✗ Branch 21 → 150 not taken.
✓ Branch 22 → 23 taken 24318 times.
✗ Branch 22 → 150 not taken.
24318 entryNode->topLevelDefs.push_back(std::any_cast<FctDefNode *>(visit(fctDefCtx)));
28
3/4
✓ Branch 25 → 26 taken 33130 times.
✗ Branch 25 → 27 not taken.
✓ Branch 28 → 29 taken 12912 times.
✓ Branch 28 → 34 taken 20218 times.
33130 else if (auto *procDefCtx = dynamic_cast<SpiceParser::ProcedureDefContext *>(child))
29
3/6
✓ Branch 29 → 30 taken 12912 times.
✗ Branch 29 → 156 not taken.
✓ Branch 30 → 31 taken 12912 times.
✗ Branch 30 → 154 not taken.
✓ Branch 31 → 32 taken 12912 times.
✗ Branch 31 → 154 not taken.
12912 entryNode->topLevelDefs.push_back(std::any_cast<ProcDefNode *>(visit(procDefCtx)));
30
3/4
✓ Branch 34 → 35 taken 20218 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 3282 times.
✓ Branch 37 → 43 taken 16936 times.
20218 else if (auto *structDefCtx = dynamic_cast<SpiceParser::StructDefContext *>(child))
31
4/6
✓ Branch 38 → 39 taken 3281 times.
✓ Branch 38 → 160 taken 1 time.
✓ Branch 39 → 40 taken 3281 times.
✗ Branch 39 → 158 not taken.
✓ Branch 40 → 41 taken 3281 times.
✗ Branch 40 → 158 not taken.
3282 entryNode->topLevelDefs.push_back(std::any_cast<StructDefNode *>(visit(structDefCtx)));
32
3/4
✓ Branch 43 → 44 taken 16936 times.
✗ Branch 43 → 45 not taken.
✓ Branch 46 → 47 taken 405 times.
✓ Branch 46 → 52 taken 16531 times.
16936 else if (auto *interfaceDefCtx = dynamic_cast<SpiceParser::InterfaceDefContext *>(child))
33
3/6
✓ Branch 47 → 48 taken 405 times.
✗ Branch 47 → 164 not taken.
✓ Branch 48 → 49 taken 405 times.
✗ Branch 48 → 162 not taken.
✓ Branch 49 → 50 taken 405 times.
✗ Branch 49 → 162 not taken.
405 entryNode->topLevelDefs.push_back(std::any_cast<InterfaceDefNode *>(visit(interfaceDefCtx)));
34
3/4
✓ Branch 52 → 53 taken 16531 times.
✗ Branch 52 → 54 not taken.
✓ Branch 55 → 56 taken 611 times.
✓ Branch 55 → 61 taken 15920 times.
16531 else if (auto *enumDefCtx = dynamic_cast<SpiceParser::EnumDefContext *>(child))
35
3/6
✓ Branch 56 → 57 taken 611 times.
✗ Branch 56 → 168 not taken.
✓ Branch 57 → 58 taken 611 times.
✗ Branch 57 → 166 not taken.
✓ Branch 58 → 59 taken 611 times.
✗ Branch 58 → 166 not taken.
611 entryNode->topLevelDefs.push_back(std::any_cast<EnumDefNode *>(visit(enumDefCtx)));
36
3/4
✓ Branch 61 → 62 taken 15920 times.
✗ Branch 61 → 63 not taken.
✓ Branch 64 → 65 taken 2260 times.
✓ Branch 64 → 70 taken 13660 times.
15920 else if (auto *genericTypeDefCtx = dynamic_cast<SpiceParser::GenericTypeDefContext *>(child))
37
3/6
✓ Branch 65 → 66 taken 2260 times.
✗ Branch 65 → 172 not taken.
✓ Branch 66 → 67 taken 2260 times.
✗ Branch 66 → 170 not taken.
✓ Branch 67 → 68 taken 2260 times.
✗ Branch 67 → 170 not taken.
2260 entryNode->topLevelDefs.push_back(std::any_cast<GenericTypeDefNode *>(visit(genericTypeDefCtx)));
38
3/4
✓ Branch 70 → 71 taken 13660 times.
✗ Branch 70 → 72 not taken.
✓ Branch 73 → 74 taken 352 times.
✓ Branch 73 → 79 taken 13308 times.
13660 else if (auto *aliasDefCtx = dynamic_cast<SpiceParser::AliasDefContext *>(child))
39
3/6
✓ Branch 74 → 75 taken 352 times.
✗ Branch 74 → 176 not taken.
✓ Branch 75 → 76 taken 352 times.
✗ Branch 75 → 174 not taken.
✓ Branch 76 → 77 taken 352 times.
✗ Branch 76 → 174 not taken.
352 entryNode->topLevelDefs.push_back(std::any_cast<AliasDefNode *>(visit(aliasDefCtx)));
40
3/4
✓ Branch 79 → 80 taken 13308 times.
✗ Branch 79 → 81 not taken.
✓ Branch 82 → 83 taken 2743 times.
✓ Branch 82 → 88 taken 10565 times.
13308 else if (auto *globalVarDefCtx = dynamic_cast<SpiceParser::GlobalVarDefContext *>(child))
41
3/6
✓ Branch 83 → 84 taken 2743 times.
✗ Branch 83 → 180 not taken.
✓ Branch 84 → 85 taken 2743 times.
✗ Branch 84 → 178 not taken.
✓ Branch 85 → 86 taken 2743 times.
✗ Branch 85 → 178 not taken.
2743 entryNode->topLevelDefs.push_back(std::any_cast<GlobalVarDefNode *>(visit(globalVarDefCtx)));
42
3/4
✓ Branch 88 → 89 taken 10565 times.
✗ Branch 88 → 90 not taken.
✓ Branch 91 → 92 taken 2737 times.
✓ Branch 91 → 97 taken 7828 times.
10565 else if (auto *importDefCtx = dynamic_cast<SpiceParser::ImportDefContext *>(child))
43
3/6
✓ Branch 92 → 93 taken 2737 times.
✗ Branch 92 → 184 not taken.
✓ Branch 93 → 94 taken 2737 times.
✗ Branch 93 → 182 not taken.
✓ Branch 94 → 95 taken 2737 times.
✗ Branch 94 → 182 not taken.
2737 entryNode->importDefs.push_back(std::any_cast<ImportDefNode *>(visit(importDefCtx)));
44
3/4
✓ Branch 97 → 98 taken 7828 times.
✗ Branch 97 → 99 not taken.
✓ Branch 100 → 101 taken 4205 times.
✓ Branch 100 → 106 taken 3623 times.
7828 else if (auto *extDeclCtx = dynamic_cast<SpiceParser::ExtDeclContext *>(child))
45
3/6
✓ Branch 101 → 102 taken 4205 times.
✗ Branch 101 → 188 not taken.
✓ Branch 102 → 103 taken 4205 times.
✗ Branch 102 → 186 not taken.
✓ Branch 103 → 104 taken 4205 times.
✗ Branch 103 → 186 not taken.
4205 entryNode->topLevelDefs.push_back(std::any_cast<ExtDeclNode *>(visit(extDeclCtx)));
46
3/4
✓ Branch 106 → 107 taken 3623 times.
✗ Branch 106 → 108 not taken.
✓ Branch 109 → 110 taken 836 times.
✓ Branch 109 → 115 taken 2787 times.
3623 else if (auto *modAttrCtx = dynamic_cast<SpiceParser::ModAttrContext *>(child))
47
4/6
✓ Branch 110 → 111 taken 835 times.
✓ Branch 110 → 192 taken 1 time.
✓ Branch 111 → 112 taken 835 times.
✗ Branch 111 → 190 not taken.
✓ Branch 112 → 113 taken 835 times.
✗ Branch 112 → 190 not taken.
836 entryNode->modAttrs.push_back(std::any_cast<ModAttrNode *>(visit(modAttrCtx)));
48
1/2
✓ Branch 115 → 116 taken 2787 times.
✗ Branch 115 → 117 not taken.
2787 else if (const auto *eofCtx = dynamic_cast<TerminalNode *>(child);
49
5/10
✓ Branch 118 → 119 taken 2787 times.
✗ Branch 118 → 122 not taken.
✓ Branch 119 → 120 taken 2787 times.
✗ Branch 119 → 194 not taken.
✓ Branch 120 → 121 taken 2787 times.
✗ Branch 120 → 194 not taken.
✗ Branch 121 → 122 not taken.
✓ Branch 121 → 123 taken 2787 times.
✗ Branch 124 → 125 not taken.
✓ Branch 124 → 126 taken 2787 times.
2787 !eofCtx || eofCtx->getSymbol()->getType() != SpiceParser::EOF)
50 assert_fail("Unknown top level definition type"); // GCOV_EXCL_LINE
51 }
52
53
1/2
✓ Branch 142 → 143 taken 2787 times.
✗ Branch 142 → 195 not taken.
5574 return concludeNode(entryNode);
54 }
55
56 607 std::any ASTBuilder::visitMainFunctionDef(SpiceParser::MainFunctionDefContext *ctx) {
57 607 const auto mainFctDefNode = createNode<MainFctDefNode>(ctx);
58
59 // Visit children
60
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 10 taken 606 times.
607 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<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr()));
62
2/2
✓ Branch 11 → 12 taken 7 times.
✓ Branch 11 → 17 taken 600 times.
607 if (ctx->paramLst()) {
63 7 mainFctDefNode->takesArgs = true;
64
3/6
✓ Branch 12 → 13 taken 7 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 7 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 7 times.
✗ Branch 14 → 34 not taken.
7 mainFctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
65 }
66
5/8
✓ Branch 17 → 18 taken 607 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 603 times.
✓ Branch 18 → 39 taken 4 times.
✓ Branch 19 → 20 taken 603 times.
✗ Branch 19 → 37 not taken.
✓ Branch 21 → 22 taken 603 times.
✗ Branch 21 → 40 not taken.
607 mainFctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
67
68
1/2
✓ Branch 27 → 28 taken 603 times.
✗ Branch 27 → 40 not taken.
1206 return concludeNode(mainFctDefNode);
69 }
70
71 24318 std::any ASTBuilder::visitFunctionDef(SpiceParser::FunctionDefContext *ctx) {
72 24318 const auto fctDefNode = createNode<FctDefNode>(ctx);
73
74 // Visit children
75
2/2
✓ Branch 4 → 5 taken 787 times.
✓ Branch 4 → 24 taken 23531 times.
24318 if (ctx->topLevelDefAttr()) {
76
3/6
✓ Branch 5 → 6 taken 787 times.
✗ Branch 5 → 70 not taken.
✓ Branch 6 → 7 taken 787 times.
✗ Branch 6 → 70 not taken.
✓ Branch 7 → 8 taken 787 times.
✗ Branch 7 → 68 not taken.
787 fctDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr()));
77 // Tell the attributes that they are function attributes
78
2/2
✓ Branch 22 → 11 taken 889 times.
✓ Branch 22 → 23 taken 787 times.
2463 for (AttrNode *attr : fctDefNode->attrs->attrLst->attributes)
79 889 attr->target = AttrNode::TARGET_FCT_PROC;
80 }
81
2/2
✓ Branch 25 → 26 taken 23254 times.
✓ Branch 25 → 31 taken 1064 times.
24318 if (ctx->qualifierLst())
82
3/6
✓ Branch 26 → 27 taken 23254 times.
✗ Branch 26 → 73 not taken.
✓ Branch 27 → 28 taken 23254 times.
✗ Branch 27 → 73 not taken.
✓ Branch 28 → 29 taken 23254 times.
✗ Branch 28 → 71 not taken.
23254 fctDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
83
3/6
✓ Branch 31 → 32 taken 24318 times.
✗ Branch 31 → 76 not taken.
✓ Branch 32 → 33 taken 24318 times.
✗ Branch 32 → 76 not taken.
✓ Branch 33 → 34 taken 24318 times.
✗ Branch 33 → 74 not taken.
24318 fctDefNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
84 24318 fctDefNode->returnType->isReturnType = true;
85
3/6
✓ Branch 35 → 36 taken 24318 times.
✗ Branch 35 → 79 not taken.
✓ Branch 36 → 37 taken 24318 times.
✗ Branch 36 → 79 not taken.
✓ Branch 37 → 38 taken 24318 times.
✗ Branch 37 → 77 not taken.
24318 fctDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName()));
86 24318 fctDefNode->isMethod = fctDefNode->name->nameFragments.size() > 1;
87
2/2
✓ Branch 41 → 42 taken 2588 times.
✓ Branch 41 → 47 taken 21730 times.
24318 if (ctx->typeLst()) {
88 2588 fctDefNode->hasTemplateTypes = true;
89
3/6
✓ Branch 42 → 43 taken 2588 times.
✗ Branch 42 → 82 not taken.
✓ Branch 43 → 44 taken 2588 times.
✗ Branch 43 → 82 not taken.
✓ Branch 44 → 45 taken 2588 times.
✗ Branch 44 → 80 not taken.
2588 fctDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
90 }
91
2/2
✓ Branch 48 → 49 taken 17844 times.
✓ Branch 48 → 54 taken 6474 times.
24318 if (ctx->paramLst()) {
92 17844 fctDefNode->hasParams = true;
93
3/6
✓ Branch 49 → 50 taken 17844 times.
✗ Branch 49 → 85 not taken.
✓ Branch 50 → 51 taken 17844 times.
✗ Branch 50 → 85 not taken.
✓ Branch 51 → 52 taken 17844 times.
✗ Branch 51 → 83 not taken.
17844 fctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
94 }
95
4/8
✓ Branch 54 → 55 taken 24318 times.
✗ Branch 54 → 88 not taken.
✓ Branch 55 → 56 taken 24318 times.
✗ Branch 55 → 88 not taken.
✓ Branch 56 → 57 taken 24318 times.
✗ Branch 56 → 86 not taken.
✓ Branch 58 → 59 taken 24318 times.
✗ Branch 58 → 89 not taken.
24318 fctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
96
97
1/2
✓ Branch 64 → 65 taken 24318 times.
✗ Branch 64 → 89 not taken.
48636 return concludeNode(fctDefNode);
98 }
99
100 12912 std::any ASTBuilder::visitProcedureDef(SpiceParser::ProcedureDefContext *ctx) {
101 12912 const auto procDefNode = createNode<ProcDefNode>(ctx);
102
103 // Visit children
104
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 24 taken 12911 times.
12912 if (ctx->topLevelDefAttr()) {
105
3/6
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 66 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 66 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 64 not taken.
1 procDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr()));
106 // Tell the attributes that they are function attributes
107
2/2
✓ Branch 22 → 11 taken 1 time.
✓ Branch 22 → 23 taken 1 time.
3 for (AttrNode *attr : procDefNode->attrs->attrLst->attributes)
108 1 attr->target = AttrNode::TARGET_FCT_PROC;
109 }
110
2/2
✓ Branch 25 → 26 taken 11281 times.
✓ Branch 25 → 31 taken 1631 times.
12912 if (ctx->qualifierLst())
111
3/6
✓ Branch 26 → 27 taken 11281 times.
✗ Branch 26 → 69 not taken.
✓ Branch 27 → 28 taken 11281 times.
✗ Branch 27 → 69 not taken.
✓ Branch 28 → 29 taken 11281 times.
✗ Branch 28 → 67 not taken.
11281 procDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
112
3/6
✓ Branch 31 → 32 taken 12912 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 12912 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 12912 times.
✗ Branch 33 → 70 not taken.
12912 procDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName()));
113 12912 procDefNode->isMethod = procDefNode->name->nameFragments.size() > 1;
114
2/2
✓ Branch 37 → 38 taken 2547 times.
✓ Branch 37 → 43 taken 10365 times.
12912 if (ctx->typeLst()) {
115 2547 procDefNode->hasTemplateTypes = true;
116
3/6
✓ Branch 38 → 39 taken 2547 times.
✗ Branch 38 → 75 not taken.
✓ Branch 39 → 40 taken 2547 times.
✗ Branch 39 → 75 not taken.
✓ Branch 40 → 41 taken 2547 times.
✗ Branch 40 → 73 not taken.
2547 procDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
117 }
118
2/2
✓ Branch 44 → 45 taken 9936 times.
✓ Branch 44 → 50 taken 2976 times.
12912 if (ctx->paramLst()) {
119 9936 procDefNode->hasParams = true;
120
3/6
✓ Branch 45 → 46 taken 9936 times.
✗ Branch 45 → 78 not taken.
✓ Branch 46 → 47 taken 9936 times.
✗ Branch 46 → 78 not taken.
✓ Branch 47 → 48 taken 9936 times.
✗ Branch 47 → 76 not taken.
9936 procDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
121 }
122
4/8
✓ Branch 50 → 51 taken 12912 times.
✗ Branch 50 → 81 not taken.
✓ Branch 51 → 52 taken 12912 times.
✗ Branch 51 → 81 not taken.
✓ Branch 52 → 53 taken 12912 times.
✗ Branch 52 → 79 not taken.
✓ Branch 54 → 55 taken 12912 times.
✗ Branch 54 → 82 not taken.
12912 procDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
123
124
1/2
✓ Branch 60 → 61 taken 12912 times.
✗ Branch 60 → 82 not taken.
25824 return concludeNode(procDefNode);
125 }
126
127 37230 std::any ASTBuilder::visitFctName(SpiceParser::FctNameContext *ctx) {
128
1/2
✓ Branch 2 → 3 taken 37230 times.
✗ Branch 2 → 54 not taken.
37230 const auto fctNameNode = createNode<FctNameNode>(ctx);
129
130 // Extract function name
131
1/2
✓ Branch 3 → 4 taken 37230 times.
✗ Branch 3 → 54 not taken.
37230 std::stringstream fqName;
132
3/4
✓ Branch 4 → 5 taken 37230 times.
✗ Branch 4 → 52 not taken.
✓ Branch 5 → 6 taken 23213 times.
✓ Branch 5 → 14 taken 14017 times.
37230 if (ctx->TYPE_IDENTIFIER()) {
133
2/4
✓ Branch 6 → 7 taken 23213 times.
✗ Branch 6 → 45 not taken.
✓ Branch 7 → 8 taken 23213 times.
✗ Branch 7 → 45 not taken.
23213 const std::string typeIdentifier = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
134
1/2
✓ Branch 8 → 9 taken 23213 times.
✗ Branch 8 → 43 not taken.
23213 fctNameNode->structName = typeIdentifier;
135
2/4
✓ Branch 9 → 10 taken 23213 times.
✗ Branch 9 → 43 not taken.
✓ Branch 10 → 11 taken 23213 times.
✗ Branch 10 → 43 not taken.
23213 fqName << typeIdentifier << MEMBER_ACCESS_TOKEN;
136
1/2
✓ Branch 11 → 12 taken 23213 times.
✗ Branch 11 → 43 not taken.
23213 fctNameNode->nameFragments.push_back(typeIdentifier);
137 23213 }
138
3/4
✓ Branch 14 → 15 taken 37230 times.
✗ Branch 14 → 52 not taken.
✓ Branch 15 → 16 taken 33167 times.
✓ Branch 15 → 23 taken 4063 times.
37230 if (ctx->IDENTIFIER()) {
139
2/4
✓ Branch 16 → 17 taken 33167 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 33167 times.
✗ Branch 17 → 48 not taken.
33167 const std::string fctIdentifier = getIdentifier(ctx->IDENTIFIER(), false);
140
1/2
✓ Branch 18 → 19 taken 33167 times.
✗ Branch 18 → 46 not taken.
33167 fctNameNode->name = fctIdentifier;
141
1/2
✓ Branch 19 → 20 taken 33167 times.
✗ Branch 19 → 46 not taken.
33167 fqName << fctIdentifier;
142
1/2
✓ Branch 20 → 21 taken 33167 times.
✗ Branch 20 → 46 not taken.
33167 fctNameNode->nameFragments.push_back(fctIdentifier);
143 33167 }
144
1/2
✓ Branch 23 → 24 taken 37230 times.
✗ Branch 23 → 49 not taken.
37230 fctNameNode->fqName = fqName.str();
145
146 // Visit children
147
3/4
✓ Branch 26 → 27 taken 37230 times.
✗ Branch 26 → 52 not taken.
✓ Branch 27 → 28 taken 4063 times.
✓ Branch 27 → 32 taken 33167 times.
37230 if (ctx->overloadableOp())
148
2/4
✓ Branch 28 → 29 taken 4063 times.
✗ Branch 28 → 50 not taken.
✓ Branch 29 → 30 taken 4063 times.
✗ Branch 29 → 50 not taken.
4063 visit(ctx->overloadableOp());
149
150
1/2
✓ Branch 38 → 39 taken 37230 times.
✗ Branch 38 → 51 not taken.
74460 return concludeNode(fctNameNode);
151 37230 }
152
153 3282 std::any ASTBuilder::visitStructDef(SpiceParser::StructDefContext *ctx) {
154 3282 const auto structDefNode = createNode<StructDefNode>(ctx);
155
156 // Enrich
157
3/4
✓ Branch 3 → 4 taken 3282 times.
✗ Branch 3 → 103 not taken.
✓ Branch 4 → 5 taken 3281 times.
✓ Branch 4 → 103 taken 1 time.
3282 structDefNode->structName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
158 3281 structDefNode->typeId = resourceManager.getNextCustomTypeId();
159
160 // Visit children
161
2/2
✓ Branch 9 → 10 taken 125 times.
✓ Branch 9 → 49 taken 3156 times.
3281 if (ctx->topLevelDefAttr()) {
162
3/6
✓ Branch 10 → 11 taken 125 times.
✗ Branch 10 → 106 not taken.
✓ Branch 11 → 12 taken 125 times.
✗ Branch 11 → 106 not taken.
✓ Branch 12 → 13 taken 125 times.
✗ Branch 12 → 104 not taken.
125 structDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr()));
163
164 // Tell the attributes that they are struct attributes
165
2/2
✓ Branch 27 → 16 taken 125 times.
✓ Branch 27 → 28 taken 125 times.
375 for (AttrNode *attr : structDefNode->attrs->attrLst->attributes)
166 125 attr->target = AttrNode::TARGET_STRUCT;
167
168 // Check if a custom type id was set
169
7/18
✓ Branch 28 → 29 taken 125 times.
✗ Branch 28 → 35 not taken.
✓ Branch 31 → 32 taken 125 times.
✗ Branch 31 → 107 not taken.
✓ Branch 32 → 33 taken 125 times.
✗ Branch 32 → 107 not taken.
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 125 times.
✓ Branch 36 → 37 taken 125 times.
✗ Branch 36 → 38 not taken.
✓ Branch 38 → 39 taken 125 times.
✗ Branch 38 → 41 not taken.
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 125 times.
✗ Branch 107 → 108 not taken.
✗ Branch 107 → 109 not taken.
✗ Branch 111 → 112 not taken.
✗ Branch 111 → 114 not taken.
375 if (structDefNode->attrs && structDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID))
170 structDefNode->typeId = structDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue;
171 }
172
2/2
✓ Branch 50 → 51 taken 2984 times.
✓ Branch 50 → 56 taken 297 times.
3281 if (ctx->qualifierLst())
173
3/6
✓ Branch 51 → 52 taken 2984 times.
✗ Branch 51 → 124 not taken.
✓ Branch 52 → 53 taken 2984 times.
✗ Branch 52 → 124 not taken.
✓ Branch 53 → 54 taken 2984 times.
✗ Branch 53 → 122 not taken.
2984 structDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
174
2/2
✓ Branch 57 → 58 taken 736 times.
✓ Branch 57 → 63 taken 2545 times.
3281 if (ctx->LESS()) {
175 736 structDefNode->hasTemplateTypes = true;
176
3/6
✓ Branch 58 → 59 taken 736 times.
✗ Branch 58 → 127 not taken.
✓ Branch 59 → 60 taken 736 times.
✗ Branch 59 → 127 not taken.
✓ Branch 60 → 61 taken 736 times.
✗ Branch 60 → 125 not taken.
736 structDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0)));
177 }
178
2/2
✓ Branch 64 → 65 taken 378 times.
✓ Branch 64 → 73 taken 2903 times.
3281 if (ctx->COLON()) {
179 378 structDefNode->hasInterfaces = true;
180
5/8
✓ Branch 65 → 66 taken 313 times.
✓ Branch 65 → 67 taken 65 times.
✓ Branch 68 → 69 taken 378 times.
✗ Branch 68 → 130 not taken.
✓ Branch 69 → 70 taken 378 times.
✗ Branch 69 → 130 not taken.
✓ Branch 70 → 71 taken 378 times.
✗ Branch 70 → 128 not taken.
378 structDefNode->interfaceTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(structDefNode->hasTemplateTypes ? 1 : 0)));
181 }
182
3/4
✓ Branch 73 → 74 taken 3281 times.
✗ Branch 73 → 137 not taken.
✓ Branch 91 → 76 taken 6268 times.
✓ Branch 91 → 92 taken 3281 times.
12830 for (SpiceParser::FieldContext *field : ctx->field())
183
3/6
✓ Branch 78 → 79 taken 6268 times.
✗ Branch 78 → 133 not taken.
✓ Branch 79 → 80 taken 6268 times.
✗ Branch 79 → 131 not taken.
✓ Branch 80 → 81 taken 6268 times.
✗ Branch 80 → 131 not taken.
9549 structDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field)));
184
185
1/2
✓ Branch 99 → 100 taken 3281 times.
✗ Branch 99 → 138 not taken.
6562 return concludeNode(structDefNode);
186 }
187
188 405 std::any ASTBuilder::visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) {
189 405 const auto interfaceDefNode = createNode<InterfaceDefNode>(ctx);
190
191 // Enrich
192
2/4
✓ Branch 3 → 4 taken 405 times.
✗ Branch 3 → 93 not taken.
✓ Branch 4 → 5 taken 405 times.
✗ Branch 4 → 93 not taken.
405 interfaceDefNode->interfaceName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
193 405 interfaceDefNode->typeId = resourceManager.getNextCustomTypeId();
194
195 // Visit children
196
2/2
✓ Branch 9 → 10 taken 187 times.
✓ Branch 9 → 49 taken 218 times.
405 if (ctx->topLevelDefAttr()) {
197
3/6
✓ Branch 10 → 11 taken 187 times.
✗ Branch 10 → 96 not taken.
✓ Branch 11 → 12 taken 187 times.
✗ Branch 11 → 96 not taken.
✓ Branch 12 → 13 taken 187 times.
✗ Branch 12 → 94 not taken.
187 interfaceDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr()));
198
199 // Tell the attributes that they are struct attributes
200
2/2
✓ Branch 27 → 16 taken 187 times.
✓ Branch 27 → 28 taken 187 times.
561 for (AttrNode *attr : interfaceDefNode->attrs->attrLst->attributes)
201 187 attr->target = AttrNode::TARGET_INTERFACE;
202
203 // Check if a custom type id was set
204
7/18
✓ Branch 28 → 29 taken 187 times.
✗ Branch 28 → 35 not taken.
✓ Branch 31 → 32 taken 187 times.
✗ Branch 31 → 97 not taken.
✓ Branch 32 → 33 taken 187 times.
✗ Branch 32 → 97 not taken.
✓ Branch 33 → 34 taken 187 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 187 times.
✗ Branch 36 → 38 not taken.
✓ Branch 38 → 39 taken 187 times.
✗ Branch 38 → 41 not taken.
✓ Branch 41 → 42 taken 187 times.
✗ Branch 41 → 49 not taken.
✗ Branch 97 → 98 not taken.
✗ Branch 97 → 99 not taken.
✗ Branch 101 → 102 not taken.
✗ Branch 101 → 104 not taken.
561 if (interfaceDefNode->attrs && interfaceDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID))
205
2/4
✓ Branch 44 → 45 taken 187 times.
✗ Branch 44 → 108 not taken.
✓ Branch 45 → 46 taken 187 times.
✗ Branch 45 → 106 not taken.
561 interfaceDefNode->typeId = interfaceDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue;
206 }
207
2/2
✓ Branch 50 → 51 taken 384 times.
✓ Branch 50 → 56 taken 21 times.
405 if (ctx->qualifierLst())
208
3/6
✓ Branch 51 → 52 taken 384 times.
✗ Branch 51 → 114 not taken.
✓ Branch 52 → 53 taken 384 times.
✗ Branch 52 → 114 not taken.
✓ Branch 53 → 54 taken 384 times.
✗ Branch 53 → 112 not taken.
384 interfaceDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
209
2/2
✓ Branch 57 → 58 taken 191 times.
✓ Branch 57 → 63 taken 214 times.
405 if (ctx->LESS()) {
210 191 interfaceDefNode->hasTemplateTypes = true;
211
3/6
✓ Branch 58 → 59 taken 191 times.
✗ Branch 58 → 117 not taken.
✓ Branch 59 → 60 taken 191 times.
✗ Branch 59 → 117 not taken.
✓ Branch 60 → 61 taken 191 times.
✗ Branch 60 → 115 not taken.
191 interfaceDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
212 }
213
3/4
✓ Branch 63 → 64 taken 405 times.
✗ Branch 63 → 124 not taken.
✓ Branch 81 → 66 taken 2440 times.
✓ Branch 81 → 82 taken 405 times.
3250 for (SpiceParser::SignatureContext *signature : ctx->signature())
214
3/6
✓ Branch 68 → 69 taken 2440 times.
✗ Branch 68 → 120 not taken.
✓ Branch 69 → 70 taken 2440 times.
✗ Branch 69 → 118 not taken.
✓ Branch 70 → 71 taken 2440 times.
✗ Branch 70 → 118 not taken.
2845 interfaceDefNode->signatures.push_back(std::any_cast<SignatureNode *>(visit(signature)));
215
216
1/2
✓ Branch 89 → 90 taken 405 times.
✗ Branch 89 → 125 not taken.
810 return concludeNode(interfaceDefNode);
217 }
218
219 611 std::any ASTBuilder::visitEnumDef(SpiceParser::EnumDefContext *ctx) {
220 611 const auto enumDefNode = createNode<EnumDefNode>(ctx);
221
222 // Enrich
223
2/4
✓ Branch 3 → 4 taken 611 times.
✗ Branch 3 → 43 not taken.
✓ Branch 4 → 5 taken 611 times.
✗ Branch 4 → 43 not taken.
611 enumDefNode->enumName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
224 611 enumDefNode->typeId = resourceManager.getNextCustomTypeId();
225
226 // Visit children
227
2/2
✓ Branch 9 → 10 taken 569 times.
✓ Branch 9 → 15 taken 42 times.
611 if (ctx->qualifierLst())
228
3/6
✓ Branch 10 → 11 taken 569 times.
✗ Branch 10 → 46 not taken.
✓ Branch 11 → 12 taken 569 times.
✗ Branch 11 → 46 not taken.
✓ Branch 12 → 13 taken 569 times.
✗ Branch 12 → 44 not taken.
569 enumDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
229
3/6
✓ Branch 15 → 16 taken 611 times.
✗ Branch 15 → 49 not taken.
✓ Branch 16 → 17 taken 611 times.
✗ Branch 16 → 49 not taken.
✓ Branch 17 → 18 taken 611 times.
✗ Branch 17 → 47 not taken.
611 enumDefNode->itemLst = std::any_cast<EnumItemLstNode *>(visit(ctx->enumItemLst()));
230
231 // Tell all items about the enum def
232
2/2
✓ Branch 32 → 21 taken 5485 times.
✓ Branch 32 → 33 taken 611 times.
6707 for (EnumItemNode *enumItem : enumDefNode->itemLst->items)
233 5485 enumItem->enumDef = enumDefNode;
234
235
1/2
✓ Branch 39 → 40 taken 611 times.
✗ Branch 39 → 50 not taken.
1222 return concludeNode(enumDefNode);
236 }
237
238 2260 std::any ASTBuilder::visitGenericTypeDef(SpiceParser::GenericTypeDefContext *ctx) {
239 2260 const auto genericTypeDefNode = createNode<GenericTypeDefNode>(ctx);
240
241 // Enrich
242
2/4
✓ Branch 3 → 4 taken 2260 times.
✗ Branch 3 → 21 not taken.
✓ Branch 4 → 5 taken 2260 times.
✗ Branch 4 → 21 not taken.
2260 genericTypeDefNode->typeName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
243
244 // Visit children
245
4/8
✓ Branch 7 → 8 taken 2260 times.
✗ Branch 7 → 24 not taken.
✓ Branch 8 → 9 taken 2260 times.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 2260 times.
✗ Branch 9 → 22 not taken.
✓ Branch 11 → 12 taken 2260 times.
✗ Branch 11 → 25 not taken.
2260 genericTypeDefNode->typeAltsLst = std::any_cast<TypeAltsLstNode *>(visit(ctx->typeAltsLst()));
246
247
1/2
✓ Branch 17 → 18 taken 2260 times.
✗ Branch 17 → 25 not taken.
4520 return concludeNode(genericTypeDefNode);
248 }
249
250 352 std::any ASTBuilder::visitAliasDef(SpiceParser::AliasDefContext *ctx) {
251 352 const auto aliasDefNode = createNode<AliasDefNode>(ctx);
252
253 // Enrich
254
2/4
✓ Branch 3 → 4 taken 352 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 352 times.
✗ Branch 4 → 33 not taken.
352 aliasDefNode->aliasName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
255
2/4
✓ Branch 7 → 8 taken 352 times.
✗ Branch 7 → 34 not taken.
✓ Branch 8 → 9 taken 352 times.
✗ Branch 8 → 34 not taken.
352 aliasDefNode->dataTypeString = ctx->dataType()->getText();
256 352 aliasDefNode->typeId = resourceManager.getNextCustomTypeId();
257
258 // Visit children
259
2/2
✓ Branch 13 → 14 taken 111 times.
✓ Branch 13 → 19 taken 241 times.
352 if (ctx->qualifierLst())
260
3/6
✓ Branch 14 → 15 taken 111 times.
✗ Branch 14 → 37 not taken.
✓ Branch 15 → 16 taken 111 times.
✗ Branch 15 → 37 not taken.
✓ Branch 16 → 17 taken 111 times.
✗ Branch 16 → 35 not taken.
111 aliasDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
261
4/8
✓ Branch 19 → 20 taken 352 times.
✗ Branch 19 → 40 not taken.
✓ Branch 20 → 21 taken 352 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 352 times.
✗ Branch 21 → 38 not taken.
✓ Branch 23 → 24 taken 352 times.
✗ Branch 23 → 41 not taken.
352 aliasDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
262
263
1/2
✓ Branch 29 → 30 taken 352 times.
✗ Branch 29 → 41 not taken.
704 return concludeNode(aliasDefNode);
264 }
265
266 2743 std::any ASTBuilder::visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) {
267 2743 const auto globalVarDefNode = createNode<GlobalVarDefNode>(ctx);
268
269 // Enrich
270
2/4
✓ Branch 3 → 4 taken 2743 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 2743 times.
✗ Branch 4 → 28 not taken.
2743 globalVarDefNode->varName = getIdentifier(ctx->TYPE_IDENTIFIER(), true);
271
272 // Visit children
273
3/6
✓ Branch 7 → 8 taken 2743 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 2743 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 2743 times.
✗ Branch 9 → 29 not taken.
2743 globalVarDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
274 2743 globalVarDefNode->dataType->isGlobalType = true;
275
2/2
✓ Branch 12 → 13 taken 2741 times.
✓ Branch 12 → 18 taken 2 times.
2743 if (ctx->constant()) {
276 2741 globalVarDefNode->hasValue = true;
277
3/6
✓ Branch 13 → 14 taken 2741 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 2741 times.
✗ Branch 14 → 34 not taken.
✓ Branch 15 → 16 taken 2741 times.
✗ Branch 15 → 32 not taken.
2741 globalVarDefNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
278 }
279
280
1/2
✓ Branch 24 → 25 taken 2743 times.
✗ Branch 24 → 35 not taken.
5486 return concludeNode(globalVarDefNode);
281 }
282
283 4205 std::any ASTBuilder::visitExtDecl(SpiceParser::ExtDeclContext *ctx) {
284 4205 const auto extDeclNode = createNode<ExtDeclNode>(ctx);
285
286 // Enrich
287
6/10
✓ Branch 3 → 4 taken 4205 times.
✗ Branch 3 → 57 not taken.
✓ Branch 4 → 5 taken 2808 times.
✓ Branch 4 → 7 taken 1397 times.
✓ Branch 5 → 6 taken 2808 times.
✗ Branch 5 → 57 not taken.
✓ Branch 7 → 8 taken 1397 times.
✗ Branch 7 → 57 not taken.
✓ Branch 9 → 10 taken 4205 times.
✗ Branch 9 → 57 not taken.
4205 extDeclNode->extFunctionName = getIdentifier(ctx->IDENTIFIER() ? ctx->IDENTIFIER() : ctx->TYPE_IDENTIFIER(), false);
288
289 // Visit children
290
2/2
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 33 taken 4204 times.
4205 if (ctx->topLevelDefAttr()) {
291
3/6
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 60 not taken.
✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 60 not taken.
✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 58 not taken.
1 extDeclNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr()));
292
293 // Tell the attributes that they are ext decl attributes
294
2/2
✓ Branch 31 → 20 taken 1 time.
✓ Branch 31 → 32 taken 1 time.
3 for (AttrNode *attr : extDeclNode->attrs->attrLst->attributes)
295 1 attr->target = AttrNode::TARGET_EXT_DECL;
296 }
297
2/2
✓ Branch 34 → 35 taken 3394 times.
✓ Branch 34 → 40 taken 811 times.
4205 if (ctx->F()) {
298
3/6
✓ Branch 35 → 36 taken 3394 times.
✗ Branch 35 → 63 not taken.
✓ Branch 36 → 37 taken 3394 times.
✗ Branch 36 → 63 not taken.
✓ Branch 37 → 38 taken 3394 times.
✗ Branch 37 → 61 not taken.
3394 extDeclNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
299 3394 extDeclNode->returnType->isReturnType = true;
300 }
301
2/2
✓ Branch 41 → 42 taken 3996 times.
✓ Branch 41 → 47 taken 209 times.
4205 if (ctx->typeLstWithEllipsis()) {
302 3996 extDeclNode->hasArgs = true;
303
3/6
✓ Branch 42 → 43 taken 3996 times.
✗ Branch 42 → 66 not taken.
✓ Branch 43 → 44 taken 3996 times.
✗ Branch 43 → 66 not taken.
✓ Branch 44 → 45 taken 3996 times.
✗ Branch 44 → 64 not taken.
3996 extDeclNode->argTypeLst = std::any_cast<TypeLstWithEllipsisNode *>(visit(ctx->typeLstWithEllipsis()));
304 }
305
306
1/2
✓ Branch 53 → 54 taken 4205 times.
✗ Branch 53 → 67 not taken.
8410 return concludeNode(extDeclNode);
307 }
308
309 2737 std::any ASTBuilder::visitImportDef(SpiceParser::ImportDefContext *ctx) {
310
1/2
✓ Branch 2 → 3 taken 2737 times.
✗ Branch 2 → 32 not taken.
2737 const auto importDefNode = createNode<ImportDefNode>(ctx);
311
312 // Extract path
313
2/4
✓ Branch 3 → 4 taken 2737 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 2737 times.
✗ Branch 4 → 32 not taken.
2737 const std::string pathStr = ctx->STRING_LIT()->getText();
314
1/2
✓ Branch 6 → 7 taken 2737 times.
✗ Branch 6 → 27 not taken.
2737 importDefNode->importPath = pathStr.substr(1, pathStr.size() - 2);
315
316 // If no name is given, use the path as name
317
7/12
✓ Branch 9 → 10 taken 2737 times.
✗ Branch 9 → 28 not taken.
✓ Branch 10 → 11 taken 102 times.
✓ Branch 10 → 13 taken 2635 times.
✓ Branch 11 → 12 taken 102 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 14 taken 102 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 2635 times.
✗ Branch 13 → 28 not taken.
✓ Branch 16 → 17 taken 2737 times.
✗ Branch 16 → 29 not taken.
2737 importDefNode->importName = ctx->AS() ? getIdentifier(ctx->IDENTIFIER(), false) : importDefNode->importPath;
318
319
1/2
✓ Branch 22 → 23 taken 2737 times.
✗ Branch 22 → 29 not taken.
5474 return concludeNode(importDefNode);
320 2737 }
321
322 8773 std::any ASTBuilder::visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) {
323 8773 const auto unsafeBlockDefNode = createNode<UnsafeBlockNode>(ctx);
324
325 // Visit children
326
4/8
✓ Branch 3 → 4 taken 8773 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 8773 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 8773 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 8773 times.
✗ Branch 7 → 20 not taken.
8773 unsafeBlockDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
327
328
1/2
✓ Branch 13 → 14 taken 8773 times.
✗ Branch 13 → 20 not taken.
17546 return concludeNode(unsafeBlockDefNode);
329 }
330
331 3001 std::any ASTBuilder::visitForLoop(SpiceParser::ForLoopContext *ctx) {
332 3001 const auto forLoopNode = createNode<ForLoopNode>(ctx);
333
334
2/4
✓ Branch 3 → 4 taken 3001 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 3001 times.
✗ Branch 4 → 20 not taken.
3001 visit(ctx->forHead());
335
4/8
✓ Branch 6 → 7 taken 3001 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 3001 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 3001 times.
✗ Branch 8 → 21 not taken.
✓ Branch 10 → 11 taken 3001 times.
✗ Branch 10 → 24 not taken.
3001 forLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
336
337
1/2
✓ Branch 16 → 17 taken 3001 times.
✗ Branch 16 → 24 not taken.
6002 return concludeNode(forLoopNode);
338 }
339
340 3001 std::any ASTBuilder::visitForHead(SpiceParser::ForHeadContext *ctx) {
341 3001 const auto forLoopNode = resumeForExpansion<ForLoopNode>();
342
343 // Visit children
344
3/6
✓ Branch 14 → 15 taken 3001 times.
✗ Branch 14 → 32 not taken.
✓ Branch 15 → 16 taken 3001 times.
✗ Branch 15 → 32 not taken.
✓ Branch 16 → 17 taken 3001 times.
✗ Branch 16 → 30 not taken.
3001 forLoopNode->initDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt()));
345
3/6
✓ Branch 18 → 19 taken 3001 times.
✗ Branch 18 → 35 not taken.
✓ Branch 19 → 20 taken 3001 times.
✗ Branch 19 → 35 not taken.
✓ Branch 20 → 21 taken 3001 times.
✗ Branch 20 → 33 not taken.
3001 forLoopNode->condAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(0)));
346
3/6
✓ Branch 22 → 23 taken 3001 times.
✗ Branch 22 → 38 not taken.
✓ Branch 23 → 24 taken 3001 times.
✗ Branch 23 → 38 not taken.
✓ Branch 24 → 25 taken 3001 times.
✗ Branch 24 → 36 not taken.
3001 forLoopNode->incAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(1)));
347
348
1/2
✓ Branch 26 → 27 taken 3001 times.
✗ Branch 26 → 39 not taken.
6002 return nullptr;
349 }
350
351 411 std::any ASTBuilder::visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) {
352 411 const auto foreachLoopNode = createNode<ForeachLoopNode>(ctx);
353
354 // Visit children
355
2/4
✓ Branch 3 → 4 taken 411 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 411 times.
✗ Branch 4 → 20 not taken.
411 visit(ctx->foreachHead());
356
3/6
✓ Branch 6 → 7 taken 411 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 411 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 411 times.
✗ Branch 8 → 21 not taken.
411 foreachLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
357
358 // Tell the foreach item that it is one
359
1/2
✓ Branch 10 → 11 taken 411 times.
✗ Branch 10 → 24 not taken.
411 foreachLoopNode->itemVarDecl->isForEachItem = true;
360
361
1/2
✓ Branch 16 → 17 taken 411 times.
✗ Branch 16 → 24 not taken.
822 return concludeNode(foreachLoopNode);
362 }
363
364 411 std::any ASTBuilder::visitForeachHead(SpiceParser::ForeachHeadContext *ctx) {
365 411 const auto foreachLoopNode = resumeForExpansion<ForeachLoopNode>();
366
367 // Visit children
368
3/4
✓ Branch 14 → 15 taken 411 times.
✗ Branch 14 → 45 not taken.
✓ Branch 17 → 18 taken 353 times.
✓ Branch 17 → 23 taken 58 times.
411 if (ctx->declStmt().size() == 1) {
369
3/6
✓ Branch 18 → 19 taken 353 times.
✗ Branch 18 → 48 not taken.
✓ Branch 19 → 20 taken 353 times.
✗ Branch 19 → 48 not taken.
✓ Branch 20 → 21 taken 353 times.
✗ Branch 20 → 46 not taken.
353 foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0)));
370
2/4
✓ Branch 23 → 24 taken 58 times.
✗ Branch 23 → 49 not taken.
✓ Branch 26 → 27 taken 58 times.
✗ Branch 26 → 36 not taken.
58 } else if (ctx->declStmt().size() == 2) {
371
3/6
✓ Branch 27 → 28 taken 58 times.
✗ Branch 27 → 52 not taken.
✓ Branch 28 → 29 taken 58 times.
✗ Branch 28 → 52 not taken.
✓ Branch 29 → 30 taken 58 times.
✗ Branch 29 → 50 not taken.
58 foreachLoopNode->idxVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0)));
372
3/6
✓ Branch 31 → 32 taken 58 times.
✗ Branch 31 → 55 not taken.
✓ Branch 32 → 33 taken 58 times.
✗ Branch 32 → 55 not taken.
✓ Branch 33 → 34 taken 58 times.
✗ Branch 33 → 53 not taken.
58 foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(1)));
373 } else {
374 assert_fail("Invalid number of decl statements in foreach loop"); // GCOV_EXCL_LINE
375 }
376
3/6
✓ Branch 37 → 38 taken 411 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 411 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 411 times.
✗ Branch 39 → 56 not taken.
411 foreachLoopNode->iteratorAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
377
378
1/2
✓ Branch 41 → 42 taken 411 times.
✗ Branch 41 → 59 not taken.
822 return nullptr;
379 }
380
381 1508 std::any ASTBuilder::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) {
382 1508 const auto whileLoopNode = createNode<WhileLoopNode>(ctx);
383
384 // Visit children
385
3/6
✓ Branch 3 → 4 taken 1508 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 1508 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 1508 times.
✗ Branch 5 → 21 not taken.
1508 whileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
386
4/8
✓ Branch 7 → 8 taken 1508 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 1508 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 1508 times.
✗ Branch 9 → 24 not taken.
✓ Branch 11 → 12 taken 1508 times.
✗ Branch 11 → 27 not taken.
1508 whileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
387
388
1/2
✓ Branch 17 → 18 taken 1508 times.
✗ Branch 17 → 27 not taken.
3016 return concludeNode(whileLoopNode);
389 }
390
391 17 std::any ASTBuilder::visitDoWhileLoop(SpiceParser::DoWhileLoopContext *ctx) {
392 17 const auto doWhileLoopNode = createNode<DoWhileLoopNode>(ctx);
393
394 // Visit children
395
3/6
✓ Branch 3 → 4 taken 17 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 17 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 17 times.
✗ Branch 5 → 21 not taken.
17 doWhileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
396
4/8
✓ Branch 7 → 8 taken 17 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 17 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 17 times.
✗ Branch 9 → 24 not taken.
✓ Branch 11 → 12 taken 17 times.
✗ Branch 11 → 27 not taken.
17 doWhileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
397
398
1/2
✓ Branch 17 → 18 taken 17 times.
✗ Branch 17 → 27 not taken.
34 return concludeNode(doWhileLoopNode);
399 }
400
401 18264 std::any ASTBuilder::visitIfStmt(SpiceParser::IfStmtContext *ctx) {
402 18264 const auto ifStmtNode = createNode<IfStmtNode>(ctx);
403
404 // Visit children
405
3/6
✓ Branch 3 → 4 taken 18264 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 18264 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 18264 times.
✗ Branch 5 → 28 not taken.
18264 ifStmtNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
406
3/6
✓ Branch 7 → 8 taken 18264 times.
✗ Branch 7 → 33 not taken.
✓ Branch 8 → 9 taken 18264 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 18264 times.
✗ Branch 9 → 31 not taken.
18264 ifStmtNode->thenBody = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
407
2/2
✓ Branch 12 → 13 taken 1489 times.
✓ Branch 12 → 18 taken 16775 times.
18264 if (ctx->elseStmt())
408
3/6
✓ Branch 13 → 14 taken 1489 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 1489 times.
✗ Branch 14 → 36 not taken.
✓ Branch 15 → 16 taken 1489 times.
✗ Branch 15 → 34 not taken.
1489 ifStmtNode->elseStmt = std::any_cast<ElseStmtNode *>(visit(ctx->elseStmt()));
409
410
1/2
✓ Branch 24 → 25 taken 18264 times.
✗ Branch 24 → 37 not taken.
36528 return concludeNode(ifStmtNode);
411 }
412
413 1489 std::any ASTBuilder::visitElseStmt(SpiceParser::ElseStmtContext *ctx) {
414 1489 const auto elseStmtNode = createNode<ElseStmtNode>(ctx);
415
416 // Visit children
417
2/2
✓ Branch 4 → 5 taken 599 times.
✓ Branch 4 → 10 taken 890 times.
1489 if (ctx->ifStmt()) {
418 599 elseStmtNode->isElseIf = true;
419
3/6
✓ Branch 5 → 6 taken 599 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 599 times.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 599 times.
✗ Branch 7 → 25 not taken.
599 elseStmtNode->ifStmt = std::any_cast<IfStmtNode *>(visit(ctx->ifStmt()));
420 } else {
421
3/6
✓ Branch 10 → 11 taken 890 times.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 890 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 890 times.
✗ Branch 12 → 28 not taken.
890 elseStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
422 }
423
424
1/2
✓ Branch 21 → 22 taken 1489 times.
✗ Branch 21 → 31 not taken.
2978 return concludeNode(elseStmtNode);
425 }
426
427 94 std::any ASTBuilder::visitSwitchStmt(SpiceParser::SwitchStmtContext *ctx) {
428 94 const auto switchStmtNode = createNode<SwitchStmtNode>(ctx);
429
430 // Visit children
431
3/6
✓ Branch 3 → 4 taken 94 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 94 times.
✗ Branch 4 → 29 not taken.
✓ Branch 5 → 6 taken 94 times.
✗ Branch 5 → 27 not taken.
94 switchStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
432
2/4
✓ Branch 7 → 8 taken 94 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 94 times.
✗ Branch 8 → 30 not taken.
94 fetchChildrenIntoVector(switchStmtNode->caseBranches, ctx->caseBranch());
433
2/2
✓ Branch 11 → 12 taken 78 times.
✓ Branch 11 → 17 taken 16 times.
94 if (ctx->defaultBranch()) {
434 78 switchStmtNode->hasDefaultBranch = true;
435
3/6
✓ Branch 12 → 13 taken 78 times.
✗ Branch 12 → 35 not taken.
✓ Branch 13 → 14 taken 78 times.
✗ Branch 13 → 35 not taken.
✓ Branch 14 → 15 taken 78 times.
✗ Branch 14 → 33 not taken.
78 switchStmtNode->defaultBranch = std::any_cast<DefaultBranchNode *>(visit(ctx->defaultBranch()));
436 }
437
438
1/2
✓ Branch 23 → 24 taken 94 times.
✗ Branch 23 → 36 not taken.
188 return concludeNode(switchStmtNode);
439 }
440
441 768 std::any ASTBuilder::visitCaseBranch(SpiceParser::CaseBranchContext *ctx) {
442 768 const auto caseBranchNode = createNode<CaseBranchNode>(ctx);
443
444 // Visit children
445
2/4
✓ Branch 3 → 4 taken 768 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 768 times.
✗ Branch 4 → 20 not taken.
768 fetchChildrenIntoVector(caseBranchNode->caseConstants, ctx->caseConstant());
446
4/8
✓ Branch 6 → 7 taken 768 times.
✗ Branch 6 → 25 not taken.
✓ Branch 7 → 8 taken 768 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 768 times.
✗ Branch 8 → 23 not taken.
✓ Branch 10 → 11 taken 768 times.
✗ Branch 10 → 26 not taken.
768 caseBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
447
448
1/2
✓ Branch 16 → 17 taken 768 times.
✗ Branch 16 → 26 not taken.
1536 return concludeNode(caseBranchNode);
449 }
450
451 78 std::any ASTBuilder::visitDefaultBranch(SpiceParser::DefaultBranchContext *ctx) {
452 78 const auto defaultBranchNode = createNode<DefaultBranchNode>(ctx);
453
454 // Visit children
455
4/8
✓ Branch 3 → 4 taken 78 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 78 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 78 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 78 times.
✗ Branch 7 → 20 not taken.
78 defaultBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
456
457
1/2
✓ Branch 13 → 14 taken 78 times.
✗ Branch 13 → 20 not taken.
156 return concludeNode(defaultBranchNode);
458 }
459
460 67 std::any ASTBuilder::visitAnonymousBlockStmt(SpiceParser::AnonymousBlockStmtContext *ctx) {
461 67 const auto anonymousBlockStmtNode = createNode<AnonymousBlockStmtNode>(ctx);
462
463 // Visit children
464
4/8
✓ Branch 3 → 4 taken 67 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 67 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 67 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 67 times.
✗ Branch 7 → 20 not taken.
67 anonymousBlockStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
465
466
1/2
✓ Branch 13 → 14 taken 67 times.
✗ Branch 13 → 20 not taken.
134 return concludeNode(anonymousBlockStmtNode);
467 }
468
469 71744 std::any ASTBuilder::visitStmtLst(SpiceParser::StmtLstContext *ctx) {
470 71744 const auto stmtLstNode = createNode<StmtLstNode>(ctx);
471
472 // Enrich
473
2/4
✓ Branch 3 → 4 taken 71744 times.
✗ Branch 3 → 126 not taken.
✓ Branch 4 → 5 taken 71744 times.
✗ Branch 4 → 126 not taken.
71744 stmtLstNode->closingBraceCodeLoc = CodeLoc(ctx->getStop(), sourceFile);
474
475 // Visit children
476
2/2
✓ Branch 115 → 7 taken 281084 times.
✓ Branch 115 → 116 taken 71740 times.
424568 for (ParserRuleContext::ParseTree *stmt : ctx->children) {
477
3/4
✓ Branch 9 → 10 taken 281084 times.
✗ Branch 9 → 11 not taken.
✓ Branch 12 → 13 taken 101906 times.
✓ Branch 12 → 18 taken 179178 times.
281084 if (auto *stmtCtx = dynamic_cast<SpiceParser::StmtContext *>(stmt))
478
4/6
✓ Branch 13 → 14 taken 101902 times.
✓ Branch 13 → 129 taken 4 times.
✓ Branch 14 → 15 taken 101902 times.
✗ Branch 14 → 127 not taken.
✓ Branch 15 → 16 taken 101902 times.
✗ Branch 15 → 127 not taken.
101906 stmtLstNode->statements.push_back(std::any_cast<StmtNode *>(visit(stmtCtx)));
479
3/4
✓ Branch 18 → 19 taken 179178 times.
✗ Branch 18 → 20 not taken.
✓ Branch 21 → 22 taken 3001 times.
✓ Branch 21 → 27 taken 176177 times.
179178 else if (auto *forLoopCtx = dynamic_cast<SpiceParser::ForLoopContext *>(stmt))
480
3/6
✓ Branch 22 → 23 taken 3001 times.
✗ Branch 22 → 133 not taken.
✓ Branch 23 → 24 taken 3001 times.
✗ Branch 23 → 131 not taken.
✓ Branch 24 → 25 taken 3001 times.
✗ Branch 24 → 131 not taken.
3001 stmtLstNode->statements.push_back(std::any_cast<ForLoopNode *>(visit(forLoopCtx)));
481
3/4
✓ Branch 27 → 28 taken 176177 times.
✗ Branch 27 → 29 not taken.
✓ Branch 30 → 31 taken 411 times.
✓ Branch 30 → 36 taken 175766 times.
176177 else if (auto *foreachLoopCtx = dynamic_cast<SpiceParser::ForeachLoopContext *>(stmt))
482
3/6
✓ Branch 31 → 32 taken 411 times.
✗ Branch 31 → 137 not taken.
✓ Branch 32 → 33 taken 411 times.
✗ Branch 32 → 135 not taken.
✓ Branch 33 → 34 taken 411 times.
✗ Branch 33 → 135 not taken.
411 stmtLstNode->statements.push_back(std::any_cast<ForeachLoopNode *>(visit(foreachLoopCtx)));
483
3/4
✓ Branch 36 → 37 taken 175766 times.
✗ Branch 36 → 38 not taken.
✓ Branch 39 → 40 taken 1508 times.
✓ Branch 39 → 45 taken 174258 times.
175766 else if (auto *whileLoopCtx = dynamic_cast<SpiceParser::WhileLoopContext *>(stmt))
484
3/6
✓ Branch 40 → 41 taken 1508 times.
✗ Branch 40 → 141 not taken.
✓ Branch 41 → 42 taken 1508 times.
✗ Branch 41 → 139 not taken.
✓ Branch 42 → 43 taken 1508 times.
✗ Branch 42 → 139 not taken.
1508 stmtLstNode->statements.push_back(std::any_cast<WhileLoopNode *>(visit(whileLoopCtx)));
485
3/4
✓ Branch 45 → 46 taken 174258 times.
✗ Branch 45 → 47 not taken.
✓ Branch 48 → 49 taken 17 times.
✓ Branch 48 → 54 taken 174241 times.
174258 else if (auto *doWhileLoopCtx = dynamic_cast<SpiceParser::DoWhileLoopContext *>(stmt))
486
3/6
✓ Branch 49 → 50 taken 17 times.
✗ Branch 49 → 145 not taken.
✓ Branch 50 → 51 taken 17 times.
✗ Branch 50 → 143 not taken.
✓ Branch 51 → 52 taken 17 times.
✗ Branch 51 → 143 not taken.
17 stmtLstNode->statements.push_back(std::any_cast<DoWhileLoopNode *>(visit(doWhileLoopCtx)));
487
3/4
✓ Branch 54 → 55 taken 174241 times.
✗ Branch 54 → 56 not taken.
✓ Branch 57 → 58 taken 17665 times.
✓ Branch 57 → 63 taken 156576 times.
174241 else if (auto *ifStmtCtx = dynamic_cast<SpiceParser::IfStmtContext *>(stmt))
488
3/6
✓ Branch 58 → 59 taken 17665 times.
✗ Branch 58 → 149 not taken.
✓ Branch 59 → 60 taken 17665 times.
✗ Branch 59 → 147 not taken.
✓ Branch 60 → 61 taken 17665 times.
✗ Branch 60 → 147 not taken.
17665 stmtLstNode->statements.push_back(std::any_cast<IfStmtNode *>(visit(ifStmtCtx)));
489
3/4
✓ Branch 63 → 64 taken 156576 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 94 times.
✓ Branch 66 → 72 taken 156482 times.
156576 else if (auto *switchStmtCtx = dynamic_cast<SpiceParser::SwitchStmtContext *>(stmt))
490
3/6
✓ Branch 67 → 68 taken 94 times.
✗ Branch 67 → 153 not taken.
✓ Branch 68 → 69 taken 94 times.
✗ Branch 68 → 151 not taken.
✓ Branch 69 → 70 taken 94 times.
✗ Branch 69 → 151 not taken.
94 stmtLstNode->statements.push_back(std::any_cast<SwitchStmtNode *>(visit(switchStmtCtx)));
491
3/4
✓ Branch 72 → 73 taken 156482 times.
✗ Branch 72 → 74 not taken.
✓ Branch 75 → 76 taken 4158 times.
✓ Branch 75 → 81 taken 152324 times.
156482 else if (auto *assetStmtCtx = dynamic_cast<SpiceParser::AssertStmtContext *>(stmt))
492
3/6
✓ Branch 76 → 77 taken 4158 times.
✗ Branch 76 → 157 not taken.
✓ Branch 77 → 78 taken 4158 times.
✗ Branch 77 → 155 not taken.
✓ Branch 78 → 79 taken 4158 times.
✗ Branch 78 → 155 not taken.
4158 stmtLstNode->statements.push_back(std::any_cast<AssertStmtNode *>(visit(assetStmtCtx)));
493
3/4
✓ Branch 81 → 82 taken 152324 times.
✗ Branch 81 → 83 not taken.
✓ Branch 84 → 85 taken 8773 times.
✓ Branch 84 → 90 taken 143551 times.
152324 else if (auto *unsafeBlockCtx = dynamic_cast<SpiceParser::UnsafeBlockContext *>(stmt))
494
3/6
✓ Branch 85 → 86 taken 8773 times.
✗ Branch 85 → 161 not taken.
✓ Branch 86 → 87 taken 8773 times.
✗ Branch 86 → 159 not taken.
✓ Branch 87 → 88 taken 8773 times.
✗ Branch 87 → 159 not taken.
8773 stmtLstNode->statements.push_back(std::any_cast<UnsafeBlockNode *>(visit(unsafeBlockCtx)));
495
3/4
✓ Branch 90 → 91 taken 143551 times.
✗ Branch 90 → 92 not taken.
✓ Branch 93 → 94 taken 67 times.
✓ Branch 93 → 99 taken 143484 times.
143551 else if (auto *anonymousScopeCtx = dynamic_cast<SpiceParser::AnonymousBlockStmtContext *>(stmt))
496
3/6
✓ Branch 94 → 95 taken 67 times.
✗ Branch 94 → 165 not taken.
✓ Branch 95 → 96 taken 67 times.
✗ Branch 95 → 163 not taken.
✓ Branch 96 → 97 taken 67 times.
✗ Branch 96 → 163 not taken.
67 stmtLstNode->statements.push_back(std::any_cast<AnonymousBlockStmtNode *>(visit(anonymousScopeCtx)));
497 else
498 assert(is<TerminalNode *>(stmt)); // GCOV_EXCL_LINE
499 }
500
501
1/2
✓ Branch 122 → 123 taken 71740 times.
✗ Branch 122 → 168 not taken.
143480 return concludeNode(stmtLstNode);
502 }
503
504 25610 std::any ASTBuilder::visitTypeLst(SpiceParser::TypeLstContext *ctx) {
505 25610 const auto typeLstNode = createNode<TypeLstNode>(ctx);
506
507 // Visit children
508
3/6
✓ Branch 3 → 4 taken 25610 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 25610 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 25610 times.
✗ Branch 6 → 19 not taken.
25610 fetchChildrenIntoVector(typeLstNode->dataTypes, ctx->dataType());
509
510
1/2
✓ Branch 12 → 13 taken 25610 times.
✗ Branch 12 → 19 not taken.
51220 return concludeNode(typeLstNode);
511 }
512
513 3996 std::any ASTBuilder::visitTypeLstWithEllipsis(SpiceParser::TypeLstWithEllipsisContext *ctx) {
514 3996 const auto typeLstWithEllipsisNode = createNode<TypeLstWithEllipsisNode>(ctx);
515
516 // Visit children
517
3/6
✓ Branch 3 → 4 taken 3996 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 3996 times.
✗ Branch 4 → 20 not taken.
✓ Branch 5 → 6 taken 3996 times.
✗ Branch 5 → 18 not taken.
3996 typeLstWithEllipsisNode->typeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
518
519 // Set some flags
520
1/2
✓ Branch 8 → 9 taken 3996 times.
✗ Branch 8 → 21 not taken.
3996 typeLstWithEllipsisNode->hasEllipsis = ctx->ELLIPSIS() != nullptr;
521
522
1/2
✓ Branch 14 → 15 taken 3996 times.
✗ Branch 14 → 21 not taken.
7992 return concludeNode(typeLstWithEllipsisNode);
523 }
524
525 2260 std::any ASTBuilder::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ctx) {
526 2260 const auto typeAltsLstNode = createNode<TypeAltsLstNode>(ctx);
527
528 // Visit children
529
3/6
✓ Branch 3 → 4 taken 2260 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 2260 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 2260 times.
✗ Branch 6 → 19 not taken.
2260 fetchChildrenIntoVector(typeAltsLstNode->dataTypes, ctx->dataType());
530
531
1/2
✓ Branch 12 → 13 taken 2260 times.
✗ Branch 12 → 19 not taken.
4520 return concludeNode(typeAltsLstNode);
532 }
533
534 27897 std::any ASTBuilder::visitParamLst(SpiceParser::ParamLstContext *ctx) {
535 27897 const auto paramLstNode = createNode<ParamLstNode>(ctx);
536
537 // Visit children
538
2/4
✓ Branch 3 → 4 taken 27897 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 27897 times.
✗ Branch 4 → 30 not taken.
27897 fetchChildrenIntoVector(paramLstNode->params, ctx->declStmt());
539
540 // Set some flags to later detect that the decl statements are parameters
541
2/2
✓ Branch 19 → 8 taken 40620 times.
✓ Branch 19 → 20 taken 27897 times.
96414 for (DeclStmtNode *declStmt : paramLstNode->params) {
542 40620 declStmt->isFctParam = true;
543 40620 declStmt->dataType->isParamType = true;
544 }
545
546
1/2
✓ Branch 26 → 27 taken 27897 times.
✗ Branch 26 → 33 not taken.
55794 return concludeNode(paramLstNode);
547 }
548
549 50317 std::any ASTBuilder::visitArgLst(SpiceParser::ArgLstContext *ctx) {
550 50317 const auto argLstNode = createNode<ArgLstNode>(ctx);
551
552 // Visit children
553
2/4
✓ Branch 3 → 4 taken 50317 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 50317 times.
✗ Branch 4 → 18 not taken.
50317 fetchChildrenIntoVector(argLstNode->args, ctx->assignExpr());
554 50317 argLstNode->argInfos.reserve(argLstNode->args.size());
555
556
1/2
✓ Branch 14 → 15 taken 50317 times.
✗ Branch 14 → 21 not taken.
100634 return concludeNode(argLstNode);
557 }
558
559 611 std::any ASTBuilder::visitEnumItemLst(SpiceParser::EnumItemLstContext *ctx) {
560 611 const auto enumItemLstNode = createNode<EnumItemLstNode>(ctx);
561
562 // Visit children
563
3/6
✓ Branch 3 → 4 taken 611 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 611 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 611 times.
✗ Branch 6 → 19 not taken.
611 fetchChildrenIntoVector(enumItemLstNode->items, ctx->enumItem());
564
565
1/2
✓ Branch 12 → 13 taken 611 times.
✗ Branch 12 → 19 not taken.
1222 return concludeNode(enumItemLstNode);
566 }
567
568 5485 std::any ASTBuilder::visitEnumItem(SpiceParser::EnumItemContext *ctx) {
569 5485 const auto enumItemNode = createNode<EnumItemNode>(ctx);
570
571 // Enrich
572
2/4
✓ Branch 3 → 4 taken 5485 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 5485 times.
✗ Branch 4 → 22 not taken.
5485 enumItemNode->itemName = getIdentifier(ctx->TYPE_IDENTIFIER(), false);
573
2/2
✓ Branch 8 → 9 taken 3094 times.
✓ Branch 8 → 12 taken 2391 times.
5485 if (ctx->ASSIGN()) {
574 3094 enumItemNode->itemValue = parseInt(ctx->INT_LIT());
575 3094 enumItemNode->hasValue = true;
576 }
577
578
1/2
✓ Branch 18 → 19 taken 5485 times.
✗ Branch 18 → 23 not taken.
10970 return concludeNode(enumItemNode);
579 }
580
581 6268 std::any ASTBuilder::visitField(SpiceParser::FieldContext *ctx) {
582 6268 const auto fieldNode = createNode<FieldNode>(ctx);
583
584 // Enrich
585
2/4
✓ Branch 3 → 4 taken 6268 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 6268 times.
✗ Branch 4 → 29 not taken.
6268 fieldNode->fieldName = getIdentifier(ctx->IDENTIFIER(), false);
586
587 // Visit children
588
3/6
✓ Branch 7 → 8 taken 6268 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 6268 times.
✗ Branch 8 → 32 not taken.
✓ Branch 9 → 10 taken 6268 times.
✗ Branch 9 → 30 not taken.
6268 fieldNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
589 6268 fieldNode->dataType->setFieldTypeRecursive();
590
2/2
✓ Branch 13 → 14 taken 1937 times.
✓ Branch 13 → 19 taken 4331 times.
6268 if (ctx->ternaryExpr())
591
3/6
✓ Branch 14 → 15 taken 1937 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 1937 times.
✗ Branch 15 → 35 not taken.
✓ Branch 16 → 17 taken 1937 times.
✗ Branch 16 → 33 not taken.
1937 fieldNode->defaultValue = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr()));
592
593
1/2
✓ Branch 25 → 26 taken 6268 times.
✗ Branch 25 → 36 not taken.
12536 return concludeNode(fieldNode);
594 }
595
596 2440 std::any ASTBuilder::visitSignature(SpiceParser::SignatureContext *ctx) {
597 2440 const auto signatureNode = createNode<SignatureNode>(ctx);
598
599 // Extract method name
600
2/4
✓ Branch 3 → 4 taken 2440 times.
✗ Branch 3 → 73 not taken.
✓ Branch 4 → 5 taken 2440 times.
✗ Branch 4 → 73 not taken.
2440 signatureNode->methodName = getIdentifier(ctx->IDENTIFIER(), false);
601
602 // Visit children
603
2/2
✓ Branch 8 → 9 taken 2393 times.
✓ Branch 8 → 14 taken 47 times.
2440 if (ctx->qualifierLst()) {
604
3/6
✓ Branch 9 → 10 taken 2393 times.
✗ Branch 9 → 76 not taken.
✓ Branch 10 → 11 taken 2393 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 2393 times.
✗ Branch 11 → 74 not taken.
2393 signatureNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
605 }
606
2/2
✓ Branch 15 → 16 taken 2296 times.
✓ Branch 15 → 22 taken 144 times.
2440 if (ctx->F()) {
607 2296 signatureNode->hasReturnType = true;
608 2296 signatureNode->signatureType = SignatureNode::SignatureType::TYPE_FUNCTION;
609 2296 signatureNode->signatureQualifiers = TypeQualifiers::of(TY_FUNCTION);
610
3/6
✓ Branch 17 → 18 taken 2296 times.
✗ Branch 17 → 79 not taken.
✓ Branch 18 → 19 taken 2296 times.
✗ Branch 18 → 79 not taken.
✓ Branch 19 → 20 taken 2296 times.
✗ Branch 19 → 77 not taken.
2296 signatureNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
611 } else {
612 144 signatureNode->signatureType = SignatureNode::SignatureType::TYPE_PROCEDURE;
613 144 signatureNode->signatureQualifiers = TypeQualifiers::of(TY_PROCEDURE);
614 }
615
10/16
✓ Branch 24 → 25 taken 2296 times.
✓ Branch 24 → 28 taken 144 times.
✓ Branch 25 → 26 taken 2296 times.
✗ Branch 25 → 80 not taken.
✓ Branch 28 → 29 taken 144 times.
✗ Branch 28 → 80 not taken.
✓ Branch 31 → 32 taken 144 times.
✓ Branch 31 → 33 taken 2296 times.
✓ Branch 33 → 34 taken 2296 times.
✓ Branch 33 → 35 taken 144 times.
✓ Branch 35 → 36 taken 289 times.
✓ Branch 35 → 41 taken 2151 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
2440 if (ctx->F() ? ctx->LESS().size() == 2 : ctx->LESS().size() == 1) {
616 289 signatureNode->hasTemplateTypes = true;
617
3/6
✓ Branch 36 → 37 taken 289 times.
✗ Branch 36 → 90 not taken.
✓ Branch 37 → 38 taken 289 times.
✗ Branch 37 → 90 not taken.
✓ Branch 38 → 39 taken 289 times.
✗ Branch 38 → 88 not taken.
289 signatureNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0)));
618 }
619
13/20
✓ Branch 41 → 42 taken 2440 times.
✗ Branch 41 → 91 not taken.
✓ Branch 43 → 44 taken 2438 times.
✓ Branch 43 → 48 taken 2 times.
✓ Branch 44 → 45 taken 2438 times.
✗ Branch 44 → 91 not taken.
✓ Branch 46 → 47 taken 1728 times.
✓ Branch 46 → 49 taken 710 times.
✓ Branch 47 → 48 taken 1441 times.
✓ Branch 47 → 49 taken 287 times.
✓ Branch 50 → 51 taken 2438 times.
✓ Branch 50 → 52 taken 2 times.
✓ Branch 52 → 53 taken 2440 times.
✗ Branch 52 → 54 not taken.
✓ Branch 54 → 55 taken 1443 times.
✓ Branch 54 → 63 taken 997 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
2440 if (ctx->typeLst().size() == 2 || (ctx->typeLst().size() == 1 && !signatureNode->hasTemplateTypes)) {
620 1443 signatureNode->hasParams = true;
621
5/8
✓ Branch 55 → 56 taken 2 times.
✓ Branch 55 → 57 taken 1441 times.
✓ Branch 58 → 59 taken 1443 times.
✗ Branch 58 → 101 not taken.
✓ Branch 59 → 60 taken 1443 times.
✗ Branch 59 → 101 not taken.
✓ Branch 60 → 61 taken 1443 times.
✗ Branch 60 → 99 not taken.
1443 signatureNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(signatureNode->hasTemplateTypes ? 1 : 0)));
622 }
623
624
1/2
✓ Branch 69 → 70 taken 2440 times.
✗ Branch 69 → 102 not taken.
4880 return concludeNode(signatureNode);
625 }
626
627 101906 std::any ASTBuilder::visitStmt(SpiceParser::StmtContext *ctx) {
628
2/2
✓ Branch 3 → 4 taken 18989 times.
✓ Branch 3 → 11 taken 82917 times.
101906 if (ctx->declStmt())
629
5/8
✓ Branch 4 → 5 taken 18989 times.
✗ Branch 4 → 60 not taken.
✓ Branch 5 → 6 taken 18985 times.
✓ Branch 5 → 60 taken 4 times.
✓ Branch 6 → 7 taken 18985 times.
✗ Branch 6 → 58 not taken.
✓ Branch 7 → 8 taken 18985 times.
✗ Branch 7 → 58 not taken.
37974 return static_cast<StmtNode *>(std::any_cast<DeclStmtNode *>(visit(ctx->declStmt())));
630
2/2
✓ Branch 12 → 13 taken 48322 times.
✓ Branch 12 → 20 taken 34595 times.
82917 if (ctx->exprStmt())
631
4/8
✓ Branch 13 → 14 taken 48322 times.
✗ Branch 13 → 64 not taken.
✓ Branch 14 → 15 taken 48322 times.
✗ Branch 14 → 64 not taken.
✓ Branch 15 → 16 taken 48322 times.
✗ Branch 15 → 62 not taken.
✓ Branch 16 → 17 taken 48322 times.
✗ Branch 16 → 62 not taken.
96644 return static_cast<StmtNode *>(std::any_cast<ExprStmtNode *>(visit(ctx->exprStmt())));
632
2/2
✓ Branch 21 → 22 taken 33602 times.
✓ Branch 21 → 29 taken 993 times.
34595 if (ctx->returnStmt())
633
4/8
✓ Branch 22 → 23 taken 33602 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 33602 times.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 33602 times.
✗ Branch 24 → 66 not taken.
✓ Branch 25 → 26 taken 33602 times.
✗ Branch 25 → 66 not taken.
67204 return static_cast<StmtNode *>(std::any_cast<ReturnStmtNode *>(visit(ctx->returnStmt())));
634
2/2
✓ Branch 30 → 31 taken 506 times.
✓ Branch 30 → 38 taken 487 times.
993 if (ctx->breakStmt())
635
4/8
✓ Branch 31 → 32 taken 506 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 506 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 506 times.
✗ Branch 33 → 70 not taken.
✓ Branch 34 → 35 taken 506 times.
✗ Branch 34 → 70 not taken.
1012 return static_cast<StmtNode *>(std::any_cast<BreakStmtNode *>(visit(ctx->breakStmt())));
636
2/2
✓ Branch 39 → 40 taken 481 times.
✓ Branch 39 → 47 taken 6 times.
487 if (ctx->continueStmt())
637
4/8
✓ Branch 40 → 41 taken 481 times.
✗ Branch 40 → 76 not taken.
✓ Branch 41 → 42 taken 481 times.
✗ Branch 41 → 76 not taken.
✓ Branch 42 → 43 taken 481 times.
✗ Branch 42 → 74 not taken.
✓ Branch 43 → 44 taken 481 times.
✗ Branch 43 → 74 not taken.
962 return static_cast<StmtNode *>(std::any_cast<ContinueStmtNode *>(visit(ctx->continueStmt())));
638
1/2
✓ Branch 48 → 49 taken 6 times.
✗ Branch 48 → 56 not taken.
6 if (ctx->fallthroughStmt())
639
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.
12 return static_cast<StmtNode *>(std::any_cast<FallthroughStmtNode *>(visit(ctx->fallthroughStmt())));
640 assert_fail("Unknown statement type"); // GCOV_EXCL_LINE
641 return nullptr; // GCOV_EXCL_LINE
642 }
643
644 63079 std::any ASTBuilder::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) {
645 63079 const auto declStmtNode = createNode<DeclStmtNode>(ctx);
646
647 // Enrich
648
3/4
✓ Branch 3 → 4 taken 63079 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 63078 times.
✓ Branch 4 → 28 taken 1 time.
63079 declStmtNode->varName = getIdentifier(ctx->IDENTIFIER(), false);
649
650 // Visit children
651
4/6
✓ Branch 7 → 8 taken 63078 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 63077 times.
✓ Branch 8 → 31 taken 1 time.
✓ Branch 9 → 10 taken 63077 times.
✗ Branch 9 → 29 not taken.
63078 declStmtNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
652
2/2
✓ Branch 12 → 13 taken 23467 times.
✓ Branch 12 → 18 taken 39610 times.
63077 if (ctx->assignExpr()) {
653 23467 declStmtNode->hasAssignment = true;
654
4/6
✓ Branch 13 → 14 taken 23467 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 23465 times.
✓ Branch 14 → 34 taken 2 times.
✓ Branch 15 → 16 taken 23465 times.
✗ Branch 15 → 32 not taken.
23467 declStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
655 }
656
657
1/2
✓ Branch 24 → 25 taken 63075 times.
✗ Branch 24 → 35 not taken.
126150 return concludeNode(declStmtNode);
658 }
659
660 48322 std::any ASTBuilder::visitExprStmt(SpiceParser::ExprStmtContext *ctx) {
661 48322 const auto exprStmtNode = createNode<ExprStmtNode>(ctx);
662
663 // Enrich
664
4/8
✓ Branch 3 → 4 taken 48322 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 48322 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 48322 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 48322 times.
✗ Branch 7 → 20 not taken.
48322 exprStmtNode->expr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
665
666
1/2
✓ Branch 13 → 14 taken 48322 times.
✗ Branch 13 → 20 not taken.
96644 return concludeNode(exprStmtNode);
667 }
668
669 99252 std::any ASTBuilder::visitQualifierLst(SpiceParser::QualifierLstContext *ctx) {
670 99252 const auto qualifierLstNode = createNode<QualifierLstNode>(ctx);
671
672 // Visit children
673
2/4
✓ Branch 3 → 4 taken 99252 times.
✗ Branch 3 → 45 not taken.
✓ Branch 4 → 5 taken 99252 times.
✗ Branch 4 → 43 not taken.
99252 fetchChildrenIntoVector(qualifierLstNode->qualifiers, ctx->qualifier());
674
675 // Check if qualifier combination is invalid
676 99252 bool seenSignedOrUnsigned = false;
677
2/2
✓ Branch 32 → 8 taken 118389 times.
✓ Branch 32 → 33 taken 99251 times.
316892 for (const QualifierNode *qualifier : qualifierLstNode->qualifiers) {
678 // Check if we have both, signed and unsigned qualifier
679
2/2
✓ Branch 10 → 11 taken 118382 times.
✓ Branch 10 → 13 taken 7 times.
118389 if (qualifier->type != QualifierNode::QualifierType::TY_SIGNED &&
680
2/2
✓ Branch 11 → 12 taken 93639 times.
✓ Branch 11 → 13 taken 24743 times.
118382 qualifier->type != QualifierNode::QualifierType::TY_UNSIGNED)
681 93639 continue;
682
2/2
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 22 taken 24749 times.
24750 if (seenSignedOrUnsigned)
683
2/4
✓ Branch 17 → 18 taken 1 time.
✗ Branch 17 → 49 not taken.
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 46 not taken.
3 throw ParserError(qualifier->codeLoc, INVALID_QUALIFIER_COMBINATION, "A variable can not be signed and unsigned");
684 24749 seenSignedOrUnsigned = true;
685 }
686
687
1/2
✓ Branch 39 → 40 taken 99251 times.
✗ Branch 39 → 56 not taken.
198502 return concludeNode(qualifierLstNode);
688 }
689
690 118389 std::any ASTBuilder::visitQualifier(SpiceParser::QualifierContext *ctx) {
691 118389 const auto qualifierNode = createNode<QualifierNode>(ctx);
692
693
3/4
✓ Branch 7 → 8 taken 118389 times.
✗ Branch 7 → 9 not taken.
✓ Branch 42 → 5 taken 118389 times.
✓ Branch 42 → 43 taken 118389 times.
473556 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
694 118389 const auto token = spice_pointer_cast<TerminalNode *>(subTree);
695
2/4
✓ Branch 16 → 17 taken 118389 times.
✗ Branch 16 → 53 not taken.
✓ Branch 17 → 18 taken 118389 times.
✗ Branch 17 → 53 not taken.
118389 const size_t symbolType = token->getSymbol()->getType();
696
2/2
✓ Branch 18 → 19 taken 25909 times.
✓ Branch 18 → 20 taken 92480 times.
118389 if (symbolType == SpiceParser::CONST)
697 25909 qualifierNode->type = QualifierNode::QualifierType::TY_CONST;
698
2/2
✓ Branch 20 → 21 taken 7 times.
✓ Branch 20 → 22 taken 92473 times.
92480 else if (symbolType == SpiceParser::SIGNED)
699 7 qualifierNode->type = QualifierNode::QualifierType::TY_SIGNED;
700
2/2
✓ Branch 22 → 23 taken 24743 times.
✓ Branch 22 → 24 taken 67730 times.
92473 else if (symbolType == SpiceParser::UNSIGNED)
701 24743 qualifierNode->type = QualifierNode::QualifierType::TY_UNSIGNED;
702
2/2
✓ Branch 24 → 25 taken 8901 times.
✓ Branch 24 → 26 taken 58829 times.
67730 else if (symbolType == SpiceParser::INLINE)
703 8901 qualifierNode->type = QualifierNode::QualifierType::TY_INLINE;
704
2/2
✓ Branch 26 → 27 taken 44099 times.
✓ Branch 26 → 28 taken 14730 times.
58829 else if (symbolType == SpiceParser::PUBLIC)
705 44099 qualifierNode->type = QualifierNode::QualifierType::TY_PUBLIC;
706
2/2
✓ Branch 28 → 29 taken 13472 times.
✓ Branch 28 → 30 taken 1258 times.
14730 else if (symbolType == SpiceParser::HEAP)
707 13472 qualifierNode->type = QualifierNode::QualifierType::TY_HEAP;
708
1/2
✓ Branch 30 → 31 taken 1258 times.
✗ Branch 30 → 32 not taken.
1258 else if (symbolType == SpiceParser::COMPOSE)
709 1258 qualifierNode->type = QualifierNode::QualifierType::TY_COMPOSITION;
710 else
711 assert_fail("Unknown qualifier type"); // GCOV_EXCL_LINE
712 }
713
714
1/2
✓ Branch 49 → 50 taken 118389 times.
✗ Branch 49 → 54 not taken.
236778 return concludeNode(qualifierNode);
715 }
716
717 836 std::any ASTBuilder::visitModAttr(SpiceParser::ModAttrContext *ctx) {
718 836 const auto modAttrNode = createNode<ModAttrNode>(ctx);
719
720 // Visit children
721
4/6
✓ Branch 3 → 4 taken 836 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 835 times.
✓ Branch 4 → 33 taken 1 time.
✓ Branch 5 → 6 taken 835 times.
✗ Branch 5 → 31 not taken.
836 modAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
722
723 // Tell the attributes that they are module attributes
724
2/2
✓ Branch 20 → 9 taken 2469 times.
✓ Branch 20 → 21 taken 835 times.
4139 for (AttrNode *attr : modAttrNode->attrLst->attributes)
725 2469 attr->target = AttrNode::TARGET_MODULE;
726
727
1/2
✓ Branch 27 → 28 taken 835 times.
✗ Branch 27 → 34 not taken.
1670 return concludeNode(modAttrNode);
728 }
729
730 1102 std::any ASTBuilder::visitTopLevelDefAttr(SpiceParser::TopLevelDefAttrContext *ctx) {
731 1102 const auto fctAttrNode = createNode<TopLevelDefAttrNode>(ctx);
732
733 // Visit children
734
4/8
✓ Branch 3 → 4 taken 1102 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 1102 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 1102 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 1102 times.
✗ Branch 7 → 20 not taken.
1102 fctAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
735
736
1/2
✓ Branch 13 → 14 taken 1102 times.
✗ Branch 13 → 20 not taken.
2204 return concludeNode(fctAttrNode);
737 }
738
739 8 std::any ASTBuilder::visitLambdaAttr(SpiceParser::LambdaAttrContext *ctx) {
740 8 const auto lambdaAttrNode = createNode<LambdaAttrNode>(ctx);
741
742 // Visit children
743
3/6
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 33 not taken.
✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 31 not taken.
8 lambdaAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
744
745 // Tell the attributes that they are module attributes
746
2/2
✓ Branch 20 → 9 taken 8 times.
✓ Branch 20 → 21 taken 8 times.
24 for (AttrNode *attr : lambdaAttrNode->attrLst->attributes)
747 8 attr->target = AttrNode::TARGET_LAMBDA;
748
749
1/2
✓ Branch 27 → 28 taken 8 times.
✗ Branch 27 → 34 not taken.
16 return concludeNode(lambdaAttrNode);
750 }
751
752 1946 std::any ASTBuilder::visitAttrLst(SpiceParser::AttrLstContext *ctx) {
753 1946 const auto attrLstNode = createNode<AttrLstNode>(ctx);
754
755 // Visit children
756
4/6
✓ Branch 3 → 4 taken 1946 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 1945 times.
✓ Branch 4 → 16 taken 1 time.
✓ Branch 6 → 7 taken 1945 times.
✗ Branch 6 → 19 not taken.
1947 fetchChildrenIntoVector(attrLstNode->attributes, ctx->attr());
757
758
1/2
✓ Branch 12 → 13 taken 1945 times.
✗ Branch 12 → 19 not taken.
3890 return concludeNode(attrLstNode);
759 }
760
761 3682 std::any ASTBuilder::visitAttr(SpiceParser::AttrContext *ctx) {
762
1/2
✓ Branch 2 → 3 taken 3682 times.
✗ Branch 2 → 83 not taken.
3682 const auto attrNode = createNode<AttrNode>(ctx);
763
764 // Extract key
765
1/2
✓ Branch 3 → 4 taken 3682 times.
✗ Branch 3 → 83 not taken.
3682 std::stringstream key;
766
3/4
✓ Branch 12 → 13 taken 13281 times.
✗ Branch 12 → 66 not taken.
✓ Branch 15 → 5 taken 9599 times.
✓ Branch 15 → 16 taken 3682 times.
13281 for (size_t i = 0; i < ctx->IDENTIFIER().size(); i++) {
767
2/2
✓ Branch 5 → 6 taken 5917 times.
✓ Branch 5 → 7 taken 3682 times.
9599 if (i > 0)
768
1/2
✓ Branch 6 → 7 taken 5917 times.
✗ Branch 6 → 81 not taken.
5917 key << MEMBER_ACCESS_TOKEN;
769
3/6
✓ Branch 7 → 8 taken 9599 times.
✗ Branch 7 → 65 not taken.
✓ Branch 8 → 9 taken 9599 times.
✗ Branch 8 → 65 not taken.
✓ Branch 9 → 10 taken 9599 times.
✗ Branch 9 → 63 not taken.
9599 key << ctx->IDENTIFIER(i)->getText();
770 }
771
1/2
✓ Branch 16 → 17 taken 3682 times.
✗ Branch 16 → 67 not taken.
3682 attrNode->key = key.str();
772
773 // Visit children
774
3/4
✓ Branch 19 → 20 taken 3682 times.
✗ Branch 19 → 81 not taken.
✓ Branch 20 → 21 taken 2874 times.
✓ Branch 20 → 51 taken 808 times.
3682 if (ctx->constant()) {
775
3/6
✓ Branch 21 → 22 taken 2874 times.
✗ Branch 21 → 70 not taken.
✓ Branch 22 → 23 taken 2874 times.
✗ Branch 22 → 70 not taken.
✓ Branch 23 → 24 taken 2874 times.
✗ Branch 23 → 68 not taken.
2874 attrNode->value = std::any_cast<ConstantNode *>(visit(ctx->constant()));
776
777
4/6
✓ Branch 25 → 26 taken 2874 times.
✗ Branch 25 → 81 not taken.
✓ Branch 26 → 27 taken 2874 times.
✗ Branch 26 → 81 not taken.
✓ Branch 27 → 28 taken 1756 times.
✓ Branch 27 → 29 taken 1118 times.
2874 if (ctx->constant()->STRING_LIT())
778 1756 attrNode->type = AttrNode::AttrType::TYPE_STRING;
779
4/6
✓ Branch 29 → 30 taken 1118 times.
✗ Branch 29 → 81 not taken.
✓ Branch 30 → 31 taken 1118 times.
✗ Branch 30 → 81 not taken.
✓ Branch 31 → 32 taken 188 times.
✓ Branch 31 → 33 taken 930 times.
1118 else if (ctx->constant()->INT_LIT())
780 188 attrNode->type = AttrNode::AttrType::TYPE_INT;
781
10/14
✓ Branch 33 → 34 taken 930 times.
✗ Branch 33 → 81 not taken.
✓ Branch 34 → 35 taken 930 times.
✗ Branch 34 → 81 not taken.
✓ Branch 35 → 36 taken 5 times.
✓ Branch 35 → 39 taken 925 times.
✓ Branch 36 → 37 taken 5 times.
✗ Branch 36 → 81 not taken.
✓ Branch 37 → 38 taken 5 times.
✗ Branch 37 → 81 not taken.
✓ Branch 38 → 39 taken 4 times.
✓ Branch 38 → 40 taken 1 time.
✓ Branch 41 → 42 taken 929 times.
✓ Branch 41 → 43 taken 1 time.
930 else if (ctx->constant()->TRUE() || ctx->constant()->FALSE())
782 929 attrNode->type = AttrNode::AttrType::TYPE_BOOL;
783 else
784
2/4
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 74 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 71 not taken.
3 throw ParserError(attrNode->value->codeLoc, INVALID_ATTR_VALUE_TYPE, "Invalid attribute value type");
785 } else {
786 // If no value is given, use the bool type
787 808 attrNode->type = AttrNode::AttrType::TYPE_BOOL;
788 }
789
790
1/2
✓ Branch 58 → 59 taken 3681 times.
✗ Branch 58 → 80 not taken.
7362 return concludeNode(attrNode);
791 3682 }
792
793 953 std::any ASTBuilder::visitCaseConstant(SpiceParser::CaseConstantContext *ctx) {
794 953 const auto caseConstantNode = createNode<CaseConstantNode>(ctx);
795
796 // Visit children
797
2/2
✓ Branch 4 → 5 taken 64 times.
✓ Branch 4 → 10 taken 889 times.
953 if (ctx->constant()) {
798
3/6
✓ Branch 5 → 6 taken 64 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 64 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 64 times.
✗ Branch 7 → 63 not taken.
64 caseConstantNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
799
2/4
✓ Branch 10 → 11 taken 889 times.
✗ Branch 10 → 66 not taken.
✓ Branch 13 → 14 taken 889 times.
✗ Branch 13 → 52 not taken.
889 } else if (!ctx->TYPE_IDENTIFIER().empty()) {
800
1/2
✓ Branch 14 → 15 taken 889 times.
✗ Branch 14 → 75 not taken.
889 std::stringstream fqIdentifier;
801
2/2
✓ Branch 46 → 17 taken 2413 times.
✓ Branch 46 → 47 taken 889 times.
4191 for (antlr4::tree::ParseTree *parseTree : ctx->children) {
802
1/2
✓ Branch 19 → 20 taken 2413 times.
✗ Branch 19 → 21 not taken.
2413 const auto terminal = dynamic_cast<TerminalNode *>(parseTree);
803
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 2413 times.
2413 if (!terminal)
804 continue;
805
806
2/4
✓ Branch 24 → 25 taken 2413 times.
✗ Branch 24 → 71 not taken.
✓ Branch 25 → 26 taken 2413 times.
✗ Branch 25 → 71 not taken.
2413 const size_t terminalType = terminal->getSymbol()->getType();
807
3/4
✓ Branch 26 → 27 taken 2413 times.
✗ Branch 26 → 28 not taken.
✓ Branch 27 → 28 taken 1651 times.
✓ Branch 27 → 37 taken 762 times.
2413 if (terminalType == SpiceParser::IDENTIFIER || terminalType == SpiceParser::TYPE_IDENTIFIER) {
808
1/2
✓ Branch 28 → 29 taken 1651 times.
✗ Branch 28 → 70 not taken.
1651 const std::string fragment = getIdentifier(terminal, false);
809
1/2
✓ Branch 29 → 30 taken 1651 times.
✗ Branch 29 → 68 not taken.
1651 caseConstantNode->identifierFragments.push_back(fragment);
810
3/4
✓ Branch 30 → 31 taken 1651 times.
✗ Branch 30 → 67 not taken.
✓ Branch 32 → 33 taken 762 times.
✓ Branch 32 → 34 taken 889 times.
1651 if (fqIdentifier.tellp() != 0)
811
1/2
✓ Branch 33 → 34 taken 762 times.
✗ Branch 33 → 68 not taken.
762 fqIdentifier << SCOPE_ACCESS_TOKEN;
812
1/2
✓ Branch 34 → 35 taken 1651 times.
✗ Branch 34 → 68 not taken.
1651 fqIdentifier << fragment;
813 1651 }
814 }
815
1/2
✓ Branch 47 → 48 taken 889 times.
✗ Branch 47 → 72 not taken.
889 caseConstantNode->fqIdentifier = fqIdentifier.str();
816 889 } else {
817 assert_fail("Unknown case constant type"); // GCOV_EXCL_LINE
818 }
819
820
1/2
✓ Branch 59 → 60 taken 953 times.
✗ Branch 59 → 76 not taken.
1906 return concludeNode(caseConstantNode);
821 }
822
823 33602 std::any ASTBuilder::visitReturnStmt(SpiceParser::ReturnStmtContext *ctx) {
824 33602 const auto returnStmtNode = createNode<ReturnStmtNode>(ctx);
825
826 // Visit children
827
2/2
✓ Branch 4 → 5 taken 30416 times.
✓ Branch 4 → 10 taken 3186 times.
33602 if (ctx->assignExpr()) {
828 30416 returnStmtNode->hasReturnValue = true;
829
3/6
✓ Branch 5 → 6 taken 30416 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 30416 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 30416 times.
✗ Branch 7 → 20 not taken.
30416 returnStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
830 }
831
832
1/2
✓ Branch 16 → 17 taken 33602 times.
✗ Branch 16 → 23 not taken.
67204 return concludeNode(returnStmtNode);
833 }
834
835 506 std::any ASTBuilder::visitBreakStmt(SpiceParser::BreakStmtContext *ctx) {
836 506 const auto breakStmtNode = createNode<BreakStmtNode>(ctx);
837
838 // Extract number of breaks
839
2/2
✓ Branch 4 → 5 taken 7 times.
✓ Branch 4 → 10 taken 499 times.
506 if (ctx->INT_LIT())
840
3/6
✓ Branch 5 → 6 taken 7 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 7 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 7 times.
✗ Branch 7 → 22 not taken.
7 breakStmtNode->breakTimes = std::stoi(ctx->INT_LIT()->toString());
841
842 // Visit children
843
2/4
✓ Branch 10 → 11 taken 506 times.
✗ Branch 10 → 25 not taken.
✓ Branch 12 → 13 taken 506 times.
✗ Branch 12 → 26 not taken.
506 visitChildren(ctx);
844
845
1/2
✓ Branch 18 → 19 taken 506 times.
✗ Branch 18 → 26 not taken.
1012 return concludeNode(breakStmtNode);
846 }
847
848 481 std::any ASTBuilder::visitContinueStmt(SpiceParser::ContinueStmtContext *ctx) {
849 481 const auto continueStmtNode = createNode<ContinueStmtNode>(ctx);
850
851 // Extract number of continues
852
2/2
✓ Branch 4 → 5 taken 386 times.
✓ Branch 4 → 10 taken 95 times.
481 if (ctx->INT_LIT())
853
3/6
✓ Branch 5 → 6 taken 386 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 386 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 386 times.
✗ Branch 7 → 22 not taken.
386 continueStmtNode->continueTimes = std::stoi(ctx->INT_LIT()->toString());
854
855 // Visit children
856
2/4
✓ Branch 10 → 11 taken 481 times.
✗ Branch 10 → 25 not taken.
✓ Branch 12 → 13 taken 481 times.
✗ Branch 12 → 26 not taken.
481 visitChildren(ctx);
857
858
1/2
✓ Branch 18 → 19 taken 481 times.
✗ Branch 18 → 26 not taken.
962 return concludeNode(continueStmtNode);
859 }
860
861 6 std::any ASTBuilder::visitFallthroughStmt(SpiceParser::FallthroughStmtContext *ctx) {
862 6 const auto fallthroughStmtNode = createNode<FallthroughStmtNode>(ctx);
863
864 // Visit children
865
2/4
✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 15 not taken.
✓ Branch 5 → 6 taken 6 times.
✗ Branch 5 → 16 not taken.
6 visitChildren(ctx);
866
867
1/2
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 16 not taken.
12 return concludeNode(fallthroughStmtNode);
868 }
869
870 4158 std::any ASTBuilder::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) {
871
1/2
✓ Branch 2 → 3 taken 4158 times.
✗ Branch 2 → 30 not taken.
4158 const auto assertStmtNode = createNode<AssertStmtNode>(ctx);
872
873 // Enrich
874
5/10
✓ Branch 3 → 4 taken 4158 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 4158 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 4158 times.
✗ Branch 5 → 30 not taken.
✓ Branch 6 → 7 taken 4158 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 4158 times.
✗ Branch 7 → 30 not taken.
4158 const antlr4::misc::Interval interval(ctx->assignExpr()->start->getStartIndex(), ctx->assignExpr()->stop->getStopIndex());
875
1/2
✓ Branch 8 → 9 taken 4158 times.
✗ Branch 8 → 25 not taken.
4158 assertStmtNode->expressionString = inputStream->getText(interval);
876
877 // Visit children
878
4/8
✓ Branch 11 → 12 taken 4158 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 13 taken 4158 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 4158 times.
✗ Branch 13 → 26 not taken.
✓ Branch 15 → 16 taken 4158 times.
✗ Branch 15 → 29 not taken.
4158 assertStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
879
880
1/2
✓ Branch 21 → 22 taken 4158 times.
✗ Branch 21 → 29 not taken.
8316 return concludeNode(assertStmtNode);
881 }
882
883 254662 std::any ASTBuilder::visitAssignExpr(SpiceParser::AssignExprContext *ctx) {
884
2/2
✓ Branch 3 → 4 taken 230330 times.
✓ Branch 3 → 6 taken 24332 times.
254662 if (!ctx->assignOp())
885 230330 return visit(ctx->ternaryExpr());
886
887 24332 const auto assignExprNode = createNode<AssignExprNode>(ctx);
888
889 // Visit children
890
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 24332 times.
24332 if (ctx->ternaryExpr()) {
891 assignExprNode->ternaryExpr = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr()));
892
1/2
✓ Branch 15 → 16 taken 24332 times.
✗ Branch 15 → 28 not taken.
24332 } else if (ctx->prefixUnaryExpr()) {
893
3/6
✓ Branch 16 → 17 taken 24332 times.
✗ Branch 16 → 44 not taken.
✓ Branch 17 → 18 taken 24332 times.
✗ Branch 17 → 44 not taken.
✓ Branch 18 → 19 taken 24332 times.
✗ Branch 18 → 42 not taken.
24332 assignExprNode->lhs = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr()));
894
2/4
✓ Branch 20 → 21 taken 24332 times.
✗ Branch 20 → 45 not taken.
✓ Branch 21 → 22 taken 24332 times.
✗ Branch 21 → 45 not taken.
24332 visit(ctx->assignOp());
895
3/6
✓ Branch 23 → 24 taken 24332 times.
✗ Branch 23 → 48 not taken.
✓ Branch 24 → 25 taken 24332 times.
✗ Branch 24 → 48 not taken.
✓ Branch 25 → 26 taken 24332 times.
✗ Branch 25 → 46 not taken.
24332 assignExprNode->rhs = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
896 } else {
897 assert_fail("Invalid assign expression"); // GCOV_EXCL_LINE
898 }
899
900
1/2
✓ Branch 35 → 36 taken 24332 times.
✗ Branch 35 → 49 not taken.
48664 return concludeExprNode(assignExprNode);
901 }
902
903 232267 std::any ASTBuilder::visitTernaryExpr(SpiceParser::TernaryExprContext *ctx) {
904
3/4
✓ Branch 2 → 3 taken 232267 times.
✗ Branch 2 → 45 not taken.
✓ Branch 5 → 6 taken 230251 times.
✓ Branch 5 → 8 taken 2016 times.
232267 if (ctx->logicalOrExpr().size() == 1)
905 230251 return visit(ctx->logicalOrExpr(0));
906
907 2016 const auto ternaryExprNode = createNode<TernaryExprNode>(ctx);
908
909
3/6
✓ Branch 9 → 10 taken 2016 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 2016 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 2016 times.
✗ Branch 11 → 46 not taken.
2016 ternaryExprNode->condition = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(0)));
910
3/4
✓ Branch 13 → 14 taken 2016 times.
✗ Branch 13 → 49 not taken.
✓ Branch 16 → 17 taken 2015 times.
✓ Branch 16 → 26 taken 1 time.
2016 if (ctx->logicalOrExpr().size() == 3) {
911
3/6
✓ Branch 17 → 18 taken 2015 times.
✗ Branch 17 → 52 not taken.
✓ Branch 18 → 19 taken 2015 times.
✗ Branch 18 → 52 not taken.
✓ Branch 19 → 20 taken 2015 times.
✗ Branch 19 → 50 not taken.
2015 ternaryExprNode->trueExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(1)));
912
3/6
✓ Branch 21 → 22 taken 2015 times.
✗ Branch 21 → 55 not taken.
✓ Branch 22 → 23 taken 2015 times.
✗ Branch 22 → 55 not taken.
✓ Branch 23 → 24 taken 2015 times.
✗ Branch 23 → 53 not taken.
2015 ternaryExprNode->falseExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(2)));
913
2/4
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 56 not taken.
✓ Branch 29 → 30 taken 1 time.
✗ Branch 29 → 35 not taken.
1 } else if (ctx->logicalOrExpr().size() == 2) {
914 1 ternaryExprNode->isShortened = true;
915
3/6
✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 59 not taken.
✓ Branch 31 → 32 taken 1 time.
✗ Branch 31 → 59 not taken.
✓ Branch 32 → 33 taken 1 time.
✗ Branch 32 → 57 not taken.
1 ternaryExprNode->falseExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(1)));
916 }
917
918
1/2
✓ Branch 41 → 42 taken 2016 times.
✗ Branch 41 → 60 not taken.
4032 return concludeExprNode(ternaryExprNode);
919 }
920
921 236298 std::any ASTBuilder::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext *ctx) {
922
3/4
✓ Branch 2 → 3 taken 236298 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 233387 times.
✓ Branch 5 → 8 taken 2911 times.
236298 if (ctx->logicalAndExpr().size() == 1)
923 233387 return visit(ctx->logicalAndExpr(0));
924
925 2911 const auto logicalOrExprNode = createNode<LogicalOrExprNode>(ctx);
926
927 // Visit children
928
3/6
✓ Branch 9 → 10 taken 2911 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 2911 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 2911 times.
✗ Branch 12 → 26 not taken.
2911 fetchChildrenIntoVector(logicalOrExprNode->operands, ctx->logicalAndExpr());
929
930
1/2
✓ Branch 18 → 19 taken 2911 times.
✗ Branch 18 → 26 not taken.
5822 return concludeExprNode(logicalOrExprNode);
931 }
932
933 240084 std::any ASTBuilder::visitLogicalAndExpr(SpiceParser::LogicalAndExprContext *ctx) {
934
3/4
✓ Branch 2 → 3 taken 240084 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 238552 times.
✓ Branch 5 → 8 taken 1532 times.
240084 if (ctx->bitwiseOrExpr().size() == 1)
935 238552 return visit(ctx->bitwiseOrExpr(0));
936
937 1532 const auto logicalAndExprNode = createNode<LogicalAndExprNode>(ctx);
938
939 // Visit children
940
3/6
✓ Branch 9 → 10 taken 1532 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 1532 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 1532 times.
✗ Branch 12 → 26 not taken.
1532 fetchChildrenIntoVector(logicalAndExprNode->operands, ctx->bitwiseOrExpr());
941
942
1/2
✓ Branch 18 → 19 taken 1532 times.
✗ Branch 18 → 26 not taken.
3064 return concludeExprNode(logicalAndExprNode);
943 }
944
945 242058 std::any ASTBuilder::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext *ctx) {
946
3/4
✓ Branch 2 → 3 taken 242058 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 241675 times.
✓ Branch 5 → 8 taken 383 times.
242058 if (ctx->bitwiseXorExpr().size() == 1)
947 241675 return visit(ctx->bitwiseXorExpr(0));
948
949 383 const auto bitwiseOrExprNode = createNode<BitwiseOrExprNode>(ctx);
950
951 // Visit children
952
3/6
✓ Branch 9 → 10 taken 383 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 383 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 383 times.
✗ Branch 12 → 26 not taken.
383 fetchChildrenIntoVector(bitwiseOrExprNode->operands, ctx->bitwiseXorExpr());
953
954
1/2
✓ Branch 18 → 19 taken 383 times.
✗ Branch 18 → 26 not taken.
766 return concludeExprNode(bitwiseOrExprNode);
955 }
956
957 242442 std::any ASTBuilder::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprContext *ctx) {
958
3/4
✓ Branch 2 → 3 taken 242442 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 242372 times.
✓ Branch 5 → 8 taken 70 times.
242442 if (ctx->bitwiseAndExpr().size() == 1)
959 242372 return visit(ctx->bitwiseAndExpr(0));
960
961 70 const auto bitwiseXorExprNode = createNode<BitwiseXorExprNode>(ctx);
962
963 // Visit children
964
3/6
✓ Branch 9 → 10 taken 70 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 70 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 70 times.
✗ Branch 12 → 26 not taken.
70 fetchChildrenIntoVector(bitwiseXorExprNode->operands, ctx->bitwiseAndExpr());
965
966
1/2
✓ Branch 18 → 19 taken 70 times.
✗ Branch 18 → 26 not taken.
140 return concludeExprNode(bitwiseXorExprNode);
967 }
968
969 242513 std::any ASTBuilder::visitBitwiseAndExpr(SpiceParser::BitwiseAndExprContext *ctx) {
970
3/4
✓ Branch 2 → 3 taken 242513 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 242263 times.
✓ Branch 5 → 8 taken 250 times.
242513 if (ctx->equalityExpr().size() == 1)
971 242263 return visit(ctx->equalityExpr(0));
972
973 250 const auto bitwiseAndExprNode = createNode<BitwiseAndExprNode>(ctx);
974
975 // Visit children
976
3/6
✓ Branch 9 → 10 taken 250 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 250 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 250 times.
✗ Branch 12 → 26 not taken.
250 fetchChildrenIntoVector(bitwiseAndExprNode->operands, ctx->equalityExpr());
977
978
1/2
✓ Branch 18 → 19 taken 250 times.
✗ Branch 18 → 26 not taken.
500 return concludeExprNode(bitwiseAndExprNode);
979 }
980
981 242764 std::any ASTBuilder::visitEqualityExpr(SpiceParser::EqualityExprContext *ctx) {
982
3/4
✓ Branch 2 → 3 taken 242764 times.
✗ Branch 2 → 28 not taken.
✓ Branch 5 → 6 taken 221785 times.
✓ Branch 5 → 8 taken 20979 times.
242764 if (ctx->relationalExpr().size() == 1)
983 221785 return visit(ctx->relationalExpr(0));
984
985 20979 const auto equalityExprNode = createNode<EqualityExprNode>(ctx);
986
987 // Visit children
988
2/4
✓ Branch 9 → 10 taken 20979 times.
✗ Branch 9 → 31 not taken.
✓ Branch 10 → 11 taken 20979 times.
✗ Branch 10 → 29 not taken.
20979 fetchChildrenIntoVector(equalityExprNode->operands, ctx->relationalExpr());
989
990 // Extract operator
991
2/2
✓ Branch 13 → 14 taken 17900 times.
✓ Branch 13 → 15 taken 3079 times.
20979 if (ctx->EQUAL())
992 17900 equalityExprNode->op = EqualityExprNode::EqualityOp::OP_EQUAL;
993
1/2
✓ Branch 16 → 17 taken 3079 times.
✗ Branch 16 → 18 not taken.
3079 else if (ctx->NOT_EQUAL())
994 3079 equalityExprNode->op = EqualityExprNode::EqualityOp::OP_NOT_EQUAL;
995
996
1/2
✓ Branch 24 → 25 taken 20979 times.
✗ Branch 24 → 32 not taken.
41958 return concludeExprNode(equalityExprNode);
997 }
998
999 263743 std::any ASTBuilder::visitRelationalExpr(SpiceParser::RelationalExprContext *ctx) {
1000
3/4
✓ Branch 2 → 3 taken 263743 times.
✗ Branch 2 → 34 not taken.
✓ Branch 5 → 6 taken 253007 times.
✓ Branch 5 → 8 taken 10736 times.
263743 if (ctx->shiftExpr().size() == 1)
1001 253007 return visit(ctx->shiftExpr(0));
1002
1003 10736 const auto relationalExprNode = createNode<RelationalExprNode>(ctx);
1004
1005 // Visit children
1006
2/4
✓ Branch 9 → 10 taken 10736 times.
✗ Branch 9 → 37 not taken.
✓ Branch 10 → 11 taken 10736 times.
✗ Branch 10 → 35 not taken.
10736 fetchChildrenIntoVector(relationalExprNode->operands, ctx->shiftExpr());
1007
1008 // Extract operator
1009
2/2
✓ Branch 13 → 14 taken 4658 times.
✓ Branch 13 → 15 taken 6078 times.
10736 if (ctx->LESS())
1010 4658 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS;
1011
2/2
✓ Branch 16 → 17 taken 2500 times.
✓ Branch 16 → 18 taken 3578 times.
6078 else if (ctx->GREATER())
1012 2500 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER;
1013
2/2
✓ Branch 19 → 20 taken 1185 times.
✓ Branch 19 → 21 taken 2393 times.
3578 else if (ctx->LESS_EQUAL())
1014 1185 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS_EQUAL;
1015
1/2
✓ Branch 22 → 23 taken 2393 times.
✗ Branch 22 → 24 not taken.
2393 else if (ctx->GREATER_EQUAL())
1016 2393 relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER_EQUAL;
1017
1018
1/2
✓ Branch 30 → 31 taken 10736 times.
✗ Branch 30 → 38 not taken.
21472 return concludeExprNode(relationalExprNode);
1019 }
1020
1021 274479 std::any ASTBuilder::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) {
1022
3/4
✓ Branch 2 → 3 taken 274479 times.
✗ Branch 2 → 60 not taken.
✓ Branch 5 → 6 taken 273494 times.
✓ Branch 5 → 8 taken 985 times.
274479 if (ctx->additiveExpr().size() == 1)
1023 273494 return visit(ctx->additiveExpr(0));
1024
1025 985 const auto shiftExprNode = createNode<ShiftExprNode>(ctx);
1026
1027 // Visit children
1028
2/4
✓ Branch 9 → 10 taken 985 times.
✗ Branch 9 → 63 not taken.
✓ Branch 10 → 11 taken 985 times.
✗ Branch 10 → 61 not taken.
985 fetchChildrenIntoVector(shiftExprNode->operands, ctx->additiveExpr());
1029
1030 985 bool seenFirstLess = false;
1031 985 bool seenFirstGreater = false;
1032
2/2
✓ Branch 45 → 14 taken 4690 times.
✓ Branch 45 → 46 taken 985 times.
6660 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1033
1/2
✓ Branch 16 → 17 taken 4690 times.
✗ Branch 16 → 18 not taken.
4690 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1034
2/2
✓ Branch 19 → 20 taken 2220 times.
✓ Branch 19 → 21 taken 2470 times.
4690 if (!terminal)
1035 2220 continue;
1036
1037
4/6
✓ Branch 21 → 22 taken 2470 times.
✗ Branch 21 → 68 not taken.
✓ Branch 22 → 23 taken 2470 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 1806 times.
✓ Branch 23 → 28 taken 664 times.
2470 if (terminal->getSymbol()->getType() == SpiceParser::LESS) {
1038
2/2
✓ Branch 24 → 25 taken 903 times.
✓ Branch 24 → 27 taken 903 times.
1806 if (seenFirstLess)
1039
1/2
✓ Branch 25 → 26 taken 903 times.
✗ Branch 25 → 64 not taken.
903 shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_LEFT, TY_INVALID);
1040 1806 seenFirstLess = !seenFirstLess;
1041 1806 continue;
1042 }
1043
1044
3/6
✓ Branch 28 → 29 taken 664 times.
✗ Branch 28 → 68 not taken.
✓ Branch 29 → 30 taken 664 times.
✗ Branch 29 → 68 not taken.
✓ Branch 30 → 31 taken 664 times.
✗ Branch 30 → 35 not taken.
664 if (terminal->getSymbol()->getType() == SpiceParser::GREATER) {
1045
2/2
✓ Branch 31 → 32 taken 332 times.
✓ Branch 31 → 34 taken 332 times.
664 if (seenFirstGreater)
1046
1/2
✓ Branch 32 → 33 taken 332 times.
✗ Branch 32 → 66 not taken.
332 shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT, TY_INVALID);
1047 664 seenFirstGreater = !seenFirstGreater;
1048 664 continue;
1049 }
1050
1051 assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE
1052 }
1053
2/4
✓ Branch 46 → 47 taken 985 times.
✗ Branch 46 → 49 not taken.
✓ Branch 47 → 48 taken 985 times.
✗ Branch 47 → 49 not taken.
985 assert(!seenFirstLess && !seenFirstGreater);
1054
1055
1/2
✓ Branch 56 → 57 taken 985 times.
✗ Branch 56 → 69 not taken.
1970 return concludeExprNode(shiftExprNode);
1056 }
1057
1058 275714 std::any ASTBuilder::visitAdditiveExpr(SpiceParser::AdditiveExprContext *ctx) {
1059
3/4
✓ Branch 2 → 3 taken 275714 times.
✗ Branch 2 → 52 not taken.
✓ Branch 5 → 6 taken 264938 times.
✓ Branch 5 → 8 taken 10776 times.
275714 if (ctx->multiplicativeExpr().size() == 1)
1060 264938 return visit(ctx->multiplicativeExpr(0));
1061
1062 10776 const auto additiveExprNode = createNode<AdditiveExprNode>(ctx);
1063
1064 // Visit children
1065
2/4
✓ Branch 9 → 10 taken 10776 times.
✗ Branch 9 → 55 not taken.
✓ Branch 10 → 11 taken 10776 times.
✗ Branch 10 → 53 not taken.
10776 fetchChildrenIntoVector(additiveExprNode->operands, ctx->multiplicativeExpr());
1066
1067
2/2
✓ Branch 41 → 14 taken 34912 times.
✓ Branch 41 → 42 taken 10776 times.
56464 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1068
1/2
✓ Branch 16 → 17 taken 34912 times.
✗ Branch 16 → 18 not taken.
34912 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1069
2/2
✓ Branch 19 → 20 taken 22844 times.
✓ Branch 19 → 21 taken 12068 times.
34912 if (!terminal)
1070 22844 continue;
1071
1072
4/6
✓ Branch 21 → 22 taken 12068 times.
✗ Branch 21 → 60 not taken.
✓ Branch 22 → 23 taken 12068 times.
✗ Branch 22 → 60 not taken.
✓ Branch 23 → 24 taken 8124 times.
✓ Branch 23 → 26 taken 3944 times.
12068 if (terminal->getSymbol()->getType() == SpiceParser::PLUS)
1073
1/2
✓ Branch 24 → 25 taken 8124 times.
✗ Branch 24 → 56 not taken.
8124 additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_PLUS, TY_INVALID);
1074
3/6
✓ Branch 26 → 27 taken 3944 times.
✗ Branch 26 → 60 not taken.
✓ Branch 27 → 28 taken 3944 times.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 3944 times.
✗ Branch 28 → 31 not taken.
3944 else if (terminal->getSymbol()->getType() == SpiceParser::MINUS)
1075
1/2
✓ Branch 29 → 30 taken 3944 times.
✗ Branch 29 → 58 not taken.
3944 additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_MINUS, TY_INVALID);
1076 else
1077 assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE
1078 }
1079
1080
1/2
✓ Branch 48 → 49 taken 10776 times.
✗ Branch 48 → 61 not taken.
21552 return concludeExprNode(additiveExprNode);
1081 }
1082
1083 287782 std::any ASTBuilder::visitMultiplicativeExpr(SpiceParser::MultiplicativeExprContext *ctx) {
1084
3/4
✓ Branch 2 → 3 taken 287782 times.
✗ Branch 2 → 57 not taken.
✓ Branch 5 → 6 taken 285105 times.
✓ Branch 5 → 8 taken 2677 times.
287782 if (ctx->castExpr().size() == 1)
1085 285105 return visit(ctx->castExpr(0));
1086
1087 2677 const auto multiplicativeExprNode = createNode<MultiplicativeExprNode>(ctx);
1088
1089 // Visit children
1090
2/4
✓ Branch 9 → 10 taken 2677 times.
✗ Branch 9 → 60 not taken.
✓ Branch 10 → 11 taken 2677 times.
✗ Branch 10 → 58 not taken.
2677 fetchChildrenIntoVector(multiplicativeExprNode->operands, ctx->castExpr());
1091
1092
2/2
✓ Branch 46 → 14 taken 8241 times.
✓ Branch 46 → 47 taken 2677 times.
13595 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1093
1/2
✓ Branch 16 → 17 taken 8241 times.
✗ Branch 16 → 18 not taken.
8241 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1094
2/2
✓ Branch 19 → 20 taken 5459 times.
✓ Branch 19 → 21 taken 2782 times.
8241 if (!terminal)
1095 5459 continue;
1096
1097
4/6
✓ Branch 21 → 22 taken 2782 times.
✗ Branch 21 → 67 not taken.
✓ Branch 22 → 23 taken 2782 times.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 2170 times.
✓ Branch 23 → 26 taken 612 times.
2782 if (terminal->getSymbol()->getType() == SpiceParser::MUL)
1098
1/2
✓ Branch 24 → 25 taken 2170 times.
✗ Branch 24 → 61 not taken.
2170 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_MUL, TY_INVALID);
1099
4/6
✓ Branch 26 → 27 taken 612 times.
✗ Branch 26 → 67 not taken.
✓ Branch 27 → 28 taken 612 times.
✗ Branch 27 → 67 not taken.
✓ Branch 28 → 29 taken 450 times.
✓ Branch 28 → 31 taken 162 times.
612 else if (terminal->getSymbol()->getType() == SpiceParser::DIV)
1100
1/2
✓ Branch 29 → 30 taken 450 times.
✗ Branch 29 → 63 not taken.
450 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_DIV, TY_INVALID);
1101
3/6
✓ Branch 31 → 32 taken 162 times.
✗ Branch 31 → 67 not taken.
✓ Branch 32 → 33 taken 162 times.
✗ Branch 32 → 67 not taken.
✓ Branch 33 → 34 taken 162 times.
✗ Branch 33 → 36 not taken.
162 else if (terminal->getSymbol()->getType() == SpiceParser::REM)
1102
1/2
✓ Branch 34 → 35 taken 162 times.
✗ Branch 34 → 65 not taken.
162 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_REM, TY_INVALID);
1103 else
1104 assert_fail("Invalid terminal symbol for multiplicative expression"); // GCOV_EXCL_LINE
1105 }
1106
1107
1/2
✓ Branch 53 → 54 taken 2677 times.
✗ Branch 53 → 68 not taken.
5354 return concludeExprNode(multiplicativeExprNode);
1108 }
1109
1110 290564 std::any ASTBuilder::visitCastExpr(SpiceParser::CastExprContext *ctx) {
1111
2/2
✓ Branch 3 → 4 taken 280867 times.
✓ Branch 3 → 6 taken 9697 times.
290564 if (!ctx->CAST())
1112 280867 return visit(ctx->prefixUnaryExpr());
1113
1114 9697 const auto castExprNode = createNode<CastExprNode>(ctx);
1115
1116 // Visit children
1117
1/2
✓ Branch 8 → 9 taken 9697 times.
✗ Branch 8 → 18 not taken.
9697 if (ctx->dataType()) {
1118
3/6
✓ Branch 9 → 10 taken 9697 times.
✗ Branch 9 → 35 not taken.
✓ Branch 10 → 11 taken 9697 times.
✗ Branch 10 → 35 not taken.
✓ Branch 11 → 12 taken 9697 times.
✗ Branch 11 → 33 not taken.
9697 castExprNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1119
3/6
✓ Branch 13 → 14 taken 9697 times.
✗ Branch 13 → 38 not taken.
✓ Branch 14 → 15 taken 9697 times.
✗ Branch 14 → 38 not taken.
✓ Branch 15 → 16 taken 9697 times.
✗ Branch 15 → 36 not taken.
9697 castExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
1120 9697 castExprNode->isCast = true;
1121 } else {
1122 castExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr()));
1123 }
1124
1125
1/2
✓ Branch 29 → 30 taken 9697 times.
✗ Branch 29 → 42 not taken.
19394 return concludeExprNode(castExprNode);
1126 }
1127
1128 310963 std::any ASTBuilder::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprContext *ctx) {
1129
2/2
✓ Branch 3 → 4 taken 305199 times.
✓ Branch 3 → 6 taken 5764 times.
310963 if (!ctx->prefixUnaryExpr())
1130 305199 return visit(ctx->postfixUnaryExpr());
1131
1132 5764 const auto prefixUnaryExprNode = createNode<PrefixUnaryExprNode>(ctx);
1133
1134 // Visit children
1135
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 5764 times.
5764 if (ctx->postfixUnaryExpr()) {
1136 prefixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr()));
1137
1/2
✓ Branch 15 → 16 taken 5764 times.
✗ Branch 15 → 42 not taken.
5764 } else if (ctx->prefixUnaryExpr()) {
1138 // Extract operator
1139
2/2
✓ Branch 17 → 18 taken 224 times.
✓ Branch 17 → 19 taken 5540 times.
5764 if (ctx->MINUS())
1140 224 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS;
1141
2/2
✓ Branch 20 → 21 taken 12 times.
✓ Branch 20 → 22 taken 5528 times.
5540 else if (ctx->PLUS_PLUS())
1142 12 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS;
1143
2/2
✓ Branch 23 → 24 taken 15 times.
✓ Branch 23 → 25 taken 5513 times.
5528 else if (ctx->MINUS_MINUS())
1144 15 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS;
1145
2/2
✓ Branch 26 → 27 taken 3666 times.
✓ Branch 26 → 28 taken 1847 times.
5513 else if (ctx->NOT())
1146 3666 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT;
1147
2/2
✓ Branch 29 → 30 taken 27 times.
✓ Branch 29 → 31 taken 1820 times.
1847 else if (ctx->BITWISE_NOT())
1148 27 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT;
1149
2/2
✓ Branch 32 → 33 taken 806 times.
✓ Branch 32 → 34 taken 1014 times.
1820 else if (ctx->MUL())
1150 806 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE;
1151
1/2
✓ Branch 35 → 36 taken 1014 times.
✗ Branch 35 → 37 not taken.
1014 else if (ctx->BITWISE_AND())
1152 1014 prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF;
1153
1154
3/6
✓ Branch 37 → 38 taken 5764 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 5764 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 5764 times.
✗ Branch 39 → 56 not taken.
5764 prefixUnaryExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr()));
1155 } else {
1156 assert_fail("Unknown prefix unary expression type"); // GCOV_EXCL_LINE
1157 }
1158
1159
1/2
✓ Branch 49 → 50 taken 5764 times.
✗ Branch 49 → 59 not taken.
11528 return concludeExprNode(prefixUnaryExprNode);
1160 }
1161
1162 381245 std::any ASTBuilder::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprContext *ctx) {
1163
2/2
✓ Branch 3 → 4 taken 305199 times.
✓ Branch 3 → 6 taken 76046 times.
381245 if (!ctx->postfixUnaryExpr())
1164 305199 return visit(ctx->atomicExpr());
1165
1166 76046 const auto postfixUnaryExprNode = createNode<PostfixUnaryExprNode>(ctx);
1167
1168
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 76046 times.
76046 if (ctx->atomicExpr()) {
1169 postfixUnaryExprNode->atomicExpr = std::any_cast<ExprNode *>(visit(ctx->atomicExpr()));
1170
1/2
✓ Branch 15 → 16 taken 76046 times.
✗ Branch 15 → 43 not taken.
76046 } else if (ctx->postfixUnaryExpr()) {
1171
3/6
✓ Branch 16 → 17 taken 76046 times.
✗ Branch 16 → 59 not taken.
✓ Branch 17 → 18 taken 76046 times.
✗ Branch 17 → 59 not taken.
✓ Branch 18 → 19 taken 76046 times.
✗ Branch 18 → 57 not taken.
76046 postfixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr()));
1172
1173 // Extract operator
1174
2/2
✓ Branch 21 → 22 taken 7719 times.
✓ Branch 21 → 27 taken 68327 times.
76046 if (ctx->assignExpr()) {
1175 7719 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT;
1176
3/6
✓ Branch 22 → 23 taken 7719 times.
✗ Branch 22 → 62 not taken.
✓ Branch 23 → 24 taken 7719 times.
✗ Branch 23 → 62 not taken.
✓ Branch 24 → 25 taken 7719 times.
✗ Branch 24 → 60 not taken.
7719 postfixUnaryExprNode->subscriptIndexExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
1177
2/2
✓ Branch 28 → 29 taken 62894 times.
✓ Branch 28 → 34 taken 5433 times.
68327 } else if (ctx->IDENTIFIER()) {
1178 62894 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS;
1179
2/4
✓ Branch 29 → 30 taken 62894 times.
✗ Branch 29 → 63 not taken.
✓ Branch 30 → 31 taken 62894 times.
✗ Branch 30 → 63 not taken.
62894 postfixUnaryExprNode->identifier = getIdentifier(ctx->IDENTIFIER(), false);
1180
2/2
✓ Branch 35 → 36 taken 4615 times.
✓ Branch 35 → 37 taken 818 times.
5433 } else if (ctx->PLUS_PLUS()) {
1181 4615 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS;
1182
2/2
✓ Branch 38 → 39 taken 761 times.
✓ Branch 38 → 40 taken 57 times.
818 } else if (ctx->MINUS_MINUS()) {
1183 761 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS;
1184
1/2
✓ Branch 41 → 42 taken 57 times.
✗ Branch 41 → 44 not taken.
57 } else if (ctx->NOT()) {
1185 57 postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_ERR_PROPAGATION;
1186 }
1187 } else {
1188 assert_fail("Unknown postfix unary expression type"); // GCOV_EXCL_LINE
1189 }
1190
1191
1/2
✓ Branch 50 → 51 taken 76046 times.
✗ Branch 50 → 64 not taken.
152092 return concludeExprNode(postfixUnaryExprNode);
1192 }
1193
1194 305199 std::any ASTBuilder::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) {
1195 305199 const auto atomicExprNode = createNode<AtomicExprNode>(ctx);
1196
1197 // Visit children
1198
2/2
✓ Branch 4 → 5 taken 55925 times.
✓ Branch 4 → 10 taken 249274 times.
305199 if (ctx->constant()) {
1199
4/6
✓ Branch 5 → 6 taken 55925 times.
✗ Branch 5 → 88 not taken.
✓ Branch 6 → 7 taken 55923 times.
✓ Branch 6 → 88 taken 2 times.
✓ Branch 7 → 8 taken 55923 times.
✗ Branch 7 → 86 not taken.
55925 atomicExprNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
1200
2/2
✓ Branch 11 → 12 taken 73024 times.
✓ Branch 11 → 17 taken 176250 times.
249274 } else if (ctx->value()) {
1201
3/6
✓ Branch 12 → 13 taken 73024 times.
✗ Branch 12 → 91 not taken.
✓ Branch 13 → 14 taken 73024 times.
✗ Branch 13 → 91 not taken.
✓ Branch 14 → 15 taken 73024 times.
✗ Branch 14 → 89 not taken.
73024 atomicExprNode->value = std::any_cast<ValueNode *>(visit(ctx->value()));
1202
11/18
✓ Branch 17 → 18 taken 176250 times.
✗ Branch 17 → 92 not taken.
✓ Branch 19 → 20 taken 10228 times.
✓ Branch 19 → 23 taken 166022 times.
✓ Branch 20 → 21 taken 10228 times.
✗ Branch 20 → 92 not taken.
✓ Branch 22 → 23 taken 8327 times.
✓ Branch 22 → 24 taken 1901 times.
✓ Branch 25 → 26 taken 10228 times.
✓ Branch 25 → 27 taken 166022 times.
✓ Branch 27 → 28 taken 176250 times.
✗ Branch 27 → 29 not taken.
✓ Branch 29 → 30 taken 174349 times.
✓ Branch 29 → 68 taken 1901 times.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 94 not taken.
✗ Branch 96 → 97 not taken.
✗ Branch 96 → 98 not taken.
176250 } else if (!ctx->IDENTIFIER().empty() || !ctx->TYPE_IDENTIFIER().empty()) {
1203
1/2
✓ Branch 30 → 31 taken 174349 times.
✗ Branch 30 → 108 not taken.
174349 std::stringstream fqIdentifier;
1204
2/2
✓ Branch 62 → 33 taken 183679 times.
✓ Branch 62 → 63 taken 174349 times.
532377 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1205
1/2
✓ Branch 35 → 36 taken 183679 times.
✗ Branch 35 → 37 not taken.
183679 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1206
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 183679 times.
183679 if (!terminal)
1207 continue;
1208
1209
2/4
✓ Branch 40 → 41 taken 183679 times.
✗ Branch 40 → 104 not taken.
✓ Branch 41 → 42 taken 183679 times.
✗ Branch 41 → 104 not taken.
183679 const size_t terminalType = terminal->getSymbol()->getType();
1210
4/4
✓ Branch 42 → 43 taken 17657 times.
✓ Branch 42 → 44 taken 166022 times.
✓ Branch 43 → 44 taken 12992 times.
✓ Branch 43 → 53 taken 4665 times.
183679 if (terminalType == SpiceParser::IDENTIFIER || terminalType == SpiceParser::TYPE_IDENTIFIER) {
1211
1/2
✓ Branch 44 → 45 taken 179014 times.
✗ Branch 44 → 103 not taken.
179014 const std::string fragment = getIdentifier(terminal, false);
1212
1/2
✓ Branch 45 → 46 taken 179014 times.
✗ Branch 45 → 101 not taken.
179014 atomicExprNode->identifierFragments.push_back(fragment);
1213
3/4
✓ Branch 46 → 47 taken 179014 times.
✗ Branch 46 → 100 not taken.
✓ Branch 48 → 49 taken 4665 times.
✓ Branch 48 → 50 taken 174349 times.
179014 if (fqIdentifier.tellp() != 0)
1214
1/2
✓ Branch 49 → 50 taken 4665 times.
✗ Branch 49 → 101 not taken.
4665 fqIdentifier << SCOPE_ACCESS_TOKEN;
1215
1/2
✓ Branch 50 → 51 taken 179014 times.
✗ Branch 50 → 101 not taken.
179014 fqIdentifier << fragment;
1216 179014 }
1217 }
1218
1/2
✓ Branch 63 → 64 taken 174349 times.
✗ Branch 63 → 105 not taken.
174349 atomicExprNode->fqIdentifier = fqIdentifier.str();
1219
1/2
✓ Branch 69 → 70 taken 1901 times.
✗ Branch 69 → 75 not taken.
176250 } else if (ctx->assignExpr()) {
1220
3/6
✓ Branch 70 → 71 taken 1901 times.
✗ Branch 70 → 111 not taken.
✓ Branch 71 → 72 taken 1901 times.
✗ Branch 71 → 111 not taken.
✓ Branch 72 → 73 taken 1901 times.
✗ Branch 72 → 109 not taken.
1901 atomicExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
1221 } else {
1222 assert_fail("Unknown atomic expression type"); // GCOV_EXCL_LINE
1223 }
1224
1225
1/2
✓ Branch 82 → 83 taken 305197 times.
✗ Branch 82 → 112 not taken.
610394 return concludeExprNode(atomicExprNode);
1226 }
1227
1228 73024 std::any ASTBuilder::visitValue(SpiceParser::ValueContext *ctx) {
1229 73024 const auto valueNode = createNode<ValueNode>(ctx);
1230
1231 // Visit children
1232
2/2
✓ Branch 4 → 5 taken 65019 times.
✓ Branch 4 → 10 taken 8005 times.
73024 if (ctx->fctCall()) {
1233
3/6
✓ Branch 5 → 6 taken 65019 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 65019 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 65019 times.
✗ Branch 7 → 63 not taken.
65019 valueNode->fctCall = std::any_cast<FctCallNode *>(visit(ctx->fctCall()));
1234
2/2
✓ Branch 11 → 12 taken 307 times.
✓ Branch 11 → 17 taken 7698 times.
8005 } else if (ctx->arrayInitialization()) {
1235
3/6
✓ Branch 12 → 13 taken 307 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 307 times.
✗ Branch 13 → 68 not taken.
✓ Branch 14 → 15 taken 307 times.
✗ Branch 14 → 66 not taken.
307 valueNode->arrayInitialization = std::any_cast<ArrayInitializationNode *>(visit(ctx->arrayInitialization()));
1236
2/2
✓ Branch 18 → 19 taken 923 times.
✓ Branch 18 → 24 taken 6775 times.
7698 } else if (ctx->structInstantiation()) {
1237
3/6
✓ Branch 19 → 20 taken 923 times.
✗ Branch 19 → 71 not taken.
✓ Branch 20 → 21 taken 923 times.
✗ Branch 20 → 71 not taken.
✓ Branch 21 → 22 taken 923 times.
✗ Branch 21 → 69 not taken.
923 valueNode->structInstantiation = std::any_cast<StructInstantiationNode *>(visit(ctx->structInstantiation()));
1238
2/2
✓ Branch 25 → 26 taken 55 times.
✓ Branch 25 → 31 taken 6720 times.
6775 } else if (ctx->lambdaFunc()) {
1239
3/6
✓ Branch 26 → 27 taken 55 times.
✗ Branch 26 → 74 not taken.
✓ Branch 27 → 28 taken 55 times.
✗ Branch 27 → 74 not taken.
✓ Branch 28 → 29 taken 55 times.
✗ Branch 28 → 72 not taken.
55 valueNode->lambdaFunc = std::any_cast<LambdaFuncNode *>(visit(ctx->lambdaFunc()));
1240
2/2
✓ Branch 32 → 33 taken 75 times.
✓ Branch 32 → 38 taken 6645 times.
6720 } else if (ctx->lambdaProc()) {
1241
3/6
✓ Branch 33 → 34 taken 75 times.
✗ Branch 33 → 77 not taken.
✓ Branch 34 → 35 taken 75 times.
✗ Branch 34 → 77 not taken.
✓ Branch 35 → 36 taken 75 times.
✗ Branch 35 → 75 not taken.
75 valueNode->lambdaProc = std::any_cast<LambdaProcNode *>(visit(ctx->lambdaProc()));
1242
2/2
✓ Branch 39 → 40 taken 1 time.
✓ Branch 39 → 45 taken 6644 times.
6645 } else if (ctx->lambdaExpr()) {
1243
3/6
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 80 not taken.
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 80 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 78 not taken.
1 valueNode->lambdaExpr = std::any_cast<LambdaExprNode *>(visit(ctx->lambdaExpr()));
1244
1/2
✓ Branch 46 → 47 taken 6644 times.
✗ Branch 46 → 52 not taken.
6644 } else if (ctx->dataType()) {
1245 6644 valueNode->isNil = true;
1246
3/6
✓ Branch 47 → 48 taken 6644 times.
✗ Branch 47 → 83 not taken.
✓ Branch 48 → 49 taken 6644 times.
✗ Branch 48 → 83 not taken.
✓ Branch 49 → 50 taken 6644 times.
✗ Branch 49 → 81 not taken.
6644 valueNode->nilType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1247 } else {
1248 assert_fail("Unknown value type"); // GCOV_EXCL_LINE
1249 }
1250
1251
1/2
✓ Branch 59 → 60 taken 73024 times.
✗ Branch 59 → 84 not taken.
146048 return concludeNode(valueNode);
1252 }
1253
1254 61604 std::any ASTBuilder::visitConstant(SpiceParser::ConstantContext *ctx) {
1255 61604 const auto constantNode = createNode<ConstantNode>(ctx);
1256
1257 // Detect an optional leading minus sign for numeric literals
1258 61604 const bool isNegative = ctx->MINUS() != nullptr;
1259
1260 // Enrich
1261
2/2
✓ Branch 5 → 6 taken 2017 times.
✓ Branch 5 → 14 taken 59587 times.
61604 if (ctx->DOUBLE_LIT()) {
1262 2017 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_DOUBLE;
1263
3/6
✓ Branch 6 → 7 taken 2017 times.
✗ Branch 6 → 63 not taken.
✓ Branch 7 → 8 taken 2017 times.
✗ Branch 7 → 63 not taken.
✓ Branch 8 → 9 taken 2017 times.
✗ Branch 8 → 61 not taken.
2017 const double value = std::stod(ctx->DOUBLE_LIT()->toString());
1264
2/2
✓ Branch 10 → 11 taken 159 times.
✓ Branch 10 → 12 taken 1858 times.
2017 constantNode->compileTimeValue.doubleValue = isNegative ? -value : value;
1265
2/2
✓ Branch 15 → 16 taken 10523 times.
✓ Branch 15 → 19 taken 49064 times.
59587 } else if (ctx->INT_LIT()) {
1266 10523 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_INT;
1267 10523 constantNode->compileTimeValue.intValue = parseInt(ctx->INT_LIT(), isNegative);
1268
2/2
✓ Branch 20 → 21 taken 1224 times.
✓ Branch 20 → 24 taken 47840 times.
49064 } else if (ctx->SHORT_LIT()) {
1269 1224 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_SHORT;
1270 1224 constantNode->compileTimeValue.shortValue = parseShort(ctx->SHORT_LIT(), isNegative);
1271
2/2
✓ Branch 25 → 26 taken 21894 times.
✓ Branch 25 → 29 taken 25946 times.
47840 } else if (ctx->LONG_LIT()) {
1272 21894 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_LONG;
1273 21894 constantNode->compileTimeValue.longValue = parseLong(ctx->LONG_LIT(), isNegative);
1274
2/2
✓ Branch 30 → 31 taken 7147 times.
✓ Branch 30 → 34 taken 18799 times.
25946 } else if (ctx->CHAR_LIT()) {
1275 7147 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_CHAR;
1276 7147 constantNode->compileTimeValue.charValue = parseChar(ctx->CHAR_LIT());
1277
2/2
✓ Branch 35 → 36 taken 13188 times.
✓ Branch 35 → 44 taken 5611 times.
18799 } else if (ctx->STRING_LIT()) {
1278 // Save a pointer to the string in the compile time value
1279 13188 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_STRING;
1280 13188 constantNode->compileTimeValue.stringValueOffset = resourceManager.compileTimeStringValues.size();
1281 // Add the string to the global compile time string list
1282
4/8
✓ Branch 37 → 38 taken 13188 times.
✗ Branch 37 → 68 not taken.
✓ Branch 38 → 39 taken 13188 times.
✗ Branch 38 → 68 not taken.
✓ Branch 39 → 40 taken 13188 times.
✗ Branch 39 → 66 not taken.
✓ Branch 40 → 41 taken 13188 times.
✗ Branch 40 → 64 not taken.
13188 resourceManager.compileTimeStringValues.push_back(parseString(ctx->STRING_LIT()->toString()));
1283
2/2
✓ Branch 45 → 46 taken 2665 times.
✓ Branch 45 → 47 taken 2946 times.
5611 } else if (ctx->TRUE()) {
1284 2665 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL;
1285 2665 constantNode->compileTimeValue.boolValue = true;
1286
1/2
✓ Branch 48 → 49 taken 2946 times.
✗ Branch 48 → 50 not taken.
2946 } else if (ctx->FALSE()) {
1287 2946 constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL;
1288 2946 constantNode->compileTimeValue.boolValue = false;
1289 } else {
1290 assert_fail("Unknown constant type"); // GCOV_EXCL_LINE
1291 }
1292
1293
1/2
✓ Branch 57 → 58 taken 61602 times.
✗ Branch 57 → 70 not taken.
123204 return concludeNode(constantNode);
1294 }
1295
1296 65019 std::any ASTBuilder::visitFctCall(SpiceParser::FctCallContext *ctx) {
1297
1/2
✓ Branch 2 → 3 taken 65019 times.
✗ Branch 2 → 92 not taken.
65019 const auto fctCallNode = createNode<FctCallNode>(ctx);
1298
1299
1/2
✓ Branch 3 → 4 taken 65019 times.
✗ Branch 3 → 92 not taken.
65019 std::stringstream fqFunctionName;
1300
2/2
✓ Branch 46 → 6 taken 323056 times.
✓ Branch 46 → 47 taken 65019 times.
453094 for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) {
1301
1/2
✓ Branch 8 → 9 taken 323056 times.
✗ Branch 8 → 10 not taken.
323056 const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree);
1302
2/2
✓ Branch 11 → 12 taken 53313 times.
✓ Branch 11 → 13 taken 269743 times.
323056 if (!terminal)
1303 53313 continue;
1304
1305
4/6
✓ Branch 13 → 14 taken 269743 times.
✗ Branch 13 → 81 not taken.
✓ Branch 14 → 15 taken 269743 times.
✗ Branch 14 → 81 not taken.
✓ Branch 15 → 16 taken 87321 times.
✓ Branch 15 → 21 taken 182422 times.
269743 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1306
1/2
✓ Branch 16 → 17 taken 87321 times.
✗ Branch 16 → 77 not taken.
87321 const std::string fragment = terminal->toString();
1307
1/2
✓ Branch 17 → 18 taken 87321 times.
✗ Branch 17 → 75 not taken.
87321 fctCallNode->functionNameFragments.push_back(fragment);
1308
1/2
✓ Branch 18 → 19 taken 87321 times.
✗ Branch 18 → 75 not taken.
87321 fqFunctionName << fragment;
1309
4/6
✓ Branch 21 → 22 taken 182422 times.
✗ Branch 21 → 81 not taken.
✓ Branch 22 → 23 taken 182422 times.
✗ Branch 22 → 81 not taken.
✓ Branch 23 → 24 taken 10844 times.
✓ Branch 23 → 29 taken 171578 times.
269743 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1310
1/2
✓ Branch 24 → 25 taken 10844 times.
✗ Branch 24 → 80 not taken.
10844 const std::string fragment = terminal->toString();
1311
1/2
✓ Branch 25 → 26 taken 10844 times.
✗ Branch 25 → 78 not taken.
10844 fctCallNode->functionNameFragments.push_back(fragment);
1312
1/2
✓ Branch 26 → 27 taken 10844 times.
✗ Branch 26 → 78 not taken.
10844 fqFunctionName << fragment;
1313
4/6
✓ Branch 29 → 30 taken 171578 times.
✗ Branch 29 → 81 not taken.
✓ Branch 30 → 31 taken 171578 times.
✗ Branch 30 → 81 not taken.
✓ Branch 31 → 32 taken 162 times.
✓ Branch 31 → 33 taken 171416 times.
182422 } else if (terminal->getSymbol()->getType() == SpiceParser::SCOPE_ACCESS) {
1314
1/2
✓ Branch 32 → 37 taken 162 times.
✗ Branch 32 → 81 not taken.
162 fqFunctionName << SCOPE_ACCESS_TOKEN;
1315
4/6
✓ Branch 33 → 34 taken 171416 times.
✗ Branch 33 → 81 not taken.
✓ Branch 34 → 35 taken 171416 times.
✗ Branch 34 → 81 not taken.
✓ Branch 35 → 36 taken 32984 times.
✓ Branch 35 → 37 taken 138432 times.
171416 } else if (terminal->getSymbol()->getType() == SpiceParser::DOT) {
1316
1/2
✓ Branch 36 → 37 taken 32984 times.
✗ Branch 36 → 81 not taken.
32984 fqFunctionName << MEMBER_ACCESS_TOKEN;
1317 }
1318 }
1319
1/2
✓ Branch 47 → 48 taken 65019 times.
✗ Branch 47 → 82 not taken.
65019 fctCallNode->fqFunctionName = fqFunctionName.str();
1320
1321 // Visit children
1322
3/4
✓ Branch 50 → 51 taken 65019 times.
✗ Branch 50 → 90 not taken.
✓ Branch 51 → 52 taken 4197 times.
✓ Branch 51 → 57 taken 60822 times.
65019 if (ctx->typeLst()) {
1323 4197 fctCallNode->hasTemplateTypes = true;
1324
3/6
✓ Branch 52 → 53 taken 4197 times.
✗ Branch 52 → 85 not taken.
✓ Branch 53 → 54 taken 4197 times.
✗ Branch 53 → 85 not taken.
✓ Branch 54 → 55 taken 4197 times.
✗ Branch 54 → 83 not taken.
4197 fctCallNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1325 }
1326
3/4
✓ Branch 57 → 58 taken 65019 times.
✗ Branch 57 → 90 not taken.
✓ Branch 58 → 59 taken 49116 times.
✓ Branch 58 → 64 taken 15903 times.
65019 if (ctx->argLst()) {
1327 49116 fctCallNode->hasArgs = true;
1328
3/6
✓ Branch 59 → 60 taken 49116 times.
✗ Branch 59 → 88 not taken.
✓ Branch 60 → 61 taken 49116 times.
✗ Branch 60 → 88 not taken.
✓ Branch 61 → 62 taken 49116 times.
✗ Branch 61 → 86 not taken.
49116 fctCallNode->argLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1329 }
1330
1331
1/2
✓ Branch 70 → 71 taken 65019 times.
✗ Branch 70 → 89 not taken.
130038 return concludeNode(fctCallNode);
1332 65019 }
1333
1334 307 std::any ASTBuilder::visitArrayInitialization(SpiceParser::ArrayInitializationContext *ctx) {
1335 307 const auto arrayInitializationNode = createNode<ArrayInitializationNode>(ctx);
1336
1337 // Visit children
1338
2/2
✓ Branch 4 → 5 taken 306 times.
✓ Branch 4 → 10 taken 1 time.
307 if (ctx->argLst())
1339
3/6
✓ Branch 5 → 6 taken 306 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 306 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 306 times.
✗ Branch 7 → 20 not taken.
306 arrayInitializationNode->itemLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1340
1341
1/2
✓ Branch 16 → 17 taken 307 times.
✗ Branch 16 → 23 not taken.
614 return concludeNode(arrayInitializationNode);
1342 }
1343
1344 923 std::any ASTBuilder::visitStructInstantiation(SpiceParser::StructInstantiationContext *ctx) {
1345
1/2
✓ Branch 2 → 3 taken 923 times.
✗ Branch 2 → 85 not taken.
923 const auto structInstantiationNode = createNode<StructInstantiationNode>(ctx);
1346
1347 // Enrich
1348
1/2
✓ Branch 3 → 4 taken 923 times.
✗ Branch 3 → 85 not taken.
923 std::stringstream fqStructName;
1349
2/2
✓ Branch 39 → 6 taken 3703 times.
✓ Branch 39 → 40 taken 923 times.
5549 for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) {
1350
1/2
✓ Branch 8 → 9 taken 3703 times.
✗ Branch 8 → 10 not taken.
3703 const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree);
1351
2/2
✓ Branch 11 → 12 taken 906 times.
✓ Branch 11 → 13 taken 2797 times.
3703 if (!terminal)
1352 906 continue;
1353
1354
4/6
✓ Branch 13 → 14 taken 2797 times.
✗ Branch 13 → 74 not taken.
✓ Branch 14 → 15 taken 2797 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 3 times.
✓ Branch 15 → 22 taken 2794 times.
2797 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1355
1/2
✓ Branch 16 → 17 taken 3 times.
✗ Branch 16 → 70 not taken.
3 const std::string fragment = terminal->toString();
1356
1/2
✓ Branch 17 → 18 taken 3 times.
✗ Branch 17 → 68 not taken.
3 structInstantiationNode->structNameFragments.push_back(fragment);
1357
2/4
✓ Branch 18 → 19 taken 3 times.
✗ Branch 18 → 68 not taken.
✓ Branch 19 → 20 taken 3 times.
✗ Branch 19 → 68 not taken.
3 fqStructName << fragment << SCOPE_ACCESS_TOKEN;
1358
4/6
✓ Branch 22 → 23 taken 2794 times.
✗ Branch 22 → 74 not taken.
✓ Branch 23 → 24 taken 2794 times.
✗ Branch 23 → 74 not taken.
✓ Branch 24 → 25 taken 923 times.
✓ Branch 24 → 30 taken 1871 times.
2797 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1359
1/2
✓ Branch 25 → 26 taken 923 times.
✗ Branch 25 → 73 not taken.
923 const std::string fragment = terminal->toString();
1360
1/2
✓ Branch 26 → 27 taken 923 times.
✗ Branch 26 → 71 not taken.
923 structInstantiationNode->structNameFragments.push_back(fragment);
1361
1/2
✓ Branch 27 → 28 taken 923 times.
✗ Branch 27 → 71 not taken.
923 fqStructName << fragment;
1362 923 }
1363 }
1364
1/2
✓ Branch 40 → 41 taken 923 times.
✗ Branch 40 → 75 not taken.
923 structInstantiationNode->fqStructName = fqStructName.str();
1365
1366 // Visit children
1367
3/4
✓ Branch 43 → 44 taken 923 times.
✗ Branch 43 → 83 not taken.
✓ Branch 44 → 45 taken 11 times.
✓ Branch 44 → 50 taken 912 times.
923 if (ctx->typeLst()) {
1368 11 structInstantiationNode->hasTemplateTypes = true;
1369
3/6
✓ Branch 45 → 46 taken 11 times.
✗ Branch 45 → 78 not taken.
✓ Branch 46 → 47 taken 11 times.
✗ Branch 46 → 78 not taken.
✓ Branch 47 → 48 taken 11 times.
✗ Branch 47 → 76 not taken.
11 structInstantiationNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1370 }
1371
3/4
✓ Branch 50 → 51 taken 923 times.
✗ Branch 50 → 83 not taken.
✓ Branch 51 → 52 taken 895 times.
✓ Branch 51 → 57 taken 28 times.
923 if (ctx->argLst())
1372
3/6
✓ Branch 52 → 53 taken 895 times.
✗ Branch 52 → 81 not taken.
✓ Branch 53 → 54 taken 895 times.
✗ Branch 53 → 81 not taken.
✓ Branch 54 → 55 taken 895 times.
✗ Branch 54 → 79 not taken.
895 structInstantiationNode->fieldLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1373
1374
1/2
✓ Branch 63 → 64 taken 923 times.
✗ Branch 63 → 82 not taken.
1846 return concludeNode(structInstantiationNode);
1375 923 }
1376
1377 55 std::any ASTBuilder::visitLambdaFunc(SpiceParser::LambdaFuncContext *ctx) {
1378 55 const auto lambdaFuncNode = createNode<LambdaFuncNode>(ctx);
1379
1380 // Visit children
1381
3/6
✓ Branch 3 → 4 taken 55 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 55 times.
✗ Branch 4 → 37 not taken.
✓ Branch 5 → 6 taken 55 times.
✗ Branch 5 → 35 not taken.
55 lambdaFuncNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1382
2/2
✓ Branch 8 → 9 taken 50 times.
✓ Branch 8 → 14 taken 5 times.
55 if (ctx->paramLst()) {
1383 50 lambdaFuncNode->hasParams = true;
1384
3/6
✓ Branch 9 → 10 taken 50 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 50 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 50 times.
✗ Branch 11 → 38 not taken.
50 lambdaFuncNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1385 }
1386
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 21 taken 55 times.
55 if (ctx->lambdaAttr())
1387 lambdaFuncNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr()));
1388
4/8
✓ Branch 21 → 22 taken 55 times.
✗ Branch 21 → 46 not taken.
✓ Branch 22 → 23 taken 55 times.
✗ Branch 22 → 46 not taken.
✓ Branch 23 → 24 taken 55 times.
✗ Branch 23 → 44 not taken.
✓ Branch 25 → 26 taken 55 times.
✗ Branch 25 → 47 not taken.
55 lambdaFuncNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
1389
1390
1/2
✓ Branch 31 → 32 taken 55 times.
✗ Branch 31 → 47 not taken.
110 return concludeNode(lambdaFuncNode);
1391 }
1392
1393 75 std::any ASTBuilder::visitLambdaProc(SpiceParser::LambdaProcContext *ctx) {
1394 75 const auto lambdaProcNode = createNode<LambdaProcNode>(ctx);
1395
1396 // Visit children
1397
2/2
✓ Branch 4 → 5 taken 59 times.
✓ Branch 4 → 10 taken 16 times.
75 if (ctx->paramLst()) {
1398 59 lambdaProcNode->hasParams = true;
1399
3/6
✓ Branch 5 → 6 taken 59 times.
✗ Branch 5 → 33 not taken.
✓ Branch 6 → 7 taken 59 times.
✗ Branch 6 → 33 not taken.
✓ Branch 7 → 8 taken 59 times.
✗ Branch 7 → 31 not taken.
59 lambdaProcNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1400 }
1401
2/2
✓ Branch 11 → 12 taken 8 times.
✓ Branch 11 → 17 taken 67 times.
75 if (ctx->lambdaAttr())
1402
3/6
✓ Branch 12 → 13 taken 8 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 8 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 8 times.
✗ Branch 14 → 34 not taken.
8 lambdaProcNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr()));
1403
4/8
✓ Branch 17 → 18 taken 75 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 75 times.
✗ Branch 18 → 39 not taken.
✓ Branch 19 → 20 taken 75 times.
✗ Branch 19 → 37 not taken.
✓ Branch 21 → 22 taken 75 times.
✗ Branch 21 → 40 not taken.
75 lambdaProcNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
1404
1405
1/2
✓ Branch 27 → 28 taken 75 times.
✗ Branch 27 → 40 not taken.
150 return concludeNode(lambdaProcNode);
1406 }
1407
1408 1 std::any ASTBuilder::visitLambdaExpr(SpiceParser::LambdaExprContext *ctx) {
1409 1 const auto lambdaExprNode = createNode<LambdaExprNode>(ctx);
1410
1411 // Visit children
1412
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 10 not taken.
1 if (ctx->paramLst()) {
1413 1 lambdaExprNode->hasParams = true;
1414
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()));
1415 }
1416
4/8
✓ 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.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 30 not taken.
1 lambdaExprNode->lambdaExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr()));
1417
1418
1/2
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 30 not taken.
2 return concludeNode(lambdaExprNode);
1419 }
1420
1421 158741 std::any ASTBuilder::visitDataType(SpiceParser::DataTypeContext *ctx) {
1422 158741 const auto dataTypeNode = createNode<DataTypeNode>(ctx);
1423
1424 // Visit children
1425
2/2
✓ Branch 4 → 5 taken 58276 times.
✓ Branch 4 → 10 taken 100465 times.
158741 if (ctx->qualifierLst())
1426
4/6
✓ Branch 5 → 6 taken 58276 times.
✗ Branch 5 → 73 not taken.
✓ Branch 6 → 7 taken 58275 times.
✓ Branch 6 → 73 taken 1 time.
✓ Branch 7 → 8 taken 58275 times.
✗ Branch 7 → 71 not taken.
58276 dataTypeNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst()));
1427
3/6
✓ Branch 10 → 11 taken 158740 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 158740 times.
✗ Branch 11 → 76 not taken.
✓ Branch 12 → 13 taken 158740 times.
✗ Branch 12 → 74 not taken.
158740 dataTypeNode->baseDataType = std::any_cast<BaseDataTypeNode *>(visit(ctx->baseDataType()));
1428
1429 // Enrich
1430
2/2
✓ Branch 60 → 15 taken 262391 times.
✓ Branch 60 → 61 taken 158740 times.
421131 for (size_t i = 0; i < ctx->children.size(); i++) {
1431 262391 antlr4::tree::ParseTree *subTree = ctx->children.at(i);
1432
1/2
✓ Branch 16 → 17 taken 262391 times.
✗ Branch 16 → 18 not taken.
262391 auto terminal = dynamic_cast<TerminalNode *>(subTree);
1433
2/2
✓ Branch 19 → 20 taken 217015 times.
✓ Branch 19 → 21 taken 45376 times.
262391 if (!terminal)
1434 217015 continue;
1435
1436
2/2
✓ Branch 23 → 24 taken 27955 times.
✓ Branch 23 → 26 taken 17421 times.
45376 if (terminal->getSymbol()->getType() == SpiceParser::MUL) {
1437
1/2
✓ Branch 24 → 25 taken 27955 times.
✗ Branch 24 → 77 not taken.
27955 dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_PTR, false, 0);
1438
2/2
✓ Branch 28 → 29 taken 17170 times.
✓ Branch 28 → 31 taken 251 times.
17421 } else if (terminal->getSymbol()->getType() == SpiceParser::BITWISE_AND) {
1439
1/2
✓ Branch 29 → 30 taken 17170 times.
✗ Branch 29 → 80 not taken.
17170 dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_REF, false, 0);
1440
1/2
✓ Branch 33 → 34 taken 251 times.
✗ Branch 33 → 58 not taken.
251 } else if (terminal->getSymbol()->getType() == SpiceParser::LBRACKET) {
1441 251 i++; // Consume LBRACKET
1442
1/2
✓ Branch 34 → 35 taken 251 times.
✗ Branch 34 → 92 not taken.
251 subTree = ctx->children.at(i);
1443
1/2
✓ Branch 35 → 36 taken 251 times.
✗ Branch 35 → 37 not taken.
251 terminal = dynamic_cast<TerminalNode *>(subTree);
1444 251 bool hasSize = false;
1445 251 unsigned int hardCodedSize = 0;
1446 251 std::string sizeVarName;
1447
4/6
✓ Branch 39 → 40 taken 251 times.
✗ Branch 39 → 90 not taken.
✓ Branch 40 → 41 taken 251 times.
✗ Branch 40 → 90 not taken.
✓ Branch 41 → 42 taken 114 times.
✓ Branch 41 → 46 taken 137 times.
251 if (terminal->getSymbol()->getType() == SpiceParser::INT_LIT) {
1448 114 hasSize = true;
1449
2/4
✓ Branch 42 → 43 taken 114 times.
✗ Branch 42 → 85 not taken.
✓ Branch 43 → 44 taken 114 times.
✗ Branch 43 → 83 not taken.
114 hardCodedSize = std::stoi(terminal->getText());
1450 114 i++; // Consume INT_LIT
1451
4/6
✓ Branch 46 → 47 taken 137 times.
✗ Branch 46 → 90 not taken.
✓ Branch 47 → 48 taken 137 times.
✗ Branch 47 → 90 not taken.
✓ Branch 48 → 49 taken 47 times.
✓ Branch 48 → 53 taken 90 times.
137 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1452 47 hasSize = true;
1453
1/2
✓ Branch 49 → 50 taken 47 times.
✗ Branch 49 → 86 not taken.
47 sizeVarName = getIdentifier(terminal, true);
1454 47 i++; // Consume TYPE_IDENTIFIER
1455 }
1456
1/2
✓ Branch 54 → 55 taken 251 times.
✗ Branch 54 → 87 not taken.
251 dataTypeNode->tmQueue.push({DataTypeNode::TypeModifierType::TYPE_ARRAY, hasSize, hardCodedSize, sizeVarName});
1457 251 }
1458 }
1459
1460
1/2
✓ Branch 67 → 68 taken 158740 times.
✗ Branch 67 → 93 not taken.
317480 return concludeNode(dataTypeNode);
1461
1/2
✓ Branch 53 → 54 taken 251 times.
✗ Branch 53 → 89 not taken.
251 }
1462
1463 158740 std::any ASTBuilder::visitBaseDataType(SpiceParser::BaseDataTypeContext *ctx) {
1464 158740 const auto baseDataTypeNode = createNode<BaseDataTypeNode>(ctx);
1465
1466 // Enrich
1467
2/2
✓ Branch 4 → 5 taken 2172 times.
✓ Branch 4 → 6 taken 156568 times.
158740 if (ctx->TYPE_DOUBLE()) {
1468 2172 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DOUBLE;
1469
2/2
✓ Branch 7 → 8 taken 9050 times.
✓ Branch 7 → 9 taken 147518 times.
156568 } else if (ctx->TYPE_INT()) {
1470 9050 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_INT;
1471
2/2
✓ Branch 10 → 11 taken 2320 times.
✓ Branch 10 → 12 taken 145198 times.
147518 } else if (ctx->TYPE_SHORT()) {
1472 2320 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_SHORT;
1473
2/2
✓ Branch 13 → 14 taken 24931 times.
✓ Branch 13 → 15 taken 120267 times.
145198 } else if (ctx->TYPE_LONG()) {
1474 24931 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_LONG;
1475
2/2
✓ Branch 16 → 17 taken 9310 times.
✓ Branch 16 → 18 taken 110957 times.
120267 } else if (ctx->TYPE_BYTE()) {
1476 9310 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BYTE;
1477
2/2
✓ Branch 19 → 20 taken 15681 times.
✓ Branch 19 → 21 taken 95276 times.
110957 } else if (ctx->TYPE_CHAR()) {
1478 15681 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CHAR;
1479
2/2
✓ Branch 22 → 23 taken 11224 times.
✓ Branch 22 → 24 taken 84052 times.
95276 } else if (ctx->TYPE_STRING()) {
1480 11224 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_STRING;
1481
2/2
✓ Branch 25 → 26 taken 11494 times.
✓ Branch 25 → 27 taken 72558 times.
84052 } else if (ctx->TYPE_BOOL()) {
1482 11494 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BOOL;
1483
2/2
✓ Branch 28 → 29 taken 1554 times.
✓ Branch 28 → 30 taken 71004 times.
72558 } else if (ctx->TYPE_DYN()) {
1484 1554 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DYN;
1485
2/2
✓ Branch 31 → 32 taken 70571 times.
✓ Branch 31 → 37 taken 433 times.
71004 } else if (ctx->customDataType()) {
1486 70571 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CUSTOM;
1487
3/6
✓ Branch 32 → 33 taken 70571 times.
✗ Branch 32 → 57 not taken.
✓ Branch 33 → 34 taken 70571 times.
✗ Branch 33 → 57 not taken.
✓ Branch 34 → 35 taken 70571 times.
✗ Branch 34 → 55 not taken.
70571 baseDataTypeNode->customDataType = std::any_cast<CustomDataTypeNode *>(visit(ctx->customDataType()));
1488
1/2
✓ Branch 38 → 39 taken 433 times.
✗ Branch 38 → 44 not taken.
433 } else if (ctx->functionDataType()) {
1489 433 baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_FUNCTION;
1490
3/6
✓ Branch 39 → 40 taken 433 times.
✗ Branch 39 → 60 not taken.
✓ Branch 40 → 41 taken 433 times.
✗ Branch 40 → 60 not taken.
✓ Branch 41 → 42 taken 433 times.
✗ Branch 41 → 58 not taken.
433 baseDataTypeNode->functionDataType = std::any_cast<FunctionDataTypeNode *>(visit(ctx->functionDataType()));
1491 } else {
1492 assert_fail("Unknown base data type");
1493 }
1494
1495
1/2
✓ Branch 51 → 52 taken 158740 times.
✗ Branch 51 → 61 not taken.
317480 return concludeNode(baseDataTypeNode);
1496 }
1497
1498 70571 std::any ASTBuilder::visitCustomDataType(SpiceParser::CustomDataTypeContext *ctx) {
1499
1/2
✓ Branch 2 → 3 taken 70571 times.
✗ Branch 2 → 75 not taken.
70571 const auto customDataTypeNode = createNode<CustomDataTypeNode>(ctx);
1500
1501 // Enrich
1502
1/2
✓ Branch 3 → 4 taken 70571 times.
✗ Branch 3 → 75 not taken.
70571 std::stringstream fqTypeName;
1503
2/2
✓ Branch 39 → 6 taken 97390 times.
✓ Branch 39 → 40 taken 70571 times.
238532 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1504
1/2
✓ Branch 8 → 9 taken 97390 times.
✗ Branch 8 → 10 not taken.
97390 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1505
2/2
✓ Branch 11 → 12 taken 8871 times.
✓ Branch 11 → 13 taken 88519 times.
97390 if (!terminal)
1506 8871 continue;
1507
1508
4/6
✓ Branch 13 → 14 taken 88519 times.
✗ Branch 13 → 67 not taken.
✓ Branch 14 → 15 taken 88519 times.
✗ Branch 14 → 67 not taken.
✓ Branch 15 → 16 taken 103 times.
✓ Branch 15 → 22 taken 88416 times.
88519 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1509
1/2
✓ Branch 16 → 17 taken 103 times.
✗ Branch 16 → 63 not taken.
103 const std::string fragment = terminal->toString();
1510
1/2
✓ Branch 17 → 18 taken 103 times.
✗ Branch 17 → 61 not taken.
103 customDataTypeNode->typeNameFragments.push_back(fragment);
1511
2/4
✓ Branch 18 → 19 taken 103 times.
✗ Branch 18 → 61 not taken.
✓ Branch 19 → 20 taken 103 times.
✗ Branch 19 → 61 not taken.
103 fqTypeName << fragment << SCOPE_ACCESS_TOKEN;
1512
4/6
✓ Branch 22 → 23 taken 88416 times.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 88416 times.
✗ Branch 23 → 67 not taken.
✓ Branch 24 → 25 taken 70571 times.
✓ Branch 24 → 30 taken 17845 times.
88519 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1513
1/2
✓ Branch 25 → 26 taken 70571 times.
✗ Branch 25 → 66 not taken.
70571 const std::string fragment = terminal->toString();
1514
1/2
✓ Branch 26 → 27 taken 70571 times.
✗ Branch 26 → 64 not taken.
70571 customDataTypeNode->typeNameFragments.push_back(fragment);
1515
1/2
✓ Branch 27 → 28 taken 70571 times.
✗ Branch 27 → 64 not taken.
70571 fqTypeName << fragment;
1516 70571 }
1517 }
1518
1/2
✓ Branch 40 → 41 taken 70571 times.
✗ Branch 40 → 68 not taken.
70571 customDataTypeNode->fqTypeName = fqTypeName.str();
1519
1520 // Visit children
1521
3/4
✓ Branch 43 → 44 taken 70571 times.
✗ Branch 43 → 73 not taken.
✓ Branch 44 → 45 taken 8871 times.
✓ Branch 44 → 50 taken 61700 times.
70571 if (ctx->typeLst())
1522
3/6
✓ Branch 45 → 46 taken 8871 times.
✗ Branch 45 → 71 not taken.
✓ Branch 46 → 47 taken 8871 times.
✗ Branch 46 → 71 not taken.
✓ Branch 47 → 48 taken 8871 times.
✗ Branch 47 → 69 not taken.
8871 customDataTypeNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1523
1524
1/2
✓ Branch 56 → 57 taken 70571 times.
✗ Branch 56 → 72 not taken.
141142 return concludeNode(customDataTypeNode);
1525 70571 }
1526
1527 433 std::any ASTBuilder::visitFunctionDataType(SpiceParser::FunctionDataTypeContext *ctx) {
1528 433 const auto functionDataTypeNode = createNode<FunctionDataTypeNode>(ctx);
1529
1530 // Enrich
1531
2/2
✓ Branch 4 → 5 taken 258 times.
✓ Branch 4 → 11 taken 175 times.
433 if (ctx->dataType()) {
1532 258 functionDataTypeNode->isFunction = ctx->dataType();
1533
3/6
✓ Branch 6 → 7 taken 258 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 258 times.
✗ Branch 7 → 30 not taken.
✓ Branch 8 → 9 taken 258 times.
✗ Branch 8 → 28 not taken.
258 functionDataTypeNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1534 }
1535
2/2
✓ Branch 12 → 13 taken 363 times.
✓ Branch 12 → 18 taken 70 times.
433 if (ctx->typeLst())
1536
3/6
✓ Branch 13 → 14 taken 363 times.
✗ Branch 13 → 33 not taken.
✓ Branch 14 → 15 taken 363 times.
✗ Branch 14 → 33 not taken.
✓ Branch 15 → 16 taken 363 times.
✗ Branch 15 → 31 not taken.
363 functionDataTypeNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1537
1538
1/2
✓ Branch 24 → 25 taken 433 times.
✗ Branch 24 → 34 not taken.
866 return concludeNode(functionDataTypeNode);
1539 }
1540
1541 24332 std::any ASTBuilder::visitAssignOp(SpiceParser::AssignOpContext *ctx) {
1542 24332 const auto assignExprNode = resumeForExpansion<AssignExprNode>();
1543
1544 // Extract assign operator
1545
2/2
✓ Branch 15 → 16 taken 21185 times.
✓ Branch 15 → 17 taken 3147 times.
24332 if (ctx->ASSIGN())
1546 21185 assignExprNode->op = AssignExprNode::AssignOp::OP_ASSIGN;
1547
2/2
✓ Branch 18 → 19 taken 2268 times.
✓ Branch 18 → 20 taken 879 times.
3147 else if (ctx->PLUS_EQUAL())
1548 2268 assignExprNode->op = AssignExprNode::AssignOp::OP_PLUS_EQUAL;
1549
2/2
✓ Branch 21 → 22 taken 147 times.
✓ Branch 21 → 23 taken 732 times.
879 else if (ctx->MINUS_EQUAL())
1550 147 assignExprNode->op = AssignExprNode::AssignOp::OP_MINUS_EQUAL;
1551
2/2
✓ Branch 24 → 25 taken 250 times.
✓ Branch 24 → 26 taken 482 times.
732 else if (ctx->MUL_EQUAL())
1552 250 assignExprNode->op = AssignExprNode::AssignOp::OP_MUL_EQUAL;
1553
2/2
✓ Branch 27 → 28 taken 93 times.
✓ Branch 27 → 29 taken 389 times.
482 else if (ctx->DIV_EQUAL())
1554 93 assignExprNode->op = AssignExprNode::AssignOp::OP_DIV_EQUAL;
1555
2/2
✓ Branch 30 → 31 taken 36 times.
✓ Branch 30 → 32 taken 353 times.
389 else if (ctx->REM_EQUAL())
1556 36 assignExprNode->op = AssignExprNode::AssignOp::OP_REM_EQUAL;
1557
2/2
✓ Branch 33 → 34 taken 3 times.
✓ Branch 33 → 35 taken 350 times.
353 else if (ctx->SHL_EQUAL())
1558 3 assignExprNode->op = AssignExprNode::AssignOp::OP_SHL_EQUAL;
1559
2/2
✓ Branch 36 → 37 taken 8 times.
✓ Branch 36 → 38 taken 342 times.
350 else if (ctx->SHR_EQUAL())
1560 8 assignExprNode->op = AssignExprNode::AssignOp::OP_SHR_EQUAL;
1561
2/2
✓ Branch 39 → 40 taken 19 times.
✓ Branch 39 → 41 taken 323 times.
342 else if (ctx->AND_EQUAL())
1562 19 assignExprNode->op = AssignExprNode::AssignOp::OP_AND_EQUAL;
1563
2/2
✓ Branch 42 → 43 taken 19 times.
✓ Branch 42 → 44 taken 304 times.
323 else if (ctx->OR_EQUAL())
1564 19 assignExprNode->op = AssignExprNode::AssignOp::OP_OR_EQUAL;
1565
1/2
✓ Branch 45 → 46 taken 304 times.
✗ Branch 45 → 47 not taken.
304 else if (ctx->XOR_EQUAL())
1566 304 assignExprNode->op = AssignExprNode::AssignOp::OP_XOR_EQUAL;
1567 else
1568 assert_fail("Unknown assign operator");
1569
1570
1/2
✓ Branch 48 → 49 taken 24332 times.
✗ Branch 48 → 52 not taken.
48664 return nullptr;
1571 }
1572
1573 4063 std::any ASTBuilder::visitOverloadableOp(SpiceParser::OverloadableOpContext *ctx) {
1574 4063 const auto fctNameNode = resumeForExpansion<FctNameNode>();
1575
1576 // Enrich
1577
2/2
✓ Branch 15 → 16 taken 182 times.
✓ Branch 15 → 17 taken 3881 times.
4063 if (ctx->PLUS())
1578 182 fctNameNode->name = OP_FCT_PLUS;
1579
2/2
✓ Branch 18 → 19 taken 1 time.
✓ Branch 18 → 20 taken 3880 times.
3881 else if (ctx->MINUS())
1580 1 fctNameNode->name = OP_FCT_MINUS;
1581
2/2
✓ Branch 21 → 22 taken 361 times.
✓ Branch 21 → 23 taken 3519 times.
3880 else if (ctx->MUL())
1582 361 fctNameNode->name = OP_FCT_MUL;
1583
2/2
✓ Branch 24 → 25 taken 37 times.
✓ Branch 24 → 26 taken 3482 times.
3519 else if (ctx->DIV())
1584 37 fctNameNode->name = OP_FCT_DIV;
1585
2/2
✓ Branch 27 → 28 taken 937 times.
✓ Branch 27 → 29 taken 2545 times.
3482 else if (ctx->EQUAL())
1586 937 fctNameNode->name = OP_FCT_EQUAL;
1587
2/2
✓ Branch 30 → 31 taken 901 times.
✓ Branch 30 → 32 taken 1644 times.
2545 else if (ctx->NOT_EQUAL())
1588 901 fctNameNode->name = OP_FCT_NOT_EQUAL;
1589
3/4
✓ Branch 32 → 33 taken 1644 times.
✗ Branch 32 → 85 not taken.
✓ Branch 35 → 36 taken 73 times.
✓ Branch 35 → 37 taken 1571 times.
1644 else if (ctx->LESS().size() == 2)
1590 73 fctNameNode->name = OP_FCT_SHL;
1591
3/4
✓ Branch 37 → 38 taken 1571 times.
✗ Branch 37 → 86 not taken.
✓ Branch 40 → 41 taken 1 time.
✓ Branch 40 → 42 taken 1570 times.
1571 else if (ctx->GREATER().size() == 2)
1592 1 fctNameNode->name = OP_FCT_SHR;
1593
2/2
✓ Branch 43 → 44 taken 4 times.
✓ Branch 43 → 45 taken 1566 times.
1570 else if (ctx->BITWISE_AND())
1594 4 fctNameNode->name = OP_FCT_BITWISE_AND;
1595
2/2
✓ Branch 46 → 47 taken 4 times.
✓ Branch 46 → 48 taken 1562 times.
1566 else if (ctx->BITWISE_OR())
1596 4 fctNameNode->name = OP_FCT_BITWISE_OR;
1597
2/2
✓ Branch 49 → 50 taken 4 times.
✓ Branch 49 → 51 taken 1558 times.
1562 else if (ctx->BITWISE_XOR())
1598 4 fctNameNode->name = OP_FCT_BITWISE_XOR;
1599
2/2
✓ Branch 52 → 53 taken 4 times.
✓ Branch 52 → 54 taken 1554 times.
1558 else if (ctx->BITWISE_NOT())
1600 4 fctNameNode->name = OP_FCT_BITWISE_NOT;
1601
2/2
✓ Branch 55 → 56 taken 264 times.
✓ Branch 55 → 57 taken 1290 times.
1554 else if (ctx->PLUS_EQUAL())
1602 264 fctNameNode->name = OP_FCT_PLUS_EQUAL;
1603
2/2
✓ Branch 58 → 59 taken 84 times.
✓ Branch 58 → 60 taken 1206 times.
1290 else if (ctx->MINUS_EQUAL())
1604 84 fctNameNode->name = OP_FCT_MINUS_EQUAL;
1605
2/2
✓ Branch 61 → 62 taken 181 times.
✓ Branch 61 → 63 taken 1025 times.
1206 else if (ctx->MUL_EQUAL())
1606 181 fctNameNode->name = OP_FCT_MUL_EQUAL;
1607
2/2
✓ Branch 64 → 65 taken 37 times.
✓ Branch 64 → 66 taken 988 times.
1025 else if (ctx->DIV_EQUAL())
1608 37 fctNameNode->name = OP_FCT_DIV_EQUAL;
1609
2/2
✓ Branch 67 → 68 taken 118 times.
✓ Branch 67 → 69 taken 870 times.
988 else if (ctx->PLUS_PLUS())
1610 118 fctNameNode->name = OP_FCT_POSTFIX_PLUS_PLUS;
1611
2/2
✓ Branch 70 → 71 taken 84 times.
✓ Branch 70 → 72 taken 786 times.
870 else if (ctx->MINUS_MINUS())
1612 84 fctNameNode->name = OP_FCT_POSTFIX_MINUS_MINUS;
1613
2/2
✓ Branch 73 → 74 taken 449 times.
✓ Branch 73 → 75 taken 337 times.
786 else if (ctx->LBRACKET())
1614 449 fctNameNode->name = OP_FCT_SUBSCRIPT;
1615
1/2
✓ Branch 76 → 77 taken 337 times.
✗ Branch 76 → 78 not taken.
337 else if (ctx->ASSIGN())
1616 337 fctNameNode->name = OP_FCT_ASSIGN;
1617 else
1618 assert_fail("Unsupported overloadable operator"); // GCOV_EXCL_LINE
1619
1620 4063 fctNameNode->fqName = fctNameNode->name;
1621 4063 fctNameNode->nameFragments.push_back(fctNameNode->name);
1622
1623
1/2
✓ Branch 81 → 82 taken 4063 times.
✗ Branch 81 → 87 not taken.
8126 return nullptr;
1624 }
1625
1626 13617 int32_t ASTBuilder::parseInt(TerminalNode *terminal, bool isNegative) {
1627 40851 const NumericParserCallback<int32_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int32_t {
1628 // Prepare limits
1629
2/2
✓ Branch 2 → 3 taken 13216 times.
✓ Branch 2 → 4 taken 401 times.
13617 const int64_t upperLimit = isSigned ? INT32_MAX : UINT32_MAX;
1630
2/2
✓ Branch 5 → 6 taken 13216 times.
✓ Branch 5 → 7 taken 401 times.
13617 const int64_t lowerLimit = isSigned ? INT32_MIN : 0;
1631 // Parse number, apply sign and check for limits
1632 13617 int64_t number = std::stoll(substr, nullptr, base);
1633
2/2
✓ Branch 9 → 10 taken 223 times.
✓ Branch 9 → 11 taken 13393 times.
13616 if (isNegative)
1634 223 number = -number;
1635
2/4
✓ Branch 11 → 12 taken 13616 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 13616 times.
13616 if (number < lowerLimit || number > upperLimit)
1636 throw std::out_of_range("Number out of range");
1637 13616 return static_cast<int32_t>(number);
1638 13617 };
1639
2/2
✓ Branch 3 → 4 taken 13616 times.
✓ Branch 3 → 8 taken 1 time.
27233 return parseNumeric(terminal, cb);
1640 13617 }
1641
1642 1224 int16_t ASTBuilder::parseShort(TerminalNode *terminal, bool isNegative) {
1643 3672 const NumericParserCallback<int16_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int16_t {
1644 // Prepare limits
1645
2/2
✓ Branch 2 → 3 taken 890 times.
✓ Branch 2 → 4 taken 334 times.
1224 const int64_t upperLimit = isSigned ? INT16_MAX : UINT16_MAX;
1646
2/2
✓ Branch 5 → 6 taken 890 times.
✓ Branch 5 → 7 taken 334 times.
1224 const int64_t lowerLimit = isSigned ? INT16_MIN : 0;
1647 // Parse number, apply sign and check for limits
1648 1224 int64_t number = std::stoll(substr, nullptr, base);
1649
2/2
✓ Branch 9 → 10 taken 86 times.
✓ Branch 9 → 11 taken 1138 times.
1224 if (isNegative)
1650 86 number = -number;
1651
2/4
✓ Branch 11 → 12 taken 1224 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 1224 times.
1224 if (number < lowerLimit || number > upperLimit)
1652 throw std::out_of_range("Number out of range");
1653 1224 return static_cast<int16_t>(number);
1654 1224 };
1655
1/2
✓ Branch 3 → 4 taken 1224 times.
✗ Branch 3 → 8 not taken.
2448 return parseNumeric(terminal, cb);
1656 1224 }
1657
1658 21894 int64_t ASTBuilder::parseLong(TerminalNode *terminal, bool isNegative) {
1659 65682 const NumericParserCallback<int64_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int64_t {
1660 // Parse the magnitude as unsigned so values like 2^63 (the absolute value of INT64_MIN) fit
1661 21894 const uint64_t magnitude = std::stoull(substr, nullptr, base);
1662
2/2
✓ Branch 3 → 4 taken 2759 times.
✓ Branch 3 → 11 taken 19135 times.
21894 if (isNegative) {
1663 2759 constexpr uint64_t maxNegMagnitude = static_cast<uint64_t>(INT64_MAX) + 1; // 2^63
1664
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 2759 times.
2759 if (magnitude > maxNegMagnitude)
1665 throw std::out_of_range("Number out of range");
1666
2/2
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 10 taken 2757 times.
2759 if (magnitude == maxNegMagnitude)
1667 2 return INT64_MIN;
1668 2757 return -static_cast<int64_t>(magnitude);
1669 }
1670
3/4
✓ Branch 11 → 12 taken 17448 times.
✓ Branch 11 → 16 taken 1687 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 17448 times.
19135 if (isSigned && magnitude > static_cast<uint64_t>(INT64_MAX))
1671 throw std::out_of_range("Number out of range");
1672 19135 return static_cast<int64_t>(magnitude);
1673 21894 };
1674
1/2
✓ Branch 3 → 4 taken 21894 times.
✗ Branch 3 → 8 not taken.
43788 return parseNumeric(terminal, cb);
1675 21894 }
1676
1677 7147 int8_t ASTBuilder::parseChar(TerminalNode *terminal) const {
1678
1/2
✓ Branch 2 → 3 taken 7147 times.
✗ Branch 2 → 59 not taken.
7147 const std::string input = terminal->toString();
1679
2/2
✓ Branch 4 → 5 taken 4646 times.
✓ Branch 4 → 7 taken 2501 times.
7147 if (input.length() == 3) // Normal char literals
1680 4646 return input[1];
1681
1682
3/6
✓ Branch 8 → 9 taken 2501 times.
✗ Branch 8 → 12 not taken.
✓ Branch 10 → 11 taken 2501 times.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 2501 times.
✗ Branch 13 → 34 not taken.
2501 if (input.length() == 4 && input[1] == '\\') { // Char literals with escape sequence
1683
10/11
✓ Branch 15 → 16 taken 47 times.
✗ Branch 15 → 17 not taken.
✓ Branch 15 → 18 taken 59 times.
✓ Branch 15 → 19 taken 329 times.
✓ Branch 15 → 20 taken 254 times.
✓ Branch 15 → 21 taken 231 times.
✓ Branch 15 → 22 taken 9 times.
✓ Branch 15 → 23 taken 18 times.
✓ Branch 15 → 24 taken 11 times.
✓ Branch 15 → 25 taken 1542 times.
✓ Branch 15 → 26 taken 1 time.
2501 switch (input[2]) {
1684 47 case '\'':
1685 47 return '\'';
1686 case '"':
1687 return '\"';
1688 59 case '\\':
1689 59 return '\\';
1690 329 case 'n':
1691 329 return '\n';
1692 254 case 'r':
1693 254 return '\r';
1694 231 case 't':
1695 231 return '\t';
1696 9 case 'b':
1697 9 return '\b';
1698 18 case 'f':
1699 18 return '\f';
1700 11 case 'v':
1701 11 return '\v';
1702 1542 case '0':
1703 1542 return '\0';
1704 1 default:
1705
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);
1706
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);
1707 }
1708 }
1709
1710 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1711 throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid char literal " + input);
1712 7147 }
1713
1714 13188 std::string ASTBuilder::parseString(std::string input) {
1715
1/2
✓ Branch 3 → 4 taken 13188 times.
✗ Branch 3 → 9 not taken.
13188 input = input.substr(1, input.size() - 2);
1716 13188 replaceEscapeChars(input);
1717 13188 return input;
1718 }
1719
1720 36735 template <typename T> T ASTBuilder::parseNumeric(TerminalNode *terminal, const NumericParserCallback<T> &cb) {
1721
3/6
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 13617 times.
✗ Branch 2 → 87 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 21894 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 1224 times.
✗ Branch 2 → 87 not taken.
36735 const std::string input = terminal->toString();
1722
1723 // Set to signed if the input string does not end with 'u'
1724
12/18
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 4 → 5 taken 13216 times.
✓ Branch 4 → 9 taken 401 times.
✓ Branch 6 → 7 taken 13216 times.
✗ Branch 6 → 9 not taken.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 13216 times.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 4 → 5 taken 21894 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 21894 times.
✗ Branch 6 → 9 not taken.
✓ Branch 8 → 9 taken 1687 times.
✓ Branch 8 → 10 taken 20207 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 1224 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 890 times.
✓ Branch 6 → 9 taken 334 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 890 times.
36735 const bool isUnsigned = input.ends_with('u') || input.ends_with("us") || input.ends_with("ul");
1725
1726 try {
1727
6/6
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 12 → 13 taken 1755 times.
✓ Branch 12 → 30 taken 11862 times.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 12 → 13 taken 2640 times.
✓ Branch 12 → 30 taken 19254 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 837 times.
✓ Branch 12 → 30 taken 387 times.
36735 if (input.length() >= 3) {
1728
6/6
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 14 → 15 taken 555 times.
✓ Branch 14 → 30 taken 1200 times.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 14 → 15 taken 1050 times.
✓ Branch 14 → 30 taken 1590 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 181 times.
✓ Branch 14 → 30 taken 656 times.
5232 if (input[0] == '0') {
1729
3/6
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 15 → 16 taken 555 times.
✗ Branch 15 → 37 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 15 → 16 taken 1050 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 181 times.
✗ Branch 15 → 37 not taken.
1786 const std::string subStr = input.substr(2);
1730
6/15
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✓ Branch 17 → 22 taken 236 times.
✓ Branch 17 → 24 taken 319 times.
✗ Branch 17 → 26 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✓ Branch 17 → 22 taken 346 times.
✗ Branch 17 → 24 not taken.
✓ Branch 17 → 26 taken 704 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 180 times.
✓ Branch 17 → 26 taken 1 time.
1786 switch (input[1]) {
1731 case 'd': // fall-through
1732 case 'D':
1733 return cb(subStr, 10, !isUnsigned);
1734 case 'b': // fall-through
1735 case 'B':
1736 return cb(subStr, 2, !isUnsigned);
1737 582 case 'h': // fall-through
1738 case 'H': // fall-through
1739 case 'x': // fall-through
1740 case 'X':
1741
2/6
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 22 → 23 taken 236 times.
✗ Branch 22 → 35 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 22 → 23 taken 346 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.
582 return cb(subStr, 16, !isUnsigned);
1742 499 case 'o': // fall-through
1743 case 'O':
1744
2/6
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 24 → 25 taken 319 times.
✗ Branch 24 → 35 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 35 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 24 → 25 taken 180 times.
✗ Branch 24 → 35 not taken.
499 return cb(subStr, 8, !isUnsigned);
1745 705 default: // default is decimal
1746
2/6
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 35 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 26 → 27 taken 704 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.
705 return cb(input, 10, !isUnsigned);
1747 }
1748 1786 }
1749 }
1750
4/6
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 30 → 31 taken 13061 times.
✓ Branch 30 → 38 taken 1 time.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 30 → 31 taken 20844 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 1043 times.
✗ Branch 30 → 38 not taken.
34949 return cb(input, 10, !isUnsigned);
1751
1/9
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 1 time.
✗ Branch 38 → 51 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 38 → 51 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 38 → 51 not taken.
2 } catch (std::out_of_range &) {
1752
2/12
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 41 → 42 taken 1 time.
✗ Branch 41 → 70 not taken.
✓ Branch 42 → 43 taken 1 time.
✗ Branch 42 → 70 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 70 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 70 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 70 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 70 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1753
2/12
int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 46 → 47 taken 1 time.
✗ Branch 46 → 64 not taken.
✓ Branch 47 → 48 taken 1 time.
✗ Branch 47 → 61 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 64 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 61 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 64 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 61 not taken.
3 throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "The provided number is out of range");
1754 } catch (std::invalid_argument &) {
1755 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1756 throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "You tried to parse '" + input + "' as an integer, but it was no integer");
1757 }
1758 36735 }
1759
1760 13188 void ASTBuilder::replaceEscapeChars(std::string &input) {
1761 13188 const std::unordered_map<char, char> escapeMap = {
1762 {'a', '\a'}, {'b', '\b'}, {'f', '\f'}, {'n', '\n'}, {'r', '\r'}, {'t', '\t'},
1763 {'v', '\v'}, {'\\', '\\'}, {'?', '\?'}, {'\'', '\''}, {'"', '\"'},
1764
1/2
✓ Branch 4 → 5 taken 13188 times.
✗ Branch 4 → 40 not taken.
26376 };
1765
1766 13188 size_t writeIndex = 0;
1767 13188 size_t readIndex = 0;
1768 13188 const size_t len = input.length();
1769
1770
2/2
✓ Branch 36 → 8 taken 187938 times.
✓ Branch 36 → 37 taken 13188 times.
201126 while (readIndex < len) {
1771 187938 const char c = input[readIndex];
1772
3/4
✓ Branch 9 → 10 taken 2392 times.
✓ Branch 9 → 33 taken 185546 times.
✓ Branch 10 → 11 taken 2392 times.
✗ Branch 10 → 33 not taken.
187938 if (c == '\\' && readIndex + 1 < len) {
1773 2392 char next = input[readIndex + 1];
1774
1/2
✓ Branch 12 → 13 taken 2392 times.
✗ Branch 12 → 45 not taken.
2392 auto it = escapeMap.find(next);
1775
2/2
✓ Branch 15 → 16 taken 2352 times.
✓ Branch 15 → 19 taken 40 times.
2392 if (it != escapeMap.end()) {
1776 2352 input[writeIndex++] = it->second;
1777 2352 readIndex += 2;
1778 2389 continue;
1779 }
1780
1781 // Handle octal escape sequences (up to 3 digits)
1782
3/4
✓ Branch 19 → 20 taken 40 times.
✗ Branch 19 → 31 not taken.
✓ Branch 20 → 21 taken 37 times.
✓ Branch 20 → 31 taken 3 times.
40 if (next >= '0' && next <= '7') {
1783 37 int value = 0;
1784 37 size_t octalDigits = 0;
1785
1786 // Look ahead up to 3 digits
1787
3/4
✓ Branch 26 → 27 taken 111 times.
✓ Branch 26 → 28 taken 37 times.
✓ Branch 27 → 22 taken 111 times.
✗ Branch 27 → 28 not taken.
148 for (size_t i = 1; i <= 3 && readIndex + i < len; ++i) {
1788 111 const char oc = input[readIndex + i];
1789
2/4
✓ Branch 23 → 24 taken 111 times.
✗ Branch 23 → 28 not taken.
✓ Branch 24 → 25 taken 111 times.
✗ Branch 24 → 28 not taken.
111 if (oc >= '0' && oc <= '7') {
1790 111 value = value << 3 | (oc - '0'); // multiply by 8 and add digit
1791 111 octalDigits++;
1792 } else {
1793 break;
1794 }
1795 }
1796
1797
1/2
✓ Branch 28 → 29 taken 37 times.
✗ Branch 28 → 31 not taken.
37 if (octalDigits > 0) {
1798 37 input[writeIndex++] = static_cast<char>(value);
1799 37 readIndex += 1 + octalDigits; // backslash + octal digits
1800 37 continue;
1801 }
1802 }
1803 }
1804
1805 // Copy current character
1806 185549 input[writeIndex++] = c;
1807 185549 readIndex++;
1808 }
1809
1810
1/2
✓ Branch 37 → 38 taken 13188 times.
✗ Branch 37 → 46 not taken.
13188 input.resize(writeIndex);
1811 13188 }
1812
1813 391218 std::string ASTBuilder::getIdentifier(TerminalNode *terminal, bool isTypeIdentifier) const {
1814 391218 const std::string identifier = terminal->getText();
1815
1816 // Check if the list of reserved keywords contains the given identifier
1817
3/4
✓ Branch 3 → 4 taken 391218 times.
✗ Branch 3 → 52 not taken.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 14 taken 391217 times.
391218 if (std::ranges::find(RESERVED_KEYWORDS, identifier) != std::end(RESERVED_KEYWORDS)) {
1818
2/4
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 41 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 41 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1819
3/6
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 35 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 32 not taken.
1 throw ParserError(codeLoc, RESERVED_KEYWORD, "'" + identifier + "' is a reserved keyword. Please use another name instead");
1820 }
1821
1822 // Check if the identifier is a type identifier and is reserved
1823
6/6
✓ Branch 14 → 15 taken 32913 times.
✓ Branch 14 → 19 taken 358304 times.
✓ Branch 15 → 16 taken 7562 times.
✓ Branch 15 → 19 taken 25351 times.
✓ Branch 20 → 21 taken 1 time.
✓ Branch 20 → 30 taken 391216 times.
398779 if (isTypeIdentifier && !sourceFile->isStdFile &&
1824
3/4
✓ Branch 16 → 17 taken 7562 times.
✗ Branch 16 → 52 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 7561 times.
7562 std::ranges::find(RESERVED_TYPE_NAMES, identifier) != std::end(RESERVED_TYPE_NAMES)) {
1825
2/4
✓ Branch 21 → 22 taken 1 time.
✗ Branch 21 → 51 not taken.
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 51 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1826
3/6
✓ Branch 24 → 25 taken 1 time.
✗ Branch 24 → 47 not taken.
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 45 not taken.
✓ Branch 26 → 27 taken 1 time.
✗ Branch 26 → 42 not taken.
1 throw ParserError(codeLoc, RESERVED_TYPENAME, "'" + identifier + "' is a reserved type name. Please use another one instead");
1827 }
1828
1829 391216 return identifier;
1830 2 }
1831
1832 } // namespace spice::compiler
1833