1 /* 2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.scenario.effect.compiler.model; 27 28 import java.util.Locale; 29 30 /** 31 */ 32 public class Variable { 33 34 private final String name; 35 private final Type type; 36 private final Qualifier qual; 37 private final Precision precision; 38 private final int reg; 39 private final int arraySize; 40 private final Object constValue; 41 private final boolean isParam; 42 private int refCount; 43 44 Variable(String name, Type type) { 45 this(name, type, null, null, -1, -1, null, false); 46 } 47 48 Variable(String name, Type type, Qualifier qual, Precision precision, 49 int reg, int arraySize, Object constValue, boolean isParam) 50 { 51 if (name == null) { 52 throw new IllegalArgumentException("Name must be non-null"); 53 } 54 if (type == null) { 55 throw new IllegalArgumentException("Type must be non-null"); 56 } 57 this.name = name; 58 this.type = type; 59 this.qual = qual; 60 this.precision = precision; 61 this.reg = reg; 62 this.arraySize = arraySize; 63 this.constValue = constValue; 64 this.isParam = isParam; 65 } 66 67 public String getName() { 68 return name; 69 } 70 71 public Type getType() { 72 return type; 73 } 74 75 public Qualifier getQualifier() { 76 return qual; 77 } 78 79 public Precision getPrecision() { 80 return precision; 81 } 82 83 public int getReg() { 84 return reg; 85 } 86 87 public boolean isArray() { 88 return arraySize > 0; 89 } 90 91 public int getArraySize() { 92 return arraySize; 93 } 94 95 public Object getConstValue() { 96 return constValue; 97 } 98 99 public boolean isParam() { 100 return isParam; 101 } 102 103 /** 104 * Returns the JavaBean-style accessor name for this variable. For 105 * example, if variable.getName() returns "someVariable", this method 106 * will return "getSomeVariable". 107 */ 108 public String getAccessorName() { 109 return "get" + name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1); 110 } 111 112 public void incrementRefCount() { 113 refCount++; 114 } 115 116 public boolean isReferenced() { 117 return refCount > 0; 118 } 119 }