girst-signature.c 34.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* girst-signature.c
 *
 * Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define G_LOG_DOMAIN "girst-signature"

#include <string.h>

23 24
#include "c-parse-helper.h"

25 26
#include "girst-cache.h"
#include "girst-signature.h"
27
#include "girst-util.h"
28 29

#include "parser/girst-alias.h"
30
#include "parser/girst-bitfield.h"
31
#include "parser/girst-array.h"
32
#include "parser/girst-callback.h"
33
#include "parser/girst-class.h"
34
#include "parser/girst-constant.h"
35
#include "parser/girst-constructor.h"
Christian Hergert's avatar
Christian Hergert committed
36
#include "parser/girst-doc.h"
37
#include "parser/girst-enumeration.h"
38
#include "parser/girst-function.h"
39
#include "parser/girst-glib-signal.h"
40
#include "parser/girst-implements.h"
41
#include "parser/girst-interface.h"
42
#include "parser/girst-member.h"
43 44 45
#include "parser/girst-method.h"
#include "parser/girst-namespace.h"
#include "parser/girst-parameter.h"
46
#include "parser/girst-parser-types.h"
Christian Hergert's avatar
Christian Hergert committed
47
#include "parser/girst-prerequisite.h"
48
#include "parser/girst-property.h"
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include "parser/girst-record.h"
#include "parser/girst-return-value.h"
#include "parser/girst-type.h"
#include "parser/girst-varargs.h"
#include "parser/girst-virtual-method.h"

static gpointer
find_ancestor (GirstParserObject *obj,
               GType              type)
{
  while (obj && !g_type_is_a (G_OBJECT_TYPE (obj), type))
    obj = girst_parser_object_get_parent (obj);
  return obj;
}

64 65 66 67 68 69 70 71 72 73
static const gchar *
find_namespace_name (GirstParserObject *obj)
{
  if (obj && !GIRST_IS_NAMESPACE (obj))
    obj = find_ancestor (obj, GIRST_TYPE_NAMESPACE);
  if (obj)
    return girst_namespace_get_name (GIRST_NAMESPACE (obj));
  return NULL;
}

Christian Hergert's avatar
Christian Hergert committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87
static const gchar *
find_object_c_type (GirstParserObject *obj)
{
  while (obj && !GIRST_IS_CLASS (obj) && !GIRST_IS_INTERFACE (obj) && !GIRST_IS_RECORD (obj))
    obj = girst_parser_object_get_parent (obj);
  if (GIRST_IS_CLASS (obj))
    return girst_class_get_c_type (GIRST_CLASS (obj));
  if (GIRST_IS_INTERFACE (obj))
    return girst_interface_get_c_type (GIRST_INTERFACE (obj));
  if (GIRST_IS_RECORD (obj))
    return girst_record_get_c_type (GIRST_RECORD (obj));
  return NULL;
}

88 89 90 91 92 93 94 95
static GirstParserObject *
find_ctor_parent (GirstParserObject *obj)
{
  while (obj && !GIRST_IS_CLASS (obj) && !GIRST_IS_RECORD (obj) && !GIRST_IS_INTERFACE (obj))
    obj = girst_parser_object_get_parent (obj);
  return obj;
}

Christian Hergert's avatar
Christian Hergert committed
96
#if 0
97 98 99 100 101 102 103
static GirstParserObject *
find_enumlike_parent (GirstParserObject *obj)
{
  while (obj && !GIRST_IS_ENUMERATION (obj) && !GIRST_IS_BITFIELD (obj))
    obj = girst_parser_object_get_parent (obj);
  return obj;
}
Christian Hergert's avatar
Christian Hergert committed
104
#endif
105

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
static GirstParserObject *
girst_resolve (GirstParserObject *relative,
               const gchar       *name)
{
  g_autofree gchar *freeme = NULL;
  GirstNamespace *nsobj;
  const gchar *dot;
  const gchar *ns = NULL;

  if (name == NULL || relative == NULL)
    return NULL;

  nsobj = find_ancestor (relative, GIRST_TYPE_NAMESPACE);
  if (nsobj != NULL)
    ns = girst_namespace_get_name (nsobj);

  if (NULL != (dot = strchr (name, '.')))
    {
      ns = freeme = g_strndup (name, dot - name);
      name = dot + 1;
    }

  return girst_cache_resolve (ns, name);
}

gchar *
132
girst_return_value_get_lhs_ctype (GirstReturnValue *self)
133 134 135 136 137 138
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_RETURN_VALUE (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_ARRAY)))
139
    return girst_array_get_lhs_ctype (GIRST_ARRAY (obj));
140 141

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
142
    return girst_type_get_lhs_ctype (GIRST_TYPE (obj));
143 144 145 146 147

  return g_strdup ("void");
}

gchar *
148
girst_alias_get_lhs_ctype (GirstAlias *self)
149 150 151 152 153 154 155
{
  g_return_val_if_fail (GIRST_IS_ALIAS (self), NULL);

  return g_strdup (girst_alias_get_c_type (self));
}

gchar *
156
girst_array_get_lhs_ctype (GirstArray *self)
157 158 159 160 161 162 163 164 165 166 167
{
  GirstParserObject *obj;
  const gchar *c_type;

  g_return_val_if_fail (GIRST_IS_ARRAY (self), NULL);

  if ((c_type = girst_array_get_c_type (self)))
    return g_strdup (c_type);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
    {
168
      g_autofree gchar *res = girst_type_get_lhs_ctype (GIRST_TYPE (obj));
169 170 171 172 173 174 175 176 177

      if (res != NULL)
        return g_strdup_printf ("%s*", res);
    }

  return NULL;
}

