GCC Code Coverage Report


Directory: ../
File: src/ast/ASTBuilder.cpp
Date: 2024-12-24 01:17:15
Exec Total Coverage
Lines: 1099 1128 97.4%
Functions: 270 270 100.0%
Branches: 1662 2774 59.9%

Line Branch Exec Source
1 // Copyright (c) 2021-2024 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 <global/GlobalResourceManager.h>
12 #include <typechecker/OpRuleManager.h>
13 #include <util/GlobalDefinitions.h>
14
15 namespace spice::compiler {
16
17 901 ASTBuilder::ASTBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile, antlr4::ANTLRInputStream *inputStream)
18
1/2
✓ Branch 3 taken 901 times.
✗ Branch 4 not taken.
901 : CompilerPass(resourceManager, sourceFile), inputStream(inputStream) {}
19
20 899 std::any ASTBuilder::visitEntry(SpiceParser::EntryContext *ctx) {
21 899 const auto entryNode = createNode<EntryNode>(ctx);
22
23 // Visit children
24
2/2
✓ Branch 5 taken 11745 times.
✓ Branch 6 taken 894 times.
12639 for (ParserRuleContext::ParseTree *child : ctx->children) {
25
3/4
✓ Branch 0 taken 11745 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 382 times.
✓ Branch 3 taken 11363 times.
11745 if (auto *mainFctDefCtx = dynamic_cast<SpiceParser::MainFunctionDefContext *>(child))
26
4/6
✓ Branch 1 taken 378 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 378 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 378 times.
✗ Branch 8 not taken.
382 entryNode->topLevelDefs.push_back(std::any_cast<MainFctDefNode *>(visit(mainFctDefCtx)));
27
3/4
✓ Branch 0 taken 11363 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4250 times.
✓ Branch 3 taken 7113 times.
11363 else if (auto *fctDefCtx = dynamic_cast<SpiceParser::FunctionDefContext *>(child))
28
3/6
✓ Branch 1 taken 4250 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4250 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4250 times.
✗ Branch 8 not taken.
4250 entryNode->topLevelDefs.push_back(std::any_cast<FctDefNode *>(visit(fctDefCtx)));
29
3/4
✓ Branch 0 taken 7113 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2707 times.
✓ Branch 3 taken 4406 times.
7113 else if (auto *procDefCtx = dynamic_cast<SpiceParser::ProcedureDefContext *>(child))
30
3/6
✓ Branch 1 taken 2707 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2707 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2707 times.
✗ Branch 8 not taken.
2707 entryNode->topLevelDefs.push_back(std::any_cast<ProcDefNode *>(visit(procDefCtx)));
31
3/4
✓ Branch 0 taken 4406 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 548 times.
✓ Branch 3 taken 3858 times.
4406 else if (auto *structDefCtx = dynamic_cast<SpiceParser::StructDefContext *>(child))
32
3/6
✓ Branch 1 taken 548 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 548 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 548 times.
✗ Branch 8 not taken.
548 entryNode->topLevelDefs.push_back(std::any_cast<StructDefNode *>(visit(structDefCtx)));
33
3/4
✓ Branch 0 taken 3858 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 3782 times.
3858 else if (auto *interfaceDefCtx = dynamic_cast<SpiceParser::InterfaceDefContext *>(child))
34
3/6
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 76 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 76 times.
✗ Branch 8 not taken.
76 entryNode->topLevelDefs.push_back(std::any_cast<InterfaceDefNode *>(visit(interfaceDefCtx)));
35
3/4
✓ Branch 0 taken 3782 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 3741 times.
3782 else if (auto *enumDefCtx = dynamic_cast<SpiceParser::EnumDefContext *>(child))
36
3/6
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 41 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 41 times.
✗ Branch 8 not taken.
41 entryNode->topLevelDefs.push_back(std::any_cast<EnumDefNode *>(visit(enumDefCtx)));
37
3/4
✓ Branch 0 taken 3741 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 724 times.
✓ Branch 3 taken 3017 times.
3741 else if (auto *genericTypeDefCtx = dynamic_cast<SpiceParser::GenericTypeDefContext *>(child))
38
3/6
✓ Branch 1 taken 724 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 724 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 724 times.
✗ Branch 8 not taken.
724 entryNode->topLevelDefs.push_back(std::any_cast<GenericTypeDefNode *>(visit(genericTypeDefCtx)));
39
3/4
✓ Branch 0 taken 3017 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 2985 times.
3017 else if (auto *aliasDefCtx = dynamic_cast<SpiceParser::AliasDefContext *>(child))
40
3/6
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 32 times.
✗ Branch 8 not taken.
32 entryNode->topLevelDefs.push_back(std::any_cast<AliasDefNode *>(visit(aliasDefCtx)));
41
3/4
✓ Branch 0 taken 2985 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 739 times.
✓ Branch 3 taken 2246 times.
2985 else if (auto *globalVarDefCtx = dynamic_cast<SpiceParser::GlobalVarDefContext *>(child))
42
3/6
✓ Branch 1 taken 739 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 739 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 739 times.
✗ Branch 8 not taken.
739 entryNode->topLevelDefs.push_back(std::any_cast<GlobalVarDefNode *>(visit(globalVarDefCtx)));
43
3/4
✓ Branch 0 taken 2246 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 371 times.
✓ Branch 3 taken 1875 times.
2246 else if (auto *importDefCtx = dynamic_cast<SpiceParser::ImportDefContext *>(child))
44
3/6
✓ Branch 1 taken 371 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 371 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 371 times.
✗ Branch 8 not taken.
371 entryNode->importDefs.push_back(std::any_cast<ImportDefNode *>(visit(importDefCtx)));
45
3/4
✓ Branch 0 taken 1875 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 703 times.
✓ Branch 3 taken 1172 times.
1875 else if (auto *extDeclCtx = dynamic_cast<SpiceParser::ExtDeclContext *>(child))
46
3/6
✓ Branch 1 taken 703 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 703 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 703 times.
✗ Branch 8 not taken.
703 entryNode->topLevelDefs.push_back(std::any_cast<ExtDeclNode *>(visit(extDeclCtx)));
47
3/4
✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 278 times.
✓ Branch 3 taken 894 times.
1172 else if (auto *modAttrCtx = dynamic_cast<SpiceParser::ModAttrContext *>(child))
48
4/6
✓ Branch 1 taken 277 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 277 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 277 times.
✗ Branch 8 not taken.
278 entryNode->modAttrs.push_back(std::any_cast<ModAttrNode *>(visit(modAttrCtx)));
49
1/2
✓ Branch 0 taken 894 times.
✗ Branch 1 not taken.
894 else if (const auto *eofCtx = dynamic_cast<TerminalNode *>(child);
50
5/10
✓ Branch 0 taken 894 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 894 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 894 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 894 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 894 times.
894 !eofCtx || eofCtx->getSymbol()->getType() != SpiceParser::EOF)
51 assert_fail("Unknown top level definition type"); // GCOV_EXCL_LINE
52 }
53
54
2/4
✓ Branch 1 taken 894 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 894 times.
✗ Branch 5 not taken.
894 return concludeNode(entryNode);
55 }
56
57 382 std::any ASTBuilder::visitMainFunctionDef(SpiceParser::MainFunctionDefContext *ctx) {
58 382 const auto mainFctDefNode = createNode<MainFctDefNode>(ctx);
59
60 // Visit children
61
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 381 times.
382 if (ctx->topLevelDefAttr())
62
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 mainFctDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
63
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 378 times.
382 if (ctx->paramLst()) {
64 4 mainFctDefNode->takesArgs = true;
65
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
4 mainFctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
66 }
67
4/6
✓ Branch 1 taken 382 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 378 times.
✓ Branch 5 taken 4 times.
✓ Branch 7 taken 378 times.
✗ Branch 8 not taken.
382 mainFctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
68
69
2/4
✓ Branch 1 taken 378 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 378 times.
✗ Branch 5 not taken.
378 return concludeNode(mainFctDefNode);
70 }
71
72 4250 std::any ASTBuilder::visitFunctionDef(SpiceParser::FunctionDefContext *ctx) {
73 4250 const auto fctDefNode = createNode<FctDefNode>(ctx);
74
75 // Visit children
76
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 4239 times.
4250 if (ctx->topLevelDefAttr()) {
77
3/6
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
11 fctDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
78 // Tell the attributes that they are function attributes
79
2/2
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 11 times.
26 for (AttrNode *attr : fctDefNode->attrs->attrLst->attributes)
80 15 attr->target = AttrNode::TARGET_FCT_PROC;
81 }
82
2/2
✓ Branch 1 taken 4101 times.
✓ Branch 2 taken 149 times.
4250 if (ctx->specifierLst())
83
3/6
✓ Branch 1 taken 4101 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4101 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4101 times.
✗ Branch 8 not taken.
4101 fctDefNode->specifierLst = std::any_cast<SpecifierLstNode *>(visit(ctx->specifierLst()));
84
3/6
✓ Branch 1 taken 4250 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4250 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4250 times.
✗ Branch 8 not taken.
4250 fctDefNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
85 4250 fctDefNode->returnType->isReturnType = true;
86
3/6
✓ Branch 1 taken 4250 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4250 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4250 times.
✗ Branch 8 not taken.
4250 fctDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName()));
87 4250 fctDefNode->isMethod = fctDefNode->name->nameFragments.size() > 1;
88
2/2
✓ Branch 1 taken 699 times.
✓ Branch 2 taken 3551 times.
4250 if (ctx->typeLst()) {
89 699 fctDefNode->hasTemplateTypes = true;
90
3/6
✓ Branch 1 taken 699 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 699 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 699 times.
✗ Branch 8 not taken.
699 fctDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
91 }
92
2/2
✓ Branch 1 taken 3002 times.
✓ Branch 2 taken 1248 times.
4250 if (ctx->paramLst()) {
93 3002 fctDefNode->hasParams = true;
94
3/6
✓ Branch 1 taken 3002 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3002 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3002 times.
✗ Branch 8 not taken.
3002 fctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
95 }
96
3/6
✓ Branch 1 taken 4250 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4250 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4250 times.
✗ Branch 8 not taken.
4250 fctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
97
98
2/4
✓ Branch 1 taken 4250 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4250 times.
✗ Branch 5 not taken.
4250 return concludeNode(fctDefNode);
99 }
100
101 2707 std::any ASTBuilder::visitProcedureDef(SpiceParser::ProcedureDefContext *ctx) {
102 2707 const auto procDefNode = createNode<ProcDefNode>(ctx);
103
104 // Visit children
105
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2706 times.
2707 if (ctx->topLevelDefAttr()) {
106
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 procDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
107 // Tell the attributes that they are function attributes
108
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 for (AttrNode *attr : procDefNode->attrs->attrLst->attributes)
109 1 attr->target = AttrNode::TARGET_FCT_PROC;
110 }
111
2/2
✓ Branch 1 taken 2411 times.
✓ Branch 2 taken 296 times.
2707 if (ctx->specifierLst())
112
3/6
✓ Branch 1 taken 2411 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2411 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2411 times.
✗ Branch 8 not taken.
2411 procDefNode->specifierLst = std::any_cast<SpecifierLstNode *>(visit(ctx->specifierLst()));
113
3/6
✓ Branch 1 taken 2707 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2707 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2707 times.
✗ Branch 8 not taken.
2707 procDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName()));
114 2707 procDefNode->isMethod = procDefNode->name->nameFragments.size() > 1;
115
2/2
✓ Branch 1 taken 514 times.
✓ Branch 2 taken 2193 times.
2707 if (ctx->typeLst()) {
116 514 procDefNode->hasTemplateTypes = true;
117
3/6
✓ Branch 1 taken 514 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 514 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 514 times.
✗ Branch 8 not taken.
514 procDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
118 }
119
2/2
✓ Branch 1 taken 1915 times.
✓ Branch 2 taken 792 times.
2707 if (ctx->paramLst()) {
120 1915 procDefNode->hasParams = true;
121
3/6
✓ Branch 1 taken 1915 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1915 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1915 times.
✗ Branch 8 not taken.
1915 procDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
122 }
123
3/6
✓ Branch 1 taken 2707 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2707 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2707 times.
✗ Branch 8 not taken.
2707 procDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
124
125
2/4
✓ Branch 1 taken 2707 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2707 times.
✗ Branch 5 not taken.
2707 return concludeNode(procDefNode);
126 }
127
128 6957 std::any ASTBuilder::visitFctName(SpiceParser::FctNameContext *ctx) {
129 6957 const auto fctNameNode = createNode<FctNameNode>(ctx);
130
131 // Extract function name
132
2/2
✓ Branch 1 taken 4635 times.
✓ Branch 2 taken 2322 times.
6957 if (ctx->TYPE_IDENTIFIER()) {
133
2/4
✓ Branch 1 taken 4635 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4635 times.
✗ Branch 5 not taken.
4635 const std::string typeIdentifier = getIdentifier(ctx->TYPE_IDENTIFIER());
134
1/2
✓ Branch 1 taken 4635 times.
✗ Branch 2 not taken.
4635 fctNameNode->structName = typeIdentifier;
135
1/2
✓ Branch 1 taken 4635 times.
✗ Branch 2 not taken.
4635 fctNameNode->fqName = typeIdentifier + MEMBER_ACCESS_TOKEN;
136
1/2
✓ Branch 1 taken 4635 times.
✗ Branch 2 not taken.
4635 fctNameNode->nameFragments.push_back(typeIdentifier);
137 4635 }
138
2/2
✓ Branch 1 taken 5727 times.
✓ Branch 2 taken 1230 times.
6957 if (ctx->IDENTIFIER()) {
139
2/4
✓ Branch 1 taken 5727 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5727 times.
✗ Branch 5 not taken.
5727 const std::string fctIdentifier = getIdentifier(ctx->IDENTIFIER());
140
1/2
✓ Branch 1 taken 5727 times.
✗ Branch 2 not taken.
5727 fctNameNode->name = fctIdentifier;
141
1/2
✓ Branch 1 taken 5727 times.
✗ Branch 2 not taken.
5727 fctNameNode->fqName += fctIdentifier;
142
1/2
✓ Branch 1 taken 5727 times.
✗ Branch 2 not taken.
5727 fctNameNode->nameFragments.push_back(fctIdentifier);
143 5727 }
144
145 // Visit children
146
2/2
✓ Branch 1 taken 1230 times.
✓ Branch 2 taken 5727 times.
6957 if (ctx->overloadableOp())
147
2/4
✓ Branch 1 taken 1230 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1230 times.
✗ Branch 5 not taken.
1230 visit(ctx->overloadableOp());
148
149
2/4
✓ Branch 1 taken 6957 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6957 times.
✗ Branch 5 not taken.
6957 return concludeNode(fctNameNode);
150 }
151
152 548 std::any ASTBuilder::visitStructDef(SpiceParser::StructDefContext *ctx) {
153 548 const auto structDefNode = createNode<StructDefNode>(ctx);
154
155 // Enrich
156
2/4
✓ Branch 1 taken 548 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 548 times.
✗ Branch 5 not taken.
548 structDefNode->structName = getIdentifier(ctx->TYPE_IDENTIFIER());
157 548 structDefNode->typeId = resourceManager.getNextCustomTypeId();
158
159 // Visit children
160
2/2
✓ Branch 1 taken 51 times.
✓ Branch 2 taken 497 times.
548 if (ctx->topLevelDefAttr()) {
161
3/6
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 51 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 51 times.
✗ Branch 8 not taken.
51 structDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
162
163 // Tell the attributes that they are struct attributes
164
2/2
✓ Branch 4 taken 51 times.
✓ Branch 5 taken 51 times.
102 for (AttrNode *attr : structDefNode->attrs->attrLst->attributes)
165 51 attr->target = AttrNode::TARGET_STRUCT;
166
167 // Check if a custom type id was set
168
7/18
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 51 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 51 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 51 times.
✓ Branch 10 taken 51 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 51 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 51 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
153 if (structDefNode->attrs && structDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID))
169 structDefNode->typeId = structDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue;
170 }
171
2/2
✓ Branch 1 taken 410 times.
✓ Branch 2 taken 138 times.
548 if (ctx->specifierLst())
172
3/6
✓ Branch 1 taken 410 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 410 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 410 times.
✗ Branch 8 not taken.
410 structDefNode->specifierLst = std::any_cast<SpecifierLstNode *>(visit(ctx->specifierLst()));
173
2/2
✓ Branch 1 taken 172 times.
✓ Branch 2 taken 376 times.
548 if (ctx->LESS()) {
174 172 structDefNode->hasTemplateTypes = true;
175
3/6
✓ Branch 1 taken 172 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 172 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 172 times.
✗ Branch 8 not taken.
172 structDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0)));
176 }
177
2/2
✓ Branch 1 taken 87 times.
✓ Branch 2 taken 461 times.
548 if (ctx->COLON()) {
178 87 structDefNode->hasInterfaces = true;
179
5/8
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 16 times.
✓ Branch 3 taken 87 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 87 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 87 times.
✗ Branch 10 not taken.
87 structDefNode->interfaceTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(structDefNode->hasTemplateTypes ? 1 : 0)));
180 }
181
3/4
✓ Branch 1 taken 548 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 1194 times.
✓ Branch 8 taken 548 times.
1742 for (SpiceParser::FieldContext *field : ctx->field())
182
3/6
✓ Branch 1 taken 1194 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1194 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1194 times.
✗ Branch 8 not taken.
1742 structDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field)));
183
184
2/4
✓ Branch 1 taken 548 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 548 times.
✗ Branch 5 not taken.
548 return concludeNode(structDefNode);
185 }
186
187 76 std::any ASTBuilder::visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) {
188 76 const auto interfaceDefNode = createNode<InterfaceDefNode>(ctx);
189
190 // Enrich
191
2/4
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 76 times.
✗ Branch 5 not taken.
76 interfaceDefNode->interfaceName = getIdentifier(ctx->TYPE_IDENTIFIER());
192 76 interfaceDefNode->typeId = resourceManager.getNextCustomTypeId();
193
194 // Visit children
195
2/2
✓ Branch 1 taken 53 times.
✓ Branch 2 taken 23 times.
76 if (ctx->topLevelDefAttr()) {
196
3/6
✓ Branch 1 taken 53 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 53 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 53 times.
✗ Branch 8 not taken.
53 interfaceDefNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
197
198 // Tell the attributes that they are struct attributes
199
2/2
✓ Branch 4 taken 53 times.
✓ Branch 5 taken 53 times.
106 for (AttrNode *attr : interfaceDefNode->attrs->attrLst->attributes)
200 53 attr->target = AttrNode::TARGET_INTERFACE;
201
202 // Check if a custom type id was set
203
7/18
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 53 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 53 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 53 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 53 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 53 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 53 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
159 if (interfaceDefNode->attrs && interfaceDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID))
204 53 interfaceDefNode->typeId =
205
2/4
✓ Branch 1 taken 53 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 53 times.
✗ Branch 5 not taken.
159 interfaceDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue;
206 }
207
2/2
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 16 times.
76 if (ctx->specifierLst())
208
3/6
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 60 times.
✗ Branch 8 not taken.
60 interfaceDefNode->specifierLst = std::any_cast<SpecifierLstNode *>(visit(ctx->specifierLst()));
209
2/2
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 20 times.
76 if (ctx->LESS()) {
210 56 interfaceDefNode->hasTemplateTypes = true;
211
3/6
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 56 times.
✗ Branch 8 not taken.
56 interfaceDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
212 }
213
3/4
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 174 times.
✓ Branch 8 taken 76 times.
250 for (SpiceParser::SignatureContext *signature : ctx->signature())
214
3/6
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 174 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 174 times.
✗ Branch 8 not taken.
250 interfaceDefNode->signatures.push_back(std::any_cast<SignatureNode *>(visit(signature)));
215
216
2/4
✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 76 times.
✗ Branch 5 not taken.
76 return concludeNode(interfaceDefNode);
217 }
218
219 41 std::any ASTBuilder::visitEnumDef(SpiceParser::EnumDefContext *ctx) {
220 41 const auto enumDefNode = createNode<EnumDefNode>(ctx);
221
222 // Enrich
223
2/4
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 41 times.
✗ Branch 5 not taken.
41 enumDefNode->enumName = getIdentifier(ctx->TYPE_IDENTIFIER());
224 41 enumDefNode->typeId = resourceManager.getNextCustomTypeId();
225
226 // Visit children
227
2/2
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 14 times.
41 if (ctx->specifierLst())
228
3/6
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 27 times.
✗ Branch 8 not taken.
27 enumDefNode->specifierLst = std::any_cast<SpecifierLstNode *>(visit(ctx->specifierLst()));
229
3/6
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 41 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 41 times.
✗ Branch 8 not taken.
41 enumDefNode->itemLst = std::any_cast<EnumItemLstNode *>(visit(ctx->enumItemLst()));
230
231 // Tell all items about the enum def
232
2/2
✓ Branch 4 taken 441 times.
✓ Branch 5 taken 41 times.
482 for (EnumItemNode *enumItem : enumDefNode->itemLst->items)
233 441 enumItem->enumDef = enumDefNode;
234
235
2/4
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 41 times.
✗ Branch 5 not taken.
41 return concludeNode(enumDefNode);
236 }
237
238 724 std::any ASTBuilder::visitGenericTypeDef(SpiceParser::GenericTypeDefContext *ctx) {
239 724 const auto genericTypeDefNode = createNode<GenericTypeDefNode>(ctx);
240
241 // Enrich
242
2/4
✓ Branch 1 taken 724 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 724 times.
✗ Branch 5 not taken.
724 genericTypeDefNode->typeName = getIdentifier(ctx->TYPE_IDENTIFIER());
243
244 // Visit children
245
3/6
✓ Branch 1 taken 724 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 724 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 724 times.
✗ Branch 8 not taken.
724 genericTypeDefNode->typeAltsLst = std::any_cast<TypeAltsLstNode *>(visit(ctx->typeAltsLst()));
246
247
2/4
✓ Branch 1 taken 724 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 724 times.
✗ Branch 5 not taken.
724 return concludeNode(genericTypeDefNode);
248 }
249
250 32 std::any ASTBuilder::visitAliasDef(SpiceParser::AliasDefContext *ctx) {
251 32 const auto aliasDefNode = createNode<AliasDefNode>(ctx);
252
253 // Enrich
254
2/4
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
32 aliasDefNode->aliasName = getIdentifier(ctx->TYPE_IDENTIFIER());
255
2/4
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
32 aliasDefNode->dataTypeString = ctx->dataType()->getText();
256 32 aliasDefNode->typeId = resourceManager.getNextCustomTypeId();
257
258 // Visit children
259
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 30 times.
32 if (ctx->specifierLst())
260
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
2 aliasDefNode->specifierLst = std::any_cast<SpecifierLstNode *>(visit(ctx->specifierLst()));
261
3/6
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 32 times.
✗ Branch 8 not taken.
32 aliasDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
262
263
2/4
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
32 return concludeNode(aliasDefNode);
264 }
265
266 739 std::any ASTBuilder::visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) {
267 739 const auto globalVarDefNode = createNode<GlobalVarDefNode>(ctx);
268
269 // Enrich
270
2/4
✓ Branch 1 taken 739 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 739 times.
✗ Branch 5 not taken.
739 globalVarDefNode->varName = getIdentifier(ctx->TYPE_IDENTIFIER());
271
272 // Visit children
273
3/6
✓ Branch 1 taken 739 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 739 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 739 times.
✗ Branch 8 not taken.
739 globalVarDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
274 739 globalVarDefNode->dataType->isGlobalType = true;
275
2/2
✓ Branch 1 taken 737 times.
✓ Branch 2 taken 2 times.
739 if (ctx->constant()) {
276 737 globalVarDefNode->hasValue = true;
277
3/6
✓ Branch 1 taken 737 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 737 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 737 times.
✗ Branch 8 not taken.
737 globalVarDefNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
278 }
279
280
2/4
✓ Branch 1 taken 739 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 739 times.
✗ Branch 5 not taken.
739 return concludeNode(globalVarDefNode);
281 }
282
283 703 std::any ASTBuilder::visitExtDecl(SpiceParser::ExtDeclContext *ctx) {
284 703 const auto extDeclNode = createNode<ExtDeclNode>(ctx);
285
286 // Enrich
287
6/10
✓ Branch 1 taken 703 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 583 times.
✓ Branch 4 taken 120 times.
✓ Branch 6 taken 583 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 120 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 703 times.
✗ Branch 13 not taken.
703 extDeclNode->extFunctionName = getIdentifier(ctx->IDENTIFIER() ? ctx->IDENTIFIER() : ctx->TYPE_IDENTIFIER());
288
289 // Visit children
290
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 702 times.
703 if (ctx->topLevelDefAttr()) {
291
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 extDeclNode->attrs = std::any_cast<TopLevelDefinitionAttrNode *>(visit(ctx->topLevelDefAttr()));
292
293 // Tell the attributes that they are ext decl attributes
294
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 for (AttrNode *attr : extDeclNode->attrs->attrLst->attributes)
295 1 attr->target = AttrNode::TARGET_EXT_DECL;
296 }
297
2/2
✓ Branch 1 taken 455 times.
✓ Branch 2 taken 248 times.
703 if (ctx->F()) {
298
3/6
✓ Branch 1 taken 455 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 455 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 455 times.
✗ Branch 8 not taken.
455 extDeclNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
299 455 extDeclNode->returnType->isReturnType = true;
300 }
301
2/2
✓ Branch 1 taken 679 times.
✓ Branch 2 taken 24 times.
703 if (ctx->typeLst()) {
302 679 extDeclNode->hasArgs = true;
303
3/6
✓ Branch 1 taken 679 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 679 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 679 times.
✗ Branch 8 not taken.
679 extDeclNode->argTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
304 }
305 703 extDeclNode->isVarArg = ctx->ELLIPSIS();
306
307
2/4
✓ Branch 1 taken 703 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 703 times.
✗ Branch 5 not taken.
703 return concludeNode(extDeclNode);
308 }
309
310 371 std::any ASTBuilder::visitImportDef(SpiceParser::ImportDefContext *ctx) {
311
1/2
✓ Branch 1 taken 371 times.
✗ Branch 2 not taken.
371 const auto importDefNode = createNode<ImportDefNode>(ctx);
312
313 // Extract path
314
2/4
✓ Branch 1 taken 371 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 371 times.
✗ Branch 5 not taken.
371 const std::string pathStr = ctx->STRING_LIT()->getText();
315
1/2
✓ Branch 2 taken 371 times.
✗ Branch 3 not taken.
371 importDefNode->importPath = pathStr.substr(1, pathStr.size() - 2);
316
317 // If no name is given, use the path as name
318
6/10
✓ Branch 1 taken 371 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 339 times.
✓ Branch 6 taken 32 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 32 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 339 times.
✗ Branch 13 not taken.
371 importDefNode->importName = ctx->AS() ? getIdentifier(ctx->IDENTIFIER()) : importDefNode->importPath;
319
320
2/4
✓ Branch 1 taken 371 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 371 times.
✗ Branch 5 not taken.
742 return concludeNode(importDefNode);
321 371 }
322
323 1808 std::any ASTBuilder::visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) {
324 1808 const auto unsafeBlockDefNode = createNode<UnsafeBlockNode>(ctx);
325
326 // Visit children
327
3/6
✓ Branch 1 taken 1808 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1808 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1808 times.
✗ Branch 8 not taken.
1808 unsafeBlockDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
328
329
2/4
✓ Branch 1 taken 1808 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1808 times.
✗ Branch 5 not taken.
1808 return concludeNode(unsafeBlockDefNode);
330 }
331
332 984 std::any ASTBuilder::visitForLoop(SpiceParser::ForLoopContext *ctx) {
333 984 const auto forLoopNode = createNode<ForLoopNode>(ctx);
334
335
2/4
✓ Branch 1 taken 984 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 984 times.
✗ Branch 5 not taken.
984 visit(ctx->forHead());
336
3/6
✓ Branch 1 taken 984 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 984 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 984 times.
✗ Branch 8 not taken.
984 forLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
337
338
2/4
✓ Branch 1 taken 984 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 984 times.
✗ Branch 5 not taken.
984 return concludeNode(forLoopNode);
339 }
340
341 984 std::any ASTBuilder::visitForHead(SpiceParser::ForHeadContext *ctx) {
342 984 auto forLoopNode = resumeForExpansion<ForLoopNode>();
343
344 // Visit children
345
3/6
✓ Branch 1 taken 984 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 984 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 984 times.
✗ Branch 8 not taken.
984 forLoopNode->initDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt()));
346
3/6
✓ Branch 1 taken 984 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 984 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 984 times.
✗ Branch 8 not taken.
984 forLoopNode->condAssign = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr(0)));
347
3/6
✓ Branch 1 taken 984 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 984 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 984 times.
✗ Branch 8 not taken.
984 forLoopNode->incAssign = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr(1)));
348
349
1/2
✓ Branch 1 taken 984 times.
✗ Branch 2 not taken.
984 return nullptr;
350 }
351
352 87 std::any ASTBuilder::visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) {
353 87 const auto foreachLoopNode = createNode<ForeachLoopNode>(ctx);
354
355 // Visit children
356
2/4
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 87 times.
✗ Branch 5 not taken.
87 visit(ctx->foreachHead());
357
3/6
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 87 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 87 times.
✗ Branch 8 not taken.
87 foreachLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
358
359 // Tell the foreach item that it is one
360 87 foreachLoopNode->itemVarDecl->isForEachItem = true;
361
362
2/4
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 87 times.
✗ Branch 5 not taken.
87 return concludeNode(foreachLoopNode);
363 }
364
365 87 std::any ASTBuilder::visitForeachHead(SpiceParser::ForeachHeadContext *ctx) {
366 87 auto foreachLoopNode = resumeForExpansion<ForeachLoopNode>();
367
368 // Visit children
369
3/4
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 81 times.
✓ Branch 6 taken 6 times.
87 if (ctx->declStmt().size() == 1) {
370
3/6
✓ Branch 1 taken 81 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 81 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 81 times.
✗ Branch 8 not taken.
81 foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0)));
371
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 } else if (ctx->declStmt().size() == 2) {
372
3/6
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
6 foreachLoopNode->idxVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0)));
373
3/6
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
6 foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(1)));
374 } else {
375 assert_fail("Invalid number of decl statements in foreach loop"); // GCOV_EXCL_LINE
376 }
377
3/6
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 87 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 87 times.
✗ Branch 8 not taken.
87 foreachLoopNode->iteratorAssign = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
378
379
1/2
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
87 return nullptr;
380 }
381
382 398 std::any ASTBuilder::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) {
383 398 const auto whileLoopNode = createNode<WhileLoopNode>(ctx);
384
385 // Visit children
386
3/6
✓ Branch 1 taken 398 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 398 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 398 times.
✗ Branch 8 not taken.
398 whileLoopNode->condition = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
387
3/6
✓ Branch 1 taken 398 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 398 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 398 times.
✗ Branch 8 not taken.
398 whileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
388
389
2/4
✓ Branch 1 taken 398 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 398 times.
✗ Branch 5 not taken.
398 return concludeNode(whileLoopNode);
390 }
391
392 9 std::any ASTBuilder::visitDoWhileLoop(SpiceParser::DoWhileLoopContext *ctx) {
393 9 const auto doWhileLoopNode = createNode<DoWhileLoopNode>(ctx);
394
395 // Visit children
396
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
9 doWhileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
397
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
9 doWhileLoopNode->condition = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
398
399
2/4
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
9 return concludeNode(doWhileLoopNode);
400 }
401
402 2918 std::any ASTBuilder::visitIfStmt(SpiceParser::IfStmtContext *ctx) {
403 2918 const auto ifStmtNode = createNode<IfStmtNode>(ctx);
404
405 // Visit children
406
3/6
✓ Branch 1 taken 2918 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2918 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2918 times.
✗ Branch 8 not taken.
2918 ifStmtNode->condition = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
407
3/6
✓ Branch 1 taken 2918 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2918 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2918 times.
✗ Branch 8 not taken.
2918 ifStmtNode->thenBody = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
408
2/2
✓ Branch 1 taken 168 times.
✓ Branch 2 taken 2750 times.
2918 if (ctx->elseStmt())
409
3/6
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 168 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 168 times.
✗ Branch 8 not taken.
168 ifStmtNode->elseStmt = std::any_cast<ElseStmtNode *>(visit(ctx->elseStmt()));
410
411
2/4
✓ Branch 1 taken 2918 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2918 times.
✗ Branch 5 not taken.
2918 return concludeNode(ifStmtNode);
412 }
413
414 168 std::any ASTBuilder::visitElseStmt(SpiceParser::ElseStmtContext *ctx) {
415 168 const auto elseStmtNode = createNode<ElseStmtNode>(ctx);
416
417 // Visit children
418
2/2
✓ Branch 1 taken 51 times.
✓ Branch 2 taken 117 times.
168 if (ctx->ifStmt()) {
419 51 elseStmtNode->isElseIf = true;
420
3/6
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 51 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 51 times.
✗ Branch 8 not taken.
51 elseStmtNode->ifStmt = std::any_cast<IfStmtNode *>(visit(ctx->ifStmt()));
421 } else {
422
3/6
✓ Branch 1 taken 117 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 117 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 117 times.
✗ Branch 8 not taken.
117 elseStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
423 }
424
425
2/4
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 168 times.
✗ Branch 5 not taken.
168 return concludeNode(elseStmtNode);
426 }
427
428 8 std::any ASTBuilder::visitSwitchStmt(SpiceParser::SwitchStmtContext *ctx) {
429 8 const auto switchStmtNode = createNode<SwitchStmtNode>(ctx);
430
431 // Visit children
432
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
8 switchStmtNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
433
3/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 28 times.
✓ Branch 8 taken 8 times.
36 for (SpiceParser::CaseBranchContext *caseBranch : ctx->caseBranch())
434
3/6
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 28 times.
✗ Branch 8 not taken.
36 switchStmtNode->caseBranches.push_back(std::any_cast<CaseBranchNode *>(visit(caseBranch)));
435
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5 times.
8 if (ctx->defaultBranch()) {
436 3 switchStmtNode->hasDefaultBranch = true;
437
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 switchStmtNode->defaultBranch = std::any_cast<DefaultBranchNode *>(visit(ctx->defaultBranch()));
438 }
439
440
2/4
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
8 return concludeNode(switchStmtNode);
441 }
442
443 28 std::any ASTBuilder::visitCaseBranch(SpiceParser::CaseBranchContext *ctx) {
444 28 const auto caseBranchNode = createNode<CaseBranchNode>(ctx);
445
446 // Visit children
447
3/4
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 28 times.
✓ Branch 8 taken 28 times.
56 for (SpiceParser::CaseConstantContext *caseConstant : ctx->caseConstant())
448
3/6
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 28 times.
✗ Branch 8 not taken.
56 caseBranchNode->caseConstants.push_back(std::any_cast<CaseConstantNode *>(visit(caseConstant)));
449
3/6
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 28 times.
✗ Branch 8 not taken.
28 caseBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
450
451
2/4
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
28 return concludeNode(caseBranchNode);
452 }
453
454 3 std::any ASTBuilder::visitDefaultBranch(SpiceParser::DefaultBranchContext *ctx) {
455 3 const auto defaultBranchNode = createNode<DefaultBranchNode>(ctx);
456
457 // Visit children
458
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 defaultBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
459
460
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 return concludeNode(defaultBranchNode);
461 }
462
463 13 std::any ASTBuilder::visitAnonymousBlockStmt(SpiceParser::AnonymousBlockStmtContext *ctx) {
464 13 const auto anonymousBlockStmtNode = createNode<AnonymousBlockStmtNode>(ctx);
465
466 // Visit children
467
3/6
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 13 times.
✗ Branch 8 not taken.
13 anonymousBlockStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
468
469
2/4
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
13 return concludeNode(anonymousBlockStmtNode);
470 }
471
472 13740 std::any ASTBuilder::visitStmtLst(SpiceParser::StmtLstContext *ctx) {
473 13740 const auto stmtLstNode = createNode<StmtLstNode>(ctx);
474
475 // Enrich
476
2/4
✓ Branch 1 taken 13740 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 13740 times.
✗ Branch 5 not taken.
13740 stmtLstNode->closingBraceCodeLoc = CodeLoc(ctx->getStop(), sourceFile);
477
478 // Visit children
479
2/2
✓ Branch 5 taken 53717 times.
✓ Branch 6 taken 13736 times.
67453 for (ParserRuleContext::ParseTree *stmt : ctx->children) {
480
3/4
✓ Branch 0 taken 53717 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19459 times.
✓ Branch 3 taken 34258 times.
53717 if (auto *stmtCtx = dynamic_cast<SpiceParser::StmtContext *>(stmt))
481
4/6
✓ Branch 1 taken 19455 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 19455 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 19455 times.
✗ Branch 8 not taken.
19459 stmtLstNode->statements.push_back(std::any_cast<StmtNode *>(visit(stmtCtx)));
482
3/4
✓ Branch 0 taken 34258 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 984 times.
✓ Branch 3 taken 33274 times.
34258 else if (auto *forLoopCtx = dynamic_cast<SpiceParser::ForLoopContext *>(stmt))
483
3/6
✓ Branch 1 taken 984 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 984 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 984 times.
✗ Branch 8 not taken.
984 stmtLstNode->statements.push_back(std::any_cast<ForLoopNode *>(visit(forLoopCtx)));
484
3/4
✓ Branch 0 taken 33274 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 87 times.
✓ Branch 3 taken 33187 times.
33274 else if (auto *foreachLoopCtx = dynamic_cast<SpiceParser::ForeachLoopContext *>(stmt))
485
3/6
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 87 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 87 times.
✗ Branch 8 not taken.
87 stmtLstNode->statements.push_back(std::any_cast<ForeachLoopNode *>(visit(foreachLoopCtx)));
486
3/4
✓ Branch 0 taken 33187 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 398 times.
✓ Branch 3 taken 32789 times.
33187 else if (auto *whileLoopCtx = dynamic_cast<SpiceParser::WhileLoopContext *>(stmt))
487
3/6
✓ Branch 1 taken 398 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 398 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 398 times.
✗ Branch 8 not taken.
398 stmtLstNode->statements.push_back(std::any_cast<WhileLoopNode *>(visit(whileLoopCtx)));
488
3/4
✓ Branch 0 taken 32789 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 32780 times.
32789 else if (auto *doWhileLoopCtx = dynamic_cast<SpiceParser::DoWhileLoopContext *>(stmt))
489
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
9 stmtLstNode->statements.push_back(std::any_cast<DoWhileLoopNode *>(visit(doWhileLoopCtx)));
490
3/4
✓ Branch 0 taken 32780 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2867 times.
✓ Branch 3 taken 29913 times.
32780 else if (auto *ifStmtCtx = dynamic_cast<SpiceParser::IfStmtContext *>(stmt))
491
3/6
✓ Branch 1 taken 2867 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2867 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2867 times.
✗ Branch 8 not taken.
2867 stmtLstNode->statements.push_back(std::any_cast<IfStmtNode *>(visit(ifStmtCtx)));
492
3/4
✓ Branch 0 taken 29913 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 29905 times.
29913 else if (auto *switchStmtCtx = dynamic_cast<SpiceParser::SwitchStmtContext *>(stmt))
493
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
8 stmtLstNode->statements.push_back(std::any_cast<SwitchStmtNode *>(visit(switchStmtCtx)));
494
3/4
✓ Branch 0 taken 29905 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 608 times.
✓ Branch 3 taken 29297 times.
29905 else if (auto *assetStmtCtx = dynamic_cast<SpiceParser::AssertStmtContext *>(stmt))
495
3/6
✓ Branch 1 taken 608 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 608 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 608 times.
✗ Branch 8 not taken.
608 stmtLstNode->statements.push_back(std::any_cast<AssertStmtNode *>(visit(assetStmtCtx)));
496
3/4
✓ Branch 0 taken 29297 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1808 times.
✓ Branch 3 taken 27489 times.
29297 else if (auto *unsafeBlockCtx = dynamic_cast<SpiceParser::UnsafeBlockContext *>(stmt))
497
3/6
✓ Branch 1 taken 1808 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1808 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1808 times.
✗ Branch 8 not taken.
1808 stmtLstNode->statements.push_back(std::any_cast<UnsafeBlockNode *>(visit(unsafeBlockCtx)));
498
3/4
✓ Branch 0 taken 27489 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 27476 times.
27489 else if (auto *anonymousScopeCtx = dynamic_cast<SpiceParser::AnonymousBlockStmtContext *>(stmt))
499
3/6
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 13 times.
✗ Branch 8 not taken.
13 stmtLstNode->statements.push_back(std::any_cast<AnonymousBlockStmtNode *>(visit(anonymousScopeCtx)));
500 else
501 assert(dynamic_cast<TerminalNode *>(stmt) != nullptr); // GCOV_EXCL_LINE
502 }
503
504
2/4
✓ Branch 1 taken 13736 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 13736 times.
✗ Branch 5 not taken.
13736 return concludeNode(stmtLstNode);
505 }
506
507 4411 std::any ASTBuilder::visitTypeLst(SpiceParser::TypeLstContext *ctx) {
508 4411 const auto typeLstNode = createNode<TypeLstNode>(ctx);
509
510 // Visit children
511
3/4
✓ Branch 1 taken 4411 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 5993 times.
✓ Branch 8 taken 4411 times.
10404 for (SpiceParser::DataTypeContext *dataType : ctx->dataType())
512
3/6
✓ Branch 1 taken 5993 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5993 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5993 times.
✗ Branch 8 not taken.
10404 typeLstNode->dataTypes.push_back(std::any_cast<DataTypeNode *>(visit(dataType)));
513
514
2/4
✓ Branch 1 taken 4411 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4411 times.
✗ Branch 5 not taken.
4411 return concludeNode(typeLstNode);
515 }
516
517 724 std::any ASTBuilder::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ctx) {
518 724 const auto typeAltsLstNode = createNode<TypeAltsLstNode>(ctx);
519
520 // Visit children
521
3/4
✓ Branch 1 taken 724 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 1401 times.
✓ Branch 8 taken 724 times.
2125 for (SpiceParser::DataTypeContext *dataType : ctx->dataType())
522
3/6
✓ Branch 1 taken 1401 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1401 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1401 times.
✗ Branch 8 not taken.
2125 typeAltsLstNode->dataTypes.push_back(std::any_cast<DataTypeNode *>(visit(dataType)));
523
524
2/4
✓ Branch 1 taken 724 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 724 times.
✗ Branch 5 not taken.
724 return concludeNode(typeAltsLstNode);
525 }
526
527 4937 std::any ASTBuilder::visitParamLst(SpiceParser::ParamLstContext *ctx) {
528 4937 const auto paramLstNode = createNode<ParamLstNode>(ctx);
529
530 // Visit children
531
3/4
✓ Branch 1 taken 4937 times.
✗ Branch 2 not taken.
✓ Branch 8 taken 7752 times.
✓ Branch 9 taken 4937 times.
12689 for (SpiceParser::DeclStmtContext *declStmt : ctx->declStmt()) {
532
2/4
✓ Branch 1 taken 7752 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7752 times.
✗ Branch 5 not taken.
7752 auto param = std::any_cast<DeclStmtNode *>(visit(declStmt));
533 7752 param->isFctParam = true;
534 7752 param->dataType->isParamType = true;
535
1/2
✓ Branch 1 taken 7752 times.
✗ Branch 2 not taken.
7752 paramLstNode->params.push_back(param);
536 4937 }
537
538
2/4
✓ Branch 1 taken 4937 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4937 times.
✗ Branch 5 not taken.
4937 return concludeNode(paramLstNode);
539 }
540
541 7529 std::any ASTBuilder::visitArgLst(SpiceParser::ArgLstContext *ctx) {
542 7529 const auto argLstNode = createNode<ArgLstNode>(ctx);
543
544 // Visit children
545
3/4
✓ Branch 1 taken 7529 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 10963 times.
✓ Branch 8 taken 7529 times.
18492 for (SpiceParser::AssignExprContext *assignExpr : ctx->assignExpr())
546
3/6
✓ Branch 1 taken 10963 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10963 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10963 times.
✗ Branch 8 not taken.
18492 argLstNode->args.push_back(std::any_cast<AssignExprNode *>(visit(assignExpr)));
547
548
2/4
✓ Branch 1 taken 7529 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7529 times.
✗ Branch 5 not taken.
7529 return concludeNode(argLstNode);
549 }
550
551 41 std::any ASTBuilder::visitEnumItemLst(SpiceParser::EnumItemLstContext *ctx) {
552 41 const auto enumItemLstNode = createNode<EnumItemLstNode>(ctx);
553
554 // Visit children
555
3/4
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 441 times.
✓ Branch 8 taken 41 times.
482 for (SpiceParser::EnumItemContext *enumItem : ctx->enumItem())
556
3/6
✓ Branch 1 taken 441 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 441 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 441 times.
✗ Branch 8 not taken.
482 enumItemLstNode->items.push_back(std::any_cast<EnumItemNode *>(visit(enumItem)));
557
558
2/4
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 41 times.
✗ Branch 5 not taken.
41 return concludeNode(enumItemLstNode);
559 }
560
561 441 std::any ASTBuilder::visitEnumItem(SpiceParser::EnumItemContext *ctx) {
562 441 const auto enumItemNode = createNode<EnumItemNode>(ctx);
563
564 // Enrich
565
2/4
✓ Branch 1 taken 441 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 441 times.
✗ Branch 5 not taken.
441 enumItemNode->itemName = getIdentifier(ctx->TYPE_IDENTIFIER());
566
2/2
✓ Branch 1 taken 263 times.
✓ Branch 2 taken 178 times.
441 if (ctx->ASSIGN()) {
567 263 enumItemNode->itemValue = parseInt(ctx->INT_LIT());
568 263 enumItemNode->hasValue = true;
569 }
570
571
2/4
✓ Branch 1 taken 441 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 441 times.
✗ Branch 5 not taken.
441 return concludeNode(enumItemNode);
572 }
573
574 1194 std::any ASTBuilder::visitField(SpiceParser::FieldContext *ctx) {
575 1194 const auto fieldNode = createNode<FieldNode>(ctx);
576
577 // Enrich
578
2/4
✓ Branch 1 taken 1194 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1194 times.
✗ Branch 5 not taken.
1194 fieldNode->fieldName = getIdentifier(ctx->IDENTIFIER());
579
580 // Visit children
581
3/6
✓ Branch 1 taken 1194 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1194 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1194 times.
✗ Branch 8 not taken.
1194 fieldNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
582 1194 fieldNode->dataType->setFieldTypeRecursive();
583
2/2
✓ Branch 1 taken 151 times.
✓ Branch 2 taken 1043 times.
1194 if (ctx->ternaryExpr())
584
3/6
✓ Branch 1 taken 151 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 151 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 151 times.
✗ Branch 8 not taken.
151 fieldNode->defaultValue = std::any_cast<TernaryExprNode *>(visit(ctx->ternaryExpr()));
585
586
2/4
✓ Branch 1 taken 1194 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1194 times.
✗ Branch 5 not taken.
1194 return concludeNode(fieldNode);
587 }
588
589 174 std::any ASTBuilder::visitSignature(SpiceParser::SignatureContext *ctx) {
590 174 const auto signatureNode = createNode<SignatureNode>(ctx);
591
592 // Extract method name
593
2/4
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 174 times.
✗ Branch 5 not taken.
174 signatureNode->methodName = getIdentifier(ctx->IDENTIFIER());
594
595 // Visit children
596
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 166 times.
174 if (ctx->specifierLst()) {
597
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
8 signatureNode->specifierLst = std::any_cast<SpecifierLstNode *>(visit(ctx->specifierLst()));
598 }
599
2/2
✓ Branch 1 taken 134 times.
✓ Branch 2 taken 40 times.
174 if (ctx->F()) {
600 134 signatureNode->hasReturnType = true;
601 134 signatureNode->signatureType = SignatureNode::TYPE_FUNCTION;
602 134 signatureNode->signatureSpecifiers = TypeSpecifiers::of(TY_FUNCTION);
603
3/6
✓ Branch 1 taken 134 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 134 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 134 times.
✗ Branch 8 not taken.
134 signatureNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
604 } else {
605 40 signatureNode->signatureType = SignatureNode::TYPE_PROCEDURE;
606 40 signatureNode->signatureSpecifiers = TypeSpecifiers::of(TY_PROCEDURE);
607 }
608
10/16
✓ Branch 1 taken 134 times.
✓ Branch 2 taken 40 times.
✓ Branch 4 taken 134 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 40 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 40 times.
✓ Branch 12 taken 134 times.
✓ Branch 14 taken 134 times.
✓ Branch 15 taken 40 times.
✓ Branch 17 taken 91 times.
✓ Branch 18 taken 83 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
174 if (ctx->F() ? ctx->LESS().size() == 2 : ctx->LESS().size() == 1) {
609 91 signatureNode->hasTemplateTypes = true;
610
3/6
✓ Branch 1 taken 91 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 91 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 91 times.
✗ Branch 8 not taken.
91 signatureNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0)));
611 }
612
13/20
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 168 times.
✓ Branch 5 taken 6 times.
✓ Branch 7 taken 168 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 92 times.
✓ Branch 11 taken 76 times.
✓ Branch 12 taken 7 times.
✓ Branch 13 taken 85 times.
✓ Branch 14 taken 168 times.
✓ Branch 15 taken 6 times.
✓ Branch 17 taken 174 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 13 times.
✓ Branch 21 taken 161 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
174 if (ctx->typeLst().size() == 2 || (ctx->typeLst().size() == 1 && !signatureNode->hasTemplateTypes)) {
613 13 signatureNode->hasParams = true;
614
5/8
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 13 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 13 times.
✗ Branch 10 not taken.
13 signatureNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(signatureNode->hasTemplateTypes ? 1 : 0)));
615 }
616
617
2/4
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 174 times.
✗ Branch 5 not taken.
174 return concludeNode(signatureNode);
618 }
619
620 19459 std::any ASTBuilder::visitStmt(SpiceParser::StmtContext *ctx) {
621
2/2
✓ Branch 1 taken 3845 times.
✓ Branch 2 taken 15614 times.
19459 if (ctx->declStmt())
622
5/8
✓ Branch 1 taken 3845 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3841 times.
✓ Branch 5 taken 4 times.
✓ Branch 7 taken 3841 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 3841 times.
✗ Branch 11 not taken.
3845 return static_cast<StmtNode *>(std::any_cast<DeclStmtNode *>(visit(ctx->declStmt())));
623
2/2
✓ Branch 1 taken 9727 times.
✓ Branch 2 taken 5887 times.
15614 if (ctx->exprStmt())
624
4/8
✓ Branch 1 taken 9727 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9727 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9727 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 9727 times.
✗ Branch 11 not taken.
9727 return static_cast<StmtNode *>(std::any_cast<ExprStmtNode *>(visit(ctx->exprStmt())));
625
2/2
✓ Branch 1 taken 5612 times.
✓ Branch 2 taken 275 times.
5887 if (ctx->returnStmt())
626
4/8
✓ Branch 1 taken 5612 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5612 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5612 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5612 times.
✗ Branch 11 not taken.
5612 return static_cast<StmtNode *>(std::any_cast<ReturnStmtNode *>(visit(ctx->returnStmt())));
627
2/2
✓ Branch 1 taken 98 times.
✓ Branch 2 taken 177 times.
275 if (ctx->breakStmt())
628
4/8
✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 98 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 98 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 98 times.
✗ Branch 11 not taken.
98 return static_cast<StmtNode *>(std::any_cast<BreakStmtNode *>(visit(ctx->breakStmt())));
629
2/2
✓ Branch 1 taken 171 times.
✓ Branch 2 taken 6 times.
177 if (ctx->continueStmt())
630
4/8
✓ Branch 1 taken 171 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 171 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 171 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 171 times.
✗ Branch 11 not taken.
171 return static_cast<StmtNode *>(std::any_cast<ContinueStmtNode *>(visit(ctx->continueStmt())));
631
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 if (ctx->fallthroughStmt())
632
4/8
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
6 return static_cast<StmtNode *>(std::any_cast<FallthroughStmtNode *>(visit(ctx->fallthroughStmt())));
633 assert_fail("Unknown statement type"); // GCOV_EXCL_LINE
634 return nullptr; // GCOV_EXCL_LINE
635 }
636
637 12674 std::any ASTBuilder::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) {
638 12674 const auto declStmtNode = createNode<DeclStmtNode>(ctx);
639
640 // Enrich
641
3/4
✓ Branch 1 taken 12674 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12673 times.
✓ Branch 5 taken 1 times.
12674 declStmtNode->varName = getIdentifier(ctx->IDENTIFIER());
642
643 // Visit children
644
4/6
✓ Branch 1 taken 12673 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12672 times.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 12672 times.
✗ Branch 8 not taken.
12673 declStmtNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
645
2/2
✓ Branch 1 taken 5372 times.
✓ Branch 2 taken 7300 times.
12672 if (ctx->assignExpr()) {
646 5372 declStmtNode->hasAssignment = true;
647
4/6
✓ Branch 1 taken 5372 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5370 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 5370 times.
✗ Branch 8 not taken.
5372 declStmtNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
648 }
649
650
2/4
✓ Branch 1 taken 12670 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12670 times.
✗ Branch 5 not taken.
12670 return concludeNode(declStmtNode);
651 }
652
653 9727 std::any ASTBuilder::visitExprStmt(SpiceParser::ExprStmtContext *ctx) {
654 9727 const auto exprStmtNode = createNode<ExprStmtNode>(ctx);
655
656 // Enrich
657
3/6
✓ Branch 1 taken 9727 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9727 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9727 times.
✗ Branch 8 not taken.
9727 exprStmtNode->expr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
658
659
2/4
✓ Branch 1 taken 9727 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9727 times.
✗ Branch 5 not taken.
9727 return concludeNode(exprStmtNode);
660 }
661
662 19651 std::any ASTBuilder::visitSpecifierLst(SpiceParser::SpecifierLstContext *ctx) {
663 19651 const auto specifierLstNode = createNode<SpecifierLstNode>(ctx);
664
665 // Visit children
666 19651 bool seenSignedOrUnsigned = false;
667
3/4
✓ Branch 1 taken 19651 times.
✗ Branch 2 not taken.
✓ Branch 8 taken 22996 times.
✓ Branch 9 taken 19650 times.
42646 for (SpiceParser::SpecifierContext *specifierCtx : ctx->specifier()) {
668
2/4
✓ Branch 1 taken 22996 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22996 times.
✗ Branch 5 not taken.
22996 auto specifier = std::any_cast<SpecifierNode *>(visit(specifierCtx));
669
1/2
✓ Branch 1 taken 22996 times.
✗ Branch 2 not taken.
22996 specifierLstNode->specifiers.push_back(specifier);
670
671 // Check if we have both, signed and unsigned specifier
672
4/4
✓ Branch 0 taken 22993 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 16964 times.
✓ Branch 3 taken 6029 times.
22996 if (specifier->type != SpecifierNode::TY_SIGNED && specifier->type != SpecifierNode::TY_UNSIGNED)
673 16964 continue;
674
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6031 times.
6032 if (seenSignedOrUnsigned)
675
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
3 throw ParserError(specifier->codeLoc, INVALID_SPECIFIER_COMBINATION, "A variable can not be signed and unsigned");
676 6031 seenSignedOrUnsigned = true;
677 19651 }
678
679
2/4
✓ Branch 1 taken 19650 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19650 times.
✗ Branch 5 not taken.
19650 return concludeNode(specifierLstNode);
680 }
681
682 22996 std::any ASTBuilder::visitSpecifier(SpiceParser::SpecifierContext *ctx) {
683 22996 const auto specifierNode = createNode<SpecifierNode>(ctx);
684
685
3/4
✓ Branch 3 taken 22996 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 22996 times.
✓ Branch 8 taken 22996 times.
45992 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
686 22996 const auto token = spice_pointer_cast<TerminalNode *>(subTree);
687
2/4
✓ Branch 1 taken 22996 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22996 times.
✗ Branch 5 not taken.
22996 const size_t symbolType = token->getSymbol()->getType();
688
2/2
✓ Branch 0 taken 5506 times.
✓ Branch 1 taken 17490 times.
22996 if (symbolType == SpiceParser::CONST)
689 5506 specifierNode->type = SpecifierNode::TY_CONST;
690
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 17487 times.
17490 else if (symbolType == SpiceParser::SIGNED)
691 3 specifierNode->type = SpecifierNode::TY_SIGNED;
692
2/2
✓ Branch 0 taken 6029 times.
✓ Branch 1 taken 11458 times.
17487 else if (symbolType == SpiceParser::UNSIGNED)
693 6029 specifierNode->type = SpecifierNode::TY_UNSIGNED;
694
2/2
✓ Branch 0 taken 1478 times.
✓ Branch 1 taken 9980 times.
11458 else if (symbolType == SpiceParser::INLINE)
695 1478 specifierNode->type = SpecifierNode::TY_INLINE;
696
2/2
✓ Branch 0 taken 7439 times.
✓ Branch 1 taken 2541 times.
9980 else if (symbolType == SpiceParser::PUBLIC)
697 7439 specifierNode->type = SpecifierNode::TY_PUBLIC;
698
2/2
✓ Branch 0 taken 2534 times.
✓ Branch 1 taken 7 times.
2541 else if (symbolType == SpiceParser::HEAP)
699 2534 specifierNode->type = SpecifierNode::TY_HEAP;
700
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 else if (symbolType == SpiceParser::COMPOSE)
701 7 specifierNode->type = SpecifierNode::TY_COMPOSITION;
702 else
703 assert_fail("Unknown specifier type"); // GCOV_EXCL_LINE
704 }
705
706
2/4
✓ Branch 1 taken 22996 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22996 times.
✗ Branch 5 not taken.
22996 return concludeNode(specifierNode);
707 }
708
709 278 std::any ASTBuilder::visitModAttr(SpiceParser::ModAttrContext *ctx) {
710 278 const auto modAttrNode = createNode<ModAttrNode>(ctx);
711
712 // Visit children
713
4/6
✓ Branch 1 taken 278 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 277 times.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 277 times.
✗ Branch 8 not taken.
278 modAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
714
715 // Tell the attributes that they are module attributes
716
2/2
✓ Branch 4 taken 488 times.
✓ Branch 5 taken 277 times.
765 for (AttrNode *attr : modAttrNode->attrLst->attributes)
717 488 attr->target = AttrNode::TARGET_MODULE;
718
719
2/4
✓ Branch 1 taken 277 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 277 times.
✗ Branch 5 not taken.
277 return concludeNode(modAttrNode);
720 }
721
722 118 std::any ASTBuilder::visitTopLevelDefAttr(SpiceParser::TopLevelDefAttrContext *ctx) {
723 118 const auto fctAttrNode = createNode<TopLevelDefinitionAttrNode>(ctx);
724
725 // Visit children
726
3/6
✓ Branch 1 taken 118 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 118 times.
✗ Branch 8 not taken.
118 fctAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
727
728
2/4
✓ Branch 1 taken 118 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 118 times.
✗ Branch 5 not taken.
118 return concludeNode(fctAttrNode);
729 }
730
731 16 std::any ASTBuilder::visitLambdaAttr(SpiceParser::LambdaAttrContext *ctx) {
732 16 const auto lambdaAttrNode = createNode<LambdaAttrNode>(ctx);
733
734 // Visit children
735
3/6
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
16 lambdaAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst()));
736
737 // Tell the attributes that they are module attributes
738
2/2
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 16 times.
32 for (AttrNode *attr : lambdaAttrNode->attrLst->attributes)
739 16 attr->target = AttrNode::TARGET_LAMBDA;
740
741
2/4
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
16 return concludeNode(lambdaAttrNode);
742 }
743
744 412 std::any ASTBuilder::visitAttrLst(SpiceParser::AttrLstContext *ctx) {
745 412 const auto attrLstNode = createNode<AttrLstNode>(ctx);
746
747 // Visit children
748
3/4
✓ Branch 1 taken 412 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 627 times.
✓ Branch 8 taken 411 times.
1038 for (SpiceParser::AttrContext *attr : ctx->attr())
749
4/6
✓ Branch 1 taken 626 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 626 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 626 times.
✗ Branch 8 not taken.
1038 attrLstNode->attributes.push_back(std::any_cast<AttrNode *>(visit(attr)));
750
751
2/4
✓ Branch 1 taken 411 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 411 times.
✗ Branch 5 not taken.
411 return concludeNode(attrLstNode);
752 }
753
754 627 std::any ASTBuilder::visitAttr(SpiceParser::AttrContext *ctx) {
755 627 const auto attrNode = createNode<AttrNode>(ctx);
756
757 // Extract key
758
3/4
✓ Branch 1 taken 627 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 1836 times.
✓ Branch 8 taken 627 times.
2463 for (const TerminalNode *keyFragment : ctx->IDENTIFIER()) {
759
2/2
✓ Branch 1 taken 1209 times.
✓ Branch 2 taken 627 times.
1836 if (!attrNode->key.empty())
760
1/2
✓ Branch 1 taken 1209 times.
✗ Branch 2 not taken.
1209 attrNode->key += MEMBER_ACCESS_TOKEN;
761
3/6
✓ Branch 1 taken 1836 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1836 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1836 times.
✗ Branch 8 not taken.
1836 attrNode->key += keyFragment->getSymbol()->getText();
762 627 }
763
764 // Visit children
765
2/2
✓ Branch 1 taken 599 times.
✓ Branch 2 taken 28 times.
627 if (ctx->constant()) {
766
3/6
✓ Branch 1 taken 599 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 599 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 599 times.
✗ Branch 8 not taken.
599 attrNode->value = std::any_cast<ConstantNode *>(visit(ctx->constant()));
767
768
2/2
✓ Branch 2 taken 217 times.
✓ Branch 3 taken 382 times.
599 if (ctx->constant()->STRING_LIT())
769 217 attrNode->type = AttrNode::TYPE_STRING;
770
2/2
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 328 times.
382 else if (ctx->constant()->INT_LIT())
771 54 attrNode->type = AttrNode::TYPE_INT;
772
6/6
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 324 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 327 times.
✓ Branch 9 taken 1 times.
328 else if (ctx->constant()->TRUE() || ctx->constant()->FALSE())
773 327 attrNode->type = AttrNode::TYPE_BOOL;
774 else
775
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
3 throw ParserError(attrNode->value->codeLoc, INVALID_ATTR_VALUE_TYPE, "Invalid attribute value type");
776 } else {
777 // If no value is given, use the bool type
778 28 attrNode->type = AttrNode::TYPE_BOOL;
779 }
780
781
2/4
✓ Branch 1 taken 626 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 626 times.
✗ Branch 5 not taken.
626 return concludeNode(attrNode);
782 }
783
784 28 std::any ASTBuilder::visitCaseConstant(SpiceParser::CaseConstantContext *ctx) {
785 28 const auto caseConstantNode = createNode<CaseConstantNode>(ctx);
786
787 // Visit children
788
2/2
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 10 times.
28 if (ctx->constant()) {
789
3/6
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
18 caseConstantNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
790
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
10 } else if (!ctx->TYPE_IDENTIFIER().empty()) {
791
2/2
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 10 times.
38 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
792
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (!terminal)
794 continue;
795
796
3/6
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 28 times.
28 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
797 const std::string fragment = getIdentifier(terminal);
798 caseConstantNode->identifierFragments.push_back(fragment);
799 if (!caseConstantNode->fqIdentifier.empty())
800 caseConstantNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
801 caseConstantNode->fqIdentifier += fragment;
802
4/6
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 28 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 19 times.
✓ Branch 8 taken 9 times.
28 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
803
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 const std::string fragment = getIdentifier(terminal);
804
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 caseConstantNode->identifierFragments.push_back(fragment);
805
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 10 times.
19 if (!caseConstantNode->fqIdentifier.empty())
806
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 caseConstantNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
807
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 caseConstantNode->fqIdentifier += fragment;
808 19 }
809 }
810 } else {
811 assert_fail("Unknown case constant type"); // GCOV_EXCL_LINE
812 }
813
814
2/4
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
28 return concludeNode(caseConstantNode);
815 }
816
817 5612 std::any ASTBuilder::visitReturnStmt(SpiceParser::ReturnStmtContext *ctx) {
818 5612 const auto returnStmtNode = createNode<ReturnStmtNode>(ctx);
819
820 // Visit children
821
2/2
✓ Branch 1 taken 5439 times.
✓ Branch 2 taken 173 times.
5612 if (ctx->assignExpr()) {
822 5439 returnStmtNode->hasReturnValue = true;
823
3/6
✓ Branch 1 taken 5439 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5439 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5439 times.
✗ Branch 8 not taken.
5439 returnStmtNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
824 }
825
826
2/4
✓ Branch 1 taken 5612 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5612 times.
✗ Branch 5 not taken.
5612 return concludeNode(returnStmtNode);
827 }
828
829 98 std::any ASTBuilder::visitBreakStmt(SpiceParser::BreakStmtContext *ctx) {
830 98 const auto breakStmtNode = createNode<BreakStmtNode>(ctx);
831
832 // Extract number of breaks
833
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 92 times.
98 if (ctx->INT_LIT())
834
3/6
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
6 breakStmtNode->breakTimes = std::stoi(ctx->INT_LIT()->toString());
835
836 // Visit children
837
1/2
✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
98 visitChildren(ctx);
838
839
2/4
✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 98 times.
✗ Branch 5 not taken.
98 return concludeNode(breakStmtNode);
840 }
841
842 171 std::any ASTBuilder::visitContinueStmt(SpiceParser::ContinueStmtContext *ctx) {
843 171 const auto continueStmtNode = createNode<ContinueStmtNode>(ctx);
844
845 // Extract number of continues
846
2/2
✓ Branch 1 taken 170 times.
✓ Branch 2 taken 1 times.
171 if (ctx->INT_LIT())
847
3/6
✓ Branch 1 taken 170 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 170 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 170 times.
✗ Branch 8 not taken.
170 continueStmtNode->continueTimes = std::stoi(ctx->INT_LIT()->toString());
848
849 // Visit children
850
1/2
✓ Branch 1 taken 171 times.
✗ Branch 2 not taken.
171 visitChildren(ctx);
851
852
2/4
✓ Branch 1 taken 171 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 171 times.
✗ Branch 5 not taken.
171 return concludeNode(continueStmtNode);
853 }
854
855 6 std::any ASTBuilder::visitFallthroughStmt(SpiceParser::FallthroughStmtContext *ctx) {
856 6 const auto fallthroughStmtNode = createNode<FallthroughStmtNode>(ctx);
857
858 // Visit children
859
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 visitChildren(ctx);
860
861
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 return concludeNode(fallthroughStmtNode);
862 }
863
864 608 std::any ASTBuilder::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) {
865
1/2
✓ Branch 1 taken 608 times.
✗ Branch 2 not taken.
608 const auto assertStmtNode = createNode<AssertStmtNode>(ctx);
866
867 // Enrich
868
5/10
✓ Branch 1 taken 608 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 608 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 608 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 608 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 608 times.
✗ Branch 14 not taken.
608 const antlr4::misc::Interval interval(ctx->assignExpr()->start->getStartIndex(), ctx->assignExpr()->stop->getStopIndex());
869
1/2
✓ Branch 1 taken 608 times.
✗ Branch 2 not taken.
608 assertStmtNode->expressionString = inputStream->getText(interval);
870
871 // Visit children
872
3/6
✓ Branch 1 taken 608 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 608 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 608 times.
✗ Branch 8 not taken.
608 assertStmtNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
873
874
2/4
✓ Branch 1 taken 608 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 608 times.
✗ Branch 5 not taken.
608 return concludeNode(assertStmtNode);
875 }
876
877 1363 std::any ASTBuilder::visitBuiltinCall(SpiceParser::BuiltinCallContext *ctx) {
878 1363 const auto builtinCallNode = createNode<BuiltinCallNode>(ctx);
879
880
2/2
✓ Branch 1 taken 674 times.
✓ Branch 2 taken 689 times.
1363 if (ctx->printfCall()) {
881
3/6
✓ Branch 1 taken 674 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 674 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 674 times.
✗ Branch 8 not taken.
674 builtinCallNode->printfCall = std::any_cast<PrintfCallNode *>(visit(ctx->printfCall()));
882
2/2
✓ Branch 1 taken 185 times.
✓ Branch 2 taken 504 times.
689 } else if (ctx->sizeOfCall()) {
883
3/6
✓ Branch 1 taken 185 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 185 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 185 times.
✗ Branch 8 not taken.
185 builtinCallNode->sizeofCall = std::any_cast<SizeofCallNode *>(visit(ctx->sizeOfCall()));
884
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 493 times.
504 } else if (ctx->alignOfCall()) {
885
3/6
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
11 builtinCallNode->alignofCall = std::any_cast<AlignofCallNode *>(visit(ctx->alignOfCall()));
886
2/2
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 460 times.
493 } else if (ctx->lenCall()) {
887
3/6
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 33 times.
✗ Branch 8 not taken.
33 builtinCallNode->lenCall = std::any_cast<LenCallNode *>(visit(ctx->lenCall()));
888
2/2
✓ Branch 1 taken 459 times.
✓ Branch 2 taken 1 times.
460 } else if (ctx->panicCall()) {
889
3/6
✓ Branch 1 taken 459 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 459 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 459 times.
✗ Branch 8 not taken.
459 builtinCallNode->panicCall = std::any_cast<PanicCallNode *>(visit(ctx->panicCall()));
890
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 } else if (ctx->sysCall()) {
891
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 builtinCallNode->sysCall = std::any_cast<SysCallNode *>(visit(ctx->sysCall()));
892 } else {
893 assert_fail("Unknown builtin call"); // GCOV_EXCL_LINE
894 }
895
896
2/4
✓ Branch 1 taken 1363 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1363 times.
✗ Branch 5 not taken.
1363 return concludeNode(builtinCallNode);
897 }
898
899 674 std::any ASTBuilder::visitPrintfCall(SpiceParser::PrintfCallContext *ctx) {
900
1/2
✓ Branch 1 taken 674 times.
✗ Branch 2 not taken.
674 const auto printfCallNode = createNode<PrintfCallNode>(ctx);
901
902 // Enrich
903
2/4
✓ Branch 1 taken 674 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 674 times.
✗ Branch 5 not taken.
674 std::string templatedString = ctx->STRING_LIT()->getText();
904
1/2
✓ Branch 2 taken 674 times.
✗ Branch 3 not taken.
674 templatedString = templatedString.substr(1, templatedString.size() - 2);
905
1/2
✓ Branch 1 taken 674 times.
✗ Branch 2 not taken.
674 replaceEscapeChars(templatedString);
906
1/2
✓ Branch 1 taken 674 times.
✗ Branch 2 not taken.
674 printfCallNode->templatedString = templatedString;
907
908 // Visit children
909
3/4
✓ Branch 1 taken 674 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 565 times.
✓ Branch 8 taken 674 times.
1239 for (SpiceParser::AssignExprContext *assignExprContext : ctx->assignExpr())
910
3/6
✓ Branch 1 taken 565 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 565 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 565 times.
✗ Branch 8 not taken.
1239 printfCallNode->args.push_back(std::any_cast<AssignExprNode *>(visit(assignExprContext)));
911
912
2/4
✓ Branch 1 taken 674 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 674 times.
✗ Branch 5 not taken.
1348 return concludeNode(printfCallNode);
913 674 }
914
915 185 std::any ASTBuilder::visitSizeOfCall(SpiceParser::SizeOfCallContext *ctx) {
916 185 const auto sizeofCallNode = createNode<SizeofCallNode>(ctx);
917
918 // Visit children
919
2/2
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 171 times.
185 if (ctx->assignExpr()) {
920
3/6
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
14 sizeofCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
921 } else {
922 171 sizeofCallNode->isType = true;
923
3/6
✓ Branch 1 taken 171 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 171 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 171 times.
✗ Branch 8 not taken.
171 sizeofCallNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
924 }
925
926
2/4
✓ Branch 1 taken 185 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 185 times.
✗ Branch 5 not taken.
185 return concludeNode(sizeofCallNode);
927 }
928
929 11 std::any ASTBuilder::visitAlignOfCall(SpiceParser::AlignOfCallContext *ctx) {
930 11 const auto alignofCallNode = createNode<AlignofCallNode>(ctx);
931
932 // Visit children
933
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 1 times.
11 if (ctx->assignExpr()) {
934
3/6
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
10 alignofCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
935 } else {
936 1 alignofCallNode->isType = true;
937
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 alignofCallNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
938 }
939
940
2/4
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
11 return concludeNode(alignofCallNode);
941 }
942
943 33 std::any ASTBuilder::visitLenCall(SpiceParser::LenCallContext *ctx) {
944 33 const auto lenCallNode = createNode<LenCallNode>(ctx);
945
946 // Visit children
947
3/6
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 33 times.
✗ Branch 8 not taken.
33 lenCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
948
949
2/4
✓ Branch 1 taken 33 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 33 times.
✗ Branch 5 not taken.
33 return concludeNode(lenCallNode);
950 }
951
952 459 std::any ASTBuilder::visitPanicCall(SpiceParser::PanicCallContext *ctx) {
953 459 const auto panicCallNode = createNode<PanicCallNode>(ctx);
954
955 // Visit children
956
3/6
✓ Branch 1 taken 459 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 459 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 459 times.
✗ Branch 8 not taken.
459 panicCallNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
957
958
2/4
✓ Branch 1 taken 459 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 459 times.
✗ Branch 5 not taken.
459 return concludeNode(panicCallNode);
959 }
960
961 1 std::any ASTBuilder::visitSysCall(SpiceParser::SysCallContext *ctx) {
962 1 const auto sysCallNode = createNode<SysCallNode>(ctx);
963
964 // Visit children
965
3/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 1 times.
5 for (SpiceParser::AssignExprContext *assignExprContext : ctx->assignExpr())
966
3/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
5 sysCallNode->args.push_back(std::any_cast<AssignExprNode *>(visit(assignExprContext)));
967
968
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 return concludeNode(sysCallNode);
969 }
970
971 47294 std::any ASTBuilder::visitAssignExpr(SpiceParser::AssignExprContext *ctx) {
972 47294 const auto assignExprNode = createNode<AssignExprNode>(ctx);
973
974 // Visit children
975
2/2
✓ Branch 1 taken 41878 times.
✓ Branch 2 taken 5416 times.
47294 if (ctx->ternaryExpr()) {
976
4/6
✓ Branch 1 taken 41878 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 41876 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 41876 times.
✗ Branch 8 not taken.
41878 assignExprNode->ternaryExpr = std::any_cast<TernaryExprNode *>(visit(ctx->ternaryExpr()));
977
1/2
✓ Branch 1 taken 5416 times.
✗ Branch 2 not taken.
5416 } else if (ctx->prefixUnaryExpr()) {
978
3/6
✓ Branch 1 taken 5416 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5416 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5416 times.
✗ Branch 8 not taken.
5416 assignExprNode->lhs = std::any_cast<PrefixUnaryExprNode *>(visit(ctx->prefixUnaryExpr()));
979
2/4
✓ Branch 1 taken 5416 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5416 times.
✗ Branch 5 not taken.
5416 visit(ctx->assignOp());
980
3/6
✓ Branch 1 taken 5416 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5416 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5416 times.
✗ Branch 8 not taken.
5416 assignExprNode->rhs = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
981 } else {
982 assert_fail("Invalid assign expression"); // GCOV_EXCL_LINE
983 }
984
985
2/4
✓ Branch 1 taken 47292 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 47292 times.
✗ Branch 5 not taken.
47292 return concludeNode(assignExprNode);
986 }
987
988 42029 std::any ASTBuilder::visitTernaryExpr(SpiceParser::TernaryExprContext *ctx) {
989 42029 const auto ternaryExprNode = createNode<TernaryExprNode>(ctx);
990
991
4/6
✓ Branch 1 taken 42029 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 42027 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 42027 times.
✗ Branch 8 not taken.
42029 ternaryExprNode->condition = std::any_cast<LogicalOrExprNode *>(visit(ctx->logicalOrExpr(0)));
992
3/4
✓ Branch 1 taken 42027 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 254 times.
✓ Branch 6 taken 41773 times.
42027 if (ctx->logicalOrExpr().size() == 3) {
993
3/6
✓ Branch 1 taken 254 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 254 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 254 times.
✗ Branch 8 not taken.
254 ternaryExprNode->trueExpr = std::any_cast<LogicalOrExprNode *>(visit(ctx->logicalOrExpr(1)));
994
3/6
✓ Branch 1 taken 254 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 254 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 254 times.
✗ Branch 8 not taken.
254 ternaryExprNode->falseExpr = std::any_cast<LogicalOrExprNode *>(visit(ctx->logicalOrExpr(2)));
995
3/4
✓ Branch 1 taken 41773 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 41772 times.
41773 } else if (ctx->logicalOrExpr().size() == 2) {
996 1 ternaryExprNode->isShortened = true;
997
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 ternaryExprNode->falseExpr = std::any_cast<LogicalOrExprNode *>(visit(ctx->logicalOrExpr(1)));
998 }
999
1000
2/4
✓ Branch 1 taken 42027 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 42027 times.
✗ Branch 5 not taken.
42027 return concludeNode(ternaryExprNode);
1001 }
1002
1003 42538 std::any ASTBuilder::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext *ctx) {
1004 42538 const auto logicalOrExprNode = createNode<LogicalOrExprNode>(ctx);
1005
1006 // Visit children
1007
3/4
✓ Branch 1 taken 42538 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 42864 times.
✓ Branch 8 taken 42536 times.
85400 for (SpiceParser::LogicalAndExprContext *logicalAndExpr : ctx->logicalAndExpr())
1008
4/6
✓ Branch 1 taken 42862 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 42862 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 42862 times.
✗ Branch 8 not taken.
85400 logicalOrExprNode->operands.push_back(std::any_cast<LogicalAndExprNode *>(visit(logicalAndExpr)));
1009
1010
2/4
✓ Branch 1 taken 42536 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 42536 times.
✗ Branch 5 not taken.
42536 return concludeNode(logicalOrExprNode);
1011 }
1012
1013 42864 std::any ASTBuilder::visitLogicalAndExpr(SpiceParser::LogicalAndExprContext *ctx) {
1014 42864 const auto logicalAndExprNode = createNode<LogicalAndExprNode>(ctx);
1015
1016 // Visit children
1017
3/4
✓ Branch 1 taken 42864 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 42978 times.
✓ Branch 8 taken 42862 times.
85840 for (SpiceParser::BitwiseOrExprContext *bitwiseOrExpr : ctx->bitwiseOrExpr())
1018
4/6
✓ Branch 1 taken 42976 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 42976 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 42976 times.
✗ Branch 8 not taken.
85840 logicalAndExprNode->operands.push_back(std::any_cast<BitwiseOrExprNode *>(visit(bitwiseOrExpr)));
1019
1020
2/4
✓ Branch 1 taken 42862 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 42862 times.
✗ Branch 5 not taken.
42862 return concludeNode(logicalAndExprNode);
1021 }
1022
1023 42978 std::any ASTBuilder::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext *ctx) {
1024 42978 const auto bitwiseOrExprNode = createNode<BitwiseOrExprNode>(ctx);
1025
1026 // Visit children
1027
3/4
✓ Branch 1 taken 42978 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 43010 times.
✓ Branch 8 taken 42976 times.
85986 for (SpiceParser::BitwiseXorExprContext *bitwiseXorExpr : ctx->bitwiseXorExpr())
1028
4/6
✓ Branch 1 taken 43008 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 43008 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 43008 times.
✗ Branch 8 not taken.
85986 bitwiseOrExprNode->operands.push_back(std::any_cast<BitwiseXorExprNode *>(visit(bitwiseXorExpr)));
1029
1030
2/4
✓ Branch 1 taken 42976 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 42976 times.
✗ Branch 5 not taken.
42976 return concludeNode(bitwiseOrExprNode);
1031 }
1032
1033 43010 std::any ASTBuilder::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprContext *ctx) {
1034 43010 const auto bitwiseXorExprNode = createNode<BitwiseXorExprNode>(ctx);
1035
1036 // Visit children
1037
3/4
✓ Branch 1 taken 43010 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 43014 times.
✓ Branch 8 taken 43008 times.
86022 for (SpiceParser::BitwiseAndExprContext *bitwiseAndExpr : ctx->bitwiseAndExpr())
1038
4/6
✓ Branch 1 taken 43012 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 43012 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 43012 times.
✗ Branch 8 not taken.
86022 bitwiseXorExprNode->operands.push_back(std::any_cast<BitwiseAndExprNode *>(visit(bitwiseAndExpr)));
1039
1040
2/4
✓ Branch 1 taken 43008 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 43008 times.
✗ Branch 5 not taken.
43008 return concludeNode(bitwiseXorExprNode);
1041 }
1042
1043 43014 std::any ASTBuilder::visitBitwiseAndExpr(SpiceParser::BitwiseAndExprContext *ctx) {
1044 43014 const auto bitwiseAndExprNode = createNode<BitwiseAndExprNode>(ctx);
1045
1046 // Visit children
1047
3/4
✓ Branch 1 taken 43014 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 43041 times.
✓ Branch 8 taken 43012 times.
86053 for (SpiceParser::EqualityExprContext *equalityExpr : ctx->equalityExpr())
1048
4/6
✓ Branch 1 taken 43039 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 43039 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 43039 times.
✗ Branch 8 not taken.
86053 bitwiseAndExprNode->operands.push_back(std::any_cast<EqualityExprNode *>(visit(equalityExpr)));
1049
1050
2/4
✓ Branch 1 taken 43012 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 43012 times.
✗ Branch 5 not taken.
43012 return concludeNode(bitwiseAndExprNode);
1051 }
1052
1053 43041 std::any ASTBuilder::visitEqualityExpr(SpiceParser::EqualityExprContext *ctx) {
1054 43041 const auto equalityExprNode = createNode<EqualityExprNode>(ctx);
1055
1056 // Visit children
1057
3/4
✓ Branch 1 taken 43041 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 46597 times.
✓ Branch 8 taken 43039 times.
89636 for (SpiceParser::RelationalExprContext *relationalExpr : ctx->relationalExpr())
1058
4/6
✓ Branch 1 taken 46595 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 46595 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 46595 times.
✗ Branch 8 not taken.
89636 equalityExprNode->operands.push_back(std::any_cast<RelationalExprNode *>(visit(relationalExpr)));
1059
1060 // Extract operator
1061
2/2
✓ Branch 1 taken 2460 times.
✓ Branch 2 taken 40579 times.
43039 if (ctx->EQUAL())
1062 2460 equalityExprNode->op = EqualityExprNode::OP_EQUAL;
1063
2/2
✓ Branch 1 taken 1096 times.
✓ Branch 2 taken 39483 times.
40579 else if (ctx->NOT_EQUAL())
1064 1096 equalityExprNode->op = EqualityExprNode::OP_NOT_EQUAL;
1065
1066
2/4
✓ Branch 1 taken 43039 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 43039 times.
✗ Branch 5 not taken.
43039 return concludeNode(equalityExprNode);
1067 }
1068
1069 46597 std::any ASTBuilder::visitRelationalExpr(SpiceParser::RelationalExprContext *ctx) {
1070 46597 const auto relationalExprNode = createNode<RelationalExprNode>(ctx);
1071
1072 // Visit children
1073
3/4
✓ Branch 1 taken 46597 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 49160 times.
✓ Branch 8 taken 46595 times.
95755 for (SpiceParser::ShiftExprContext *shiftExpr : ctx->shiftExpr())
1074
4/6
✓ Branch 1 taken 49158 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 49158 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 49158 times.
✗ Branch 8 not taken.
95755 relationalExprNode->operands.push_back(std::any_cast<ShiftExprNode *>(visit(shiftExpr)));
1075
1076 // Extract operator
1077
2/2
✓ Branch 1 taken 1515 times.
✓ Branch 2 taken 45080 times.
46595 if (ctx->LESS())
1078 1515 relationalExprNode->op = RelationalExprNode::OP_LESS;
1079
2/2
✓ Branch 1 taken 390 times.
✓ Branch 2 taken 44690 times.
45080 else if (ctx->GREATER())
1080 390 relationalExprNode->op = RelationalExprNode::OP_GREATER;
1081
2/2
✓ Branch 1 taken 207 times.
✓ Branch 2 taken 44483 times.
44690 else if (ctx->LESS_EQUAL())
1082 207 relationalExprNode->op = RelationalExprNode::OP_LESS_EQUAL;
1083
2/2
✓ Branch 1 taken 451 times.
✓ Branch 2 taken 44032 times.
44483 else if (ctx->GREATER_EQUAL())
1084 451 relationalExprNode->op = RelationalExprNode::OP_GREATER_EQUAL;
1085
1086
2/4
✓ Branch 1 taken 46595 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 46595 times.
✗ Branch 5 not taken.
46595 return concludeNode(relationalExprNode);
1087 }
1088
1089 49160 std::any ASTBuilder::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) {
1090 49160 const auto shiftExprNode = createNode<ShiftExprNode>(ctx);
1091
1092 // Visit children
1093
3/4
✓ Branch 1 taken 49160 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 49175 times.
✓ Branch 8 taken 49158 times.
98333 for (SpiceParser::AdditiveExprContext *additiveExpr : ctx->additiveExpr())
1094
4/6
✓ Branch 1 taken 49173 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 49173 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 49173 times.
✗ Branch 8 not taken.
98333 shiftExprNode->operands.push_back(std::any_cast<AdditiveExprNode *>(visit(additiveExpr)));
1095
1096 // Extract operator
1097
3/4
✓ Branch 1 taken 49158 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 49148 times.
49158 if (!ctx->LESS().empty())
1098 10 shiftExprNode->op = ShiftExprNode::OP_SHIFT_LEFT;
1099
3/4
✓ Branch 1 taken 49148 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 49143 times.
49148 else if (!ctx->GREATER().empty())
1100 5 shiftExprNode->op = ShiftExprNode::OP_SHIFT_RIGHT;
1101
1102
2/4
✓ Branch 1 taken 49158 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 49158 times.
✗ Branch 5 not taken.
49158 return concludeNode(shiftExprNode);
1103 }
1104
1105 49175 std::any ASTBuilder::visitAdditiveExpr(SpiceParser::AdditiveExprContext *ctx) {
1106 49175 const auto additiveExprNode = createNode<AdditiveExprNode>(ctx);
1107
1108 // Visit children
1109
3/4
✓ Branch 1 taken 49175 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 51994 times.
✓ Branch 8 taken 49173 times.
101167 for (SpiceParser::MultiplicativeExprContext *multiplicativeExpr : ctx->multiplicativeExpr())
1110
4/6
✓ Branch 1 taken 51992 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 51992 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 51992 times.
✗ Branch 8 not taken.
101167 additiveExprNode->operands.push_back(std::any_cast<MultiplicativeExprNode *>(visit(multiplicativeExpr)));
1111
1112
2/2
✓ Branch 5 taken 54811 times.
✓ Branch 6 taken 49173 times.
103984 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1113
1/2
✓ Branch 0 taken 54811 times.
✗ Branch 1 not taken.
54811 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1114
2/2
✓ Branch 0 taken 51992 times.
✓ Branch 1 taken 2819 times.
54811 if (!terminal)
1115 51992 continue;
1116
1117
4/6
✓ Branch 1 taken 2819 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2819 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1708 times.
✓ Branch 7 taken 1111 times.
2819 if (terminal->getSymbol()->getType() == SpiceParser::PLUS)
1118
1/2
✓ Branch 1 taken 1708 times.
✗ Branch 2 not taken.
1708 additiveExprNode->opQueue.emplace(AdditiveExprNode::OP_PLUS, TY_INVALID);
1119
3/6
✓ Branch 1 taken 1111 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1111 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1111 times.
✗ Branch 7 not taken.
1111 else if (terminal->getSymbol()->getType() == SpiceParser::MINUS)
1120
1/2
✓ Branch 1 taken 1111 times.
✗ Branch 2 not taken.
1111 additiveExprNode->opQueue.emplace(AdditiveExprNode::OP_MINUS, TY_INVALID);
1121 else
1122 assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE
1123 }
1124
1125
2/4
✓ Branch 1 taken 49173 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 49173 times.
✗ Branch 5 not taken.
49173 return concludeNode(additiveExprNode);
1126 }
1127
1128 51994 std::any ASTBuilder::visitMultiplicativeExpr(SpiceParser::MultiplicativeExprContext *ctx) {
1129 51994 const auto multiplicativeExprNode = createNode<MultiplicativeExprNode>(ctx);
1130
1131 // Visit children
1132
3/4
✓ Branch 1 taken 51994 times.
✗ Branch 2 not taken.
✓ Branch 7 taken 53050 times.
✓ Branch 8 taken 51992 times.
105042 for (SpiceParser::CastExprContext *castExpr : ctx->castExpr())
1133
4/6
✓ Branch 1 taken 53048 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 53048 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 53048 times.
✗ Branch 8 not taken.
105042 multiplicativeExprNode->operands.push_back(std::any_cast<CastExprNode *>(visit(castExpr)));
1134
1135
2/2
✓ Branch 5 taken 54104 times.
✓ Branch 6 taken 51992 times.
106096 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1136
1/2
✓ Branch 0 taken 54104 times.
✗ Branch 1 not taken.
54104 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1137
2/2
✓ Branch 0 taken 53048 times.
✓ Branch 1 taken 1056 times.
54104 if (!terminal)
1138 53048 continue;
1139
1140
4/6
✓ Branch 1 taken 1056 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1056 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 736 times.
✓ Branch 7 taken 320 times.
1056 if (terminal->getSymbol()->getType() == SpiceParser::MUL)
1141
1/2
✓ Branch 1 taken 736 times.
✗ Branch 2 not taken.
736 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::OP_MUL, TY_INVALID);
1142
4/6
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 320 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 154 times.
✓ Branch 7 taken 166 times.
320 else if (terminal->getSymbol()->getType() == SpiceParser::DIV)
1143
1/2
✓ Branch 1 taken 154 times.
✗ Branch 2 not taken.
154 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::OP_DIV, TY_INVALID);
1144
3/6
✓ Branch 1 taken 166 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 166 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 166 times.
✗ Branch 7 not taken.
166 else if (terminal->getSymbol()->getType() == SpiceParser::REM)
1145
1/2
✓ Branch 1 taken 166 times.
✗ Branch 2 not taken.
166 multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::OP_REM, TY_INVALID);
1146 else
1147 assert_fail("Invalid terminal symbol for multiplicative expression"); // GCOV_EXCL_LINE
1148 }
1149
1150
2/4
✓ Branch 1 taken 51992 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 51992 times.
✗ Branch 5 not taken.
51992 return concludeNode(multiplicativeExprNode);
1151 }
1152
1153 53050 std::any ASTBuilder::visitCastExpr(SpiceParser::CastExprContext *ctx) {
1154 53050 const auto castExprNode = createNode<CastExprNode>(ctx);
1155
1156
2/2
✓ Branch 1 taken 2077 times.
✓ Branch 2 taken 50973 times.
53050 if (ctx->dataType()) {
1157 2077 castExprNode->isCast = true;
1158
3/6
✓ Branch 1 taken 2077 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2077 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2077 times.
✗ Branch 8 not taken.
2077 castExprNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1159 }
1160
4/6
✓ Branch 1 taken 53050 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 53048 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 53048 times.
✗ Branch 8 not taken.
53050 castExprNode->prefixUnaryExpr = std::any_cast<PrefixUnaryExprNode *>(visit(ctx->prefixUnaryExpr()));
1161
1162
2/4
✓ Branch 1 taken 53048 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 53048 times.
✗ Branch 5 not taken.
53048 return concludeNode(castExprNode);
1163 }
1164
1165 59386 std::any ASTBuilder::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprContext *ctx) {
1166 59386 const auto prefixUnaryExprNode = createNode<PrefixUnaryExprNode>(ctx);
1167
1168 // Visit children
1169
2/2
✓ Branch 1 taken 58466 times.
✓ Branch 2 taken 920 times.
59386 if (ctx->postfixUnaryExpr()) {
1170
4/6
✓ Branch 1 taken 58466 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 58464 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 58464 times.
✗ Branch 8 not taken.
58466 prefixUnaryExprNode->postfixUnaryExpr = std::any_cast<PostfixUnaryExprNode *>(visit(ctx->postfixUnaryExpr()));
1171
1/2
✓ Branch 1 taken 920 times.
✗ Branch 2 not taken.
920 } else if (ctx->prefixUnaryExpr()) {
1172 // Extract operator
1173
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 916 times.
920 if (ctx->MINUS())
1174 4 prefixUnaryExprNode->op = PrefixUnaryExprNode::OP_MINUS;
1175
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 896 times.
916 else if (ctx->PLUS_PLUS())
1176 20 prefixUnaryExprNode->op = PrefixUnaryExprNode::OP_PLUS_PLUS;
1177
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 888 times.
896 else if (ctx->MINUS_MINUS())
1178 8 prefixUnaryExprNode->op = PrefixUnaryExprNode::OP_MINUS_MINUS;
1179
2/2
✓ Branch 1 taken 623 times.
✓ Branch 2 taken 265 times.
888 else if (ctx->NOT())
1180 623 prefixUnaryExprNode->op = PrefixUnaryExprNode::OP_NOT;
1181
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 264 times.
265 else if (ctx->BITWISE_NOT())
1182 1 prefixUnaryExprNode->op = PrefixUnaryExprNode::OP_BITWISE_NOT;
1183
2/2
✓ Branch 1 taken 148 times.
✓ Branch 2 taken 116 times.
264 else if (ctx->MUL())
1184 148 prefixUnaryExprNode->op = PrefixUnaryExprNode::OP_DEREFERENCE;
1185
1/2
✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
116 else if (ctx->BITWISE_AND())
1186 116 prefixUnaryExprNode->op = PrefixUnaryExprNode::OP_ADDRESS_OF;
1187
1188
3/6
✓ Branch 1 taken 920 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 920 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 920 times.
✗ Branch 8 not taken.
920 prefixUnaryExprNode->prefixUnaryExpr = std::any_cast<PrefixUnaryExprNode *>(visit(ctx->prefixUnaryExpr()));
1189 } else {
1190 assert_fail("Unknown prefix unary expression type"); // GCOV_EXCL_LINE
1191 }
1192
1193
2/4
✓ Branch 1 taken 59384 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 59384 times.
✗ Branch 5 not taken.
59384 return concludeNode(prefixUnaryExprNode);
1194 }
1195
1196 75671 std::any ASTBuilder::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprContext *ctx) {
1197 75671 const auto postfixUnaryExprNode = createNode<PostfixUnaryExprNode>(ctx);
1198
1199
2/2
✓ Branch 1 taken 58466 times.
✓ Branch 2 taken 17205 times.
75671 if (ctx->atomicExpr()) {
1200
4/6
✓ Branch 1 taken 58466 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 58464 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 58464 times.
✗ Branch 8 not taken.
58466 postfixUnaryExprNode->atomicExpr = std::any_cast<AtomicExprNode *>(visit(ctx->atomicExpr()));
1201
1/2
✓ Branch 1 taken 17205 times.
✗ Branch 2 not taken.
17205 } else if (ctx->postfixUnaryExpr()) {
1202
3/6
✓ Branch 1 taken 17205 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 17205 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 17205 times.
✗ Branch 8 not taken.
17205 postfixUnaryExprNode->postfixUnaryExpr = std::any_cast<PostfixUnaryExprNode *>(visit(ctx->postfixUnaryExpr()));
1203
1204 // Extract operator
1205
2/2
✓ Branch 1 taken 2729 times.
✓ Branch 2 taken 14476 times.
17205 if (ctx->assignExpr()) {
1206 2729 postfixUnaryExprNode->op = PostfixUnaryExprNode::OP_SUBSCRIPT;
1207
3/6
✓ Branch 1 taken 2729 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2729 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2729 times.
✗ Branch 8 not taken.
2729 postfixUnaryExprNode->subscriptIndexExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
1208
2/2
✓ Branch 1 taken 12859 times.
✓ Branch 2 taken 1617 times.
14476 } else if (ctx->IDENTIFIER()) {
1209 12859 postfixUnaryExprNode->op = PostfixUnaryExprNode::OP_MEMBER_ACCESS;
1210
2/4
✓ Branch 1 taken 12859 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12859 times.
✗ Branch 5 not taken.
12859 postfixUnaryExprNode->identifier = getIdentifier(ctx->IDENTIFIER());
1211
2/2
✓ Branch 1 taken 1372 times.
✓ Branch 2 taken 245 times.
1617 } else if (ctx->PLUS_PLUS()) {
1212 1372 postfixUnaryExprNode->op = PostfixUnaryExprNode::OP_PLUS_PLUS;
1213
1/2
✓ Branch 1 taken 245 times.
✗ Branch 2 not taken.
245 } else if (ctx->MINUS_MINUS()) {
1214 245 postfixUnaryExprNode->op = PostfixUnaryExprNode::OP_MINUS_MINUS;
1215 }
1216 } else {
1217 assert_fail("Unknown postfix unary expression type"); // GCOV_EXCL_LINE
1218 }
1219
1220
2/4
✓ Branch 1 taken 75669 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 75669 times.
✗ Branch 5 not taken.
75669 return concludeNode(postfixUnaryExprNode);
1221 }
1222
1223 58466 std::any ASTBuilder::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) {
1224 58466 const auto atomicExprNode = createNode<AtomicExprNode>(ctx);
1225
1226 // Visit children
1227
2/2
✓ Branch 1 taken 10151 times.
✓ Branch 2 taken 48315 times.
58466 if (ctx->constant()) {
1228
4/6
✓ Branch 1 taken 10151 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10149 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 10149 times.
✗ Branch 8 not taken.
10151 atomicExprNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant()));
1229
2/2
✓ Branch 1 taken 10964 times.
✓ Branch 2 taken 37351 times.
48315 } else if (ctx->value()) {
1230
3/6
✓ Branch 1 taken 10964 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10964 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10964 times.
✗ Branch 8 not taken.
10964 atomicExprNode->value = std::any_cast<ValueNode *>(visit(ctx->value()));
1231
11/18
✓ Branch 1 taken 37351 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3307 times.
✓ Branch 5 taken 34044 times.
✓ Branch 7 taken 3307 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1378 times.
✓ Branch 11 taken 1929 times.
✓ Branch 12 taken 3307 times.
✓ Branch 13 taken 34044 times.
✓ Branch 15 taken 37351 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 35422 times.
✓ Branch 19 taken 1929 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
37351 } else if (!ctx->IDENTIFIER().empty() || !ctx->TYPE_IDENTIFIER().empty()) {
1232
2/2
✓ Branch 5 taken 35916 times.
✓ Branch 6 taken 35422 times.
71338 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1233
1/2
✓ Branch 0 taken 35916 times.
✗ Branch 1 not taken.
35916 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35916 times.
35916 if (!terminal)
1235 continue;
1236
1237
4/6
✓ Branch 1 taken 35916 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 35916 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 34044 times.
✓ Branch 7 taken 1872 times.
35916 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1238
1/2
✓ Branch 1 taken 34044 times.
✗ Branch 2 not taken.
34044 std::string fragment = getIdentifier(terminal);
1239
1/2
✓ Branch 1 taken 34044 times.
✗ Branch 2 not taken.
34044 atomicExprNode->identifierFragments.push_back(fragment);
1240
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 34044 times.
34044 if (!atomicExprNode->fqIdentifier.empty())
1241 atomicExprNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
1242
1/2
✓ Branch 1 taken 34044 times.
✗ Branch 2 not taken.
34044 atomicExprNode->fqIdentifier += fragment;
1243
4/6
✓ Branch 2 taken 1872 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1872 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1625 times.
✓ Branch 8 taken 247 times.
35916 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1244
1/2
✓ Branch 1 taken 1625 times.
✗ Branch 2 not taken.
1625 std::string fragment = getIdentifier(terminal);
1245
1/2
✓ Branch 1 taken 1625 times.
✗ Branch 2 not taken.
1625 atomicExprNode->identifierFragments.push_back(fragment);
1246
2/2
✓ Branch 1 taken 247 times.
✓ Branch 2 taken 1378 times.
1625 if (!atomicExprNode->fqIdentifier.empty())
1247
1/2
✓ Branch 1 taken 247 times.
✗ Branch 2 not taken.
247 atomicExprNode->fqIdentifier += SCOPE_ACCESS_TOKEN;
1248
1/2
✓ Branch 1 taken 1625 times.
✗ Branch 2 not taken.
1625 atomicExprNode->fqIdentifier += fragment;
1249 1625 }
1250 }
1251
2/2
✓ Branch 1 taken 1363 times.
✓ Branch 2 taken 566 times.
1929 } else if (ctx->builtinCall()) {
1252
3/6
✓ Branch 1 taken 1363 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1363 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1363 times.
✗ Branch 8 not taken.
1363 atomicExprNode->builtinCall = std::any_cast<BuiltinCallNode *>(visit(ctx->builtinCall()));
1253
1/2
✓ Branch 1 taken 566 times.
✗ Branch 2 not taken.
566 } else if (ctx->assignExpr()) {
1254
3/6
✓ Branch 1 taken 566 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 566 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 566 times.
✗ Branch 8 not taken.
566 atomicExprNode->assignExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
1255 } else {
1256 assert_fail("Unknown atomic expression type"); // GCOV_EXCL_LINE
1257 }
1258
1259
2/4
✓ Branch 1 taken 58464 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 58464 times.
✗ Branch 5 not taken.
58464 return concludeNode(atomicExprNode);
1260 }
1261
1262 10964 std::any ASTBuilder::visitValue(SpiceParser::ValueContext *ctx) {
1263 10964 const auto valueNode = createNode<ValueNode>(ctx);
1264
1265 // Visit children
1266
2/2
✓ Branch 1 taken 9994 times.
✓ Branch 2 taken 970 times.
10964 if (ctx->fctCall()) {
1267
3/6
✓ Branch 1 taken 9994 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9994 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9994 times.
✗ Branch 8 not taken.
9994 valueNode->fctCall = std::any_cast<FctCallNode *>(visit(ctx->fctCall()));
1268
2/2
✓ Branch 1 taken 67 times.
✓ Branch 2 taken 903 times.
970 } else if (ctx->arrayInitialization()) {
1269
3/6
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 67 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 67 times.
✗ Branch 8 not taken.
67 valueNode->arrayInitialization = std::any_cast<ArrayInitializationNode *>(visit(ctx->arrayInitialization()));
1270
2/2
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 765 times.
903 } else if (ctx->structInstantiation()) {
1271
3/6
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 138 times.
✗ Branch 8 not taken.
138 valueNode->structInstantiation = std::any_cast<StructInstantiationNode *>(visit(ctx->structInstantiation()));
1272
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 756 times.
765 } else if (ctx->lambdaFunc()) {
1273
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
9 valueNode->lambdaFunc = std::any_cast<LambdaFuncNode *>(visit(ctx->lambdaFunc()));
1274
2/2
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 729 times.
756 } else if (ctx->lambdaProc()) {
1275
3/6
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 27 times.
✗ Branch 8 not taken.
27 valueNode->lambdaProc = std::any_cast<LambdaProcNode *>(visit(ctx->lambdaProc()));
1276
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 728 times.
729 } else if (ctx->lambdaExpr()) {
1277
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 valueNode->lambdaExpr = std::any_cast<LambdaExprNode *>(visit(ctx->lambdaExpr()));
1278
1/2
✓ Branch 1 taken 728 times.
✗ Branch 2 not taken.
728 } else if (ctx->dataType()) {
1279 728 valueNode->isNil = true;
1280
3/6
✓ Branch 1 taken 728 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 728 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 728 times.
✗ Branch 8 not taken.
728 valueNode->nilType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1281 } else {
1282 assert_fail("Unknown value type"); // GCOV_EXCL_LINE
1283 }
1284
1285
2/4
✓ Branch 1 taken 10964 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10964 times.
✗ Branch 5 not taken.
10964 return concludeNode(valueNode);
1286 }
1287
1288 11505 std::any ASTBuilder::visitConstant(SpiceParser::ConstantContext *ctx) {
1289 11505 const auto constantNode = createNode<ConstantNode>(ctx);
1290
1291 // Enrich
1292 11505 auto &[doubleValue, intValue, shortValue, longValue, charValue, boolValue, stringValueOffset] = constantNode->compileTimeValue;
1293
2/2
✓ Branch 1 taken 176 times.
✓ Branch 2 taken 11329 times.
11505 if (ctx->DOUBLE_LIT()) {
1294 176 constantNode->type = ConstantNode::TYPE_DOUBLE;
1295
3/6
✓ Branch 1 taken 176 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 176 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 176 times.
✗ Branch 8 not taken.
176 doubleValue = std::stod(ctx->DOUBLE_LIT()->toString());
1296
2/2
✓ Branch 1 taken 3141 times.
✓ Branch 2 taken 8188 times.
11329 } else if (ctx->INT_LIT()) {
1297 3141 constantNode->type = ConstantNode::TYPE_INT;
1298 3141 intValue = parseInt(ctx->INT_LIT());
1299
2/2
✓ Branch 1 taken 177 times.
✓ Branch 2 taken 8011 times.
8188 } else if (ctx->SHORT_LIT()) {
1300 177 constantNode->type = ConstantNode::TYPE_SHORT;
1301 177 shortValue = parseShort(ctx->SHORT_LIT());
1302
2/2
✓ Branch 1 taken 4078 times.
✓ Branch 2 taken 3933 times.
8011 } else if (ctx->LONG_LIT()) {
1303 4078 constantNode->type = ConstantNode::TYPE_LONG;
1304 4078 longValue = parseLong(ctx->LONG_LIT());
1305
2/2
✓ Branch 1 taken 887 times.
✓ Branch 2 taken 3046 times.
3933 } else if (ctx->CHAR_LIT()) {
1306 887 constantNode->type = ConstantNode::TYPE_CHAR;
1307 887 charValue = parseChar(ctx->CHAR_LIT());
1308
2/2
✓ Branch 1 taken 1717 times.
✓ Branch 2 taken 1329 times.
3046 } else if (ctx->STRING_LIT()) {
1309 // Save a pointer to the string in the compile time value
1310 1717 constantNode->type = ConstantNode::TYPE_STRING;
1311 1717 stringValueOffset = resourceManager.compileTimeStringValues.size();
1312 // Add the string to the global compile time string list
1313
4/8
✓ Branch 1 taken 1717 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1717 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1717 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1717 times.
✗ Branch 11 not taken.
1717 resourceManager.compileTimeStringValues.push_back(parseString(ctx->STRING_LIT()->toString()));
1314
2/2
✓ Branch 1 taken 697 times.
✓ Branch 2 taken 632 times.
1329 } else if (ctx->TRUE()) {
1315 697 constantNode->type = ConstantNode::TYPE_BOOL;
1316 697 boolValue = true;
1317
1/2
✓ Branch 1 taken 632 times.
✗ Branch 2 not taken.
632 } else if (ctx->FALSE()) {
1318 632 constantNode->type = ConstantNode::TYPE_BOOL;
1319 632 boolValue = false;
1320 } else {
1321 assert_fail("Unknown constant type"); // GCOV_EXCL_LINE
1322 }
1323
1324
2/4
✓ Branch 1 taken 11503 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11503 times.
✗ Branch 5 not taken.
11503 return concludeNode(constantNode);
1325 }
1326
1327 9994 std::any ASTBuilder::visitFctCall(SpiceParser::FctCallContext *ctx) {
1328 9994 const auto fctCallNode = createNode<FctCallNode>(ctx);
1329
1330
2/2
✓ Branch 5 taken 49818 times.
✓ Branch 6 taken 9994 times.
59812 for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) {
1331
1/2
✓ Branch 0 taken 49818 times.
✗ Branch 1 not taken.
49818 const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree);
1332
2/2
✓ Branch 0 taken 7728 times.
✓ Branch 1 taken 42090 times.
49818 if (!terminal)
1333 7728 continue;
1334
1335
4/6
✓ Branch 1 taken 42090 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 42090 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13819 times.
✓ Branch 7 taken 28271 times.
42090 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1336
1/2
✓ Branch 1 taken 13819 times.
✗ Branch 2 not taken.
13819 const std::string fragment = terminal->toString();
1337
1/2
✓ Branch 1 taken 13819 times.
✗ Branch 2 not taken.
13819 fctCallNode->functionNameFragments.push_back(fragment);
1338
1/2
✓ Branch 1 taken 13819 times.
✗ Branch 2 not taken.
13819 fctCallNode->fqFunctionName += fragment;
1339
4/6
✓ Branch 2 taken 28271 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 28271 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1843 times.
✓ Branch 8 taken 26428 times.
42090 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1340
1/2
✓ Branch 1 taken 1843 times.
✗ Branch 2 not taken.
1843 const std::string fragment = terminal->toString();
1341
1/2
✓ Branch 1 taken 1843 times.
✗ Branch 2 not taken.
1843 fctCallNode->functionNameFragments.push_back(fragment);
1342
1/2
✓ Branch 1 taken 1843 times.
✗ Branch 2 not taken.
1843 fctCallNode->fqFunctionName += fragment;
1343
4/6
✓ Branch 2 taken 26428 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 26428 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 61 times.
✓ Branch 8 taken 26367 times.
28271 } else if (terminal->getSymbol()->getType() == SpiceParser::SCOPE_ACCESS) {
1344
1/2
✓ Branch 1 taken 61 times.
✗ Branch 2 not taken.
61 fctCallNode->fqFunctionName += SCOPE_ACCESS_TOKEN;
1345
4/6
✓ Branch 1 taken 26367 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26367 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5607 times.
✓ Branch 7 taken 20760 times.
26367 } else if (terminal->getSymbol()->getType() == SpiceParser::DOT) {
1346
1/2
✓ Branch 1 taken 5607 times.
✗ Branch 2 not taken.
5607 fctCallNode->fqFunctionName += MEMBER_ACCESS_TOKEN;
1347 }
1348 }
1349
1350 // Visit children
1351
2/2
✓ Branch 1 taken 386 times.
✓ Branch 2 taken 9608 times.
9994 if (ctx->typeLst()) {
1352 386 fctCallNode->hasTemplateTypes = true;
1353
3/6
✓ Branch 1 taken 386 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 386 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 386 times.
✗ Branch 8 not taken.
386 fctCallNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1354 }
1355
2/2
✓ Branch 1 taken 7342 times.
✓ Branch 2 taken 2652 times.
9994 if (ctx->argLst()) {
1356 7342 fctCallNode->hasArgs = true;
1357
3/6
✓ Branch 1 taken 7342 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7342 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7342 times.
✗ Branch 8 not taken.
7342 fctCallNode->argLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1358 }
1359
1360
2/4
✓ Branch 1 taken 9994 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9994 times.
✗ Branch 5 not taken.
9994 return concludeNode(fctCallNode);
1361 }
1362
1363 67 std::any ASTBuilder::visitArrayInitialization(SpiceParser::ArrayInitializationContext *ctx) {
1364 67 const auto arrayInitializationNode = createNode<ArrayInitializationNode>(ctx);
1365
1366 // Visit children
1367
2/2
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 2 times.
67 if (ctx->argLst())
1368
3/6
✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 65 times.
✗ Branch 8 not taken.
65 arrayInitializationNode->itemLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1369
1370
2/4
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 67 times.
✗ Branch 5 not taken.
67 return concludeNode(arrayInitializationNode);
1371 }
1372
1373 138 std::any ASTBuilder::visitStructInstantiation(SpiceParser::StructInstantiationContext *ctx) {
1374 138 const auto structInstantiationNode = createNode<StructInstantiationNode>(ctx);
1375
1376 // Enrich
1377
2/2
✓ Branch 5 taken 587 times.
✓ Branch 6 taken 138 times.
725 for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) {
1378
1/2
✓ Branch 0 taken 587 times.
✗ Branch 1 not taken.
587 const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree);
1379
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 450 times.
587 if (!terminal)
1380 137 continue;
1381
1382
4/6
✓ Branch 1 taken 450 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 450 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 447 times.
450 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1383
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 const std::string fragment = terminal->toString();
1384
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 structInstantiationNode->structNameFragments.push_back(fragment);
1385
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 structInstantiationNode->fqStructName += fragment + SCOPE_ACCESS_TOKEN;
1386
4/6
✓ Branch 2 taken 447 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 447 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 138 times.
✓ Branch 8 taken 309 times.
450 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1387
1/2
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
138 const std::string fragment = terminal->toString();
1388
1/2
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
138 structInstantiationNode->structNameFragments.push_back(fragment);
1389
1/2
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
138 structInstantiationNode->fqStructName += fragment;
1390 138 }
1391 }
1392
1393 // Visit children
1394
2/2
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 123 times.
138 if (ctx->typeLst()) {
1395 15 structInstantiationNode->hasTemplateTypes = true;
1396
3/6
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 15 times.
✗ Branch 8 not taken.
15 structInstantiationNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1397 }
1398
2/2
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 16 times.
138 if (ctx->argLst())
1399
3/6
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 122 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 122 times.
✗ Branch 8 not taken.
122 structInstantiationNode->fieldLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst()));
1400
1401
2/4
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
138 return concludeNode(structInstantiationNode);
1402 }
1403
1404 9 std::any ASTBuilder::visitLambdaFunc(SpiceParser::LambdaFuncContext *ctx) {
1405 9 const auto lambdaFuncNode = createNode<LambdaFuncNode>(ctx);
1406
1407 // Visit children
1408
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
9 lambdaFuncNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1409
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
9 if (ctx->paramLst()) {
1410 8 lambdaFuncNode->hasParams = true;
1411
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
8 lambdaFuncNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1412 }
1413
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 if (ctx->lambdaAttr())
1414 lambdaFuncNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr()));
1415
3/6
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
9 lambdaFuncNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
1416
1417
2/4
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
9 return concludeNode(lambdaFuncNode);
1418 }
1419
1420 27 std::any ASTBuilder::visitLambdaProc(SpiceParser::LambdaProcContext *ctx) {
1421 27 const auto lambdaProcNode = createNode<LambdaProcNode>(ctx);
1422
1423 // Visit children
1424
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 20 times.
27 if (ctx->paramLst()) {
1425 7 lambdaProcNode->hasParams = true;
1426
3/6
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
7 lambdaProcNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1427 }
1428
2/2
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 11 times.
27 if (ctx->lambdaAttr())
1429
3/6
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
16 lambdaProcNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr()));
1430
3/6
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 27 times.
✗ Branch 8 not taken.
27 lambdaProcNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst()));
1431
1432
2/4
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
27 return concludeNode(lambdaProcNode);
1433 }
1434
1435 1 std::any ASTBuilder::visitLambdaExpr(SpiceParser::LambdaExprContext *ctx) {
1436 1 const auto lambdaExprNode = createNode<LambdaExprNode>(ctx);
1437
1438 // Visit children
1439
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (ctx->paramLst()) {
1440 1 lambdaExprNode->hasParams = true;
1441
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 lambdaExprNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst()));
1442 }
1443
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 lambdaExprNode->lambdaExpr = std::any_cast<AssignExprNode *>(visit(ctx->assignExpr()));
1444
1445
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 return concludeNode(lambdaExprNode);
1446 }
1447
1448 29878 std::any ASTBuilder::visitDataType(SpiceParser::DataTypeContext *ctx) {
1449 29878 const auto dataTypeNode = createNode<DataTypeNode>(ctx);
1450
1451 // Visit children
1452
2/2
✓ Branch 1 taken 12632 times.
✓ Branch 2 taken 17246 times.
29878 if (ctx->specifierLst())
1453
4/6
✓ Branch 1 taken 12632 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 12631 times.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 12631 times.
✗ Branch 8 not taken.
12632 dataTypeNode->specifierLst = std::any_cast<SpecifierLstNode *>(visit(ctx->specifierLst()));
1454
3/6
✓ Branch 1 taken 29877 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 29877 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 29877 times.
✗ Branch 8 not taken.
29877 dataTypeNode->baseDataType = std::any_cast<BaseDataTypeNode *>(visit(ctx->baseDataType()));
1455
1456 // Enrich
1457
2/2
✓ Branch 1 taken 49794 times.
✓ Branch 2 taken 29877 times.
79671 for (size_t i = 0; i < ctx->children.size(); i++) {
1458 49794 antlr4::tree::ParseTree *subTree = ctx->children.at(i);
1459
1/2
✓ Branch 0 taken 49794 times.
✗ Branch 1 not taken.
49794 auto terminal = dynamic_cast<TerminalNode *>(subTree);
1460
2/2
✓ Branch 0 taken 42508 times.
✓ Branch 1 taken 7286 times.
49794 if (!terminal)
1461 42508 continue;
1462
1463
2/2
✓ Branch 2 taken 3734 times.
✓ Branch 3 taken 3552 times.
7286 if (terminal->getSymbol()->getType() == SpiceParser::MUL) {
1464
1/2
✓ Branch 1 taken 3734 times.
✗ Branch 2 not taken.
3734 dataTypeNode->tmQueue.emplace(DataTypeNode::TYPE_PTR, false, 0);
1465
2/2
✓ Branch 2 taken 3457 times.
✓ Branch 3 taken 95 times.
3552 } else if (terminal->getSymbol()->getType() == SpiceParser::BITWISE_AND) {
1466
1/2
✓ Branch 1 taken 3457 times.
✗ Branch 2 not taken.
3457 dataTypeNode->tmQueue.emplace(DataTypeNode::TYPE_REF, false, 0);
1467
1/2
✓ Branch 2 taken 95 times.
✗ Branch 3 not taken.
95 } else if (terminal->getSymbol()->getType() == SpiceParser::LBRACKET) {
1468 95 i++; // Consume LBRACKET
1469
1/2
✓ Branch 1 taken 95 times.
✗ Branch 2 not taken.
95 subTree = ctx->children.at(i);
1470
1/2
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
95 terminal = dynamic_cast<TerminalNode *>(subTree);
1471 95 bool hasSize = false;
1472 95 unsigned int hardCodedSize = 0;
1473 95 std::string sizeVarName;
1474
4/6
✓ Branch 1 taken 95 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 95 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 41 times.
✓ Branch 7 taken 54 times.
95 if (terminal->getSymbol()->getType() == SpiceParser::INT_LIT) {
1475 41 hasSize = true;
1476
3/6
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 41 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 41 times.
✗ Branch 8 not taken.
41 hardCodedSize = std::stoi(terminal->getSymbol()->getText());
1477 41 i++; // Consume INT_LIT
1478
4/6
✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
✓ Branch 7 taken 30 times.
54 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1479 24 hasSize = true;
1480
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 sizeVarName = getIdentifier(terminal);
1481 24 i++; // Consume TYPE_IDENTIFIER
1482 }
1483
1/2
✓ Branch 1 taken 95 times.
✗ Branch 2 not taken.
95 dataTypeNode->tmQueue.push({DataTypeNode::TYPE_ARRAY, hasSize, hardCodedSize, sizeVarName});
1484 95 }
1485 }
1486
1487
2/4
✓ Branch 1 taken 29877 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 29877 times.
✗ Branch 5 not taken.
29877 return concludeNode(dataTypeNode);
1488
1/2
✓ Branch 1 taken 95 times.
✗ Branch 2 not taken.
95 }
1489
1490 29877 std::any ASTBuilder::visitBaseDataType(SpiceParser::BaseDataTypeContext *ctx) {
1491 29877 const auto baseDataTypeNode = createNode<BaseDataTypeNode>(ctx);
1492
1493 // Enrich
1494
2/2
✓ Branch 1 taken 156 times.
✓ Branch 2 taken 29721 times.
29877 if (ctx->TYPE_DOUBLE()) {
1495 156 baseDataTypeNode->type = BaseDataTypeNode::TYPE_DOUBLE;
1496
2/2
✓ Branch 1 taken 1985 times.
✓ Branch 2 taken 27736 times.
29721 } else if (ctx->TYPE_INT()) {
1497 1985 baseDataTypeNode->type = BaseDataTypeNode::TYPE_INT;
1498
2/2
✓ Branch 1 taken 316 times.
✓ Branch 2 taken 27420 times.
27736 } else if (ctx->TYPE_SHORT()) {
1499 316 baseDataTypeNode->type = BaseDataTypeNode::TYPE_SHORT;
1500
2/2
✓ Branch 1 taken 6862 times.
✓ Branch 2 taken 20558 times.
27420 } else if (ctx->TYPE_LONG()) {
1501 6862 baseDataTypeNode->type = BaseDataTypeNode::TYPE_LONG;
1502
2/2
✓ Branch 1 taken 1353 times.
✓ Branch 2 taken 19205 times.
20558 } else if (ctx->TYPE_BYTE()) {
1503 1353 baseDataTypeNode->type = BaseDataTypeNode::TYPE_BYTE;
1504
2/2
✓ Branch 1 taken 2446 times.
✓ Branch 2 taken 16759 times.
19205 } else if (ctx->TYPE_CHAR()) {
1505 2446 baseDataTypeNode->type = BaseDataTypeNode::TYPE_CHAR;
1506
2/2
✓ Branch 1 taken 3193 times.
✓ Branch 2 taken 13566 times.
16759 } else if (ctx->TYPE_STRING()) {
1507 3193 baseDataTypeNode->type = BaseDataTypeNode::TYPE_STRING;
1508
2/2
✓ Branch 1 taken 1940 times.
✓ Branch 2 taken 11626 times.
13566 } else if (ctx->TYPE_BOOL()) {
1509 1940 baseDataTypeNode->type = BaseDataTypeNode::TYPE_BOOL;
1510
2/2
✓ Branch 1 taken 347 times.
✓ Branch 2 taken 11279 times.
11626 } else if (ctx->TYPE_DYN()) {
1511 347 baseDataTypeNode->type = BaseDataTypeNode::TYPE_DYN;
1512
2/2
✓ Branch 1 taken 11202 times.
✓ Branch 2 taken 77 times.
11279 } else if (ctx->customDataType()) {
1513 11202 baseDataTypeNode->type = BaseDataTypeNode::TYPE_CUSTOM;
1514
3/6
✓ Branch 1 taken 11202 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11202 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11202 times.
✗ Branch 8 not taken.
11202 baseDataTypeNode->customDataType = std::any_cast<CustomDataTypeNode *>(visit(ctx->customDataType()));
1515
1/2
✓ Branch 1 taken 77 times.
✗ Branch 2 not taken.
77 } else if (ctx->functionDataType()) {
1516 77 baseDataTypeNode->type = BaseDataTypeNode::TYPE_FUNCTION;
1517
3/6
✓ Branch 1 taken 77 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 77 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 77 times.
✗ Branch 8 not taken.
77 baseDataTypeNode->functionDataType = std::any_cast<FunctionDataTypeNode *>(visit(ctx->functionDataType()));
1518 } else {
1519 assert_fail("Unknown base data type");
1520 }
1521
1522
2/4
✓ Branch 1 taken 29877 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 29877 times.
✗ Branch 5 not taken.
29877 return concludeNode(baseDataTypeNode);
1523 }
1524
1525 11202 std::any ASTBuilder::visitCustomDataType(SpiceParser::CustomDataTypeContext *ctx) {
1526 11202 const auto customDataTypeNode = createNode<CustomDataTypeNode>(ctx);
1527
1528 // Enrich
1529
2/2
✓ Branch 5 taken 16207 times.
✓ Branch 6 taken 11202 times.
27409 for (ParserRuleContext::ParseTree *subTree : ctx->children) {
1530
1/2
✓ Branch 0 taken 16207 times.
✗ Branch 1 not taken.
16207 const auto terminal = dynamic_cast<TerminalNode *>(subTree);
1531
2/2
✓ Branch 0 taken 1651 times.
✓ Branch 1 taken 14556 times.
16207 if (!terminal)
1532 1651 continue;
1533
1534
4/6
✓ Branch 1 taken 14556 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14556 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 26 times.
✓ Branch 7 taken 14530 times.
14556 if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) {
1535
1/2
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
26 const std::string fragment = terminal->toString();
1536
1/2
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
26 customDataTypeNode->typeNameFragments.push_back(fragment);
1537
2/4
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
26 customDataTypeNode->fqTypeName += fragment + SCOPE_ACCESS_TOKEN;
1538
4/6
✓ Branch 2 taken 14530 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 14530 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 11202 times.
✓ Branch 8 taken 3328 times.
14556 } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) {
1539
1/2
✓ Branch 1 taken 11202 times.
✗ Branch 2 not taken.
11202 const std::string fragment = terminal->toString();
1540
1/2
✓ Branch 1 taken 11202 times.
✗ Branch 2 not taken.
11202 customDataTypeNode->typeNameFragments.push_back(fragment);
1541
1/2
✓ Branch 1 taken 11202 times.
✗ Branch 2 not taken.
11202 customDataTypeNode->fqTypeName += fragment;
1542 11202 }
1543 }
1544
1545 // Visit children
1546
2/2
✓ Branch 1 taken 1651 times.
✓ Branch 2 taken 9551 times.
11202 if (ctx->typeLst())
1547
3/6
✓ Branch 1 taken 1651 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1651 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1651 times.
✗ Branch 8 not taken.
1651 customDataTypeNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1548
1549
2/4
✓ Branch 1 taken 11202 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11202 times.
✗ Branch 5 not taken.
11202 return concludeNode(customDataTypeNode);
1550 }
1551
1552 77 std::any ASTBuilder::visitFunctionDataType(SpiceParser::FunctionDataTypeContext *ctx) {
1553 77 const auto functionDataTypeNode = createNode<FunctionDataTypeNode>(ctx);
1554
1555 // Enrich
1556
2/2
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 56 times.
77 if (ctx->dataType()) {
1557 21 functionDataTypeNode->isFunction = ctx->dataType();
1558
3/6
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 21 times.
✗ Branch 8 not taken.
21 functionDataTypeNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType()));
1559 }
1560
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 29 times.
77 if (ctx->typeLst())
1561
3/6
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 48 times.
✗ Branch 8 not taken.
48 functionDataTypeNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst()));
1562
1563
2/4
✓ Branch 1 taken 77 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 77 times.
✗ Branch 5 not taken.
77 return concludeNode(functionDataTypeNode);
1564 }
1565
1566 5416 std::any ASTBuilder::visitAssignOp(SpiceParser::AssignOpContext *ctx) {
1567
1/2
✓ Branch 1 taken 5416 times.
✗ Branch 2 not taken.
5416 const auto assignExprNode = spice_pointer_cast<AssignExprNode *>(parentStack.top());
1568
1569 // Extract assign operator
1570
2/2
✓ Branch 1 taken 4864 times.
✓ Branch 2 taken 552 times.
5416 if (ctx->ASSIGN())
1571 4864 assignExprNode->op = AssignExprNode::OP_ASSIGN;
1572
2/2
✓ Branch 1 taken 222 times.
✓ Branch 2 taken 330 times.
552 else if (ctx->PLUS_EQUAL())
1573 222 assignExprNode->op = AssignExprNode::OP_PLUS_EQUAL;
1574
2/2
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 287 times.
330 else if (ctx->MINUS_EQUAL())
1575 43 assignExprNode->op = AssignExprNode::OP_MINUS_EQUAL;
1576
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 277 times.
287 else if (ctx->MUL_EQUAL())
1577 10 assignExprNode->op = AssignExprNode::OP_MUL_EQUAL;
1578
2/2
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 242 times.
277 else if (ctx->DIV_EQUAL())
1579 35 assignExprNode->op = AssignExprNode::OP_DIV_EQUAL;
1580
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 236 times.
242 else if (ctx->REM_EQUAL())
1581 6 assignExprNode->op = AssignExprNode::OP_REM_EQUAL;
1582
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 235 times.
236 else if (ctx->SHL_EQUAL())
1583 1 assignExprNode->op = AssignExprNode::OP_SHL_EQUAL;
1584
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 233 times.
235 else if (ctx->SHR_EQUAL())
1585 2 assignExprNode->op = AssignExprNode::OP_SHR_EQUAL;
1586
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 232 times.
233 else if (ctx->AND_EQUAL())
1587 1 assignExprNode->op = AssignExprNode::OP_AND_EQUAL;
1588
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 231 times.
232 else if (ctx->OR_EQUAL())
1589 1 assignExprNode->op = AssignExprNode::OP_OR_EQUAL;
1590
1/2
✓ Branch 1 taken 231 times.
✗ Branch 2 not taken.
231 else if (ctx->XOR_EQUAL())
1591 231 assignExprNode->op = AssignExprNode::OP_XOR_EQUAL;
1592 else
1593 assert_fail("Unknown assign operator");
1594
1595
1/2
✓ Branch 1 taken 5416 times.
✗ Branch 2 not taken.
5416 return nullptr;
1596 }
1597
1598 1230 std::any ASTBuilder::visitOverloadableOp(SpiceParser::OverloadableOpContext *ctx) {
1599
1/2
✓ Branch 1 taken 1230 times.
✗ Branch 2 not taken.
1230 const auto fctNameNode = spice_pointer_cast<FctNameNode *>(parentStack.top());
1600
1601 // Enrich
1602
2/2
✓ Branch 1 taken 78 times.
✓ Branch 2 taken 1152 times.
1230 if (ctx->PLUS())
1603 78 fctNameNode->name = OP_FCT_PLUS;
1604
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1151 times.
1152 else if (ctx->MINUS())
1605 1 fctNameNode->name = OP_FCT_MINUS;
1606
2/2
✓ Branch 1 taken 155 times.
✓ Branch 2 taken 996 times.
1151 else if (ctx->MUL())
1607 155 fctNameNode->name = OP_FCT_MUL;
1608
2/2
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 977 times.
996 else if (ctx->DIV())
1609 19 fctNameNode->name = OP_FCT_DIV;
1610
2/2
✓ Branch 1 taken 342 times.
✓ Branch 2 taken 635 times.
977 else if (ctx->EQUAL())
1611 342 fctNameNode->name = OP_FCT_EQUAL;
1612
2/2
✓ Branch 1 taken 340 times.
✓ Branch 2 taken 295 times.
635 else if (ctx->NOT_EQUAL())
1613 340 fctNameNode->name = OP_FCT_NOT_EQUAL;
1614
3/4
✓ Branch 1 taken 295 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 294 times.
295 else if (ctx->LESS().size() == 2)
1615 1 fctNameNode->name = OP_FCT_SHL;
1616
3/4
✓ Branch 1 taken 294 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 293 times.
294 else if (ctx->GREATER().size() == 2)
1617 1 fctNameNode->name = OP_FCT_SHR;
1618
2/2
✓ Branch 1 taken 106 times.
✓ Branch 2 taken 187 times.
293 else if (ctx->PLUS_EQUAL())
1619 106 fctNameNode->name = OP_FCT_PLUS_EQUAL;
1620
2/2
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 158 times.
187 else if (ctx->MINUS_EQUAL())
1621 29 fctNameNode->name = OP_FCT_MINUS_EQUAL;
1622
2/2
✓ Branch 1 taken 78 times.
✓ Branch 2 taken 80 times.
158 else if (ctx->MUL_EQUAL())
1623 78 fctNameNode->name = OP_FCT_MUL_EQUAL;
1624
2/2
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 61 times.
80 else if (ctx->DIV_EQUAL())
1625 19 fctNameNode->name = OP_FCT_DIV_EQUAL;
1626
2/2
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 28 times.
61 else if (ctx->PLUS_PLUS())
1627 33 fctNameNode->name = OP_FCT_POSTFIX_PLUS_PLUS;
1628
1/2
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
28 else if (ctx->MINUS_MINUS())
1629 28 fctNameNode->name = OP_FCT_POSTFIX_MINUS_MINUS;
1630 else
1631 assert_fail("Unsupported overloadable operator"); // GCOV_EXCL_LINE
1632
1633 1230 fctNameNode->fqName = fctNameNode->name;
1634 1230 fctNameNode->nameFragments.push_back(fctNameNode->name);
1635
1636
1/2
✓ Branch 1 taken 1230 times.
✗ Branch 2 not taken.
1230 return nullptr;
1637 }
1638
1639 2055596 template <typename T> T *ASTBuilder::createNode(const ParserRuleContext *ctx) {
1640 2055596 ASTNode *parent = nullptr;
1641 if constexpr (!std::is_same_v<T, EntryNode>)
1642 2053798 parent = parentStack.top();
1643
1644 // Create the new node
1645
2/4
✓ Branch 1 taken 1027798 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1027798 times.
✗ Branch 5 not taken.
4111192 T *node = resourceManager.astNodeAlloc.allocate<T>(getCodeLoc(ctx));
1646
1647 // If this is not the entry node, we need to add the new node to its parent
1648 if constexpr (!std::is_same_v<T, EntryNode>)
1649 2053798 parent->addChild(node);
1650
1651 // This node is the parent for its children
1652
1/2
✓ Branch 1 taken 1027798 times.
✗ Branch 2 not taken.
2055596 parentStack.push(node);
1653
1654 2055596 return node;
1655 }
1656
1657
1/2
✓ Branch 1 taken 1071 times.
✗ Branch 2 not taken.
4284 template <typename T> T *ASTBuilder::resumeForExpansion() { return spice_pointer_cast<T *>(parentStack.top()); }
1658
1659 2055484 template <typename T> T *ASTBuilder::concludeNode(T *node) {
1660 // This node is no longer the parent for its children
1661
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1027742 times.
2055484 assert(parentStack.top() == node);
1662 2055484 parentStack.pop();
1663 2055484 return node;
1664 }
1665
1666 3404 int32_t ASTBuilder::parseInt(TerminalNode *terminal) {
1667 6808 const NumericParserCallback<int32_t> cb = [](const std::string &substr, short base, bool isSigned) -> int32_t {
1668 // Prepare limits
1669
2/2
✓ Branch 0 taken 3401 times.
✓ Branch 1 taken 3 times.
3404 const int64_t upperLimit = isSigned ? INT32_MAX : UINT32_MAX;
1670
2/2
✓ Branch 0 taken 3401 times.
✓ Branch 1 taken 3 times.
3404 const int64_t lowerLimit = isSigned ? INT32_MIN : 0;
1671 // Parse number and check for limits
1672 3404 const int64_t number = std::stoll(substr, nullptr, base);
1673
2/4
✓ Branch 0 taken 3403 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3403 times.
3403 if (number < lowerLimit || number > upperLimit)
1674 throw std::out_of_range("Number out of range");
1675 3403 return static_cast<int32_t>(number);
1676 3404 };
1677
2/2
✓ Branch 1 taken 3403 times.
✓ Branch 2 taken 1 times.
6807 return parseNumeric(terminal, cb);
1678 3404 }
1679
1680 177 int16_t ASTBuilder::parseShort(TerminalNode *terminal) {
1681 354 const NumericParserCallback<int16_t> cb = [](const std::string &substr, short base, bool isSigned) -> int16_t {
1682 // Prepare limits
1683
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 1 times.
177 const int64_t upperLimit = isSigned ? INT16_MAX : UINT16_MAX;
1684
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 1 times.
177 const int64_t lowerLimit = isSigned ? INT16_MIN : 0;
1685 // Parse number and check for limits
1686 177 const int64_t number = std::stoll(substr, nullptr, base);
1687
2/4
✓ Branch 0 taken 177 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 177 times.
177 if (number < lowerLimit || number > upperLimit)
1688 throw std::out_of_range("Number out of range");
1689 177 return static_cast<int16_t>(number);
1690 177 };
1691
1/2
✓ Branch 1 taken 177 times.
✗ Branch 2 not taken.
354 return parseNumeric(terminal, cb);
1692 177 }
1693
1694 4078 int64_t ASTBuilder::parseLong(TerminalNode *terminal) {
1695 8156 const NumericParserCallback<int64_t> cb = [](const std::string &substr, short base, bool isSigned) -> int64_t {
1696
2/2
✓ Branch 0 taken 4072 times.
✓ Branch 1 taken 6 times.
4078 if (isSigned)
1697 4072 return std::stoll(substr, nullptr, base);
1698 else
1699 6 return static_cast<int64_t>(std::stoull(substr, nullptr, base));
1700 4078 };
1701
1/2
✓ Branch 1 taken 4078 times.
✗ Branch 2 not taken.
8156 return parseNumeric(terminal, cb);
1702 4078 }
1703
1704 887 int8_t ASTBuilder::parseChar(TerminalNode *terminal) const {
1705
1/2
✓ Branch 1 taken 887 times.
✗ Branch 2 not taken.
887 const std::string input = terminal->toString();
1706
2/2
✓ Branch 1 taken 230 times.
✓ Branch 2 taken 657 times.
887 if (input.length() == 3) { // Normal char literals
1707 230 return input[1];
1708
3/6
✓ Branch 1 taken 657 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 657 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 657 times.
✗ Branch 7 not taken.
657 } else if (input.length() == 4 && input[1] == '\\') { // Char literals with escape sequence
1709
7/11
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 618 times.
✓ Branch 11 taken 1 times.
657 switch (input[2]) {
1710 5 case '\'':
1711 5 return '\'';
1712 case '"':
1713 return '\"';
1714 10 case '\\':
1715 10 return '\\';
1716 15 case 'n':
1717 15 return '\n';
1718 4 case 'r':
1719 4 return '\r';
1720 4 case 't':
1721 4 return '\t';
1722 case 'b':
1723 return '\b';
1724 case 'f':
1725 return '\f';
1726 case 'v':
1727 return '\v';
1728 618 case '0':
1729 618 return '\0';
1730 1 default:
1731
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1732
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid escape sequence " + input);
1733 }
1734 } else {
1735 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1736 throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid char literal " + input);
1737 }
1738 887 }
1739
1740 1717 std::string ASTBuilder::parseString(std::string input) {
1741
1/2
✓ Branch 2 taken 1717 times.
✗ Branch 3 not taken.
1717 input = input.substr(1, input.size() - 2);
1742 1717 replaceEscapeChars(input);
1743 1717 return input;
1744 }
1745
1746 15318 template <typename T> T ASTBuilder::parseNumeric(TerminalNode *terminal, const NumericParserCallback<T> &cb) {
1747
1/2
✓ Branch 1 taken 7659 times.
✗ Branch 2 not taken.
15318 const std::string input = terminal->toString();
1748
1749 // Set to signed if the input string does not end with 'u'
1750
6/6
✓ Branch 1 taken 7656 times.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 7655 times.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 7649 times.
15318 const bool isUnsigned = input.ends_with('u') || input.ends_with("us") || input.ends_with("ul");
1751
1752 try {
1753
2/2
✓ Branch 1 taken 1458 times.
✓ Branch 2 taken 6201 times.
15318 if (input.length() >= 3) {
1754
2/2
✓ Branch 1 taken 281 times.
✓ Branch 2 taken 1177 times.
2916 if (input[0] == '0') {
1755
1/2
✓ Branch 1 taken 281 times.
✗ Branch 2 not taken.
562 const std::string subStr = input.substr(2);
1756
3/4
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 275 times.
✓ Branch 4 taken 3 times.
562 switch (input[1]) {
1757 case 'b':
1758 case 'B':
1759 return cb(subStr, 2, !isUnsigned);
1760 6 case 'h':
1761 case 'H':
1762 case 'x':
1763 case 'X':
1764
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
6 return cb(subStr, 16, !isUnsigned);
1765 550 case 'o':
1766 case 'O':
1767
1/2
✓ Branch 1 taken 275 times.
✗ Branch 2 not taken.
550 return cb(subStr, 8, !isUnsigned);
1768 6 default:
1769
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
6 return cb(input, 10, !isUnsigned);
1770 }
1771 562 }
1772 }
1773
2/2
✓ Branch 1 taken 7377 times.
✓ Branch 2 taken 1 times.
14756 return cb(input, 10, !isUnsigned);
1774
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
4 } catch (std::out_of_range &) {
1775
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1776
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
6 throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "The provided number is out of range");
1777 } catch (std::invalid_argument &) {
1778 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1779 throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "You tried to parse '" + input + "' as an integer, but it was no integer");
1780 }
1781 15318 }
1782
1783 2391 void ASTBuilder::replaceEscapeChars(std::string &input) {
1784 std::unordered_map<char, char> escapeMap = {
1785 {'a', '\a'}, {'b', '\b'}, {'f', '\f'}, {'n', '\n'}, {'r', '\r'}, {'t', '\t'},
1786 {'v', '\v'}, {'\\', '\\'}, {'?', '\?'}, {'\'', '\''}, {'"', '\"'},
1787
1/2
✓ Branch 1 taken 2391 times.
✗ Branch 2 not taken.
4782 };
1788
1789 2391 size_t writeIndex = 0; // Index where the next character should be written
1790
2/2
✓ Branch 1 taken 31724 times.
✓ Branch 2 taken 2391 times.
34115 for (size_t readIndex = 0; readIndex < input.length(); ++readIndex, ++writeIndex) {
1791
5/6
✓ Branch 1 taken 526 times.
✓ Branch 2 taken 31198 times.
✓ Branch 4 taken 526 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 526 times.
✓ Branch 7 taken 31198 times.
31724 if (input[readIndex] == '\\' && readIndex + 1 < input.length()) {
1792 526 char nextChar = input[readIndex + 1];
1793
3/4
✓ Branch 1 taken 526 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 523 times.
✓ Branch 4 taken 3 times.
526 if (escapeMap.contains(nextChar)) {
1794 // If the next character forms a valid escape sequence, replace it
1795
1/2
✓ Branch 1 taken 523 times.
✗ Branch 2 not taken.
523 input[writeIndex] = escapeMap[nextChar];
1796 523 readIndex++; // Skip the next character as it's part of the escape sequence
1797 } else {
1798 // If it's not a valid escape sequence, just copy the backslash
1799 3 input[writeIndex] = input[readIndex];
1800 }
1801 } else {
1802
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 30920 times.
31198 if (writeIndex != readIndex) {
1803 // If we've made replacements, shift the current character to the write position
1804 278 input[writeIndex] = input[readIndex];
1805 }
1806 // If no replacements were needed, writeIndex and readIndex are the same, and this does nothing
1807 }
1808 }
1809 // Resize the string to remove the unused portion
1810
1/2
✓ Branch 1 taken 2391 times.
✗ Branch 2 not taken.
2391 input.resize(writeIndex);
1811 2391 }
1812
1813 76311 std::string ASTBuilder::getIdentifier(TerminalNode *terminal) const {
1814 76311 std::string identifier = terminal->getText();
1815
1816 // Check if the identifier is 'String' and this is no std source file
1817
6/10
✓ Branch 0 taken 5966 times.
✓ Branch 1 taken 70345 times.
✓ Branch 3 taken 5966 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5966 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 5966 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 5966 times.
76311 bool isReserved = !sourceFile->isStdFile && (identifier == STROBJ_NAME || identifier == RESULTOBJ_NAME);
1818 // Check if the list of reserved keywords contains the given identifier
1819
1/2
✓ Branch 1 taken 76311 times.
✗ Branch 2 not taken.
76311 isReserved |= std::ranges::find(RESERVED_KEYWORDS, identifier) != std::end(RESERVED_KEYWORDS);
1820 // Print error message
1821
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 76310 times.
76311 if (isReserved) {
1822
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 const CodeLoc codeLoc(terminal->getSymbol(), sourceFile);
1823
3/6
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
1 throw ParserError(codeLoc, RESERVED_KEYWORD, "'" + identifier + "' is a reserved keyword. Please use another name instead");
1824 }
1825
1826 76310 return identifier;
1827 1 }
1828
1829 } // namespace spice::compiler
1830