Changeset 9c23f31 for src/SynTree


Ignore:
Timestamp:
Sep 24, 2016, 12:19:33 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
3b5e3aa
Parents:
2298f728 (diff), 7ae930a (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:

fix conflicts

Location:
src/SynTree
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r2298f728 r9c23f31  
    2828#include "TypeSubstitution.h"
    2929#include "Common/utility.h"
     30#include "InitTweak/InitTweak.h"
    3031
    3132
     
    493494
    494495void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
    495         os << std::string( indent, ' ' ) << "Implicit Copy Constructor Expression: " << std::endl;
     496        os << "Implicit Copy Constructor Expression: " << std::endl;
    496497        assert( callExpr );
    497498        callExpr->print( os, indent + 2 );
     
    503504}
    504505
     506
     507ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
     508        // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
     509        assert( callExpr );
     510        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
     511        assert( arg );
     512        cloneAll( arg->get_results(), results );
     513}
     514
     515ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
     516}
     517
     518ConstructorExpr::~ConstructorExpr() {
     519        delete callExpr;
     520}
     521
     522void ConstructorExpr::print( std::ostream &os, int indent ) const {
     523        os <<  "Constructor Expression: " << std::endl;
     524        assert( callExpr );
     525        os << std::string( indent+2, ' ' );
     526        callExpr->print( os, indent + 2 );
     527        Expression::print( os, indent );
     528}
     529
     530
     531CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
     532        add_result( type->clone() );
     533}
     534
     535CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
     536
     537CompoundLiteralExpr::~CompoundLiteralExpr() {
     538        delete initializer;
     539        delete type;
     540}
     541
     542void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
     543        os << "Compound Literal Expression: " << std::endl;
     544        if ( type ) type->print( os, indent + 2 );
     545        if ( initializer ) initializer->print( os, indent + 2 );
     546}
     547
    505548UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
    506549
     
    511554        if ( get_body() != 0 )
    512555                get_body()->print( os, indent + 2 );
    513 }
    514 
    515 
    516 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
    517         add_result( type->clone() );
    518 }
    519 
    520 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
    521 
    522 CompoundLiteralExpr::~CompoundLiteralExpr() {
    523         delete initializer;
    524         delete type;
    525 }
    526 
    527 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
    528         os << "Compound Literal Expression: " << std::endl;
    529         if ( type ) type->print( os, indent + 2 );
    530         if ( initializer ) initializer->print( os, indent + 2 );
    531556}
    532557
  • src/SynTree/Expression.h

    r2298f728 r9c23f31  
    595595};
    596596
     597/// ConstructorExpr represents the use of a constructor in an expression context, e.g. int * x = malloc() { 5 };
     598class ConstructorExpr : public Expression {
     599public:
     600        ConstructorExpr( Expression * callExpr );
     601        ConstructorExpr( const ConstructorExpr & other );
     602        ~ConstructorExpr();
     603
     604        Expression *get_callExpr() const { return callExpr; }
     605        void set_callExpr( Expression *newValue ) { callExpr = newValue; }
     606
     607        virtual ConstructorExpr *clone() const { return new ConstructorExpr( *this ); }
     608        virtual void accept( Visitor &v ) { v.visit( this ); }
     609        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     610        virtual void print( std::ostream &os, int indent = 0 ) const;
     611private:
     612        Expression * callExpr;
     613};
     614
     615/// CompoundLiteralExpr represents a C99 'compound literal'
     616class CompoundLiteralExpr : public Expression {
     617  public:
     618        CompoundLiteralExpr( Type * type, Initializer * initializer );
     619        CompoundLiteralExpr( const CompoundLiteralExpr &other );
     620        ~CompoundLiteralExpr();
     621
     622        Type * get_type() const { return type; }
     623        void set_type( Type * t ) { type = t; }
     624
     625        Initializer * get_initializer() const { return initializer; }
     626        void set_initializer( Initializer * i ) { initializer = i; }
     627
     628        virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }
     629        virtual void accept( Visitor &v ) { v.visit( this ); }
     630        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     631        virtual void print( std::ostream &os, int indent = 0 ) const;
     632  private:
     633        Type * type;
     634        Initializer * initializer;
     635};
     636
    597637/// ValofExpr represents a GCC 'lambda expression'
    598638class UntypedValofExpr : public Expression {
     
    613653};
    614654
    615 /// CompoundLiteralExpr represents a C99 'compound literal'
    616 class CompoundLiteralExpr : public Expression {
    617   public:
    618         CompoundLiteralExpr( Type * type, Initializer * initializer );
    619         CompoundLiteralExpr( const CompoundLiteralExpr &other );
    620         ~CompoundLiteralExpr();
    621 
    622         Type * get_type() const { return type; }
    623         void set_type( Type * t ) { type = t; }
    624 
    625         Initializer * get_initializer() const { return initializer; }
    626         void set_initializer( Initializer * i ) { initializer = i; }
    627 
    628         virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }
    629         virtual void accept( Visitor &v ) { v.visit( this ); }
    630         virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    631         virtual void print( std::ostream &os, int indent = 0 ) const;
    632   private:
    633         Type * type;
    634         Initializer * initializer;
    635 };
    636 
     655/// RangeExpr represents a range e.g. '3 ... 5' or '1~10'
    637656class RangeExpr : public Expression {
    638657  public:
  • src/SynTree/Mutator.cc

    r2298f728 r9c23f31  
    339339}
    340340
    341 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
    342         mutateAll( valofExpr->get_results(), *this );
    343         return valofExpr;
     341Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) {
     342        mutateAll( ctorExpr->get_results(), *this );
     343        ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) );
     344        return ctorExpr;
    344345}
    345346
     
    349350        compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );
    350351        return compLitExpr;
     352}
     353
     354Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
     355        mutateAll( valofExpr->get_results(), *this );
     356        return valofExpr;
    351357}
    352358
     
    447453}
    448454
     455Type *Mutator::mutate( ZeroType *zeroType ) {
     456        mutateAll( zeroType->get_forall(), *this );
     457        return zeroType;
     458}
     459
     460Type *Mutator::mutate( OneType *oneType ) {
     461        mutateAll( oneType->get_forall(), *this );
     462        return oneType;
     463}
     464
    449465Initializer *Mutator::mutate( SingleInit *singleInit ) {
    450466        singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
  • src/SynTree/Mutator.h

    r2298f728 r9c23f31  
    7676        virtual Expression* mutate( AsmExpr *asmExpr );
    7777        virtual Expression* mutate( ImplicitCopyCtorExpr *impCpCtorExpr );
     78        virtual Expression* mutate( ConstructorExpr *ctorExpr );
     79        virtual Expression* mutate( CompoundLiteralExpr *compLitExpr );
    7880        virtual Expression* mutate( UntypedValofExpr *valofExpr );
    79         virtual Expression* mutate( CompoundLiteralExpr *compLitExpr );
    8081        virtual Expression* mutate( RangeExpr *rangeExpr );
    8182
     
    9495        virtual Type* mutate( AttrType *attrType );
    9596        virtual Type* mutate( VarArgsType *varArgsType );
     97        virtual Type* mutate( ZeroType *zeroType );
     98        virtual Type* mutate( OneType *oneType );
    9699
    97100        virtual Initializer* mutate( SingleInit *singleInit );
  • src/SynTree/SynTree.h

    r2298f728 r9c23f31  
    8181class AsmExpr;
    8282class ImplicitCopyCtorExpr;
     83class ConstructorExpr;
     84class CompoundLiteralExpr;
    8385class UntypedValofExpr;
    84 class CompoundLiteralExpr;
    8586class RangeExpr;
    8687
     
    101102class AttrType;
    102103class VarArgsType;
     104class ZeroType;
     105class OneType;
    103106
    104107class Initializer;
  • src/SynTree/Type.h

    r2298f728 r9c23f31  
    418418};
    419419
     420/// Represents a zero constant
     421class ZeroType : public Type {
     422  public:
     423        ZeroType();
     424        ZeroType( Type::Qualifiers tq );
     425
     426        virtual ZeroType *clone() const { return new ZeroType( *this ); }
     427        virtual void accept( Visitor &v ) { v.visit( this ); }
     428        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     429        virtual void print( std::ostream &os, int indent = 0 ) const;
     430};
     431
     432/// Represents a one constant
     433class OneType : public Type {
     434  public:
     435        OneType();
     436        OneType( Type::Qualifiers tq );
     437
     438        virtual OneType *clone() const { return new OneType( *this ); }
     439        virtual void accept( Visitor &v ) { v.visit( this ); }
     440        virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     441        virtual void print( std::ostream &os, int indent = 0 ) const;
     442};
     443
    420444inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
    421445        isConst |= other.isConst;
  • src/SynTree/TypeSubstitution.cc

    r2298f728 r9c23f31  
    179179}
    180180
    181 Type * TypeSubstitution::mutate( VoidType *basicType ) {
    182         return handleType( basicType );
     181Type * TypeSubstitution::mutate( VoidType *voidType ) {
     182        return handleType( voidType );
    183183}
    184184
     
    221221Type * TypeSubstitution::mutate( VarArgsType *varArgsType ) {
    222222        return handleType( varArgsType );
     223}
     224
     225Type * TypeSubstitution::mutate( ZeroType *zeroType ) {
     226        return handleType( zeroType );
     227}
     228
     229Type * TypeSubstitution::mutate( OneType *oneType ) {
     230        return handleType( oneType );
    223231}
    224232
  • src/SynTree/TypeSubstitution.h

    r2298f728 r9c23f31  
    7676        virtual Type* mutate(TupleType *tupleType);
    7777        virtual Type* mutate(VarArgsType *varArgsType);
     78        virtual Type* mutate(ZeroType *zeroType);
     79        virtual Type* mutate(OneType *oneType);
    7880
    7981        // TODO: worry about traversing into a forall-qualified function type or type decl with assertions
  • src/SynTree/Visitor.cc

    r2298f728 r9c23f31  
    287287}
    288288
    289 void Visitor::visit( UntypedValofExpr *valofExpr ) {
    290         acceptAll( valofExpr->get_results(), *this );
    291         maybeAccept( valofExpr->get_body(), *this );
     289void Visitor::visit( ConstructorExpr * ctorExpr ) {
     290        acceptAll( ctorExpr->get_results(), *this );
     291        maybeAccept( ctorExpr->get_callExpr(), *this );
    292292}
    293293
     
    296296        maybeAccept( compLitExpr->get_type(), *this );
    297297        maybeAccept( compLitExpr->get_initializer(), *this );
     298}
     299
     300void Visitor::visit( UntypedValofExpr *valofExpr ) {
     301        acceptAll( valofExpr->get_results(), *this );
     302        maybeAccept( valofExpr->get_body(), *this );
    298303}
    299304
     
    378383}
    379384
     385void Visitor::visit( ZeroType *zeroType ) {
     386        acceptAll( zeroType->get_forall(), *this );
     387}
     388
     389void Visitor::visit( OneType *oneType ) {
     390        acceptAll( oneType->get_forall(), *this );
     391}
     392
    380393void Visitor::visit( SingleInit *singleInit ) {
    381394        singleInit->get_value()->accept( *this );
  • src/SynTree/Visitor.h

    r2298f728 r9c23f31  
    7676        virtual void visit( AsmExpr *asmExpr );
    7777        virtual void visit( ImplicitCopyCtorExpr *impCpCtorExpr );
     78        virtual void visit( ConstructorExpr * ctorExpr );
     79        virtual void visit( CompoundLiteralExpr *compLitExpr );
    7880        virtual void visit( UntypedValofExpr *valofExpr );
    79         virtual void visit( CompoundLiteralExpr *compLitExpr );
    8081        virtual void visit( RangeExpr *rangeExpr );
    8182
     
    9495        virtual void visit( AttrType *attrType );
    9596        virtual void visit( VarArgsType *varArgsType );
     97        virtual void visit( ZeroType *zeroType );
     98        virtual void visit( OneType *oneType );
    9699
    97100        virtual void visit( SingleInit *singleInit );
  • src/SynTree/module.mk

    r2298f728 r9c23f31  
    2626       SynTree/AttrType.cc \
    2727       SynTree/VarArgsType.cc \
     28       SynTree/ZeroOneType.cc \
    2829       SynTree/Constant.cc \
    2930       SynTree/Expression.cc \
Note: See TracChangeset for help on using the changeset viewer.