示例#1
0
static Declarator_t f_ArgAbstractDeclarator( void )
{
   Declarator_t Declarator;
   Save();

   if(( Declarator = f_AbstractDeclarator()))
   {
      if( token( 0 ) == '=' )
      {
         step( 1 );
         Declarator->Expr = f_AssignmentExpression();
      }

      switch( token( 0 ))
      {
         case ',':
         case ')':
         case SN_ELLIPSIS:
            return Declarator;
         default:
            f_DeclaratorDestroy( Declarator );
            Restore();  /* 21.02.97 rigo */
            return 0;
      }
   }
   Restore();  /* 21.02.97 rigo */
   return 0;
}
示例#2
0
文件: cp_init.c 项目: AndresGG/sn-8.4
extern Init_t f_Init( char cTerminator )
{
   Init_t Init;
   List_t ListInit;
   Expr_t Expr;
   Save();
   niveau++;

   if( token( 0 ) == '{' )
   {
      step( 1 );

      ListInit = f_InitList( '}' );

      if( token( 0 ) == '}' )
      {
         step( 1 );
      }

      Init = f_InitCreate();
      Init->ListInit = ListInit;
      niveau--;
      return Init;
   }
   else if(( Expr = f_AssignmentExpression()))
   {
      Init = f_InitCreate();
      Init->Expr = Expr;
      niveau--;
      return Init;
   }
   else
   {
      f_StepTo( ',', ';', cTerminator, 0 );
      Restore();
      niveau--;
      return 0;
   }
}
示例#3
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;
      }
   }
}