Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

nci/suif/suif2b/j2s/metaloader/jhl_unit.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 // $Id: jhl_unit.h,v 1.2 2000/07/24 00:33:31 brm Exp $
00003 
00004 #ifndef __JHL_UNIT_H
00005 #define __JHL_UNIT_H
00006 
00007 
00008 #include <iostream.h>
00009 
00010 #include "j2s_metaloader/jhl_class_forwards.h"
00011 #include "j2s_metaloader/jhl_array_templ.h"
00012 #include "j2s_metaloader/jhl_access_flags.h"
00013 
00014 
00015 /*
00016  * Class for a Java class or interface (JVMS 4.1).
00017  * Def.: unit means either class or interface.
00018  * _classfile points to the low-level representation of the
00019  * corresponding unit.
00020  * If is_root() is true then the class is java.lang.Object
00021  * and _super_class is a NULL-pointer.
00022  * If the SourceFile attribute does not exist then _sourcefile
00023  * is NULL.
00024  * The constructor initialized the name of the class only!
00025  * The method init must be used to read in the whole structure.
00026  * This is due to recursion in Java classes, for example
00027  *   class X { X obj; }.
00028  */
00029 class jhl_Unit 
00030 #ifdef BDW_GC
00031  : public gc
00032 #endif
00033 {
00034 private:
00035   jhl_Unit(jhl_Unit&);
00036   jhl_Unit operator=(jhl_Unit&);
00037 
00038   static const char* const _clinit_str;
00039   static const char* const _clinit_descriptor_str;
00040   static const int _init_num_children;
00041 
00042   jhl_AccessFlags* _access_flags;
00043   jhl_FQName* _name;
00044   jhl_Unit* _super_class;
00045   jhl_Array<jhl_Unit>* _interfaces;
00046   jhl_Array<jhl_Field>* _fields;
00047   jhl_Array<jhl_Method>* _methods;
00048   jhl_Name* _sourcefile;
00049 
00050   jvm_Classfile* _classfile;
00051 
00052   int _children_index;
00053   jhl_GrowableArray<jhl_Unit>* _children;
00054 
00055   // value numbering (for subclass test)
00056   long _left;
00057   long _right;
00058   
00059   void add_child(jhl_Unit* child);
00060   
00061 public:
00062   jhl_Unit(jvm_Classfile* cf);
00063   ~jhl_Unit();
00064 
00065   void  init(jvm_Classfile* cf); 
00066 
00067   bool is_public()    const { return _access_flags->is_public(); }
00068   bool is_final()     const { return _access_flags->is_final(); }
00069   bool is_super()     const { return _access_flags->is_super(); }
00070   bool is_interface() const { return _access_flags->is_interface(); }
00071   bool is_abstract()  const { return _access_flags->is_abstract(); }
00072 
00073   bool is_class()     const { return !is_interface(); }
00074   bool is_root()      const { return _super_class == NULL; }
00075   bool is_interfaceimplemented (jhl_Unit* iface) const;
00076   
00077   bool has_sourcefile() const { return _sourcefile != NULL; }
00078   bool has_method(jhl_Name* mn, jhl_MethodType* mt) const; 
00079   jhl_Method* get_method (jhl_Name* mn, jhl_MethodType* mt) const;
00080   bool has_clinit() const;
00081   jhl_Method* get_clinit() const;
00082   jhl_Unit* get_clinit_super();
00083 
00084   // accessors
00085   jhl_AccessFlags* access_flags()   const { return _access_flags; }
00086   jhl_FQName* name()                const { return _name; }
00087   jvm_Utf8Constant* utf8_name()     const;
00088   char* char_name()                 const;
00089   jhl_Unit* super_class()           const { return _super_class; }
00090   jhl_Array<jhl_Unit>* interfaces() const { return _interfaces; }
00091   jhl_Array<jhl_Field>* fields()    const { return _fields; }
00092   jhl_Array<jhl_Method>* methods()  const { return _methods; }
00093   jhl_Name* sourcefile()            const { return _sourcefile; }
00094   jvm_Classfile* classfile()        const { return _classfile; }
00095 
00096   jhl_Array<jhl_Unit>* children()   const;
00097   bool is_leaf_class()           const { return _children_index == 0; }
00098   long left_value_number()          const { return _left; }
00099   long right_value_number()         const { return _right; }
00100 
00101   // accessors by name and Type
00102   jhl_Method* lookupMethod(jhl_Name* m, jhl_MethodType* sig) const;
00103   jhl_Field*  lookupField (jhl_Name* f) const;
00104 
00105   jhl_Method* findMethod(jhl_Name* m) const;
00106 
00107   // modifiers
00108   void set_access_flags(jhl_AccessFlags* a)    { _access_flags = a; }
00109   void set_name(jhl_FQName* n)                 { _name = n; }
00110   void set_super_class(jhl_Unit* u)            { _super_class = u; }
00111   void set_interfaces(jhl_Array<jhl_Unit>* i)  { _interfaces = i; }
00112   void set_fields(jhl_Array<jhl_Field>* f)     { _fields = f; }
00113   void set_methods(jhl_Array<jhl_Method>* m)   { _methods = m; }
00114   void set_sourcefile(jhl_Name* n)             { _sourcefile = n; }
00115   void set_classfile(jvm_Classfile* cf)        { _classfile = cf; }
00116 
00117   void set_left_value_number(long l)           { _left= l; }
00118   void set_right_value_number(long r)          { _right= r; }
00119 
00120   bool verify() const;
00121   void print() const;
00122   void print_filepath() const;
00123 
00124   friend ostream& operator<<(ostream& os, jhl_Unit* u);
00125 };
00126 
00127 ostream& operator<<(ostream& os, jhl_Unit* u);
00128 
00129 #endif /* __JHL_UNIT_H */

Generated at Mon Jul 31 13:42:19 2000 for NCI SUIF by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000