X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCC.y;h=24741ae5c6be39a0f1215a5c658e383aff496a37;hb=b25efb9a75e0bb7fb74196af0c77fabaf1760fc5;hp=4a7ac6cfc2e3ac0beb8062c66926002ba08a90db;hpb=e483295e5a0539ea4cea6a708f37fb94ea557c08;p=fw%2Fsdcc diff --git a/src/SDCC.y b/src/SDCC.y index 4a7ac6cf..24741ae5 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -34,6 +34,7 @@ #include "port.h" #include "newalloc.h" #include "SDCCerr.h" +#include "SDCCutil.h" extern int yyerror (char *); extern FILE *yyin; @@ -768,7 +769,7 @@ struct_declaration sym->etype = getSpec(sym->type); } else - addDecl (sym,0,cloneSpec($1)); + addDecl (sym,0,copyLinkChain($1)); /* make sure the type is complete and sane */ checkTypeSanity(sym->etype, sym->name); } @@ -868,11 +869,13 @@ opt_assign_expr } | { if (cenum) { - sprintf(lbuff,"%d",(int) floatFromVal(cenum)+1); + SNPRINTF(lbuff, sizeof(lbuff), + "%d",(int) floatFromVal(cenum)+1); $$ = cenum = constVal(lbuff); } else { - sprintf(lbuff,"%d",0); + SNPRINTF(lbuff, sizeof(lbuff), + "%d",0); $$ = cenum = constVal(lbuff); } } @@ -1015,6 +1018,7 @@ pointer default: // this could be just "constant" // werror(W_PTR_TYPE_INVALID); + ; } } else @@ -1101,9 +1105,13 @@ type_name /* go to the end of the list */ sym_link *p; pointerTypes($2,$1); - for ( p = $2 ; p->next ; p=p->next); - p->next = $1 ; - $$ = $2 ; + for ( p = $2 ; p && p->next ; p=p->next); + if (!p) { + werror(E_SYNTAX_ERROR, yytext); + } else { + p->next = $1 ; + } + $$ = $2 ; } ; @@ -1146,10 +1154,16 @@ abstract_declarator2 // $1 must be a pointer to a function sym_link *p=newLink(); DCL_TYPE(p) = FUNCTION; + if (!$1) { + // ((void (code *) ()) 0) () + $1=newLink(); + DCL_TYPE($1)=CPOINTER; + $$ = $1; + } $1->next=p; } | abstract_declarator2 '(' parameter_type_list ')' { - if (!IS_VOID($3->type)) { + if (!IS_VOID($3->etype)) { // this is nonsense, so let's just burp something werror(E_TOO_FEW_PARMS); } else { @@ -1165,6 +1179,7 @@ abstract_declarator2 $1->next=p; } } + ; initializer : assignment_expr { $$ = newiList(INIT_NODE,$1); } @@ -1186,8 +1201,7 @@ statement | jump_statement | INLINEASM ';' { ast *ex = newNode(INLINEASM,NULL,NULL); - ex->values.inlineasm = malloc(strlen($1)+1); - strcpy(ex->values.inlineasm,$1); + ex->values.inlineasm = strdup($1); $$ = ex; } ; @@ -1281,7 +1295,8 @@ selection_statement ex->values.switchVals.swNum = swLabel ; /* now create the label */ - sprintf(lbuff,"_swBrk_%d",swLabel++); + SNPRINTF(lbuff, sizeof(lbuff), + "_swBrk_%d",swLabel++); $$ = newSymbol(lbuff,NestLevel); /* put label in the break stack */ STACK_PUSH(breakStack,$$); @@ -1297,45 +1312,49 @@ selection_statement while : WHILE { /* create and push the continue , break & body labels */ static int Lblnum = 0 ; /* continue */ - sprintf (lbuff,"_whilecontinue_%d",Lblnum); + SNPRINTF (lbuff, sizeof(lbuff), "_whilecontinue_%d",Lblnum); STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel)); /* break */ - sprintf (lbuff,"_whilebreak_%d",Lblnum); + SNPRINTF (lbuff, sizeof(lbuff), "_whilebreak_%d",Lblnum); STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel)); /* body */ - sprintf (lbuff,"_whilebody_%d",Lblnum++); + SNPRINTF (lbuff, sizeof(lbuff), "_whilebody_%d",Lblnum++); $$ = newSymbol(lbuff,NestLevel); } + ; do : DO { /* create and push the continue , break & body Labels */ static int Lblnum = 0 ; /* continue */ - sprintf(lbuff,"_docontinue_%d",Lblnum); + SNPRINTF(lbuff, sizeof(lbuff), "_docontinue_%d",Lblnum); STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel)); /* break */ - sprintf (lbuff,"_dobreak_%d",Lblnum); + SNPRINTF(lbuff, sizeof(lbuff), "_dobreak_%d",Lblnum); STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel)); /* do body */ - sprintf (lbuff,"_dobody_%d",Lblnum++); + SNPRINTF(lbuff, sizeof(lbuff), "_dobody_%d",Lblnum++); $$ = newSymbol (lbuff,NestLevel); } + ; + for : FOR { /* create & push continue, break & body labels */ static int Lblnum = 0 ; /* continue */ - sprintf (lbuff,"_forcontinue_%d",Lblnum); + SNPRINTF(lbuff, sizeof(lbuff), "_forcontinue_%d",Lblnum); STACK_PUSH(continueStack,newSymbol(lbuff,NestLevel)); /* break */ - sprintf (lbuff,"_forbreak_%d",Lblnum); + SNPRINTF(lbuff, sizeof(lbuff), "_forbreak_%d",Lblnum); STACK_PUSH(breakStack,newSymbol(lbuff,NestLevel)); /* body */ - sprintf (lbuff,"_forbody_%d",Lblnum); + SNPRINTF(lbuff, sizeof(lbuff), "_forbody_%d",Lblnum); $$ = newSymbol(lbuff,NestLevel); /* condition */ - sprintf (lbuff,"_forcond_%d",Lblnum++); + SNPRINTF(lbuff, sizeof(lbuff), "_forcond_%d",Lblnum++); STACK_PUSH(forStack,newSymbol(lbuff,NestLevel)); } + ; iteration_statement : while '(' expr ')' statement