X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCval.c;h=31b4159c0e09a9d632b410cbac3cfedcdf3312a7;hb=272375bec00437e18d3e3912902b32d320c754c8;hp=2f5b9710076e6d14edd5cd26af3363233eb4c067;hpb=6f813805bf1e3226d29fab8d46a7a8a46102dbf6;p=fw%2Fsdcc diff --git a/src/SDCCval.c b/src/SDCCval.c index 2f5b9710..31b4159c 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -97,6 +97,107 @@ revinit (initList * val) return prev; } +bool +convertIListToConstList(initList *src, literalList **lList) +{ + initList *iLoop; + literalList *head, *last, *newL; + + head = last = NULL; + + if (!src || src->type != INIT_DEEP) + { + return FALSE; + } + + iLoop = src->init.deep; + + while (iLoop) + { + if (iLoop->type != INIT_NODE) + { + return FALSE; + } + + if (!IS_AST_LIT_VALUE(decorateType(resolveSymbols(iLoop->init.node)))) + { + return FALSE; + } + iLoop = iLoop->next; + } + + // We've now established that the initializer list contains only literal values. + + iLoop = src->init.deep; + while (iLoop) + { + double val = AST_LIT_VALUE(iLoop->init.node); + + if (last && last->literalValue == val) + { + last->count++; + } + else + { + newL = Safe_malloc(sizeof(literalList)); + newL->literalValue = val; + newL->count = 1; + newL->next = NULL; + + if (last) + { + last->next = newL; + } + else + { + head = newL; + } + last = newL; + } + iLoop = iLoop->next; + } + + if (!head) + { + return FALSE; + } + + *lList = head; + return TRUE; +} + +literalList * +copyLiteralList(literalList *src) +{ + literalList *head, *prev, *newL; + + head = prev = NULL; + + while (src) + { + newL = Safe_malloc(sizeof(literalList)); + + newL->literalValue = src->literalValue; + newL->count = src->count; + newL->next = NULL; + + if (prev) + { + prev->next = newL; + } + else + { + head = newL; + } + prev = newL; + src = src->next; + } + + return head; +} + + + /*------------------------------------------------------------------*/ /* copyIlist - copy initializer list */ /*------------------------------------------------------------------*/ @@ -1311,7 +1412,7 @@ getNelements (sym_link * type, initList * ilist) ilist = ilist->init.deep; /* if type is a character array and there is only one - initialiser then get the length of the string */ + (string) initialiser then get the length of the string */ if (IS_ARRAY (type) && IS_CHAR (etype) && !ilist->next) { ast *iast = ilist->init.node; @@ -1321,12 +1422,12 @@ getNelements (sym_link * type, initList * ilist) werror (E_INIT_WRONG); return 0; } - if (!IS_ARRAY (v->type) || !IS_CHAR (v->etype)) + + if (IS_ARRAY (v->type) && IS_CHAR (v->etype)) + // yep, it's a string { - werror (E_INIT_WRONG); - return 0; + return DCL_ELEM (v->type); } - return DCL_ELEM (v->type); } i = 0;