[Laszlo-checkins] r9010 - openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc

dda@openlaszlo.org dda at openlaszlo.org
Mon May 5 17:28:00 PDT 2008


Author: dda
Date: 2008-05-05 17:27:53 -0700 (Mon, 05 May 2008)
New Revision: 9010

Modified:
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
Log:
Change 20080505-dda-T by dda at lester.local on 2008-05-05 14:48:08 EDT
    in /Users/dda/laszlo/src/svn/openlaszlo/trunk-d
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: More script compiler line number fixes

New Features:

Bugs Fixed:  Nexb bug #443 sometimes some sourcelocators missing (part of LPP-5784)

Technical Reviewer: ptw (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
   This fixes a bug in the simple line number scheme.  There are
   two variations of line numbers emitted for javascript:
     file: somename.lzx#123.456
   and
     file: #789
   The first is emitted as the result of processing a function declaration, the second is emitted
   as a result of line number tracking info in the annotations for statements.  Trouble was that
   the presence of the markers of the first kind was effectively ignored when we
   determine whether to emit the second one.

   This change better integrates the two styles so that when a first style appears, we
   are tracking its line number as we do the second style.

Tests:
   smokecheck,weather,lzpix  x  swf8,dhtml
   ant lztest
   Tried test case from nexb, compiled via 'lzc -DnameFunctions --runtime=dhtml -S nexb443.lzx':
	<canvas proxied="false">
	<simplelayout spacing="5"/>
	<class name="box" height="100" width="100" bgcolor="red">

	<attribute name="posh" type="string"/>
	<handler name="onclick">
	window.alert("1st click on1 "+posh);
	window.alert("2nd click on2 "+posh);
	</handler>
	</class>
	<box posh="a1"/><box  posh="b2"/><box posh="c3"/>

	<class name="box2">
	<handler name="onclick">
	window.alert("Second Section");
	</handler>
	</class>
	</canvas>
   and confirmed that a 'file: #7' now appears before the first window alert.



Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java	2008-05-05 23:47:42 UTC (rev 9009)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java	2008-05-06 00:27:53 UTC (rev 9010)
@@ -749,7 +749,7 @@
     String txt = "";
     // Add location information if not compressing
     if ((!this.compress) && (node.filename != null) && (node.beginLine != 0)) {
-      txt = ("\n/* -*- file: " + Compiler.getLocationString(node) + " -*- */\n" );
+      txt = annotateFileLineNumber(Compiler.getLocationString(node));
     }
     txt += "function" + (useName ? (" " + name) : "") + OPENPAREN + args + CLOSEPAREN;
     if (!inmixin) {
@@ -889,6 +889,7 @@
   public static final char ANNOTATE_OP_CLASSEND = 'c';
   public static final char ANNOTATE_OP_INSERTSTREAM = 'i';
   public static final char ANNOTATE_OP_LINENUM = 'L';
+  public static final char ANNOTATE_OP_FILE_LINENUM = 'F';
   public static final char ANNOTATE_OP_NODENAME = 'N';
   public static final char ANNOTATE_OP_NODEEND = 'n';
   public static final char ANNOTATE_OP_TEXT = 'T';
@@ -950,6 +951,10 @@
     return sb.toString();
   }
 
+  public String annotateFileLineNumber(String encodedFileLineNumber) {
+    return makeAnnotation(ANNOTATE_OP_FILE_LINENUM, encodedFileLineNumber);
+  }
+
   /**
    * Add annotations, which look like \u0001 opchar operand \u0001
    * opchar is a single character.
@@ -995,6 +1000,12 @@
           switch (op) {
           case ANNOTATE_OP_TEXT:
             return operand;
+          case ANNOTATE_OP_FILE_LINENUM:
+            /* File/linenums annotations are added only when
+             * nameFunctions is on.  Here we pass them through
+             * unconditionally.
+             */
+            return "\n/* -*- file: " + operand + " -*- */\n";
           }
           return "";
         }
@@ -1011,6 +1022,8 @@
             return operand;
           case ANNOTATE_OP_LINENUM:
             return "#line " + operand + ": ";
+          case ANNOTATE_OP_FILE_LINENUM:
+            return "#fileline " + operand + ": ";
           case ANNOTATE_OP_CLASSNAME:
             return "#class " + operand + ": ";
           case ANNOTATE_OP_CLASSEND:
@@ -1033,6 +1046,12 @@
     return ap.process(annotated);
   }
 
+  public int extractLineNumber(String str) {
+    int linenumPos = str.indexOf('#');
+    int linenumEnd = str.indexOf('.', linenumPos+1);
+    return Integer.parseInt(str.substring(linenumPos+1, linenumEnd));
+  }
+
   public List makeTranslationUnits(String annotated) {
     final ArrayList tunits = new ArrayList();
     final TranslationUnit defaulttu = new TranslationUnit(true);
@@ -1046,6 +1065,8 @@
         TranslationUnit curtu = defaulttu;
         boolean atBol = true;
         int linenumDiff = 0;
+        int newdiff;
+        int linenum;
 
         public String notify(char op, String operand) {
           switch (op) {
@@ -1060,17 +1081,34 @@
               }
             }
             return "";
+
+          /* We always emit the FILE_LINENUM annotations (they appear
+           * at beginning of functions) but plain old line number
+           * annotations are emitted only if the line information
+           * cannot be determined from the previous 'file: ' marker
+           * and simple incrementing.  We keep track of the difference
+           * between the line number we would generate and the number
+           * of lines we've actually output, if the difference
+           * changes, we know an observer of the output would be off
+           * and it's time to output a line number marker.
+           */
           case ANNOTATE_OP_LINENUM:
-            int linenum = Integer.parseInt(operand);
+            linenum = Integer.parseInt(operand);
             if (trackLines && atBol && linenum != 0) {
-              int newdiff = curtu.getTextLineNumber() - linenum;
+              newdiff = curtu.getTextLineNumber() - linenum;
               if (newdiff != linenumDiff) {
                 curtu.addText("/* -*- file: #" + linenum + " -*- */\n");
-                linenumDiff = newdiff + 1;  // account for the line just added
+                linenumDiff = curtu.getTextLineNumber() - linenum;
               }
             }
             curtu.setInputLineNumber(linenum);
             return "";
+          case ANNOTATE_OP_FILE_LINENUM:
+            linenum = extractLineNumber(operand);
+            curtu.addText("\n/* -*- file: " + operand + " -*- */\n");
+            linenumDiff = curtu.getTextLineNumber() - linenum;
+            curtu.setInputLineNumber(linenum);
+            return "";
           case ANNOTATE_OP_CLASSNAME:
             curtu = new TranslationUnit();
             curtu.setName(operand);



More information about the Laszlo-checkins mailing list