forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasmparse.y
2076 lines (1858 loc) · 153 KB
/
asmparse.y
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
%{
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// File asmparse.y
//
#include "ilasmpch.h"
#include "grammar_before.cpp"
%}
%union {
CorRegTypeAttr classAttr;
CorMethodAttr methAttr;
CorFieldAttr fieldAttr;
CorMethodImpl implAttr;
CorEventAttr eventAttr;
CorPropertyAttr propAttr;
CorPinvokeMap pinvAttr;
CorDeclSecurity secAct;
CorFileFlags fileAttr;
CorAssemblyFlags asmAttr;
CorAssemblyFlags asmRefAttr;
CorTypeAttr exptAttr;
CorManifestResourceFlags manresAttr;
double* float64;
__int64* int64;
__int32 int32;
char* string;
BinStr* binstr;
Labels* labels;
Instr* instr; // instruction opcode
NVPair* pair;
pTyParList typarlist;
mdToken token;
TypeDefDescr* tdd;
CustomDescr* cad;
unsigned short opcode;
};
/* These are returned by the LEXER and have values */
%token ERROR_ BAD_COMMENT_ BAD_LITERAL_ /* bad strings, */
%token <string> ID /* testing343 */
%token <string> DOTTEDNAME /* System.Object */
%token <binstr> QSTRING /* "Hello World\n" */
%token <string> SQSTRING /* 'Hello World\n' */
%token <int32> INT32 /* 3425 0x34FA 0352 */
%token <int64> INT64 /* 342534523534534 0x34FA434644554 */
%token <float64> FLOAT64 /* -334234 24E-34 */
%token <int32> HEXBYTE /* 05 1A FA */
%token <tdd> TYPEDEF_T
%token <tdd> TYPEDEF_M
%token <tdd> TYPEDEF_F
%token <tdd> TYPEDEF_TS
%token <tdd> TYPEDEF_MR
%token <tdd> TYPEDEF_CA
/* multi-character punctuation */
%token DCOLON /* :: */
%token ELLIPSIS /* ... */
/* Keywords Note the undersores are to avoid collisions as these are common names */
%token VOID_ BOOL_ CHAR_ UNSIGNED_ INT_ INT8_ INT16_ INT32_ INT64_ FLOAT_ FLOAT32_ FLOAT64_ BYTEARRAY_
%token UINT_ UINT8_ UINT16_ UINT32_ UINT64_ FLAGS_ CALLCONV_ MDTOKEN_
%token OBJECT_ STRING_ NULLREF_
/* misc keywords */
%token DEFAULT_ CDECL_ VARARG_ STDCALL_ THISCALL_ FASTCALL_ CLASS_ BYREFLIKE_
%token TYPEDREF_ UNMANAGED_ FINALLY_ HANDLER_ CATCH_ FILTER_ FAULT_
%token EXTENDS_ IMPLEMENTS_ TO_ AT_ TLS_ TRUE_ FALSE_ _INTERFACEIMPL
/* class, method, field attributes */
%token VALUE_ VALUETYPE_ NATIVE_ INSTANCE_ SPECIALNAME_ FORWARDER_
%token STATIC_ PUBLIC_ PRIVATE_ FAMILY_ FINAL_ SYNCHRONIZED_ INTERFACE_ SEALED_ NESTED_
%token ABSTRACT_ AUTO_ SEQUENTIAL_ EXPLICIT_ ANSI_ UNICODE_ AUTOCHAR_ IMPORT_ ENUM_
%token VIRTUAL_ NOINLINING_ AGGRESSIVEINLINING_ NOOPTIMIZATION_ AGGRESSIVEOPTIMIZATION_ UNMANAGEDEXP_ BEFOREFIELDINIT_
%token STRICT_ RETARGETABLE_ WINDOWSRUNTIME_ NOPLATFORM_
%token METHOD_ FIELD_ PINNED_ MODREQ_ MODOPT_ SERIALIZABLE_ PROPERTY_ TYPE_
%token ASSEMBLY_ FAMANDASSEM_ FAMORASSEM_ PRIVATESCOPE_ HIDEBYSIG_ NEWSLOT_ RTSPECIALNAME_ PINVOKEIMPL_
%token _CTOR _CCTOR LITERAL_ NOTSERIALIZED_ INITONLY_ REQSECOBJ_
/* method implementation attributes: NATIVE_ and UNMANAGED_ listed above */
%token CIL_ OPTIL_ MANAGED_ FORWARDREF_ PRESERVESIG_ RUNTIME_ INTERNALCALL_
/* PInvoke-specific keywords */
%token _IMPORT NOMANGLE_ LASTERR_ WINAPI_ AS_ BESTFIT_ ON_ OFF_ CHARMAPERROR_
/* instruction tokens (actually instruction groupings) */
%token <opcode> INSTR_NONE INSTR_VAR INSTR_I INSTR_I8 INSTR_R INSTR_BRTARGET INSTR_METHOD INSTR_FIELD
%token <opcode> INSTR_TYPE INSTR_STRING INSTR_SIG INSTR_TOK
%token <opcode> INSTR_SWITCH
/* assember directives */
%token _CLASS _NAMESPACE _METHOD _FIELD _DATA _THIS _BASE _NESTER
%token _EMITBYTE _TRY _MAXSTACK _LOCALS _ENTRYPOINT _ZEROINIT
%token _EVENT _ADDON _REMOVEON _FIRE _OTHER
%token _PROPERTY _SET _GET DEFAULT_
%token _PERMISSION _PERMISSIONSET
/* security actions */
%token REQUEST_ DEMAND_ ASSERT_ DENY_ PERMITONLY_ LINKCHECK_ INHERITCHECK_
%token REQMIN_ REQOPT_ REQREFUSE_ PREJITGRANT_ PREJITDENY_ NONCASDEMAND_
%token NONCASLINKDEMAND_ NONCASINHERITANCE_
/* extern debug info specifier (to be used by precompilers only) */
%token _LINE P_LINE _LANGUAGE
/* custom value specifier */
%token _CUSTOM
/* local vars zeroinit specifier */
%token INIT_
/* class layout */
%token _SIZE _PACK
%token _VTABLE _VTFIXUP FROMUNMANAGED_ CALLMOSTDERIVED_ _VTENTRY RETAINAPPDOMAIN_
/* manifest */
%token _FILE NOMETADATA_ _HASH _ASSEMBLY _PUBLICKEY _PUBLICKEYTOKEN ALGORITHM_ _VER _LOCALE EXTERN_
%token _MRESOURCE
%token _MODULE _EXPORT
%token LEGACY_ LIBRARY_ X86_ AMD64_ ARM_ ARM64_
/* field marshaling */
%token MARSHAL_ CUSTOM_ SYSSTRING_ FIXED_ VARIANT_ CURRENCY_ SYSCHAR_ DECIMAL_ DATE_ BSTR_ TBSTR_ LPSTR_
%token LPWSTR_ LPTSTR_ OBJECTREF_ IUNKNOWN_ IDISPATCH_ STRUCT_ SAFEARRAY_ BYVALSTR_ LPVOID_ ANY_ ARRAY_ LPSTRUCT_
%token IIDPARAM_
/* parameter keywords */
%token IN_ OUT_ OPT_
/* .param directive */
%token _PARAM
/* method implementations */
%token _OVERRIDE WITH_
/* variant type specifics */
%token NULL_ ERROR_ HRESULT_ CARRAY_ USERDEFINED_ RECORD_ FILETIME_ BLOB_ STREAM_ STORAGE_
%token STREAMED_OBJECT_ STORED_OBJECT_ BLOB_OBJECT_ CF_ CLSID_ VECTOR_
/* header flags */
%token _SUBSYSTEM _CORFLAGS ALIGNMENT_ _IMAGEBASE _STACKRESERVE
/* syntactic sugar */
%token _TYPEDEF _TEMPLATE _TYPELIST _MSCORLIB
/* compilation control directives */
%token P_DEFINE P_UNDEF P_IFDEF P_IFNDEF P_ELSE P_ENDIF P_INCLUDE
/* newly added tokens go here */
%token CONSTRAINT_ TYPECHECK_ RANGECHECK_ NULLCHECK_
/* nonTerminals */
%type <string> dottedName id methodName atOpt slashedName
%type <labels> labels
%type <int32> callConv callKind int32 customHead customHeadWithOwner vtfixupAttr paramAttr ddItemCount variantType repeatOpt truefalse typarAttrib typarAttribs
%type <int32> iidParamIndex genArity genArityNotEmpty
%type <float64> float64
%type <int64> int64
%type <int32> noCheckOptGroup noCheckOpt
%type <binstr> sigArgs0 sigArgs1 sigArg type bound bounds1 bytes hexbytes nativeType marshalBlob initOpt compQstring caValue
%type <binstr> marshalClause
%type <binstr> fieldInit serInit fieldSerInit
%type <binstr> f32seq f64seq i8seq i16seq i32seq i64seq boolSeq sqstringSeq classSeq objSeq
%type <binstr> simpleType
%type <binstr> tyArgs0 tyArgs1 tyArgs2 typeList typeListNotEmpty tyBound
%type <binstr> customBlobDescr serializType customBlobArgs customBlobNVPairs
%type <binstr> secAttrBlob secAttrSetBlob
%type <int32> fieldOrProp intOrWildcard
%type <typarlist> typarsRest typars typarsClause
%type <token> className typeSpec ownerType customType memberRef methodRef mdtoken
%type <classAttr> classAttr
%type <methAttr> methAttr
%type <fieldAttr> fieldAttr
%type <implAttr> implAttr
%type <eventAttr> eventAttr
%type <propAttr> propAttr
%type <pinvAttr> pinvAttr
%type <pair> nameValPairs nameValPair
%type <secAct> secAction
%type <secAct> psetHead
%type <fileAttr> fileAttr
%type <fileAttr> fileEntry
%type <asmAttr> asmAttr
%type <exptAttr> exptAttr
%type <manresAttr> manresAttr
%type <cad> customDescr customDescrWithOwner
%type <instr> instr_none instr_var instr_i instr_i8 instr_r instr_brtarget instr_method instr_field
%type <instr> instr_type instr_string instr_sig instr_tok instr_switch
%type <instr> instr_r_head
%start decls
/**************************************************************************/
%%
decls : /* EMPTY */
| decls decl
;
/* Module-level declarations */
decl : classHead '{' classDecls '}' { PASM->EndClass(); }
| nameSpaceHead '{' decls '}' { PASM->EndNameSpace(); }
| methodHead methodDecls '}' { if(PASM->m_pCurMethod->m_ulLines[1] ==0)
{ PASM->m_pCurMethod->m_ulLines[1] = PASM->m_ulCurLine;
PASM->m_pCurMethod->m_ulColumns[1]=PASM->m_ulCurColumn;}
PASM->EndMethod(); }
| fieldDecl
| dataDecl
| vtableDecl
| vtfixupDecl
| extSourceSpec
| fileDecl
| assemblyHead '{' assemblyDecls '}' { PASMM->EndAssembly(); }
| assemblyRefHead '{' assemblyRefDecls '}' { PASMM->EndAssembly(); }
| exptypeHead '{' exptypeDecls '}' { PASMM->EndComType(); }
| manifestResHead '{' manifestResDecls '}' { PASMM->EndManifestRes(); }
| moduleHead
| secDecl
| customAttrDecl
| _SUBSYSTEM int32 {
#ifdef _PREFAST_
#pragma warning(push)
#pragma warning(disable:22011) // Suppress PREFast warning about integer overflow/underflow
#endif
PASM->m_dwSubsystem = $2;
#ifdef _PREFAST_
#pragma warning(pop)
#endif
}
| _CORFLAGS int32 { PASM->m_dwComImageFlags = $2; }
| _FILE ALIGNMENT_ int32 { PASM->m_dwFileAlignment = $3;
if(($3 & ($3 - 1))||($3 < 0x200)||($3 > 0x10000))
PASM->report->error("Invalid file alignment, must be power of 2 from 0x200 to 0x10000\n");}
| _IMAGEBASE int64 { PASM->m_stBaseAddress = (ULONGLONG)(*($2)); delete $2;
if(PASM->m_stBaseAddress & 0xFFFF)
PASM->report->error("Invalid image base, must be 0x10000-aligned\n");}
| _STACKRESERVE int64 { PASM->m_stSizeOfStackReserve = (size_t)(*($2)); delete $2; }
| languageDecl
| typedefDecl
| compControl
| _TYPELIST '{' classNameSeq '}'
| _MSCORLIB { PASM->m_fIsMscorlib = TRUE; }
;
classNameSeq : /* EMPTY */
| className classNameSeq
;
compQstring : QSTRING { $$ = $1; }
| compQstring '+' QSTRING { $$ = $1; $$->append($3); delete $3; }
;
languageDecl : _LANGUAGE SQSTRING { LPCSTRToGuid($2,&(PASM->m_guidLang)); }
| _LANGUAGE SQSTRING ',' SQSTRING { LPCSTRToGuid($2,&(PASM->m_guidLang));
LPCSTRToGuid($4,&(PASM->m_guidLangVendor));}
| _LANGUAGE SQSTRING ',' SQSTRING ',' SQSTRING { LPCSTRToGuid($2,&(PASM->m_guidLang));
LPCSTRToGuid($4,&(PASM->m_guidLangVendor));
LPCSTRToGuid($4,&(PASM->m_guidDoc));}
;
/* Basic tokens */
id : ID { $$ = $1; }
| SQSTRING { $$ = $1; }
;
dottedName : id { $$ = $1; }
| DOTTEDNAME { $$ = $1; }
| dottedName '.' dottedName { $$ = newStringWDel($1, '.', $3); }
;
int32 : INT32 { $$ = $1; }
;
int64 : INT64 { $$ = $1; }
| INT32 { $$ = neg ? new __int64($1) : new __int64((unsigned)$1); }
;
float64 : FLOAT64 { $$ = $1; }
| FLOAT32_ '(' int32 ')' { float f; *((__int32*) (&f)) = $3; $$ = new double(f); }
| FLOAT64_ '(' int64 ')' { $$ = (double*) $3; }
;
noCheckOpt : TYPECHECK_ { $$ = 0x01; }
| RANGECHECK_ { $$ = 0x02; }
| NULLCHECK_ { $$ = 0x04; }
;
noCheckOptGroup : noCheckOpt { $$ = $1; }
| noCheckOpt noCheckOptGroup { $$ = $1 | $2; }
;
/* Aliasing of types, type specs, methods, fields and custom attributes */
typedefDecl : _TYPEDEF type AS_ dottedName { PASM->AddTypeDef($2,$4); }
| _TYPEDEF className AS_ dottedName { PASM->AddTypeDef($2,$4); }
| _TYPEDEF memberRef AS_ dottedName { PASM->AddTypeDef($2,$4); }
| _TYPEDEF customDescr AS_ dottedName { $2->tkOwner = 0; PASM->AddTypeDef($2,$4); }
| _TYPEDEF customDescrWithOwner AS_ dottedName { PASM->AddTypeDef($2,$4); }
;
/* Compilation control directives are processed within yylex(),
displayed here just for grammar completeness */
compControl : P_DEFINE dottedName { DefineVar($2, NULL); }
| P_DEFINE dottedName compQstring { DefineVar($2, $3); }
| P_UNDEF dottedName { UndefVar($2); }
| P_IFDEF dottedName { SkipToken = !IsVarDefined($2);
IfEndif++;
}
| P_IFNDEF dottedName { SkipToken = IsVarDefined($2);
IfEndif++;
}
| P_ELSE { if(IfEndif == 1) SkipToken = !SkipToken;}
| P_ENDIF { if(IfEndif == 0)
PASM->report->error("Unmatched #endif\n");
else IfEndif--;
}
| P_INCLUDE QSTRING { _ASSERTE(!"yylex should have dealt with this"); }
| ';' { }
;
/* Custom attribute declarations */
customDescr : _CUSTOM customType { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, NULL); }
| _CUSTOM customType '=' compQstring { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, $4); }
| _CUSTOM customType '=' '{' customBlobDescr '}' { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, $5); }
| customHead bytes ')' { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $1, $2); }
;
customDescrWithOwner : _CUSTOM '(' ownerType ')' customType { $$ = new CustomDescr($3, $5, NULL); }
| _CUSTOM '(' ownerType ')' customType '=' compQstring { $$ = new CustomDescr($3, $5, $7); }
| _CUSTOM '(' ownerType ')' customType '=' '{' customBlobDescr '}'
{ $$ = new CustomDescr($3, $5, $8); }
| customHeadWithOwner bytes ')' { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $1, $2); }
;
customHead : _CUSTOM customType '=' '(' { $$ = $2; bParsingByteArray = TRUE; }
;
customHeadWithOwner : _CUSTOM '(' ownerType ')' customType '=' '('
{ PASM->m_pCustomDescrList = NULL;
PASM->m_tkCurrentCVOwner = $3;
$$ = $5; bParsingByteArray = TRUE; }
;
customType : methodRef { $$ = $1; }
;
ownerType : typeSpec { $$ = $1; }
| memberRef { $$ = $1; }
;
/* Verbal description of custom attribute initialization blob */
customBlobDescr : customBlobArgs customBlobNVPairs { $$ = $1;
$$->appendInt16(VAL16(nCustomBlobNVPairs));
$$->append($2);
nCustomBlobNVPairs = 0; }
;
customBlobArgs : /* EMPTY */ { $$ = new BinStr(); $$->appendInt16(VAL16(0x0001)); }
| customBlobArgs serInit { $$ = $1;
AppendFieldToCustomBlob($$,$2); }
| customBlobArgs compControl { $$ = $1; }
;
customBlobNVPairs : /* EMPTY */ { $$ = new BinStr(); }
| customBlobNVPairs fieldOrProp serializType dottedName '=' serInit
{ $$ = $1; $$->appendInt8($2);
$$->append($3);
AppendStringWithLength($$,$4);
AppendFieldToCustomBlob($$,$6);
nCustomBlobNVPairs++; }
| customBlobNVPairs compControl { $$ = $1; }
;
fieldOrProp : FIELD_ { $$ = SERIALIZATION_TYPE_FIELD; }
| PROPERTY_ { $$ = SERIALIZATION_TYPE_PROPERTY; }
;
customAttrDecl : customDescr { if($1->tkOwner && !$1->tkInterfacePair)
PASM->DefineCV($1);
else if(PASM->m_pCustomDescrList)
PASM->m_pCustomDescrList->PUSH($1); }
| customDescrWithOwner { PASM->DefineCV($1); }
| TYPEDEF_CA { CustomDescr* pNew = new CustomDescr($1->m_pCA);
if(pNew->tkOwner == 0) pNew->tkOwner = PASM->m_tkCurrentCVOwner;
if(pNew->tkOwner)
PASM->DefineCV(pNew);
else if(PASM->m_pCustomDescrList)
PASM->m_pCustomDescrList->PUSH(pNew); }
;
serializType : simpleType { $$ = $1; }
| TYPE_ { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE); }
| OBJECT_ { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TAGGED_OBJECT); }
| ENUM_ CLASS_ SQSTRING { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_ENUM);
AppendStringWithLength($$,$3); }
| ENUM_ className { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_ENUM);
AppendStringWithLength($$,PASM->ReflectionNotation($2)); }
| serializType '[' ']' { $$ = $1; $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
;
/* Module declaration */
moduleHead : _MODULE { PASMM->SetModuleName(NULL); PASM->m_tkCurrentCVOwner=1; }
| _MODULE dottedName { PASMM->SetModuleName($2); PASM->m_tkCurrentCVOwner=1; }
| _MODULE EXTERN_ dottedName { BinStr* pbs = new BinStr();
unsigned L = (unsigned)strlen($3);
memcpy((char*)(pbs->getBuff(L)),$3,L);
PASM->EmitImport(pbs); delete pbs;}
;
/* VTable Fixup table declaration */
vtfixupDecl : _VTFIXUP '[' int32 ']' vtfixupAttr AT_ id { /*PASM->SetDataSection(); PASM->EmitDataLabel($7);*/
PASM->m_VTFList.PUSH(new VTFEntry((USHORT)$3, (USHORT)$5, $7)); }
;
vtfixupAttr : /* EMPTY */ { $$ = 0; }
| vtfixupAttr INT32_ { $$ = $1 | COR_VTABLE_32BIT; }
| vtfixupAttr INT64_ { $$ = $1 | COR_VTABLE_64BIT; }
| vtfixupAttr FROMUNMANAGED_ { $$ = $1 | COR_VTABLE_FROM_UNMANAGED; }
| vtfixupAttr CALLMOSTDERIVED_ { $$ = $1 | COR_VTABLE_CALL_MOST_DERIVED; }
| vtfixupAttr RETAINAPPDOMAIN_ { $$ = $1 | COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN; }
;
vtableDecl : vtableHead bytes ')' /* deprecated */ { PASM->m_pVTable = $2; }
;
vtableHead : _VTABLE '=' '(' /* deprecated */ { bParsingByteArray = TRUE; }
;
/* Namespace and class declaration */
nameSpaceHead : _NAMESPACE dottedName { PASM->StartNameSpace($2); }
;
_class : _CLASS { newclass = TRUE; }
;
classHeadBegin : _class classAttr dottedName typarsClause { if($4) FixupConstraints();
PASM->StartClass($3, $2, $4);
TyParFixupList.RESET(false);
newclass = FALSE;
}
;
classHead : classHeadBegin extendsClause implClause { PASM->AddClass(); }
;
classAttr : /* EMPTY */ { $$ = (CorRegTypeAttr) 0; }
| classAttr PUBLIC_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdPublic); }
| classAttr PRIVATE_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNotPublic); }
| classAttr VALUE_ { $$ = (CorRegTypeAttr) ($1 | 0x80000000 | tdSealed); }
| classAttr ENUM_ { $$ = (CorRegTypeAttr) ($1 | 0x40000000); }
| classAttr INTERFACE_ { $$ = (CorRegTypeAttr) ($1 | tdInterface | tdAbstract); }
| classAttr SEALED_ { $$ = (CorRegTypeAttr) ($1 | tdSealed); }
| classAttr ABSTRACT_ { $$ = (CorRegTypeAttr) ($1 | tdAbstract); }
| classAttr AUTO_ { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdAutoLayout); }
| classAttr SEQUENTIAL_ { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdSequentialLayout); }
| classAttr EXPLICIT_ { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdExplicitLayout); }
| classAttr ANSI_ { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdAnsiClass); }
| classAttr UNICODE_ { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdUnicodeClass); }
| classAttr AUTOCHAR_ { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdAutoClass); }
| classAttr IMPORT_ { $$ = (CorRegTypeAttr) ($1 | tdImport); }
| classAttr SERIALIZABLE_ { $$ = (CorRegTypeAttr) ($1 | tdSerializable); }
| classAttr WINDOWSRUNTIME_ { $$ = (CorRegTypeAttr) ($1 | tdWindowsRuntime); }
| classAttr NESTED_ PUBLIC_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedPublic); }
| classAttr NESTED_ PRIVATE_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedPrivate); }
| classAttr NESTED_ FAMILY_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamily); }
| classAttr NESTED_ ASSEMBLY_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedAssembly); }
| classAttr NESTED_ FAMANDASSEM_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamANDAssem); }
| classAttr NESTED_ FAMORASSEM_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamORAssem); }
| classAttr BEFOREFIELDINIT_ { $$ = (CorRegTypeAttr) ($1 | tdBeforeFieldInit); }
| classAttr SPECIALNAME_ { $$ = (CorRegTypeAttr) ($1 | tdSpecialName); }
| classAttr RTSPECIALNAME_ { $$ = (CorRegTypeAttr) ($1); }
| classAttr FLAGS_ '(' int32 ')' { $$ = (CorRegTypeAttr) ($4); }
;
extendsClause : /* EMPTY */
| EXTENDS_ typeSpec { PASM->m_crExtends = $2; }
;
implClause : /* EMPTY */
| IMPLEMENTS_ implList
;
classDecls : /* EMPTY */
| classDecls classDecl
;
implList : implList ',' typeSpec { PASM->AddToImplList($3); }
| typeSpec { PASM->AddToImplList($1); }
;
/* Generic type parameters declaration */
typeList : /* EMPTY */ { $$ = new BinStr(); }
| typeListNotEmpty { $$ = $1; }
;
typeListNotEmpty : typeSpec { $$ = new BinStr(); $$->appendInt32($1); }
| typeListNotEmpty ',' typeSpec { $$ = $1; $$->appendInt32($3); }
;
typarsClause : /* EMPTY */ { $$ = NULL; PASM->m_TyParList = NULL;}
| '<' typars '>' { $$ = $2; PASM->m_TyParList = $2;}
;
typarAttrib : '+' { $$ = gpCovariant; }
| '-' { $$ = gpContravariant; }
| CLASS_ { $$ = gpReferenceTypeConstraint; }
| VALUETYPE_ { $$ = gpNotNullableValueTypeConstraint; }
| BYREFLIKE_ { $$ = gpAcceptByRefLike; }
| _CTOR { $$ = gpDefaultConstructorConstraint; }
| FLAGS_ '(' int32 ')' { $$ = (CorGenericParamAttr)$3; }
;
typarAttribs : /* EMPTY */ { $$ = 0; }
| typarAttrib typarAttribs { $$ = $1 | $2; }
;
typars : typarAttribs tyBound dottedName typarsRest {$$ = new TyParList($1, $2, $3, $4);}
| typarAttribs dottedName typarsRest {$$ = new TyParList($1, NULL, $2, $3);}
;
typarsRest : /* EMPTY */ { $$ = NULL; }
| ',' typars { $$ = $2; }
;
tyBound : '(' typeList ')' { $$ = $2; }
;
genArity : /* EMPTY */ { $$= 0; }
| genArityNotEmpty { $$ = $1; }
;
genArityNotEmpty : '<' '[' int32 ']' '>' { $$ = $3; }
;
/* Class body declarations */
classDecl : methodHead methodDecls '}' { if(PASM->m_pCurMethod->m_ulLines[1] ==0)
{ PASM->m_pCurMethod->m_ulLines[1] = PASM->m_ulCurLine;
PASM->m_pCurMethod->m_ulColumns[1]=PASM->m_ulCurColumn;}
PASM->EndMethod(); }
| classHead '{' classDecls '}' { PASM->EndClass(); }
| eventHead '{' eventDecls '}' { PASM->EndEvent(); }
| propHead '{' propDecls '}' { PASM->EndProp(); }
| fieldDecl
| dataDecl
| secDecl
| extSourceSpec
| customAttrDecl
| _SIZE int32 { PASM->m_pCurClass->m_ulSize = $2; }
| _PACK int32 { PASM->m_pCurClass->m_ulPack = $2; }
| exportHead '{' exptypeDecls '}' { PASMM->EndComType(); }
| _OVERRIDE typeSpec DCOLON methodName WITH_ callConv type typeSpec DCOLON methodName '(' sigArgs0 ')'
{ BinStr *sig1 = parser->MakeSig($6, $7, $12);
BinStr *sig2 = new BinStr(); sig2->append(sig1);
PASM->AddMethodImpl($2,$4,sig1,$8,$10,sig2);
PASM->ResetArgNameList();
}
| _OVERRIDE METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')' WITH_ METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')'
{ PASM->AddMethodImpl($5,$7,
($8==0 ? parser->MakeSig($3,$4,$10) :
parser->MakeSig($3| IMAGE_CEE_CS_CALLCONV_GENERIC,$4,$10,$8)),
$16,$18,
($19==0 ? parser->MakeSig($14,$15,$21) :
parser->MakeSig($14| IMAGE_CEE_CS_CALLCONV_GENERIC,$15,$21,$19)));
PASM->ResetArgNameList();
}
| languageDecl
| compControl
| _PARAM TYPE_ '[' int32 ']' { if(($4 > 0) && ($4 <= (int)PASM->m_pCurClass->m_NumTyPars))
PASM->m_pCustomDescrList = PASM->m_pCurClass->m_TyPars[$4-1].CAList();
else
PASM->report->error("Type parameter index out of range\n");
}
| _PARAM TYPE_ dottedName { int n = PASM->m_pCurClass->FindTyPar($3);
if(n >= 0)
PASM->m_pCustomDescrList = PASM->m_pCurClass->m_TyPars[n].CAList();
else
PASM->report->error("Type parameter '%s' undefined\n",$3);
}
| _PARAM CONSTRAINT_ '[' int32 ']' ',' typeSpec { PASM->AddGenericParamConstraint($4, 0, $7); }
| _PARAM CONSTRAINT_ dottedName ',' typeSpec { PASM->AddGenericParamConstraint(0, $3, $5); }
| _INTERFACEIMPL TYPE_ typeSpec customDescr { $4->tkInterfacePair = $3;
if(PASM->m_pCustomDescrList)
PASM->m_pCustomDescrList->PUSH($4);
}
;
/* Field declaration */
fieldDecl : _FIELD repeatOpt fieldAttr type dottedName atOpt initOpt
{ $4->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
PASM->AddField($5, $4, $3, $6, $7, $2); }
;
fieldAttr : /* EMPTY */ { $$ = (CorFieldAttr) 0; }
| fieldAttr STATIC_ { $$ = (CorFieldAttr) ($1 | fdStatic); }
| fieldAttr PUBLIC_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPublic); }
| fieldAttr PRIVATE_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPrivate); }
| fieldAttr FAMILY_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamily); }
| fieldAttr INITONLY_ { $$ = (CorFieldAttr) ($1 | fdInitOnly); }
| fieldAttr RTSPECIALNAME_ { $$ = $1; } /*{ $$ = (CorFieldAttr) ($1 | fdRTSpecialName); }*/
| fieldAttr SPECIALNAME_ { $$ = (CorFieldAttr) ($1 | fdSpecialName); }
/* <STRIP>commented out because PInvoke for fields is not supported by EE
| fieldAttr PINVOKEIMPL_ '(' compQstring AS_ compQstring pinvAttr ')'
{ $$ = (CorFieldAttr) ($1 | fdPinvokeImpl);
PASM->SetPinvoke($4,0,$6,$7); }
| fieldAttr PINVOKEIMPL_ '(' compQstring pinvAttr ')'
{ $$ = (CorFieldAttr) ($1 | fdPinvokeImpl);
PASM->SetPinvoke($4,0,NULL,$5); }
| fieldAttr PINVOKEIMPL_ '(' pinvAttr ')'
{ PASM->SetPinvoke(new BinStr(),0,NULL,$4);
$$ = (CorFieldAttr) ($1 | fdPinvokeImpl); }
</STRIP>*/
| fieldAttr MARSHAL_ '(' marshalBlob ')'
{ PASM->m_pMarshal = $4; }
| fieldAttr ASSEMBLY_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdAssembly); }
| fieldAttr FAMANDASSEM_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamANDAssem); }
| fieldAttr FAMORASSEM_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamORAssem); }
| fieldAttr PRIVATESCOPE_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPrivateScope); }
| fieldAttr LITERAL_ { $$ = (CorFieldAttr) ($1 | fdLiteral); }
| fieldAttr NOTSERIALIZED_ { $$ = (CorFieldAttr) ($1 | fdNotSerialized); }
| fieldAttr FLAGS_ '(' int32 ')' { $$ = (CorFieldAttr) ($4); }
;
atOpt : /* EMPTY */ { $$ = 0; }
| AT_ id { $$ = $2; }
;
initOpt : /* EMPTY */ { $$ = NULL; }
| '=' fieldInit { $$ = $2; }
;
repeatOpt : /* EMPTY */ { $$ = 0xFFFFFFFF; }
| '[' int32 ']' { $$ = $2; }
;
/* Method referencing */
methodRef : callConv type typeSpec DCOLON methodName tyArgs0 '(' sigArgs0 ')'
{ PASM->ResetArgNameList();
if ($6 == NULL)
{
if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
$$ = PASM->MakeMemberRef($3, $5, parser->MakeSig($1|iCallConv, $2, $8));
}
else
{
mdToken mr;
if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
mr = PASM->MakeMemberRef($3, $5,
parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $8, corCountArgs($6)));
$$ = PASM->MakeMethodSpec(mr,
parser->MakeSig(IMAGE_CEE_CS_CALLCONV_INSTANTIATION, 0, $6));
}
}
| callConv type typeSpec DCOLON methodName genArityNotEmpty '(' sigArgs0 ')'
{ PASM->ResetArgNameList();
if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
$$ = PASM->MakeMemberRef($3, $5,
parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $8, $6));
}
| callConv type methodName tyArgs0 '(' sigArgs0 ')'
{ PASM->ResetArgNameList();
if ($4 == NULL)
{
if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
$$ = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1|iCallConv, $2, $6));
}
else
{
mdToken mr;
if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
mr = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $6, corCountArgs($4)));
$$ = PASM->MakeMethodSpec(mr,
parser->MakeSig(IMAGE_CEE_CS_CALLCONV_INSTANTIATION, 0, $4));
}
}
| callConv type methodName genArityNotEmpty '(' sigArgs0 ')'
{ PASM->ResetArgNameList();
if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
$$ = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $6, $4));
}
| mdtoken { $$ = $1; }
| TYPEDEF_M { $$ = $1->m_tkTypeSpec; }
| TYPEDEF_MR { $$ = $1->m_tkTypeSpec; }
;
callConv : INSTANCE_ callConv { $$ = ($2 | IMAGE_CEE_CS_CALLCONV_HASTHIS); }
| EXPLICIT_ callConv { $$ = ($2 | IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS); }
| callKind { $$ = $1; }
| CALLCONV_ '(' int32 ')' { $$ = $3; }
;
callKind : /* EMPTY */ { $$ = IMAGE_CEE_CS_CALLCONV_DEFAULT; }
| DEFAULT_ { $$ = IMAGE_CEE_CS_CALLCONV_DEFAULT; }
| VARARG_ { $$ = IMAGE_CEE_CS_CALLCONV_VARARG; }
| UNMANAGED_ CDECL_ { $$ = IMAGE_CEE_CS_CALLCONV_C; }
| UNMANAGED_ STDCALL_ { $$ = IMAGE_CEE_CS_CALLCONV_STDCALL; }
| UNMANAGED_ THISCALL_ { $$ = IMAGE_CEE_CS_CALLCONV_THISCALL; }
| UNMANAGED_ FASTCALL_ { $$ = IMAGE_CEE_CS_CALLCONV_FASTCALL; }
| UNMANAGED_ { $$ = IMAGE_CEE_CS_CALLCONV_UNMANAGED; }
;
mdtoken : MDTOKEN_ '(' int32 ')' { $$ = $3; }
;
memberRef : methodSpec methodRef { $$ = $2;
PASM->delArgNameList(PASM->m_firstArgName);
PASM->m_firstArgName = parser->m_ANSFirst.POP();
PASM->m_lastArgName = parser->m_ANSLast.POP();
PASM->SetMemberRefFixup($2,iOpcodeLen); }
| FIELD_ type typeSpec DCOLON dottedName
{ $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
$$ = PASM->MakeMemberRef($3, $5, $2);
PASM->SetMemberRefFixup($$,iOpcodeLen); }
| FIELD_ type dottedName
{ $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
$$ = PASM->MakeMemberRef(NULL, $3, $2);
PASM->SetMemberRefFixup($$,iOpcodeLen); }
| FIELD_ TYPEDEF_F { $$ = $2->m_tkTypeSpec;
PASM->SetMemberRefFixup($$,iOpcodeLen); }
| FIELD_ TYPEDEF_MR { $$ = $2->m_tkTypeSpec;
PASM->SetMemberRefFixup($$,iOpcodeLen); }
| mdtoken { $$ = $1;
PASM->SetMemberRefFixup($$,iOpcodeLen); }
;
/* Event declaration */
eventHead : _EVENT eventAttr typeSpec dottedName { PASM->ResetEvent($4, $3, $2); }
| _EVENT eventAttr dottedName { PASM->ResetEvent($3, mdTypeRefNil, $2); }
;
eventAttr : /* EMPTY */ { $$ = (CorEventAttr) 0; }
| eventAttr RTSPECIALNAME_ { $$ = $1; }/*{ $$ = (CorEventAttr) ($1 | evRTSpecialName); }*/
| eventAttr SPECIALNAME_ { $$ = (CorEventAttr) ($1 | evSpecialName); }
;
eventDecls : /* EMPTY */
| eventDecls eventDecl
;
eventDecl : _ADDON methodRef { PASM->SetEventMethod(0, $2); }
| _REMOVEON methodRef { PASM->SetEventMethod(1, $2); }
| _FIRE methodRef { PASM->SetEventMethod(2, $2); }
| _OTHER methodRef { PASM->SetEventMethod(3, $2); }
| extSourceSpec
| customAttrDecl
| languageDecl
| compControl
;
/* Property declaration */
propHead : _PROPERTY propAttr callConv type dottedName '(' sigArgs0 ')' initOpt
{ PASM->ResetProp($5,
parser->MakeSig((IMAGE_CEE_CS_CALLCONV_PROPERTY |
($3 & IMAGE_CEE_CS_CALLCONV_HASTHIS)),$4,$7), $2, $9);}
;
propAttr : /* EMPTY */ { $$ = (CorPropertyAttr) 0; }
| propAttr RTSPECIALNAME_ { $$ = $1; }/*{ $$ = (CorPropertyAttr) ($1 | prRTSpecialName); }*/
| propAttr SPECIALNAME_ { $$ = (CorPropertyAttr) ($1 | prSpecialName); }
;
propDecls : /* EMPTY */
| propDecls propDecl
;
propDecl : _SET methodRef { PASM->SetPropMethod(0, $2); }
| _GET methodRef { PASM->SetPropMethod(1, $2); }
| _OTHER methodRef { PASM->SetPropMethod(2, $2); }
| customAttrDecl
| extSourceSpec
| languageDecl
| compControl
;
/* Method declaration */
methodHeadPart1 : _METHOD { PASM->ResetForNextMethod();
uMethodBeginLine = PASM->m_ulCurLine;
uMethodBeginColumn=PASM->m_ulCurColumn;
}
;
marshalClause : /* EMPTY */ { $$ = NULL; }
| MARSHAL_ '(' marshalBlob ')' { $$ = $3; }
;
marshalBlob : nativeType { $$ = $1; }
| marshalBlobHead hexbytes '}' { $$ = $2; }
;
marshalBlobHead : '{' { bParsingByteArray = TRUE; }
;
methodHead : methodHeadPart1 methAttr callConv paramAttr type marshalClause methodName typarsClause'(' sigArgs0 ')' implAttr '{'
{ BinStr* sig;
if ($8 == NULL) sig = parser->MakeSig($3, $5, $10);
else {
FixupTyPars($5);
sig = parser->MakeSig($3 | IMAGE_CEE_CS_CALLCONV_GENERIC, $5, $10, $8->Count());
FixupConstraints();
}
PASM->StartMethod($7, sig, $2, $6, $4, $8);
TyParFixupList.RESET(false);
PASM->SetImplAttr((USHORT)$12);
PASM->m_pCurMethod->m_ulLines[0] = uMethodBeginLine;
PASM->m_pCurMethod->m_ulColumns[0]=uMethodBeginColumn;
}
;
methAttr : /* EMPTY */ { $$ = (CorMethodAttr) 0; }
| methAttr STATIC_ { $$ = (CorMethodAttr) ($1 | mdStatic); }
| methAttr PUBLIC_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPublic); }
| methAttr PRIVATE_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPrivate); }
| methAttr FAMILY_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamily); }
| methAttr FINAL_ { $$ = (CorMethodAttr) ($1 | mdFinal); }
| methAttr SPECIALNAME_ { $$ = (CorMethodAttr) ($1 | mdSpecialName); }
| methAttr VIRTUAL_ { $$ = (CorMethodAttr) ($1 | mdVirtual); }
| methAttr STRICT_ { $$ = (CorMethodAttr) ($1 | mdCheckAccessOnOverride); }
| methAttr ABSTRACT_ { $$ = (CorMethodAttr) ($1 | mdAbstract); }
| methAttr ASSEMBLY_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdAssem); }
| methAttr FAMANDASSEM_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamANDAssem); }
| methAttr FAMORASSEM_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamORAssem); }
| methAttr PRIVATESCOPE_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPrivateScope); }
| methAttr HIDEBYSIG_ { $$ = (CorMethodAttr) ($1 | mdHideBySig); }
| methAttr NEWSLOT_ { $$ = (CorMethodAttr) ($1 | mdNewSlot); }
| methAttr RTSPECIALNAME_ { $$ = $1; }/*{ $$ = (CorMethodAttr) ($1 | mdRTSpecialName); }*/
| methAttr UNMANAGEDEXP_ { $$ = (CorMethodAttr) ($1 | mdUnmanagedExport); }
| methAttr REQSECOBJ_ { $$ = (CorMethodAttr) ($1 | mdRequireSecObject); }
| methAttr FLAGS_ '(' int32 ')' { $$ = (CorMethodAttr) ($4); }
| methAttr PINVOKEIMPL_ '(' compQstring AS_ compQstring pinvAttr ')'
{ PASM->SetPinvoke($4,0,$6,$7);
$$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
| methAttr PINVOKEIMPL_ '(' compQstring pinvAttr ')'
{ PASM->SetPinvoke($4,0,NULL,$5);
$$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
| methAttr PINVOKEIMPL_ '(' pinvAttr ')'
{ PASM->SetPinvoke(new BinStr(),0,NULL,$4);
$$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
;
pinvAttr : /* EMPTY */ { $$ = (CorPinvokeMap) 0; }
| pinvAttr NOMANGLE_ { $$ = (CorPinvokeMap) ($1 | pmNoMangle); }
| pinvAttr ANSI_ { $$ = (CorPinvokeMap) ($1 | pmCharSetAnsi); }
| pinvAttr UNICODE_ { $$ = (CorPinvokeMap) ($1 | pmCharSetUnicode); }
| pinvAttr AUTOCHAR_ { $$ = (CorPinvokeMap) ($1 | pmCharSetAuto); }
| pinvAttr LASTERR_ { $$ = (CorPinvokeMap) ($1 | pmSupportsLastError); }
| pinvAttr WINAPI_ { $$ = (CorPinvokeMap) ($1 | pmCallConvWinapi); }
| pinvAttr CDECL_ { $$ = (CorPinvokeMap) ($1 | pmCallConvCdecl); }
| pinvAttr STDCALL_ { $$ = (CorPinvokeMap) ($1 | pmCallConvStdcall); }
| pinvAttr THISCALL_ { $$ = (CorPinvokeMap) ($1 | pmCallConvThiscall); }
| pinvAttr FASTCALL_ { $$ = (CorPinvokeMap) ($1 | pmCallConvFastcall); }
| pinvAttr BESTFIT_ ':' ON_ { $$ = (CorPinvokeMap) ($1 | pmBestFitEnabled); }
| pinvAttr BESTFIT_ ':' OFF_ { $$ = (CorPinvokeMap) ($1 | pmBestFitDisabled); }
| pinvAttr CHARMAPERROR_ ':' ON_ { $$ = (CorPinvokeMap) ($1 | pmThrowOnUnmappableCharEnabled); }
| pinvAttr CHARMAPERROR_ ':' OFF_ { $$ = (CorPinvokeMap) ($1 | pmThrowOnUnmappableCharDisabled); }
| pinvAttr FLAGS_ '(' int32 ')' { $$ = (CorPinvokeMap) ($4); }
;
methodName : _CTOR { $$ = newString(COR_CTOR_METHOD_NAME); }
| _CCTOR { $$ = newString(COR_CCTOR_METHOD_NAME); }
| dottedName { $$ = $1; }
;
paramAttr : /* EMPTY */ { $$ = 0; }
| paramAttr '[' IN_ ']' { $$ = $1 | pdIn; }
| paramAttr '[' OUT_ ']' { $$ = $1 | pdOut; }
| paramAttr '[' OPT_ ']' { $$ = $1 | pdOptional; }
| paramAttr '[' int32 ']' { $$ = $3 + 1; }
;
implAttr : /* EMPTY */ { $$ = (CorMethodImpl) (miIL | miManaged); }
| implAttr NATIVE_ { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miNative); }
| implAttr CIL_ { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miIL); }
| implAttr OPTIL_ { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miOPTIL); }
| implAttr MANAGED_ { $$ = (CorMethodImpl) (($1 & 0xFFFB) | miManaged); }
| implAttr UNMANAGED_ { $$ = (CorMethodImpl) (($1 & 0xFFFB) | miUnmanaged); }
| implAttr FORWARDREF_ { $$ = (CorMethodImpl) ($1 | miForwardRef); }
| implAttr PRESERVESIG_ { $$ = (CorMethodImpl) ($1 | miPreserveSig); }
| implAttr RUNTIME_ { $$ = (CorMethodImpl) ($1 | miRuntime); }
| implAttr INTERNALCALL_ { $$ = (CorMethodImpl) ($1 | miInternalCall); }
| implAttr SYNCHRONIZED_ { $$ = (CorMethodImpl) ($1 | miSynchronized); }
| implAttr NOINLINING_ { $$ = (CorMethodImpl) ($1 | miNoInlining); }
| implAttr AGGRESSIVEINLINING_ { $$ = (CorMethodImpl) ($1 | miAggressiveInlining); }
| implAttr NOOPTIMIZATION_ { $$ = (CorMethodImpl) ($1 | miNoOptimization); }
| implAttr AGGRESSIVEOPTIMIZATION_ { $$ = (CorMethodImpl) ($1 | miAggressiveOptimization); }
| implAttr FLAGS_ '(' int32 ')' { $$ = (CorMethodImpl) ($4); }
;
localsHead : _LOCALS { PASM->delArgNameList(PASM->m_firstArgName); PASM->m_firstArgName = NULL;PASM->m_lastArgName = NULL;
}
;
methodDecls : /* EMPTY */
| methodDecls methodDecl
;
methodDecl : _EMITBYTE int32 { PASM->EmitByte($2); }
| sehBlock { delete PASM->m_SEHD; PASM->m_SEHD = PASM->m_SEHDstack.POP(); }
| _MAXSTACK int32 { PASM->EmitMaxStack($2); }
| localsHead '(' sigArgs0 ')' { PASM->EmitLocals(parser->MakeSig(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG, 0, $3));
}
| localsHead INIT_ '(' sigArgs0 ')' { PASM->EmitZeroInit();
PASM->EmitLocals(parser->MakeSig(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG, 0, $4));
}
| _ENTRYPOINT { PASM->EmitEntryPoint(); }
| _ZEROINIT { PASM->EmitZeroInit(); }
| dataDecl
| instr
| id ':' { PASM->AddLabel(PASM->m_CurPC,$1); /*PASM->EmitLabel($1);*/ }
| secDecl
| extSourceSpec
| languageDecl
| customAttrDecl
| compControl
| _EXPORT '[' int32 ']' { if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
{
PASM->m_pCurMethod->m_dwExportOrdinal = $3;
PASM->m_pCurMethod->m_szExportAlias = NULL;
if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = (WORD)($3 + 0x8000);
}
else
PASM->report->warn("Duplicate .export directive, ignored\n");
}
| _EXPORT '[' int32 ']' AS_ id { if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
{
PASM->m_pCurMethod->m_dwExportOrdinal = $3;
PASM->m_pCurMethod->m_szExportAlias = $6;
if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = (WORD)($3 + 0x8000);
}
else
PASM->report->warn("Duplicate .export directive, ignored\n");
}
| _VTENTRY int32 ':' int32 { PASM->m_pCurMethod->m_wVTEntry = (WORD)$2;
PASM->m_pCurMethod->m_wVTSlot = (WORD)$4; }
| _OVERRIDE typeSpec DCOLON methodName
{ PASM->AddMethodImpl($2,$4,NULL,NULL,NULL,NULL); }
| _OVERRIDE METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')'
{ PASM->AddMethodImpl($5,$7,
($8==0 ? parser->MakeSig($3,$4,$10) :
parser->MakeSig($3| IMAGE_CEE_CS_CALLCONV_GENERIC,$4,$10,$8))
,NULL,NULL,NULL);
PASM->ResetArgNameList();
}
| scopeBlock
| _PARAM TYPE_ '[' int32 ']' { if(($4 > 0) && ($4 <= (int)PASM->m_pCurMethod->m_NumTyPars))
PASM->m_pCustomDescrList = PASM->m_pCurMethod->m_TyPars[$4-1].CAList();
else
PASM->report->error("Type parameter index out of range\n");
}
| _PARAM TYPE_ dottedName { int n = PASM->m_pCurMethod->FindTyPar($3);
if(n >= 0)
PASM->m_pCustomDescrList = PASM->m_pCurMethod->m_TyPars[n].CAList();
else
PASM->report->error("Type parameter '%s' undefined\n",$3);
}
| _PARAM CONSTRAINT_ '[' int32 ']' ',' typeSpec { PASM->m_pCurMethod->AddGenericParamConstraint($4, 0, $7); }
| _PARAM CONSTRAINT_ dottedName ',' typeSpec { PASM->m_pCurMethod->AddGenericParamConstraint(0, $3, $5); }
| _PARAM '[' int32 ']' initOpt
{ if( $3 ) {
ARG_NAME_LIST* pAN=PASM->findArg(PASM->m_pCurMethod->m_firstArgName, $3 - 1);
if(pAN)
{
PASM->m_pCustomDescrList = &(pAN->CustDList);
pAN->pValue = $5;
}
else
{
PASM->m_pCustomDescrList = NULL;
if($5) delete $5;
}
} else {
PASM->m_pCustomDescrList = &(PASM->m_pCurMethod->m_RetCustDList);
PASM->m_pCurMethod->m_pRetValue = $5;
}
PASM->m_tkCurrentCVOwner = 0;
}
;
scopeBlock : scopeOpen methodDecls '}' { PASM->m_pCurMethod->CloseScope(); }
;
scopeOpen : '{' { PASM->m_pCurMethod->OpenScope(); }
;
/* Structured exception handling directives */
sehBlock : tryBlock sehClauses
;
sehClauses : sehClause sehClauses
| sehClause
;
tryBlock : tryHead scopeBlock { PASM->m_SEHD->tryTo = PASM->m_CurPC; }
| tryHead id TO_ id { PASM->SetTryLabels($2, $4); }
| tryHead int32 TO_ int32 { if(PASM->m_SEHD) {PASM->m_SEHD->tryFrom = $2;
PASM->m_SEHD->tryTo = $4;} }
;
tryHead : _TRY { PASM->NewSEHDescriptor();
PASM->m_SEHD->tryFrom = PASM->m_CurPC; }
;
sehClause : catchClause handlerBlock { PASM->EmitTry(); }
| filterClause handlerBlock { PASM->EmitTry(); }