GCC Code Coverage Report


Directory: ../
File: src/symboltablebuilder/TypeChain.h
Date: 2025-06-14 23:29:02
Exec Total Coverage
Lines: 6 6 100.0%
Functions: 4 4 100.0%
Branches: 0 0 -%

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