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