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 | 6103 | ASTBuilder::ASTBuilder(GlobalResourceManager &resourceManager, SourceFile *sourceFile, antlr4::ANTLRInputStream *inputStream) | |
| 17 |
1/2✓ Branch 4 → 5 taken 6103 times.
✗ Branch 4 → 6 not taken.
|
6103 | : CompilerPass(resourceManager, sourceFile), inputStream(inputStream) {} |
| 18 | |||
| 19 | 6099 | std::any ASTBuilder::visitEntry(SpiceParser::EntryContext *ctx) { | |
| 20 | 6099 | const auto entryNode = createNode<EntryNode>(ctx); | |
| 21 | |||
| 22 | // Visit children | ||
| 23 |
2/2✓ Branch 144 → 5 taken 123005 times.
✓ Branch 144 → 145 taken 6087 times.
|
135191 | for (ParserRuleContext::ParseTree *child : ctx->children) { |
| 24 |
3/4✓ Branch 7 → 8 taken 123005 times.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 1262 times.
✓ Branch 10 → 16 taken 121743 times.
|
123005 | if (auto *mainFctDefCtx = dynamic_cast<SpiceParser::MainFunctionDefContext *>(child)) |
| 25 |
4/6✓ Branch 11 → 12 taken 1254 times.
✓ Branch 11 → 157 taken 8 times.
✓ Branch 12 → 13 taken 1254 times.
✗ Branch 12 → 155 not taken.
✓ Branch 13 → 14 taken 1254 times.
✗ Branch 13 → 155 not taken.
|
1262 | entryNode->topLevelDefs.push_back(std::any_cast<MainFctDefNode *>(visit(mainFctDefCtx))); |
| 26 |
3/4✓ Branch 16 → 17 taken 121743 times.
✗ Branch 16 → 18 not taken.
✓ Branch 19 → 20 taken 48728 times.
✓ Branch 19 → 25 taken 73015 times.
|
121743 | else if (auto *fctDefCtx = dynamic_cast<SpiceParser::FunctionDefContext *>(child)) |
| 27 |
3/6✓ Branch 20 → 21 taken 48728 times.
✗ Branch 20 → 161 not taken.
✓ Branch 21 → 22 taken 48728 times.
✗ Branch 21 → 159 not taken.
✓ Branch 22 → 23 taken 48728 times.
✗ Branch 22 → 159 not taken.
|
48728 | entryNode->topLevelDefs.push_back(std::any_cast<FctDefNode *>(visit(fctDefCtx))); |
| 28 |
3/4✓ Branch 25 → 26 taken 73015 times.
✗ Branch 25 → 27 not taken.
✓ Branch 28 → 29 taken 29256 times.
✓ Branch 28 → 34 taken 43759 times.
|
73015 | else if (auto *procDefCtx = dynamic_cast<SpiceParser::ProcedureDefContext *>(child)) |
| 29 |
3/6✓ Branch 29 → 30 taken 29256 times.
✗ Branch 29 → 165 not taken.
✓ Branch 30 → 31 taken 29256 times.
✗ Branch 30 → 163 not taken.
✓ Branch 31 → 32 taken 29256 times.
✗ Branch 31 → 163 not taken.
|
29256 | entryNode->topLevelDefs.push_back(std::any_cast<ProcDefNode *>(visit(procDefCtx))); |
| 30 |
3/4✓ Branch 34 → 35 taken 43759 times.
✗ Branch 34 → 36 not taken.
✓ Branch 37 → 38 taken 7467 times.
✓ Branch 37 → 43 taken 36292 times.
|
43759 | else if (auto *structDefCtx = dynamic_cast<SpiceParser::StructDefContext *>(child)) |
| 31 |
4/6✓ Branch 38 → 39 taken 7465 times.
✓ Branch 38 → 169 taken 2 times.
✓ Branch 39 → 40 taken 7465 times.
✗ Branch 39 → 167 not taken.
✓ Branch 40 → 41 taken 7465 times.
✗ Branch 40 → 167 not taken.
|
7467 | entryNode->topLevelDefs.push_back(std::any_cast<StructDefNode *>(visit(structDefCtx))); |
| 32 |
3/4✓ Branch 43 → 44 taken 36292 times.
✗ Branch 43 → 45 not taken.
✓ Branch 46 → 47 taken 805 times.
✓ Branch 46 → 52 taken 35487 times.
|
36292 | else if (auto *interfaceDefCtx = dynamic_cast<SpiceParser::InterfaceDefContext *>(child)) |
| 33 |
3/6✓ Branch 47 → 48 taken 805 times.
✗ Branch 47 → 173 not taken.
✓ Branch 48 → 49 taken 805 times.
✗ Branch 48 → 171 not taken.
✓ Branch 49 → 50 taken 805 times.
✗ Branch 49 → 171 not taken.
|
805 | entryNode->topLevelDefs.push_back(std::any_cast<InterfaceDefNode *>(visit(interfaceDefCtx))); |
| 34 |
3/4✓ Branch 52 → 53 taken 35487 times.
✗ Branch 52 → 54 not taken.
✓ Branch 55 → 56 taken 68 times.
✓ Branch 55 → 61 taken 35419 times.
|
35487 | else if (auto *unionDefCtx = dynamic_cast<SpiceParser::UnionDefContext *>(child)) |
| 35 |
3/6✓ Branch 56 → 57 taken 68 times.
✗ Branch 56 → 177 not taken.
✓ Branch 57 → 58 taken 68 times.
✗ Branch 57 → 175 not taken.
✓ Branch 58 → 59 taken 68 times.
✗ Branch 58 → 175 not taken.
|
68 | entryNode->topLevelDefs.push_back(std::any_cast<UnionDefNode *>(visit(unionDefCtx))); |
| 36 |
3/4✓ Branch 61 → 62 taken 35419 times.
✗ Branch 61 → 63 not taken.
✓ Branch 64 → 65 taken 1232 times.
✓ Branch 64 → 70 taken 34187 times.
|
35419 | else if (auto *enumDefCtx = dynamic_cast<SpiceParser::EnumDefContext *>(child)) |
| 37 |
3/6✓ Branch 65 → 66 taken 1232 times.
✗ Branch 65 → 181 not taken.
✓ Branch 66 → 67 taken 1232 times.
✗ Branch 66 → 179 not taken.
✓ Branch 67 → 68 taken 1232 times.
✗ Branch 67 → 179 not taken.
|
1232 | entryNode->topLevelDefs.push_back(std::any_cast<EnumDefNode *>(visit(enumDefCtx))); |
| 38 |
3/4✓ Branch 70 → 71 taken 34187 times.
✗ Branch 70 → 72 not taken.
✓ Branch 73 → 74 taken 4499 times.
✓ Branch 73 → 79 taken 29688 times.
|
34187 | else if (auto *genericTypeDefCtx = dynamic_cast<SpiceParser::GenericTypeDefContext *>(child)) |
| 39 |
3/6✓ Branch 74 → 75 taken 4499 times.
✗ Branch 74 → 185 not taken.
✓ Branch 75 → 76 taken 4499 times.
✗ Branch 75 → 183 not taken.
✓ Branch 76 → 77 taken 4499 times.
✗ Branch 76 → 183 not taken.
|
4499 | entryNode->topLevelDefs.push_back(std::any_cast<GenericTypeDefNode *>(visit(genericTypeDefCtx))); |
| 40 |
3/4✓ Branch 79 → 80 taken 29688 times.
✗ Branch 79 → 81 not taken.
✓ Branch 82 → 83 taken 707 times.
✓ Branch 82 → 88 taken 28981 times.
|
29688 | else if (auto *aliasDefCtx = dynamic_cast<SpiceParser::AliasDefContext *>(child)) |
| 41 |
3/6✓ Branch 83 → 84 taken 707 times.
✗ Branch 83 → 189 not taken.
✓ Branch 84 → 85 taken 707 times.
✗ Branch 84 → 187 not taken.
✓ Branch 85 → 86 taken 707 times.
✗ Branch 85 → 187 not taken.
|
707 | entryNode->topLevelDefs.push_back(std::any_cast<AliasDefNode *>(visit(aliasDefCtx))); |
| 42 |
3/4✓ Branch 88 → 89 taken 28981 times.
✗ Branch 88 → 90 not taken.
✓ Branch 91 → 92 taken 5945 times.
✓ Branch 91 → 97 taken 23036 times.
|
28981 | else if (auto *globalVarDefCtx = dynamic_cast<SpiceParser::GlobalVarDefContext *>(child)) |
| 43 |
3/6✓ Branch 92 → 93 taken 5945 times.
✗ Branch 92 → 193 not taken.
✓ Branch 93 → 94 taken 5945 times.
✗ Branch 93 → 191 not taken.
✓ Branch 94 → 95 taken 5945 times.
✗ Branch 94 → 191 not taken.
|
5945 | entryNode->topLevelDefs.push_back(std::any_cast<GlobalVarDefNode *>(visit(globalVarDefCtx))); |
| 44 |
3/4✓ Branch 97 → 98 taken 23036 times.
✗ Branch 97 → 99 not taken.
✓ Branch 100 → 101 taken 5908 times.
✓ Branch 100 → 106 taken 17128 times.
|
23036 | else if (auto *importDefCtx = dynamic_cast<SpiceParser::ImportDefContext *>(child)) |
| 45 |
3/6✓ Branch 101 → 102 taken 5908 times.
✗ Branch 101 → 197 not taken.
✓ Branch 102 → 103 taken 5908 times.
✗ Branch 102 → 195 not taken.
✓ Branch 103 → 104 taken 5908 times.
✗ Branch 103 → 195 not taken.
|
5908 | entryNode->importDefs.push_back(std::any_cast<ImportDefNode *>(visit(importDefCtx))); |
| 46 |
3/4✓ Branch 106 → 107 taken 17128 times.
✗ Branch 106 → 108 not taken.
✓ Branch 109 → 110 taken 8887 times.
✓ Branch 109 → 115 taken 8241 times.
|
17128 | else if (auto *extDeclCtx = dynamic_cast<SpiceParser::ExtDeclContext *>(child)) |
| 47 |
3/6✓ Branch 110 → 111 taken 8887 times.
✗ Branch 110 → 201 not taken.
✓ Branch 111 → 112 taken 8887 times.
✗ Branch 111 → 199 not taken.
✓ Branch 112 → 113 taken 8887 times.
✗ Branch 112 → 199 not taken.
|
8887 | entryNode->topLevelDefs.push_back(std::any_cast<ExtDeclNode *>(visit(extDeclCtx))); |
| 48 |
3/4✓ Branch 115 → 116 taken 8241 times.
✗ Branch 115 → 117 not taken.
✓ Branch 118 → 119 taken 2154 times.
✓ Branch 118 → 124 taken 6087 times.
|
8241 | else if (auto *modAttrCtx = dynamic_cast<SpiceParser::ModAttrContext *>(child)) |
| 49 |
4/6✓ Branch 119 → 120 taken 2152 times.
✓ Branch 119 → 205 taken 2 times.
✓ Branch 120 → 121 taken 2152 times.
✗ Branch 120 → 203 not taken.
✓ Branch 121 → 122 taken 2152 times.
✗ Branch 121 → 203 not taken.
|
2154 | entryNode->modAttrs.push_back(std::any_cast<ModAttrNode *>(visit(modAttrCtx))); |
| 50 |
1/2✓ Branch 124 → 125 taken 6087 times.
✗ Branch 124 → 126 not taken.
|
6087 | else if (const auto *eofCtx = dynamic_cast<TerminalNode *>(child); |
| 51 |
5/10✓ Branch 127 → 128 taken 6087 times.
✗ Branch 127 → 131 not taken.
✓ Branch 128 → 129 taken 6087 times.
✗ Branch 128 → 207 not taken.
✓ Branch 129 → 130 taken 6087 times.
✗ Branch 129 → 207 not taken.
✗ Branch 130 → 131 not taken.
✓ Branch 130 → 132 taken 6087 times.
✗ Branch 133 → 134 not taken.
✓ Branch 133 → 135 taken 6087 times.
|
6087 | !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 6087 times.
✗ Branch 151 → 208 not taken.
|
12174 | return concludeNode(entryNode); |
| 56 | } | ||
| 57 | |||
| 58 | 1262 | std::any ASTBuilder::visitMainFunctionDef(SpiceParser::MainFunctionDefContext *ctx) { | |
| 59 | 1262 | const auto mainFctDefNode = createNode<MainFctDefNode>(ctx); | |
| 60 | |||
| 61 | // Visit children | ||
| 62 |
2/2✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 10 taken 1260 times.
|
1262 | 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 1248 times.
|
1262 | 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 1262 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 1254 times.
✓ Branch 18 → 39 taken 8 times.
✓ Branch 19 → 20 taken 1254 times.
✗ Branch 19 → 37 not taken.
✓ Branch 21 → 22 taken 1254 times.
✗ Branch 21 → 40 not taken.
|
1262 | mainFctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 69 | |||
| 70 |
1/2✓ Branch 27 → 28 taken 1254 times.
✗ Branch 27 → 40 not taken.
|
2508 | return concludeNode(mainFctDefNode); |
| 71 | } | ||
| 72 | |||
| 73 | 48728 | std::any ASTBuilder::visitFunctionDef(SpiceParser::FunctionDefContext *ctx) { | |
| 74 | 48728 | const auto fctDefNode = createNode<FctDefNode>(ctx); | |
| 75 | |||
| 76 | // Visit children | ||
| 77 |
2/2✓ Branch 4 → 5 taken 1612 times.
✓ Branch 4 → 24 taken 47116 times.
|
48728 | if (ctx->topLevelDefAttr()) { |
| 78 |
3/6✓ Branch 5 → 6 taken 1612 times.
✗ Branch 5 → 70 not taken.
✓ Branch 6 → 7 taken 1612 times.
✗ Branch 6 → 70 not taken.
✓ Branch 7 → 8 taken 1612 times.
✗ Branch 7 → 68 not taken.
|
1612 | 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 1816 times.
✓ Branch 22 → 23 taken 1612 times.
|
5040 | for (AttrNode *attr : fctDefNode->attrs->attrLst->attributes) |
| 81 | 1816 | attr->target = AttrNode::TARGET_FCT_PROC; | |
| 82 | } | ||
| 83 |
2/2✓ Branch 25 → 26 taken 46597 times.
✓ Branch 25 → 31 taken 2131 times.
|
48728 | if (ctx->qualifierLst()) |
| 84 |
3/6✓ Branch 26 → 27 taken 46597 times.
✗ Branch 26 → 73 not taken.
✓ Branch 27 → 28 taken 46597 times.
✗ Branch 27 → 73 not taken.
✓ Branch 28 → 29 taken 46597 times.
✗ Branch 28 → 71 not taken.
|
46597 | fctDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 85 |
3/6✓ Branch 31 → 32 taken 48728 times.
✗ Branch 31 → 76 not taken.
✓ Branch 32 → 33 taken 48728 times.
✗ Branch 32 → 76 not taken.
✓ Branch 33 → 34 taken 48728 times.
✗ Branch 33 → 74 not taken.
|
48728 | fctDefNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 86 | 48728 | fctDefNode->returnType->isReturnType = true; | |
| 87 |
3/6✓ Branch 35 → 36 taken 48728 times.
✗ Branch 35 → 79 not taken.
✓ Branch 36 → 37 taken 48728 times.
✗ Branch 36 → 79 not taken.
✓ Branch 37 → 38 taken 48728 times.
✗ Branch 37 → 77 not taken.
|
48728 | fctDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName())); |
| 88 | 48728 | fctDefNode->isMethod = fctDefNode->name->nameFragments.size() > 1; | |
| 89 |
2/2✓ Branch 41 → 42 taken 4932 times.
✓ Branch 41 → 47 taken 43796 times.
|
48728 | if (ctx->typeLst()) { |
| 90 | 4932 | fctDefNode->hasTemplateTypes = true; | |
| 91 |
3/6✓ Branch 42 → 43 taken 4932 times.
✗ Branch 42 → 82 not taken.
✓ Branch 43 → 44 taken 4932 times.
✗ Branch 43 → 82 not taken.
✓ Branch 44 → 45 taken 4932 times.
✗ Branch 44 → 80 not taken.
|
4932 | fctDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 92 | } | ||
| 93 |
2/2✓ Branch 48 → 49 taken 35398 times.
✓ Branch 48 → 54 taken 13330 times.
|
48728 | if (ctx->paramLst()) { |
| 94 | 35398 | fctDefNode->hasParams = true; | |
| 95 |
3/6✓ Branch 49 → 50 taken 35398 times.
✗ Branch 49 → 85 not taken.
✓ Branch 50 → 51 taken 35398 times.
✗ Branch 50 → 85 not taken.
✓ Branch 51 → 52 taken 35398 times.
✗ Branch 51 → 83 not taken.
|
35398 | fctDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 96 | } | ||
| 97 |
4/8✓ Branch 54 → 55 taken 48728 times.
✗ Branch 54 → 88 not taken.
✓ Branch 55 → 56 taken 48728 times.
✗ Branch 55 → 88 not taken.
✓ Branch 56 → 57 taken 48728 times.
✗ Branch 56 → 86 not taken.
✓ Branch 58 → 59 taken 48728 times.
✗ Branch 58 → 89 not taken.
|
48728 | fctDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 98 | |||
| 99 |
1/2✓ Branch 64 → 65 taken 48728 times.
✗ Branch 64 → 89 not taken.
|
97456 | return concludeNode(fctDefNode); |
| 100 | } | ||
| 101 | |||
| 102 | 29256 | std::any ASTBuilder::visitProcedureDef(SpiceParser::ProcedureDefContext *ctx) { | |
| 103 | 29256 | const auto procDefNode = createNode<ProcDefNode>(ctx); | |
| 104 | |||
| 105 | // Visit children | ||
| 106 |
2/2✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 24 taken 29254 times.
|
29256 | 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 24645 times.
✓ Branch 25 → 31 taken 4611 times.
|
29256 | if (ctx->qualifierLst()) |
| 113 |
3/6✓ Branch 26 → 27 taken 24645 times.
✗ Branch 26 → 69 not taken.
✓ Branch 27 → 28 taken 24645 times.
✗ Branch 27 → 69 not taken.
✓ Branch 28 → 29 taken 24645 times.
✗ Branch 28 → 67 not taken.
|
24645 | procDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 114 |
3/6✓ Branch 31 → 32 taken 29256 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 29256 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 29256 times.
✗ Branch 33 → 70 not taken.
|
29256 | procDefNode->name = std::any_cast<FctNameNode *>(visit(ctx->fctName())); |
| 115 | 29256 | procDefNode->isMethod = procDefNode->name->nameFragments.size() > 1; | |
| 116 |
2/2✓ Branch 37 → 38 taken 5042 times.
✓ Branch 37 → 43 taken 24214 times.
|
29256 | if (ctx->typeLst()) { |
| 117 | 5042 | procDefNode->hasTemplateTypes = true; | |
| 118 |
3/6✓ Branch 38 → 39 taken 5042 times.
✗ Branch 38 → 75 not taken.
✓ Branch 39 → 40 taken 5042 times.
✗ Branch 39 → 75 not taken.
✓ Branch 40 → 41 taken 5042 times.
✗ Branch 40 → 73 not taken.
|
5042 | procDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 119 | } | ||
| 120 |
2/2✓ Branch 44 → 45 taken 21629 times.
✓ Branch 44 → 50 taken 7627 times.
|
29256 | if (ctx->paramLst()) { |
| 121 | 21629 | procDefNode->hasParams = true; | |
| 122 |
3/6✓ Branch 45 → 46 taken 21629 times.
✗ Branch 45 → 78 not taken.
✓ Branch 46 → 47 taken 21629 times.
✗ Branch 46 → 78 not taken.
✓ Branch 47 → 48 taken 21629 times.
✗ Branch 47 → 76 not taken.
|
21629 | procDefNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 123 | } | ||
| 124 |
4/8✓ Branch 50 → 51 taken 29256 times.
✗ Branch 50 → 81 not taken.
✓ Branch 51 → 52 taken 29256 times.
✗ Branch 51 → 81 not taken.
✓ Branch 52 → 53 taken 29256 times.
✗ Branch 52 → 79 not taken.
✓ Branch 54 → 55 taken 29256 times.
✗ Branch 54 → 82 not taken.
|
29256 | procDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 125 | |||
| 126 |
1/2✓ Branch 60 → 61 taken 29256 times.
✗ Branch 60 → 82 not taken.
|
58512 | return concludeNode(procDefNode); |
| 127 | } | ||
| 128 | |||
| 129 | 77984 | std::any ASTBuilder::visitFctName(SpiceParser::FctNameContext *ctx) { | |
| 130 |
1/2✓ Branch 2 → 3 taken 77984 times.
✗ Branch 2 → 54 not taken.
|
77984 | const auto fctNameNode = createNode<FctNameNode>(ctx); |
| 131 | |||
| 132 | // Extract function name | ||
| 133 |
1/2✓ Branch 3 → 4 taken 77984 times.
✗ Branch 3 → 54 not taken.
|
77984 | std::stringstream fqName; |
| 134 |
3/4✓ Branch 4 → 5 taken 77984 times.
✗ Branch 4 → 52 not taken.
✓ Branch 5 → 6 taken 48845 times.
✓ Branch 5 → 14 taken 29139 times.
|
77984 | if (ctx->TYPE_IDENTIFIER()) { |
| 135 |
2/4✓ Branch 6 → 7 taken 48845 times.
✗ Branch 6 → 45 not taken.
✓ Branch 7 → 8 taken 48845 times.
✗ Branch 7 → 45 not taken.
|
48845 | const std::string typeIdentifier = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 136 |
1/2✓ Branch 8 → 9 taken 48845 times.
✗ Branch 8 → 43 not taken.
|
48845 | fctNameNode->structName = typeIdentifier; |
| 137 |
2/4✓ Branch 9 → 10 taken 48845 times.
✗ Branch 9 → 43 not taken.
✓ Branch 10 → 11 taken 48845 times.
✗ Branch 10 → 43 not taken.
|
48845 | fqName << typeIdentifier << MEMBER_ACCESS_TOKEN; |
| 138 |
1/2✓ Branch 11 → 12 taken 48845 times.
✗ Branch 11 → 43 not taken.
|
48845 | fctNameNode->nameFragments.push_back(typeIdentifier); |
| 139 | 48845 | } | |
| 140 |
3/4✓ Branch 14 → 15 taken 77984 times.
✗ Branch 14 → 52 not taken.
✓ Branch 15 → 16 taken 69876 times.
✓ Branch 15 → 23 taken 8108 times.
|
77984 | if (ctx->IDENTIFIER()) { |
| 141 |
2/4✓ Branch 16 → 17 taken 69876 times.
✗ Branch 16 → 48 not taken.
✓ Branch 17 → 18 taken 69876 times.
✗ Branch 17 → 48 not taken.
|
69876 | const std::string fctIdentifier = getIdentifier(ctx->IDENTIFIER(), false); |
| 142 |
1/2✓ Branch 18 → 19 taken 69876 times.
✗ Branch 18 → 46 not taken.
|
69876 | fctNameNode->name = fctIdentifier; |
| 143 |
1/2✓ Branch 19 → 20 taken 69876 times.
✗ Branch 19 → 46 not taken.
|
69876 | fqName << fctIdentifier; |
| 144 |
1/2✓ Branch 20 → 21 taken 69876 times.
✗ Branch 20 → 46 not taken.
|
69876 | fctNameNode->nameFragments.push_back(fctIdentifier); |
| 145 | 69876 | } | |
| 146 |
1/2✓ Branch 23 → 24 taken 77984 times.
✗ Branch 23 → 49 not taken.
|
77984 | fctNameNode->fqName = fqName.str(); |
| 147 | |||
| 148 | // Visit children | ||
| 149 |
3/4✓ Branch 26 → 27 taken 77984 times.
✗ Branch 26 → 52 not taken.
✓ Branch 27 → 28 taken 8108 times.
✓ Branch 27 → 32 taken 69876 times.
|
77984 | if (ctx->overloadableOp()) |
| 150 |
2/4✓ Branch 28 → 29 taken 8108 times.
✗ Branch 28 → 50 not taken.
✓ Branch 29 → 30 taken 8108 times.
✗ Branch 29 → 50 not taken.
|
8108 | visit(ctx->overloadableOp()); |
| 151 | |||
| 152 |
1/2✓ Branch 38 → 39 taken 77984 times.
✗ Branch 38 → 51 not taken.
|
155968 | return concludeNode(fctNameNode); |
| 153 | 77984 | } | |
| 154 | |||
| 155 | 7467 | std::any ASTBuilder::visitStructDef(SpiceParser::StructDefContext *ctx) { | |
| 156 | 7467 | const auto structDefNode = createNode<StructDefNode>(ctx); | |
| 157 | |||
| 158 | // Enrich | ||
| 159 |
3/4✓ Branch 3 → 4 taken 7467 times.
✗ Branch 3 → 103 not taken.
✓ Branch 4 → 5 taken 7465 times.
✓ Branch 4 → 103 taken 2 times.
|
7467 | structDefNode->structName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 160 | 7465 | structDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 161 | |||
| 162 | // Visit children | ||
| 163 |
2/2✓ Branch 9 → 10 taken 248 times.
✓ Branch 9 → 49 taken 7217 times.
|
7465 | if (ctx->topLevelDefAttr()) { |
| 164 |
3/6✓ Branch 10 → 11 taken 248 times.
✗ Branch 10 → 106 not taken.
✓ Branch 11 → 12 taken 248 times.
✗ Branch 11 → 106 not taken.
✓ Branch 12 → 13 taken 248 times.
✗ Branch 12 → 104 not taken.
|
248 | 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 248 times.
✓ Branch 27 → 28 taken 248 times.
|
744 | for (AttrNode *attr : structDefNode->attrs->attrLst->attributes) |
| 168 | 248 | attr->target = AttrNode::TARGET_STRUCT; | |
| 169 | |||
| 170 | // Check if a custom type id was set | ||
| 171 |
7/18✓ Branch 28 → 29 taken 248 times.
✗ Branch 28 → 35 not taken.
✓ Branch 31 → 32 taken 248 times.
✗ Branch 31 → 107 not taken.
✓ Branch 32 → 33 taken 248 times.
✗ Branch 32 → 107 not taken.
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 248 times.
✓ Branch 36 → 37 taken 248 times.
✗ Branch 36 → 38 not taken.
✓ Branch 38 → 39 taken 248 times.
✗ Branch 38 → 41 not taken.
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 49 taken 248 times.
✗ Branch 107 → 108 not taken.
✗ Branch 107 → 109 not taken.
✗ Branch 111 → 112 not taken.
✗ Branch 111 → 114 not taken.
|
744 | 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 5949 times.
✓ Branch 50 → 56 taken 1516 times.
|
7465 | if (ctx->qualifierLst()) |
| 175 |
3/6✓ Branch 51 → 52 taken 5949 times.
✗ Branch 51 → 124 not taken.
✓ Branch 52 → 53 taken 5949 times.
✗ Branch 52 → 124 not taken.
✓ Branch 53 → 54 taken 5949 times.
✗ Branch 53 → 122 not taken.
|
5949 | structDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 176 |
2/2✓ Branch 57 → 58 taken 1462 times.
✓ Branch 57 → 63 taken 6003 times.
|
7465 | if (ctx->LESS()) { |
| 177 | 1462 | structDefNode->hasTemplateTypes = true; | |
| 178 |
3/6✓ Branch 58 → 59 taken 1462 times.
✗ Branch 58 → 127 not taken.
✓ Branch 59 → 60 taken 1462 times.
✗ Branch 59 → 127 not taken.
✓ Branch 60 → 61 taken 1462 times.
✗ Branch 60 → 125 not taken.
|
1462 | structDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0))); |
| 179 | } | ||
| 180 |
2/2✓ Branch 64 → 65 taken 742 times.
✓ Branch 64 → 73 taken 6723 times.
|
7465 | if (ctx->COLON()) { |
| 181 | 742 | structDefNode->hasInterfaces = true; | |
| 182 |
5/8✓ Branch 65 → 66 taken 612 times.
✓ Branch 65 → 67 taken 130 times.
✓ Branch 68 → 69 taken 742 times.
✗ Branch 68 → 130 not taken.
✓ Branch 69 → 70 taken 742 times.
✗ Branch 69 → 130 not taken.
✓ Branch 70 → 71 taken 742 times.
✗ Branch 70 → 128 not taken.
|
742 | structDefNode->interfaceTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(structDefNode->hasTemplateTypes ? 1 : 0))); |
| 183 | } | ||
| 184 |
3/4✓ Branch 73 → 74 taken 7465 times.
✗ Branch 73 → 137 not taken.
✓ Branch 91 → 76 taken 15049 times.
✓ Branch 91 → 92 taken 7465 times.
|
29979 | for (SpiceParser::FieldContext *field : ctx->field()) |
| 185 |
3/6✓ Branch 78 → 79 taken 15049 times.
✗ Branch 78 → 133 not taken.
✓ Branch 79 → 80 taken 15049 times.
✗ Branch 79 → 131 not taken.
✓ Branch 80 → 81 taken 15049 times.
✗ Branch 80 → 131 not taken.
|
22514 | structDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field))); |
| 186 | |||
| 187 |
1/2✓ Branch 99 → 100 taken 7465 times.
✗ Branch 99 → 138 not taken.
|
14930 | return concludeNode(structDefNode); |
| 188 | } | ||
| 189 | |||
| 190 | 805 | std::any ASTBuilder::visitInterfaceDef(SpiceParser::InterfaceDefContext *ctx) { | |
| 191 | 805 | const auto interfaceDefNode = createNode<InterfaceDefNode>(ctx); | |
| 192 | |||
| 193 | // Enrich | ||
| 194 |
2/4✓ Branch 3 → 4 taken 805 times.
✗ Branch 3 → 93 not taken.
✓ Branch 4 → 5 taken 805 times.
✗ Branch 4 → 93 not taken.
|
805 | interfaceDefNode->interfaceName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 195 | 805 | interfaceDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 196 | |||
| 197 | // Visit children | ||
| 198 |
2/2✓ Branch 9 → 10 taken 370 times.
✓ Branch 9 → 49 taken 435 times.
|
805 | if (ctx->topLevelDefAttr()) { |
| 199 |
3/6✓ Branch 10 → 11 taken 370 times.
✗ Branch 10 → 96 not taken.
✓ Branch 11 → 12 taken 370 times.
✗ Branch 11 → 96 not taken.
✓ Branch 12 → 13 taken 370 times.
✗ Branch 12 → 94 not taken.
|
370 | 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 370 times.
✓ Branch 27 → 28 taken 370 times.
|
1110 | for (AttrNode *attr : interfaceDefNode->attrs->attrLst->attributes) |
| 203 | 370 | attr->target = AttrNode::TARGET_INTERFACE; | |
| 204 | |||
| 205 | // Check if a custom type id was set | ||
| 206 |
7/18✓ Branch 28 → 29 taken 370 times.
✗ Branch 28 → 35 not taken.
✓ Branch 31 → 32 taken 370 times.
✗ Branch 31 → 97 not taken.
✓ Branch 32 → 33 taken 370 times.
✗ Branch 32 → 97 not taken.
✓ Branch 33 → 34 taken 370 times.
✗ Branch 33 → 35 not taken.
✓ Branch 36 → 37 taken 370 times.
✗ Branch 36 → 38 not taken.
✓ Branch 38 → 39 taken 370 times.
✗ Branch 38 → 41 not taken.
✓ Branch 41 → 42 taken 370 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.
|
1110 | if (interfaceDefNode->attrs && interfaceDefNode->attrs->attrLst->hasAttr(ATTR_CORE_COMPILER_FIXED_TYPE_ID)) |
| 207 |
2/4✓ Branch 44 → 45 taken 370 times.
✗ Branch 44 → 108 not taken.
✓ Branch 45 → 46 taken 370 times.
✗ Branch 45 → 106 not taken.
|
1110 | interfaceDefNode->typeId = interfaceDefNode->attrs->attrLst->getAttrValueByName(ATTR_CORE_COMPILER_FIXED_TYPE_ID)->intValue; |
| 208 | } | ||
| 209 |
2/2✓ Branch 50 → 51 taken 763 times.
✓ Branch 50 → 56 taken 42 times.
|
805 | if (ctx->qualifierLst()) |
| 210 |
3/6✓ Branch 51 → 52 taken 763 times.
✗ Branch 51 → 114 not taken.
✓ Branch 52 → 53 taken 763 times.
✗ Branch 52 → 114 not taken.
✓ Branch 53 → 54 taken 763 times.
✗ Branch 53 → 112 not taken.
|
763 | interfaceDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 211 |
2/2✓ Branch 57 → 58 taken 378 times.
✓ Branch 57 → 63 taken 427 times.
|
805 | if (ctx->LESS()) { |
| 212 | 378 | interfaceDefNode->hasTemplateTypes = true; | |
| 213 |
3/6✓ Branch 58 → 59 taken 378 times.
✗ Branch 58 → 117 not taken.
✓ Branch 59 → 60 taken 378 times.
✗ Branch 59 → 117 not taken.
✓ Branch 60 → 61 taken 378 times.
✗ Branch 60 → 115 not taken.
|
378 | interfaceDefNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 214 | } | ||
| 215 |
3/4✓ Branch 63 → 64 taken 805 times.
✗ Branch 63 → 124 not taken.
✓ Branch 81 → 66 taken 4869 times.
✓ Branch 81 → 82 taken 805 times.
|
6479 | for (SpiceParser::SignatureContext *signature : ctx->signature()) |
| 216 |
3/6✓ Branch 68 → 69 taken 4869 times.
✗ Branch 68 → 120 not taken.
✓ Branch 69 → 70 taken 4869 times.
✗ Branch 69 → 118 not taken.
✓ Branch 70 → 71 taken 4869 times.
✗ Branch 70 → 118 not taken.
|
5674 | interfaceDefNode->signatures.push_back(std::any_cast<SignatureNode *>(visit(signature))); |
| 217 | |||
| 218 |
1/2✓ Branch 89 → 90 taken 805 times.
✗ Branch 89 → 125 not taken.
|
1610 | return concludeNode(interfaceDefNode); |
| 219 | } | ||
| 220 | |||
| 221 | 68 | std::any ASTBuilder::visitUnionDef(SpiceParser::UnionDefContext *ctx) { | |
| 222 | 68 | const auto unionDefNode = createNode<UnionDefNode>(ctx); | |
| 223 | |||
| 224 | // Enrich | ||
| 225 |
2/4✓ Branch 3 → 4 taken 68 times.
✗ Branch 3 → 93 not taken.
✓ Branch 4 → 5 taken 68 times.
✗ Branch 4 → 93 not taken.
|
68 | unionDefNode->unionName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 226 | 68 | unionDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 227 | |||
| 228 | // Visit children | ||
| 229 |
1/2✗ Branch 9 → 10 not taken.
✓ Branch 9 → 49 taken 68 times.
|
68 | 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 32 times.
✓ Branch 50 → 56 taken 36 times.
|
68 | if (ctx->qualifierLst()) |
| 241 |
3/6✓ Branch 51 → 52 taken 32 times.
✗ Branch 51 → 114 not taken.
✓ Branch 52 → 53 taken 32 times.
✗ Branch 52 → 114 not taken.
✓ Branch 53 → 54 taken 32 times.
✗ Branch 53 → 112 not taken.
|
32 | unionDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 242 |
2/2✓ Branch 57 → 58 taken 4 times.
✓ Branch 57 → 63 taken 64 times.
|
68 | 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 68 times.
✗ Branch 63 → 124 not taken.
✓ Branch 81 → 66 taken 318 times.
✓ Branch 81 → 82 taken 68 times.
|
454 | for (SpiceParser::FieldContext *field : ctx->field()) |
| 247 |
3/6✓ Branch 68 → 69 taken 318 times.
✗ Branch 68 → 120 not taken.
✓ Branch 69 → 70 taken 318 times.
✗ Branch 69 → 118 not taken.
✓ Branch 70 → 71 taken 318 times.
✗ Branch 70 → 118 not taken.
|
386 | unionDefNode->fields.push_back(std::any_cast<FieldNode *>(visit(field))); |
| 248 | |||
| 249 |
1/2✓ Branch 89 → 90 taken 68 times.
✗ Branch 89 → 125 not taken.
|
136 | return concludeNode(unionDefNode); |
| 250 | } | ||
| 251 | |||
| 252 | 1232 | std::any ASTBuilder::visitEnumDef(SpiceParser::EnumDefContext *ctx) { | |
| 253 | 1232 | const auto enumDefNode = createNode<EnumDefNode>(ctx); | |
| 254 | |||
| 255 | // Enrich | ||
| 256 |
2/4✓ Branch 3 → 4 taken 1232 times.
✗ Branch 3 → 43 not taken.
✓ Branch 4 → 5 taken 1232 times.
✗ Branch 4 → 43 not taken.
|
1232 | enumDefNode->enumName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 257 | 1232 | enumDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 258 | |||
| 259 | // Visit children | ||
| 260 |
2/2✓ Branch 9 → 10 taken 1149 times.
✓ Branch 9 → 15 taken 83 times.
|
1232 | if (ctx->qualifierLst()) |
| 261 |
3/6✓ Branch 10 → 11 taken 1149 times.
✗ Branch 10 → 46 not taken.
✓ Branch 11 → 12 taken 1149 times.
✗ Branch 11 → 46 not taken.
✓ Branch 12 → 13 taken 1149 times.
✗ Branch 12 → 44 not taken.
|
1149 | enumDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 262 |
3/6✓ Branch 15 → 16 taken 1232 times.
✗ Branch 15 → 49 not taken.
✓ Branch 16 → 17 taken 1232 times.
✗ Branch 16 → 49 not taken.
✓ Branch 17 → 18 taken 1232 times.
✗ Branch 17 → 47 not taken.
|
1232 | 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 11054 times.
✓ Branch 32 → 33 taken 1232 times.
|
13518 | for (EnumItemNode *enumItem : enumDefNode->itemLst->items) |
| 266 | 11054 | enumItem->enumDef = enumDefNode; | |
| 267 | |||
| 268 |
1/2✓ Branch 39 → 40 taken 1232 times.
✗ Branch 39 → 50 not taken.
|
2464 | return concludeNode(enumDefNode); |
| 269 | } | ||
| 270 | |||
| 271 | 4499 | std::any ASTBuilder::visitGenericTypeDef(SpiceParser::GenericTypeDefContext *ctx) { | |
| 272 | 4499 | const auto genericTypeDefNode = createNode<GenericTypeDefNode>(ctx); | |
| 273 | |||
| 274 | // Enrich | ||
| 275 |
2/4✓ Branch 3 → 4 taken 4499 times.
✗ Branch 3 → 21 not taken.
✓ Branch 4 → 5 taken 4499 times.
✗ Branch 4 → 21 not taken.
|
4499 | genericTypeDefNode->typeName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 276 | |||
| 277 | // Visit children | ||
| 278 |
4/8✓ Branch 7 → 8 taken 4499 times.
✗ Branch 7 → 24 not taken.
✓ Branch 8 → 9 taken 4499 times.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 4499 times.
✗ Branch 9 → 22 not taken.
✓ Branch 11 → 12 taken 4499 times.
✗ Branch 11 → 25 not taken.
|
4499 | genericTypeDefNode->typeAltsLst = std::any_cast<TypeAltsLstNode *>(visit(ctx->typeAltsLst())); |
| 279 | |||
| 280 |
1/2✓ Branch 17 → 18 taken 4499 times.
✗ Branch 17 → 25 not taken.
|
8998 | return concludeNode(genericTypeDefNode); |
| 281 | } | ||
| 282 | |||
| 283 | 707 | std::any ASTBuilder::visitAliasDef(SpiceParser::AliasDefContext *ctx) { | |
| 284 | 707 | const auto aliasDefNode = createNode<AliasDefNode>(ctx); | |
| 285 | |||
| 286 | // Enrich | ||
| 287 |
2/4✓ Branch 3 → 4 taken 707 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 707 times.
✗ Branch 4 → 33 not taken.
|
707 | aliasDefNode->aliasName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 288 |
2/4✓ Branch 7 → 8 taken 707 times.
✗ Branch 7 → 34 not taken.
✓ Branch 8 → 9 taken 707 times.
✗ Branch 8 → 34 not taken.
|
707 | aliasDefNode->dataTypeString = ctx->dataType()->getText(); |
| 289 | 707 | aliasDefNode->typeId = resourceManager.getNextCustomTypeId(); | |
| 290 | |||
| 291 | // Visit children | ||
| 292 |
2/2✓ Branch 13 → 14 taken 221 times.
✓ Branch 13 → 19 taken 486 times.
|
707 | if (ctx->qualifierLst()) |
| 293 |
3/6✓ Branch 14 → 15 taken 221 times.
✗ Branch 14 → 37 not taken.
✓ Branch 15 → 16 taken 221 times.
✗ Branch 15 → 37 not taken.
✓ Branch 16 → 17 taken 221 times.
✗ Branch 16 → 35 not taken.
|
221 | aliasDefNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 294 |
4/8✓ Branch 19 → 20 taken 707 times.
✗ Branch 19 → 40 not taken.
✓ Branch 20 → 21 taken 707 times.
✗ Branch 20 → 40 not taken.
✓ Branch 21 → 22 taken 707 times.
✗ Branch 21 → 38 not taken.
✓ Branch 23 → 24 taken 707 times.
✗ Branch 23 → 41 not taken.
|
707 | aliasDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 295 | |||
| 296 |
1/2✓ Branch 29 → 30 taken 707 times.
✗ Branch 29 → 41 not taken.
|
1414 | return concludeNode(aliasDefNode); |
| 297 | } | ||
| 298 | |||
| 299 | 5945 | std::any ASTBuilder::visitGlobalVarDef(SpiceParser::GlobalVarDefContext *ctx) { | |
| 300 | 5945 | const auto globalVarDefNode = createNode<GlobalVarDefNode>(ctx); | |
| 301 | |||
| 302 | // Enrich | ||
| 303 |
2/4✓ Branch 3 → 4 taken 5945 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 5945 times.
✗ Branch 4 → 28 not taken.
|
5945 | globalVarDefNode->varName = getIdentifier(ctx->TYPE_IDENTIFIER(), true); |
| 304 | |||
| 305 | // Visit children | ||
| 306 |
3/6✓ Branch 7 → 8 taken 5945 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 5945 times.
✗ Branch 8 → 31 not taken.
✓ Branch 9 → 10 taken 5945 times.
✗ Branch 9 → 29 not taken.
|
5945 | globalVarDefNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 307 | 5945 | globalVarDefNode->dataType->isGlobalType = true; | |
| 308 |
2/2✓ Branch 12 → 13 taken 5941 times.
✓ Branch 12 → 18 taken 4 times.
|
5945 | if (ctx->constant()) { |
| 309 | 5941 | globalVarDefNode->hasValue = true; | |
| 310 |
3/6✓ Branch 13 → 14 taken 5941 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 5941 times.
✗ Branch 14 → 34 not taken.
✓ Branch 15 → 16 taken 5941 times.
✗ Branch 15 → 32 not taken.
|
5941 | globalVarDefNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 311 | } | ||
| 312 | |||
| 313 |
1/2✓ Branch 24 → 25 taken 5945 times.
✗ Branch 24 → 35 not taken.
|
11890 | return concludeNode(globalVarDefNode); |
| 314 | } | ||
| 315 | |||
| 316 | 8887 | std::any ASTBuilder::visitExtDecl(SpiceParser::ExtDeclContext *ctx) { | |
| 317 | 8887 | const auto extDeclNode = createNode<ExtDeclNode>(ctx); | |
| 318 | |||
| 319 | // Enrich | ||
| 320 |
6/10✓ Branch 3 → 4 taken 8887 times.
✗ Branch 3 → 57 not taken.
✓ Branch 4 → 5 taken 6093 times.
✓ Branch 4 → 7 taken 2794 times.
✓ Branch 5 → 6 taken 6093 times.
✗ Branch 5 → 57 not taken.
✓ Branch 7 → 8 taken 2794 times.
✗ Branch 7 → 57 not taken.
✓ Branch 9 → 10 taken 8887 times.
✗ Branch 9 → 57 not taken.
|
8887 | 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 8885 times.
|
8887 | 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 7270 times.
✓ Branch 34 → 40 taken 1617 times.
|
8887 | if (ctx->F()) { |
| 331 |
3/6✓ Branch 35 → 36 taken 7270 times.
✗ Branch 35 → 63 not taken.
✓ Branch 36 → 37 taken 7270 times.
✗ Branch 36 → 63 not taken.
✓ Branch 37 → 38 taken 7270 times.
✗ Branch 37 → 61 not taken.
|
7270 | extDeclNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 332 | 7270 | extDeclNode->returnType->isReturnType = true; | |
| 333 | } | ||
| 334 |
2/2✓ Branch 41 → 42 taken 8467 times.
✓ Branch 41 → 47 taken 420 times.
|
8887 | if (ctx->typeLstWithEllipsis()) { |
| 335 | 8467 | extDeclNode->hasArgs = true; | |
| 336 |
3/6✓ Branch 42 → 43 taken 8467 times.
✗ Branch 42 → 66 not taken.
✓ Branch 43 → 44 taken 8467 times.
✗ Branch 43 → 66 not taken.
✓ Branch 44 → 45 taken 8467 times.
✗ Branch 44 → 64 not taken.
|
8467 | extDeclNode->argTypeLst = std::any_cast<TypeLstWithEllipsisNode *>(visit(ctx->typeLstWithEllipsis())); |
| 337 | } | ||
| 338 | |||
| 339 |
1/2✓ Branch 53 → 54 taken 8887 times.
✗ Branch 53 → 67 not taken.
|
17774 | return concludeNode(extDeclNode); |
| 340 | } | ||
| 341 | |||
| 342 | 5908 | std::any ASTBuilder::visitImportDef(SpiceParser::ImportDefContext *ctx) { | |
| 343 |
1/2✓ Branch 2 → 3 taken 5908 times.
✗ Branch 2 → 32 not taken.
|
5908 | const auto importDefNode = createNode<ImportDefNode>(ctx); |
| 344 | |||
| 345 | // Extract path | ||
| 346 |
2/4✓ Branch 3 → 4 taken 5908 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 5908 times.
✗ Branch 4 → 32 not taken.
|
5908 | const std::string pathStr = ctx->STRING_LIT()->getText(); |
| 347 |
1/2✓ Branch 6 → 7 taken 5908 times.
✗ Branch 6 → 27 not taken.
|
5908 | 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 5908 times.
✗ Branch 9 → 28 not taken.
✓ Branch 10 → 11 taken 202 times.
✓ Branch 10 → 13 taken 5706 times.
✓ Branch 11 → 12 taken 202 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 14 taken 202 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 5706 times.
✗ Branch 13 → 28 not taken.
✓ Branch 16 → 17 taken 5908 times.
✗ Branch 16 → 29 not taken.
|
5908 | importDefNode->importName = ctx->AS() ? getIdentifier(ctx->IDENTIFIER(), false) : importDefNode->importPath; |
| 351 | |||
| 352 |
1/2✓ Branch 22 → 23 taken 5908 times.
✗ Branch 22 → 29 not taken.
|
11816 | return concludeNode(importDefNode); |
| 353 | 5908 | } | |
| 354 | |||
| 355 | 17404 | std::any ASTBuilder::visitUnsafeBlock(SpiceParser::UnsafeBlockContext *ctx) { | |
| 356 | 17404 | const auto unsafeBlockDefNode = createNode<UnsafeBlockNode>(ctx); | |
| 357 | |||
| 358 | // Visit children | ||
| 359 |
4/8✓ Branch 3 → 4 taken 17404 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 17404 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 17404 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 17404 times.
✗ Branch 7 → 20 not taken.
|
17404 | unsafeBlockDefNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 360 | |||
| 361 |
1/2✓ Branch 13 → 14 taken 17404 times.
✗ Branch 13 → 20 not taken.
|
34808 | return concludeNode(unsafeBlockDefNode); |
| 362 | } | ||
| 363 | |||
| 364 | 6412 | std::any ASTBuilder::visitForLoop(SpiceParser::ForLoopContext *ctx) { | |
| 365 | 6412 | const auto forLoopNode = createNode<ForLoopNode>(ctx); | |
| 366 | |||
| 367 |
2/4✓ Branch 3 → 4 taken 6412 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 6412 times.
✗ Branch 4 → 20 not taken.
|
6412 | visit(ctx->forHead()); |
| 368 |
4/8✓ Branch 6 → 7 taken 6412 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 6412 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 6412 times.
✗ Branch 8 → 21 not taken.
✓ Branch 10 → 11 taken 6412 times.
✗ Branch 10 → 24 not taken.
|
6412 | forLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 369 | |||
| 370 |
1/2✓ Branch 16 → 17 taken 6412 times.
✗ Branch 16 → 24 not taken.
|
12824 | return concludeNode(forLoopNode); |
| 371 | } | ||
| 372 | |||
| 373 | 6412 | std::any ASTBuilder::visitForHead(SpiceParser::ForHeadContext *ctx) { | |
| 374 | 6412 | const auto forLoopNode = resumeForExpansion<ForLoopNode>(); | |
| 375 | |||
| 376 | // Visit children | ||
| 377 |
3/6✓ Branch 14 → 15 taken 6412 times.
✗ Branch 14 → 32 not taken.
✓ Branch 15 → 16 taken 6412 times.
✗ Branch 15 → 32 not taken.
✓ Branch 16 → 17 taken 6412 times.
✗ Branch 16 → 30 not taken.
|
6412 | forLoopNode->initDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt())); |
| 378 |
3/6✓ Branch 18 → 19 taken 6412 times.
✗ Branch 18 → 35 not taken.
✓ Branch 19 → 20 taken 6412 times.
✗ Branch 19 → 35 not taken.
✓ Branch 20 → 21 taken 6412 times.
✗ Branch 20 → 33 not taken.
|
6412 | forLoopNode->condAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(0))); |
| 379 |
3/6✓ Branch 22 → 23 taken 6412 times.
✗ Branch 22 → 38 not taken.
✓ Branch 23 → 24 taken 6412 times.
✗ Branch 23 → 38 not taken.
✓ Branch 24 → 25 taken 6412 times.
✗ Branch 24 → 36 not taken.
|
6412 | forLoopNode->incAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr(1))); |
| 380 | |||
| 381 |
1/2✓ Branch 26 → 27 taken 6412 times.
✗ Branch 26 → 39 not taken.
|
12824 | return nullptr; |
| 382 | } | ||
| 383 | |||
| 384 | 819 | std::any ASTBuilder::visitForeachLoop(SpiceParser::ForeachLoopContext *ctx) { | |
| 385 | 819 | const auto foreachLoopNode = createNode<ForeachLoopNode>(ctx); | |
| 386 | |||
| 387 | // Visit children | ||
| 388 |
2/4✓ Branch 3 → 4 taken 819 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 819 times.
✗ Branch 4 → 20 not taken.
|
819 | visit(ctx->foreachHead()); |
| 389 |
3/6✓ Branch 6 → 7 taken 819 times.
✗ Branch 6 → 23 not taken.
✓ Branch 7 → 8 taken 819 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 819 times.
✗ Branch 8 → 21 not taken.
|
819 | 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 819 times.
✗ Branch 10 → 24 not taken.
|
819 | foreachLoopNode->itemVarDecl->isForEachItem = true; |
| 393 | |||
| 394 |
1/2✓ Branch 16 → 17 taken 819 times.
✗ Branch 16 → 24 not taken.
|
1638 | return concludeNode(foreachLoopNode); |
| 395 | } | ||
| 396 | |||
| 397 | 819 | std::any ASTBuilder::visitForeachHead(SpiceParser::ForeachHeadContext *ctx) { | |
| 398 | 819 | const auto foreachLoopNode = resumeForExpansion<ForeachLoopNode>(); | |
| 399 | |||
| 400 | // Visit children | ||
| 401 |
3/4✓ Branch 14 → 15 taken 819 times.
✗ Branch 14 → 45 not taken.
✓ Branch 17 → 18 taken 703 times.
✓ Branch 17 → 23 taken 116 times.
|
819 | if (ctx->declStmt().size() == 1) { |
| 402 |
3/6✓ Branch 18 → 19 taken 703 times.
✗ Branch 18 → 48 not taken.
✓ Branch 19 → 20 taken 703 times.
✗ Branch 19 → 48 not taken.
✓ Branch 20 → 21 taken 703 times.
✗ Branch 20 → 46 not taken.
|
703 | foreachLoopNode->itemVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0))); |
| 403 |
2/4✓ Branch 23 → 24 taken 116 times.
✗ Branch 23 → 49 not taken.
✓ Branch 26 → 27 taken 116 times.
✗ Branch 26 → 36 not taken.
|
116 | } else if (ctx->declStmt().size() == 2) { |
| 404 |
3/6✓ Branch 27 → 28 taken 116 times.
✗ Branch 27 → 52 not taken.
✓ Branch 28 → 29 taken 116 times.
✗ Branch 28 → 52 not taken.
✓ Branch 29 → 30 taken 116 times.
✗ Branch 29 → 50 not taken.
|
116 | foreachLoopNode->idxVarDecl = std::any_cast<DeclStmtNode *>(visit(ctx->declStmt(0))); |
| 405 |
3/6✓ Branch 31 → 32 taken 116 times.
✗ Branch 31 → 55 not taken.
✓ Branch 32 → 33 taken 116 times.
✗ Branch 32 → 55 not taken.
✓ Branch 33 → 34 taken 116 times.
✗ Branch 33 → 53 not taken.
|
116 | 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 819 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 819 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 819 times.
✗ Branch 39 → 56 not taken.
|
819 | foreachLoopNode->iteratorAssign = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 410 | |||
| 411 |
1/2✓ Branch 41 → 42 taken 819 times.
✗ Branch 41 → 59 not taken.
|
1638 | return nullptr; |
| 412 | } | ||
| 413 | |||
| 414 | 2987 | std::any ASTBuilder::visitWhileLoop(SpiceParser::WhileLoopContext *ctx) { | |
| 415 | 2987 | const auto whileLoopNode = createNode<WhileLoopNode>(ctx); | |
| 416 | |||
| 417 | // Visit children | ||
| 418 |
3/6✓ Branch 3 → 4 taken 2987 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 2987 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 2987 times.
✗ Branch 5 → 21 not taken.
|
2987 | whileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 419 |
4/8✓ Branch 7 → 8 taken 2987 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 2987 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 2987 times.
✗ Branch 9 → 24 not taken.
✓ Branch 11 → 12 taken 2987 times.
✗ Branch 11 → 27 not taken.
|
2987 | whileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 420 | |||
| 421 |
1/2✓ Branch 17 → 18 taken 2987 times.
✗ Branch 17 → 27 not taken.
|
5974 | return concludeNode(whileLoopNode); |
| 422 | } | ||
| 423 | |||
| 424 | 33 | std::any ASTBuilder::visitDoWhileLoop(SpiceParser::DoWhileLoopContext *ctx) { | |
| 425 | 33 | const auto doWhileLoopNode = createNode<DoWhileLoopNode>(ctx); | |
| 426 | |||
| 427 | // Visit children | ||
| 428 |
3/6✓ Branch 3 → 4 taken 33 times.
✗ Branch 3 → 23 not taken.
✓ Branch 4 → 5 taken 33 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 33 times.
✗ Branch 5 → 21 not taken.
|
33 | doWhileLoopNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 429 |
4/8✓ Branch 7 → 8 taken 33 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 33 times.
✗ Branch 8 → 26 not taken.
✓ Branch 9 → 10 taken 33 times.
✗ Branch 9 → 24 not taken.
✓ Branch 11 → 12 taken 33 times.
✗ Branch 11 → 27 not taken.
|
33 | doWhileLoopNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 430 | |||
| 431 |
1/2✓ Branch 17 → 18 taken 33 times.
✗ Branch 17 → 27 not taken.
|
66 | return concludeNode(doWhileLoopNode); |
| 432 | } | ||
| 433 | |||
| 434 | 37620 | std::any ASTBuilder::visitIfStmt(SpiceParser::IfStmtContext *ctx) { | |
| 435 | 37620 | const auto ifStmtNode = createNode<IfStmtNode>(ctx); | |
| 436 | |||
| 437 | // Visit children | ||
| 438 |
3/6✓ Branch 3 → 4 taken 37620 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 37620 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 37620 times.
✗ Branch 5 → 28 not taken.
|
37620 | ifStmtNode->condition = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 439 |
3/6✓ Branch 7 → 8 taken 37620 times.
✗ Branch 7 → 33 not taken.
✓ Branch 8 → 9 taken 37620 times.
✗ Branch 8 → 33 not taken.
✓ Branch 9 → 10 taken 37620 times.
✗ Branch 9 → 31 not taken.
|
37620 | ifStmtNode->thenBody = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 440 |
2/2✓ Branch 12 → 13 taken 2933 times.
✓ Branch 12 → 18 taken 34687 times.
|
37620 | if (ctx->elseStmt()) |
| 441 |
3/6✓ Branch 13 → 14 taken 2933 times.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 2933 times.
✗ Branch 14 → 36 not taken.
✓ Branch 15 → 16 taken 2933 times.
✗ Branch 15 → 34 not taken.
|
2933 | ifStmtNode->elseStmt = std::any_cast<ElseStmtNode *>(visit(ctx->elseStmt())); |
| 442 | |||
| 443 |
1/2✓ Branch 24 → 25 taken 37620 times.
✗ Branch 24 → 37 not taken.
|
75240 | return concludeNode(ifStmtNode); |
| 444 | } | ||
| 445 | |||
| 446 | 2933 | std::any ASTBuilder::visitElseStmt(SpiceParser::ElseStmtContext *ctx) { | |
| 447 | 2933 | const auto elseStmtNode = createNode<ElseStmtNode>(ctx); | |
| 448 | |||
| 449 | // Visit children | ||
| 450 |
2/2✓ Branch 4 → 5 taken 1185 times.
✓ Branch 4 → 10 taken 1748 times.
|
2933 | if (ctx->ifStmt()) { |
| 451 | 1185 | elseStmtNode->isElseIf = true; | |
| 452 |
3/6✓ Branch 5 → 6 taken 1185 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 1185 times.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 1185 times.
✗ Branch 7 → 25 not taken.
|
1185 | elseStmtNode->ifStmt = std::any_cast<IfStmtNode *>(visit(ctx->ifStmt())); |
| 453 | } else { | ||
| 454 |
3/6✓ Branch 10 → 11 taken 1748 times.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 1748 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 1748 times.
✗ Branch 12 → 28 not taken.
|
1748 | elseStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 455 | } | ||
| 456 | |||
| 457 |
1/2✓ Branch 21 → 22 taken 2933 times.
✗ Branch 21 → 31 not taken.
|
5866 | return concludeNode(elseStmtNode); |
| 458 | } | ||
| 459 | |||
| 460 | 189 | std::any ASTBuilder::visitSwitchStmt(SpiceParser::SwitchStmtContext *ctx) { | |
| 461 | 189 | const auto switchStmtNode = createNode<SwitchStmtNode>(ctx); | |
| 462 | |||
| 463 | // Visit children | ||
| 464 |
3/6✓ Branch 3 → 4 taken 189 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 189 times.
✗ Branch 4 → 29 not taken.
✓ Branch 5 → 6 taken 189 times.
✗ Branch 5 → 27 not taken.
|
189 | switchStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 465 |
2/4✓ Branch 7 → 8 taken 189 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 189 times.
✗ Branch 8 → 30 not taken.
|
189 | fetchChildrenIntoVector(switchStmtNode->caseBranches, ctx->caseBranch()); |
| 466 |
2/2✓ Branch 11 → 12 taken 157 times.
✓ Branch 11 → 17 taken 32 times.
|
189 | if (ctx->defaultBranch()) { |
| 467 | 157 | switchStmtNode->hasDefaultBranch = true; | |
| 468 |
3/6✓ Branch 12 → 13 taken 157 times.
✗ Branch 12 → 35 not taken.
✓ Branch 13 → 14 taken 157 times.
✗ Branch 13 → 35 not taken.
✓ Branch 14 → 15 taken 157 times.
✗ Branch 14 → 33 not taken.
|
157 | switchStmtNode->defaultBranch = std::any_cast<DefaultBranchNode *>(visit(ctx->defaultBranch())); |
| 469 | } | ||
| 470 | |||
| 471 |
1/2✓ Branch 23 → 24 taken 189 times.
✗ Branch 23 → 36 not taken.
|
378 | return concludeNode(switchStmtNode); |
| 472 | } | ||
| 473 | |||
| 474 | 1539 | std::any ASTBuilder::visitCaseBranch(SpiceParser::CaseBranchContext *ctx) { | |
| 475 | 1539 | const auto caseBranchNode = createNode<CaseBranchNode>(ctx); | |
| 476 | |||
| 477 | // Visit children | ||
| 478 |
2/4✓ Branch 3 → 4 taken 1539 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 1539 times.
✗ Branch 4 → 20 not taken.
|
1539 | fetchChildrenIntoVector(caseBranchNode->caseConstants, ctx->caseConstant()); |
| 479 |
4/8✓ Branch 6 → 7 taken 1539 times.
✗ Branch 6 → 25 not taken.
✓ Branch 7 → 8 taken 1539 times.
✗ Branch 7 → 25 not taken.
✓ Branch 8 → 9 taken 1539 times.
✗ Branch 8 → 23 not taken.
✓ Branch 10 → 11 taken 1539 times.
✗ Branch 10 → 26 not taken.
|
1539 | caseBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 480 | |||
| 481 |
1/2✓ Branch 16 → 17 taken 1539 times.
✗ Branch 16 → 26 not taken.
|
3078 | return concludeNode(caseBranchNode); |
| 482 | } | ||
| 483 | |||
| 484 | 157 | std::any ASTBuilder::visitDefaultBranch(SpiceParser::DefaultBranchContext *ctx) { | |
| 485 | 157 | const auto defaultBranchNode = createNode<DefaultBranchNode>(ctx); | |
| 486 | |||
| 487 | // Visit children | ||
| 488 |
4/8✓ Branch 3 → 4 taken 157 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 157 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 157 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 157 times.
✗ Branch 7 → 20 not taken.
|
157 | defaultBranchNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 489 | |||
| 490 |
1/2✓ Branch 13 → 14 taken 157 times.
✗ Branch 13 → 20 not taken.
|
314 | return concludeNode(defaultBranchNode); |
| 491 | } | ||
| 492 | |||
| 493 | 123 | std::any ASTBuilder::visitAnonymousBlockStmt(SpiceParser::AnonymousBlockStmtContext *ctx) { | |
| 494 | 123 | const auto anonymousBlockStmtNode = createNode<AnonymousBlockStmtNode>(ctx); | |
| 495 | |||
| 496 | // Visit children | ||
| 497 |
4/8✓ Branch 3 → 4 taken 123 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 123 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 123 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 123 times.
✗ Branch 7 → 20 not taken.
|
123 | anonymousBlockStmtNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 498 | |||
| 499 |
1/2✓ Branch 13 → 14 taken 123 times.
✗ Branch 13 → 20 not taken.
|
246 | return concludeNode(anonymousBlockStmtNode); |
| 500 | } | ||
| 501 | |||
| 502 | 148347 | std::any ASTBuilder::visitStmtLst(SpiceParser::StmtLstContext *ctx) { | |
| 503 | 148347 | const auto stmtLstNode = createNode<StmtLstNode>(ctx); | |
| 504 | |||
| 505 | // Enrich | ||
| 506 |
2/4✓ Branch 3 → 4 taken 148347 times.
✗ Branch 3 → 126 not taken.
✓ Branch 4 → 5 taken 148347 times.
✗ Branch 4 → 126 not taken.
|
148347 | stmtLstNode->closingBraceCodeLoc = CodeLoc(ctx->getStop(), sourceFile); |
| 507 | |||
| 508 | // Visit children | ||
| 509 |
2/2✓ Branch 115 → 7 taken 579334 times.
✓ Branch 115 → 116 taken 148339 times.
|
876020 | for (ParserRuleContext::ParseTree *stmt : ctx->children) { |
| 510 |
3/4✓ Branch 9 → 10 taken 579334 times.
✗ Branch 9 → 11 not taken.
✓ Branch 12 → 13 taken 209917 times.
✓ Branch 12 → 18 taken 369417 times.
|
579334 | if (auto *stmtCtx = dynamic_cast<SpiceParser::StmtContext *>(stmt)) |
| 511 |
4/6✓ Branch 13 → 14 taken 209909 times.
✓ Branch 13 → 129 taken 8 times.
✓ Branch 14 → 15 taken 209909 times.
✗ Branch 14 → 127 not taken.
✓ Branch 15 → 16 taken 209909 times.
✗ Branch 15 → 127 not taken.
|
209917 | stmtLstNode->statements.push_back(std::any_cast<StmtNode *>(visit(stmtCtx))); |
| 512 |
3/4✓ Branch 18 → 19 taken 369417 times.
✗ Branch 18 → 20 not taken.
✓ Branch 21 → 22 taken 6412 times.
✓ Branch 21 → 27 taken 363005 times.
|
369417 | else if (auto *forLoopCtx = dynamic_cast<SpiceParser::ForLoopContext *>(stmt)) |
| 513 |
3/6✓ Branch 22 → 23 taken 6412 times.
✗ Branch 22 → 133 not taken.
✓ Branch 23 → 24 taken 6412 times.
✗ Branch 23 → 131 not taken.
✓ Branch 24 → 25 taken 6412 times.
✗ Branch 24 → 131 not taken.
|
6412 | stmtLstNode->statements.push_back(std::any_cast<ForLoopNode *>(visit(forLoopCtx))); |
| 514 |
3/4✓ Branch 27 → 28 taken 363005 times.
✗ Branch 27 → 29 not taken.
✓ Branch 30 → 31 taken 819 times.
✓ Branch 30 → 36 taken 362186 times.
|
363005 | else if (auto *foreachLoopCtx = dynamic_cast<SpiceParser::ForeachLoopContext *>(stmt)) |
| 515 |
3/6✓ Branch 31 → 32 taken 819 times.
✗ Branch 31 → 137 not taken.
✓ Branch 32 → 33 taken 819 times.
✗ Branch 32 → 135 not taken.
✓ Branch 33 → 34 taken 819 times.
✗ Branch 33 → 135 not taken.
|
819 | stmtLstNode->statements.push_back(std::any_cast<ForeachLoopNode *>(visit(foreachLoopCtx))); |
| 516 |
3/4✓ Branch 36 → 37 taken 362186 times.
✗ Branch 36 → 38 not taken.
✓ Branch 39 → 40 taken 2987 times.
✓ Branch 39 → 45 taken 359199 times.
|
362186 | else if (auto *whileLoopCtx = dynamic_cast<SpiceParser::WhileLoopContext *>(stmt)) |
| 517 |
3/6✓ Branch 40 → 41 taken 2987 times.
✗ Branch 40 → 141 not taken.
✓ Branch 41 → 42 taken 2987 times.
✗ Branch 41 → 139 not taken.
✓ Branch 42 → 43 taken 2987 times.
✗ Branch 42 → 139 not taken.
|
2987 | stmtLstNode->statements.push_back(std::any_cast<WhileLoopNode *>(visit(whileLoopCtx))); |
| 518 |
3/4✓ Branch 45 → 46 taken 359199 times.
✗ Branch 45 → 47 not taken.
✓ Branch 48 → 49 taken 33 times.
✓ Branch 48 → 54 taken 359166 times.
|
359199 | else if (auto *doWhileLoopCtx = dynamic_cast<SpiceParser::DoWhileLoopContext *>(stmt)) |
| 519 |
3/6✓ Branch 49 → 50 taken 33 times.
✗ Branch 49 → 145 not taken.
✓ Branch 50 → 51 taken 33 times.
✗ Branch 50 → 143 not taken.
✓ Branch 51 → 52 taken 33 times.
✗ Branch 51 → 143 not taken.
|
33 | stmtLstNode->statements.push_back(std::any_cast<DoWhileLoopNode *>(visit(doWhileLoopCtx))); |
| 520 |
3/4✓ Branch 54 → 55 taken 359166 times.
✗ Branch 54 → 56 not taken.
✓ Branch 57 → 58 taken 36435 times.
✓ Branch 57 → 63 taken 322731 times.
|
359166 | else if (auto *ifStmtCtx = dynamic_cast<SpiceParser::IfStmtContext *>(stmt)) |
| 521 |
3/6✓ Branch 58 → 59 taken 36435 times.
✗ Branch 58 → 149 not taken.
✓ Branch 59 → 60 taken 36435 times.
✗ Branch 59 → 147 not taken.
✓ Branch 60 → 61 taken 36435 times.
✗ Branch 60 → 147 not taken.
|
36435 | stmtLstNode->statements.push_back(std::any_cast<IfStmtNode *>(visit(ifStmtCtx))); |
| 522 |
3/4✓ Branch 63 → 64 taken 322731 times.
✗ Branch 63 → 65 not taken.
✓ Branch 66 → 67 taken 189 times.
✓ Branch 66 → 72 taken 322542 times.
|
322731 | else if (auto *switchStmtCtx = dynamic_cast<SpiceParser::SwitchStmtContext *>(stmt)) |
| 523 |
3/6✓ Branch 67 → 68 taken 189 times.
✗ Branch 67 → 153 not taken.
✓ Branch 68 → 69 taken 189 times.
✗ Branch 68 → 151 not taken.
✓ Branch 69 → 70 taken 189 times.
✗ Branch 69 → 151 not taken.
|
189 | stmtLstNode->statements.push_back(std::any_cast<SwitchStmtNode *>(visit(switchStmtCtx))); |
| 524 |
3/4✓ Branch 72 → 73 taken 322542 times.
✗ Branch 72 → 74 not taken.
✓ Branch 75 → 76 taken 8329 times.
✓ Branch 75 → 81 taken 314213 times.
|
322542 | else if (auto *assetStmtCtx = dynamic_cast<SpiceParser::AssertStmtContext *>(stmt)) |
| 525 |
3/6✓ Branch 76 → 77 taken 8329 times.
✗ Branch 76 → 157 not taken.
✓ Branch 77 → 78 taken 8329 times.
✗ Branch 77 → 155 not taken.
✓ Branch 78 → 79 taken 8329 times.
✗ Branch 78 → 155 not taken.
|
8329 | stmtLstNode->statements.push_back(std::any_cast<AssertStmtNode *>(visit(assetStmtCtx))); |
| 526 |
3/4✓ Branch 81 → 82 taken 314213 times.
✗ Branch 81 → 83 not taken.
✓ Branch 84 → 85 taken 17404 times.
✓ Branch 84 → 90 taken 296809 times.
|
314213 | else if (auto *unsafeBlockCtx = dynamic_cast<SpiceParser::UnsafeBlockContext *>(stmt)) |
| 527 |
3/6✓ Branch 85 → 86 taken 17404 times.
✗ Branch 85 → 161 not taken.
✓ Branch 86 → 87 taken 17404 times.
✗ Branch 86 → 159 not taken.
✓ Branch 87 → 88 taken 17404 times.
✗ Branch 87 → 159 not taken.
|
17404 | stmtLstNode->statements.push_back(std::any_cast<UnsafeBlockNode *>(visit(unsafeBlockCtx))); |
| 528 |
3/4✓ Branch 90 → 91 taken 296809 times.
✗ Branch 90 → 92 not taken.
✓ Branch 93 → 94 taken 123 times.
✓ Branch 93 → 99 taken 296686 times.
|
296809 | else if (auto *anonymousScopeCtx = dynamic_cast<SpiceParser::AnonymousBlockStmtContext *>(stmt)) |
| 529 |
3/6✓ Branch 94 → 95 taken 123 times.
✗ Branch 94 → 165 not taken.
✓ Branch 95 → 96 taken 123 times.
✗ Branch 95 → 163 not taken.
✓ Branch 96 → 97 taken 123 times.
✗ Branch 96 → 163 not taken.
|
123 | 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 148339 times.
✗ Branch 122 → 168 not taken.
|
296678 | return concludeNode(stmtLstNode); |
| 535 | } | ||
| 536 | |||
| 537 | 51083 | std::any ASTBuilder::visitTypeLst(SpiceParser::TypeLstContext *ctx) { | |
| 538 | 51083 | const auto typeLstNode = createNode<TypeLstNode>(ctx); | |
| 539 | |||
| 540 | // Visit children | ||
| 541 |
3/6✓ Branch 3 → 4 taken 51083 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 51083 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 51083 times.
✗ Branch 6 → 19 not taken.
|
51083 | fetchChildrenIntoVector(typeLstNode->dataTypes, ctx->dataType()); |
| 542 | |||
| 543 |
1/2✓ Branch 12 → 13 taken 51083 times.
✗ Branch 12 → 19 not taken.
|
102166 | return concludeNode(typeLstNode); |
| 544 | } | ||
| 545 | |||
| 546 | 8467 | std::any ASTBuilder::visitTypeLstWithEllipsis(SpiceParser::TypeLstWithEllipsisContext *ctx) { | |
| 547 | 8467 | const auto typeLstWithEllipsisNode = createNode<TypeLstWithEllipsisNode>(ctx); | |
| 548 | |||
| 549 | // Visit children | ||
| 550 |
3/6✓ Branch 3 → 4 taken 8467 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 8467 times.
✗ Branch 4 → 20 not taken.
✓ Branch 5 → 6 taken 8467 times.
✗ Branch 5 → 18 not taken.
|
8467 | typeLstWithEllipsisNode->typeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 551 | |||
| 552 | // Set some flags | ||
| 553 |
1/2✓ Branch 8 → 9 taken 8467 times.
✗ Branch 8 → 21 not taken.
|
8467 | typeLstWithEllipsisNode->hasEllipsis = ctx->ELLIPSIS() != nullptr; |
| 554 | |||
| 555 |
1/2✓ Branch 14 → 15 taken 8467 times.
✗ Branch 14 → 21 not taken.
|
16934 | return concludeNode(typeLstWithEllipsisNode); |
| 556 | } | ||
| 557 | |||
| 558 | 4499 | std::any ASTBuilder::visitTypeAltsLst(SpiceParser::TypeAltsLstContext *ctx) { | |
| 559 | 4499 | const auto typeAltsLstNode = createNode<TypeAltsLstNode>(ctx); | |
| 560 | |||
| 561 | // Visit children | ||
| 562 |
3/6✓ Branch 3 → 4 taken 4499 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 4499 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 4499 times.
✗ Branch 6 → 19 not taken.
|
4499 | fetchChildrenIntoVector(typeAltsLstNode->dataTypes, ctx->dataType()); |
| 563 | |||
| 564 |
1/2✓ Branch 12 → 13 taken 4499 times.
✗ Branch 12 → 19 not taken.
|
8998 | return concludeNode(typeAltsLstNode); |
| 565 | } | ||
| 566 | |||
| 567 | 57260 | std::any ASTBuilder::visitParamLst(SpiceParser::ParamLstContext *ctx) { | |
| 568 | 57260 | const auto paramLstNode = createNode<ParamLstNode>(ctx); | |
| 569 | |||
| 570 | // Visit children | ||
| 571 |
2/4✓ Branch 3 → 4 taken 57260 times.
✗ Branch 3 → 32 not taken.
✓ Branch 4 → 5 taken 57260 times.
✗ Branch 4 → 30 not taken.
|
57260 | 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 88144 times.
✓ Branch 19 → 20 taken 57260 times.
|
202664 | for (DeclStmtNode *declStmt : paramLstNode->params) { |
| 575 | 88144 | declStmt->isFctParam = true; | |
| 576 | 88144 | declStmt->dataType->isParamType = true; | |
| 577 | } | ||
| 578 | |||
| 579 |
1/2✓ Branch 26 → 27 taken 57260 times.
✗ Branch 26 → 33 not taken.
|
114520 | return concludeNode(paramLstNode); |
| 580 | } | ||
| 581 | |||
| 582 | 102568 | std::any ASTBuilder::visitArgLst(SpiceParser::ArgLstContext *ctx) { | |
| 583 | 102568 | const auto argLstNode = createNode<ArgLstNode>(ctx); | |
| 584 | |||
| 585 | // Visit children | ||
| 586 |
2/4✓ Branch 3 → 4 taken 102568 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 102568 times.
✗ Branch 4 → 18 not taken.
|
102568 | fetchChildrenIntoVector(argLstNode->args, ctx->assignExpr()); |
| 587 | 102568 | argLstNode->argInfos.reserve(argLstNode->args.size()); | |
| 588 | |||
| 589 |
1/2✓ Branch 14 → 15 taken 102568 times.
✗ Branch 14 → 21 not taken.
|
205136 | return concludeNode(argLstNode); |
| 590 | } | ||
| 591 | |||
| 592 | 1232 | std::any ASTBuilder::visitEnumItemLst(SpiceParser::EnumItemLstContext *ctx) { | |
| 593 | 1232 | const auto enumItemLstNode = createNode<EnumItemLstNode>(ctx); | |
| 594 | |||
| 595 | // Visit children | ||
| 596 |
3/6✓ Branch 3 → 4 taken 1232 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 1232 times.
✗ Branch 4 → 16 not taken.
✓ Branch 6 → 7 taken 1232 times.
✗ Branch 6 → 19 not taken.
|
1232 | fetchChildrenIntoVector(enumItemLstNode->items, ctx->enumItem()); |
| 597 | |||
| 598 |
1/2✓ Branch 12 → 13 taken 1232 times.
✗ Branch 12 → 19 not taken.
|
2464 | return concludeNode(enumItemLstNode); |
| 599 | } | ||
| 600 | |||
| 601 | 11054 | std::any ASTBuilder::visitEnumItem(SpiceParser::EnumItemContext *ctx) { | |
| 602 | 11054 | const auto enumItemNode = createNode<EnumItemNode>(ctx); | |
| 603 | |||
| 604 | // Enrich | ||
| 605 |
2/4✓ Branch 3 → 4 taken 11054 times.
✗ Branch 3 → 22 not taken.
✓ Branch 4 → 5 taken 11054 times.
✗ Branch 4 → 22 not taken.
|
11054 | enumItemNode->itemName = getIdentifier(ctx->TYPE_IDENTIFIER(), false); |
| 606 |
2/2✓ Branch 8 → 9 taken 6274 times.
✓ Branch 8 → 12 taken 4780 times.
|
11054 | if (ctx->ASSIGN()) { |
| 607 | 6274 | enumItemNode->itemValue = parseInt(ctx->INT_LIT()); | |
| 608 | 6274 | enumItemNode->hasValue = true; | |
| 609 | } | ||
| 610 | |||
| 611 |
1/2✓ Branch 18 → 19 taken 11054 times.
✗ Branch 18 → 23 not taken.
|
22108 | return concludeNode(enumItemNode); |
| 612 | } | ||
| 613 | |||
| 614 | 15367 | std::any ASTBuilder::visitField(SpiceParser::FieldContext *ctx) { | |
| 615 | 15367 | const auto fieldNode = createNode<FieldNode>(ctx); | |
| 616 | |||
| 617 | // Enrich | ||
| 618 |
2/4✓ Branch 3 → 4 taken 15367 times.
✗ Branch 3 → 29 not taken.
✓ Branch 4 → 5 taken 15367 times.
✗ Branch 4 → 29 not taken.
|
15367 | fieldNode->fieldName = getIdentifier(ctx->IDENTIFIER(), false); |
| 619 | |||
| 620 | // Visit children | ||
| 621 |
3/6✓ Branch 7 → 8 taken 15367 times.
✗ Branch 7 → 32 not taken.
✓ Branch 8 → 9 taken 15367 times.
✗ Branch 8 → 32 not taken.
✓ Branch 9 → 10 taken 15367 times.
✗ Branch 9 → 30 not taken.
|
15367 | fieldNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 622 | 15367 | fieldNode->dataType->setFieldTypeRecursive(); | |
| 623 |
2/2✓ Branch 13 → 14 taken 3655 times.
✓ Branch 13 → 19 taken 11712 times.
|
15367 | if (ctx->ternaryExpr()) |
| 624 |
3/6✓ Branch 14 → 15 taken 3655 times.
✗ Branch 14 → 35 not taken.
✓ Branch 15 → 16 taken 3655 times.
✗ Branch 15 → 35 not taken.
✓ Branch 16 → 17 taken 3655 times.
✗ Branch 16 → 33 not taken.
|
3655 | fieldNode->defaultValue = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr())); |
| 625 | |||
| 626 |
1/2✓ Branch 25 → 26 taken 15367 times.
✗ Branch 25 → 36 not taken.
|
30734 | return concludeNode(fieldNode); |
| 627 | } | ||
| 628 | |||
| 629 | 4869 | std::any ASTBuilder::visitSignature(SpiceParser::SignatureContext *ctx) { | |
| 630 | 4869 | const auto signatureNode = createNode<SignatureNode>(ctx); | |
| 631 | |||
| 632 | // Extract method name | ||
| 633 |
2/4✓ Branch 3 → 4 taken 4869 times.
✗ Branch 3 → 73 not taken.
✓ Branch 4 → 5 taken 4869 times.
✗ Branch 4 → 73 not taken.
|
4869 | signatureNode->methodName = getIdentifier(ctx->IDENTIFIER(), false); |
| 634 | |||
| 635 | // Visit children | ||
| 636 |
2/2✓ Branch 8 → 9 taken 4775 times.
✓ Branch 8 → 14 taken 94 times.
|
4869 | if (ctx->qualifierLst()) { |
| 637 |
3/6✓ Branch 9 → 10 taken 4775 times.
✗ Branch 9 → 76 not taken.
✓ Branch 10 → 11 taken 4775 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 4775 times.
✗ Branch 11 → 74 not taken.
|
4775 | signatureNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 638 | } | ||
| 639 |
2/2✓ Branch 15 → 16 taken 4583 times.
✓ Branch 15 → 22 taken 286 times.
|
4869 | if (ctx->F()) { |
| 640 | 4583 | signatureNode->hasReturnType = true; | |
| 641 | 4583 | signatureNode->signatureType = SignatureNode::SignatureType::TYPE_FUNCTION; | |
| 642 | 4583 | signatureNode->signatureQualifiers = TypeQualifiers::of(TY_FUNCTION); | |
| 643 |
3/6✓ Branch 17 → 18 taken 4583 times.
✗ Branch 17 → 79 not taken.
✓ Branch 18 → 19 taken 4583 times.
✗ Branch 18 → 79 not taken.
✓ Branch 19 → 20 taken 4583 times.
✗ Branch 19 → 77 not taken.
|
4583 | signatureNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 644 | } else { | ||
| 645 | 286 | signatureNode->signatureType = SignatureNode::SignatureType::TYPE_PROCEDURE; | |
| 646 | 286 | signatureNode->signatureQualifiers = TypeQualifiers::of(TY_PROCEDURE); | |
| 647 | } | ||
| 648 |
10/16✓ Branch 24 → 25 taken 4583 times.
✓ Branch 24 → 28 taken 286 times.
✓ Branch 25 → 26 taken 4583 times.
✗ Branch 25 → 80 not taken.
✓ Branch 28 → 29 taken 286 times.
✗ Branch 28 → 80 not taken.
✓ Branch 31 → 32 taken 286 times.
✓ Branch 31 → 33 taken 4583 times.
✓ Branch 33 → 34 taken 4583 times.
✓ Branch 33 → 35 taken 286 times.
✓ Branch 35 → 36 taken 572 times.
✓ Branch 35 → 41 taken 4297 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 86 not taken.
|
4869 | if (ctx->F() ? ctx->LESS().size() == 2 : ctx->LESS().size() == 1) { |
| 649 | 572 | signatureNode->hasTemplateTypes = true; | |
| 650 |
3/6✓ Branch 36 → 37 taken 572 times.
✗ Branch 36 → 90 not taken.
✓ Branch 37 → 38 taken 572 times.
✗ Branch 37 → 90 not taken.
✓ Branch 38 → 39 taken 572 times.
✗ Branch 38 → 88 not taken.
|
572 | signatureNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(0))); |
| 651 | } | ||
| 652 |
13/20✓ Branch 41 → 42 taken 4869 times.
✗ Branch 41 → 91 not taken.
✓ Branch 43 → 44 taken 4865 times.
✓ Branch 43 → 48 taken 4 times.
✓ Branch 44 → 45 taken 4865 times.
✗ Branch 44 → 91 not taken.
✓ Branch 46 → 47 taken 3450 times.
✓ Branch 46 → 49 taken 1415 times.
✓ Branch 47 → 48 taken 2882 times.
✓ Branch 47 → 49 taken 568 times.
✓ Branch 50 → 51 taken 4865 times.
✓ Branch 50 → 52 taken 4 times.
✓ Branch 52 → 53 taken 4869 times.
✗ Branch 52 → 54 not taken.
✓ Branch 54 → 55 taken 2886 times.
✓ Branch 54 → 63 taken 1983 times.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
|
4869 | if (ctx->typeLst().size() == 2 || (ctx->typeLst().size() == 1 && !signatureNode->hasTemplateTypes)) { |
| 653 | 2886 | signatureNode->hasParams = true; | |
| 654 |
5/8✓ Branch 55 → 56 taken 4 times.
✓ Branch 55 → 57 taken 2882 times.
✓ Branch 58 → 59 taken 2886 times.
✗ Branch 58 → 101 not taken.
✓ Branch 59 → 60 taken 2886 times.
✗ Branch 59 → 101 not taken.
✓ Branch 60 → 61 taken 2886 times.
✗ Branch 60 → 99 not taken.
|
2886 | signatureNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst(signatureNode->hasTemplateTypes ? 1 : 0))); |
| 655 | } | ||
| 656 | |||
| 657 |
1/2✓ Branch 69 → 70 taken 4869 times.
✗ Branch 69 → 102 not taken.
|
9738 | return concludeNode(signatureNode); |
| 658 | } | ||
| 659 | |||
| 660 | 209917 | std::any ASTBuilder::visitStmt(SpiceParser::StmtContext *ctx) { | |
| 661 |
2/2✓ Branch 3 → 4 taken 39596 times.
✓ Branch 3 → 11 taken 170321 times.
|
209917 | if (ctx->declStmt()) |
| 662 |
5/8✓ Branch 4 → 5 taken 39596 times.
✗ Branch 4 → 60 not taken.
✓ Branch 5 → 6 taken 39588 times.
✓ Branch 5 → 60 taken 8 times.
✓ Branch 6 → 7 taken 39588 times.
✗ Branch 6 → 58 not taken.
✓ Branch 7 → 8 taken 39588 times.
✗ Branch 7 → 58 not taken.
|
79184 | return static_cast<StmtNode *>(std::any_cast<DeclStmtNode *>(visit(ctx->declStmt()))); |
| 663 |
2/2✓ Branch 12 → 13 taken 100882 times.
✓ Branch 12 → 20 taken 69439 times.
|
170321 | if (ctx->exprStmt()) |
| 664 |
4/8✓ Branch 13 → 14 taken 100882 times.
✗ Branch 13 → 64 not taken.
✓ Branch 14 → 15 taken 100882 times.
✗ Branch 14 → 64 not taken.
✓ Branch 15 → 16 taken 100882 times.
✗ Branch 15 → 62 not taken.
✓ Branch 16 → 17 taken 100882 times.
✗ Branch 16 → 62 not taken.
|
201764 | return static_cast<StmtNode *>(std::any_cast<ExprStmtNode *>(visit(ctx->exprStmt()))); |
| 665 |
2/2✓ Branch 21 → 22 taken 67451 times.
✓ Branch 21 → 29 taken 1988 times.
|
69439 | if (ctx->returnStmt()) |
| 666 |
4/8✓ Branch 22 → 23 taken 67451 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 67451 times.
✗ Branch 23 → 68 not taken.
✓ Branch 24 → 25 taken 67451 times.
✗ Branch 24 → 66 not taken.
✓ Branch 25 → 26 taken 67451 times.
✗ Branch 25 → 66 not taken.
|
134902 | return static_cast<StmtNode *>(std::any_cast<ReturnStmtNode *>(visit(ctx->returnStmt()))); |
| 667 |
2/2✓ Branch 30 → 31 taken 1020 times.
✓ Branch 30 → 38 taken 968 times.
|
1988 | if (ctx->breakStmt()) |
| 668 |
4/8✓ Branch 31 → 32 taken 1020 times.
✗ Branch 31 → 72 not taken.
✓ Branch 32 → 33 taken 1020 times.
✗ Branch 32 → 72 not taken.
✓ Branch 33 → 34 taken 1020 times.
✗ Branch 33 → 70 not taken.
✓ Branch 34 → 35 taken 1020 times.
✗ Branch 34 → 70 not taken.
|
2040 | return static_cast<StmtNode *>(std::any_cast<BreakStmtNode *>(visit(ctx->breakStmt()))); |
| 669 |
2/2✓ Branch 39 → 40 taken 956 times.
✓ Branch 39 → 47 taken 12 times.
|
968 | if (ctx->continueStmt()) |
| 670 |
4/8✓ Branch 40 → 41 taken 956 times.
✗ Branch 40 → 76 not taken.
✓ Branch 41 → 42 taken 956 times.
✗ Branch 41 → 76 not taken.
✓ Branch 42 → 43 taken 956 times.
✗ Branch 42 → 74 not taken.
✓ Branch 43 → 44 taken 956 times.
✗ Branch 43 → 74 not taken.
|
1912 | 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 | 135087 | std::any ASTBuilder::visitDeclStmt(SpiceParser::DeclStmtContext *ctx) { | |
| 678 | 135087 | const auto declStmtNode = createNode<DeclStmtNode>(ctx); | |
| 679 | |||
| 680 | // Enrich | ||
| 681 |
3/4✓ Branch 3 → 4 taken 135087 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 135085 times.
✓ Branch 4 → 28 taken 2 times.
|
135087 | declStmtNode->varName = getIdentifier(ctx->IDENTIFIER(), false); |
| 682 | |||
| 683 | // Visit children | ||
| 684 |
4/6✓ Branch 7 → 8 taken 135085 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 135083 times.
✓ Branch 8 → 31 taken 2 times.
✓ Branch 9 → 10 taken 135083 times.
✗ Branch 9 → 29 not taken.
|
135085 | declStmtNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 685 |
2/2✓ Branch 12 → 13 taken 48929 times.
✓ Branch 12 → 18 taken 86154 times.
|
135083 | if (ctx->assignExpr()) { |
| 686 | 48929 | declStmtNode->hasAssignment = true; | |
| 687 |
4/6✓ Branch 13 → 14 taken 48929 times.
✗ Branch 13 → 34 not taken.
✓ Branch 14 → 15 taken 48925 times.
✓ Branch 14 → 34 taken 4 times.
✓ Branch 15 → 16 taken 48925 times.
✗ Branch 15 → 32 not taken.
|
48929 | declStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 688 | } | ||
| 689 | |||
| 690 |
1/2✓ Branch 24 → 25 taken 135079 times.
✗ Branch 24 → 35 not taken.
|
270158 | return concludeNode(declStmtNode); |
| 691 | } | ||
| 692 | |||
| 693 | 100882 | std::any ASTBuilder::visitExprStmt(SpiceParser::ExprStmtContext *ctx) { | |
| 694 | 100882 | const auto exprStmtNode = createNode<ExprStmtNode>(ctx); | |
| 695 | |||
| 696 | // Enrich | ||
| 697 |
4/8✓ Branch 3 → 4 taken 100882 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 100882 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 100882 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 100882 times.
✗ Branch 7 → 20 not taken.
|
100882 | exprStmtNode->expr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 698 | |||
| 699 |
1/2✓ Branch 13 → 14 taken 100882 times.
✗ Branch 13 → 20 not taken.
|
201764 | return concludeNode(exprStmtNode); |
| 700 | } | ||
| 701 | |||
| 702 | 204917 | std::any ASTBuilder::visitQualifierLst(SpiceParser::QualifierLstContext *ctx) { | |
| 703 | 204917 | const auto qualifierLstNode = createNode<QualifierLstNode>(ctx); | |
| 704 | |||
| 705 | // Visit children | ||
| 706 |
2/4✓ Branch 3 → 4 taken 204917 times.
✗ Branch 3 → 45 not taken.
✓ Branch 4 → 5 taken 204917 times.
✗ Branch 4 → 43 not taken.
|
204917 | fetchChildrenIntoVector(qualifierLstNode->qualifiers, ctx->qualifier()); |
| 707 | |||
| 708 | // Check if qualifier combination is invalid | ||
| 709 | 204917 | bool seenSignedOrUnsigned = false; | |
| 710 |
2/2✓ Branch 32 → 8 taken 244588 times.
✓ Branch 32 → 33 taken 204915 times.
|
654420 | for (const QualifierNode *qualifier : qualifierLstNode->qualifiers) { |
| 711 | // Check if we have both, signed and unsigned qualifier | ||
| 712 |
2/2✓ Branch 10 → 11 taken 244574 times.
✓ Branch 10 → 13 taken 14 times.
|
244588 | if (qualifier->type != QualifierNode::QualifierType::TY_SIGNED && |
| 713 |
2/2✓ Branch 11 → 12 taken 190866 times.
✓ Branch 11 → 13 taken 53708 times.
|
244574 | qualifier->type != QualifierNode::QualifierType::TY_UNSIGNED) |
| 714 | 190866 | continue; | |
| 715 |
2/2✓ Branch 13 → 14 taken 2 times.
✓ Branch 13 → 22 taken 53720 times.
|
53722 | 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 | 53720 | seenSignedOrUnsigned = true; | |
| 718 | } | ||
| 719 | |||
| 720 |
1/2✓ Branch 39 → 40 taken 204915 times.
✗ Branch 39 → 56 not taken.
|
409830 | return concludeNode(qualifierLstNode); |
| 721 | } | ||
| 722 | |||
| 723 | 244588 | std::any ASTBuilder::visitQualifier(SpiceParser::QualifierContext *ctx) { | |
| 724 | 244588 | const auto qualifierNode = createNode<QualifierNode>(ctx); | |
| 725 | |||
| 726 |
3/4✓ Branch 7 → 8 taken 244588 times.
✗ Branch 7 → 9 not taken.
✓ Branch 42 → 5 taken 244588 times.
✓ Branch 42 → 43 taken 244588 times.
|
978352 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 727 | 244588 | const auto token = spice_pointer_cast<TerminalNode *>(subTree); | |
| 728 |
2/4✓ Branch 16 → 17 taken 244588 times.
✗ Branch 16 → 53 not taken.
✓ Branch 17 → 18 taken 244588 times.
✗ Branch 17 → 53 not taken.
|
244588 | const size_t symbolType = token->getSymbol()->getType(); |
| 729 |
2/2✓ Branch 18 → 19 taken 52561 times.
✓ Branch 18 → 20 taken 192027 times.
|
244588 | if (symbolType == SpiceParser::CONST) |
| 730 | 52561 | qualifierNode->type = QualifierNode::QualifierType::TY_CONST; | |
| 731 |
2/2✓ Branch 20 → 21 taken 14 times.
✓ Branch 20 → 22 taken 192013 times.
|
192027 | else if (symbolType == SpiceParser::SIGNED) |
| 732 | 14 | qualifierNode->type = QualifierNode::QualifierType::TY_SIGNED; | |
| 733 |
2/2✓ Branch 22 → 23 taken 53708 times.
✓ Branch 22 → 24 taken 138305 times.
|
192013 | else if (symbolType == SpiceParser::UNSIGNED) |
| 734 | 53708 | qualifierNode->type = QualifierNode::QualifierType::TY_UNSIGNED; | |
| 735 |
2/2✓ Branch 24 → 25 taken 19272 times.
✓ Branch 24 → 26 taken 119033 times.
|
138305 | else if (symbolType == SpiceParser::INLINE) |
| 736 | 19272 | qualifierNode->type = QualifierNode::QualifierType::TY_INLINE; | |
| 737 |
2/2✓ Branch 26 → 27 taken 90397 times.
✓ Branch 26 → 28 taken 28636 times.
|
119033 | else if (symbolType == SpiceParser::PUBLIC) |
| 738 | 90397 | qualifierNode->type = QualifierNode::QualifierType::TY_PUBLIC; | |
| 739 |
2/2✓ Branch 28 → 29 taken 26120 times.
✓ Branch 28 → 30 taken 2516 times.
|
28636 | else if (symbolType == SpiceParser::HEAP) |
| 740 | 26120 | qualifierNode->type = QualifierNode::QualifierType::TY_HEAP; | |
| 741 |
1/2✓ Branch 30 → 31 taken 2516 times.
✗ Branch 30 → 32 not taken.
|
2516 | else if (symbolType == SpiceParser::COMPOSE) |
| 742 | 2516 | 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 244588 times.
✗ Branch 49 → 54 not taken.
|
489176 | return concludeNode(qualifierNode); |
| 748 | } | ||
| 749 | |||
| 750 | 2154 | std::any ASTBuilder::visitModAttr(SpiceParser::ModAttrContext *ctx) { | |
| 751 | 2154 | const auto modAttrNode = createNode<ModAttrNode>(ctx); | |
| 752 | |||
| 753 | // Visit children | ||
| 754 |
4/6✓ Branch 3 → 4 taken 2154 times.
✗ Branch 3 → 33 not taken.
✓ Branch 4 → 5 taken 2152 times.
✓ Branch 4 → 33 taken 2 times.
✓ Branch 5 → 6 taken 2152 times.
✗ Branch 5 → 31 not taken.
|
2154 | 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 5424 times.
✓ Branch 20 → 21 taken 2152 times.
|
9728 | for (AttrNode *attr : modAttrNode->attrLst->attributes) |
| 758 | 5424 | attr->target = AttrNode::TARGET_MODULE; | |
| 759 | |||
| 760 |
1/2✓ Branch 27 → 28 taken 2152 times.
✗ Branch 27 → 34 not taken.
|
4304 | return concludeNode(modAttrNode); |
| 761 | } | ||
| 762 | |||
| 763 | 2236 | std::any ASTBuilder::visitTopLevelDefAttr(SpiceParser::TopLevelDefAttrContext *ctx) { | |
| 764 | 2236 | const auto fctAttrNode = createNode<TopLevelDefAttrNode>(ctx); | |
| 765 | |||
| 766 | // Visit children | ||
| 767 |
4/8✓ Branch 3 → 4 taken 2236 times.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 2236 times.
✗ Branch 4 → 19 not taken.
✓ Branch 5 → 6 taken 2236 times.
✗ Branch 5 → 17 not taken.
✓ Branch 7 → 8 taken 2236 times.
✗ Branch 7 → 20 not taken.
|
2236 | fctAttrNode->attrLst = std::any_cast<AttrLstNode *>(visit(ctx->attrLst())); |
| 768 | |||
| 769 |
1/2✓ Branch 13 → 14 taken 2236 times.
✗ Branch 13 → 20 not taken.
|
4472 | 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 | 4406 | std::any ASTBuilder::visitAttrLst(SpiceParser::AttrLstContext *ctx) { | |
| 786 | 4406 | const auto attrLstNode = createNode<AttrLstNode>(ctx); | |
| 787 | |||
| 788 | // Visit children | ||
| 789 |
4/6✓ Branch 3 → 4 taken 4406 times.
✗ Branch 3 → 18 not taken.
✓ Branch 4 → 5 taken 4404 times.
✓ Branch 4 → 16 taken 2 times.
✓ Branch 6 → 7 taken 4404 times.
✗ Branch 6 → 19 not taken.
|
4408 | fetchChildrenIntoVector(attrLstNode->attributes, ctx->attr()); |
| 790 | |||
| 791 |
1/2✓ Branch 12 → 13 taken 4404 times.
✗ Branch 12 → 19 not taken.
|
8808 | return concludeNode(attrLstNode); |
| 792 | } | ||
| 793 | |||
| 794 | 7882 | std::any ASTBuilder::visitAttr(SpiceParser::AttrContext *ctx) { | |
| 795 |
1/2✓ Branch 2 → 3 taken 7882 times.
✗ Branch 2 → 83 not taken.
|
7882 | const auto attrNode = createNode<AttrNode>(ctx); |
| 796 | |||
| 797 | // Extract key | ||
| 798 |
1/2✓ Branch 3 → 4 taken 7882 times.
✗ Branch 3 → 83 not taken.
|
7882 | std::stringstream key; |
| 799 |
3/4✓ Branch 12 → 13 taken 28566 times.
✗ Branch 12 → 66 not taken.
✓ Branch 15 → 5 taken 20684 times.
✓ Branch 15 → 16 taken 7882 times.
|
28566 | for (size_t i = 0; i < ctx->IDENTIFIER().size(); i++) { |
| 800 |
2/2✓ Branch 5 → 6 taken 12802 times.
✓ Branch 5 → 7 taken 7882 times.
|
20684 | if (i > 0) |
| 801 |
1/2✓ Branch 6 → 7 taken 12802 times.
✗ Branch 6 → 81 not taken.
|
12802 | key << MEMBER_ACCESS_TOKEN; |
| 802 |
3/6✓ Branch 7 → 8 taken 20684 times.
✗ Branch 7 → 65 not taken.
✓ Branch 8 → 9 taken 20684 times.
✗ Branch 8 → 65 not taken.
✓ Branch 9 → 10 taken 20684 times.
✗ Branch 9 → 63 not taken.
|
20684 | key << ctx->IDENTIFIER(i)->getText(); |
| 803 | } | ||
| 804 |
1/2✓ Branch 16 → 17 taken 7882 times.
✗ Branch 16 → 67 not taken.
|
7882 | attrNode->key = key.str(); |
| 805 | |||
| 806 | // Visit children | ||
| 807 |
3/4✓ Branch 19 → 20 taken 7882 times.
✗ Branch 19 → 81 not taken.
✓ Branch 20 → 21 taken 6226 times.
✓ Branch 20 → 51 taken 1656 times.
|
7882 | if (ctx->constant()) { |
| 808 |
3/6✓ Branch 21 → 22 taken 6226 times.
✗ Branch 21 → 70 not taken.
✓ Branch 22 → 23 taken 6226 times.
✗ Branch 22 → 70 not taken.
✓ Branch 23 → 24 taken 6226 times.
✗ Branch 23 → 68 not taken.
|
6226 | attrNode->value = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 809 | |||
| 810 |
4/6✓ Branch 25 → 26 taken 6226 times.
✗ Branch 25 → 81 not taken.
✓ Branch 26 → 27 taken 6226 times.
✗ Branch 26 → 81 not taken.
✓ Branch 27 → 28 taken 3518 times.
✓ Branch 27 → 29 taken 2708 times.
|
6226 | if (ctx->constant()->STRING_LIT()) |
| 811 | 3518 | attrNode->type = AttrNode::AttrType::TYPE_STRING; | |
| 812 |
4/6✓ Branch 29 → 30 taken 2708 times.
✗ Branch 29 → 81 not taken.
✓ Branch 30 → 31 taken 2708 times.
✗ Branch 30 → 81 not taken.
✓ Branch 31 → 32 taken 372 times.
✓ Branch 31 → 33 taken 2336 times.
|
2708 | else if (ctx->constant()->INT_LIT()) |
| 813 | 372 | attrNode->type = AttrNode::AttrType::TYPE_INT; | |
| 814 |
10/14✓ Branch 33 → 34 taken 2336 times.
✗ Branch 33 → 81 not taken.
✓ Branch 34 → 35 taken 2336 times.
✗ Branch 34 → 81 not taken.
✓ Branch 35 → 36 taken 10 times.
✓ Branch 35 → 39 taken 2326 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 2334 times.
✓ Branch 41 → 43 taken 2 times.
|
2336 | else if (ctx->constant()->TRUE() || ctx->constant()->FALSE()) |
| 815 | 2334 | 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 | 1656 | attrNode->type = AttrNode::AttrType::TYPE_BOOL; | |
| 821 | } | ||
| 822 | |||
| 823 |
1/2✓ Branch 58 → 59 taken 7880 times.
✗ Branch 58 → 80 not taken.
|
15760 | return concludeNode(attrNode); |
| 824 | 7882 | } | |
| 825 | |||
| 826 | 1915 | std::any ASTBuilder::visitCaseConstant(SpiceParser::CaseConstantContext *ctx) { | |
| 827 | 1915 | const auto caseConstantNode = createNode<CaseConstantNode>(ctx); | |
| 828 | |||
| 829 | // Visit children | ||
| 830 |
2/2✓ Branch 4 → 5 taken 137 times.
✓ Branch 4 → 10 taken 1778 times.
|
1915 | 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 1778 times.
✗ Branch 10 → 66 not taken.
✓ Branch 13 → 14 taken 1778 times.
✗ Branch 13 → 52 not taken.
|
1778 | } else if (!ctx->TYPE_IDENTIFIER().empty()) { |
| 833 |
1/2✓ Branch 14 → 15 taken 1778 times.
✗ Branch 14 → 75 not taken.
|
1778 | std::stringstream fqIdentifier; |
| 834 |
2/2✓ Branch 46 → 17 taken 4826 times.
✓ Branch 46 → 47 taken 1778 times.
|
8382 | for (antlr4::tree::ParseTree *parseTree : ctx->children) { |
| 835 |
1/2✓ Branch 19 → 20 taken 4826 times.
✗ Branch 19 → 21 not taken.
|
4826 | const auto terminal = dynamic_cast<TerminalNode *>(parseTree); |
| 836 |
1/2✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 4826 times.
|
4826 | if (!terminal) |
| 837 | ✗ | continue; | |
| 838 | |||
| 839 |
2/4✓ Branch 24 → 25 taken 4826 times.
✗ Branch 24 → 71 not taken.
✓ Branch 25 → 26 taken 4826 times.
✗ Branch 25 → 71 not taken.
|
4826 | const size_t terminalType = terminal->getSymbol()->getType(); |
| 840 |
3/4✓ Branch 26 → 27 taken 4826 times.
✗ Branch 26 → 28 not taken.
✓ Branch 27 → 28 taken 3302 times.
✓ Branch 27 → 37 taken 1524 times.
|
4826 | if (terminalType == SpiceParser::IDENTIFIER || terminalType == SpiceParser::TYPE_IDENTIFIER) { |
| 841 |
1/2✓ Branch 28 → 29 taken 3302 times.
✗ Branch 28 → 70 not taken.
|
3302 | const std::string fragment = getIdentifier(terminal, false); |
| 842 |
1/2✓ Branch 29 → 30 taken 3302 times.
✗ Branch 29 → 68 not taken.
|
3302 | caseConstantNode->identifierFragments.push_back(fragment); |
| 843 |
3/4✓ Branch 30 → 31 taken 3302 times.
✗ Branch 30 → 67 not taken.
✓ Branch 32 → 33 taken 1524 times.
✓ Branch 32 → 34 taken 1778 times.
|
3302 | if (fqIdentifier.tellp() != 0) |
| 844 |
1/2✓ Branch 33 → 34 taken 1524 times.
✗ Branch 33 → 68 not taken.
|
1524 | fqIdentifier << SCOPE_ACCESS_TOKEN; |
| 845 |
1/2✓ Branch 34 → 35 taken 3302 times.
✗ Branch 34 → 68 not taken.
|
3302 | fqIdentifier << fragment; |
| 846 | 3302 | } | |
| 847 | } | ||
| 848 |
1/2✓ Branch 47 → 48 taken 1778 times.
✗ Branch 47 → 72 not taken.
|
1778 | caseConstantNode->fqIdentifier = fqIdentifier.str(); |
| 849 | 1778 | } else { | |
| 850 | − | assert_fail("Unknown case constant type"); // GCOV_EXCL_LINE | |
| 851 | } | ||
| 852 | |||
| 853 |
1/2✓ Branch 59 → 60 taken 1915 times.
✗ Branch 59 → 76 not taken.
|
3830 | return concludeNode(caseConstantNode); |
| 854 | } | ||
| 855 | |||
| 856 | 67451 | std::any ASTBuilder::visitReturnStmt(SpiceParser::ReturnStmtContext *ctx) { | |
| 857 | 67451 | const auto returnStmtNode = createNode<ReturnStmtNode>(ctx); | |
| 858 | |||
| 859 | // Visit children | ||
| 860 |
2/2✓ Branch 4 → 5 taken 61133 times.
✓ Branch 4 → 10 taken 6318 times.
|
67451 | if (ctx->assignExpr()) { |
| 861 | 61133 | returnStmtNode->hasReturnValue = true; | |
| 862 |
3/6✓ Branch 5 → 6 taken 61133 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 61133 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 61133 times.
✗ Branch 7 → 20 not taken.
|
61133 | returnStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 863 | } | ||
| 864 | |||
| 865 |
1/2✓ Branch 16 → 17 taken 67451 times.
✗ Branch 16 → 23 not taken.
|
134902 | return concludeNode(returnStmtNode); |
| 866 | } | ||
| 867 | |||
| 868 | 1020 | std::any ASTBuilder::visitBreakStmt(SpiceParser::BreakStmtContext *ctx) { | |
| 869 | 1020 | 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 1007 times.
|
1020 | 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 1020 times.
✗ Branch 10 → 25 not taken.
✓ Branch 12 → 13 taken 1020 times.
✗ Branch 12 → 26 not taken.
|
1020 | visitChildren(ctx); |
| 877 | |||
| 878 |
1/2✓ Branch 18 → 19 taken 1020 times.
✗ Branch 18 → 26 not taken.
|
2040 | return concludeNode(breakStmtNode); |
| 879 | } | ||
| 880 | |||
| 881 | 956 | std::any ASTBuilder::visitContinueStmt(SpiceParser::ContinueStmtContext *ctx) { | |
| 882 | 956 | const auto continueStmtNode = createNode<ContinueStmtNode>(ctx); | |
| 883 | |||
| 884 | // Extract number of continues | ||
| 885 |
2/2✓ Branch 4 → 5 taken 768 times.
✓ Branch 4 → 10 taken 188 times.
|
956 | if (ctx->INT_LIT()) |
| 886 |
3/6✓ Branch 5 → 6 taken 768 times.
✗ Branch 5 → 24 not taken.
✓ Branch 6 → 7 taken 768 times.
✗ Branch 6 → 24 not taken.
✓ Branch 7 → 8 taken 768 times.
✗ Branch 7 → 22 not taken.
|
768 | continueStmtNode->continueTimes = std::stoi(ctx->INT_LIT()->toString()); |
| 887 | |||
| 888 | // Visit children | ||
| 889 |
2/4✓ Branch 10 → 11 taken 956 times.
✗ Branch 10 → 25 not taken.
✓ Branch 12 → 13 taken 956 times.
✗ Branch 12 → 26 not taken.
|
956 | visitChildren(ctx); |
| 890 | |||
| 891 |
1/2✓ Branch 18 → 19 taken 956 times.
✗ Branch 18 → 26 not taken.
|
1912 | 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 | 8329 | std::any ASTBuilder::visitAssertStmt(SpiceParser::AssertStmtContext *ctx) { | |
| 904 |
1/2✓ Branch 2 → 3 taken 8329 times.
✗ Branch 2 → 30 not taken.
|
8329 | const auto assertStmtNode = createNode<AssertStmtNode>(ctx); |
| 905 | |||
| 906 | // Enrich | ||
| 907 |
5/10✓ Branch 3 → 4 taken 8329 times.
✗ Branch 3 → 30 not taken.
✓ Branch 4 → 5 taken 8329 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 8329 times.
✗ Branch 5 → 30 not taken.
✓ Branch 6 → 7 taken 8329 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 8329 times.
✗ Branch 7 → 30 not taken.
|
8329 | const antlr4::misc::Interval interval(ctx->assignExpr()->start->getStartIndex(), ctx->assignExpr()->stop->getStopIndex()); |
| 908 |
1/2✓ Branch 8 → 9 taken 8329 times.
✗ Branch 8 → 25 not taken.
|
8329 | assertStmtNode->expressionString = inputStream->getText(interval); |
| 909 | |||
| 910 | // Visit children | ||
| 911 |
4/8✓ Branch 11 → 12 taken 8329 times.
✗ Branch 11 → 28 not taken.
✓ Branch 12 → 13 taken 8329 times.
✗ Branch 12 → 28 not taken.
✓ Branch 13 → 14 taken 8329 times.
✗ Branch 13 → 26 not taken.
✓ Branch 15 → 16 taken 8329 times.
✗ Branch 15 → 29 not taken.
|
8329 | assertStmtNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 912 | |||
| 913 |
1/2✓ Branch 21 → 22 taken 8329 times.
✗ Branch 21 → 29 not taken.
|
16658 | return concludeNode(assertStmtNode); |
| 914 | } | ||
| 915 | |||
| 916 | 529815 | std::any ASTBuilder::visitAssignExpr(SpiceParser::AssignExprContext *ctx) { | |
| 917 |
2/2✓ Branch 3 → 4 taken 480764 times.
✓ Branch 3 → 6 taken 49051 times.
|
529815 | if (!ctx->assignOp()) |
| 918 | 480764 | return visit(ctx->ternaryExpr()); | |
| 919 | |||
| 920 | 49051 | const auto assignExprNode = createNode<AssignExprNode>(ctx); | |
| 921 | |||
| 922 | // Visit children | ||
| 923 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 49051 times.
|
49051 | if (ctx->ternaryExpr()) { |
| 924 | ✗ | assignExprNode->ternaryExpr = std::any_cast<ExprNode *>(visit(ctx->ternaryExpr())); | |
| 925 |
1/2✓ Branch 15 → 16 taken 49051 times.
✗ Branch 15 → 28 not taken.
|
49051 | } else if (ctx->prefixUnaryExpr()) { |
| 926 |
3/6✓ Branch 16 → 17 taken 49051 times.
✗ Branch 16 → 44 not taken.
✓ Branch 17 → 18 taken 49051 times.
✗ Branch 17 → 44 not taken.
✓ Branch 18 → 19 taken 49051 times.
✗ Branch 18 → 42 not taken.
|
49051 | assignExprNode->lhs = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr())); |
| 927 |
2/4✓ Branch 20 → 21 taken 49051 times.
✗ Branch 20 → 45 not taken.
✓ Branch 21 → 22 taken 49051 times.
✗ Branch 21 → 45 not taken.
|
49051 | visit(ctx->assignOp()); |
| 928 |
3/6✓ Branch 23 → 24 taken 49051 times.
✗ Branch 23 → 48 not taken.
✓ Branch 24 → 25 taken 49051 times.
✗ Branch 24 → 48 not taken.
✓ Branch 25 → 26 taken 49051 times.
✗ Branch 25 → 46 not taken.
|
49051 | 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 49051 times.
✗ Branch 35 → 49 not taken.
|
98102 | return concludeExprNode(assignExprNode); |
| 934 | } | ||
| 935 | |||
| 936 | 484419 | std::any ASTBuilder::visitTernaryExpr(SpiceParser::TernaryExprContext *ctx) { | |
| 937 |
3/4✓ Branch 2 → 3 taken 484419 times.
✗ Branch 2 → 45 not taken.
✓ Branch 5 → 6 taken 480388 times.
✓ Branch 5 → 8 taken 4031 times.
|
484419 | if (ctx->logicalOrExpr().size() == 1) |
| 938 | 480388 | return visit(ctx->logicalOrExpr(0)); | |
| 939 | |||
| 940 | 4031 | const auto ternaryExprNode = createNode<TernaryExprNode>(ctx); | |
| 941 | |||
| 942 |
3/6✓ Branch 9 → 10 taken 4031 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 4031 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 4031 times.
✗ Branch 11 → 46 not taken.
|
4031 | ternaryExprNode->condition = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(0))); |
| 943 |
3/4✓ Branch 13 → 14 taken 4031 times.
✗ Branch 13 → 49 not taken.
✓ Branch 16 → 17 taken 4029 times.
✓ Branch 16 → 26 taken 2 times.
|
4031 | if (ctx->logicalOrExpr().size() == 3) { |
| 944 |
3/6✓ Branch 17 → 18 taken 4029 times.
✗ Branch 17 → 52 not taken.
✓ Branch 18 → 19 taken 4029 times.
✗ Branch 18 → 52 not taken.
✓ Branch 19 → 20 taken 4029 times.
✗ Branch 19 → 50 not taken.
|
4029 | ternaryExprNode->trueExpr = std::any_cast<ExprNode *>(visit(ctx->logicalOrExpr(1))); |
| 945 |
3/6✓ Branch 21 → 22 taken 4029 times.
✗ Branch 21 → 55 not taken.
✓ Branch 22 → 23 taken 4029 times.
✗ Branch 22 → 55 not taken.
✓ Branch 23 → 24 taken 4029 times.
✗ Branch 23 → 53 not taken.
|
4029 | 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 4031 times.
✗ Branch 41 → 60 not taken.
|
8062 | return concludeExprNode(ternaryExprNode); |
| 952 | } | ||
| 953 | |||
| 954 | 492479 | std::any ASTBuilder::visitLogicalOrExpr(SpiceParser::LogicalOrExprContext *ctx) { | |
| 955 |
3/4✓ Branch 2 → 3 taken 492479 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 486700 times.
✓ Branch 5 → 8 taken 5779 times.
|
492479 | if (ctx->logicalAndExpr().size() == 1) |
| 956 | 486700 | return visit(ctx->logicalAndExpr(0)); | |
| 957 | |||
| 958 | 5779 | const auto logicalOrExprNode = createNode<LogicalOrExprNode>(ctx); | |
| 959 | |||
| 960 | // Visit children | ||
| 961 |
3/6✓ Branch 9 → 10 taken 5779 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 5779 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 5779 times.
✗ Branch 12 → 26 not taken.
|
5779 | fetchChildrenIntoVector(logicalOrExprNode->operands, ctx->logicalAndExpr()); |
| 962 | |||
| 963 |
1/2✓ Branch 18 → 19 taken 5779 times.
✗ Branch 18 → 26 not taken.
|
11558 | return concludeExprNode(logicalOrExprNode); |
| 964 | } | ||
| 965 | |||
| 966 | 499998 | std::any ASTBuilder::visitLogicalAndExpr(SpiceParser::LogicalAndExprContext *ctx) { | |
| 967 |
3/4✓ Branch 2 → 3 taken 499998 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 496513 times.
✓ Branch 5 → 8 taken 3485 times.
|
499998 | if (ctx->bitwiseOrExpr().size() == 1) |
| 968 | 496513 | return visit(ctx->bitwiseOrExpr(0)); | |
| 969 | |||
| 970 | 3485 | const auto logicalAndExprNode = createNode<LogicalAndExprNode>(ctx); | |
| 971 | |||
| 972 | // Visit children | ||
| 973 |
3/6✓ Branch 9 → 10 taken 3485 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 3485 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 3485 times.
✗ Branch 12 → 26 not taken.
|
3485 | fetchChildrenIntoVector(logicalAndExprNode->operands, ctx->bitwiseOrExpr()); |
| 974 | |||
| 975 |
1/2✓ Branch 18 → 19 taken 3485 times.
✗ Branch 18 → 26 not taken.
|
6970 | return concludeExprNode(logicalAndExprNode); |
| 976 | } | ||
| 977 | |||
| 978 | 504367 | std::any ASTBuilder::visitBitwiseOrExpr(SpiceParser::BitwiseOrExprContext *ctx) { | |
| 979 |
3/4✓ Branch 2 → 3 taken 504367 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 503607 times.
✓ Branch 5 → 8 taken 760 times.
|
504367 | if (ctx->bitwiseXorExpr().size() == 1) |
| 980 | 503607 | return visit(ctx->bitwiseXorExpr(0)); | |
| 981 | |||
| 982 | 760 | const auto bitwiseOrExprNode = createNode<BitwiseOrExprNode>(ctx); | |
| 983 | |||
| 984 | // Visit children | ||
| 985 |
3/6✓ Branch 9 → 10 taken 760 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 760 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 760 times.
✗ Branch 12 → 26 not taken.
|
760 | fetchChildrenIntoVector(bitwiseOrExprNode->operands, ctx->bitwiseXorExpr()); |
| 986 | |||
| 987 |
1/2✓ Branch 18 → 19 taken 760 times.
✗ Branch 18 → 26 not taken.
|
1520 | return concludeExprNode(bitwiseOrExprNode); |
| 988 | } | ||
| 989 | |||
| 990 | 505129 | std::any ASTBuilder::visitBitwiseXorExpr(SpiceParser::BitwiseXorExprContext *ctx) { | |
| 991 |
3/4✓ Branch 2 → 3 taken 505129 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 504990 times.
✓ Branch 5 → 8 taken 139 times.
|
505129 | if (ctx->bitwiseAndExpr().size() == 1) |
| 992 | 504990 | return visit(ctx->bitwiseAndExpr(0)); | |
| 993 | |||
| 994 | 139 | const auto bitwiseXorExprNode = createNode<BitwiseXorExprNode>(ctx); | |
| 995 | |||
| 996 | // Visit children | ||
| 997 |
3/6✓ Branch 9 → 10 taken 139 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 139 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 139 times.
✗ Branch 12 → 26 not taken.
|
139 | fetchChildrenIntoVector(bitwiseXorExprNode->operands, ctx->bitwiseAndExpr()); |
| 998 | |||
| 999 |
1/2✓ Branch 18 → 19 taken 139 times.
✗ Branch 18 → 26 not taken.
|
278 | return concludeExprNode(bitwiseXorExprNode); |
| 1000 | } | ||
| 1001 | |||
| 1002 | 505270 | std::any ASTBuilder::visitBitwiseAndExpr(SpiceParser::BitwiseAndExprContext *ctx) { | |
| 1003 |
3/4✓ Branch 2 → 3 taken 505270 times.
✗ Branch 2 → 22 not taken.
✓ Branch 5 → 6 taken 504774 times.
✓ Branch 5 → 8 taken 496 times.
|
505270 | if (ctx->equalityExpr().size() == 1) |
| 1004 | 504774 | return visit(ctx->equalityExpr(0)); | |
| 1005 | |||
| 1006 | 496 | const auto bitwiseAndExprNode = createNode<BitwiseAndExprNode>(ctx); | |
| 1007 | |||
| 1008 | // Visit children | ||
| 1009 |
3/6✓ Branch 9 → 10 taken 496 times.
✗ Branch 9 → 25 not taken.
✓ Branch 10 → 11 taken 496 times.
✗ Branch 10 → 23 not taken.
✓ Branch 12 → 13 taken 496 times.
✗ Branch 12 → 26 not taken.
|
496 | fetchChildrenIntoVector(bitwiseAndExprNode->operands, ctx->equalityExpr()); |
| 1010 | |||
| 1011 |
1/2✓ Branch 18 → 19 taken 496 times.
✗ Branch 18 → 26 not taken.
|
992 | return concludeExprNode(bitwiseAndExprNode); |
| 1012 | } | ||
| 1013 | |||
| 1014 | 505768 | std::any ASTBuilder::visitEqualityExpr(SpiceParser::EqualityExprContext *ctx) { | |
| 1015 |
3/4✓ Branch 2 → 3 taken 505768 times.
✗ Branch 2 → 28 not taken.
✓ Branch 5 → 6 taken 463620 times.
✓ Branch 5 → 8 taken 42148 times.
|
505768 | if (ctx->relationalExpr().size() == 1) |
| 1016 | 463620 | return visit(ctx->relationalExpr(0)); | |
| 1017 | |||
| 1018 | 42148 | const auto equalityExprNode = createNode<EqualityExprNode>(ctx); | |
| 1019 | |||
| 1020 | // Visit children | ||
| 1021 |
2/4✓ Branch 9 → 10 taken 42148 times.
✗ Branch 9 → 31 not taken.
✓ Branch 10 → 11 taken 42148 times.
✗ Branch 10 → 29 not taken.
|
42148 | fetchChildrenIntoVector(equalityExprNode->operands, ctx->relationalExpr()); |
| 1022 | |||
| 1023 | // Extract operator | ||
| 1024 |
2/2✓ Branch 13 → 14 taken 35574 times.
✓ Branch 13 → 15 taken 6574 times.
|
42148 | if (ctx->EQUAL()) |
| 1025 | 35574 | equalityExprNode->op = EqualityExprNode::EqualityOp::OP_EQUAL; | |
| 1026 |
1/2✓ Branch 16 → 17 taken 6574 times.
✗ Branch 16 → 18 not taken.
|
6574 | else if (ctx->NOT_EQUAL()) |
| 1027 | 6574 | equalityExprNode->op = EqualityExprNode::EqualityOp::OP_NOT_EQUAL; | |
| 1028 | |||
| 1029 |
1/2✓ Branch 24 → 25 taken 42148 times.
✗ Branch 24 → 32 not taken.
|
84296 | return concludeExprNode(equalityExprNode); |
| 1030 | } | ||
| 1031 | |||
| 1032 | 547916 | std::any ASTBuilder::visitRelationalExpr(SpiceParser::RelationalExprContext *ctx) { | |
| 1033 |
3/4✓ Branch 2 → 3 taken 547916 times.
✗ Branch 2 → 34 not taken.
✓ Branch 5 → 6 taken 524786 times.
✓ Branch 5 → 8 taken 23130 times.
|
547916 | if (ctx->shiftExpr().size() == 1) |
| 1034 | 524786 | return visit(ctx->shiftExpr(0)); | |
| 1035 | |||
| 1036 | 23130 | const auto relationalExprNode = createNode<RelationalExprNode>(ctx); | |
| 1037 | |||
| 1038 | // Visit children | ||
| 1039 |
2/4✓ Branch 9 → 10 taken 23130 times.
✗ Branch 9 → 37 not taken.
✓ Branch 10 → 11 taken 23130 times.
✗ Branch 10 → 35 not taken.
|
23130 | fetchChildrenIntoVector(relationalExprNode->operands, ctx->shiftExpr()); |
| 1040 | |||
| 1041 | // Extract operator | ||
| 1042 |
2/2✓ Branch 13 → 14 taken 10149 times.
✓ Branch 13 → 15 taken 12981 times.
|
23130 | if (ctx->LESS()) |
| 1043 | 10149 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS; | |
| 1044 |
2/2✓ Branch 16 → 17 taken 5878 times.
✓ Branch 16 → 18 taken 7103 times.
|
12981 | else if (ctx->GREATER()) |
| 1045 | 5878 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER; | |
| 1046 |
2/2✓ Branch 19 → 20 taken 2354 times.
✓ Branch 19 → 21 taken 4749 times.
|
7103 | else if (ctx->LESS_EQUAL()) |
| 1047 | 2354 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_LESS_EQUAL; | |
| 1048 |
1/2✓ Branch 22 → 23 taken 4749 times.
✗ Branch 22 → 24 not taken.
|
4749 | else if (ctx->GREATER_EQUAL()) |
| 1049 | 4749 | relationalExprNode->op = RelationalExprNode::RelationalOp::OP_GREATER_EQUAL; | |
| 1050 | |||
| 1051 |
1/2✓ Branch 30 → 31 taken 23130 times.
✗ Branch 30 → 38 not taken.
|
46260 | return concludeExprNode(relationalExprNode); |
| 1052 | } | ||
| 1053 | |||
| 1054 | 571046 | std::any ASTBuilder::visitShiftExpr(SpiceParser::ShiftExprContext *ctx) { | |
| 1055 |
3/4✓ Branch 2 → 3 taken 571046 times.
✗ Branch 2 → 60 not taken.
✓ Branch 5 → 6 taken 568864 times.
✓ Branch 5 → 8 taken 2182 times.
|
571046 | if (ctx->additiveExpr().size() == 1) |
| 1056 | 568864 | return visit(ctx->additiveExpr(0)); | |
| 1057 | |||
| 1058 | 2182 | const auto shiftExprNode = createNode<ShiftExprNode>(ctx); | |
| 1059 | |||
| 1060 | // Visit children | ||
| 1061 |
2/4✓ Branch 9 → 10 taken 2182 times.
✗ Branch 9 → 63 not taken.
✓ Branch 10 → 11 taken 2182 times.
✗ Branch 10 → 61 not taken.
|
2182 | fetchChildrenIntoVector(shiftExprNode->operands, ctx->additiveExpr()); |
| 1062 | |||
| 1063 | 2182 | bool seenFirstLess = false; | |
| 1064 | 2182 | bool seenFirstGreater = false; | |
| 1065 |
2/2✓ Branch 45 → 14 taken 10288 times.
✓ Branch 45 → 46 taken 2182 times.
|
14652 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1066 |
1/2✓ Branch 16 → 17 taken 10288 times.
✗ Branch 16 → 18 not taken.
|
10288 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1067 |
2/2✓ Branch 19 → 20 taken 4884 times.
✓ Branch 19 → 21 taken 5404 times.
|
10288 | if (!terminal) |
| 1068 | 4884 | continue; | |
| 1069 | |||
| 1070 |
4/6✓ Branch 21 → 22 taken 5404 times.
✗ Branch 21 → 68 not taken.
✓ Branch 22 → 23 taken 5404 times.
✗ Branch 22 → 68 not taken.
✓ Branch 23 → 24 taken 4094 times.
✓ Branch 23 → 28 taken 1310 times.
|
5404 | if (terminal->getSymbol()->getType() == SpiceParser::LESS) { |
| 1071 |
2/2✓ Branch 24 → 25 taken 2047 times.
✓ Branch 24 → 27 taken 2047 times.
|
4094 | if (seenFirstLess) |
| 1072 |
1/2✓ Branch 25 → 26 taken 2047 times.
✗ Branch 25 → 64 not taken.
|
2047 | shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_LEFT, TY_INVALID); |
| 1073 | 4094 | seenFirstLess = !seenFirstLess; | |
| 1074 | 4094 | continue; | |
| 1075 | } | ||
| 1076 | |||
| 1077 |
3/6✓ Branch 28 → 29 taken 1310 times.
✗ Branch 28 → 68 not taken.
✓ Branch 29 → 30 taken 1310 times.
✗ Branch 29 → 68 not taken.
✓ Branch 30 → 31 taken 1310 times.
✗ Branch 30 → 35 not taken.
|
1310 | if (terminal->getSymbol()->getType() == SpiceParser::GREATER) { |
| 1078 |
2/2✓ Branch 31 → 32 taken 655 times.
✓ Branch 31 → 34 taken 655 times.
|
1310 | if (seenFirstGreater) |
| 1079 |
1/2✓ Branch 32 → 33 taken 655 times.
✗ Branch 32 → 66 not taken.
|
655 | shiftExprNode->opQueue.emplace(ShiftExprNode::ShiftOp::OP_SHIFT_RIGHT, TY_INVALID); |
| 1080 | 1310 | seenFirstGreater = !seenFirstGreater; | |
| 1081 | 1310 | continue; | |
| 1082 | } | ||
| 1083 | |||
| 1084 | − | assert_fail("Invalid terminal symbol for additive expression"); // GCOV_EXCL_LINE | |
| 1085 | } | ||
| 1086 |
2/4✓ Branch 46 → 47 taken 2182 times.
✗ Branch 46 → 49 not taken.
✓ Branch 47 → 48 taken 2182 times.
✗ Branch 47 → 49 not taken.
|
2182 | assert(!seenFirstLess && !seenFirstGreater); |
| 1087 | |||
| 1088 |
1/2✓ Branch 56 → 57 taken 2182 times.
✗ Branch 56 → 69 not taken.
|
4364 | return concludeExprNode(shiftExprNode); |
| 1089 | } | ||
| 1090 | |||
| 1091 | 573748 | std::any ASTBuilder::visitAdditiveExpr(SpiceParser::AdditiveExprContext *ctx) { | |
| 1092 |
3/4✓ Branch 2 → 3 taken 573748 times.
✗ Branch 2 → 52 not taken.
✓ Branch 5 → 6 taken 552323 times.
✓ Branch 5 → 8 taken 21425 times.
|
573748 | if (ctx->multiplicativeExpr().size() == 1) |
| 1093 | 552323 | return visit(ctx->multiplicativeExpr(0)); | |
| 1094 | |||
| 1095 | 21425 | const auto additiveExprNode = createNode<AdditiveExprNode>(ctx); | |
| 1096 | |||
| 1097 | // Visit children | ||
| 1098 |
2/4✓ Branch 9 → 10 taken 21425 times.
✗ Branch 9 → 55 not taken.
✓ Branch 10 → 11 taken 21425 times.
✗ Branch 10 → 53 not taken.
|
21425 | fetchChildrenIntoVector(additiveExprNode->operands, ctx->multiplicativeExpr()); |
| 1099 | |||
| 1100 |
2/2✓ Branch 41 → 14 taken 69415 times.
✓ Branch 41 → 42 taken 21425 times.
|
112265 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1101 |
1/2✓ Branch 16 → 17 taken 69415 times.
✗ Branch 16 → 18 not taken.
|
69415 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1102 |
2/2✓ Branch 19 → 20 taken 45420 times.
✓ Branch 19 → 21 taken 23995 times.
|
69415 | if (!terminal) |
| 1103 | 45420 | continue; | |
| 1104 | |||
| 1105 |
4/6✓ Branch 21 → 22 taken 23995 times.
✗ Branch 21 → 60 not taken.
✓ Branch 22 → 23 taken 23995 times.
✗ Branch 22 → 60 not taken.
✓ Branch 23 → 24 taken 16163 times.
✓ Branch 23 → 26 taken 7832 times.
|
23995 | if (terminal->getSymbol()->getType() == SpiceParser::PLUS) |
| 1106 |
1/2✓ Branch 24 → 25 taken 16163 times.
✗ Branch 24 → 56 not taken.
|
16163 | additiveExprNode->opQueue.emplace(AdditiveExprNode::AdditiveOp::OP_PLUS, TY_INVALID); |
| 1107 |
3/6✓ Branch 26 → 27 taken 7832 times.
✗ Branch 26 → 60 not taken.
✓ Branch 27 → 28 taken 7832 times.
✗ Branch 27 → 60 not taken.
✓ Branch 28 → 29 taken 7832 times.
✗ Branch 28 → 31 not taken.
|
7832 | else if (terminal->getSymbol()->getType() == SpiceParser::MINUS) |
| 1108 |
1/2✓ Branch 29 → 30 taken 7832 times.
✗ Branch 29 → 58 not taken.
|
7832 | 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 21425 times.
✗ Branch 48 → 61 not taken.
|
42850 | return concludeExprNode(additiveExprNode); |
| 1114 | } | ||
| 1115 | |||
| 1116 | 597743 | std::any ASTBuilder::visitMultiplicativeExpr(SpiceParser::MultiplicativeExprContext *ctx) { | |
| 1117 |
3/4✓ Branch 2 → 3 taken 597743 times.
✗ Branch 2 → 57 not taken.
✓ Branch 5 → 6 taken 592420 times.
✓ Branch 5 → 8 taken 5323 times.
|
597743 | if (ctx->castExpr().size() == 1) |
| 1118 | 592420 | return visit(ctx->castExpr(0)); | |
| 1119 | |||
| 1120 | 5323 | const auto multiplicativeExprNode = createNode<MultiplicativeExprNode>(ctx); | |
| 1121 | |||
| 1122 | // Visit children | ||
| 1123 |
2/4✓ Branch 9 → 10 taken 5323 times.
✗ Branch 9 → 60 not taken.
✓ Branch 10 → 11 taken 5323 times.
✗ Branch 10 → 58 not taken.
|
5323 | fetchChildrenIntoVector(multiplicativeExprNode->operands, ctx->castExpr()); |
| 1124 | |||
| 1125 |
2/2✓ Branch 46 → 14 taken 16387 times.
✓ Branch 46 → 47 taken 5323 times.
|
27033 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1126 |
1/2✓ Branch 16 → 17 taken 16387 times.
✗ Branch 16 → 18 not taken.
|
16387 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1127 |
2/2✓ Branch 19 → 20 taken 10855 times.
✓ Branch 19 → 21 taken 5532 times.
|
16387 | if (!terminal) |
| 1128 | 10855 | continue; | |
| 1129 | |||
| 1130 |
4/6✓ Branch 21 → 22 taken 5532 times.
✗ Branch 21 → 67 not taken.
✓ Branch 22 → 23 taken 5532 times.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 4313 times.
✓ Branch 23 → 26 taken 1219 times.
|
5532 | if (terminal->getSymbol()->getType() == SpiceParser::MUL) |
| 1131 |
1/2✓ Branch 24 → 25 taken 4313 times.
✗ Branch 24 → 61 not taken.
|
4313 | multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_MUL, TY_INVALID); |
| 1132 |
4/6✓ Branch 26 → 27 taken 1219 times.
✗ Branch 26 → 67 not taken.
✓ Branch 27 → 28 taken 1219 times.
✗ Branch 27 → 67 not taken.
✓ Branch 28 → 29 taken 899 times.
✓ Branch 28 → 31 taken 320 times.
|
1219 | else if (terminal->getSymbol()->getType() == SpiceParser::DIV) |
| 1133 |
1/2✓ Branch 29 → 30 taken 899 times.
✗ Branch 29 → 63 not taken.
|
899 | multiplicativeExprNode->opQueue.emplace(MultiplicativeExprNode::MultiplicativeOp::OP_DIV, TY_INVALID); |
| 1134 |
3/6✓ Branch 31 → 32 taken 320 times.
✗ Branch 31 → 67 not taken.
✓ Branch 32 → 33 taken 320 times.
✗ Branch 32 → 67 not taken.
✓ Branch 33 → 34 taken 320 times.
✗ Branch 33 → 36 not taken.
|
320 | else if (terminal->getSymbol()->getType() == SpiceParser::REM) |
| 1135 |
1/2✓ Branch 34 → 35 taken 320 times.
✗ Branch 34 → 65 not taken.
|
320 | 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 5323 times.
✗ Branch 53 → 68 not taken.
|
10646 | return concludeExprNode(multiplicativeExprNode); |
| 1141 | } | ||
| 1142 | |||
| 1143 | 603275 | std::any ASTBuilder::visitCastExpr(SpiceParser::CastExprContext *ctx) { | |
| 1144 |
2/2✓ Branch 3 → 4 taken 584019 times.
✓ Branch 3 → 6 taken 19256 times.
|
603275 | if (!ctx->CAST()) |
| 1145 | 584019 | return visit(ctx->prefixUnaryExpr()); | |
| 1146 | |||
| 1147 | 19256 | const auto castExprNode = createNode<CastExprNode>(ctx); | |
| 1148 | |||
| 1149 | // Visit children | ||
| 1150 |
1/2✓ Branch 8 → 9 taken 19256 times.
✗ Branch 8 → 18 not taken.
|
19256 | if (ctx->dataType()) { |
| 1151 |
3/6✓ Branch 9 → 10 taken 19256 times.
✗ Branch 9 → 35 not taken.
✓ Branch 10 → 11 taken 19256 times.
✗ Branch 10 → 35 not taken.
✓ Branch 11 → 12 taken 19256 times.
✗ Branch 11 → 33 not taken.
|
19256 | castExprNode->dataType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1152 |
3/6✓ Branch 13 → 14 taken 19256 times.
✗ Branch 13 → 38 not taken.
✓ Branch 14 → 15 taken 19256 times.
✗ Branch 14 → 38 not taken.
✓ Branch 15 → 16 taken 19256 times.
✗ Branch 15 → 36 not taken.
|
19256 | castExprNode->assignExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1153 | 19256 | castExprNode->isCast = true; | |
| 1154 | } else { | ||
| 1155 | ✗ | castExprNode->prefixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->prefixUnaryExpr())); | |
| 1156 | } | ||
| 1157 | |||
| 1158 |
1/2✓ Branch 29 → 30 taken 19256 times.
✗ Branch 29 → 42 not taken.
|
38512 | return concludeExprNode(castExprNode); |
| 1159 | } | ||
| 1160 | |||
| 1161 | 644560 | std::any ASTBuilder::visitPrefixUnaryExpr(SpiceParser::PrefixUnaryExprContext *ctx) { | |
| 1162 |
2/2✓ Branch 3 → 4 taken 633070 times.
✓ Branch 3 → 6 taken 11490 times.
|
644560 | if (!ctx->prefixUnaryExpr()) |
| 1163 | 633070 | return visit(ctx->postfixUnaryExpr()); | |
| 1164 | |||
| 1165 | 11490 | const auto prefixUnaryExprNode = createNode<PrefixUnaryExprNode>(ctx); | |
| 1166 | |||
| 1167 | // Visit children | ||
| 1168 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 11490 times.
|
11490 | if (ctx->postfixUnaryExpr()) { |
| 1169 | ✗ | prefixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr())); | |
| 1170 |
1/2✓ Branch 15 → 16 taken 11490 times.
✗ Branch 15 → 42 not taken.
|
11490 | } else if (ctx->prefixUnaryExpr()) { |
| 1171 | // Extract operator | ||
| 1172 |
2/2✓ Branch 17 → 18 taken 447 times.
✓ Branch 17 → 19 taken 11043 times.
|
11490 | if (ctx->MINUS()) |
| 1173 | 447 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS; | |
| 1174 |
2/2✓ Branch 20 → 21 taken 24 times.
✓ Branch 20 → 22 taken 11019 times.
|
11043 | else if (ctx->PLUS_PLUS()) |
| 1175 | 24 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_PLUS_PLUS; | |
| 1176 |
2/2✓ Branch 23 → 24 taken 30 times.
✓ Branch 23 → 25 taken 10989 times.
|
11019 | else if (ctx->MINUS_MINUS()) |
| 1177 | 30 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_MINUS_MINUS; | |
| 1178 |
2/2✓ Branch 26 → 27 taken 7317 times.
✓ Branch 26 → 28 taken 3672 times.
|
10989 | else if (ctx->NOT()) |
| 1179 | 7317 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_NOT; | |
| 1180 |
2/2✓ Branch 29 → 30 taken 54 times.
✓ Branch 29 → 31 taken 3618 times.
|
3672 | else if (ctx->BITWISE_NOT()) |
| 1181 | 54 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_BITWISE_NOT; | |
| 1182 |
2/2✓ Branch 32 → 33 taken 1602 times.
✓ Branch 32 → 34 taken 2016 times.
|
3618 | else if (ctx->MUL()) |
| 1183 | 1602 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_DEREFERENCE; | |
| 1184 |
1/2✓ Branch 35 → 36 taken 2016 times.
✗ Branch 35 → 37 not taken.
|
2016 | else if (ctx->BITWISE_AND()) |
| 1185 | 2016 | prefixUnaryExprNode->op = PrefixUnaryExprNode::PrefixUnaryOp::OP_ADDRESS_OF; | |
| 1186 | |||
| 1187 |
3/6✓ Branch 37 → 38 taken 11490 times.
✗ Branch 37 → 58 not taken.
✓ Branch 38 → 39 taken 11490 times.
✗ Branch 38 → 58 not taken.
✓ Branch 39 → 40 taken 11490 times.
✗ Branch 39 → 56 not taken.
|
11490 | 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 11490 times.
✗ Branch 49 → 59 not taken.
|
22980 | return concludeExprNode(prefixUnaryExprNode); |
| 1193 | } | ||
| 1194 | |||
| 1195 | 793240 | std::any ASTBuilder::visitPostfixUnaryExpr(SpiceParser::PostfixUnaryExprContext *ctx) { | |
| 1196 |
2/2✓ Branch 3 → 4 taken 633070 times.
✓ Branch 3 → 6 taken 160170 times.
|
793240 | if (!ctx->postfixUnaryExpr()) |
| 1197 | 633070 | return visit(ctx->atomicExpr()); | |
| 1198 | |||
| 1199 | 160170 | const auto postfixUnaryExprNode = createNode<PostfixUnaryExprNode>(ctx); | |
| 1200 | |||
| 1201 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 14 taken 160170 times.
|
160170 | if (ctx->atomicExpr()) { |
| 1202 | ✗ | postfixUnaryExprNode->atomicExpr = std::any_cast<ExprNode *>(visit(ctx->atomicExpr())); | |
| 1203 |
1/2✓ Branch 15 → 16 taken 160170 times.
✗ Branch 15 → 43 not taken.
|
160170 | } else if (ctx->postfixUnaryExpr()) { |
| 1204 |
3/6✓ Branch 16 → 17 taken 160170 times.
✗ Branch 16 → 59 not taken.
✓ Branch 17 → 18 taken 160170 times.
✗ Branch 17 → 59 not taken.
✓ Branch 18 → 19 taken 160170 times.
✗ Branch 18 → 57 not taken.
|
160170 | postfixUnaryExprNode->postfixUnaryExpr = std::any_cast<ExprNode *>(visit(ctx->postfixUnaryExpr())); |
| 1205 | |||
| 1206 | // Extract operator | ||
| 1207 |
2/2✓ Branch 21 → 22 taken 16710 times.
✓ Branch 21 → 27 taken 143460 times.
|
160170 | if (ctx->assignExpr()) { |
| 1208 | 16710 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_SUBSCRIPT; | |
| 1209 |
3/6✓ Branch 22 → 23 taken 16710 times.
✗ Branch 22 → 62 not taken.
✓ Branch 23 → 24 taken 16710 times.
✗ Branch 23 → 62 not taken.
✓ Branch 24 → 25 taken 16710 times.
✗ Branch 24 → 60 not taken.
|
16710 | postfixUnaryExprNode->subscriptIndexExpr = std::any_cast<ExprNode *>(visit(ctx->assignExpr())); |
| 1210 |
2/2✓ Branch 28 → 29 taken 131771 times.
✓ Branch 28 → 34 taken 11689 times.
|
143460 | } else if (ctx->IDENTIFIER()) { |
| 1211 | 131771 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MEMBER_ACCESS; | |
| 1212 |
2/4✓ Branch 29 → 30 taken 131771 times.
✗ Branch 29 → 63 not taken.
✓ Branch 30 → 31 taken 131771 times.
✗ Branch 30 → 63 not taken.
|
131771 | postfixUnaryExprNode->identifier = getIdentifier(ctx->IDENTIFIER(), false); |
| 1213 |
2/2✓ Branch 35 → 36 taken 10064 times.
✓ Branch 35 → 37 taken 1625 times.
|
11689 | } else if (ctx->PLUS_PLUS()) { |
| 1214 | 10064 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_PLUS_PLUS; | |
| 1215 |
2/2✓ Branch 38 → 39 taken 1503 times.
✓ Branch 38 → 40 taken 122 times.
|
1625 | } else if (ctx->MINUS_MINUS()) { |
| 1216 | 1503 | postfixUnaryExprNode->op = PostfixUnaryExprNode::PostfixUnaryOp::OP_MINUS_MINUS; | |
| 1217 |
1/2✓ Branch 41 → 42 taken 122 times.
✗ Branch 41 → 44 not taken.
|
122 | } else if (ctx->NOT()) { |
| 1218 | 122 | 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 160170 times.
✗ Branch 50 → 64 not taken.
|
320340 | return concludeExprNode(postfixUnaryExprNode); |
| 1225 | } | ||
| 1226 | |||
| 1227 | 633070 | std::any ASTBuilder::visitAtomicExpr(SpiceParser::AtomicExprContext *ctx) { | |
| 1228 | 633070 | const auto atomicExprNode = createNode<AtomicExprNode>(ctx); | |
| 1229 | |||
| 1230 | // Visit children | ||
| 1231 |
2/2✓ Branch 4 → 5 taken 114352 times.
✓ Branch 4 → 10 taken 518718 times.
|
633070 | if (ctx->constant()) { |
| 1232 |
4/6✓ Branch 5 → 6 taken 114352 times.
✗ Branch 5 → 88 not taken.
✓ Branch 6 → 7 taken 114348 times.
✓ Branch 6 → 88 taken 4 times.
✓ Branch 7 → 8 taken 114348 times.
✗ Branch 7 → 86 not taken.
|
114352 | atomicExprNode->constant = std::any_cast<ConstantNode *>(visit(ctx->constant())); |
| 1233 |
2/2✓ Branch 11 → 12 taken 151924 times.
✓ Branch 11 → 17 taken 366794 times.
|
518718 | } else if (ctx->value()) { |
| 1234 |
3/6✓ Branch 12 → 13 taken 151924 times.
✗ Branch 12 → 91 not taken.
✓ Branch 13 → 14 taken 151924 times.
✗ Branch 13 → 91 not taken.
✓ Branch 14 → 15 taken 151924 times.
✗ Branch 14 → 89 not taken.
|
151924 | atomicExprNode->value = std::any_cast<ValueNode *>(visit(ctx->value())); |
| 1235 |
11/18✓ Branch 17 → 18 taken 366794 times.
✗ Branch 17 → 92 not taken.
✓ Branch 19 → 20 taken 21311 times.
✓ Branch 19 → 23 taken 345483 times.
✓ Branch 20 → 21 taken 21311 times.
✗ Branch 20 → 92 not taken.
✓ Branch 22 → 23 taken 17528 times.
✓ Branch 22 → 24 taken 3783 times.
✓ Branch 25 → 26 taken 21311 times.
✓ Branch 25 → 27 taken 345483 times.
✓ Branch 27 → 28 taken 366794 times.
✗ Branch 27 → 29 not taken.
✓ Branch 29 → 30 taken 363011 times.
✓ Branch 29 → 68 taken 3783 times.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 94 not taken.
✗ Branch 96 → 97 not taken.
✗ Branch 96 → 98 not taken.
|
366794 | } else if (!ctx->IDENTIFIER().empty() || !ctx->TYPE_IDENTIFIER().empty()) { |
| 1236 |
1/2✓ Branch 30 → 31 taken 363011 times.
✗ Branch 30 → 108 not taken.
|
363011 | std::stringstream fqIdentifier; |
| 1237 |
2/2✓ Branch 62 → 33 taken 382593 times.
✓ Branch 62 → 63 taken 363011 times.
|
1108615 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1238 |
1/2✓ Branch 35 → 36 taken 382593 times.
✗ Branch 35 → 37 not taken.
|
382593 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1239 |
1/2✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 382593 times.
|
382593 | if (!terminal) |
| 1240 | ✗ | continue; | |
| 1241 | |||
| 1242 |
2/4✓ Branch 40 → 41 taken 382593 times.
✗ Branch 40 → 104 not taken.
✓ Branch 41 → 42 taken 382593 times.
✗ Branch 41 → 104 not taken.
|
382593 | const size_t terminalType = terminal->getSymbol()->getType(); |
| 1243 |
4/4✓ Branch 42 → 43 taken 37110 times.
✓ Branch 42 → 44 taken 345483 times.
✓ Branch 43 → 44 taken 27319 times.
✓ Branch 43 → 53 taken 9791 times.
|
382593 | if (terminalType == SpiceParser::IDENTIFIER || terminalType == SpiceParser::TYPE_IDENTIFIER) { |
| 1244 |
1/2✓ Branch 44 → 45 taken 372802 times.
✗ Branch 44 → 103 not taken.
|
372802 | const std::string fragment = getIdentifier(terminal, false); |
| 1245 |
1/2✓ Branch 45 → 46 taken 372802 times.
✗ Branch 45 → 101 not taken.
|
372802 | atomicExprNode->identifierFragments.push_back(fragment); |
| 1246 |
3/4✓ Branch 46 → 47 taken 372802 times.
✗ Branch 46 → 100 not taken.
✓ Branch 48 → 49 taken 9791 times.
✓ Branch 48 → 50 taken 363011 times.
|
372802 | if (fqIdentifier.tellp() != 0) |
| 1247 |
1/2✓ Branch 49 → 50 taken 9791 times.
✗ Branch 49 → 101 not taken.
|
9791 | fqIdentifier << SCOPE_ACCESS_TOKEN; |
| 1248 |
1/2✓ Branch 50 → 51 taken 372802 times.
✗ Branch 50 → 101 not taken.
|
372802 | fqIdentifier << fragment; |
| 1249 | 372802 | } | |
| 1250 | } | ||
| 1251 |
1/2✓ Branch 63 → 64 taken 363011 times.
✗ Branch 63 → 105 not taken.
|
363011 | atomicExprNode->fqIdentifier = fqIdentifier.str(); |
| 1252 |
1/2✓ Branch 69 → 70 taken 3783 times.
✗ Branch 69 → 75 not taken.
|
366794 | } else if (ctx->assignExpr()) { |
| 1253 |
3/6✓ Branch 70 → 71 taken 3783 times.
✗ Branch 70 → 111 not taken.
✓ Branch 71 → 72 taken 3783 times.
✗ Branch 71 → 111 not taken.
✓ Branch 72 → 73 taken 3783 times.
✗ Branch 72 → 109 not taken.
|
3783 | 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 633066 times.
✗ Branch 82 → 112 not taken.
|
1266132 | return concludeExprNode(atomicExprNode); |
| 1259 | } | ||
| 1260 | |||
| 1261 | 151924 | std::any ASTBuilder::visitValue(SpiceParser::ValueContext *ctx) { | |
| 1262 | 151924 | const auto valueNode = createNode<ValueNode>(ctx); | |
| 1263 | |||
| 1264 | // Visit children | ||
| 1265 |
2/2✓ Branch 4 → 5 taken 135378 times.
✓ Branch 4 → 10 taken 16546 times.
|
151924 | if (ctx->fctCall()) { |
| 1266 |
3/6✓ Branch 5 → 6 taken 135378 times.
✗ Branch 5 → 65 not taken.
✓ Branch 6 → 7 taken 135378 times.
✗ Branch 6 → 65 not taken.
✓ Branch 7 → 8 taken 135378 times.
✗ Branch 7 → 63 not taken.
|
135378 | valueNode->fctCall = std::any_cast<FctCallNode *>(visit(ctx->fctCall())); |
| 1267 |
2/2✓ Branch 11 → 12 taken 614 times.
✓ Branch 11 → 17 taken 15932 times.
|
16546 | } else if (ctx->arrayInitialization()) { |
| 1268 |
3/6✓ Branch 12 → 13 taken 614 times.
✗ Branch 12 → 68 not taken.
✓ Branch 13 → 14 taken 614 times.
✗ Branch 13 → 68 not taken.
✓ Branch 14 → 15 taken 614 times.
✗ Branch 14 → 66 not taken.
|
614 | valueNode->arrayInitialization = std::any_cast<ArrayInitializationNode *>(visit(ctx->arrayInitialization())); |
| 1269 |
2/2✓ Branch 18 → 19 taken 2766 times.
✓ Branch 18 → 24 taken 13166 times.
|
15932 | } else if (ctx->structInstantiation()) { |
| 1270 |
3/6✓ Branch 19 → 20 taken 2766 times.
✗ Branch 19 → 71 not taken.
✓ Branch 20 → 21 taken 2766 times.
✗ Branch 20 → 71 not taken.
✓ Branch 21 → 22 taken 2766 times.
✗ Branch 21 → 69 not taken.
|
2766 | valueNode->structInstantiation = std::any_cast<StructInstantiationNode *>(visit(ctx->structInstantiation())); |
| 1271 |
2/2✓ Branch 25 → 26 taken 109 times.
✓ Branch 25 → 31 taken 13057 times.
|
13166 | } 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 150 times.
✓ Branch 32 → 38 taken 12907 times.
|
13057 | } else if (ctx->lambdaProc()) { |
| 1274 |
3/6✓ Branch 33 → 34 taken 150 times.
✗ Branch 33 → 77 not taken.
✓ Branch 34 → 35 taken 150 times.
✗ Branch 34 → 77 not taken.
✓ Branch 35 → 36 taken 150 times.
✗ Branch 35 → 75 not taken.
|
150 | valueNode->lambdaProc = std::any_cast<LambdaProcNode *>(visit(ctx->lambdaProc())); |
| 1275 |
2/2✓ Branch 39 → 40 taken 2 times.
✓ Branch 39 → 45 taken 12905 times.
|
12907 | } 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 12905 times.
✗ Branch 46 → 52 not taken.
|
12905 | } else if (ctx->dataType()) { |
| 1278 | 12905 | valueNode->isNil = true; | |
| 1279 |
3/6✓ Branch 47 → 48 taken 12905 times.
✗ Branch 47 → 83 not taken.
✓ Branch 48 → 49 taken 12905 times.
✗ Branch 48 → 83 not taken.
✓ Branch 49 → 50 taken 12905 times.
✗ Branch 49 → 81 not taken.
|
12905 | 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 151924 times.
✗ Branch 59 → 84 not taken.
|
303848 | return concludeNode(valueNode); |
| 1285 | } | ||
| 1286 | |||
| 1287 | 126656 | std::any ASTBuilder::visitConstant(SpiceParser::ConstantContext *ctx) { | |
| 1288 | 126656 | const auto constantNode = createNode<ConstantNode>(ctx); | |
| 1289 | |||
| 1290 | // Detect an optional leading minus sign for numeric literals | ||
| 1291 | 126656 | const bool isNegative = ctx->MINUS() != nullptr; | |
| 1292 | |||
| 1293 | // Enrich | ||
| 1294 |
2/2✓ Branch 5 → 6 taken 4008 times.
✓ Branch 5 → 14 taken 122648 times.
|
126656 | if (ctx->DOUBLE_LIT()) { |
| 1295 | 4008 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_DOUBLE; | |
| 1296 |
3/6✓ Branch 6 → 7 taken 4008 times.
✗ Branch 6 → 63 not taken.
✓ Branch 7 → 8 taken 4008 times.
✗ Branch 7 → 63 not taken.
✓ Branch 8 → 9 taken 4008 times.
✗ Branch 8 → 61 not taken.
|
4008 | const double value = std::stod(ctx->DOUBLE_LIT()->toString()); |
| 1297 |
2/2✓ Branch 10 → 11 taken 318 times.
✓ Branch 10 → 12 taken 3690 times.
|
4008 | constantNode->compileTimeValue.doubleValue = isNegative ? -value : value; |
| 1298 |
2/2✓ Branch 15 → 16 taken 23730 times.
✓ Branch 15 → 19 taken 98918 times.
|
122648 | } else if (ctx->INT_LIT()) { |
| 1299 | 23730 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_INT; | |
| 1300 | 23730 | constantNode->compileTimeValue.intValue = parseInt(ctx->INT_LIT(), isNegative); | |
| 1301 |
2/2✓ Branch 20 → 21 taken 2418 times.
✓ Branch 20 → 24 taken 96500 times.
|
98918 | } else if (ctx->SHORT_LIT()) { |
| 1302 | 2418 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_SHORT; | |
| 1303 | 2418 | constantNode->compileTimeValue.shortValue = parseShort(ctx->SHORT_LIT(), isNegative); | |
| 1304 |
2/2✓ Branch 25 → 26 taken 43412 times.
✓ Branch 25 → 29 taken 53088 times.
|
96500 | } else if (ctx->LONG_LIT()) { |
| 1305 | 43412 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_LONG; | |
| 1306 | 43412 | constantNode->compileTimeValue.longValue = parseLong(ctx->LONG_LIT(), isNegative); | |
| 1307 |
2/2✓ Branch 30 → 31 taken 14221 times.
✓ Branch 30 → 34 taken 38867 times.
|
53088 | } else if (ctx->CHAR_LIT()) { |
| 1308 | 14221 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_CHAR; | |
| 1309 | 14221 | constantNode->compileTimeValue.charValue = parseChar(ctx->CHAR_LIT()); | |
| 1310 |
2/2✓ Branch 35 → 36 taken 27243 times.
✓ Branch 35 → 44 taken 11624 times.
|
38867 | } else if (ctx->STRING_LIT()) { |
| 1311 | // Save a pointer to the string in the compile time value | ||
| 1312 | 27243 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_STRING; | |
| 1313 | 27243 | constantNode->compileTimeValue.stringValueOffset = resourceManager.compileTimeStringValues.size(); | |
| 1314 | // Add the string to the global compile time string list | ||
| 1315 |
4/8✓ Branch 37 → 38 taken 27243 times.
✗ Branch 37 → 68 not taken.
✓ Branch 38 → 39 taken 27243 times.
✗ Branch 38 → 68 not taken.
✓ Branch 39 → 40 taken 27243 times.
✗ Branch 39 → 66 not taken.
✓ Branch 40 → 41 taken 27243 times.
✗ Branch 40 → 64 not taken.
|
27243 | resourceManager.compileTimeStringValues.push_back(parseString(ctx->STRING_LIT()->toString())); |
| 1316 |
2/2✓ Branch 45 → 46 taken 5792 times.
✓ Branch 45 → 47 taken 5832 times.
|
11624 | } else if (ctx->TRUE()) { |
| 1317 | 5792 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL; | |
| 1318 | 5792 | constantNode->compileTimeValue.boolValue = true; | |
| 1319 |
1/2✓ Branch 48 → 49 taken 5832 times.
✗ Branch 48 → 50 not taken.
|
5832 | } else if (ctx->FALSE()) { |
| 1320 | 5832 | constantNode->type = ConstantNode::PrimitiveValueType::TYPE_BOOL; | |
| 1321 | 5832 | constantNode->compileTimeValue.boolValue = false; | |
| 1322 | } else { | ||
| 1323 | − | assert_fail("Unknown constant type"); // GCOV_EXCL_LINE | |
| 1324 | } | ||
| 1325 | |||
| 1326 |
1/2✓ Branch 57 → 58 taken 126652 times.
✗ Branch 57 → 70 not taken.
|
253304 | return concludeNode(constantNode); |
| 1327 | } | ||
| 1328 | |||
| 1329 | 135378 | std::any ASTBuilder::visitFctCall(SpiceParser::FctCallContext *ctx) { | |
| 1330 |
1/2✓ Branch 2 → 3 taken 135378 times.
✗ Branch 2 → 92 not taken.
|
135378 | const auto fctCallNode = createNode<FctCallNode>(ctx); |
| 1331 | |||
| 1332 |
1/2✓ Branch 3 → 4 taken 135378 times.
✗ Branch 3 → 92 not taken.
|
135378 | std::stringstream fqFunctionName; |
| 1333 |
2/2✓ Branch 46 → 6 taken 668211 times.
✓ Branch 46 → 47 taken 135378 times.
|
938967 | for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1334 |
1/2✓ Branch 8 → 9 taken 668211 times.
✗ Branch 8 → 10 not taken.
|
668211 | const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree); |
| 1335 |
2/2✓ Branch 11 → 12 taken 107631 times.
✓ Branch 11 → 13 taken 560580 times.
|
668211 | if (!terminal) |
| 1336 | 107631 | continue; | |
| 1337 | |||
| 1338 |
4/6✓ Branch 13 → 14 taken 560580 times.
✗ Branch 13 → 81 not taken.
✓ Branch 14 → 15 taken 560580 times.
✗ Branch 14 → 81 not taken.
✓ Branch 15 → 16 taken 182532 times.
✓ Branch 15 → 21 taken 378048 times.
|
560580 | if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) { |
| 1339 |
1/2✓ Branch 16 → 17 taken 182532 times.
✗ Branch 16 → 77 not taken.
|
182532 | const std::string fragment = terminal->toString(); |
| 1340 |
1/2✓ Branch 17 → 18 taken 182532 times.
✗ Branch 17 → 75 not taken.
|
182532 | fctCallNode->functionNameFragments.push_back(fragment); |
| 1341 |
1/2✓ Branch 18 → 19 taken 182532 times.
✗ Branch 18 → 75 not taken.
|
182532 | fqFunctionName << fragment; |
| 1342 |
4/6✓ Branch 21 → 22 taken 378048 times.
✗ Branch 21 → 81 not taken.
✓ Branch 22 → 23 taken 378048 times.
✗ Branch 22 → 81 not taken.
✓ Branch 23 → 24 taken 21684 times.
✓ Branch 23 → 29 taken 356364 times.
|
560580 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1343 |
1/2✓ Branch 24 → 25 taken 21684 times.
✗ Branch 24 → 80 not taken.
|
21684 | const std::string fragment = terminal->toString(); |
| 1344 |
1/2✓ Branch 25 → 26 taken 21684 times.
✗ Branch 25 → 78 not taken.
|
21684 | fctCallNode->functionNameFragments.push_back(fragment); |
| 1345 |
1/2✓ Branch 26 → 27 taken 21684 times.
✗ Branch 26 → 78 not taken.
|
21684 | fqFunctionName << fragment; |
| 1346 |
4/6✓ Branch 29 → 30 taken 356364 times.
✗ Branch 29 → 81 not taken.
✓ Branch 30 → 31 taken 356364 times.
✗ Branch 30 → 81 not taken.
✓ Branch 31 → 32 taken 320 times.
✓ Branch 31 → 33 taken 356044 times.
|
378048 | } else if (terminal->getSymbol()->getType() == SpiceParser::SCOPE_ACCESS) { |
| 1347 |
1/2✓ Branch 32 → 37 taken 320 times.
✗ Branch 32 → 81 not taken.
|
320 | fqFunctionName << SCOPE_ACCESS_TOKEN; |
| 1348 |
4/6✓ Branch 33 → 34 taken 356044 times.
✗ Branch 33 → 81 not taken.
✓ Branch 34 → 35 taken 356044 times.
✗ Branch 34 → 81 not taken.
✓ Branch 35 → 36 taken 68518 times.
✓ Branch 35 → 37 taken 287526 times.
|
356044 | } else if (terminal->getSymbol()->getType() == SpiceParser::DOT) { |
| 1349 |
1/2✓ Branch 36 → 37 taken 68518 times.
✗ Branch 36 → 81 not taken.
|
68518 | fqFunctionName << MEMBER_ACCESS_TOKEN; |
| 1350 | } | ||
| 1351 | } | ||
| 1352 |
1/2✓ Branch 47 → 48 taken 135378 times.
✗ Branch 47 → 82 not taken.
|
135378 | fctCallNode->fqFunctionName = fqFunctionName.str(); |
| 1353 | |||
| 1354 | // Visit children | ||
| 1355 |
3/4✓ Branch 50 → 51 taken 135378 times.
✗ Branch 50 → 90 not taken.
✓ Branch 51 → 52 taken 8385 times.
✓ Branch 51 → 57 taken 126993 times.
|
135378 | if (ctx->typeLst()) { |
| 1356 | 8385 | fctCallNode->hasTemplateTypes = true; | |
| 1357 |
3/6✓ Branch 52 → 53 taken 8385 times.
✗ Branch 52 → 85 not taken.
✓ Branch 53 → 54 taken 8385 times.
✗ Branch 53 → 85 not taken.
✓ Branch 54 → 55 taken 8385 times.
✗ Branch 54 → 83 not taken.
|
8385 | fctCallNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1358 | } | ||
| 1359 |
3/4✓ Branch 57 → 58 taken 135378 times.
✗ Branch 57 → 90 not taken.
✓ Branch 58 → 59 taken 99246 times.
✓ Branch 58 → 64 taken 36132 times.
|
135378 | if (ctx->argLst()) { |
| 1360 | 99246 | fctCallNode->hasArgs = true; | |
| 1361 |
3/6✓ Branch 59 → 60 taken 99246 times.
✗ Branch 59 → 88 not taken.
✓ Branch 60 → 61 taken 99246 times.
✗ Branch 60 → 88 not taken.
✓ Branch 61 → 62 taken 99246 times.
✗ Branch 61 → 86 not taken.
|
99246 | fctCallNode->argLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1362 | } | ||
| 1363 | |||
| 1364 |
1/2✓ Branch 70 → 71 taken 135378 times.
✗ Branch 70 → 89 not taken.
|
270756 | return concludeNode(fctCallNode); |
| 1365 | 135378 | } | |
| 1366 | |||
| 1367 | 614 | std::any ASTBuilder::visitArrayInitialization(SpiceParser::ArrayInitializationContext *ctx) { | |
| 1368 | 614 | const auto arrayInitializationNode = createNode<ArrayInitializationNode>(ctx); | |
| 1369 | |||
| 1370 | // Visit children | ||
| 1371 |
2/2✓ Branch 4 → 5 taken 612 times.
✓ Branch 4 → 10 taken 2 times.
|
614 | if (ctx->argLst()) |
| 1372 |
3/6✓ Branch 5 → 6 taken 612 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 612 times.
✗ Branch 6 → 22 not taken.
✓ Branch 7 → 8 taken 612 times.
✗ Branch 7 → 20 not taken.
|
612 | arrayInitializationNode->itemLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1373 | |||
| 1374 |
1/2✓ Branch 16 → 17 taken 614 times.
✗ Branch 16 → 23 not taken.
|
1228 | return concludeNode(arrayInitializationNode); |
| 1375 | } | ||
| 1376 | |||
| 1377 | 2766 | std::any ASTBuilder::visitStructInstantiation(SpiceParser::StructInstantiationContext *ctx) { | |
| 1378 |
1/2✓ Branch 2 → 3 taken 2766 times.
✗ Branch 2 → 85 not taken.
|
2766 | const auto structInstantiationNode = createNode<StructInstantiationNode>(ctx); |
| 1379 | |||
| 1380 | // Enrich | ||
| 1381 |
1/2✓ Branch 3 → 4 taken 2766 times.
✗ Branch 3 → 85 not taken.
|
2766 | std::stringstream fqStructName; |
| 1382 |
2/2✓ Branch 39 → 6 taken 11083 times.
✓ Branch 39 → 40 taken 2766 times.
|
16615 | for (antlr4::ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1383 |
1/2✓ Branch 8 → 9 taken 11083 times.
✗ Branch 8 → 10 not taken.
|
11083 | const auto terminal = dynamic_cast<antlr4::tree::TerminalNode *>(subTree); |
| 1384 |
2/2✓ Branch 11 → 12 taken 2731 times.
✓ Branch 11 → 13 taken 8352 times.
|
11083 | if (!terminal) |
| 1385 | 2731 | continue; | |
| 1386 | |||
| 1387 |
4/6✓ Branch 13 → 14 taken 8352 times.
✗ Branch 13 → 74 not taken.
✓ Branch 14 → 15 taken 8352 times.
✗ Branch 14 → 74 not taken.
✓ Branch 15 → 16 taken 6 times.
✓ Branch 15 → 22 taken 8346 times.
|
8352 | 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 8346 times.
✗ Branch 22 → 74 not taken.
✓ Branch 23 → 24 taken 8346 times.
✗ Branch 23 → 74 not taken.
✓ Branch 24 → 25 taken 2766 times.
✓ Branch 24 → 30 taken 5580 times.
|
8352 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1392 |
1/2✓ Branch 25 → 26 taken 2766 times.
✗ Branch 25 → 73 not taken.
|
2766 | const std::string fragment = terminal->toString(); |
| 1393 |
1/2✓ Branch 26 → 27 taken 2766 times.
✗ Branch 26 → 71 not taken.
|
2766 | structInstantiationNode->structNameFragments.push_back(fragment); |
| 1394 |
1/2✓ Branch 27 → 28 taken 2766 times.
✗ Branch 27 → 71 not taken.
|
2766 | fqStructName << fragment; |
| 1395 | 2766 | } | |
| 1396 | } | ||
| 1397 |
1/2✓ Branch 40 → 41 taken 2766 times.
✗ Branch 40 → 75 not taken.
|
2766 | structInstantiationNode->fqStructName = fqStructName.str(); |
| 1398 | |||
| 1399 | // Visit children | ||
| 1400 |
3/4✓ Branch 43 → 44 taken 2766 times.
✗ Branch 43 → 83 not taken.
✓ Branch 44 → 45 taken 21 times.
✓ Branch 44 → 50 taken 2745 times.
|
2766 | 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 2766 times.
✗ Branch 50 → 83 not taken.
✓ Branch 51 → 52 taken 2710 times.
✓ Branch 51 → 57 taken 56 times.
|
2766 | if (ctx->argLst()) |
| 1405 |
3/6✓ Branch 52 → 53 taken 2710 times.
✗ Branch 52 → 81 not taken.
✓ Branch 53 → 54 taken 2710 times.
✗ Branch 53 → 81 not taken.
✓ Branch 54 → 55 taken 2710 times.
✗ Branch 54 → 79 not taken.
|
2710 | structInstantiationNode->fieldLst = std::any_cast<ArgLstNode *>(visit(ctx->argLst())); |
| 1406 | |||
| 1407 |
1/2✓ Branch 63 → 64 taken 2766 times.
✗ Branch 63 → 82 not taken.
|
5532 | return concludeNode(structInstantiationNode); |
| 1408 | 2766 | } | |
| 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 | 150 | std::any ASTBuilder::visitLambdaProc(SpiceParser::LambdaProcContext *ctx) { | |
| 1427 | 150 | const auto lambdaProcNode = createNode<LambdaProcNode>(ctx); | |
| 1428 | |||
| 1429 | // Visit children | ||
| 1430 |
2/2✓ Branch 4 → 5 taken 118 times.
✓ Branch 4 → 10 taken 32 times.
|
150 | if (ctx->paramLst()) { |
| 1431 | 118 | lambdaProcNode->hasParams = true; | |
| 1432 |
3/6✓ Branch 5 → 6 taken 118 times.
✗ Branch 5 → 33 not taken.
✓ Branch 6 → 7 taken 118 times.
✗ Branch 6 → 33 not taken.
✓ Branch 7 → 8 taken 118 times.
✗ Branch 7 → 31 not taken.
|
118 | lambdaProcNode->paramLst = std::any_cast<ParamLstNode *>(visit(ctx->paramLst())); |
| 1433 | } | ||
| 1434 |
2/2✓ Branch 11 → 12 taken 16 times.
✓ Branch 11 → 17 taken 134 times.
|
150 | 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 150 times.
✗ Branch 17 → 39 not taken.
✓ Branch 18 → 19 taken 150 times.
✗ Branch 18 → 39 not taken.
✓ Branch 19 → 20 taken 150 times.
✗ Branch 19 → 37 not taken.
✓ Branch 21 → 22 taken 150 times.
✗ Branch 21 → 40 not taken.
|
150 | lambdaProcNode->body = std::any_cast<StmtLstNode *>(visit(ctx->stmtLst())); |
| 1437 | |||
| 1438 |
1/2✓ Branch 27 → 28 taken 150 times.
✗ Branch 27 → 40 not taken.
|
300 | 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 | 329846 | std::any ASTBuilder::visitDataType(SpiceParser::DataTypeContext *ctx) { | |
| 1455 | 329846 | const auto dataTypeNode = createNode<DataTypeNode>(ctx); | |
| 1456 | |||
| 1457 | // Visit children | ||
| 1458 |
2/2✓ Branch 4 → 5 taken 120786 times.
✓ Branch 4 → 10 taken 209060 times.
|
329846 | if (ctx->qualifierLst()) |
| 1459 |
4/6✓ Branch 5 → 6 taken 120786 times.
✗ Branch 5 → 73 not taken.
✓ Branch 6 → 7 taken 120784 times.
✓ Branch 6 → 73 taken 2 times.
✓ Branch 7 → 8 taken 120784 times.
✗ Branch 7 → 71 not taken.
|
120786 | dataTypeNode->qualifierLst = std::any_cast<QualifierLstNode *>(visit(ctx->qualifierLst())); |
| 1460 |
3/6✓ Branch 10 → 11 taken 329844 times.
✗ Branch 10 → 76 not taken.
✓ Branch 11 → 12 taken 329844 times.
✗ Branch 11 → 76 not taken.
✓ Branch 12 → 13 taken 329844 times.
✗ Branch 12 → 74 not taken.
|
329844 | dataTypeNode->baseDataType = std::any_cast<BaseDataTypeNode *>(visit(ctx->baseDataType())); |
| 1461 | |||
| 1462 | // Enrich | ||
| 1463 |
2/2✓ Branch 60 → 15 taken 542607 times.
✓ Branch 60 → 61 taken 329844 times.
|
872451 | for (size_t i = 0; i < ctx->children.size(); i++) { |
| 1464 | 542607 | antlr4::tree::ParseTree *subTree = ctx->children.at(i); | |
| 1465 |
1/2✓ Branch 16 → 17 taken 542607 times.
✗ Branch 16 → 18 not taken.
|
542607 | auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1466 |
2/2✓ Branch 19 → 20 taken 450628 times.
✓ Branch 19 → 21 taken 91979 times.
|
542607 | if (!terminal) |
| 1467 | 450628 | continue; | |
| 1468 | |||
| 1469 |
2/2✓ Branch 23 → 24 taken 55161 times.
✓ Branch 23 → 26 taken 36818 times.
|
91979 | if (terminal->getSymbol()->getType() == SpiceParser::MUL) { |
| 1470 |
1/2✓ Branch 24 → 25 taken 55161 times.
✗ Branch 24 → 77 not taken.
|
55161 | dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_PTR, false, 0); |
| 1471 |
2/2✓ Branch 28 → 29 taken 35853 times.
✓ Branch 28 → 31 taken 965 times.
|
36818 | } else if (terminal->getSymbol()->getType() == SpiceParser::BITWISE_AND) { |
| 1472 |
1/2✓ Branch 29 → 30 taken 35853 times.
✗ Branch 29 → 80 not taken.
|
35853 | dataTypeNode->tmQueue.emplace(DataTypeNode::TypeModifierType::TYPE_REF, false, 0); |
| 1473 |
1/2✓ Branch 33 → 34 taken 965 times.
✗ Branch 33 → 58 not taken.
|
965 | } else if (terminal->getSymbol()->getType() == SpiceParser::LBRACKET) { |
| 1474 | 965 | i++; // Consume LBRACKET | |
| 1475 |
1/2✓ Branch 34 → 35 taken 965 times.
✗ Branch 34 → 92 not taken.
|
965 | subTree = ctx->children.at(i); |
| 1476 |
1/2✓ Branch 35 → 36 taken 965 times.
✗ Branch 35 → 37 not taken.
|
965 | terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1477 | 965 | bool hasSize = false; | |
| 1478 | 965 | unsigned int hardCodedSize = 0; | |
| 1479 | 965 | std::string sizeVarName; | |
| 1480 |
4/6✓ Branch 39 → 40 taken 965 times.
✗ Branch 39 → 90 not taken.
✓ Branch 40 → 41 taken 965 times.
✗ Branch 40 → 90 not taken.
✓ Branch 41 → 42 taken 232 times.
✓ Branch 41 → 46 taken 733 times.
|
965 | if (terminal->getSymbol()->getType() == SpiceParser::INT_LIT) { |
| 1481 | 232 | hasSize = true; | |
| 1482 |
2/4✓ Branch 42 → 43 taken 232 times.
✗ Branch 42 → 85 not taken.
✓ Branch 43 → 44 taken 232 times.
✗ Branch 43 → 83 not taken.
|
232 | hardCodedSize = std::stoi(terminal->getText()); |
| 1483 | 232 | i++; // Consume INT_LIT | |
| 1484 |
4/6✓ Branch 46 → 47 taken 733 times.
✗ Branch 46 → 90 not taken.
✓ Branch 47 → 48 taken 733 times.
✗ Branch 47 → 90 not taken.
✓ Branch 48 → 49 taken 553 times.
✓ Branch 48 → 53 taken 180 times.
|
733 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1485 | 553 | hasSize = true; | |
| 1486 |
1/2✓ Branch 49 → 50 taken 553 times.
✗ Branch 49 → 86 not taken.
|
553 | sizeVarName = getIdentifier(terminal, true); |
| 1487 | 553 | i++; // Consume TYPE_IDENTIFIER | |
| 1488 | } | ||
| 1489 |
1/2✓ Branch 54 → 55 taken 965 times.
✗ Branch 54 → 87 not taken.
|
965 | dataTypeNode->tmQueue.push({DataTypeNode::TypeModifierType::TYPE_ARRAY, hasSize, hardCodedSize, sizeVarName}); |
| 1490 | 965 | } | |
| 1491 | } | ||
| 1492 | |||
| 1493 |
1/2✓ Branch 67 → 68 taken 329844 times.
✗ Branch 67 → 93 not taken.
|
659688 | return concludeNode(dataTypeNode); |
| 1494 |
1/2✓ Branch 53 → 54 taken 965 times.
✗ Branch 53 → 89 not taken.
|
965 | } |
| 1495 | |||
| 1496 | 329844 | std::any ASTBuilder::visitBaseDataType(SpiceParser::BaseDataTypeContext *ctx) { | |
| 1497 | 329844 | const auto baseDataTypeNode = createNode<BaseDataTypeNode>(ctx); | |
| 1498 | |||
| 1499 | // Enrich | ||
| 1500 |
2/2✓ Branch 4 → 5 taken 4369 times.
✓ Branch 4 → 6 taken 325475 times.
|
329844 | if (ctx->TYPE_DOUBLE()) { |
| 1501 | 4369 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DOUBLE; | |
| 1502 |
2/2✓ Branch 7 → 8 taken 24642 times.
✓ Branch 7 → 9 taken 300833 times.
|
325475 | } else if (ctx->TYPE_INT()) { |
| 1503 | 24642 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_INT; | |
| 1504 |
2/2✓ Branch 10 → 11 taken 4638 times.
✓ Branch 10 → 12 taken 296195 times.
|
300833 | } else if (ctx->TYPE_SHORT()) { |
| 1505 | 4638 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_SHORT; | |
| 1506 |
2/2✓ Branch 13 → 14 taken 49525 times.
✓ Branch 13 → 15 taken 246670 times.
|
296195 | } else if (ctx->TYPE_LONG()) { |
| 1507 | 49525 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_LONG; | |
| 1508 |
2/2✓ Branch 16 → 17 taken 18896 times.
✓ Branch 16 → 18 taken 227774 times.
|
246670 | } else if (ctx->TYPE_BYTE()) { |
| 1509 | 18896 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BYTE; | |
| 1510 |
2/2✓ Branch 19 → 20 taken 31243 times.
✓ Branch 19 → 21 taken 196531 times.
|
227774 | } else if (ctx->TYPE_CHAR()) { |
| 1511 | 31243 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CHAR; | |
| 1512 |
2/2✓ Branch 22 → 23 taken 27554 times.
✓ Branch 22 → 24 taken 168977 times.
|
196531 | } else if (ctx->TYPE_STRING()) { |
| 1513 | 27554 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_STRING; | |
| 1514 |
2/2✓ Branch 25 → 26 taken 22979 times.
✓ Branch 25 → 27 taken 145998 times.
|
168977 | } else if (ctx->TYPE_BOOL()) { |
| 1515 | 22979 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_BOOL; | |
| 1516 |
2/2✓ Branch 28 → 29 taken 3106 times.
✓ Branch 28 → 30 taken 142892 times.
|
145998 | } else if (ctx->TYPE_DYN()) { |
| 1517 | 3106 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_DYN; | |
| 1518 |
2/2✓ Branch 31 → 32 taken 142018 times.
✓ Branch 31 → 37 taken 874 times.
|
142892 | } else if (ctx->customDataType()) { |
| 1519 | 142018 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_CUSTOM; | |
| 1520 |
3/6✓ Branch 32 → 33 taken 142018 times.
✗ Branch 32 → 57 not taken.
✓ Branch 33 → 34 taken 142018 times.
✗ Branch 33 → 57 not taken.
✓ Branch 34 → 35 taken 142018 times.
✗ Branch 34 → 55 not taken.
|
142018 | baseDataTypeNode->customDataType = std::any_cast<CustomDataTypeNode *>(visit(ctx->customDataType())); |
| 1521 |
1/2✓ Branch 38 → 39 taken 874 times.
✗ Branch 38 → 44 not taken.
|
874 | } else if (ctx->functionDataType()) { |
| 1522 | 874 | baseDataTypeNode->type = BaseDataTypeNode::Type::TYPE_FUNCTION; | |
| 1523 |
3/6✓ Branch 39 → 40 taken 874 times.
✗ Branch 39 → 60 not taken.
✓ Branch 40 → 41 taken 874 times.
✗ Branch 40 → 60 not taken.
✓ Branch 41 → 42 taken 874 times.
✗ Branch 41 → 58 not taken.
|
874 | 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 329844 times.
✗ Branch 51 → 61 not taken.
|
659688 | return concludeNode(baseDataTypeNode); |
| 1529 | } | ||
| 1530 | |||
| 1531 | 142018 | std::any ASTBuilder::visitCustomDataType(SpiceParser::CustomDataTypeContext *ctx) { | |
| 1532 |
1/2✓ Branch 2 → 3 taken 142018 times.
✗ Branch 2 → 75 not taken.
|
142018 | const auto customDataTypeNode = createNode<CustomDataTypeNode>(ctx); |
| 1533 | |||
| 1534 | // Enrich | ||
| 1535 |
1/2✓ Branch 3 → 4 taken 142018 times.
✗ Branch 3 → 75 not taken.
|
142018 | std::stringstream fqTypeName; |
| 1536 |
2/2✓ Branch 39 → 6 taken 194804 times.
✓ Branch 39 → 40 taken 142018 times.
|
478840 | for (ParserRuleContext::ParseTree *subTree : ctx->children) { |
| 1537 |
1/2✓ Branch 8 → 9 taken 194804 times.
✗ Branch 8 → 10 not taken.
|
194804 | const auto terminal = dynamic_cast<TerminalNode *>(subTree); |
| 1538 |
2/2✓ Branch 11 → 12 taken 17458 times.
✓ Branch 11 → 13 taken 177346 times.
|
194804 | if (!terminal) |
| 1539 | 17458 | continue; | |
| 1540 | |||
| 1541 |
4/6✓ Branch 13 → 14 taken 177346 times.
✗ Branch 13 → 67 not taken.
✓ Branch 14 → 15 taken 177346 times.
✗ Branch 14 → 67 not taken.
✓ Branch 15 → 16 taken 206 times.
✓ Branch 15 → 22 taken 177140 times.
|
177346 | if (terminal->getSymbol()->getType() == SpiceParser::IDENTIFIER) { |
| 1542 |
1/2✓ Branch 16 → 17 taken 206 times.
✗ Branch 16 → 63 not taken.
|
206 | const std::string fragment = terminal->toString(); |
| 1543 |
1/2✓ Branch 17 → 18 taken 206 times.
✗ Branch 17 → 61 not taken.
|
206 | customDataTypeNode->typeNameFragments.push_back(fragment); |
| 1544 |
2/4✓ Branch 18 → 19 taken 206 times.
✗ Branch 18 → 61 not taken.
✓ Branch 19 → 20 taken 206 times.
✗ Branch 19 → 61 not taken.
|
206 | fqTypeName << fragment << SCOPE_ACCESS_TOKEN; |
| 1545 |
4/6✓ Branch 22 → 23 taken 177140 times.
✗ Branch 22 → 67 not taken.
✓ Branch 23 → 24 taken 177140 times.
✗ Branch 23 → 67 not taken.
✓ Branch 24 → 25 taken 142018 times.
✓ Branch 24 → 30 taken 35122 times.
|
177346 | } else if (terminal->getSymbol()->getType() == SpiceParser::TYPE_IDENTIFIER) { |
| 1546 |
1/2✓ Branch 25 → 26 taken 142018 times.
✗ Branch 25 → 66 not taken.
|
142018 | const std::string fragment = terminal->toString(); |
| 1547 |
1/2✓ Branch 26 → 27 taken 142018 times.
✗ Branch 26 → 64 not taken.
|
142018 | customDataTypeNode->typeNameFragments.push_back(fragment); |
| 1548 |
1/2✓ Branch 27 → 28 taken 142018 times.
✗ Branch 27 → 64 not taken.
|
142018 | fqTypeName << fragment; |
| 1549 | 142018 | } | |
| 1550 | } | ||
| 1551 |
1/2✓ Branch 40 → 41 taken 142018 times.
✗ Branch 40 → 68 not taken.
|
142018 | customDataTypeNode->fqTypeName = fqTypeName.str(); |
| 1552 | |||
| 1553 | // Visit children | ||
| 1554 |
3/4✓ Branch 43 → 44 taken 142018 times.
✗ Branch 43 → 73 not taken.
✓ Branch 44 → 45 taken 17458 times.
✓ Branch 44 → 50 taken 124560 times.
|
142018 | if (ctx->typeLst()) |
| 1555 |
3/6✓ Branch 45 → 46 taken 17458 times.
✗ Branch 45 → 71 not taken.
✓ Branch 46 → 47 taken 17458 times.
✗ Branch 46 → 71 not taken.
✓ Branch 47 → 48 taken 17458 times.
✗ Branch 47 → 69 not taken.
|
17458 | customDataTypeNode->templateTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1556 | |||
| 1557 |
1/2✓ Branch 56 → 57 taken 142018 times.
✗ Branch 56 → 72 not taken.
|
284036 | return concludeNode(customDataTypeNode); |
| 1558 | 142018 | } | |
| 1559 | |||
| 1560 | 874 | std::any ASTBuilder::visitFunctionDataType(SpiceParser::FunctionDataTypeContext *ctx) { | |
| 1561 | 874 | const auto functionDataTypeNode = createNode<FunctionDataTypeNode>(ctx); | |
| 1562 | |||
| 1563 | // Enrich | ||
| 1564 |
2/2✓ Branch 4 → 5 taken 524 times.
✓ Branch 4 → 11 taken 350 times.
|
874 | if (ctx->dataType()) { |
| 1565 | 524 | functionDataTypeNode->isFunction = ctx->dataType(); | |
| 1566 |
3/6✓ Branch 6 → 7 taken 524 times.
✗ Branch 6 → 30 not taken.
✓ Branch 7 → 8 taken 524 times.
✗ Branch 7 → 30 not taken.
✓ Branch 8 → 9 taken 524 times.
✗ Branch 8 → 28 not taken.
|
524 | functionDataTypeNode->returnType = std::any_cast<DataTypeNode *>(visit(ctx->dataType())); |
| 1567 | } | ||
| 1568 |
2/2✓ Branch 12 → 13 taken 734 times.
✓ Branch 12 → 18 taken 140 times.
|
874 | if (ctx->typeLst()) |
| 1569 |
3/6✓ Branch 13 → 14 taken 734 times.
✗ Branch 13 → 33 not taken.
✓ Branch 14 → 15 taken 734 times.
✗ Branch 14 → 33 not taken.
✓ Branch 15 → 16 taken 734 times.
✗ Branch 15 → 31 not taken.
|
734 | functionDataTypeNode->paramTypeLst = std::any_cast<TypeLstNode *>(visit(ctx->typeLst())); |
| 1570 | |||
| 1571 |
1/2✓ Branch 24 → 25 taken 874 times.
✗ Branch 24 → 34 not taken.
|
1748 | return concludeNode(functionDataTypeNode); |
| 1572 | } | ||
| 1573 | |||
| 1574 | 49051 | std::any ASTBuilder::visitAssignOp(SpiceParser::AssignOpContext *ctx) { | |
| 1575 | 49051 | const auto assignExprNode = resumeForExpansion<AssignExprNode>(); | |
| 1576 | |||
| 1577 | // Extract assign operator | ||
| 1578 |
2/2✓ Branch 15 → 16 taken 42934 times.
✓ Branch 15 → 17 taken 6117 times.
|
49051 | if (ctx->ASSIGN()) |
| 1579 | 42934 | assignExprNode->op = AssignExprNode::AssignOp::OP_ASSIGN; | |
| 1580 |
2/2✓ Branch 18 → 19 taken 4378 times.
✓ Branch 18 → 20 taken 1739 times.
|
6117 | else if (ctx->PLUS_EQUAL()) |
| 1581 | 4378 | assignExprNode->op = AssignExprNode::AssignOp::OP_PLUS_EQUAL; | |
| 1582 |
2/2✓ Branch 21 → 22 taken 291 times.
✓ Branch 21 → 23 taken 1448 times.
|
1739 | else if (ctx->MINUS_EQUAL()) |
| 1583 | 291 | assignExprNode->op = AssignExprNode::AssignOp::OP_MINUS_EQUAL; | |
| 1584 |
2/2✓ Branch 24 → 25 taken 495 times.
✓ Branch 24 → 26 taken 953 times.
|
1448 | else if (ctx->MUL_EQUAL()) |
| 1585 | 495 | assignExprNode->op = AssignExprNode::AssignOp::OP_MUL_EQUAL; | |
| 1586 |
2/2✓ Branch 27 → 28 taken 186 times.
✓ Branch 27 → 29 taken 767 times.
|
953 | else if (ctx->DIV_EQUAL()) |
| 1587 | 186 | assignExprNode->op = AssignExprNode::AssignOp::OP_DIV_EQUAL; | |
| 1588 |
2/2✓ Branch 30 → 31 taken 72 times.
✓ Branch 30 → 32 taken 695 times.
|
767 | 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 689 times.
|
695 | 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 673 times.
|
689 | 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 635 times.
|
673 | 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 597 times.
|
635 | else if (ctx->OR_EQUAL()) |
| 1597 | 38 | assignExprNode->op = AssignExprNode::AssignOp::OP_OR_EQUAL; | |
| 1598 |
1/2✓ Branch 45 → 46 taken 597 times.
✗ Branch 45 → 47 not taken.
|
597 | else if (ctx->XOR_EQUAL()) |
| 1599 | 597 | assignExprNode->op = AssignExprNode::AssignOp::OP_XOR_EQUAL; | |
| 1600 | else | ||
| 1601 | ✗ | assert_fail("Unknown assign operator"); | |
| 1602 | |||
| 1603 |
1/2✓ Branch 48 → 49 taken 49051 times.
✗ Branch 48 → 52 not taken.
|
98102 | return nullptr; |
| 1604 | } | ||
| 1605 | |||
| 1606 | 8108 | std::any ASTBuilder::visitOverloadableOp(SpiceParser::OverloadableOpContext *ctx) { | |
| 1607 | 8108 | const auto fctNameNode = resumeForExpansion<FctNameNode>(); | |
| 1608 | |||
| 1609 | // Enrich | ||
| 1610 |
2/2✓ Branch 15 → 16 taken 362 times.
✓ Branch 15 → 17 taken 7746 times.
|
8108 | if (ctx->PLUS()) |
| 1611 | 362 | fctNameNode->name = OP_FCT_PLUS; | |
| 1612 |
2/2✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 20 taken 7744 times.
|
7746 | else if (ctx->MINUS()) |
| 1613 | 2 | fctNameNode->name = OP_FCT_MINUS; | |
| 1614 |
2/2✓ Branch 21 → 22 taken 718 times.
✓ Branch 21 → 23 taken 7026 times.
|
7744 | else if (ctx->MUL()) |
| 1615 | 718 | fctNameNode->name = OP_FCT_MUL; | |
| 1616 |
2/2✓ Branch 24 → 25 taken 74 times.
✓ Branch 24 → 26 taken 6952 times.
|
7026 | else if (ctx->DIV()) |
| 1617 | 74 | fctNameNode->name = OP_FCT_DIV; | |
| 1618 |
2/2✓ Branch 27 → 28 taken 1862 times.
✓ Branch 27 → 29 taken 5090 times.
|
6952 | else if (ctx->EQUAL()) |
| 1619 | 1862 | fctNameNode->name = OP_FCT_EQUAL; | |
| 1620 |
2/2✓ Branch 30 → 31 taken 1790 times.
✓ Branch 30 → 32 taken 3300 times.
|
5090 | else if (ctx->NOT_EQUAL()) |
| 1621 | 1790 | fctNameNode->name = OP_FCT_NOT_EQUAL; | |
| 1622 |
3/4✓ Branch 32 → 33 taken 3300 times.
✗ Branch 32 → 85 not taken.
✓ Branch 35 → 36 taken 188 times.
✓ Branch 35 → 37 taken 3112 times.
|
3300 | else if (ctx->LESS().size() == 2) |
| 1623 | 188 | fctNameNode->name = OP_FCT_SHL; | |
| 1624 |
3/4✓ Branch 37 → 38 taken 3112 times.
✗ Branch 37 → 86 not taken.
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 42 taken 3110 times.
|
3112 | 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 3102 times.
|
3110 | 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 3094 times.
|
3102 | 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 3086 times.
|
3094 | 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 3078 times.
|
3086 | else if (ctx->BITWISE_NOT()) |
| 1633 | 8 | fctNameNode->name = OP_FCT_BITWISE_NOT; | |
| 1634 |
2/2✓ Branch 55 → 56 taken 523 times.
✓ Branch 55 → 57 taken 2555 times.
|
3078 | else if (ctx->PLUS_EQUAL()) |
| 1635 | 523 | fctNameNode->name = OP_FCT_PLUS_EQUAL; | |
| 1636 |
2/2✓ Branch 58 → 59 taken 165 times.
✓ Branch 58 → 60 taken 2390 times.
|
2555 | else if (ctx->MINUS_EQUAL()) |
| 1637 | 165 | fctNameNode->name = OP_FCT_MINUS_EQUAL; | |
| 1638 |
2/2✓ Branch 61 → 62 taken 360 times.
✓ Branch 61 → 63 taken 2030 times.
|
2390 | else if (ctx->MUL_EQUAL()) |
| 1639 | 360 | fctNameNode->name = OP_FCT_MUL_EQUAL; | |
| 1640 |
2/2✓ Branch 64 → 65 taken 74 times.
✓ Branch 64 → 66 taken 1956 times.
|
2030 | else if (ctx->DIV_EQUAL()) |
| 1641 | 74 | fctNameNode->name = OP_FCT_DIV_EQUAL; | |
| 1642 |
2/2✓ Branch 67 → 68 taken 231 times.
✓ Branch 67 → 69 taken 1725 times.
|
1956 | else if (ctx->PLUS_PLUS()) |
| 1643 | 231 | fctNameNode->name = OP_FCT_POSTFIX_PLUS_PLUS; | |
| 1644 |
2/2✓ Branch 70 → 71 taken 165 times.
✓ Branch 70 → 72 taken 1560 times.
|
1725 | else if (ctx->MINUS_MINUS()) |
| 1645 | 165 | fctNameNode->name = OP_FCT_POSTFIX_MINUS_MINUS; | |
| 1646 |
2/2✓ Branch 73 → 74 taken 891 times.
✓ Branch 73 → 75 taken 669 times.
|
1560 | else if (ctx->LBRACKET()) |
| 1647 | 891 | fctNameNode->name = OP_FCT_SUBSCRIPT; | |
| 1648 |
1/2✓ Branch 76 → 77 taken 669 times.
✗ Branch 76 → 78 not taken.
|
669 | else if (ctx->ASSIGN()) |
| 1649 | 669 | fctNameNode->name = OP_FCT_ASSIGN; | |
| 1650 | else | ||
| 1651 | − | assert_fail("Unsupported overloadable operator"); // GCOV_EXCL_LINE | |
| 1652 | |||
| 1653 | 8108 | fctNameNode->fqName = fctNameNode->name; | |
| 1654 | 8108 | fctNameNode->nameFragments.push_back(fctNameNode->name); | |
| 1655 | |||
| 1656 |
1/2✓ Branch 81 → 82 taken 8108 times.
✗ Branch 81 → 87 not taken.
|
16216 | return nullptr; |
| 1657 | } | ||
| 1658 | |||
| 1659 | 30004 | int32_t ASTBuilder::parseInt(TerminalNode *terminal, bool isNegative) { | |
| 1660 | 90012 | 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 29198 times.
✓ Branch 2 → 4 taken 806 times.
|
30004 | const int64_t upperLimit = isSigned ? INT32_MAX : UINT32_MAX; |
| 1663 |
2/2✓ Branch 5 → 6 taken 29198 times.
✓ Branch 5 → 7 taken 806 times.
|
30004 | const int64_t lowerLimit = isSigned ? INT32_MIN : 0; |
| 1664 | // Parse number, apply sign and check for limits | ||
| 1665 | 30004 | int64_t number = std::stoll(substr, nullptr, base); | |
| 1666 |
2/2✓ Branch 9 → 10 taken 449 times.
✓ Branch 9 → 11 taken 29553 times.
|
30002 | if (isNegative) |
| 1667 | 449 | number = -number; | |
| 1668 |
2/4✓ Branch 11 → 12 taken 30002 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 30002 times.
|
30002 | if (number < lowerLimit || number > upperLimit) |
| 1669 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1670 | 30002 | return static_cast<int32_t>(number); | |
| 1671 | 30004 | }; | |
| 1672 |
2/2✓ Branch 3 → 4 taken 30002 times.
✓ Branch 3 → 8 taken 2 times.
|
60006 | return parseNumeric(terminal, cb); |
| 1673 | 30004 | } | |
| 1674 | |||
| 1675 | 2418 | int16_t ASTBuilder::parseShort(TerminalNode *terminal, bool isNegative) { | |
| 1676 | 7254 | 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 1750 times.
✓ Branch 2 → 4 taken 668 times.
|
2418 | const int64_t upperLimit = isSigned ? INT16_MAX : UINT16_MAX; |
| 1679 |
2/2✓ Branch 5 → 6 taken 1750 times.
✓ Branch 5 → 7 taken 668 times.
|
2418 | const int64_t lowerLimit = isSigned ? INT16_MIN : 0; |
| 1680 | // Parse number, apply sign and check for limits | ||
| 1681 | 2418 | int64_t number = std::stoll(substr, nullptr, base); | |
| 1682 |
2/2✓ Branch 9 → 10 taken 172 times.
✓ Branch 9 → 11 taken 2246 times.
|
2418 | if (isNegative) |
| 1683 | 172 | number = -number; | |
| 1684 |
2/4✓ Branch 11 → 12 taken 2418 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 2418 times.
|
2418 | if (number < lowerLimit || number > upperLimit) |
| 1685 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1686 | 2418 | return static_cast<int16_t>(number); | |
| 1687 | 2418 | }; | |
| 1688 |
1/2✓ Branch 3 → 4 taken 2418 times.
✗ Branch 3 → 8 not taken.
|
4836 | return parseNumeric(terminal, cb); |
| 1689 | 2418 | } | |
| 1690 | |||
| 1691 | 43412 | int64_t ASTBuilder::parseLong(TerminalNode *terminal, bool isNegative) { | |
| 1692 | 130236 | 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 | 43412 | const uint64_t magnitude = std::stoull(substr, nullptr, base); | |
| 1695 |
2/2✓ Branch 3 → 4 taken 5492 times.
✓ Branch 3 → 11 taken 37920 times.
|
43412 | if (isNegative) { |
| 1696 | 5492 | 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 5492 times.
|
5492 | 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 5488 times.
|
5492 | if (magnitude == maxNegMagnitude) |
| 1700 | 4 | return INT64_MIN; | |
| 1701 | 5488 | return -static_cast<int64_t>(magnitude); | |
| 1702 | } | ||
| 1703 |
3/4✓ Branch 11 → 12 taken 34616 times.
✓ Branch 11 → 16 taken 3304 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 16 taken 34616 times.
|
37920 | if (isSigned && magnitude > static_cast<uint64_t>(INT64_MAX)) |
| 1704 | ✗ | throw std::out_of_range("Number out of range"); | |
| 1705 | 37920 | return static_cast<int64_t>(magnitude); | |
| 1706 | 43412 | }; | |
| 1707 |
1/2✓ Branch 3 → 4 taken 43412 times.
✗ Branch 3 → 8 not taken.
|
86824 | return parseNumeric(terminal, cb); |
| 1708 | 43412 | } | |
| 1709 | |||
| 1710 | 14221 | int8_t ASTBuilder::parseChar(TerminalNode *terminal) const { | |
| 1711 |
1/2✓ Branch 2 → 3 taken 14221 times.
✗ Branch 2 → 59 not taken.
|
14221 | const std::string input = terminal->toString(); |
| 1712 |
2/2✓ Branch 4 → 5 taken 9258 times.
✓ Branch 4 → 7 taken 4963 times.
|
14221 | if (input.length() == 3) // Normal char literals |
| 1713 | 9258 | return input[1]; | |
| 1714 | |||
| 1715 |
3/6✓ Branch 8 → 9 taken 4963 times.
✗ Branch 8 → 12 not taken.
✓ Branch 10 → 11 taken 4963 times.
✗ Branch 10 → 12 not taken.
✓ Branch 13 → 14 taken 4963 times.
✗ Branch 13 → 34 not taken.
|
4963 | if (input.length() == 4 && input[1] == '\\') { // Char literals with escape sequence |
| 1716 |
10/11✓ Branch 15 → 16 taken 94 times.
✗ Branch 15 → 17 not taken.
✓ Branch 15 → 18 taken 118 times.
✓ Branch 15 → 19 taken 670 times.
✓ Branch 15 → 20 taken 506 times.
✓ Branch 15 → 21 taken 460 times.
✓ Branch 15 → 22 taken 18 times.
✓ Branch 15 → 23 taken 36 times.
✓ Branch 15 → 24 taken 22 times.
✓ Branch 15 → 25 taken 3037 times.
✓ Branch 15 → 26 taken 2 times.
|
4963 | switch (input[2]) { |
| 1717 | 94 | case '\'': | |
| 1718 | 94 | return '\''; | |
| 1719 | ✗ | case '"': | |
| 1720 | ✗ | return '\"'; | |
| 1721 | 118 | case '\\': | |
| 1722 | 118 | return '\\'; | |
| 1723 | 670 | case 'n': | |
| 1724 | 670 | return '\n'; | |
| 1725 | 506 | case 'r': | |
| 1726 | 506 | return '\r'; | |
| 1727 | 460 | case 't': | |
| 1728 | 460 | 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 | 3037 | case '0': | |
| 1736 | 3037 | 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 | 14221 | } | |
| 1746 | |||
| 1747 | 27243 | std::string ASTBuilder::parseString(std::string input) { | |
| 1748 |
1/2✓ Branch 3 → 4 taken 27243 times.
✗ Branch 3 → 9 not taken.
|
27243 | input = input.substr(1, input.size() - 2); |
| 1749 | 27243 | replaceEscapeChars(input); | |
| 1750 | 27243 | return input; | |
| 1751 | } | ||
| 1752 | |||
| 1753 | 75834 | 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 30004 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 43412 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 2418 times.
✗ Branch 2 → 87 not taken.
|
75834 | 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 29198 times.
✓ Branch 4 → 9 taken 806 times.
✓ Branch 6 → 7 taken 29198 times.
✗ Branch 6 → 9 not taken.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 29198 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 43412 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 43412 times.
✗ Branch 6 → 9 not taken.
✓ Branch 8 → 9 taken 3304 times.
✓ Branch 8 → 10 taken 40108 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 2418 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 1750 times.
✓ Branch 6 → 9 taken 668 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1750 times.
|
75834 | 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 3518 times.
✓ Branch 12 → 30 taken 26486 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 5209 times.
✓ Branch 12 → 30 taken 38203 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 1674 times.
✓ Branch 12 → 30 taken 744 times.
|
75834 | 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 1126 times.
✓ Branch 14 → 30 taken 2392 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 2049 times.
✓ Branch 14 → 30 taken 3160 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 362 times.
✓ Branch 14 → 30 taken 1312 times.
|
10401 | 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 1126 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 2049 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 362 times.
✗ Branch 15 → 37 not taken.
|
3537 | 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 488 times.
✓ Branch 17 → 24 taken 638 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 686 times.
✗ Branch 17 → 24 not taken.
✓ Branch 17 → 26 taken 1363 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 360 times.
✓ Branch 17 → 26 taken 2 times.
|
3537 | 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 | 1174 | 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 488 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 686 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.
|
1174 | return cb(subStr, 16, !isUnsigned); |
| 1775 | 998 | 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 638 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 360 times.
✗ Branch 24 → 35 not taken.
|
998 | return cb(subStr, 8, !isUnsigned); |
| 1778 | 1365 | 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 1363 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.
|
1365 | return cb(input, 10, !isUnsigned); |
| 1780 | } | ||
| 1781 | 3537 | } | |
| 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 28876 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 41363 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 2056 times.
✗ Branch 30 → 38 not taken.
|
72297 | 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 | 75834 | } | |
| 1792 | |||
| 1793 | 27243 | void ASTBuilder::replaceEscapeChars(std::string &input) { | |
| 1794 | 27243 | 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 27243 times.
✗ Branch 4 → 40 not taken.
|
54486 | }; |
| 1798 | |||
| 1799 | 27243 | size_t writeIndex = 0; | |
| 1800 | 27243 | size_t readIndex = 0; | |
| 1801 | 27243 | const size_t len = input.length(); | |
| 1802 | |||
| 1803 |
2/2✓ Branch 36 → 8 taken 394005 times.
✓ Branch 36 → 37 taken 27243 times.
|
421248 | while (readIndex < len) { |
| 1804 | 394005 | const char c = input[readIndex]; | |
| 1805 |
3/4✓ Branch 9 → 10 taken 5733 times.
✓ Branch 9 → 33 taken 388272 times.
✓ Branch 10 → 11 taken 5733 times.
✗ Branch 10 → 33 not taken.
|
394005 | if (c == '\\' && readIndex + 1 < len) { |
| 1806 | 5733 | char next = input[readIndex + 1]; | |
| 1807 |
1/2✓ Branch 12 → 13 taken 5733 times.
✗ Branch 12 → 45 not taken.
|
5733 | auto it = escapeMap.find(next); |
| 1808 |
2/2✓ Branch 15 → 16 taken 5653 times.
✓ Branch 15 → 19 taken 80 times.
|
5733 | if (it != escapeMap.end()) { |
| 1809 | 5653 | input[writeIndex++] = it->second; | |
| 1810 | 5653 | readIndex += 2; | |
| 1811 | 5727 | 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 | 388278 | input[writeIndex++] = c; | |
| 1840 | 388278 | readIndex++; | |
| 1841 | } | ||
| 1842 | |||
| 1843 |
1/2✓ Branch 37 → 38 taken 27243 times.
✗ Branch 37 → 46 not taken.
|
27243 | input.resize(writeIndex); |
| 1844 | 27243 | } | |
| 1845 | |||
| 1846 | 823338 | std::string ASTBuilder::getIdentifier(TerminalNode *terminal, bool isTypeIdentifier) const { | |
| 1847 | 823338 | 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 823338 times.
✗ Branch 3 → 52 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 14 taken 823336 times.
|
823338 | 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 70121 times.
✓ Branch 14 → 19 taken 753215 times.
✓ Branch 15 → 16 taken 15181 times.
✓ Branch 15 → 19 taken 54940 times.
✓ Branch 20 → 21 taken 2 times.
✓ Branch 20 → 30 taken 823334 times.
|
838517 | if (isTypeIdentifier && !sourceFile->isStdFile && |
| 1857 |
3/4✓ Branch 16 → 17 taken 15181 times.
✗ Branch 16 → 52 not taken.
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 19 taken 15179 times.
|
15181 | 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 | 823334 | return identifier; | |
| 1863 | 4 | } | |
| 1864 | |||
| 1865 | } // namespace spice::compiler | ||
| 1866 |