private string TranslateEnumExpression(Function function, Type desugared, string @params) { TypeMap typeMap; if ((function.Parameters.Count == 0 || HasSingleZeroArgExpression(function)) && TypeDatabase.FindTypeMap(desugared, out typeMap)) { var typeInSignature = typeMap.CSharpSignatureType(new CSharpTypePrinterContext { MarshalKind = CSharpMarshalKind.DefaultExpression, Type = desugared }).SkipPointerRefs().Desugar(); Enumeration @enum; if (typeInSignature.TryGetEnum(out @enum)) { return("0"); } } if (@params.Contains("::")) { return(regexDoubleColon.Replace(@params, desugared + ".")); } return(regexName.Replace(@params, desugared + ".$1")); }
private bool IsTypeComplete(Type type) { TypeMap typeMap; if (TypeDatabase.FindTypeMap(type, out typeMap) && !typeMap.IsIgnored) { return(true); } var desugared = type.Desugar(); var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar(); var templateSpecializationType = finalType as TemplateSpecializationType; if (templateSpecializationType != null) { finalType = templateSpecializationType.Desugared.Type; } Declaration decl; if (!finalType.TryGetDeclaration(out decl)) { return(true); } return(!decl.IsIncomplete); }
private bool IsDeclIgnored(Declaration decl) { var parameter = decl as Parameter; if (parameter != null && parameter.Type.Desugar().IsPrimitiveType(PrimitiveType.Null)) { return(true); } TypeMap typeMap; return(TypeDatabase.FindTypeMap(decl, out typeMap) ? typeMap.IsIgnored : decl.Ignore); }
private bool?CheckForDefaultConstruct(Type desugared, Expression expression, ref string result) { var type = desugared.GetFinalPointee() ?? desugared; Class decl; if (!type.TryGetClass(out decl)) { return(false); } var ctor = expression as CXXConstructExpr; TypeMap typeMap; var typePrinter = new CSharpTypePrinter(Context); typePrinter.PushMarshalKind(CSharpMarshalKind.DefaultExpression); var typePrinterResult = type.Visit(typePrinter).Type; if (TypeDatabase.FindTypeMap(decl, type, out typeMap)) { var typeInSignature = typeMap.CSharpSignatureType( typePrinter.TypePrinterContext).SkipPointerRefs().Desugar(); Enumeration @enum; if (typeInSignature.TryGetEnum(out @enum)) { if (ctor != null && (ctor.Arguments.Count == 0 || HasSingleZeroArgExpression((Function)ctor.Declaration))) { result = "0"; return(true); } return(false); } if (ctor != null && typePrinterResult == "string" && ctor.Arguments.Count == 0) { result = "\"\""; return(true); } } if (ctor == null) { CheckForSimpleExpressions(expression, ref result, desugared); return(decl.IsValueType ? (bool?)false : null); } var method = (Method)expression.Declaration; var expressionSupported = decl.IsValueType && method.Parameters.Count == 0; if (expression.String.Contains('(')) { var argsBuilder = new StringBuilder("new "); argsBuilder.Append(typePrinterResult); argsBuilder.Append('('); for (var i = 0; i < ctor.Arguments.Count; i++) { var argument = ctor.Arguments[i]; var argResult = argument.String; expressionSupported &= PrintExpression(method.Parameters[i].Type.Desugar(), argument, ref argResult) ?? false; argsBuilder.Append(argResult); if (i < ctor.Arguments.Count - 1) { argsBuilder.Append(", "); } } argsBuilder.Append(')'); result = argsBuilder.ToString(); } else { if (method.Parameters.Count > 0) { var paramType = method.Parameters[0].Type.SkipPointerRefs().Desugar(); Enumeration @enum; if (paramType.TryGetEnum(out @enum)) { result = TranslateEnumExpression(method, paramType, expression.String); } } } return(expressionSupported ? true : (bool?)null); }