#include "semcheck.h" /***************************************************************** ** File Name : UNIQUE_LABELS.c ** ** ** ** The names of parts are unique ** *****************************************************************/ #include char * tolowercase(char* partname) { char *result = new char[strlen(partname)+1]; strcpy(result,partname); int loop = 0; while (result[loop]) { char c = result[loop]; if (((c>='0')&&(c<='9'))||((c>='a')&&(c<='z')) || (c=='_')) { loop++; continue; } else if ((c>='A')&&(c<='Z')) result[loop] = (char) tolower(result[loop]); else { cerr << toolname << ": error: illegal identifier : " << partname << "." << endl; } loop++; } result[loop]='\0'; return (result); } Cd_graph* Cd_graph::UNIQUE_LABELS(int &thisresult) { Cd_graph *new_cd = new Cd_graph(); thisresult = adjacencies->UNIQUE_LABELS(new_cd); new_cd->rset_terminal_sets(terminal_sets); new_cd->rset_foreign_classes(foreign_classes); return (new_cd); } int Adjacency_Nlist::UNIQUE_LABELS(Cd_graph *new_cd) { int result = SUCCESS; new_cd->rset_adjacencies(this); Adjacency_list_iterator next_Adjacency(*this); Adjacency_ each_Adjacency; while (each_Adjacency=next_Adjacency()) if (each_Adjacency->UNIQUE_LABELS()!=SUCCESS) result = ERROR_UNIQUE_LB; return result; } int Adjacency::UNIQUE_LABELS() { this->rset_treated(NULL); this->rset_imm_ancester(NULL); this->rset_inherited_Any_vertex(NULL); this->rset_expanded_common_parts(NULL); return ns->UNIQUE_LABELS(this); } int Neighbors::UNIQUE_LABELS(Adjacency *adj) { return SUCCESS; } int Construct_ns::UNIQUE_LABELS(Adjacency *adj) { int result; this->rset_construct_ns( this->get_construct_ns()->UNIQUE_LABELS(adj,result)); return result; } int Alternat_ns::UNIQUE_LABELS(Adjacency *adj) { this->rset_construct_ns(new Any_vertex_List()); return SUCCESS; } int Any_vertex::IsTerm() { return (1); // for Opt_labeled_term | Optional_term } int Syntax_vertex::IsTerm() { return (0); } int Inherit_term::IsTerm() { sem_out << "Warning : meet int Inherit_term::IsTerm()!" << endl; return (0); } Any_vertex_List *Any_vertex_List::UNIQUE_LABELS(Adjacency *adj,int& result) { Any_vertex_List *new_list = new Any_vertex_List(); result = SUCCESS; int position = 0; Any_vertex_list_iterator next_vertex(*this); Any_vertex_ each_vertex; while (each_vertex = next_vertex()) { if (each_vertex-> UNIQUE_LABELS(this,position,adj,new_list)!=SUCCESS) result = ERROR_UNIQUE_LB; position++; } Any_vertex_list_iterator next_vertex2(*new_list); Any_vertex_ each_vertex2; while (each_vertex2 = next_vertex2()) { each_vertex2->rset_origin(NULL); } return (new_list); } int Any_vertex::UNIQUE_LABELS(Any_vertex_List *alist,int position,Adjacency *adj,Any_vertex_List *new_list) { Any_vertex *anyvertex; int result = 1; int loop = 0; while (loopget_data_member(loop); loop++; if (((char*)anyvertex)==((char*)this)) return SUCCESS; if (this->IsTerm() && anyvertex->IsTerm() && (strcmp(this->UNIQUE_LABELS_partname(), anyvertex->UNIQUE_LABELS_partname())==0)) { this->PRINT_UNIQUE_ERROR(anyvertex,adj); cerr << "" << endl; new_list->append(this); return ERROR_UNIQUE_LB; } } new_list->append(this); return SUCCESS; } char *Any_vertex::UNIQUE_LABELS_partname() { cout << "\ncan not reach char *Any_vertex::UNIQUE_LABELS_partname()" << endl; return NULL; } char *Regular::UNIQUE_LABELS_partname() { return this->get_vertex()->UNIQUE_LABELS_partname(); } char *Labeled::UNIQUE_LABELS_partname() { return tolowercase(this->get_label_name()->get_val()); } char *Term::UNIQUE_LABELS_partname() { /*extern int strlen(const char*);*/ Term *aterm; char *partname = new char[200]; Term_Comma_list *act_pars = this->get_actual_parameters(); if (act_pars) { int list_len = act_pars->number_of_parts(); while (list_len--) { aterm = (Term *)act_pars->get_data_member(list_len); if (list_len==1) sprintf(partname,"%s%s_",partname,aterm->UNIQUE_LABELS_partname()); else sprintf(partname,"%s%s__",partname,aterm->UNIQUE_LABELS_partname()); } } sprintf(partname,"%s%s",partname, tolowercase(this->get_vertex()->get_vertex_name()->get_val())); return (partname); } /* Optional_term = "[" < opt > Opt_labeled_term_Sandwich "]" . */ char *Optional_term::UNIQUE_LABELS_partname() { return opt->UNIQUE_LABELS_partname(); } char *Opt_labeled_term_Sandwich::UNIQUE_LABELS_partname() { return inner->UNIQUE_LABELS_partname(); } void Any_vertex::PRINT_UNIQUE_ERROR(Any_vertex *anyvertex,Adjacency *adj) { cerr << toolname << ": error: near line " << adj->get_source()->get_vertex_name()->get_line_number() << " find nonunique parts: of "; adj->PRINT_UNIQUE_ERROR(cerr); cerr << endl; Adjacency *orig1 = this->get_origin(); Adjacency *orig2 = anyvertex->get_origin(); this->rset_origin(NULL); anyvertex->rset_origin(NULL); cerr << " "; this->pp(cerr); cerr << " from "; if (orig1==NULL) adj->get_source()->pp(cerr); else orig1->get_source()->pp(cerr); cerr << endl; cerr << " "; anyvertex->pp(cerr); cerr << " from "; if (orig2==NULL) adj->get_source()->pp(cerr); else orig2->get_source()->pp(cerr); cerr << endl; this->rset_origin(orig1); anyvertex->rset_origin(orig2); } void Adjacency::PRINT_UNIQUE_ERROR(ostream& strm) { source->pp(strm); if (parameters) parameters->pp(strm); ns->PRINT_UNIQUE_ERROR(strm); } void Neighbors::PRINT_UNIQUE_ERROR(ostream& strm) { } void Neighbors_wc::PRINT_UNIQUE_ERROR(ostream& strm) { this->get_construct_ns()->PRINT_UNIQUE_ERROR(strm); } void Repetit_n::PRINT_UNIQUE_ERROR(ostream& strm) { this->pp(strm); } void Construct_ns::PRINT_UNIQUE_ERROR(ostream& strm) { strm << "="; this->Neighbors_wc::PRINT_UNIQUE_ERROR(strm); } void Alternat_ns::PRINT_UNIQUE_ERROR(ostream& strm) { strm << ":"; alternat_ns -> pp( strm ); if ( common ) { common -> pp( strm ); } Neighbors_wc::PRINT_UNIQUE_ERROR( strm ); } void Any_vertex_List::PRINT_UNIQUE_ERROR(ostream& strm) { Any_vertex_list_iterator next(*this); Any_vertex_ each; while (each = next()) { Adjacency *orig = each->get_origin(); each->rset_origin(NULL); each->pp(strm); each->rset_origin(orig); } }