001 /* 002 $Id: Variable.java 3715 2006-03-27 16:53:34Z blackdrag $ 003 004 Copyright 2003 (C) James Strachan and Bob Mcwhirter. All Rights Reserved. 005 006 Redistribution and use of this software and associated documentation 007 ("Software"), with or without modification, are permitted provided 008 that the following conditions are met: 009 010 1. Redistributions of source code must retain copyright 011 statements and notices. Redistributions must also contain a 012 copy of this document. 013 014 2. Redistributions in binary form must reproduce the 015 above copyright notice, this list of conditions and the 016 following disclaimer in the documentation and/or other 017 materials provided with the distribution. 018 019 3. The name "groovy" must not be used to endorse or promote 020 products derived from this Software without prior written 021 permission of The Codehaus. For written permission, 022 please contact info@codehaus.org. 023 024 4. Products derived from this Software may not be called "groovy" 025 nor may "groovy" appear in their names without prior written 026 permission of The Codehaus. "groovy" is a registered 027 trademark of The Codehaus. 028 029 5. Due credit should be given to The Codehaus - 030 http://groovy.codehaus.org/ 031 032 THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS 033 ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 034 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 035 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 036 THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 037 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 038 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 039 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 040 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 041 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 042 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 043 OF THE POSSIBILITY OF SUCH DAMAGE. 044 045 */ 046 package org.codehaus.groovy.classgen; 047 048 import org.codehaus.groovy.ast.ClassHelper; 049 import org.codehaus.groovy.ast.ClassNode; 050 import org.objectweb.asm.Label; 051 052 053 /** 054 * Represents compile time variable metadata while compiling a method. 055 * 056 * @author <a href="mailto:james@coredevelopers.net">James Strachan</a> 057 * @version $Revision: 3715 $ 058 */ 059 public class Variable { 060 061 public static Variable THIS_VARIABLE = new Variable(); 062 public static Variable SUPER_VARIABLE = new Variable(); 063 064 private int index; 065 private ClassNode type; 066 private String name; 067 private boolean holder; 068 private boolean property; 069 070 // br for setting on the LocalVariableTable in the class file 071 // these fields should probably go to jvm Operand class 072 private Label startLabel = null; 073 private Label endLabel = null; 074 private boolean dynamicTyped; 075 076 private Variable(){ 077 dynamicTyped = true; 078 index=0; 079 holder=false; 080 property=false; 081 } 082 083 public Variable(int index, ClassNode type, String name) { 084 this.index = index; 085 this.type = type; 086 this.name = name; 087 } 088 089 public String getName() { 090 return name; 091 } 092 093 public ClassNode getType() { 094 return type; 095 } 096 097 public String getTypeName() { 098 return type.getName(); 099 } 100 101 /** 102 * @return the stack index for this variable 103 */ 104 public int getIndex() { 105 return index; 106 } 107 108 /** 109 * @return is this local variable shared in other scopes (and so must use a ValueHolder) 110 */ 111 public boolean isHolder() { 112 return holder; 113 } 114 115 public void setHolder(boolean holder) { 116 this.holder = holder; 117 } 118 119 public boolean isProperty() { 120 return property; 121 } 122 123 public void setProperty(boolean property) { 124 this.property = property; 125 } 126 127 public Label getStartLabel() { 128 return startLabel; 129 } 130 131 public void setStartLabel(Label startLabel) { 132 this.startLabel = startLabel; 133 } 134 135 public Label getEndLabel() { 136 return endLabel; 137 } 138 139 public void setEndLabel(Label endLabel) { 140 this.endLabel = endLabel; 141 } 142 143 public String toString() { 144 // TODO Auto-generated method stub 145 return super.toString() + "[" + type + " " + name + " (" + index + ")"; 146 } 147 148 public void setType(ClassNode type) { 149 this.type = type; 150 dynamicTyped |= type==ClassHelper.DYNAMIC_TYPE; 151 } 152 153 public void setDynamicTyped(boolean b) { 154 dynamicTyped = b; 155 } 156 157 public boolean isDynamicTyped() { 158 return dynamicTyped; 159 } 160 }