📄 driver.c
字号:
replace a pointer ref with an integer. */strcpy( rt->name, p );rt->num_stars = 0;*is_function = strcmp( p, "void" );reading_function_type = 1; /* !*is_function; */p += strlen( p );*p++ = ' ';leadingm = 0; /* If a newline is encountered before this is one, AND this is a macro, insert one and exit */found_name = 0;while (1) { c = FindNextANToken( fin, p, &nsp ); if (c == EOF) { fprintf( stderr, "Unexpected EOF in %s\n", filename ); return; } if (reading_function_type) { if (nsp > 0) strcat( rt->name, " " ); if (strcmp( p, name ) != 0 && p[0] != '(') strcat( rt->name, p ); if (c == '*') { *is_function = 1; rt->num_stars++; } } if (flag && c == '\n' && leadingm == 0) { break; } if (c == '\n') leadingm = 1; if (c == '(') { reading_function_type = 0; in_args += 1; } if (c == ')') { in_args -= 1; if (in_args == 0) { break; } } if (in_args == 0) { if (strcmp( p, name ) == 0) { /* Convert to Fortran name. For now, this just does the lowercase_ version */ found_name = 1; } else { if (p[0] != '*') fprintf( stderr, "%s:Did not find matching name: %s != %s\n", filename, p, name ); } } if (in_args == 1) { if (c != ',' && c != '(' && c != '\n') { /* Assume that it is a name and remember it */ args[nargs].name = p; args[nargs].has_star = 0; args[nargs].implied_star = 0; args[nargs].is_char = 0; args[nargs].is_FILE = 0; args[nargs].is_native = 1; /* Unspecified args are ints */ args[nargs].type = 0; nargs++; } } if (in_args) { p += strlen( p ); *p++ = 0; } }if (!found_name) { fprintf( stderr, "%s:Did not find routine name (may be untyped): %s \n", filename, name ); }/* Handle definitions of the form "type (*Name( args, ... ))()" (this is function returns pointer to function returning type). */SkipWhite( fin );c = getc( fin );if (c == '(') { SkipWhite( fin ); c = getc(fin); if (c == ')') fputs( "()", fout ); else ungetc( (char)c, fin ); }else ungetc( (char)c, fin );*Nargs = nargs;}/* if flag == 1, stop on empty line rather than { *//* This needs to distinguish between pointers and values, since all parameters are passed by reference in Fortran. Just to keep things lively, there are two ways to indicate a pointer in C: type *foo; type foo[]; Needed to add a change that definitions are terminated by ;, not by \n. */int ProcessArgDefs( fin, fout, args, nargs, types, Ntypes, Nstrings, flag, name, flag2 )FILE *fin, *fout;ARG_LIST *args;int nargs;TYPE_LIST *types;int *Ntypes, *Nstrings, flag, flag2;char *name;{int c;char token[1024], *p;int i, nsp, bl, newline, newstmt;char rcall[1024];int is_function, in_function;int ln, in_args, has_star, implied_star, n_strings, is_char, nstrings, is_native, has_array, is_FILE;int ntypes, set_void, void_function;int done = 0; /* set to 1 if ate end-of-definition */int type_has_star;newline = 1;newstmt = 1;if (flag) newline = 0;has_star = 0;type_has_star = 0;implied_star = 0;has_array = 0;is_char = 0;is_FILE = 0;nstrings = 0;/* The default type is int */ntypes = 1;strcpy( types[0].type, "int" );is_function = 0;in_function = 0;set_void = 0;void_function = 0;while (1) { c = FindNextANToken( fin, token, &nsp ); if (c == EOF || token[0] == '{') break; /* Check for empty line; if found, exit. Otherwise, check for M * / (Macro definition) and handle that case */ if (flag) { if (newline && c == '\n') break; if (c == MACRO) { c = getc( fin ); if (c == '*') { c = getc( fin ); if (c == '/') { done = 1; break; } else { /* This won't work on all systems. */ ungetc( '*', fin ); ungetc( (char)c, fin ); } } else ungetc( (char)c, fin ); } } /* Don't output register */ if (strcmp( token, "register" ) == 0) continue; /* Handle various argument features */ if (c == '*') has_star++; else if (c == ',') { has_star = type_has_star; has_array = 0; in_function = 0; is_function = 0; set_void = 0; void_function = 0; /* implied_star = 0; */ } else if (c == ';') { is_char = 0; is_FILE = 0; has_star = 0; implied_star = 0; has_array= 0; is_native= 0; is_function = 0; in_function = 0; set_void = 0; void_function = 0; type_has_star = 0; newstmt = 1; } else if (c == '(') { in_function = 1; /* If set_void is activated, set the void function indicator */ if (set_void) { set_void = 0; void_function = 1; } } else if (c == ')' && in_function) { is_function = 1; } else if (c == '\n') { /* New lines have little meaning in declarations. However, they are necessary to handle blanks lines */ newline = 1; }#ifdef OLD_CODE else if (c == '\n') { newline = 1; is_char = 0; is_FILE = 0; has_star = 0; has_array= 0; is_native= 0; is_function = 0; implied_star = 0; in_function = 0; set_void = 0; void_function = 0; }#endif else if (newstmt) { if (strcmp( token, "char" ) == 0) is_char = 1; if (strcmp( token, "FILE" ) == 0) is_FILE = 1; is_native = 0; if (strcmp( token, "double" ) == 0 || strcmp( token, "int" ) == 0 || strcmp( token, "float" ) == 0 || strcmp( token, "char" ) == 0 || strcmp( token, "complex") == 0 || strcmp( token, "dcomplex")== 0 || strcmp( token, "MPI_Status") == 0 || strcmp( token, "BCArrayPart") == 0) is_native = 1; if (isMPI) { /* Some things need to be considered ints in the declarations. That is, these are "implicit" pointer objects; often they are pointers to be returned from the calling routine. These tests set these up as being pointer objects */ if (strcmp( token, "MPI_Comm" ) == 0 || strcmp( token, "MPI_Request" ) == 0 || strcmp( token, "MPI_Group" ) == 0 || strcmp( token, "MPI_Intercomm_request" ) == 0 || strcmp( token, "MPI_Op" ) == 0 || strcmp( token, "MPI_Datatype" ) == 0) { has_star = 1; type_has_star = 1; implied_star = 1; } } if (strcmp( token, "void" ) == 0) { /* Activate set_void only for the files specified by flag2 */ if (!flag2) is_native = 1; else set_void = 1; } newline = 0; newstmt = 0; strcpy( types[ntypes].type, token ); if (strcmp( token, "struct" ) == 0 || strcmp( token, "unsigned") == 0) { /* Flush struct to the output */ for (i=0; i<nsp; i++) putc( ' ', fout ); fputs( token, fout ); c = FindNextANToken( fin, token, &nsp ); strcat( types[ntypes].type, " " ); strcat( types[ntypes].type, token ); } ntypes++; } else in_function = 0; /* Check for "[]". This won't work for [][3], for example */ c = getc( fin ); if (c == '[') { has_star++; while ((c = getc(fin)) != EOF && c != ']') ; has_array = 1; } else ungetc( c, fin ); /* Look up name */ for (i=0; i<nargs; i++) { if (strcmp( token, args[i].name ) == 0) { args[i].has_star = has_star; args[i].implied_star = implied_star; args[i].is_char = is_char; args[i].is_FILE = is_FILE; args[i].type = ntypes-1; args[i].is_native = is_native; args[i].void_function = void_function; break; } } }*Ntypes = ntypes;*Nstrings = nstrings;return done;}PrintBody( fout, is_function, name, nstrings, nargs, args, types, rt, prefix )FILE *fout;char *name, *prefix;int is_function, nstrings, nargs;ARG_LIST *args;TYPE_LIST *types;RETURN_TYPE *rt;{int i;fprintf( fout, "Start of function\n" );fprintf( fout, "%s %s( ", rt->name, name ); /* return type and function name */if (nargs) { fprintf( fout, "%s", args[0].name );}for (i=1; i<nargs; i++) { fprintf( fout, ", %s", args[i].name ); /* argument names */}fprintf( fout, " )\n" );for (i=0; i<nargs; i++) { fprintf( fout, "%s%s %s;\n", /* argument definitions */ types[args[i].type].type, args[i].has_star ? " *" : "", args[i].name);}fprintf( fout, "{\n" );fprintf( fout, " %s returnVal;\n\n", rt->name ); /* declare returnVal */fprintf( fout, " returnVal = %s%s( ", prefix, name ); /* start function call */if (nargs) { fprintf( fout, "%s", args[0].name );}for (i=1; i<nargs; i++) { fprintf( fout, ", %s", args[i].name ); /* function arguments */}fprintf( fout, " );\n\n" );fprintf( fout, " return returnVal;\n" ); /* return returnVal */fprintf( fout, "}\n\n" ); /* close the function definition */fprintf( fout, "End of function\n" );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -