⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cp_declarator.c

📁 这是一个Linux下的集成开发环境
💻 C
📖 第 1 页 / 共 2 页
字号:
   Save();   switch( token( 0 ))   {   case '*':   case '&':   case SN_IDENTIFIER:   case SN_CLCL:      if(( OperPointer = f_PtrOperator()) == 0 )      {         Restore();         return 0;      }      List = __AbstractDeclarator();      f_ListAddLast( &List, (Elem_t) OperPointer );      return List;   case '[':      return f_FunctionOrArrayList( True );   case '(':      step( 1 );      if( List = __AbstractDeclarator())      {         if( token( 0 ) == ')' )         {            step( 1 );            f_ListConcat( &List, f_FunctionOrArrayList( True ));            return List;         }         else         {            Restore();            f_ListDestroy( List, (void(*)()) f_OperDestroy );         }      }      else      {         Restore();      }      return f_FunctionOrArrayList( True );   default:      return 0;   }}static Oper_t f_PtrOperator( void ){   Oper_t Oper = f_OperCreate();   Save();   switch( token( 0 ))   {   case '*':      Oper->type = POINTER_STAR;      step( 1 );      f_CvQualifierList( Oper );      return Oper;   case '&':      Oper->type = POINTER_AMPERSAND;      step( 1 );      f_CvQualifierList( Oper );      return Oper;   case SN_IDENTIFIER:   case SN_CLCL:      Oper->Name = f_CompleteClassName();      if( token( 0 ) != SN_CLCL )      {         /* int ( far * kfunc )(); esetet le kell kezelni !! */         Restore();         f_OperDestroy( Oper );#ifdef rigo         return 0;#else         /* ez itt egy veszelyes fejlesztes, ami utan jol le kell               tesztelni a programot 22.02.97 rigo */         step( 1 );  /* atlepjuk az identifier-t */         if(( Oper = f_PtrOperator()))         {            return Oper;         }         else         {            Restore();            return 0;         }#endif      }      step( 1 );      switch( token( 0 ))      {      case '*':         Oper->type = POINTER_STAR;         step( 1 );         f_CvQualifierList( Oper );         return Oper;      default:         Restore();         f_OperDestroy( Oper );         return 0;      }         default:      Restore();      f_OperDestroy( Oper );      return 0;   }}static Oper_t f_SimplePtrOperator( void ){   Oper_t Oper = f_OperCreate();   Save();   switch( token( 0 ))   {   case '*':      Oper->type = POINTER_STAR;      step( 1 );      f_CvQualifierList( Oper );      return Oper;   case SN_IDENTIFIER:   case SN_CLCL:      Oper->Name = f_CompleteClassName();      if( token( 0 ) != SN_CLCL )      {         Restore();         f_OperDestroy( Oper );         return 0;      }      step( 1 );      switch( token( 0 ))      {      case '*':         Oper->type = POINTER_STAR;         step( 1 );         f_CvQualifierList( Oper );         return Oper;      default:         Restore();         f_OperDestroy( Oper );         return 0;      }         default:      Restore();      f_OperDestroy( Oper );      return 0;   }}static List_t f_FunctionOrArrayList( Boolean_t may_function ){   List_t List = 0;   Oper_t Oper;   int iFunction = 0;   while( True )   {      switch( token( 0 ))      {      case '[':         if(( Oper = f_OperArray()))         {            f_ListAddLast( &List, (Elem_t) Oper );            break;         }         else         {            return List;         }      case SN_IDENTIFIER:      case '(':         if( ! may_function ) /* 12.03.97 rigo */         {            if (List)        /* Zsolt Koppany 11-jun-97; mem leak fix */            {               f_ListDestroy( List, (void(*)()) f_OperDestroy );               List = 0;            }            return 0;         }         if( ++iFunction == 2 )  /* nem lehet ket fuggveny egy listaban */         {            return List;         }         if(( Oper = f_OperFunction()))         {            f_ListAddLast( &List, (Elem_t) Oper );            break;         }         else         {            return List;         }      default:         return List;      }   }}static List_t f_ArrayList( void ){   List_t List = 0;   Oper_t Oper;   while( True )   {      switch( token( 0 ))      {      case '[':         if(( Oper = f_OperArray()))         {            f_ListAddLast( &List, (Elem_t) Oper );            break;         }         else         {            return List;         }      default:         return List;      }   }}static Oper_t f_OperArray( void ){   Oper_t Oper;   step( 1 );   Oper = f_OperCreate();   Oper->type = ARRAY;   Oper->Expr = expression();   f_StepTo( ']', 0 );   step( 1 );   return Oper;}static Oper_t f_OperFunction( void ){   Oper_t Oper;   Save();   if( test ) printf( "f_OperFunction: %s\n", ident( 0 ));   /* int a ANSI(( int b )); miatt */   if( token( 0 ) == SN_IDENTIFIER )   {      step( 1 );      if( token( 0 ) == '(' && token( 1 ) == '(' )      {/*         printf( "****** ide csak ritkan jon be %s(%d.%d)\n", filename_g, f_lineno( 0 ), f_charno( 0 ));*/         Oper = f_OperCreate();         Oper->type = FUNCTION;         step( 1 );         if(( Oper->ListDeclaration = f_ArgumentDeclarationList()))         {            f_StepTo( ')', 0 );            step( 1 );            f_CvQualifierList( Oper );            return Oper;         }         else         {            f_OperDestroy( Oper );            Restore();            return 0;         }      }      else      {         Restore();         return 0;      }   }   else  /* token( 0 ) == '(' */   {      Oper = f_OperCreate();      Oper->type = FUNCTION;      if(( Oper->ListDeclaration = f_ArgumentDeclarationList()))      {         f_CvQualifierList( Oper );         return Oper;      }      else      {         f_OperDestroy( Oper );         Restore();         return 0;      }   }}static void f_CvQualifierList( Oper_t Oper ){   while( True )   {      switch( token( 0 ))      {      case SN_CONST   : Oper->s_const    = True; break;      case SN_VOLATILE: Oper->s_volatile = True; break;      default      : return;      }      step( 1 );   }}extern Declarator_t f_DeclaratorCreate( void ){   Declarator_t Declarator = (Declarator_t) Malloc( sizeof( Declarator[0] ));   memset((void *) Declarator, 0, sizeof( Declarator[0] ));   Declarator->iCheck = DECLARATOR_CHECK;   return Declarator;}extern Declarator_t f_DeclaratorDuplicate( Declarator_t Declarator ){   Declarator_t DeclaratorDuplicate;   if( Declarator == 0 )   {      return 0;   }   if( Declarator->iCheck != DECLARATOR_CHECK ) Abort();   DeclaratorDuplicate = f_DeclaratorCreate();   DeclaratorDuplicate->Name     = f_NameDuplicate( Declarator->Name );   DeclaratorDuplicate->ListOper = f_ListDuplicate( Declarator->ListOper                                    , (Elem_t(*)(Elem_t)) f_OperDuplicate );   return DeclaratorDuplicate;}extern void f_DeclaratorDestroy( Declarator_t Declarator ){   if( Declarator )   {      if( Declarator->iCheck != DECLARATOR_CHECK ) Abort();      f_NameDestroy( Declarator->Name );      f_ExprDestroy( Declarator->Expr );      f_InitDestroy( Declarator->Init );      f_ListDestroy( Declarator->ListOper, (void(*)()) f_OperDestroy );      f_ListDestroy( Declarator->ListExpr, (void(*)()) f_ExprDestroy );      ckfree( (char*)Declarator );   }}extern void f_DeclaratorStrcat( char *pc, Declarator_t Declarator, int exact ){   Oper_t Oper;   char ac[10000];   /* old: 1000 */   int type;   if( Declarator->Name && exact )   {      strcpy( ac, Declarator->Name->pcName );   }   else   {      ac[0] = 0;   }   type = 0;   for( Oper = (Oper_t) d_ElemFirst( Declarator->ListOper )      ; Oper      ; Oper = Oper->OperNext )   {      f_OperStrcat( ac, Oper, type );      type = Oper->type;   }   f_Strcat( pc, ac );}static void f_OperStrcat( char *pc, Oper_t Oper, int type_prev ){   Declaration_t Declaration;   int bFirst;   char ac[10000];   /* old: 1000 */   ac[0] = 0;   switch( Oper->type )   {   case POINTER_STAR:      if( Oper->Name )      {         f_Strcat( ac, Oper->Name->pcName );         f_Strcat( ac, "::" );      }      f_Strcat( ac, "*" );      if( Oper->s_const    ) { f_Strcat( ac, "const"    ); }      if( Oper->s_volatile ) { f_Strcat( ac, "volatile" ); }      f_Strcat( ac, pc );      strcpy( pc, ac );      break;   case POINTER_AMPERSAND:      f_Strcat( ac, "&" );      if( Oper->s_const    ) { f_Strcat( ac, "const"    ); }      if( Oper->s_volatile ) { f_Strcat( ac, "volatile" ); }      f_Strcat( ac, pc );      strcpy( pc, ac );      break;   case ARRAY:      if( type_prev == POINTER_STAR || type_prev == POINTER_AMPERSAND )      {         f_Strcat( ac, "(" );         f_Strcat( ac, pc );         f_Strcat( ac, ")" );         strcpy( pc, ac );      }      f_Strcat( pc, "[]" );      break;   case FUNCTION:      if( type_prev == POINTER_STAR || type_prev == POINTER_AMPERSAND )      {         f_Strcat( ac, "(" );         f_Strcat( ac, pc );         f_Strcat( ac, ")" );         strcpy( pc, ac );      }      f_Strcat( pc, "(" );      bFirst = True;      for( Declaration = (Declaration_t) d_ElemFirst( Oper->ListDeclaration )         ; Declaration         ; Declaration = Declaration->DeclarationNext         )      {         if( bFirst )         {            bFirst = False;         }         else         {            f_Strcat( pc, "," );         }         f_DeclarationStrcat( pc, Declaration );      }      f_Strcat( pc, ")" );      break;   default:      f_InternalError( 11 );      break;   }}extern Boolean_t f_DeclaratorIsFunctionDefinition( Declarator_t Declarator ){   if( Declarator )   {      Oper_t Oper;      if(( Oper = (Oper_t) d_ElemFirst( Declarator->ListOper )))      {         if( Oper->type == FUNCTION )         {            return True;         }      }   }   return False;}extern void f_DeclaratorProcess( Declarator_t Declarator ){   if( Declarator )   {      Expr_t Expr;      Oper_t Oper;      if( Declarator->Expr ) f_ExprProcess( Declarator->Expr );      if( Declarator->Init ) f_InitProcess( Declarator->Init );      for( Expr = (Expr_t) d_ElemFirst( Declarator->ListExpr )         ; Expr         ; Expr = Expr->ExprNext )      {         f_ExprProcess( Expr );      }      for( Oper = (Oper_t) d_ElemFirst( Declarator->ListOper )         ; Oper         ; Oper = Oper->OperNext )      {         f_OperProcess( Oper );      }   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -