示例#1
0
bool TypeAnalyzer::isAutoboxedType(Type* type, Type** boxed) {
	if(type->type == TYPE_MATCHALL) return false;

	// shouldn't be here...throw exception?
	if(type->type == TYPE_UNUSABLE) return false;

	// need to return a List<T>
	if(type->arrayed) {
		*boxed = MakeType(TYPE_CLASS);
		Type* loweredtype = copyType(type);
		loweredtype->arrayed--;
		(*boxed)->typedata._class.classname = strdup("List");
		(*boxed)->typedata._class.parameters = MakeTypeArray();
		AddTypeToTypeArray(loweredtype, (*boxed)->typedata._class.parameters);
		return true;
	}

	// need to return a generic autoboxed type according to arguments/return
	if(type->type == TYPE_LAMBDA) {
		*boxed = MakeType(TYPE_CLASS);
		(*boxed)->typedata._class.classname = strdup("lambda");
		return true;
	}

	// shouldn't ever get here,..unless I decide to make, say, T?.exists() and/or T?.applyIfExists(fn(T))
	if(type->optional) return false;

	if(isPrimitiveTypeBool(type)) {
		*boxed = MakeType(TYPE_CLASS);
		(*boxed)->typedata._class.classname = strdup("Bool");
		return true;
	}

	if(isPrimitiveTypeText(type)) {
		*boxed = MakeType(TYPE_CLASS);
		(*boxed)->typedata._class.classname = strdup("Text");
		return true;
	}

	if(isPrimitiveTypeNum(type)) {
		*boxed = MakeType(TYPE_CLASS);
		(*boxed)->typedata._class.classname = strdup("Num");
		return true;
	}

	return false;
}
bool TypeAnalyzer::isAutoboxedType(PureType<wake::QUALIFIED>* type, PureType<wake::QUALIFIED>** boxed) {
	if(type->type == TYPE_MATCHALL) return false;

	// shouldn't be here...throw exception?
	if(type->type == TYPE_UNUSABLE) return false;

	// need to return a List<T>
	if(type->type == TYPE_LIST) {
		*boxed = new PureType<wake::QUALIFIED>(TYPE_CLASS);
		PureType<wake::QUALIFIED>* loweredtype = new PureType<wake::QUALIFIED>(*type->typedata.list.contained);
		(*boxed)->typedata._class.modulename = strdup("lang");
		(*boxed)->typedata._class.classname = strdup("List");
		(*boxed)->typedata._class.parameters = new PureTypeArray<wake::QUALIFIED>();

		// the template is just for static checks, we can safely cast these
		addPureTypeToPureTypeArray(
			(PureType<wake::UNQUALIFIED>*) loweredtype,
			(PureTypeArray<wake::UNQUALIFIED>*) (*boxed)->typedata._class.parameters
		);
		return true;
	}

	// need to return a generic autoboxed type according to arguments/return
	if(type->type == TYPE_LAMBDA) {
		*boxed = new PureType<wake::QUALIFIED>(TYPE_CLASS);
		(*boxed)->typedata._class.classname = strdup("lambda");
		return true;
	}

	// shouldn't ever get here,..unless I decide to make, say, T?.exists() and/or T?.applyIfExists(fn(T))
	if(type->type == TYPE_OPTIONAL) return false;

	if(isPrimitiveTypeBool(type)) {
		*boxed = new PureType<wake::QUALIFIED>(TYPE_CLASS);
		(*boxed)->typedata._class.modulename = strdup("lang");
		(*boxed)->typedata._class.classname = strdup("Bool");
		return true;
	}

	if(isPrimitiveTypeText(type)) {
		*boxed = new PureType<wake::QUALIFIED>(TYPE_CLASS);
		(*boxed)->typedata._class.modulename = strdup("lang");
		(*boxed)->typedata._class.classname = strdup("Text");
		return true;
	}

	if(isPrimitiveTypeNum(type)) {
		*boxed = new PureType<wake::QUALIFIED>(TYPE_CLASS);
		(*boxed)->typedata._class.modulename = strdup("lang");
		(*boxed)->typedata._class.classname = strdup("Num");
		return true;
	}

	if(isPrimitiveTypeInt(type)) {
		*boxed = new PureType<wake::QUALIFIED>(TYPE_CLASS);
		(*boxed)->typedata._class.modulename = strdup("lang");
		(*boxed)->typedata._class.classname = strdup("Int");
		return true;
	}

	if(isPrimitiveTypeChar(type)) {
		*boxed = new PureType<wake::QUALIFIED>(TYPE_CLASS);
		(*boxed)->typedata._class.modulename = strdup("lang");
		(*boxed)->typedata._class.classname = strdup("Char");
		return true;
	}

	return false;
}