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