001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.transformer.bytecode.statement; 020 021import lucee.runtime.exp.TemplateException; 022import lucee.transformer.bytecode.BytecodeContext; 023import lucee.transformer.bytecode.BytecodeException; 024import lucee.transformer.bytecode.Position; 025import lucee.transformer.bytecode.Statement; 026import lucee.transformer.bytecode.util.ExpressionUtil; 027 028/** 029 * A single Statement 030 */ 031public abstract class StatementBase implements Statement { 032 033 private Position start; 034 private Position end; 035 private Statement parent; 036 private int hasReturnChild=-1; 037 038 /** 039 * constructor of the class 040 * @param line 041 */ 042 public StatementBase(Position start, Position end) { 043 this.start=start; 044 this.end=end; 045 } 046 047 /** 048 * @see lucee.transformer.bytecode.Statement#getParent() 049 */ 050 public Statement getParent() { 051 return parent; 052 } 053 054 055 /** 056 * @see lucee.transformer.bytecode.Statement#setParent(lucee.transformer.bytecode.Statement) 057 */ 058 public void setParent(Statement parent) { 059 this.parent=parent; 060 if(hasReturnChild!=-1 && parent!=null) 061 parent.setHasFlowController(hasReturnChild==1); 062 } 063 064 065 /** 066 * write out the stament to adapter 067 * @param adapter 068 * @throws TemplateException 069 */ 070 public final void writeOut(BytecodeContext bc) throws BytecodeException { 071 ExpressionUtil.visitLine(bc, start); 072 _writeOut(bc); 073 ExpressionUtil.visitLine(bc, end); 074 075 } 076 077 078 /** 079 * write out the stament to the adater 080 * @param adapter 081 * @throws BytecodeException 082 */ 083 public abstract void _writeOut(BytecodeContext bc) throws BytecodeException; 084 085 086 087 /** 088 * sets the line value. 089 * @param line The line to set. 090 */ 091 public void setStart(Position start) { 092 this.start = start; 093 } 094 095 /** 096 * sets the line value. 097 * @param line The line to set. 098 */ 099 public void setEnd(Position end) { 100 this.end = end; 101 } 102 103 @Override 104 public Position getStart() { 105 return start; 106 } 107 108 @Override 109 public Position getEnd() { 110 return end; 111 } 112 113 /** 114 * @see lucee.transformer.bytecode.Statement#getDescendantCount() 115 */ 116 public final int getDescendantCount() { 117 return 0; 118 } 119 120 /** 121 * 122 * @see lucee.transformer.bytecode.Statement#hasFlowController() 123 */ 124 public boolean hasFlowController() { 125 return hasReturnChild==1; 126 } 127 128 /** 129 * @param hasReturnChild the hasReturnChild to set 130 */ 131 public void setHasFlowController(boolean hasReturnChild) { 132 if(parent!=null)parent.setHasFlowController(hasReturnChild); 133 this.hasReturnChild = hasReturnChild?1:0; 134 } 135}