[Laszlo-checkins] r14016 - openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler

hqm@openlaszlo.org hqm at openlaszlo.org
Wed May 27 08:16:28 PDT 2009


Author: hqm
Date: 2009-05-27 08:16:24 -0700 (Wed, 27 May 2009)
New Revision: 14016

Modified:
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
   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 20090526-hqm-s by hqm at badtzmaru.home on 2009-05-26 17:07:58 EDT
    in /Users/hqm/openlaszlo/trunk-clean
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary:  make all compiler property definitions visible to <switch> tag

New Features:

Bugs Fixed: LPP-8228 

Technical Reviewer: ptw
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:

+ we were storing the "runtime constants" (e.g., the vars that says what runtime is $swf8, $swf9, etc)
in a separate table in the CompilationEnvironment, and that was the only table being checked by
the switch tag to look up properties. 

This change
    

Tests:

run smoke  in all runtimes
compile 

lzc -Dfoobar=true foo.lzx

and see if you can  select on the 'foobar' property

<switch>
  <when property="foobar" value="true">
    <script>
      Debug.write('conditionally compiled: compile time constant foobar is true');
    </script>
  </when>
  <otherwise>
    <script>
      Debug.write('otherwise clause select: foobar was false');
    </script>
  </otherwise>
</switch>




Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java	2009-05-27 10:30:06 UTC (rev 14015)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java	2009-05-27 15:16:24 UTC (rev 14016)
@@ -161,8 +161,6 @@
 
     private List mLibraryCompilations = new ArrayList();
 
-    private Map mCompileTimeConstants = null;
-
     /** Information about where the ScriptCompiler put intermediate
      * working files. This is used for linking loadable libraries for
      * as3 runtime */
@@ -208,8 +206,6 @@
         // Default property values
         this.mSchema = srcEnv.getSchema();
         this.mCanvas = srcEnv.getCanvas();
-        this.mCompileTimeConstants = srcEnv.getCompileTimeConstants();
-
         this.mImportedLibraryFiles = new HashSet(srcEnv.getImportedLibraryFiles());
         this.mLoadableImportedLibraryFiles = srcEnv.getLoadableImportedLibraryFiles();
         this.mResourceNames = srcEnv.getResourceNames();
@@ -808,27 +804,38 @@
         return mMainCompilationEnv != null ? mMainCompilationEnv : this;
     }
 
-    public void setCompileTimeConstants(Map map) {
-        mCompileTimeConstants = map;
-    }
-
     public Map getCompileTimeConstants() {
-        return mCompileTimeConstants;
+        HashMap cc = new HashMap();
+        cc.put("$runtime",   mProperties.get("$runtime"));
+        cc.put("$swf7",      mProperties.get("$swf7"));
+        cc.put("$swf8",      mProperties.get("$swf8"));
+        cc.put("$as2",       mProperties.get("$as2"));
+        cc.put("$swf9",      mProperties.get("$swf9"));
+        cc.put("$swf10",     mProperties.get("$swf10"));
+        cc.put("$as3",       mProperties.get("$as3"));
+        cc.put("$dhtml",     mProperties.get("$dhtml"));
+        cc.put("$j2me",      mProperties.get("$j2me"));
+        cc.put("$svg",       mProperties.get("$svg"));
+        cc.put("$js1",       mProperties.get("$js1"));
+        cc.put("$debug",     mProperties.get("$debug"));
+        cc.put("$profile",   mProperties.get("$profile"));
+        cc.put("$backtrace", mProperties.get("$backtrace"));
+        return cc;
     }
 
     // Set up runtime-related compile-time constants 
     public void setRuntimeConstants(String runtime) {
-        mCompileTimeConstants.put("$runtime", runtime);
-        mCompileTimeConstants.put("$swf7", Boolean.valueOf("swf7".equals(runtime)));
-        mCompileTimeConstants.put("$swf8", Boolean.valueOf("swf8".equals(runtime)));
-        mCompileTimeConstants.put("$as2", Boolean.valueOf(Arrays.asList(new String[] {"swf7", "swf8"}).contains(runtime)));
-        mCompileTimeConstants.put("$swf9", Boolean.valueOf("swf9".equals(runtime)));
-        mCompileTimeConstants.put("$swf10", Boolean.valueOf("swf10".equals(runtime)));
-        mCompileTimeConstants.put("$as3", Boolean.valueOf(this.isAS3()));
-        mCompileTimeConstants.put("$dhtml", Boolean.valueOf("dhtml".equals(runtime)));
-        mCompileTimeConstants.put("$j2me", Boolean.valueOf("j2me".equals(runtime)));
-        mCompileTimeConstants.put("$svg", Boolean.valueOf("svg".equals(runtime)));            
-        mCompileTimeConstants.put("$js1", Boolean.valueOf(Arrays.asList(new String[] {"dhtml", "j2me", "svg"}).contains(runtime)));
+        mProperties.put("$runtime", runtime);
+        mProperties.put("$swf7", Boolean.valueOf("swf7".equals(runtime)));
+        mProperties.put("$swf8", Boolean.valueOf("swf8".equals(runtime)));
+        mProperties.put("$as2", Boolean.valueOf(Arrays.asList(new String[] {"swf7", "swf8"}).contains(runtime)));
+        mProperties.put("$swf9", Boolean.valueOf("swf9".equals(runtime)));
+        mProperties.put("$swf10", Boolean.valueOf("swf10".equals(runtime)));
+        mProperties.put("$as3", Boolean.valueOf(this.isAS3()));
+        mProperties.put("$dhtml", Boolean.valueOf("dhtml".equals(runtime)));
+        mProperties.put("$j2me", Boolean.valueOf("j2me".equals(runtime)));
+        mProperties.put("$svg", Boolean.valueOf("svg".equals(runtime)));            
+        mProperties.put("$js1", Boolean.valueOf(Arrays.asList(new String[] {"dhtml", "j2me", "svg"}).contains(runtime)));
     }
 
 }

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-05-27 10:30:06 UTC (rev 14015)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java	2009-05-27 15:16:24 UTC (rev 14016)
@@ -186,6 +186,7 @@
         // Compile to a byte-array, and write out to objectFile, and
         // write a copy into sourceFile.[swf|js] if this is a serverless deployment.
         CompilationEnvironment env = makeCompilationEnvironment(props);
