Browse Source

HPCC-11819 Restructure esdlcomp for advanced use
- Package scanner/parser compiler in shared lib (esdlcomp)
-- Move from tools/esdlcmd-xml to tools/esdlcomp
- Restructure scanner/parser code for rentry
-- Previously coded for one time use
- re-initialize globals used to house parsed tokens
- Isolate esdl2esxdl executable code
- Add verbose and recursive options to esdl2esxdl executable
- Remove unused artifacts
-
Signed-off-by: rpastrana <rodrigo.pastrana@lexisnexis.com>

rpastrana 11 years ago
parent
commit
7245a79429

+ 1 - 0
tools/CMakeLists.txt

@@ -13,6 +13,7 @@
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 ################################################################################
+HPCC_ADD_SUBDIRECTORY (esdlcomp)
 HPCC_ADD_SUBDIRECTORY (esdlcmd-xml)
 HPCC_ADD_SUBDIRECTORY (hidl)
 HPCC_ADD_SUBDIRECTORY (backupnode "PLATFORM")

+ 8 - 16
tools/esdlcmd-xml/CMakeLists.txt

@@ -24,27 +24,15 @@
 
 project( esdl-xml )
 
-add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/esdlgram.cpp ${CMAKE_CURRENT_BINARY_DIR}/esdlgram.h
-    COMMAND ${bisoncmdprefix} ${bisoncmd} --defines=${CMAKE_CURRENT_BINARY_DIR}/esdlgram.h --output=${CMAKE_CURRENT_BINARY_DIR}/esdlgram.cpp ${CMAKE_CURRENT_SOURCE_DIR}/esdlgram.y
-    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/esdlgram.y
-)
-
-add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/esdllex.cpp
-    COMMAND ${flexcmdprefix} ${flexcmd} --outfile=${CMAKE_CURRENT_BINARY_DIR}/esdllex.cpp ${CMAKE_CURRENT_SOURCE_DIR}/esdllex.l
-    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/esdllex.l
-)
-
 set ( SRCS
-        ${CMAKE_CURRENT_BINARY_DIR}/esdlgram.cpp
-        ${CMAKE_CURRENT_BINARY_DIR}/esdllex.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/esdlcomp.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/esdl_utils.cpp
+         ${CMAKE_CURRENT_SOURCE_DIR}/esdl2xml.cpp
     )
 
 include_directories (
          ${CMAKE_CURRENT_BINARY_DIR}   # for generated .h file
          ${HPCC_SOURCE_DIR}/system/include
+         ${HPCC_SOURCE_DIR}/system/jlib
+         ${HPCC_SOURCE_DIR}/tools/esdlcomp
          ${CMAKE_CURRENT_SOURCE_DIR}
     )
 
@@ -54,7 +42,7 @@ HPCC_ADD_EXECUTABLE ( esdl-xml ${SRCS} )
 
 # The tool esdl-xml is built in HPCCPlatform as a build-time
 # pre-req. But it is not distributed in CE packages.
-if ("${BUILD_LEVEL}" STREQUAL "ENTERPRISE")
+if ("${BUILD_LEVEL}" STREQUAL "ENTERPRISE" OR "${BUILD_LEVEL}" STREQUAL "INTERNAL")
     MESSAGE("----INSTALLING ESDL-XML")
     install ( TARGETS esdl-xml RUNTIME DESTINATION ${EXEC_DIR} )
     if ( UNIX )
@@ -62,3 +50,7 @@ if ("${BUILD_LEVEL}" STREQUAL "ENTERPRISE")
         install ( PROGRAMS esdl-xml.uninstall DESTINATION etc/init.d/uninstall COMPONENT Runtime )
     endif ( UNIX )
 endif()
+
+target_link_libraries ( esdl-xml
+                        jlib
+                        esdlcomp)

+ 27 - 26
tools/esdlcmd-xml/main.cpp

