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