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