vm/src/main/java/org/apidesign/vm4brwsr/Variable.java
branchregisters
changeset 319 83f638b13242
parent 310 ec7d8bc17725
     1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Variable.java	Wed Dec 12 14:07:53 2012 +0100
     1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Variable.java	Fri Dec 14 15:06:53 2012 +0100
     1.3 @@ -1,100 +1,100 @@
     1.4 -/**
     1.5 - * Back 2 Browser Bytecode Translator
     1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, version 2 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. Look for COPYING file in the top folder.
    1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 - */
    1.21 -package org.apidesign.vm4brwsr;
    1.22 -
    1.23 -final class Variable implements CharSequence {
    1.24 -    private static final String STACK_VAR_PREFIX = "st";
    1.25 -    private static final String LOCAL_VAR_PREFIX = "lc";
    1.26 -
    1.27 -    private final String name;
    1.28 -    private final int type;
    1.29 -    private final int index;
    1.30 -
    1.31 -    private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' };
    1.32 -
    1.33 -    private Variable(final String prefix, final int type, final int index) {
    1.34 -        this.name = prefix + TYPE_IDS[type] + index;
    1.35 -        this.type = type;
    1.36 -        this.index = index;
    1.37 -    }
    1.38 -
    1.39 -    public static Variable getStackVariable(
    1.40 -            final int type, final int index) {
    1.41 -        // TODO: precreate frequently used variables
    1.42 -        return new Variable(STACK_VAR_PREFIX, type, index);
    1.43 -    }
    1.44 -
    1.45 -    public static Variable getLocalVariable(
    1.46 -            final int type, final int index) {
    1.47 -        // TODO: precreate frequently used variables
    1.48 -        return new Variable(LOCAL_VAR_PREFIX, type, index);
    1.49 -    }
    1.50 -
    1.51 -    public String getName() {
    1.52 -        return name;
    1.53 -    }
    1.54 -
    1.55 -    public int getType() {
    1.56 -        return type;
    1.57 -    }
    1.58 -
    1.59 -    public int getIndex() {
    1.60 -        return index;
    1.61 -    }
    1.62 -
    1.63 -    public boolean isCategory2() {
    1.64 -        return VarType.isCategory2(type);
    1.65 -    }
    1.66 -
    1.67 -    @Override
    1.68 -    public int length() {
    1.69 -        return name.length();
    1.70 -    }
    1.71 -
    1.72 -    @Override
    1.73 -    public char charAt(final int index) {
    1.74 -        return name.charAt(index);
    1.75 -    }
    1.76 -
    1.77 -    @Override
    1.78 -    public CharSequence subSequence(final int start, final int end) {
    1.79 -        return name.subSequence(start, end);
    1.80 -    }
    1.81 -
    1.82 -    @Override
    1.83 -    public int hashCode() {
    1.84 -        return name.hashCode();
    1.85 -    }
    1.86 -
    1.87 -    @Override
    1.88 -    public boolean equals(final Object other) {
    1.89 -        if (this == other) {
    1.90 -            return true;
    1.91 -        }
    1.92 -        if (!(other instanceof Variable)) {
    1.93 -            return false;
    1.94 -        }
    1.95 -
    1.96 -        return name.equals(((Variable) other).name);
    1.97 -    }
    1.98 -
    1.99 -    @Override
   1.100 -    public String toString() {
   1.101 -        return name;
   1.102 -    }
   1.103 -}
   1.104 +/**
   1.105 + * Back 2 Browser Bytecode Translator
   1.106 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   1.107 + *
   1.108 + * This program is free software: you can redistribute it and/or modify
   1.109 + * it under the terms of the GNU General Public License as published by
   1.110 + * the Free Software Foundation, version 2 of the License.
   1.111 + *
   1.112 + * This program is distributed in the hope that it will be useful,
   1.113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   1.115 + * GNU General Public License for more details.
   1.116 + *
   1.117 + * You should have received a copy of the GNU General Public License
   1.118 + * along with this program. Look for COPYING file in the top folder.
   1.119 + * If not, see http://opensource.org/licenses/GPL-2.0.
   1.120 + */
   1.121 +package org.apidesign.vm4brwsr;
   1.122 +
   1.123 +final class Variable implements CharSequence {
   1.124 +    private static final String STACK_VAR_PREFIX = "st";
   1.125 +    private static final String LOCAL_VAR_PREFIX = "lc";
   1.126 +
   1.127 +    private final String name;
   1.128 +    private final int type;
   1.129 +    private final int index;
   1.130 +
   1.131 +    private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' };
   1.132 +
   1.133 +    private Variable(final String prefix, final int type, final int index) {
   1.134 +        this.name = prefix + TYPE_IDS[type] + index;
   1.135 +        this.type = type;
   1.136 +        this.index = index;
   1.137 +    }
   1.138 +
   1.139 +    public static Variable getStackVariable(
   1.140 +            final int type, final int index) {
   1.141 +        // TODO: precreate frequently used variables
   1.142 +        return new Variable(STACK_VAR_PREFIX, type, index);
   1.143 +    }
   1.144 +
   1.145 +    public static Variable getLocalVariable(
   1.146 +            final int type, final int index) {
   1.147 +        // TODO: precreate frequently used variables
   1.148 +        return new Variable(LOCAL_VAR_PREFIX, type, index);
   1.149 +    }
   1.150 +
   1.151 +    public String getName() {
   1.152 +        return name;
   1.153 +    }
   1.154 +
   1.155 +    public int getType() {
   1.156 +        return type;
   1.157 +    }
   1.158 +
   1.159 +    public int getIndex() {
   1.160 +        return index;
   1.161 +    }
   1.162 +
   1.163 +    public boolean isCategory2() {
   1.164 +        return VarType.isCategory2(type);
   1.165 +    }
   1.166 +
   1.167 +    @Override
   1.168 +    public int length() {
   1.169 +        return name.length();
   1.170 +    }
   1.171 +
   1.172 +    @Override
   1.173 +    public char charAt(final int index) {
   1.174 +        return name.charAt(index);
   1.175 +    }
   1.176 +
   1.177 +    @Override
   1.178 +    public CharSequence subSequence(final int start, final int end) {
   1.179 +        return name.subSequence(start, end);
   1.180 +    }
   1.181 +
   1.182 +    @Override
   1.183 +    public int hashCode() {
   1.184 +        return name.hashCode();
   1.185 +    }
   1.186 +
   1.187 +    @Override
   1.188 +    public boolean equals(final Object other) {
   1.189 +        if (this == other) {
   1.190 +            return true;
   1.191 +        }
   1.192 +        if (!(other instanceof Variable)) {
   1.193 +            return false;
   1.194 +        }
   1.195 +
   1.196 +        return name.equals(((Variable) other).name);
   1.197 +    }
   1.198 +
   1.199 +    @Override
   1.200 +    public String toString() {
   1.201 +        return name;
   1.202 +    }
   1.203 +}