| 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 | 13220 | Function(std::string name, SymbolTableEntry *entry, const QualType &thisType, const QualType &returnType, ParamList paramList, | |
| 36 | std::vector<GenericType> templateTypes, ASTNode *declNode) | ||
| 37 | 13220 | : name(std::move(name)), thisType(thisType), returnType(returnType), paramList(std::move(paramList)), | |
| 38 | 13220 | templateTypes(std::move(templateTypes)), entry(entry), declNode(declNode) {} | |
| 39 |
2/4✓ Branch 3 → 4 taken 41 times.
✗ Branch 3 → 11 not taken.
✓ Branch 4 → 5 taken 41 times.
✗ Branch 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 withTemplateTypes = true) const; | ||
| 44 | [[nodiscard]] static std::string getSignature(const std::string &name, const QualType &thisType, const QualType &returnType, | ||
| 45 | const ParamList ¶mList, 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 |
23/48✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 153 not taken.
✓ Branch 11 → 12 taken 28998 times.
✗ Branch 11 → 55 not taken.
✗ Branch 11 → 102 not taken.
✗ Branch 11 → 152 not taken.
✓ Branch 12 → 13 taken 404 times.
✗ Branch 12 → 37 not taken.
✓ Branch 17 → 18 taken 6892 times.
✗ Branch 17 → 328 not taken.
✓ Branch 18 → 19 taken 6902 times.
✗ Branch 18 → 42 not taken.
✓ Branch 19 → 20 taken 2827 times.
✗ Branch 19 → 244 not taken.
✓ Branch 22 → 23 taken 27198 times.
✗ Branch 22 → 100 not taken.
✓ Branch 23 → 24 taken 95 times.
✗ Branch 23 → 181 not taken.
✓ Branch 26 → 27 taken 408 times.
✗ Branch 26 → 77 not taken.
✓ Branch 29 → 30 taken 192 times.
✗ Branch 29 → 115 not taken.
✓ Branch 36 → 37 taken 6892 times.
✗ Branch 36 → 324 not taken.
✓ Branch 38 → 39 taken 2827 times.
✗ Branch 38 → 240 not taken.
✓ Branch 46 → 47 taken 1617 times.
✗ Branch 46 → 100 not taken.
✓ Branch 47 → 48 taken 8 times.
✗ Branch 47 → 277 not taken.
✓ Branch 49 → 50 taken 2 times.
✗ Branch 49 → 151 not taken.
✓ Branch 51 → 52 taken 164 times.
✗ Branch 51 → 150 not taken.
✓ Branch 57 → 58 taken 25581 times.
✗ Branch 57 → 100 not taken.
✓ Branch 61 → 62 taken 192 times.
✗ Branch 61 → 113 not taken.
✓ Branch 83 → 84 taken 2 times.
✗ Branch 83 → 151 not taken.
✓ Branch 84 → 85 taken 164 times.
✗ Branch 84 → 150 not taken.
✓ Branch 100 → 101 taken 2212 times.
✗ Branch 100 → 169 not taken.
✓ Branch 109 → 110 taken 2827 times.
✗ Branch 109 → 238 not taken.
✓ Branch 128 → 129 taken 6892 times.
✗ Branch 128 → 322 not taken.
|
123298 | [[nodiscard]] ALWAYS_INLINE bool isMethod() const { return !thisType.is(TY_DYN); } |
| 53 |
8/16✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 155 not taken.
✓ Branch 8 → 9 taken 404 times.
✗ Branch 8 → 37 not taken.
✓ Branch 13 → 14 taken 3 times.
✗ Branch 13 → 53 not taken.
✓ Branch 14 → 15 taken 408 times.
✗ Branch 14 → 77 not taken.
✓ Branch 33 → 34 taken 1 time.
✗ Branch 33 → 165 not taken.
✓ Branch 43 → 44 taken 8 times.
✗ Branch 43 → 277 not taken.
✓ Branch 51 → 52 taken 1617 times.
✗ Branch 51 → 100 not taken.
✓ Branch 309 → 310 taken 15094 times.
✗ Branch 309 → 486 not taken.
|
17537 | [[nodiscard]] ALWAYS_INLINE bool isFunction() const { return !returnType.is(TY_DYN); } |
| 54 |
5/10✓ Branch 4 → 5 taken 238 times.
✗ Branch 4 → 154 not taken.
✓ Branch 20 → 21 taken 192 times.
✗ Branch 20 → 115 not taken.
✓ Branch 69 → 70 taken 16 times.
✗ Branch 69 → 116 not taken.
✓ Branch 78 → 79 taken 813 times.
✗ Branch 78 → 125 not taken.
✓ Branch 325 → 326 taken 12788 times.
✗ Branch 325 → 502 not taken.
|
14916 | [[nodiscard]] ALWAYS_INLINE bool isProcedure() const { return returnType.is(TY_DYN); } |
| 55 |
4/8✓ Branch 11 → 12 taken 404 times.
✗ Branch 11 → 17 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 404 times.
✓ Branch 46 → 47 taken 8 times.
✗ Branch 46 → 52 not taken.
✓ Branch 50 → 51 taken 8 times.
✗ Branch 50 → 52 not taken.
|
824 | [[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 21 → 22 taken 6902 times.
✗ Branch 21 → 24 not taken.
✓ Branch 22 → 23 taken 1650 times.
✓ Branch 22 → 24 taken 5252 times.
|
6902 | [[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 isVararg = false; | ||
| 80 | bool mangleFunctionName = true; | ||
| 81 | bool alreadyTypeChecked = false; | ||
| 82 | bool used = false; | ||
| 83 | bool implicitDefault = false; | ||
| 84 | bool isVirtual = false; | ||
| 85 | llvm::Function *llvmFunction = nullptr; | ||
| 86 | size_t vtableIndex = 0; | ||
| 87 | }; | ||
| 88 | |||
| 89 | } // namespace spice::compiler | ||
| 90 |