Beispiel #1
0
bool CompilerTest::may_be_initialized(InstanceClass *klass) {
 if (klass->is_initialized()) {
    return false;
  }

  // All super classes and super interfaces must be initialized
  InstanceClass ic;
  for (ic = klass->obj(); !ic.is_null(); ic = ic.super()) {
    if (!ic.equals(klass) && !ic.is_initialized()) {
      return false;
    }

    TypeArray interfaces = ic.local_interfaces();
    int n_interfaces = interfaces.length();

    for (int i = 0; i < n_interfaces; i++) {
      int intf_id = interfaces.ushort_at(i);
      InstanceClass intf = Universe::class_from_id(intf_id);
      if (!intf.is_initialized()) {
        return false;
      }
    }
  }

  return true;
}
Beispiel #2
0
void VisitorNodeTyper::visit(ExprOP2 *n){
    n->getLeft()->accept(*this);
    TypeClass* tc = dynamic_cast<TypeClass*>(n->getLeft()->getType());
    Class* old_cur_class = this->cur_class;
    this->cur_class = tc ? tc->getClass() : 0;
    n->getRight()->accept(*this);
    // Type of binary operator is type of operands (with promotion), except for comparison operators
    if (   n->getOperator() == ExprOP2::LT || n->getOperator() == ExprOP2::LTE
        || n->getOperator() == ExprOP2::GT || n->getOperator() == ExprOP2::GTE
        || n->getOperator() == ExprOP2::EQ || n->getOperator() == ExprOP2::NEQ
    )
    {
        n->setType(TypePrimary::getBool());
    }
    else if (n->getOperator() == ExprOP2::DOT)
    {
        if (!tc)
            throw __FILE__ "(" QUOTE(__LINE__) "): Left hand side of . operator must be an object / class.";
        n->setType(n->getRight()->getType());
    }
    else if (n->getOperator() == ExprOP2::ARRAY)
    {
        // TODO Check rhs type
        TypeArray* ta = dynamic_cast<TypeArray*>(n->getLeft()->getType());
        if (!ta)
            throw __FILE__ "(" QUOTE(__LINE__) "): Left hand side of [] operator must be an array.";
        n->setType(ta->getType());
    }
    else    // All other operators
    {
        n->setType(n->getLeft()->getType());
    }
    this->cur_class = old_cur_class;
}
Beispiel #3
0
int fbtBuildInfo::getLengths(fbtBuildStructs& struct_builders)
{


	makeBuiltinTypes();

	fbtBuildStructs::Iterator bit = struct_builders.iterator();
	while (bit.hasMoreElements())
	{
		fbtBuildStruct& bs = bit.getNext();
		bs.m_structId = addType(bs.m_name, 0);

		m_strc.push_back(bs.m_structId);
		m_strc.push_back((FBTint16)bs.m_data.size());

		m_alloc.m_strc += (sizeof(FBTtype) * 2);


		fbtVariables::Iterator it = bs.m_data.iterator();
		while (it.hasMoreElements())
		{
			fbtVariable& cvar = it.getNext();

			cvar.m_typeId = addType(cvar.m_type, 0);
			cvar.m_nameId = addName(cvar.m_name);

			m_strc.push_back(cvar.m_typeId);
			m_strc.push_back(cvar.m_nameId);

			m_alloc.m_strc += (sizeof(FBTtype) * 2);
		}
	}

	return getTLengths(struct_builders);
}
Beispiel #4
0
		FunctionType
		FunctionType::substitute(const TemplateVarMap& templateVarMap,
		                         const Predicate& selfconst) const {
			if (templateVarMap.empty() && selfconst.isSelfConst()) {
				return *this;
			}
			
			const auto substitutedReturnType = returnType()->substitute(templateVarMap,
			                                                            selfconst);
			
			bool changed = (substitutedReturnType != returnType());
			
			TypeArray substitutedParameterTypes;
			
			for (const auto parameterType: parameterTypes()) {
				const auto substitutedParameterType = parameterType->substitute(templateVarMap,
				                                                                selfconst);
				changed |= (substitutedParameterType != parameterType);
				substitutedParameterTypes.push_back(substitutedParameterType);
			}
			
			auto noExceptPredicate = attributes().noExceptPredicate().substitute(templateVarMap,
			                                                                     selfconst);
			changed |= (noExceptPredicate != attributes().noExceptPredicate());
			
			if (changed) {
				FunctionAttributes newAttributes(attributes().isVarArg(),
				                                 attributes().isMethod(),
				                                 attributes().isTemplated(),
				                                 std::move(noExceptPredicate));
				return FunctionType(std::move(newAttributes), substitutedReturnType, std::move(substitutedParameterTypes));
			} else {
				return *this;
			}
		}
