]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/CharacterConstant.java
Merge "(refs #7866) Better error location for the NPE in compilation"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / CharacterConstant.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 CharacterConstant extends Constant {
12     char value;
13
14     public CharacterConstant(char value) {
15         super(Types.CHARACTER);
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 "'" + Character.toString(value) + "'";
27     }
28     
29     public char getValue() {
30         return value;
31     }
32
33     @Override
34     public int hashCode() {
35         return value;
36     }
37
38     @Override
39     public boolean equals(Object obj) {
40         if (this == obj)
41             return true;
42         if (obj == null)
43             return false;
44         if (getClass() != obj.getClass())
45             return false;
46         CharacterConstant other = (CharacterConstant) obj;
47         if (value != other.value)
48             return false;
49         return true;
50     }
51     
52     @Override
53     public void deconstruct(MethodBuilder mb, IVal parameter, Cont success,
54             Label failure) {
55         mb.push(parameter, Types.CHARACTER);
56         mb.loadConstant(value);
57         mb.ifComparisonBranch(failure, "!=", TypeDesc.CHAR);
58         mb.jump(success);
59     }
60     
61     @Override
62     public int constructorTag() {
63         return 0;
64     }
65
66     @Override
67     public Object realizeValue(TransientClassBuilder classBuilder) {
68         return value;
69     }
70 }