1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*******************************************************************************
* Copyright (c) 2004 INRIA.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Frederic Jouault (INRIA) - initial API and implementation
*******************************************************************************/
package org.eclipse.m2m.atl.engine.vm.nativelib;
import org.eclipse.m2m.atl.engine.vm.StackFrame;
/**
* @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a>
*/
public class ASMInteger extends ASMNumber {
public static ASMOclType myType = new ASMOclSimpleType("Integer", ASMReal.myType);
public ASMInteger(int s) {
super(myType);
this.s = s;
}
public String toString() {
return "" + s;
}
public int getSymbol() {
return s;
}
public double asDouble() {
return s;
}
public boolean equals(Object o) {
return (o instanceof ASMInteger) && (((ASMInteger)o).s == s);
}
public int hashCode() {
return s;
}
// Native Operations below
public static ASMInteger abs(StackFrame frame, ASMInteger self) {
return new ASMInteger((self.s < 0) ? -self.s : self.s);
}
public static ASMInteger mod(StackFrame frame, ASMInteger self, ASMInteger o) {
return new ASMInteger(self.s % o.s);
}
public static ASMInteger div(StackFrame frame, ASMInteger self, ASMInteger o) {
return new ASMInteger(self.s / o.s);
}
public static ASMInteger max(StackFrame frame, ASMInteger self, ASMInteger o) {
return new ASMInteger(Math.max(self.s, o.s));
}
public static ASMInteger min(StackFrame frame, ASMInteger self, ASMInteger o) {
return new ASMInteger(Math.min(self.s, o.s));
}
/*
* TODO: operation overloading is not supported yet. public static ASMInteger operatorMinus(StackFrame
* frame, ASMInteger self) { return new ASMInteger(-self.s); }
*/
public static ASMNumber operatorMinus(StackFrame frame, ASMInteger self, ASMNumber o) {
if (o instanceof ASMInteger) {
return new ASMInteger(self.s - ((ASMInteger)o).s);
}
return new ASMReal(self.s - o.asDouble());
}
public static ASMNumber operatorPlus(StackFrame frame, ASMInteger self, ASMNumber o) {
if (o instanceof ASMInteger) {
return new ASMInteger(self.s + ((ASMInteger)o).s);
}
return new ASMReal(self.s + o.asDouble());
}
public static ASMNumber operatorMul(StackFrame frame, ASMInteger self, ASMNumber o) {
if (o instanceof ASMInteger) {
return new ASMInteger(self.s * ((ASMInteger)o).s);
}
return new ASMReal(self.s * o.asDouble());
}
public static ASMReal operatorDiv(StackFrame frame, ASMInteger self, ASMNumber o) {// Second parameter
// should be ASMReal
return new ASMReal(self.s / o.asDouble());
}
public static ASMBoolean operatorEQ(StackFrame frame, ASMInteger self, ASMOclAny o) {
if (o instanceof ASMInteger) {
return new ASMBoolean(self.s == ((ASMInteger)o).s);
} else if (o instanceof ASMNumber) {
return new ASMBoolean(self.s == ((ASMNumber)o).asDouble());
} else {
return new ASMBoolean(false);
}
}
public static ASMBoolean operatorNE(StackFrame frame, ASMInteger self, ASMOclAny o) {
if (o instanceof ASMInteger) {
return new ASMBoolean(self.s != ((ASMInteger)o).s);
} else if (o instanceof ASMNumber) {
return new ASMBoolean(self.s != ((ASMNumber)o).asDouble());
} else {
return new ASMBoolean(true);
}
}
public static ASMBoolean operatorLT(StackFrame frame, ASMInteger self, ASMNumber o) {
if (o instanceof ASMInteger) {
return new ASMBoolean(self.s < ((ASMInteger)o).s);
}
return new ASMBoolean(self.s < o.asDouble());
}
public static ASMBoolean operatorLE(StackFrame frame, ASMInteger self, ASMNumber o) {
if (o instanceof ASMInteger) {
return new ASMBoolean(self.s <= ((ASMInteger)o).s);
}
return new ASMBoolean(self.s <= o.asDouble());
}
public static ASMBoolean operatorGT(StackFrame frame, ASMInteger self, ASMNumber o) {
if (o instanceof ASMInteger) {
return new ASMBoolean(self.s > ((ASMInteger)o).s);
}
return new ASMBoolean(self.s > o.asDouble());
}
public static ASMBoolean operatorGE(StackFrame frame, ASMInteger self, ASMNumber o) {
if (o instanceof ASMInteger) {
return new ASMBoolean(self.s >= ((ASMInteger)o).s);
}
return new ASMBoolean(self.s >= o.asDouble());
}
public static ASMString toString(StackFrame frame, ASMInteger self) {
return new ASMString("" + self.s);
}
// additional operations, not in OCL standard library
public static ASMString toHexString(StackFrame frame, ASMInteger self) {
return new ASMString(Integer.toHexString(self.s));
}
public static ASMString toBinaryString(StackFrame frame, ASMInteger self) {
return new ASMString(Integer.toBinaryString(self.s));
}
private int s;
}
|