aboutsummaryrefslogtreecommitdiffstats
blob: 3a3a3c661eb0e9c7e441f5d1a31e0f958161cfcc (plain)
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
/*******************************************************************************
 * Copyright (c) 2004 INRIA.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * 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 ASMBoolean extends ASMOclAny {

	public static ASMOclType myType = new ASMOclSimpleType("Boolean", getOclAnyType());

	public ASMBoolean(boolean s) {
		super(myType);
		this.s = s;
	}

	public String toString() {
		return "" + s;
	}

	public boolean getSymbol() {
		return s;
	}

	public int hashCode() {
		return s ? 1 : 0;
	}

	public boolean equals(Object o) {
		return (o instanceof ASMBoolean) && (((ASMBoolean)o).s == s);
	}

	// Native Operations below

	public static ASMBoolean not(StackFrame frame, ASMBoolean self) {
		return new ASMBoolean(!self.s);
	}

	public static ASMBoolean and(StackFrame frame, ASMBoolean self, ASMBoolean o) {
		return new ASMBoolean(self.s && o.s);
	}

	public static ASMBoolean or(StackFrame frame, ASMBoolean self, ASMBoolean o) {
		return new ASMBoolean(self.s || o.s);
	}

	public static ASMBoolean xor(StackFrame frame, ASMBoolean self, ASMBoolean o) {
		return new ASMBoolean(self.s ^ o.s);
	}

	public static ASMBoolean implies(StackFrame frame, ASMBoolean self, ASMBoolean o) {
		return new ASMBoolean((!self.s) || (self.s && o.s));
	}

	public static ASMString toString(StackFrame frame, ASMBoolean self) {
		return new ASMString(self.s ? "true" : "false");
	}

	private boolean s;
}