gchar *
178
girst_property_get_lhs_ctype (GirstProperty *self)
179 180 181 182 183 184
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_PROPERTY (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_ARRAY)))
185
    return girst_array_get_lhs_ctype (GIRST_ARRAY (obj));
186 187

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
188
    return girst_type_get_lhs_ctype (GIRST_TYPE (obj));
189 190 191 192 193

  return NULL;
}

gchar *
194
girst_parameter_get_lhs_ctype (GirstParameter *self)
195 196 197 198 199 200 201
{
  GirstParserObject *obj;
  g_autofree gchar *res = NULL;

  g_return_val_if_fail (GIRST_IS_PARAMETER (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_ARRAY)))
202
    res = girst_array_get_lhs_ctype (GIRST_ARRAY (obj));
203 204

  if (!res && (obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
205
    res = girst_type_get_lhs_ctype (GIRST_TYPE (obj));
206 207 208 209 210 211 212 213

  if (!res && (obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_VARARGS)))
    return g_strdup ("...");

  return g_steal_pointer (&res);
}

gchar *
214
girst_instance_parameter_get_lhs_ctype (GirstInstanceParameter *self)
215 216 217 218 219 220 221 222 223 224 225 226
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_INSTANCE_PARAMETER (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
    return g_strdup (girst_type_get_c_type (GIRST_TYPE (obj)));

  return NULL;
}

gchar *
227
girst_glib_signal_get_lhs_ctype (GirstGlibSignal *self)
228 229 230 231 232 233 234 235
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_GLIB_SIGNAL (self), NULL);

  obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_RETURN_VALUE);
  if (obj == NULL)
    return g_strdup ("void");
236
  return girst_return_value_get_lhs_ctype (GIRST_RETURN_VALUE (obj));
237 238 239
}

gchar *
240
girst_type_get_lhs_ctype (GirstType *self)
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
{
  GirstParserObject *obj;
  const gchar *c_type;
  const gchar *name;

  g_return_val_if_fail (GIRST_IS_TYPE (self), NULL);

  if ((c_type = girst_type_get_c_type (self)))
    return g_strdup (c_type);

  name = girst_type_get_name (self);

  if (g_strcmp0 (name, "utf8") == 0)
    return g_strdup ("gchar*");

  if ((obj = girst_resolve (GIRST_PARSER_OBJECT (self), name)))
    {
258
      g_autofree gchar *res = girst_parser_object_get_lhs_ctype (obj);
259 260 261 262 263 264 265 266 267 268

      if (GIRST_IS_RECORD (obj) ||
          GIRST_IS_CLASS (obj) ||
          GIRST_IS_INTERFACE (obj) ||
          GIRST_IS_UNION (obj) ||
          GIRST_IS_IMPLEMENTS (obj) ||
          GIRST_IS_PREREQUISITE (obj))
        return g_strdup_printf ("%s*", res);

      return g_steal_pointer (&res);
269 270 271 272 273 274
    }

  return NULL;
}

gchar *
275
girst_record_get_lhs_ctype (GirstRecord *self)
276 277 278 279 280 281
{
  g_return_val_if_fail (GIRST_IS_RECORD (self), NULL);

  return g_strdup (girst_record_get_c_type (self));
}

282 283 284 285 286 287 288 289
gchar *
girst_constructor_get_lhs_ctype (GirstConstructor *self)
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_CONSTRUCTOR (self), NULL);

  if ((obj = find_ctor_parent (GIRST_PARSER_OBJECT (self))))
290 291 292 293 294
    {
      g_autofree gchar *res = girst_parser_object_get_lhs_ctype (obj);

      return g_strdup_printf ("%s*", res);
    }
295 296 297 298 299 300 301 302 303 304 305 306

  return g_strdup ("void");
}

static GirstParserObject *
girst_constructor_get_lhs (GirstConstructor *self)
{
  g_return_val_if_fail (GIRST_IS_CONSTRUCTOR (self), NULL);

  return find_ctor_parent (GIRST_PARSER_OBJECT (self));
}

307
gchar *
308
girst_function_get_lhs_ctype (GirstFunction *self)
309 310 311 312 313 314
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_FUNCTION (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_RETURN_VALUE)))
315
    return girst_return_value_get_lhs_ctype (GIRST_RETURN_VALUE (obj));
316 317 318 319 320

  return g_strdup ("void");
}

gchar *
321
girst_method_get_lhs_ctype (GirstMethod *self)
322 323 324 325 326 327
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_METHOD (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_RETURN_VALUE)))
328
    return girst_return_value_get_lhs_ctype (GIRST_RETURN_VALUE (obj));
329 330 331 332 333

  return g_strdup ("void");
}

gchar *
334
girst_virtual_method_get_lhs_ctype (GirstVirtualMethod *self)
335 336 337 338 339 340
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_VIRTUAL_METHOD (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_RETURN_VALUE)))
341
    return girst_return_value_get_lhs_ctype (GIRST_RETURN_VALUE (obj));
342 343 344 345 346

  return g_strdup ("void");
}

