summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-base-type-info.h
blob: bad70c6faaf547aced92ce5828aea450c4e765e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// slang-base-type-info.h
#pragma once

//
// This file defines the `BaseTypeInfo` type, which encodes
// information (such as size in bits) about the base types
// supported by the Slang language. That information is used
// for things like checking if a literal is in the representible
// range of a given type, and for determining the relative
// cost of implicit conversions between the base types.
//

#include "../core/slang-basic.h"
#include "slang-type-system-shared.h"

namespace Slang
{

// Information about BaseType that's useful for checking literals
struct BaseTypeInfo
{
    typedef uint8_t Flags;
    struct Flag
    {
        enum Enum : Flags
        {
            Signed = 0x1,
            FloatingPoint = 0x2,
            Integer = 0x4,
        };
    };

    SLANG_FORCE_INLINE static const BaseTypeInfo& getInfo(BaseType baseType)
    {
        return s_info[Index(baseType)];
    }

    static UnownedStringSlice asText(BaseType baseType);

    uint8_t sizeInBytes; ///< Size of type in bytes
    Flags flags;
    uint8_t baseType;

    static bool check();

private:
    static const BaseTypeInfo s_info[Index(BaseType::CountOfPrimitives)];
};

} // namespace Slang