public static void IgnoreFunctionsWithParameterTypeName(this ASTContext context, string matchTypeName)
 {
     foreach (TranslationUnit unit in context.TranslationUnits)
     {
         foreach (Function function in unit.Functions)
         {
             if (function.Parameters.Any(
                     p =>
             {
                 Type type = p.Type;
                 // depointer
                 if (type.IsPointer())
                 {
                     type = ((PointerType)type).Pointee;
                 }
                 string typeName;
                 if (type is TypedefType)
                 {
                     typeName = ((TypedefType)type).Declaration.Name;
                 }
                 else
                 {
                     typeName = type.ToString();
                 }
                 bool match = typeName == matchTypeName;
                 return(match);
             }))
             {
                 function.ExplicityIgnored = true;
             }
         }
     }
 }
Example #2
0
        private void MarshalRefClass(Class @class)
        {
            var method = Context.Function as Method;

            if (method != null &&
                method.Conversion == MethodConversionKind.FunctionToInstanceMethod &&
                Context.ParameterIndex == 0)
            {
                Context.Return.Write("{0}", Helpers.InstanceIdentifier);
                return;
            }

            string param = Context.Parameter.Name;
            Type   type  = Context.Parameter.Type.Desugar();

            if (type.IsAddress())
            {
                Class decl;
                if (type.TryGetClass(out decl) && decl.IsValueType)
                {
                    Context.Return.Write("{0}.{1}", param, Helpers.InstanceIdentifier);
                }
                else
                {
                    if (type.IsPointer())
                    {
                        Context.Return.Write("{0}{1}.{2}",
                                             method != null && method.OperatorKind == CXXOperatorKind.EqualEqual
                                ? string.Empty
                                : string.Format("ReferenceEquals({0}, null) ? global::System.IntPtr.Zero : ", param),
                                             param, Helpers.InstanceIdentifier, type);
                    }
                    else
                    {
                        if (method == null ||
                            // redundant for comparison operators, they are handled in a special way
                            (method.OperatorKind != CXXOperatorKind.EqualEqual &&
                             method.OperatorKind != CXXOperatorKind.ExclaimEqual))
                        {
                            Context.SupportBefore.WriteLine("if (ReferenceEquals({0}, null))", param);
                            Context.SupportBefore.WriteLineIndent(
                                "throw new global::System.ArgumentNullException(\"{0}\", " +
                                "\"Cannot be null because it is a C++ reference (&).\");",
                                param);
                        }
                        Context.Return.Write("{0}.{1}", param, Helpers.InstanceIdentifier);
                    }
                }
                return;
            }

            var realClass           = @class.OriginalClass ?? @class;
            var qualifiedIdentifier = realClass.Visit(this.typePrinter);

            Context.Return.Write(
                "ReferenceEquals({0}, null) ? new {1}.Internal{3}() : *({1}.Internal{3}*) ({0}.{2})", param,
                qualifiedIdentifier, Helpers.InstanceIdentifier, Helpers.GetSuffixForInternal(@class));
        }
 private static bool CheckForDefaultPointer(Type desugared, Parameter parameter)
 {
     if (desugared.IsPointer())
     {
         parameter.DefaultArgument.String = "null";
         return(true);
     }
     return(false);
 }
 private static bool CheckForDefaultPointer(Type desugared, Parameter parameter)
 {
     if (desugared.IsPointer())
     {
         parameter.DefaultArgument.String = "null";
         return true;
     }
     return false;
 }
 private static bool CheckForDefaultPointer(Type desugared, Parameter parameter)
 {
     if (desugared.IsPointer())
     {
         // IntPtr.Zero is not a constant
         parameter.DefaultArgument.String = desugared.IsPointerToPrimitiveType(PrimitiveType.Void) ?
                                            "new global::System.IntPtr()" : "null";
         return(true);
     }
     return(false);
 }
 private static bool CheckForDefaultPointer(Type desugared, Parameter parameter)
 {
     if (desugared.IsPointer())
     {
         // IntPtr.Zero is not a constant
         parameter.DefaultArgument.String = desugared.IsPointerToPrimitiveType(PrimitiveType.Void) ?
             "new global::System.IntPtr()" : "null";
         return true;
     }
     return false;
 }
Example #7
0
        private void MarshalRefClass(Class @class)
        {
            var method = Context.Function as Method;

            if (method != null &&
                method.Conversion == MethodConversionKind.FunctionToInstanceMethod &&
                Context.ParameterIndex == 0)
            {
                Context.Return.Write("{0}", Helpers.InstanceIdentifier);
                return;
            }

            string param = Context.Parameter.Name;
            Type   type  = Context.Parameter.Type.Desugar(resolveTemplateSubstitution: false);
            string paramInstance;
            Class  @interface;
            var    finalType    = type.GetFinalPointee() ?? type;
            var    templateType = finalType as TemplateParameterSubstitutionType;

            type = Context.Parameter.Type.Desugar();
            if (finalType.TryGetClass(out @interface) &&
                @interface.IsInterface)
            {
                paramInstance = $"{param}.__PointerTo{@interface.OriginalClass.Name}";
            }
            else
            {
                paramInstance = $@"{
                    (templateType != null ? $"(({@class.Visit(typePrinter)}) (object) " : string.Empty)}{
                    param}{(templateType != null ? ")" : string.Empty)
                    }.{Helpers.InstanceIdentifier}";
            }
            if (type.IsAddress())
            {
                Class decl;
                if (type.TryGetClass(out decl) && decl.IsValueType)
                {
                    Context.Return.Write(paramInstance);
                }
                else
                {
                    if (type.IsPointer())
                    {
                        Context.Return.Write("{0}{1}",
                                             method != null && method.OperatorKind == CXXOperatorKind.EqualEqual
                                ? string.Empty
                                : $"ReferenceEquals({param}, null) ? global::System.IntPtr.Zero : ",
                                             paramInstance);
                    }
                    else
                    {
                        if (method == null ||
                            // redundant for comparison operators, they are handled in a special way
                            (method.OperatorKind != CXXOperatorKind.EqualEqual &&
                             method.OperatorKind != CXXOperatorKind.ExclaimEqual))
                        {
                            Context.Before.WriteLine("if (ReferenceEquals({0}, null))", param);
                            Context.Before.WriteLineIndent(
                                "throw new global::System.ArgumentNullException(\"{0}\", " +
                                "\"Cannot be null because it is a C++ reference (&).\");",
                                param);
                        }
                        Context.Return.Write(paramInstance);
                    }
                }
                return;
            }

            var realClass           = @class.OriginalClass ?? @class;
            var qualifiedIdentifier = typePrinter.PrintNative(realClass);

            Context.Return.Write(
                "ReferenceEquals({0}, null) ? new {1}() : *({1}*) {2}",
                param, qualifiedIdentifier, paramInstance);
        }