]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/ATNSerializer.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / ATNSerializer.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 namespace antlr4 {
9 namespace atn {
10
11   class ANTLR4CPP_PUBLIC ATNSerializer {
12   public:
13     ATN *atn;
14
15     ATNSerializer(ATN *atn);
16     ATNSerializer(ATN *atn, const std::vector<std::string> &tokenNames);
17     virtual ~ATNSerializer();
18
19     /// <summary>
20     /// Serialize state descriptors, edge descriptors, and decision->state map
21     ///  into list of ints:
22     ///
23     ///                 grammar-type, (ANTLRParser.LEXER, ...)
24     ///         max token type,
25     ///         num states,
26     ///         state-0-type ruleIndex, state-1-type ruleIndex, ... state-i-type
27     ///  ruleIndex optional-arg ...
28     ///         num rules,
29     ///         rule-1-start-state rule-1-args, rule-2-start-state  rule-2-args, ...
30     ///         (args are token type,actionIndex in lexer else 0,0)
31     ///      num modes,
32     ///      mode-0-start-state, mode-1-start-state, ... (parser has 0 modes)
33     ///      num sets
34     ///      set-0-interval-count intervals, set-1-interval-count intervals, ...
35     ///         num total edges,
36     ///      src, trg, edge-type, edge arg1, optional edge arg2 (present always),
37     ///      ...
38     ///      num decisions,
39     ///      decision-0-start-state, decision-1-start-state, ...
40     ///
41     ///  Convenient to pack into unsigned shorts to make as Java string.
42     /// </summary>
43     virtual std::vector<size_t> serialize();
44
45     virtual std::string decode(const std::wstring& data);
46     virtual std::string getTokenName(size_t t);
47
48     /// Used by Java target to encode short/int array as chars in string.
49     static std::wstring getSerializedAsString(ATN *atn);
50     static std::vector<size_t> getSerialized(ATN *atn);
51
52     static std::string getDecoded(ATN *atn, std::vector<std::string> &tokenNames);
53
54   private:
55     std::vector<std::string> _tokenNames;
56
57     void serializeUUID(std::vector<size_t> &data, Guid uuid);
58   };
59
60 } // namespace atn
61 } // namespace antlr4