Changeset 546e712 for src/AST/Convert.cpp
- Timestamp:
- Jun 6, 2019, 3:01:46 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8c0d801, f46bfd2f
- Parents:
- 2a54479
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r2a54479 r546e712 148 148 149 149 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 150 if ( inCache( node ) ) return nullptr; 150 auto&& bfwd = get<Expression>().accept1( node->bitfieldWidth ); 151 auto&& type = get<Type>().accept1( node->type ); 152 auto&& init = get<Initializer>().accept1( node->init ); 153 auto&& attr = get<Attribute>().acceptL( node->attributes ); 154 if ( inCache( node ) ) { 155 if(node->name == "tmp") { 156 std::cerr << (void*)node << "(new) in cache " << (void*)this->node << "(old)" << std::endl; 157 } 158 return nullptr; 159 } 151 160 auto decl = new ObjectDecl( 152 161 node->name, 153 162 Type::StorageClasses( node->storage.val ), 154 163 LinkageSpec::Spec( node->linkage.val ), 155 get<Expression>().accept1( node->bitfieldWidth ),156 get<Type>().accept1( node->type ),157 get<Initializer>().accept1( node->init ),158 get<Attribute>().acceptL( node->attributes ),164 bfwd, 165 type, 166 init, 167 attr, 159 168 Type::FuncSpecifiers( node->funcSpec.val ) 160 169 ); 170 if(node->name == "tmp") { 171 std::cerr << (void*)node << "(new) created " << (void*)decl << "(old)" << std::endl; 172 } 161 173 return declWithTypePostamble( decl, node ); 162 174 } … … 719 731 720 732 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 721 auto expr = visitBaseExpr( node, 722 new VariableExpr( 723 get<DeclarationWithType>().accept1(node->var) 724 ) 725 ); 733 auto expr = new VariableExpr(); 734 visitBaseExpr( node, expr ); 735 expr->var = get<DeclarationWithType>().accept1(node->var); 736 Type * type = expr->var->get_type()->clone(); 737 type->set_lvalue( true ); 738 expr->set_result( type ); 726 739 this->node = expr; 727 740 return nullptr; … … 1356 1369 return strict_dynamic_cast< ast::Decl * >( node ); 1357 1370 } 1371 1372 ConverterOldToNew() = default; 1373 ConverterOldToNew(const ConverterOldToNew &) = delete; 1374 ConverterOldToNew(ConverterOldToNew &&) = delete; 1358 1375 private: 1359 1376 /// conversion output 1360 ast::Node * node ;1377 ast::Node * node = nullptr; 1361 1378 /// cache of nodes that might be referenced by readonly<> for de-duplication 1362 std::unordered_map< BaseSyntaxNode *, ast::Node * > cache ;1379 std::unordered_map< BaseSyntaxNode *, ast::Node * > cache = {}; 1363 1380 1364 1381 // Local Utilities: 1382 1383 #define construct(T, key, ...) ({ \ 1384 void * data = ::operator new(sizeof(T)); \ 1385 cache.emplace( key, (T*)data ); \ 1386 new (data) T( __VA_ARGS__ ); \ 1387 }) 1365 1388 1366 1389 template<typename NewT, typename OldT> … … 1424 1447 1425 1448 virtual void visit( ObjectDecl * old ) override final { 1426 if ( inCache( old ) ) return; 1449 if( old->name == "tmp" ) { 1450 std::cerr << "building parameters for" << (void*)old << std::endl; 1451 } 1452 auto&& type = GET_ACCEPT_1(type, Type); 1453 auto&& init = GET_ACCEPT_1(init, Init); 1454 auto&& bfwd = GET_ACCEPT_1(bitfieldWidth, Expr); 1455 auto&& attr = GET_ACCEPT_V(attributes, Attribute); 1456 if( old->name == "tmp" ) { 1457 std::cerr << "checking cache for " << (void*)old << std::endl; 1458 } 1459 if ( inCache( old ) ) { 1460 if( old->name == "tmp" ) { 1461 std::cerr << (void*)old << "(old) in cache " << (void*)this->node << "(new)" << std::endl; 1462 } 1463 return; 1464 } 1427 1465 auto decl = new ast::ObjectDecl( 1428 1466 old->location, 1429 1467 old->name, 1430 GET_ACCEPT_1(type, Type),1431 GET_ACCEPT_1(init, Init),1468 type, 1469 init, 1432 1470 { old->get_storageClasses().val }, 1433 1471 { old->linkage.val }, 1434 GET_ACCEPT_1(bitfieldWidth, Expr),1435 GET_ACCEPT_V(attributes, Attribute),1472 bfwd, 1473 std::move(attr), 1436 1474 { old->get_funcSpec().val } 1437 1475 ); 1438 cache.emplace( old, decl ); 1476 cache.emplace(old, decl); 1477 if( old->name == "tmp" ) { 1478 std::cerr << (void*)old << "(old) added to cache with " << (void*)decl << "(new)" << std::endl; 1479 } 1480 assert(cache.find( old ) != cache.end()); 1439 1481 decl->scopeLevel = old->scopeLevel; 1440 1482 decl->mangleName = old->mangleName; … … 1444 1486 1445 1487 this->node = decl; 1488 1489 if( old->name == "tmp" ) { 1490 std::cerr << (void*)old << "(old) created " << (void*)this->node << "(new)" << std::endl; 1491 } 1446 1492 } 1447 1493 … … 2099 2145 2100 2146 virtual void visit( VariableExpr * old ) override final { 2101 this->node = visitBaseExpr( old, 2102 new ast::VariableExpr( 2103 old->location, 2104 GET_ACCEPT_1(var, DeclWithType) 2105 ) 2106 ); 2147 auto expr = new ast::VariableExpr( 2148 old->location 2149 ); 2150 2151 visitBaseExpr( old, 2152 expr 2153 ); 2154 2155 expr->var = GET_ACCEPT_1(var, DeclWithType); 2156 expr->result = expr->var->get_type(); 2157 add_qualifiers( expr->result, ast::CV::Lvalue ); 2158 this->node = expr; 2107 2159 } 2108 2160
Note: See TracChangeset
for help on using the changeset viewer.