Changes in src/Parser/parser.yy [ab57786:8d2844a]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rab57786 r8d2844a 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 22 14:15:15201613 // Update Count : 19 4312 // Last Modified On : Thu Aug 18 23:49:10 2016 13 // Update Count : 1909 14 14 // 15 15 … … 55 55 #include "LinkageSpec.h" 56 56 57 union DeclQualifiers {58 unsigned int value; // assume 32-bits59 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 }; // DeclQualifiers76 DeclQualifiers declQualifiers = { 0 };77 78 union DeclType {79 unsigned int value; // assume 32-bits80 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 }; // DeclType96 DeclType declTypes = { 0 };97 98 57 extern DeclarationNode * parseTree; 99 58 extern LinkageSpec::Spec linkage; … … 102 61 std::stack< LinkageSpec::Spec > linkageStack; 103 62 104 void appendStr( std::string *to, std::string *from ) {63 void appendStr( std::string &to, std::string *from ) { 105 64 // "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 ) ); 107 66 } // appendStr 108 67 %} … … 167 126 InitializerNode *in; 168 127 OperKinds op; 169 std::string *str;170 128 bool flag; 171 129 } … … 173 131 %type<tok> identifier no_01_identifier no_attr_identifier zero_one 174 132 %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 177 134 178 135 // expressions … … 339 296 340 297 push: 341 { typedefTable.enterScope(); } 298 { 299 typedefTable.enterScope(); 300 } 342 301 ; 343 302 344 303 pop: 345 { typedefTable.leaveScope(); } 304 { 305 typedefTable.leaveScope(); 306 } 346 307 ; 347 308 … … 350 311 constant: 351 312 // 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) ) ); } 355 316 ; 356 317 … … 376 337 ; 377 338 378 string_literal:379 string_literal_list { $$ = build_constantStr( *$1 ); }380 ;381 382 339 string_literal_list: // juxtaposed strings are concatenated 383 STRINGliteral { $$ = $1; } // conversion from tok to str340 STRINGliteral { $$ = build_constantStr( assign_strptr($1) ); } 384 341 | string_literal_list STRINGliteral 385 342 { 386 appendStr( $1 , $2 ); // append 2nd juxtaposed string to 1st343 appendStr( $1->get_constant()->get_value(), $2 ); 387 344 delete $2; // allocated by lexer 388 $$ = $1; // conversion from tok to str345 $$ = $1; 389 346 } 390 347 ; … … 413 370 | postfix_expression '(' argument_expression_list ')' 414 371 { $$ = 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. 416 373 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 417 374 | postfix_expression '.' no_attr_identifier … … 455 412 no_attr_identifier 456 413 { $$ = 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. 458 415 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 459 416 | no_attr_identifier '.' field … … 473 430 | constant 474 431 { $$ = $1; } 475 | string_literal 432 | string_literal_list 476 433 { $$ = new ExpressionNode( $1 ); } 477 434 | EXTENSION cast_expression // GCC … … 852 809 fall_through_opt: // CFA 853 810 // empty 854 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break811 { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } // insert implicit break 855 812 | fall_through 856 813 ; … … 881 838 jump_statement: 882 839 GOTO IDENTIFIER ';' 883 { $$ = new StatementNode( build_branch( $2, BranchStmt::Goto ) ); }840 { $$ = new StatementNode( build_branch( assign_strptr($2), BranchStmt::Goto ) ); } 884 841 | GOTO '*' comma_expression ';' // GCC, computed goto 885 842 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3); … … 888 845 | CONTINUE ';' 889 846 // 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 ) ); } 891 848 | CONTINUE IDENTIFIER ';' // CFA, multi-level continue 892 849 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 893 850 // 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 ) ); } 895 852 | BREAK ';' 896 853 // 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 ) ); } 898 855 | BREAK IDENTIFIER ';' // CFA, multi-level exit 899 856 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 900 857 // 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 ) ); } 902 859 | RETURN comma_expression_opt ';' 903 860 { $$ = new StatementNode( build_return( $2 ) ); } … … 973 930 974 931 asm_statement: 975 ASM asm_volatile_opt '(' string_literal ')' ';'932 ASM asm_volatile_opt '(' string_literal_list ')' ';' 976 933 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); } 977 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC934 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC 978 935 { $$ = 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 ')' ';' 980 937 { $$ = 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 ')' ';' 982 939 { $$ = 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 ')' ';' 984 941 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); } 985 942 ; … … 1005 962 1006 963 asm_operand: // GCC 1007 string_literal '(' constant_expression ')'964 string_literal_list '(' constant_expression ')' 1008 965 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); } 1009 | '[' constant_expression ']' string_literal '(' constant_expression ')'966 | '[' constant_expression ']' string_literal_list '(' constant_expression ')' 1010 967 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); } 1011 968 ; … … 1014 971 // empty 1015 972 { $$ = 0; } // use default argument 1016 | string_literal 973 | string_literal_list 1017 974 { $$ = new ExpressionNode( $1 ); } 1018 | asm_clobbers_list_opt ',' string_literal 975 | asm_clobbers_list_opt ',' string_literal_list 1019 976 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 1020 977 ; … … 1022 979 label_list: 1023 980 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) ); } 1028 982 | 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) ); } 1033 984 ; 1034 985 … … 2042 1993 { 2043 1994 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2044 linkage = LinkageSpec::fromString( *$2);1995 linkage = LinkageSpec::fromString( assign_strptr($2) ); 2045 1996 } 2046 1997 '{' external_definition_list_opt '}' // C++-style linkage specifier … … 2153 2104 asm_name_opt: // GCC 2154 2105 // empty 2155 | ASM '(' string_literal ')' attribute_list_opt 2106 | ASM '(' string_literal_list ')' attribute_list_opt 2107 { delete $3; } 2156 2108 ; 2157 2109 … … 2183 2135 | any_word 2184 2136 | any_word '(' comma_expression_opt ')' 2137 { delete $3; } 2185 2138 ; 2186 2139
Note:
See TracChangeset
for help on using the changeset viewer.