-
Notifications
You must be signed in to change notification settings - Fork 2
/
msgc.hpp
1624 lines (1522 loc) · 68.7 KB
/
msgc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef _MAKE_MSGC_msgc_hpp_ID_
#define _MAKE_MSGC_msgc_hpp_ID_
#if defined(__sgi) && defined(_SGI_COMPILER_VERSION)
#pragma weak _MAKE_MSGC_msgc_hpp_id_w = _MAKE_MSGC_msgc_hpp_id_
#endif /* __sgi */
static const char* _MAKE_MSGC_msgc_hpp_id_
#if defined(__GNUC__)
__attribute__ ((used,unused))
#endif /* __GNUC__ */
= "@(#)$Id: msgc.hpp 55141 2009-08-18 21:17:30Z wguan@syncsort.com $";
#endif
/******************************************************************************
Syncsort CLIENT-SERVER BACKUP
COPYRIGHT(C) 2000
Module Name : msgc
Component Name : DevTools
Program Filename : msgc.hpp
General Description : Message Compiler
System Dependencies : NONE
History Information : Provided by the RCS package in the following.
* $Log: msgc.hpp,v $
* Revision 1.18 2006/11/06 22:23:00 urano
* I..4-204: msgc: verstr directive
*
* Revision 1.17 2005/03/14 20:52:16 urano
* I..2-820: BEXIDL: hidden qualifier for a mdata member
*
* Revision 1.16 2004/02/09 16:14:23 urano
* I..1-917: BEXIDL : clear cache between 'translation units'
*
* Revision 1.15 2003/07/23 16:11:31 urano
* I..1-658: msgc JAVA stub to synchronize
*
* Revision 1.14 2003/05/06 20:10:15 urano
* I..1-613: BEXIDL : format specification for mdata
*
* Revision 1.13 2003/04/11 14:25:34 urano
* I..1-584: bexException to keep ctlMDat; SvcInt_X in Java
*
* Revision 1.12 2003/01/30 20:14:26 urano
* I...-659: Backup Express Message Library
*
* Revision 1.11 2003/01/15 18:49:31 urano
* I..1-412: Improving compile time for BEXIDL C++ stubs
*
* Revision 1.9 2003/01/08 18:27:39 urano
* I...-666: rstring_sy
*
* Revision 1.8 2002/11/15 20:10:28 urano
* I..1-436: devui
*
* Revision 1.7 2002/11/06 22:25:23 urano
* I..1-412: Improving compile time for BEXIDL C++ stubs
*
* Revision 1.6 2002/10/10 22:07:38 urano
* I...-674: winnt compatibility
*
* Revision 1.5 2002/10/08 14:19:04 urano
* I...-674: Device Management Module
*
* Revision 1.4 2002/07/23 21:14:15 urano
* I...-674: Device Management Module
*
* Revision 1.3 2002/06/12 19:41:32 urano
* I..1-069: Device Management Module
*
* Revision 1.2 2001/09/28 21:29:56 urano
* I..1-069: msg_flag autogeneration in msgc
*
* Revision 1.1 2001/09/20 16:33:44 urano
* Initial revision
*
*
*****************************************************************************/
#ifndef _MSGC_HPP_
#define _MSGC_HPP_
// stdlib includes
#include <ctype.h> // for upper
#include <exception>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <stdexcept>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// additional utility includes
#if !defined(yyFlexLexerOnce)
#include <FlexLexer.h>
#endif
// genlib includes
#include <cntdptr.hpp>
///////////////////////////////////////////////////////////
// Base Classes
//
class msgc_exception : public std::exception {
protected:
std::string message;
public:
virtual ~msgc_exception() throw() {}
explicit msgc_exception (const std::string & _msg): message(_msg) {}
virtual const char * what () const throw() {return (message.c_str()); }
};
class msgc_exception_not_in_store : public msgc_exception {
public:
explicit msgc_exception_not_in_store(const std::string & _msg): msgc_exception(_msg) {}
virtual ~msgc_exception_not_in_store() throw() {}
};
// utility class stringPtrMap - adaptor to map<string,Ptr>
template<class Ptr>
class stringPtrMap : public std::map<std::string,Ptr> {
typedef std::map<std::string,Ptr> Base;
public:
void insert(const std::string & _name, Ptr _p) {
if (!Base::insert(std::make_pair(_name,_p)).second)
throw msgc_exception(_name+" has already been defined.");
}
bool erase (const std::string & _name) {
return (Base::erase (_name) > 0);
}
Ptr get (const std::string & _name) {
typename Base::iterator it = Base::find (_name);
if (it == Base::end())
throw msgc_exception_not_in_store(_name+" is undefined.");
return (*it).second;
}
std::vector<std::string> getKeys() const {
std::vector<std::string> result;
for (typename Base::const_iterator it=Base::begin(); it!=Base::end(); ++it) {
result.push_back(it->first);
}
return result;
}
};
class NamedObject : public gen::CountedObject {
std::string name; // name of the type
public:
explicit NamedObject (const std::string & _name) : name(_name) {};
const std::string & getName () const { return name; }
void setName (const std::string & _name) { name = _name; }
};
//
// InclusionInfo
//
class InclusionInfo {
public:
enum IncType {INC_H, INC_C, INC_HPP, INC_CPP, INC_JAVA, numIncs};
private:
std::vector<std::string> inclusions[numIncs];
public:
static IncType getIncType (const std::string & _incTypeStr) {
if (_incTypeStr == "H")
return INC_H;
else if (_incTypeStr == "C")
return INC_C;
else if (_incTypeStr == "HPP")
return INC_HPP;
else if (_incTypeStr == "CPP")
return INC_CPP;
else if (_incTypeStr == "JAVA")
return INC_JAVA;
else
throw msgc_exception ("Unknown inclusion type: "+_incTypeStr);
}
std::vector<std::string> & operator[] (IncType _incType) {
return inclusions[_incType];
}
bool hasInclusion (IncType _incType) const {
return !inclusions[_incType].empty();
}
void printInclusion (std::ostream & os, IncType _incType) const {
for (std::vector<std::string>::size_type i=0; i<inclusions[_incType].size(); i++)
os << inclusions[_incType][i] << std::endl;
}
};
// MsgClassInfo contain info about any "object" defined in a .m file.
// They all have some C++ and Java interpretation.
// NB: the C++ and Java classes follow the Java convention that class names
// each begins with a capital letter.
// abstract
class MsgClassInfo : public NamedObject {
std::string cppName; /* corresponding c++ name */
std::string jName; /* corresponding java name */
protected:
virtual void setCPPName (const std::string & _cppName) {
cppName = _cppName;
}
virtual void setJName (const std::string & _jName) {
jName = _jName;
}
public:
explicit MsgClassInfo (const std::string & _name) : NamedObject(_name) {};
virtual const std::string & getCPPName () const { return cppName; }
virtual const std::string & getJName() const { return jName; };
};
// DataType object will have a C interpretation as well.
// abstract
class DataTypeInfo : public MsgClassInfo {
typedef MsgClassInfo Base;
public:
typedef gen::CountedPtr<DataTypeInfo> Ptr;
private:
static stringPtrMap<Ptr> store;
std::string cName; // corresponding c type
char cTok; // msg_create/parse_generic template token
std::string jTok; // corresponding java type token
protected:
static bool erase (const std::string & _name) { return store.erase (_name); }
virtual bool erase () {return erase(getName());}
explicit DataTypeInfo (const std::string & _name) : Base (_name)
{ store.insert(_name, Ptr(this)); }
virtual void setCName (const std::string & _cName) {cName = _cName;}
virtual void setCTok (const char & _cTok) {cTok = _cTok;}
virtual void setJTok (const std::string & _jTok) {jTok = _jTok;}
public:
static Ptr get (const std::string & _name) { return store.get (_name); }
virtual std::string getCName () const { return cName; }
virtual const char & getCTok () const { return cTok; }
virtual std::string getJTok () const { return jTok; }
virtual bool parserMustAllocateMemory() const =0;
virtual bool parserUsesMSList() const =0;
virtual std::string getCTokPut (const std::string & buffPtrName, const std::string & buffEndPtrName,
const std::string & dataVarName) const = 0;
virtual std::string getCTokGet (const std::string & buffPtrName, const std::string & memHandleName,
const std::string & dataVarName) const = 0;
virtual std::string getCCopy (const std::string & copyDatName, const std::string & origDatName,
const std::string & memHandleName) const = 0;
virtual std::string getCOstrmPrint (const std::string & ostrmPtrName, const std::string & dataVarName,
const std::string & nameVarName) const = 0;
virtual std::string getCSTreePut (const std::string & streePtrName, const std::string & dataVarName,
const std::string & nameVarName) const = 0;
virtual std::string getCSTreeGet (const std::string & streePtrName, const std::string & memHandleName,
const std::string & dataVarName, const std::string & nameVarName) const = 0;
virtual bool specializesArray () const { return false; } // redefine the following functions if true
virtual bool arrayNeedsLenVar () const { return true; }
virtual std::string getCArrayTokPut (const std::string & buffPtrName, const std::string & buffEndPtrName,
const std::string & dataVarName, const std::string & lenVarName) const {}
virtual std::string getCArrayTokGet (const std::string & buffPtrName, const std::string & memHandleName,
const std::string & dataVarName, const std::string & lenVarName) const {}
virtual std::string getCArrayCopy (const std::string & copyVarName, const std::string & origVarName,
const std::string & memHandleName,
const std::string & copyLenVarName, const std::string & origLenVarName) const {}
virtual std::string getCArrayOstrmPrint (const std::string & ostrmPtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {}
virtual std::string getCArraySTreePut (const std::string & streePtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {}
virtual std::string getCArraySTreeGet (const std::string & streePtrName, const std::string & memHandleName,
const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {}
virtual bool isInner() const =0;
virtual bool isLink() const =0;
virtual std::string getLinkVar() const {return "";}
virtual std::string getCPPArrayName () const {
if (isLink())
return "std::list<" + getCPPName() + " >";
else
return "std::vector<" + getCPPName() + " >";
}
virtual std::string getJArrayName () const {
return getJName() + "[]";
}
virtual std::string getJArrayTok () const {
return "[" + getJTok();
}
};
// Primitive Types
class PrimTypeInfo : public DataTypeInfo {
typedef DataTypeInfo Base;
public:
typedef gen::CountedPtr<PrimTypeInfo> Ptr;
private:
static stringPtrMap<Ptr> store;
std::string tokPutName;
std::string tokGetName;
protected:
static bool erase (const std::string & _name) {return Base::erase (_name) && store.erase (_name);}
PrimTypeInfo ( const std::string & _name,
const std::string & _cName,
const std::string & _cppName,
const char & _cTok,
const std::string & _tokPutName,
const std::string & _tokGetName,
const std::string & _jName,
const std::string & _jTok
) : Base (_name), tokPutName(_tokPutName), tokGetName(_tokGetName) {
setCName(_cName);
setCPPName(_cppName);
setCTok(_cTok);
setJName(_jName);
setJTok(_jTok);
store.insert(_name,Ptr(this));
}
public:
static Ptr getNew ( const std::string & _name,
const std::string & _cName,
const std::string & _cppName,
const char & _cTok,
const std::string & _tokPutName,
const std::string & _tokGetName,
const std::string & _jName,
const std::string & _jTok
);
virtual bool erase () {return erase(getName());}
static Ptr get (const std::string & _name) { return store.get (_name); }
virtual bool parserMustAllocateMemory() const {return true;}
virtual bool parserUsesMSList() const {return false;}
virtual std::string getCTokPut (const std::string & buffPtrName, const std::string & buffEndPtrName,
const std::string & dataVarName) const {
return tokPutName + "( &" + buffPtrName + ", (char_sy *) " + buffEndPtrName + ", " + dataVarName + ")";
};
virtual std::string getCTokGet (const std::string & buffPtrName, const std::string & memHandleName,
const std::string & dataVarName) const {
return tokGetName + "( (char_sy **) &" + buffPtrName + ", &" + dataVarName + ")";
};
virtual std::string getCCopy (const std::string & copyDatName, const std::string & origDatName,
const std::string & memHandleName) const {
return copyDatName + " = " + origDatName;
};
virtual std::string getCOstrmPrint (const std::string & ostrmPtrName, const std::string & dataVarName,
const std::string & nameVarName) const {
return "mdat_ostrm_print_" + getCName() + "_ ( " + ostrmPtrName
+ ", " + dataVarName + ", " + nameVarName + ")";
};
virtual std::string getCSTreePut (const std::string & streePtrName, const std::string & dataVarName,
const std::string & nameVarName) const {
return "mdat_stree_put_" + getCName() + "_ ( " + streePtrName
+ ", " + dataVarName + ", " + nameVarName + ")";
};
virtual std::string getCSTreeGet (const std::string & streePtrName, const std::string & memHandleName,
const std::string & dataVarName,
const std::string & nameVarName) const {
return "mdat_stree_get_" + getCName() + "_ ( " + streePtrName
+ ", &" + dataVarName + ", " + nameVarName + ")";
};
bool isInner() const {return true;}
bool isLink() const {return false;}
};
// special Primitive Type : "tchar_sy" (tchar_sy[] = string_sy)
class TCharSy : public PrimTypeInfo {
public:
const static std::string NAME;
private:
friend class PrimTypeInfo;
TCharSy ( const std::string & _cName,
const char & _cTok,
const std::string & _tokPutName,
const std::string & _tokGetName,
const std::string & _jName,
const std::string & _jTok
) : PrimTypeInfo (NAME, _cName, _cName, _cTok, _tokPutName, _tokGetName, _jName, _jTok) {};
public:
std::string getCPPArrayName () const {
return "gen::string_sy";
}
std::string getJArrayName () const {
return "String";
}
virtual std::string getJArrayTok () const {
return "Ljava/lang/String;";
}
bool parserMustAllocateMemory() const {return false;};
bool parserUsesMSList() const {return true;}
bool specializesArray () const { return true; }
bool arrayNeedsLenVar () const { return true; }
std::string getCArrayTokPut (const std::string & buffPtrName, const std::string & buffEndPtrName,
const std::string & dataVarName, const std::string & lenVarName) const {
return "TOK_putstring( &" + buffPtrName + ", (char_sy *) " + buffEndPtrName + ", "
+ dataVarName + ", " + lenVarName + ")";
}
std::string getCArrayTokGet (const std::string & buffPtrName, const std::string & memHandleName,
const std::string & dataVarName, const std::string & lenVarName) const {
return "(" + memHandleName + ")?TOK_getstring_alloc( (char_sy **) &" + buffPtrName + ", &" + dataVarName
+ ", &" + lenVarName + ", " + memHandleName + "):"
+ "TOK_getstring( (char_sy **) &" + buffPtrName + ", &" + dataVarName
+ ", &" + lenVarName + ")";
}
std::string getCArrayCopy (const std::string & copyVarName, const std::string & origVarName,
const std::string & memHandleName,
const std::string & copyLenVarName, const std::string & origLenVarName) const {
return "if(1) {if (" + memHandleName + ") {" + copyVarName + "= (char_sy *) malloc ((size_t) ("
+ origLenVarName + ")); " + "list_push(" + memHandleName + ", " + copyVarName + "); }; "
+ copyLenVarName + " = " + origLenVarName + "; "
+ "strncpy (" + copyVarName + ", " + origVarName + ", " + origLenVarName + "); "
+ "} else";
}
std::string getCArrayOstrmPrint (const std::string & ostrmPtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_ostrm_print_string_sy_ (" + ostrmPtrName + ", " + dataVarName + ", "
+ lenVarName + ", " + nameVarName + ")";
}
std::string getCArraySTreePut (const std::string & streePtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_stree_put_string_sy_ (" + streePtrName + ", " + dataVarName + ", "
+ lenVarName + ", " + nameVarName + ")";
}
std::string getCArraySTreeGet (const std::string & streePtrName, const std::string & memHandleName,
const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_stree_get_string_sy_ (" + streePtrName + ", &" + dataVarName + ", &"
+ lenVarName + ", " + nameVarName + ", " + memHandleName + ")";
}
};
// special Primitive Type : "bchar_sy" (bchar_sy[] = bstring_sy)
class BCharSy : public PrimTypeInfo {
public:
const static std::string NAME;
private:
friend class PrimTypeInfo;
BCharSy ( const std::string & _cName,
const char & _cTok,
const std::string & _tokPutName,
const std::string & _tokGetName,
const std::string & _jName,
const std::string & _jTok
) : PrimTypeInfo (NAME, _cName, _cName, _cTok, _tokPutName, _tokGetName, _jName, _jTok) {};
public:
std::string getCPPArrayName () const {
return "gen::string_sy";
}
std::string getJArrayName () const {
return "String";
}
virtual std::string getJArrayTok () const {
return "Ljava/lang/String;";
}
bool parserMustAllocateMemory() const {return false;};
bool parserUsesMSList() const {return false;}
bool specializesArray () const { return true; }
bool arrayNeedsLenVar () const { return true; }
std::string getCArrayTokPut (const std::string & buffPtrName, const std::string & buffEndPtrName,
const std::string & dataVarName, const std::string & lenVarName) const {
return "TOK_putstring( &" + buffPtrName + ", (char_sy *) " + buffEndPtrName + ", "
+ dataVarName + ", " + lenVarName + ")";
}
std::string getCArrayTokGet (const std::string & buffPtrName, const std::string & memHandleName,
const std::string & dataVarName, const std::string & lenVarName) const {
return "TOK_getstring( (char_sy **) &" + buffPtrName + ", &" + dataVarName
+ ", &" + lenVarName + ")";
}
std::string getCArrayCopy (const std::string & copyVarName, const std::string & origVarName,
const std::string & memHandleName,
const std::string & copyLenVarName, const std::string & origLenVarName) const {
return "if(1) {" + copyVarName + " = " + origVarName + "; "
+ copyLenVarName + "=" + origLenVarName + ";} else";
}
std::string getCArrayOstrmPrint (const std::string & ostrmPtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_ostrm_print_string_sy_ (" + ostrmPtrName + ", " + dataVarName + ", "
+ lenVarName + ", " + nameVarName + ")";
}
std::string getCArraySTreePut (const std::string & streePtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_stree_put_string_sy_ (" + streePtrName + ", " + dataVarName + ", "
+ lenVarName + ", " + nameVarName + ")";
}
std::string getCArraySTreeGet (const std::string & streePtrName, const std::string & memHandleName,
const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_stree_get_bstring_sy_ (" + streePtrName + ", &" + dataVarName + ", &"
+ lenVarName + ", " + nameVarName + ")";
}
};
// special Primitive Type : "cchar_sy" (cchar_sy[] = cstring_sy)
class CCharSy : public PrimTypeInfo {
public:
const static std::string NAME;
private:
friend class PrimTypeInfo;
CCharSy ( const std::string & _cName,
const char & _cTok,
const std::string & _tokPutName,
const std::string & _tokGetName,
const std::string & _jName,
const std::string & _jTok
) : PrimTypeInfo (NAME, _cName, _cName, _cTok, _tokPutName, _tokGetName, _jName, _jTok) {};
public:
std::string getCPPArrayName () const {
return "gen::string_sy";
}
std::string getJArrayName () const {
return "String";
}
virtual std::string getJArrayTok () const {
return "Ljava/lang/String;";
}
bool parserMustAllocateMemory() const {return false;};
bool parserUsesMSList() const {return true;}
bool specializesArray () const { return true; }
bool arrayNeedsLenVar () const { return false; }
std::string getCArrayTokPut (const std::string & buffPtrName, const std::string & buffEndPtrName,
const std::string & dataVarName, const std::string & lenVarName) const {
return "TOK_putstring( &" + buffPtrName + ", (char_sy *) " + buffEndPtrName + ", "
+ dataVarName + ", (short_sy) (" + dataVarName + "?(strlen(" + dataVarName + ")+1):0))";
}
std::string getCArrayTokGet (const std::string & buffPtrName, const std::string & memHandleName,
const std::string & dataVarName, const std::string & lenVarName) const {
return "TOK_getstring( (char_sy **) &" + buffPtrName + ", &" + dataVarName
+ ", &" + lenVarName + ")";
}
std::string getCArrayCopy (const std::string & copyVarName, const std::string & origVarName,
const std::string & memHandleName,
const std::string & copyLenVarName, const std::string & origLenVarName) const {
return "if(1) {if (" + memHandleName + " && " + origVarName + ") {" + copyVarName
+ "= (char_sy *) malloc ((size_t) strlen(" + origVarName + ")+1); "
+ "list_push(" + memHandleName + ", " + copyVarName + "); }; "
+ "strcpy (" + copyVarName + ", " + origVarName + "); "
+ "} else";
}
std::string getCArrayOstrmPrint (const std::string & ostrmPtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_ostrm_print_cstring_sy_ (" + ostrmPtrName + ", " + dataVarName + ", "
+ nameVarName + ")";
}
std::string getCArraySTreePut (const std::string & streePtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_stree_put_cstring_sy_ (" + streePtrName + ", " + dataVarName + ", "
+ nameVarName + ")";
}
std::string getCArraySTreeGet (const std::string & streePtrName, const std::string & memHandleName,
const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_stree_get_cstring_sy_ (" + streePtrName + ", &" + dataVarName + ", "
+ nameVarName + ", " + memHandleName + ")";
}
};
// special Primitive Type : "rchar_sy" (rchar_sy[] = rstring_sy)
class RCharSy : public PrimTypeInfo {
public:
const static std::string NAME;
private:
friend class PrimTypeInfo;
RCharSy ( const std::string & _cName,
const char & _cTok,
const std::string & _tokPutName,
const std::string & _tokGetName,
const std::string & _jName,
const std::string & _jTok
) : PrimTypeInfo (NAME, _cName, _cName, _cTok, _tokPutName, _tokGetName, _jName, _jTok) {};
public:
std::string getCPPArrayName () const {
return "gen::string_sy";
}
std::string getJArrayName () const {
return "String";
}
virtual std::string getJArrayTok () const {
return "Ljava/lang/String;";
}
bool parserMustAllocateMemory() const {return false;};
bool parserUsesMSList() const {return false;}
bool specializesArray () const { return true; }
bool arrayNeedsLenVar () const { return true; }
std::string getCArrayTokPut (const std::string & buffPtrName, const std::string & buffEndPtrName,
const std::string & dataVarName, const std::string & lenVarName) const {
return "TOK_putblob( &" + buffPtrName + ", (char_sy *) " + buffEndPtrName + ", "
+ dataVarName + ", " + lenVarName + ")";
}
std::string getCArrayTokGet (const std::string & buffPtrName, const std::string & memHandleName,
const std::string & dataVarName, const std::string & lenVarName) const {
return "TOK_getblob( (char_sy **) &" + buffPtrName + ", &" + dataVarName
+ ", &" + lenVarName + ")";
}
std::string getCArrayCopy (const std::string & copyVarName, const std::string & origVarName,
const std::string & memHandleName,
const std::string & copyLenVarName, const std::string & origLenVarName) const {
return "if(1) {" + copyVarName + " = " + origVarName + "; "
+ copyLenVarName + "=" + origLenVarName + ";} else";
}
std::string getCArrayOstrmPrint (const std::string & ostrmPtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_ostrm_print_string_sy_ (" + ostrmPtrName + ", " + dataVarName + ", "
+ lenVarName + ", " + nameVarName + ")";
}
std::string getCArraySTreePut (const std::string & streePtrName, const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_stree_put_string_sy_ (" + streePtrName + ", " + dataVarName + ", "
+ lenVarName + ", " + nameVarName + ")";
}
std::string getCArraySTreeGet (const std::string & streePtrName, const std::string & memHandleName,
const std::string & dataVarName,
const std::string & lenVarName, const std::string & nameVarName) const {
return "mdat_stree_get_bstring_sy_ (" + streePtrName + ", &" + dataVarName + ", &"
+ lenVarName + ", " + nameVarName + ")";
}
};
inline
PrimTypeInfo::Ptr PrimTypeInfo::getNew ( const std::string & _name,
const std::string & _cName,
const std::string & _cppName,
const char & _cTok,
const std::string & _tokPutName,
const std::string & _tokGetName,
const std::string & _jName,
const std::string & _jTok
) {
// handle special primitive types
if (_name == TCharSy::NAME)
return Ptr(new TCharSy(_cName, _cTok, _tokPutName, _tokGetName, _jName, _jTok));
if (_name == BCharSy::NAME)
return Ptr(new BCharSy(_cName, _cTok, _tokPutName, _tokGetName, _jName, _jTok));
if (_name == CCharSy::NAME)
return Ptr(new CCharSy(_cName, _cTok, _tokPutName, _tokGetName, _jName, _jTok));
if (_name == RCharSy::NAME)
return Ptr(new RCharSy(_cName, _cTok, _tokPutName, _tokGetName, _jName, _jTok));
return Ptr(new PrimTypeInfo(_name, _cName, _cppName, _cTok, _tokPutName, _tokGetName, _jName, _jTok));
}
// generic "User Defined" Interface
// abstract interface
class UserDefined {
public:
virtual void printCDeclaration (std::ostream & os) const =0;
virtual void printCPPDeclaration (std::ostream & os) const =0;
virtual void printCDefinition (std::ostream & os) const =0;
virtual void printCPPDefinition (std::ostream & os) const =0;
virtual void printJDefinition (const std::string & javaDir, const std::string & inFileName) const =0;
};
// KeywordTab is a singleton table used to hold
// information regarding all the message keywords (tokens)
class KeywordTab : public UserDefined {
static std::map<std::string, int> tab;
static std::map<std::string, std::vector<std::string> > classTab;
bool done;
int insertSlot;
KeywordTab () : done (false), insertSlot(0) {};
KeywordTab (const KeywordTab &);
KeywordTab & operator= (const KeywordTab &);
public:
static KeywordTab & get() {
static KeywordTab glob;
return glob;
}
void add (const std::string & _name, const std::string & _idName,
const std::string & _className);
void add (const std::string & _name, int _value =0);
void setDone ();
const std::string getJName() const { return "keyword"; };
void printCDeclaration (std::ostream & os) const;
void printCPPDeclaration (std::ostream & os) const;
void printCDefinition (std::ostream & os) const;
void printCPPDefinition (std::ostream & os) const;
void printJDefinition (const std::string & javaDir, const std::string & inFileName) const;
};
// User Defined Message Class
// abstract
class UserDefinedMsgClass : public MsgClassInfo, public UserDefined {
typedef MsgClassInfo Base;
public:
typedef gen::CountedPtr<UserDefinedMsgClass> Ptr;
protected:
virtual void setCPPName (const std::string & _cppName) {Base::setCPPName(_cppName);}
virtual void setJName (const std::string & _jName) {
std::string temp = _jName;
if (!temp.empty()) temp[0] = toupper(temp[0]);
Base::setJName(temp);
}
virtual void setCPPName () =0;
virtual void setJName () =0;
void setMangledNames () {
setCPPName(); setJName();
}
explicit UserDefinedMsgClass (const std::string & _name) : Base (_name) {}
public:
};
// User Defined Data Types
// abstract
class UserDefinedTypeInfo : public DataTypeInfo, public UserDefined {
typedef DataTypeInfo Base;
public:
typedef gen::CountedPtr<UserDefinedTypeInfo> Ptr;
private:
static stringPtrMap<Ptr> store;
protected:
static bool erase (const std::string & _name) {return Base::erase (_name) && store.erase (_name);}
virtual bool erase () {return erase(getName());}
explicit UserDefinedTypeInfo (const std::string & _name) : Base (_name)
{ store.insert(_name,Ptr(this)); }
virtual void setCName (const std::string & _cName) {Base::setCName(_cName);}
virtual void setCTok (const char & _cTok) {Base::setCTok(_cTok);}
virtual void setCPPName (const std::string & _cppName) {Base::setCPPName(_cppName);}
virtual void setJName (const std::string & _jName) {Base::setJName(_jName);}
virtual void setCName () =0;
virtual void setCTok () =0;
virtual void setCPPName () =0;
virtual void setJName () =0;
virtual void setJTok () {Base::setJTok("Lcom/syncsort/bex/msg/" + getJName() + ";");}
void setMangledNames () {
setCName(); setCTok(); setCPPName(); setJName(); setJTok ();
}
public:
static Ptr get (const std::string & _name) { return store.get (_name); }
virtual bool parserMustAllocateMemory() const {return true;};
virtual bool parserUsesMSList() const {return false;}
virtual std::string getCTokPut (const std::string & buffPtrName, const std::string & buffEndPtrName,
const std::string & dataVarName) const {
return "mdat_create_"+getName() + "( &" + buffPtrName + ", " + buffEndPtrName + ", &" + dataVarName + ")";
};
virtual std::string getCTokGet (const std::string & buffPtrName, const std::string & memHandleName,
const std::string & dataVarName) const {
return "mdat_parse_"+getName() + "( &" + buffPtrName + ", &" + dataVarName + ")";
};
virtual std::string getCCopy (const std::string & copyDatName, const std::string & origDatName,
const std::string & memHandleName) const {
return "mdat_copy_"+getName() + "(" + copyDatName + ", " + origDatName + ")";
};
virtual std::string getCOstrmPrint (const std::string & ostrmPtrName, const std::string & dataVarName,
const std::string & nameVarName) const {
return "mdat_ostrm_print_"+getName() + "( " + ostrmPtrName + ", &" + dataVarName
+ ", " + nameVarName + ")";
};
virtual std::string getCSTreePut (const std::string & streePtrName, const std::string & dataVarName,
const std::string & nameVarName) const {
return "mdat_stree_put_"+getName() + "( " + streePtrName + ", &" + dataVarName
+ ", " + nameVarName + ")";
};
virtual std::string getCSTreeGet (const std::string & streePtrName, const std::string & memHandleName,
const std::string & dataVarName, const std::string & nameVarName) const {
return "mdat_stree_get_"+getName() + "( " + streePtrName + ", &" + dataVarName
+ ", " + nameVarName + ")";
};
};
///////////////////////////////////////////////////////////
// Flag class related
//
class FlagEnumItem {
std::string name;
std::string value;
public:
FlagEnumItem (const std::string & _name ="", const std::string & _value ="") :
name(_name), value(_value) {}
std::string getName () const {return name; }
std::string getValue () const {return value; }
};
// holds instance of " flag_sy<prim_type> name {enum_list}; "
class FlagTypeInfo : public UserDefinedTypeInfo {
typedef UserDefinedTypeInfo Base;
public:
typedef gen::CountedPtr<FlagTypeInfo> Ptr;
private:
static stringPtrMap<Ptr> store;
PrimTypeInfo::Ptr primTypePtr;
std::vector<FlagEnumItem> flags;
void setCName() { Base::setCName (primTypePtr->getCName()); }
void setCTok () { Base::setCTok (primTypePtr->getCTok()); }
void setCPPName() { Base::setCPPName (getName()); }
void setJName() { Base::setJName (getName()); }
protected:
static bool erase (const std::string & _name) {return Base::erase (_name) && store.erase (_name);}
FlagTypeInfo (const std::string & _name, const std::string & _primTypeName) : Base (_name) {
primTypePtr = PrimTypeInfo::get (_primTypeName);
setMangledNames ();
store.insert(_name,Ptr(this));
}
public:
static void eraseAll() {
std::vector<std::string> allNames = store.getKeys();
for (std::vector<std::string>::const_iterator it=allNames.begin(); it!=allNames.end(); ++it)
erase (*it);
}
static Ptr getNew (const std::string & _name, const std::string & _primTypeName) {
return Ptr(new FlagTypeInfo(_name, _primTypeName));
}
virtual bool erase () {return erase(getName());}
static Ptr get (const std::string & _name) { return store.get (_name); }
void addFlagEnumItem (const FlagEnumItem & _item) { flags.push_back(_item); }
virtual void printCDeclaration (std::ostream & os) const;
virtual void printCPPDeclaration (std::ostream & os) const;
virtual void printCDefinition (std::ostream & os) const;
virtual void printCPPDefinition (std::ostream & os) const;
virtual void printJDefinition (const std::string & javaDir, const std::string & inFileName) const;
bool isInner() const {return true;}
bool isLink() const {return false;}
};
///////////////////////////////////////////////////////////
// MData related
//
class MDataTypeInfo; // early declaration
class MDataMemberInfo; // early declaration
class MDataVisualInfo {
friend int yyparse();
friend class MDataTypeInfo;
std::string vType; // name of the visual component type
std::string vURI; // name of the URI associated with the visual component
std::string vFunc; // name of the function associated with the visual component
public:
MDataVisualInfo (const std::string & _vType ="",
const std::string & _vURI ="\"\"",
const std::string & _vFunc = "\"\"") :
vType(_vType), vURI(_vURI), vFunc(_vFunc) {}
};
class TypeQualifier {
friend class MDataMemberInfo;
friend class MDataTypeInfo;
public:
const static char C_NULL = '\0'; // (used to indicate that memory management is done internally in the mdata)
const static char C_PTR = '*'; // (used to indicate that memory management is not done by the mdata)
const static char C_MSLIST = '+'; // (used to indicate that memory management is done via ms_list subsystem)
private:
bool b_IsPtr;
bool b_CtorAllocatesMemory;
bool b_ParserAllocatesMemory;
bool b_ParserUsesMSList;
bool b_DtorReleasesMemory;
std::string lenName;
std::string maxLenName;
protected:
TypeQualifier (bool _isPtr, char _c, const std::string & _lenName, const std::string & _maxLenName) :
b_IsPtr(_isPtr), lenName(_lenName), maxLenName(_maxLenName) {
switch (_c) {
case (C_NULL) :
b_CtorAllocatesMemory = false;
b_ParserAllocatesMemory = true;
b_ParserUsesMSList = false;
b_DtorReleasesMemory = true;
break;
case (C_PTR) :
b_CtorAllocatesMemory = false;
b_ParserAllocatesMemory = false;
b_ParserUsesMSList = true;
b_DtorReleasesMemory = false;
break;
case (C_MSLIST) :
b_CtorAllocatesMemory = false;
b_ParserAllocatesMemory = true;
b_ParserUsesMSList = true;
b_DtorReleasesMemory = false;
break;
default :
throw std::logic_error (std::string("TypeQualifier::TypeQualifier() called with unknown memory management spec, \'")
+ _c + "\'");
break;
};
}
public:
bool isPtr() const {return b_IsPtr;}
bool isArray() const {return isFixedArray() || isVarArray(); }
bool isFixedArray() const {return !maxLenName.empty(); }
bool isVarArray() const {return (maxLenName.empty() && !b_IsPtr); }
std::string getLenName() const {return lenName;}
void setLenName (const std::string & _lenName) {
if (b_IsPtr) throw std::logic_error ("TypeQualifier::setLenName() called on ptr type.");
if (isFixedArray()) throw std::logic_error ("TypeQualifier::setLenName() called on fixed array type.");
lenName = _lenName;
}
std::string getMaxLenName() const {return maxLenName;}
};
class TypeQualifierPtr : public TypeQualifier {
public:
TypeQualifierPtr(char _c =C_NULL) : TypeQualifier (true, _c, "", "") {};
};
class TypeQualifierFixedArray : public TypeQualifier {
public:
TypeQualifierFixedArray (const std::string & _maxLenName, const std::string & _varLenName ="") :
TypeQualifier (false, C_NULL, _varLenName, _maxLenName) {}
};
class TypeQualifierVarArray : public TypeQualifier {
public:
TypeQualifierVarArray (const std::string & _varLenName ="", char _c =C_NULL) :
TypeQualifier (false, _c, _varLenName, "") {}
};
class MDataMemberInfo : public NamedObject { // name is that of the variable
friend int yyparse();
friend class MDataTypeInfo;
public:
typedef gen::CountedPtr<MDataMemberInfo> Ptr;
private:
int b_IsConst;
int b_IsHidden;
DataTypeInfo::Ptr typePtr; // data type
std::vector<TypeQualifier> typeQuals; // data type's qualifiers
std::string defVal; // default value of the member
MDataVisualInfo visInfo; // visual info
std::vector<std::string> comments; // associated comment info
static void printDecDefine (std::ostream & os, const std::string & _name, const std::string & _val);
static void printDecOneLine (std::ostream & os, const std::string & _type, const std::string & _name);
static std::ostream & indent (std::ostream & os, int indentCount);
public:
MDataMemberInfo (const std::string & _name, int _isConst, int _isHidden,
const std::string & _typeName, const std::vector<TypeQualifier> & _typeQuals,
const std::string & _defVal, const MDataVisualInfo & _visInfo,
const std::vector<std::string> & _comments);
bool isConst() const {return b_IsConst;}
bool isHidden() const {return b_IsHidden;}
std::string getCPPQualTypeName () const;
std::string getCPPConstRef () const;
std::string getCPPDefaultVal () const;
std::string getJQualTypeName () const;
DataTypeInfo::Ptr getTypePtr() const {return typePtr;}
std::string getLenNameAtLevel (std::vector<TypeQualifier>::size_type level);
std::string getMaxLenNameAtLevel (std::vector<TypeQualifier>::size_type level);
std::string getSzName (const std::string & szNameBase, std::vector<TypeQualifier>::size_type level) const;
void printCDeclaration (std::ostream & os, std::vector<std::string> & usedLenNames, const std::string & className) const;
void printCTokPut (std::ostream & os, const std::string & buffPtrName,
const std::string & buffEndPtrName, const std::string & structPtrName,
int & loopVarCount, int & errCodeCount,
const std::string & varName, std::vector<TypeQualifier>::size_type level) const;
void printCTokGet (std::ostream & os, const std::string & buffPtrName,
const std::string & memHndlName, const std::string & structPtrName,
int & loopVarCount, int & errCodeCount,
std::vector<std::string> & usedLenNames, bool & useTmp,
const std::string & varName, std::vector<TypeQualifier>::size_type level) const;
void printCCopy (std::ostream & os,
const std::string & copyStructPtrName, const std::string & origStructPtrName,
const std::string & memHndlName,
int & loopVarCount, std::vector<std::string> & usedLenNames,
const std::string & copyVarName, const std::string & origVarName,
std::vector<TypeQualifier>::size_type level) const;
void printCOstrmPrint (std::ostream & os, const std::string & ostrmPtrName,
const std::string & structPtrName, int & loopVarCount,
const std::string & nameVarName, const std::string & varName,
std::vector<TypeQualifier>::size_type level) const;
void printCSTreePut (std::ostream & os, const std::string & streePtrName,
const std::string & structPtrName, int & loopVarCount,
const std::string & nameVarName, const std::string & varName,
std::vector<TypeQualifier>::size_type level) const;
void printCSTreeGet (std::ostream & os, const std::string & streePtrName,
const std::string & structPtrName, const std::string & memHndlName, int & loopVarCount,
std::vector<std::string> & usedLenNames, const std::string & nameVarName,
const std::string & varName, std::vector<TypeQualifier>::size_type level) const;
void printCPPDeclaration (std::ostream & os) const;
void printCPPIntDef (std::ostream & os,
const bool autoSetMsgFlag = false,
const std::string & msgFlagVarName = "", const std::string flagConstName = "") const;
void printJDeclaration (std::ostream & os) const;
void printJIntDef (std::ostream & os, const std::string & this_str ="this",
const bool autoSetMsgFlag = false,
const std::string & msgFlagVarName = "", const std::string flagConstName = "") const;
};
// holds instance of " [control] mdata name {mdata_info} "
class MDataQualifier; // early declaration
class MDataTypeInfo : public UserDefinedTypeInfo {
public:
const static std::string STR_NEXT; // "next" (variable name used for link mdata's pointer to itself)
const static std::string STR_REQID; // "reqid" (variable name used for request id)
enum Flag {FLAG_NONE=0x00, FLAG_IS_CONTROL=0x01, FLAG_IS_LINK=0x02,
FLAG_IS_INNER=0x04, FLAG_IS_VISUAL=0x08, FLAG_IS_FORMAT=0x10};
enum Component {COMP_NONE=0x00, COMP_SERVICE=0x01};
private:
typedef UserDefinedTypeInfo Base;
public:
typedef gen::CountedPtr<MDataTypeInfo> Ptr;
private:
static stringPtrMap<Ptr> store;
void setCName() { Base::setCName("mdat_" + getName()); }
void setCTok () { Base::setCTok('X'); };
void setCPPName() { Base::setCPPName("MDat_" + getName()); }