GCC Code Coverage Report


Directory: ../
File: src/ast/ASTBuilder.cpp
Date: 2025-08-26 18:26:32
Exec Total Coverage
Lines: 1109 1140 97.3%
Functions: 104 104 100.0%
Branches: 1543 2555 60.4%

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