private Expression GetAllocatorNewExpression(CallArguments/*!*/ args, Func<Expression>/*!*/ defaultExceptionMessage) {
Type type = GetUnderlyingSystemType();
if (type == typeof(object)) {
type = typeof(RubyObject);
}
if (_structInfo != null) {
return Methods.AllocateStructInstance.OpCall(AstUtils.Convert(args.TargetExpression, typeof(RubyClass)));
}
ConstructorInfo ctor;
if (IsException()) {
if ((ctor = GetConstructor(type, typeof(string))) != null) {
return Ast.New(ctor, defaultExceptionMessage());
} else if ((ctor = GetConstructor(type, typeof(string), typeof(Exception))) != null) {
return Ast.New(ctor, defaultExceptionMessage(), AstUtils.Constant(null));
}
}
if ((ctor = GetConstructor(type, typeof(RubyClass))) != null) {
return Ast.New(ctor, AstUtils.Convert(args.TargetExpression, typeof(RubyClass)));
}
if ((ctor = GetConstructor(type, typeof(RubyContext))) != null) {
return Ast.New(ctor, AstUtils.Convert(args.MetaContext.Expression, typeof(RubyContext)));
}
if ((ctor = GetConstructor(type)) != null) {
return Ast.New(ctor);
}
if (type.IsValueType && type != typeof(int) && type != typeof(double)) {
return Ast.New(type);
}
return null;
}