Changeset 63be3387 for src/AST


Ignore:
Timestamp:
Nov 14, 2022, 11:52:44 AM (3 years ago)
Author:
caparson <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
7d9598d8
Parents:
b77f0e1 (diff), 19a8c40 (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 branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rb77f0e1 r63be3387  
    234234                }
    235235                return declWithTypePostamble( decl, node );
     236        }
     237
     238        // InlineMemberDecl vanish after EnumAndPointerDecay pass so no necessary to implement NewToOld
     239        const ast::DeclWithType * visit( const ast::InlineMemberDecl * node ) override final { 
     240                assert( false );
     241                (void) node;
     242                return nullptr;
    236243        }
    237244
     
    16141621                        { old->get_funcSpec().val }
    16151622                );
    1616                 decl->enumInLine = old->enumInLine;
    16171623                cache.emplace(old, decl);
    16181624                assert(cache.find( old ) != cache.end());
     
    18591865                decl->uniqueId   = old->uniqueId;
    18601866                decl->storage    = { old->storageClasses.val };
     1867
     1868                this->node = decl;
     1869        }
     1870
     1871        virtual void visit( const InlineMemberDecl * old ) override final {
     1872                if ( inCache( old ) ) {
     1873                        return;
     1874                }
     1875                auto&& type = GET_ACCEPT_1(type, Type);
     1876                auto&& attr = GET_ACCEPT_V(attributes, Attribute);
     1877
     1878                auto decl = new ast::InlineMemberDecl(
     1879                        old->location,
     1880                        old->name,
     1881                        type,
     1882                        { old->get_storageClasses().val },
     1883                        { old->linkage.val },
     1884                        std::move(attr),
     1885                        { old->get_funcSpec().val }
     1886                );
     1887                cache.emplace(old, decl);
     1888                assert(cache.find( old ) != cache.end());
     1889                decl->scopeLevel = old->scopeLevel;
     1890                decl->mangleName = old->mangleName;
     1891                decl->isDeleted  = old->isDeleted;
     1892                decl->asmName    = GET_ACCEPT_1(asmName, Expr);
     1893                decl->uniqueId   = old->uniqueId;
     1894                decl->extension  = old->extension;
    18611895
    18621896                this->node = decl;
  • src/AST/Decl.hpp

    rb77f0e1 r63be3387  
    105105        ptr<Init> init;
    106106        ptr<Expr> bitfieldWidth;
    107         bool enumInLine = false; // enum inline is not a real object declaration.
    108         // It is a place holder for a set of enum value (ObjectDecl)
    109         bool importValue = false; // if the value copied from somewhere else
    110107
    111108        ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type,
     
    400397};
    401398
     399/// Static Assertion `_Static_assert( ... , ... );`
    402400class StaticAssertDecl : public Decl {
    403401public:
     
    411409private:
    412410        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
     411        MUTATE_FRIEND
     412};
     413
     414/// Inline Member Declaration `inline TypeName;`
     415class InlineMemberDecl final : public DeclWithType {
     416public:
     417        ptr<Type> type;
     418
     419        InlineMemberDecl( const CodeLocation & loc, const std::string & name, const Type * type,
     420                Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::Cforall,
     421                std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {} )
     422        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ) {}
     423
     424        const Type * get_type() const override { return type; }
     425        void set_type( const Type * ty ) override { type = ty; }
     426
     427        const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); }
     428private:
     429        InlineMemberDecl * clone() const override { return new InlineMemberDecl{ *this }; }
    413430        MUTATE_FRIEND
    414431};
  • src/AST/Fwd.hpp

    rb77f0e1 r63be3387  
    3737class DirectiveDecl;
    3838class StaticAssertDecl;
     39class InlineMemberDecl;
    3940
    4041class Stmt;
  • src/AST/Pass.hpp

    rb77f0e1 r63be3387  
    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::InlineMemberDecl     * ) 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

    rb77f0e1 r63be3387  
    617617                                maybe_accept( node, &FunctionDecl::returns );
    618618                                maybe_accept( node, &FunctionDecl::type );
     619                                maybe_accept( node, &FunctionDecl::attributes );
    619620                                // First remember that we are now within a function.
    620621                                ValueGuard< bool > oldInFunction( inFunction );
     
    625626                                atFunctionTop = true;
    626627                                maybe_accept( node, &FunctionDecl::stmts );
    627                                 maybe_accept( node, &FunctionDecl::attributes );
    628628                        }
    629629                }
     
    800800
    801801        VISIT_END( StaticAssertDecl, node );
     802}
     803
     804//--------------------------------------------------------------------------
     805// InlineMemberDecl
     806template< typename core_t >
     807const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::InlineMemberDecl * node ) {
     808        VISIT_START( node );
     809
     810        if ( __visit_children() ) {
     811                {
     812                        guard_symtab guard { *this };
     813                        maybe_accept( node, &InlineMemberDecl::type );
     814                }
     815        }
     816
     817        VISIT_END( DeclWithType, node );
    802818}
    803819
  • src/AST/Print.cpp

    rb77f0e1 r63be3387  
    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::InlineMemberDecl * node ) override final {
     404                os << "inline ";
     405                if ( ! node->name.empty() ) os << node->name;
     406
    400407                return node;
    401408        }
  • src/AST/Type.cpp

    rb77f0e1 r63be3387  
    147147// --- TypeInstType
    148148
     149bool TypeInstType::operator==( const TypeInstType & other ) const {
     150        return base == other.base
     151                && formal_usage == other.formal_usage
     152                && expr_id == other.expr_id;
     153}
     154
    149155TypeInstType::TypeInstType( const TypeDecl * b,
    150156        CV::Qualifiers q, std::vector<ptr<Attribute>> && as )
     
    157163
    158164bool TypeInstType::isComplete() const { return base->sized; }
     165
     166std::string TypeInstType::TypeEnvKey::typeString() const {
     167        return std::string("_") + std::to_string(formal_usage)
     168                + "_" + std::to_string(expr_id) + "_" + base->name;
     169}
     170
     171bool TypeInstType::TypeEnvKey::operator==(
     172                const TypeInstType::TypeEnvKey & other ) const {
     173        return base == other.base
     174                && formal_usage == other.formal_usage
     175                && expr_id == other.expr_id;
     176}
     177
     178bool TypeInstType::TypeEnvKey::operator<(
     179                const TypeInstType::TypeEnvKey & other ) const {
     180        // TypeEnvKey ordering is an arbitrary total ordering.
     181        // It doesn't mean anything but allows for a sorting.
     182        if ( base < other.base ) {
     183                return true;
     184        } else if ( other.base < base ) {
     185                return false;
     186        } else if ( formal_usage < other.formal_usage ) {
     187                return true;
     188        } else if ( other.formal_usage < formal_usage ) {
     189                return false;
     190        } else {
     191                return expr_id < other.expr_id;
     192        }
     193}
    159194
    160195// --- TupleType
  • src/AST/Type.hpp

    rb77f0e1 r63be3387  
    408408
    409409                TypeEnvKey() = default;
    410                 TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0): base(base), formal_usage(formal_usage), expr_id(expr_id) {}
    411                 TypeEnvKey(const TypeInstType & inst): base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {}
    412                 std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; }
    413                 bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
     410                TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0)
     411                : base(base), formal_usage(formal_usage), expr_id(expr_id) {}
     412                TypeEnvKey(const TypeInstType & inst)
     413                : base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {}
     414                std::string typeString() const;
     415                bool operator==(const TypeEnvKey & other) const;
     416                bool operator<(const TypeEnvKey & other) const;
    414417        };
    415418
    416         bool operator==(const TypeInstType & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
     419        bool operator==(const TypeInstType & other) const;
    417420
    418421        TypeInstType(
  • src/AST/Visitor.hpp

    rb77f0e1 r63be3387  
    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::InlineMemberDecl     * ) = 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.