Changeset 1cdfa82 for src/SynTree


Ignore:
Timestamp:
Apr 25, 2018, 4:55:53 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
42107b4
Parents:
2efe4b8 (diff), 9d5fb67 (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 remote-tracking branch 'origin/master' into with_gc

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

Legend:

Unmodified
Added
Removed
  • src/SynTree/CompoundStmt.cc

    r2efe4b8 r1cdfa82  
    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

    r2efe4b8 r1cdfa82  
    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/Declaration.cc

    r2efe4b8 r1cdfa82  
    7474
    7575
     76StaticAssertDecl::StaticAssertDecl( Expression * condition, ConstantExpr * message ) : Declaration( "", Type::StorageClasses(), LinkageSpec::C ), condition( condition ), message( message )  {
     77}
     78
     79StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) )  {
     80}
     81
     82StaticAssertDecl::~StaticAssertDecl() {
     83        delete condition;
     84        delete message;
     85}
     86
     87void StaticAssertDecl::print( std::ostream &os, Indenter indent ) const {
     88        os << "Static Assert with condition: ";
     89        condition->print( os, indent+1 );
     90        os << std::endl << indent << "and message: ";
     91        message->print( os, indent+1 );
     92os << std::endl;
     93}
     94
     95void StaticAssertDecl::printShort( std::ostream &os, Indenter indent ) const {
     96        print( os, indent );
     97}
     98
    7699// Local Variables: //
    77100// tab-width: 4 //
  • src/SynTree/Declaration.h

    r2efe4b8 r1cdfa82  
    357357};
    358358
     359class StaticAssertDecl : public Declaration {
     360public:
     361        Expression * condition;
     362        ConstantExpr * message;   // string literal
     363
     364        StaticAssertDecl( Expression * condition, ConstantExpr * message );
     365        StaticAssertDecl( const StaticAssertDecl & other );
     366        virtual ~StaticAssertDecl();
     367
     368        virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
     369        virtual void accept( Visitor &v ) override { v.visit( this ); }
     370        virtual StaticAssertDecl * acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     371        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
     372        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     373};
     374
    359375std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data );
    360376
  • src/SynTree/Expression.cc

    r2efe4b8 r1cdfa82  
    238238}
    239239
    240 CastExpr::CastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
     240CastExpr::CastExpr( Expression *arg, Type *toType, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
    241241        set_result(toType);
    242242}
    243243
    244 CastExpr::CastExpr( Expression *arg_ ) : Expression(), arg(arg_) {
     244CastExpr::CastExpr( Expression *arg, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
    245245        set_result( new VoidType( Type::Qualifiers() ) );
    246246}
    247247
    248 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
     248CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {
    249249}
    250250
     
    259259                result->print( os, indent+1 );
    260260        } // if
     261        Expression::print( os, indent );
     262}
     263
     264KeywordCastExpr::KeywordCastExpr( Expression *arg, Target target ) : Expression(), arg(arg), target( target ) {
     265}
     266
     267KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) {
     268}
     269
     270KeywordCastExpr::~KeywordCastExpr() {
     271        delete arg;
     272}
     273
     274const std::string & KeywordCastExpr::targetString() const {
     275        static const std::string targetStrs[] = {
     276                "coroutine", "thread", "monitor"
     277        };
     278        static_assert(
     279                (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
     280                "Each KeywordCastExpr::Target should have a corresponding string representation"
     281        );
     282        return targetStrs[(unsigned long)target];
     283}
     284
     285void KeywordCastExpr::print( std::ostream &os, Indenter indent ) const {
     286        os << "Keyword Cast of:" << std::endl << indent+1;
     287        arg->print(os, indent+1);
     288        os << std::endl << indent << "... to: ";
     289        os << targetString();
    261290        Expression::print( os, indent );
    262291}
  • src/SynTree/Expression.h

    r2efe4b8 r1cdfa82  
    184184  public:
    185185        Expression * arg;
    186 
    187         CastExpr( Expression * arg );
    188         CastExpr( Expression * arg, Type * toType );
     186        bool isGenerated = true; // whether this cast appeared in the source program
     187
     188        CastExpr( Expression * arg, bool isGenerated = true );
     189        CastExpr( Expression * arg, Type * toType, bool isGenerated = true );
     190        CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor
    189191        CastExpr( const CastExpr & other );
    190192
     
    193195
    194196        virtual CastExpr * clone() const { return new CastExpr( * this ); }
     197        virtual void accept( Visitor & v ) { v.visit( this ); }
     198        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     199        virtual void print( std::ostream & os, Indenter indent = {} ) const;
     200};
     201
     202/// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t
     203class KeywordCastExpr : public Expression {
     204public:
     205        Expression * arg;
     206        enum Target {
     207                Coroutine, Thread, Monitor, NUMBER_OF_TARGETS
     208        } target;
     209
     210        KeywordCastExpr( Expression * arg, Target target );
     211        KeywordCastExpr( const KeywordCastExpr & other );
     212        virtual ~KeywordCastExpr();
     213
     214        const std::string & targetString() const;
     215
     216        virtual KeywordCastExpr * clone() const { return new KeywordCastExpr( * this ); }
    195217        virtual void accept( Visitor & v ) { v.visit( this ); }
    196218        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
  • src/SynTree/FunctionDecl.cc

    r2efe4b8 r1cdfa82  
    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

    r2efe4b8 r1cdfa82  
    3434        virtual Declaration * mutate( TypedefDecl * typeDecl ) = 0;
    3535        virtual AsmDecl * mutate( AsmDecl * asmDecl ) = 0;
     36        virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) = 0;
    3637
    3738        virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) = 0;
     
    5859        virtual Expression * mutate( UntypedExpr * untypedExpr ) = 0;
    5960        virtual Expression * mutate( NameExpr * nameExpr ) = 0;
    60         virtual Expression * mutate( AddressExpr * castExpr ) = 0;
     61        virtual Expression * mutate( AddressExpr * addrExpr ) = 0;
    6162        virtual Expression * mutate( LabelAddressExpr * labAddressExpr ) = 0;
    6263        virtual Expression * mutate( CastExpr * castExpr ) = 0;
     64        virtual Expression * mutate( KeywordCastExpr * castExpr ) = 0;
    6365        virtual Expression * mutate( VirtualCastExpr * castExpr ) = 0;
    6466        virtual Expression * mutate( UntypedMemberExpr * memberExpr ) = 0;
  • src/SynTree/Statement.cc

    r2efe4b8 r1cdfa82  
    3434Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {}
    3535
    36 void Statement::print( std::ostream & os, Indenter ) const {
     36void Statement::print( std::ostream & os, Indenter indent ) const {
    3737        if ( ! labels.empty() ) {
    38                 os << "Labels: {";
     38                os << indent << "... Labels: {";
    3939                for ( const Label & l : labels ) {
    4040                        os << l << ",";
     
    188188
    189189void CaseStmt::print( std::ostream &os, Indenter indent ) const {
    190         if ( isDefault() ) os << "Default ";
     190        if ( isDefault() ) os << indent << "Default ";
    191191        else {
    192                 os << "Case ";
     192                os << indent << "Case ";
    193193                condition->print( os, indent );
    194194        } // if
     
    196196
    197197        for ( Statement * stmt : stmts ) {
     198                os << indent+1;
    198199                stmt->print( os, indent+1 );
    199200        }
     
    391392}
    392393
    393 void NullStmt::print( std::ostream &os, Indenter ) const {
     394void NullStmt::print( std::ostream &os, Indenter indent ) const {
    394395        os << "Null Statement" << endl;
     396        Statement::print( os, indent );
    395397}
    396398
  • src/SynTree/Statement.h

    r2efe4b8 r1cdfa82  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 20:46:46 2017
    13 // Update Count     : 77
     12// Last Modified On : Thu Mar  8 14:53:02 2018
     13// Update Count     : 78
    1414//
    1515
     
    246246class BranchStmt : public Statement {
    247247  public:
    248         enum Type { Goto = 0, Break, Continue };
     248        enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault };
    249249
    250250        // originalTarget kept for error messages.
  • src/SynTree/SynTree.h

    r2efe4b8 r1cdfa82  
    3838class TypedefDecl;
    3939class AsmDecl;
     40class StaticAssertDecl;
    4041
    4142class Statement;
     
    6869class LabelAddressExpr;
    6970class CastExpr;
     71class KeywordCastExpr;
    7072class VirtualCastExpr;
    7173class MemberExpr;
  • src/SynTree/TypeSubstitution.cc

    r2efe4b8 r1cdfa82  
    132132                return inst;
    133133        } else {
    134 ///         std::cerr << "found " << inst->get_name() << ", replacing with ";
    135 ///         i->second->print( std::cerr );
    136 ///         std::cerr << std::endl;
     134                // cut off infinite loop for the case where a type is bound to itself.
     135                // Note: this does not prevent cycles in the general case, so it may be necessary to do something more sophisticated here.
     136                // TODO: investigate preventing type variables from being bound to themselves in the first place.
     137                if ( TypeInstType * replacement = dynamic_cast< TypeInstType * >( i->second ) ) {
     138                        if ( inst->name == replacement->name ) {
     139                                return inst;
     140                        }
     141                }
     142                // std::cerr << "found " << inst->name << ", replacing with " << i->second << std::endl;
    137143                subCount++;
    138144                Type * newtype = i->second->clone();
    139145                newtype->get_qualifiers() |= inst->get_qualifiers();
    140                 return newtype;
     146                // 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.
     147                return newtype->acceptMutator( *visitor );
    141148        } // if
    142149}
  • src/SynTree/TypeSubstitution.h

    r2efe4b8 r1cdfa82  
    125125
    126126// definitition must happen after PassVisitor is included so that WithGuards can be used
    127 struct TypeSubstitution::Substituter : public WithGuards {
     127struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
    128128                Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    129129
  • src/SynTree/Visitor.h

    r2efe4b8 r1cdfa82  
    3636        virtual void visit( TypedefDecl * typeDecl ) = 0;
    3737        virtual void visit( AsmDecl * asmDecl ) = 0;
     38        virtual void visit( StaticAssertDecl * assertDecl ) = 0;
    3839
    3940        virtual void visit( CompoundStmt * compoundStmt ) = 0;
     
    6162        virtual void visit( NameExpr * nameExpr ) = 0;
    6263        virtual void visit( CastExpr * castExpr ) = 0;
     64        virtual void visit( KeywordCastExpr * castExpr ) = 0;
    6365        virtual void visit( VirtualCastExpr * castExpr ) = 0;
    6466        virtual void visit( AddressExpr * addressExpr ) = 0;
  • src/SynTree/module.mk

    r2efe4b8 r1cdfa82  
    4949       SynTree/Attribute.cc \
    5050       SynTree/BaseSyntaxNode.cc \
    51        SynTree/VarExprReplacer.cc
     51       SynTree/DeclReplacer.cc
    5252
Note: See TracChangeset for help on using the changeset viewer.