Changeset add7117 for src/SynTree


Ignore:
Timestamp:
Sep 10, 2016, 11:08:47 AM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
5af62f1
Parents:
f5e81d1 (diff), 03e3117 (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' into tuples

Conflicts:

src/ResolvExpr/AlternativeFinder.cc
src/ResolvExpr/AlternativeFinder.h

Location:
src/SynTree
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    rf5e81d1 radd7117  
    2828#include "TypeSubstitution.h"
    2929#include "Common/utility.h"
     30#include "InitTweak/InitTweak.h"
    3031
    3132
     
    496497
    497498void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
    498         os << std::string( indent, ' ' ) << "Implicit Copy Constructor Expression: " << std::endl;
     499        os << "Implicit Copy Constructor Expression: " << std::endl;
    499500        assert( callExpr );
    500501        callExpr->print( os, indent + 2 );
     
    506507}
    507508
     509
     510ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
     511        // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
     512        assert( callExpr );
     513        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
     514        assert( arg );
     515        cloneAll( arg->get_results(), results );
     516}
     517
     518ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
     519}
     520
     521ConstructorExpr::~ConstructorExpr() {
     522        delete callExpr;
     523}
     524
     525void ConstructorExpr::print( std::ostream &os, int indent ) const {
     526        os <<  "Constructor Expression: " << std::endl;
     527        assert( callExpr );
     528        os << std::string( indent+2, ' ' );
     529        callExpr->print( os, indent + 2 );
     530        Expression::print( os, indent );
     531}
     532
     533
     534CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
     535        add_result( type->clone() );
     536}
     537
     538CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
     539
     540CompoundLiteralExpr::~CompoundLiteralExpr() {
     541        delete initializer;
     542        delete type;
     543}
     544
     545void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
     546        os << "Compound Literal Expression: " << std::endl;
     547        if ( type ) type->print( os, indent + 2 );
     548        if ( initializer ) initializer->print( os, indent + 2 );
     549}
     550
    508551UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
    509552
     
    514557        if ( get_body() != 0 )
    515558                get_body()->print( os, indent + 2 );
    516 }
    517 
    518 
    519 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
    520         add_result( type->clone() );
    521 }
    522 
    523 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
    524 
    525 CompoundLiteralExpr::~CompoundLiteralExpr() {
    526         delete initializer;
    527         delete type;
    528 }
    529 
    530 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
    531         os << "Compound Literal Expression: " << std::endl;
    532         if ( type ) type->print( os, indent + 2 );
    533         if ( initializer ) initializer->print( os, indent + 2 );
    534559}
    535560
  • src/SynTree/Expression.h

    rf5e81d1 radd7117  
    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        virtual ~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         virtual ~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

    rf5e81d1 radd7117  
    340340}
    341341
    342 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
    343         mutateAll( valofExpr->get_results(), *this );
    344         return valofExpr;
     342Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) {
     343        mutateAll( ctorExpr->get_results(), *this );
     344        ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) );
     345        return ctorExpr;
    345346}
    346347
     
    350351        compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );
    351352        return compLitExpr;
     353}
     354
     355Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
     356        mutateAll( valofExpr->get_results(), *this );
     357        return valofExpr;
    352358}
    353359
  • src/SynTree/Mutator.h

    rf5e81d1 radd7117  
    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        virtual Expression* mutate( TupleIndexExpr *tupleExpr );
  • src/SynTree/SynTree.h

    rf5e81d1 radd7117  
    8181class AsmExpr;
    8282class ImplicitCopyCtorExpr;
     83class ConstructorExpr;
     84class CompoundLiteralExpr;
    8385class UntypedValofExpr;
    84 class CompoundLiteralExpr;
    8586class RangeExpr;
    8687class TupleIndexExpr;
  • src/SynTree/Visitor.cc

    rf5e81d1 radd7117  
    288288}
    289289
    290 void Visitor::visit( UntypedValofExpr *valofExpr ) {
    291         acceptAll( valofExpr->get_results(), *this );
    292         maybeAccept( valofExpr->get_body(), *this );
     290void Visitor::visit( ConstructorExpr * ctorExpr ) {
     291        acceptAll( ctorExpr->get_results(), *this );
     292        maybeAccept( ctorExpr->get_callExpr(), *this );
    293293}
    294294
     
    297297        maybeAccept( compLitExpr->get_type(), *this );
    298298        maybeAccept( compLitExpr->get_initializer(), *this );
     299}
     300
     301void Visitor::visit( UntypedValofExpr *valofExpr ) {
     302        acceptAll( valofExpr->get_results(), *this );
     303        maybeAccept( valofExpr->get_body(), *this );
    299304}
    300305
  • src/SynTree/Visitor.h

    rf5e81d1 radd7117  
    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        virtual void visit( TupleIndexExpr *tupleExpr );
Note: See TracChangeset for help on using the changeset viewer.