コード例 #1
0
ファイル: cp_type.c プロジェクト: mildrock/dummy
extern Type_t f_TypeCreateString( void )
{
   Type_t Type = f_TypeCreate();
   Declarator_t Declarator = f_DeclaratorCreate();
   Oper_t Oper = f_OperCreate();

/* printf( "TypeCreateString\n" ); */

   Type->s_char = True;
   Type->s_const = True;
   Type->Declarator = Declarator;
   Oper->type = POINTER_STAR;
   f_ListAddLast( &Type->Declarator->ListOper, (Elem_t) Oper );
   return Type;
}
コード例 #2
0
ファイル: cp_statement.c プロジェクト: AndresGG/sn-8.4
extern Boolean_t f_CompoundStatement( char *types, char *names )
{
   int retval;

/* printf( "Compund Statement: (%s) (%s)\n", types, names ); */

   if( SymtabVariable == 0 )
   {
      SymtabVariable = SymtabCreate((void (*)(void*)) f_TypeDestroy );
   }

   if( SymtabClass == 0 )
   {
      SymtabClass = SymtabCreate((void (*)(void*)) f_ClassDestroy );
   }

   if( types && names )
   {
      /* feldolgozzuk a fuggveny argumentum listat */

      char *my_types, *types_beg, *types_end;
      char *my_names, *names_beg, *names_end;
      int iBreak;

      my_types = SN_StrDup( types );
      my_names = SN_StrDup( names );

      types_beg = my_types;
      names_beg = my_names;
      iBreak = False;

      while( ! iBreak )
      {
         if(( types_end = my_strchr( types_beg, ',' ))) { *types_end = 0; }
         else                                           { iBreak = True; }

         if(( names_end = my_strchr( names_beg, ',' ))) { *names_end = 0; }
         else                                           { iBreak = True; }

         if( *names_beg && types_beg[0] != '.' )
         {
            Type_t Type;

            Type = f_TypeFromString( types_beg );

            if( Type == 0 )
            {
/* 24.02.97 rigo */
/* int DEFUN(_IO_fflush, (fp), register _IO_FILE *fp ){} eseten elofordul */
/*             f_InternalError( 61 ); */
               Type = f_TypeCreateInt();
            }

            if( Type->Declarator == 0 )
            {
               Type->Declarator = f_DeclaratorCreate();
               Type->Declarator->Name = f_NameCreate( names_beg );
            }
            else
            {
               if( Type->Declarator->Name )
               {
                  f_InternalError( 62 );
               }
               else
               {
                  Type->Declarator->Name = f_NameCreate( names_beg );
               }
            }

            /* felodjuk az esetleges typedef-eket */
            Type = f_TypeBasic( Type, start_lineno_g - 1 );

            if( SymtabInsert( SymtabVariable
                            , Type->Declarator->Name->pcName
                            , (void *) Type
                            , niveauComp ))
            {
#ifdef SYMTAB_TRACE
               char acType[10000];  /* old: 1000 */

               f_TypeToString( Type, acType, 1 );
               printf( "argument type: %s ----- name: %s\n"
                     , acType
                     , Type->Declarator->Name->pcName
                     );
#endif
            }
            else
            {
               f_TypeDestroy( Type );
            }
         }

         if( ! iBreak )
         {
            types_beg = types_end + 1;
            names_beg = names_end + 1;
         }
      }

      ckfree( my_names );
      ckfree( my_types );
   }

   retval = compound_statement();

#ifdef SYMTAB_TRACE
   printf( "vor Clear\n" );
   SymtabPrint( SymtabVariable, 0 );
#endif

   SymtabClear( SymtabVariable );
   SymtabClear( SymtabClass    );

#ifdef SYMTAB_TRACE
   printf( "after Clear\n" );
   SymtabPrint( SymtabVariable, 0 );
#endif

   return retval;
}
コード例 #3
0
ファイル: cp_argument.c プロジェクト: mildrock/dummy
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;
      }
   }
}
コード例 #4
0
ファイル: cp_type.c プロジェクト: mildrock/dummy
static Declarator_t AbstractDeclarator( void )
{
   Oper_t OperPointer;
   Declarator_t Declarator;
   List_t ListOper;

   TokenSave();

/* printf( "AbstractDeclartor: %s {%s}\n", TokenIdent( 0 ), pcLex ); */

   switch( Token( 0 ))
   {
   case '*':
   case '&':
   case SN_IDENTIFIER:
   case SN_CLCL:
      if(( OperPointer = PtrOperator()) == 0 )
      {
         return 0;
      }
      if(( Declarator = AbstractDeclarator()) == 0 )  /* 14.02.97 rigo */
      {
         Declarator = f_DeclaratorCreate();
      }
      f_ListAddLast( &Declarator->ListOper, (Elem_t) OperPointer );
      return Declarator;

   case '[':
      Declarator = f_DeclaratorCreate();
      Declarator->ListOper = FunctionOrArrayList();
      return Declarator;

   case '(':
      TokenStep( 1 );
      if( OperPointer = PtrOperator())
      {
         f_OperDestroy( OperPointer );
         TokenRestore();
         TokenStep( 1 );
         if( Declarator = AbstractDeclarator())
         {
            if( Token( 0 ) == ')' )
            {
               TokenStep( 1 );
               ListOper = FunctionOrArrayList();
               f_ListConcat( &Declarator->ListOper, ListOper );
               return Declarator;
            }
            else
            {
               TokenRestore();
               f_DeclaratorDestroy( Declarator );
               return 0;
            }
         }
         else
         {
            TokenRestore();
            return 0;
         }
      }
      else if( Token( 0 ) == '[' )  /* 06.03.97 rigo: Void (*([]))() miatt */
      {
         if( Declarator = AbstractDeclarator())
         {
            if( Token( 0 ) == ')' )
            {
               TokenStep( 1 );
               ListOper = FunctionOrArrayList();
               f_ListConcat( &Declarator->ListOper, ListOper );
               return Declarator;
            }
            else
            {
               TokenRestore();
               f_DeclaratorDestroy( Declarator );
               return 0;
            }
         }
         else
         {
            TokenRestore();
            return 0;
         }
      }
      else
      {
         TokenRestore();
         Declarator = f_DeclaratorCreate();
         Declarator->ListOper = FunctionOrArrayList();
         return Declarator;
      }

   default:
      return 0;
   }
}