Ignore:
Timestamp:
Jan 23, 2019, 4:52:16 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
a200795
Parents:
9b086ca (diff), 1d832f4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r9b086ca rcde3891  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug  8 17:50:07 2018
    13 // Update Count     : 3998
     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());
     190        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
     191        type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
     192        } // if
    189193        return new ForCtrl(
    190                 distAttr( DeclarationNode::newTypeof( type ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
     194                distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
    191195                new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ),
    192                 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
    193206} // forCtrl
    194207
     
    214227
    215228// Types declaration for productions
    216 %union
    217 {
     229%union {
    218230        Token tok;
    219231        ParseNode * pn;
     
    254266%token ZERO_T ONE_T                                                                             // CFA
    255267%token VALIST                                                                                   // GCC
    256 %token TYPEOF LABEL                                                                             // GCC
     268%token TYPEOF BASETYPEOF LABEL                                                  // GCC
    257269%token ENUM STRUCT UNION
    258270%token EXCEPTION                                                                                // CFA
     
    290302%token ANDassign        ERassign        ORassign                                // &=   ^=      |=
    291303
    292 %token Erange                                                                                   // ~=
     304%token ErangeUpEq       ErangeDown      ErangeDownEq                    // ~=   -~      -~=
    293305%token ATassign                                                                                 // @=
    294306
     
    629641                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    630642        | postfix_expression ARROW no_attr_identifier
    631                 {
    632                         $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
    633                 }
     643                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
    634644        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    635645                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
     
    11301140        | FOR '(' push for_control_expression ')' statement pop
    11311141                { $$ = 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 ) ); }
    11321144        ;
    11331145
    11341146for_control_expression:
    1135         comma_expression_opt                                                            // CFA
    1136                 {
    1137                         if ( ! $1 ) {                                                           // => for ( ;; )
    1138                                 $$ = new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr );
    1139                         } else {
    1140                                 $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), OperKinds::LThan, $1->clone(),
    1141                                                          new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    1142                         } // if
    1143                 }
     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" ) ) ) ); }
    11441150        | constant_expression inclexcl constant_expression      // CFA
    11451151                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11461152        | constant_expression inclexcl constant_expression '~' constant_expression // CFA
    11471153                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
    1148         | comma_expression_opt ';' comma_expression                     // CFA
    1149                 {
    1150                         if ( ! $1 ) {
    1151                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1152                         } else if ( ! $3 ) {
    1153                                 SemanticError( yylloc, "Missing loop range." ); $$ = nullptr;
    1154                         } else {
    1155                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1156                                         $$ = forCtrl( $3, new string( identifier->name ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), OperKinds::LThan, $3->clone(),
    1157                                                                  new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    1158                                 } else {
    1159                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1160                                 } // if
    1161                         } // if
    1162                 }
    1163         | comma_expression_opt ';' constant_expression inclexcl constant_expression // CFA
    1164                 {
    1165                         if ( ! $1 ) {
    1166                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1167                         } else {
    1168                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1169                                         $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    1170                                 } else {
    1171                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1172                                 } // if
    1173                         } // if
    1174                 }
    1175         | comma_expression_opt ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA
    1176                 {
    1177                         if ( ! $1 ) {
    1178                                 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr;
    1179                         } else {
    1180                                 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1181                                         $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, $7 );
    1182                                 } else {
    1183                                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
    1184                                 } // if
    1185                         } // if
    1186                 }
    1187         | 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
    11881162                { $$ = new ForCtrl( $1, $3, $5 ); }
     1163        | ';' comma_expression_opt ';' comma_expression_opt
     1164                { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }
    11891165        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
    11901166                { $$ = new ForCtrl( $1, $2, $4 ); }
     
    11941170        '~'
    11951171                { $$ = OperKinds::LThan; }
    1196         | Erange
     1172        | ErangeUpEq
    11971173                { $$ = OperKinds::LEThan; }
     1174        | ErangeDown
     1175                { $$ = OperKinds::GThan; }
     1176        | ErangeDownEq
     1177                { $$ = OperKinds::GEThan; }
    11981178        ;
    11991179
     
    18441824
    18451825indirect_type:
    1846         TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
     1826        TYPEOF '(' type ')'                                                                     // GCC: typeof( x ) y;
    18471827                { $$ = $3; }
    1848         | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
     1828        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof( a+b ) y;
    18491829                { $$ = DeclarationNode::newTypeof( $3 ); }
    1850         | 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;
    18511835                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    1852         | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
     1836        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type( a+b ) y;
    18531837                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    18541838        | ZERO_T                                                                                        // CFA
Note: See TracChangeset for help on using the changeset viewer.