]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/DoubleConstant.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / DoubleConstant.java
1 package org.simantics.scl.compiler.constants;
2
3 import org.cojen.classfile.TypeDesc;
4 import org.objectweb.asm.Label;
5 import org.simantics.scl.compiler.internal.codegen.continuations.Cont;
6 import org.simantics.scl.compiler.internal.codegen.references.IVal;
7 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
8 import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
9 import org.simantics.scl.compiler.types.Types;
10
11 public class DoubleConstant extends Constant {
12     double value;
13
14     public DoubleConstant(double value) {
15         super(Types.DOUBLE);
16         this.value = value;
17     }
18     
19     @Override
20     public void push(MethodBuilder mb) {
21         mb.loadConstant(value);
22     }
23     
24     @Override
25     public String toString() {
26         return String.valueOf(value);
27     }
28
29     @Override
30     public int hashCode() {
31         final int prime = 31;
32         int result = 1;
33         long temp;
34         temp = Double.doubleToLongBits(value);
35         result = prime * result + (int) (temp ^ (temp >>> 32));
36         return result;
37     }
38
39     @Override
40     public boolean equals(Object obj) {
41         if (this == obj)
42             return true;
43         if (obj == null)
44             return false;
45         if (getClass() != obj.getClass())
46             return false;
47         DoubleConstant other = (DoubleConstant) obj;
48         if (Double.doubleToLongBits(value) != Double
49                 .doubleToLongBits(other.value))
50             return false;
51         return true;
52     }
53     
54     @Override
55     public void deconstruct(MethodBuilder mb, IVal parameter, Cont success,
56             Label failure) {        
57         mb.push(parameter, Types.DOUBLE);
58         mb.loadConstant(value);
59         mb.ifComparisonBranch(failure, "!=", TypeDesc.DOUBLE);
60         mb.jump(success);
61     }
62     
63     @Override
64     public int constructorTag() {
65         return 0;
66     }
67     
68     @Override
69     public Object realizeValue(TransientClassBuilder classBuilder) {
70         return value;
71     }
72 }