Changeset 51c6353
- Timestamp:
- Sep 1, 2017, 2:42:47 PM (7 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:
- 681c764
- Parents:
- a984e65 (diff), 76c62b2 (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. - Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
ra984e65 r51c6353 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:17:07 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Aug 2 11:12:00201713 // Update Count : 56811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 31 21:05:04 2017 13 // Update Count : 605 14 14 // 15 15 … … 58 58 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 59 59 60 Expression * build_constantInteger( const std::string & str ) { 60 static void sepNumeric( string & str, string & units ) { 61 string::size_type posn = str.find_first_of( "`" ); 62 if ( posn != string::npos ) { 63 units = str.substr( posn ); // extract units 64 str.erase( posn ); // remove units 65 } // if 66 } // sepNumeric 67 68 Expression * build_constantInteger( std::string & str ) { 61 69 static const BasicType::Kind kind[2][3] = { 62 70 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, 63 71 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 64 72 }; 73 74 string units; // units 75 sepNumeric( str, units ); // separate constant from units 76 65 77 bool dec = true, Unsigned = false; // decimal, unsigned constant 66 78 int size; // 0 => int, 1 => long, 2 => long long … … 69 81 Expression * ret; 70 82 83 // ROB: what do we do with units on 0 and 1? 71 84 // special constants 72 85 if ( str == "0" ) { … … 132 145 } // if 133 146 134 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 147 // if ( units.length() == 0 ) { 148 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 149 // } else { 150 // // ROB: generate call to units routine 151 // ret = nullptr; 152 // } // if 135 153 CLEANUP: 136 154 delete &str; // created by lex … … 138 156 } // build_constantInteger 139 157 140 Expression * build_constantFloat( conststd::string & str ) {158 Expression * build_constantFloat( std::string & str ) { 141 159 static const BasicType::Kind kind[2][3] = { 142 160 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, 143 161 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, 144 162 }; 163 164 string units; // units 165 sepNumeric( str, units ); // separate constant from units 145 166 146 167 bool complx = false; // real, complex … … 168 189 } // if 169 190 170 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 191 Expression * ret; 192 // if ( units.length() == 0 ) { 193 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 194 // } else { 195 // ret = nullptr; 196 // // ROB: generate call to units routine 197 // } // if 198 171 199 delete &str; // created by lex 172 200 return ret; 173 201 } // build_constantFloat 174 202 175 Expression * build_constantChar( const std::string & str ) { 176 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 203 static void sepString( string & str, string & units, char delimit ) { 204 string::size_type posn = str.find_last_of( delimit ) + 1; 205 if ( posn != str.length() ) { 206 units = str.substr( posn ); // extract units 207 str.erase( posn ); // remove units 208 } // if 209 } // sepString 210 211 Expression * build_constantChar( std::string & str ) { 212 string units; // units 213 sepString( str, units, '\'' ); // separate constant from units 214 215 Expression * ret; 216 // if ( units.length() == 0 ) { 217 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 218 // } else { 219 // ret = nullptr; 220 // // ROB: generate call to units routine 221 // } // if 222 177 223 delete &str; // created by lex 178 224 return ret; 179 225 } // build_constantChar 180 226 181 ConstantExpr * build_constantStr( const std::string & str ) { 182 // string should probably be a primitive type 183 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 184 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 185 false, false ); 186 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 227 ConstantExpr * build_constantStr( std::string & str ) { 228 string units; // units 229 sepString( str, units, '"' ); // separate constant from units 230 231 ConstantExpr * ret; 232 // if ( units.length() == 0 ) { 233 // string should probably be a primitive type 234 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 235 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 236 false, false ); 237 ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 238 // } else { 239 // ret = nullptr; 240 // // ROB: generate call to units routine 241 // } // if 242 187 243 delete &str; // created by lex 188 244 return ret; -
src/Parser/ParseNode.h
ra984e65 r51c6353 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Th r Aug 17 13:46:00201713 // Update Count : 79 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 31 17:42:49 2017 13 // Update Count : 797 14 14 // 15 15 … … 162 162 }; 163 163 164 Expression * build_constantInteger( conststd::string &str );165 Expression * build_constantFloat( conststd::string &str );166 Expression * build_constantChar( conststd::string &str );167 ConstantExpr * build_constantStr( conststd::string &str );164 Expression * build_constantInteger( std::string &str ); 165 Expression * build_constantFloat( std::string &str ); 166 Expression * build_constantChar( std::string &str ); 167 ConstantExpr * build_constantStr( std::string &str ); 168 168 Expression * build_field_name_FLOATINGconstant( const std::string & str ); 169 169 Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ); -
src/Parser/lex.ll
ra984e65 r51c6353 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Wed Aug 30 17:35:21201713 * Update Count : 5 8412 * Last Modified On : Thu Aug 31 21:30:10 2017 13 * Update Count : 598 14 14 */ 15 15 … … 57 57 yyleng = 0; 58 58 for ( int i = 0; yytext[i] != '\0'; i += 1 ) { 59 if ( yytext[i] == '`' ) { 60 // copy user suffix 61 for ( ; yytext[i] != '\0'; i += 1 ) { 62 yytext[yyleng] = yytext[i]; 63 yyleng += 1; 64 } // for 65 break; 66 } // if 59 67 if ( yytext[i] != '_' ) { 60 68 yytext[yyleng] = yytext[i]; … … 81 89 attr_identifier "@"{identifier} 82 90 91 user_suffix_opt ("`"{identifier})? 92 83 93 // numeric constants, CFA: '_' in constant 84 94 hex_quad {hex}("_"?{hex}){3} 85 integer_suffix "_"?(([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 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]?))))? 86 96 87 97 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) 88 98 octal_prefix "0""_"? 89 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix }?99 octal_constant (("0")|({octal_prefix}{octal_digits})){integer_suffix_opt}{user_suffix_opt} 90 100 91 101 nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal}) 92 decimal_constant {nonzero_digits}{integer_suffix }?102 decimal_constant {nonzero_digits}{integer_suffix_opt}{user_suffix_opt} 93 103 94 104 hex_digits ({hex})|({hex}({hex}|"_")*{hex}) 95 105 hex_prefix "0"[xX]"_"? 96 hex_constant {hex_prefix}{hex_digits}{integer_suffix}? 97 106 hex_constant {hex_prefix}{hex_digits}{integer_suffix_opt}{user_suffix_opt} 107 108 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 109 floating_suffix_opt ("_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL"))? 98 110 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 99 real_decimal {decimal_digits}"."{exponent}?{floating_suffix }?100 real_fraction "."{decimal_digits}{exponent}?{floating_suffix }?111 real_decimal {decimal_digits}"."{exponent}?{floating_suffix_opt}{user_suffix_opt} 112 real_fraction "."{decimal_digits}{exponent}?{floating_suffix_opt}{user_suffix_opt} 101 113 real_constant {decimal_digits}{real_fraction} 102 114 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 103 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 104 floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL") 105 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}? 115 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix_opt}{user_suffix_opt} 106 116 107 117 binary_exponent "_"?[pP]"_"?[+-]?{decimal_digits} 108 118 hex_fractional_constant ({hex_digits}?"."{hex_digits})|({hex_digits}".") 109 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix }?119 hex_floating_constant {hex_prefix}(({hex_fractional_constant}{binary_exponent})|({hex_digits}{binary_exponent})){floating_suffix_opt} 110 120 111 121 // character escape sequence, GCC: \e => esc character … … 308 318 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); } 309 319 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); } 310 <QUOTE>['\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); }320 <QUOTE>['\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); } 311 321 /* ' stop highlighting */ 312 322 … … 314 324 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); } 315 325 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); } 316 <STRING>["\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); }326 <STRING>["\n]{user_suffix_opt} { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); } 317 327 /* " stop highlighting */ 318 328 … … 387 397 {op_unary}"?" { IDENTIFIER_RETURN(); } // unary 388 398 "?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); } 389 "^?{}" { IDENTIFIER_RETURN(); } 399 "^?{}" { IDENTIFIER_RETURN(); } 400 "?`"{identifier} { IDENTIFIER_RETURN(); } // unit operator 390 401 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 391 402 /*
Note: See TracChangeset
for help on using the changeset viewer.