Changeset e874605 for src/AST


Ignore:
Timestamp:
Oct 28, 2022, 3:11:57 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master
Children:
93d2219
Parents:
77de429
Message:

Add class InlineValueDecl?, which is a Declaration class that works as a placeholder for aggregration value inherited from other aggregration. Disable inline value overwrite.

Location:
src/AST
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r77de429 re874605  
    234234                }
    235235                return declWithTypePostamble( decl, node );
     236        }
     237
     238        // InlineValueDecl vanish after EnumAndPointerDecay pass so no necessary to implement NewToOld
     239        const ast::DeclWithType * visit( const ast::InlineValueDecl * node ) override final {   
     240                assert( false );
     241                (void) node;
     242                return nullptr;
    236243        }
    237244
     
    18631870        }
    18641871
     1872        virtual void visit( const InlineValueDecl * old ) override final {
     1873                if ( inCache( old ) ) {
     1874                        return;
     1875                }
     1876                auto&& type = GET_ACCEPT_1(type, Type);
     1877                auto&& attr = GET_ACCEPT_V(attributes, Attribute);
     1878 
     1879                auto decl = new ast::InlineValueDecl(
     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
    18651900        virtual void visit( const CompoundStmt * old ) override final {
    18661901                if ( inCache( old ) ) return;
  • src/AST/Decl.hpp

    r77de429 re874605  
    414414};
    415415
     416class InlineValueDecl final : public DeclWithType {
     417public:
     418        ptr<Type> type;
     419
     420        InlineValueDecl( const CodeLocation & loc, const std::string & name, const Type * type,
     421                Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::Cforall,
     422                std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {} )
     423        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ) {}
     424
     425        const Type * get_type() const override { return type; }
     426        void set_type( const Type * ty ) override { type = ty; }
     427
     428        const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); }
     429private:
     430        InlineValueDecl * clone() const override { return new InlineValueDecl{ *this }; }
     431        MUTATE_FRIEND
     432};
    416433}
    417434
  • src/AST/Fwd.hpp

    r77de429 re874605  
    3737class DirectiveDecl;
    3838class StaticAssertDecl;
     39class InlineValueDecl;
    3940
    4041class Stmt;
  • src/AST/Pass.hpp

    r77de429 re874605  
    141141        const ast::DirectiveDecl *    visit( const ast::DirectiveDecl        * ) override final;
    142142        const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl     * ) override final;
     143        const ast::DeclWithType *     visit( const ast::InlineValueDecl      * ) override final;
    143144        const ast::CompoundStmt *     visit( const ast::CompoundStmt         * ) override final;
    144145        const ast::Stmt *             visit( const ast::ExprStmt             * ) override final;
  • src/AST/Pass.impl.hpp

    r77de429 re874605  
    803803
    804804//--------------------------------------------------------------------------
     805// DeclWithType
     806template< typename core_t >
     807const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::InlineValueDecl * node ) {
     808        VISIT_START( node );
     809
     810        if ( __visit_children() ) {
     811                {
     812                        guard_symtab guard { *this };
     813                        maybe_accept( node, &InlineValueDecl::type );
     814                }
     815        }
     816
     817        VISIT_END( DeclWithType, node );
     818}
     819
     820//--------------------------------------------------------------------------
    805821// CompoundStmt
    806822template< typename core_t >
  • src/AST/Print.cpp

    r77de429 re874605  
    398398        virtual const ast::Decl * visit( const ast::StructDecl * node ) override final {
    399399                print(node);
     400                return node;
     401        }
     402
     403        virtual const ast::DeclWithType * visit( const ast::InlineValueDecl * node ) override final {
     404                os << "inline ";
     405                if ( ! node->name.empty() ) os << node->name;
     406
    400407                return node;
    401408        }
  • src/AST/Visitor.hpp

    r77de429 re874605  
    3333    virtual const ast::DirectiveDecl *    visit( const ast::DirectiveDecl        * ) = 0;
    3434    virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl     * ) = 0;
     35    virtual const ast::DeclWithType *     visit( const ast::InlineValueDecl      * ) = 0;
    3536    virtual const ast::CompoundStmt *     visit( const ast::CompoundStmt         * ) = 0;
    3637    virtual const ast::Stmt *             visit( const ast::ExprStmt             * ) = 0;
Note: See TracChangeset for help on using the changeset viewer.