README.dem revision b9bd317cda1afb3a01f4812de73e8cec888cbbd7
3853N/A#
3853N/A# CDDL HEADER START
3853N/A#
3853N/A# The contents of this file are subject to the terms of the
3853N/A# Common Development and Distribution License, Version 1.0 only
3853N/A# (the "License"). You may not use this file except in compliance
3853N/A# with the License.
3853N/A#
3853N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3853N/A# or http://www.opensolaris.org/os/licensing.
3853N/A# See the License for the specific language governing permissions
3853N/A# and limitations under the License.
3853N/A#
3853N/A# When distributing Covered Code, include this CDDL HEADER in each
3853N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3853N/A# If applicable, add the following below this CDDL HEADER, with the
3853N/A# fields enclosed by brackets "[]" replaced with your own identifying
3853N/A# information: Portions Copyright [yyyy] [name of copyright owner]
3853N/A#
3853N/A# CDDL HEADER END
3853N/A#
3853N/A/*ident "@(#)cls4:tools/demangler/README.dem 1.3" */
3853N/A#ident "%Z%%M% %I% %E% SMI"
3853N/A
3853N/A###############################################################################
3853N/A#
3853N/A# C++ source for the C++ Language System, Release 3.0. This product
3853N/A# is a new release of the original cfront developed in the computer
3853N/A# science research center of AT&T Bell Laboratories.
3853N/A#
3853N/A# Copyright (c) 1991 AT&T and UNIX System Laboratories, Inc.
3853N/A# Copyright (c) 1984, 1989, 1990 AT&T. All Rights Reserved.
3853N/A#
3853N/A###############################################################################
3853N/ADemangler Release Notes for 3.0.1
3853N/AJanuary 1992
3853N/A
3853N/A
3853N/AINTRODUCTION
3853N/A
3853N/AThis is the first release of the new C++ external name demangler. It
3853N/Awas rewritten for a couple of reasons, notably the desire to separate
3853N/Athe unmangling and printing functions and the need to fully support
3853N/Atemplate names and nested class names.
3853N/A
3853N/AIn what follows it is assumed that the reader is familiar with page
3853N/A122 and following of the Annotated C++ Reference Manual, where the
3853N/Aname mangling scheme is given.
3853N/A
3853N/A
3853N/AINSTALLATION AND CUSTOMIZATION
3853N/A
3853N/AThe demangler has two files, dem.h and dem.c. dem.h is #included in
3853N/Auser programs. dem.c can be compiled either for a standalone program:
3853N/A
3853N/A $ cc -DDEM_MAIN dem.c -o dem
3853N/A
3853N/Aor to produce an object to be linked with an application:
3853N/A
3853N/A $ cc -c dem.c
3853N/A
3853N/A ...
3853N/A
3853N/A $ cc appl.o dem.o
3853N/A
3853N/AThe standard main() driver program in dem.c will read from standard
3853N/Ainput or from a set of command-line files, and unmangle names in
3853N/Aplace, while passing all whitespace and invalid names through
3853N/Aunchanged.
3853N/A
3853N/AThere are a couple of customization options. CLIP_UNDER should be set
3853N/A(#defined) at the top of dem.c if external names on your system have a
3853N/Aleading underscore added to them. This is common, for example on the
3853N/ASun SPARCstation. An #if has been added for the most common machine
3853N/Atypes.
3853N/A
3853N/Adem.c uses its own space management system both for speed and to avoid
3853N/Ahaving to call malloc(). SP_ALIGN is the alignment of blocks that are
3853N/Aallocated; 4 bytes is the default. If your system requires alignment
3853N/Aon other than a power-of-2 boundary, you will have to adjust the
3853N/Afunction gs() to use the mod operator rather than the mask technique
3853N/Athat is used by default.
3853N/A
3853N/AThere is a constant MAXDBUF defined in dem.h. This is the maximum
3853N/Asize of buffer required for an unmangled name's data structure. The
3853N/A4096 size is the worst-case setting for a maximum input mangled name
3853N/Alength of 256. If you routinely have names longer than this, you
3853N/Ashould adjust MAXDBUF upwards accordingly.
3853N/A
3853N/AFinally, there is a compile-time value EXPLAIN that can be set. If
3853N/Aturned on with -DEXPLAIN, the demanger will append a brief description
3853N/Aof the type of each input name to the demangled output.
3853N/A
3853N/A
3853N/AUSE OF THE STANDALONE DEMANGLER
3853N/A
3853N/AThe standalone program reads from standard input or from one or more
3853N/Afiles and processes each line in turn. All whitespace and
3853N/Anon-alphanumeric characters are passed through unchanged. All other
3853N/Acharacters are separated into names and given to the demangler. If
3853N/Athe demangler fails, the name is printed unchanged. Otherwise, the
3853N/Aunmangled name is printed.
3853N/A
3853N/AThe standalone demangler has an exit status of 0 unless one or more
3853N/Ainput files could not be opened for reading; in that case the exit
3853N/Astatus is the number of unopenable files.
3853N/A
3853N/A
3853N/AUSE OF THE DEMANGLER LIBRARY
3853N/A
3853N/AThe basic idea is to call the dem() function:
3853N/A
3853N/A int ret;
3853N/A char inbuf[1024];
3853N/A DEM d;
3853N/A char sbuf[MAXDBUF];
3853N/A
3853N/A ret = dem(inbuf, &d, sbuf);
3853N/A
3853N/Ainbuf is the input name, d the data structure that dem() fills up, and
3853N/Asbuf the internal buffer that the demangler writes into to allocate
3853N/Aits data structure.
3853N/A
3853N/Adem() returns -1 on error, otherwise 0.
3853N/A
3853N/Adem.h has comments describing each field in the data structures. The
3853N/Adata structures are somewhat complicated by the need to handle nested
3853N/Atypes and function arguments which themselves are function pointers
3853N/Awith their own arguments.
3853N/A
3853N/ATo format this data structure, there are several functions:
3853N/A
3853N/A dem_print - format a complete name
3853N/A
3853N/A dem_printcl - format a class name
3853N/A
3853N/A dem_printarg - format a function argument
3853N/A
3853N/A dem_printarglist - format a function argument list
3853N/A
3853N/A dem_printfunc - format a function name
3853N/A
3853N/A dem_explain - return a string explaining a type
3853N/A
3853N/A demangle - demangle in (char*) to out (char*)
3853N/A
3853N/A
3853N/AAN EXAMPLE APPLICATION
3853N/A
3853N/AThis particular application reads from standard input and displays the
3853N/Aclass name for each mangled name read, or "(none)" on errors and C
3853N/Afunctions/data.
3853N/A
3853N/A #include <stdio.h>
3853N/A #include "dem.h"
3853N/A
3853N/A main()
3853N/A {
3853N/A char sbuf[MAXDBUF];
3853N/A DEM d;
3853N/A int ret;
3853N/A char buf[1024];
3853N/A char buf2[1024];
3853N/A
3853N/A while (gets(buf) != NULL) {
3853N/A ret = dem(buf, &d, sbuf);
3853N/A if (ret || d.cl == NULL) {
3853N/A printf("%s --> (none)\n", buf);
3853N/A }
3853N/A else {
3853N/A dem_printcl(d.cl, buf2);
3853N/A printf("%s --> %s\n", buf, buf2);
3853N/A }
3853N/A }
3853N/A }
3853N/A
3853N/A
3853N/ATYPENAMES
3853N/A
3853N/AThe demangler handles mangled class typenames, whether they are
3853N/Asimple, nested, or template classes. For example:
3853N/A
3853N/A A__pt__2_i --> A<int>
3853N/A
3853N/A __Q2_1A1B --> A::B
3853N/A
3853N/A
3853N/ALOCAL VARIABLES
3853N/A
3853N/AThe demangler also handles local variables of the form:
3853N/A
3853N/A __nnnxxx
3853N/A
3853N/AFor example:
3853N/A
3853N/A __2x --> x
3853N/A
3853N/AUSE OF THE OLD C++FILT PROGRAM
3853N/A
3853N/AMany of the previously supported options to c++filt are no longer
3853N/Asupported. If you need to use them, you can build the old c++filt
3853N/Ausing the source in the subdirectory "osrc". Note that we are
3853N/Aplanning to eliminate them in a future release, so please send mail to
3934N/Ayour C++ support person explaining what option you needed and why.
3853N/A
3853N/A
3853N/AKNOWN BUGS AND AMBIGUITIES
3853N/A
3853N/A1. "signed" and "volatile" encodings are not handled.
3853N/A
3853N/A2. The encoding for nested classes as mentioned on page 123 of the
3853N/AARM is handled slightly differently in cfront; there is a "_" after
3853N/Athe digit after the "Q".
3853N/A
3853N/A3. A nested class starting with "Q" sometimes has the length encoded
3853N/Abefore it; the demangler handles either case.
3853N/A
3853N/A4. The "Tnn" and "Nnnn" notations mentioned on page 124 are not fully
3853N/Asupported. It is assumed that the number of the designated argument
3853N/Ais less than or equal to 9. So if you have 11 or more arguments, and
3853N/Ayou want to repeat argument 10 or greater, the demangler will reject
3853N/Athe encoded name.
3853N/A
3853N/A5. All literal arguments to templates are assumed to be const. For
3853N/Aexample, the non-const literal value "37" is encoded as "Ci".
3853N/A
3853N/A6. Some compilers will add a gratuitous "_" before external names.
3853N/A
3853N/A7. The grammar allows class names up to 999 characters. This is
3853N/Aconsidered important for handling templates.
3853N/A
3853N/A
3853N/ATHE GRAMMAR FOR EXTERNAL NAMES
3853N/A
3853N/Astart --> name
3853N/A
3853N/A######################### COMPLETE NAMES #########################
3853N/A
3853N/Aname --> sti | std | ptbl | func | data | vtbl | cname3 | local
3853N/A
3853N/Asti --> "__sti" "__" id
3853N/A
3853N/Astd --> "__std" "__" id
3853N/A
3853N/Aptbl --> "__ptbl_vec" "__" id
3853N/A
3853N/Afunc --> "__op" arg funcpost | id funcpost
3853N/A
3853N/Afuncpost --> "__" funcpost2 | "__" cname funcpost2
3853N/A
3853N/Afuncpost2 --> csv "F" arglist
3853N/A
3853N/Acsv --> "" | "C" | "S" | "V"
3853N/A
3853N/Adata --> id | id "__" cname
3853N/A
3853N/Avtbl --> "__vtbl" "__" cname
3853N/A
3853N/Alocal --> "__" num regid
3853N/A
3853N/A######################### CLASS NAMES #########################
3853N/A
3853N/Acname --> cname2 | nest
3853N/A
3853N/Anest --> "Q" digit "_" cnamelist
3853N/A
3853N/Acnamelist --> cname2 | cnamelist cname2
3853N/A
3853N/Acname2 --> cnlen cnid
3853N/A
3853N/Acname3 --> cnid | "__" nest
3853N/A
3853N/Acnlen --> digit | digit digit | digit digit digit
3853N/A
3853N/Acnid --> id | id "__pt__" cnlen "_" arglist
3853N/A
3853N/A######################### ARGUMENT LISTS #########################
3853N/A
3853N/Aarglist --> arg | arglist arg
3853N/A
3853N/Aarg --> modlist arg2 | "X" modlist arg2 lit
3853N/A
3853N/Amodlist --> mod | modlist mod
3853N/A
3853N/Amod --> "" | "U" | "C" | "V" | "S" | "P" | "R" | arr | mptr
3853N/A
3853N/Aarr --> "A" num "_"
3853N/A
3853N/Amptr --> "M" cname
3853N/A
3853N/Aarg2 --> fund | cname | funcp | repeat1 | repeat2
3853N/A
3853N/Afund --> "v" | "c" | "s" | "i" | "l" | "f" | "d" | "r" | "e"
3853N/A
3853N/Afuncp --> "F" arglist "_" arg
3853N/A
3853N/Arepeat1 --> "T" digit | "T" digit digit
3853N/A
3853N/Arepeat2 --> "N" digit digit | "N" digit digit digit
3853N/A
3853N/Alit --> litnum | zero | litmptr | cnlen id | sptr
3853N/A
3853N/Alitnum --> "L" digit lnum | "L" digit digit "_" lnum
3853N/A
3853N/Alitmptr --> "LM" num "_" litnum "_" cnlen id
3853N/A
3853N/Alnum --> num | "n" num
3853N/A
3853N/Asptr --> cnlen id "__" cname
3853N/A
zero --> 0
######################### LOW LEVEL STUFF #########################
digit --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
id --> special | regid
special --> "__ct" | "__pp" # etc.
regid --> letter | letter restid
restid --> letter | digit | restid letter | restid digit
letter --> "A"-"Z" | "a" - "z" | "_"
num --> digit | num digit