2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 public final class Variable implements CharSequence {
21 public static final int TYPE_INT = 0;
22 public static final int TYPE_LONG = 1;
23 public static final int TYPE_FLOAT = 2;
24 public static final int TYPE_DOUBLE = 3;
25 public static final int TYPE_REF = 4;
27 public static final int LAST_TYPE = TYPE_REF;
29 private static final String STACK_VAR_PREFIX = "st";
31 private final String name;
32 private final int type;
33 private final int index;
35 private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' };
37 private Variable(final String prefix, final int type, final int index) {
38 this.name = prefix + TYPE_IDS[type] + index;
43 public static Variable getStackVariable(
44 final int type, final int index) {
45 // TODO: precreate frequently used variables
46 return new Variable(STACK_VAR_PREFIX, type, index);
49 public String getName() {
53 public int getType() {
57 public int getIndex() {
61 public boolean isCategory2() {
62 return (type == TYPE_LONG) || (type == TYPE_DOUBLE);
71 public char charAt(final int index) {
72 return name.charAt(index);
76 public CharSequence subSequence(final int start, final int end) {
77 return name.subSequence(start, end);
81 public int hashCode() {
82 return name.hashCode();
86 public boolean equals(final Object other) {
90 if (!(other instanceof Variable)) {
94 return name.equals(((Variable) other).name);
98 public String toString() {