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