Changes in src/ResolvExpr/Resolver.cc [5f2f2d7:bfbf97f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r5f2f2d7 rbfbf97f 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 16:11:19 2015 13 // Update Count : 77 14 14 // 15 15 … … 37 37 virtual void visit( ObjectDecl *functionDecl ); 38 38 virtual void visit( TypeDecl *typeDecl ); 39 virtual void visit( ArrayType * at ); 39 40 40 41 virtual void visit( ExprStmt *exprStmt ); … … 157 158 initContext = new_type; 158 159 SymTab::Indexer::visit( objectDecl ); 159 160 if ( ArrayType * at = dynamic_cast< ArrayType * >( new_type ) ){ 161 if ( at->get_dimension() ) { 162 BasicType arrayLenType = BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 163 CastExpr *castExpr = new CastExpr( at->get_dimension(), arrayLenType.clone() ); 164 Expression *newExpr = findSingleExpression( castExpr, *this ); 165 delete at->get_dimension(); 166 at->set_dimension( newExpr ); 167 } 168 } 160 } 161 162 void Resolver::visit( ArrayType * at ) { 163 if ( at->get_dimension() ) { 164 BasicType arrayLenType = BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 165 CastExpr *castExpr = new CastExpr( at->get_dimension(), arrayLenType.clone() ); 166 Expression *newExpr = findSingleExpression( castExpr, *this ); 167 delete at->get_dimension(); 168 at->set_dimension( newExpr ); 169 170 } 171 Visitor::visit( at ); 169 172 } 170 173 … … 270 273 returnStmt->set_expr( newExpr ); 271 274 } // if 275 } 276 277 template< typename T > 278 bool isCharType( T t ) { 279 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 280 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 281 bt->get_kind() == BasicType::UnsignedChar; 282 } 283 return false; 272 284 } 273 285 … … 296 308 delete castExpr; 297 309 singleInit->set_value( newExpr ); 310 311 // check if initializing type is char[] 312 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 313 if ( isCharType( at->get_base() ) ) { 314 // check if the resolved type is char * 315 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_results().front() ) ) { 316 if ( isCharType( pt->get_base() ) ) { 317 // strip cast if we're initializing a char[] with a char *, e.g. 318 // char x[] = "hello"; 319 CastExpr *ce = dynamic_cast< CastExpr * >( newExpr ); 320 singleInit->set_value( ce->get_arg() ); 321 ce->set_arg( NULL ); 322 delete ce; 323 } 324 } 325 } 326 } 298 327 } // if 299 328 // singleInit->get_value()->accept( *this ); … … 301 330 302 331 void Resolver::visit( ListInit *listInit ) { 303 Visitor::visit(listInit); 332 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 333 std::list< Initializer * >::iterator iter( listInit->begin_initializers() ); 334 for ( ; iter != listInit->end_initializers(); ++iter ) { 335 initContext = at->get_base(); 336 (*iter)->accept( *this ); 337 } // for 338 } else if ( UnionInstType *st = dynamic_cast< UnionInstType * >( initContext ) ) { 339 DeclarationWithType *dt = dynamic_cast< DeclarationWithType * >( *st->get_baseUnion()->get_members().begin() ); 340 initContext = dt->get_type(); 341 (*listInit->begin_initializers())->accept( *this ); 342 } else { 343 // basic types are handled here 344 Visitor::visit( listInit ); 345 } 346 304 347 #if 0 305 348 if ( ArrayType *at = dynamic_cast<ArrayType*>(initContext) ) {
Note: See TracChangeset
for help on using the changeset viewer.