[6d51bd7] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[74dbbf6] | 7 | // Convert.cpp -- Convert between the new and old syntax trees. |
---|
[6d51bd7] | 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Thu May 09 15::37::05 2019 |
---|
[39d8950] | 11 | // Last Modified By : Andrew Beach |
---|
[f6e6a55] | 12 | // Last Modified On : Wed Apr 20 13:58:00 2022 |
---|
| 13 | // Update Count : 43 |
---|
[6d51bd7] | 14 | // |
---|
| 15 | |
---|
| 16 | #include "Convert.hpp" |
---|
| 17 | |
---|
[60aaa51d] | 18 | #include <deque> |
---|
[d148778] | 19 | #include <unordered_map> |
---|
| 20 | |
---|
[6d51bd7] | 21 | #include "AST/Attribute.hpp" |
---|
[8ff586c] | 22 | #include "AST/Copy.hpp" |
---|
[6d51bd7] | 23 | #include "AST/Decl.hpp" |
---|
| 24 | #include "AST/Expr.hpp" |
---|
| 25 | #include "AST/Init.hpp" |
---|
| 26 | #include "AST/Stmt.hpp" |
---|
[293dc1c] | 27 | #include "AST/TranslationUnit.hpp" |
---|
[172d9342] | 28 | #include "AST/TypeSubstitution.hpp" |
---|
[6d51bd7] | 29 | |
---|
[157a816] | 30 | #include "SymTab/Autogen.h" |
---|
[6d51bd7] | 31 | #include "SynTree/Attribute.h" |
---|
| 32 | #include "SynTree/Declaration.h" |
---|
[172d9342] | 33 | #include "SynTree/TypeSubstitution.h" |
---|
[6d51bd7] | 34 | |
---|
[0aedb01] | 35 | #include "Validate/FindSpecialDecls.h" |
---|
| 36 | |
---|
[6d51bd7] | 37 | //================================================================================================ |
---|
| 38 | // Utilities |
---|
| 39 | template<template <class...> class C> |
---|
| 40 | struct to { |
---|
| 41 | template<typename T> |
---|
| 42 | static auto from( T && v ) -> C< typename T::value_type > { |
---|
| 43 | C< typename T::value_type > l; |
---|
| 44 | std::move(std::begin(v), std::end(v), std::back_inserter(l)); |
---|
| 45 | return l; |
---|
| 46 | } |
---|
| 47 | }; |
---|
| 48 | |
---|
[157a816] | 49 | //================================================================================================ |
---|
[490fb92e] | 50 | namespace ast { |
---|
[39d8950] | 51 | // These are the shared local information used by ConverterNewToOld and |
---|
| 52 | // ConverterOldToNew to update the global information in the two versions. |
---|
[157a816] | 53 | |
---|
[39d8950] | 54 | static ast::ptr<ast::Type> sizeType = nullptr; |
---|
| 55 | static const ast::FunctionDecl * dereferenceOperator = nullptr; |
---|
| 56 | static const ast::StructDecl * dtorStruct = nullptr; |
---|
| 57 | static const ast::FunctionDecl * dtorStructDestroy = nullptr; |
---|
[157a816] | 58 | |
---|
| 59 | } |
---|
| 60 | |
---|
[6d51bd7] | 61 | //================================================================================================ |
---|
[74dbbf6] | 62 | class ConverterNewToOld : public ast::Visitor { |
---|
[675d816] | 63 | BaseSyntaxNode * node = nullptr; |
---|
[b869ec5] | 64 | using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >; |
---|
| 65 | Cache cache; |
---|
[675d816] | 66 | |
---|
[490fb92e] | 67 | // Statements can no longer be shared. |
---|
| 68 | // however, since StmtExprResult is now implemented, need to still maintain |
---|
| 69 | // readonly references. |
---|
| 70 | Cache readonlyCache; |
---|
| 71 | |
---|
[74dbbf6] | 72 | template<typename T> |
---|
[675d816] | 73 | struct Getter { |
---|
| 74 | ConverterNewToOld & visitor; |
---|
| 75 | |
---|
[514a791] | 76 | template<typename U, enum ast::Node::ref_type R> |
---|
| 77 | T * accept1( const ast::ptr_base<U, R> & ptr ) { |
---|
[d148778] | 78 | if ( ! ptr ) return nullptr; |
---|
[675d816] | 79 | ptr->accept( visitor ); |
---|
| 80 | T * ret = strict_dynamic_cast< T * >( visitor.node ); |
---|
| 81 | visitor.node = nullptr; |
---|
| 82 | return ret; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | template<typename U> |
---|
| 86 | std::list< T * > acceptL( const U & container ) { |
---|
| 87 | std::list< T * > ret; |
---|
[d76c588] | 88 | for ( auto ptr : container ) { |
---|
[675d816] | 89 | ret.emplace_back( accept1( ptr ) ); |
---|
| 90 | } |
---|
| 91 | return ret; |
---|
| 92 | } |
---|
| 93 | }; |
---|
| 94 | |
---|
[7edd5c1] | 95 | template<typename T> |
---|
| 96 | Getter<T> get() { |
---|
| 97 | return Getter<T>{ *this }; |
---|
| 98 | } |
---|
[675d816] | 99 | |
---|
| 100 | Label makeLabel(Statement * labelled, const ast::Label& label) { |
---|
[a62749f] | 101 | // This probably will leak memory, but only until we get rid of the old tree. |
---|
| 102 | if ( nullptr == labelled && label.location.isSet() ) { |
---|
| 103 | labelled = new NullStmt(); |
---|
| 104 | labelled->location = label.location; |
---|
| 105 | } |
---|
[675d816] | 106 | return Label( |
---|
| 107 | label.name, |
---|
| 108 | labelled, |
---|
| 109 | get<Attribute>().acceptL(label.attributes) |
---|
| 110 | ); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | template<template <class...> class C> |
---|
| 114 | std::list<Label> makeLabelL(Statement * labelled, const C<ast::Label>& labels) { |
---|
| 115 | std::list<Label> ret; |
---|
| 116 | for (auto label : labels) { |
---|
| 117 | ret.push_back( makeLabel(labelled, label) ); |
---|
| 118 | } |
---|
[74dbbf6] | 119 | return ret; |
---|
| 120 | } |
---|
| 121 | |
---|
[d148778] | 122 | /// get new qualifiers from old type |
---|
| 123 | Type::Qualifiers cv( const ast::Type * ty ) { return { ty->qualifiers.val }; } |
---|
| 124 | |
---|
[b869ec5] | 125 | /// returns true and sets `node` if in cache |
---|
| 126 | bool inCache( const ast::Node * node ) { |
---|
| 127 | auto it = cache.find( node ); |
---|
| 128 | if ( it == cache.end() ) return false; |
---|
| 129 | this->node = it->second; |
---|
| 130 | return true; |
---|
[d148778] | 131 | } |
---|
| 132 | |
---|
[675d816] | 133 | public: |
---|
| 134 | Declaration * decl( const ast::Decl * declNode ) { |
---|
| 135 | return get<Declaration>().accept1( ast::ptr<ast::Decl>( declNode ) ); |
---|
| 136 | } |
---|
[74dbbf6] | 137 | |
---|
[675d816] | 138 | private: |
---|
[112fe04] | 139 | void declPostamble( Declaration * decl, const ast::Decl * node ) { |
---|
| 140 | decl->location = node->location; |
---|
| 141 | // name comes from constructor |
---|
| 142 | // linkage comes from constructor |
---|
| 143 | decl->extension = node->extension; |
---|
| 144 | decl->uniqueId = node->uniqueId; |
---|
| 145 | // storageClasses comes from constructor |
---|
| 146 | this->node = decl; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | const ast::DeclWithType * declWithTypePostamble ( |
---|
| 150 | DeclarationWithType * decl, const ast::DeclWithType * node ) { |
---|
[f685679] | 151 | cache.emplace( node, decl ); |
---|
[112fe04] | 152 | decl->mangleName = node->mangleName; |
---|
| 153 | decl->scopeLevel = node->scopeLevel; |
---|
| 154 | decl->asmName = get<Expression>().accept1( node->asmName ); |
---|
| 155 | // attributes comes from constructor |
---|
| 156 | decl->isDeleted = node->isDeleted; |
---|
| 157 | // fs comes from constructor |
---|
[f685679] | 158 | declPostamble( decl, node ); |
---|
[74dbbf6] | 159 | return nullptr; |
---|
| 160 | } |
---|
| 161 | |
---|
[490fb92e] | 162 | const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { |
---|
[546e712] | 163 | if ( inCache( node ) ) { |
---|
| 164 | return nullptr; |
---|
| 165 | } |
---|
[490fb92e] | 166 | auto bfwd = get<Expression>().accept1( node->bitfieldWidth ); |
---|
| 167 | auto type = get<Type>().accept1( node->type ); |
---|
| 168 | auto attr = get<Attribute>().acceptL( node->attributes ); |
---|
| 169 | |
---|
[1931bb01] | 170 | // This field can be unset very early on (Pre-FixReturnTypes). |
---|
| 171 | auto newType = (type) ? type->clone() : nullptr; |
---|
| 172 | |
---|
[112fe04] | 173 | auto decl = new ObjectDecl( |
---|
| 174 | node->name, |
---|
| 175 | Type::StorageClasses( node->storage.val ), |
---|
| 176 | LinkageSpec::Spec( node->linkage.val ), |
---|
[546e712] | 177 | bfwd, |
---|
[1931bb01] | 178 | newType, |
---|
[490fb92e] | 179 | nullptr, // prevent infinite loop |
---|
[546e712] | 180 | attr, |
---|
[112fe04] | 181 | Type::FuncSpecifiers( node->funcSpec.val ) |
---|
| 182 | ); |
---|
[490fb92e] | 183 | |
---|
| 184 | // handles the case where node->init references itself |
---|
| 185 | // xxx - does it really happen? |
---|
| 186 | declWithTypePostamble(decl, node); |
---|
| 187 | auto init = get<Initializer>().accept1( node->init ); |
---|
| 188 | decl->init = init; |
---|
[23954b6] | 189 | |
---|
[490fb92e] | 190 | this->node = decl; |
---|
| 191 | return nullptr; |
---|
[112fe04] | 192 | } |
---|
| 193 | |
---|
[74dbbf6] | 194 | const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { |
---|
[b869ec5] | 195 | if ( inCache( node ) ) return nullptr; |
---|
[954c954] | 196 | |
---|
| 197 | // function decl contains real variables that the type must use. |
---|
| 198 | // the structural change means function type in and out of decl |
---|
| 199 | // must be handled **differently** on convert back to old. |
---|
| 200 | auto ftype = new FunctionType( |
---|
| 201 | cv(node->type), |
---|
| 202 | (bool)node->type->isVarArgs |
---|
| 203 | ); |
---|
| 204 | ftype->returnVals = get<DeclarationWithType>().acceptL(node->returns); |
---|
| 205 | ftype->parameters = get<DeclarationWithType>().acceptL(node->params); |
---|
| 206 | |
---|
[3e5dd913] | 207 | ftype->forall = get<TypeDecl>().acceptL( node->type_params ); |
---|
| 208 | if (!node->assertions.empty()) { |
---|
| 209 | assert(!ftype->forall.empty()); |
---|
| 210 | // find somewhere to place assertions back, for convenience it is the last slot |
---|
| 211 | ftype->forall.back()->assertions = get<DeclarationWithType>().acceptL(node->assertions); |
---|
| 212 | } |
---|
[954c954] | 213 | |
---|
| 214 | visitType(node->type, ftype); |
---|
| 215 | |
---|
[112fe04] | 216 | auto decl = new FunctionDecl( |
---|
| 217 | node->name, |
---|
| 218 | Type::StorageClasses( node->storage.val ), |
---|
| 219 | LinkageSpec::Spec( node->linkage.val ), |
---|
[954c954] | 220 | ftype, |
---|
| 221 | //get<FunctionType>().accept1( node->type ), |
---|
[d88f8b3b] | 222 | {}, |
---|
[112fe04] | 223 | get<Attribute>().acceptL( node->attributes ), |
---|
| 224 | Type::FuncSpecifiers( node->funcSpec.val ) |
---|
| 225 | ); |
---|
[d88f8b3b] | 226 | cache.emplace( node, decl ); |
---|
| 227 | decl->statements = get<CompoundStmt>().accept1( node->stmts ); |
---|
[112fe04] | 228 | decl->withExprs = get<Expression>().acceptL( node->withExprs ); |
---|
[490fb92e] | 229 | if ( ast::dereferenceOperator == node ) { |
---|
[0aedb01] | 230 | Validate::dereferenceOperator = decl; |
---|
[157a816] | 231 | } |
---|
[490fb92e] | 232 | if ( ast::dtorStructDestroy == node ) { |
---|
[043a5b6] | 233 | Validate::dtorStructDestroy = decl; |
---|
| 234 | } |
---|
[112fe04] | 235 | return declWithTypePostamble( decl, node ); |
---|
[74dbbf6] | 236 | } |
---|
| 237 | |
---|
[71806e0] | 238 | // InlineMemberDecl vanish after EnumAndPointerDecay pass so no necessary to implement NewToOld |
---|
| 239 | const ast::DeclWithType * visit( const ast::InlineMemberDecl * node ) override final { |
---|
[e874605] | 240 | assert( false ); |
---|
| 241 | (void) node; |
---|
| 242 | return nullptr; |
---|
| 243 | } |
---|
| 244 | |
---|
[112fe04] | 245 | const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) { |
---|
| 246 | // base comes from constructor |
---|
| 247 | decl->assertions = get<DeclarationWithType>().acceptL( node->assertions ); |
---|
[f685679] | 248 | declPostamble( decl, node ); |
---|
[74dbbf6] | 249 | return nullptr; |
---|
| 250 | } |
---|
| 251 | |
---|
[112fe04] | 252 | const ast::Decl * visit( const ast::TypeDecl * node ) override final { |
---|
[b869ec5] | 253 | if ( inCache( node ) ) return nullptr; |
---|
[112fe04] | 254 | auto decl = new TypeDecl( |
---|
| 255 | node->name, |
---|
| 256 | Type::StorageClasses( node->storage.val ), |
---|
| 257 | get<Type>().accept1( node->base ), |
---|
[b869ec5] | 258 | (TypeDecl::Kind)(unsigned)node->kind, |
---|
[112fe04] | 259 | node->sized, |
---|
| 260 | get<Type>().accept1( node->init ) |
---|
| 261 | ); |
---|
[b869ec5] | 262 | cache.emplace( node, decl ); |
---|
[112fe04] | 263 | return namedTypePostamble( decl, node ); |
---|
[74dbbf6] | 264 | } |
---|
| 265 | |
---|
[112fe04] | 266 | const ast::Decl * visit( const ast::TypedefDecl * node ) override final { |
---|
| 267 | auto decl = new TypedefDecl( |
---|
| 268 | node->name, |
---|
| 269 | node->location, |
---|
| 270 | Type::StorageClasses( node->storage.val ), |
---|
| 271 | get<Type>().accept1( node->base ), |
---|
| 272 | LinkageSpec::Spec( node->linkage.val ) |
---|
| 273 | ); |
---|
| 274 | return namedTypePostamble( decl, node ); |
---|
[74dbbf6] | 275 | } |
---|
| 276 | |
---|
[112fe04] | 277 | const ast::Decl * aggregatePostamble( AggregateDecl * decl, const ast::AggregateDecl * node ) { |
---|
[f685679] | 278 | cache.emplace( node, decl ); |
---|
[112fe04] | 279 | decl->members = get<Declaration>().acceptL( node->members ); |
---|
| 280 | decl->parameters = get<TypeDecl>().acceptL( node->params ); |
---|
| 281 | decl->body = node->body; |
---|
| 282 | // attributes come from constructor |
---|
[b869ec5] | 283 | decl->parent = get<AggregateDecl>().accept1( node->parent ); |
---|
[f685679] | 284 | declPostamble( decl, node ); |
---|
[f135b50] | 285 | return nullptr; // ?? |
---|
[74dbbf6] | 286 | } |
---|
| 287 | |
---|
[112fe04] | 288 | const ast::Decl * visit( const ast::StructDecl * node ) override final { |
---|
[b869ec5] | 289 | if ( inCache( node ) ) return nullptr; |
---|
[112fe04] | 290 | auto decl = new StructDecl( |
---|
| 291 | node->name, |
---|
[312029a] | 292 | (AggregateDecl::Aggregate)node->kind, |
---|
[112fe04] | 293 | get<Attribute>().acceptL( node->attributes ), |
---|
| 294 | LinkageSpec::Spec( node->linkage.val ) |
---|
| 295 | ); |
---|
[043a5b6] | 296 | |
---|
[490fb92e] | 297 | if ( ast::dtorStruct == node ) { |
---|
[043a5b6] | 298 | Validate::dtorStruct = decl; |
---|
| 299 | } |
---|
| 300 | |
---|
[112fe04] | 301 | return aggregatePostamble( decl, node ); |
---|
[74dbbf6] | 302 | } |
---|
| 303 | |
---|
[112fe04] | 304 | const ast::Decl * visit( const ast::UnionDecl * node ) override final { |
---|
[b869ec5] | 305 | if ( inCache( node ) ) return nullptr; |
---|
[112fe04] | 306 | auto decl = new UnionDecl( |
---|
| 307 | node->name, |
---|
| 308 | get<Attribute>().acceptL( node->attributes ), |
---|
| 309 | LinkageSpec::Spec( node->linkage.val ) |
---|
| 310 | ); |
---|
| 311 | return aggregatePostamble( decl, node ); |
---|
| 312 | } |
---|
| 313 | |
---|
[3e54399] | 314 | const ast::Decl * visit( const ast::EnumDecl * node ) override final { |
---|
[b869ec5] | 315 | if ( inCache( node ) ) return nullptr; |
---|
[112fe04] | 316 | auto decl = new EnumDecl( |
---|
| 317 | node->name, |
---|
| 318 | get<Attribute>().acceptL( node->attributes ), |
---|
[5408b59] | 319 | node->isTyped, |
---|
[3e54399] | 320 | LinkageSpec::Spec( node->linkage.val ), |
---|
| 321 | get<Type>().accept1(node->base) |
---|
[112fe04] | 322 | ); |
---|
[5408b59] | 323 | return aggregatePostamble( decl, node ); |
---|
[112fe04] | 324 | } |
---|
| 325 | |
---|
| 326 | const ast::Decl * visit( const ast::TraitDecl * node ) override final { |
---|
[b869ec5] | 327 | if ( inCache( node ) ) return nullptr; |
---|
[112fe04] | 328 | auto decl = new TraitDecl( |
---|
| 329 | node->name, |
---|
| 330 | {}, |
---|
| 331 | LinkageSpec::Spec( node->linkage.val ) |
---|
| 332 | ); |
---|
| 333 | return aggregatePostamble( decl, node ); |
---|
[74dbbf6] | 334 | } |
---|
| 335 | |
---|
| 336 | const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { |
---|
[112fe04] | 337 | auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) ); |
---|
| 338 | declPostamble( decl, node ); |
---|
[74dbbf6] | 339 | return nullptr; |
---|
| 340 | } |
---|
| 341 | |
---|
[2d019af] | 342 | const ast::DirectiveDecl * visit( const ast::DirectiveDecl * node ) override final { |
---|
| 343 | auto decl = new DirectiveDecl( get<DirectiveStmt>().accept1( node->stmt ) ); |
---|
| 344 | declPostamble( decl, node ); |
---|
| 345 | return nullptr; |
---|
| 346 | } |
---|
| 347 | |
---|
[74dbbf6] | 348 | const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { |
---|
[112fe04] | 349 | auto decl = new StaticAssertDecl( |
---|
| 350 | get<Expression>().accept1( node->cond ), |
---|
| 351 | get<ConstantExpr>().accept1( node->msg ) |
---|
| 352 | ); |
---|
| 353 | declPostamble( decl, node ); |
---|
[74dbbf6] | 354 | return nullptr; |
---|
| 355 | } |
---|
| 356 | |
---|
[112fe04] | 357 | const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) { |
---|
[490fb92e] | 358 | // force statements in old tree to be unique. |
---|
| 359 | // cache.emplace( node, stmt ); |
---|
| 360 | readonlyCache.emplace( node, stmt ); |
---|
[675d816] | 361 | stmt->location = node->location; |
---|
| 362 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
| 363 | this->node = stmt; |
---|
[74dbbf6] | 364 | return nullptr; |
---|
| 365 | } |
---|
| 366 | |
---|
[400b8be] | 367 | void clausePostamble( Statement * stmt, const ast::StmtClause * node ) { |
---|
| 368 | stmt->location = node->location; |
---|
| 369 | this->node = stmt; |
---|
| 370 | } |
---|
| 371 | |
---|
[112fe04] | 372 | const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { |
---|
[4073b16] | 373 | if ( inCache( node ) ) return nullptr; |
---|
[112fe04] | 374 | auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); |
---|
| 375 | stmtPostamble( stmt, node ); |
---|
| 376 | return nullptr; |
---|
| 377 | } |
---|
| 378 | |
---|
[74dbbf6] | 379 | const ast::Stmt * visit( const ast::ExprStmt * node ) override final { |
---|
[4073b16] | 380 | if ( inCache( node ) ) return nullptr; |
---|
[f685679] | 381 | auto stmt = new ExprStmt( nullptr ); |
---|
| 382 | stmt->expr = get<Expression>().accept1( node->expr ); |
---|
[112fe04] | 383 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 384 | } |
---|
| 385 | |
---|
| 386 | const ast::Stmt * visit( const ast::AsmStmt * node ) override final { |
---|
[4073b16] | 387 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 388 | auto stmt = new AsmStmt( |
---|
| 389 | node->isVolatile, |
---|
| 390 | get<Expression>().accept1( node->instruction ), |
---|
| 391 | get<Expression>().acceptL( node->output ), |
---|
| 392 | get<Expression>().acceptL( node->input ), |
---|
| 393 | get<ConstantExpr>().acceptL( node->clobber ), |
---|
| 394 | makeLabelL( nullptr, node->gotoLabels ) // What are these labelling? |
---|
| 395 | ); |
---|
[112fe04] | 396 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 397 | } |
---|
| 398 | |
---|
| 399 | const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { |
---|
[4073b16] | 400 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 401 | auto stmt = new DirectiveStmt( node->directive ); |
---|
[112fe04] | 402 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 403 | } |
---|
| 404 | |
---|
| 405 | const ast::Stmt * visit( const ast::IfStmt * node ) override final { |
---|
[4073b16] | 406 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 407 | auto stmt = new IfStmt( |
---|
| 408 | get<Expression>().accept1( node->cond ), |
---|
[3b0bc16] | 409 | get<Statement>().accept1( node->then ), |
---|
| 410 | get<Statement>().accept1( node->else_ ), |
---|
[675d816] | 411 | get<Statement>().acceptL( node->inits ) |
---|
| 412 | ); |
---|
[112fe04] | 413 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 414 | } |
---|
| 415 | |
---|
[675d816] | 416 | const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { |
---|
[4073b16] | 417 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 418 | auto stmt = new SwitchStmt( |
---|
| 419 | get<Expression>().accept1( node->cond ), |
---|
[400b8be] | 420 | get<Statement>().acceptL( node->cases ) |
---|
[675d816] | 421 | ); |
---|
[112fe04] | 422 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 423 | } |
---|
| 424 | |
---|
[400b8be] | 425 | const ast::CaseClause * visit( const ast::CaseClause * node ) override final { |
---|
[4073b16] | 426 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 427 | auto stmt = new CaseStmt( |
---|
| 428 | get<Expression>().accept1( node->cond ), |
---|
| 429 | get<Statement>().acceptL( node->stmts ), |
---|
| 430 | node->isDefault() |
---|
| 431 | ); |
---|
[400b8be] | 432 | clausePostamble( stmt, node ); |
---|
| 433 | return nullptr; |
---|
[74dbbf6] | 434 | } |
---|
| 435 | |
---|
[3b0bc16] | 436 | const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final { |
---|
[4073b16] | 437 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 438 | auto inits = get<Statement>().acceptL( node->inits ); |
---|
[3b0bc16] | 439 | auto stmt = new WhileDoStmt( |
---|
[675d816] | 440 | get<Expression>().accept1( node->cond ), |
---|
| 441 | get<Statement>().accept1( node->body ), |
---|
[ff3b0249] | 442 | get<Statement>().accept1( node->else_ ), |
---|
[675d816] | 443 | inits, |
---|
| 444 | node->isDoWhile |
---|
| 445 | ); |
---|
[112fe04] | 446 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 447 | } |
---|
| 448 | |
---|
[675d816] | 449 | const ast::Stmt * visit( const ast::ForStmt * node ) override final { |
---|
[4073b16] | 450 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 451 | auto stmt = new ForStmt( |
---|
| 452 | get<Statement>().acceptL( node->inits ), |
---|
| 453 | get<Expression>().accept1( node->cond ), |
---|
| 454 | get<Expression>().accept1( node->inc ), |
---|
[ff3b0249] | 455 | get<Statement>().accept1( node->body ), |
---|
| 456 | get<Statement>().accept1( node->else_ ) |
---|
[675d816] | 457 | ); |
---|
[112fe04] | 458 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 459 | } |
---|
| 460 | |
---|
| 461 | const ast::Stmt * visit( const ast::BranchStmt * node ) override final { |
---|
[4073b16] | 462 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 463 | BranchStmt * stmt; |
---|
| 464 | if (node->computedTarget) { |
---|
| 465 | stmt = new BranchStmt( get<Expression>().accept1( node->computedTarget ), |
---|
| 466 | BranchStmt::Goto ); |
---|
| 467 | } else { |
---|
| 468 | BranchStmt::Type type; |
---|
| 469 | switch (node->kind) { |
---|
| 470 | #define CASE(n) \ |
---|
| 471 | case ast::BranchStmt::n: \ |
---|
| 472 | type = BranchStmt::n; \ |
---|
| 473 | break |
---|
| 474 | CASE(Goto); |
---|
| 475 | CASE(Break); |
---|
| 476 | CASE(Continue); |
---|
| 477 | CASE(FallThrough); |
---|
| 478 | CASE(FallThroughDefault); |
---|
| 479 | #undef CASE |
---|
| 480 | default: |
---|
| 481 | assertf(false, "Invalid ast::BranchStmt::Kind: %d\n", node->kind); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | // The labels here are also weird. |
---|
| 485 | stmt = new BranchStmt( makeLabel( nullptr, node->originalTarget ), type ); |
---|
| 486 | stmt->target = makeLabel( stmt, node->target ); |
---|
| 487 | } |
---|
[112fe04] | 488 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 489 | } |
---|
| 490 | |
---|
| 491 | const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { |
---|
[4073b16] | 492 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 493 | auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); |
---|
[112fe04] | 494 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 495 | } |
---|
| 496 | |
---|
| 497 | const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { |
---|
[4073b16] | 498 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 499 | ThrowStmt::Kind kind; |
---|
| 500 | switch (node->kind) { |
---|
[6f4b7f2] | 501 | case ast::ExceptionKind::Terminate: |
---|
[675d816] | 502 | kind = ThrowStmt::Terminate; |
---|
| 503 | break; |
---|
[6f4b7f2] | 504 | case ast::ExceptionKind::Resume: |
---|
[675d816] | 505 | kind = ThrowStmt::Resume; |
---|
| 506 | break; |
---|
| 507 | default: |
---|
| 508 | assertf(false, "Invalid ast::ThrowStmt::Kind: %d\n", node->kind); |
---|
| 509 | } |
---|
| 510 | auto stmt = new ThrowStmt( |
---|
| 511 | kind, |
---|
| 512 | get<Expression>().accept1( node->expr ), |
---|
| 513 | get<Expression>().accept1( node->target ) |
---|
| 514 | ); |
---|
[112fe04] | 515 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 516 | } |
---|
| 517 | |
---|
| 518 | const ast::Stmt * visit( const ast::TryStmt * node ) override final { |
---|
[4073b16] | 519 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 520 | auto handlers = get<CatchStmt>().acceptL( node->handlers ); |
---|
| 521 | auto stmt = new TryStmt( |
---|
| 522 | get<CompoundStmt>().accept1( node->body ), |
---|
| 523 | handlers, |
---|
| 524 | get<FinallyStmt>().accept1( node->finally ) |
---|
| 525 | ); |
---|
[112fe04] | 526 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 527 | } |
---|
| 528 | |
---|
[400b8be] | 529 | const ast::CatchClause * visit( const ast::CatchClause * node ) override final { |
---|
[4073b16] | 530 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 531 | CatchStmt::Kind kind; |
---|
| 532 | switch (node->kind) { |
---|
[6f4b7f2] | 533 | case ast::ExceptionKind::Terminate: |
---|
[675d816] | 534 | kind = CatchStmt::Terminate; |
---|
| 535 | break; |
---|
[6f4b7f2] | 536 | case ast::ExceptionKind::Resume: |
---|
[675d816] | 537 | kind = CatchStmt::Resume; |
---|
| 538 | break; |
---|
| 539 | default: |
---|
[400b8be] | 540 | assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind); |
---|
[675d816] | 541 | } |
---|
| 542 | auto stmt = new CatchStmt( |
---|
| 543 | kind, |
---|
| 544 | get<Declaration>().accept1( node->decl ), |
---|
| 545 | get<Expression>().accept1( node->cond ), |
---|
| 546 | get<Statement>().accept1( node->body ) |
---|
| 547 | ); |
---|
[400b8be] | 548 | return clausePostamble( stmt, node ), nullptr; |
---|
[74dbbf6] | 549 | } |
---|
| 550 | |
---|
[400b8be] | 551 | const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final { |
---|
[4073b16] | 552 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 553 | auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); |
---|
[400b8be] | 554 | return clausePostamble( stmt, node ), nullptr; |
---|
[74dbbf6] | 555 | } |
---|
| 556 | |
---|
[37cdd97] | 557 | const ast::Stmt * visit(const ast::SuspendStmt * node ) override final { |
---|
| 558 | if ( inCache( node ) ) return nullptr; |
---|
| 559 | auto stmt = new SuspendStmt(); |
---|
| 560 | stmt->then = get<CompoundStmt>().accept1( node->then ); |
---|
[835d6e8] | 561 | switch (node->kind) { |
---|
[37cdd97] | 562 | case ast::SuspendStmt::None : stmt->type = SuspendStmt::None ; break; |
---|
| 563 | case ast::SuspendStmt::Coroutine: stmt->type = SuspendStmt::Coroutine; break; |
---|
| 564 | case ast::SuspendStmt::Generator: stmt->type = SuspendStmt::Generator; break; |
---|
| 565 | } |
---|
| 566 | return stmtPostamble( stmt, node ); |
---|
| 567 | } |
---|
| 568 | |
---|
[c86b08d] | 569 | const ast::WhenClause * visit( const ast::WhenClause * node ) override final { |
---|
| 570 | // There is no old-AST WhenClause, so this should never be called. |
---|
| 571 | assert( !node ); |
---|
| 572 | return nullptr; |
---|
| 573 | } |
---|
| 574 | |
---|
[74dbbf6] | 575 | const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { |
---|
[4073b16] | 576 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 577 | auto stmt = new WaitForStmt; |
---|
| 578 | stmt->clauses.reserve( node->clauses.size() ); |
---|
| 579 | for ( auto clause : node->clauses ) { |
---|
| 580 | stmt->clauses.push_back({{ |
---|
[c86b08d] | 581 | get<Expression>().accept1( clause->target ), |
---|
[f6e6a55] | 582 | get<Expression>().acceptL( clause->target_args ), |
---|
[675d816] | 583 | }, |
---|
[f6e6a55] | 584 | get<Statement>().accept1( clause->stmt ), |
---|
[c86b08d] | 585 | get<Expression>().accept1( clause->when_cond ), |
---|
[675d816] | 586 | }); |
---|
| 587 | } |
---|
| 588 | stmt->timeout = { |
---|
[f6e6a55] | 589 | get<Expression>().accept1( node->timeout_time ), |
---|
| 590 | get<Statement>().accept1( node->timeout_stmt ), |
---|
| 591 | get<Expression>().accept1( node->timeout_cond ), |
---|
[675d816] | 592 | }; |
---|
| 593 | stmt->orelse = { |
---|
[f6e6a55] | 594 | get<Statement>().accept1( node->else_stmt ), |
---|
| 595 | get<Expression>().accept1( node->else_cond ), |
---|
[675d816] | 596 | }; |
---|
[112fe04] | 597 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 598 | } |
---|
| 599 | |
---|
[f6e6a55] | 600 | const ast::WaitForClause * visit( const ast::WaitForClause * node ) override final { |
---|
| 601 | // There is no old-AST WaitForClause, so this should never be called. |
---|
| 602 | assert( !node ); |
---|
| 603 | return nullptr; |
---|
| 604 | } |
---|
| 605 | |
---|
[c86b08d] | 606 | const ast::Stmt * visit( const ast::WaitUntilStmt * node ) override final { |
---|
| 607 | // There is no old-AST WaitUntilStmt, so this should never be called. |
---|
| 608 | assert( !node ); |
---|
| 609 | return nullptr; |
---|
| 610 | } |
---|
| 611 | |
---|
[e67991f] | 612 | const ast::Decl * visit( const ast::WithStmt * node ) override final { |
---|
[4073b16] | 613 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 614 | auto stmt = new WithStmt( |
---|
| 615 | get<Expression>().acceptL( node->exprs ), |
---|
| 616 | get<Statement>().accept1( node->stmt ) |
---|
| 617 | ); |
---|
[e67991f] | 618 | declPostamble( stmt, node ); |
---|
| 619 | return nullptr; |
---|
[74dbbf6] | 620 | } |
---|
| 621 | |
---|
| 622 | const ast::NullStmt * visit( const ast::NullStmt * node ) override final { |
---|
[4073b16] | 623 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 624 | auto stmt = new NullStmt(); |
---|
[112fe04] | 625 | stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 626 | return nullptr; |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | const ast::Stmt * visit( const ast::DeclStmt * node ) override final { |
---|
[4073b16] | 630 | if ( inCache( node ) ) return nullptr; |
---|
[675d816] | 631 | auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); |
---|
[112fe04] | 632 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 633 | } |
---|
| 634 | |
---|
| 635 | const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { |
---|
[4073b16] | 636 | if ( inCache( node ) ) return nullptr; |
---|
| 637 | auto stmt = new ImplicitCtorDtorStmt{ |
---|
| 638 | get<Statement>().accept1( node->callStmt ) |
---|
| 639 | }; |
---|
| 640 | return stmtPostamble( stmt, node ); |
---|
[74dbbf6] | 641 | } |
---|
| 642 | |
---|
[6cebfef] | 643 | const ast::Stmt * visit( const ast::MutexStmt * node ) override final { |
---|
| 644 | if ( inCache( node ) ) return nullptr; |
---|
| 645 | auto stmt = new MutexStmt( |
---|
| 646 | get<Statement>().accept1( node->stmt ), |
---|
| 647 | get<Expression>().acceptL( node->mutexObjs ) |
---|
| 648 | ); |
---|
| 649 | return stmtPostamble( stmt, node ); |
---|
| 650 | } |
---|
| 651 | |
---|
[19e567dd] | 652 | TypeSubstitution * convertTypeSubstitution(const ast::TypeSubstitution * src) { |
---|
| 653 | |
---|
[f685679] | 654 | if (!src) return nullptr; |
---|
| 655 | |
---|
[19e567dd] | 656 | TypeSubstitution *rslt = new TypeSubstitution(); |
---|
| 657 | |
---|
| 658 | for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) { |
---|
[3e5dd913] | 659 | rslt->add( src_i->first.typeString(), |
---|
[19e567dd] | 660 | get<Type>().accept1(src_i->second) ); |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | return rslt; |
---|
| 664 | } |
---|
| 665 | |
---|
| 666 | void convertInferUnion(std::map<UniqueId,ParamEntry> &tgtInferParams, |
---|
| 667 | std::vector<UniqueId> &tgtResnSlots, |
---|
| 668 | const ast::Expr::InferUnion &srcInferred ) { |
---|
| 669 | |
---|
| 670 | assert( tgtInferParams.empty() ); |
---|
| 671 | assert( tgtResnSlots.empty() ); |
---|
| 672 | |
---|
[07d867b] | 673 | if ( srcInferred.data.inferParams ) { |
---|
[60aaa51d] | 674 | const ast::InferredParams &srcParams = srcInferred.inferParams(); |
---|
[8b34df0] | 675 | for (auto & srcParam : srcParams) { |
---|
| 676 | auto res = tgtInferParams.emplace(srcParam.first, ParamEntry( |
---|
[19e567dd] | 677 | srcParam.second.decl, |
---|
[07d867b] | 678 | get<Declaration>().accept1(srcParam.second.declptr), |
---|
| 679 | get<Type>().accept1(srcParam.second.actualType)->clone(), |
---|
| 680 | get<Type>().accept1(srcParam.second.formalType)->clone(), |
---|
| 681 | get<Expression>().accept1(srcParam.second.expr)->clone() |
---|
[8b34df0] | 682 | )); |
---|
| 683 | assert(res.second); |
---|
[19e567dd] | 684 | } |
---|
[07d867b] | 685 | } |
---|
| 686 | if ( srcInferred.data.resnSlots ) { |
---|
[60aaa51d] | 687 | const ast::ResnSlots &srcSlots = srcInferred.resnSlots(); |
---|
[19e567dd] | 688 | for (auto srcSlot : srcSlots) { |
---|
| 689 | tgtResnSlots.push_back(srcSlot); |
---|
| 690 | } |
---|
| 691 | } |
---|
| 692 | } |
---|
| 693 | |
---|
[20de6fb] | 694 | Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) { |
---|
[19e567dd] | 695 | |
---|
[20de6fb] | 696 | tgt->location = src->location; |
---|
| 697 | tgt->env = convertTypeSubstitution(src->env); |
---|
[19e567dd] | 698 | tgt->extension = src->extension; |
---|
| 699 | |
---|
[20de6fb] | 700 | convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); |
---|
[19e567dd] | 701 | return tgt; |
---|
| 702 | } |
---|
| 703 | |
---|
[20de6fb] | 704 | Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { |
---|
| 705 | |
---|
| 706 | tgt->result = get<Type>().accept1(src->result); |
---|
[f6cc734e] | 707 | // Unconditionally use a clone of the result type. |
---|
| 708 | // We know this will leak some objects: much of the immediate conversion result. |
---|
| 709 | // In some cases, using the conversion result directly gives unintended object sharing. |
---|
| 710 | // A parameter (ObjectDecl, a child of a FunctionType) is shared by the weak-ref cache. |
---|
| 711 | // But tgt->result must be fully owned privately by tgt. |
---|
| 712 | // Applying these conservative copies here means |
---|
| 713 | // - weak references point at the declaration's copy, not these expr.result copies (good) |
---|
| 714 | // - we copy more objects than really needed (bad, tolerated) |
---|
| 715 | if (tgt->result) { |
---|
| 716 | tgt->result = tgt->result->clone(); |
---|
| 717 | } |
---|
[20de6fb] | 718 | return visitBaseExpr_skipResultType(src, tgt); |
---|
| 719 | } |
---|
| 720 | |
---|
[74dbbf6] | 721 | const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { |
---|
[19e567dd] | 722 | auto expr = visitBaseExpr( node, |
---|
| 723 | new ApplicationExpr( |
---|
| 724 | get<Expression>().accept1(node->func), |
---|
| 725 | get<Expression>().acceptL(node->args) |
---|
| 726 | ) |
---|
| 727 | ); |
---|
| 728 | this->node = expr; |
---|
[74dbbf6] | 729 | return nullptr; |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | const ast::Expr * visit( const ast::UntypedExpr * node ) override final { |
---|
[19e567dd] | 733 | auto expr = visitBaseExpr( node, |
---|
| 734 | new UntypedExpr( |
---|
| 735 | get<Expression>().accept1(node->func), |
---|
| 736 | get<Expression>().acceptL(node->args) |
---|
| 737 | ) |
---|
| 738 | ); |
---|
| 739 | this->node = expr; |
---|
[74dbbf6] | 740 | return nullptr; |
---|
| 741 | } |
---|
| 742 | |
---|
| 743 | const ast::Expr * visit( const ast::NameExpr * node ) override final { |
---|
[19e567dd] | 744 | auto expr = visitBaseExpr( node, |
---|
| 745 | new NameExpr( |
---|
| 746 | node->name |
---|
| 747 | ) |
---|
| 748 | ); |
---|
| 749 | this->node = expr; |
---|
[74dbbf6] | 750 | return nullptr; |
---|
| 751 | } |
---|
| 752 | |
---|
[b0d9ff7] | 753 | const ast::Expr * visit( const ast::QualifiedNameExpr * node ) override final { |
---|
| 754 | auto temp = new QualifiedNameExpr( |
---|
| 755 | get<Declaration>().accept1(node->type_decl), |
---|
| 756 | node->name |
---|
| 757 | ); |
---|
| 758 | auto expr = visitBaseExpr( node, |
---|
| 759 | temp |
---|
| 760 | ); |
---|
| 761 | this->node = expr; |
---|
| 762 | return nullptr; |
---|
| 763 | } |
---|
| 764 | |
---|
[74dbbf6] | 765 | const ast::Expr * visit( const ast::AddressExpr * node ) override final { |
---|
[28c89f4] | 766 | auto expr = visitBaseExpr( node, |
---|
| 767 | new AddressExpr( |
---|
| 768 | get<Expression>().accept1(node->arg) |
---|
| 769 | ) |
---|
| 770 | ); |
---|
| 771 | this->node = expr; |
---|
[74dbbf6] | 772 | return nullptr; |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { |
---|
[28c89f4] | 776 | auto expr = visitBaseExpr( node, |
---|
| 777 | new LabelAddressExpr( |
---|
| 778 | makeLabel(nullptr, node->arg) |
---|
| 779 | ) |
---|
| 780 | ); |
---|
| 781 | this->node = expr; |
---|
[74dbbf6] | 782 | return nullptr; |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | const ast::Expr * visit( const ast::CastExpr * node ) override final { |
---|
[28c89f4] | 786 | auto expr = visitBaseExpr( node, |
---|
| 787 | new CastExpr( |
---|
| 788 | get<Expression>().accept1(node->arg), |
---|
| 789 | (node->isGenerated == ast::GeneratedCast) |
---|
| 790 | ) |
---|
| 791 | ); |
---|
| 792 | this->node = expr; |
---|
[74dbbf6] | 793 | return nullptr; |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { |
---|
[312029a] | 797 | AggregateDecl::Aggregate castTarget = (AggregateDecl::Aggregate)node->target; |
---|
| 798 | assert( AggregateDecl::Generator <= castTarget && castTarget <= AggregateDecl::Thread ); |
---|
[28c89f4] | 799 | auto expr = visitBaseExpr( node, |
---|
| 800 | new KeywordCastExpr( |
---|
| 801 | get<Expression>().accept1(node->arg), |
---|
[4ef08f7] | 802 | castTarget, |
---|
| 803 | {node->concrete_target.field, node->concrete_target.getter} |
---|
[28c89f4] | 804 | ) |
---|
| 805 | ); |
---|
| 806 | this->node = expr; |
---|
[74dbbf6] | 807 | return nullptr; |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { |
---|
[20de6fb] | 811 | auto expr = visitBaseExpr_skipResultType( node, |
---|
[28c89f4] | 812 | new VirtualCastExpr( |
---|
| 813 | get<Expression>().accept1(node->arg), |
---|
[20de6fb] | 814 | get<Type>().accept1(node->result) |
---|
[28c89f4] | 815 | ) |
---|
| 816 | ); |
---|
| 817 | this->node = expr; |
---|
[74dbbf6] | 818 | return nullptr; |
---|
| 819 | } |
---|
| 820 | |
---|
| 821 | const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { |
---|
[28c89f4] | 822 | auto expr = visitBaseExpr( node, |
---|
| 823 | new UntypedMemberExpr( |
---|
| 824 | get<Expression>().accept1(node->member), |
---|
| 825 | get<Expression>().accept1(node->aggregate) |
---|
| 826 | ) |
---|
| 827 | ); |
---|
| 828 | this->node = expr; |
---|
[74dbbf6] | 829 | return nullptr; |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | const ast::Expr * visit( const ast::MemberExpr * node ) override final { |
---|
[28c89f4] | 833 | auto expr = visitBaseExpr( node, |
---|
| 834 | new MemberExpr( |
---|
[2a54479] | 835 | get<DeclarationWithType>().accept1(node->member), |
---|
[28c89f4] | 836 | get<Expression>().accept1(node->aggregate) |
---|
| 837 | ) |
---|
| 838 | ); |
---|
| 839 | this->node = expr; |
---|
[74dbbf6] | 840 | return nullptr; |
---|
| 841 | } |
---|
| 842 | |
---|
| 843 | const ast::Expr * visit( const ast::VariableExpr * node ) override final { |
---|
[546e712] | 844 | auto expr = new VariableExpr(); |
---|
| 845 | expr->var = get<DeclarationWithType>().accept1(node->var); |
---|
[6896548] | 846 | visitBaseExpr( node, expr ); |
---|
[28c89f4] | 847 | this->node = expr; |
---|
[74dbbf6] | 848 | return nullptr; |
---|
| 849 | } |
---|
| 850 | |
---|
| 851 | const ast::Expr * visit( const ast::ConstantExpr * node ) override final { |
---|
[c36298d] | 852 | // Old world: two types: rslt->constant.type, rslt->result |
---|
| 853 | // New workd: one public type: node->result, plus node->underlyer only to support roundtrip conversion |
---|
| 854 | // preserving underlyer because the correct type for string literals is complicated to construct, |
---|
| 855 | // and distinguishing a string from other literals using the type is hard to do accurately |
---|
| 856 | // Both worlds: the outer, expression-level type can change during resolution |
---|
| 857 | // for a string, that's char[k] before-resolve and char * after |
---|
| 858 | // Old world: the inner Constant type stays what it was built with |
---|
| 859 | // for a string, that's char[k] always |
---|
| 860 | // Both worlds: the "rep" field of a constant is the C source file fragment that compiles to the desired value |
---|
| 861 | // for a string, that includes outer quotes, backslashes, et al cases from the Literals test |
---|
| 862 | ConstantExpr *rslt = new ConstantExpr(Constant( |
---|
| 863 | get<Type>().accept1(node->underlyer), |
---|
| 864 | node->rep, |
---|
| 865 | node->ival)); |
---|
[28c89f4] | 866 | auto expr = visitBaseExpr( node, rslt ); |
---|
| 867 | this->node = expr; |
---|
[74dbbf6] | 868 | return nullptr; |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | const ast::Expr * visit( const ast::SizeofExpr * node ) override final { |
---|
[28c89f4] | 872 | assert (node->expr || node->type); |
---|
| 873 | assert (! (node->expr && node->type)); |
---|
| 874 | SizeofExpr *rslt; |
---|
| 875 | if (node->expr) { |
---|
| 876 | rslt = new SizeofExpr( |
---|
| 877 | get<Expression>().accept1(node->expr) |
---|
| 878 | ); |
---|
| 879 | assert (!rslt->isType); |
---|
| 880 | } |
---|
[0b73f0c] | 881 | else { |
---|
| 882 | assert(node->type); |
---|
[28c89f4] | 883 | rslt = new SizeofExpr( |
---|
| 884 | get<Type>().accept1(node->type) |
---|
| 885 | ); |
---|
| 886 | assert (rslt->isType); |
---|
| 887 | } |
---|
| 888 | auto expr = visitBaseExpr( node, rslt ); |
---|
| 889 | this->node = expr; |
---|
[74dbbf6] | 890 | return nullptr; |
---|
| 891 | } |
---|
| 892 | |
---|
| 893 | const ast::Expr * visit( const ast::AlignofExpr * node ) override final { |
---|
[28c89f4] | 894 | assert (node->expr || node->type); |
---|
| 895 | assert (! (node->expr && node->type)); |
---|
| 896 | AlignofExpr *rslt; |
---|
| 897 | if (node->expr) { |
---|
| 898 | rslt = new AlignofExpr( |
---|
| 899 | get<Expression>().accept1(node->expr) |
---|
| 900 | ); |
---|
| 901 | assert (!rslt->isType); |
---|
| 902 | } |
---|
[0b73f0c] | 903 | else { |
---|
| 904 | assert(node->type); |
---|
[28c89f4] | 905 | rslt = new AlignofExpr( |
---|
| 906 | get<Type>().accept1(node->type) |
---|
| 907 | ); |
---|
| 908 | assert (rslt->isType); |
---|
| 909 | } |
---|
| 910 | auto expr = visitBaseExpr( node, rslt ); |
---|
| 911 | this->node = expr; |
---|
[74dbbf6] | 912 | return nullptr; |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { |
---|
[28c89f4] | 916 | auto expr = visitBaseExpr( node, |
---|
| 917 | new UntypedOffsetofExpr( |
---|
| 918 | get<Type>().accept1(node->type), |
---|
| 919 | node->member |
---|
| 920 | ) |
---|
| 921 | ); |
---|
| 922 | this->node = expr; |
---|
[74dbbf6] | 923 | return nullptr; |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { |
---|
[28c89f4] | 927 | auto expr = visitBaseExpr( node, |
---|
| 928 | new OffsetofExpr( |
---|
| 929 | get<Type>().accept1(node->type), |
---|
[2a54479] | 930 | get<DeclarationWithType>().accept1(node->member) |
---|
[28c89f4] | 931 | ) |
---|
| 932 | ); |
---|
| 933 | this->node = expr; |
---|
[74dbbf6] | 934 | return nullptr; |
---|
| 935 | } |
---|
| 936 | |
---|
| 937 | const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { |
---|
[28c89f4] | 938 | auto expr = visitBaseExpr( node, |
---|
| 939 | new OffsetPackExpr( |
---|
| 940 | get<StructInstType>().accept1(node->type) |
---|
| 941 | ) |
---|
| 942 | ); |
---|
| 943 | this->node = expr; |
---|
[74dbbf6] | 944 | return nullptr; |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | const ast::Expr * visit( const ast::LogicalExpr * node ) override final { |
---|
[28c89f4] | 948 | assert (node->isAnd == ast::LogicalFlag::AndExpr || |
---|
| 949 | node->isAnd == ast::LogicalFlag::OrExpr ); |
---|
| 950 | auto expr = visitBaseExpr( node, |
---|
| 951 | new LogicalExpr( |
---|
| 952 | get<Expression>().accept1(node->arg1), |
---|
| 953 | get<Expression>().accept1(node->arg2), |
---|
| 954 | (node->isAnd == ast::LogicalFlag::AndExpr) |
---|
| 955 | ) |
---|
| 956 | ); |
---|
| 957 | this->node = expr; |
---|
[74dbbf6] | 958 | return nullptr; |
---|
| 959 | } |
---|
| 960 | |
---|
| 961 | const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { |
---|
[28c89f4] | 962 | auto expr = visitBaseExpr( node, |
---|
| 963 | new ConditionalExpr( |
---|
| 964 | get<Expression>().accept1(node->arg1), |
---|
| 965 | get<Expression>().accept1(node->arg2), |
---|
| 966 | get<Expression>().accept1(node->arg3) |
---|
| 967 | ) |
---|
| 968 | ); |
---|
| 969 | this->node = expr; |
---|
[74dbbf6] | 970 | return nullptr; |
---|
| 971 | } |
---|
| 972 | |
---|
| 973 | const ast::Expr * visit( const ast::CommaExpr * node ) override final { |
---|
[28c89f4] | 974 | auto expr = visitBaseExpr( node, |
---|
| 975 | new CommaExpr( |
---|
| 976 | get<Expression>().accept1(node->arg1), |
---|
| 977 | get<Expression>().accept1(node->arg2) |
---|
| 978 | ) |
---|
| 979 | ); |
---|
| 980 | this->node = expr; |
---|
[74dbbf6] | 981 | return nullptr; |
---|
| 982 | } |
---|
| 983 | |
---|
| 984 | const ast::Expr * visit( const ast::TypeExpr * node ) override final { |
---|
[20de6fb] | 985 | auto expr = visitBaseExpr( node, |
---|
| 986 | new TypeExpr( |
---|
| 987 | get<Type>().accept1(node->type) |
---|
| 988 | ) |
---|
| 989 | ); |
---|
| 990 | this->node = expr; |
---|
[74dbbf6] | 991 | return nullptr; |
---|
| 992 | } |
---|
| 993 | |
---|
[4ec9513] | 994 | const ast::Expr * visit( const ast::DimensionExpr * node ) override final { |
---|
| 995 | auto expr = visitBaseExpr( node, new DimensionExpr( node->name ) ); |
---|
| 996 | this->node = expr; |
---|
| 997 | return nullptr; |
---|
| 998 | } |
---|
| 999 | |
---|
[74dbbf6] | 1000 | const ast::Expr * visit( const ast::AsmExpr * node ) override final { |
---|
[20de6fb] | 1001 | auto expr = visitBaseExpr( node, |
---|
| 1002 | new AsmExpr( |
---|
[665f432] | 1003 | new std::string(node->inout), |
---|
[20de6fb] | 1004 | get<Expression>().accept1(node->constraint), |
---|
| 1005 | get<Expression>().accept1(node->operand) |
---|
| 1006 | ) |
---|
| 1007 | ); |
---|
| 1008 | this->node = expr; |
---|
[74dbbf6] | 1009 | return nullptr; |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { |
---|
[20de6fb] | 1013 | auto rslt = new ImplicitCopyCtorExpr( |
---|
| 1014 | get<ApplicationExpr>().accept1(node->callExpr) |
---|
| 1015 | ); |
---|
| 1016 | |
---|
| 1017 | auto expr = visitBaseExpr( node, rslt ); |
---|
| 1018 | this->node = expr; |
---|
[74dbbf6] | 1019 | return nullptr; |
---|
| 1020 | } |
---|
| 1021 | |
---|
| 1022 | const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { |
---|
[20de6fb] | 1023 | auto expr = visitBaseExpr( node, |
---|
| 1024 | new ConstructorExpr( |
---|
| 1025 | get<Expression>().accept1(node->callExpr) |
---|
| 1026 | ) |
---|
| 1027 | ); |
---|
| 1028 | this->node = expr; |
---|
[74dbbf6] | 1029 | return nullptr; |
---|
| 1030 | } |
---|
| 1031 | |
---|
| 1032 | const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { |
---|
[20de6fb] | 1033 | auto expr = visitBaseExpr_skipResultType( node, |
---|
| 1034 | new CompoundLiteralExpr( |
---|
| 1035 | get<Type>().accept1(node->result), |
---|
| 1036 | get<Initializer>().accept1(node->init) |
---|
| 1037 | ) |
---|
| 1038 | ); |
---|
| 1039 | this->node = expr; |
---|
[74dbbf6] | 1040 | return nullptr; |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | const ast::Expr * visit( const ast::RangeExpr * node ) override final { |
---|
[20de6fb] | 1044 | auto expr = visitBaseExpr( node, |
---|
| 1045 | new RangeExpr( |
---|
| 1046 | get<Expression>().accept1(node->low), |
---|
| 1047 | get<Expression>().accept1(node->high) |
---|
| 1048 | ) |
---|
| 1049 | ); |
---|
| 1050 | this->node = expr; |
---|
[74dbbf6] | 1051 | return nullptr; |
---|
| 1052 | } |
---|
| 1053 | |
---|
| 1054 | const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { |
---|
[20de6fb] | 1055 | auto expr = visitBaseExpr( node, |
---|
| 1056 | new UntypedTupleExpr( |
---|
| 1057 | get<Expression>().acceptL(node->exprs) |
---|
| 1058 | ) |
---|
| 1059 | ); |
---|
| 1060 | this->node = expr; |
---|
[74dbbf6] | 1061 | return nullptr; |
---|
| 1062 | } |
---|
| 1063 | |
---|
| 1064 | const ast::Expr * visit( const ast::TupleExpr * node ) override final { |
---|
[20de6fb] | 1065 | auto expr = visitBaseExpr( node, |
---|
[6e55240] | 1066 | new TupleExpr( |
---|
[20de6fb] | 1067 | get<Expression>().acceptL(node->exprs) |
---|
| 1068 | ) |
---|
| 1069 | ); |
---|
| 1070 | this->node = expr; |
---|
[74dbbf6] | 1071 | return nullptr; |
---|
| 1072 | } |
---|
| 1073 | |
---|
| 1074 | const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { |
---|
[20de6fb] | 1075 | auto expr = visitBaseExpr( node, |
---|
| 1076 | new TupleIndexExpr( |
---|
| 1077 | get<Expression>().accept1(node->tuple), |
---|
| 1078 | node->index |
---|
| 1079 | ) |
---|
| 1080 | ); |
---|
| 1081 | this->node = expr; |
---|
[74dbbf6] | 1082 | return nullptr; |
---|
| 1083 | } |
---|
| 1084 | |
---|
| 1085 | const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { |
---|
[20de6fb] | 1086 | auto expr = visitBaseExpr( node, |
---|
| 1087 | new TupleAssignExpr( |
---|
| 1088 | get<StmtExpr>().accept1(node->stmtExpr) |
---|
| 1089 | ) |
---|
| 1090 | ); |
---|
| 1091 | this->node = expr; |
---|
[74dbbf6] | 1092 | return nullptr; |
---|
| 1093 | } |
---|
| 1094 | |
---|
| 1095 | const ast::Expr * visit( const ast::StmtExpr * node ) override final { |
---|
[20de6fb] | 1096 | auto rslt = new StmtExpr( |
---|
[bb9924c] | 1097 | get<CompoundStmt>().accept1(node->stmts) |
---|
[20de6fb] | 1098 | ); |
---|
| 1099 | |
---|
| 1100 | rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); |
---|
| 1101 | rslt->dtors = get<Expression>().acceptL(node->dtors); |
---|
[bb9924c] | 1102 | |
---|
| 1103 | // is this even used after convert? |
---|
| 1104 | //if (tmp->resultExpr) { |
---|
| 1105 | // // this MUST be found by children visit |
---|
| 1106 | // rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(tmp->resultExpr)); |
---|
| 1107 | //} |
---|
[20de6fb] | 1108 | |
---|
| 1109 | auto expr = visitBaseExpr( node, rslt ); |
---|
| 1110 | this->node = expr; |
---|
[74dbbf6] | 1111 | return nullptr; |
---|
| 1112 | } |
---|
| 1113 | |
---|
| 1114 | const ast::Expr * visit( const ast::UniqueExpr * node ) override final { |
---|
[20de6fb] | 1115 | auto rslt = new UniqueExpr( |
---|
[a2a85658] | 1116 | get<Expression>().accept1(node->expr), |
---|
| 1117 | node->id |
---|
[20de6fb] | 1118 | ); |
---|
| 1119 | |
---|
| 1120 | rslt->object = get<ObjectDecl> ().accept1(node->object); |
---|
| 1121 | rslt->var = get<VariableExpr>().accept1(node->var); |
---|
| 1122 | |
---|
| 1123 | auto expr = visitBaseExpr( node, rslt ); |
---|
[490fb92e] | 1124 | this->node = expr->clone(); |
---|
[74dbbf6] | 1125 | return nullptr; |
---|
| 1126 | } |
---|
| 1127 | |
---|
| 1128 | const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { |
---|
[20de6fb] | 1129 | std::list<InitAlternative> initAlts; |
---|
| 1130 | for (auto ia : node->initAlts) { |
---|
| 1131 | initAlts.push_back(InitAlternative( |
---|
| 1132 | get<Type> ().accept1(ia.type), |
---|
| 1133 | get<Designation>().accept1(ia.designation) |
---|
| 1134 | )); |
---|
| 1135 | } |
---|
| 1136 | auto expr = visitBaseExpr( node, |
---|
| 1137 | new UntypedInitExpr( |
---|
| 1138 | get<Expression>().accept1(node->expr), |
---|
| 1139 | initAlts |
---|
| 1140 | ) |
---|
| 1141 | ); |
---|
| 1142 | this->node = expr; |
---|
[74dbbf6] | 1143 | return nullptr; |
---|
| 1144 | } |
---|
| 1145 | |
---|
| 1146 | const ast::Expr * visit( const ast::InitExpr * node ) override final { |
---|
[20de6fb] | 1147 | auto expr = visitBaseExpr( node, |
---|
| 1148 | new InitExpr( |
---|
| 1149 | get<Expression>().accept1(node->expr), |
---|
| 1150 | get<Designation>().accept1(node->designation) |
---|
| 1151 | ) |
---|
| 1152 | ); |
---|
| 1153 | this->node = expr; |
---|
[74dbbf6] | 1154 | return nullptr; |
---|
| 1155 | } |
---|
| 1156 | |
---|
| 1157 | const ast::Expr * visit( const ast::DeletedExpr * node ) override final { |
---|
[20de6fb] | 1158 | auto expr = visitBaseExpr( node, |
---|
| 1159 | new DeletedExpr( |
---|
| 1160 | get<Expression>().accept1(node->expr), |
---|
| 1161 | inCache(node->deleteStmt) ? |
---|
[e67991f] | 1162 | strict_dynamic_cast<Declaration*>(this->node) : |
---|
| 1163 | get<Declaration>().accept1(node->deleteStmt) |
---|
[20de6fb] | 1164 | ) |
---|
| 1165 | ); |
---|
| 1166 | this->node = expr; |
---|
[74dbbf6] | 1167 | return nullptr; |
---|
| 1168 | } |
---|
| 1169 | |
---|
| 1170 | const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { |
---|
[20de6fb] | 1171 | auto expr = visitBaseExpr( node, |
---|
| 1172 | new DefaultArgExpr( |
---|
| 1173 | get<Expression>().accept1(node->expr) |
---|
| 1174 | ) |
---|
| 1175 | ); |
---|
| 1176 | this->node = expr; |
---|
[74dbbf6] | 1177 | return nullptr; |
---|
| 1178 | } |
---|
| 1179 | |
---|
| 1180 | const ast::Expr * visit( const ast::GenericExpr * node ) override final { |
---|
[20de6fb] | 1181 | std::list<GenericExpr::Association> associations; |
---|
| 1182 | for (auto association : node->associations) { |
---|
| 1183 | associations.push_back(GenericExpr::Association( |
---|
| 1184 | get<Type> ().accept1(association.type), |
---|
| 1185 | get<Expression>().accept1(association.expr) |
---|
| 1186 | )); |
---|
| 1187 | } |
---|
| 1188 | auto expr = visitBaseExpr( node, |
---|
| 1189 | new GenericExpr( |
---|
| 1190 | get<Expression>().accept1(node->control), |
---|
| 1191 | associations |
---|
| 1192 | ) |
---|
| 1193 | ); |
---|
| 1194 | this->node = expr; |
---|
[74dbbf6] | 1195 | return nullptr; |
---|
| 1196 | } |
---|
| 1197 | |
---|
[1ae47de] | 1198 | const ast::Type * visitType( const ast::Type * node, Type * type ) { |
---|
| 1199 | // Some types do this in their constructor so add a check. |
---|
| 1200 | if ( !node->attributes.empty() && type->attributes.empty() ) { |
---|
| 1201 | type->attributes = get<Attribute>().acceptL( node->attributes ); |
---|
| 1202 | } |
---|
| 1203 | this->node = type; |
---|
[74dbbf6] | 1204 | return nullptr; |
---|
| 1205 | } |
---|
| 1206 | |
---|
[1ae47de] | 1207 | const ast::Type * visit( const ast::VoidType * node ) override final { |
---|
| 1208 | return visitType( node, new VoidType{ cv( node ) } ); |
---|
| 1209 | } |
---|
| 1210 | |
---|
[74dbbf6] | 1211 | const ast::Type * visit( const ast::BasicType * node ) override final { |
---|
[2a54479] | 1212 | auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind }; |
---|
| 1213 | // I believe this should always be a BasicType. |
---|
[490fb92e] | 1214 | if ( ast::sizeType == node ) { |
---|
[2a54479] | 1215 | Validate::SizeType = type; |
---|
| 1216 | } |
---|
[1ae47de] | 1217 | return visitType( node, type ); |
---|
[74dbbf6] | 1218 | } |
---|
| 1219 | |
---|
| 1220 | const ast::Type * visit( const ast::PointerType * node ) override final { |
---|
[1ae47de] | 1221 | return visitType( node, new PointerType{ |
---|
[d148778] | 1222 | cv( node ), |
---|
| 1223 | get<Type>().accept1( node->base ), |
---|
| 1224 | get<Expression>().accept1( node->dimension ), |
---|
[746ae82] | 1225 | (bool)node->isVarLen, |
---|
| 1226 | (bool)node->isStatic |
---|
[1ae47de] | 1227 | } ); |
---|
[74dbbf6] | 1228 | } |
---|
| 1229 | |
---|
| 1230 | const ast::Type * visit( const ast::ArrayType * node ) override final { |
---|
[1ae47de] | 1231 | return visitType( node, new ArrayType{ |
---|
[d148778] | 1232 | cv( node ), |
---|
| 1233 | get<Type>().accept1( node->base ), |
---|
| 1234 | get<Expression>().accept1( node->dimension ), |
---|
[746ae82] | 1235 | (bool)node->isVarLen, |
---|
| 1236 | (bool)node->isStatic |
---|
[1ae47de] | 1237 | } ); |
---|
[74dbbf6] | 1238 | } |
---|
| 1239 | |
---|
| 1240 | const ast::Type * visit( const ast::ReferenceType * node ) override final { |
---|
[1ae47de] | 1241 | return visitType( node, new ReferenceType{ |
---|
[d148778] | 1242 | cv( node ), |
---|
| 1243 | get<Type>().accept1( node->base ) |
---|
[1ae47de] | 1244 | } ); |
---|
[74dbbf6] | 1245 | } |
---|
| 1246 | |
---|
| 1247 | const ast::Type * visit( const ast::QualifiedType * node ) override final { |
---|
[1ae47de] | 1248 | return visitType( node, new QualifiedType{ |
---|
[d148778] | 1249 | cv( node ), |
---|
| 1250 | get<Type>().accept1( node->parent ), |
---|
| 1251 | get<Type>().accept1( node->child ) |
---|
[1ae47de] | 1252 | } ); |
---|
[74dbbf6] | 1253 | } |
---|
| 1254 | |
---|
| 1255 | const ast::Type * visit( const ast::FunctionType * node ) override final { |
---|
[954c954] | 1256 | static std::string dummy_paramvar_prefix = "__param_"; |
---|
| 1257 | static std::string dummy_returnvar_prefix = "__retval_"; |
---|
| 1258 | |
---|
[746ae82] | 1259 | auto ty = new FunctionType { |
---|
[0b57626] | 1260 | cv( node ), |
---|
[746ae82] | 1261 | (bool)node->isVarArgs |
---|
| 1262 | }; |
---|
[954c954] | 1263 | auto returns = get<Type>().acceptL(node->returns); |
---|
| 1264 | auto params = get<Type>().acceptL(node->params); |
---|
| 1265 | |
---|
| 1266 | int ret_index = 0; |
---|
| 1267 | for (auto t: returns) { |
---|
| 1268 | // xxx - LinkageSpec shouldn't matter but needs to be something |
---|
| 1269 | ObjectDecl * dummy = new ObjectDecl(dummy_returnvar_prefix + std::to_string(ret_index++), {}, LinkageSpec::C, nullptr, t, nullptr); |
---|
| 1270 | ty->returnVals.push_back(dummy); |
---|
| 1271 | } |
---|
| 1272 | int param_index = 0; |
---|
| 1273 | for (auto t: params) { |
---|
| 1274 | ObjectDecl * dummy = new ObjectDecl(dummy_paramvar_prefix + std::to_string(param_index++), {}, LinkageSpec::C, nullptr, t, nullptr); |
---|
| 1275 | ty->parameters.push_back(dummy); |
---|
| 1276 | } |
---|
| 1277 | |
---|
| 1278 | // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); |
---|
| 1279 | // ty->parameters = get<DeclarationWithType>().acceptL( node->params ); |
---|
[3e5dd913] | 1280 | |
---|
| 1281 | auto types = get<TypeInstType>().acceptL( node->forall ); |
---|
| 1282 | for (auto t : types) { |
---|
| 1283 | auto newT = new TypeDecl(*t->baseType); |
---|
| 1284 | newT->name = t->name; // converted by typeString() |
---|
| 1285 | for (auto asst : newT->assertions) delete asst; |
---|
| 1286 | newT->assertions.clear(); |
---|
| 1287 | ty->forall.push_back(newT); |
---|
| 1288 | } |
---|
| 1289 | auto assts = get<VariableExpr>().acceptL( node->assertions ); |
---|
| 1290 | if (!assts.empty()) { |
---|
| 1291 | assert(!types.empty()); |
---|
| 1292 | for (auto asst : assts) { |
---|
| 1293 | auto newDecl = new ObjectDecl(*strict_dynamic_cast<ObjectDecl*>(asst->var)); |
---|
| 1294 | delete newDecl->type; |
---|
| 1295 | newDecl->type = asst->result->clone(); |
---|
| 1296 | newDecl->storageClasses.is_extern = true; // hack |
---|
| 1297 | ty->forall.back()->assertions.push_back(newDecl); |
---|
| 1298 | } |
---|
| 1299 | } |
---|
| 1300 | |
---|
[1ae47de] | 1301 | return visitType( node, ty ); |
---|
[74dbbf6] | 1302 | } |
---|
| 1303 | |
---|
[98e8b3b] | 1304 | const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) { |
---|
[b869ec5] | 1305 | ty->parameters = get<Expression>().acceptL( old->params ); |
---|
| 1306 | ty->hoistType = old->hoistType; |
---|
[1ae47de] | 1307 | return visitType( old, ty ); |
---|
[b869ec5] | 1308 | } |
---|
| 1309 | |
---|
[74dbbf6] | 1310 | const ast::Type * visit( const ast::StructInstType * node ) override final { |
---|
[b869ec5] | 1311 | StructInstType * ty; |
---|
| 1312 | if ( node->base ) { |
---|
| 1313 | ty = new StructInstType{ |
---|
| 1314 | cv( node ), |
---|
| 1315 | get<StructDecl>().accept1( node->base ), |
---|
| 1316 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1317 | }; |
---|
| 1318 | } else { |
---|
| 1319 | ty = new StructInstType{ |
---|
| 1320 | cv( node ), |
---|
| 1321 | node->name, |
---|
| 1322 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1323 | }; |
---|
| 1324 | } |
---|
[1ae47de] | 1325 | return postvisit( node, ty ); |
---|
[74dbbf6] | 1326 | } |
---|
| 1327 | |
---|
| 1328 | const ast::Type * visit( const ast::UnionInstType * node ) override final { |
---|
[b869ec5] | 1329 | UnionInstType * ty; |
---|
| 1330 | if ( node->base ) { |
---|
| 1331 | ty = new UnionInstType{ |
---|
| 1332 | cv( node ), |
---|
| 1333 | get<UnionDecl>().accept1( node->base ), |
---|
| 1334 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1335 | }; |
---|
| 1336 | } else { |
---|
| 1337 | ty = new UnionInstType{ |
---|
| 1338 | cv( node ), |
---|
| 1339 | node->name, |
---|
| 1340 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1341 | }; |
---|
| 1342 | } |
---|
[1ae47de] | 1343 | return postvisit( node, ty ); |
---|
[74dbbf6] | 1344 | } |
---|
| 1345 | |
---|
| 1346 | const ast::Type * visit( const ast::EnumInstType * node ) override final { |
---|
[b869ec5] | 1347 | EnumInstType * ty; |
---|
| 1348 | if ( node->base ) { |
---|
| 1349 | ty = new EnumInstType{ |
---|
| 1350 | cv( node ), |
---|
| 1351 | get<EnumDecl>().accept1( node->base ), |
---|
| 1352 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1353 | }; |
---|
| 1354 | } else { |
---|
| 1355 | ty = new EnumInstType{ |
---|
| 1356 | cv( node ), |
---|
| 1357 | node->name, |
---|
| 1358 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1359 | }; |
---|
| 1360 | } |
---|
[1ae47de] | 1361 | return postvisit( node, ty ); |
---|
[74dbbf6] | 1362 | } |
---|
| 1363 | |
---|
| 1364 | const ast::Type * visit( const ast::TraitInstType * node ) override final { |
---|
[b869ec5] | 1365 | TraitInstType * ty; |
---|
| 1366 | if ( node->base ) { |
---|
| 1367 | ty = new TraitInstType{ |
---|
| 1368 | cv( node ), |
---|
| 1369 | get<TraitDecl>().accept1( node->base ), |
---|
| 1370 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1371 | }; |
---|
| 1372 | } else { |
---|
| 1373 | ty = new TraitInstType{ |
---|
| 1374 | cv( node ), |
---|
| 1375 | node->name, |
---|
| 1376 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1377 | }; |
---|
| 1378 | } |
---|
[1ae47de] | 1379 | return postvisit( node, ty ); |
---|
[74dbbf6] | 1380 | } |
---|
| 1381 | |
---|
| 1382 | const ast::Type * visit( const ast::TypeInstType * node ) override final { |
---|
[b869ec5] | 1383 | TypeInstType * ty; |
---|
| 1384 | if ( node->base ) { |
---|
| 1385 | ty = new TypeInstType{ |
---|
| 1386 | cv( node ), |
---|
[3e5dd913] | 1387 | node->typeString(), |
---|
[b869ec5] | 1388 | get<TypeDecl>().accept1( node->base ), |
---|
| 1389 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1390 | }; |
---|
| 1391 | } else { |
---|
| 1392 | ty = new TypeInstType{ |
---|
| 1393 | cv( node ), |
---|
[3e5dd913] | 1394 | node->typeString(), |
---|
[07de76b] | 1395 | node->kind == ast::TypeDecl::Ftype, |
---|
[b869ec5] | 1396 | get<Attribute>().acceptL( node->attributes ) |
---|
| 1397 | }; |
---|
| 1398 | } |
---|
[1ae47de] | 1399 | return postvisit( node, ty ); |
---|
[74dbbf6] | 1400 | } |
---|
| 1401 | |
---|
| 1402 | const ast::Type * visit( const ast::TupleType * node ) override final { |
---|
[1ae47de] | 1403 | return visitType( node, new TupleType{ |
---|
[746ae82] | 1404 | cv( node ), |
---|
| 1405 | get<Type>().acceptL( node->types ) |
---|
| 1406 | // members generated by TupleType c'tor |
---|
[1ae47de] | 1407 | } ); |
---|
[74dbbf6] | 1408 | } |
---|
| 1409 | |
---|
| 1410 | const ast::Type * visit( const ast::TypeofType * node ) override final { |
---|
[1ae47de] | 1411 | return visitType( node, new TypeofType{ |
---|
[746ae82] | 1412 | cv( node ), |
---|
| 1413 | get<Expression>().accept1( node->expr ), |
---|
| 1414 | (bool)node->kind |
---|
[1ae47de] | 1415 | } ); |
---|
[74dbbf6] | 1416 | } |
---|
| 1417 | |
---|
[cc64be1d] | 1418 | const ast::Type * visit( const ast::VTableType * node ) override final { |
---|
| 1419 | return visitType( node, new VTableType{ |
---|
| 1420 | cv( node ), |
---|
| 1421 | get<Type>().accept1( node->base ) |
---|
| 1422 | } ); |
---|
| 1423 | } |
---|
| 1424 | |
---|
[74dbbf6] | 1425 | const ast::Type * visit( const ast::VarArgsType * node ) override final { |
---|
[1ae47de] | 1426 | return visitType( node, new VarArgsType{ cv( node ) } ); |
---|
[74dbbf6] | 1427 | } |
---|
| 1428 | |
---|
| 1429 | const ast::Type * visit( const ast::ZeroType * node ) override final { |
---|
[1ae47de] | 1430 | return visitType( node, new ZeroType{ cv( node ) } ); |
---|
[74dbbf6] | 1431 | } |
---|
| 1432 | |
---|
| 1433 | const ast::Type * visit( const ast::OneType * node ) override final { |
---|
[1ae47de] | 1434 | return visitType( node, new OneType{ cv( node ) } ); |
---|
[74dbbf6] | 1435 | } |
---|
| 1436 | |
---|
[1ae47de] | 1437 | const ast::Type * visit( const ast::GlobalScopeType * node ) override final { |
---|
| 1438 | return visitType( node, new GlobalScopeType{} ); |
---|
[74dbbf6] | 1439 | } |
---|
| 1440 | |
---|
| 1441 | const ast::Designation * visit( const ast::Designation * node ) override final { |
---|
[74ad8c0] | 1442 | auto designation = new Designation( get<Expression>().acceptL( node->designators ) ); |
---|
| 1443 | designation->location = node->location; |
---|
| 1444 | this->node = designation; |
---|
[74dbbf6] | 1445 | return nullptr; |
---|
| 1446 | } |
---|
| 1447 | |
---|
| 1448 | const ast::Init * visit( const ast::SingleInit * node ) override final { |
---|
[74ad8c0] | 1449 | auto init = new SingleInit( |
---|
| 1450 | get<Expression>().accept1( node->value ), |
---|
| 1451 | ast::MaybeConstruct == node->maybeConstructed |
---|
| 1452 | ); |
---|
| 1453 | init->location = node->location; |
---|
| 1454 | this->node = init; |
---|
[74dbbf6] | 1455 | return nullptr; |
---|
| 1456 | } |
---|
| 1457 | |
---|
| 1458 | const ast::Init * visit( const ast::ListInit * node ) override final { |
---|
[74ad8c0] | 1459 | auto init = new ListInit( |
---|
| 1460 | get<Initializer>().acceptL( node->initializers ), |
---|
| 1461 | get<Designation>().acceptL( node->designations ), |
---|
| 1462 | ast::MaybeConstruct == node->maybeConstructed |
---|
| 1463 | ); |
---|
| 1464 | init->location = node->location; |
---|
| 1465 | this->node = init; |
---|
[74dbbf6] | 1466 | return nullptr; |
---|
| 1467 | } |
---|
| 1468 | |
---|
| 1469 | const ast::Init * visit( const ast::ConstructorInit * node ) override final { |
---|
[74ad8c0] | 1470 | auto init = new ConstructorInit( |
---|
| 1471 | get<Statement>().accept1( node->ctor ), |
---|
| 1472 | get<Statement>().accept1( node->dtor ), |
---|
| 1473 | get<Initializer>().accept1( node->init ) |
---|
| 1474 | ); |
---|
| 1475 | init->location = node->location; |
---|
| 1476 | this->node = init; |
---|
[74dbbf6] | 1477 | return nullptr; |
---|
| 1478 | } |
---|
| 1479 | |
---|
| 1480 | const ast::Attribute * visit( const ast::Attribute * node ) override final { |
---|
[dd6d7c6] | 1481 | auto attr = new Attribute( |
---|
| 1482 | node->name, |
---|
[489bacf] | 1483 | get<Expression>().acceptL(node->params) |
---|
[dd6d7c6] | 1484 | ); |
---|
| 1485 | this->node = attr; |
---|
[74dbbf6] | 1486 | return nullptr; |
---|
| 1487 | } |
---|
| 1488 | |
---|
| 1489 | const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { |
---|
[dd6d7c6] | 1490 | // Handled by convertTypeSubstitution helper instead. |
---|
| 1491 | // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node. |
---|
| 1492 | assert( 0 ); |
---|
[0b57626] | 1493 | (void)node; |
---|
[74dbbf6] | 1494 | return nullptr; |
---|
| 1495 | } |
---|
[6d51bd7] | 1496 | }; |
---|
| 1497 | |
---|
[293dc1c] | 1498 | std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) { |
---|
[1387ea0] | 1499 | // Copy values from the global store to the local static variables. |
---|
| 1500 | ast::sizeType = translationUnit.global.sizeType; |
---|
| 1501 | ast::dereferenceOperator = translationUnit.global.dereference; |
---|
| 1502 | ast::dtorStruct = translationUnit.global.dtorStruct; |
---|
| 1503 | ast::dtorStructDestroy = translationUnit.global.dtorDestroy; |
---|
| 1504 | |
---|
[74dbbf6] | 1505 | ConverterNewToOld c; |
---|
| 1506 | std::list< Declaration * > decls; |
---|
[293dc1c] | 1507 | for(auto d : translationUnit.decls) { |
---|
[675d816] | 1508 | decls.emplace_back( c.decl( d ) ); |
---|
[74dbbf6] | 1509 | } |
---|
| 1510 | return decls; |
---|
[6d51bd7] | 1511 | } |
---|
| 1512 | |
---|
| 1513 | //================================================================================================ |
---|
| 1514 | |
---|
| 1515 | class ConverterOldToNew : public Visitor { |
---|
| 1516 | public: |
---|
| 1517 | ast::Decl * decl() { |
---|
| 1518 | return strict_dynamic_cast< ast::Decl * >( node ); |
---|
| 1519 | } |
---|
[4559b34] | 1520 | |
---|
[546e712] | 1521 | ConverterOldToNew() = default; |
---|
| 1522 | ConverterOldToNew(const ConverterOldToNew &) = delete; |
---|
| 1523 | ConverterOldToNew(ConverterOldToNew &&) = delete; |
---|
[6d51bd7] | 1524 | private: |
---|
[d148778] | 1525 | /// conversion output |
---|
[546e712] | 1526 | ast::Node * node = nullptr; |
---|
[d148778] | 1527 | /// cache of nodes that might be referenced by readonly<> for de-duplication |
---|
[954c954] | 1528 | /// in case that some nodes are dropped by conversion (due to possible structural change) |
---|
| 1529 | /// use smart pointers in cache value to prevent accidental invalidation. |
---|
| 1530 | /// at conversion stage, all created nodes are guaranteed to be unique, therefore |
---|
| 1531 | /// const_casting out of smart pointers is permitted. |
---|
[3e5dd913] | 1532 | std::unordered_map< const BaseSyntaxNode *, ast::readonly<ast::Node> > cache = {}; |
---|
[6d51bd7] | 1533 | |
---|
[6f8e87d] | 1534 | // Local Utilities: |
---|
| 1535 | |
---|
| 1536 | template<typename NewT, typename OldT> |
---|
| 1537 | NewT * getAccept1( OldT old ) { |
---|
[d148778] | 1538 | if ( ! old ) return nullptr; |
---|
[6f8e87d] | 1539 | old->accept(*this); |
---|
[2c04369] | 1540 | ast::Node * ret = node; |
---|
| 1541 | node = nullptr; |
---|
| 1542 | return strict_dynamic_cast< NewT * >( ret ); |
---|
[6f8e87d] | 1543 | } |
---|
| 1544 | |
---|
| 1545 | # define GET_ACCEPT_1(child, type) \ |
---|
| 1546 | getAccept1< ast::type, decltype( old->child ) >( old->child ) |
---|
| 1547 | |
---|
[f135b50] | 1548 | |
---|
[6f8e87d] | 1549 | template<typename NewT, typename OldC> |
---|
[a62749f] | 1550 | std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) { |
---|
[6f8e87d] | 1551 | std::vector< ast::ptr<NewT> > ret; |
---|
| 1552 | ret.reserve( old.size() ); |
---|
| 1553 | for ( auto a : old ) { |
---|
| 1554 | a->accept( *this ); |
---|
| 1555 | ret.emplace_back( strict_dynamic_cast< NewT * >(node) ); |
---|
[2c04369] | 1556 | node = nullptr; |
---|
[6f8e87d] | 1557 | } |
---|
| 1558 | return ret; |
---|
| 1559 | } |
---|
| 1560 | |
---|
| 1561 | # define GET_ACCEPT_V(child, type) \ |
---|
| 1562 | getAcceptV< ast::type, decltype( old->child ) >( old->child ) |
---|
[6355ba7] | 1563 | |
---|
[f238fcc2] | 1564 | # define GET_ACCEPT_E(child, type) \ |
---|
| 1565 | getAccept1< ast::type, decltype( old->base ) >( old->base ) |
---|
| 1566 | |
---|
[60aaa51d] | 1567 | template<typename NewT, typename OldC> |
---|
[a62749f] | 1568 | std::deque< ast::ptr<NewT> > getAcceptD( const OldC& old ) { |
---|
[60aaa51d] | 1569 | std::deque< ast::ptr<NewT> > ret; |
---|
| 1570 | for ( auto a : old ) { |
---|
| 1571 | a->accept( *this ); |
---|
| 1572 | ret.emplace_back( strict_dynamic_cast< NewT * >(node) ); |
---|
| 1573 | node = nullptr; |
---|
| 1574 | } |
---|
| 1575 | return ret; |
---|
| 1576 | } |
---|
| 1577 | |
---|
| 1578 | # define GET_ACCEPT_D(child, type) \ |
---|
| 1579 | getAcceptD< ast::type, decltype( old->child ) >( old->child ) |
---|
[6f8e87d] | 1580 | |
---|
[a62749f] | 1581 | ast::Label make_label(const Label* old) { |
---|
| 1582 | CodeLocation const & location = |
---|
| 1583 | ( old->labelled ) ? old->labelled->location : CodeLocation(); |
---|
[6f8e87d] | 1584 | return ast::Label( |
---|
[a62749f] | 1585 | location, |
---|
[6f8e87d] | 1586 | old->name, |
---|
| 1587 | GET_ACCEPT_V(attributes, Attribute) |
---|
| 1588 | ); |
---|
| 1589 | } |
---|
| 1590 | |
---|
[6d51bd7] | 1591 | template<template <class...> class C> |
---|
| 1592 | C<ast::Label> make_labels(C<Label> olds) { |
---|
| 1593 | C<ast::Label> ret; |
---|
[6f8e87d] | 1594 | for (auto oldn : olds) { |
---|
| 1595 | ret.push_back( make_label( &oldn ) ); |
---|
[6d51bd7] | 1596 | } |
---|
| 1597 | return ret; |
---|
| 1598 | } |
---|
| 1599 | |
---|
[6f8e87d] | 1600 | # define GET_LABELS_V(labels) \ |
---|
| 1601 | to<std::vector>::from( make_labels( std::move( labels ) ) ) |
---|
[0b57626] | 1602 | |
---|
[7870799] | 1603 | static ast::CV::Qualifiers cv( const Type * ty ) { return { ty->tq.val }; } |
---|
[d148778] | 1604 | |
---|
[b869ec5] | 1605 | /// returns true and sets `node` if in cache |
---|
[7870799] | 1606 | bool inCache( const BaseSyntaxNode * old ) { |
---|
[d148778] | 1607 | auto it = cache.find( old ); |
---|
[b869ec5] | 1608 | if ( it == cache.end() ) return false; |
---|
[954c954] | 1609 | node = const_cast<ast::Node *>(it->second.get()); |
---|
[b869ec5] | 1610 | return true; |
---|
[d148778] | 1611 | } |
---|
[6f8e87d] | 1612 | |
---|
| 1613 | // Now all the visit functions: |
---|
| 1614 | |
---|
[7870799] | 1615 | virtual void visit( const ObjectDecl * old ) override final { |
---|
[1931bb01] | 1616 | if ( inCache( old ) ) { |
---|
| 1617 | return; |
---|
| 1618 | } |
---|
[546e712] | 1619 | auto&& type = GET_ACCEPT_1(type, Type); |
---|
| 1620 | auto&& init = GET_ACCEPT_1(init, Init); |
---|
| 1621 | auto&& bfwd = GET_ACCEPT_1(bitfieldWidth, Expr); |
---|
| 1622 | auto&& attr = GET_ACCEPT_V(attributes, Attribute); |
---|
[1931bb01] | 1623 | |
---|
[6d51bd7] | 1624 | auto decl = new ast::ObjectDecl( |
---|
| 1625 | old->location, |
---|
| 1626 | old->name, |
---|
[546e712] | 1627 | type, |
---|
| 1628 | init, |
---|
[6d51bd7] | 1629 | { old->get_storageClasses().val }, |
---|
| 1630 | { old->linkage.val }, |
---|
[546e712] | 1631 | bfwd, |
---|
| 1632 | std::move(attr), |
---|
[6d51bd7] | 1633 | { old->get_funcSpec().val } |
---|
| 1634 | ); |
---|
[546e712] | 1635 | cache.emplace(old, decl); |
---|
| 1636 | assert(cache.find( old ) != cache.end()); |
---|
[6d51bd7] | 1637 | decl->scopeLevel = old->scopeLevel; |
---|
| 1638 | decl->mangleName = old->mangleName; |
---|
| 1639 | decl->isDeleted = old->isDeleted; |
---|
[e6faef4] | 1640 | decl->asmName = GET_ACCEPT_1(asmName, Expr); |
---|
[6d51bd7] | 1641 | decl->uniqueId = old->uniqueId; |
---|
| 1642 | decl->extension = old->extension; |
---|
| 1643 | |
---|
| 1644 | this->node = decl; |
---|
| 1645 | } |
---|
| 1646 | |
---|
[7870799] | 1647 | virtual void visit( const FunctionDecl * old ) override final { |
---|
[b869ec5] | 1648 | if ( inCache( old ) ) return; |
---|
[954c954] | 1649 | auto paramVars = GET_ACCEPT_V(type->parameters, DeclWithType); |
---|
| 1650 | auto returnVars = GET_ACCEPT_V(type->returnVals, DeclWithType); |
---|
| 1651 | auto forall = GET_ACCEPT_V(type->forall, TypeDecl); |
---|
| 1652 | |
---|
| 1653 | // function type is now derived from parameter decls instead of storing them |
---|
[490fb92e] | 1654 | |
---|
| 1655 | /* |
---|
[954c954] | 1656 | auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type)); |
---|
| 1657 | ftype->params.reserve(paramVars.size()); |
---|
| 1658 | ftype->returns.reserve(returnVars.size()); |
---|
| 1659 | |
---|
| 1660 | for (auto & v: paramVars) { |
---|
| 1661 | ftype->params.emplace_back(v->get_type()); |
---|
| 1662 | } |
---|
| 1663 | for (auto & v: returnVars) { |
---|
| 1664 | ftype->returns.emplace_back(v->get_type()); |
---|
| 1665 | } |
---|
| 1666 | ftype->forall = std::move(forall); |
---|
[490fb92e] | 1667 | */ |
---|
| 1668 | |
---|
| 1669 | // can function type have attributes? seems not to be the case. |
---|
| 1670 | // visitType(old->type, ftype); |
---|
[954c954] | 1671 | |
---|
[3e5dd913] | 1672 | // collect assertions and put directly in FunctionDecl |
---|
| 1673 | std::vector<ast::ptr<ast::DeclWithType>> assertions; |
---|
| 1674 | for (auto & param: forall) { |
---|
| 1675 | for (auto & asst: param->assertions) { |
---|
| 1676 | assertf(asst->unique(), "newly converted decl must be unique"); |
---|
| 1677 | assertions.emplace_back(asst); |
---|
| 1678 | } |
---|
| 1679 | auto mut = param.get_and_mutate(); |
---|
| 1680 | assertf(mut == param, "newly converted decl must be unique"); |
---|
| 1681 | mut->assertions.clear(); |
---|
| 1682 | } |
---|
| 1683 | |
---|
[9a0cd9c] | 1684 | auto decl = new ast::FunctionDecl{ |
---|
| 1685 | old->location, |
---|
| 1686 | old->name, |
---|
[954c954] | 1687 | // GET_ACCEPT_1(type, FunctionType), |
---|
[490fb92e] | 1688 | std::move(forall), |
---|
[7edd5c1] | 1689 | std::move(assertions), |
---|
[954c954] | 1690 | std::move(paramVars), |
---|
| 1691 | std::move(returnVars), |
---|
[d88f8b3b] | 1692 | {}, |
---|
[9a0cd9c] | 1693 | { old->storageClasses.val }, |
---|
| 1694 | { old->linkage.val }, |
---|
| 1695 | GET_ACCEPT_V(attributes, Attribute), |
---|
[490fb92e] | 1696 | { old->get_funcSpec().val }, |
---|
[3e94a23] | 1697 | (old->type->isVarArgs) ? ast::VariableArgs : ast::FixedArgs |
---|
[9a0cd9c] | 1698 | }; |
---|
[954c954] | 1699 | |
---|
[490fb92e] | 1700 | // decl->type = ftype; |
---|
[8abee136] | 1701 | cache.emplace( old, decl ); |
---|
[954c954] | 1702 | |
---|
[d76c588] | 1703 | decl->withExprs = GET_ACCEPT_V(withExprs, Expr); |
---|
[d88f8b3b] | 1704 | decl->stmts = GET_ACCEPT_1(statements, CompoundStmt); |
---|
[9a0cd9c] | 1705 | decl->scopeLevel = old->scopeLevel; |
---|
| 1706 | decl->mangleName = old->mangleName; |
---|
| 1707 | decl->isDeleted = old->isDeleted; |
---|
[e6faef4] | 1708 | decl->asmName = GET_ACCEPT_1(asmName, Expr); |
---|
[9a0cd9c] | 1709 | decl->uniqueId = old->uniqueId; |
---|
| 1710 | decl->extension = old->extension; |
---|
| 1711 | |
---|
| 1712 | this->node = decl; |
---|
[157a816] | 1713 | |
---|
[0aedb01] | 1714 | if ( Validate::dereferenceOperator == old ) { |
---|
[490fb92e] | 1715 | ast::dereferenceOperator = decl; |
---|
[157a816] | 1716 | } |
---|
[043a5b6] | 1717 | |
---|
| 1718 | if ( Validate::dtorStructDestroy == old ) { |
---|
[490fb92e] | 1719 | ast::dtorStructDestroy = decl; |
---|
[043a5b6] | 1720 | } |
---|
[6d51bd7] | 1721 | } |
---|
| 1722 | |
---|
[7870799] | 1723 | virtual void visit( const StructDecl * old ) override final { |
---|
[b869ec5] | 1724 | if ( inCache( old ) ) return; |
---|
[6d51bd7] | 1725 | auto decl = new ast::StructDecl( |
---|
| 1726 | old->location, |
---|
| 1727 | old->name, |
---|
[312029a] | 1728 | (ast::AggregateDecl::Aggregate)old->kind, |
---|
[d66e7b7] | 1729 | GET_ACCEPT_V(attributes, Attribute), |
---|
[6d51bd7] | 1730 | { old->linkage.val } |
---|
| 1731 | ); |
---|
[8abee136] | 1732 | cache.emplace( old, decl ); |
---|
[d66e7b7] | 1733 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl); |
---|
[6d51bd7] | 1734 | decl->body = old->body; |
---|
[d66e7b7] | 1735 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
| 1736 | decl->members = GET_ACCEPT_V(members, Decl); |
---|
[6d51bd7] | 1737 | decl->extension = old->extension; |
---|
| 1738 | decl->uniqueId = old->uniqueId; |
---|
| 1739 | decl->storage = { old->storageClasses.val }; |
---|
| 1740 | |
---|
| 1741 | this->node = decl; |
---|
[043a5b6] | 1742 | |
---|
| 1743 | if ( Validate::dtorStruct == old ) { |
---|
[490fb92e] | 1744 | ast::dtorStruct = decl; |
---|
[043a5b6] | 1745 | } |
---|
[6d51bd7] | 1746 | } |
---|
| 1747 | |
---|
[7870799] | 1748 | virtual void visit( const UnionDecl * old ) override final { |
---|
[b869ec5] | 1749 | if ( inCache( old ) ) return; |
---|
[6d51bd7] | 1750 | auto decl = new ast::UnionDecl( |
---|
| 1751 | old->location, |
---|
| 1752 | old->name, |
---|
[d66e7b7] | 1753 | GET_ACCEPT_V(attributes, Attribute), |
---|
[6d51bd7] | 1754 | { old->linkage.val } |
---|
| 1755 | ); |
---|
[8abee136] | 1756 | cache.emplace( old, decl ); |
---|
[d66e7b7] | 1757 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl); |
---|
[6d51bd7] | 1758 | decl->body = old->body; |
---|
[d66e7b7] | 1759 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
| 1760 | decl->members = GET_ACCEPT_V(members, Decl); |
---|
[6d51bd7] | 1761 | decl->extension = old->extension; |
---|
| 1762 | decl->uniqueId = old->uniqueId; |
---|
| 1763 | decl->storage = { old->storageClasses.val }; |
---|
| 1764 | |
---|
| 1765 | this->node = decl; |
---|
| 1766 | } |
---|
| 1767 | |
---|
[9e7236f4] | 1768 | |
---|
[7870799] | 1769 | virtual void visit( const EnumDecl * old ) override final { |
---|
[b869ec5] | 1770 | if ( inCache( old ) ) return; |
---|
[157a816] | 1771 | auto decl = new ast::EnumDecl( |
---|
[6d51bd7] | 1772 | old->location, |
---|
| 1773 | old->name, |
---|
[b0d9ff7] | 1774 | old->isTyped, |
---|
[d66e7b7] | 1775 | GET_ACCEPT_V(attributes, Attribute), |
---|
[f135b50] | 1776 | { old->linkage.val }, |
---|
[f238fcc2] | 1777 | GET_ACCEPT_1(base, Type), |
---|
[e4d7c1c] | 1778 | old->hide == EnumDecl::EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible, |
---|
[f135b50] | 1779 | old->enumValues |
---|
[6d51bd7] | 1780 | ); |
---|
[8abee136] | 1781 | cache.emplace( old, decl ); |
---|
[d66e7b7] | 1782 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl); |
---|
[6d51bd7] | 1783 | decl->body = old->body; |
---|
[d66e7b7] | 1784 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
| 1785 | decl->members = GET_ACCEPT_V(members, Decl); |
---|
[6d51bd7] | 1786 | decl->extension = old->extension; |
---|
| 1787 | decl->uniqueId = old->uniqueId; |
---|
| 1788 | decl->storage = { old->storageClasses.val }; |
---|
| 1789 | this->node = decl; |
---|
| 1790 | } |
---|
| 1791 | |
---|
[7870799] | 1792 | virtual void visit( const TraitDecl * old ) override final { |
---|
[b869ec5] | 1793 | if ( inCache( old ) ) return; |
---|
[157a816] | 1794 | auto decl = new ast::TraitDecl( |
---|
[6d51bd7] | 1795 | old->location, |
---|
| 1796 | old->name, |
---|
[d66e7b7] | 1797 | GET_ACCEPT_V(attributes, Attribute), |
---|
[6d51bd7] | 1798 | { old->linkage.val } |
---|
| 1799 | ); |
---|
[8abee136] | 1800 | cache.emplace( old, decl ); |
---|
[d66e7b7] | 1801 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl); |
---|
[6d51bd7] | 1802 | decl->body = old->body; |
---|
[d66e7b7] | 1803 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
| 1804 | decl->members = GET_ACCEPT_V(members, Decl); |
---|
[6d51bd7] | 1805 | decl->extension = old->extension; |
---|
| 1806 | decl->uniqueId = old->uniqueId; |
---|
| 1807 | decl->storage = { old->storageClasses.val }; |
---|
| 1808 | |
---|
| 1809 | this->node = decl; |
---|
| 1810 | } |
---|
| 1811 | |
---|
[7870799] | 1812 | virtual void visit( const TypeDecl * old ) override final { |
---|
[0b57626] | 1813 | if ( inCache( old ) ) return; |
---|
[9a0cd9c] | 1814 | auto decl = new ast::TypeDecl{ |
---|
| 1815 | old->location, |
---|
| 1816 | old->name, |
---|
| 1817 | { old->storageClasses.val }, |
---|
| 1818 | GET_ACCEPT_1(base, Type), |
---|
[07de76b] | 1819 | (ast::TypeDecl::Kind)(unsigned)old->kind, |
---|
[9a0cd9c] | 1820 | old->sized, |
---|
| 1821 | GET_ACCEPT_1(init, Type) |
---|
| 1822 | }; |
---|
[8abee136] | 1823 | cache.emplace( old, decl ); |
---|
[9a0cd9c] | 1824 | decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); |
---|
| 1825 | decl->extension = old->extension; |
---|
| 1826 | decl->uniqueId = old->uniqueId; |
---|
| 1827 | |
---|
| 1828 | this->node = decl; |
---|
[6d51bd7] | 1829 | } |
---|
| 1830 | |
---|
[7870799] | 1831 | virtual void visit( const TypedefDecl * old ) override final { |
---|
[6d51bd7] | 1832 | auto decl = new ast::TypedefDecl( |
---|
| 1833 | old->location, |
---|
| 1834 | old->name, |
---|
| 1835 | { old->storageClasses.val }, |
---|
[d66e7b7] | 1836 | GET_ACCEPT_1(base, Type), |
---|
[6d51bd7] | 1837 | { old->linkage.val } |
---|
| 1838 | ); |
---|
[d66e7b7] | 1839 | decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); |
---|
[6d51bd7] | 1840 | decl->extension = old->extension; |
---|
| 1841 | decl->uniqueId = old->uniqueId; |
---|
| 1842 | decl->storage = { old->storageClasses.val }; |
---|
| 1843 | |
---|
| 1844 | this->node = decl; |
---|
| 1845 | } |
---|
| 1846 | |
---|
[7870799] | 1847 | virtual void visit( const AsmDecl * old ) override final { |
---|
[9a0cd9c] | 1848 | auto decl = new ast::AsmDecl{ |
---|
[0b57626] | 1849 | old->location, |
---|
[9a0cd9c] | 1850 | GET_ACCEPT_1(stmt, AsmStmt) |
---|
| 1851 | }; |
---|
| 1852 | decl->extension = old->extension; |
---|
| 1853 | decl->uniqueId = old->uniqueId; |
---|
| 1854 | decl->storage = { old->storageClasses.val }; |
---|
[6d51bd7] | 1855 | |
---|
[9a0cd9c] | 1856 | this->node = decl; |
---|
[6d51bd7] | 1857 | } |
---|
| 1858 | |
---|
[2d019af] | 1859 | virtual void visit( const DirectiveDecl * old ) override final { |
---|
| 1860 | auto decl = new ast::DirectiveDecl{ |
---|
| 1861 | old->location, |
---|
| 1862 | GET_ACCEPT_1(stmt, DirectiveStmt) |
---|
| 1863 | }; |
---|
| 1864 | decl->extension = old->extension; |
---|
| 1865 | decl->uniqueId = old->uniqueId; |
---|
| 1866 | decl->storage = { old->storageClasses.val }; |
---|
| 1867 | |
---|
| 1868 | this->node = decl; |
---|
| 1869 | } |
---|
| 1870 | |
---|
[7870799] | 1871 | virtual void visit( const StaticAssertDecl * old ) override final { |
---|
[9a0cd9c] | 1872 | auto decl = new ast::StaticAssertDecl{ |
---|
| 1873 | old->location, |
---|
| 1874 | GET_ACCEPT_1(condition, Expr), |
---|
| 1875 | GET_ACCEPT_1(message, ConstantExpr) |
---|
| 1876 | }; |
---|
| 1877 | decl->extension = old->extension; |
---|
| 1878 | decl->uniqueId = old->uniqueId; |
---|
| 1879 | decl->storage = { old->storageClasses.val }; |
---|
[6d51bd7] | 1880 | |
---|
[9a0cd9c] | 1881 | this->node = decl; |
---|
[6d51bd7] | 1882 | } |
---|
| 1883 | |
---|
[71806e0] | 1884 | virtual void visit( const InlineMemberDecl * old ) override final { |
---|
[e874605] | 1885 | if ( inCache( old ) ) { |
---|
| 1886 | return; |
---|
| 1887 | } |
---|
| 1888 | auto&& type = GET_ACCEPT_1(type, Type); |
---|
| 1889 | auto&& attr = GET_ACCEPT_V(attributes, Attribute); |
---|
[19a8c40] | 1890 | |
---|
[71806e0] | 1891 | auto decl = new ast::InlineMemberDecl( |
---|
[e874605] | 1892 | old->location, |
---|
| 1893 | old->name, |
---|
| 1894 | type, |
---|
| 1895 | { old->get_storageClasses().val }, |
---|
| 1896 | { old->linkage.val }, |
---|
| 1897 | std::move(attr), |
---|
| 1898 | { old->get_funcSpec().val } |
---|
| 1899 | ); |
---|
| 1900 | cache.emplace(old, decl); |
---|
| 1901 | assert(cache.find( old ) != cache.end()); |
---|
| 1902 | decl->scopeLevel = old->scopeLevel; |
---|
| 1903 | decl->mangleName = old->mangleName; |
---|
| 1904 | decl->isDeleted = old->isDeleted; |
---|
| 1905 | decl->asmName = GET_ACCEPT_1(asmName, Expr); |
---|
| 1906 | decl->uniqueId = old->uniqueId; |
---|
| 1907 | decl->extension = old->extension; |
---|
| 1908 | |
---|
| 1909 | this->node = decl; |
---|
| 1910 | } |
---|
| 1911 | |
---|
[7870799] | 1912 | virtual void visit( const CompoundStmt * old ) override final { |
---|
[4073b16] | 1913 | if ( inCache( old ) ) return; |
---|
[6d51bd7] | 1914 | auto stmt = new ast::CompoundStmt( |
---|
| 1915 | old->location, |
---|
[d66e7b7] | 1916 | to<std::list>::from( GET_ACCEPT_V(kids, Stmt) ), |
---|
| 1917 | GET_LABELS_V(old->labels) |
---|
[6d51bd7] | 1918 | ); |
---|
| 1919 | |
---|
| 1920 | this->node = stmt; |
---|
[4073b16] | 1921 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 1922 | } |
---|
| 1923 | |
---|
[7870799] | 1924 | virtual void visit( const ExprStmt * old ) override final { |
---|
[4073b16] | 1925 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 1926 | this->node = new ast::ExprStmt( |
---|
[6d51bd7] | 1927 | old->location, |
---|
[6f8e87d] | 1928 | GET_ACCEPT_1(expr, Expr), |
---|
| 1929 | GET_LABELS_V(old->labels) |
---|
[6d51bd7] | 1930 | ); |
---|
[4073b16] | 1931 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 1932 | } |
---|
| 1933 | |
---|
[7870799] | 1934 | virtual void visit( const AsmStmt * old ) override final { |
---|
[4073b16] | 1935 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 1936 | this->node = new ast::AsmStmt( |
---|
| 1937 | old->location, |
---|
| 1938 | old->voltile, |
---|
| 1939 | GET_ACCEPT_1(instruction, Expr), |
---|
| 1940 | GET_ACCEPT_V(output, Expr), |
---|
| 1941 | GET_ACCEPT_V(input, Expr), |
---|
| 1942 | GET_ACCEPT_V(clobber, ConstantExpr), |
---|
| 1943 | GET_LABELS_V(old->gotolabels), |
---|
| 1944 | GET_LABELS_V(old->labels) |
---|
| 1945 | ); |
---|
[4073b16] | 1946 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 1947 | } |
---|
| 1948 | |
---|
[7870799] | 1949 | virtual void visit( const DirectiveStmt * old ) override final { |
---|
[4073b16] | 1950 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 1951 | this->node = new ast::DirectiveStmt( |
---|
| 1952 | old->location, |
---|
| 1953 | old->directive, |
---|
| 1954 | GET_LABELS_V(old->labels) |
---|
| 1955 | ); |
---|
[4073b16] | 1956 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 1957 | } |
---|
| 1958 | |
---|
[7870799] | 1959 | virtual void visit( const IfStmt * old ) override final { |
---|
[4073b16] | 1960 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 1961 | this->node = new ast::IfStmt( |
---|
| 1962 | old->location, |
---|
| 1963 | GET_ACCEPT_1(condition, Expr), |
---|
[3b0bc16] | 1964 | GET_ACCEPT_1(then, Stmt), |
---|
| 1965 | GET_ACCEPT_1(else_, Stmt), |
---|
[6f8e87d] | 1966 | GET_ACCEPT_V(initialization, Stmt), |
---|
| 1967 | GET_LABELS_V(old->labels) |
---|
| 1968 | ); |
---|
[4073b16] | 1969 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 1970 | } |
---|
| 1971 | |
---|
[7870799] | 1972 | virtual void visit( const SwitchStmt * old ) override final { |
---|
[4073b16] | 1973 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 1974 | this->node = new ast::SwitchStmt( |
---|
| 1975 | old->location, |
---|
| 1976 | GET_ACCEPT_1(condition, Expr), |
---|
[400b8be] | 1977 | GET_ACCEPT_V(statements, CaseClause), |
---|
[6f8e87d] | 1978 | GET_LABELS_V(old->labels) |
---|
| 1979 | ); |
---|
[4073b16] | 1980 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 1981 | } |
---|
| 1982 | |
---|
[7870799] | 1983 | virtual void visit( const CaseStmt * old ) override final { |
---|
[4073b16] | 1984 | if ( inCache( old ) ) return; |
---|
[400b8be] | 1985 | this->node = new ast::CaseClause( |
---|
[6f8e87d] | 1986 | old->location, |
---|
| 1987 | GET_ACCEPT_1(condition, Expr), |
---|
[400b8be] | 1988 | GET_ACCEPT_V(stmts, Stmt) |
---|
[6f8e87d] | 1989 | ); |
---|
[400b8be] | 1990 | auto labels = GET_LABELS_V(old->labels); |
---|
| 1991 | assertf(labels.empty(), "Labels found on CaseStmt."); |
---|
[4073b16] | 1992 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 1993 | } |
---|
| 1994 | |
---|
[3b0bc16] | 1995 | virtual void visit( const WhileDoStmt * old ) override final { |
---|
[4073b16] | 1996 | if ( inCache( old ) ) return; |
---|
[3b0bc16] | 1997 | this->node = new ast::WhileDoStmt( |
---|
[6f8e87d] | 1998 | old->location, |
---|
| 1999 | GET_ACCEPT_1(condition, Expr), |
---|
| 2000 | GET_ACCEPT_1(body, Stmt), |
---|
[ff3b0249] | 2001 | GET_ACCEPT_1(else_, Stmt), |
---|
[6f8e87d] | 2002 | GET_ACCEPT_V(initialization, Stmt), |
---|
[3e94a23] | 2003 | (old->isDoWhile) ? ast::DoWhile : ast::While, |
---|
[6f8e87d] | 2004 | GET_LABELS_V(old->labels) |
---|
| 2005 | ); |
---|
[4073b16] | 2006 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2007 | } |
---|
| 2008 | |
---|
[7870799] | 2009 | virtual void visit( const ForStmt * old ) override final { |
---|
[4073b16] | 2010 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 2011 | this->node = new ast::ForStmt( |
---|
| 2012 | old->location, |
---|
| 2013 | GET_ACCEPT_V(initialization, Stmt), |
---|
| 2014 | GET_ACCEPT_1(condition, Expr), |
---|
| 2015 | GET_ACCEPT_1(increment, Expr), |
---|
| 2016 | GET_ACCEPT_1(body, Stmt), |
---|
[ff3b0249] | 2017 | GET_ACCEPT_1(else_, Stmt), |
---|
[6f8e87d] | 2018 | GET_LABELS_V(old->labels) |
---|
| 2019 | ); |
---|
[4073b16] | 2020 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2021 | } |
---|
| 2022 | |
---|
[7870799] | 2023 | virtual void visit( const BranchStmt * old ) override final { |
---|
[4073b16] | 2024 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 2025 | if (old->computedTarget) { |
---|
| 2026 | this->node = new ast::BranchStmt( |
---|
| 2027 | old->location, |
---|
| 2028 | GET_ACCEPT_1(computedTarget, Expr), |
---|
| 2029 | GET_LABELS_V(old->labels) |
---|
| 2030 | ); |
---|
| 2031 | } else { |
---|
| 2032 | ast::BranchStmt::Kind kind; |
---|
| 2033 | switch (old->type) { |
---|
| 2034 | #define CASE(n) \ |
---|
| 2035 | case BranchStmt::n: \ |
---|
| 2036 | kind = ast::BranchStmt::n; \ |
---|
| 2037 | break |
---|
| 2038 | CASE(Goto); |
---|
| 2039 | CASE(Break); |
---|
| 2040 | CASE(Continue); |
---|
| 2041 | CASE(FallThrough); |
---|
| 2042 | CASE(FallThroughDefault); |
---|
| 2043 | #undef CASE |
---|
[d66e7b7] | 2044 | default: |
---|
| 2045 | assertf(false, "Invalid BranchStmt::Type %d\n", old->type); |
---|
[6f8e87d] | 2046 | } |
---|
| 2047 | |
---|
| 2048 | auto stmt = new ast::BranchStmt( |
---|
| 2049 | old->location, |
---|
| 2050 | kind, |
---|
[a62749f] | 2051 | make_label(&old->originalTarget), |
---|
[6f8e87d] | 2052 | GET_LABELS_V(old->labels) |
---|
| 2053 | ); |
---|
| 2054 | stmt->target = make_label(&old->target); |
---|
| 2055 | this->node = stmt; |
---|
| 2056 | } |
---|
[4073b16] | 2057 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2058 | } |
---|
| 2059 | |
---|
[7870799] | 2060 | virtual void visit( const ReturnStmt * old ) override final { |
---|
[4073b16] | 2061 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 2062 | this->node = new ast::ReturnStmt( |
---|
| 2063 | old->location, |
---|
| 2064 | GET_ACCEPT_1(expr, Expr), |
---|
| 2065 | GET_LABELS_V(old->labels) |
---|
| 2066 | ); |
---|
[4073b16] | 2067 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2068 | } |
---|
| 2069 | |
---|
[7870799] | 2070 | virtual void visit( const ThrowStmt * old ) override final { |
---|
[4073b16] | 2071 | if ( inCache( old ) ) return; |
---|
[6f4b7f2] | 2072 | ast::ExceptionKind kind; |
---|
[6f8e87d] | 2073 | switch (old->kind) { |
---|
| 2074 | case ThrowStmt::Terminate: |
---|
[6f4b7f2] | 2075 | kind = ast::ExceptionKind::Terminate; |
---|
[6f8e87d] | 2076 | break; |
---|
| 2077 | case ThrowStmt::Resume: |
---|
[6f4b7f2] | 2078 | kind = ast::ExceptionKind::Resume; |
---|
[6f8e87d] | 2079 | break; |
---|
[d66e7b7] | 2080 | default: |
---|
| 2081 | assertf(false, "Invalid ThrowStmt::Kind %d\n", old->kind); |
---|
[6f8e87d] | 2082 | } |
---|
[6d51bd7] | 2083 | |
---|
[6f8e87d] | 2084 | this->node = new ast::ThrowStmt( |
---|
| 2085 | old->location, |
---|
| 2086 | kind, |
---|
| 2087 | GET_ACCEPT_1(expr, Expr), |
---|
| 2088 | GET_ACCEPT_1(target, Expr), |
---|
| 2089 | GET_LABELS_V(old->labels) |
---|
| 2090 | ); |
---|
[4073b16] | 2091 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2092 | } |
---|
| 2093 | |
---|
[7870799] | 2094 | virtual void visit( const TryStmt * old ) override final { |
---|
[4073b16] | 2095 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 2096 | this->node = new ast::TryStmt( |
---|
| 2097 | old->location, |
---|
| 2098 | GET_ACCEPT_1(block, CompoundStmt), |
---|
[400b8be] | 2099 | GET_ACCEPT_V(handlers, CatchClause), |
---|
| 2100 | GET_ACCEPT_1(finallyBlock, FinallyClause), |
---|
[6f8e87d] | 2101 | GET_LABELS_V(old->labels) |
---|
| 2102 | ); |
---|
[4073b16] | 2103 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2104 | } |
---|
| 2105 | |
---|
[7870799] | 2106 | virtual void visit( const CatchStmt * old ) override final { |
---|
[4073b16] | 2107 | if ( inCache( old ) ) return; |
---|
[6f4b7f2] | 2108 | ast::ExceptionKind kind; |
---|
[6f8e87d] | 2109 | switch (old->kind) { |
---|
| 2110 | case CatchStmt::Terminate: |
---|
[6f4b7f2] | 2111 | kind = ast::ExceptionKind::Terminate; |
---|
[6f8e87d] | 2112 | break; |
---|
| 2113 | case CatchStmt::Resume: |
---|
[6f4b7f2] | 2114 | kind = ast::ExceptionKind::Resume; |
---|
[6f8e87d] | 2115 | break; |
---|
[d66e7b7] | 2116 | default: |
---|
| 2117 | assertf(false, "Invalid CatchStmt::Kind %d\n", old->kind); |
---|
[6f8e87d] | 2118 | } |
---|
[6d51bd7] | 2119 | |
---|
[400b8be] | 2120 | this->node = new ast::CatchClause( |
---|
[6f8e87d] | 2121 | old->location, |
---|
| 2122 | kind, |
---|
| 2123 | GET_ACCEPT_1(decl, Decl), |
---|
| 2124 | GET_ACCEPT_1(cond, Expr), |
---|
[400b8be] | 2125 | GET_ACCEPT_1(body, Stmt) |
---|
[6f8e87d] | 2126 | ); |
---|
[400b8be] | 2127 | auto labels = GET_LABELS_V(old->labels); |
---|
| 2128 | assertf(labels.empty(), "Labels found on CatchStmt."); |
---|
[4073b16] | 2129 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2130 | } |
---|
| 2131 | |
---|
[7870799] | 2132 | virtual void visit( const FinallyStmt * old ) override final { |
---|
[4073b16] | 2133 | if ( inCache( old ) ) return; |
---|
[400b8be] | 2134 | this->node = new ast::FinallyClause( |
---|
[6f8e87d] | 2135 | old->location, |
---|
[400b8be] | 2136 | GET_ACCEPT_1(block, CompoundStmt) |
---|
[6f8e87d] | 2137 | ); |
---|
[400b8be] | 2138 | auto labels = GET_LABELS_V(old->labels); |
---|
| 2139 | assertf(labels.empty(), "Labels found on FinallyStmt."); |
---|
[4073b16] | 2140 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2141 | } |
---|
| 2142 | |
---|
[37cdd97] | 2143 | virtual void visit( const SuspendStmt * old ) override final { |
---|
| 2144 | if ( inCache( old ) ) return; |
---|
[835d6e8] | 2145 | ast::SuspendStmt::Kind type; |
---|
[37cdd97] | 2146 | switch (old->type) { |
---|
| 2147 | case SuspendStmt::Coroutine: type = ast::SuspendStmt::Coroutine; break; |
---|
| 2148 | case SuspendStmt::Generator: type = ast::SuspendStmt::Generator; break; |
---|
| 2149 | case SuspendStmt::None : type = ast::SuspendStmt::None ; break; |
---|
| 2150 | default: abort(); |
---|
| 2151 | } |
---|
| 2152 | this->node = new ast::SuspendStmt( |
---|
| 2153 | old->location, |
---|
| 2154 | GET_ACCEPT_1(then , CompoundStmt), |
---|
| 2155 | type, |
---|
| 2156 | GET_LABELS_V(old->labels) |
---|
| 2157 | ); |
---|
[4073b16] | 2158 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2159 | } |
---|
| 2160 | |
---|
[7870799] | 2161 | virtual void visit( const WaitForStmt * old ) override final { |
---|
[4073b16] | 2162 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 2163 | ast::WaitForStmt * stmt = new ast::WaitForStmt( |
---|
| 2164 | old->location, |
---|
| 2165 | GET_LABELS_V(old->labels) |
---|
| 2166 | ); |
---|
[6d51bd7] | 2167 | |
---|
[6f8e87d] | 2168 | stmt->clauses.reserve( old->clauses.size() ); |
---|
| 2169 | for (size_t i = 0 ; i < old->clauses.size() ; ++i) { |
---|
[f6e6a55] | 2170 | auto clause = new ast::WaitForClause( old->location ); |
---|
| 2171 | |
---|
[c86b08d] | 2172 | clause->target = GET_ACCEPT_1(clauses[i].target.function, Expr); |
---|
[f6e6a55] | 2173 | clause->target_args = GET_ACCEPT_V(clauses[i].target.arguments, Expr); |
---|
| 2174 | clause->stmt = GET_ACCEPT_1(clauses[i].statement, Stmt); |
---|
[c86b08d] | 2175 | clause->when_cond = GET_ACCEPT_1(clauses[i].condition, Expr); |
---|
[f6e6a55] | 2176 | |
---|
| 2177 | stmt->clauses.push_back( clause ); |
---|
[6f8e87d] | 2178 | } |
---|
[f6e6a55] | 2179 | stmt->timeout_time = GET_ACCEPT_1(timeout.time, Expr); |
---|
| 2180 | stmt->timeout_stmt = GET_ACCEPT_1(timeout.statement, Stmt); |
---|
| 2181 | stmt->timeout_cond = GET_ACCEPT_1(timeout.condition, Expr); |
---|
| 2182 | stmt->else_stmt = GET_ACCEPT_1(orelse.statement, Stmt); |
---|
| 2183 | stmt->else_cond = GET_ACCEPT_1(orelse.condition, Expr); |
---|
[6d51bd7] | 2184 | |
---|
[6f8e87d] | 2185 | this->node = stmt; |
---|
[4073b16] | 2186 | cache.emplace( old, this->node ); |
---|
[6f8e87d] | 2187 | } |
---|
[6d51bd7] | 2188 | |
---|
[7870799] | 2189 | virtual void visit( const WithStmt * old ) override final { |
---|
[4073b16] | 2190 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 2191 | this->node = new ast::WithStmt( |
---|
| 2192 | old->location, |
---|
| 2193 | GET_ACCEPT_V(exprs, Expr), |
---|
[e67991f] | 2194 | GET_ACCEPT_1(stmt, Stmt) |
---|
[6f8e87d] | 2195 | ); |
---|
[4073b16] | 2196 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2197 | } |
---|
| 2198 | |
---|
[7870799] | 2199 | virtual void visit( const NullStmt * old ) override final { |
---|
[4073b16] | 2200 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 2201 | this->node = new ast::NullStmt( |
---|
[6d51bd7] | 2202 | old->location, |
---|
[6f8e87d] | 2203 | GET_LABELS_V(old->labels) |
---|
[6d51bd7] | 2204 | ); |
---|
[4073b16] | 2205 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2206 | } |
---|
| 2207 | |
---|
[7870799] | 2208 | virtual void visit( const DeclStmt * old ) override final { |
---|
[4073b16] | 2209 | if ( inCache( old ) ) return; |
---|
[6f8e87d] | 2210 | this->node = new ast::DeclStmt( |
---|
| 2211 | old->location, |
---|
| 2212 | GET_ACCEPT_1(decl, Decl), |
---|
| 2213 | GET_LABELS_V(old->labels) |
---|
| 2214 | ); |
---|
[4073b16] | 2215 | cache.emplace( old, this->node ); |
---|
[6d51bd7] | 2216 | } |
---|
| 2217 | |
---|
[7870799] | 2218 | virtual void visit( const ImplicitCtorDtorStmt * old ) override final { |
---|
[4073b16] | 2219 | if ( inCache( old ) ) return; |
---|
[f685679] | 2220 | auto stmt = new ast::ImplicitCtorDtorStmt( |
---|
[6f8e87d] | 2221 | old->location, |
---|
[f685679] | 2222 | nullptr, |
---|
[6f8e87d] | 2223 | GET_LABELS_V(old->labels) |
---|
| 2224 | ); |
---|
[2c04369] | 2225 | cache.emplace( old, stmt ); |
---|
[f685679] | 2226 | stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt); |
---|
[2c04369] | 2227 | this->node = stmt; |
---|
[6d51bd7] | 2228 | } |
---|
| 2229 | |
---|
[6cebfef] | 2230 | virtual void visit( const MutexStmt * old ) override final { |
---|
| 2231 | if ( inCache( old ) ) return; |
---|
| 2232 | this->node = new ast::MutexStmt( |
---|
| 2233 | old->location, |
---|
| 2234 | GET_ACCEPT_1(stmt, Stmt), |
---|
| 2235 | GET_ACCEPT_V(mutexObjs, Expr) |
---|
| 2236 | ); |
---|
| 2237 | cache.emplace( old, this->node ); |
---|
| 2238 | } |
---|
| 2239 | |
---|
[3e5dd913] | 2240 | // TypeSubstitution shouldn't exist yet in old. |
---|
[172d9342] | 2241 | ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) { |
---|
[3e5dd913] | 2242 | |
---|
[8abee136] | 2243 | if (!old) return nullptr; |
---|
[3e5dd913] | 2244 | if (old->empty()) return nullptr; |
---|
| 2245 | assert(false); |
---|
[8abee136] | 2246 | |
---|
[3e5dd913] | 2247 | /* |
---|
[172d9342] | 2248 | ast::TypeSubstitution *rslt = new ast::TypeSubstitution(); |
---|
| 2249 | |
---|
| 2250 | for (decltype(old->begin()) old_i = old->begin(); old_i != old->end(); old_i++) { |
---|
| 2251 | rslt->add( old_i->first, |
---|
| 2252 | getAccept1<ast::Type>(old_i->second) ); |
---|
| 2253 | } |
---|
[6d51bd7] | 2254 | |
---|
[19e567dd] | 2255 | return rslt; |
---|
[3e5dd913] | 2256 | */ |
---|
[6d51bd7] | 2257 | } |
---|
| 2258 | |
---|
[e0016a5] | 2259 | void convertInferUnion(ast::Expr::InferUnion &newInferred, |
---|
[19e567dd] | 2260 | const std::map<UniqueId,ParamEntry> &oldInferParams, |
---|
| 2261 | const std::vector<UniqueId> &oldResnSlots) { |
---|
| 2262 | |
---|
| 2263 | assert( oldInferParams.empty() || oldResnSlots.empty() ); |
---|
[07d867b] | 2264 | // assert( newInferred.mode == ast::Expr::InferUnion::Empty ); |
---|
[19e567dd] | 2265 | |
---|
| 2266 | if ( !oldInferParams.empty() ) { |
---|
| 2267 | ast::InferredParams &tgt = newInferred.inferParams(); |
---|
[8b34df0] | 2268 | for (auto & old : oldInferParams) { |
---|
[19e567dd] | 2269 | tgt[old.first] = ast::ParamEntry( |
---|
| 2270 | old.second.decl, |
---|
[aaeacf4] | 2271 | getAccept1<ast::Decl>(old.second.declptr), |
---|
[19e567dd] | 2272 | getAccept1<ast::Type>(old.second.actualType), |
---|
| 2273 | getAccept1<ast::Type>(old.second.formalType), |
---|
| 2274 | getAccept1<ast::Expr>(old.second.expr) |
---|
| 2275 | ); |
---|
| 2276 | } |
---|
| 2277 | } else if ( !oldResnSlots.empty() ) { |
---|
| 2278 | ast::ResnSlots &tgt = newInferred.resnSlots(); |
---|
| 2279 | for (auto old : oldResnSlots) { |
---|
| 2280 | tgt.push_back(old); |
---|
| 2281 | } |
---|
| 2282 | } |
---|
[172d9342] | 2283 | } |
---|
| 2284 | |
---|
[7870799] | 2285 | ast::Expr * visitBaseExpr_SkipResultType( const Expression * old, ast::Expr * nw) { |
---|
[6d51bd7] | 2286 | |
---|
[172d9342] | 2287 | nw->env = convertTypeSubstitution(old->env); |
---|
| 2288 | |
---|
| 2289 | nw->extension = old->extension; |
---|
| 2290 | convertInferUnion(nw->inferred, old->inferParams, old->resnSlots); |
---|
| 2291 | |
---|
| 2292 | return nw; |
---|
| 2293 | } |
---|
[6d51bd7] | 2294 | |
---|
[7870799] | 2295 | ast::Expr * visitBaseExpr( const Expression * old, ast::Expr * nw) { |
---|
[20de6fb] | 2296 | |
---|
| 2297 | nw->result = GET_ACCEPT_1(result, Type); |
---|
| 2298 | return visitBaseExpr_SkipResultType(old, nw);; |
---|
| 2299 | } |
---|
| 2300 | |
---|
[7870799] | 2301 | virtual void visit( const ApplicationExpr * old ) override final { |
---|
[19e567dd] | 2302 | this->node = visitBaseExpr( old, |
---|
| 2303 | new ast::ApplicationExpr( |
---|
| 2304 | old->location, |
---|
| 2305 | GET_ACCEPT_1(function, Expr), |
---|
| 2306 | GET_ACCEPT_V(args, Expr) |
---|
| 2307 | ) |
---|
| 2308 | ); |
---|
[6d51bd7] | 2309 | } |
---|
| 2310 | |
---|
[7870799] | 2311 | virtual void visit( const UntypedExpr * old ) override final { |
---|
[19e567dd] | 2312 | this->node = visitBaseExpr( old, |
---|
| 2313 | new ast::UntypedExpr( |
---|
| 2314 | old->location, |
---|
| 2315 | GET_ACCEPT_1(function, Expr), |
---|
| 2316 | GET_ACCEPT_V(args, Expr) |
---|
| 2317 | ) |
---|
| 2318 | ); |
---|
[172d9342] | 2319 | } |
---|
[6d51bd7] | 2320 | |
---|
[7870799] | 2321 | virtual void visit( const NameExpr * old ) override final { |
---|
[172d9342] | 2322 | this->node = visitBaseExpr( old, |
---|
| 2323 | new ast::NameExpr( |
---|
| 2324 | old->location, |
---|
| 2325 | old->get_name() |
---|
| 2326 | ) |
---|
| 2327 | ); |
---|
[6d51bd7] | 2328 | } |
---|
| 2329 | |
---|
[b0d9ff7] | 2330 | virtual void visit( const QualifiedNameExpr * old ) override final { |
---|
| 2331 | this->node = visitBaseExpr( old, |
---|
| 2332 | new ast::QualifiedNameExpr ( |
---|
| 2333 | old->location, |
---|
| 2334 | GET_ACCEPT_1(type_decl, Decl), |
---|
| 2335 | old->name |
---|
| 2336 | ) |
---|
| 2337 | ); |
---|
| 2338 | } |
---|
| 2339 | |
---|
[7870799] | 2340 | virtual void visit( const CastExpr * old ) override final { |
---|
[19e567dd] | 2341 | this->node = visitBaseExpr( old, |
---|
| 2342 | new ast::CastExpr( |
---|
| 2343 | old->location, |
---|
[28c89f4] | 2344 | GET_ACCEPT_1(arg, Expr), |
---|
[46da46b] | 2345 | old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast, |
---|
| 2346 | (ast::CastExpr::CastKind) old->kind |
---|
[19e567dd] | 2347 | ) |
---|
| 2348 | ); |
---|
[6d51bd7] | 2349 | } |
---|
| 2350 | |
---|
[312029a] | 2351 | virtual void visit( const KeywordCastExpr * old ) override final { |
---|
| 2352 | ast::AggregateDecl::Aggregate castTarget = (ast::AggregateDecl::Aggregate)old->target; |
---|
| 2353 | assert( ast::AggregateDecl::Generator <= castTarget && castTarget <= ast::AggregateDecl::Thread ); |
---|
[28c89f4] | 2354 | this->node = visitBaseExpr( old, |
---|
| 2355 | new ast::KeywordCastExpr( |
---|
| 2356 | old->location, |
---|
| 2357 | GET_ACCEPT_1(arg, Expr), |
---|
[4ef08f7] | 2358 | castTarget, |
---|
| 2359 | {old->concrete_target.field, old->concrete_target.getter} |
---|
[28c89f4] | 2360 | ) |
---|
| 2361 | ); |
---|
[6d51bd7] | 2362 | } |
---|
| 2363 | |
---|
[7870799] | 2364 | virtual void visit( const VirtualCastExpr * old ) override final { |
---|
[20de6fb] | 2365 | this->node = visitBaseExpr_SkipResultType( old, |
---|
[28c89f4] | 2366 | new ast::VirtualCastExpr( |
---|
| 2367 | old->location, |
---|
| 2368 | GET_ACCEPT_1(arg, Expr), |
---|
[20de6fb] | 2369 | GET_ACCEPT_1(result, Type) |
---|
[28c89f4] | 2370 | ) |
---|
| 2371 | ); |
---|
[6d51bd7] | 2372 | } |
---|
| 2373 | |
---|
[7870799] | 2374 | virtual void visit( const AddressExpr * old ) override final { |
---|
[28c89f4] | 2375 | this->node = visitBaseExpr( old, |
---|
| 2376 | new ast::AddressExpr( |
---|
| 2377 | old->location, |
---|
| 2378 | GET_ACCEPT_1(arg, Expr) |
---|
| 2379 | ) |
---|
| 2380 | ); |
---|
[6d51bd7] | 2381 | } |
---|
| 2382 | |
---|
[7870799] | 2383 | virtual void visit( const LabelAddressExpr * old ) override final { |
---|
[28c89f4] | 2384 | this->node = visitBaseExpr( old, |
---|
| 2385 | new ast::LabelAddressExpr( |
---|
| 2386 | old->location, |
---|
| 2387 | make_label(&old->arg) |
---|
| 2388 | ) |
---|
| 2389 | ); |
---|
[6d51bd7] | 2390 | } |
---|
| 2391 | |
---|
[7870799] | 2392 | virtual void visit( const UntypedMemberExpr * old ) override final { |
---|
[28c89f4] | 2393 | this->node = visitBaseExpr( old, |
---|
| 2394 | new ast::UntypedMemberExpr( |
---|
| 2395 | old->location, |
---|
| 2396 | GET_ACCEPT_1(member, Expr), |
---|
| 2397 | GET_ACCEPT_1(aggregate, Expr) |
---|
| 2398 | ) |
---|
| 2399 | ); |
---|
[6d51bd7] | 2400 | } |
---|
| 2401 | |
---|
[7870799] | 2402 | virtual void visit( const MemberExpr * old ) override final { |
---|
[28c89f4] | 2403 | this->node = visitBaseExpr( old, |
---|
| 2404 | new ast::MemberExpr( |
---|
| 2405 | old->location, |
---|
[2a54479] | 2406 | GET_ACCEPT_1(member, DeclWithType), |
---|
[ae265b55] | 2407 | GET_ACCEPT_1(aggregate, Expr), |
---|
| 2408 | ast::MemberExpr::NoOpConstructionChosen |
---|
[28c89f4] | 2409 | ) |
---|
| 2410 | ); |
---|
[6d51bd7] | 2411 | } |
---|
| 2412 | |
---|
[7870799] | 2413 | virtual void visit( const VariableExpr * old ) override final { |
---|
[546e712] | 2414 | auto expr = new ast::VariableExpr( |
---|
| 2415 | old->location |
---|
| 2416 | ); |
---|
| 2417 | |
---|
| 2418 | expr->var = GET_ACCEPT_1(var, DeclWithType); |
---|
[6896548] | 2419 | visitBaseExpr( old, expr ); |
---|
[6d51bd7] | 2420 | |
---|
[546e712] | 2421 | this->node = expr; |
---|
[6d51bd7] | 2422 | } |
---|
| 2423 | |
---|
[7870799] | 2424 | virtual void visit( const ConstantExpr * old ) override final { |
---|
[c36298d] | 2425 | ast::ConstantExpr *rslt = new ast::ConstantExpr( |
---|
| 2426 | old->location, |
---|
| 2427 | GET_ACCEPT_1(result, Type), |
---|
[7870799] | 2428 | old->constant.rep, |
---|
[c36298d] | 2429 | old->constant.ival |
---|
| 2430 | ); |
---|
[7870799] | 2431 | rslt->underlyer = getAccept1< ast::Type, Type* >( old->constant.type ); |
---|
[28c89f4] | 2432 | this->node = visitBaseExpr( old, rslt ); |
---|
| 2433 | } |
---|
| 2434 | |
---|
[7870799] | 2435 | virtual void visit( const SizeofExpr * old ) override final { |
---|
[28c89f4] | 2436 | assert (old->expr || old->type); |
---|
| 2437 | assert (! (old->expr && old->type)); |
---|
| 2438 | ast::SizeofExpr *rslt; |
---|
| 2439 | if (old->expr) { |
---|
| 2440 | assert(!old->isType); |
---|
| 2441 | rslt = new ast::SizeofExpr( |
---|
[0b57626] | 2442 | old->location, |
---|
[28c89f4] | 2443 | GET_ACCEPT_1(expr, Expr) |
---|
| 2444 | ); |
---|
| 2445 | } |
---|
| 2446 | if (old->type) { |
---|
| 2447 | assert(old->isType); |
---|
| 2448 | rslt = new ast::SizeofExpr( |
---|
[0b57626] | 2449 | old->location, |
---|
[28c89f4] | 2450 | GET_ACCEPT_1(type, Type) |
---|
| 2451 | ); |
---|
| 2452 | } |
---|
| 2453 | this->node = visitBaseExpr( old, rslt ); |
---|
| 2454 | } |
---|
| 2455 | |
---|
[7870799] | 2456 | virtual void visit( const AlignofExpr * old ) override final { |
---|
[28c89f4] | 2457 | assert (old->expr || old->type); |
---|
| 2458 | assert (! (old->expr && old->type)); |
---|
| 2459 | ast::AlignofExpr *rslt; |
---|
| 2460 | if (old->expr) { |
---|
| 2461 | assert(!old->isType); |
---|
| 2462 | rslt = new ast::AlignofExpr( |
---|
[0b57626] | 2463 | old->location, |
---|
[28c89f4] | 2464 | GET_ACCEPT_1(expr, Expr) |
---|
| 2465 | ); |
---|
| 2466 | } |
---|
| 2467 | if (old->type) { |
---|
| 2468 | assert(old->isType); |
---|
| 2469 | rslt = new ast::AlignofExpr( |
---|
[0b57626] | 2470 | old->location, |
---|
[28c89f4] | 2471 | GET_ACCEPT_1(type, Type) |
---|
| 2472 | ); |
---|
| 2473 | } |
---|
| 2474 | this->node = visitBaseExpr( old, rslt ); |
---|
[6d51bd7] | 2475 | } |
---|
| 2476 | |
---|
[7870799] | 2477 | virtual void visit( const UntypedOffsetofExpr * old ) override final { |
---|
[28c89f4] | 2478 | this->node = visitBaseExpr( old, |
---|
| 2479 | new ast::UntypedOffsetofExpr( |
---|
| 2480 | old->location, |
---|
| 2481 | GET_ACCEPT_1(type, Type), |
---|
| 2482 | old->member |
---|
| 2483 | ) |
---|
| 2484 | ); |
---|
[6d51bd7] | 2485 | } |
---|
| 2486 | |
---|
[7870799] | 2487 | virtual void visit( const OffsetofExpr * old ) override final { |
---|
[28c89f4] | 2488 | this->node = visitBaseExpr( old, |
---|
| 2489 | new ast::OffsetofExpr( |
---|
| 2490 | old->location, |
---|
| 2491 | GET_ACCEPT_1(type, Type), |
---|
[2a54479] | 2492 | GET_ACCEPT_1(member, DeclWithType) |
---|
[28c89f4] | 2493 | ) |
---|
| 2494 | ); |
---|
[6d51bd7] | 2495 | } |
---|
| 2496 | |
---|
[7870799] | 2497 | virtual void visit( const OffsetPackExpr * old ) override final { |
---|
[28c89f4] | 2498 | this->node = visitBaseExpr( old, |
---|
| 2499 | new ast::OffsetPackExpr( |
---|
| 2500 | old->location, |
---|
| 2501 | GET_ACCEPT_1(type, StructInstType) |
---|
| 2502 | ) |
---|
| 2503 | ); |
---|
[6d51bd7] | 2504 | } |
---|
| 2505 | |
---|
[7870799] | 2506 | virtual void visit( const LogicalExpr * old ) override final { |
---|
[28c89f4] | 2507 | this->node = visitBaseExpr( old, |
---|
| 2508 | new ast::LogicalExpr( |
---|
| 2509 | old->location, |
---|
| 2510 | GET_ACCEPT_1(arg1, Expr), |
---|
| 2511 | GET_ACCEPT_1(arg2, Expr), |
---|
[0b57626] | 2512 | old->get_isAnd() ? |
---|
[28c89f4] | 2513 | ast::LogicalFlag::AndExpr : |
---|
| 2514 | ast::LogicalFlag::OrExpr |
---|
| 2515 | ) |
---|
| 2516 | ); |
---|
[6d51bd7] | 2517 | } |
---|
| 2518 | |
---|
[7870799] | 2519 | virtual void visit( const ConditionalExpr * old ) override final { |
---|
[28c89f4] | 2520 | this->node = visitBaseExpr( old, |
---|
| 2521 | new ast::ConditionalExpr( |
---|
| 2522 | old->location, |
---|
| 2523 | GET_ACCEPT_1(arg1, Expr), |
---|
| 2524 | GET_ACCEPT_1(arg2, Expr), |
---|
| 2525 | GET_ACCEPT_1(arg3, Expr) |
---|
| 2526 | ) |
---|
| 2527 | ); |
---|
| 2528 | } |
---|
[6d51bd7] | 2529 | |
---|
[7870799] | 2530 | virtual void visit( const CommaExpr * old ) override final { |
---|
[28c89f4] | 2531 | this->node = visitBaseExpr( old, |
---|
| 2532 | new ast::CommaExpr( |
---|
| 2533 | old->location, |
---|
| 2534 | GET_ACCEPT_1(arg1, Expr), |
---|
| 2535 | GET_ACCEPT_1(arg2, Expr) |
---|
| 2536 | ) |
---|
| 2537 | ); |
---|
[6d51bd7] | 2538 | } |
---|
| 2539 | |
---|
[7870799] | 2540 | virtual void visit( const TypeExpr * old ) override final { |
---|
[20de6fb] | 2541 | this->node = visitBaseExpr( old, |
---|
| 2542 | new ast::TypeExpr( |
---|
| 2543 | old->location, |
---|
| 2544 | GET_ACCEPT_1(type, Type) |
---|
| 2545 | ) |
---|
| 2546 | ); |
---|
[6d51bd7] | 2547 | } |
---|
| 2548 | |
---|
[6e50a6b] | 2549 | virtual void visit( const DimensionExpr * old ) override final { |
---|
[4ec9513] | 2550 | this->node = visitBaseExpr( old, |
---|
| 2551 | new ast::DimensionExpr( old->location, old->name ) |
---|
| 2552 | ); |
---|
[6e50a6b] | 2553 | } |
---|
| 2554 | |
---|
[7870799] | 2555 | virtual void visit( const AsmExpr * old ) override final { |
---|
[20de6fb] | 2556 | this->node = visitBaseExpr( old, |
---|
| 2557 | new ast::AsmExpr( |
---|
| 2558 | old->location, |
---|
[665f432] | 2559 | old->inout, |
---|
[20de6fb] | 2560 | GET_ACCEPT_1(constraint, Expr), |
---|
| 2561 | GET_ACCEPT_1(operand, Expr) |
---|
| 2562 | ) |
---|
| 2563 | ); |
---|
[6d51bd7] | 2564 | } |
---|
| 2565 | |
---|
[7870799] | 2566 | virtual void visit( const ImplicitCopyCtorExpr * old ) override final { |
---|
[20de6fb] | 2567 | auto rslt = new ast::ImplicitCopyCtorExpr( |
---|
| 2568 | old->location, |
---|
| 2569 | GET_ACCEPT_1(callExpr, ApplicationExpr) |
---|
| 2570 | ); |
---|
[6d51bd7] | 2571 | |
---|
[20de6fb] | 2572 | this->node = visitBaseExpr( old, rslt ); |
---|
[6d51bd7] | 2573 | } |
---|
| 2574 | |
---|
[7870799] | 2575 | virtual void visit( const ConstructorExpr * old ) override final { |
---|
[20de6fb] | 2576 | this->node = visitBaseExpr( old, |
---|
| 2577 | new ast::ConstructorExpr( |
---|
| 2578 | old->location, |
---|
| 2579 | GET_ACCEPT_1(callExpr, Expr) |
---|
| 2580 | ) |
---|
| 2581 | ); |
---|
[6d51bd7] | 2582 | } |
---|
| 2583 | |
---|
[7870799] | 2584 | virtual void visit( const CompoundLiteralExpr * old ) override final { |
---|
[20de6fb] | 2585 | this->node = visitBaseExpr_SkipResultType( old, |
---|
| 2586 | new ast::CompoundLiteralExpr( |
---|
| 2587 | old->location, |
---|
| 2588 | GET_ACCEPT_1(result, Type), |
---|
| 2589 | GET_ACCEPT_1(initializer, Init) |
---|
| 2590 | ) |
---|
| 2591 | ); |
---|
[6d51bd7] | 2592 | } |
---|
| 2593 | |
---|
[7870799] | 2594 | virtual void visit( const RangeExpr * old ) override final { |
---|
[20de6fb] | 2595 | this->node = visitBaseExpr( old, |
---|
| 2596 | new ast::RangeExpr( |
---|
| 2597 | old->location, |
---|
| 2598 | GET_ACCEPT_1(low, Expr), |
---|
| 2599 | GET_ACCEPT_1(high, Expr) |
---|
| 2600 | ) |
---|
| 2601 | ); |
---|
[6d51bd7] | 2602 | } |
---|
| 2603 | |
---|
[7870799] | 2604 | virtual void visit( const UntypedTupleExpr * old ) override final { |
---|
[20de6fb] | 2605 | this->node = visitBaseExpr( old, |
---|
| 2606 | new ast::UntypedTupleExpr( |
---|
| 2607 | old->location, |
---|
| 2608 | GET_ACCEPT_V(exprs, Expr) |
---|
| 2609 | ) |
---|
| 2610 | ); |
---|
[6d51bd7] | 2611 | } |
---|
| 2612 | |
---|
[7870799] | 2613 | virtual void visit( const TupleExpr * old ) override final { |
---|
[20de6fb] | 2614 | this->node = visitBaseExpr( old, |
---|
| 2615 | new ast::TupleExpr( |
---|
| 2616 | old->location, |
---|
| 2617 | GET_ACCEPT_V(exprs, Expr) |
---|
| 2618 | ) |
---|
| 2619 | ); |
---|
[6d51bd7] | 2620 | } |
---|
| 2621 | |
---|
[7870799] | 2622 | virtual void visit( const TupleIndexExpr * old ) override final { |
---|
[20de6fb] | 2623 | this->node = visitBaseExpr( old, |
---|
| 2624 | new ast::TupleIndexExpr( |
---|
| 2625 | old->location, |
---|
| 2626 | GET_ACCEPT_1(tuple, Expr), |
---|
| 2627 | old->index |
---|
| 2628 | ) |
---|
| 2629 | ); |
---|
[6d51bd7] | 2630 | } |
---|
| 2631 | |
---|
[7870799] | 2632 | virtual void visit( const TupleAssignExpr * old ) override final { |
---|
[20de6fb] | 2633 | this->node = visitBaseExpr_SkipResultType( old, |
---|
| 2634 | new ast::TupleAssignExpr( |
---|
| 2635 | old->location, |
---|
| 2636 | GET_ACCEPT_1(result, Type), |
---|
| 2637 | GET_ACCEPT_1(stmtExpr, StmtExpr) |
---|
| 2638 | ) |
---|
| 2639 | ); |
---|
[6d51bd7] | 2640 | } |
---|
| 2641 | |
---|
[7870799] | 2642 | virtual void visit( const StmtExpr * old ) override final { |
---|
[20de6fb] | 2643 | auto rslt = new ast::StmtExpr( |
---|
| 2644 | old->location, |
---|
| 2645 | GET_ACCEPT_1(statements, CompoundStmt) |
---|
| 2646 | ); |
---|
| 2647 | rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); |
---|
| 2648 | rslt->dtors = GET_ACCEPT_V(dtors , Expr); |
---|
[6d51bd7] | 2649 | |
---|
[20de6fb] | 2650 | this->node = visitBaseExpr_SkipResultType( old, rslt ); |
---|
[6d51bd7] | 2651 | } |
---|
| 2652 | |
---|
[7870799] | 2653 | virtual void visit( const UniqueExpr * old ) override final { |
---|
[20de6fb] | 2654 | auto rslt = new ast::UniqueExpr( |
---|
| 2655 | old->location, |
---|
[a2a85658] | 2656 | GET_ACCEPT_1(expr, Expr), |
---|
| 2657 | old->get_id() |
---|
[20de6fb] | 2658 | ); |
---|
| 2659 | rslt->object = GET_ACCEPT_1(object, ObjectDecl); |
---|
| 2660 | rslt->var = GET_ACCEPT_1(var , VariableExpr); |
---|
[6d51bd7] | 2661 | |
---|
[20de6fb] | 2662 | this->node = visitBaseExpr( old, rslt ); |
---|
[6d51bd7] | 2663 | } |
---|
| 2664 | |
---|
[7870799] | 2665 | virtual void visit( const UntypedInitExpr * old ) override final { |
---|
[60aaa51d] | 2666 | std::deque<ast::InitAlternative> initAlts; |
---|
[20de6fb] | 2667 | for (auto ia : old->initAlts) { |
---|
| 2668 | initAlts.push_back(ast::InitAlternative( |
---|
| 2669 | getAccept1< ast::Type, Type * >( ia.type ), |
---|
| 2670 | getAccept1< ast::Designation, Designation * >( ia.designation ) |
---|
| 2671 | )); |
---|
| 2672 | } |
---|
| 2673 | this->node = visitBaseExpr( old, |
---|
| 2674 | new ast::UntypedInitExpr( |
---|
| 2675 | old->location, |
---|
| 2676 | GET_ACCEPT_1(expr, Expr), |
---|
| 2677 | std::move(initAlts) |
---|
| 2678 | ) |
---|
| 2679 | ); |
---|
[6d51bd7] | 2680 | } |
---|
| 2681 | |
---|
[7870799] | 2682 | virtual void visit( const InitExpr * old ) override final { |
---|
[20de6fb] | 2683 | this->node = visitBaseExpr( old, |
---|
| 2684 | new ast::InitExpr( |
---|
| 2685 | old->location, |
---|
| 2686 | GET_ACCEPT_1(expr, Expr), |
---|
| 2687 | GET_ACCEPT_1(designation, Designation) |
---|
| 2688 | ) |
---|
| 2689 | ); |
---|
[6d51bd7] | 2690 | } |
---|
| 2691 | |
---|
[7870799] | 2692 | virtual void visit( const DeletedExpr * old ) override final { |
---|
[20de6fb] | 2693 | this->node = visitBaseExpr( old, |
---|
| 2694 | new ast::DeletedExpr( |
---|
| 2695 | old->location, |
---|
| 2696 | GET_ACCEPT_1(expr, Expr), |
---|
| 2697 | inCache(old->deleteStmt) ? |
---|
[e67991f] | 2698 | strict_dynamic_cast<ast::Decl*>(this->node) : |
---|
| 2699 | GET_ACCEPT_1(deleteStmt, Decl) |
---|
[20de6fb] | 2700 | ) |
---|
| 2701 | ); |
---|
[6d51bd7] | 2702 | } |
---|
| 2703 | |
---|
[7870799] | 2704 | virtual void visit( const DefaultArgExpr * old ) override final { |
---|
[20de6fb] | 2705 | this->node = visitBaseExpr( old, |
---|
| 2706 | new ast::DefaultArgExpr( |
---|
| 2707 | old->location, |
---|
| 2708 | GET_ACCEPT_1(expr, Expr) |
---|
| 2709 | ) |
---|
| 2710 | ); |
---|
| 2711 | } |
---|
[6d51bd7] | 2712 | |
---|
[7870799] | 2713 | virtual void visit( const GenericExpr * old ) override final { |
---|
[20de6fb] | 2714 | std::vector<ast::GenericExpr::Association> associations; |
---|
| 2715 | for (auto association : old->associations) { |
---|
| 2716 | associations.push_back(ast::GenericExpr::Association( |
---|
| 2717 | getAccept1< ast::Type, Type * >( association.type ), |
---|
| 2718 | getAccept1< ast::Expr, Expression * >( association.expr ) |
---|
| 2719 | )); |
---|
| 2720 | } |
---|
| 2721 | this->node = visitBaseExpr( old, |
---|
| 2722 | new ast::GenericExpr( |
---|
| 2723 | old->location, |
---|
| 2724 | GET_ACCEPT_1(control, Expr), |
---|
| 2725 | std::move(associations) |
---|
| 2726 | ) |
---|
| 2727 | ); |
---|
[6d51bd7] | 2728 | } |
---|
| 2729 | |
---|
[7870799] | 2730 | void visitType( const Type * old, ast::Type * type ) { |
---|
[1ae47de] | 2731 | // Some types do this in their constructor so add a check. |
---|
| 2732 | if ( !old->attributes.empty() && type->attributes.empty() ) { |
---|
| 2733 | type->attributes = GET_ACCEPT_V(attributes, Attribute); |
---|
| 2734 | } |
---|
| 2735 | this->node = type; |
---|
| 2736 | } |
---|
| 2737 | |
---|
[7870799] | 2738 | virtual void visit( const VoidType * old ) override final { |
---|
[1ae47de] | 2739 | visitType( old, new ast::VoidType{ cv( old ) } ); |
---|
[6d51bd7] | 2740 | } |
---|
| 2741 | |
---|
[7870799] | 2742 | virtual void visit( const BasicType * old ) override final { |
---|
[2a54479] | 2743 | auto type = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) }; |
---|
| 2744 | // I believe this should always be a BasicType. |
---|
| 2745 | if ( Validate::SizeType == old ) { |
---|
[490fb92e] | 2746 | ast::sizeType = type; |
---|
[2a54479] | 2747 | } |
---|
[1ae47de] | 2748 | visitType( old, type ); |
---|
[6d51bd7] | 2749 | } |
---|
| 2750 | |
---|
[7870799] | 2751 | virtual void visit( const PointerType * old ) override final { |
---|
[1ae47de] | 2752 | visitType( old, new ast::PointerType{ |
---|
[d148778] | 2753 | GET_ACCEPT_1( base, Type ), |
---|
| 2754 | GET_ACCEPT_1( dimension, Expr ), |
---|
| 2755 | (ast::LengthFlag)old->isVarLen, |
---|
| 2756 | (ast::DimensionFlag)old->isStatic, |
---|
| 2757 | cv( old ) |
---|
[1ae47de] | 2758 | } ); |
---|
[6d51bd7] | 2759 | } |
---|
| 2760 | |
---|
[7870799] | 2761 | virtual void visit( const ArrayType * old ) override final { |
---|
[1ae47de] | 2762 | visitType( old, new ast::ArrayType{ |
---|
[d148778] | 2763 | GET_ACCEPT_1( base, Type ), |
---|
| 2764 | GET_ACCEPT_1( dimension, Expr ), |
---|
| 2765 | (ast::LengthFlag)old->isVarLen, |
---|
| 2766 | (ast::DimensionFlag)old->isStatic, |
---|
| 2767 | cv( old ) |
---|
[1ae47de] | 2768 | } ); |
---|
[6d51bd7] | 2769 | } |
---|
| 2770 | |
---|
[7870799] | 2771 | virtual void visit( const ReferenceType * old ) override final { |
---|
[1ae47de] | 2772 | visitType( old, new ast::ReferenceType{ |
---|
[d148778] | 2773 | GET_ACCEPT_1( base, Type ), |
---|
| 2774 | cv( old ) |
---|
[1ae47de] | 2775 | } ); |
---|
[6d51bd7] | 2776 | } |
---|
| 2777 | |
---|
[7870799] | 2778 | virtual void visit( const QualifiedType * old ) override final { |
---|
[1ae47de] | 2779 | visitType( old, new ast::QualifiedType{ |
---|
[d148778] | 2780 | GET_ACCEPT_1( parent, Type ), |
---|
| 2781 | GET_ACCEPT_1( child, Type ), |
---|
| 2782 | cv( old ) |
---|
[1ae47de] | 2783 | } ); |
---|
[6d51bd7] | 2784 | } |
---|
| 2785 | |
---|
[7870799] | 2786 | virtual void visit( const FunctionType * old ) override final { |
---|
[d148778] | 2787 | auto ty = new ast::FunctionType { |
---|
| 2788 | (ast::ArgumentFlag)old->isVarArgs, |
---|
| 2789 | cv( old ) |
---|
| 2790 | }; |
---|
[954c954] | 2791 | auto returnVars = GET_ACCEPT_V(returnVals, DeclWithType); |
---|
| 2792 | auto paramVars = GET_ACCEPT_V(parameters, DeclWithType); |
---|
| 2793 | // ty->returns = GET_ACCEPT_V( returnVals, DeclWithType ); |
---|
| 2794 | // ty->params = GET_ACCEPT_V( parameters, DeclWithType ); |
---|
| 2795 | for (auto & v: returnVars) { |
---|
| 2796 | ty->returns.emplace_back(v->get_type()); |
---|
| 2797 | } |
---|
| 2798 | for (auto & v: paramVars) { |
---|
| 2799 | ty->params.emplace_back(v->get_type()); |
---|
| 2800 | } |
---|
[3e5dd913] | 2801 | // xxx - when will this be non-null? |
---|
| 2802 | // will have to create dangling (no-owner) decls to be pointed to |
---|
| 2803 | auto foralls = GET_ACCEPT_V( forall, TypeDecl ); |
---|
| 2804 | |
---|
| 2805 | for (auto & param : foralls) { |
---|
[b230091] | 2806 | ty->forall.emplace_back(new ast::TypeInstType(param)); |
---|
[3e5dd913] | 2807 | for (auto asst : param->assertions) { |
---|
[298fe57] | 2808 | ty->assertions.emplace_back( |
---|
| 2809 | new ast::VariableExpr(param->location, asst)); |
---|
[3e5dd913] | 2810 | } |
---|
| 2811 | } |
---|
[1ae47de] | 2812 | visitType( old, ty ); |
---|
[6d51bd7] | 2813 | } |
---|
| 2814 | |
---|
[98e8b3b] | 2815 | void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) { |
---|
[d148778] | 2816 | ty->params = GET_ACCEPT_V( parameters, Expr ); |
---|
| 2817 | ty->hoistType = old->hoistType; |
---|
[1ae47de] | 2818 | visitType( old, ty ); |
---|
[6d51bd7] | 2819 | } |
---|
| 2820 | |
---|
[7870799] | 2821 | virtual void visit( const StructInstType * old ) override final { |
---|
[b869ec5] | 2822 | ast::StructInstType * ty; |
---|
| 2823 | if ( old->baseStruct ) { |
---|
| 2824 | ty = new ast::StructInstType{ |
---|
| 2825 | GET_ACCEPT_1( baseStruct, StructDecl ), |
---|
| 2826 | cv( old ), |
---|
| 2827 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2828 | }; |
---|
| 2829 | } else { |
---|
| 2830 | ty = new ast::StructInstType{ |
---|
| 2831 | old->name, |
---|
| 2832 | cv( old ), |
---|
| 2833 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2834 | }; |
---|
| 2835 | } |
---|
[d148778] | 2836 | postvisit( old, ty ); |
---|
[6d51bd7] | 2837 | } |
---|
| 2838 | |
---|
[7870799] | 2839 | virtual void visit( const UnionInstType * old ) override final { |
---|
[b869ec5] | 2840 | ast::UnionInstType * ty; |
---|
| 2841 | if ( old->baseUnion ) { |
---|
| 2842 | ty = new ast::UnionInstType{ |
---|
| 2843 | GET_ACCEPT_1( baseUnion, UnionDecl ), |
---|
| 2844 | cv( old ), |
---|
| 2845 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2846 | }; |
---|
| 2847 | } else { |
---|
| 2848 | ty = new ast::UnionInstType{ |
---|
| 2849 | old->name, |
---|
| 2850 | cv( old ), |
---|
| 2851 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2852 | }; |
---|
| 2853 | } |
---|
[d148778] | 2854 | postvisit( old, ty ); |
---|
[6d51bd7] | 2855 | } |
---|
| 2856 | |
---|
[374cb117] | 2857 | virtual void visit( const EnumInstType * old ) override final { |
---|
[3e54399] | 2858 | ast::EnumInstType * ty; |
---|
[b869ec5] | 2859 | if ( old->baseEnum ) { |
---|
[374cb117] | 2860 | ty = new ast::EnumInstType{ |
---|
[b869ec5] | 2861 | GET_ACCEPT_1( baseEnum, EnumDecl ), |
---|
| 2862 | cv( old ), |
---|
| 2863 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2864 | }; |
---|
| 2865 | } else { |
---|
| 2866 | ty = new ast::EnumInstType{ |
---|
| 2867 | old->name, |
---|
| 2868 | cv( old ), |
---|
| 2869 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2870 | }; |
---|
| 2871 | } |
---|
[d148778] | 2872 | postvisit( old, ty ); |
---|
[6d51bd7] | 2873 | } |
---|
| 2874 | |
---|
[7870799] | 2875 | virtual void visit( const TraitInstType * old ) override final { |
---|
[b869ec5] | 2876 | ast::TraitInstType * ty; |
---|
| 2877 | if ( old->baseTrait ) { |
---|
| 2878 | ty = new ast::TraitInstType{ |
---|
| 2879 | GET_ACCEPT_1( baseTrait, TraitDecl ), |
---|
| 2880 | cv( old ), |
---|
| 2881 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2882 | }; |
---|
| 2883 | } else { |
---|
| 2884 | ty = new ast::TraitInstType{ |
---|
| 2885 | old->name, |
---|
| 2886 | cv( old ), |
---|
| 2887 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2888 | }; |
---|
| 2889 | } |
---|
[d148778] | 2890 | postvisit( old, ty ); |
---|
| 2891 | } |
---|
[6d51bd7] | 2892 | |
---|
[7870799] | 2893 | virtual void visit( const TypeInstType * old ) override final { |
---|
[514a791] | 2894 | ast::TypeInstType * ty; |
---|
| 2895 | if ( old->baseType ) { |
---|
| 2896 | ty = new ast::TypeInstType{ |
---|
| 2897 | old->name, |
---|
[b869ec5] | 2898 | GET_ACCEPT_1( baseType, TypeDecl ), |
---|
[514a791] | 2899 | cv( old ), |
---|
| 2900 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2901 | }; |
---|
| 2902 | } else { |
---|
| 2903 | ty = new ast::TypeInstType{ |
---|
| 2904 | old->name, |
---|
[07de76b] | 2905 | old->isFtype ? ast::TypeDecl::Ftype : ast::TypeDecl::Dtype, |
---|
[514a791] | 2906 | cv( old ), |
---|
| 2907 | GET_ACCEPT_V( attributes, Attribute ) |
---|
| 2908 | }; |
---|
| 2909 | } |
---|
[d148778] | 2910 | postvisit( old, ty ); |
---|
[6d51bd7] | 2911 | } |
---|
| 2912 | |
---|
[7870799] | 2913 | virtual void visit( const TupleType * old ) override final { |
---|
[1ae47de] | 2914 | visitType( old, new ast::TupleType{ |
---|
[746ae82] | 2915 | GET_ACCEPT_V( types, Type ), |
---|
| 2916 | // members generated by TupleType c'tor |
---|
| 2917 | cv( old ) |
---|
[1ae47de] | 2918 | } ); |
---|
[6d51bd7] | 2919 | } |
---|
| 2920 | |
---|
[7870799] | 2921 | virtual void visit( const TypeofType * old ) override final { |
---|
[1ae47de] | 2922 | visitType( old, new ast::TypeofType{ |
---|
[746ae82] | 2923 | GET_ACCEPT_1( expr, Expr ), |
---|
| 2924 | (ast::TypeofType::Kind)old->is_basetypeof, |
---|
| 2925 | cv( old ) |
---|
[1ae47de] | 2926 | } ); |
---|
[6d51bd7] | 2927 | } |
---|
| 2928 | |
---|
[cc64be1d] | 2929 | virtual void visit( const VTableType * old ) override final { |
---|
| 2930 | visitType( old, new ast::VTableType{ |
---|
| 2931 | GET_ACCEPT_1( base, Type ), |
---|
| 2932 | cv( old ) |
---|
| 2933 | } ); |
---|
| 2934 | } |
---|
| 2935 | |
---|
[7870799] | 2936 | virtual void visit( const AttrType * ) override final { |
---|
[746ae82] | 2937 | assertf( false, "AttrType deprecated in new AST." ); |
---|
[6d51bd7] | 2938 | } |
---|
| 2939 | |
---|
[7870799] | 2940 | virtual void visit( const VarArgsType * old ) override final { |
---|
[1ae47de] | 2941 | visitType( old, new ast::VarArgsType{ cv( old ) } ); |
---|
[6d51bd7] | 2942 | } |
---|
| 2943 | |
---|
[7870799] | 2944 | virtual void visit( const ZeroType * old ) override final { |
---|
[1ae47de] | 2945 | visitType( old, new ast::ZeroType{ cv( old ) } ); |
---|
[6d51bd7] | 2946 | } |
---|
| 2947 | |
---|
[7870799] | 2948 | virtual void visit( const OneType * old ) override final { |
---|
[1ae47de] | 2949 | visitType( old, new ast::OneType{ cv( old ) } ); |
---|
[6d51bd7] | 2950 | } |
---|
| 2951 | |
---|
[7870799] | 2952 | virtual void visit( const GlobalScopeType * old ) override final { |
---|
[1ae47de] | 2953 | visitType( old, new ast::GlobalScopeType{} ); |
---|
[6d51bd7] | 2954 | } |
---|
| 2955 | |
---|
[7870799] | 2956 | virtual void visit( const Designation * old ) override final { |
---|
[74ad8c0] | 2957 | this->node = new ast::Designation( |
---|
| 2958 | old->location, |
---|
[60aaa51d] | 2959 | GET_ACCEPT_D(designators, Expr) |
---|
[74ad8c0] | 2960 | ); |
---|
[6d51bd7] | 2961 | } |
---|
| 2962 | |
---|
[7870799] | 2963 | virtual void visit( const SingleInit * old ) override final { |
---|
[74ad8c0] | 2964 | this->node = new ast::SingleInit( |
---|
| 2965 | old->location, |
---|
| 2966 | GET_ACCEPT_1(value, Expr), |
---|
[16ba4a6f] | 2967 | (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct |
---|
[74ad8c0] | 2968 | ); |
---|
[6d51bd7] | 2969 | } |
---|
| 2970 | |
---|
[7870799] | 2971 | virtual void visit( const ListInit * old ) override final { |
---|
[74ad8c0] | 2972 | this->node = new ast::ListInit( |
---|
| 2973 | old->location, |
---|
| 2974 | GET_ACCEPT_V(initializers, Init), |
---|
| 2975 | GET_ACCEPT_V(designations, Designation), |
---|
[16ba4a6f] | 2976 | (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct |
---|
[74ad8c0] | 2977 | ); |
---|
[6d51bd7] | 2978 | } |
---|
| 2979 | |
---|
[7870799] | 2980 | virtual void visit( const ConstructorInit * old ) override final { |
---|
[74ad8c0] | 2981 | this->node = new ast::ConstructorInit( |
---|
| 2982 | old->location, |
---|
| 2983 | GET_ACCEPT_1(ctor, Stmt), |
---|
| 2984 | GET_ACCEPT_1(dtor, Stmt), |
---|
| 2985 | GET_ACCEPT_1(init, Init) |
---|
| 2986 | ); |
---|
[6d51bd7] | 2987 | } |
---|
| 2988 | |
---|
[7870799] | 2989 | virtual void visit( const Constant * ) override final { |
---|
[dd6d7c6] | 2990 | // Handled in visit( ConstantEpxr * ). |
---|
| 2991 | // In the new tree, Constant fields are inlined into containing ConstantExpression. |
---|
| 2992 | assert( 0 ); |
---|
[6d51bd7] | 2993 | } |
---|
| 2994 | |
---|
[7870799] | 2995 | virtual void visit( const Attribute * old ) override final { |
---|
[dd6d7c6] | 2996 | this->node = new ast::Attribute( |
---|
| 2997 | old->name, |
---|
| 2998 | GET_ACCEPT_V( parameters, Expr ) |
---|
| 2999 | ); |
---|
[6d51bd7] | 3000 | } |
---|
| 3001 | }; |
---|
| 3002 | |
---|
[6f8e87d] | 3003 | #undef GET_LABELS_V |
---|
| 3004 | #undef GET_ACCEPT_V |
---|
| 3005 | #undef GET_ACCEPT_1 |
---|
| 3006 | |
---|
[293dc1c] | 3007 | ast::TranslationUnit convert( const std::list< Declaration * > && translationUnit ) { |
---|
[6d51bd7] | 3008 | ConverterOldToNew c; |
---|
[293dc1c] | 3009 | ast::TranslationUnit unit; |
---|
[b3a0df6] | 3010 | if (Validate::SizeType) { |
---|
| 3011 | // this should be a BasicType. |
---|
| 3012 | auto old = strict_dynamic_cast<BasicType *>(Validate::SizeType); |
---|
| 3013 | ast::sizeType = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind }; |
---|
| 3014 | } |
---|
| 3015 | |
---|
[6d51bd7] | 3016 | for(auto d : translationUnit) { |
---|
| 3017 | d->accept( c ); |
---|
[293dc1c] | 3018 | unit.decls.emplace_back( c.decl() ); |
---|
[6d51bd7] | 3019 | } |
---|
[8abee136] | 3020 | deleteAll(translationUnit); |
---|
[23954b6] | 3021 | |
---|
| 3022 | // Load the local static varables into the global store. |
---|
| 3023 | unit.global.sizeType = ast::sizeType; |
---|
| 3024 | unit.global.dereference = ast::dereferenceOperator; |
---|
| 3025 | unit.global.dtorStruct = ast::dtorStruct; |
---|
| 3026 | unit.global.dtorDestroy = ast::dtorStructDestroy; |
---|
| 3027 | |
---|
[293dc1c] | 3028 | return unit; |
---|
[6f8e87d] | 3029 | } |
---|