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.Statement; 007 import railo.transformer.bytecode.util.ExpressionUtil; 008 009 /** 010 * A single Statement 011 */ 012 public abstract class StatementBase implements Statement { 013 014 015 private int startLine; 016 private int endLine; 017 private Statement parent; 018 private int hasReturnChild=-1; 019 020 /** 021 * constructor of the class 022 * @param line 023 */ 024 public StatementBase(int startLine, int endLine) { 025 this.startLine=startLine; 026 this.endLine=endLine; 027 } 028 public StatementBase(int startLine) { 029 this.startLine=startLine; 030 this.endLine=-1; 031 } 032 033 /** 034 * @see railo.transformer.bytecode.Statement#getParent() 035 */ 036 public Statement getParent() { 037 return parent; 038 } 039 040 041 /** 042 * @see railo.transformer.bytecode.Statement#setParent(railo.transformer.bytecode.Statement) 043 */ 044 public void setParent(Statement parent) { 045 this.parent=parent; 046 if(hasReturnChild!=-1 && parent!=null) 047 parent.setHasFlowController(hasReturnChild==1); 048 } 049 050 051 /** 052 * write out the stament to adapter 053 * @param adapter 054 * @throws TemplateException 055 */ 056 public final void writeOut(BytecodeContext bc) throws BytecodeException { 057 ExpressionUtil.visitLine(bc, startLine); 058 _writeOut(bc); 059 ExpressionUtil.visitLine(bc, endLine); 060 061 } 062 063 064 /** 065 * write out the stament to the adater 066 * @param adapter 067 * @throws BytecodeException 068 */ 069 public abstract void _writeOut(BytecodeContext bc) throws BytecodeException; 070 071 072 /** 073 * Returns the value of line. 074 * @return value line 075 */ 076 public int getLine() { 077 return startLine; 078 } 079 080 081 /** 082 * sets the line value. 083 * @param line The line to set. 084 */ 085 public void setStartLine(int startLine) { 086 this.startLine = startLine; 087 } 088 089 /** 090 * sets the line value. 091 * @param line The line to set. 092 * @deprecated replaced with "setStartLine" 093 */ 094 public void setLine(int startLine) { 095 setStartLine(startLine); 096 } 097 098 /** 099 * sets the line value. 100 * @param line The line to set. 101 */ 102 public void setEndLine(int endLine) { 103 this.endLine = endLine; 104 } 105 /** 106 * @return the startLine 107 */ 108 public int getStartLine() { 109 return startLine; 110 } 111 /** 112 * @return the endLine 113 */ 114 public int getEndLine() { 115 return endLine; 116 } 117 118 /** 119 * @see railo.transformer.bytecode.Statement#getDescendantCount() 120 */ 121 public final int getDescendantCount() { 122 return 0; 123 } 124 125 /** 126 * 127 * @see railo.transformer.bytecode.Statement#hasFlowController() 128 */ 129 public boolean hasFlowController() { 130 return hasReturnChild==1; 131 } 132 133 /** 134 * @param hasReturnChild the hasReturnChild to set 135 */ 136 public void setHasFlowController(boolean hasReturnChild) { 137 if(parent!=null)parent.setHasFlowController(hasReturnChild); 138 this.hasReturnChild = hasReturnChild?1:0; 139 } 140 141 }