示例#1
0
        public override void VisitFunctionDecl(FunctionDecl decl, VisitKind visitKind)
        {
            if (visitKind != VisitKind.Enter)
            {
                return;
            }
            // skip macros : we generally implement them but their name is lost (so no matching is possible)
            if (!decl.IsExternC)
            {
                return;
            }

            var name = decl.Name;

            // do not consider _* or __* as public API that should be bound
            if (name [0] == '_')
            {
                return;
            }

            var framework = Helpers.GetFramework(decl);

            if (framework == null)
            {
                return;
            }

            // check availability macros to see if the API is available on the OS and not deprecated
            if (!decl.IsAvailable())
            {
                return;
            }

            if (!dllimports.ContainsKey(name))
            {
                // if we find functions without matching DllImport then we report them
                // but don't report deprecated functions
                if (!decl.IsDeprecated())
                {
                    Log.On(framework).Add($"!missing-pinvoke! {name} is not bound");
                }
                return;
            }

            dllimports.Remove(name);
        }
示例#2
0
        public override void VisitFunctionDecl(FunctionDecl decl, VisitKind visitKind)
        {
            if (visitKind != VisitKind.Enter)
            {
                return;
            }
            // skip macros : we generally implement them but their name is lost (so no matching is possible)
            if (!decl.IsExternC)
            {
                return;
            }

            var name = decl.Name;

            // do not consider _* or __* as public API that should be bound
            if (name [0] == '_')
            {
                return;
            }

            // exclude non-framework code (e.g. all unix headers)
            var header_file = decl.PresumedLoc.FileName;
            var fxh         = header_file.IndexOf(".framework/Headers/", StringComparison.Ordinal);
            var framework   = String.Empty;

            if (fxh > 0)
            {
                var start = header_file.LastIndexOf('/', fxh) + 1;
                framework = header_file.Substring(start, fxh - start);
            }
            else
            {
                // FIXME: we only process the headers in Frameworks, not all the UNIX headers
                // that still miss a few things (like objc runtime) but nothing that *requires* binding
                return;
            }

            // check availability macros to see if the API is available on the OS and not deprecated
            if (!decl.IsAvailable())
            {
                return;
            }

            MethodDefinition md;

            if (!dllimports.TryGetValue(name, out md))
            {
                // FIXME: we ignore some frameworks we have not bound (too many entries for our data files)
                // we do this late because, in some cases like vImage, we do bind a few API
                switch (framework)
                {
                // Accelerate and friends
                case "vImage":
                case "vecLib":
                    return;

                // security
                case "GSS":
                    return;

                // exposed in OpenTK-1.dll
                case "OpenAL":
                case "OpenGLES":
                    return;
                }

                // if we find functions without matching DllImport then we report them
                Console.WriteLine("!missing-pinvoke! {0} is not bound", name);
                return;
            }

            dllimports.Remove(name);
        }