esdlcomp.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 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 __ESDLCOMP_H__
  14. #define __ESDLCOMP_H__
  15. #include <stdarg.h>
  16. #include <assert.h>
  17. #include "platform.h"
  18. #include "jmutex.hpp"
  19. #include "jstring.hpp"
  20. #include "jfile.hpp"
  21. #include "esdldecl.hpp"
  22. #undef YYSTYPE
  23. #define YYSTYPE attribute
  24. #define ESDLVER "1.2"
  25. #define MAX_IDENT 2048
  26. #define RETURNNAME "_return"
  27. #ifndef _WIN32
  28. #define stricmp strcasecmp
  29. #endif
  30. inline bool es_streq(const char* s, const char* t) { return strcmp(s,t)==0; }
  31. #define PF_IN 0x1
  32. #define PF_OUT 0x2
  33. #define PF_VARSIZE 0x4
  34. #define PF_PTR 0x8
  35. #define PF_REF 0x10
  36. #define PF_CONST 0x40
  37. #define PF_SIMPLE 0x80
  38. #define PF_RETURN 0x100
  39. #define PF_STRING 0x200
  40. #define PF_TEMPLATE 0x400
  41. #define PF_ESPSTRUCT 0x800
  42. #define PF_MASK 0x7fff
  43. #define LEGACY_FILE_EXTENSION ".ecm"
  44. #define ESDL_FILE_EXTENSION ".esdl"
  45. #define XML_FILE_EXTENSION ".xml"
  46. enum type_kind
  47. {
  48. TK_null,
  49. TK_CHAR,
  50. TK_UNSIGNEDCHAR,
  51. TK_BYTE,
  52. TK_BOOL,
  53. TK_SHORT,
  54. TK_UNSIGNEDSHORT,
  55. TK_INT,
  56. TK_UNSIGNED,
  57. TK_LONG,
  58. TK_UNSIGNEDLONG,
  59. TK_LONGLONG,
  60. TK_UNSIGNEDLONGLONG,
  61. TK_DOUBLE,
  62. TK_FLOAT,
  63. TK_STRUCT,
  64. TK_ENUM,
  65. TK_VOID,
  66. TK_ESPSTRUCT,
  67. TK_ESPENUM
  68. };
  69. enum EAMType
  70. {
  71. EAM_basic,
  72. EAM_jsbuf,
  73. EAM_jmbuf,
  74. EAM_jmbin
  75. };
  76. typedef struct esp_xlate_info_
  77. {
  78. const char *meta_type;
  79. const char *xsd_type;
  80. const char *store_type;
  81. const char *array_type;
  82. const char *access_type;
  83. enum type_kind access_kind;
  84. unsigned access_flags;
  85. enum EAMType eam_type;
  86. } esp_xlate_info;
  87. esp_xlate_info *esp_xlat(const char *from, bool defaultToString=true);
  88. enum clarion_special_type_enum { cte_normal,cte_longref,cte_constcstr,cte_cstr };
  89. void out(const char*, size_t);
  90. void outs(const char*);
  91. void outf(const char*,...) __attribute__((format(printf, 1, 2)));
  92. void outs(int indent, const char*);
  93. void outf(int indent, const char*,...) __attribute__((format(printf, 2, 3)));
  94. char *appendstr(char *text,const char *str);
  95. struct attribute
  96. {
  97. private:
  98. union
  99. {
  100. char *str_val;
  101. int int_val;
  102. double double_val;
  103. };
  104. enum { t_none, t_string, t_int, t_double } atr_type;
  105. char name_[MAX_IDENT];
  106. public:
  107. attribute()
  108. {
  109. atr_type=t_none;
  110. str_val=NULL;
  111. }
  112. ~attribute()
  113. {
  114. release();
  115. }
  116. void release()
  117. {
  118. if (atr_type==t_string)
  119. free(str_val);
  120. atr_type=t_none;
  121. }
  122. void setVal(int val)
  123. {
  124. release();
  125. int_val=val;
  126. atr_type = t_int;
  127. }
  128. void setVal(double val)
  129. {
  130. release();
  131. double_val=val;
  132. atr_type = t_double;
  133. }
  134. void setVal(char *val)
  135. {
  136. release();
  137. str_val=val;
  138. atr_type = t_int;
  139. }
  140. const char *getString()
  141. {
  142. return str_val;
  143. }
  144. int getInt()
  145. {
  146. return int_val;
  147. }
  148. double getDouble()
  149. {
  150. return double_val;
  151. }
  152. const char *getName(){return name_;}
  153. void setName(const char *value)
  154. {
  155. strcpy(name_,(value)? value : (char *)"");
  156. }
  157. void setNameF(const char *format, ...) __attribute__((format(printf, 2, 3)))
  158. {
  159. va_list args;
  160. va_start(args, format);
  161. _vsnprintf(name_, MAX_IDENT,format, args);
  162. va_end(args);
  163. }
  164. };
  165. class LayoutInfo
  166. {
  167. public:
  168. LayoutInfo();
  169. ~LayoutInfo();
  170. char * size;
  171. char * count;
  172. LayoutInfo * next;
  173. };
  174. class MetaTagInfo
  175. {
  176. private:
  177. char *name_;
  178. union
  179. {
  180. char *str_val_;
  181. int int_val_;
  182. double double_val_;
  183. };
  184. public:
  185. enum {mt_none, mt_int, mt_string, mt_double, mt_const_id} mttype_;
  186. MetaTagInfo *next;
  187. public:
  188. MetaTagInfo(const char *name, const char *strval)
  189. {
  190. mttype_=mt_string;
  191. str_val_=strdup(strval);
  192. name_ = strdup(name);
  193. }
  194. MetaTagInfo(const char *name, const char *strval,bool)
  195. {
  196. mttype_=mt_const_id;
  197. str_val_=strdup(strval);
  198. name_ = strdup(name);
  199. }
  200. MetaTagInfo(const char *name, int intval)
  201. {
  202. mttype_=mt_int;
  203. int_val_=intval;
  204. name_ =strdup(name);
  205. }
  206. MetaTagInfo(const char *name, double doubleval)
  207. {
  208. mttype_=mt_double;
  209. double_val_=doubleval;
  210. name_ =strdup(name);
  211. }
  212. ~MetaTagInfo()
  213. {
  214. release();
  215. }
  216. void release()
  217. {
  218. if (mttype_==mt_string && str_val_!=NULL)
  219. free(str_val_);
  220. if (name_)
  221. free(name_);
  222. mttype_=mt_none;
  223. }
  224. const char *getName()
  225. {
  226. return name_;
  227. }
  228. const char* getConstId()
  229. {
  230. if (mttype_==mt_const_id)
  231. return str_val_;
  232. return NULL;
  233. }
  234. void setName(const char *name)
  235. {
  236. if (name_)
  237. free(name_);
  238. name_ =strdup(name);
  239. }
  240. void setString(const char *val)
  241. {
  242. if (mttype_==mt_string && str_val_!=NULL)
  243. free(str_val_);
  244. str_val_=strdup(val);
  245. mttype_=mt_string;
  246. }
  247. const char *getString()
  248. {
  249. if (mttype_==mt_string)
  250. return str_val_;
  251. return NULL;
  252. }
  253. int getInt()
  254. {
  255. if (mttype_==mt_int)
  256. return int_val_;
  257. return -1;
  258. }
  259. double getDouble()
  260. {
  261. if (mttype_==mt_double)
  262. return double_val_;
  263. return -1;
  264. }
  265. void toStringXmlAttr(StringBuffer & out)
  266. {
  267. out.append(' ').append(getName()).append("='");
  268. switch (mttype_)
  269. {
  270. case mt_string:
  271. case mt_const_id:
  272. {
  273. if (str_val_)
  274. {
  275. const char *val = str_val_;
  276. int len=strlen(val);
  277. if (len>=2 && *val=='\"')
  278. {
  279. val++;
  280. len -= 2;
  281. }
  282. encodeXML(val, out, 0, len);
  283. }
  284. break;
  285. }
  286. case mt_double:
  287. out.append(double_val_);
  288. break;
  289. case mt_int:
  290. out.append(int_val_);
  291. break;
  292. case mt_none:
  293. default:
  294. break;
  295. }
  296. out.append('\'');
  297. }
  298. };
  299. inline MetaTagInfo* findMetaTag(MetaTagInfo *list, const char *name)
  300. {
  301. MetaTagInfo *mti;
  302. for (mti=list; mti; mti=mti->next)
  303. {
  304. if (stricmp(mti->getName(), name)==0)
  305. return mti;
  306. }
  307. return NULL;
  308. }
  309. inline const char *getMetaString(MetaTagInfo *list, const char *tag, const char *def_val)
  310. {
  311. MetaTagInfo *mti=findMetaTag(list, tag);
  312. return (mti!=NULL) ? mti->getString() : def_val;
  313. }
  314. inline bool getMetaStringValue(MetaTagInfo *list, StringBuffer &val, const char *tag)
  315. {
  316. MetaTagInfo *mti=findMetaTag(list, tag);
  317. if (!mti)
  318. return false;
  319. const char *mtval=mti->getString();
  320. if (!mtval || strlen(mtval)<2)
  321. return false;
  322. val.append(strlen(mtval)-2, mtval+1);
  323. return true;
  324. }
  325. inline int getMetaInt(MetaTagInfo *list, const char *tag, int def_val=0)
  326. {
  327. MetaTagInfo *mti=findMetaTag(list, tag);
  328. return (mti!=NULL) ? mti->getInt() : def_val;
  329. }
  330. inline double getMetaDouble(MetaTagInfo *list, const char *tag, double def_val=0)
  331. {
  332. MetaTagInfo *mti=findMetaTag(list, tag);
  333. return (mti!=NULL) ? mti->getDouble() : def_val;
  334. }
  335. inline const char* getMetaConstId(MetaTagInfo *list, const char *tag, const char* def_val=NULL)
  336. {
  337. MetaTagInfo *mti=findMetaTag(list, tag);
  338. return (mti!=NULL) ? mti->getConstId() : def_val;
  339. }
  340. // return: true if the ver tag is defined
  341. bool hasMetaVerInfo(MetaTagInfo *list, const char* tag);
  342. bool getMetaVerInfo(MetaTagInfo *list, const char* tag, StringBuffer& s);
  343. class ParamInfo
  344. {
  345. public:
  346. ParamInfo();
  347. ~ParamInfo();
  348. char *bytesize(int deref=0);
  349. bool simpleneedsswap();
  350. void cat_type(char *s,int deref=0,int var=0);
  351. clarion_special_type_enum clarion_special_type();
  352. void out_clarion_parameter();
  353. void out_clarion_type(bool ret);
  354. void out_parameter(const char *pfx,int forclarion=0);
  355. void out_type(int deref=0,int var=0);
  356. void typesizeacc(char *accstr,size_t &acc);
  357. size_t typesizealign(size_t &ofs);
  358. void write_body_struct_elem(int ref);
  359. void write_param_convert(int deref=0);
  360. bool isEspArrayOf(const char *elem_type=NULL, bool def=true)
  361. {
  362. if (flags & PF_TEMPLATE && (!strcmp(templ, "ESParray") || streq(templ, "ESPlist")))
  363. {
  364. if (!elem_type || !typname)
  365. return def;
  366. return (!strcmp(typname, elem_type));
  367. }
  368. return false;
  369. }
  370. bool isEspStringArray()
  371. {
  372. if (flags & PF_TEMPLATE && (!strcmp(templ, "ESParray") || streq(templ, "ESPlist")))
  373. return (!typname||!strcmp(typname, "string")||!strcmp(typname, "EspTextFile"));
  374. return false;
  375. }
  376. bool isPrimitiveArray()
  377. {
  378. if (flags & PF_TEMPLATE && (!strcmp(templ, "ESParray") || streq(templ, "ESPlist")))
  379. return (kind != TK_STRUCT && kind != TK_null && kind != TK_ESPENUM && kind != TK_ESPSTRUCT) || !typname;
  380. return false;
  381. }
  382. type_kind getArrayItemType()
  383. {
  384. assert(isPrimitiveArray());
  385. return kind;
  386. }
  387. const char* getArrayItemXsdType();
  388. const char* getArrayImplType();
  389. bool hasNameTag(){return (typname && !stricmp(typname, "EspTextFile"));}
  390. void write_clarion_attr_method(bool isSet);
  391. bool hasMapInfo();
  392. bool write_mapinfo_check(int indents, const char* ctxvar);
  393. bool hasMetaTag(const char* tag)
  394. {
  395. return findMetaTag(tags,tag)!=NULL;
  396. }
  397. const char *getMetaString(const char *tag, const char *def_val)
  398. {
  399. return ::getMetaString(tags, tag, def_val);
  400. }
  401. bool getMetaStringValue(StringBuffer &val, const char *tag)
  402. {
  403. return ::getMetaStringValue(tags, val, tag);
  404. }
  405. int getMetaInt(const char *tag, int def_val=0)
  406. {
  407. return ::getMetaInt(tags, tag, def_val);
  408. }
  409. double getMetaDouble(const char *tag, double def_val=0)
  410. {
  411. return ::getMetaDouble(tags, tag, def_val);
  412. }
  413. bool hasMetaVerInfo(const char* tag)
  414. {
  415. return ::hasMetaVerInfo(tags,tag);
  416. }
  417. bool getMetaVerInfo(const char* tag, StringBuffer& s)
  418. {
  419. return ::getMetaVerInfo(tags,tag,s);
  420. }
  421. void setXsdType(const char *value);
  422. const char *getXsdType();
  423. const char *getMetaXsdType() { const char* xsd = getMetaString("xsd_type",NULL); return xsd ? xsd : getMetaString("format_as",NULL); }
  424. // should be call once at a time. Better: use CStringBuffer
  425. const char* getXmlTag()
  426. {
  427. static char buffer[256];
  428. const char* xmlTag = getMetaString("xml_tag", NULL);
  429. if (xmlTag) {
  430. if (*xmlTag == '"' || *xmlTag == '\'')
  431. xmlTag++;
  432. int len = strlen(xmlTag);
  433. if (*(xmlTag+len-1)=='"' || *(xmlTag+len-1)=='\'')
  434. len--;
  435. strncpy(buffer, xmlTag, len);
  436. buffer[len] = 0;
  437. }
  438. else
  439. strcpy(buffer,name);
  440. return buffer;
  441. }
  442. void toStringXmlAttr(StringBuffer & out)
  443. {
  444. const char *xsd_type = getMetaString("xsd_type", NULL);
  445. if (xsd_type)
  446. {
  447. const char *attr = "complex_type";
  448. if (*xsd_type=='\"')
  449. xsd_type++;
  450. const char *finger = strchr(xsd_type, ':');
  451. if (finger)
  452. {
  453. xsd_type=finger+1;
  454. if (!strncmp("ArrayOf", xsd_type, 7))
  455. {
  456. attr = "type";
  457. xsd_type += 7;
  458. }
  459. }
  460. StringBuffer TypeName(xsd_type);
  461. TypeName.replace('\"', 0);
  462. out.appendf(" %s='%s'", attr, TypeName.str());
  463. }
  464. else
  465. {
  466. char typestr[256]={0};
  467. cat_type(typestr, 0, 0);
  468. out.appendf(" %s='%s'", (kind==TK_ESPSTRUCT) ? "complex_type" : "type", typestr);
  469. }
  470. }
  471. void toString(StringBuffer & out)
  472. {
  473. const char *xsd_type = getMetaString("xsd_type", NULL);
  474. if (xsd_type && *xsd_type=='\"')
  475. xsd_type++;
  476. unsigned pcl = strlen("tns:ArrayOf");
  477. //purely for compatability with scapps ESDL processing... ESDL should never have relied on interpreting the xsd_type which is for external use
  478. if (xsd_type && !strncmp("tns:ArrayOf", xsd_type, pcl))
  479. {
  480. out.appendf("\t\t<EsdlArray name='%s' ", name);
  481. toStringXmlAttr(out);
  482. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  483. {
  484. mtag->toStringXmlAttr(out);
  485. }
  486. }
  487. else if (flags & PF_TEMPLATE && !strcmp(templ, "ESParray"))
  488. {
  489. out.appendf("\t\t<EsdlArray name='%s' ", name);
  490. toStringXmlAttr(out);
  491. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  492. {
  493. mtag->toStringXmlAttr(out);
  494. }
  495. }
  496. else if (flags & PF_TEMPLATE && !strcmp(templ, "ESPlist"))
  497. {
  498. out.appendf("\t\t<EsdlList name='%s' ", name);
  499. toStringXmlAttr(out);
  500. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  501. {
  502. mtag->toStringXmlAttr(out);
  503. }
  504. }
  505. else if (kind==TK_ENUM)
  506. {
  507. out.appendf("\t\t<EsdlEnumItem name='%s'", name);
  508. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  509. {
  510. mtag->toStringXmlAttr(out);
  511. }
  512. }
  513. else if (kind==TK_ESPENUM)
  514. {
  515. out.appendf("\t\t<EsdlEnum name='%s' enum_type='%s'", name, typname);
  516. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  517. {
  518. mtag->toStringXmlAttr(out);
  519. }
  520. }
  521. else
  522. {
  523. out.appendf("\t\t<EsdlElement name='%s'", name);
  524. toStringXmlAttr(out);
  525. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  526. {
  527. mtag->toStringXmlAttr(out);
  528. }
  529. }
  530. out.append("/>\n");
  531. };
  532. bool checkDup(StringArray& ErrMsgs, ParamInfo* attrlist)
  533. {
  534. bool hasDup = false;
  535. ParamInfo* attr = attrlist;
  536. while(attr)
  537. {
  538. if(strcmp(name, attr->name) == 0)
  539. {
  540. VStringBuffer msg("\"%s\" conflicts with \"%s\"", name, attr->name);
  541. ErrMsgs.append(msg.str());
  542. hasDup = true;
  543. }
  544. attr = attr->next;
  545. }
  546. return hasDup;
  547. }
  548. type_kind kind;
  549. char *name;
  550. char *templ;
  551. char *typname;
  552. char *size;
  553. char *sizebytes;
  554. unsigned flags;
  555. LayoutInfo *layouts;
  556. ParamInfo *next;
  557. MetaTagInfo *tags;
  558. private:
  559. char *xsdtype;
  560. StringBuffer *m_arrayImplType;
  561. };
  562. class ProcInfo
  563. {
  564. public:
  565. ProcInfo();
  566. ~ProcInfo();
  567. char * name;
  568. ParamInfo * rettype;
  569. ParamInfo * params;
  570. ProcInfo * next;
  571. char * conntimeout;
  572. char * calltimeout;
  573. int async;
  574. int callback;
  575. ParamInfo * firstin;
  576. ParamInfo * lastin;
  577. int virt;
  578. int constfunc;
  579. };
  580. class ModuleInfo
  581. {
  582. public:
  583. ModuleInfo(const char *n);
  584. ~ModuleInfo();
  585. char *name;
  586. char *base;
  587. int version;
  588. ProcInfo *procs;
  589. ModuleInfo *next;
  590. bool isSCMinterface;
  591. };
  592. class ExportDefInfo
  593. {
  594. public:
  595. ExportDefInfo(const char *name)
  596. {
  597. name_=strdup(name);
  598. next=NULL;
  599. }
  600. ~ExportDefInfo()
  601. {
  602. if (name_)
  603. free(name_);
  604. }
  605. char *name_;
  606. ExportDefInfo *next;
  607. };
  608. class ApiInfo
  609. {
  610. public:
  611. ApiInfo(const char *grp="");
  612. ~ApiInfo();
  613. void write_header_method();
  614. void write_clarion_include_method();
  615. char *group;
  616. char *name;
  617. ProcInfo *proc;
  618. ApiInfo *next;
  619. };
  620. class IncludeInfo
  621. {
  622. public:
  623. IncludeInfo(const char *path_) : pathstr(path_), next(NULL)
  624. {
  625. };
  626. ~IncludeInfo(){}
  627. void toString(StringBuffer & out)
  628. {
  629. out.appendf("\t<EsdlInclude file='%s'/>\n", pathstr.str());
  630. }
  631. StringBuffer pathstr;
  632. IncludeInfo *next;
  633. };
  634. class VersionInfo
  635. {
  636. public:
  637. VersionInfo(const char *version_name_, double version_value_)
  638. {
  639. version_name.append(version_name_);
  640. version_value = version_value_;
  641. next=NULL;
  642. };
  643. ~VersionInfo(){}
  644. void toString(StringBuffer & out)
  645. {
  646. out.appendf("\t<EsdlVersion name='%s' version='%f' />\n", version_name.str(), version_value);
  647. }
  648. StringBuffer version_name;
  649. double version_value;
  650. VersionInfo *next;
  651. };
  652. class EnumValInfo
  653. {
  654. public:
  655. EnumValInfo(const char *_name,int _val)
  656. {
  657. name = strdup(_name);
  658. val = _val;
  659. next = NULL;
  660. }
  661. ~EnumValInfo()
  662. {
  663. free(name);
  664. }
  665. char *name;
  666. int val;
  667. EnumValInfo *next;
  668. };
  669. class EnumInfo
  670. {
  671. public:
  672. EnumInfo(const char *_name)
  673. {
  674. name = strdup(_name);
  675. vals = NULL;
  676. next = NULL;
  677. }
  678. ~EnumInfo()
  679. {
  680. free(name);
  681. while (vals)
  682. {
  683. EnumValInfo *va=vals;
  684. vals = va->next;
  685. delete va;
  686. }
  687. }
  688. char *name;
  689. EnumValInfo *vals;
  690. EnumInfo *next;
  691. };
  692. class EspMessageInfo
  693. {
  694. public:
  695. enum espm_type {espm_none, espm_struct, espm_enum, espm_request, espm_response};
  696. enum espaxm_type {espaxm_getters, espaxm_setters, espaxm_both};
  697. EspMessageInfo(const char *name, enum espm_type type=espm_none)
  698. {
  699. espm_type_=type;
  700. name_ =strdup(name);
  701. base_=NULL;
  702. attrs_=NULL;
  703. tags=NULL;
  704. next=NULL;
  705. parent=NULL;
  706. xsdgrouptype=NULL;
  707. }
  708. EspMessageInfo(enum espm_type type, ProcInfo *procInfo)
  709. {
  710. espm_type_=type;
  711. name_ =strdup(procInfo->name);
  712. if (espm_type_==espm_struct)
  713. {
  714. name_ =(char *)malloc(strlen(procInfo->name)+6);
  715. strcpy(name_, procInfo->name);
  716. strcat(name_, "Struct");
  717. attrs_ = procInfo->params;
  718. procInfo->params=NULL;
  719. }
  720. else if (espm_type_==espm_request)
  721. {
  722. name_ =(char *)malloc(strlen(procInfo->name)+8);
  723. strcpy(name_, procInfo->name);
  724. strcat(name_, "Request");
  725. attrs_ = procInfo->params;
  726. procInfo->params=NULL;
  727. }
  728. else
  729. {
  730. name_ =(char *)malloc(strlen(procInfo->name)+9);
  731. strcpy(name_, procInfo->name);
  732. strcat(name_, "Response");
  733. setParams(procInfo->rettype);
  734. procInfo->rettype=NULL;
  735. }
  736. tags=NULL;
  737. next=NULL;
  738. parent=NULL;
  739. xsdgrouptype=NULL;
  740. }
  741. void setType(espm_type type){espm_type_=type;}
  742. espm_type getType(){return espm_type_;}
  743. const char *getName(){return name_;}
  744. void setName(const char *name)
  745. {
  746. if (name_)
  747. free(name_);
  748. name_=strdup(name);
  749. }
  750. const char *getBase(){return base_;}
  751. void setBase(const char *base)
  752. {
  753. if (base_)
  754. free(base_);
  755. base_=strdup(base);
  756. }
  757. const char *getParentName()
  758. {
  759. if (parent)
  760. return parent;
  761. if (!getMetaString("extends", NULL))
  762. return NULL;
  763. parent=((char *)strdup(getMetaString("extends", NULL))+1);
  764. char *finger=strchr(parent, '\"');
  765. if (finger)
  766. *finger=0;
  767. return parent;
  768. }
  769. void setParentName(const char* name)
  770. {
  771. parent = strdup(name);
  772. }
  773. const char *getXsdGroupType()
  774. {
  775. if (!xsdgrouptype)
  776. {
  777. const char* s = getMetaString("xsd_group_type", "\"all\"");
  778. if (*s == '\"')
  779. {
  780. xsdgrouptype = strdup(s+1);
  781. char *finger = strchr(xsdgrouptype, '\"');
  782. if (finger)
  783. *finger=0;
  784. }
  785. else
  786. xsdgrouptype = strdup(s);
  787. }
  788. return xsdgrouptype;
  789. }
  790. const char *getMetaString(const char *tag, const char *def_val)
  791. {
  792. return ::getMetaString(tags, tag, def_val);
  793. }
  794. bool getMetaStringValue(StringBuffer &val, const char *tag)
  795. {
  796. return ::getMetaStringValue(tags, val, tag);
  797. }
  798. int getMetaInt(const char *tag, int def_val=0)
  799. {
  800. return ::getMetaInt(tags, tag, def_val);
  801. }
  802. bool hasMapInfo();
  803. void setParams(ParamInfo *param)
  804. {
  805. attrs_=param;
  806. }
  807. ParamInfo *getParams(){return attrs_;}
  808. const char * query_esxdl_type()
  809. {
  810. switch (espm_type_)
  811. {
  812. case espm_struct:
  813. return "EsdlStruct";
  814. case espm_enum:
  815. return "EsdlEnumType";
  816. case espm_request:
  817. return "EsdlRequest";
  818. case espm_response:
  819. return "EsdlResponse";
  820. case espm_none:
  821. default:
  822. break;
  823. }
  824. return NULL;
  825. }
  826. EspMessageInfo *find_parent();
  827. void toStringEsxdlChildren(StringBuffer & out)
  828. {
  829. EspMessageInfo *parmsg = find_parent();
  830. if (parmsg)
  831. parmsg->toStringEsxdlChildren(out);
  832. for (ParamInfo *param=attrs_; param; param=param->next)
  833. param->toString(out);
  834. }
  835. void toString(StringBuffer & out)
  836. {
  837. const char *esdltype = query_esxdl_type();
  838. if (esdltype)
  839. {
  840. out.appendf("\t<%s name='%s'", esdltype, name_);
  841. if (base_ && *base_)
  842. {
  843. out.appendf(" base='%s'", base_);
  844. }
  845. if (parent)
  846. {
  847. out.appendf(" base_type='%s'", parent);
  848. }
  849. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  850. {
  851. mtag->toStringXmlAttr(out);
  852. }
  853. out.append(">\n");
  854. for (ParamInfo *param=attrs_; param; param=param->next)
  855. {
  856. param->toString(out);
  857. }
  858. out.appendf("\t</%s>\n", esdltype);
  859. }
  860. }
  861. MetaTagInfo *tags;
  862. EspMessageInfo *next;
  863. ~EspMessageInfo()
  864. {
  865. while (attrs_)
  866. {
  867. ParamInfo *attr=attrs_;
  868. attrs_ = attr->next;
  869. delete attr;
  870. }
  871. while (tags)
  872. {
  873. MetaTagInfo *attr=tags;
  874. tags = attr->next;
  875. delete attr;
  876. }
  877. delete tags;
  878. free (name_);
  879. free (base_);
  880. free (parent);
  881. free (xsdgrouptype);
  882. }
  883. private:
  884. ParamInfo *attrs_;
  885. espm_type espm_type_;
  886. char *name_;
  887. char *base_;
  888. char *parent;
  889. char *xsdgrouptype;
  890. };
  891. class EspMethodInfo
  892. {
  893. private:
  894. char *name_;
  895. char *request_;
  896. char *response_;
  897. ProcInfo *proc_;
  898. public:
  899. EspMethodInfo(const char *name, const char *req, const char *resp)
  900. {
  901. name_ =strdup(name);
  902. request_ =strdup(req);
  903. response_ =strdup(resp);
  904. proc_=NULL;
  905. tags=NULL;
  906. next=NULL;
  907. }
  908. EspMethodInfo(ProcInfo *procInfo)
  909. {
  910. proc_=procInfo;
  911. name_ =strdup(procInfo->name);
  912. request_ =(char *)malloc(strlen(name_)+8);
  913. strcpy(request_, name_);
  914. strcat(request_, "Request");
  915. response_ =(char *)malloc(strlen(name_)+9);
  916. strcpy(response_, name_);
  917. strcat(response_, "Response");
  918. tags=NULL;
  919. next=NULL;
  920. }
  921. ~EspMethodInfo()
  922. {
  923. fprintf(stderr, "~EspMethodInfo(%s)\n", name_);
  924. while (tags)
  925. {
  926. MetaTagInfo *p=tags;
  927. tags = p->next;
  928. delete p;
  929. }
  930. if (name_)
  931. free(name_);
  932. if (request_)
  933. free(request_);
  934. if (response_)
  935. free(response_);
  936. }
  937. const char *getName(){return name_;}
  938. void setName(const char *name)
  939. {
  940. if (name_)
  941. free(name_);
  942. name_ =strdup(name);
  943. }
  944. const char *getReq(){return request_;}
  945. void setReq(const char *name)
  946. {
  947. if (request_)
  948. free(request_);
  949. request_ =strdup(name);
  950. }
  951. const char *getResp(){return response_;}
  952. void setResp(const char *name)
  953. {
  954. if (response_)
  955. free(response_);
  956. response_ =strdup(name);
  957. }
  958. const char *getMetaString(const char *tag, const char *def_val)
  959. {
  960. return ::getMetaString(tags, tag, def_val);
  961. }
  962. bool getMetaStringValue(StringBuffer &val, const char *tag)
  963. {
  964. return ::getMetaStringValue(tags, val, tag);
  965. }
  966. int getMetaInt(const char *tag, int def_val=0)
  967. {
  968. return ::getMetaInt(tags, tag, def_val);
  969. }
  970. bool getMetaVerInfo(const char* tag, StringBuffer& s)
  971. {
  972. return ::getMetaVerInfo(tags,tag,s);
  973. }
  974. EspMessageInfo *getRequestInfo();
  975. void toString(StringBuffer & out)
  976. {
  977. out.appendf("\t<EsdlMethod name='%s' request_type='%s' response_type='%s' ", name_, request_, response_);
  978. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  979. {
  980. mtag->toStringXmlAttr(out);
  981. }
  982. out.append("/>\n");
  983. }
  984. MetaTagInfo *tags;
  985. EspMethodInfo *next;
  986. };
  987. class EspMountInfo
  988. {
  989. private:
  990. char *name_;
  991. char *localPath_;
  992. public:
  993. EspMountInfo(const char *name, const char *localPath)
  994. {
  995. name_ =strdup(name);
  996. localPath_ =strdup(localPath);
  997. tags=NULL;
  998. next=NULL;
  999. }
  1000. ~EspMountInfo()
  1001. {
  1002. if (name_)
  1003. free(name_);
  1004. if (localPath_)
  1005. free(localPath_);
  1006. }
  1007. const char *getName(){return name_;}
  1008. void setName(const char *name)
  1009. {
  1010. if (name_)
  1011. free(name_);
  1012. name_ =strdup(name);
  1013. }
  1014. const char *getLocalPath(){return localPath_;}
  1015. void setLocalPath(const char *path)
  1016. {
  1017. if (localPath_)
  1018. free(localPath_);
  1019. localPath_ =strdup(path);
  1020. }
  1021. const char *getMetaString(const char *tag, const char *def_val)
  1022. {
  1023. return ::getMetaString(tags, tag, def_val);
  1024. }
  1025. bool getMetaStringValue(StringBuffer &val, const char *tag)
  1026. {
  1027. return ::getMetaStringValue(tags, val, tag);
  1028. }
  1029. int getMetaInt(const char *tag, int def_val=0)
  1030. {
  1031. return ::getMetaInt(tags, tag, def_val);
  1032. }
  1033. double getMetaDouble(const char* tag, double def_val=0)
  1034. {
  1035. return ::getMetaDouble(tags,tag,def_val);
  1036. }
  1037. MetaTagInfo *tags;
  1038. EspMountInfo *next;
  1039. };
  1040. class EspStructInfo
  1041. {
  1042. private:
  1043. char *name_;
  1044. public:
  1045. EspStructInfo(const char *name)
  1046. {
  1047. name_ =strdup(name);
  1048. tags=NULL;
  1049. next=NULL;
  1050. }
  1051. ~EspStructInfo()
  1052. {
  1053. if (name_)
  1054. free(name_);
  1055. }
  1056. const char *getName(){return name_;}
  1057. void setName(const char *name)
  1058. {
  1059. if (name_)
  1060. free(name_);
  1061. name_ =strdup(name);
  1062. }
  1063. const char *getMetaString(const char *tag, const char *def_val)
  1064. {
  1065. return ::getMetaString(tags, tag, def_val);
  1066. }
  1067. bool getMetaStringValue(StringBuffer &val, const char *tag)
  1068. {
  1069. return ::getMetaStringValue(tags, val, tag);
  1070. }
  1071. int getMetaInt(const char *tag, int def_val=0)
  1072. {
  1073. return ::getMetaInt(tags, tag, def_val);
  1074. }
  1075. MetaTagInfo *tags;
  1076. EspStructInfo *next;
  1077. };
  1078. typedef enum _catch_type
  1079. {
  1080. ct_httpresp,
  1081. ct_soapresp,
  1082. } catch_type;
  1083. class EspServInfo
  1084. {
  1085. private:
  1086. char *name_;
  1087. char *base_;
  1088. bool needsXslt;
  1089. public:
  1090. EspServInfo(const char *name)
  1091. {
  1092. name_ =strdup(name);
  1093. base_=NULL;
  1094. methods=NULL;
  1095. mounts=NULL;
  1096. tags=NULL;
  1097. structs=NULL;
  1098. next=NULL;
  1099. needsXslt = false;
  1100. }
  1101. ~EspServInfo()
  1102. {
  1103. if (name_)
  1104. free(name_);
  1105. if (base_)
  1106. free(base_);
  1107. }
  1108. const char *getName(){return name_;}
  1109. void setName(const char *name)
  1110. {
  1111. if (name_)
  1112. free(name_);
  1113. name_ =strdup(name);
  1114. }
  1115. const char *getBase(){return base_;}
  1116. void setBase(const char *base)
  1117. {
  1118. if (base_)
  1119. free(base_);
  1120. base_ =strdup(base);
  1121. }
  1122. const char *getMetaString(const char *tag, const char *def_val)
  1123. {
  1124. return ::getMetaString(tags, tag, def_val);
  1125. }
  1126. bool getMetaStringValue(StringBuffer &val, const char *tag)
  1127. {
  1128. return ::getMetaStringValue(tags, val, tag);
  1129. }
  1130. int getMetaInt(const char *tag, int def_val=0)
  1131. {
  1132. return ::getMetaInt(tags, tag, def_val);
  1133. }
  1134. void toString(StringBuffer & out)
  1135. {
  1136. out.appendf("\t\t<EsdlService name='%s' ", name_);
  1137. for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
  1138. {
  1139. mtag->toStringXmlAttr(out);
  1140. }
  1141. out.append(">\n");
  1142. for (EspMethodInfo *mth=methods; mth; mth=mth->next)
  1143. {
  1144. mth->toString(out);
  1145. }
  1146. out.append("\t\t</EsdlService>");
  1147. }
  1148. EspStructInfo *structs;
  1149. EspMethodInfo *methods;
  1150. EspMountInfo *mounts;
  1151. MetaTagInfo *tags;
  1152. EspServInfo *next;
  1153. void sortMethods();
  1154. };
  1155. class esdlcomp_decl ESDLcompiler
  1156. {
  1157. public:
  1158. ESDLcompiler(const char * sourceFile, bool generatefile, const char * outDir, bool outputIncludes, bool includedEsdl, const char* includePath);
  1159. ~ESDLcompiler();
  1160. void Process();
  1161. void write_esxdl();
  1162. const char * getSrcDir() const
  1163. {
  1164. return srcDir.str();
  1165. }
  1166. const char * getEsxdlContent() const
  1167. {
  1168. return esxdlcontent.str();
  1169. }
  1170. const char* getPackageName()
  1171. {
  1172. return packagename;
  1173. }
  1174. char* filename;
  1175. StringBuffer name;
  1176. private:
  1177. bool outputIncludes;
  1178. int esxdlo;
  1179. char* packagename;
  1180. StringBuffer srcDir;
  1181. StringBuffer esxdlcontent;
  1182. StringArray includeDirs;
  1183. bool locateIncludedFile(StringBuffer& filepath, const char* prot, const char* srcDir, const char* fname, const char* ext);
  1184. public:
  1185. static CriticalSection m_critSect;
  1186. ModuleInfo* modules;
  1187. EnumInfo* enums;
  1188. ApiInfo* apis;
  1189. EspMessageInfo* msgs;
  1190. EspServInfo* servs;
  1191. EspMethodInfo* methods;
  1192. IncludeInfo* includes;
  1193. VersionInfo* versions;
  1194. };
  1195. extern int nCommentStartLine;
  1196. extern void yyerror(const char *s);
  1197. inline char upperchar(char val){return ((val<97 || val>122) ? val : (val-32));}
  1198. #endif