Example #1
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
            {
                return(false);
            }

            var @params      = method.GatherInternalParams(Driver.Options.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var @delegate = new TypedefDecl
            {
                Name          = delegateName,
                QualifiedType = new QualifiedType(
                    new PointerType(
                        new QualifiedType(
                            new FunctionType
                {
                    CallingConvention = method.CallingConvention,
                    IsDependent       = method.IsDependent,
                    Parameters        = @params,
                    ReturnType        = method.ReturnType
                }))),
                Namespace = namespaceDelegates
            };

            var delegateString   = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(delegateString);

            if (existingDelegate != null)
            {
                Driver.Delegates.Add(method, existingDelegate);
                return(true);
            }

            existingDelegate = new DelegateDefinition(Driver.Options.OutputNamespace, delegateString);
            Driver.Delegates.Add(method, existingDelegate);
            foreach (var library in Driver.Options.Libraries)
            {
                libsDelegates[library].Add(delegateString, existingDelegate);
            }

            namespaceDelegates.Declarations.Add(@delegate);

            return(true);
        }
Example #2
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
                return false;

            var @params = method.GatherInternalParams(Driver.Options.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var @delegate = new TypedefDecl
                {
                    Name = delegateName,
                    QualifiedType = new QualifiedType(
                        new PointerType(
                            new QualifiedType(
                                new FunctionType
                                {
                                    CallingConvention = method.CallingConvention,
                                    IsDependent = method.IsDependent,
                                    Parameters = @params,
                                    ReturnType = method.ReturnType
                                }))),
                    Namespace = namespaceDelegates
                };

            var delegateString = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(delegateString);
            if (existingDelegate != null)
            {
                Driver.Delegates.Add(method, existingDelegate);
                return true;
            }

            existingDelegate = new DelegateDefinition(Driver.Options.OutputNamespace, delegateString);
            Driver.Delegates.Add(method, existingDelegate);
            foreach (var library in Driver.Options.Libraries)
                libsDelegates[library].Add(delegateString, existingDelegate);

            namespaceDelegates.Declarations.Add(@delegate);

            return true;
        }
Example #3
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
                return false;

            var @params = method.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var module = method.TranslationUnit.Module;

            Namespace namespaceDelegates;
            if (namespacesDelegates.ContainsKey(module))
            {
                namespaceDelegates = namespacesDelegates[module];
            }
            else
            {
                namespaceDelegates = new Namespace
                {
                    Name = DelegatesNamespace,
                    Namespace = module.Units.Last()
                };
                namespacesDelegates.Add(module, namespaceDelegates);
            }

            var @delegate = new TypedefDecl
                {
                    Name = delegateName,
                    QualifiedType = new QualifiedType(
                        new PointerType(
                            new QualifiedType(
                                new FunctionType
                                {
                                    CallingConvention = method.CallingConvention,
                                    IsDependent = method.IsDependent,
                                    Parameters = @params,
                                    ReturnType = method.ReturnType
                                }))),
                    Namespace = namespaceDelegates,
                    IsSynthetized = true
                };

            Generator.CurrentOutputNamespace = module.OutputNamespace;
            var delegateString = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(
                method.TranslationUnit.Module.Libraries, delegateString);

            if (existingDelegate != null)
            {
                Context.Delegates.Add(method, existingDelegate);
                return true;
            }

            existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
            Context.Delegates.Add(method, existingDelegate);

            foreach (var library in module.Libraries)
                libsDelegates[library].Add(delegateString, existingDelegate);

            namespaceDelegates.Declarations.Add(@delegate);

            return true;
        }
Example #4
0
        private void AddDelegatesToDictionary(Declaration decl, Module module)
        {
            CallingConvention callingConvention;
            bool             isDependent = false;
            QualifiedType    returnType;
            List <Parameter> @params;

            if (decl is Method)
            {
                var method = (Method)decl;
                @params           = method.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi, true).ToList();
                callingConvention = method.CallingConvention;
                isDependent       = method.IsDependent;
                returnType        = method.ReturnType;
            }
            else
            {
                var param         = (Parameter)decl;
                var funcTypeParam = param.Type.Desugar().GetFinalPointee().Desugar() as FunctionType;
                @params           = funcTypeParam.Parameters;
                callingConvention = funcTypeParam.CallingConvention;
                isDependent       = funcTypeParam.IsDependent;
                returnType        = funcTypeParam.ReturnType;
            }

            var       delegateName = GenerateDelegateSignature(@params, returnType);
            Namespace namespaceDelegates;

            if (namespacesDelegates.ContainsKey(module))
            {
                namespaceDelegates = namespacesDelegates[module];
            }
            else
            {
                Namespace parent = null;
                if (string.IsNullOrEmpty(module.OutputNamespace))
                {
                    var group = module.Units.SelectMany(u => u.Declarations).OfType <Namespace>(
                        ).GroupBy(d => d.Name).Where(g => g.Any(d => d.HasDeclarations)).ToList();
                    if (group.Count == 1)
                    {
                        parent = group.Last().Last();
                    }
                }
                if (parent == null)
                {
                    parent = module.Units.Last();
                }
                namespaceDelegates = new Namespace
                {
                    Name      = DelegatesNamespace,
                    Namespace = parent
                };
                namespacesDelegates.Add(module, namespaceDelegates);
            }

            var @delegate = new TypedefDecl
            {
                Name          = delegateName,
                QualifiedType = new QualifiedType(
                    new PointerType(
                        new QualifiedType(
                            new FunctionType
                {
                    CallingConvention = callingConvention,
                    IsDependent       = isDependent,
                    Parameters        = @params,
                    ReturnType        = returnType
                }))),
                Namespace     = namespaceDelegates,
                IsSynthetized = true,
                Access        = decl is Method ? AccessSpecifier.Private : AccessSpecifier.Public
            };

            var delegateString   = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(
                module, delegateString);

            if (existingDelegate != null)
            {
                Context.Delegates.Add(decl, existingDelegate);
                return;
            }

            existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
            Context.Delegates.Add(decl, existingDelegate);

            libsDelegates[module].Add(delegateString, existingDelegate);

            namespaceDelegates.Declarations.Add(@delegate);
        }
