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(unittest) { 81 import dshould : be, equal, not, should; 82 import unit_threaded; 83 @Tags("EmptyPredictionContext") 84 @("Construction") 85 unittest { 86 auto spc = new EmptyPredictionContext; 87 spc.should.not.be(null); 88 spc.isEmpty.should.equal(true); 89 spc.getReturnState(0).should.equal(int.max); 90 auto spc1 = new EmptyPredictionContext; 91 spc1.isEmpty.should.equal(true); 92 if (spc == spc1) 93 assert(true); 94 auto spc2 = SingletonPredictionContext.create(null, 95 PredictionContext.EMPTY_RETURN_STATE); 96 spc2.isEmpty.should.equal(true); 97 spc2.toString.should.equal("$"); 98 spc2.getReturnState(0).should.equal(int.max); 99 spc2.classinfo.should.equal(EmptyPredictionContext.classinfo); 100 spc.opEquals(spc1).should.equal(true); 101 import antlr.v4.runtime.ParserRuleContext; 102 auto prc1 = new ParserRuleContext; 103 spc2.opEquals(prc1).should.equal(false); 104 spc.toDOTString(spc2).should.equal("digraph G {\nrankdir=LR;\n}\n"); 105 } 106 }