- Timestamp:
- Jun 6, 2019, 3:40:56 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:
- 1a4323e
- Parents:
- b7d92b96 (diff), 546e712 (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. - Location:
- src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rb7d92b96 r8c0d801 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 29 17:05:00 201913 // Update Count : 912 // Last Modified On : Thu May 06 19:51:00 2019 13 // Update Count : 10 14 14 // 15 15 … … 49 49 // This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not) 50 50 // allow us to use the same stratagy in the new ast. 51 ast::Type * sizeType = nullptr; 51 52 ast::FunctionDecl * dereferenceOperator = nullptr; 52 53 ast::StructDecl * dtorStruct = nullptr; … … 147 148 148 149 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 149 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 } 150 160 auto decl = new ObjectDecl( 151 161 node->name, 152 162 Type::StorageClasses( node->storage.val ), 153 163 LinkageSpec::Spec( node->linkage.val ), 154 get<Expression>().accept1( node->bitfieldWidth ),155 get<Type>().accept1( node->type ),156 get<Initializer>().accept1( node->init ),157 get<Attribute>().acceptL( node->attributes ),164 bfwd, 165 type, 166 init, 167 attr, 158 168 Type::FuncSpecifiers( node->funcSpec.val ) 159 169 ); 170 if(node->name == "tmp") { 171 std::cerr << (void*)node << "(new) created " << (void*)decl << "(old)" << std::endl; 172 } 160 173 return declWithTypePostamble( decl, node ); 161 174 } … … 709 722 auto expr = visitBaseExpr( node, 710 723 new MemberExpr( 711 inCache(node->member) ? 712 dynamic_cast<DeclarationWithType *>(this->node) : 713 get<DeclarationWithType>().accept1(node->member), 724 get<DeclarationWithType>().accept1(node->member), 714 725 get<Expression>().accept1(node->aggregate) 715 726 ) … … 720 731 721 732 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 722 auto expr = visitBaseExpr( node, 723 new VariableExpr( 724 inCache(node->var) ? 725 dynamic_cast<DeclarationWithType *>(this->node) : 726 get<DeclarationWithType>().accept1(node->var) 727 ) 728 ); 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 ); 729 739 this->node = expr; 730 740 return nullptr; … … 819 829 new OffsetofExpr( 820 830 get<Type>().accept1(node->type), 821 inCache(node->member) ? 822 dynamic_cast<DeclarationWithType *>(this->node) : 823 get<DeclarationWithType>().accept1(node->member) 831 get<DeclarationWithType>().accept1(node->member) 824 832 ) 825 833 ); … … 1082 1090 1083 1091 const ast::Type * visit( const ast::BasicType * node ) override final { 1084 this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind }; 1092 auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind }; 1093 // I believe this should always be a BasicType. 1094 if ( sizeType == node ) { 1095 Validate::SizeType = type; 1096 } 1097 this->node = type; 1085 1098 return nullptr; 1086 1099 } … … 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 … … 2092 2138 new ast::MemberExpr( 2093 2139 old->location, 2094 inCache(old->member) ? 2095 dynamic_cast<ast::DeclWithType *>(this->node) : 2096 GET_ACCEPT_1(member, DeclWithType), 2140 GET_ACCEPT_1(member, DeclWithType), 2097 2141 GET_ACCEPT_1(aggregate, Expr) 2098 2142 ) … … 2101 2145 2102 2146 virtual void visit( VariableExpr * old ) override final { 2103 this->node = visitBaseExpr( old, 2104 new ast::VariableExpr( 2105 old->location, 2106 inCache(old->var) ? 2107 dynamic_cast<ast::DeclWithType *>(this->node) : 2108 GET_ACCEPT_1(var, DeclWithType) 2109 ) 2110 ); 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; 2111 2159 } 2112 2160 … … 2234 2282 old->location, 2235 2283 GET_ACCEPT_1(type, Type), 2236 inCache(old->member) ? 2237 dynamic_cast<ast::DeclWithType *>(this->node) : 2238 GET_ACCEPT_1(member, DeclWithType) 2284 GET_ACCEPT_1(member, DeclWithType) 2239 2285 ) 2240 2286 ); … … 2472 2518 2473 2519 virtual void visit( BasicType * old ) override final { 2474 this->node = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) }; 2520 auto type = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) }; 2521 // I believe this should always be a BasicType. 2522 if ( Validate::SizeType == old ) { 2523 sizeType = type; 2524 } 2525 this->node = type; 2475 2526 } 2476 2527 -
src/AST/Expr.cpp
rb7d92b96 r8c0d801 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
rb7d92b96 r8c0d801 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
rb7d92b96 r8c0d801 206 206 /// wrapper for convenient access to strict_dynamic_cast 207 207 template<typename o_node_t> 208 const o_node_t * strict_as() const { return strict_dynamic_cast<const o_node_t *>(node); }208 const o_node_t * strict_as() const { _check(); return strict_dynamic_cast<const o_node_t *>(node); } 209 209 210 210 /// Returns a mutable version of the pointer in this node. -
src/InitTweak/FixInit.cc
rb7d92b96 r8c0d801 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
rb7d92b96 r8c0d801 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
rb7d92b96 r8c0d801 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
rb7d92b96 r8c0d801 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.