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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#pragma once
#include "diagnostics.h"
namespace CppParse
{
using namespace Slang;
enum class IdentifierStyle
{
None, ///< It's not an identifier
Identifier, ///< Just an identifier
PreDeclare, ///< Declare a type (not visible in C++ code)
TypeSet, ///< TypeSet
TypeModifier, ///< const, volatile etc
Keyword, ///< A keyword C/C++ keyword that is not another type
Class, ///< class
Struct, ///< struct
Namespace, ///< namespace
Enum, ///< enum
TypeDef, ///< typedef
Access, ///< public, protected, private
Reflected,
Unreflected,
CallingConvention, ///< Used on a method
Virtual, ///<
Template,
Static,
IntegerModifier,
Extern,
CallableMisc, ///< For SLANG_NO_THROW etc
IntegerType, ///< Built in integer type
Default, /// default
CountOf,
};
typedef uint32_t IdentifierFlags;
struct IdentifierFlag
{
enum Enum : IdentifierFlags
{
StartScope = 0x1, ///< namespace, struct or class
ClassLike = 0x2, ///< Struct or class
Keyword = 0x4,
Reflection = 0x8,
};
};
class IdentifierLookup
{
public:
struct Pair
{
const char* name;
IdentifierStyle style;
};
IdentifierStyle get(const UnownedStringSlice& slice) const
{
Index index = m_pool.findIndex(slice);
return (index >= 0) ? m_styles[index] : IdentifierStyle::None;
}
void set(const char* name, IdentifierStyle style) { set(UnownedStringSlice(name), style); }
void set(const UnownedStringSlice& name, IdentifierStyle style);
void set(const char* const* names, size_t namesCount, IdentifierStyle style);
void set(const Pair* pairs, Index pairsCount);
void reset()
{
m_styles.clear();
m_pool.clear();
}
void initDefault(const UnownedStringSlice& markPrefix);
IdentifierLookup()
: m_pool(StringSlicePool::Style::Empty)
{
SLANG_ASSERT(m_pool.getSlicesCount() == 0);
}
static const IdentifierFlags kIdentifierFlags[Index(IdentifierStyle::CountOf)];
protected:
List<IdentifierStyle> m_styles;
StringSlicePool m_pool;
};
SLANG_FORCE_INLINE IdentifierFlags getFlags(IdentifierStyle style)
{
return IdentifierLookup::kIdentifierFlags[Index(style)];
}
SLANG_FORCE_INLINE bool hasFlag(IdentifierStyle style, IdentifierFlag::Enum flag)
{
return (getFlags(style) & flag) != 0;
}
} // namespace CppParse
|