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: 49.4% 41 / 0 / 83

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 namespace spice::compiler {
13
14 // Forward declarations
15 class ASTNode;
16 struct CodeLoc;
17 class SymbolTableEntry;
18
19 struct Param {
20 QualType qualType;
21 bool isOptional = false;
22 };
23 struct NamedParam {
24 const char *name = nullptr;
25 QualType qualType;
26 bool isOptional = false;
27 };
28 using ParamList = std::vector<Param>;
29 using NamedParamList = std::vector<NamedParam>;
30
31 class Function {
32 public:
33 // Constructors
34 Function(std::string name, SymbolTableEntry *entry, const QualType &thisType, const QualType &returnType, ParamList paramList,
35 std::vector<GenericType> templateTypes, ASTNode *declNode);
36
2/4
✓ Branch 3 → 4 taken 142 times.
✗ Branch 3 → 11 not taken.
✓ Branch 4 → 5 taken 142 times.
✗ Branch 4 → 11 not taken.
142 Function() = default;
37
38 // Public methods
39 [[nodiscard]] QualTypeList getParamTypes() const;
40 [[nodiscard]] std::string getSignature(bool withThisType = true, bool withTemplateTypes = true, bool withTypeAliases = true,
41 bool withSize = false) const;
42 [[nodiscard]] static std::string getSignature(const std::string &name, const QualType &thisType, const QualType &returnType,
43 const ParamList &paramList, const QualTypeList &concreteTemplateTypes,
44 bool withReturnType = true, bool withThisType = true, bool ignorePublic = true,
45 bool withTypeAliases = true, bool withSize = false);
46 [[nodiscard]] std::string getScopeName() const;
47 [[nodiscard]] std::string getMangledName() const;
48 [[nodiscard]] static std::string getSymbolTableEntryName(const std::string &functionName, const CodeLoc &codeLoc);
49 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultCtor(const CodeLoc &structCodeLoc);
50 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultCopyCtor(const CodeLoc &structCodeLoc);
51 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultMoveCtor(const CodeLoc &structCodeLoc);
52 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultDtor(const CodeLoc &structCodeLoc);
53
18/41
✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 159 not taken.
✓ Branch 11 → 12 taken 138877 times.
✗ Branch 11 → 55 not taken.
✗ Branch 11 → 115 not taken.
✗ Branch 11 → 157 not taken.
✓ Branch 13 → 14 taken 2519 times.
✗ Branch 13 → 53 not taken.
✓ Branch 18 → 19 taken 77180 times.
✗ Branch 18 → 42 not taken.
✗ Branch 18 → 305 not taken.
✓ Branch 20 → 21 taken 14075 times.
✗ Branch 20 → 220 not taken.
✓ Branch 22 → 23 taken 127539 times.
✗ Branch 22 → 113 not taken.
✗ Branch 22 → 194 not taken.
✓ Branch 29 → 30 taken 862 times.
✗ Branch 29 → 123 not taken.
✓ Branch 34 → 35 taken 2702 times.
✗ Branch 34 → 85 not taken.
✓ Branch 35 → 36 taken 24950 times.
✗ Branch 35 → 301 not taken.
✓ Branch 37 → 38 taken 14075 times.
✗ Branch 37 → 216 not taken.
✓ Branch 42 → 43 taken 10 times.
✗ Branch 42 → 279 not taken.
✓ Branch 54 → 55 taken 10997 times.
✗ Branch 54 → 113 not taken.
✓ Branch 55 → 56 taken 4 times.
✗ Branch 55 → 157 not taken.
✓ Branch 57 → 58 taken 925 times.
✗ Branch 57 → 155 not taken.
✓ Branch 65 → 66 taken 116094 times.
✗ Branch 65 → 113 not taken.
✓ Branch 69 → 70 taken 862 times.
✗ Branch 69 → 121 not taken.
✓ Branch 90 → 91 taken 929 times.
✗ Branch 90 → 155 not taken.
✗ Branch 90 → 157 not taken.
✓ Branch 105 → 106 taken 12853 times.
✗ Branch 105 → 197 not taken.
545457 [[nodiscard]] ALWAYS_INLINE bool isMethod() const { return !thisType.is(TY_DYN); }
54
8/16
✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 161 not taken.
✓ Branch 9 → 10 taken 3173 times.
✗ Branch 9 → 53 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 58 not taken.
✓ Branch 22 → 23 taken 2702 times.
✗ Branch 22 → 85 not taken.
✓ Branch 34 → 35 taken 1 time.
✗ Branch 34 → 169 not taken.
✓ Branch 38 → 39 taken 10 times.
✗ Branch 38 → 279 not taken.
✓ Branch 59 → 60 taken 10997 times.
✗ Branch 59 → 113 not taken.
✓ Branch 333 → 334 taken 64552 times.
✗ Branch 333 → 508 not taken.
81441 [[nodiscard]] ALWAYS_INLINE bool isFunction() const { return !returnType.is(TY_DYN); }
55
5/10
✓ Branch 4 → 5 taken 3817 times.
✗ Branch 4 → 159 not taken.
✓ Branch 20 → 21 taken 862 times.
✗ Branch 20 → 123 not taken.
✓ Branch 86 → 87 taken 18 times.
✗ Branch 86 → 133 not taken.
✓ Branch 95 → 96 taken 6138 times.
✗ Branch 95 → 142 not taken.
✓ Branch 349 → 350 taken 54733 times.
✗ Branch 349 → 524 not taken.
71765 [[nodiscard]] ALWAYS_INLINE bool isProcedure() const { return returnType.is(TY_DYN); }
56
5/8
✓ Branch 12 → 13 taken 2519 times.
✓ Branch 12 → 18 taken 654 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 2519 times.
✓ Branch 41 → 42 taken 10 times.
✗ Branch 41 → 47 not taken.
✓ Branch 45 → 46 taken 10 times.
✗ Branch 45 → 47 not taken.
5712 [[nodiscard]] ALWAYS_INLINE bool isNormalFunction() const { return isFunction() && !isMethod(); }
57 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isNormalProcedure() const { return isProcedure() && !isMethod(); }
58 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodFunction() const { return isFunction() && isMethod(); }
59 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodProcedure() const { return isProcedure() && isMethod(); }
60
3/4
✓ Branch 21 → 22 taken 52230 times.
✗ Branch 21 → 24 not taken.
✓ Branch 22 → 23 taken 14692 times.
✓ Branch 22 → 24 taken 37538 times.
52230 [[nodiscard]] ALWAYS_INLINE bool isVirtualMethod() const { return isMethod() && isVirtual; }
61 [[nodiscard]] bool hasSubstantiatedParams() const;
62 [[nodiscard]] bool hasSubstantiatedGenerics() const;
63 [[nodiscard]] bool isFullySubstantiated() const;
64 [[nodiscard]] bool isGenericSubstantiation() const;
65 [[nodiscard]] const CodeLoc &getDeclCodeLoc() const;
66
67 // Public members
68 std::string name;
69 QualType thisType = QualType(TY_DYN);
70 QualType returnType = QualType(TY_DYN);
71 ParamList paramList;
72 std::vector<GenericType> templateTypes;
73 TypeMapping typeMapping;
74 SymbolTableEntry *entry = nullptr;
75 ASTNode *declNode = nullptr;
76 Scope *bodyScope = nullptr;
77 std::string predefinedMangledName;
78 std::string mangleSuffix;
79 Function *genericPreset = nullptr;
80 bool isVararg = false;
81 bool mangleFunctionName = true;
82 bool alreadyTypeChecked = false;
83 bool used = false;
84 bool implicitDefault = false;
85 bool isVirtual = false;
86 bool isNewlyInserted = false;
87 size_t vtableIndex = 0;
88 };
89
90 } // namespace spice::compiler
91