]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/ATNDeserializer.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / ATNDeserializer.h
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #pragma once
7
8 #include "atn/LexerAction.h"
9 #include "atn/ATNDeserializationOptions.h"
10
11 namespace antlr4 {
12 namespace atn {
13
14   class ANTLR4CPP_PUBLIC ATNDeserializer {
15   public:
16 #if __cplusplus >= 201703L
17     static constexpr size_t SERIALIZED_VERSION = 3;
18 #else
19     enum : size_t {
20       SERIALIZED_VERSION = 3,
21     };
22 #endif
23
24     /// This is the current serialized UUID.
25     // ml: defined as function to avoid the “static initialization order fiasco”.
26     static Guid SERIALIZED_UUID();
27
28     ATNDeserializer();
29     ATNDeserializer(const ATNDeserializationOptions& dso);
30     virtual ~ATNDeserializer();
31
32     static Guid toUUID(const unsigned short *data, size_t offset);
33
34     virtual ATN deserialize(const std::vector<uint16_t> &input);
35     virtual void verifyATN(const ATN &atn);
36
37     static void checkCondition(bool condition);
38     static void checkCondition(bool condition, const std::string &message);
39
40     static Transition *edgeFactory(const ATN &atn, size_t type, size_t src, size_t trg, size_t arg1, size_t arg2,
41                                    size_t arg3, const std::vector<misc::IntervalSet> &sets);
42
43     static ATNState *stateFactory(size_t type, size_t ruleIndex);
44
45   protected:
46     /// Determines if a particular serialized representation of an ATN supports
47     /// a particular feature, identified by the <seealso cref="UUID"/> used for serializing
48     /// the ATN at the time the feature was first introduced.
49     ///
50     /// <param name="feature"> The <seealso cref="UUID"/> marking the first time the feature was
51     /// supported in the serialized ATN. </param>
52     /// <param name="actualUuid"> The <seealso cref="UUID"/> of the actual serialized ATN which is
53     /// currently being deserialized. </param>
54     /// <returns> {@code true} if the {@code actualUuid} value represents a
55     /// serialized ATN at or after the feature identified by {@code feature} was
56     /// introduced; otherwise, {@code false}. </returns>
57     virtual bool isFeatureSupported(const Guid &feature, const Guid &actualUuid);
58     void markPrecedenceDecisions(const ATN &atn);
59     Ref<LexerAction> lexerActionFactory(LexerActionType type, int data1, int data2);
60
61   private:
62     /// This is the earliest supported serialized UUID.
63     static Guid BASE_SERIALIZED_UUID();
64
65     /// This UUID indicates an extension of <seealso cref="BASE_SERIALIZED_UUID"/> for the
66     /// addition of precedence predicates.
67     static Guid ADDED_PRECEDENCE_TRANSITIONS();
68
69     /**
70      * This UUID indicates an extension of ADDED_PRECEDENCE_TRANSITIONS
71      * for the addition of lexer actions encoded as a sequence of
72      * LexerAction instances.
73      */
74     static Guid ADDED_LEXER_ACTIONS();
75
76     /**
77      * This UUID indicates the serialized ATN contains two sets of
78      * IntervalSets, where the second set's values are encoded as
79      * 32-bit integers to support the full Unicode SMP range up to U+10FFFF.
80      */
81     static Guid ADDED_UNICODE_SMP();
82
83     /// This list contains all of the currently supported UUIDs, ordered by when
84     /// the feature first appeared in this branch.
85     static std::vector<Guid>& SUPPORTED_UUIDS();
86
87     ATNDeserializationOptions deserializationOptions;
88   };
89
90 } // namespace atn
91 } // namespace antlr4