📄 mal_parser.c
字号:
#line 978 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" /* the last argument may be variable length */ if( MALkeyword(cntxt,"...",3) ){ curInstr->varargs |= VARARGS; setPolymorphic(curInstr,TYPE_any,FALSE); break; } if ((ch = currChar(cntxt)) != ',') { if (ch == ')') break; return (MalBlkPtr) parseError(cntxt,"',' expected\n"); } else nextChar(cntxt); /* skip ',' */ skipSpace(cntxt); ch = currChar(cntxt); } if (currChar(cntxt) != ')') { freeInstruction(curInstr); return (MalBlkPtr) parseError(cntxt,"')' expected\n"); } advance(cntxt,1); /* skip ')' *//*The return type is either a single type or multiple return type structure.We simply keep track of the number of arguments added andduring the final phase reshuffle the return values to the beginning (?)*/ if (currChar(cntxt)== ':'){ type = typeElm(cntxt, TYPE_void); setPolymorphic(curInstr,type,TRUE); setVarType(curBlk,curInstr->argv[0],type); /* we may be confronted by a variable target type list */ if( MALkeyword(cntxt,"...",3) ){ curInstr->varargs |= VARRETS; setPolymorphic(curInstr,TYPE_any,FALSE); } #line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( keyphrase1(cntxt,"{")) { do { str pname,opname; int i,lo; ValRecord cst; l = idLength(cntxt); if(l==0) break; pname= idCopy(cntxt,l); if( curBlk->var[curInstr->argv[0]]->props== NULL) curBlk->var[curInstr->argv[0]]->props= newPropertySet(); /* localize value , simplified version */ lo= operatorLength(cntxt); if( lo > 0) opname= operatorCopy(cntxt,lo); else opname= GDKstrdup(""); if((i= cstToken(cntxt,&cst))){ setVarProperty(curBlk,curInstr->argv[0], pname, opname, &cst); advance(cntxt,i); } else setVarProperty(curBlk,curInstr->argv[0], pname, NULL, NULL); GDKfree(pname); GDKfree(opname); } while( keyphrase1(cntxt,",")); if( !keyphrase1(cntxt,"}") ) /* return (MalBlkPtr) */ parseError(cntxt,"'}' expected\n"); }#line 1014 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" } else if( keyphrase1(cntxt,"(")){ /* deal with compound return */ int retc= curInstr->argc, i1,i2=0; int maxarg; int *newarg; /* parse multi-target result */ /* skipSpace(cntxt);*/ ch= currChar(cntxt); while( ch !=')' && ch && !NL(ch)){ int varid=0; int type= TYPE_any; #line 1071 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" l = idLength(cntxt); if( l>0) { varid = findVariableLength(curBlk, CURRENT(cntxt), l); if( varid < 0){ varid = newVariable(curBlk,idCopy(cntxt,l),TYPE_any); type= typeElm(cntxt,TYPE_any); if( isPolymorphic(type) ) setPolymorphic(curInstr,type,TRUE); setVarType(curBlk,varid,type); #line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( keyphrase1(cntxt,"{")) { do { str pname,opname; int i,lo; ValRecord cst; l = idLength(cntxt); if(l==0) break; pname= idCopy(cntxt,l); if( curBlk->var[varid]->props== NULL) curBlk->var[varid]->props= newPropertySet(); /* localize value , simplified version */ lo= operatorLength(cntxt); if( lo > 0) opname= operatorCopy(cntxt,lo); else opname= GDKstrdup(""); if((i= cstToken(cntxt,&cst))){ setVarProperty(curBlk,varid, pname, opname, &cst); advance(cntxt,i); } else setVarProperty(curBlk,varid, pname, NULL, NULL); GDKfree(pname); GDKfree(opname); } while( keyphrase1(cntxt,",")); if( !keyphrase1(cntxt,"}") ) /* return (MalBlkPtr) */ parseError(cntxt,"'}' expected\n"); }#line 1080 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" } else if( 0){ parseError(cntxt,"Argument defined twice\n"); typeElm(cntxt,getVarType(curBlk,varid)); #line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( keyphrase1(cntxt,"{")) { do { str pname,opname; int i,lo; ValRecord cst; l = idLength(cntxt); if(l==0) break; pname= idCopy(cntxt,l); if( curBlk->var[varid]->props== NULL) curBlk->var[varid]->props= newPropertySet(); /* localize value , simplified version */ lo= operatorLength(cntxt); if( lo > 0) opname= operatorCopy(cntxt,lo); else opname= GDKstrdup(""); if((i= cstToken(cntxt,&cst))){ setVarProperty(curBlk,varid, pname, opname, &cst); advance(cntxt,i); } else setVarProperty(curBlk,varid, pname, NULL, NULL); GDKfree(pname); GDKfree(opname); } while( keyphrase1(cntxt,",")); if( !keyphrase1(cntxt,"}") ) /* return (MalBlkPtr) */ parseError(cntxt,"'}' expected\n"); }#line 1085 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" } else { advance(cntxt,l); type= typeElm(cntxt,getVarType(curBlk,varid)); if( type != getVarType(curBlk,varid)) parseError(cntxt,"Incompatible argument type\n"); if( isPolymorphic(type) ) setPolymorphic(curInstr,type,TRUE); setVarType(curBlk,varid,type); #line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( keyphrase1(cntxt,"{")) { do { str pname,opname; int i,lo; ValRecord cst; l = idLength(cntxt); if(l==0) break; pname= idCopy(cntxt,l); if( curBlk->var[varid]->props== NULL) curBlk->var[varid]->props= newPropertySet(); /* localize value , simplified version */ lo= operatorLength(cntxt); if( lo > 0) opname= operatorCopy(cntxt,lo); else opname= GDKstrdup(""); if((i= cstToken(cntxt,&cst))){ setVarProperty(curBlk,varid, pname, opname, &cst); advance(cntxt,i); } else setVarProperty(curBlk,varid, pname, NULL, NULL); GDKfree(pname); GDKfree(opname); } while( keyphrase1(cntxt,",")); if( !keyphrase1(cntxt,"}") ) /* return (MalBlkPtr) */ parseError(cntxt,"'}' expected\n"); }#line 1094 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" } } else if( currChar(cntxt)== ':' ){ type= typeElm(cntxt,TYPE_any); varid = newTmpVariable(curBlk,type); if( isPolymorphic(type) ) setPolymorphic(curInstr,type,TRUE); setVarType(curBlk,varid,type); #line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( keyphrase1(cntxt,"{")) { do { str pname,opname; int i,lo; ValRecord cst; l = idLength(cntxt); if(l==0) break; pname= idCopy(cntxt,l); if( curBlk->var[varid]->props== NULL) curBlk->var[varid]->props= newPropertySet(); /* localize value , simplified version */ lo= operatorLength(cntxt); if( lo > 0) opname= operatorCopy(cntxt,lo); else opname= GDKstrdup(""); if((i= cstToken(cntxt,&cst))){ setVarProperty(curBlk,varid, pname, opname, &cst); advance(cntxt,i); } else setVarProperty(curBlk,varid, pname, NULL, NULL); GDKfree(pname); GDKfree(opname); } while( keyphrase1(cntxt,",")); if( !keyphrase1(cntxt,"}") ) /* return (MalBlkPtr) */ parseError(cntxt,"'}' expected\n"); }#line 1102 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" } else parseError(cntxt,"argument expected\n"); curInstr= pushArgument(curBlk,curInstr, varid);#line 1026 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( (ch=currChar(cntxt)) != ',') { if( ch==')') break; return (MalBlkPtr) parseError(cntxt, "',' expected\n"); } else { nextChar(cntxt); /* skip ',' */ } skipSpace(cntxt); ch = currChar(cntxt); } /* re-arrange the parameters, results first*/ maxarg= curInstr->maxarg; newarg= (int*)GDKmalloc(maxarg*sizeof(int)); for(i1= retc; i1<curInstr->argc; i1++) newarg[i2++]= curInstr->argv[i1]; curInstr->retc= curInstr->argc-retc; for(i1= 1; i1<retc; i1++) newarg[i2++]= curInstr->argv[i1]; curInstr->argc= i2; for(; i2<maxarg; i2++) newarg[i2]= 0; for(i1=0; i1<maxarg; i1++) curInstr->argv[i1] = newarg[i1]; GDKfree(newarg); if (currChar(cntxt) != ')') { freeInstruction(curInstr); return (MalBlkPtr) parseError(cntxt, "')' expected\n"); } nextChar(cntxt); /* skip ')' */ } else { /* default */ setVarType(curBlk,0,TYPE_void); }#line 1193 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" getInstrPtr(curBlk,0)->token= kind; curPrg->kind = kind; modnme= modnme? modnme:cntxt->nspace->name; insertSymbol(findModule(cntxt->nspace, putName(modnme,strlen(modnme))), curPrg); trimMalBlk(curBlk); chkProgram(cntxt->nspace,curBlk); if( cntxt->backup){ cntxt->curprg = cntxt->backup; cntxt->backup = 0; }#line 1217 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( MALkeyword(cntxt,"address",7)){ str nme; int i; i = idLength(cntxt); if( i==0){ parseError(cntxt,"<identifier> expected\n"); return 0; } cntxt->blkmode=0; nme = idCopy(cntxt,i); if( getModuleId(curInstr)) setModuleId(curInstr, NULL); setModuleScope(curInstr, findModule(cntxt->nspace, putName(modnme,strlen(modnme))) ); curInstr->fcn = getAddress(cntxt->srcFile, modnme, nme,0); curBlk->binding = nme; if( cntxt->nspace->isAtomModule) malAtomProperty(curBlk, curInstr); } else { return (MalBlkPtr) parseError(cntxt,"'address' expected\n"); } #line 1170 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( MALkeyword(cntxt,"comment",7)){ if( (l= stringLength(cntxt))){ curBlk->help = strCopy(cntxt,l); advance(cntxt,l); } else { parseError(cntxt,"<string> expected\n"); } } else if (currChar(cntxt) != ';') parseError(cntxt,"';' expected\n"); skipToEnd(cntxt);#line 1238 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" showErrors(); if(curBlk && cntxt->listing) printFunction(GDKout, curBlk, cntxt->listing); return curBlk;}MalBlkPtr parseFunction(Client cntxt, int kind){ MalBlkPtr curBlk = 0; Symbol curPrg = 0; InstrPtr curInstr=0; int l; str fnme=0, modnme=0; char ch; int varid=0; int type= TYPE_any; #line 933 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" l = operatorLength(cntxt); if (l == 0) l = idLength(cntxt); if (l == 0) return (MalBlkPtr) parseError(cntxt, "<identifier> | <operator> expected\n"); fnme= putName( ((char *) CURRENT(cntxt)),l); advance(cntxt,l); if (currChar(cntxt) == '.') { nextChar(cntxt); /* skip '.' */ modnme = fnme; l= operatorLength(cntxt); if (l == 0) l = idLength(cntxt); if (l == 0) return (MalBlkPtr) parseError(cntxt, "<identifier> | <operator> expected\n"); fnme= putName( ((char *) CURRENT(cntxt)),l); advance(cntxt,l); } /* temporary suspend capturing statements in main block */ if( cntxt->backup && curBlk && curBlk->errors==0) GDKfatal("mal_parser: unexpected recursion\n"); cntxt->backup = cntxt->curprg; cntxt->curprg = newFunction(fnme, kind); curPrg = cntxt->curprg; curBlk = curPrg->def; curBlk->flowfixed= 0; curBlk->typefixed= 0; curInstr = getInstrPtr(curBlk,0); #line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( keyphrase1(cntxt,"{")) { do { str pname,opname; int i,lo; ValRecord cst; l = idLength(cntxt); if(l==0) break; pname= idCopy(cntxt,l); if( curBlk->var[curInstr->argv[0]]->props== NULL) curBlk->var[curInstr->argv[0]]->props= newPropertySet(); /* localize value , simplified version */ lo= operatorLength(cntxt); if( lo > 0) opname= operatorCopy(cntxt,lo); else opname= GDKstrdup(""); if((i= cstToken(cntxt,&cst))){ setVarProperty(curBlk,curInstr->argv[0], pname, opname, &cst); advance(cntxt,i); } else setVarProperty(curBlk,curInstr->argv[0], pname, NULL, NULL); GDKfree(pname); GDKfree(opname); } while( keyphrase1(cntxt,",")); if( !keyphrase1(cntxt,"}") ) /* return (MalBlkPtr) */ parseError(cntxt,"'}' expected\n"); }#line 966 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if (currChar(cntxt) != '(') return (MalBlkPtr)parseError(cntxt, "function header '(' expected\n"); advance(cntxt,1); setModuleId(curInstr, modnme?putName(modnme,strlen(modnme)): putName(cntxt->nspace->name, strlen(cntxt->nspace->name))); /* get calling parameters */ ch= currChar(cntxt); while( ch !=')' && ch && !NL(ch)){ #line 1071 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" l = idLength(cntxt); if( l>0) { varid = findVariableLength(curBlk, CURRENT(cntxt), l); if( varid < 0){ varid = newVariable(curBlk,idCopy(cntxt,l),TYPE_any); type= typeElm(cntxt,TYPE_any); if( isPolymorphic(type) ) setPolymorphic(curInstr,type,TRUE); setVarType(curBlk,varid,type); #line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( keyphrase1(cntxt,"{")) { do { str pname,opname; int i,lo; ValRecord cst; l = idLength(cntxt); if(l==0) break; pname= idCopy(cntxt,l); if( curBlk->var[varid]->props== NULL) curBlk->var[varid]->props= newPropertySet(); /* localize value , simplified version */ lo= operatorLength(cntxt); if( lo > 0) opname= operatorCopy(cntxt,lo); else opname= GDKstrdup(""); if((i= cstToken(cntxt,&cst))){ setVarProperty(curBlk,varid, pname, opname, &cst); advance(cntxt,i); } else setVarProperty(curBlk,varid, pname, NULL, NULL); GDKfree(pname); GDKfree(opname); } while( keyphrase1(cntxt,",")); if( !keyphrase1(cntxt,"}") ) /* return (MalBlkPtr) */ parseError(cntxt,"'}' expected\n"); }#line 1080 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" } else if( 1){ parseError(cntxt,"Argument defined twice\n"); typeElm(cntxt,getVarType(curBlk,varid)); #line 1127 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_parser.mx" if( keyphrase1(cntxt,"{")) { do { str pname,opname; int i,lo; ValRecord cst; l = idLength(cntxt); if(l==0) break; pname= idCopy(cntxt,l); if( curBlk->var[varid]->props== NULL) curBlk->var[varid]->props= newPropertySet(); /* localize value , simplified version */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -