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.
8 #include "atn/PredictionContext.h"
13 class ANTLR4CPP_PUBLIC SingletonPredictionContext : public PredictionContext {
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;
23 SingletonPredictionContext(Ref<PredictionContext> const& parent, size_t returnState);
24 virtual ~SingletonPredictionContext();
26 static Ref<SingletonPredictionContext> create(Ref<PredictionContext> const& parent, size_t returnState);
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;