001 package railo.transformer.bytecode.statement; 002 003 import railo.runtime.exp.TemplateException; 004 import railo.transformer.bytecode.BytecodeContext; 005 import railo.transformer.bytecode.BytecodeException; 006 import railo.transformer.bytecode.Position; 007 import railo.transformer.bytecode.Statement; 008 import railo.transformer.bytecode.util.ExpressionUtil; 009 010 /** 011 * A single Statement 012 */ 013 public abstract class StatementBase implements Statement { 014 015 private Position start; 016 private Position end; 017 private Statement parent; 018 private int hasReturnChild=-1; 019 020 /** 021 * constructor of the class 022 * @param line 023 */ 024 public StatementBase(Position start, Position end) { 025 this.start=start; 026 this.end=end; 027 } 028 029 /** 030 * @see railo.transformer.bytecode.Statement#getParent() 031 */ 032 public Statement getParent() { 033 return parent; 034 } 035 036 037 /** 038 * @see railo.transformer.bytecode.Statement#setParent(railo.transformer.bytecode.Statement) 039 */ 040 public void setParent(Statement parent) { 041 this.parent=parent; 042 if(hasReturnChild!=-1 && parent!=null) 043 parent.setHasFlowController(hasReturnChild==1); 044 } 045 046 047 /** 048 * write out the stament to adapter 049 * @param adapter 050 * @throws TemplateException 051 */ 052 public final void writeOut(BytecodeContext bc) throws BytecodeException { 053 ExpressionUtil.visitLine(bc, start); 054 _writeOut(bc); 055 ExpressionUtil.visitLine(bc, end); 056 057 } 058 059 060 /** 061 * write out the stament to the adater 062 * @param adapter 063 * @throws BytecodeException 064 */ 065 public abstract void _writeOut(BytecodeContext bc) throws BytecodeException; 066 067 068 069 /** 070 * sets the line value. 071 * @param line The line to set. 072 */ 073 public void setStart(Position start) { 074 this.start = start; 075 } 076 077 /** 078 * sets the line value. 079 * @param line The line to set. 080 */ 081 public void setEnd(Position end) { 082 this.end = end; 083 } 084 085 @Override 086 public Position getStart() { 087 return start; 088 } 089 090 @Override 091 public Position getEnd() { 092 return end; 093 } 094 095 /** 096 * @see railo.transformer.bytecode.Statement#getDescendantCount() 097 */ 098 public final int getDescendantCount() { 099 return 0; 100 } 101 102 /** 103 * 104 * @see railo.transformer.bytecode.Statement#hasFlowController() 105 */ 106 public boolean hasFlowController() { 107 return hasReturnChild==1; 108 } 109 110 /** 111 * @param hasReturnChild the hasReturnChild to set 112 */ 113 public void setHasFlowController(boolean hasReturnChild) { 114 if(parent!=null)parent.setHasFlowController(hasReturnChild); 115 this.hasReturnChild = hasReturnChild?1:0; 116 } 117 }