Changeset da7fe39 for src/SynTree


Ignore:
Timestamp:
Apr 23, 2018, 12:57:46 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, stuck-waitfor-destruct, with_gc
Children:
57acae0
Parents:
ba89e9b7 (diff), c8ad5d9 (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 references

Location:
src/SynTree
Files:
1 added
1 deleted
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/SynTree/CompoundStmt.cc

    rba89e9b7 rda7fe39  
    2323#include "Statement.h"                // for CompoundStmt, Statement, DeclStmt
    2424#include "SynTree/Label.h"            // for Label
    25 #include "SynTree/VarExprReplacer.h"  // for VarExprReplacer, VarExprReplace...
     25#include "SynTree/DeclReplacer.h"     // for DeclReplacer
    2626
    2727using std::string;
     
    4949        // recursively execute this routine. There may be more efficient ways of doing
    5050        // this.
    51         VarExprReplacer::DeclMap declMap;
     51        DeclReplacer::DeclMap declMap;
    5252        std::list< Statement * >::const_iterator origit = other.kids.begin();
    5353        for ( Statement * s : kids ) {
     
    6464        }
    6565        if ( ! declMap.empty() ) {
    66                 VarExprReplacer::replace( this, declMap );
     66                DeclReplacer::replace( this, declMap );
    6767        }
    6868}
  • src/SynTree/DeclReplacer.h

    rba89e9b7 rda7fe39  
    2323class VariableExpr;
    2424
    25 namespace VarExprReplacer {
     25namespace DeclReplacer {
    2626        typedef std::map< DeclarationWithType *, DeclarationWithType * > DeclMap;
     27        typedef std::map< TypeDecl *, TypeDecl * > TypeMap;
    2728
    2829        void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
     30        void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
     31        void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
    2932}
    3033
  • src/SynTree/Expression.cc

    rba89e9b7 rda7fe39  
    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

    rba89e9b7 rda7fe39  
    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/FunctionDecl.cc

    rba89e9b7 rda7fe39  
    2626#include "Statement.h"           // for CompoundStmt
    2727#include "Type.h"                // for Type, FunctionType, Type::FuncSpecif...
    28 #include "VarExprReplacer.h"
     28#include "DeclReplacer.h"
    2929
    3030extern bool translation_unit_nomain;
     
    4141                : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
    4242
    43         VarExprReplacer::DeclMap declMap;
     43        DeclReplacer::DeclMap declMap;
    4444        for ( auto p : group_iterate( other.type->parameters, type->parameters ) ) {
    4545                declMap[ std::get<0>(p) ] = std::get<1>(p);
     
    4949        }
    5050        if ( ! declMap.empty() ) {
    51                 VarExprReplacer::replace( this, declMap );
     51                DeclReplacer::replace( this, declMap );
    5252        }
    5353        cloneAll( other.withExprs, withExprs );
  • src/SynTree/Mutator.h

    rba89e9b7 rda7fe39  
    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

    rba89e9b7 rda7fe39  
    6969class LabelAddressExpr;
    7070class CastExpr;
     71class KeywordCastExpr;
    7172class VirtualCastExpr;
    7273class MemberExpr;
  • src/SynTree/TypeSubstitution.cc

    rba89e9b7 rda7fe39  
    149149                return inst;
    150150        } else {
    151 ///         std::cerr << "found " << inst->get_name() << ", replacing with ";
    152 ///         i->second->print( std::cerr );
    153 ///         std::cerr << std::endl;
     151                // cut off infinite loop for the case where a type is bound to itself.
     152                // Note: this does not prevent cycles in the general case, so it may be necessary to do something more sophisticated here.
     153                // TODO: investigate preventing type variables from being bound to themselves in the first place.
     154                if ( TypeInstType * replacement = dynamic_cast< TypeInstType * >( i->second ) ) {
     155                        if ( inst->name == replacement->name ) {
     156                                return inst;
     157                        }
     158                }
     159                // std::cerr << "found " << inst->name << ", replacing with " << i->second << std::endl;
    154160                subCount++;
    155161                Type * newtype = i->second->clone();
    156162                newtype->get_qualifiers() |= inst->get_qualifiers();
    157163                delete inst;
    158                 return newtype;
     164                // Note: need to recursively apply substitution to the new type because normalize does not substitute bound vars, but bound vars must be substituted when not in freeOnly mode.
     165                return newtype->acceptMutator( *visitor );
    159166        } // if
    160167}
  • src/SynTree/TypeSubstitution.h

    rba89e9b7 rda7fe39  
    129129
    130130// definitition must happen after PassVisitor is included so that WithGuards can be used
    131 struct TypeSubstitution::Substituter : public WithGuards {
     131struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
    132132                Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    133133
  • src/SynTree/Visitor.h

    rba89e9b7 rda7fe39  
    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;
  • src/SynTree/module.mk

    rba89e9b7 rda7fe39  
    4848       SynTree/TypeSubstitution.cc \
    4949       SynTree/Attribute.cc \
    50        SynTree/VarExprReplacer.cc
     50       SynTree/DeclReplacer.cc
    5151
Note: See TracChangeset for help on using the changeset viewer.