tools: Remove unreachable break after return/break. Found by Smatch.
[wine.git] / tools / winedump / msmangle.c
blobd9d99efdd1738e572b71383eb64066a76bdfb037
1 /*
2 * Demangle VC++ symbols into C function prototypes
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include "winedump.h"
26 /* Type for parsing mangled types */
27 typedef struct _compound_type
29 char dest_type;
30 int flags;
31 int have_qualifiers;
32 char *expression;
33 } compound_type;
36 /* Initialise a compound type structure */
37 #define INIT_CT(ct) do { memset (&ct, 0, sizeof (ct)); } while (0)
39 /* free the memory used by a compound structure */
40 #define FREE_CT(ct) free (ct.expression)
42 /* Flags for data types */
43 #define DATA_VTABLE 0x1
45 /* Internal functions */
46 static char *demangle_datatype (char **str, compound_type *ct,
47 parsed_symbol* sym);
49 static char *get_constraints_convention_1 (char **str, compound_type *ct);
51 static char *get_constraints_convention_2 (char **str, compound_type *ct);
53 static char *get_type_string (const char c, const int constraints);
55 static int get_type_constant (const char c, const int constraints);
57 static char *get_pointer_type_string (compound_type *ct,
58 const char *expression);
61 /*******************************************************************
62 * demangle_symbol
64 * Demangle a C++ linker symbol into a C prototype
66 int symbol_demangle (parsed_symbol *sym)
68 compound_type ct;
69 int is_static = 0, is_const = 0;
70 char *function_name = NULL;
71 char *class_name = NULL;
72 char *name;
73 const char *const_status;
74 static unsigned int hash = 0; /* In case of overloaded functions */
75 unsigned int data_flags = 0;
77 assert (globals.do_code);
78 assert (sym && sym->symbol);
80 hash++;
82 /* MS mangled names always begin with '?' */
83 name = sym->symbol;
84 if (*name++ != '?')
85 return -1;
87 if (VERBOSE)
88 puts ("Attempting to demangle symbol");
90 /* Then function name or operator code */
91 if (*name == '?')
93 /* C++ operator code (one character, or two if the first is '_') */
94 switch (*++name)
96 case '0': function_name = strdup ("ctor"); break;
97 case '1': function_name = strdup ("dtor"); break;
98 case '2': function_name = strdup ("operator_new"); break;
99 case '3': function_name = strdup ("operator_delete"); break;
100 case '4': function_name = strdup ("operator_equals"); break;
101 case '5': function_name = strdup ("operator_shiftright"); break;
102 case '6': function_name = strdup ("operator_shiftleft"); break;
103 case '7': function_name = strdup ("operator_not"); break;
104 case '8': function_name = strdup ("operator_equalsequals"); break;
105 case '9': function_name = strdup ("operator_notequals"); break;
106 case 'A': function_name = strdup ("operator_array"); break;
107 case 'C': function_name = strdup ("operator_dereference"); break;
108 case 'D': function_name = strdup ("operator_multiply"); break;
109 case 'E': function_name = strdup ("operator_plusplus"); break;
110 case 'F': function_name = strdup ("operator_minusminus"); break;
111 case 'G': function_name = strdup ("operator_minus"); break;
112 case 'H': function_name = strdup ("operator_plus"); break;
113 case 'I': function_name = strdup ("operator_address"); break;
114 case 'J': function_name = strdup ("operator_dereferencememberptr"); break;
115 case 'K': function_name = strdup ("operator_divide"); break;
116 case 'L': function_name = strdup ("operator_modulo"); break;
117 case 'M': function_name = strdup ("operator_lessthan"); break;
118 case 'N': function_name = strdup ("operator_lessthanequal"); break;
119 case 'O': function_name = strdup ("operator_greaterthan"); break;
120 case 'P': function_name = strdup ("operator_greaterthanequal"); break;
121 case 'Q': function_name = strdup ("operator_comma"); break;
122 case 'R': function_name = strdup ("operator_functioncall"); break;
123 case 'S': function_name = strdup ("operator_complement"); break;
124 case 'T': function_name = strdup ("operator_xor"); break;
125 case 'U': function_name = strdup ("operator_logicalor"); break;
126 case 'V': function_name = strdup ("operator_logicaland"); break;
127 case 'W': function_name = strdup ("operator_or"); break;
128 case 'X': function_name = strdup ("operator_multiplyequals"); break;
129 case 'Y': function_name = strdup ("operator_plusequals"); break;
130 case 'Z': function_name = strdup ("operator_minusequals"); break;
131 case '_':
132 switch (*++name)
134 case '0': function_name = strdup ("operator_divideequals"); break;
135 case '1': function_name = strdup ("operator_moduloequals"); break;
136 case '2': function_name = strdup ("operator_shiftrightequals"); break;
137 case '3': function_name = strdup ("operator_shiftleftequals"); break;
138 case '4': function_name = strdup ("operator_andequals"); break;
139 case '5': function_name = strdup ("operator_orequals"); break;
140 case '6': function_name = strdup ("operator_xorequals"); break;
141 case '7': function_name = strdup ("vftable"); data_flags = DATA_VTABLE; break;
142 case '8': function_name = strdup ("vbtable"); data_flags = DATA_VTABLE; break;
143 case '9': function_name = strdup ("vcall"); data_flags = DATA_VTABLE; break;
144 case 'A': function_name = strdup ("typeof"); data_flags = DATA_VTABLE; break;
145 case 'B': function_name = strdup ("local_static_guard"); data_flags = DATA_VTABLE; break;
146 case 'C': function_name = strdup ("string"); data_flags = DATA_VTABLE; break;
147 case 'D': function_name = strdup ("vbase_dtor"); data_flags = DATA_VTABLE; break;
148 case 'E': function_name = strdup ("vector_dtor"); break;
149 case 'G': function_name = strdup ("scalar_dtor"); break;
150 case 'H': function_name = strdup ("vector_ctor_iter"); break;
151 case 'I': function_name = strdup ("vector_dtor_iter"); break;
152 case 'J': function_name = strdup ("vector_vbase_ctor_iter"); break;
153 case 'L': function_name = strdup ("eh_vector_ctor_iter"); break;
154 case 'M': function_name = strdup ("eh_vector_dtor_iter"); break;
155 case 'N': function_name = strdup ("eh_vector_vbase_ctor_iter"); break;
156 case 'O': function_name = strdup ("copy_ctor_closure"); break;
157 case 'S': function_name = strdup ("local_vftable"); data_flags = DATA_VTABLE; break;
158 case 'T': function_name = strdup ("local_vftable_ctor_closure"); break;
159 case 'U': function_name = strdup ("operator_new_vector"); break;
160 case 'V': function_name = strdup ("operator_delete_vector"); break;
161 case 'X': function_name = strdup ("placement_new_closure"); break;
162 case 'Y': function_name = strdup ("placement_delete_closure"); break;
163 default:
164 return -1;
166 break;
167 default:
168 /* FIXME: Other operators */
169 return -1;
171 name++;
173 else
175 /* Type or function name terminated by '@' */
176 function_name = name;
177 while (*name && *name++ != '@') ;
178 if (!*name)
179 return -1;
180 function_name = str_substring (function_name, name - 1);
183 /* Either a class name, or '@' if the symbol is not a class member */
184 if (*name == '@')
186 class_name = strdup ("global"); /* Non member function (or a datatype) */
187 name++;
189 else
191 /* Class the function is associated with, terminated by '@@' */
192 class_name = name;
193 while (*name && *name++ != '@') ;
194 if (*name++ != '@') {
195 free (function_name);
196 return -1;
198 class_name = str_substring (class_name, name - 2);
201 /* Function/Data type and access level */
202 /* FIXME: why 2 possible letters for each option? */
203 switch(*name++)
205 /* Data */
207 case '0' : /* private static */
208 case '1' : /* protected static */
209 case '2' : /* public static */
210 is_static = 1;
211 /* Fall through */
212 case '3' : /* non static */
213 case '4' : /* non static */
214 /* Data members need to be implemented: report */
215 INIT_CT (ct);
216 if (!demangle_datatype (&name, &ct, sym))
218 if (VERBOSE)
219 printf ("/*FIXME: %s: unknown data*/\n", sym->symbol);
220 free (function_name);
221 return -1;
223 sym->flags |= SYM_DATA;
224 sym->argc = 1;
225 sym->arg_name[0] = str_create (5, OUTPUT_UC_DLL_NAME, "_", class_name,
226 is_static ? "static_" : "_", function_name);
227 sym->arg_text[0] = str_create (3, ct.expression, " ", sym->arg_name[0]);
228 FREE_CT (ct);
229 free (function_name);
230 return 0;
232 case '6' : /* compiler generated static */
233 case '7' : /* compiler generated static */
234 if (data_flags & DATA_VTABLE)
236 sym->flags |= SYM_DATA;
237 sym->argc = 1;
238 sym->arg_name[0] = str_create (5, OUTPUT_UC_DLL_NAME, "_", class_name,
239 "_", function_name);
240 sym->arg_text[0] = str_create (2, "void *", sym->arg_name[0]);
242 if (VERBOSE)
243 puts ("Demangled symbol OK [vtable]");
244 free (function_name);
245 return 0;
247 free (function_name);
248 return -1;
250 /* Functions */
252 case 'E' : /* private virtual */
253 case 'F' : /* private virtual */
254 case 'M' : /* protected virtual */
255 case 'N' : /* protected virtual */
256 case 'U' : /* public virtual */
257 case 'V' : /* public virtual */
258 /* Virtual functions need to be added to the exported vtable: report */
259 if (VERBOSE)
260 printf ("/*FIXME %s: %s::%s is virtual-add to vftable*/\n", sym->symbol,
261 class_name, function_name);
262 /* Fall through */
263 case 'A' : /* private */
264 case 'B' : /* private */
265 case 'I' : /* protected */
266 case 'J' : /* protected */
267 case 'Q' : /* public */
268 case 'R' : /* public */
269 /* Implicit 'this' pointer */
270 sym->arg_text [sym->argc] = str_create (3, "struct ", class_name, " *");
271 sym->arg_type [sym->argc] = ARG_POINTER;
272 sym->arg_flag [sym->argc] = 0;
273 sym->arg_name [sym->argc++] = strdup ("_this");
274 /* New struct definitions can be 'grep'ed out for making a fixup header */
275 if (VERBOSE)
276 printf ("struct %s { void **vtable; /*FIXME: class definition */ };\n", class_name);
277 break;
278 case 'C' : /* private: static */
279 case 'D' : /* private: static */
280 case 'K' : /* protected: static */
281 case 'L' : /* protected: static */
282 case 'S' : /* public: static */
283 case 'T' : /* public: static */
284 is_static = 1; /* No implicit this pointer */
285 break;
286 case 'Y' :
287 case 'Z' :
288 break;
289 /* FIXME: G,H / O,P / W,X are private / protected / public thunks */
290 default:
291 free (function_name);
292 return -1;
295 /* If there is an implicit this pointer, const status follows */
296 if (sym->argc)
298 switch (*name++)
300 case 'A': break; /* non-const */
301 case 'B': is_const = CT_CONST; break;
302 case 'C': is_const = CT_VOLATILE; break;
303 case 'D': is_const = (CT_CONST | CT_VOLATILE); break;
304 default:
305 free (function_name);
306 return -1;
310 /* Next is the calling convention */
311 switch (*name++)
313 case 'A': /* __cdecl */
314 case 'B': /* __cdecl __declspec(dllexport) */
315 if (!sym->argc)
317 sym->flags |= SYM_CDECL;
318 break;
320 /* Else fall through */
321 case 'C': /* __pascal */
322 case 'D': /* __pascal __declspec(dllexport) */
323 case 'E': /* __thiscall */
324 case 'F': /* __thiscall __declspec(dllexport) */
325 case 'G': /* __stdcall */
326 case 'H': /* __stdcall __declspec(dllexport) */
327 case 'I': /* __fastcall */
328 case 'J': /* __fastcall __declspec(dllexport)*/
329 case 'K': /* default (none given) */
330 if (sym->argc)
331 sym->flags |= SYM_THISCALL;
332 else
333 sym->flags |= SYM_STDCALL;
334 break;
335 default:
336 free (function_name);
337 return -1;
340 /* Return type, or @ if 'void' */
341 if (*name == '@')
343 sym->return_text = strdup ("void");
344 sym->return_type = ARG_VOID;
345 name++;
347 else
349 INIT_CT (ct);
350 if (!demangle_datatype (&name, &ct, sym)) {
351 free (function_name);
352 return -1;
354 sym->return_text = ct.expression;
355 sym->return_type = get_type_constant(ct.dest_type, ct.flags);
356 ct.expression = NULL;
357 FREE_CT (ct);
360 /* Now come the function arguments */
361 while (*name && *name != 'Z')
363 /* Decode each data type and append it to the argument list */
364 if (*name != '@')
366 INIT_CT (ct);
367 if (!demangle_datatype(&name, &ct, sym)) {
368 free (function_name);
369 return -1;
372 if (strcmp (ct.expression, "void"))
374 sym->arg_text [sym->argc] = ct.expression;
375 ct.expression = NULL;
376 sym->arg_type [sym->argc] = get_type_constant (ct.dest_type, ct.flags);
377 sym->arg_flag [sym->argc] = ct.flags;
378 sym->arg_name[sym->argc] = str_create_num (1, sym->argc, "arg");
379 sym->argc++;
381 else
382 break; /* 'void' terminates an argument list */
383 FREE_CT (ct);
385 else
386 name++;
389 while (*name == '@')
390 name++;
392 /* Functions are always terminated by 'Z'. If we made it this far and
393 * Don't find it, we have incorrectly identified a data type.
395 if (*name != 'Z') {
396 free (function_name);
397 return -1;
400 /* Note: '()' after 'Z' means 'throws', but we don't care here */
402 /* Create the function name. Include a unique number because otherwise
403 * overloaded functions could have the same c signature.
405 switch (is_const)
407 case (CT_CONST | CT_VOLATILE): const_status = "_const_volatile"; break;
408 case CT_CONST: const_status = "_const"; break;
409 case CT_VOLATILE: const_status = "_volatile"; break;
410 default: const_status = "_"; break;
412 sym->function_name = str_create_num (4, hash, class_name, "_",
413 function_name, is_static ? "_static" : const_status);
415 assert (sym->return_text);
416 assert (sym->flags);
417 assert (sym->function_name);
419 free (class_name);
420 free (function_name);
422 if (VERBOSE)
423 puts ("Demangled symbol OK");
425 return 0;
429 /*******************************************************************
430 * demangle_datatype
432 * Attempt to demangle a C++ data type, which may be compound.
433 * a compound type is made up of a number of simple types. e.g:
434 * char** = (pointer to (pointer to (char)))
436 * Uses a simple recursive descent algorithm that is broken
437 * and/or incomplete, without a doubt ;-)
439 static char *demangle_datatype (char **str, compound_type *ct,
440 parsed_symbol* sym)
442 char *iter;
444 assert (str && *str);
445 assert (ct);
447 iter = *str;
449 if (!get_constraints_convention_1 (&iter, ct))
450 return NULL;
452 if (*iter == '_')
454 /* MS type: __int8,__int16 etc */
455 ct->flags |= CT_EXTENDED;
456 iter++;
459 switch (*iter)
461 case 'C': case 'D': case 'E': case 'F': case 'G':
462 case 'H': case 'I': case 'J': case 'K': case 'M':
463 case 'N': case 'O': case 'X': case 'Z':
464 /* Simple data types */
465 ct->dest_type = *iter++;
466 if (!get_constraints_convention_2 (&iter, ct))
467 return NULL;
468 ct->expression = get_type_string (ct->dest_type, ct->flags);
469 break;
470 case 'U':
471 case 'V':
472 /* Class/struct/union */
473 ct->dest_type = *iter++;
474 if (*iter == '0' || *iter == '1')
476 /* Referring to class type (implicit 'this') */
477 char *stripped;
478 if (!sym->argc)
479 return NULL;
481 iter++;
482 /* Apply our constraints to the base type (struct xxx *) */
483 stripped = strdup (sym->arg_text [0]);
484 if (!stripped)
485 fatal ("Out of Memory");
487 /* If we're a reference, re-use the pointer already in the type */
488 if (!(ct->flags & CT_BY_REFERENCE))
489 stripped[ strlen (stripped) - 2] = '\0'; /* otherwise, strip it */
491 ct->expression = str_create (2, ct->flags & CT_CONST ? "const " :
492 ct->flags & CT_VOLATILE ? "volatile " : "", stripped);
493 free (stripped);
495 else if (*iter != '@')
497 /* The name of the class/struct, followed by '@@' */
498 char *struct_name = iter;
499 while (*iter && *iter++ != '@') ;
500 if (*iter++ != '@')
501 return NULL;
502 struct_name = str_substring (struct_name, iter - 2);
503 ct->expression = str_create (4, ct->flags & CT_CONST ? "const " :
504 ct->flags & CT_VOLATILE ? "volatile " : "", "struct ",
505 struct_name, ct->flags & CT_BY_REFERENCE ? " *" : "");
506 free (struct_name);
508 break;
509 case 'Q': /* FIXME: Array Just treated as pointer currently */
510 case 'P': /* Pointer */
512 compound_type sub_ct;
513 INIT_CT (sub_ct);
515 ct->dest_type = *iter++;
516 if (!get_constraints_convention_2 (&iter, ct))
517 return NULL;
519 /* FIXME: P6 = Function pointer, others who knows.. */
520 if (isdigit (*iter))
522 if (*iter == '6')
524 int sub_expressions = 0;
525 /* FIXME: there are a tons of memory leaks here */
526 /* FIXME: this is still broken in some cases and it has to be
527 * merged with the function prototype parsing above...
529 iter += iter[1] == 'A' ? 2 : 3; /* FIXME */
530 if (!demangle_datatype (&iter, &sub_ct, sym))
531 return NULL;
532 ct->expression = str_create(2, sub_ct.expression, " (*)(");
533 if (*iter != '@')
535 while (*iter != 'Z')
537 FREE_CT (sub_ct);
538 INIT_CT (sub_ct);
539 if (!demangle_datatype (&iter, &sub_ct, sym))
540 return NULL;
541 if (sub_expressions)
542 ct->expression = str_create(3, ct->expression, ", ", sub_ct.expression);
543 else
544 ct->expression = str_create(2, ct->expression, sub_ct.expression);
545 while (*iter == '@') iter++;
546 sub_expressions++;
548 } else while (*iter == '@') iter++;
549 iter++;
550 ct->expression = str_create(2, ct->expression, ")");
552 else
553 return NULL;
555 else
557 /* Recurse to get the pointed-to type */
558 if (!demangle_datatype (&iter, &sub_ct, sym))
559 return NULL;
561 ct->expression = get_pointer_type_string (ct, sub_ct.expression);
564 FREE_CT (sub_ct);
566 break;
567 case '0': case '1': case '2': case '3': case '4':
568 case '5': case '6': case '7': case '8': case '9':
569 /* Referring back to previously parsed type */
570 if (sym->argc >= (size_t)('0' - *iter))
571 return NULL;
572 ct->dest_type = sym->arg_type ['0' - *iter];
573 ct->expression = strdup (sym->arg_text ['0' - *iter]);
574 iter++;
575 break;
576 default :
577 return NULL;
579 if (!ct->expression)
580 return NULL;
582 return (char *)(*str = iter);
586 /* Constraints:
587 * There are two conventions for specifying data type constaints. I
588 * don't know how the compiler chooses between them, but I suspect it
589 * is based on ensuring that linker names are unique.
590 * Convention 1. The data type modifier is given first, followed
591 * by the data type it operates on. '?' means passed by value,
592 * 'A' means passed by reference. Note neither of these characters
593 * is a valid base data type. This is then followed by a character
594 * specifying constness or volatilty.
595 * Convention 2. The base data type (which is never '?' or 'A') is
596 * given first. The character modifier is optionally given after
597 * the base type character. If a valid character mofifier is present,
598 * then it only applies to the current data type if the character
599 * after that is not 'A' 'B' or 'C' (Because this makes a convention 1
600 * constraint for the next data type).
602 * The conventions are usually mixed within the same symbol.
603 * Since 'C' is both a qualifier and a data type, I suspect that
604 * convention 1 allows specifying e.g. 'volatile signed char*'. In
605 * convention 2 this would be 'CC' which is ambigious (i.e. Is it two
606 * pointers, or a single pointer + modifier?). In convention 1 it
607 * is encoded as '?CC' which is not ambigious. This probably
608 * holds true for some other types as well.
611 /*******************************************************************
612 * get_constraints_convention_1
614 * Get type constraint information for a data type
616 static char *get_constraints_convention_1 (char **str, compound_type *ct)
618 char *iter = *str, **retval = str;
620 if (ct->have_qualifiers)
621 return (char *)*str; /* Previously got constraints for this type */
623 if (*iter == '?' || *iter == 'A')
625 ct->have_qualifiers = 1;
626 ct->flags |= (*iter++ == '?' ? 0 : CT_BY_REFERENCE);
628 switch (*iter++)
630 case 'A' :
631 break; /* non-const, non-volatile */
632 case 'B' :
633 ct->flags |= CT_CONST;
634 break;
635 case 'C' :
636 ct->flags |= CT_VOLATILE;
637 break;
638 default :
639 return NULL;
643 return (char *)(*retval = iter);
647 /*******************************************************************
648 * get_constraints_convention_2
650 * Get type constraint information for a data type
652 static char *get_constraints_convention_2 (char **str, compound_type *ct)
654 char *iter = *str, **retval = str;
656 /* FIXME: Why do arrays have both convention 1 & 2 constraints? */
657 if (ct->have_qualifiers && ct->dest_type != 'Q')
658 return (char *)*str; /* Previously got constraints for this type */
660 ct->have_qualifiers = 1; /* Even if none, we've got all we're getting */
662 switch (*iter)
664 case 'A' :
665 if (iter[1] != 'A' && iter[1] != 'B' && iter[1] != 'C')
666 iter++;
667 break;
668 case 'B' :
669 ct->flags |= CT_CONST;
670 iter++;
671 break;
672 case 'C' :
673 /* See note above, if we find 'C' it is _not_ a signed char */
674 ct->flags |= CT_VOLATILE;
675 iter++;
676 break;
679 return (char *)(*retval = iter);
683 /*******************************************************************
684 * get_type_string
686 * Return a string containing the name of a data type
688 static char *get_type_string (const char c, const int constraints)
690 const char *type_string;
692 if (constraints & CT_EXTENDED)
694 switch (c)
696 case 'D': type_string = "__int8"; break;
697 case 'E': type_string = "unsigned __int8"; break;
698 case 'F': type_string = "__int16"; break;
699 case 'G': type_string = "unsigned __int16"; break;
700 case 'H': type_string = "__int32"; break;
701 case 'I': type_string = "unsigned __int32"; break;
702 case 'J': type_string = "__int64"; break;
703 case 'K': type_string = "unsigned __int64"; break;
704 case 'L': type_string = "__int128"; break;
705 case 'M': type_string = "unsigned __int128"; break;
706 case 'N': type_string = "int"; break; /* bool */
707 case 'W': type_string = "WCHAR"; break; /* wchar_t */
708 default:
709 return NULL;
712 else
714 switch (c)
716 case 'C': /* Signed char, fall through */
717 case 'D': type_string = "char"; break;
718 case 'E': type_string = "unsigned char"; break;
719 case 'F': type_string = "short int"; break;
720 case 'G': type_string = "unsigned short int"; break;
721 case 'H': type_string = "int"; break;
722 case 'I': type_string = "unsigned int"; break;
723 case 'J': type_string = "long"; break;
724 case 'K': type_string = "unsigned long"; break;
725 case 'M': type_string = "float"; break;
726 case 'N': type_string = "double"; break;
727 case 'O': type_string = "long double"; break;
728 /* FIXME: T = union */
729 case 'U':
730 case 'V': type_string = "struct"; break;
731 case 'X': return strdup ("void");
732 case 'Z': return strdup ("...");
733 default:
734 return NULL;
738 return str_create (3, constraints & CT_CONST ? "const " :
739 constraints & CT_VOLATILE ? "volatile " : "", type_string,
740 constraints & CT_BY_REFERENCE ? " *" : "");
744 /*******************************************************************
745 * get_type_constant
747 * Get the ARG_* constant for this data type
749 static int get_type_constant (const char c, const int constraints)
751 /* Any reference type is really a pointer */
752 if (constraints & CT_BY_REFERENCE)
753 return ARG_POINTER;
755 switch (c)
757 case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I':
758 case 'J': case 'K':
759 return ARG_LONG;
760 case 'M':
761 return ARG_FLOAT;
762 case 'N': case 'O':
763 return ARG_DOUBLE;
764 case 'P': case 'Q':
765 return ARG_POINTER;
766 case 'U': case 'V':
767 return ARG_STRUCT;
768 case 'X':
769 return ARG_VOID;
770 case 'Z':
771 default:
772 return -1;
777 /*******************************************************************
778 * get_pointer_type_string
780 * Return a string containing 'pointer to expression'
782 static char *get_pointer_type_string (compound_type *ct,
783 const char *expression)
785 /* FIXME: set a compound flag for bracketing expression if needed */
786 return str_create (3, ct->flags & CT_CONST ? "const " :
787 ct->flags & CT_VOLATILE ? "volatile " : "", expression,
788 ct->flags & CT_BY_REFERENCE ? " **" : " *");