Source code: Clazz/jq_Field.java
1 // jq_Field.java, created Mon Feb 5 23:23:20 2001 by joewhaley
2 // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3 // Licensed under the terms of the GNU LGPL; see COPYING for details.
4 package Clazz;
5
6 import java.io.DataInput;
7 import java.io.IOException;
8 import java.util.Map;
9
10 import Bootstrap.PrimordialClassLoader;
11 import ClassLib.ClassLibInterface;
12 import Compil3r.Quad.AndersenInterface.AndersenField;
13 import Compil3r.Quad.AndersenInterface.AndersenType;
14 import Main.jq;
15
16 /*
17 * @author John Whaley <jwhaley@alum.mit.edu>
18 * @version $Id: jq_Field.java,v 1.19 2003/05/12 10:05:12 joewhaley Exp $
19 */
20 public abstract class jq_Field extends jq_Member implements AndersenField {
21
22 protected jq_Type type;
23
24 // clazz, name, desc, access_flags are inherited
25 protected jq_Field(jq_Class clazz, jq_NameAndDesc nd) {
26 super(clazz, nd);
27 type = PrimordialClassLoader.getOrCreateType(clazz.getClassLoader(), nd.getDesc());
28 }
29
30 public void load(char access_flags, DataInput in)
31 throws IOException, ClassFormatError {
32 super.load(access_flags, in);
33 if (jq.RunningNative)
34 ClassLibInterface.DEFAULT.initNewField((java.lang.reflect.Field)this.getJavaLangReflectMemberObject(), this);
35 }
36
37 public void load(char access_flags, Map attributes) {
38 super.load(access_flags, attributes);
39 if (jq.RunningNative)
40 ClassLibInterface.DEFAULT.initNewField((java.lang.reflect.Field)this.getJavaLangReflectMemberObject(), this);
41 }
42
43 public final jq_Type getType() { return type; }
44 public final AndersenType and_getType() { return getType(); }
45 public boolean isVolatile() { chkState(STATE_LOADING2); return (access_flags & ACC_VOLATILE) != 0; }
46 public boolean isTransient() { chkState(STATE_LOADING2); return (access_flags & ACC_TRANSIENT) != 0; }
47
48 public abstract int getWidth();
49
50 public void accept(jq_FieldVisitor mv) {
51 mv.visitField(this);
52 }
53
54 static interface Delegate {
55 boolean isCodeAddressType(jq_Field t);
56 boolean isHeapAddressType(jq_Field t);
57 boolean isStackAddressType(jq_Field t);
58 }
59
60 private static Delegate _delegate;
61
62 public final boolean isCodeAddressType() {
63 return _delegate.isCodeAddressType(this);
64 }
65 public final boolean isHeapAddressType() {
66 return _delegate.isHeapAddressType(this);
67 }
68 public final boolean isStackAddressType() {
69 return _delegate.isStackAddressType(this);
70 }
71
72 public String toString() { return getDeclaringClass()+"."+getName(); }
73
74 static {
75 /* Set up delegates. */
76 _delegate = null;
77 boolean nullVM = jq.nullVM || System.getProperty("joeq.nullvm") != null;
78 if (!nullVM) {
79 _delegate = attemptDelegate("Clazz.Delegates$Field");
80 }
81 if (_delegate == null) {
82 _delegate = new NullDelegates.Field();
83 }
84 }
85
86 private static Delegate attemptDelegate(String s) {
87 String type = "field delegate";
88 try {
89 Class c = Class.forName(s);
90 return (Delegate)c.newInstance();
91 } catch (java.lang.ClassNotFoundException x) {
92 System.err.println("Cannot find "+type+" "+s+": "+x);
93 } catch (java.lang.InstantiationException x) {
94 System.err.println("Cannot instantiate "+type+" "+s+": "+x);
95 } catch (java.lang.IllegalAccessException x) {
96 System.err.println("Cannot access "+type+" "+s+": "+x);
97 }
98 return null;
99 }
100
101 }