Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rab57786 r8d2844a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 22 14:15:15 2016
    13 // Update Count     : 1943
     12// Last Modified On : Thu Aug 18 23:49:10 2016
     13// Update Count     : 1909
    1414//
    1515
     
    5555#include "LinkageSpec.h"
    5656
    57 union DeclQualifiers {
    58         unsigned int value;                                                                     // assume 32-bits
    59         struct {
    60                 bool Extern : 1;
    61                 bool Static : 1;
    62                 bool Auto : 1;
    63                 bool Register : 1;
    64                 bool Inline : 1;
    65                 bool Fortran : 1;
    66                 bool Noreturn : 1;
    67                 bool Threadlocal : 1;
    68                 bool Extension : 1;
    69                 bool Lvalue : 1;
    70                 bool Const : 1;
    71                 bool Volatile : 1;
    72                 bool Restrict : 1;
    73                 bool Atomic : 1;
    74         } qual;
    75 }; // DeclQualifiers
    76 DeclQualifiers declQualifiers = { 0 };
    77 
    78 union DeclType {
    79         unsigned int value;                                                                     // assume 32-bits
    80         struct {
    81                 bool Char : 1;
    82                 bool Bool : 1;
    83                 bool Short : 1;
    84                 bool Int : 1;
    85                 bool Float : 1;
    86                 bool Double : 1;
    87                 bool Long : 1;
    88                 bool Signed : 1;
    89                 bool Unsigned : 1;
    90                 bool Void : 1;
    91                 bool Complex : 1;
    92                 bool Imaginary : 1;
    93                 bool Valist : 1;
    94         } type;
    95 }; // DeclType
    96 DeclType declTypes = { 0 };
    97 
    9857extern DeclarationNode * parseTree;
    9958extern LinkageSpec::Spec linkage;
     
    10261std::stack< LinkageSpec::Spec > linkageStack;
    10362
    104 void appendStr( std::string *to, std::string *from ) {
     63void appendStr( std::string &to, std::string *from ) {
    10564        // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    106         to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
     65        to.insert( to.length() - 1, from->substr( 1, from->length() - 2 ) );
    10766} // appendStr
    10867%}
     
    167126        InitializerNode *in;
    168127        OperKinds op;
    169         std::string *str;
    170128        bool flag;
    171129}
     
    173131%type<tok> identifier  no_01_identifier  no_attr_identifier zero_one
    174132%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name
    175 %type<constant> string_literal
    176 %type<str> string_literal_list
     133%type<constant> string_literal_list
    177134
    178135// expressions
     
    339296
    340297push:
    341                 { typedefTable.enterScope(); }
     298                {
     299                        typedefTable.enterScope();
     300                }
    342301        ;
    343302
    344303pop:
    345                 { typedefTable.leaveScope(); }
     304                {
     305                        typedefTable.leaveScope();
     306                }
    346307        ;
    347308
     
    350311constant:
    351312                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    352         INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
    353         | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
    354         | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
     313        INTEGERconstant                                                                 { $$ = new ExpressionNode( build_constantInteger( assign_strptr($1) ) ); }
     314        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( assign_strptr($1) ) ); }
     315        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( assign_strptr($1) ) ); }
    355316        ;
    356317
     
    376337        ;
    377338
    378 string_literal:
    379         string_literal_list                                                     { $$ = build_constantStr( *$1 ); }
    380         ;
    381 
    382339string_literal_list:                                                                    // juxtaposed strings are concatenated
    383         STRINGliteral                                                           { $$ = $1; } // conversion from tok to str
     340        STRINGliteral                                                           { $$ = build_constantStr( assign_strptr($1) ); }
    384341        | string_literal_list STRINGliteral
    385342                {
    386                         appendStr( $1, $2 );                                            // append 2nd juxtaposed string to 1st
     343                        appendStr( $1->get_constant()->get_value(), $2 );
    387344                        delete $2;                                                                      // allocated by lexer
    388                         $$ = $1;                                                                        // conversion from tok to str
     345                        $$ = $1;
    389346                }
    390347        ;
     
    413370        | postfix_expression '(' argument_expression_list ')'
    414371                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    415                 // ambiguity with .0 so space required after field-selection, e.g.
     372        // ambiguity with .0 so space required after field-selection, e.g.
    416373                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    417374        | postfix_expression '.' no_attr_identifier
     
    455412        no_attr_identifier
    456413                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    457                 // ambiguity with .0 so space required after field-selection, e.g.
     414        // ambiguity with .0 so space required after field-selection, e.g.
    458415                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    459416        | no_attr_identifier '.' field
     
    473430        | constant
    474431                { $$ = $1; }
    475         | string_literal
     432        | string_literal_list
    476433                { $$ = new ExpressionNode( $1 ); }
    477434        | EXTENSION cast_expression                                                     // GCC
     
    852809fall_through_opt:                                                                               // CFA
    853810        // empty
    854                 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
     811                { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } // insert implicit break
    855812        | fall_through
    856813        ;
     
    881838jump_statement:
    882839        GOTO IDENTIFIER ';'
    883                 { $$ = new StatementNode( build_branch( $2, BranchStmt::Goto ) ); }
     840                { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Goto ) ); }
    884841        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
    885842                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
     
    888845        | CONTINUE ';'
    889846                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    890                 { $$ = new StatementNode( build_branch( BranchStmt::Continue ) ); }
     847                { $$ = new StatementNode( build_branch( "", BranchStmt::Continue ) ); }
    891848        | CONTINUE IDENTIFIER ';'                                                       // CFA, multi-level continue
    892849                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    893850                // the target of the transfer appears only at the start of an iteration statement.
    894                 { $$ = new StatementNode( build_branch( $2, BranchStmt::Continue ) ); }
     851                { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Continue ) ); }
    895852        | BREAK ';'
    896853                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    897                 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); }
     854                { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); }
    898855        | BREAK IDENTIFIER ';'                                                          // CFA, multi-level exit
    899856                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    900857                // the target of the transfer appears only at the start of an iteration statement.
    901                 { $$ = new StatementNode( build_branch( $2, BranchStmt::Break ) ); }
     858                { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Break ) ); }
    902859        | RETURN comma_expression_opt ';'
    903860                { $$ = new StatementNode( build_return( $2 ) ); }
     
    973930
    974931asm_statement:
    975         ASM asm_volatile_opt '(' string_literal ')' ';'
     932        ASM asm_volatile_opt '(' string_literal_list ')' ';'
    976933                { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
    977         | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
     934        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC
    978935                { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
    979         | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
     936        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    980937                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
    981         | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
     938        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    982939                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
    983         | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
     940        | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    984941                { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
    985942        ;
     
    1005962
    1006963asm_operand:                                                                                    // GCC
    1007         string_literal '(' constant_expression ')'
     964        string_literal_list '(' constant_expression ')'
    1008965                { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
    1009         | '[' constant_expression ']' string_literal '(' constant_expression ')'
     966        | '[' constant_expression ']' string_literal_list '(' constant_expression ')'
    1010967        { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
    1011968        ;
     
    1014971        // empty
    1015972                { $$ = 0; }                                                                             // use default argument
    1016         | string_literal
     973        | string_literal_list
    1017974                { $$ = new ExpressionNode( $1 ); }
    1018         | asm_clobbers_list_opt ',' string_literal
     975        | asm_clobbers_list_opt ',' string_literal_list
    1019976                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
    1020977        ;
     
    1022979label_list:
    1023980        no_attr_identifier
    1024                 {
    1025                         $$ = new LabelNode(); $$->labels.push_back( *$1 );
    1026                         delete $1;                                                                      // allocated by lexer
    1027                 }
     981                { $$ = new LabelNode(); $$->labels.push_back( assign_strptr($1) ); }
    1028982        | label_list ',' no_attr_identifier
    1029                 {
    1030                         $$ = $1; $1->labels.push_back( *$3 );
    1031                         delete $3;                                                                      // allocated by lexer
    1032                 }
     983                { $$ = $1; $1->labels.push_back( assign_strptr($3) ); }
    1033984        ;
    1034985
     
    20421993                {
    20431994                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2044                         linkage = LinkageSpec::fromString( *$2 );
     1995                        linkage = LinkageSpec::fromString( assign_strptr($2) );
    20451996                }
    20461997          '{' external_definition_list_opt '}'                          // C++-style linkage specifier
     
    21532104asm_name_opt:                                                                                   // GCC
    21542105        // empty
    2155         | ASM '(' string_literal ')' attribute_list_opt
     2106        | ASM '(' string_literal_list ')' attribute_list_opt
     2107                { delete $3; }
    21562108        ;
    21572109
     
    21832135        | any_word
    21842136        | any_word '(' comma_expression_opt ')'
     2137                { delete $3; }
    21852138        ;
    21862139
Note: See TracChangeset for help on using the changeset viewer.