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 | using TypeMapping = std::unordered_map</*typeName=*/std::string, /*concreteType=*/QualType>; | ||
| 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 | Function(std::string name, SymbolTableEntry *entry, const QualType &thisType, const QualType &returnType, ParamList paramList, | ||
| 36 | std::vector<GenericType> templateTypes, ASTNode *declNode); | ||
| 37 |
2/4✓ Branch 3 → 4 taken 110 times.
✗ Branch 3 → 11 not taken.
✓ Branch 4 → 5 taken 110 times.
✗ Branch 4 → 11 not taken.
|
110 | Function() = default; |
| 38 | |||
| 39 | // Public methods | ||
| 40 | [[nodiscard]] QualTypeList getParamTypes() const; | ||
| 41 | [[nodiscard]] std::string getSignature(bool withThisType = true, bool withTemplateTypes = true, bool withTypeAliases = true, | ||
| 42 | bool withSize = false) const; | ||
| 43 | [[nodiscard]] static std::string getSignature(const std::string &name, const QualType &thisType, const QualType &returnType, | ||
| 44 | const ParamList ¶mList, const QualTypeList &concreteTemplateTypes, | ||
| 45 | bool withReturnType = true, bool withThisType = true, bool ignorePublic = true, | ||
| 46 | bool withTypeAliases = true, bool withSize = false); | ||
| 47 | [[nodiscard]] std::string getScopeName() const; | ||
| 48 | [[nodiscard]] std::string getMangledName() const; | ||
| 49 | [[nodiscard]] static std::string getSymbolTableEntryName(const std::string &functionName, const CodeLoc &codeLoc); | ||
| 50 | [[nodiscard]] static std::string getSymbolTableEntryNameDefaultCtor(const CodeLoc &structCodeLoc); | ||
| 51 | [[nodiscard]] static std::string getSymbolTableEntryNameDefaultCopyCtor(const CodeLoc &structCodeLoc); | ||
| 52 | [[nodiscard]] static std::string getSymbolTableEntryNameDefaultMoveCtor(const CodeLoc &structCodeLoc); | ||
| 53 | [[nodiscard]] static std::string getSymbolTableEntryNameDefaultDtor(const CodeLoc &structCodeLoc); | ||
| 54 |
20/43✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 166 not taken.
✓ Branch 11 → 12 taken 117081 times.
✗ Branch 11 → 55 not taken.
✗ Branch 11 → 115 not taken.
✗ Branch 11 → 165 not taken.
✓ Branch 13 → 14 taken 1801 times.
✗ Branch 13 → 53 not taken.
✓ Branch 18 → 19 taken 70619 times.
✗ Branch 18 → 42 not taken.
✗ Branch 18 → 304 not taken.
✓ Branch 20 → 21 taken 10963 times.
✗ Branch 20 → 217 not taken.
✓ Branch 22 → 23 taken 107372 times.
✗ Branch 22 → 113 not taken.
✓ Branch 23 → 24 taken 634 times.
✗ Branch 23 → 193 not taken.
✓ Branch 29 → 30 taken 227 times.
✗ Branch 29 → 123 not taken.
✓ Branch 34 → 35 taken 2235 times.
✗ Branch 34 → 85 not taken.
✓ Branch 35 → 36 taken 21857 times.
✗ Branch 35 → 300 not taken.
✓ Branch 37 → 38 taken 10963 times.
✗ Branch 37 → 213 not taken.
✓ Branch 42 → 43 taken 10 times.
✗ Branch 42 → 279 not taken.
✓ Branch 54 → 55 taken 8142 times.
✗ Branch 54 → 113 not taken.
✓ Branch 62 → 63 taken 4 times.
✗ Branch 62 → 164 not taken.
✓ Branch 64 → 65 taken 1034 times.
✗ Branch 64 → 163 not taken.
✓ Branch 65 → 66 taken 99230 times.
✗ Branch 65 → 113 not taken.
✓ Branch 69 → 70 taken 227 times.
✗ Branch 69 → 121 not taken.
✓ Branch 96 → 97 taken 4 times.
✗ Branch 96 → 164 not taken.
✓ Branch 97 → 98 taken 1034 times.
✗ Branch 97 → 163 not taken.
✓ Branch 104 → 105 taken 11056 times.
✗ Branch 104 → 197 not taken.
|
464497 | [[nodiscard]] ALWAYS_INLINE bool isMethod() const { return !thisType.is(TY_DYN); } |
| 55 |
8/16✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 168 not taken.
✓ Branch 9 → 10 taken 1801 times.
✗ Branch 9 → 53 not taken.
✓ Branch 13 → 14 taken 2 times.
✗ Branch 13 → 58 not taken.
✓ Branch 22 → 23 taken 2235 times.
✗ Branch 22 → 85 not taken.
✓ Branch 34 → 35 taken 1 time.
✗ Branch 34 → 164 not taken.
✓ Branch 38 → 39 taken 10 times.
✗ Branch 38 → 279 not taken.
✓ Branch 59 → 60 taken 8142 times.
✗ Branch 59 → 113 not taken.
✓ Branch 333 → 334 taken 53908 times.
✗ Branch 333 → 508 not taken.
|
66103 | [[nodiscard]] ALWAYS_INLINE bool isFunction() const { return !returnType.is(TY_DYN); } |
| 56 |
5/10✓ Branch 4 → 5 taken 3244 times.
✗ Branch 4 → 167 not taken.
✓ Branch 20 → 21 taken 227 times.
✗ Branch 20 → 123 not taken.
✓ Branch 77 → 78 taken 18 times.
✗ Branch 77 → 124 not taken.
✓ Branch 86 → 87 taken 5459 times.
✗ Branch 86 → 133 not taken.
✓ Branch 349 → 350 taken 43983 times.
✗ Branch 349 → 524 not taken.
|
58448 | [[nodiscard]] ALWAYS_INLINE bool isProcedure() const { return returnType.is(TY_DYN); } |
| 57 |
4/8✓ Branch 12 → 13 taken 1801 times.
✗ Branch 12 → 18 not taken.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 1801 times.
✓ Branch 41 → 42 taken 10 times.
✗ Branch 41 → 47 not taken.
✓ Branch 45 → 46 taken 10 times.
✗ Branch 45 → 47 not taken.
|
3622 | [[nodiscard]] ALWAYS_INLINE bool isNormalFunction() const { return isFunction() && !isMethod(); } |
| 58 | [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isNormalProcedure() const { return isProcedure() && !isMethod(); } | ||
| 59 | [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodFunction() const { return isFunction() && isMethod(); } | ||
| 60 | [[nodiscard]] [[maybe_unused]] ALWAYS_INLINE bool isMethodProcedure() const { return isProcedure() && isMethod(); } | ||
| 61 |
3/4✓ Branch 21 → 22 taken 48762 times.
✗ Branch 21 → 24 not taken.
✓ Branch 22 → 23 taken 12584 times.
✓ Branch 22 → 24 taken 36178 times.
|
48762 | [[nodiscard]] ALWAYS_INLINE bool isVirtualMethod() const { return isMethod() && isVirtual; } |
| 62 | [[nodiscard]] bool hasSubstantiatedParams() const; | ||
| 63 | [[nodiscard]] bool hasSubstantiatedGenerics() const; | ||
| 64 | [[nodiscard]] bool isFullySubstantiated() const; | ||
| 65 | [[nodiscard]] bool isGenericSubstantiation() const; | ||
| 66 | [[nodiscard]] const CodeLoc &getDeclCodeLoc() const; | ||
| 67 | |||
| 68 | // Public members | ||
| 69 | std::string name; | ||
| 70 | QualType thisType = QualType(TY_DYN); | ||
| 71 | QualType returnType = QualType(TY_DYN); | ||
| 72 | ParamList paramList; | ||
| 73 | std::vector<GenericType> templateTypes; | ||
| 74 | TypeMapping typeMapping; | ||
| 75 | SymbolTableEntry *entry = nullptr; | ||
| 76 | ASTNode *declNode = nullptr; | ||
| 77 | Scope *bodyScope = nullptr; | ||
| 78 | std::string predefinedMangledName; | ||
| 79 | std::string mangleSuffix; | ||
| 80 | Function *genericPreset = nullptr; | ||
| 81 | bool isVararg = false; | ||
| 82 | bool mangleFunctionName = true; | ||
| 83 | bool alreadyTypeChecked = false; | ||
| 84 | bool used = false; | ||
| 85 | bool implicitDefault = false; | ||
| 86 | bool isVirtual = false; | ||
| 87 | bool isNewlyInserted = false; | ||
| 88 | size_t vtableIndex = 0; | ||
| 89 | }; | ||
| 90 | |||
| 91 | } // namespace spice::compiler | ||
| 92 |