Changeset 4ec9513 for src/AST


Ignore:
Timestamp:
Apr 13, 2022, 2:55:51 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
365c8dcb
Parents:
6b06abe
Message:

Converted validate C, including adding DimensionExpr? to the new ast.

Location:
src/AST
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/AST/Convert.cpp

    r6b06abe r4ec9513  
    951951        }
    952952
     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
    953959        const ast::Expr * visit( const ast::AsmExpr * node ) override final {
    954960                auto expr = visitBaseExpr( node,
     
    24632469
    24642470        virtual void visit( const DimensionExpr * old ) override final {
    2465                 // DimensionExpr gets desugared away in Validate.
    2466                 // As long as new-AST passes don't use it, this cheap-cheerful error
    2467                 // detection helps ensure that these occurrences have been compiled
    2468                 // away, as expected.  To move the DimensionExpr boundary downstream
    2469                 // or move the new-AST translation boundary upstream, implement
    2470                 // DimensionExpr in the new AST and implement a conversion.
    2471                 (void) old;
    2472                 assert(false && "DimensionExpr should not be present at new-AST boundary");
     2471                this->node = visitBaseExpr( old,
     2472                        new ast::DimensionExpr( old->location, old->name )
     2473                );
    24732474        }
    24742475
  • TabularUnified src/AST/Expr.hpp

    r6b06abe r4ec9513  
    604604};
    605605
     606class DimensionExpr final : public Expr {
     607public:
     608        std::string name;
     609
     610        DimensionExpr( const CodeLocation & loc, std::string name )
     611        : Expr( loc ), name( name ) {}
     612
     613        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     614private:
     615        DimensionExpr * clone() const override { return new DimensionExpr{ *this }; }
     616        MUTATE_FRIEND
     617};
     618
    606619/// A GCC "asm constraint operand" used in an asm statement, e.g. `[output] "=f" (result)`.
    607620/// https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
  • TabularUnified src/AST/Fwd.hpp

    r6b06abe r4ec9513  
    8484class CommaExpr;
    8585class TypeExpr;
     86class DimensionExpr;
    8687class AsmExpr;
    8788class ImplicitCopyCtorExpr;
  • TabularUnified src/AST/Pass.hpp

    r6b06abe r4ec9513  
    184184        const ast::Expr *             visit( const ast::CommaExpr            * ) override final;
    185185        const ast::Expr *             visit( const ast::TypeExpr             * ) override final;
     186        const ast::Expr *             visit( const ast::DimensionExpr        * ) override final;
    186187        const ast::Expr *             visit( const ast::AsmExpr              * ) override final;
    187188        const ast::Expr *             visit( const ast::ImplicitCopyCtorExpr * ) override final;
  • TabularUnified src/AST/Pass.impl.hpp

    r6b06abe r4ec9513  
    575575                        __pass::symtab::addId( core, 0, func );
    576576                        if ( __visit_children() ) {
    577                                 // parameter declarations
     577                                maybe_accept( node, &FunctionDecl::type_params );
     578                                maybe_accept( node, &FunctionDecl::assertions );
    578579                                maybe_accept( node, &FunctionDecl::params );
    579580                                maybe_accept( node, &FunctionDecl::returns );
    580                                 // type params and assertions
    581                                 maybe_accept( node, &FunctionDecl::type_params );
    582                                 maybe_accept( node, &FunctionDecl::assertions );
     581                                maybe_accept( node, &FunctionDecl::type );
    583582                                // First remember that we are now within a function.
    584583                                ValueGuard< bool > oldInFunction( inFunction );
     
    15221521
    15231522//--------------------------------------------------------------------------
     1523// DimensionExpr
     1524template< typename core_t >
     1525const ast::Expr * ast::Pass< core_t >::visit( const ast::DimensionExpr * node ) {
     1526        VISIT_START( node );
     1527
     1528        if ( __visit_children() ) {
     1529                guard_symtab guard { *this };
     1530                maybe_accept( node, &DimensionExpr::result );
     1531        }
     1532
     1533        VISIT_END( Expr, node );
     1534}
     1535
     1536//--------------------------------------------------------------------------
    15241537// AsmExpr
    15251538template< typename core_t >
     
    18591872
    18601873        if ( __visit_children() ) {
    1861                 // xxx - should PointerType visit/mutate dimension?
     1874                maybe_accept( node, &PointerType::dimension );
    18621875                maybe_accept( node, &PointerType::base );
    18631876        }
  • TabularUnified src/AST/Pass.proto.hpp

    r6b06abe r4ec9513  
    2626
    2727struct PureVisitor;
     28
     29template<typename node_t>
     30node_t * deepCopy( const node_t * localRoot );
    2831
    2932namespace __pass {
     
    396399                static inline auto addStructFwd( core_t & core, int, const ast::StructDecl * decl ) -> decltype( core.symtab.addStruct( decl ), void() ) {
    397400                        ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );
    398                         fwd->params = decl->params;
     401                        for ( const auto & param : decl->params ) {
     402                                fwd->params.push_back( deepCopy( param.get() ) );
     403                        }
    399404                        core.symtab.addStruct( fwd );
    400405                }
     
    405410                template<typename core_t>
    406411                static inline auto addUnionFwd( core_t & core, int, const ast::UnionDecl * decl ) -> decltype( core.symtab.addUnion( decl ), void() ) {
    407                         UnionDecl * fwd = new UnionDecl( decl->location, decl->name );
    408                         fwd->params = decl->params;
     412                        ast::UnionDecl * fwd = new ast::UnionDecl( decl->location, decl->name );
     413                        for ( const auto & param : decl->params ) {
     414                                fwd->params.push_back( deepCopy( param.get() ) );
     415                        }
    409416                        core.symtab.addUnion( fwd );
    410417                }
  • TabularUnified src/AST/Print.cpp

    r6b06abe r4ec9513  
    11011101        }
    11021102
     1103        virtual const ast::Expr * visit( const ast::DimensionExpr * node ) override final {
     1104                os << "Type-Sys Value: " << node->name;
     1105                postprint( node );
     1106
     1107                return node;
     1108        }
     1109
    11031110        virtual const ast::Expr * visit( const ast::AsmExpr * node ) override final {
    11041111                os << "Asm Expression:" << endl;
  • TabularUnified src/AST/Visitor.hpp

    r6b06abe r4ec9513  
    7676    virtual const ast::Expr *             visit( const ast::CommaExpr            * ) = 0;
    7777    virtual const ast::Expr *             visit( const ast::TypeExpr             * ) = 0;
     78    virtual const ast::Expr *             visit( const ast::DimensionExpr        * ) = 0;
    7879    virtual const ast::Expr *             visit( const ast::AsmExpr              * ) = 0;
    7980    virtual const ast::Expr *             visit( const ast::ImplicitCopyCtorExpr * ) = 0;
Note: See TracChangeset for help on using the changeset viewer.