source: src/AST/Convert.cpp@ b787cad

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since b787cad was 92538ab, checked in by JiadaL <j82liang@…>, 3 years ago

Resolve conflict

  • Property mode set to 100644
File size: 81.4 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
953 const ast::Expr * visit( const ast::AsmExpr * node ) override final {
[20de6fb]954 auto expr = visitBaseExpr( node,
955 new AsmExpr(
[665f432]956 new std::string(node->inout),
[20de6fb]957 get<Expression>().accept1(node->constraint),
958 get<Expression>().accept1(node->operand)
959 )
960 );
961 this->node = expr;
[74dbbf6]962 return nullptr;
963 }
964
965 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
[20de6fb]966 auto rslt = new ImplicitCopyCtorExpr(
967 get<ApplicationExpr>().accept1(node->callExpr)
968 );
969
970 auto expr = visitBaseExpr( node, rslt );
971 this->node = expr;
[74dbbf6]972 return nullptr;
973 }
974
975 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
[20de6fb]976 auto expr = visitBaseExpr( node,
977 new ConstructorExpr(
978 get<Expression>().accept1(node->callExpr)
979 )
980 );
981 this->node = expr;
[74dbbf6]982 return nullptr;
983 }
984
985 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
[20de6fb]986 auto expr = visitBaseExpr_skipResultType( node,
987 new CompoundLiteralExpr(
988 get<Type>().accept1(node->result),
989 get<Initializer>().accept1(node->init)
990 )
991 );
992 this->node = expr;
[74dbbf6]993 return nullptr;
994 }
995
996 const ast::Expr * visit( const ast::RangeExpr * node ) override final {
[20de6fb]997 auto expr = visitBaseExpr( node,
998 new RangeExpr(
999 get<Expression>().accept1(node->low),
1000 get<Expression>().accept1(node->high)
1001 )
1002 );
1003 this->node = expr;
[74dbbf6]1004 return nullptr;
1005 }
1006
1007 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
[20de6fb]1008 auto expr = visitBaseExpr( node,
1009 new UntypedTupleExpr(
1010 get<Expression>().acceptL(node->exprs)
1011 )
1012 );
1013 this->node = expr;
[74dbbf6]1014 return nullptr;
1015 }
1016
1017 const ast::Expr * visit( const ast::TupleExpr * node ) override final {
[20de6fb]1018 auto expr = visitBaseExpr( node,
[6e55240]1019 new TupleExpr(
[20de6fb]1020 get<Expression>().acceptL(node->exprs)
1021 )
1022 );
1023 this->node = expr;
[74dbbf6]1024 return nullptr;
1025 }
1026
1027 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
[20de6fb]1028 auto expr = visitBaseExpr( node,
1029 new TupleIndexExpr(
1030 get<Expression>().accept1(node->tuple),
1031 node->index
1032 )
1033 );
1034 this->node = expr;
[74dbbf6]1035 return nullptr;
1036 }
1037
1038 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
[20de6fb]1039 auto expr = visitBaseExpr( node,
1040 new TupleAssignExpr(
1041 get<StmtExpr>().accept1(node->stmtExpr)
1042 )
1043 );
1044 this->node = expr;
[74dbbf6]1045 return nullptr;
1046 }
1047
1048 const ast::Expr * visit( const ast::StmtExpr * node ) override final {
[20de6fb]1049 auto rslt = new StmtExpr(
[bb9924c]1050 get<CompoundStmt>().accept1(node->stmts)
[20de6fb]1051 );
1052
1053 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
1054 rslt->dtors = get<Expression>().acceptL(node->dtors);
[bb9924c]1055
1056 // is this even used after convert?
1057 //if (tmp->resultExpr) {
1058 // // this MUST be found by children visit
1059 // rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(tmp->resultExpr));
1060 //}
[20de6fb]1061
1062 auto expr = visitBaseExpr( node, rslt );
1063 this->node = expr;
[74dbbf6]1064 return nullptr;
1065 }
1066
1067 const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
[20de6fb]1068 auto rslt = new UniqueExpr(
[a2a85658]1069 get<Expression>().accept1(node->expr),
1070 node->id
[20de6fb]1071 );
1072
1073 rslt->object = get<ObjectDecl> ().accept1(node->object);
1074 rslt->var = get<VariableExpr>().accept1(node->var);
1075
1076 auto expr = visitBaseExpr( node, rslt );
[490fb92e]1077 this->node = expr->clone();
[74dbbf6]1078 return nullptr;
1079 }
1080
1081 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
[20de6fb]1082 std::list<InitAlternative> initAlts;
1083 for (auto ia : node->initAlts) {
1084 initAlts.push_back(InitAlternative(
1085 get<Type> ().accept1(ia.type),
1086 get<Designation>().accept1(ia.designation)
1087 ));
1088 }
1089 auto expr = visitBaseExpr( node,
1090 new UntypedInitExpr(
1091 get<Expression>().accept1(node->expr),
1092 initAlts
1093 )
1094 );
1095 this->node = expr;
[74dbbf6]1096 return nullptr;
1097 }
1098
1099 const ast::Expr * visit( const ast::InitExpr * node ) override final {
[20de6fb]1100 auto expr = visitBaseExpr( node,
1101 new InitExpr(
1102 get<Expression>().accept1(node->expr),
1103 get<Designation>().accept1(node->designation)
1104 )
1105 );
1106 this->node = expr;
[74dbbf6]1107 return nullptr;
1108 }
1109
1110 const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
[20de6fb]1111 auto expr = visitBaseExpr( node,
1112 new DeletedExpr(
1113 get<Expression>().accept1(node->expr),
1114 inCache(node->deleteStmt) ?
[e67991f]1115 strict_dynamic_cast<Declaration*>(this->node) :
1116 get<Declaration>().accept1(node->deleteStmt)
[20de6fb]1117 )
1118 );
1119 this->node = expr;
[74dbbf6]1120 return nullptr;
1121 }
1122
1123 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
[20de6fb]1124 auto expr = visitBaseExpr( node,
1125 new DefaultArgExpr(
1126 get<Expression>().accept1(node->expr)
1127 )
1128 );
1129 this->node = expr;
[74dbbf6]1130 return nullptr;
1131 }
1132
1133 const ast::Expr * visit( const ast::GenericExpr * node ) override final {
[20de6fb]1134 std::list<GenericExpr::Association> associations;
1135 for (auto association : node->associations) {
1136 associations.push_back(GenericExpr::Association(
1137 get<Type> ().accept1(association.type),
1138 get<Expression>().accept1(association.expr)
1139 ));
1140 }
1141 auto expr = visitBaseExpr( node,
1142 new GenericExpr(
1143 get<Expression>().accept1(node->control),
1144 associations
1145 )
1146 );
1147 this->node = expr;
[74dbbf6]1148 return nullptr;
1149 }
1150
[1ae47de]1151 const ast::Type * visitType( const ast::Type * node, Type * type ) {
1152 // Some types do this in their constructor so add a check.
1153 if ( !node->attributes.empty() && type->attributes.empty() ) {
1154 type->attributes = get<Attribute>().acceptL( node->attributes );
1155 }
1156 this->node = type;
[74dbbf6]1157 return nullptr;
1158 }
1159
[1ae47de]1160 const ast::Type * visit( const ast::VoidType * node ) override final {
1161 return visitType( node, new VoidType{ cv( node ) } );
1162 }
1163
[74dbbf6]1164 const ast::Type * visit( const ast::BasicType * node ) override final {
[2a54479]1165 auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
1166 // I believe this should always be a BasicType.
[490fb92e]1167 if ( ast::sizeType == node ) {
[2a54479]1168 Validate::SizeType = type;
1169 }
[1ae47de]1170 return visitType( node, type );
[74dbbf6]1171 }
1172
1173 const ast::Type * visit( const ast::PointerType * node ) override final {
[1ae47de]1174 return visitType( node, new PointerType{
[d148778]1175 cv( node ),
1176 get<Type>().accept1( node->base ),
1177 get<Expression>().accept1( node->dimension ),
[746ae82]1178 (bool)node->isVarLen,
1179 (bool)node->isStatic
[1ae47de]1180 } );
[74dbbf6]1181 }
1182
1183 const ast::Type * visit( const ast::ArrayType * node ) override final {
[1ae47de]1184 return visitType( node, new ArrayType{
[d148778]1185 cv( node ),
1186 get<Type>().accept1( node->base ),
1187 get<Expression>().accept1( node->dimension ),
[746ae82]1188 (bool)node->isVarLen,
1189 (bool)node->isStatic
[1ae47de]1190 } );
[74dbbf6]1191 }
1192
1193 const ast::Type * visit( const ast::ReferenceType * node ) override final {
[1ae47de]1194 return visitType( node, new ReferenceType{
[d148778]1195 cv( node ),
1196 get<Type>().accept1( node->base )
[1ae47de]1197 } );
[74dbbf6]1198 }
1199
1200 const ast::Type * visit( const ast::QualifiedType * node ) override final {
[1ae47de]1201 return visitType( node, new QualifiedType{
[d148778]1202 cv( node ),
1203 get<Type>().accept1( node->parent ),
1204 get<Type>().accept1( node->child )
[1ae47de]1205 } );
[74dbbf6]1206 }
1207
1208 const ast::Type * visit( const ast::FunctionType * node ) override final {
[954c954]1209 static std::string dummy_paramvar_prefix = "__param_";
1210 static std::string dummy_returnvar_prefix = "__retval_";
1211
[746ae82]1212 auto ty = new FunctionType {
[0b57626]1213 cv( node ),
[746ae82]1214 (bool)node->isVarArgs
1215 };
[954c954]1216 auto returns = get<Type>().acceptL(node->returns);
1217 auto params = get<Type>().acceptL(node->params);
1218
1219 int ret_index = 0;
1220 for (auto t: returns) {
1221 // xxx - LinkageSpec shouldn't matter but needs to be something
1222 ObjectDecl * dummy = new ObjectDecl(dummy_returnvar_prefix + std::to_string(ret_index++), {}, LinkageSpec::C, nullptr, t, nullptr);
1223 ty->returnVals.push_back(dummy);
1224 }
1225 int param_index = 0;
1226 for (auto t: params) {
1227 ObjectDecl * dummy = new ObjectDecl(dummy_paramvar_prefix + std::to_string(param_index++), {}, LinkageSpec::C, nullptr, t, nullptr);
1228 ty->parameters.push_back(dummy);
1229 }
1230
1231 // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
1232 // ty->parameters = get<DeclarationWithType>().acceptL( node->params );
[3e5dd913]1233
1234 auto types = get<TypeInstType>().acceptL( node->forall );
1235 for (auto t : types) {
1236 auto newT = new TypeDecl(*t->baseType);
1237 newT->name = t->name; // converted by typeString()
1238 for (auto asst : newT->assertions) delete asst;
1239 newT->assertions.clear();
1240 ty->forall.push_back(newT);
1241 }
1242 auto assts = get<VariableExpr>().acceptL( node->assertions );
1243 if (!assts.empty()) {
1244 assert(!types.empty());
1245 for (auto asst : assts) {
1246 auto newDecl = new ObjectDecl(*strict_dynamic_cast<ObjectDecl*>(asst->var));
1247 delete newDecl->type;
1248 newDecl->type = asst->result->clone();
1249 newDecl->storageClasses.is_extern = true; // hack
1250 ty->forall.back()->assertions.push_back(newDecl);
1251 }
1252 }
1253
[1ae47de]1254 return visitType( node, ty );
[74dbbf6]1255 }
1256
[98e8b3b]1257 const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) {
[b869ec5]1258 ty->parameters = get<Expression>().acceptL( old->params );
1259 ty->hoistType = old->hoistType;
[1ae47de]1260 return visitType( old, ty );
[b869ec5]1261 }
1262
[74dbbf6]1263 const ast::Type * visit( const ast::StructInstType * node ) override final {
[b869ec5]1264 StructInstType * ty;
1265 if ( node->base ) {
1266 ty = new StructInstType{
1267 cv( node ),
1268 get<StructDecl>().accept1( node->base ),
1269 get<Attribute>().acceptL( node->attributes )
1270 };
1271 } else {
1272 ty = new StructInstType{
1273 cv( node ),
1274 node->name,
1275 get<Attribute>().acceptL( node->attributes )
1276 };
1277 }
[1ae47de]1278 return postvisit( node, ty );
[74dbbf6]1279 }
1280
1281 const ast::Type * visit( const ast::UnionInstType * node ) override final {
[b869ec5]1282 UnionInstType * ty;
1283 if ( node->base ) {
1284 ty = new UnionInstType{
1285 cv( node ),
1286 get<UnionDecl>().accept1( node->base ),
1287 get<Attribute>().acceptL( node->attributes )
1288 };
1289 } else {
1290 ty = new UnionInstType{
1291 cv( node ),
1292 node->name,
1293 get<Attribute>().acceptL( node->attributes )
1294 };
1295 }
[1ae47de]1296 return postvisit( node, ty );
[74dbbf6]1297 }
1298
1299 const ast::Type * visit( const ast::EnumInstType * node ) override final {
[b869ec5]1300 EnumInstType * ty;
1301 if ( node->base ) {
1302 ty = new EnumInstType{
1303 cv( node ),
1304 get<EnumDecl>().accept1( node->base ),
1305 get<Attribute>().acceptL( node->attributes )
1306 };
1307 } else {
1308 ty = new EnumInstType{
1309 cv( node ),
1310 node->name,
1311 get<Attribute>().acceptL( node->attributes )
1312 };
1313 }
[1ae47de]1314 return postvisit( node, ty );
[74dbbf6]1315 }
1316
1317 const ast::Type * visit( const ast::TraitInstType * node ) override final {
[b869ec5]1318 TraitInstType * ty;
1319 if ( node->base ) {
1320 ty = new TraitInstType{
1321 cv( node ),
1322 get<TraitDecl>().accept1( node->base ),
1323 get<Attribute>().acceptL( node->attributes )
1324 };
1325 } else {
1326 ty = new TraitInstType{
1327 cv( node ),
1328 node->name,
1329 get<Attribute>().acceptL( node->attributes )
1330 };
1331 }
[1ae47de]1332 return postvisit( node, ty );
[74dbbf6]1333 }
1334
1335 const ast::Type * visit( const ast::TypeInstType * node ) override final {
[b869ec5]1336 TypeInstType * ty;
1337 if ( node->base ) {
1338 ty = new TypeInstType{
1339 cv( node ),
[3e5dd913]1340 node->typeString(),
[b869ec5]1341 get<TypeDecl>().accept1( node->base ),
1342 get<Attribute>().acceptL( node->attributes )
1343 };
1344 } else {
1345 ty = new TypeInstType{
1346 cv( node ),
[3e5dd913]1347 node->typeString(),
[07de76b]1348 node->kind == ast::TypeDecl::Ftype,
[b869ec5]1349 get<Attribute>().acceptL( node->attributes )
1350 };
1351 }
[1ae47de]1352 return postvisit( node, ty );
[74dbbf6]1353 }
1354
1355 const ast::Type * visit( const ast::TupleType * node ) override final {
[1ae47de]1356 return visitType( node, new TupleType{
[746ae82]1357 cv( node ),
1358 get<Type>().acceptL( node->types )
1359 // members generated by TupleType c'tor
[1ae47de]1360 } );
[74dbbf6]1361 }
1362
1363 const ast::Type * visit( const ast::TypeofType * node ) override final {
[1ae47de]1364 return visitType( node, new TypeofType{
[746ae82]1365 cv( node ),
1366 get<Expression>().accept1( node->expr ),
1367 (bool)node->kind
[1ae47de]1368 } );
[74dbbf6]1369 }
1370
[cc64be1d]1371 const ast::Type * visit( const ast::VTableType * node ) override final {
1372 return visitType( node, new VTableType{
1373 cv( node ),
1374 get<Type>().accept1( node->base )
1375 } );
1376 }
1377
[74dbbf6]1378 const ast::Type * visit( const ast::VarArgsType * node ) override final {
[1ae47de]1379 return visitType( node, new VarArgsType{ cv( node ) } );
[74dbbf6]1380 }
1381
1382 const ast::Type * visit( const ast::ZeroType * node ) override final {
[1ae47de]1383 return visitType( node, new ZeroType{ cv( node ) } );
[74dbbf6]1384 }
1385
1386 const ast::Type * visit( const ast::OneType * node ) override final {
[1ae47de]1387 return visitType( node, new OneType{ cv( node ) } );
[74dbbf6]1388 }
1389
[1ae47de]1390 const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
1391 return visitType( node, new GlobalScopeType{} );
[74dbbf6]1392 }
1393
1394 const ast::Designation * visit( const ast::Designation * node ) override final {
[74ad8c0]1395 auto designation = new Designation( get<Expression>().acceptL( node->designators ) );
1396 designation->location = node->location;
1397 this->node = designation;
[74dbbf6]1398 return nullptr;
1399 }
1400
1401 const ast::Init * visit( const ast::SingleInit * node ) override final {
[74ad8c0]1402 auto init = new SingleInit(
1403 get<Expression>().accept1( node->value ),
1404 ast::MaybeConstruct == node->maybeConstructed
1405 );
1406 init->location = node->location;
1407 this->node = init;
[74dbbf6]1408 return nullptr;
1409 }
1410
1411 const ast::Init * visit( const ast::ListInit * node ) override final {
[74ad8c0]1412 auto init = new ListInit(
1413 get<Initializer>().acceptL( node->initializers ),
1414 get<Designation>().acceptL( node->designations ),
1415 ast::MaybeConstruct == node->maybeConstructed
1416 );
1417 init->location = node->location;
1418 this->node = init;
[74dbbf6]1419 return nullptr;
1420 }
1421
1422 const ast::Init * visit( const ast::ConstructorInit * node ) override final {
[74ad8c0]1423 auto init = new ConstructorInit(
1424 get<Statement>().accept1( node->ctor ),
1425 get<Statement>().accept1( node->dtor ),
1426 get<Initializer>().accept1( node->init )
1427 );
1428 init->location = node->location;
1429 this->node = init;
[74dbbf6]1430 return nullptr;
1431 }
1432
1433 const ast::Attribute * visit( const ast::Attribute * node ) override final {
[dd6d7c6]1434 auto attr = new Attribute(
1435 node->name,
[489bacf]1436 get<Expression>().acceptL(node->params)
[dd6d7c6]1437 );
1438 this->node = attr;
[74dbbf6]1439 return nullptr;
1440 }
1441
1442 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
[dd6d7c6]1443 // Handled by convertTypeSubstitution helper instead.
1444 // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node.
1445 assert( 0 );
[0b57626]1446 (void)node;
[74dbbf6]1447 return nullptr;
1448 }
[6d51bd7]1449};
1450
[293dc1c]1451std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) {
[1387ea0]1452 // Copy values from the global store to the local static variables.
1453 ast::sizeType = translationUnit.global.sizeType;
1454 ast::dereferenceOperator = translationUnit.global.dereference;
1455 ast::dtorStruct = translationUnit.global.dtorStruct;
1456 ast::dtorStructDestroy = translationUnit.global.dtorDestroy;
1457
[74dbbf6]1458 ConverterNewToOld c;
1459 std::list< Declaration * > decls;
[293dc1c]1460 for(auto d : translationUnit.decls) {
[675d816]1461 decls.emplace_back( c.decl( d ) );
[74dbbf6]1462 }
1463 return decls;
[6d51bd7]1464}
1465
1466//================================================================================================
1467
1468class ConverterOldToNew : public Visitor {
1469public:
1470 ast::Decl * decl() {
1471 return strict_dynamic_cast< ast::Decl * >( node );
1472 }
[4559b34]1473
[546e712]1474 ConverterOldToNew() = default;
1475 ConverterOldToNew(const ConverterOldToNew &) = delete;
1476 ConverterOldToNew(ConverterOldToNew &&) = delete;
[6d51bd7]1477private:
[d148778]1478 /// conversion output
[546e712]1479 ast::Node * node = nullptr;
[d148778]1480 /// cache of nodes that might be referenced by readonly<> for de-duplication
[954c954]1481 /// in case that some nodes are dropped by conversion (due to possible structural change)
1482 /// use smart pointers in cache value to prevent accidental invalidation.
1483 /// at conversion stage, all created nodes are guaranteed to be unique, therefore
1484 /// const_casting out of smart pointers is permitted.
[3e5dd913]1485 std::unordered_map< const BaseSyntaxNode *, ast::readonly<ast::Node> > cache = {};
[6d51bd7]1486
[6f8e87d]1487 // Local Utilities:
1488
1489 template<typename NewT, typename OldT>
1490 NewT * getAccept1( OldT old ) {
[d148778]1491 if ( ! old ) return nullptr;
[6f8e87d]1492 old->accept(*this);
[2c04369]1493 ast::Node * ret = node;
1494 node = nullptr;
1495 return strict_dynamic_cast< NewT * >( ret );
[6f8e87d]1496 }
1497
1498# define GET_ACCEPT_1(child, type) \
1499 getAccept1< ast::type, decltype( old->child ) >( old->child )
1500
[f135b50]1501
[6f8e87d]1502 template<typename NewT, typename OldC>
[a62749f]1503 std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) {
[6f8e87d]1504 std::vector< ast::ptr<NewT> > ret;
1505 ret.reserve( old.size() );
1506 for ( auto a : old ) {
1507 a->accept( *this );
1508 ret.emplace_back( strict_dynamic_cast< NewT * >(node) );
[2c04369]1509 node = nullptr;
[6f8e87d]1510 }
1511 return ret;
1512 }
1513
1514# define GET_ACCEPT_V(child, type) \
1515 getAcceptV< ast::type, decltype( old->child ) >( old->child )
[6355ba7]1516
[f238fcc2]1517# define GET_ACCEPT_E(child, type) \
1518 getAccept1< ast::type, decltype( old->base ) >( old->base )
1519
[60aaa51d]1520 template<typename NewT, typename OldC>
[a62749f]1521 std::deque< ast::ptr<NewT> > getAcceptD( const OldC& old ) {
[60aaa51d]1522 std::deque< ast::ptr<NewT> > ret;
1523 for ( auto a : old ) {
1524 a->accept( *this );
1525 ret.emplace_back( strict_dynamic_cast< NewT * >(node) );
1526 node = nullptr;
1527 }
1528 return ret;
1529 }
1530
1531# define GET_ACCEPT_D(child, type) \
1532 getAcceptD< ast::type, decltype( old->child ) >( old->child )
[6f8e87d]1533
[a62749f]1534 ast::Label make_label(const Label* old) {
1535 CodeLocation const & location =
1536 ( old->labelled ) ? old->labelled->location : CodeLocation();
[6f8e87d]1537 return ast::Label(
[a62749f]1538 location,
[6f8e87d]1539 old->name,
1540 GET_ACCEPT_V(attributes, Attribute)
1541 );
1542 }
1543
[6d51bd7]1544 template<template <class...> class C>
1545 C<ast::Label> make_labels(C<Label> olds) {
1546 C<ast::Label> ret;
[6f8e87d]1547 for (auto oldn : olds) {
1548 ret.push_back( make_label( &oldn ) );
[6d51bd7]1549 }
1550 return ret;
1551 }
1552
[6f8e87d]1553# define GET_LABELS_V(labels) \
1554 to<std::vector>::from( make_labels( std::move( labels ) ) )
[0b57626]1555
[7870799]1556 static ast::CV::Qualifiers cv( const Type * ty ) { return { ty->tq.val }; }
[d148778]1557
[b869ec5]1558 /// returns true and sets `node` if in cache
[7870799]1559 bool inCache( const BaseSyntaxNode * old ) {
[d148778]1560 auto it = cache.find( old );
[b869ec5]1561 if ( it == cache.end() ) return false;
[954c954]1562 node = const_cast<ast::Node *>(it->second.get());
[b869ec5]1563 return true;
[d148778]1564 }
[6f8e87d]1565
1566 // Now all the visit functions:
1567
[7870799]1568 virtual void visit( const ObjectDecl * old ) override final {
[546e712]1569 auto&& type = GET_ACCEPT_1(type, Type);
1570 auto&& init = GET_ACCEPT_1(init, Init);
1571 auto&& bfwd = GET_ACCEPT_1(bitfieldWidth, Expr);
1572 auto&& attr = GET_ACCEPT_V(attributes, Attribute);
1573 if ( inCache( old ) ) {
1574 return;
1575 }
[6d51bd7]1576 auto decl = new ast::ObjectDecl(
1577 old->location,
1578 old->name,
[546e712]1579 type,
1580 init,
[6d51bd7]1581 { old->get_storageClasses().val },
1582 { old->linkage.val },
[546e712]1583 bfwd,
1584 std::move(attr),
[6d51bd7]1585 { old->get_funcSpec().val }
1586 );
[546e712]1587 cache.emplace(old, decl);
1588 assert(cache.find( old ) != cache.end());
[6d51bd7]1589 decl->scopeLevel = old->scopeLevel;
1590 decl->mangleName = old->mangleName;
1591 decl->isDeleted = old->isDeleted;
[e6faef4]1592 decl->asmName = GET_ACCEPT_1(asmName, Expr);
[6d51bd7]1593 decl->uniqueId = old->uniqueId;
1594 decl->extension = old->extension;
1595
1596 this->node = decl;
1597 }
1598
[7870799]1599 virtual void visit( const FunctionDecl * old ) override final {
[b869ec5]1600 if ( inCache( old ) ) return;
[954c954]1601 auto paramVars = GET_ACCEPT_V(type->parameters, DeclWithType);
1602 auto returnVars = GET_ACCEPT_V(type->returnVals, DeclWithType);
1603 auto forall = GET_ACCEPT_V(type->forall, TypeDecl);
1604
1605 // function type is now derived from parameter decls instead of storing them
[490fb92e]1606
1607 /*
[954c954]1608 auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type));
1609 ftype->params.reserve(paramVars.size());
1610 ftype->returns.reserve(returnVars.size());
1611
1612 for (auto & v: paramVars) {
1613 ftype->params.emplace_back(v->get_type());
1614 }
1615 for (auto & v: returnVars) {
1616 ftype->returns.emplace_back(v->get_type());
1617 }
1618 ftype->forall = std::move(forall);
[490fb92e]1619 */
1620
1621 // can function type have attributes? seems not to be the case.
1622 // visitType(old->type, ftype);
[954c954]1623
[3e5dd913]1624 // collect assertions and put directly in FunctionDecl
1625 std::vector<ast::ptr<ast::DeclWithType>> assertions;
1626 for (auto & param: forall) {
1627 for (auto & asst: param->assertions) {
1628 assertf(asst->unique(), "newly converted decl must be unique");
1629 assertions.emplace_back(asst);
1630 }
1631 auto mut = param.get_and_mutate();
1632 assertf(mut == param, "newly converted decl must be unique");
1633 mut->assertions.clear();
1634 }
1635
[9a0cd9c]1636 auto decl = new ast::FunctionDecl{
1637 old->location,
1638 old->name,
[954c954]1639 // GET_ACCEPT_1(type, FunctionType),
[490fb92e]1640 std::move(forall),
[954c954]1641 std::move(paramVars),
1642 std::move(returnVars),
[d88f8b3b]1643 {},
[9a0cd9c]1644 { old->storageClasses.val },
1645 { old->linkage.val },
1646 GET_ACCEPT_V(attributes, Attribute),
[490fb92e]1647 { old->get_funcSpec().val },
1648 old->type->isVarArgs
[9a0cd9c]1649 };
[954c954]1650
[490fb92e]1651 // decl->type = ftype;
[8abee136]1652 cache.emplace( old, decl );
[954c954]1653
[3e5dd913]1654 decl->assertions = std::move(assertions);
[d76c588]1655 decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
[d88f8b3b]1656 decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
[9a0cd9c]1657 decl->scopeLevel = old->scopeLevel;
1658 decl->mangleName = old->mangleName;
1659 decl->isDeleted = old->isDeleted;
[e6faef4]1660 decl->asmName = GET_ACCEPT_1(asmName, Expr);
[9a0cd9c]1661 decl->uniqueId = old->uniqueId;
1662 decl->extension = old->extension;
1663
1664 this->node = decl;
[157a816]1665
[0aedb01]1666 if ( Validate::dereferenceOperator == old ) {
[490fb92e]1667 ast::dereferenceOperator = decl;
[157a816]1668 }
[043a5b6]1669
1670 if ( Validate::dtorStructDestroy == old ) {
[490fb92e]1671 ast::dtorStructDestroy = decl;
[043a5b6]1672 }
[6d51bd7]1673 }
1674
[7870799]1675 virtual void visit( const StructDecl * old ) override final {
[b869ec5]1676 if ( inCache( old ) ) return;
[6d51bd7]1677 auto decl = new ast::StructDecl(
1678 old->location,
1679 old->name,
[312029a]1680 (ast::AggregateDecl::Aggregate)old->kind,
[d66e7b7]1681 GET_ACCEPT_V(attributes, Attribute),
[6d51bd7]1682 { old->linkage.val }
1683 );
[8abee136]1684 cache.emplace( old, decl );
[d66e7b7]1685 decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
[6d51bd7]1686 decl->body = old->body;
[d66e7b7]1687 decl->params = GET_ACCEPT_V(parameters, TypeDecl);
1688 decl->members = GET_ACCEPT_V(members, Decl);
[6d51bd7]1689 decl->extension = old->extension;
1690 decl->uniqueId = old->uniqueId;
1691 decl->storage = { old->storageClasses.val };
1692
1693 this->node = decl;
[043a5b6]1694
1695 if ( Validate::dtorStruct == old ) {
[490fb92e]1696 ast::dtorStruct = decl;
[043a5b6]1697 }
[6d51bd7]1698 }
1699
[7870799]1700 virtual void visit( const UnionDecl * old ) override final {
[b869ec5]1701 if ( inCache( old ) ) return;
[6d51bd7]1702 auto decl = new ast::UnionDecl(
1703 old->location,
1704 old->name,
[d66e7b7]1705 GET_ACCEPT_V(attributes, Attribute),
[6d51bd7]1706 { old->linkage.val }
1707 );
[8abee136]1708 cache.emplace( old, decl );
[d66e7b7]1709 decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
[6d51bd7]1710 decl->body = old->body;
[d66e7b7]1711 decl->params = GET_ACCEPT_V(parameters, TypeDecl);
1712 decl->members = GET_ACCEPT_V(members, Decl);
[6d51bd7]1713 decl->extension = old->extension;
1714 decl->uniqueId = old->uniqueId;
1715 decl->storage = { old->storageClasses.val };
1716
1717 this->node = decl;
1718 }
1719
[f135b50]1720 // Convert SynTree::EnumDecl to AST::EnumDecl
[7870799]1721 virtual void visit( const EnumDecl * old ) override final {
[b869ec5]1722 if ( inCache( old ) ) return;
[157a816]1723 auto decl = new ast::EnumDecl(
[6d51bd7]1724 old->location,
1725 old->name,
[d66e7b7]1726 GET_ACCEPT_V(attributes, Attribute),
[f135b50]1727 { old->linkage.val },
[f238fcc2]1728 GET_ACCEPT_1(base, Type),
[f135b50]1729 old->enumValues
[6d51bd7]1730 );
[8abee136]1731 cache.emplace( old, decl );
[d66e7b7]1732 decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
[6d51bd7]1733 decl->body = old->body;
[d66e7b7]1734 decl->params = GET_ACCEPT_V(parameters, TypeDecl);
1735 decl->members = GET_ACCEPT_V(members, Decl);
[6d51bd7]1736 decl->extension = old->extension;
1737 decl->uniqueId = old->uniqueId;
1738 decl->storage = { old->storageClasses.val };
1739 this->node = decl;
1740 }
1741
[7870799]1742 virtual void visit( const TraitDecl * old ) override final {
[b869ec5]1743 if ( inCache( old ) ) return;
[157a816]1744 auto decl = new ast::TraitDecl(
[6d51bd7]1745 old->location,
1746 old->name,
[d66e7b7]1747 GET_ACCEPT_V(attributes, Attribute),
[6d51bd7]1748 { old->linkage.val }
1749 );
[8abee136]1750 cache.emplace( old, decl );
[d66e7b7]1751 decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
[6d51bd7]1752 decl->body = old->body;
[d66e7b7]1753 decl->params = GET_ACCEPT_V(parameters, TypeDecl);
1754 decl->members = GET_ACCEPT_V(members, Decl);
[6d51bd7]1755 decl->extension = old->extension;
1756 decl->uniqueId = old->uniqueId;
1757 decl->storage = { old->storageClasses.val };
1758
1759 this->node = decl;
1760 }
1761
[7870799]1762 virtual void visit( const TypeDecl * old ) override final {
[0b57626]1763 if ( inCache( old ) ) return;
[9a0cd9c]1764 auto decl = new ast::TypeDecl{
1765 old->location,
1766 old->name,
1767 { old->storageClasses.val },
1768 GET_ACCEPT_1(base, Type),
[07de76b]1769 (ast::TypeDecl::Kind)(unsigned)old->kind,
[9a0cd9c]1770 old->sized,
1771 GET_ACCEPT_1(init, Type)
1772 };
[8abee136]1773 cache.emplace( old, decl );
[9a0cd9c]1774 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
1775 decl->extension = old->extension;
1776 decl->uniqueId = old->uniqueId;
1777
1778 this->node = decl;
[6d51bd7]1779 }
1780
[7870799]1781 virtual void visit( const TypedefDecl * old ) override final {
[6d51bd7]1782 auto decl = new ast::TypedefDecl(
1783 old->location,
1784 old->name,
1785 { old->storageClasses.val },
[d66e7b7]1786 GET_ACCEPT_1(base, Type),
[6d51bd7]1787 { old->linkage.val }
1788 );
[d66e7b7]1789 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
[6d51bd7]1790 decl->extension = old->extension;
1791 decl->uniqueId = old->uniqueId;
1792 decl->storage = { old->storageClasses.val };
1793
1794 this->node = decl;
1795 }
1796
[7870799]1797 virtual void visit( const AsmDecl * old ) override final {
[9a0cd9c]1798 auto decl = new ast::AsmDecl{
[0b57626]1799 old->location,
[9a0cd9c]1800 GET_ACCEPT_1(stmt, AsmStmt)
1801 };
1802 decl->extension = old->extension;
1803 decl->uniqueId = old->uniqueId;
1804 decl->storage = { old->storageClasses.val };
[6d51bd7]1805
[9a0cd9c]1806 this->node = decl;
[6d51bd7]1807 }
1808
[2d019af]1809 virtual void visit( const DirectiveDecl * old ) override final {
1810 auto decl = new ast::DirectiveDecl{
1811 old->location,
1812 GET_ACCEPT_1(stmt, DirectiveStmt)
1813 };
1814 decl->extension = old->extension;
1815 decl->uniqueId = old->uniqueId;
1816 decl->storage = { old->storageClasses.val };
1817
1818 this->node = decl;
1819 }
1820
[7870799]1821 virtual void visit( const StaticAssertDecl * old ) override final {
[9a0cd9c]1822 auto decl = new ast::StaticAssertDecl{
1823 old->location,
1824 GET_ACCEPT_1(condition, Expr),
1825 GET_ACCEPT_1(message, ConstantExpr)
1826 };
1827 decl->extension = old->extension;
1828 decl->uniqueId = old->uniqueId;
1829 decl->storage = { old->storageClasses.val };
[6d51bd7]1830
[9a0cd9c]1831 this->node = decl;
[6d51bd7]1832 }
1833
[7870799]1834 virtual void visit( const CompoundStmt * old ) override final {
[4073b16]1835 if ( inCache( old ) ) return;
[6d51bd7]1836 auto stmt = new ast::CompoundStmt(
1837 old->location,
[d66e7b7]1838 to<std::list>::from( GET_ACCEPT_V(kids, Stmt) ),
1839 GET_LABELS_V(old->labels)
[6d51bd7]1840 );
1841
1842 this->node = stmt;
[4073b16]1843 cache.emplace( old, this->node );
[6d51bd7]1844 }
1845
[7870799]1846 virtual void visit( const ExprStmt * old ) override final {
[4073b16]1847 if ( inCache( old ) ) return;
[6f8e87d]1848 this->node = new ast::ExprStmt(
[6d51bd7]1849 old->location,
[6f8e87d]1850 GET_ACCEPT_1(expr, Expr),
1851 GET_LABELS_V(old->labels)
[6d51bd7]1852 );
[4073b16]1853 cache.emplace( old, this->node );
[6d51bd7]1854 }
1855
[7870799]1856 virtual void visit( const AsmStmt * old ) override final {
[4073b16]1857 if ( inCache( old ) ) return;
[6f8e87d]1858 this->node = new ast::AsmStmt(
1859 old->location,
1860 old->voltile,
1861 GET_ACCEPT_1(instruction, Expr),
1862 GET_ACCEPT_V(output, Expr),
1863 GET_ACCEPT_V(input, Expr),
1864 GET_ACCEPT_V(clobber, ConstantExpr),
1865 GET_LABELS_V(old->gotolabels),
1866 GET_LABELS_V(old->labels)
1867 );
[4073b16]1868 cache.emplace( old, this->node );
[6d51bd7]1869 }
1870
[7870799]1871 virtual void visit( const DirectiveStmt * old ) override final {
[4073b16]1872 if ( inCache( old ) ) return;
[6f8e87d]1873 this->node = new ast::DirectiveStmt(
1874 old->location,
1875 old->directive,
1876 GET_LABELS_V(old->labels)
1877 );
[4073b16]1878 cache.emplace( old, this->node );
[6d51bd7]1879 }
1880
[7870799]1881 virtual void visit( const IfStmt * old ) override final {
[4073b16]1882 if ( inCache( old ) ) return;
[6f8e87d]1883 this->node = new ast::IfStmt(
1884 old->location,
1885 GET_ACCEPT_1(condition, Expr),
[3b0bc16]1886 GET_ACCEPT_1(then, Stmt),
1887 GET_ACCEPT_1(else_, Stmt),
[6f8e87d]1888 GET_ACCEPT_V(initialization, Stmt),
1889 GET_LABELS_V(old->labels)
1890 );
[4073b16]1891 cache.emplace( old, this->node );
[6d51bd7]1892 }
1893
[7870799]1894 virtual void visit( const SwitchStmt * old ) override final {
[4073b16]1895 if ( inCache( old ) ) return;
[6f8e87d]1896 this->node = new ast::SwitchStmt(
1897 old->location,
1898 GET_ACCEPT_1(condition, Expr),
[400b8be]1899 GET_ACCEPT_V(statements, CaseClause),
[6f8e87d]1900 GET_LABELS_V(old->labels)
1901 );
[4073b16]1902 cache.emplace( old, this->node );
[6d51bd7]1903 }
1904
[7870799]1905 virtual void visit( const CaseStmt * old ) override final {
[4073b16]1906 if ( inCache( old ) ) return;
[400b8be]1907 this->node = new ast::CaseClause(
[6f8e87d]1908 old->location,
1909 GET_ACCEPT_1(condition, Expr),
[400b8be]1910 GET_ACCEPT_V(stmts, Stmt)
[6f8e87d]1911 );
[400b8be]1912 auto labels = GET_LABELS_V(old->labels);
1913 assertf(labels.empty(), "Labels found on CaseStmt.");
[4073b16]1914 cache.emplace( old, this->node );
[6d51bd7]1915 }
1916
[3b0bc16]1917 virtual void visit( const WhileDoStmt * old ) override final {
[4073b16]1918 if ( inCache( old ) ) return;
[3b0bc16]1919 this->node = new ast::WhileDoStmt(
[6f8e87d]1920 old->location,
1921 GET_ACCEPT_1(condition, Expr),
1922 GET_ACCEPT_1(body, Stmt),
[ff3b0249]1923 GET_ACCEPT_1(else_, Stmt),
[6f8e87d]1924 GET_ACCEPT_V(initialization, Stmt),
1925 old->isDoWhile,
1926 GET_LABELS_V(old->labels)
1927 );
[4073b16]1928 cache.emplace( old, this->node );
[6d51bd7]1929 }
1930
[7870799]1931 virtual void visit( const ForStmt * old ) override final {
[4073b16]1932 if ( inCache( old ) ) return;
[6f8e87d]1933 this->node = new ast::ForStmt(
1934 old->location,
1935 GET_ACCEPT_V(initialization, Stmt),
1936 GET_ACCEPT_1(condition, Expr),
1937 GET_ACCEPT_1(increment, Expr),
1938 GET_ACCEPT_1(body, Stmt),
[ff3b0249]1939 GET_ACCEPT_1(else_, Stmt),
[6f8e87d]1940 GET_LABELS_V(old->labels)
1941 );
[4073b16]1942 cache.emplace( old, this->node );
[6d51bd7]1943 }
1944
[7870799]1945 virtual void visit( const BranchStmt * old ) override final {
[4073b16]1946 if ( inCache( old ) ) return;
[6f8e87d]1947 if (old->computedTarget) {
1948 this->node = new ast::BranchStmt(
1949 old->location,
1950 GET_ACCEPT_1(computedTarget, Expr),
1951 GET_LABELS_V(old->labels)
1952 );
1953 } else {
1954 ast::BranchStmt::Kind kind;
1955 switch (old->type) {
1956 #define CASE(n) \
1957 case BranchStmt::n: \
1958 kind = ast::BranchStmt::n; \
1959 break
1960 CASE(Goto);
1961 CASE(Break);
1962 CASE(Continue);
1963 CASE(FallThrough);
1964 CASE(FallThroughDefault);
1965 #undef CASE
[d66e7b7]1966 default:
1967 assertf(false, "Invalid BranchStmt::Type %d\n", old->type);
[6f8e87d]1968 }
1969
1970 auto stmt = new ast::BranchStmt(
1971 old->location,
1972 kind,
[a62749f]1973 make_label(&old->originalTarget),
[6f8e87d]1974 GET_LABELS_V(old->labels)
1975 );
1976 stmt->target = make_label(&old->target);
1977 this->node = stmt;
1978 }
[4073b16]1979 cache.emplace( old, this->node );
[6d51bd7]1980 }
1981
[7870799]1982 virtual void visit( const ReturnStmt * old ) override final {
[4073b16]1983 if ( inCache( old ) ) return;
[6f8e87d]1984 this->node = new ast::ReturnStmt(
1985 old->location,
1986 GET_ACCEPT_1(expr, Expr),
1987 GET_LABELS_V(old->labels)
1988 );
[4073b16]1989 cache.emplace( old, this->node );
[6d51bd7]1990 }
1991
[7870799]1992 virtual void visit( const ThrowStmt * old ) override final {
[4073b16]1993 if ( inCache( old ) ) return;
[6f4b7f2]1994 ast::ExceptionKind kind;
[6f8e87d]1995 switch (old->kind) {
1996 case ThrowStmt::Terminate:
[6f4b7f2]1997 kind = ast::ExceptionKind::Terminate;
[6f8e87d]1998 break;
1999 case ThrowStmt::Resume:
[6f4b7f2]2000 kind = ast::ExceptionKind::Resume;
[6f8e87d]2001 break;
[d66e7b7]2002 default:
2003 assertf(false, "Invalid ThrowStmt::Kind %d\n", old->kind);
[6f8e87d]2004 }
[6d51bd7]2005
[6f8e87d]2006 this->node = new ast::ThrowStmt(
2007 old->location,
2008 kind,
2009 GET_ACCEPT_1(expr, Expr),
2010 GET_ACCEPT_1(target, Expr),
2011 GET_LABELS_V(old->labels)
2012 );
[4073b16]2013 cache.emplace( old, this->node );
[6d51bd7]2014 }
2015
[7870799]2016 virtual void visit( const TryStmt * old ) override final {
[4073b16]2017 if ( inCache( old ) ) return;
[6f8e87d]2018 this->node = new ast::TryStmt(
2019 old->location,
2020 GET_ACCEPT_1(block, CompoundStmt),
[400b8be]2021 GET_ACCEPT_V(handlers, CatchClause),
2022 GET_ACCEPT_1(finallyBlock, FinallyClause),
[6f8e87d]2023 GET_LABELS_V(old->labels)
2024 );
[4073b16]2025 cache.emplace( old, this->node );
[6d51bd7]2026 }
2027
[7870799]2028 virtual void visit( const CatchStmt * old ) override final {
[4073b16]2029 if ( inCache( old ) ) return;
[6f4b7f2]2030 ast::ExceptionKind kind;
[6f8e87d]2031 switch (old->kind) {
2032 case CatchStmt::Terminate:
[6f4b7f2]2033 kind = ast::ExceptionKind::Terminate;
[6f8e87d]2034 break;
2035 case CatchStmt::Resume:
[6f4b7f2]2036 kind = ast::ExceptionKind::Resume;
[6f8e87d]2037 break;
[d66e7b7]2038 default:
2039 assertf(false, "Invalid CatchStmt::Kind %d\n", old->kind);
[6f8e87d]2040 }
[6d51bd7]2041
[400b8be]2042 this->node = new ast::CatchClause(
[6f8e87d]2043 old->location,
2044 kind,
2045 GET_ACCEPT_1(decl, Decl),
2046 GET_ACCEPT_1(cond, Expr),
[400b8be]2047 GET_ACCEPT_1(body, Stmt)
[6f8e87d]2048 );
[400b8be]2049 auto labels = GET_LABELS_V(old->labels);
2050 assertf(labels.empty(), "Labels found on CatchStmt.");
[4073b16]2051 cache.emplace( old, this->node );
[6d51bd7]2052 }
2053
[7870799]2054 virtual void visit( const FinallyStmt * old ) override final {
[4073b16]2055 if ( inCache( old ) ) return;
[400b8be]2056 this->node = new ast::FinallyClause(
[6f8e87d]2057 old->location,
[400b8be]2058 GET_ACCEPT_1(block, CompoundStmt)
[6f8e87d]2059 );
[400b8be]2060 auto labels = GET_LABELS_V(old->labels);
2061 assertf(labels.empty(), "Labels found on FinallyStmt.");
[4073b16]2062 cache.emplace( old, this->node );
[6d51bd7]2063 }
2064
[37cdd97]2065 virtual void visit( const SuspendStmt * old ) override final {
2066 if ( inCache( old ) ) return;
2067 ast::SuspendStmt::Type type;
2068 switch (old->type) {
2069 case SuspendStmt::Coroutine: type = ast::SuspendStmt::Coroutine; break;
2070 case SuspendStmt::Generator: type = ast::SuspendStmt::Generator; break;
2071 case SuspendStmt::None : type = ast::SuspendStmt::None ; break;
2072 default: abort();
2073 }
2074 this->node = new ast::SuspendStmt(
2075 old->location,
2076 GET_ACCEPT_1(then , CompoundStmt),
2077 type,
2078 GET_LABELS_V(old->labels)
2079 );
[4073b16]2080 cache.emplace( old, this->node );
[6d51bd7]2081 }
2082
[7870799]2083 virtual void visit( const WaitForStmt * old ) override final {
[4073b16]2084 if ( inCache( old ) ) return;
[6f8e87d]2085 ast::WaitForStmt * stmt = new ast::WaitForStmt(
2086 old->location,
2087 GET_LABELS_V(old->labels)
2088 );
[6d51bd7]2089
[6f8e87d]2090 stmt->clauses.reserve( old->clauses.size() );
2091 for (size_t i = 0 ; i < old->clauses.size() ; ++i) {
2092 stmt->clauses.push_back({
2093 ast::WaitForStmt::Target{
2094 GET_ACCEPT_1(clauses[i].target.function, Expr),
2095 GET_ACCEPT_V(clauses[i].target.arguments, Expr)
2096 },
2097 GET_ACCEPT_1(clauses[i].statement, Stmt),
2098 GET_ACCEPT_1(clauses[i].condition, Expr)
2099 });
2100 }
2101 stmt->timeout = {
2102 GET_ACCEPT_1(timeout.time, Expr),
2103 GET_ACCEPT_1(timeout.statement, Stmt),
2104 GET_ACCEPT_1(timeout.condition, Expr),
2105 };
2106 stmt->orElse = {
[1e5dedc4]2107 GET_ACCEPT_1(orelse.statement, Stmt),
2108 GET_ACCEPT_1(orelse.condition, Expr),
[6f8e87d]2109 };
[6d51bd7]2110
[6f8e87d]2111 this->node = stmt;
[4073b16]2112 cache.emplace( old, this->node );
[6f8e87d]2113 }
[6d51bd7]2114
[7870799]2115 virtual void visit( const WithStmt * old ) override final {
[4073b16]2116 if ( inCache( old ) ) return;
[6f8e87d]2117 this->node = new ast::WithStmt(
2118 old->location,
2119 GET_ACCEPT_V(exprs, Expr),
[e67991f]2120 GET_ACCEPT_1(stmt, Stmt)
[6f8e87d]2121 );
[4073b16]2122 cache.emplace( old, this->node );
[6d51bd7]2123 }
2124
[7870799]2125 virtual void visit( const NullStmt * old ) override final {
[4073b16]2126 if ( inCache( old ) ) return;
[6f8e87d]2127 this->node = new ast::NullStmt(
[6d51bd7]2128 old->location,
[6f8e87d]2129 GET_LABELS_V(old->labels)
[6d51bd7]2130 );
[4073b16]2131 cache.emplace( old, this->node );
[6d51bd7]2132 }
2133
[7870799]2134 virtual void visit( const DeclStmt * old ) override final {
[4073b16]2135 if ( inCache( old ) ) return;
[6f8e87d]2136 this->node = new ast::DeclStmt(
2137 old->location,
2138 GET_ACCEPT_1(decl, Decl),
2139 GET_LABELS_V(old->labels)
2140 );
[4073b16]2141 cache.emplace( old, this->node );
[6d51bd7]2142 }
2143
[7870799]2144 virtual void visit( const ImplicitCtorDtorStmt * old ) override final {
[4073b16]2145 if ( inCache( old ) ) return;
[f685679]2146 auto stmt = new ast::ImplicitCtorDtorStmt(
[6f8e87d]2147 old->location,
[f685679]2148 nullptr,
[6f8e87d]2149 GET_LABELS_V(old->labels)
2150 );
[2c04369]2151 cache.emplace( old, stmt );
[f685679]2152 stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt);
[2c04369]2153 this->node = stmt;
[6d51bd7]2154 }
2155
[6cebfef]2156 virtual void visit( const MutexStmt * old ) override final {
2157 if ( inCache( old ) ) return;
2158 this->node = new ast::MutexStmt(
2159 old->location,
2160 GET_ACCEPT_1(stmt, Stmt),
2161 GET_ACCEPT_V(mutexObjs, Expr)
2162 );
2163 cache.emplace( old, this->node );
2164 }
2165
[3e5dd913]2166 // TypeSubstitution shouldn't exist yet in old.
[172d9342]2167 ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
[3e5dd913]2168
[8abee136]2169 if (!old) return nullptr;
[3e5dd913]2170 if (old->empty()) return nullptr;
2171 assert(false);
[8abee136]2172
[3e5dd913]2173 /*
[172d9342]2174 ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
2175
2176 for (decltype(old->begin()) old_i = old->begin(); old_i != old->end(); old_i++) {
2177 rslt->add( old_i->first,
2178 getAccept1<ast::Type>(old_i->second) );
2179 }
[6d51bd7]2180
[19e567dd]2181 return rslt;
[3e5dd913]2182 */
[6d51bd7]2183 }
2184
[e0016a5]2185 void convertInferUnion(ast::Expr::InferUnion &newInferred,
[19e567dd]2186 const std::map<UniqueId,ParamEntry> &oldInferParams,
2187 const std::vector<UniqueId> &oldResnSlots) {
2188
2189 assert( oldInferParams.empty() || oldResnSlots.empty() );
[07d867b]2190 // assert( newInferred.mode == ast::Expr::InferUnion::Empty );
[19e567dd]2191
2192 if ( !oldInferParams.empty() ) {
2193 ast::InferredParams &tgt = newInferred.inferParams();
[8b34df0]2194 for (auto & old : oldInferParams) {
[19e567dd]2195 tgt[old.first] = ast::ParamEntry(
2196 old.second.decl,
[aaeacf4]2197 getAccept1<ast::Decl>(old.second.declptr),
[19e567dd]2198 getAccept1<ast::Type>(old.second.actualType),
2199 getAccept1<ast::Type>(old.second.formalType),
2200 getAccept1<ast::Expr>(old.second.expr)
2201 );
2202 }
2203 } else if ( !oldResnSlots.empty() ) {
2204 ast::ResnSlots &tgt = newInferred.resnSlots();
2205 for (auto old : oldResnSlots) {
2206 tgt.push_back(old);
2207 }
2208 }
[172d9342]2209 }
2210
[7870799]2211 ast::Expr * visitBaseExpr_SkipResultType( const Expression * old, ast::Expr * nw) {
[6d51bd7]2212
[172d9342]2213 nw->env = convertTypeSubstitution(old->env);
2214
2215 nw->extension = old->extension;
2216 convertInferUnion(nw->inferred, old->inferParams, old->resnSlots);
2217
2218 return nw;
2219 }
[6d51bd7]2220
[7870799]2221 ast::Expr * visitBaseExpr( const Expression * old, ast::Expr * nw) {
[20de6fb]2222
2223 nw->result = GET_ACCEPT_1(result, Type);
2224 return visitBaseExpr_SkipResultType(old, nw);;
2225 }
2226
[7870799]2227 virtual void visit( const ApplicationExpr * old ) override final {
[19e567dd]2228 this->node = visitBaseExpr( old,
2229 new ast::ApplicationExpr(
2230 old->location,
2231 GET_ACCEPT_1(function, Expr),
2232 GET_ACCEPT_V(args, Expr)
2233 )
2234 );
[6d51bd7]2235 }
2236
[7870799]2237 virtual void visit( const UntypedExpr * old ) override final {
[19e567dd]2238 this->node = visitBaseExpr( old,
2239 new ast::UntypedExpr(
2240 old->location,
2241 GET_ACCEPT_1(function, Expr),
2242 GET_ACCEPT_V(args, Expr)
2243 )
2244 );
[172d9342]2245 }
[6d51bd7]2246
[7870799]2247 virtual void visit( const NameExpr * old ) override final {
[172d9342]2248 this->node = visitBaseExpr( old,
2249 new ast::NameExpr(
2250 old->location,
2251 old->get_name()
2252 )
2253 );
[6d51bd7]2254 }
2255
[7870799]2256 virtual void visit( const CastExpr * old ) override final {
[19e567dd]2257 this->node = visitBaseExpr( old,
2258 new ast::CastExpr(
2259 old->location,
[28c89f4]2260 GET_ACCEPT_1(arg, Expr),
[19e567dd]2261 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast
2262 )
2263 );
[6d51bd7]2264 }
2265
[312029a]2266 virtual void visit( const KeywordCastExpr * old ) override final {
2267 ast::AggregateDecl::Aggregate castTarget = (ast::AggregateDecl::Aggregate)old->target;
2268 assert( ast::AggregateDecl::Generator <= castTarget && castTarget <= ast::AggregateDecl::Thread );
[28c89f4]2269 this->node = visitBaseExpr( old,
2270 new ast::KeywordCastExpr(
2271 old->location,
2272 GET_ACCEPT_1(arg, Expr),
[4ef08f7]2273 castTarget,
2274 {old->concrete_target.field, old->concrete_target.getter}
[28c89f4]2275 )
2276 );
[6d51bd7]2277 }
2278
[7870799]2279 virtual void visit( const VirtualCastExpr * old ) override final {
[20de6fb]2280 this->node = visitBaseExpr_SkipResultType( old,
[28c89f4]2281 new ast::VirtualCastExpr(
2282 old->location,
2283 GET_ACCEPT_1(arg, Expr),
[20de6fb]2284 GET_ACCEPT_1(result, Type)
[28c89f4]2285 )
2286 );
[6d51bd7]2287 }
2288
[7870799]2289 virtual void visit( const AddressExpr * old ) override final {
[28c89f4]2290 this->node = visitBaseExpr( old,
2291 new ast::AddressExpr(
2292 old->location,
2293 GET_ACCEPT_1(arg, Expr)
2294 )
2295 );
[6d51bd7]2296 }
2297
[7870799]2298 virtual void visit( const LabelAddressExpr * old ) override final {
[28c89f4]2299 this->node = visitBaseExpr( old,
2300 new ast::LabelAddressExpr(
2301 old->location,
2302 make_label(&old->arg)
2303 )
2304 );
[6d51bd7]2305 }
2306
[7870799]2307 virtual void visit( const UntypedMemberExpr * old ) override final {
[28c89f4]2308 this->node = visitBaseExpr( old,
2309 new ast::UntypedMemberExpr(
2310 old->location,
2311 GET_ACCEPT_1(member, Expr),
2312 GET_ACCEPT_1(aggregate, Expr)
2313 )
2314 );
[6d51bd7]2315 }
2316
[7870799]2317 virtual void visit( const MemberExpr * old ) override final {
[28c89f4]2318 this->node = visitBaseExpr( old,
2319 new ast::MemberExpr(
2320 old->location,
[2a54479]2321 GET_ACCEPT_1(member, DeclWithType),
[ae265b55]2322 GET_ACCEPT_1(aggregate, Expr),
2323 ast::MemberExpr::NoOpConstructionChosen
[28c89f4]2324 )
2325 );
[6d51bd7]2326 }
2327
[7870799]2328 virtual void visit( const VariableExpr * old ) override final {
[546e712]2329 auto expr = new ast::VariableExpr(
2330 old->location
2331 );
2332
2333 expr->var = GET_ACCEPT_1(var, DeclWithType);
[6896548]2334 visitBaseExpr( old, expr );
[6d51bd7]2335
[546e712]2336 this->node = expr;
[6d51bd7]2337 }
2338
[7870799]2339 virtual void visit( const ConstantExpr * old ) override final {
[c36298d]2340 ast::ConstantExpr *rslt = new ast::ConstantExpr(
2341 old->location,
2342 GET_ACCEPT_1(result, Type),
[7870799]2343 old->constant.rep,
[c36298d]2344 old->constant.ival
2345 );
[7870799]2346 rslt->underlyer = getAccept1< ast::Type, Type* >( old->constant.type );
[28c89f4]2347 this->node = visitBaseExpr( old, rslt );
2348 }
2349
[7870799]2350 virtual void visit( const SizeofExpr * old ) override final {
[28c89f4]2351 assert (old->expr || old->type);
2352 assert (! (old->expr && old->type));
2353 ast::SizeofExpr *rslt;
2354 if (old->expr) {
2355 assert(!old->isType);
2356 rslt = new ast::SizeofExpr(
[0b57626]2357 old->location,
[28c89f4]2358 GET_ACCEPT_1(expr, Expr)
2359 );
2360 }
2361 if (old->type) {
2362 assert(old->isType);
2363 rslt = new ast::SizeofExpr(
[0b57626]2364 old->location,
[28c89f4]2365 GET_ACCEPT_1(type, Type)
2366 );
2367 }
2368 this->node = visitBaseExpr( old, rslt );
2369 }
2370
[7870799]2371 virtual void visit( const AlignofExpr * old ) override final {
[28c89f4]2372 assert (old->expr || old->type);
2373 assert (! (old->expr && old->type));
2374 ast::AlignofExpr *rslt;
2375 if (old->expr) {
2376 assert(!old->isType);
2377 rslt = new ast::AlignofExpr(
[0b57626]2378 old->location,
[28c89f4]2379 GET_ACCEPT_1(expr, Expr)
2380 );
2381 }
2382 if (old->type) {
2383 assert(old->isType);
2384 rslt = new ast::AlignofExpr(
[0b57626]2385 old->location,
[28c89f4]2386 GET_ACCEPT_1(type, Type)
2387 );
2388 }
2389 this->node = visitBaseExpr( old, rslt );
[6d51bd7]2390 }
2391
[7870799]2392 virtual void visit( const UntypedOffsetofExpr * old ) override final {
[28c89f4]2393 this->node = visitBaseExpr( old,
2394 new ast::UntypedOffsetofExpr(
2395 old->location,
2396 GET_ACCEPT_1(type, Type),
2397 old->member
2398 )
2399 );
[6d51bd7]2400 }
2401
[7870799]2402 virtual void visit( const OffsetofExpr * old ) override final {
[28c89f4]2403 this->node = visitBaseExpr( old,
2404 new ast::OffsetofExpr(
2405 old->location,
2406 GET_ACCEPT_1(type, Type),
[2a54479]2407 GET_ACCEPT_1(member, DeclWithType)
[28c89f4]2408 )
2409 );
[6d51bd7]2410 }
2411
[7870799]2412 virtual void visit( const OffsetPackExpr * old ) override final {
[28c89f4]2413 this->node = visitBaseExpr( old,
2414 new ast::OffsetPackExpr(
2415 old->location,
2416 GET_ACCEPT_1(type, StructInstType)
2417 )
2418 );
[6d51bd7]2419 }
2420
[7870799]2421 virtual void visit( const LogicalExpr * old ) override final {
[28c89f4]2422 this->node = visitBaseExpr( old,
2423 new ast::LogicalExpr(
2424 old->location,
2425 GET_ACCEPT_1(arg1, Expr),
2426 GET_ACCEPT_1(arg2, Expr),
[0b57626]2427 old->get_isAnd() ?
[28c89f4]2428 ast::LogicalFlag::AndExpr :
2429 ast::LogicalFlag::OrExpr
2430 )
2431 );
[6d51bd7]2432 }
2433
[7870799]2434 virtual void visit( const ConditionalExpr * old ) override final {
[28c89f4]2435 this->node = visitBaseExpr( old,
2436 new ast::ConditionalExpr(
2437 old->location,
2438 GET_ACCEPT_1(arg1, Expr),
2439 GET_ACCEPT_1(arg2, Expr),
2440 GET_ACCEPT_1(arg3, Expr)
2441 )
2442 );
2443 }
[6d51bd7]2444
[7870799]2445 virtual void visit( const CommaExpr * old ) override final {
[28c89f4]2446 this->node = visitBaseExpr( old,
2447 new ast::CommaExpr(
2448 old->location,
2449 GET_ACCEPT_1(arg1, Expr),
2450 GET_ACCEPT_1(arg2, Expr)
2451 )
2452 );
[6d51bd7]2453 }
2454
[7870799]2455 virtual void visit( const TypeExpr * old ) override final {
[20de6fb]2456 this->node = visitBaseExpr( old,
2457 new ast::TypeExpr(
2458 old->location,
2459 GET_ACCEPT_1(type, Type)
2460 )
2461 );
[6d51bd7]2462 }
2463
[6e50a6b]2464 virtual void visit( const DimensionExpr * old ) override final {
2465 // DimensionExpr gets desugared away in Validate.
2466 // As long as new-AST passes don't use it, this cheap-cheerful error
2467 // detection helps ensure that these occurrences have been compiled
2468 // away, as expected. To move the DimensionExpr boundary downstream
2469 // or move the new-AST translation boundary upstream, implement
2470 // DimensionExpr in the new AST and implement a conversion.
2471 (void) old;
2472 assert(false && "DimensionExpr should not be present at new-AST boundary");
2473 }
2474
[7870799]2475 virtual void visit( const AsmExpr * old ) override final {
[20de6fb]2476 this->node = visitBaseExpr( old,
2477 new ast::AsmExpr(
2478 old->location,
[665f432]2479 old->inout,
[20de6fb]2480 GET_ACCEPT_1(constraint, Expr),
2481 GET_ACCEPT_1(operand, Expr)
2482 )
2483 );
[6d51bd7]2484 }
2485
[7870799]2486 virtual void visit( const ImplicitCopyCtorExpr * old ) override final {
[20de6fb]2487 auto rslt = new ast::ImplicitCopyCtorExpr(
2488 old->location,
2489 GET_ACCEPT_1(callExpr, ApplicationExpr)
2490 );
[6d51bd7]2491
[20de6fb]2492 this->node = visitBaseExpr( old, rslt );
[6d51bd7]2493 }
2494
[7870799]2495 virtual void visit( const ConstructorExpr * old ) override final {
[20de6fb]2496 this->node = visitBaseExpr( old,
2497 new ast::ConstructorExpr(
2498 old->location,
2499 GET_ACCEPT_1(callExpr, Expr)
2500 )
2501 );
[6d51bd7]2502 }
2503
[7870799]2504 virtual void visit( const CompoundLiteralExpr * old ) override final {
[20de6fb]2505 this->node = visitBaseExpr_SkipResultType( old,
2506 new ast::CompoundLiteralExpr(
2507 old->location,
2508 GET_ACCEPT_1(result, Type),
2509 GET_ACCEPT_1(initializer, Init)
2510 )
2511 );
[6d51bd7]2512 }
2513
[7870799]2514 virtual void visit( const RangeExpr * old ) override final {
[20de6fb]2515 this->node = visitBaseExpr( old,
2516 new ast::RangeExpr(
2517 old->location,
2518 GET_ACCEPT_1(low, Expr),
2519 GET_ACCEPT_1(high, Expr)
2520 )
2521 );
[6d51bd7]2522 }
2523
[7870799]2524 virtual void visit( const UntypedTupleExpr * old ) override final {
[20de6fb]2525 this->node = visitBaseExpr( old,
2526 new ast::UntypedTupleExpr(
2527 old->location,
2528 GET_ACCEPT_V(exprs, Expr)
2529 )
2530 );
[6d51bd7]2531 }
2532
[7870799]2533 virtual void visit( const TupleExpr * old ) override final {
[20de6fb]2534 this->node = visitBaseExpr( old,
2535 new ast::TupleExpr(
2536 old->location,
2537 GET_ACCEPT_V(exprs, Expr)
2538 )
2539 );
[6d51bd7]2540 }
2541
[7870799]2542 virtual void visit( const TupleIndexExpr * old ) override final {
[20de6fb]2543 this->node = visitBaseExpr( old,
2544 new ast::TupleIndexExpr(
2545 old->location,
2546 GET_ACCEPT_1(tuple, Expr),
2547 old->index
2548 )
2549 );
[6d51bd7]2550 }
2551
[7870799]2552 virtual void visit( const TupleAssignExpr * old ) override final {
[20de6fb]2553 this->node = visitBaseExpr_SkipResultType( old,
2554 new ast::TupleAssignExpr(
2555 old->location,
2556 GET_ACCEPT_1(result, Type),
2557 GET_ACCEPT_1(stmtExpr, StmtExpr)
2558 )
2559 );
[6d51bd7]2560 }
2561
[7870799]2562 virtual void visit( const StmtExpr * old ) override final {
[20de6fb]2563 auto rslt = new ast::StmtExpr(
2564 old->location,
2565 GET_ACCEPT_1(statements, CompoundStmt)
2566 );
2567 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl);
2568 rslt->dtors = GET_ACCEPT_V(dtors , Expr);
[6d51bd7]2569
[20de6fb]2570 this->node = visitBaseExpr_SkipResultType( old, rslt );
[6d51bd7]2571 }
2572
[7870799]2573 virtual void visit( const UniqueExpr * old ) override final {
[20de6fb]2574 auto rslt = new ast::UniqueExpr(
2575 old->location,
[a2a85658]2576 GET_ACCEPT_1(expr, Expr),
2577 old->get_id()
[20de6fb]2578 );
2579 rslt->object = GET_ACCEPT_1(object, ObjectDecl);
2580 rslt->var = GET_ACCEPT_1(var , VariableExpr);
[6d51bd7]2581
[20de6fb]2582 this->node = visitBaseExpr( old, rslt );
[6d51bd7]2583 }
2584
[7870799]2585 virtual void visit( const UntypedInitExpr * old ) override final {
[60aaa51d]2586 std::deque<ast::InitAlternative> initAlts;
[20de6fb]2587 for (auto ia : old->initAlts) {
2588 initAlts.push_back(ast::InitAlternative(
2589 getAccept1< ast::Type, Type * >( ia.type ),
2590 getAccept1< ast::Designation, Designation * >( ia.designation )
2591 ));
2592 }
2593 this->node = visitBaseExpr( old,
2594 new ast::UntypedInitExpr(
2595 old->location,
2596 GET_ACCEPT_1(expr, Expr),
2597 std::move(initAlts)
2598 )
2599 );
[6d51bd7]2600 }
2601
[7870799]2602 virtual void visit( const InitExpr * old ) override final {
[20de6fb]2603 this->node = visitBaseExpr( old,
2604 new ast::InitExpr(
2605 old->location,
2606 GET_ACCEPT_1(expr, Expr),
2607 GET_ACCEPT_1(designation, Designation)
2608 )
2609 );
[6d51bd7]2610 }
2611
[7870799]2612 virtual void visit( const DeletedExpr * old ) override final {
[20de6fb]2613 this->node = visitBaseExpr( old,
2614 new ast::DeletedExpr(
2615 old->location,
2616 GET_ACCEPT_1(expr, Expr),
2617 inCache(old->deleteStmt) ?
[e67991f]2618 strict_dynamic_cast<ast::Decl*>(this->node) :
2619 GET_ACCEPT_1(deleteStmt, Decl)
[20de6fb]2620 )
2621 );
[6d51bd7]2622 }
2623
[7870799]2624 virtual void visit( const DefaultArgExpr * old ) override final {
[20de6fb]2625 this->node = visitBaseExpr( old,
2626 new ast::DefaultArgExpr(
2627 old->location,
2628 GET_ACCEPT_1(expr, Expr)
2629 )
2630 );
2631 }
[6d51bd7]2632
[7870799]2633 virtual void visit( const GenericExpr * old ) override final {
[20de6fb]2634 std::vector<ast::GenericExpr::Association> associations;
2635 for (auto association : old->associations) {
2636 associations.push_back(ast::GenericExpr::Association(
2637 getAccept1< ast::Type, Type * >( association.type ),
2638 getAccept1< ast::Expr, Expression * >( association.expr )
2639 ));
2640 }
2641 this->node = visitBaseExpr( old,
2642 new ast::GenericExpr(
2643 old->location,
2644 GET_ACCEPT_1(control, Expr),
2645 std::move(associations)
2646 )
2647 );
[6d51bd7]2648 }
2649
[7870799]2650 void visitType( const Type * old, ast::Type * type ) {
[1ae47de]2651 // Some types do this in their constructor so add a check.
2652 if ( !old->attributes.empty() && type->attributes.empty() ) {
2653 type->attributes = GET_ACCEPT_V(attributes, Attribute);
2654 }
2655 this->node = type;
2656 }
2657
[7870799]2658 virtual void visit( const VoidType * old ) override final {
[1ae47de]2659 visitType( old, new ast::VoidType{ cv( old ) } );
[6d51bd7]2660 }
2661
[7870799]2662 virtual void visit( const BasicType * old ) override final {
[2a54479]2663 auto type = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) };
2664 // I believe this should always be a BasicType.
2665 if ( Validate::SizeType == old ) {
[490fb92e]2666 ast::sizeType = type;
[2a54479]2667 }
[1ae47de]2668 visitType( old, type );
[6d51bd7]2669 }
2670
[7870799]2671 virtual void visit( const PointerType * old ) override final {
[1ae47de]2672 visitType( old, new ast::PointerType{
[d148778]2673 GET_ACCEPT_1( base, Type ),
2674 GET_ACCEPT_1( dimension, Expr ),
2675 (ast::LengthFlag)old->isVarLen,
2676 (ast::DimensionFlag)old->isStatic,
2677 cv( old )
[1ae47de]2678 } );
[6d51bd7]2679 }
2680
[7870799]2681 virtual void visit( const ArrayType * old ) override final {
[1ae47de]2682 visitType( old, new ast::ArrayType{
[d148778]2683 GET_ACCEPT_1( base, Type ),
2684 GET_ACCEPT_1( dimension, Expr ),
2685 (ast::LengthFlag)old->isVarLen,
2686 (ast::DimensionFlag)old->isStatic,
2687 cv( old )
[1ae47de]2688 } );
[6d51bd7]2689 }
2690
[7870799]2691 virtual void visit( const ReferenceType * old ) override final {
[1ae47de]2692 visitType( old, new ast::ReferenceType{
[d148778]2693 GET_ACCEPT_1( base, Type ),
2694 cv( old )
[1ae47de]2695 } );
[6d51bd7]2696 }
2697
[7870799]2698 virtual void visit( const QualifiedType * old ) override final {
[1ae47de]2699 visitType( old, new ast::QualifiedType{
[d148778]2700 GET_ACCEPT_1( parent, Type ),
2701 GET_ACCEPT_1( child, Type ),
2702 cv( old )
[1ae47de]2703 } );
[6d51bd7]2704 }
2705
[7870799]2706 virtual void visit( const FunctionType * old ) override final {
[d148778]2707 auto ty = new ast::FunctionType {
2708 (ast::ArgumentFlag)old->isVarArgs,
2709 cv( old )
2710 };
[954c954]2711 auto returnVars = GET_ACCEPT_V(returnVals, DeclWithType);
2712 auto paramVars = GET_ACCEPT_V(parameters, DeclWithType);
2713 // ty->returns = GET_ACCEPT_V( returnVals, DeclWithType );
2714 // ty->params = GET_ACCEPT_V( parameters, DeclWithType );
2715 for (auto & v: returnVars) {
2716 ty->returns.emplace_back(v->get_type());
2717 }
2718 for (auto & v: paramVars) {
2719 ty->params.emplace_back(v->get_type());
2720 }
[3e5dd913]2721 // xxx - when will this be non-null?
2722 // will have to create dangling (no-owner) decls to be pointed to
2723 auto foralls = GET_ACCEPT_V( forall, TypeDecl );
2724
2725 for (auto & param : foralls) {
[b230091]2726 ty->forall.emplace_back(new ast::TypeInstType(param));
[3e5dd913]2727 for (auto asst : param->assertions) {
2728 ty->assertions.emplace_back(new ast::VariableExpr({}, asst));
2729 }
2730 }
[1ae47de]2731 visitType( old, ty );
[6d51bd7]2732 }
2733
[98e8b3b]2734 void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) {
[d148778]2735 ty->params = GET_ACCEPT_V( parameters, Expr );
2736 ty->hoistType = old->hoistType;
[1ae47de]2737 visitType( old, ty );
[6d51bd7]2738 }
2739
[7870799]2740 virtual void visit( const StructInstType * old ) override final {
[b869ec5]2741 ast::StructInstType * ty;
2742 if ( old->baseStruct ) {
2743 ty = new ast::StructInstType{
2744 GET_ACCEPT_1( baseStruct, StructDecl ),
2745 cv( old ),
2746 GET_ACCEPT_V( attributes, Attribute )
2747 };
2748 } else {
2749 ty = new ast::StructInstType{
2750 old->name,
2751 cv( old ),
2752 GET_ACCEPT_V( attributes, Attribute )
2753 };
2754 }
[d148778]2755 postvisit( old, ty );
[6d51bd7]2756 }
2757
[7870799]2758 virtual void visit( const UnionInstType * old ) override final {
[b869ec5]2759 ast::UnionInstType * ty;
2760 if ( old->baseUnion ) {
2761 ty = new ast::UnionInstType{
2762 GET_ACCEPT_1( baseUnion, UnionDecl ),
2763 cv( old ),
2764 GET_ACCEPT_V( attributes, Attribute )
2765 };
2766 } else {
2767 ty = new ast::UnionInstType{
2768 old->name,
2769 cv( old ),
2770 GET_ACCEPT_V( attributes, Attribute )
2771 };
2772 }
[d148778]2773 postvisit( old, ty );
[6d51bd7]2774 }
2775
[3e54399]2776 virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage.
2777 ast::EnumInstType * ty;
[b869ec5]2778 if ( old->baseEnum ) {
[4559b34]2779 ty = new ast::EnumInstType{ // Probably here: missing the specification of the base
[b869ec5]2780 GET_ACCEPT_1( baseEnum, EnumDecl ),
2781 cv( old ),
2782 GET_ACCEPT_V( attributes, Attribute )
2783 };
2784 } else {
2785 ty = new ast::EnumInstType{
2786 old->name,
2787 cv( old ),
2788 GET_ACCEPT_V( attributes, Attribute )
2789 };
2790 }
[d148778]2791 postvisit( old, ty );
[6d51bd7]2792 }
2793
[7870799]2794 virtual void visit( const TraitInstType * old ) override final {
[b869ec5]2795 ast::TraitInstType * ty;
2796 if ( old->baseTrait ) {
2797 ty = new ast::TraitInstType{
2798 GET_ACCEPT_1( baseTrait, TraitDecl ),
2799 cv( old ),
2800 GET_ACCEPT_V( attributes, Attribute )
2801 };
2802 } else {
2803 ty = new ast::TraitInstType{
2804 old->name,
2805 cv( old ),
2806 GET_ACCEPT_V( attributes, Attribute )
2807 };
2808 }
[d148778]2809 postvisit( old, ty );
2810 }
[6d51bd7]2811
[7870799]2812 virtual void visit( const TypeInstType * old ) override final {
[514a791]2813 ast::TypeInstType * ty;
2814 if ( old->baseType ) {
2815 ty = new ast::TypeInstType{
2816 old->name,
[b869ec5]2817 GET_ACCEPT_1( baseType, TypeDecl ),
[514a791]2818 cv( old ),
2819 GET_ACCEPT_V( attributes, Attribute )
2820 };
2821 } else {
2822 ty = new ast::TypeInstType{
2823 old->name,
[07de76b]2824 old->isFtype ? ast::TypeDecl::Ftype : ast::TypeDecl::Dtype,
[514a791]2825 cv( old ),
2826 GET_ACCEPT_V( attributes, Attribute )
2827 };
2828 }
[d148778]2829 postvisit( old, ty );
[6d51bd7]2830 }
2831
[7870799]2832 virtual void visit( const TupleType * old ) override final {
[1ae47de]2833 visitType( old, new ast::TupleType{
[746ae82]2834 GET_ACCEPT_V( types, Type ),
2835 // members generated by TupleType c'tor
2836 cv( old )
[1ae47de]2837 } );
[6d51bd7]2838 }
2839
[7870799]2840 virtual void visit( const TypeofType * old ) override final {
[1ae47de]2841 visitType( old, new ast::TypeofType{
[746ae82]2842 GET_ACCEPT_1( expr, Expr ),
2843 (ast::TypeofType::Kind)old->is_basetypeof,
2844 cv( old )
[1ae47de]2845 } );
[6d51bd7]2846 }
2847
[cc64be1d]2848 virtual void visit( const VTableType * old ) override final {
2849 visitType( old, new ast::VTableType{
2850 GET_ACCEPT_1( base, Type ),
2851 cv( old )
2852 } );
2853 }
2854
[7870799]2855 virtual void visit( const AttrType * ) override final {
[746ae82]2856 assertf( false, "AttrType deprecated in new AST." );
[6d51bd7]2857 }
2858
[7870799]2859 virtual void visit( const VarArgsType * old ) override final {
[1ae47de]2860 visitType( old, new ast::VarArgsType{ cv( old ) } );
[6d51bd7]2861 }
2862
[7870799]2863 virtual void visit( const ZeroType * old ) override final {
[1ae47de]2864 visitType( old, new ast::ZeroType{ cv( old ) } );
[6d51bd7]2865 }
2866
[7870799]2867 virtual void visit( const OneType * old ) override final {
[1ae47de]2868 visitType( old, new ast::OneType{ cv( old ) } );
[6d51bd7]2869 }
2870
[7870799]2871 virtual void visit( const GlobalScopeType * old ) override final {
[1ae47de]2872 visitType( old, new ast::GlobalScopeType{} );
[6d51bd7]2873 }
2874
[7870799]2875 virtual void visit( const Designation * old ) override final {
[74ad8c0]2876 this->node = new ast::Designation(
2877 old->location,
[60aaa51d]2878 GET_ACCEPT_D(designators, Expr)
[74ad8c0]2879 );
[6d51bd7]2880 }
2881
[7870799]2882 virtual void visit( const SingleInit * old ) override final {
[74ad8c0]2883 this->node = new ast::SingleInit(
2884 old->location,
2885 GET_ACCEPT_1(value, Expr),
[16ba4a6f]2886 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct
[74ad8c0]2887 );
[6d51bd7]2888 }
2889
[7870799]2890 virtual void visit( const ListInit * old ) override final {
[74ad8c0]2891 this->node = new ast::ListInit(
2892 old->location,
2893 GET_ACCEPT_V(initializers, Init),
2894 GET_ACCEPT_V(designations, Designation),
[16ba4a6f]2895 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct
[74ad8c0]2896 );
[6d51bd7]2897 }
2898
[7870799]2899 virtual void visit( const ConstructorInit * old ) override final {
[74ad8c0]2900 this->node = new ast::ConstructorInit(
2901 old->location,
2902 GET_ACCEPT_1(ctor, Stmt),
2903 GET_ACCEPT_1(dtor, Stmt),
2904 GET_ACCEPT_1(init, Init)
2905 );
[6d51bd7]2906 }
2907
[7870799]2908 virtual void visit( const Constant * ) override final {
[dd6d7c6]2909 // Handled in visit( ConstantEpxr * ).
2910 // In the new tree, Constant fields are inlined into containing ConstantExpression.
2911 assert( 0 );
[6d51bd7]2912 }
2913
[7870799]2914 virtual void visit( const Attribute * old ) override final {
[dd6d7c6]2915 this->node = new ast::Attribute(
2916 old->name,
2917 GET_ACCEPT_V( parameters, Expr )
2918 );
[6d51bd7]2919 }
2920};
2921
[6f8e87d]2922#undef GET_LABELS_V
2923#undef GET_ACCEPT_V
2924#undef GET_ACCEPT_1
2925
[293dc1c]2926ast::TranslationUnit convert( const std::list< Declaration * > && translationUnit ) {
[6d51bd7]2927 ConverterOldToNew c;
[293dc1c]2928 ast::TranslationUnit unit;
[b3a0df6]2929 if (Validate::SizeType) {
2930 // this should be a BasicType.
2931 auto old = strict_dynamic_cast<BasicType *>(Validate::SizeType);
2932 ast::sizeType = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind };
2933 }
2934
[6d51bd7]2935 for(auto d : translationUnit) {
2936 d->accept( c );
[293dc1c]2937 unit.decls.emplace_back( c.decl() );
[6d51bd7]2938 }
[8abee136]2939 deleteAll(translationUnit);
[23954b6]2940
2941 // Load the local static varables into the global store.
2942 unit.global.sizeType = ast::sizeType;
2943 unit.global.dereference = ast::dereferenceOperator;
2944 unit.global.dtorStruct = ast::dtorStruct;
2945 unit.global.dtorDestroy = ast::dtorStructDestroy;
2946
[293dc1c]2947 return unit;
[6f8e87d]2948}
Note: See TracBrowser for help on using the repository browser.