summaryrefslogtreecommitdiff
path: root/src/ilasm/grammar_before.cpp
blob: 60d6b57b3b568112de708a4718efbdb9bc62de27 (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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
//
#include <asmparse.h>
#include <assembler.h>

// Disable the "initialization of static local vars is no thread safe" error
#ifdef _MSC_VER
#pragma warning(disable : 4640)
#endif

#define YYMAXDEPTH 0x80000
//#define YYRECURSIVE

//#define DEBUG_PARSING
#ifdef DEBUG_PARSING
bool parseDBFlag = true;
#define dbprintf(x)     if (parseDBFlag) printf x
#define YYDEBUG 1
#else
#define dbprintf(x)     
#endif

#define FAIL_UNLESS(cond, msg) if (!(cond)) { parser->success = false; parser->error msg; }

static AsmParse* parser = 0;
#define PASM    (parser->assem)
#define PASMM   (parser->assem->m_pManifest)
#define PENV    (parser->penv)

#if (0)

#define nextchar                parser->penv->pfn_nextchar
#define Sym                     parser->penv->pfn_Sym
#define NewStrFromToken         parser->penv->pfn_NewStrFromToken
#define NewStaticStrFromToken   parser->penv->pfn_NewStaticStrFromToken
#define GetDouble               parser->penv->pfn_GetDouble

void SetFunctionPtrs() {;}

#else


PFN_NEXTCHAR    nextchar;
PFN_SYM         Sym;
PFN_NEWSTRFROMTOKEN NewStrFromToken;
PFN_NEWSTATICSTRFROMTOKEN NewStaticStrFromToken;
PFN_GETDOUBLE   GetDouble;

void SetFunctionPtrs()
{
    nextchar = PENV->pfn_nextchar;
    Sym = PENV->pfn_Sym;
    NewStrFromToken = PENV->pfn_NewStrFromToken;
    NewStaticStrFromToken = PENV->pfn_NewStaticStrFromToken;
    GetDouble = PENV->pfn_GetDouble;
}    
    
#endif    

static char* newStringWDel(__in __nullterminated char* str1, char delimiter, __in __nullterminated char* str3 = 0);
static char* newString(__in __nullterminated char* str1);
static void corEmitInt(BinStr* buff, unsigned data);
static void AppendStringWithLength(BinStr* pbs, __in __nullterminated char* sz);
bool bParsingByteArray = FALSE;
int iOpcodeLen = 0;
int iCallConv = 0;
unsigned IfEndif = 0;
unsigned IfEndifSkip = 0;
unsigned nCustomBlobNVPairs = 0;
unsigned nSecAttrBlobs = 0;
unsigned  nCurrPC = 0;
BOOL SkipToken = FALSE;
BOOL neg = FALSE;
BOOL newclass = FALSE;

extern unsigned int g_uConsoleCP;

struct VarName
{
    char* name;
    BinStr* pbody;
    VarName(__in_opt __nullterminated char* sz, BinStr* pbs) { name = sz; pbody = pbs; };
    ~VarName() { delete [] name; delete pbody; };
    int ComparedTo(VarName* pN) { return strcmp(name,pN->name); };
};
SORTEDARRAY<VarName> VarNameList;
void DefineVar(__in __nullterminated char* sz, BinStr* pbs) { VarNameList.PUSH(new VarName(sz,pbs)); };
void UndefVar(__in __nullterminated char* sz) 
{ 
    CHECK_LOCAL_STATIC_VAR(static VarName VN(NULL,NULL)); 

    VN.name = sz; 
    VarNameList.DEL(&VN); 
    VN.name = NULL; 
    delete [] sz;
}
VarName* FindVarDef(__in __nullterminated char* sz)
{
    CHECK_LOCAL_STATIC_VAR(static VarName VN(NULL,NULL));

    VarName* Ret = NULL;
    VN.name = sz;
    Ret = VarNameList.FIND(&VN);
    VN.name = NULL; 
    delete [] sz;
    return Ret;
}
BOOL IsVarDefined(__in __nullterminated char* sz)
{
    return (FindVarDef(sz) != NULL);
}

int  nTemp=0;

unsigned int uMethodBeginLine,uMethodBeginColumn;

#define ELEMENT_TYPE_VARFIXUP ELEMENT_TYPE_MAX+2
#define ELEMENT_TYPE_MVARFIXUP ELEMENT_TYPE_MAX+3

FIFO<char> TyParFixupList;
void FixupTyPars(PCOR_SIGNATURE pSig, ULONG cSig);
void FixupTyPars(BinStr* pbstype);
void FixupConstraints()
{
    if((TyParFixupList.COUNT()) && (PASM->m_TyParList))
    {
        TyParList* pTPL;
        for(pTPL = PASM->m_TyParList; pTPL; pTPL=pTPL->Next())
        {
            mdToken* ptk;
            for(ptk = (mdToken*)(pTPL->Bound()->ptr()); *ptk; ptk++)
            {
                if(TypeFromToken(*ptk)==mdtTypeSpec)
                {
                    PCOR_SIGNATURE pSig;
                    ULONG cSig;
                    PASM->m_pImporter->GetTypeSpecFromToken(*ptk,(PCCOR_SIGNATURE*)&pSig,&cSig);
                    if((pSig)&&(cSig))
                    {
                        FixupTyPars(pSig,cSig);    
                    } // end if((pSig)&&(cSig))
                } // end if(TypeFromToken(*ptk)==mdtTypeSpec)
            } //end for(ptk    
        } // end for(pTPL
    } //end if((TyParFixupList.COUNT()) 
}

#define SET_PA(x,y,z) {x = (CorAssemblyFlags)(((y) & ~afPA_FullMask)|(z)|afPA_Specified);}