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; }
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; }
public void Basics() { DelegateDefinition one = new DelegateDefinition(SomeArbitraryMethod); one += SomeOtherArbitraryMethod; one(1000); }