GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 6 / 0 / 6
Functions: 100.0% 1 / 0 / 1
Branches: 50.0% 43 / 0 / 86

src/model/Function.h
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <utility>
6
7 #include <model/GenericType.h>
8 #include <symboltablebuilder/QualType.h>
9 #include <symboltablebuilder/TypeChain.h>
10 #include <util/GlobalDefinitions.h>
11
12 #include <llvm/IR/Function.h>
13
14 namespace spice::compiler {
15
16 // Forward declarations
17 class ASTNode;
18 struct CodeLoc;
19 class SymbolTableEntry;
20 using TypeMapping = std::unordered_map</*typeName=*/std::string, /*concreteType=*/QualType>;
21
22 struct Param {
23 QualType qualType;
24 bool isOptional = false;
25 };
26 struct NamedParam {
27 const char *name = nullptr;
28 QualType qualType;
29 bool isOptional = false;
30 };
31 using ParamList = std::vector<Param>;
32 using NamedParamList = std::vector<NamedParam>;
33
34 class Function {
35 public:
36 // Constructors
37 Function(std::string name, SymbolTableEntry *entry, const QualType &thisType, const QualType &returnType, ParamList paramList,
38 std::vector<GenericType> templateTypes, ASTNode *declNode);
39
2/4
✓ Branch 3 → 4 taken 38 times.
✗ Branch 3 → 11 not taken.
✓ Branch 4 → 5 taken 38 times.
✗ Branch 4 → 11 not taken.
38 Function() = default;
40
41 // Public methods
42 [[nodiscard]] QualTypeList getParamTypes() const;
43 [[nodiscard]] std::string getSignature(bool withThisType = true, bool withTemplateTypes = true,
44 bool withTypeAliases = true) const;
45 [[nodiscard]] static std::string getSignature(const std::string &name, const QualType &thisType, const QualType &returnType,
46 const ParamList &paramList, const QualTypeList &concreteTemplateTypes,
47 bool withReturnType = true, bool withThisType = true, bool ignorePublic = true,
48 bool withTypeAliases = true);
49 [[nodiscard]] std::string getScopeName() const;
50 [[nodiscard]] std::string getMangledName() const;
51 [[nodiscard]] static std::string getSymbolTableEntryName(const std::string &functionName, const CodeLoc &codeLoc);
52 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultCtor(const CodeLoc &structCodeLoc);
53 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultCopyCtor(const CodeLoc &structCodeLoc);
54 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultDtor(const CodeLoc &structCodeLoc);
55
21/44
✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 158 not taken.
✓ Branch 11 → 12 taken 34076 times.
✗ Branch 11 → 55 not taken.
✗ Branch 11 → 102 not taken.
✗ Branch 11 → 157 not taken.
✓ Branch 12 → 13 taken 432 times.
✗ Branch 12 → 37 not taken.
✓ Branch 17 → 18 taken 7651 times.
✗ Branch 17 → 298 not taken.
✓ Branch 18 → 19 taken 7282 times.
✗ Branch 18 → 42 not taken.
✓ Branch 19 → 20 taken 3918 times.
✗ Branch 19 → 211 not taken.
✓ Branch 22 → 23 taken 32107 times.
✗ Branch 22 → 100 not taken.
✓ Branch 23 → 24 taken 99 times.
✗ Branch 23 → 192 not taken.
✓ Branch 26 → 27 taken 436 times.
✗ Branch 26 → 77 not taken.
✓ Branch 29 → 30 taken 206 times.
✗ Branch 29 → 115 not taken.
✓ Branch 34 → 35 taken 7651 times.
✗ Branch 34 → 294 not taken.
✓ Branch 36 → 37 taken 3918 times.
✗ Branch 36 → 207 not taken.
✓ Branch 40 → 41 taken 10 times.
✗ Branch 40 → 255 not taken.
✓ Branch 46 → 47 taken 3861 times.
✗ Branch 46 → 100 not taken.
✓ Branch 54 → 55 taken 4 times.
✗ Branch 54 → 156 not taken.
✓ Branch 56 → 57 taken 170 times.
✗ Branch 56 → 155 not taken.
✓ Branch 57 → 58 taken 28246 times.
✗ Branch 57 → 100 not taken.
✓ Branch 61 → 62 taken 206 times.
✗ Branch 61 → 113 not taken.
✓ Branch 88 → 89 taken 4 times.
✗ Branch 88 → 156 not taken.
✓ Branch 89 → 90 taken 170 times.
✗ Branch 89 → 155 not taken.
✓ Branch 101 → 102 taken 3049 times.
✗ Branch 101 → 188 not taken.
133500 [[nodiscard]] ALWAYS_INLINE bool isMethod() const { return !thisType.is(TY_DYN); }
56
8/16
✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 160 not taken.
✓ Branch 8 → 9 taken 432 times.
✗ Branch 8 → 37 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 58 not taken.
✓ Branch 14 → 15 taken 436 times.
✗ Branch 14 → 77 not taken.
✓ Branch 33 → 34 taken 1 time.
✗ Branch 33 → 164 not taken.
✓ Branch 36 → 37 taken 10 times.
✗ Branch 36 → 255 not taken.
✓ Branch 51 → 52 taken 3861 times.
✗ Branch 51 → 100 not taken.
✓ Branch 317 → 318 taken 17981 times.
✗ Branch 317 → 492 not taken.
22727 [[nodiscard]] ALWAYS_INLINE bool isFunction() const { return !returnType.is(TY_DYN); }
57
5/10
✓ Branch 4 → 5 taken 254 times.
✗ Branch 4 → 159 not taken.
✓ Branch 20 → 21 taken 206 times.
✗ Branch 20 → 115 not taken.
✓ Branch 69 → 70 taken 16 times.
✗ Branch 69 → 116 not taken.
✓ Branch 78 → 79 taken 863 times.
✗ Branch 78 → 125 not taken.
✓ Branch 333 → 334 taken 15485 times.
✗ Branch 333 → 508 not taken.
17747 [[nodiscard]] ALWAYS_INLINE bool isProcedure() const { return returnType.is(TY_DYN); }
58
4/8
✓ Branch 11 → 12 taken 432 times.
✗ Branch 11 → 17 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 432 times.
✓ Branch 39 → 40 taken 10 times.
✗ Branch 39 → 45 not taken.
✓ Branch 43 → 44 taken 10 times.
✗ Branch 43 → 45 not taken.
884 [[nodiscard]] ALWAYS_INLINE bool isNormalFunction() const { return isFunction() && !isMethod(); }
59 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isNormalProcedure() const { return isProcedure() && !isMethod(); }
60 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodFunction() const { return isFunction() && isMethod(); }
61 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodProcedure() const { return isProcedure() && isMethod(); }
62
3/4
✓ Branch 21 → 22 taken 7282 times.
✗ Branch 21 → 24 not taken.
✓ Branch 22 → 23 taken 1758 times.
✓ Branch 22 → 24 taken 5524 times.
7282 [[nodiscard]] ALWAYS_INLINE bool isVirtualMethod() const { return isMethod() && isVirtual; }
63 [[nodiscard]] bool hasSubstantiatedParams() const;
64 [[nodiscard]] bool hasSubstantiatedGenerics() const;
65 [[nodiscard]] bool isFullySubstantiated() const;
66 [[nodiscard]] bool isGenericSubstantiation() const;
67 [[nodiscard]] const CodeLoc &getDeclCodeLoc() const;
68
69 // Public members
70 std::string name;
71 QualType thisType = QualType(TY_DYN);
72 QualType returnType = QualType(TY_DYN);
73 ParamList paramList;
74 std::vector<GenericType> templateTypes;
75 TypeMapping typeMapping;
76 SymbolTableEntry *entry = nullptr;
77 ASTNode *declNode = nullptr;
78 Scope *bodyScope = nullptr;
79 std::string predefinedMangledName;
80 std::string mangleSuffix;
81 Function *genericPreset = nullptr;
82 bool isVararg = false;
83 bool mangleFunctionName = true;
84 bool alreadyTypeChecked = false;
85 bool used = false;
86 bool implicitDefault = false;
87 bool isVirtual = false;
88 llvm::Function *llvmFunction = nullptr;
89 size_t vtableIndex = 0;
90 };
91
92 } // namespace spice::compiler
93