GCC Code Coverage Report


Directory: ../
File: src/model/Function.h
Date: 2024-12-24 01:17:15
Exec Total Coverage
Lines: 9 9 100.0%
Functions: 2 2 100.0%
Branches: 19 34 55.9%

Line Branch Exec Source
1 // Copyright (c) 2021-2024 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <utility>
6
7 #include <model/GenericType.h>
8 #include <symboltablebuilder/Type.h>
9 #include <util/GlobalDefinitions.h>
10
11 #include <llvm/IR/Function.h>
12
13 namespace spice::compiler {
14
15 // Forward declarations
16 class ASTNode;
17 struct CodeLoc;
18 class SymbolTableEntry;
19
20 struct Param {
21 QualType qualType;
22 bool isOptional = false;
23 };
24 struct NamedParam {
25 const char *name = nullptr;
26 QualType qualType;
27 bool isOptional = false;
28 };
29 using ParamList = std::vector<Param>;
30 using NamedParamList = std::vector<NamedParam>;
31
32 class Function {
33 public:
34 // Constructors
35 8311 Function(std::string name, SymbolTableEntry *entry, const QualType &thisType, const QualType &returnType, ParamList paramList,
36 std::vector<GenericType> templateTypes, ASTNode *declNode)
37 8311 : name(std::move(name)), thisType(thisType), returnType(returnType), paramList(std::move(paramList)),
38 8311 templateTypes(std::move(templateTypes)), entry(entry), declNode(declNode) {}
39
2/4
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 38 times.
✗ Branch 6 not taken.
38 Function() = default;
40
41 // Public methods
42 [[nodiscard]] QualTypeList getParamTypes() const;
43 [[nodiscard]] std::string getSignature(bool withThisType = true, bool ignorePublic = true) const;
44 [[nodiscard]] static std::string getSignature(const std::string &name, const QualType &thisType, const QualType &returnType,
45 const ParamList &paramList, const QualTypeList &concreteTemplateTypes,
46 bool withReturnType = true, bool withThisType = true, bool ignorePublic = true);
47 [[nodiscard]] std::string getMangledName() const;
48 [[nodiscard]] static std::string getSymbolTableEntryName(const std::string &functionName, const CodeLoc &codeLoc);
49
7/14
✓ Branch 1 taken 25078 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18620 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3142 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 19267 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 3790 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 3790 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
73689 [[nodiscard]] ALWAYS_INLINE bool isMethod() const { return !thisType.is(TY_DYN); }
50
2/4
✓ Branch 1 taken 11153 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
11155 [[nodiscard]] ALWAYS_INLINE bool isFunction() const { return !returnType.is(TY_DYN); }
51
2/4
✓ Branch 1 taken 8945 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 516 times.
✗ Branch 5 not taken.
10024 [[nodiscard]] ALWAYS_INLINE bool isProcedure() const { return returnType.is(TY_DYN); }
52
3/4
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 260 times.
536 [[nodiscard]] ALWAYS_INLINE bool isNormalFunction() const { return isFunction() && !isMethod(); }
53 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isNormalProcedure() const { return isProcedure() && !isMethod(); }
54 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodFunction() const { return isFunction() && isMethod(); }
55 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodProcedure() const { return isProcedure() && isMethod(); }
56
3/4
✓ Branch 0 taken 4774 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1104 times.
✓ Branch 3 taken 3670 times.
4774 [[nodiscard]] ALWAYS_INLINE bool isVirtualMethod() const { return isMethod() && isVirtual; }
57 [[nodiscard]] bool hasSubstantiatedParams() const;
58 [[nodiscard]] bool hasSubstantiatedGenerics() const;
59 [[nodiscard]] bool isFullySubstantiated() const;
60 [[nodiscard]] bool isGenericSubstantiation() const;
61 [[nodiscard]] const CodeLoc &getDeclCodeLoc() const;
62
63 // Public members
64 std::string name;
65 QualType thisType = QualType(TY_DYN);
66 QualType returnType = QualType(TY_DYN);
67 ParamList paramList;
68 std::vector<GenericType> templateTypes;
69 TypeMapping typeMapping;
70 SymbolTableEntry *entry = nullptr;
71 ASTNode *declNode = nullptr;
72 Scope *bodyScope = nullptr;
73 std::string predefinedMangledName;
74 std::string mangleSuffix;
75 Function *genericPreset = nullptr;
76 bool mangleFunctionName = true;
77 bool alreadyTypeChecked = false;
78 bool used = false;
79 bool implicitDefault = false;
80 bool isVirtual = false;
81 llvm::Function *llvmFunction = nullptr;
82 size_t vtableIndex = 0;
83 };
84
85 } // namespace spice::compiler
86