1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4#include <asmparse.h>
5#include <assembler.h>
6
7// Disable the "initialization of static local vars is no thread safe" error
8#ifdef _MSC_VER
9#pragma warning(disable : 4640)
10#endif
11
12#define YYMAXDEPTH 0x80000
13#define YYLOCAL int
14//#define YYRECURSIVE
15
16//#define DEBUG_PARSING
17#ifdef DEBUG_PARSING
18bool parseDBFlag = true;
19#define dbprintf(x) if (parseDBFlag) printf x
20#define YYDEBUG 1
21#else
22#define dbprintf(x)
23#endif
24
25#define FAIL_UNLESS(cond, msg) if (!(cond)) { parser->success = false; parser->error msg; }
26
27static AsmParse* parser = 0;
28#define PASM (parser->assem)
29#define PASMM (parser->assem->m_pManifest)
30#define PENV (parser->penv)
31
32
33
34PFN_NEXTCHAR nextchar;
35PFN_SYM Sym;
36PFN_NEWSTRFROMTOKEN NewStrFromToken;
37PFN_NEWSTATICSTRFROMTOKEN NewStaticStrFromToken;
38PFN_GETDOUBLE GetDouble;
39
40void SetFunctionPtrs()
41{
42 nextchar = PENV->pfn_nextchar;
43 Sym = PENV->pfn_Sym;
44 NewStrFromToken = PENV->pfn_NewStrFromToken;
45 NewStaticStrFromToken = PENV->pfn_NewStaticStrFromToken;
46 GetDouble = PENV->pfn_GetDouble;
47}
48
49
50static char* newStringWDel(__in __nullterminated char* str1, char delimiter, __in __nullterminated char* str3 = 0);
51static char* newString(__in __nullterminated const char* str1);
52static void corEmitInt(BinStr* buff, unsigned data);
53static void AppendStringWithLength(BinStr* pbs, __in __nullterminated char* sz);
54bool bParsingByteArray = FALSE;
55int iOpcodeLen = 0;
56int iCallConv = 0;
57unsigned IfEndif = 0;
58unsigned IfEndifSkip = 0;
59unsigned nCustomBlobNVPairs = 0;
60unsigned nSecAttrBlobs = 0;
61unsigned nCurrPC = 0;
62BOOL SkipToken = FALSE;
63BOOL neg = FALSE;
64BOOL newclass = FALSE;
65
66extern unsigned int g_uConsoleCP;
67
68struct VarName
69{
70 char* name;
71 BinStr* pbody;
72 VarName(__in_opt __nullterminated char* sz, BinStr* pbs) { name = sz; pbody = pbs; };
73 ~VarName() { delete [] name; delete pbody; };
74 int ComparedTo(VarName* pN) { return strcmp(name,pN->name); };
75};
76SORTEDARRAY<VarName> VarNameList;
77void DefineVar(__in __nullterminated char* sz, BinStr* pbs) { VarNameList.PUSH(new VarName(sz,pbs)); };
78void UndefVar(__in __nullterminated char* sz)
79{
80 CHECK_LOCAL_STATIC_VAR(static VarName VN(NULL,NULL));
81
82 VN.name = sz;
83 VarNameList.DEL(&VN);
84 VN.name = NULL;
85 delete [] sz;
86}
87VarName* FindVarDef(__in __nullterminated char* sz)
88{
89 CHECK_LOCAL_STATIC_VAR(static VarName VN(NULL,NULL));
90
91 VarName* Ret = NULL;
92 VN.name = sz;
93 Ret = VarNameList.FIND(&VN);
94 VN.name = NULL;
95 delete [] sz;
96 return Ret;
97}
98BOOL IsVarDefined(__in __nullterminated char* sz)
99{
100 return (FindVarDef(sz) != NULL);
101}
102
103int nTemp=0;
104
105unsigned int uMethodBeginLine,uMethodBeginColumn;
106
107#define ELEMENT_TYPE_VARFIXUP ELEMENT_TYPE_MAX+2
108#define ELEMENT_TYPE_MVARFIXUP ELEMENT_TYPE_MAX+3
109
110FIFO<char> TyParFixupList;
111void FixupTyPars(PCOR_SIGNATURE pSig, ULONG cSig);
112void FixupTyPars(BinStr* pbstype);
113void FixupConstraints()
114{
115 if((TyParFixupList.COUNT()) && (PASM->m_TyParList))
116 {
117 TyParList* pTPL;
118 for(pTPL = PASM->m_TyParList; pTPL; pTPL=pTPL->Next())
119 {
120 mdToken* ptk;
121 for(ptk = (mdToken*)(pTPL->Bound()->ptr()); *ptk; ptk++)
122 {
123 if(TypeFromToken(*ptk)==mdtTypeSpec)
124 {
125 PCOR_SIGNATURE pSig;
126 ULONG cSig;
127 PASM->m_pImporter->GetTypeSpecFromToken(*ptk,(PCCOR_SIGNATURE*)&pSig,&cSig);
128 if((pSig)&&(cSig))
129 {
130 FixupTyPars(pSig,cSig);
131 } // end if((pSig)&&(cSig))
132 } // end if(TypeFromToken(*ptk)==mdtTypeSpec)
133 } //end for(ptk
134 } // end for(pTPL
135 } //end if((TyParFixupList.COUNT())
136}
137
138#define SET_PA(x,y,z) {x = (CorAssemblyFlags)(((y) & ~afPA_FullMask)|(z)|afPA_Specified);}
139