@@ -1,6 +1,6 @@
 /*##############################################################################
 
-    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
+    HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -18,30 +18,27 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "esdl2xml.hpp"
 
-#include "esdlcomp.h"
-
-int gArgc;
 char** gArgv = NULL;
+int gArgc = 0;
 
 //------------------------------------------------------
 // usage
-
-void usage(const char* programName)
+void static usage(const char* programName)
 {
-    printf("ESDL Compiler\n\n");
-    printf("Usage:  %s [options] filename.scm [<outdir>]\n\n", programName);
-    printf("Output:       filename.xml\n");
+    printf("\nESDL Compiler\n\n");
+    printf("Usage:        %s [options] filename.ecm [<outdir>]\n", programName);
+    printf("Output:       (srcdir|<outdir>)/filename.xml\n\n");
 
     puts("Available options:");
-    puts(" -?/-h: show this usage page");
+    puts(" -r|--recursive: process all includes");
+    puts(" -v|--verbose:   display information");
+    puts(" -?/-h:          show this usage page");
     exit(1);
 }
 
-//------------------------------------------------------
-// parse comamnd line: put non-option params into gArgv
-
-void parseCommandLine(int argc, char* argv[])
+void parseCommandLine(int argc, char* argv[], Esdl2Esxdl * cmd)
 {
     gArgv = new char*[argc+1];
     gArgc = 0;
@@ -52,12 +49,21 @@ void parseCommandLine(int argc, char* argv[])
         if (*argv[i]=='-')
         {
             if (stricmp(argv[i], "-?")==0 || stricmp(argv[i], "-h")==0)
+            {
                 usage(argv[0]);
-
+            }
+            else if (stricmp(argv[i], "-r")==0 || stricmp(argv[i], "--recursive")==0)
+            {
+                cmd->setRecursive(true);
+            }
+            else if (stricmp(argv[i], "-v")==0 || stricmp(argv[i], "--verbose")==0)
+            {
+                cmd->setVerbose(true);
+            }
             else
             {
-                printf("Unknown option: %s\n", argv[i]);
-                exit(1);
+                fprintf(stdout, "Unknown option: %s\n", argv[i]);
+                usage(argv[0]);
             }
         }
         else
@@ -74,16 +80,11 @@ void parseCommandLine(int argc, char* argv[])
 
 int main(int argc, char* argv[])
 {
-    parseCommandLine(argc, argv);
-
-    char* sourcefile = gArgv[1];
-    char* outdir = (gArgc>=3)?(char*)gArgv[2]:(char*)"";
-
-    ESDLcompiler hc(sourcefile, outdir);
-    hc.Process();
-
-    delete[] gArgv;
+    Owned<Esdl2Esxdl> cmd = new Esdl2Esxdl();
+    parseCommandLine(argc, argv, cmd.get());
+    cmd->transform(gArgv[1], (char*)gArgv[2]);
 
+    delete [] gArgv;
     return 0;
 }
 

+ 85 - 0
tools/esdlcmd-xml/esdl2xml.hpp

@@ -0,0 +1,85 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+#ifndef __ESDL2XML_HPP__
+#define __ESDL2XML_HPP__
+
+#include "jhash.hpp"
+#include "esdlcomp.h"
+
+typedef MapStringTo<bool> AddedHash;
+
+class Esdl2Esxdl : public CInterface
+{
+public:
+    IMPLEMENT_IINTERFACE;
+
+    Esdl2Esxdl()
+    {
+        optRecursive = false;
+        optVerbose   = false;
+    }
+
+    Esdl2Esxdl(bool recursive, bool verbose)
+    {
+        optRecursive = recursive;
+        optVerbose   = verbose;
+    }
+
+    void setRecursive(bool recursive){optRecursive = recursive;};
+    bool getRecursive(){return optRecursive;};
+
+    void setVerbose(bool verbose){optVerbose = verbose;};
+    bool getVerbose(){return optVerbose;};
+    void transform(const char * source, const char * outdir="")
+    {
+        if (added.getValue(source) == false)
+        {
+            if (optVerbose)
+            {
+                fprintf(stdout, "Processing ESDL definition: %s\n", source);
+                if (!outdir || !*outdir)
+                    fprintf(stdout, "Output directory not specified\n");
+            }
+
+            ESDLcompiler hc(source, outdir);
+            hc.Process();
+            added.setValue(source, true);
+
+            if (optRecursive && hc.includes)
+            {
+                StrBuffer subfile;
+                StrBuffer srcDir = hc.getSrcDir();
+
+                IncludeInfo * ii;
+                for (ii=hc.includes;ii;ii=ii->next)
+                {
+                   subfile.setf("%s%s.ecm", srcDir.str(), ii->pathstr.str());
+                   transform(subfile, outdir);
+                }
+            }
+        }
+        else if (optVerbose)
+            fprintf(stdout, "ESDL definition: %s has already been loaded!\n", source);
+    }
+
+protected:
+    bool      optRecursive;
+    bool      optVerbose;
+    AddedHash added;
+};
+
+#endif

+ 0 - 299
tools/esdlcmd-xml/esdl_esp_ng.cpp

@@ -1,299 +0,0 @@
-/*##############################################################################
-
-    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
-
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-############################################################################## */
-
-#pragma warning(disable:4786)
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <platform.h>
-#include "esdlcomp.h"
-#include <set>
-#include <string>
-
-extern int gOutfile;
-
-//more flexible SCM/ESP code gen initially for RiskWise -- ProtocolX
-void ESDLcompiler::write_esp_ng()
-{
-    //create the *.esp file
-    gOutfile = espng;
-    outf("// *** Source file generated by ESDL Version %s from %s.scm ***\n", ESDLVER, packagename);
-    outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
-
-    outf("#ifndef %s_ESP_NG_INCLUDED\n", packagename);
-    outf("#define %s_ESP_NG_INCLUDED\n\n", packagename);
-    outs("\n");
-    outs("#ifdef _WIN32\n");
-    outs("#include <process.h>\n");
-    outs("#endif\n");
-
-    outs("#include \"bind_ng.hpp\"\n");
-    outf("#include \"%s.hpp\"\n", packagename);
-
-    outs("\n\n");
-
-    EspMessageInfo * mi;
-    for (mi=msgs;mi;mi=mi->next)
-    {
-        mi->write_esp_ng_ipp();
-    }
-
-    EspServInfo *si;
-    for (si=servs;si;si=si->next)
-    {
-        si->write_esp_binding_ng_ipp(msgs);
-        outs("\n\n");
-        si->write_esp_service();
-        outs("\n\n");
-    }
-
-    outf("#endif //%s_ESP_NG_INCLUDED\n", packagename);
-}
-
-void ESDLcompiler::write_esp_ng_cpp()
-{
-    //create the *.esp file
-    gOutfile = espngc;
-    outf("// *** Source file generated by ESDL Version %s from %s.scm ***\n", ESDLVER, packagename);
-    outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
-    outf("#include \"%s_esp_ng.ipp\"\n\n\n", packagename);
-
-    EspServInfo *si;
-    for (si=servs;si;si=si->next)
-    {
-        si->write_esp_binding_ng_cpp(msgs);
-        outs("\n\n");
-    }
-}
-
-void EspMessageInfo::write_esp_ng_ipp()
-{
-    const char *parent=getParentName();
-    const char *baseclass=parent;
-    if (!baseclass)
-    {
-        switch(espm_type_)
-        {
-            case espm_struct:
-                baseclass="CEspNgStruct";
-                break;
-            case espm_request:
-                baseclass="CEspNgRequest";
-                break;
-            default:
-                baseclass="CEspNgResponse";
-                break;
-        }
-    }
-    outf("class CNg%s : public %s,\n", name_, baseclass);
-
-    outf("   implements IEsp%s\n", name_);
-    outs("{\n");
-
-    outs("protected:\n");
-    int pcount=0;
-    ParamInfo *pi=NULL;
-    for (pi=getParams();pi!=NULL;pi=pi->next)
-        pcount++;
-
-    outs(1, "int m_pcount;\n");
-    outf(1, "IEspNgParameter *m_params[%d];\n", pcount);
-
-    outs("public:\n\n");
-
-    outs(1,"StringBuffer m_serviceName;\n");
-    outs(1,"StringBuffer m_methodName;\n");
-    outs(1,"StringBuffer m_msgName;\n");
-
-    outs(1,"IMPLEMENT_IINTERFACE;\n\n");
-
-    outs(1, "void init_params()\n");
-    outs(1, "{\n");
-    outf(2, "m_pcount=%d;\n", pcount);
-    int pidx=0;
-    for (pi=getParams();pi!=NULL;pi=pi->next)
-    {
-        pi->write_esp_ng_declaration(pidx++);
-    }
-    outs(1, "}\n\n");
-
-    outs(1, "virtual IEspNgParameterIterator * getParameterIterator()\n");
-    outs(1, "{\n");
-    outs(2, "return new EspNgParameterIterator(m_params, m_pcount);\n");
-    outs(1, "}\n");
-
-    //default constructor
-    outf(1, "CNg%s(const char *serviceName){\n", name_);
-    outs(2, "m_serviceName.append(serviceName);\n");
-    outs(2, "init_params();\n");
-    outs(1, "}\n");
-
-    //default destructor -- bhegerle
-    outf(1, "~CNg%s() {\n", name_);
-    outs(2, "for(int i=0; i < m_pcount; i++)\n");
-    outs(3, "m_params[i]->Release();\n");
-    outs(1, "}\n");
-
-    if (espm_type_==espm_response)
-    {
-        outs(1,"virtual void setRedirectUrl(const char *url){CEspNgResponse::setRedirectUrl(url);}\n");
-        outs(1,"virtual const IMultiException & getExceptions(){return CEspNgResponse::getExceptions();}\n");
-        outs(1,"virtual void noteException(IException & e){CEspNgResponse::noteException(e);}\n");
-    }
-
-    outs("\n");
-    write_esp_methods_ng(espaxm_both);
-
-    outf(1, "virtual void copy(IConst%s &from){/*not implemented*/}\n", name_);
-    outf(1, "virtual const char * queryName(){return \"%s\";}\n", name_);
-
-    outs("};\n\n");
-}
-
-
-void ParamInfo::write_esp_ng_declaration(int pos)
-{
-    char metatype[256]={0};
-    cat_type(metatype);
-
-    esp_xlate_info *xlation=esp_xlat(metatype, false);
-    const char *type_name="StringBuffer";
-    if (xlation)
-    {
-        if (xlation->eam_type==EAM_jmbin || (flags & PF_TEMPLATE) || getMetaInt("attach", 0))
-            return; //not implemented
-        type_name=xlation->store_type;
-    }
-
-    int maxlen=getMetaInt("maxlen", -1);
-    if (!strcmp(type_name, "StringBuffer"))
-        outf(2, "m_params[%d]=new EspNgStringParameter(\"%s\", %d);\n", pos, name, maxlen);
-    else
-        outf(2, "m_params[%d]=new EspNgParameter<%s>(\"%s\", %d);\n", pos, type_name, name, maxlen);
-}
-
-void ParamInfo::write_esp_attr_method_ng(const char *msgname, int pos, bool isSet, bool hasNilRemove)
-{
-    char metatype[256]={0};
-    cat_type(metatype);
-
-    esp_xlate_info *xlation=esp_xlat(metatype);
-
-    char *methName=strdup(name);
-    *methName=upperchar(*methName);
-
-    if (isSet)
-    {
-        if (hasNilRemove)
-            outf(1,"void set%s_null(){ m_params[%d]->setNull(); }\n", methName, pos);
-        outf(1,"void set%s(%s val){m_params[%d]->setValue(val);}\n", methName, xlation->access_type, pos);
-    }
-    else
-    {
-        if (hasNilRemove)
-            outf(1,"bool get%s_isNull(){return m_params[%d]->isNull();}\n", methName, pos);
-        outf(1,"%s get%s(){return EspNgParamConverter(m_params[%d]);}\n", xlation->access_type, methName, pos);
-    }
-    free(methName);
-}
-
-void EspMessageInfo::write_esp_methods_ng(enum espaxm_type axstype)
-{
-    if (axstype!=espaxm_setters)
-    {
-        int pos=0;
-        ParamInfo *pi;
-        for (pi=getParams();pi!=NULL;pi=pi->next)
-        {
-            pi->write_esp_attr_method_ng(name_, pos++, false, getMetaInt("nil_remove")!=0);
-        }
-    }
-
-    if (axstype!=espaxm_getters)
-    {
-        int pos=0;
-        ParamInfo *pi;
-        for (pi=getParams();pi!=NULL;pi=pi->next)
-        {
-            pi->write_esp_attr_method_ng(name_, pos++, true, getMetaInt("nil_remove")!=0);
-        }
-    }
-}
-
-
-void EspServInfo::write_esp_binding_ng_ipp(EspMessageInfo *msgs)
-{
-    EspMethodInfo *mthi=NULL;
-
-    outs("\n\n");
-    outf("template <class base_binding> class CNg%sServiceBinding : public base_binding\n", name_);
-    outs("{\npublic:\n");
-
-    outf(1,"CNg%sServiceBinding(IPropertyTree* cfg, const char *bindname=NULL, const char *procname=NULL) : base_binding(cfg, bindname, procname){}\n", name_);
-
-    outs(1,"IEspNgRequest* createRequest(const char *method)\n");
-    outs(1,"{\n");
-    int count=0;
-    for (mthi=methods;mthi;mthi=mthi->next)
-    {
-        outf(2,"%sif (!stricmp(method, \"%s\"))\n", (count++==0)? "" : "else ", mthi->getName());
-        outs(2,"{\n");
-        outf(3,"return new CNg%s(\"%s\");\n", mthi->getReq(), name_);
-        outs(2,"}\n");
-    }
-    outs(2,"return NULL;\n");
-    outs(1,"}\n\n");
-
-    outs(1,"virtual IEspNgResponse* createResponse(const char *method)\n");
-    outs(1,"{\n");
-    count=0;
-    for (mthi=methods;mthi;mthi=mthi->next)
-    {
-        outf(2,"%sif (!stricmp(method, \"%s\"))\n", (count++==0)? "" : "else ", mthi->getName());
-        outs(2,"{\n");
-        outf(3,"return new CNg%s(\"%s\");\n", mthi->getResp(), name_);
-        outs(2,"}\n");
-    }
-    outs(2,"return NULL;\n");
-    outs(1,"}\n\n");
-
-    //method ==> processRequest
-    outs(1,"virtual int processRequest(IEspContext &context, const char *method_name, IEspNgRequest* req, IEspNgResponse* resp)\n");
-    outs(1,"{\n");
-    outf(2, "Owned<IEsp%s> iserv = (IEsp%s*)base_binding::getService();\n", name_, name_);
-    count=0;
-    for (mthi=methods;mthi;mthi=mthi->next)
-    {
-        outf(2,"%sif (!stricmp(method_name, \"%s\")/*||!stricmp(req->queryName(), \"%s\")*/)\n", (count++==0)? "" : "else ", mthi->getName(), mthi->getReq());
-        outs(2,"{\n");
-        outf(3,"return iserv->on%s(context, *dynamic_cast<IEsp%s*>(req), *dynamic_cast<IEsp%s*>(resp));\n", mthi->getName(), mthi->getReq(), mthi->getResp());
-        outs(2,"}\n");
-    }
-    outs(2,"return 0;\n");
-    outs(1,"}\n\n");
-
-    //method ==> getServiceName
-    outf(1,"StringBuffer & getServiceName(StringBuffer &resp){resp.clear().append(\"%s\");}\n", name_);
-
-    outs("};\n\n");
-}
-
-void EspServInfo::write_esp_binding_ng_cpp(EspMessageInfo *msgs)
-{
-}

