Welcome to mirror list, hosted at ThFree Co, Russian Federation.

method.cpp « ilasm « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10fd7537f3201f7838c307fe3c4c016150b4f61a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// file: method.cpp
//

//
#include "ilasmpch.h"
#include "assembler.h"

Method::Method(Assembler *pAssembler, Class *pClass, __in __nullterminated char *pszName, BinStr* pbsSig, DWORD Attr)
{

    // default values
    m_pClass        = pClass;
    m_MaxStack      = 8;
    m_Flags         = 0;
    m_LocalsSig     = 0;
    m_dwNumExceptions = 0;
    m_dwNumEndfilters = 0;
    m_firstArgName = NULL;
    m_firstVarName = NULL;
    m_pMethodSig = NULL;
    m_wImplAttr = miIL; //default, if native or optil are not specified
    m_wVTEntry = 0;
    m_wVTSlot = 0;
    m_pAssembler = pAssembler;
    m_pCurrScope = &m_MainScope;
    m_pRetMarshal = NULL;
    m_pRetValue = NULL;
    m_szExportAlias = NULL;
    m_dwExportOrdinal = 0xFFFFFFFF;
    m_ulLines[0]=m_ulLines[1]=0;
    m_ulColumns[0]=m_ulColumns[1]=0;
    m_pbsBody = NULL;
    m_fNewBody = TRUE;
    m_fNew = TRUE;

    // move the PInvoke descriptor (if any) from Assembler
    // (Assembler gets the descriptor BEFORE it calls new Method)
    m_pPInvoke = pAssembler->m_pPInvoke;
    pAssembler->m_pPInvoke = NULL;

    _ASSERTE(pszName);
    if (!pszName) return;

    m_szName = pszName;
    m_dwName = (DWORD)strlen(pszName);

    m_ExceptionList = new COR_ILMETHOD_SECT_EH_CLAUSE_FAT[MAX_EXCEPTIONS];
    m_EndfilterOffsetList = new DWORD[MAX_EXCEPTIONS];
    if((m_ExceptionList==NULL)||(m_EndfilterOffsetList==NULL))
    {
        fprintf(stderr,"\nOutOfMemory!\n");
        return;
    }
    m_dwMaxNumExceptions = MAX_EXCEPTIONS;
    m_dwMaxNumEndfilters = MAX_EXCEPTIONS;

    m_Attr          = Attr;
    if((!strcmp(pszName,COR_CCTOR_METHOD_NAME))||(!strcmp(pszName,COR_CTOR_METHOD_NAME)))
        m_Attr |= mdSpecialName;
    m_fEntryPoint   = FALSE;
    m_fGlobalMethod = FALSE;

    if(pbsSig)
    {
        m_dwMethodCSig = pbsSig->length();
        m_pMethodSig = (COR_SIGNATURE*)(pbsSig->ptr());
        m_pbsMethodSig = pbsSig;
    }

    m_firstArgName = pAssembler->getArgNameList();
    if(pClass == NULL) pClass = pAssembler->m_pModuleClass; // fake "class" <Module>
    pClass->m_MethodList.PUSH(this);
    pClass->m_fNewMembers = TRUE;


    m_pPermissions = NULL;
    m_pPermissionSets = NULL;

    m_TyPars = NULL;
    m_NumTyPars = 0;
}


// lexical scope handling
void Method::OpenScope()
{
    Scope*  psc = new Scope;
    if(psc)
    {
        psc->dwStart = m_pAssembler->m_CurPC;
        psc->pSuperScope = m_pCurrScope;
        m_pCurrScope->SubScope.PUSH(psc);
        m_pCurrScope = psc;
    }
}
void Method::CloseScope()
{
    VarDescr*       pVD;
    ARG_NAME_LIST*  pAN;
    for(pAN=m_pCurrScope->pLocals; pAN; pAN = pAN->pNext)
    {
        if((pVD = m_Locals.PEEK(pAN->dwAttr))) pVD->bInScope = FALSE;
    }
    m_pCurrScope->dwEnd = m_pAssembler->m_CurPC;
    m_pCurrScope = m_pCurrScope->pSuperScope;
}

Label *Method::FindLabel(LPCUTF8 pszName)
{
    Label lSearch(pszName,0), *pL;
    lSearch.m_szName = pszName;
    //pL =  m_lstLabel.FIND(&lSearch);
    pL =  m_pAssembler->m_lstLabel.FIND(&lSearch);
    lSearch.m_szName = NULL;
    return pL;
    //return  m_lstLabel.FIND(pszName);
}


Label *Method::FindLabel(DWORD PC)
{
    Label *pSearch;

    //for (int i = 0; (pSearch = m_lstLabel.PEEK(i)); i++)
    for (int i = 0; (pSearch = m_pAssembler->m_lstLabel.PEEK(i)); i++)
    {
        if (pSearch->m_PC == PC)
            return pSearch;
    }

    return NULL;
}

// Method::AddGenericParamConstraint is called when we have a .param constraint directive after a method definition
// 
void Method::AddGenericParamConstraint(int index, char * pStrGenericParam, mdToken tkTypeConstraint)
{
    if (index > 0)
    {
        if (pStrGenericParam != 0)
        {
            m_pAssembler->report->error("LOGIC ERROR - we have both an index and a pStrGenericParam");
            return;
        }
        if (index > (int)m_NumTyPars)
        {
            m_pAssembler->report->error("Type parameter index out of range: 1.. %d\n", m_NumTyPars);
            return;
        }
        index = index - 1;
    }
    else  // index was 0, so a name must be supplied by pStrGenericParam
    {
        if (pStrGenericParam == 0)
        {
            m_pAssembler->report->error("LOGIC ERROR - we have neither an index or a pStrGenericParam");
            return;
        }
        index = FindTyPar(pStrGenericParam);
        if (index == -1)
        {
            m_pAssembler->report->error("Type parameter '%s' undefined\n", pStrGenericParam);
            return;
        }
    }

    // pass true for isParamDirective, we are parsing a .param directive for a method here
    //
    m_pAssembler->CheckAddGenericParamConstraint(&m_GPCList, index, tkTypeConstraint, true);
}