// Check that each class is defined at least once. *operation* int check_classes() *init* (@ 1 @) *traverse* *from* Cd_graph *through* ->Term,vertex,* *to* Vertex *carry* *in* Cd_graph* graph = (@ this @) *along* *from* Cd_graph *to* Vertex *carry* *in* Vertex_Comma_list* params = (@ this->get_parameters() @) *along* *from* Adjacency *to* Vertex *wrapper* Cd_graph *prefix* (@ cout << endl << "Checking that every class is defined exactly once ..." << endl; @) *wrapper* Adjacency *prefix* (@ if (graph->check_classes1(this->get_source()) > 1) return_val = 0; @) *wrapper* Vertex *prefix* (@ if ((strcmp(this->get_vertex_name()->get_val(), "DemIdent") != 0) && (strcmp(this->get_vertex_name()->get_val(), "DemReal") != 0) && (strcmp(this->get_vertex_name()->get_val(), "DemNumber") != 0) && (strcmp(this->get_vertex_name()->get_val(), "DemString") != 0) && (strcmp(this->get_vertex_name()->get_val(), "DemText") != 0)) { if (graph->find_adjacency(this) == NULL) { if ((params == NULL) || (!params->check_classes2(this))) { return_val = 0; cout << "sem-check: error: undefined class: '"; this->g_print(); cout << "' on line " << this->get_vertex_name()->get_line_number() << endl; } } } @) // Check if class is defined more than once. *operation* int check_classes1(Vertex *v) *init* (@ 0 @) *traverse* *from* Cd_graph *through* ->Adjacency,source,* *to* Vertex *wrapper* Vertex *prefix* (@ if(this->g_equal(v)) { return_val++; if ((return_val > 1) && (this->get_vertex_name()->get_line_number() > v->get_vertex_name()->get_line_number())) { cout << "sem-check: error: class '"; v->g_print(); cout << "' on line " << this->get_vertex_name()->get_line_number() << " is redefined." << endl; } } @) // Check if class is defined as a parameter *operation* int check_classes2(Vertex* v) *init* (@ 0 @) *traverse* *from* Vertex_Comma_list *to* Vertex *wrapper* Vertex *prefix* (@ if (this->g_equal(v)) return_val = 1; @)