Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r4ec9513 rff3b0249  
    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                         get<Type>().accept1(node->base)
    311                 );
    312                 return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble
     312                        LinkageSpec::Spec( node->linkage.val )
     313                );
     314                return aggregatePostamble( decl, node );
    313315        }
    314316
     
    352354                this->node = stmt;
    353355                return nullptr;
    354         }
    355 
    356         void clausePostamble( Statement * stmt, const ast::StmtClause * node ) {
    357                 stmt->location = node->location;
    358                 this->node = stmt;
    359356        }
    360357
     
    407404                auto stmt = new SwitchStmt(
    408405                        get<Expression>().accept1( node->cond ),
    409                         get<Statement>().acceptL( node->cases )
     406                        get<Statement>().acceptL( node->stmts )
    410407                );
    411408                return stmtPostamble( stmt, node );
    412409        }
    413410
    414         const ast::CaseClause * visit( const ast::CaseClause * node ) override final {
     411        const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
    415412                if ( inCache( node ) ) return nullptr;
    416413                auto stmt = new CaseStmt(
     
    419416                        node->isDefault()
    420417                );
    421                 clausePostamble( stmt, node );
    422                 return nullptr;
     418                return stmtPostamble( stmt, node );
    423419        }
    424420
     
    516512        }
    517513
    518         const ast::CatchClause * visit( const ast::CatchClause * node ) override final {
     514        const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
    519515                if ( inCache( node ) ) return nullptr;
    520516                CatchStmt::Kind kind;
     
    527523                        break;
    528524                default:
    529                         assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind);
     525                        assertf(false, "Invalid ast::CatchStmt::Kind: %d\n", node->kind);
    530526                }
    531527                auto stmt = new CatchStmt(
     
    535531                        get<Statement>().accept1( node->body )
    536532                );
    537                 return clausePostamble( stmt, node ), nullptr;
    538         }
    539 
    540         const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final {
     533                return stmtPostamble( stmt, node );
     534        }
     535
     536        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
    541537                if ( inCache( node ) ) return nullptr;
    542538                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    543                 return clausePostamble( stmt, node ), nullptr;
     539                return stmtPostamble( stmt, node );
    544540        }
    545541
     
    951947        }
    952948
    953         const ast::Expr * visit( const ast::DimensionExpr * node ) override final {
    954                 auto expr = visitBaseExpr( node, new DimensionExpr( node->name ) );
    955                 this->node = expr;
    956                 return nullptr;
    957         }
    958 
    959949        const ast::Expr * visit( const ast::AsmExpr * node ) override final {
    960950                auto expr = visitBaseExpr( node,
     
    14771467                return strict_dynamic_cast< ast::Decl * >( node );
    14781468        }
    1479        
     1469
    14801470        ConverterOldToNew() = default;
    14811471        ConverterOldToNew(const ConverterOldToNew &) = delete;
     
    15051495                getAccept1< ast::type, decltype( old->child ) >( old->child )
    15061496
    1507 
    15081497        template<typename NewT, typename OldC>
    15091498        std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) {
     
    15201509#       define GET_ACCEPT_V(child, type) \
    15211510                getAcceptV< ast::type, decltype( old->child ) >( old->child )
    1522 
    1523 #       define GET_ACCEPT_E(child, type) \
    1524                 getAccept1< ast::type, decltype( old->base ) >( old->base )
    15251511
    15261512        template<typename NewT, typename OldC>
     
    17241710        }
    17251711
    1726         // Convert SynTree::EnumDecl to AST::EnumDecl
    17271712        virtual void visit( const EnumDecl * old ) override final {
    17281713                if ( inCache( old ) ) return;
     
    17311716                        old->name,
    17321717                        GET_ACCEPT_V(attributes, Attribute),
    1733                         { old->linkage.val },
    1734                         GET_ACCEPT_1(base, Type),
    1735                         old->enumValues
     1718                        { old->linkage.val }
    17361719                );
    17371720                cache.emplace( old, decl );
     
    17431726                decl->uniqueId   = old->uniqueId;
    17441727                decl->storage    = { old->storageClasses.val };
     1728
    17451729                this->node = decl;
    17461730        }
     
    19031887                        old->location,
    19041888                        GET_ACCEPT_1(condition, Expr),
    1905                         GET_ACCEPT_V(statements, CaseClause),
     1889                        GET_ACCEPT_V(statements, Stmt),
    19061890                        GET_LABELS_V(old->labels)
    19071891                );
     
    19111895        virtual void visit( const CaseStmt * old ) override final {
    19121896                if ( inCache( old ) ) return;
    1913                 this->node = new ast::CaseClause(
     1897                this->node = new ast::CaseStmt(
    19141898                        old->location,
    19151899                        GET_ACCEPT_1(condition, Expr),
    1916                         GET_ACCEPT_V(stmts, Stmt)
    1917                 );
    1918                 auto labels = GET_LABELS_V(old->labels);
    1919                 assertf(labels.empty(), "Labels found on CaseStmt.");
     1900                        GET_ACCEPT_V(stmts, Stmt),
     1901                        GET_LABELS_V(old->labels)
     1902                );
    19201903                cache.emplace( old, this->node );
    19211904        }
     
    20252008                        old->location,
    20262009                        GET_ACCEPT_1(block, CompoundStmt),
    2027                         GET_ACCEPT_V(handlers, CatchClause),
    2028                         GET_ACCEPT_1(finallyBlock, FinallyClause),
     2010                        GET_ACCEPT_V(handlers, CatchStmt),
     2011                        GET_ACCEPT_1(finallyBlock, FinallyStmt),
    20292012                        GET_LABELS_V(old->labels)
    20302013                );
     
    20462029                }
    20472030
    2048                 this->node = new ast::CatchClause(
     2031                this->node = new ast::CatchStmt(
    20492032                        old->location,
    20502033                        kind,
    20512034                        GET_ACCEPT_1(decl, Decl),
    20522035                        GET_ACCEPT_1(cond, Expr),
    2053                         GET_ACCEPT_1(body, Stmt)
    2054                 );
    2055                 auto labels = GET_LABELS_V(old->labels);
    2056                 assertf(labels.empty(), "Labels found on CatchStmt.");
     2036                        GET_ACCEPT_1(body, Stmt),
     2037                        GET_LABELS_V(old->labels)
     2038                );
    20572039                cache.emplace( old, this->node );
    20582040        }
     
    20602042        virtual void visit( const FinallyStmt * old ) override final {
    20612043                if ( inCache( old ) ) return;
    2062                 this->node = new ast::FinallyClause(
    2063                         old->location,
    2064                         GET_ACCEPT_1(block, CompoundStmt)
    2065                 );
    2066                 auto labels = GET_LABELS_V(old->labels);
    2067                 assertf(labels.empty(), "Labels found on FinallyStmt.");
     2044                this->node = new ast::FinallyStmt(
     2045                        old->location,
     2046                        GET_ACCEPT_1(block, CompoundStmt),
     2047                        GET_LABELS_V(old->labels)
     2048                );
    20682049                cache.emplace( old, this->node );
    20692050        }
     
    24692450
    24702451        virtual void visit( const DimensionExpr * old ) override final {
    2471                 this->node = visitBaseExpr( old,
    2472                         new ast::DimensionExpr( old->location, old->name )
    2473                 );
     2452                // DimensionExpr gets desugared away in Validate.
     2453                // As long as new-AST passes don't use it, this cheap-cheerful error
     2454                // detection helps ensure that these occurrences have been compiled
     2455                // away, as expected.  To move the DimensionExpr boundary downstream
     2456                // or move the new-AST translation boundary upstream, implement
     2457                // DimensionExpr in the new AST and implement a conversion.
     2458                (void) old;
     2459                assert(false && "DimensionExpr should not be present at new-AST boundary");
    24742460        }
    24752461
     
    27252711
    27262712                for (auto & param : foralls) {
    2727                         ty->forall.emplace_back(new ast::TypeInstType(param));
     2713                        ty->forall.emplace_back(new ast::TypeInstType(param->name, param));
    27282714                        for (auto asst : param->assertions) {
    27292715                                ty->assertions.emplace_back(new ast::VariableExpr({}, asst));
     
    27752761        }
    27762762
    2777         virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage.
    2778                 ast::EnumInstType * ty; 
     2763        virtual void visit( const EnumInstType * old ) override final {
     2764                ast::EnumInstType * ty;
    27792765                if ( old->baseEnum ) {
    2780                         ty = new ast::EnumInstType{ // Probably here: missing the specification of the base
     2766                        ty = new ast::EnumInstType{
    27812767                                GET_ACCEPT_1( baseEnum, EnumDecl ),
    27822768                                cv( old ),
Note: See TracChangeset for help on using the changeset viewer.