GCC Code Coverage Report


Directory: ../
File: src/symboltablebuilder/TypeSpecifiers.h
Date: 2024-11-22 23:10:59
Exec Total Coverage
Lines: 3 3 100.0%
Functions: 2 2 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // Copyright (c) 2021-2024 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <cstdint>
6
7 namespace spice::compiler {
8
9 // Bit indices from right to left
10 static constexpr uint8_t BIT_INDEX_COMPOSITION = 0;
11 static constexpr uint8_t BIT_INDEX_INLINE = 1;
12 static constexpr uint8_t BIT_INDEX_PUBLIC = 2;
13 static constexpr uint8_t BIT_INDEX_HEAP = 3;
14 static constexpr uint8_t BIT_INDEX_UNSIGNED = 4;
15 static constexpr uint8_t BIT_INDEX_SIGNED = 5;
16 static constexpr uint8_t BIT_INDEX_CONST = 6;
17 static constexpr uint8_t BIT_INDEX_MAX = BIT_INDEX_CONST; // Please adjust if something changes above
18
19 class TypeSpecifiers {
20 public:
21 // Constructors
22 54793 TypeSpecifiers() = default;
23 8082448 TypeSpecifiers(bool isConst, bool isSigned, bool isUnsigned, bool isHeap)
24 8082448 : isConst(isConst), isSigned(isSigned), isUnsigned(isUnsigned), isHeap(isHeap) {}
25
26 // Public static methods
27 static TypeSpecifiers of(uint16_t superType);
28
29 // Public methods
30 [[nodiscard]] TypeSpecifiers merge(const TypeSpecifiers &other) const;
31 [[nodiscard]] bool match(TypeSpecifiers other, bool allowConstify) const;
32 void eraseWithMask(const TypeSpecifiers &mask);
33
34 // Overloaded operators
35 friend bool operator==(const TypeSpecifiers &lhs, const TypeSpecifiers &rhs);
36
37 // public members
38 // Note: Please adjust bit indices above, if something changes here
39 bool isConst : 1 = false;
40 bool isSigned : 1 = false;
41 bool isUnsigned : 1 = false;
42 bool isHeap : 1 = false;
43 bool isPublic : 1 = false;
44 bool isInline : 1 = false;
45 bool isComposition : 1 = false;
46
47 private:
48 // Private methods
49 [[nodiscard]] bool getBit(uint8_t index) const;
50 bool setBit(uint8_t index, bool value);
51 };
52
53 } // namespace spice::compiler
54