Example #5
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
            {
                return(false);
            }

            var @params      = method.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var module = method.TranslationUnit.Module;

            Namespace namespaceDelegates;

            if (namespacesDelegates.ContainsKey(module))
            {
                namespaceDelegates = namespacesDelegates[module];
            }
            else
            {
                namespaceDelegates = new Namespace
                {
                    Name      = DelegatesNamespace,
                    Namespace = module.Units.Last()
                };
                namespacesDelegates.Add(module, namespaceDelegates);
            }

            var @delegate = new TypedefDecl
            {
                Name          = delegateName,
                QualifiedType = new QualifiedType(
                    new PointerType(
                        new QualifiedType(
                            new FunctionType
                {
                    CallingConvention = method.CallingConvention,
                    IsDependent       = method.IsDependent,
                    Parameters        = @params,
                    ReturnType        = method.ReturnType
                }))),
                Namespace     = namespaceDelegates,
                IsSynthetized = true
            };

            Generator.CurrentOutputNamespace = module.OutputNamespace;
            var delegateString   = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(
                method.TranslationUnit.Module.Libraries, delegateString);

            if (existingDelegate != null)
            {
                Context.Delegates.Add(method, existingDelegate);
                return(true);
            }

            existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
            Context.Delegates.Add(method, existingDelegate);

            foreach (var library in module.Libraries)
            {
                libsDelegates[library].Add(delegateString, existingDelegate);
            }

            namespaceDelegates.Declarations.Add(@delegate);

            return(true);
        }
Example #6
0
        public override bool VisitMethodDecl(Method method)
        {
            if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)
            {
                return(false);
            }

            var @params      = method.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi, true).ToList();
            var delegateName = GenerateDelegateSignature(@params, method.ReturnType);

            var module = method.TranslationUnit.Module;

            Namespace namespaceDelegates;

            if (namespacesDelegates.ContainsKey(module))
            {
                namespaceDelegates = namespacesDelegates[module];
            }
            else
            {
                Namespace parent = null;
                if (string.IsNullOrEmpty(module.OutputNamespace))
                {
                    var group = module.Units.SelectMany(u => u.Declarations).OfType <Namespace>(
                        ).GroupBy(d => d.Name).Where(g => g.Any(d => d.HasDeclarations)).ToList();
                    if (group.Count == 1)
                    {
                        parent = group.Last().Last();
                    }
                }
                if (parent == null)
                {
                    parent = module.Units.Last();
                }
                namespaceDelegates = new Namespace
                {
                    Name      = DelegatesNamespace,
                    Namespace = parent
                };
                namespacesDelegates.Add(module, namespaceDelegates);
            }

            var @delegate = new TypedefDecl
            {
                Name          = delegateName,
                QualifiedType = new QualifiedType(
                    new PointerType(
                        new QualifiedType(
                            new FunctionType
                {
                    CallingConvention = method.CallingConvention,
                    IsDependent       = method.IsDependent,
                    Parameters        = @params,
                    ReturnType        = method.ReturnType
                }))),
                Namespace     = namespaceDelegates,
                IsSynthetized = true,
                Access        = AccessSpecifier.Private
            };

            var delegateString   = @delegate.Visit(TypePrinter).Type;
            var existingDelegate = GetExistingDelegate(
                method.TranslationUnit.Module, delegateString);

            if (existingDelegate != null)
            {
                Context.Delegates.Add(method, existingDelegate);
                return(true);
            }

            existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
            Context.Delegates.Add(method, existingDelegate);

            libsDelegates[module].Add(delegateString, existingDelegate);

            namespaceDelegates.Declarations.Add(@delegate);

            return(true);
        }