private static void MoveFunction(Function function, Class @class) { var method = new Method(function) { Namespace = @class, IsStatic = true }; function.ExplicitlyIgnore(); if (method.OperatorKind != CXXOperatorKind.None) { var param = function.Parameters[0]; Class type; if (!FunctionToInstanceMethodPass.GetClassParameter(param, out type)) { return; } method.Kind = CXXMethodKind.Operator; method.IsNonMemberOperator = true; method.OriginalFunction = null; } @class.Methods.Add(method); }
private Class FindClassToMoveFunctionTo(Function function) { Class @class = null; if (function.IsOperator) { foreach (var param in function.Parameters) { if (FunctionToInstanceMethodPass.GetClassParameter(param, out @class)) { break; } } if (@class == null) { function.ExplicitlyIgnore(); } } else { string name = (function.Namespace as TranslationUnit)?.FileNameWithoutExtension ?? function.Namespace.Name; @class = ASTContext.FindClass( name, ignoreCase: true).FirstOrDefault( c => c.TranslationUnit.Module == function.TranslationUnit.Module && !c.IsIncomplete); } return(@class); }
private Class FindClassToMoveFunctionTo(Function function) { Class @class = null; if (function.IsOperator) { foreach (var param in function.Parameters) { if (FunctionToInstanceMethodPass.GetClassParameter(param, out @class)) { break; } } if (@class == null) { function.ExplicitlyIgnore(); } } else { var unit = function.Namespace as TranslationUnit; @class = unit == null ? ASTContext.FindClass( function.Namespace.Name, ignoreCase : true).FirstOrDefault() : ASTContext.FindCompleteClass( unit.FileNameWithoutExtension.ToLowerInvariant(), true); } return(@class); }
public override bool VisitFunctionDecl(Function function) { if (function.Ignore || !function.IsOperator) { return(false); } var param = function.Parameters[0]; Class @class; if (!FunctionToInstanceMethodPass.GetClassParameter(param, out @class)) { return(false); } function.ExplicityIgnored = true; // Create a new fake method so it acts as a static method. var method = new Method() { Namespace = @class, OriginalNamespace = function.Namespace, Name = function.Name, OriginalName = function.OriginalName, Mangled = function.Mangled, Access = AccessSpecifier.Public, Kind = CXXMethodKind.Operator, ReturnType = function.ReturnType, Parameters = new List <Parameter>(function.Parameters).Skip(1).ToList(), CallingConvention = function.CallingConvention, IsVariadic = function.IsVariadic, IsInline = function.IsInline, OperatorKind = function.OperatorKind, SynthKind = FunctionSynthKind.NonMemberOperator, OriginalFunction = function }; @class.Methods.Add(method); Driver.Diagnostics.Debug("Function converted to operator: {0}::{1}", @class.Name, function.Name); return(true); }
public override bool VisitFunctionDecl(Function function) { if (!function.IsGenerated || !function.IsOperator) { return(false); } Class @class = null; foreach (var param in function.Parameters) { FunctionToInstanceMethodPass.GetClassParameter( param, out @class); if (@class != null) { break; } } if (@class == null) { return(false); } // Create a new fake method so it acts as a static method. var method = new Method(function) { Namespace = @class, Kind = CXXMethodKind.Operator, OperatorKind = function.OperatorKind, IsNonMemberOperator = true, OriginalFunction = null, IsStatic = true }; function.ExplicitlyIgnore(); @class.Methods.Add(method); Driver.Diagnostics.Debug("Function converted to operator: {0}::{1}", @class.Name, function.Name); return(true); }