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 |
18 | bool 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 | |
27 | static AsmParse* parser = 0; |
28 | #define PASM (parser->assem) |
29 | #define PASMM (parser->assem->m_pManifest) |
30 | #define PENV (parser->penv) |
31 | |
32 | |
33 | |
34 | PFN_NEXTCHAR nextchar; |
35 | PFN_SYM Sym; |
36 | PFN_NEWSTRFROMTOKEN NewStrFromToken; |
37 | PFN_NEWSTATICSTRFROMTOKEN NewStaticStrFromToken; |
38 | PFN_GETDOUBLE GetDouble; |
39 | |
40 | void 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 | |
50 | static char* newStringWDel(__in __nullterminated char* str1, char delimiter, __in __nullterminated char* str3 = 0); |
51 | static char* newString(__in __nullterminated const char* str1); |
52 | static void corEmitInt(BinStr* buff, unsigned data); |
53 | static void AppendStringWithLength(BinStr* pbs, __in __nullterminated char* sz); |
54 | bool bParsingByteArray = FALSE; |
55 | int iOpcodeLen = 0; |
56 | int iCallConv = 0; |
57 | unsigned IfEndif = 0; |
58 | unsigned IfEndifSkip = 0; |
59 | unsigned nCustomBlobNVPairs = 0; |
60 | unsigned nSecAttrBlobs = 0; |
61 | unsigned nCurrPC = 0; |
62 | BOOL SkipToken = FALSE; |
63 | BOOL neg = FALSE; |
64 | BOOL newclass = FALSE; |
65 | |
66 | extern unsigned int g_uConsoleCP; |
67 | |
68 | struct 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 | }; |
76 | SORTEDARRAY<VarName> VarNameList; |
77 | void DefineVar(__in __nullterminated char* sz, BinStr* pbs) { VarNameList.PUSH(new VarName(sz,pbs)); }; |
78 | void 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 | } |
87 | VarName* 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 | } |
98 | BOOL IsVarDefined(__in __nullterminated char* sz) |
99 | { |
100 | return (FindVarDef(sz) != NULL); |
101 | } |
102 | |
103 | int nTemp=0; |
104 | |
105 | unsigned int uMethodBeginLine,uMethodBeginColumn; |
106 | |
107 | #define ELEMENT_TYPE_VARFIXUP ELEMENT_TYPE_MAX+2 |
108 | #define ELEMENT_TYPE_MVARFIXUP ELEMENT_TYPE_MAX+3 |
109 | |
110 | FIFO<char> TyParFixupList; |
111 | void FixupTyPars(PCOR_SIGNATURE pSig, ULONG cSig); |
112 | void FixupTyPars(BinStr* pbstype); |
113 | void 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 | |