1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414 |
- /*##############################################################################
- 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.
- ############################################################################## */
- #ifndef __ESDLCOMP_H__
- #define __ESDLCOMP_H__
- #include <stdarg.h>
- #include <assert.h>
- #include "platform.h"
- #include "jmutex.hpp"
- #include "jstring.hpp"
- #include "jfile.hpp"
- #include "esdldecl.hpp"
- #undef YYSTYPE
- #define YYSTYPE attribute
- #define ESDLVER "1.2"
- #define MAX_IDENT 2048
- #define RETURNNAME "_return"
- #ifndef _WIN32
- #define stricmp strcasecmp
- #endif
- inline bool es_streq(const char* s, const char* t) { return strcmp(s,t)==0; }
- #define PF_IN 0x1
- #define PF_OUT 0x2
- #define PF_VARSIZE 0x4
- #define PF_PTR 0x8
- #define PF_REF 0x10
- #define PF_CONST 0x40
- #define PF_SIMPLE 0x80
- #define PF_RETURN 0x100
- #define PF_STRING 0x200
- #define PF_TEMPLATE 0x400
- #define PF_ESPSTRUCT 0x800
- #define PF_MASK 0x7fff
- #define LEGACY_FILE_EXTENSION ".ecm"
- #define ESDL_FILE_EXTENSION ".esdl"
- #define XML_FILE_EXTENSION ".xml"
- enum type_kind
- {
- TK_null,
- TK_CHAR,
- TK_UNSIGNEDCHAR,
- TK_BYTE,
- TK_BOOL,
- TK_SHORT,
- TK_UNSIGNEDSHORT,
- TK_INT,
- TK_UNSIGNED,
- TK_LONG,
- TK_UNSIGNEDLONG,
- TK_LONGLONG,
- TK_UNSIGNEDLONGLONG,
- TK_DOUBLE,
- TK_FLOAT,
- TK_STRUCT,
- TK_ENUM,
- TK_VOID,
- TK_ESPSTRUCT,
- TK_ESPENUM
- };
- enum EAMType
- {
- EAM_basic,
- EAM_jsbuf,
- EAM_jmbuf,
- EAM_jmbin
- };
- typedef struct esp_xlate_info_
- {
- const char *meta_type;
- const char *xsd_type;
- const char *store_type;
- const char *array_type;
- const char *access_type;
- enum type_kind access_kind;
- unsigned access_flags;
- enum EAMType eam_type;
- } esp_xlate_info;
- esp_xlate_info *esp_xlat(const char *from, bool defaultToString=true);
- enum clarion_special_type_enum { cte_normal,cte_longref,cte_constcstr,cte_cstr };
- void out(const char*, size_t);
- void outs(const char*);
- void outf(const char*,...) __attribute__((format(printf, 1, 2)));
- void outs(int indent, const char*);
- void outf(int indent, const char*,...) __attribute__((format(printf, 2, 3)));
- char *appendstr(char *text,const char *str);
- struct attribute
- {
- private:
- union
- {
- char *str_val;
- int int_val;
- double double_val;
- };
- enum { t_none, t_string, t_int, t_double } atr_type;
- char name_[MAX_IDENT];
- public:
- attribute()
- {
- atr_type=t_none;
- str_val=NULL;
- }
- ~attribute()
- {
- release();
- }
- void release()
- {
- if (atr_type==t_string)
- free(str_val);
- atr_type=t_none;
- }
- void setVal(int val)
- {
- release();
- int_val=val;
- atr_type = t_int;
- }
- void setVal(double val)
- {
- release();
- double_val=val;
- atr_type = t_double;
- }
- void setVal(char *val)
- {
- release();
- str_val=val;
- atr_type = t_int;
- }
- const char *getString()
- {
- return str_val;
- }
- int getInt()
- {
- return int_val;
- }
- double getDouble()
- {
- return double_val;
- }
- const char *getName(){return name_;}
- void setName(const char *value)
- {
- strcpy(name_,(value)? value : (char *)"");
- }
- void setNameF(const char *format, ...) __attribute__((format(printf, 2, 3)))
- {
- va_list args;
- va_start(args, format);
- _vsnprintf(name_, MAX_IDENT,format, args);
- va_end(args);
- }
- };
- class LayoutInfo
- {
- public:
- LayoutInfo();
- ~LayoutInfo();
- char * size;
- char * count;
- LayoutInfo * next;
- };
- class MetaTagInfo
- {
- private:
- char *name_;
- union
- {
- char *str_val_;
- int int_val_;
- double double_val_;
- };
- public:
- enum {mt_none, mt_int, mt_string, mt_double, mt_const_id} mttype_;
- MetaTagInfo *next;
- public:
- MetaTagInfo(const char *name, const char *strval)
- {
- mttype_=mt_string;
- str_val_=strdup(strval);
- name_ = strdup(name);
- }
- MetaTagInfo(const char *name, const char *strval,bool)
- {
- mttype_=mt_const_id;
- str_val_=strdup(strval);
- name_ = strdup(name);
- }
- MetaTagInfo(const char *name, int intval)
- {
- mttype_=mt_int;
- int_val_=intval;
- name_ =strdup(name);
- }
- MetaTagInfo(const char *name, double doubleval)
- {
- mttype_=mt_double;
- double_val_=doubleval;
- name_ =strdup(name);
- }
- ~MetaTagInfo()
- {
- release();
- }
- void release()
- {
- if (mttype_==mt_string && str_val_!=NULL)
- free(str_val_);
- if (name_)
- free(name_);
- mttype_=mt_none;
- }
- const char *getName()
- {
- return name_;
- }
- const char* getConstId()
- {
- if (mttype_==mt_const_id)
- return str_val_;
- return NULL;
- }
- void setName(const char *name)
- {
- if (name_)
- free(name_);
- name_ =strdup(name);
- }
- void setString(const char *val)
- {
- if (mttype_==mt_string && str_val_!=NULL)
- free(str_val_);
- str_val_=strdup(val);
- mttype_=mt_string;
- }
- const char *getString()
- {
- if (mttype_==mt_string)
- return str_val_;
- return NULL;
- }
- int getInt()
- {
- if (mttype_==mt_int)
- return int_val_;
- return -1;
- }
- double getDouble()
- {
- if (mttype_==mt_double)
- return double_val_;
- return -1;
- }
- void toStringXmlAttr(StringBuffer & out)
- {
- out.append(' ').append(getName()).append("='");
- switch (mttype_)
- {
- case mt_string:
- case mt_const_id:
- {
- if (str_val_)
- {
- const char *val = str_val_;
- int len=strlen(val);
- if (len>=2 && *val=='\"')
- {
- val++;
- len -= 2;
- }
- encodeXML(val, out, 0, len);
- }
- break;
- }
- case mt_double:
- out.append(double_val_);
- break;
- case mt_int:
- out.append(int_val_);
- break;
- case mt_none:
- default:
- break;
- }
- out.append('\'');
- }
- };
- inline MetaTagInfo* findMetaTag(MetaTagInfo *list, const char *name)
- {
- MetaTagInfo *mti;
- for (mti=list; mti; mti=mti->next)
- {
- if (stricmp(mti->getName(), name)==0)
- return mti;
- }
- return NULL;
- }
- inline const char *getMetaString(MetaTagInfo *list, const char *tag, const char *def_val)
- {
- MetaTagInfo *mti=findMetaTag(list, tag);
- return (mti!=NULL) ? mti->getString() : def_val;
- }
- inline bool getMetaStringValue(MetaTagInfo *list, StringBuffer &val, const char *tag)
- {
- MetaTagInfo *mti=findMetaTag(list, tag);
- if (!mti)
- return false;
- const char *mtval=mti->getString();
- if (!mtval || strlen(mtval)<2)
- return false;
- val.append(strlen(mtval)-2, mtval+1);
- return true;
- }
- inline int getMetaInt(MetaTagInfo *list, const char *tag, int def_val=0)
- {
- MetaTagInfo *mti=findMetaTag(list, tag);
- return (mti!=NULL) ? mti->getInt() : def_val;
- }
- inline double getMetaDouble(MetaTagInfo *list, const char *tag, double def_val=0)
- {
- MetaTagInfo *mti=findMetaTag(list, tag);
- return (mti!=NULL) ? mti->getDouble() : def_val;
- }
- inline const char* getMetaConstId(MetaTagInfo *list, const char *tag, const char* def_val=NULL)
- {
- MetaTagInfo *mti=findMetaTag(list, tag);
- return (mti!=NULL) ? mti->getConstId() : def_val;
- }
- // return: true if the ver tag is defined
- bool hasMetaVerInfo(MetaTagInfo *list, const char* tag);
- bool getMetaVerInfo(MetaTagInfo *list, const char* tag, StringBuffer& s);
- class ParamInfo
- {
- public:
- ParamInfo();
- ~ParamInfo();
- char *bytesize(int deref=0);
- bool simpleneedsswap();
- void cat_type(char *s,int deref=0,int var=0);
- clarion_special_type_enum clarion_special_type();
- void out_clarion_parameter();
- void out_clarion_type(bool ret);
- void out_parameter(const char *pfx,int forclarion=0);
- void out_type(int deref=0,int var=0);
- void typesizeacc(char *accstr,size_t &acc);
- size_t typesizealign(size_t &ofs);
- void write_body_struct_elem(int ref);
- void write_param_convert(int deref=0);
- bool isEspArrayOf(const char *elem_type=NULL, bool def=true)
- {
- if (flags & PF_TEMPLATE && (!strcmp(templ, "ESParray") || streq(templ, "ESPlist")))
- {
- if (!elem_type || !typname)
- return def;
- return (!strcmp(typname, elem_type));
- }
- return false;
- }
- bool isEspStringArray()
- {
- if (flags & PF_TEMPLATE && (!strcmp(templ, "ESParray") || streq(templ, "ESPlist")))
- return (!typname||!strcmp(typname, "string")||!strcmp(typname, "EspTextFile"));
- return false;
- }
- bool isPrimitiveArray()
- {
- if (flags & PF_TEMPLATE && (!strcmp(templ, "ESParray") || streq(templ, "ESPlist")))
- return (kind != TK_STRUCT && kind != TK_null && kind != TK_ESPENUM && kind != TK_ESPSTRUCT) || !typname;
- return false;
- }
- type_kind getArrayItemType()
- {
- assert(isPrimitiveArray());
- return kind;
- }
- const char* getArrayItemXsdType();
- const char* getArrayImplType();
- bool hasNameTag(){return (typname && !stricmp(typname, "EspTextFile"));}
- void write_clarion_attr_method(bool isSet);
- bool hasMapInfo();
- bool write_mapinfo_check(int indents, const char* ctxvar);
- bool hasMetaTag(const char* tag)
- {
- return findMetaTag(tags,tag)!=NULL;
- }
- const char *getMetaString(const char *tag, const char *def_val)
- {
- return ::getMetaString(tags, tag, def_val);
- }
- bool getMetaStringValue(StringBuffer &val, const char *tag)
- {
- return ::getMetaStringValue(tags, val, tag);
- }
- int getMetaInt(const char *tag, int def_val=0)
- {
- return ::getMetaInt(tags, tag, def_val);
- }
- double getMetaDouble(const char *tag, double def_val=0)
- {
- return ::getMetaDouble(tags, tag, def_val);
- }
- bool hasMetaVerInfo(const char* tag)
- {
- return ::hasMetaVerInfo(tags,tag);
- }
- bool getMetaVerInfo(const char* tag, StringBuffer& s)
- {
- return ::getMetaVerInfo(tags,tag,s);
- }
- void setXsdType(const char *value);
- const char *getXsdType();
- const char *getMetaXsdType() { const char* xsd = getMetaString("xsd_type",NULL); return xsd ? xsd : getMetaString("format_as",NULL); }
- // should be call once at a time. Better: use CStringBuffer
- const char* getXmlTag()
- {
- static char buffer[256];
- const char* xmlTag = getMetaString("xml_tag", NULL);
- if (xmlTag) {
- if (*xmlTag == '"' || *xmlTag == '\'')
- xmlTag++;
- int len = strlen(xmlTag);
- if (*(xmlTag+len-1)=='"' || *(xmlTag+len-1)=='\'')
- len--;
- strncpy(buffer, xmlTag, len);
- buffer[len] = 0;
- }
- else
- strcpy(buffer,name);
- return buffer;
- }
- void toStringXmlAttr(StringBuffer & out)
- {
- const char *xsd_type = getMetaString("xsd_type", NULL);
- if (xsd_type)
- {
- const char *attr = "complex_type";
- if (*xsd_type=='\"')
- xsd_type++;
- const char *finger = strchr(xsd_type, ':');
- if (finger)
- {
- xsd_type=finger+1;
- if (!strncmp("ArrayOf", xsd_type, 7))
- {
- attr = "type";
- xsd_type += 7;
- }
- }
- StringBuffer TypeName(xsd_type);
- TypeName.replace('\"', 0);
- out.appendf(" %s='%s'", attr, TypeName.str());
- }
- else
- {
- char typestr[256]={0};
- cat_type(typestr, 0, 0);
- out.appendf(" %s='%s'", (kind==TK_ESPSTRUCT) ? "complex_type" : "type", typestr);
- }
- }
- void toString(StringBuffer & out)
- {
- const char *xsd_type = getMetaString("xsd_type", NULL);
- if (xsd_type && *xsd_type=='\"')
- xsd_type++;
- unsigned pcl = strlen("tns:ArrayOf");
- //purely for compatability with scapps ESDL processing... ESDL should never have relied on interpreting the xsd_type which is for external use
- if (xsd_type && !strncmp("tns:ArrayOf", xsd_type, pcl))
- {
- out.appendf("\t\t<EsdlArray name='%s' ", name);
- toStringXmlAttr(out);
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- }
- else if (flags & PF_TEMPLATE && !strcmp(templ, "ESParray"))
- {
- out.appendf("\t\t<EsdlArray name='%s' ", name);
- toStringXmlAttr(out);
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- }
- else if (flags & PF_TEMPLATE && !strcmp(templ, "ESPlist"))
- {
- out.appendf("\t\t<EsdlList name='%s' ", name);
- toStringXmlAttr(out);
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- }
- else if (kind==TK_ENUM)
- {
- out.appendf("\t\t<EsdlEnumItem name='%s'", name);
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- }
- else if (kind==TK_ESPENUM)
- {
- out.appendf("\t\t<EsdlEnum name='%s' enum_type='%s'", name, typname);
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- }
- else
- {
- out.appendf("\t\t<EsdlElement name='%s'", name);
- toStringXmlAttr(out);
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- }
- out.append("/>\n");
- };
- bool checkDup(StringArray& ErrMsgs, ParamInfo* attrlist)
- {
- bool hasDup = false;
- ParamInfo* attr = attrlist;
- while(attr)
- {
- if(strcmp(name, attr->name) == 0)
- {
- VStringBuffer msg("\"%s\" conflicts with \"%s\"", name, attr->name);
- ErrMsgs.append(msg.str());
- hasDup = true;
- }
- attr = attr->next;
- }
- return hasDup;
- }
- type_kind kind;
- char *name;
- char *templ;
- char *typname;
- char *size;
- char *sizebytes;
- unsigned flags;
- LayoutInfo *layouts;
- ParamInfo *next;
- MetaTagInfo *tags;
- private:
- char *xsdtype;
- StringBuffer *m_arrayImplType;
- };
- class ProcInfo
- {
- public:
- ProcInfo();
- ~ProcInfo();
- char * name;
- ParamInfo * rettype;
- ParamInfo * params;
- ProcInfo * next;
- char * conntimeout;
- char * calltimeout;
- int async;
- int callback;
- ParamInfo * firstin;
- ParamInfo * lastin;
- int virt;
- int constfunc;
- };
- class ModuleInfo
- {
- public:
- ModuleInfo(const char *n);
- ~ModuleInfo();
- char *name;
- char *base;
- int version;
- ProcInfo *procs;
- ModuleInfo *next;
- bool isSCMinterface;
- };
- class ExportDefInfo
- {
- public:
- ExportDefInfo(const char *name)
- {
- name_=strdup(name);
- next=NULL;
- }
- ~ExportDefInfo()
- {
- if (name_)
- free(name_);
- }
- char *name_;
- ExportDefInfo *next;
- };
- class ApiInfo
- {
- public:
- ApiInfo(const char *grp="");
- ~ApiInfo();
- void write_header_method();
- void write_clarion_include_method();
- char *group;
- char *name;
- ProcInfo *proc;
- ApiInfo *next;
- };
- class IncludeInfo
- {
- public:
- IncludeInfo(const char *path_) : pathstr(path_), next(NULL)
- {
- };
- ~IncludeInfo(){}
- void toString(StringBuffer & out)
- {
- out.appendf("\t<EsdlInclude file='%s'/>\n", pathstr.str());
- }
- StringBuffer pathstr;
- IncludeInfo *next;
- };
- class VersionInfo
- {
- public:
- VersionInfo(const char *version_name_, double version_value_)
- {
- version_name.append(version_name_);
- version_value = version_value_;
- next=NULL;
- };
- ~VersionInfo(){}
- void toString(StringBuffer & out)
- {
- out.appendf("\t<EsdlVersion name='%s' version='%f' />\n", version_name.str(), version_value);
- }
- StringBuffer version_name;
- double version_value;
- VersionInfo *next;
- };
- class EnumValInfo
- {
- public:
- EnumValInfo(const char *_name,int _val)
- {
- name = strdup(_name);
- val = _val;
- next = NULL;
- }
- ~EnumValInfo()
- {
- free(name);
- }
- char *name;
- int val;
- EnumValInfo *next;
- };
- class EnumInfo
- {
- public:
- EnumInfo(const char *_name)
- {
- name = strdup(_name);
- vals = NULL;
- next = NULL;
- }
- ~EnumInfo()
- {
- free(name);
- while (vals)
- {
- EnumValInfo *va=vals;
- vals = va->next;
- delete va;
- }
- }
- char *name;
- EnumValInfo *vals;
- EnumInfo *next;
- };
- class EspMessageInfo
- {
- public:
- enum espm_type {espm_none, espm_struct, espm_enum, espm_request, espm_response};
- enum espaxm_type {espaxm_getters, espaxm_setters, espaxm_both};
- EspMessageInfo(const char *name, enum espm_type type=espm_none)
- {
- espm_type_=type;
- name_ =strdup(name);
- base_=NULL;
- attrs_=NULL;
- tags=NULL;
- next=NULL;
- parent=NULL;
- xsdgrouptype=NULL;
- }
- EspMessageInfo(enum espm_type type, ProcInfo *procInfo)
- {
- espm_type_=type;
- name_ =strdup(procInfo->name);
- if (espm_type_==espm_struct)
- {
- name_ =(char *)malloc(strlen(procInfo->name)+6);
- strcpy(name_, procInfo->name);
- strcat(name_, "Struct");
- attrs_ = procInfo->params;
- procInfo->params=NULL;
- }
- else if (espm_type_==espm_request)
- {
- name_ =(char *)malloc(strlen(procInfo->name)+8);
- strcpy(name_, procInfo->name);
- strcat(name_, "Request");
- attrs_ = procInfo->params;
- procInfo->params=NULL;
- }
- else
- {
- name_ =(char *)malloc(strlen(procInfo->name)+9);
- strcpy(name_, procInfo->name);
- strcat(name_, "Response");
- setParams(procInfo->rettype);
- procInfo->rettype=NULL;
- }
- tags=NULL;
- next=NULL;
- parent=NULL;
- xsdgrouptype=NULL;
- }
- void setType(espm_type type){espm_type_=type;}
- espm_type getType(){return espm_type_;}
- const char *getName(){return name_;}
- void setName(const char *name)
- {
- if (name_)
- free(name_);
- name_=strdup(name);
- }
- const char *getBase(){return base_;}
- void setBase(const char *base)
- {
- if (base_)
- free(base_);
- base_=strdup(base);
- }
- const char *getParentName()
- {
- if (parent)
- return parent;
- if (!getMetaString("extends", NULL))
- return NULL;
- parent=((char *)strdup(getMetaString("extends", NULL))+1);
- char *finger=strchr(parent, '\"');
- if (finger)
- *finger=0;
- return parent;
- }
- void setParentName(const char* name)
- {
- parent = strdup(name);
- }
- const char *getXsdGroupType()
- {
- if (!xsdgrouptype)
- {
- const char* s = getMetaString("xsd_group_type", "\"all\"");
- if (*s == '\"')
- {
- xsdgrouptype = strdup(s+1);
- char *finger = strchr(xsdgrouptype, '\"');
- if (finger)
- *finger=0;
- }
- else
- xsdgrouptype = strdup(s);
- }
- return xsdgrouptype;
- }
- const char *getMetaString(const char *tag, const char *def_val)
- {
- return ::getMetaString(tags, tag, def_val);
- }
- bool getMetaStringValue(StringBuffer &val, const char *tag)
- {
- return ::getMetaStringValue(tags, val, tag);
- }
- int getMetaInt(const char *tag, int def_val=0)
- {
- return ::getMetaInt(tags, tag, def_val);
- }
- bool hasMapInfo();
- void setParams(ParamInfo *param)
- {
- attrs_=param;
- }
- ParamInfo *getParams(){return attrs_;}
- const char * query_esxdl_type()
- {
- switch (espm_type_)
- {
- case espm_struct:
- return "EsdlStruct";
- case espm_enum:
- return "EsdlEnumType";
- case espm_request:
- return "EsdlRequest";
- case espm_response:
- return "EsdlResponse";
- case espm_none:
- default:
- break;
- }
- return NULL;
- }
- EspMessageInfo *find_parent();
- void toStringEsxdlChildren(StringBuffer & out)
- {
- EspMessageInfo *parmsg = find_parent();
- if (parmsg)
- parmsg->toStringEsxdlChildren(out);
- for (ParamInfo *param=attrs_; param; param=param->next)
- param->toString(out);
- }
- void toString(StringBuffer & out)
- {
- const char *esdltype = query_esxdl_type();
- if (esdltype)
- {
- out.appendf("\t<%s name='%s'", esdltype, name_);
- if (base_ && *base_)
- {
- out.appendf(" base='%s'", base_);
- }
- if (parent)
- {
- out.appendf(" base_type='%s'", parent);
- }
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- out.append(">\n");
- for (ParamInfo *param=attrs_; param; param=param->next)
- {
- param->toString(out);
- }
- out.appendf("\t</%s>\n", esdltype);
- }
- }
- MetaTagInfo *tags;
- EspMessageInfo *next;
- ~EspMessageInfo()
- {
- while (attrs_)
- {
- ParamInfo *attr=attrs_;
- attrs_ = attr->next;
- delete attr;
- }
- while (tags)
- {
- MetaTagInfo *attr=tags;
- tags = attr->next;
- delete attr;
- }
- delete tags;
- free (name_);
- free (base_);
- free (parent);
- free (xsdgrouptype);
- }
- private:
- ParamInfo *attrs_;
- espm_type espm_type_;
- char *name_;
- char *base_;
- char *parent;
- char *xsdgrouptype;
- };
- class EspMethodInfo
- {
- private:
- char *name_;
- char *request_;
- char *response_;
- ProcInfo *proc_;
- public:
- EspMethodInfo(const char *name, const char *req, const char *resp)
- {
- name_ =strdup(name);
- request_ =strdup(req);
- response_ =strdup(resp);
- proc_=NULL;
- tags=NULL;
- next=NULL;
- }
- EspMethodInfo(ProcInfo *procInfo)
- {
- proc_=procInfo;
- name_ =strdup(procInfo->name);
- request_ =(char *)malloc(strlen(name_)+8);
- strcpy(request_, name_);
- strcat(request_, "Request");
- response_ =(char *)malloc(strlen(name_)+9);
- strcpy(response_, name_);
- strcat(response_, "Response");
- tags=NULL;
- next=NULL;
- }
- ~EspMethodInfo()
- {
- fprintf(stderr, "~EspMethodInfo(%s)\n", name_);
- while (tags)
- {
- MetaTagInfo *p=tags;
- tags = p->next;
- delete p;
- }
- if (name_)
- free(name_);
- if (request_)
- free(request_);
- if (response_)
- free(response_);
- }
- const char *getName(){return name_;}
- void setName(const char *name)
- {
- if (name_)
- free(name_);
- name_ =strdup(name);
- }
- const char *getReq(){return request_;}
- void setReq(const char *name)
- {
- if (request_)
- free(request_);
- request_ =strdup(name);
- }
- const char *getResp(){return response_;}
- void setResp(const char *name)
- {
- if (response_)
- free(response_);
- response_ =strdup(name);
- }
- const char *getMetaString(const char *tag, const char *def_val)
- {
- return ::getMetaString(tags, tag, def_val);
- }
- bool getMetaStringValue(StringBuffer &val, const char *tag)
- {
- return ::getMetaStringValue(tags, val, tag);
- }
- int getMetaInt(const char *tag, int def_val=0)
- {
- return ::getMetaInt(tags, tag, def_val);
- }
- bool getMetaVerInfo(const char* tag, StringBuffer& s)
- {
- return ::getMetaVerInfo(tags,tag,s);
- }
- EspMessageInfo *getRequestInfo();
- void toString(StringBuffer & out)
- {
- out.appendf("\t<EsdlMethod name='%s' request_type='%s' response_type='%s' ", name_, request_, response_);
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- out.append("/>\n");
- }
- MetaTagInfo *tags;
- EspMethodInfo *next;
- };
- class EspMountInfo
- {
- private:
- char *name_;
- char *localPath_;
- public:
- EspMountInfo(const char *name, const char *localPath)
- {
- name_ =strdup(name);
- localPath_ =strdup(localPath);
- tags=NULL;
- next=NULL;
- }
- ~EspMountInfo()
- {
- if (name_)
- free(name_);
- if (localPath_)
- free(localPath_);
- }
- const char *getName(){return name_;}
- void setName(const char *name)
- {
- if (name_)
- free(name_);
- name_ =strdup(name);
- }
- const char *getLocalPath(){return localPath_;}
- void setLocalPath(const char *path)
- {
- if (localPath_)
- free(localPath_);
- localPath_ =strdup(path);
- }
- const char *getMetaString(const char *tag, const char *def_val)
- {
- return ::getMetaString(tags, tag, def_val);
- }
- bool getMetaStringValue(StringBuffer &val, const char *tag)
- {
- return ::getMetaStringValue(tags, val, tag);
- }
- int getMetaInt(const char *tag, int def_val=0)
- {
- return ::getMetaInt(tags, tag, def_val);
- }
- double getMetaDouble(const char* tag, double def_val=0)
- {
- return ::getMetaDouble(tags,tag,def_val);
- }
- MetaTagInfo *tags;
- EspMountInfo *next;
- };
- class EspStructInfo
- {
- private:
- char *name_;
- public:
- EspStructInfo(const char *name)
- {
- name_ =strdup(name);
- tags=NULL;
- next=NULL;
- }
- ~EspStructInfo()
- {
- if (name_)
- free(name_);
- }
- const char *getName(){return name_;}
- void setName(const char *name)
- {
- if (name_)
- free(name_);
- name_ =strdup(name);
- }
- const char *getMetaString(const char *tag, const char *def_val)
- {
- return ::getMetaString(tags, tag, def_val);
- }
- bool getMetaStringValue(StringBuffer &val, const char *tag)
- {
- return ::getMetaStringValue(tags, val, tag);
- }
- int getMetaInt(const char *tag, int def_val=0)
- {
- return ::getMetaInt(tags, tag, def_val);
- }
- MetaTagInfo *tags;
- EspStructInfo *next;
- };
- typedef enum _catch_type
- {
- ct_httpresp,
- ct_soapresp,
- } catch_type;
- class EspServInfo
- {
- private:
- char *name_;
- char *base_;
- bool needsXslt;
- public:
- EspServInfo(const char *name)
- {
- name_ =strdup(name);
- base_=NULL;
- methods=NULL;
- mounts=NULL;
- tags=NULL;
- structs=NULL;
- next=NULL;
- needsXslt = false;
- }
- ~EspServInfo()
- {
- if (name_)
- free(name_);
- if (base_)
- free(base_);
- }
- const char *getName(){return name_;}
- void setName(const char *name)
- {
- if (name_)
- free(name_);
- name_ =strdup(name);
- }
- const char *getBase(){return base_;}
- void setBase(const char *base)
- {
- if (base_)
- free(base_);
- base_ =strdup(base);
- }
- const char *getMetaString(const char *tag, const char *def_val)
- {
- return ::getMetaString(tags, tag, def_val);
- }
- bool getMetaStringValue(StringBuffer &val, const char *tag)
- {
- return ::getMetaStringValue(tags, val, tag);
- }
- int getMetaInt(const char *tag, int def_val=0)
- {
- return ::getMetaInt(tags, tag, def_val);
- }
- void toString(StringBuffer & out)
- {
- out.appendf("\t\t<EsdlService name='%s' ", name_);
- for (MetaTagInfo *mtag=tags; mtag; mtag=mtag->next)
- {
- mtag->toStringXmlAttr(out);
- }
- out.append(">\n");
- for (EspMethodInfo *mth=methods; mth; mth=mth->next)
- {
- mth->toString(out);
- }
- out.append("\t\t</EsdlService>");
- }
- EspStructInfo *structs;
- EspMethodInfo *methods;
- EspMountInfo *mounts;
- MetaTagInfo *tags;
- EspServInfo *next;
- void sortMethods();
- };
- class esdlcomp_decl ESDLcompiler
- {
- public:
- ESDLcompiler(const char * sourceFile, bool generatefile, const char * outDir, bool outputIncludes, bool includedEsdl, const char* includePath);
- ~ESDLcompiler();
- void Process();
- void write_esxdl();
- const char * getSrcDir() const
- {
- return srcDir.str();
- }
- const char * getEsxdlContent() const
- {
- return esxdlcontent.str();
- }
- const char* getPackageName()
- {
- return packagename;
- }
- char* filename;
- StringBuffer name;
- private:
- bool outputIncludes;
- int esxdlo;
- char* packagename;
- StringBuffer srcDir;
- StringBuffer esxdlcontent;
- StringArray includeDirs;
- bool locateIncludedFile(StringBuffer& filepath, const char* prot, const char* srcDir, const char* fname, const char* ext);
- public:
- static CriticalSection m_critSect;
- ModuleInfo* modules;
- EnumInfo* enums;
- ApiInfo* apis;
- EspMessageInfo* msgs;
- EspServInfo* servs;
- EspMethodInfo* methods;
- IncludeInfo* includes;
- VersionInfo* versions;
- };
- extern int nCommentStartLine;
- extern void yyerror(const char *s);
- inline char upperchar(char val){return ((val<97 || val>122) ? val : (val-32));}
- #endif
|