Changeset 235b41f for src/Parser/ExpressionNode.cc
- Timestamp:
- Sep 5, 2017, 3:41:04 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:
- 416cc86
- Parents:
- 800d275 (diff), 3f8dd01 (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
-
src/Parser/ExpressionNode.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r800d275 r235b41f 7 7 // ExpressionNode.cc -- 8 8 // 9 // Author : Rodolfo G. Esteves9 // Author : Peter A. Buhr 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 : Sun Sep 3 22:21:21 2017 13 // Update Count : 639 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( 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" ) { … … 134 147 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 135 148 CLEANUP: 149 if ( units.length() != 0 ) { 150 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 151 } // if 152 136 153 delete &str; // created by lex 137 154 return ret; 138 155 } // build_constantInteger 139 156 140 Expression * build_constantFloat( const std::string & str ) {157 Expression * build_constantFloat( string & str ) { 141 158 static const BasicType::Kind kind[2][3] = { 142 159 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, 143 160 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, 144 161 }; 162 163 string units; // units 164 sepNumeric( str, units ); // separate constant from units 145 165 146 166 bool complx = false; // real, complex … … 169 189 170 190 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[complx][size] ), str, v ) ); 191 if ( units.length() != 0 ) { 192 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 193 } // if 194 171 195 delete &str; // created by lex 172 196 return ret; 173 197 } // build_constantFloat 174 198 175 Expression * build_constantChar( const std::string & str ) { 199 static void sepString( string & str, string & units, char delimit ) { 200 string::size_type posn = str.find_last_of( delimit ) + 1; 201 if ( posn != str.length() ) { 202 units = "?" + str.substr( posn ); // extract units 203 str.erase( posn ); // remove units 204 } // if 205 } // sepString 206 207 Expression * build_constantChar( string & str ) { 208 string units; // units 209 sepString( str, units, '\'' ); // separate constant from units 210 176 211 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 212 if ( units.length() != 0 ) { 213 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 214 } // if 215 177 216 delete &str; // created by lex 178 217 return ret; 179 218 } // build_constantChar 180 219 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 220 Expression * build_constantStr( string & str ) { 221 string units; // units 222 sepString( str, units, '"' ); // separate constant from units 223 224 BasicType::Kind strtype = BasicType::Char; // default string type 225 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" 226 case 'u': 227 if ( str[1] == '8' ) break; // utf-8 characters 228 strtype = BasicType::ShortUnsignedInt; 229 break; 230 case 'U': 231 strtype = BasicType::UnsignedInt; 232 break; 233 case 'L': 234 strtype = BasicType::SignedInt; 235 break; 236 } // switch 237 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), strtype ), 238 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 239 false, false ); 240 Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 241 if ( units.length() != 0 ) { 242 ret = new UntypedExpr( new NameExpr( units ), { ret } ); 243 } // if 244 187 245 delete &str; // created by lex 188 246 return ret; 189 247 } // build_constantStr 190 248 191 Expression * build_field_name_FLOATINGconstant( const st d::string & str ) {249 Expression * build_field_name_FLOATINGconstant( const string & str ) { 192 250 // str is of the form A.B -> separate at the . and return member expression 193 251 int a, b; 194 252 char dot; 195 st d::stringstream ss( str );253 stringstream ss( str ); 196 254 ss >> a >> dot >> b; 197 255 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) ); … … 207 265 } else { 208 266 return new UntypedMemberExpr( fracts, fieldName ); 209 } 210 } 267 } // if 268 } // if 211 269 return fieldName; 212 270 } // make_field_name_fraction_constants … … 216 274 } // build_field_name_fraction_constants 217 275 218 Expression * build_field_name_REALFRACTIONconstant( const st d::string & str ) {276 Expression * build_field_name_REALFRACTIONconstant( const string & str ) { 219 277 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); 220 Expression * ret = build_constantInteger( *new st d::string( str.substr(1) ) );278 Expression * ret = build_constantInteger( *new string( str.substr(1) ) ); 221 279 delete &str; 222 280 return ret; 223 281 } // build_field_name_REALFRACTIONconstant 224 282 225 Expression * build_field_name_REALDECIMALconstant( const st d::string & str ) {283 Expression * build_field_name_REALDECIMALconstant( const string & str ) { 226 284 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str ); 227 Expression * ret = build_constantInteger( *new st d::string( str.substr( 0, str.size()-1 ) ) );285 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 228 286 delete &str; 229 287 return ret; … … 236 294 } // build_varref 237 295 238 296 // TODO: get rid of this and OperKinds and reuse code from OperatorTable 239 297 static const char * OperName[] = { // must harmonize with OperKinds 240 298 // diadic … … 244 302 "?[?]", "...", 245 303 // monadic 246 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"304 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", 247 305 }; // OperName 248 306 … … 307 365 308 366 Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) { 309 std::list< Expression * > args;367 list< Expression * > args; 310 368 args.push_back( maybeMoveBuild< Expression >(expr_node) ); 311 369 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); … … 313 371 314 372 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) { 315 std::list< Expression * > args;316 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx 373 list< Expression * > args; 374 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code. 317 375 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 318 376 } // build_unary_ptr 319 377 320 378 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 321 std::list< Expression * > args;379 list< Expression * > args; 322 380 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 323 381 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 326 384 327 385 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 328 std::list< Expression * > args;386 list< Expression * > args; 329 387 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 330 388 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); … … 349 407 350 408 Expression * build_tuple( ExpressionNode * expr_node ) { 351 std::list< Expression * > exprs;409 list< Expression * > exprs; 352 410 buildMoveList( expr_node, exprs ); 353 411 return new UntypedTupleExpr( exprs );; … … 355 413 356 414 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 357 std::list< Expression * > args;415 list< Expression * > args; 358 416 buildMoveList( expr_node, args ); 359 417 return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr ); … … 364 422 } // build_range 365 423 366 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr* constraint, ExpressionNode * operand ) {424 Expression * build_asmexpr( ExpressionNode * inout, Expression * constraint, ExpressionNode * operand ) { 367 425 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 368 426 } // build_asmexpr
Note:
See TracChangeset
for help on using the changeset viewer.