Changeset f441c88


Ignore:
Timestamp:
Nov 2, 2018, 4:14:33 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
5753b33, 8e04794
Parents:
c45b304
Message:

Implement basetypeof

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypeData.cc

    rc45b304 rf441c88  
    522522        switch ( td->kind ) {
    523523          case TypeData::Unknown:
    524                 // fill in implicit int
    525                 return new BasicType( buildQualifiers( td ), BasicType::SignedInt );
     524                        // fill in implicit int
     525                        return new BasicType( buildQualifiers( td ), BasicType::SignedInt );
    526526          case TypeData::Basic:
    527                 return buildBasicType( td );
     527                        return buildBasicType( td );
    528528          case TypeData::Pointer:
    529                 return buildPointer( td );
     529                        return buildPointer( td );
    530530          case TypeData::Array:
    531                 return buildArray( td );
     531                        return buildArray( td );
    532532          case TypeData::Reference:
    533                 return buildReference( td );
     533                        return buildReference( td );
    534534          case TypeData::Function:
    535                 return buildFunction( td );
     535                        return buildFunction( td );
    536536          case TypeData::AggregateInst:
    537                 return buildAggInst( td );
     537                        return buildAggInst( td );
    538538          case TypeData::EnumConstant:
    539                 // the name gets filled in later -- by SymTab::Validate
    540                 return new EnumInstType( buildQualifiers( td ), "" );
     539                        // the name gets filled in later -- by SymTab::Validate
     540                        return new EnumInstType( buildQualifiers( td ), "" );
    541541          case TypeData::SymbolicInst:
    542                 return buildSymbolicInst( td );
     542                        return buildSymbolicInst( td );
    543543          case TypeData::Tuple:
    544                 return buildTuple( td );
     544                        return buildTuple( td );
    545545          case TypeData::Typeof:
    546546          case TypeData::Basetypeof:
    547                 return buildTypeof( td );
     547                        return buildTypeof( td );
    548548          case TypeData::Builtin:
    549                 if(td->builtintype == DeclarationNode::Zero) {
    550                         return new ZeroType( noQualifiers );
    551                 }
    552                 else if(td->builtintype == DeclarationNode::One) {
    553                         return new OneType( noQualifiers );
    554                 }
    555                 else {
    556                         return new VarArgsType( buildQualifiers( td ) );
    557                 }
     549                        if (td->builtintype == DeclarationNode::Zero) {
     550                                return new ZeroType( noQualifiers );
     551                        }
     552                        else if (td->builtintype == DeclarationNode::One) {
     553                                return new OneType( noQualifiers );
     554                        }
     555                        else {
     556                                return new VarArgsType( buildQualifiers( td ) );
     557                        }
    558558          case TypeData::GlobalScope:
    559                 return new GlobalScopeType();
     559                        return new GlobalScopeType();
    560560                case TypeData::Qualified:
    561                 return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );
     561                        return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );
    562562          case TypeData::Symbolic:
    563563          case TypeData::Enum:
    564564          case TypeData::Aggregate:
    565                 assert( false );
     565                        assert( false );
    566566        } // switch
    567567
     
    942942        assert( td->typeexpr );
    943943        // assert( td->typeexpr->expr );
    944         return new TypeofType( td->kind == TypeData::Basetypeof ? Type::Qualifiers{} : buildQualifiers( td ), td->typeexpr->build() );
     944        return new TypeofType{
     945                buildQualifiers( td ), td->typeexpr->build(), td->kind == TypeData::Basetypeof };
    945946} // buildTypeof
    946947
  • src/ResolvExpr/ResolveTypeof.cc

    rc45b304 rf441c88  
    6767                std::cerr << std::endl;
    6868#endif
    69                 if ( typeofType->expr ) {
     69                // pass on null expression
     70                if ( ! typeofType->expr ) return typeofType;
     71
     72                bool isBasetypeof = typeofType->is_basetypeof;
     73                auto oldQuals = typeofType->get_qualifiers().val;
     74
     75                Type* newType;
     76                if ( TypeExpr* tyExpr = dynamic_cast<TypeExpr*>(typeofType->expr) ) {
     77                        // typeof wrapping type
     78                        newType = tyExpr->type;
     79                        tyExpr->type = nullptr;
     80                        delete tyExpr;
     81                } else {
     82                        // typeof wrapping expression
    7083                        Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer );
    7184                        assert( newExpr->result && ! newExpr->result->isVoid() );
    72                         Type * newType = newExpr->result;
     85                        newType = newExpr->result;
    7386                        newExpr->result = nullptr;
    7487                        delete typeofType;
    7588                        delete newExpr;
    76                         return newType;
    77                 } // if
    78                 return typeofType;
     89                }
     90
     91                // clear qualifiers for base, combine with typeoftype quals in any case
     92                if ( isBasetypeof ) {
     93                        newType->get_qualifiers().val
     94                                = ( newType->get_qualifiers().val & ~Type::Qualifiers::Mask ) | oldQuals;
     95                } else {
     96                        newType->get_qualifiers().val |= oldQuals;
     97                }
     98               
     99                return newType;
    79100        }
    80101} // namespace ResolvExpr
  • src/SynTree/Type.h

    rc45b304 rf441c88  
    598598class TypeofType : public Type {
    599599  public:
    600         Expression *expr;
    601 
    602         TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     600        Expression *expr;    ///< expression to take the type of
     601        bool is_basetypeof;  ///< true iff is basetypeof type
     602
     603        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
     604        TypeofType( const Type::Qualifiers & tq, Expression *expr, bool is_basetypeof,
     605                const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    603606        TypeofType( const TypeofType& );
    604607        virtual ~TypeofType();
  • src/SynTree/TypeofType.cc

    rc45b304 rf441c88  
    2323class Attribute;
    2424
    25 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, const std::list< Attribute * > & attributes ) : Type( tq, attributes ), expr( expr ) {
    26 }
     25TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr,
     26        const std::list< Attribute * > & attributes )
     27: Type( tq, attributes ), expr( expr ), is_basetypeof(false) {}
    2728
    28 TypeofType::TypeofType( const TypeofType &other ) : Type( other ), expr( maybeClone( other.expr ) ) {
    29 }
     29TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr, bool is_basetypeof,
     30        const std::list< Attribute * > & attributes )
     31: Type( tq, attributes ), expr( expr ), is_basetypeof( is_basetypeof ) {}
     32
     33TypeofType::TypeofType( const TypeofType &other )
     34: Type( other ), expr( maybeClone( other.expr ) ), is_basetypeof( other.is_basetypeof ) {}
    3035
    3136TypeofType::~TypeofType() {
     
    3540void TypeofType::print( std::ostream &os, Indenter indent ) const {
    3641        Type::print( os, indent );
     42        if ( is_basetypeof ) { os << "base-"; }
    3743        os << "type-of expression ";
    3844        if ( expr ) {
Note: See TracChangeset for help on using the changeset viewer.