Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r4559b34 rb230091  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  2 13:19:22 2022
    13 // Update Count     : 41
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Mar 16 15:01:00 2022
     13// Update Count     : 42
    1414//
    1515
     
    4949//================================================================================================
    5050namespace ast {
    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
    57 ast::ptr<ast::Type> sizeType = nullptr;
    58 const ast::FunctionDecl * dereferenceOperator = nullptr;
    59 const ast::StructDecl   * dtorStruct = nullptr;
    60 const ast::FunctionDecl * dtorStructDestroy = nullptr;
     51// These are the shared local information used by ConverterNewToOld and
     52// ConverterOldToNew to update the global information in the two versions.
     53
     54static ast::ptr<ast::Type> sizeType = nullptr;
     55static const ast::FunctionDecl * dereferenceOperator = nullptr;
     56static const ast::StructDecl   * dtorStruct = nullptr;
     57static const ast::FunctionDecl * dtorStructDestroy = nullptr;
    6158
    6259}
     
    276273                decl->parent = get<AggregateDecl>().accept1( node->parent );
    277274                declPostamble( decl, node );
    278                 return nullptr; // ??
     275                return nullptr;
    279276        }
    280277
     
    310307                        node->name,
    311308                        get<Attribute>().acceptL( node->attributes ),
    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
     309                        LinkageSpec::Spec( node->linkage.val )
     310                );
     311                return aggregatePostamble( decl, node );
    316312        }
    317313
     
    355351                this->node = stmt;
    356352                return nullptr;
     353        }
     354
     355        void clausePostamble( Statement * stmt, const ast::StmtClause * node ) {
     356                stmt->location = node->location;
     357                this->node = stmt;
    357358        }
    358359
     
    405406                auto stmt = new SwitchStmt(
    406407                        get<Expression>().accept1( node->cond ),
    407                         get<Statement>().acceptL( node->stmts )
     408                        get<Statement>().acceptL( node->cases )
    408409                );
    409410                return stmtPostamble( stmt, node );
    410411        }
    411412
    412         const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
     413        const ast::CaseClause * visit( const ast::CaseClause * node ) override final {
    413414                if ( inCache( node ) ) return nullptr;
    414415                auto stmt = new CaseStmt(
     
    417418                        node->isDefault()
    418419                );
    419                 return stmtPostamble( stmt, node );
     420                clausePostamble( stmt, node );
     421                return nullptr;
    420422        }
    421423
     
    513515        }
    514516
    515         const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
     517        const ast::CatchClause * visit( const ast::CatchClause * node ) override final {
    516518                if ( inCache( node ) ) return nullptr;
    517519                CatchStmt::Kind kind;
     
    524526                        break;
    525527                default:
    526                         assertf(false, "Invalid ast::CatchStmt::Kind: %d\n", node->kind);
     528                        assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind);
    527529                }
    528530                auto stmt = new CatchStmt(
     
    532534                        get<Statement>().accept1( node->body )
    533535                );
    534                 return stmtPostamble( stmt, node );
    535         }
    536 
    537         const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
     536                return clausePostamble( stmt, node ), nullptr;
     537        }
     538
     539        const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final {
    538540                if ( inCache( node ) ) return nullptr;
    539541                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    540                 return stmtPostamble( stmt, node );
     542                return clausePostamble( stmt, node ), nullptr;
    541543        }
    542544
     
    14681470                return strict_dynamic_cast< ast::Decl * >( node );
    14691471        }
    1470        
     1472
    14711473        ConverterOldToNew() = default;
    14721474        ConverterOldToNew(const ConverterOldToNew &) = delete;
     
    14961498                getAccept1< ast::type, decltype( old->child ) >( old->child )
    14971499
    1498 
    14991500        template<typename NewT, typename OldC>
    15001501        std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) {
     
    15111512#       define GET_ACCEPT_V(child, type) \
    15121513                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 )
    15161514
    15171515        template<typename NewT, typename OldC>
     
    17151713        }
    17161714
    1717         // Convert SynTree::EnumDecl to AST::EnumDecl
    17181715        virtual void visit( const EnumDecl * old ) override final {
    17191716                if ( inCache( old ) ) return;
     
    17221719                        old->name,
    17231720                        GET_ACCEPT_V(attributes, Attribute),
    1724                         { old->linkage.val },
    1725                         GET_ACCEPT_1(base, Type),
    1726                         old->enumValues
     1721                        { old->linkage.val }
    17271722                );
    17281723                cache.emplace( old, decl );
     
    17341729                decl->uniqueId   = old->uniqueId;
    17351730                decl->storage    = { old->storageClasses.val };
     1731
    17361732                this->node = decl;
    17371733        }
     
    18941890                        old->location,
    18951891                        GET_ACCEPT_1(condition, Expr),
    1896                         GET_ACCEPT_V(statements, Stmt),
     1892                        GET_ACCEPT_V(statements, CaseClause),
    18971893                        GET_LABELS_V(old->labels)
    18981894                );
     
    19021898        virtual void visit( const CaseStmt * old ) override final {
    19031899                if ( inCache( old ) ) return;
    1904                 this->node = new ast::CaseStmt(
     1900                this->node = new ast::CaseClause(
    19051901                        old->location,
    19061902                        GET_ACCEPT_1(condition, Expr),
    1907                         GET_ACCEPT_V(stmts, Stmt),
    1908                         GET_LABELS_V(old->labels)
    1909                 );
     1903                        GET_ACCEPT_V(stmts, Stmt)
     1904                );
     1905                auto labels = GET_LABELS_V(old->labels);
     1906                assertf(labels.empty(), "Labels found on CaseStmt.");
    19101907                cache.emplace( old, this->node );
    19111908        }
     
    20152012                        old->location,
    20162013                        GET_ACCEPT_1(block, CompoundStmt),
    2017                         GET_ACCEPT_V(handlers, CatchStmt),
    2018                         GET_ACCEPT_1(finallyBlock, FinallyStmt),
     2014                        GET_ACCEPT_V(handlers, CatchClause),
     2015                        GET_ACCEPT_1(finallyBlock, FinallyClause),
    20192016                        GET_LABELS_V(old->labels)
    20202017                );
     
    20362033                }
    20372034
    2038                 this->node = new ast::CatchStmt(
     2035                this->node = new ast::CatchClause(
    20392036                        old->location,
    20402037                        kind,
    20412038                        GET_ACCEPT_1(decl, Decl),
    20422039                        GET_ACCEPT_1(cond, Expr),
    2043                         GET_ACCEPT_1(body, Stmt),
    2044                         GET_LABELS_V(old->labels)
    2045                 );
     2040                        GET_ACCEPT_1(body, Stmt)
     2041                );
     2042                auto labels = GET_LABELS_V(old->labels);
     2043                assertf(labels.empty(), "Labels found on CatchStmt.");
    20462044                cache.emplace( old, this->node );
    20472045        }
     
    20492047        virtual void visit( const FinallyStmt * old ) override final {
    20502048                if ( inCache( old ) ) return;
    2051                 this->node = new ast::FinallyStmt(
    2052                         old->location,
    2053                         GET_ACCEPT_1(block, CompoundStmt),
    2054                         GET_LABELS_V(old->labels)
    2055                 );
     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.");
    20562055                cache.emplace( old, this->node );
    20572056        }
     
    27182717
    27192718                for (auto & param : foralls) {
    2720                         ty->forall.emplace_back(new ast::TypeInstType(param->name, param));
     2719                        ty->forall.emplace_back(new ast::TypeInstType(param));
    27212720                        for (auto asst : param->assertions) {
    27222721                                ty->assertions.emplace_back(new ast::VariableExpr({}, asst));
     
    27682767        }
    27692768
    2770         virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage.
    2771                 ast::EnumInstType * ty; 
     2769        virtual void visit( const EnumInstType * old ) override final {
     2770                ast::EnumInstType * ty;
    27722771                if ( old->baseEnum ) {
    2773                         ty = new ast::EnumInstType{ // Probably here: missing the specification of the base
     2772                        ty = new ast::EnumInstType{
    27742773                                GET_ACCEPT_1( baseEnum, EnumDecl ),
    27752774                                cv( old ),
Note: See TracChangeset for help on using the changeset viewer.