#include "c.h"
Include dependency graph for decl.c:

Go to the source code of this file.
Defines | |
| #define | add(x, n) (x > inttype->u.sym->u.limits.max.i-(n) ? (overflow=1,x) : x+(n)) |
| #define | bits2bytes(n) (((n) + 7)/8) |
| #define | chkoverflow(x, n) ((void)add(x,n)) |
Functions | |
| void | checklab (Symbol p, void *cl) |
| void | checkref (Symbol, void *) |
| void | compound (int loop, struct swtch *swp, int lev) |
| Symbol | dclglobal (int, char *, Type, Coordinate *) |
| Symbol | dcllocal (int, char *, Type, Coordinate *) |
| Symbol | dclparam (int, char *, Type, Coordinate *) |
| Type | dclr (Type, char **, Symbol **, int) |
| Type | dclr1 (char **, Symbol **, int) |
| void | decl (Symbol(*)(int, char *, Type, Coordinate *)) |
| void | defglobal (Symbol p, int seg) |
| void | doconst (Symbol, void *) |
| void | doextern (Symbol, void *) |
| void | doglobal (Symbol, void *) |
| Type | enumdcl (void) |
| void | exitparams (Symbol[]) |
| void | fields (Type) |
| void | finalize (void) |
| void | funcdefn (int, char *, Type, Symbol[], Coordinate) |
| void | initglobal (Symbol, int) |
| void | oldparam (Symbol, void *) |
| Symbol * | parameters (Type) |
| void | program (void) |
| Type | specifier (int *) |
| Type | structdcl (int) |
| Type | tnode (int, Type) |
| Type | typename (void) |
Variables | |
| List | autos |
| Symbol | cfunc |
| int | regcount |
| List | registers |
| Symbol | retv |
|
|
Definition at line 4 of file decl.c. Referenced by AsmCall(), LightContributionToPoint(), LightingAtSample(), TraceGrid(), VL_LightSurfaceWithVolume(), and VS_LightSurfaceWithVolume(). |
|
|
|
|
|
|
|
||||||||||||
|
Definition at line 1071 of file decl.c. References symbol::defined, error(), symbol::name, p, and Symbol. Referenced by funcdefn(). 01071 {
01072 if (!p->defined)
01073 error("undefined label `%s'\n", p->name);
01074 p->defined = 1;
01075 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 895 of file decl.c. References symbol::addressed, Aflag, assert, symbol::defined, error(), GLOBAL, isfunc, isscalar, isvolatile, level, LOCAL, symbol::name, p, PARAM, symbol::ref, regcount, symbol::sclass, symbol::scope, Symbol, symbol::type, and warning(). Referenced by compound(), finalize(), and funcdefn(). 00895 {
00896 if (p->scope >= PARAM
00897 && (isvolatile(p->type) || isfunc(p->type)))
00898 p->addressed = 1;
00899 if (Aflag >= 2 && p->defined && p->ref == 0) {
00900 if (p->sclass == STATIC)
00901 warning("static `%t %s' is not referenced\n",
00902 p->type, p->name);
00903 else if (p->scope == PARAM)
00904 warning("parameter `%t %s' is not referenced\n",
00905 p->type, p->name);
00906 else if (p->scope >= LOCAL && p->sclass != EXTERN)
00907 warning("local `%t %s' is not referenced\n",
00908 p->type, p->name);
00909 }
00910 if (p->sclass == AUTO
00911 && (p->scope == PARAM && regcount == 0
00912 || p->scope >= LOCAL)
00913 && !p->addressed && isscalar(p->type) && p->ref >= 3.0)
00914 p->sclass = REGISTER;
00915 if (level == GLOBAL && p->sclass == STATIC && !p->defined
00916 && isfunc(p->type) && p->ref)
00917 error("undefined static `%t %s'\n", p->type, p->name);
00918 assert(!(level == GLOBAL && p->sclass == STATIC && !p->defined && !isfunc(p->type)));
00919 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 835 of file decl.c. References a, append(), apply(), assert, autos, code::begin, code::block, Events::blockentry, Events::blockexit, cfunc, CHAR, checkref(), code(), Code, cp, dcllocal(), decl(), symbol::defined, definept(), enterscope(), Events::entry, events, exitscope(), expect(), foreach(), freturn(), FUNC, genident(), getchr(), i, code::identifiers, identifiers, IR, isstruct, istypename, j, kind, length(), code::level, level, LOCAL, code::locals, ltov(), NULL, p, ptr(), reachable(), symbol::ref, registers, retv, statement(), STMT, Symbol, t, tsym, symbol::type, code::types, code::u, walk(), and interface::wants_callb. Referenced by funcdefn(), and statement(). 00835 {
00836 Code cp;
00837 int nregs;
00838
00839 walk(NULL, 0, 0);
00840 cp = code(Blockbeg);
00841 enterscope();
00842 assert(level >= LOCAL);
00843 if (level == LOCAL && events.entry)
00844 apply(events.entry, cfunc, NULL);
00845 definept(NULL);
00846 expect('{');
00847 autos = registers = NULL;
00848 if (level == LOCAL && IR->wants_callb
00849 && isstruct(freturn(cfunc->type))) {
00850 retv = genident(AUTO, ptr(freturn(cfunc->type)), level);
00851 retv->defined = 1;
00852 retv->ref = 1;
00853 registers = append(retv, registers);
00854 }
00855 while (kind[t] == CHAR || kind[t] == STATIC
00856 || istypename(t, tsym) && getchr() != ':')
00857 decl(dcllocal);
00858 {
00859 int i;
00860 Symbol *a = ltov(&autos, STMT);
00861 nregs = length(registers);
00862 for (i = 0; a[i]; i++)
00863 registers = append(a[i], registers);
00864 cp->u.block.locals = ltov(®isters, FUNC);
00865 }
00866 if (events.blockentry)
00867 apply(events.blockentry, cp->u.block.locals, NULL);
00868 while (kind[t] == IF || kind[t] == ID)
00869 statement(loop, swp, lev);
00870 walk(NULL, 0, 0);
00871 foreach(identifiers, level, checkref, NULL);
00872 {
00873 int i = nregs, j;
00874 Symbol p;
00875 for ( ; (p = cp->u.block.locals[i]) != NULL; i++) {
00876 for (j = i; j > nregs
00877 && cp->u.block.locals[j-1]->ref < p->ref; j--)
00878 cp->u.block.locals[j] = cp->u.block.locals[j-1];
00879 cp->u.block.locals[j] = p;
00880 }
00881 }
00882 if (events.blockexit)
00883 apply(events.blockexit, cp->u.block.locals, NULL);
00884 cp->u.block.level = level;
00885 cp->u.block.identifiers = identifiers;
00886 cp->u.block.types = types;
00887 code(Blockend)->u.begin = cp;
00888 if (reachable(Gen))
00889 definept(NULL);
00890 if (level > LOCAL) {
00891 exitscope();
00892 expect('}');
00893 }
00894 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 203 of file decl.c. References Aflag, compose(), Coordinate, symbol::defined, interface::defsymbol, eqtype(), error(), EXTERN, externals, gettok(), glevel, GLOBAL, globals, identifiers, initglobal(), initializer(), install(), IR, isfunc, lookup(), symbol::name, NULL, p, PERM, q, relocate(), symbol::sclass, symbol::scope, symbol::seg, type::size, symbol::src, interface::stabsym, swtoseg(), Symbol, t, symbol::type, Type, symbol::u, and warning(). Referenced by funcdefn(), and program(). 00203 {
00204 Symbol p;
00205
00206 if (sclass == 0)
00207 sclass = AUTO;
00208 else if (sclass != EXTERN && sclass != STATIC) {
00209 error("invalid storage class `%k' for `%t %s'\n",
00210 sclass, ty, id);
00211 sclass = AUTO;
00212 }
00213 p = lookup(id, identifiers);
00214 if (p && p->scope == GLOBAL) {
00215 if (p->sclass != TYPEDEF && eqtype(ty, p->type, 1))
00216 ty = compose(ty, p->type);
00217 else
00218 error("redeclaration of `%s' previously declared at %w\n", p->name, &p->src);
00219
00220 if (!isfunc(ty) && p->defined && t == '=')
00221 error("redefinition of `%s' previously defined at %w\n", p->name, &p->src);
00222
00223 if (p->sclass == EXTERN && sclass == STATIC
00224 || p->sclass == STATIC && sclass == AUTO
00225 || p->sclass == AUTO && sclass == STATIC)
00226 warning("inconsistent linkage for `%s' previously declared at %w\n", p->name, &p->src);
00227
00228 }
00229 if (p == NULL || p->scope != GLOBAL) {
00230 Symbol q = lookup(id, externals);
00231 if (q) {
00232 if (sclass == STATIC || !eqtype(ty, q->type, 1))
00233 warning("declaration of `%s' does not match previous declaration at %w\n", id, &q->src);
00234
00235 p = relocate(id, externals, globals);
00236 p->sclass = sclass;
00237 } else {
00238 p = install(id, &globals, GLOBAL, PERM);
00239 p->sclass = sclass;
00240 (*IR->defsymbol)(p);
00241 }
00242 if (p->sclass != STATIC) {
00243 static int nglobals;
00244 nglobals++;
00245 if (Aflag >= 2 && nglobals == 512)
00246 warning("more than 511 external identifiers\n");
00247 }
00248 } else if (p->sclass == EXTERN)
00249 p->sclass = sclass;
00250 p->type = ty;
00251 p->src = *pos;
00252 if (t == '=' && isfunc(p->type)) {
00253 error("illegal initialization for `%s'\n", p->name);
00254 t = gettok();
00255 initializer(p->type, 0);
00256 } else if (t == '=') {
00257 initglobal(p, 0);
00258 if (glevel > 0 && IR->stabsym) {
00259 (*IR->stabsym)(p); swtoseg(p->u.seg); }
00260 } else if (p->sclass == STATIC && !isfunc(p->type)
00261 && p->type->size == 0)
00262 error("undefined size for `%t %s'\n", p->type, p->name);
00263 return p;
00264 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 920 of file decl.c. References symbol::alias, append(), array(), asgn(), assert, autos, BSS, compose(), CONST, Coordinate, defglobal(), symbol::defined, definept(), interface::defsymbol, e, eqtype(), error(), expect(), expr1(), EXTERN, externals, FUNC, genident(), gettok(), GLOBAL, globals, identifiers, idtree(), initglobal(), install(), IR, isarray, isconst, isfunc, isscalar, isstruct, isvolatile, level, LOCAL, lookup(), symbol::name, NULL, p, PARAM, PERM, q, qual(), symbol::ref, regcount, registers, root(), symbol::sclass, symbol::scope, type::size, interface::space, symbol::src, Symbol, t, Tree, type::type, symbol::type, Type, symbol::u, walk(), and warning(). Referenced by compound(). 00920 {
00921 Symbol p, q;
00922
00923 if (sclass == 0)
00924 sclass = isfunc(ty) ? EXTERN : AUTO;
00925 else if (isfunc(ty) && sclass != EXTERN) {
00926 error("invalid storage class `%k' for `%t %s'\n",
00927 sclass, ty, id);
00928 sclass = EXTERN;
00929 } else if (sclass == REGISTER
00930 && (isvolatile(ty) || isstruct(ty) || isarray(ty))) {
00931 warning("register declaration ignored for `%t %s'\n",
00932 ty, id);
00933 sclass = AUTO;
00934 }
00935 q = lookup(id, identifiers);
00936 if (q && q->scope >= level
00937 || q && q->scope == PARAM && level == LOCAL)
00938 if (sclass == EXTERN && q->sclass == EXTERN
00939 && eqtype(q->type, ty, 1))
00940 ty = compose(ty, q->type);
00941 else
00942 error("redeclaration of `%s' previously declared at %w\n", q->name, &q->src);
00943
00944 assert(level >= LOCAL);
00945 p = install(id, &identifiers, level, sclass == STATIC || sclass == EXTERN ? PERM : FUNC);
00946 p->type = ty;
00947 p->sclass = sclass;
00948 p->src = *pos;
00949 switch (sclass) {
00950 case EXTERN: q = lookup(id, globals);
00951 if (q == NULL || q->sclass == TYPEDEF || q->sclass == ENUM) {
00952 q = lookup(id, externals);
00953 if (q == NULL) {
00954 q = install(p->name, &externals, GLOBAL, PERM);
00955 q->type = p->type;
00956 q->sclass = EXTERN;
00957 q->src = src;
00958 (*IR->defsymbol)(q);
00959 }
00960 }
00961 if (!eqtype(p->type, q->type, 1))
00962 warning("declaration of `%s' does not match previous declaration at %w\n", q->name, &q->src);
00963
00964 p->u.alias = q; break;
00965 case STATIC: (*IR->defsymbol)(p);
00966 initglobal(p, 0);
00967 if (!p->defined)
00968 if (p->type->size > 0) {
00969 defglobal(p, BSS);
00970 (*IR->space)(p->type->size);
00971 } else
00972 error("undefined size for `%t %s'\n",
00973 p->type, p->name);
00974 p->defined = 1; break;
00975 case REGISTER: registers = append(p, registers);
00976 regcount++;
00977 p->defined = 1;
00978 break;
00979 case AUTO: autos = append(p, autos);
00980 p->defined = 1; break;
00981 default: assert(0);
00982 }
00983 if (t == '=') {
00984 Tree e;
00985 if (sclass == EXTERN)
00986 error("illegal initialization of `extern %s'\n", id);
00987 t = gettok();
00988 definept(NULL);
00989 if (isscalar(p->type)
00990 || isstruct(p->type) && t != '{') {
00991 if (t == '{') {
00992 t = gettok();
00993 e = expr1(0);
00994 expect('}');
00995 } else
00996 e = expr1(0);
00997 } else {
00998 Symbol t1;
00999 Type ty = p->type, ty1 = ty;
01000 while (isarray(ty1))
01001 ty1 = ty1->type;
01002 if (!isconst(ty) && (!isarray(ty) || !isconst(ty1)))
01003 ty = qual(CONST, ty);
01004 t1 = genident(STATIC, ty, GLOBAL);
01005 initglobal(t1, 1);
01006 if (isarray(p->type) && p->type->size == 0
01007 && t1->type->size > 0)
01008 p->type = array(p->type->type,
01009 t1->type->size/t1->type->type->size, 0);
01010 e = idtree(t1);
01011 }
01012 walk(root(asgn(p, e)), 0, 0);
01013 p->ref = 1;
01014 }
01015 if (!isfunc(p->type) && p->defined && p->type->size <= 0)
01016 error("undefined size for `%t %s'\n", p->type, id);
01017 return p;
01018 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 479 of file decl.c. References atop(), Coordinate, symbol::defined, error(), expr1(), FUNC, gettok(), identifiers, install(), isarray, isfunc, isstruct, isvolatile, level, lookup(), p, ptr(), symbol::sclass, symbol::scope, symbol::src, stringf(), Symbol, t, symbol::type, Type, and warning(). Referenced by funcdefn(), and parameters(). 00479 {
00480 Symbol p;
00481
00482 if (isfunc(ty))
00483 ty = ptr(ty);
00484 else if (isarray(ty))
00485 ty = atop(ty);
00486 if (sclass == 0)
00487 sclass = AUTO;
00488 else if (sclass != REGISTER) {
00489 error("invalid storage class `%k' for `%t%s\n",
00490 sclass, ty, stringf(id ? " %s'" : "' parameter", id));
00491 sclass = AUTO;
00492 } else if (isvolatile(ty) || isstruct(ty)) {
00493 warning("register declaration ignored for `%t%s\n",
00494 ty, stringf(id ? " %s'" : "' parameter", id));
00495 sclass = AUTO;
00496 }
00497
00498 p = lookup(id, identifiers);
00499 if (p && p->scope == level)
00500 error("duplicate declaration for `%s' previously declared at %w\n", id, &p->src);
00501
00502 else
00503 p = install(id, &identifiers, level, FUNC);
00504 p->sclass = sclass;
00505 p->src = *pos;
00506 p->type = ty;
00507 p->defined = 1;
00508 if (t == '=') {
00509 error("illegal initialization for parameter `%s'\n", id);
00510 t = gettok();
00511 (void)expr1(0);
00512 }
00513 return p;
00514 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 293 of file decl.c. References Aflag, array(), ARRAY, assert, CONST, dclr1(), type::f, func(), FUNCTION, type::oldstyle, type::op, params, POINTER, type::proto, ptr(), qual(), type::size, Symbol, type::type, Type, type::u, VOLATILE, and warning(). Referenced by decl(), parameters(), and typename(). 00293 {
00294 Type ty = dclr1(id, params, abstract);
00295
00296 for ( ; ty; ty = ty->type)
00297 switch (ty->op) {
00298 case POINTER:
00299 basety = ptr(basety);
00300 break;
00301 case FUNCTION:
00302 basety = func(basety, ty->u.f.proto,
00303 ty->u.f.oldstyle);
00304 break;
00305 case ARRAY:
00306 basety = array(basety, ty->size, 0);
00307 break;
00308 case CONST: case VOLATILE:
00309 basety = qual(ty->op, basety);
00310 break;
00311 default: assert(0);
00312 }
00313 if (Aflag >= 2 && basety->size > 32767)
00314 warning("more than 32767 bytes in `%t'\n", basety);
00315 return basety;
00316 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 325 of file decl.c. References ARRAY, assert, CONST, enterscope(), error(), exitparams(), expect(), FUNCTION, gettok(), ID, intexpr(), istypename, kind, level, n, NULL, parameters(), params, POINTER, type::size, Symbol, t, tnode(), tsym, type::type, and Type. Referenced by dclr(). 00325 {
00326 Type ty = NULL;
00327
00328 switch (t) {
00329 case ID: if (id)
00330 *id = token;
00331 else
00332 error("extraneous identifier `%s'\n", token);
00333 t = gettok(); break;
00334 case '*': t = gettok(); if (t == CONST || t == VOLATILE) {
00335 Type ty1;
00336 ty1 = ty = tnode(t, NULL);
00337 while ((t = gettok()) == CONST || t == VOLATILE)
00338 ty1 = tnode(t, ty1);
00339 ty->type = dclr1(id, params, abstract);
00340 ty = ty1;
00341 } else
00342 ty = dclr1(id, params, abstract);
00343 ty = tnode(POINTER, ty); break;
00344 case '(': t = gettok(); if (abstract
00345 && (t == REGISTER || istypename(t, tsym) || t == ')')) {
00346 Symbol *args;
00347 ty = tnode(FUNCTION, ty);
00348 enterscope();
00349 if (level > PARAM)
00350 enterscope();
00351 args = parameters(ty);
00352 exitparams(args);
00353 } else {
00354 ty = dclr1(id, params, abstract);
00355 expect(')');
00356 if (abstract && ty == NULL
00357 && (id == NULL || *id == NULL))
00358 return tnode(FUNCTION, NULL);
00359 } break;
00360 case '[': break;
00361 default: return ty;
00362 }
00363 while (t == '(' || t == '[')
00364 switch (t) {
00365 case '(': t = gettok(); { Symbol *args;
00366 ty = tnode(FUNCTION, ty);
00367 enterscope();
00368 if (level > PARAM)
00369 enterscope();
00370 args = parameters(ty);
00371 if (params && *params == NULL)
00372 *params = args;
00373 else
00374 exitparams(args);
00375 }
00376 break;
00377 case '[': t = gettok(); { int n = 0;
00378 if (kind[t] == ID) {
00379 n = intexpr(']', 1);
00380 if (n <= 0) {
00381 error("`%d' is an illegal array size\n", n);
00382 n = 1;
00383 }
00384 } else
00385 expect(']');
00386 ty = tnode(ARRAY, ty);
00387 ty->size = n; } break;
00388 default: assert(0);
00389 }
00390 return ty;
00391 }
|
Here is the call graph for this function:

|
|
Definition at line 143 of file decl.c. References Aflag, Coordinate, dclr(), error(), exitparams(), exitscope(), type::f, FUNC, funcdefn(), gettok(), hasproto(), ID, identifiers, install(), isenum, isfunc, isstruct, istypename, kind, level, LOCAL, lookup(), NULL, type::oldstyle, p, params, PERM, symbol::sclass, symbol::scope, specifier(), symbol::src, Symbol, t, test(), tsym, symbol::type, Type, type::u, unqual, and warning(). Referenced by compound(), funcdefn(), and program(). 00143 {
00144 int sclass;
00145 Type ty, ty1;
00146 static char stop[] = { CHAR, STATIC, ID, 0 };
00147
00148 ty = specifier(&sclass);
00149 if (t == ID || t == '*' || t == '(' || t == '[') {
00150 char *id;
00151 Coordinate pos;
00152 id = NULL;
00153 pos = src;
00154 if (level == GLOBAL) {
00155 Symbol *params = NULL;
00156 ty1 = dclr(ty, &id, ¶ms, 0);
00157 if (params && id && isfunc(ty1)
00158 && (t == '{' || istypename(t, tsym)
00159 || (kind[t] == STATIC && t != TYPEDEF))) {
00160 if (sclass == TYPEDEF) {
00161 error("invalid use of `typedef'\n");
00162 sclass = EXTERN;
00163 }
00164 if (ty1->u.f.oldstyle)
00165 exitscope();
00166 funcdefn(sclass, id, ty1, params, pos);
00167 return;
00168 } else if (params)
00169 exitparams(params);
00170 } else
00171 ty1 = dclr(ty, &id, NULL, 0);
00172 for (;;) {
00173 if (Aflag >= 1 && !hasproto(ty1))
00174 warning("missing prototype\n");
00175 if (id == NULL)
00176 error("missing identifier\n");
00177 else if (sclass == TYPEDEF)
00178 {
00179 Symbol p = lookup(id, identifiers);
00180 if (p && p->scope == level)
00181 error("redeclaration of `%s'\n", id);
00182 p = install(id, &identifiers, level,
00183 level < LOCAL ? PERM : FUNC);
00184 p->type = ty1;
00185 p->sclass = TYPEDEF;
00186 p->src = pos;
00187 }
00188 else
00189 (void)(*dcl)(sclass, id, ty1, &pos);
00190 if (t != ',')
00191 break;
00192 t = gettok();
00193 id = NULL;
00194 pos = src;
00195 ty1 = dclr(ty, &id, NULL, 0);
00196 }
00197 } else if (ty == NULL
00198 || !(isenum(ty) ||
00199 isstruct(ty) && (*unqual(ty)->u.sym->name < '1' || *unqual(ty)->u.sym->name > '9')))
00200 error("empty declaration\n");
00201 test(';', stop);
00202 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 284 of file decl.c. References symbol::defined, interface::export, interface::global, IR, p, symbol::sclass, symbol::seg, swtoseg(), Symbol, and symbol::u. Referenced by bbcall(), bbfunc(), bbvars(), dcllocal(), doconst(), doglobal(), emitcode(), initglobal(), and tracecall(). 00284 {
00285 p->u.seg = seg;
00286 swtoseg(p->u.seg);
00287 if (p->sclass != STATIC)
00288 (*IR->export)(p);
00289 (*IR->global)(p);
00290 p->defined = 1;
00291 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1052 of file decl.c. References assert, symbol::c, interface::defconst, defglobal(), interface::defstring, IR, isarray, LIT, symbol::loc, n, type::op, value::p, p, s, symbol::seg, type::size, Symbol, type::type, symbol::type, value::u, symbol::u, v, symbol::v, Value, and widechar. Referenced by finalize(). 01052 {
01053 if (p->u.c.loc) {
01054 assert(p->u.c.loc->u.seg == 0);
01055 defglobal(p->u.c.loc, LIT);
01056 if (isarray(p->type) && p->type->type == widechar) {
01057 unsigned int *s = p->u.c.v.p;
01058 int n = p->type->size/widechar->size;
01059 while (n-- > 0) {
01060 Value v;
01061 v.u = *s++;
01062 (*IR->defconst)(widechar->op, widechar->size, v);
01063 }
01064 } else if (isarray(p->type))
01065 (*IR->defstring)(p->type->size, p->u.c.v. |