- 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
- Location:
- src
- Files:
-
- 8 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 -
src/AST/Expr.cpp
r2a54479 r546e712 170 170 // --- VariableExpr 171 171 172 VariableExpr::VariableExpr( const CodeLocation & loc ) 173 : Expr( loc ), var( nullptr ) {} 174 172 175 VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v ) 173 176 : Expr( loc ), var( v ) { -
src/AST/Expr.hpp
r2a54479 r546e712 315 315 readonly<DeclWithType> var; 316 316 317 VariableExpr( const CodeLocation & loc ); 317 318 VariableExpr( const CodeLocation & loc, const DeclWithType * v ); 318 319 -
src/AST/Node.hpp
r2a54479 r546e712 191 191 /// wrapper for convenient access to strict_dynamic_cast 192 192 template<typename o_node_t> 193 const o_node_t * strict_as() const { return strict_dynamic_cast<const o_node_t *>(node); }193 const o_node_t * strict_as() const { _check(); return strict_dynamic_cast<const o_node_t *>(node); } 194 194 195 195 /// Returns a mutable version of the pointer in this node. -
src/InitTweak/FixInit.cc
r2a54479 r546e712 262 262 // unwrap implicit statement wrapper 263 263 Statement * dtor = input; 264 if ( ImplicitCtorDtorStmt * implicit = dynamic_cast< ImplicitCtorDtorStmt * >( input ) ) {265 // dtor = implicit->callStmt;266 // implicit->callStmt = nullptr;267 }268 264 assert( dtor ); 269 265 std::list< Expression * > matches; … … 291 287 // wraps the more complicated code. 292 288 static UniqueName dtorNamer( "__cleanup_dtor" ); 293 FunctionDecl * dtorFunc = FunctionDecl::newFunction( dtorNamer.newName(), SymTab::genDefaultType( objDecl->type->stripReferences(), false ), new CompoundStmt() ); 289 std::string name = dtorNamer.newName(); 290 if(name == "__cleanup_dtor8") { 291 objDecl->print(std::cerr); 292 std::cerr << "-----" << std::endl; 293 dtor->print(std::cerr); 294 } 295 FunctionDecl * dtorFunc = FunctionDecl::newFunction( name, SymTab::genDefaultType( objDecl->type->stripReferences(), false ), new CompoundStmt() ); 294 296 stmtsToAdd.push_back( new DeclStmt( dtorFunc ) ); 295 297 … … 304 306 replacement = new CastExpr( replacement, base->clone() ); 305 307 } 306 DeclReplacer::replace( dtor, { std::make_pair( objDecl, replacement ) } ); 308 size_t replaced = DeclReplacer::replace( dtor, { std::make_pair( objDecl, replacement ) } ); 309 if(replaced == 0) { 310 std::cerr << "Failed to replace " << objDecl << std::endl; 311 abort(); 312 } 307 313 dtorFunc->statements->push_back( strict_dynamic_cast<Statement *>( dtor ) ); 308 314 -
src/SynTree/DeclReplacer.h
r2a54479 r546e712 33 33 34 34 size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false); 35 35 36 template<typename T> 36 voidreplace( T *& node, const ExprMap & exprMap, bool debug = false ) {37 if ( ! node ) return ;37 size_t replace( T *& node, const ExprMap & exprMap, bool debug = false ) { 38 if ( ! node ) return 0ul; 38 39 BaseSyntaxNode * arg = node; 39 replace( arg, exprMap, debug );40 size_t replaced = replace( arg, exprMap, debug ); 40 41 node = dynamic_cast<T *>( arg ); 41 42 assertf( node, "DeclReplacer fundamentally changed the type of its argument." ); 43 return replaced; 42 44 } 43 45 } -
src/SynTree/Expression.cc
r2a54479 r546e712 102 102 SemanticError( this, "Constant expression of non-integral type " ); 103 103 } 104 105 VariableExpr::VariableExpr() : Expression(), var( nullptr ) {} 104 106 105 107 VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) { -
src/SynTree/Expression.h
r2a54479 r546e712 299 299 DeclarationWithType * var; 300 300 301 VariableExpr(); 301 302 VariableExpr( DeclarationWithType * var ); 302 303 VariableExpr( const VariableExpr & other );
Note: See TracChangeset
for help on using the changeset viewer.