1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QV4IDENTIFIERTABLE_H
4#define QV4IDENTIFIERTABLE_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include "qv4identifierhash_p.h"
18#include "qv4string_p.h"
19#include "qv4engine_p.h"
20#include <qset.h>
21#include <limits.h>
22
23QT_BEGIN_NAMESPACE
24
25namespace QV4 {
26
27struct Q_QML_PRIVATE_EXPORT IdentifierTable
28{
29 ExecutionEngine *engine;
30
31 uint alloc;
32 uint size;
33 int numBits;
34 Heap::StringOrSymbol **entriesByHash;
35 Heap::StringOrSymbol **entriesById;
36
37 QSet<IdentifierHashData *> idHashes;
38
39 void addEntry(Heap::StringOrSymbol *str);
40
41public:
42
43 IdentifierTable(ExecutionEngine *engine, int numBits = 8);
44 ~IdentifierTable();
45
46 Heap::String *insertString(const QString &s);
47 Heap::Symbol *insertSymbol(const QString &s);
48
49 PropertyKey asPropertyKey(const Heap::String *str) {
50 if (str->identifier.isValid())
51 return str->identifier;
52 return asPropertyKeyImpl(str);
53 }
54 PropertyKey asPropertyKey(const QV4::String *str) {
55 return asPropertyKey(str: str->d());
56 }
57
58 enum KeyConversionBehavior { Default, ForceConversionToId };
59 PropertyKey asPropertyKey(const QString &s, KeyConversionBehavior conversionBehavior = Default);
60 PropertyKey asPropertyKey(const char *s, int len);
61
62 PropertyKey asPropertyKeyImpl(const Heap::String *str);
63
64 Heap::StringOrSymbol *resolveId(PropertyKey i) const;
65 Heap::String *stringForId(PropertyKey i) const;
66 Heap::Symbol *symbolForId(PropertyKey i) const;
67
68 void markObjects(MarkStack *markStack);
69 void sweep();
70
71 void addIdentifierHash(IdentifierHashData *h) {
72 idHashes.insert(value: h);
73 }
74 void removeIdentifierHash(IdentifierHashData *h) {
75 idHashes.remove(value: h);
76 }
77
78private:
79 Heap::String *resolveStringEntry(const QString &s, uint hash, uint subtype);
80};
81
82}
83
84QT_END_NAMESPACE
85
86#endif
87

source code of qtdeclarative/src/qml/jsruntime/qv4identifiertable_p.h