|
|
|
|
@ -3,34 +3,34 @@ using CppSharp.AST;
@@ -3,34 +3,34 @@ using CppSharp.AST;
|
|
|
|
|
|
|
|
|
|
namespace CppSharp.Passes |
|
|
|
|
{ |
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moves a function to a class, if any, named after the function's header.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MoveFunctionToClassPass : TranslationUnitPass |
|
|
|
|
{ |
|
|
|
|
public override bool VisitFunctionDecl(Function function) |
|
|
|
|
{ |
|
|
|
|
if (!AlreadyVisited(function) && !function.Ignore && !(function.Namespace is Class) |
|
|
|
|
// HACK: there are bugs with operators generated by Q_DECLARE_OPERATORS_FOR_FLAGS, an incorrect argument type, to say the least
|
|
|
|
|
&& !function.IsOperator) |
|
|
|
|
{ |
|
|
|
|
TranslationUnit unit = function.Namespace as TranslationUnit; |
|
|
|
|
Class @class; |
|
|
|
|
if (unit != null) |
|
|
|
|
{ |
|
|
|
|
@class = Driver.ASTContext.FindCompleteClass( |
|
|
|
|
unit.FileNameWithoutExtension.ToLowerInvariant(), true); |
|
|
|
|
if (AlreadyVisited(function) || function.Ignore || function.Namespace is Class) |
|
|
|
|
return base.VisitFunctionDecl(function); |
|
|
|
|
|
|
|
|
|
Class @class = FindClassToMoveFunctionTo(function.Namespace); |
|
|
|
|
if (@class != null) |
|
|
|
|
{ |
|
|
|
|
MoveFunction(function, @class); |
|
|
|
|
return base.VisitFunctionDecl(function); |
|
|
|
|
} |
|
|
|
|
return base.VisitFunctionDecl(function); |
|
|
|
|
} |
|
|
|
|
@class = Driver.ASTContext.FindClass( |
|
|
|
|
function.Namespace.Name, ignoreCase: true).FirstOrDefault(); |
|
|
|
|
if (@class != null) |
|
|
|
|
|
|
|
|
|
private Class FindClassToMoveFunctionTo(INamedDecl @namespace) |
|
|
|
|
{ |
|
|
|
|
MoveFunction(function, @class); |
|
|
|
|
} |
|
|
|
|
TranslationUnit unit = @namespace as TranslationUnit; |
|
|
|
|
if (unit == null) |
|
|
|
|
{ |
|
|
|
|
return Driver.ASTContext.FindClass( |
|
|
|
|
@namespace.Name, ignoreCase: true).FirstOrDefault(); |
|
|
|
|
} |
|
|
|
|
return base.VisitFunctionDecl(function); |
|
|
|
|
return Driver.ASTContext.FindCompleteClass( |
|
|
|
|
unit.FileNameWithoutExtension.ToLowerInvariant(), true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void MoveFunction(Function function, Class @class) |
|
|
|
|
@ -41,6 +41,17 @@ namespace CppSharp.Passes
@@ -41,6 +41,17 @@ namespace CppSharp.Passes
|
|
|
|
|
IsStatic = true |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (method.OperatorKind != CXXOperatorKind.None) |
|
|
|
|
{ |
|
|
|
|
var param = function.Parameters[0]; |
|
|
|
|
Class type; |
|
|
|
|
if (!FunctionToInstanceMethodPass.GetClassParameter(param, out type)) |
|
|
|
|
return; |
|
|
|
|
method.Kind = CXXMethodKind.Operator; |
|
|
|
|
method.SynthKind = FunctionSynthKind.NonMemberOperator; |
|
|
|
|
method.OriginalFunction = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function.ExplicityIgnored = true; |
|
|
|
|
|
|
|
|
|
@class.Methods.Add(method); |
|
|
|
|
|