gchar *
347
girst_callback_get_lhs_ctype (GirstCallback *self)
348 349 350 351 352 353
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_CALLBACK (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_RETURN_VALUE)))
354
    return girst_return_value_get_lhs_ctype (GIRST_RETURN_VALUE (obj));
355 356 357 358

  return g_strdup ("void");
}

359 360 361 362 363 364 365 366 367 368 369 370 371
gchar *
girst_constant_get_lhs_ctype (GirstConstant *self)
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_CONSTANT (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
    return girst_type_get_lhs_ctype (GIRST_TYPE (obj));

  return NULL;
}

372
gchar *
373
girst_class_get_lhs_ctype (GirstClass *self)
374 375 376 377 378 379 380
{
  g_return_val_if_fail (GIRST_IS_CLASS (self), NULL);

  return g_strdup (girst_class_get_c_type (self));
}

gchar *
381
girst_interface_get_lhs_ctype (GirstInterface *self)
382 383 384 385 386 387
{
  g_return_val_if_fail (GIRST_IS_INTERFACE (self), NULL);

  return g_strdup (girst_interface_get_c_type (self));
}

388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
gchar *
girst_enumeration_get_lhs_ctype (GirstEnumeration *self)
{
  g_return_val_if_fail (GIRST_IS_ENUMERATION (self), NULL);

  return g_strdup (girst_enumeration_get_c_type (self));
}

gchar *
girst_member_get_lhs_ctype (GirstMember *self)
{
  g_return_val_if_fail (GIRST_IS_MEMBER (self), NULL);

  return g_strdup (girst_member_get_c_identifier (self));
}

gchar *
girst_bitfield_get_lhs_ctype (GirstBitfield *self)
{
Christian Hergert's avatar
Christian Hergert committed
407
  g_return_val_if_fail (GIRST_IS_BITFIELD (self), NULL);
408 409 410 411

  return g_strdup (girst_bitfield_get_c_type (self));
}

Christian Hergert's avatar
Christian Hergert committed
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
gchar *
girst_prerequisite_get_lhs_ctype (GirstPrerequisite *self)
{
  GirstParserObject *obj;
  const gchar *name;

  g_return_val_if_fail (GIRST_IS_PREREQUISITE (self), NULL);

  name = girst_prerequisite_get_name (self);
  obj = girst_resolve (GIRST_PARSER_OBJECT (self), name);
  if (obj != NULL)
    return girst_parser_object_get_lhs_ctype (obj);

  return NULL;
}

428 429 430 431 432 433 434 435 436 437 438 439 440
gchar *
girst_implements_get_lhs_ctype (GirstImplements *self)
{
  GirstParserObject *obj;
  const gchar *name;

  g_return_val_if_fail (GIRST_IS_IMPLEMENTS (self), NULL);

  name = girst_implements_get_name (self);
  obj = girst_resolve (GIRST_PARSER_OBJECT (self), name);
  if (obj != NULL)
    return girst_parser_object_get_lhs_ctype (obj);

441
  return g_strdup (name);
442 443
}

444
gchar *
445
girst_varargs_get_lhs_ctype (GirstVarargs *self)
446 447 448 449 450
{
  return g_strdup ("...");
}

gchar *
451
girst_parser_object_get_lhs_ctype (GirstParserObject *self)
452 453 454 455
{
  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), NULL);

  if (GIRST_IS_ALIAS (self))
456
    return girst_alias_get_lhs_ctype (GIRST_ALIAS (self));
457 458

  if (GIRST_IS_ARRAY (self))
459
    return girst_array_get_lhs_ctype (GIRST_ARRAY (self));
460

461 462 463
  if (GIRST_IS_BITFIELD (self))
    return girst_bitfield_get_lhs_ctype (GIRST_BITFIELD (self));

464
  if (GIRST_IS_CALLBACK (self))
465
    return girst_callback_get_lhs_ctype (GIRST_CALLBACK (self));
466 467

  if (GIRST_IS_CLASS (self))
468
    return girst_class_get_lhs_ctype (GIRST_CLASS (self));
469 470

  if (GIRST_IS_FUNCTION (self))
471
    return girst_function_get_lhs_ctype (GIRST_FUNCTION (self));
472

473 474 475
  if (GIRST_IS_CONSTRUCTOR (self))
    return girst_constructor_get_lhs_ctype (GIRST_CONSTRUCTOR (self));

476
  if (GIRST_IS_GLIB_SIGNAL (self))
477
    return girst_glib_signal_get_lhs_ctype (GIRST_GLIB_SIGNAL (self));
478 479

  if (GIRST_IS_INSTANCE_PARAMETER (self))
480
    return girst_instance_parameter_get_lhs_ctype (GIRST_INSTANCE_PARAMETER (self));
481 482

  if (GIRST_IS_INTERFACE (self))
483
    return girst_interface_get_lhs_ctype (GIRST_INTERFACE (self));
484

485 486 487
  if (GIRST_IS_CONSTANT (self))
    return girst_constant_get_lhs_ctype (GIRST_CONSTANT (self));

488 489 490 491 492 493
  if (GIRST_IS_ENUMERATION (self))
    return girst_enumeration_get_lhs_ctype (GIRST_ENUMERATION (self));

  if (GIRST_IS_MEMBER (self))
    return girst_member_get_lhs_ctype (GIRST_MEMBER (self));

