void visitFuncImpl(FuncImpl * p) { p->m_attribute.m_scope = m_st->get_scope(); p->m_type->accept(this); add_func_symbol(p); m_st->open_scope(); p->visit_children(this); m_st->close_scope(); check_return_type(p); }
void visitClassImpl(ClassImpl *p) { int stop; m_symboltable->open_scope(); Symbol * symPtr = new Symbol; // = new ClassNode; Symbol * symp;// = new Symbol; ClassIDImpl * ClassIdP = dynamic_cast<ClassIDImpl*>(p->m_classid_1); ClassIDImpl * ClassIdP2 = dynamic_cast<ClassIDImpl*>(p->m_classid_2); char * key1 = strdup(ClassIdP->m_classname->spelling()); symPtr->classType.classID = ClassIdP->m_classname->spelling(); char * progFinder = strdup("Program"); ClassName * nm = new ClassName(key1); if(progger == true){ t_error(no_program, p->m_attribute); } if(std::string(key1) == std::string(progFinder)){ progger = true; } //char * key2 = strdup(ClassIdP2->m_classname->spelling()); if(m_classtable->exist(key1)){ t_error(dup_ident_name, p->m_attribute); } else{ if(ClassIdP2->m_classname != NULL){ char * key2 = strdup(ClassIdP2->m_classname->spelling()); ClassName * nm2 = new ClassName(key2); // cout<<"inserted class: " <<key1 <<" from :"<<key2 <<endl; m_classtable->insert(nm, nm2, p, m_symboltable->get_scope()); ClassNode * clasp = m_classtable->getParentOf(key2); // cout<<"Class: " <<key1 <<", Super class: "<<clasp->name->spelling()<<endl; } else{ // cout<< "instered this in class table: "<< key1 <<endl; m_classtable->insert(nm, NULL, p, m_symboltable->get_scope()); } } m_symboltable->insert((char *)"xxx", symPtr); p->visit_children(this); m_symboltable->close_scope(); //WRITE ME }
void visitMethodImpl(MethodImpl *p) { m_symboltable->open_scope(); if (p->m_type != NULL) { p->m_type->accept( this ); } else { this->visitNullPointer(); } // cout<<"my type: "<<p->m_type->m_attribute.m_type.baseType<<endl; Symbol *symp = new Symbol; Symbol *Msymp = new Symbol; Symbol *test; MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid); p->m_attribute.m_type.baseType = p->m_type->m_attribute.m_type.baseType; //this is dealing with duplicate method names char * key = strdup(MethIdP->m_symname->spelling());//~!~!~!~!~!~!~!~ place here test = InScope(key); if(test != NULL){//change this make Msymp = my function t_error(dup_ident_name, p->m_attribute); } else{ CompoundType arg; p->visit_children(this); //Adding parameters to sym table and each argument to method vector typename std::list<Parameter_ptr>::iterator it = p->m_parameter_list->begin(); for( ; it != p->m_parameter_list->end(); ++it) { ParameterImpl * Pimp = dynamic_cast<ParameterImpl *> (*it); VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(Pimp->m_variableid); //char * key = strdup(VarIdP->m_symname->spelling()); arg.baseType = Pimp->m_type->m_attribute.m_type.baseType; Msymp->methodType.argsType.push_back(arg); } Msymp->methodType.returnType.baseType = p->m_type->m_attribute.m_type.baseType; Msymp->baseType = p->m_type->m_attribute.m_type.baseType; m_symboltable->insert_in_parent_scope(key, Msymp); } if(p->m_type->m_attribute.m_type.baseType != p->m_methodbody->m_attribute.m_type.baseType){ t_error(ret_type_mismatch, p->m_attribute); } m_symboltable->close_scope(); //WRITE ME }