Changeset e6d39fe for src/SynTree


Ignore:
Timestamp:
Apr 20, 2018, 9:04:41 AM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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, with_gc
Children:
22bdc34
Parents:
9181f1d (diff), 88f15ae (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/SynTree
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r9181f1d re6d39fe  
    271271}
    272272
    273 CastExpr::CastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
     273CastExpr::CastExpr( Expression *arg, Type *toType, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
    274274        set_result(toType);
    275275}
    276276
    277 CastExpr::CastExpr( Expression *arg_ ) : Expression(), arg(arg_) {
     277CastExpr::CastExpr( Expression *arg, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
    278278        set_result( new VoidType( Type::Qualifiers() ) );
    279279}
    280280
    281 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
     281CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {
    282282}
    283283
     
    296296                result->print( os, indent+1 );
    297297        } // if
     298        Expression::print( os, indent );
     299}
     300
     301KeywordCastExpr::KeywordCastExpr( Expression *arg, Target target ) : Expression(), arg(arg), target( target ) {
     302}
     303
     304KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) {
     305}
     306
     307KeywordCastExpr::~KeywordCastExpr() {
     308        delete arg;
     309}
     310
     311const std::string & KeywordCastExpr::targetString() const {
     312        static const std::string targetStrs[] = {
     313                "coroutine", "thread", "monitor"
     314        };
     315        static_assert(
     316                (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
     317                "Each KeywordCastExpr::Target should have a corresponding string representation"
     318        );
     319        return targetStrs[(unsigned long)target];
     320}
     321
     322void KeywordCastExpr::print( std::ostream &os, Indenter indent ) const {
     323        os << "Keyword Cast of:" << std::endl << indent+1;
     324        arg->print(os, indent+1);
     325        os << std::endl << indent << "... to: ";
     326        os << targetString();
    298327        Expression::print( os, indent );
    299328}
  • src/SynTree/Expression.h

    r9181f1d re6d39fe  
    188188  public:
    189189        Expression * arg;
    190 
    191         CastExpr( Expression * arg );
    192         CastExpr( Expression * arg, Type * toType );
     190        bool isGenerated = true; // whether this cast appeared in the source program
     191
     192        CastExpr( Expression * arg, bool isGenerated = true );
     193        CastExpr( Expression * arg, Type * toType, bool isGenerated = true );
     194        CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor
    193195        CastExpr( const CastExpr & other );
    194196        virtual ~CastExpr();
     
    198200
    199201        virtual CastExpr * clone() const { return new CastExpr( * this ); }
     202        virtual void accept( Visitor & v ) { v.visit( this ); }
     203        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     204        virtual void print( std::ostream & os, Indenter indent = {} ) const;
     205};
     206
     207/// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t
     208class KeywordCastExpr : public Expression {
     209public:
     210        Expression * arg;
     211        enum Target {
     212                Coroutine, Thread, Monitor, NUMBER_OF_TARGETS
     213        } target;
     214
     215        KeywordCastExpr( Expression * arg, Target target );
     216        KeywordCastExpr( const KeywordCastExpr & other );
     217        virtual ~KeywordCastExpr();
     218
     219        const std::string & targetString() const;
     220
     221        virtual KeywordCastExpr * clone() const { return new KeywordCastExpr( * this ); }
    200222        virtual void accept( Visitor & v ) { v.visit( this ); }
    201223        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
  • src/SynTree/Mutator.h

    r9181f1d re6d39fe  
    5959        virtual Expression * mutate( UntypedExpr * untypedExpr ) = 0;
    6060        virtual Expression * mutate( NameExpr * nameExpr ) = 0;
    61         virtual Expression * mutate( AddressExpr * castExpr ) = 0;
     61        virtual Expression * mutate( AddressExpr * addrExpr ) = 0;
    6262        virtual Expression * mutate( LabelAddressExpr * labAddressExpr ) = 0;
    6363        virtual Expression * mutate( CastExpr * castExpr ) = 0;
     64        virtual Expression * mutate( KeywordCastExpr * castExpr ) = 0;
    6465        virtual Expression * mutate( VirtualCastExpr * castExpr ) = 0;
    6566        virtual Expression * mutate( UntypedMemberExpr * memberExpr ) = 0;
  • src/SynTree/SynTree.h

    r9181f1d re6d39fe  
    6969class LabelAddressExpr;
    7070class CastExpr;
     71class KeywordCastExpr;
    7172class VirtualCastExpr;
    7273class MemberExpr;
  • src/SynTree/Visitor.h

    r9181f1d re6d39fe  
    6262        virtual void visit( NameExpr * nameExpr ) = 0;
    6363        virtual void visit( CastExpr * castExpr ) = 0;
     64        virtual void visit( KeywordCastExpr * castExpr ) = 0;
    6465        virtual void visit( VirtualCastExpr * castExpr ) = 0;
    6566        virtual void visit( AddressExpr * addressExpr ) = 0;
Note: See TracChangeset for help on using the changeset viewer.