Commit 5180534d authored by Christian Hergert's avatar Christian Hergert

signature: start on basic signature definitions

Still needs lots of work and tweaks for some situations. Needs parameter
formatting code from Builder too.
parent c91e5175
......@@ -27,6 +27,7 @@
#include "parser/girst-alias.h"
#include "parser/girst-bitfield.h"
#include "parser/girst-array.h"
#include "parser/girst-callback.h"
#include "parser/girst-class.h"
#include "parser/girst-constant.h"
#include "parser/girst-constructor.h"
......@@ -1075,3 +1076,111 @@ girst_parser_object_short_cdoc (GirstParserObject *self)
return NULL;
}
gchar *
girst_parser_object_get_signature (GirstParserObject *self)
{
g_autoptr(GString) str = NULL;
GirstParserObject *return_value;
GirstParserObject *params;
GPtrArray *children;
g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), NULL);
if (!GIRST_IS_FUNCTION (self) &&
!GIRST_IS_CALLBACK (self) &&
!GIRST_IS_VIRTUAL_METHOD (self) &&
!GIRST_IS_METHOD (self))
return NULL;
str = g_string_new (NULL);
/* Add our return type on a single line */
if ((return_value = girst_parser_object_first_typed (self, GIRST_TYPE_RETURN_VALUE)))
{
g_autofree gchar *return_c_type = girst_return_value_get_lhs_ctype (GIRST_RETURN_VALUE (return_value));
g_string_append (str, return_c_type);
}
else
{
g_string_append (str, "void");
}
g_string_append_c (str, '\n');
/* Now the function name (or callback/vtable definition) */
if (GIRST_IS_CALLBACK (self))
{
const gchar *c_type = girst_callback_get_c_type (GIRST_CALLBACK (self));
const gchar *name = girst_callback_get_name (GIRST_CALLBACK (self));
if (c_type != NULL)
g_string_append_printf (str, "(*%s) ", c_type);
else
g_string_append_printf (str, "%s ", name);
}
else if (GIRST_IS_FUNCTION (self))
{
const gchar *c_identifier = girst_function_get_c_identifier (GIRST_FUNCTION (self));
g_string_append_printf (str, "%s ", c_identifier);
}
else if (GIRST_IS_METHOD (self))
{
const gchar *c_identifier = girst_method_get_c_identifier (GIRST_METHOD (self));
g_string_append_printf (str, "%s ", c_identifier);
}
else if (GIRST_IS_METHOD (self))
{
const gchar *c_identifier = girst_method_get_c_identifier (GIRST_METHOD (self));
g_string_append_printf (str, "%s ", c_identifier);
}
else
g_return_val_if_reached (NULL);
g_string_append_c (str, '(');
params = girst_parser_object_first_typed (self, GIRST_TYPE_PARAMETERS);
if (params == NULL)
{
g_string_append (str, "void");
goto cleanup;
}
children = girst_parser_object_get_children (params);
for (guint i = 0; i < children->len; i++)
{
GirstParserObject *child = g_ptr_array_index (children, i);
g_autofree gchar *c_type = NULL;
g_autofree gchar *name = NULL;
if (GIRST_IS_VARARGS (child))
{
g_string_append (str, "...");
break;
}
if (!GIRST_IS_PARAMETER (child) && !GIRST_IS_INSTANCE_PARAMETER (child))
continue;
g_object_get (child, "name", &name, NULL);
c_type = girst_parser_object_get_lhs_ctype (child);
g_string_append_printf (str, "%s %s,", c_type, name);
}
if (str->str[str->len-1] == ',')
g_string_truncate (str, str->len - 1);
cleanup:
g_string_append_c (str, ')');
return g_string_free (g_steal_pointer (&str), FALSE);
}
......@@ -56,5 +56,6 @@ gboolean girst_parser_object_has_vfuncs (GirstParserObject
gboolean girst_parser_object_has_props (GirstParserObject *self);
gboolean girst_parser_object_has_methods (GirstParserObject *self);
gboolean girst_parser_object_has_functions (GirstParserObject *self);
gchar *girst_parser_object_get_signature (GirstParserObject *self);
G_END_DECLS
......@@ -8,6 +8,12 @@
{{end}}
.. code-block:: c
{{function.get_signature()}}
..
{{if function.has_child_typed(Girst.Doc)}}
{{function.first_typed(Girst.Doc).to_c(" ")}}
{{end}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment