author | mhaupt |
Tue, 09 Feb 2016 14:14:06 +0100 | |
changeset 35793 | b89ddacf3104 |
parent 35725 | c7a2c18529b1 |
child 36026 | ad5ff5d5459b |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
35793 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.nashorn.internal.codegen.types; |
|
27 |
||
24751 | 28 |
import static jdk.internal.org.objectweb.asm.Opcodes.I2D; |
29 |
import static jdk.internal.org.objectweb.asm.Opcodes.I2L; |
|
30 |
import static jdk.internal.org.objectweb.asm.Opcodes.IADD; |
|
16147 | 31 |
import static jdk.internal.org.objectweb.asm.Opcodes.ICONST_0; |
32 |
import static jdk.internal.org.objectweb.asm.Opcodes.ICONST_1; |
|
33 |
import static jdk.internal.org.objectweb.asm.Opcodes.ILOAD; |
|
34 |
import static jdk.internal.org.objectweb.asm.Opcodes.IRETURN; |
|
35 |
import static jdk.internal.org.objectweb.asm.Opcodes.ISTORE; |
|
36 |
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup; |
|
24719 | 37 |
import static jdk.nashorn.internal.runtime.JSType.UNDEFINED_INT; |
24751 | 38 |
import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT; |
39 |
||
16147 | 40 |
import jdk.internal.org.objectweb.asm.MethodVisitor; |
41 |
import jdk.nashorn.internal.codegen.CompilerConstants; |
|
42 |
||
43 |
/** |
|
44 |
* The boolean type class |
|
45 |
*/ |
|
46 |
public final class BooleanType extends Type { |
|
27204 | 47 |
private static final long serialVersionUID = 1L; |
16147 | 48 |
|
49 |
private static final CompilerConstants.Call VALUE_OF = staticCallNoLookup(Boolean.class, "valueOf", Boolean.class, boolean.class); |
|
24751 | 50 |
private static final CompilerConstants.Call TO_STRING = staticCallNoLookup(Boolean.class, "toString", String.class, boolean.class); |
16147 | 51 |
|
52 |
/** |
|
53 |
* Constructor |
|
54 |
*/ |
|
55 |
protected BooleanType() { |
|
56 |
super("boolean", boolean.class, 1, 1); |
|
57 |
} |
|
58 |
||
59 |
@Override |
|
60 |
public Type nextWider() { |
|
61 |
return INT; |
|
62 |
} |
|
63 |
||
64 |
@Override |
|
65 |
public Class<?> getBoxedType() { |
|
66 |
return Boolean.class; |
|
67 |
} |
|
68 |
||
69 |
@Override |
|
24719 | 70 |
public char getBytecodeStackType() { |
71 |
return 'I'; |
|
72 |
} |
|
73 |
||
74 |
@Override |
|
16147 | 75 |
public Type loadUndefined(final MethodVisitor method) { |
24719 | 76 |
method.visitLdcInsn(UNDEFINED_INT); |
77 |
return BOOLEAN; |
|
78 |
} |
|
79 |
||
80 |
@Override |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24751
diff
changeset
|
81 |
public Type loadForcedInitializer(final MethodVisitor method) { |
24719 | 82 |
method.visitInsn(ICONST_0); |
16147 | 83 |
return BOOLEAN; |
84 |
} |
|
85 |
||
86 |
@Override |
|
87 |
public void _return(final MethodVisitor method) { |
|
88 |
method.visitInsn(IRETURN); |
|
89 |
} |
|
90 |
||
91 |
@Override |
|
92 |
public Type load(final MethodVisitor method, final int slot) { |
|
93 |
assert slot != -1; |
|
94 |
method.visitVarInsn(ILOAD, slot); |
|
95 |
return BOOLEAN; |
|
96 |
} |
|
97 |
||
98 |
@Override |
|
99 |
public void store(final MethodVisitor method, final int slot) { |
|
100 |
assert slot != -1; |
|
101 |
method.visitVarInsn(ISTORE, slot); |
|
102 |
} |
|
103 |
||
104 |
@Override |
|
105 |
public Type ldc(final MethodVisitor method, final Object c) { |
|
106 |
assert c instanceof Boolean; |
|
107 |
method.visitInsn((Boolean) c ? ICONST_1 : ICONST_0); |
|
108 |
return BOOLEAN; |
|
109 |
} |
|
110 |
||
111 |
@Override |
|
112 |
public Type convert(final MethodVisitor method, final Type to) { |
|
113 |
if (isEquivalentTo(to)) { |
|
114 |
return to; |
|
115 |
} |
|
116 |
||
117 |
if (to.isNumber()) { |
|
24751 | 118 |
method.visitInsn(I2D); |
16147 | 119 |
} else if (to.isLong()) { |
24751 | 120 |
method.visitInsn(I2L); |
121 |
} else if (to.isInteger()) { |
|
122 |
//nop |
|
16147 | 123 |
} else if (to.isString()) { |
24751 | 124 |
invokestatic(method, TO_STRING); |
16147 | 125 |
} else if (to.isObject()) { |
24719 | 126 |
invokestatic(method, VALUE_OF); |
16147 | 127 |
} else { |
24719 | 128 |
throw new UnsupportedOperationException("Illegal conversion " + this + " -> " + to); |
16147 | 129 |
} |
130 |
||
131 |
return to; |
|
132 |
} |
|
133 |
||
134 |
@Override |
|
24719 | 135 |
public Type add(final MethodVisitor method, final int programPoint) { |
24751 | 136 |
// Adding booleans in JavaScript is perfectly valid, they add as if false=0 and true=1 |
35793 | 137 |
if(programPoint == INVALID_PROGRAM_POINT) { |
138 |
method.visitInsn(IADD); |
|
139 |
} else { |
|
140 |
method.visitInvokeDynamicInsn("iadd", "(II)I", MATHBOOTSTRAP, programPoint); |
|
141 |
} |
|
24751 | 142 |
return INT; |
16147 | 143 |
} |
144 |
} |