Changeset b5c5684 for src/ResolvExpr
- Timestamp:
- Jun 10, 2015, 3:37:34 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- bfbf97f
- Parents:
- 8a95629
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r8a95629 rb5c5684 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun Jun 7 21:50:37201513 // Update Count : 2311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 10 15:32:16 2015 13 // Update Count : 45 14 14 // 15 15 … … 272 272 } 273 273 274 template< typename T > 275 bool isCharType( T t ) { 276 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 277 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 278 bt->get_kind() == BasicType::UnsignedChar; 279 } 280 return false; 281 } 282 274 283 void Resolver::visit( SingleInit *singleInit ) { 275 284 if ( singleInit->get_value() ) { … … 296 305 delete castExpr; 297 306 singleInit->set_value( newExpr ); 307 308 // check if initializing type is char[] 309 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 310 if ( isCharType( at->get_base() ) ) { 311 // check if the resolved type is char * 312 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_results().front() ) ) { 313 if ( isCharType( pt->get_base() ) ) { 314 // strip cast if we're initializing a char[] with a char *, e.g. 315 // char x[] = "hello"; 316 CastExpr *ce = dynamic_cast< CastExpr * >( newExpr ); 317 singleInit->set_value( ce->get_arg() ); 318 ce->set_arg( NULL ); 319 delete ce; 320 } 321 } 322 } 323 } 298 324 } // if 299 325 // singleInit->get_value()->accept( *this ); … … 301 327 302 328 void Resolver::visit( ListInit *listInit ) { 303 Visitor::visit(listInit); 329 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 330 std::list< Initializer * >::iterator iter( listInit->begin_initializers() ); 331 for ( ; iter != listInit->end_initializers(); ++iter ) { 332 initContext = at->get_base(); 333 (*iter)->accept( *this ); 334 } // for 335 } else if ( UnionInstType *st = dynamic_cast< UnionInstType * >( initContext ) ) { 336 DeclarationWithType *dt = dynamic_cast< DeclarationWithType * >( *st->get_baseUnion()->get_members().begin() ); 337 initContext = dt->get_type(); 338 (*listInit->begin_initializers())->accept( *this ); 339 } else { 340 // basic types are handled here 341 Visitor::visit( listInit ); 342 } 343 304 344 #if 0 305 345 if ( ArrayType *at = dynamic_cast<ArrayType*>(initContext) ) {
Note: See TracChangeset
for help on using the changeset viewer.