+ 0 - 30
tools/esdlcmd-xml/esdlfile.cpp

@@ -1,30 +0,0 @@
-/*##############################################################################
-
-    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
-
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-############################################################################## */
-
-#include <hidlfile.h>
-
-HIDLfile::HIDLfile()
-{
-}
-
-HIDLfile::~HIDLfile()
-{
-}
-
-HIDLfile::Open()
-{
-}

+ 0 - 27
tools/esdlcmd-xml/esdlfile.h

@@ -1,27 +0,0 @@
-/*##############################################################################
-
-    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
-
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-############################################################################## */
-
-#include <afx.h>
-
-class HIDLfile : CFile
-{
-public:
-    HIDLfile();
-    ~HIDLfile();
-
-    Open();
-};

+ 62 - 0
tools/esdlcomp/CMakeLists.txt

@@ -0,0 +1,62 @@
+################################################################################
+#    HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+################################################################################
+# Component: esdlcomp
+#####################################################
+# Description:
+# ------------
+#    Cmake Input File for esdlcomp
+#####################################################
+
+project( esdlcomp )
+
+SET (REENTRANTBISONCMD "${bisoncmd} -d")
+add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/esdlgram.cpp ${CMAKE_CURRENT_BINARY_DIR}/esdlgram.h
+    COMMAND ${bisoncmdprefix} ${bisoncmd} --defines=${CMAKE_CURRENT_BINARY_DIR}/esdlgram.h --output=${CMAKE_CURRENT_BINARY_DIR}/esdlgram.cpp ${CMAKE_CURRENT_SOURCE_DIR}/esdlgram.y
+    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/esdlgram.y
+)
+
+add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/esdllex.cpp
+    COMMAND ${flexcmdprefix} ${flexcmd} --outfile=${CMAKE_CURRENT_BINARY_DIR}/esdllex.cpp --header-file=${CMAKE_CURRENT_BINARY_DIR}/esdllex.hpp ${CMAKE_CURRENT_SOURCE_DIR}/esdllex.l
+    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/esdllex.l
+)
+
+set ( SRCS
+        ${CMAKE_CURRENT_BINARY_DIR}/esdlgram.cpp
+        ${CMAKE_CURRENT_BINARY_DIR}/esdllex.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/esdlcomp.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/esdl_utils.cpp
+    )
+
+include_directories (
+         ${CMAKE_CURRENT_BINARY_DIR}   # for generated .h file
+         ${HPCC_SOURCE_DIR}/system/include
+         ${HPCC_SOURCE_DIR}/system/jlib
+         ${CMAKE_CURRENT_SOURCE_DIR}
+    )
+
+ADD_DEFINITIONS( -D_CONSOLE -O0 )
+HPCC_ADD_LIBRARY ( esdlcomp SHARED ${SRCS} )
+
+# The library esdlcomp is built in HPCCPlatform as a build-time
+# pre-req. But it is not distributed in CE packages.
+if ("${BUILD_LEVEL}" STREQUAL "ENTERPRISE" OR "${BUILD_LEVEL}" STREQUAL "INTERNAL")
+    MESSAGE("----INSTALLING esdlcomp")
+    #install ( TARGETS esdlcomp RUNTIME DESTINATION bin )
+    install ( TARGETS esdlcomp RUNTIME DESTINATION bin LIBRARY DESTINATION lib )
+endif()
+
+target_link_libraries ( esdlcomp
+                   jlib )

