]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/SingletonPredictionContext.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / SingletonPredictionContext.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/PredictionContext.h"
9
10 namespace antlr4 {
11 namespace atn {
12
13   class ANTLR4CPP_PUBLIC SingletonPredictionContext : public PredictionContext {
14   public:
15     // Usually a parent is linked via a weak ptr. Not so here as we have kinda reverse reference chain.
16     // There are no child contexts stored here and often the parent context is left dangling when it's
17     // owning ATNState is released. In order to avoid having this context released as well (leaving all other contexts
18     // which got this one as parent with a null reference) we use a shared_ptr here instead, to keep those left alone
19     // parent contexts alive.
20     const Ref<PredictionContext> parent;
21     const size_t returnState;
22
23     SingletonPredictionContext(Ref<PredictionContext> const& parent, size_t returnState);
24     virtual ~SingletonPredictionContext();
25
26     static Ref<SingletonPredictionContext> create(Ref<PredictionContext> const& parent, size_t returnState);
27
28     virtual size_t size() const override;
29     virtual Ref<PredictionContext> getParent(size_t index) const override;
30     virtual size_t getReturnState(size_t index) const override;
31     virtual bool operator == (const PredictionContext &o) const override;
32     virtual std::string toString() const override;
33   };
34
35 } // namespace atn
36 } // namespace antlr4