GCC Code Coverage Report


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

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