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