// GENARG // GENARG ',' GENARGS BOOL CLRTypeName::TypeNameParser::GENARGS() { IfFalseReturn(TokenIs(TypeNameGENARGS)); IfFalseReturn(GENARG()); if (TokenIs(TypeNameComma)) { NextToken(); IfFalseReturn(GENARGS()); } return TRUE; }
// id // id '+' NESTNAME BOOL CLRTypeName::TypeNameParser::NESTNAME() { IfFalseReturn(TokenIs(TypeNameNESTNAME)); GetIdentifier(m_pTypeName->AddName(), TypeNameId); NextToken(); if (TokenIs(TypeNamePlus)) { NextToken(); IfFalseReturn(NESTNAME()); } return TRUE; }
void Expect(char *str) { GetToken(); if (TokenIs(str)) { return; } vcerr("error: %s expected, %s got", str, tok.ident); //token); }
// fusionName BOOL CLRTypeName::TypeNameParser::ASSEMSPEC() { IfFalseReturn(TokenIs(TypeNameASSEMSPEC)); GetIdentifier(m_pTypeName->GetAssembly(), TypeNameFusionName); NextToken(); return TRUE; }
// *empty* // '[' GENARGS ']' BOOL CLRTypeName::TypeNameParser::GENPARAMS() { if (!TokenIs(TypeNameGENPARAM)) { return TRUE; } if (!NextTokenIs(TypeNameGENARGS)) { return TRUE; } NextToken(); IfFalseReturn(GENARGS()); IfFalseReturn(TokenIs(TypeNameCloseSqBracket)); NextToken(); return TRUE; }
// NAME GENPARAMS QUALIFIER BOOL CLRTypeName::TypeNameParser::FULLNAME() { IfFalseReturn(TokenIs(TypeNameFULLNAME)); IfFalseReturn(NAME()); IfFalseReturn(GENPARAMS()); IfFalseReturn(QUALIFIER()); return TRUE; }
#include "stdafx.h" #define IfFalseReturn(P) if (!P) return FALSE; HRESULT CLRTypeName::ParseTypeName(LPCWSTR szTypeName, DWORD* pError, CLRTypeName** ppTypeName) { if (!ppTypeName || !pError) { return E_INVALIDARG; } HRESULT hr = S_OK; *ppTypeName = NULL; *pError = (DWORD)-1; CLRTypeName* pTypeName = new CLRTypeName(szTypeName, pError); if (!pTypeName) { hr = E_OUTOFMEMORY; } else { pTypeName->AddRef(); if (*pError != (DWORD)-1) { pTypeName->Release(); hr = S_FALSE; } else { *ppTypeName = pTypeName; } } return hr; } INT32 CLRTypeName::GetCharacterInfoHelper(WCHAR c, INT32 CharInfoType) { unsigned short result=0; if (!GetStringTypeEx(LOCALE_USER_DEFAULT, CharInfoType, &(c), 1, &result)) { _ASSERTE(!"This should not happen, verify the arguments passed to GetStringTypeEx()"); } return(INT32)result; } BOOL CLRTypeName::NativeIsWhiteSpace(WCHAR c) { if (c <= (WCHAR) 0x7F) // common case { BOOL result = (c == ' ') || (c == '\r') || (c == '\n') || (c == '\t') || (c == '\f') || (c == (WCHAR) 0x0B); ASSERT(result == ((GetCharacterInfoHelper(c, CT_CTYPE1) & C1_SPACE) != 0), ""); return result; } // GetCharacterInfoHelper costs around 160 instructions return((GetCharacterInfoHelper(c, CT_CTYPE1) & C1_SPACE)!=0); } ULONG CLRTypeName::AddRef() { m_count++; return m_count; } DWORD CLRTypeName::Release() { m_count--; DWORD dwCount = m_count; if (dwCount == 0) { delete this; } return dwCount; } CLRTypeName::~CLRTypeName() { for (ULONG i = m_genericArguments.Count(); i > 0; i--) { CLRTypeName* pGenericArgument = m_genericArguments.Element(i - 1); m_genericArguments.Remove(i - 1); pGenericArgument->Release(); } for (ULONG i = m_names.Count(); i > 0; i--) { StringBuffer* pBuffer = m_names.Element(i - 1); m_names.Remove(i - 1); delete pBuffer; } } CLRTypeName* CLRTypeName::AddGenericArgument() { CLRTypeName* pGenArg = new CLRTypeName(); pGenArg->AddRef(); pGenArg->m_bIsGenericArgument = TRUE; m_genericArguments.AddElement(pGenArg); return pGenArg; } CLRTypeName::TypeNameParser::TypeNameTokens CLRTypeName::TypeNameParser::LexAToken() { if (m_nextToken == TypeNameIdentifier) { return TypeNamePostIdentifier; } if (m_nextToken == TypeNameEnd) { return TypeNameEnd; } if (*m_itr == L'\0') { return TypeNameEnd; } if (NativeIsWhiteSpace(*m_itr)) { m_itr++; return LexAToken(); } WCHAR c = *m_itr; m_itr++; switch(c) { case L',': return TypeNameComma; case L'[': return TypeNameOpenSqBracket; case L']': return TypeNameCloseSqBracket; case L'&': return TypeNameAmperstand; case L'*': return TypeNameAstrix; case L'+': return TypeNamePlus; case L'\\': m_itr--; return TypeNameIdentifier; } ASSERT(!CLRTypeName::IsTypeNameReservedChar(c), ""); m_itr--; return TypeNameIdentifier; } BOOL CLRTypeName::TypeNameParser::GetIdentifier(StringBuffer* sszId, CLRTypeName::TypeNameParser::TypeNameIdentifiers identifierType) { ASSERT(m_currentToken == TypeNameIdentifier && m_nextToken == TypeNamePostIdentifier, ""); sszId->Clear(); LPCWSTR start = m_currentItr; DynamicArray<LPCWSTR> m_escape; if (identifierType == TypeNameId) { do { switch (* m_currentItr ++) { case L',': case L'[': case L']': case L'&': case L'*': case L'+': case L'\0': goto done; case L'\\': m_escape.AddElement(m_currentItr - 1); if (!CLRTypeName::IsTypeNameReservedChar(*m_currentItr) || *m_currentItr == '\0') { return FALSE; } m_currentItr++; break; default: break; } } while(true); done: m_currentItr--; } else if (identifierType == TypeNameFusionName) { while(*m_currentItr != L'\0') { m_currentItr++; } } else if (identifierType == TypeNameEmbeddedFusionName) { for (; (*m_currentItr != L'\0') && (*m_currentItr != L']'); m_currentItr++) { if (*m_currentItr == L'\\') { if (*(m_currentItr + 1) == L']') { m_escape.AddElement(m_currentItr); m_currentItr ++; continue; } } if (*m_currentItr == '\0') { return FALSE; } } if (*m_currentItr == L'\0') { return FALSE; } } else { return FALSE; } sszId->AppendWithLength(start, (size_t)(m_currentItr - start)); for (ULONG i = m_escape.Count(); i > 0; i--) { sszId->DelWCharsFromString((unsigned)(m_escape.Element(i - 1) - start), 1); } m_itr = m_currentItr; m_nextToken = LexAToken(); return TRUE; } BOOL CLRTypeName::TypeNameParser::START() { NextToken(); NextToken(); return AQN(); } // FULLNAME ',' ASSEMSPEC // FULLNAME // /* empty */ BOOL CLRTypeName::TypeNameParser::AQN() { IfFalseReturn(TokenIs(TypeNameAQN)); if (TokenIs(TypeNameEnd)) { return TRUE; } IfFalseReturn(FULLNAME()); if (TokenIs(TypeNameComma)) { NextToken(); IfFalseReturn(ASSEMSPEC()); } IfFalseReturn(TokenIs(TypeNameEnd)); return TRUE; }
// *empty* // ',' RANK BOOL CLRTypeName::TypeNameParser::RANK(DWORD* pdwRank) { if (!TokenIs(TypeNameRANK)) { return TRUE; } NextToken(); *pdwRank = *pdwRank + 1; IfFalseReturn(RANK(pdwRank)); return TRUE; }
// '[' EAQN ']' // FULLNAME BOOL CLRTypeName::TypeNameParser::GENARG() { IfFalseReturn(TokenIs(TypeNameGENARG)); CLRTypeName* pEnclosingTypeName = m_pTypeName; m_pTypeName = m_pTypeName->AddGenericArgument(); { if (TokenIs(TypeNameOpenSqBracket)) { NextToken(); IfFalseReturn(EAQN()); IfFalseReturn(TokenIs(TypeNameCloseSqBracket)); NextToken(); } else { IfFalseReturn(FULLNAME()); } } m_pTypeName = pEnclosingTypeName; return TRUE; }
void Expect(char *str) { GetToken(); if (TokenIs(str)) return; vcerr("error: %s expected, %s got", str, token); }
void CheckLibFunc() { int i; token_nvalue=0; token_type=0; if (TokenIs("if") || TokenIs("else") || TokenIs("for") || TokenIs("while") || TokenIs("switch") || TokenIs("case") || TokenIs("goto")) { token_type=RESERVED; return; } if (TokenIs("and")) { token_type=CONTROL; token[0]='&'; token[1]='&'; token[2]=0; return; } if (TokenIs("or")) { token_type=CONTROL; token[0]='|'; token[1]='|'; token[2]=0; return; } i=0; while (i<numhardfuncs) { if (!strcmp(hardfuncs[i], token)) break; i++; } if (i<numhardfuncs) { token_type=FUNCTION; token_subtype=op_BFUNC; funcidx=i; } i=0; while (i<numhardvar0) { if (!strcmp(hardvar0[i], token)) break; i++; } if (i<numhardvar0) { token_type=IDENTIFIER; varcategory=op_HVAR0; varidx=i; } i=0; while (i<numhardvar1) { if (!strcmp(hardvar1[i], token)) break; i++; } if (i<numhardvar1) { token_type=IDENTIFIER; varcategory=op_HVAR1; varidx=i; } i=0; while (i<numfuncs) { if (!strcmp(funcs[i].fname, token)) break; i++; } if (i<numfuncs) { token_type=FUNCTION; token_subtype=op_UFUNC; funcidx=i; } i=0; while (i<numvars) { if (!strcmp(vars[i].vname, token)) break; i++; } if (i<numvars) { token_type=IDENTIFIER; varidx=i; varcategory=op_UVAR; if (vars[varidx].arraylen>1) varcategory=op_UVARRAY; } i=0; while (i<funcs[c].numlocals) { if (!strcmp(larg[i], token)) break; i++; } if (i<funcs[c].numlocals) { token_type=IDENTIFIER; varidx=i; switch (funcs[c].argtype[varidx]) { case INT: varcategory=op_LVAR; break; case STRING: varcategory=op_SLOCAL; varidx=GetStringIdx(varidx); break; default: vcerr("um."); } } i=0; while (i<numstr) { if (!strcmp(str[i].vname, token)) break; i++; } if (i<numstr) { token_type=IDENTIFIER; varidx=i; varcategory=op_STRING; if (str[i].arraylen>1) varcategory=op_SARRAY; } }
void CheckLibFunc() { int n; tok.value=0; tok.type=0; //token_nvalue=0; //token_type=0; if (TokenIs("if") || TokenIs("else") || TokenIs("for") || TokenIs("while") || TokenIs("switch") || TokenIs("case") || TokenIs("goto")) { tok.type=RESERVED; //token_type=RESERVED; return; } if (TokenIs("and")) { tok.type=CONTROL; tok.ident[0]='&'; tok.ident[1]='&'; tok.ident[2]='\0'; //token_type=CONTROL; //token[0]='&'; token[1]='&'; token[2]=0; return; } if (TokenIs("or")) { tok.type=CONTROL; tok.ident[0]='|'; tok.ident[1]='|'; tok.ident[2]='\0'; //token_type=CONTROL; //token[0]='|'; token[1]='|'; token[2]=0; return; } if (!hardfuncs_hash_ready) { init_hardfuncs_hash(); } hardfunc_lookup::iterator iter=hardfuncs_hash.find(tok.ident); if (iter!=hardfuncs_hash.end()) { //printf("matched hardfunc: %s\n", tok.ident); hardfunc_t* hfunc=iter->second; tok.type=FUNCTION; tok.subtype=op_BFUNC; tok.index=hfunc->index; return; } //for (n=0; n<numhardfuncs; n++) //{ // if (!strcmp(hardfuncs[n], tok.ident)) //token)) // { // //token_type=FUNCTION; // //token_subtype=op_BFUNC; // //funcidx=n; // tok.type=FUNCTION; // tok.subtype=op_BFUNC; // tok.index=n; // return; // } //} if (!hardvar0_hash_ready) { init_hardvar0_hash(); } hardvar0_lookup::iterator h0iter=hardvar0_hash.find(tok.ident); if (h0iter!=hardvar0_hash.end()) { //printf("matched hardvar0: %s\n", tok.ident); tok.type=IDENTIFIER; tok.subtype=op_HVAR0; tok.index=h0iter->second; return; } //for (n=0; n<numhardvar0; n++) //{ // if (!strcmp(hardvar0[n], tok.ident)) //token)) // { // //token_type=IDENTIFIER; // //varcategory=op_HVAR0; // //varidx=n; // tok.type=IDENTIFIER; // tok.subtype=op_HVAR0; // tok.index=n; // return; // } //} if (!hardvar1_hash_ready) { init_hardvar1_hash(); } hardvar1_lookup::iterator h1iter=hardvar1_hash.find(tok.ident); if (h1iter!=hardvar1_hash.end()) { //printf("matched hardvar1: %s\n", tok.ident); tok.type=IDENTIFIER; tok.subtype=op_HVAR1; tok.index=h1iter->second; return; } //for (n=0; n<numhardvar1; n++) //{ // if (!strcmp(hardvar1[n], tok.ident)) //token)) // { // //token_type=IDENTIFIER; // //varcategory=op_HVAR1; // //varidx=n; // tok.type=IDENTIFIER; // tok.subtype=op_HVAR1; // tok.index=n; // return; // } //} if (functionlist_array.size())//number_nodes()) { find_fun=0; function_lookup::iterator iter=functionlist.find(tok.ident); if (iter!=functionlist.end()) { tok.type=FUNCTION; tok.subtype=op_UFUNC; tok.index=iter->second->created_index; find_fun=iter->second; return; } //for (n=0; n<(int)functionlist.size(); n++) { // function_t* f=functionlist[n]; // try { // if (!strcmp(f->fname, tok.ident)) { // tok.type=FUNCTION; // tok.subtype=op_UFUNC; // tok.index=n; // find_fun=f; // return; // } // } catch (...) { // printf("exception during strcmp: f=%p, tok.ident=%s\n",f,tok.ident); // } //} //do //{ // function_t* f=(function_t *)functionlist.current(); // if (!strcmp(f->fname, tok.ident)) //token)) // { // tok.type=FUNCTION; // tok.subtype=op_UFUNC; // tok.index=n; // //token_type=FUNCTION; // //token_subtype=op_UFUNC; // //funcidx=n; // find_fun=f; // return; // } // functionlist.go_next(); // n++; //} while (functionlist.current() != functionlist.head()); } if (current_func) { for (n=0; n<current_func->numlocals; n++) { if (!strcmp(larg[n], tok.ident)) //token)) { //token_type=IDENTIFIER; //varidx=0; tok.type=IDENTIFIER; tok.index=0; switch (current_func->argtype[n]) { case INT: tok.subtype=op_LVAR; tok.index=GetVarIdx(n); //varcategory=op_LVAR; //varidx=GetVarIdx(n); break; case STRING: tok.subtype=op_SLOCAL; tok.index=GetStringIdx(n); //varcategory=op_SLOCAL; //varidx=GetStringIdx(n); break; default: vcerr("CheckLibFunc: invalid local type (weird): %d", current_func->argtype[n]); } return; } } } if (varlist_array.size())//number_nodes()) { variable_lookup::iterator iter=varlist.find(tok.ident); if (iter!=varlist.end()) { tok.type=IDENTIFIER; tok.subtype=(iter->second->arraylen>1) ? op_UVARRAY : op_UVAR; tok.index=iter->second->created_index; find_var=iter->second; return; } //find_var=0; //for (n=0; n<(int)varlist.size(); n++) { // variable_t* v=varlist[n]; // if (!strcmp(v->vname, tok.ident)) { // tok.type=IDENTIFIER; // tok.subtype=(v->arraylen>1) ? op_UVARRAY : op_UVAR; // tok.index=n; // find_var=v; // return; // } //} //varlist.go_head(); //do //{ // variable_t* v=(variable_t *)varlist.current(); // if (!strcmp(v->vname, tok.ident)) //token)) // { // tok.type=IDENTIFIER; // tok.subtype=(v->arraylen>1) ? op_UVARRAY : op_UVAR; // tok.index=n; // //token_type=IDENTIFIER; // //varcategory=(v->arraylen>1) ? op_UVARRAY : op_UVAR; // //varidx=n; // find_var=v; // return; // } // varlist.go_next(); // n++; //} while (varlist.current() != varlist.head()); } if (strlist.size())//number_nodes()) { find_str=0; string_lookup::iterator iter=strlist.find(tok.ident); if (iter!=strlist.end()) { tok.type=IDENTIFIER; tok.subtype=(iter->second->arraylen>1) ? op_SARRAY : op_STRING; tok.index=iter->second->created_index; find_str=iter->second; return; } //for (n=0; n<(int)strlist.size(); n++) { // string_sym* s=strlist[n]; // if (!strcmp(s->vname, tok.ident)) { // tok.type=IDENTIFIER; // tok.subtype=(s->arraylen>1) ? op_SARRAY : op_STRING; // tok.index=n; // find_str=s; // return; // } //} //strlist.go_head(); //do //{ // string_t* s=(string_t *)strlist.current(); // if (!strcmp(s->vname, tok.ident)) //token)) // { // tok.type=IDENTIFIER; // tok.subtype=(s->arraylen>1) ? op_SARRAY : op_STRING; // tok.index=n; // //token_type=IDENTIFIER; // //varcategory=(s->arraylen>1) ? op_SARRAY : op_STRING; // //varidx=n; // find_str=s; // return; // } // strlist.go_next(); // n++; //} while (strlist.current() != strlist.head()); } }