[Laszlo-checkins] r10493 - in openlaszlo/trunk/WEB-INF/lps/server: sc/src/org/openlaszlo/sc/parser src/org/openlaszlo/sc
dda@openlaszlo.org
dda at openlaszlo.org
Mon Jul 28 13:30:35 PDT 2008
Author: dda
Date: 2008-07-28 13:29:43 -0700 (Mon, 28 Jul 2008)
New Revision: 10493
Modified:
openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/SimpleNode.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ReferenceCollector.java
Log:
Change 20080723-dda-H by dda at lester.local on 2008-07-23 12:33:08 EDT
in /Users/dda/laszlo/src/svn/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary:
New Features:
Bugs Fixed:
Technical Reviewer: (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
Tests:
Modified: openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/SimpleNode.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/SimpleNode.java 2008-07-28 16:44:25 UTC (rev 10492)
+++ openlaszlo/trunk/WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/SimpleNode.java 2008-07-28 20:29:43 UTC (rev 10493)
@@ -61,7 +61,27 @@
toString(String), otherwise overriding toString() is probably all
you need to do. */
- public String toString(String prefix) { return prefix + toString(); }
+ public String toString(String prefix) {
+ String filename = getFilename();
+ int line = getLineNumber();
+ int col = getColumnNumber();
+
+ String fileloc = "";
+ if (filename != null || line != 0) {
+ fileloc = " [";
+ if (filename != null) {
+ fileloc += filename;
+ }
+ if (line != 0) {
+ fileloc += ":" + line;
+ }
+ if (col != 0) {
+ fileloc += "#" + col;
+ }
+ fileloc += "]";
+ }
+ return prefix + toString() + fileloc;
+ }
/* Override this method if you want to customize how the node dumps
out its children. */
@@ -154,6 +174,16 @@
this.beginColumn = column;
}
+ /**
+ * Set only the location fields from another node.
+ * @param that node to copy from
+ */
+ public void setLocation(SimpleNode that) {
+ this.filename = that.filename;
+ this.beginLine = that.beginLine;
+ this.beginColumn = that.beginColumn;
+ }
+
public void setComment(String comment) {
this.comment = comment;
}
@@ -162,6 +192,11 @@
return this.comment;
}
+ /**
+ * Create a deep copy (clone) of a SimpleNode. deepCopy or
+ * copyFields Must be overridden if a subclass has data fields
+ * that must be copied.
+ */
public SimpleNode deepCopy() {
SimpleNode result;
try {
@@ -177,7 +212,12 @@
return result;
}
- public void copyFields(SimpleNode that) {
+ /**
+ * Copy fields and children, but not parent.
+ * @param that node to copy from
+ * @return this for convenience.
+ */
+ public SimpleNode copyFields(SimpleNode that) {
this.id = that.id;
this.parser = that.parser;
this.filename = that.filename;
@@ -187,6 +227,7 @@
for (int i=0; i<that.children.length; i++) {
this.set(i, that.children[i].deepCopy());
}
+ return this;
}
/** Accept the visitor */
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java 2008-07-28 16:44:25 UTC (rev 10492)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/CommonGenerator.java 2008-07-28 20:29:43 UTC (rev 10493)
@@ -406,6 +406,8 @@
classProperties = new ASTArrayLiteral(0);
classProperties.setChildren((SimpleNode[])(classProps.toArray(new SimpleNode[0])));
}
+ instanceProperties.setLocation(node);
+ classProperties.setLocation(node);
Map map = new HashMap();
String xtor = "class".equals(classortrait.getName())?"Class":"Trait";
@@ -413,7 +415,8 @@
map.put("_2", traitsandsuper);
map.put("_3", instanceProperties);
map.put("_4", classProperties);
- SimpleNode replNode = (new Compiler.Parser()).substitute(xtor + ".make(" +
+ SimpleNode replNode = (new Compiler.Parser()).substitute(node,
+ xtor + ".make(" +
ScriptCompiler.quote(classnameString) +
", _2, _3, _4);",
map);
@@ -431,7 +434,8 @@
SimpleNode statements = new ASTStatementList(0);
statements.setChildren((SimpleNode[])(stmts.toArray(new SimpleNode[0])));
map.put("_5", statements);
- SimpleNode stmtNode = (new Compiler.Parser()).substitute("(function () { with("+globalprefix+"_1"+")"+
+ SimpleNode stmtNode = (new Compiler.Parser()).substitute(node,
+ "(function () { with("+globalprefix+"_1"+")"+
"with("+globalprefix+"_1.prototype) { _5 }})()",
map);
SimpleNode listNode = new ASTStatementList(0);
@@ -542,7 +546,7 @@
if (rest != null) {
defaults += rest;
}
- SimpleNode[] newNodes = (new Compiler.Parser()).substituteStmts(defaults, map);
+ SimpleNode[] newNodes = (new Compiler.Parser()).substituteStmts(children[formalPos], defaults, map);
stmts.addAll(flatten(newNodes));
// newargs contains arguments without initializers
children[formalPos].setChildren((SimpleNode[])newargs.toArray(new SimpleNode[0]));
@@ -1008,7 +1012,7 @@
} else {
assert false: "Unhandled super call " + ca;
}
- SimpleNode n = (new Compiler.Parser()).substitute(pattern, map);
+ SimpleNode n = (new Compiler.Parser()).substitute(node, pattern, map);
return n;
}
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java 2008-07-28 16:44:25 UTC (rev 10492)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java 2008-07-28 20:29:43 UTC (rev 10493)
@@ -755,11 +755,21 @@
return node;
}
+ private String fileLineInputString(SimpleNode n) {
+ if (n == null || n.getFilename() == null) {
+ return "#file [Compiler.substitute]\n#line 0\n";
+ }
+ else {
+ return "#file " + n.getFilename() + "\n#line " + n.getLineNumber() + "\n";
+ }
+ }
// Parse an expression and replace any identifier with the same
// name as a keyword argument to this function, with the value of
// that key. If the value has type Splice, it's spliced into
// place instead of substituting at the same level.
+ // If the 'nearnode' argument is non-null, its file/line info
+ // is used.
//
// >>> s = Parser().substitute
// >>> s("[0,1,2]")
@@ -772,22 +782,22 @@
// (ASTArrayLiteral, ASTArrayLiteral, ASTIdentifier(a), ASTIdentifier(b), ASTIdentifier(c), Literal(1), Literal(2))
//
// N.B., there is no attempt to enforce macro hygiene
- public SimpleNode substitute(String str, Map keys) {
+ public SimpleNode substitute(SimpleNode nearnode, String str, Map keys) {
// Since the parser can't parse an Expression, turn the source
// into a Program, and extract the Expression from the parse tree.
- SimpleNode node = parse("x = \n#file [Compiler.substitute]\n#line 0\n" + str).get(0).get(0).get(2);
+ SimpleNode node = parse("x = \n" + fileLineInputString(nearnode) + str).get(0).get(0).get(2);
return visit(node, keys);
}
// Input is one or more statements, returns the nodes
// that correspond to those statements
- public SimpleNode[] substituteStmts(String str, Map keys) {
- SimpleNode fexpr = substitute("(function () {" + str + "})()", keys);
+ public SimpleNode[] substituteStmts(SimpleNode nearnode, String str, Map keys) {
+ SimpleNode fexpr = substitute(nearnode, "(function () {" + str + "})()", keys);
return fexpr.get(0).get(1).getChildren();
}
- public SimpleNode substituteStmt(String str, Map keys) {
- SimpleNode node = parse("#file [Compiler.substitute]\n#line 0\n" + str).get(0);
+ public SimpleNode substituteStmt(SimpleNode nearnode, String str, Map keys) {
+ SimpleNode node = parse(fileLineInputString(nearnode) + str).get(0);
return visit(node, keys);
}
@@ -858,9 +868,18 @@
return result;
}
- public void copyFields(SimpleNode that) {
+ public SimpleNode copyFields(SimpleNode that) {
+ super.copyFields(that);
this.realNode = ((PassThroughNode)that).realNode.deepCopy();
+ return this;
}
+
+ public void dump(String prefix) {
+ super.dump(prefix);
+ if (realNode != null) {
+ realNode.dump(prefix + " ");
+ }
+ }
}
//
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 2008-07-28 16:44:25 UTC (rev 10492)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java 2008-07-28 20:29:43 UTC (rev 10493)
@@ -382,7 +382,7 @@
if (false && ASTProgram.class.equals(context.type)) {
Map map = new HashMap();
map.put("_1", new Compiler.Splice(ast));
- SimpleNode newNode = (new Compiler.Parser()).substitute("with (_root) { _1 }", map);
+ SimpleNode newNode = (new Compiler.Parser()).substitute(node, "with (_root) { _1 }", map);
return visitStatement(newNode);
} else {
return translateFunction(node, true, ast);
@@ -781,7 +781,7 @@
// if (ASTProgram.class.equals(context.type)) {
// Map map = new HashMap();
// map.put("_1", new Compiler.Splice(children));
-// SimpleNode newNode = (new Compiler.Parser()).substitute("with (_root) { _1 }", map);
+// SimpleNode newNode = (new Compiler.Parser()).substitute(node, "with (_root) { _1 }", map);
// visitStatement(newNode);
// } else {
return translateFunction(node, false, children);
@@ -825,6 +825,7 @@
Map map = new HashMap();
map.put("_1", node);
return new Compiler.PassThroughNode((new Compiler.Parser()).substitute(
+ node,
"(Debug.evalCarefully(" + file + ", " + line + ", function () { return _1; }, this))", map));
}
return node;
@@ -960,7 +961,7 @@
Map map = new HashMap();
map.put("_1", ref);
String pattern = "(function () { var $lzsc$tmp = _1; return _1 = $lzsc$tmp " + XfixInstrs.get(op) + " 1; })()";
- SimpleNode n = (new Compiler.Parser()).substitute(pattern, map);
+ SimpleNode n = (new Compiler.Parser()).substitute(node, pattern, map);
return visitExpression(n);
}
children[1] = translateReference(ref, 2).get();
@@ -976,7 +977,7 @@
Map map = new HashMap();
map.put("_1", ref);
String pattern = "(function () { var $lzsc$tmp = _1; _1 = $lzsc$tmp " + XfixInstrs.get(op) + " 1; return $lzsc$tmp; })()";
- SimpleNode n = (new Compiler.Parser()).substitute(pattern, map);
+ SimpleNode n = (new Compiler.Parser()).substitute(node, pattern, map);
return visitExpression(n);
}
children[0] = translateReference(ref, 2).get();
@@ -1030,7 +1031,7 @@
} else {
pattern = "((function (a, b) {return b['$lzsc$isa'] ? b.$lzsc$isa(a) : (a instanceof b)})(_1, _2))";
}
- SimpleNode n = (new Compiler.Parser()).substitute(pattern, map);
+ SimpleNode n = (new Compiler.Parser()).substitute(node, pattern, map);
return visitExpression(n);
}
children[0] = visitExpression(a);
@@ -1068,7 +1069,7 @@
map.put("_2", rhs);
map.put("_3", lhs.set());
String pattern = "(function () { var $lzsc$tmp = _1; return _3 = $lzsc$tmp " + AssignOpTable.get(op) + " _2; })()";
- SimpleNode n = (new Compiler.Parser()).substitute(pattern, map);
+ SimpleNode n = (new Compiler.Parser()).substitute(node, pattern, map);
return visitExpression(n);
}
children[2] = rhs;
@@ -1100,7 +1101,7 @@
Map map = new HashMap();
map.put("_1", node);
map.put("_2", translateFunction(dependencies, false, dependencies.getChildren()));
- SimpleNode newNode = (new Compiler.Parser()).substitute(
+ SimpleNode newNode = (new Compiler.Parser()).substitute(node,
"(function () {var $lzsc$f = _1; $lzsc$f.dependencies = _2; return $lzsc$f })();", map);
return newNode;
}
@@ -1414,7 +1415,7 @@
Map map = new HashMap();
map.put("_1", funexpr);
// Do I need a new one of these each time?
- newBody.add((new Compiler.Parser()).substitute(name + " = _1;", map));
+ newBody.add((new Compiler.Parser()).substitute(fundecl, name + " = _1;", map));
}
}
// If the locals are not remapped, we assume we are in a runtime
@@ -1484,6 +1485,7 @@
Map map = new HashMap();
map.put("_1", node);
SimpleNode newNode = new Compiler.PassThroughNode((new Compiler.Parser()).substitute(
+ node,
"(function () {" +
" var $lzsc$temp = _1;" +
" $lzsc$temp._dbg_name = " + ScriptCompiler.quote(userFunctionName) + ";" +
@@ -1630,6 +1632,7 @@
if (registers != null && registers.containsKey(name)) {
String register = (String)registers.get(name);
ASTIdentifier newNode = new ASTIdentifier(0);
+ newNode.setLocation(node);
if (node instanceof ASTIdentifier) {
ASTIdentifier oldid = (ASTIdentifier)node;
newNode.setEllipsis(oldid.getEllipsis());
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-07-28 16:44:25 UTC (rev 10492)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java 2008-07-28 20:29:43 UTC (rev 10493)
@@ -764,7 +764,9 @@
// This is an interface - no body needed
txt += SEMI;
}
- return txt;
+ // When functions go out of scope we should tell
+ // any readers to forget the current line number info.
+ return txt + forceBlankLnum();
}
public String visitClassDefinition(SimpleNode node, String[] children) {
@@ -880,6 +882,10 @@
return makeTranslationUnits(visit(node));
}
+ public static String unparse(SimpleNode node) {
+ return (new ParseTreePrinter()).text(node);
+ }
+
public String text(SimpleNode node) {
return unannotate(visit(node));
}
@@ -985,6 +991,18 @@
return result;
}
+ /**
+ * Return an annotation that forces a blank line number
+ * at this point.
+ */
+ public String forceBlankLnum() {
+ if (!trackLines) {
+ return "";
+ } else {
+ return NEWLINE + annotateFileLineNumber("", true);
+ }
+ }
+
public String annotateClass(String classnm, String str) {
StringBuffer sb = new StringBuffer();
sb.append(makeAnnotation(ANNOTATE_OP_CLASSNAME, classnm));
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ReferenceCollector.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ReferenceCollector.java 2008-07-28 16:44:25 UTC (rev 10492)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ReferenceCollector.java 2008-07-28 20:29:43 UTC (rev 10493)
@@ -89,7 +89,7 @@
map.put("_1", fn);
map.put("_2", callee);
map.put("_3", new Compiler.Splice(node.get(1).getChildren()));
- return parser.substitute("_1.hasOwnProperty('dependencies') ? _1.dependencies(this, _2, _3) : []", map);
+ return parser.substitute(node, "_1.hasOwnProperty('dependencies') ? _1.dependencies(this, _2, _3) : []", map);
}
// callee.fn(args...) ->
@@ -117,7 +117,7 @@
map.put("_1", callee);
map.put("_2", new Compiler.Splice(node.get(1).getChildren()));
- return parser.substitute("_1['" + depnm + "'] ? _1['" + depnm + "'](this, _1, _2) : []", map);
+ return parser.substitute(fn, "_1['" + depnm + "'] ? _1['" + depnm + "'](this, _1, _2) : []", map);
}
// TODO: [2006-02-22 dda] Remove this 'subfunction' version soon.
@@ -141,7 +141,7 @@
map.put("_1", a);
map.put("_2", b);
- a = parser.substitute("_1.concat(_2)", map);
+ a = parser.substitute(n, "_1.concat(_2)", map);
}
}
return a;
@@ -164,7 +164,7 @@
map.put("_1", a);
map.put("_2", b);
- a = parser.substitute("_1.concat(_2)", map);
+ a = parser.substitute(n, "_1.concat(_2)", map);
}
}
return a;
@@ -202,7 +202,7 @@
Map map = new HashMap();
map.put("_1", d);
map.put("_2", md);
- return parser.substitute(
+ return parser.substitute(d,
// TODO: [2003-06-19 ptw] (krank) Have to use sanitized
// name here, so that substitute does not try to name
// the function "x"
@@ -215,7 +215,7 @@
} else {
Map map = new HashMap();
map.put("_1", d);
- return parser.substitute(
+ return parser.substitute(d,
// TODO: [2003-06-19 ptw] (krank) Have to use sanitized
// name here, so that substitute does not try to name
// the function "x"
More information about the Laszlo-checkins
mailing list