[Laszlo-checkins] r13808 - in openlaszlo/trunk/WEB-INF/lps: lfc/compiler lfc/core server/src/org/openlaszlo/compiler server/src/org/openlaszlo/sc

ptw@openlaszlo.org ptw at openlaszlo.org
Tue May 5 09:39:38 PDT 2009


Author: ptw
Date: 2009-05-05 09:39:33 -0700 (Tue, 05 May 2009)
New Revision: 13808

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/compiler/Class.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/core/LzDefs.lzs
   openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
Log:
Change 20090505-ptw-b by ptw at dueling-banjos.home on 2009-05-05 11:31:34 EDT
    in /Users/ptw/OpenLaszlo/trunk-2
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Improve profiler annotation

Bugs Fixed:
LPP-8146 Profiler needs non-anonymous names for constraint methods
LPP-8157 debug info in script compiler for IE7 causes profiler difficulties

Technical Reviewer: hminsky (IM 2009-05-05T12:30EDT)
QA Reviewer: max (pending)

Details:
    LzNode: Remove redundant code that is now handled in Class.

    LzNode, Class: Fix _ignoreAttribute tests to use `===`.

    LzDefs: Add info to binding expressions for profiling

    JavascriptGenerator, CodeGenerator: look for #pragma
    userFunctionName that allows tag compiler to pass prettier
    debug/profile names for what would otherwise be anonymous
    functions.

    NodeModel: Give pretty names to binders, handlers, setters.

Tests:
    profiling lzxpix, Henry will test IE



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/compiler/Class.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/compiler/Class.lzs	2009-05-05 15:38:08 UTC (rev 13807)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/compiler/Class.lzs	2009-05-05 16:39:33 UTC (rev 13808)
@@ -98,6 +98,9 @@
           // `this` is the prototype of the class here, not the class
           var o = this['_profile_typename'];
           if (o) {
+            if (value.hasOwnProperty('_dbg_name')) {
+              name = value._dbg_name;
+            }
             // Give the initializer an intelligible name for profiling
             if (name == '$lzsc$initialize') {
               var pn = o;
@@ -224,7 +227,7 @@
         // Here `this` is the class
         var o = this.prototype['_profile_typename'];
         if (o) {
-          value._profile_name = value._dbg_name = value.name = (o + '.' + value.name);
+          value._profile_name = value._dbg_name = value.name = (o + '.' + value._dbg_name);
         }
       }
     }
