[mapguide-commits] r7622 - in sandbox/jng/node: BuildTools/WebTools/IMake BuildTools/WebTools/IMake/Win32 Web/src/MapGuideApi

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jun 14 05:48:24 PDT 2013


Author: jng
Date: 2013-06-14 05:48:24 -0700 (Fri, 14 Jun 2013)
New Revision: 7622

Modified:
   sandbox/jng/node/BuildTools/WebTools/IMake/IMake.cpp
   sandbox/jng/node/BuildTools/WebTools/IMake/Win32/IMake.exe
   sandbox/jng/node/Web/src/MapGuideApi/Constants.xml
Log:
Update IMake to support generating constants for javascript

Modified: sandbox/jng/node/BuildTools/WebTools/IMake/IMake.cpp
===================================================================
--- sandbox/jng/node/BuildTools/WebTools/IMake/IMake.cpp	2013-06-14 12:19:56 UTC (rev 7621)
+++ sandbox/jng/node/BuildTools/WebTools/IMake/IMake.cpp	2013-06-14 12:48:24 UTC (rev 7622)
@@ -9,10 +9,11 @@
     unknown,
     php,
     csharp,
-    java
+    java,
+    javascript
 };
 
-static char version[] = "1.2";
+static char version[] = "1.3";
 
 static string module;
 static string customPath;
@@ -251,6 +252,13 @@
             if(language == php)
                 parseTypeReplacements(node, typeReplacements);
         }
+        else if(node->name == "JavaScriptTypeReplacements")
+        {
+            if(!translateMode)
+                error("JavaScriptTypeReplacements is not a valid section in SWIG mode");
+            if(language == javascript)
+                parseTypeReplacements(node, typeReplacements);
+        }
         else if(node->name == "JavaTypeReplacements")
         {
             if(!translateMode)
@@ -1257,15 +1265,25 @@
                             string expr = comment.substr(posBeginValue + 6, strLen);
                             comment = comment.substr(0, posBeginValue) + comment.substr(posEndValue + 1);
 
+                            string endstr = ";";
+                            string assignOp = "=";
+                            if (language == javascript)
+                            {
+                                //We use object literal notation for JS
+                                endstr = ",";
+                                comment = "";
+                                assignOp = ":";
+                            }
+
                             if(Trim(comment) == "")
                             {
                                 //comment contained only the string value. remove comment at all
-                                token = " = " + expr + ";";
+                                token = " " + assignOp + " " + expr + endstr;
                             }
                             else
                             {
                                 // insert
-                                token = " = " + expr + "; /// " + comment;
+                                token = " " + assignOp + " " + expr + endstr +" /// " + comment;
                             }
                             assignmentAdded = true;
                         }
@@ -1353,8 +1371,24 @@
             }
         }
 
-        if(token.length() > 0)
+        if (token.length() > 0) 
+        {
+            if (translateMode && language == javascript)
+            {
+                //This is an assignment expression
+                if (token.find('=') != string::npos)
+                {
+                    std::replace(token.begin(), token.end(), '=', ':');
+                }
+                if (token.find(';') != string::npos)
+                {
+                    std::replace(token.begin(), token.end(), ';', ',');
+                    token += "\n";
+                }
+            }
+            
             fprintf(outfile, "%s ", token.c_str());
+        }
 
         if (token.find('~') != string::npos)
         {
@@ -1498,7 +1532,11 @@
             if(translateMode && (language == java || language == csharp))
                 fprintf(outfile, "public ");
 
-            fprintf(outfile, "class %s", className.c_str());
+            if (translateMode && language == javascript)
+                fprintf(outfile, "OSGeo.MapGuide.%s = ", className.c_str());
+            else
+                fprintf(outfile, "class %s", className.c_str());
+
             if(colonPos != -1)
             {
                 fprintf(outfile, " : ");
@@ -1553,8 +1591,12 @@
         //end of class
         if(!ignore)
         {
+            if (translateMode && language == javascript)
+            {
+                fprintf(outfile, "CLASS_NAME:\"%s\"\n\n", className.c_str());
+            }
             fprintf(outfile, "\n}");
-            if(!translateMode) {
+            if(!translateMode || language == javascript) {
                 fprintf(outfile, ";\n\n");
             }
             else {
@@ -1659,6 +1701,11 @@
         }
     }
 
+    if(language == javascript)
+    {
+        fprintf(outfile, "if (typeof(OSGeo) == 'undefined') OSGeo = {};\nif (typeof(OSGeo.MapGuide) == 'undefined') OSGeo.MapGuide = {};\n");
+    }
+
     if(language == php)
         fprintf(outfile, "<?php\n\n");
     else
@@ -1730,7 +1777,7 @@
     printf("\n      parameterFile: XML description of generation parameters\n");
     printf("\n      lang: Target language (PHP, C# or Java).\n");
     printf("\n      generation_path_or_folder: Do not generate SWIG.  Generate constant definitions.");
-    printf("\n                                 For PHP and C#, pathname of the constant file.");
+    printf("\n                                 For PHP, JavaScript and C#, pathname of the constant file.");
     printf("\n                                 For Java, folder where the constant files are created");
     exit(1);
 }
@@ -1762,6 +1809,8 @@
     }
     else if(!strcmp(argv[2], "Java"))
         language = java;
+    else if(!strcmp(argv[2], "JavaScript"))
+        language = javascript;
     else
         usage();
 

Modified: sandbox/jng/node/BuildTools/WebTools/IMake/Win32/IMake.exe
===================================================================
(Binary files differ)

Modified: sandbox/jng/node/Web/src/MapGuideApi/Constants.xml
===================================================================
--- sandbox/jng/node/Web/src/MapGuideApi/Constants.xml	2013-06-14 12:19:56 UTC (rev 7621)
+++ sandbox/jng/node/Web/src/MapGuideApi/Constants.xml	2013-06-14 12:48:24 UTC (rev 7622)
@@ -5,6 +5,18 @@
 <!--
    Type replacements.
 -->
+<JavaScriptTypeReplacements>
+    <TypeReplacement oldtype="STRING" newtype="" />
+    <TypeReplacement oldtype="INT8" newtype="" />
+    <TypeReplacement oldtype="INT16" newtype="" />
+    <TypeReplacement oldtype="INT32" newtype="" />
+    <TypeReplacement oldtype="int" newtype="" />
+    <TypeReplacement oldtype="float" newtype="" />
+    <TypeReplacement oldtype="double" newtype="" />
+    <TypeReplacement oldtype="static" newtype="" />
+    <TypeReplacement oldtype="bool" newtype="" />
+    <TypeReplacement oldtype="const" newtype="" />
+</JavaScriptTypeReplacements>
 <PHPTypeReplacements>
     <TypeReplacement oldtype="STRING" newtype="" />
     <TypeReplacement oldtype="INT8" newtype="" />



More information about the mapguide-commits mailing list