Exemplo n.º 1
0
static Boolean_t declaration_statement2( void )
{
   Declaration_t Declaration;
   int record;

   Save();

   xprintf( "declaration_statement2\n" );

   if(( Declaration = f_Declaration( LEVEL_2 )))
   {
      xprintf( "declaration_statement2: OK: %s\n", ident( 0 ));
      f_DeclarationProcess( Declaration, record = True );
      f_DeclarationDestroy( Declaration );
      return True;
   }
   else
   {
      xprintf( "declaration_statement2: 0\n" );
      Restore();
      return False;
   }
}
Exemplo n.º 2
0
static Declaration_t f_ArgumentDeclaration( void )
{
   Declaration_t Declaration = f_DeclarationCreate( DECLARATION_ARGUMENT );
   Declarator_t Declarator;
   int iTypeSpec = 0;
   int iStorage = 0;
   int iModifier = 0;
   Name_t Name;
   Save();
   niveau++;

   if( test ) printf( "f_ArgumentDeclaration: %s\n", ident( 0 ));

   while( True )
   {
      switch( token( 0 ))
      {
   /* storage class specifiers */
      case SN_REGISTER  :
         Declaration->storage_class = SN_REGISTER;
         iStorage++;
         step( 1 );
         break;

      case SN_AUTO  :
         Declaration->storage_class = SN_AUTO;
         iStorage++;
         step( 1 );
         break;

   /* fct specifiers */
      case SN_INLINE    :
         Declaration->fct_specifier = SN_INLINE;
         iModifier++;
         step( 1 );
         break;

      case SN_VIRTUAL   :
         Declaration->fct_specifier = SN_VIRTUAL;
         iModifier++;
         step( 1 );
         break;

      case SN_CLASS      :
      case SN_STRUCT     :
      case SN_UNION      :
         iTypeSpec++;
         if(( Declaration->Class = f_Class()) == 0 )
         {
            f_DeclarationDestroy( Declaration );
            Restore();
            f_SyntaxError( 2 );
            niveau--;
            return 0;
         }
         break;

      case SN_ENUM       :
         iTypeSpec++;
         if(( Declaration->Enum = f_Enum()) == 0 )
         {
            f_DeclarationDestroy( Declaration );
            Restore();
            f_SyntaxError( 3 );
            niveau--;
            return 0;
         }
         break;

      case SN_CONST      : Declaration->s_const    = True; goto modifier;
      case SN_VOLATILE   : Declaration->s_volatile = True; goto modifier;
modifier:
         iModifier++;
         step( 1 );
         break;

      case SN_CHAR       : Declaration->s_char     = True; goto type;
      case SN_SHORT      : Declaration->s_short    = True; goto type;
      case SN_INT        : Declaration->s_int      = True; goto type;
      case SN_LONG       : Declaration->s_long     = True; goto type;
      case SN_SIGNED     : Declaration->s_signed   = True; goto type;
      case SN_UNSIGNED   : Declaration->s_unsigned = True; goto type;
      case SN_FLOAT      : Declaration->s_float    = True; goto type;
      case SN_DOUBLE     : Declaration->s_double   = True; goto type;
      case SN_BOOL       : Declaration->s_bool     = True; goto type;
      case SN_VOID       : Declaration->s_void     = True; goto type;
type:
         iTypeSpec++;
         step( 1 );
         break;

      case ',':
      case ')':
      case SN_ELLIPSIS:
         if( iTypeSpec > 0 || iStorage > 0 || iModifier > 0 )
         {  /* optional abstract_declarator */
            niveau--;
            return Declaration;
         }
         else
         {
            f_DeclarationDestroy( Declaration );
            Restore();
            f_SyntaxError( 4 );
            niveau--;
            return 0;
         }

      case '=':
         if( iTypeSpec > 0 || iStorage > 0 || iModifier > 0 )
         {  /* optional abstract_declarator */
            step( 1 );
            Declarator = f_DeclaratorCreate();
            Declarator->Expr = f_AssignmentExpression();
            f_ListAddLast( &Declaration->ListDeclarator, (Elem_t) Declarator );
            niveau--;
            return Declaration;
         }
         else
         {
            f_DeclarationDestroy( Declaration );
            Restore();
            f_SyntaxError( 5 );
            niveau--;
            return 0;
         }

      default:
         if( iTypeSpec == 0 && iStorage == 0 && iModifier == 0 )
         {
            if(( Declaration->Name = f_CompleteClassName()))
            {
               iTypeSpec++;
            }
            else
            {
               f_DeclarationDestroy( Declaration );
               Restore();
               niveau--;
               return 0;
            }
         }
         else if( iTypeSpec == 0 )
         {
            if(( Declaration->Name = f_CompleteClassName()))
            {
               iTypeSpec++;
            }
            else if(( Declarator = f_ArgumentDeclarator()))
            {
               f_ListAddLast( &Declaration->ListDeclarator, (Elem_t) Declarator );
               niveau--;
               return Declaration;
            }
            else
            {
/* A constructor hivasok nagyon hasonlitanak a fuggveny deklaraciokra, ezert
   itt nem szabad nagyvonaluan atlepni a feldolgozhatatlan token-t */
               f_DeclarationDestroy( Declaration );
               Restore();
               niveau--;
               return 0;
            }
         }
         else
         {
            if(( Declarator = f_ArgumentDeclarator()))
            {
               f_ListAddLast( &Declaration->ListDeclarator, (Elem_t) Declarator );
               niveau--;
               return Declaration;
            }

            if(( Name = f_CompleteClassName()))
            {
               iTypeSpec++;
               if( Declaration->Name )
               {
#ifdef CORVEX
                  printf( "error: second name: %s %s (%s:%d.%d)\n"
                        , Declaration->Name->pcName
                        , Name->pcName
                        , filename_g
                        , f_lineno( 0 )
                        , f_charno( 0 )
                        );
#endif
                  f_NameDestroy( Name );
               }
               else
               {
                  Declaration->Name = Name;
               }
            }
            else
            {
/*             step( 1 );
   A constructor hivasok nagyon hasonlitanak a fuggveny deklaraciokra, ezert
   itt nem szabad nagyvonaluan atlepni a feldolgozhatatlan token-t */
               f_DeclarationDestroy( Declaration );
               Restore();
/*                f_SyntaxError( 7 ); */
               niveau--;
               return 0;
            }
         }
         break;
      }
   }
}