Merge pull request #24002 from sandreenko/fixDesktopFailure
[platform/upstream/coreclr.git] / src / ilasm / asmparse.y
1 %{
2
3 // Licensed to the .NET Foundation under one or more agreements.
4 // The .NET Foundation licenses this file to you under the MIT license.
5 // See the LICENSE file in the project root for more information.
6
7 //
8 // File asmparse.y
9 //
10 #include "ilasmpch.h"
11
12 #include "grammar_before.cpp"
13
14 %}
15
16 %union {
17         CorRegTypeAttr classAttr;
18         CorMethodAttr methAttr;
19         CorFieldAttr fieldAttr;
20         CorMethodImpl implAttr;
21         CorEventAttr  eventAttr;
22         CorPropertyAttr propAttr;
23         CorPinvokeMap pinvAttr;
24         CorDeclSecurity secAct;
25         CorFileFlags fileAttr;
26         CorAssemblyFlags asmAttr;
27         CorAssemblyFlags asmRefAttr;
28         CorTypeAttr exptAttr;
29         CorManifestResourceFlags manresAttr;
30         double*  float64;
31         __int64* int64;
32         __int32  int32;
33         char*    string;
34         BinStr*  binstr;
35         Labels*  labels;
36         Instr*   instr;         // instruction opcode
37         NVPair*  pair;
38         pTyParList typarlist;
39         mdToken token;
40         TypeDefDescr* tdd;
41         CustomDescr*  cad;
42         unsigned short opcode;
43 };
44
45         /* These are returned by the LEXER and have values */
46 %token ERROR_ BAD_COMMENT_ BAD_LITERAL_                         /* bad strings,    */
47 %token <string>  ID             /* testing343 */
48 %token <string>  DOTTEDNAME     /* System.Object */
49 %token <binstr>  QSTRING        /* "Hello World\n" */
50 %token <string>  SQSTRING       /* 'Hello World\n' */
51 %token <int32>   INT32          /* 3425 0x34FA  0352  */
52 %token <int64>   INT64          /* 342534523534534      0x34FA434644554 */
53 %token <float64> FLOAT64        /* -334234 24E-34 */
54 %token <int32>   HEXBYTE        /* 05 1A FA */
55 %token <tdd>     TYPEDEF_T
56 %token <tdd>     TYPEDEF_M
57 %token <tdd>     TYPEDEF_F
58 %token <tdd>     TYPEDEF_TS
59 %token <tdd>     TYPEDEF_MR
60 %token <tdd>     TYPEDEF_CA
61
62
63         /* multi-character punctuation */
64 %token DCOLON                   /* :: */
65 %token ELIPSIS                  /* ... */
66
67         /* Keywords   Note the undersores are to avoid collisions as these are common names */
68 %token VOID_ BOOL_ CHAR_ UNSIGNED_ INT_ INT8_ INT16_ INT32_ INT64_ FLOAT_ FLOAT32_ FLOAT64_ BYTEARRAY_
69 %token UINT_ UINT8_ UINT16_ UINT32_ UINT64_  FLAGS_ CALLCONV_ MDTOKEN_
70 %token OBJECT_ STRING_ NULLREF_
71         /* misc keywords */ 
72 %token DEFAULT_ CDECL_ VARARG_ STDCALL_ THISCALL_ FASTCALL_ CLASS_ 
73 %token TYPEDREF_ UNMANAGED_ FINALLY_ HANDLER_ CATCH_ FILTER_ FAULT_
74 %token EXTENDS_ IMPLEMENTS_ TO_ AT_ TLS_ TRUE_ FALSE_ _INTERFACEIMPL
75
76         /* class, method, field attributes */
77
78 %token VALUE_ VALUETYPE_ NATIVE_ INSTANCE_ SPECIALNAME_ FORWARDER_
79 %token STATIC_ PUBLIC_ PRIVATE_ FAMILY_ FINAL_ SYNCHRONIZED_ INTERFACE_ SEALED_ NESTED_
80 %token ABSTRACT_ AUTO_ SEQUENTIAL_ EXPLICIT_ ANSI_ UNICODE_ AUTOCHAR_ IMPORT_ ENUM_
81 %token VIRTUAL_ NOINLINING_ AGGRESSIVEINLINING_ NOOPTIMIZATION_ AGGRESSIVEOPTIMIZATION_ UNMANAGEDEXP_ BEFOREFIELDINIT_
82 %token STRICT_ RETARGETABLE_ WINDOWSRUNTIME_ NOPLATFORM_
83 %token METHOD_ FIELD_ PINNED_ MODREQ_ MODOPT_ SERIALIZABLE_ PROPERTY_ TYPE_
84 %token ASSEMBLY_ FAMANDASSEM_ FAMORASSEM_ PRIVATESCOPE_ HIDEBYSIG_ NEWSLOT_ RTSPECIALNAME_ PINVOKEIMPL_
85 %token _CTOR _CCTOR LITERAL_ NOTSERIALIZED_ INITONLY_ REQSECOBJ_
86         /* method implementation attributes: NATIVE_ and UNMANAGED_ listed above */
87 %token CIL_ OPTIL_ MANAGED_ FORWARDREF_ PRESERVESIG_ RUNTIME_ INTERNALCALL_
88         /* PInvoke-specific keywords */
89 %token _IMPORT NOMANGLE_ LASTERR_ WINAPI_ AS_ BESTFIT_ ON_ OFF_ CHARMAPERROR_
90
91         /* intruction tokens (actually instruction groupings) */
92 %token <opcode> INSTR_NONE INSTR_VAR INSTR_I INSTR_I8 INSTR_R INSTR_BRTARGET INSTR_METHOD INSTR_FIELD 
93 %token <opcode> INSTR_TYPE INSTR_STRING INSTR_SIG INSTR_TOK 
94 %token <opcode> INSTR_SWITCH
95
96         /* assember directives */
97 %token _CLASS _NAMESPACE _METHOD _FIELD _DATA _THIS _BASE _NESTER
98 %token _EMITBYTE _TRY _MAXSTACK _LOCALS _ENTRYPOINT _ZEROINIT  
99 %token _EVENT _ADDON _REMOVEON _FIRE _OTHER 
100 %token _PROPERTY _SET _GET DEFAULT_ 
101 %token _PERMISSION _PERMISSIONSET
102
103                 /* security actions */
104 %token REQUEST_ DEMAND_ ASSERT_ DENY_ PERMITONLY_ LINKCHECK_ INHERITCHECK_ 
105 %token REQMIN_ REQOPT_ REQREFUSE_ PREJITGRANT_ PREJITDENY_ NONCASDEMAND_
106 %token NONCASLINKDEMAND_ NONCASINHERITANCE_ 
107
108         /* extern debug info specifier (to be used by precompilers only) */
109 %token _LINE P_LINE _LANGUAGE
110         /* custom value specifier */
111 %token _CUSTOM
112         /* local vars zeroinit specifier */
113 %token INIT_
114         /* class layout */
115 %token _SIZE _PACK
116 %token _VTABLE _VTFIXUP FROMUNMANAGED_ CALLMOSTDERIVED_ _VTENTRY RETAINAPPDOMAIN_
117         /* manifest */
118 %token _FILE NOMETADATA_ _HASH _ASSEMBLY _PUBLICKEY _PUBLICKEYTOKEN ALGORITHM_ _VER _LOCALE EXTERN_ 
119 %token _MRESOURCE 
120 %token _MODULE _EXPORT
121 %token LEGACY_ LIBRARY_ X86_ AMD64_ ARM_ ARM64_
122         /* field marshaling */
123 %token MARSHAL_ CUSTOM_ SYSSTRING_ FIXED_ VARIANT_ CURRENCY_ SYSCHAR_ DECIMAL_ DATE_ BSTR_ TBSTR_ LPSTR_
124 %token LPWSTR_ LPTSTR_ OBJECTREF_ IUNKNOWN_ IDISPATCH_ STRUCT_ SAFEARRAY_ BYVALSTR_ LPVOID_ ANY_ ARRAY_ LPSTRUCT_
125 %token IIDPARAM_
126         /* parameter attributes */
127 %token IN_ OUT_ OPT_ PARAM_
128                 /* method implementations */
129 %token _OVERRIDE WITH_
130                 /* variant type specifics */
131 %token NULL_ ERROR_ HRESULT_ CARRAY_ USERDEFINED_ RECORD_ FILETIME_ BLOB_ STREAM_ STORAGE_
132 %token STREAMED_OBJECT_ STORED_OBJECT_ BLOB_OBJECT_ CF_ CLSID_ VECTOR_
133                 /* header flags */
134 %token _SUBSYSTEM _CORFLAGS ALIGNMENT_ _IMAGEBASE _STACKRESERVE
135
136         /* syntactic sugar */
137 %token _TYPEDEF _TEMPLATE _TYPELIST _MSCORLIB      
138
139         /* compilation control directives */
140 %token P_DEFINE P_UNDEF P_IFDEF P_IFNDEF P_ELSE P_ENDIF P_INCLUDE
141
142         /* nonTerminals */
143 %type <string> dottedName id methodName atOpt slashedName
144 %type <labels> labels
145 %type <int32> callConv callKind int32 customHead customHeadWithOwner vtfixupAttr paramAttr ddItemCount variantType repeatOpt truefalse typarAttrib typarAttribs
146 %type <int32> iidParamIndex genArity genArityNotEmpty
147 %type <float64> float64
148 %type <int64> int64
149 %type <binstr> sigArgs0 sigArgs1 sigArg type bound bounds1 bytes hexbytes nativeType marshalBlob initOpt compQstring caValue
150 %type <binstr> marshalClause
151 %type <binstr> fieldInit serInit fieldSerInit
152 %type <binstr> f32seq f64seq i8seq i16seq i32seq i64seq boolSeq sqstringSeq classSeq objSeq
153 %type <binstr> simpleType
154 %type <binstr> tyArgs0 tyArgs1 tyArgs2 typeList typeListNotEmpty tyBound
155 %type <binstr> customBlobDescr serializType customBlobArgs customBlobNVPairs
156 %type <binstr> secAttrBlob secAttrSetBlob
157 %type <int32> fieldOrProp intOrWildcard
158 %type <typarlist> typarsRest typars typarsClause
159 %type <token> className typeSpec ownerType customType memberRef methodRef mdtoken
160 %type <classAttr> classAttr
161 %type <methAttr> methAttr
162 %type <fieldAttr> fieldAttr
163 %type <implAttr> implAttr
164 %type <eventAttr> eventAttr
165 %type <propAttr> propAttr
166 %type <pinvAttr> pinvAttr
167 %type <pair> nameValPairs nameValPair
168 %type <secAct> secAction
169 %type <secAct> psetHead
170 %type <fileAttr> fileAttr
171 %type <fileAttr> fileEntry
172 %type <asmAttr> asmAttr
173 %type <exptAttr> exptAttr
174 %type <manresAttr> manresAttr
175 %type <cad> customDescr customDescrWithOwner
176 %type <instr> instr_none instr_var instr_i instr_i8 instr_r instr_brtarget instr_method instr_field
177 %type <instr> instr_type instr_string instr_sig instr_tok instr_switch
178 %type <instr> instr_r_head
179
180 %start decls
181
182 /**************************************************************************/
183 %%      
184
185 decls                   : /* EMPTY */
186                         | decls decl                                            
187                         ;
188 /* Module-level declarations */
189 decl                    : classHead '{' classDecls '}'                          { PASM->EndClass(); }
190                         | nameSpaceHead '{' decls '}'                           { PASM->EndNameSpace(); }
191                         | methodHead  methodDecls '}'                           { if(PASM->m_pCurMethod->m_ulLines[1] ==0)
192                                                                                   {  PASM->m_pCurMethod->m_ulLines[1] = PASM->m_ulCurLine;
193                                                                                      PASM->m_pCurMethod->m_ulColumns[1]=PASM->m_ulCurColumn;}
194                                                                                   PASM->EndMethod(); }
195                         | fieldDecl
196                         | dataDecl
197                         | vtableDecl
198                         | vtfixupDecl
199                         | extSourceSpec
200                         | fileDecl
201                         | assemblyHead '{' assemblyDecls '}'                    { PASMM->EndAssembly(); }
202                         | assemblyRefHead '{' assemblyRefDecls '}'              { PASMM->EndAssembly(); }
203                         | exptypeHead '{' exptypeDecls '}'                      { PASMM->EndComType(); }
204                         | manifestResHead '{' manifestResDecls '}'              { PASMM->EndManifestRes(); }
205                         | moduleHead
206                         | secDecl
207                         | customAttrDecl
208                         | _SUBSYSTEM int32                                      { 
209 #ifdef _PREFAST_
210 #pragma warning(push)
211 #pragma warning(disable:22011) // Suppress PREFast warning about integer overflow/underflow
212 #endif
213                                                                                   PASM->m_dwSubsystem = $2;
214 #ifdef _PREFAST_
215 #pragma warning(pop)
216 #endif
217                                                                                 }
218                         | _CORFLAGS int32                                       { PASM->m_dwComImageFlags = $2; }
219                         | _FILE ALIGNMENT_ int32                                { PASM->m_dwFileAlignment = $3; 
220                                                                                   if(($3 & ($3 - 1))||($3 < 0x200)||($3 > 0x10000))
221                                                                                     PASM->report->error("Invalid file alignment, must be power of 2 from 0x200 to 0x10000\n");}
222                         | _IMAGEBASE int64                                      { PASM->m_stBaseAddress = (ULONGLONG)(*($2)); delete $2; 
223                                                                                   if(PASM->m_stBaseAddress & 0xFFFF)
224                                                                                     PASM->report->error("Invalid image base, must be 0x10000-aligned\n");}
225                         | _STACKRESERVE int64                                   { PASM->m_stSizeOfStackReserve = (size_t)(*($2)); delete $2; }
226                         | languageDecl
227                         | typedefDecl
228                         | compControl
229                         | _TYPELIST '{' classNameSeq '}'
230                         | _MSCORLIB                                             { PASM->m_fIsMscorlib = TRUE; }
231                         ;
232                         
233 classNameSeq            : /* EMPTY */
234                         | className classNameSeq
235                         ;                        
236
237 compQstring             : QSTRING                                               { $$ = $1; }
238                         | compQstring '+' QSTRING                               { $$ = $1; $$->append($3); delete $3; }
239                         ;
240
241 languageDecl            : _LANGUAGE SQSTRING                                    { LPCSTRToGuid($2,&(PASM->m_guidLang)); }
242                         | _LANGUAGE SQSTRING ',' SQSTRING                       { LPCSTRToGuid($2,&(PASM->m_guidLang)); 
243                                                                                   LPCSTRToGuid($4,&(PASM->m_guidLangVendor));}
244                         | _LANGUAGE SQSTRING ',' SQSTRING ',' SQSTRING          { LPCSTRToGuid($2,&(PASM->m_guidLang)); 
245                                                                                   LPCSTRToGuid($4,&(PASM->m_guidLangVendor));
246                                                                                   LPCSTRToGuid($4,&(PASM->m_guidDoc));}
247                         ;
248 /*  Basic tokens  */                        
249 id                      : ID                                  { $$ = $1; }
250                         | SQSTRING                            { $$ = $1; }
251                         ;
252
253 dottedName              : id                                  { $$ = $1; }
254                         | DOTTEDNAME                          { $$ = $1; }
255                         | dottedName '.' dottedName           { $$ = newStringWDel($1, '.', $3); }
256                         ;
257
258 int32                   : INT32                               { $$ = $1; }
259                         ;
260
261 int64                   : INT64                               { $$ = $1; }
262                         | INT32                               { $$ = neg ? new __int64($1) : new __int64((unsigned)$1); }
263                         ;
264
265 float64                 : FLOAT64                             { $$ = $1; }
266                         | FLOAT32_ '(' int32 ')'              { float f; *((__int32*) (&f)) = $3; $$ = new double(f); }
267                         | FLOAT64_ '(' int64 ')'              { $$ = (double*) $3; }
268                         ;
269
270 /*  Aliasing of types, type specs, methods, fields and custom attributes */                        
271 typedefDecl             : _TYPEDEF type AS_ dottedName                          { PASM->AddTypeDef($2,$4); }
272                         | _TYPEDEF className AS_ dottedName                     { PASM->AddTypeDef($2,$4); }
273                         | _TYPEDEF memberRef AS_ dottedName                     { PASM->AddTypeDef($2,$4); }
274                         | _TYPEDEF customDescr AS_ dottedName                   { $2->tkOwner = 0; PASM->AddTypeDef($2,$4); }
275                         | _TYPEDEF customDescrWithOwner AS_ dottedName          { PASM->AddTypeDef($2,$4); }
276                         ;
277                         
278 /*  Compilation control directives are processed within yylex(), 
279     displayed here just for grammar completeness */
280 compControl             : P_DEFINE dottedName                                   { DefineVar($2, NULL); }
281                         | P_DEFINE dottedName compQstring                       { DefineVar($2, $3); }
282                         | P_UNDEF dottedName                                    { UndefVar($2); }
283                         | P_IFDEF dottedName                                    { SkipToken = !IsVarDefined($2);
284                                                                                   IfEndif++;
285                                                                                 }                        
286                         | P_IFNDEF dottedName                                   { SkipToken = IsVarDefined($2);
287                                                                                   IfEndif++;
288                                                                                 } 
289                         | P_ELSE                                                { if(IfEndif == 1) SkipToken = !SkipToken;}
290                         | P_ENDIF                                               { if(IfEndif == 0)
291                                                                                     PASM->report->error("Unmatched #endif\n");
292                                                                                   else IfEndif--;
293                                                                                 }
294                         | P_INCLUDE QSTRING                                     { _ASSERTE(!"yylex should have dealt with this"); }
295                         | ';'                                                   { }
296                         ; 
297                                               
298 /* Custom attribute declarations  */
299 customDescr             : _CUSTOM customType                                    { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, NULL); }
300                         | _CUSTOM customType '=' compQstring                    { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, $4); }
301                         | _CUSTOM customType '=' '{' customBlobDescr '}'        { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, $5); }
302                         | customHead bytes ')'                                  { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $1, $2); }
303                         ;
304
305 customDescrWithOwner    : _CUSTOM '(' ownerType ')' customType                  { $$ = new CustomDescr($3, $5, NULL); }
306                         | _CUSTOM '(' ownerType ')' customType '=' compQstring  { $$ = new CustomDescr($3, $5, $7); }
307                         | _CUSTOM '(' ownerType ')' customType '=' '{' customBlobDescr '}'
308                                                                                 { $$ = new CustomDescr($3, $5, $8); }
309                         | customHeadWithOwner bytes ')'                         { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $1, $2); }
310                         ;
311                         
312 customHead              : _CUSTOM customType '=' '('                            { $$ = $2; bParsingByteArray = TRUE; }
313                         ;
314
315 customHeadWithOwner     : _CUSTOM '(' ownerType ')' customType '=' '('        
316                                                                                 { PASM->m_pCustomDescrList = NULL;
317                                                                                   PASM->m_tkCurrentCVOwner = $3;
318                                                                                   $$ = $5; bParsingByteArray = TRUE; }
319                         ;
320
321 customType              : methodRef                         { $$ = $1; }
322                         ;
323
324 ownerType               : typeSpec                          { $$ = $1; }
325                         | memberRef                         { $$ = $1; }
326                         ;
327
328 /*  Verbal description of custom attribute initialization blob  */                        
329 customBlobDescr         : customBlobArgs customBlobNVPairs                      { $$ = $1; 
330                                                                                   $$->appendInt16(nCustomBlobNVPairs);
331                                                                                   $$->append($2);
332                                                                                   nCustomBlobNVPairs = 0; }
333                         ;
334                         
335 customBlobArgs          : /* EMPTY */                                           { $$ = new BinStr(); $$->appendInt16(VAL16(0x0001)); }
336                         | customBlobArgs serInit                                { $$ = $1;
337                                                                                   $$->appendFrom($2, (*($2->ptr()) == ELEMENT_TYPE_SZARRAY) ? 2 : 1); }
338                         | customBlobArgs compControl                            { $$ = $1; }
339                         ;
340                         
341 customBlobNVPairs       : /* EMPTY */                                           { $$ = new BinStr(); }
342                         | customBlobNVPairs fieldOrProp serializType dottedName '=' serInit
343                                                                                 { $$ = $1; $$->appendInt8($2);
344                                                                                   $$->append($3); 
345                                                                                   AppendStringWithLength($$,$4);
346                                                                                   $$->appendFrom($6, (*($6->ptr()) == ELEMENT_TYPE_SZARRAY) ? 2 : 1);
347                                                                                   nCustomBlobNVPairs++; }
348                         | customBlobNVPairs compControl                         { $$ = $1; }
349                         ;
350
351 fieldOrProp             : FIELD_                                                { $$ = SERIALIZATION_TYPE_FIELD; }
352                         | PROPERTY_                                             { $$ = SERIALIZATION_TYPE_PROPERTY; }
353                         ;
354
355 customAttrDecl          : customDescr                                           { if($1->tkOwner && !$1->tkInterfacePair) 
356                                                                                     PASM->DefineCV($1);
357                                                                                   else if(PASM->m_pCustomDescrList)
358                                                                                     PASM->m_pCustomDescrList->PUSH($1); }
359                         | customDescrWithOwner                                  { PASM->DefineCV($1); }
360                         | TYPEDEF_CA                                            { CustomDescr* pNew = new CustomDescr($1->m_pCA);
361                                                                                   if(pNew->tkOwner == 0) pNew->tkOwner = PASM->m_tkCurrentCVOwner;
362                                                                                   if(pNew->tkOwner) 
363                                                                                     PASM->DefineCV(pNew);
364                                                                                   else if(PASM->m_pCustomDescrList)
365                                                                                     PASM->m_pCustomDescrList->PUSH(pNew); }
366                         ;
367                         
368 serializType            : simpleType                          { $$ = $1; }
369                         | TYPE_                               { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE); }
370                         | OBJECT_                             { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TAGGED_OBJECT); }
371                         | ENUM_ CLASS_ SQSTRING               { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_ENUM);
372                                                                 AppendStringWithLength($$,$3); } 
373                         | ENUM_ className                     { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_ENUM);
374                                                                 AppendStringWithLength($$,PASM->ReflectionNotation($2)); } 
375                         | serializType '[' ']'                { $$ = $1; $$->insertInt8(ELEMENT_TYPE_SZARRAY); } 
376                         ;
377
378                         
379 /*  Module declaration */
380 moduleHead              : _MODULE                                               { PASMM->SetModuleName(NULL); PASM->m_tkCurrentCVOwner=1; }
381                         | _MODULE dottedName                                    { PASMM->SetModuleName($2); PASM->m_tkCurrentCVOwner=1; }
382                         | _MODULE EXTERN_ dottedName                            { BinStr* pbs = new BinStr();
383                                                                                   unsigned L = (unsigned)strlen($3);
384                                                                                   memcpy((char*)(pbs->getBuff(L)),$3,L);
385                                                                                   PASM->EmitImport(pbs); delete pbs;}
386                         ;
387                         
388 /*  VTable Fixup table declaration  */
389 vtfixupDecl             : _VTFIXUP '[' int32 ']' vtfixupAttr AT_ id             { /*PASM->SetDataSection(); PASM->EmitDataLabel($7);*/
390                                                                                   PASM->m_VTFList.PUSH(new VTFEntry((USHORT)$3, (USHORT)$5, $7)); }
391                         ;
392
393 vtfixupAttr             : /* EMPTY */                                           { $$ = 0; }
394                         | vtfixupAttr INT32_                                    { $$ = $1 | COR_VTABLE_32BIT; }
395                         | vtfixupAttr INT64_                                    { $$ = $1 | COR_VTABLE_64BIT; }
396                         | vtfixupAttr FROMUNMANAGED_                            { $$ = $1 | COR_VTABLE_FROM_UNMANAGED; }
397                         | vtfixupAttr CALLMOSTDERIVED_                          { $$ = $1 | COR_VTABLE_CALL_MOST_DERIVED; }
398                         | vtfixupAttr RETAINAPPDOMAIN_                          { $$ = $1 | COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN; }
399                         ;
400
401 vtableDecl              : vtableHead bytes ')'   /* deprecated */               { PASM->m_pVTable = $2; }
402                         ;
403
404 vtableHead              : _VTABLE '=' '('        /* deprecated */               { bParsingByteArray = TRUE; }
405                         ;
406
407 /*  Namespace and class declaration  */                         
408 nameSpaceHead           : _NAMESPACE dottedName                                 { PASM->StartNameSpace($2); }
409                         ;
410
411 _class                  : _CLASS                                                { newclass = TRUE; }
412                         ;
413                         
414 classHeadBegin          : _class classAttr dottedName typarsClause              { if($4) FixupConstraints();
415                                                                                   PASM->StartClass($3, $2, $4); 
416                                                                                   TyParFixupList.RESET(false);
417                                                                                   newclass = FALSE;
418                                                                                 }
419                         ;
420 classHead               : classHeadBegin extendsClause implClause               { PASM->AddClass(); }
421                         ;
422
423 classAttr               : /* EMPTY */                       { $$ = (CorRegTypeAttr) 0; }
424                         | classAttr PUBLIC_                 { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdPublic); }
425                         | classAttr PRIVATE_                { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNotPublic); }
426                         | classAttr VALUE_                  { $$ = (CorRegTypeAttr) ($1 | 0x80000000 | tdSealed); }
427                         | classAttr ENUM_                   { $$ = (CorRegTypeAttr) ($1 | 0x40000000); }
428                         | classAttr INTERFACE_              { $$ = (CorRegTypeAttr) ($1 | tdInterface | tdAbstract); }
429                         | classAttr SEALED_                 { $$ = (CorRegTypeAttr) ($1 | tdSealed); }
430                         | classAttr ABSTRACT_               { $$ = (CorRegTypeAttr) ($1 | tdAbstract); }
431                         | classAttr AUTO_                   { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdAutoLayout); }
432                         | classAttr SEQUENTIAL_             { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdSequentialLayout); }
433                         | classAttr EXPLICIT_               { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdExplicitLayout); }
434                         | classAttr ANSI_                   { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdAnsiClass); }
435                         | classAttr UNICODE_                { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdUnicodeClass); }
436                         | classAttr AUTOCHAR_               { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdAutoClass); }
437                         | classAttr IMPORT_                 { $$ = (CorRegTypeAttr) ($1 | tdImport); }
438                         | classAttr SERIALIZABLE_           { $$ = (CorRegTypeAttr) ($1 | tdSerializable); }
439                         | classAttr WINDOWSRUNTIME_         { $$ = (CorRegTypeAttr) ($1 | tdWindowsRuntime); }
440                         | classAttr NESTED_ PUBLIC_         { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedPublic); }
441                         | classAttr NESTED_ PRIVATE_        { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedPrivate); }
442                         | classAttr NESTED_ FAMILY_         { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamily); }
443                         | classAttr NESTED_ ASSEMBLY_       { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedAssembly); }
444                         | classAttr NESTED_ FAMANDASSEM_    { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamANDAssem); }
445                         | classAttr NESTED_ FAMORASSEM_     { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamORAssem); }
446                         | classAttr BEFOREFIELDINIT_        { $$ = (CorRegTypeAttr) ($1 | tdBeforeFieldInit); }
447                         | classAttr SPECIALNAME_            { $$ = (CorRegTypeAttr) ($1 | tdSpecialName); }
448                         | classAttr RTSPECIALNAME_          { $$ = (CorRegTypeAttr) ($1); }
449                         | classAttr FLAGS_ '(' int32 ')'    { $$ = (CorRegTypeAttr) ($4); }
450                         ;
451
452 extendsClause           : /* EMPTY */                                           
453                         | EXTENDS_ typeSpec                                 { PASM->m_crExtends = $2; }
454                         ;
455
456 implClause              : /* EMPTY */
457                         | IMPLEMENTS_ implList
458                         ;
459
460 classDecls              : /* EMPTY */
461                         | classDecls classDecl
462                         ;
463                         
464 implList                : implList ',' typeSpec             { PASM->AddToImplList($3); }
465                         | typeSpec                          { PASM->AddToImplList($1); }
466                                         ;
467
468 /* Generic type parameters declaration  */                         
469 typeList                : /* EMPTY */                       { $$ = new BinStr(); }
470                         | typeListNotEmpty                  { $$ = $1; }
471                         ;
472                         
473 typeListNotEmpty        : typeSpec                          { $$ = new BinStr(); $$->appendInt32($1); }
474                         | typeListNotEmpty ',' typeSpec     { $$ = $1; $$->appendInt32($3); }
475                         ;
476
477 typarsClause            : /* EMPTY */                       { $$ = NULL; PASM->m_TyParList = NULL;}
478                         | '<' typars '>'                    { $$ = $2;   PASM->m_TyParList = $2;}
479                         ;
480
481 typarAttrib             : '+'                               { $$ = gpCovariant; }
482                         | '-'                               { $$ = gpContravariant; }
483                         | CLASS_                            { $$ = gpReferenceTypeConstraint; }
484                         | VALUETYPE_                        { $$ = gpNotNullableValueTypeConstraint; }
485                         | _CTOR                             { $$ = gpDefaultConstructorConstraint; }
486                         ;
487                   
488 typarAttribs            : /* EMPTY */                       { $$ = 0; }
489                         | typarAttrib typarAttribs          { $$ = $1 | $2; }                         
490                         ;
491
492 typars                  : typarAttribs tyBound dottedName typarsRest {$$ = new TyParList($1, $2, $3, $4);}
493                         | typarAttribs dottedName typarsRest   {$$ = new TyParList($1, NULL, $2, $3);}
494                         ;
495
496 typarsRest              : /* EMPTY */                       { $$ = NULL; }
497                         | ',' typars                        { $$ = $2; }
498                         ;
499
500 tyBound                 : '(' typeList ')'                  { $$ = $2; }
501                         ;
502                         
503 genArity                : /* EMPTY */                       { $$= 0; }
504                         | genArityNotEmpty                  { $$ = $1; }
505                         ;                        
506
507 genArityNotEmpty        : '<' '[' int32 ']' '>'             { $$ = $3; }
508                         ;
509
510 /*  Class body declarations  */                         
511 classDecl               : methodHead  methodDecls '}'       { if(PASM->m_pCurMethod->m_ulLines[1] ==0)
512                                                               {  PASM->m_pCurMethod->m_ulLines[1] = PASM->m_ulCurLine;
513                                                                  PASM->m_pCurMethod->m_ulColumns[1]=PASM->m_ulCurColumn;}
514                                                               PASM->EndMethod(); }
515                         | classHead '{' classDecls '}'      { PASM->EndClass(); }
516                         | eventHead '{' eventDecls '}'      { PASM->EndEvent(); }
517                         | propHead '{' propDecls '}'        { PASM->EndProp(); }
518                         | fieldDecl
519                         | dataDecl
520                         | secDecl
521                         | extSourceSpec
522                         | customAttrDecl
523                         | _SIZE int32                           { PASM->m_pCurClass->m_ulSize = $2; }
524                         | _PACK int32                           { PASM->m_pCurClass->m_ulPack = $2; }
525                         | exportHead '{' exptypeDecls '}'       { PASMM->EndComType(); }
526                         | _OVERRIDE typeSpec DCOLON methodName WITH_ callConv type typeSpec DCOLON methodName '(' sigArgs0 ')'
527                                                                 { BinStr *sig1 = parser->MakeSig($6, $7, $12); 
528                                                                   BinStr *sig2 = new BinStr(); sig2->append(sig1); 
529                                                                   PASM->AddMethodImpl($2,$4,sig1,$8,$10,sig2);
530                                                                   PASM->ResetArgNameList(); 
531                                                                 } 
532                         | _OVERRIDE METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')' WITH_ METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')' 
533                                                                  { PASM->AddMethodImpl($5,$7,
534                                                                       ($8==0 ? parser->MakeSig($3,$4,$10) :
535                                                                       parser->MakeSig($3| IMAGE_CEE_CS_CALLCONV_GENERIC,$4,$10,$8)),
536                                                                       $16,$18,
537                                                                       ($19==0 ? parser->MakeSig($14,$15,$21) :
538                                                                       parser->MakeSig($14| IMAGE_CEE_CS_CALLCONV_GENERIC,$15,$21,$19))); 
539                                                                    PASM->ResetArgNameList();
540                                                                  }
541                         | languageDecl
542                         | compControl
543                         | PARAM_ TYPE_ '[' int32 ']'        { if(($4 > 0) && ($4 <= (int)PASM->m_pCurClass->m_NumTyPars))
544                                                                 PASM->m_pCustomDescrList = PASM->m_pCurClass->m_TyPars[$4-1].CAList();
545                                                               else
546                                                                 PASM->report->error("Type parameter index out of range\n");
547                                                             }
548                         | PARAM_ TYPE_ dottedName           { int n = PASM->m_pCurClass->FindTyPar($3);
549                                                               if(n >= 0)
550                                                                 PASM->m_pCustomDescrList = PASM->m_pCurClass->m_TyPars[n].CAList();
551                                                               else
552                                                                 PASM->report->error("Type parameter '%s' undefined\n",$3);
553                                                             }
554                         | _INTERFACEIMPL TYPE_ typeSpec customDescr   { $4->tkInterfacePair = $3;     
555                                                                         if(PASM->m_pCustomDescrList)
556                                                                             PASM->m_pCustomDescrList->PUSH($4);
557                                                                       }
558                         ;
559
560 /*  Field declaration  */                        
561 fieldDecl               : _FIELD repeatOpt fieldAttr type dottedName atOpt initOpt
562                                                             { $4->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
563                                                               PASM->AddField($5, $4, $3, $6, $7, $2); }
564                         ;
565
566 fieldAttr               : /* EMPTY */                       { $$ = (CorFieldAttr) 0; }
567                         | fieldAttr STATIC_                 { $$ = (CorFieldAttr) ($1 | fdStatic); }
568                         | fieldAttr PUBLIC_                 { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPublic); }
569                         | fieldAttr PRIVATE_                { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPrivate); }
570                         | fieldAttr FAMILY_                 { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamily); }
571                         | fieldAttr INITONLY_               { $$ = (CorFieldAttr) ($1 | fdInitOnly); }
572                         | fieldAttr RTSPECIALNAME_          { $$ = $1; } /*{ $$ = (CorFieldAttr) ($1 | fdRTSpecialName); }*/
573                         | fieldAttr SPECIALNAME_            { $$ = (CorFieldAttr) ($1 | fdSpecialName); }
574                                                 /* <STRIP>commented out because PInvoke for fields is not supported by EE
575                         | fieldAttr PINVOKEIMPL_ '(' compQstring AS_ compQstring pinvAttr ')'                   
576                                                             { $$ = (CorFieldAttr) ($1 | fdPinvokeImpl); 
577                                                               PASM->SetPinvoke($4,0,$6,$7); }
578                         | fieldAttr PINVOKEIMPL_ '(' compQstring  pinvAttr ')'                      
579                                                             { $$ = (CorFieldAttr) ($1 | fdPinvokeImpl); 
580                                                               PASM->SetPinvoke($4,0,NULL,$5); }
581                         | fieldAttr PINVOKEIMPL_ '(' pinvAttr ')'                       
582                                                             { PASM->SetPinvoke(new BinStr(),0,NULL,$4); 
583                                                               $$ = (CorFieldAttr) ($1 | fdPinvokeImpl); }
584                                                 </STRIP>*/
585                         | fieldAttr MARSHAL_ '(' marshalBlob ')'                 
586                                                             { PASM->m_pMarshal = $4; }
587                         | fieldAttr ASSEMBLY_               { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdAssembly); }
588                         | fieldAttr FAMANDASSEM_            { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamANDAssem); }
589                         | fieldAttr FAMORASSEM_             { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamORAssem); }
590                         | fieldAttr PRIVATESCOPE_           { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPrivateScope); }
591                         | fieldAttr LITERAL_                { $$ = (CorFieldAttr) ($1 | fdLiteral); }
592                         | fieldAttr NOTSERIALIZED_          { $$ = (CorFieldAttr) ($1 | fdNotSerialized); }
593                         | fieldAttr FLAGS_ '(' int32 ')'    { $$ = (CorFieldAttr) ($4); }
594                         ;
595
596 atOpt                   : /* EMPTY */                       { $$ = 0; } 
597                         | AT_ id                            { $$ = $2; }
598                         ;
599
600 initOpt                 : /* EMPTY */                       { $$ = NULL; }
601                         | '=' fieldInit                     { $$ = $2; }
602                                                 ;
603
604 repeatOpt               : /* EMPTY */                       { $$ = 0xFFFFFFFF; }
605                         | '[' int32 ']'                     { $$ = $2; }
606                                                 ;
607
608 /*  Method referencing  */
609 methodRef               : callConv type typeSpec DCOLON methodName tyArgs0 '(' sigArgs0 ')'
610                                                              { PASM->ResetArgNameList();
611                                                                if ($6 == NULL)
612                                                                {
613                                                                  if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n"); 
614                                                                  $$ = PASM->MakeMemberRef($3, $5, parser->MakeSig($1|iCallConv, $2, $8));
615                                                                }
616                                                                else
617                                                                {
618                                                                  mdToken mr;
619                                                                  if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n"); 
620                                                                  mr = PASM->MakeMemberRef($3, $5, 
621                                                                    parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $8, corCountArgs($6)));
622                                                                  $$ = PASM->MakeMethodSpec(mr, 
623                                                                    parser->MakeSig(IMAGE_CEE_CS_CALLCONV_INSTANTIATION, 0, $6));
624                                                                }
625                                                              }
626                         | callConv type typeSpec DCOLON methodName genArityNotEmpty '(' sigArgs0 ')'
627                                                              { PASM->ResetArgNameList();
628                                                                if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n"); 
629                                                                $$ = PASM->MakeMemberRef($3, $5, 
630                                                                  parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $8, $6));
631                                                              }
632                         | callConv type methodName tyArgs0 '(' sigArgs0 ')'
633                                                              { PASM->ResetArgNameList();
634                                                                if ($4 == NULL)
635                                                                {
636                                                                  if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n"); 
637                                                                  $$ = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1|iCallConv, $2, $6));
638                                                                }
639                                                                else
640                                                                {
641                                                                  mdToken mr;
642                                                                  if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n"); 
643                                                                  mr = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $6, corCountArgs($4)));
644                                                                  $$ = PASM->MakeMethodSpec(mr, 
645                                                                    parser->MakeSig(IMAGE_CEE_CS_CALLCONV_INSTANTIATION, 0, $4));
646                                                                }
647                                                              }
648                         | callConv type methodName genArityNotEmpty '(' sigArgs0 ')'
649                                                              { PASM->ResetArgNameList();
650                                                                if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n"); 
651                                                                $$ = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $6, $4));
652                                                              }
653                         | mdtoken                            { $$ = $1; }
654                         | TYPEDEF_M                          { $$ = $1->m_tkTypeSpec; }                                                             
655                         | TYPEDEF_MR                         { $$ = $1->m_tkTypeSpec; }                                                             
656                         ;
657                         
658 callConv                : INSTANCE_ callConv                  { $$ = ($2 | IMAGE_CEE_CS_CALLCONV_HASTHIS); }
659                         | EXPLICIT_ callConv                  { $$ = ($2 | IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS); }
660                         | callKind                            { $$ = $1; }
661                         | CALLCONV_ '(' int32 ')'             { $$ = $3; }
662                         ;
663
664 callKind                : /* EMPTY */                         { $$ = IMAGE_CEE_CS_CALLCONV_DEFAULT; }
665                         | DEFAULT_                            { $$ = IMAGE_CEE_CS_CALLCONV_DEFAULT; }
666                         | VARARG_                             { $$ = IMAGE_CEE_CS_CALLCONV_VARARG; }
667                         | UNMANAGED_ CDECL_                   { $$ = IMAGE_CEE_CS_CALLCONV_C; }
668                         | UNMANAGED_ STDCALL_                 { $$ = IMAGE_CEE_CS_CALLCONV_STDCALL; }
669                         | UNMANAGED_ THISCALL_                { $$ = IMAGE_CEE_CS_CALLCONV_THISCALL; }
670                         | UNMANAGED_ FASTCALL_                { $$ = IMAGE_CEE_CS_CALLCONV_FASTCALL; }
671                         ;
672
673 mdtoken                 : MDTOKEN_ '(' int32 ')'             { $$ = $3; }
674                         ;
675
676 memberRef               : methodSpec methodRef               { $$ = $2; 
677                                                                PASM->delArgNameList(PASM->m_firstArgName);
678                                                                PASM->m_firstArgName = parser->m_ANSFirst.POP();
679                                                                PASM->m_lastArgName = parser->m_ANSLast.POP();
680                                                                PASM->SetMemberRefFixup($2,iOpcodeLen); }
681                         | FIELD_ type typeSpec DCOLON dottedName
682                                                              { $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD); 
683                                                                $$ = PASM->MakeMemberRef($3, $5, $2); 
684                                                                PASM->SetMemberRefFixup($$,iOpcodeLen); }
685                         | FIELD_ type dottedName
686                                                              { $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD); 
687                                                                $$ = PASM->MakeMemberRef(NULL, $3, $2); 
688                                                                PASM->SetMemberRefFixup($$,iOpcodeLen); }
689                         | FIELD_ TYPEDEF_F                   { $$ = $2->m_tkTypeSpec;
690                                                                PASM->SetMemberRefFixup($$,iOpcodeLen); }
691                         | FIELD_ TYPEDEF_MR                  { $$ = $2->m_tkTypeSpec;
692                                                                PASM->SetMemberRefFixup($$,iOpcodeLen); }
693                         | mdtoken                            { $$ = $1; 
694                                                                PASM->SetMemberRefFixup($$,iOpcodeLen); }
695                         ;
696
697 /*  Event declaration  */                        
698 eventHead               : _EVENT eventAttr typeSpec dottedName   { PASM->ResetEvent($4, $3, $2); }
699                         | _EVENT eventAttr dottedName            { PASM->ResetEvent($3, mdTypeRefNil, $2); }
700                         ;
701
702
703 eventAttr               : /* EMPTY */                       { $$ = (CorEventAttr) 0; }
704                         | eventAttr RTSPECIALNAME_          { $$ = $1; }/*{ $$ = (CorEventAttr) ($1 | evRTSpecialName); }*/
705                         | eventAttr SPECIALNAME_            { $$ = (CorEventAttr) ($1 | evSpecialName); }
706                         ;
707
708 eventDecls              : /* EMPTY */
709                         | eventDecls eventDecl
710                         ;
711
712 eventDecl               : _ADDON methodRef                 { PASM->SetEventMethod(0, $2); }
713                         | _REMOVEON methodRef              { PASM->SetEventMethod(1, $2); }
714                         | _FIRE methodRef                  { PASM->SetEventMethod(2, $2); }
715                         | _OTHER methodRef                 { PASM->SetEventMethod(3, $2); }
716                         | extSourceSpec
717                         | customAttrDecl
718                         | languageDecl
719                         | compControl
720                         ;
721
722 /*  Property declaration  */                         
723 propHead                : _PROPERTY propAttr callConv type dottedName '(' sigArgs0 ')' initOpt     
724                                                             { PASM->ResetProp($5, 
725                                                               parser->MakeSig((IMAGE_CEE_CS_CALLCONV_PROPERTY |
726                                                               ($3 & IMAGE_CEE_CS_CALLCONV_HASTHIS)),$4,$7), $2, $9);}
727                         ;
728
729 propAttr                : /* EMPTY */                       { $$ = (CorPropertyAttr) 0; }
730                         | propAttr RTSPECIALNAME_           { $$ = $1; }/*{ $$ = (CorPropertyAttr) ($1 | prRTSpecialName); }*/
731                         | propAttr SPECIALNAME_             { $$ = (CorPropertyAttr) ($1 | prSpecialName); }
732                         ;
733
734 propDecls               : /* EMPTY */
735                         | propDecls propDecl
736                         ;
737
738
739 propDecl                : _SET methodRef                    { PASM->SetPropMethod(0, $2); }
740                         | _GET methodRef                    { PASM->SetPropMethod(1, $2); }
741                         | _OTHER methodRef                  { PASM->SetPropMethod(2, $2); }
742                         | customAttrDecl
743                         | extSourceSpec
744                         | languageDecl
745                         | compControl
746                         ;
747
748 /*  Method declaration  */
749 methodHeadPart1         : _METHOD                           { PASM->ResetForNextMethod(); 
750                                                               uMethodBeginLine = PASM->m_ulCurLine;
751                                                               uMethodBeginColumn=PASM->m_ulCurColumn;
752                                                             }
753                         ;
754                         
755 marshalClause           : /* EMPTY */                       { $$ = NULL; }
756                         | MARSHAL_ '(' marshalBlob ')'       { $$ = $3; }
757                         ;
758
759 marshalBlob             : nativeType                        { $$ = $1; }
760                         | marshalBlobHead hexbytes '}'       { $$ = $2; }
761                         ;
762
763 marshalBlobHead         : '{'                                { bParsingByteArray = TRUE; } 
764                         ;
765
766 methodHead              : methodHeadPart1 methAttr callConv paramAttr type marshalClause methodName typarsClause'(' sigArgs0 ')' implAttr '{'
767                                                             { BinStr* sig;
768                                                               if ($8 == NULL) sig = parser->MakeSig($3, $5, $10);
769                                                               else {
770                                                                FixupTyPars($5);
771                                                                sig = parser->MakeSig($3 | IMAGE_CEE_CS_CALLCONV_GENERIC, $5, $10, $8->Count());
772                                                                FixupConstraints();
773                                                               }
774                                                               PASM->StartMethod($7, sig, $2, $6, $4, $8);
775                                                               TyParFixupList.RESET(false);
776                                                               PASM->SetImplAttr((USHORT)$12);  
777                                                               PASM->m_pCurMethod->m_ulLines[0] = uMethodBeginLine;
778                                                               PASM->m_pCurMethod->m_ulColumns[0]=uMethodBeginColumn; 
779                                                             }
780                         ;
781
782 methAttr                : /* EMPTY */                       { $$ = (CorMethodAttr) 0; }
783                         | methAttr STATIC_                  { $$ = (CorMethodAttr) ($1 | mdStatic); }
784                         | methAttr PUBLIC_                  { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPublic); }
785                         | methAttr PRIVATE_                 { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPrivate); }
786                         | methAttr FAMILY_                  { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamily); }
787                         | methAttr FINAL_                   { $$ = (CorMethodAttr) ($1 | mdFinal); }
788                         | methAttr SPECIALNAME_             { $$ = (CorMethodAttr) ($1 | mdSpecialName); }
789                         | methAttr VIRTUAL_                 { $$ = (CorMethodAttr) ($1 | mdVirtual); }
790                         | methAttr STRICT_                  { $$ = (CorMethodAttr) ($1 | mdCheckAccessOnOverride); }
791                         | methAttr ABSTRACT_                { $$ = (CorMethodAttr) ($1 | mdAbstract); }
792                         | methAttr ASSEMBLY_                { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdAssem); }
793                         | methAttr FAMANDASSEM_             { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamANDAssem); }
794                         | methAttr FAMORASSEM_              { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamORAssem); }
795                         | methAttr PRIVATESCOPE_            { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPrivateScope); }
796                         | methAttr HIDEBYSIG_               { $$ = (CorMethodAttr) ($1 | mdHideBySig); }
797                         | methAttr NEWSLOT_                 { $$ = (CorMethodAttr) ($1 | mdNewSlot); }
798                         | methAttr RTSPECIALNAME_           { $$ = $1; }/*{ $$ = (CorMethodAttr) ($1 | mdRTSpecialName); }*/
799                         | methAttr UNMANAGEDEXP_            { $$ = (CorMethodAttr) ($1 | mdUnmanagedExport); }
800                         | methAttr REQSECOBJ_               { $$ = (CorMethodAttr) ($1 | mdRequireSecObject); }
801                         | methAttr FLAGS_ '(' int32 ')'     { $$ = (CorMethodAttr) ($4); }
802                         | methAttr PINVOKEIMPL_ '(' compQstring AS_ compQstring pinvAttr ')'                    
803                                                             { PASM->SetPinvoke($4,0,$6,$7); 
804                                                               $$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
805                         | methAttr PINVOKEIMPL_ '(' compQstring  pinvAttr ')'                       
806                                                             { PASM->SetPinvoke($4,0,NULL,$5); 
807                                                               $$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
808                         | methAttr PINVOKEIMPL_ '(' pinvAttr ')'                        
809                                                             { PASM->SetPinvoke(new BinStr(),0,NULL,$4); 
810                                                               $$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
811                         ;
812
813 pinvAttr                : /* EMPTY */                       { $$ = (CorPinvokeMap) 0; }
814                         | pinvAttr NOMANGLE_                { $$ = (CorPinvokeMap) ($1 | pmNoMangle); }
815                         | pinvAttr ANSI_                    { $$ = (CorPinvokeMap) ($1 | pmCharSetAnsi); }
816                         | pinvAttr UNICODE_                 { $$ = (CorPinvokeMap) ($1 | pmCharSetUnicode); }
817                         | pinvAttr AUTOCHAR_                { $$ = (CorPinvokeMap) ($1 | pmCharSetAuto); }
818                         | pinvAttr LASTERR_                 { $$ = (CorPinvokeMap) ($1 | pmSupportsLastError); }
819                         | pinvAttr WINAPI_                  { $$ = (CorPinvokeMap) ($1 | pmCallConvWinapi); }
820                         | pinvAttr CDECL_                   { $$ = (CorPinvokeMap) ($1 | pmCallConvCdecl); }
821                         | pinvAttr STDCALL_                 { $$ = (CorPinvokeMap) ($1 | pmCallConvStdcall); }
822                         | pinvAttr THISCALL_                { $$ = (CorPinvokeMap) ($1 | pmCallConvThiscall); }
823                         | pinvAttr FASTCALL_                { $$ = (CorPinvokeMap) ($1 | pmCallConvFastcall); }
824                         | pinvAttr BESTFIT_ ':' ON_         { $$ = (CorPinvokeMap) ($1 | pmBestFitEnabled); }
825                         | pinvAttr BESTFIT_ ':' OFF_        { $$ = (CorPinvokeMap) ($1 | pmBestFitDisabled); }
826                         | pinvAttr CHARMAPERROR_ ':' ON_    { $$ = (CorPinvokeMap) ($1 | pmThrowOnUnmappableCharEnabled); }
827                         | pinvAttr CHARMAPERROR_ ':' OFF_   { $$ = (CorPinvokeMap) ($1 | pmThrowOnUnmappableCharDisabled); }
828                         | pinvAttr FLAGS_ '(' int32 ')'     { $$ = (CorPinvokeMap) ($4); }
829                         ;
830
831 methodName              : _CTOR                             { $$ = newString(COR_CTOR_METHOD_NAME); }
832                         | _CCTOR                            { $$ = newString(COR_CCTOR_METHOD_NAME); }
833                         | dottedName                        { $$ = $1; }
834                         ;
835
836 paramAttr               : /* EMPTY */                       { $$ = 0; }
837                         | paramAttr '[' IN_ ']'             { $$ = $1 | pdIn; }
838                         | paramAttr '[' OUT_ ']'            { $$ = $1 | pdOut; }
839                         | paramAttr '[' OPT_ ']'            { $$ = $1 | pdOptional; }
840                         | paramAttr '[' int32 ']'           { $$ = $3 + 1; } 
841                         ;
842         
843 implAttr                : /* EMPTY */                       { $$ = (CorMethodImpl) (miIL | miManaged); }
844                         | implAttr NATIVE_                  { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miNative); }
845                         | implAttr CIL_                     { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miIL); }
846                         | implAttr OPTIL_                   { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miOPTIL); }
847                         | implAttr MANAGED_                 { $$ = (CorMethodImpl) (($1 & 0xFFFB) | miManaged); }
848                         | implAttr UNMANAGED_               { $$ = (CorMethodImpl) (($1 & 0xFFFB) | miUnmanaged); }
849                         | implAttr FORWARDREF_              { $$ = (CorMethodImpl) ($1 | miForwardRef); }
850                         | implAttr PRESERVESIG_             { $$ = (CorMethodImpl) ($1 | miPreserveSig); }
851                         | implAttr RUNTIME_                 { $$ = (CorMethodImpl) ($1 | miRuntime); }
852                         | implAttr INTERNALCALL_            { $$ = (CorMethodImpl) ($1 | miInternalCall); }
853                         | implAttr SYNCHRONIZED_            { $$ = (CorMethodImpl) ($1 | miSynchronized); }
854                         | implAttr NOINLINING_              { $$ = (CorMethodImpl) ($1 | miNoInlining); }
855                         | implAttr AGGRESSIVEINLINING_      { $$ = (CorMethodImpl) ($1 | miAggressiveInlining); }
856                         | implAttr NOOPTIMIZATION_          { $$ = (CorMethodImpl) ($1 | miNoOptimization); }
857                         | implAttr AGGRESSIVEOPTIMIZATION_  { $$ = (CorMethodImpl) ($1 | miAggressiveOptimization); }
858                         | implAttr FLAGS_ '(' int32 ')'     { $$ = (CorMethodImpl) ($4); }
859                         ;
860
861 localsHead              : _LOCALS                           { PASM->delArgNameList(PASM->m_firstArgName); PASM->m_firstArgName = NULL;PASM->m_lastArgName = NULL; 
862                                                             }
863                         ;
864
865 methodDecls             : /* EMPTY */
866                         | methodDecls methodDecl
867                         ;
868
869 methodDecl              : _EMITBYTE int32                   { PASM->EmitByte($2); }
870                         | sehBlock                          { delete PASM->m_SEHD; PASM->m_SEHD = PASM->m_SEHDstack.POP(); }
871                         | _MAXSTACK int32                   { PASM->EmitMaxStack($2); }
872                         | localsHead '(' sigArgs0 ')'       { PASM->EmitLocals(parser->MakeSig(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG, 0, $3)); 
873                                                             }
874                         | localsHead INIT_ '(' sigArgs0 ')' { PASM->EmitZeroInit(); 
875                                                               PASM->EmitLocals(parser->MakeSig(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG, 0, $4)); 
876                                                             }
877                         | _ENTRYPOINT                       { PASM->EmitEntryPoint(); }
878                         | _ZEROINIT                         { PASM->EmitZeroInit(); }
879                         | dataDecl
880                         | instr
881                         | id ':'                            { PASM->AddLabel(PASM->m_CurPC,$1); /*PASM->EmitLabel($1);*/ }
882                         | secDecl
883                         | extSourceSpec
884                         | languageDecl
885                         | customAttrDecl
886                         | compControl
887                         | _EXPORT '[' int32 ']'             { if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
888                                                               {
889                                                                 PASM->m_pCurMethod->m_dwExportOrdinal = $3;
890                                                                 PASM->m_pCurMethod->m_szExportAlias = NULL;
891                                                                 if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
892                                                                 if(PASM->m_pCurMethod->m_wVTSlot  == 0) PASM->m_pCurMethod->m_wVTSlot = $3 + 0x8000;
893                                                               }
894                                                               else
895                                                                 PASM->report->warn("Duplicate .export directive, ignored\n");
896                                                             }
897                         | _EXPORT '[' int32 ']' AS_ id      { if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
898                                                               {
899                                                                 PASM->m_pCurMethod->m_dwExportOrdinal = $3;
900                                                                 PASM->m_pCurMethod->m_szExportAlias = $6;
901                                                                 if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
902                                                                 if(PASM->m_pCurMethod->m_wVTSlot  == 0) PASM->m_pCurMethod->m_wVTSlot = $3 + 0x8000;
903                                                               }
904                                                               else
905                                                                 PASM->report->warn("Duplicate .export directive, ignored\n");
906                                                             }
907                         | _VTENTRY int32 ':' int32          { PASM->m_pCurMethod->m_wVTEntry = (WORD)$2;
908                                                               PASM->m_pCurMethod->m_wVTSlot = (WORD)$4; }
909                         | _OVERRIDE typeSpec DCOLON methodName 
910                                                             { PASM->AddMethodImpl($2,$4,NULL,NULL,NULL,NULL); }
911
912                         | _OVERRIDE METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')'
913                                                             { PASM->AddMethodImpl($5,$7,
914                                                               ($8==0 ? parser->MakeSig($3,$4,$10) :
915                                                               parser->MakeSig($3| IMAGE_CEE_CS_CALLCONV_GENERIC,$4,$10,$8))
916                                                               ,NULL,NULL,NULL); 
917                                                               PASM->ResetArgNameList();
918                                                             }
919                         | scopeBlock
920                         | PARAM_ TYPE_ '[' int32 ']'        { if(($4 > 0) && ($4 <= (int)PASM->m_pCurMethod->m_NumTyPars))
921                                                                 PASM->m_pCustomDescrList = PASM->m_pCurMethod->m_TyPars[$4-1].CAList();
922                                                               else
923                                                                 PASM->report->error("Type parameter index out of range\n");
924                                                             }
925                         | PARAM_ TYPE_ dottedName           { int n = PASM->m_pCurMethod->FindTyPar($3);
926                                                               if(n >= 0)
927                                                                 PASM->m_pCustomDescrList = PASM->m_pCurMethod->m_TyPars[n].CAList();
928                                                               else
929                                                                 PASM->report->error("Type parameter '%s' undefined\n",$3);
930                                                             }
931                         | PARAM_ '[' int32 ']' initOpt                            
932                                                             { if( $3 ) {
933                                                                 ARG_NAME_LIST* pAN=PASM->findArg(PASM->m_pCurMethod->m_firstArgName, $3 - 1);
934                                                                 if(pAN)
935                                                                 {
936                                                                     PASM->m_pCustomDescrList = &(pAN->CustDList);
937                                                                     pAN->pValue = $5;
938                                                                 }
939                                                                 else
940                                                                 {
941                                                                     PASM->m_pCustomDescrList = NULL;
942                                                                     if($5) delete $5;
943                                                                 }
944                                                               } else {
945                                                                 PASM->m_pCustomDescrList = &(PASM->m_pCurMethod->m_RetCustDList);
946                                                                 PASM->m_pCurMethod->m_pRetValue = $5;
947                                                               }
948                                                               PASM->m_tkCurrentCVOwner = 0;
949                                                             }
950                         ;
951
952 scopeBlock              : scopeOpen methodDecls '}'         { PASM->m_pCurMethod->CloseScope(); }
953                         ;
954
955 scopeOpen               : '{'                               { PASM->m_pCurMethod->OpenScope(); }
956                         ;
957
958 /* Structured exception handling directives  */                          
959 sehBlock                : tryBlock sehClauses
960                         ;
961
962 sehClauses              : sehClause sehClauses
963                         | sehClause
964                         ;
965
966 tryBlock                : tryHead scopeBlock                { PASM->m_SEHD->tryTo = PASM->m_CurPC; }
967                         | tryHead id TO_ id                 { PASM->SetTryLabels($2, $4); }
968                         | tryHead int32 TO_ int32           { if(PASM->m_SEHD) {PASM->m_SEHD->tryFrom = $2;
969                                                               PASM->m_SEHD->tryTo = $4;} }
970                         ;
971
972 tryHead                 : _TRY                              { PASM->NewSEHDescriptor();
973                                                               PASM->m_SEHD->tryFrom = PASM->m_CurPC; }
974                         ;
975
976
977 sehClause               : catchClause handlerBlock           { PASM->EmitTry(); }
978                         | filterClause handlerBlock          { PASM->EmitTry(); }
979                         | finallyClause handlerBlock         { PASM->EmitTry(); }
980                         | faultClause handlerBlock           { PASM->EmitTry(); }
981                         ;
982
983                                                                                                                                 
984 filterClause            : filterHead scopeBlock              { PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
985                         | filterHead id                      { PASM->SetFilterLabel($2); 
986                                                                PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
987                         | filterHead int32                   { PASM->m_SEHD->sehFilter = $2; 
988                                                                PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
989                         ;
990
991 filterHead              : FILTER_                            { PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FILTER;
992                                                                PASM->m_SEHD->sehFilter = PASM->m_CurPC; } 
993                         ;
994
995 catchClause             : CATCH_ typeSpec                   {  PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_NONE;
996                                                                PASM->SetCatchClass($2); 
997                                                                PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
998                         ;
999
1000 finallyClause           : FINALLY_                           { PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FINALLY;
1001                                                                PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
1002                         ;
1003
1004 faultClause             : FAULT_                             { PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FAULT;
1005                                                                PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
1006                         ;
1007
1008 handlerBlock            : scopeBlock                         { PASM->m_SEHD->sehHandlerTo = PASM->m_CurPC; }                 
1009                         | HANDLER_ id TO_ id                 { PASM->SetHandlerLabels($2, $4); }
1010                         | HANDLER_ int32 TO_ int32           { PASM->m_SEHD->sehHandler = $2;
1011                                                                PASM->m_SEHD->sehHandlerTo = $4; }
1012                         ;
1013
1014 /*  Data declaration  */
1015 dataDecl                : ddHead ddBody
1016                         ;
1017
1018 ddHead                  : _DATA tls id '='                   { PASM->EmitDataLabel($3); }
1019                         | _DATA tls  
1020                         ;
1021
1022 tls                     : /* EMPTY */                        { PASM->SetDataSection(); }
1023                         | TLS_                               { PASM->SetTLSSection(); }
1024                         | CIL_                               { PASM->SetILSection(); }
1025                         ;
1026
1027 ddBody                  : '{' ddItemList '}'
1028                         | ddItem
1029                         ;
1030
1031 ddItemList              : ddItem ',' ddItemList
1032                         | ddItem
1033                         ;
1034
1035 ddItemCount             : /* EMPTY */                        { $$ = 1; }
1036                         | '[' int32 ']'                      { $$ = $2;
1037                                                                if($2 <= 0) { PASM->report->error("Illegal item count: %d\n",$2);
1038                                                                   if(!PASM->OnErrGo) $$ = 1; }}
1039                         ;
1040
1041 ddItem                  : CHAR_ '*' '(' compQstring ')'      { PASM->EmitDataString($4); }
1042                         | '&' '(' id ')'                     { PASM->EmitDD($3); }
1043                         | bytearrayhead bytes ')'            { PASM->EmitData($2->ptr(),$2->length()); }
1044                         | FLOAT32_ '(' float64 ')' ddItemCount
1045                                                              { float f = (float) (*$3); float* p = new (nothrow) float[$5];
1046                                                                if(p != NULL) {
1047                                                                  for(int i=0; i < $5; i++) p[i] = f;
1048                                                                  PASM->EmitData(p, sizeof(float)*$5); delete $3; delete [] p; 
1049                                                                } else PASM->report->error("Out of memory emitting data block %d bytes\n",
1050                                                                      sizeof(float)*$5); }
1051                         | FLOAT64_ '(' float64 ')' ddItemCount
1052                                                              { double* p = new (nothrow) double[$5];
1053                                                                if(p != NULL) {
1054                                                                  for(int i=0; i<$5; i++) p[i] = *($3);
1055                                                                  PASM->EmitData(p, sizeof(double)*$5); delete $3; delete [] p;
1056                                                                } else PASM->report->error("Out of memory emitting data block %d bytes\n",
1057                                                                      sizeof(double)*$5); }
1058                         | INT64_ '(' int64 ')' ddItemCount
1059                                                              { __int64* p = new (nothrow) __int64[$5];
1060                                                                if(p != NULL) {
1061                                                                  for(int i=0; i<$5; i++) p[i] = *($3);
1062                                                                  PASM->EmitData(p, sizeof(__int64)*$5); delete $3; delete [] p;
1063                                                                } else PASM->report->error("Out of memory emitting data block %d bytes\n",
1064                                                                      sizeof(__int64)*$5); }
1065                         | INT32_ '(' int32 ')' ddItemCount
1066                                                              { __int32* p = new (nothrow) __int32[$5];
1067                                                                if(p != NULL) {
1068                                                                  for(int i=0; i<$5; i++) p[i] = $3;
1069                                                                  PASM->EmitData(p, sizeof(__int32)*$5); delete [] p;
1070                                                                } else PASM->report->error("Out of memory emitting data block %d bytes\n",
1071                                                                      sizeof(__int32)*$5); }
1072                         | INT16_ '(' int32 ')' ddItemCount
1073                                                              { __int16 i = (__int16) $3; FAIL_UNLESS(i == $3, ("Value %d too big\n", $3));
1074                                                                __int16* p = new (nothrow) __int16[$5];
1075                                                                if(p != NULL) {
1076                                                                  for(int j=0; j<$5; j++) p[j] = i;
1077                                                                  PASM->EmitData(p, sizeof(__int16)*$5); delete [] p;
1078                                                                } else PASM->report->error("Out of memory emitting data block %d bytes\n",
1079                                                                      sizeof(__int16)*$5); }
1080                         | INT8_ '(' int32 ')' ddItemCount
1081                                                              { __int8 i = (__int8) $3; FAIL_UNLESS(i == $3, ("Value %d too big\n", $3));
1082                                                                __int8* p = new (nothrow) __int8[$5];
1083                                                                if(p != NULL) {
1084                                                                  for(int j=0; j<$5; j++) p[j] = i;
1085                                                                  PASM->EmitData(p, sizeof(__int8)*$5); delete [] p;
1086                                                                } else PASM->report->error("Out of memory emitting data block %d bytes\n",
1087                                                                      sizeof(__int8)*$5); }
1088                         | FLOAT32_ ddItemCount               { PASM->EmitData(NULL, sizeof(float)*$2); }
1089                         | FLOAT64_ ddItemCount               { PASM->EmitData(NULL, sizeof(double)*$2); }
1090                         | INT64_ ddItemCount                 { PASM->EmitData(NULL, sizeof(__int64)*$2); }
1091                         | INT32_ ddItemCount                 { PASM->EmitData(NULL, sizeof(__int32)*$2); }
1092                         | INT16_ ddItemCount                 { PASM->EmitData(NULL, sizeof(__int16)*$2); }
1093                         | INT8_ ddItemCount                  { PASM->EmitData(NULL, sizeof(__int8)*$2); }
1094                         ;
1095
1096 /*  Default values declaration for fields, parameters and verbal form of CA blob description  */
1097 fieldSerInit            : FLOAT32_ '(' float64 ')'           { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R4);
1098                                                                float f = (float)(*$3);
1099                                                                $$->appendInt32(*((__int32*)&f)); delete $3; }
1100                         | FLOAT64_ '(' float64 ')'           { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R8); 
1101                                                                $$->appendInt64((__int64 *)$3); delete $3; }
1102                         | FLOAT32_ '(' int32 ')'             { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R4); 
1103                                                                $$->appendInt32($3); }
1104                         | FLOAT64_ '(' int64 ')'             { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R8); 
1105                                                                $$->appendInt64((__int64 *)$3); delete $3; }
1106                         | INT64_ '(' int64 ')'               { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I8); 
1107                                                                $$->appendInt64((__int64 *)$3); delete $3; } 
1108                         | INT32_ '(' int32 ')'               { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I4); 
1109                                                                $$->appendInt32($3); }
1110                         | INT16_ '(' int32 ')'               { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I2); 
1111                                                                $$->appendInt16($3); }
1112                         | INT8_ '(' int32 ')'                { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I1); 
1113                                                                $$->appendInt8($3); }
1114                         | UNSIGNED_ INT64_ '(' int64 ')'     { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8); 
1115                                                                $$->appendInt64((__int64 *)$4); delete $4; } 
1116                         | UNSIGNED_ INT32_ '(' int32 ')'     { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4); 
1117                                                                $$->appendInt32($4); }
1118                         | UNSIGNED_ INT16_ '(' int32 ')'     { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2); 
1119                                                                $$->appendInt16($4); }
1120                         | UNSIGNED_ INT8_ '(' int32 ')'      { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1); 
1121                                                                $$->appendInt8($4); }
1122                         | UINT64_ '(' int64 ')'              { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8); 
1123                                                                $$->appendInt64((__int64 *)$3); delete $3; } 
1124                         | UINT32_ '(' int32 ')'              { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4); 
1125                                                                $$->appendInt32($3); }
1126                         | UINT16_ '(' int32 ')'              { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2); 
1127                                                                $$->appendInt16($3); }
1128                         | UINT8_ '(' int32 ')'               { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1); 
1129                                                                $$->appendInt8($3); }
1130                         | CHAR_ '(' int32 ')'                { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_CHAR); 
1131                                                                $$->appendInt16($3); }
1132                         | BOOL_ '(' truefalse ')'            { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_BOOLEAN); 
1133                                                                $$->appendInt8($3);}
1134                         | bytearrayhead bytes ')'            { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING);
1135                                                                $$->append($2); delete $2;}
1136                         ;
1137                         
1138 bytearrayhead           : BYTEARRAY_ '('                     { bParsingByteArray = TRUE; }
1139                         ;
1140
1141 bytes                   : /* EMPTY */                        { $$ = new BinStr(); }
1142                         | hexbytes                           { $$ = $1; }
1143                         ;
1144
1145 hexbytes                : HEXBYTE                            { __int8 i = (__int8) $1; $$ = new BinStr(); $$->appendInt8(i); }
1146                         | hexbytes HEXBYTE                   { __int8 i = (__int8) $2; $$ = $1; $$->appendInt8(i); }
1147                         ;
1148
1149 /*  Field/parameter initialization  */
1150 fieldInit               : fieldSerInit                       { $$ = $1; }
1151                         | compQstring                        { $$ = BinStrToUnicode($1,true); $$->insertInt8(ELEMENT_TYPE_STRING);}
1152                         | NULLREF_                           { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_CLASS); 
1153                                                                $$->appendInt32(0); }
1154                         ;                        
1155
1156 /*  Values for verbal form of CA blob description  */
1157 serInit                 : fieldSerInit                       { $$ = $1; }
1158                         | STRING_ '(' NULLREF_ ')'           { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING); $$->appendInt8(0xFF); }
1159                         | STRING_ '(' SQSTRING ')'           { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING); 
1160                                                                AppendStringWithLength($$,$3); delete [] $3;}
1161                         | TYPE_ '(' CLASS_ SQSTRING ')'      { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE); 
1162                                                                AppendStringWithLength($$,$4); delete [] $4;}
1163                         | TYPE_ '(' className ')'            { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE); 
1164                                                                AppendStringWithLength($$,PASM->ReflectionNotation($3));}
1165                         | TYPE_ '(' NULLREF_ ')'             { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE); $$->appendInt8(0xFF); }
1166                         | OBJECT_ '(' serInit ')'            { $$ = $3; $$->insertInt8(SERIALIZATION_TYPE_TAGGED_OBJECT);} 
1167                         | FLOAT32_ '[' int32 ']' '(' f32seq ')'
1168                                                              { $$ = $6; $$->insertInt32($3);
1169                                                                $$->insertInt8(ELEMENT_TYPE_R4);
1170                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1171                         | FLOAT64_ '[' int32 ']' '(' f64seq ')'
1172                                                              { $$ = $6; $$->insertInt32($3);
1173                                                                $$->insertInt8(ELEMENT_TYPE_R8);
1174                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1175                         | INT64_ '[' int32 ']' '(' i64seq ')'
1176                                                              { $$ = $6; $$->insertInt32($3);
1177                                                                $$->insertInt8(ELEMENT_TYPE_I8);
1178                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1179                         | INT32_ '[' int32 ']' '(' i32seq ')'
1180                                                              { $$ = $6; $$->insertInt32($3);
1181                                                                $$->insertInt8(ELEMENT_TYPE_I4);
1182                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1183                         | INT16_ '[' int32 ']' '(' i16seq ')'
1184                                                              { $$ = $6; $$->insertInt32($3);
1185                                                                $$->insertInt8(ELEMENT_TYPE_I2);
1186                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1187                         | INT8_ '[' int32 ']' '(' i8seq ')'
1188                                                              { $$ = $6; $$->insertInt32($3);
1189                                                                $$->insertInt8(ELEMENT_TYPE_I1);
1190                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1191                         | UINT64_ '[' int32 ']' '(' i64seq ')'
1192                                                              { $$ = $6; $$->insertInt32($3);
1193                                                                $$->insertInt8(ELEMENT_TYPE_U8);
1194                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1195                         | UINT32_ '[' int32 ']' '(' i32seq ')'
1196                                                              { $$ = $6; $$->insertInt32($3);
1197                                                                $$->insertInt8(ELEMENT_TYPE_U4);
1198                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1199                         | UINT16_ '[' int32 ']' '(' i16seq ')'
1200                                                              { $$ = $6; $$->insertInt32($3);
1201                                                                $$->insertInt8(ELEMENT_TYPE_U2);
1202                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1203                         | UINT8_ '[' int32 ']' '(' i8seq ')'
1204                                                              { $$ = $6; $$->insertInt32($3);
1205                                                                $$->insertInt8(ELEMENT_TYPE_U1);
1206                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1207                         | UNSIGNED_ INT64_ '[' int32 ']' '(' i64seq ')'
1208                                                              { $$ = $7; $$->insertInt32($4);
1209                                                                $$->insertInt8(ELEMENT_TYPE_U8);
1210                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1211                         | UNSIGNED_ INT32_ '[' int32 ']' '(' i32seq ')'
1212                                                              { $$ = $7; $$->insertInt32($4);
1213                                                                $$->insertInt8(ELEMENT_TYPE_U4);
1214                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1215                         | UNSIGNED_ INT16_ '[' int32 ']' '(' i16seq ')'
1216                                                              { $$ = $7; $$->insertInt32($4);
1217                                                                $$->insertInt8(ELEMENT_TYPE_U2);
1218                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1219                         | UNSIGNED_ INT8_ '[' int32 ']' '(' i8seq ')'
1220                                                              { $$ = $7; $$->insertInt32($4);
1221                                                                $$->insertInt8(ELEMENT_TYPE_U1);
1222                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1223                         | CHAR_ '[' int32 ']' '(' i16seq ')'
1224                                                              { $$ = $6; $$->insertInt32($3);
1225                                                                $$->insertInt8(ELEMENT_TYPE_CHAR);
1226                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1227                         | BOOL_ '[' int32 ']' '(' boolSeq ')'
1228                                                              { $$ = $6; $$->insertInt32($3);
1229                                                                $$->insertInt8(ELEMENT_TYPE_BOOLEAN);
1230                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1231                         | STRING_ '[' int32 ']' '(' sqstringSeq ')'
1232                                                              { $$ = $6; $$->insertInt32($3);
1233                                                                $$->insertInt8(ELEMENT_TYPE_STRING);
1234                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1235                         | TYPE_ '[' int32 ']' '(' classSeq ')'
1236                                                              { $$ = $6; $$->insertInt32($3);
1237                                                                $$->insertInt8(SERIALIZATION_TYPE_TYPE);
1238                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1239                         | OBJECT_ '[' int32 ']' '(' objSeq ')'
1240                                                              { $$ = $6; $$->insertInt32($3);
1241                                                                $$->insertInt8(SERIALIZATION_TYPE_TAGGED_OBJECT);
1242                                                                $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
1243                         ;
1244
1245
1246 f32seq                  : /* EMPTY */                        { $$ = new BinStr(); }
1247                         | f32seq float64                     { $$ = $1;
1248                                                                float f = (float) (*$2); $$->appendInt32(*((__int32*)&f)); delete $2; }
1249                         | f32seq int32                       { $$ = $1; 
1250                                                                $$->appendInt32($2); }
1251                         ;
1252                                                                
1253 f64seq                  : /* EMPTY */                        { $$ = new BinStr(); }
1254                         | f64seq float64                     { $$ = $1; 
1255                                                                $$->appendInt64((__int64 *)$2); delete $2; }
1256                         | f64seq int64                       { $$ = $1; 
1257                                                                $$->appendInt64((__int64 *)$2); delete $2; }
1258                         ;
1259                         
1260 i64seq                  : /* EMPTY */                        { $$ = new BinStr(); }
1261                         | i64seq int64                       { $$ = $1; 
1262                                                                $$->appendInt64((__int64 *)$2); delete $2; }
1263                         ;
1264                         
1265 i32seq                  : /* EMPTY */                        { $$ = new BinStr(); }
1266                         | i32seq int32                       { $$ = $1; $$->appendInt32($2);}
1267                         ;
1268                         
1269 i16seq                  : /* EMPTY */                        { $$ = new BinStr(); }
1270                         | i16seq int32                       { $$ = $1; $$->appendInt16($2);}
1271                         ;
1272                         
1273 i8seq                   : /* EMPTY */                        { $$ = new BinStr(); }
1274                         | i8seq int32                        { $$ = $1; $$->appendInt8($2); }
1275                         ;
1276                         
1277 boolSeq                 : /* EMPTY */                        { $$ = new BinStr(); }
1278                         | boolSeq truefalse                  { $$ = $1; 
1279                                                                $$->appendInt8($2);}
1280                         ;
1281                         
1282 sqstringSeq             : /* EMPTY */                        { $$ = new BinStr(); }
1283                         | sqstringSeq NULLREF_               { $$ = $1; $$->appendInt8(0xFF); }
1284                         | sqstringSeq SQSTRING               { $$ = $1; 
1285                                                                AppendStringWithLength($$,$2); delete [] $2;}
1286                         ;
1287                         
1288 classSeq                : /* EMPTY */                        { $$ = new BinStr(); }
1289                         | classSeq NULLREF_                  { $$ = $1; $$->appendInt8(0xFF); }
1290                         | classSeq CLASS_ SQSTRING           { $$ = $1; 
1291                                                                AppendStringWithLength($$,$3); delete [] $3;}
1292                         | classSeq className                 { $$ = $1; 
1293                                                                AppendStringWithLength($$,PASM->ReflectionNotation($2));}
1294                         ;
1295                         
1296 objSeq                  : /* EMPTY */                        { $$ = new BinStr(); }
1297                         | objSeq serInit                     { $$ = $1; $$->append($2); delete $2; }
1298                         ;
1299
1300 /*  IL instructions and associated definitions  */
1301 methodSpec              : METHOD_                            { parser->m_ANSFirst.PUSH(PASM->m_firstArgName);
1302                                                                parser->m_ANSLast.PUSH(PASM->m_lastArgName);   
1303                                                                PASM->m_firstArgName = NULL;
1304                                                                PASM->m_lastArgName = NULL; }
1305                         ;
1306                         
1307 instr_none              : INSTR_NONE                         { $$ = SetupInstr($1); }
1308                         ;
1309
1310 instr_var               : INSTR_VAR                          { $$ = SetupInstr($1); }
1311                         ;
1312
1313 instr_i                 : INSTR_I                            { $$ = SetupInstr($1); }
1314                         ;
1315
1316 instr_i8                : INSTR_I8                           { $$ = SetupInstr($1); }
1317                         ;
1318
1319 instr_r                 : INSTR_R                            { $$ = SetupInstr($1); }
1320                         ;
1321
1322 instr_brtarget          : INSTR_BRTARGET                     { $$ = SetupInstr($1); }
1323                         ;
1324
1325 instr_method            : INSTR_METHOD                       { $$ = SetupInstr($1); 
1326                                                                if((!PASM->OnErrGo)&&
1327                                                                (($1 == CEE_NEWOBJ)||
1328                                                                 ($1 == CEE_CALLVIRT))) 
1329                                                                   iCallConv = IMAGE_CEE_CS_CALLCONV_HASTHIS;
1330                                                              }
1331                         ;
1332
1333 instr_field             : INSTR_FIELD                        { $$ = SetupInstr($1); }
1334                         ;
1335
1336 instr_type              : INSTR_TYPE                         { $$ = SetupInstr($1); }
1337                         ;
1338
1339 instr_string            : INSTR_STRING                       { $$ = SetupInstr($1); }
1340                         ;
1341
1342 instr_sig               : INSTR_SIG                          { $$ = SetupInstr($1); }
1343                         ;
1344
1345 instr_tok               : INSTR_TOK                          { $$ = SetupInstr($1); iOpcodeLen = PASM->OpcodeLen($$); }
1346                         ;
1347
1348 instr_switch            : INSTR_SWITCH                       { $$ = SetupInstr($1); }
1349                         ;
1350
1351 instr_r_head            : instr_r '('                        { $$ = $1; bParsingByteArray = TRUE; }
1352                         ;
1353
1354
1355 instr                   : instr_none                         { PASM->EmitOpcode($1); }
1356                         | instr_var int32                    { PASM->EmitInstrVar($1, $2); }
1357                         | instr_var id                       { PASM->EmitInstrVarByName($1, $2); }
1358                         | instr_i int32                      { PASM->EmitInstrI($1, $2); }
1359                         | instr_i8 int64                     { PASM->EmitInstrI8($1, $2); }
1360                         | instr_r float64                    { PASM->EmitInstrR($1, $2); delete ($2);}
1361                         | instr_r int64                      { double f = (double) (*$2); PASM->EmitInstrR($1, &f); }
1362                         | instr_r_head bytes ')'             { unsigned L = $2->length();
1363                                                                FAIL_UNLESS(L >= sizeof(float), ("%d hexbytes, must be at least %d\n",
1364                                                                            L,sizeof(float))); 
1365                                                                if(L < sizeof(float)) {YYERROR; } 
1366                                                                else {
1367                                                                    double f = (L >= sizeof(double)) ? *((double *)($2->ptr()))
1368                                                                                     : (double)(*(float *)($2->ptr())); 
1369                                                                    PASM->EmitInstrR($1,&f); }
1370                                                                delete $2; }
1371                         | instr_brtarget int32               { PASM->EmitInstrBrOffset($1, $2); }
1372                         | instr_brtarget id                  { PASM->EmitInstrBrTarget($1, $2); }
1373                         | instr_method methodRef
1374                                                              { PASM->SetMemberRefFixup($2,PASM->OpcodeLen($1));
1375                                                                PASM->EmitInstrI($1,$2);
1376                                                                PASM->m_tkCurrentCVOwner = $2;
1377                                                                PASM->m_pCustomDescrList = NULL;
1378                                                                iCallConv = 0;
1379                                                              }
1380                         | instr_field type typeSpec DCOLON dottedName
1381                                                              { $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD); 
1382                                                                mdToken mr = PASM->MakeMemberRef($3, $5, $2);
1383                                                                PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
1384                                                                PASM->EmitInstrI($1,mr);
1385                                                                PASM->m_tkCurrentCVOwner = mr;
1386                                                                PASM->m_pCustomDescrList = NULL;
1387                                                              }
1388                         | instr_field type dottedName
1389                                                              { $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD); 
1390                                                                mdToken mr = PASM->MakeMemberRef(mdTokenNil, $3, $2);
1391                                                                PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
1392                                                                PASM->EmitInstrI($1,mr);
1393                                                                PASM->m_tkCurrentCVOwner = mr;
1394                                                                PASM->m_pCustomDescrList = NULL;
1395                                                              }
1396                         | instr_field mdtoken                { mdToken mr = $2;
1397                                                                PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
1398                                                                PASM->EmitInstrI($1,mr);
1399                                                                PASM->m_tkCurrentCVOwner = mr;
1400                                                                PASM->m_pCustomDescrList = NULL;
1401                                                              }
1402                         | instr_field TYPEDEF_F              { mdToken mr = $2->m_tkTypeSpec;
1403                                                                PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
1404                                                                PASM->EmitInstrI($1,mr);
1405                                                                PASM->m_tkCurrentCVOwner = mr;
1406                                                                PASM->m_pCustomDescrList = NULL;
1407                                                              }
1408                         | instr_field TYPEDEF_MR             { mdToken mr = $2->m_tkTypeSpec;
1409                                                                PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
1410                                                                PASM->EmitInstrI($1,mr);
1411                                                                PASM->m_tkCurrentCVOwner = mr;
1412                                                                PASM->m_pCustomDescrList = NULL;
1413                                                              }
1414                         | instr_type typeSpec                { PASM->EmitInstrI($1, $2); 
1415                                                                PASM->m_tkCurrentCVOwner = $2;
1416                                                                PASM->m_pCustomDescrList = NULL;
1417                                                              }
1418                         | instr_string compQstring           { PASM->EmitInstrStringLiteral($1, $2,TRUE); }
1419                         | instr_string ANSI_ '(' compQstring ')'
1420                                                              { PASM->EmitInstrStringLiteral($1, $4,FALSE); }
1421                         | instr_string bytearrayhead bytes ')'
1422                                                              { PASM->EmitInstrStringLiteral($1, $3,FALSE,TRUE); }
1423                         | instr_sig callConv type '(' sigArgs0 ')'      
1424                                                              { PASM->EmitInstrSig($1, parser->MakeSig($2, $3, $5)); 
1425                                                                PASM->ResetArgNameList();
1426                                                              }
1427                         | instr_tok ownerType /* ownerType ::= memberRef | typeSpec */
1428                                                              { PASM->EmitInstrI($1,$2);
1429                                                                PASM->m_tkCurrentCVOwner = $2;
1430                                                                PASM->m_pCustomDescrList = NULL;
1431                                                                iOpcodeLen = 0;
1432                                                              }
1433                         | instr_switch '(' labels ')'        { PASM->EmitInstrSwitch($1, $3); }
1434                         ;
1435                         
1436 labels                  : /* empty */                         { $$ = 0; }
1437                         | id ',' labels                       { $$ = new Labels($1, $3, TRUE); }
1438                         | int32 ',' labels                    { $$ = new Labels((char *)(UINT_PTR)$1, $3, FALSE); }
1439                         | id                                  { $$ = new Labels($1, NULL, TRUE); }
1440                         | int32                               { $$ = new Labels((char *)(UINT_PTR)$1, NULL, FALSE); }
1441                         ;
1442
1443 /*  Signatures  */
1444 tyArgs0                 : /* EMPTY */                        { $$ = NULL; }
1445                         | '<' tyArgs1 '>'                    { $$ = $2; }
1446                         ;
1447
1448 tyArgs1                 : /* EMPTY */                        { $$ = NULL; }
1449                         | tyArgs2                            { $$ = $1; }
1450                         ;
1451
1452 tyArgs2                 : type                               { $$ = $1; }
1453                         | tyArgs2 ',' type                   { $$ = $1; $$->append($3); delete $3; }
1454                         ;
1455
1456
1457 sigArgs0                : /* EMPTY */                        { $$ = new BinStr(); }
1458                         | sigArgs1                           { $$ = $1;}
1459                         ;
1460
1461 sigArgs1                : sigArg                             { $$ = $1; }
1462                         | sigArgs1 ',' sigArg                { $$ = $1; $$->append($3); delete $3; }
1463                         ;
1464
1465 sigArg                  : ELIPSIS                             { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_SENTINEL); }
1466                         | paramAttr type marshalClause        { $$ = new BinStr(); $$->append($2); PASM->addArgName(NULL, $2, $3, $1); }
1467                         | paramAttr type marshalClause id     { $$ = new BinStr(); $$->append($2); PASM->addArgName($4, $2, $3, $1);}
1468                         ;
1469
1470 /*  Class referencing  */
1471 className               : '[' dottedName ']' slashedName      { $$ = PASM->ResolveClassRef(PASM->GetAsmRef($2), $4, NULL); delete[] $2;}
1472                         | '[' mdtoken ']' slashedName         { $$ = PASM->ResolveClassRef($2, $4, NULL); }
1473                         | '[' '*' ']' slashedName             { $$ = PASM->ResolveClassRef(mdTokenNil, $4, NULL); }
1474                         | '[' _MODULE dottedName ']' slashedName   { $$ = PASM->ResolveClassRef(PASM->GetModRef($3),$5, NULL); delete[] $3;}
1475                         | slashedName                         { $$ = PASM->ResolveClassRef(1,$1,NULL); }
1476                         | mdtoken                             { $$ = $1; }
1477                         | TYPEDEF_T                           { $$ = $1->m_tkTypeSpec; }
1478                         | _THIS                               { if(PASM->m_pCurClass != NULL) $$ = PASM->m_pCurClass->m_cl;
1479                                                                 else { $$ = 0; PASM->report->error(".this outside class scope\n"); } 
1480                                                               }
1481                         | _BASE                               { if(PASM->m_pCurClass != NULL) {
1482                                                                   $$ = PASM->m_pCurClass->m_crExtends;
1483                                                                   if(RidFromToken($$) == 0)
1484                                                                     PASM->report->error(".base undefined\n");
1485                                                                 } else { $$ = 0; PASM->report->error(".base outside class scope\n"); } 
1486                                                               }
1487                         | _NESTER                             { if(PASM->m_pCurClass != NULL) {
1488                                                                   if(PASM->m_pCurClass->m_pEncloser != NULL) $$ = PASM->m_pCurClass->m_pEncloser->m_cl;
1489                                                                   else { $$ = 0; PASM->report->error(".nester undefined\n"); }
1490                                                                 } else { $$ = 0; PASM->report->error(".nester outside class scope\n"); } 
1491                                                               }
1492                         ;
1493
1494 slashedName             : dottedName                          { $$ = $1; }
1495                         | slashedName '/' dottedName          { $$ = newStringWDel($1, NESTING_SEP, $3); }
1496                         ;
1497
1498 typeSpec                : className                           { $$ = $1;}
1499                         | '[' dottedName ']'                  { $$ = PASM->GetAsmRef($2); delete[] $2;}
1500                         | '[' _MODULE dottedName ']'          { $$ = PASM->GetModRef($3); delete[] $3;}
1501                         | type                                { $$ = PASM->ResolveTypeSpec($1); }
1502                         ;
1503
1504 /*  Native types for marshaling signatures  */                         
1505 nativeType              : /* EMPTY */                         { $$ = new BinStr(); } 
1506                         | CUSTOM_ '(' compQstring ',' compQstring ',' compQstring ',' compQstring ')'
1507                                                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_CUSTOMMARSHALER);
1508                                                                 corEmitInt($$,$3->length()); $$->append($3);
1509                                                                 corEmitInt($$,$5->length()); $$->append($5);
1510                                                                 corEmitInt($$,$7->length()); $$->append($7);
1511                                                                 corEmitInt($$,$9->length()); $$->append($9); 
1512                                                                 PASM->report->warn("Deprecated 4-string form of custom marshaler, first two strings ignored\n");}
1513                         | CUSTOM_ '(' compQstring ',' compQstring ')'
1514                                                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_CUSTOMMARSHALER);
1515                                                                 corEmitInt($$,0);
1516                                                                 corEmitInt($$,0);
1517                                                                 corEmitInt($$,$3->length()); $$->append($3);
1518                                                                 corEmitInt($$,$5->length()); $$->append($5); }
1519                         | FIXED_ SYSSTRING_ '[' int32 ']'     { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_FIXEDSYSSTRING);
1520                                                                 corEmitInt($$,$4); }
1521                         | FIXED_ ARRAY_ '[' int32 ']' nativeType
1522                                                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_FIXEDARRAY);
1523                                                                 corEmitInt($$,$4); $$->append($6); }
1524                         | VARIANT_                            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_VARIANT); 
1525                                                                 PASM->report->warn("Deprecated native type 'variant'\n"); }
1526                         | CURRENCY_                           { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_CURRENCY); }
1527                         | SYSCHAR_                            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_SYSCHAR); 
1528                                                                 PASM->report->warn("Deprecated native type 'syschar'\n"); }
1529                         | VOID_                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_VOID); 
1530                                                                 PASM->report->warn("Deprecated native type 'void'\n"); }
1531                         | BOOL_                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_BOOLEAN); }
1532                         | INT8_                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_I1); }
1533                         | INT16_                              { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_I2); }
1534                         | INT32_                              { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_I4); }
1535                         | INT64_                              { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_I8); }
1536                         | FLOAT32_                            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_R4); }
1537                         | FLOAT64_                            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_R8); }
1538                         | ERROR_                              { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_ERROR); }
1539                         | UNSIGNED_ INT8_                     { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U1); }
1540                         | UNSIGNED_ INT16_                    { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U2); }
1541                         | UNSIGNED_ INT32_                    { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U4); }
1542                         | UNSIGNED_ INT64_                    { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U8); }
1543                         | UINT8_                              { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U1); }
1544                         | UINT16_                             { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U2); }
1545                         | UINT32_                             { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U4); }
1546                         | UINT64_                             { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U8); }
1547                         | nativeType '*'                      { $$ = $1; $$->insertInt8(NATIVE_TYPE_PTR); 
1548                                                                 PASM->report->warn("Deprecated native type '*'\n"); }
1549                         | nativeType '[' ']'                  { $$ = $1; if($$->length()==0) $$->appendInt8(NATIVE_TYPE_MAX);
1550                                                                 $$->insertInt8(NATIVE_TYPE_ARRAY); }
1551                         | nativeType '[' int32 ']'            { $$ = $1; if($$->length()==0) $$->appendInt8(NATIVE_TYPE_MAX); 
1552                                                                 $$->insertInt8(NATIVE_TYPE_ARRAY);
1553                                                                 corEmitInt($$,0);
1554                                                                 corEmitInt($$,$3); 
1555                                                                 corEmitInt($$,0); }
1556                         | nativeType '[' int32 '+' int32 ']'  { $$ = $1; if($$->length()==0) $$->appendInt8(NATIVE_TYPE_MAX); 
1557                                                                 $$->insertInt8(NATIVE_TYPE_ARRAY);
1558                                                                 corEmitInt($$,$5);
1559                                                                 corEmitInt($$,$3);
1560                                                                 corEmitInt($$,ntaSizeParamIndexSpecified); }
1561                         | nativeType '[' '+' int32 ']'        { $$ = $1; if($$->length()==0) $$->appendInt8(NATIVE_TYPE_MAX); 
1562                                                                 $$->insertInt8(NATIVE_TYPE_ARRAY);
1563                                                                 corEmitInt($$,$4); }
1564                         | DECIMAL_                            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_DECIMAL); 
1565                                                                 PASM->report->warn("Deprecated native type 'decimal'\n"); }
1566                         | DATE_                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_DATE); 
1567                                                                 PASM->report->warn("Deprecated native type 'date'\n"); }
1568                         | BSTR_                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_BSTR); }
1569                         | LPSTR_                              { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_LPSTR); }
1570                         | LPWSTR_                             { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_LPWSTR); }
1571                         | LPTSTR_                             { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_LPTSTR); }
1572                         | OBJECTREF_                          { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_OBJECTREF); 
1573                                                                 PASM->report->warn("Deprecated native type 'objectref'\n"); }
1574                         | IUNKNOWN_  iidParamIndex            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_IUNKNOWN);
1575                                                                 if($2 != -1) corEmitInt($$,$2); }
1576                         | IDISPATCH_ iidParamIndex            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_IDISPATCH); 
1577                                                                 if($2 != -1) corEmitInt($$,$2); }
1578                         | STRUCT_                             { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_STRUCT); }
1579                         | INTERFACE_ iidParamIndex            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_INTF);
1580                                                                 if($2 != -1) corEmitInt($$,$2); }
1581                         | SAFEARRAY_ variantType              { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_SAFEARRAY); 
1582                                                                 corEmitInt($$,$2); 
1583                                                                 corEmitInt($$,0);}
1584                         | SAFEARRAY_ variantType ',' compQstring { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_SAFEARRAY); 
1585                                                                 corEmitInt($$,$2); 
1586                                                                 corEmitInt($$,$4->length()); $$->append($4); }
1587                                                                 
1588                         | INT_                                { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_INT); }
1589                         | UNSIGNED_ INT_                      { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_UINT); }
1590                         | UINT_                               { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_UINT); }
1591                         | NESTED_ STRUCT_                     { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_NESTEDSTRUCT); 
1592                                                                 PASM->report->warn("Deprecated native type 'nested struct'\n"); }
1593                         | BYVALSTR_                           { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_BYVALSTR); }
1594                         | ANSI_ BSTR_                         { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_ANSIBSTR); }
1595                         | TBSTR_                              { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_TBSTR); }
1596                         | VARIANT_ BOOL_                      { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_VARIANTBOOL); }
1597                         | METHOD_                             { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_FUNC); }
1598                         | AS_ ANY_                            { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_ASANY); }
1599                         | LPSTRUCT_                           { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_LPSTRUCT); }
1600                         | TYPEDEF_TS                          { $$ = new BinStr(); $$->append($1->m_pbsTypeSpec); }
1601                         ;
1602                         
1603 iidParamIndex           : /* EMPTY */                         { $$ = -1; }
1604                         | '(' IIDPARAM_ '=' int32 ')'         { $$ = $4; }
1605                         ;                        
1606
1607 variantType             : /* EMPTY */                         { $$ = VT_EMPTY; }
1608                         | NULL_                               { $$ = VT_NULL; }
1609                         | VARIANT_                            { $$ = VT_VARIANT; }
1610                         | CURRENCY_                           { $$ = VT_CY; }
1611                         | VOID_                               { $$ = VT_VOID; }
1612                         | BOOL_                               { $$ = VT_BOOL; }
1613                         | INT8_                               { $$ = VT_I1; }
1614                         | INT16_                              { $$ = VT_I2; }
1615                         | INT32_                              { $$ = VT_I4; }
1616                         | INT64_                              { $$ = VT_I8; }
1617                         | FLOAT32_                            { $$ = VT_R4; }
1618                         | FLOAT64_                            { $$ = VT_R8; }
1619                         | UNSIGNED_ INT8_                     { $$ = VT_UI1; }
1620                         | UNSIGNED_ INT16_                    { $$ = VT_UI2; }
1621                         | UNSIGNED_ INT32_                    { $$ = VT_UI4; }
1622                         | UNSIGNED_ INT64_                    { $$ = VT_UI8; }
1623                         | UINT8_                              { $$ = VT_UI1; }
1624                         | UINT16_                             { $$ = VT_UI2; }
1625                         | UINT32_                             { $$ = VT_UI4; }
1626                         | UINT64_                             { $$ = VT_UI8; }
1627                         | '*'                                 { $$ = VT_PTR; }
1628                         | variantType '[' ']'                 { $$ = $1 | VT_ARRAY; }
1629                         | variantType VECTOR_                 { $$ = $1 | VT_VECTOR; }
1630                         | variantType '&'                     { $$ = $1 | VT_BYREF; }
1631                         | DECIMAL_                            { $$ = VT_DECIMAL; }
1632                         | DATE_                               { $$ = VT_DATE; }
1633                         | BSTR_                               { $$ = VT_BSTR; }
1634                         | LPSTR_                              { $$ = VT_LPSTR; }
1635                         | LPWSTR_                             { $$ = VT_LPWSTR; }
1636                         | IUNKNOWN_                           { $$ = VT_UNKNOWN; }
1637                         | IDISPATCH_                          { $$ = VT_DISPATCH; }
1638                         | SAFEARRAY_                          { $$ = VT_SAFEARRAY; }
1639                         | INT_                                { $$ = VT_INT; }
1640                         | UNSIGNED_ INT_                      { $$ = VT_UINT; }
1641                         | UINT_                               { $$ = VT_UINT; }
1642                         | ERROR_                              { $$ = VT_ERROR; }
1643                         | HRESULT_                            { $$ = VT_HRESULT; }
1644                         | CARRAY_                             { $$ = VT_CARRAY; }
1645                         | USERDEFINED_                        { $$ = VT_USERDEFINED; }
1646                         | RECORD_                             { $$ = VT_RECORD; }
1647                         | FILETIME_                           { $$ = VT_FILETIME; }
1648                         | BLOB_                               { $$ = VT_BLOB; }
1649                         | STREAM_                             { $$ = VT_STREAM; }
1650                         | STORAGE_                            { $$ = VT_STORAGE; }
1651                         | STREAMED_OBJECT_                    { $$ = VT_STREAMED_OBJECT; }
1652                         | STORED_OBJECT_                      { $$ = VT_STORED_OBJECT; }
1653                         | BLOB_OBJECT_                        { $$ = VT_BLOB_OBJECT; }
1654                         | CF_                                 { $$ = VT_CF; }
1655                         | CLSID_                              { $$ = VT_CLSID; }
1656                         ;
1657
1658 /*  Managed types for signatures  */                        
1659 type                    : CLASS_ className                    { if($2 == PASM->m_tkSysString)
1660                                                                 {     $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING); }
1661                                                                 else if($2 == PASM->m_tkSysObject)
1662                                                                 {     $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_OBJECT); }
1663                                                                 else  
1664                                                                  $$ = parser->MakeTypeClass(ELEMENT_TYPE_CLASS, $2); } 
1665                         | OBJECT_                             { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_OBJECT); } 
1666                         | VALUE_ CLASS_ className             { $$ = parser->MakeTypeClass(ELEMENT_TYPE_VALUETYPE, $3); } 
1667                         | VALUETYPE_ className                { $$ = parser->MakeTypeClass(ELEMENT_TYPE_VALUETYPE, $2); } 
1668                         | type '[' ']'                        { $$ = $1; $$->insertInt8(ELEMENT_TYPE_SZARRAY); } 
1669                         | type '[' bounds1 ']'                { $$ = parser->MakeTypeArray(ELEMENT_TYPE_ARRAY, $1, $3); } 
1670                         | type '&'                            { $$ = $1; $$->insertInt8(ELEMENT_TYPE_BYREF); }
1671                         | type '*'                            { $$ = $1; $$->insertInt8(ELEMENT_TYPE_PTR); }
1672                         | type PINNED_                        { $$ = $1; $$->insertInt8(ELEMENT_TYPE_PINNED); }
1673                         | type MODREQ_ '(' typeSpec ')'       { $$ = parser->MakeTypeClass(ELEMENT_TYPE_CMOD_REQD, $4);
1674                                                                 $$->append($1); }
1675                         | type MODOPT_ '(' typeSpec ')'       { $$ = parser->MakeTypeClass(ELEMENT_TYPE_CMOD_OPT, $4);
1676                                                                 $$->append($1); }
1677                         | methodSpec callConv type '*' '(' sigArgs0 ')'  
1678                                                               { $$ = parser->MakeSig($2, $3, $6);
1679                                                                 $$->insertInt8(ELEMENT_TYPE_FNPTR); 
1680                                                                 PASM->delArgNameList(PASM->m_firstArgName);
1681                                                                 PASM->m_firstArgName = parser->m_ANSFirst.POP();
1682                                                                 PASM->m_lastArgName = parser->m_ANSLast.POP();
1683                                                               }
1684                         | type '<' tyArgs1 '>'                { if($3 == NULL) $$ = $1;
1685                                                                 else {
1686                                                                   $$ = new BinStr(); 
1687                                                                   $$->appendInt8(ELEMENT_TYPE_GENERICINST); 
1688                                                                   $$->append($1);
1689                                                                   corEmitInt($$, corCountArgs($3));
1690                                                                   $$->append($3); delete $1; delete $3; }}
1691                         | '!' '!' int32                       { //if(PASM->m_pCurMethod)  {
1692                                                                 //  if(($3 < 0)||((DWORD)$3 >= PASM->m_pCurMethod->m_NumTyPars))
1693                                                                 //    PASM->report->error("Invalid method type parameter '%d'\n",$3);
1694                                                                   $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_MVAR); corEmitInt($$, $3); 
1695                                                                 //} else PASM->report->error("Method type parameter '%d' outside method scope\n",$3);
1696                                                               }
1697                         | '!' int32                           { //if(PASM->m_pCurClass)  {
1698                                                                 //  if(($2 < 0)||((DWORD)$2 >= PASM->m_pCurClass->m_NumTyPars))
1699                                                                 //    PASM->report->error("Invalid type parameter '%d'\n",$2);
1700                                                                   $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_VAR); corEmitInt($$, $2); 
1701                                                                 //} else PASM->report->error("Type parameter '%d' outside class scope\n",$2);
1702                                                               }
1703                         | '!' '!' dottedName                  { int eltype = ELEMENT_TYPE_MVAR;
1704                                                                 int n=-1;
1705                                                                 if(PASM->m_pCurMethod) n = PASM->m_pCurMethod->FindTyPar($3);
1706                                                                 else {
1707                                                                   if(PASM->m_TyParList) n = PASM->m_TyParList->IndexOf($3);
1708                                                                   if(n == -1)
1709                                                                   { n = TyParFixupList.COUNT();
1710                                                                     TyParFixupList.PUSH($3);
1711                                                                     eltype = ELEMENT_TYPE_MVARFIXUP;
1712                                                                   }
1713                                                                 }
1714                                                                 if(n == -1) { PASM->report->error("Invalid method type parameter '%s'\n",$3);
1715                                                                 n = 0x1FFFFFFF; }
1716                                                                 $$ = new BinStr(); $$->appendInt8(eltype); corEmitInt($$,n); 
1717                                                               }
1718                         | '!' dottedName                      { int eltype = ELEMENT_TYPE_VAR;
1719                                                                 int n=-1;
1720                                                                 if(PASM->m_pCurClass && !newclass) n = PASM->m_pCurClass->FindTyPar($2);
1721                                                                 else {
1722                                                                   if(PASM->m_TyParList) n = PASM->m_TyParList->IndexOf($2);
1723                                                                   if(n == -1)
1724                                                                   { n = TyParFixupList.COUNT();
1725                                                                     TyParFixupList.PUSH($2);
1726                                                                     eltype = ELEMENT_TYPE_VARFIXUP;
1727                                                                   }
1728                                                                 }
1729                                                                 if(n == -1) { PASM->report->error("Invalid type parameter '%s'\n",$2);
1730                                                                 n = 0x1FFFFFFF; }
1731                                                                 $$ = new BinStr(); $$->appendInt8(eltype); corEmitInt($$,n); 
1732                                                               }
1733                         | TYPEDREF_                           { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_TYPEDBYREF); }
1734                         | VOID_                               { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_VOID); }
1735                         | NATIVE_ INT_                        { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I); }
1736                         | NATIVE_ UNSIGNED_ INT_              { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U); }
1737                         | NATIVE_ UINT_                       { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U); }
1738                         | simpleType                          { $$ = $1; }
1739                         | ELIPSIS type                        { $$ = $2; $$->insertInt8(ELEMENT_TYPE_SENTINEL); }
1740                         ;
1741                         
1742 simpleType              : CHAR_                               { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_CHAR); }
1743                         | STRING_                             { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING); } 
1744                         | BOOL_                               { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_BOOLEAN); }
1745                         | INT8_                               { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I1); }
1746                         | INT16_                              { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I2); }
1747                         | INT32_                              { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I4); }
1748                         | INT64_                              { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I8); }
1749                         | FLOAT32_                            { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R4); }
1750                         | FLOAT64_                            { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R8); }
1751                         | UNSIGNED_ INT8_                     { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1); }
1752                         | UNSIGNED_ INT16_                    { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2); }
1753                         | UNSIGNED_ INT32_                    { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4); }
1754                         | UNSIGNED_ INT64_                    { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8); }
1755                         | UINT8_                              { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1); }
1756                         | UINT16_                             { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2); }
1757                         | UINT32_                             { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4); }
1758                         | UINT64_                             { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8); }
1759                         | TYPEDEF_TS                          { $$ = new BinStr(); $$->append($1->m_pbsTypeSpec); }
1760                         ;
1761                         
1762 bounds1                 : bound                               { $$ = $1; }
1763                         | bounds1 ',' bound                   { $$ = $1; $1->append($3); delete $3; }
1764                         ;
1765
1766 bound                   : /* EMPTY */                         { $$ = new BinStr(); $$->appendInt32(0x7FFFFFFF); $$->appendInt32(0x7FFFFFFF);  }
1767                         | ELIPSIS                             { $$ = new BinStr(); $$->appendInt32(0x7FFFFFFF); $$->appendInt32(0x7FFFFFFF);  }
1768                         | int32                               { $$ = new BinStr(); $$->appendInt32(0); $$->appendInt32($1); } 
1769                         | int32 ELIPSIS int32                 { FAIL_UNLESS($1 <= $3, ("lower bound %d must be <= upper bound %d\n", $1, $3));
1770                                                                 if ($1 > $3) { YYERROR; };        
1771                                                                 $$ = new BinStr(); $$->appendInt32($1); $$->appendInt32($3-$1+1); }   
1772                         | int32 ELIPSIS                       { $$ = new BinStr(); $$->appendInt32($1); $$->appendInt32(0x7FFFFFFF); } 
1773                         ;
1774
1775 /*  Security declarations  */                        
1776 secDecl                 : _PERMISSION secAction typeSpec '(' nameValPairs ')'
1777                                                               { PASM->AddPermissionDecl($2, $3, $5); }
1778                         | _PERMISSION secAction typeSpec '=' '{' customBlobDescr '}'
1779                                                               { PASM->AddPermissionDecl($2, $3, $6); }
1780                         | _PERMISSION secAction typeSpec      { PASM->AddPermissionDecl($2, $3, (NVPair *)NULL); }
1781                         | psetHead bytes ')'                  { PASM->AddPermissionSetDecl($1, $2); }
1782                         | _PERMISSIONSET secAction compQstring
1783                                                               { PASM->AddPermissionSetDecl($2,BinStrToUnicode($3,true));}
1784                         | _PERMISSIONSET secAction '=' '{' secAttrSetBlob '}'
1785                                                               { BinStr* ret = new BinStr();
1786                                                                 ret->insertInt8('.');
1787                                                                 corEmitInt(ret, nSecAttrBlobs);
1788                                                                 ret->append($5);
1789                                                                 PASM->AddPermissionSetDecl($2,ret);
1790                                                                 nSecAttrBlobs = 0; }
1791                         ;
1792                         
1793 secAttrSetBlob          : /* EMPTY */                         { $$ = new BinStr(); nSecAttrBlobs = 0;}
1794                         | secAttrBlob                         { $$ = $1; nSecAttrBlobs = 1; }
1795                         | secAttrBlob ',' secAttrSetBlob      { $$ = $1; $$->append($3); nSecAttrBlobs++; }
1796                         ;
1797                         
1798 secAttrBlob             : typeSpec '=' '{' customBlobNVPairs '}'
1799                                                               { $$ = PASM->EncodeSecAttr(PASM->ReflectionNotation($1),$4,nCustomBlobNVPairs); 
1800                                                                 nCustomBlobNVPairs = 0; }                                               
1801                         | CLASS_ SQSTRING '=' '{' customBlobNVPairs '}'
1802                                                               { $$ = PASM->EncodeSecAttr($2,$5,nCustomBlobNVPairs); 
1803                                                                 nCustomBlobNVPairs = 0; }
1804                         ;                                               
1805
1806 psetHead                : _PERMISSIONSET secAction '=' '('    { $$ = $2; bParsingByteArray = TRUE; }
1807                         | _PERMISSIONSET secAction BYTEARRAY_ '(' 
1808                                                               { $$ = $2; bParsingByteArray = TRUE; }
1809                         ;
1810
1811 nameValPairs            : nameValPair                         { $$ = $1; }
1812                         | nameValPair ',' nameValPairs        { $$ = $1->Concat($3); }
1813                         ;
1814
1815 nameValPair             : compQstring '=' caValue             { $1->appendInt8(0); $$ = new NVPair($1, $3); }
1816                         ;
1817
1818 truefalse               : TRUE_                               { $$ = 1; }
1819                         | FALSE_                              { $$ = 0; }
1820                         ;
1821
1822 caValue                 : truefalse                           { $$ = new BinStr();
1823                                                                 $$->appendInt8(SERIALIZATION_TYPE_BOOLEAN);
1824                                                                 $$->appendInt8($1); }
1825                         | int32                               { $$ = new BinStr();
1826                                                                 $$->appendInt8(SERIALIZATION_TYPE_I4);
1827                                                                 $$->appendInt32($1); }
1828                         | INT32_ '(' int32 ')'                { $$ = new BinStr();
1829                                                                 $$->appendInt8(SERIALIZATION_TYPE_I4);
1830                                                                 $$->appendInt32($3); }
1831                         | compQstring                         { $$ = new BinStr();
1832                                                                 $$->appendInt8(SERIALIZATION_TYPE_STRING);
1833                                                                 $$->append($1); delete $1;
1834                                                                 $$->appendInt8(0); }
1835                         | className '(' INT8_ ':' int32 ')'   { $$ = new BinStr();
1836                                                                 $$->appendInt8(SERIALIZATION_TYPE_ENUM);
1837                                                                 char* sz = PASM->ReflectionNotation($1);
1838                                                                 strcpy_s((char *)$$->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
1839                                                                 $$->appendInt8(1);
1840                                                                 $$->appendInt32($5); }
1841                         | className '(' INT16_ ':' int32 ')'  { $$ = new BinStr();
1842                                                                 $$->appendInt8(SERIALIZATION_TYPE_ENUM);
1843                                                                 char* sz = PASM->ReflectionNotation($1);
1844                                                                 strcpy_s((char *)$$->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
1845                                                                 $$->appendInt8(2);
1846                                                                 $$->appendInt32($5); }
1847                         | className '(' INT32_ ':' int32 ')'  { $$ = new BinStr();
1848                                                                 $$->appendInt8(SERIALIZATION_TYPE_ENUM);
1849                                                                 char* sz = PASM->ReflectionNotation($1);
1850                                                                 strcpy_s((char *)$$->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
1851                                                                 $$->appendInt8(4);
1852                                                                 $$->appendInt32($5); }
1853                         | className '(' int32 ')'             { $$ = new BinStr();
1854                                                                 $$->appendInt8(SERIALIZATION_TYPE_ENUM);
1855                                                                 char* sz = PASM->ReflectionNotation($1);
1856                                                                 strcpy_s((char *)$$->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
1857                                                                 $$->appendInt8(4);
1858                                                                 $$->appendInt32($3); }
1859                         ;
1860
1861 secAction               : REQUEST_                            { $$ = dclRequest; }
1862                         | DEMAND_                             { $$ = dclDemand; }
1863                         | ASSERT_                             { $$ = dclAssert; }
1864                         | DENY_                               { $$ = dclDeny; }
1865                         | PERMITONLY_                         { $$ = dclPermitOnly; }
1866                         | LINKCHECK_                          { $$ = dclLinktimeCheck; }
1867                         | INHERITCHECK_                       { $$ = dclInheritanceCheck; }
1868                         | REQMIN_                             { $$ = dclRequestMinimum; }
1869                         | REQOPT_                             { $$ = dclRequestOptional; }
1870                         | REQREFUSE_                          { $$ = dclRequestRefuse; }
1871                         | PREJITGRANT_                        { $$ = dclPrejitGrant; }
1872                         | PREJITDENY_                         { $$ = dclPrejitDenied; }
1873                         | NONCASDEMAND_                       { $$ = dclNonCasDemand; }
1874                         | NONCASLINKDEMAND_                   { $$ = dclNonCasLinkDemand; }
1875                         | NONCASINHERITANCE_                  { $$ = dclNonCasInheritance; }
1876                         ;
1877
1878 /*  External source declarations  */                        
1879 esHead                  : _LINE                               { PASM->ResetLineNumbers(); nCurrPC = PASM->m_CurPC; PENV->bExternSource = TRUE; PENV->bExternSourceAutoincrement = FALSE; }
1880                         | P_LINE                              { PASM->ResetLineNumbers(); nCurrPC = PASM->m_CurPC; PENV->bExternSource = TRUE; PENV->bExternSourceAutoincrement = TRUE; }
1881                         ;
1882                         
1883 extSourceSpec           : esHead int32 SQSTRING               { PENV->nExtLine = PENV->nExtLineEnd = $2;
1884                                                                 PENV->nExtCol = 0; PENV->nExtColEnd  = static_cast<unsigned>(-1);
1885                                                                 PASM->SetSourceFileName($3);}
1886                         | esHead int32                        { PENV->nExtLine = PENV->nExtLineEnd = $2;
1887                                                                 PENV->nExtCol = 0; PENV->nExtColEnd  = static_cast<unsigned>(-1); }
1888                         | esHead int32 ':' int32 SQSTRING     { PENV->nExtLine = PENV->nExtLineEnd = $2; 
1889                                                                 PENV->nExtCol=$4; PENV->nExtColEnd = static_cast<unsigned>(-1);
1890                                                                 PASM->SetSourceFileName($5);}
1891                         | esHead int32 ':' int32              { PENV->nExtLine = PENV->nExtLineEnd = $2; 
1892                                                                 PENV->nExtCol=$4; PENV->nExtColEnd = static_cast<unsigned>(-1);}
1893                         | esHead int32 ':' int32 ',' int32 SQSTRING     
1894                                                               { PENV->nExtLine = PENV->nExtLineEnd = $2; 
1895                                                                 PENV->nExtCol=$4; PENV->nExtColEnd = $6;
1896                                                                 PASM->SetSourceFileName($7);}
1897                         | esHead int32 ':' int32 ',' int32     
1898                                                               { PENV->nExtLine = PENV->nExtLineEnd = $2; 
1899                                                                 PENV->nExtCol=$4; PENV->nExtColEnd = $6; }
1900                         | esHead int32 ',' int32 ':' int32 SQSTRING     
1901                                                               { PENV->nExtLine = $2; PENV->nExtLineEnd = $4; 
1902                                                                 PENV->nExtCol=$6; PENV->nExtColEnd = static_cast<unsigned>(-1);
1903                                                                 PASM->SetSourceFileName($7);}
1904                         | esHead int32 ',' int32 ':' int32     
1905                                                               { PENV->nExtLine = $2; PENV->nExtLineEnd = $4; 
1906                                                                 PENV->nExtCol=$6; PENV->nExtColEnd = static_cast<unsigned>(-1); }
1907                         | esHead int32 ',' int32 ':' int32 ',' int32 SQSTRING     
1908                                                               { PENV->nExtLine = $2; PENV->nExtLineEnd = $4; 
1909                                                                 PENV->nExtCol=$6; PENV->nExtColEnd = $8;
1910                                                                 PASM->SetSourceFileName($9);}
1911                         | esHead int32 ',' int32 ':' int32 ',' int32     
1912                                                               { PENV->nExtLine = $2; PENV->nExtLineEnd = $4; 
1913                                                                 PENV->nExtCol=$6; PENV->nExtColEnd = $8; }
1914                         | esHead int32 QSTRING                { PENV->nExtLine = PENV->nExtLineEnd = $2 - 1;
1915                                                                 PENV->nExtCol = 0; PENV->nExtColEnd = static_cast<unsigned>(-1);
1916                                                                 PASM->SetSourceFileName($3);}
1917                         ;
1918
1919 /*  Manifest declarations  */                         
1920 fileDecl                : _FILE fileAttr dottedName fileEntry hashHead bytes ')' fileEntry      
1921                                                               { PASMM->AddFile($3, $2|$4|$8, $6); }
1922                         | _FILE fileAttr dottedName fileEntry { PASMM->AddFile($3, $2|$4, NULL); }
1923                         ;
1924
1925 fileAttr                : /* EMPTY */                         { $$ = (CorFileFlags) 0; }
1926                         | fileAttr NOMETADATA_                { $$ = (CorFileFlags) ($1 | ffContainsNoMetaData); }
1927                         ;
1928
1929 fileEntry               : /* EMPTY */                         { $$ = (CorFileFlags) 0; }
1930                         | _ENTRYPOINT                         { $$ = (CorFileFlags) 0x80000000; }
1931                         ;
1932
1933 hashHead                : _HASH '=' '('                       { bParsingByteArray = TRUE; }
1934                         ;
1935
1936 assemblyHead            : _ASSEMBLY asmAttr dottedName        { PASMM->StartAssembly($3, NULL, (DWORD)$2, FALSE); }
1937                         ;
1938
1939 asmAttr                 : /* EMPTY */                         { $$ = (CorAssemblyFlags) 0; }
1940                         | asmAttr RETARGETABLE_               { $$ = (CorAssemblyFlags) ($1 | afRetargetable); }
1941                         | asmAttr WINDOWSRUNTIME_             { $$ = (CorAssemblyFlags) ($1 | afContentType_WindowsRuntime); }
1942                         | asmAttr NOPLATFORM_                 { $$ = (CorAssemblyFlags) ($1 | afPA_NoPlatform); }
1943                         | asmAttr LEGACY_ LIBRARY_            { $$ = $1; }
1944                         | asmAttr CIL_                        { SET_PA($$,$1,afPA_MSIL); }
1945                         | asmAttr X86_                        { SET_PA($$,$1,afPA_x86); }
1946                         | asmAttr AMD64_                      { SET_PA($$,$1,afPA_AMD64); }
1947                         | asmAttr ARM_                        { SET_PA($$,$1,afPA_ARM); }
1948                         | asmAttr ARM64_                      { SET_PA($$,$1,afPA_ARM64); }
1949                         ;
1950
1951 assemblyDecls           : /* EMPTY */
1952                         | assemblyDecls assemblyDecl
1953                         ;
1954
1955 assemblyDecl            : _HASH ALGORITHM_ int32              { PASMM->SetAssemblyHashAlg($3); }
1956                         | secDecl
1957                         | asmOrRefDecl
1958                         ;
1959                         
1960 intOrWildcard           : int32                               { $$ = $1; }
1961                         | '*'                                 { $$ = 0xFFFF; }
1962                         ;                        
1963
1964 asmOrRefDecl            : publicKeyHead bytes ')'             { PASMM->SetAssemblyPublicKey($2); }
1965                         | _VER intOrWildcard ':' intOrWildcard ':' intOrWildcard ':' intOrWildcard      
1966                                                               { PASMM->SetAssemblyVer((USHORT)$2, (USHORT)$4, (USHORT)$6, (USHORT)$8); }
1967                         | _LOCALE compQstring                 { $2->appendInt8(0); PASMM->SetAssemblyLocale($2,TRUE); }
1968                         | localeHead bytes ')'                { PASMM->SetAssemblyLocale($2,FALSE); }
1969                         | customAttrDecl
1970                         | compControl
1971                         ;
1972
1973 publicKeyHead           : _PUBLICKEY '=' '('                  { bParsingByteArray = TRUE; }
1974                         ;
1975
1976 publicKeyTokenHead      : _PUBLICKEYTOKEN '=' '('             { bParsingByteArray = TRUE; }
1977                         ;
1978
1979 localeHead              : _LOCALE '=' '('                     { bParsingByteArray = TRUE; }
1980                         ;
1981
1982 assemblyRefHead         : _ASSEMBLY EXTERN_ asmAttr dottedName     
1983                                                               { PASMM->StartAssembly($4, NULL, $3, TRUE); }
1984                         | _ASSEMBLY EXTERN_ asmAttr dottedName AS_ dottedName   
1985                                                               { PASMM->StartAssembly($4, $6, $3, TRUE); }
1986                         ;
1987
1988 assemblyRefDecls        : /* EMPTY */
1989                         | assemblyRefDecls assemblyRefDecl
1990                         ;
1991
1992 assemblyRefDecl         : hashHead bytes ')'                  { PASMM->SetAssemblyHashBlob($2); }
1993                         | asmOrRefDecl
1994                         | publicKeyTokenHead bytes ')'        { PASMM->SetAssemblyPublicKeyToken($2); }
1995                         | AUTO_                               { PASMM->SetAssemblyAutodetect(); }
1996                         ;
1997
1998 exptypeHead             : _CLASS EXTERN_ exptAttr dottedName  { PASMM->StartComType($4, $3);} 
1999                         ;
2000
2001 exportHead              : _EXPORT exptAttr dottedName   /* deprecated */      { PASMM->StartComType($3, $2); }
2002                         ;
2003
2004 exptAttr                : /* EMPTY */                         { $$ = (CorTypeAttr) 0; }
2005                         | exptAttr PRIVATE_                   { $$ = (CorTypeAttr) ($1 | tdNotPublic); }
2006                         | exptAttr PUBLIC_                    { $$ = (CorTypeAttr) ($1 | tdPublic); }
2007                         | exptAttr FORWARDER_                 { $$ = (CorTypeAttr) ($1 | tdForwarder); }
2008                         | exptAttr NESTED_ PUBLIC_            { $$ = (CorTypeAttr) ($1 | tdNestedPublic); }
2009                         | exptAttr NESTED_ PRIVATE_           { $$ = (CorTypeAttr) ($1 | tdNestedPrivate); }
2010                         | exptAttr NESTED_ FAMILY_            { $$ = (CorTypeAttr) ($1 | tdNestedFamily); }
2011                         | exptAttr NESTED_ ASSEMBLY_          { $$ = (CorTypeAttr) ($1 | tdNestedAssembly); }
2012                         | exptAttr NESTED_ FAMANDASSEM_       { $$ = (CorTypeAttr) ($1 | tdNestedFamANDAssem); }
2013                         | exptAttr NESTED_ FAMORASSEM_        { $$ = (CorTypeAttr) ($1 | tdNestedFamORAssem); }
2014                         ;
2015
2016 exptypeDecls            : /* EMPTY */
2017                         | exptypeDecls exptypeDecl
2018                         ;
2019
2020 exptypeDecl             : _FILE dottedName                    { PASMM->SetComTypeFile($2); }
2021                         | _CLASS EXTERN_ slashedName           { PASMM->SetComTypeComType($3); }
2022                         | _ASSEMBLY EXTERN_ dottedName        { PASMM->SetComTypeAsmRef($3); }
2023                         | MDTOKEN_ '(' int32 ')'              { if(!PASMM->SetComTypeImplementationTok($3))
2024                                                                   PASM->report->error("Invalid implementation of exported type\n"); }
2025                         | _CLASS  int32                       { if(!PASMM->SetComTypeClassTok($2))
2026                                                                   PASM->report->error("Invalid TypeDefID of exported type\n"); }
2027                         | customAttrDecl
2028                         | compControl
2029                         ;
2030
2031 manifestResHead         : _MRESOURCE manresAttr dottedName    { PASMM->StartManifestRes($3, $3, $2); }
2032                         | _MRESOURCE manresAttr dottedName AS_ dottedName
2033                                                               { PASMM->StartManifestRes($3, $5, $2); }
2034                         ;
2035
2036 manresAttr              : /* EMPTY */                         { $$ = (CorManifestResourceFlags) 0; }
2037                         | manresAttr PUBLIC_                  { $$ = (CorManifestResourceFlags) ($1 | mrPublic); }
2038                         | manresAttr PRIVATE_                 { $$ = (CorManifestResourceFlags) ($1 | mrPrivate); }
2039                         ;
2040
2041 manifestResDecls        : /* EMPTY */
2042                         | manifestResDecls manifestResDecl
2043                         ;
2044
2045 manifestResDecl         : _FILE dottedName AT_ int32          { PASMM->SetManifestResFile($2, (ULONG)$4); }
2046                         | _ASSEMBLY EXTERN_ dottedName        { PASMM->SetManifestResAsmRef($3); }
2047                         | customAttrDecl
2048                         | compControl
2049                         ;
2050
2051
2052 %%
2053
2054 #include "grammar_after.cpp"