|
|
@ -42,7 +42,8 @@ namespace CppSharp.Passes |
|
|
|
|
|
|
|
|
|
|
|
CheckFloatSyntax(desugared, parameter); |
|
|
|
CheckFloatSyntax(desugared, parameter); |
|
|
|
|
|
|
|
|
|
|
|
bool? defaultConstruct = CheckForDefaultConstruct(desugared, parameter.DefaultArgument); |
|
|
|
bool? defaultConstruct = CheckForDefaultConstruct(desugared, parameter.DefaultArgument, |
|
|
|
|
|
|
|
parameter.QualifiedType.Qualifiers); |
|
|
|
if (defaultConstruct == null || |
|
|
|
if (defaultConstruct == null || |
|
|
|
(!Driver.Options.MarshalCharAsManagedChar && |
|
|
|
(!Driver.Options.MarshalCharAsManagedChar && |
|
|
|
parameter.Type.Desugar().IsPrimitiveType(PrimitiveType.UChar))) |
|
|
|
parameter.Type.Desugar().IsPrimitiveType(PrimitiveType.UChar))) |
|
|
@ -106,12 +107,10 @@ namespace CppSharp.Passes |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private bool? CheckForDefaultConstruct(Type desugared, Expression arg) |
|
|
|
private bool? CheckForDefaultConstruct(Type desugared, Expression arg, TypeQualifiers qualifiers) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Unwrapping the underlying type behind a possible pointer/reference
|
|
|
|
// Unwrapping the underlying type behind a possible pointer/reference
|
|
|
|
Type type; |
|
|
|
Type type = desugared.GetFinalPointee() ?? desugared; |
|
|
|
desugared.IsPointerTo(out type); |
|
|
|
|
|
|
|
type = type ?? desugared; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Class decl; |
|
|
|
Class decl; |
|
|
|
if (!type.TryGetClass(out decl)) |
|
|
|
if (!type.TryGetClass(out decl)) |
|
|
@ -120,38 +119,48 @@ namespace CppSharp.Passes |
|
|
|
var ctor = arg.Declaration as Method; |
|
|
|
var ctor = arg.Declaration as Method; |
|
|
|
|
|
|
|
|
|
|
|
TypeMap typeMap; |
|
|
|
TypeMap typeMap; |
|
|
|
if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var typePrinterContext = new CSharpTypePrinterContext |
|
|
|
var typePrinterContext = new CSharpTypePrinterContext |
|
|
|
{ |
|
|
|
{ |
|
|
|
CSharpKind = CSharpTypePrinterContextKind.Managed, |
|
|
|
CSharpKind = CSharpTypePrinterContextKind.DefaultExpression, |
|
|
|
Type = type |
|
|
|
Type = type |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string typePrinterResult = null; |
|
|
|
|
|
|
|
if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap)) |
|
|
|
|
|
|
|
{ |
|
|
|
var typeInSignature = typeMap.CSharpSignatureType(typePrinterContext).SkipPointerRefs(); |
|
|
|
var typeInSignature = typeMap.CSharpSignatureType(typePrinterContext).SkipPointerRefs(); |
|
|
|
var mappedTo = typeMap.CSharpSignature(typePrinterContext); |
|
|
|
|
|
|
|
Enumeration @enum; |
|
|
|
Enumeration @enum; |
|
|
|
if (typeInSignature.TryGetEnum(out @enum)) |
|
|
|
if (typeInSignature.TryGetEnum(out @enum)) |
|
|
|
{ |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ctor == null || !ctor.IsConstructor) |
|
|
|
if (ctor == null || !ctor.IsConstructor) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (mappedTo == "string" && ctor.Parameters.Count == 0) |
|
|
|
|
|
|
|
|
|
|
|
typePrinterResult = typeMap.CSharpSignature(typePrinterContext); |
|
|
|
|
|
|
|
if (typePrinterResult == "string" && ctor.Parameters.Count == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
arg.String = "\"\""; |
|
|
|
arg.String = "\"\""; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (regexCtor.IsMatch(arg.String)) |
|
|
|
var match = regexCtor.Match(arg.String); |
|
|
|
|
|
|
|
if (match.Success) |
|
|
|
{ |
|
|
|
{ |
|
|
|
arg.String = string.Format("new {0}", arg.String); |
|
|
|
if (ctor != null) |
|
|
|
if (ctor != null && ctor.Parameters.Count > 0 && ctor.Parameters[0].Type.IsAddress()) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
var templateSpecializationType = type as TemplateSpecializationType; |
|
|
|
|
|
|
|
var typePrinter = new CSharpTypePrinter(Driver); |
|
|
|
|
|
|
|
typePrinterResult = typePrinterResult ?? (templateSpecializationType != null |
|
|
|
|
|
|
|
? typePrinter.VisitTemplateSpecializationType(templateSpecializationType, qualifiers) |
|
|
|
|
|
|
|
: typePrinter.VisitClassDecl((Class) ctor.Namespace)).Type; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
arg.String = string.Format("new {0}{1}", typePrinterResult, match.Groups[2].Value); |
|
|
|
|
|
|
|
if (ctor.Parameters.Count > 0 && ctor.Parameters[0].Type.IsAddress()) |
|
|
|
arg.String = arg.String.Replace("(0)", "()"); |
|
|
|
arg.String = arg.String.Replace("(0)", "()"); |
|
|
|
return decl.IsValueType ? true : (bool?) null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
arg.String = string.Format("new {0}", arg.String); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|