[PPL-devel] [GIT] ppl/ppl(floating_point): Interface for Java class Linear_Expression_Times improved.

Enea Zaffanella zaffanella at cs.unipr.it
Wed Jun 10 09:55:35 CEST 2009


Module: ppl/ppl
Branch: floating_point
Commit: 81e8a397938b2a0e20787581c68dcc8fd0799e89
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=81e8a397938b2a0e20787581c68dcc8fd0799e89

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Tue Jun  2 11:00:09 2009 +0200

Interface for Java class Linear_Expression_Times improved.
The misleading methods left_hand_side() and right_hand_side() replaced by:
    public Coefficient coefficient();
and
    public Linear_Expression linear_expression();
returing the two object factors using clearer naming.

---

 interfaces/Java/jni/ppl_java_common.cc             |   46 ++++++++-----------
 interfaces/Java/jni/ppl_java_common.defs.hh        |    4 +-
 interfaces/Java/jni/ppl_java_globals.cc            |   10 ++--
 .../Linear_Expression_Times.java                   |   36 +++++++++------
 4 files changed, 47 insertions(+), 49 deletions(-)

diff --git a/interfaces/Java/jni/ppl_java_common.cc b/interfaces/Java/jni/ppl_java_common.cc
index d2b9675..9c82657 100644
--- a/interfaces/Java/jni/ppl_java_common.cc
+++ b/interfaces/Java/jni/ppl_java_common.cc
@@ -616,65 +616,57 @@ build_cxx_constraint(JNIEnv* env, jobject j_constraint) {
 
 Linear_Expression
 build_cxx_linear_expression(JNIEnv* env, jobject j_le) {
+  jfieldID fID;
   jclass current_class = env->GetObjectClass(j_le);
   // LE_Variable
   if (env->IsAssignableFrom(current_class,
                             cached_classes.Linear_Expression_Variable)) {
-    jint var_id
-      = env->CallIntMethod(j_le,
-                           cached_FMIDs.Linear_Expression_Variable_var_id_ID);
+    jmethodID mID = cached_FMIDs.Linear_Expression_Variable_var_id_ID;
+    jint var_id = env->CallIntMethod(j_le, mID);
     return Linear_Expression(Variable(var_id));
   }
   // LE_Coefficient
   if (env->IsAssignableFrom(current_class,
                             cached_classes.Linear_Expression_Coefficient)) {
-    jfieldID fID = cached_FMIDs.Linear_Expression_Coefficient_coeff_ID;
+    fID = cached_FMIDs.Linear_Expression_Coefficient_coeff_ID;
     jobject ppl_coeff = env->GetObjectField(j_le, fID);
     return Linear_Expression(build_cxx_coeff(env, ppl_coeff));
   }
   // LE_Sum
   if (env->IsAssignableFrom(current_class,
                             cached_classes.Linear_Expression_Sum)) {
-    jobject l_value
-      = env->GetObjectField(j_le, cached_FMIDs.Linear_Expression_Sum_lhs_ID);
-    jobject r_value
-      = env->GetObjectField(j_le, cached_FMIDs.Linear_Expression_Sum_rhs_ID);
+    fID = cached_FMIDs.Linear_Expression_Sum_lhs_ID;
+    jobject l_value = env->GetObjectField(j_le, fID);
+    fID = cached_FMIDs.Linear_Expression_Sum_rhs_ID;
+    jobject r_value = env->GetObjectField(j_le, fID);
     return build_cxx_linear_expression(env, l_value)
       + build_cxx_linear_expression(env, r_value);
   }
   // LE_Times
   if (env->IsAssignableFrom(current_class,
                             cached_classes.Linear_Expression_Times)) {
-    jobject le_coeff_value
-      = env->GetObjectField(j_le,
-                            cached_FMIDs.Linear_Expression_Times_lhs_ID);
-    jobject ppl_coeff
-      = env->GetObjectField(le_coeff_value,
-                            cached_FMIDs.Linear_Expression_Coefficient_coeff_ID);
-    jobject le_value
-      = env->GetObjectField(j_le,
-                            cached_FMIDs.Linear_Expression_Times_rhs_ID);
-    return build_cxx_coeff(env, ppl_coeff)
+    fID = cached_FMIDs.Linear_Expression_Times_coeff_ID;
+    jobject coeff_value = env->GetObjectField(j_le, fID);
+    fID = cached_FMIDs.Linear_Expression_Times_lin_expr_ID;
+    jobject le_value = env->GetObjectField(j_le, fID);
+    return build_cxx_coeff(env, coeff_value)
       * build_cxx_linear_expression(env, le_value);
   }
   // LE_Difference
   if (env->IsAssignableFrom(current_class,
                             cached_classes.Linear_Expression_Difference)) {
-    jobject l_value
-      = env->GetObjectField(j_le,
-                            cached_FMIDs.Linear_Expression_Difference_lhs_ID);
-    jobject r_value
-      = env->GetObjectField(j_le,
-                            cached_FMIDs.Linear_Expression_Difference_rhs_ID);
+    fID = cached_FMIDs.Linear_Expression_Difference_lhs_ID;
+    jobject l_value = env->GetObjectField(j_le,fID);
+    fID = cached_FMIDs.Linear_Expression_Difference_rhs_ID;
+    jobject r_value = env->GetObjectField(j_le, fID);
     return build_cxx_linear_expression(env, l_value)
       - build_cxx_linear_expression(env, r_value);
   }
   // LE_Unary_Minus
   if (env->IsAssignableFrom(current_class,
                             cached_classes.Linear_Expression_Unary_Minus)) {
-    jobject le_value
-      = env->GetObjectField(j_le,
-                            cached_FMIDs.Linear_Expression_Unary_Minus_arg_ID);
+    fID = cached_FMIDs.Linear_Expression_Unary_Minus_arg_ID;
+    jobject le_value = env->GetObjectField(j_le, fID);
     return -build_cxx_linear_expression(env, le_value);
   }
   assert(false);
diff --git a/interfaces/Java/jni/ppl_java_common.defs.hh b/interfaces/Java/jni/ppl_java_common.defs.hh
index 6c52441..6a9399e 100644
--- a/interfaces/Java/jni/ppl_java_common.defs.hh
+++ b/interfaces/Java/jni/ppl_java_common.defs.hh
@@ -302,8 +302,8 @@ struct Java_FMID_Cache {
   jfieldID Linear_Expression_Difference_rhs_ID;
   jfieldID Linear_Expression_Sum_lhs_ID;
   jfieldID Linear_Expression_Sum_rhs_ID;
-  jfieldID Linear_Expression_Times_lhs_ID;
-  jfieldID Linear_Expression_Times_rhs_ID;
+  jfieldID Linear_Expression_Times_coeff_ID;
+  jfieldID Linear_Expression_Times_lin_expr_ID;
   jmethodID Linear_Expression_Times_init_from_coeff_var_ID;
   jfieldID Linear_Expression_Unary_Minus_arg_ID;
   jmethodID Linear_Expression_Variable_init_ID;
diff --git a/interfaces/Java/jni/ppl_java_globals.cc b/interfaces/Java/jni/ppl_java_globals.cc
index 071d4c1..e1d296c 100644
--- a/interfaces/Java/jni/ppl_java_globals.cc
+++ b/interfaces/Java/jni/ppl_java_globals.cc
@@ -408,14 +408,14 @@ JNIEXPORT void JNICALL
 Java_parma_1polyhedra_1library_Linear_1Expression_1Times_initIDs
 (JNIEnv* env, jclass j_le_times_class) {
   jfieldID fID;
-  fID = env->GetFieldID(j_le_times_class, "lhs",
-                        "Lparma_polyhedra_library/Linear_Expression_Coefficient;");
+  fID = env->GetFieldID(j_le_times_class, "coeff",
+                        "Lparma_polyhedra_library/Coefficient;");
   CHECK_RESULT_ASSERT(env, fID);
-  cached_FMIDs.Linear_Expression_Times_lhs_ID = fID;
-  fID = env->GetFieldID(j_le_times_class, "rhs",
+  cached_FMIDs.Linear_Expression_Times_coeff_ID = fID;
+  fID = env->GetFieldID(j_le_times_class, "lin_expr",
                         "Lparma_polyhedra_library/Linear_Expression;");
   CHECK_RESULT_ASSERT(env, fID);
-  cached_FMIDs.Linear_Expression_Times_rhs_ID = fID;
+  cached_FMIDs.Linear_Expression_Times_lin_expr_ID = fID;
   jmethodID mID;
   mID = env->GetMethodID(j_le_times_class, "<init>",
                          "(Lparma_polyhedra_library/Coefficient;"
diff --git a/interfaces/Java/parma_polyhedra_library/Linear_Expression_Times.java b/interfaces/Java/parma_polyhedra_library/Linear_Expression_Times.java
index 44f6cc4..dc69ccd 100644
--- a/interfaces/Java/parma_polyhedra_library/Linear_Expression_Times.java
+++ b/interfaces/Java/parma_polyhedra_library/Linear_Expression_Times.java
@@ -27,37 +27,43 @@ package parma_polyhedra_library;
 public class Linear_Expression_Times
     extends Linear_Expression {
 
-    //! The value of the left hand side of \p this.
-    protected Linear_Expression_Coefficient lhs;
+    //! The value of the coefficient.
+    protected Coefficient coeff;
 
-    //! The value of the left hand side of \p this.
-    protected Linear_Expression rhs;
+    //! The value of the inner linear expression.
+    protected Linear_Expression lin_expr;
 
     //! Builds an object cloning the input arguments.
     public Linear_Expression_Times(Coefficient c, Variable v) {
-	lhs = new Linear_Expression_Coefficient(c);
-	rhs = new Linear_Expression_Variable(v);
+	coeff = new Coefficient(c);
+	lin_expr = new Linear_Expression_Variable(v);
+    }
+
+    //! Builds an object cloning the input arguments.
+    public Linear_Expression_Times(Coefficient c, Linear_Expression l) {
+	coeff = new Coefficient(c);
+	lin_expr = l.clone();
     }
 
     //! Builds an object cloning the input arguments.
     public Linear_Expression_Times(Linear_Expression l, Coefficient c) {
-	lhs = new Linear_Expression_Coefficient(c);
-	rhs = l.clone();
+	coeff = new Coefficient(c);
+	lin_expr = l.clone();
     }
 
-    //! Returns the left hand side of \p this.
-   public Linear_Expression left_hand_side() {
-	return lhs;
+    //! Returns the coefficient of \p this.
+    public Coefficient coefficient() {
+	return coeff;
     }
 
-    //! Returns the right hand side of \p this.
-    public Linear_Expression right_hand_side() {
-	return rhs;
+    //! Returns the linear expression subobject of \p this.
+    public Linear_Expression linear_expression() {
+	return lin_expr;
     }
 
     //! Builds a copy of this.
     public Linear_Expression_Times clone() {
-	return new Linear_Expression_Times(rhs, lhs.argument());
+	return new Linear_Expression_Times(coeff, lin_expr);
     }
 
     private static native void initIDs();




More information about the PPL-devel mailing list