41 import static jdk.nashorn.internal.codegen.CompilerConstants.VARARGS;
42 import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup;
43 import static jdk.nashorn.internal.codegen.CompilerConstants.interfaceCallNoLookup;
44 import static jdk.nashorn.internal.codegen.CompilerConstants.methodDescriptor;
45 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
46 import static jdk.nashorn.internal.codegen.CompilerConstants.staticField;
47 import static jdk.nashorn.internal.codegen.CompilerConstants.typeDescriptor;
48 import static jdk.nashorn.internal.ir.Symbol.IS_INTERNAL;
49 import static jdk.nashorn.internal.ir.Symbol.IS_TEMP;
50 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_FAST_SCOPE;
51 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_SCOPE;
52 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
53
54 import java.io.PrintWriter;
55 import java.util.ArrayList;
56 import java.util.Arrays;
57 import java.util.EnumSet;
58 import java.util.Iterator;
59 import java.util.LinkedList;
60 import java.util.List;
61 import java.util.TreeMap;
62
63 import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
64 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
65 import jdk.nashorn.internal.codegen.RuntimeCallSite.SpecializedRuntimeNode;
66 import jdk.nashorn.internal.codegen.types.ArrayType;
67 import jdk.nashorn.internal.codegen.types.Type;
68 import jdk.nashorn.internal.ir.AccessNode;
69 import jdk.nashorn.internal.ir.BaseNode;
70 import jdk.nashorn.internal.ir.BinaryNode;
71 import jdk.nashorn.internal.ir.Block;
72 import jdk.nashorn.internal.ir.BreakNode;
73 import jdk.nashorn.internal.ir.BreakableNode;
74 import jdk.nashorn.internal.ir.CallNode;
75 import jdk.nashorn.internal.ir.CaseNode;
76 import jdk.nashorn.internal.ir.CatchNode;
77 import jdk.nashorn.internal.ir.ContinueNode;
78 import jdk.nashorn.internal.ir.EmptyNode;
79 import jdk.nashorn.internal.ir.ExecuteNode;
80 import jdk.nashorn.internal.ir.ForNode;
2203 final Node rhs = unaryNode.rhs();
2204 final Type to = unaryNode.getType();
2205
2206 if (to.isObject() && rhs instanceof LiteralNode) {
2207 final LiteralNode<?> literalNode = (LiteralNode<?>)rhs;
2208 final Object value = literalNode.getValue();
2209
2210 if (value instanceof Number) {
2211 assert !to.isArray() : "type hygiene - cannot convert number to array: (" + to.getTypeClass().getSimpleName() + ')' + value;
2212 if (value instanceof Integer) {
2213 method.load((Integer)value);
2214 } else if (value instanceof Long) {
2215 method.load((Long)value);
2216 } else if (value instanceof Double) {
2217 method.load((Double)value);
2218 } else {
2219 assert false;
2220 }
2221 method.convert(Type.OBJECT);
2222 } else if (value instanceof Boolean) {
2223 method.getField(staticField(Boolean.class, value.toString().toUpperCase(), Boolean.class));
2224 } else {
2225 load(rhs);
2226 method.convert(unaryNode.getType());
2227 }
2228 } else {
2229 load(rhs);
2230 method.convert(unaryNode.getType());
2231 }
2232
2233 method.store(unaryNode.getSymbol());
2234
2235 return false;
2236 }
2237
2238 @Override
2239 public boolean enterDECINC(final UnaryNode unaryNode) {
2240 final Node rhs = unaryNode.rhs();
2241 final Type type = unaryNode.getType();
2242 final TokenType tokenType = unaryNode.tokenType();
2243 final boolean isPostfix = tokenType == TokenType.DECPOSTFIX || tokenType == TokenType.INCPOSTFIX;
|
41 import static jdk.nashorn.internal.codegen.CompilerConstants.VARARGS;
42 import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup;
43 import static jdk.nashorn.internal.codegen.CompilerConstants.interfaceCallNoLookup;
44 import static jdk.nashorn.internal.codegen.CompilerConstants.methodDescriptor;
45 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
46 import static jdk.nashorn.internal.codegen.CompilerConstants.staticField;
47 import static jdk.nashorn.internal.codegen.CompilerConstants.typeDescriptor;
48 import static jdk.nashorn.internal.ir.Symbol.IS_INTERNAL;
49 import static jdk.nashorn.internal.ir.Symbol.IS_TEMP;
50 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_FAST_SCOPE;
51 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_SCOPE;
52 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
53
54 import java.io.PrintWriter;
55 import java.util.ArrayList;
56 import java.util.Arrays;
57 import java.util.EnumSet;
58 import java.util.Iterator;
59 import java.util.LinkedList;
60 import java.util.List;
61 import java.util.Locale;
62 import java.util.TreeMap;
63
64 import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
65 import jdk.nashorn.internal.codegen.CompilerConstants.Call;
66 import jdk.nashorn.internal.codegen.RuntimeCallSite.SpecializedRuntimeNode;
67 import jdk.nashorn.internal.codegen.types.ArrayType;
68 import jdk.nashorn.internal.codegen.types.Type;
69 import jdk.nashorn.internal.ir.AccessNode;
70 import jdk.nashorn.internal.ir.BaseNode;
71 import jdk.nashorn.internal.ir.BinaryNode;
72 import jdk.nashorn.internal.ir.Block;
73 import jdk.nashorn.internal.ir.BreakNode;
74 import jdk.nashorn.internal.ir.BreakableNode;
75 import jdk.nashorn.internal.ir.CallNode;
76 import jdk.nashorn.internal.ir.CaseNode;
77 import jdk.nashorn.internal.ir.CatchNode;
78 import jdk.nashorn.internal.ir.ContinueNode;
79 import jdk.nashorn.internal.ir.EmptyNode;
80 import jdk.nashorn.internal.ir.ExecuteNode;
81 import jdk.nashorn.internal.ir.ForNode;
2204 final Node rhs = unaryNode.rhs();
2205 final Type to = unaryNode.getType();
2206
2207 if (to.isObject() && rhs instanceof LiteralNode) {
2208 final LiteralNode<?> literalNode = (LiteralNode<?>)rhs;
2209 final Object value = literalNode.getValue();
2210
2211 if (value instanceof Number) {
2212 assert !to.isArray() : "type hygiene - cannot convert number to array: (" + to.getTypeClass().getSimpleName() + ')' + value;
2213 if (value instanceof Integer) {
2214 method.load((Integer)value);
2215 } else if (value instanceof Long) {
2216 method.load((Long)value);
2217 } else if (value instanceof Double) {
2218 method.load((Double)value);
2219 } else {
2220 assert false;
2221 }
2222 method.convert(Type.OBJECT);
2223 } else if (value instanceof Boolean) {
2224 method.getField(staticField(Boolean.class, value.toString().toUpperCase(Locale.ENGLISH), Boolean.class));
2225 } else {
2226 load(rhs);
2227 method.convert(unaryNode.getType());
2228 }
2229 } else {
2230 load(rhs);
2231 method.convert(unaryNode.getType());
2232 }
2233
2234 method.store(unaryNode.getSymbol());
2235
2236 return false;
2237 }
2238
2239 @Override
2240 public boolean enterDECINC(final UnaryNode unaryNode) {
2241 final Node rhs = unaryNode.rhs();
2242 final Type type = unaryNode.getType();
2243 final TokenType tokenType = unaryNode.tokenType();
2244 final boolean isPostfix = tokenType == TokenType.DECPOSTFIX || tokenType == TokenType.INCPOSTFIX;
|