*operation* void inject_local_pps(char *inst_env_path,char *default_pps_path) *wrapper* Instantiation *prefix* (@ assert( (inst_env_path != NULL) && (default_pps_path != NULL) ); char * u_1_path = new char[strlen(inst_env_path)+10]; sprintf(u_1_path,"%s",inst_env_path); char *inst_name; inst_name = inst_env_path + strlen(inst_env_path) - 1; while (*inst_name != '/') inst_name --; inst_name ++; pps->inject_local_pps(u_1_path,inst_name,default_pps_path); char *tmp = tempnam(tmpdir,"inst.meta"); ofstream inst_meta( tmp ); if (!inst_meta) { cerr << toolname << ": unable to open " << tmp << " for output." << endl; exit(1); } if (meta_def) { meta_def->g_print(inst_meta); inst_meta << "\n\n"; } inst_meta.close(); char *tfile = new char[MAXDIRLEN+1]; sprintf(tfile,"%s/inst.meta",u_1_path); mv_if_change(mv_interactive,tmp,tfile); delete tmp; delete tfile; delete u_1_path; @) *operation* void inject_local_pps (char *u_1_path,char *inst_name,char *default_pps_path) *wrapper* Pps *prefix* (@ if (pps->list_length() == 0) return; /* insert the default path for search pps */ if (pp_paths == NULL) pp_paths = new Search_path_Nlist(); char *default_path = new char[strlen(default_pps_path)+1]; strcpy(default_path,default_pps_path); DemString * s = new DemString(default_path); Search_path * p = new Search_path(); p->set_search_path(s); pp_paths->insert(p); pps->inject_local_pps(u_1_path,inst_name,pp_paths); @) *operation* void inject_local_pps(char *u_1_path,char *inst_name, Search_path_Nlist *pp_path) *wrapper* Propagation_pattern_List *prefix* (@ int file_count = 1; Propagation_pattern_list_iterator next(*this); Propagation_pattern * each; while (each = next()) { each->inject_local_pps(u_1_path,inst_name,pp_path,file_count); file_count++; } @) *operation* void inject_local_pps(char *u_1_path,char *inst_name, Search_path_Nlist *pp_path,int file_count) *wrapper* Propagation_pattern *prefix* (@ impl_or_loc->inject_local_pps(u_1_path,inst_name,pp_path,file_count, header,rename,meta_def); @) *operation* void inject_local_pps(char *u_1_path,char *inst_name, Search_path_Nlist *pp_path,int file_count,Header *header, Rename *rename,Meta_def *meta_def) *traverse* *from* Impl_or_loc *to* { Pp_location, Implementation } *wrapper* Implementation (@ char *tmp; char *targetfile; char * oname; char *p; if (rename) derror('e',1,"renaming is not allowed with known implementation."); targetfile = ppfname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); cout << toolname << ": generating " << targetfile << " for "; header->g_print(cout); cout << " ... " << endl; ofstream tfile(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } Propagation_pattern * tmp_pp = new Propagation_pattern(); tmp_pp->set_header(header); tmp_pp->set_impl_or_loc(this); tmp_pp->g_print(tfile); tfile << "\n"; tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); targetfile = metafname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } if (meta_def) { meta_def->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); @) *wrapper* Pp_location *prefix* (@ struct stat buf; Propagation_pattern * prop; char ppfile[MAXDIRLEN+1]; char org_n[MAXDIRLEN+1]; char *tmp,*targetfile; pp_file->fetch_fname(ppfile); strcpy(org_n,ppfile); if (*ppfile != '/') { cout << toolname << ": searching " << org_n << " for "; header->g_print(cout); cout << " ... " << endl; pp_path->search_file(ppfile); if (ppfile[0] == '\0') { cerr << toolname << ": error: unable to find " << org_n << endl; exit(1); } } else { if (lstat(ppfile,&buf) && (access(ppfile, R_OK) != 0)) { cerr << toolname << ": error: unable to open " << ppfile << " for input." << endl; exit(1); } } cout << toolname << ": reading " << ppfile << " ... " << endl; Propagation_patterns *pps = new Propagation_patterns(); pps = (Propagation_patterns *) pps->g_parse(ppfile); if (pps == NULL) derror('e',1," failed to parse the propagation pattern file.\n"); Propagation_pattern_List * props = pps->get_pps(); targetfile = cppfname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); ofstream tfile(tmp); if (pps->get_text() != NULL) tfile << "\n" << pps->get_text()->get_code()->get_val() << "\n\n"; else tfile << "\n"; tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); /* find the propagation pattern */ Propagation_pattern_list_iterator next_p(*props); Propagation_pattern * each_p; prop = NULL; while (each_p = next_p()) if (each_p->get_header()->get_signature()->g_equal(header->get_signature())) { prop = each_p; break; } if (prop == NULL) derror('e',1," unable to find this operation.\n"); /* prop coannot contain another file name */ prop->no_filename(ppfile,header); if (prop->get_rename()) derror('e',1,"renaming is not allowed with known implementation."); targetfile = renfname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } if (rename) { rename->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); targetfile = metafname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } if (prop->get_meta_def()) { prop->get_meta_def()->g_print(tfile); tfile << "\n"; } if (meta_def) { meta_def->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); targetfile = ppfname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); cout << toolname << ": generating " << targetfile << " for "; header->g_print(cout); cout << " ... " << endl; tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } /* print the pp */ prop->set_meta_def(NULL); prop->g_print(tfile); tfile << "\n"; tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(tmp); delete props; @) *operation* void search_file(char *ppfile) *wrapper* Search_path_Nlist *prefix* (@ char tmp[MAXDIRLEN+1]; struct stat buf; Search_path_list_iterator next(*this); Search_path * each; assert( ppfile != NULL ); while (each = next()) { each->fetch_fname(tmp); sprintf(tmp,"%s/%s",tmp,ppfile); if (lstat(tmp,&buf)) { if (errno == ENOENT) continue; else { cerr << toolname << ": error: unable to open " << tmp << " for input." << endl; perror(tmp); ppfile[0] = '\0'; return; } } else if (access(tmp, R_OK) != 0) { cerr << toolname << ": error: unable to open " << tmp << " for input." << endl; ppfile[0] = '\0'; return; } else { strcpy(ppfile,tmp); return; } } ppfile[0] = '\0'; @) *operation* void fetch_fname(char* fname) *wrapper* Search_path *prefix* (@ strcpy(fname,search_path->get_val()); @) *wrapper* File_name *prefix* (@ strcpy(fname,name->get_val()); @) *operation* void fetch_op_name(char *&oname) *traverse* *from* Header *to* Op_name *wrapper* Op_name *prefix* (@ oname = op_name->get_val(); @) *operation* void no_filename(char *ppfile,Header *header) *traverse* *from* Propagation_pattern *to* Pp_location *wrapper* Pp_location *prefix* (@ cerr << toolname << ": in file " << ppfile << ": "; header->g_print(cerr); cerr << ": cannot use file name to refer to a propagation pattern.\n" << endl; exit(1); @)