tools/esdlcmd-xml/esdl_utils.cpp → tools/esdlcomp/esdl_utils.cpp


tools/esdlcmd-xml/esdl_utils.hpp → tools/esdlcomp/esdl_utils.hpp


+ 35 - 36
tools/esdlcmd-xml/esdlcomp.cpp

@@ -35,14 +35,26 @@ inline bool es_strieq(const char* s,const char* t) { return stricmp(s,t)==0; }
 
 extern FILE *yyin;
 extern int yyparse();
+//extern int yydebug;
+
+//#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+//#define YY_TYPEDEF_YY_BUFFER_STATE
+//typedef struct yy_buffer_state *YY_BUFFER_STATE;
+//#endif
+
+//extern YY_BUFFER_STATE getCurrentBuffer();
+
+extern void yyrestart  (FILE * input_file );
+extern int yylex_destroy  (void);
+extern void yyInitESDLGlobals(ESDLcompiler * esdlcompiler);
 
 extern ESDLcompiler * hcp;
 extern char *esp_def_export_tag;
-// --- globals -----
-
 
+// --- globals -----
 int gOutfile = -1;
 
+CriticalSection ESDLcompiler::m_critSect;
 //-------------------------------------------------------------------------------------------------------------
 // Utility struct and function
 
@@ -465,8 +477,6 @@ bool ParamInfo::simpleneedsswap()
     }
 }
 
