Browse Source

Extract method.TranslationUnit.Module expression into a local variable.

pull/658/head
Joao Matos 9 years ago
parent
commit
7542f7c868
  1. 19
      src/Generator/Passes/DelegatesPass.cs

19
src/Generator/Passes/DelegatesPass.cs

@ -93,19 +93,21 @@ namespace CppSharp.Passes
var @params = method.GatherInternalParams(Driver.Options.IsItaniumLikeAbi, true).ToList(); var @params = method.GatherInternalParams(Driver.Options.IsItaniumLikeAbi, true).ToList();
var delegateName = GenerateDelegateSignature(@params, method.ReturnType); var delegateName = GenerateDelegateSignature(@params, method.ReturnType);
var module = method.TranslationUnit.Module;
Namespace namespaceDelegates; Namespace namespaceDelegates;
if (namespacesDelegates.ContainsKey(method.TranslationUnit.Module)) if (namespacesDelegates.ContainsKey(module))
{ {
namespaceDelegates = namespacesDelegates[method.TranslationUnit.Module]; namespaceDelegates = namespacesDelegates[module];
} }
else else
{ {
namespaceDelegates = new Namespace namespaceDelegates = new Namespace
{ {
Name = DelegatesNamespace, Name = DelegatesNamespace,
Namespace = method.TranslationUnit.Module.Units.Last() Namespace = module.Units.Last()
}; };
namespacesDelegates.Add(method.TranslationUnit.Module, namespaceDelegates); namespacesDelegates.Add(module, namespaceDelegates);
} }
var @delegate = new TypedefDecl var @delegate = new TypedefDecl
@ -124,20 +126,21 @@ namespace CppSharp.Passes
Namespace = namespaceDelegates Namespace = namespaceDelegates
}; };
Generator.CurrentOutputNamespace = method.TranslationUnit.Module.OutputNamespace; Generator.CurrentOutputNamespace = module.OutputNamespace;
var delegateString = @delegate.Visit(TypePrinter).Type; var delegateString = @delegate.Visit(TypePrinter).Type;
var existingDelegate = GetExistingDelegate( var existingDelegate = GetExistingDelegate(
method.TranslationUnit.Module.Libraries, delegateString); method.TranslationUnit.Module.Libraries, delegateString);
if (existingDelegate != null) if (existingDelegate != null)
{ {
Driver.Delegates.Add(method, existingDelegate); Driver.Delegates.Add(method, existingDelegate);
return true; return true;
} }
existingDelegate = new DelegateDefinition( existingDelegate = new DelegateDefinition(module.OutputNamespace, delegateString);
method.TranslationUnit.Module.OutputNamespace, delegateString);
Driver.Delegates.Add(method, existingDelegate); Driver.Delegates.Add(method, existingDelegate);
foreach (var library in method.TranslationUnit.Module.Libraries)
foreach (var library in module.Libraries)
libsDelegates[library].Add(delegateString, existingDelegate); libsDelegates[library].Add(delegateString, existingDelegate);
namespaceDelegates.Declarations.Add(@delegate); namespaceDelegates.Declarations.Add(@delegate);

Loading…
Cancel
Save