[Laszlo-checkins] r12301 - openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler
hqm@openlaszlo.org
hqm at openlaszlo.org
Mon Jan 5 11:53:14 PST 2009
Author: hqm
Date: 2009-01-05 11:53:12 -0800 (Mon, 05 Jan 2009)
New Revision: 12301
Modified:
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java
Log:
Change 20090105-hqm-q by hqm at badtzmaru.home on 2009-01-05 14:49:21 EST
in /Users/hqm/openlaszlo/trunk4
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: fix null pointer error in <switch> statement
New Features:
Bugs Fixed: LP-6982
Technical Reviewer: andre
QA Reviewer: promanik
Doc Reviewer: (pending)
Documentation:
Release Notes:
<switch> statement now supports an <unless> clause
example:
<switch>
<unless property="$dhtml">
[lzx code to be included]
</unless>
</switch>
Details:
+ initialize compile time constants table before running the parser
+ the parser checks for overrides of 'debug' and 'profile' on the canvas element,
(e.g., <canvas debug="xx" profile="yyy">) before it evaluates any <switch> statements
+ added <unless> clause
Tests:
test case from bug report, and case from review
<canvas debug="true" >
<handler name="oninit" >
txt.addFormat("$debug = %w", $debug === true);
</handler>
<text id="txt" />
</canvas>
works in swf8,swf9,swf10, dhtml
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java 2009-01-05 15:11:38 UTC (rev 12300)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java 2009-01-05 19:53:12 UTC (rev 12301)
@@ -3,7 +3,7 @@
* ****************************************************************************/
/* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2008 Laszlo Systems, Inc. All Rights Reserved. *
+* Copyright 2001-2009 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* J_LZ_COPYRIGHT_END *********************************************************/
@@ -394,19 +394,34 @@
}
+ Map compileTimeConstants = new HashMap();
+ compileTimeConstants.put("$debug", new Boolean(
+ env.getBooleanProperty(CompilationEnvironment.DEBUG_PROPERTY)));
+ compileTimeConstants.put("$profile", new Boolean(
+ env.getBooleanProperty(CompilationEnvironment.PROFILE_PROPERTY)));
+
+ boolean backtraceValue = env.getBooleanProperty(CompilationEnvironment.BACKTRACE_PROPERTY);
+ compileTimeConstants.put("$backtrace", new Boolean(backtraceValue));
+
+ runtime = env.getProperty(env.RUNTIME_PROPERTY);
+
+ // Must be kept in sync with server/sc/lzsc.py main
+ compileTimeConstants.put("$runtime", runtime);
+ compileTimeConstants.put("$swf7", Boolean.valueOf("swf7".equals(runtime)));
+ compileTimeConstants.put("$swf8", Boolean.valueOf("swf8".equals(runtime)));
+ compileTimeConstants.put("$as2", Boolean.valueOf(Arrays.asList(new String[] {"swf7", "swf8"}).contains(runtime)));
+ compileTimeConstants.put("$swf9", Boolean.valueOf("swf9".equals(runtime)));
+ compileTimeConstants.put("$swf10", Boolean.valueOf("swf10".equals(runtime)));
+ compileTimeConstants.put("$as3", Boolean.valueOf(env.isAS3()));
+ compileTimeConstants.put("$dhtml", Boolean.valueOf("dhtml".equals(runtime)));
+ compileTimeConstants.put("$j2me", Boolean.valueOf("j2me".equals(runtime)));
+ compileTimeConstants.put("$svg", Boolean.valueOf("svg".equals(runtime)));
+ compileTimeConstants.put("$js1", Boolean.valueOf(Arrays.asList(new String[] {"dhtml", "j2me", "svg"}).contains(runtime)));
+ env.setCompileTimeConstants(compileTimeConstants);
+
Document doc = env.getParser().parse(file, env);
Element root = doc.getRootElement();
- // Override passed in runtime target properties with the
- // canvas values.
- if ("true".equals(root.getAttributeValue("debug"))) {
- env.setProperty(CompilationEnvironment.DEBUG_PROPERTY, true);
- }
-
- if ("true".equals(root.getAttributeValue("profile"))) {
- env.setProperty(CompilationEnvironment.PROFILE_PROPERTY, true);
- }
-
// cssfile cannot be set in the canvas tag
String cssfile = props.getProperty(CompilationEnvironment.CSSFILE_PROPERTY);
if (cssfile != null) {
@@ -436,30 +451,6 @@
}
Properties nprops = (Properties) env.getProperties().clone();
- Map compileTimeConstants = new HashMap();
- compileTimeConstants.put("$debug", new Boolean(
- env.getBooleanProperty(CompilationEnvironment.DEBUG_PROPERTY)));
- compileTimeConstants.put("$profile", new Boolean(
- env.getBooleanProperty(CompilationEnvironment.PROFILE_PROPERTY)));
-
- boolean backtraceValue = env.getBooleanProperty(CompilationEnvironment.BACKTRACE_PROPERTY);
- compileTimeConstants.put("$backtrace", new Boolean(backtraceValue));
-
- runtime = env.getProperty(env.RUNTIME_PROPERTY);
-
- // Must be kept in sync with server/sc/lzsc.py main
- compileTimeConstants.put("$runtime", runtime);
- compileTimeConstants.put("$swf7", Boolean.valueOf("swf7".equals(runtime)));
- compileTimeConstants.put("$swf8", Boolean.valueOf("swf8".equals(runtime)));
- compileTimeConstants.put("$as2", Boolean.valueOf(Arrays.asList(new String[] {"swf7", "swf8"}).contains(runtime)));
- compileTimeConstants.put("$swf9", Boolean.valueOf("swf9".equals(runtime)));
- compileTimeConstants.put("$swf10", Boolean.valueOf("swf10".equals(runtime)));
- compileTimeConstants.put("$as3", Boolean.valueOf(env.isAS3()));
- compileTimeConstants.put("$dhtml", Boolean.valueOf("dhtml".equals(runtime)));
- compileTimeConstants.put("$j2me", Boolean.valueOf("j2me".equals(runtime)));
- compileTimeConstants.put("$svg", Boolean.valueOf("svg".equals(runtime)));
- compileTimeConstants.put("$js1", Boolean.valueOf(Arrays.asList(new String[] {"dhtml", "j2me", "svg"}).contains(runtime)));
-
// [todo: 2006-04-17 hqm] These compileTimeConstants will be used by the script compiler
// at compile time, but they won't be emitted into the object code for user apps. Only
// the compiled LFC emits code which defines these constants. We need to have some
@@ -469,7 +460,6 @@
ObjectWriter writer = createObjectWriter(nprops, ostr, env, root);
env.setObjectWriter(writer);
- env.setCompileTimeConstants(compileTimeConstants);
Compiler.updateRootSchema(root, env, schema, externalLibraries);
@@ -651,7 +641,21 @@
"import flash.text.*;\n" +
"import flash.ui.*;\n" +
"import flash.utils.*;\n" +
- "import flash.xml.*;\n" +
+ "import flash.xml.*;\n";
+
+ if ("swf10".equals(runtime)) {
+ // These it easier to debug SWF 10 Text Layout Framework code
+ prog = prog +
+ "import flashx.textLayout.container.*;\n" +
+ "import flashx.textLayout.compose.*;\n" +
+ "import flashx.textLayout.elements.*;\n" +
+ "import flashx.textLayout.conversion.*;\n" +
+ "import flashx.textLayout.formats.*;\n" +
+ "import flashx.textLayout.formats.Direction;\n" +
+ "import flashx.textLayout.edit.*;\n" +
+ "import flashx.textLayout.events.*;\n";
+ }
+ prog = prog +
"}#\n" +
"public function DebugExec (...ignore) {runToplevelDefinitions();}\n" +
"public function runToplevelDefinitions() {}\n" +
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java 2009-01-05 15:11:38 UTC (rev 12300)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java 2009-01-05 19:53:12 UTC (rev 12301)
@@ -3,7 +3,7 @@
* ****************************************************************************/
/* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2008 Laszlo Systems, Inc. All Rights Reserved. *
+* Copyright 2001-2009 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* J_LZ_COPYRIGHT_END *********************************************************/
@@ -399,11 +399,30 @@
newCurrentFiles.add(key);
Document doc = read(file);
Element root = doc.getRootElement();
+
+ Map cc = env.getCompileTimeConstants();
+ // Override passed in runtime target properties 'debug' and 'profile' with
+ // canvas values, if any.
+ if (root.getName().equals("canvas")) {
+ String dbg = root.getAttributeValue("debug");
+ if (dbg != null) {
+ cc.put("$debug", new Boolean(dbg));
+ env.setProperty(CompilationEnvironment.DEBUG_PROPERTY, dbg.equals("true"));
+ }
+
+ String prof = root.getAttributeValue("profile");
+ if (prof != null) {
+ cc.put("$profile", new Boolean(prof));
+ env.setProperty(CompilationEnvironment.PROFILE_PROPERTY, prof.equals("true"));
+ }
+ }
+
expandIncludes(root, newCurrentFiles, env);
return doc;
}
static final String WHEN = "when";
+ static final String UNLESS = "unless";
static final String OTHERWISE = "otherwise";
/**
@@ -480,6 +499,7 @@
iter.hasNext(); ) {
Element child = (Element) iter.next();
if (! (child.getName().equals("when") ||
+ child.getName().equals("unless") ||
child.getName().equals("otherwise"))) {
throw new CompilationError("unknown clause for a switch statement: "+child.getName(), child);
}
@@ -492,6 +512,15 @@
break;
}
}
+ for (Iterator iter = elt.getChildren(UNLESS, elt.getNamespace()).iterator();
+ iter.hasNext(); ) {
+ Element when = (Element) iter.next();
+ if (!evaluateConditions(when, env)) {
+ selected = when;
+ break;
+ }
+ }
+
if (selected == null) {
for (Iterator iter = elt.getChildren(OTHERWISE, elt.getNamespace()).iterator();
iter.hasNext(); ) {
More information about the Laszlo-checkins
mailing list