void visitDeclarationImpl(DeclarationImpl *p) { // cout<< "this is my first variable : "<< VarIdP->m_symname->spelling()<<endl; p->visit_children(this); Symbol * symp = new Symbol; Symbol * test; SymScope * sync; typename std::list<VariableID_ptr>::iterator it = p->m_variableid_list->begin(); for( ; it != p->m_variableid_list->end(); ++it) { VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(*it); char * key = strdup(VarIdP->m_symname->spelling()); sync = m_symboltable->get_scope(); // cout<<key<<endl; // p->m_attribute.m_type.baseType = p->m_type->m_attribute.m_type.baseType; // i think this is setting the type of the assignment node // test = m_symboltable->lookup(key); if(m_symboltable->exist(key))//~!~!~!~!~!~!~!~ place here t_error(dup_ident_name, p->m_attribute); else{ test = InScope(key); if(test != NULL){ t_error(dup_ident_name, p->m_attribute); } m_symboltable->insert(key, symp); symp->baseType = p->m_type->m_attribute.m_type.baseType; if(symp->baseType == 8){ symp->classType.classID = p->m_type->m_attribute.m_type.classType.classID; } // cout<< "Decla; key: "<< key <<" type : "<< symp->baseType<<endl; } }//forloop //cout<<"declaration TYPE: "<<p->m_type->m_attribute.m_type.baseType<<endl; //WRITE ME }
Symbol * InScope(char* key){// before calling this function make sure there is a parent scope Symbol * symbP; SymScope *sync; ClassNode * parent; ClassNode * clasp; char* parentName; bool found; string pName; int i =0; // cout<<" the key is "<<key<<endl; symbP = m_symboltable->lookup(key); if(!m_symboltable->exist(key)){ symbP = m_symboltable->lookup((const char *)"xxx"); char * Cname = strdup(symbP->classType.classID); parent = m_classtable->lookup(Cname); // cout<<"parent: "<<parent->name->spelling()<<endl; sync = parent->scope; symbP = sync->lookup(key); found = sync->exist(key); while(found == false){ ClassName * classGreat = new ClassName(Cname); ClassNode* pNode = m_classtable->getParentOf(classGreat); Cname = strdup(pNode->name->spelling()); std::string pName(pNode->name->spelling()); // cout<<"the parent name: "<<Cname<<endl; if( pName == "TopClass"){ return NULL; } sync = pNode->scope; found = sync->exist(key); symbP = sync->lookup(key); i++; } } return symbP; }
void visitMethodCall(MethodCall *p) { p->visit_children(this); Symbol* symp; ClassNode * clasp; Basetype bargs; int i =0; Symbol * test; VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(p->m_variableid); MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid); char * meth = strdup(MethIdP->m_symname->spelling()); test = m_symboltable->lookup(meth); // Basetype bargs; char * var = strdup(VarIdP->m_symname->spelling()); // cout<<"the var : "<<var<<endl; if( !m_symboltable->exist(var)){//if symbol not defined within class t_error(sym_name_undef, p->m_attribute); } symp = InScope(var) ;//~!~!~!~!~!~!~!~ place here if(symp->baseType != 8){ t_error(sym_type_mismatch,p->m_attribute); } char *name = strdup(symp->classType.classID); clasp = m_classtable->lookup(name); // cout<<name<<endl; if(!m_classtable->exist(name)){ t_error(sym_name_undef,p->m_attribute); } // SymScope *sync = clasp->scope; char * className= strdup(symp->classType.classID); ClassNode* classnode = m_classtable->lookup(className); SymScope * sync = classnode->scope; symp= sync->lookup(meth); //symp = InScope(meth);//~!~!~!~!~!~!~!~ place here if(symp == NULL){ t_error(no_class_method, p->m_attribute); } if(p->m_expression_list->size()!= symp->methodType.argsType.size() ) t_error(call_args_mismatch,p->m_attribute); typename std::list<Expression_ptr>::iterator it = p->m_expression_list->begin(); for( ; it != p->m_expression_list->end(); ++it) { Expression * Expoin = dynamic_cast<Expression *> (*it); bargs = symp->methodType.argsType[i].baseType; if(bargs != Expoin->m_attribute.m_type.baseType) t_error(call_args_mismatch, p->m_attribute); i++; } p->m_attribute.m_type.baseType = symp->methodType.returnType.baseType; p->m_attribute.m_type.methodType.returnType.baseType = symp->methodType.returnType.baseType; //WRITE ME }