src/ast/ASTBuilder.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "ASTBuilder.h" | ||
| 4 | |||
| 5 | #include <regex> | ||
| 6 | |||
| 7 | #include <SourceFile.h> | ||
| 8 | #include <ast/ASTNodes.h> | ||
| 9 | #include <ast/Attributes.h> | ||
| 10 | #include <exception/ParserError.h> | ||
| 11 | #include <typechecker/OpRuleManager.h> | ||
| 12 | #include <util/GlobalDefinitions.h> | ||
| 13 | |||
| 14 | namespace spice::compiler { | ||
| 15 | |||
| 16 | 5355 | ASTBuilder::ASTBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile, antlr4::ANTLRInputStream *inputStream) | |
| 17 |
1/2✓ Branch 4 → 5 taken 5355 times.
✗ Branch 4 → 7 not taken.
|
5355 | : CompilerPass(resourceManager, sourceFile), inputStream(inputStream) {} |
| 18 | |||
| 19 | 5351 | std::any ASTBuilder::visitEntry(SpiceParser::EntryContext *ctx) { | |
| 20 | 5351 | const auto entryNode = createNode<EntryNode>(ctx); | |
| 21 | |||
| 22 | // Visit children | ||
| 23 |
2/2✓ Branch 144 → 5 taken 98256 times.
✓ Branch 144 → 145 taken 5339 times.
|
108946 | for (ParserRuleContext::ParseTree *child : ctx->children) { |
| 24 |
3/4✓ Branch 7 → 8 taken 98256 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 1319 times.
✓ Branch 10 → 16 taken 96937 times.
|
98256 | if (auto *mainFctDefCtx = dynamic_cast<SpiceParser::MainFunctionDefContext *>(child)) |
| 25 |
4/6✓ Branch 11 → 12 taken 1311 times.
✓ Branch 11 → 160 taken 8 times.
✓ Branch 12 → 13 taken 1311 times.
✗ Branch 12 → 158 not taken.
✓ Branch 13 → 14 taken 1311 times.
✗ Branch 13 → 158 not taken.
|
1319 | entryNode->topLevelDefs.push_back(std::any_cast<MainFctDefNode *>(visit(mainFctDefCtx))); |
| 26 |
3/4✓ Branch 16 → 17 taken 96937 times.
✗ Branch 16 → 18 not taken.
✓ Branch 19 → 20 taken 38345 times.
✓ Branch 19 → 25 taken 58592 times.
|
96937 | else if (auto *fctDefCtx = dynamic_cast<SpiceParser::FunctionDefContext *>(child)) |
| 27 |
3/6✓ Branch 20 → 21 taken 38345 times.
✗ Branch 20 → 164 not taken.
✓ Branch 21 → 22 taken 38345 times.
✗ Branch 21 → 162 not taken.
✓ Branch 22 → 23 taken 38345 times.
✗ Branch 22 → 162 not taken.
|
38345 | entryNode->topLevelDefs.push_back(std::any_cast<FctDefNode *>(visit(fctDefCtx))); |
| 28 |
3/4✓ Branch 25 → 26 taken 58592 times.
✗ Branch 25 → 27 not taken.
✓ Branch 28 → 29 taken 24257 times.
✓ Branch 28 → 34 taken 34335 times.
|
58592 | else if (auto *procDefCtx = dynamic_cast<SpiceParser::ProcedureDefContext *>(child)) |
| 29 |
3/6✓ Branch 29 → 30 taken 24257 times.
✗ Branch 29 → 168 not taken.
✓ Branch 30 → 31 taken 24257 times.
✗ Branch 30 → 166 not taken.
✓ Branch 31 → 32 taken 24257 times.
✗ Branch 31 → 166 not taken.
|
24257 | entryNode->topLevelDefs.push_back(std::any_cast<ProcDefNode *>(visit(procDefCtx))); |
| 30 |
3/4✓ Branch 34 → 35 taken 34335 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 4310 times.
✓ Branch 37 → 43 taken 30025 times.
|
34335 | else if (auto *structDefCtx = dynamic_cast<SpiceParser::StructDefContext *>(child)) |
| 31 |
4/6✓ Branch 38 → 39 taken 4308 times.
✓ Branch 38 → 172 taken 2 times.
✓ Branch 39 → 40 taken 4308 times.
✗ Branch 39 → 170 not taken.
✓ Branch 40 → 41 taken 4308 times.
✗ Branch 40 → 170 not taken.
|
4310 | entryNode->topLevelDefs.push_back(std::any_cast<StructDefNode *>(visit(structDefCtx))); |
| 32 |
3/4✓ Branch 43 → 44 taken 30025 times.
✗ Branch 43 → 45 not taken.
✓ Branch 46 → 47 taken 437 times.
✓ Branch 46 → 52 taken 29588 times.
|
30025 | else if (auto *interfaceDefCtx = dynamic_cast<SpiceParser::InterfaceDefContext *>(child)) |
| 33 |
3/6✓ Branch 47 → 48 taken 437 times.
✗ Branch 47 → 176 not taken.
✓ Branch 48 → 49 taken 437 times.
✗ Branch 48 → 174 not taken.
✓ Branch 49 → 50 taken 437 times.
✗ Branch 49 → 174 not taken.
|
437 | entryNode->topLevelDefs.push_back(std::any_cast<InterfaceDefNode *>(visit(interfaceDefCtx))); |
| 34 |
3/4✓ Branch 52 → 53 taken 29588 times.
✗ Branch 52 → 54 not taken.
✓ Branch 55 → 56 taken 38 times.
✓ Branch 55 → 61 taken 29550 times.
|
29588 | else if (auto *unionDefCtx = dynamic_cast<SpiceParser::UnionDefContext *>(child)) |
| 35 |
3/6✓ Branch 56 → 57 taken 38 times.
✗ Branch 56 → 180 not taken.
✓ Branch 57 → 58 taken 38 times.
✗ Branch 57 → 178 not taken.
✓ Branch 58 → 59 taken 38 times.
✗ Branch 58 → 178 not taken.
|
38 | entryNode->topLevelDefs.push_back(std::any_cast<UnionDefNode *>(visit(unionDefCtx))); |
| 36 |
3/4✓ Branch 61 → 62 taken 29550 times.
✗ Branch 61 → 63 not taken.
✓ Branch 64 → 65 taken 714 times.
✓ Branch 64 → 70 taken 28836 times.
|
29550 | else if (auto *enumDefCtx = dynamic_cast<SpiceParser::EnumDefContext *>(child)) |
| 37 |
3/6✓ Branch 65 → 66 taken 714 times.
✗ Branch 65 → 184 not taken.
✓ Branch 66 → 67 taken 714 times.
✗ Branch 66 → 182 not taken.
✓ Branch 67 → 68 taken 714 times.
✗ Branch 67 → 182 not taken.
|
714 | entryNode->topLevelDefs.push_back(std::any_cast<EnumDefNode *>(visit(enumDefCtx))); |
| 38 |
3/4✓ Branch 70 → 71 taken 28836 times.
✗ Branch 70 → 72 not taken.
✓ Branch 73 → 74 taken 4204 times.
✓ Branch 73 → 79 taken 24632 times.
|
28836 | else if (auto *genericTypeDefCtx = dynamic_cast<SpiceParser::GenericTypeDefContext *>(child)) |
| 39 |
3/6✓ Branch 74 → 75 taken 4204 times.
✗ Branch 74 → 188 not taken.
✓ Branch 75 → 76 taken 4204 times.
✗ Branch 75 → 186 not taken.
✓ Branch 76 → 77 taken 4204 times.
✗ Branch 76 → 186 not taken.
|
4204 | entryNode->topLevelDefs.push_back(std::any_cast<GenericTypeDefNode *>(visit(genericTypeDefCtx))); |
| 40 |
3/4✓ Branch 79 → 80 taken 24632 times.
✗ Branch 79 → 81 not taken.
✓ Branch 82 → 83 taken 361 times.
✓ Branch 82 → 88 taken 24271 times.
|
24632 | else if (auto *aliasDefCtx = dynamic_cast<SpiceParser::AliasDefContext *>(child)) |
| 41 |
3/6✓ Branch 83 → 84 taken 361 times.
✗ Branch 83 → 192 not taken.
✓ Branch 84 → 85 taken 361 times.
✗ Branch 84 → 190 not taken.
✓ Branch 85 → 86 taken 361 times.
✗ Branch 85 → 190 not taken.
|
361 | entryNode->topLevelDefs.push_back(std::any_cast<AliasDefNode *>(visit(aliasDefCtx))); |
| 42 |
3/4✓ Branch 88 → 89 taken 24271 times.
✗ Branch 88 → 90 not taken.
✓ Branch 91 → 92 taken 5603 times.
✓ Branch 91 → 97 taken 18668 times.
|
24271 | else if (auto *globalVarDefCtx = dynamic_cast<SpiceParser::GlobalVarDefContext *>(child)) |
| 43 |
3/6✓ Branch 92 → 93 taken 5603 times.
✗ Branch 92 → 196 not taken.
✓ Branch 93 → 94 taken 5603 times.
✗ Branch 93 → 194 not taken.
✓ Branch 94 → 95 taken 5603 times.
✗ Branch 94 → 194 not taken.
|
5603 | entryNode->topLevelDefs.push_back(std::any_cast<GlobalVarDefNode *>(visit(globalVarDefCtx))); |
| 44 |
3/4✓ Branch 97 → 98 taken 18668 times.
✗ Branch 97 → 99 not taken.
✓ Branch 100 → 101 taken 3594 times.
✓ Branch 100 → 106 taken 15074 times.
|
18668 | else if (auto *importDefCtx = dynamic_cast<SpiceParser::ImportDefContext *>(child)) |
| 45 |
3/6✓ Branch 101 → 102 taken 3594 times.
✗ Branch 101 → 200 not taken.
✓ Branch 102 → 103 taken 3594 times.
✗ Branch 102 → 198 not taken.
✓ Branch 103 → 104 taken 3594 times.
✗ Branch 103 → 198 not taken.
|
3594 | entryNode->importDefs.push_back(std::any_cast<ImportDefNode *>(visit(importDefCtx))); |
| 46 |
3/4✓ Branch 106 → 107 taken 15074 times.
✗ Branch 106 → 108 not taken.
✓ Branch 109 → 110 taken 7618 times.
✓ Branch 109 → 115 taken 7456 times.
|
15074 | else if (auto *extDeclCtx = dynamic_cast<SpiceParser::ExtDeclContext *>(child)) |
| 47 |
3/6✓ Branch 110 → 111 taken 7618 times.
✗ Branch 110 → 204 not taken.
✓ Branch 111 → 112 taken 7618 times.
✗ Branch 111 → 202 not taken.
✓ Branch 112 → 113 taken 7618 times.
✗ Branch 112 → 202 not taken.
|
7618 | entryNode->topLevelDefs.push_back(std::any_cast<ExtDeclNode *>(visit(extDeclCtx))); |
| 48 |
3/4✓ Branch 115 → 116 taken 7456 times.
✗ Branch 115 → 117 not taken.
✓ Branch 118 → 119 taken 2117 times.
✓ Branch 118 → 124 taken 5339 times.
|
7456 | else if (auto *modAttrCtx = dynamic_cast<SpiceParser::ModAttrContext *>(child)) |
| 49 |
4/6✓ Branch 119 → 120 taken 2115 times.
✓ Branch 119 → 208 taken 2 times.
✓ Branch 120 → 121 taken 2115 times.
✗ Branch 120 → 206 not taken.
✓ Branch 121 → 122 taken 2115 times.
✗ Branch 121 → 206 not taken.
|
2117 | entryNode->modAttrs.push_back(std::any_cast<ModAttrNode *>(visit(modAttrCtx))); |
| 50 |
1/2✓ Branch 124 → 125 taken 5339 times.
✗ Branch 124 → 126 not taken.
|
5339 | else if (const auto *eofCtx = dynamic_cast<TerminalNode *>(child); |
| 51 |
5/10✓ Branch 127 → 128 taken 5339 times.
✗ Branch 127 → 131 not taken.
✓ Branch 128 → 129 taken 5339 times.
✗ Branch 128 → 210 not taken.
✓ Branch 129 → 130 taken 5339 times.
✗ Branch 129 → 210 not taken.
✗ Branch 130 → 131 not taken.
✓ Branch 130 → 132 taken 5339 times.
✗ Branch 133 → 134 not taken.
✓ Branch 133 → 135 taken 5339 times.
|
5339 | !eofCtx || eofCtx->getSymbol()->getType() != SpiceParser::EOF) |
| 52 | − | assert_fail("Unknown top level definition type"); // GCOV_EXCL_LINE | |
| 53 | } | ||
| 54 | |||
| 55 | // Hand over all switch statements of this file | ||
| 56 | 10678 | entryNode->switchStmts = std::move(switchStmts); | |
| 57 | |||
| 58 |
1/2✓ Branch 154 → 155 taken 5339 times.
✗ Branch 154 → 211 not taken.
|
10678 | return concludeNode(entryNode); |
| 59 | } | ||
| 60 | |||
| 61 | 1319 | std::any ASTBuilder::visitMainFunctionDef(SpiceParser::MainFunctionDefContext *ctx) { | |
| 62 | 1319 | const auto mainFctDefNode = createNode<MainFctDefNode>(ctx); | |
| 63 | |||
| 64 | // Visit children | ||
| 65 |
2/2✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 10 taken 1317 times.
|
1319 | if (ctx->topLevelDefAttr()) |
| 66 |
3/6✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 33 not taken.
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 33 not taken.
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 31 not taken.
|
2 | mainFctDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 67 |
2/2✓ Branch 11 → 12 taken 14 times.
✓ Branch 11 → 17 taken 1305 times.
|
1319 | if (ctx->paramLst()) { |
| 68 | 14 | mainFctDefNode->takesArgs = true; | |
| 69 |
3/6✓ Branch 12 → 13 taken 14 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 14 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 14 times.
✗ Branch 14 → 34 not taken.
|
14 | mainFctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 70 | } | ||
| 71 |
5/8✓ Branch 17 → 18 taken 1319 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 1311 times.
✓ Branch 18 → 39 taken 8 times.
✓ Branch 19 → 20 taken 1311 times.
✗ Branch 19 → 37 not taken.
✓ Branch 21 → 22 taken 1311 times.
✗ Branch 21 → 40 not taken.
|
1319 | mainFctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 72 | |||
| 73 |
1/2✓ Branch 27 → 28 taken 1311 times.
✗ Branch 27 → 40 not taken.
|
2622 | return concludeNode(mainFctDefNode); |
| 74 | } | ||
| 75 | |||
| 76 | 38345 | std::any ASTBuilder::visitFunctionDef(SpiceParser::FunctionDefContext *ctx) { | |
| 77 | 38345 | const auto fctDefNode = createNode<FctDefNode>(ctx); | |
| 78 | |||
| 79 | // Visit children | ||
| 80 |
2/2✓ Branch 4 → 5 taken 1404 times.
✓ Branch 4 → 24 taken 36941 times.
|
38345 | if (ctx->topLevelDefAttr()) { |
| 81 |
3/6✓ Branch 5 → 6 taken 1404 times.
✗ Branch 5 → 70 not taken.
✓ Branch 6 → 7 taken 1404 times.
✗ Branch 6 → 70 not taken.
✓ Branch 7 → 8 taken 1404 times.
✗ Branch 7 → 68 not taken.
|
1404 | fctDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 82 | // Tell the attributes that they are function attributes | ||
| 83 |
2/2✓ Branch 22 → 11 taken 1428 times.
✓ Branch 22 → 23 taken 1404 times.
|
4236 | for (AttrNode *attr : fctDefNode->attrs->attrLst->attributes) |
| 84 | 1428 | attr->target = AttrNode::TARGET_FCT_PROC; | |
| 85 | } | ||
| 86 |
2/2✓ Branch 25 → 26 taken 36572 times.
✓ Branch 25 → 31 taken 1773 times.
|
38345 | if (ctx->qualifierLst()) |
| 87 |
3/6✓ Branch 26 → 27 taken 36572 times.
✗ Branch 26 → 73 not taken.
✓ Branch 27 → 28 taken 36572 times.
✗ Branch 27 → 73 not taken.
✓ Branch 28 → 29 taken 36572 times.
✗ Branch 28 → 71 not taken.
|
36572 | fctDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 88 |
3/6✓ Branch 31 → 32 taken 38345 times.
✗ Branch 31 → 76 not taken.
✓ Branch 32 → 33 taken 38345 times.
✗ Branch 32 → 76 not taken.
✓ Branch 33 → 34 taken 38345 times.
✗ Branch 33 → 74 not taken.
|
38345 | fctDefNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 89 | 38345 | fctDefNode->returnType->isReturnType = true; | |
| 90 |
3/6✓ Branch 35 → 36 taken 38345 times.
✗ Branch 35 → 79 not taken.
✓ Branch 36 → 37 taken 38345 times.
✗ Branch 36 → 79 not taken.
✓ Branch 37 → 38 taken 38345 times.
✗ Branch 37 → 77 not taken.
|
38345 | fctDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName())); |
| 91 | 38345 | fctDefNode->isMethod = fctDefNode->name->nameFragments.size() > 1; | |
| 92 |
2/2✓ Branch 41 → 42 taken 4586 times.
✓ Branch 41 → 47 taken 33759 times.
|
38345 | if (ctx->typeLst()) { |
| 93 | 4586 | fctDefNode->hasTemplateTypes = true; | |
| 94 |
3/6✓ Branch 42 → 43 taken 4586 times.
✗ Branch 42 → 82 not taken.
✓ Branch 43 → 44 taken 4586 times.
✗ Branch 43 → 82 not taken.
✓ Branch 44 → 45 taken 4586 times.
✗ Branch 44 → 80 not taken.
|
4586 | fctDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 95 | } | ||
| 96 |
2/2✓ Branch 48 → 49 taken 27730 times.
✓ Branch 48 → 54 taken 10615 times.
|
38345 | if (ctx->paramLst()) { |
| 97 | 27730 | fctDefNode->hasParams = true; | |
| 98 |
3/6✓ Branch 49 → 50 taken 27730 times.
✗ Branch 49 → 85 not taken.
✓ Branch 50 → 51 taken 27730 times.
✗ Branch 50 → 85 not taken.
✓ Branch 51 → 52 taken 27730 times.
✗ Branch 51 → 83 not taken.
|
27730 | fctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 99 | } | ||
| 100 |
4/8✓ Branch 54 → 55 taken 38345 times.
✗ Branch 54 → 88 not taken.
✓ Branch 55 → 56 taken 38345 times.
✗ Branch 55 → 88 not taken.
✓ Branch 56 → 57 taken 38345 times.
✗ Branch 56 → 86 not taken.
✓ Branch 58 → 59 taken 38345 times.
✗ Branch 58 → 89 not taken.
|
38345 | fctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 101 | |||
| 102 |
1/2✓ Branch 64 → 65 taken 38345 times.
✗ Branch 64 → 89 not taken.
|
76690 | return concludeNode(fctDefNode); |
| 103 | } | ||
| 104 | |||
| 105 | 24257 | std::any ASTBuilder::visitProcedureDef(SpiceParser::ProcedureDefContext *ctx) { | |
| 106 | 24257 | const auto procDefNode = createNode<ProcDefNode>(ctx); | |
| 107 | |||
| 108 | // Visit children | ||
| 109 |
2/2✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 24 taken 24255 times.
|
24257 | if (ctx->topLevelDefAttr()) { |
| 110 |
3/6✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 66 not taken.
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 66 not taken.
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 64 not taken.
|
2 | procDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 111 | // Tell the attributes that they are function attributes | ||
| 112 |
2/2✓ Branch 22 → 11 taken 2 times.
✓ Branch 22 → 23 taken 2 times.
|
6 | for (AttrNode *attr : procDefNode->attrs->attrLst->attributes) |
| 113 | 2 | attr->target = AttrNode::TARGET_FCT_PROC; | |
| 114 | } | ||
| 115 |
2/2✓ Branch 25 → 26 taken 19784 times.
✓ Branch 25 → 31 taken 4473 times.
|
24257 | if (ctx->qualifierLst()) |
| 116 |
3/6✓ Branch 26 → 27 taken 19784 times.
✗ Branch 26 → 69 not taken.
✓ Branch 27 → 28 taken 19784 times.
✗ Branch 27 → 69 not taken.
✓ Branch 28 → 29 taken 19784 times.
✗ Branch 28 → 67 not taken.
|
19784 | procDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 117 |
3/6✓ Branch 31 → 32 taken 24257 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 24257 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 24257 times.
✗ Branch 33 → 70 not taken.
|
24257 | procDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName())); |
| 118 | 24257 | procDefNode->isMethod = procDefNode->name->nameFragments.size() > 1; | |
| 119 |
2/2✓ Branch 37 → 38 taken 4767 times.
✓ Branch 37 → 43 taken 19490 times.
|
24257 | if (ctx->typeLst()) { |
| 120 | 4767 | procDefNode->hasTemplateTypes = true; | |
| 121 |
3/6✓ Branch 38 → 39 taken 4767 times.
✗ Branch 38 → 75 not taken.
✓ Branch 39 → 40 taken 4767 times.
✗ Branch 39 → 75 not taken.
✓ Branch 40 → 41 taken 4767 times.
✗ Branch 40 → 73 not taken.
|
4767 | procDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 122 | } | ||
| 123 |
2/2✓ Branch 44 → 45 taken 17363 times.
✓ Branch 44 → 50 taken 6894 times.
|
24257 | if (ctx->paramLst()) { |
| 124 | 17363 | procDefNode->hasParams = true; | |
| 125 |
3/6✓ Branch 45 → 46 taken 17363 times.
✗ Branch 45 → 78 not taken.
✓ Branch 46 → 47 taken 17363 times.
✗ Branch 46 → 78 not taken.
✓ Branch 47 → 48 taken 17363 times.
✗ Branch 47 → 76 not taken.
|
17363 | procDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 126 | } | ||
| 127 |
4/8✓ Branch 50 → 51 taken 24257 times.
✗ Branch 50 → 81 not taken.
✓ Branch 51 → 52 taken 24257 times.
✗ Branch 51 → 81 not taken.
✓ Branch 52 → 53 taken 24257 times.
✗ Branch 52 → 79 not taken.
✓ Branch 54 → 55 taken 24257 times.
✗ Branch 54 → 82 not taken.
|
24257 | procDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 128 | |||
| 129 |
1/2✓ Branch 60 → 61 taken 24257 times.
✗ Branch 60 → 82 not taken.
|
48514 | return concludeNode(procDefNode); |
| 130 | } | ||
| 131 | |||
| 132 | 62602 | std::any ASTBuilder::visitFctName(SpiceParser::FctNameContext *ctx) { | |
| 133 |
1/2✓ Branch 2 → 3 taken 62602 times.
✗ Branch 2 → 54 not taken.
|
62602 | const auto fctNameNode = createNode<FctNameNode>(ctx); |
| 134 | |||
| 135 | // Extract function name | ||
| 136 |
1/2✓ Branch 3 → 4 taken 62602 times.
✗ Branch 3 → 54 not taken.
|
62602 | std::stringstream fqName; |
| 137 |
3/4✓ Branch 4 → 5 taken 62602 times.
✗ Branch 4 → 52 not taken.
✓ Branch 5 → 6 taken 37116 times.
✓ Branch 5 → 14 taken 25486 times.
|
62602 | if (ctx->TYPE_IDENTIFIER()) { |
| 138 |
2/4✓ Branch 6 → 7 taken 37116 times.
✗ Branch 6 → 45 not taken.
✓ Branch 7 → 8 taken 37116 times.
✗ Branch 7 → 45 not taken.
|
37116 | const std::string typeIdentifier = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 139 |
1/2✓ Branch 8 → 9 taken 37116 times.
✗ Branch 8 → 43 not taken.
|
37116 | fctNameNode->structName = typeIdentifier; |
| 140 |
2/4✓ Branch 9 → 10 taken 37116 times.
✗ Branch 9 → 43 not taken.
✓ Branch 10 → 11 taken 37116 times.
✗ Branch 10 → 43 not taken.
|
37116 | fqName << typeIdentifier << MEMBER_ACCESS_TOKEN; |
| 141 |
1/2✓ Branch 11 → 12 taken 37116 times.
✗ Branch 11 → 43 not taken.
|
37116 | fctNameNode->nameFragments.push_back(typeIdentifier); |
| 142 | 37116 | } | |
| 143 |
3/4✓ Branch 14 → 15 taken 62602 times.
✗ Branch 14 → 52 not taken.
✓ Branch 15 → 16 taken 55118 times.
✓ Branch 15 → 23 taken 7484 times.
|
62602 | if (ctx->IDENTIFIER()) { |
| 144 |
2/4✓ Branch 16 → 17 taken 55118 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 55118 times.
✗ Branch 17 → 48 not taken.
|
55118 | const std::string fctIdentifier = getIdentifier(ctx->IDENTIFIER(), false); |
| 145 |
1/2✓ Branch 18 → 19 taken 55118 times.
✗ Branch 18 → 46 not taken.
|
55118 | fctNameNode->name = fctIdentifier; |
| 146 |
1/2✓ Branch 19 → 20 taken 55118 times.
✗ Branch 19 → 46 not taken.
|
55118 | fqName << fctIdentifier; |
| 147 |
1/2✓ Branch 20 → 21 taken 55118 times.
✗ Branch 20 → 46 not taken.
|
55118 | fctNameNode->nameFragments.push_back(fctIdentifier); |
| 148 | 55118 | } | |
| 149 |
1/2✓ Branch 23 → 24 taken 62602 times.
✗ Branch 23 → 49 not taken.
|
62602 | fctNameNode->fqName = fqName.str(); |
| 150 | |||
| 151 | // Visit children | ||
| 152 |
3/4✓ Branch 26 → 27 taken 62602 times.
✗ Branch 26 → 52 not taken.
✓ Branch 27 → 28 taken 7484 times.
✓ Branch 27 → 32 taken 55118 times.
|
62602 | if (ctx->overloadableOp()) |
| 153 |
2/4✓ Branch 28 → 29 taken 7484 times.
✗ Branch 28 → 50 not taken.
✓ Branch 29 → 30 taken 7484 times.
✗ Branch 29 → 50 not taken.
|
7484 | visit(ctx->overloadableOp()); |
| 154 | |||
| 155 |
1/2✓ Branch 38 → 39 taken 62602 times.
✗ Branch 38 → 51 not taken.
|
125204 | return concludeNode(fctNameNode); |
| 156 | 62602 | } | |
| 157 | |||
| 158 | 4310 | std::any ASTBuilder::visitStructDef(SpiceParser::StructDefContext *ctx) { | |
| 159 | 4310 | const auto structDefNode = createNode<StructDefNode>(ctx); | |
| 160 | |||
| 161 | // Enrich | ||
| 162 |
3/4✓ Branch 3 → 4 taken 4310 times.
✗ Branch 3 → 103 not taken.
✓ Branch 4 → 5 taken 4308 times.
✓ Branch 4 → 103 taken 2 times.
|
4310 | structDefNode->structName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 163 | 4308 | structDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 164 | |||
| 165 | // Visit children | ||
| 166 |
2/2✓ Branch 9 → 10 taken 235 times.
✓ Branch 9 → 49 taken 4073 times.
|
4308 | if (ctx->topLevelDefAttr()) { |
| 167 |
3/6✓ Branch 10 → 11 taken 235 times.
✗ Branch 10 → 106 not taken.
✓ Branch 11 → 12 taken 235 times.
✗ Branch 11 → 106 not taken.
✓ Branch 12 → 13 taken 235 times.
✗ Branch 12 → 104 not taken.
|
235 | structDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 168 | |||
| 169 | // Tell the attributes that they are struct attributes | ||
| 170 |
2/2✓ Branch 27 → 16 taken 235 times.
✓ Branch 27 → 28 taken 235 times.
|
705 | for (AttrNode *attr : structDefNode->attrs->attrLst->attributes) |
| 171 | 235 | attr->target = AttrNode::TARGET_STRUCT; | |
| 172 | |||
| 173 | // Check if a custom type id was set | ||
| 174 |
7/18✓ Branch 28 → 29 taken 235 times.
✗ Branch 28 → 35 not taken.
✓ Branch 31 → 32 taken 235 times.
✗ Branch 31 → 107 not taken.
✓ Branch 32 → 33 taken 235 times.
✗ Branch 32 → 107 not taken.
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 235 times.
✓ Branch 36 → 37 taken 235 times.
✗ Branch 36 → 38 not taken.
✓ Branch 38 → 39 taken 235 times.
✗ Branch 38 → 41 not taken.
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 235 times.
✗ Branch 107 → 108 not taken.
✗ Branch 107 → 109 not taken.
✗ Branch 111 → 112 not taken.
✗ Branch 111 → 114 not taken.
|
705 | if (structDefNode->attrs && structDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID)) |
| 175 | ✗ | structDefNode->typeId = structDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue; | |
| 176 | } | ||
| 177 |
2/2✓ Branch 50 → 51 taken 2754 times.
✓ Branch 50 → 56 taken 1554 times.
|
4308 | if (ctx->qualifierLst()) |
| 178 |
3/6✓ Branch 51 → 52 taken 2754 times.
✗ Branch 51 → 124 not taken.
✓ Branch 52 → 53 taken 2754 times.
✗ Branch 52 → 124 not taken.
✓ Branch 53 → 54 taken 2754 times.
✗ Branch 53 → 122 not taken.
|
2754 | structDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 179 |
2/2✓ Branch 57 → 58 taken 1320 times.
✓ Branch 57 → 63 taken 2988 times.
|
4308 | if (ctx->LESS()) { |
| 180 | 1320 | structDefNode->hasTemplateTypes = true; | |
| 181 |
3/6✓ Branch 58 → 59 taken 1320 times.
✗ Branch 58 → 127 not taken.
✓ Branch 59 → 60 taken 1320 times.
✗ Branch 59 → 127 not taken.
✓ Branch 60 → 61 taken 1320 times.
✗ Branch 60 → 125 not taken.
|
1320 | structDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0))); |
| 182 | } | ||
| 183 |
2/2✓ Branch 64 → 65 taken 586 times.
✓ Branch 64 → 73 taken 3722 times.
|
4308 | if (ctx->COLON()) { |
| 184 | 586 | structDefNode->hasInterfaces = true; | |
| 185 |
5/8✓ Branch 65 → 66 taken 520 times.
✓ Branch 65 → 67 taken 66 times.
✓ Branch 68 → 69 taken 586 times.
✗ Branch 68 → 130 not taken.
✓ Branch 69 → 70 taken 586 times.
✗ Branch 69 → 130 not taken.
✓ Branch 70 → 71 taken 586 times.
✗ Branch 70 → 128 not taken.
|
586 | structDefNode->interfaceTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(structDefNode->hasTemplateTypes ? 1 : 0))); |
| 186 | } | ||
| 187 |
3/4✓ Branch 73 → 74 taken 4308 times.
✗ Branch 73 → 137 not taken.
✓ Branch 91 → 76 taken 10504 times.
✓ Branch 91 → 92 taken 4308 times.
|
19120 | for (SpiceParser::FieldContext *field : ctx->field()) |
| 188 |
3/6✓ Branch 78 → 79 taken 10504 times.
✗ Branch 78 → 133 not taken.
✓ Branch 79 → 80 taken 10504 times.
✗ Branch 79 → 131 not taken.
✓ Branch 80 → 81 taken 10504 times.
✗ Branch 80 → 131 not taken.
|
14812 | structDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field))); |
| 189 | |||
| 190 |
1/2✓ Branch 99 → 100 taken 4308 times.
✗ Branch 99 → 138 not taken.
|
8616 | return concludeNode(structDefNode); |
| 191 | } | ||
| 192 | |||
| 193 | 437 | std::any ASTBuilder::visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) { | |
| 194 | 437 | const auto interfaceDefNode = createNode<InterfaceDefNode>(ctx); | |
| 195 | |||
| 196 | // Enrich | ||
| 197 |
2/4✓ Branch 3 → 4 taken 437 times.
✗ Branch 3 → 93 not taken.
✓ Branch 4 → 5 taken 437 times.
✗ Branch 4 → 93 not taken.
|
437 | interfaceDefNode->interfaceName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 198 | 437 | interfaceDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 199 | |||
| 200 | // Visit children | ||
| 201 |
2/2✓ Branch 9 → 10 taken 346 times.
✓ Branch 9 → 49 taken 91 times.
|
437 | if (ctx->topLevelDefAttr()) { |
| 202 |
3/6✓ Branch 10 → 11 taken 346 times.
✗ Branch 10 → 96 not taken.
✓ Branch 11 → 12 taken 346 times.
✗ Branch 11 → 96 not taken.
✓ Branch 12 → 13 taken 346 times.
✗ Branch 12 → 94 not taken.
|
346 | interfaceDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 203 | |||
| 204 | // Tell the attributes that they are struct attributes | ||
| 205 |
2/2✓ Branch 27 → 16 taken 346 times.
✓ Branch 27 → 28 taken 346 times.
|
1038 | for (AttrNode *attr : interfaceDefNode->attrs->attrLst->attributes) |
| 206 | 346 | attr->target = AttrNode::TARGET_INTERFACE; | |
| 207 | |||
| 208 | // Check if a custom type id was set | ||
| 209 |
7/18✓ Branch 28 → 29 taken 346 times.
✗ Branch 28 → 35 not taken.
✓ Branch 31 → 32 taken 346 times.
✗ Branch 31 → 97 not taken.
✓ Branch 32 → 33 taken 346 times.
✗ Branch 32 → 97 not taken.
✓ Branch 33 → 34 taken 346 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 346 times.
✗ Branch 36 → 38 not taken.
✓ Branch 38 → 39 taken 346 times.
✗ Branch 38 → 41 not taken.
✓ Branch 41 → 42 taken 346 times.
✗ Branch 41 → 49 not taken.
✗ Branch 97 → 98 not taken.
✗ Branch 97 → 99 not taken.
✗ Branch 101 → 102 not taken.
✗ Branch 101 → 104 not taken.
|
1038 | if (interfaceDefNode->attrs && interfaceDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID)) |
| 210 |
2/4✓ Branch 44 → 45 taken 346 times.
✗ Branch 44 → 108 not taken.
✓ Branch 45 → 46 taken 346 times.
✗ Branch 45 → 106 not taken.
|
1038 | interfaceDefNode->typeId = interfaceDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue; |
| 211 | } | ||
| 212 |
2/2✓ Branch 50 → 51 taken 395 times.
✓ Branch 50 → 56 taken 42 times.
|
437 | if (ctx->qualifierLst()) |
| 213 |
3/6✓ Branch 51 → 52 taken 395 times.
✗ Branch 51 → 114 not taken.
✓ Branch 52 → 53 taken 395 times.
✗ Branch 52 → 114 not taken.
✓ Branch 53 → 54 taken 395 times.
✗ Branch 53 → 112 not taken.
|
395 | interfaceDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 214 |
2/2✓ Branch 57 → 58 taken 354 times.
✓ Branch 57 → 63 taken 83 times.
|
437 | if (ctx->LESS()) { |
| 215 | 354 | interfaceDefNode->hasTemplateTypes = true; | |
| 216 |
3/6✓ Branch 58 → 59 taken 354 times.
✗ Branch 58 → 117 not taken.
✓ Branch 59 → 60 taken 354 times.
✗ Branch 59 → 117 not taken.
✓ Branch 60 → 61 taken 354 times.
✗ Branch 60 → 115 not taken.
|
354 | interfaceDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 217 | } | ||
| 218 |
3/4✓ Branch 63 → 64 taken 437 times.
✗ Branch 63 → 124 not taken.
✓ Branch 81 → 66 taken 994 times.
✓ Branch 81 → 82 taken 437 times.
|
1868 | for (SpiceParser::SignatureContext *signature : ctx->signature()) |
| 219 |
3/6✓ Branch 68 → 69 taken 994 times.
✗ Branch 68 → 120 not taken.
✓ Branch 69 → 70 taken 994 times.
✗ Branch 69 → 118 not taken.
✓ Branch 70 → 71 taken 994 times.
✗ Branch 70 → 118 not taken.
|
1431 | interfaceDefNode->signatures.push_back(std::any_cast<SignatureNode *>(visit(signature))); |
| 220 | |||
| 221 |
1/2✓ Branch 89 → 90 taken 437 times.
✗ Branch 89 → 125 not taken.
|
874 | return concludeNode(interfaceDefNode); |
| 222 | } | ||
| 223 | |||
| 224 | 38 | std::any ASTBuilder::visitUnionDef(SpiceParser::UnionDefContext *ctx) { | |
| 225 | 38 | const auto unionDefNode = createNode<UnionDefNode>(ctx); | |
| 226 | |||
| 227 | // Enrich | ||
| 228 |
2/4✓ Branch 3 → 4 taken 38 times.
✗ Branch 3 → 93 not taken.
✓ Branch 4 → 5 taken 38 times.
✗ Branch 4 → 93 not taken.
|
38 | unionDefNode->unionName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 229 | 38 | unionDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 230 | |||
| 231 | // Visit children | ||
| 232 |
1/2✗ Branch 9 → 10 not taken.
✓ Branch 9 → 49 taken 38 times.
|
38 | if (ctx->topLevelDefAttr()) { |
| 233 | ✗ | unionDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); | |
| 234 | |||
| 235 | // Tell the attributes that they are union attributes | ||
| 236 | ✗ | for (AttrNode *attr : unionDefNode->attrs->attrLst->attributes) | |
| 237 | ✗ | attr->target = AttrNode::TARGET_UNION; | |
| 238 | |||
| 239 | // Check if a custom type id was set | ||
| 240 | ✗ | if (unionDefNode->attrs && unionDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID)) | |
| 241 | ✗ | unionDefNode->typeId = unionDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue; | |
| 242 | } | ||
| 243 |
2/2✓ Branch 50 → 51 taken 2 times.
✓ Branch 50 → 56 taken 36 times.
|
38 | if (ctx->qualifierLst()) |
| 244 |
3/6✓ Branch 51 → 52 taken 2 times.
✗ Branch 51 → 114 not taken.
✓ Branch 52 → 53 taken 2 times.
✗ Branch 52 → 114 not taken.
✓ Branch 53 → 54 taken 2 times.
✗ Branch 53 → 112 not taken.
|
2 | unionDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 245 |
2/2✓ Branch 57 → 58 taken 4 times.
✓ Branch 57 → 63 taken 34 times.
|
38 | if (ctx->LESS()) { |
| 246 | 4 | unionDefNode->hasTemplateTypes = true; | |
| 247 |
3/6✓ Branch 58 → 59 taken 4 times.
✗ Branch 58 → 117 not taken.
✓ Branch 59 → 60 taken 4 times.
✗ Branch 59 → 117 not taken.
✓ Branch 60 → 61 taken 4 times.
✗ Branch 60 → 115 not taken.
|
4 | unionDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 248 | } | ||
| 249 |
3/4✓ Branch 63 → 64 taken 38 times.
✗ Branch 63 → 124 not taken.
✓ Branch 81 → 66 taken 78 times.
✓ Branch 81 → 82 taken 38 times.
|
154 | for (SpiceParser::FieldContext *field : ctx->field()) |
| 250 |
3/6✓ Branch 68 → 69 taken 78 times.
✗ Branch 68 → 120 not taken.
✓ Branch 69 → 70 taken 78 times.
✗ Branch 69 → 118 not taken.
✓ Branch 70 → 71 taken 78 times.
✗ Branch 70 → 118 not taken.
|
116 | unionDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field))); |
| 251 | |||
| 252 |
1/2✓ Branch 89 → 90 taken 38 times.
✗ Branch 89 → 125 not taken.
|
76 | return concludeNode(unionDefNode); |
| 253 | } | ||
| 254 | |||
| 255 | 714 | std::any ASTBuilder::visitEnumDef(SpiceParser::EnumDefContext *ctx) { | |
| 256 | 714 | const auto enumDefNode = createNode<EnumDefNode>(ctx); | |
| 257 | |||
| 258 | // Enrich | ||
| 259 |
2/4✓ Branch 3 → 4 taken 714 times.
✗ Branch 3 → 43 not taken.
✓ Branch 4 → 5 taken 714 times.
✗ Branch 4 → 43 not taken.
|
714 | enumDefNode->enumName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 260 | 714 | enumDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 261 | |||
| 262 | // Visit children | ||
| 263 |
2/2✓ Branch 9 → 10 taken 657 times.
✓ Branch 9 → 15 taken 57 times.
|
714 | if (ctx->qualifierLst()) |
| 264 |
3/6✓ Branch 10 → 11 taken 657 times.
✗ Branch 10 → 46 not taken.
✓ Branch 11 → 12 taken 657 times.
✗ Branch 11 → 46 not taken.
✓ Branch 12 → 13 taken 657 times.
✗ Branch 12 → 44 not taken.
|
657 | enumDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 265 |
3/6✓ Branch 15 → 16 taken 714 times.
✗ Branch 15 → 49 not taken.
✓ Branch 16 → 17 taken 714 times.
✗ Branch 16 → 49 not taken.
✓ Branch 17 → 18 taken 714 times.
✗ Branch 17 → 47 not taken.
|
714 | enumDefNode->itemLst = std::any_cast<EnumItemLstNode *>(visit(ctx->enumItemLst())); |
| 266 | |||
| 267 | // Tell all items about the enum def | ||
| 268 |
2/2✓ Branch 32 → 21 taken 3954 times.
✓ Branch 32 → 33 taken 714 times.
|
5382 | for (EnumItemNode *enumItem : enumDefNode->itemLst->items) |
| 269 | 3954 | enumItem->enumDef = enumDefNode; | |
| 270 | |||
| 271 |
1/2✓ Branch 39 → 40 taken 714 times.
✗ Branch 39 → 50 not taken.
|
1428 | return concludeNode(enumDefNode); |
| 272 | } | ||
| 273 | |||
| 274 | 4204 | std::any ASTBuilder::visitGenericTypeDef(SpiceParser::GenericTypeDefContext *ctx) { | |
| 275 | 4204 | const auto genericTypeDefNode = createNode<GenericTypeDefNode>(ctx); | |
| 276 | |||
| 277 | // Enrich | ||
| 278 |
2/4✓ Branch 3 → 4 taken 4204 times.
✗ Branch 3 → 21 not taken.
✓ Branch 4 → 5 taken 4204 times.
✗ Branch 4 → 21 not taken.
|
4204 | genericTypeDefNode->typeName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 279 | |||
| 280 | // Visit children | ||
| 281 |
4/8✓ Branch 7 → 8 taken 4204 times.
✗ Branch 7 → 24 not taken.
✓ Branch 8 → 9 taken 4204 times.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 4204 times.
✗ Branch 9 → 22 not taken.
✓ Branch 11 → 12 taken 4204 times.
✗ Branch 11 → 25 not taken.
|
4204 | genericTypeDefNode->typeAltsLst = std::any_cast<TypeAltsLstNode *>(visit(ctx->typeAltsLst())); |
| 282 | |||
| 283 |
1/2✓ Branch 17 → 18 taken 4204 times.
✗ Branch 17 → 25 not taken.
|
8408 | return concludeNode(genericTypeDefNode); |
| 284 | } | ||
| 285 | |||
| 286 | 361 | std::any ASTBuilder::visitAliasDef(SpiceParser::AliasDefContext *ctx) { | |
| 287 | 361 | const auto aliasDefNode = createNode<AliasDefNode>(ctx); | |
| 288 | |||
| 289 | // Enrich | ||
| 290 |
2/4✓ Branch 3 → 4 taken 361 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 361 times.
✗ Branch 4 → 33 not taken.
|
361 | aliasDefNode->aliasName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 291 |
2/4✓ Branch 7 → 8 taken 361 times.
✗ Branch 7 → 34 not taken.
✓ Branch 8 → 9 taken 361 times.
✗ Branch 8 → 34 not taken.
|
361 | aliasDefNode->dataTypeString = ctx->dataType()->getText(); |
| 292 | 361 | aliasDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 293 | |||
| 294 | // Visit children | ||
| 295 |
2/2✓ Branch 13 → 14 taken 101 times.
✓ Branch 13 → 19 taken 260 times.
|
361 | if (ctx->qualifierLst()) |
| 296 |
3/6✓ Branch 14 → 15 taken 101 times.
✗ Branch 14 → 37 not taken.
✓ Branch 15 → 16 taken 101 times.
✗ Branch 15 → 37 not taken.
✓ Branch 16 → 17 taken 101 times.
✗ Branch 16 → 35 not taken.
|
101 | aliasDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 297 |
4/8✓ Branch 19 → 20 taken 361 times.
✗ Branch 19 → 40 not taken.
✓ Branch 20 → 21 taken 361 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 361 times.
✗ Branch 21 → 38 not taken.
✓ Branch 23 → 24 taken 361 times.
✗ Branch 23 → 41 not taken.
|
361 | aliasDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 298 | |||
| 299 |
1/2✓ Branch 29 → 30 taken 361 times.
✗ Branch 29 → 41 not taken.
|
722 | return concludeNode(aliasDefNode); |
| 300 | } | ||
| 301 | |||
| 302 | 5603 | std::any ASTBuilder::visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) { | |
| 303 | 5603 | const auto globalVarDefNode = createNode<GlobalVarDefNode>(ctx); | |
| 304 | |||
| 305 | // Enrich | ||
| 306 |
2/4✓ Branch 3 → 4 taken 5603 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 5603 times.
✗ Branch 4 → 28 not taken.
|
5603 | globalVarDefNode->varName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 307 | |||
| 308 | // Visit children | ||
| 309 |
3/6✓ Branch 7 → 8 taken 5603 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 5603 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 5603 times.
✗ Branch 9 → 29 not taken.
|
5603 | globalVarDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 310 | 5603 | globalVarDefNode->dataType->isGlobalType = true; | |
| 311 |
2/2✓ Branch 12 → 13 taken 5599 times.
✓ Branch 12 → 18 taken 4 times.
|
5603 | if (ctx->constant()) { |
| 312 | 5599 | globalVarDefNode->hasValue = true; | |
| 313 |
3/6✓ Branch 13 → 14 taken 5599 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 5599 times.
✗ Branch 14 → 34 not taken.
✓ Branch 15 → 16 taken 5599 times.
✗ Branch 15 → 32 not taken.
|
5599 | globalVarDefNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 314 | } | ||
| 315 | |||
| 316 |
1/2✓ Branch 24 → 25 taken 5603 times.
✗ Branch 24 → 35 not taken.
|
11206 | return concludeNode(globalVarDefNode); |
| 317 | } | ||
| 318 | |||
| 319 | 7618 | std::any ASTBuilder::visitExtDecl(SpiceParser::ExtDeclContext *ctx) { | |
| 320 | 7618 | const auto extDeclNode = createNode<ExtDeclNode>(ctx); | |
| 321 | |||
| 322 | // Enrich | ||
| 323 |
6/10✓ Branch 3 → 4 taken 7618 times.
✗ Branch 3 → 57 not taken.
✓ Branch 4 → 5 taken 6058 times.
✓ Branch 4 → 7 taken 1560 times.
✓ Branch 5 → 6 taken 6058 times.
✗ Branch 5 → 57 not taken.
✓ Branch 7 → 8 taken 1560 times.
✗ Branch 7 → 57 not taken.
✓ Branch 9 → 10 taken 7618 times.
✗ Branch 9 → 57 not taken.
|
7618 | extDeclNode->extFunctionName = getIdentifier(ctx->IDENTIFIER() ? ctx->IDENTIFIER() : ctx->TYPE_IDENTIFIER(), false); |
| 324 | |||
| 325 | // Visit children | ||
| 326 |
2/2✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 33 taken 7616 times.
|
7618 | if (ctx->topLevelDefAttr()) { |
| 327 |
3/6✓ Branch 14 → 15 taken 2 times.
✗ Branch 14 → 60 not taken.
✓ Branch 15 → 16 taken 2 times.
✗ Branch 15 → 60 not taken.
✓ Branch 16 → 17 taken 2 times.
✗ Branch 16 → 58 not taken.
|
2 | extDeclNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 328 | |||
| 329 | // Tell the attributes that they are ext decl attributes | ||
| 330 |
2/2✓ Branch 31 → 20 taken 2 times.
✓ Branch 31 → 32 taken 2 times.
|
6 | for (AttrNode *attr : extDeclNode->attrs->attrLst->attributes) |
| 331 | 2 | attr->target = AttrNode::TARGET_EXT_DECL; | |
| 332 | } | ||
| 333 |
2/2✓ Branch 34 → 35 taken 6508 times.
✓ Branch 34 → 40 taken 1110 times.
|
7618 | if (ctx->F()) { |
| 334 |
3/6✓ Branch 35 → 36 taken 6508 times.
✗ Branch 35 → 63 not taken.
✓ Branch 36 → 37 taken 6508 times.
✗ Branch 36 → 63 not taken.
✓ Branch 37 → 38 taken 6508 times.
✗ Branch 37 → 61 not taken.
|
6508 | extDeclNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 335 | 6508 | extDeclNode->returnType->isReturnType = true; | |
| 336 | } | ||
| 337 |
2/2✓ Branch 41 → 42 taken 7476 times.
✓ Branch 41 → 47 taken 142 times.
|
7618 | if (ctx->typeLstWithEllipsis()) { |
| 338 | 7476 | extDeclNode->hasArgs = true; | |
| 339 |
3/6✓ Branch 42 → 43 taken 7476 times.
✗ Branch 42 → 66 not taken.
✓ Branch 43 → 44 taken 7476 times.
✗ Branch 43 → 66 not taken.
✓ Branch 44 → 45 taken 7476 times.
✗ Branch 44 → 64 not taken.
|
7476 | extDeclNode->argTypeLst = std::any_cast<TypeLstWithEllipsisNode *>(visit(ctx->typeLstWithEllipsis())); |
| 340 | } | ||
| 341 | |||
| 342 |
1/2✓ Branch 53 → 54 taken 7618 times.
✗ Branch 53 → 67 not taken.
|
15236 | return concludeNode(extDeclNode); |
| 343 | } | ||
| 344 | |||
| 345 | 3594 | std::any ASTBuilder::visitImportDef(SpiceParser::ImportDefContext *ctx) { | |
| 346 |
1/2✓ Branch 2 → 3 taken 3594 times.
✗ Branch 2 → 32 not taken.
|
3594 | const auto importDefNode = createNode<ImportDefNode>(ctx); |
| 347 | |||
| 348 | // Extract path | ||
| 349 |
2/4✓ Branch 3 → 4 taken 3594 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 3594 times.
✗ Branch 4 → 32 not taken.
|
3594 | const std::string pathStr = ctx->STRING_LIT()->getText(); |
| 350 |
1/2✓ Branch 6 → 7 taken 3594 times.
✗ Branch 6 → 27 not taken.
|
3594 | importDefNode->importPath = pathStr.substr(1, pathStr.size() - 2); |
| 351 | |||
| 352 | // If no name is given, use the path as name | ||
| 353 |
7/12✓ Branch 9 → 10 taken 3594 times.
✗ Branch 9 → 28 not taken.
✓ Branch 10 → 11 taken 156 times.
✓ Branch 10 → 13 taken 3438 times.
✓ Branch 11 → 12 taken 156 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 14 taken 156 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 3438 times.
✗ Branch 13 → 28 not taken.
✓ Branch 16 → 17 taken 3594 times.
✗ Branch 16 → 29 not taken.
|
3594 | importDefNode->importName = ctx->AS() ? getIdentifier(ctx->IDENTIFIER(), false) : importDefNode->importPath; |
| 354 | |||
| 355 |
1/2✓ Branch 22 → 23 taken 3594 times.
✗ Branch 22 → 29 not taken.
|
7188 | return concludeNode(importDefNode); |
| 356 | 3594 | } | |
| 357 | |||
| 358 | 16298 | std::any ASTBuilder::visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) { | |
| 359 | 16298 | const auto unsafeBlockDefNode = createNode<UnsafeBlockNode>(ctx); | |
| 360 | |||
| 361 | // Visit children | ||
| 362 |
4/8✓ Branch 3 → 4 taken 16298 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 16298 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 16298 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 16298 times.
✗ Branch 7 → 20 not taken.
|
16298 | unsafeBlockDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 363 | |||
| 364 |
1/2✓ Branch 13 → 14 taken 16298 times.
✗ Branch 13 → 20 not taken.
|
32596 | return concludeNode(unsafeBlockDefNode); |
| 365 | } | ||
| 366 | |||
| 367 | 5910 | std::any ASTBuilder::visitForLoop(SpiceParser::ForLoopContext *ctx) { | |
| 368 | 5910 | const auto forLoopNode = createNode<ForLoopNode>(ctx); | |
| 369 | |||
| 370 |
2/4✓ Branch 3 → 4 taken 5910 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 5910 times.
✗ Branch 4 → 20 not taken.
|
5910 | visit(ctx->forHead()); |
| 371 |
4/8✓ Branch 6 → 7 taken 5910 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 5910 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 5910 times.
✗ Branch 8 → 21 not taken.
✓ Branch 10 → 11 taken 5910 times.
✗ Branch 10 → 24 not taken.
|
5910 | forLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 372 | |||
| 373 |
1/2✓ Branch 16 → 17 taken 5910 times.
✗ Branch 16 → 24 not taken.
|
11820 | return concludeNode(forLoopNode); |
| 374 | } | ||
| 375 | |||
| 376 | 5910 | std::any ASTBuilder::visitForHead(SpiceParser::ForHeadContext *ctx) { | |
| 377 | 5910 | const auto forLoopNode = resumeForExpansion<ForLoopNode>(); | |
| 378 | |||
| 379 | // Visit children | ||
| 380 |
3/6✓ Branch 14 → 15 taken 5910 times.
✗ Branch 14 → 32 not taken.
✓ Branch 15 → 16 taken 5910 times.
✗ Branch 15 → 32 not taken.
✓ Branch 16 → 17 taken 5910 times.
✗ Branch 16 → 30 not taken.
|
5910 | forLoopNode->initDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt())); |
| 381 |
3/6✓ Branch 18 → 19 taken 5910 times.
✗ Branch 18 → 35 not taken.
✓ Branch 19 → 20 taken 5910 times.
✗ Branch 19 → 35 not taken.
✓ Branch 20 → 21 taken 5910 times.
✗ Branch 20 → 33 not taken.
|
5910 | forLoopNode->condAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(0))); |
| 382 |
3/6✓ Branch 22 → 23 taken 5910 times.
✗ Branch 22 → 38 not taken.
✓ Branch 23 → 24 taken 5910 times.
✗ Branch 23 → 38 not taken.
✓ Branch 24 → 25 taken 5910 times.
✗ Branch 24 → 36 not taken.
|
5910 | forLoopNode->incAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(1))); |
| 383 | |||
| 384 |
1/2✓ Branch 26 → 27 taken 5910 times.
✗ Branch 26 → 39 not taken.
|
11820 | return nullptr; |
| 385 | } | ||
| 386 | |||
| 387 | 617 | std::any ASTBuilder::visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) { | |
| 388 | 617 | const auto foreachLoopNode = createNode<ForeachLoopNode>(ctx); | |
| 389 | |||
| 390 | // Visit children | ||
| 391 |
2/4✓ Branch 3 → 4 taken 617 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 617 times.
✗ Branch 4 → 20 not taken.
|
617 | visit(ctx->foreachHead()); |
| 392 |
3/6✓ Branch 6 → 7 taken 617 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 617 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 617 times.
✗ Branch 8 → 21 not taken.
|
617 | foreachLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 393 | |||
| 394 | // Tell the foreach item that it is one | ||
| 395 |
1/2✓ Branch 10 → 11 taken 617 times.
✗ Branch 10 → 24 not taken.
|
617 | foreachLoopNode->itemVarDecl->isForEachItem = true; |
| 396 | |||
| 397 |
1/2✓ Branch 16 → 17 taken 617 times.
✗ Branch 16 → 24 not taken.
|
1234 | return concludeNode(foreachLoopNode); |
| 398 | } | ||
| 399 | |||
| 400 | 617 | std::any ASTBuilder::visitForeachHead(SpiceParser::ForeachHeadContext *ctx) { | |
| 401 | 617 | const auto foreachLoopNode = resumeForExpansion<ForeachLoopNode>(); | |
| 402 | |||
| 403 | // Visit children | ||
| 404 |
3/4✓ Branch 14 → 15 taken 617 times.
✗ Branch 14 → 45 not taken.
✓ Branch 17 → 18 taken 587 times.
✓ Branch 17 → 23 taken 30 times.
|
617 | if (ctx->declStmt().size() == 1) { |
| 405 |
3/6✓ Branch 18 → 19 taken 587 times.
✗ Branch 18 → 48 not taken.
✓ Branch 19 → 20 taken 587 times.
✗ Branch 19 → 48 not taken.
✓ Branch 20 → 21 taken 587 times.
✗ Branch 20 → 46 not taken.
|
587 | foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0))); |
| 406 |
2/4✓ Branch 23 → 24 taken 30 times.
✗ Branch 23 → 49 not taken.
✓ Branch 26 → 27 taken 30 times.
✗ Branch 26 → 36 not taken.
|
30 | } else if (ctx->declStmt().size() == 2) { |
| 407 |
3/6✓ Branch 27 → 28 taken 30 times.
✗ Branch 27 → 52 not taken.
✓ Branch 28 → 29 taken 30 times.
✗ Branch 28 → 52 not taken.
✓ Branch 29 → 30 taken 30 times.
✗ Branch 29 → 50 not taken.
|
30 | foreachLoopNode->idxVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0))); |
| 408 |
3/6✓ Branch 31 → 32 taken 30 times.
✗ Branch 31 → 55 not taken.
✓ Branch 32 → 33 taken 30 times.
✗ Branch 32 → 55 not taken.
✓ Branch 33 → 34 taken 30 times.
✗ Branch 33 → 53 not taken.
|
30 | foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(1))); |
| 409 | } else { | ||
| 410 | − | assert_fail("Invalid number of decl statements in foreach loop"); // GCOV_EXCL_LINE | |
| 411 | } | ||
| 412 |
3/6✓ Branch 37 → 38 taken 617 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 617 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 617 times.
✗ Branch 39 → 56 not taken.
|
617 | foreachLoopNode->iteratorAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 413 | |||
| 414 |
1/2✓ Branch 41 → 42 taken 617 times.
✗ Branch 41 → 59 not taken.
|
1234 | return nullptr; |
| 415 | } | ||
| 416 | |||
| 417 | 2717 | std::any ASTBuilder::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) { | |
| 418 | 2717 | const auto whileLoopNode = createNode<WhileLoopNode>(ctx); | |
| 419 | |||
| 420 | // Visit children | ||
| 421 |
3/6✓ Branch 3 → 4 taken 2717 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 2717 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 2717 times.
✗ Branch 5 → 21 not taken.
|
2717 | whileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 422 |
4/8✓ Branch 7 → 8 taken 2717 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 2717 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 2717 times.
✗ Branch 9 → 24 not taken.
✓ Branch 11 → 12 taken 2717 times.
✗ Branch 11 → 27 not taken.
|
2717 | whileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 423 | |||
| 424 |
1/2✓ Branch 17 → 18 taken 2717 times.
✗ Branch 17 → 27 not taken.
|
5434 | return concludeNode(whileLoopNode); |
| 425 | } | ||
| 426 | |||
| 427 | 65 | std::any ASTBuilder::visitDoWhileLoop(SpiceParser::DoWhileLoopContext *ctx) { | |
| 428 | 65 | const auto doWhileLoopNode = createNode<DoWhileLoopNode>(ctx); | |
| 429 | |||
| 430 | // Visit children | ||
| 431 |
3/6✓ Branch 3 → 4 taken 65 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 65 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 65 times.
✗ Branch 5 → 21 not taken.
|
65 | doWhileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 432 |
4/8✓ Branch 7 → 8 taken 65 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 65 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 65 times.
✗ Branch 9 → 24 not taken.
✓ Branch 11 → 12 taken 65 times.
✗ Branch 11 → 27 not taken.
|
65 | doWhileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 433 | |||
| 434 |
1/2✓ Branch 17 → 18 taken 65 times.
✗ Branch 17 → 27 not taken.
|
130 | return concludeNode(doWhileLoopNode); |
| 435 | } | ||
| 436 | |||
| 437 | 34143 | std::any ASTBuilder::visitIfStmt(SpiceParser::IfStmtContext *ctx) { | |
| 438 | 34143 | const auto ifStmtNode = createNode<IfStmtNode>(ctx); | |
| 439 | |||
| 440 | // Visit children | ||
| 441 |
3/6✓ Branch 3 → 4 taken 34143 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 34143 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 34143 times.
✗ Branch 5 → 28 not taken.
|
34143 | ifStmtNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 442 |
3/6✓ Branch 7 → 8 taken 34143 times.
✗ Branch 7 → 33 not taken.
✓ Branch 8 → 9 taken 34143 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 34143 times.
✗ Branch 9 → 31 not taken.
|
34143 | ifStmtNode->thenBody = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 443 |
2/2✓ Branch 12 → 13 taken 2128 times.
✓ Branch 12 → 18 taken 32015 times.
|
34143 | if (ctx->elseStmt()) |
| 444 |
3/6✓ Branch 13 → 14 taken 2128 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 2128 times.
✗ Branch 14 → 36 not taken.
✓ Branch 15 → 16 taken 2128 times.
✗ Branch 15 → 34 not taken.
|
2128 | ifStmtNode->elseStmt = std::any_cast<ElseStmtNode *>(visit(ctx->elseStmt())); |
| 445 | |||
| 446 |
1/2✓ Branch 24 → 25 taken 34143 times.
✗ Branch 24 → 37 not taken.
|
68286 | return concludeNode(ifStmtNode); |
| 447 | } | ||
| 448 | |||
| 449 | 2128 | std::any ASTBuilder::visitElseStmt(SpiceParser::ElseStmtContext *ctx) { | |
| 450 | 2128 | const auto elseStmtNode = createNode<ElseStmtNode>(ctx); | |
| 451 | |||
| 452 | // Visit children | ||
| 453 |
2/2✓ Branch 4 → 5 taken 891 times.
✓ Branch 4 → 10 taken 1237 times.
|
2128 | if (ctx->ifStmt()) { |
| 454 | 891 | elseStmtNode->isElseIf = true; | |
| 455 |
3/6✓ Branch 5 → 6 taken 891 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 891 times.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 891 times.
✗ Branch 7 → 25 not taken.
|
891 | elseStmtNode->ifStmt = std::any_cast<IfStmtNode *>(visit(ctx->ifStmt())); |
| 456 | } else { | ||
| 457 |
3/6✓ Branch 10 → 11 taken 1237 times.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 1237 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 1237 times.
✗ Branch 12 → 28 not taken.
|
1237 | elseStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 458 | } | ||
| 459 | |||
| 460 |
1/2✓ Branch 21 → 22 taken 2128 times.
✗ Branch 21 → 31 not taken.
|
4256 | return concludeNode(elseStmtNode); |
| 461 | } | ||
| 462 | |||
| 463 | 53 | std::any ASTBuilder::visitSwitchStmt(SpiceParser::SwitchStmtContext *ctx) { | |
| 464 |
1/2✓ Branch 2 → 3 taken 53 times.
✗ Branch 2 → 38 not taken.
|
53 | const auto switchStmtNode = createNode<SwitchStmtNode>(ctx); |
| 465 | |||
| 466 | // Visit children | ||
| 467 |
3/6✓ Branch 3 → 4 taken 53 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 53 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 53 times.
✗ Branch 5 → 28 not taken.
|
53 | switchStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 468 |
2/4✓ Branch 7 → 8 taken 53 times.
✗ Branch 7 → 33 not taken.
✓ Branch 8 → 9 taken 53 times.
✗ Branch 8 → 31 not taken.
|
53 | fetchChildrenIntoVector(switchStmtNode->caseBranches, ctx->caseBranch()); |
| 469 |
3/4✓ Branch 10 → 11 taken 53 times.
✗ Branch 10 → 38 not taken.
✓ Branch 11 → 12 taken 29 times.
✓ Branch 11 → 17 taken 24 times.
|
53 | if (ctx->defaultBranch()) { |
| 470 | 29 | switchStmtNode->hasDefaultBranch = true; | |
| 471 |
3/6✓ Branch 12 → 13 taken 29 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 29 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 29 times.
✗ Branch 14 → 34 not taken.
|
29 | switchStmtNode->defaultBranch = std::any_cast<DefaultBranchNode *>(visit(ctx->defaultBranch())); |
| 472 | } | ||
| 473 | |||
| 474 | // Remember the switch statement, so that later passes can access all switch statements without walking the whole AST | ||
| 475 |
1/2✓ Branch 17 → 18 taken 53 times.
✗ Branch 17 → 38 not taken.
|
53 | switchStmts.push_back(switchStmtNode); |
| 476 | |||
| 477 |
2/4✓ Branch 18 → 19 taken 53 times.
✗ Branch 18 → 37 not taken.
✓ Branch 24 → 25 taken 53 times.
✗ Branch 24 → 37 not taken.
|
159 | return concludeNode(switchStmtNode); |
| 478 | } | ||
| 479 | |||
| 480 | 321 | std::any ASTBuilder::visitCaseBranch(SpiceParser::CaseBranchContext *ctx) { | |
| 481 | 321 | const auto caseBranchNode = createNode<CaseBranchNode>(ctx); | |
| 482 | |||
| 483 | // Visit children | ||
| 484 |
2/4✓ Branch 3 → 4 taken 321 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 321 times.
✗ Branch 4 → 20 not taken.
|
321 | fetchChildrenIntoVector(caseBranchNode->caseConstants, ctx->caseConstant()); |
| 485 |
4/8✓ Branch 6 → 7 taken 321 times.
✗ Branch 6 → 25 not taken.
✓ Branch 7 → 8 taken 321 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 321 times.
✗ Branch 8 → 23 not taken.
✓ Branch 10 → 11 taken 321 times.
✗ Branch 10 → 26 not taken.
|
321 | caseBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 486 | |||
| 487 |
1/2✓ Branch 16 → 17 taken 321 times.
✗ Branch 16 → 26 not taken.
|
642 | return concludeNode(caseBranchNode); |
| 488 | } | ||
| 489 | |||
| 490 | 29 | std::any ASTBuilder::visitDefaultBranch(SpiceParser::DefaultBranchContext *ctx) { | |
| 491 | 29 | const auto defaultBranchNode = createNode<DefaultBranchNode>(ctx); | |
| 492 | |||
| 493 | // Visit children | ||
| 494 |
4/8✓ Branch 3 → 4 taken 29 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 29 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 29 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 29 times.
✗ Branch 7 → 20 not taken.
|
29 | defaultBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 495 | |||
| 496 |
1/2✓ Branch 13 → 14 taken 29 times.
✗ Branch 13 → 20 not taken.
|
58 | return concludeNode(defaultBranchNode); |
| 497 | } | ||
| 498 | |||
| 499 | 169 | std::any ASTBuilder::visitAnonymousBlockStmt(SpiceParser::AnonymousBlockStmtContext *ctx) { | |
| 500 | 169 | const auto anonymousBlockStmtNode = createNode<AnonymousBlockStmtNode>(ctx); | |
| 501 | |||
| 502 | // Visit children | ||
| 503 |
4/8✓ Branch 3 → 4 taken 169 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 169 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 169 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 169 times.
✗ Branch 7 → 20 not taken.
|
169 | anonymousBlockStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 504 | |||
| 505 |
1/2✓ Branch 13 → 14 taken 169 times.
✗ Branch 13 → 20 not taken.
|
338 | return concludeNode(anonymousBlockStmtNode); |
| 506 | } | ||
| 507 | |||
| 508 | 125633 | std::any ASTBuilder::visitStmtLst(SpiceParser::StmtLstContext *ctx) { | |
| 509 | 125633 | const auto stmtLstNode = createNode<StmtLstNode>(ctx); | |
| 510 | |||
| 511 | // Enrich | ||
| 512 |
2/4✓ Branch 3 → 4 taken 125633 times.
✗ Branch 3 → 126 not taken.
✓ Branch 4 → 5 taken 125633 times.
✗ Branch 4 → 126 not taken.
|
125633 | stmtLstNode->closingBraceCodeLoc = CodeLoc(ctx->getStop(), sourceFile); |
| 513 | |||
| 514 | // Visit children | ||
| 515 |
2/2✓ Branch 115 → 7 taken 496217 times.
✓ Branch 115 → 116 taken 125625 times.
|
747475 | for (ParserRuleContext::ParseTree *stmt : ctx->children) { |
| 516 |
3/4✓ Branch 9 → 10 taken 496217 times.
✗ Branch 9 → 11 not taken.
✓ Branch 12 → 13 taken 179468 times.
✓ Branch 12 → 18 taken 316749 times.
|
496217 | if (auto *stmtCtx = dynamic_cast<SpiceParser::StmtContext *>(stmt)) |
| 517 |
4/6✓ Branch 13 → 14 taken 179460 times.
✓ Branch 13 → 129 taken 8 times.
✓ Branch 14 → 15 taken 179460 times.
✗ Branch 14 → 127 not taken.
✓ Branch 15 → 16 taken 179460 times.
✗ Branch 15 → 127 not taken.
|
179468 | stmtLstNode->statements.push_back(std::any_cast<StmtNode *>(visit(stmtCtx))); |
| 518 |
3/4✓ Branch 18 → 19 taken 316749 times.
✗ Branch 18 → 20 not taken.
✓ Branch 21 → 22 taken 5910 times.
✓ Branch 21 → 27 taken 310839 times.
|
316749 | else if (auto *forLoopCtx = dynamic_cast<SpiceParser::ForLoopContext *>(stmt)) |
| 519 |
3/6✓ Branch 22 → 23 taken 5910 times.
✗ Branch 22 → 133 not taken.
✓ Branch 23 → 24 taken 5910 times.
✗ Branch 23 → 131 not taken.
✓ Branch 24 → 25 taken 5910 times.
✗ Branch 24 → 131 not taken.
|
5910 | stmtLstNode->statements.push_back(std::any_cast<ForLoopNode *>(visit(forLoopCtx))); |
| 520 |
3/4✓ Branch 27 → 28 taken 310839 times.
✗ Branch 27 → 29 not taken.
✓ Branch 30 → 31 taken 617 times.
✓ Branch 30 → 36 taken 310222 times.
|
310839 | else if (auto *foreachLoopCtx = dynamic_cast<SpiceParser::ForeachLoopContext *>(stmt)) |
| 521 |
3/6✓ Branch 31 → 32 taken 617 times.
✗ Branch 31 → 137 not taken.
✓ Branch 32 → 33 taken 617 times.
✗ Branch 32 → 135 not taken.
✓ Branch 33 → 34 taken 617 times.
✗ Branch 33 → 135 not taken.
|
617 | stmtLstNode->statements.push_back(std::any_cast<ForeachLoopNode *>(visit(foreachLoopCtx))); |
| 522 |
3/4✓ Branch 36 → 37 taken 310222 times.
✗ Branch 36 → 38 not taken.
✓ Branch 39 → 40 taken 2717 times.
✓ Branch 39 → 45 taken 307505 times.
|
310222 | else if (auto *whileLoopCtx = dynamic_cast<SpiceParser::WhileLoopContext *>(stmt)) |
| 523 |
3/6✓ Branch 40 → 41 taken 2717 times.
✗ Branch 40 → 141 not taken.
✓ Branch 41 → 42 taken 2717 times.
✗ Branch 41 → 139 not taken.
✓ Branch 42 → 43 taken 2717 times.
✗ Branch 42 → 139 not taken.
|
2717 | stmtLstNode->statements.push_back(std::any_cast<WhileLoopNode *>(visit(whileLoopCtx))); |
| 524 |
3/4✓ Branch 45 → 46 taken 307505 times.
✗ Branch 45 → 47 not taken.
✓ Branch 48 → 49 taken 65 times.
✓ Branch 48 → 54 taken 307440 times.
|
307505 | else if (auto *doWhileLoopCtx = dynamic_cast<SpiceParser::DoWhileLoopContext *>(stmt)) |
| 525 |
3/6✓ Branch 49 → 50 taken 65 times.
✗ Branch 49 → 145 not taken.
✓ Branch 50 → 51 taken 65 times.
✗ Branch 50 → 143 not taken.
✓ Branch 51 → 52 taken 65 times.
✗ Branch 51 → 143 not taken.
|
65 | stmtLstNode->statements.push_back(std::any_cast<DoWhileLoopNode *>(visit(doWhileLoopCtx))); |
| 526 |
3/4✓ Branch 54 → 55 taken 307440 times.
✗ Branch 54 → 56 not taken.
✓ Branch 57 → 58 taken 33252 times.
✓ Branch 57 → 63 taken 274188 times.
|
307440 | else if (auto *ifStmtCtx = dynamic_cast<SpiceParser::IfStmtContext *>(stmt)) |
| 527 |
3/6✓ Branch 58 → 59 taken 33252 times.
✗ Branch 58 → 149 not taken.
✓ Branch 59 → 60 taken 33252 times.
✗ Branch 59 → 147 not taken.
✓ Branch 60 → 61 taken 33252 times.
✗ Branch 60 → 147 not taken.
|
33252 | stmtLstNode->statements.push_back(std::any_cast<IfStmtNode *>(visit(ifStmtCtx))); |
| 528 |
3/4✓ Branch 63 → 64 taken 274188 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 53 times.
✓ Branch 66 → 72 taken 274135 times.
|
274188 | else if (auto *switchStmtCtx = dynamic_cast<SpiceParser::SwitchStmtContext *>(stmt)) |
| 529 |
3/6✓ Branch 67 → 68 taken 53 times.
✗ Branch 67 → 153 not taken.
✓ Branch 68 → 69 taken 53 times.
✗ Branch 68 → 151 not taken.
✓ Branch 69 → 70 taken 53 times.
✗ Branch 69 → 151 not taken.
|
53 | stmtLstNode->statements.push_back(std::any_cast<SwitchStmtNode *>(visit(switchStmtCtx))); |
| 530 |
3/4✓ Branch 72 → 73 taken 274135 times.
✗ Branch 72 → 74 not taken.
✓ Branch 75 → 76 taken 6410 times.
✓ Branch 75 → 81 taken 267725 times.
|
274135 | else if (auto *assetStmtCtx = dynamic_cast<SpiceParser::AssertStmtContext *>(stmt)) |
| 531 |
3/6✓ Branch 76 → 77 taken 6410 times.
✗ Branch 76 → 157 not taken.
✓ Branch 77 → 78 taken 6410 times.
✗ Branch 77 → 155 not taken.
✓ Branch 78 → 79 taken 6410 times.
✗ Branch 78 → 155 not taken.
|
6410 | stmtLstNode->statements.push_back(std::any_cast<AssertStmtNode *>(visit(assetStmtCtx))); |
| 532 |
3/4✓ Branch 81 → 82 taken 267725 times.
✗ Branch 81 → 83 not taken.
✓ Branch 84 → 85 taken 16298 times.
✓ Branch 84 → 90 taken 251427 times.
|
267725 | else if (auto *unsafeBlockCtx = dynamic_cast<SpiceParser::UnsafeBlockContext *>(stmt)) |
| 533 |
3/6✓ Branch 85 → 86 taken 16298 times.
✗ Branch 85 → 161 not taken.
✓ Branch 86 → 87 taken 16298 times.
✗ Branch 86 → 159 not taken.
✓ Branch 87 → 88 taken 16298 times.
✗ Branch 87 → 159 not taken.
|
16298 | stmtLstNode->statements.push_back(std::any_cast<UnsafeBlockNode *>(visit(unsafeBlockCtx))); |
| 534 |
3/4✓ Branch 90 → 91 taken 251427 times.
✗ Branch 90 → 92 not taken.
✓ Branch 93 → 94 taken 169 times.
✓ Branch 93 → 99 taken 251258 times.
|
251427 | else if (auto *anonymousScopeCtx = dynamic_cast<SpiceParser::AnonymousBlockStmtContext *>(stmt)) |
| 535 |
3/6✓ Branch 94 → 95 taken 169 times.
✗ Branch 94 → 165 not taken.
✓ Branch 95 → 96 taken 169 times.
✗ Branch 95 → 163 not taken.
✓ Branch 96 → 97 taken 169 times.
✗ Branch 96 → 163 not taken.
|
169 | stmtLstNode->statements.push_back(std::any_cast<AnonymousBlockStmtNode *>(visit(anonymousScopeCtx))); |
| 536 | else | ||
| 537 | − | assert(is<TerminalNode *>(stmt)); // GCOV_EXCL_LINE | |
| 538 | } | ||
| 539 | |||
| 540 |
1/2✓ Branch 122 → 123 taken 125625 times.
✗ Branch 122 → 168 not taken.
|
251250 | return concludeNode(stmtLstNode); |
| 541 | } | ||
| 542 | |||
| 543 | 43538 | std::any ASTBuilder::visitTypeLst(SpiceParser::TypeLstContext *ctx) { | |
| 544 | 43538 | const auto typeLstNode = createNode<TypeLstNode>(ctx); | |
| 545 | |||
| 546 | // Visit children | ||
| 547 |
3/6✓ Branch 3 → 4 taken 43538 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 43538 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 43538 times.
✗ Branch 6 → 19 not taken.
|
43538 | fetchChildrenIntoVector(typeLstNode->dataTypes, ctx->dataType()); |
| 548 | |||
| 549 |
1/2✓ Branch 12 → 13 taken 43538 times.
✗ Branch 12 → 19 not taken.
|
87076 | return concludeNode(typeLstNode); |
| 550 | } | ||
| 551 | |||
| 552 | 7476 | std::any ASTBuilder::visitTypeLstWithEllipsis(SpiceParser::TypeLstWithEllipsisContext *ctx) { | |
| 553 | 7476 | const auto typeLstWithEllipsisNode = createNode<TypeLstWithEllipsisNode>(ctx); | |
| 554 | |||
| 555 | // Visit children | ||
| 556 |
3/6✓ Branch 3 → 4 taken 7476 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 7476 times.
✗ Branch 4 → 20 not taken.
✓ Branch 5 → 6 taken 7476 times.
✗ Branch 5 → 18 not taken.
|
7476 | typeLstWithEllipsisNode->typeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 557 | |||
| 558 | // Set some flags | ||
| 559 |
1/2✓ Branch 8 → 9 taken 7476 times.
✗ Branch 8 → 21 not taken.
|
7476 | typeLstWithEllipsisNode->hasEllipsis = ctx->ELLIPSIS() != nullptr; |
| 560 | |||
| 561 |
1/2✓ Branch 14 → 15 taken 7476 times.
✗ Branch 14 → 21 not taken.
|
14952 | return concludeNode(typeLstWithEllipsisNode); |
| 562 | } | ||
| 563 | |||
| 564 | 4204 | std::any ASTBuilder::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ctx) { | |
| 565 | 4204 | const auto typeAltsLstNode = createNode<TypeAltsLstNode>(ctx); | |
| 566 | |||
| 567 | // Visit children | ||
| 568 |
3/6✓ Branch 3 → 4 taken 4204 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 4204 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 4204 times.
✗ Branch 6 → 19 not taken.
|
4204 | fetchChildrenIntoVector(typeAltsLstNode->dataTypes, ctx->dataType()); |
| 569 | |||
| 570 |
1/2✓ Branch 12 → 13 taken 4204 times.
✗ Branch 12 → 19 not taken.
|
8408 | return concludeNode(typeAltsLstNode); |
| 571 | } | ||
| 572 | |||
| 573 | 45256 | std::any ASTBuilder::visitParamLst(SpiceParser::ParamLstContext *ctx) { | |
| 574 | 45256 | const auto paramLstNode = createNode<ParamLstNode>(ctx); | |
| 575 | |||
| 576 | // Visit children | ||
| 577 |
2/4✓ Branch 3 → 4 taken 45256 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 45256 times.
✗ Branch 4 → 30 not taken.
|
45256 | fetchChildrenIntoVector(paramLstNode->params, ctx->declStmt()); |
| 578 | |||
| 579 | // Set some flags to later detect that the decl statements are parameters | ||
| 580 |
2/2✓ Branch 19 → 8 taken 73371 times.
✓ Branch 19 → 20 taken 45256 times.
|
163883 | for (DeclStmtNode *declStmt : paramLstNode->params) { |
| 581 | 73371 | declStmt->isFctParam = true; | |
| 582 | 73371 | declStmt->dataType->isParamType = true; | |
| 583 | } | ||
| 584 | |||
| 585 |
1/2✓ Branch 26 → 27 taken 45256 times.
✗ Branch 26 → 33 not taken.
|
90512 | return concludeNode(paramLstNode); |
| 586 | } | ||
| 587 | |||
| 588 | 85433 | std::any ASTBuilder::visitArgLst(SpiceParser::ArgLstContext *ctx) { | |
| 589 | 85433 | const auto argLstNode = createNode<ArgLstNode>(ctx); | |
| 590 | |||
| 591 | // Visit children | ||
| 592 |
2/4✓ Branch 3 → 4 taken 85433 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 85433 times.
✗ Branch 4 → 18 not taken.
|
85433 | fetchChildrenIntoVector(argLstNode->args, ctx->assignExpr()); |
| 593 | 85433 | argLstNode->argInfos.reserve(argLstNode->args.size()); | |
| 594 | |||
| 595 |
1/2✓ Branch 14 → 15 taken 85433 times.
✗ Branch 14 → 21 not taken.
|
170866 | return concludeNode(argLstNode); |
| 596 | } | ||
| 597 | |||
| 598 | 714 | std::any ASTBuilder::visitEnumItemLst(SpiceParser::EnumItemLstContext *ctx) { | |
| 599 | 714 | const auto enumItemLstNode = createNode<EnumItemLstNode>(ctx); | |
| 600 | |||
| 601 | // Visit children | ||
| 602 |
3/6✓ Branch 3 → 4 taken 714 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 714 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 714 times.
✗ Branch 6 → 19 not taken.
|
714 | fetchChildrenIntoVector(enumItemLstNode->items, ctx->enumItem()); |
| 603 | |||
| 604 |
1/2✓ Branch 12 → 13 taken 714 times.
✗ Branch 12 → 19 not taken.
|
1428 | return concludeNode(enumItemLstNode); |
| 605 | } | ||
| 606 | |||
| 607 | 3954 | std::any ASTBuilder::visitEnumItem(SpiceParser::EnumItemContext *ctx) { | |
| 608 | 3954 | const auto enumItemNode = createNode<EnumItemNode>(ctx); | |
| 609 | |||
| 610 | // Enrich | ||
| 611 |
2/4✓ Branch 3 → 4 taken 3954 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 3954 times.
✗ Branch 4 → 22 not taken.
|
3954 | enumItemNode->itemName = getIdentifier(ctx->TYPE_IDENTIFIER(), false); |
| 612 |
2/2✓ Branch 8 → 9 taken 2858 times.
✓ Branch 8 → 12 taken 1096 times.
|
3954 | if (ctx->ASSIGN()) { |
| 613 | 2858 | enumItemNode->itemValue = parseInt(ctx->INT_LIT()); | |
| 614 | 2858 | enumItemNode->hasValue = true; | |
| 615 | } | ||
| 616 | |||
| 617 |
1/2✓ Branch 18 → 19 taken 3954 times.
✗ Branch 18 → 23 not taken.
|
7908 | return concludeNode(enumItemNode); |
| 618 | } | ||
| 619 | |||
| 620 | 10582 | std::any ASTBuilder::visitField(SpiceParser::FieldContext *ctx) { | |
| 621 | 10582 | const auto fieldNode = createNode<FieldNode>(ctx); | |
| 622 | |||
| 623 | // Enrich | ||
| 624 |
2/4✓ Branch 3 → 4 taken 10582 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 10582 times.
✗ Branch 4 → 29 not taken.
|
10582 | fieldNode->fieldName = getIdentifier(ctx->IDENTIFIER(), false); |
| 625 | |||
| 626 | // Visit children | ||
| 627 |
3/6✓ Branch 7 → 8 taken 10582 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 10582 times.
✗ Branch 8 → 32 not taken.
✓ Branch 9 → 10 taken 10582 times.
✗ Branch 9 → 30 not taken.
|
10582 | fieldNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 628 | 10582 | fieldNode->dataType->setFieldTypeRecursive(); | |
| 629 |
2/2✓ Branch 13 → 14 taken 2663 times.
✓ Branch 13 → 19 taken 7919 times.
|
10582 | if (ctx->ternaryExpr()) |
| 630 |
3/6✓ Branch 14 → 15 taken 2663 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 2663 times.
✗ Branch 15 → 35 not taken.
✓ Branch 16 → 17 taken 2663 times.
✗ Branch 16 → 33 not taken.
|
2663 | fieldNode->defaultValue = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr())); |
| 631 | |||
| 632 |
1/2✓ Branch 25 → 26 taken 10582 times.
✗ Branch 25 → 36 not taken.
|
21164 | return concludeNode(fieldNode); |
| 633 | } | ||
| 634 | |||
| 635 | 994 | std::any ASTBuilder::visitSignature(SpiceParser::SignatureContext *ctx) { | |
| 636 | 994 | const auto signatureNode = createNode<SignatureNode>(ctx); | |
| 637 | |||
| 638 | // Extract method name | ||
| 639 |
2/4✓ Branch 3 → 4 taken 994 times.
✗ Branch 3 → 73 not taken.
✓ Branch 4 → 5 taken 994 times.
✗ Branch 4 → 73 not taken.
|
994 | signatureNode->methodName = getIdentifier(ctx->IDENTIFIER(), false); |
| 640 | |||
| 641 | // Visit children | ||
| 642 |
2/2✓ Branch 8 → 9 taken 946 times.
✓ Branch 8 → 14 taken 48 times.
|
994 | if (ctx->qualifierLst()) { |
| 643 |
3/6✓ Branch 9 → 10 taken 946 times.
✗ Branch 9 → 76 not taken.
✓ Branch 10 → 11 taken 946 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 946 times.
✗ Branch 11 → 74 not taken.
|
946 | signatureNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 644 | } | ||
| 645 |
2/2✓ Branch 15 → 16 taken 787 times.
✓ Branch 15 → 22 taken 207 times.
|
994 | if (ctx->F()) { |
| 646 | 787 | signatureNode->hasReturnType = true; | |
| 647 | 787 | signatureNode->signatureType = SignatureNode::SignatureType::TYPE_FUNCTION; | |
| 648 | 787 | signatureNode->signatureQualifiers = TypeQualifiers::of(TY_FUNCTION); | |
| 649 |
3/6✓ Branch 17 → 18 taken 787 times.
✗ Branch 17 → 79 not taken.
✓ Branch 18 → 19 taken 787 times.
✗ Branch 18 → 79 not taken.
✓ Branch 19 → 20 taken 787 times.
✗ Branch 19 → 77 not taken.
|
787 | signatureNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 650 | } else { | ||
| 651 | 207 | signatureNode->signatureType = SignatureNode::SignatureType::TYPE_PROCEDURE; | |
| 652 | 207 | signatureNode->signatureQualifiers = TypeQualifiers::of(TY_PROCEDURE); | |
| 653 | } | ||
| 654 |
10/16✓ Branch 24 → 25 taken 787 times.
✓ Branch 24 → 28 taken 207 times.
✓ Branch 25 → 26 taken 787 times.
✗ Branch 25 → 80 not taken.
✓ Branch 28 → 29 taken 207 times.
✗ Branch 28 → 80 not taken.
✓ Branch 31 → 32 taken 207 times.
✓ Branch 31 → 33 taken 787 times.
✓ Branch 33 → 34 taken 787 times.
✓ Branch 33 → 35 taken 207 times.
✓ Branch 35 → 36 taken 535 times.
✓ Branch 35 → 41 taken 459 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
|
994 | if (ctx->F() ? ctx->LESS().size() == 2 : ctx->LESS().size() == 1) { |
| 655 | 535 | signatureNode->hasTemplateTypes = true; | |
| 656 |
3/6✓ Branch 36 → 37 taken 535 times.
✗ Branch 36 → 90 not taken.
✓ Branch 37 → 38 taken 535 times.
✗ Branch 37 → 90 not taken.
✓ Branch 38 → 39 taken 535 times.
✗ Branch 38 → 88 not taken.
|
535 | signatureNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0))); |
| 657 | } | ||
| 658 |
13/20✓ Branch 41 → 42 taken 994 times.
✗ Branch 41 → 91 not taken.
✓ Branch 43 → 44 taken 990 times.
✓ Branch 43 → 48 taken 4 times.
✓ Branch 44 → 45 taken 990 times.
✗ Branch 44 → 91 not taken.
✓ Branch 46 → 47 taken 547 times.
✓ Branch 46 → 49 taken 443 times.
✓ Branch 47 → 48 taken 16 times.
✓ Branch 47 → 49 taken 531 times.
✓ Branch 50 → 51 taken 990 times.
✓ Branch 50 → 52 taken 4 times.
✓ Branch 52 → 53 taken 994 times.
✗ Branch 52 → 54 not taken.
✓ Branch 54 → 55 taken 20 times.
✓ Branch 54 → 63 taken 974 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
|
994 | if (ctx->typeLst().size() == 2 || (ctx->typeLst().size() == 1 && !signatureNode->hasTemplateTypes)) { |
| 659 | 20 | signatureNode->hasParams = true; | |
| 660 |
5/8✓ Branch 55 → 56 taken 4 times.
✓ Branch 55 → 57 taken 16 times.
✓ Branch 58 → 59 taken 20 times.
✗ Branch 58 → 101 not taken.
✓ Branch 59 → 60 taken 20 times.
✗ Branch 59 → 101 not taken.
✓ Branch 60 → 61 taken 20 times.
✗ Branch 60 → 99 not taken.
|
20 | signatureNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(signatureNode->hasTemplateTypes ? 1 : 0))); |
| 661 | } | ||
| 662 | |||
| 663 |
1/2✓ Branch 69 → 70 taken 994 times.
✗ Branch 69 → 102 not taken.
|
1988 | return concludeNode(signatureNode); |
| 664 | } | ||
| 665 | |||
| 666 | 179468 | std::any ASTBuilder::visitStmt(SpiceParser::StmtContext *ctx) { | |
| 667 |
2/2✓ Branch 3 → 4 taken 34613 times.
✓ Branch 3 → 11 taken 144855 times.
|
179468 | if (ctx->declStmt()) |
| 668 |
5/8✓ Branch 4 → 5 taken 34613 times.
✗ Branch 4 → 60 not taken.
✓ Branch 5 → 6 taken 34605 times.
✓ Branch 5 → 60 taken 8 times.
✓ Branch 6 → 7 taken 34605 times.
✗ Branch 6 → 58 not taken.
✓ Branch 7 → 8 taken 34605 times.
✗ Branch 7 → 58 not taken.
|
69218 | return static_cast<StmtNode *>(std::any_cast<DeclStmtNode *>(visit(ctx->declStmt()))); |
| 669 |
2/2✓ Branch 12 → 13 taken 87737 times.
✓ Branch 12 → 20 taken 57118 times.
|
144855 | if (ctx->exprStmt()) |
| 670 |
4/8✓ Branch 13 → 14 taken 87737 times.
✗ Branch 13 → 64 not taken.
✓ Branch 14 → 15 taken 87737 times.
✗ Branch 14 → 64 not taken.
✓ Branch 15 → 16 taken 87737 times.
✗ Branch 15 → 62 not taken.
✓ Branch 16 → 17 taken 87737 times.
✗ Branch 16 → 62 not taken.
|
175474 | return static_cast<StmtNode *>(std::any_cast<ExprStmtNode *>(visit(ctx->exprStmt()))); |
| 671 |
2/2✓ Branch 21 → 22 taken 55050 times.
✓ Branch 21 → 29 taken 2068 times.
|
57118 | if (ctx->returnStmt()) |
| 672 |
4/8✓ Branch 22 → 23 taken 55050 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 55050 times.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 55050 times.
✗ Branch 24 → 66 not taken.
✓ Branch 25 → 26 taken 55050 times.
✗ Branch 25 → 66 not taken.
|
110100 | return static_cast<StmtNode *>(std::any_cast<ReturnStmtNode *>(visit(ctx->returnStmt()))); |
| 673 |
2/2✓ Branch 30 → 31 taken 1004 times.
✓ Branch 30 → 38 taken 1064 times.
|
2068 | if (ctx->breakStmt()) |
| 674 |
4/8✓ Branch 31 → 32 taken 1004 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 1004 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 1004 times.
✗ Branch 33 → 70 not taken.
✓ Branch 34 → 35 taken 1004 times.
✗ Branch 34 → 70 not taken.
|
2008 | return static_cast<StmtNode *>(std::any_cast<BreakStmtNode *>(visit(ctx->breakStmt()))); |
| 675 |
2/2✓ Branch 39 → 40 taken 1052 times.
✓ Branch 39 → 47 taken 12 times.
|
1064 | if (ctx->continueStmt()) |
| 676 |
4/8✓ Branch 40 → 41 taken 1052 times.
✗ Branch 40 → 76 not taken.
✓ Branch 41 → 42 taken 1052 times.
✗ Branch 41 → 76 not taken.
✓ Branch 42 → 43 taken 1052 times.
✗ Branch 42 → 74 not taken.
✓ Branch 43 → 44 taken 1052 times.
✗ Branch 43 → 74 not taken.
|
2104 | return static_cast<StmtNode *>(std::any_cast<ContinueStmtNode *>(visit(ctx->continueStmt()))); |
| 677 |
1/2✓ Branch 48 → 49 taken 12 times.
✗ Branch 48 → 56 not taken.
|
12 | if (ctx->fallthroughStmt()) |
| 678 |
4/8✓ Branch 49 → 50 taken 12 times.
✗ Branch 49 → 80 not taken.
✓ Branch 50 → 51 taken 12 times.
✗ Branch 50 → 80 not taken.
✓ Branch 51 → 52 taken 12 times.
✗ Branch 51 → 78 not taken.
✓ Branch 52 → 53 taken 12 times.
✗ Branch 52 → 78 not taken.
|
24 | return static_cast<StmtNode *>(std::any_cast<FallthroughStmtNode *>(visit(ctx->fallthroughStmt()))); |
| 679 | − | assert_fail("Unknown statement type"); // GCOV_EXCL_LINE | |
| 680 | return nullptr; // GCOV_EXCL_LINE | ||
| 681 | } | ||
| 682 | |||
| 683 | 114541 | std::any ASTBuilder::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) { | |
| 684 | 114541 | const auto declStmtNode = createNode<DeclStmtNode>(ctx); | |
| 685 | |||
| 686 | // Enrich | ||
| 687 |
3/4✓ Branch 3 → 4 taken 114541 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 114539 times.
✓ Branch 4 → 28 taken 2 times.
|
114541 | declStmtNode->varName = getIdentifier(ctx->IDENTIFIER(), false); |
| 688 | |||
| 689 | // Visit children | ||
| 690 |
4/6✓ Branch 7 → 8 taken 114539 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 114537 times.
✓ Branch 8 → 31 taken 2 times.
✓ Branch 9 → 10 taken 114537 times.
✗ Branch 9 → 29 not taken.
|
114539 | declStmtNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 691 |
2/2✓ Branch 12 → 13 taken 42680 times.
✓ Branch 12 → 18 taken 71857 times.
|
114537 | if (ctx->assignExpr()) { |
| 692 | 42680 | declStmtNode->hasAssignment = true; | |
| 693 |
4/6✓ Branch 13 → 14 taken 42680 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 42676 times.
✓ Branch 14 → 34 taken 4 times.
✓ Branch 15 → 16 taken 42676 times.
✗ Branch 15 → 32 not taken.
|
42680 | declStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 694 | } | ||
| 695 | |||
| 696 |
1/2✓ Branch 24 → 25 taken 114533 times.
✗ Branch 24 → 35 not taken.
|
229066 | return concludeNode(declStmtNode); |
| 697 | } | ||
| 698 | |||
| 699 | 87737 | std::any ASTBuilder::visitExprStmt(SpiceParser::ExprStmtContext *ctx) { | |
| 700 | 87737 | const auto exprStmtNode = createNode<ExprStmtNode>(ctx); | |
| 701 | |||
| 702 | // Enrich | ||
| 703 |
4/8✓ Branch 3 → 4 taken 87737 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 87737 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 87737 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 87737 times.
✗ Branch 7 → 20 not taken.
|
87737 | exprStmtNode->expr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 704 | |||
| 705 |
1/2✓ Branch 13 → 14 taken 87737 times.
✗ Branch 13 → 20 not taken.
|
175474 | return concludeNode(exprStmtNode); |
| 706 | } | ||
| 707 | |||
| 708 | 168785 | std::any ASTBuilder::visitQualifierLst(SpiceParser::QualifierLstContext *ctx) { | |
| 709 | 168785 | const auto qualifierLstNode = createNode<QualifierLstNode>(ctx); | |
| 710 | |||
| 711 | // Visit children | ||
| 712 |
2/4✓ Branch 3 → 4 taken 168785 times.
✗ Branch 3 → 45 not taken.
✓ Branch 4 → 5 taken 168785 times.
✗ Branch 4 → 43 not taken.
|
168785 | fetchChildrenIntoVector(qualifierLstNode->qualifiers, ctx->qualifier()); |
| 713 | |||
| 714 | // Check if qualifier combination is invalid | ||
| 715 | 168785 | bool seenSignedOrUnsigned = false; | |
| 716 |
2/2✓ Branch 32 → 8 taken 204293 times.
✓ Branch 32 → 33 taken 168783 times.
|
541861 | for (const QualifierNode *qualifier : qualifierLstNode->qualifiers) { |
| 717 | // Check if we have both, signed and unsigned qualifier | ||
| 718 |
2/2✓ Branch 10 → 11 taken 204279 times.
✓ Branch 10 → 13 taken 14 times.
|
204293 | if (qualifier->type != QualifierNode::QualifierType::TY_SIGNED && |
| 719 |
2/2✓ Branch 11 → 12 taken 152291 times.
✓ Branch 11 → 13 taken 51988 times.
|
204279 | qualifier->type != QualifierNode::QualifierType::TY_UNSIGNED) |
| 720 | 152291 | continue; | |
| 721 |
2/2✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 22 taken 52000 times.
|
52002 | if (seenSignedOrUnsigned) |
| 722 |
2/4✓ Branch 17 → 18 taken 2 times.
✗ Branch 17 → 49 not taken.
✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 46 not taken.
|
6 | throw ParserError(qualifier->codeLoc, INVALID_QUALIFIER_COMBINATION, "A variable can not be signed and unsigned"); |
| 723 | 52000 | seenSignedOrUnsigned = true; | |
| 724 | } | ||
| 725 | |||
| 726 |
1/2✓ Branch 39 → 40 taken 168783 times.
✗ Branch 39 → 56 not taken.
|
337566 | return concludeNode(qualifierLstNode); |
| 727 | } | ||
| 728 | |||
| 729 | 204293 | std::any ASTBuilder::visitQualifier(SpiceParser::QualifierContext *ctx) { | |
| 730 | 204293 | const auto qualifierNode = createNode<QualifierNode>(ctx); | |
| 731 | |||
| 732 |
3/4✓ Branch 7 → 8 taken 204293 times.
✗ Branch 7 → 9 not taken.
✓ Branch 42 → 5 taken 204293 times.
✓ Branch 42 → 43 taken 204293 times.
|
817172 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 733 | 204293 | const auto token = spice_pointer_cast<TerminalNode *>(subTree); | |
| 734 |
2/4✓ Branch 16 → 17 taken 204293 times.
✗ Branch 16 → 53 not taken.
✓ Branch 17 → 18 taken 204293 times.
✗ Branch 17 → 53 not taken.
|
204293 | const size_t symbolType = token->getSymbol()->getType(); |
| 735 |
2/2✓ Branch 18 → 19 taken 45187 times.
✓ Branch 18 → 20 taken 159106 times.
|
204293 | if (symbolType == SpiceParser::CONST) |
| 736 | 45187 | qualifierNode->type = QualifierNode::QualifierType::TY_CONST; | |
| 737 |
2/2✓ Branch 20 → 21 taken 14 times.
✓ Branch 20 → 22 taken 159092 times.
|
159106 | else if (symbolType == SpiceParser::SIGNED) |
| 738 | 14 | qualifierNode->type = QualifierNode::QualifierType::TY_SIGNED; | |
| 739 |
2/2✓ Branch 22 → 23 taken 51988 times.
✓ Branch 22 → 24 taken 107104 times.
|
159092 | else if (symbolType == SpiceParser::UNSIGNED) |
| 740 | 51988 | qualifierNode->type = QualifierNode::QualifierType::TY_UNSIGNED; | |
| 741 |
2/2✓ Branch 24 → 25 taken 18179 times.
✓ Branch 24 → 26 taken 88925 times.
|
107104 | else if (symbolType == SpiceParser::INLINE) |
| 742 | 18179 | qualifierNode->type = QualifierNode::QualifierType::TY_INLINE; | |
| 743 |
2/2✓ Branch 26 → 27 taken 63946 times.
✓ Branch 26 → 28 taken 24979 times.
|
88925 | else if (symbolType == SpiceParser::PUBLIC) |
| 744 | 63946 | qualifierNode->type = QualifierNode::QualifierType::TY_PUBLIC; | |
| 745 |
2/2✓ Branch 28 → 29 taken 24945 times.
✓ Branch 28 → 30 taken 34 times.
|
24979 | else if (symbolType == SpiceParser::HEAP) |
| 746 | 24945 | qualifierNode->type = QualifierNode::QualifierType::TY_HEAP; | |
| 747 |
1/2✓ Branch 30 → 31 taken 34 times.
✗ Branch 30 → 32 not taken.
|
34 | else if (symbolType == SpiceParser::COMPOSE) |
| 748 | 34 | qualifierNode->type = QualifierNode::QualifierType::TY_COMPOSITION; | |
| 749 | else | ||
| 750 | − | assert_fail("Unknown qualifier type"); // GCOV_EXCL_LINE | |
| 751 | } | ||
| 752 | |||
| 753 |
1/2✓ Branch 49 → 50 taken 204293 times.
✗ Branch 49 → 54 not taken.
|
408586 | return concludeNode(qualifierNode); |
| 754 | } | ||
| 755 | |||
| 756 | 2117 | std::any ASTBuilder::visitModAttr(SpiceParser::ModAttrContext *ctx) { | |
| 757 | 2117 | const auto modAttrNode = createNode<ModAttrNode>(ctx); | |
| 758 | |||
| 759 | // Visit children | ||
| 760 |
4/6✓ Branch 3 → 4 taken 2117 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 2115 times.
✓ Branch 4 → 33 taken 2 times.
✓ Branch 5 → 6 taken 2115 times.
✗ Branch 5 → 31 not taken.
|
2117 | modAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst())); |
| 761 | |||
| 762 | // Tell the attributes that they are module attributes | ||
| 763 |
2/2✓ Branch 20 → 9 taken 3021 times.
✓ Branch 20 → 21 taken 2115 times.
|
7251 | for (AttrNode *attr : modAttrNode->attrLst->attributes) |
| 764 | 3021 | attr->target = AttrNode::TARGET_MODULE; | |
| 765 | |||
| 766 |
1/2✓ Branch 27 → 28 taken 2115 times.
✗ Branch 27 → 34 not taken.
|
4230 | return concludeNode(modAttrNode); |
| 767 | } | ||
| 768 | |||
| 769 | 1991 | std::any ASTBuilder::visitTopLevelDefAttr(SpiceParser::TopLevelDefAttrContext *ctx) { | |
| 770 | 1991 | const auto fctAttrNode = createNode<TopLevelDefAttrNode>(ctx); | |
| 771 | |||
| 772 | // Visit children | ||
| 773 |
4/8✓ Branch 3 → 4 taken 1991 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 1991 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 1991 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 1991 times.
✗ Branch 7 → 20 not taken.
|
1991 | fctAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst())); |
| 774 | |||
| 775 |
1/2✓ Branch 13 → 14 taken 1991 times.
✗ Branch 13 → 20 not taken.
|
3982 | return concludeNode(fctAttrNode); |
| 776 | } | ||
| 777 | |||
| 778 | 36 | std::any ASTBuilder::visitLambdaAttr(SpiceParser::LambdaAttrContext *ctx) { | |
| 779 | 36 | const auto lambdaAttrNode = createNode<LambdaAttrNode>(ctx); | |
| 780 | |||
| 781 | // Visit children | ||
| 782 |
3/6✓ Branch 3 → 4 taken 36 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 36 times.
✗ Branch 4 → 33 not taken.
✓ Branch 5 → 6 taken 36 times.
✗ Branch 5 → 31 not taken.
|
36 | lambdaAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst())); |
| 783 | |||
| 784 | // Tell the attributes that they are module attributes | ||
| 785 |
2/2✓ Branch 20 → 9 taken 36 times.
✓ Branch 20 → 21 taken 36 times.
|
108 | for (AttrNode *attr : lambdaAttrNode->attrLst->attributes) |
| 786 | 36 | attr->target = AttrNode::TARGET_LAMBDA; | |
| 787 | |||
| 788 |
1/2✓ Branch 27 → 28 taken 36 times.
✗ Branch 27 → 34 not taken.
|
72 | return concludeNode(lambdaAttrNode); |
| 789 | } | ||
| 790 | |||
| 791 | 4144 | std::any ASTBuilder::visitAttrLst(SpiceParser::AttrLstContext *ctx) { | |
| 792 | 4144 | const auto attrLstNode = createNode<AttrLstNode>(ctx); | |
| 793 | |||
| 794 | // Visit children | ||
| 795 |
4/6✓ Branch 3 → 4 taken 4144 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 4142 times.
✓ Branch 4 → 16 taken 2 times.
✓ Branch 6 → 7 taken 4142 times.
✗ Branch 6 → 19 not taken.
|
4146 | fetchChildrenIntoVector(attrLstNode->attributes, ctx->attr()); |
| 796 | |||
| 797 |
1/2✓ Branch 12 → 13 taken 4142 times.
✗ Branch 12 → 19 not taken.
|
8284 | return concludeNode(attrLstNode); |
| 798 | } | ||
| 799 | |||
| 800 | 5074 | std::any ASTBuilder::visitAttr(SpiceParser::AttrContext *ctx) { | |
| 801 |
1/2✓ Branch 2 → 3 taken 5074 times.
✗ Branch 2 → 83 not taken.
|
5074 | const auto attrNode = createNode<AttrNode>(ctx); |
| 802 | |||
| 803 | // Extract key | ||
| 804 |
1/2✓ Branch 3 → 4 taken 5074 times.
✗ Branch 3 → 83 not taken.
|
5074 | std::stringstream key; |
| 805 |
3/4✓ Branch 12 → 13 taken 17558 times.
✗ Branch 12 → 66 not taken.
✓ Branch 15 → 5 taken 12484 times.
✓ Branch 15 → 16 taken 5074 times.
|
17558 | for (size_t i = 0; i < ctx->IDENTIFIER().size(); i++) { |
| 806 |
2/2✓ Branch 5 → 6 taken 7410 times.
✓ Branch 5 → 7 taken 5074 times.
|
12484 | if (i > 0) |
| 807 |
1/2✓ Branch 6 → 7 taken 7410 times.
✗ Branch 6 → 81 not taken.
|
7410 | key << MEMBER_ACCESS_TOKEN; |
| 808 |
3/6✓ Branch 7 → 8 taken 12484 times.
✗ Branch 7 → 65 not taken.
✓ Branch 8 → 9 taken 12484 times.
✗ Branch 8 → 65 not taken.
✓ Branch 9 → 10 taken 12484 times.
✗ Branch 9 → 63 not taken.
|
12484 | key << ctx->IDENTIFIER(i)->getText(); |
| 809 | } | ||
| 810 |
1/2✓ Branch 16 → 17 taken 5074 times.
✗ Branch 16 → 67 not taken.
|
5074 | attrNode->key = key.str(); |
| 811 | |||
| 812 | // Visit children | ||
| 813 |
3/4✓ Branch 19 → 20 taken 5074 times.
✗ Branch 19 → 81 not taken.
✓ Branch 20 → 21 taken 3620 times.
✓ Branch 20 → 51 taken 1454 times.
|
5074 | if (ctx->constant()) { |
| 814 |
3/6✓ Branch 21 → 22 taken 3620 times.
✗ Branch 21 → 70 not taken.
✓ Branch 22 → 23 taken 3620 times.
✗ Branch 22 → 70 not taken.
✓ Branch 23 → 24 taken 3620 times.
✗ Branch 23 → 68 not taken.
|
3620 | attrNode->value = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 815 | |||
| 816 |
4/6✓ Branch 25 → 26 taken 3620 times.
✗ Branch 25 → 81 not taken.
✓ Branch 26 → 27 taken 3620 times.
✗ Branch 26 → 81 not taken.
✓ Branch 27 → 28 taken 980 times.
✓ Branch 27 → 29 taken 2640 times.
|
3620 | if (ctx->constant()->STRING_LIT()) |
| 817 | 980 | attrNode->type = AttrNode::AttrType::TYPE_STRING; | |
| 818 |
4/6✓ Branch 29 → 30 taken 2640 times.
✗ Branch 29 → 81 not taken.
✓ Branch 30 → 31 taken 2640 times.
✗ Branch 30 → 81 not taken.
✓ Branch 31 → 32 taken 348 times.
✓ Branch 31 → 33 taken 2292 times.
|
2640 | else if (ctx->constant()->INT_LIT()) |
| 819 | 348 | attrNode->type = AttrNode::AttrType::TYPE_INT; | |
| 820 |
10/14✓ Branch 33 → 34 taken 2292 times.
✗ Branch 33 → 81 not taken.
✓ Branch 34 → 35 taken 2292 times.
✗ Branch 34 → 81 not taken.
✓ Branch 35 → 36 taken 10 times.
✓ Branch 35 → 39 taken 2282 times.
✓ Branch 36 → 37 taken 10 times.
✗ Branch 36 → 81 not taken.
✓ Branch 37 → 38 taken 10 times.
✗ Branch 37 → 81 not taken.
✓ Branch 38 → 39 taken 8 times.
✓ Branch 38 → 40 taken 2 times.
✓ Branch 41 → 42 taken 2290 times.
✓ Branch 41 → 43 taken 2 times.
|
2292 | else if (ctx->constant()->TRUE() || ctx->constant()->FALSE()) |
| 821 | 2290 | attrNode->type = AttrNode::AttrType::TYPE_BOOL; | |
| 822 | else | ||
| 823 |
2/4✓ Branch 46 → 47 taken 2 times.
✗ Branch 46 → 74 not taken.
✓ Branch 47 → 48 taken 2 times.
✗ Branch 47 → 71 not taken.
|
6 | throw ParserError(attrNode->value->codeLoc, INVALID_ATTR_VALUE_TYPE, "Invalid attribute value type"); |
| 824 | } else { | ||
| 825 | // If no value is given, use the bool type | ||
| 826 | 1454 | attrNode->type = AttrNode::AttrType::TYPE_BOOL; | |
| 827 | } | ||
| 828 | |||
| 829 |
1/2✓ Branch 58 → 59 taken 5072 times.
✗ Branch 58 → 80 not taken.
|
10144 | return concludeNode(attrNode); |
| 830 | 5074 | } | |
| 831 | |||
| 832 | 331 | std::any ASTBuilder::visitCaseConstant(SpiceParser::CaseConstantContext *ctx) { | |
| 833 | 331 | const auto caseConstantNode = createNode<CaseConstantNode>(ctx); | |
| 834 | |||
| 835 | // Visit children | ||
| 836 |
2/2✓ Branch 4 → 5 taken 157 times.
✓ Branch 4 → 10 taken 174 times.
|
331 | if (ctx->constant()) { |
| 837 |
3/6✓ Branch 5 → 6 taken 157 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 157 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 157 times.
✗ Branch 7 → 63 not taken.
|
157 | caseConstantNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 838 |
2/4✓ Branch 10 → 11 taken 174 times.
✗ Branch 10 → 66 not taken.
✓ Branch 13 → 14 taken 174 times.
✗ Branch 13 → 52 not taken.
|
174 | } else if (!ctx->TYPE_IDENTIFIER().empty()) { |
| 839 |
1/2✓ Branch 14 → 15 taken 174 times.
✗ Branch 14 → 75 not taken.
|
174 | std::stringstream fqIdentifier; |
| 840 |
2/2✓ Branch 46 → 17 taken 518 times.
✓ Branch 46 → 47 taken 174 times.
|
866 | for (antlr4::tree::ParseTree *parseTree : ctx->children) { |
| 841 |
1/2✓ Branch 19 → 20 taken 518 times.
✗ Branch 19 → 21 not taken.
|
518 | const auto terminal = dynamic_cast<TerminalNode *>(parseTree); |
| 842 |
1/2✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 518 times.
|
518 | if (!terminal) |
| 843 | ✗ | continue; | |
| 844 | |||
| 845 |
2/4✓ Branch 24 → 25 taken 518 times.
✗ Branch 24 → 71 not taken.
✓ Branch 25 → 26 taken 518 times.
✗ Branch 25 → 71 not taken.
|
518 | const size_t terminalType = terminal->getSymbol()->getType(); |
| 846 |
3/4✓ Branch 26 → 27 taken 518 times.
✗ Branch 26 → 28 not taken.
✓ Branch 27 → 28 taken 346 times.
✓ Branch 27 → 37 taken 172 times.
|
518 | if (terminalType == SpiceParser::IDENTIFIER || terminalType == SpiceParser::TYPE_IDENTIFIER) { |
| 847 |
1/2✓ Branch 28 → 29 taken 346 times.
✗ Branch 28 → 70 not taken.
|
346 | const std::string fragment = getIdentifier(terminal, false); |
| 848 |
1/2✓ Branch 29 → 30 taken 346 times.
✗ Branch 29 → 68 not taken.
|
346 | caseConstantNode->identifierFragments.push_back(fragment); |
| 849 |
3/4✓ Branch 30 → 31 taken 346 times.
✗ Branch 30 → 67 not taken.
✓ Branch 32 → 33 taken 172 times.
✓ Branch 32 → 34 taken 174 times.
|
346 | if (fqIdentifier.tellp() != 0) |
| 850 |
1/2✓ Branch 33 → 34 taken 172 times.
✗ Branch 33 → 68 not taken.
|
172 | fqIdentifier << SCOPE_ACCESS_TOKEN; |
| 851 |
1/2✓ Branch 34 → 35 taken 346 times.
✗ Branch 34 → 68 not taken.
|
346 | fqIdentifier << fragment; |
| 852 | 346 | } | |
| 853 | } | ||
| 854 |
1/2✓ Branch 47 → 48 taken 174 times.
✗ Branch 47 → 72 not taken.
|
174 | caseConstantNode->fqIdentifier = fqIdentifier.str(); |
| 855 | 174 | } else { | |
| 856 | − | assert_fail("Unknown case constant type"); // GCOV_EXCL_LINE | |
| 857 | } | ||
| 858 | |||
| 859 |
1/2✓ Branch 59 → 60 taken 331 times.
✗ Branch 59 → 76 not taken.
|
662 | return concludeNode(caseConstantNode); |
| 860 | } | ||
| 861 | |||
| 862 | 55050 | std::any ASTBuilder::visitReturnStmt(SpiceParser::ReturnStmtContext *ctx) { | |
| 863 | 55050 | const auto returnStmtNode = createNode<ReturnStmtNode>(ctx); | |
| 864 | |||
| 865 | // Visit children | ||
| 866 |
2/2✓ Branch 4 → 5 taken 49054 times.
✓ Branch 4 → 10 taken 5996 times.
|
55050 | if (ctx->assignExpr()) { |
| 867 | 49054 | returnStmtNode->hasReturnValue = true; | |
| 868 |
3/6✓ Branch 5 → 6 taken 49054 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 49054 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 49054 times.
✗ Branch 7 → 20 not taken.
|
49054 | returnStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 869 | } | ||
| 870 | |||
| 871 |
1/2✓ Branch 16 → 17 taken 55050 times.
✗ Branch 16 → 23 not taken.
|
110100 | return concludeNode(returnStmtNode); |
| 872 | } | ||
| 873 | |||
| 874 | 1004 | std::any ASTBuilder::visitBreakStmt(SpiceParser::BreakStmtContext *ctx) { | |
| 875 | 1004 | const auto breakStmtNode = createNode<BreakStmtNode>(ctx); | |
| 876 | |||
| 877 | // Extract number of breaks | ||
| 878 |
2/2✓ Branch 4 → 5 taken 13 times.
✓ Branch 4 → 10 taken 991 times.
|
1004 | if (ctx->INT_LIT()) |
| 879 |
3/6✓ Branch 5 → 6 taken 13 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 13 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 13 times.
✗ Branch 7 → 22 not taken.
|
13 | breakStmtNode->breakTimes = std::stoi(ctx->INT_LIT()->toString()); |
| 880 | |||
| 881 | // Visit children | ||
| 882 |
2/4✓ Branch 10 → 11 taken 1004 times.
✗ Branch 10 → 25 not taken.
✓ Branch 12 → 13 taken 1004 times.
✗ Branch 12 → 26 not taken.
|
1004 | visitChildren(ctx); |
| 883 | |||
| 884 |
1/2✓ Branch 18 → 19 taken 1004 times.
✗ Branch 18 → 26 not taken.
|
2008 | return concludeNode(breakStmtNode); |
| 885 | } | ||
| 886 | |||
| 887 | 1052 | std::any ASTBuilder::visitContinueStmt(SpiceParser::ContinueStmtContext *ctx) { | |
| 888 | 1052 | const auto continueStmtNode = createNode<ContinueStmtNode>(ctx); | |
| 889 | |||
| 890 | // Extract number of continues | ||
| 891 |
2/2✓ Branch 4 → 5 taken 820 times.
✓ Branch 4 → 10 taken 232 times.
|
1052 | if (ctx->INT_LIT()) |
| 892 |
3/6✓ Branch 5 → 6 taken 820 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 820 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 820 times.
✗ Branch 7 → 22 not taken.
|
820 | continueStmtNode->continueTimes = std::stoi(ctx->INT_LIT()->toString()); |
| 893 | |||
| 894 | // Visit children | ||
| 895 |
2/4✓ Branch 10 → 11 taken 1052 times.
✗ Branch 10 → 25 not taken.
✓ Branch 12 → 13 taken 1052 times.
✗ Branch 12 → 26 not taken.
|
1052 | visitChildren(ctx); |
| 896 | |||
| 897 |
1/2✓ Branch 18 → 19 taken 1052 times.
✗ Branch 18 → 26 not taken.
|
2104 | return concludeNode(continueStmtNode); |
| 898 | } | ||
| 899 | |||
| 900 | 12 | std::any ASTBuilder::visitFallthroughStmt(SpiceParser::FallthroughStmtContext *ctx) { | |
| 901 | 12 | const auto fallthroughStmtNode = createNode<FallthroughStmtNode>(ctx); | |
| 902 | |||
| 903 | // Visit children | ||
| 904 |
2/4✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 15 not taken.
✓ Branch 5 → 6 taken 12 times.
✗ Branch 5 → 16 not taken.
|
12 | visitChildren(ctx); |
| 905 | |||
| 906 |
1/2✓ Branch 11 → 12 taken 12 times.
✗ Branch 11 → 16 not taken.
|
24 | return concludeNode(fallthroughStmtNode); |
| 907 | } | ||
| 908 | |||
| 909 | 6410 | std::any ASTBuilder::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) { | |
| 910 |
1/2✓ Branch 2 → 3 taken 6410 times.
✗ Branch 2 → 30 not taken.
|
6410 | const auto assertStmtNode = createNode<AssertStmtNode>(ctx); |
| 911 | |||
| 912 | // Enrich | ||
| 913 |
5/10✓ Branch 3 → 4 taken 6410 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 6410 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 6410 times.
✗ Branch 5 → 30 not taken.
✓ Branch 6 → 7 taken 6410 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 6410 times.
✗ Branch 7 → 30 not taken.
|
6410 | const antlr4::misc::Interval interval(ctx->assignExpr()->start->getStartIndex(), ctx->assignExpr()->stop->getStopIndex()); |
| 914 |
1/2✓ Branch 8 → 9 taken 6410 times.
✗ Branch 8 → 25 not taken.
|
6410 | assertStmtNode->expressionString = inputStream->getText(interval); |
| 915 | |||
| 916 | // Visit children | ||
| 917 |
4/8✓ Branch 11 → 12 taken 6410 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 13 taken 6410 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 6410 times.
✗ Branch 13 → 26 not taken.
✓ Branch 15 → 16 taken 6410 times.
✗ Branch 15 → 29 not taken.
|
6410 | assertStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 918 | |||
| 919 |
1/2✓ Branch 21 → 22 taken 6410 times.
✗ Branch 21 → 29 not taken.
|
12820 | return concludeNode(assertStmtNode); |
| 920 | } | ||
| 921 | |||
| 922 | 455746 | std::any ASTBuilder::visitAssignExpr(SpiceParser::AssignExprContext *ctx) { | |
| 923 |
2/2✓ Branch 3 → 4 taken 414149 times.
✓ Branch 3 → 6 taken 41597 times.
|
455746 | if (!ctx->assignOp()) |
| 924 | 414149 | return visit(ctx->ternaryExpr()); | |
| 925 | |||
| 926 | 41597 | const auto assignExprNode = createNode<AssignExprNode>(ctx); | |
| 927 | |||
| 928 | // Visit children | ||
| 929 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 41597 times.
|
41597 | if (ctx->ternaryExpr()) { |
| 930 | ✗ | assignExprNode->ternaryExpr = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr())); | |
| 931 |
1/2✓ Branch 15 → 16 taken 41597 times.
✗ Branch 15 → 28 not taken.
|
41597 | } else if (ctx->prefixUnaryExpr()) { |
| 932 |
3/6✓ Branch 16 → 17 taken 41597 times.
✗ Branch 16 → 44 not taken.
✓ Branch 17 → 18 taken 41597 times.
✗ Branch 17 → 44 not taken.
✓ Branch 18 → 19 taken 41597 times.
✗ Branch 18 → 42 not taken.
|
41597 | assignExprNode->lhs = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr())); |
| 933 |
2/4✓ Branch 20 → 21 taken 41597 times.
✗ Branch 20 → 45 not taken.
✓ Branch 21 → 22 taken 41597 times.
✗ Branch 21 → 45 not taken.
|
41597 | visit(ctx->assignOp()); |
| 934 |
3/6✓ Branch 23 → 24 taken 41597 times.
✗ Branch 23 → 48 not taken.
✓ Branch 24 → 25 taken 41597 times.
✗ Branch 24 → 48 not taken.
✓ Branch 25 → 26 taken 41597 times.
✗ Branch 25 → 46 not taken.
|
41597 | assignExprNode->rhs = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 935 | } else { | ||
| 936 | − | assert_fail("Invalid assign expression"); // GCOV_EXCL_LINE | |
| 937 | } | ||
| 938 | |||
| 939 |
1/2✓ Branch 35 → 36 taken 41597 times.
✗ Branch 35 → 49 not taken.
|
83194 | return concludeExprNode(assignExprNode); |
| 940 | } | ||
| 941 | |||
| 942 | 416812 | std::any ASTBuilder::visitTernaryExpr(SpiceParser::TernaryExprContext *ctx) { | |
| 943 |
3/4✓ Branch 2 → 3 taken 416812 times.
✗ Branch 2 → 45 not taken.
✓ Branch 5 → 6 taken 413227 times.
✓ Branch 5 → 8 taken 3585 times.
|
416812 | if (ctx->logicalOrExpr().size() == 1) |
| 944 | 413227 | return visit(ctx->logicalOrExpr(0)); | |
| 945 | |||
| 946 | 3585 | const auto ternaryExprNode = createNode<TernaryExprNode>(ctx); | |
| 947 | |||
| 948 |
3/6✓ Branch 9 → 10 taken 3585 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 3585 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 3585 times.
✗ Branch 11 → 46 not taken.
|
3585 | ternaryExprNode->condition = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(0))); |
| 949 |
3/4✓ Branch 13 → 14 taken 3585 times.
✗ Branch 13 → 49 not taken.
✓ Branch 16 → 17 taken 3583 times.
✓ Branch 16 → 26 taken 2 times.
|
3585 | if (ctx->logicalOrExpr().size() == 3) { |
| 950 |
3/6✓ Branch 17 → 18 taken 3583 times.
✗ Branch 17 → 52 not taken.
✓ Branch 18 → 19 taken 3583 times.
✗ Branch 18 → 52 not taken.
✓ Branch 19 → 20 taken 3583 times.
✗ Branch 19 → 50 not taken.
|
3583 | ternaryExprNode->trueExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(1))); |
| 951 |
3/6✓ Branch 21 → 22 taken 3583 times.
✗ Branch 21 → 55 not taken.
✓ Branch 22 → 23 taken 3583 times.
✗ Branch 22 → 55 not taken.
✓ Branch 23 → 24 taken 3583 times.
✗ Branch 23 → 53 not taken.
|
3583 | ternaryExprNode->falseExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(2))); |
| 952 |
2/4✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 56 not taken.
✓ Branch 29 → 30 taken 2 times.
✗ Branch 29 → 35 not taken.
|
2 | } else if (ctx->logicalOrExpr().size() == 2) { |
| 953 | 2 | ternaryExprNode->isShortened = true; | |
| 954 |
3/6✓ Branch 30 → 31 taken 2 times.
✗ Branch 30 → 59 not taken.
✓ Branch 31 → 32 taken 2 times.
✗ Branch 31 → 59 not taken.
✓ Branch 32 → 33 taken 2 times.
✗ Branch 32 → 57 not taken.
|
2 | ternaryExprNode->falseExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(1))); |
| 955 | } | ||
| 956 | |||
| 957 |
1/2✓ Branch 41 → 42 taken 3585 times.
✗ Branch 41 → 60 not taken.
|
7170 | return concludeExprNode(ternaryExprNode); |
| 958 | } | ||
| 959 | |||
| 960 | 423980 | std::any ASTBuilder::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext *ctx) { | |
| 961 |
3/4✓ Branch 2 → 3 taken 423980 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 418473 times.
✓ Branch 5 → 8 taken 5507 times.
|
423980 | if (ctx->logicalAndExpr().size() == 1) |
| 962 | 418473 | return visit(ctx->logicalAndExpr(0)); | |
| 963 | |||
| 964 | 5507 | const auto logicalOrExprNode = createNode<LogicalOrExprNode>(ctx); | |
| 965 | |||
| 966 | // Visit children | ||
| 967 |
3/6✓ Branch 9 → 10 taken 5507 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 5507 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 5507 times.
✗ Branch 12 → 26 not taken.
|
5507 | fetchChildrenIntoVector(logicalOrExprNode->operands, ctx->logicalAndExpr()); |
| 968 | |||
| 969 |
1/2✓ Branch 18 → 19 taken 5507 times.
✗ Branch 18 → 26 not taken.
|
11014 | return concludeExprNode(logicalOrExprNode); |
| 970 | } | ||
| 971 | |||
| 972 | 430949 | std::any ASTBuilder::visitLogicalAndExpr(SpiceParser::LogicalAndExprContext *ctx) { | |
| 973 |
3/4✓ Branch 2 → 3 taken 430949 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 428046 times.
✓ Branch 5 → 8 taken 2903 times.
|
430949 | if (ctx->bitwiseOrExpr().size() == 1) |
| 974 | 428046 | return visit(ctx->bitwiseOrExpr(0)); | |
| 975 | |||
| 976 | 2903 | const auto logicalAndExprNode = createNode<LogicalAndExprNode>(ctx); | |
| 977 | |||
| 978 | // Visit children | ||
| 979 |
3/6✓ Branch 9 → 10 taken 2903 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 2903 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 2903 times.
✗ Branch 12 → 26 not taken.
|
2903 | fetchChildrenIntoVector(logicalAndExprNode->operands, ctx->bitwiseOrExpr()); |
| 980 | |||
| 981 |
1/2✓ Branch 18 → 19 taken 2903 times.
✗ Branch 18 → 26 not taken.
|
5806 | return concludeExprNode(logicalAndExprNode); |
| 982 | } | ||
| 983 | |||
| 984 | 434152 | std::any ASTBuilder::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext *ctx) { | |
| 985 |
3/4✓ Branch 2 → 3 taken 434152 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 433520 times.
✓ Branch 5 → 8 taken 632 times.
|
434152 | if (ctx->bitwiseXorExpr().size() == 1) |
| 986 | 433520 | return visit(ctx->bitwiseXorExpr(0)); | |
| 987 | |||
| 988 | 632 | const auto bitwiseOrExprNode = createNode<BitwiseOrExprNode>(ctx); | |
| 989 | |||
| 990 | // Visit children | ||
| 991 |
3/6✓ Branch 9 → 10 taken 632 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 632 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 632 times.
✗ Branch 12 → 26 not taken.
|
632 | fetchChildrenIntoVector(bitwiseOrExprNode->operands, ctx->bitwiseXorExpr()); |
| 992 | |||
| 993 |
1/2✓ Branch 18 → 19 taken 632 times.
✗ Branch 18 → 26 not taken.
|
1264 | return concludeExprNode(bitwiseOrExprNode); |
| 994 | } | ||
| 995 | |||
| 996 | 434786 | std::any ASTBuilder::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprContext *ctx) { | |
| 997 |
3/4✓ Branch 2 → 3 taken 434786 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 434651 times.
✓ Branch 5 → 8 taken 135 times.
|
434786 | if (ctx->bitwiseAndExpr().size() == 1) |
| 998 | 434651 | return visit(ctx->bitwiseAndExpr(0)); | |
| 999 | |||
| 1000 | 135 | const auto bitwiseXorExprNode = createNode<BitwiseXorExprNode>(ctx); | |
| 1001 | |||
| 1002 | // Visit children | ||
| 1003 |
3/6✓ Branch 9 → 10 taken 135 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 135 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 135 times.
✗ Branch 12 → 26 not taken.
|
135 | fetchChildrenIntoVector(bitwiseXorExprNode->operands, ctx->bitwiseAndExpr()); |
| 1004 | |||
| 1005 |
1/2✓ Branch 18 → 19 taken 135 times.
✗ Branch 18 → 26 not taken.
|
270 | return concludeExprNode(bitwiseXorExprNode); |
| 1006 | } | ||
| 1007 | |||
| 1008 | 434923 | std::any ASTBuilder::visitBitwiseAndExpr(SpiceParser::BitwiseAndExprContext *ctx) { | |
| 1009 |
3/4✓ Branch 2 → 3 taken 434923 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 434497 times.
✓ Branch 5 → 8 taken 426 times.
|
434923 | if (ctx->equalityExpr().size() == 1) |
| 1010 | 434497 | return visit(ctx->equalityExpr(0)); | |
| 1011 | |||
| 1012 | 426 | const auto bitwiseAndExprNode = createNode<BitwiseAndExprNode>(ctx); | |
| 1013 | |||
| 1014 | // Visit children | ||
| 1015 |
3/6✓ Branch 9 → 10 taken 426 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 426 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 426 times.
✗ Branch 12 → 26 not taken.
|
426 | fetchChildrenIntoVector(bitwiseAndExprNode->operands, ctx->equalityExpr()); |
| 1016 | |||
| 1017 |
1/2✓ Branch 18 → 19 taken 426 times.
✗ Branch 18 → 26 not taken.
|
852 | return concludeExprNode(bitwiseAndExprNode); |
| 1018 | } | ||
| 1019 | |||
| 1020 | 435351 | std::any ASTBuilder::visitEqualityExpr(SpiceParser::EqualityExprContext *ctx) { | |
| 1021 |
3/4✓ Branch 2 → 3 taken 435351 times.
✗ Branch 2 → 28 not taken.
✓ Branch 5 → 6 taken 397763 times.
✓ Branch 5 → 8 taken 37588 times.
|
435351 | if (ctx->relationalExpr().size() == 1) |
| 1022 | 397763 | return visit(ctx->relationalExpr(0)); | |
| 1023 | |||
| 1024 | 37588 | const auto equalityExprNode = createNode<EqualityExprNode>(ctx); | |
| 1025 | |||
| 1026 | // Visit children | ||
| 1027 |
2/4✓ Branch 9 → 10 taken 37588 times.
✗ Branch 9 → 31 not taken.
✓ Branch 10 → 11 taken 37588 times.
✗ Branch 10 → 29 not taken.
|
37588 | fetchChildrenIntoVector(equalityExprNode->operands, ctx->relationalExpr()); |
| 1028 | |||
| 1029 | // Extract operator | ||
| 1030 |
2/2✓ Branch 13 → 14 taken 31665 times.
✓ Branch 13 → 15 taken 5923 times.
|
37588 | if (ctx->EQUAL()) |
| 1031 | 31665 | equalityExprNode->op = EqualityExprNode::EqualityOp::OP_EQUAL; | |
| 1032 |
1/2✓ Branch 16 → 17 taken 5923 times.
✗ Branch 16 → 18 not taken.
|
5923 | else if (ctx->NOT_EQUAL()) |
| 1033 | 5923 | equalityExprNode->op = EqualityExprNode::EqualityOp::OP_NOT_EQUAL; | |
| 1034 | |||
| 1035 |
1/2✓ Branch 24 → 25 taken 37588 times.
✗ Branch 24 → 32 not taken.
|
75176 | return concludeExprNode(equalityExprNode); |
| 1036 | } | ||
| 1037 | |||
| 1038 | 472939 | std::any ASTBuilder::visitRelationalExpr(SpiceParser::RelationalExprContext *ctx) { | |
| 1039 |
3/4✓ Branch 2 → 3 taken 472939 times.
✗ Branch 2 → 34 not taken.
✓ Branch 5 → 6 taken 451148 times.
✓ Branch 5 → 8 taken 21791 times.
|
472939 | if (ctx->shiftExpr().size() == 1) |
| 1040 | 451148 | return visit(ctx->shiftExpr(0)); | |
| 1041 | |||
| 1042 | 21791 | const auto relationalExprNode = createNode<RelationalExprNode>(ctx); | |
| 1043 | |||
| 1044 | // Visit children | ||
| 1045 |
2/4✓ Branch 9 → 10 taken 21791 times.
✗ Branch 9 → 37 not taken.
✓ Branch 10 → 11 taken 21791 times.
✗ Branch 10 → 35 not taken.
|
21791 | fetchChildrenIntoVector(relationalExprNode->operands, ctx->shiftExpr()); |
| 1046 | |||
| 1047 | // Extract operator | ||
| 1048 |
2/2✓ Branch 13 → 14 taken 9728 times.
✓ Branch 13 → 15 taken 12063 times.
|
21791 | if (ctx->LESS()) |
| 1049 | 9728 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS; | |
| 1050 |
2/2✓ Branch 16 → 17 taken 5470 times.
✓ Branch 16 → 18 taken 6593 times.
|
12063 | else if (ctx->GREATER()) |
| 1051 | 5470 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER; | |
| 1052 |
2/2✓ Branch 19 → 20 taken 2175 times.
✓ Branch 19 → 21 taken 4418 times.
|
6593 | else if (ctx->LESS_EQUAL()) |
| 1053 | 2175 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS_EQUAL; | |
| 1054 |
1/2✓ Branch 22 → 23 taken 4418 times.
✗ Branch 22 → 24 not taken.
|
4418 | else if (ctx->GREATER_EQUAL()) |
| 1055 | 4418 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER_EQUAL; | |
| 1056 | |||
| 1057 |
1/2✓ Branch 30 → 31 taken 21791 times.
✗ Branch 30 → 38 not taken.
|
43582 | return concludeExprNode(relationalExprNode); |
| 1058 | } | ||
| 1059 | |||
| 1060 | 494730 | std::any ASTBuilder::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) { | |
| 1061 |
3/4✓ Branch 2 → 3 taken 494730 times.
✗ Branch 2 → 60 not taken.
✓ Branch 5 → 6 taken 493666 times.
✓ Branch 5 → 8 taken 1064 times.
|
494730 | if (ctx->additiveExpr().size() == 1) |
| 1062 | 493666 | return visit(ctx->additiveExpr(0)); | |
| 1063 | |||
| 1064 | 1064 | const auto shiftExprNode = createNode<ShiftExprNode>(ctx); | |
| 1065 | |||
| 1066 | // Visit children | ||
| 1067 |
2/4✓ Branch 9 → 10 taken 1064 times.
✗ Branch 9 → 63 not taken.
✓ Branch 10 → 11 taken 1064 times.
✗ Branch 10 → 61 not taken.
|
1064 | fetchChildrenIntoVector(shiftExprNode->operands, ctx->additiveExpr()); |
| 1068 | |||
| 1069 | 1064 | bool seenFirstLess = false; | |
| 1070 | 1064 | bool seenFirstGreater = false; | |
| 1071 |
2/2✓ Branch 45 → 14 taken 4874 times.
✓ Branch 45 → 46 taken 1064 times.
|
7002 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1072 |
1/2✓ Branch 16 → 17 taken 4874 times.
✗ Branch 16 → 18 not taken.
|
4874 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1073 |
2/2✓ Branch 19 → 20 taken 2334 times.
✓ Branch 19 → 21 taken 2540 times.
|
4874 | if (!terminal) |
| 1074 | 2334 | continue; | |
| 1075 | |||
| 1076 |
4/6✓ Branch 21 → 22 taken 2540 times.
✗ Branch 21 → 68 not taken.
✓ Branch 22 → 23 taken 2540 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 1522 times.
✓ Branch 23 → 28 taken 1018 times.
|
2540 | if (terminal->getSymbol()->getType() == SpiceParser::LESS) { |
| 1077 |
2/2✓ Branch 24 → 25 taken 761 times.
✓ Branch 24 → 27 taken 761 times.
|
1522 | if (seenFirstLess) |
| 1078 |
1/2✓ Branch 25 → 26 taken 761 times.
✗ Branch 25 → 64 not taken.
|
761 | shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_LEFT, TY_INVALID); |
| 1079 | 1522 | seenFirstLess = !seenFirstLess; | |
| 1080 | 1522 | continue; | |
| 1081 | } | ||
| 1082 | |||
| 1083 |
3/6✓ Branch 28 → 29 taken 1018 times.
✗ Branch 28 → 68 not taken.
✓ Branch 29 → 30 taken 1018 times.
✗ Branch 29 → 68 not taken.
✓ Branch 30 → 31 taken 1018 times.
✗ Branch 30 → 35 not taken.
|
1018 | if (terminal->getSymbol()->getType() == SpiceParser::GREATER) { |
| 1084 |
2/2✓ Branch 31 → 32 taken 509 times.
✓ Branch 31 → 34 taken 509 times.
|
1018 | if (seenFirstGreater) |
| 1085 |
1/2✓ Branch 32 → 33 taken 509 times.
✗ Branch 32 → 66 not taken.
|
509 | shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT, TY_INVALID); |
| 1086 | 1018 | seenFirstGreater = !seenFirstGreater; | |
| 1087 | 1018 | continue; | |
| 1088 | } | ||
| 1089 | |||
| 1090 | − | assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE | |
| 1091 | } | ||
| 1092 |
2/4✓ Branch 46 → 47 taken 1064 times.
✗ Branch 46 → 49 not taken.
✓ Branch 47 → 48 taken 1064 times.
✗ Branch 47 → 49 not taken.
|
1064 | assert(!seenFirstLess && !seenFirstGreater); |
| 1093 | |||
| 1094 |
1/2✓ Branch 56 → 57 taken 1064 times.
✗ Branch 56 → 69 not taken.
|
2128 | return concludeExprNode(shiftExprNode); |
| 1095 | } | ||
| 1096 | |||
| 1097 | 496000 | std::any ASTBuilder::visitAdditiveExpr(SpiceParser::AdditiveExprContext *ctx) { | |
| 1098 |
3/4✓ Branch 2 → 3 taken 496000 times.
✗ Branch 2 → 52 not taken.
✓ Branch 5 → 6 taken 475821 times.
✓ Branch 5 → 8 taken 20179 times.
|
496000 | if (ctx->multiplicativeExpr().size() == 1) |
| 1099 | 475821 | return visit(ctx->multiplicativeExpr(0)); | |
| 1100 | |||
| 1101 | 20179 | const auto additiveExprNode = createNode<AdditiveExprNode>(ctx); | |
| 1102 | |||
| 1103 | // Visit children | ||
| 1104 |
2/4✓ Branch 9 → 10 taken 20179 times.
✗ Branch 9 → 55 not taken.
✓ Branch 10 → 11 taken 20179 times.
✗ Branch 10 → 53 not taken.
|
20179 | fetchChildrenIntoVector(additiveExprNode->operands, ctx->multiplicativeExpr()); |
| 1105 | |||
| 1106 |
2/2✓ Branch 41 → 14 taken 64661 times.
✓ Branch 41 → 42 taken 20179 times.
|
105019 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1107 |
1/2✓ Branch 16 → 17 taken 64661 times.
✗ Branch 16 → 18 not taken.
|
64661 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1108 |
2/2✓ Branch 19 → 20 taken 42420 times.
✓ Branch 19 → 21 taken 22241 times.
|
64661 | if (!terminal) |
| 1109 | 42420 | continue; | |
| 1110 | |||
| 1111 |
4/6✓ Branch 21 → 22 taken 22241 times.
✗ Branch 21 → 60 not taken.
✓ Branch 22 → 23 taken 22241 times.
✗ Branch 22 → 60 not taken.
✓ Branch 23 → 24 taken 14657 times.
✓ Branch 23 → 26 taken 7584 times.
|
22241 | if (terminal->getSymbol()->getType() == SpiceParser::PLUS) |
| 1112 |
1/2✓ Branch 24 → 25 taken 14657 times.
✗ Branch 24 → 56 not taken.
|
14657 | additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_PLUS, TY_INVALID); |
| 1113 |
3/6✓ Branch 26 → 27 taken 7584 times.
✗ Branch 26 → 60 not taken.
✓ Branch 27 → 28 taken 7584 times.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 7584 times.
✗ Branch 28 → 31 not taken.
|
7584 | else if (terminal->getSymbol()->getType() == SpiceParser::MINUS) |
| 1114 |
1/2✓ Branch 29 → 30 taken 7584 times.
✗ Branch 29 → 58 not taken.
|
7584 | additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_MINUS, TY_INVALID); |
| 1115 | else | ||
| 1116 | − | assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE | |
| 1117 | } | ||
| 1118 | |||
| 1119 |
1/2✓ Branch 48 → 49 taken 20179 times.
✗ Branch 48 → 61 not taken.
|
40358 | return concludeExprNode(additiveExprNode); |
| 1120 | } | ||
| 1121 | |||
| 1122 | 518241 | std::any ASTBuilder::visitMultiplicativeExpr(SpiceParser::MultiplicativeExprContext *ctx) { | |
| 1123 |
3/4✓ Branch 2 → 3 taken 518241 times.
✗ Branch 2 → 57 not taken.
✓ Branch 5 → 6 taken 513485 times.
✓ Branch 5 → 8 taken 4756 times.
|
518241 | if (ctx->castExpr().size() == 1) |
| 1124 | 513485 | return visit(ctx->castExpr(0)); | |
| 1125 | |||
| 1126 | 4756 | const auto multiplicativeExprNode = createNode<MultiplicativeExprNode>(ctx); | |
| 1127 | |||
| 1128 | // Visit children | ||
| 1129 |
2/4✓ Branch 9 → 10 taken 4756 times.
✗ Branch 9 → 60 not taken.
✓ Branch 10 → 11 taken 4756 times.
✗ Branch 10 → 58 not taken.
|
4756 | fetchChildrenIntoVector(multiplicativeExprNode->operands, ctx->castExpr()); |
| 1130 | |||
| 1131 |
2/2✓ Branch 46 → 14 taken 14530 times.
✓ Branch 46 → 47 taken 4756 times.
|
24042 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1132 |
1/2✓ Branch 16 → 17 taken 14530 times.
✗ Branch 16 → 18 not taken.
|
14530 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1133 |
2/2✓ Branch 19 → 20 taken 9643 times.
✓ Branch 19 → 21 taken 4887 times.
|
14530 | if (!terminal) |
| 1134 | 9643 | continue; | |
| 1135 | |||
| 1136 |
4/6✓ Branch 21 → 22 taken 4887 times.
✗ Branch 21 → 67 not taken.
✓ Branch 22 → 23 taken 4887 times.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 3962 times.
✓ Branch 23 → 26 taken 925 times.
|
4887 | if (terminal->getSymbol()->getType() == SpiceParser::MUL) |
| 1137 |
1/2✓ Branch 24 → 25 taken 3962 times.
✗ Branch 24 → 61 not taken.
|
3962 | multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_MUL, TY_INVALID); |
| 1138 |
4/6✓ Branch 26 → 27 taken 925 times.
✗ Branch 26 → 67 not taken.
✓ Branch 27 → 28 taken 925 times.
✗ Branch 27 → 67 not taken.
✓ Branch 28 → 29 taken 603 times.
✓ Branch 28 → 31 taken 322 times.
|
925 | else if (terminal->getSymbol()->getType() == SpiceParser::DIV) |
| 1139 |
1/2✓ Branch 29 → 30 taken 603 times.
✗ Branch 29 → 63 not taken.
|
603 | multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_DIV, TY_INVALID); |
| 1140 |
3/6✓ Branch 31 → 32 taken 322 times.
✗ Branch 31 → 67 not taken.
✓ Branch 32 → 33 taken 322 times.
✗ Branch 32 → 67 not taken.
✓ Branch 33 → 34 taken 322 times.
✗ Branch 33 → 36 not taken.
|
322 | else if (terminal->getSymbol()->getType() == SpiceParser::REM) |
| 1141 |
1/2✓ Branch 34 → 35 taken 322 times.
✗ Branch 34 → 65 not taken.
|
322 | multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_REM, TY_INVALID); |
| 1142 | else | ||
| 1143 | − | assert_fail("Invalid terminal symbol for multiplicative expression"); // GCOV_EXCL_LINE | |
| 1144 | } | ||
| 1145 | |||
| 1146 |
1/2✓ Branch 53 → 54 taken 4756 times.
✗ Branch 53 → 68 not taken.
|
9512 | return concludeExprNode(multiplicativeExprNode); |
| 1147 | } | ||
| 1148 | |||
| 1149 | 523128 | std::any ASTBuilder::visitCastExpr(SpiceParser::CastExprContext *ctx) { | |
| 1150 |
2/2✓ Branch 3 → 4 taken 506554 times.
✓ Branch 3 → 6 taken 16574 times.
|
523128 | if (!ctx->CAST()) |
| 1151 | 506554 | return visit(ctx->prefixUnaryExpr()); | |
| 1152 | |||
| 1153 | 16574 | const auto castExprNode = createNode<CastExprNode>(ctx); | |
| 1154 | |||
| 1155 | // Visit children | ||
| 1156 |
1/2✓ Branch 8 → 9 taken 16574 times.
✗ Branch 8 → 18 not taken.
|
16574 | if (ctx->dataType()) { |
| 1157 |
3/6✓ Branch 9 → 10 taken 16574 times.
✗ Branch 9 → 35 not taken.
✓ Branch 10 → 11 taken 16574 times.
✗ Branch 10 → 35 not taken.
✓ Branch 11 → 12 taken 16574 times.
✗ Branch 11 → 33 not taken.
|
16574 | castExprNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1158 |
3/6✓ Branch 13 → 14 taken 16574 times.
✗ Branch 13 → 38 not taken.
✓ Branch 14 → 15 taken 16574 times.
✗ Branch 14 → 38 not taken.
✓ Branch 15 → 16 taken 16574 times.
✗ Branch 15 → 36 not taken.
|
16574 | castExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1159 | 16574 | castExprNode->isCast = true; | |
| 1160 | } else { | ||
| 1161 | ✗ | castExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr())); | |
| 1162 | } | ||
| 1163 | |||
| 1164 |
1/2✓ Branch 29 → 30 taken 16574 times.
✗ Branch 29 → 42 not taken.
|
33148 | return concludeExprNode(castExprNode); |
| 1165 | } | ||
| 1166 | |||
| 1167 | 557663 | std::any ASTBuilder::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprContext *ctx) { | |
| 1168 |
2/2✓ Branch 3 → 4 taken 548151 times.
✓ Branch 3 → 6 taken 9512 times.
|
557663 | if (!ctx->prefixUnaryExpr()) |
| 1169 | 548151 | return visit(ctx->postfixUnaryExpr()); | |
| 1170 | |||
| 1171 | 9512 | const auto prefixUnaryExprNode = createNode<PrefixUnaryExprNode>(ctx); | |
| 1172 | |||
| 1173 | // Visit children | ||
| 1174 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 9512 times.
|
9512 | if (ctx->postfixUnaryExpr()) { |
| 1175 | ✗ | prefixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr())); | |
| 1176 |
1/2✓ Branch 15 → 16 taken 9512 times.
✗ Branch 15 → 42 not taken.
|
9512 | } else if (ctx->prefixUnaryExpr()) { |
| 1177 | // Extract operator | ||
| 1178 |
2/2✓ Branch 17 → 18 taken 335 times.
✓ Branch 17 → 19 taken 9177 times.
|
9512 | if (ctx->MINUS()) |
| 1179 | 335 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS; | |
| 1180 |
2/2✓ Branch 20 → 21 taken 24 times.
✓ Branch 20 → 22 taken 9153 times.
|
9177 | else if (ctx->PLUS_PLUS()) |
| 1181 | 24 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS; | |
| 1182 |
2/2✓ Branch 23 → 24 taken 133 times.
✓ Branch 23 → 25 taken 9020 times.
|
9153 | else if (ctx->MINUS_MINUS()) |
| 1183 | 133 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS; | |
| 1184 |
2/2✓ Branch 26 → 27 taken 5836 times.
✓ Branch 26 → 28 taken 3184 times.
|
9020 | else if (ctx->NOT()) |
| 1185 | 5836 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT; | |
| 1186 |
2/2✓ Branch 29 → 30 taken 56 times.
✓ Branch 29 → 31 taken 3128 times.
|
3184 | else if (ctx->BITWISE_NOT()) |
| 1187 | 56 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT; | |
| 1188 |
2/2✓ Branch 32 → 33 taken 1264 times.
✓ Branch 32 → 34 taken 1864 times.
|
3128 | else if (ctx->MUL()) |
| 1189 | 1264 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE; | |
| 1190 |
1/2✓ Branch 35 → 36 taken 1864 times.
✗ Branch 35 → 37 not taken.
|
1864 | else if (ctx->BITWISE_AND()) |
| 1191 | 1864 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF; | |
| 1192 | |||
| 1193 |
3/6✓ Branch 37 → 38 taken 9512 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 9512 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 9512 times.
✗ Branch 39 → 56 not taken.
|
9512 | prefixUnaryExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr())); |
| 1194 | } else { | ||
| 1195 | − | assert_fail("Unknown prefix unary expression type"); // GCOV_EXCL_LINE | |
| 1196 | } | ||
| 1197 | |||
| 1198 |
1/2✓ Branch 49 → 50 taken 9512 times.
✗ Branch 49 → 59 not taken.
|
19024 | return concludeExprNode(prefixUnaryExprNode); |
| 1199 | } | ||
| 1200 | |||
| 1201 | 689479 | std::any ASTBuilder::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprContext *ctx) { | |
| 1202 |
2/2✓ Branch 3 → 4 taken 548151 times.
✓ Branch 3 → 6 taken 141328 times.
|
689479 | if (!ctx->postfixUnaryExpr()) |
| 1203 | 548151 | return visit(ctx->atomicExpr()); | |
| 1204 | |||
| 1205 | 141328 | const auto postfixUnaryExprNode = createNode<PostfixUnaryExprNode>(ctx); | |
| 1206 | |||
| 1207 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 141328 times.
|
141328 | if (ctx->atomicExpr()) { |
| 1208 | ✗ | postfixUnaryExprNode->atomicExpr = std::any_cast<ExprNode *>(visit(ctx->atomicExpr())); | |
| 1209 |
1/2✓ Branch 15 → 16 taken 141328 times.
✗ Branch 15 → 43 not taken.
|
141328 | } else if (ctx->postfixUnaryExpr()) { |
| 1210 |
3/6✓ Branch 16 → 17 taken 141328 times.
✗ Branch 16 → 59 not taken.
✓ Branch 17 → 18 taken 141328 times.
✗ Branch 17 → 59 not taken.
✓ Branch 18 → 19 taken 141328 times.
✗ Branch 18 → 57 not taken.
|
141328 | postfixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr())); |
| 1211 | |||
| 1212 | // Extract operator | ||
| 1213 |
2/2✓ Branch 21 → 22 taken 16329 times.
✓ Branch 21 → 27 taken 124999 times.
|
141328 | if (ctx->assignExpr()) { |
| 1214 | 16329 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT; | |
| 1215 |
3/6✓ Branch 22 → 23 taken 16329 times.
✗ Branch 22 → 62 not taken.
✓ Branch 23 → 24 taken 16329 times.
✗ Branch 23 → 62 not taken.
✓ Branch 24 → 25 taken 16329 times.
✗ Branch 24 → 60 not taken.
|
16329 | postfixUnaryExprNode->subscriptIndexExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1216 |
2/2✓ Branch 28 → 29 taken 113792 times.
✓ Branch 28 → 34 taken 11207 times.
|
124999 | } else if (ctx->IDENTIFIER()) { |
| 1217 | 113792 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS; | |
| 1218 |
2/4✓ Branch 29 → 30 taken 113792 times.
✗ Branch 29 → 63 not taken.
✓ Branch 30 → 31 taken 113792 times.
✗ Branch 30 → 63 not taken.
|
113792 | postfixUnaryExprNode->identifier = getIdentifier(ctx->IDENTIFIER(), false); |
| 1219 |
2/2✓ Branch 35 → 36 taken 9712 times.
✓ Branch 35 → 37 taken 1495 times.
|
11207 | } else if (ctx->PLUS_PLUS()) { |
| 1220 | 9712 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS; | |
| 1221 |
2/2✓ Branch 38 → 39 taken 1349 times.
✓ Branch 38 → 40 taken 146 times.
|
1495 | } else if (ctx->MINUS_MINUS()) { |
| 1222 | 1349 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS; | |
| 1223 |
1/2✓ Branch 41 → 42 taken 146 times.
✗ Branch 41 → 44 not taken.
|
146 | } else if (ctx->NOT()) { |
| 1224 | 146 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_ERR_PROPAGATION; | |
| 1225 | } | ||
| 1226 | } else { | ||
| 1227 | − | assert_fail("Unknown postfix unary expression type"); // GCOV_EXCL_LINE | |
| 1228 | } | ||
| 1229 | |||
| 1230 |
1/2✓ Branch 50 → 51 taken 141328 times.
✗ Branch 50 → 64 not taken.
|
282656 | return concludeExprNode(postfixUnaryExprNode); |
| 1231 | } | ||
| 1232 | |||
| 1233 | 548151 | std::any ASTBuilder::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) { | |
| 1234 | 548151 | const auto atomicExprNode = createNode<AtomicExprNode>(ctx); | |
| 1235 | |||
| 1236 | // Visit children | ||
| 1237 |
2/2✓ Branch 4 → 5 taken 103386 times.
✓ Branch 4 → 10 taken 444765 times.
|
548151 | if (ctx->constant()) { |
| 1238 |
4/6✓ Branch 5 → 6 taken 103386 times.
✗ Branch 5 → 88 not taken.
✓ Branch 6 → 7 taken 103382 times.
✓ Branch 6 → 88 taken 4 times.
✓ Branch 7 → 8 taken 103382 times.
✗ Branch 7 → 86 not taken.
|
103386 | atomicExprNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 1239 |
2/2✓ Branch 11 → 12 taken 127124 times.
✓ Branch 11 → 17 taken 317641 times.
|
444765 | } else if (ctx->value()) { |
| 1240 |
3/6✓ Branch 12 → 13 taken 127124 times.
✗ Branch 12 → 91 not taken.
✓ Branch 13 → 14 taken 127124 times.
✗ Branch 13 → 91 not taken.
✓ Branch 14 → 15 taken 127124 times.
✗ Branch 14 → 89 not taken.
|
127124 | atomicExprNode->value = std::any_cast<ValueNode *>(visit(ctx->value())); |
| 1241 |
11/18✓ Branch 17 → 18 taken 317641 times.
✗ Branch 17 → 92 not taken.
✓ Branch 19 → 20 taken 14060 times.
✓ Branch 19 → 23 taken 303581 times.
✓ Branch 20 → 21 taken 14060 times.
✗ Branch 20 → 92 not taken.
✓ Branch 22 → 23 taken 10684 times.
✓ Branch 22 → 24 taken 3376 times.
✓ Branch 25 → 26 taken 14060 times.
✓ Branch 25 → 27 taken 303581 times.
✓ Branch 27 → 28 taken 317641 times.
✗ Branch 27 → 29 not taken.
✓ Branch 29 → 30 taken 314265 times.
✓ Branch 29 → 68 taken 3376 times.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 94 not taken.
✗ Branch 96 → 97 not taken.
✗ Branch 96 → 98 not taken.
|
317641 | } else if (!ctx->IDENTIFIER().empty() || !ctx->TYPE_IDENTIFIER().empty()) { |
| 1242 |
1/2✓ Branch 30 → 31 taken 314265 times.
✗ Branch 30 → 108 not taken.
|
314265 | std::stringstream fqIdentifier; |
| 1243 |
2/2✓ Branch 62 → 33 taken 321291 times.
✓ Branch 62 → 63 taken 314265 times.
|
949821 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1244 |
1/2✓ Branch 35 → 36 taken 321291 times.
✗ Branch 35 → 37 not taken.
|
321291 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1245 |
1/2✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 321291 times.
|
321291 | if (!terminal) |
| 1246 | ✗ | continue; | |
| 1247 | |||
| 1248 |
2/4✓ Branch 40 → 41 taken 321291 times.
✗ Branch 40 → 104 not taken.
✓ Branch 41 → 42 taken 321291 times.
✗ Branch 41 → 104 not taken.
|
321291 | const size_t terminalType = terminal->getSymbol()->getType(); |
| 1249 |
4/4✓ Branch 42 → 43 taken 17710 times.
✓ Branch 42 → 44 taken 303581 times.
✓ Branch 43 → 44 taken 14197 times.
✓ Branch 43 → 53 taken 3513 times.
|
321291 | if (terminalType == SpiceParser::IDENTIFIER || terminalType == SpiceParser::TYPE_IDENTIFIER) { |
| 1250 |
1/2✓ Branch 44 → 45 taken 317778 times.
✗ Branch 44 → 103 not taken.
|
317778 | const std::string fragment = getIdentifier(terminal, false); |
| 1251 |
1/2✓ Branch 45 → 46 taken 317778 times.
✗ Branch 45 → 101 not taken.
|
317778 | atomicExprNode->identifierFragments.push_back(fragment); |
| 1252 |
3/4✓ Branch 46 → 47 taken 317778 times.
✗ Branch 46 → 100 not taken.
✓ Branch 48 → 49 taken 3513 times.
✓ Branch 48 → 50 taken 314265 times.
|
317778 | if (fqIdentifier.tellp() != 0) |
| 1253 |
1/2✓ Branch 49 → 50 taken 3513 times.
✗ Branch 49 → 101 not taken.
|
3513 | fqIdentifier << SCOPE_ACCESS_TOKEN; |
| 1254 |
1/2✓ Branch 50 → 51 taken 317778 times.
✗ Branch 50 → 101 not taken.
|
317778 | fqIdentifier << fragment; |
| 1255 | 317778 | } | |
| 1256 | } | ||
| 1257 |
1/2✓ Branch 63 → 64 taken 314265 times.
✗ Branch 63 → 105 not taken.
|
314265 | atomicExprNode->fqIdentifier = fqIdentifier.str(); |
| 1258 |
1/2✓ Branch 69 → 70 taken 3376 times.
✗ Branch 69 → 75 not taken.
|
317641 | } else if (ctx->assignExpr()) { |
| 1259 |
3/6✓ Branch 70 → 71 taken 3376 times.
✗ Branch 70 → 111 not taken.
✓ Branch 71 → 72 taken 3376 times.
✗ Branch 71 → 111 not taken.
✓ Branch 72 → 73 taken 3376 times.
✗ Branch 72 → 109 not taken.
|
3376 | atomicExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1260 | } else { | ||
| 1261 | − | assert_fail("Unknown atomic expression type"); // GCOV_EXCL_LINE | |
| 1262 | } | ||
| 1263 | |||
| 1264 |
1/2✓ Branch 82 → 83 taken 548147 times.
✗ Branch 82 → 112 not taken.
|
1096294 | return concludeExprNode(atomicExprNode); |
| 1265 | } | ||
| 1266 | |||
| 1267 | 127124 | std::any ASTBuilder::visitValue(SpiceParser::ValueContext *ctx) { | |
| 1268 | 127124 | const auto valueNode = createNode<ValueNode>(ctx); | |
| 1269 | |||
| 1270 | // Visit children | ||
| 1271 |
2/2✓ Branch 4 → 5 taken 113030 times.
✓ Branch 4 → 10 taken 14094 times.
|
127124 | if (ctx->fctCall()) { |
| 1272 |
3/6✓ Branch 5 → 6 taken 113030 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 113030 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 113030 times.
✗ Branch 7 → 63 not taken.
|
113030 | valueNode->fctCall = std::any_cast<FctCallNode *>(visit(ctx->fctCall())); |
| 1273 |
2/2✓ Branch 11 → 12 taken 256 times.
✓ Branch 11 → 17 taken 13838 times.
|
14094 | } else if (ctx->arrayInitialization()) { |
| 1274 |
3/6✓ Branch 12 → 13 taken 256 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 256 times.
✗ Branch 13 → 68 not taken.
✓ Branch 14 → 15 taken 256 times.
✗ Branch 14 → 66 not taken.
|
256 | valueNode->arrayInitialization = std::any_cast<ArrayInitializationNode *>(visit(ctx->arrayInitialization())); |
| 1275 |
2/2✓ Branch 18 → 19 taken 2157 times.
✓ Branch 18 → 24 taken 11681 times.
|
13838 | } else if (ctx->structInstantiation()) { |
| 1276 |
3/6✓ Branch 19 → 20 taken 2157 times.
✗ Branch 19 → 71 not taken.
✓ Branch 20 → 21 taken 2157 times.
✗ Branch 20 → 71 not taken.
✓ Branch 21 → 22 taken 2157 times.
✗ Branch 21 → 69 not taken.
|
2157 | valueNode->structInstantiation = std::any_cast<StructInstantiationNode *>(visit(ctx->structInstantiation())); |
| 1277 |
2/2✓ Branch 25 → 26 taken 112 times.
✓ Branch 25 → 31 taken 11569 times.
|
11681 | } else if (ctx->lambdaFunc()) { |
| 1278 |
3/6✓ Branch 26 → 27 taken 112 times.
✗ Branch 26 → 74 not taken.
✓ Branch 27 → 28 taken 112 times.
✗ Branch 27 → 74 not taken.
✓ Branch 28 → 29 taken 112 times.
✗ Branch 28 → 72 not taken.
|
112 | valueNode->lambdaFunc = std::any_cast<LambdaFuncNode *>(visit(ctx->lambdaFunc())); |
| 1279 |
2/2✓ Branch 32 → 33 taken 94 times.
✓ Branch 32 → 38 taken 11475 times.
|
11569 | } else if (ctx->lambdaProc()) { |
| 1280 |
3/6✓ Branch 33 → 34 taken 94 times.
✗ Branch 33 → 77 not taken.
✓ Branch 34 → 35 taken 94 times.
✗ Branch 34 → 77 not taken.
✓ Branch 35 → 36 taken 94 times.
✗ Branch 35 → 75 not taken.
|
94 | valueNode->lambdaProc = std::any_cast<LambdaProcNode *>(visit(ctx->lambdaProc())); |
| 1281 |
2/2✓ Branch 39 → 40 taken 2 times.
✓ Branch 39 → 45 taken 11473 times.
|
11475 | } else if (ctx->lambdaExpr()) { |
| 1282 |
3/6✓ Branch 40 → 41 taken 2 times.
✗ Branch 40 → 80 not taken.
✓ Branch 41 → 42 taken 2 times.
✗ Branch 41 → 80 not taken.
✓ Branch 42 → 43 taken 2 times.
✗ Branch 42 → 78 not taken.
|
2 | valueNode->lambdaExpr = std::any_cast<LambdaExprNode *>(visit(ctx->lambdaExpr())); |
| 1283 |
1/2✓ Branch 46 → 47 taken 11473 times.
✗ Branch 46 → 52 not taken.
|
11473 | } else if (ctx->dataType()) { |
| 1284 | 11473 | valueNode->isNil = true; | |
| 1285 |
3/6✓ Branch 47 → 48 taken 11473 times.
✗ Branch 47 → 83 not taken.
✓ Branch 48 → 49 taken 11473 times.
✗ Branch 48 → 83 not taken.
✓ Branch 49 → 50 taken 11473 times.
✗ Branch 49 → 81 not taken.
|
11473 | valueNode->nilType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1286 | } else { | ||
| 1287 | − | assert_fail("Unknown value type"); // GCOV_EXCL_LINE | |
| 1288 | } | ||
| 1289 | |||
| 1290 |
1/2✓ Branch 59 → 60 taken 127124 times.
✗ Branch 59 → 84 not taken.
|
254248 | return concludeNode(valueNode); |
| 1291 | } | ||
| 1292 | |||
| 1293 | 112762 | std::any ASTBuilder::visitConstant(SpiceParser::ConstantContext *ctx) { | |
| 1294 | 112762 | const auto constantNode = createNode<ConstantNode>(ctx); | |
| 1295 | |||
| 1296 | // Detect an optional leading minus sign for numeric literals | ||
| 1297 | 112762 | const bool isNegative = ctx->MINUS() != nullptr; | |
| 1298 | |||
| 1299 | // Enrich | ||
| 1300 |
2/2✓ Branch 5 → 6 taken 2842 times.
✓ Branch 5 → 14 taken 109920 times.
|
112762 | if (ctx->DOUBLE_LIT()) { |
| 1301 | 2842 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_DOUBLE; | |
| 1302 |
3/6✓ Branch 6 → 7 taken 2842 times.
✗ Branch 6 → 75 not taken.
✓ Branch 7 → 8 taken 2842 times.
✗ Branch 7 → 75 not taken.
✓ Branch 8 → 9 taken 2842 times.
✗ Branch 8 → 73 not taken.
|
2842 | const double value = std::stod(ctx->DOUBLE_LIT()->toString()); |
| 1303 |
2/2✓ Branch 10 → 11 taken 278 times.
✓ Branch 10 → 12 taken 2564 times.
|
2842 | constantNode->compileTimeValue.doubleValue = isNegative ? -value : value; |
| 1304 |
2/2✓ Branch 15 → 16 taken 23556 times.
✓ Branch 15 → 23 taken 86364 times.
|
109920 | } else if (ctx->INT_LIT()) { |
| 1305 | 23556 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_INT; | |
| 1306 |
2/4✓ Branch 16 → 17 taken 23556 times.
✗ Branch 16 → 76 not taken.
✓ Branch 17 → 18 taken 23556 times.
✗ Branch 17 → 76 not taken.
|
23556 | constantNode->isUnsigned = isUnsignedLiteral(ctx->INT_LIT()->toString()); |
| 1307 | 23556 | constantNode->compileTimeValue.intValue = parseInt(ctx->INT_LIT(), isNegative); | |
| 1308 |
2/2✓ Branch 24 → 25 taken 2850 times.
✓ Branch 24 → 32 taken 83514 times.
|
86364 | } else if (ctx->SHORT_LIT()) { |
| 1309 | 2850 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_SHORT; | |
| 1310 |
2/4✓ Branch 25 → 26 taken 2850 times.
✗ Branch 25 → 77 not taken.
✓ Branch 26 → 27 taken 2850 times.
✗ Branch 26 → 77 not taken.
|
2850 | constantNode->isUnsigned = isUnsignedLiteral(ctx->SHORT_LIT()->toString()); |
| 1311 | 2850 | constantNode->compileTimeValue.shortValue = parseShort(ctx->SHORT_LIT(), isNegative); | |
| 1312 |
2/2✓ Branch 33 → 34 taken 39821 times.
✓ Branch 33 → 41 taken 43693 times.
|
83514 | } else if (ctx->LONG_LIT()) { |
| 1313 | 39821 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_LONG; | |
| 1314 |
2/4✓ Branch 34 → 35 taken 39821 times.
✗ Branch 34 → 78 not taken.
✓ Branch 35 → 36 taken 39821 times.
✗ Branch 35 → 78 not taken.
|
39821 | constantNode->isUnsigned = isUnsignedLiteral(ctx->LONG_LIT()->toString()); |
| 1315 | 39821 | constantNode->compileTimeValue.longValue = parseLong(ctx->LONG_LIT(), isNegative); | |
| 1316 |
2/2✓ Branch 42 → 43 taken 13685 times.
✓ Branch 42 → 46 taken 30008 times.
|
43693 | } else if (ctx->CHAR_LIT()) { |
| 1317 | 13685 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_CHAR; | |
| 1318 | 13685 | constantNode->compileTimeValue.charValue = parseChar(ctx->CHAR_LIT()); | |
| 1319 |
2/2✓ Branch 47 → 48 taken 20515 times.
✓ Branch 47 → 56 taken 9493 times.
|
30008 | } else if (ctx->STRING_LIT()) { |
| 1320 | // Save a pointer to the string in the compile time value | ||
| 1321 | 20515 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_STRING; | |
| 1322 | 20515 | constantNode->compileTimeValue.stringValueOffset = resourceManager.compileTimeStringValues.size(); | |
| 1323 | // Add the string to the global compile time string list | ||
| 1324 |
4/8✓ Branch 49 → 50 taken 20515 times.
✗ Branch 49 → 83 not taken.
✓ Branch 50 → 51 taken 20515 times.
✗ Branch 50 → 83 not taken.
✓ Branch 51 → 52 taken 20515 times.
✗ Branch 51 → 81 not taken.
✓ Branch 52 → 53 taken 20515 times.
✗ Branch 52 → 79 not taken.
|
20515 | resourceManager.compileTimeStringValues.push_back(parseString(ctx->STRING_LIT()->toString())); |
| 1325 |
2/2✓ Branch 57 → 58 taken 5273 times.
✓ Branch 57 → 59 taken 4220 times.
|
9493 | } else if (ctx->TRUE()) { |
| 1326 | 5273 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL; | |
| 1327 | 5273 | constantNode->compileTimeValue.boolValue = true; | |
| 1328 |
1/2✓ Branch 60 → 61 taken 4220 times.
✗ Branch 60 → 62 not taken.
|
4220 | } else if (ctx->FALSE()) { |
| 1329 | 4220 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL; | |
| 1330 | 4220 | constantNode->compileTimeValue.boolValue = false; | |
| 1331 | } else { | ||
| 1332 | − | assert_fail("Unknown constant type"); // GCOV_EXCL_LINE | |
| 1333 | } | ||
| 1334 | |||
| 1335 |
1/2✓ Branch 69 → 70 taken 112758 times.
✗ Branch 69 → 85 not taken.
|
225516 | return concludeNode(constantNode); |
| 1336 | } | ||
| 1337 | |||
| 1338 | 113030 | std::any ASTBuilder::visitFctCall(SpiceParser::FctCallContext *ctx) { | |
| 1339 |
1/2✓ Branch 2 → 3 taken 113030 times.
✗ Branch 2 → 92 not taken.
|
113030 | const auto fctCallNode = createNode<FctCallNode>(ctx); |
| 1340 | |||
| 1341 |
1/2✓ Branch 3 → 4 taken 113030 times.
✗ Branch 3 → 92 not taken.
|
113030 | std::stringstream fqFunctionName; |
| 1342 |
2/2✓ Branch 46 → 6 taken 547453 times.
✓ Branch 46 → 47 taken 113030 times.
|
773513 | for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1343 |
1/2✓ Branch 8 → 9 taken 547453 times.
✗ Branch 8 → 10 not taken.
|
547453 | const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree); |
| 1344 |
2/2✓ Branch 11 → 12 taken 90513 times.
✓ Branch 11 → 13 taken 456940 times.
|
547453 | if (!terminal) |
| 1345 | 90513 | continue; | |
| 1346 | |||
| 1347 |
4/6✓ Branch 13 → 14 taken 456940 times.
✗ Branch 13 → 81 not taken.
✓ Branch 14 → 15 taken 456940 times.
✗ Branch 14 → 81 not taken.
✓ Branch 15 → 16 taken 148705 times.
✓ Branch 15 → 21 taken 308235 times.
|
456940 | if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) { |
| 1348 |
1/2✓ Branch 16 → 17 taken 148705 times.
✗ Branch 16 → 77 not taken.
|
148705 | const std::string fragment = terminal->toString(); |
| 1349 |
1/2✓ Branch 17 → 18 taken 148705 times.
✗ Branch 17 → 75 not taken.
|
148705 | fctCallNode->functionNameFragments.push_back(fragment); |
| 1350 |
1/2✓ Branch 18 → 19 taken 148705 times.
✗ Branch 18 → 75 not taken.
|
148705 | fqFunctionName << fragment; |
| 1351 |
4/6✓ Branch 21 → 22 taken 308235 times.
✗ Branch 21 → 81 not taken.
✓ Branch 22 → 23 taken 308235 times.
✗ Branch 22 → 81 not taken.
✓ Branch 23 → 24 taken 15803 times.
✓ Branch 23 → 29 taken 292432 times.
|
456940 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1352 |
1/2✓ Branch 24 → 25 taken 15803 times.
✗ Branch 24 → 80 not taken.
|
15803 | const std::string fragment = terminal->toString(); |
| 1353 |
1/2✓ Branch 25 → 26 taken 15803 times.
✗ Branch 25 → 78 not taken.
|
15803 | fctCallNode->functionNameFragments.push_back(fragment); |
| 1354 |
1/2✓ Branch 26 → 27 taken 15803 times.
✗ Branch 26 → 78 not taken.
|
15803 | fqFunctionName << fragment; |
| 1355 |
4/6✓ Branch 29 → 30 taken 292432 times.
✗ Branch 29 → 81 not taken.
✓ Branch 30 → 31 taken 292432 times.
✗ Branch 30 → 81 not taken.
✓ Branch 31 → 32 taken 354 times.
✓ Branch 31 → 33 taken 292078 times.
|
308235 | } else if (terminal->getSymbol()->getType() == SpiceParser::SCOPE_ACCESS) { |
| 1356 |
1/2✓ Branch 32 → 37 taken 354 times.
✗ Branch 32 → 81 not taken.
|
354 | fqFunctionName << SCOPE_ACCESS_TOKEN; |
| 1357 |
4/6✓ Branch 33 → 34 taken 292078 times.
✗ Branch 33 → 81 not taken.
✓ Branch 34 → 35 taken 292078 times.
✗ Branch 34 → 81 not taken.
✓ Branch 35 → 36 taken 51124 times.
✓ Branch 35 → 37 taken 240954 times.
|
292078 | } else if (terminal->getSymbol()->getType() == SpiceParser::DOT) { |
| 1358 |
1/2✓ Branch 36 → 37 taken 51124 times.
✗ Branch 36 → 81 not taken.
|
51124 | fqFunctionName << MEMBER_ACCESS_TOKEN; |
| 1359 | } | ||
| 1360 | } | ||
| 1361 |
1/2✓ Branch 47 → 48 taken 113030 times.
✗ Branch 47 → 82 not taken.
|
113030 | fctCallNode->fqFunctionName = fqFunctionName.str(); |
| 1362 | |||
| 1363 | // Visit children | ||
| 1364 |
3/4✓ Branch 50 → 51 taken 113030 times.
✗ Branch 50 → 90 not taken.
✓ Branch 51 → 52 taken 7447 times.
✓ Branch 51 → 57 taken 105583 times.
|
113030 | if (ctx->typeLst()) { |
| 1365 | 7447 | fctCallNode->hasTemplateTypes = true; | |
| 1366 |
3/6✓ Branch 52 → 53 taken 7447 times.
✗ Branch 52 → 85 not taken.
✓ Branch 53 → 54 taken 7447 times.
✗ Branch 53 → 85 not taken.
✓ Branch 54 → 55 taken 7447 times.
✗ Branch 54 → 83 not taken.
|
7447 | fctCallNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1367 | } | ||
| 1368 |
3/4✓ Branch 57 → 58 taken 113030 times.
✗ Branch 57 → 90 not taken.
✓ Branch 58 → 59 taken 83066 times.
✓ Branch 58 → 64 taken 29964 times.
|
113030 | if (ctx->argLst()) { |
| 1369 | 83066 | fctCallNode->hasArgs = true; | |
| 1370 |
3/6✓ Branch 59 → 60 taken 83066 times.
✗ Branch 59 → 88 not taken.
✓ Branch 60 → 61 taken 83066 times.
✗ Branch 60 → 88 not taken.
✓ Branch 61 → 62 taken 83066 times.
✗ Branch 61 → 86 not taken.
|
83066 | fctCallNode->argLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1371 | } | ||
| 1372 | |||
| 1373 |
1/2✓ Branch 70 → 71 taken 113030 times.
✗ Branch 70 → 89 not taken.
|
226060 | return concludeNode(fctCallNode); |
| 1374 | 113030 | } | |
| 1375 | |||
| 1376 | 256 | std::any ASTBuilder::visitArrayInitialization(SpiceParser::ArrayInitializationContext *ctx) { | |
| 1377 | 256 | const auto arrayInitializationNode = createNode<ArrayInitializationNode>(ctx); | |
| 1378 | |||
| 1379 | // Visit children | ||
| 1380 |
2/2✓ Branch 4 → 5 taken 254 times.
✓ Branch 4 → 10 taken 2 times.
|
256 | if (ctx->argLst()) |
| 1381 |
3/6✓ Branch 5 → 6 taken 254 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 254 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 254 times.
✗ Branch 7 → 20 not taken.
|
254 | arrayInitializationNode->itemLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1382 | |||
| 1383 |
1/2✓ Branch 16 → 17 taken 256 times.
✗ Branch 16 → 23 not taken.
|
512 | return concludeNode(arrayInitializationNode); |
| 1384 | } | ||
| 1385 | |||
| 1386 | 2157 | std::any ASTBuilder::visitStructInstantiation(SpiceParser::StructInstantiationContext *ctx) { | |
| 1387 |
1/2✓ Branch 2 → 3 taken 2157 times.
✗ Branch 2 → 85 not taken.
|
2157 | const auto structInstantiationNode = createNode<StructInstantiationNode>(ctx); |
| 1388 | |||
| 1389 | // Enrich | ||
| 1390 |
1/2✓ Branch 3 → 4 taken 2157 times.
✗ Branch 3 → 85 not taken.
|
2157 | std::stringstream fqStructName; |
| 1391 |
2/2✓ Branch 39 → 6 taken 8667 times.
✓ Branch 39 → 40 taken 2157 times.
|
12981 | for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1392 |
1/2✓ Branch 8 → 9 taken 8667 times.
✗ Branch 8 → 10 not taken.
|
8667 | const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree); |
| 1393 |
2/2✓ Branch 11 → 12 taken 2134 times.
✓ Branch 11 → 13 taken 6533 times.
|
8667 | if (!terminal) |
| 1394 | 2134 | continue; | |
| 1395 | |||
| 1396 |
4/6✓ Branch 13 → 14 taken 6533 times.
✗ Branch 13 → 74 not taken.
✓ Branch 14 → 15 taken 6533 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 10 times.
✓ Branch 15 → 22 taken 6523 times.
|
6533 | if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) { |
| 1397 |
1/2✓ Branch 16 → 17 taken 10 times.
✗ Branch 16 → 70 not taken.
|
10 | const std::string fragment = terminal->toString(); |
| 1398 |
1/2✓ Branch 17 → 18 taken 10 times.
✗ Branch 17 → 68 not taken.
|
10 | structInstantiationNode->structNameFragments.push_back(fragment); |
| 1399 |
2/4✓ Branch 18 → 19 taken 10 times.
✗ Branch 18 → 68 not taken.
✓ Branch 19 → 20 taken 10 times.
✗ Branch 19 → 68 not taken.
|
10 | fqStructName << fragment << SCOPE_ACCESS_TOKEN; |
| 1400 |
4/6✓ Branch 22 → 23 taken 6523 times.
✗ Branch 22 → 74 not taken.
✓ Branch 23 → 24 taken 6523 times.
✗ Branch 23 → 74 not taken.
✓ Branch 24 → 25 taken 2157 times.
✓ Branch 24 → 30 taken 4366 times.
|
6533 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1401 |
1/2✓ Branch 25 → 26 taken 2157 times.
✗ Branch 25 → 73 not taken.
|
2157 | const std::string fragment = terminal->toString(); |
| 1402 |
1/2✓ Branch 26 → 27 taken 2157 times.
✗ Branch 26 → 71 not taken.
|
2157 | structInstantiationNode->structNameFragments.push_back(fragment); |
| 1403 |
1/2✓ Branch 27 → 28 taken 2157 times.
✗ Branch 27 → 71 not taken.
|
2157 | fqStructName << fragment; |
| 1404 | 2157 | } | |
| 1405 | } | ||
| 1406 |
1/2✓ Branch 40 → 41 taken 2157 times.
✗ Branch 40 → 75 not taken.
|
2157 | structInstantiationNode->fqStructName = fqStructName.str(); |
| 1407 | |||
| 1408 | // Visit children | ||
| 1409 |
3/4✓ Branch 43 → 44 taken 2157 times.
✗ Branch 43 → 83 not taken.
✓ Branch 44 → 45 taken 21 times.
✓ Branch 44 → 50 taken 2136 times.
|
2157 | if (ctx->typeLst()) { |
| 1410 | 21 | structInstantiationNode->hasTemplateTypes = true; | |
| 1411 |
3/6✓ Branch 45 → 46 taken 21 times.
✗ Branch 45 → 78 not taken.
✓ Branch 46 → 47 taken 21 times.
✗ Branch 46 → 78 not taken.
✓ Branch 47 → 48 taken 21 times.
✗ Branch 47 → 76 not taken.
|
21 | structInstantiationNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1412 | } | ||
| 1413 |
3/4✓ Branch 50 → 51 taken 2157 times.
✗ Branch 50 → 83 not taken.
✓ Branch 51 → 52 taken 2113 times.
✓ Branch 51 → 57 taken 44 times.
|
2157 | if (ctx->argLst()) |
| 1414 |
3/6✓ Branch 52 → 53 taken 2113 times.
✗ Branch 52 → 81 not taken.
✓ Branch 53 → 54 taken 2113 times.
✗ Branch 53 → 81 not taken.
✓ Branch 54 → 55 taken 2113 times.
✗ Branch 54 → 79 not taken.
|
2113 | structInstantiationNode->fieldLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1415 | |||
| 1416 |
1/2✓ Branch 63 → 64 taken 2157 times.
✗ Branch 63 → 82 not taken.
|
4314 | return concludeNode(structInstantiationNode); |
| 1417 | 2157 | } | |
| 1418 | |||
| 1419 | 112 | std::any ASTBuilder::visitLambdaFunc(SpiceParser::LambdaFuncContext *ctx) { | |
| 1420 | 112 | const auto lambdaFuncNode = createNode<LambdaFuncNode>(ctx); | |
| 1421 | |||
| 1422 | // Visit children | ||
| 1423 |
3/6✓ Branch 3 → 4 taken 112 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 112 times.
✗ Branch 4 → 37 not taken.
✓ Branch 5 → 6 taken 112 times.
✗ Branch 5 → 35 not taken.
|
112 | lambdaFuncNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1424 |
2/2✓ Branch 8 → 9 taken 101 times.
✓ Branch 8 → 14 taken 11 times.
|
112 | if (ctx->paramLst()) { |
| 1425 | 101 | lambdaFuncNode->hasParams = true; | |
| 1426 |
3/6✓ Branch 9 → 10 taken 101 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 101 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 101 times.
✗ Branch 11 → 38 not taken.
|
101 | lambdaFuncNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 1427 | } | ||
| 1428 |
1/2✗ Branch 15 → 16 not taken.
✓ Branch 15 → 21 taken 112 times.
|
112 | if (ctx->lambdaAttr()) |
| 1429 | ✗ | lambdaFuncNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr())); | |
| 1430 |
4/8✓ Branch 21 → 22 taken 112 times.
✗ Branch 21 → 46 not taken.
✓ Branch 22 → 23 taken 112 times.
✗ Branch 22 → 46 not taken.
✓ Branch 23 → 24 taken 112 times.
✗ Branch 23 → 44 not taken.
✓ Branch 25 → 26 taken 112 times.
✗ Branch 25 → 47 not taken.
|
112 | lambdaFuncNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 1431 | |||
| 1432 |
1/2✓ Branch 31 → 32 taken 112 times.
✗ Branch 31 → 47 not taken.
|
224 | return concludeNode(lambdaFuncNode); |
| 1433 | } | ||
| 1434 | |||
| 1435 | 94 | std::any ASTBuilder::visitLambdaProc(SpiceParser::LambdaProcContext *ctx) { | |
| 1436 | 94 | const auto lambdaProcNode = createNode<LambdaProcNode>(ctx); | |
| 1437 | |||
| 1438 | // Visit children | ||
| 1439 |
2/2✓ Branch 4 → 5 taken 46 times.
✓ Branch 4 → 10 taken 48 times.
|
94 | if (ctx->paramLst()) { |
| 1440 | 46 | lambdaProcNode->hasParams = true; | |
| 1441 |
3/6✓ Branch 5 → 6 taken 46 times.
✗ Branch 5 → 33 not taken.
✓ Branch 6 → 7 taken 46 times.
✗ Branch 6 → 33 not taken.
✓ Branch 7 → 8 taken 46 times.
✗ Branch 7 → 31 not taken.
|
46 | lambdaProcNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 1442 | } | ||
| 1443 |
2/2✓ Branch 11 → 12 taken 36 times.
✓ Branch 11 → 17 taken 58 times.
|
94 | if (ctx->lambdaAttr()) |
| 1444 |
3/6✓ Branch 12 → 13 taken 36 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 36 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 36 times.
✗ Branch 14 → 34 not taken.
|
36 | lambdaProcNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr())); |
| 1445 |
4/8✓ Branch 17 → 18 taken 94 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 94 times.
✗ Branch 18 → 39 not taken.
✓ Branch 19 → 20 taken 94 times.
✗ Branch 19 → 37 not taken.
✓ Branch 21 → 22 taken 94 times.
✗ Branch 21 → 40 not taken.
|
94 | lambdaProcNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 1446 | |||
| 1447 |
1/2✓ Branch 27 → 28 taken 94 times.
✗ Branch 27 → 40 not taken.
|
188 | return concludeNode(lambdaProcNode); |
| 1448 | } | ||
| 1449 | |||
| 1450 | 2 | std::any ASTBuilder::visitLambdaExpr(SpiceParser::LambdaExprContext *ctx) { | |
| 1451 | 2 | const auto lambdaExprNode = createNode<LambdaExprNode>(ctx); | |
| 1452 | |||
| 1453 | // Visit children | ||
| 1454 |
1/2✓ Branch 4 → 5 taken 2 times.
✗ Branch 4 → 10 not taken.
|
2 | if (ctx->paramLst()) { |
| 1455 | 2 | lambdaExprNode->hasParams = true; | |
| 1456 |
3/6✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 26 not taken.
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 26 not taken.
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 24 not taken.
|
2 | lambdaExprNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 1457 | } | ||
| 1458 |
4/8✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 29 not taken.
✓ Branch 11 → 12 taken 2 times.
✗ Branch 11 → 29 not taken.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 27 not taken.
✓ Branch 14 → 15 taken 2 times.
✗ Branch 14 → 30 not taken.
|
2 | lambdaExprNode->lambdaExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1459 | |||
| 1460 |
1/2✓ Branch 20 → 21 taken 2 times.
✗ Branch 20 → 30 not taken.
|
4 | return concludeNode(lambdaExprNode); |
| 1461 | } | ||
| 1462 | |||
| 1463 | 274240 | std::any ASTBuilder::visitDataType(SpiceParser::DataTypeContext *ctx) { | |
| 1464 | 274240 | const auto dataTypeNode = createNode<DataTypeNode>(ctx); | |
| 1465 | |||
| 1466 | // Visit children | ||
| 1467 |
2/2✓ Branch 4 → 5 taken 107574 times.
✓ Branch 4 → 10 taken 166666 times.
|
274240 | if (ctx->qualifierLst()) |
| 1468 |
4/6✓ Branch 5 → 6 taken 107574 times.
✗ Branch 5 → 73 not taken.
✓ Branch 6 → 7 taken 107572 times.
✓ Branch 6 → 73 taken 2 times.
✓ Branch 7 → 8 taken 107572 times.
✗ Branch 7 → 71 not taken.
|
107574 | dataTypeNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 1469 |
3/6✓ Branch 10 → 11 taken 274238 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 274238 times.
✗ Branch 11 → 76 not taken.
✓ Branch 12 → 13 taken 274238 times.
✗ Branch 12 → 74 not taken.
|
274238 | dataTypeNode->baseDataType = std::any_cast<BaseDataTypeNode *>(visit(ctx->baseDataType())); |
| 1470 | |||
| 1471 | // Enrich | ||
| 1472 |
2/2✓ Branch 60 → 15 taken 457168 times.
✓ Branch 60 → 61 taken 274238 times.
|
731406 | for (size_t i = 0; i < ctx->children.size(); i++) { |
| 1473 | 457168 | antlr4::tree::ParseTree *subTree = ctx->children.at(i); | |
| 1474 |
1/2✓ Branch 16 → 17 taken 457168 times.
✗ Branch 16 → 18 not taken.
|
457168 | auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1475 |
2/2✓ Branch 19 → 20 taken 381810 times.
✓ Branch 19 → 21 taken 75358 times.
|
457168 | if (!terminal) |
| 1476 | 381810 | continue; | |
| 1477 | |||
| 1478 |
2/2✓ Branch 23 → 24 taken 42657 times.
✓ Branch 23 → 26 taken 32701 times.
|
75358 | if (terminal->getSymbol()->getType() == SpiceParser::MUL) { |
| 1479 |
1/2✓ Branch 24 → 25 taken 42657 times.
✗ Branch 24 → 77 not taken.
|
42657 | dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_PTR, false, 0); |
| 1480 |
2/2✓ Branch 28 → 29 taken 31712 times.
✓ Branch 28 → 31 taken 989 times.
|
32701 | } else if (terminal->getSymbol()->getType() == SpiceParser::BITWISE_AND) { |
| 1481 |
1/2✓ Branch 29 → 30 taken 31712 times.
✗ Branch 29 → 80 not taken.
|
31712 | dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_REF, false, 0); |
| 1482 |
1/2✓ Branch 33 → 34 taken 989 times.
✗ Branch 33 → 58 not taken.
|
989 | } else if (terminal->getSymbol()->getType() == SpiceParser::LBRACKET) { |
| 1483 | 989 | i++; // Consume LBRACKET | |
| 1484 |
1/2✓ Branch 34 → 35 taken 989 times.
✗ Branch 34 → 92 not taken.
|
989 | subTree = ctx->children.at(i); |
| 1485 |
1/2✓ Branch 35 → 36 taken 989 times.
✗ Branch 35 → 37 not taken.
|
989 | terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1486 | 989 | bool hasSize = false; | |
| 1487 | 989 | unsigned int hardCodedSize = 0; | |
| 1488 | 989 | std::string sizeVarName; | |
| 1489 |
4/6✓ Branch 39 → 40 taken 989 times.
✗ Branch 39 → 90 not taken.
✓ Branch 40 → 41 taken 989 times.
✗ Branch 40 → 90 not taken.
✓ Branch 41 → 42 taken 256 times.
✓ Branch 41 → 46 taken 733 times.
|
989 | if (terminal->getSymbol()->getType() == SpiceParser::INT_LIT) { |
| 1490 | 256 | hasSize = true; | |
| 1491 |
2/4✓ Branch 42 → 43 taken 256 times.
✗ Branch 42 → 85 not taken.
✓ Branch 43 → 44 taken 256 times.
✗ Branch 43 → 83 not taken.
|
256 | hardCodedSize = std::stoi(terminal->getText()); |
| 1492 | 256 | i++; // Consume INT_LIT | |
| 1493 |
4/6✓ Branch 46 → 47 taken 733 times.
✗ Branch 46 → 90 not taken.
✓ Branch 47 → 48 taken 733 times.
✗ Branch 47 → 90 not taken.
✓ Branch 48 → 49 taken 575 times.
✓ Branch 48 → 53 taken 158 times.
|
733 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1494 | 575 | hasSize = true; | |
| 1495 |
1/2✓ Branch 49 → 50 taken 575 times.
✗ Branch 49 → 86 not taken.
|
575 | sizeVarName = getIdentifier(terminal, true); |
| 1496 | 575 | i++; // Consume TYPE_IDENTIFIER | |
| 1497 | } | ||
| 1498 |
1/2✓ Branch 54 → 55 taken 989 times.
✗ Branch 54 → 87 not taken.
|
989 | dataTypeNode->tmQueue.push({DataTypeNode::TypeModifierType::TYPE_ARRAY, hasSize, hardCodedSize, sizeVarName}); |
| 1499 | 989 | } | |
| 1500 | } | ||
| 1501 | |||
| 1502 |
1/2✓ Branch 67 → 68 taken 274238 times.
✗ Branch 67 → 93 not taken.
|
548476 | return concludeNode(dataTypeNode); |
| 1503 |
1/2✓ Branch 53 → 54 taken 989 times.
✗ Branch 53 → 89 not taken.
|
989 | } |
| 1504 | |||
| 1505 | 274238 | std::any ASTBuilder::visitBaseDataType(SpiceParser::BaseDataTypeContext *ctx) { | |
| 1506 | 274238 | const auto baseDataTypeNode = createNode<BaseDataTypeNode>(ctx); | |
| 1507 | |||
| 1508 | // Enrich | ||
| 1509 |
2/2✓ Branch 4 → 5 taken 2899 times.
✓ Branch 4 → 6 taken 271339 times.
|
274238 | if (ctx->TYPE_DOUBLE()) { |
| 1510 | 2899 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DOUBLE; | |
| 1511 |
2/2✓ Branch 7 → 8 taken 23959 times.
✓ Branch 7 → 9 taken 247380 times.
|
271339 | } else if (ctx->TYPE_INT()) { |
| 1512 | 23959 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_INT; | |
| 1513 |
2/2✓ Branch 10 → 11 taken 4233 times.
✓ Branch 10 → 12 taken 243147 times.
|
247380 | } else if (ctx->TYPE_SHORT()) { |
| 1514 | 4233 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_SHORT; | |
| 1515 |
2/2✓ Branch 13 → 14 taken 46141 times.
✓ Branch 13 → 15 taken 197006 times.
|
243147 | } else if (ctx->TYPE_LONG()) { |
| 1516 | 46141 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_LONG; | |
| 1517 |
2/2✓ Branch 16 → 17 taken 17449 times.
✓ Branch 16 → 18 taken 179557 times.
|
197006 | } else if (ctx->TYPE_BYTE()) { |
| 1518 | 17449 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BYTE; | |
| 1519 |
2/2✓ Branch 19 → 20 taken 28975 times.
✓ Branch 19 → 21 taken 150582 times.
|
179557 | } else if (ctx->TYPE_CHAR()) { |
| 1520 | 28975 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CHAR; | |
| 1521 |
2/2✓ Branch 22 → 23 taken 24797 times.
✓ Branch 22 → 24 taken 125785 times.
|
150582 | } else if (ctx->TYPE_STRING()) { |
| 1522 | 24797 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_STRING; | |
| 1523 |
2/2✓ Branch 25 → 26 taken 19037 times.
✓ Branch 25 → 27 taken 106748 times.
|
125785 | } else if (ctx->TYPE_BOOL()) { |
| 1524 | 19037 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BOOL; | |
| 1525 |
2/2✓ Branch 28 → 29 taken 2295 times.
✓ Branch 28 → 30 taken 104453 times.
|
106748 | } else if (ctx->TYPE_DYN()) { |
| 1526 | 2295 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DYN; | |
| 1527 |
2/2✓ Branch 31 → 32 taken 103441 times.
✓ Branch 31 → 37 taken 1012 times.
|
104453 | } else if (ctx->customDataType()) { |
| 1528 | 103441 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CUSTOM; | |
| 1529 |
3/6✓ Branch 32 → 33 taken 103441 times.
✗ Branch 32 → 57 not taken.
✓ Branch 33 → 34 taken 103441 times.
✗ Branch 33 → 57 not taken.
✓ Branch 34 → 35 taken 103441 times.
✗ Branch 34 → 55 not taken.
|
103441 | baseDataTypeNode->customDataType = std::any_cast<CustomDataTypeNode *>(visit(ctx->customDataType())); |
| 1530 |
1/2✓ Branch 38 → 39 taken 1012 times.
✗ Branch 38 → 44 not taken.
|
1012 | } else if (ctx->functionDataType()) { |
| 1531 | 1012 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_FUNCTION; | |
| 1532 |
3/6✓ Branch 39 → 40 taken 1012 times.
✗ Branch 39 → 60 not taken.
✓ Branch 40 → 41 taken 1012 times.
✗ Branch 40 → 60 not taken.
✓ Branch 41 → 42 taken 1012 times.
✗ Branch 41 → 58 not taken.
|
1012 | baseDataTypeNode->functionDataType = std::any_cast<FunctionDataTypeNode *>(visit(ctx->functionDataType())); |
| 1533 | } else { | ||
| 1534 | ✗ | assert_fail("Unknown base data type"); | |
| 1535 | } | ||
| 1536 | |||
| 1537 |
1/2✓ Branch 51 → 52 taken 274238 times.
✗ Branch 51 → 61 not taken.
|
548476 | return concludeNode(baseDataTypeNode); |
| 1538 | } | ||
| 1539 | |||
| 1540 | 103441 | std::any ASTBuilder::visitCustomDataType(SpiceParser::CustomDataTypeContext *ctx) { | |
| 1541 |
1/2✓ Branch 2 → 3 taken 103441 times.
✗ Branch 2 → 75 not taken.
|
103441 | const auto customDataTypeNode = createNode<CustomDataTypeNode>(ctx); |
| 1542 | |||
| 1543 | // Enrich | ||
| 1544 |
1/2✓ Branch 3 → 4 taken 103441 times.
✗ Branch 3 → 75 not taken.
|
103441 | std::stringstream fqTypeName; |
| 1545 |
2/2✓ Branch 39 → 6 taken 150718 times.
✓ Branch 39 → 40 taken 103441 times.
|
357600 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1546 |
1/2✓ Branch 8 → 9 taken 150718 times.
✗ Branch 8 → 10 not taken.
|
150718 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1547 |
2/2✓ Branch 11 → 12 taken 15651 times.
✓ Branch 11 → 13 taken 135067 times.
|
150718 | if (!terminal) |
| 1548 | 15651 | continue; | |
| 1549 | |||
| 1550 |
4/6✓ Branch 13 → 14 taken 135067 times.
✗ Branch 13 → 67 not taken.
✓ Branch 14 → 15 taken 135067 times.
✗ Branch 14 → 67 not taken.
✓ Branch 15 → 16 taken 162 times.
✓ Branch 15 → 22 taken 134905 times.
|
135067 | if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) { |
| 1551 |
1/2✓ Branch 16 → 17 taken 162 times.
✗ Branch 16 → 63 not taken.
|
162 | const std::string fragment = terminal->toString(); |
| 1552 |
1/2✓ Branch 17 → 18 taken 162 times.
✗ Branch 17 → 61 not taken.
|
162 | customDataTypeNode->typeNameFragments.push_back(fragment); |
| 1553 |
2/4✓ Branch 18 → 19 taken 162 times.
✗ Branch 18 → 61 not taken.
✓ Branch 19 → 20 taken 162 times.
✗ Branch 19 → 61 not taken.
|
162 | fqTypeName << fragment << SCOPE_ACCESS_TOKEN; |
| 1554 |
4/6✓ Branch 22 → 23 taken 134905 times.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 134905 times.
✗ Branch 23 → 67 not taken.
✓ Branch 24 → 25 taken 103441 times.
✓ Branch 24 → 30 taken 31464 times.
|
135067 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1555 |
1/2✓ Branch 25 → 26 taken 103441 times.
✗ Branch 25 → 66 not taken.
|
103441 | const std::string fragment = terminal->toString(); |
| 1556 |
1/2✓ Branch 26 → 27 taken 103441 times.
✗ Branch 26 → 64 not taken.
|
103441 | customDataTypeNode->typeNameFragments.push_back(fragment); |
| 1557 |
1/2✓ Branch 27 → 28 taken 103441 times.
✗ Branch 27 → 64 not taken.
|
103441 | fqTypeName << fragment; |
| 1558 | 103441 | } | |
| 1559 | } | ||
| 1560 |
1/2✓ Branch 40 → 41 taken 103441 times.
✗ Branch 40 → 68 not taken.
|
103441 | customDataTypeNode->fqTypeName = fqTypeName.str(); |
| 1561 | |||
| 1562 | // Visit children | ||
| 1563 |
3/4✓ Branch 43 → 44 taken 103441 times.
✗ Branch 43 → 73 not taken.
✓ Branch 44 → 45 taken 15651 times.
✓ Branch 44 → 50 taken 87790 times.
|
103441 | if (ctx->typeLst()) |
| 1564 |
3/6✓ Branch 45 → 46 taken 15651 times.
✗ Branch 45 → 71 not taken.
✓ Branch 46 → 47 taken 15651 times.
✗ Branch 46 → 71 not taken.
✓ Branch 47 → 48 taken 15651 times.
✗ Branch 47 → 69 not taken.
|
15651 | customDataTypeNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1565 | |||
| 1566 |
1/2✓ Branch 56 → 57 taken 103441 times.
✗ Branch 56 → 72 not taken.
|
206882 | return concludeNode(customDataTypeNode); |
| 1567 | 103441 | } | |
| 1568 | |||
| 1569 | 1012 | std::any ASTBuilder::visitFunctionDataType(SpiceParser::FunctionDataTypeContext *ctx) { | |
| 1570 | 1012 | const auto functionDataTypeNode = createNode<FunctionDataTypeNode>(ctx); | |
| 1571 | |||
| 1572 | // Enrich | ||
| 1573 |
2/2✓ Branch 4 → 5 taken 576 times.
✓ Branch 4 → 11 taken 436 times.
|
1012 | if (ctx->dataType()) { |
| 1574 | 576 | functionDataTypeNode->isFunction = ctx->dataType(); | |
| 1575 |
3/6✓ Branch 6 → 7 taken 576 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 576 times.
✗ Branch 7 → 30 not taken.
✓ Branch 8 → 9 taken 576 times.
✗ Branch 8 → 28 not taken.
|
576 | functionDataTypeNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1576 | } | ||
| 1577 |
2/2✓ Branch 12 → 13 taken 771 times.
✓ Branch 12 → 18 taken 241 times.
|
1012 | if (ctx->typeLst()) |
| 1578 |
3/6✓ Branch 13 → 14 taken 771 times.
✗ Branch 13 → 33 not taken.
✓ Branch 14 → 15 taken 771 times.
✗ Branch 14 → 33 not taken.
✓ Branch 15 → 16 taken 771 times.
✗ Branch 15 → 31 not taken.
|
771 | functionDataTypeNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1579 | |||
| 1580 |
1/2✓ Branch 24 → 25 taken 1012 times.
✗ Branch 24 → 34 not taken.
|
2024 | return concludeNode(functionDataTypeNode); |
| 1581 | } | ||
| 1582 | |||
| 1583 | 41597 | std::any ASTBuilder::visitAssignOp(SpiceParser::AssignOpContext *ctx) { | |
| 1584 | 41597 | const auto assignExprNode = resumeForExpansion<AssignExprNode>(); | |
| 1585 | |||
| 1586 | // Extract assign operator | ||
| 1587 |
2/2✓ Branch 15 → 16 taken 36128 times.
✓ Branch 15 → 17 taken 5469 times.
|
41597 | if (ctx->ASSIGN()) |
| 1588 | 36128 | assignExprNode->op = AssignExprNode::AssignOp::OP_ASSIGN; | |
| 1589 |
2/2✓ Branch 18 → 19 taken 4173 times.
✓ Branch 18 → 20 taken 1296 times.
|
5469 | else if (ctx->PLUS_EQUAL()) |
| 1590 | 4173 | assignExprNode->op = AssignExprNode::AssignOp::OP_PLUS_EQUAL; | |
| 1591 |
2/2✓ Branch 21 → 22 taken 258 times.
✓ Branch 21 → 23 taken 1038 times.
|
1296 | else if (ctx->MINUS_EQUAL()) |
| 1592 | 258 | assignExprNode->op = AssignExprNode::AssignOp::OP_MINUS_EQUAL; | |
| 1593 |
2/2✓ Branch 24 → 25 taken 317 times.
✓ Branch 24 → 26 taken 721 times.
|
1038 | else if (ctx->MUL_EQUAL()) |
| 1594 | 317 | assignExprNode->op = AssignExprNode::AssignOp::OP_MUL_EQUAL; | |
| 1595 |
2/2✓ Branch 27 → 28 taken 136 times.
✓ Branch 27 → 29 taken 585 times.
|
721 | else if (ctx->DIV_EQUAL()) |
| 1596 | 136 | assignExprNode->op = AssignExprNode::AssignOp::OP_DIV_EQUAL; | |
| 1597 |
2/2✓ Branch 30 → 31 taken 76 times.
✓ Branch 30 → 32 taken 509 times.
|
585 | else if (ctx->REM_EQUAL()) |
| 1598 | 76 | assignExprNode->op = AssignExprNode::AssignOp::OP_REM_EQUAL; | |
| 1599 |
2/2✓ Branch 33 → 34 taken 6 times.
✓ Branch 33 → 35 taken 503 times.
|
509 | else if (ctx->SHL_EQUAL()) |
| 1600 | 6 | assignExprNode->op = AssignExprNode::AssignOp::OP_SHL_EQUAL; | |
| 1601 |
2/2✓ Branch 36 → 37 taken 16 times.
✓ Branch 36 → 38 taken 487 times.
|
503 | else if (ctx->SHR_EQUAL()) |
| 1602 | 16 | assignExprNode->op = AssignExprNode::AssignOp::OP_SHR_EQUAL; | |
| 1603 |
2/2✓ Branch 39 → 40 taken 38 times.
✓ Branch 39 → 41 taken 449 times.
|
487 | else if (ctx->AND_EQUAL()) |
| 1604 | 38 | assignExprNode->op = AssignExprNode::AssignOp::OP_AND_EQUAL; | |
| 1605 |
2/2✓ Branch 42 → 43 taken 44 times.
✓ Branch 42 → 44 taken 405 times.
|
449 | else if (ctx->OR_EQUAL()) |
| 1606 | 44 | assignExprNode->op = AssignExprNode::AssignOp::OP_OR_EQUAL; | |
| 1607 |
1/2✓ Branch 45 → 46 taken 405 times.
✗ Branch 45 → 47 not taken.
|
405 | else if (ctx->XOR_EQUAL()) |
| 1608 | 405 | assignExprNode->op = AssignExprNode::AssignOp::OP_XOR_EQUAL; | |
| 1609 | else | ||
| 1610 | ✗ | assert_fail("Unknown assign operator"); | |
| 1611 | |||
| 1612 |
1/2✓ Branch 48 → 49 taken 41597 times.
✗ Branch 48 → 52 not taken.
|
83194 | return nullptr; |
| 1613 | } | ||
| 1614 | |||
| 1615 | 7484 | std::any ASTBuilder::visitOverloadableOp(SpiceParser::OverloadableOpContext *ctx) { | |
| 1616 | 7484 | const auto fctNameNode = resumeForExpansion<FctNameNode>(); | |
| 1617 | |||
| 1618 | // Enrich | ||
| 1619 |
2/2✓ Branch 15 → 16 taken 354 times.
✓ Branch 15 → 17 taken 7130 times.
|
7484 | if (ctx->PLUS()) |
| 1620 | 354 | fctNameNode->name = OP_FCT_PLUS; | |
| 1621 |
2/2✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 20 taken 7128 times.
|
7130 | else if (ctx->MINUS()) |
| 1622 | 2 | fctNameNode->name = OP_FCT_MINUS; | |
| 1623 |
2/2✓ Branch 21 → 22 taken 702 times.
✓ Branch 21 → 23 taken 6426 times.
|
7128 | else if (ctx->MUL()) |
| 1624 | 702 | fctNameNode->name = OP_FCT_MUL; | |
| 1625 |
2/2✓ Branch 24 → 25 taken 50 times.
✓ Branch 24 → 26 taken 6376 times.
|
6426 | else if (ctx->DIV()) |
| 1626 | 50 | fctNameNode->name = OP_FCT_DIV; | |
| 1627 |
2/2✓ Branch 27 → 28 taken 1681 times.
✓ Branch 27 → 29 taken 4695 times.
|
6376 | else if (ctx->EQUAL()) |
| 1628 | 1681 | fctNameNode->name = OP_FCT_EQUAL; | |
| 1629 |
2/2✓ Branch 30 → 31 taken 1671 times.
✓ Branch 30 → 32 taken 3024 times.
|
4695 | else if (ctx->NOT_EQUAL()) |
| 1630 | 1671 | fctNameNode->name = OP_FCT_NOT_EQUAL; | |
| 1631 |
3/4✓ Branch 32 → 33 taken 3024 times.
✗ Branch 32 → 85 not taken.
✓ Branch 35 → 36 taken 104 times.
✓ Branch 35 → 37 taken 2920 times.
|
3024 | else if (ctx->LESS().size() == 2) |
| 1632 | 104 | fctNameNode->name = OP_FCT_SHL; | |
| 1633 |
3/4✓ Branch 37 → 38 taken 2920 times.
✗ Branch 37 → 86 not taken.
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 42 taken 2918 times.
|
2920 | else if (ctx->GREATER().size() == 2) |
| 1634 | 2 | fctNameNode->name = OP_FCT_SHR; | |
| 1635 |
2/2✓ Branch 43 → 44 taken 8 times.
✓ Branch 43 → 45 taken 2910 times.
|
2918 | else if (ctx->BITWISE_AND()) |
| 1636 | 8 | fctNameNode->name = OP_FCT_BITWISE_AND; | |
| 1637 |
2/2✓ Branch 46 → 47 taken 8 times.
✓ Branch 46 → 48 taken 2902 times.
|
2910 | else if (ctx->BITWISE_OR()) |
| 1638 | 8 | fctNameNode->name = OP_FCT_BITWISE_OR; | |
| 1639 |
2/2✓ Branch 49 → 50 taken 8 times.
✓ Branch 49 → 51 taken 2894 times.
|
2902 | else if (ctx->BITWISE_XOR()) |
| 1640 | 8 | fctNameNode->name = OP_FCT_BITWISE_XOR; | |
| 1641 |
2/2✓ Branch 52 → 53 taken 8 times.
✓ Branch 52 → 54 taken 2886 times.
|
2894 | else if (ctx->BITWISE_NOT()) |
| 1642 | 8 | fctNameNode->name = OP_FCT_BITWISE_NOT; | |
| 1643 |
2/2✓ Branch 55 → 56 taken 510 times.
✓ Branch 55 → 57 taken 2376 times.
|
2886 | else if (ctx->PLUS_EQUAL()) |
| 1644 | 510 | fctNameNode->name = OP_FCT_PLUS_EQUAL; | |
| 1645 |
2/2✓ Branch 58 → 59 taken 160 times.
✓ Branch 58 → 60 taken 2216 times.
|
2376 | else if (ctx->MINUS_EQUAL()) |
| 1646 | 160 | fctNameNode->name = OP_FCT_MINUS_EQUAL; | |
| 1647 |
2/2✓ Branch 61 → 62 taken 352 times.
✓ Branch 61 → 63 taken 1864 times.
|
2216 | else if (ctx->MUL_EQUAL()) |
| 1648 | 352 | fctNameNode->name = OP_FCT_MUL_EQUAL; | |
| 1649 |
2/2✓ Branch 64 → 65 taken 50 times.
✓ Branch 64 → 66 taken 1814 times.
|
1864 | else if (ctx->DIV_EQUAL()) |
| 1650 | 50 | fctNameNode->name = OP_FCT_DIV_EQUAL; | |
| 1651 |
2/2✓ Branch 67 → 68 taken 208 times.
✓ Branch 67 → 69 taken 1606 times.
|
1814 | else if (ctx->PLUS_PLUS()) |
| 1652 | 208 | fctNameNode->name = OP_FCT_POSTFIX_PLUS_PLUS; | |
| 1653 |
2/2✓ Branch 70 → 71 taken 160 times.
✓ Branch 70 → 72 taken 1446 times.
|
1606 | else if (ctx->MINUS_MINUS()) |
| 1654 | 160 | fctNameNode->name = OP_FCT_POSTFIX_MINUS_MINUS; | |
| 1655 |
2/2✓ Branch 73 → 74 taken 850 times.
✓ Branch 73 → 75 taken 596 times.
|
1446 | else if (ctx->LBRACKET()) |
| 1656 | 850 | fctNameNode->name = OP_FCT_SUBSCRIPT; | |
| 1657 |
1/2✓ Branch 76 → 77 taken 596 times.
✗ Branch 76 → 78 not taken.
|
596 | else if (ctx->ASSIGN()) |
| 1658 | 596 | fctNameNode->name = OP_FCT_ASSIGN; | |
| 1659 | else | ||
| 1660 | − | assert_fail("Unsupported overloadable operator"); // GCOV_EXCL_LINE | |
| 1661 | |||
| 1662 | 7484 | fctNameNode->fqName = fctNameNode->name; | |
| 1663 | 7484 | fctNameNode->nameFragments.push_back(fctNameNode->name); | |
| 1664 | |||
| 1665 |
1/2✓ Branch 81 → 82 taken 7484 times.
✗ Branch 81 → 87 not taken.
|
14968 | return nullptr; |
| 1666 | } | ||
| 1667 | |||
| 1668 | 26414 | int32_t ASTBuilder::parseInt(TerminalNode *terminal, bool isNegative) { | |
| 1669 | 79242 | const NumericParserCallback<int32_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int32_t { | |
| 1670 | // Prepare limits | ||
| 1671 |
2/2✓ Branch 2 → 3 taken 25306 times.
✓ Branch 2 → 4 taken 1108 times.
|
26414 | const int64_t upperLimit = isSigned ? INT32_MAX : UINT32_MAX; |
| 1672 |
2/2✓ Branch 5 → 6 taken 25306 times.
✓ Branch 5 → 7 taken 1108 times.
|
26414 | const int64_t lowerLimit = isSigned ? INT32_MIN : 0; |
| 1673 | // Parse number, apply sign and check for limits | ||
| 1674 | 26414 | int64_t number = std::stoll(substr, nullptr, base); | |
| 1675 |
2/2✓ Branch 9 → 10 taken 459 times.
✓ Branch 9 → 11 taken 25953 times.
|
26412 | if (isNegative) |
| 1676 | 459 | number = -number; | |
| 1677 |
2/4✓ Branch 11 → 12 taken 26412 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 26412 times.
|
26412 | if (number < lowerLimit || number > upperLimit) |
| 1678 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1679 | 26412 | return static_cast<int32_t>(number); | |
| 1680 | 26414 | }; | |
| 1681 |
2/2✓ Branch 3 → 4 taken 26412 times.
✓ Branch 3 → 8 taken 2 times.
|
52826 | return parseNumeric(terminal, cb); |
| 1682 | 26414 | } | |
| 1683 | |||
| 1684 | 2850 | int16_t ASTBuilder::parseShort(TerminalNode *terminal, bool isNegative) { | |
| 1685 | 8550 | const NumericParserCallback<int16_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int16_t { | |
| 1686 | // Prepare limits | ||
| 1687 |
2/2✓ Branch 2 → 3 taken 1514 times.
✓ Branch 2 → 4 taken 1336 times.
|
2850 | const int64_t upperLimit = isSigned ? INT16_MAX : UINT16_MAX; |
| 1688 |
2/2✓ Branch 5 → 6 taken 1514 times.
✓ Branch 5 → 7 taken 1336 times.
|
2850 | const int64_t lowerLimit = isSigned ? INT16_MIN : 0; |
| 1689 | // Parse number, apply sign and check for limits | ||
| 1690 | 2850 | int64_t number = std::stoll(substr, nullptr, base); | |
| 1691 |
2/2✓ Branch 9 → 10 taken 174 times.
✓ Branch 9 → 11 taken 2676 times.
|
2850 | if (isNegative) |
| 1692 | 174 | number = -number; | |
| 1693 |
2/4✓ Branch 11 → 12 taken 2850 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 2850 times.
|
2850 | if (number < lowerLimit || number > upperLimit) |
| 1694 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1695 | 2850 | return static_cast<int16_t>(number); | |
| 1696 | 2850 | }; | |
| 1697 |
1/2✓ Branch 3 → 4 taken 2850 times.
✗ Branch 3 → 8 not taken.
|
5700 | return parseNumeric(terminal, cb); |
| 1698 | 2850 | } | |
| 1699 | |||
| 1700 | 39821 | int64_t ASTBuilder::parseLong(TerminalNode *terminal, bool isNegative) { | |
| 1701 | 119463 | const NumericParserCallback<int64_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int64_t { | |
| 1702 | // Parse the magnitude as unsigned so values like 2^63 (the absolute value of INT64_MIN) fit | ||
| 1703 | 39821 | const uint64_t magnitude = std::stoull(substr, nullptr, base); | |
| 1704 |
2/2✓ Branch 3 → 4 taken 5310 times.
✓ Branch 3 → 11 taken 34511 times.
|
39821 | if (isNegative) { |
| 1705 | 5310 | constexpr uint64_t maxNegMagnitude = static_cast<uint64_t>(INT64_MAX) + 1; // 2^63 | |
| 1706 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 5310 times.
|
5310 | if (magnitude > maxNegMagnitude) |
| 1707 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1708 |
2/2✓ Branch 8 → 9 taken 4 times.
✓ Branch 8 → 10 taken 5306 times.
|
5310 | if (magnitude == maxNegMagnitude) |
| 1709 | 4 | return INT64_MIN; | |
| 1710 | 5306 | return -static_cast<int64_t>(magnitude); | |
| 1711 | } | ||
| 1712 |
3/4✓ Branch 11 → 12 taken 31944 times.
✓ Branch 11 → 16 taken 2567 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 31944 times.
|
34511 | if (isSigned && magnitude > static_cast<uint64_t>(INT64_MAX)) |
| 1713 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1714 | 34511 | return static_cast<int64_t>(magnitude); | |
| 1715 | 39821 | }; | |
| 1716 |
1/2✓ Branch 3 → 4 taken 39821 times.
✗ Branch 3 → 8 not taken.
|
79642 | return parseNumeric(terminal, cb); |
| 1717 | 39821 | } | |
| 1718 | |||
| 1719 | 13685 | int8_t ASTBuilder::parseChar(TerminalNode *terminal) const { | |
| 1720 |
1/2✓ Branch 2 → 3 taken 13685 times.
✗ Branch 2 → 59 not taken.
|
13685 | const std::string input = terminal->toString(); |
| 1721 |
2/2✓ Branch 4 → 5 taken 8942 times.
✓ Branch 4 → 7 taken 4743 times.
|
13685 | if (input.length() == 3) // Normal char literals |
| 1722 | 8942 | return input[1]; | |
| 1723 | |||
| 1724 |
3/6✓ Branch 8 → 9 taken 4743 times.
✗ Branch 8 → 12 not taken.
✓ Branch 10 → 11 taken 4743 times.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 4743 times.
✗ Branch 13 → 34 not taken.
|
4743 | if (input.length() == 4 && input[1] == '\\') { // Char literals with escape sequence |
| 1725 |
10/11✓ Branch 15 → 16 taken 54 times.
✗ Branch 15 → 17 not taken.
✓ Branch 15 → 18 taken 78 times.
✓ Branch 15 → 19 taken 616 times.
✓ Branch 15 → 20 taken 498 times.
✓ Branch 15 → 21 taken 452 times.
✓ Branch 15 → 22 taken 18 times.
✓ Branch 15 → 23 taken 36 times.
✓ Branch 15 → 24 taken 22 times.
✓ Branch 15 → 25 taken 2967 times.
✓ Branch 15 → 26 taken 2 times.
|
4743 | switch (input[2]) { |
| 1726 | 54 | case '\'': | |
| 1727 | 54 | return '\''; | |
| 1728 | ✗ | case '"': | |
| 1729 | ✗ | return '\"'; | |
| 1730 | 78 | case '\\': | |
| 1731 | 78 | return '\\'; | |
| 1732 | 616 | case 'n': | |
| 1733 | 616 | return '\n'; | |
| 1734 | 498 | case 'r': | |
| 1735 | 498 | return '\r'; | |
| 1736 | 452 | case 't': | |
| 1737 | 452 | return '\t'; | |
| 1738 | 18 | case 'b': | |
| 1739 | 18 | return '\b'; | |
| 1740 | 36 | case 'f': | |
| 1741 | 36 | return '\f'; | |
| 1742 | 22 | case 'v': | |
| 1743 | 22 | return '\v'; | |
| 1744 | 2967 | case '0': | |
| 1745 | 2967 | return '\0'; | |
| 1746 | 2 | default: | |
| 1747 |
2/4✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 50 not taken.
✓ Branch 27 → 28 taken 2 times.
✗ Branch 27 → 50 not taken.
|
2 | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); |
| 1748 |
2/4✓ Branch 29 → 30 taken 2 times.
✗ Branch 29 → 47 not taken.
✓ Branch 30 → 31 taken 2 times.
✗ Branch 30 → 44 not taken.
|
2 | throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid escape sequence " + input); |
| 1749 | } | ||
| 1750 | } | ||
| 1751 | |||
| 1752 | ✗ | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); | |
| 1753 | ✗ | throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid char literal " + input); | |
| 1754 | 13685 | } | |
| 1755 | |||
| 1756 | 20515 | std::string ASTBuilder::parseString(std::string input) { | |
| 1757 |
1/2✓ Branch 3 → 4 taken 20515 times.
✗ Branch 3 → 9 not taken.
|
20515 | input = input.substr(1, input.size() - 2); |
| 1758 | 20515 | replaceEscapeChars(input); | |
| 1759 | 20515 | return input; | |
| 1760 | } | ||
| 1761 | |||
| 1762 | /** | ||
| 1763 | * Check if the given integer literal is marked unsigned by its suffix ('u', 'us' or 'ul') | ||
| 1764 | * | ||
| 1765 | * @param input Integer literal | ||
| 1766 | * @return Unsigned or not | ||
| 1767 | */ | ||
| 1768 | 135312 | bool ASTBuilder::isUnsignedLiteral(const std::string &input) { | |
| 1769 |
6/6✓ Branch 3 → 4 taken 133096 times.
✓ Branch 3 → 8 taken 2216 times.
✓ Branch 5 → 6 taken 130424 times.
✓ Branch 5 → 8 taken 2672 times.
✓ Branch 7 → 8 taken 5134 times.
✓ Branch 7 → 9 taken 125290 times.
|
135312 | return input.ends_with('u') || input.ends_with("us") || input.ends_with("ul"); |
| 1770 | } | ||
| 1771 | |||
| 1772 | 69085 | template <typename T> T ASTBuilder::parseNumeric(TerminalNode *terminal, const NumericParserCallback<T> &cb) { | |
| 1773 |
3/6int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 26414 times.
✗ Branch 2 → 80 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 39821 times.
✗ Branch 2 → 80 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 2850 times.
✗ Branch 2 → 80 not taken.
|
69085 | const std::string input = terminal->toString(); |
| 1774 | |||
| 1775 | // Set to signed if the input string does not end with 'u' | ||
| 1776 | 69085 | const bool isUnsigned = isUnsignedLiteral(input); | |
| 1777 | |||
| 1778 | try { | ||
| 1779 |
6/6int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 5 → 6 taken 3426 times.
✓ Branch 5 → 23 taken 22988 times.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 5 → 6 taken 4264 times.
✓ Branch 5 → 23 taken 35557 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 5 → 6 taken 2342 times.
✓ Branch 5 → 23 taken 508 times.
|
69085 | if (input.length() >= 3) { |
| 1780 |
6/6int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 7 → 8 taken 1146 times.
✓ Branch 7 → 23 taken 2280 times.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 7 → 8 taken 1656 times.
✓ Branch 7 → 23 taken 2608 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 7 → 8 taken 364 times.
✓ Branch 7 → 23 taken 1978 times.
|
10032 | if (input[0] == '0') { |
| 1781 |
3/6int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 8 → 9 taken 1146 times.
✗ Branch 8 → 30 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 8 → 9 taken 1656 times.
✗ Branch 8 → 30 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 8 → 9 taken 364 times.
✗ Branch 8 → 30 not taken.
|
3166 | const std::string subStr = input.substr(2); |
| 1782 |
6/15int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 13 not taken.
✓ Branch 10 → 15 taken 482 times.
✓ Branch 10 → 17 taken 664 times.
✗ Branch 10 → 19 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 13 not taken.
✓ Branch 10 → 15 taken 608 times.
✗ Branch 10 → 17 not taken.
✓ Branch 10 → 19 taken 1048 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 13 not taken.
✗ Branch 10 → 15 not taken.
✓ Branch 10 → 17 taken 360 times.
✓ Branch 10 → 19 taken 4 times.
|
3166 | switch (input[1]) { |
| 1783 | ✗ | case 'd': // fall-through | |
| 1784 | case 'D': | ||
| 1785 | ✗ | return cb(subStr, 10, !isUnsigned); | |
| 1786 | ✗ | case 'b': // fall-through | |
| 1787 | case 'B': | ||
| 1788 | ✗ | return cb(subStr, 2, !isUnsigned); | |
| 1789 | 1090 | case 'h': // fall-through | |
| 1790 | case 'H': // fall-through | ||
| 1791 | case 'x': // fall-through | ||
| 1792 | case 'X': | ||
| 1793 |
2/6int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 15 → 16 taken 482 times.
✗ Branch 15 → 28 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 15 → 16 taken 608 times.
✗ Branch 15 → 28 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 28 not taken.
|
1090 | return cb(subStr, 16, !isUnsigned); |
| 1794 | 1024 | case 'o': // fall-through | |
| 1795 | case 'O': | ||
| 1796 |
2/6int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 17 → 18 taken 664 times.
✗ Branch 17 → 28 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 28 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 17 → 18 taken 360 times.
✗ Branch 17 → 28 not taken.
|
1024 | return cb(subStr, 8, !isUnsigned); |
| 1797 | 1052 | default: // default is decimal | |
| 1798 |
2/6int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 28 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 19 → 20 taken 1048 times.
✗ Branch 19 → 28 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 19 → 20 taken 4 times.
✗ Branch 19 → 28 not taken.
|
1052 | return cb(input, 10, !isUnsigned); |
| 1799 | } | ||
| 1800 | 3166 | } | |
| 1801 | } | ||
| 1802 |
4/6int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 23 → 24 taken 25266 times.
✓ Branch 23 → 31 taken 2 times.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 23 → 24 taken 38165 times.
✗ Branch 23 → 31 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 23 → 24 taken 2486 times.
✗ Branch 23 → 31 not taken.
|
65919 | return cb(input, 10, !isUnsigned); |
| 1803 |
1/9int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 2 times.
✗ Branch 31 → 44 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
✗ Branch 31 → 44 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
✗ Branch 31 → 44 not taken.
|
4 | } catch (std::out_of_range &) { |
| 1804 |
2/12int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 34 → 35 taken 2 times.
✗ Branch 34 → 63 not taken.
✓ Branch 35 → 36 taken 2 times.
✗ Branch 35 → 63 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 63 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 63 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 63 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 63 not taken.
|
2 | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); |
| 1805 |
2/12int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 39 → 40 taken 2 times.
✗ Branch 39 → 57 not taken.
✓ Branch 40 → 41 taken 2 times.
✗ Branch 40 → 54 not taken.
long spice::compiler::ASTBuilder::parseNumeric<long>(antlr4::tree::TerminalNode*, std::function<long (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 57 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 54 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 57 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 54 not taken.
|
6 | throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "The provided number is out of range"); |
| 1806 | ✗ | } catch (std::invalid_argument &) { | |
| 1807 | ✗ | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); | |
| 1808 | ✗ | throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "You tried to parse '" + input + "' as an integer, but it was no integer"); | |
| 1809 | } | ||
| 1810 | 69085 | } | |
| 1811 | |||
| 1812 | 20515 | void ASTBuilder::replaceEscapeChars(std::string &input) { | |
| 1813 | 20515 | const std::unordered_map<char, char> escapeMap = { | |
| 1814 | {'a', '\a'}, {'b', '\b'}, {'f', '\f'}, {'n', '\n'}, {'r', '\r'}, {'t', '\t'}, | ||
| 1815 | {'v', '\v'}, {'\\', '\\'}, {'?', '\?'}, {'\'', '\''}, {'"', '\"'}, | ||
| 1816 |
1/2✓ Branch 4 → 5 taken 20515 times.
✗ Branch 4 → 40 not taken.
|
41030 | }; |
| 1817 | |||
| 1818 | 20515 | size_t writeIndex = 0; | |
| 1819 | 20515 | size_t readIndex = 0; | |
| 1820 | 20515 | const size_t len = input.length(); | |
| 1821 | |||
| 1822 |
2/2✓ Branch 36 → 8 taken 316971 times.
✓ Branch 36 → 37 taken 20515 times.
|
337486 | while (readIndex < len) { |
| 1823 | 316971 | const char c = input[readIndex]; | |
| 1824 |
3/4✓ Branch 9 → 10 taken 5987 times.
✓ Branch 9 → 33 taken 310984 times.
✓ Branch 10 → 11 taken 5987 times.
✗ Branch 10 → 33 not taken.
|
316971 | if (c == '\\' && readIndex + 1 < len) { |
| 1825 | 5987 | char next = input[readIndex + 1]; | |
| 1826 |
1/2✓ Branch 12 → 13 taken 5987 times.
✗ Branch 12 → 45 not taken.
|
5987 | auto it = escapeMap.find(next); |
| 1827 |
2/2✓ Branch 15 → 16 taken 5907 times.
✓ Branch 15 → 19 taken 80 times.
|
5987 | if (it != escapeMap.end()) { |
| 1828 | 5907 | input[writeIndex++] = it->second; | |
| 1829 | 5907 | readIndex += 2; | |
| 1830 | 5981 | continue; | |
| 1831 | } | ||
| 1832 | |||
| 1833 | // Handle octal escape sequences (up to 3 digits) | ||
| 1834 |
3/4✓ Branch 19 → 20 taken 80 times.
✗ Branch 19 → 31 not taken.
✓ Branch 20 → 21 taken 74 times.
✓ Branch 20 → 31 taken 6 times.
|
80 | if (next >= '0' && next <= '7') { |
| 1835 | 74 | int value = 0; | |
| 1836 | 74 | size_t octalDigits = 0; | |
| 1837 | |||
| 1838 | // Look ahead up to 3 digits | ||
| 1839 |
3/4✓ Branch 26 → 27 taken 222 times.
✓ Branch 26 → 28 taken 74 times.
✓ Branch 27 → 22 taken 222 times.
✗ Branch 27 → 28 not taken.
|
296 | for (size_t i = 1; i <= 3 && readIndex + i < len; ++i) { |
| 1840 | 222 | const char oc = input[readIndex + i]; | |
| 1841 |
2/4✓ Branch 23 → 24 taken 222 times.
✗ Branch 23 → 28 not taken.
✓ Branch 24 → 25 taken 222 times.
✗ Branch 24 → 28 not taken.
|
222 | if (oc >= '0' && oc <= '7') { |
| 1842 | 222 | value = value << 3 | (oc - '0'); // multiply by 8 and add digit | |
| 1843 | 222 | octalDigits++; | |
| 1844 | } else { | ||
| 1845 | break; | ||
| 1846 | } | ||
| 1847 | } | ||
| 1848 | |||
| 1849 |
1/2✓ Branch 28 → 29 taken 74 times.
✗ Branch 28 → 31 not taken.
|
74 | if (octalDigits > 0) { |
| 1850 | 74 | input[writeIndex++] = static_cast<char>(value); | |
| 1851 | 74 | readIndex += 1 + octalDigits; // backslash + octal digits | |
| 1852 | 74 | continue; | |
| 1853 | } | ||
| 1854 | } | ||
| 1855 | } | ||
| 1856 | |||
| 1857 | // Copy current character | ||
| 1858 | 310990 | input[writeIndex++] = c; | |
| 1859 | 310990 | readIndex++; | |
| 1860 | } | ||
| 1861 | |||
| 1862 |
1/2✓ Branch 37 → 38 taken 20515 times.
✗ Branch 37 → 46 not taken.
|
20515 | input.resize(writeIndex); |
| 1863 | 20515 | } | |
| 1864 | |||
| 1865 | 678237 | std::string ASTBuilder::getIdentifier(TerminalNode *terminal, bool isTypeIdentifier) const { | |
| 1866 | 678237 | const std::string identifier = terminal->getText(); | |
| 1867 | |||
| 1868 | // Check if the list of reserved keywords contains the given identifier | ||
| 1869 |
3/4✓ Branch 3 → 4 taken 678237 times.
✗ Branch 3 → 52 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 14 taken 678235 times.
|
678237 | if (std::ranges::find(RESERVED_KEYWORDS, identifier) != std::end(RESERVED_KEYWORDS)) { |
| 1870 |
2/4✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 41 not taken.
✓ Branch 6 → 7 taken 2 times.
✗ Branch 6 → 41 not taken.
|
2 | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); |
| 1871 |
3/6✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 37 not taken.
✓ Branch 9 → 10 taken 2 times.
✗ Branch 9 → 35 not taken.
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 32 not taken.
|
2 | throw ParserError(codeLoc, RESERVED_KEYWORD, "'" + identifier + "' is a reserved keyword. Please use another name instead"); |
| 1872 | } | ||
| 1873 | |||
| 1874 | // Check if the identifier is a type identifier and is reserved | ||
| 1875 |
6/6✓ Branch 14 → 15 taken 53358 times.
✓ Branch 14 → 19 taken 624877 times.
✓ Branch 15 → 16 taken 1479 times.
✓ Branch 15 → 19 taken 51879 times.
✓ Branch 20 → 21 taken 2 times.
✓ Branch 20 → 30 taken 678233 times.
|
679714 | if (isTypeIdentifier && !sourceFile->isStdFile && |
| 1876 |
3/4✓ Branch 16 → 17 taken 1479 times.
✗ Branch 16 → 52 not taken.
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 19 taken 1477 times.
|
1479 | std::ranges::find(RESERVED_TYPE_NAMES, identifier) != std::end(RESERVED_TYPE_NAMES)) { |
| 1877 |
2/4✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 51 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 51 not taken.
|
2 | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); |
| 1878 |
3/6✓ Branch 24 → 25 taken 2 times.
✗ Branch 24 → 47 not taken.
✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 45 not taken.
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 42 not taken.
|
2 | throw ParserError(codeLoc, RESERVED_TYPENAME, "'" + identifier + "' is a reserved type name. Please use another one instead"); |
| 1879 | } | ||
| 1880 | |||
| 1881 | 678233 | return identifier; | |
| 1882 | 4 | } | |
| 1883 | |||
| 1884 | } // namespace spice::compiler | ||
| 1885 |