Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright (c) 2021-2024 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 |
|
|
public: |
52 |
|
|
// Constructors |
53 |
|
|
TypeChainElement() = default; |
54 |
|
7549074 |
explicit TypeChainElement(SuperType superType) : superType(superType), typeId(superType){}; |
55 |
|
1253 |
TypeChainElement(SuperType superType, std::string subType) |
56 |
|
1253 |
: superType(superType), subType(std::move(subType)), typeId(superType){}; |
57 |
|
200 |
TypeChainElement(SuperType superType, TypeChainElementData data) : superType(superType), typeId(superType), data(data){}; |
58 |
|
855 |
TypeChainElement(SuperType superType, std::string subType, uint64_t typeId, TypeChainElementData data, |
59 |
|
|
QualTypeList templateTypes) |
60 |
|
855 |
: 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) const; |
66 |
|
|
[[nodiscard]] std::string getName(bool withSize) 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 |
|
|
static_assert(sizeof(TypeChainElement) == 104); |
79 |
|
|
|
80 |
|
|
// Typedefs |
81 |
|
|
using TypeChain = std::vector<TypeChainElement>; |
82 |
|
|
|
83 |
|
|
} // namespace spice::compiler |
84 |
|
|
|
85 |
|
|
|