esdl2xml.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef __ESDL2XML_HPP__
  14. #define __ESDL2XML_HPP__
  15. #include "jhash.hpp"
  16. #include "esdlcomp.h"
  17. typedef MapStringTo<bool> AddedHash;
  18. class Esdl2Esxdl : public CInterface
  19. {
  20. public:
  21. Esdl2Esxdl()
  22. {
  23. optRecursive = false;
  24. optVerbose = false;
  25. }
  26. Esdl2Esxdl(bool recursive, bool verbose)
  27. {
  28. optRecursive = recursive;
  29. optVerbose = verbose;
  30. }
  31. void setRecursive(bool recursive){optRecursive = recursive;};
  32. bool getRecursive(){return optRecursive;};
  33. void setVerbose(bool verbose){optVerbose = verbose;};
  34. bool getVerbose(){return optVerbose;};
  35. void transform(const char * source, const char * outdir="", StringBuffer * out=NULL, bool outputIncludes=true, bool includedESDL=false)
  36. {
  37. if (!added.getValue(source))
  38. {
  39. if (optVerbose)
  40. {
  41. fprintf(stdout, "Processing ESDL definition: %s\n", source);
  42. if (out==NULL && (!outdir || !*outdir))
  43. fprintf(stdout, "Output directory not specified\n");
  44. }
  45. //prevent recursive adding of this same content
  46. added.setValue(source, true);
  47. ESDLcompiler hc(source, out==NULL, outdir, outputIncludes, includedESDL, includePath);
  48. hc.Process();
  49. if (optRecursive && hc.includes)
  50. {
  51. StringBuffer subfile;
  52. StringBuffer srcDir(hc.getSrcDir());
  53. IncludeInfo * ii;
  54. for (ii=hc.includes;ii;ii=ii->next)
  55. {
  56. subfile.setf("%s%s%s", srcDir.str(), ii->pathstr.str(), ESDL_FILE_EXTENSION);
  57. transform(subfile, outdir, out, outputIncludes, true);
  58. }
  59. }
  60. if (out != NULL) //includes must come before body to handle ESDLDefVersions correctly
  61. out->append(hc.getEsxdlContent());
  62. if (optVerbose)
  63. fprintf(stdout, "Finished processing ESDL definition: %s\n", source);
  64. }
  65. else if (optVerbose)
  66. fprintf(stdout, "ESDL definition: %s has already been loaded!\n", source);
  67. }
  68. void setIncluePath(const char* path)
  69. {
  70. if (path && *path)
  71. includePath.set(path);
  72. }
  73. protected:
  74. bool optRecursive;
  75. bool optVerbose;
  76. StringAttr includePath;
  77. AddedHash added;
  78. };
  79. #endif