Changeset 930f69e
- Timestamp:
- Sep 10, 2017, 5:35:59 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- de9285f
- Parents:
- 0cc818b
- Location:
- src
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r0cc818b r930f69e 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 22:21:21201713 // Update Count : 6 3912 // Last Modified On : Sun Sep 10 09:56:06 2017 13 // Update Count : 655 14 14 // 15 15 … … 51 51 extern const Type::Qualifiers noQualifiers; // no qualifiers on constants 52 52 53 static inline bool checkH( char c ) { return c == 'h' || c == 'H'; } 54 static inline bool checkL( char c ) { return c == 'l' || c == 'L'; } 55 static inline bool checkZ( char c ) { return c == 'z' || c == 'Z'; } 53 56 static inline bool checkU( char c ) { return c == 'u' || c == 'U'; } 54 static inline bool checkL( char c ) { return c == 'l' || c == 'L'; }55 57 static inline bool checkF( char c ) { return c == 'f' || c == 'F'; } 56 58 static inline bool checkD( char c ) { return c == 'd' || c == 'D'; } … … 67 69 68 70 Expression * build_constantInteger( string & str ) { 69 static const BasicType::Kind kind[2][3] = { 70 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 71 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 71 static const BasicType::Kind kind[2][5] = { 72 // short (h) must be before char (hh) 73 { BasicType::ShortSignedInt, BasicType::SignedChar, BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 74 { BasicType::ShortUnsignedInt, BasicType::UnsignedChar, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 72 75 }; 73 76 … … 81 84 Expression * ret; 82 85 83 // ROB: what do we do with units on 0 and 1?84 86 // special constants 85 87 if ( str == "0" ) { … … 107 109 108 110 if ( v <= INT_MAX ) { // signed int 109 size = 0;111 size = 2; 110 112 } else if ( v <= UINT_MAX && ! dec ) { // unsigned int 111 size = 0;113 size = 2; 112 114 Unsigned = true; // unsigned 113 115 } else if ( v <= LONG_MAX ) { // signed long int 114 size = 1;116 size = 3; 115 117 } else if ( v <= ULONG_MAX && ( ! dec || LONG_MAX == LLONG_MAX ) ) { // signed long int 116 size = 1;118 size = 3; 117 119 Unsigned = true; // unsigned long int 118 120 } else if ( v <= LLONG_MAX ) { // signed long long int 119 size = 2;121 size = 4; 120 122 } else { // unsigned long long int 121 size = 2;123 size = 4; 122 124 Unsigned = true; // unsigned long long int 123 125 } // if 126 127 // At least one digit in integer constant, so safe to backup while looking for suffix. 124 128 125 129 if ( checkU( str[last] ) ) { // suffix 'u' ? 126 130 Unsigned = true; 127 if ( last > 0 && checkL( str[last - 1] ) ) {// suffix 'l' ?128 size = 1;129 if ( last > 1 && checkL( str[last - 2] ) ) { // suffix 'll'?130 size = 2;131 if ( checkL( str[last - 1] ) ) { // suffix 'l' ? 132 size = 3; 133 if ( checkL( str[last - 2] ) ) { // suffix "ll" ? 134 size = 4; 131 135 } // if 136 } else if ( checkH( str[last - 1] ) ) { // suffix 'h' ? 137 size = 0; 138 if ( checkH( str[last - 2] ) ) { // suffix "hh" ? 139 size = 1; 140 } // if 141 str.erase( last - size - 1, size + 1 ); // remove 'h'/"hh" 132 142 } // if 133 143 } else if ( checkL( str[ last ] ) ) { // suffix 'l' ? 134 size = 1;135 if ( last > 0 && checkL( str[last - 1] ) ) {// suffix 'll' ?136 size = 2;137 if ( last > 1 && checkU( str[last - 2] ) ) {// suffix 'u' ?144 size = 3; 145 if ( checkL( str[last - 1] ) ) { // suffix 'll' ? 146 size = 4; 147 if ( checkU( str[last - 2] ) ) { // suffix 'u' ? 138 148 Unsigned = true; 139 149 } // if 140 } else { 141 if ( last > 0 && checkU( str[last - 1] ) ) { // suffix 'u' ? 150 } else if ( checkU( str[last - 1] ) ) { // suffix 'u' ? 151 Unsigned = true; 152 } // if 153 } else if ( checkH( str[ last ] ) ) { // suffix 'h' ? 154 size = 0; 155 if ( checkH( str[last - 1] ) ) { // suffix "hh" ? 156 size = 1; 157 if ( checkU( str[last - 2] ) ) { // suffix 'u' ? 142 158 Unsigned = true; 143 159 } // if 144 } // if 160 } else if ( checkU( str[last - 1] ) ) { // suffix 'u' ? 161 Unsigned = true; 162 } // if 163 str.erase( last - size, size + 1 ); // remove 'h'/"hh" 164 } else if ( checkZ( str[last] ) ) { // suffix 'z' ? 165 str.erase( last, 1 ); // remove 'z' 145 166 } // if 146 167 … … 247 268 } // build_constantStr 248 269 270 Expression * build_field_name_FLOATING_FRACTIONconstant( const string & str ) { 271 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); 272 Expression * ret = build_constantInteger( *new string( str.substr(1) ) ); 273 delete &str; 274 return ret; 275 } // build_field_name_FLOATING_FRACTIONconstant 276 277 Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) { 278 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str ); 279 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 280 delete &str; 281 return ret; 282 } // build_field_name_FLOATING_DECIMALconstant 283 249 284 Expression * build_field_name_FLOATINGconstant( const string & str ) { 250 285 // str is of the form A.B -> separate at the . and return member expression … … 273 308 return make_field_name_fraction_constants( fieldName, maybeMoveBuild< Expression >( fracts ) ); 274 309 } // build_field_name_fraction_constants 275 276 Expression * build_field_name_REALFRACTIONconstant( const string & str ) {277 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );278 Expression * ret = build_constantInteger( *new string( str.substr(1) ) );279 delete &str;280 return ret;281 } // build_field_name_REALFRACTIONconstant282 283 Expression * build_field_name_REALDECIMALconstant( const string & str ) {284 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str );285 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) );286 delete &str;287 return ret;288 } // build_field_name_REALDECIMALconstant289 310 290 311 NameExpr * build_varref( const string * name ) { -
src/Parser/ParseNode.h
r0cc818b r930f69e 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 19:24:34201713 // Update Count : 79912 // Last Modified On : Sun Sep 10 09:56:32 2017 13 // Update Count : 801 14 14 // 15 15 … … 166 166 Expression * build_constantChar( std::string &str ); 167 167 Expression * build_constantStr( std::string &str ); 168 Expression * build_field_name_FLOATING_FRACTIONconstant( const std::string & str ); 169 Expression * build_field_name_FLOATING_DECIMALconstant( const std::string & str ); 168 170 Expression * build_field_name_FLOATINGconstant( const std::string & str ); 169 171 Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ); 170 Expression * build_field_name_REALFRACTIONconstant( const std::string & str );171 Expression * build_field_name_REALDECIMALconstant( const std::string & str );172 172 173 173 NameExpr * build_varref( const std::string * name ); -
src/Parser/lex.ll
r0cc818b r930f69e 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Thu Aug 31 21:30:10201713 * Update Count : 59812 * Last Modified On : Sun Sep 10 11:15:37 2017 13 * Update Count : 617 14 14 */ 15 15 … … 93 93 // numeric constants, CFA: '_' in constant 94 94 hex_quad {hex}("_"?{hex}){3} 95 integer_suffix_opt ("_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?))))? 95 length ("ll"|"LL"|[lL])|("hh"|"HH"|[hH]) 96 integer_suffix_opt ("_"?(([uU]({length}?[iI]?)|([iI]{length}))|([iI]({length}?[uU]?)|([uU]{length}))|({length}([iI]?[uU]?)|([uU][iI]))|[zZ]))?{user_suffix_opt} 96 97 97 98 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) 98 99 octal_prefix "0""_"? 99 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt} {user_suffix_opt}100 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt} 100 101 101 102 nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal}) 102 decimal_constant {nonzero_digits}{integer_suffix_opt} {user_suffix_opt}103 decimal_constant {nonzero_digits}{integer_suffix_opt} 103 104 104 105 hex_digits ({hex})|({hex}({hex}|"_")*{hex}) 105 106 hex_prefix "0"[xX]"_"? 106 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt} {user_suffix_opt}107 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt} 107 108 108 109 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 109 floating_suffix_opt ("_"?( [fFdDlL][iI]?|[iI][lLfFdD]?|"DL"))?110 floating_suffix_opt ("_"?(([fFdDlL]?[iI]?)|([iI][lLfFdD])|"DL"))?{user_suffix_opt} 110 111 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 111 real_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}{user_suffix_opt}112 real_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt}{user_suffix_opt}113 real_constant {decimal_digits}{real_fraction}114 112 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 115 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt} 113 floating_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt} 114 floating_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt} 115 floating_constant ({decimal_digits}{exponent}{floating_suffix_opt})|({decimal_digits}{floating_fraction}) 116 116 117 117 binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits} 118 hex_f ractional_constant({hex_digits}?"."{hex_digits})|({hex_digits}".")119 hex_floating_constant {hex_prefix}(({hex_f ractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix_opt}118 hex_floating_fraction ({hex_digits}?"."{hex_digits})|({hex_digits}".") 119 hex_floating_constant {hex_prefix}(({hex_floating_fraction}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix_opt} 120 120 121 121 // character escape sequence, GCC: \e => esc character 122 122 simple_escape "\\"[abefnrtv'"?\\] 123 // ' stop highlighting123 // ' stop editor highlighting 124 124 octal_escape "\\"{octal}("_"?{octal}){0,2} 125 125 hex_escape "\\""x""_"?{hex_digits} … … 154 154 /* line directives */ 155 155 ^{h_white}*"#"{h_white}*[0-9]+{h_white}*["][^"\n]+["].*"\n" { 156 /* " stop highlighting */156 /* " stop editor highlighting */ 157 157 static char filename[FILENAME_MAX]; // temporarily store current source-file name 158 158 char *end_num; … … 310 310 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); } 311 311 {hex_constant} { NUMERIC_RETURN(INTEGERconstant); } 312 { real_decimal} { NUMERIC_RETURN(REALDECIMALconstant); } // must appear before floating_constant313 { real_fraction} { NUMERIC_RETURN(REALFRACTIONconstant); } // must appear before floating_constant312 {floating_decimal} { NUMERIC_RETURN(FLOATING_DECIMALconstant); } // must appear before floating_constant 313 {floating_fraction} { NUMERIC_RETURN(FLOATING_FRACTIONconstant); } // must appear before floating_constant 314 314 {floating_constant} { NUMERIC_RETURN(FLOATINGconstant); } 315 315 {hex_floating_constant} { NUMERIC_RETURN(FLOATINGconstant); } … … 319 319 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); } 320 320 <QUOTE>['\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); } 321 /* ' stop highlighting */321 /* ' stop editor highlighting */ 322 322 323 323 /* string constant */ … … 325 325 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); } 326 326 <STRING>["\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); } 327 /* " stop highlighting */327 /* " stop editor highlighting */ 328 328 329 329 /* common character/string constant */ -
src/Parser/parser.yy
r0cc818b r930f69e 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 20:43:19201713 // Update Count : 27 4212 // Last Modified On : Sun Sep 10 10:07:10 2017 13 // Update Count : 2752 14 14 // 15 15 … … 146 146 // overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically 147 147 // converted into the tuple index (.)(1). e.g., 3.x 148 %token<tok> REALDECIMALconstant REALFRACTIONconstant FLOATINGconstant148 %token<tok> FLOATING_DECIMALconstant FLOATING_FRACTIONconstant FLOATINGconstant 149 149 150 150 // multi-character operators … … 315 315 %precedence ELSE // token precedence for start of else clause in IF/WAITFOR statement 316 316 317 317 318 %start translation_unit // parse-tree root 318 319 … … 321 322 322 323 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols 323 // "identifier" and "TYPEDEFname" that are lexically identical. While it is possible to write a purely context-free324 // grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. Hence, this325 // grammar uses the ANSI style.324 // "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical. While it is possible to write a purely 325 // context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. 326 // Hence, this grammar uses the ANSI style. 326 327 // 327 328 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those … … 360 361 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 361 362 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); } 362 | REALDECIMALconstant{ $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }363 | REALFRACTIONconstant{ $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }363 | FLOATING_DECIMALconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 364 | FLOATING_FRACTIONconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 364 365 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 365 366 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); } … … 434 435 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 435 436 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); } 436 | postfix_expression REALFRACTIONconstant// CFA, tuple index437 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_ REALFRACTIONconstant( *$2 ) ) ); }437 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 438 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 438 439 | postfix_expression ARROW no_attr_identifier 439 440 { … … 479 480 field: // CFA, tuple field selector 480 481 field_name 481 | REALDECIMALconstant field482 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_ REALDECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }483 | REALDECIMALconstant '[' push field_list pop ']'484 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_ REALDECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }482 | FLOATING_DECIMALconstant field 483 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); } 484 | FLOATING_DECIMALconstant '[' push field_list pop ']' 485 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); } 485 486 | field_name '.' field 486 487 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } … … 507 508 // empty 508 509 { $$ = nullptr; } 509 | fraction_constants REALFRACTIONconstant510 { 511 Expression * constant = build_field_name_ REALFRACTIONconstant( *$2 );510 | fraction_constants FLOATING_FRACTIONconstant 511 { 512 Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 ); 512 513 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1, constant ) ) : new ExpressionNode( constant ); 513 514 }
Note: See TracChangeset
for help on using the changeset viewer.