494
  if (GIRST_IS_METHOD (self))
495
    return girst_method_get_lhs_ctype (GIRST_METHOD (self));
496 497

  if (GIRST_IS_PARAMETER (self))
498
    return girst_parameter_get_lhs_ctype (GIRST_PARAMETER (self));
499 500

  if (GIRST_IS_PROPERTY (self))
501
    return girst_property_get_lhs_ctype (GIRST_PROPERTY (self));
502 503

  if (GIRST_IS_RECORD (self))
504
    return girst_record_get_lhs_ctype (GIRST_RECORD (self));
505 506

  if (GIRST_IS_RETURN_VALUE (self))
507
    return girst_return_value_get_lhs_ctype (GIRST_RETURN_VALUE (self));
508 509

  if (GIRST_IS_VIRTUAL_METHOD (self))
510
    return girst_virtual_method_get_lhs_ctype (GIRST_VIRTUAL_METHOD (self));
511

Christian Hergert's avatar
Christian Hergert committed
512 513 514
  if (GIRST_IS_PREREQUISITE (self))
    return girst_prerequisite_get_lhs_ctype (GIRST_PREREQUISITE (self));

515 516 517
  if (GIRST_IS_IMPLEMENTS (self))
    return girst_implements_get_lhs_ctype (GIRST_IMPLEMENTS (self));

518
  if (GIRST_IS_VARARGS (self))
519
    return girst_varargs_get_lhs_ctype (GIRST_VARARGS (self));
520 521 522 523 524

  g_warning ("Unknown dispatch: %s", G_OBJECT_TYPE_NAME (self));

  return NULL;
}
525 526 527 528 529

static GirstParserObject *
girst_array_get_lhs (GirstArray *self)
{
  GirstParserObject *obj;
530
  const gchar *name;
531 532 533

  g_return_val_if_fail (GIRST_IS_ARRAY (self), NULL);

534 535 536
  if ((name = girst_array_get_name (self)))
    return girst_resolve (GIRST_PARSER_OBJECT (self), name);

537 538
  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
    {
539
      name = girst_type_get_name (GIRST_TYPE (obj));
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
      return girst_resolve (obj, name);
    }

  return NULL;
}

static GirstParserObject *
girst_type_get_lhs (GirstType *self)
{
  const gchar *name;

  g_return_val_if_fail (GIRST_IS_TYPE (self), NULL);

  name = girst_type_get_name (self);
  return girst_resolve (GIRST_PARSER_OBJECT (self), name);
}

Christian Hergert's avatar
Christian Hergert committed
557 558 559 560 561 562 563 564 565 566 567
static GirstParserObject *
girst_prerequisite_get_lhs (GirstPrerequisite *self)
{
  const gchar *name;

  g_return_val_if_fail (GIRST_IS_PREREQUISITE (self), NULL);

  name = girst_prerequisite_get_name (self);
  return girst_resolve (GIRST_PARSER_OBJECT (self), name);
}

568 569 570 571 572 573 574 575 576 577 578
static GirstParserObject *
girst_implements_get_lhs (GirstImplements *self)
{
  const gchar *name;

  g_return_val_if_fail (GIRST_IS_IMPLEMENTS (self), NULL);

  name = girst_implements_get_name (self);
  return girst_resolve (GIRST_PARSER_OBJECT (self), name);
}

579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
static GirstParserObject *
girst_return_value_get_lhs (GirstReturnValue *self)
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_RETURN_VALUE (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_ARRAY)))
    return girst_array_get_lhs (GIRST_ARRAY (obj));

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
    return girst_type_get_lhs (GIRST_TYPE (obj));

  return NULL;
}

static GirstParserObject *
girst_typeish_get_lhs (GirstParserObject *self)
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_ARRAY)))
    return girst_array_get_lhs (GIRST_ARRAY (obj));

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_TYPE)))
    return girst_type_get_lhs (GIRST_TYPE (obj));

  return NULL;
}

static GirstParserObject *
girst_funcish_get_lhs (GirstParserObject *self)
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), NULL);

  if ((obj = girst_parser_object_first_typed (GIRST_PARSER_OBJECT (self), GIRST_TYPE_RETURN_VALUE)))
    return girst_return_value_get_lhs (GIRST_RETURN_VALUE (obj));

  return NULL;
}

/**
 * girst_parser_object_get_lhs:
 *
 * Returns: (transfer none): a parser object or %NULL
 */
GirstParserObject *
girst_parser_object_get_lhs (GirstParserObject *self)
{
  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), NULL);

  if (GIRST_IS_ARRAY (self))
    return girst_array_get_lhs (GIRST_ARRAY (self));

  if (GIRST_IS_CALLBACK (self))
    return girst_funcish_get_lhs (self);

  if (GIRST_IS_CLASS (self))
    return self;

643 644 645
  if (GIRST_IS_CONSTRUCTOR (self))
    return girst_constructor_get_lhs (GIRST_CONSTRUCTOR (self));

646 647 648 649 650 651
  if (GIRST_IS_BITFIELD (self))
    return self;

  if (GIRST_IS_ENUMERATION (self))
    return self;