-
-
 void ParamInfo::cat_type(char *s,int deref,int var)
 {
     if ((flags&PF_CONST)&&!var)
@@ -787,7 +797,6 @@ void ParamInfo::setXsdType(const char *value)
     xsdtype = (newValue!=NULL) ? strdup(newValue) : NULL;
 }
 
-
 const char *ParamInfo::getXsdType()
 {
     if (xsdtype==NULL)
@@ -855,10 +864,6 @@ const char* ParamInfo::getArrayItemXsdType()
     }
 }
 
-
-
-
-
 //-------------------------------------------------------------------------------------------------------------
 // class ProcInfo
 
@@ -890,10 +895,6 @@ ProcInfo::~ProcInfo()
     }
 }
 
-
-
-
-
 //-------------------------------------------------------------------------------------------------------------
 // class ApiInfo
 
@@ -915,8 +916,6 @@ ApiInfo::~ApiInfo()
         free(group);
 }
 
-
-
 //-------------------------------------------------------------------------------------------------------------
 // class ModuleInfo
 
@@ -941,13 +940,9 @@ ModuleInfo::~ModuleInfo()
     }
 }
 
-
-
-
 //-------------------------------------------------------------------------------------------------------------
 // class EspMessageInfo
 
-
 bool EspMessageInfo::hasMapInfo()
 {
     for (ParamInfo* pi=getParams();pi!=NULL;pi=pi->next)
@@ -970,7 +965,6 @@ EspMessageInfo *EspMessageInfo::find_parent()
     return NULL;
 }
 
-
 char* makeXsdType(const char* s)
 {
     if (!s)
@@ -993,9 +987,6 @@ char* makeXsdType(const char* s)
         return NULL;
 }
 
-
-
-
 EspMessageInfo *EspMethodInfo::getRequestInfo()
 {
     EspMessageInfo *msg = hcp->msgs;
@@ -1095,6 +1086,7 @@ char* getTargetBase(const char* outDir, const char* src)
 
 ESDLcompiler::ESDLcompiler(const char * sourceFile,const char *outDir)
 {
+    //yydebug = 1;
     modules = NULL;
     enums = NULL;
     apis=NULL;
@@ -1104,19 +1096,24 @@ ESDLcompiler::ESDLcompiler(const char * sourceFile,const char *outDir)
     methods=NULL;
     versions = NULL;
 
-    splitFilename(sourceFile, NULL, NULL, &name, NULL);
+    splitFilename(sourceFile, NULL, &srcDir, &name, NULL);
 
 
     filename = strdup(sourceFile);
     size_t l = strlen(filename);
-    //sourceFile = es_changeext(sourceFile, "scm");
+
     yyin = fopen(sourceFile, "rt");
-    if (!yyin) {
-        printf("Fatal Error: Cannot read %s\n",sourceFile);
+    if (!yyin)
+    {
+        fprintf(stderr, "Fatal Error: Cannot read %s\n",sourceFile);
         exit(1);
     }
+
     packagename = es_gettail(sourceFile);
 
+    if (!outDir || !*outDir)
+        outDir = srcDir.str();
+
     char* targetBase = getTargetBase(outDir, sourceFile);
 
     esxdlo = es_createFile(targetBase,"xml");
@@ -1126,18 +1123,18 @@ ESDLcompiler::ESDLcompiler(const char * sourceFile,const char *outDir)
 
 ESDLcompiler::~ESDLcompiler()
 {
-    fclose(yyin);
-    close(esxdlo);
     free(packagename);
     free(filename);
 }
 
 void ESDLcompiler::Process()
 {
-    hcp = this;
+    CriticalBlock block(m_critSect);
 
-    nCommentStartLine = -1;
+    yyInitESDLGlobals(this);
+    yyrestart (yyin);
     yyparse();
+
     if (nCommentStartLine > -1)
     {
         char tempBuf[256];
@@ -1145,6 +1142,11 @@ void ESDLcompiler::Process()
         yyerror(tempBuf);
     }
     write_esxdl();
+
+    fclose(yyin);
+    close(esxdlo);
+
+    yylex_destroy();
 }
 
 void ESDLcompiler::write_esxdl()
@@ -1161,7 +1163,7 @@ void ESDLcompiler::write_esxdl()
     }
 
     IncludeInfo * ii;
-    for (ii=includes;ii;ii=ii->next)
+    for (ii=hcp->includes;ii;ii=ii->next)
     {
         ii->write_esxdl();
     }
@@ -1188,12 +1190,9 @@ void ESDLcompiler::write_esxdl()
     }
 
     outs("</esxdl>");
-
-
+    gOutfile = -1;
 }
 
