2001-10-21 Michael Hope <michaelh@juju.net.nz>
[fw/sdcc] / src / SDCC.y
index c986486087d90b7750307d6c5c1dbb1154c41bec..776775bafa53ed55e6b70e057144c25c589d178b 100644 (file)
@@ -756,11 +756,11 @@ struct_declaration
               if (!sym->type) {
                   sym->type = copyLinkChain($1);
                   sym->etype = getSpec(sym->type);
-                  /* make sure the type is complete and sane */
-                  checkTypeSanity(sym->etype, sym->name);
               }
               else
                   addDecl (sym,0,cloneSpec($1));              
+              /* make sure the type is complete and sane */
+              checkTypeSanity(sym->etype, sym->name);
           }
            $$ = $2;
        }
@@ -776,7 +776,7 @@ struct_declarator_list
    ;
 
 struct_declarator
-   : declarator
+   : declarator 
    | ':' constant_expr  {  
                            $$ = newSymbol (genSymName(NestLevel),NestLevel) ; 
                            $$->bitVar = (int) floatFromVal(constExprValue($2,TRUE));
@@ -917,9 +917,19 @@ declarator2
             $1->hasVargs = IS_VARG($4);
             $1->args = reverseVal($4)  ;
             
+            
             /* nest level was incremented to take care of the parms  */
             NestLevel-- ;
             currBlockno--;
+
+            // if this was a pointer to a function, remove the symbol args
+            // (if any)
+            if (IS_PTR($1->type) && IS_FUNC($1->etype)) {
+              cleanUpLevel(SymbolTab,NestLevel+1);
+              /* fprintf (stderr, "Removed parm symbols of %s in line %d\n", 
+                 $1->name, yylineno); */
+            }
+            
             $$ = $1;
          }
    | declarator2 '(' parameter_identifier_list ')'
@@ -943,6 +953,7 @@ pointer
          {
             $$ = $1 ;          
             $$->next = $2 ;
+            DCL_TYPE($2)=GPOINTER;
         }
    | unqualified_pointer type_specifier_list pointer
          {
@@ -990,7 +1001,20 @@ unqualified_pointer
 
 type_specifier_list
    : type_specifier
-   | type_specifier_list type_specifier         {  $$ = mergeSpec ($1,$2, "type_specifier_list"); }
+   //| type_specifier_list type_specifier         {  $$ = mergeSpec ($1,$2, "type_specifier_list"); }
+   | type_specifier_list type_specifier {
+     /* 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, "type_specifier_list");
+       $$ = $2 ;
+     }
+     else
+       $$ = mergeSpec($1,$2, "type_specifier_list");
+   }
    ;
 
 parameter_identifier_list
@@ -1124,14 +1148,15 @@ statement
    | jump_statement
    | INLINEASM  ';'      {
                             ast *ex = newNode(INLINEASM,NULL,NULL);
-                           ex->values.inlineasm = Safe_calloc(1,strlen($1)+1);
+                           ex->values.inlineasm = malloc(strlen($1)+1);
                            strcpy(ex->values.inlineasm,$1);                        
                            $$ = ex;
-                         }   
+                         } 
    ;
 
 labeled_statement
-   : identifier ':' statement          {  $$ = createLabel($1,$3);  }   
+//   : identifier ':' statement          {  $$ = createLabel($1,$3);  }   
+   : identifier ':'                    {  $$ = createLabel($1,NULL);  }   
    | CASE constant_expr ':' statement  {  $$ = createCase(STACK_PEEK(swStk),$2,$4); }
    | DEFAULT ':' statement             {  $$ = createDefault(STACK_PEEK(swStk),$3); }
    ;