abouttreesummaryrefslogcommitdiff
path: root/antlr4-cpp-runtime-4.9.2-source/install/include/antlr4-runtime/atn/ATNSerializer.h
blob: a6d1d6976fa3a5614f2b747c437ff3314d4c93ce (plain)
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
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
 * Use of this file is governed by the BSD 3-clause license that
 * can be found in the LICENSE.txt file in the project root.
 */

#pragma once

namespace antlr4 {
namespace atn {

  class ANTLR4CPP_PUBLIC ATNSerializer {
  public:
    ATN *atn;

    ATNSerializer(ATN *atn);
    ATNSerializer(ATN *atn, const std::vector<std::string> &tokenNames);
    virtual ~ATNSerializer();

    /// <summary>
    /// Serialize state descriptors, edge descriptors, and decision->state map
    ///  into list of ints:
    ///
    /// 		grammar-type, (ANTLRParser.LEXER, ...)
    ///  	max token type,
    ///  	num states,
    ///  	state-0-type ruleIndex, state-1-type ruleIndex, ... state-i-type
    ///  ruleIndex optional-arg ...
    ///  	num rules,
    ///  	rule-1-start-state rule-1-args, rule-2-start-state  rule-2-args, ...
    ///  	(args are token type,actionIndex in lexer else 0,0)
    ///      num modes,
    ///      mode-0-start-state, mode-1-start-state, ... (parser has 0 modes)
    ///      num sets
    ///      set-0-interval-count intervals, set-1-interval-count intervals, ...
    ///  	num total edges,
    ///      src, trg, edge-type, edge arg1, optional edge arg2 (present always),
    ///      ...
    ///      num decisions,
    ///      decision-0-start-state, decision-1-start-state, ...
    ///
    ///  Convenient to pack into unsigned shorts to make as Java string.
    /// </summary>
    virtual std::vector<size_t> serialize();

    virtual std::string decode(const std::wstring& data);
    virtual std::string getTokenName(size_t t);

    /// Used by Java target to encode short/int array as chars in string.
    static std::wstring getSerializedAsString(ATN *atn);
    static std::vector<size_t> getSerialized(ATN *atn);

    static std::string getDecoded(ATN *atn, std::vector<std::string> &tokenNames);

  private:
    std::vector<std::string> _tokenNames;

    void serializeUUID(std::vector<size_t> &data, Guid uuid);
  };

} // namespace atn
} // namespace antlr4