[Laszlo-checkins] r13572 - openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler

ptw@openlaszlo.org ptw at openlaszlo.org
Wed Apr 1 12:21:47 PDT 2009


Author: ptw
Date: 2009-04-01 12:21:38 -0700 (Wed, 01 Apr 2009)
New Revision: 13572

Modified:
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassModel.java
Log:
Change 20090401-ptw-K by ptw at dueling-banjos.home on 2009-04-01 14:26:40 EDT
    in /Users/ptw/OpenLaszlo/trunk-3
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: The last nail for LPP-7750?

Bugs Fixed: LPP-7750 Many warnings and errors with LZOs

Technical Reviewer: hminsky (pending)
QA Reviewer: mdemmon (pending)

Details:
    Remove the bogus methods getMerged*, which can't work because the
    compiler does not know all classes at compile time (it does not
    know the structure of the LFC-implemented classes and it does not
    know the structure of classes that will come from libraries).

    Define a new predicate inheritsClassChildren that tells whether
    the super class has (or could have, for classes we don't know)
    children.

    Fix the optimization for merging superclass children into a
    class to use the new predicate and be correct.

Tests:
    Test case from bug report



Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassModel.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassModel.java	2009-04-01 19:20:48 UTC (rev 13571)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/ClassModel.java	2009-04-01 19:21:38 UTC (rev 13572)
@@ -218,19 +218,24 @@
     //
     // Before you output this, see if it is necessary:  will this node
     // end up with children at all?
-    if (getMergedChildren().size() > 0) {
-      // TODO: [2008-05-30 ptw] We don't output the merged children,
-      // on the belief that is is more efficient to build the merged
-      // list at runtime, but this should be measured.
+    boolean hasChildren = (! nodeModel.getChildren().isEmpty());
+    boolean inheritsChildren = inheritsChildren();
+    if (hasChildren || inheritsChildren) {
       String children = ScriptCompiler.objectAsJavascript(nodeModel.childrenMaps());
-      // class#classChildren now class.children
-      nodeModel.setClassAttribute("children", "LzNode.mergeChildren(" + children + ", " + superClassName + "['children'])");
+      if (inheritsChildren) {
+        // NOTE: [2009-04-01 ptw] We don't compute the merged children
+        // at compile time, because we may not know them (superclass
+        // may be loaded from a library).  It might be possible to
+        // optimize this when we know the superclass.
+        nodeModel.setClassAttribute("children", "LzNode.mergeChildren(" + children + ", " + superClassName + "['children'])");
+      } else {
+        nodeModel.setClassAttribute("children", children);
+      }
     }
 
     // Declare all instance vars and methods, save initialization
     // in <class>.attributes
-    Map attrs = nodeModel.getAttrs(); // classModel.getMergedAttributes();
-    Map setters = getMergedSetters();
+    Map attrs = nodeModel.getAttrs();
     Map decls = new LinkedHashMap();
     Map inits = new LinkedHashMap();
     boolean isstate = isSubclassOf(schema.getClassModel("state"));
@@ -258,11 +263,11 @@
         // magic merging, the value has to be installed as an init,
         // otherwise it should be installed as a decl
         //
-        // TODO: [2008-03-15 ptw] This won't work until we know
-        // (in the classModel) the setters for the built-in
-        // classes, so we install as an init for now and this is
-        // fixed up in LzNode by installing inits that have no
-        // setters when the arguments are merged
+        // TODO: [2008-03-15 ptw] This won't work until we know (in
+        // the classModel) the setters for all the superclasses
+        // (built-in and in libraries), so we install as an init for
+        // now and this is fixed up in LzNode by installing inits that
+        // have no setters when the arguments are merged
         if (true) { // (! (value instanceof String))  || setters.containsKey(key) || isstate) {
           // If this is a re-declared attribute, we just init it,
           // don't re-declare it
@@ -376,38 +381,25 @@
       return superclass;
   }
 
-  private List mergedChildren;
-
-  List getMergedChildren() {
-    if (mergedChildren != null) { return mergedChildren; }
-    if (nodeModel == null) { return mergedChildren = new Vector(); }
-    List merged = mergedChildren = new Vector(superclass.getMergedChildren());
-    merged.addAll(nodeModel.getChildren());
-    return merged;
+  // A class needs to merge its children if its superclass has
+  // children, or its superclass is in a library (in which case, we
+  // just don't know)
+  boolean inheritsChildren() {
+    // No LFC class has children
+    if (superclass.builtin) { return false; }
+    // If we don't know, we have to assume true
+    if (superclass.nodeModel == null) { return true; }
+    // Otherwise ask them
+    return ((! superclass.nodeModel.getChildren().isEmpty()) ||
+            superclass.inheritsChildren());
   }
 
-  private Map mergedAttributes;
-
-  Map getMergedAttributes() {
-    if (mergedAttributes != null) { return mergedAttributes; }
-    if (nodeModel == null) { return mergedAttributes = new LinkedHashMap(); }
-    Map merged = mergedAttributes = new LinkedHashMap(superclass.getMergedAttributes());
-    // Merge in the our attributes, omitting methods
-    for (Iterator i = nodeModel.getAttrs().entrySet().iterator(); i.hasNext(); ) {
-      Map.Entry entry = (Map.Entry) i.next();
-      String key = (String) entry.getKey();
-      Object value = entry.getValue();
-      if ("LzNode._ignoreAttribute".equals(value)) {
-        merged.remove(key);
-      } else if (! (value instanceof Method)) {
-        merged.put(key, value);
-      }
-    }
-    return merged;
-  }
-
   private Map mergedMethods;
 
+  // NOTE: [2009-03-31 ptw] This information is incomplete.  It only
+  // knows the methods the tag compiler has added.  It does _not_ know
+  // methods that may have come from a library (only the schema knows
+  // those, assuming it has parsed the interface).
   Map getMergedMethods() {
     if (mergedMethods != null) { return mergedMethods; }
     if (nodeModel == null) { return mergedMethods = new LinkedHashMap(); }
@@ -424,22 +416,6 @@
     return merged;
   }
 
-  private Map mergedSetters;
-
-  Map getMergedSetters() {
-    if (mergedSetters != null) { return mergedSetters; }
-    if (nodeModel == null) { return mergedSetters = new LinkedHashMap(); }
-    Map merged = mergedSetters = new LinkedHashMap(superclass.getMergedSetters());
-    // Merge in the our setters
-    for (Iterator i = nodeModel.getSetters().entrySet().iterator(); i.hasNext(); ) {
-      Map.Entry entry = (Map.Entry) i.next();
-      String key = (String) entry.getKey();
-      Object value = entry.getValue();
-      merged.put(key, value);
-    }
-    return merged;
-  }
-
     /** This is really the LZX tag name */
     public String getClassName () {
      return this.tagName;



More information about the Laszlo-checkins mailing list