/*************************************************************************** classdecl.cpp - description ------------------- begin : Thu Mar 20 20:48:22 2003 copyright : (C) 2002 by Cavalli Andrea email : cavalli@bioc.unizh.ch **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include ClassDecl::~ClassDecl(){ delete identifier; delete parents; delete attribute_list; delete methods; } ZObj * ClassDecl::eval(){ //exec_line done exec_line = line; string name = identifier->val; map::iterator iter = SYMBOLTABLE.find(name); if(iter!=SYMBOLTABLE.end()){ throw ZError(line,"Re-definition of class: "+name); } ZClass * cl = new ZClass(name); // SYMBOLTABLE[name] = cl; SymbolTable::instance().add_type(name,cl); //register attributes if(attribute_list!=NULL) for(int i=0;iattr_list.size();++i){ string name = attribute_list->attr_list[i]->id->val; cout<<"class register is wrong should implement var a; var b;"<attr_map[name] = attribute_list->attr_list[i]->exp; } //register methods ZObj * res = NULL; if(methods!=NULL){ res = register_methods(cl); ZObj::remove(res); } if(parents!=NULL){ res = register_parent_methods(cl); ZObj::remove(res); } return new ZStatus(true); } ZObj * ClassDecl::register_methods(ZClass * cl){ for(int i=0; imeth_list.size();++i){ ZObj * meth = methods->meth_list[i]->eval(); if(is_zmethdec(meth)){ ZMethodDec * m = (ZMethodDec*) meth; ZClass::ZMethodMap::iterator iter =cl->class_map.find(m->name); if(iter!=cl->class_map.end()){ ZObj * r = new ZError(line, "Re-definition of method " +m->name+" in class " +cl->name); ZObj::remove(m); return r; } cl->class_map[m->name] = m; SYMBOLTABLE[cl->name+":"+m->name]=m; } else return meth; } return new ZStatus(true); } ZObj * ClassDecl::register_parent_methods(ZClass * cl){ // for(int i=0;iident_list.size();++i){ // string name = parents->ident_list[i]->val; // ZObj * p = parents->ident_list[i]->eval(); // if(!is_zclass(p)){ // ZObj::remove(p); // throw ZError(line,"Object "+ name + " is not a class: "+ // p->class_name()); // } // //is class // ZClass * pc = (ZClass*) p; // map parent_class_map = pc->class_map; // map::iterator iter = parent_class_map.begin(); // while(iter!=parent_class_map.end()){ // if(cl->class_map.end()==cl->class_map.find(iter->first)){ // cl->class_map[iter->first] = iter->second; // } // ++iter; // } // ZObj::remove(p); // } // return new ZStatus(true); }