FuncInfo * unknown_user_FuncInfo(char * funcstr) { FuncInfo * fi; fi = FuncInfo_from_str("Unknown user-defined function"); if( reconcile_FuncInfo_with_funcstr(fi,funcstr) == FALSE ) { warn("Could not reconcile [%s]... bad internal error.",funcstr); } return fi; }
ModuleFunctionList * parse_function_section(FILE * input,DYNFILE * dfp,FailureType * ft,boolean addnumbers) { ModuleFunctionList * out; boolean outoffunction=TRUE; char * name; boolean next_line_alloc = FALSE; boolean next_line_free = FALSE; char buffer[MAXLINE]; char * tempb; ModuleFunction * mf; FuncInfo * fi = NULL; out = ModuleFunctionList_alloc_std(); while( get_watched_line(buffer,MAXLINE,input) != NULL) { chop_newline(buffer); if( strstartcmp(buffer,"%}") == 0) break; if( strstartcmp(buffer,"%func") == 0 ) { /* fprintf(stderr,"Getting info line!\n"); */ fi = read_FuncInfo_line(buffer,input); fi->is_hand_written = TRUE; if( fi == NULL ) { warn("Unable to read function info line at %s. Probably going to give a parse error",buffer); } else add_DYNFILE(dfp,fi); continue; } if( outoffunction == TRUE ) { if( buffer[0] == '{' ) { outoffunction = FALSE; fputs_func_DYNFILE(buffer,dfp); continue; } /* fprintf(stderr,"Got here [%s]\n",buffer); */ if( buffer[0] == '\0' || isspace(buffer[0]) || strstartcmp(buffer,"static") == 0 || buffer[0] == '#' || buffer[0] == '/' || buffer[0] == '*' ) { next_line_alloc = next_line_free = FALSE; fputs_func_DYNFILE(buffer,dfp); continue; } /*** if the line starts with a ! we want to interpret it ***/ /*** as a dynamite specific tag ***/ if( strstartcmp(buffer,"!constructor") == 0 ) { next_line_alloc = TRUE; continue; } if( strstartcmp(buffer,"!deconstructor") == 0 ) { next_line_free = TRUE; continue; } if ( buffer[0] == '!' ) { next_line_alloc = next_line_free = FALSE; continue; } /*fprintf(stderr,"Got here again [%s]\n",buffer);*/ /*** ok this should be a function! ****/ if( next_line_alloc == TRUE || next_line_free == TRUE ) { tempb = stringalloc(buffer); name = parse_and_get_module_name_from_func(tempb,next_line_alloc); if(name == NULL) { warn("Function [%s] specified as cons/decons, but no module name parsed...",buffer); } else { if( (mf=get_ModuleFunction_from_name(out,name)) == NULL ) mf = new_ModuleFunction(out,name); if( next_line_alloc == TRUE ) { if( mf->has_cons == TRUE ) warn("Module %s already has a constructor... double overload!",name); else mf->has_cons = TRUE; } else { if( mf->has_decons == TRUE ) warn("Module %s already has a deconstructor... double overload",name); else mf->has_decons = TRUE; } ckfree(name); } ckfree(tempb); } /*** end of if cons/decons ***/ next_line_alloc = next_line_free = FALSE; /*** reconcile with fi if any ***/ if( fi != NULL ) { reconcile_FuncInfo_with_funcstr(fi,buffer); dfp->funcpos += show_eddystyle_FuncInfo(fi,dfp->func); /** already added to DYNFILE **/ } else { /* fprintf(stderr,"Using [%s] as an unknown function\n",buffer); */ fi = unknown_user_FuncInfo(buffer); /* fprintf(stderr,"Unknown function %s...\n",fi->name);*/ add_DYNFILE(dfp,fi); } /*** put #line compiler information ***/ /*** using global parsed file which is also used for errors... sort of yukky. ***/ if( addnumbers == TRUE) { fprintf(dfp->func,"# line %d \"%s\"\n",get_watched_linecount(),parsed_file); dfp->funcpos++; } /*** put line ***/ fi->line_in_c = dfp->funcpos; fi = NULL; fputs_func_DYNFILE(buffer,dfp); /*** put away function now ***/ /*** header information will be put away in dfp call ***/ } else { /*** actually inside a function ***/ if( buffer[0] == '}' ) outoffunction = TRUE; fputs_func_DYNFILE(buffer,dfp); } } return out; }