it is a global variable */
if (sym->ival && sym->level == 0) {
if (SPEC_OCLS(sym->etype)==xidata) {
- // create a new "XINIT (CODE)" symbol, that will be emitted later
+ /* create a new "XINIT (CODE)" symbol, that will be emitted later
+ in the static seg */
newSym=copySymbol (sym);
SPEC_OCLS(newSym->etype)=xinit;
SNPRINTF (newSym->name, sizeof(newSym->name), "__xinit_%s", sym->name);
if (ilist->type == INIT_DEEP)
ilist = ilist->init.deep;
- if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) {
- werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef);
- }
-
if (!(val = list2val (ilist))) {
// assuming a warning has been thrown
val=constVal("0");
FILE * oFile)
{
initList *iloop;
- int lcnt = 0, size = 0;
- sym_link *last_type;
+ int size = 0;
/* take care of the special case */
/* array of characters can be init */
return;
}
- iloop = ilist->init.deep;
- lcnt = DCL_ELEM (type);
- for (last_type = type->next;
- last_type && IS_DECL(last_type) && DCL_ELEM (last_type);
- last_type = last_type->next) {
- lcnt *= DCL_ELEM (last_type);
- }
-
- for (;;)
+ for (iloop=ilist->init.deep; iloop; iloop=iloop->next)
{
- size++;
printIval (sym, type->next, iloop, oFile);
- iloop = (iloop ? iloop->next : NULL);
-
-
- /* if not array limits given & we */
- /* are out of initialisers then */
- if (!DCL_ELEM (type) && !iloop)
- break;
-
- /* no of elements given and we */
- /* have generated for all of them */
- if (!--lcnt) {
- /* if initializers left */
- if (iloop) {
- werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
- }
+
+ if (++size > DCL_ELEM(type)) {
+ werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
break;
}
}
-
- /* if we have not been given a size */
- if (!DCL_ELEM (type))
+
+ if (DCL_ELEM(type)) {
+ // pad with zeros if needed
+ if (size<DCL_ELEM(type)) {
+ size = (DCL_ELEM(type) - size) * getSize(type->next);
+ while (size--) {
+ tfprintf (oFile, "\t!db !constbyte\n", 0);
+ }
+ }
+ } else {
+ // we have not been given a size, but we now know it
DCL_ELEM (type) = size;
+ }
return;
}
void
printIval (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
{
+ sym_link *itype;
+
if (!ilist)
return;
return;
}
- /* if this is a pointer */
- if (IS_PTR (type))
+ /* if this is an array */
+ if (IS_ARRAY (type))
{
- printIvalPtr (sym, type, ilist, oFile);
+ printIvalArray (sym, type, ilist, oFile);
return;
}
- /* if this is an array */
- if (IS_ARRAY (type))
+ // not an aggregate, ilist must be a node
+ if (ilist->type!=INIT_NODE) {
+ // or a 1-element list
+ if (ilist->init.deep->next) {
+ werror (W_EXCESS_INITIALIZERS, "scalar",
+ sym->name, sym->lineDef);
+ } else {
+ ilist=ilist->init.deep;
+ }
+ }
+
+ // and the type must match
+ itype=ilist->init.node->ftype;
+
+ if (compareType(type, itype)==0) {
+ // special case for literal strings
+ if (IS_ARRAY (itype) && IS_CHAR (getSpec(itype)) &&
+ // which are really code pointers
+ IS_PTR(type) && DCL_TYPE(type)==CPOINTER) {
+ // no sweat
+ } else {
+ werror (E_TYPE_MISMATCH, "assignment", " ");
+ printFromToType(itype, type);
+ }
+ }
+
+ /* if this is a pointer */
+ if (IS_PTR (type))
{
- printIvalArray (sym, type, ilist, oFile);
+ printIvalPtr (sym, type, ilist, oFile);
return;
}
const char *tmpdir = NULL;
int fd;
+ static int warning_emitted;
if ((tmpdir = getenv ("TMP")) == NULL)
if ((tmpdir = getenv ("TEMP")) == NULL)
tmpdir = getenv ("TMPDIR");
-#ifndef _WIN32
+#if defined(_WIN32)
+ if (tmpdir == NULL)
+ {
+ tmpdir = "c:\\";
+ if (!warning_emitted)
+ {
+ fprintf (stderr, "TMP not defined in environment, using %s for temporary files\n", tmpdir);
+ warning_emitted = 1;
+ }
+ }
+#else
{
/* try with /usr/tmp and /tmp on Un*x systems */
struct stat statbuf;
tmpdir = "/usr/tmp";
else if (stat("/tmp", &statbuf) != -1)
tmpdir = "/tmp";
+ if (!warning_emitted) {
+ fprintf (stderr, "TMP not defined in environment, using %s for temporary files\n", tmpdir);
+ warning_emitted = 1;
+ }
}
}
#endif