public void GenerateFunction(Function function, DeclarationContext @namespace) { if (!function.IsGenerated || CLIHeaders.FunctionIgnored(function)) { return; } GenerateDeclarationCommon(function); var classSig = string.Format("{0}::{1}", QualifiedIdentifier(@namespace), TranslationUnit.FileNameWithoutExtension); Write("{0} {1}::{2}(", function.ReturnType, classSig, function.Name); for (var i = 0; i < function.Parameters.Count; ++i) { var param = function.Parameters[i]; Write("{0}", CTypePrinter.VisitParameter(param)); if (i < function.Parameters.Count - 1) { Write(", "); } } WriteLine(")"); WriteOpenBraceAndIndent(); GenerateFunctionCall(function); UnindentAndWriteCloseBrace(); }
private void GenerateClassMethods(Class @class, Class realOwner) { if (@class.IsValueType) { foreach (var @base in @class.Bases.Where(b => b.IsClass && !b.Class.Ignore)) { GenerateClassMethods(@base.Class, realOwner); } } foreach (var method in @class.Methods.Where(m => @class == realOwner || !m.IsOperator)) { if (ASTUtils.CheckIgnoreMethod(method) || CLIHeaders.FunctionIgnored(method)) { continue; } // C++/CLI does not allow special member funtions for value types. if (@class.IsValueType && method.IsCopyConstructor) { continue; } // Do not generate constructors or destructors from base classes. var declaringClass = method.Namespace as Class; if (declaringClass != realOwner && (method.IsConstructor || method.IsDestructor)) { continue; } GenerateMethod(method, realOwner); } }
public void GenerateMethod(Method method, Class @class) { if (CLIHeaders.FunctionIgnored(method)) { return; } PushBlock(BlockKind.Method, method); if (method.IsConstructor || method.IsDestructor || method.OperatorKind == CXXOperatorKind.Conversion || method.OperatorKind == CXXOperatorKind.ExplicitConversion) { Write("{0}::{1}(", QualifiedIdentifier(@class), GetMethodName(method)); } else { Write("{0} {1}::{2}(", method.ReturnType, QualifiedIdentifier(@class), method.Name); } GenerateMethodParameters(method); WriteLine(")"); if (method.IsConstructor) { GenerateClassConstructorBase(@class, method: method); } WriteOpenBraceAndIndent(); PushBlock(BlockKind.MethodBody, method); if (method.IsConstructor && @class.IsRefType) { PushBlock(BlockKind.ConstructorBody, @class); WriteLine("{0} = true;", Helpers.OwnsNativeInstanceIdentifier); } if (method.IsProxy) { goto SkipImpl; } if (@class.IsRefType) { if (method.IsConstructor) { if ([email protected]) { var @params = GenerateFunctionParamsMarshal(method.Parameters, method); Write($@"NativePtr = new {typePrinter.PrintTag(@class)}::{ @class.QualifiedOriginalName}("); GenerateFunctionParams(@params); WriteLine(");"); } PopBlock(); } else { GenerateFunctionCall(method, @class); } } else if (@class.IsValueType) { if (!method.IsConstructor) { GenerateFunctionCall(method, @class); } else { GenerateValueTypeConstructorCall(method, @class); } } SkipImpl: PopBlock(); UnindentAndWriteCloseBrace(); if (method.OperatorKind == CXXOperatorKind.EqualEqual) { GenerateEquals(method, @class); } PopBlock(NewLineKind.Always); }