home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gnu
/
f2c-1993.04.28-src.lha
/
f2c-1993.04.28
/
src
/
names.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-28
|
20KB
|
746 lines
/****************************************************************
Copyright 1990, 1992, 1993 by AT&T Bell Laboratories and Bellcore.
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the names of AT&T Bell Laboratories or
Bellcore or any of their entities not be used in advertising or
publicity pertaining to distribution of the software without
specific, written prior permission.
AT&T and Bellcore disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall AT&T or Bellcore be liable for
any special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
****************************************************************/
#include "defs.h"
#include "output.h"
#include "names.h"
#include "iob.h"
/* Names generated by the translator are guaranteed to be unique from the
Fortan names because Fortran does not allow underscores in identifiers,
and all of the system generated names do have underscores. The various
naming conventions are outlined below:
FORMAT APPLICATION
----------------------------------------------------------------------
io_# temporaries generated by IO calls; these will
contain the device number (e.g. 5, 6, 0)
ret_val function return value, required for complex and
character functions.
ret_val_len length of the return value in character functions
ssss_len length of character argument "ssss"
c_# member of the literal pool, where # is an
arbitrary label assigned by the system
cs_# short integer constant in the literal pool
t_# expression temporary, # is the depth of arguments
on the stack.
L# label "#", given by user in the Fortran program.
This is unique because Fortran labels are numeric
pad_# label on an init field required for alignment
xxx_init label on a common block union, if a block data
requires a separate declaration
*/
/* generate variable references */
char *c_type_decl (type, is_extern)
int type, is_extern;
{
static char buff[100];
switch (type) {
case TYREAL: if (!is_extern || !forcedouble)
{ strcpy (buff, "real");break; }
case TYDREAL: strcpy (buff, "doublereal"); break;
case TYCOMPLEX: if (is_extern)
strcpy (buff, Ansi ? "/* Complex */ VOID"
: "/* Complex */ int");
else
strcpy (buff, "complex");
break;
case TYDCOMPLEX:if (is_extern)
strcpy (buff, Ansi ? "/* Double Complex */ VOID"
: "/* Double Complex */ int");
else
strcpy (buff, "doublecomplex");
break;
case TYADDR:
case TYINT1:
case TYSHORT:
case TYLONG:
#ifdef TYQUAD
case TYQUAD:
#endif
case TYLOGICAL1:
case TYLOGICAL2:
case TYLOGICAL: strcpy(buff, typename[type]);
break;
case TYCHAR: if (is_extern)
strcpy (buff, Ansi ? "/* Character */ VOID"
: "/* Character */ int");
else
strcpy (buff, "char");
break;
case TYUNKNOWN: strcpy (buff, "UNKNOWN");
/* If a procedure's type is unknown, assume it's a subroutine */
if (!is_extern)
break;
/* Subroutines must return an INT, because they might return a label
value. Even if one doesn't, the caller will EXPECT it to. */
case TYSUBR: strcpy (buff, "/* Subroutine */ int");
break;
case TYERROR: strcpy (buff, "ERROR"); break;
case TYVOID: strcpy (buff, "void"); break;
case TYCILIST: strcpy (buff, "cilist"); break;
case TYICILIST: strcpy (buff, "icilist"); break;
case TYOLIST: strcpy (buff, "olist"); break;
case TYCLLIST: strcpy (buff, "cllist"); break;
case TYALIST: strcpy (buff, "alist"); break;
case TYINLIST: strcpy (buff, "inlist"); break;
case TYFTNLEN: strcpy (buff, "ftnlen"); break;
default: sprintf (buff, "BAD DECL '%d'", type);
break;
} /* switch */
return buff;
} /* c_type_decl */
char *new_func_length()
{ return "ret_val_len"; }
char *new_arg_length(arg)
Namep arg;
{
static char buf[64];
sprintf (buf, "%s_len", arg->fvarname);
return buf;
} /* new_arg_length */
/* declare_new_addr -- Add a new local variable to the function, given a
pointer to an Addrblock structure (which must have the uname_tag set)
This list of idents will be printed in reverse (i.e., chronological)
order */
void
declare_new_addr (addrp)
struct Addrblock *addrp;
{
extern chainp new_vars;
new_vars = mkchain((char *)cpexpr((expptr)addrp), new_vars);
} /* declare_new_addr */
wr_nv_ident_help (outfile, addrp)
FILE *outfile;
struct Addrblock *addrp;
{
int eltcount = 0;
if (addrp == (struct Addrblock *) NULL)
return;
if (addrp -> isarray) {
frexpr (addrp -> memoffset);
addrp -> memoffset = ICON(0);
eltcount = addrp -> ntempelt;
addrp -> ntempelt = 0;
addrp -> isarray = 0;
} /* if */
out_addr (outfile, addrp);
if (eltcount)
nice_printf (outfile, "[%d]", eltcount);
} /* wr_nv_ident_help */
int nv_type_help (addrp)
struct Addrblock *addrp;
{
if (addrp == (struct Addrblock *) NULL)
return -1;
return addrp -> vtype;
} /* nv_type_help */
/* lit_name -- returns a unique identifier for the given literal. Make
the label useful, when possible. For example:
1 -> c_1 (constant 1)
2 -> c_2 (constant 2)
1000 -> c_1000 (constant 1000)
1000000 -> c_b<memno> (big constant number)
1.2 -> c_1_2 (constant 1.2)
1.234345 -> c_b<memno> (big constant number)
-1 -> c_n1 (constant -1)
-1.0 -> c_n1_0 (constant -1.0)
.true. -> c_true (constant true)
.false. -> c_false (constant false)
default -> c_b<memno> (default label)
*/
char *lit_name (litp)
struct Literal *litp;
{
static char buf[CONST_IDENT_MAX];
ftnint val;
if (litp == (struct Literal *) NULL)
return NULL;
switch (litp -> littype) {
case TYINT1:
val = litp -> litval.litival;
if (val >= 256 || val < -255)
sprintf (buf, "c_b%d", litp -> litnum);
else if (val < 0)
sprintf (buf, "ci1_n%ld", -val);
else
sprintf(buf, "ci1__%ld", val);
case TYSHORT:
val = litp -> litval.litival;
if (val >= 32768 || val <= -32769)
sprintf (buf, "c_b%d", litp -> litnum);
else if (val < 0)
sprintf (buf, "cs_n%ld", -val);
else
sprintf (buf, "cs__%ld", val);
break;
case TYLONG:
#ifdef TYQUAD
case TYQUAD:
#endif
val = litp -> litval.litival;
if (val >= 100000 || val <= -10000)
sprintf (buf, "c_b%d", litp -> litnum);
else if (val < 0)
sprintf (buf, "c_n%ld", -val);
else
sprintf (buf, "c__%ld", val);
break;
case TYLOGICAL1:
case TYLOGICAL2:
case TYLOGICAL:
sprintf (buf, "c_%s", (litp -> litval.litival
? "true" : "false"));
break;
case TYREAL:
case TYDREAL:
/* Given a limit of 6 or 8 character on external names, */
/* few f.p. values can be meaningfully encoded in the */
/* constant name. Just going with the default cb_# */
/* seems to be the best course for floating-point */
/* constants. */
case TYCHAR:
/* Shouldn't be any of these */
case TYADDR:
case TYCOMPLEX:
case TYDCOMPLEX:
case TYSUBR:
default:
sprintf (buf, "c_b%d", litp -> litnum);
} /* switch */
return buf;
} /* lit_name */
char *
comm_union_name(count)
int count;
{
static char buf[12];
sprintf(buf, "%d", count);
return buf;
}
/* wr_globals -- after every function has been translated, we need to
output the global declarations, such as the static table of constant
values */
wr_globals (outfile)
FILE *outfile;
{
struct Literal *litp, *lastlit;
extern int hsize;
extern char *lit_name();
char *litname;
int did_one, t;
struct Constblock cb;
ftnint x, y;
if (nliterals == 0)
return;
lastlit = litpool + nliterals;
did_one = 0;
for (litp = litpool; litp < lastlit; litp++) {
if (!litp->lituse)
continue;
litname = lit_name(litp);
if (!did_on