1 28 29 package com.caucho.es.parser; 30 31 import com.caucho.es.ESException; 32 33 import java.io.IOException ; 34 35 38 class AssignExpr extends Expr { 39 private Expr lhs; 40 private IdExpr var; 41 private Expr field; 42 private Expr rhs; 43 44 AssignExpr(Block block, IdExpr var, Expr rhs) 45 { 46 super(block); 47 48 this.var = var; 49 this.rhs = rhs; 50 rhs.getType(); 51 if (! (rhs instanceof LiteralExpr || rhs instanceof IdExpr)) 52 var.setUsed(); 53 } 54 55 AssignExpr(Block block, Expr lhs, Expr field, Expr rhs) 56 { 57 super(block); 58 59 this.lhs = lhs; 60 this.field = field; 61 this.rhs = rhs; 62 rhs.getType(); 63 lhs.setUsed(); 64 } 65 66 void exprStatement(Function fun) throws ESException 67 { 68 isTop = true; 69 noValue = true; 70 71 fun.addExpr(this); 72 } 73 74 77 void printImpl() 78 throws IOException 79 { 80 cl.setLine(getFilename(), getLine()); 81 82 if (var != null && (var.isJavaLocal() || var.isJavaGlobal())) { 83 if (! isTop && ! noValue) { 84 switch (var.getType()) { 85 case TYPE_NUMBER: 86 case TYPE_INTEGER: 87 cl.print("ESNumber.create("); 88 break; 89 90 case TYPE_BOOLEAN: 91 cl.print("ESBoolean.create("); 92 break; 93 94 default: 95 cl.print("("); 96 break; 97 } 98 } 99 else if (noValue && ! var.isUsed() && 100 (rhs instanceof LiteralExpr || rhs instanceof IdExpr)) 101 return; 102 else if (! noValue) 103 cl.print("("); 104 105 cl.print(var.getId()); 106 cl.print(" = "); 107 switch (var.getType()) { 108 case TYPE_NUMBER: 109 rhs.printNum(); 110 break; 111 112 case TYPE_INTEGER: 113 rhs.printInt32(); 114 break; 115 116 case TYPE_BOOLEAN: 117 rhs.printBoolean(); 118 break; 119 120 case TYPE_JAVA: 121 if (var.getType() == TYPE_JAVA && 122 ! var.getJavaClass().isAssignableFrom(rhs.getJavaClass())) 123 cl.print("(" + var.getJavaClass().getName() + ") "); 124 rhs.printJava(); 125 break; 126 127 default: 128 rhs.print(); 129 break; 130 } 131 132 if (! noValue) 133 cl.print(")"); 134 } 135 else if (noValue && var != null) { 136 if (var.isGlobalScope()) 137 cl.print("_env.global.setProperty("); 138 else if (! var.isUsed() && var.isLocal() && 140 (rhs instanceof LiteralExpr || rhs instanceof IdExpr)) 141 return; 142 else if (var.getVar().hasInit()) 143 cl.print("_arg.setProperty("); 144 else 145 cl.print("_env.setScopeProperty("); 146 147 printLiteral(var.getId()); 148 cl.print(", "); 149 rhs.print(); 150 cl.print(")"); 151 } 152 else if (var != null) { 153 if (var.isGlobalScope()) 154 cl.print("_env.setGlobalProperty("); 155 else if (! var.isUsed() && var.isLocal() && 156 (rhs instanceof LiteralExpr || rhs instanceof IdExpr)) 157 return; 158 else if (var.getVar().hasInit()) 159 cl.print("_arg.setProperty("); 160 else 161 cl.print("_env.setScopeProperty("); 162 163 printLiteral(var.getId()); 164 cl.print(", "); 165 rhs.print(); 166 cl.print(")"); 167 } 168 else if (noValue) { 169 lhs.print(); 170 cl.print(".setProperty("); 171 if (field.getType() == TYPE_INTEGER) 172 field.printInt32(); 173 else 174 field.printStr(); 175 cl.print(", "); 176 rhs.print(); 177 cl.print(")"); 178 } 179 else { 180 cl.print("_env.setProperty("); 181 lhs.print(); 182 cl.print(", "); 183 field.printStr(); 184 cl.print(", "); 185 rhs.print(); 186 cl.print(")"); 187 } 188 } 189 } 190 | Popular Tags |