GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 6 / 0 / 6
Functions: 100.0% 4 / 0 / 4
Branches: -% 0 / 0 / 0

src/symboltablebuilder/TypeChain.h
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <cstdint>
6 #include <string>
7 #include <vector>
8
9 #include <symboltablebuilder/QualType.h>
10
11 namespace spice::compiler {
12
13 // Forward declarations
14 class Scope;
15
16 // Constants
17 static constexpr long ARRAY_SIZE_UNKNOWN = 0;
18
19 enum SuperType : uint8_t {
20 TY_INVALID,
21 TY_UNRESOLVED,
22 TY_DOUBLE,
23 TY_INT,
24 TY_SHORT,
25 TY_LONG,
26 TY_BYTE,
27 TY_CHAR,
28 TY_STRING, // Alias for 'const char*'
29 TY_BOOL,
30 TY_STRUCT,
31 TY_INTERFACE,
32 TY_ENUM,
33 TY_GENERIC,
34 TY_ALIAS,
35 TY_DYN,
36 TY_PTR,
37 TY_REF,
38 TY_ARRAY,
39 TY_FUNCTION,
40 TY_PROCEDURE,
41 TY_IMPORT,
42 };
43
44 union TypeChainElementData {
45 unsigned int arraySize; // TY_ARRAY
46 Scope *bodyScope = nullptr; // TY_STRUCT, TY_INTERFACE, TY_ENUM
47 bool hasCaptures; // TY_FUNCTION, TY_PROCEDURE (lambdas)
48 };
49
50 // Structs
51 struct TypeChainElement {
52 // Constructors
53 TypeChainElement() = default;
54 5442160 explicit TypeChainElement(SuperType superType) : superType(superType), typeId(superType) {}
55 1869 TypeChainElement(SuperType superType, std::string subType)
56 1869 : superType(superType), subType(std::move(subType)), typeId(superType) {}
57 226 TypeChainElement(SuperType superType, TypeChainElementData data) : superType(superType), typeId(superType), data(data) {}
58 1204 TypeChainElement(SuperType superType, std::string subType, uint64_t typeId, TypeChainElementData data,
59 QualTypeList templateTypes)
60 1204 : superType(superType), subType(std::move(subType)), typeId(typeId), data(data), templateTypes(std::move(templateTypes)) {}
61
62 // Overloaded operators
63 friend bool operator==(const TypeChainElement &lhs, const TypeChainElement &rhs);
64 friend bool operator!=(const TypeChainElement &lhs, const TypeChainElement &rhs);
65 void getName(std::stringstream &name, bool withSize, bool ignorePublic, bool withAliases) const;
66 [[nodiscard]] std::string getName(bool withSize, bool ignorePublic, bool withAliases) const;
67
68 // Public members
69 SuperType superType = TY_INVALID;
70 std::string subType;
71 uint64_t typeId = TY_INVALID;
72 TypeChainElementData data = {.arraySize = 0};
73 QualTypeList templateTypes;
74 QualTypeList paramTypes; // First type is the return type
75 };
76
77 // Make sure we have no unexpected increases in memory consumption
78 #if defined(__clang__) && defined(__apple_build_version__)
79 // std::string for Apple Clang is smaller than std::string for GCC and Clang
80 static_assert(sizeof(TypeChainElement) == 96);
81 #else
82 static_assert(sizeof(TypeChainElement) == 104);
83 #endif
84
85 // Typedefs
86 using TypeChain = std::vector<TypeChainElement>;
87
88 } // namespace spice::compiler
89