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 | 7330 | ASTBuilder::ASTBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile, antlr4::ANTLRInputStream *inputStream) | |
| 17 |
1/2✓ Branch 4 → 5 taken 7330 times.
✗ Branch 4 → 6 not taken.
|
7330 | : CompilerPass(resourceManager, sourceFile), inputStream(inputStream) {} |
| 18 | |||
| 19 | 7326 | std::any ASTBuilder::visitEntry(SpiceParser::EntryContext *ctx) { | |
| 20 | 7326 | const auto entryNode = createNode<EntryNode>(ctx); | |
| 21 | |||
| 22 | // Visit children | ||
| 23 |
2/2✓ Branch 144 → 5 taken 163616 times.
✓ Branch 144 → 145 taken 7314 times.
|
178256 | for (ParserRuleContext::ParseTree *child : ctx->children) { |
| 24 |
3/4✓ Branch 7 → 8 taken 163616 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 1319 times.
✓ Branch 10 → 16 taken 162297 times.
|
163616 | if (auto *mainFctDefCtx = dynamic_cast<SpiceParser::MainFunctionDefContext *>(child)) |
| 25 |
4/6✓ Branch 11 → 12 taken 1311 times.
✓ Branch 11 → 157 taken 8 times.
✓ Branch 12 → 13 taken 1311 times.
✗ Branch 12 → 155 not taken.
✓ Branch 13 → 14 taken 1311 times.
✗ Branch 13 → 155 not taken.
|
1319 | entryNode->topLevelDefs.push_back(std::any_cast<MainFctDefNode *>(visit(mainFctDefCtx))); |
| 26 |
3/4✓ Branch 16 → 17 taken 162297 times.
✗ Branch 16 → 18 not taken.
✓ Branch 19 → 20 taken 65726 times.
✓ Branch 19 → 25 taken 96571 times.
|
162297 | else if (auto *fctDefCtx = dynamic_cast<SpiceParser::FunctionDefContext *>(child)) |
| 27 |
3/6✓ Branch 20 → 21 taken 65726 times.
✗ Branch 20 → 161 not taken.
✓ Branch 21 → 22 taken 65726 times.
✗ Branch 21 → 159 not taken.
✓ Branch 22 → 23 taken 65726 times.
✗ Branch 22 → 159 not taken.
|
65726 | entryNode->topLevelDefs.push_back(std::any_cast<FctDefNode *>(visit(fctDefCtx))); |
| 28 |
3/4✓ Branch 25 → 26 taken 96571 times.
✗ Branch 25 → 27 not taken.
✓ Branch 28 → 29 taken 35755 times.
✓ Branch 28 → 34 taken 60816 times.
|
96571 | else if (auto *procDefCtx = dynamic_cast<SpiceParser::ProcedureDefContext *>(child)) |
| 29 |
3/6✓ Branch 29 → 30 taken 35755 times.
✗ Branch 29 → 165 not taken.
✓ Branch 30 → 31 taken 35755 times.
✗ Branch 30 → 163 not taken.
✓ Branch 31 → 32 taken 35755 times.
✗ Branch 31 → 163 not taken.
|
35755 | entryNode->topLevelDefs.push_back(std::any_cast<ProcDefNode *>(visit(procDefCtx))); |
| 30 |
3/4✓ Branch 34 → 35 taken 60816 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 9663 times.
✓ Branch 37 → 43 taken 51153 times.
|
60816 | else if (auto *structDefCtx = dynamic_cast<SpiceParser::StructDefContext *>(child)) |
| 31 |
4/6✓ Branch 38 → 39 taken 9661 times.
✓ Branch 38 → 169 taken 2 times.
✓ Branch 39 → 40 taken 9661 times.
✗ Branch 39 → 167 not taken.
✓ Branch 40 → 41 taken 9661 times.
✗ Branch 40 → 167 not taken.
|
9663 | entryNode->topLevelDefs.push_back(std::any_cast<StructDefNode *>(visit(structDefCtx))); |
| 32 |
3/4✓ Branch 43 → 44 taken 51153 times.
✗ Branch 43 → 45 not taken.
✓ Branch 46 → 47 taken 1019 times.
✓ Branch 46 → 52 taken 50134 times.
|
51153 | else if (auto *interfaceDefCtx = dynamic_cast<SpiceParser::InterfaceDefContext *>(child)) |
| 33 |
3/6✓ Branch 47 → 48 taken 1019 times.
✗ Branch 47 → 173 not taken.
✓ Branch 48 → 49 taken 1019 times.
✗ Branch 48 → 171 not taken.
✓ Branch 49 → 50 taken 1019 times.
✗ Branch 49 → 171 not taken.
|
1019 | entryNode->topLevelDefs.push_back(std::any_cast<InterfaceDefNode *>(visit(interfaceDefCtx))); |
| 34 |
3/4✓ Branch 52 → 53 taken 50134 times.
✗ Branch 52 → 54 not taken.
✓ Branch 55 → 56 taken 78 times.
✓ Branch 55 → 61 taken 50056 times.
|
50134 | else if (auto *unionDefCtx = dynamic_cast<SpiceParser::UnionDefContext *>(child)) |
| 35 |
3/6✓ Branch 56 → 57 taken 78 times.
✗ Branch 56 → 177 not taken.
✓ Branch 57 → 58 taken 78 times.
✗ Branch 57 → 175 not taken.
✓ Branch 58 → 59 taken 78 times.
✗ Branch 58 → 175 not taken.
|
78 | entryNode->topLevelDefs.push_back(std::any_cast<UnionDefNode *>(visit(unionDefCtx))); |
| 36 |
3/4✓ Branch 61 → 62 taken 50056 times.
✗ Branch 61 → 63 not taken.
✓ Branch 64 → 65 taken 1970 times.
✓ Branch 64 → 70 taken 48086 times.
|
50056 | else if (auto *enumDefCtx = dynamic_cast<SpiceParser::EnumDefContext *>(child)) |
| 37 |
3/6✓ Branch 65 → 66 taken 1970 times.
✗ Branch 65 → 181 not taken.
✓ Branch 66 → 67 taken 1970 times.
✗ Branch 66 → 179 not taken.
✓ Branch 67 → 68 taken 1970 times.
✗ Branch 67 → 179 not taken.
|
1970 | entryNode->topLevelDefs.push_back(std::any_cast<EnumDefNode *>(visit(enumDefCtx))); |
| 38 |
3/4✓ Branch 70 → 71 taken 48086 times.
✗ Branch 70 → 72 not taken.
✓ Branch 73 → 74 taken 5141 times.
✓ Branch 73 → 79 taken 42945 times.
|
48086 | else if (auto *genericTypeDefCtx = dynamic_cast<SpiceParser::GenericTypeDefContext *>(child)) |
| 39 |
3/6✓ Branch 74 → 75 taken 5141 times.
✗ Branch 74 → 185 not taken.
✓ Branch 75 → 76 taken 5141 times.
✗ Branch 75 → 183 not taken.
✓ Branch 76 → 77 taken 5141 times.
✗ Branch 76 → 183 not taken.
|
5141 | entryNode->topLevelDefs.push_back(std::any_cast<GenericTypeDefNode *>(visit(genericTypeDefCtx))); |
| 40 |
3/4✓ Branch 79 → 80 taken 42945 times.
✗ Branch 79 → 81 not taken.
✓ Branch 82 → 83 taken 1189 times.
✓ Branch 82 → 88 taken 41756 times.
|
42945 | else if (auto *aliasDefCtx = dynamic_cast<SpiceParser::AliasDefContext *>(child)) |
| 41 |
3/6✓ Branch 83 → 84 taken 1189 times.
✗ Branch 83 → 189 not taken.
✓ Branch 84 → 85 taken 1189 times.
✗ Branch 84 → 187 not taken.
✓ Branch 85 → 86 taken 1189 times.
✗ Branch 85 → 187 not taken.
|
1189 | entryNode->topLevelDefs.push_back(std::any_cast<AliasDefNode *>(visit(aliasDefCtx))); |
| 42 |
3/4✓ Branch 88 → 89 taken 41756 times.
✗ Branch 88 → 90 not taken.
✓ Branch 91 → 92 taken 10251 times.
✓ Branch 91 → 97 taken 31505 times.
|
41756 | else if (auto *globalVarDefCtx = dynamic_cast<SpiceParser::GlobalVarDefContext *>(child)) |
| 43 |
3/6✓ Branch 92 → 93 taken 10251 times.
✗ Branch 92 → 193 not taken.
✓ Branch 93 → 94 taken 10251 times.
✗ Branch 93 → 191 not taken.
✓ Branch 94 → 95 taken 10251 times.
✗ Branch 94 → 191 not taken.
|
10251 | entryNode->topLevelDefs.push_back(std::any_cast<GlobalVarDefNode *>(visit(globalVarDefCtx))); |
| 44 |
3/4✓ Branch 97 → 98 taken 31505 times.
✗ Branch 97 → 99 not taken.
✓ Branch 100 → 101 taken 9486 times.
✓ Branch 100 → 106 taken 22019 times.
|
31505 | else if (auto *importDefCtx = dynamic_cast<SpiceParser::ImportDefContext *>(child)) |
| 45 |
3/6✓ Branch 101 → 102 taken 9486 times.
✗ Branch 101 → 197 not taken.
✓ Branch 102 → 103 taken 9486 times.
✗ Branch 102 → 195 not taken.
✓ Branch 103 → 104 taken 9486 times.
✗ Branch 103 → 195 not taken.
|
9486 | entryNode->importDefs.push_back(std::any_cast<ImportDefNode *>(visit(importDefCtx))); |
| 46 |
3/4✓ Branch 106 → 107 taken 22019 times.
✗ Branch 106 → 108 not taken.
✓ Branch 109 → 110 taken 12367 times.
✓ Branch 109 → 115 taken 9652 times.
|
22019 | else if (auto *extDeclCtx = dynamic_cast<SpiceParser::ExtDeclContext *>(child)) |
| 47 |
3/6✓ Branch 110 → 111 taken 12367 times.
✗ Branch 110 → 201 not taken.
✓ Branch 111 → 112 taken 12367 times.
✗ Branch 111 → 199 not taken.
✓ Branch 112 → 113 taken 12367 times.
✗ Branch 112 → 199 not taken.
|
12367 | entryNode->topLevelDefs.push_back(std::any_cast<ExtDeclNode *>(visit(extDeclCtx))); |
| 48 |
3/4✓ Branch 115 → 116 taken 9652 times.
✗ Branch 115 → 117 not taken.
✓ Branch 118 → 119 taken 2338 times.
✓ Branch 118 → 124 taken 7314 times.
|
9652 | else if (auto *modAttrCtx = dynamic_cast<SpiceParser::ModAttrContext *>(child)) |
| 49 |
4/6✓ Branch 119 → 120 taken 2336 times.
✓ Branch 119 → 205 taken 2 times.
✓ Branch 120 → 121 taken 2336 times.
✗ Branch 120 → 203 not taken.
✓ Branch 121 → 122 taken 2336 times.
✗ Branch 121 → 203 not taken.
|
2338 | entryNode->modAttrs.push_back(std::any_cast<ModAttrNode *>(visit(modAttrCtx))); |
| 50 |
1/2✓ Branch 124 → 125 taken 7314 times.
✗ Branch 124 → 126 not taken.
|
7314 | else if (const auto *eofCtx = dynamic_cast<TerminalNode *>(child); |
| 51 |
5/10✓ Branch 127 → 128 taken 7314 times.
✗ Branch 127 → 131 not taken.
✓ Branch 128 → 129 taken 7314 times.
✗ Branch 128 → 207 not taken.
✓ Branch 129 → 130 taken 7314 times.
✗ Branch 129 → 207 not taken.
✗ Branch 130 → 131 not taken.
✓ Branch 130 → 132 taken 7314 times.
✗ Branch 133 → 134 not taken.
✓ Branch 133 → 135 taken 7314 times.
|
7314 | !eofCtx || eofCtx->getSymbol()->getType() != SpiceParser::EOF) |
| 52 | − | assert_fail("Unknown top level definition type"); // GCOV_EXCL_LINE | |
| 53 | } | ||
| 54 | |||
| 55 |
1/2✓ Branch 151 → 152 taken 7314 times.
✗ Branch 151 → 208 not taken.
|
14628 | return concludeNode(entryNode); |
| 56 | } | ||
| 57 | |||
| 58 | 1319 | std::any ASTBuilder::visitMainFunctionDef(SpiceParser::MainFunctionDefContext *ctx) { | |
| 59 | 1319 | const auto mainFctDefNode = createNode<MainFctDefNode>(ctx); | |
| 60 | |||
| 61 | // Visit children | ||
| 62 |
2/2✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 10 taken 1317 times.
|
1319 | if (ctx->topLevelDefAttr()) |
| 63 |
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())); |
| 64 |
2/2✓ Branch 11 → 12 taken 14 times.
✓ Branch 11 → 17 taken 1305 times.
|
1319 | if (ctx->paramLst()) { |
| 65 | 14 | mainFctDefNode->takesArgs = true; | |
| 66 |
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())); |
| 67 | } | ||
| 68 |
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())); |
| 69 | |||
| 70 |
1/2✓ Branch 27 → 28 taken 1311 times.
✗ Branch 27 → 40 not taken.
|
2622 | return concludeNode(mainFctDefNode); |
| 71 | } | ||
| 72 | |||
| 73 | 65726 | std::any ASTBuilder::visitFunctionDef(SpiceParser::FunctionDefContext *ctx) { | |
| 74 | 65726 | const auto fctDefNode = createNode<FctDefNode>(ctx); | |
| 75 | |||
| 76 | // Visit children | ||
| 77 |
2/2✓ Branch 4 → 5 taken 2032 times.
✓ Branch 4 → 24 taken 63694 times.
|
65726 | if (ctx->topLevelDefAttr()) { |
| 78 |
3/6✓ Branch 5 → 6 taken 2032 times.
✗ Branch 5 → 70 not taken.
✓ Branch 6 → 7 taken 2032 times.
✗ Branch 6 → 70 not taken.
✓ Branch 7 → 8 taken 2032 times.
✗ Branch 7 → 68 not taken.
|
2032 | fctDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 79 | // Tell the attributes that they are function attributes | ||
| 80 |
2/2✓ Branch 22 → 11 taken 2456 times.
✓ Branch 22 → 23 taken 2032 times.
|
6520 | for (AttrNode *attr : fctDefNode->attrs->attrLst->attributes) |
| 81 | 2456 | attr->target = AttrNode::TARGET_FCT_PROC; | |
| 82 | } | ||
| 83 |
2/2✓ Branch 25 → 26 taken 62909 times.
✓ Branch 25 → 31 taken 2817 times.
|
65726 | if (ctx->qualifierLst()) |
| 84 |
3/6✓ Branch 26 → 27 taken 62909 times.
✗ Branch 26 → 73 not taken.
✓ Branch 27 → 28 taken 62909 times.
✗ Branch 27 → 73 not taken.
✓ Branch 28 → 29 taken 62909 times.
✗ Branch 28 → 71 not taken.
|
62909 | fctDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 85 |
3/6✓ Branch 31 → 32 taken 65726 times.
✗ Branch 31 → 76 not taken.
✓ Branch 32 → 33 taken 65726 times.
✗ Branch 32 → 76 not taken.
✓ Branch 33 → 34 taken 65726 times.
✗ Branch 33 → 74 not taken.
|
65726 | fctDefNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 86 | 65726 | fctDefNode->returnType->isReturnType = true; | |
| 87 |
3/6✓ Branch 35 → 36 taken 65726 times.
✗ Branch 35 → 79 not taken.
✓ Branch 36 → 37 taken 65726 times.
✗ Branch 36 → 79 not taken.
✓ Branch 37 → 38 taken 65726 times.
✗ Branch 37 → 77 not taken.
|
65726 | fctDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName())); |
| 88 | 65726 | fctDefNode->isMethod = fctDefNode->name->nameFragments.size() > 1; | |
| 89 |
2/2✓ Branch 41 → 42 taken 5678 times.
✓ Branch 41 → 47 taken 60048 times.
|
65726 | if (ctx->typeLst()) { |
| 90 | 5678 | fctDefNode->hasTemplateTypes = true; | |
| 91 |
3/6✓ Branch 42 → 43 taken 5678 times.
✗ Branch 42 → 82 not taken.
✓ Branch 43 → 44 taken 5678 times.
✗ Branch 43 → 82 not taken.
✓ Branch 44 → 45 taken 5678 times.
✗ Branch 44 → 80 not taken.
|
5678 | fctDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 92 | } | ||
| 93 |
2/2✓ Branch 48 → 49 taken 43658 times.
✓ Branch 48 → 54 taken 22068 times.
|
65726 | if (ctx->paramLst()) { |
| 94 | 43658 | fctDefNode->hasParams = true; | |
| 95 |
3/6✓ Branch 49 → 50 taken 43658 times.
✗ Branch 49 → 85 not taken.
✓ Branch 50 → 51 taken 43658 times.
✗ Branch 50 → 85 not taken.
✓ Branch 51 → 52 taken 43658 times.
✗ Branch 51 → 83 not taken.
|
43658 | fctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 96 | } | ||
| 97 |
4/8✓ Branch 54 → 55 taken 65726 times.
✗ Branch 54 → 88 not taken.
✓ Branch 55 → 56 taken 65726 times.
✗ Branch 55 → 88 not taken.
✓ Branch 56 → 57 taken 65726 times.
✗ Branch 56 → 86 not taken.
✓ Branch 58 → 59 taken 65726 times.
✗ Branch 58 → 89 not taken.
|
65726 | fctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 98 | |||
| 99 |
1/2✓ Branch 64 → 65 taken 65726 times.
✗ Branch 64 → 89 not taken.
|
131452 | return concludeNode(fctDefNode); |
| 100 | } | ||
| 101 | |||
| 102 | 35755 | std::any ASTBuilder::visitProcedureDef(SpiceParser::ProcedureDefContext *ctx) { | |
| 103 | 35755 | const auto procDefNode = createNode<ProcDefNode>(ctx); | |
| 104 | |||
| 105 | // Visit children | ||
| 106 |
2/2✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 24 taken 35753 times.
|
35755 | if (ctx->topLevelDefAttr()) { |
| 107 |
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())); |
| 108 | // Tell the attributes that they are function attributes | ||
| 109 |
2/2✓ Branch 22 → 11 taken 2 times.
✓ Branch 22 → 23 taken 2 times.
|
6 | for (AttrNode *attr : procDefNode->attrs->attrLst->attributes) |
| 110 | 2 | attr->target = AttrNode::TARGET_FCT_PROC; | |
| 111 | } | ||
| 112 |
2/2✓ Branch 25 → 26 taken 30481 times.
✓ Branch 25 → 31 taken 5274 times.
|
35755 | if (ctx->qualifierLst()) |
| 113 |
3/6✓ Branch 26 → 27 taken 30481 times.
✗ Branch 26 → 69 not taken.
✓ Branch 27 → 28 taken 30481 times.
✗ Branch 27 → 69 not taken.
✓ Branch 28 → 29 taken 30481 times.
✗ Branch 28 → 67 not taken.
|
30481 | procDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 114 |
3/6✓ Branch 31 → 32 taken 35755 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 35755 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 35755 times.
✗ Branch 33 → 70 not taken.
|
35755 | procDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName())); |
| 115 | 35755 | procDefNode->isMethod = procDefNode->name->nameFragments.size() > 1; | |
| 116 |
2/2✓ Branch 37 → 38 taken 5598 times.
✓ Branch 37 → 43 taken 30157 times.
|
35755 | if (ctx->typeLst()) { |
| 117 | 5598 | procDefNode->hasTemplateTypes = true; | |
| 118 |
3/6✓ Branch 38 → 39 taken 5598 times.
✗ Branch 38 → 75 not taken.
✓ Branch 39 → 40 taken 5598 times.
✗ Branch 39 → 75 not taken.
✓ Branch 40 → 41 taken 5598 times.
✗ Branch 40 → 73 not taken.
|
5598 | procDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 119 | } | ||
| 120 |
2/2✓ Branch 44 → 45 taken 26435 times.
✓ Branch 44 → 50 taken 9320 times.
|
35755 | if (ctx->paramLst()) { |
| 121 | 26435 | procDefNode->hasParams = true; | |
| 122 |
3/6✓ Branch 45 → 46 taken 26435 times.
✗ Branch 45 → 78 not taken.
✓ Branch 46 → 47 taken 26435 times.
✗ Branch 46 → 78 not taken.
✓ Branch 47 → 48 taken 26435 times.
✗ Branch 47 → 76 not taken.
|
26435 | procDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 123 | } | ||
| 124 |
4/8✓ Branch 50 → 51 taken 35755 times.
✗ Branch 50 → 81 not taken.
✓ Branch 51 → 52 taken 35755 times.
✗ Branch 51 → 81 not taken.
✓ Branch 52 → 53 taken 35755 times.
✗ Branch 52 → 79 not taken.
✓ Branch 54 → 55 taken 35755 times.
✗ Branch 54 → 82 not taken.
|
35755 | procDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 125 | |||
| 126 |
1/2✓ Branch 60 → 61 taken 35755 times.
✗ Branch 60 → 82 not taken.
|
71510 | return concludeNode(procDefNode); |
| 127 | } | ||
| 128 | |||
| 129 | 101481 | std::any ASTBuilder::visitFctName(SpiceParser::FctNameContext *ctx) { | |
| 130 |
1/2✓ Branch 2 → 3 taken 101481 times.
✗ Branch 2 → 54 not taken.
|
101481 | const auto fctNameNode = createNode<FctNameNode>(ctx); |
| 131 | |||
| 132 | // Extract function name | ||
| 133 |
1/2✓ Branch 3 → 4 taken 101481 times.
✗ Branch 3 → 54 not taken.
|
101481 | std::stringstream fqName; |
| 134 |
3/4✓ Branch 4 → 5 taken 101481 times.
✗ Branch 4 → 52 not taken.
✓ Branch 5 → 6 taken 67436 times.
✓ Branch 5 → 14 taken 34045 times.
|
101481 | if (ctx->TYPE_IDENTIFIER()) { |
| 135 |
2/4✓ Branch 6 → 7 taken 67436 times.
✗ Branch 6 → 45 not taken.
✓ Branch 7 → 8 taken 67436 times.
✗ Branch 7 → 45 not taken.
|
67436 | const std::string typeIdentifier = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 136 |
1/2✓ Branch 8 → 9 taken 67436 times.
✗ Branch 8 → 43 not taken.
|
67436 | fctNameNode->structName = typeIdentifier; |
| 137 |
2/4✓ Branch 9 → 10 taken 67436 times.
✗ Branch 9 → 43 not taken.
✓ Branch 10 → 11 taken 67436 times.
✗ Branch 10 → 43 not taken.
|
67436 | fqName << typeIdentifier << MEMBER_ACCESS_TOKEN; |
| 138 |
1/2✓ Branch 11 → 12 taken 67436 times.
✗ Branch 11 → 43 not taken.
|
67436 | fctNameNode->nameFragments.push_back(typeIdentifier); |
| 139 | 67436 | } | |
| 140 |
3/4✓ Branch 14 → 15 taken 101481 times.
✗ Branch 14 → 52 not taken.
✓ Branch 15 → 16 taken 92177 times.
✓ Branch 15 → 23 taken 9304 times.
|
101481 | if (ctx->IDENTIFIER()) { |
| 141 |
2/4✓ Branch 16 → 17 taken 92177 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 92177 times.
✗ Branch 17 → 48 not taken.
|
92177 | const std::string fctIdentifier = getIdentifier(ctx->IDENTIFIER(), false); |
| 142 |
1/2✓ Branch 18 → 19 taken 92177 times.
✗ Branch 18 → 46 not taken.
|
92177 | fctNameNode->name = fctIdentifier; |
| 143 |
1/2✓ Branch 19 → 20 taken 92177 times.
✗ Branch 19 → 46 not taken.
|
92177 | fqName << fctIdentifier; |
| 144 |
1/2✓ Branch 20 → 21 taken 92177 times.
✗ Branch 20 → 46 not taken.
|
92177 | fctNameNode->nameFragments.push_back(fctIdentifier); |
| 145 | 92177 | } | |
| 146 |
1/2✓ Branch 23 → 24 taken 101481 times.
✗ Branch 23 → 49 not taken.
|
101481 | fctNameNode->fqName = fqName.str(); |
| 147 | |||
| 148 | // Visit children | ||
| 149 |
3/4✓ Branch 26 → 27 taken 101481 times.
✗ Branch 26 → 52 not taken.
✓ Branch 27 → 28 taken 9304 times.
✓ Branch 27 → 32 taken 92177 times.
|
101481 | if (ctx->overloadableOp()) |
| 150 |
2/4✓ Branch 28 → 29 taken 9304 times.
✗ Branch 28 → 50 not taken.
✓ Branch 29 → 30 taken 9304 times.
✗ Branch 29 → 50 not taken.
|
9304 | visit(ctx->overloadableOp()); |
| 151 | |||
| 152 |
1/2✓ Branch 38 → 39 taken 101481 times.
✗ Branch 38 → 51 not taken.
|
202962 | return concludeNode(fctNameNode); |
| 153 | 101481 | } | |
| 154 | |||
| 155 | 9663 | std::any ASTBuilder::visitStructDef(SpiceParser::StructDefContext *ctx) { | |
| 156 | 9663 | const auto structDefNode = createNode<StructDefNode>(ctx); | |
| 157 | |||
| 158 | // Enrich | ||
| 159 |
3/4✓ Branch 3 → 4 taken 9663 times.
✗ Branch 3 → 103 not taken.
✓ Branch 4 → 5 taken 9661 times.
✓ Branch 4 → 103 taken 2 times.
|
9663 | structDefNode->structName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 160 | 9661 | structDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 161 | |||
| 162 | // Visit children | ||
| 163 |
2/2✓ Branch 9 → 10 taken 262 times.
✓ Branch 9 → 49 taken 9399 times.
|
9661 | if (ctx->topLevelDefAttr()) { |
| 164 |
3/6✓ Branch 10 → 11 taken 262 times.
✗ Branch 10 → 106 not taken.
✓ Branch 11 → 12 taken 262 times.
✗ Branch 11 → 106 not taken.
✓ Branch 12 → 13 taken 262 times.
✗ Branch 12 → 104 not taken.
|
262 | structDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 165 | |||
| 166 | // Tell the attributes that they are struct attributes | ||
| 167 |
2/2✓ Branch 27 → 16 taken 262 times.
✓ Branch 27 → 28 taken 262 times.
|
786 | for (AttrNode *attr : structDefNode->attrs->attrLst->attributes) |
| 168 | 262 | attr->target = AttrNode::TARGET_STRUCT; | |
| 169 | |||
| 170 | // Check if a custom type id was set | ||
| 171 |
7/18✓ Branch 28 → 29 taken 262 times.
✗ Branch 28 → 35 not taken.
✓ Branch 31 → 32 taken 262 times.
✗ Branch 31 → 107 not taken.
✓ Branch 32 → 33 taken 262 times.
✗ Branch 32 → 107 not taken.
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 262 times.
✓ Branch 36 → 37 taken 262 times.
✗ Branch 36 → 38 not taken.
✓ Branch 38 → 39 taken 262 times.
✗ Branch 38 → 41 not taken.
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 262 times.
✗ Branch 107 → 108 not taken.
✗ Branch 107 → 109 not taken.
✗ Branch 111 → 112 not taken.
✗ Branch 111 → 114 not taken.
|
786 | if (structDefNode->attrs && structDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID)) |
| 172 | ✗ | structDefNode->typeId = structDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue; | |
| 173 | } | ||
| 174 |
2/2✓ Branch 50 → 51 taken 7977 times.
✓ Branch 50 → 56 taken 1684 times.
|
9661 | if (ctx->qualifierLst()) |
| 175 |
3/6✓ Branch 51 → 52 taken 7977 times.
✗ Branch 51 → 124 not taken.
✓ Branch 52 → 53 taken 7977 times.
✗ Branch 52 → 124 not taken.
✓ Branch 53 → 54 taken 7977 times.
✗ Branch 53 → 122 not taken.
|
7977 | structDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 176 |
2/2✓ Branch 57 → 58 taken 1738 times.
✓ Branch 57 → 63 taken 7923 times.
|
9661 | if (ctx->LESS()) { |
| 177 | 1738 | structDefNode->hasTemplateTypes = true; | |
| 178 |
3/6✓ Branch 58 → 59 taken 1738 times.
✗ Branch 58 → 127 not taken.
✓ Branch 59 → 60 taken 1738 times.
✗ Branch 59 → 127 not taken.
✓ Branch 60 → 61 taken 1738 times.
✗ Branch 60 → 125 not taken.
|
1738 | structDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0))); |
| 179 | } | ||
| 180 |
2/2✓ Branch 64 → 65 taken 4092 times.
✓ Branch 64 → 73 taken 5569 times.
|
9661 | if (ctx->COLON()) { |
| 181 | 4092 | structDefNode->hasInterfaces = true; | |
| 182 |
5/8✓ Branch 65 → 66 taken 770 times.
✓ Branch 65 → 67 taken 3322 times.
✓ Branch 68 → 69 taken 4092 times.
✗ Branch 68 → 130 not taken.
✓ Branch 69 → 70 taken 4092 times.
✗ Branch 69 → 130 not taken.
✓ Branch 70 → 71 taken 4092 times.
✗ Branch 70 → 128 not taken.
|
4092 | structDefNode->interfaceTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(structDefNode->hasTemplateTypes ? 1 : 0))); |
| 183 | } | ||
| 184 |
3/4✓ Branch 73 → 74 taken 9661 times.
✗ Branch 73 → 137 not taken.
✓ Branch 91 → 76 taken 26424 times.
✓ Branch 91 → 92 taken 9661 times.
|
45746 | for (SpiceParser::FieldContext *field : ctx->field()) |
| 185 |
3/6✓ Branch 78 → 79 taken 26424 times.
✗ Branch 78 → 133 not taken.
✓ Branch 79 → 80 taken 26424 times.
✗ Branch 79 → 131 not taken.
✓ Branch 80 → 81 taken 26424 times.
✗ Branch 80 → 131 not taken.
|
36085 | structDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field))); |
| 186 | |||
| 187 |
1/2✓ Branch 99 → 100 taken 9661 times.
✗ Branch 99 → 138 not taken.
|
19322 | return concludeNode(structDefNode); |
| 188 | } | ||
| 189 | |||
| 190 | 1019 | std::any ASTBuilder::visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) { | |
| 191 | 1019 | const auto interfaceDefNode = createNode<InterfaceDefNode>(ctx); | |
| 192 | |||
| 193 | // Enrich | ||
| 194 |
2/4✓ Branch 3 → 4 taken 1019 times.
✗ Branch 3 → 93 not taken.
✓ Branch 4 → 5 taken 1019 times.
✗ Branch 4 → 93 not taken.
|
1019 | interfaceDefNode->interfaceName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 195 | 1019 | interfaceDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 196 | |||
| 197 | // Visit children | ||
| 198 |
2/2✓ Branch 9 → 10 taken 398 times.
✓ Branch 9 → 49 taken 621 times.
|
1019 | if (ctx->topLevelDefAttr()) { |
| 199 |
3/6✓ Branch 10 → 11 taken 398 times.
✗ Branch 10 → 96 not taken.
✓ Branch 11 → 12 taken 398 times.
✗ Branch 11 → 96 not taken.
✓ Branch 12 → 13 taken 398 times.
✗ Branch 12 → 94 not taken.
|
398 | interfaceDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); |
| 200 | |||
| 201 | // Tell the attributes that they are struct attributes | ||
| 202 |
2/2✓ Branch 27 → 16 taken 398 times.
✓ Branch 27 → 28 taken 398 times.
|
1194 | for (AttrNode *attr : interfaceDefNode->attrs->attrLst->attributes) |
| 203 | 398 | attr->target = AttrNode::TARGET_INTERFACE; | |
| 204 | |||
| 205 | // Check if a custom type id was set | ||
| 206 |
7/18✓ Branch 28 → 29 taken 398 times.
✗ Branch 28 → 35 not taken.
✓ Branch 31 → 32 taken 398 times.
✗ Branch 31 → 97 not taken.
✓ Branch 32 → 33 taken 398 times.
✗ Branch 32 → 97 not taken.
✓ Branch 33 → 34 taken 398 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 398 times.
✗ Branch 36 → 38 not taken.
✓ Branch 38 → 39 taken 398 times.
✗ Branch 38 → 41 not taken.
✓ Branch 41 → 42 taken 398 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.
|
1194 | if (interfaceDefNode->attrs && interfaceDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID)) |
| 207 |
2/4✓ Branch 44 → 45 taken 398 times.
✗ Branch 44 → 108 not taken.
✓ Branch 45 → 46 taken 398 times.
✗ Branch 45 → 106 not taken.
|
1194 | interfaceDefNode->typeId = interfaceDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue; |
| 208 | } | ||
| 209 |
2/2✓ Branch 50 → 51 taken 977 times.
✓ Branch 50 → 56 taken 42 times.
|
1019 | if (ctx->qualifierLst()) |
| 210 |
3/6✓ Branch 51 → 52 taken 977 times.
✗ Branch 51 → 114 not taken.
✓ Branch 52 → 53 taken 977 times.
✗ Branch 52 → 114 not taken.
✓ Branch 53 → 54 taken 977 times.
✗ Branch 53 → 112 not taken.
|
977 | interfaceDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 211 |
2/2✓ Branch 57 → 58 taken 406 times.
✓ Branch 57 → 63 taken 613 times.
|
1019 | if (ctx->LESS()) { |
| 212 | 406 | interfaceDefNode->hasTemplateTypes = true; | |
| 213 |
3/6✓ Branch 58 → 59 taken 406 times.
✗ Branch 58 → 117 not taken.
✓ Branch 59 → 60 taken 406 times.
✗ Branch 59 → 117 not taken.
✓ Branch 60 → 61 taken 406 times.
✗ Branch 60 → 115 not taken.
|
406 | interfaceDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 214 | } | ||
| 215 |
3/4✓ Branch 63 → 64 taken 1019 times.
✗ Branch 63 → 124 not taken.
✓ Branch 81 → 66 taken 7527 times.
✓ Branch 81 → 82 taken 1019 times.
|
9565 | for (SpiceParser::SignatureContext *signature : ctx->signature()) |
| 216 |
3/6✓ Branch 68 → 69 taken 7527 times.
✗ Branch 68 → 120 not taken.
✓ Branch 69 → 70 taken 7527 times.
✗ Branch 69 → 118 not taken.
✓ Branch 70 → 71 taken 7527 times.
✗ Branch 70 → 118 not taken.
|
8546 | interfaceDefNode->signatures.push_back(std::any_cast<SignatureNode *>(visit(signature))); |
| 217 | |||
| 218 |
1/2✓ Branch 89 → 90 taken 1019 times.
✗ Branch 89 → 125 not taken.
|
2038 | return concludeNode(interfaceDefNode); |
| 219 | } | ||
| 220 | |||
| 221 | 78 | std::any ASTBuilder::visitUnionDef(SpiceParser::UnionDefContext *ctx) { | |
| 222 | 78 | const auto unionDefNode = createNode<UnionDefNode>(ctx); | |
| 223 | |||
| 224 | // Enrich | ||
| 225 |
2/4✓ Branch 3 → 4 taken 78 times.
✗ Branch 3 → 93 not taken.
✓ Branch 4 → 5 taken 78 times.
✗ Branch 4 → 93 not taken.
|
78 | unionDefNode->unionName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 226 | 78 | unionDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 227 | |||
| 228 | // Visit children | ||
| 229 |
1/2✗ Branch 9 → 10 not taken.
✓ Branch 9 → 49 taken 78 times.
|
78 | if (ctx->topLevelDefAttr()) { |
| 230 | ✗ | unionDefNode->attrs = std::any_cast<TopLevelDefAttrNode *>(visit(ctx->topLevelDefAttr())); | |
| 231 | |||
| 232 | // Tell the attributes that they are union attributes | ||
| 233 | ✗ | for (AttrNode *attr : unionDefNode->attrs->attrLst->attributes) | |
| 234 | ✗ | attr->target = AttrNode::TARGET_UNION; | |
| 235 | |||
| 236 | // Check if a custom type id was set | ||
| 237 | ✗ | if (unionDefNode->attrs && unionDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID)) | |
| 238 | ✗ | unionDefNode->typeId = unionDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue; | |
| 239 | } | ||
| 240 |
2/2✓ Branch 50 → 51 taken 42 times.
✓ Branch 50 → 56 taken 36 times.
|
78 | if (ctx->qualifierLst()) |
| 241 |
3/6✓ Branch 51 → 52 taken 42 times.
✗ Branch 51 → 114 not taken.
✓ Branch 52 → 53 taken 42 times.
✗ Branch 52 → 114 not taken.
✓ Branch 53 → 54 taken 42 times.
✗ Branch 53 → 112 not taken.
|
42 | unionDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 242 |
2/2✓ Branch 57 → 58 taken 4 times.
✓ Branch 57 → 63 taken 74 times.
|
78 | if (ctx->LESS()) { |
| 243 | 4 | unionDefNode->hasTemplateTypes = true; | |
| 244 |
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())); |
| 245 | } | ||
| 246 |
3/4✓ Branch 63 → 64 taken 78 times.
✗ Branch 63 → 124 not taken.
✓ Branch 81 → 66 taken 398 times.
✓ Branch 81 → 82 taken 78 times.
|
554 | for (SpiceParser::FieldContext *field : ctx->field()) |
| 247 |
3/6✓ Branch 68 → 69 taken 398 times.
✗ Branch 68 → 120 not taken.
✓ Branch 69 → 70 taken 398 times.
✗ Branch 69 → 118 not taken.
✓ Branch 70 → 71 taken 398 times.
✗ Branch 70 → 118 not taken.
|
476 | unionDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field))); |
| 248 | |||
| 249 |
1/2✓ Branch 89 → 90 taken 78 times.
✗ Branch 89 → 125 not taken.
|
156 | return concludeNode(unionDefNode); |
| 250 | } | ||
| 251 | |||
| 252 | 1970 | std::any ASTBuilder::visitEnumDef(SpiceParser::EnumDefContext *ctx) { | |
| 253 | 1970 | const auto enumDefNode = createNode<EnumDefNode>(ctx); | |
| 254 | |||
| 255 | // Enrich | ||
| 256 |
2/4✓ Branch 3 → 4 taken 1970 times.
✗ Branch 3 → 43 not taken.
✓ Branch 4 → 5 taken 1970 times.
✗ Branch 4 → 43 not taken.
|
1970 | enumDefNode->enumName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 257 | 1970 | enumDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 258 | |||
| 259 | // Visit children | ||
| 260 |
2/2✓ Branch 9 → 10 taken 1895 times.
✓ Branch 9 → 15 taken 75 times.
|
1970 | if (ctx->qualifierLst()) |
| 261 |
3/6✓ Branch 10 → 11 taken 1895 times.
✗ Branch 10 → 46 not taken.
✓ Branch 11 → 12 taken 1895 times.
✗ Branch 11 → 46 not taken.
✓ Branch 12 → 13 taken 1895 times.
✗ Branch 12 → 44 not taken.
|
1895 | enumDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 262 |
3/6✓ Branch 15 → 16 taken 1970 times.
✗ Branch 15 → 49 not taken.
✓ Branch 16 → 17 taken 1970 times.
✗ Branch 16 → 49 not taken.
✓ Branch 17 → 18 taken 1970 times.
✗ Branch 17 → 47 not taken.
|
1970 | enumDefNode->itemLst = std::any_cast<EnumItemLstNode *>(visit(ctx->enumItemLst())); |
| 263 | |||
| 264 | // Tell all items about the enum def | ||
| 265 |
2/2✓ Branch 32 → 21 taken 19416 times.
✓ Branch 32 → 33 taken 1970 times.
|
23356 | for (EnumItemNode *enumItem : enumDefNode->itemLst->items) |
| 266 | 19416 | enumItem->enumDef = enumDefNode; | |
| 267 | |||
| 268 |
1/2✓ Branch 39 → 40 taken 1970 times.
✗ Branch 39 → 50 not taken.
|
3940 | return concludeNode(enumDefNode); |
| 269 | } | ||
| 270 | |||
| 271 | 5141 | std::any ASTBuilder::visitGenericTypeDef(SpiceParser::GenericTypeDefContext *ctx) { | |
| 272 | 5141 | const auto genericTypeDefNode = createNode<GenericTypeDefNode>(ctx); | |
| 273 | |||
| 274 | // Enrich | ||
| 275 |
2/4✓ Branch 3 → 4 taken 5141 times.
✗ Branch 3 → 21 not taken.
✓ Branch 4 → 5 taken 5141 times.
✗ Branch 4 → 21 not taken.
|
5141 | genericTypeDefNode->typeName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 276 | |||
| 277 | // Visit children | ||
| 278 |
4/8✓ Branch 7 → 8 taken 5141 times.
✗ Branch 7 → 24 not taken.
✓ Branch 8 → 9 taken 5141 times.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 5141 times.
✗ Branch 9 → 22 not taken.
✓ Branch 11 → 12 taken 5141 times.
✗ Branch 11 → 25 not taken.
|
5141 | genericTypeDefNode->typeAltsLst = std::any_cast<TypeAltsLstNode *>(visit(ctx->typeAltsLst())); |
| 279 | |||
| 280 |
1/2✓ Branch 17 → 18 taken 5141 times.
✗ Branch 17 → 25 not taken.
|
10282 | return concludeNode(genericTypeDefNode); |
| 281 | } | ||
| 282 | |||
| 283 | 1189 | std::any ASTBuilder::visitAliasDef(SpiceParser::AliasDefContext *ctx) { | |
| 284 | 1189 | const auto aliasDefNode = createNode<AliasDefNode>(ctx); | |
| 285 | |||
| 286 | // Enrich | ||
| 287 |
2/4✓ Branch 3 → 4 taken 1189 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 1189 times.
✗ Branch 4 → 33 not taken.
|
1189 | aliasDefNode->aliasName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 288 |
2/4✓ Branch 7 → 8 taken 1189 times.
✗ Branch 7 → 34 not taken.
✓ Branch 8 → 9 taken 1189 times.
✗ Branch 8 → 34 not taken.
|
1189 | aliasDefNode->dataTypeString = ctx->dataType()->getText(); |
| 289 | 1189 | aliasDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 290 | |||
| 291 | // Visit children | ||
| 292 |
2/2✓ Branch 13 → 14 taken 401 times.
✓ Branch 13 → 19 taken 788 times.
|
1189 | if (ctx->qualifierLst()) |
| 293 |
3/6✓ Branch 14 → 15 taken 401 times.
✗ Branch 14 → 37 not taken.
✓ Branch 15 → 16 taken 401 times.
✗ Branch 15 → 37 not taken.
✓ Branch 16 → 17 taken 401 times.
✗ Branch 16 → 35 not taken.
|
401 | aliasDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 294 |
4/8✓ Branch 19 → 20 taken 1189 times.
✗ Branch 19 → 40 not taken.
✓ Branch 20 → 21 taken 1189 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 1189 times.
✗ Branch 21 → 38 not taken.
✓ Branch 23 → 24 taken 1189 times.
✗ Branch 23 → 41 not taken.
|
1189 | aliasDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 295 | |||
| 296 |
1/2✓ Branch 29 → 30 taken 1189 times.
✗ Branch 29 → 41 not taken.
|
2378 | return concludeNode(aliasDefNode); |
| 297 | } | ||
| 298 | |||
| 299 | 10251 | std::any ASTBuilder::visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) { | |
| 300 | 10251 | const auto globalVarDefNode = createNode<GlobalVarDefNode>(ctx); | |
| 301 | |||
| 302 | // Enrich | ||
| 303 |
2/4✓ Branch 3 → 4 taken 10251 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 10251 times.
✗ Branch 4 → 28 not taken.
|
10251 | globalVarDefNode->varName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 304 | |||
| 305 | // Visit children | ||
| 306 |
3/6✓ Branch 7 → 8 taken 10251 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 10251 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 10251 times.
✗ Branch 9 → 29 not taken.
|
10251 | globalVarDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 307 | 10251 | globalVarDefNode->dataType->isGlobalType = true; | |
| 308 |
2/2✓ Branch 12 → 13 taken 10247 times.
✓ Branch 12 → 18 taken 4 times.
|
10251 | if (ctx->constant()) { |
| 309 | 10247 | globalVarDefNode->hasValue = true; | |
| 310 |
3/6✓ Branch 13 → 14 taken 10247 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 10247 times.
✗ Branch 14 → 34 not taken.
✓ Branch 15 → 16 taken 10247 times.
✗ Branch 15 → 32 not taken.
|
10247 | globalVarDefNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 311 | } | ||
| 312 | |||
| 313 |
1/2✓ Branch 24 → 25 taken 10251 times.
✗ Branch 24 → 35 not taken.
|
20502 | return concludeNode(globalVarDefNode); |
| 314 | } | ||
| 315 | |||
| 316 | 12367 | std::any ASTBuilder::visitExtDecl(SpiceParser::ExtDeclContext *ctx) { | |
| 317 | 12367 | const auto extDeclNode = createNode<ExtDeclNode>(ctx); | |
| 318 | |||
| 319 | // Enrich | ||
| 320 |
6/10✓ Branch 3 → 4 taken 12367 times.
✗ Branch 3 → 57 not taken.
✓ Branch 4 → 5 taken 7033 times.
✓ Branch 4 → 7 taken 5334 times.
✓ Branch 5 → 6 taken 7033 times.
✗ Branch 5 → 57 not taken.
✓ Branch 7 → 8 taken 5334 times.
✗ Branch 7 → 57 not taken.
✓ Branch 9 → 10 taken 12367 times.
✗ Branch 9 → 57 not taken.
|
12367 | extDeclNode->extFunctionName = getIdentifier(ctx->IDENTIFIER() ? ctx->IDENTIFIER() : ctx->TYPE_IDENTIFIER(), false); |
| 321 | |||
| 322 | // Visit children | ||
| 323 |
2/2✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 33 taken 12365 times.
|
12367 | if (ctx->topLevelDefAttr()) { |
| 324 |
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())); |
| 325 | |||
| 326 | // Tell the attributes that they are ext decl attributes | ||
| 327 |
2/2✓ Branch 31 → 20 taken 2 times.
✓ Branch 31 → 32 taken 2 times.
|
6 | for (AttrNode *attr : extDeclNode->attrs->attrLst->attributes) |
| 328 | 2 | attr->target = AttrNode::TARGET_EXT_DECL; | |
| 329 | } | ||
| 330 |
2/2✓ Branch 34 → 35 taken 9840 times.
✓ Branch 34 → 40 taken 2527 times.
|
12367 | if (ctx->F()) { |
| 331 |
3/6✓ Branch 35 → 36 taken 9840 times.
✗ Branch 35 → 63 not taken.
✓ Branch 36 → 37 taken 9840 times.
✗ Branch 36 → 63 not taken.
✓ Branch 37 → 38 taken 9840 times.
✗ Branch 37 → 61 not taken.
|
9840 | extDeclNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 332 | 9840 | extDeclNode->returnType->isReturnType = true; | |
| 333 | } | ||
| 334 |
2/2✓ Branch 41 → 42 taken 11605 times.
✓ Branch 41 → 47 taken 762 times.
|
12367 | if (ctx->typeLstWithEllipsis()) { |
| 335 | 11605 | extDeclNode->hasArgs = true; | |
| 336 |
3/6✓ Branch 42 → 43 taken 11605 times.
✗ Branch 42 → 66 not taken.
✓ Branch 43 → 44 taken 11605 times.
✗ Branch 43 → 66 not taken.
✓ Branch 44 → 45 taken 11605 times.
✗ Branch 44 → 64 not taken.
|
11605 | extDeclNode->argTypeLst = std::any_cast<TypeLstWithEllipsisNode *>(visit(ctx->typeLstWithEllipsis())); |
| 337 | } | ||
| 338 | |||
| 339 |
1/2✓ Branch 53 → 54 taken 12367 times.
✗ Branch 53 → 67 not taken.
|
24734 | return concludeNode(extDeclNode); |
| 340 | } | ||
| 341 | |||
| 342 | 9486 | std::any ASTBuilder::visitImportDef(SpiceParser::ImportDefContext *ctx) { | |
| 343 |
1/2✓ Branch 2 → 3 taken 9486 times.
✗ Branch 2 → 32 not taken.
|
9486 | const auto importDefNode = createNode<ImportDefNode>(ctx); |
| 344 | |||
| 345 | // Extract path | ||
| 346 |
2/4✓ Branch 3 → 4 taken 9486 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 9486 times.
✗ Branch 4 → 32 not taken.
|
9486 | const std::string pathStr = ctx->STRING_LIT()->getText(); |
| 347 |
1/2✓ Branch 6 → 7 taken 9486 times.
✗ Branch 6 → 27 not taken.
|
9486 | importDefNode->importPath = pathStr.substr(1, pathStr.size() - 2); |
| 348 | |||
| 349 | // If no name is given, use the path as name | ||
| 350 |
7/12✓ Branch 9 → 10 taken 9486 times.
✗ Branch 9 → 28 not taken.
✓ Branch 10 → 11 taken 290 times.
✓ Branch 10 → 13 taken 9196 times.
✓ Branch 11 → 12 taken 290 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 14 taken 290 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 9196 times.
✗ Branch 13 → 28 not taken.
✓ Branch 16 → 17 taken 9486 times.
✗ Branch 16 → 29 not taken.
|
9486 | importDefNode->importName = ctx->AS() ? getIdentifier(ctx->IDENTIFIER(), false) : importDefNode->importPath; |
| 351 | |||
| 352 |
1/2✓ Branch 22 → 23 taken 9486 times.
✗ Branch 22 → 29 not taken.
|
18972 | return concludeNode(importDefNode); |
| 353 | 9486 | } | |
| 354 | |||
| 355 | 19604 | std::any ASTBuilder::visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) { | |
| 356 | 19604 | const auto unsafeBlockDefNode = createNode<UnsafeBlockNode>(ctx); | |
| 357 | |||
| 358 | // Visit children | ||
| 359 |
4/8✓ Branch 3 → 4 taken 19604 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 19604 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 19604 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 19604 times.
✗ Branch 7 → 20 not taken.
|
19604 | unsafeBlockDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 360 | |||
| 361 |
1/2✓ Branch 13 → 14 taken 19604 times.
✗ Branch 13 → 20 not taken.
|
39208 | return concludeNode(unsafeBlockDefNode); |
| 362 | } | ||
| 363 | |||
| 364 | 7246 | std::any ASTBuilder::visitForLoop(SpiceParser::ForLoopContext *ctx) { | |
| 365 | 7246 | const auto forLoopNode = createNode<ForLoopNode>(ctx); | |
| 366 | |||
| 367 |
2/4✓ Branch 3 → 4 taken 7246 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 7246 times.
✗ Branch 4 → 20 not taken.
|
7246 | visit(ctx->forHead()); |
| 368 |
4/8✓ Branch 6 → 7 taken 7246 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 7246 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 7246 times.
✗ Branch 8 → 21 not taken.
✓ Branch 10 → 11 taken 7246 times.
✗ Branch 10 → 24 not taken.
|
7246 | forLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 369 | |||
| 370 |
1/2✓ Branch 16 → 17 taken 7246 times.
✗ Branch 16 → 24 not taken.
|
14492 | return concludeNode(forLoopNode); |
| 371 | } | ||
| 372 | |||
| 373 | 7246 | std::any ASTBuilder::visitForHead(SpiceParser::ForHeadContext *ctx) { | |
| 374 | 7246 | const auto forLoopNode = resumeForExpansion<ForLoopNode>(); | |
| 375 | |||
| 376 | // Visit children | ||
| 377 |
3/6✓ Branch 14 → 15 taken 7246 times.
✗ Branch 14 → 32 not taken.
✓ Branch 15 → 16 taken 7246 times.
✗ Branch 15 → 32 not taken.
✓ Branch 16 → 17 taken 7246 times.
✗ Branch 16 → 30 not taken.
|
7246 | forLoopNode->initDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt())); |
| 378 |
3/6✓ Branch 18 → 19 taken 7246 times.
✗ Branch 18 → 35 not taken.
✓ Branch 19 → 20 taken 7246 times.
✗ Branch 19 → 35 not taken.
✓ Branch 20 → 21 taken 7246 times.
✗ Branch 20 → 33 not taken.
|
7246 | forLoopNode->condAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(0))); |
| 379 |
3/6✓ Branch 22 → 23 taken 7246 times.
✗ Branch 22 → 38 not taken.
✓ Branch 23 → 24 taken 7246 times.
✗ Branch 23 → 38 not taken.
✓ Branch 24 → 25 taken 7246 times.
✗ Branch 24 → 36 not taken.
|
7246 | forLoopNode->incAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(1))); |
| 380 | |||
| 381 |
1/2✓ Branch 26 → 27 taken 7246 times.
✗ Branch 26 → 39 not taken.
|
14492 | return nullptr; |
| 382 | } | ||
| 383 | |||
| 384 | 1523 | std::any ASTBuilder::visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) { | |
| 385 | 1523 | const auto foreachLoopNode = createNode<ForeachLoopNode>(ctx); | |
| 386 | |||
| 387 | // Visit children | ||
| 388 |
2/4✓ Branch 3 → 4 taken 1523 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 1523 times.
✗ Branch 4 → 20 not taken.
|
1523 | visit(ctx->foreachHead()); |
| 389 |
3/6✓ Branch 6 → 7 taken 1523 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 1523 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 1523 times.
✗ Branch 8 → 21 not taken.
|
1523 | foreachLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 390 | |||
| 391 | // Tell the foreach item that it is one | ||
| 392 |
1/2✓ Branch 10 → 11 taken 1523 times.
✗ Branch 10 → 24 not taken.
|
1523 | foreachLoopNode->itemVarDecl->isForEachItem = true; |
| 393 | |||
| 394 |
1/2✓ Branch 16 → 17 taken 1523 times.
✗ Branch 16 → 24 not taken.
|
3046 | return concludeNode(foreachLoopNode); |
| 395 | } | ||
| 396 | |||
| 397 | 1523 | std::any ASTBuilder::visitForeachHead(SpiceParser::ForeachHeadContext *ctx) { | |
| 398 | 1523 | const auto foreachLoopNode = resumeForExpansion<ForeachLoopNode>(); | |
| 399 | |||
| 400 | // Visit children | ||
| 401 |
3/4✓ Branch 14 → 15 taken 1523 times.
✗ Branch 14 → 45 not taken.
✓ Branch 17 → 18 taken 1325 times.
✓ Branch 17 → 23 taken 198 times.
|
1523 | if (ctx->declStmt().size() == 1) { |
| 402 |
3/6✓ Branch 18 → 19 taken 1325 times.
✗ Branch 18 → 48 not taken.
✓ Branch 19 → 20 taken 1325 times.
✗ Branch 19 → 48 not taken.
✓ Branch 20 → 21 taken 1325 times.
✗ Branch 20 → 46 not taken.
|
1325 | foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0))); |
| 403 |
2/4✓ Branch 23 → 24 taken 198 times.
✗ Branch 23 → 49 not taken.
✓ Branch 26 → 27 taken 198 times.
✗ Branch 26 → 36 not taken.
|
198 | } else if (ctx->declStmt().size() == 2) { |
| 404 |
3/6✓ Branch 27 → 28 taken 198 times.
✗ Branch 27 → 52 not taken.
✓ Branch 28 → 29 taken 198 times.
✗ Branch 28 → 52 not taken.
✓ Branch 29 → 30 taken 198 times.
✗ Branch 29 → 50 not taken.
|
198 | foreachLoopNode->idxVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0))); |
| 405 |
3/6✓ Branch 31 → 32 taken 198 times.
✗ Branch 31 → 55 not taken.
✓ Branch 32 → 33 taken 198 times.
✗ Branch 32 → 55 not taken.
✓ Branch 33 → 34 taken 198 times.
✗ Branch 33 → 53 not taken.
|
198 | foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(1))); |
| 406 | } else { | ||
| 407 | − | assert_fail("Invalid number of decl statements in foreach loop"); // GCOV_EXCL_LINE | |
| 408 | } | ||
| 409 |
3/6✓ Branch 37 → 38 taken 1523 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 1523 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 1523 times.
✗ Branch 39 → 56 not taken.
|
1523 | foreachLoopNode->iteratorAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 410 | |||
| 411 |
1/2✓ Branch 41 → 42 taken 1523 times.
✗ Branch 41 → 59 not taken.
|
3046 | return nullptr; |
| 412 | } | ||
| 413 | |||
| 414 | 3655 | std::any ASTBuilder::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) { | |
| 415 | 3655 | const auto whileLoopNode = createNode<WhileLoopNode>(ctx); | |
| 416 | |||
| 417 | // Visit children | ||
| 418 |
3/6✓ Branch 3 → 4 taken 3655 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 3655 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 3655 times.
✗ Branch 5 → 21 not taken.
|
3655 | whileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 419 |
4/8✓ Branch 7 → 8 taken 3655 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 3655 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 3655 times.
✗ Branch 9 → 24 not taken.
✓ Branch 11 → 12 taken 3655 times.
✗ Branch 11 → 27 not taken.
|
3655 | whileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 420 | |||
| 421 |
1/2✓ Branch 17 → 18 taken 3655 times.
✗ Branch 17 → 27 not taken.
|
7310 | return concludeNode(whileLoopNode); |
| 422 | } | ||
| 423 | |||
| 424 | 43 | std::any ASTBuilder::visitDoWhileLoop(SpiceParser::DoWhileLoopContext *ctx) { | |
| 425 | 43 | const auto doWhileLoopNode = createNode<DoWhileLoopNode>(ctx); | |
| 426 | |||
| 427 | // Visit children | ||
| 428 |
3/6✓ Branch 3 → 4 taken 43 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 43 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 43 times.
✗ Branch 5 → 21 not taken.
|
43 | doWhileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 429 |
4/8✓ Branch 7 → 8 taken 43 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 43 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 43 times.
✗ Branch 9 → 24 not taken.
✓ Branch 11 → 12 taken 43 times.
✗ Branch 11 → 27 not taken.
|
43 | doWhileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 430 | |||
| 431 |
1/2✓ Branch 17 → 18 taken 43 times.
✗ Branch 17 → 27 not taken.
|
86 | return concludeNode(doWhileLoopNode); |
| 432 | } | ||
| 433 | |||
| 434 | 46180 | std::any ASTBuilder::visitIfStmt(SpiceParser::IfStmtContext *ctx) { | |
| 435 | 46180 | const auto ifStmtNode = createNode<IfStmtNode>(ctx); | |
| 436 | |||
| 437 | // Visit children | ||
| 438 |
3/6✓ Branch 3 → 4 taken 46180 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 46180 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 46180 times.
✗ Branch 5 → 28 not taken.
|
46180 | ifStmtNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 439 |
3/6✓ Branch 7 → 8 taken 46180 times.
✗ Branch 7 → 33 not taken.
✓ Branch 8 → 9 taken 46180 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 46180 times.
✗ Branch 9 → 31 not taken.
|
46180 | ifStmtNode->thenBody = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 440 |
2/2✓ Branch 12 → 13 taken 4529 times.
✓ Branch 12 → 18 taken 41651 times.
|
46180 | if (ctx->elseStmt()) |
| 441 |
3/6✓ Branch 13 → 14 taken 4529 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 4529 times.
✗ Branch 14 → 36 not taken.
✓ Branch 15 → 16 taken 4529 times.
✗ Branch 15 → 34 not taken.
|
4529 | ifStmtNode->elseStmt = std::any_cast<ElseStmtNode *>(visit(ctx->elseStmt())); |
| 442 | |||
| 443 |
1/2✓ Branch 24 → 25 taken 46180 times.
✗ Branch 24 → 37 not taken.
|
92360 | return concludeNode(ifStmtNode); |
| 444 | } | ||
| 445 | |||
| 446 | 4529 | std::any ASTBuilder::visitElseStmt(SpiceParser::ElseStmtContext *ctx) { | |
| 447 | 4529 | const auto elseStmtNode = createNode<ElseStmtNode>(ctx); | |
| 448 | |||
| 449 | // Visit children | ||
| 450 |
2/2✓ Branch 4 → 5 taken 2131 times.
✓ Branch 4 → 10 taken 2398 times.
|
4529 | if (ctx->ifStmt()) { |
| 451 | 2131 | elseStmtNode->isElseIf = true; | |
| 452 |
3/6✓ Branch 5 → 6 taken 2131 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 2131 times.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 2131 times.
✗ Branch 7 → 25 not taken.
|
2131 | elseStmtNode->ifStmt = std::any_cast<IfStmtNode *>(visit(ctx->ifStmt())); |
| 453 | } else { | ||
| 454 |
3/6✓ Branch 10 → 11 taken 2398 times.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 2398 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 2398 times.
✗ Branch 12 → 28 not taken.
|
2398 | elseStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 455 | } | ||
| 456 | |||
| 457 |
1/2✓ Branch 21 → 22 taken 4529 times.
✗ Branch 21 → 31 not taken.
|
9058 | return concludeNode(elseStmtNode); |
| 458 | } | ||
| 459 | |||
| 460 | 341 | std::any ASTBuilder::visitSwitchStmt(SpiceParser::SwitchStmtContext *ctx) { | |
| 461 | 341 | const auto switchStmtNode = createNode<SwitchStmtNode>(ctx); | |
| 462 | |||
| 463 | // Visit children | ||
| 464 |
3/6✓ Branch 3 → 4 taken 341 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 341 times.
✗ Branch 4 → 29 not taken.
✓ Branch 5 → 6 taken 341 times.
✗ Branch 5 → 27 not taken.
|
341 | switchStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 465 |
2/4✓ Branch 7 → 8 taken 341 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 341 times.
✗ Branch 8 → 30 not taken.
|
341 | fetchChildrenIntoVector(switchStmtNode->caseBranches, ctx->caseBranch()); |
| 466 |
2/2✓ Branch 11 → 12 taken 289 times.
✓ Branch 11 → 17 taken 52 times.
|
341 | if (ctx->defaultBranch()) { |
| 467 | 289 | switchStmtNode->hasDefaultBranch = true; | |
| 468 |
3/6✓ Branch 12 → 13 taken 289 times.
✗ Branch 12 → 35 not taken.
✓ Branch 13 → 14 taken 289 times.
✗ Branch 13 → 35 not taken.
✓ Branch 14 → 15 taken 289 times.
✗ Branch 14 → 33 not taken.
|
289 | switchStmtNode->defaultBranch = std::any_cast<DefaultBranchNode *>(visit(ctx->defaultBranch())); |
| 469 | } | ||
| 470 | |||
| 471 |
1/2✓ Branch 23 → 24 taken 341 times.
✗ Branch 23 → 36 not taken.
|
682 | return concludeNode(switchStmtNode); |
| 472 | } | ||
| 473 | |||
| 474 | 3255 | std::any ASTBuilder::visitCaseBranch(SpiceParser::CaseBranchContext *ctx) { | |
| 475 | 3255 | const auto caseBranchNode = createNode<CaseBranchNode>(ctx); | |
| 476 | |||
| 477 | // Visit children | ||
| 478 |
2/4✓ Branch 3 → 4 taken 3255 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 3255 times.
✗ Branch 4 → 20 not taken.
|
3255 | fetchChildrenIntoVector(caseBranchNode->caseConstants, ctx->caseConstant()); |
| 479 |
4/8✓ Branch 6 → 7 taken 3255 times.
✗ Branch 6 → 25 not taken.
✓ Branch 7 → 8 taken 3255 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 3255 times.
✗ Branch 8 → 23 not taken.
✓ Branch 10 → 11 taken 3255 times.
✗ Branch 10 → 26 not taken.
|
3255 | caseBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 480 | |||
| 481 |
1/2✓ Branch 16 → 17 taken 3255 times.
✗ Branch 16 → 26 not taken.
|
6510 | return concludeNode(caseBranchNode); |
| 482 | } | ||
| 483 | |||
| 484 | 289 | std::any ASTBuilder::visitDefaultBranch(SpiceParser::DefaultBranchContext *ctx) { | |
| 485 | 289 | const auto defaultBranchNode = createNode<DefaultBranchNode>(ctx); | |
| 486 | |||
| 487 | // Visit children | ||
| 488 |
4/8✓ Branch 3 → 4 taken 289 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 289 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 289 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 289 times.
✗ Branch 7 → 20 not taken.
|
289 | defaultBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 489 | |||
| 490 |
1/2✓ Branch 13 → 14 taken 289 times.
✗ Branch 13 → 20 not taken.
|
578 | return concludeNode(defaultBranchNode); |
| 491 | } | ||
| 492 | |||
| 493 | 141 | std::any ASTBuilder::visitAnonymousBlockStmt(SpiceParser::AnonymousBlockStmtContext *ctx) { | |
| 494 | 141 | const auto anonymousBlockStmtNode = createNode<AnonymousBlockStmtNode>(ctx); | |
| 495 | |||
| 496 | // Visit children | ||
| 497 |
4/8✓ Branch 3 → 4 taken 141 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 141 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 141 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 141 times.
✗ Branch 7 → 20 not taken.
|
141 | anonymousBlockStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 498 | |||
| 499 |
1/2✓ Branch 13 → 14 taken 141 times.
✗ Branch 13 → 20 not taken.
|
282 | return concludeNode(anonymousBlockStmtNode); |
| 500 | } | ||
| 501 | |||
| 502 | 187533 | std::any ASTBuilder::visitStmtLst(SpiceParser::StmtLstContext *ctx) { | |
| 503 | 187533 | const auto stmtLstNode = createNode<StmtLstNode>(ctx); | |
| 504 | |||
| 505 | // Enrich | ||
| 506 |
2/4✓ Branch 3 → 4 taken 187533 times.
✗ Branch 3 → 126 not taken.
✓ Branch 4 → 5 taken 187533 times.
✗ Branch 4 → 126 not taken.
|
187533 | stmtLstNode->closingBraceCodeLoc = CodeLoc(ctx->getStop(), sourceFile); |
| 507 | |||
| 508 | // Visit children | ||
| 509 |
2/2✓ Branch 115 → 7 taken 733245 times.
✓ Branch 115 → 116 taken 187525 times.
|
1108303 | for (ParserRuleContext::ParseTree *stmt : ctx->children) { |
| 510 |
3/4✓ Branch 9 → 10 taken 733245 times.
✗ Branch 9 → 11 not taken.
✓ Branch 12 → 13 taken 268396 times.
✓ Branch 12 → 18 taken 464849 times.
|
733245 | if (auto *stmtCtx = dynamic_cast<SpiceParser::StmtContext *>(stmt)) |
| 511 |
4/6✓ Branch 13 → 14 taken 268388 times.
✓ Branch 13 → 129 taken 8 times.
✓ Branch 14 → 15 taken 268388 times.
✗ Branch 14 → 127 not taken.
✓ Branch 15 → 16 taken 268388 times.
✗ Branch 15 → 127 not taken.
|
268396 | stmtLstNode->statements.push_back(std::any_cast<StmtNode *>(visit(stmtCtx))); |
| 512 |
3/4✓ Branch 18 → 19 taken 464849 times.
✗ Branch 18 → 20 not taken.
✓ Branch 21 → 22 taken 7246 times.
✓ Branch 21 → 27 taken 457603 times.
|
464849 | else if (auto *forLoopCtx = dynamic_cast<SpiceParser::ForLoopContext *>(stmt)) |
| 513 |
3/6✓ Branch 22 → 23 taken 7246 times.
✗ Branch 22 → 133 not taken.
✓ Branch 23 → 24 taken 7246 times.
✗ Branch 23 → 131 not taken.
✓ Branch 24 → 25 taken 7246 times.
✗ Branch 24 → 131 not taken.
|
7246 | stmtLstNode->statements.push_back(std::any_cast<ForLoopNode *>(visit(forLoopCtx))); |
| 514 |
3/4✓ Branch 27 → 28 taken 457603 times.
✗ Branch 27 → 29 not taken.
✓ Branch 30 → 31 taken 1523 times.
✓ Branch 30 → 36 taken 456080 times.
|
457603 | else if (auto *foreachLoopCtx = dynamic_cast<SpiceParser::ForeachLoopContext *>(stmt)) |
| 515 |
3/6✓ Branch 31 → 32 taken 1523 times.
✗ Branch 31 → 137 not taken.
✓ Branch 32 → 33 taken 1523 times.
✗ Branch 32 → 135 not taken.
✓ Branch 33 → 34 taken 1523 times.
✗ Branch 33 → 135 not taken.
|
1523 | stmtLstNode->statements.push_back(std::any_cast<ForeachLoopNode *>(visit(foreachLoopCtx))); |
| 516 |
3/4✓ Branch 36 → 37 taken 456080 times.
✗ Branch 36 → 38 not taken.
✓ Branch 39 → 40 taken 3655 times.
✓ Branch 39 → 45 taken 452425 times.
|
456080 | else if (auto *whileLoopCtx = dynamic_cast<SpiceParser::WhileLoopContext *>(stmt)) |
| 517 |
3/6✓ Branch 40 → 41 taken 3655 times.
✗ Branch 40 → 141 not taken.
✓ Branch 41 → 42 taken 3655 times.
✗ Branch 41 → 139 not taken.
✓ Branch 42 → 43 taken 3655 times.
✗ Branch 42 → 139 not taken.
|
3655 | stmtLstNode->statements.push_back(std::any_cast<WhileLoopNode *>(visit(whileLoopCtx))); |
| 518 |
3/4✓ Branch 45 → 46 taken 452425 times.
✗ Branch 45 → 47 not taken.
✓ Branch 48 → 49 taken 43 times.
✓ Branch 48 → 54 taken 452382 times.
|
452425 | else if (auto *doWhileLoopCtx = dynamic_cast<SpiceParser::DoWhileLoopContext *>(stmt)) |
| 519 |
3/6✓ Branch 49 → 50 taken 43 times.
✗ Branch 49 → 145 not taken.
✓ Branch 50 → 51 taken 43 times.
✗ Branch 50 → 143 not taken.
✓ Branch 51 → 52 taken 43 times.
✗ Branch 51 → 143 not taken.
|
43 | stmtLstNode->statements.push_back(std::any_cast<DoWhileLoopNode *>(visit(doWhileLoopCtx))); |
| 520 |
3/4✓ Branch 54 → 55 taken 452382 times.
✗ Branch 54 → 56 not taken.
✓ Branch 57 → 58 taken 44049 times.
✓ Branch 57 → 63 taken 408333 times.
|
452382 | else if (auto *ifStmtCtx = dynamic_cast<SpiceParser::IfStmtContext *>(stmt)) |
| 521 |
3/6✓ Branch 58 → 59 taken 44049 times.
✗ Branch 58 → 149 not taken.
✓ Branch 59 → 60 taken 44049 times.
✗ Branch 59 → 147 not taken.
✓ Branch 60 → 61 taken 44049 times.
✗ Branch 60 → 147 not taken.
|
44049 | stmtLstNode->statements.push_back(std::any_cast<IfStmtNode *>(visit(ifStmtCtx))); |
| 522 |
3/4✓ Branch 63 → 64 taken 408333 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 341 times.
✓ Branch 66 → 72 taken 407992 times.
|
408333 | else if (auto *switchStmtCtx = dynamic_cast<SpiceParser::SwitchStmtContext *>(stmt)) |
| 523 |
3/6✓ Branch 67 → 68 taken 341 times.
✗ Branch 67 → 153 not taken.
✓ Branch 68 → 69 taken 341 times.
✗ Branch 68 → 151 not taken.
✓ Branch 69 → 70 taken 341 times.
✗ Branch 69 → 151 not taken.
|
341 | stmtLstNode->statements.push_back(std::any_cast<SwitchStmtNode *>(visit(switchStmtCtx))); |
| 524 |
3/4✓ Branch 72 → 73 taken 407992 times.
✗ Branch 72 → 74 not taken.
✓ Branch 75 → 76 taken 13189 times.
✓ Branch 75 → 81 taken 394803 times.
|
407992 | else if (auto *assetStmtCtx = dynamic_cast<SpiceParser::AssertStmtContext *>(stmt)) |
| 525 |
3/6✓ Branch 76 → 77 taken 13189 times.
✗ Branch 76 → 157 not taken.
✓ Branch 77 → 78 taken 13189 times.
✗ Branch 77 → 155 not taken.
✓ Branch 78 → 79 taken 13189 times.
✗ Branch 78 → 155 not taken.
|
13189 | stmtLstNode->statements.push_back(std::any_cast<AssertStmtNode *>(visit(assetStmtCtx))); |
| 526 |
3/4✓ Branch 81 → 82 taken 394803 times.
✗ Branch 81 → 83 not taken.
✓ Branch 84 → 85 taken 19604 times.
✓ Branch 84 → 90 taken 375199 times.
|
394803 | else if (auto *unsafeBlockCtx = dynamic_cast<SpiceParser::UnsafeBlockContext *>(stmt)) |
| 527 |
3/6✓ Branch 85 → 86 taken 19604 times.
✗ Branch 85 → 161 not taken.
✓ Branch 86 → 87 taken 19604 times.
✗ Branch 86 → 159 not taken.
✓ Branch 87 → 88 taken 19604 times.
✗ Branch 87 → 159 not taken.
|
19604 | stmtLstNode->statements.push_back(std::any_cast<UnsafeBlockNode *>(visit(unsafeBlockCtx))); |
| 528 |
3/4✓ Branch 90 → 91 taken 375199 times.
✗ Branch 90 → 92 not taken.
✓ Branch 93 → 94 taken 141 times.
✓ Branch 93 → 99 taken 375058 times.
|
375199 | else if (auto *anonymousScopeCtx = dynamic_cast<SpiceParser::AnonymousBlockStmtContext *>(stmt)) |
| 529 |
3/6✓ Branch 94 → 95 taken 141 times.
✗ Branch 94 → 165 not taken.
✓ Branch 95 → 96 taken 141 times.
✗ Branch 95 → 163 not taken.
✓ Branch 96 → 97 taken 141 times.
✗ Branch 96 → 163 not taken.
|
141 | stmtLstNode->statements.push_back(std::any_cast<AnonymousBlockStmtNode *>(visit(anonymousScopeCtx))); |
| 530 | else | ||
| 531 | − | assert(is<TerminalNode *>(stmt)); // GCOV_EXCL_LINE | |
| 532 | } | ||
| 533 | |||
| 534 |
1/2✓ Branch 122 → 123 taken 187525 times.
✗ Branch 122 → 168 not taken.
|
375050 | return concludeNode(stmtLstNode); |
| 535 | } | ||
| 536 | |||
| 537 | 68003 | std::any ASTBuilder::visitTypeLst(SpiceParser::TypeLstContext *ctx) { | |
| 538 | 68003 | const auto typeLstNode = createNode<TypeLstNode>(ctx); | |
| 539 | |||
| 540 | // Visit children | ||
| 541 |
3/6✓ Branch 3 → 4 taken 68003 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 68003 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 68003 times.
✗ Branch 6 → 19 not taken.
|
68003 | fetchChildrenIntoVector(typeLstNode->dataTypes, ctx->dataType()); |
| 542 | |||
| 543 |
1/2✓ Branch 12 → 13 taken 68003 times.
✗ Branch 12 → 19 not taken.
|
136006 | return concludeNode(typeLstNode); |
| 544 | } | ||
| 545 | |||
| 546 | 11605 | std::any ASTBuilder::visitTypeLstWithEllipsis(SpiceParser::TypeLstWithEllipsisContext *ctx) { | |
| 547 | 11605 | const auto typeLstWithEllipsisNode = createNode<TypeLstWithEllipsisNode>(ctx); | |
| 548 | |||
| 549 | // Visit children | ||
| 550 |
3/6✓ Branch 3 → 4 taken 11605 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 11605 times.
✗ Branch 4 → 20 not taken.
✓ Branch 5 → 6 taken 11605 times.
✗ Branch 5 → 18 not taken.
|
11605 | typeLstWithEllipsisNode->typeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 551 | |||
| 552 | // Set some flags | ||
| 553 |
1/2✓ Branch 8 → 9 taken 11605 times.
✗ Branch 8 → 21 not taken.
|
11605 | typeLstWithEllipsisNode->hasEllipsis = ctx->ELLIPSIS() != nullptr; |
| 554 | |||
| 555 |
1/2✓ Branch 14 → 15 taken 11605 times.
✗ Branch 14 → 21 not taken.
|
23210 | return concludeNode(typeLstWithEllipsisNode); |
| 556 | } | ||
| 557 | |||
| 558 | 5141 | std::any ASTBuilder::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ctx) { | |
| 559 | 5141 | const auto typeAltsLstNode = createNode<TypeAltsLstNode>(ctx); | |
| 560 | |||
| 561 | // Visit children | ||
| 562 |
3/6✓ Branch 3 → 4 taken 5141 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 5141 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 5141 times.
✗ Branch 6 → 19 not taken.
|
5141 | fetchChildrenIntoVector(typeAltsLstNode->dataTypes, ctx->dataType()); |
| 563 | |||
| 564 |
1/2✓ Branch 12 → 13 taken 5141 times.
✗ Branch 12 → 19 not taken.
|
10282 | return concludeNode(typeAltsLstNode); |
| 565 | } | ||
| 566 | |||
| 567 | 70426 | std::any ASTBuilder::visitParamLst(SpiceParser::ParamLstContext *ctx) { | |
| 568 | 70426 | const auto paramLstNode = createNode<ParamLstNode>(ctx); | |
| 569 | |||
| 570 | // Visit children | ||
| 571 |
2/4✓ Branch 3 → 4 taken 70426 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 70426 times.
✗ Branch 4 → 30 not taken.
|
70426 | fetchChildrenIntoVector(paramLstNode->params, ctx->declStmt()); |
| 572 | |||
| 573 | // Set some flags to later detect that the decl statements are parameters | ||
| 574 |
2/2✓ Branch 19 → 8 taken 108609 times.
✓ Branch 19 → 20 taken 70426 times.
|
249461 | for (DeclStmtNode *declStmt : paramLstNode->params) { |
| 575 | 108609 | declStmt->isFctParam = true; | |
| 576 | 108609 | declStmt->dataType->isParamType = true; | |
| 577 | } | ||
| 578 | |||
| 579 |
1/2✓ Branch 26 → 27 taken 70426 times.
✗ Branch 26 → 33 not taken.
|
140852 | return concludeNode(paramLstNode); |
| 580 | } | ||
| 581 | |||
| 582 | 134754 | std::any ASTBuilder::visitArgLst(SpiceParser::ArgLstContext *ctx) { | |
| 583 | 134754 | const auto argLstNode = createNode<ArgLstNode>(ctx); | |
| 584 | |||
| 585 | // Visit children | ||
| 586 |
2/4✓ Branch 3 → 4 taken 134754 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 134754 times.
✗ Branch 4 → 18 not taken.
|
134754 | fetchChildrenIntoVector(argLstNode->args, ctx->assignExpr()); |
| 587 | 134754 | argLstNode->argInfos.reserve(argLstNode->args.size()); | |
| 588 | |||
| 589 |
1/2✓ Branch 14 → 15 taken 134754 times.
✗ Branch 14 → 21 not taken.
|
269508 | return concludeNode(argLstNode); |
| 590 | } | ||
| 591 | |||
| 592 | 1970 | std::any ASTBuilder::visitEnumItemLst(SpiceParser::EnumItemLstContext *ctx) { | |
| 593 | 1970 | const auto enumItemLstNode = createNode<EnumItemLstNode>(ctx); | |
| 594 | |||
| 595 | // Visit children | ||
| 596 |
3/6✓ Branch 3 → 4 taken 1970 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 1970 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 1970 times.
✗ Branch 6 → 19 not taken.
|
1970 | fetchChildrenIntoVector(enumItemLstNode->items, ctx->enumItem()); |
| 597 | |||
| 598 |
1/2✓ Branch 12 → 13 taken 1970 times.
✗ Branch 12 → 19 not taken.
|
3940 | return concludeNode(enumItemLstNode); |
| 599 | } | ||
| 600 | |||
| 601 | 19416 | std::any ASTBuilder::visitEnumItem(SpiceParser::EnumItemContext *ctx) { | |
| 602 | 19416 | const auto enumItemNode = createNode<EnumItemNode>(ctx); | |
| 603 | |||
| 604 | // Enrich | ||
| 605 |
2/4✓ Branch 3 → 4 taken 19416 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 19416 times.
✗ Branch 4 → 22 not taken.
|
19416 | enumItemNode->itemName = getIdentifier(ctx->TYPE_IDENTIFIER(), false); |
| 606 |
2/2✓ Branch 8 → 9 taken 9908 times.
✓ Branch 8 → 12 taken 9508 times.
|
19416 | if (ctx->ASSIGN()) { |
| 607 | 9908 | enumItemNode->itemValue = parseInt(ctx->INT_LIT()); | |
| 608 | 9908 | enumItemNode->hasValue = true; | |
| 609 | } | ||
| 610 | |||
| 611 |
1/2✓ Branch 18 → 19 taken 19416 times.
✗ Branch 18 → 23 not taken.
|
38832 | return concludeNode(enumItemNode); |
| 612 | } | ||
| 613 | |||
| 614 | 26822 | std::any ASTBuilder::visitField(SpiceParser::FieldContext *ctx) { | |
| 615 | 26822 | const auto fieldNode = createNode<FieldNode>(ctx); | |
| 616 | |||
| 617 | // Enrich | ||
| 618 |
2/4✓ Branch 3 → 4 taken 26822 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 26822 times.
✗ Branch 4 → 29 not taken.
|
26822 | fieldNode->fieldName = getIdentifier(ctx->IDENTIFIER(), false); |
| 619 | |||
| 620 | // Visit children | ||
| 621 |
3/6✓ Branch 7 → 8 taken 26822 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 26822 times.
✗ Branch 8 → 32 not taken.
✓ Branch 9 → 10 taken 26822 times.
✗ Branch 9 → 30 not taken.
|
26822 | fieldNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 622 | 26822 | fieldNode->dataType->setFieldTypeRecursive(); | |
| 623 |
2/2✓ Branch 13 → 14 taken 9555 times.
✓ Branch 13 → 19 taken 17267 times.
|
26822 | if (ctx->ternaryExpr()) |
| 624 |
3/6✓ Branch 14 → 15 taken 9555 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 9555 times.
✗ Branch 15 → 35 not taken.
✓ Branch 16 → 17 taken 9555 times.
✗ Branch 16 → 33 not taken.
|
9555 | fieldNode->defaultValue = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr())); |
| 625 | |||
| 626 |
1/2✓ Branch 25 → 26 taken 26822 times.
✗ Branch 25 → 36 not taken.
|
53644 | return concludeNode(fieldNode); |
| 627 | } | ||
| 628 | |||
| 629 | 7527 | std::any ASTBuilder::visitSignature(SpiceParser::SignatureContext *ctx) { | |
| 630 | 7527 | const auto signatureNode = createNode<SignatureNode>(ctx); | |
| 631 | |||
| 632 | // Extract method name | ||
| 633 |
2/4✓ Branch 3 → 4 taken 7527 times.
✗ Branch 3 → 73 not taken.
✓ Branch 4 → 5 taken 7527 times.
✗ Branch 4 → 73 not taken.
|
7527 | signatureNode->methodName = getIdentifier(ctx->IDENTIFIER(), false); |
| 634 | |||
| 635 | // Visit children | ||
| 636 |
2/2✓ Branch 8 → 9 taken 7443 times.
✓ Branch 8 → 14 taken 84 times.
|
7527 | if (ctx->qualifierLst()) { |
| 637 |
3/6✓ Branch 9 → 10 taken 7443 times.
✗ Branch 9 → 76 not taken.
✓ Branch 10 → 11 taken 7443 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 7443 times.
✗ Branch 11 → 74 not taken.
|
7443 | signatureNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 638 | } | ||
| 639 |
2/2✓ Branch 15 → 16 taken 6851 times.
✓ Branch 15 → 22 taken 676 times.
|
7527 | if (ctx->F()) { |
| 640 | 6851 | signatureNode->hasReturnType = true; | |
| 641 | 6851 | signatureNode->signatureType = SignatureNode::SignatureType::TYPE_FUNCTION; | |
| 642 | 6851 | signatureNode->signatureQualifiers = TypeQualifiers::of(TY_FUNCTION); | |
| 643 |
3/6✓ Branch 17 → 18 taken 6851 times.
✗ Branch 17 → 79 not taken.
✓ Branch 18 → 19 taken 6851 times.
✗ Branch 18 → 79 not taken.
✓ Branch 19 → 20 taken 6851 times.
✗ Branch 19 → 77 not taken.
|
6851 | signatureNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 644 | } else { | ||
| 645 | 676 | signatureNode->signatureType = SignatureNode::SignatureType::TYPE_PROCEDURE; | |
| 646 | 676 | signatureNode->signatureQualifiers = TypeQualifiers::of(TY_PROCEDURE); | |
| 647 | } | ||
| 648 |
10/16✓ Branch 24 → 25 taken 6851 times.
✓ Branch 24 → 28 taken 676 times.
✓ Branch 25 → 26 taken 6851 times.
✗ Branch 25 → 80 not taken.
✓ Branch 28 → 29 taken 676 times.
✗ Branch 28 → 80 not taken.
✓ Branch 31 → 32 taken 676 times.
✓ Branch 31 → 33 taken 6851 times.
✓ Branch 33 → 34 taken 6851 times.
✓ Branch 33 → 35 taken 676 times.
✓ Branch 35 → 36 taken 614 times.
✓ Branch 35 → 41 taken 6913 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
|
7527 | if (ctx->F() ? ctx->LESS().size() == 2 : ctx->LESS().size() == 1) { |
| 649 | 614 | signatureNode->hasTemplateTypes = true; | |
| 650 |
3/6✓ Branch 36 → 37 taken 614 times.
✗ Branch 36 → 90 not taken.
✓ Branch 37 → 38 taken 614 times.
✗ Branch 37 → 90 not taken.
✓ Branch 38 → 39 taken 614 times.
✗ Branch 38 → 88 not taken.
|
614 | signatureNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0))); |
| 651 | } | ||
| 652 |
13/20✓ Branch 41 → 42 taken 7527 times.
✗ Branch 41 → 91 not taken.
✓ Branch 43 → 44 taken 7523 times.
✓ Branch 43 → 48 taken 4 times.
✓ Branch 44 → 45 taken 7523 times.
✗ Branch 44 → 91 not taken.
✓ Branch 46 → 47 taken 5256 times.
✓ Branch 46 → 49 taken 2267 times.
✓ Branch 47 → 48 taken 4646 times.
✓ Branch 47 → 49 taken 610 times.
✓ Branch 50 → 51 taken 7523 times.
✓ Branch 50 → 52 taken 4 times.
✓ Branch 52 → 53 taken 7527 times.
✗ Branch 52 → 54 not taken.
✓ Branch 54 → 55 taken 4650 times.
✓ Branch 54 → 63 taken 2877 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
|
7527 | if (ctx->typeLst().size() == 2 || (ctx->typeLst().size() == 1 && !signatureNode->hasTemplateTypes)) { |
| 653 | 4650 | signatureNode->hasParams = true; | |
| 654 |
5/8✓ Branch 55 → 56 taken 4 times.
✓ Branch 55 → 57 taken 4646 times.
✓ Branch 58 → 59 taken 4650 times.
✗ Branch 58 → 101 not taken.
✓ Branch 59 → 60 taken 4650 times.
✗ Branch 59 → 101 not taken.
✓ Branch 60 → 61 taken 4650 times.
✗ Branch 60 → 99 not taken.
|
4650 | signatureNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(signatureNode->hasTemplateTypes ? 1 : 0))); |
| 655 | } | ||
| 656 | |||
| 657 |
1/2✓ Branch 69 → 70 taken 7527 times.
✗ Branch 69 → 102 not taken.
|
15054 | return concludeNode(signatureNode); |
| 658 | } | ||
| 659 | |||
| 660 | 268396 | std::any ASTBuilder::visitStmt(SpiceParser::StmtContext *ctx) { | |
| 661 |
2/2✓ Branch 3 → 4 taken 51748 times.
✓ Branch 3 → 11 taken 216648 times.
|
268396 | if (ctx->declStmt()) |
| 662 |
5/8✓ Branch 4 → 5 taken 51748 times.
✗ Branch 4 → 60 not taken.
✓ Branch 5 → 6 taken 51740 times.
✓ Branch 5 → 60 taken 8 times.
✓ Branch 6 → 7 taken 51740 times.
✗ Branch 6 → 58 not taken.
✓ Branch 7 → 8 taken 51740 times.
✗ Branch 7 → 58 not taken.
|
103488 | return static_cast<StmtNode *>(std::any_cast<DeclStmtNode *>(visit(ctx->declStmt()))); |
| 663 |
2/2✓ Branch 12 → 13 taken 125313 times.
✓ Branch 12 → 20 taken 91335 times.
|
216648 | if (ctx->exprStmt()) |
| 664 |
4/8✓ Branch 13 → 14 taken 125313 times.
✗ Branch 13 → 64 not taken.
✓ Branch 14 → 15 taken 125313 times.
✗ Branch 14 → 64 not taken.
✓ Branch 15 → 16 taken 125313 times.
✗ Branch 15 → 62 not taken.
✓ Branch 16 → 17 taken 125313 times.
✗ Branch 16 → 62 not taken.
|
250626 | return static_cast<StmtNode *>(std::any_cast<ExprStmtNode *>(visit(ctx->exprStmt()))); |
| 665 |
2/2✓ Branch 21 → 22 taken 88847 times.
✓ Branch 21 → 29 taken 2488 times.
|
91335 | if (ctx->returnStmt()) |
| 666 |
4/8✓ Branch 22 → 23 taken 88847 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 88847 times.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 88847 times.
✗ Branch 24 → 66 not taken.
✓ Branch 25 → 26 taken 88847 times.
✗ Branch 25 → 66 not taken.
|
177694 | return static_cast<StmtNode *>(std::any_cast<ReturnStmtNode *>(visit(ctx->returnStmt()))); |
| 667 |
2/2✓ Branch 30 → 31 taken 1264 times.
✓ Branch 30 → 38 taken 1224 times.
|
2488 | if (ctx->breakStmt()) |
| 668 |
4/8✓ Branch 31 → 32 taken 1264 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 1264 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 1264 times.
✗ Branch 33 → 70 not taken.
✓ Branch 34 → 35 taken 1264 times.
✗ Branch 34 → 70 not taken.
|
2528 | return static_cast<StmtNode *>(std::any_cast<BreakStmtNode *>(visit(ctx->breakStmt()))); |
| 669 |
2/2✓ Branch 39 → 40 taken 1212 times.
✓ Branch 39 → 47 taken 12 times.
|
1224 | if (ctx->continueStmt()) |
| 670 |
4/8✓ Branch 40 → 41 taken 1212 times.
✗ Branch 40 → 76 not taken.
✓ Branch 41 → 42 taken 1212 times.
✗ Branch 41 → 76 not taken.
✓ Branch 42 → 43 taken 1212 times.
✗ Branch 42 → 74 not taken.
✓ Branch 43 → 44 taken 1212 times.
✗ Branch 43 → 74 not taken.
|
2424 | return static_cast<StmtNode *>(std::any_cast<ContinueStmtNode *>(visit(ctx->continueStmt()))); |
| 671 |
1/2✓ Branch 48 → 49 taken 12 times.
✗ Branch 48 → 56 not taken.
|
12 | if (ctx->fallthroughStmt()) |
| 672 |
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()))); |
| 673 | − | assert_fail("Unknown statement type"); // GCOV_EXCL_LINE | |
| 674 | return nullptr; // GCOV_EXCL_LINE | ||
| 675 | } | ||
| 676 | |||
| 677 | 169324 | std::any ASTBuilder::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) { | |
| 678 | 169324 | const auto declStmtNode = createNode<DeclStmtNode>(ctx); | |
| 679 | |||
| 680 | // Enrich | ||
| 681 |
3/4✓ Branch 3 → 4 taken 169324 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 169322 times.
✓ Branch 4 → 28 taken 2 times.
|
169324 | declStmtNode->varName = getIdentifier(ctx->IDENTIFIER(), false); |
| 682 | |||
| 683 | // Visit children | ||
| 684 |
4/6✓ Branch 7 → 8 taken 169322 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 169320 times.
✓ Branch 8 → 31 taken 2 times.
✓ Branch 9 → 10 taken 169320 times.
✗ Branch 9 → 29 not taken.
|
169322 | declStmtNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 685 |
2/2✓ Branch 12 → 13 taken 62725 times.
✓ Branch 12 → 18 taken 106595 times.
|
169320 | if (ctx->assignExpr()) { |
| 686 | 62725 | declStmtNode->hasAssignment = true; | |
| 687 |
4/6✓ Branch 13 → 14 taken 62725 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 62721 times.
✓ Branch 14 → 34 taken 4 times.
✓ Branch 15 → 16 taken 62721 times.
✗ Branch 15 → 32 not taken.
|
62725 | declStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 688 | } | ||
| 689 | |||
| 690 |
1/2✓ Branch 24 → 25 taken 169316 times.
✗ Branch 24 → 35 not taken.
|
338632 | return concludeNode(declStmtNode); |
| 691 | } | ||
| 692 | |||
| 693 | 125313 | std::any ASTBuilder::visitExprStmt(SpiceParser::ExprStmtContext *ctx) { | |
| 694 | 125313 | const auto exprStmtNode = createNode<ExprStmtNode>(ctx); | |
| 695 | |||
| 696 | // Enrich | ||
| 697 |
4/8✓ Branch 3 → 4 taken 125313 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 125313 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 125313 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 125313 times.
✗ Branch 7 → 20 not taken.
|
125313 | exprStmtNode->expr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 698 | |||
| 699 |
1/2✓ Branch 13 → 14 taken 125313 times.
✗ Branch 13 → 20 not taken.
|
250626 | return concludeNode(exprStmtNode); |
| 700 | } | ||
| 701 | |||
| 702 | 273263 | std::any ASTBuilder::visitQualifierLst(SpiceParser::QualifierLstContext *ctx) { | |
| 703 | 273263 | const auto qualifierLstNode = createNode<QualifierLstNode>(ctx); | |
| 704 | |||
| 705 | // Visit children | ||
| 706 |
2/4✓ Branch 3 → 4 taken 273263 times.
✗ Branch 3 → 45 not taken.
✓ Branch 4 → 5 taken 273263 times.
✗ Branch 4 → 43 not taken.
|
273263 | fetchChildrenIntoVector(qualifierLstNode->qualifiers, ctx->qualifier()); |
| 707 | |||
| 708 | // Check if qualifier combination is invalid | ||
| 709 | 273263 | bool seenSignedOrUnsigned = false; | |
| 710 |
2/2✓ Branch 32 → 8 taken 322068 times.
✓ Branch 32 → 33 taken 273261 times.
|
868592 | for (const QualifierNode *qualifier : qualifierLstNode->qualifiers) { |
| 711 | // Check if we have both, signed and unsigned qualifier | ||
| 712 |
2/2✓ Branch 10 → 11 taken 322054 times.
✓ Branch 10 → 13 taken 14 times.
|
322068 | if (qualifier->type != QualifierNode::QualifierType::TY_SIGNED && |
| 713 |
2/2✓ Branch 11 → 12 taken 259190 times.
✓ Branch 11 → 13 taken 62864 times.
|
322054 | qualifier->type != QualifierNode::QualifierType::TY_UNSIGNED) |
| 714 | 259190 | continue; | |
| 715 |
2/2✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 22 taken 62876 times.
|
62878 | if (seenSignedOrUnsigned) |
| 716 |
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"); |
| 717 | 62876 | seenSignedOrUnsigned = true; | |
| 718 | } | ||
| 719 | |||
| 720 |
1/2✓ Branch 39 → 40 taken 273261 times.
✗ Branch 39 → 56 not taken.
|
546522 | return concludeNode(qualifierLstNode); |
| 721 | } | ||
| 722 | |||
| 723 | 322068 | std::any ASTBuilder::visitQualifier(SpiceParser::QualifierContext *ctx) { | |
| 724 | 322068 | const auto qualifierNode = createNode<QualifierNode>(ctx); | |
| 725 | |||
| 726 |
3/4✓ Branch 7 → 8 taken 322068 times.
✗ Branch 7 → 9 not taken.
✓ Branch 42 → 5 taken 322068 times.
✓ Branch 42 → 43 taken 322068 times.
|
1288272 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 727 | 322068 | const auto token = spice_pointer_cast<TerminalNode *>(subTree); | |
| 728 |
2/4✓ Branch 16 → 17 taken 322068 times.
✗ Branch 16 → 53 not taken.
✓ Branch 17 → 18 taken 322068 times.
✗ Branch 17 → 53 not taken.
|
322068 | const size_t symbolType = token->getSymbol()->getType(); |
| 729 |
2/2✓ Branch 18 → 19 taken 75163 times.
✓ Branch 18 → 20 taken 246905 times.
|
322068 | if (symbolType == SpiceParser::CONST) |
| 730 | 75163 | qualifierNode->type = QualifierNode::QualifierType::TY_CONST; | |
| 731 |
2/2✓ Branch 20 → 21 taken 14 times.
✓ Branch 20 → 22 taken 246891 times.
|
246905 | else if (symbolType == SpiceParser::SIGNED) |
| 732 | 14 | qualifierNode->type = QualifierNode::QualifierType::TY_SIGNED; | |
| 733 |
2/2✓ Branch 22 → 23 taken 62864 times.
✓ Branch 22 → 24 taken 184027 times.
|
246891 | else if (symbolType == SpiceParser::UNSIGNED) |
| 734 | 62864 | qualifierNode->type = QualifierNode::QualifierType::TY_UNSIGNED; | |
| 735 |
2/2✓ Branch 24 → 25 taken 22080 times.
✓ Branch 24 → 26 taken 161947 times.
|
184027 | else if (symbolType == SpiceParser::INLINE) |
| 736 | 22080 | qualifierNode->type = QualifierNode::QualifierType::TY_INLINE; | |
| 737 |
2/2✓ Branch 26 → 27 taken 130175 times.
✓ Branch 26 → 28 taken 31772 times.
|
161947 | else if (symbolType == SpiceParser::PUBLIC) |
| 738 | 130175 | qualifierNode->type = QualifierNode::QualifierType::TY_PUBLIC; | |
| 739 |
2/2✓ Branch 28 → 29 taken 28368 times.
✓ Branch 28 → 30 taken 3404 times.
|
31772 | else if (symbolType == SpiceParser::HEAP) |
| 740 | 28368 | qualifierNode->type = QualifierNode::QualifierType::TY_HEAP; | |
| 741 |
1/2✓ Branch 30 → 31 taken 3404 times.
✗ Branch 30 → 32 not taken.
|
3404 | else if (symbolType == SpiceParser::COMPOSE) |
| 742 | 3404 | qualifierNode->type = QualifierNode::QualifierType::TY_COMPOSITION; | |
| 743 | else | ||
| 744 | − | assert_fail("Unknown qualifier type"); // GCOV_EXCL_LINE | |
| 745 | } | ||
| 746 | |||
| 747 |
1/2✓ Branch 49 → 50 taken 322068 times.
✗ Branch 49 → 54 not taken.
|
644136 | return concludeNode(qualifierNode); |
| 748 | } | ||
| 749 | |||
| 750 | 2338 | std::any ASTBuilder::visitModAttr(SpiceParser::ModAttrContext *ctx) { | |
| 751 | 2338 | const auto modAttrNode = createNode<ModAttrNode>(ctx); | |
| 752 | |||
| 753 | // Visit children | ||
| 754 |
4/6✓ Branch 3 → 4 taken 2338 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 2336 times.
✓ Branch 4 → 33 taken 2 times.
✓ Branch 5 → 6 taken 2336 times.
✗ Branch 5 → 31 not taken.
|
2338 | modAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst())); |
| 755 | |||
| 756 | // Tell the attributes that they are module attributes | ||
| 757 |
2/2✓ Branch 20 → 9 taken 8568 times.
✓ Branch 20 → 21 taken 2336 times.
|
13240 | for (AttrNode *attr : modAttrNode->attrLst->attributes) |
| 758 | 8568 | attr->target = AttrNode::TARGET_MODULE; | |
| 759 | |||
| 760 |
1/2✓ Branch 27 → 28 taken 2336 times.
✗ Branch 27 → 34 not taken.
|
4672 | return concludeNode(modAttrNode); |
| 761 | } | ||
| 762 | |||
| 763 | 2698 | std::any ASTBuilder::visitTopLevelDefAttr(SpiceParser::TopLevelDefAttrContext *ctx) { | |
| 764 | 2698 | const auto fctAttrNode = createNode<TopLevelDefAttrNode>(ctx); | |
| 765 | |||
| 766 | // Visit children | ||
| 767 |
4/8✓ Branch 3 → 4 taken 2698 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 2698 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 2698 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 2698 times.
✗ Branch 7 → 20 not taken.
|
2698 | fctAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst())); |
| 768 | |||
| 769 |
1/2✓ Branch 13 → 14 taken 2698 times.
✗ Branch 13 → 20 not taken.
|
5396 | return concludeNode(fctAttrNode); |
| 770 | } | ||
| 771 | |||
| 772 | 16 | std::any ASTBuilder::visitLambdaAttr(SpiceParser::LambdaAttrContext *ctx) { | |
| 773 | 16 | const auto lambdaAttrNode = createNode<LambdaAttrNode>(ctx); | |
| 774 | |||
| 775 | // Visit children | ||
| 776 |
3/6✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 16 times.
✗ Branch 4 → 33 not taken.
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 31 not taken.
|
16 | lambdaAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst())); |
| 777 | |||
| 778 | // Tell the attributes that they are module attributes | ||
| 779 |
2/2✓ Branch 20 → 9 taken 16 times.
✓ Branch 20 → 21 taken 16 times.
|
48 | for (AttrNode *attr : lambdaAttrNode->attrLst->attributes) |
| 780 | 16 | attr->target = AttrNode::TARGET_LAMBDA; | |
| 781 | |||
| 782 |
1/2✓ Branch 27 → 28 taken 16 times.
✗ Branch 27 → 34 not taken.
|
32 | return concludeNode(lambdaAttrNode); |
| 783 | } | ||
| 784 | |||
| 785 | 5052 | std::any ASTBuilder::visitAttrLst(SpiceParser::AttrLstContext *ctx) { | |
| 786 | 5052 | const auto attrLstNode = createNode<AttrLstNode>(ctx); | |
| 787 | |||
| 788 | // Visit children | ||
| 789 |
4/6✓ Branch 3 → 4 taken 5052 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 5050 times.
✓ Branch 4 → 16 taken 2 times.
✓ Branch 6 → 7 taken 5050 times.
✗ Branch 6 → 19 not taken.
|
5054 | fetchChildrenIntoVector(attrLstNode->attributes, ctx->attr()); |
| 790 | |||
| 791 |
1/2✓ Branch 12 → 13 taken 5050 times.
✗ Branch 12 → 19 not taken.
|
10100 | return concludeNode(attrLstNode); |
| 792 | } | ||
| 793 | |||
| 794 | 11708 | std::any ASTBuilder::visitAttr(SpiceParser::AttrContext *ctx) { | |
| 795 |
1/2✓ Branch 2 → 3 taken 11708 times.
✗ Branch 2 → 83 not taken.
|
11708 | const auto attrNode = createNode<AttrNode>(ctx); |
| 796 | |||
| 797 | // Extract key | ||
| 798 |
1/2✓ Branch 3 → 4 taken 11708 times.
✗ Branch 3 → 83 not taken.
|
11708 | std::stringstream key; |
| 799 |
3/4✓ Branch 12 → 13 taken 43230 times.
✗ Branch 12 → 66 not taken.
✓ Branch 15 → 5 taken 31522 times.
✓ Branch 15 → 16 taken 11708 times.
|
43230 | for (size_t i = 0; i < ctx->IDENTIFIER().size(); i++) { |
| 800 |
2/2✓ Branch 5 → 6 taken 19814 times.
✓ Branch 5 → 7 taken 11708 times.
|
31522 | if (i > 0) |
| 801 |
1/2✓ Branch 6 → 7 taken 19814 times.
✗ Branch 6 → 81 not taken.
|
19814 | key << MEMBER_ACCESS_TOKEN; |
| 802 |
3/6✓ Branch 7 → 8 taken 31522 times.
✗ Branch 7 → 65 not taken.
✓ Branch 8 → 9 taken 31522 times.
✗ Branch 8 → 65 not taken.
✓ Branch 9 → 10 taken 31522 times.
✗ Branch 9 → 63 not taken.
|
31522 | key << ctx->IDENTIFIER(i)->getText(); |
| 803 | } | ||
| 804 |
1/2✓ Branch 16 → 17 taken 11708 times.
✗ Branch 16 → 67 not taken.
|
11708 | attrNode->key = key.str(); |
| 805 | |||
| 806 | // Visit children | ||
| 807 |
3/4✓ Branch 19 → 20 taken 11708 times.
✗ Branch 19 → 81 not taken.
✓ Branch 20 → 21 taken 9612 times.
✓ Branch 20 → 51 taken 2096 times.
|
11708 | if (ctx->constant()) { |
| 808 |
3/6✓ Branch 21 → 22 taken 9612 times.
✗ Branch 21 → 70 not taken.
✓ Branch 22 → 23 taken 9612 times.
✗ Branch 22 → 70 not taken.
✓ Branch 23 → 24 taken 9612 times.
✗ Branch 23 → 68 not taken.
|
9612 | attrNode->value = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 809 | |||
| 810 |
4/6✓ Branch 25 → 26 taken 9612 times.
✗ Branch 25 → 81 not taken.
✓ Branch 26 → 27 taken 9612 times.
✗ Branch 26 → 81 not taken.
✓ Branch 27 → 28 taken 6728 times.
✓ Branch 27 → 29 taken 2884 times.
|
9612 | if (ctx->constant()->STRING_LIT()) |
| 811 | 6728 | attrNode->type = AttrNode::AttrType::TYPE_STRING; | |
| 812 |
4/6✓ Branch 29 → 30 taken 2884 times.
✗ Branch 29 → 81 not taken.
✓ Branch 30 → 31 taken 2884 times.
✗ Branch 30 → 81 not taken.
✓ Branch 31 → 32 taken 400 times.
✓ Branch 31 → 33 taken 2484 times.
|
2884 | else if (ctx->constant()->INT_LIT()) |
| 813 | 400 | attrNode->type = AttrNode::AttrType::TYPE_INT; | |
| 814 |
10/14✓ Branch 33 → 34 taken 2484 times.
✗ Branch 33 → 81 not taken.
✓ Branch 34 → 35 taken 2484 times.
✗ Branch 34 → 81 not taken.
✓ Branch 35 → 36 taken 10 times.
✓ Branch 35 → 39 taken 2474 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 2482 times.
✓ Branch 41 → 43 taken 2 times.
|
2484 | else if (ctx->constant()->TRUE() || ctx->constant()->FALSE()) |
| 815 | 2482 | attrNode->type = AttrNode::AttrType::TYPE_BOOL; | |
| 816 | else | ||
| 817 |
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"); |
| 818 | } else { | ||
| 819 | // If no value is given, use the bool type | ||
| 820 | 2096 | attrNode->type = AttrNode::AttrType::TYPE_BOOL; | |
| 821 | } | ||
| 822 | |||
| 823 |
1/2✓ Branch 58 → 59 taken 11706 times.
✗ Branch 58 → 80 not taken.
|
23412 | return concludeNode(attrNode); |
| 824 | 11708 | } | |
| 825 | |||
| 826 | 4063 | std::any ASTBuilder::visitCaseConstant(SpiceParser::CaseConstantContext *ctx) { | |
| 827 | 4063 | const auto caseConstantNode = createNode<CaseConstantNode>(ctx); | |
| 828 | |||
| 829 | // Visit children | ||
| 830 |
2/2✓ Branch 4 → 5 taken 137 times.
✓ Branch 4 → 10 taken 3926 times.
|
4063 | if (ctx->constant()) { |
| 831 |
3/6✓ Branch 5 → 6 taken 137 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 137 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 137 times.
✗ Branch 7 → 63 not taken.
|
137 | caseConstantNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 832 |
2/4✓ Branch 10 → 11 taken 3926 times.
✗ Branch 10 → 66 not taken.
✓ Branch 13 → 14 taken 3926 times.
✗ Branch 13 → 52 not taken.
|
3926 | } else if (!ctx->TYPE_IDENTIFIER().empty()) { |
| 833 |
1/2✓ Branch 14 → 15 taken 3926 times.
✗ Branch 14 → 75 not taken.
|
3926 | std::stringstream fqIdentifier; |
| 834 |
2/2✓ Branch 46 → 17 taken 10598 times.
✓ Branch 46 → 47 taken 3926 times.
|
18450 | for (antlr4::tree::ParseTree *parseTree : ctx->children) { |
| 835 |
1/2✓ Branch 19 → 20 taken 10598 times.
✗ Branch 19 → 21 not taken.
|
10598 | const auto terminal = dynamic_cast<TerminalNode *>(parseTree); |
| 836 |
1/2✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 10598 times.
|
10598 | if (!terminal) |
| 837 | ✗ | continue; | |
| 838 | |||
| 839 |
2/4✓ Branch 24 → 25 taken 10598 times.
✗ Branch 24 → 71 not taken.
✓ Branch 25 → 26 taken 10598 times.
✗ Branch 25 → 71 not taken.
|
10598 | const size_t terminalType = terminal->getSymbol()->getType(); |
| 840 |
3/4✓ Branch 26 → 27 taken 10598 times.
✗ Branch 26 → 28 not taken.
✓ Branch 27 → 28 taken 7262 times.
✓ Branch 27 → 37 taken 3336 times.
|
10598 | if (terminalType == SpiceParser::IDENTIFIER || terminalType == SpiceParser::TYPE_IDENTIFIER) { |
| 841 |
1/2✓ Branch 28 → 29 taken 7262 times.
✗ Branch 28 → 70 not taken.
|
7262 | const std::string fragment = getIdentifier(terminal, false); |
| 842 |
1/2✓ Branch 29 → 30 taken 7262 times.
✗ Branch 29 → 68 not taken.
|
7262 | caseConstantNode->identifierFragments.push_back(fragment); |
| 843 |
3/4✓ Branch 30 → 31 taken 7262 times.
✗ Branch 30 → 67 not taken.
✓ Branch 32 → 33 taken 3336 times.
✓ Branch 32 → 34 taken 3926 times.
|
7262 | if (fqIdentifier.tellp() != 0) |
| 844 |
1/2✓ Branch 33 → 34 taken 3336 times.
✗ Branch 33 → 68 not taken.
|
3336 | fqIdentifier << SCOPE_ACCESS_TOKEN; |
| 845 |
1/2✓ Branch 34 → 35 taken 7262 times.
✗ Branch 34 → 68 not taken.
|
7262 | fqIdentifier << fragment; |
| 846 | 7262 | } | |
| 847 | } | ||
| 848 |
1/2✓ Branch 47 → 48 taken 3926 times.
✗ Branch 47 → 72 not taken.
|
3926 | caseConstantNode->fqIdentifier = fqIdentifier.str(); |
| 849 | 3926 | } else { | |
| 850 | − | assert_fail("Unknown case constant type"); // GCOV_EXCL_LINE | |
| 851 | } | ||
| 852 | |||
| 853 |
1/2✓ Branch 59 → 60 taken 4063 times.
✗ Branch 59 → 76 not taken.
|
8126 | return concludeNode(caseConstantNode); |
| 854 | } | ||
| 855 | |||
| 856 | 88847 | std::any ASTBuilder::visitReturnStmt(SpiceParser::ReturnStmtContext *ctx) { | |
| 857 | 88847 | const auto returnStmtNode = createNode<ReturnStmtNode>(ctx); | |
| 858 | |||
| 859 | // Visit children | ||
| 860 |
2/2✓ Branch 4 → 5 taken 81837 times.
✓ Branch 4 → 10 taken 7010 times.
|
88847 | if (ctx->assignExpr()) { |
| 861 | 81837 | returnStmtNode->hasReturnValue = true; | |
| 862 |
3/6✓ Branch 5 → 6 taken 81837 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 81837 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 81837 times.
✗ Branch 7 → 20 not taken.
|
81837 | returnStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 863 | } | ||
| 864 | |||
| 865 |
1/2✓ Branch 16 → 17 taken 88847 times.
✗ Branch 16 → 23 not taken.
|
177694 | return concludeNode(returnStmtNode); |
| 866 | } | ||
| 867 | |||
| 868 | 1264 | std::any ASTBuilder::visitBreakStmt(SpiceParser::BreakStmtContext *ctx) { | |
| 869 | 1264 | const auto breakStmtNode = createNode<BreakStmtNode>(ctx); | |
| 870 | |||
| 871 | // Extract number of breaks | ||
| 872 |
2/2✓ Branch 4 → 5 taken 13 times.
✓ Branch 4 → 10 taken 1251 times.
|
1264 | if (ctx->INT_LIT()) |
| 873 |
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()); |
| 874 | |||
| 875 | // Visit children | ||
| 876 |
2/4✓ Branch 10 → 11 taken 1264 times.
✗ Branch 10 → 25 not taken.
✓ Branch 12 → 13 taken 1264 times.
✗ Branch 12 → 26 not taken.
|
1264 | visitChildren(ctx); |
| 877 | |||
| 878 |
1/2✓ Branch 18 → 19 taken 1264 times.
✗ Branch 18 → 26 not taken.
|
2528 | return concludeNode(breakStmtNode); |
| 879 | } | ||
| 880 | |||
| 881 | 1212 | std::any ASTBuilder::visitContinueStmt(SpiceParser::ContinueStmtContext *ctx) { | |
| 882 | 1212 | const auto continueStmtNode = createNode<ContinueStmtNode>(ctx); | |
| 883 | |||
| 884 | // Extract number of continues | ||
| 885 |
2/2✓ Branch 4 → 5 taken 860 times.
✓ Branch 4 → 10 taken 352 times.
|
1212 | if (ctx->INT_LIT()) |
| 886 |
3/6✓ Branch 5 → 6 taken 860 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 860 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 860 times.
✗ Branch 7 → 22 not taken.
|
860 | continueStmtNode->continueTimes = std::stoi(ctx->INT_LIT()->toString()); |
| 887 | |||
| 888 | // Visit children | ||
| 889 |
2/4✓ Branch 10 → 11 taken 1212 times.
✗ Branch 10 → 25 not taken.
✓ Branch 12 → 13 taken 1212 times.
✗ Branch 12 → 26 not taken.
|
1212 | visitChildren(ctx); |
| 890 | |||
| 891 |
1/2✓ Branch 18 → 19 taken 1212 times.
✗ Branch 18 → 26 not taken.
|
2424 | return concludeNode(continueStmtNode); |
| 892 | } | ||
| 893 | |||
| 894 | 12 | std::any ASTBuilder::visitFallthroughStmt(SpiceParser::FallthroughStmtContext *ctx) { | |
| 895 | 12 | const auto fallthroughStmtNode = createNode<FallthroughStmtNode>(ctx); | |
| 896 | |||
| 897 | // Visit children | ||
| 898 |
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); |
| 899 | |||
| 900 |
1/2✓ Branch 11 → 12 taken 12 times.
✗ Branch 11 → 16 not taken.
|
24 | return concludeNode(fallthroughStmtNode); |
| 901 | } | ||
| 902 | |||
| 903 | 13189 | std::any ASTBuilder::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) { | |
| 904 |
1/2✓ Branch 2 → 3 taken 13189 times.
✗ Branch 2 → 30 not taken.
|
13189 | const auto assertStmtNode = createNode<AssertStmtNode>(ctx); |
| 905 | |||
| 906 | // Enrich | ||
| 907 |
5/10✓ Branch 3 → 4 taken 13189 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 13189 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 13189 times.
✗ Branch 5 → 30 not taken.
✓ Branch 6 → 7 taken 13189 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 13189 times.
✗ Branch 7 → 30 not taken.
|
13189 | const antlr4::misc::Interval interval(ctx->assignExpr()->start->getStartIndex(), ctx->assignExpr()->stop->getStopIndex()); |
| 908 |
1/2✓ Branch 8 → 9 taken 13189 times.
✗ Branch 8 → 25 not taken.
|
13189 | assertStmtNode->expressionString = inputStream->getText(interval); |
| 909 | |||
| 910 | // Visit children | ||
| 911 |
4/8✓ Branch 11 → 12 taken 13189 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 13 taken 13189 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 13189 times.
✗ Branch 13 → 26 not taken.
✓ Branch 15 → 16 taken 13189 times.
✗ Branch 15 → 29 not taken.
|
13189 | assertStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 912 | |||
| 913 |
1/2✓ Branch 21 → 22 taken 13189 times.
✗ Branch 21 → 29 not taken.
|
26378 | return concludeNode(assertStmtNode); |
| 914 | } | ||
| 915 | |||
| 916 | 675154 | std::any ASTBuilder::visitAssignExpr(SpiceParser::AssignExprContext *ctx) { | |
| 917 |
2/2✓ Branch 3 → 4 taken 613086 times.
✓ Branch 3 → 6 taken 62068 times.
|
675154 | if (!ctx->assignOp()) |
| 918 | 613086 | return visit(ctx->ternaryExpr()); | |
| 919 | |||
| 920 | 62068 | const auto assignExprNode = createNode<AssignExprNode>(ctx); | |
| 921 | |||
| 922 | // Visit children | ||
| 923 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 62068 times.
|
62068 | if (ctx->ternaryExpr()) { |
| 924 | ✗ | assignExprNode->ternaryExpr = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr())); | |
| 925 |
1/2✓ Branch 15 → 16 taken 62068 times.
✗ Branch 15 → 28 not taken.
|
62068 | } else if (ctx->prefixUnaryExpr()) { |
| 926 |
3/6✓ Branch 16 → 17 taken 62068 times.
✗ Branch 16 → 44 not taken.
✓ Branch 17 → 18 taken 62068 times.
✗ Branch 17 → 44 not taken.
✓ Branch 18 → 19 taken 62068 times.
✗ Branch 18 → 42 not taken.
|
62068 | assignExprNode->lhs = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr())); |
| 927 |
2/4✓ Branch 20 → 21 taken 62068 times.
✗ Branch 20 → 45 not taken.
✓ Branch 21 → 22 taken 62068 times.
✗ Branch 21 → 45 not taken.
|
62068 | visit(ctx->assignOp()); |
| 928 |
3/6✓ Branch 23 → 24 taken 62068 times.
✗ Branch 23 → 48 not taken.
✓ Branch 24 → 25 taken 62068 times.
✗ Branch 24 → 48 not taken.
✓ Branch 25 → 26 taken 62068 times.
✗ Branch 25 → 46 not taken.
|
62068 | assignExprNode->rhs = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 929 | } else { | ||
| 930 | − | assert_fail("Invalid assign expression"); // GCOV_EXCL_LINE | |
| 931 | } | ||
| 932 | |||
| 933 |
1/2✓ Branch 35 → 36 taken 62068 times.
✗ Branch 35 → 49 not taken.
|
124136 | return concludeExprNode(assignExprNode); |
| 934 | } | ||
| 935 | |||
| 936 | 622641 | std::any ASTBuilder::visitTernaryExpr(SpiceParser::TernaryExprContext *ctx) { | |
| 937 |
3/4✓ Branch 2 → 3 taken 622641 times.
✗ Branch 2 → 45 not taken.
✓ Branch 5 → 6 taken 617831 times.
✓ Branch 5 → 8 taken 4810 times.
|
622641 | if (ctx->logicalOrExpr().size() == 1) |
| 938 | 617831 | return visit(ctx->logicalOrExpr(0)); | |
| 939 | |||
| 940 | 4810 | const auto ternaryExprNode = createNode<TernaryExprNode>(ctx); | |
| 941 | |||
| 942 |
3/6✓ Branch 9 → 10 taken 4810 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 4810 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 4810 times.
✗ Branch 11 → 46 not taken.
|
4810 | ternaryExprNode->condition = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(0))); |
| 943 |
3/4✓ Branch 13 → 14 taken 4810 times.
✗ Branch 13 → 49 not taken.
✓ Branch 16 → 17 taken 4808 times.
✓ Branch 16 → 26 taken 2 times.
|
4810 | if (ctx->logicalOrExpr().size() == 3) { |
| 944 |
3/6✓ Branch 17 → 18 taken 4808 times.
✗ Branch 17 → 52 not taken.
✓ Branch 18 → 19 taken 4808 times.
✗ Branch 18 → 52 not taken.
✓ Branch 19 → 20 taken 4808 times.
✗ Branch 19 → 50 not taken.
|
4808 | ternaryExprNode->trueExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(1))); |
| 945 |
3/6✓ Branch 21 → 22 taken 4808 times.
✗ Branch 21 → 55 not taken.
✓ Branch 22 → 23 taken 4808 times.
✗ Branch 22 → 55 not taken.
✓ Branch 23 → 24 taken 4808 times.
✗ Branch 23 → 53 not taken.
|
4808 | ternaryExprNode->falseExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(2))); |
| 946 |
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) { |
| 947 | 2 | ternaryExprNode->isShortened = true; | |
| 948 |
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))); |
| 949 | } | ||
| 950 | |||
| 951 |
1/2✓ Branch 41 → 42 taken 4810 times.
✗ Branch 41 → 60 not taken.
|
9620 | return concludeExprNode(ternaryExprNode); |
| 952 | } | ||
| 953 | |||
| 954 | 632259 | std::any ASTBuilder::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext *ctx) { | |
| 955 |
3/4✓ Branch 2 → 3 taken 632259 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 625282 times.
✓ Branch 5 → 8 taken 6977 times.
|
632259 | if (ctx->logicalAndExpr().size() == 1) |
| 956 | 625282 | return visit(ctx->logicalAndExpr(0)); | |
| 957 | |||
| 958 | 6977 | const auto logicalOrExprNode = createNode<LogicalOrExprNode>(ctx); | |
| 959 | |||
| 960 | // Visit children | ||
| 961 |
3/6✓ Branch 9 → 10 taken 6977 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 6977 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 6977 times.
✗ Branch 12 → 26 not taken.
|
6977 | fetchChildrenIntoVector(logicalOrExprNode->operands, ctx->logicalAndExpr()); |
| 962 | |||
| 963 |
1/2✓ Branch 18 → 19 taken 6977 times.
✗ Branch 18 → 26 not taken.
|
13954 | return concludeExprNode(logicalOrExprNode); |
| 964 | } | ||
| 965 | |||
| 966 | 641412 | std::any ASTBuilder::visitLogicalAndExpr(SpiceParser::LogicalAndExprContext *ctx) { | |
| 967 |
3/4✓ Branch 2 → 3 taken 641412 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 636633 times.
✓ Branch 5 → 8 taken 4779 times.
|
641412 | if (ctx->bitwiseOrExpr().size() == 1) |
| 968 | 636633 | return visit(ctx->bitwiseOrExpr(0)); | |
| 969 | |||
| 970 | 4779 | const auto logicalAndExprNode = createNode<LogicalAndExprNode>(ctx); | |
| 971 | |||
| 972 | // Visit children | ||
| 973 |
3/6✓ Branch 9 → 10 taken 4779 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 4779 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 4779 times.
✗ Branch 12 → 26 not taken.
|
4779 | fetchChildrenIntoVector(logicalAndExprNode->operands, ctx->bitwiseOrExpr()); |
| 974 | |||
| 975 |
1/2✓ Branch 18 → 19 taken 4779 times.
✗ Branch 18 → 26 not taken.
|
9558 | return concludeExprNode(logicalAndExprNode); |
| 976 | } | ||
| 977 | |||
| 978 | 647975 | std::any ASTBuilder::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext *ctx) { | |
| 979 |
3/4✓ Branch 2 → 3 taken 647975 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 646887 times.
✓ Branch 5 → 8 taken 1088 times.
|
647975 | if (ctx->bitwiseXorExpr().size() == 1) |
| 980 | 646887 | return visit(ctx->bitwiseXorExpr(0)); | |
| 981 | |||
| 982 | 1088 | const auto bitwiseOrExprNode = createNode<BitwiseOrExprNode>(ctx); | |
| 983 | |||
| 984 | // Visit children | ||
| 985 |
3/6✓ Branch 9 → 10 taken 1088 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 1088 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 1088 times.
✗ Branch 12 → 26 not taken.
|
1088 | fetchChildrenIntoVector(bitwiseOrExprNode->operands, ctx->bitwiseXorExpr()); |
| 986 | |||
| 987 |
1/2✓ Branch 18 → 19 taken 1088 times.
✗ Branch 18 → 26 not taken.
|
2176 | return concludeExprNode(bitwiseOrExprNode); |
| 988 | } | ||
| 989 | |||
| 990 | 649145 | std::any ASTBuilder::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprContext *ctx) { | |
| 991 |
3/4✓ Branch 2 → 3 taken 649145 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 648984 times.
✓ Branch 5 → 8 taken 161 times.
|
649145 | if (ctx->bitwiseAndExpr().size() == 1) |
| 992 | 648984 | return visit(ctx->bitwiseAndExpr(0)); | |
| 993 | |||
| 994 | 161 | const auto bitwiseXorExprNode = createNode<BitwiseXorExprNode>(ctx); | |
| 995 | |||
| 996 | // Visit children | ||
| 997 |
3/6✓ Branch 9 → 10 taken 161 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 161 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 161 times.
✗ Branch 12 → 26 not taken.
|
161 | fetchChildrenIntoVector(bitwiseXorExprNode->operands, ctx->bitwiseAndExpr()); |
| 998 | |||
| 999 |
1/2✓ Branch 18 → 19 taken 161 times.
✗ Branch 18 → 26 not taken.
|
322 | return concludeExprNode(bitwiseXorExprNode); |
| 1000 | } | ||
| 1001 | |||
| 1002 | 649308 | std::any ASTBuilder::visitBitwiseAndExpr(SpiceParser::BitwiseAndExprContext *ctx) { | |
| 1003 |
3/4✓ Branch 2 → 3 taken 649308 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 648690 times.
✓ Branch 5 → 8 taken 618 times.
|
649308 | if (ctx->equalityExpr().size() == 1) |
| 1004 | 648690 | return visit(ctx->equalityExpr(0)); | |
| 1005 | |||
| 1006 | 618 | const auto bitwiseAndExprNode = createNode<BitwiseAndExprNode>(ctx); | |
| 1007 | |||
| 1008 | // Visit children | ||
| 1009 |
3/6✓ Branch 9 → 10 taken 618 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 618 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 618 times.
✗ Branch 12 → 26 not taken.
|
618 | fetchChildrenIntoVector(bitwiseAndExprNode->operands, ctx->equalityExpr()); |
| 1010 | |||
| 1011 |
1/2✓ Branch 18 → 19 taken 618 times.
✗ Branch 18 → 26 not taken.
|
1236 | return concludeExprNode(bitwiseAndExprNode); |
| 1012 | } | ||
| 1013 | |||
| 1014 | 649928 | std::any ASTBuilder::visitEqualityExpr(SpiceParser::EqualityExprContext *ctx) { | |
| 1015 |
3/4✓ Branch 2 → 3 taken 649928 times.
✗ Branch 2 → 28 not taken.
✓ Branch 5 → 6 taken 597636 times.
✓ Branch 5 → 8 taken 52292 times.
|
649928 | if (ctx->relationalExpr().size() == 1) |
| 1016 | 597636 | return visit(ctx->relationalExpr(0)); | |
| 1017 | |||
| 1018 | 52292 | const auto equalityExprNode = createNode<EqualityExprNode>(ctx); | |
| 1019 | |||
| 1020 | // Visit children | ||
| 1021 |
2/4✓ Branch 9 → 10 taken 52292 times.
✗ Branch 9 → 31 not taken.
✓ Branch 10 → 11 taken 52292 times.
✗ Branch 10 → 29 not taken.
|
52292 | fetchChildrenIntoVector(equalityExprNode->operands, ctx->relationalExpr()); |
| 1022 | |||
| 1023 | // Extract operator | ||
| 1024 |
2/2✓ Branch 13 → 14 taken 43358 times.
✓ Branch 13 → 15 taken 8934 times.
|
52292 | if (ctx->EQUAL()) |
| 1025 | 43358 | equalityExprNode->op = EqualityExprNode::EqualityOp::OP_EQUAL; | |
| 1026 |
1/2✓ Branch 16 → 17 taken 8934 times.
✗ Branch 16 → 18 not taken.
|
8934 | else if (ctx->NOT_EQUAL()) |
| 1027 | 8934 | equalityExprNode->op = EqualityExprNode::EqualityOp::OP_NOT_EQUAL; | |
| 1028 | |||
| 1029 |
1/2✓ Branch 24 → 25 taken 52292 times.
✗ Branch 24 → 32 not taken.
|
104584 | return concludeExprNode(equalityExprNode); |
| 1030 | } | ||
| 1031 | |||
| 1032 | 702220 | std::any ASTBuilder::visitRelationalExpr(SpiceParser::RelationalExprContext *ctx) { | |
| 1033 |
3/4✓ Branch 2 → 3 taken 702220 times.
✗ Branch 2 → 34 not taken.
✓ Branch 5 → 6 taken 676182 times.
✓ Branch 5 → 8 taken 26038 times.
|
702220 | if (ctx->shiftExpr().size() == 1) |
| 1034 | 676182 | return visit(ctx->shiftExpr(0)); | |
| 1035 | |||
| 1036 | 26038 | const auto relationalExprNode = createNode<RelationalExprNode>(ctx); | |
| 1037 | |||
| 1038 | // Visit children | ||
| 1039 |
2/4✓ Branch 9 → 10 taken 26038 times.
✗ Branch 9 → 37 not taken.
✓ Branch 10 → 11 taken 26038 times.
✗ Branch 10 → 35 not taken.
|
26038 | fetchChildrenIntoVector(relationalExprNode->operands, ctx->shiftExpr()); |
| 1040 | |||
| 1041 | // Extract operator | ||
| 1042 |
2/2✓ Branch 13 → 14 taken 11581 times.
✓ Branch 13 → 15 taken 14457 times.
|
26038 | if (ctx->LESS()) |
| 1043 | 11581 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS; | |
| 1044 |
2/2✓ Branch 16 → 17 taken 6576 times.
✓ Branch 16 → 18 taken 7881 times.
|
14457 | else if (ctx->GREATER()) |
| 1045 | 6576 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER; | |
| 1046 |
2/2✓ Branch 19 → 20 taken 2566 times.
✓ Branch 19 → 21 taken 5315 times.
|
7881 | else if (ctx->LESS_EQUAL()) |
| 1047 | 2566 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS_EQUAL; | |
| 1048 |
1/2✓ Branch 22 → 23 taken 5315 times.
✗ Branch 22 → 24 not taken.
|
5315 | else if (ctx->GREATER_EQUAL()) |
| 1049 | 5315 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER_EQUAL; | |
| 1050 | |||
| 1051 |
1/2✓ Branch 30 → 31 taken 26038 times.
✗ Branch 30 → 38 not taken.
|
52076 | return concludeExprNode(relationalExprNode); |
| 1052 | } | ||
| 1053 | |||
| 1054 | 728258 | std::any ASTBuilder::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) { | |
| 1055 |
3/4✓ Branch 2 → 3 taken 728258 times.
✗ Branch 2 → 60 not taken.
✓ Branch 5 → 6 taken 725150 times.
✓ Branch 5 → 8 taken 3108 times.
|
728258 | if (ctx->additiveExpr().size() == 1) |
| 1056 | 725150 | return visit(ctx->additiveExpr(0)); | |
| 1057 | |||
| 1058 | 3108 | const auto shiftExprNode = createNode<ShiftExprNode>(ctx); | |
| 1059 | |||
| 1060 | // Visit children | ||
| 1061 |
2/4✓ Branch 9 → 10 taken 3108 times.
✗ Branch 9 → 63 not taken.
✓ Branch 10 → 11 taken 3108 times.
✗ Branch 10 → 61 not taken.
|
3108 | fetchChildrenIntoVector(shiftExprNode->operands, ctx->additiveExpr()); |
| 1062 | |||
| 1063 | 3108 | bool seenFirstLess = false; | |
| 1064 | 3108 | bool seenFirstGreater = false; | |
| 1065 |
2/2✓ Branch 45 → 14 taken 14856 times.
✓ Branch 45 → 46 taken 3108 times.
|
21072 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1066 |
1/2✓ Branch 16 → 17 taken 14856 times.
✗ Branch 16 → 18 not taken.
|
14856 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1067 |
2/2✓ Branch 19 → 20 taken 7024 times.
✓ Branch 19 → 21 taken 7832 times.
|
14856 | if (!terminal) |
| 1068 | 7024 | continue; | |
| 1069 | |||
| 1070 |
4/6✓ Branch 21 → 22 taken 7832 times.
✗ Branch 21 → 68 not taken.
✓ Branch 22 → 23 taken 7832 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 6122 times.
✓ Branch 23 → 28 taken 1710 times.
|
7832 | if (terminal->getSymbol()->getType() == SpiceParser::LESS) { |
| 1071 |
2/2✓ Branch 24 → 25 taken 3061 times.
✓ Branch 24 → 27 taken 3061 times.
|
6122 | if (seenFirstLess) |
| 1072 |
1/2✓ Branch 25 → 26 taken 3061 times.
✗ Branch 25 → 64 not taken.
|
3061 | shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_LEFT, TY_INVALID); |
| 1073 | 6122 | seenFirstLess = !seenFirstLess; | |
| 1074 | 6122 | continue; | |
| 1075 | } | ||
| 1076 | |||
| 1077 |
3/6✓ Branch 28 → 29 taken 1710 times.
✗ Branch 28 → 68 not taken.
✓ Branch 29 → 30 taken 1710 times.
✗ Branch 29 → 68 not taken.
✓ Branch 30 → 31 taken 1710 times.
✗ Branch 30 → 35 not taken.
|
1710 | if (terminal->getSymbol()->getType() == SpiceParser::GREATER) { |
| 1078 |
2/2✓ Branch 31 → 32 taken 855 times.
✓ Branch 31 → 34 taken 855 times.
|
1710 | if (seenFirstGreater) |
| 1079 |
1/2✓ Branch 32 → 33 taken 855 times.
✗ Branch 32 → 66 not taken.
|
855 | shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT, TY_INVALID); |
| 1080 | 1710 | seenFirstGreater = !seenFirstGreater; | |
| 1081 | 1710 | continue; | |
| 1082 | } | ||
| 1083 | |||
| 1084 | − | assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE | |
| 1085 | } | ||
| 1086 |
2/4✓ Branch 46 → 47 taken 3108 times.
✗ Branch 46 → 49 not taken.
✓ Branch 47 → 48 taken 3108 times.
✗ Branch 47 → 49 not taken.
|
3108 | assert(!seenFirstLess && !seenFirstGreater); |
| 1087 | |||
| 1088 |
1/2✓ Branch 56 → 57 taken 3108 times.
✗ Branch 56 → 69 not taken.
|
6216 | return concludeExprNode(shiftExprNode); |
| 1089 | } | ||
| 1090 | |||
| 1091 | 732174 | std::any ASTBuilder::visitAdditiveExpr(SpiceParser::AdditiveExprContext *ctx) { | |
| 1092 |
3/4✓ Branch 2 → 3 taken 732174 times.
✗ Branch 2 → 52 not taken.
✓ Branch 5 → 6 taken 707317 times.
✓ Branch 5 → 8 taken 24857 times.
|
732174 | if (ctx->multiplicativeExpr().size() == 1) |
| 1093 | 707317 | return visit(ctx->multiplicativeExpr(0)); | |
| 1094 | |||
| 1095 | 24857 | const auto additiveExprNode = createNode<AdditiveExprNode>(ctx); | |
| 1096 | |||
| 1097 | // Visit children | ||
| 1098 |
2/4✓ Branch 9 → 10 taken 24857 times.
✗ Branch 9 → 55 not taken.
✓ Branch 10 → 11 taken 24857 times.
✗ Branch 10 → 53 not taken.
|
24857 | fetchChildrenIntoVector(additiveExprNode->operands, ctx->multiplicativeExpr()); |
| 1099 | |||
| 1100 |
2/2✓ Branch 41 → 14 taken 80831 times.
✓ Branch 41 → 42 taken 24857 times.
|
130545 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1101 |
1/2✓ Branch 16 → 17 taken 80831 times.
✗ Branch 16 → 18 not taken.
|
80831 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1102 |
2/2✓ Branch 19 → 20 taken 52844 times.
✓ Branch 19 → 21 taken 27987 times.
|
80831 | if (!terminal) |
| 1103 | 52844 | continue; | |
| 1104 | |||
| 1105 |
4/6✓ Branch 21 → 22 taken 27987 times.
✗ Branch 21 → 60 not taken.
✓ Branch 22 → 23 taken 27987 times.
✗ Branch 22 → 60 not taken.
✓ Branch 23 → 24 taken 19185 times.
✓ Branch 23 → 26 taken 8802 times.
|
27987 | if (terminal->getSymbol()->getType() == SpiceParser::PLUS) |
| 1106 |
1/2✓ Branch 24 → 25 taken 19185 times.
✗ Branch 24 → 56 not taken.
|
19185 | additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_PLUS, TY_INVALID); |
| 1107 |
3/6✓ Branch 26 → 27 taken 8802 times.
✗ Branch 26 → 60 not taken.
✓ Branch 27 → 28 taken 8802 times.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 8802 times.
✗ Branch 28 → 31 not taken.
|
8802 | else if (terminal->getSymbol()->getType() == SpiceParser::MINUS) |
| 1108 |
1/2✓ Branch 29 → 30 taken 8802 times.
✗ Branch 29 → 58 not taken.
|
8802 | additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_MINUS, TY_INVALID); |
| 1109 | else | ||
| 1110 | − | assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE | |
| 1111 | } | ||
| 1112 | |||
| 1113 |
1/2✓ Branch 48 → 49 taken 24857 times.
✗ Branch 48 → 61 not taken.
|
49714 | return concludeExprNode(additiveExprNode); |
| 1114 | } | ||
| 1115 | |||
| 1116 | 760161 | std::any ASTBuilder::visitMultiplicativeExpr(SpiceParser::MultiplicativeExprContext *ctx) { | |
| 1117 |
3/4✓ Branch 2 → 3 taken 760161 times.
✗ Branch 2 → 57 not taken.
✓ Branch 5 → 6 taken 754160 times.
✓ Branch 5 → 8 taken 6001 times.
|
760161 | if (ctx->castExpr().size() == 1) |
| 1118 | 754160 | return visit(ctx->castExpr(0)); | |
| 1119 | |||
| 1120 | 6001 | const auto multiplicativeExprNode = createNode<MultiplicativeExprNode>(ctx); | |
| 1121 | |||
| 1122 | // Visit children | ||
| 1123 |
2/4✓ Branch 9 → 10 taken 6001 times.
✗ Branch 9 → 60 not taken.
✓ Branch 10 → 11 taken 6001 times.
✗ Branch 10 → 58 not taken.
|
6001 | fetchChildrenIntoVector(multiplicativeExprNode->operands, ctx->castExpr()); |
| 1124 | |||
| 1125 |
2/2✓ Branch 46 → 14 taken 18497 times.
✓ Branch 46 → 47 taken 6001 times.
|
30499 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1126 |
1/2✓ Branch 16 → 17 taken 18497 times.
✗ Branch 16 → 18 not taken.
|
18497 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1127 |
2/2✓ Branch 19 → 20 taken 12249 times.
✓ Branch 19 → 21 taken 6248 times.
|
18497 | if (!terminal) |
| 1128 | 12249 | continue; | |
| 1129 | |||
| 1130 |
4/6✓ Branch 21 → 22 taken 6248 times.
✗ Branch 21 → 67 not taken.
✓ Branch 22 → 23 taken 6248 times.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 4841 times.
✓ Branch 23 → 26 taken 1407 times.
|
6248 | if (terminal->getSymbol()->getType() == SpiceParser::MUL) |
| 1131 |
1/2✓ Branch 24 → 25 taken 4841 times.
✗ Branch 24 → 61 not taken.
|
4841 | multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_MUL, TY_INVALID); |
| 1132 |
4/6✓ Branch 26 → 27 taken 1407 times.
✗ Branch 26 → 67 not taken.
✓ Branch 27 → 28 taken 1407 times.
✗ Branch 27 → 67 not taken.
✓ Branch 28 → 29 taken 1045 times.
✓ Branch 28 → 31 taken 362 times.
|
1407 | else if (terminal->getSymbol()->getType() == SpiceParser::DIV) |
| 1133 |
1/2✓ Branch 29 → 30 taken 1045 times.
✗ Branch 29 → 63 not taken.
|
1045 | multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_DIV, TY_INVALID); |
| 1134 |
3/6✓ Branch 31 → 32 taken 362 times.
✗ Branch 31 → 67 not taken.
✓ Branch 32 → 33 taken 362 times.
✗ Branch 32 → 67 not taken.
✓ Branch 33 → 34 taken 362 times.
✗ Branch 33 → 36 not taken.
|
362 | else if (terminal->getSymbol()->getType() == SpiceParser::REM) |
| 1135 |
1/2✓ Branch 34 → 35 taken 362 times.
✗ Branch 34 → 65 not taken.
|
362 | multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_REM, TY_INVALID); |
| 1136 | else | ||
| 1137 | − | assert_fail("Invalid terminal symbol for multiplicative expression"); // GCOV_EXCL_LINE | |
| 1138 | } | ||
| 1139 | |||
| 1140 |
1/2✓ Branch 53 → 54 taken 6001 times.
✗ Branch 53 → 68 not taken.
|
12002 | return concludeExprNode(multiplicativeExprNode); |
| 1141 | } | ||
| 1142 | |||
| 1143 | 766409 | std::any ASTBuilder::visitCastExpr(SpiceParser::CastExprContext *ctx) { | |
| 1144 |
2/2✓ Branch 3 → 4 taken 742831 times.
✓ Branch 3 → 6 taken 23578 times.
|
766409 | if (!ctx->CAST()) |
| 1145 | 742831 | return visit(ctx->prefixUnaryExpr()); | |
| 1146 | |||
| 1147 | 23578 | const auto castExprNode = createNode<CastExprNode>(ctx); | |
| 1148 | |||
| 1149 | // Visit children | ||
| 1150 |
1/2✓ Branch 8 → 9 taken 23578 times.
✗ Branch 8 → 18 not taken.
|
23578 | if (ctx->dataType()) { |
| 1151 |
3/6✓ Branch 9 → 10 taken 23578 times.
✗ Branch 9 → 35 not taken.
✓ Branch 10 → 11 taken 23578 times.
✗ Branch 10 → 35 not taken.
✓ Branch 11 → 12 taken 23578 times.
✗ Branch 11 → 33 not taken.
|
23578 | castExprNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1152 |
3/6✓ Branch 13 → 14 taken 23578 times.
✗ Branch 13 → 38 not taken.
✓ Branch 14 → 15 taken 23578 times.
✗ Branch 14 → 38 not taken.
✓ Branch 15 → 16 taken 23578 times.
✗ Branch 15 → 36 not taken.
|
23578 | castExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1153 | 23578 | castExprNode->isCast = true; | |
| 1154 | } else { | ||
| 1155 | ✗ | castExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr())); | |
| 1156 | } | ||
| 1157 | |||
| 1158 |
1/2✓ Branch 29 → 30 taken 23578 times.
✗ Branch 29 → 42 not taken.
|
47156 | return concludeExprNode(castExprNode); |
| 1159 | } | ||
| 1160 | |||
| 1161 | 821647 | std::any ASTBuilder::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprContext *ctx) { | |
| 1162 |
2/2✓ Branch 3 → 4 taken 804899 times.
✓ Branch 3 → 6 taken 16748 times.
|
821647 | if (!ctx->prefixUnaryExpr()) |
| 1163 | 804899 | return visit(ctx->postfixUnaryExpr()); | |
| 1164 | |||
| 1165 | 16748 | const auto prefixUnaryExprNode = createNode<PrefixUnaryExprNode>(ctx); | |
| 1166 | |||
| 1167 | // Visit children | ||
| 1168 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 16748 times.
|
16748 | if (ctx->postfixUnaryExpr()) { |
| 1169 | ✗ | prefixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr())); | |
| 1170 |
1/2✓ Branch 15 → 16 taken 16748 times.
✗ Branch 15 → 42 not taken.
|
16748 | } else if (ctx->prefixUnaryExpr()) { |
| 1171 | // Extract operator | ||
| 1172 |
2/2✓ Branch 17 → 18 taken 475 times.
✓ Branch 17 → 19 taken 16273 times.
|
16748 | if (ctx->MINUS()) |
| 1173 | 475 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS; | |
| 1174 |
2/2✓ Branch 20 → 21 taken 24 times.
✓ Branch 20 → 22 taken 16249 times.
|
16273 | else if (ctx->PLUS_PLUS()) |
| 1175 | 24 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS; | |
| 1176 |
2/2✓ Branch 23 → 24 taken 166 times.
✓ Branch 23 → 25 taken 16083 times.
|
16249 | else if (ctx->MINUS_MINUS()) |
| 1177 | 166 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS; | |
| 1178 |
2/2✓ Branch 26 → 27 taken 10879 times.
✓ Branch 26 → 28 taken 5204 times.
|
16083 | else if (ctx->NOT()) |
| 1179 | 10879 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT; | |
| 1180 |
2/2✓ Branch 29 → 30 taken 54 times.
✓ Branch 29 → 31 taken 5150 times.
|
5204 | else if (ctx->BITWISE_NOT()) |
| 1181 | 54 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT; | |
| 1182 |
2/2✓ Branch 32 → 33 taken 2086 times.
✓ Branch 32 → 34 taken 3064 times.
|
5150 | else if (ctx->MUL()) |
| 1183 | 2086 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE; | |
| 1184 |
1/2✓ Branch 35 → 36 taken 3064 times.
✗ Branch 35 → 37 not taken.
|
3064 | else if (ctx->BITWISE_AND()) |
| 1185 | 3064 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF; | |
| 1186 | |||
| 1187 |
3/6✓ Branch 37 → 38 taken 16748 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 16748 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 16748 times.
✗ Branch 39 → 56 not taken.
|
16748 | prefixUnaryExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr())); |
| 1188 | } else { | ||
| 1189 | − | assert_fail("Unknown prefix unary expression type"); // GCOV_EXCL_LINE | |
| 1190 | } | ||
| 1191 | |||
| 1192 |
1/2✓ Branch 49 → 50 taken 16748 times.
✗ Branch 49 → 59 not taken.
|
33496 | return concludeExprNode(prefixUnaryExprNode); |
| 1193 | } | ||
| 1194 | |||
| 1195 | 1004960 | std::any ASTBuilder::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprContext *ctx) { | |
| 1196 |
2/2✓ Branch 3 → 4 taken 804899 times.
✓ Branch 3 → 6 taken 200061 times.
|
1004960 | if (!ctx->postfixUnaryExpr()) |
| 1197 | 804899 | return visit(ctx->atomicExpr()); | |
| 1198 | |||
| 1199 | 200061 | const auto postfixUnaryExprNode = createNode<PostfixUnaryExprNode>(ctx); | |
| 1200 | |||
| 1201 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 200061 times.
|
200061 | if (ctx->atomicExpr()) { |
| 1202 | ✗ | postfixUnaryExprNode->atomicExpr = std::any_cast<ExprNode *>(visit(ctx->atomicExpr())); | |
| 1203 |
1/2✓ Branch 15 → 16 taken 200061 times.
✗ Branch 15 → 43 not taken.
|
200061 | } else if (ctx->postfixUnaryExpr()) { |
| 1204 |
3/6✓ Branch 16 → 17 taken 200061 times.
✗ Branch 16 → 59 not taken.
✓ Branch 17 → 18 taken 200061 times.
✗ Branch 17 → 59 not taken.
✓ Branch 18 → 19 taken 200061 times.
✗ Branch 18 → 57 not taken.
|
200061 | postfixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr())); |
| 1205 | |||
| 1206 | // Extract operator | ||
| 1207 |
2/2✓ Branch 21 → 22 taken 18650 times.
✓ Branch 21 → 27 taken 181411 times.
|
200061 | if (ctx->assignExpr()) { |
| 1208 | 18650 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT; | |
| 1209 |
3/6✓ Branch 22 → 23 taken 18650 times.
✗ Branch 22 → 62 not taken.
✓ Branch 23 → 24 taken 18650 times.
✗ Branch 23 → 62 not taken.
✓ Branch 24 → 25 taken 18650 times.
✗ Branch 24 → 60 not taken.
|
18650 | postfixUnaryExprNode->subscriptIndexExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1210 |
2/2✓ Branch 28 → 29 taken 167920 times.
✓ Branch 28 → 34 taken 13491 times.
|
181411 | } else if (ctx->IDENTIFIER()) { |
| 1211 | 167920 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS; | |
| 1212 |
2/4✓ Branch 29 → 30 taken 167920 times.
✗ Branch 29 → 63 not taken.
✓ Branch 30 → 31 taken 167920 times.
✗ Branch 30 → 63 not taken.
|
167920 | postfixUnaryExprNode->identifier = getIdentifier(ctx->IDENTIFIER(), false); |
| 1213 |
2/2✓ Branch 35 → 36 taken 11526 times.
✓ Branch 35 → 37 taken 1965 times.
|
13491 | } else if (ctx->PLUS_PLUS()) { |
| 1214 | 11526 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS; | |
| 1215 |
2/2✓ Branch 38 → 39 taken 1711 times.
✓ Branch 38 → 40 taken 254 times.
|
1965 | } else if (ctx->MINUS_MINUS()) { |
| 1216 | 1711 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS; | |
| 1217 |
1/2✓ Branch 41 → 42 taken 254 times.
✗ Branch 41 → 44 not taken.
|
254 | } else if (ctx->NOT()) { |
| 1218 | 254 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_ERR_PROPAGATION; | |
| 1219 | } | ||
| 1220 | } else { | ||
| 1221 | − | assert_fail("Unknown postfix unary expression type"); // GCOV_EXCL_LINE | |
| 1222 | } | ||
| 1223 | |||
| 1224 |
1/2✓ Branch 50 → 51 taken 200061 times.
✗ Branch 50 → 64 not taken.
|
400122 | return concludeExprNode(postfixUnaryExprNode); |
| 1225 | } | ||
| 1226 | |||
| 1227 | 804899 | std::any ASTBuilder::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) { | |
| 1228 | 804899 | const auto atomicExprNode = createNode<AtomicExprNode>(ctx); | |
| 1229 | |||
| 1230 | // Visit children | ||
| 1231 |
2/2✓ Branch 4 → 5 taken 141664 times.
✓ Branch 4 → 10 taken 663235 times.
|
804899 | if (ctx->constant()) { |
| 1232 |
4/6✓ Branch 5 → 6 taken 141664 times.
✗ Branch 5 → 88 not taken.
✓ Branch 6 → 7 taken 141660 times.
✓ Branch 6 → 88 taken 4 times.
✓ Branch 7 → 8 taken 141660 times.
✗ Branch 7 → 86 not taken.
|
141664 | atomicExprNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 1233 |
2/2✓ Branch 11 → 12 taken 205642 times.
✓ Branch 11 → 17 taken 457593 times.
|
663235 | } else if (ctx->value()) { |
| 1234 |
3/6✓ Branch 12 → 13 taken 205642 times.
✗ Branch 12 → 91 not taken.
✓ Branch 13 → 14 taken 205642 times.
✗ Branch 13 → 91 not taken.
✓ Branch 14 → 15 taken 205642 times.
✗ Branch 14 → 89 not taken.
|
205642 | atomicExprNode->value = std::any_cast<ValueNode *>(visit(ctx->value())); |
| 1235 |
11/18✓ Branch 17 → 18 taken 457593 times.
✗ Branch 17 → 92 not taken.
✓ Branch 19 → 20 taken 33474 times.
✓ Branch 19 → 23 taken 424119 times.
✓ Branch 20 → 21 taken 33474 times.
✗ Branch 20 → 92 not taken.
✓ Branch 22 → 23 taken 28982 times.
✓ Branch 22 → 24 taken 4492 times.
✓ Branch 25 → 26 taken 33474 times.
✓ Branch 25 → 27 taken 424119 times.
✓ Branch 27 → 28 taken 457593 times.
✗ Branch 27 → 29 not taken.
✓ Branch 29 → 30 taken 453101 times.
✓ Branch 29 → 68 taken 4492 times.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 94 not taken.
✗ Branch 96 → 97 not taken.
✗ Branch 96 → 98 not taken.
|
457593 | } else if (!ctx->IDENTIFIER().empty() || !ctx->TYPE_IDENTIFIER().empty()) { |
| 1236 |
1/2✓ Branch 30 → 31 taken 453101 times.
✗ Branch 30 → 108 not taken.
|
453101 | std::stringstream fqIdentifier; |
| 1237 |
2/2✓ Branch 62 → 33 taken 486227 times.
✓ Branch 62 → 63 taken 453101 times.
|
1392429 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1238 |
1/2✓ Branch 35 → 36 taken 486227 times.
✗ Branch 35 → 37 not taken.
|
486227 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1239 |
1/2✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 486227 times.
|
486227 | if (!terminal) |
| 1240 | ✗ | continue; | |
| 1241 | |||
| 1242 |
2/4✓ Branch 40 → 41 taken 486227 times.
✗ Branch 40 → 104 not taken.
✓ Branch 41 → 42 taken 486227 times.
✗ Branch 41 → 104 not taken.
|
486227 | const size_t terminalType = terminal->getSymbol()->getType(); |
| 1243 |
4/4✓ Branch 42 → 43 taken 62108 times.
✓ Branch 42 → 44 taken 424119 times.
✓ Branch 43 → 44 taken 45545 times.
✓ Branch 43 → 53 taken 16563 times.
|
486227 | if (terminalType == SpiceParser::IDENTIFIER || terminalType == SpiceParser::TYPE_IDENTIFIER) { |
| 1244 |
1/2✓ Branch 44 → 45 taken 469664 times.
✗ Branch 44 → 103 not taken.
|
469664 | const std::string fragment = getIdentifier(terminal, false); |
| 1245 |
1/2✓ Branch 45 → 46 taken 469664 times.
✗ Branch 45 → 101 not taken.
|
469664 | atomicExprNode->identifierFragments.push_back(fragment); |
| 1246 |
3/4✓ Branch 46 → 47 taken 469664 times.
✗ Branch 46 → 100 not taken.
✓ Branch 48 → 49 taken 16563 times.
✓ Branch 48 → 50 taken 453101 times.
|
469664 | if (fqIdentifier.tellp() != 0) |
| 1247 |
1/2✓ Branch 49 → 50 taken 16563 times.
✗ Branch 49 → 101 not taken.
|
16563 | fqIdentifier << SCOPE_ACCESS_TOKEN; |
| 1248 |
1/2✓ Branch 50 → 51 taken 469664 times.
✗ Branch 50 → 101 not taken.
|
469664 | fqIdentifier << fragment; |
| 1249 | 469664 | } | |
| 1250 | } | ||
| 1251 |
1/2✓ Branch 63 → 64 taken 453101 times.
✗ Branch 63 → 105 not taken.
|
453101 | atomicExprNode->fqIdentifier = fqIdentifier.str(); |
| 1252 |
1/2✓ Branch 69 → 70 taken 4492 times.
✗ Branch 69 → 75 not taken.
|
457593 | } else if (ctx->assignExpr()) { |
| 1253 |
3/6✓ Branch 70 → 71 taken 4492 times.
✗ Branch 70 → 111 not taken.
✓ Branch 71 → 72 taken 4492 times.
✗ Branch 71 → 111 not taken.
✓ Branch 72 → 73 taken 4492 times.
✗ Branch 72 → 109 not taken.
|
4492 | atomicExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1254 | } else { | ||
| 1255 | − | assert_fail("Unknown atomic expression type"); // GCOV_EXCL_LINE | |
| 1256 | } | ||
| 1257 | |||
| 1258 |
1/2✓ Branch 82 → 83 taken 804895 times.
✗ Branch 82 → 112 not taken.
|
1609790 | return concludeExprNode(atomicExprNode); |
| 1259 | } | ||
| 1260 | |||
| 1261 | 205642 | std::any ASTBuilder::visitValue(SpiceParser::ValueContext *ctx) { | |
| 1262 | 205642 | const auto valueNode = createNode<ValueNode>(ctx); | |
| 1263 | |||
| 1264 | // Visit children | ||
| 1265 |
2/2✓ Branch 4 → 5 taken 179947 times.
✓ Branch 4 → 10 taken 25695 times.
|
205642 | if (ctx->fctCall()) { |
| 1266 |
3/6✓ Branch 5 → 6 taken 179947 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 179947 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 179947 times.
✗ Branch 7 → 63 not taken.
|
179947 | valueNode->fctCall = std::any_cast<FctCallNode *>(visit(ctx->fctCall())); |
| 1267 |
2/2✓ Branch 11 → 12 taken 958 times.
✓ Branch 11 → 17 taken 24737 times.
|
25695 | } else if (ctx->arrayInitialization()) { |
| 1268 |
3/6✓ Branch 12 → 13 taken 958 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 958 times.
✗ Branch 13 → 68 not taken.
✓ Branch 14 → 15 taken 958 times.
✗ Branch 14 → 66 not taken.
|
958 | valueNode->arrayInitialization = std::any_cast<ArrayInitializationNode *>(visit(ctx->arrayInitialization())); |
| 1269 |
2/2✓ Branch 18 → 19 taken 4433 times.
✓ Branch 18 → 24 taken 20304 times.
|
24737 | } else if (ctx->structInstantiation()) { |
| 1270 |
3/6✓ Branch 19 → 20 taken 4433 times.
✗ Branch 19 → 71 not taken.
✓ Branch 20 → 21 taken 4433 times.
✗ Branch 20 → 71 not taken.
✓ Branch 21 → 22 taken 4433 times.
✗ Branch 21 → 69 not taken.
|
4433 | valueNode->structInstantiation = std::any_cast<StructInstantiationNode *>(visit(ctx->structInstantiation())); |
| 1271 |
2/2✓ Branch 25 → 26 taken 109 times.
✓ Branch 25 → 31 taken 20195 times.
|
20304 | } else if (ctx->lambdaFunc()) { |
| 1272 |
3/6✓ Branch 26 → 27 taken 109 times.
✗ Branch 26 → 74 not taken.
✓ Branch 27 → 28 taken 109 times.
✗ Branch 27 → 74 not taken.
✓ Branch 28 → 29 taken 109 times.
✗ Branch 28 → 72 not taken.
|
109 | valueNode->lambdaFunc = std::any_cast<LambdaFuncNode *>(visit(ctx->lambdaFunc())); |
| 1273 |
2/2✓ Branch 32 → 33 taken 290 times.
✓ Branch 32 → 38 taken 19905 times.
|
20195 | } else if (ctx->lambdaProc()) { |
| 1274 |
3/6✓ Branch 33 → 34 taken 290 times.
✗ Branch 33 → 77 not taken.
✓ Branch 34 → 35 taken 290 times.
✗ Branch 34 → 77 not taken.
✓ Branch 35 → 36 taken 290 times.
✗ Branch 35 → 75 not taken.
|
290 | valueNode->lambdaProc = std::any_cast<LambdaProcNode *>(visit(ctx->lambdaProc())); |
| 1275 |
2/2✓ Branch 39 → 40 taken 2 times.
✓ Branch 39 → 45 taken 19903 times.
|
19905 | } else if (ctx->lambdaExpr()) { |
| 1276 |
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())); |
| 1277 |
1/2✓ Branch 46 → 47 taken 19903 times.
✗ Branch 46 → 52 not taken.
|
19903 | } else if (ctx->dataType()) { |
| 1278 | 19903 | valueNode->isNil = true; | |
| 1279 |
3/6✓ Branch 47 → 48 taken 19903 times.
✗ Branch 47 → 83 not taken.
✓ Branch 48 → 49 taken 19903 times.
✗ Branch 48 → 83 not taken.
✓ Branch 49 → 50 taken 19903 times.
✗ Branch 49 → 81 not taken.
|
19903 | valueNode->nilType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1280 | } else { | ||
| 1281 | − | assert_fail("Unknown value type"); // GCOV_EXCL_LINE | |
| 1282 | } | ||
| 1283 | |||
| 1284 |
1/2✓ Branch 59 → 60 taken 205642 times.
✗ Branch 59 → 84 not taken.
|
411284 | return concludeNode(valueNode); |
| 1285 | } | ||
| 1286 | |||
| 1287 | 161660 | std::any ASTBuilder::visitConstant(SpiceParser::ConstantContext *ctx) { | |
| 1288 | 161660 | const auto constantNode = createNode<ConstantNode>(ctx); | |
| 1289 | |||
| 1290 | // Detect an optional leading minus sign for numeric literals | ||
| 1291 | 161660 | const bool isNegative = ctx->MINUS() != nullptr; | |
| 1292 | |||
| 1293 | // Enrich | ||
| 1294 |
2/2✓ Branch 5 → 6 taken 4320 times.
✓ Branch 5 → 14 taken 157340 times.
|
161660 | if (ctx->DOUBLE_LIT()) { |
| 1295 | 4320 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_DOUBLE; | |
| 1296 |
3/6✓ Branch 6 → 7 taken 4320 times.
✗ Branch 6 → 63 not taken.
✓ Branch 7 → 8 taken 4320 times.
✗ Branch 7 → 63 not taken.
✓ Branch 8 → 9 taken 4320 times.
✗ Branch 8 → 61 not taken.
|
4320 | const double value = std::stod(ctx->DOUBLE_LIT()->toString()); |
| 1297 |
2/2✓ Branch 10 → 11 taken 328 times.
✓ Branch 10 → 12 taken 3992 times.
|
4320 | constantNode->compileTimeValue.doubleValue = isNegative ? -value : value; |
| 1298 |
2/2✓ Branch 15 → 16 taken 27556 times.
✓ Branch 15 → 19 taken 129784 times.
|
157340 | } else if (ctx->INT_LIT()) { |
| 1299 | 27556 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_INT; | |
| 1300 | 27556 | constantNode->compileTimeValue.intValue = parseInt(ctx->INT_LIT(), isNegative); | |
| 1301 |
2/2✓ Branch 20 → 21 taken 3106 times.
✓ Branch 20 → 24 taken 126678 times.
|
129784 | } else if (ctx->SHORT_LIT()) { |
| 1302 | 3106 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_SHORT; | |
| 1303 | 3106 | constantNode->compileTimeValue.shortValue = parseShort(ctx->SHORT_LIT(), isNegative); | |
| 1304 |
2/2✓ Branch 25 → 26 taken 50128 times.
✓ Branch 25 → 29 taken 76550 times.
|
126678 | } else if (ctx->LONG_LIT()) { |
| 1305 | 50128 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_LONG; | |
| 1306 | 50128 | constantNode->compileTimeValue.longValue = parseLong(ctx->LONG_LIT(), isNegative); | |
| 1307 |
2/2✓ Branch 30 → 31 taken 16129 times.
✓ Branch 30 → 34 taken 60421 times.
|
76550 | } else if (ctx->CHAR_LIT()) { |
| 1308 | 16129 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_CHAR; | |
| 1309 | 16129 | constantNode->compileTimeValue.charValue = parseChar(ctx->CHAR_LIT()); | |
| 1310 |
2/2✓ Branch 35 → 36 taken 42193 times.
✓ Branch 35 → 44 taken 18228 times.
|
60421 | } else if (ctx->STRING_LIT()) { |
| 1311 | // Save a pointer to the string in the compile time value | ||
| 1312 | 42193 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_STRING; | |
| 1313 | 42193 | constantNode->compileTimeValue.stringValueOffset = resourceManager.compileTimeStringValues.size(); | |
| 1314 | // Add the string to the global compile time string list | ||
| 1315 |
4/8✓ Branch 37 → 38 taken 42193 times.
✗ Branch 37 → 68 not taken.
✓ Branch 38 → 39 taken 42193 times.
✗ Branch 38 → 68 not taken.
✓ Branch 39 → 40 taken 42193 times.
✗ Branch 39 → 66 not taken.
✓ Branch 40 → 41 taken 42193 times.
✗ Branch 40 → 64 not taken.
|
42193 | resourceManager.compileTimeStringValues.push_back(parseString(ctx->STRING_LIT()->toString())); |
| 1316 |
2/2✓ Branch 45 → 46 taken 8167 times.
✓ Branch 45 → 47 taken 10061 times.
|
18228 | } else if (ctx->TRUE()) { |
| 1317 | 8167 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL; | |
| 1318 | 8167 | constantNode->compileTimeValue.boolValue = true; | |
| 1319 |
1/2✓ Branch 48 → 49 taken 10061 times.
✗ Branch 48 → 50 not taken.
|
10061 | } else if (ctx->FALSE()) { |
| 1320 | 10061 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL; | |
| 1321 | 10061 | constantNode->compileTimeValue.boolValue = false; | |
| 1322 | } else { | ||
| 1323 | − | assert_fail("Unknown constant type"); // GCOV_EXCL_LINE | |
| 1324 | } | ||
| 1325 | |||
| 1326 |
1/2✓ Branch 57 → 58 taken 161656 times.
✗ Branch 57 → 70 not taken.
|
323312 | return concludeNode(constantNode); |
| 1327 | } | ||
| 1328 | |||
| 1329 | 179947 | std::any ASTBuilder::visitFctCall(SpiceParser::FctCallContext *ctx) { | |
| 1330 |
1/2✓ Branch 2 → 3 taken 179947 times.
✗ Branch 2 → 92 not taken.
|
179947 | const auto fctCallNode = createNode<FctCallNode>(ctx); |
| 1331 | |||
| 1332 |
1/2✓ Branch 3 → 4 taken 179947 times.
✗ Branch 3 → 92 not taken.
|
179947 | std::stringstream fqFunctionName; |
| 1333 |
2/2✓ Branch 46 → 6 taken 899953 times.
✓ Branch 46 → 47 taken 179947 times.
|
1259847 | for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1334 |
1/2✓ Branch 8 → 9 taken 899953 times.
✗ Branch 8 → 10 not taken.
|
899953 | const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree); |
| 1335 |
2/2✓ Branch 11 → 12 taken 139074 times.
✓ Branch 11 → 13 taken 760879 times.
|
899953 | if (!terminal) |
| 1336 | 139074 | continue; | |
| 1337 | |||
| 1338 |
4/6✓ Branch 13 → 14 taken 760879 times.
✗ Branch 13 → 81 not taken.
✓ Branch 14 → 15 taken 760879 times.
✗ Branch 14 → 81 not taken.
✓ Branch 15 → 16 taken 247556 times.
✓ Branch 15 → 21 taken 513323 times.
|
760879 | if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) { |
| 1339 |
1/2✓ Branch 16 → 17 taken 247556 times.
✗ Branch 16 → 77 not taken.
|
247556 | const std::string fragment = terminal->toString(); |
| 1340 |
1/2✓ Branch 17 → 18 taken 247556 times.
✗ Branch 17 → 75 not taken.
|
247556 | fctCallNode->functionNameFragments.push_back(fragment); |
| 1341 |
1/2✓ Branch 18 → 19 taken 247556 times.
✗ Branch 18 → 75 not taken.
|
247556 | fqFunctionName << fragment; |
| 1342 |
4/6✓ Branch 21 → 22 taken 513323 times.
✗ Branch 21 → 81 not taken.
✓ Branch 22 → 23 taken 513323 times.
✗ Branch 22 → 81 not taken.
✓ Branch 23 → 24 taken 33293 times.
✓ Branch 23 → 29 taken 480030 times.
|
760879 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1343 |
1/2✓ Branch 24 → 25 taken 33293 times.
✗ Branch 24 → 80 not taken.
|
33293 | const std::string fragment = terminal->toString(); |
| 1344 |
1/2✓ Branch 25 → 26 taken 33293 times.
✗ Branch 25 → 78 not taken.
|
33293 | fctCallNode->functionNameFragments.push_back(fragment); |
| 1345 |
1/2✓ Branch 26 → 27 taken 33293 times.
✗ Branch 26 → 78 not taken.
|
33293 | fqFunctionName << fragment; |
| 1346 |
4/6✓ Branch 29 → 30 taken 480030 times.
✗ Branch 29 → 81 not taken.
✓ Branch 30 → 31 taken 480030 times.
✗ Branch 30 → 81 not taken.
✓ Branch 31 → 32 taken 366 times.
✓ Branch 31 → 33 taken 479664 times.
|
513323 | } else if (terminal->getSymbol()->getType() == SpiceParser::SCOPE_ACCESS) { |
| 1347 |
1/2✓ Branch 32 → 37 taken 366 times.
✗ Branch 32 → 81 not taken.
|
366 | fqFunctionName << SCOPE_ACCESS_TOKEN; |
| 1348 |
4/6✓ Branch 33 → 34 taken 479664 times.
✗ Branch 33 → 81 not taken.
✓ Branch 34 → 35 taken 479664 times.
✗ Branch 34 → 81 not taken.
✓ Branch 35 → 36 taken 100536 times.
✓ Branch 35 → 37 taken 379128 times.
|
479664 | } else if (terminal->getSymbol()->getType() == SpiceParser::DOT) { |
| 1349 |
1/2✓ Branch 36 → 37 taken 100536 times.
✗ Branch 36 → 81 not taken.
|
100536 | fqFunctionName << MEMBER_ACCESS_TOKEN; |
| 1350 | } | ||
| 1351 | } | ||
| 1352 |
1/2✓ Branch 47 → 48 taken 179947 times.
✗ Branch 47 → 82 not taken.
|
179947 | fctCallNode->fqFunctionName = fqFunctionName.str(); |
| 1353 | |||
| 1354 | // Visit children | ||
| 1355 |
3/4✓ Branch 50 → 51 taken 179947 times.
✗ Branch 50 → 90 not taken.
✓ Branch 51 → 52 taken 9617 times.
✓ Branch 51 → 57 taken 170330 times.
|
179947 | if (ctx->typeLst()) { |
| 1356 | 9617 | fctCallNode->hasTemplateTypes = true; | |
| 1357 |
3/6✓ Branch 52 → 53 taken 9617 times.
✗ Branch 52 → 85 not taken.
✓ Branch 53 → 54 taken 9617 times.
✗ Branch 53 → 85 not taken.
✓ Branch 54 → 55 taken 9617 times.
✗ Branch 54 → 83 not taken.
|
9617 | fctCallNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1358 | } | ||
| 1359 |
3/4✓ Branch 57 → 58 taken 179947 times.
✗ Branch 57 → 90 not taken.
✓ Branch 58 → 59 taken 129457 times.
✓ Branch 58 → 64 taken 50490 times.
|
179947 | if (ctx->argLst()) { |
| 1360 | 129457 | fctCallNode->hasArgs = true; | |
| 1361 |
3/6✓ Branch 59 → 60 taken 129457 times.
✗ Branch 59 → 88 not taken.
✓ Branch 60 → 61 taken 129457 times.
✗ Branch 60 → 88 not taken.
✓ Branch 61 → 62 taken 129457 times.
✗ Branch 61 → 86 not taken.
|
129457 | fctCallNode->argLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1362 | } | ||
| 1363 | |||
| 1364 |
1/2✓ Branch 70 → 71 taken 179947 times.
✗ Branch 70 → 89 not taken.
|
359894 | return concludeNode(fctCallNode); |
| 1365 | 179947 | } | |
| 1366 | |||
| 1367 | 958 | std::any ASTBuilder::visitArrayInitialization(SpiceParser::ArrayInitializationContext *ctx) { | |
| 1368 | 958 | const auto arrayInitializationNode = createNode<ArrayInitializationNode>(ctx); | |
| 1369 | |||
| 1370 | // Visit children | ||
| 1371 |
2/2✓ Branch 4 → 5 taken 956 times.
✓ Branch 4 → 10 taken 2 times.
|
958 | if (ctx->argLst()) |
| 1372 |
3/6✓ Branch 5 → 6 taken 956 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 956 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 956 times.
✗ Branch 7 → 20 not taken.
|
956 | arrayInitializationNode->itemLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1373 | |||
| 1374 |
1/2✓ Branch 16 → 17 taken 958 times.
✗ Branch 16 → 23 not taken.
|
1916 | return concludeNode(arrayInitializationNode); |
| 1375 | } | ||
| 1376 | |||
| 1377 | 4433 | std::any ASTBuilder::visitStructInstantiation(SpiceParser::StructInstantiationContext *ctx) { | |
| 1378 |
1/2✓ Branch 2 → 3 taken 4433 times.
✗ Branch 2 → 85 not taken.
|
4433 | const auto structInstantiationNode = createNode<StructInstantiationNode>(ctx); |
| 1379 | |||
| 1380 | // Enrich | ||
| 1381 |
1/2✓ Branch 3 → 4 taken 4433 times.
✗ Branch 3 → 85 not taken.
|
4433 | std::stringstream fqStructName; |
| 1382 |
2/2✓ Branch 39 → 6 taken 17715 times.
✓ Branch 39 → 40 taken 4433 times.
|
26581 | for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1383 |
1/2✓ Branch 8 → 9 taken 17715 times.
✗ Branch 8 → 10 not taken.
|
17715 | const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree); |
| 1384 |
2/2✓ Branch 11 → 12 taken 4362 times.
✓ Branch 11 → 13 taken 13353 times.
|
17715 | if (!terminal) |
| 1385 | 4362 | continue; | |
| 1386 | |||
| 1387 |
4/6✓ Branch 13 → 14 taken 13353 times.
✗ Branch 13 → 74 not taken.
✓ Branch 14 → 15 taken 13353 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 6 times.
✓ Branch 15 → 22 taken 13347 times.
|
13353 | if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) { |
| 1388 |
1/2✓ Branch 16 → 17 taken 6 times.
✗ Branch 16 → 70 not taken.
|
6 | const std::string fragment = terminal->toString(); |
| 1389 |
1/2✓ Branch 17 → 18 taken 6 times.
✗ Branch 17 → 68 not taken.
|
6 | structInstantiationNode->structNameFragments.push_back(fragment); |
| 1390 |
2/4✓ Branch 18 → 19 taken 6 times.
✗ Branch 18 → 68 not taken.
✓ Branch 19 → 20 taken 6 times.
✗ Branch 19 → 68 not taken.
|
6 | fqStructName << fragment << SCOPE_ACCESS_TOKEN; |
| 1391 |
4/6✓ Branch 22 → 23 taken 13347 times.
✗ Branch 22 → 74 not taken.
✓ Branch 23 → 24 taken 13347 times.
✗ Branch 23 → 74 not taken.
✓ Branch 24 → 25 taken 4433 times.
✓ Branch 24 → 30 taken 8914 times.
|
13353 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1392 |
1/2✓ Branch 25 → 26 taken 4433 times.
✗ Branch 25 → 73 not taken.
|
4433 | const std::string fragment = terminal->toString(); |
| 1393 |
1/2✓ Branch 26 → 27 taken 4433 times.
✗ Branch 26 → 71 not taken.
|
4433 | structInstantiationNode->structNameFragments.push_back(fragment); |
| 1394 |
1/2✓ Branch 27 → 28 taken 4433 times.
✗ Branch 27 → 71 not taken.
|
4433 | fqStructName << fragment; |
| 1395 | 4433 | } | |
| 1396 | } | ||
| 1397 |
1/2✓ Branch 40 → 41 taken 4433 times.
✗ Branch 40 → 75 not taken.
|
4433 | structInstantiationNode->fqStructName = fqStructName.str(); |
| 1398 | |||
| 1399 | // Visit children | ||
| 1400 |
3/4✓ Branch 43 → 44 taken 4433 times.
✗ Branch 43 → 83 not taken.
✓ Branch 44 → 45 taken 21 times.
✓ Branch 44 → 50 taken 4412 times.
|
4433 | if (ctx->typeLst()) { |
| 1401 | 21 | structInstantiationNode->hasTemplateTypes = true; | |
| 1402 |
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())); |
| 1403 | } | ||
| 1404 |
3/4✓ Branch 50 → 51 taken 4433 times.
✗ Branch 50 → 83 not taken.
✓ Branch 51 → 52 taken 4341 times.
✓ Branch 51 → 57 taken 92 times.
|
4433 | if (ctx->argLst()) |
| 1405 |
3/6✓ Branch 52 → 53 taken 4341 times.
✗ Branch 52 → 81 not taken.
✓ Branch 53 → 54 taken 4341 times.
✗ Branch 53 → 81 not taken.
✓ Branch 54 → 55 taken 4341 times.
✗ Branch 54 → 79 not taken.
|
4341 | structInstantiationNode->fieldLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1406 | |||
| 1407 |
1/2✓ Branch 63 → 64 taken 4433 times.
✗ Branch 63 → 82 not taken.
|
8866 | return concludeNode(structInstantiationNode); |
| 1408 | 4433 | } | |
| 1409 | |||
| 1410 | 109 | std::any ASTBuilder::visitLambdaFunc(SpiceParser::LambdaFuncContext *ctx) { | |
| 1411 | 109 | const auto lambdaFuncNode = createNode<LambdaFuncNode>(ctx); | |
| 1412 | |||
| 1413 | // Visit children | ||
| 1414 |
3/6✓ Branch 3 → 4 taken 109 times.
✗ Branch 3 → 37 not taken.
✓ Branch 4 → 5 taken 109 times.
✗ Branch 4 → 37 not taken.
✓ Branch 5 → 6 taken 109 times.
✗ Branch 5 → 35 not taken.
|
109 | lambdaFuncNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1415 |
2/2✓ Branch 8 → 9 taken 99 times.
✓ Branch 8 → 14 taken 10 times.
|
109 | if (ctx->paramLst()) { |
| 1416 | 99 | lambdaFuncNode->hasParams = true; | |
| 1417 |
3/6✓ Branch 9 → 10 taken 99 times.
✗ Branch 9 → 40 not taken.
✓ Branch 10 → 11 taken 99 times.
✗ Branch 10 → 40 not taken.
✓ Branch 11 → 12 taken 99 times.
✗ Branch 11 → 38 not taken.
|
99 | lambdaFuncNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 1418 | } | ||
| 1419 |
1/2✗ Branch 15 → 16 not taken.
✓ Branch 15 → 21 taken 109 times.
|
109 | if (ctx->lambdaAttr()) |
| 1420 | ✗ | lambdaFuncNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr())); | |
| 1421 |
4/8✓ Branch 21 → 22 taken 109 times.
✗ Branch 21 → 46 not taken.
✓ Branch 22 → 23 taken 109 times.
✗ Branch 22 → 46 not taken.
✓ Branch 23 → 24 taken 109 times.
✗ Branch 23 → 44 not taken.
✓ Branch 25 → 26 taken 109 times.
✗ Branch 25 → 47 not taken.
|
109 | lambdaFuncNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 1422 | |||
| 1423 |
1/2✓ Branch 31 → 32 taken 109 times.
✗ Branch 31 → 47 not taken.
|
218 | return concludeNode(lambdaFuncNode); |
| 1424 | } | ||
| 1425 | |||
| 1426 | 290 | std::any ASTBuilder::visitLambdaProc(SpiceParser::LambdaProcContext *ctx) { | |
| 1427 | 290 | const auto lambdaProcNode = createNode<LambdaProcNode>(ctx); | |
| 1428 | |||
| 1429 | // Visit children | ||
| 1430 |
2/2✓ Branch 4 → 5 taken 218 times.
✓ Branch 4 → 10 taken 72 times.
|
290 | if (ctx->paramLst()) { |
| 1431 | 218 | lambdaProcNode->hasParams = true; | |
| 1432 |
3/6✓ Branch 5 → 6 taken 218 times.
✗ Branch 5 → 33 not taken.
✓ Branch 6 → 7 taken 218 times.
✗ Branch 6 → 33 not taken.
✓ Branch 7 → 8 taken 218 times.
✗ Branch 7 → 31 not taken.
|
218 | lambdaProcNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 1433 | } | ||
| 1434 |
2/2✓ Branch 11 → 12 taken 16 times.
✓ Branch 11 → 17 taken 274 times.
|
290 | if (ctx->lambdaAttr()) |
| 1435 |
3/6✓ Branch 12 → 13 taken 16 times.
✗ Branch 12 → 36 not taken.
✓ Branch 13 → 14 taken 16 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 16 times.
✗ Branch 14 → 34 not taken.
|
16 | lambdaProcNode->lambdaAttr = std::any_cast<LambdaAttrNode *>(visit(ctx->lambdaAttr())); |
| 1436 |
4/8✓ Branch 17 → 18 taken 290 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 290 times.
✗ Branch 18 → 39 not taken.
✓ Branch 19 → 20 taken 290 times.
✗ Branch 19 → 37 not taken.
✓ Branch 21 → 22 taken 290 times.
✗ Branch 21 → 40 not taken.
|
290 | lambdaProcNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 1437 | |||
| 1438 |
1/2✓ Branch 27 → 28 taken 290 times.
✗ Branch 27 → 40 not taken.
|
580 | return concludeNode(lambdaProcNode); |
| 1439 | } | ||
| 1440 | |||
| 1441 | 2 | std::any ASTBuilder::visitLambdaExpr(SpiceParser::LambdaExprContext *ctx) { | |
| 1442 | 2 | const auto lambdaExprNode = createNode<LambdaExprNode>(ctx); | |
| 1443 | |||
| 1444 | // Visit children | ||
| 1445 |
1/2✓ Branch 4 → 5 taken 2 times.
✗ Branch 4 → 10 not taken.
|
2 | if (ctx->paramLst()) { |
| 1446 | 2 | lambdaExprNode->hasParams = true; | |
| 1447 |
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())); |
| 1448 | } | ||
| 1449 |
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())); |
| 1450 | |||
| 1451 |
1/2✓ Branch 20 → 21 taken 2 times.
✗ Branch 20 → 30 not taken.
|
4 | return concludeNode(lambdaExprNode); |
| 1452 | } | ||
| 1453 | |||
| 1454 | 439394 | std::any ASTBuilder::visitDataType(SpiceParser::DataTypeContext *ctx) { | |
| 1455 | 439394 | const auto dataTypeNode = createNode<DataTypeNode>(ctx); | |
| 1456 | |||
| 1457 | // Visit children | ||
| 1458 |
2/2✓ Branch 4 → 5 taken 161138 times.
✓ Branch 4 → 10 taken 278256 times.
|
439394 | if (ctx->qualifierLst()) |
| 1459 |
4/6✓ Branch 5 → 6 taken 161138 times.
✗ Branch 5 → 73 not taken.
✓ Branch 6 → 7 taken 161136 times.
✓ Branch 6 → 73 taken 2 times.
✓ Branch 7 → 8 taken 161136 times.
✗ Branch 7 → 71 not taken.
|
161138 | dataTypeNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 1460 |
3/6✓ Branch 10 → 11 taken 439392 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 439392 times.
✗ Branch 11 → 76 not taken.
✓ Branch 12 → 13 taken 439392 times.
✗ Branch 12 → 74 not taken.
|
439392 | dataTypeNode->baseDataType = std::any_cast<BaseDataTypeNode *>(visit(ctx->baseDataType())); |
| 1461 | |||
| 1462 | // Enrich | ||
| 1463 |
2/2✓ Branch 60 → 15 taken 728045 times.
✓ Branch 60 → 61 taken 439392 times.
|
1167437 | for (size_t i = 0; i < ctx->children.size(); i++) { |
| 1464 | 728045 | antlr4::tree::ParseTree *subTree = ctx->children.at(i); | |
| 1465 |
1/2✓ Branch 16 → 17 taken 728045 times.
✗ Branch 16 → 18 not taken.
|
728045 | auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1466 |
2/2✓ Branch 19 → 20 taken 600528 times.
✓ Branch 19 → 21 taken 127517 times.
|
728045 | if (!terminal) |
| 1467 | 600528 | continue; | |
| 1468 | |||
| 1469 |
2/2✓ Branch 23 → 24 taken 77381 times.
✓ Branch 23 → 26 taken 50136 times.
|
127517 | if (terminal->getSymbol()->getType() == SpiceParser::MUL) { |
| 1470 |
1/2✓ Branch 24 → 25 taken 77381 times.
✗ Branch 24 → 77 not taken.
|
77381 | dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_PTR, false, 0); |
| 1471 |
2/2✓ Branch 28 → 29 taken 48931 times.
✓ Branch 28 → 31 taken 1205 times.
|
50136 | } else if (terminal->getSymbol()->getType() == SpiceParser::BITWISE_AND) { |
| 1472 |
1/2✓ Branch 29 → 30 taken 48931 times.
✗ Branch 29 → 80 not taken.
|
48931 | dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_REF, false, 0); |
| 1473 |
1/2✓ Branch 33 → 34 taken 1205 times.
✗ Branch 33 → 58 not taken.
|
1205 | } else if (terminal->getSymbol()->getType() == SpiceParser::LBRACKET) { |
| 1474 | 1205 | i++; // Consume LBRACKET | |
| 1475 |
1/2✓ Branch 34 → 35 taken 1205 times.
✗ Branch 34 → 92 not taken.
|
1205 | subTree = ctx->children.at(i); |
| 1476 |
1/2✓ Branch 35 → 36 taken 1205 times.
✗ Branch 35 → 37 not taken.
|
1205 | terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1477 | 1205 | bool hasSize = false; | |
| 1478 | 1205 | unsigned int hardCodedSize = 0; | |
| 1479 | 1205 | std::string sizeVarName; | |
| 1480 |
4/6✓ Branch 39 → 40 taken 1205 times.
✗ Branch 39 → 90 not taken.
✓ Branch 40 → 41 taken 1205 times.
✗ Branch 40 → 90 not taken.
✓ Branch 41 → 42 taken 244 times.
✓ Branch 41 → 46 taken 961 times.
|
1205 | if (terminal->getSymbol()->getType() == SpiceParser::INT_LIT) { |
| 1481 | 244 | hasSize = true; | |
| 1482 |
2/4✓ Branch 42 → 43 taken 244 times.
✗ Branch 42 → 85 not taken.
✓ Branch 43 → 44 taken 244 times.
✗ Branch 43 → 83 not taken.
|
244 | hardCodedSize = std::stoi(terminal->getText()); |
| 1483 | 244 | i++; // Consume INT_LIT | |
| 1484 |
4/6✓ Branch 46 → 47 taken 961 times.
✗ Branch 46 → 90 not taken.
✓ Branch 47 → 48 taken 961 times.
✗ Branch 47 → 90 not taken.
✓ Branch 48 → 49 taken 689 times.
✓ Branch 48 → 53 taken 272 times.
|
961 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1485 | 689 | hasSize = true; | |
| 1486 |
1/2✓ Branch 49 → 50 taken 689 times.
✗ Branch 49 → 86 not taken.
|
689 | sizeVarName = getIdentifier(terminal, true); |
| 1487 | 689 | i++; // Consume TYPE_IDENTIFIER | |
| 1488 | } | ||
| 1489 |
1/2✓ Branch 54 → 55 taken 1205 times.
✗ Branch 54 → 87 not taken.
|
1205 | dataTypeNode->tmQueue.push({DataTypeNode::TypeModifierType::TYPE_ARRAY, hasSize, hardCodedSize, sizeVarName}); |
| 1490 | 1205 | } | |
| 1491 | } | ||
| 1492 | |||
| 1493 |
1/2✓ Branch 67 → 68 taken 439392 times.
✗ Branch 67 → 93 not taken.
|
878784 | return concludeNode(dataTypeNode); |
| 1494 |
1/2✓ Branch 53 → 54 taken 1205 times.
✗ Branch 53 → 89 not taken.
|
1205 | } |
| 1495 | |||
| 1496 | 439392 | std::any ASTBuilder::visitBaseDataType(SpiceParser::BaseDataTypeContext *ctx) { | |
| 1497 | 439392 | const auto baseDataTypeNode = createNode<BaseDataTypeNode>(ctx); | |
| 1498 | |||
| 1499 | // Enrich | ||
| 1500 |
2/2✓ Branch 4 → 5 taken 4769 times.
✓ Branch 4 → 6 taken 434623 times.
|
439392 | if (ctx->TYPE_DOUBLE()) { |
| 1501 | 4769 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DOUBLE; | |
| 1502 |
2/2✓ Branch 7 → 8 taken 29800 times.
✓ Branch 7 → 9 taken 404823 times.
|
434623 | } else if (ctx->TYPE_INT()) { |
| 1503 | 29800 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_INT; | |
| 1504 |
2/2✓ Branch 10 → 11 taken 5708 times.
✓ Branch 10 → 12 taken 399115 times.
|
404823 | } else if (ctx->TYPE_SHORT()) { |
| 1505 | 5708 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_SHORT; | |
| 1506 |
2/2✓ Branch 13 → 14 taken 56621 times.
✓ Branch 13 → 15 taken 342494 times.
|
399115 | } else if (ctx->TYPE_LONG()) { |
| 1507 | 56621 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_LONG; | |
| 1508 |
2/2✓ Branch 16 → 17 taken 21822 times.
✓ Branch 16 → 18 taken 320672 times.
|
342494 | } else if (ctx->TYPE_BYTE()) { |
| 1509 | 21822 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BYTE; | |
| 1510 |
2/2✓ Branch 19 → 20 taken 34197 times.
✓ Branch 19 → 21 taken 286475 times.
|
320672 | } else if (ctx->TYPE_CHAR()) { |
| 1511 | 34197 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CHAR; | |
| 1512 |
2/2✓ Branch 22 → 23 taken 35972 times.
✓ Branch 22 → 24 taken 250503 times.
|
286475 | } else if (ctx->TYPE_STRING()) { |
| 1513 | 35972 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_STRING; | |
| 1514 |
2/2✓ Branch 25 → 26 taken 31904 times.
✓ Branch 25 → 27 taken 218599 times.
|
250503 | } else if (ctx->TYPE_BOOL()) { |
| 1515 | 31904 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BOOL; | |
| 1516 |
2/2✓ Branch 28 → 29 taken 3972 times.
✓ Branch 28 → 30 taken 214627 times.
|
218599 | } else if (ctx->TYPE_DYN()) { |
| 1517 | 3972 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DYN; | |
| 1518 |
2/2✓ Branch 31 → 32 taken 213417 times.
✓ Branch 31 → 37 taken 1210 times.
|
214627 | } else if (ctx->customDataType()) { |
| 1519 | 213417 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CUSTOM; | |
| 1520 |
3/6✓ Branch 32 → 33 taken 213417 times.
✗ Branch 32 → 57 not taken.
✓ Branch 33 → 34 taken 213417 times.
✗ Branch 33 → 57 not taken.
✓ Branch 34 → 35 taken 213417 times.
✗ Branch 34 → 55 not taken.
|
213417 | baseDataTypeNode->customDataType = std::any_cast<CustomDataTypeNode *>(visit(ctx->customDataType())); |
| 1521 |
1/2✓ Branch 38 → 39 taken 1210 times.
✗ Branch 38 → 44 not taken.
|
1210 | } else if (ctx->functionDataType()) { |
| 1522 | 1210 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_FUNCTION; | |
| 1523 |
3/6✓ Branch 39 → 40 taken 1210 times.
✗ Branch 39 → 60 not taken.
✓ Branch 40 → 41 taken 1210 times.
✗ Branch 40 → 60 not taken.
✓ Branch 41 → 42 taken 1210 times.
✗ Branch 41 → 58 not taken.
|
1210 | baseDataTypeNode->functionDataType = std::any_cast<FunctionDataTypeNode *>(visit(ctx->functionDataType())); |
| 1524 | } else { | ||
| 1525 | ✗ | assert_fail("Unknown base data type"); | |
| 1526 | } | ||
| 1527 | |||
| 1528 |
1/2✓ Branch 51 → 52 taken 439392 times.
✗ Branch 51 → 61 not taken.
|
878784 | return concludeNode(baseDataTypeNode); |
| 1529 | } | ||
| 1530 | |||
| 1531 | 213417 | std::any ASTBuilder::visitCustomDataType(SpiceParser::CustomDataTypeContext *ctx) { | |
| 1532 |
1/2✓ Branch 2 → 3 taken 213417 times.
✗ Branch 2 → 75 not taken.
|
213417 | const auto customDataTypeNode = createNode<CustomDataTypeNode>(ctx); |
| 1533 | |||
| 1534 | // Enrich | ||
| 1535 |
1/2✓ Branch 3 → 4 taken 213417 times.
✗ Branch 3 → 75 not taken.
|
213417 | std::stringstream fqTypeName; |
| 1536 |
2/2✓ Branch 39 → 6 taken 283033 times.
✓ Branch 39 → 40 taken 213417 times.
|
709867 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1537 |
1/2✓ Branch 8 → 9 taken 283033 times.
✗ Branch 8 → 10 not taken.
|
283033 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1538 |
2/2✓ Branch 11 → 12 taken 22976 times.
✓ Branch 11 → 13 taken 260057 times.
|
283033 | if (!terminal) |
| 1539 | 22976 | continue; | |
| 1540 | |||
| 1541 |
4/6✓ Branch 13 → 14 taken 260057 times.
✗ Branch 13 → 67 not taken.
✓ Branch 14 → 15 taken 260057 times.
✗ Branch 14 → 67 not taken.
✓ Branch 15 → 16 taken 344 times.
✓ Branch 15 → 22 taken 259713 times.
|
260057 | if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) { |
| 1542 |
1/2✓ Branch 16 → 17 taken 344 times.
✗ Branch 16 → 63 not taken.
|
344 | const std::string fragment = terminal->toString(); |
| 1543 |
1/2✓ Branch 17 → 18 taken 344 times.
✗ Branch 17 → 61 not taken.
|
344 | customDataTypeNode->typeNameFragments.push_back(fragment); |
| 1544 |
2/4✓ Branch 18 → 19 taken 344 times.
✗ Branch 18 → 61 not taken.
✓ Branch 19 → 20 taken 344 times.
✗ Branch 19 → 61 not taken.
|
344 | fqTypeName << fragment << SCOPE_ACCESS_TOKEN; |
| 1545 |
4/6✓ Branch 22 → 23 taken 259713 times.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 259713 times.
✗ Branch 23 → 67 not taken.
✓ Branch 24 → 25 taken 213417 times.
✓ Branch 24 → 30 taken 46296 times.
|
260057 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1546 |
1/2✓ Branch 25 → 26 taken 213417 times.
✗ Branch 25 → 66 not taken.
|
213417 | const std::string fragment = terminal->toString(); |
| 1547 |
1/2✓ Branch 26 → 27 taken 213417 times.
✗ Branch 26 → 64 not taken.
|
213417 | customDataTypeNode->typeNameFragments.push_back(fragment); |
| 1548 |
1/2✓ Branch 27 → 28 taken 213417 times.
✗ Branch 27 → 64 not taken.
|
213417 | fqTypeName << fragment; |
| 1549 | 213417 | } | |
| 1550 | } | ||
| 1551 |
1/2✓ Branch 40 → 41 taken 213417 times.
✗ Branch 40 → 68 not taken.
|
213417 | customDataTypeNode->fqTypeName = fqTypeName.str(); |
| 1552 | |||
| 1553 | // Visit children | ||
| 1554 |
3/4✓ Branch 43 → 44 taken 213417 times.
✗ Branch 43 → 73 not taken.
✓ Branch 44 → 45 taken 22976 times.
✓ Branch 44 → 50 taken 190441 times.
|
213417 | if (ctx->typeLst()) |
| 1555 |
3/6✓ Branch 45 → 46 taken 22976 times.
✗ Branch 45 → 71 not taken.
✓ Branch 46 → 47 taken 22976 times.
✗ Branch 46 → 71 not taken.
✓ Branch 47 → 48 taken 22976 times.
✗ Branch 47 → 69 not taken.
|
22976 | customDataTypeNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1556 | |||
| 1557 |
1/2✓ Branch 56 → 57 taken 213417 times.
✗ Branch 56 → 72 not taken.
|
426834 | return concludeNode(customDataTypeNode); |
| 1558 | 213417 | } | |
| 1559 | |||
| 1560 | 1210 | std::any ASTBuilder::visitFunctionDataType(SpiceParser::FunctionDataTypeContext *ctx) { | |
| 1561 | 1210 | const auto functionDataTypeNode = createNode<FunctionDataTypeNode>(ctx); | |
| 1562 | |||
| 1563 | // Enrich | ||
| 1564 |
2/2✓ Branch 4 → 5 taken 638 times.
✓ Branch 4 → 11 taken 572 times.
|
1210 | if (ctx->dataType()) { |
| 1565 | 638 | functionDataTypeNode->isFunction = ctx->dataType(); | |
| 1566 |
3/6✓ Branch 6 → 7 taken 638 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 638 times.
✗ Branch 7 → 30 not taken.
✓ Branch 8 → 9 taken 638 times.
✗ Branch 8 → 28 not taken.
|
638 | functionDataTypeNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1567 | } | ||
| 1568 |
2/2✓ Branch 12 → 13 taken 1004 times.
✓ Branch 12 → 18 taken 206 times.
|
1210 | if (ctx->typeLst()) |
| 1569 |
3/6✓ Branch 13 → 14 taken 1004 times.
✗ Branch 13 → 33 not taken.
✓ Branch 14 → 15 taken 1004 times.
✗ Branch 14 → 33 not taken.
✓ Branch 15 → 16 taken 1004 times.
✗ Branch 15 → 31 not taken.
|
1004 | functionDataTypeNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1570 | |||
| 1571 |
1/2✓ Branch 24 → 25 taken 1210 times.
✗ Branch 24 → 34 not taken.
|
2420 | return concludeNode(functionDataTypeNode); |
| 1572 | } | ||
| 1573 | |||
| 1574 | 62068 | std::any ASTBuilder::visitAssignOp(SpiceParser::AssignOpContext *ctx) { | |
| 1575 | 62068 | const auto assignExprNode = resumeForExpansion<AssignExprNode>(); | |
| 1576 | |||
| 1577 | // Extract assign operator | ||
| 1578 |
2/2✓ Branch 15 → 16 taken 54391 times.
✓ Branch 15 → 17 taken 7677 times.
|
62068 | if (ctx->ASSIGN()) |
| 1579 | 54391 | assignExprNode->op = AssignExprNode::AssignOp::OP_ASSIGN; | |
| 1580 |
2/2✓ Branch 18 → 19 taken 5322 times.
✓ Branch 18 → 20 taken 2355 times.
|
7677 | else if (ctx->PLUS_EQUAL()) |
| 1581 | 5322 | assignExprNode->op = AssignExprNode::AssignOp::OP_PLUS_EQUAL; | |
| 1582 |
2/2✓ Branch 21 → 22 taken 347 times.
✓ Branch 21 → 23 taken 2008 times.
|
2355 | else if (ctx->MINUS_EQUAL()) |
| 1583 | 347 | assignExprNode->op = AssignExprNode::AssignOp::OP_MINUS_EQUAL; | |
| 1584 |
2/2✓ Branch 24 → 25 taken 627 times.
✓ Branch 24 → 26 taken 1381 times.
|
2008 | else if (ctx->MUL_EQUAL()) |
| 1585 | 627 | assignExprNode->op = AssignExprNode::AssignOp::OP_MUL_EQUAL; | |
| 1586 |
2/2✓ Branch 27 → 28 taken 372 times.
✓ Branch 27 → 29 taken 1009 times.
|
1381 | else if (ctx->DIV_EQUAL()) |
| 1587 | 372 | assignExprNode->op = AssignExprNode::AssignOp::OP_DIV_EQUAL; | |
| 1588 |
2/2✓ Branch 30 → 31 taken 72 times.
✓ Branch 30 → 32 taken 937 times.
|
1009 | else if (ctx->REM_EQUAL()) |
| 1589 | 72 | assignExprNode->op = AssignExprNode::AssignOp::OP_REM_EQUAL; | |
| 1590 |
2/2✓ Branch 33 → 34 taken 6 times.
✓ Branch 33 → 35 taken 931 times.
|
937 | else if (ctx->SHL_EQUAL()) |
| 1591 | 6 | assignExprNode->op = AssignExprNode::AssignOp::OP_SHL_EQUAL; | |
| 1592 |
2/2✓ Branch 36 → 37 taken 16 times.
✓ Branch 36 → 38 taken 915 times.
|
931 | else if (ctx->SHR_EQUAL()) |
| 1593 | 16 | assignExprNode->op = AssignExprNode::AssignOp::OP_SHR_EQUAL; | |
| 1594 |
2/2✓ Branch 39 → 40 taken 38 times.
✓ Branch 39 → 41 taken 877 times.
|
915 | else if (ctx->AND_EQUAL()) |
| 1595 | 38 | assignExprNode->op = AssignExprNode::AssignOp::OP_AND_EQUAL; | |
| 1596 |
2/2✓ Branch 42 → 43 taken 38 times.
✓ Branch 42 → 44 taken 839 times.
|
877 | else if (ctx->OR_EQUAL()) |
| 1597 | 38 | assignExprNode->op = AssignExprNode::AssignOp::OP_OR_EQUAL; | |
| 1598 |
1/2✓ Branch 45 → 46 taken 839 times.
✗ Branch 45 → 47 not taken.
|
839 | else if (ctx->XOR_EQUAL()) |
| 1599 | 839 | assignExprNode->op = AssignExprNode::AssignOp::OP_XOR_EQUAL; | |
| 1600 | else | ||
| 1601 | ✗ | assert_fail("Unknown assign operator"); | |
| 1602 | |||
| 1603 |
1/2✓ Branch 48 → 49 taken 62068 times.
✗ Branch 48 → 52 not taken.
|
124136 | return nullptr; |
| 1604 | } | ||
| 1605 | |||
| 1606 | 9304 | std::any ASTBuilder::visitOverloadableOp(SpiceParser::OverloadableOpContext *ctx) { | |
| 1607 | 9304 | const auto fctNameNode = resumeForExpansion<FctNameNode>(); | |
| 1608 | |||
| 1609 | // Enrich | ||
| 1610 |
2/2✓ Branch 15 → 16 taken 388 times.
✓ Branch 15 → 17 taken 8916 times.
|
9304 | if (ctx->PLUS()) |
| 1611 | 388 | fctNameNode->name = OP_FCT_PLUS; | |
| 1612 |
2/2✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 20 taken 8914 times.
|
8916 | else if (ctx->MINUS()) |
| 1613 | 2 | fctNameNode->name = OP_FCT_MINUS; | |
| 1614 |
2/2✓ Branch 21 → 22 taken 770 times.
✓ Branch 21 → 23 taken 8144 times.
|
8914 | else if (ctx->MUL()) |
| 1615 | 770 | fctNameNode->name = OP_FCT_MUL; | |
| 1616 |
2/2✓ Branch 24 → 25 taken 176 times.
✓ Branch 24 → 26 taken 7968 times.
|
8144 | else if (ctx->DIV()) |
| 1617 | 176 | fctNameNode->name = OP_FCT_DIV; | |
| 1618 |
2/2✓ Branch 27 → 28 taken 2114 times.
✓ Branch 27 → 29 taken 5854 times.
|
7968 | else if (ctx->EQUAL()) |
| 1619 | 2114 | fctNameNode->name = OP_FCT_EQUAL; | |
| 1620 |
2/2✓ Branch 30 → 31 taken 2004 times.
✓ Branch 30 → 32 taken 3850 times.
|
5854 | else if (ctx->NOT_EQUAL()) |
| 1621 | 2004 | fctNameNode->name = OP_FCT_NOT_EQUAL; | |
| 1622 |
3/4✓ Branch 32 → 33 taken 3850 times.
✗ Branch 32 → 85 not taken.
✓ Branch 35 → 36 taken 236 times.
✓ Branch 35 → 37 taken 3614 times.
|
3850 | else if (ctx->LESS().size() == 2) |
| 1623 | 236 | fctNameNode->name = OP_FCT_SHL; | |
| 1624 |
3/4✓ Branch 37 → 38 taken 3614 times.
✗ Branch 37 → 86 not taken.
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 42 taken 3612 times.
|
3614 | else if (ctx->GREATER().size() == 2) |
| 1625 | 2 | fctNameNode->name = OP_FCT_SHR; | |
| 1626 |
2/2✓ Branch 43 → 44 taken 8 times.
✓ Branch 43 → 45 taken 3604 times.
|
3612 | else if (ctx->BITWISE_AND()) |
| 1627 | 8 | fctNameNode->name = OP_FCT_BITWISE_AND; | |
| 1628 |
2/2✓ Branch 46 → 47 taken 8 times.
✓ Branch 46 → 48 taken 3596 times.
|
3604 | else if (ctx->BITWISE_OR()) |
| 1629 | 8 | fctNameNode->name = OP_FCT_BITWISE_OR; | |
| 1630 |
2/2✓ Branch 49 → 50 taken 8 times.
✓ Branch 49 → 51 taken 3588 times.
|
3596 | else if (ctx->BITWISE_XOR()) |
| 1631 | 8 | fctNameNode->name = OP_FCT_BITWISE_XOR; | |
| 1632 |
2/2✓ Branch 52 → 53 taken 8 times.
✓ Branch 52 → 54 taken 3580 times.
|
3588 | else if (ctx->BITWISE_NOT()) |
| 1633 | 8 | fctNameNode->name = OP_FCT_BITWISE_NOT; | |
| 1634 |
2/2✓ Branch 55 → 56 taken 573 times.
✓ Branch 55 → 57 taken 3007 times.
|
3580 | else if (ctx->PLUS_EQUAL()) |
| 1635 | 573 | fctNameNode->name = OP_FCT_PLUS_EQUAL; | |
| 1636 |
2/2✓ Branch 58 → 59 taken 189 times.
✓ Branch 58 → 60 taken 2818 times.
|
3007 | else if (ctx->MINUS_EQUAL()) |
| 1637 | 189 | fctNameNode->name = OP_FCT_MINUS_EQUAL; | |
| 1638 |
2/2✓ Branch 61 → 62 taken 386 times.
✓ Branch 61 → 63 taken 2432 times.
|
2818 | else if (ctx->MUL_EQUAL()) |
| 1639 | 386 | fctNameNode->name = OP_FCT_MUL_EQUAL; | |
| 1640 |
2/2✓ Branch 64 → 65 taken 176 times.
✓ Branch 64 → 66 taken 2256 times.
|
2432 | else if (ctx->DIV_EQUAL()) |
| 1641 | 176 | fctNameNode->name = OP_FCT_DIV_EQUAL; | |
| 1642 |
2/2✓ Branch 67 → 68 taken 285 times.
✓ Branch 67 → 69 taken 1971 times.
|
2256 | else if (ctx->PLUS_PLUS()) |
| 1643 | 285 | fctNameNode->name = OP_FCT_POSTFIX_PLUS_PLUS; | |
| 1644 |
2/2✓ Branch 70 → 71 taken 189 times.
✓ Branch 70 → 72 taken 1782 times.
|
1971 | else if (ctx->MINUS_MINUS()) |
| 1645 | 189 | fctNameNode->name = OP_FCT_POSTFIX_MINUS_MINUS; | |
| 1646 |
2/2✓ Branch 73 → 74 taken 995 times.
✓ Branch 73 → 75 taken 787 times.
|
1782 | else if (ctx->LBRACKET()) |
| 1647 | 995 | fctNameNode->name = OP_FCT_SUBSCRIPT; | |
| 1648 |
1/2✓ Branch 76 → 77 taken 787 times.
✗ Branch 76 → 78 not taken.
|
787 | else if (ctx->ASSIGN()) |
| 1649 | 787 | fctNameNode->name = OP_FCT_ASSIGN; | |
| 1650 | else | ||
| 1651 | − | assert_fail("Unsupported overloadable operator"); // GCOV_EXCL_LINE | |
| 1652 | |||
| 1653 | 9304 | fctNameNode->fqName = fctNameNode->name; | |
| 1654 | 9304 | fctNameNode->nameFragments.push_back(fctNameNode->name); | |
| 1655 | |||
| 1656 |
1/2✓ Branch 81 → 82 taken 9304 times.
✗ Branch 81 → 87 not taken.
|
18608 | return nullptr; |
| 1657 | } | ||
| 1658 | |||
| 1659 | 37464 | int32_t ASTBuilder::parseInt(TerminalNode *terminal, bool isNegative) { | |
| 1660 | 112392 | const NumericParserCallback<int32_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int32_t { | |
| 1661 | // Prepare limits | ||
| 1662 |
2/2✓ Branch 2 → 3 taken 36530 times.
✓ Branch 2 → 4 taken 934 times.
|
37464 | const int64_t upperLimit = isSigned ? INT32_MAX : UINT32_MAX; |
| 1663 |
2/2✓ Branch 5 → 6 taken 36530 times.
✓ Branch 5 → 7 taken 934 times.
|
37464 | const int64_t lowerLimit = isSigned ? INT32_MIN : 0; |
| 1664 | // Parse number, apply sign and check for limits | ||
| 1665 | 37464 | int64_t number = std::stoll(substr, nullptr, base); | |
| 1666 |
2/2✓ Branch 9 → 10 taken 541 times.
✓ Branch 9 → 11 taken 36921 times.
|
37462 | if (isNegative) |
| 1667 | 541 | number = -number; | |
| 1668 |
2/4✓ Branch 11 → 12 taken 37462 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 37462 times.
|
37462 | if (number < lowerLimit || number > upperLimit) |
| 1669 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1670 | 37462 | return static_cast<int32_t>(number); | |
| 1671 | 37464 | }; | |
| 1672 |
2/2✓ Branch 3 → 4 taken 37462 times.
✓ Branch 3 → 8 taken 2 times.
|
74926 | return parseNumeric(terminal, cb); |
| 1673 | 37464 | } | |
| 1674 | |||
| 1675 | 3106 | int16_t ASTBuilder::parseShort(TerminalNode *terminal, bool isNegative) { | |
| 1676 | 9318 | const NumericParserCallback<int16_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int16_t { | |
| 1677 | // Prepare limits | ||
| 1678 |
2/2✓ Branch 2 → 3 taken 2438 times.
✓ Branch 2 → 4 taken 668 times.
|
3106 | const int64_t upperLimit = isSigned ? INT16_MAX : UINT16_MAX; |
| 1679 |
2/2✓ Branch 5 → 6 taken 2438 times.
✓ Branch 5 → 7 taken 668 times.
|
3106 | const int64_t lowerLimit = isSigned ? INT16_MIN : 0; |
| 1680 | // Parse number, apply sign and check for limits | ||
| 1681 | 3106 | int64_t number = std::stoll(substr, nullptr, base); | |
| 1682 |
2/2✓ Branch 9 → 10 taken 172 times.
✓ Branch 9 → 11 taken 2934 times.
|
3106 | if (isNegative) |
| 1683 | 172 | number = -number; | |
| 1684 |
2/4✓ Branch 11 → 12 taken 3106 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 3106 times.
|
3106 | if (number < lowerLimit || number > upperLimit) |
| 1685 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1686 | 3106 | return static_cast<int16_t>(number); | |
| 1687 | 3106 | }; | |
| 1688 |
1/2✓ Branch 3 → 4 taken 3106 times.
✗ Branch 3 → 8 not taken.
|
6212 | return parseNumeric(terminal, cb); |
| 1689 | 3106 | } | |
| 1690 | |||
| 1691 | 50128 | int64_t ASTBuilder::parseLong(TerminalNode *terminal, bool isNegative) { | |
| 1692 | 150384 | const NumericParserCallback<int64_t> cb = [isNegative](const std::string &substr, short base, bool isSigned) -> int64_t { | |
| 1693 | // Parse the magnitude as unsigned so values like 2^63 (the absolute value of INT64_MIN) fit | ||
| 1694 | 50128 | const uint64_t magnitude = std::stoull(substr, nullptr, base); | |
| 1695 |
2/2✓ Branch 3 → 4 taken 5914 times.
✓ Branch 3 → 11 taken 44214 times.
|
50128 | if (isNegative) { |
| 1696 | 5914 | constexpr uint64_t maxNegMagnitude = static_cast<uint64_t>(INT64_MAX) + 1; // 2^63 | |
| 1697 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 8 taken 5914 times.
|
5914 | if (magnitude > maxNegMagnitude) |
| 1698 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1699 |
2/2✓ Branch 8 → 9 taken 4 times.
✓ Branch 8 → 10 taken 5910 times.
|
5914 | if (magnitude == maxNegMagnitude) |
| 1700 | 4 | return INT64_MIN; | |
| 1701 | 5910 | return -static_cast<int64_t>(magnitude); | |
| 1702 | } | ||
| 1703 |
3/4✓ Branch 11 → 12 taken 39792 times.
✓ Branch 11 → 16 taken 4422 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 39792 times.
|
44214 | if (isSigned && magnitude > static_cast<uint64_t>(INT64_MAX)) |
| 1704 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1705 | 44214 | return static_cast<int64_t>(magnitude); | |
| 1706 | 50128 | }; | |
| 1707 |
1/2✓ Branch 3 → 4 taken 50128 times.
✗ Branch 3 → 8 not taken.
|
100256 | return parseNumeric(terminal, cb); |
| 1708 | 50128 | } | |
| 1709 | |||
| 1710 | 16129 | int8_t ASTBuilder::parseChar(TerminalNode *terminal) const { | |
| 1711 |
1/2✓ Branch 2 → 3 taken 16129 times.
✗ Branch 2 → 59 not taken.
|
16129 | const std::string input = terminal->toString(); |
| 1712 |
2/2✓ Branch 4 → 5 taken 10728 times.
✓ Branch 4 → 7 taken 5401 times.
|
16129 | if (input.length() == 3) // Normal char literals |
| 1713 | 10728 | return input[1]; | |
| 1714 | |||
| 1715 |
3/6✓ Branch 8 → 9 taken 5401 times.
✗ Branch 8 → 12 not taken.
✓ Branch 10 → 11 taken 5401 times.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 5401 times.
✗ Branch 13 → 34 not taken.
|
5401 | if (input.length() == 4 && input[1] == '\\') { // Char literals with escape sequence |
| 1716 |
10/11✓ Branch 15 → 16 taken 104 times.
✗ Branch 15 → 17 not taken.
✓ Branch 15 → 18 taken 160 times.
✓ Branch 15 → 19 taken 752 times.
✓ Branch 15 → 20 taken 532 times.
✓ Branch 15 → 21 taken 486 times.
✓ Branch 15 → 22 taken 18 times.
✓ Branch 15 → 23 taken 36 times.
✓ Branch 15 → 24 taken 22 times.
✓ Branch 15 → 25 taken 3289 times.
✓ Branch 15 → 26 taken 2 times.
|
5401 | switch (input[2]) { |
| 1717 | 104 | case '\'': | |
| 1718 | 104 | return '\''; | |
| 1719 | ✗ | case '"': | |
| 1720 | ✗ | return '\"'; | |
| 1721 | 160 | case '\\': | |
| 1722 | 160 | return '\\'; | |
| 1723 | 752 | case 'n': | |
| 1724 | 752 | return '\n'; | |
| 1725 | 532 | case 'r': | |
| 1726 | 532 | return '\r'; | |
| 1727 | 486 | case 't': | |
| 1728 | 486 | return '\t'; | |
| 1729 | 18 | case 'b': | |
| 1730 | 18 | return '\b'; | |
| 1731 | 36 | case 'f': | |
| 1732 | 36 | return '\f'; | |
| 1733 | 22 | case 'v': | |
| 1734 | 22 | return '\v'; | |
| 1735 | 3289 | case '0': | |
| 1736 | 3289 | return '\0'; | |
| 1737 | 2 | default: | |
| 1738 |
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); |
| 1739 |
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); |
| 1740 | } | ||
| 1741 | } | ||
| 1742 | |||
| 1743 | ✗ | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); | |
| 1744 | ✗ | throw ParserError(codeLoc, INVALID_CHAR_LITERAL, "Invalid char literal " + input); | |
| 1745 | 16129 | } | |
| 1746 | |||
| 1747 | 42193 | std::string ASTBuilder::parseString(std::string input) { | |
| 1748 |
1/2✓ Branch 3 → 4 taken 42193 times.
✗ Branch 3 → 9 not taken.
|
42193 | input = input.substr(1, input.size() - 2); |
| 1749 | 42193 | replaceEscapeChars(input); | |
| 1750 | 42193 | return input; | |
| 1751 | } | ||
| 1752 | |||
| 1753 | 90698 | template <typename T> T ASTBuilder::parseNumeric(TerminalNode *terminal, const NumericParserCallback<T> &cb) { | |
| 1754 |
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 37464 times.
✗ Branch 2 → 87 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 50128 times.
✗ Branch 2 → 87 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 2 → 3 taken 3106 times.
✗ Branch 2 → 87 not taken.
|
90698 | const std::string input = terminal->toString(); |
| 1755 | |||
| 1756 | // Set to signed if the input string does not end with 'u' | ||
| 1757 |
12/18int spice::compiler::ASTBuilder::parseNumeric<int>(antlr4::tree::TerminalNode*, std::function<int (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 4 → 5 taken 36530 times.
✓ Branch 4 → 9 taken 934 times.
✓ Branch 6 → 7 taken 36530 times.
✗ Branch 6 → 9 not taken.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 36530 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 4 → 5 taken 50128 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 50128 times.
✗ Branch 6 → 9 not taken.
✓ Branch 8 → 9 taken 4422 times.
✓ Branch 8 → 10 taken 45706 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 4 → 5 taken 3106 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 2438 times.
✓ Branch 6 → 9 taken 668 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 2438 times.
|
90698 | const bool isUnsigned = input.ends_with('u') || input.ends_with("us") || input.ends_with("ul"); |
| 1758 | |||
| 1759 | try { | ||
| 1760 |
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 12 → 13 taken 4488 times.
✓ Branch 12 → 30 taken 32976 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 12 → 13 taken 6637 times.
✓ Branch 12 → 30 taken 43491 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 12 → 13 taken 2106 times.
✓ Branch 12 → 30 taken 1000 times.
|
90698 | if (input.length() >= 3) { |
| 1761 |
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 14 → 15 taken 1886 times.
✓ Branch 14 → 30 taken 2602 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 14 → 15 taken 2659 times.
✓ Branch 14 → 30 taken 3978 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 14 → 15 taken 794 times.
✓ Branch 14 → 30 taken 1312 times.
|
13231 | if (input[0] == '0') { |
| 1762 |
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 15 → 16 taken 1886 times.
✗ Branch 15 → 37 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 2659 times.
✗ Branch 15 → 37 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 15 → 16 taken 794 times.
✗ Branch 15 → 37 not taken.
|
5339 | const std::string subStr = input.substr(2); |
| 1763 |
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 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✓ Branch 17 → 22 taken 494 times.
✓ Branch 17 → 24 taken 1392 times.
✗ Branch 17 → 26 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 → 20 not taken.
✓ Branch 17 → 22 taken 818 times.
✗ Branch 17 → 24 not taken.
✓ Branch 17 → 26 taken 1841 times.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✗ Branch 17 → 22 not taken.
✓ Branch 17 → 24 taken 792 times.
✓ Branch 17 → 26 taken 2 times.
|
5339 | switch (input[1]) { |
| 1764 | ✗ | case 'd': // fall-through | |
| 1765 | case 'D': | ||
| 1766 | ✗ | return cb(subStr, 10, !isUnsigned); | |
| 1767 | ✗ | case 'b': // fall-through | |
| 1768 | case 'B': | ||
| 1769 | ✗ | return cb(subStr, 2, !isUnsigned); | |
| 1770 | 1312 | case 'h': // fall-through | |
| 1771 | case 'H': // fall-through | ||
| 1772 | case 'x': // fall-through | ||
| 1773 | case 'X': | ||
| 1774 |
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 22 → 23 taken 494 times.
✗ Branch 22 → 35 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 22 → 23 taken 818 times.
✗ Branch 22 → 35 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 35 not taken.
|
1312 | return cb(subStr, 16, !isUnsigned); |
| 1775 | 2184 | case 'o': // fall-through | |
| 1776 | case 'O': | ||
| 1777 |
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 24 → 25 taken 1392 times.
✗ Branch 24 → 35 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 24 → 25 not taken.
✗ Branch 24 → 35 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 24 → 25 taken 792 times.
✗ Branch 24 → 35 not taken.
|
2184 | return cb(subStr, 8, !isUnsigned); |
| 1778 | 1843 | default: // default is decimal | |
| 1779 |
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 26 → 27 not taken.
✗ Branch 26 → 35 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 26 → 27 taken 1841 times.
✗ Branch 26 → 35 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 35 not taken.
|
1843 | return cb(input, 10, !isUnsigned); |
| 1780 | } | ||
| 1781 | 5339 | } | |
| 1782 | } | ||
| 1783 |
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 30 → 31 taken 35576 times.
✓ Branch 30 → 38 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 30 → 31 taken 47469 times.
✗ Branch 30 → 38 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✓ Branch 30 → 31 taken 2312 times.
✗ Branch 30 → 38 not taken.
|
85359 | return cb(input, 10, !isUnsigned); |
| 1784 |
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 38 → 39 not taken.
✓ Branch 38 → 40 taken 2 times.
✗ Branch 38 → 51 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 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 38 → 51 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ Branch 38 → 51 not taken.
|
4 | } catch (std::out_of_range &) { |
| 1785 |
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 41 → 42 taken 2 times.
✗ Branch 41 → 70 not taken.
✓ Branch 42 → 43 taken 2 times.
✗ Branch 42 → 70 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 41 → 42 not taken.
✗ Branch 41 → 70 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 70 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 70 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 70 not taken.
|
2 | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); |
| 1786 |
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 46 → 47 taken 2 times.
✗ Branch 46 → 64 not taken.
✓ Branch 47 → 48 taken 2 times.
✗ Branch 47 → 61 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 46 → 47 not taken.
✗ Branch 46 → 64 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 61 not taken.
short spice::compiler::ASTBuilder::parseNumeric<short>(antlr4::tree::TerminalNode*, std::function<short (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, short, bool)> const&):
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 64 not taken.
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 61 not taken.
|
6 | throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "The provided number is out of range"); |
| 1787 | ✗ | } catch (std::invalid_argument &) { | |
| 1788 | ✗ | const CodeLoc codeLoc(terminal->getSymbol(), sourceFile); | |
| 1789 | ✗ | throw ParserError(codeLoc, NUMBER_OUT_OF_RANGE, "You tried to parse '" + input + "' as an integer, but it was no integer"); | |
| 1790 | } | ||
| 1791 | 90698 | } | |
| 1792 | |||
| 1793 | 42193 | void ASTBuilder::replaceEscapeChars(std::string &input) { | |
| 1794 | 42193 | const std::unordered_map<char, char> escapeMap = { | |
| 1795 | {'a', '\a'}, {'b', '\b'}, {'f', '\f'}, {'n', '\n'}, {'r', '\r'}, {'t', '\t'}, | ||
| 1796 | {'v', '\v'}, {'\\', '\\'}, {'?', '\?'}, {'\'', '\''}, {'"', '\"'}, | ||
| 1797 |
1/2✓ Branch 4 → 5 taken 42193 times.
✗ Branch 4 → 40 not taken.
|
84386 | }; |
| 1798 | |||
| 1799 | 42193 | size_t writeIndex = 0; | |
| 1800 | 42193 | size_t readIndex = 0; | |
| 1801 | 42193 | const size_t len = input.length(); | |
| 1802 | |||
| 1803 |
2/2✓ Branch 36 → 8 taken 602147 times.
✓ Branch 36 → 37 taken 42193 times.
|
644340 | while (readIndex < len) { |
| 1804 | 602147 | const char c = input[readIndex]; | |
| 1805 |
3/4✓ Branch 9 → 10 taken 6187 times.
✓ Branch 9 → 33 taken 595960 times.
✓ Branch 10 → 11 taken 6187 times.
✗ Branch 10 → 33 not taken.
|
602147 | if (c == '\\' && readIndex + 1 < len) { |
| 1806 | 6187 | char next = input[readIndex + 1]; | |
| 1807 |
1/2✓ Branch 12 → 13 taken 6187 times.
✗ Branch 12 → 45 not taken.
|
6187 | auto it = escapeMap.find(next); |
| 1808 |
2/2✓ Branch 15 → 16 taken 6107 times.
✓ Branch 15 → 19 taken 80 times.
|
6187 | if (it != escapeMap.end()) { |
| 1809 | 6107 | input[writeIndex++] = it->second; | |
| 1810 | 6107 | readIndex += 2; | |
| 1811 | 6181 | continue; | |
| 1812 | } | ||
| 1813 | |||
| 1814 | // Handle octal escape sequences (up to 3 digits) | ||
| 1815 |
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') { |
| 1816 | 74 | int value = 0; | |
| 1817 | 74 | size_t octalDigits = 0; | |
| 1818 | |||
| 1819 | // Look ahead up to 3 digits | ||
| 1820 |
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) { |
| 1821 | 222 | const char oc = input[readIndex + i]; | |
| 1822 |
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') { |
| 1823 | 222 | value = value << 3 | (oc - '0'); // multiply by 8 and add digit | |
| 1824 | 222 | octalDigits++; | |
| 1825 | } else { | ||
| 1826 | break; | ||
| 1827 | } | ||
| 1828 | } | ||
| 1829 | |||
| 1830 |
1/2✓ Branch 28 → 29 taken 74 times.
✗ Branch 28 → 31 not taken.
|
74 | if (octalDigits > 0) { |
| 1831 | 74 | input[writeIndex++] = static_cast<char>(value); | |
| 1832 | 74 | readIndex += 1 + octalDigits; // backslash + octal digits | |
| 1833 | 74 | continue; | |
| 1834 | } | ||
| 1835 | } | ||
| 1836 | } | ||
| 1837 | |||
| 1838 | // Copy current character | ||
| 1839 | 595966 | input[writeIndex++] = c; | |
| 1840 | 595966 | readIndex++; | |
| 1841 | } | ||
| 1842 | |||
| 1843 |
1/2✓ Branch 37 → 38 taken 42193 times.
✗ Branch 37 → 46 not taken.
|
42193 | input.resize(writeIndex); |
| 1844 | 42193 | } | |
| 1845 | |||
| 1846 | 1070205 | std::string ASTBuilder::getIdentifier(TerminalNode *terminal, bool isTypeIdentifier) const { | |
| 1847 | 1070205 | const std::string identifier = terminal->getText(); | |
| 1848 | |||
| 1849 | // Check if the list of reserved keywords contains the given identifier | ||
| 1850 |
3/4✓ Branch 3 → 4 taken 1070205 times.
✗ Branch 3 → 52 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 14 taken 1070203 times.
|
1070205 | if (std::ranges::find(RESERVED_KEYWORDS, identifier) != std::end(RESERVED_KEYWORDS)) { |
| 1851 |
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); |
| 1852 |
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"); |
| 1853 | } | ||
| 1854 | |||
| 1855 | // Check if the identifier is a type identifier and is reserved | ||
| 1856 |
6/6✓ Branch 14 → 15 taken 97436 times.
✓ Branch 14 → 19 taken 972767 times.
✓ Branch 15 → 16 taken 29024 times.
✓ Branch 15 → 19 taken 68412 times.
✓ Branch 20 → 21 taken 2 times.
✓ Branch 20 → 30 taken 1070201 times.
|
1099227 | if (isTypeIdentifier && !sourceFile->isStdFile && |
| 1857 |
3/4✓ Branch 16 → 17 taken 29024 times.
✗ Branch 16 → 52 not taken.
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 19 taken 29022 times.
|
29024 | std::ranges::find(RESERVED_TYPE_NAMES, identifier) != std::end(RESERVED_TYPE_NAMES)) { |
| 1858 |
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); |
| 1859 |
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"); |
| 1860 | } | ||
| 1861 | |||
| 1862 | 1070201 | return identifier; | |
| 1863 | 4 | } | |
| 1864 | |||
| 1865 | } // namespace spice::compiler | ||
| 1866 |