source: src/AST/Convert.cpp@ 3c79ea9

ADT ast-experimental pthread-emulation qualifiedEnum
Last change on this file since 3c79ea9 was 4ec9513, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Converted validate C, including adding DimensionExpr to the new ast.

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