-
-
 //-------------------------------------------------------------------------------------------------------------
 // class EnumInfo
 

+ 25 - 15
tools/esdlcmd-xml/esdlcomp.h

@@ -23,7 +23,7 @@
 
 #include "esdl_utils.hpp"
 #include "../../system/include/platform.h"
-
+#include "jmutex.hpp"
 
 #undef YYSTYPE
 #define YYSTYPE attribute
@@ -1036,7 +1036,6 @@ public:
         outs("/>\n");
     }
 
-
     MetaTagInfo     *tags;
     EspMethodInfo   *next;
 };
@@ -1228,33 +1227,44 @@ public:
 class ESDLcompiler
 {
 public:
-    ESDLcompiler(const char * SourceFile,const char *OutDir);
+    ESDLcompiler(const char * sourceFile, const char * outDir);
     ~ESDLcompiler();
 
     void Process();
     void write_esxdl();
 
-    const char *getPackageName(){return packagename;}
-    char *       filename;
+    const char * getSrcDir() const
+    {
+        return srcDir.str();
+    }
+
+    const char* getPackageName()
+    {
+        return packagename;
+    }
+
+    char* filename;
     StrBuffer name;
 
 private:
     int esxdlo;
-    char *       packagename;
+    char* packagename;
+    StrBuffer srcDir;
+    StrBuffer outBuffer;
 
 public:
-    ModuleInfo * modules;
-    EnumInfo * enums;
-    ApiInfo *apis;
-    EspMessageInfo *msgs;
-    EspServInfo *servs;
-    EspMethodInfo *methods;
-    IncludeInfo *includes;
-    VersionInfo *versions;
+    static CriticalSection m_critSect;
+    ModuleInfo* modules;
+    EnumInfo* enums;
+    ApiInfo* apis;
+    EspMessageInfo* msgs;
+    EspServInfo* servs;
+    EspMethodInfo* methods;
+    IncludeInfo* includes;
+    VersionInfo* versions;
 };
 
 
-//extern char * clarion;
 extern int nCommentStartLine;
 extern void yyerror(const char *s);
 inline char upperchar(char val){return ((val<97 || val>122) ? val : (val-32));}

+ 98 - 66
tools/esdlcmd-xml/esdlgram.y

@@ -932,7 +932,6 @@ ProcDef
  }
  ;
 
-
 ProcAttr
  : Virtual
  | Callback
@@ -945,7 +944,6 @@ ProcAttrList
  |
  ;
 
-
 RetParam
  : StartRetParam TypeModifiers TypeList
  {
@@ -980,7 +978,6 @@ ParamList
  }
  ;
 