@@ -290,9 +293,9 @@
             // Have to extract name from attrs
             var attrs = arguments[1];
             if (attrs) {
-                if (attrs['id'] && (attrs.id != lzn._ignoreAttribute)) {
+                if (attrs['id'] && (attrs.id !== lzn._ignoreAttribute)) {
                     nm = '#' + attrs.id;
-                } else if (attrs['name'] && (attrs.name != lzn._ignoreAttribute)) {
+                } else if (attrs['name'] && (attrs.name !== lzn._ignoreAttribute)) {
                     nm = ((parent === canvas)?'#':'.') + attrs.name;
                 } else if (attrs['_profile_name']) {
                     nm = attrs._profile_name;

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/core/LzDefs.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/core/LzDefs.lzs	2009-05-05 15:38:08 UTC (rev 13807)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/core/LzDefs.lzs	2009-05-05 16:39:33 UTC (rev 13808)
@@ -112,12 +112,16 @@
   var methodName:String;
   if ($debug) {
     var _dbg_name;
+  } else if ($profile) {
+    var _dbg_name;
   }
 
   function LzOnceExpr(initMethod:String, description=null) {
     this.methodName = initMethod;
     if ($debug) {
       this._dbg_name = description;
+    } else if ($profile) {
+      this._dbg_name = description;
     }
   }
 }
@@ -151,6 +155,12 @@
  * @access private
  */
 class LzStyleExpr extends LzValueExpr {
+  if ($debug) {
+    var _dbg_name;
+  } else if ($profile) {
+    var _dbg_name;
+  }
+
   function LzStyleExpr() {
   }
 }
@@ -164,10 +174,10 @@
   function LzStyleAttr(sourceAttributeName:String) {
     super();
     this.sourceAttributeName = sourceAttributeName;
-  }
-  if ($debug) {
-    var _dbg_name = function () {
-      return "attr(" + this.sourceAttributeName + ")";
+    if ($debug) {
+      this._dbg_name = "attr(" + this.sourceAttributeName + ")";
+    } else if ($profile) {
+      this._dbg_name = "attr(" + this.sourceAttributeName + ")";
     }
   }
 };
@@ -181,10 +191,10 @@
   function LzStyleIdent(sourceValueID:String) {
     super();
     this.sourceValueID = sourceValueID;
-  }
-  if ($debug) {
-    var _dbg_name = function () {
-      return this.sourceValueID;
+    if ($debug) {
+      this._dbg_name = sourceValueID;
+    } else if ($profile) {
+      this._dbg_name = sourceValueID;
     }
   }
 };

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs	2009-05-05 15:38:08 UTC (rev 13807)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/core/LzNode.lzs	2009-05-05 16:39:33 UTC (rev 13808)
@@ -205,26 +205,6 @@
     var bindname = this.$lzc$bind_name;
     if (bindname) { bindname.call(null, this) };
 
-    // Node node start
-    if ($profile) {
-      var nm = null;
-      // Have to extract name from attrs
-      if (attrs) {
-        if (attrs['id'] && (attrs.id != LzNode._ignoreAttribute)) {
-          nm = '#' + attrs.id;
-        } else if (attrs['name'] && (attrs.name != LzNode._ignoreAttribute)) {
-          nm = ((parent === canvas)?'#':'.') + attrs.name;
-        } else if (attrs['_profile_name']) {
-          nm = attrs._profile_name;
-        }
-      }
-      if (nm) {
-        this._profile_name = nm;
-        Profiler.event('start: ' + nm);
-        Profiler.event(nm, 'calls');
-      }
-    }
-
     // Squirrel away instance attributes and children for cloning...
     this._instanceAttrs = attrs;
     this._instanceChildren = children;
@@ -347,19 +327,6 @@
     } else {
       this.__LZinstantiationDone( );
     }
-
-    if ($profile) {
-      var nm = this['_profile_name'];
-      if (nm) {
-        Profiler.event(nm, 'returns');
-        this._profile_instantiator_name = nm;
-      }
-      // Set _profile_instantiator_name to constructor._dbg_name for
-      // annotation in lz.Instantiator.makeSomeViews
-      else {
-        this._profile_instantiator_name = this['constructor']._dbg_name;
-      }
-    }
   }
 
   /**
@@ -482,7 +449,7 @@
    * @access private
    */
   function $lzc$set_datapath (dp) {
-    if (null != this.datapath && dp != LzNode._ignoreAttribute) {
+    if (null != this.datapath && dp !== LzNode._ignoreAttribute) {
       this.datapath.setXPath(dp);
     } else {
       // LzDatapath will set datapath of its immediateparent
@@ -2304,7 +2271,7 @@
    * setter for $datapath
    */
   function $lzc$set_$datapath( dpobj ){
-    if (dpobj == LzNode._ignoreAttribute) {
+    if (dpobj === LzNode._ignoreAttribute) {
       // a 'datapath' attribute overrode our $datapath
       return;
     } else if (! (dpobj instanceof Object)) {

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java	2009-05-05 15:38:08 UTC (rev 13807)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/NodeModel.java	2009-05-05 16:39:33 UTC (rev 13808)
@@ -287,25 +287,9 @@
       this.source = source;
       this.env = env;
       this.srcloc = CompilerUtils.sourceLocationDirective(source, true);
-      // --- Temp solution for overriding binders in subclasses or
-      // --- instances, we just make all binders have unique names
-      String parent_name = source.getAttributeValue("id");
-      if (parent_name == null) {
-          parent_name = CompilerUtils.attributeUniqueName(source, "binder");
-      }
-      if (env.getBooleanProperty(env.DEBUG_PROPERTY)) {
-        String unique = "$" + parent_name + "_"  + env.methodNameGenerator.next();
-        if (when.equals(WHEN_PATH) || (when.equals(WHEN_STYLE)) || when.equals(WHEN_ONCE) || when.equals(WHEN_ALWAYS)) {
-          this.bindername = "$lzc$bind_" + name + unique;
-        }
+      if (when.equals(WHEN_PATH) || (when.equals(WHEN_STYLE)) || when.equals(WHEN_ONCE) || when.equals(WHEN_ALWAYS)) {
+        this.bindername =  env.methodNameGenerator.next();
         if (when.equals(WHEN_ALWAYS)) {
-          this.dependenciesname = "$lzc$dependencies_" + name + unique;
-        }
-      } else {
-        if (when.equals(WHEN_PATH) || (when.equals(WHEN_STYLE)) || when.equals(WHEN_ONCE) || when.equals(WHEN_ALWAYS)) {
-          this.bindername =  env.methodNameGenerator.next();
-        }
-        if (when.equals(WHEN_ALWAYS)) {
           this.dependenciesname =  env.methodNameGenerator.next();
         }
       }
@@ -319,12 +303,13 @@
       String prefix ="";
       String body = "\n#beginAttribute\n" + srcloc + value + CompilerUtils.endSourceLocationDirective + "\n#endAttribute\n";
       String suffix = "";
-      String pragmas = "";
+      String prettyBinderName = name + "='$";
 
       // All constraint methods need ignore args for swf9
       String args="$lzc$ignore";
       if (when.equals(WHEN_ONCE)) {
         // default
+        prettyBinderName += "once";
       } else if (when.equals(WHEN_ALWAYS)) {
         // Only call the installer if the value will change, to
         // minimize event cascades (data and style binding have to
@@ -336,6 +321,7 @@
       } else if (when.equals(WHEN_PATH)) {
         installer = "dataBindAttribute";
         body = body + ",'" + type + "'";
+        prettyBinderName += "path";
       } else if (when.equals(WHEN_STYLE)) {
         // Styles are processed at the same time as constraints.
         // Whether a style actually results in a constraint or not
@@ -343,11 +329,14 @@
         // derived (at run time)
         installer = "__LZstyleBindAttribute";
         body = body + ",'" + type + "'";
+        prettyBinderName += "style";
       }
       body = prefix + "this." + installer + "(" +
           ScriptCompiler.quote(name) + "," +
           body + ")" + suffix;
       Function binder;
+      prettyBinderName += "{...}'";
+      String pragmas = "#pragma " + ScriptCompiler.quote("userFunctionName=" + prettyBinderName);
       // Binders are called by LzDelegate.execute, which passes the
       // value sent by sendEvent, so we have to accept it, but we
       // ignore it
@@ -369,7 +358,7 @@
       if (! when.equals(WHEN_ALWAYS)) {
         return null;
       }
-      String pragmas = "";
+      String pragmas = "#pragma " + ScriptCompiler.quote("userFunctionName=" + name + " dependencies");
       String body = "";
       try {
         body = "return (" + getCompiler().dependenciesForExpression(srcloc + value) + ")";
@@ -825,6 +814,7 @@
      */
     private static String buildIdBinderBody (String symbol, boolean setId, boolean debug) {
         return
+            "#pragma " + ScriptCompiler.quote("userFunctionName=bind #" + symbol) + "\n" +
             "if ($lzc$bind) {\n" +
             (debug ?
              "    if (" + symbol + " && (" + symbol + " !== $lzc$node)) {\n" +
@@ -1500,7 +1490,7 @@
             referencename = debug ?
               ("$lzc$" + "handle_" + event + "_reference" + unique) :
               env.methodNameGenerator.next();
-            String pragmas = "";
+            String pragmas = "#pragma " + ScriptCompiler.quote("userFunctionName=get " + reference);
             String refbody = "var $lzc$reference = (" +
                 "#beginAttribute\n" +
                 reference + "\n#endAttribute\n);\n" +
@@ -1531,24 +1521,27 @@
         }
 
         if (body != null) {
+            String pragmas = "#beginContent\n";
             if (method == null) {
                 method = debug ?
                   ("$lzc$" + "handle_" + event + unique) :
                   env.methodNameGenerator.next();
+                pragmas += "#pragma " + ScriptCompiler.quote("userFunctionName=handle " +
+                                                             ((reference != null) ? (reference + ".") : "") +
+                                                             event) +"\n";
             }
-            String pragmas = "\n#beginContent\n" +
-                "\n#pragma 'methodName=" + method + "'\n";
-            body = body + "\n#endContent";
+            pragmas += "#pragma 'methodName=" + method + "'\n";
+            body = body + "\n#endContent\n";
             Function fndef;
             if (canHaveMethods) {
                 // TODO: [2008-07-21 ptw] (LPP-5813) This should really
                 // be in the script-compiler back-end
                 if (! (env.isAS3())) {
-                  pragmas += "\n#pragma 'withThis'\n";
+                  pragmas += "#pragma 'withThis'\n";
                 }
                 fndef = new Method(method, args, "", pragmas, body, srcloc, null);
             } else {
-                pragmas += "\n#pragma 'withThis'\n";
+                pragmas += "#pragma 'withThis'\n";
                 fndef = new Function(method, args, "", pragmas, body, srcloc);
             }
             // Add handler as a method
@@ -2076,7 +2069,8 @@
       // the name set_<property name> NOTE: LzNode#applyArgs and
       // #setAttribute depend on this convention to find setters
       String settername = "$lzc$" + "set_" + attribute;
-      addMethodInternal(settername, args, "", body, element, allocation);
+      String pragmas = "#pragma " + ScriptCompiler.quote("userFunctionName=set " + attribute) + "\n";
+      addMethodInternal(settername, args, "", pragmas + body, element, allocation);
       // This is just for nice error messages
       if (setters.get(attribute) != null) {
         env.warn(

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java	2009-05-05 15:38:08 UTC (rev 13807)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CodeGenerator.java	2009-05-05 16:39:33 UTC (rev 13808)
@@ -230,7 +230,7 @@
     if (name != null) {
       getname = "'" + name + "'";
     } else {
-      getname = "arguments.callee.name";
+      getname = "arguments.callee._dbg_name";
     }
 
     // Note _root.$lzprofiler can be undedefined to disable profiling
@@ -1805,7 +1805,7 @@
     // Tell metering to look up the name at runtime if it is not a
     // global name (this allows us to name closures more
     // mnemonically at runtime
-    String meterFunctionName = functionName;
+    String meterFunctionName = useName ? functionName : null;
     // Pull all the pragmas from the statement list: process them, and
     // remove them
     assert stmts instanceof ASTStatementList;
@@ -1819,6 +1819,11 @@
         }
       }
     }
+    // Allows the tag compiler to pass through a pretty name for debugging
+    String explicitUserFunctionName = (String)options.get("userFunctionName");
+    if (explicitUserFunctionName != null) {
+      userFunctionName = explicitUserFunctionName;
+    }
     if (options.getBoolean(Compiler.CONSTRAINT_FUNCTION)) {
 //       assert (functionName != null);
       if (ReferenceCollector.DebugConstraints) {
@@ -1916,7 +1921,7 @@
       // Is there any other way to construct a closure in js
       // other than a function returning a function?
       if (context.findFunctionContext().parent.findFunctionContext() != null) {
-        userFunctionName = "" + closed + "." + userFunctionName;
+        userFunctionName = userFunctionName + " closure";
       }
     }
     if (false) {
@@ -2212,7 +2217,7 @@
         collector.emit(Instructions.DUP);
         collector.emit(Instructions.DUP);
       }
-      collector.push("name");
+      collector.push("_dbg_name");
       collector.push(userFunctionName);
       collector.emit(Instructions.SetMember);
       collector.push("length");

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java	2009-05-05 15:38:08 UTC (rev 13807)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java	2009-05-05 16:39:33 UTC (rev 13808)
@@ -1168,6 +1168,11 @@
         }
       }
     }
+    // Allows the tag compiler to pass through a pretty name for debugging
+    String explicitUserFunctionName = (String)options.get("userFunctionName");
+    if (explicitUserFunctionName != null) {
+      userFunctionName = explicitUserFunctionName;
+    }
     String methodName = (String)options.get(Compiler.METHOD_NAME);
     // Backwards compatibility with tag compiler
     if (methodName != null && functionNameIdentifier != null) {
@@ -1339,7 +1344,7 @@
       // Is there any other way to construct a closure in js
       // other than a function returning a function?
       if (context.findFunctionContext().parent.findFunctionContext() != null) {
-        userFunctionName = "" + closed + "." + userFunctionName;
+        userFunctionName = userFunctionName + " closure";
       }
     }
     if (false) {



More information about the Laszlo-checkins mailing list