Changeset 4520b77e for src/AST


Ignore:
Timestamp:
Sep 20, 2022, 8:37:05 PM (22 months ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
a065f1f
Parents:
d489da8 (diff), 12df6fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge to Master Sept 19

Location:
src/AST
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rd489da8 r4520b77e  
    310310                        node->name,
    311311                        get<Attribute>().acceptL( node->attributes ),
     312                        false, // Temporary
    312313                        LinkageSpec::Spec( node->linkage.val ),
    313314                        get<Type>().accept1(node->base)
     
    731732        }
    732733
     734        const ast::Expr * visit( const ast::QualifiedNameExpr * node ) override final {
     735                auto temp = new QualifiedNameExpr(
     736                                get<Declaration>().accept1(node->type_decl),
     737                                node->name
     738                );
     739                temp->var = get<DeclarationWithType>().accept1(node->var);
     740                auto expr = visitBaseExpr( node,
     741                        temp
     742                );
     743                this->node = expr;
     744                return nullptr;
     745        }
     746
    733747        const ast::Expr * visit( const ast::AddressExpr * node ) override final {
    734748                auto expr = visitBaseExpr( node,
     
    17401754                        old->location,
    17411755                        old->name,
     1756                        old->isTyped,
    17421757                        GET_ACCEPT_V(attributes, Attribute),
    17431758                        { old->linkage.val },
     
    22662281        }
    22672282
     2283        /// xxx - type_decl should be DeclWithType in the final design
     2284        /// type_decl is set to EnumDecl as a temporary fix
     2285        virtual void visit( const QualifiedNameExpr * old ) override final {
     2286                this->node = visitBaseExpr( old,
     2287                        new ast::QualifiedNameExpr (
     2288                                old->location,
     2289                                GET_ACCEPT_1(type_decl, Decl),
     2290                                GET_ACCEPT_1(var, DeclWithType),
     2291                                old->name
     2292                        )
     2293                );
     2294        }
     2295
    22682296        virtual void visit( const CastExpr * old ) override final {
    22692297                this->node = visitBaseExpr( old,
  • src/AST/Decl.hpp

    rd489da8 r4520b77e  
    312312class EnumDecl final : public AggregateDecl {
    313313public:
     314        bool isTyped;
    314315        ptr<Type> base;
    315316
    316         EnumDecl( const CodeLocation& loc, const std::string& name,
    317                 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, Type const * base = nullptr,
     317        EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false,
     318                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall,
     319                Type const * base = nullptr,
    318320                std::unordered_map< std::string, long long > enumValues = std::unordered_map< std::string, long long >() )
    319         : AggregateDecl( loc, name, std::move(attrs), linkage ), base(base), enumValues(enumValues) {}
     321        : AggregateDecl( loc, name, std::move(attrs), linkage ), isTyped(isTyped), base(base), enumValues(enumValues) {}
    320322
    321323        /// gets the integer value for this enumerator, returning true iff value found
     
    327329        const char * typeString() const override { return aggrString( Enum ); }
    328330
    329         bool isTyped() {return base && base.get();}
    330331
    331332private:
  • src/AST/Expr.hpp

    rd489da8 r4520b77e  
    254254};
    255255
     256class QualifiedNameExpr final : public Expr {
     257public:
     258        ptr<Decl> type_decl;
     259        ptr<DeclWithType> var;
     260        std::string name;
     261
     262        QualifiedNameExpr( const CodeLocation & loc, const Decl * d, const DeclWithType * r, const std::string & n )
     263        : Expr( loc ), type_decl( d ), var(r), name( n ) {}
     264
     265        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     266private:
     267        QualifiedNameExpr * clone() const override { return new QualifiedNameExpr{ *this }; }
     268        MUTATE_FRIEND
     269};
     270
    256271/// A reference to a named variable.
    257272class VariableExpr final : public Expr {
  • src/AST/Fwd.hpp

    rd489da8 r4520b77e  
    6767class UntypedExpr;
    6868class NameExpr;
     69class QualifiedNameExpr;
    6970class AddressExpr;
    7071class LabelAddressExpr;
  • src/AST/Pass.hpp

    rd489da8 r4520b77e  
    167167        const ast::Expr *             visit( const ast::UntypedExpr          * ) override final;
    168168        const ast::Expr *             visit( const ast::NameExpr             * ) override final;
     169        const ast::Expr *                         visit( const ast::QualifiedNameExpr    * ) override final;
    169170        const ast::Expr *             visit( const ast::AddressExpr          * ) override final;
    170171        const ast::Expr *             visit( const ast::LabelAddressExpr     * ) override final;
  • src/AST/Pass.impl.hpp

    rd489da8 r4520b77e  
    11991199
    12001200//--------------------------------------------------------------------------
     1201// QualifiedNameExpr
     1202template< typename core_t >
     1203const ast::Expr * ast::Pass< core_t >::visit( const ast::QualifiedNameExpr * node ) {
     1204        VISIT_START( node );
     1205        if ( __visit_children() ) {
     1206                guard_symtab guard { *this };
     1207                maybe_accept( node, &QualifiedNameExpr::var );
     1208                maybe_accept( node, &QualifiedNameExpr::type_decl );
     1209        }
     1210        VISIT_END( Expr, node );
     1211}
     1212
     1213//--------------------------------------------------------------------------
    12011214// CastExpr
    12021215template< typename core_t >
  • src/AST/Print.cpp

    rd489da8 r4520b77e  
    899899                postprint( node );
    900900
     901                return node;
     902        }
     903
     904        virtual const ast::Expr * visit( const ast::QualifiedNameExpr * node ) override final {
     905                os << "QualifiedNameExpr: " << std::endl;
     906                os << ++indent << "Type: ";
     907                safe_print( node->type_decl );
     908                os << std::endl;
     909                os <<  indent << "Name: " << node->name  << std::endl;
     910                --indent;
     911                postprint( node );
    901912                return node;
    902913        }
  • src/AST/Visitor.hpp

    rd489da8 r4520b77e  
    5959    virtual const ast::Expr *             visit( const ast::UntypedExpr          * ) = 0;
    6060    virtual const ast::Expr *             visit( const ast::NameExpr             * ) = 0;
     61    virtual const ast::Expr *             visit( const ast::QualifiedNameExpr    * ) = 0;
    6162    virtual const ast::Expr *             visit( const ast::AddressExpr          * ) = 0;
    6263    virtual const ast::Expr *             visit( const ast::LabelAddressExpr     * ) = 0;
Note: See TracChangeset for help on using the changeset viewer.