source: src/AST/Convert.cpp@ 12df6fe

ADT ast-experimental pthread-emulation qualifiedEnum
Last change on this file since 12df6fe was b0d9ff7, checked in by JiadaL <j82liang@…>, 3 years ago

Fix up the QualifiedNameExpr. It should now work on both old AST and new AST. There are some known bugs to fix so make all-tests will fail.

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