Changeset b6fe7e6 for src/SynTree


Ignore:
Timestamp:
Sep 9, 2016, 1:58:07 PM (8 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:
03e3117
Parents:
d1969a6
Message:

make constructor expressions work, fix bug with using the wrong TypeEnvironment? on member exprs, remove many unnecessary ctor/dtors from the prelude

Location:
src/SynTree
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    rd1969a6 rb6fe7e6  
    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

    rd1969a6 rb6fe7e6  
    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

    rd1969a6 rb6fe7e6  
    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
  • src/SynTree/Mutator.h

    rd1969a6 rb6fe7e6  
    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
  • src/SynTree/SynTree.h

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

    rd1969a6 rb6fe7e6  
    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
  • src/SynTree/Visitor.h

    rd1969a6 rb6fe7e6  
    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
Note: See TracChangeset for help on using the changeset viewer.