Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r0982a05 rf1aeede  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 30 17:02:25 2018
    13 // Update Count     : 4029
     12// Last Modified On : Thu Nov  8 18:08:23 2018
     13// Update Count     : 4052
    1414//
    1515
     
    186186} // fieldDecl
    187187
    188 ExpressionNode *forInc( const OperKinds op ) {
    189         return new ExpressionNode( build_constantInteger( *new string( op == OperKinds::LThan || op == OperKinds::LEThan ? "1" : "-1" ) ) );
    190 } // forInc
    191 
    192188ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    193         ConstantExpr *constant = dynamic_cast<ConstantExpr *>(type->get_expr());
     189        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->get_expr());
    194190        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
    195191        type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
    196192        } // if
    197193        return new ForCtrl(
    198                 distAttr( DeclarationNode::newTypeof( type ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
     194                distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
    199195                new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ),
    200                 new ExpressionNode( build_binary_val( OperKinds::PlusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) );
     196                new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto
     197                                                                                          OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) );
     198} // forCtrl
     199
     200ForCtrl * forCtrl( ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
     201        if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->get_expr()) ) {
     202                return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );
     203        } else {
     204                SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
     205        } // if
    201206} // forCtrl
    202207
     
    261266%token ZERO_T ONE_T                                                                             // CFA
    262267%token VALIST                                                                                   // GCC
    263 %token TYPEOF LABEL                                                                             // GCC
     268%token TYPEOF BASETYPEOF LABEL                                                  // GCC
    264269%token ENUM STRUCT UNION
    265270%token EXCEPTION                                                                                // CFA
     
    636641                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    637642        | postfix_expression ARROW no_attr_identifier
    638                 {
    639                         $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
    640                 }
     643                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
    641644        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    642645                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
     
    11371140        | FOR '(' push for_control_expression ')' statement pop
    11381141                { $$ = new StatementNode( build_for( $4, $6 ) ); }
     1142        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
     1143                { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), $4 ) ); }
    11391144        ;
    11401145
    11411146for_control_expression:
    1142         comma_expression_opt                                                            // CFA
    1143                 {
    1144                         if ( ! $1 ) {                                                           // => for ( ;; )
    1145                                 $$ = new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr );
    1146                         } else {
    1147                                 $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1148                                                           OperKinds::LThan, $1->clone(), forInc( OperKinds::LThan ) );
    1149                         } // if
    1150                 }
     1147        comma_expression                                                                        // CFA
     1148                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
     1149                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11511150        | constant_expression inclexcl constant_expression      // CFA
    1152                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, forInc( $2 ) ); }
     1151                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11531152        | constant_expression inclexcl constant_expression '~' constant_expression // CFA
    11541153                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
    1155         | comma_expression_opt ';' comma_expression                     // CFA
    1156                 {
    1157                         if ( ! $1 ) {
    1158                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1159                         } else if ( ! $3 ) {
    1160                                 SemanticError( yylloc, "Missing loop range." ); $$ = nullptr;
    1161                         } else {
    1162                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1163                                         $$ = forCtrl( $3, new string( identifier->name ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1164                                                                   OperKinds::LThan, $3->clone(), forInc( OperKinds::LThan ) );
    1165                                 } else {
    1166                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1167                                 } // if
    1168                         } // if
    1169                 }
    1170         | comma_expression_opt ';' constant_expression inclexcl constant_expression // CFA
    1171                 {
    1172                         if ( ! $1 ) {
    1173                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1174                         } else {
    1175                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1176                                         $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, forInc( $4 ) );
    1177                                 } else {
    1178                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1179                                 } // if
    1180                         } // if
    1181                 }
    1182         | comma_expression_opt ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA
    1183                 {
    1184                         if ( ! $1 ) {
    1185                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1186                         } else {
    1187                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1188                                         $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, $7 );
    1189                                 } else {
    1190                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1191                                 } // if
    1192                         } // if
    1193                 }
    1194         | comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
     1154        | comma_expression ';' comma_expression                         // CFA
     1155                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
     1156                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1157        | comma_expression ';' constant_expression inclexcl constant_expression // CFA
     1158                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1159        | comma_expression ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA
     1160                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); }
     1161        | comma_expression ';' comma_expression_opt ';' comma_expression_opt
    11951162                { $$ = new ForCtrl( $1, $3, $5 ); }
     1163        | ';' comma_expression_opt ';' comma_expression_opt
     1164                { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }
    11961165        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
    11971166                { $$ = new ForCtrl( $1, $2, $4 ); }
     
    18551824
    18561825indirect_type:
    1857         TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
     1826        TYPEOF '(' type ')'                                                                     // GCC: typeof( x ) y;
    18581827                { $$ = $3; }
    1859         | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
     1828        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof( a+b ) y;
    18601829                { $$ = DeclarationNode::newTypeof( $3 ); }
    1861         | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type(x) y;
     1830        | BASETYPEOF '(' type ')'                                                       // CFA: basetypeof( x ) y;
     1831                { $$ = DeclarationNode::newTypeof( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ), true ); }
     1832        | BASETYPEOF '(' comma_expression ')'                           // CFA: basetypeof( a+b ) y;
     1833                { $$ = DeclarationNode::newTypeof( $3, true ); }
     1834        | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type( x ) y;
    18621835                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    1863         | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
     1836        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type( a+b ) y;
    18641837                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    18651838        | ZERO_T                                                                                        // CFA
Note: See TracChangeset for help on using the changeset viewer.