コード例 #1
0
ファイル: typecheck.cpp プロジェクト: Kazanovitz/compiler
    void visitSelfCall(SelfCall *p) {
      p->visit_children(this);
      Symbol * symp;
      MethodIDImpl * MethIdP = dynamic_cast<MethodIDImpl*>(p->m_methodid);
      Basetype bargs;
      char * key = strdup(MethIdP->m_symname->spelling());
      symp = InScope(key);
       // cout<<"After scope "<<key<<endl;
      std::vector<CompoundType> args;
      if(symp == NULL){

        t_error(no_class_method,p->m_attribute);
      }
      // cout<< "the key is: "<<key<<endl;

      int i = 0;
      if((p->m_expression_list->size()) != symp->methodType.argsType.size()) {

          t_error(call_narg_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->baseType;
      //WRITE ME
    }
コード例 #2
0
ファイル: typecheck.cpp プロジェクト: Kazanovitz/compiler
    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
    }
コード例 #3
0
ファイル: ACM476.cpp プロジェクト: mavs141/my_works_C
void PointPlace( double point1, double point2, nodePtr root, int count2 )
{
  bool canFindAns = false ;
  while ( root != NULL )
  {
    if ( InScope( root->value1, root->value2, point1 )
         && InScope( root->value3, root->value4, point2 ) )
    {
      printf( "Point %d is contained in figure %d\n", count2, root->num ) ;
      canFindAns = true ;
    } // if
    root = root->next ;
  } // while

  if( !canFindAns ) // 輸入的點不再任何矩形內 
    printf( "Point %d is not contained in any figure\n", count2 ) ;
  
} // PointPlace()
コード例 #4
0
ファイル: typecheck.cpp プロジェクト: Kazanovitz/compiler
    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
    }
コード例 #5
0
ファイル: typecheck.cpp プロジェクト: Kazanovitz/compiler
    void visitVariable(Variable *p) {
      p->visit_children(this);
     Symbol * symp;
    VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(p->m_variableid);
    char * key = strdup(VarIdP->m_symname->spelling());

    symp = InScope(key);
if(symp == NULL){

  t_error(sym_name_undef, p->m_attribute);
  }
      p->m_attribute.m_type.baseType = symp->baseType;

    if(symp->baseType == 8)
      p->m_attribute.m_type.classType.classID = symp->classType.classID;

      //WRITE ME
    }
コード例 #6
0
ファイル: typecheck.cpp プロジェクト: Kazanovitz/compiler
    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
    }
コード例 #7
0
ファイル: optimize.c プロジェクト: davidechiappetta/atalan
void OptimizeProcInline(Var * proc)
/*
Purpose:
	Replace every call to function that should be inlined with actual code from the function.
*/
{
	Instr * i;	//, * next;
	InstrBlock * blk;
	Var * subproc, * var, * arg;

	for(blk = proc->instr; blk != NULL; blk = blk->next) {
		for(i = blk->first; i != NULL; i = i->next) {
			if (i->op == INSTR_CALL) {
				subproc = i->result;

				// 1. We inline procedures that are called just once
				if (subproc->read == 1) {

					if (subproc->instr != NULL) {
						BufEmpty();
						FOR_EACH_ARG(subproc, arg, SUBMODE_ARG_IN+SUBMODE_ARG_OUT)
							if (arg->adr == NULL) {
								var = VarAllocScopeTmp(proc, INSTR_VAR, arg->type);
							} else {
								var = arg->adr;
							}
							BufPush(var);
							ProcReplaceVar(proc, arg, var);
						NEXT_ARG

						InScope(proc);
						GenSetDestination(blk, i);
						GenMacro(subproc, STACK);
						i = InstrDelete(blk, i);
						subproc->read--;

					}
				}
			}
		}
コード例 #8
0
ファイル: typecheck.cpp プロジェクト: Kazanovitz/compiler
    void visitAssignment(Assignment *p) {
     p->visit_children(this);

     string str1, str2, temp1, temp2;
     Symbol * symp;
     // Symbol * symp;
     SymScope *sync;
     ClassNode * parent;
     char* parentName;
     bool oneLevel = false;
      VariableIDImpl * VarIdP = dynamic_cast<VariableIDImpl*>(p->m_variableid);
      char * key = strdup(VarIdP->m_symname->spelling());
      symp = m_symboltable->lookup((const char *)"xxx");


      symp = InScope(key);
      if(symp != NULL){ // or i could change this to if symp ==NULL
        if(p->m_expression->m_attribute.m_type.baseType == 8){
          if(p->m_expression->m_attribute.m_type.baseType == 8 && symp->baseType == 8){
          // std::string temp1(p->m_expression->m_attribute.m_type.classType.classID);
          //std::string temp2(symp->classType.classID);
          if(temp1!= temp2){
            t_error(incompat_assign, p->m_attribute);
            }
          if(p->m_expression->m_attribute.m_type.methodType.returnType.baseType != symp->baseType){
            t_error(incompat_assign, p->m_attribute);
            }
           } 
        }
        if(p->m_expression->m_attribute.m_type.baseType != 8 && p->m_expression->m_attribute.m_type.baseType != symp->baseType){

          t_error(incompat_assign, p->m_attribute);
        }
      }     
      else{
         t_error(sym_name_undef, p->m_attribute);
        }
      //WRITE ME
    }
コード例 #9
0
ファイル: typecheck.cpp プロジェクト: Kazanovitz/compiler
    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
    }