yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Lauro OyenMove c++ parsing code from slang-cpp-extractor to static library (#5675)eaa8dcfcc

master
2.4 KiB121 linesraw
1#pragma once
2
3#include "diagnostics.h"
4
5namespace CppParse
6{
7using namespace Slang;
8
9enum class IdentifierStyle
10{
11    None, ///< It's not an identifier
12
13    Identifier, ///< Just an identifier
14
15    PreDeclare, ///< Declare a type (not visible in C++ code)
16    TypeSet,    ///< TypeSet
17
18    TypeModifier, ///< const, volatile etc
19    Keyword,      ///< A keyword C/C++ keyword that is not another type
20
21    Class,     ///< class
22    Struct,    ///< struct
23    Namespace, ///< namespace
24    Enum,      ///< enum
25
26    TypeDef, ///< typedef
27
28    Access, ///< public, protected, private
29
30    Reflected,
31    Unreflected,
32
33    CallingConvention, ///< Used on a method
34    Virtual,           ///<
35
36    Template,
37
38    Static,
39
40    IntegerModifier,
41
42    Extern,
43
44    CallableMisc, ///< For SLANG_NO_THROW etc
45
46    IntegerType, ///< Built in integer type
47
48    Default, /// default
49
50    CountOf,
51};
52
53typedef uint32_t IdentifierFlags;
54struct IdentifierFlag
55{
56    enum Enum : IdentifierFlags
57    {
58        StartScope = 0x1, ///< namespace, struct or class
59        ClassLike = 0x2,  ///< Struct or class
60        Keyword = 0x4,
61        Reflection = 0x8,
62    };
63};
64
65
66class IdentifierLookup
67{
68public:
69    struct Pair
70    {
71        const char* name;
72        IdentifierStyle style;
73    };
74
75    IdentifierStyle get(const UnownedStringSlice& slice) const
76    {
77        Index index = m_pool.findIndex(slice);
78        return (index >= 0) ? m_styles[index] : IdentifierStyle::None;
79    }
80
81    void set(const char* name, IdentifierStyle style) { set(UnownedStringSlice(name), style); }
82
83    void set(const UnownedStringSlice& name, IdentifierStyle style);
84
85    void set(const char* const* names, size_t namesCount, IdentifierStyle style);
86
87    void set(const Pair* pairs, Index pairsCount);
88
89    void reset()
90    {
91        m_styles.clear();
92        m_pool.clear();
93    }
94
95    void initDefault(const UnownedStringSlice& markPrefix);
96
97    IdentifierLookup()
98        : m_pool(StringSlicePool::Style::Empty)
99    {
100        SLANG_ASSERT(m_pool.getSlicesCount() == 0);
101    }
102
103    static const IdentifierFlags kIdentifierFlags[Index(IdentifierStyle::CountOf)];
104
105protected:
106    List<IdentifierStyle> m_styles;
107    StringSlicePool m_pool;
108};
109
110
111SLANG_FORCE_INLINE IdentifierFlags getFlags(IdentifierStyle style)
112{
113    return IdentifierLookup::kIdentifierFlags[Index(style)];
114}
115
116SLANG_FORCE_INLINE bool hasFlag(IdentifierStyle style, IdentifierFlag::Enum flag)
117{
118    return (getFlags(style) & flag) != 0;
119}
120
121} // namespace CppParse