Re: Name Mangling: Case-sensitive -> insensitive

torbenm@diku.dk (Torben AEgidius Mogensen)
4 Dec 1999 22:30:57 -0500

          From comp.compilers

Related articles
Name Mangling: Case-sensitive -> insensitive dstarner98@aasaa.ofe.org (1999-12-03)
Re: Name Mangling: Case-sensitive -> insensitive torbenm@diku.dk (1999-12-04)
Re: Name Mangling: Case-sensitive -> insensitive gsc@zip.com.au (1999-12-04)
| List of all articles for this month |

From: torbenm@diku.dk (Torben AEgidius Mogensen)
Newsgroups: comp.compilers
Date: 4 Dec 1999 22:30:57 -0500
Organization: Department of Computer Science, U of Copenhagen
References: 99-12-018
Keywords: translator

dstarner98@aasaa.ofe.org (David Starner) writes:


>I'm working on a compiler that compiles Modula-3 into Ada. Part of the
>problem is that Modula-3 is case-sensitive, whereas Ada is
>not. Modula-3 also allows double-underlines in identifiers, while Ada
>doesn't. Is there anyway I can map the M3 identifers into Ada and keep
>it recognizable as the original identifer (for debugging and stuff)?


>[I suppose you could mangle in some character that means case shift.
>Worked for those old Flexowriters. -John]


You can do this in two ways:


  1) Use a systematic injective string transformation, as John
        suggests.


  2) Collect all names in the program and find the names that will
        clash when translated to lower case and multiple-underlines are
        collapsed. Then apply transformation to these names only (making
        sure the transformed names don't clash with any original
        untransformed names). You can apply this to individual scopes to
        minimize the amount of renaming.


The first option is, obviously, simpler, but the other makes fewer
changes and hence aids readability.


A possible string transformation along the lines that John suggests is
to use underlines as escape-characters (similar to backslash in C
strings): Lower case letters are unchanged. Upper case letters are
translated to lower case, but preceeded by an underscore. A sequence
of underscores is translated to a single underscore followed by a
digit indicating the number of underscores (so a single underscore
would be translated to _1 while a double becomes _2).


If names are not allowed to start with underscores, you can let the
underscore follow the letter/digit instead of preceeding it.


Torben Mogensen (torbenm@diku.dk)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.