Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rb230091 r4559b34  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Mar 16 15:01:00 2022
    13 // Update Count     : 42
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Feb  2 13:19:22 2022
     13// Update Count     : 41
    1414//
    1515
     
    4949//================================================================================================
    5050namespace ast {
    51 // These are the shared local information used by ConverterNewToOld and
    52 // ConverterOldToNew to update the global information in the two versions.
    53 
    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;
     51
     52// This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not)
     53// allow us to use the same stratagy in the new ast.
     54// xxx - since convert back pass works, this concern seems to be unnecessary.
     55
     56// these need to be accessed in new FixInit now
     57ast::ptr<ast::Type> sizeType = nullptr;
     58const ast::FunctionDecl * dereferenceOperator = nullptr;
     59const ast::StructDecl   * dtorStruct = nullptr;
     60const ast::FunctionDecl * dtorStructDestroy = nullptr;
    5861
    5962}
     
    273276                decl->parent = get<AggregateDecl>().accept1( node->parent );
    274277                declPostamble( decl, node );
    275                 return nullptr;
     278                return nullptr; // ??
    276279        }
    277280
     
    307310                        node->name,
    308311                        get<Attribute>().acceptL( node->attributes ),
    309                         LinkageSpec::Spec( node->linkage.val )
    310                 );
    311                 return aggregatePostamble( decl, node );
     312                        LinkageSpec::Spec( node->linkage.val ),
     313                        get<Type>().accept1(node->base)
     314                );
     315                return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble
    312316        }
    313317
     
    351355                this->node = stmt;
    352356                return nullptr;
    353         }
    354 
    355         void clausePostamble( Statement * stmt, const ast::StmtClause * node ) {
    356                 stmt->location = node->location;
    357                 this->node = stmt;
    358357        }
    359358
     
    406405                auto stmt = new SwitchStmt(
    407406                        get<Expression>().accept1( node->cond ),
    408                         get<Statement>().acceptL( node->cases )
     407                        get<Statement>().acceptL( node->stmts )
    409408                );
    410409                return stmtPostamble( stmt, node );
    411410        }
    412411
    413         const ast::CaseClause * visit( const ast::CaseClause * node ) override final {
     412        const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
    414413                if ( inCache( node ) ) return nullptr;
    415414                auto stmt = new CaseStmt(
     
    418417                        node->isDefault()
    419418                );
    420                 clausePostamble( stmt, node );
    421                 return nullptr;
     419                return stmtPostamble( stmt, node );
    422420        }
    423421
     
    515513        }
    516514
    517         const ast::CatchClause * visit( const ast::CatchClause * node ) override final {
     515        const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
    518516                if ( inCache( node ) ) return nullptr;
    519517                CatchStmt::Kind kind;
     
    526524                        break;
    527525                default:
    528                         assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind);
     526                        assertf(false, "Invalid ast::CatchStmt::Kind: %d\n", node->kind);
    529527                }
    530528                auto stmt = new CatchStmt(
     
    534532                        get<Statement>().accept1( node->body )
    535533                );
    536                 return clausePostamble( stmt, node ), nullptr;
    537         }
    538 
    539         const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final {
     534                return stmtPostamble( stmt, node );
     535        }
     536
     537        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
    540538                if ( inCache( node ) ) return nullptr;
    541539                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    542                 return clausePostamble( stmt, node ), nullptr;
     540                return stmtPostamble( stmt, node );
    543541        }
    544542
     
    14701468                return strict_dynamic_cast< ast::Decl * >( node );
    14711469        }
    1472 
     1470       
    14731471        ConverterOldToNew() = default;
    14741472        ConverterOldToNew(const ConverterOldToNew &) = delete;
     
    14981496                getAccept1< ast::type, decltype( old->child ) >( old->child )
    14991497
     1498
    15001499        template<typename NewT, typename OldC>
    15011500        std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) {
     
    15121511#       define GET_ACCEPT_V(child, type) \
    15131512                getAcceptV< ast::type, decltype( old->child ) >( old->child )
     1513
     1514#       define GET_ACCEPT_E(child, type) \
     1515                getAccept1< ast::type, decltype( old->base ) >( old->base )
    15141516
    15151517        template<typename NewT, typename OldC>
     
    17131715        }
    17141716
     1717        // Convert SynTree::EnumDecl to AST::EnumDecl
    17151718        virtual void visit( const EnumDecl * old ) override final {
    17161719                if ( inCache( old ) ) return;
     
    17191722                        old->name,
    17201723                        GET_ACCEPT_V(attributes, Attribute),
    1721                         { old->linkage.val }
     1724                        { old->linkage.val },
     1725                        GET_ACCEPT_1(base, Type),
     1726                        old->enumValues
    17221727                );
    17231728                cache.emplace( old, decl );
     
    17291734                decl->uniqueId   = old->uniqueId;
    17301735                decl->storage    = { old->storageClasses.val };
    1731 
    17321736                this->node = decl;
    17331737        }
     
    18901894                        old->location,
    18911895                        GET_ACCEPT_1(condition, Expr),
    1892                         GET_ACCEPT_V(statements, CaseClause),
     1896                        GET_ACCEPT_V(statements, Stmt),
    18931897                        GET_LABELS_V(old->labels)
    18941898                );
     
    18981902        virtual void visit( const CaseStmt * old ) override final {
    18991903                if ( inCache( old ) ) return;
    1900                 this->node = new ast::CaseClause(
     1904                this->node = new ast::CaseStmt(
    19011905                        old->location,
    19021906                        GET_ACCEPT_1(condition, Expr),
    1903                         GET_ACCEPT_V(stmts, Stmt)
    1904                 );
    1905                 auto labels = GET_LABELS_V(old->labels);
    1906                 assertf(labels.empty(), "Labels found on CaseStmt.");
     1907                        GET_ACCEPT_V(stmts, Stmt),
     1908                        GET_LABELS_V(old->labels)
     1909                );
    19071910                cache.emplace( old, this->node );
    19081911        }
     
    20122015                        old->location,
    20132016                        GET_ACCEPT_1(block, CompoundStmt),
    2014                         GET_ACCEPT_V(handlers, CatchClause),
    2015                         GET_ACCEPT_1(finallyBlock, FinallyClause),
     2017                        GET_ACCEPT_V(handlers, CatchStmt),
     2018                        GET_ACCEPT_1(finallyBlock, FinallyStmt),
    20162019                        GET_LABELS_V(old->labels)
    20172020                );
     
    20332036                }
    20342037
    2035                 this->node = new ast::CatchClause(
     2038                this->node = new ast::CatchStmt(
    20362039                        old->location,
    20372040                        kind,
    20382041                        GET_ACCEPT_1(decl, Decl),
    20392042                        GET_ACCEPT_1(cond, Expr),
    2040                         GET_ACCEPT_1(body, Stmt)
    2041                 );
    2042                 auto labels = GET_LABELS_V(old->labels);
    2043                 assertf(labels.empty(), "Labels found on CatchStmt.");
     2043                        GET_ACCEPT_1(body, Stmt),
     2044                        GET_LABELS_V(old->labels)
     2045                );
    20442046                cache.emplace( old, this->node );
    20452047        }
     
    20472049        virtual void visit( const FinallyStmt * old ) override final {
    20482050                if ( inCache( old ) ) return;
    2049                 this->node = new ast::FinallyClause(
    2050                         old->location,
    2051                         GET_ACCEPT_1(block, CompoundStmt)
    2052                 );
    2053                 auto labels = GET_LABELS_V(old->labels);
    2054                 assertf(labels.empty(), "Labels found on FinallyStmt.");
     2051                this->node = new ast::FinallyStmt(
     2052                        old->location,
     2053                        GET_ACCEPT_1(block, CompoundStmt),
     2054                        GET_LABELS_V(old->labels)
     2055                );
    20552056                cache.emplace( old, this->node );
    20562057        }
     
    27172718
    27182719                for (auto & param : foralls) {
    2719                         ty->forall.emplace_back(new ast::TypeInstType(param));
     2720                        ty->forall.emplace_back(new ast::TypeInstType(param->name, param));
    27202721                        for (auto asst : param->assertions) {
    27212722                                ty->assertions.emplace_back(new ast::VariableExpr({}, asst));
     
    27672768        }
    27682769
    2769         virtual void visit( const EnumInstType * old ) override final {
    2770                 ast::EnumInstType * ty;
     2770        virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage.
     2771                ast::EnumInstType * ty; 
    27712772                if ( old->baseEnum ) {
    2772                         ty = new ast::EnumInstType{
     2773                        ty = new ast::EnumInstType{ // Probably here: missing the specification of the base
    27732774                                GET_ACCEPT_1( baseEnum, EnumDecl ),
    27742775                                cv( old ),
Note: See TracChangeset for help on using the changeset viewer.