Changeset 71f4e4f for src/SynTree


Ignore:
Timestamp:
Jan 13, 2016, 5:19:47 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
f1e012b
Parents:
02c7d04
Message:

added ConstructorInit?, simple constructors and destructors work correctly

Location:
src/SynTree
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Declaration.h

    r02c7d04 r71f4e4f  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 14:48:44 2016
    13 // Update Count     : 34
     12// Last Modified On : Wed Jan 13 16:11:49 2016
     13// Update Count     : 36
    1414//
    1515
     
    9191        Expression *get_bitfieldWidth() const { return bitfieldWidth; }
    9292        void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
    93         ExprStmt * get_ctor() const { return ctor; }
    94         void set_ctor( ExprStmt * newValue ) { ctor = newValue; }
    9593
    9694        virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
     
    103101        Initializer *init;
    104102        Expression *bitfieldWidth;
    105         ExprStmt * ctor;
    106103};
    107104
  • src/SynTree/Initializer.cc

    r02c7d04 r71f4e4f  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 15:00:18 2016
    13 // Update Count     : 23
     12// Last Modified On : Wed Jan 13 15:31:45 2016
     13// Update Count     : 28
    1414//
    1515
     
    7979                (*i)->print( os, indent + 2 );
    8080}
     81
     82
     83ConstructorInit::ConstructorInit( Expression * ctor, Initializer * init ) : Initializer( true ), ctor( ctor ), init( init ) {}
     84ConstructorInit::~ConstructorInit() {
     85        delete ctor;
     86        delete init;
     87}
     88
     89ConstructorInit *ConstructorInit::clone() const {
     90        return new ConstructorInit( *this );
     91}
     92
     93void ConstructorInit::print( std::ostream &os, int indent ) {
     94        os << std::endl << std::string(indent, ' ') << "Constructor initializer: ";
     95        if ( ctor ) {
     96                os << " initially constructed with ";
     97                ctor->print( os, indent+2 );
     98        } // if
     99
     100        if ( init ) {
     101                os << " with fallback C-style initializer: ";
     102                init->print( os, indent+2 );
     103        }
     104}
     105
     106
    81107// Local Variables: //
    82108// tab-width: 4 //
  • src/SynTree/Initializer.h

    r02c7d04 r71f4e4f  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jan 07 13:33:20 2016
    13 // Update Count     : 5
     12// Last Modified On : Wed Jan 13 15:29:53 2016
     13// Update Count     : 17
    1414//
    1515
     
    103103};
    104104
     105// ConstructorInit represents an initializer that is either a constructor expression or
     106// a C-style initializer.
     107class ConstructorInit : public Initializer {
     108  public:
     109        ConstructorInit( Expression * ctor, Initializer * init );
     110        virtual ~ConstructorInit();
     111
     112        void set_ctor( Expression * newValue ) { ctor = newValue; }
     113        Expression * get_ctor() const { return ctor; }
     114        void set_init( Initializer * newValue ) { init = newValue; }
     115        Initializer * get_init() const { return init; }
     116
     117        virtual ConstructorInit *clone() const;
     118        virtual void accept( Visitor &v ) { v.visit( this ); }
     119        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     120        virtual void print( std::ostream &os, int indent = 0 );
     121
     122  private:
     123        Expression * ctor;
     124        // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback
     125        // if an appropriate constructor definition is not found by the resolver
     126        Initializer * init;
     127};
     128
    105129#endif // INITIALIZER_H
    106130
  • src/SynTree/Mutator.cc

    r02c7d04 r71f4e4f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Mutator.cc -- 
     7// Mutator.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 25 19:21:33 2015
    13 // Update Count     : 11
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jan 13 15:32:29 2016
     13// Update Count     : 15
    1414//
    1515
     
    419419}
    420420
     421Initializer *Mutator::mutate( ConstructorInit *ctorInit ) {
     422        ctorInit->set_ctor( maybeMutate( ctorInit->get_ctor(), *this ) );
     423        ctorInit->set_init( maybeMutate( ctorInit->get_init(), *this ) );
     424        return ctorInit;
     425}
     426
    421427Subrange *Mutator::mutate( Subrange *subrange ) {
    422428        return subrange;
  • src/SynTree/Mutator.h

    r02c7d04 r71f4e4f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Mutator.h -- 
     7// Mutator.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 22:26:16 2015
    13 // Update Count     : 8
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jan 13 15:24:26 2016
     13// Update Count     : 9
    1414//
    1515#include <cassert>
     
    6262        virtual Expression* mutate( MemberExpr *memberExpr );
    6363        virtual Expression* mutate( VariableExpr *variableExpr );
    64         virtual Expression* mutate( ConstantExpr *constantExpr ); 
     64        virtual Expression* mutate( ConstantExpr *constantExpr );
    6565        virtual Expression* mutate( SizeofExpr *sizeofExpr );
    6666        virtual Expression* mutate( AlignofExpr *alignofExpr );
     
    9191        virtual Initializer* mutate( SingleInit *singleInit );
    9292        virtual Initializer* mutate( ListInit *listInit );
     93        virtual Initializer* mutate( ConstructorInit *ctorInit );
    9394
    9495        virtual Subrange *mutate( Subrange *subrange );
  • src/SynTree/ObjectDecl.cc

    r02c7d04 r71f4e4f  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Jan 08 15:29:10 2016
    13 // Update Count     : 27
     12// Last Modified On : Wed Jan 13 16:11:19 2016
     13// Update Count     : 29
    1414//
    1515
     
    2525        set_isInline( isInline );
    2626        set_isNoreturn( isNoreturn );
    27         set_ctor( NULL );
    2827}
    2928
    3029ObjectDecl::ObjectDecl( const ObjectDecl &other )
    31         : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ), ctor( maybeClone( other.ctor ) ) {
     30        : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
    3231}
    3332
     
    3635        delete init;
    3736        delete bitfieldWidth;
    38         delete ctor;
    3937}
    4038
     
    6765                os << " with bitfield width ";
    6866                bitfieldWidth->print( os );
    69         } // if
    70 
    71         if ( ctor ) {
    72                 os << " initially constructed with ";
    73                 ctor->print( os, indent );
    7467        } // if
    7568}
  • src/SynTree/SynTree.h

    r02c7d04 r71f4e4f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // SynTree.h -- 
     7// SynTree.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 23 23:25:04 2015
    13 // Update Count     : 3
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jan 13 15:28:41 2016
     13// Update Count     : 4
    1414//
    1515
     
    9999class SingleInit;
    100100class ListInit;
     101class ConstructorInit;
    101102
    102103class Subrange;
  • src/SynTree/Visitor.cc

    r02c7d04 r71f4e4f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Visitor.cc -- 
     7// Visitor.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 24 16:11:05 2015
    13 // Update Count     : 15
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jan 13 15:27:23 2016
     13// Update Count     : 18
    1414//
    1515
     
    353353}
    354354
     355void Visitor::visit( ConstructorInit *ctorInit ) {
     356        maybeAccept( ctorInit->get_ctor(), *this );
     357        maybeAccept( ctorInit->get_init(), *this );
     358}
     359
    355360void Visitor::visit( Subrange *subrange ) {}
    356361
  • src/SynTree/Visitor.h

    r02c7d04 r71f4e4f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Visitor.h -- 
     7// Visitor.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 23 23:22:23 2015
    13 // Update Count     : 4
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jan 13 15:24:05 2016
     13// Update Count     : 5
    1414//
    1515
     
    6262        virtual void visit( MemberExpr *memberExpr );
    6363        virtual void visit( VariableExpr *variableExpr );
    64         virtual void visit( ConstantExpr *constantExpr ); 
     64        virtual void visit( ConstantExpr *constantExpr );
    6565        virtual void visit( SizeofExpr *sizeofExpr );
    6666        virtual void visit( AlignofExpr *alignofExpr );
     
    9191        virtual void visit( SingleInit *singleInit );
    9292        virtual void visit( ListInit *listInit );
     93        virtual void visit( ConstructorInit *ctorInit );
    9394
    9495        virtual void visit( Subrange *subrange );
Note: See TracChangeset for help on using the changeset viewer.