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
    }
  //=====================================================================================================================
  void visitClassImpl(ClassImpl *p) {

      fprintf(m_outputfile, "############ CLASS\n");

      // Set current class name for function labels
      currClassName = dynamic_cast<ClassIDImpl*>(p->m_classid_1)->m_classname->spelling();

      // Create this class's classnode and insert into class table
      ClassNode* node = new ClassNode();
      node->name = new ClassName(currClassName);
      node->superClass = NULL;
      node->scope = new SymScope(); // only used for holding methods
      node->p = p;
      if(p->m_classid_2!=NULL) {
          const char* superclass = dynamic_cast<ClassIDImpl*>(p->m_classid_2)->m_classname->spelling();
          assert(m_classtable->exist(superclass));
          node->superClass = new ClassName(superclass);
          m_classtable->lookup(superclass)->offset->copyTo(node->offset);
      }
      currClassOffset = node->offset;
      m_classtable->insert(node->name->spelling(), node);

      inMethod = false;

      // Visit the children
      p->visit_children(this);

      fprintf(m_outputfile, "############\n\n");
  }