Debian Codegraph @

src/sksl/lex/DFAState.h

raw
1 /*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SKSL_DFASTATE
9 #define SKSL_DFASTATE
10
11 #include "src/sksl/lex/LexUtil.h"
12
13 #include <vector>
14 #include <string>
15
16 struct DFAState {
17 struct Label {
18 std::vector<int> fStates;
19
20 Label(std::vector<int> states)
21 : fStates(std::move(states)) {}
22
23 bool operator==(const Label& other) const {
24 return fStates == other.fStates;
25 }
26
27 bool operator!=(const Label& other) const {
28 return !(*this == other);
29 }
30
31 #ifdef SK_DEBUG
32 std::string description() const {
33 std::string result = "<";
34 const char* separator = "";
35 for (int s : fStates) {
36 result += separator;
37 result += std::to_string(s);
38 separator = ", ";
39 }
40 result += ">";
41 return result;
42 }
43 #endif
44 };
45
46 DFAState()
47 : fId(INVALID)
48 , fLabel({}) {}
49
50 DFAState(int id, Label label)
51 : fId(id)
52 , fLabel(std::move(label)) {}
53
54 DFAState(const DFAState& other) = delete;
55
56 int fId;
57
58 Label fLabel;
59
60 bool fIsScanned = false;
61 };
62
63 namespace std {
64 template<> struct hash<DFAState::Label> {
65 size_t operator()(const DFAState::Label& s) const {
66 size_t result = 0;
67 for (int i : s.fStates) {
68 result = result * 101 + i;
69 }
70 return result;
71 }
72 };
73 } // namespace
74
75 #endif