Ignore:
Timestamp:
Aug 22, 2016, 3:31:54 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
dadc1b5, f87408e
Parents:
03b812d2 (diff), 2acf5fc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r03b812d2 rbd9f8be  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 18 23:49:10 2016
    13 // Update Count     : 1909
     12// Last Modified On : Mon Aug 22 14:30:56 2016
     13// Update Count     : 1944
    1414//
    1515
     
    5555#include "LinkageSpec.h"
    5656
     57union 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
     76DeclQualifiers declQualifiers = { 0 };
     77
     78union 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
     96DeclType declTypes = { 0 };
     97
    5798extern DeclarationNode * parseTree;
    5899extern LinkageSpec::Spec linkage;
     
    61102std::stack< LinkageSpec::Spec > linkageStack;
    62103
    63 void appendStr( std::string &to, std::string *from ) {
     104void appendStr( std::string *to, std::string *from ) {
    64105        // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    65         to.insert( to.length() - 1, from->substr( 1, from->length() - 2 ) );
     106        to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
    66107} // appendStr
    67108%}
     
    126167        InitializerNode *in;
    127168        OperKinds op;
     169        std::string *str;
    128170        bool flag;
    129171}
     
    131173%type<tok> identifier  no_01_identifier  no_attr_identifier zero_one
    132174%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  no_01_identifier_or_type_name
    133 %type<constant> string_literal_list
     175%type<constant> string_literal
     176%type<str> string_literal_list
    134177
    135178// expressions
     
    296339
    297340push:
    298                 {
    299                         typedefTable.enterScope();
    300                 }
     341                { typedefTable.enterScope(); }
    301342        ;
    302343
    303344pop:
    304                 {
    305                         typedefTable.leaveScope();
    306                 }
     345                { typedefTable.leaveScope(); }
    307346        ;
    308347
     
    311350constant:
    312351                // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant".
    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) ) ); }
     352        INTEGERconstant                                                         { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }
     353        | FLOATINGconstant                                                      { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }
     354        | CHARACTERconstant                                                     { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }
    316355        ;
    317356
     
    337376        ;
    338377
     378string_literal:
     379        string_literal_list                                                     { $$ = build_constantStr( *$1 ); }
     380        ;
     381
    339382string_literal_list:                                                                    // juxtaposed strings are concatenated
    340         STRINGliteral                                                           { $$ = build_constantStr( assign_strptr($1) ); }
     383        STRINGliteral                                                           { $$ = $1; } // conversion from tok to str
    341384        | string_literal_list STRINGliteral
    342385                {
    343                         appendStr( $1->get_constant()->get_value(), $2 );
     386                        appendStr( $1, $2 );                                            // append 2nd juxtaposed string to 1st
    344387                        delete $2;                                                                      // allocated by lexer
    345                         $$ = $1;
     388                        $$ = $1;                                                                        // conversion from tok to str
    346389                }
    347390        ;
     
    370413        | postfix_expression '(' argument_expression_list ')'
    371414                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    372         // ambiguity with .0 so space required after field-selection, e.g.
     415                // ambiguity with .0 so space required after field-selection, e.g.
    373416                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    374417        | postfix_expression '.' no_attr_identifier
     
    412455        no_attr_identifier
    413456                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    414         // ambiguity with .0 so space required after field-selection, e.g.
     457                // ambiguity with .0 so space required after field-selection, e.g.
    415458                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
    416459        | no_attr_identifier '.' field
     
    430473        | constant
    431474                { $$ = $1; }
    432         | string_literal_list
     475        | string_literal
    433476                { $$ = new ExpressionNode( $1 ); }
    434477        | EXTENSION cast_expression                                                     // GCC
     
    809852fall_through_opt:                                                                               // CFA
    810853        // empty
    811                 { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } // insert implicit break
     854                { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
    812855        | fall_through
    813856        ;
     
    838881jump_statement:
    839882        GOTO IDENTIFIER ';'
    840                 { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Goto ) ); }
     883                { $$ = new StatementNode( build_branch( $2, BranchStmt::Goto ) ); }
    841884        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
    842885                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
     
    845888        | CONTINUE ';'
    846889                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    847                 { $$ = new StatementNode( build_branch( "", BranchStmt::Continue ) ); }
     890                { $$ = new StatementNode( build_branch( BranchStmt::Continue ) ); }
    848891        | CONTINUE IDENTIFIER ';'                                                       // CFA, multi-level continue
    849892                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    850893                // the target of the transfer appears only at the start of an iteration statement.
    851                 { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Continue ) ); }
     894                { $$ = new StatementNode( build_branch( $2, BranchStmt::Continue ) ); }
    852895        | BREAK ';'
    853896                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    854                 { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); }
     897                { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); }
    855898        | BREAK IDENTIFIER ';'                                                          // CFA, multi-level exit
    856899                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    857900                // the target of the transfer appears only at the start of an iteration statement.
    858                 { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Break ) ); }
     901                { $$ = new StatementNode( build_branch( $2, BranchStmt::Break ) ); }
    859902        | RETURN comma_expression_opt ';'
    860903                { $$ = new StatementNode( build_return( $2 ) ); }
     
    930973
    931974asm_statement:
    932         ASM asm_volatile_opt '(' string_literal_list ')' ';'
     975        ASM asm_volatile_opt '(' string_literal ')' ';'
    933976                { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
    934         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC
     977        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC
    935978                { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
    936         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';'
     979        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    937980                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
    938         | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
     981        | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    939982                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
    940         | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
     983        | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    941984                { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
    942985        ;
     
    9621005
    9631006asm_operand:                                                                                    // GCC
    964         string_literal_list '(' constant_expression ')'
     1007        string_literal '(' constant_expression ')'
    9651008                { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
    966         | '[' constant_expression ']' string_literal_list '(' constant_expression ')'
     1009        | '[' constant_expression ']' string_literal '(' constant_expression ')'
    9671010        { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
    9681011        ;
     
    9711014        // empty
    9721015                { $$ = 0; }                                                                             // use default argument
    973         | string_literal_list
     1016        | string_literal
    9741017                { $$ = new ExpressionNode( $1 ); }
    975         | asm_clobbers_list_opt ',' string_literal_list
     1018        | asm_clobbers_list_opt ',' string_literal
    9761019                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
    9771020        ;
     
    9791022label_list:
    9801023        no_attr_identifier
    981                 { $$ = new LabelNode(); $$->labels.push_back( assign_strptr($1) ); }
     1024                {
     1025                        $$ = new LabelNode(); $$->labels.push_back( *$1 );
     1026                        delete $1;                                                                      // allocated by lexer
     1027                }
    9821028        | label_list ',' no_attr_identifier
    983                 { $$ = $1; $1->labels.push_back( assign_strptr($3) ); }
     1029                {
     1030                        $$ = $1; $1->labels.push_back( *$3 );
     1031                        delete $3;                                                                      // allocated by lexer
     1032                }
    9841033        ;
    9851034
     
    19932042                {
    19942043                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    1995                         linkage = LinkageSpec::fromString( assign_strptr($2) );
     2044                        linkage = LinkageSpec::fromString( *$2 );
    19962045                }
    19972046          '{' external_definition_list_opt '}'                          // C++-style linkage specifier
Note: See TracChangeset for help on using the changeset viewer.