Changeset a3f53d64 for src/AST/Convert.cpp
- Timestamp:
- Sep 24, 2020, 4:11:41 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- a9f0c65
- Parents:
- 10d78f1 (diff), 6cc913e (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r10d78f1 ra3f53d64 177 177 const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 178 178 if ( inCache( node ) ) return nullptr; 179 180 // function decl contains real variables that the type must use. 181 // the structural change means function type in and out of decl 182 // must be handled **differently** on convert back to old. 183 auto ftype = new FunctionType( 184 cv(node->type), 185 (bool)node->type->isVarArgs 186 ); 187 ftype->returnVals = get<DeclarationWithType>().acceptL(node->returns); 188 ftype->parameters = get<DeclarationWithType>().acceptL(node->params); 189 190 ftype->forall = get<TypeDecl>().acceptL( node->type->forall ); 191 192 visitType(node->type, ftype); 193 179 194 auto decl = new FunctionDecl( 180 195 node->name, 181 196 Type::StorageClasses( node->storage.val ), 182 197 LinkageSpec::Spec( node->linkage.val ), 183 get<FunctionType>().accept1( node->type ), 198 ftype, 199 //get<FunctionType>().accept1( node->type ), 184 200 {}, 185 201 get<Attribute>().acceptL( node->attributes ), … … 1152 1168 1153 1169 const ast::Type * visit( const ast::FunctionType * node ) override final { 1170 static std::string dummy_paramvar_prefix = "__param_"; 1171 static std::string dummy_returnvar_prefix = "__retval_"; 1172 1154 1173 auto ty = new FunctionType { 1155 1174 cv( node ), 1156 1175 (bool)node->isVarArgs 1157 1176 }; 1158 ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 1159 ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 1177 auto returns = get<Type>().acceptL(node->returns); 1178 auto params = get<Type>().acceptL(node->params); 1179 1180 int ret_index = 0; 1181 for (auto t: returns) { 1182 // xxx - LinkageSpec shouldn't matter but needs to be something 1183 ObjectDecl * dummy = new ObjectDecl(dummy_returnvar_prefix + std::to_string(ret_index++), {}, LinkageSpec::C, nullptr, t, nullptr); 1184 ty->returnVals.push_back(dummy); 1185 } 1186 int param_index = 0; 1187 for (auto t: params) { 1188 ObjectDecl * dummy = new ObjectDecl(dummy_paramvar_prefix + std::to_string(param_index++), {}, LinkageSpec::C, nullptr, t, nullptr); 1189 ty->parameters.push_back(dummy); 1190 } 1191 1192 // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 1193 // ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 1160 1194 ty->forall = get<TypeDecl>().acceptL( node->forall ); 1161 1195 return visitType( node, ty ); … … 1374 1408 ast::Node * node = nullptr; 1375 1409 /// cache of nodes that might be referenced by readonly<> for de-duplication 1376 std::unordered_map< const BaseSyntaxNode *, ast::Node * > cache = {}; 1410 /// in case that some nodes are dropped by conversion (due to possible structural change) 1411 /// use smart pointers in cache value to prevent accidental invalidation. 1412 /// at conversion stage, all created nodes are guaranteed to be unique, therefore 1413 /// const_casting out of smart pointers is permitted. 1414 std::unordered_map< const BaseSyntaxNode *, ast::ptr<ast::Node> > cache = {}; 1377 1415 1378 1416 // Local Utilities: … … 1447 1485 auto it = cache.find( old ); 1448 1486 if ( it == cache.end() ) return false; 1449 node = it->second;1487 node = const_cast<ast::Node *>(it->second.get()); 1450 1488 return true; 1451 1489 } … … 1486 1524 virtual void visit( const FunctionDecl * old ) override final { 1487 1525 if ( inCache( old ) ) return; 1526 auto paramVars = GET_ACCEPT_V(type->parameters, DeclWithType); 1527 auto returnVars = GET_ACCEPT_V(type->returnVals, DeclWithType); 1528 auto forall = GET_ACCEPT_V(type->forall, TypeDecl); 1529 1530 // function type is now derived from parameter decls instead of storing them 1531 auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type)); 1532 ftype->params.reserve(paramVars.size()); 1533 ftype->returns.reserve(returnVars.size()); 1534 1535 for (auto & v: paramVars) { 1536 ftype->params.emplace_back(v->get_type()); 1537 } 1538 for (auto & v: returnVars) { 1539 ftype->returns.emplace_back(v->get_type()); 1540 } 1541 ftype->forall = std::move(forall); 1542 visitType(old->type, ftype); 1543 1488 1544 auto decl = new ast::FunctionDecl{ 1489 1545 old->location, 1490 1546 old->name, 1491 GET_ACCEPT_1(type, FunctionType), 1547 // GET_ACCEPT_1(type, FunctionType), 1548 std::move(paramVars), 1549 std::move(returnVars), 1492 1550 {}, 1493 1551 { old->storageClasses.val }, … … 1496 1554 { old->get_funcSpec().val } 1497 1555 }; 1556 1557 decl->type = ftype; 1498 1558 cache.emplace( old, decl ); 1559 1499 1560 decl->withExprs = GET_ACCEPT_V(withExprs, Expr); 1500 1561 decl->stmts = GET_ACCEPT_1(statements, CompoundStmt); … … 2515 2576 cv( old ) 2516 2577 }; 2517 ty->returns = GET_ACCEPT_V( returnVals, DeclWithType ); 2518 ty->params = GET_ACCEPT_V( parameters, DeclWithType ); 2578 auto returnVars = GET_ACCEPT_V(returnVals, DeclWithType); 2579 auto paramVars = GET_ACCEPT_V(parameters, DeclWithType); 2580 // ty->returns = GET_ACCEPT_V( returnVals, DeclWithType ); 2581 // ty->params = GET_ACCEPT_V( parameters, DeclWithType ); 2582 for (auto & v: returnVars) { 2583 ty->returns.emplace_back(v->get_type()); 2584 } 2585 for (auto & v: paramVars) { 2586 ty->params.emplace_back(v->get_type()); 2587 } 2519 2588 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2520 2589 visitType( old, ty );
Note: See TracChangeset
for help on using the changeset viewer.