X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCC.y;h=b37f2ba868bd945422e482d169402cf1cbe99b67;hb=6cb515b98c5977589446a39a6271958383d0a3da;hp=1ffd9a4e482271869e67eba4f9169711be17613d;hpb=5ec86507972e4b25f3acd259f5e05f65f17fa70c;p=fw%2Fsdcc diff --git a/src/SDCC.y b/src/SDCC.y index 1ffd9a4e..b37f2ba8 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -109,7 +109,7 @@ bool uselessDecl = TRUE; %type declaration_list identifier_list %type declarator2_function_attributes while do for critical %type pointer type_specifier_list type_specifier type_name -%type storage_class_specifier struct_or_union_specifier +%type storage_class_specifier struct_or_union_specifier function_specifier %type declaration_specifiers sfr_reg_bit sfr_attributes type_specifier2 %type function_attribute function_attributes enum_specifier %type abstract_declarator abstract_declarator2 unqualified_pointer @@ -198,7 +198,7 @@ function_attribute function_attributes : USING constant_expr { $$ = newLink(SPECIFIER) ; - FUNC_REGBANK($$) = (int) floatFromVal(constExprValue($2,TRUE)); + FUNC_REGBANK($$) = (int) ulFromVal(constExprValue($2,TRUE)); } | REENTRANT { $$ = newLink (SPECIFIER); FUNC_ISREENT($$)=1; @@ -520,6 +520,20 @@ declaration_specifiers else $$ = mergeSpec($1,$2, "type_specifier declaration_specifiers"); } + | function_specifier { $$ = $1; } + | function_specifier declaration_specifiers { + /* if the decl $2 is not a specifier */ + /* find the spec and replace it */ + if ( !IS_SPEC($2)) { + sym_link *lnk = $2 ; + while (lnk && !IS_SPEC(lnk->next)) + lnk = lnk->next; + lnk->next = mergeSpec($1,lnk->next, "function_specifier declaration_specifiers - skipped"); + $$ = $2 ; + } + else + $$ = mergeSpec($1,$2, "function_specifier declaration_specifiers"); + } ; init_declarator_list @@ -556,10 +570,17 @@ storage_class_specifier } ; +function_specifier + : INLINE { + $$ = newLink (SPECIFIER) ; + SPEC_INLINE($$) = 1 ; + } + ; + Interrupt_storage : INTERRUPT { $$ = INTNO_UNSPEC ; } | INTERRUPT constant_expr - { int intno = (int) floatFromVal(constExprValue($2,TRUE)); + { int intno = (int) ulFromVal(constExprValue($2,TRUE)); if ((intno >= 0) && (intno <= INTNO_MAX)) $$ = intno; else @@ -577,7 +598,7 @@ type_specifier /* add this to the storage class specifier */ SPEC_ABSA($1) = 1; /* set the absolute addr flag */ /* now get the abs addr from value */ - SPEC_ADDR($1) = (unsigned) floatFromVal(constExprValue($3,TRUE)) ; + SPEC_ADDR($1) = (unsigned int) ulFromVal(constExprValue($3,TRUE)) ; } ; @@ -625,6 +646,10 @@ type_specifier2 $$=newLink(SPECIFIER); SPEC_VOLATILE($$) = 1 ; } + | RESTRICT { + $$=newLink(SPECIFIER); + SPEC_RESTRICT($$) = 1 ; + } | FLOAT { $$=newLink(SPECIFIER); SPEC_NOUN($$) = V_FLOAT; @@ -893,7 +918,7 @@ struct_declarator | ':' constant_expr { unsigned int bitsize; $$ = newSymbol (genSymName(NestLevel),NestLevel) ; - bitsize= (unsigned int) floatFromVal(constExprValue($2,TRUE)); + bitsize = (unsigned int) ulFromVal(constExprValue($2,TRUE)); if (bitsize > (port->s.int_size * 8)) { bitsize = port->s.int_size * 8; werror(E_BITFLD_SIZE, bitsize); @@ -905,7 +930,7 @@ struct_declarator | declarator ':' constant_expr { unsigned int bitsize; - bitsize= (unsigned int) floatFromVal(constExprValue($3,TRUE)); + bitsize = (unsigned int) ulFromVal(constExprValue($3,TRUE)); if (bitsize > (port->s.int_size * 8)) { bitsize = port->s.int_size * 8; werror(E_BITFLD_SIZE, bitsize); @@ -962,40 +987,37 @@ enum_specifier ; enumerator_list - : enumerator - | enumerator_list ',' { - } - | enumerator_list ',' enumerator - { - symbol *dsym; - - for (dsym=$1; dsym; dsym=dsym->next) - { - if (strcmp($3->name, dsym->name)==0) - { - werrorfl($3->fileDef, $3->lineDef, E_DUPLICATE_MEMBER, "enum", $3->name); - werrorfl(dsym->fileDef, dsym->lineDef, E_PREVIOUS_DEF); - } - } - - $3->next = $1 ; - $$ = $3 ; - } - ; + : enumerator + | enumerator_list ',' + | enumerator_list ',' enumerator + { + $3->next = $1 ; + $$ = $3 ; + } + ; enumerator - : identifier opt_assign_expr - { - /* make the symbol one level up */ - $1->level-- ; - $1->type = copyLinkChain($2->type); - $1->etype= getSpec($1->type); - SPEC_ENUM($1->etype) = 1; - $$ = $1 ; - // do this now, so we can use it for the next enums in the list - addSymChain(&$1); - } - ; + : identifier opt_assign_expr + { + symbol *sym; + + /* make the symbol one level up */ + $1->level-- ; + // check if the symbol at the same level already exists + if ((sym = findSymWithLevel (SymbolTab, $1)) && + sym->level == $1->level) + { + werrorfl ($1->fileDef, $1->lineDef, E_DUPLICATE_MEMBER, "enum", $1->name); + werrorfl (sym->fileDef, sym->lineDef, E_PREVIOUS_DEF); + } + $1->type = copyLinkChain ($2->type); + $1->etype= getSpec ($1->type); + SPEC_ENUM ($1->etype) = 1; + $$ = $1 ; + // do this now, so we can use it for the next enums in the list + addSymChain (&$1); + } + ; opt_assign_expr : '=' constant_expr { @@ -1006,7 +1028,7 @@ opt_assign_expr { werror(E_ENUM_NON_INTEGER); SNPRINTF(lbuff, sizeof(lbuff), - "%d",(int) floatFromVal(val)); + "%d", (int) ulFromVal(val)); val = constVal(lbuff); } $$ = cenum = val ; @@ -1014,11 +1036,11 @@ opt_assign_expr | { if (cenum) { SNPRINTF(lbuff, sizeof(lbuff), - "%d",(int) floatFromVal(cenum)+1); + "%d", (int) ulFromVal(cenum)+1); $$ = cenum = constVal(lbuff); } else { - $$ = cenum = constVal("0"); + $$ = cenum = constCharVal(0); } } ; @@ -1093,23 +1115,32 @@ declarator2 } | declarator3 '[' constant_expr ']' { - sym_link *p ; - value *tval; + sym_link *p; + value *tval; + int size; - tval = constExprValue($3,TRUE); + tval = constExprValue($3, TRUE); /* if it is not a constant then Error */ p = newLink (DECLARATOR); - DCL_TYPE(p) = ARRAY ; - if ( !tval || (SPEC_SCLS(tval->etype) != S_LITERAL)) { - werror(E_CONST_EXPECTED) ; - /* Assume a single item array to limit the cascade */ - /* of additional errors. */ - DCL_ELEM(p) = 1; - } - else { - DCL_ELEM(p) = (int) floatFromVal(tval) ; - } - addDecl($1,0,p); + DCL_TYPE(p) = ARRAY; + + if (!tval || (SPEC_SCLS(tval->etype) != S_LITERAL)) + { + werror(E_CONST_EXPECTED); + /* Assume a single item array to limit the cascade */ + /* of additional errors. */ + size = 1; + } + else + { + if ((size = (int) ulFromVal(tval)) < 0) + { + werror(E_NEGATIVE_ARRAY_SIZE, $1->name); + size = 1; + } + } + DCL_ELEM(p) = size; + addDecl($1, 0, p); } ; @@ -1159,6 +1190,7 @@ pointer DCL_TSPEC($1) = $2; DCL_PTR_CONST($1) = SPEC_CONST($2); DCL_PTR_VOLATILE($1) = SPEC_VOLATILE($2); + DCL_PTR_RESTRICT($1) = SPEC_RESTRICT($2); } else werror (W_PTR_TYPE_INVALID); @@ -1175,6 +1207,7 @@ pointer if (IS_SPEC($2) && DCL_TYPE($3) == UPOINTER) { DCL_PTR_CONST($1) = SPEC_CONST($2); DCL_PTR_VOLATILE($1) = SPEC_VOLATILE($2); + DCL_PTR_RESTRICT($1) = SPEC_RESTRICT($2); switch (SPEC_SCLS($2)) { case S_XDATA: DCL_TYPE($3) = FPOINTER; @@ -1316,7 +1349,7 @@ abstract_declarator2 value *val ; $$ = newLink (DECLARATOR); DCL_TYPE($$) = ARRAY ; - DCL_ELEM($$) = (int) floatFromVal(val = constExprValue($2,TRUE)); + DCL_ELEM($$) = (int) ulFromVal(val = constExprValue($2,TRUE)); } | abstract_declarator2 '[' ']' { $$ = newLink (DECLARATOR); @@ -1329,7 +1362,7 @@ abstract_declarator2 value *val ; $$ = newLink (DECLARATOR); DCL_TYPE($$) = ARRAY ; - DCL_ELEM($$) = (int) floatFromVal(val = constExprValue($3,TRUE)); + DCL_ELEM($$) = (int) ulFromVal(val = constExprValue($3,TRUE)); $$->next = $1 ; } | '(' ')' { $$ = NULL;} @@ -1694,4 +1727,3 @@ identifier : IDENTIFIER { $$ = newSymbol ($1,NestLevel) ; } ; %% -