⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printsym.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 1983 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)printsym.c	5.7 (Berkeley) 6/1/90";#endif /* not lint *//* * Printing of symbolic information. */#include "defs.h"#include "symbols.h"#include "languages.h"#include "printsym.h"#include "tree.h"#include "eval.h"#include "mappings.h"#include "process.h"#include "runtime.h"#include "machine.h"#include "names.h"#include "keywords.h"#include "main.h"#include <ctype.h>#ifndef public#endif/* * Maximum number of arguments to a function. * This is used as a check for the possibility that the stack has been * overwritten and therefore a saved argument pointer might indicate * to an absurdly large number of arguments. */#define MAXARGSPASSED 20/* * Return a pointer to the string for the name of the class that * the given symbol belongs to. */private String clname[] = {    "bad use", "constant", "type", "variable", "array", "array",    "dynarray", "subarray", "fileptr", "record", "field",    "procedure", "function", "funcvar",    "ref", "pointer", "file", "set", "range", "label", "withptr",    "scalar", "string", "program", "improper", "variant",    "procparam", "funcparam", "module", "tag", "common", "extref", "typeref"};public String classname(s)Symbol s;{    return clname[ord(s->class)];}/* * Note the entry of the given block, unless it's the main program. */public printentry(s)Symbol s;{    if (s != program) {	printf("\nentering %s ", classname(s));	printname(stdout, s);	printf("\n");    }}/* * Note the exit of the given block */public printexit(s)Symbol s;{    if (s != program) {	printf("leaving %s ", classname(s));	printname(stdout, s);	printf("\n\n");    }}/* * Note the call of s from t. */public printcall(s, t)Symbol s, t;{    printf("calling ");    printname(stdout, s);    printparams(s, nil);    printf(" from %s ", classname(t));    printname(stdout, t);    printf("\n");}/* * Note the return from s.  If s is a function, print the value * it is returning.  This is somewhat painful, since the function * has actually just returned. */public printrtn(s)Symbol s;{    register Symbol t;    register int len;    Boolean isindirect;    printf("returning ");    if (s->class == FUNC && (!istypename(s->type,"void"))) {	len = size(s->type);	if (canpush(len)) {	    t = rtype(s->type);	    isindirect = (Boolean) (t->class == RECORD or t->class == VARNT);	    pushretval(len, isindirect);	    printval(s->type);	    putchar(' ');	} else {	    printf("(value too large) ");	}    }    printf("from ");    printname(stdout, s);    printf("\n");}/* * Print the values of the parameters of the given procedure or function. * The frame distinguishes recursive instances of a procedure. * * If the procedure or function is internal, the argument count is * not valid so we ignore it. */public printparams(f, frame)Symbol f;Frame frame;{    Symbol param;    int n, m, s;    n = nargspassed(frame);    if (isinternal(f)) {	n = 0;    }    printf("(");    param = f->chain;    if (param != nil or n > 0) {	m = n;	if (param != nil) {	    for (;;) {		s = psize(param) div sizeof(Word);		if (s == 0) {		    s = 1;		}		m -= s;		if (showaggrs) {		    printv(param, frame);		} else {		    printparamv(param, frame);		}		param = param->chain;	    if (param == nil) break;		printf(", ");	    }	}	if (m > 0) {	    if (m > MAXARGSPASSED) {		m = MAXARGSPASSED;	    }	    if (f->chain != nil) {		printf(", ");	    }	    for (;;) {		--m;		printf("0x%x", argn(n - m, frame));	    if (m <= 0) break;		printf(", ");	    }	}    }    printf(")");}/* * Test if a symbol should be printed.  We don't print files, * for example, simply because there's no good way to do it. * The symbol must be within the given function. */public Boolean should_print(s)Symbol s;{    Boolean b;    register Symbol t;    switch (s->class) {	case VAR:	case FVAR:	    if (isparam(s)) {		b = false;	    } else {		t = rtype(s->type);		if (t == nil) {		    b = false;		} else {		    switch (t->class) {			case FILET:			case SET:			case BADUSE:			    b = false;			    break;			default:			    b = true;			    break;		    }		}	    }	    break;	default:	    b = false;	    break;    }    return b;}/* * Print out a parameter value. * * Since this is intended to be printed on a single line with other information * aggregate values are not printed. */public printparamv (p, frame)Symbol p;Frame frame;{    Symbol t;    t = rtype(p->type);    switch (t->class) {	case ARRAY:	case OPENARRAY:	case DYNARRAY:	case SUBARRAY:	    t = rtype(t->type);	    if (compatible(t, t_char)) {		printv(p, frame);	    } else {		printf("%s = (...)", symname(p));	    }	    break;	case RECORD:	    printf("%s = (...)", symname(p));	    break;	default:	    printv(p, frame);	    break;    }}/* * Print the name and value of a variable. */public printv(s, frame)Symbol s;Frame frame;{    Address addr;    int len;    if (isambiguous(s) and ismodule(container(s))) {	printname(stdout, s);	printf(" = ");    } else {	printf("%s = ", symname(s));    }    if (isvarparam(s) and not isopenarray(s)) {	rpush(address(s, frame), sizeof(Address));	addr = pop(Address);    } else {	addr = address(s, frame);    }    len = size(s);    if (not canpush(len)) {	printf("*** expression too large ***");    } else if (isreg(s)) {	push(Address, addr);	printval(s->type);    } else {	rpush(addr, len);	printval(s->type);    }}/* * Print out the name of a symbol. */public printname(f, s)File f;Symbol s;{    if (s == nil) {	fprintf(f, "(noname)");    } else if (s == program) {	fprintf(f, ".");    } else if (isredirected() or isambiguous(s)) {	printwhich(f, s);    } else {	fprintf(f, "%s", symname(s));    }}/* * Print the fully specified variable that is described by the given identifer. */public printwhich(f, s)File f;Symbol s;{    printouter(f, container(s));    fprintf(f, "%s", symname(s));}/* * Print the fully qualified name of each symbol that has the same name * as the given symbol. */public printwhereis(f, s)File f;Symbol s;{    register Name n;    register Symbol t;    checkref(s);    n = s->name;    t = lookup(n);    printwhich(f, t);    t = t->next_sym;    while (t != nil) {	if (t->name == n) {	    putc(' ', f);	    printwhich(f, t);	}	t = t->next_sym;    }    putc('\n', f);}private printouter(f, s)File f;Symbol s;{    Symbol outer;    if (s != nil) {	outer = container(s);	if (outer != nil and outer != program) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -