*operation* void inject_components(char *inst_path,char *default_path, Search_path_Nlist*comp_names) *wrapper* Instantiation *prefix* (@ comps->inject_components(inst_path,default_path,comp_names); @) *operation* void inject_components(char *inst_path,char *default_path, Search_path_Nlist*comp_names) *wrapper* Comps *prefix* (@ if (comp_paths == NULL) comp_paths = new Search_path_Nlist(); char *default_comp_path = new char[strlen(default_path)+1]; strcpy(default_comp_path,default_path); DemString * s = new DemString(default_comp_path); Search_path * p = new Search_path(); p->set_search_path(s); comp_paths->insert(p); components->inject_components(inst_path,default_path,comp_paths,comp_names); @) *operation* void inject_components (char *inst_path,char *default_path,Search_path_Nlist *comp_paths, Search_path_Nlist*comp_names) *traverse* *from* Component_inst_List *to-stop* Component_inst *wrapper* Component_inst *prefix* (@ component->inject_components(inst_path,default_path,comp_paths,rename,meta_def,comp_names); @) *operation* void inject_components(char *inst_path,char *default_path, Search_path_Nlist *comp_paths, Rename * comp_ren, Meta_def * comp_meta, Search_path_Nlist*comp_names) *traverse* *from* Component_location *to-stop* { Component_name, Component_file } *wrapper* Component_name *prefix* (@ char cn[MAXDIRLEN+1]; char cpath[MAXDIRLEN+1]; char org_n[MAXDIRLEN+1]; Search_path * cname_obj = new Search_path(); char * cname = new char[strlen(name->get_val())+1]; cout << "\n\n"; strcpy(cname,name->get_val()); cname_obj->set_search_path(new DemString(cname)); comp_names->append(cname_obj); strcpy(cpath,name->get_val()); cout << toolname << ": searching component " << cpath << " ... " << endl; comp_paths->search_path(cpath); if (cpath[0] == '\0') { cerr << toolname << ": error: unable to find component" << name->get_val() << endl; exit(1); } sprintf(cn,"%s/%s%s",cpath,name->get_val(),comp_suffix); cout << toolname << ": parsing component file " << cn << " ... " << endl; Component * comp = new Component(); comp = (Component *)comp->g_parse(cn); if (comp == NULL) derror('e',1," failed to parse the component file.\n"); cout << toolname << ": successfully parsed component file " << cn << "." << endl; comp->inject_comp(inst_path,cpath,comp_meta,comp_ren); delete comp; @) *wrapper* Component_file *prefix* (@ char fn[MAXDIRLEN+1]; char org_n[MAXDIRLEN+1]; location->fetch_fname(fn); strcpy(org_n,fn); cout << "\n\n"; if (*fn != '/') { cout << toolname << ": searching component file " << org_n << " ... " << endl; comp_paths->search_file(fn); if (fn[0] == '\0') { cerr << toolname << ": error: unable to find " << org_n << endl; exit(1); } } cout << toolname << ": parsing component file " << fn << " ... " << endl; Component * comp = new Component(); comp = (Component *)comp->g_parse(fn); if (comp == NULL) derror('e',1," failed to parse the component file.\n"); cout << toolname << ": successfully parsed component file " << fn << "." << endl; Search_path * cname_obj = new Search_path(); char * cname = new char[strlen(comp->get_name()->get_name()->get_val())+1]; strcpy(cname,comp->get_name()->get_name()->get_val()); cname_obj->set_search_path(new DemString(cname)); comp_names->append(cname_obj); char *p; p = fn + strlen(fn)-1; while (*p != '/') p--; *p = '\0'; comp->inject_comp(inst_path,fn,comp_meta,comp_ren); delete comp; @) *operation* void inject_comp(char *inst_path,char *comp_path, Meta_def *comp_meta, Rename *comp_ren) *wrapper* Component *prefix* (@ char *tfile; char *compname = name->get_name()->get_val(); char *compdir = new char[strlen(inst_path)+strlen(compname)+10]; sprintf(compdir,"%s/%s",inst_path,compname); if (mkdir(compdir,0755)) { if (errno != EEXIST) { cerr << toolname << ": unable to create directory " << compdir << endl; exit(1); } } else cout << toolname << ": " << compdir << " created." << endl; char *tmp = tempnam(tmpdir,compname); ofstream comp_h( tmp ); if (!comp_h) { cerr << toolname << ": unable to open " << tmp << " for output." << endl; exit(1); } if (declared) { comp_h << "#include \"interface.h\"\n"; comp_h << declared->get_code()->get_val() << "\n\n"; } comp_h.close(); tfile = new char[MAXDIRLEN+1]; sprintf(tfile,"%s/%s.h",compdir,compname); mv_if_change(mv_interactive,tmp,tfile); delete tmp; tmp = tempnam(tmpdir,compname); ofstream comp_c( tmp ); if (!comp_c) { cerr << toolname << ": unable to open " << tmp << " for output." << endl; exit(1); } if (defined) { comp_c << "#include \"interface.h\"\n"; comp_c << defined->get_code()->get_val() << "\n\n"; } comp_c.close(); sprintf(tfile,"%s/%s.C",compdir,compname); mv_if_change(mv_interactive,tmp,tfile); delete tmp; delete tfile; tmp = tempnam(tmpdir,"comp_inst.meta"); ofstream inst_meta( tmp ); if (!inst_meta) { cerr << toolname << ": unable to open " << tmp << " for output." << endl; exit(1); } if (this->get_meta_def()) { this->get_meta_def()->g_print(inst_meta); inst_meta << "\n"; } if (comp_meta) { comp_meta->g_print(inst_meta); inst_meta << "\n\n"; } inst_meta.close(); tfile = new char[MAXDIRLEN+1]; sprintf(tfile,"%s/comp_inst.meta",compdir); mv_if_change(mv_interactive,tmp,tfile); delete tmp; delete tfile; tmp = tempnam(tmpdir,"comp_inst.ren"); ofstream inst_ren( tmp ); if (!inst_ren) { cerr << toolname << ": unable to open " << tmp << " for output." << endl; exit(1); } if (comp_ren) { comp_ren->g_print(inst_ren); inst_ren << "\n\n"; } inst_ren.close(); tfile = new char[MAXDIRLEN+1]; sprintf(tfile,"%s/comp_inst.ren",compdir); mv_if_change(mv_interactive,tmp,tfile); delete tmp; delete tfile; int file_count = 1; provides->inject_comp(compdir,compname,comp_path,file_count); delete compdir; @) *operation* void inject_comp(char *compdir,char *compname,char *comp_path,int& file_count) *traverse* *from* Provided_asset *to* Propagation_pattern *wrapper* Propagation_pattern *prefix* (@ impl_or_loc->inject_comp(compdir,compname,comp_path,file_count,meta_def,rename,header); file_count++; @) *operation* void inject_comp(char *compdir,char *compname,char *comp_path, int file_count, Meta_def *meta, Rename *ren, Header *header) *traverse* *from* Impl_or_loc *to* { Pp_location, Implementation } *wrapper* Implementation *prefix* (@ char *tmp; char *targetfile; /* get target and temporary file names */ targetfile = ppfname(compdir,compname,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(compdir,compname,header,file_count); tmp = tmpfname(); tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } if (meta) { meta->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); if (ren) derror('e',1,"renaming is not allowed with known implementation."); @) *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(org_n); if (*org_n != '/') sprintf(ppfile,"%s/%s",comp_path,org_n); else strcpy(ppfile,org_n); cout << toolname << ": searching " << ppfile << " for "; header->g_print(cout); cout << " ... " << endl; 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(compdir,compname,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"); if (prop->get_rename()) derror('e',1,"renaming is not allowed with known implementation."); /* prop coannot contain another file name */ prop->no_filename(ppfile,header); targetfile = renfname(compdir,compname,header,file_count); tmp = tmpfname(); tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } if (ren) { ren->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); targetfile = metafname(compdir,compname,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) { meta->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); targetfile = ppfname(compdir,compname,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_path(char *fpath) *wrapper* Search_path_Nlist *prefix* (@ char tmp[MAXDIRLEN+1]; struct stat buf; Search_path_list_iterator next(*this); Search_path * each; assert( fpath != NULL ); while (each = next()) { each->fetch_fname(tmp); sprintf(tmp,"%s/%s",tmp,fpath); if (lstat(tmp,&buf)) { if (errno == ENOENT) continue; else { cerr << toolname << ": error: unable to open " << tmp << endl; perror(tmp); fpath[0] = '\0'; return; } } else if (access(tmp, X_OK | R_OK) != 0) { cerr << toolname << ": error: unable to open " << tmp << endl; fpath[0] = '\0'; return; } else { strcpy(fpath,tmp); return; } } fpath[0] = '\0'; @)