Ejemplo n.º 1
0
    void visitParameterImpl(ParameterImpl *p) {
      p->visit_children(this);
      Symbol *symp = new Symbol;
      Symbol * test;

      VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(p->m_variableid);

      char * key = strdup(VarIdP->m_symname->spelling());
      test = InScope(key);
        if(test!=NULL){
            t_error(dup_ident_name, p->m_attribute);
          }
        else{
            symp->baseType = p->m_type->m_attribute.m_type.baseType;
        //    cout<< "param; key: "<< key <<" type : "<< symp->baseType<<endl;
            if(symp->baseType == 8){
              symp->classType.classID = p->m_type->m_attribute.m_type.classType.classID;
        //      cout<< "this is what i'm SEETTTING key: " << symp->classType.classID<<endl;

            }
            // cout<<"insertingthis var from param: "<<key <<endl;
            m_symboltable->insert(key, symp);
          }      

      //WRITE ME
    }
Ejemplo n.º 2
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
    }
Ejemplo n.º 3
0
  void visitClassImpl(ClassImpl *p) {
      ClassIDImpl * ClassIdP = dynamic_cast<ClassIDImpl*>(p->m_classid_1);
      char * key1 = strdup(ClassIdP->m_classname->spelling());
      Symbol * symPtr = new Symbol;
      symPtr->classType.classID = ClassIdP->m_classname->spelling();
      m_symboltable->insert((char *)"xxx", symPtr);

      p->visit_children(this);
         // WRITEME

  }
Ejemplo n.º 4
0
 // add symbol table information for all the declarations following
 void add_decl_symbol(DeclImpl *p)
 {
     
     list<SymName_ptr>::iterator iter;
     char *name; Symbol *s;
     
     for (iter = p->m_symname_list->begin(); iter != p->m_symname_list->end(); ++iter) {
         name = strdup((*iter)->spelling());
         s = new Symbol();
         s->m_basetype = p->m_type->m_attribute.m_basetype;
         
         if (! m_st->insert(name, s))
             this->t_error(dup_ident_name,  p->m_attribute);
     }
 }
Ejemplo n.º 5
0
  // create a symbol for the function and check there is none already existing
  void add_func_symbol(FuncImpl *p)
  {
      
      char *name; Symbol *s;
      
      name = strdup((p)->m_symname->spelling());
      
      s = new Symbol();
      s->m_basetype = bt_function;
      
      s->m_return_type = p->m_type->m_attribute.m_basetype;
      
      if (! m_st->insert(name, s))
          this->t_error(dup_ident_name,  p->m_attribute);


  }
Ejemplo n.º 6
0
    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
    }