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.
10 #include "assembler.h"
12 Method::Method(Assembler *pAssembler, Class *pClass, __in __nullterminated char *pszName, BinStr* pbsSig, DWORD Attr)
20 m_dwNumExceptions = 0;
21 m_dwNumEndfilters = 0;
22 m_firstArgName = NULL;
23 m_firstVarName = NULL;
25 m_wImplAttr = miIL; //default, if native or optil are not specified
28 m_pAssembler = pAssembler;
29 m_pCurrScope = &m_MainScope;
32 m_szExportAlias = NULL;
33 m_dwExportOrdinal = 0xFFFFFFFF;
34 m_ulLines[0]=m_ulLines[1]=0;
35 m_ulColumns[0]=m_ulColumns[0]=0;
40 // move the PInvoke descriptor (if any) from Assembler
41 // (Assembler gets the descriptor BEFORE it calls new Method)
42 m_pPInvoke = pAssembler->m_pPInvoke;
43 pAssembler->m_pPInvoke = NULL;
49 m_dwName = (DWORD)strlen(pszName);
51 m_ExceptionList = new COR_ILMETHOD_SECT_EH_CLAUSE_FAT[MAX_EXCEPTIONS];
52 m_EndfilterOffsetList = new DWORD[MAX_EXCEPTIONS];
53 if((m_ExceptionList==NULL)||(m_EndfilterOffsetList==NULL))
55 fprintf(stderr,"\nOutOfMemory!\n");
58 m_dwMaxNumExceptions = MAX_EXCEPTIONS;
59 m_dwMaxNumEndfilters = MAX_EXCEPTIONS;
62 if((!strcmp(pszName,COR_CCTOR_METHOD_NAME))||(!strcmp(pszName,COR_CTOR_METHOD_NAME)))
63 m_Attr |= mdSpecialName;
64 m_fEntryPoint = FALSE;
65 m_fGlobalMethod = FALSE;
69 m_dwMethodCSig = pbsSig->length();
70 m_pMethodSig = (COR_SIGNATURE*)(pbsSig->ptr());
71 m_pbsMethodSig = pbsSig;
74 m_firstArgName = pAssembler->getArgNameList();
75 if(pClass == NULL) pClass = pAssembler->m_pModuleClass; // fake "class" <Module>
76 pClass->m_MethodList.PUSH(this);
77 pClass->m_fNewMembers = TRUE;
80 m_pPermissions = NULL;
81 m_pPermissionSets = NULL;
88 // lexical scope handling
89 void Method::OpenScope()
91 Scope* psc = new Scope;
94 psc->dwStart = m_pAssembler->m_CurPC;
95 psc->pSuperScope = m_pCurrScope;
96 m_pCurrScope->SubScope.PUSH(psc);
100 void Method::CloseScope()
104 for(pAN=m_pCurrScope->pLocals; pAN; pAN = pAN->pNext)
106 if((pVD = m_Locals.PEEK(pAN->dwAttr))) pVD->bInScope = FALSE;
108 m_pCurrScope->dwEnd = m_pAssembler->m_CurPC;
109 m_pCurrScope = m_pCurrScope->pSuperScope;
112 Label *Method::FindLabel(LPCUTF8 pszName)
114 Label lSearch(pszName,0), *pL;
115 lSearch.m_szName = pszName;
116 //pL = m_lstLabel.FIND(&lSearch);
117 pL = m_pAssembler->m_lstLabel.FIND(&lSearch);
118 lSearch.m_szName = NULL;
120 //return m_lstLabel.FIND(pszName);
124 Label *Method::FindLabel(DWORD PC)
128 //for (int i = 0; (pSearch = m_lstLabel.PEEK(i)); i++)
129 for (int i = 0; (pSearch = m_pAssembler->m_lstLabel.PEEK(i)); i++)
131 if (pSearch->m_PC == PC)