📄 cp_expression.c
字号:
Expr_t Expr2; int operator; Save();#ifdef TRACE printf( "multiplicative_expression: %s\n", ident( 0 ));#endif if(( Expr1 = pm_expression()) == 0 ) { Restore(); return 0; } while( True ) { switch( token( 0 )) { case '*': operator = OPERATOR_MULT; break; case '/': operator = OPERATOR_DIV ; break; case '%': operator = OPERATOR_MOD ; break; default : return Expr1; } step( 1 ); if(( Expr2 = pm_expression()) == 0 ) { f_ExprDestroy( Expr1 ); Restore(); return 0; } Expr1 = ExprCreateOp2( operator, Expr1, Expr2 ); }}static Expr_t pm_expression( void ){ Expr_t Expr1; Expr_t Expr2; int operator; Save();#ifdef TRACE printf( "pm_expression: %s\n", ident( 0 ));#endif if(( Expr1 = cast_expression()) == 0 ) { Restore(); return 0; } while( True ) { switch( token( 0 )) { case SN_DOTstar : operator = OPERATOR_DOTstar ; break; case SN_ARROWstar: operator = OPERATOR_ARROWstar; break; default : return Expr1; } step( 1 ); if(( Expr2 = cast_expression()) == 0 ) { f_ExprDestroy( Expr1 ); Restore(); return 0; } Expr1 = ExprCreateOp2( operator, Expr1, Expr2 ); }}#define OLD_VERSION_OF_CAST#ifdef OLD_VERSION_OF_CASTstatic Expr_t cast_expression( void ){ Expr_t Expr; Expr_t Expr1; Expr_t Expr2; Type_t Type; Save();#ifdef TRACE printf( "cast_expression: %s\n", ident( 0 ));#endif if( token( 0 ) == '(' ) { int lineno_beg; int charno_beg; int lineno_end; int charno_end; Save(); lineno_beg = f_lineno( 0 ); charno_beg = f_charno( 0 ); step( 1 ); if(( Type = f_TypeName( ")" ))) { if( token( 0 ) == ')' ) { lineno_end = f_lineno( 0 ); charno_end = f_charno( 0 ) + identlen( 0 ); step( 1 ); if(( Expr2 = cast_expression())) { Expr1 = ExprCreateType( Type ); Expr1->lineno_beg = lineno_beg; Expr1->charno_beg = charno_beg; Expr1->lineno_end = lineno_end; Expr1->charno_end = lineno_end; return ExprCreateOp2( OPERATOR_CAST, Expr1, Expr2 ); } } f_TypeDestroy( Type ); } Restore(); } if(( Expr = unary_expression())) { return Expr; } Restore(); return 0;}#else/* elobb megnezzuk, hogy lehet-e ertelmezni a kifejezest, cast nelkul,** es ha nem, akkor nezzuk meg, hogy hatha cast-tal kezdodik*/static Expr_t cast_expression( void ){ Expr_t Expr; Expr_t Expr1; Expr_t Expr2; Type_t TypeCast; Expr_t ExprCast; int lineno_beg; int charno_beg; int lineno_end; int charno_end; Save();#ifdef TRACE printf( "cast_expression: %s\n", ident( 0 ));#endif if( token( 0 ) == '(' ) { int iva_expr; int iva_type; int token_after_par; Save(); step( 1 ); if(( ExprCast = expression())) { if( token( 0 ) == ')' ) { step( 1 ); iva_expr = iva; token_after_par = token( 0 ); } else { f_ExprDestroy( ExprCast ); ExprCast = 0; } } Restore(); lineno_beg = f_lineno( 0 ); charno_beg = f_charno( 0 ); step( 1 ); if(( TypeCast = f_TypeName( ")" ))) { if( token( 0 ) == ')' ) { lineno_end = f_lineno( 0 ); charno_end = f_charno( 0 ) + identlen( 0 ); step( 1 ); iva_type = iva; } else { f_TypeDestroy( TypeCast ); TypeCast = 0; } } Restore(); if( ExprCast && TypeCast ) { if( iva_type != iva_expr ) { f_InternalError( 72 ); } switch( token_after_par ) { case '+': case '-': /* inkabb az ExprCast-ot vesszuk */ f_ExprDestroy( ExprCast ); f_TypeDestroy( TypeCast ); goto unary_expression; default: /* inkabb a TypeCast-ot vesszuk */ f_ExprDestroy( ExprCast ); goto cast_expression; } } else if( ExprCast ) /* TypeCast == 0 */ { f_ExprDestroy( ExprCast ); goto unary_expression; } else if( TypeCast ) /* ExprCast == 0 */ {cast_expression: iva = iva_type; if(( Expr2 = cast_expression())) { Expr1 = ExprCreateType( TypeCast ); Expr1->lineno_beg = lineno_beg; Expr1->charno_beg = charno_beg; Expr1->lineno_end = lineno_end; Expr1->charno_end = charno_end; return ExprCreateOp2( OPERATOR_CAST, Expr1, Expr2 ); } } else /* ExprCast == 0 && TypeCast == 0 */ { return 0; } }unary_expression: if(( Expr = unary_expression())) { return Expr; } Restore(); return 0;}#endif /* OLD_VERSION_OF_CAST */static Expr_t unary_expression( void ){ Expr_t Expr; Expr_t Expr1; Type_t Type; int operator; int lineno_beg; int charno_beg; int lineno_end; int charno_end; Save();#ifdef TRACE printf( "unary_expression: %s\n", ident( 0 ));#endif if(( Expr = allocation_expression())) { goto ret; } if(( Expr = deallocation_expression())) { goto ret; } if( token( 0 ) != '~' ) /* 24.02.97 rigo : ~WS_BORDER miatt */ { if(( Expr = postfix_expression())) /* ezt csak az allocation es deallocation kifejezesek utan ellenorizzuk, hogy a new nevu valtozok is atmenjenek ( 24.02.97: erre nem lesz szukseg, ha a pass1 pontosan felmeri, hogy c vagy c++ projektrol van-e szo */ { goto ret; } } switch( token( 0 )) { case SN_SIZEOF: step( 1 ); if( token( 0 ) == '(' ) { Save(); lineno_beg = f_lineno( 0 ); charno_beg = f_charno( 0 ); step( 1 ); if(( Type = f_TypeName( ")" ))) { if( token( 0 ) == ')' ) { lineno_end = f_lineno( 0 ); charno_end = f_charno( 0 ) + identlen( 0 ); step( 1 ); Expr1 = ExprCreateType( Type ); Expr1->lineno_beg = lineno_beg; Expr1->charno_beg = charno_beg; Expr1->lineno_end = lineno_end; Expr1->charno_end = charno_end; Expr = ExprCreateOp1( OPERATOR_SIZEOF_TYPENAME, Expr1 ); goto ret; } else { f_TypeDestroy( Type ); } } Restore(); } if(( Expr1 = unary_expression())) { Expr = ExprCreateOp1( OPERATOR_SIZEOF_EXPRESSION, Expr1 ); goto ret; } break; case SN_ICR: step( 1 ); if(( Expr1 = unary_expression())) { Expr = ExprCreateOp1( OPERATOR_PRE_ICR, Expr1 ); goto ret; } break; case SN_DECR: step( 1 ); if(( Expr1 = unary_expression())) { Expr = ExprCreateOp1( OPERATOR_PRE_DECR, Expr1 ); goto ret; } break; case '*': operator = OPERATOR_STAR ; goto process; case '&': operator = OPERATOR_ET ; goto process; case '+': operator = OPERATOR_UPLUS ; goto process; case '-': operator = OPERATOR_UMINUS; goto process; case '!': operator = OPERATOR_NOT ; goto process; case '~': operator = OPERATOR_BNOT ; goto process;process: step( 1 ); if(( Expr1 = cast_expression())) { Expr = ExprCreateOp1( operator, Expr1 ); goto ret; } break; default: break; } Restore(); Expr = 0;ret:#ifdef TRACE printf( "unary_expression: return %d\n", Expr != 0 );#endif return Expr;}static Expr_t postfix_expression( void ){ Expr_t Expr1; Expr_t Expr2; List_t ListExpr; Name_t Name; Type_t Type; int operator; int lineno_beg; int charno_beg; int lineno_end; int charno_end; Save();#ifdef TRACE printf( "postfix_expression: %s\n", ident( 0 ));#endif Expr1 = 0; Expr2 = 0; switch( token( 0 )) { case SN_CHAR : Type = f_TypeCreateChar (); goto label; case SN_SHORT : Type = f_TypeCreateShort (); goto label; case SN_INT : Type = f_TypeCreateInt (); goto label; case SN_LONG : Type = f_TypeCreateLong (); goto label; case SN_SIGNED : Type = f_TypeCreateSigned (); goto label; case SN_UNSIGNED : Type = f_TypeCreateUnsigned(); goto label; case SN_FLOAT : Type = f_TypeCreateFloat (); goto label; case SN_DOUBLE : Type = f_TypeCreateDouble (); goto label; case SN_BOOL : Type = f_TypeCreateBool (); goto label; case SN_VOID : Type = f_TypeCreateVoid (); goto label;label: step( 1 ); if( token( 0 ) == '(' ) { lineno_beg = f_lineno( 0 ); charno_beg = f_charno( 0 ); step( 1 ); ListExpr = expression_list_opt(); if( token( 0 ) == ')' ) { lineno_end = f_lineno( 0 ); charno_end = f_charno( 0 ) + identlen( 0 ); step( 1 ); Expr1 = ExprCreateType( Type ); Expr1->lineno_beg = lineno_beg; Expr1->charno_beg = charno_beg; Expr1->lineno_end = lineno_end; Expr1->charno_end = charno_end; Expr1 = ExprCreateOp2List( OPERATOR_CONSTRUCTOR_CALL, Expr1, ListExpr ); } else { f_TypeDestroy( Type ); f_ListDestroy( ListExpr, (void(*)()) f_ExprDestroy ); Expr1 = 0; ListExpr = 0; Restore(); } } else { f_TypeDestroy( Type ); Restore(); } break; case SN_IDENTIFIER: case SN_CLCL: if(( Name = f_CompleteClassName())) { if( token( 0 ) == '(' ) { lineno_beg = f_lineno( 0 ); charno_beg = f_charno( 0 ); step( 1 ); if( f_IsNameSimpleTypeName( Name )) { ListExpr = expression_list_opt(); if( token( 0 ) == ')' ) { lineno_end = f_lineno( 0 ); charno_end = f_charno( 0 ) + identlen( 0 ); step( 1 ); Type = f_TypeCreateName( Name ); Expr1 = ExprCreateType( Type ); Expr1->lineno_beg = lineno_beg; Expr1->charno_beg = charno_beg; Expr1->lineno_end = lineno_end; Expr1->charno_end = charno_end; Expr1 = ExprCreateOp2List( OPERATOR_CONSTRUCTOR_CALL, Expr1, ListExpr ); } else { f_NameDestroy( Name ); f_ListDestroy( ListExpr, (void(*)()) f_ExprDestroy ); Expr1 = 0; ListExpr = 0; Restore(); } } else { f_NameDestroy( Name ); Restore(); } } else { f_NameDestroy( Name ); Restore(); } } else { Restore(); } break; } if( Expr1 == 0 ) { if(( Expr1 = primary_expression()) == 0 ) { Restore(); return 0; } } while( True ) { switch( token( 0 )) { case '[' : operator = OPERATOR_ARRAY; step( 1 ); if(( Expr2 = expression()) == 0 ) { f_ExprDestroy( Expr1 ); Restore(); return 0; } if( token( 0 ) == ']' ) { step( 1 ); } Expr1 = ExprCreateOp2( operator, Expr1, Expr2 ); break; case '(' : operator = OPERATOR_FUNCTION_CALL; step( 1 ); ListExpr = expression_list_opt(); f_StepTo( ')', ';', '{', '}', 0 ); if( token( 0 ) == ')' ) { step( 1 ); } else {/* f_InternalError( 29 ); *//* ez nem komoly, mert minden hibas c programban elojohet */#ifdef CORVEX printf( "expression_list is not terminated width ')': %s:%d.%d\n" , filename_g , f_lineno( 0 ) , f_charno( 0 ) );#endif f_ListDestroy( ListExpr, (void(*)()) f_ExprDestroy ); f_ExprDestroy( Expr1 ); Restore(); return 0; } Expr1 = ExprCreateOp2List( operator, Expr1, ListExpr ); break; case '.' : operator = OPERATOR_DOT; step( 1 ); if(( Expr2 = expression_member_name()) == 0 ) { f_ExprDestroy( Expr1 ); Restore(); return 0; } Expr1 = ExprCreateOp2( operator, Expr1, Expr2 ); break; case SN_ARROW : operator = OPERATOR_ARROW; step( 1 ); if(( Expr2 = expression_member_name()) == 0 ) { f_ExprDestroy( Expr1 ); Restore(); return 0; } Expr1 = ExprCreateOp2( operator, Expr1, Expr2 ); break; case SN_ICR: operator = OPERATOR_POST_ICR; step( 1 ); Expr1 = ExprCreateOp1( operator, Expr1 ); break; case SN_DECR: operator = OPERATOR_POST_DECR; step( 1 ); Expr1 = ExprCreateOp1( operator, Expr1 ); break; default : return Expr1; } }}static Expr_t primary_expression( void ){ Expr_t Expr; Type_t Type; Name_t Name; int lineno_beg; int charno_beg; Save();#ifdef TRACE printf( "primary_expression: %s\n", ident( 0 ));#endif switch( token( 0 )) {/* a c-ben elofordulhatnak mint valtozok */ case SN_ASM :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -