Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    ree27df2 rf1aeede  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct 21 08:27:29 2018
    13 // Update Count     : 4045
     12// Last Modified On : Thu Nov  8 18:08:23 2018
     13// Update Count     : 4052
    1414//
    1515
     
    187187
    188188ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    189         ConstantExpr *constant = dynamic_cast<ConstantExpr *>(type->get_expr());
     189        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->get_expr());
    190190        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
    191191        type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
    192192        } // if
    193193        return new ForCtrl(
    194                 distAttr( DeclarationNode::newTypeof( type ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
     194                distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
    195195                new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ),
    196196                new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto
    197197                                                                                          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
    198206} // forCtrl
    199207
     
    11321140        | FOR '(' push for_control_expression ')' statement pop
    11331141                { $$ = 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 ) ); }
    11341144        ;
    11351145
    11361146for_control_expression:
    1137         comma_expression_opt                                                            // CFA
    1138                 {
    1139                         if ( ! $1 ) {                                                           // => for ( ;; )
    1140                                 $$ = new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr );
    1141                         } else {
    1142                                 $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1143                                                           OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    1144                         } // if
    1145                 }
     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" ) ) ) ); }
    11461150        | constant_expression inclexcl constant_expression      // CFA
    11471151                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11481152        | constant_expression inclexcl constant_expression '~' constant_expression // CFA
    11491153                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
    1150         | comma_expression_opt ';' comma_expression                     // CFA
    1151                 {
    1152                         if ( ! $1 ) {
    1153                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1154                         } else if ( ! $3 ) {
    1155                                 SemanticError( yylloc, "Missing loop range." ); $$ = nullptr;
    1156                         } else {
    1157                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1158                                         $$ = forCtrl( $3, new string( identifier->name ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1159                                                                   OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    1160                                 } else {
    1161                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1162                                 } // if
    1163                         } // if
    1164                 }
    1165         | comma_expression_opt ';' constant_expression inclexcl constant_expression // CFA
    1166                 {
    1167                         if ( ! $1 ) {
    1168                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1169                         } else {
    1170                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1171                                         $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    1172                                 } else {
    1173                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1174                                 } // if
    1175                         } // if
    1176                 }
    1177         | comma_expression_opt ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA
    1178                 {
    1179                         if ( ! $1 ) {
    1180                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1181                         } else {
    1182                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1183                                         $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, $7 );
    1184                                 } else {
    1185                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1186                                 } // if
    1187                         } // if
    1188                 }
    1189         | 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
    11901162                { $$ = new ForCtrl( $1, $3, $5 ); }
     1163        | ';' comma_expression_opt ';' comma_expression_opt
     1164                { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }
    11911165        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
    11921166                { $$ = new ForCtrl( $1, $2, $4 ); }
     
    18501824
    18511825indirect_type:
    1852         TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
     1826        TYPEOF '(' type ')'                                                                     // GCC: typeof( x ) y;
    18531827                { $$ = $3; }
    1854         | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
     1828        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof( a+b ) y;
    18551829                { $$ = DeclarationNode::newTypeof( $3 ); }
    1856         | BASETYPEOF '(' type ')'                                                       // CFA: basetypeof(x) y;
    1857                 { $$ = $3; }
    1858         | BASETYPEOF '(' comma_expression ')'                           // CFA: basetypeof(a+b) y;
    1859                 { $$ = DeclarationNode::newTypeof( $3 ); }
    1860         | 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;
    18611835                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    1862         | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
     1836        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type( a+b ) y;
    18631837                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    18641838        | ZERO_T                                                                                        // CFA
Note: See TracChangeset for help on using the changeset viewer.