-
 Param
  : StartParam TypeModifiers TypeList
  {
@@ -1002,8 +999,6 @@ TypeModifier
  | Layout
  ;
 
-
-
 Layout
  : LAYOUT '(' LayoutParams ')'
  {
@@ -1442,17 +1437,16 @@ string_const
 
 %%
 
-
 void AddModule()
 {
-   if (CurModule)
-   {
-     if (LastModule)
-       LastModule->next = CurModule;
-     else
-       hcp->modules = CurModule;
-     LastModule = CurModule;
-   }
+    if (CurModule)
+    {
+        if (LastModule)
+            LastModule->next = CurModule;
+        else
+            hcp->modules = CurModule;
+        LastModule = CurModule;
+    }
 }
 
 void TestOut(const char *str)
@@ -1462,74 +1456,74 @@ void TestOut(const char *str)
 
 void AddApi()
 {
-   if (CurApi)
-   {
-     if (LastApi)
-       LastApi->next = CurApi;
-     else
-       hcp->apis = CurApi;
-     LastApi = CurApi;
-   }
+    if (CurApi)
+    {
+        if (LastApi)
+            LastApi->next = CurApi;
+        else
+            hcp->apis = CurApi;
+        LastApi = CurApi;
+    }
 }
 
 void AddEspMessage()
 {
-   if (CurEspMessage)
-   {
-     if (LastEspMessage)
-       LastEspMessage->next = CurEspMessage;
-     else
-       hcp->msgs = CurEspMessage;
-     LastEspMessage = CurEspMessage;
+    if (CurEspMessage)
+    {
+        if (LastEspMessage)
+            LastEspMessage->next = CurEspMessage;
+        else
+            hcp->msgs = CurEspMessage;
+        LastEspMessage = CurEspMessage;
    }
 }
 
 void AddEspProperty()
 {
-   if (CurParam)
-   {
-     if (LastParam)
-       LastParam->next = CurParam;
-     else
-       CurEspMessage->setParams(CurParam);
-     LastParam = CurParam;
+    if (CurParam)
+    {
+        if (LastParam)
+            LastParam->next = CurParam;
+        else
+            CurEspMessage->setParams(CurParam);
+        LastParam = CurParam;
    }
 }
 
 void AddEspService()
 {
-   if (CurService)
-   {
-     if (LastService)
-       LastService->next = CurService;
-     else
-       hcp->servs = CurService;
-     LastService = CurService;
-   }
+    if (CurService)
+    {
+        if (LastService)
+           LastService->next = CurService;
+        else
+           hcp->servs = CurService;
+        LastService = CurService;
+    }
 }
 
 void AddEspMethod()
 {
-   if (CurMethod)
-   {
-     if (LastMethod)
-       LastMethod->next = CurMethod;
-     else
-       hcp->methods = CurMethod;
-     LastMethod = CurMethod;
+    if (CurMethod)
+    {
+        if (LastMethod)
+            LastMethod->next = CurMethod;
+        else
+            hcp->methods = CurMethod;
+        LastMethod = CurMethod;
    }
 }
 
 void AddEspInclude()
 {
-   if (CurInclude)
-   {
-     if (LastInclude)
-       LastInclude->next = CurInclude;
-     else
-       hcp->includes = CurInclude;
-     LastInclude = CurInclude;
-   }
+    if (CurInclude)
+    {
+        if (LastInclude)
+            LastInclude->next = CurInclude;
+        else
+            hcp->includes = CurInclude;
+        LastInclude = CurInclude;
+    }
 }
 
 void AddMetaTag(MetaTagInfo *mti)
@@ -1570,16 +1564,54 @@ MetaTagInfo* getClearCurMetaTags()
 
 void AddEnum()
 {
-   if (CurEnum)
-   {
-     if (LastEnum)
-       LastEnum->next = CurEnum;
-     else
-       hcp->enums = CurEnum;
-     LastEnum = CurEnum;
+    if (CurEnum)
+    {
+        if (LastEnum)
+            LastEnum->next = CurEnum;
+        else
+            hcp->enums = CurEnum;
+        LastEnum = CurEnum;
    }
 }
 
+void yyInitESDLGlobals(ESDLcompiler * esdlcompiler)
+{
+    hcp = esdlcompiler;
+    CurModule=NULL;
+    CurProc=NULL;
+    CurParam=NULL;
+    CurLayout=NULL;
+    CurEnum=NULL;
+    CurEnumVal=NULL;
+    EnumValue = 0;
+    CurApi=NULL;
+    CurInclude=NULL;
+
+    CurEspMessage=NULL;
+    CurService=NULL;
+    CurMethod=NULL;
+    CurMetaTags=NULL;
+
+    LastModule=NULL;
+    LastProc=NULL;
+    LastParam=NULL;
+    LastLayout=NULL;
+    LastEnum=NULL;
+    LastEnumVal=NULL;
+    LastApi=NULL;
+    LastInclude=NULL;
+
+    LastEspMessage=NULL;
+    LastService=NULL;
+    LastMethod=NULL;
+
+    esp_def_export_tag=NULL;
+
+    unsigned linenum=1;
+    unsigned errnum=0;
+    nCommentStartLine = -1;
+}
+
 
 extern char *yytext;
 void yyerror(const char *s)

+ 11 - 0
tools/esdlcmd-xml/esdllex.l

@@ -10,6 +10,12 @@
 extern YYSTYPE yylval;
 extern unsigned linenum;
 
+extern void yy_flush_buffer (YY_BUFFER_STATE b  );
+//#define YY_CURRENT_BUFFER void()
+//extern YY_CURRENT_BUFFER;
+//extern YY_FLUSH_BUFFER;
+//extern void * getCurrentBuffer();
+
 static enum { LSskip,LSclarion,LSsectionheader,LSsectionbody,LSsectionfooter} state=LSskip;
 static int   opencurly=0;
 
@@ -282,6 +288,11 @@ int yywrap()
 }
 #endif
 
+YY_BUFFER_STATE getCurrentBuffer()
+{
+    return YY_CURRENT_BUFFER;
+}
+
 void output_text()
 {
     if (state==LSclarion) {