| 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 | 14271 | Function(std::string name, SymbolTableEntry *entry, const QualType &thisType, const QualType &returnType, ParamList paramList, | |
| 36 | std::vector<GenericType> templateTypes, ASTNode *declNode) | ||
| 37 | 14271 | : name(std::move(name)), thisType(thisType), returnType(returnType), paramList(std::move(paramList)), | |
| 38 | 14271 | templateTypes(std::move(templateTypes)), entry(entry), declNode(declNode) {} | |
| 39 |
2/4✓ Branch 3 → 4 taken 49 times.
✗ Branch 3 → 11 not taken.
✓ Branch 4 → 5 taken 49 times.
✗ Branch 4 → 11 not taken.
|
49 | 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 ¶mList, 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 → 153 not taken.
✓ Branch 11 → 12 taken 32882 times.
✗ Branch 11 → 55 not taken.
✗ Branch 11 → 102 not taken.
✗ Branch 11 → 152 not taken.
✓ Branch 12 → 13 taken 428 times.
✗ Branch 12 → 37 not taken.
✓ Branch 17 → 18 taken 7326 times.
✗ Branch 17 → 296 not taken.
✓ Branch 18 → 19 taken 7324 times.
✗ Branch 18 → 42 not taken.
✓ Branch 19 → 20 taken 3752 times.
✗ Branch 19 → 212 not taken.
✓ Branch 22 → 23 taken 30995 times.
✗ Branch 22 → 100 not taken.
✓ Branch 23 → 24 taken 99 times.
✗ Branch 23 → 181 not taken.
✓ Branch 26 → 27 taken 429 times.
✗ Branch 26 → 77 not taken.
✓ Branch 29 → 30 taken 206 times.
✗ Branch 29 → 115 not taken.
✓ Branch 34 → 35 taken 7326 times.
✗ Branch 34 → 292 not taken.
✓ Branch 36 → 37 taken 3752 times.
✗ Branch 36 → 208 not taken.
✓ Branch 40 → 41 taken 10 times.
✗ Branch 40 → 255 not taken.
✓ Branch 46 → 47 taken 3742 times.
✗ Branch 46 → 100 not taken.
✓ Branch 49 → 50 taken 4 times.
✗ Branch 49 → 151 not taken.
✓ Branch 51 → 52 taken 169 times.
✗ Branch 51 → 150 not taken.
✓ Branch 57 → 58 taken 27253 times.
✗ Branch 57 → 100 not taken.
✓ Branch 61 → 62 taken 206 times.
✗ Branch 61 → 113 not taken.
✓ Branch 83 → 84 taken 4 times.
✗ Branch 83 → 151 not taken.
✓ Branch 84 → 85 taken 169 times.
✗ Branch 84 → 150 not taken.
✓ Branch 100 → 101 taken 2986 times.
✗ Branch 100 → 169 not taken.
|
129066 | [[nodiscard]] ALWAYS_INLINE bool isMethod() const { return !thisType.is(TY_DYN); } |
| 56 |
8/16✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 155 not taken.
✓ Branch 8 → 9 taken 428 times.
✗ Branch 8 → 37 not taken.
✓ Branch 13 → 14 taken 3 times.
✗ Branch 13 → 58 not taken.
✓ Branch 14 → 15 taken 429 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 3742 times.
✗ Branch 51 → 100 not taken.
✓ Branch 309 → 310 taken 17389 times.
✗ Branch 309 → 486 not taken.
|
22006 | [[nodiscard]] ALWAYS_INLINE bool isFunction() const { return !returnType.is(TY_DYN); } |
| 57 |
5/10✓ Branch 4 → 5 taken 249 times.
✗ Branch 4 → 154 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 846 times.
✗ Branch 78 → 125 not taken.
✓ Branch 325 → 326 taken 14951 times.
✗ Branch 325 → 502 not taken.
|
17170 | [[nodiscard]] ALWAYS_INLINE bool isProcedure() const { return returnType.is(TY_DYN); } |
| 58 |
4/8✓ Branch 11 → 12 taken 428 times.
✗ Branch 11 → 17 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 428 times.
✓ Branch 39 → 40 taken 10 times.
✗ Branch 39 → 45 not taken.
✓ Branch 43 → 44 taken 10 times.
✗ Branch 43 → 45 not taken.
|
876 | [[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 7324 times.
✗ Branch 21 → 24 not taken.
✓ Branch 22 → 23 taken 1734 times.
✓ Branch 22 → 24 taken 5590 times.
|
7324 | [[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 |