Changeset b6ad601


Ignore:
Timestamp:
Nov 2, 2018, 7:43:28 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
76beed8
Parents:
d6a98f3
Message:

start basetypeof, update loop control, remove unnecessary 0/1 check from parsing

Files:
1 added
1 deleted
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    rd6a98f3 rb6ad601  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Aug 29 15:02:41 2018
    13  * Update Count     : 686
     12 * Last Modified On : Thu Nov  1 20:57:35 2018
     13 * Update Count     : 687
    1414 */
    1515
     
    209209__attribute__   { KEYWORD_RETURN(ATTRIBUTE); }                  // GCC
    210210auto                    { KEYWORD_RETURN(AUTO); }
     211basetypeof              { KEYWORD_RETURN(BASETYPEOF); }                 // CFA
    211212_Bool                   { KEYWORD_RETURN(BOOL); }                               // C99
    212213break                   { KEYWORD_RETURN(BREAK); }
  • src/Parser/parser.yy

    rd6a98f3 rb6ad601  
    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  1 20:59:49 2018
     13// Update Count     : 4030
    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 ) {
    193189        ConstantExpr *constant = dynamic_cast<ConstantExpr *>(type->get_expr());
     
    198194                distAttr( DeclarationNode::newTypeof( type ), 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 ) ) );
    201198} // forCtrl
    202199
     
    261258%token ZERO_T ONE_T                                                                             // CFA
    262259%token VALIST                                                                                   // GCC
    263 %token TYPEOF LABEL                                                                             // GCC
     260%token TYPEOF BASETYPEOF LABEL                                                  // GCC
    264261%token ENUM STRUCT UNION
    265262%token EXCEPTION                                                                                // CFA
     
    636633                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    637634        | postfix_expression ARROW no_attr_identifier
    638                 {
    639                         $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
    640                 }
     635                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
    641636        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    642637                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
     
    11461141                        } else {
    11471142                                $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1148                                                           OperKinds::LThan, $1->clone(), forInc( OperKinds::LThan ) );
     1143                                                          OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    11491144                        } // if
    11501145                }
    11511146        | constant_expression inclexcl constant_expression      // CFA
    1152                 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, forInc( $2 ) ); }
     1147                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11531148        | constant_expression inclexcl constant_expression '~' constant_expression // CFA
    11541149                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
     
    11621157                                if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    11631158                                        $$ = forCtrl( $3, new string( identifier->name ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1164                                                                   OperKinds::LThan, $3->clone(), forInc( OperKinds::LThan ) );
     1159                                                                  OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    11651160                                } else {
    11661161                                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
     
    11741169                        } else {
    11751170                                if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) {
    1176                                         $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, forInc( $4 ) );
     1171                                        $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) );
    11771172                                } else {
    11781173                                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr;
     
    18551850
    18561851indirect_type:
    1857         TYPEOF '(' type ')'                                                                     // GCC: typeof(x) y;
     1852        TYPEOF '(' type ')'                                                                     // GCC: typeof( x ) y;
    18581853                { $$ = $3; }
    1859         | TYPEOF '(' comma_expression ')'                                       // GCC: typeof(a+b) y;
     1854        | TYPEOF '(' comma_expression ')'                                       // GCC: typeof( a+b ) y;
    18601855                { $$ = DeclarationNode::newTypeof( $3 ); }
    1861         | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type(x) y;
     1856        | BASETYPEOF '(' type ')'                                                       // CFA: basetypeof( x ) y;
     1857                { $$ = DeclarationNode::newTypeof( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ), true ); }
     1858        | BASETYPEOF '(' comma_expression ')'                           // CFA: basetypeof( a+b ) y;
     1859                { $$ = DeclarationNode::newTypeof( $3, true ); }
     1860        | ATTR_TYPEGENname '(' type ')'                                         // CFA: e.g., @type( x ) y;
    18621861                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    1863         | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type(a+b) y;
     1862        | ATTR_TYPEGENname '(' comma_expression ')'                     // CFA: e.g., @type( a+b ) y;
    18641863                { $$ = DeclarationNode::newAttr( $1, $3 ); }
    18651864        | ZERO_T                                                                                        // CFA
  • tests/.expect/loopctrl.txt

    rd6a98f3 rb6ad601  
    33empty
    44
     5zero
    56A
    6 A A
    77A A A A A A A A A A
    88B B B B B
     
    1010D D D D D
    1111E E E E E
    12 0 1 2 3 4 5 6 7 8 9
     12
    13130 1 2 3 4 5 6 7 8 9
    14141 3 5 7 9
     
    18182 4 6 8 10
    191910 8 6 4 2
     20
     21
    20223 6 9
     23
    2124(0 0)(1 1)(2 2)(3 3)(4 4)(5 5)(6 6)(7 7)(8 8)(9 9)
    2225(0 0)(1 1)(2 2)(3 3)(4 4)(5 5)(6 6)(7 7)(8 8)(9 9)
     26
    2327(0 0)(1 1)(2 2)(3 3)(4 4)(5 5)(6 6)(7 7)(8 8)(9 9)
    2428(0 0)(1 1)(2 2)(3 3)(4 4)(5 5)(6 6)(7 7)(8 8)(9 9)
     29(0 0)(1 1)(2 2)(3 3)(4 4)(5 5)(6 6)(7 7)(8 8)(9 9)(10 10)
     30(0 0)(1 1)(2 2)(3 3)(4 4)(5 5)(6 6)(7 7)(8 8)(9 9)(10 10)
     31
     32(10 10)(9 9)(8 8)(7 7)(6 6)(5 5)(4 4)(3 3)(2 2)(1 1)
     33(10 10)(9 9)(8 8)(7 7)(6 6)(5 5)(4 4)(3 3)(2 2)(1 1)
     34(10 10)(9 9)(8 8)(7 7)(6 6)(5 5)(4 4)(3 3)(2 2)(1 1)(0 0)
     35(10 10)(9 9)(8 8)(7 7)(6 6)(5 5)(4 4)(3 3)(2 2)(1 1)(0 0)
Note: See TracChangeset for help on using the changeset viewer.