Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r45161b4d rbd85400  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 13 16:58:43 2016
    13 // Update Count     : 1519
     12// Last Modified On : Mon Feb  1 18:22:42 2016
     13// Update Count     : 1483
    1414//
    1515
     
    5151#include <cstdio>
    5252#include <stack>
     53#include "TypedefTable.h"
    5354#include "lex.h"
    54 #include "parser.h"
    5555#include "ParseNode.h"
    56 #include "TypedefTable.h"
    5756#include "TypeData.h"
    5857#include "LinkageSpec.h"
     
    7574%token FORALL LVALUE                                                                    // CFA
    7675%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    77 %token VALIST                                                                                   // GCC
    7876%token BOOL COMPLEX IMAGINARY                                                   // C99
    7977%token TYPEOF LABEL                                                                             // GCC
    8078%token ENUM STRUCT UNION
    81 %token OTYPE FTYPE DTYPE TRAIT                                          // CFA
     79%token TYPE FTYPE DTYPE CONTEXT                                                 // CFA
    8280%token SIZEOF OFFSETOF
    8381%token ATTRIBUTE EXTENSION                                                              // GCC
     
    173171%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type_name indirect_type_name
    174172
    175 %type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier
     173%type<decl> context_declaration context_declaration_list context_declaring_list context_specifier
    176174
    177175%type<decl> declaration declaration_list declaration_list_opt declaration_qualifier_list
     
    199197%type<decl> new_array_parameter_1st_dimension
    200198
    201 %type<decl> new_trait_declaring_list new_declaration new_field_declaring_list
     199%type<decl> new_context_declaring_list new_declaration new_field_declaring_list
    202200%type<decl> new_function_declaration new_function_return new_function_specifier
    203201
     
    372370                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1 ); }
    373371        | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99
    374                 { $$ = new CompoundLiteralNode( $2, new InitializerNode( $5, true ) ); }
     372                { $$ = 0; }
    375373        | postfix_expression '{' argument_expression_list '}' // CFA
    376374                {
     
    450448                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), new TypeValueNode( $3 )); }
    451449        | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')'
    452                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::OffsetOf ), new TypeValueNode( $3 ), new VarRefNode( $5 )); }
     450        { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::OffsetOf ), new TypeValueNode( $3 ), new VarRefNode( $5 )); }
    453451        | ATTR_IDENTIFIER
    454452                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 )); }
     
    10221020        | new_function_declaration pop ';'
    10231021        | type_declaring_list pop ';'
    1024         | trait_specifier pop ';'
     1022        | context_specifier pop ';'
    10251023        ;
    10261024
     
    10291027                {
    10301028                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    1031                         $$ = $1->addInitializer( $2 );
     1029                        $$ = $1;
    10321030                }
    10331031        | declaration_qualifier_list new_variable_specifier initializer_opt
     
    10361034                {
    10371035                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    1038                         $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
     1036                        $$ = $2->addQualifiers( $1 );
    10391037                }
    10401038        | new_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    10411039                {
    10421040                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
    1043                         $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) );
     1041                        $$ = $1->appendList( $1->cloneType( $5 ) );
    10441042                }
    10451043        ;
     
    13471345        | IMAGINARY                                                                                     // C99
    13481346                { $$ = DeclarationNode::newBasicType( DeclarationNode::Imaginary ); }
    1349         | VALIST                                                                                        // GCC, __builtin_va_list
    1350                 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
    13511347        ;
    13521348
     
    14381434                { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3 ); }
    14391435        | aggregate_key no_attr_identifier_or_type_name
    1440                 {
    1441                         typedefTable.makeTypedef( *$2 );
    1442                         $$ = DeclarationNode::newAggregate( $1, $2, 0, 0 );
    1443                 }
    1444         | aggregate_key no_attr_identifier_or_type_name
    1445                 { typedefTable.makeTypedef( *$2 ); }
    1446                 '{' field_declaration_list '}'
    1447                 { $$ = DeclarationNode::newAggregate( $1, $2, 0, $5); }
     1436                { $$ = DeclarationNode::newAggregate( $1, $2, 0, 0 ); }
     1437        | aggregate_key no_attr_identifier_or_type_name '{' field_declaration_list '}'
     1438                { $$ = DeclarationNode::newAggregate( $1, $2, 0, $4 ); }
    14481439        | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA
    1449                 { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6 ); }
     1440                { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6 ); }
    14501441        | aggregate_key typegen_name                                            // CFA, S/R conflict
    14511442                { $$ = $2; }
     
    15251516        enum_key '{' enumerator_list comma_opt '}'
    15261517                { $$ = DeclarationNode::newEnum( 0, $3 ); }
     1518        | enum_key no_attr_identifier_or_type_name '{' enumerator_list comma_opt '}'
     1519                { $$ = DeclarationNode::newEnum( $2, $4 ); }
    15271520        | enum_key no_attr_identifier_or_type_name
    1528                 {
    1529                         typedefTable.makeTypedef( *$2 );
    1530                         $$ = DeclarationNode::newEnum( $2, 0 );
    1531                 }
    1532         | enum_key no_attr_identifier_or_type_name
    1533                 { typedefTable.makeTypedef( *$2 ); }
    1534                 '{' enumerator_list comma_opt '}'
    1535                 { $$ = DeclarationNode::newEnum( $2, $5 ); }
     1521                { $$ = DeclarationNode::newEnum( $2, 0 ); }
    15361522        ;
    15371523
     
    18171803
    18181804type_class:                                                                                             // CFA
    1819         OTYPE
     1805        TYPE
    18201806                { $$ = DeclarationNode::Type; }
    18211807        | DTYPE
     
    18351821        '|' no_attr_identifier_or_type_name '(' type_name_list ')'
    18361822                {
    1837                         typedefTable.openTrait( *$2 );
    1838                         $$ = DeclarationNode::newTraitUse( $2, $4 );
    1839                 }
    1840         | '|' '{' push trait_declaration_list '}'
     1823                        typedefTable.openContext( *$2 );
     1824                        $$ = DeclarationNode::newContextUse( $2, $4 );
     1825                }
     1826        | '|' '{' push context_declaration_list '}'
    18411827                { $$ = $4; }
    1842         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_name_list ')'
     1828        | '|' '(' push type_parameter_list pop ')' '{' push context_declaration_list '}' '(' type_name_list ')'
    18431829                { $$ = 0; }
    18441830        ;
     
    18551841
    18561842type_declaring_list:                                                                    // CFA
    1857         OTYPE type_declarator
    1858                 { $$ = $2; }
    1859         | storage_class_list OTYPE type_declarator
     1843        TYPE type_declarator
     1844                { $$ = $2; }
     1845        | storage_class_list TYPE type_declarator
    18601846                { $$ = $3->addQualifiers( $1 ); }
    18611847        | type_declaring_list ',' type_declarator
     
    18831869        ;
    18841870
    1885 trait_specifier:                                                                                // CFA
    1886         TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
     1871context_specifier:                                                                              // CFA
     1872        CONTEXT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
    18871873                {
    18881874                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
    1889                         $$ = DeclarationNode::newTrait( $2, $5, 0 );
    1890                 }
    1891         | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
    1892                 {
    1893                         typedefTable.enterTrait( *$2 );
     1875                        $$ = DeclarationNode::newContext( $2, $5, 0 );
     1876                }
     1877        | CONTEXT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
     1878                {
     1879                        typedefTable.enterContext( *$2 );
    18941880                        typedefTable.enterScope();
    18951881                }
    1896           trait_declaration_list '}'
    1897                 {
    1898                         typedefTable.leaveTrait();
     1882          context_declaration_list '}'
     1883                {
     1884                        typedefTable.leaveContext();
    18991885                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
    1900                         $$ = DeclarationNode::newTrait( $2, $5, $10 );
    1901                 }
    1902         ;
    1903 
    1904 trait_declaration_list:                                                         // CFA
    1905         trait_declaration
    1906         | trait_declaration_list push trait_declaration
     1886                        $$ = DeclarationNode::newContext( $2, $5, $10 );
     1887                }
     1888        ;
     1889
     1890context_declaration_list:                                                               // CFA
     1891        context_declaration
     1892        | context_declaration_list push context_declaration
    19071893                { $$ = $1->appendList( $3 ); }
    19081894        ;
    19091895
    1910 trait_declaration:                                                                      // CFA
    1911         new_trait_declaring_list pop ';'
    1912         | trait_declaring_list pop ';'
    1913         ;
    1914 
    1915 new_trait_declaring_list:                                                               // CFA
     1896context_declaration:                                                                    // CFA
     1897        new_context_declaring_list pop ';'
     1898        | context_declaring_list pop ';'
     1899        ;
     1900
     1901new_context_declaring_list:                                                             // CFA
    19161902        new_variable_specifier
    19171903                {
     
    19241910                        $$ = $1;
    19251911                }
    1926         | new_trait_declaring_list pop ',' push identifier_or_type_name
     1912        | new_context_declaring_list pop ',' push identifier_or_type_name
    19271913                {
    19281914                        typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
     
    19311917        ;
    19321918
    1933 trait_declaring_list:                                                                   // CFA
     1919context_declaring_list:                                                                 // CFA
    19341920        type_specifier declarator
    19351921                {
     
    19371923                        $$ = $2->addType( $1 );
    19381924                }
    1939         | trait_declaring_list pop ',' push declarator
     1925        | context_declaring_list pop ',' push declarator
    19401926                {
    19411927                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     
    28232809        std::cout << "Error ";
    28242810        if ( yyfilename ) {
    2825                 std::cout << "in file " << yyfilename << " ";
     2811            std::cout << "in file " << yyfilename << " ";
    28262812        } // if
    28272813        std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;
Note: See TracChangeset for help on using the changeset viewer.