Exemple #1
0
String ConvertTypeToString(TypeInfo &ti, TypeInfo *subType=NULL)
{
    if(!ti.name || !ti.name[0])
        return String() << TEXT("void");
    else if(ti.type == DataType_Object)
    {
        Class *cls = FindClass(ti.name);
        assert(cls);
        while(cls->IsPureScriptClass()) cls = cls->GetParent();
        return String() << cls->GetName() << TEXT("*");
    }
    else if(ti.type == DataType_String)
        return String() << TEXT("String");
    else if(ti.type == DataType_List)
        return String() << TEXT("List<") << ConvertTypeToString(*subType) << TEXT(">");
    else if(ti.type == DataType_Type)
        return String() << TEXT("TypeDataInfo");
    else if(scmp(ti.name, TEXT("bool")) == 0)
        return String() << TEXT("BOOL");
    else if(scmp(ti.name, TEXT("icolor")) == 0)
        return String() << TEXT("DWORD");
    else if(scmp(ti.name, TEXT("handle")) == 0)
        return String() << TEXT("HANDLE");
    else
        return String() << ti.name;
}
void Environment::AddClassPtr(Class *class_ptr)
{
	infunc(Environment::AddClassPtr);

	Class	*tclass;

	// Check to see if the class is already in the environment
	if ((tclass = (Class *)class_hash.GetEntry(class_ptr->GetName())) == NULL)
	{
		// Add to the classes in the environment
		class_hash.Add(class_ptr->GetName(), class_ptr);
	}
	else
	{
		// Throw an error if the class has already been defined
		if (tclass->IsDefined())
			throw CompileError("(File %s) Second definition of class %s found", cur_filename, tclass->GetName());

		// Remove the old shell and replace it with the defined class
		class_hash.Remove(tclass);
		class_hash.Add(class_ptr->GetName(), class_ptr);
	}

	// Add to the list of base classes if it's a base class
	if (!class_ptr->DoesInherit())
		base_classes.Add(class_ptr);

	outfunc;
}
Exemple #3
0
/****************************
 * Encodes a method parameter
 ****************************/
wstring Method::EncodeType(Type* type, ParsedProgram* program, Linker* linker)
{
  wstring name;
  if(type) {
    // type
    switch(type->GetType()) {
    case BOOLEAN_TYPE:
      name = L'l';
      break;

    case BYTE_TYPE:
      name = L'b';
      break;

    case INT_TYPE:
      name = L'i';
      break;

    case FLOAT_TYPE:
      name = L'f';
      break;

    case CHAR_TYPE:
      name = L'c';
      break;

    case NIL_TYPE:
      name = L'n';
      break;

    case VAR_TYPE:
      name = L'v';
      break;

    case CLASS_TYPE: {
      name = L"o.";

      // search program
      wstring klass_name = type->GetClassName();
      Class* klass = program->GetClass(klass_name);
      if(!klass) {
        vector<wstring> uses = program->GetUses();
        for(size_t i = 0; !klass && i < uses.size(); ++i) {
          klass = program->GetClass(uses[i] + L"." + klass_name);
        }
      }
      if(klass) {
        name += klass->GetName();
      }
      // search libaraires
      else {
        LibraryClass* lib_klass = linker->SearchClassLibraries(klass_name, program->GetUses());
        if(lib_klass) {
          name += lib_klass->GetName();
        } 
        else {
	  name += type->GetClassName();
        }
      }
    }
      break;
      
    case FUNC_TYPE:  {
      name = L"m.";
      if(type->GetClassName().size() == 0) {
	name += EncodeFunctionType(type->GetFunctionParameters(), type->GetFunctionReturn(),
				   program, linker);
      }
      else {
	name += type->GetClassName();
      }
    }
      break;
    }
    // dimension
    for(int i = 0; i < type->GetDimension(); i++) {
      name += L'*';
    }
  }

  return name;
}