⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrappergen.c

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 C
📖 第 1 页 / 共 3 页
字号:
  while (!reachedEnd && ReadUntilEscape( finfo, &preceding,					 &bodyList, &bodyLen,					 &bodyLit, &startingLine )) {    /* save the stuff before the escape was reached */    for (i=0; preceding[i]; i++)      ListAddItem( body, char, preceding[i] );    /* if the body is non-null */    if (bodyLen) {#if DEBUG      fprintf( stderr, "ReadUntilmatch hit :%s:\n", bodyList[0] );#endif	/* go one level deeper; found {{foreach}} within {{foreach}} */      if (!strcmp( bodyList[0], start )) {#if DEBUG>1	fprintf( stderr, "level deeper...\n" );#endif	stackLevel++;	for (i=0; bodyLit[i]; i++)	  ListAddItem( body, char, bodyLit[i] );      } else if (!strcmp( bodyList[0], end )) {#if DEBUG>1	fprintf( stderr, "level higher...\n" );#endif	stackLevel--;	if (!stackLevel) {	  reachedEnd = 1;	} else {	  for (i=0; bodyLit[i]; i++)	    ListAddItem( body, char, bodyLit[i] );	}		/* unrecognized escape, doesn't matter */      } else {	for (i=0; bodyLit[i]; i++)	  ListAddItem( body, char, bodyLit[i] );      }            /* null body, add directly */    } else {      for (i=0; bodyLit[i]; i++)	ListAddItem( body, char, bodyLit[i] );    }    free( bodyList );  free( bodyLit );  free( preceding );  }  if (reachedEnd) {    ListAddItem( body, char, '\0' );    ListClose( body, char, *escbody, i );  } else {    fprintf( stderr, "No matching '%s' for '%s' in file %s, line %d.\n",	     end, start, finfo->name, initialLine );    ListDestroy( body, char );  }  return reachedEnd;}void DoForEach( outf, finfo, rinfo, bodyList, bodyLen, escBody,	        startLine, body )FILE *outf;fileinfo *finfo;rpcinfo *rinfo;char *body, **bodyList, *escBody;int  bodyLen, startLine;{  int i, fn_num;  replacement rpc;  fileinfo my_finfo;#if DEBUG>1  printf( "For each occurrence of %s in :%s:, replace with:\n",	  bodyList[1], body );  for (i=2; i<bodyLen; i++) {    printf( "%s\n", bodyList[i] );  }#endif  rpc.from = bodyList[1];  my_finfo.name = finfo->name;  my_finfo.filenum = finfo->filenum;  for (i=2; i<bodyLen; i++) {    my_finfo.lineno = startLine;    my_finfo.str = body;    /* StrToLower( bodyList[i] ); */    fn_num = IsFnInList( bodyList[i], rinfo->fn_list, rinfo->n_fn );    if (fn_num != -1) {      rpc.to = rinfo->fn_list[fn_num].name;      ListAddItem( rinfo->rpc, replacement, rpc );#if DEBUG      fprintf( stderr, "foreach replacement of %s with %s.\n",	       bodyList[1], rinfo->fn_list[fn_num].name );#endif      /* wrappers should not be defined within a foreach or forall */      ProcessString( outf, &my_finfo, rinfo, (wrapperinfo *)0 );      ListRemoveItems( rinfo->rpc, replacement, 1 );    }  }}void DoForAll( outf, finfo, rinfo, bodyList, bodyLen, escBody, startLine,	       body )FILE *outf;fileinfo *finfo;rpcinfo *rinfo;char *body, **bodyList, *escBody;int  bodyLen, startLine;{  int i, fn_num;  replacement rpc;  fileinfo my_finfo;#if DEBUG>1  printf( "For each occurrence of %s in :%s:, replace with:\n",	  bodyList[1], body );  for (i=2; i<bodyLen; i++) {    printf( "%s\n", bodyList[i] );  }#endif  rpc.from = bodyList[1];  my_finfo.name = finfo->name;  my_finfo.filenum = finfo->filenum;  for (fn_num=0; fn_num < rinfo->n_fn; fn_num++) {      /* don't expand for the functions named */    if (!IsNameInList( rinfo->fn_list[fn_num].name, bodyList+2, bodyLen-2 )) {      my_finfo.lineno = startLine;      my_finfo.str = body;      rpc.to = rinfo->fn_list[fn_num].name;      ListAddItem( rinfo->rpc, replacement, rpc );#if DEBUG      fprintf( stderr, "foreach replacement of %s with %s.\n",	      bodyList[1], rinfo->fn_list[fn_num].name );#endif      /* wrappers should not be defined within a foreach or forall */      ProcessString( outf, &my_finfo, rinfo, (wrapperinfo *)0 );            ListRemoveItems( rinfo->rpc, replacement, 1 );    } else {#if DEBUG      fprintf( stderr, "Don't foreach replace %s.\n",	      rinfo->fn_list[fn_num].name );#endif    }  }}void DoFnAll( finfo, rinfo, winfo, argv, argc, body, startLine )fileinfo *finfo;rpcinfo *rinfo;wrapperinfo *winfo;char *body, **argv;int argc, startLine;{#if DEBUG  fprintf( stderr, "fnall :%s:\n", body );#endif  ReadFnDef( finfo, rinfo, winfo, argv, argc, body, startLine, 1 );}void DoFn( finfo, rinfo, winfo, argv, argc, body, startLine )fileinfo *finfo;rpcinfo *rinfo;wrapperinfo *winfo;char *body, **argv;int argc, startLine;{#if DEBUG  fprintf( stderr, "fn :%s:\n", body );#endif  ReadFnDef( finfo, rinfo, winfo, argv, argc, body, startLine, 0 );}void ReadFnDef( finfo, rinfo, winfo, argv, argc, body, startLine, allFn )fileinfo *finfo;rpcinfo *rinfo;wrapperinfo *winfo;char *body, **argv;int argc, startLine, allFn;{  int i, fn_num, lineNo, escLen, escStartLine;  replacement rpc;  char *bodyCopy, *escBody, **escList, *preceding,       *prefixEnd, *suffixStart;  wrapperdef newWrapper;  variable newVar;  xpandList vars, varStr;  fileinfo my_finfo;  lineNo = startLine;  bodyCopy = body;  ListCreate( vars, variable, 5 );  ListCreate( varStr, char, 100 );  newWrapper.prefixCode = newWrapper.suffixCode = 0;  newWrapper.prefixLineNo = startLine;  newWrapper.finfo = *finfo;  newWrapper.firstLine = startLine;    /* copies over the filename, file number */    my_finfo = *finfo;  my_finfo.str = body;  my_finfo.lineno = startLine;  while (ReadUntilEscape( &my_finfo, &preceding, &escList, &escLen, &escBody,			  &escStartLine )) {    for (i=0; preceding[i]; i++)      ListAddItem( varStr, char, preceding[i] );    if (escLen) {      /* if variable declaration found */      if (!strcmp( escList[0], "vardecl" )) {	ReadVardecl( finfo, escStartLine, escBody, winfo, vars );	/* if the {{callfn}} escape, */      } else if (!strcmp( escList[0], "callfn" )) {	  /* make sure there aren't more than one calls */	if (!newWrapper.prefixCode) {	    /* close out the preceding string */	  ListAddItem( varStr, char, '\0' );	    /* close out the preceding stuff */	  ListClose( varStr, char, newWrapper.prefixCode, i );	    /* open up new list for the suffix code */	  ListCreate( varStr, char, 100 );	  newWrapper.suffixLineNo = escStartLine;	} else {	  fprintf( stderr, "multiple {{callfn}} in file %s, line %d\n",		   finfo->name, escStartLine );	}	/* unrecognized escape, probably an argument or variable name */	/* just copy it out directly */      } else {	for (i=0; escBody[i]; i++)	  ListAddItem( varStr, char, escBody[i] );      }    }  }  /* while */  for (i=0; preceding[i]; i++)    ListAddItem( varStr, char, preceding[i] );    /* close out the code copy */  ListAddItem( varStr, char, '\0' );  if (newWrapper.prefixCode) {    ListClose( varStr, char, newWrapper.suffixCode, i );  } else {    fprintf( stderr, "warning: no {{callfn}} in wrapper definition starting \inf file %s at line %d.\n", finfo->name, startLine );    ListClose( varStr, char, newWrapper.prefixCode, i );  }  ListClose( vars, variable, newWrapper.vars, newWrapper.nvars );  newWrapper.nameEscape = argv[1];  if (allFn) {    for (fn_num=0; fn_num<rinfo->n_fn; fn_num++) {        /* keep out exclusions */      if (!IsNameInList( rinfo->fn_list[fn_num].name, argv+2, argc-2 )) {	ListAddItem( rinfo->fn_list[fn_num].wrapperdefs, int,		     ListSize( winfo->wrapperDefs, wrapperdef ) );      }    }  } else {    for (i=2; i<argc; i++) {      /* StrToLower( argv[i] ); */      fn_num = IsFnInList( argv[i], rinfo->fn_list, rinfo->n_fn );      if (fn_num != -1) {	ListAddItem( rinfo->fn_list[fn_num].wrapperdefs, int,		    ListSize( winfo->wrapperDefs, wrapperdef ) );      }    }  }  ListAddItem( winfo->wrapperDefs, wrapperdef, newWrapper );}void ReadVardecl( finfo, startLine, body, winfo, vars )fileinfo *finfo;char *body;wrapperinfo *winfo;xpandList vars;int startLine;{  char *basetype, *readPt, *varPrefix, *varName, *varSuffix;  variable newVar;  /* skip "vardecl", read the base type ("static unsigned long"),     and return a pointer to just after the base type */  if (ReadVardeclBasetype( finfo->name, startLine, body,			   &basetype, &readPt )) {    while (ReadVardeclVarname( &readPt, &varPrefix, &varName,			       &varSuffix )) {      newVar.rqName = varName;        /* one extra for '\0', one for the space between	   basetype and varPrefix */      newVar.typePrefix = (char *)malloc( strlen( basetype ) +					  strlen( varPrefix ) + 2 );      sprintf( newVar.typePrefix, "%s %s", basetype, varPrefix );      free( varPrefix );      newVar.typeSuffix = varSuffix;      ListAddItem( vars, variable, newVar );    }  }}int ReadVardeclBasetype( filename, lineno, body, basetype, end)char *body, **basetype, **end, *filename;int lineno;{  char *typeEnd1, *typeEnd2, *ptr, *typeStart;  int readingIdent;  ptr = body+2;			/* skip over "{{" */  body[strlen(body)-2] = '\0';	/* chop off "}}" */  while (isspace(*ptr)) ptr++;  if (strncmp( ptr, "vardecl", 7)) {    /* doesn't start with vardecl? */    fprintf( stderr, "'vardecl' syntax error (no vardecl?) in %s, line %d.\n",	     filename, lineno );    return 0;  }  ptr += 7;  if (!isspace(*ptr)) {    /* no space following vardecl */    fprintf( stderr, "'vardecl' syntax error (no space?) in %s, line %d.\n",	     filename, lineno );    return 0;  }  /* skip to the good stuff */  while (isspace(*ptr)) ptr++;  typeEnd1 = typeEnd2 = 0;  typeStart = ptr;  readingIdent = 0;  while (*ptr!=0 && *ptr!=',') {    if (readingIdent && !(isalnum(*ptr) || *ptr=='_')) {      /* if end of an identifier */      typeEnd2 = typeEnd1;      typeEnd1 = ptr;    }    readingIdent =  (isalnum(*ptr) || *ptr=='_');    ptr++;  }  if (readingIdent) {    typeEnd2 = typeEnd1;    typeEnd1 = ptr;  }  if (!typeEnd2) {    fprintf( stderr, "(%d)No variable names found in vardecl in %s, line %d.\n",	     __LINE__, filename, lineno );    return 0;  }  STR_RANGE_DUP( *basetype, typeStart, typeEnd2 );  *end = typeEnd2;#if DEBUG  fprintf( stderr, "ReadVardeclBasetype: '%s'\n", *basetype );#endif  return 1;}  int ReadVardeclVarname( readPt, varPrefix,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -