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