652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
  if (GIRST_IS_FUNCTION (self))
    return girst_funcish_get_lhs (self);

  if (GIRST_IS_GLIB_SIGNAL (self))
    return girst_funcish_get_lhs (self);

  if (GIRST_IS_INSTANCE_PARAMETER (self))
    return girst_typeish_get_lhs (self);

  if (GIRST_IS_INTERFACE (self))
    return self;

  if (GIRST_IS_METHOD (self))
    return girst_funcish_get_lhs (self);

667 668 669
  if (GIRST_IS_MEMBER (self))
    return girst_typeish_get_lhs (self);

670 671 672 673 674 675
  if (GIRST_IS_PARAMETER (self))
    return girst_typeish_get_lhs (self);

  if (GIRST_IS_PROPERTY (self))
    return girst_typeish_get_lhs (self);

676 677 678
  if (GIRST_IS_IMPLEMENTS (self))
    return girst_implements_get_lhs (GIRST_IMPLEMENTS (self));

Christian Hergert's avatar
Christian Hergert committed
679 680 681
  if (GIRST_IS_PREREQUISITE (self))
    return girst_prerequisite_get_lhs (GIRST_PREREQUISITE (self));

682 683 684 685 686 687
  if (GIRST_IS_RECORD (self))
    return self;

  if (GIRST_IS_RETURN_VALUE (self))
    return girst_return_value_get_lhs (GIRST_RETURN_VALUE (self));

688 689 690
  if (GIRST_IS_CONSTANT (self))
    return girst_typeish_get_lhs (self);

691 692 693 694 695 696
  if (GIRST_IS_VIRTUAL_METHOD (self))
    return girst_funcish_get_lhs (self);

  return NULL;
}

