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