Changeset c8c03683 for src/SynTree


Ignore:
Timestamp:
Jun 14, 2016, 12:53:26 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
7ff30d07
Parents:
e04ef3a (diff), d14d96a (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 plg2:software/cfa/cfa-cc

Location:
src/SynTree
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Declaration.h

    re04ef3a rc8c03683  
    115115        typedef DeclarationWithType Parent;
    116116  public:
    117         // temporary - merge this into general GCC attributes
    118         struct Attribute {
    119                 enum Type {
    120                         NoAttribute, Constructor, Destructor,
    121                 } type;
    122                 enum Priority {
    123                         // priorities 0-100 are reserved by gcc, so it's okay to use 100 an exceptional case
    124                         Default = 100, High,
    125                 } priority;
    126                 Attribute(Type t = NoAttribute, Priority p = Default) : type(t), priority(p) {};
    127         };
    128 
    129         FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = Attribute() );
     117        FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, const std::list< Attribute * > attributes = std::list< Attribute * >() );
    130118        FunctionDecl( const FunctionDecl &other );
    131119        virtual ~FunctionDecl();
     
    140128        std::list< std::string >& get_oldIdents() { return oldIdents; }
    141129        std::list< Declaration* >& get_oldDecls() { return oldDecls; }
    142         Attribute get_attribute() const { return attribute; }
    143         void set_attribute( Attribute newValue ) { attribute = newValue; }
     130        std::list< Attribute * >& get_attributes() { return attributes; }
    144131
    145132        virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
     
    153140        std::list< std::string > oldIdents;
    154141        std::list< Declaration* > oldDecls;
    155         Attribute attribute;
     142        std::list< Attribute * > attributes;
    156143};
    157144
  • src/SynTree/FunctionDecl.cc

    re04ef3a rc8c03683  
    1919#include "Statement.h"
    2020#include "Type.h"
     21#include "Attribute.h"
    2122#include "Common/utility.h"
    2223
    23 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute )
    24                 : Parent( name, sc, linkage ), type( type ), statements( statements ), attribute( attribute ) {
     24FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
     25                : Parent( name, sc, linkage ), type( type ), statements( statements ), attributes( attributes ) {
    2526        set_isInline( isInline );
    2627        set_isNoreturn( isNoreturn );
     
    3233
    3334FunctionDecl::FunctionDecl( const FunctionDecl &other )
    34         : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), attribute( other.attribute ) {
     35        : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
     36                cloneAll( other.attributes, attributes );
    3537}
    3638
     
    3840        delete type;
    3941        delete statements;
     42        deleteAll( attributes );
    4043}
    4144
     
    6568                os << "_Noreturn ";
    6669        } // if
    67         switch ( attribute.type ) {
    68                 case Attribute::Constructor:
    69                         os << "Global Constructor ";
    70                         break;
    71                 case Attribute::Destructor:
    72                         os << "Global Destructor ";
    73                         break;
    74                 default:
    75                         break;
    76         }
    77         if ( attribute.priority != Attribute::Default ) {
    78                 os << "with priority " << attribute.priority << " ";
    79         }
     70
     71        printAll( attributes, os, indent );
     72
    8073        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
    8174                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
     
    118111                os << "_Noreturn ";
    119112        } // if
    120         switch ( attribute.type ) {
    121                 case Attribute::Constructor:
    122                         os << " Global Constructor ";
    123                         break;
    124                 case Attribute::Destructor:
    125                         os << " Global Destructor ";
    126                         break;
    127                 default:
    128                         break;
    129         }
    130         if ( attribute.priority != Attribute::Default ) {
    131                 os << "with priority " << attribute.priority << " ";
    132         }
     113
     114        // xxx - should printShort print attributes?
     115
    133116        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
    134117                os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
  • src/SynTree/Initializer.cc

    re04ef3a rc8c03683  
    2020
    2121Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {}
     22Initializer::Initializer( const Initializer & other ) : maybeConstructed( other.maybeConstructed ) {
     23}
     24
    2225
    2326Initializer::~Initializer() {}
     
    3942}
    4043
    41 SingleInit::~SingleInit() {}
    42 
    43 SingleInit *SingleInit::clone() const { return new SingleInit( *this); }
     44SingleInit::~SingleInit() {
     45        deleteAll(designators);
     46}
    4447
    4548void SingleInit::print( std::ostream &os, int indent ) {
     
    5861
    5962ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
    60         : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) {
     63        : Initializer( maybeConstructed ), initializers( _initializers ), designators( _designators ) {
    6164}
    6265
    63 ListInit::~ListInit() {}
    64 
    65 ListInit *ListInit::clone() const {
    66         return new ListInit( *this );
     66ListInit::~ListInit() {
     67        deleteAll( initializers );
     68        deleteAll( designators );
    6769}
    6870
     
    8587
    8688ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {}
     89ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) {
     90}
     91
    8792ConstructorInit::~ConstructorInit() {
    8893        delete ctor;
     94        delete dtor;
    8995        delete init;
    90 }
    91 
    92 ConstructorInit *ConstructorInit::clone() const {
    93         return new ConstructorInit( *this );
    9496}
    9597
  • src/SynTree/Initializer.h

    re04ef3a rc8c03683  
    2020#include "Visitor.h"
    2121#include "Mutator.h"
     22#include "Type.h"
    2223
    2324#include <cassert>
     
    2829        //      Initializer( std::string _name = std::string(""), int _pos = 0 );
    2930        Initializer( bool maybeConstructed );
     31        Initializer( const Initializer & other );
    3032        virtual ~Initializer();
    3133
     
    6870        std::list<Expression *> &get_designators() { return designators; }
    6971
    70         virtual SingleInit *clone() const;
     72        virtual SingleInit *clone() const { return new SingleInit( *this); }
    7173        virtual void accept( Visitor &v ) { v.visit( this ); }
    7274        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     
    9496        std::list<Initializer*>::iterator end_initializers() { return initializers.end(); }
    9597
    96         virtual ListInit *clone() const;
     98        virtual ListInit *clone() const { return new ListInit( *this ); }
    9799        virtual void accept( Visitor &v ) { v.visit( this ); }
    98100        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     
    108110  public:
    109111        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
     112        ConstructorInit( const ConstructorInit &other );
    110113        virtual ~ConstructorInit();
    111114
     
    117120        Initializer * get_init() const { return init; }
    118121
    119         virtual ConstructorInit *clone() const;
     122        ConstructorInit *clone() const { return new ConstructorInit( *this ); }
    120123        virtual void accept( Visitor &v ) { v.visit( this ); }
    121124        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
  • src/SynTree/Mutator.cc

    re04ef3a rc8c03683  
    182182}
    183183
     184Statement *Mutator::mutate( ImplicitCtorDtorStmt *impCtorDtorStmt ) {
     185        impCtorDtorStmt->set_callStmt( maybeMutate( impCtorDtorStmt->get_callStmt(), *this ) );
     186        return impCtorDtorStmt;
     187}
     188
    184189Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) {
    185190        mutateAll( applicationExpr->get_results(), *this );
  • src/SynTree/Mutator.h

    re04ef3a rc8c03683  
    5252        virtual NullStmt* mutate( NullStmt *nullStmt );
    5353        virtual Statement* mutate( DeclStmt *declStmt );
     54        virtual Statement* mutate( ImplicitCtorDtorStmt *impCtorDtorStmt );
    5455
    5556        virtual Expression* mutate( ApplicationExpr *applicationExpr );
  • src/SynTree/Statement.cc

    re04ef3a rc8c03683  
    358358
    359359void CatchStmt::print( std::ostream &os, int indent ) const {
    360         os << string( indent, ' ' ) << "Catch Statement" << endl;
     360        os << "Catch Statement" << endl;
    361361
    362362        os << string( indent, ' ' ) << "... catching" << endl;
     
    383383
    384384void FinallyStmt::print( std::ostream &os, int indent ) const {
    385         os << string( indent, ' ' ) << "Finally Statement" << endl;
     385        os << "Finally Statement" << endl;
    386386        os << string( indent + 2, ' ' ) << "with block: " << endl;
    387387        block->print( os, indent + 4 );
     
    393393void NullStmt::print( std::ostream &os, int indent ) const {
    394394        os << "Null Statement" << endl ;
     395}
     396
     397ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) {
     398        assert( callStmt );
     399}
     400
     401ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( other.callStmt ) {
     402}
     403
     404ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {
     405}
     406
     407void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const {
     408        os << "Implicit Ctor Dtor Statement" << endl;
     409        os << string( indent + 2, ' ' ) << "with Ctor/Dtor: ";
     410        callStmt->print( os, indent + 2);
     411        os << endl;
    395412}
    396413
  • src/SynTree/Statement.h

    re04ef3a rc8c03683  
    2121#include "Mutator.h"
    2222#include "Common/SemanticError.h"
     23#include "Type.h"
    2324
    2425class Statement {
     
    394395        virtual ~DeclStmt();
    395396
    396         Declaration *get_decl() { return decl; }
     397        Declaration *get_decl() const { return decl; }
    397398        void set_decl( Declaration *newValue ) { decl = newValue; }
    398399
     
    404405        Declaration *decl;
    405406};
     407
     408
     409/// represents an implicit application of a constructor or destructor. Qualifiers are replaced
     410/// immediately before and after the call so that qualified objects can be constructed
     411/// with the same functions as unqualified objects.
     412class ImplicitCtorDtorStmt : public Statement {
     413  public:
     414        ImplicitCtorDtorStmt( Statement * callStmt );
     415        ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
     416        virtual ~ImplicitCtorDtorStmt();
     417
     418        Statement *get_callStmt() const { return callStmt; }
     419        void set_callStmt( Statement * newValue ) { callStmt = newValue; }
     420
     421        virtual ImplicitCtorDtorStmt *clone() const { return new ImplicitCtorDtorStmt( *this ); }
     422        virtual void accept( Visitor &v ) { v.visit( this ); }
     423        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     424        virtual void print( std::ostream &os, int indent = 0 ) const;
     425
     426  private:
     427        // Non-owned pointer to the constructor/destructor statement
     428        Statement * callStmt;
     429};
     430
    406431
    407432std::ostream & operator<<( std::ostream & out, Statement * statement );
  • src/SynTree/SynTree.h

    re04ef3a rc8c03683  
    5656class DeclStmt;
    5757class NullStmt;
     58class ImplicitCtorDtorStmt;
    5859
    5960class Expression;
     
    117118class TypeSubstitution;
    118119
     120// gcc attribute
     121class Attribute;
     122
    119123#endif // SYNTREE_H
    120124
  • src/SynTree/Type.cc

    re04ef3a rc8c03683  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Type.cc -- 
     7// Type.cc --
    88//
    99// Author           : Richard C. Bilson
     
    5454}
    5555
     56void Type::Qualifiers::print( std::ostream &os, int indent ) const {
     57        if ( isConst ) {
     58                os << "const ";
     59        } // if
     60        if ( isVolatile ) {
     61                os << "volatile ";
     62        } // if
     63        if ( isRestrict ) {
     64                os << "restrict ";
     65        } // if
     66        if ( isLvalue ) {
     67                os << "lvalue ";
     68        } // if
     69        if ( isAtomic ) {
     70                os << "_Atomic ";
     71        } // if
     72        if ( isAttribute ) {
     73                os << "__attribute(( )) ";
     74        } // if
     75}
     76
    5677void Type::print( std::ostream &os, int indent ) const {
    5778        if ( ! forall.empty() ) {
     
    6081                os << std::string( indent+2, ' ' );
    6182        } // if
    62         if ( tq.isConst ) {
    63                 os << "const ";
    64         } // if
    65         if ( tq.isVolatile ) {
    66                 os << "volatile ";
    67         } // if
    68         if ( tq.isRestrict ) {
    69                 os << "restrict ";
    70         } // if
    71         if ( tq.isLvalue ) {
    72                 os << "lvalue ";
    73         } // if
    74         if ( tq.isAtomic ) {
    75                 os << "_Atomic ";
    76         } // if
    77         if ( tq.isAttribute ) {
    78                 os << "__attribute(( )) ";
    79         } // if
     83        tq.print( os, indent );
    8084}
    8185
  • src/SynTree/Type.h

    re04ef3a rc8c03683  
    3636                bool operator<( const Qualifiers &other );
    3737                bool operator>( const Qualifiers &other );
     38                void print( std::ostream &os, int indent = 0 ) const;
    3839
    3940                bool isConst;
  • src/SynTree/Visitor.cc

    re04ef3a rc8c03683  
    152152}
    153153
     154void Visitor::visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) {
     155        maybeAccept( impCtorDtorStmt->get_callStmt(), *this );
     156}
     157
    154158void Visitor::visit( ApplicationExpr *applicationExpr ) {
    155159        acceptAll( applicationExpr->get_results(), *this );
  • src/SynTree/Visitor.h

    re04ef3a rc8c03683  
    5252        virtual void visit( NullStmt *nullStmt );
    5353        virtual void visit( DeclStmt *declStmt );
     54        virtual void visit( ImplicitCtorDtorStmt *impCtorDtorStmt );
    5455
    5556        virtual void visit( ApplicationExpr *applicationExpr );
  • src/SynTree/module.mk

    re04ef3a rc8c03683  
    66## file "LICENCE" distributed with Cforall.
    77##
    8 ## module.mk -- 
     8## module.mk --
    99##
    1010## Author           : Richard C. Bilson
     
    4646       SynTree/Visitor.cc \
    4747       SynTree/Mutator.cc \
    48        SynTree/TypeSubstitution.cc
     48       SynTree/TypeSubstitution.cc \
     49       SynTree/Attribute.cc
    4950
Note: See TracChangeset for help on using the changeset viewer.