697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
gchar *
girst_clink_full (const gchar       *word,
                  GirstParserObject *dest,
                  const gchar       *section)
{
  if (word == NULL)
    return NULL;

  if (section == NULL)
    section = "";

  /* If no link, do nothing */
  if (dest == NULL)
    return g_strdup (word);

  if (GIRST_IS_CLASS (dest))
    {
      const gchar *name = girst_class_get_c_type (GIRST_CLASS (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, name, section);
    }

  if (GIRST_IS_INTERFACE (dest))
    {
      const gchar *name = girst_interface_get_c_type (GIRST_INTERFACE (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, name, section);
    }

  if (GIRST_IS_ALIAS (dest))
    {
      const gchar *name = girst_alias_get_c_type (GIRST_ALIAS (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, name, section);
    }

  if (GIRST_IS_GLIB_SIGNAL (dest))
    {
      const gchar *name = girst_glib_signal_get_name (GIRST_GLIB_SIGNAL (dest));
      const gchar *c_type = find_object_c_type (dest);

      return g_strdup_printf (":ref:`%s <C:%s::%s%s>`", word, c_type, name, section);
    }

  if (GIRST_IS_PROPERTY (dest))
    {
      const gchar *name = girst_property_get_name (GIRST_PROPERTY (dest));
      const gchar *c_type = find_object_c_type (dest);

      return g_strdup_printf (":ref:`%s <C:%s:%s%s>`", word, c_type, name, section);
    }

  if (GIRST_IS_METHOD (dest))
    {
      const gchar *c_identifier = girst_method_get_c_identifier (GIRST_METHOD (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_identifier, section);
    }

  if (GIRST_IS_VIRTUAL_METHOD (dest))
    {
      const gchar *name = girst_virtual_method_get_name (GIRST_VIRTUAL_METHOD (dest));
      const gchar *c_type = find_object_c_type (dest);

      return g_strdup_printf (":ref:`%s <C:%s.%s%s>`", word, c_type, name, section);
    }

  if (GIRST_IS_ENUMERATION (dest))
    {
      const gchar *c_type = girst_enumeration_get_c_type (GIRST_ENUMERATION (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_type, section);
    }

  if (GIRST_IS_BITFIELD (dest))
    {
      const gchar *c_type = girst_bitfield_get_c_type (GIRST_BITFIELD (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_type, section);
    }

Christian Hergert's avatar
Christian Hergert committed
778 779 780 781 782 783 784
  if (GIRST_IS_CALLBACK (dest))
    {
      const gchar *c_type = girst_callback_get_c_type (GIRST_CALLBACK (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_type, section);
    }

785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
  if (GIRST_IS_MEMBER (dest))
    {
      const gchar *c_identifier = girst_member_get_c_identifier (GIRST_MEMBER (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_identifier, section);
    }

  if (GIRST_IS_FUNCTION (dest))
    {
      const gchar *c_identifier = girst_function_get_c_identifier (GIRST_FUNCTION (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_identifier, section);
    }

  if (GIRST_IS_CONSTRUCTOR (dest))
    {
      const gchar *c_identifier = girst_constructor_get_c_identifier (GIRST_CONSTRUCTOR (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_identifier, section);
    }

  if (GIRST_IS_CONSTANT (dest))
    {
      const gchar *c_type = girst_constant_get_c_type (GIRST_CONSTANT (dest));
      if (c_type == NULL)
        c_type = girst_constant_get_c_identifier (GIRST_CONSTANT (dest));
      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_type, section);
    }

  if (GIRST_IS_RECORD (dest))
    {
      const gchar *c_type = girst_record_get_c_type (GIRST_RECORD (dest));

      return g_strdup_printf (":ref:`%s <C:%s%s>`", word, c_type, section);
    }

  if (GIRST_IS_IMPLEMENTS (dest))
    {
      const gchar *name = girst_implements_get_name (GIRST_IMPLEMENTS (dest));
      GirstParserObject *obj = girst_resolve (dest, name);
      if (obj != NULL)
        return girst_clink (obj);
Christian Hergert's avatar
Christian Hergert committed
827
      return g_strdup (name);
828 829 830 831
    }

  if (GIRST_IS_NAMESPACE (dest))
    {
832 833
      const gchar *name = girst_namespace_get_name (GIRST_NAMESPACE (dest));
      const gchar *version = girst_namespace_get_version (GIRST_NAMESPACE (dest));
834

835
      return g_strdup_printf (":ref:`%s <C:%s-%s%s>`", word, name, version, section);
836 837 838 839 840
    }

  return g_strdup (word);
}

841 842 843
gchar *
girst_clink (GirstParserObject *self)
{
844 845
  if (self == NULL)
    return NULL;
846 847 848

  if (GIRST_IS_CLASS (self))
    {
849
      const gchar *name = girst_class_get_c_type (GIRST_CLASS (self));
850

851
      return g_strdup_printf ("<C:%s>", name);
852 853 854 855
    }

  if (GIRST_IS_INTERFACE (self))
    {
856
      const gchar *name = girst_interface_get_c_type (GIRST_INTERFACE (self));
857

858
      return g_strdup_printf ("<C:%s>", name);
859 860 861 862
    }

  if (GIRST_IS_ALIAS (self))
    {
863
      const gchar *name = girst_alias_get_c_type (GIRST_ALIAS (self));
864

865
      return g_strdup_printf ("<C:%s>", name);
866 867 868 869 870
    }

  if (GIRST_IS_GLIB_SIGNAL (self))
    {
      const gchar *name = girst_glib_signal_get_name (GIRST_GLIB_SIGNAL (self));
871
      const gchar *c_type = find_object_c_type (self);
872

873
      return g_strdup_printf ("<C:%s::%s>", c_type, name);
874 875 876 877 878
    }

  if (GIRST_IS_PROPERTY (self))
    {
      const gchar *name = girst_property_get_name (GIRST_PROPERTY (self));
Christian Hergert's avatar
Christian Hergert committed
879
      const gchar *c_type = find_object_c_type (self);
880

Christian Hergert's avatar
Christian Hergert committed
881
      return g_strdup_printf ("<C:%s:%s>", c_type, name);
882 883 884 885
    }

  if (GIRST_IS_METHOD (self))
    {
Christian Hergert's avatar
Christian Hergert committed
886
      const gchar *c_identifier = girst_method_get_c_identifier (GIRST_METHOD (self));
887

Christian Hergert's avatar
Christian Hergert committed
888
      return g_strdup_printf ("<C:%s>", c_identifier);
889 890 891 892 893
    }

  if (GIRST_IS_VIRTUAL_METHOD (self))
    {
      const gchar *name = girst_virtual_method_get_name (GIRST_VIRTUAL_METHOD (self));
894
      const gchar *c_type = find_object_c_type (self);
895

896
      return g_strdup_printf ("<C:%s.%s>", c_type, name);
897 898 899 900
    }

  if (GIRST_IS_ENUMERATION (self))
    {
Christian Hergert's avatar
Christian Hergert committed
901
      const gchar *c_type = girst_enumeration_get_c_type (GIRST_ENUMERATION (self));
902

Christian Hergert's avatar
Christian Hergert committed
903
      return g_strdup_printf ("<C:%s>", c_type);
904 905 906 907
    }

  if (GIRST_IS_BITFIELD (self))
    {
908
      const gchar *name = girst_bitfield_get_c_type (GIRST_BITFIELD (self));
909

910
      return g_strdup_printf ("<C:%s>", name);
911 912 913 914
    }

  if (GIRST_IS_MEMBER (self))
    {
Christian Hergert's avatar
Christian Hergert committed
915 916
      const gchar *c_identifier = girst_member_get_c_identifier (GIRST_MEMBER (self));
      return g_strdup_printf ("<C:%s>", c_identifier);
917 918 919 920
    }

  if (GIRST_IS_FUNCTION (self))
    {
Christian Hergert's avatar
Christian Hergert committed
921
      const gchar *c_identifier = girst_function_get_c_identifier (GIRST_FUNCTION (self));
922

Christian Hergert's avatar
Christian Hergert committed
923
      return g_strdup_printf ("<C:%s>", c_identifier);
924 925
    }

926 927
  if (GIRST_IS_CONSTRUCTOR (self))
    {
928
      const gchar *name = girst_constructor_get_c_identifier (GIRST_CONSTRUCTOR (self));
929

930
      return g_strdup_printf ("<C:%s>", name);
931 932
    }

933 934 935
  if (GIRST_IS_CONSTANT (self))
    {
      const gchar *name = girst_constant_get_c_type (GIRST_CONSTANT (self));
936 937 938
      if (name == NULL)
        name = girst_constant_get_c_identifier (GIRST_CONSTANT (self));
      return g_strdup_printf ("<C:%s>", name);
939 940
    }

941 942
  if (GIRST_IS_RECORD (self))
    {
943
      const gchar *c_type = girst_record_get_c_type (GIRST_RECORD (self));
944
      const gchar *peer = girst_record_get_glib_is_gtype_struct_for (GIRST_RECORD (self));
945
      GirstParserObject *obj;
946

947 948 949
      /* Prefer the object instance over class */
      if ((obj = girst_resolve (self, peer)))
        return girst_clink (obj);
950

951
      return g_strdup_printf ("<C:%s>", c_type);
952 953
    }

954 955 956 957 958 959 960 961 962
  if (GIRST_IS_IMPLEMENTS (self))
    {
      const gchar *name = girst_implements_get_name (GIRST_IMPLEMENTS (self));
      GirstParserObject *obj = girst_resolve (self, name);
      if (obj != NULL)
        return girst_clink (obj);
      return NULL;
    }

963 964 965 966
  if (GIRST_IS_NAMESPACE (self))
    {
      const gchar *nsname = find_namespace_name (self);

967
      return g_strdup_printf ("<C:%s>", nsname);
968 969 970 971
    }

  return NULL;
}
972 973 974 975 976 977 978 979 980

gboolean
girst_parser_object_has_parent_type (GirstParserObject *self)
{
  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), FALSE);

  return GIRST_IS_CLASS (self) &&
         !girst_str_empty0 (girst_class_get_parent (GIRST_CLASS (self)));
}
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036

static gboolean
girst_parser_object_has_or_parent_has (GirstParserObject *self,
                                       GType              type)
{
  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), FALSE);

  if (girst_parser_object_has_child_typed (self, type))
    return TRUE;

  if (GIRST_IS_CLASS (self))
    {
      g_autoptr(GListModel) parents = girst_class_get_parents (GIRST_CLASS (self));
      guint n_items = g_list_model_get_n_items (parents);

      for (guint i = 0; i < n_items; i++)
        {
          g_autoptr(GirstParserObject) parent = g_list_model_get_item (parents, i);

          if (girst_parser_object_has_child_typed (parent, type))
            return TRUE;
        }
    }

  return FALSE;
}

gboolean
girst_parser_object_has_signals (GirstParserObject *self)
{
  return girst_parser_object_has_or_parent_has (self, GIRST_TYPE_GLIB_SIGNAL);
}

gboolean
girst_parser_object_has_vfuncs (GirstParserObject *self)
{
  return girst_parser_object_has_or_parent_has (self, GIRST_TYPE_VIRTUAL_METHOD);
}

gboolean
girst_parser_object_has_props (GirstParserObject *self)
{
  return girst_parser_object_has_or_parent_has (self, GIRST_TYPE_PROPERTY);
}

gboolean
girst_parser_object_has_methods (GirstParserObject *self)
{
  return girst_parser_object_has_or_parent_has (self, GIRST_TYPE_METHOD);
}

gboolean
girst_parser_object_has_functions (GirstParserObject *self)
{
  return girst_parser_object_has_or_parent_has (self, GIRST_TYPE_FUNCTION);
}
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069

/**
 * girst_parser_object_get_parameters:
 *
 * Returns: (transfer full): A #GListModel
 */
GListModel *
girst_parser_object_get_parameters (GirstParserObject *self)
{
  GListStore *store;
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), NULL);

  store = g_list_store_new (GIRST_TYPE_PARSER_OBJECT);

  obj = girst_parser_object_first_typed (self, GIRST_TYPE_PARAMETERS);

  if (obj != NULL)
    {
      GPtrArray *ar = girst_parser_object_get_children (obj);

      for (guint i = 0; i < ar->len; i++)
        {
          GirstParserObject *child = g_ptr_array_index (ar, i);

          if (GIRST_IS_INSTANCE_PARAMETER (child) || GIRST_IS_PARAMETER (child))
            g_list_store_append (store, child);
        }
    }

  return G_LIST_MODEL (store);
}
Christian Hergert's avatar
Christian Hergert committed
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082

gchar *
girst_parser_object_short_cdoc (GirstParserObject *self)
{
  GirstParserObject *obj;

  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), NULL);

  if ((obj = girst_parser_object_first_typed (self, GIRST_TYPE_DOC)))
    return girst_one_line (girst_doc_get_inner_text (GIRST_DOC (obj)), GIRST_LANGUAGE_C);

  return NULL;
}
1083

1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
static gchar *
format_parameter (const Parameter *param,
                  guint            max_type,
                  guint            max_star)
{
  GString *str;
  guint i;

  if (param->ellipsis)
    return g_strdup ("...");

  str = g_string_new (param->type);

  for (i = str->len; i < max_type; i++)
    g_string_append_c (str, ' ');

  g_string_append_c (str, ' ');

  for (i = max_star; i > 0; i--)
    {
      if (i <= param->n_star)
        g_string_append_c (str, '*');
      else
        g_string_append_c (str, ' ');
    }

  g_string_append (str, param->name);

  return g_string_free (str, FALSE);
}

static gchar *
reformat_parameters (const gchar *input,
                     guint        prefix)
{
  GSList *params = parse_parameters (input);
  g_autoptr(GString) join = g_string_new (",\n");
  GString *str = g_string_new (NULL);
  guint max_star = 0;
  guint max_type = 0;

  if (girst_str_empty0 (input) || girst_str_equal0 (input, "void"))
    {
      g_string_append (str, "void");
      goto finish;
    }

  for (guint i = 0; i < prefix; i++)
    g_string_append_c (join, ' ');

  for (const GSList *iter = params; iter; iter = iter->next)
    {
      Parameter *p = iter->data;

      if (p->n_star)
        max_star = MAX (max_star, p->n_star);
      if (p->type)
        max_type = MAX (max_type, strlen (p->type));
    }

  for (const GSList *iter = params; iter; iter = iter->next)
    {
      g_autofree gchar *param_str = NULL;

      if (iter != params)
        g_string_append_len (str, join->str, join->len);
      param_str = format_parameter (iter->data, max_type, max_star);
      g_string_append (str, param_str);
    }

finish:
  g_slist_free_full (params, (GDestroyNotify)parameter_free);
  return g_string_free (str, FALSE);
}

1159 1160 1161 1162
gchar *
girst_parser_object_get_signature (GirstParserObject *self)
{
  g_autoptr(GString) str = NULL;
1163
  g_autoptr(GString) param_str = NULL;
1164
  const gchar *container_c_type = NULL;
1165
  g_autofree gchar *formatted = NULL;
1166 1167
  GirstParserObject *return_value;
  GirstParserObject *params;
1168 1169
  guint space = 0;
  guint begin;
1170 1171 1172 1173 1174

  g_return_val_if_fail (GIRST_IS_PARSER_OBJECT (self), NULL);

  if (!GIRST_IS_FUNCTION (self) &&
      !GIRST_IS_CALLBACK (self) &&
1175
      !GIRST_IS_CONSTRUCTOR (self) &&
1176
      !GIRST_IS_GLIB_SIGNAL (self) &&
1177 1178 1179 1180
      !GIRST_IS_VIRTUAL_METHOD (self) &&
      !GIRST_IS_METHOD (self))
    return NULL;

1181 1182
  container_c_type = find_object_c_type (self);

1183
  str = g_string_new (NULL);
1184
  param_str = g_string_new (NULL);
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198

  /* 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");
    }

1199 1200
  g_string_append (str, "\n   ");
  begin = str->len;
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217

  /* 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));

1218 1219 1220 1221 1222 1223
      g_string_append_printf (str, "%s ", c_identifier);
    }
  else if (GIRST_IS_CONSTRUCTOR (self))
    {
      const gchar *c_identifier = girst_constructor_get_c_identifier (GIRST_CONSTRUCTOR (self));

1224 1225 1226 1227 1228 1229 1230 1231
      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);
    }
1232 1233 1234 1235
  else if (GIRST_IS_GLIB_SIGNAL (self))
    {
      g_string_append (str, "user_function ");
    }
Christian Hergert's avatar
Christian Hergert committed
1236
  else if (GIRST_IS_VIRTUAL_METHOD (self))
1237
    {
Christian Hergert's avatar
Christian Hergert committed
1238
      const gchar *c_identifier = girst_virtual_method_get_c_identifier (GIRST_VIRTUAL_METHOD (self));
1239
      const gchar *name = girst_virtual_method_get_name (GIRST_VIRTUAL_METHOD (self));
1240

1241 1242 1243 1244
      if (c_identifier != NULL)
        g_string_append_printf (str, "%s ", c_identifier);
      else
        g_string_append_printf (str, "(*%s) ", name);
1245 1246 1247 1248 1249 1250
    }
  else
    g_return_val_if_reached (NULL);

  g_string_append_c (str, '(');

1251 1252 1253 1254 1255 1256 1257
  space = str->len - begin;

  /* XXX: Until we have a better way to ensure this
   *      is indented from the template code.
   */
  space += 3;

1258 1259
  params = girst_parser_object_first_typed (self, GIRST_TYPE_PARAMETERS);

1260 1261 1262 1263 1264
  if (GIRST_IS_GLIB_SIGNAL (self))
    {
      g_string_append_printf (param_str, "%s *self, ", container_c_type);
    }
  else if (params == NULL)
1265 1266 1267 1268 1269
    {
      g_string_append (str, "void");
      goto cleanup;
    }

1270
  if (params != NULL)
1271
    {
1272
      GPtrArray *children;
1273

1274
      children = girst_parser_object_get_children (params);
1275

1276
      for (guint i = 0; i < children->len; i++)
1277
        {
1278 1279 1280 1281 1282 1283 1284 1285
          GirstParserObject *child = g_ptr_array_index (children, i);
          g_autofree gchar *c_type = NULL;
          g_autofree gchar *name = NULL;

          if (!GIRST_IS_PARAMETER (child) &&
              !GIRST_IS_INSTANCE_PARAMETER (child) &&
              !GIRST_IS_VARARGS (child))
            continue;
1286

1287
          g_string_append_c (param_str, ' ');
1288

1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
          if (GIRST_IS_VARARGS (child))
            {
              g_string_append (param_str, "...");
              break;
            }

          g_object_get (child, "name", &name, NULL);
          c_type = girst_parser_object_get_lhs_ctype (child);

          g_string_append_printf (param_str, "%s %s, ", c_type, name);
        }
1300 1301
    }

1302 1303 1304
  if (GIRST_IS_GLIB_SIGNAL (self))
    g_string_append (param_str, "gpointer user_data, ");

1305 1306 1307 1308 1309
  if (param_str->len > 2)
    g_string_truncate (param_str, param_str->len - 2);

  formatted = reformat_parameters (param_str->str, space);
  g_string_append (str, formatted);
1310 1311

cleanup:
Christian Hergert's avatar
Christian Hergert committed
1312
  g_string_append (str, ");");
1313 1314 1315

  return g_string_free (g_steal_pointer (&str), FALSE);
}