[Laszlo-checkins] r11510 - openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc
dda@openlaszlo.org
dda at openlaszlo.org
Wed Oct 22 10:31:44 PDT 2008
Author: dda
Date: 2008-10-22 10:31:41 -0700 (Wed, 22 Oct 2008)
New Revision: 11510
Modified:
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/TranslationUnit.java
Log:
Change 20081021-dda-m by dda at lester.local on 2008-10-21 14:56:49 EDT
in /Users/dda/laszlo/src/svn/openlaszlo/trunk-f
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: Fix line numbers in embedded script
New Features:
Bugs Fixed: LPP-7129 (No line numbers in script tag errors)
Technical Reviewer: ptw (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
Script coming from <script> tags goes into the application's constructor.
This is collected into its own TranslationUnit, and folded into the
application class's TranslationUnit later. At the time it is folded in,
the line number information collected on its translation unit is lost.
This change merges the line number information.
The mechanism for embedding additional streams in TranslationUnits
currently being used is sort of a primitive bookmark. When
a translation unit is cooked, such bookmarks are
replaced by text. The difference now is that the contents of a bookmark
doesn't have to be a String, it can be a TranslationUnit, so when the translation
takes place, we have access to the line numbers to merge.
Merging B into A involves sliding all lines in A past the insertion point
'down', that is, all line numbers past that point are increased by the size of B.
And the line numbers from B are increased by the number of lines in A before
the insertion point.
Tests:
tests: (smokecheck) * (swf8+dhtml)
apps: (weather+lzpix) * (swf8+swf9+dhtml), hello(swf9)
The test case in the JIRA now correctly gives:
org.openlaszlo.sc.CompilerError: linenumscript.lzx: 4: Error: Access of undefined property a, in line: if (a == 5) {
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-10-22 17:11:29 UTC (rev 11509)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java 2008-10-22 17:31:41 UTC (rev 11510)
@@ -1195,6 +1195,9 @@
boolean hasfile = false;
int linenum = Integer.MIN_VALUE;
int linediff = Integer.MIN_VALUE;
+ public String toString() {
+ return "LineNumberState(\"" + filename + "\", hasfile=" + hasfile + ", line=" + linenum + ", diff=" + linediff + ")";
+ }
}
public boolean isActualFile(String str) {
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java 2008-10-22 17:11:29 UTC (rev 11509)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java 2008-10-22 17:31:41 UTC (rev 11510)
@@ -143,12 +143,11 @@
// If the main class is not present, we'll need to revisit
// our assumptions about where we put top level statements.
if (mainTunit != null) {
- String topstmts = defaultTunit.getContents();
if (config.islib) {
- mainTunit.addStreamText(CLASS_LEVEL_STREAM, topstmts);
+ mainTunit.setStreamObject(CLASS_LEVEL_STREAM, defaultTunit);
}
else {
- mainTunit.addStreamText(MAIN_CONSTRUCTOR_STREAM, topstmts);
+ mainTunit.setStreamObject(MAIN_CONSTRUCTOR_STREAM, defaultTunit);
}
mainTunit.setMainTranslationUnit(true);
}
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/TranslationUnit.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/TranslationUnit.java 2008-10-22 17:11:29 UTC (rev 11509)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/TranslationUnit.java 2008-10-22 17:31:41 UTC (rev 11510)
@@ -78,13 +78,55 @@
String mark = INSERT_STREAM_MARK + i + INSERT_END_MARK;
int markPos = result.indexOf(mark);
if (markPos >= 0) {
- result = result.substring(0, markPos) + getStreamText(i) +
- result.substring(markPos + mark.length());
+ String before = result.substring(0, markPos);
+ String after = result.substring(markPos + mark.length());
+ Object insert = getStreamObject(i);
+ String text = "";
+ if (insert != null) {
+ if (insert instanceof String) {
+ text = (String)insert;
+ }
+ else if (insert instanceof TranslationUnit) {
+ text = ((TranslationUnit)insert).getContents();
+ insertLnums(countLines(before), countLines(text), ((TranslationUnit)insert).lnums);
+ }
+ else {
+ throw new RuntimeException("TranslationUnit.stream unsupported type" + insert.getClass().getName());
+ }
+ }
+ result = before + text + after;
}
}
return result;
}
+ /** Merge the lnums from another translation unit
+ */
+ public void insertLnums(int startline, int nlines, SortedMap inserted) {
+
+ // from startline to the end, we must first shift all entries nlines.
+ // so we don't overwrite, we must go from the end to the beginning.
+ List keys = new ArrayList(lnums.keySet());
+ for (ListIterator liter=keys.listIterator(); liter.hasPrevious(); ) {
+ Integer key = (Integer)liter.previous();
+ int keyval = key.intValue();
+ if (keyval < startline) {
+ break;
+ }
+ lnums.put(new Integer(keyval + nlines), lnums.remove(key));
+ }
+
+ // now insert the new entries, checking for out of bounds
+ for (Iterator iter = inserted.keySet().iterator(); iter.hasNext(); ) {
+ Integer key = (Integer)iter.next();
+ int keyval = key.intValue();
+ if (keyval < 0 || keyval > nlines) {
+ throw new IndexOutOfBoundsException("linenumber table entry out of range: " + keyval + " is not in (0, " + nlines + ")");
+ }
+ lnums.put(new Integer(keyval + startline), inserted.get(key));
+ }
+ }
+
public boolean isDefaultTranslationUnit() {
return isDefault;
}
@@ -107,7 +149,7 @@
public void addText(String s) {
text.append(s);
- linenum += countOccurence(s, '\n');
+ linenum += countLines(s);
}
public int getTextLineNumber() {
@@ -129,14 +171,20 @@
streams.put(key, cur);
}
- public String getStreamText(int streamNum) {
+ public void setStreamObject(int streamNum, Object o) {
Integer key = new Integer(streamNum);
- String cur = (String)streams.get(key);
- if (cur == null)
- cur = "";
- return cur;
+ Object cur = streams.get(key);
+ if (cur != null) {
+ throw new RuntimeException("TranslationUnit.setStreamObject value should not already exist");
+ }
+ streams.put(key, o);
}
+ public Object getStreamObject(int streamNum) {
+ Integer key = new Integer(streamNum);
+ return streams.get(key);
+ }
+
public void setInputLineNumber(int inputLinenum, SourceFile srcf) {
Integer key = new Integer(linenum);
SourceFileLine cur = (SourceFileLine)lnums.get(key);
@@ -148,7 +196,7 @@
}
// if the source file changed, we'll just use the first one.
// otherwise, we want the smallest input line in the mapping.
- else if (cur.sourcefile.equals(srcf) && inputLinenum < cur.line) {
+ else if (cur.sourcefile.equals(srcf) && inputLinenum < cur.line && inputLinenum > 0) {
cur.line = inputLinenum;
lnums.put(key, cur);
}
@@ -164,6 +212,10 @@
return count;
}
+ public static int countLines(String s) {
+ return countOccurence(s, '\n');
+ }
+
public String toString() {
String shortText = text.toString();
if (shortText.length() > 10) {
More information about the Laszlo-checkins
mailing list