GCC Code Coverage Report


Directory: ../
File: src/model/Function.h
Date: 2025-02-05 01:09:36
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-2025 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 10502 Function(std::string name, SymbolTableEntry *entry, const QualType &thisType, const QualType &returnType, ParamList paramList,
36 std::vector<GenericType> templateTypes, ASTNode *declNode)
37 10502 : name(std::move(name)), thisType(thisType), returnType(returnType), paramList(std::move(paramList)),
38 10502 templateTypes(std::move(templateTypes)), entry(entry), declNode(declNode) {}
39
2/4
✓ Branch 0 (3→4) taken 41 times.
✗ Branch 1 (3→11) not taken.
✓ Branch 2 (4→5) taken 41 times.
✗ Branch 3 (4→11) not taken.
41 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 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultCtor(const CodeLoc &structCodeLoc);
50 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultCopyCtor(const CodeLoc &structCodeLoc);
51 [[nodiscard]] static std::string getSymbolTableEntryNameDefaultDtor(const CodeLoc &structCodeLoc);
52
7/14
✓ Branch 0 (47→48) taken 31748 times.
✗ Branch 1 (47→277) not taken.
✓ Branch 2 (11→12) taken 24533 times.
✗ Branch 3 (11→152) not taken.
✓ Branch 4 (51→52) taken 3804 times.
✗ Branch 5 (51→150) not taken.
✓ Branch 6 (84→85) taken 26157 times.
✗ Branch 7 (84→150) not taken.
✓ Branch 8 (10→11) taken 5462 times.
✗ Branch 9 (10→153) not taken.
✓ Branch 10 (49→50) taken 5462 times.
✗ Branch 11 (49→151) not taken.
✓ Branch 12 (83→84) taken 2 times.
✗ Branch 13 (83→151) not taken.
97168 [[nodiscard]] ALWAYS_INLINE bool isMethod() const { return !thisType.is(TY_DYN); }
53
2/4
✓ Branch 0 (43→44) taken 14570 times.
✗ Branch 1 (43→277) not taken.
✓ Branch 2 (2→3) taken 2 times.
✗ Branch 3 (2→155) not taken.
14572 [[nodiscard]] ALWAYS_INLINE bool isFunction() const { return !returnType.is(TY_DYN); }
54
2/4
✓ Branch 0 (69→70) taken 11449 times.
✗ Branch 1 (69→116) not taken.
✓ Branch 2 (78→79) taken 687 times.
✗ Branch 3 (78→125) not taken.
12879 [[nodiscard]] ALWAYS_INLINE bool isProcedure() const { return returnType.is(TY_DYN); }
55
3/4
✓ Branch 0 (46→47) taken 289 times.
✗ Branch 1 (46→52) not taken.
✓ Branch 2 (50→51) taken 8 times.
✓ Branch 3 (50→52) taken 281 times.
578 [[nodiscard]] ALWAYS_INLINE bool isNormalFunction() const { return isFunction() && !isMethod(); }
56 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isNormalProcedure() const { return isProcedure() && !isMethod(); }
57 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodFunction() const { return isFunction() && isMethod(); }
58 [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodProcedure() const { return isProcedure() && isMethod(); }
59
3/4
✓ Branch 0 (21→22) taken 5286 times.
✗ Branch 1 (21→24) not taken.
✓ Branch 2 (22→23) taken 1220 times.
✓ Branch 3 (22→24) taken 4066 times.
5286 [[nodiscard]] ALWAYS_INLINE bool isVirtualMethod() const { return isMethod() && isVirtual; }
60 [[nodiscard]] bool hasSubstantiatedParams() const;
61 [[nodiscard]] bool hasSubstantiatedGenerics() const;
62 [[nodiscard]] bool isFullySubstantiated() const;
63 [[nodiscard]] bool isGenericSubstantiation() const;
64 [[nodiscard]] const CodeLoc &getDeclCodeLoc() const;
65
66 // Public members
67 std::string name;
68 QualType thisType = QualType(TY_DYN);
69 QualType returnType = QualType(TY_DYN);
70 ParamList paramList;
71 std::vector<GenericType> templateTypes;
72 TypeMapping typeMapping;
73 SymbolTableEntry *entry = nullptr;
74 ASTNode *declNode = nullptr;
75 Scope *bodyScope = nullptr;
76 std::string predefinedMangledName;
77 std::string mangleSuffix;
78 Function *genericPreset = nullptr;
79 bool mangleFunctionName = true;
80 bool alreadyTypeChecked = false;
81 bool used = false;
82 bool implicitDefault = false;
83 bool isVirtual = false;
84 llvm::Function *llvmFunction = nullptr;
85 size_t vtableIndex = 0;
86 };
87
88 } // namespace spice::compiler
89