Esempio n. 1
0
    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
    }
Esempio n. 2
0
    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;
      
    }