Beispiel #5
0
void fbtBuildInfo::reserve(void)
{
	m_name.reserve(fbtMaxTable);
	m_type.reserve(fbtMaxTable);
	m_tlen.reserve(fbtMaxTable);
	m_strc.reserve(fbtMaxTable * fbtMaxMember);
}
Beispiel #6
0
void list_var(SYM *sp, int i)
{
	TypeArray *ta;
	
		int     j;
        for(j = i; j; --j)
                lfs.printf("    ");
		if (sp->name->length()== 0)
			lfs.printf("%-10s =%06x ","<unnamed>",(unsigned int)sp->value.u);
		else {
			lfs.printf("%-10s =%06x",(char *)sp->name->c_str(),(unsigned int)sp->value.u);
			if (sp->tp)
				if (sp->tp->bit_width != -1)
					lfs.printf("  %d %d",sp->tp->bit_offset,sp->tp->bit_width);
		}
//			if (sp->IsPascal) ofs.printf("\tpascal ");
        if( sp->storage_class == sc_external)
                ofs.printf("\textern\t%s\n",(char *)sp->name->c_str());
        else if( sp->storage_class == sc_global )
                ofs.printf(";\tglobal\t%s\n",(char *)sp->name->c_str());
		put_typedef(sp->storage_class==sc_typedef);
        put_sc(sp->storage_class);
        put_ty(sp->tp);
        lfs.printf("\n");
        if(sp->tp == 0)
                return;
    if (sp->tp) {
  		if (sp->tp->type==bt_ifunc || sp->tp->type==bt_func) {
  			lfs.printf("\t\tParameters:\n\t\t\t");
  			ta = sp->GetProtoTypes();
  			ta->Print(&lfs);
  			if (ta)
  				delete ta;
			lfs.printf("Stack Space:\n\t\t");
			lfs.printf("Argbot: %d\n\t\t", sp->argbot);
			lfs.printf("Tmpbot: %d\n\t\t", sp->tempbot);
			lfs.printf("Stkspc: %d\n\t\t", sp->stkspace);
  		}
	  }
	  if (sp->tp) {
        if((sp->tp->type == bt_struct || sp->tp->type == bt_union || sp->tp->type==bt_class) &&
                sp->storage_class == sc_type)
                ListTable(&(sp->tp->lst),i+1);
    }
}
Beispiel #7
0
int TABLE::Find(std::string na,__int16 rettype, TypeArray *typearray, bool exact)
{
	SYM *thead, *first;
	int nn;
	TypeArray *ta;
	char namebuf[1000];
	int s1,s2,s3;
	std::string name;

  dfs.puts("</Find>\n");
  dfs.puts((char *)na.c_str());
  if (this==nullptr) {
    matchno = 0;
    return 0;
  }
	if (na.length()==0) {
	  dfs.printf("name is empty string\n");
		throw new C64PException(ERR_NULLPOINTER,1);
  }

	matchno = 0;
	if (this==&gsyms[0])
		thead = SYM::GetPtr(gsyms[hashadd((char *)na.c_str())].GetHead());
	else
		thead = SYM::GetPtr(head);
	first = thead;
//	while(thead != NULL) {
//	  lfs.printf("Ele:%s|\n", (char *)thead->name->c_str());
//	  thead = thead->GetNext();
// }
 thead = first;
	while( thead != NULL) {
//		dfs.printf((char *)"|%s|,|%s|\n",(char *)thead->name->c_str(),(char *)na.c_str());
    name = *thead->name;
		s1 = thead->name->compare(na);
		s2 = thead->name2->compare(na);
		s3 = thead->name3->compare(na);
//		dfs.printf("s1:%d ",s1);
//		dfs.printf("s2:%d ",s2);
//		dfs.printf("s3:%d\n",s3);
		if(((s1&s2)|(s1&s3)|(s2&s3))==0) {
		  dfs.printf("Match\n");
			match[matchno] = thead;
			matchno++;
			if (matchno > 98)
				break;
		
			if (exact) {
				ta = thead->GetProtoTypes();
				if (ta->IsEqual(typearray)) {
				  dfs.printf("Exact match");
				  ta->Print();
				  typearray->Print();
				  delete ta;
				  return 1;
				}
				ta->Print();
				delete ta;
			}
		}
    thead = thead->GetNextPtr();
    if (thead==first) {
      dfs.printf("Circular list.\n");
      throw new C64PException(ERR_CIRCULAR_LIST,1);
    }
  }
  dfs.puts("</Find>\n");
  return exact ? 0 : matchno;
}
static void iterate_fields(InstanceClass* ic, OopVisitor* visitor, 
                           bool visit_value) {
  InstanceClass s = ic->super();
  // Print fields defined by super class
  if (!s.is_null()) {
    iterate_fields(&s, visitor, visit_value);
  }
  // Print fields define by local class
  TypeArray fields = ic->original_fields(); 
  int last_field_offset = -1;
  for (;;) {
    int next_field_index = -1;
    int min_offset = 0x7fffffff;

    for(int index = 0; index < fields.length(); index += 5) {
      OriginalField f(ic, index);
      if (!f.is_static() &&
          f.offset() > last_field_offset && 
          f.offset() < min_offset) {
        next_field_index = index;
        min_offset = f.offset();
      }
    }

    last_field_offset = min_offset;
    if (next_field_index < 0) {
      break;
    }

    OriginalField f(ic, next_field_index);
    Symbol name = f.name();
    SymbolField field(&name, false);
    switch(f.type()) {
    case T_BOOLEAN:
      visitor->do_bool(&field, f.offset(), visit_value);
      break;
    case T_CHAR:
      visitor->do_char(&field, f.offset(), visit_value);
      break;
    case T_FLOAT :
      visitor->do_float(&field, f.offset(), visit_value);
      break;
    case T_DOUBLE:
      visitor->do_double(&field, f.offset(), visit_value);
      break;
    case T_BYTE:
      visitor->do_byte(&field, f.offset(), visit_value);
      break;
    case T_SHORT:
      visitor->do_short(&field, f.offset(), visit_value);
      break;
    case T_INT:
      visitor->do_int(&field, f.offset(), visit_value);
      break;
    case T_LONG:
      visitor->do_long(&field, f.offset(), visit_value);
      break;
    case T_OBJECT:
      visitor->do_oop(&field, f.offset(), visit_value);
      break;
    case T_ARRAY:
      visitor->do_oop(&field, f.offset(), visit_value);
      break;
    }
  }
}