public override bool VisitFunctionDecl(Function function) { if (!function.IsGenerated) { return(false); } var types = StringHelpers.SplitCamelCase(function.Name); if (types.Length == 0) { return(false); } var @class = AstContext.FindCompleteClass(types[0]); if (@class == null) { return(false); } // TODO: If the translation units of the declarations are different, // and we apply the pass, we might need additional includes in the // generated translation unit of the class. if (@class.TranslationUnit != function.TranslationUnit) { return(false); } // Clean up the name of the function now that it will be a static method. var name = function.Name.Substring(@class.Name.Length); function.ExplicitlyIgnore(); // Create a new fake method so it acts as a static method. var method = new Method { Namespace = @class, OriginalNamespace = function.Namespace, Name = name, OriginalName = function.OriginalName, Mangled = function.Mangled, Access = AccessSpecifier.Public, Kind = CXXMethodKind.Normal, ReturnType = function.ReturnType, Parameters = function.Parameters, CallingConvention = function.CallingConvention, IsVariadic = function.IsVariadic, IsInline = function.IsInline, IsStatic = true, Conversion = MethodConversionKind.FunctionToStaticMethod }; @class.Methods.Add(method); Log.Debug("Function converted to static method: {0}::{1}", @class.Name, function.Name); return(true); }
public void TestComments() { var @class = AstContext.FindCompleteClass("TestComments"); var commentClass = @class.Comment.FullComment.CommentToString(Options.CommentPrefix); Assert.AreEqual(@"/// <summary> /// <para>Hash set/map base class.</para> /// <para>Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor</para> /// <para>and therefore %HashBase pointers should never be used.</para> /// </summary>".Replace("\r", string.Empty), commentClass.Replace("\r", string.Empty)); var method = @class.Methods.First(m => m.Name == "GetIOHandlerControlSequence"); var commentMethod = method.Comment.FullComment.CommentToString(Options.CommentPrefix); Assert.AreEqual(@"/// <summary> /// <para>Get the string that needs to be written to the debugger stdin file</para> /// <para>handle when a control character is typed.</para> /// </summary> /// <remarks> /// <para>Some GUI programs will intercept "control + char" sequences and want</para> /// <para>to have them do what normally would happen when using a real</para> /// <para>terminal, so this function allows GUI programs to emulate this</para> /// <para>functionality.</para> /// </remarks> /// <param name=""ch""> /// <para>The character that was typed along with the control key</para> /// </param> /// <returns> /// <para>The string that should be written into the file handle that is</para> /// <para>feeding the input stream for the debugger, or NULL if there is</para> /// <para>no string for this control key.</para> /// </returns>".Replace("\r", string.Empty), commentMethod.Replace("\r", string.Empty)); }
public override bool VisitClassDecl(Class @class) { if ([email protected]) { goto Out; } if (@class.CompleteDeclaration != null) { goto Out; } @class.CompleteDeclaration = AstContext.FindCompleteClass(@class.QualifiedName); if (@class.CompleteDeclaration == null) { @class.IsGenerated = false; Driver.Diagnostics.Debug("Unresolved declaration: {0}", @class.Name); } Out: return(base.VisitClassDecl(@class)); }
public void TestPrivateCCtorCopyAssignment() { Class @class = AstContext.FindCompleteClass("HasPrivateCCtorCopyAssignment"); Assert.That(@class.Constructors.Any(c => c.Parameters.Count == 0), Is.True); Assert.That(@class.Constructors.Any(c => c.IsCopyConstructor), Is.True); Assert.That(@class.Methods.Any(o => o.OperatorKind == CXXOperatorKind.Equal), Is.True); }
public void TestComments() { var @class = AstContext.FindCompleteClass("TestComments"); var commentClass = @class.Comment.FullComment.CommentToString(CommentKind.BCPLSlash); Assert.AreEqual(@"/// <summary> /// <para>Hash set/map base class.</para> /// <para>Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor</para> /// <para>and therefore %HashBase pointers should never be used.</para> /// </summary>".Replace("\r", string.Empty), commentClass.Replace("\r", string.Empty)); var method = @class.Methods.First(m => m.Name == "GetIOHandlerControlSequence"); var commentMethod = method.Comment.FullComment.CommentToString(CommentKind.BCPL); Assert.AreEqual(@"// <summary> // <para>Get the string that needs to be written to the debugger stdin file</para> // <para>handle when a control character is typed.</para> // </summary> // <remarks> // <para>Some GUI programs will intercept "control + char" sequences and want</para> // <para>to have them do what normally would happen when using a real</para> // <para>terminal, so this function allows GUI programs to emulate this</para> // <para>functionality.</para> // </remarks> // <param name=""ch"">The character that was typed along with the control key</param> // <returns> // <para>The string that should be written into the file handle that is</para> // <para>feeding the input stream for the debugger, or NULL if there is</para> // <para>no string for this control key.</para> // </returns>".Replace("\r", string.Empty), commentMethod.Replace("\r", string.Empty)); var methodTestDoxygen = @class.Methods.First(m => m.Name == "SBAttachInfo"); var commentMethodDoxygen = methodTestDoxygen.Comment.FullComment.CommentToString(CommentKind.BCPLSlash); Assert.AreEqual(@"/// <summary>Attach to a process by name.</summary> /// <remarks> /// <para>This function implies that a future call to SBTarget::Attach(...)</para> /// <para>will be synchronous.</para> /// </remarks> /// <param name=""path"">A full or partial name for the process to attach to.</param> /// <param name=""wait_for""> /// <para>If <c>false,</c> attach to an existing process whose name matches.</para> /// <para>If <c>true,</c> then wait for the next process whose name matches.</para> /// </param>".Replace("\r", string.Empty), commentMethodDoxygen.Replace("\r", string.Empty)); }
private void EnsureCompleteDeclaration(Declaration declaration) { if (!declaration.IsIncomplete) { return; } if (declaration.CompleteDeclaration != null) { return; } declaration.CompleteDeclaration = AstContext.FindCompleteClass(declaration.QualifiedName); if (declaration.CompleteDeclaration == null) { declaration.GenerationKind = GenerationKind.Internal; Driver.Diagnostics.Debug("Unresolved declaration: {0}", declaration.Name); } }
public void TestLayoutBase() { var @class = AstContext.FindCompleteClass("TestComments"); Assert.That(@class.Layout.Bases.Count, Is.EqualTo(0)); }
public void TestComments() { var @class = AstContext.FindCompleteClass("TestComments"); var textGenerator = new TextGenerator(); textGenerator.Print(@class.Comment.FullComment, CommentKind.BCPLSlash); Assert.AreEqual(@"/// <summary> /// <para>Hash set/map base class.</para> /// <para>Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor</para> /// <para>and therefore %HashBase pointers should never be used.</para> /// </summary> ".Replace("\r", string.Empty), textGenerator.StringBuilder.Replace("\r", string.Empty).ToString()); var method = @class.Methods.First(m => m.Name == "GetIOHandlerControlSequence"); textGenerator.StringBuilder.Clear(); textGenerator.Print(method.Comment.FullComment, CommentKind.BCPL); Assert.AreEqual(@"// <summary> // <para>Get the string that needs to be written to the debugger stdin file</para> // <para>handle when a control character is typed.</para> // </summary> // <param name=""ch"">The character that was typed along with the control key</param> // <returns> // <para>The string that should be written into the file handle that is</para> // <para>feeding the input stream for the debugger, or NULL if there is</para> // <para>no string for this control key.</para> // </returns> // <remarks> // <para>Some GUI programs will intercept "control + char" sequences and want</para> // <para>to have them do what normally would happen when using a real</para> // <para>terminal, so this function allows GUI programs to emulate this</para> // <para>functionality.</para> // </remarks> ".Replace("\r", string.Empty), textGenerator.StringBuilder.Replace("\r", string.Empty).ToString()); var methodTestDoxygen = @class.Methods.First(m => m.Name == "SBAttachInfo"); textGenerator.StringBuilder.Clear(); textGenerator.Print(methodTestDoxygen.Comment.FullComment, CommentKind.BCPLSlash); Assert.AreEqual(@"/// <summary>Attach to a process by name.</summary> /// <param name=""path"">A full or partial name for the process to attach to.</param> /// <param name=""wait_for""> /// <para>If <c>false,</c> attach to an existing process whose name matches.</para> /// <para>If <c>true,</c> then wait for the next process whose name matches.</para> /// </param> /// <remarks> /// <para>This function implies that a future call to SBTarget::Attach(...)</para> /// <para>will be synchronous.</para> /// </remarks> ".Replace("\r", string.Empty), textGenerator.StringBuilder.Replace("\r", string.Empty).ToString()); var methodDoxygenCustomTags = @class.Methods.First(m => m.Name == "glfwDestroyWindow"); new CleanCommentsPass().VisitFull(methodDoxygenCustomTags.Comment.FullComment); textGenerator.StringBuilder.Clear(); textGenerator.Print(methodDoxygenCustomTags.Comment.FullComment, CommentKind.BCPLSlash); Assert.AreEqual(@"/// <summary>Destroys the specified window and its context.</summary> /// <param name=""window"">The window to destroy.</param> /// <remarks> /// <para>This function destroys the specified window and its context. On calling</para> /// <para>this function, no further callbacks will be called for that window.</para> /// <para>If the context of the specified window is current on the main thread, it is</para> /// <para>detached before being destroyed.</para> /// <para>The context of the specified window must not be current on any other</para> /// <para>thread when this function is called.</para> /// <para>This function must not be called from a callback.</para> /// <para>This function must only be called from the main thread.</para> /// <para>Added in version 3.0. Replaces `glfwCloseWindow`.</para> /// </remarks> ".Replace("\r", string.Empty), textGenerator.StringBuilder.Replace("\r", string.Empty).ToString()); }