Changeset 4e08a54 for src/AST


Ignore:
Timestamp:
Apr 19, 2024, 12:01:34 PM (22 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master, stuck-waitfor-destruct
Children:
b9b6efb
Parents:
da87eaf (diff), 02c80cdc (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:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

    rda87eaf r4e08a54  
    169169}
    170170
     171const std::string EnumDecl::getUnmangeldArrayName( const ast::EnumAttribute attr ) const {
     172                switch( attr ) {
     173                        case ast::EnumAttribute::Value: return "values_" + name ;
     174                        case ast::EnumAttribute::Label: return "labels_" + name;
     175                        default: /* Posn does not generate array */
     176                                return "";
     177                }
     178        }
     179
    171180}
    172181
  • src/AST/Decl.hpp

    rda87eaf r4e08a54  
    303303};
    304304
     305enum class EnumAttribute{ Value, Posn, Label };
    305306/// enum declaration `enum Foo { ... };`
    306307class EnumDecl final : public AggregateDecl {
     
    326327        const char * typeString() const override { return aggrString( Enum ); }
    327328
    328 
     329        const std::string getUnmangeldArrayName( const EnumAttribute attr ) const;
    329330private:
    330331        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
  • src/AST/Expr.cpp

    rda87eaf r4e08a54  
    246246ConstantExpr * ConstantExpr::from_bool( const CodeLocation & loc, bool b ) {
    247247        return new ConstantExpr{
    248                 loc, new BasicType{ BasicType::Bool }, b ? "1" : "0", (unsigned long long)b };
     248                loc, new BasicType{ BasicKind::Bool }, b ? "1" : "0", (unsigned long long)b };
    249249}
    250250
    251251ConstantExpr * ConstantExpr::from_int( const CodeLocation & loc, int i ) {
    252252        return new ConstantExpr{
    253                 loc, new BasicType{ BasicType::SignedInt }, std::to_string( i ), (unsigned long long)i };
     253                loc, new BasicType{ BasicKind::SignedInt }, std::to_string( i ), (unsigned long long)i };
    254254}
    255255
    256256ConstantExpr * ConstantExpr::from_ulong( const CodeLocation & loc, unsigned long i ) {
    257257        return new ConstantExpr{
    258                 loc, new BasicType{ BasicType::LongUnsignedInt }, std::to_string( i ),
     258                loc, new BasicType{ BasicKind::LongUnsignedInt }, std::to_string( i ),
    259259                (unsigned long long)i };
    260260}
    261261
    262262ConstantExpr * ConstantExpr::from_string( const CodeLocation & loc, const std::string & str ) {
    263         const Type * charType = new BasicType( BasicType::Char );
     263        const Type * charType = new BasicType( BasicKind::Char );
    264264        // Adjust the length of the string for the terminator.
    265265        const Expr * strSize = from_ulong( loc, str.size() + 1 );
     
    277277
    278278SizeofExpr::SizeofExpr( const CodeLocation & loc, const Expr * e )
    279 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( e ), type( nullptr ) {}
     279: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( e ), type( nullptr ) {}
    280280
    281281SizeofExpr::SizeofExpr( const CodeLocation & loc, const Type * t )
    282 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
     282: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
    283283
    284284// --- AlignofExpr
    285285
    286286AlignofExpr::AlignofExpr( const CodeLocation & loc, const Expr * e )
    287 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( e ), type( nullptr ) {}
     287: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( e ), type( nullptr ) {}
    288288
    289289AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t )
    290 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
     290: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
    291291
    292292// --- OffsetofExpr
    293293
    294294OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem )
    295 : Expr( loc, new BasicType{ BasicType::LongUnsignedInt } ), type( ty ), member( mem ) {
     295: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( ty ), member( mem ) {
    296296        assert( type );
    297297        assert( member );
     
    302302OffsetPackExpr::OffsetPackExpr( const CodeLocation & loc, const StructInstType * ty )
    303303: Expr( loc, new ArrayType{
    304         new BasicType{ BasicType::LongUnsignedInt }, nullptr, FixedLen, DynamicDim }
     304        new BasicType{ BasicKind::LongUnsignedInt }, nullptr, FixedLen, DynamicDim }
    305305), type( ty ) {
    306306        assert( type );
     
    311311LogicalExpr::LogicalExpr(
    312312        const CodeLocation & loc, const Expr * a1, const Expr * a2, LogicalFlag ia )
    313 : Expr( loc, new BasicType{ BasicType::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
     313: Expr( loc, new BasicType{ BasicKind::SignedInt } ), arg1( a1 ), arg2( a2 ), isAnd( ia ) {}
    314314
    315315// --- CommaExpr
  • src/AST/Fwd.hpp

    rda87eaf r4e08a54  
    133133class OneType;
    134134class GlobalScopeType;
    135 class EnumPosType;
     135class EnumAttrType;
    136136
    137137class Designation;
  • src/AST/Pass.hpp

    rda87eaf r4e08a54  
    222222        const ast::Type *             visit( const ast::UnionInstType        * ) override final;
    223223        const ast::Type *             visit( const ast::EnumInstType         * ) override final;
    224         const ast::Type *             visit( const ast::EnumPosType          * ) override final;
     224        const ast::Type *             visit( const ast::EnumAttrType         * ) override final;
    225225        const ast::Type *             visit( const ast::TraitInstType        * ) override final;
    226226        const ast::Type *             visit( const ast::TypeInstType         * ) override final;
  • src/AST/Pass.impl.hpp

    rda87eaf r4e08a54  
    477477                                CodeLocation{}, "__func__",
    478478                                new ast::ArrayType{
    479                                         new ast::BasicType{ ast::BasicType::Char, ast::CV::Const },
     479                                        new ast::BasicType{ ast::BasicKind::Char, ast::CV::Const },
    480480                                        nullptr, VariableLen, DynamicDim
    481481                                },
     
    19401940
    19411941//--------------------------------------------------------------------------
    1942 // EnumPosType
    1943 template< typename core_t >
    1944 const ast::Type * ast::Pass< core_t >::visit( const ast::EnumPosType * node ) {
    1945         VISIT_START( node );
    1946 
     1942// EnumAttrType
     1943template< typename core_t >
     1944const ast::Type * ast::Pass< core_t >::visit( const ast::EnumAttrType * node ) {
     1945        VISIT_START( node );
    19471946        VISIT_END( Type, node );
    19481947}
  • src/AST/Print.cpp

    rda87eaf r4e08a54  
    15761576        }
    15771577
    1578         virtual const ast::Type * visit( const ast::EnumPosType * node ) override final {
    1579                 preprint( node );
    1580                 os << "enum pos with ";
     1578        virtual const ast::Type * visit( const ast::EnumAttrType * node ) override final {
     1579                preprint( node );
     1580                os << "enum attr ";
     1581        if ( node->attr == ast::EnumAttribute::Label ) {
     1582            os << "Label ";
     1583        } else if ( node->attr == ast::EnumAttribute::Value ) {
     1584            os << "Value ";
     1585        } else {
     1586            os << "Posn ";
     1587        }
    15811588                (*(node->instance)).accept( *this );
    15821589                return node;
  • src/AST/Type.hpp

    rda87eaf r4e08a54  
    2222#include <vector>
    2323
     24#include "BasicKind.hpp"     // for BasicKind
    2425#include "CVQualifiers.hpp"
    2526#include "Decl.hpp"          // for AggregateDecl subclasses
     
    114115class BasicType final : public Type {
    115116public:
    116         // GENERATED START, DO NOT EDIT
    117         // GENERATED BY BasicTypes-gen.cc
    118         enum Kind {
    119                 Bool,
    120                 Char,
    121                 SignedChar,
    122                 UnsignedChar,
    123                 ShortSignedInt,
    124                 ShortUnsignedInt,
    125                 SignedInt,
    126                 UnsignedInt,
    127                 LongSignedInt,
    128                 LongUnsignedInt,
    129                 LongLongSignedInt,
    130                 LongLongUnsignedInt,
    131                 SignedInt128,
    132                 UnsignedInt128,
    133                 uFloat16,
    134                 uFloat16Complex,
    135                 uFloat32,
    136                 uFloat32Complex,
    137                 Float,
    138                 FloatComplex,
    139                 uFloat32x,
    140                 uFloat32xComplex,
    141                 uFloat64,
    142                 uFloat64Complex,
    143                 Double,
    144                 DoubleComplex,
    145                 uFloat64x,
    146                 uFloat64xComplex,
    147                 uuFloat80,
    148                 uFloat128,
    149                 uFloat128Complex,
    150                 uuFloat128,
    151                 LongDouble,
    152                 LongDoubleComplex,
    153                 uFloat128x,
    154                 uFloat128xComplex,
    155                 NUMBER_OF_BASIC_TYPES
    156         } kind;
    157         // GENERATED END
    158 
    159         /// xxx -- MAX_INTEGER_TYPE should probably be in BasicTypes-gen.cc, rather than hardcoded here
    160         enum { MAX_INTEGER_TYPE = UnsignedInt128 };
     117        BasicKind kind;
    161118
    162119        /// string names of basic types; generated to match with Kind
    163120        static const char *typeNames[];
    164121
    165         BasicType( Kind k, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
     122        BasicType( BasicKind k, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    166123        : Type(q, std::move(as)), kind(k) {}
    167124
    168125        /// Check if this type represents an integer type
    169         bool isInteger() const { return (unsigned)kind <= (unsigned)MAX_INTEGER_TYPE; }
     126        bool isInteger() const { return kind <= MAX_INTEGER_TYPE; }
    170127
    171128        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
     
    362319using EnumInstType = SueInstType<EnumDecl>;
    363320
    364 class EnumPosType final : public Type {
     321class EnumAttrType final : public Type {
    365322public:
    366323        readonly<EnumInstType> instance;
    367         const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    368         EnumPosType( const EnumInstType * instance ): instance(instance) {}
     324    EnumAttribute attr;
     325        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
     326        EnumAttrType( const EnumInstType * instance, EnumAttribute attr = EnumAttribute::Posn )
     327                : instance(instance), attr(attr) {}
    369328       
    370 private:
    371         EnumPosType * clone() const override { return new EnumPosType{ *this }; }
     329    bool match( const ast::EnumAttrType * other) const {
     330        return instance->base->name == other->instance->base->name && attr == other->attr;
     331    }
     332private:
     333        EnumAttrType * clone() const override { return new EnumAttrType{ *this }; }
    372334        MUTATE_FRIEND
    373335};
     
    425387        TypeInstType( const TypeInstType & o ) = default;
    426388
    427         TypeInstType( const TypeEnvKey & key );
     389        explicit TypeInstType( const TypeEnvKey & key );
    428390
    429391        /// sets `base`, updating `kind` correctly
  • src/AST/Visitor.hpp

    rda87eaf r4e08a54  
    119119    virtual const ast::Type *             visit( const ast::OneType              * ) = 0;
    120120    virtual const ast::Type *             visit( const ast::GlobalScopeType      * ) = 0;
    121     virtual const ast::Type *             visit( const ast::EnumPosType          * ) = 0;
     121    virtual const ast::Type *             visit( const ast::EnumAttrType         * ) = 0;
    122122    virtual const ast::Designation *      visit( const ast::Designation          * ) = 0;
    123123    virtual const ast::Init *             visit( const ast::SingleInit           * ) = 0;
  • src/AST/module.mk

    rda87eaf r4e08a54  
    1818        AST/Attribute.cpp \
    1919        AST/Attribute.hpp \
     20        AST/BasicKind.hpp \
    2021        AST/Bitfield.hpp \
    2122        AST/Chain.hpp \
Note: See TracChangeset for help on using the changeset viewer.