From b5d29d69138a09774f423a86270ca058a545cfd2 Mon Sep 17 00:00:00 2001 From: johanknol Date: Tue, 13 Nov 2001 13:25:43 +0000 Subject: [PATCH] all excess initializers (that I can think of) are catched now git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1579 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCast.c | 13 +++++++++++-- src/SDCCglue.c | 10 +++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index e876cc4a..000088b1 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -1095,11 +1095,16 @@ gatherAutoInit (symbol * autoChain) addSym (SymbolTab, newSym, newSym->rname, 0, 0, 1); /* now lift the code to main */ - if (IS_AGGREGATE (sym->type)) + if (IS_AGGREGATE (sym->type)) { work = initAggregates (sym, sym->ival, NULL); - else + } else { + if (getNelements(sym->type, sym->ival)>1) { + werror (W_EXCESS_INITIALIZERS, "scalar", + sym->name, sym->lineDef); + } work = newNode ('=', newAst_VALUE (symbolVal (newSym)), list2expr (sym->ival)); + } setAstLineno (work, sym->lineDef); @@ -1118,6 +1123,10 @@ gatherAutoInit (symbol * autoChain) if (IS_AGGREGATE (sym->type)) { work = initAggregates (sym, sym->ival, NULL); } else { + if (getNelements(sym->type, sym->ival)>1) { + werror (W_EXCESS_INITIALIZERS, "scalar", + sym->name, sym->lineDef); + } work = newNode ('=', newAst_VALUE (symbolVal (sym)), list2expr (sym->ival)); } diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 4523afe0..e31f9860 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -260,6 +260,10 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) if (IS_AGGREGATE (sym->type)) { ival = initAggregates (sym, sym->ival, NULL); } else { + if (getNelements(sym->type, sym->ival)>1) { + werror (W_EXCESS_INITIALIZERS, "scalar", + sym->name, sym->lineDef); + } ival = newNode ('=', newAst_VALUE (symbolVal (sym)), decorateType (resolveSymbols (list2expr (sym->ival)))); } @@ -527,7 +531,7 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, FILE * oFile) if (ilist->type == INIT_DEEP) ilist = ilist->init.deep; - if (sym && ilist->next) { + if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) { werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef); } @@ -633,7 +637,7 @@ printIvalStruct (symbol * sym, sym_link * type, if (IS_BITFIELD(sflds->type)) { printIvalBitFields(&sflds,&iloop,oFile); } else { - printIval (NULL, sflds->type, iloop, oFile); + printIval (sym, sflds->type, iloop, oFile); } } if (iloop) { @@ -709,7 +713,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist, for (;;) { size++; - printIval (NULL, type->next, iloop, oFile); + printIval (sym, type->next, iloop, oFile); iloop = (iloop ? iloop->next : NULL); -- 2.30.2