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 module antlr.v4.runtime.atn.EmptyPredictionContext;
8 
9 import antlr.v4.runtime.atn;
10 
11 // Class EmptyPredictionContext
12 /**
13  * Empty PredictionContex
14  */
15 class EmptyPredictionContext : SingletonPredictionContext
16 {
17 
18     public this()
19     {
20         super(null, EMPTY_RETURN_STATE);
21     }
22 
23     /**
24      * @uml
25      * @override
26      */
27     public override bool isEmpty()
28     {
29         return true;
30     }
31 
32     /**
33      * @uml
34      * @override
35      */
36     public override size_t size()
37     {
38         return 1;
39     }
40 
41     /**
42      * @uml
43      * @override
44      */
45     public override PredictionContext getParent(int index)
46     {
47         return null;
48     }
49 
50     /**
51      * @uml
52      * @override
53      */
54     public override int getReturnState(int index)
55     {
56         return returnState;
57     }
58 
59     /**
60      * @uml
61      * @override
62      */
63     public override bool opEquals(Object o)
64     {
65         if (cast(EmptyPredictionContext)o)
66             return true;
67         return this is o;
68     }
69 
70     /**
71      * @uml
72      * @override
73      */
74     public override string toString()
75     {
76         return "$";
77     }
78 
79 }
80 
81 version(unittest) {
82     import dshould : be, equal, not, should;
83     import unit_threaded;
84     @Tags("EmptyPredictionContext")
85     @("Construction")
86     unittest {
87         auto spc = new EmptyPredictionContext;
88         spc.should.not.be(null);
89         spc.isEmpty.should.equal(true);
90         spc.getReturnState(0).should.equal(int.max);
91         auto spc1 = new EmptyPredictionContext;
92         spc1.isEmpty.should.equal(true);
93         if (spc == spc1)
94             assert(true);
95         auto spc2 = SingletonPredictionContext.create(null,
96                                                       PredictionContext.EMPTY_RETURN_STATE);
97         spc2.isEmpty.should.equal(true);
98         spc2.toString.should.equal("$");
99         spc2.getReturnState(0).should.equal(int.max);
100         spc2.classinfo.should.equal(EmptyPredictionContext.classinfo);
101         spc.opEquals(spc1).should.equal(true);
102         import antlr.v4.runtime.ParserRuleContext;
103         auto prc1 = new ParserRuleContext;
104         spc2.opEquals(prc1).should.equal(false);
105         spc.toDOTString(spc2).should.equal("digraph G {\nrankdir=LR;\n}\n");
106     }
107 }