Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r9a705dc8 r1dbc8590  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 17 17:10:30 2018
    13 // Update Count     : 3144
     12// Last Modified On : Fri May 11 17:51:38 2018
     13// Update Count     : 3261
    1414//
    1515
     
    133133} // build_postfix_name
    134134
    135 bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
     135bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
    136136
    137137// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    208208%token<tok> ATTR_IDENTIFIER             ATTR_TYPEDEFname                ATTR_TYPEGENname
    209209%token<tok> INTEGERconstant             CHARACTERconstant               STRINGliteral
     210%token<tok> DIRECTIVE
    210211// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
    211212// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
     
    282283%type<decl> aggregate_type aggregate_type_nobody
    283284
    284 %type<decl> assertion assertion_list_opt
     285%type<decl> assertion assertion_list assertion_list_opt
    285286
    286287%type<en>   bit_subrange_size_opt bit_subrange_size
     
    301302
    302303%type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
    303 %type<en> field field_list field_name fraction_constants
     304%type<en> field field_list field_name fraction_constants_opt
    304305
    305306%type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr
     
    498499        | type_name '.' no_attr_identifier                                      // CFA, nested type
    499500                { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; }
     501//              { $$ = nullptr; }
    500502        | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
    501503                { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; }
     504//              { $$ = nullptr; }
    502505        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    503506                { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; }
     
    532535        | postfix_expression '.' no_attr_identifier
    533536                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
     537        | postfix_expression '.' INTEGERconstant                        // CFA, tuple index
     538                { $$ = new ExpressionNode( build_fieldSel( $1, build_constantInteger( *$3 ) ) ); }
     539        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
     540                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    534541        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
    535542                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    536         | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    537                 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    538543        | postfix_expression ARROW no_attr_identifier
    539544                {
    540545                        $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) );
    541546                }
    542         | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
    543                         { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    544547        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    545548                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
     549        | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
     550                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    546551        | postfix_expression ICR
    547552                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
     
    596601
    597602field_name:
    598         INTEGERconstant fraction_constants
     603        INTEGERconstant fraction_constants_opt
    599604                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger( *$1 ), $2 ) ); }
    600         | FLOATINGconstant fraction_constants
     605        | FLOATINGconstant fraction_constants_opt
    601606                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
    602         | no_attr_identifier fraction_constants
     607        | no_attr_identifier fraction_constants_opt
    603608                {
    604609                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
     
    606611        ;
    607612
    608 fraction_constants:
     613fraction_constants_opt:
    609614        // empty
    610615                { $$ = nullptr; }
    611         | fraction_constants FLOATING_FRACTIONconstant
     616        | fraction_constants_opt FLOATING_FRACTIONconstant
    612617                {
    613618                        Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 );
     
    875880                { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; }
    876881        | asm_statement
     882        | DIRECTIVE
     883                { $$ = new StatementNode( build_directive( $1 ) ); }
    877884        ;
    878885
     
    12041211asm_statement:
    12051212        ASM asm_volatile_opt '(' string_literal ')' ';'
    1206                 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
     1213                { $$ = new StatementNode( build_asm( $2, $4, 0 ) ); }
    12071214        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
    1208                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
     1215                { $$ = new StatementNode( build_asm( $2, $4, $6 ) ); }
    12091216        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    1210                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
     1217                { $$ = new StatementNode( build_asm( $2, $4, $6, $8 ) ); }
    12111218        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    1212                 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
     1219                { $$ = new StatementNode( build_asm( $2, $4, $6, $8, $10 ) ); }
    12131220        | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    1214                 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
     1221                { $$ = new StatementNode( build_asm( $2, $5, 0, $8, $10, $12 ) ); }
    12151222        ;
    12161223
     
    18661873                {
    18671874                        typedefTable.makeTypedef( *$3 );
     1875                        if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update
     1876                        forall = false;                                                         // reset
    18681877                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18691878                }
     
    22352244                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    22362245        | type_specifier identifier_parameter_declarator
     2246        | assertion_list
     2247                { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    22372248        ;
    22382249
     
    22512262        // empty
    22522263                { $$ = nullptr; }
    2253         | assertion_list_opt assertion
     2264        | assertion_list
     2265        ;
     2266
     2267assertion_list:                                                                                 // CFA
     2268        assertion
     2269        | assertion_list assertion
    22542270                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    22552271        ;
     
    23782394external_definition_list:
    23792395        external_definition
    2380         | external_definition_list push external_definition
    2381                 { $$ = $1 ? $1->appendList( $3 ) : $3; }
     2396        | external_definition_list
     2397                { forall = xxx; }
     2398          push external_definition
     2399                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23822400        ;
    23832401
     
    23932411        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
    23942412                {
    2395                         $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asmstmt( false, $3, 0 ) ) );
     2413                        $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) );
    23962414                }
    23972415        | EXTERN STRINGliteral                                                          // C++-style linkage specifier
     
    24112429                        $$ = $2;
    24122430                }
    2413         | type_qualifier_list '{' external_definition_list '}'                  // CFA, namespace
     2431        | type_qualifier_list
     2432                {
     2433                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2434                }
     2435          push '{' external_definition_list '}'                         // CFA, namespace
     2436                {
     2437                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2438                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
     2439                                        iter->addQualifiers( $1->clone() );
     2440                                } // if
     2441                        } // for
     2442                        xxx = false;
     2443                        delete $1;
     2444                        $$ = $5;
     2445                }
     2446        | declaration_qualifier_list
     2447                {
     2448                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2449                }
     2450          push '{' external_definition_list '}'                         // CFA, namespace
     2451                {
     2452                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2453                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
     2454                                        iter->addQualifiers( $1->clone() );
     2455                                } // if
     2456                        } // for
     2457                        xxx = false;
     2458                        delete $1;
     2459                        $$ = $5;
     2460                }
     2461        | declaration_qualifier_list type_qualifier_list
     2462                {
     2463                        // forall must be in the type_qualifier_list
     2464                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
     2465                }
     2466          push '{' external_definition_list '}'                         // CFA, namespace
     2467                {
     2468                        for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2469                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
     2470                                        iter->addQualifiers( $1->clone() );
     2471                                        iter->addQualifiers( $2->clone() );
     2472                                } // if
     2473                        } // for
     2474                        xxx = false;
     2475                        delete $1;
     2476                        delete $2;
     2477                        $$ = $6;
     2478                }
    24142479        ;
    24152480
     
    24372502with_clause_opt:
    24382503        // empty
    2439                 { $$ = nullptr; }
     2504                { $$ = nullptr; forall = false; }
    24402505        | WITH '(' tuple_expression_list ')'
    2441                 { $$ = $3; }
     2506                { $$ = $3; forall = false; }
    24422507        ;
    24432508
Note: See TracChangeset for help on using the changeset viewer.