Author: ptw
Date: 2006-11-08 12:21:25 -0800 (Wed, 08 Nov 2006)
New Revision: 2443
Modified:
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
Log:
Change 20061107-ptw-G by [EMAIL PROTECTED] on 2006-11-07 17:25:34 EST
in /Users/ptw/OpenLaszlo/legals-2
Summary: Name anonymous functions
Bugs Fixed:
LPP-2984 Add nice names for sprite methods in the profiler
Technical Reviewer: max (Message-ID: <[EMAIL PROTECTED]>)
QA Reviewer: hqm (pending)
Doc Reviewer: n/a
Details:
Revive old re-write code that looks for anonymous functions in
assignments and uses the lhs expression text as the function
name.
Tests:
Inspected LFCdhtml-profile.js and noted that LzSprite methods all
have names now.
Modified:
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
===================================================================
---
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
2006-11-08 20:19:49 UTC (rev 2442)
+++
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/sc/Compiler.java
2006-11-08 20:21:25 UTC (rev 2443)
@@ -642,6 +642,25 @@
return node.get(0);
}
}
+ // After refactoring, assure each function has a name
+ // for debugging and profiling
+ if (node instanceof ASTAssignmentExpression) {
+ SimpleNode rhs = node.get(2);
+ if (rhs instanceof ASTFunctionExpression) {
+ // fn children are [(name), arglist, body]
+ if (rhs.size() == 2) {
+ String name = ptp.visit(node.get(0));
+ SimpleNode child = rhs;
+ int size = child.size();
+ SimpleNode children[] = new SimpleNode[size + 1];
+ children[0] = new ASTIdentifier(name);
+ for (int i = 0, j = 1; i < size; i++, j++) {
+ children[j] = child.get(i);
+ }
+ child.setChildren(children);
+ }
+ }
+ }
return node;
}
Modified:
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
===================================================================
---
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
2006-11-08 20:19:49 UTC (rev 2442)
+++
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
2006-11-08 20:21:25 UTC (rev 2443)
@@ -1658,6 +1658,8 @@
}
}
+ static java.util.regex.Pattern identifierPattern =
java.util.regex.Pattern.compile("[\\w$_]+");
+
// Internal helper function for above
SimpleNode[] translateFunctionInternal(SimpleNode node, boolean useName,
SimpleNode[] children) {
// ast can be any of:
@@ -1690,8 +1692,15 @@
String lineno = "" + node.beginLine;
if (functionName != null) {
userFunctionName = functionName;
- // needed?
- options.put(Compiler.METHOD_NAME,
functionName.substring(functionName.lastIndexOf('.')+1));
+ if (! useName) {
+ if (! identifierPattern.matcher(functionName).matches()) {
+ // This is a function-expression that has been annotated
+ // with a non-legal function name, so remove that and put it
+ // in _dbg_name (below)
+ functionName = null;
+ children[0] = new ASTEmptyExpression(0);
+ }
+ }
} else {
userFunctionName = "" + filename + "#" + lineno + "/" +
node.beginColumn;
}
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins