]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/ArrayPredictionContext.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / ArrayPredictionContext.h
1 
2 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
3  * Use of this file is governed by the BSD 3-clause license that
4  * can be found in the LICENSE.txt file in the project root.
5  */
6
7 #pragma once
8
9 #include "atn/PredictionContext.h"
10
11 namespace antlr4 {
12 namespace atn {
13
14   class SingletonPredictionContext;
15
16   class ANTLR4CPP_PUBLIC ArrayPredictionContext : public PredictionContext {
17   public:
18     /// Parent can be empty only if full ctx mode and we make an array
19     /// from EMPTY and non-empty. We merge EMPTY by using null parent and
20     /// returnState == EMPTY_RETURN_STATE.
21     // Also here: we use a strong reference to our parents to avoid having them freed prematurely.
22     //            See also SinglePredictionContext.
23     const std::vector<Ref<PredictionContext>> parents;
24
25     /// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last.
26     const std::vector<size_t> returnStates;
27
28     ArrayPredictionContext(Ref<SingletonPredictionContext> const& a);
29     ArrayPredictionContext(std::vector<Ref<PredictionContext>> const& parents_, std::vector<size_t> const& returnStates);
30     virtual ~ArrayPredictionContext();
31
32     virtual bool isEmpty() const override;
33     virtual size_t size() const override;
34     virtual Ref<PredictionContext> getParent(size_t index) const override;
35     virtual size_t getReturnState(size_t index) const override;
36     bool operator == (const PredictionContext &o) const override;
37
38     virtual std::string toString() const override;
39   };
40
41 } // namespace atn
42 } // namespace antlr4
43