+
         ByteArrayOutputStream bstream = new ByteArrayOutputStream();
         OutputStream ostream = new FileOutputStream(objectFile);
         env.setObjectFile(objectFile);
@@ -337,14 +338,13 @@
             }
 
 
-            Map compileTimeConstants = new HashMap();
-            env.setCompileTimeConstants(compileTimeConstants);
+            Map props = env.getProperties();
 
-            compileTimeConstants.put("$debug", new Boolean(
+            props.put("$debug", new Boolean(
                                          env.getBooleanProperty(CompilationEnvironment.DEBUG_PROPERTY)));
-            compileTimeConstants.put("$profile", new Boolean(
+            props.put("$profile", new Boolean(
                                          env.getBooleanProperty(CompilationEnvironment.PROFILE_PROPERTY)));
-            compileTimeConstants.put("$backtrace", new Boolean(
+            props.put("$backtrace", new Boolean(
                                          env.getBooleanProperty(CompilationEnvironment.BACKTRACE_PROPERTY)));
 
             String runtime = env.getProperty(env.RUNTIME_PROPERTY);
@@ -393,7 +393,7 @@
             // 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
             // better way to ensure that the LFC's constants values match the app code's.
-            nprops.put("compileTimeConstants", compileTimeConstants);
+            nprops.put("compileTimeConstants", env.getCompileTimeConstants());
 
             ObjectWriter writer = createObjectWriter(nprops, ostr, env, root);
 

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-05-27 10:30:06 UTC (rev 14015)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java	2009-05-27 15:16:24 UTC (rev 14016)
@@ -400,7 +400,7 @@
         Document doc = read(file);
         Element root = doc.getRootElement();
 
-        Map cc = env.getCompileTimeConstants();
+        Map cprops = env.getProperties();
         // Override passed in runtime target properties 'debug' and 'profile' with 
         // canvas values, if any.
         if (root.getName().equals("canvas")) {
@@ -415,13 +415,13 @@
             // options is compileroptions="debug: true;backtrace: true"
             String dbg = root.getAttributeValue("debug");
             if (dbg != null) {
-                cc.put("$debug", new Boolean(dbg));
+                cprops.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));
+                cprops.put("$profile", new Boolean(prof));
                 env.setProperty(CompilationEnvironment.PROFILE_PROPERTY,  prof.equals("true"));
             }
         }
@@ -436,7 +436,7 @@
 
     // Set compiler options
     void parseCompilerOptions(Element element, CompilationEnvironment env) {
-        Map cc = env.getCompileTimeConstants();
+        Map cprops = env.getProperties();
 
         try {
             Map properties = new CSSParser
@@ -453,19 +453,19 @@
                     if (! (value instanceof Boolean)) {
                         throw new CompilationError("value of compileroptions.debug must be a boolean", element);
                     }
-                    cc.put("$debug", value);
+                    cprops.put("$debug", value);
                     env.setProperty(env.DEBUG_PROPERTY, ((Boolean) value).booleanValue());
                 } else if (key.equals("profile")) {
                     if (! (value instanceof Boolean)) {
                         throw new CompilationError("value of compileroptions.profile must be a boolean", element);
                     }
-                    cc.put("$profile", value);
+                    cprops.put("$profile", value);
                     env.setProperty(env.PROFILE_PROPERTY, ((Boolean) value).booleanValue());
                 } else if (key.equals("backtrace")) {
                     if (! (value instanceof Boolean)) {
                         throw new CompilationError("value of compileroptions.backtrace must be a boolean", element);
                     }
-                    cc.put("$backtrace", value);
+                    cprops.put("$backtrace", value);
                     env.setProperty(env.BACKTRACE_PROPERTY, ((Boolean) value).booleanValue());
                 } else if (key.equals("runtime")) {
                     env.setProperty(env.RUNTIME_PROPERTY, (String)value);
@@ -495,8 +495,8 @@
     protected boolean evaluateConditions(Element element, CompilationEnvironment env) {
         String propname = element.getAttributeValue("property");
         if ( propname != null) {
-            Map cc = env.getCompileTimeConstants();
-            Object prop = cc.get(propname);
+            Map cprops = env.getProperties();
+            Object prop = cprops.get(propname);
             if (prop == null) {
                 return false;
             } else if (prop instanceof Boolean) {



More information about the Laszlo-checkins mailing list