2
Copyright (c) 2009, 2010 mingw-w64 project
4
Contributing authors: Kai Tietz, Jonathan Yong
6
Permission is hereby granted, free of charge, to any person obtaining a
7
copy of this software and associated documentation files (the "Software"),
8
to deal in the Software without restriction, including without limitation
9
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
and/or sell copies of the Software, and to permit persons to whom the
11
Software is furnished to do so, subject to the following conditions:
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
35
static uMToken *m_combine (sMSCtx *c, uMToken *l, uMToken *r);
36
static uMToken *m_type (sMSCtx *c, const char *typname);
37
static uMToken *m_cv (sMSCtx *c, const char *cv);
38
static uMToken *m_coloncolon (sMSCtx *c, uMToken *l, uMToken *r);
39
static uMToken *m_element (sMSCtx *c, uMToken *el);
40
static uMToken *m_array (sMSCtx *c, uMToken *dim);
41
static uMToken *m_scope (sMSCtx *c, uMToken *n);
42
static uMToken *m_oper (sMSCtx *c, uMToken *n);
43
static uMToken *m_name (sMSCtx *c, const char *str);
44
static uMToken *m_colon (sMSCtx *c, const char *str);
45
static uMToken *m_opname (sMSCtx *c, const char *str);
46
static uMToken *m_rtti (sMSCtx *c, const char *str);
47
static uMToken *m_frame (sMSCtx *c, uMToken *u);
48
static uMToken *m_rframe (sMSCtx *c, uMToken *u);
49
static uMToken *m_ltgt (sMSCtx *c, uMToken *u);
50
static uMToken *m_throw (sMSCtx *c, uMToken *u);
51
static uMToken *m_lexical_frame (sMSCtx *c, uMToken *u);
53
static uMToken *get_decorated_name (sMSCtx *c);
54
static uMToken *get_string_literal_type (sMSCtx *c);
55
static uMToken *get_symbol_name (sMSCtx *c);
56
static uMToken *get_zbuf_name (sMSCtx *c, int updateCache);
57
static uMToken *get_dimension_signed (sMSCtx *c);
58
static uMToken *get_dimension (sMSCtx *c,int fSigned, int fNegate);
59
static uMToken *extract_name (sMSCtx *c, char term);
60
static uMToken *get_scope (sMSCtx *c);
61
static uMToken *get_template_name (sMSCtx *c, int fReadTerminator);
62
static uMToken *get_operator_name (sMSCtx *c, int fIsTemplate, int *pfReadTemplateArguments);
63
static uMToken *get_template_argument_list (sMSCtx *c);
64
static uMToken *get_lexical_frame(sMSCtx *c);
65
static uMToken *get_string_encoding (sMSCtx *c, int wantBody);
66
static uMToken *get_template_constant (sMSCtx *c);
67
static uMToken *get_data_type (sMSCtx *c);
68
static uMToken *get_indirect_data_type(sMSCtx *c, uMToken *superType, char prType, uMToken *cvType, int thisFlag);
69
static uMToken *get_primary_data_type (sMSCtx *c, uMToken *superType);
70
static uMToken *get_based_type (sMSCtx *c);
71
static uMToken *get_scoped_name (sMSCtx *c);
72
static uMToken *get_basic_data_type (sMSCtx *c, uMToken *superName);
73
static uMToken *get_pointer_reference_type (sMSCtx *c, uMToken *cvType, uMToken *superType, char ptrChar);
74
static uMToken *get_indirect_function_type (sMSCtx *c, uMToken *superType);
75
static uMToken *get_pointer_reference_data_type (sMSCtx *c, uMToken *superType,int isPtr);
76
static uMToken *get_ECSU_data_type (sMSCtx *c);
77
static uMToken *get_enum_size_type (sMSCtx *c);
78
static uMToken *get_this_type (sMSCtx *c);
79
static uMToken *get_calling_convention (sMSCtx *c);
80
static uMToken *get_throw_types (sMSCtx *c);
81
static uMToken *get_argument_types (sMSCtx *c);
82
static uMToken *get_return_type (sMSCtx *c);
83
static uMToken *get_array_type (sMSCtx *c, uMToken *superType);
84
static uMToken *get_argument_list (sMSCtx *c);
85
static uMToken *compose_decl (sMSCtx *c, uMToken *symbol);
86
static uMToken *get_vftable_type (sMSCtx *c, uMToken *superType);
87
static int get_number_of_dimensions (sMSCtx *c);
88
static int get_encoded_type (sMSCtx *);
89
static uMToken *get_vdisp_map_type (sMSCtx *c, uMToken *superType);
90
static uMToken *get_ext_data_type (sMSCtx *c, uMToken *superType);
93
decode_ms_name (sGcCtx *gc, const char *name)
96
sCached ZNameList, ArgList, TempArgList;
98
if (!name || *name == 0)
101
memset (&ctx, 0, sizeof (ctx));
103
memset (&ZNameList, 0, sizeof (ZNameList));
104
memset (&ArgList, 0, sizeof (ArgList));
105
memset (&TempArgList, 0, sizeof (TempArgList));
107
ctx.end = name + strlen (name);
110
ctx.pZNameList = &ZNameList;
111
ctx.pArgList = &ArgList;
112
ctx.pTemplateArgList = &TempArgList;
114
fprintf(stderr,"decode_ms_name: %s\n", name);
121
ret = get_decorated_name (&ctx);
124
else if (name[1] == '$')
126
if (!(ret = get_template_name (&ctx, 0)))
127
ret = get_decorated_name (&ctx);
130
ret = get_decorated_name (&ctx);
133
ret = get_decorated_name (&ctx);
137
ret = gen_name (ctx.gc, eMST_unmangled, name);
144
encode_ms_name (sGcCtx *gc, uMToken *tok)
150
get_decorated_name (sMSCtx *c)
155
if (GET_CHAR (c) != '?')
157
if (GET_CHAR (c) == 0)
159
fprintf (stderr,"*** get_decorated_name %s empty\n", c->name);
164
n = get_symbol_name (c);
165
isudc = (n && (MTOKEN_FLAGS (n) & MTOKEN_FLAGS_UDC)) ? 1 : 0;
168
if (GET_CHAR (c) != 0 && GET_CHAR (c) != '@')
173
if (c->fExplicitTemplateParams == 0)
174
n = m_coloncolon (c, d, n);
177
c->fExplicitTemplateParams = 0;
178
n = m_combine (c, n, d);
179
if (GET_CHAR (c) != '@')
182
n = m_coloncolon (c, d, n);
190
MTOKEN_FLAGS (n) |= MTOKEN_FLAGS_UDC;
191
if (MTOKEN_FLAGS (n) & MTOKEN_FLAGS_NOTE)
193
if (GET_CHAR (c) != 0)
195
if (GET_CHAR (c) != '@')
199
return compose_decl (c, n);
204
get_symbol_name (sMSCtx *c)
206
if (GET_CHAR (c) != '?')
207
return get_zbuf_name (c, 1);
208
if (c->pos[1] == '$')
209
return get_template_name (c, 1);
211
return get_operator_name (c, 0, NULL);
215
get_zbuf_name (sMSCtx *c, int updateCache)
218
uMToken *dim, *ret = NULL, *n = NULL;
220
if (GET_CHAR(c) >= '0' && GET_CHAR (c) <= '9')
222
ret = c->pZNameList->arr[GET_CHAR (c) - '0'];
226
if (GET_CHAR (c) == '?')
228
n = get_template_name (c, 0);
229
if (GET_CHAR (c) == '@')
231
if (updateCache && c->pZNameList->count < 10)
233
c->pZNameList->arr[c->pZNameList->count] = n;
234
c->pZNameList->count += 1;
238
ntmp="template-parameter-";
239
if (!strncmp(c->pos,"template-parameter-",19))
243
ntmp="generic-type-";
244
if (!strncmp(c->pos, "generic-type-", 13))
248
n = extract_name (c, '@');
249
if (updateCache && c->pZNameList->count < 10)
251
c->pZNameList->arr[c->pZNameList->count] = n;
252
c->pZNameList->count += 1;
257
dim=get_dimension_signed (c);
258
n=chain_tok (gen_name (c->gc, eMST_templargname, ntmp), dim);
259
if (updateCache && c->pZNameList->count < 10)
261
c->pZNameList->arr[c->pZNameList->count] = n;
262
c->pZNameList->count += 1;
268
get_dimension_signed (sMSCtx *c)
270
if (GET_CHAR (c) == 0)
275
if (GET_CHAR (c) != '?')
276
return get_dimension (c, 0, 0);
278
return get_dimension (c, 0, 1/* be negative*/);
282
get_dimension (sMSCtx *c, int fSigned, int fNegate)
284
const char *non_tt_param=NULL;
285
uint64_t v_r = 0ULL, v1;
287
if (GET_CHAR (c) == 'Q')
290
non_tt_param="'non-type-template-parameter";
292
if (GET_CHAR (c) == 0)
297
if (GET_CHAR (c) >= '0' && GET_CHAR (c) <= '9')
299
uint64_t v = (uint64_t) ((GET_CHAR (c)-'0') + 1);
301
return gen_dim (c->gc, eMST_dim,v, non_tt_param, fSigned, fNegate);
304
while (GET_CHAR (c) != '@')
306
if (GET_CHAR (c) == 0)
311
if (GET_CHAR (c) < 'A' || GET_CHAR (c) > 'P')
316
v1=(uint64_t) (GET_CHAR (c) - 'A');
317
v_r = v_r*10ULL + v1;
320
if (GET_CHAR (c) !='@')
326
return gen_dim (c->gc, eMST_dim,v_r, non_tt_param, fSigned, fNegate);
330
extract_name (sMSCtx *c, char term)
335
const char *sv = c->pos;
336
while (GET_CHAR (c) != 0 && GET_CHAR (c) != term)
340
if (GET_CHAR (c) != '@')
345
len = (size_t) (c->pos - sv);
346
txt = (char *) malloc (len + 1);
347
memcpy (txt, sv, len);
350
ret = m_name (c, txt);
356
get_scope (sMSCtx *c)
362
if (GET_CHAR (c) == 0 || GET_CHAR (c) == '@')
364
if (c->fExplicitTemplateParams != 0 && !c->fGetTemplateArgumentList)
366
if (GET_CHAR (c) == '?')
369
if (GET_CHAR (c) == '$')
372
n = m_coloncolon (c, get_zbuf_name (c, 1), n);
374
else if (GET_CHAR (c) == '%' || GET_CHAR (c) == 'A')
376
while (GET_CHAR (c) != '@')
379
n = m_coloncolon (c, m_name (c, "anonymous_namespace"), n);
381
else if (GET_CHAR (c) == '?')
383
if (c->pos[1] == '_' && c->pos[2] == '?')
386
n = m_coloncolon (c, get_operator_name (c, 0,NULL), n);
387
if (GET_CHAR (c) == '@')
392
n = m_coloncolon (c, gen_unary (c->gc, eMST_slashed, get_decorated_name (c)), n);
395
else if (GET_CHAR (c) == 'I')
398
n = m_coloncolon (c, m_array (c, get_zbuf_name (c, 1)), n);
401
n = m_coloncolon (c, get_lexical_frame (c), n);
404
n = m_coloncolon (c, get_zbuf_name (c, 1), n);
410
if (GET_CHAR (c) == '@')
422
get_template_name (sMSCtx *c, int fReadTerminator)
427
sCached *svZName,*svArgList,*svTempArgList;
431
if (GET_CHAR (c) !='?' || c->pos[1] != '$')
433
memset (&rep1, 0, sizeof (rep1));
434
memset (&rep2, 0, sizeof (rep2));
435
memset (&rep3, 0, sizeof (rep3));
437
svTempArgList = c->pTemplateArgList;
438
svArgList = c->pArgList;
439
svZName = c->pZNameList;
445
c->pTemplateArgList=&rep3;
447
if (GET_CHAR (c) == '?')
450
n = get_operator_name (c, 1, &fFlag);
453
n = get_zbuf_name (c, 1);
455
c->fExplicitTemplateParams = 1;
458
n = get_template_argument_list (c);
463
c->pArgList = svArgList;
464
c->pZNameList = svZName;
465
c->pTemplateArgList = svTempArgList;
470
get_operator_name (sMSCtx *c, int fIsTemplate, int *pfReadTemplateArguments)
473
char ch = GET_CHAR (c);
474
uMToken *n = NULL,*h = NULL;
487
h = m_ltgt (c, get_template_argument_list (c));
488
if (pfReadTemplateArguments)
489
*pfReadTemplateArguments = 1;
492
return m_oper (c, h);
496
n = get_zbuf_name (c, 0);
499
n=gen_unary (c->gc, eMST_destructor, n);
500
n = chain_tok (n, h);
501
return m_oper (c, n);
503
return m_oper (c, m_opname (c, "operator new"));
505
return m_oper (c, m_opname (c, "operator delete"));
507
return m_oper (c, m_opname (c, "operator ="));
509
return m_oper (c, m_opname (c, "operator >>"));
511
return m_oper (c, m_opname (c, "operator <<"));
513
return m_oper (c, m_opname (c, "operator !"));
515
return m_oper (c, m_opname (c, "operator =="));
517
return m_oper (c, m_opname (c, "operator !="));
519
return m_oper (c, m_opname (c, "operator []"));
521
n = m_opname (c, "operator");
522
MTOKEN_FLAGS(n) |= MTOKEN_FLAGS_UDC;
524
MTOKEN_FLAGS(n) |= MTOKEN_FLAGS_UDC;
527
return m_oper (c, m_opname (c, "operator ->"));
529
return m_oper (c, m_opname (c, "operator *"));
531
return m_oper (c, m_opname (c, "operator ++"));
533
return m_oper (c, m_opname (c, "operator --"));
535
return m_oper (c, m_opname (c, "operator -"));
537
return m_oper (c, m_opname (c, "operator +"));
539
return m_oper (c, m_opname (c, "operator &"));
541
return m_oper (c, m_opname (c, "operator ->*"));
543
return m_oper (c, m_opname (c, "operator /"));
545
return m_oper (c, m_opname (c, "operator %"));
547
return m_oper (c, m_opname (c, "operator <"));
549
return m_oper (c, m_opname (c, "operator <="));
551
return m_oper (c, m_opname (c, "operator >"));
553
return m_oper (c, m_opname (c, "operator >="));
555
return m_oper (c, m_opname (c, "operator ,"));
557
return m_oper (c, m_opname (c, "operator ()"));
559
return m_oper (c, m_opname (c, "operator ~"));
561
return m_oper (c, m_opname (c, "operator ^"));
563
return m_oper (c, m_opname (c, "operator |"));
565
return m_oper (c, m_opname (c, "operator &&"));
567
return m_oper (c, m_opname (c, "operator ||"));
569
return m_oper (c, m_opname (c, "operator *="));
571
return m_oper (c, m_opname (c, "operator +="));
573
return m_oper (c, m_opname (c, "operator -="));
577
fprintf (stderr, " *** get_operator_name unknown '%c'\n", ch);
595
return m_oper (c, m_opname (c, "__man_vec_ctor"));
597
return m_oper (c, m_opname (c, "__man_vec_dtor"));
599
return m_oper (c, m_opname (c, "__ehvec_copy_ctor"));
601
return m_oper (c, m_opname (c, "__ehvec_copy_ctor_vb"));
603
fprintf (stderr, " *** get_operator_name unknown '__%c'\n", ch);
607
return m_oper (c, m_opname (c, "operator /="));
609
return m_oper (c, m_opname (c, "operator %="));
611
return m_oper (c, m_opname (c, "operator >>="));
613
return m_oper (c, m_opname (c, "operator <<="));
615
return m_oper (c, m_opname (c, "operator &="));
617
return m_oper (c, m_opname (c, "operator |="));
619
return m_oper (c, m_opname (c, "operator ^="));
621
return m_oper (c, gen_name (c->gc, eMST_vftable, "$vftable"));
623
return m_oper (c, gen_name (c->gc, eMST_vbtable, "$vbtable"));
625
return m_oper (c, gen_name (c->gc, eMST_vcall, "vcall"));
627
return m_oper (c, m_opname (c,"typeof"));
629
return m_oper (c, m_opname (c,"local_static_guard"));
631
n = get_string_encoding (c, 1);
632
MTOKEN_FLAGS(n) |= MTOKEN_FLAGS_NOTE;
635
return m_oper (c, m_opname (c,"vbase_destructor"));
637
return m_oper (c, m_opname (c,"__vecDelDtor"));
639
return m_oper (c, m_opname (c,"__dflt_ctor_closure"));
641
return m_oper (c, m_opname (c, "__delDtor"));
643
return m_oper (c, m_opname (c, "__vec_ctor"));
645
return m_oper (c, m_opname (c, "__vec_dtor"));
647
return m_oper (c, m_opname (c, "__vec_ctor_vb"));
649
return m_oper (c, m_opname (c, "$vdispmap"));
651
return m_oper (c, m_opname (c, "__ehvec_ctor"));
653
return m_oper (c, m_opname (c, "__ehvec_dtor"));
655
return m_oper (c, m_name (c, "__ehvec_ctor_vb"));
657
return m_oper (c, m_opname (c, "__copy_ctor_closure"));
659
return gen_unary (c->gc, eMST_udt_returning, get_operator_name (c, 0, NULL));
661
return m_oper (c, m_opname (c, "operator 'EH'"));
668
h = m_rtti (c, "$type_descriptor");
669
return m_oper (c, m_combine (c, get_data_type (c) , h));
671
h = m_rtti (c, "base_class_descriptor");
672
n = m_element (c, get_dimension_signed (c));
673
n = chain_tok (n, m_element (c, get_dimension_signed (c)));
674
n = chain_tok (n, m_element (c, get_dimension_signed (c)));
675
n = chain_tok (n, m_element (c, get_dimension (c, 0, 0)));
677
return m_oper (c, gen_binary (c->gc, eMST_assign, h, n));
679
return m_oper (c, m_rtti (c, "base_class_array"));
681
return m_oper (c, m_rtti (c, "class_hierarchy_descriptor"));
683
return m_oper (c, m_rtti (c, "complete_object_locator"));
686
fprintf (stderr, " *** Unkown RTTI %c\n", ch);
690
return m_oper (c, m_opname (c, "$locvftable"));
692
return m_oper (c, m_opname (c, "__local_vftable_ctor_closure"));
694
n = m_opname (c, "operator new[]");
695
return m_oper (c, n);
697
n = m_opname (c, "operator delete[]");
698
return m_oper (c, n);
699
case 'W': /* omni callsig ??? */
701
fprintf (stderr, " *** get_operator_name unknown '_%c'\n", ch);
704
return m_oper (c, m_opname (c, "__placement_delete_closure"));
706
return m_oper (c, m_opname (c, "__placement_arrayDelete_closure"));
720
m_combine (c, m_name (c, "using namespace"), get_string_encoding (c, 0));
721
MTOKEN_FLAGS (n) |= MTOKEN_FLAGS_NOTE;
724
fprintf (stderr, " *** get_operator_name unknown '__?%c'\n", ch);
729
get_template_argument_list (sMSCtx *c)
735
c->fGetTemplateArgumentList = 1;
738
if (GET_CHAR (c) == 0 || GET_CHAR (c) == '@')
740
idx = (int) (GET_CHAR (c) - '0');
741
if (GET_CHAR (c) >= '0' && GET_CHAR (c) <= '9')
743
h = c->pTemplateArgList->arr[idx];
748
const char *svPos = c->pos;
749
if (GET_CHAR (c) =='X')
752
h = m_type (c, "void");
754
else if (GET_CHAR (c) == '$' && c->pos[1] != '$')
757
h = get_template_constant (c);
759
else if (GET_CHAR (c) == '?')
761
uMToken *sdim = get_dimension_signed (c);
762
h = gen_binary (c->gc, eMST_templateparam, m_name (c, "template-parameter"), sdim);
765
h = get_primary_data_type (c, NULL);
766
if ((int)(c->pos-svPos)>1 &&
767
c->pTemplateArgList->count < 10)
769
c->pTemplateArgList->arr[c->pTemplateArgList->count] = h;
770
c->pTemplateArgList->count += 1;
773
h = m_element (c, h);
781
n = chain_tok (n, h);
785
c->fGetTemplateArgumentList = 0;
787
n = gen_unary (c->gc, eMST_template_argument_list, n);
792
get_lexical_frame (sMSCtx *c)
794
return m_lexical_frame (c, get_dimension (c, 0, 0));
798
get_string_encoding (sMSCtx *c, int wantBody)
800
uMToken *length = NULL;
801
uMToken *crc = NULL, *h = NULL;
807
if (GET_CHAR (c) != '@') return NULL;
809
typ = get_string_literal_type (c);
810
length = get_dimension (c, 0, 0);
811
crc = get_dimension (c, 0, 0);
812
if (GET_CHAR (c) == 0)
818
while (GET_CHAR (c) != 0)
820
if (GET_CHAR (c) == '@')
824
if (GET_CHAR (c) == 0)
829
len = (size_t) (c->pos - svName);
830
hp = (char *) malloc (len + 1);
831
memcpy (hp, svName, len);
837
h = m_combine (c, typ, m_combine (c, h, m_array (c, length)));
842
get_template_constant (sMSCtx *c)
856
return get_decorated_name (c);
857
if (ch > 'E' && ch <= 'J')
859
if (ch >= 'H' && ch <= 'J')
861
exp = m_element (c, get_decorated_name (c));
863
else chain_tok (n, exp);
868
exp = m_element (c, get_dimension_signed (c));
870
else chain_tok (n, exp);
872
exp = m_element (c, get_dimension_signed (c));
874
else chain_tok (n, exp);
876
exp = m_element (c, get_dimension_signed (c));
878
else chain_tok (n, exp);
881
return m_frame (c, n);
883
if (ch == 'Q' || ch == 'D')
885
n = get_dimension_signed (c);
887
return gen_binary (c->gc, eMST_templateparam, m_name (c, "template-parameter"), n);
888
return gen_binary (c->gc, eMST_nonetypetemplateparam, m_name (c, "none-type-template-parameter"), n);
891
return get_dimension_signed (c);
894
if (GET_CHAR (c) != '@')
895
return m_combine (c, m_cv (c, "&"), get_decorated_name (c));
897
return m_name (c, "NULL");
901
fprintf (stderr, " *** get_template_constant unknown '%c'\n", ch);
904
n = get_dimension_signed (c);
905
exp = get_dimension_signed (c);
906
return gen_binary (c->gc, eMST_exp, n, exp);
910
get_data_type (sMSCtx *c)
913
if (GET_CHAR (c) == 0)
918
if (GET_CHAR (c) == '?')
921
n = get_indirect_data_type (c, n, (char)0, NULL, 0);
922
return get_primary_data_type (c, n);
924
if (GET_CHAR (c) != 'X')
925
return get_primary_data_type (c, n);
927
return m_combine (c, m_type (c, "void"), n);
931
get_indirect_data_type (sMSCtx *c, uMToken *superType, char prType, uMToken *cvType, int thisFlag)
933
uMToken *n = NULL, *n1 = NULL, *n2 = NULL;
936
if (GET_CHAR (c) == 0)
947
if (MTOKEN_FLAGS (superType) & MTOKEN_FLAGS_PTRREF)
951
return m_combine (c, cvType, superType);
953
if (GET_CHAR (c) == '$')
956
if (GET_CHAR (c) == 'A')
958
n = m_cv (c, "__gc");
961
else if (GET_CHAR (c) == 'B')
963
n = m_cv (c, "__pin");
968
state = (int)(GET_CHAR (c) - '3')*16;
970
state += (int)GET_CHAR (c);
972
n = gen_value (c->gc, eMST_gcarray, (uint64_t) state, 0, 4);
975
if (!(MTOKEN_FLAGS (superType) & MTOKEN_FLAGS_ARRAY))
976
superType = m_rframe (c, superType);
977
n=m_combine (c, superType, n);
983
state = (GET_CHAR (c) - (GET_CHAR (c) < 'A' ? 0x16 : 0x41));
987
n1 = m_combine (c, n1, m_cv (c, "__ptr64"));
989
n2 = m_combine (c, n2, m_cv (c, "__unaligned"));
998
else if (prType == '&')
1001
ret = m_combine (c, n ,ret);
1002
ret = m_combine (c, ret, n1);
1003
ret = m_combine (c, n2, ret);
1004
if ((state & 0x10) != 0)
1010
if (GET_CHAR (c) == 0)
1018
ret = gen_binary (c->gc, eMST_coloncolon , get_scope (c), ret);
1020
ret = get_scope (c);
1022
if (GET_CHAR (c) == 0) c->err = 2;
1025
char ch = GET_CHAR (c);
1031
else if (GET_CHAR (c) == 0)
1035
ret = get_scope (c);
1036
if (GET_CHAR (c) != 0)
1038
char ch = GET_CHAR (c);
1047
if ((state&0xc)==0xc)
1051
ret = m_combine (c, get_based_type (c), ret);
1053
if ((state & 2) != 0)
1054
ret = m_combine (c, m_cv (c, "volatile"), ret);
1055
if ((state & 1) != 0)
1056
ret = m_combine (c, m_cv (c, "const"), ret);
1060
ret = m_name (c, "");
1061
MTOKEN_FLAGS(ret) |= MTOKEN_FLAGS_PTRREF;
1067
ret = m_combine (c, ret, cvType);
1069
ret = m_name (c, "");
1070
MTOKEN_FLAGS(ret) |= MTOKEN_FLAGS_PTRREF;
1073
if (MTOKEN_FLAGS(superType) & MTOKEN_FLAGS_PTRREF)
1077
ret = m_combine (c, ret, cvType);
1078
ret = m_combine (c, ret, superType);
1079
MTOKEN_FLAGS(ret) |= MTOKEN_FLAGS_PTRREF;
1083
if (!(MTOKEN_FLAGS(superType)&MTOKEN_FLAGS_ARRAY))
1084
ret = m_combine (c, ret, superType);
1087
MTOKEN_FLAGS(ret) |= MTOKEN_FLAGS_PTRREF;
1093
n1 = m_cv (c, "__restrict");
1095
n1 = m_combine (c, n1, m_cv (c, "__restrict"));
1098
state=GET_CHAR (c)-(GET_CHAR (c) < 'A' ? 0x16 : 0x41);
1103
get_primary_data_type (sMSCtx *c, uMToken *superType)
1105
uMToken *superName = NULL;
1106
uMToken *cvType = NULL;
1107
switch(GET_CHAR (c))
1113
cvType = m_cv (c, "volatile");
1116
superName = superType;
1118
superName = m_name (c, "");
1119
MTOKEN_FLAGS (superName) |= MTOKEN_FLAGS_PTRREF;
1121
return get_pointer_reference_type (c, cvType, superName, '&');
1123
if (c->pos[1] == '$')
1133
fprintf (stderr, " *** get_primary_data_type '$%c' unknown\n", c->pos[1]);
1136
return get_basic_data_type (c, superType);
1138
switch(GET_CHAR (c))
1145
return get_indirect_function_type (c, superType);
1148
return get_pointer_reference_data_type (c, superType, 1);
1151
return get_basic_data_type (c, get_indirect_data_type (c, superType, (char)0, superName, 0));
1153
fprintf (stderr, " *** get_primary_data_type '$$%c' unknown\n", GET_CHAR (c));
1158
get_based_type (sMSCtx *c)
1160
uMToken *n = m_cv (c, "__based");
1164
if (GET_CHAR (c) == 0)
1167
return gen_binary (c->gc, eMST_based, n, NULL);
1174
p = m_type (c, "void");
1177
p = get_scoped_name (c);
1180
fprintf (stderr, " *** get_based_type unknown '%c'\n", ch);
1183
fprintf (stderr, " *** get_based_type unknown '%c' (ignored)\n", ch);
1186
return gen_binary (c->gc, eMST_based, n, p);
1190
get_scoped_name (sMSCtx *c)
1193
n = get_zbuf_name (c, 1);
1194
if (n && GET_CHAR (c) != 0)
1196
if (GET_CHAR (c) =='@')
1201
n = m_coloncolon (c, get_scope (c), n);
1203
if (GET_CHAR (c) == '@')
1208
if (GET_CHAR (c) != 0)
1215
get_basic_data_type (sMSCtx *c, uMToken *superName)
1217
uMToken *bTyp = NULL;
1218
uMToken *cvName = NULL;
1219
uMToken *arType = NULL;
1220
uMToken *tmp = NULL;
1221
char svChar,svChar1;
1224
if (GET_CHAR (c) == 0)
1229
svChar1 = GET_CHAR (c);
1235
bTyp = m_type (c, "float");
1238
bTyp = m_type (c, "signed char");
1241
bTyp = m_type (c, "char");
1244
bTyp = m_type (c, "unsigned char");
1247
bTyp = m_type (c, "short");
1250
bTyp = m_type (c, "unsigned short");
1253
bTyp = m_type (c, "int");
1256
bTyp = m_type (c, "unsigned int");
1259
bTyp = m_type (c, "long");
1262
bTyp = m_type (c, "unsigned long");
1265
bTyp = m_type (c, "double");
1268
bTyp = m_type (c, "long double");
1271
return get_pointer_reference_type (c, bTyp, superName, '*');
1274
bTyp = m_cv (c, "const");
1275
return get_pointer_reference_type (c, bTyp, superName, '*');
1278
bTyp = m_cv (c, "volatile");
1279
return get_pointer_reference_type (c, bTyp, superName, '*');
1283
bTyp = m_cv (c, "const");
1284
bTyp = m_combine (c, bTyp, m_cv (c, "volatile"));
1286
return get_pointer_reference_type (c, bTyp, superName, '*');
1288
svChar = GET_CHAR (c);
1293
bTyp = m_type (c, "bool");
1297
superName = m_name (c, "");
1299
MTOKEN_FLAGS (cvName) |= MTOKEN_FLAGS_ARRAY;
1300
arType = get_pointer_reference_type (c, bTyp, cvName, 0);
1301
if (!(MTOKEN_FLAGS (arType)&MTOKEN_FLAGS_ARRAY))
1302
arType = m_combine (c, arType, m_array (c, NULL));
1305
bTyp = m_type (c, "wchar_t");
1310
if (!(bTyp = get_ECSU_data_type (c)))
1314
bTyp = m_type (c, "__int8");
1317
bTyp = m_type (c, "unsigned __int8");
1320
bTyp = m_type (c, "__int16");
1323
bTyp = m_type (c, "unsigned __int16");
1326
bTyp = m_type (c, "__int32");
1329
bTyp = m_type (c, "unsigned __int32");
1332
bTyp = m_type (c, "__int64");
1335
bTyp = m_type (c, "unsigned __int64");
1338
bTyp = m_type (c, "__int128");
1341
bTyp = m_type (c, "unsigned");
1344
bTyp = get_basic_data_type (c, superName);
1345
return m_combine (c, m_cv (c, "__w64"), bTyp);
1347
fprintf (stderr, " *** get_basic_data_type unknown '_%c' (ignored).\n", svChar);
1348
bTyp = m_type (c, "UNKNOWN");
1354
bTyp = get_ECSU_data_type (c);
1360
bTyp = m_combine (c, bTyp, superName);
1365
get_pointer_reference_type (sMSCtx *c, uMToken *cvType, uMToken *superType, char ptrChar)
1370
else if (ptrChar == '*')
1372
if (GET_CHAR (c) == 0)
1380
n = m_combine (c, n, cvType);
1383
n = m_combine (c, n, superType);
1386
if (GET_CHAR (c) < '6' || GET_CHAR (c) > '9')
1388
if (GET_CHAR (c) != '_')
1389
return get_pointer_reference_data_type (c,
1390
get_indirect_data_type (c, superType, ptrChar, cvType, 0),(ptrChar=='*' ? 1 : 0));
1394
if (!superType || !(MTOKEN_FLAGS (superType)&MTOKEN_FLAGS_PTRREF))
1399
n = m_combine (c, n, cvType);
1407
n = m_combine (c, n, superType);
1409
return get_indirect_function_type (c, n);
1413
get_indirect_function_type (sMSCtx *c, uMToken *superType)
1415
uMToken *retType = NULL;
1416
uMToken *n1 = NULL, *n2 = NULL;
1419
char ch = GET_CHAR (c);
1425
if (ch != '_' && (ch < '6' || ch > '9'))
1427
cidx = (int) (ch - '6');
1437
if (ch < 'A' || ch > 'D')
1439
cidx=(int)(ch - 'A') + 4;
1452
n2 = m_coloncolon (c, get_scope (c), n2);
1453
if (GET_CHAR (c) == 0)
1458
if (GET_CHAR (c) != '@')
1461
n1 = get_this_type (c);
1464
n2 = m_combine (c, get_based_type (c), n2);
1465
n2 = m_combine (c, get_calling_convention (c), n2);
1467
n2 = m_rframe (c, n2);
1468
retType = get_return_type (c);
1469
n2 = m_combine (c, n2, m_rframe (c, get_argument_types (c)));
1471
n2 = m_combine (c, n2, n1);
1472
n2 = m_combine (c, n2, get_throw_types (c));
1473
return m_combine (c, retType, n2);
1477
get_pointer_reference_data_type (sMSCtx *c, uMToken *superType,int isPtr)
1480
if (GET_CHAR (c) == 0)
1486
if (isPtr && GET_CHAR (c) == 'X')
1489
n = m_type (c, "void");
1491
n = m_combine (c, n, superType);
1494
if (GET_CHAR (c) == 'Y')
1497
return get_array_type (c, superType);
1499
if (GET_CHAR (c) != '_')
1500
return get_basic_data_type (c, superType);
1501
if (c->pos[1] != 'Z')
1502
return get_basic_data_type (c, superType);
1504
n = m_cv (c, "__box");
1505
return m_combine (c, n, get_basic_data_type (c, superType));
1509
get_ECSU_data_type (sMSCtx *c)
1511
char ch = GET_CHAR (c);
1517
return m_type (c, "no-ecsu");
1523
fprintf (stderr, " *** get_ECSU_data_type unknown %c\n", ch);
1524
n = m_type (c, "unknown ecsu");
1527
n = m_type (c, "union");
1530
n = m_type (c, "struct");
1533
n = m_type (c, "class");
1536
n = m_type (c, "enum");
1537
get_enum_size_type (c);
1540
n = m_type (c, "coclass");
1543
n = m_type (c, "cointerface");
1546
return gen_binary (c->gc, eMST_ecsu, n, get_scoped_name (c));
1550
get_string_literal_type (sMSCtx *c)
1553
char ch = GET_CHAR (c);
1562
n = m_cv (c, "const");
1565
if (GET_CHAR (c) == 0)
1574
return m_combine (c, n, m_type (c, "char"));
1576
return m_combine (c, n, m_type (c, "wchar_t"));
1578
fprintf (stderr, " *** get_string_literal_type unknown '_%c'\n", ch);
1583
get_enum_size_type (sMSCtx *c)
1586
switch (GET_CHAR (c))
1592
n = m_type (c, "char");
1595
n = m_type (c, "unsigned char");
1598
n = m_type (c, "short");
1601
n = m_type (c, "unsigned short");
1604
n = m_type (c, "int");
1607
n = m_type (c, "unsigned int");
1610
n = m_type (c, "long");
1613
n = m_type (c, "unsigned long");
1616
fprintf (stderr, " *** get_enum_size_type unknown ,%c'\n", GET_CHAR (c));
1624
get_this_type (sMSCtx *c)
1626
return get_indirect_data_type (c, NULL, (char)0, NULL, 1);
1630
get_calling_convention (sMSCtx *c)
1632
char ch = GET_CHAR (c);
1643
return m_cv (c, "__cdecl");
1645
return m_cv (c, "__pascal");
1647
return m_cv (c, "__thiscall");
1649
return m_cv (c, "__stdcall");
1651
return m_cv (c, "__fastcall");
1653
return m_cv (c, "");
1655
return m_cv (c, "__clrcall");
1657
fprintf (stderr, " *** get_calling_convention ,%c' unknown.\n", ch);
1662
get_throw_types (sMSCtx *c)
1664
if (GET_CHAR (c) == 0)
1667
return m_throw (c, m_rframe (c, NULL));
1669
if (GET_CHAR (c) == 'Z')
1672
return m_name (c, "");
1674
return m_throw (c, m_rframe (c, get_argument_types (c)));
1678
get_argument_types (sMSCtx *c)
1680
char ch = GET_CHAR (c);
1686
return m_element (c, m_type (c, "void"));
1691
return m_element (c, m_type (c, "..."));
1693
n = get_argument_list (c);
1696
if (GET_CHAR (c) == 0)
1701
if (GET_CHAR (c) == '@')
1706
if (GET_CHAR (c) == 'Z')
1709
return chain_tok (n, m_element (c, m_type (c, "...")));
1711
fprintf (stderr, " *** get_argument_types unknown ,%c'\n", GET_CHAR (c));
1716
get_return_type (sMSCtx *c)
1718
if (GET_CHAR (c) == '@')
1721
return m_name (c, "");
1723
return get_data_type (c);
1727
get_number_of_dimensions (sMSCtx *c)
1732
if (GET_CHAR (c) >= '0' && GET_CHAR (c) <= '9')
1734
ret = (int) (GET_CHAR (c) - '0') + 1;
1738
while (GET_CHAR (c) != '@')
1740
if (GET_CHAR (c) == 0)
1742
if (GET_CHAR (c) < 'A' || GET_CHAR (c) > 'P')
1745
ret += (int) (GET_CHAR (c) - 'A');
1748
if (GET_CHAR (c) == '@')
1757
get_array_type (sMSCtx *c, uMToken *superType)
1759
uMToken *n = NULL, *h = NULL;
1762
if (GET_CHAR (c) == 0)
1766
return m_combine (c, m_rframe (c, superType), m_array (c, NULL));
1767
return m_array (c, NULL);
1769
dims = get_number_of_dimensions (c);
1775
return get_basic_data_type (c, m_array (c, NULL));
1777
if (superType && (MTOKEN_FLAGS(superType)&MTOKEN_FLAGS_ARRAY))
1778
h = m_array (c, NULL);
1780
n = m_array (c, get_dimension (c, 0, 0));
1784
h = m_combine (c, h, n);
1785
} while (--dims != 0);
1788
if (!(MTOKEN_FLAGS(superType)&MTOKEN_FLAGS_ARRAY))
1789
superType = m_rframe (c, superType);
1790
h = m_combine (c, superType, h);
1792
n = get_primary_data_type (c, h);
1793
MTOKEN_FLAGS (n) |= MTOKEN_FLAGS_ARRAY;
1798
get_argument_list (sMSCtx *c)
1800
uMToken *n = NULL, *h = NULL;
1807
if (GET_CHAR (c) == '@' || GET_CHAR (c) == 'Z')
1809
if (GET_CHAR (c) == 0)
1814
idx= (int) (GET_CHAR (c) - '0');
1815
if (idx < 0 || idx > 9)
1817
const char *svName = c->pos;
1818
h = get_primary_data_type (c, NULL);
1819
if ((size_t) (c->pos - svName)>1 && c->pArgList->count < 10)
1821
c->pArgList->arr[c->pArgList->count]=h;
1822
c->pArgList->count += 1;
1828
h = c->pArgList->arr[idx];
1830
h = m_element (c, h);
1831
n = chain_tok (n, h);
1832
} while (c->err != 2);
1837
get_vdisp_map_type (sMSCtx *c, uMToken *superType)
1839
uMToken *n = superType;
1840
uMToken *h = get_scope (c);
1841
h = m_combine (c, m_name (c, "for"), h);
1843
n = m_combine (c, n, h);
1844
if (GET_CHAR (c) =='@')
1850
get_ext_data_type (sMSCtx *c, uMToken *superType)
1852
uMToken *dt = NULL,*n = NULL;
1853
dt = get_data_type (c);
1854
n = get_indirect_data_type (c, NULL, (char)0, NULL, 0);
1856
n = m_combine (c, n, superType);
1858
return m_combine (c, dt, n);
1861
static uMToken *getVCallThunkType(sMSCtx *c)
1863
if (GET_CHAR (c) == 0)
1868
if (GET_CHAR (c) != 'A')
1870
fprintf (stderr, " *** getVCallThunkType unknown '%c'\n", GET_CHAR (c));
1874
return m_cv (c, "{flat}");
1878
get_vftable_type (sMSCtx *c, uMToken *superType)
1880
uMToken *n = superType;
1881
if (c->err || GET_CHAR (c) == 0)
1886
n = m_combine (c, get_indirect_data_type (c, NULL, (char)0, NULL, 0), n);
1887
if (c->err == 2 || !n)
1889
if (GET_CHAR (c) != '@')
1891
n = m_combine (c, n, m_name (c, "{for "));
1894
if (GET_CHAR (c) ==0 || GET_CHAR (c) =='@')
1896
n = m_combine (c, n, m_lexical_frame (c, get_scope (c)));
1897
if (GET_CHAR (c) == '@')
1899
if (c->err == 0 && GET_CHAR (c) != '@')
1900
n = m_combine (c, n, m_name (c, "s "));
1904
if (GET_CHAR (c) == 0)
1906
n = m_combine (c, n, m_name (c, "}"));
1908
if (GET_CHAR (c) != '@')
1916
compose_decl (sMSCtx *c, uMToken *symbol)
1919
int et = get_encoded_type (c);
1920
int nIsUDC = (symbol && (MTOKEN_FLAGS (symbol) & MTOKEN_FLAGS_UDC)) ? 1 : 0;
1933
if ((et&0x7c00)==0x6800)
1934
return get_vftable_type (c, n);
1935
if ((et&0x7c00)==0x7000)
1936
return get_vftable_type (c, n);
1937
if ((et&0x7c00)==0x6000)
1939
uMToken *ll = m_element (c, get_dimension (c, 0, 0));
1940
ll = m_frame (c, ll);
1941
return m_combine (c, n, ll);
1943
if ((et&0x7c00)==0x7c00)
1944
return get_vdisp_map_type (c, n);
1945
if ((et&0x7c00)==0x7800)
1947
n = get_ext_data_type (c, n);
1951
n = m_combine (c, m_colon (c, "[thunk]"), n);
1954
n = m_combine (c, m_cv (c, "static"), n);
1955
if ((et&0x700) == 0x400 || (et&0x700) == 0x500)
1956
n = m_combine (c, m_cv (c, "virtual"), n);
1957
switch ((et&0x1800))
1960
n = m_combine (c, m_colon (c, "private"), n);
1963
n = m_combine (c, m_colon (c, "protected"), n);
1966
n = m_combine (c, m_colon (c, "public"), n);
1970
n = m_combine (c, m_colon (c, "[thunk]"), n);
1973
if ((et&0x1f00)==0x1000 || (et&0x1f00)==0x1400)
1976
if ((et&0x6000)!=0 || (et&0x7f00)==0x1400)
1977
n = m_combine (c, n, m_name (c, "local_static_destructor_helper"));
1978
n = get_ext_data_type (c, n);
1981
else if ((et&0x1f00)==0x1500 || (et&0x1f00)==0x1600)
1985
if ((et&0x1f00)==0x1500)
1986
n = m_combine (c, n, m_name (c, "template_static_data_member_constructor_helper"));
1987
else if ((et&0x1f00)==0x1600)
1988
n = m_combine (c, n, m_name (c, "template_static_data_member_destructor_helper"));
1993
n = get_based_type (c);
1994
if ((et&0x1800)==0x1800)
1997
hh = m_element (c, get_dimension (c, 0, 0));
1998
hh = chain_tok (hh, m_element (c, getVCallThunkType (c)));
1999
n = m_combine (c, symbol,
2001
n = m_combine (c, get_calling_convention (c), n);
2009
if ((et&0x1000)!=0 || (et&0x1c00)==0xc00)
2011
if ((et&0x1f00)==0xd00)
2012
n1 = get_dimension (c, 1, 0);
2013
n2 = get_dimension (c, 1, 0);
2015
if (((et&0x1800)==0x800) && (et&0x700)!=0x200)
2016
n3 = get_this_type (c);
2017
n = m_combine (c, get_calling_convention (c), n);
2019
n = m_combine (c, n, symbol);
2022
n = m_combine (c, n, get_return_type (c));
2023
h = get_return_type (c);
2024
if (((et&0x1800)!=0x800 ? (et&0x1000)!=0 : (et&0x400)!=0))
2026
if (((et&0x1800)==0x800) && (et&0x700)==0x500)
2031
n2 = m_frame (c, n2);
2032
n = m_combine (c, n, m_combine (c, m_name (c, "vtordisp"), n2));
2036
n2 = m_frame (c, m_element (c, n2));
2037
n = m_combine (c, n, m_combine (c, m_name (c, "adjustor"), n2));
2040
n = m_combine (c, n, m_rframe (c, get_argument_types (c)));
2041
if (((et&0x1800)==0x800) && (et&0x700)!=0x200)
2042
n = m_combine (c, n, n3);
2043
n = m_combine (c, n, get_throw_types (c));
2045
n = m_combine (c, h, n);
2048
if ((et&0x1800)!=0x800) {
2050
n = m_combine (c, m_colon (c, "[thunk]"), n);
2056
n = m_combine (c, m_cv (c, "static"), n);
2061
n = m_combine (c, m_cv (c, "virtual"), n);
2067
n = m_combine (c, m_colon (c, "private"), n);
2070
n = m_combine (c, m_colon (c, "protected"), n);
2073
n = m_combine (c, m_colon (c, "public"), n);
2077
n = m_combine (c, m_colon (c, "[thunk]"), n);
2082
get_encoded_type (sMSCtx *c)
2089
if (GET_CHAR (c) == '_')
2094
if (GET_CHAR (c) >= 'A' && GET_CHAR (c) <= 'Z')
2096
int chc = (int) (GET_CHAR (c) - 'A');
2129
if (GET_CHAR (c) != '$')
2162
switch(GET_CHAR (c))
2201
if (c->pos[1] == 'P')
2208
switch(GET_CHAR (c))
2210
case 'F': case 'G': case 'H': case 'I': case 'L': case 'M':
2213
case 'J': case 'K': case 'N': case 'O':
2215
if (GET_CHAR (c) < '0' || GET_CHAR (c) > '9')
2221
int skip = (GET_CHAR (c) - '0') + 1;
2222
SKIP_CHAR (c, skip);
2233
m_combine (sMSCtx *c, uMToken *l, uMToken *r)
2241
return gen_binary (c->gc, eMST_combine, l, r);
2245
m_type (sMSCtx *c, const char *typname)
2247
return gen_name (c->gc, eMST_type, typname);
2251
m_cv (sMSCtx *c, const char *cv)
2253
return gen_name (c->gc, eMST_cv, cv);
2257
m_coloncolon (sMSCtx *c, uMToken *l, uMToken *r)
2263
return gen_binary (c->gc, eMST_coloncolon, l, r);
2267
m_element (sMSCtx *c, uMToken *el)
2269
return gen_unary (c->gc, eMST_element, el);
2273
m_array (sMSCtx *c, uMToken *dim)
2275
return gen_unary (c->gc, eMST_array, dim);
2279
m_scope (sMSCtx *c, uMToken *n)
2281
return gen_unary (c->gc, eMST_scope, n);
2285
m_oper (sMSCtx *c, uMToken *n)
2287
return gen_unary (c->gc, eMST_oper, n);
2291
m_name (sMSCtx *c, const char *str)
2293
return gen_name (c->gc, eMST_name, str);
2297
m_colon (sMSCtx *c, const char *str)
2299
return gen_name (c->gc, eMST_colon, str);
2303
m_opname (sMSCtx *c, const char *str)
2305
return gen_name (c->gc, eMST_opname, str);
2309
m_rtti (sMSCtx *c, const char *str)
2311
return gen_name (c->gc, eMST_rtti, str);
2315
m_frame (sMSCtx *c, uMToken *u)
2317
return gen_unary (c->gc, eMST_frame, u);
2321
m_rframe (sMSCtx *c, uMToken *u)
2323
return gen_unary (c->gc, eMST_rframe, u);
2327
m_ltgt (sMSCtx *c, uMToken *u)
2329
return gen_unary (c->gc, eMST_ltgt, u);
2333
m_throw (sMSCtx *c, uMToken *u)
2335
return gen_unary (c->gc, eMST_throw, u);
2339
m_lexical_frame (sMSCtx *c, uMToken *u)
2341
return gen_unary (c->gc, eMST_lexical_frame, u);