📄 eicmod.c
字号:
/* eicmod.c * * (C) Copyright Apr 15 1995, Edmond J. Breen. * ALL RIGHTS RESERVED. * This code may be copied for personal, non-profit use only. * */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include "typemod.h"#include "global.h"#include "lexer.h"#include "func.h"#include "xalloc.h"#include "typesets.h"#include "preproc.h"#include "cdecl.h"#include "error.h"#include "emitter.h"#include "symbol.h"extern char EiC_LEXEM[];extern token_t *token;int EiC_listcodeON = 0;int EiC_lineNums = 0;int EiC_interpON = 1;int EiC_TIMER = 0;int EiC_SHOWLINE = 0;int EiC_memdumpON = 0;int EiC_memtraceON = 0;int EiC_traceON = 0;int EiC_traceFunc = 0;int EiC_verboseON = 0;int interfaceON=0;int EiC_interActive=1;int EiC_showIncludes = 0;int adjustNum = 0;static void outputval(int obj, void *v){ switch (obj) { case t_char: fprintf(stdout,"%d",*(char *) v);break; case t_uchar: fprintf(stdout,"%d",*(unsigned char *) v); break; case t_short: fprintf(stdout,"%d",*(short *) v); break; case t_ushort: fprintf(stdout,"%d",*(unsigned short*) v); break; case t_int: fprintf(stdout,"%d",*(int *) v); break; case t_uint: fprintf(stdout,"%u",*(unsigned *) v); break; case t_long: fprintf(stdout,"%ld",*(long *) v); break; case t_ulong: fprintf(stdout,"%lu",*(long *) v); break;#ifndef NO_LONG_LONG case t_llong: fprintf(stdout,"%Ld",*(eic_llong *) v); break;#else case t_llong: fprintf(stdout,"%ld",*(eic_llong *) v); break;#endif case t_float: fprintf(stdout,"%.9g",*(float *) v); break; case t_double: fprintf(stdout,"%.9g",*(double *) v); break; case t_lval: case t_pointer: fprintf(stdout,"%p",(void*)*(long *) v); break; case t_void: fprintf(stdout,"(void)"); break; case t_enum: fprintf(stdout,"(enumeration)"); break; case STR: fprintf(stdout,"%.100s",*(char **) v); break; default: fprintf(stdout,"Unknown type"); break; }}static void showstruct(AR_t * arg){ int i, t; struct_t *S; char *D; S = (struct_t *) EiC_getInf(arg->type); D = arg->v.p.p; fputc('{', stdout); if (!D) fputs("(null struct) ", stdout); else for (i = 0; i < S->n; i++) { switch ((t = EiC_gettype(S->type[i]))) { case t_array: fputs("Array", stdout); break; case t_union: fputs("Union",stdout); break; case t_struct: fputs("Struct", stdout); break; default: outputval(t, &D[S->offset[i]]); break; } fputc(',', stdout); } fputs("\b}", stdout);}void EiC_showvalue(AR_t * arg){ int t; if(!EiC_interActive || !arg->type) return ; fputc('\t', stdout); t = EiC_gettype(arg->type); if(isconst(arg->type) && t != t_pointer) { outputval(t, &arg->v); fputc('\n', stdout); return; } switch ((t = EiC_gettype(arg->type))) { case t_union: fputs("(Union)",stdout); break; case t_struct: showstruct(arg); break; case t_char: case t_uchar: case t_short: case t_ushort: outputval(t_int, &arg->v.ival); break; case t_float: outputval(t_double, &arg->v.ival); break; case t_array: case t_pointer: if (EiC_gettype(nextType(arg->type)) == t_char) t = STR; else t = t_pointer; default: outputval(t, &arg->v); break; } fputc('\n', stdout);}static void EiC_showdectype(type_expr *, int, FILE *);static void showFunc(type_expr **t, FILE *fp){ static int level = 0; func_t *F; int i,k; fputs("Func (", fp); F = (func_t *) EiC_getInf(*t); level++; if (F && getFNp(F)) { for (i = 0; i < getFNp(F); i++) { fputc('\n',fp); for(k=0;k<level;k++) fputc('\t',fp); if(getFPname(F,i)) printf("%s: ",getFPname(F,i)); EiC_showdectype(getFPty(F,i), 0,fp); if(i < getFNp(F)-1) fputs(",", fp); } } fputc('\n',fp); for(k=0;k<level;k++) fputc('\t',fp); fputs(") returning ", fp); if(nextType(*t)) { *t = nextType(*t); EiC_showdectype(*t,0,fp); if(*t) while(nextType(*t)) *t = nextType(*t); } if(F && getFComm(F)) fprintf(fp,"\n\n /* %s/\n", getFComm(F)); /**/ level--; } static void EiC_showdectype(type_expr * t, int expand, FILE *fp){ struct_t *S; int i; static int level = 0; while (t) { if(isconst(t) || isconstp(t)) fputs("const ",fp); switch (EiC_gettype(t)) { case t_var: fputs("...", fp); break; case t_enum: fputs("enum ", fp); break; case t_char: fputs("char ", fp); break; case t_uchar: fputs("unsigned char ", fp); break; case t_short: fputs("short ", fp); break; case t_ushort:fputs("unsigned short ", fp); break; case t_int: fputs("int ", fp); break; case t_uint: fputs("unsigned ", fp); break; case t_long: fputs("long int ", fp); break; case t_ulong: fputs("unsigned long int ", fp); break; case t_llong: fputs("long long ",fp); break; case t_float: fputs("float ", fp); break; case t_double:fputs("double ", fp); break; case t_pointer: if(isunsafe(t)) fputs("unsafe ", fp); /*else if(issafe(t)) fputs("safe ", fp);*/ fputs("* ", fp); break; case t_void: fputs("void ", fp); break; case t_hidden: fputs("hidden ",fp); break; case t_funcdec: fputs("dec_", fp); showFunc(&t,fp); break; case t_func: showFunc(&t,fp); break; case t_builtin: fputs("Builtin ",fp); showFunc(&t,fp); break; case t_array: fprintf(fp,"ARY[%d]",(int) EiC_getInf(t)); break; case t_union: case t_struct: S = EiC_getInf(t); if(!S) { fputs("Incomplete", fp); break; } if (EiC_gettype(t) == t_struct) fprintf(fp,"struct: size %u bytes",S->tsize); else fprintf(fp,"union: size %u bytes",S->tsize); if (expand) { level++; fputc('\n', fp); if (level <= 2) { int j; for (i = 0; i < S->n; i++) { for (j = 0; j < level; j++) fputc('\t', fp); fputs(S->id[i], fp); fputs(" -> ", fp); EiC_showdectype(S->type[i], expand,fp); fputc('\n', fp); } } level--; } break; case t_ref: fputs("Reference ",fp);break; case ID: fputs("Identifier ", fp); break; default: fputs("Uknown identifier", fp); return; } t = nextType(t); }}static int IsObject(int t){ if(t != t_func && t !=t_funcdec && t != t_builtin) return 1; return 0;}int EiC_IsFunc(int t){ return !IsObject(t);}static void displaySclass(symentry_t *sym){ /* display storage class */ if (sym->sclass == c_typedef) fputs("typedef ", stdout); else if(sym->sclass & c_private) fprintf(stdout,"private to %s: ", sym->fname); else if (sym->sclass & c_static) fputs("static ", stdout); if (sym->typequal == q_const) fputs("const ", stdout); else if (sym->typequal == q_volatile) fputs("volatile ", stdout);} static void showtab(int tab, int expand, token_t * e1, char *fname, int allowed()){ int i, t; symentry_t *sym; for (i = 0; i < HSIZE; i++) for (sym = EiC_HTAB[i]; sym; sym = sym->next) { if ((t = EiC_gettype(sym->type)) == t_eic || sym->nspace != tab) continue; if(e1 && e1->Type && ! EiC_sametypes(e1->Type,sym->type)) continue; /*printf("looking at [%s]\n",sym->fname);*/ if(fname && strcmp(fname,sym->fname) != 0) continue; if(allowed && !allowed(t)) continue; displaySclass(sym); fputs(sym->id, stdout); fputs(" -> ", stdout); EiC_showdectype(sym->type, expand,stdout); fputc('\n', stdout); }}static int show(void){ int t; int h = EiC_work_tab; AR_t arg; EiC_work_tab = stand_tab; if ((t = EiC_lexan()) == ID || t == TYPENAME) { if(!EiC_showMacro(token->Val.sym->id)) { /* test macros first */ t = EiC_gettype(token->Val.sym->type); if (t == ID) { EiC_remsym(token->Val.sym); /* * check for struct/union tag name. */ if ((token->Val.sym = EiC_lookup(tag_tab, EiC_LEXEM)) == NULL) { EiC_error("Unknown identifier %s",EiC_LEXEM); return 0; } fputs("Tag::",stdout); } displaySclass(token->Val.sym); fputs(token->Val.sym->id, stdout); fputs(" -> ", stdout); EiC_showdectype(token->Val.sym->type, 1,stdout); fputc('\n',stdout); /* -----------------------------------------------------*/ t = EiC_gettype(token->Val.sym->type); if (! (token->Val.sym->sclass == c_typedef || (t==t_builtin) || (t==t_func) || (t==t_funcdec))) { fputs("value= ", stdout); arg.v=EiC_ENV->AR[token->Val.sym->val.ival].v; arg.type = token->Val.sym->type; EiC_showvalue(&arg); } /* -------------------------------------------------*/ if (t == t_func && EiC_listcodeON) { if (EiC_ENV->AR[token->Val.sym->val.ival].v.p.p) EiC_listcode(EiC_ENV->AR[token->Val.sym->val.ival].v.p.p); } } else EiC_remsym(token->Val.sym); } else EiC_error("Expected identifier"); EiC_work_tab = h; return 1;}static char *getNextInput(){ char c, *p; static char buf[256]; while(isspace(c = EiC_nextchar())); p = buf; while( c && c != DONE && !isspace(c)) { *p++ = c; c = EiC_nextchar(); } *p = '\0'; return buf;}static int ResetEiC(){ char *buf; void EiCp_ResetStart(void); void EiCp_setResetStart(void); buf = getNextInput(); if(buf[0]) { if(strcmp(buf,"here") == 0) EiCp_setResetStart(); else EiC_error("Unrecgonised command `%s' for reset",buf); } else EiCp_ResetStart(); return 0;}static int filesCommand(void){ void EiC_showIncludedFiles(void); void EiC_showFileMacros(char *fname); char EiC_nextchar(void); int EiC_IsIncluded(char *fname); char *buf; buf = getNextInput(); if(buf[0]) { if(!EiC_IsIncluded(buf)) EiC_warningerror("Failed to find %s",buf); else { EiC_showFileMacros(buf); showtab(stand_tab,0,NULL,buf,IsObject); showtab(stand_tab,0,NULL,buf,EiC_IsFunc); } } else EiC_showIncludedFiles(); return 1;}static int clearCommand(void){ /* * syntax :clear file1[,file]* */ int EiC_lutClearFileEntries(char *FileName); void EiC_ClearFileMacros(char *fname); void EiC_rmIncludeFileName(char *fname); char EiC_nextchar(void); int EiC_IsIncluded(char *fname); char *buf; buf = getNextInput(); if(buf[0]) { char *p; do { p = strchr(buf,','); if(p) *p = 0; if(!EiC_IsIncluded(buf)) EiC_warningerror("Failed to find %s",buf); else { int r = EiC_lutClearFileEntries(buf); EiC_ClearFileMacros(buf); if(r) EiC_rmIncludeFileName(buf); } if(p) buf = p + 1; }while(p); } else EiC_error("Expected file name"); return 1;}static int setnextinf(void *info){ int i, t; symentry_t *sym; type_expr *type; for (i = 0; i < HSIZE; i++) for (sym = EiC_HTAB[i]; sym; sym = sym->next) if ((t = EiC_gettype(sym->type)) == t_union || t == t_struct) for (type = sym->type; type; type = nextType(type)) if (type->alias && EiC_getInf(type) == info) { type->alias = 0; return 1; } return 0;}static void checktype(type_expr * type){ int t; while (type) { if ((t = EiC_gettype(type)) == t_struct || t == t_union) if (!type->alias) if (setnextinf(EiC_getInf(type)))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -