001 /* This file was generated with JastAdd2 (http://jastadd.org) version R20130213 */ 002 package AST; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.*; 007 import beaver.*; 008 import java.util.ArrayList; 009 import java.util.zip.*; 010 import java.io.*; 011 import java.io.FileNotFoundException; 012 import java.util.Collection; 013 /** 014 * @production ClassAccess : {@link Access}; 015 * @ast node 016 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:39 017 */ 018 public class ClassAccess extends Access implements Cloneable { 019 /** 020 * @apilevel low-level 021 */ 022 public void flushCache() { 023 } 024 /** 025 * @apilevel internal 026 */ 027 public void flushCollectionCache() { 028 } 029 /** 030 * @apilevel internal 031 */ 032 @SuppressWarnings({"unchecked", "cast"}) 033 public ClassAccess clone() throws CloneNotSupportedException { 034 ClassAccess node = (ClassAccess)super.clone(); 035 node.type_computed = false; 036 node.type_value = null; 037 node.in$Circle(false); 038 node.is$Final(false); 039 return node; 040 } 041 /** 042 * @apilevel internal 043 */ 044 @SuppressWarnings({"unchecked", "cast"}) 045 public ClassAccess copy() { 046 047 try { 048 ClassAccess node = (ClassAccess) clone(); 049 node.parent = null; 050 if(children != null) 051 node.children = (ASTNode[]) children.clone(); 052 053 return node; 054 } catch (CloneNotSupportedException e) { 055 throw new Error("Error: clone not supported for " + getClass().getName()); 056 } 057 058 }/** 059 * Create a deep copy of the AST subtree at this node. 060 * The copy is dangling, i.e. has no parent. 061 * @return dangling copy of the subtree at this node 062 * @apilevel low-level 063 */ 064 @SuppressWarnings({"unchecked", "cast"}) 065 public ClassAccess fullCopy() { 066 067 ClassAccess tree = (ClassAccess) copy(); 068 if (children != null) { 069 for (int i = 0; i < children.length; ++i) { 070 071 ASTNode child = (ASTNode) children[i]; 072 if(child != null) { 073 child = child.fullCopy(); 074 tree.setChild(child, i); 075 } 076 } 077 } 078 return tree; 079 080 } /** 081 * @ast method 082 * @aspect NameCheck 083 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/NameCheck.jrag:177 084 */ 085 public void nameCheck() { 086 if(isQualified() && !qualifier().isTypeAccess()) 087 error("class literal may only contain type names"); 088 } 089 /** 090 * @ast method 091 * @aspect PrettyPrint 092 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:520 093 */ 094 public void toString(StringBuffer s) { 095 s.append("class"); 096 } 097 /** 098 * @ast method 099 * @aspect CreateBCode 100 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1571 101 */ 102 public void refined_CreateBCode_ClassAccess_createBCode(CodeGeneration gen) { 103 if(prevExpr().type().isPrimitiveType() || prevExpr().type().isVoid()) { 104 TypeDecl typeDecl = lookupType("java.lang", prevExpr().type().primitiveClassName()); 105 SimpleSet c = typeDecl.memberFields("TYPE"); 106 FieldDeclaration f = (FieldDeclaration)c.iterator().next(); 107 f.emitLoadField(gen, typeDecl); 108 } 109 else { 110 FieldDeclaration f = hostType().topLevelType().createStaticClassField(prevExpr().type().referenceClassFieldName()); 111 // add method to perform lookup as a side-effect 112 MethodDecl m = hostType().topLevelType().createStaticClassMethod(); 113 114 int next_label = hostType().constantPool().newLabel(); 115 int end_label = hostType().constantPool().newLabel(); 116 f.emitLoadField(gen, hostType()); 117 gen.emitBranchNonNull(next_label); 118 119 // emit string literal 120 121 StringLiteral.push(gen, prevExpr().type().jvmName()); 122 m.emitInvokeMethod(gen, hostType()); 123 gen.emitDup(); 124 f.emitStoreField(gen, hostType()); 125 gen.emitGoto(end_label); 126 gen.addLabel(next_label); 127 gen.changeStackDepth(-1); 128 f.emitLoadField(gen, hostType()); 129 gen.addLabel(end_label); 130 } 131 } 132 /** 133 * @ast method 134 * 135 */ 136 public ClassAccess() { 137 super(); 138 139 140 } 141 /** 142 * Initializes the child array to the correct size. 143 * Initializes List and Opt nta children. 144 * @apilevel internal 145 * @ast method 146 * @ast method 147 * 148 */ 149 public void init$Children() { 150 } 151 /** 152 * @apilevel low-level 153 * @ast method 154 * 155 */ 156 protected int numChildren() { 157 return 0; 158 } 159 /** 160 * @apilevel internal 161 * @ast method 162 * 163 */ 164 public boolean mayHaveRewrite() { 165 return false; 166 } 167 /** 168 * @ast method 169 * @aspect Version 170 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/Version.jrag:19 171 */ 172 public void createBCode(CodeGeneration gen) { 173 if(prevExpr().type().isPrimitiveType() || prevExpr().type().isVoid()) 174 refined_CreateBCode_ClassAccess_createBCode(gen); 175 else { 176 int index = gen.constantPool().addClass(prevExpr().type().jvmName()); 177 if(index < 256) 178 gen.emit(Bytecode.LDC).add(index); 179 else 180 gen.emit(Bytecode.LDC_W).add2(index); 181 } 182 } 183 /** 184 * @ast method 185 * @aspect Version 186 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/Version.jrag:16 187 */ 188 public void transformation() { 189 super.transformation(); 190 } 191 /** 192 * @ast method 193 * @aspect TypeAnalysis 194 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:401 195 */ 196 private TypeDecl refined_TypeAnalysis_ClassAccess_type() 197 { return lookupType("java.lang", "Class"); } 198 /** 199 * @attribute syn 200 * @aspect AccessTypes 201 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/ResolveAmbiguousNames.jrag:45 202 */ 203 public boolean isClassAccess() { 204 ASTNode$State state = state(); 205 try { return true; } 206 finally { 207 } 208 } 209 /** 210 * @attribute syn 211 * @aspect SyntacticClassification 212 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/SyntacticClassification.jrag:56 213 */ 214 public NameType predNameType() { 215 ASTNode$State state = state(); 216 try { return NameType.TYPE_NAME; } 217 finally { 218 } 219 } 220 /** 221 * @apilevel internal 222 */ 223 protected boolean type_computed = false; 224 /** 225 * @apilevel internal 226 */ 227 protected TypeDecl type_value; 228 /** 229 * @attribute syn 230 * @aspect Generics 231 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:119 232 */ 233 @SuppressWarnings({"unchecked", "cast"}) 234 public TypeDecl type() { 235 if(type_computed) { 236 return type_value; 237 } 238 ASTNode$State state = state(); 239 int num = state.boundariesCrossed; 240 boolean isFinal = this.is$Final(); 241 type_value = type_compute(); 242 if(isFinal && num == state().boundariesCrossed){ type_computed = true; } 243 return type_value; 244 } 245 /** 246 * @apilevel internal 247 */ 248 private TypeDecl type_compute() { 249 GenericClassDecl d = (GenericClassDecl)refined_TypeAnalysis_ClassAccess_type(); 250 TypeDecl type = qualifier().type(); 251 if(type.isPrimitiveType()) 252 type = type.boxed(); 253 ArrayList list = new ArrayList(); 254 list.add(type); 255 return d.lookupParTypeDecl(list); 256 } 257 /** 258 * @apilevel internal 259 */ 260 public ASTNode rewriteTo() { 261 return super.rewriteTo(); 262 } 263 }