📄 decl.c
字号:
/*
Copyright 1994-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
This program is derived from the cc68k complier by
Matthew Brandt (mattb@walkingdog.net)
You may contact the author of this derivative at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
*/
/*
* handle ALL declarative statements
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "lists.h"
#include "expr.h"
#include "c.h"
#include "ccerr.h"
#define LONGS /* enable 64 bit support */
extern int sys_inc;
extern int prm_c99;
extern int funcnesting;
extern ENODE *expr_runup[];
extern ENODE *expr_rundown[];
extern int expr_updowncount;
extern int incatchclause;
extern int intemplateargs;
extern LIST *local_using_list, *local_tag_using_list;
extern TYP stdenum;
extern int prm_bss;
extern int bssbytes, databytes;
extern int statictemplate;
;
extern NAMESPACE *thisnamespace;
extern SYM *templateSP;
extern int prm_debug, prm_farkeyword;
extern int stdinttype, stdunstype, stdintsize, stdldoublesize, stdaddrsize, stdwchar_tsize;
extern int stdshortsize, stdlongsize, stdlonglongsize, stdfloatsize, stddoublesize, stdenumsize;
extern int strucadd, strucmod;
extern TYP stdint;
extern LIST *instantiated_inlines;
extern int classhead, vtabhead;
extern int lineno, errlineno;
extern int packdata[], packlevel;
extern int prm_cmangle, prm_microlink, prm_asmfile;
extern char laststr[];
extern int global_flag;
extern HASHREC **gsyms;
extern TABLE lsyms, ltags, oldltag;
extern SNODE *cbautoinithead, *cbautoinittail;
extern int prm_revbits;
extern int prm_68020;
extern int prm_ansi;
extern SYM *currentfunc;
extern int prm_cplusplus;
extern char *tn_unnamed;
extern TYP stdconst;
extern enum e_sym lastst;
extern char lastid[];
extern int block_nesting;
extern long nextlabel;
extern char *cpp_funcname_tab[];
extern int stdmemberptrsize;
extern ENODE *block_rundown;
extern char *infile;
extern short *lptr;
extern int lastch;
extern TABLE *tagtable;
extern SYM *thisenode;
extern TYP stdvoidfunc;
extern int skm_closepa[];
extern int nodeclfunc;
extern int virtualfuncs;
extern int infuncargs;
extern SYM *parm_namespaces[20][100];
extern int parm_ns_counts[20];
extern int parm_ns_level;
extern int parsing_params;
int inarrayindexparsing;
TABLE *funcparmtable;
int conscount;
int increatingtemplateargs;
int indefaultinit;
ILIST *deferredFunctions;
int structlevel;
int aFriend;
int recordingTemplate;
int templateFunc;
int templateLookup;
int recordingClassFunc;
char *Cstr = "C";
SYM *declclass;
SYM *typequal;
int unnamedstructcount;
int nullnamecount;
int mangleflag;
int skm_declopenpa[] =
{
semicolon, comma, openpa, eq, 0
};
int skm_declclosepa[] =
{
semicolon, comma, closepa, eq, 0
};
int skm_declcomma[] =
{
semicolon, comma, begin, eq, 0
};
int skm_declbegin[] =
{
begin, semicolon, 0
};
int skm_declclosebr[] =
{
comma, closebr, eq, semicolon, 0
};
int skm_declend[] =
{
semicolon, comma, end, eq, 0
};
int skm_tempend[] =
{
semicolon, comma, end, 0
};
int skm_decl[] =
{
semicolon, kw_int, kw_long, kw_short, kw_char, kw_float, kw_bool, kw_double,
kw_struct, kw_union, kw_enum, kw_unsigned, kw_signed, kw_auto,
kw_extern, kw_static, kw_restrict, kw_register, kw_typedef, id, kw_void,
kw_wchar_t, 0
};
int mainfunc;
TYP *head = 0, **headptr;
TYP *tail = 0;
char declid[100];
int ispascal, isstdcall, iscdecl, isindirect, isexport, isimport;
char *importname;
LIST *localfuncs, *localdata; /* 68k */
struct template *currentTemplate, *searchTemplate;
int inprototype;
static int memberptr;
static SYM *lastdecl;
static int pcount = 0;
static int bittype = - 1;
static int curbit = 0;
int sizeoflastbit;
static int curofs = 0;
int manglelevel;
static int intflag, farflag, segflag;
int cppflags;
int defaulttype;
static int decl3size;
static int templatebufSize;
static short *templatebuf;
static int templatebufIndex;
static int encounteredflexarray;
void templateWade(void);
void declini(void)
/*
* init
*/
{
funcparmtable = 0;
inarrayindexparsing = FALSE;
increatingtemplateargs = FALSE;
bittype = - 1;
head = tail = 0;
declid[0] = 0;
pcount = 0;
mangleflag = TRUE;
manglelevel = 0;
encounteredflexarray = FALSE;
declclass = 0;
localfuncs = 0;
localdata = 0;
unnamedstructcount = 0;
templatebufSize = templatebufIndex = 0;
structlevel = 0;
deferredFunctions = 0;
indefaultinit = 0;
} int imax(int i, int j)
{
return (i > j) ? i : j;
}
//-------------------------------------------------------------------------
char *litlate(char *s)
{
char *p;
p = xalloc(strlen(s) + 1);
strcpy(p, s);
return p;
}
//-------------------------------------------------------------------------
TYP *maketype(int bt, int siz)
/*
* Create a type list entry
*/
{
TYP *tp;
tp = xalloc(sizeof(TYP));
tp->val_flag = 0;
tp->bits = tp->startbit = - 1;
tp->size = siz;
tp->type = bt;
tp->sp = 0;
tp->cflags = 0;
tp->uflags = 0;
tp->lst.head = tp->lst.tail = 0;
return tp;
}
//-------------------------------------------------------------------------
TYP *cponetype(TYP *t)
/*
* Copy a entry
*/
{
TYP *tp;
tp = xalloc(sizeof(TYP));
tp->type = t->type;
tp->val_flag = t->val_flag;
tp->cflags = t->cflags;
tp->bits = t->bits;
tp->startbit = t->startbit;
tp->size = t->size;
tp->lst = t->lst;
tp->btp = t->btp;
tp->sp = t->sp;
tp->uflags = t->uflags;
tp->typeindex = t->typeindex;
tp->enumlist = t->enumlist;
tp->alignment = t->alignment;
tp->esize = t->esize;
return tp;
}
//-------------------------------------------------------------------------
TYP *copytype(TYP *itp, int flags)
/*
* copy a type tree
*/
{
TYP *head, *tail, *x = itp, *reclone = 0;
while (x->type == bt_pointer || x->type == bt_farpointer || x->type ==
bt_segpointer || x->type == bt_ref)
x = x->btp;
if (isstructured(x))
if (!x->lst.head)
{
reclone = x;
}
if (!itp->typeindex)
itp->typeindex = xalloc(sizeof(int));
head = tail = cponetype(itp);
while (itp->type == bt_pointer || itp->type == bt_farpointer || itp->type
== bt_segpointer || itp->type == bt_ref)
{
tail = tail->btp = cponetype(itp->btp);
itp = itp->btp;
}
if (itp->type == bt_func || itp->type == bt_ifunc)
{
tail->btp = cponetype(itp->btp);
}
else
{
tail->cflags |= flags;
}
if (reclone)
{
x = head;
while (x->type == bt_pointer || x->type == bt_farpointer || x->type ==
bt_segpointer)
x = x->btp;
x->reclone = reclone->reclone;
reclone->reclone = x;
}
return head;
}
//-------------------------------------------------------------------------
SYM *parsetype(SYM *typesp, int pass)
{
if (prm_cplusplus && typesp->istemplatevar && recordingTemplate) {
while (lastst == classsel) {
getsym();
if (lastst != id)
break;
getsym();
}
return typesp;
}
while (prm_cplusplus && lastst == classsel)
{
if (typesp->istemplate)
templateMatchCheck(typesp, currentTemplate);
typequal = typesp;
if (typequal->tp->type == bt_templateplaceholder)
typequal = typequal->tp->lst.head;
getsym();
if (lastst == kw_operator || lastst == compl)
{
typesp = 0;
break;
}
else if (lastst != id)
{
generror(ERR_IDEXPECT, 0, 0);
break;
}
else if (!(typesp = tcsearch(lastid, FALSE)))
{
break;
}
else if (typesp->storage_class != sc_type && typesp->storage_class !=
sc_namespace)
break;
else
{
if (pass)
getsym();
else
{
if (isspace(lastch))
break;
getsym();
if (lastst != classsel)
{
backup(id);
break;
}
}
}
}
if (lastst == classselstar)
{
typequal = typesp;
typesp = 0;
}
return typesp;
}
//-------------------------------------------------------------------------
int decl(TABLE *table, int cppflags)
/*
* parse the declare keywords and create a basic type
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -