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()); } }