Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    ree27df2 r0982a056  
    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 Aug 30 17:02:25 2018
     13// Update Count     : 4029
    1414//
    1515
     
    186186} // fieldDecl
    187187
     188ExpressionNode *forInc( const OperKinds op ) {
     189        return new ExpressionNode( build_constantInteger( *new string( op == OperKinds::LThan || op == OperKinds::LEThan ? "1" : "-1" ) ) );
     190} // forInc
     191
    188192ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    189193        ConstantExpr *constant = dynamic_cast<ConstantExpr *>(type->get_expr());
     
    194198                distAttr( DeclarationNode::newTypeof( type ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
    195199                new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ),
    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 ) ) );
     200                new ExpressionNode( build_binary_val( OperKinds::PlusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) );
    198201} // forCtrl
    199202
     
    258261%token ZERO_T ONE_T                                                                             // CFA
    259262%token VALIST                                                                                   // GCC
    260 %token TYPEOF BASETYPEOF LABEL                                                  // GCC
     263%token TYPEOF LABEL                                                                             // GCC
    261264%token ENUM STRUCT UNION
    262265%token EXCEPTION                                                                                // CFA
     
    633636                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    634637        | postfix_expression ARROW no_attr_identifier
    635                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     638                {
     639                        $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
     640                }
    636641        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    637642                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
     
    11411146                        } else {
    11421147                                $$ = 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" ) ) ) );
     1148                                                          OperKinds::LThan, $1->clone(), forInc( OperKinds::LThan ) );
    11441149                        } // if
    11451150                }
    11461151        | constant_expression inclexcl constant_expression      // CFA
    1147                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1152                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, forInc( $2 ) ); }
    11481153        | constant_expression inclexcl constant_expression '~' constant_expression // CFA
    11491154                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
     
    11571162                                if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    11581163                                        $$ = 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" ) ) ) );
     1164                                                                  OperKinds::LThan, $3->clone(), forInc( OperKinds::LThan ) );
    11601165                                } else {
    11611166                                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
     
    11691174                        } else {
    11701175                                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" ) ) ) );
     1176                                        $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, forInc( $4 ) );
    11721177                                } else {
    11731178                                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
     
    18541859        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
    18551860                { $$ = 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 ); }
    18601861        | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type(x) y;
    18611862                { $$ = DeclarationNode::newAttr( $1, $3 ); }
Note: See TracChangeset for help on using the changeset viewer.