Author: dda
Date: 2008-02-11 14:25:03 -0800 (Mon, 11 Feb 2008)
New Revision: 7998
Modified:
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9External.java
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
Log:
Change 20080211-dda-w by [EMAIL PROTECTED] on 2008-02-11 16:50:59 EST
in /Users/dda/laszlo/src/svn/openlaszlo/branches/devildog
for http://svn.openlaszlo.org/openlaszlo/branches/devildog
Summary: SWF9: class name and file name conflict checks
New Features:
Bugs Fixed: LPP-5266
Technical Reviewer: ptw (pending)
QA Reviewer: hminsky (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
As agreed in review, compiler generated names should begin with $lzsc$
(so interstitials are now named $lzsc$Name1$Name2...), and we can be
more leniant on user's class names. This change disallows any class
name beginning with '$'.
A related change is to protect against file names conflicting.
A previous test case had names like "foo" and "Foo" getting a file
overwritten on windows (file system maps "foo.as" and "Foo.as"
to the same file). This change prevents users from defining
two or more classes whose names that differ only by case (or that are
the same). This is perhaps too conservative for Unix systems,
but may prevent cross-platform porting errors and seems to be
a reasonable limitation.
Tests:
did usual regression tests for swf8/dhtml:
smokecheck
lzpix
weather
did henry's hello for swf9.
made some local changes to LzNode to verify that class conflicts and
illegal names are detected.
Modified:
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9External.java
===================================================================
---
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9External.java
2008-02-11 22:24:32 UTC (rev 7997)
+++
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9External.java
2008-02-11 22:25:03 UTC (rev 7998)
@@ -23,6 +23,12 @@
* external compiler - generation of source files,
* calling the compiler, packaging up the result and
* interpreting error messages.
+ *
+ * It is expected that a new SWF9External object
+ * be created for each chunk of compilation. Each
+ * new SWF9External gets a new temporary directory
+ * for compilation, and verifies classname uniqueness
+ * within that space.
*/
public class SWF9External {
@@ -38,6 +44,11 @@
private File tempdir = getCompilationTempDir();
private Compiler.OptionMap options;
+ /**
+ * The key is the 'tolower' name, the value is the actual name.
+ */
+ private HashMap uniqueFileNames = new HashMap();
+
public SWF9External(Compiler.OptionMap options) {
this.options = options;
}
@@ -622,13 +633,34 @@
}
/**
+ * Checks for unique file names for files written.
+ * We do not allow files to match, or even to be differing
+ * only by case. The latter will cause problems on
+ * file systems that merge upper/lower case names.
+ * @throw CompilerError for file name conflicts
+ */
+ void checkFileNameForClassName(String name) {
+ String lower = name.toLowerCase();
+ String existing;
+ if ((existing = (String)uniqueFileNames.get(lower)) != null) {
+ if (existing.equals(name)) {
+ throw new CompilerError("cannot declare class name more than once: \""
+ name + "\"");
+ } else {
+ throw new CompilerError("class names only differ by upper/lower case:
\"" + existing + "\" versus \"" + name + "\"");
+ }
+ }
+ uniqueFileNames.put(lower, name);
+ }
+
+ /**
* Write a file given by the translation unit, and using the
* given pre and post text.
- * @throw CompilerError for any write errors
+ * @throw CompilerError for any write errors, or class name conflicts
*/
public void writeFile(TranslationUnit tunit, String pre, String post) {
String name = tunit.getName();
String body = tunit.getContents();
+ checkFileNameForClassName(name);
String infilename = tempdir.getPath() + File.separator + name + ".as";
tunit.setSourceFileName(infilename);
Modified:
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
===================================================================
---
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
2008-02-11 22:24:32 UTC (rev 7997)
+++
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
2008-02-11 22:25:03 UTC (rev 7998)
@@ -136,13 +136,14 @@
/**
* The script compiler reserves parts of the name space for
- * its own use. All of our generated names have dollar signs,
- * so to be conservative, we do not allow class/mixin names
- * with dollar signs.
+ * its own use. All of our generated names start with "$lzsc$",
+ * to be conservative, we do not allow class/mixin names
+ * that begin with dollar signs.
+ * @param name class name to check
* @throw CompilerError if name has a potential conflict
*/
public void checkClassName(String name) {
- if (name.indexOf('$') >= 0)
+ if (name.startsWith("$"))
throw new CompilerError(name + ": class or mixin name may conflict with
internally generated names");
}
@@ -182,7 +183,7 @@
String superiname = supername; // iname == 'interstitial name'
for (int i=nmixins-1; i>=0; i--) {
String mixinname = ((ASTIdentifier)mixins.get(i)).getName();
- String iname = mixinname + "$";
+ String iname = "$lzsc$mixin$" + mixinname + "$";
if (superiname != null)
iname += superiname;
mixinRef.put(iname, new MixinReference(mixinname, superiname));
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins