* configure.in,
[fw/sdcc] / src / SDCC.y
index 79d6024b1372fbf2b14b6c74824536dfeae5bc07..1196d705c150e0ba8aa2d3ccccfaf5e34f132d2c 100644 (file)
@@ -109,7 +109,7 @@ bool uselessDecl = TRUE;
 %type <sym> declaration_list identifier_list
 %type <sym> declarator2_function_attributes while do for critical
 %type <lnk> pointer type_specifier_list type_specifier type_name
-%type <lnk> storage_class_specifier struct_or_union_specifier
+%type <lnk> storage_class_specifier struct_or_union_specifier function_specifier
 %type <lnk> declaration_specifiers sfr_reg_bit sfr_attributes type_specifier2
 %type <lnk> function_attribute function_attributes enum_specifier
 %type <lnk> abstract_declarator abstract_declarator2 unqualified_pointer
@@ -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,6 +570,13 @@ storage_class_specifier
                }
    ;
 
+function_specifier
+   : INLINE   {
+                  $$ = newLink (SPECIFIER) ;
+                  SPEC_INLINE($$) = 1 ;
+               }
+   ;
+
 Interrupt_storage
    : INTERRUPT { $$ = INTNO_UNSPEC ; }
    | INTERRUPT constant_expr
@@ -625,6 +646,10 @@ type_specifier2
                   $$=newLink(SPECIFIER);
                   SPEC_VOLATILE($$) = 1 ;
                }
+   | RESTRICT  {
+                  $$=newLink(SPECIFIER);
+                  SPEC_RESTRICT($$) = 1 ;
+               }
    | FLOAT     {
                   $$=newLink(SPECIFIER);
                   SPEC_NOUN($$) = V_FLOAT;
@@ -1090,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)floatFromVal(tval)) < 0)
+                  {
+                    werror(E_NEGATIVE_ARRAY_SIZE, $1->name);
+                    size = 1;
+                  }
+              }
+            DCL_ELEM(p) = size;
+            addDecl($1, 0, p);
          }
    ;
 
@@ -1156,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);
@@ -1168,10 +1203,11 @@ pointer
          }
    | unqualified_pointer type_specifier_list pointer
          {
-             $$ = $1 ;
+             $$ = $1 ;               
              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;
@@ -1192,12 +1228,12 @@ pointer
                      DCL_TYPE($3) = EEPPOINTER;
                      break;
                  default:
-                   // this could be just "constant"
+                   // this could be just "constant" 
                    // werror(W_PTR_TYPE_INVALID);
                      ;
                  }
              }
-             else
+             else 
                  werror (W_PTR_TYPE_INVALID);
              $$->next = $3 ;
          }
@@ -1691,4 +1727,3 @@ identifier
    : IDENTIFIER   { $$ = newSymbol ($1,NestLevel) ; }
    ;
 %%
-