[llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h

Alkis Evlogimenos alkis at cs.uiuc.edu
Sat Feb 12 12:18:44 PST 2005



Changes in directory llvm-java/include/llvm/Java:

ClassFile.h updated: 1.29 -> 1.30
---
Log message:

Pass the parent classfile around when creating children objects in the
classfile structures. Constify the classes a bit more and update
users.


---
Diffs of the changes:  (+47 -51)

 ClassFile.h |   98 ++++++++++++++++++++++++++++--------------------------------
 1 files changed, 47 insertions(+), 51 deletions(-)


Index: llvm-java/include/llvm/Java/ClassFile.h
diff -u llvm-java/include/llvm/Java/ClassFile.h:1.29 llvm-java/include/llvm/Java/ClassFile.h:1.30
--- llvm-java/include/llvm/Java/ClassFile.h:1.29	Fri Feb 11 14:19:33 2005
+++ llvm-java/include/llvm/Java/ClassFile.h	Sat Feb 12 14:17:57 2005
@@ -69,14 +69,14 @@
                           const std::string& name);
 
   class ClassFile {
-    static ClassFile* readClassFile(std::istream& is);
+    static const ClassFile* readClassFile(std::istream& is);
     static std::vector<llvm::sys::Path> getClassPath();
     static sys::Path getFileForClass(const std::string& classname);
 
     typedef std::map<std::string, Method*> Name2MethodMap;
 
   public:
-    static ClassFile* get(const std::string& classname);
+    static const ClassFile* get(const std::string& classname);
 
     ~ClassFile();
 
@@ -90,6 +90,8 @@
     ConstantMethodRef* getConstantMethodRef(unsigned index) const;
     ConstantInterfaceMethodRef*
     getConstantInterfaceMethodRef(unsigned index) const;
+    ConstantNameAndType* getConstantNameAndType(unsigned index) const;
+    ConstantUtf8* getConstantUtf8(unsigned index) const;
 
     bool isPublic() const { return accessFlags_ & ACC_PUBLIC; }
     bool isFinal() const { return accessFlags_ & ACC_FINAL; }
@@ -135,10 +137,10 @@
 
   class Constant {
   protected:
-    const ConstantPool& cPool_;
+    const ClassFile* parent_;
 
-    Constant(const ConstantPool& cp)
-      : cPool_(cp) { }
+    Constant(const ClassFile* cf)
+      : parent_(cf) { }
 
   public:
     enum Tag {
@@ -155,11 +157,12 @@
       UTF8 = 1
     };
 
-    static Constant* readConstant(const ConstantPool& cp,
-                                  std::istream& is);
+    static Constant* readConstant(const ClassFile* cf, std::istream& is);
 
     virtual bool isSingleSlot() { return true; }
     bool isDoubleSlot() { return !isSingleSlot(); }
+    const ClassFile* getParent() { return parent_; }
+
     virtual ~Constant();
 
     virtual std::ostream& dump(std::ostream& os) const = 0;
@@ -172,9 +175,9 @@
   class ConstantClass : public Constant {
     uint16_t nameIdx_;
   public:
-    ConstantClass(const ConstantPool& cp, std::istream& is);
+    ConstantClass(const ClassFile* cf, std::istream& is);
     ConstantUtf8* getName() const {
-      return (ConstantUtf8*) cPool_[nameIdx_];
+      return parent_->getConstantUtf8(nameIdx_);
     }
     std::ostream& dump(std::ostream& os) const;
   };
@@ -183,42 +186,42 @@
     uint16_t classIdx_;
     uint16_t nameAndTypeIdx_;
   protected:
-    ConstantMemberRef(const ConstantPool& cp, std::istream& is);
+    ConstantMemberRef(const ClassFile* cf, std::istream& is);
 
   public:
     ConstantClass* getClass() const {
-      return (ConstantClass*) cPool_[classIdx_];
+      return parent_->getConstantClass(classIdx_);
     }
     ConstantNameAndType* getNameAndType() const {
-      return (ConstantNameAndType*) cPool_[nameAndTypeIdx_];
+      return parent_->getConstantNameAndType(nameAndTypeIdx_);
     }
     std::ostream& dump(std::ostream& os) const;
   };
 
   class ConstantFieldRef : public ConstantMemberRef {
   public:
-    ConstantFieldRef(const ConstantPool& cp, std::istream& is)
-      : ConstantMemberRef(cp, is) { }
+    ConstantFieldRef(const ClassFile* cf, std::istream& is)
+      : ConstantMemberRef(cf, is) { }
   };
 
   class ConstantMethodRef : public ConstantMemberRef {
   public:
-    ConstantMethodRef(const ConstantPool& cp, std::istream& is)
-      : ConstantMemberRef(cp, is) { }
+    ConstantMethodRef(const ClassFile* cf, std::istream& is)
+      : ConstantMemberRef(cf, is) { }
   };
 
   class ConstantInterfaceMethodRef : public ConstantMemberRef {
   public:
-    ConstantInterfaceMethodRef(const ConstantPool& cp, std::istream& is)
-      : ConstantMemberRef(cp, is) { }
+    ConstantInterfaceMethodRef(const ClassFile* cf, std::istream& is)
+      : ConstantMemberRef(cf, is) { }
   };
 
   class ConstantString : public Constant {
     uint16_t stringIdx_;
   public:
-    ConstantString(const ConstantPool& cp, std::istream& is);
+    ConstantString(const ClassFile* cf, std::istream& is);
     ConstantUtf8* getValue() const {
-      return  (ConstantUtf8*) cPool_[stringIdx_];
+      return parent_->getConstantUtf8(stringIdx_);
     }
     std::ostream& dump(std::ostream& os) const;
   };
@@ -226,7 +229,7 @@
   class ConstantInteger : public Constant {
     int32_t value_;
   public:
-    ConstantInteger(const ConstantPool& cp, std::istream& is);
+    ConstantInteger(const ClassFile* cf, std::istream& is);
     int32_t getValue() const { return value_; }
     std::ostream& dump(std::ostream& os) const;
   };
@@ -234,7 +237,7 @@
   class ConstantFloat : public Constant {
     float value_;
   public:
-    ConstantFloat(const ConstantPool& cp, std::istream& is);
+    ConstantFloat(const ClassFile* cf, std::istream& is);
     float getValue() const { return value_; }
     std::ostream& dump(std::ostream& os) const;
   };
@@ -242,7 +245,7 @@
   class ConstantLong : public Constant {
     int64_t value_;
   public:
-    ConstantLong(const ConstantPool& cp, std::istream& is);
+    ConstantLong(const ClassFile* cf, std::istream& is);
     virtual bool isSingleSlot() { return false; }
     int64_t getValue() const { return value_; }
     std::ostream& dump(std::ostream& os) const;
@@ -251,7 +254,7 @@
   class ConstantDouble : public Constant {
     double value_;
   public:
-    ConstantDouble(const ConstantPool& cp, std::istream& is);
+    ConstantDouble(const ClassFile* cf, std::istream& is);
     virtual bool isSingleSlot() { return false; }
     double getValue() const { return value_; }
     std::ostream& dump(std::ostream& os) const;
@@ -261,12 +264,12 @@
     uint16_t nameIdx_;
     uint16_t descriptorIdx_;
   public:
-    ConstantNameAndType(const ConstantPool& cp, std::istream& is);
+    ConstantNameAndType(const ClassFile* cf, std::istream& is);
     ConstantUtf8* getName() const {
-      return (ConstantUtf8*) cPool_[nameIdx_];
+      return parent_->getConstantUtf8(nameIdx_);
     }
     ConstantUtf8* getDescriptor() const {
-      return (ConstantUtf8*) cPool_[descriptorIdx_];
+      return parent_->getConstantUtf8(descriptorIdx_);
     }
     std::ostream& dump(std::ostream& os) const;
   };
@@ -274,7 +277,7 @@
   class ConstantUtf8 : public Constant {
     std::string utf8_;
   public:
-    ConstantUtf8(const ConstantPool& cp, std::istream& is);
+    ConstantUtf8(const ClassFile* cf, std::istream& is);
     const std::string& str() const { return utf8_; }
 
     std::ostream& dump(std::ostream& os) const;
@@ -282,19 +285,17 @@
 
   class Field {
   private:
-    ClassFile* parent_;
+    const ClassFile* parent_;
     uint16_t accessFlags_;
     ConstantUtf8* name_;
     ConstantUtf8* descriptor_;
     Attributes attributes_;
 
-    Field(ClassFile* parent, const ConstantPool& cp, std::istream& is);
+    Field(const ClassFile* parent, std::istream& is);
 
   public:
-    static Field* readField(ClassFile* parent,
-                            const ConstantPool& cp,
-                            std::istream& is) {
-      return new Field(parent, cp, is);
+    static Field* readField(const ClassFile* parent, std::istream& is) {
+      return new Field(parent, is);
     }
 
     ~Field();
@@ -307,7 +308,7 @@
     bool isVolatile() const { return accessFlags_ & ACC_VOLATILE; }
     bool isTransient() const { return accessFlags_ & ACC_TRANSIENT; }
 
-    ClassFile* getParent() const { return parent_; }
+    const ClassFile* getParent() const { return parent_; }
     ConstantUtf8* getName() const { return name_; }
     ConstantUtf8* getDescriptor() const { return descriptor_; }
     const Attributes& getAttributes() const { return attributes_; }
@@ -321,19 +322,17 @@
   }
 
   class Method {
-    ClassFile* parent_;
+    const ClassFile* parent_;
     uint16_t accessFlags_;
     ConstantUtf8* name_;
     ConstantUtf8* descriptor_;
     Attributes attributes_;
 
-    Method(ClassFile* parent, const ConstantPool& cp, std::istream& is);
+    Method(const ClassFile* parent, std::istream& is);
 
   public:
-    static Method* readMethod(ClassFile* parent,
-                              const ConstantPool& cp,
-                              std::istream& is) {
-      return new Method(parent, cp, is);
+    static Method* readMethod(const ClassFile* parent, std::istream& is) {
+      return new Method(parent, is);
     }
 
     ~Method();
@@ -348,7 +347,7 @@
     bool isAbstract() const { return accessFlags_ & ACC_ABSTRACT; }
     bool isStrict() const { return accessFlags_ & ACC_STRICT; }
 
-    ClassFile* getParent() const { return parent_; }
+    const ClassFile* getParent() const { return parent_; }
     ConstantUtf8* getName() const { return name_; }
     ConstantUtf8* getDescriptor() const { return descriptor_; }
     const Attributes& getAttributes() const { return attributes_; }
@@ -366,13 +365,10 @@
     ConstantUtf8* name_;
 
   protected:
-    Attribute(ConstantUtf8* name,
-              const ConstantPool& cp,
-              std::istream& is);
+    Attribute(ConstantUtf8* name, const ClassFile* cf, std::istream& is);
 
   public:
-    static Attribute* readAttribute(const ConstantPool& cp,
-                                    std::istream& is);
+    static Attribute* readAttribute(const ClassFile* cf, std::istream& is);
 
     virtual ~Attribute();
 
@@ -399,7 +395,7 @@
     Constant* value_;
   public:
     ConstantValueAttribute(ConstantUtf8* name,
-                           const ConstantPool& cp,
+                           const ClassFile* cf,
                            std::istream& is);
 
     Constant* getValue() const { return value_; }
@@ -416,7 +412,7 @@
       ConstantClass* catchType_;
 
     public:
-      Exception(const ConstantPool& cp, std::istream& is);
+      Exception(const ClassFile* cf, std::istream& is);
 
       uint16_t getStartPc() const { return startPc_; }
       uint16_t getEndPc() const { return endPc_; }
@@ -438,7 +434,7 @@
 
   public:
     CodeAttribute(ConstantUtf8* name,
-                  const ConstantPool& cp,
+                  const ClassFile* cf,
                   std::istream& is);
     ~CodeAttribute();
     uint16_t getMaxStack() const { return maxStack_; }
@@ -463,7 +459,7 @@
 
   public:
     ExceptionsAttribute(ConstantUtf8* name,
-                        const ConstantPool& cp,
+                        const ClassFile* cf,
                         std::istream& is);
 
     const Classes& getExceptions() const { return exceptions_; }






More information about the llvm-commits mailing list