GCC Code Coverage Report


Directory: ../
File: src/symboltablebuilder/TypeQualifiers.h
Date: 2025-02-05 01:09:36
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 2 2 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 <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 TypeQualifiers {
20 public:
21 // Constructors
22 93543 TypeQualifiers() = default;
23 4093517 TypeQualifiers(bool isConst, bool isSigned, bool isUnsigned) : isConst(isConst), isSigned(isSigned), isUnsigned(isUnsigned) {}
24
25 // Public static methods
26 static TypeQualifiers of(uint16_t superType);
27
28 // Public methods
29 [[nodiscard]] TypeQualifiers merge(const TypeQualifiers &other) const;
30 [[nodiscard]] bool match(TypeQualifiers other, bool allowConstify) const;
31 void eraseWithMask(const TypeQualifiers &mask);
32
33 // Overloaded operators
34 friend bool operator==(const TypeQualifiers &lhs, const TypeQualifiers &rhs);
35
36 // public members
37 // Note: Please adjust bit indices above, if something changes here
38 bool isConst : 1 = false;
39 bool isSigned : 1 = false;
40 bool isUnsigned : 1 = false;
41 bool isHeap : 1 = false;
42 bool isPublic : 1 = false;
43 bool isInline : 1 = false;
44 bool isComposition : 1 = false;
45
46 private:
47 // Private methods
48 [[nodiscard]] bool getBit(uint8_t index) const;
49 bool setBit(uint8_t index, bool value);
50 };
51
52 } // namespace spice::compiler
53