]> Git Repo - binutils.git/blob - gdb/compile/compile-cplus-types.c
Remove duplicate or commented-out #includes
[binutils.git] / gdb / compile / compile-cplus-types.c
1 /* Convert types from GDB to GCC
2
3    Copyright (C) 2014-2019 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20
21 #include "defs.h"
22 #include "common/preprocessor.h"
23 #include "gdbtypes.h"
24 #include "compile-internal.h"
25 #include "compile-cplus.h"
26 #include "gdb_assert.h"
27 #include "symtab.h"
28 #include "source.h"
29 #include "cp-support.h"
30 #include "cp-abi.h"
31 #include "objfiles.h"
32 #include "block.h"
33 #include "gdbcmd.h"
34 #include "c-lang.h"
35 #include "compile-c.h"          /* Included for c_get_range_decl_name
36                                    et al.  */
37 #include <algorithm>
38
39 /* Default compile flags for C++.  */
40
41 const char *compile_cplus_instance::m_default_cflags = "-std=gnu++11";
42
43 /* Flag to enable internal debugging.  */
44
45 static int debug_compile_cplus_types = 0;
46
47 /* Flag to enable internal scope switching debugging.  */
48
49 static int debug_compile_cplus_scopes = 0;
50
51 /* Forward declarations.  */
52
53 static gcc_type compile_cplus_convert_func (compile_cplus_instance *instance,
54                                             struct type *type,
55                                             bool strip_artificial);
56
57 /* See description in compile-cplus.h.  */
58
59 gdb::unique_xmalloc_ptr<char>
60 compile_cplus_instance::decl_name (const char *natural)
61 {
62   if (natural == nullptr)
63     return nullptr;
64
65   gdb::unique_xmalloc_ptr<char> name = cp_func_name (natural);
66   if (name != nullptr)
67     return name;
68
69   return gdb::unique_xmalloc_ptr<char> (xstrdup (natural));
70 }
71
72 /* Get the access flag for the NUM'th field of TYPE.  */
73
74 static enum gcc_cp_symbol_kind
75 get_field_access_flag (const struct type *type, int num)
76 {
77   if (TYPE_FIELD_PROTECTED (type, num))
78     return GCC_CP_ACCESS_PROTECTED;
79   else if (TYPE_FIELD_PRIVATE (type, num))
80     return GCC_CP_ACCESS_PRIVATE;
81
82   /* GDB assumes everything else is public.  */
83   return GCC_CP_ACCESS_PUBLIC;
84 }
85
86 /* Get the access flag for the NUM'th method of TYPE's FNI'th
87    fieldlist.  */
88
89 enum gcc_cp_symbol_kind
90 get_method_access_flag (const struct type *type, int fni, int num)
91 {
92   gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
93
94   /* If this type was not declared a class, everything is public.  */
95   if (!TYPE_DECLARED_CLASS (type))
96     return GCC_CP_ACCESS_PUBLIC;
97
98   /* Otherwise, read accessibility from the fn_field.  */
99   const struct fn_field *methods = TYPE_FN_FIELDLIST1 (type, fni);
100   if (TYPE_FN_FIELD_PROTECTED (methods, num))
101     return GCC_CP_ACCESS_PROTECTED;
102   else if (TYPE_FN_FIELD_PRIVATE (methods, num))
103     return GCC_CP_ACCESS_PRIVATE;
104   else
105     return GCC_CP_ACCESS_PUBLIC;
106 }
107
108 /* A useful debugging function to output the scope SCOPE to stdout.  */
109
110 static void __attribute__ ((used))
111 debug_print_scope (const compile_scope &scope)
112 {
113   for (const auto &comp: scope)
114     {
115       const char *symbol = (comp.bsymbol.symbol != nullptr
116                             ? SYMBOL_NATURAL_NAME (comp.bsymbol.symbol)
117                             : "<none>");
118
119       printf_unfiltered ("\tname = %s, symbol = %s\n", comp.name.c_str (),
120                          symbol);
121     }
122 }
123
124 /* See description in compile-cplus.h.  */
125
126 compile_scope
127 type_name_to_scope (const char *type_name, const struct block *block)
128 {
129   compile_scope scope;
130
131   if (type_name == nullptr)
132     {
133       /* An anonymous type.  We cannot really do much here.  We simply cannot
134          look up anonymous types easily/at all.  */
135       return scope;
136     }
137
138   const char *p = type_name;
139   std::string lookup_name;
140
141   while (*p != '\0')
142     {
143       /* Create a string token of the first component of TYPE_NAME.  */
144       int len = cp_find_first_component (p);
145       std::string s (p, len);
146
147       /* Advance past the last token.  */
148       p += len;
149
150       /* Look up the symbol and decide when to stop.  */
151       if (!lookup_name.empty ())
152         lookup_name += "::";
153       lookup_name += s;
154
155       /* Look up the resulting name.  */
156       struct block_symbol bsymbol
157         = lookup_symbol (lookup_name.c_str (), block, VAR_DOMAIN, nullptr);
158
159       if (bsymbol.symbol != nullptr)
160         {
161           scope_component comp = {s, bsymbol};
162
163           scope.push_back (comp);
164
165           if (TYPE_CODE (SYMBOL_TYPE (bsymbol.symbol)) != TYPE_CODE_NAMESPACE)
166             {
167               /* We're done.  */
168               break;
169             }
170         }
171
172       if (*p == ':')
173         {
174           ++p;
175           if (*p == ':')
176             ++p;
177           else
178             {
179               /* This shouldn't happen since we are not attempting to
180                  loop over user input.  This name is generated by GDB
181                  from debug info.  */
182               internal_error (__FILE__, __LINE__,
183                               _("malformed TYPE_NAME during parsing"));
184             }
185         }
186     }
187
188   return scope;
189 }
190
191 /* Compare two scope_components for equality.  These are equal if the names
192    of the two components' are the same.  */
193
194 bool
195 operator== (const scope_component &lhs, const scope_component &rhs)
196 {
197   return lhs.name == rhs.name;
198 }
199
200 /* Compare two scope_components for inequality.  These are not equal if
201    the two components' names are not equal.  */
202
203 bool
204 operator!= (const scope_component &lhs, const scope_component &rhs)
205 {
206   return lhs.name != rhs.name;
207 }
208
209 /* Compare two compile_scopes for equality.  These are equal if they are both
210    contain the same number of components and each component is equal.  */
211
212 bool
213 operator== (const compile_scope &lhs, const compile_scope &rhs)
214 {
215   if (lhs.size () != rhs.size ())
216     return false;
217
218   for (int i = 0; i < lhs.size (); ++i)
219     {
220       if (lhs[i] != rhs[i])
221         return false;
222     }
223
224   return true;
225 }
226
227 /* Compare two compile_scopes for inequality.  These are inequal if they
228    contain unequal number of elements or if any of the components are not
229    the same.  */
230
231 bool
232 operator!= (const compile_scope &lhs, const compile_scope &rhs)
233 {
234   if (lhs.size () != rhs.size ())
235     return true;
236
237   for (int i = 0; i < lhs.size (); ++i)
238     {
239       if (lhs[i] != rhs[i])
240         return true;
241     }
242
243   return false;
244 }
245
246 /* See description in compile-cplus.h.  */
247
248 void
249 compile_cplus_instance::enter_scope (compile_scope &&new_scope)
250 {
251   bool must_push = m_scopes.empty () || m_scopes.back () != new_scope;
252
253   new_scope.m_pushed = must_push;
254
255   /* Save the new scope.  */
256   m_scopes.push_back (std::move (new_scope));
257
258   if (must_push)
259     {
260       if (debug_compile_cplus_scopes)
261         {
262           fprintf_unfiltered (gdb_stdlog, "entering new scope %s\n",
263                               host_address_to_string (&m_scopes.back ()));
264         }
265
266       /* Push the global namespace. */
267       plugin ().push_namespace ("");
268
269       /* Push all other namespaces.  Note that we do not push the last
270          scope_component -- that's the actual type we are converting.  */
271       std::for_each
272         (m_scopes.back ().begin (), m_scopes.back ().end () - 1,
273          [this] (const scope_component &comp)
274          {
275           gdb_assert (TYPE_CODE (SYMBOL_TYPE (comp.bsymbol.symbol))
276                       == TYPE_CODE_NAMESPACE);
277
278           const char *ns = (comp.name == CP_ANONYMOUS_NAMESPACE_STR ? nullptr
279                             : comp.name.c_str ());
280
281           this->plugin ().push_namespace (ns);
282          });
283     }
284   else
285     {
286       if (debug_compile_cplus_scopes)
287         {
288           fprintf_unfiltered (gdb_stdlog, "staying in current scope -- "
289                               "scopes are identical\n");
290         }
291     }
292 }
293
294 /* See description in compile-cplus.h.  */
295
296 void
297 compile_cplus_instance::leave_scope ()
298 {
299   /* Get the current scope and remove it from the internal list of
300      scopes.  */
301   compile_scope current = m_scopes.back ();
302
303   m_scopes.pop_back ();
304
305   if (current.m_pushed)
306     {
307       if (debug_compile_cplus_scopes)
308         {
309           fprintf_unfiltered (gdb_stdlog, "leaving scope %s\n",
310                               host_address_to_string (&current));
311         }
312
313       /* Pop namespaces.  */
314       std::for_each
315         (current.begin (),current.end () - 1,
316          [this] (const scope_component &comp) {
317           gdb_assert (TYPE_CODE (SYMBOL_TYPE (comp.bsymbol.symbol))
318                       == TYPE_CODE_NAMESPACE);
319           this->plugin ().pop_binding_level (comp.name.c_str ());
320         });
321
322       /* Pop global namespace.  */
323       plugin ().pop_binding_level ("");
324     }
325   else
326     {
327       if (debug_compile_cplus_scopes)
328         fprintf_unfiltered (gdb_stdlog,
329                             "identical scopes -- not leaving scope\n");
330     }
331 }
332
333 /* See description in compile-cplus.h.  */
334
335 compile_scope
336 compile_cplus_instance::new_scope (const char *type_name, struct type *type)
337 {
338   /* Break the type name into components.  If TYPE was defined in some
339      superclass, we do not process TYPE but process the enclosing type
340      instead.  */
341   compile_scope scope = type_name_to_scope (type_name, block ());
342
343   if (!scope.empty ())
344     {
345       /* Get the name of the last component, which should be the
346          unqualified name of the type to process.  */
347       scope_component &comp = scope.back ();
348
349       if (!types_equal (type, SYMBOL_TYPE (comp.bsymbol.symbol))
350           && (m_scopes.empty ()
351               || (m_scopes.back ().back ().bsymbol.symbol
352                   != comp.bsymbol.symbol)))
353         {
354           /* The type is defined inside another class(es).  Convert that
355              type instead of defining this type.  */
356           convert_type (SYMBOL_TYPE (comp.bsymbol.symbol));
357
358           /* If the original type (passed in to us) is defined in a nested
359              class, the previous call will give us that type's gcc_type.
360              Upper layers are expecting to get the original type's
361              gcc_type!  */
362           get_cached_type (type, &scope.m_nested_type);
363           return scope;
364         }
365     }
366   else
367     {
368       if (TYPE_NAME (type) == nullptr)
369         {
370           /* Anonymous type  */
371
372           /* We don't have a qualified name for this to look up, but
373              we need a scope.  We have to assume, then, that it is the same
374              as the current scope, if any.  */
375           if (!m_scopes.empty ())
376             {
377               scope = m_scopes.back ();
378               scope.m_pushed = false;
379             }
380           else
381             scope.push_back (scope_component ());
382         }
383       else
384         {
385           scope_component comp
386             = {
387                 decl_name (TYPE_NAME (type)).get (),
388                 lookup_symbol (TYPE_NAME (type), block (), VAR_DOMAIN, nullptr)
389               };
390           scope.push_back (comp);
391         }
392     }
393
394   /* There must be at least one component in the compile_scope.  */
395   gdb_assert (scope.size () > 0);
396   return scope;
397 }
398
399 /* See description in compile-cplus.h.  */
400
401 gcc_type
402 compile_cplus_instance::convert_reference_base
403   (gcc_type base, enum gcc_cp_ref_qualifiers rquals)
404 {
405   return this->plugin ().build_reference_type (base, rquals);
406 }
407
408 /* Convert a reference type to its gcc representation.  */
409
410 static gcc_type
411 compile_cplus_convert_reference (compile_cplus_instance *instance,
412                                  struct type *type)
413 {
414   gcc_type target = instance->convert_type (TYPE_TARGET_TYPE (type));
415
416   enum gcc_cp_ref_qualifiers quals = GCC_CP_REF_QUAL_NONE;
417   switch (TYPE_CODE (type))
418     {
419     case TYPE_CODE_REF:
420       quals = GCC_CP_REF_QUAL_LVALUE;
421       break;
422     case TYPE_CODE_RVALUE_REF:
423       quals = GCC_CP_REF_QUAL_RVALUE;
424       break;
425     default:
426       gdb_assert_not_reached ("unexpected type code for reference type");
427     }
428
429   return instance->convert_reference_base (target, quals);
430 }
431
432 /* See description in compile-cplus.h.  */
433
434 gcc_type
435 compile_cplus_instance::convert_pointer_base(gcc_type target)
436 {
437   return plugin ().build_pointer_type (target);
438 }
439
440 /* Convert a pointer type to its gcc representation.  */
441
442 static gcc_type
443 compile_cplus_convert_pointer (compile_cplus_instance *instance,
444                                struct type *type)
445 {
446   gcc_type target = instance->convert_type (TYPE_TARGET_TYPE (type));
447
448   return instance->convert_pointer_base (target);
449 }
450
451 /* Convert an array type to its gcc representation.  */
452
453 static gcc_type
454 compile_cplus_convert_array (compile_cplus_instance *instance,
455                              struct type *type)
456 {
457   struct type *range = TYPE_INDEX_TYPE (type);
458   gcc_type element_type = instance->convert_type (TYPE_TARGET_TYPE (type));
459
460   if (TYPE_LOW_BOUND_KIND (range) != PROP_CONST)
461     {
462       const char *s = _("array type with non-constant"
463                         " lower bound is not supported");
464
465       return instance->plugin ().error (s);
466     }
467
468   if (TYPE_LOW_BOUND (range) != 0)
469     {
470       const char *s = _("cannot convert array type with "
471                         "non-zero lower bound to C");
472
473       return instance->plugin ().error (s);
474     }
475
476   if (TYPE_HIGH_BOUND_KIND (range) == PROP_LOCEXPR
477       || TYPE_HIGH_BOUND_KIND (range) == PROP_LOCLIST)
478     {
479       if (TYPE_VECTOR (type))
480         {
481           const char *s = _("variably-sized vector type is not supported");
482
483           return instance->plugin ().error (s);
484         }
485
486       std::string upper_bound
487         = c_get_range_decl_name (&TYPE_RANGE_DATA (range)->high);
488       return instance->plugin ().build_vla_array_type (element_type,
489                                              upper_bound.c_str ());
490     }
491   else
492     {
493       LONGEST low_bound, high_bound, count;
494
495       if (get_array_bounds (type, &low_bound, &high_bound) == 0)
496         count = -1;
497       else
498         {
499           gdb_assert (low_bound == 0); /* Ensured above.  */
500           count = high_bound + 1;
501         }
502
503       if (TYPE_VECTOR (type))
504         return instance->plugin ().build_vector_type (element_type, count);
505
506       return instance->plugin ().build_array_type (element_type, count);
507     }
508 }
509
510 /* Convert a typedef of TYPE.  If not GCC_CP_ACCESS_NONE, NESTED_ACCESS
511    will define the accessibility of the typedef definition in its
512    containing class.  */
513
514 static gcc_type
515 compile_cplus_convert_typedef (compile_cplus_instance *instance,
516                                struct type *type,
517                                enum gcc_cp_symbol_kind nested_access)
518 {
519   compile_scope scope = instance->new_scope (TYPE_NAME (type), type);
520
521   if (scope.nested_type () != GCC_TYPE_NONE)
522     return scope.nested_type ();
523
524   gdb::unique_xmalloc_ptr<char> name
525     = compile_cplus_instance::decl_name (TYPE_NAME (type));
526
527   /* Make sure the scope for this type has been pushed.  */
528   instance->enter_scope (std::move (scope));
529
530   /* Convert the typedef's real type.  */
531   gcc_type typedef_type = instance->convert_type (check_typedef (type));
532
533   instance->plugin ().build_decl ("typedef", name.get (),
534                                   GCC_CP_SYMBOL_TYPEDEF | nested_access,
535                         typedef_type, 0, 0, nullptr, 0);
536
537   /* Completed this scope.  */
538   instance->leave_scope ();
539   return typedef_type;
540 }
541
542 /* Convert types defined in TYPE.  */
543
544 static void
545 compile_cplus_convert_type_defns (compile_cplus_instance *instance,
546                                   struct type *type)
547 {
548   int i;
549   enum gcc_cp_symbol_kind accessibility;
550
551   /* Convert typedefs.  */
552   for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); ++i)
553     {
554       if (TYPE_TYPEDEF_FIELD_PROTECTED (type, i))
555         accessibility = GCC_CP_ACCESS_PROTECTED;
556       else if (TYPE_TYPEDEF_FIELD_PRIVATE (type, i))
557         accessibility = GCC_CP_ACCESS_PRIVATE;
558       else
559         accessibility = GCC_CP_ACCESS_PUBLIC;
560       instance->convert_type (TYPE_TYPEDEF_FIELD_TYPE (type, i), accessibility);
561     }
562
563   /* Convert nested types.  */
564   for (i = 0; i < TYPE_NESTED_TYPES_COUNT (type); ++i)
565     {
566       if (TYPE_NESTED_TYPES_FIELD_PROTECTED (type, i))
567         accessibility = GCC_CP_ACCESS_PROTECTED;
568       else if (TYPE_NESTED_TYPES_FIELD_PRIVATE (type, i))
569         accessibility = GCC_CP_ACCESS_PRIVATE;
570       else
571         accessibility = GCC_CP_ACCESS_PUBLIC;
572       instance->convert_type (TYPE_NESTED_TYPES_FIELD_TYPE (type, i),
573                               accessibility);
574     }
575 }
576
577 /* Convert data members defined in TYPE, which should be struct/class/union
578    with gcc_type COMP_TYPE.  */
579
580 static void
581 compile_cplus_convert_struct_or_union_members
582   (compile_cplus_instance *instance, struct type *type, gcc_type comp_type)
583 {
584   for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); ++i)
585     {
586       const char *field_name = TYPE_FIELD_NAME (type, i);
587
588       if (TYPE_FIELD_IGNORE (type, i)
589           || TYPE_FIELD_ARTIFICIAL (type, i))
590         continue;
591
592       /* GDB records unnamed/anonymous fields with empty string names.  */
593       if (*field_name == '\0')
594         field_name = nullptr;
595
596       gcc_type field_type
597         = instance->convert_type (TYPE_FIELD_TYPE (type, i));
598
599       if (field_is_static (&TYPE_FIELD (type, i)))
600         {
601           CORE_ADDR physaddr;
602
603           switch (TYPE_FIELD_LOC_KIND (type, i))
604             {
605             case FIELD_LOC_KIND_PHYSADDR:
606               {
607                 physaddr = TYPE_FIELD_STATIC_PHYSADDR (type, i);
608
609                 instance->plugin ().build_decl
610                   ("field physaddr", field_name,
611                    (GCC_CP_SYMBOL_VARIABLE | get_field_access_flag (type, i)),
612                    field_type, nullptr, physaddr, nullptr, 0);
613               }
614               break;
615
616             case FIELD_LOC_KIND_PHYSNAME:
617               {
618                 const char *physname = TYPE_FIELD_STATIC_PHYSNAME (type, i);
619                 struct block_symbol sym
620                   = lookup_symbol (physname, instance->block (),
621                                    VAR_DOMAIN, nullptr);
622
623                 if (sym.symbol == nullptr)
624                   {
625                     /* We didn't actually find the symbol.  There's little
626                        we can do but ignore this member.  */
627                     continue;
628                   }
629                 const char *filename = symbol_symtab (sym.symbol)->filename;
630                 unsigned int line = SYMBOL_LINE (sym.symbol);
631
632                 physaddr = SYMBOL_VALUE_ADDRESS (sym.symbol);
633                 instance->plugin ().build_decl
634                   ("field physname", field_name,
635                    (GCC_CP_SYMBOL_VARIABLE| get_field_access_flag (type, i)),
636                    field_type, nullptr, physaddr, filename, line);
637               }
638               break;
639
640             default:
641               gdb_assert_not_reached
642                 ("unexpected static field location kind");
643             }
644         }
645       else
646         {
647           unsigned long bitsize = TYPE_FIELD_BITSIZE (type, i);
648           enum gcc_cp_symbol_kind field_flags = GCC_CP_SYMBOL_FIELD
649             | get_field_access_flag (type, i);
650
651           if (bitsize == 0)
652             bitsize = 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, i));
653
654           instance->plugin ().build_field
655             (field_name, field_type, field_flags, bitsize,
656              TYPE_FIELD_BITPOS (type, i));
657         }
658     }
659 }
660
661 /* Convert a method type to its gcc representation.  */
662
663 static gcc_type
664 compile_cplus_convert_method (compile_cplus_instance *instance,
665                               struct type *parent_type,
666                               struct type *method_type)
667 {
668   /* Get the actual function type of the method, the corresponding class's
669      type and corresponding qualifier flags.  */
670   gcc_type func_type = compile_cplus_convert_func (instance, method_type, true);
671   gcc_type class_type = instance->convert_type (parent_type);
672   gcc_cp_qualifiers_flags quals = (enum gcc_cp_qualifiers) 0;
673
674   if (TYPE_CONST (method_type))
675     quals |= GCC_CP_QUALIFIER_CONST;
676   if (TYPE_VOLATILE (method_type))
677     quals |= GCC_CP_QUALIFIER_VOLATILE;
678   if (TYPE_RESTRICT (method_type))
679     quals |= GCC_CP_QUALIFIER_RESTRICT;
680
681   /* Not yet implemented.  */
682   gcc_cp_ref_qualifiers_flags rquals = GCC_CP_REF_QUAL_NONE;
683
684   return instance->plugin ().build_method_type
685     (class_type, func_type, quals, rquals);
686 }
687
688 /* Convert a member or method pointer represented by TYPE.  */
689
690 static gcc_type
691 compile_cplus_convert_memberptr (compile_cplus_instance *instance,
692                                  struct type *type)
693 {
694   struct type *containing_class = TYPE_SELF_TYPE (type);
695
696   if (containing_class == nullptr)
697     return GCC_TYPE_NONE;
698
699   gcc_type class_type = instance->convert_type (containing_class);
700   gcc_type member_type
701     = instance->convert_type (TYPE_TARGET_TYPE (type));
702
703   return instance->plugin ().build_pointer_to_member_type
704     (class_type, member_type);
705 }
706
707 /* Convert all methods defined in TYPE, which should be a class/struct/union
708    with gcc_type CLASS_TYPE.  */
709
710 static void
711 compile_cplus_convert_struct_or_union_methods (compile_cplus_instance *instance,
712                                                struct type *type,
713                                                gcc_type class_type)
714 {
715   for (int i = 0; i < TYPE_NFN_FIELDS (type); ++i)
716     {
717       struct fn_field *methods = TYPE_FN_FIELDLIST1 (type, i);
718       gdb::unique_xmalloc_ptr<char> overloaded_name
719         = compile_cplus_instance::decl_name (TYPE_FN_FIELDLIST_NAME (type, i));
720
721       /* Loop through the fieldlist, adding decls to the compiler's
722          representation of the class.  */
723       for (int j = 0; j < TYPE_FN_FIELDLIST_LENGTH (type, i); ++j)
724         {
725           /* Skip artificial methods.  */
726           if (TYPE_FN_FIELD_ARTIFICIAL (methods, j))
727             continue;
728
729           gcc_cp_symbol_kind_flags sym_kind = GCC_CP_SYMBOL_FUNCTION;
730           gcc_type method_type;
731           struct block_symbol sym
732             = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (methods, j),
733                              instance->block (), VAR_DOMAIN, nullptr);
734
735           if (sym.symbol == nullptr)
736             {
737               if (TYPE_FN_FIELD_VIRTUAL_P (methods, j))
738                 {
739                   /* This is beyond hacky, and is really only a workaround for
740                      detecting pure virtual methods.  */
741                   method_type = compile_cplus_convert_method
742                     (instance, type, TYPE_FN_FIELD_TYPE (methods, j));
743
744                   instance->plugin ().build_decl
745                     ("pure virtual method", overloaded_name.get (),
746                      (sym_kind
747                       | get_method_access_flag (type, i, j)
748                       | GCC_CP_FLAG_VIRTUAL_FUNCTION
749                       | GCC_CP_FLAG_PURE_VIRTUAL_FUNCTION),
750                      method_type, nullptr, 0, nullptr, 0);
751                   continue;
752                 }
753
754               /* This can happen if we have a DW_AT_declaration DIE
755                  for the method, but no "definition"-type DIE (with
756                  DW_AT_specification referencing the decl DIE), i.e.,
757                  the compiler has probably optimized the method away.
758
759                  In this case, all we can hope to do is issue a warning
760                  to the user letting him know.  If the user has not actually
761                  requested using this method, things should still work.  */
762               warning (_("Method %s appears to be optimized out.\n"
763                          "All references to this method will be undefined."),
764                          TYPE_FN_FIELD_PHYSNAME (methods, j));
765               continue;
766             }
767
768           const char *filename = symbol_symtab (sym.symbol)->filename;
769           unsigned int line = SYMBOL_LINE (sym.symbol);
770           CORE_ADDR address = BLOCK_START (SYMBOL_BLOCK_VALUE (sym.symbol));
771           const char *kind;
772
773           if (TYPE_FN_FIELD_STATIC_P (methods, j))
774             {
775               kind = "static method";
776               method_type = compile_cplus_convert_func
777                 (instance, TYPE_FN_FIELD_TYPE (methods, j), true);
778             }
779           else
780             {
781               kind = "method";
782               method_type = (compile_cplus_convert_method
783                              (instance, type, TYPE_FN_FIELD_TYPE (methods, j)));
784             }
785
786           if (TYPE_FN_FIELD_VIRTUAL_P (methods, j))
787             sym_kind |= GCC_CP_FLAG_VIRTUAL_FUNCTION;
788
789           instance->plugin ().build_decl
790             (kind, overloaded_name.get (),
791              sym_kind | get_method_access_flag (type, i, j),
792              method_type, nullptr, address, filename, line);
793         }
794     }
795 }
796
797 /* Convert a struct or union type to its gcc representation.  If this type
798    was defined in another type, NESTED_ACCESS should indicate the
799    accessibility of this type.  */
800
801 static gcc_type
802 compile_cplus_convert_struct_or_union (compile_cplus_instance *instance,
803                                        struct type *type,
804                                        enum gcc_cp_symbol_kind nested_access)
805 {
806   const char *filename = nullptr;
807   unsigned short line = 0;
808
809   /* Get the decl name of this type.  */
810   gdb::unique_xmalloc_ptr<char> name
811     = compile_cplus_instance::decl_name (TYPE_NAME (type));
812
813   /* Create a new scope for TYPE.  */
814   compile_scope scope = instance->new_scope (TYPE_NAME (type), type);
815
816   if (scope.nested_type () != GCC_TYPE_NONE)
817     {
818       /* The type requested was actually defined inside another type,
819          such as a nested class definition.  Return that type.  */
820       return scope.nested_type ();
821     }
822
823   /* Push all scopes.  */
824   instance->enter_scope (std::move (scope));
825
826   /* First we create the resulting type and enter it into our hash
827      table.  This lets recursive types work.  */
828
829   gcc_decl resuld;
830   if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
831     {
832       const char *what = TYPE_DECLARED_CLASS (type) ? "struct" : "class";
833
834       resuld = instance->plugin ().build_decl
835         (what, name.get (), (GCC_CP_SYMBOL_CLASS | nested_access
836                              | (TYPE_DECLARED_CLASS (type)
837                                 ? GCC_CP_FLAG_CLASS_NOFLAG
838                                 : GCC_CP_FLAG_CLASS_IS_STRUCT)),
839          0, nullptr, 0, filename, line);
840     }
841   else
842     {
843       gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
844       resuld = instance->plugin ().build_decl
845         ("union", name.get (), GCC_CP_SYMBOL_UNION | nested_access,
846          0, nullptr, 0, filename, line);
847     }
848
849   gcc_type result;
850   if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
851     {
852       struct gcc_vbase_array bases;
853       int num_baseclasses = TYPE_N_BASECLASSES (type);
854
855       memset (&bases, 0, sizeof (bases));
856
857       if (num_baseclasses > 0)
858         {
859           bases.elements = XNEWVEC (gcc_type, num_baseclasses);
860           bases.flags = XNEWVEC (enum gcc_cp_symbol_kind, num_baseclasses);
861           bases.n_elements = num_baseclasses;
862           for (int i = 0; i < num_baseclasses; ++i)
863             {
864               struct type *base_type = TYPE_BASECLASS (type, i);
865
866               bases.flags[i] = GCC_CP_SYMBOL_BASECLASS
867                 | get_field_access_flag (type, i)
868                 | (BASETYPE_VIA_VIRTUAL (type, i)
869                    ? GCC_CP_FLAG_BASECLASS_VIRTUAL
870                    : GCC_CP_FLAG_BASECLASS_NOFLAG);
871               bases.elements[i] = instance->convert_type (base_type);
872             }
873         }
874
875       result = instance->plugin ().start_class_type
876         (name.get (), resuld, &bases, filename, line);
877       xfree (bases.flags);
878       xfree (bases.elements);
879     }
880   else
881     {
882       gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
883       result = instance->plugin ().start_class_type
884         (name.get (), resuld, nullptr, filename, line);
885     }
886
887   instance->insert_type (type, result);
888
889   /* Add definitions.  */
890   compile_cplus_convert_type_defns (instance, type);
891
892   /* Add methods.  */
893   compile_cplus_convert_struct_or_union_methods (instance, type, result);
894
895   /* Add members.  */
896   compile_cplus_convert_struct_or_union_members (instance, type, result);
897
898   /* All finished.  */
899   instance->plugin ().finish_class_type (name.get (), TYPE_LENGTH (type));
900
901   /* Pop all scopes.  */
902   instance->leave_scope ();
903   return result;
904 }
905
906 /* Convert an enum type to its gcc representation.  If this type
907    was defined in another type, NESTED_ACCESS should indicate the
908    accessibility of this type.*/
909
910 static gcc_type
911 compile_cplus_convert_enum (compile_cplus_instance *instance, struct type *type,
912                             enum gcc_cp_symbol_kind nested_access)
913 {
914   int scoped_enum_p = FALSE;
915
916   /* Create a new scope for this type.  */
917   compile_scope scope = instance->new_scope (TYPE_NAME (type), type);
918
919   if (scope.nested_type () != GCC_TYPE_NONE)
920     {
921       /* The type requested was actually defined inside another type,
922          such as a nested class definition.  Return that type.  */
923       return scope.nested_type ();
924     }
925
926   gdb::unique_xmalloc_ptr<char> name
927     = compile_cplus_instance::decl_name (TYPE_NAME (type));
928
929   /* Push all scopes.  */
930   instance->enter_scope (std::move (scope));
931
932   gcc_type int_type
933     = instance->plugin ().get_int_type (TYPE_UNSIGNED (type),
934                                         TYPE_LENGTH (type), nullptr);
935   gcc_type result
936     = instance->plugin ().start_enum_type (name.get (), int_type,
937                                            GCC_CP_SYMBOL_ENUM | nested_access
938                                            | (scoped_enum_p
939                                               ? GCC_CP_FLAG_ENUM_SCOPED
940                                               : GCC_CP_FLAG_ENUM_NOFLAG),
941                                            nullptr, 0);
942   for (int i = 0; i < TYPE_NFIELDS (type); ++i)
943     {
944       gdb::unique_xmalloc_ptr<char> fname
945         = compile_cplus_instance::decl_name (TYPE_FIELD_NAME (type, i));
946
947       if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_ENUMVAL
948           || fname == nullptr)
949         continue;
950
951       instance->plugin ().build_enum_constant (result, fname.get (),
952                                                TYPE_FIELD_ENUMVAL (type, i));
953     }
954
955   /* Finish enum definition and pop scopes.  */
956   instance->plugin ().finish_enum_type (result);
957   instance->leave_scope ();
958   return result;
959 }
960
961 /* Convert a function type to its gcc representation.  This function does
962    not deal with function templates.  */
963
964 static gcc_type
965 compile_cplus_convert_func (compile_cplus_instance *instance,
966                             struct type *type, bool strip_artificial)
967 {
968   int is_varargs = TYPE_VARARGS (type);
969   struct type *target_type = TYPE_TARGET_TYPE (type);
970
971   /* Functions with no debug info have no return type.  Ideally we'd
972      want to fallback to the type of the cast just before the
973      function, like GDB's built-in expression parser, but we don't
974      have access to that type here.  For now, fallback to int, like
975      GDB's parser used to do.  */
976   if (target_type == nullptr)
977     {
978       if (TYPE_OBJFILE_OWNED (type))
979         target_type = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
980       else
981         target_type = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
982       warning (_("function has unknown return type; assuming int"));
983     }
984
985   /* This approach means we can't make self-referential function
986      types.  Those are impossible in C, though.  */
987   gcc_type return_type = instance->convert_type (target_type);
988
989   struct gcc_type_array array =
990     { TYPE_NFIELDS (type), XNEWVEC (gcc_type, TYPE_NFIELDS (type)) };
991   int artificials = 0;
992   for (int i = 0; i < TYPE_NFIELDS (type); ++i)
993     {
994       if (strip_artificial && TYPE_FIELD_ARTIFICIAL (type, i))
995         {
996           --array.n_elements;
997           ++artificials;
998         }
999       else
1000         {
1001           array.elements[i - artificials]
1002             = instance->convert_type (TYPE_FIELD_TYPE (type, i));
1003         }
1004     }
1005
1006   /* We omit setting the argument types to `void' to be a little flexible
1007      with some minsyms like printf (compile-cplus.exp has examples).  */
1008   gcc_type result = instance->plugin ().build_function_type
1009     (return_type, &array, is_varargs);
1010   xfree (array.elements);
1011   return result;
1012 }
1013
1014 /* Convert an integer type to its gcc representation.  */
1015
1016 static gcc_type
1017 compile_cplus_convert_int (compile_cplus_instance *instance, struct type *type)
1018 {
1019   if (TYPE_NOSIGN (type))
1020     {
1021       gdb_assert (TYPE_LENGTH (type) == 1);
1022       return instance->plugin ().get_char_type ();
1023     }
1024
1025   return instance->plugin ().get_int_type
1026     (TYPE_UNSIGNED (type), TYPE_LENGTH (type), TYPE_NAME (type));
1027 }
1028
1029 /* Convert a floating-point type to its gcc representation.  */
1030
1031 static gcc_type
1032 compile_cplus_convert_float (compile_cplus_instance *instance,
1033                              struct type *type)
1034 {
1035   return instance->plugin ().get_float_type
1036     (TYPE_LENGTH (type), TYPE_NAME (type));
1037 }
1038
1039 /* Convert the 'void' type to its gcc representation.  */
1040
1041 static gcc_type
1042 compile_cplus_convert_void (compile_cplus_instance *instance, struct type *type)
1043 {
1044   return instance->plugin ().get_void_type ();
1045 }
1046
1047 /* Convert a boolean type to its gcc representation.  */
1048
1049 static gcc_type
1050 compile_cplus_convert_bool (compile_cplus_instance *instance, struct type *type)
1051 {
1052   return instance->plugin ().get_bool_type ();
1053 }
1054
1055 /* See description in compile-cplus.h.  */
1056
1057 gcc_type
1058 compile_cplus_instance::convert_qualified_base (gcc_type base,
1059                                                 gcc_cp_qualifiers_flags quals)
1060 {
1061   gcc_type result = base;
1062
1063   if (quals != 0)
1064     result = plugin ().build_qualified_type (base, quals);
1065
1066   return result;
1067 }
1068
1069 /* See description in compile-cplus.h.  */
1070
1071 static gcc_type
1072 compile_cplus_convert_qualified (compile_cplus_instance *instance,
1073                                  struct type *type)
1074 {
1075   struct type *unqual = make_unqualified_type (type);
1076   gcc_cp_qualifiers_flags quals = (enum gcc_cp_qualifiers) 0;
1077   gcc_type unqual_converted = instance->convert_type (unqual);
1078
1079   if (TYPE_CONST (type))
1080     quals |= GCC_CP_QUALIFIER_CONST;
1081   if (TYPE_VOLATILE (type))
1082     quals |= GCC_CP_QUALIFIER_VOLATILE;
1083   if (TYPE_RESTRICT (type))
1084     quals |= GCC_CP_QUALIFIER_RESTRICT;
1085
1086   return instance->convert_qualified_base (unqual_converted, quals);
1087 }
1088
1089 /* Convert a complex type to its gcc representation.  */
1090
1091 static gcc_type
1092 compile_cplus_convert_complex (compile_cplus_instance *instance,
1093                                struct type *type)
1094 {
1095   gcc_type base = instance->convert_type (TYPE_TARGET_TYPE (type));
1096
1097   return instance->plugin ().build_complex_type (base);
1098 }
1099
1100 /* Convert a namespace of TYPE.  */
1101
1102 static gcc_type
1103 compile_cplus_convert_namespace (compile_cplus_instance *instance,
1104                                  struct type *type)
1105 {
1106   compile_scope scope = instance->new_scope (TYPE_NAME (type), type);
1107   gdb::unique_xmalloc_ptr<char> name
1108     = compile_cplus_instance::decl_name (TYPE_NAME (type));
1109
1110   /* Push scope.  */
1111   instance->enter_scope (std::move (scope));
1112
1113   /* Convert this namespace.  */
1114   instance->plugin ().push_namespace (name.get ());
1115   instance->plugin ().pop_binding_level (name.get ());
1116
1117   /* Pop scope.  */
1118   instance->leave_scope ();
1119
1120   /* Namespaces are non-cacheable types.  */
1121   return GCC_TYPE_NONE;
1122 }
1123
1124 /* A helper function which knows how to convert most types from their
1125    gdb representation to the corresponding gcc form.  This examines
1126    the TYPE and dispatches to the appropriate conversion function.  It
1127    returns the gcc type.
1128
1129    If the type was defined in another type, NESTED_ACCESS should indicate the
1130    accessibility of this type.  */
1131
1132 static gcc_type
1133 convert_type_cplus_basic (compile_cplus_instance *instance,
1134                           struct type *type,
1135                           enum gcc_cp_symbol_kind nested_access)
1136 {
1137   /* If we are converting a qualified type, first convert the
1138      unqualified type and then apply the qualifiers.  */
1139   if ((TYPE_INSTANCE_FLAGS (type) & (TYPE_INSTANCE_FLAG_CONST
1140                                      | TYPE_INSTANCE_FLAG_VOLATILE
1141                                      | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
1142     return compile_cplus_convert_qualified (instance, type);
1143
1144   switch (TYPE_CODE (type))
1145     {
1146     case TYPE_CODE_REF:
1147     case TYPE_CODE_RVALUE_REF:
1148       return compile_cplus_convert_reference (instance, type);
1149
1150     case TYPE_CODE_PTR:
1151       return compile_cplus_convert_pointer (instance, type);
1152
1153     case TYPE_CODE_ARRAY:
1154       return compile_cplus_convert_array (instance, type);
1155
1156     case TYPE_CODE_STRUCT:
1157     case TYPE_CODE_UNION:
1158       return
1159         compile_cplus_convert_struct_or_union (instance, type, nested_access);
1160
1161     case TYPE_CODE_ENUM:
1162       return compile_cplus_convert_enum (instance, type, nested_access);
1163
1164     case TYPE_CODE_FUNC:
1165       return compile_cplus_convert_func (instance, type, false);
1166
1167     case TYPE_CODE_METHOD:
1168       return
1169         compile_cplus_convert_method (instance, TYPE_SELF_TYPE (type), type);
1170
1171     case TYPE_CODE_MEMBERPTR:
1172     case TYPE_CODE_METHODPTR:
1173       return compile_cplus_convert_memberptr (instance, type);
1174       break;
1175
1176     case TYPE_CODE_INT:
1177       return compile_cplus_convert_int (instance, type);
1178
1179     case TYPE_CODE_FLT:
1180       return compile_cplus_convert_float (instance, type);
1181
1182     case TYPE_CODE_VOID:
1183       return compile_cplus_convert_void (instance, type);
1184
1185     case TYPE_CODE_BOOL:
1186       return compile_cplus_convert_bool (instance, type);
1187
1188     case TYPE_CODE_COMPLEX:
1189       return compile_cplus_convert_complex (instance, type);
1190
1191     case TYPE_CODE_NAMESPACE:
1192       return compile_cplus_convert_namespace (instance, type);
1193
1194     case TYPE_CODE_TYPEDEF:
1195       return compile_cplus_convert_typedef (instance, type, nested_access);
1196
1197     default:
1198       break;
1199     }
1200
1201   std::string s = string_printf (_("unhandled TYPE_CODE %d"),
1202                                  TYPE_CODE (type));
1203
1204   return instance->plugin ().error (s.c_str ());
1205 }
1206
1207 gcc_type
1208 compile_cplus_instance::convert_type (struct type *type,
1209                                       enum gcc_cp_symbol_kind nested_access)
1210 {
1211   /* Check if TYPE has already been converted.  */
1212   gcc_type result;
1213   if (get_cached_type (type, &result))
1214     return result;
1215
1216   /* It is the first time this type has been seen -- convert it
1217      and cache it, if appropriate..  */
1218   result = convert_type_cplus_basic (this, type, nested_access);
1219   if (result != GCC_TYPE_NONE)
1220     insert_type (type, result);
1221   return result;
1222 }
1223
1224 void
1225 compile_cplus_instance::gcc_cplus_enter_scope
1226  (void *datum, struct gcc_cp_context *gcc_context)
1227 {
1228 }
1229
1230 void
1231 compile_cplus_instance::gcc_cplus_leave_scope
1232   (void *datum, struct gcc_cp_context *gcc_context)
1233 {
1234 }
1235
1236 \f
1237
1238 /* Plug-in forwards.  */
1239
1240 /* C++ plug-in wrapper.  */
1241
1242 /* A result printer for plug-in calls that return a gcc_type or
1243    gcc_decl.  */
1244
1245 static void
1246 compile_cplus_debug_output_1 (ULONGEST arg)
1247 {
1248   fprintf_unfiltered (gdb_stdlog, "%s", pulongest (arg));
1249 }
1250
1251 static void
1252 compile_cplus_debug_output_1 (const char *arg)
1253 {
1254   if (arg == nullptr)
1255     fputs_unfiltered ("NULL", gdb_stdlog);
1256   else
1257     fputs_unfiltered (arg, gdb_stdlog);
1258 }
1259
1260 static void
1261 compile_cplus_debug_output ()
1262 {
1263 }
1264
1265 template <typename T>
1266 static void
1267 compile_cplus_debug_output_1 (const T *arg)
1268 {
1269 }
1270
1271 template <typename T, typename... Targs>
1272 static void
1273 compile_cplus_debug_output (T arg, Targs... Args)
1274 {
1275   compile_cplus_debug_output_1 (arg);
1276   fputc_unfiltered (' ', gdb_stdlog);
1277   compile_cplus_debug_output (Args...);
1278 }
1279
1280 #define FORWARD(OP,...) m_context->cp_ops->OP(m_context, ##__VA_ARGS__)
1281 #define OUTPUT_DEBUG_RESULT(R)                    \
1282   if (debug_compile_cplus_types)                  \
1283     {                                             \
1284       fputs_unfiltered (": ", gdb_stdlog);        \
1285       compile_cplus_debug_output (R);             \
1286       fputc_unfiltered ('\n', gdb_stdlog);        \
1287     }                                             \
1288
1289 #define GCC_METHOD0(R, N)                         \
1290   R gcc_cp_plugin::N () const                     \
1291   {                                               \
1292     if (debug_compile_cplus_types)                \
1293       compile_cplus_debug_output (STRINGIFY (N)); \
1294     auto result = FORWARD (N);                    \
1295     OUTPUT_DEBUG_RESULT (result);                 \
1296     return result;                                \
1297   }
1298 #define GCC_METHOD1(R, N, A)                            \
1299   R gcc_cp_plugin::N (A a) const                        \
1300   {                                                     \
1301     if (debug_compile_cplus_types)                      \
1302       compile_cplus_debug_output (STRINGIFY (N), a);    \
1303     auto result = FORWARD (N, a);                       \
1304     OUTPUT_DEBUG_RESULT (result);                       \
1305     return result;                                      \
1306   }
1307 #define GCC_METHOD2(R, N, A, B)                         \
1308   R gcc_cp_plugin::N (A a, B b) const                   \
1309   {                                                     \
1310     if (debug_compile_cplus_types)                      \
1311       compile_cplus_debug_output (STRINGIFY (N), a, b); \
1312     auto result = FORWARD (N, a, b);                    \
1313     OUTPUT_DEBUG_RESULT (result);                       \
1314     return result;                                      \
1315   }
1316 #define GCC_METHOD3(R, N, A, B, C) \
1317   R gcc_cp_plugin::N (A a, B b, C c) const                      \
1318   {                                                             \
1319     if (debug_compile_cplus_types)                              \
1320       compile_cplus_debug_output (STRINGIFY (N), a, b, c);      \
1321     auto result = FORWARD (N, a, b, c);                         \
1322     OUTPUT_DEBUG_RESULT (result);                               \
1323     return result;                                              \
1324   }
1325 #define GCC_METHOD4(R, N, A, B, C, D)                           \
1326   R gcc_cp_plugin::N (A a, B b, C c, D d) const                 \
1327   {                                                             \
1328     if (debug_compile_cplus_types)                              \
1329       compile_cplus_debug_output (STRINGIFY (N), a, b, c, d);   \
1330     auto result = FORWARD (N, a, b, c, d);                      \
1331     OUTPUT_DEBUG_RESULT (result);                               \
1332     return result;                                              \
1333   }
1334 #define GCC_METHOD5(R, N, A, B, C, D, E)                                \
1335   R gcc_cp_plugin::N (A a, B b, C c, D d, E e) const                    \
1336   {                                                                     \
1337     if (debug_compile_cplus_types)                                      \
1338       compile_cplus_debug_output (STRINGIFY (N), a, b, c, d, e);        \
1339     auto result = FORWARD (N, a, b, c, d, e);                           \
1340     OUTPUT_DEBUG_RESULT (result);                                       \
1341     return result;                                                      \
1342   }
1343 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G)                          \
1344   R gcc_cp_plugin::N (A a, B b, C c, D d, E e, F f, G g) const          \
1345   {                                                                     \
1346     if (debug_compile_cplus_types)                                      \
1347       compile_cplus_debug_output (STRINGIFY (N), a, b, c, d, e, f, g);  \
1348     auto result = FORWARD (N, a, b, c, d, e, f, g);                     \
1349     OUTPUT_DEBUG_RESULT (result);                                       \
1350     return result;                                                      \
1351   }
1352
1353 #include "gcc-cp-fe.def"
1354
1355 #undef GCC_METHOD0
1356 #undef GCC_METHOD1
1357 #undef GCC_METHOD2
1358 #undef GCC_METHOD3
1359 #undef GCC_METHOD4
1360 #undef GCC_METHOD5
1361 #undef GCC_METHOD7
1362 #undef FORWARD
1363 #undef OUTPUT_DEBUG_RESULT
1364
1365 gcc_expr
1366 gcc_cp_plugin::build_decl (const char *debug_decltype, const char *name,
1367                            enum gcc_cp_symbol_kind sym_kind, gcc_type sym_type,
1368                            const char *substitution_name, gcc_address address,
1369                            const char *filename, unsigned int line_number)
1370 {
1371   if (debug_compile_cplus_types)
1372     fprintf_unfiltered (gdb_stdlog, "<%s> ", debug_decltype);
1373
1374   return build_decl (name, sym_kind, sym_type, substitution_name,
1375                      address, filename, line_number);
1376 }
1377
1378 gcc_type
1379 gcc_cp_plugin::start_class_type (const char *debug_name, gcc_decl typedecl,
1380                                  const struct gcc_vbase_array *base_classes,
1381                                  const char *filename, unsigned int line_number)
1382 {
1383   if (debug_compile_cplus_types)
1384     fprintf_unfiltered (gdb_stdlog, "<%s> ", debug_name);
1385
1386   return start_class_type (typedecl, base_classes, filename, line_number);
1387 }
1388
1389 int
1390 gcc_cp_plugin::finish_class_type (const char *debug_name,
1391                                   unsigned long size_in_bytes)
1392 {
1393   if (debug_compile_cplus_types)
1394     fprintf_unfiltered (gdb_stdlog, "<%s> ", debug_name);
1395
1396   return finish_class_type (size_in_bytes);
1397 }
1398
1399 int
1400 gcc_cp_plugin::pop_binding_level (const char *debug_name)
1401 {
1402   if (debug_compile_cplus_types)
1403     fprintf_unfiltered (gdb_stdlog, "<%s> ", debug_name);
1404
1405   return pop_binding_level ();
1406 }
1407
1408 void
1409 _initialize_compile_cplus_types ()
1410 {
1411   add_setshow_boolean_cmd ("compile-cplus-types", no_class,
1412                              &debug_compile_cplus_types, _("\
1413 Set debugging of C++ compile type conversion."), _("\
1414 Show debugging of C++ compile type conversion."), _("\
1415 When enabled debugging messages are printed during C++ type conversion for\n\
1416 the compile commands."),
1417                              nullptr,
1418                              nullptr,
1419                              &setdebuglist,
1420                              &showdebuglist);
1421
1422   add_setshow_boolean_cmd ("compile-cplus-scopes", no_class,
1423                              &debug_compile_cplus_scopes, _("\
1424 Set debugging of C++ compile scopes."), _("\
1425 Show debugging of C++ compile scopes."), _("\
1426 When enabled debugging messages are printed about definition scopes during\n\
1427 C++ type conversion for the compile commands."),
1428                              nullptr,
1429                              nullptr,
1430                              &setdebuglist,
1431                              &showdebuglist);
1432 }
This page took 0.11086 seconds and 4 git commands to generate.