[llvm-commits] CVS: llvm-java/lib/Compiler/VMClass.h VMClass.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Thu Mar 31 10:12:30 PST 2005



Changes in directory llvm-java/lib/Compiler:

VMClass.h updated: 1.24 -> 1.25
VMClass.cpp updated: 1.32 -> 1.33
---
Log message:

Provide methods to get VMFields and VMMethods by name. Simplify
implementation of lookupField() and lookupMethod().


---
Diffs of the changes:  (+22 -20)

 VMClass.cpp |   32 +++++++++++++-------------------
 VMClass.h   |   10 +++++++++-
 2 files changed, 22 insertions(+), 20 deletions(-)


Index: llvm-java/lib/Compiler/VMClass.h
diff -u llvm-java/lib/Compiler/VMClass.h:1.24 llvm-java/lib/Compiler/VMClass.h:1.25
--- llvm-java/lib/Compiler/VMClass.h:1.24	Wed Mar 30 23:10:29 2005
+++ llvm-java/lib/Compiler/VMClass.h	Thu Mar 31 12:12:19 2005
@@ -51,7 +51,7 @@
     void computeLayout();
     void computeClassRecord();
     const VMField* lookupField(const std::string& name) const;
-    const VMMethod* lookupMethod(const std::string& name) const;
+    const VMMethod* lookupMethod(const std::string& nameAndType) const;
     
     friend class Resolver;
 
@@ -95,7 +95,15 @@
     llvm::Constant* getConstant(unsigned index) const;
     const VMClass* getClass(unsigned index) const;
     const VMField* getField(unsigned index) const;
+    const VMField* getField(const std::string& name) const {
+      FieldMap::const_iterator it = fieldMap_.find(name);
+      return it == fieldMap_.end() ? NULL : &it->second;
+    }
     const VMMethod* getMethod(unsigned index) const;
+    const VMMethod* getMethod(const std::string& nameAndType) const {
+      MethodMap::const_iterator it = methodMap_.find(nameAndType);
+      return it == methodMap_.end() ? NULL : &it->second;
+    }
   };
 
 } } // namespace llvm::Java


Index: llvm-java/lib/Compiler/VMClass.cpp
diff -u llvm-java/lib/Compiler/VMClass.cpp:1.32 llvm-java/lib/Compiler/VMClass.cpp:1.33
--- llvm-java/lib/Compiler/VMClass.cpp:1.32	Thu Mar 31 01:55:42 2005
+++ llvm-java/lib/Compiler/VMClass.cpp	Thu Mar 31 12:12:19 2005
@@ -72,47 +72,41 @@
 
 const VMField* VMClass::lookupField(const std::string& name) const
 {
-  FieldMap::const_iterator it = fieldMap_.find(name);
-  if (it != fieldMap_.end())
-    return &it->second;
+  if (const VMField* field = getField(name))
+    return field;
 
   for (unsigned i = 0, e = getNumInterfaces(); i != e; ++i) {
     const VMClass* interface = getInterface(i);
-    it = interface->fieldMap_.find(name);
-    if (it != interface->fieldMap_.end())
-      return &it->second;
+    if (const VMField* field = interface->getField(name))
+      return field;
   }
 
   for (unsigned i = 0, e = getNumSuperClasses(); i != e; ++i) {
     const VMClass* superClass = getSuperClass(i);
-    it = superClass->fieldMap_.find(name);
-    if (it != superClass->fieldMap_.end())
-      return &it->second;
+    if (const VMField* field = superClass->getField(name))
+      return field;
   }
 
   assert(0 && "Field not found!");
   abort();
 }
 
-const VMMethod* VMClass::lookupMethod(const std::string& name) const
+const VMMethod* VMClass::lookupMethod(const std::string& nameAndType) const
 {
-  MethodMap::const_iterator it = methodMap_.find(name);
-  if (it != methodMap_.end())
-    return &it->second;
+  if (const VMMethod* method = getMethod(nameAndType))
+    return method;
 
   if (isInterface())
     for (unsigned i = 0, e = getNumInterfaces(); i != e; ++i) {
       const VMClass* interface = getInterface(i);
-      it = interface->methodMap_.find(name);
-      if (it != interface->methodMap_.end())
-        return &it->second;
+      if (const VMMethod* method = interface->getMethod(nameAndType))
+        return method;
     }
   else
     for (unsigned i = 0, e = getNumSuperClasses(); i != e; ++i) {
       const VMClass* superClass = getSuperClass(i);
-      it = superClass->methodMap_.find(name);
-      if (it != superClass->methodMap_.end())
-        return &it->second;
+      if (const VMMethod* method = superClass->getMethod(nameAndType))
+        return method;
     }
 
   assert(0 && "Method not found!");






More information about the llvm-commits mailing list