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.
12 class PermissionSetDecl;
14 #define MAX_EXCEPTIONS 16 // init.number; increased by 16 when needed
16 extern unsigned int g_uCodePage;
17 extern WCHAR wzUniBuf[];
19 /**************************************************************************/
27 ISymUnmanagedDocumentWriter* pWriter;
29 typedef FIFO<LinePC> LinePCList;
32 struct PInvokeDescriptor
39 struct TokenRelocDescr // for OBJ generation only!
43 TokenRelocDescr(DWORD off, mdToken tk) { offset = off; token = tk; };
45 typedef FIFO<TokenRelocDescr> TRDList;
46 /* structure - element of [local] signature name list */
50 LPCUTF8 szName; //szName[1024];
52 BinStr* pSig; // argument's signature ptr
57 CustomDescrList CustDList;
59 __forceinline ARG_NAME_LIST(int i, LPCUTF8 sz, BinStr *pbSig, BinStr *pbMarsh, DWORD attr)
62 //dwName = (DWORD)strlen(sz);
65 dwName = (sz == NULL) ? 0 : (DWORD)strlen(sz);
72 inline ~ARG_NAME_LIST()
75 if(pMarshal) delete pMarshal;
76 if(pValue) delete pValue;
77 if(szName) delete [] szName;
82 typedef FIFO<Scope> ScopeList;
88 ARG_NAME_LIST* pLocals;
91 Scope() { dwStart = dwEnd = 0; pLocals = NULL; pSuperScope = NULL; };
92 ~Scope() { Reset(); };
96 while(pLocals) { pNext = pLocals->pNext; delete pLocals; pLocals = pNext; }
98 while((pS = SubScope.POP()) != NULL) delete pS;
108 VarDescr() { dwSlot = (DWORD) -1; pbsSig = NULL; bInScope = FALSE; };
110 typedef FIFO<VarDescr> VarDescrList;
119 Label() :m_szName(NULL),m_PC(0){};
120 Label(LPCUTF8 pszName, DWORD PC):m_szName(pszName),m_PC(PC){};
121 ~Label(){ delete [] m_szName; };
122 int ComparedTo(Label* L) { return strcmp(m_szName,L->m_szName); };
123 //int Compare(char* L) { return strcmp(L,m_szName); };
124 LPCUTF8 NameOf() { return m_szName; };
126 //typedef SORTEDARRAY<Label> LabelList;
127 typedef FIFO_INDEXED<Label> LabelList;
133 BYTE * m_pReference; // The place to fix up
135 GlobalFixup(LPCUTF8 pszName, BYTE* pReference)
137 m_pReference = pReference;
140 ~GlobalFixup(){ delete [] m_szLabel; }
142 typedef FIFO<GlobalFixup> GlobalFixupList;
149 BYTE * m_pBytes; // where to make the fixup
150 DWORD m_RelativeToPC;
153 Fixup(LPCUTF8 pszName, BYTE *pBytes, DWORD RelativeToPC, BYTE FixupSize)
156 m_RelativeToPC = RelativeToPC;
157 m_FixupSize = FixupSize;
160 ~Fixup(){ delete [] m_szLabel; }
162 typedef FIFO<Fixup> FixupList;
164 typedef enum { ilRVA, ilToken, ilGlobal} ILFixupType;
170 DWORD m_OffsetInMethod;
171 GlobalFixup * m_Fixup;
173 ILFixup(DWORD Offset, ILFixupType Kind, GlobalFixup *Fix)
176 m_OffsetInMethod = Offset;
180 typedef FIFO<ILFixup> ILFixupList;
186 //BinStr **m_TyParBounds;
187 //LPCWSTR *m_TyParNames;
188 TyParDescr* m_TyPars;
190 DWORD m_SigInfoCount;
192 mdSignature m_LocalsSig;
196 char* m_szExportAlias;
197 DWORD m_dwExportOrdinal;
198 COR_ILMETHOD_SECT_EH_CLAUSE_FAT *m_ExceptionList;
199 DWORD m_dwNumExceptions;
200 DWORD m_dwMaxNumExceptions;
201 DWORD* m_EndfilterOffsetList;
202 DWORD m_dwNumEndfilters;
203 DWORD m_dwMaxNumEndfilters;
206 BOOL m_fGlobalMethod;
209 DWORD m_methodOffset;
210 DWORD m_headerOffset;
215 ULONG m_ulColumns[2];
216 // PInvoke attributes
217 PInvokeDescriptor* m_pPInvoke;
218 // Security attributes
219 PermissionDecl* m_pPermissions;
220 PermissionSetDecl* m_pPermissionSets;
225 BinStr* m_pRetMarshal;
228 CustomDescrList m_RetCustDList;
229 ILFixupList m_lstILFixup;
230 FixupList m_lstFixup;
231 // LabelList m_lstLabel;
233 LocalMemberRefFixupList m_LocalMemberRefFixupList;
234 // Method body (header+code+EH)
237 Method(Assembler *pAssembler, Class *pClass, __in __nullterminated char *pszName, BinStr* pbsSig, DWORD Attr);
240 m_lstFixup.RESET(true);
241 //m_lstLabel.RESET(true);
243 if(m_szExportAlias) delete [] m_szExportAlias;
244 delArgNameList(m_firstArgName);
245 delArgNameList(m_firstVarName);
246 delete m_pbsMethodSig;
247 delete [] m_ExceptionList;
248 delete [] m_EndfilterOffsetList;
249 if(m_pRetMarshal) delete m_pRetMarshal;
250 if(m_pRetValue) delete m_pRetValue;
251 while(m_MethodImplDList.POP()); // ptrs in m_MethodImplDList are dups of those in Assembler
252 if(m_pbsBody) delete m_pbsBody;
253 if(m_TyPars) delete [] m_TyPars;
256 BOOL IsGlobalMethod()
258 return m_fGlobalMethod;
261 void SetIsGlobalMethod()
263 m_fGlobalMethod = TRUE;
266 void delArgNameList(ARG_NAME_LIST *pFirst)
268 ARG_NAME_LIST *pArgList=pFirst, *pArgListNext;
269 for(; pArgList; pArgListNext=pArgList->pNext,
271 pArgList=pArgListNext);
274 ARG_NAME_LIST *catArgNameList(ARG_NAME_LIST *pBase, ARG_NAME_LIST *pAdd)
276 if(pAdd) //even if nothing to concatenate, result == head
278 ARG_NAME_LIST *pAN = pBase;
282 for(; pAN->pNext; pAN = pAN->pNext) ;
285 for(pAN = pAdd; pAN; pAN->nNum = ++i, pAN = pAN->pNext);
287 else pBase = pAdd; //nothing to concatenate to, result == tail
292 int findArgNum(ARG_NAME_LIST *pFirst, LPCUTF8 szArgName, DWORD dwArgName)
298 for(pAN=pFirst; pAN; pAN = pAN->pNext)
300 if((pAN->dwName == dwArgName)&& ((dwArgName==0)||(!strcmp(pAN->szName,szArgName))))
310 int findLocSlot(ARG_NAME_LIST *pFirst, LPCUTF8 szArgName, DWORD dwArgName)
316 for(pAN=pFirst; pAN; pAN = pAN->pNext)
318 if((pAN->dwName == dwArgName)&& ((dwArgName==0)||(!strcmp(pAN->szName,szArgName))))
320 ret = (int)(pAN->dwAttr);
328 BinStr *m_pbsMethodSig;
329 COR_SIGNATURE* m_pMethodSig;
330 DWORD m_dwMethodCSig;
331 ARG_NAME_LIST *m_firstArgName;
332 ARG_NAME_LIST *m_firstVarName;
333 // to call error() from Method:
334 const char* m_FileName;
337 LinePCList m_LinePCList;
339 CustomDescrList m_CustomDescrList;
340 // token relocs (used for OBJ generation only)
342 // method's own list of method impls
343 MethodImplDList m_MethodImplDList;
344 // lexical scope handling
345 Assembler* m_pAssembler;
348 VarDescrList m_Locals;
352 Label *FindLabel(LPCUTF8 pszName);
353 Label *FindLabel(DWORD PC);
355 int FindTyPar(__in __nullterminated WCHAR* wz)
358 for(i=0; i < (int)m_NumTyPars; i++)
360 if(!wcscmp(wz,m_TyPars[i].Name()))
367 int FindTyPar(__in __nullterminated char* sz)
372 WszMultiByteToWideChar(g_uCodePage,0,sz,-1,wzUniBuf,dwUniBuf);
373 return FindTyPar(wzUniBuf);
379 #endif /* _METHOD_HPP */