Changeset c8c03683 for src/SynTree
- Timestamp:
- Jun 14, 2016, 12:53:26 PM (9 years ago)
- 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. - Location:
- src/SynTree
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Declaration.h
re04ef3a rc8c03683 115 115 typedef DeclarationWithType Parent; 116 116 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 * >() ); 130 118 FunctionDecl( const FunctionDecl &other ); 131 119 virtual ~FunctionDecl(); … … 140 128 std::list< std::string >& get_oldIdents() { return oldIdents; } 141 129 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; } 144 131 145 132 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); } … … 153 140 std::list< std::string > oldIdents; 154 141 std::list< Declaration* > oldDecls; 155 Attribute attribute;142 std::list< Attribute * > attributes; 156 143 }; 157 144 -
src/SynTree/FunctionDecl.cc
re04ef3a rc8c03683 19 19 #include "Statement.h" 20 20 #include "Type.h" 21 #include "Attribute.h" 21 22 #include "Common/utility.h" 22 23 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) {24 FunctionDecl::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 ) { 25 26 set_isInline( isInline ); 26 27 set_isNoreturn( isNoreturn ); … … 32 33 33 34 FunctionDecl::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 ); 35 37 } 36 38 … … 38 40 delete type; 39 41 delete statements; 42 deleteAll( attributes ); 40 43 } 41 44 … … 65 68 os << "_Noreturn "; 66 69 } // 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 80 73 if ( get_storageClass() != DeclarationNode::NoStorageClass ) { 81 74 os << DeclarationNode::storageName[ get_storageClass() ] << ' '; … … 118 111 os << "_Noreturn "; 119 112 } // 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 133 116 if ( get_storageClass() != DeclarationNode::NoStorageClass ) { 134 117 os << DeclarationNode::storageName[ get_storageClass() ] << ' '; -
src/SynTree/Initializer.cc
re04ef3a rc8c03683 20 20 21 21 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} 22 Initializer::Initializer( const Initializer & other ) : maybeConstructed( other.maybeConstructed ) { 23 } 24 22 25 23 26 Initializer::~Initializer() {} … … 39 42 } 40 43 41 SingleInit::~SingleInit() { }42 43 SingleInit *SingleInit::clone() const { return new SingleInit( *this);}44 SingleInit::~SingleInit() { 45 deleteAll(designators); 46 } 44 47 45 48 void SingleInit::print( std::ostream &os, int indent ) { … … 58 61 59 62 ListInit::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 ) { 61 64 } 62 65 63 ListInit::~ListInit() {} 64 65 ListInit *ListInit::clone() const { 66 return new ListInit( *this ); 66 ListInit::~ListInit() { 67 deleteAll( initializers ); 68 deleteAll( designators ); 67 69 } 68 70 … … 85 87 86 88 ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {} 89 ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) { 90 } 91 87 92 ConstructorInit::~ConstructorInit() { 88 93 delete ctor; 94 delete dtor; 89 95 delete init; 90 }91 92 ConstructorInit *ConstructorInit::clone() const {93 return new ConstructorInit( *this );94 96 } 95 97 -
src/SynTree/Initializer.h
re04ef3a rc8c03683 20 20 #include "Visitor.h" 21 21 #include "Mutator.h" 22 #include "Type.h" 22 23 23 24 #include <cassert> … … 28 29 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 29 30 Initializer( bool maybeConstructed ); 31 Initializer( const Initializer & other ); 30 32 virtual ~Initializer(); 31 33 … … 68 70 std::list<Expression *> &get_designators() { return designators; } 69 71 70 virtual SingleInit *clone() const ;72 virtual SingleInit *clone() const { return new SingleInit( *this); } 71 73 virtual void accept( Visitor &v ) { v.visit( this ); } 72 74 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } … … 94 96 std::list<Initializer*>::iterator end_initializers() { return initializers.end(); } 95 97 96 virtual ListInit *clone() const ;98 virtual ListInit *clone() const { return new ListInit( *this ); } 97 99 virtual void accept( Visitor &v ) { v.visit( this ); } 98 100 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } … … 108 110 public: 109 111 ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ); 112 ConstructorInit( const ConstructorInit &other ); 110 113 virtual ~ConstructorInit(); 111 114 … … 117 120 Initializer * get_init() const { return init; } 118 121 119 virtual ConstructorInit *clone() const;122 ConstructorInit *clone() const { return new ConstructorInit( *this ); } 120 123 virtual void accept( Visitor &v ) { v.visit( this ); } 121 124 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } -
src/SynTree/Mutator.cc
re04ef3a rc8c03683 182 182 } 183 183 184 Statement *Mutator::mutate( ImplicitCtorDtorStmt *impCtorDtorStmt ) { 185 impCtorDtorStmt->set_callStmt( maybeMutate( impCtorDtorStmt->get_callStmt(), *this ) ); 186 return impCtorDtorStmt; 187 } 188 184 189 Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) { 185 190 mutateAll( applicationExpr->get_results(), *this ); -
src/SynTree/Mutator.h
re04ef3a rc8c03683 52 52 virtual NullStmt* mutate( NullStmt *nullStmt ); 53 53 virtual Statement* mutate( DeclStmt *declStmt ); 54 virtual Statement* mutate( ImplicitCtorDtorStmt *impCtorDtorStmt ); 54 55 55 56 virtual Expression* mutate( ApplicationExpr *applicationExpr ); -
src/SynTree/Statement.cc
re04ef3a rc8c03683 358 358 359 359 void CatchStmt::print( std::ostream &os, int indent ) const { 360 os << string( indent, ' ' ) <<"Catch Statement" << endl;360 os << "Catch Statement" << endl; 361 361 362 362 os << string( indent, ' ' ) << "... catching" << endl; … … 383 383 384 384 void FinallyStmt::print( std::ostream &os, int indent ) const { 385 os << string( indent, ' ' ) <<"Finally Statement" << endl;385 os << "Finally Statement" << endl; 386 386 os << string( indent + 2, ' ' ) << "with block: " << endl; 387 387 block->print( os, indent + 4 ); … … 393 393 void NullStmt::print( std::ostream &os, int indent ) const { 394 394 os << "Null Statement" << endl ; 395 } 396 397 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) { 398 assert( callStmt ); 399 } 400 401 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( other.callStmt ) { 402 } 403 404 ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() { 405 } 406 407 void 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; 395 412 } 396 413 -
src/SynTree/Statement.h
re04ef3a rc8c03683 21 21 #include "Mutator.h" 22 22 #include "Common/SemanticError.h" 23 #include "Type.h" 23 24 24 25 class Statement { … … 394 395 virtual ~DeclStmt(); 395 396 396 Declaration *get_decl() { return decl; }397 Declaration *get_decl() const { return decl; } 397 398 void set_decl( Declaration *newValue ) { decl = newValue; } 398 399 … … 404 405 Declaration *decl; 405 406 }; 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. 412 class 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 406 431 407 432 std::ostream & operator<<( std::ostream & out, Statement * statement ); -
src/SynTree/SynTree.h
re04ef3a rc8c03683 56 56 class DeclStmt; 57 57 class NullStmt; 58 class ImplicitCtorDtorStmt; 58 59 59 60 class Expression; … … 117 118 class TypeSubstitution; 118 119 120 // gcc attribute 121 class Attribute; 122 119 123 #endif // SYNTREE_H 120 124 -
src/SynTree/Type.cc
re04ef3a rc8c03683 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Type.cc -- 7 // Type.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 54 54 } 55 55 56 void 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 56 77 void Type::print( std::ostream &os, int indent ) const { 57 78 if ( ! forall.empty() ) { … … 60 81 os << std::string( indent+2, ' ' ); 61 82 } // 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 ); 80 84 } 81 85 -
src/SynTree/Type.h
re04ef3a rc8c03683 36 36 bool operator<( const Qualifiers &other ); 37 37 bool operator>( const Qualifiers &other ); 38 void print( std::ostream &os, int indent = 0 ) const; 38 39 39 40 bool isConst; -
src/SynTree/Visitor.cc
re04ef3a rc8c03683 152 152 } 153 153 154 void Visitor::visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) { 155 maybeAccept( impCtorDtorStmt->get_callStmt(), *this ); 156 } 157 154 158 void Visitor::visit( ApplicationExpr *applicationExpr ) { 155 159 acceptAll( applicationExpr->get_results(), *this ); -
src/SynTree/Visitor.h
re04ef3a rc8c03683 52 52 virtual void visit( NullStmt *nullStmt ); 53 53 virtual void visit( DeclStmt *declStmt ); 54 virtual void visit( ImplicitCtorDtorStmt *impCtorDtorStmt ); 54 55 55 56 virtual void visit( ApplicationExpr *applicationExpr ); -
src/SynTree/module.mk
re04ef3a rc8c03683 6 6 ## file "LICENCE" distributed with Cforall. 7 7 ## 8 ## module.mk -- 8 ## module.mk -- 9 9 ## 10 10 ## Author : Richard C. Bilson … … 46 46 SynTree/Visitor.cc \ 47 47 SynTree/Mutator.cc \ 48 SynTree/TypeSubstitution.cc 48 SynTree/TypeSubstitution.cc \ 49 SynTree/Attribute.cc 49 50
Note:
See TracChangeset
for help on using the changeset viewer.