Changeset 0dd3a2f
- Timestamp:
- May 18, 2015, 11:20:23 AM (10 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, string, with_gc
- Children:
- 51587aa
- Parents:
- a32b204
- Location:
- translator
- Files:
-
- 60 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SymTab/AddVisit.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: AddVisit.h,v 1.2 2005/08/29 20:14:17 rcbilson Exp $ 5 * 6 */ 7 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // AddVisit.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 16:14:32 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 16:16:38 2015 13 // Update Count : 3 14 // 8 15 9 16 namespace SymTab { 17 void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i ); 10 18 11 void addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i ); 19 template< typename Visitor > 20 inline void addVisitStatementList( std::list< Statement* > &statements, Visitor &visitor ) { 21 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 22 addDecls( visitor.get_declsToAdd(), statements, i ); 23 (*i)->accept( visitor ); 24 } // for 25 addDecls( visitor.get_declsToAdd(), statements, statements.end() ); 26 } 12 27 13 template< typename Visitor > 14 inline void 15 addVisitStatementList( std::list< Statement* > &statements, Visitor &visitor ) 16 { 17 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 18 addDecls( visitor.get_declsToAdd(), statements, i ); 19 (*i)->accept( visitor ); 20 } 21 addDecls( visitor.get_declsToAdd(), statements, statements.end() ); 22 } 23 24 template< typename Visitor > 25 inline void 26 addVisitStatement( Statement *stmt, Visitor &visitor ) 27 { 28 maybeAccept( stmt, visitor ); 28 template< typename Visitor > 29 inline void addVisitStatement( Statement *stmt, Visitor &visitor ) { 30 maybeAccept( stmt, visitor ); 29 31 /// if ( ! declsToAdd.empty() ) { 30 32 /// CompoundStmt *compound = new CompoundStmt( noLabels ); … … 32 34 /// addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() ); 33 35 /// } 34 }36 } 35 37 36 template< typename Visitor > 37 inline void 38 addVisit(CompoundStmt *compoundStmt, Visitor &visitor) 39 { 40 addVisitStatementList( compoundStmt->get_kids(), visitor ); 41 } 38 template< typename Visitor > 39 inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) { 40 addVisitStatementList( compoundStmt->get_kids(), visitor ); 41 } 42 42 43 template< typename Visitor > 44 inline void 45 addVisit(IfStmt *ifStmt, Visitor &visitor) 46 { 47 addVisitStatement( ifStmt->get_thenPart(), visitor ); 48 addVisitStatement( ifStmt->get_elsePart(), visitor ); 49 maybeAccept( ifStmt->get_condition(), visitor ); 50 } 43 template< typename Visitor > 44 inline void addVisit(IfStmt *ifStmt, Visitor &visitor) { 45 addVisitStatement( ifStmt->get_thenPart(), visitor ); 46 addVisitStatement( ifStmt->get_elsePart(), visitor ); 47 maybeAccept( ifStmt->get_condition(), visitor ); 48 } 51 49 52 template< typename Visitor > 53 inline void 54 addVisit(WhileStmt *whileStmt, Visitor &visitor) 55 { 56 addVisitStatement( whileStmt->get_body(), visitor ); 57 maybeAccept( whileStmt->get_condition(), visitor ); 58 } 50 template< typename Visitor > 51 inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) { 52 addVisitStatement( whileStmt->get_body(), visitor ); 53 maybeAccept( whileStmt->get_condition(), visitor ); 54 } 59 55 60 template< typename Visitor > 61 inline void 62 addVisit(ForStmt *forStmt, Visitor &visitor) 63 { 64 addVisitStatement( forStmt->get_body(), visitor ); 65 maybeAccept( forStmt->get_initialization(), visitor ); 66 maybeAccept( forStmt->get_condition(), visitor ); 67 maybeAccept( forStmt->get_increment(), visitor ); 68 } 56 template< typename Visitor > 57 inline void addVisit(ForStmt *forStmt, Visitor &visitor) { 58 addVisitStatement( forStmt->get_body(), visitor ); 59 maybeAccept( forStmt->get_initialization(), visitor ); 60 maybeAccept( forStmt->get_condition(), visitor ); 61 maybeAccept( forStmt->get_increment(), visitor ); 62 } 69 63 70 template< typename Visitor > 71 inline void 72 addVisit(SwitchStmt *switchStmt, Visitor &visitor) 73 { 74 addVisitStatementList( switchStmt->get_branches(), visitor ); 75 maybeAccept( switchStmt->get_condition(), visitor ); 76 } 64 template< typename Visitor > 65 inline void addVisit(SwitchStmt *switchStmt, Visitor &visitor) { 66 addVisitStatementList( switchStmt->get_branches(), visitor ); 67 maybeAccept( switchStmt->get_condition(), visitor ); 68 } 77 69 78 template< typename Visitor > 79 inline void 80 addVisit(ChooseStmt *switchStmt, Visitor &visitor) 81 { 82 addVisitStatementList( switchStmt->get_branches(), visitor ); 83 maybeAccept( switchStmt->get_condition(), visitor ); 84 } 70 template< typename Visitor > 71 inline void addVisit(ChooseStmt *switchStmt, Visitor &visitor) { 72 addVisitStatementList( switchStmt->get_branches(), visitor ); 73 maybeAccept( switchStmt->get_condition(), visitor ); 74 } 85 75 86 template< typename Visitor > 87 inline void 88 addVisit(CaseStmt *caseStmt, Visitor &visitor) 89 { 90 addVisitStatementList( caseStmt->get_statements(), visitor ); 91 maybeAccept( caseStmt->get_condition(), visitor ); 92 } 76 template< typename Visitor > 77 inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) { 78 addVisitStatementList( caseStmt->get_statements(), visitor ); 79 maybeAccept( caseStmt->get_condition(), visitor ); 80 } 93 81 94 template< typename Visitor > 95 inline void 96 addVisit(CatchStmt *cathStmt, Visitor &visitor) 97 { 98 addVisitStatement( cathStmt->get_body(), visitor ); 99 maybeAccept( cathStmt->get_decl(), visitor ); 100 } 82 template< typename Visitor > 83 inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) { 84 addVisitStatement( cathStmt->get_body(), visitor ); 85 maybeAccept( cathStmt->get_decl(), visitor ); 86 } 87 } // namespace SymTab 101 88 102 } // namespace SymTab 89 // Local Variables: // 90 // tab-width: 4 // 91 // mode: c++ // 92 // compile-command: "make install" // 93 // End: // -
translator/SymTab/AggregateTable.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: AggregateTable.h,v 1.4 2005/08/29 20:14:17 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // AggregateTable.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 16:17:26 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 16:19:29 2015 13 // Update Count : 4 14 // 7 15 8 #ifndef SYMTAB_AGGREGATETABLE_H9 #define SYMTAB_AGGREGATETABLE_H16 #ifndef AGGREGATETABLE_H 17 #define AGGREGATETABLE_H 10 18 11 19 #include <map> … … 18 26 19 27 namespace SymTab { 28 template< class AggregateDeclClass > 29 class AggregateTableConflictFunction : public std::binary_function< AggregateDeclClass *, AggregateDeclClass *, AggregateDeclClass *> { 30 public: 31 AggregateDeclClass *operator()( AggregateDeclClass *existing, AggregateDeclClass *added ) { 32 if ( existing->get_members().empty() ) { 33 return added; 34 } else if ( ! added->get_members().empty() ) { 35 throw SemanticError( "redeclaration of ", added ); 36 } // if 37 return existing; 38 } 39 }; 20 40 21 template< class AggregateDeclClass > 22 class AggregateTableConflictFunction : public std::binary_function< AggregateDeclClass*, AggregateDeclClass*, AggregateDeclClass* > 23 { 24 public: 25 AggregateDeclClass *operator()( AggregateDeclClass *existing, AggregateDeclClass *added ) 26 { 27 if ( existing->get_members().empty() ) { 28 return added; 29 } else if ( ! added->get_members().empty() ) { 30 throw SemanticError( "redeclaration of ", added ); 31 } 32 return existing; 33 } 34 35 }; 36 37 typedef StackTable< StructDecl, AggregateTableConflictFunction< StructDecl > > StructTable; 38 typedef StackTable< EnumDecl, AggregateTableConflictFunction< EnumDecl > > EnumTable; 39 typedef StackTable< UnionDecl, AggregateTableConflictFunction< UnionDecl > > UnionTable; 40 typedef StackTable< ContextDecl, AggregateTableConflictFunction< ContextDecl > > ContextTable; 41 41 typedef StackTable< StructDecl, AggregateTableConflictFunction< StructDecl > > StructTable; 42 typedef StackTable< EnumDecl, AggregateTableConflictFunction< EnumDecl > > EnumTable; 43 typedef StackTable< UnionDecl, AggregateTableConflictFunction< UnionDecl > > UnionTable; 44 typedef StackTable< ContextDecl, AggregateTableConflictFunction< ContextDecl > > ContextTable; 42 45 } // namespace SymTab 43 46 44 #endif /* #ifndef SYMTAB_AGGREGATETABLE_H */ 47 #endif // AGGREGATETABLE_H 48 49 // Local Variables: // 50 // tab-width: 4 // 51 // mode: c++ // 52 // compile-command: "make install" // 53 // End: // -
translator/SymTab/FixFunction.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // FixFunction.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 16:19:49 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 16:22:54 2015 13 // Update Count : 2 14 // 15 1 16 #include "FixFunction.h" 2 17 #include "SynTree/Declaration.h" … … 6 21 7 22 namespace SymTab { 23 FixFunction::FixFunction() : isVoid( false ) { 24 } 8 25 9 FixFunction::FixFunction() 10 : isVoid( false ) 11 { 12 } 26 DeclarationWithType * FixFunction::mutate(FunctionDecl *functionDecl) { 27 ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 ); 28 delete functionDecl; 29 return pointer; 30 } 13 31 14 DeclarationWithType* 15 FixFunction::mutate(FunctionDecl *functionDecl) 16 { 17 ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 ); 18 delete functionDecl; 19 return pointer; 20 } 32 Type * FixFunction::mutate(VoidType *voidType) { 33 isVoid = true; 34 return voidType; 35 } 21 36 22 Type* 23 FixFunction::mutate(VoidType *voidType) 24 { 25 isVoid = true; 26 return voidType; 27 } 37 Type * FixFunction::mutate(BasicType *basicType) { 38 return basicType; 39 } 28 40 29 Type* 30 FixFunction::mutate(BasicType *basicType) 31 { 32 return basicType; 33 } 41 Type * FixFunction::mutate(PointerType *pointerType) { 42 return pointerType; 43 } 34 44 35 Type* 36 FixFunction::mutate(PointerType *pointerType) 37 { 38 39 }45 Type * FixFunction::mutate(ArrayType *arrayType) { 46 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), maybeClone( arrayType->get_base()->clone() ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() ); 47 delete arrayType; 48 return pointerType; 49 } 40 50 41 Type* 42 FixFunction::mutate(ArrayType *arrayType) 43 { 44 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), maybeClone( arrayType->get_base()->clone() ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() ); 45 delete arrayType; 46 return pointerType; 47 } 51 Type * FixFunction::mutate(StructInstType *aggregateUseType) { 52 return aggregateUseType; 53 } 48 54 49 Type* 50 FixFunction::mutate(StructInstType *aggregateUseType) 51 { 52 return aggregateUseType; 53 } 55 Type * FixFunction::mutate(UnionInstType *aggregateUseType) { 56 return aggregateUseType; 57 } 54 58 55 Type* 56 FixFunction::mutate(UnionInstType *aggregateUseType) 57 { 58 return aggregateUseType; 59 } 59 Type * FixFunction::mutate(EnumInstType *aggregateUseType) { 60 return aggregateUseType; 61 } 60 62 61 Type* 62 FixFunction::mutate(EnumInstType *aggregateUseType) 63 { 64 return aggregateUseType; 65 } 63 Type * FixFunction::mutate(ContextInstType *aggregateUseType) { 64 return aggregateUseType; 65 } 66 66 67 Type* 68 FixFunction::mutate(ContextInstType *aggregateUseType) 69 { 70 return aggregateUseType; 71 } 67 Type * FixFunction::mutate(TypeInstType *aggregateUseType) { 68 return aggregateUseType; 69 } 72 70 73 Type* 74 FixFunction::mutate(TypeInstType *aggregateUseType) 75 { 76 return aggregateUseType; 77 } 71 Type * FixFunction::mutate(TupleType *tupleType) { 72 return tupleType; 73 } 74 } // namespace SymTab 78 75 79 Type* 80 FixFunction::mutate(TupleType *tupleType) 81 { 82 return tupleType; 83 } 84 85 86 } // namespace SymTab 76 // Local Variables: // 77 // tab-width: 4 // 78 // mode: c++ // 79 // compile-command: "make install" // 80 // End: // -
translator/SymTab/FixFunction.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: FixFunction.h,v 1.3 2005/08/29 20:14:17 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // FixFunction.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 17:02:08 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 17:03:43 2015 13 // Update Count : 2 14 // 7 15 8 #ifndef SYMTAB_FIXFUNCTION_H9 #define SYMTAB_FIXFUNCTION_H16 #ifndef FIXFUNCTION_H 17 #define FIXFUNCTION_H 10 18 11 19 #include "SynTree/Mutator.h" 12 20 13 21 namespace SymTab { 22 class FixFunction : public Mutator { 23 typedef Mutator Parent; 24 public: 25 FixFunction(); 14 26 15 class FixFunction : public Mutator 16 { 17 typedef Mutator Parent; 27 bool get_isVoid() const { return isVoid; } 28 void set_isVoid( bool newValue ) { isVoid = newValue; } 29 private: 30 virtual DeclarationWithType* mutate(FunctionDecl *functionDecl); 18 31 19 public: 20 FixFunction(); 21 22 bool get_isVoid() const { return isVoid; } 23 void set_isVoid( bool newValue ) { isVoid = newValue; } 24 25 private: 26 virtual DeclarationWithType* mutate(FunctionDecl *functionDecl); 27 28 virtual Type* mutate(VoidType *voidType); 29 virtual Type* mutate(BasicType *basicType); 30 virtual Type* mutate(PointerType *pointerType); 31 virtual Type* mutate(ArrayType *arrayType); 32 virtual Type* mutate(StructInstType *aggregateUseType); 33 virtual Type* mutate(UnionInstType *aggregateUseType); 34 virtual Type* mutate(EnumInstType *aggregateUseType); 35 virtual Type* mutate(ContextInstType *aggregateUseType); 36 virtual Type* mutate(TypeInstType *aggregateUseType); 37 virtual Type* mutate(TupleType *tupleType); 32 virtual Type* mutate(VoidType *voidType); 33 virtual Type* mutate(BasicType *basicType); 34 virtual Type* mutate(PointerType *pointerType); 35 virtual Type* mutate(ArrayType *arrayType); 36 virtual Type* mutate(StructInstType *aggregateUseType); 37 virtual Type* mutate(UnionInstType *aggregateUseType); 38 virtual Type* mutate(EnumInstType *aggregateUseType); 39 virtual Type* mutate(ContextInstType *aggregateUseType); 40 virtual Type* mutate(TypeInstType *aggregateUseType); 41 virtual Type* mutate(TupleType *tupleType); 38 42 39 bool isVoid; 40 }; 41 43 bool isVoid; 44 }; 42 45 } // namespace SymTab 43 46 44 #endif /* #ifndef SYMTAB_FIXFUNCTION_H */ 47 #endif // FIXFUNCTION_H 48 49 // Local Variables: // 50 // tab-width: 4 // 51 // mode: c++ // 52 // compile-command: "make install" // 53 // End: // -
translator/SymTab/IdTable.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: IdTable.cc,v 1.6 2005/08/29 20:14:17 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // IdTable.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 17:04:02 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 17:07:43 2015 13 // Update Count : 3 14 // 7 15 8 16 #include <cassert> … … 18 26 19 27 namespace SymTab { 28 IdTable::IdTable() : scopeLevel( 0 ) { 29 } 20 30 21 IdTable::IdTable() 22 : scopeLevel( 0 ) 23 { 24 } 31 void IdTable::enterScope() { 32 scopeLevel++; 33 } 25 34 26 void 27 IdTable::enterScope() 28 { 29 scopeLevel++; 30 } 35 void IdTable::leaveScope() { 36 for ( OuterTableType::iterator outer = table.begin(); outer != table.end(); ++outer ) { 37 for ( InnerTableType::iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) { 38 std::stack< DeclEntry >& entry = inner->second; 39 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 40 entry.pop(); 41 } // if 42 } // for 43 } // for 31 44 32 void 33 IdTable::leaveScope() 34 { 35 for ( OuterTableType::iterator outer = table.begin(); outer != table.end(); ++outer ) { 36 for ( InnerTableType::iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) { 37 std::stack< DeclEntry >& entry = inner->second; 38 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 39 entry.pop(); 40 } 41 } 42 } 43 44 scopeLevel--; 45 assert( scopeLevel >= 0 ); 46 } 45 scopeLevel--; 46 assert( scopeLevel >= 0 ); 47 } 47 48 48 void 49 IdTable::addDecl( DeclarationWithType *decl ) 50 { 51 const string &name = decl->get_name(); 52 string manglename; 53 if ( decl->get_linkage() == LinkageSpec::C ) { 54 manglename = name; 55 } else { 56 manglename = Mangler::mangle( decl ); 57 } 58 InnerTableType &declTable = table[ name ]; 59 InnerTableType::iterator it = declTable.find( manglename ); 60 if ( it == declTable.end() ) { 61 declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) ); 62 } else { 63 std::stack< DeclEntry >& entry = it->second; 64 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 65 if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) { 66 FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl ); 67 FunctionDecl *old = dynamic_cast< FunctionDecl* >( entry.top().first ); 68 if ( newentry && old && newentry->get_statements() && old->get_statements() ) { 69 throw SemanticError( "duplicate function definition for ", decl ); 70 } else { 71 ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl ); 72 ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first ); 73 if ( newobj && oldobj && newobj->get_init() && oldobj->get_init() ) { 74 throw SemanticError( "duplicate definition for ", decl ); 75 } 76 } 77 } else { 78 throw SemanticError( "duplicate definition for ", decl ); 79 } 80 } else { 81 declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) ); 82 } 83 } 84 // ensure the set of routines with C linkage cannot be overloaded 85 for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) { 86 if ( ! i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) { 87 InnerTableType::iterator j = i; 88 for ( j++; j != declTable.end(); ++j ) { 89 if ( ! j->second.empty() && j->second.top().first->get_linkage() == LinkageSpec::C ) { 90 throw SemanticError( "invalid overload of C function " ); 91 } 49 void IdTable::addDecl( DeclarationWithType *decl ) { 50 const string &name = decl->get_name(); 51 string manglename; 52 if ( decl->get_linkage() == LinkageSpec::C ) { 53 manglename = name; 54 } else { 55 manglename = Mangler::mangle( decl ); 56 } // if 57 58 InnerTableType &declTable = table[ name ]; 59 InnerTableType::iterator it = declTable.find( manglename ); 60 61 if ( it == declTable.end() ) { 62 declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) ); 63 } else { 64 std::stack< DeclEntry >& entry = it->second; 65 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 66 if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) { 67 FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl ); 68 FunctionDecl *old = dynamic_cast< FunctionDecl* >( entry.top().first ); 69 if ( newentry && old && newentry->get_statements() && old->get_statements() ) { 70 throw SemanticError( "duplicate function definition for ", decl ); 71 } else { 72 ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl ); 73 ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first ); 74 if ( newobj && oldobj && newobj->get_init() && oldobj->get_init() ) { 75 throw SemanticError( "duplicate definition for ", decl ); 76 } // if 77 } // if 78 } else { 79 throw SemanticError( "duplicate definition for ", decl ); 80 } // if 81 } else { 82 declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) ); 83 } // if 84 } // if 85 // ensure the set of routines with C linkage cannot be overloaded 86 for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) { 87 if ( ! i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) { 88 InnerTableType::iterator j = i; 89 for ( j++; j != declTable.end(); ++j ) { 90 if ( ! j->second.empty() && j->second.top().first->get_linkage() == LinkageSpec::C ) { 91 throw SemanticError( "invalid overload of C function " ); 92 } // if 93 } // for 94 } // if 95 } // for 92 96 } 93 }94 }95 }96 97 97 void 98 IdTable::lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const 99 { 100 OuterTableType::const_iterator outer = table.find( id ); 101 if ( outer == table.end() ) return; 102 const InnerTableType &declTable = outer->second; 103 for ( InnerTableType::const_iterator it = declTable.begin(); it != declTable.end(); ++it ) { 104 const std::stack< DeclEntry >& entry = it->second; 105 if ( ! entry.empty() ) { 106 decls.push_back( entry.top().first ); 107 } 108 } 109 } 98 void IdTable::lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const { 99 OuterTableType::const_iterator outer = table.find( id ); 100 if ( outer == table.end() ) return; 101 const InnerTableType &declTable = outer->second; 102 for ( InnerTableType::const_iterator it = declTable.begin(); it != declTable.end(); ++it ) { 103 const std::stack< DeclEntry >& entry = it->second; 104 if ( ! entry.empty() ) { 105 decls.push_back( entry.top().first ); 106 } // if 107 } // for 108 } 110 109 111 DeclarationWithType* IdTable::lookupId( const std::string &id) const {112 113 110 DeclarationWithType * IdTable::lookupId( const std::string &id) const { 111 DeclarationWithType* result = 0; 112 int depth = -1; 114 113 115 116 117 118 119 120 121 122 123 } 124 } 125 126 }114 OuterTableType::const_iterator outer = table.find( id ); 115 if ( outer == table.end() ) return 0; 116 const InnerTableType &declTable = outer->second; 117 for ( InnerTableType::const_iterator it = declTable.begin(); it != declTable.end(); ++it ) { 118 const std::stack< DeclEntry >& entry = it->second; 119 if ( ! entry.empty() && entry.top().second > depth ) { 120 result = entry.top().first; 121 depth = entry.top().second; 122 } // if 123 } // for 124 return result; 125 } 127 126 128 void 129 IdTable::dump( std::ostream &os ) const 130 { 131 for ( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) { 132 for ( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) { 127 void IdTable::dump( std::ostream &os ) const { 128 for ( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) { 129 for ( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) { 133 130 #if 0 134 135 136 137 138 139 } 131 const std::stack< DeclEntry >& entry = inner->second; 132 if ( ! entry.empty() ) { // && entry.top().second == scopeLevel ) { 133 os << outer->first << " (" << inner->first << ") (" << entry.top().second << ")" << std::endl; 134 } else { 135 os << outer->first << " (" << inner->first << ") ( entry-empty)" << std::endl; 136 } // if 140 137 #endif 141 138 #if 0 142 143 144 145 146 147 148 } 139 std::stack<DeclEntry> stack = inner->second; 140 os << "dumping a stack" << std::endl; 141 while (! stack.empty()) { 142 DeclEntry d = stack.top(); 143 os << outer->first << " (" << inner->first << ") (" << d.second << ") " << std::endl; 144 stack.pop(); 145 } // while 149 146 #endif 150 } 151 } 147 } // for 148 } // for 152 149 #if 0 153 154 155 156 157 158 } 159 } 160 } 150 for ( OuterTableType::const_iterator outer = table.begin(); outer != table.end(); ++outer ) { 151 for ( InnerTableType::const_iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) { 152 const std::stack< DeclEntry >& entry = inner->second; 153 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 154 os << outer->first << " (" << inner->first << ") (" << scopeLevel << ")" << std::endl; 155 } // if 156 } // for 157 } // for 161 158 #endif 162 } 159 } 160 } // namespace SymTab 163 161 164 165 } // namespace SymTab 162 // Local Variables: // 163 // tab-width: 4 // 164 // mode: c++ // 165 // compile-command: "make install" // 166 // End: // -
translator/SymTab/IdTable.h
ra32b204 r0dd3a2f 1 #ifndef SYMTAB_IDTABLE_H 2 #define SYMTAB_IDTABLE_H 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // IdTable.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:30:02 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:31:45 2015 13 // Update Count : 3 14 // 15 16 #ifndef IDTABLE_H 17 #define IDTABLE_H 3 18 4 19 #include <iostream> … … 12 27 class IdTable { 13 28 public: 14 IdTable();29 IdTable(); 15 30 16 void enterScope();17 void leaveScope();18 void addDecl( DeclarationWithType *decl );19 void lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const;20 DeclarationWithType* lookupId( const std::string &id) const;31 void enterScope(); 32 void leaveScope(); 33 void addDecl( DeclarationWithType *decl ); 34 void lookupId( const std::string &id, std::list< DeclarationWithType* >& decls ) const; 35 DeclarationWithType* lookupId( const std::string &id) const; 21 36 22 void dump( std::ostream &os ) const; // debugging 37 void dump( std::ostream &os ) const; // debugging 38 private: 39 typedef std::pair< DeclarationWithType*, int > DeclEntry; 40 typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType; 41 typedef std::map< std::string, InnerTableType > OuterTableType; 23 42 24 private: 25 typedef std::pair< DeclarationWithType*, int > DeclEntry; 26 typedef std::map< std::string, std::stack< DeclEntry > > InnerTableType; 27 typedef std::map< std::string, InnerTableType > OuterTableType; 28 29 OuterTableType table; 30 int scopeLevel; 43 OuterTableType table; 44 int scopeLevel; 31 45 }; 32 46 } // namespace SymTab 33 47 34 #endif // SYMTAB_IDTABLE_H 48 #endif // IDTABLE_H 49 50 // Local Variables: // 51 // tab-width: 4 // 52 // mode: c++ // 53 // compile-command: "make install" // 54 // End: // -
translator/SymTab/ImplementationType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: ImplementationType.cc,v 1.4 2005/08/29 20:14:17 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // ImplementationType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:32:01 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:34:40 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "ImplementationType.h" … … 15 23 16 24 namespace SymTab { 25 class ImplementationType : public Visitor { 26 public: 27 ImplementationType( const SymTab::Indexer &indexer ); 17 28 18 class ImplementationType : public Visitor 19 { 20 public: 21 ImplementationType( const SymTab::Indexer &indexer ); 22 23 Type *get_result() { return result; } 29 Type *get_result() { return result; } 30 private: 31 virtual void visit(VoidType *voidType); 32 virtual void visit(BasicType *basicType); 33 virtual void visit(PointerType *pointerType); 34 virtual void visit(ArrayType *arrayType); 35 virtual void visit(FunctionType *functionType); 36 virtual void visit(StructInstType *aggregateUseType); 37 virtual void visit(UnionInstType *aggregateUseType); 38 virtual void visit(EnumInstType *aggregateUseType); 39 virtual void visit(ContextInstType *aggregateUseType); 40 virtual void visit(TypeInstType *aggregateUseType); 41 virtual void visit(TupleType *tupleType); 24 42 25 private: 26 virtual void visit(VoidType *voidType); 27 virtual void visit(BasicType *basicType); 28 virtual void visit(PointerType *pointerType); 29 virtual void visit(ArrayType *arrayType); 30 virtual void visit(FunctionType *functionType); 31 virtual void visit(StructInstType *aggregateUseType); 32 virtual void visit(UnionInstType *aggregateUseType); 33 virtual void visit(EnumInstType *aggregateUseType); 34 virtual void visit(ContextInstType *aggregateUseType); 35 virtual void visit(TypeInstType *aggregateUseType); 36 virtual void visit(TupleType *tupleType); 43 Type *result; // synthesized 44 const SymTab::Indexer &indexer; 45 }; 37 46 38 Type *result; // synthesized 39 const SymTab::Indexer &indexer; 40 }; 47 Type * implementationType( Type *type, const SymTab::Indexer& indexer ) { 48 ImplementationType implementor( indexer ); 49 type->accept( implementor ); 50 if ( implementor.get_result() == 0 ) { 51 return type->clone(); 52 } else { 53 return implementor.get_result(); 54 } // if 55 } 41 56 42 Type* 43 implementationType( Type *type, const SymTab::Indexer& indexer ) 44 { 45 ImplementationType implementor( indexer ); 46 type->accept( implementor ); 47 if ( implementor.get_result() == 0 ) { 48 return type->clone(); 49 } else { 50 return implementor.get_result(); 51 } 52 } 57 ImplementationType::ImplementationType( const SymTab::Indexer &indexer ) : result( 0 ), indexer( indexer ) { 58 } 53 59 54 ImplementationType::ImplementationType( const SymTab::Indexer &indexer ) 55 : result( 0 ), indexer( indexer ) 56 { 57 } 60 void ImplementationType::visit(VoidType *voidType) { 61 } 58 62 59 void 60 ImplementationType::visit(VoidType *voidType) 61 { 62 } 63 void ImplementationType::visit(BasicType *basicType) { 64 } 63 65 64 void 65 ImplementationType::visit(BasicType *basicType) 66 { 67 } 66 void ImplementationType::visit(PointerType *pointerType) { 67 PointerType *newType = pointerType->clone(); 68 newType->set_base( implementationType( pointerType->get_base(), indexer ) ); 69 result = newType; 70 } 68 71 69 void 70 ImplementationType::visit(PointerType *pointerType) 71 { 72 PointerType *newType = pointerType->clone(); 73 newType->set_base( implementationType( pointerType->get_base(), indexer ) ); 74 result = newType; 75 } 72 void ImplementationType::visit(ArrayType *arrayType) { 73 ArrayType *newType = arrayType->clone(); 74 newType->set_base( implementationType( arrayType->get_base(), indexer ) ); 75 result = newType; 76 } 76 77 77 void 78 ImplementationType::visit(ArrayType *arrayType) 79 { 80 ArrayType *newType = arrayType->clone(); 81 newType->set_base( implementationType( arrayType->get_base(), indexer ) ); 82 result = newType; 83 } 84 85 void 86 ImplementationType::visit(FunctionType *functionType) 87 { 78 void ImplementationType::visit(FunctionType *functionType) { 88 79 /// FunctionType *newType = functionType->clone(); 89 80 /// for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) { … … 93 84 /// i->set_type( implementationType( i->get_type(), indexer ) ); 94 85 /// } 95 }86 } 96 87 97 void 98 ImplementationType::visit(StructInstType *aggregateUseType) 99 { 100 } 88 void ImplementationType::visit(StructInstType *aggregateUseType) { 89 } 101 90 102 void 103 ImplementationType::visit(UnionInstType *aggregateUseType) 104 { 105 } 91 void ImplementationType::visit(UnionInstType *aggregateUseType) { 92 } 106 93 107 void 108 ImplementationType::visit(EnumInstType *aggregateUseType) 109 { 110 } 94 void ImplementationType::visit(EnumInstType *aggregateUseType) { 95 } 111 96 112 void 113 ImplementationType::visit(ContextInstType *aggregateUseType) 114 { 115 } 97 void ImplementationType::visit(ContextInstType *aggregateUseType) { 98 } 116 99 117 void 118 ImplementationType::visit(TypeInstType *inst) 119 { 120 NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() ); 121 if ( typeDecl && typeDecl->get_base() ) { 122 Type *base = implementationType( typeDecl->get_base(), indexer ); 123 base->get_qualifiers() += inst->get_qualifiers(); 124 result = base; 125 } 126 } 100 void ImplementationType::visit(TypeInstType *inst) { 101 NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() ); 102 if ( typeDecl && typeDecl->get_base() ) { 103 Type *base = implementationType( typeDecl->get_base(), indexer ); 104 base->get_qualifiers() += inst->get_qualifiers(); 105 result = base; 106 } // if 107 } 127 108 128 void 129 ImplementationType::visit(TupleType *tupleType) 130 { 131 TupleType *newType = new TupleType( Type::Qualifiers() ); 132 for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) { 133 Type *implType = implementationType( *i, indexer ); 134 implType->get_qualifiers() += tupleType->get_qualifiers(); 135 newType->get_types().push_back( implType ); 136 } 137 result = newType; 138 } 109 void ImplementationType::visit(TupleType *tupleType) { 110 TupleType *newType = new TupleType( Type::Qualifiers() ); 111 for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) { 112 Type *implType = implementationType( *i, indexer ); 113 implType->get_qualifiers() += tupleType->get_qualifiers(); 114 newType->get_types().push_back( implType ); 115 } // for 116 result = newType; 117 } 118 } // namespace SymTab 139 119 140 } // namespace SymTab 120 // Local Variables: // 121 // tab-width: 4 // 122 // mode: c++ // 123 // compile-command: "make install" // 124 // End: // -
translator/SymTab/ImplementationType.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: ImplementationType.h,v 1.3 2005/08/29 20:14:17 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // ImplementationType.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:35:41 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:37:15 2015 13 // Update Count : 2 14 // 7 15 8 #ifndef SYMTAB_IMPLEMENTATIONTYPE_H9 #define SYMTAB_IMPLEMENTATIONTYPE_H16 #ifndef IMPLEMENTATIONTYPE_H 17 #define IMPLEMENTATIONTYPE_H 10 18 11 19 #include "SynTree/SynTree.h" … … 13 21 14 22 namespace SymTab { 23 Type *implementationType( Type *, const SymTab::Indexer &indexer ); 15 24 16 Type *implementationType( Type *, const SymTab::Indexer &indexer ); 17 18 template< typename InputIterator, typename OutputIterator > 19 void 20 implementationTypeList( InputIterator begin, InputIterator end, OutputIterator out, const SymTab::Indexer &indexer ) 21 { 22 while ( begin != end ) { 23 *out++ = implementationType( *begin++, indexer ); 24 } 25 } 26 25 template< typename InputIterator, typename OutputIterator > 26 void implementationTypeList( InputIterator begin, InputIterator end, OutputIterator out, const SymTab::Indexer &indexer ) { 27 while ( begin != end ) { 28 *out++ = implementationType( *begin++, indexer ); 29 } // while 30 } 27 31 } // namespace SymTab 28 32 29 #endif /* #ifndef SYMTAB_IMPLEMENTATIONTYPE_H */ 33 #endif // IMPLEMENTATIONTYPE_H 34 35 // Local Variables: // 36 // tab-width: 4 // 37 // mode: c++ // 38 // compile-command: "make install" // 39 // End: // -
translator/SymTab/Indexer.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Indexer.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:37:33 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:38:44 2015 13 // Update Count : 2 14 // 15 1 16 #include "SynTree/Declaration.h" 2 17 #include "SynTree/Type.h" … … 16 31 17 32 void Indexer::visit( ObjectDecl *objectDecl ) { 18 maybeAccept( objectDecl->get_type(), *this );19 maybeAccept( objectDecl->get_init(), *this );20 maybeAccept( objectDecl->get_bitfieldWidth(), *this );21 if ( objectDecl->get_name() != "" ) {22 23 24 }33 maybeAccept( objectDecl->get_type(), *this ); 34 maybeAccept( objectDecl->get_init(), *this ); 35 maybeAccept( objectDecl->get_bitfieldWidth(), *this ); 36 if ( objectDecl->get_name() != "" ) { 37 debugPrint( "Adding object " << objectDecl->get_name() << std::endl ); 38 idTable.addDecl( objectDecl ); 39 } // if 25 40 } 26 41 27 42 void Indexer::visit( FunctionDecl *functionDecl ) { 28 if ( functionDecl->get_name() == "" ) return;29 debugPrint( "Adding function " << functionDecl->get_name() << std::endl );30 idTable.addDecl( functionDecl );31 enterScope();32 maybeAccept( functionDecl->get_functionType(), *this );33 acceptAll( functionDecl->get_oldDecls(), *this );34 maybeAccept( functionDecl->get_statements(), *this );35 leaveScope();43 if ( functionDecl->get_name() == "" ) return; 44 debugPrint( "Adding function " << functionDecl->get_name() << std::endl ); 45 idTable.addDecl( functionDecl ); 46 enterScope(); 47 maybeAccept( functionDecl->get_functionType(), *this ); 48 acceptAll( functionDecl->get_oldDecls(), *this ); 49 maybeAccept( functionDecl->get_statements(), *this ); 50 leaveScope(); 36 51 } 37 52 … … 56 71 57 72 void Indexer::visit( TypeDecl *typeDecl ) { 58 // see A NOTE ON THE ORDER OF TRAVERSAL, above59 // note that assertions come after the type is added to the symtab, since they aren't part60 // of the type proper and may depend on the type itself61 enterScope();62 acceptAll( typeDecl->get_parameters(), *this );63 maybeAccept( typeDecl->get_base(), *this );64 leaveScope();65 debugPrint( "Adding type " << typeDecl->get_name() << std::endl );66 typeTable.add( typeDecl );67 acceptAll( typeDecl->get_assertions(), *this );73 // see A NOTE ON THE ORDER OF TRAVERSAL, above 74 // note that assertions come after the type is added to the symtab, since they aren't part 75 // of the type proper and may depend on the type itself 76 enterScope(); 77 acceptAll( typeDecl->get_parameters(), *this ); 78 maybeAccept( typeDecl->get_base(), *this ); 79 leaveScope(); 80 debugPrint( "Adding type " << typeDecl->get_name() << std::endl ); 81 typeTable.add( typeDecl ); 82 acceptAll( typeDecl->get_assertions(), *this ); 68 83 } 69 84 70 85 void Indexer::visit( TypedefDecl *typeDecl ) { 71 enterScope();72 acceptAll( typeDecl->get_parameters(), *this );73 maybeAccept( typeDecl->get_base(), *this );74 leaveScope();75 debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl );76 typeTable.add( typeDecl );86 enterScope(); 87 acceptAll( typeDecl->get_parameters(), *this ); 88 maybeAccept( typeDecl->get_base(), *this ); 89 leaveScope(); 90 debugPrint( "Adding typedef " << typeDecl->get_name() << std::endl ); 91 typeTable.add( typeDecl ); 77 92 } 78 93 79 94 void Indexer::visit( StructDecl *aggregateDecl ) { 80 // make up a forward declaration and add it before processing the members81 StructDecl fwdDecl( aggregateDecl->get_name() );82 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );83 debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );84 structTable.add( &fwdDecl );85 86 enterScope();87 acceptAll( aggregateDecl->get_parameters(), *this );88 acceptAll( aggregateDecl->get_members(), *this );89 leaveScope();90 91 debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );92 // this addition replaces the forward declaration93 structTable.add( aggregateDecl );95 // make up a forward declaration and add it before processing the members 96 StructDecl fwdDecl( aggregateDecl->get_name() ); 97 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() ); 98 debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl ); 99 structTable.add( &fwdDecl ); 100 101 enterScope(); 102 acceptAll( aggregateDecl->get_parameters(), *this ); 103 acceptAll( aggregateDecl->get_members(), *this ); 104 leaveScope(); 105 106 debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl ); 107 // this addition replaces the forward declaration 108 structTable.add( aggregateDecl ); 94 109 } 95 110 96 111 void Indexer::visit( UnionDecl *aggregateDecl ) { 97 // make up a forward declaration and add it before processing the members98 UnionDecl fwdDecl( aggregateDecl->get_name() );99 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );100 debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );101 unionTable.add( &fwdDecl );102 103 enterScope();104 acceptAll( aggregateDecl->get_parameters(), *this );105 acceptAll( aggregateDecl->get_members(), *this );106 leaveScope();107 108 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );109 unionTable.add( aggregateDecl );112 // make up a forward declaration and add it before processing the members 113 UnionDecl fwdDecl( aggregateDecl->get_name() ); 114 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() ); 115 debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl ); 116 unionTable.add( &fwdDecl ); 117 118 enterScope(); 119 acceptAll( aggregateDecl->get_parameters(), *this ); 120 acceptAll( aggregateDecl->get_members(), *this ); 121 leaveScope(); 122 123 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl ); 124 unionTable.add( aggregateDecl ); 110 125 } 111 126 112 127 void Indexer::visit( EnumDecl *aggregateDecl ) { 113 debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl );114 enumTable.add( aggregateDecl );115 // unlike structs, contexts, and unions, enums inject their members into the global scope116 acceptAll( aggregateDecl->get_members(), *this );128 debugPrint( "Adding enum " << aggregateDecl->get_name() << std::endl ); 129 enumTable.add( aggregateDecl ); 130 // unlike structs, contexts, and unions, enums inject their members into the global scope 131 acceptAll( aggregateDecl->get_members(), *this ); 117 132 } 118 133 119 134 void Indexer::visit( ContextDecl *aggregateDecl ) { 120 enterScope();121 acceptAll( aggregateDecl->get_parameters(), *this );122 acceptAll( aggregateDecl->get_members(), *this );123 leaveScope();124 125 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );126 contextTable.add( aggregateDecl );135 enterScope(); 136 acceptAll( aggregateDecl->get_parameters(), *this ); 137 acceptAll( aggregateDecl->get_members(), *this ); 138 leaveScope(); 139 140 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl ); 141 contextTable.add( aggregateDecl ); 127 142 } 128 143 129 144 void Indexer::visit( CompoundStmt *compoundStmt ) { 130 enterScope();131 acceptAll( compoundStmt->get_kids(), *this );132 leaveScope();145 enterScope(); 146 acceptAll( compoundStmt->get_kids(), *this ); 147 leaveScope(); 133 148 } 134 149 135 150 void Indexer::visit( ContextInstType *contextInst ) { 136 acceptAll( contextInst->get_parameters(), *this );137 acceptAll( contextInst->get_members(), *this );151 acceptAll( contextInst->get_parameters(), *this ); 152 acceptAll( contextInst->get_members(), *this ); 138 153 } 139 154 140 155 void Indexer::visit( StructInstType *structInst ) { 141 if ( ! structTable.lookup( structInst->get_name() ) ) {142 143 144 }145 enterScope();146 acceptAll( structInst->get_parameters(), *this );147 leaveScope();156 if ( ! structTable.lookup( structInst->get_name() ) ) { 157 debugPrint( "Adding struct " << structInst->get_name() << " from implicit forward declaration" << std::endl ); 158 structTable.add( structInst->get_name() ); 159 } 160 enterScope(); 161 acceptAll( structInst->get_parameters(), *this ); 162 leaveScope(); 148 163 } 149 164 150 165 void Indexer::visit( UnionInstType *unionInst ) { 151 if ( ! unionTable.lookup( unionInst->get_name() ) ) {152 153 154 }155 enterScope();156 acceptAll( unionInst->get_parameters(), *this );157 leaveScope();166 if ( ! unionTable.lookup( unionInst->get_name() ) ) { 167 debugPrint( "Adding union " << unionInst->get_name() << " from implicit forward declaration" << std::endl ); 168 unionTable.add( unionInst->get_name() ); 169 } 170 enterScope(); 171 acceptAll( unionInst->get_parameters(), *this ); 172 leaveScope(); 158 173 } 159 174 … … 167 182 168 183 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &list ) const { 169 idTable.lookupId( id, list );184 idTable.lookupId( id, list ); 170 185 } 171 186 172 187 DeclarationWithType* Indexer::lookupId( const std::string &id) const { 173 return idTable.lookupId(id);188 return idTable.lookupId(id); 174 189 } 175 190 176 191 NamedTypeDecl *Indexer::lookupType( const std::string &id ) const { 177 return typeTable.lookup( id );192 return typeTable.lookup( id ); 178 193 } 179 194 180 195 StructDecl *Indexer::lookupStruct( const std::string &id ) const { 181 return structTable.lookup( id );196 return structTable.lookup( id ); 182 197 } 183 198 184 199 EnumDecl *Indexer::lookupEnum( const std::string &id ) const { 185 return enumTable.lookup( id );200 return enumTable.lookup( id ); 186 201 } 187 202 188 203 UnionDecl *Indexer::lookupUnion( const std::string &id ) const { 189 return unionTable.lookup( id );204 return unionTable.lookup( id ); 190 205 } 191 206 192 207 ContextDecl * Indexer::lookupContext( const std::string &id ) const { 193 return contextTable.lookup( id );208 return contextTable.lookup( id ); 194 209 } 195 210 196 211 void Indexer::enterScope() { 197 if ( doDebug ) {198 199 }200 idTable.enterScope();201 typeTable.enterScope();202 structTable.enterScope();203 enumTable.enterScope();204 unionTable.enterScope();205 contextTable.enterScope();212 if ( doDebug ) { 213 std::cout << "--- Entering scope" << std::endl; 214 } 215 idTable.enterScope(); 216 typeTable.enterScope(); 217 structTable.enterScope(); 218 enumTable.enterScope(); 219 unionTable.enterScope(); 220 contextTable.enterScope(); 206 221 } 207 222 208 223 void Indexer::leaveScope() { 209 using std::cout;210 using std::endl;211 212 if ( doDebug ) {213 214 215 216 217 218 219 220 }221 idTable.leaveScope();222 typeTable.leaveScope();223 structTable.leaveScope();224 enumTable.leaveScope();225 unionTable.leaveScope();226 contextTable.leaveScope();224 using std::cout; 225 using std::endl; 226 227 if ( doDebug ) { 228 cout << "--- Leaving scope containing" << endl; 229 idTable.dump( cout ); 230 typeTable.dump( cout ); 231 structTable.dump( cout ); 232 enumTable.dump( cout ); 233 unionTable.dump( cout ); 234 contextTable.dump( cout ); 235 } 236 idTable.leaveScope(); 237 typeTable.leaveScope(); 238 structTable.leaveScope(); 239 enumTable.leaveScope(); 240 unionTable.leaveScope(); 241 contextTable.leaveScope(); 227 242 } 228 243 … … 244 259 contextTable.dump( os ); 245 260 #if 0 246 idTable.dump( os );247 typeTable.dump( os );248 structTable.dump( os );249 enumTable.dump( os );250 unionTable.dump( os );251 contextTable.dump( os );261 idTable.dump( os ); 262 typeTable.dump( os ); 263 structTable.dump( os ); 264 enumTable.dump( os ); 265 unionTable.dump( os ); 266 contextTable.dump( os ); 252 267 #endif 253 268 } 254 269 } // namespace SymTab 270 271 // Local Variables: // 272 // tab-width: 4 // 273 // mode: c++ // 274 // compile-command: "make install" // 275 // End: // -
translator/SymTab/Indexer.h
ra32b204 r0dd3a2f 1 #ifndef SYMTAB_INDEXER_H 2 #define SYMTAB_INDEXER_H 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Indexer.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:38:55 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:40:17 2015 13 // Update Count : 2 14 // 15 16 #ifndef INDEXER_H 17 #define INDEXER_H 3 18 4 19 #include <list> … … 61 76 } // namespace SymTab 62 77 63 #endif // SYMTAB_INDEXER_H 78 #endif // INDEXER_H 79 80 // Local Variables: // 81 // tab-width: 4 // 82 // mode: c++ // 83 // compile-command: "make install" // 84 // End: // -
translator/SymTab/Mangler.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Mangler.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:40:29 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:43:49 2015 13 // Update Count : 2 14 // 15 1 16 #include <cassert> 2 17 #include <string> … … 15 30 16 31 namespace SymTab { 17 Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) 18 {}32 Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) { 33 } 19 34 20 35 //Mangler::Mangler( const Mangler & ) … … 23 38 //} 24 39 Mangler::Mangler( const Mangler &rhs ) : mangleName() { 25 varNums = rhs.varNums;26 nextVarNum = rhs.nextVarNum;27 isTopLevel = rhs.isTopLevel;40 varNums = rhs.varNums; 41 nextVarNum = rhs.nextVarNum; 42 isTopLevel = rhs.isTopLevel; 28 43 } 29 44 30 45 void Mangler::mangleDecl( DeclarationWithType *declaration ) { 31 bool wasTopLevel = isTopLevel;32 if ( isTopLevel ) {33 34 35 36 }37 mangleName << "__";38 CodeGen::OperatorInfo opInfo;39 if ( operatorLookup( declaration->get_name(), opInfo ) ) {40 41 } else {42 43 }44 mangleName << "__";45 maybeAccept( declaration->get_type(), *this );46 isTopLevel = wasTopLevel;46 bool wasTopLevel = isTopLevel; 47 if ( isTopLevel ) { 48 varNums.clear(); 49 nextVarNum = 0; 50 isTopLevel = false; 51 } // if 52 mangleName << "__"; 53 CodeGen::OperatorInfo opInfo; 54 if ( operatorLookup( declaration->get_name(), opInfo ) ) { 55 mangleName << opInfo.outputName; 56 } else { 57 mangleName << declaration->get_name(); 58 } // if 59 mangleName << "__"; 60 maybeAccept( declaration->get_type(), *this ); 61 isTopLevel = wasTopLevel; 47 62 } 48 63 49 64 void Mangler::visit( ObjectDecl *declaration ) { 50 mangleDecl( declaration );65 mangleDecl( declaration ); 51 66 } 52 67 53 68 void Mangler::visit( FunctionDecl *declaration ) { 54 mangleDecl( declaration );69 mangleDecl( declaration ); 55 70 } 56 71 57 72 void Mangler::visit( VoidType *voidType ) { 58 printQualifiers( voidType );59 mangleName << "v";73 printQualifiers( voidType ); 74 mangleName << "v"; 60 75 } 61 76 62 77 void Mangler::visit( BasicType *basicType ) { 63 static const char *btLetter[] = {64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 };78 static const char *btLetter[] = { 79 "b", // Bool 80 "c", // Char 81 "Sc", // SignedChar 82 "Uc", // UnsignedChar 83 "s", // ShortSignedInt 84 "Us", // ShortUnsignedInt 85 "i", // SignedInt 86 "Ui", // UnsignedInt 87 "l", // LongSignedInt 88 "Ul", // LongUnsignedInt 89 "q", // LongLongSignedInt 90 "Uq", // LongLongUnsignedInt 91 "f", // Float 92 "d", // Double 93 "r", // LongDouble 94 "Xf", // FloatComplex 95 "Xd", // DoubleComplex 96 "Xr", // LongDoubleComplex 97 "If", // FloatImaginary 98 "Id", // DoubleImaginary 99 "Ir", // LongDoubleImaginary 100 }; 86 101 87 printQualifiers( basicType );88 mangleName << btLetter[ basicType->get_kind() ];102 printQualifiers( basicType ); 103 mangleName << btLetter[ basicType->get_kind() ]; 89 104 } 90 105 91 106 void Mangler::visit( PointerType *pointerType ) { 92 printQualifiers( pointerType );93 mangleName << "P";94 maybeAccept( pointerType->get_base(), *this );107 printQualifiers( pointerType ); 108 mangleName << "P"; 109 maybeAccept( pointerType->get_base(), *this ); 95 110 } 96 111 97 112 void Mangler::visit( ArrayType *arrayType ) { 98 // TODO: encode dimension99 printQualifiers( arrayType );100 mangleName << "A0";101 maybeAccept( arrayType->get_base(), *this );113 // TODO: encode dimension 114 printQualifiers( arrayType ); 115 mangleName << "A0"; 116 maybeAccept( arrayType->get_base(), *this ); 102 117 } 103 118 104 119 namespace { 105 inline std::list< Type* > 106 getTypes( const std::list< DeclarationWithType* > decls ) 107 { 108 std::list< Type* > ret; 109 std::transform( decls.begin(), decls.end(), std::back_inserter( ret ), 110 std::mem_fun( &DeclarationWithType::get_type ) ); 111 return ret; 112 } 120 inline std::list< Type* > getTypes( const std::list< DeclarationWithType* > decls ) { 121 std::list< Type* > ret; 122 std::transform( decls.begin(), decls.end(), std::back_inserter( ret ), 123 std::mem_fun( &DeclarationWithType::get_type ) ); 124 return ret; 125 } 113 126 } 114 127 115 128 void Mangler::visit( FunctionType *functionType ) { 116 printQualifiers( functionType );117 mangleName << "F";118 std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() );119 acceptAll( returnTypes, *this );120 mangleName << "_";121 std::list< Type* > paramTypes = getTypes( functionType->get_parameters() );122 acceptAll( paramTypes, *this );123 mangleName << "_";129 printQualifiers( functionType ); 130 mangleName << "F"; 131 std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() ); 132 acceptAll( returnTypes, *this ); 133 mangleName << "_"; 134 std::list< Type* > paramTypes = getTypes( functionType->get_parameters() ); 135 acceptAll( paramTypes, *this ); 136 mangleName << "_"; 124 137 } 125 138 126 139 void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) { 127 printQualifiers( refType );128 mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name();140 printQualifiers( refType ); 141 mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name(); 129 142 } 130 143 131 144 void Mangler::visit( StructInstType *aggregateUseType ) { 132 mangleRef( aggregateUseType, "s" );145 mangleRef( aggregateUseType, "s" ); 133 146 } 134 147 135 148 void Mangler::visit( UnionInstType *aggregateUseType ) { 136 mangleRef( aggregateUseType, "u" );149 mangleRef( aggregateUseType, "u" ); 137 150 } 138 151 139 152 void Mangler::visit( EnumInstType *aggregateUseType ) { 140 mangleRef( aggregateUseType, "e" );153 mangleRef( aggregateUseType, "e" ); 141 154 } 142 155 143 156 void Mangler::visit( TypeInstType *typeInst ) { 144 VarMapType::iterator varNum = varNums.find( typeInst->get_name() );145 if ( varNum == varNums.end() ) {146 147 } else {148 149 150 151 152 153 154 mangleName << "t";155 break;156 157 mangleName << "d";158 break;159 160 mangleName << "f";161 break;162 }163 164 }157 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 158 if ( varNum == varNums.end() ) { 159 mangleRef( typeInst, "t" ); 160 } else { 161 printQualifiers( typeInst ); 162 std::ostrstream numStream; 163 numStream << varNum->second.first; 164 mangleName << (numStream.pcount() + 1); 165 switch ( (TypeDecl::Kind )varNum->second.second ) { 166 case TypeDecl::Any: 167 mangleName << "t"; 168 break; 169 case TypeDecl::Dtype: 170 mangleName << "d"; 171 break; 172 case TypeDecl::Ftype: 173 mangleName << "f"; 174 break; 175 } // switch 176 mangleName << std::string( numStream.str(), numStream.pcount() ); 177 } // if 165 178 } 166 179 167 180 void Mangler::visit( TupleType *tupleType ) { 168 printQualifiers( tupleType );169 mangleName << "T";170 acceptAll( tupleType->get_types(), *this );171 mangleName << "_";181 printQualifiers( tupleType ); 182 mangleName << "T"; 183 acceptAll( tupleType->get_types(), *this ); 184 mangleName << "_"; 172 185 } 173 186 174 187 void Mangler::visit( TypeDecl *decl ) { 175 static const char *typePrefix[] = { "BT", "BD", "BF" };176 mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name();188 static const char *typePrefix[] = { "BT", "BD", "BF" }; 189 mangleName << typePrefix[ decl->get_kind() ] << ( decl->get_name().length() + 1 ) << decl->get_name(); 177 190 } 178 191 179 192 void printVarMap( const std::map< std::string, std::pair< int, int > > &varMap, std::ostream &os ) { 180 for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) {181 182 }193 for ( std::map< std::string, std::pair< int, int > >::const_iterator i = varMap.begin(); i != varMap.end(); ++i ) { 194 os << i->first << "(" << i->second.first << "/" << i->second.second << ")" << std::endl; 195 } // for 183 196 } 184 197 185 198 void Mangler::printQualifiers( Type *type ) { 186 if ( ! type->get_forall().empty() ) { 187 std::list< std::string > assertionNames; 188 int tcount = 0, dcount = 0, fcount = 0; 189 mangleName << "A"; 190 for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) { 191 switch ( (*i)->get_kind() ) { 192 case TypeDecl::Any: 193 tcount++; 194 break; 195 case TypeDecl::Dtype: 196 dcount++; 197 break; 198 case TypeDecl::Ftype: 199 fcount++; 200 break; 201 } 202 varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() ); 203 for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) { 204 Mangler sub_mangler; 205 sub_mangler.nextVarNum = nextVarNum; 206 sub_mangler.isTopLevel = false; 207 sub_mangler.varNums = varNums; 208 (*assert)->accept( sub_mangler ); 209 assertionNames.push_back( std::string( sub_mangler.mangleName.str(), sub_mangler.mangleName.pcount() ) ); 210 } 211 } 212 mangleName << tcount << "_" << dcount << "_" << fcount << "_"; 213 std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 214 mangleName << "_"; 215 } 216 if ( type->get_isConst() ) { 217 mangleName << "C"; 218 } 219 if ( type->get_isVolatile() ) { 220 mangleName << "V"; 221 } 222 if ( type->get_isRestrict() ) { 223 mangleName << "R"; 224 } 225 if ( type->get_isLvalue() ) { 226 mangleName << "L"; 227 } 228 if ( type->get_isAtomic() ) { 229 mangleName << "A"; 230 } 231 } 232 } // SymTab 199 if ( ! type->get_forall().empty() ) { 200 std::list< std::string > assertionNames; 201 int tcount = 0, dcount = 0, fcount = 0; 202 mangleName << "A"; 203 for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) { 204 switch ( (*i)->get_kind() ) { 205 case TypeDecl::Any: 206 tcount++; 207 break; 208 case TypeDecl::Dtype: 209 dcount++; 210 break; 211 case TypeDecl::Ftype: 212 fcount++; 213 break; 214 } // switch 215 varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() ); 216 for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) { 217 Mangler sub_mangler; 218 sub_mangler.nextVarNum = nextVarNum; 219 sub_mangler.isTopLevel = false; 220 sub_mangler.varNums = varNums; 221 (*assert)->accept( sub_mangler ); 222 assertionNames.push_back( std::string( sub_mangler.mangleName.str(), sub_mangler.mangleName.pcount() ) ); 223 } // for 224 } // for 225 mangleName << tcount << "_" << dcount << "_" << fcount << "_"; 226 std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 227 mangleName << "_"; 228 } // if 229 if ( type->get_isConst() ) { 230 mangleName << "C"; 231 } // if 232 if ( type->get_isVolatile() ) { 233 mangleName << "V"; 234 } // if 235 if ( type->get_isRestrict() ) { 236 mangleName << "R"; 237 } // if 238 if ( type->get_isLvalue() ) { 239 mangleName << "L"; 240 } // if 241 if ( type->get_isAtomic() ) { 242 mangleName << "A"; 243 } // if 244 } 245 } // namespace SymTab 246 247 // Local Variables: // 248 // tab-width: 4 // 249 // mode: c++ // 250 // compile-command: "make install" // 251 // End: // -
translator/SymTab/Mangler.h
ra32b204 r0dd3a2f 1 #ifndef SYMTAB_MANGLER_H 2 #define SYMTAB_MANGLER_H 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Mangler.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:44:03 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:45:05 2015 13 // Update Count : 2 14 // 15 16 #ifndef MANGLER_H 17 #define MANGLER_H 3 18 4 19 #include <strstream> … … 9 24 class Mangler : public Visitor { 10 25 public: 11 template< typename SynTreeClass >26 template< typename SynTreeClass > 12 27 static std::string mangle( SynTreeClass *decl ); // interface to clients 13 28 14 29 /// using Visitor::visit; 15 virtual void visit( ObjectDecl *declaration );16 virtual void visit( FunctionDecl *declaration );17 virtual void visit( TypeDecl *declaration );30 virtual void visit( ObjectDecl *declaration ); 31 virtual void visit( FunctionDecl *declaration ); 32 virtual void visit( TypeDecl *declaration ); 18 33 19 virtual void visit( VoidType *voidType );20 virtual void visit( BasicType *basicType );21 virtual void visit( PointerType *pointerType );22 virtual void visit( ArrayType *arrayType );23 virtual void visit( FunctionType *functionType );24 virtual void visit( StructInstType *aggregateUseType );25 virtual void visit( UnionInstType *aggregateUseType );26 virtual void visit( EnumInstType *aggregateUseType );27 virtual void visit( TypeInstType *aggregateUseType );28 virtual void visit( TupleType *tupleType );34 virtual void visit( VoidType *voidType ); 35 virtual void visit( BasicType *basicType ); 36 virtual void visit( PointerType *pointerType ); 37 virtual void visit( ArrayType *arrayType ); 38 virtual void visit( FunctionType *functionType ); 39 virtual void visit( StructInstType *aggregateUseType ); 40 virtual void visit( UnionInstType *aggregateUseType ); 41 virtual void visit( EnumInstType *aggregateUseType ); 42 virtual void visit( TypeInstType *aggregateUseType ); 43 virtual void visit( TupleType *tupleType ); 29 44 30 std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); }45 std::string get_mangleName() { return std::string( mangleName.str(), mangleName.pcount() ); } 31 46 private: 32 std::ostrstream mangleName;33 typedef std::map< std::string, std::pair< int, int > > VarMapType;34 VarMapType varNums;35 int nextVarNum;36 bool isTopLevel;47 std::ostrstream mangleName; 48 typedef std::map< std::string, std::pair< int, int > > VarMapType; 49 VarMapType varNums; 50 int nextVarNum; 51 bool isTopLevel; 37 52 38 Mangler();39 Mangler( const Mangler & );53 Mangler(); 54 Mangler( const Mangler & ); 40 55 41 void mangleDecl( DeclarationWithType *declaration );42 void mangleRef( ReferenceToType *refType, std::string prefix );56 void mangleDecl( DeclarationWithType *declaration ); 57 void mangleRef( ReferenceToType *refType, std::string prefix ); 43 58 44 void printQualifiers( Type *type );59 void printQualifiers( Type *type ); 45 60 }; // Mangler 46 61 47 62 template< typename SynTreeClass > 48 63 std::string Mangler::mangle( SynTreeClass *decl ) { 49 Mangler mangler;50 maybeAccept( decl, mangler );51 return mangler.get_mangleName();64 Mangler mangler; 65 maybeAccept( decl, mangler ); 66 return mangler.get_mangleName(); 52 67 } 53 68 } // SymTab 54 69 55 #endif // SYMTAB_MANGLER_H 70 #endif // MANGLER_H 71 72 // Local Variables: // 73 // tab-width: 4 // 74 // mode: c++ // 75 // compile-command: "make install" // 76 // End: // -
translator/SymTab/StackTable.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // StackTable.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:45:15 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:46:59 2015 13 // Update Count : 2 14 // 15 1 16 #include <cassert> 2 17 … … 5 20 namespace SymTab { 6 21 template< typename Element, typename ConflictFunction > 7 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) 8 {}22 StackTable< Element, ConflictFunction >::StackTable() : scopeLevel( 0 ) { 23 } 9 24 10 25 template< typename Element, typename ConflictFunction > 11 26 void StackTable< Element, ConflictFunction >::enterScope() { 12 scopeLevel++;27 scopeLevel++; 13 28 } 14 29 15 30 template< typename Element, typename ConflictFunction > 16 31 void StackTable< Element, ConflictFunction >::leaveScope() { 17 for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) {18 19 20 entry.pop();21 }22 }23 scopeLevel--;24 assert( scopeLevel >= 0 );32 for ( typename TableType::iterator it = table.begin(); it != table.end(); ++it ) { 33 std::stack< Entry >& entry = it->second; 34 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 35 entry.pop(); 36 } // if 37 } // for 38 scopeLevel--; 39 assert( scopeLevel >= 0 ); 25 40 } 26 41 27 42 template< typename Element, typename ConflictFunction > 28 43 void StackTable< Element, ConflictFunction >::add( Element *type ) { 29 std::stack< Entry >& entry = table[ type->get_name() ];30 if ( ! entry.empty() && entry.top().second == scopeLevel ) {31 32 } else {33 34 }44 std::stack< Entry >& entry = table[ type->get_name() ]; 45 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 46 entry.top().first = conflictFunction( entry.top().first, type ); 47 } else { 48 entry.push( Entry( type, scopeLevel ) ); 49 } // if 35 50 } 36 51 37 52 template< typename Element, typename ConflictFunction > 38 53 void StackTable< Element, ConflictFunction >::add( std::string fwdDeclName ) { 39 add( new Element( fwdDeclName ) );54 add( new Element( fwdDeclName ) ); 40 55 } 41 56 42 57 template< typename Element, typename ConflictFunction > 43 58 Element *StackTable< Element, ConflictFunction >::lookup( std::string id ) const { 44 typename TableType::const_iterator it = table.find( id );45 if ( it == table.end() ) {46 47 } else if ( ! it->second.empty() ) {48 49 } else {50 51 }59 typename TableType::const_iterator it = table.find( id ); 60 if ( it == table.end() ) { 61 return 0; 62 } else if ( ! it->second.empty() ) { 63 return it->second.top().first; 64 } else { 65 return 0; 66 } // if 52 67 } 53 68 54 69 template< typename Element, typename ConflictFunction > 55 70 void StackTable< Element, ConflictFunction >::dump( std::ostream &os ) const { 56 for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) {57 58 59 os << it->first << std::endl;60 }61 }71 for ( typename TableType::const_iterator it = table.begin(); it != table.end(); ++it ) { 72 const std::stack< Entry >& entry = it->second; 73 if ( ! entry.empty() && entry.top().second == scopeLevel ) { 74 os << it->first << std::endl; 75 } // if 76 } // for 62 77 } 63 } // SymTab 78 } // namespace SymTab 79 80 // Local Variables: // 81 // tab-width: 4 // 82 // mode: c++ // 83 // compile-command: "make install" // 84 // End: // -
translator/SymTab/StackTable.h
ra32b204 r0dd3a2f 1 #ifndef SYMTAB_STACKTABLE_H 2 #define SYMTAB_STACKTABLE_H 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // StackTable.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:47:10 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:48:15 2015 13 // Update Count : 3 14 // 15 16 #ifndef STACKTABLE_H 17 #define STACKTABLE_H 3 18 4 19 #include <map> … … 11 26 class StackTable { 12 27 public: 13 StackTable();28 StackTable(); 14 29 15 void enterScope();16 void leaveScope();17 void add( Element *type );18 void add( std::string fwdDeclName );19 Element *lookup( std::string id ) const;30 void enterScope(); 31 void leaveScope(); 32 void add( Element *type ); 33 void add( std::string fwdDeclName ); 34 Element *lookup( std::string id ) const; 20 35 21 void dump( std::ostream &os ) const;// debugging36 void dump( std::ostream &os ) const; // debugging 22 37 private: 23 typedef std::pair< Element*, int > Entry;24 typedef std::map< std::string, std::stack< Entry > > TableType;38 typedef std::pair< Element*, int > Entry; 39 typedef std::map< std::string, std::stack< Entry > > TableType; 25 40 26 ConflictFunction conflictFunction;27 TableType table;28 int scopeLevel;41 ConflictFunction conflictFunction; 42 TableType table; 43 int scopeLevel; 29 44 }; 30 45 } // SymTab … … 32 47 #include "StackTable.cc" 33 48 34 #endif // SYMTAB_STACKTABLE_H 49 #endif // STACKTABLE_H 50 51 // Local Variables: // 52 // tab-width: 4 // 53 // mode: c++ // 54 // compile-command: "make install" // 55 // End: // -
translator/SymTab/TypeTable.h
ra32b204 r0dd3a2f 1 #ifndef SYMTAB_TYPETABLE_H 2 #define SYMTAB_TYPETABLE_H 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // TypeTable.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:48:32 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:49:49 2015 13 // Update Count : 2 14 // 15 16 #ifndef TYPETABLE_H 17 #define TYPETABLE_H 3 18 4 19 #include <cassert> … … 14 29 class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > { 15 30 public: 16 NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) {17 18 return added;19 20 return existing;21 22 throw SemanticError( "redeclaration of ", added );23 }24 25 26 }31 NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) { 32 if ( existing->get_base() == 0 ) { 33 return added; 34 } else if ( added->get_base() == 0 ) { 35 return existing; 36 } else { 37 throw SemanticError( "redeclaration of ", added ); 38 } // if 39 assert( false ); 40 return 0; 41 } 27 42 }; 28 43 29 44 typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable; 30 } // SymTab45 } // namespace SymTab 31 46 32 #endif // SYMTAB_TYPETABLE_H 47 #endif // TYPETABLE_H 48 49 // Local Variables: // 50 // tab-width: 4 // 51 // mode: c++ // 52 // compile-command: "make install" // 53 // End: // -
translator/SymTab/Validate.cc
ra32b204 r0dd3a2f 1 /* 2 The "validate" phase of translation is used to take a syntax tree and convert it into a standard form that aims to be 3 as regular in structure as possible. Some assumptions can be made regarding the state of the tree after this pass is 4 complete, including: 5 6 - No nested structure or union definitions; any in the input are "hoisted" to the level of the containing struct or 7 union. 8 9 - All enumeration constants have type EnumInstType. 10 11 - The type "void" never occurs in lists of function parameter or return types; neither do tuple types. A function 12 taking no arguments has no argument types, and tuples are flattened. 13 14 - No context instances exist; they are all replaced by the set of declarations signified by the context, instantiated 15 by the particular set of type arguments. 16 17 - Every declaration is assigned a unique id. 18 19 - No typedef declarations or instances exist; the actual type is substituted for each instance. 20 21 - Each type, struct, and union definition is followed by an appropriate assignment operator. 22 23 - Each use of a struct or union is connected to a complete definition of that struct or union, even if that definition 24 occurs later in the input. 25 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Validate.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 17 21:53:16 2015 13 // Update Count : 2 14 // 15 16 // The "validate" phase of translation is used to take a syntax tree and convert it into a standard form that aims to be 17 // as regular in structure as possible. Some assumptions can be made regarding the state of the tree after this pass is 18 // complete, including: 19 // 20 // - No nested structure or union definitions; any in the input are "hoisted" to the level of the containing struct or 21 // union. 22 // 23 // - All enumeration constants have type EnumInstType. 24 // 25 // - The type "void" never occurs in lists of function parameter or return types; neither do tuple types. A function 26 // taking no arguments has no argument types, and tuples are flattened. 27 // 28 // - No context instances exist; they are all replaced by the set of declarations signified by the context, instantiated 29 // by the particular set of type arguments. 30 // 31 // - Every declaration is assigned a unique id. 32 // 33 // - No typedef declarations or instances exist; the actual type is substituted for each instance. 34 // 35 // - Each type, struct, and union definition is followed by an appropriate assignment operator. 36 // 37 // - Each use of a struct or union is connected to a complete definition of that struct or union, even if that 38 // definition occurs later in the input. 26 39 27 40 #include <list> … … 46 59 class HoistStruct : public Visitor { 47 60 public: 48 static void hoistStruct( std::list< Declaration * > &translationUnit );49 50 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }51 52 virtual void visit( StructDecl *aggregateDecl );53 virtual void visit( UnionDecl *aggregateDecl );54 55 virtual void visit( CompoundStmt *compoundStmt );56 virtual void visit( IfStmt *ifStmt );57 virtual void visit( WhileStmt *whileStmt );58 virtual void visit( ForStmt *forStmt );59 virtual void visit( SwitchStmt *switchStmt );60 virtual void visit( ChooseStmt *chooseStmt );61 virtual void visit( CaseStmt *caseStmt );62 virtual void visit( CatchStmt *catchStmt );61 static void hoistStruct( std::list< Declaration * > &translationUnit ); 62 63 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 64 65 virtual void visit( StructDecl *aggregateDecl ); 66 virtual void visit( UnionDecl *aggregateDecl ); 67 68 virtual void visit( CompoundStmt *compoundStmt ); 69 virtual void visit( IfStmt *ifStmt ); 70 virtual void visit( WhileStmt *whileStmt ); 71 virtual void visit( ForStmt *forStmt ); 72 virtual void visit( SwitchStmt *switchStmt ); 73 virtual void visit( ChooseStmt *chooseStmt ); 74 virtual void visit( CaseStmt *caseStmt ); 75 virtual void visit( CatchStmt *catchStmt ); 63 76 private: 64 HoistStruct();65 66 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );67 68 std::list< Declaration * > declsToAdd;69 bool inStruct;77 HoistStruct(); 78 79 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl ); 80 81 std::list< Declaration * > declsToAdd; 82 bool inStruct; 70 83 }; 71 84 72 85 class Pass1 : public Visitor { 73 typedef Visitor Parent;74 virtual void visit( EnumDecl *aggregateDecl );75 virtual void visit( FunctionType *func );86 typedef Visitor Parent; 87 virtual void visit( EnumDecl *aggregateDecl ); 88 virtual void visit( FunctionType *func ); 76 89 }; 77 90 78 91 class Pass2 : public Indexer { 79 typedef Indexer Parent;92 typedef Indexer Parent; 80 93 public: 81 Pass2( bool doDebug, const Indexer *indexer );94 Pass2( bool doDebug, const Indexer *indexer ); 82 95 private: 83 virtual void visit( StructInstType *structInst );84 virtual void visit( UnionInstType *unionInst );85 virtual void visit( ContextInstType *contextInst );86 virtual void visit( StructDecl *structDecl );87 virtual void visit( UnionDecl *unionDecl );88 virtual void visit( TypeInstType *typeInst );89 90 const Indexer *indexer;91 92 typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;93 typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;94 ForwardStructsType forwardStructs;95 ForwardUnionsType forwardUnions;96 virtual void visit( StructInstType *structInst ); 97 virtual void visit( UnionInstType *unionInst ); 98 virtual void visit( ContextInstType *contextInst ); 99 virtual void visit( StructDecl *structDecl ); 100 virtual void visit( UnionDecl *unionDecl ); 101 virtual void visit( TypeInstType *typeInst ); 102 103 const Indexer *indexer; 104 105 typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType; 106 typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType; 107 ForwardStructsType forwardStructs; 108 ForwardUnionsType forwardUnions; 96 109 }; 97 110 98 111 class Pass3 : public Indexer { 99 typedef Indexer Parent;112 typedef Indexer Parent; 100 113 public: 101 Pass3( const Indexer *indexer );114 Pass3( const Indexer *indexer ); 102 115 private: 103 virtual void visit( ObjectDecl *object );104 virtual void visit( FunctionDecl *func );105 106 const Indexer *indexer;116 virtual void visit( ObjectDecl *object ); 117 virtual void visit( FunctionDecl *func ); 118 119 const Indexer *indexer; 107 120 }; 108 121 109 122 class AddStructAssignment : public Visitor { 110 123 public: 111 static void addStructAssignment( std::list< Declaration * > &translationUnit );112 113 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }114 115 virtual void visit( StructDecl *structDecl );116 virtual void visit( UnionDecl *structDecl );117 virtual void visit( TypeDecl *typeDecl );118 virtual void visit( ContextDecl *ctxDecl );119 virtual void visit( FunctionDecl *functionDecl );120 121 virtual void visit( FunctionType *ftype );122 virtual void visit( PointerType *ftype );123 124 virtual void visit( CompoundStmt *compoundStmt );125 virtual void visit( IfStmt *ifStmt );126 virtual void visit( WhileStmt *whileStmt );127 virtual void visit( ForStmt *forStmt );128 virtual void visit( SwitchStmt *switchStmt );129 virtual void visit( ChooseStmt *chooseStmt );130 virtual void visit( CaseStmt *caseStmt );131 virtual void visit( CatchStmt *catchStmt );132 133 AddStructAssignment() : functionNesting( 0 ) {}124 static void addStructAssignment( std::list< Declaration * > &translationUnit ); 125 126 std::list< Declaration * > &get_declsToAdd() { return declsToAdd; } 127 128 virtual void visit( StructDecl *structDecl ); 129 virtual void visit( UnionDecl *structDecl ); 130 virtual void visit( TypeDecl *typeDecl ); 131 virtual void visit( ContextDecl *ctxDecl ); 132 virtual void visit( FunctionDecl *functionDecl ); 133 134 virtual void visit( FunctionType *ftype ); 135 virtual void visit( PointerType *ftype ); 136 137 virtual void visit( CompoundStmt *compoundStmt ); 138 virtual void visit( IfStmt *ifStmt ); 139 virtual void visit( WhileStmt *whileStmt ); 140 virtual void visit( ForStmt *forStmt ); 141 virtual void visit( SwitchStmt *switchStmt ); 142 virtual void visit( ChooseStmt *chooseStmt ); 143 virtual void visit( CaseStmt *caseStmt ); 144 virtual void visit( CatchStmt *catchStmt ); 145 146 AddStructAssignment() : functionNesting( 0 ) {} 134 147 private: 135 template< typename StmtClass > void visitStatement( StmtClass *stmt );136 137 std::list< Declaration * > declsToAdd;138 std::set< std::string > structsDone;139 unsigned int functionNesting; // current level of nested functions148 template< typename StmtClass > void visitStatement( StmtClass *stmt ); 149 150 std::list< Declaration * > declsToAdd; 151 std::set< std::string > structsDone; 152 unsigned int functionNesting; // current level of nested functions 140 153 }; 141 154 142 155 class EliminateTypedef : public Mutator { 143 156 public: 144 static void eliminateTypedef( std::list< Declaration * > &translationUnit );157 static void eliminateTypedef( std::list< Declaration * > &translationUnit ); 145 158 private: 146 virtual Declaration *mutate( TypedefDecl *typeDecl );147 virtual TypeDecl *mutate( TypeDecl *typeDecl );148 virtual DeclarationWithType *mutate( FunctionDecl *funcDecl );149 virtual ObjectDecl *mutate( ObjectDecl *objDecl );150 virtual CompoundStmt *mutate( CompoundStmt *compoundStmt );151 virtual Type *mutate( TypeInstType *aggregateUseType );152 virtual Expression *mutate( CastExpr *castExpr );153 154 std::map< std::string, TypedefDecl * > typedefNames;159 virtual Declaration *mutate( TypedefDecl *typeDecl ); 160 virtual TypeDecl *mutate( TypeDecl *typeDecl ); 161 virtual DeclarationWithType *mutate( FunctionDecl *funcDecl ); 162 virtual ObjectDecl *mutate( ObjectDecl *objDecl ); 163 virtual CompoundStmt *mutate( CompoundStmt *compoundStmt ); 164 virtual Type *mutate( TypeInstType *aggregateUseType ); 165 virtual Expression *mutate( CastExpr *castExpr ); 166 167 std::map< std::string, TypedefDecl * > typedefNames; 155 168 }; 156 169 157 170 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 158 Pass1 pass1;159 Pass2 pass2( doDebug, 0 );160 Pass3 pass3( 0 );161 EliminateTypedef::eliminateTypedef( translationUnit );162 HoistStruct::hoistStruct( translationUnit );163 acceptAll( translationUnit, pass1 );164 acceptAll( translationUnit, pass2 );165 AddStructAssignment::addStructAssignment( translationUnit );166 acceptAll( translationUnit, pass3 );171 Pass1 pass1; 172 Pass2 pass2( doDebug, 0 ); 173 Pass3 pass3( 0 ); 174 EliminateTypedef::eliminateTypedef( translationUnit ); 175 HoistStruct::hoistStruct( translationUnit ); 176 acceptAll( translationUnit, pass1 ); 177 acceptAll( translationUnit, pass2 ); 178 AddStructAssignment::addStructAssignment( translationUnit ); 179 acceptAll( translationUnit, pass3 ); 167 180 } 168 181 169 182 void validateType( Type *type, const Indexer *indexer ) { 170 Pass1 pass1;171 Pass2 pass2( false, indexer );172 Pass3 pass3( indexer );173 type->accept( pass1 );174 type->accept( pass2 );175 type->accept( pass3 );183 Pass1 pass1; 184 Pass2 pass2( false, indexer ); 185 Pass3 pass3( indexer ); 186 type->accept( pass1 ); 187 type->accept( pass2 ); 188 type->accept( pass3 ); 176 189 } 177 190 178 191 template< typename Visitor > 179 192 void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) { 180 std::list< Declaration * >::iterator i = translationUnit.begin();181 while ( i != translationUnit.end() ) {182 183 184 185 186 translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );187 188 189 } // while193 std::list< Declaration * >::iterator i = translationUnit.begin(); 194 while ( i != translationUnit.end() ) { 195 (*i)->accept( visitor ); 196 std::list< Declaration * >::iterator next = i; 197 next++; 198 if ( ! visitor.get_declsToAdd().empty() ) { 199 translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() ); 200 } // if 201 i = next; 202 } // while 190 203 } 191 204 192 205 void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) { 193 HoistStruct hoister;194 acceptAndAdd( translationUnit, hoister, true );206 HoistStruct hoister; 207 acceptAndAdd( translationUnit, hoister, true ); 195 208 } 196 209 … … 199 212 200 213 void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) { 201 std::list< Declaration * >::iterator i = declList.begin();202 while ( i != declList.end() ) {203 204 205 206 if ( doDelete ) {207 208 } // if209 declList.erase( i );210 211 212 } // while214 std::list< Declaration * >::iterator i = declList.begin(); 215 while ( i != declList.end() ) { 216 std::list< Declaration * >::iterator next = i; 217 ++next; 218 if ( pred( *i ) ) { 219 if ( doDelete ) { 220 delete *i; 221 } // if 222 declList.erase( i ); 223 } // if 224 i = next; 225 } // while 213 226 } 214 227 215 228 bool isStructOrUnion( Declaration *decl ) { 216 return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );229 return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl ); 217 230 } 218 231 219 232 template< typename AggDecl > 220 233 void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) { 221 if ( inStruct ) {222 223 224 225 } else {226 227 228 229 } // if230 // Always remove the hoisted aggregate from the inner structure.231 filter( aggregateDecl->get_members(), isStructOrUnion, false );234 if ( inStruct ) { 235 // Add elements in stack order corresponding to nesting structure. 236 declsToAdd.push_front( aggregateDecl ); 237 Visitor::visit( aggregateDecl ); 238 } else { 239 inStruct = true; 240 Visitor::visit( aggregateDecl ); 241 inStruct = false; 242 } // if 243 // Always remove the hoisted aggregate from the inner structure. 244 filter( aggregateDecl->get_members(), isStructOrUnion, false ); 232 245 } 233 246 234 247 void HoistStruct::visit( StructDecl *aggregateDecl ) { 235 handleAggregate( aggregateDecl );248 handleAggregate( aggregateDecl ); 236 249 } 237 250 238 251 void HoistStruct::visit( UnionDecl *aggregateDecl ) { 239 handleAggregate( aggregateDecl );252 handleAggregate( aggregateDecl ); 240 253 } 241 254 242 255 void HoistStruct::visit( CompoundStmt *compoundStmt ) { 243 addVisit( compoundStmt, *this );256 addVisit( compoundStmt, *this ); 244 257 } 245 258 246 259 void HoistStruct::visit( IfStmt *ifStmt ) { 247 addVisit( ifStmt, *this );260 addVisit( ifStmt, *this ); 248 261 } 249 262 250 263 void HoistStruct::visit( WhileStmt *whileStmt ) { 251 addVisit( whileStmt, *this );264 addVisit( whileStmt, *this ); 252 265 } 253 266 254 267 void HoistStruct::visit( ForStmt *forStmt ) { 255 addVisit( forStmt, *this );268 addVisit( forStmt, *this ); 256 269 } 257 270 258 271 void HoistStruct::visit( SwitchStmt *switchStmt ) { 259 addVisit( switchStmt, *this );272 addVisit( switchStmt, *this ); 260 273 } 261 274 262 275 void HoistStruct::visit( ChooseStmt *switchStmt ) { 263 addVisit( switchStmt, *this );276 addVisit( switchStmt, *this ); 264 277 } 265 278 266 279 void HoistStruct::visit( CaseStmt *caseStmt ) { 267 addVisit( caseStmt, *this );280 addVisit( caseStmt, *this ); 268 281 } 269 282 270 283 void HoistStruct::visit( CatchStmt *cathStmt ) { 271 addVisit( cathStmt, *this );284 addVisit( cathStmt, *this ); 272 285 } 273 286 274 287 void Pass1::visit( EnumDecl *enumDecl ) { 275 // Set the type of each member of the enumeration to be EnumConstant276 277 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {278 279 280 281 } // for282 Parent::visit( enumDecl );288 // Set the type of each member of the enumeration to be EnumConstant 289 290 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) { 291 ObjectDecl *obj = dynamic_cast< ObjectDecl * >( *i ); 292 assert( obj ); 293 obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false, false ), enumDecl->get_name() ) ); 294 } // for 295 Parent::visit( enumDecl ); 283 296 } 284 297 285 298 namespace { 286 template< typename DWTIterator > 287 void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) { 288 // the only case in which "void" is valid is where it is the only one in the list; then 289 // it should be removed entirely 290 // other fix ups are handled by the FixFunction class 291 if ( begin == end ) return; 292 FixFunction fixer; 293 DWTIterator i = begin; 294 *i = (*i )->acceptMutator( fixer ); 295 if ( fixer.get_isVoid() ) { 296 DWTIterator j = i; 297 ++i; 298 func->get_parameters().erase( j ); 299 if ( i != end ) { 300 throw SemanticError( "invalid type void in function type ", func ); 301 } // if 302 } else { 303 ++i; 304 for ( ; i != end; ++i ) { 305 FixFunction fixer; 306 *i = (*i )->acceptMutator( fixer ); 307 if ( fixer.get_isVoid() ) { 308 throw SemanticError( "invalid type void in function type ", func ); 309 } // if 299 template< typename DWTIterator > 300 void fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) { 301 // the only case in which "void" is valid is where it is the only one in the list; then it should be removed 302 // entirely other fix ups are handled by the FixFunction class 303 if ( begin == end ) return; 304 FixFunction fixer; 305 DWTIterator i = begin; 306 *i = (*i )->acceptMutator( fixer ); 307 if ( fixer.get_isVoid() ) { 308 DWTIterator j = i; 309 ++i; 310 func->get_parameters().erase( j ); 311 if ( i != end ) { 312 throw SemanticError( "invalid type void in function type ", func ); 313 } // if 314 } else { 315 ++i; 316 for ( ; i != end; ++i ) { 317 FixFunction fixer; 318 *i = (*i )->acceptMutator( fixer ); 319 if ( fixer.get_isVoid() ) { 320 throw SemanticError( "invalid type void in function type ", func ); 321 } // if 322 } // for 323 } // if 324 } 325 } 326 327 void Pass1::visit( FunctionType *func ) { 328 // Fix up parameters and return types 329 fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func ); 330 fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func ); 331 Visitor::visit( func ); 332 } 333 334 Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) { 335 if ( other_indexer ) { 336 indexer = other_indexer; 337 } else { 338 indexer = this; 339 } // if 340 } 341 342 void Pass2::visit( StructInstType *structInst ) { 343 Parent::visit( structInst ); 344 StructDecl *st = indexer->lookupStruct( structInst->get_name() ); 345 // it's not a semantic error if the struct is not found, just an implicit forward declaration 346 if ( st ) { 347 assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() ); 348 structInst->set_baseStruct( st ); 349 } // if 350 if ( ! st || st->get_members().empty() ) { 351 // use of forward declaration 352 forwardStructs[ structInst->get_name() ].push_back( structInst ); 353 } // if 354 } 355 356 void Pass2::visit( UnionInstType *unionInst ) { 357 Parent::visit( unionInst ); 358 UnionDecl *un = indexer->lookupUnion( unionInst->get_name() ); 359 // it's not a semantic error if the union is not found, just an implicit forward declaration 360 if ( un ) { 361 unionInst->set_baseUnion( un ); 362 } // if 363 if ( ! un || un->get_members().empty() ) { 364 // use of forward declaration 365 forwardUnions[ unionInst->get_name() ].push_back( unionInst ); 366 } // if 367 } 368 369 void Pass2::visit( ContextInstType *contextInst ) { 370 Parent::visit( contextInst ); 371 ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() ); 372 if ( ! ctx ) { 373 throw SemanticError( "use of undeclared context " + contextInst->get_name() ); 374 } // if 375 for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) { 376 for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) { 377 if ( ContextInstType *otherCtx = dynamic_cast< ContextInstType * >(*assert ) ) { 378 cloneAll( otherCtx->get_members(), contextInst->get_members() ); 379 } else { 380 contextInst->get_members().push_back( (*assert )->clone() ); 381 } // if 382 } // for 310 383 } // for 311 } // if 312 } 313 } 314 315 void Pass1::visit( FunctionType *func ) { 316 // Fix up parameters and return types 317 fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func ); 318 fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func ); 319 Visitor::visit( func ); 320 } 321 322 Pass2::Pass2( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) { 323 if ( other_indexer ) { 324 indexer = other_indexer; 325 } else { 326 indexer = this; 327 } // if 328 } 329 330 void Pass2::visit( StructInstType *structInst ) { 331 Parent::visit( structInst ); 332 StructDecl *st = indexer->lookupStruct( structInst->get_name() ); 333 // it's not a semantic error if the struct is not found, just an implicit forward declaration 334 if ( st ) { 335 assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() ); 336 structInst->set_baseStruct( st ); 337 } // if 338 if ( ! st || st->get_members().empty() ) { 339 // use of forward declaration 340 forwardStructs[ structInst->get_name() ].push_back( structInst ); 341 } // if 342 } 343 344 void Pass2::visit( UnionInstType *unionInst ) { 345 Parent::visit( unionInst ); 346 UnionDecl *un = indexer->lookupUnion( unionInst->get_name() ); 347 // it's not a semantic error if the union is not found, just an implicit forward declaration 348 if ( un ) { 349 unionInst->set_baseUnion( un ); 350 } // if 351 if ( ! un || un->get_members().empty() ) { 352 // use of forward declaration 353 forwardUnions[ unionInst->get_name() ].push_back( unionInst ); 354 } // if 355 } 356 357 void Pass2::visit( ContextInstType *contextInst ) { 358 Parent::visit( contextInst ); 359 ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() ); 360 if ( ! ctx ) { 361 throw SemanticError( "use of undeclared context " + contextInst->get_name() ); 362 } // if 363 for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) { 364 for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) { 365 if ( ContextInstType *otherCtx = dynamic_cast< ContextInstType * >(*assert ) ) { 366 cloneAll( otherCtx->get_members(), contextInst->get_members() ); 384 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) ); 385 } 386 387 void Pass2::visit( StructDecl *structDecl ) { 388 if ( ! structDecl->get_members().empty() ) { 389 ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() ); 390 if ( fwds != forwardStructs.end() ) { 391 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) { 392 (*inst )->set_baseStruct( structDecl ); 393 } // for 394 forwardStructs.erase( fwds ); 395 } // if 396 } // if 397 Indexer::visit( structDecl ); 398 } 399 400 void Pass2::visit( UnionDecl *unionDecl ) { 401 if ( ! unionDecl->get_members().empty() ) { 402 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() ); 403 if ( fwds != forwardUnions.end() ) { 404 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) { 405 (*inst )->set_baseUnion( unionDecl ); 406 } // for 407 forwardUnions.erase( fwds ); 408 } // if 409 } // if 410 Indexer::visit( unionDecl ); 411 } 412 413 void Pass2::visit( TypeInstType *typeInst ) { 414 if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) { 415 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) { 416 typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype ); 417 } // if 418 } // if 419 } 420 421 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) { 422 if ( other_indexer ) { 423 indexer = other_indexer; 367 424 } else { 368 contextInst->get_members().push_back( (*assert )->clone() ); 369 } // if 370 } // for 371 } // for 372 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) ); 373 } 374 375 void Pass2::visit( StructDecl *structDecl ) { 376 if ( ! structDecl->get_members().empty() ) { 377 ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() ); 378 if ( fwds != forwardStructs.end() ) { 379 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) { 380 (*inst )->set_baseStruct( structDecl ); 425 indexer = this; 426 } // if 427 } 428 429 void forallFixer( Type *func ) { 430 // Fix up assertions 431 for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) { 432 std::list< DeclarationWithType * > toBeDone, nextRound; 433 toBeDone.splice( toBeDone.end(), (*type )->get_assertions() ); 434 while ( ! toBeDone.empty() ) { 435 for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) { 436 if ( ContextInstType *ctx = dynamic_cast< ContextInstType * >( (*assertion )->get_type() ) ) { 437 for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) { 438 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i ); 439 assert( dwt ); 440 nextRound.push_back( dwt->clone() ); 441 } 442 delete ctx; 443 } else { 444 FixFunction fixer; 445 *assertion = (*assertion )->acceptMutator( fixer ); 446 if ( fixer.get_isVoid() ) { 447 throw SemanticError( "invalid type void in assertion of function ", func ); 448 } 449 (*type )->get_assertions().push_back( *assertion ); 450 } // if 451 } // for 452 toBeDone.clear(); 453 toBeDone.splice( toBeDone.end(), nextRound ); 454 } // while 381 455 } // for 382 forwardStructs.erase( fwds );383 } // if384 } // if385 Indexer::visit( structDecl );386 }387 388 void Pass2::visit( UnionDecl *unionDecl ) {389 if ( ! unionDecl->get_members().empty() ) {390 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );391 if ( fwds != forwardUnions.end() ) {392 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {393 (*inst )->set_baseUnion( unionDecl );394 } // for395 forwardUnions.erase( fwds );396 } // if397 } // if398 Indexer::visit( unionDecl );399 }400 401 void Pass2::visit( TypeInstType *typeInst ) {402 if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) {403 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {404 typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );405 } // if406 } // if407 }408 409 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) {410 if ( other_indexer ) {411 indexer = other_indexer;412 } else {413 indexer = this;414 } // if415 }416 417 void forallFixer( Type *func ) {418 // Fix up assertions419 for ( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {420 std::list< DeclarationWithType * > toBeDone, nextRound;421 toBeDone.splice( toBeDone.end(), (*type )->get_assertions() );422 while ( ! toBeDone.empty() ) {423 for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {424 if ( ContextInstType *ctx = dynamic_cast< ContextInstType * >( (*assertion )->get_type() ) ) {425 for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {426 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i );427 assert( dwt );428 nextRound.push_back( dwt->clone() );429 }430 delete ctx;431 } else {432 FixFunction fixer;433 *assertion = (*assertion )->acceptMutator( fixer );434 if ( fixer.get_isVoid() ) {435 throw SemanticError( "invalid type void in assertion of function ", func );436 }437 (*type )->get_assertions().push_back( *assertion );438 }439 }440 toBeDone.clear();441 toBeDone.splice( toBeDone.end(), nextRound );442 }443 }444 456 } 445 457 446 458 void Pass3::visit( ObjectDecl *object ) { 447 forallFixer( object->get_type() );448 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {449 450 } // if451 Parent::visit( object );452 object->fixUniqueId();459 forallFixer( object->get_type() ); 460 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { 461 forallFixer( pointer->get_base() ); 462 } // if 463 Parent::visit( object ); 464 object->fixUniqueId(); 453 465 } 454 466 455 467 void Pass3::visit( FunctionDecl *func ) { 456 forallFixer( func->get_type() );457 Parent::visit( func );458 func->fixUniqueId();468 forallFixer( func->get_type() ); 469 Parent::visit( func ); 470 func->fixUniqueId(); 459 471 } 460 472 … … 462 474 463 475 void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) { 464 AddStructAssignment visitor;465 acceptAndAdd( translationUnit, visitor, false );476 AddStructAssignment visitor; 477 acceptAndAdd( translationUnit, visitor, false ); 466 478 } 467 479 468 480 template< typename OutputIterator > 469 481 void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) { 470 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member );471 // unnamed bit fields are not copied as they cannot be accessed472 if ( obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL ) return;473 474 UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );475 476 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );477 derefExpr->get_args().push_back( new VariableExpr( dstParam ) );478 479 // do something special for unnamed members480 Expression *dstselect = new AddressExpr( new MemberExpr( member, derefExpr ) );481 assignExpr->get_args().push_back( dstselect );482 483 Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );484 assignExpr->get_args().push_back( srcselect );485 486 *out++ = new ExprStmt( noLabels, assignExpr );482 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member ); 483 // unnamed bit fields are not copied as they cannot be accessed 484 if ( obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL ) return; 485 486 UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) ); 487 488 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) ); 489 derefExpr->get_args().push_back( new VariableExpr( dstParam ) ); 490 491 // do something special for unnamed members 492 Expression *dstselect = new AddressExpr( new MemberExpr( member, derefExpr ) ); 493 assignExpr->get_args().push_back( dstselect ); 494 495 Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) ); 496 assignExpr->get_args().push_back( srcselect ); 497 498 *out++ = new ExprStmt( noLabels, assignExpr ); 487 499 } 488 500 489 501 template< typename OutputIterator > 490 502 void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) { 491 static UniqueName indexName( "_index" );492 493 // for a flexible array member nothing is done -- user must define own assignment494 if ( ! array->get_dimension() ) return;495 496 ObjectDecl *index = new ObjectDecl( indexName.newName(), Declaration::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 );497 *out++ = new DeclStmt( noLabels, index );498 499 UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) );500 init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );501 init->get_args().push_back( new NameExpr( "0" ) );502 Statement *initStmt = new ExprStmt( noLabels, init );503 504 UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );505 cond->get_args().push_back( new VariableExpr( index ) );506 cond->get_args().push_back( array->get_dimension()->clone() );507 508 UntypedExpr *inc = new UntypedExpr( new NameExpr( "++?" ) );509 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );510 511 UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );512 513 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );514 derefExpr->get_args().push_back( new VariableExpr( dstParam ) );515 516 Expression *dstselect = new MemberExpr( member, derefExpr );517 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?+?" ) );518 dstIndex->get_args().push_back( dstselect );519 dstIndex->get_args().push_back( new VariableExpr( index ) );520 assignExpr->get_args().push_back( dstIndex );521 522 Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );523 UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );524 srcIndex->get_args().push_back( srcselect );525 srcIndex->get_args().push_back( new VariableExpr( index ) );526 assignExpr->get_args().push_back( srcIndex );527 528 *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );503 static UniqueName indexName( "_index" ); 504 505 // for a flexible array member nothing is done -- user must define own assignment 506 if ( ! array->get_dimension() ) return; 507 508 ObjectDecl *index = new ObjectDecl( indexName.newName(), Declaration::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ); 509 *out++ = new DeclStmt( noLabels, index ); 510 511 UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) ); 512 init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 513 init->get_args().push_back( new NameExpr( "0" ) ); 514 Statement *initStmt = new ExprStmt( noLabels, init ); 515 516 UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) ); 517 cond->get_args().push_back( new VariableExpr( index ) ); 518 cond->get_args().push_back( array->get_dimension()->clone() ); 519 520 UntypedExpr *inc = new UntypedExpr( new NameExpr( "++?" ) ); 521 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 522 523 UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) ); 524 525 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) ); 526 derefExpr->get_args().push_back( new VariableExpr( dstParam ) ); 527 528 Expression *dstselect = new MemberExpr( member, derefExpr ); 529 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?+?" ) ); 530 dstIndex->get_args().push_back( dstselect ); 531 dstIndex->get_args().push_back( new VariableExpr( index ) ); 532 assignExpr->get_args().push_back( dstIndex ); 533 534 Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) ); 535 UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) ); 536 srcIndex->get_args().push_back( srcselect ); 537 srcIndex->get_args().push_back( new VariableExpr( index ) ); 538 assignExpr->get_args().push_back( srcIndex ); 539 540 *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) ); 529 541 } 530 542 531 543 Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) { 532 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );533 534 ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );535 assignType->get_returnVals().push_back( returnVal );536 537 ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );538 assignType->get_parameters().push_back( dstParam );539 540 ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );541 assignType->get_parameters().push_back( srcParam );542 543 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units544 // because each unit generates copies of the default routines for each aggregate.545 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );546 assignDecl->fixUniqueId();547 548 for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {549 550 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {551 552 } else {553 554 } // if555 556 } // for557 assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );558 559 return assignDecl;544 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 545 546 ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 547 assignType->get_returnVals().push_back( returnVal ); 548 549 ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 ); 550 assignType->get_parameters().push_back( dstParam ); 551 552 ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 ); 553 assignType->get_parameters().push_back( srcParam ); 554 555 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 556 // because each unit generates copies of the default routines for each aggregate. 557 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 558 assignDecl->fixUniqueId(); 559 560 for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) { 561 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) { 562 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 563 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); 564 } else { 565 makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) ); 566 } // if 567 } // if 568 } // for 569 assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 570 571 return assignDecl; 560 572 } 561 573 562 574 Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) { 563 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );564 565 ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );566 assignType->get_returnVals().push_back( returnVal );567 568 ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );569 assignType->get_parameters().push_back( dstParam );570 571 ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );572 assignType->get_parameters().push_back( srcParam );573 574 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units575 // because each unit generates copies of the default routines for each aggregate.576 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );577 assignDecl->fixUniqueId();578 579 UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) );580 copy->get_args().push_back( new VariableExpr( dstParam ) );581 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );582 copy->get_args().push_back( new SizeofExpr( refType->clone() ) );583 584 assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );585 assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );586 587 return assignDecl;575 FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); 576 577 ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 ); 578 assignType->get_returnVals().push_back( returnVal ); 579 580 ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 ); 581 assignType->get_parameters().push_back( dstParam ); 582 583 ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 ); 584 assignType->get_parameters().push_back( srcParam ); 585 586 // Routines at global scope marked "static" to prevent multiple definitions is separate translation units 587 // because each unit generates copies of the default routines for each aggregate. 588 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true ); 589 assignDecl->fixUniqueId(); 590 591 UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) ); 592 copy->get_args().push_back( new VariableExpr( dstParam ) ); 593 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 594 copy->get_args().push_back( new SizeofExpr( refType->clone() ) ); 595 596 assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) ); 597 assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 598 599 return assignDecl; 588 600 } 589 601 590 602 void AddStructAssignment::visit( StructDecl *structDecl ) { 591 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {592 593 594 595 596 } // if603 if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) { 604 StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() ); 605 structInst->set_baseStruct( structDecl ); 606 declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) ); 607 structsDone.insert( structDecl->get_name() ); 608 } // if 597 609 } 598 610 599 611 void AddStructAssignment::visit( UnionDecl *unionDecl ) { 600 if ( ! unionDecl->get_members().empty() ) {601 602 603 604 } // if612 if ( ! unionDecl->get_members().empty() ) { 613 UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() ); 614 unionInst->set_baseUnion( unionDecl ); 615 declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) ); 616 } // if 605 617 } 606 618 607 619 void AddStructAssignment::visit( TypeDecl *typeDecl ) { 608 CompoundStmt *stmts = 0;609 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );610 typeInst->set_baseType( typeDecl );611 ObjectDecl *src = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst->clone(), 0 );612 ObjectDecl *dst = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), typeInst->clone() ), 0 );613 if ( typeDecl->get_base() ) {614 615 616 617 618 619 } // if620 FunctionType *type = new FunctionType( Type::Qualifiers(), false );621 type->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) );622 type->get_parameters().push_back( dst );623 type->get_parameters().push_back( src );624 FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false );625 declsToAdd.push_back( func );620 CompoundStmt *stmts = 0; 621 TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false ); 622 typeInst->set_baseType( typeDecl ); 623 ObjectDecl *src = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst->clone(), 0 ); 624 ObjectDecl *dst = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), typeInst->clone() ), 0 ); 625 if ( typeDecl->get_base() ) { 626 stmts = new CompoundStmt( std::list< Label >() ); 627 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 628 assign->get_args().push_back( new CastExpr( new VariableExpr( dst ), new PointerType( Type::Qualifiers(), typeDecl->get_base()->clone() ) ) ); 629 assign->get_args().push_back( new CastExpr( new VariableExpr( src ), typeDecl->get_base()->clone() ) ); 630 stmts->get_kids().push_back( new ReturnStmt( std::list< Label >(), assign ) ); 631 } // if 632 FunctionType *type = new FunctionType( Type::Qualifiers(), false ); 633 type->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) ); 634 type->get_parameters().push_back( dst ); 635 type->get_parameters().push_back( src ); 636 FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false ); 637 declsToAdd.push_back( func ); 626 638 } 627 639 628 640 void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) { 629 if ( ! declsToAdd.empty() ) {630 631 statements.insert( i, new DeclStmt( noLabels, *decl ) );632 633 634 } // if641 if ( ! declsToAdd.empty() ) { 642 for ( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) { 643 statements.insert( i, new DeclStmt( noLabels, *decl ) ); 644 } // for 645 declsToAdd.clear(); 646 } // if 635 647 } 636 648 637 649 void AddStructAssignment::visit( FunctionType *) { 638 // ensure that we don't add assignment ops for types defined as part of the function650 // ensure that we don't add assignment ops for types defined as part of the function 639 651 } 640 652 641 653 void AddStructAssignment::visit( PointerType *) { 642 // ensure that we don't add assignment ops for types defined as part of the pointer654 // ensure that we don't add assignment ops for types defined as part of the pointer 643 655 } 644 656 645 657 void AddStructAssignment::visit( ContextDecl *) { 646 // ensure that we don't add assignment ops for types defined as part of the context658 // ensure that we don't add assignment ops for types defined as part of the context 647 659 } 648 660 649 661 template< typename StmtClass > 650 662 inline void AddStructAssignment::visitStatement( StmtClass *stmt ) { 651 std::set< std::string > oldStructs = structsDone;652 addVisit( stmt, *this );653 structsDone = oldStructs;663 std::set< std::string > oldStructs = structsDone; 664 addVisit( stmt, *this ); 665 structsDone = oldStructs; 654 666 } 655 667 656 668 void AddStructAssignment::visit( FunctionDecl *functionDecl ) { 657 maybeAccept( functionDecl->get_functionType(), *this );658 acceptAll( functionDecl->get_oldDecls(), *this );659 functionNesting += 1;660 maybeAccept( functionDecl->get_statements(), *this );661 functionNesting -= 1;669 maybeAccept( functionDecl->get_functionType(), *this ); 670 acceptAll( functionDecl->get_oldDecls(), *this ); 671 functionNesting += 1; 672 maybeAccept( functionDecl->get_statements(), *this ); 673 functionNesting -= 1; 662 674 } 663 675 664 676 void AddStructAssignment::visit( CompoundStmt *compoundStmt ) { 665 visitStatement( compoundStmt );677 visitStatement( compoundStmt ); 666 678 } 667 679 668 680 void AddStructAssignment::visit( IfStmt *ifStmt ) { 669 visitStatement( ifStmt );681 visitStatement( ifStmt ); 670 682 } 671 683 672 684 void AddStructAssignment::visit( WhileStmt *whileStmt ) { 673 visitStatement( whileStmt );685 visitStatement( whileStmt ); 674 686 } 675 687 676 688 void AddStructAssignment::visit( ForStmt *forStmt ) { 677 visitStatement( forStmt );689 visitStatement( forStmt ); 678 690 } 679 691 680 692 void AddStructAssignment::visit( SwitchStmt *switchStmt ) { 681 visitStatement( switchStmt );693 visitStatement( switchStmt ); 682 694 } 683 695 684 696 void AddStructAssignment::visit( ChooseStmt *switchStmt ) { 685 visitStatement( switchStmt );697 visitStatement( switchStmt ); 686 698 } 687 699 688 700 void AddStructAssignment::visit( CaseStmt *caseStmt ) { 689 visitStatement( caseStmt );701 visitStatement( caseStmt ); 690 702 } 691 703 692 704 void AddStructAssignment::visit( CatchStmt *cathStmt ) { 693 visitStatement( cathStmt );705 visitStatement( cathStmt ); 694 706 } 695 707 696 708 bool isTypedef( Declaration *decl ) { 697 return dynamic_cast< TypedefDecl * >( decl );709 return dynamic_cast< TypedefDecl * >( decl ); 698 710 } 699 711 700 712 void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) { 701 EliminateTypedef eliminator;702 mutateAll( translationUnit, eliminator );703 filter( translationUnit, isTypedef, true );713 EliminateTypedef eliminator; 714 mutateAll( translationUnit, eliminator ); 715 filter( translationUnit, isTypedef, true ); 704 716 } 705 717 706 718 Type *EliminateTypedef::mutate( TypeInstType *typeInst ) { 707 std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() );708 if ( def != typedefNames.end() ) {709 710 711 712 713 } // if714 return typeInst;719 std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() ); 720 if ( def != typedefNames.end() ) { 721 Type *ret = def->second->get_base()->clone(); 722 ret->get_qualifiers() += typeInst->get_qualifiers(); 723 delete typeInst; 724 return ret; 725 } // if 726 return typeInst; 715 727 } 716 728 717 729 Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) { 718 Declaration *ret = Mutator::mutate( tyDecl );719 typedefNames[ tyDecl->get_name() ] = tyDecl;720 // When a typedef is a forward declaration:721 // typedef struct screen SCREEN;722 // the declaration portion must be retained:723 // struct screen;724 // because the expansion of the typedef is:725 // void rtn( SCREEN *p ) => void rtn( struct screen *p )726 // hence the type-name "screen" must be defined.727 // Note, qualifiers on the typedef are superfluous for the forward declaration.728 if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( tyDecl->get_base() ) ) {729 730 } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( tyDecl->get_base() ) ) {731 732 } else {733 734 } // if730 Declaration *ret = Mutator::mutate( tyDecl ); 731 typedefNames[ tyDecl->get_name() ] = tyDecl; 732 // When a typedef is a forward declaration: 733 // typedef struct screen SCREEN; 734 // the declaration portion must be retained: 735 // struct screen; 736 // because the expansion of the typedef is: 737 // void rtn( SCREEN *p ) => void rtn( struct screen *p ) 738 // hence the type-name "screen" must be defined. 739 // Note, qualifiers on the typedef are superfluous for the forward declaration. 740 if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( tyDecl->get_base() ) ) { 741 return new StructDecl( aggDecl->get_name() ); 742 } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( tyDecl->get_base() ) ) { 743 return new UnionDecl( aggDecl->get_name() ); 744 } else { 745 return ret; 746 } // if 735 747 } 736 748 737 749 TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) { 738 std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() );739 if ( i != typedefNames.end() ) {740 741 } // if742 return typeDecl;750 std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() ); 751 if ( i != typedefNames.end() ) { 752 typedefNames.erase( i ) ; 753 } // if 754 return typeDecl; 743 755 } 744 756 745 757 DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) { 746 std::map< std::string, TypedefDecl * > oldNames = typedefNames;747 DeclarationWithType *ret = Mutator::mutate( funcDecl );748 typedefNames = oldNames;749 return ret;758 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 759 DeclarationWithType *ret = Mutator::mutate( funcDecl ); 760 typedefNames = oldNames; 761 return ret; 750 762 } 751 763 752 764 ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) { 753 std::map< std::string, TypedefDecl * > oldNames = typedefNames;754 ObjectDecl *ret = Mutator::mutate( objDecl );755 typedefNames = oldNames;756 return ret;765 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 766 ObjectDecl *ret = Mutator::mutate( objDecl ); 767 typedefNames = oldNames; 768 return ret; 757 769 } 758 770 759 771 Expression *EliminateTypedef::mutate( CastExpr *castExpr ) { 760 std::map< std::string, TypedefDecl * > oldNames = typedefNames;761 Expression *ret = Mutator::mutate( castExpr );762 typedefNames = oldNames;763 return ret;772 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 773 Expression *ret = Mutator::mutate( castExpr ); 774 typedefNames = oldNames; 775 return ret; 764 776 } 765 777 766 778 CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) { 767 std::map< std::string, TypedefDecl * > oldNames = typedefNames;768 CompoundStmt *ret = Mutator::mutate( compoundStmt );769 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();770 while ( i != compoundStmt->get_kids().end() ) {771 772 773 774 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {775 776 777 } // if778 779 780 } // while781 typedefNames = oldNames;782 return ret;779 std::map< std::string, TypedefDecl * > oldNames = typedefNames; 780 CompoundStmt *ret = Mutator::mutate( compoundStmt ); 781 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 782 while ( i != compoundStmt->get_kids().end() ) { 783 std::list< Statement * >::iterator next = i; 784 ++next; 785 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) { 786 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) { 787 delete *i; 788 compoundStmt->get_kids().erase( i ); 789 } // if 790 } // if 791 i = next; 792 } // while 793 typedefNames = oldNames; 794 return ret; 783 795 } 784 796 } // namespace SymTab 797 798 // Local Variables: // 799 // tab-width: 4 // 800 // mode: c++ // 801 // compile-command: "make install" // 802 // End: // -
translator/SymTab/Validate.h
ra32b204 r0dd3a2f 1 // This class is intended to perform pre-processing of declarations, validating their 2 // correctness and computing some auxilliary data that is necessary for the indexer. 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Validate.h -- This class is intended to perform pre-processing of declarations, validating their correctness and 8 // computing some auxilliary data that is necessary for the indexer. 9 // 10 // Author : Richard C. Bilson 11 // Created On : Sun May 17 21:53:34 2015 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Sun May 17 21:55:09 2015 14 // Update Count : 2 15 // 3 16 4 #ifndef SYMTAB_VALIDATE_H5 #define SYMTAB_VALIDATE_H17 #ifndef VALIDATE_H 18 #define VALIDATE_H 6 19 7 20 #include "SynTree/SynTree.h" … … 12 25 void validate( std::list< Declaration * > &translationUnit, bool doDebug = false ); 13 26 void validateType( Type *type, const Indexer *indexer ); 14 } // SymTab27 } // namespace SymTab 15 28 16 #endif // SYMTAB_VALIDATE_H 29 #endif // VALIDATE_H 30 31 // Local Variables: // 32 // tab-width: 4 // 33 // mode: c++ // 34 // compile-command: "make install" // 35 // End: // -
translator/SynTree/AddressExpr.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: AddressExpr.cc,v 1.6 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // AddressExpr.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 23:54:44 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:48:14 2015 13 // Update Count : 5 14 // 7 15 8 16 #include "Expression.h" … … 10 18 #include "utility.h" 11 19 12 13 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) 14 : Expression( _aname ), arg( arg ) 15 { 20 AddressExpr::AddressExpr( Expression *arg, Expression *_aname ) : Expression( _aname ), arg( arg ) { 16 21 for ( std::list< Type* >::const_iterator i = arg->get_results().begin(); i != arg->get_results().end(); ++i ) { 17 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) );18 } 22 get_results().push_back( new PointerType( Type::Qualifiers(), (*i)->clone() ) ); 23 } // for 19 24 } 20 25 21 AddressExpr::AddressExpr( const AddressExpr &other ) 22 : Expression( other ), arg( maybeClone( other.arg ) ) 23 { 26 AddressExpr::AddressExpr( const AddressExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { 24 27 } 25 28 26 AddressExpr::~AddressExpr() 27 { 29 AddressExpr::~AddressExpr() { 28 30 delete arg; 29 31 } 30 32 31 void 32 AddressExpr::print( std::ostream &os, int indent ) const 33 { 33 void AddressExpr::print( std::ostream &os, int indent ) const { 34 34 os << std::string( indent, ' ' ) << "Address of:" << std::endl; 35 35 if ( arg ) { 36 arg->print( os, indent+2 );37 } 36 arg->print( os, indent+2 ); 37 } // if 38 38 } 39 39 40 40 // Local Variables: // 41 // tab-width: 4 // 42 // mode: c++ // 43 // compile-command: "make install" // 44 // End: // -
translator/SynTree/AggregateDecl.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: AggregateDecl.cc,v 1.7 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // AggregateDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Sun May 17 23:56:39 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:48:23 2015 13 // Update Count : 4 14 // 7 15 8 16 #include "Declaration.h" … … 11 19 12 20 13 AggregateDecl::AggregateDecl( const std::string &name ) 14 : Parent( name, Declaration::NoStorageClass, LinkageSpec::Cforall ) 15 { 21 AggregateDecl::AggregateDecl( const std::string &name ) : Parent( name, Declaration::NoStorageClass, LinkageSpec::Cforall ) { 16 22 } 17 23 18 AggregateDecl::AggregateDecl( const AggregateDecl &other ) 19 : Parent( other ) 20 { 24 AggregateDecl::AggregateDecl( const AggregateDecl &other ) : Parent( other ) { 21 25 cloneAll( other.members, members ); 22 26 cloneAll( other.parameters, parameters ); 23 27 } 24 28 25 AggregateDecl::~AggregateDecl() 26 { 29 AggregateDecl::~AggregateDecl() { 27 30 deleteAll( members ); 28 31 deleteAll( parameters ); 29 32 } 30 33 31 void 32 AggregateDecl::print( std::ostream &os, int indent ) const 33 { 34 void AggregateDecl::print( std::ostream &os, int indent ) const { 34 35 using std::string; 35 36 using std::endl; … … 37 38 os << typeString() << " " << get_name(); 38 39 if ( ! parameters.empty() ) { 39 os << endl << string( indent+2, ' ' ) << "with parameters" << endl;40 printAll( parameters, os, indent+4 );41 } 40 os << endl << string( indent+2, ' ' ) << "with parameters" << endl; 41 printAll( parameters, os, indent+4 ); 42 } // if 42 43 if ( ! members.empty() ) { 43 os << endl << string( indent+2, ' ' ) << "with members" << endl;44 printAll( members, os, indent+4 );45 } 44 os << endl << string( indent+2, ' ' ) << "with members" << endl; 45 printAll( members, os, indent+4 ); 46 } // if 46 47 } 47 48 48 void 49 AggregateDecl::printShort( std::ostream &os, int indent ) const 50 { 49 void AggregateDecl::printShort( std::ostream &os, int indent ) const { 51 50 using std::string; 52 51 using std::endl; … … 54 53 os << typeString() << " " << get_name(); 55 54 if ( ! parameters.empty() ) { 56 os << endl << string( indent+2, ' ' ) << "with parameters" << endl;57 printAll( parameters, os, indent+4 );58 } 55 os << endl << string( indent+2, ' ' ) << "with parameters" << endl; 56 printAll( parameters, os, indent+4 ); 57 } // if 59 58 } 60 59 … … 67 66 std::string ContextDecl::typeString() const { return "context"; } 68 67 68 // Local Variables: // 69 // tab-width: 4 // 70 // mode: c++ // 71 // compile-command: "make install" // 72 // End: // -
translator/SynTree/ApplicationExpr.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // ApplicationExpr.cc.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:54:17 2015 13 // Update Count : 4 14 // 15 1 16 #include <cassert> 2 17 … … 8 23 9 24 10 ParamEntry::ParamEntry( const ParamEntry &other ) 11 : decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) 12 { 25 ParamEntry::ParamEntry( const ParamEntry &other ) : 26 decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) { 13 27 } 14 28 15 ParamEntry & 16 ParamEntry::operator=( const ParamEntry &other ) 17 { 18 if ( &other == this ) return *this; 19 decl = other.decl; 20 actualType = maybeClone( other.actualType ); 21 formalType = maybeClone( other.formalType ); 22 expr = maybeClone( other.expr ); 23 return *this; 29 ParamEntry &ParamEntry::operator=( const ParamEntry &other ) { 30 if ( &other == this ) return *this; 31 decl = other.decl; 32 actualType = maybeClone( other.actualType ); 33 formalType = maybeClone( other.formalType ); 34 expr = maybeClone( other.expr ); 35 return *this; 24 36 } 25 37 26 ParamEntry::~ParamEntry() 27 { 28 delete actualType; 29 delete formalType; 30 delete expr; 38 ParamEntry::~ParamEntry() { 39 delete actualType; 40 delete formalType; 41 delete expr; 31 42 } 32 43 33 ApplicationExpr::ApplicationExpr( Expression *funcExpr ) 34 : function( funcExpr ) 35 { 36 PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() ); 37 assert( pointer ); 38 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ); 39 assert( function ); 40 41 for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) { 42 get_results().push_back( (*i)->get_type()->clone() ); 43 } 44 ApplicationExpr::ApplicationExpr( Expression *funcExpr ) : function( funcExpr ) { 45 PointerType *pointer = dynamic_cast< PointerType* >( funcExpr->get_results().front() ); 46 assert( pointer ); 47 FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ); 48 assert( function ); 49 50 for ( std::list< DeclarationWithType* >::const_iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) { 51 get_results().push_back( (*i)->get_type()->clone() ); 52 } // for 44 53 } 45 54 46 ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) 47 : Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) 48 { 49 cloneAll( other.args, args ); 55 ApplicationExpr::ApplicationExpr( const ApplicationExpr &other ) : 56 Expression( other ), function( maybeClone( other.function ) ), inferParams( other.inferParams ) { 57 cloneAll( other.args, args ); 50 58 } 51 59 52 ApplicationExpr::~ApplicationExpr() 53 { 54 delete function; 55 deleteAll( args ); 60 ApplicationExpr::~ApplicationExpr() { 61 delete function; 62 deleteAll( args ); 56 63 } 57 64 58 void 59 ApplicationExpr::print( std::ostream &os, int indent ) const 60 { 61 os << std::string( indent, ' ' ) << "Application of" << std::endl; 62 function->print( os, indent+2 ); 63 if ( ! args.empty() ) { 64 os << std::string( indent, ' ' ) << "to arguments" << std::endl; 65 printAll( args, os, indent+2 ); 66 } 67 if ( ! inferParams.empty() ) { 68 os << std::string(indent, ' ') << "with inferred parameters:" << std::endl; 69 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { 70 os << std::string(indent+2, ' '); 71 Declaration::declFromId( i->second.decl )->printShort( os, indent+2 ); 72 os << std::endl; 73 } 74 } 75 Expression::print( os, indent ); 65 void ApplicationExpr::print( std::ostream &os, int indent ) const { 66 os << std::string( indent, ' ' ) << "Application of" << std::endl; 67 function->print( os, indent+2 ); 68 if ( ! args.empty() ) { 69 os << std::string( indent, ' ' ) << "to arguments" << std::endl; 70 printAll( args, os, indent+2 ); 71 } // if 72 if ( ! inferParams.empty() ) { 73 os << std::string(indent, ' ') << "with inferred parameters:" << std::endl; 74 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { 75 os << std::string(indent+2, ' '); 76 Declaration::declFromId( i->second.decl )->printShort( os, indent+2 ); 77 os << std::endl; 78 } // for 79 } // if 80 Expression::print( os, indent ); 76 81 } 77 82 83 // Local Variables: // 84 // tab-width: 4 // 85 // mode: c++ // 86 // compile-command: "make install" // 87 // End: // -
translator/SynTree/ArrayType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: ArrayType.cc,v 1.6 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // ArrayType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:52:08 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" … … 12 20 13 21 ArrayType::ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ) 14 : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) 15 { 16 base->set_isLvalue( false ); 22 : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) { 23 base->set_isLvalue( false ); 17 24 } 18 25 19 26 ArrayType::ArrayType( const ArrayType &other ) 20 : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ), 21 isVarLen( other.isVarLen ), isStatic( other.isStatic ) 22 { 27 : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ), 28 isVarLen( other.isVarLen ), isStatic( other.isStatic ) { 23 29 } 24 30 25 ArrayType::~ArrayType() 26 { 27 delete base; 28 delete dimension; 31 ArrayType::~ArrayType() { 32 delete base; 33 delete dimension; 29 34 } 30 35 31 void 32 ArrayType::print( std::ostream &os, int indent ) const 33 { 34 Type::print( os, indent ); 35 if ( isStatic ) { 36 os << "static "; 37 } 38 if ( isVarLen ) { 39 os << "variable length array of "; 40 } else if ( dimension ) { 41 os << "array of "; 42 dimension->print( os, indent ); 43 } else { 44 os << "open array of "; 45 } 46 if ( base ) { 47 base->print( os, indent ); 48 } 36 void ArrayType::print( std::ostream &os, int indent ) const { 37 Type::print( os, indent ); 38 if ( isStatic ) { 39 os << "static "; 40 } // if 41 if ( isVarLen ) { 42 os << "variable length array of "; 43 } else if ( dimension ) { 44 os << "array of "; 45 dimension->print( os, indent ); 46 } else { 47 os << "open array of "; 48 } // if 49 if ( base ) { 50 base->print( os, indent ); 51 } // if 49 52 } 50 53 54 // Local Variables: // 55 // tab-width: 4 // 56 // mode: c++ // 57 // compile-command: "make install" // 58 // End: // -
translator/SynTree/AttrType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: AttrType.cc,v 1.3 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // XXX.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:53:48 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Type.h" … … 12 20 13 21 AttrType::AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr ) 14 : Type( tq ), name( name ), expr( expr ), type( 0 ), isType( false ) 15 { 22 : Type( tq ), name( name ), expr( expr ), type( 0 ), isType( false ) { 16 23 } 17 24 18 25 AttrType::AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type ) 19 : Type( tq ), name( name ), expr( 0 ), type( type ), isType( true ) 20 { 26 : Type( tq ), name( name ), expr( 0 ), type( type ), isType( true ) { 21 27 } 22 28 23 29 AttrType::AttrType( const AttrType &other ) 24 : Type( other ), name( other.name ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) 25 { 30 : Type( other ), name( other.name ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 26 31 } 27 32 28 AttrType::~AttrType() 29 { 30 delete expr; 31 delete type; 33 AttrType::~AttrType() { 34 delete expr; 35 delete type; 32 36 } 33 37 34 void 35 AttrType::print( std::ostream &os, int indent ) const 36 { 37 Type::print( os, indent ); 38 os << "attribute " << name << " applied to "; 39 if ( expr ) { 40 os << "expression "; 41 expr->print( os, indent ); 42 } 43 if ( type ) { 44 os << "type "; 45 type->print( os, indent ); 46 } 38 void AttrType::print( std::ostream &os, int indent ) const { 39 Type::print( os, indent ); 40 os << "attribute " << name << " applied to "; 41 if ( expr ) { 42 os << "expression "; 43 expr->print( os, indent ); 44 } // if 45 if ( type ) { 46 os << "type "; 47 type->print( os, indent ); 48 } // if 47 49 } 48 50 51 // Local Variables: // 52 // tab-width: 4 // 53 // mode: c++ // 54 // compile-command: "make install" // 55 // End: // -
translator/SynTree/BasicType.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // BasicType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:55:16 2015 13 // Update Count : 1 14 // 15 1 16 #include <cassert> 2 3 17 #include "Type.h" 4 5 18 6 19 BasicType::BasicType( const Type::Qualifiers &tq, Kind bt ) : Type( tq ), kind( bt ) {} 7 20 8 21 void BasicType::print( std::ostream &os, int indent ) const { 9 10 "_Bool", "char", "signed char", "unsigned char", "short signed int", "short unsigned int",11 "signed int", "unsigned int", "long signed int", "long unsigned int", "long long signed int",12 "long long unsigned int", "float", "double", "long double", "float _Complex", "double _Complex",13 "long double _Complex", "float _Imaginary", "double _Imaginary", "long double _Imaginary"14 22 static const char *kindNames[] = { 23 "_Bool", "char", "signed char", "unsigned char", "short signed int", "short unsigned int", 24 "signed int", "unsigned int", "long signed int", "long unsigned int", "long long signed int", 25 "long long unsigned int", "float", "double", "long double", "float _Complex", "double _Complex", 26 "long double _Complex", "float _Imaginary", "double _Imaginary", "long double _Imaginary" 27 }; 15 28 16 17 29 Type::print( os, indent ); 30 os << kindNames[ kind ] << ' '; 18 31 } 19 32 20 33 bool BasicType::isInteger() const { 21 switch ( kind ) { 22 case Bool: 23 case Char: 24 case SignedChar: 25 case UnsignedChar: 26 case ShortSignedInt: 27 case ShortUnsignedInt: 28 case SignedInt: 29 case UnsignedInt: 30 case LongSignedInt: 31 case LongUnsignedInt: 32 case LongLongSignedInt: 33 case LongLongUnsignedInt: 34 return true; 35 36 case Float: 37 case Double: 38 case LongDouble: 39 case FloatComplex: 40 case DoubleComplex: 41 case LongDoubleComplex: 42 case FloatImaginary: 43 case DoubleImaginary: 44 case LongDoubleImaginary: 34 switch ( kind ) { 35 case Bool: 36 case Char: 37 case SignedChar: 38 case UnsignedChar: 39 case ShortSignedInt: 40 case ShortUnsignedInt: 41 case SignedInt: 42 case UnsignedInt: 43 case LongSignedInt: 44 case LongUnsignedInt: 45 case LongLongSignedInt: 46 case LongLongUnsignedInt: 47 return true; 48 case Float: 49 case Double: 50 case LongDouble: 51 case FloatComplex: 52 case DoubleComplex: 53 case LongDoubleComplex: 54 case FloatImaginary: 55 case DoubleImaginary: 56 case LongDoubleImaginary: 57 return false; 58 case NUMBER_OF_BASIC_TYPES: 59 assert( false ); 60 } // switch 61 assert( false ); 45 62 return false; 46 47 case NUMBER_OF_BASIC_TYPES:48 assert( false );49 }50 assert( false );51 return false;52 63 } 53 64 54 65 66 // Local Variables: // 67 // tab-width: 4 // 68 // mode: c++ // 69 // compile-command: "make install" // 70 // End: // -
translator/SynTree/CodeGenVisitor.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // CodeGenVisitor.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 07:57:51 2015 13 // Update Count : 3 14 // 15 1 16 #include <iostream> 2 17 #include <list> … … 7 22 using namespace std; 8 23 9 //*** Types 10 void CodeGenVisitor::visit(Type *type){ } 11 void CodeGenVisitor::visit(BasicType *basicType) { } 24 void CodeGenVisitor::visit( Type *type ){ } 25 void CodeGenVisitor::visit( BasicType *basicType ) { } 12 26 13 //*** Constant 14 void CodeGenVisitor::visit(Constant *constant) { 15 cout << constant->get_value() << endl; 27 void CodeGenVisitor::visit( Constant *constant ) { 28 cout << constant->get_value() << endl; 16 29 } 17 30 18 //*** Expressions 19 void CodeGenVisitor::visit(Expression *expr){ } 31 void CodeGenVisitor::visit( Expression *expr ){ } 20 32 21 void CodeGenVisitor::visit( ConstantExpr *cnst){22 if (cnst != 0)23 visit(cnst->get_constant());33 void CodeGenVisitor::visit( ConstantExpr *cnst ) { 34 if ( cnst != 0 ) 35 visit(cnst->get_constant()); 24 36 } 25 37 26 //*** Statements 27 void CodeGenVisitor::visit(Statement *stmt){ } 38 void CodeGenVisitor::visit( Statement *stmt ) { } 28 39 29 void CodeGenVisitor::visit( ExprStmt *exprStmt){30 if (exprStmt != 0)31 exprStmt->get_expr()->accept(*this);// visit(exprStmt->get_expr()) doesn't work40 void CodeGenVisitor::visit( ExprStmt *exprStmt ) { 41 if ( exprStmt != 0 ) 42 exprStmt->get_expr()->accept( *this ); // visit(exprStmt->get_expr()) doesn't work 32 43 } 33 44 34 void CodeGenVisitor::visit( SwitchStmt *switchStmt){35 36 37 45 void CodeGenVisitor::visit( SwitchStmt *switchStmt ) { 46 cout << "switch (" << endl; 47 // visit(switchStmt->get_condition()); // why doesn't this work? 48 switchStmt->get_condition()->accept(*this); 38 49 39 40 41 50 cout << ") {" << endl; 51 // visit(switchStmt->get_body()); // why doesn't this work? 52 cout << "}" << endl; 42 53 } 43 54 44 55 // Local Variables: // 56 // tab-width: 4 // 57 // mode: c++ // 58 // compile-command: "make install" // 59 // End: // -
translator/SynTree/CodeGenVisitor.h
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // CodeGenVisitor.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:46:47 2015 13 // Update Count : 4 14 // 15 1 16 #ifndef CODEGENV_H 2 17 #define CODEGENV_H … … 7 22 #include "Visitor.h" 8 23 24 class CodeGenVisitor : public Visitor { 25 public: 26 virtual void visit( Type * ); 27 virtual void visit( BasicType * ); 9 28 10 class CodeGenVisitor : public Visitor { 11 public: 12 //*** Types 13 virtual void visit(Type *); 14 virtual void visit(BasicType *); 29 virtual void visit( Constant * ); 15 30 16 //*** Constant 17 virtual void visit(Constant *);31 virtual void visit( Expression * ); 32 virtual void visit( ConstantExpr * ); 18 33 19 //*** Expressions 20 virtual void visit(Expression *); 21 virtual void visit(ConstantExpr *); 22 23 //*** Statements 24 virtual void visit(Statement *); 25 virtual void visit(ExprStmt *); 26 virtual void visit(SwitchStmt *); 34 virtual void visit( Statement * ); 35 virtual void visit( ExprStmt * ); 36 virtual void visit( SwitchStmt * ); 27 37 }; 28 38 39 #endif // CODEGENV_H 29 40 30 #endif /* #ifndef CODEGENV_H */ 41 // Local Variables: // 42 // tab-width: 4 // 43 // mode: c++ // 44 // compile-command: "make install" // 45 // End: // -
translator/SynTree/CommaExpr.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: CommaExpr.cc,v 1.7 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // CommaExpr.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:09:58 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Expression.h" … … 10 18 #include "utility.h" 11 19 12 13 20 CommaExpr::CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname ) 14 : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) 15 { 16 cloneAll( arg2->get_results(), get_results() ); 21 : Expression( _aname ), arg1( arg1 ), arg2( arg2 ) { 22 cloneAll( arg2->get_results(), get_results() ); 17 23 } 18 24 19 25 CommaExpr::CommaExpr( const CommaExpr &other ) 20 : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ) 21 { 26 : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ) { 22 27 } 23 28 24 CommaExpr::~CommaExpr() 25 { 26 delete arg1; 27 delete arg2; 29 CommaExpr::~CommaExpr() { 30 delete arg1; 31 delete arg2; 28 32 } 29 33 30 void 31 CommaExpr::print( std::ostream &os, int indent ) const 32 { 33 os << std::string( indent, ' ' ) << "Comma Expression:" << std::endl; 34 arg1->print( os, indent+2 ); 35 os << std::endl; 36 arg2->print( os, indent+2 ); 37 Expression::print( os, indent ); 34 void CommaExpr::print( std::ostream &os, int indent ) const { 35 os << std::string( indent, ' ' ) << "Comma Expression:" << std::endl; 36 arg1->print( os, indent+2 ); 37 os << std::endl; 38 arg2->print( os, indent+2 ); 39 Expression::print( os, indent ); 38 40 } 39 41 40 42 // Local Variables: // 43 // tab-width: 4 // 44 // mode: c++ // 45 // compile-command: "make install" // 46 // End: // -
translator/SynTree/CompoundStmt.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: CompoundStmt.cc,v 1.4 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // XXX.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:11:02 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Statement.h" … … 18 26 19 27 CompoundStmt::CompoundStmt( const CompoundStmt &other ) : Statement( other ) { 20 28 cloneAll( other.kids, kids ); 21 29 } 22 30 23 31 CompoundStmt::~CompoundStmt() { 24 32 deleteAll( kids ); 25 33 } 26 34 27 35 void CompoundStmt::print( std::ostream &os, int indent ) { 28 29 36 os << "\r" << string(indent, ' ') << "CompoundStmt" << endl ; 37 printAll( kids, os, indent+2 ); 30 38 } 31 39 32 33 34 35 40 // Local Variables: // 41 // tab-width: 4 // 42 // mode: c++ // 43 // compile-command: "make install" // 44 // End: // -
translator/SynTree/Constant.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Constant.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:13:25 2015 13 // Update Count : 1 14 // 15 1 16 #include <iostream> 2 17 #include <list> … … 5 20 #include "Type.h" 6 21 7 8 Constant::Constant(Type *_type, std::string _value): 9 type(_type), value(_value) {} 22 Constant::Constant( Type *_type, std::string _value ) : type(_type), value(_value) {} 10 23 11 24 Constant::~Constant() {} … … 14 27 15 28 void Constant::print( std::ostream &os ) const { 16 17 18 os << " (type: ";19 type->print( os );20 os << ")";21 } 29 os << value; 30 if ( type ) { 31 os << " (type: "; 32 type->print( os ); 33 os << ")"; 34 } // if 22 35 } 23 36 24 25 26 37 // Local Variables: // 38 // tab-width: 4 // 39 // mode: c++ // 40 // compile-command: "make install" // 41 // End: // -
translator/SynTree/Constant.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: Constant.h,v 1.6 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Constant.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:46:37 2015 13 // Update Count : 2 14 // 7 15 8 16 #ifndef CONSTANT_H … … 13 21 #include "Mutator.h" 14 22 23 class Constant { 24 public: 25 Constant( Type *type, std::string value ); 26 virtual ~Constant(); 15 27 16 class Constant 17 { 18 public: 19 Constant( Type *type, std::string value ); 20 virtual ~Constant(); 28 Type *get_type() { return type; } 29 void set_type( Type *newValue ) { type = newValue; } 30 std::string get_value() { return value; } 31 void set_value( std::string newValue ) { value = newValue; } 21 32 22 Type *get_type() { return type; } 23 void set_type( Type *newValue ) { type = newValue; } 24 std::string get_value() { return value; } 25 void set_value( std::string newValue ) { value = newValue; } 26 27 virtual Constant *clone() const; 28 virtual void accept( Visitor &v ) { v.visit( this ); } 29 virtual Constant *acceptMutator( Mutator &m ) { return m.mutate( this ); } 30 virtual void print( std::ostream &os ) const; 31 32 private: 33 Type *type; 34 std::string value; 33 virtual Constant *clone() const; 34 virtual void accept( Visitor &v ) { v.visit( this ); } 35 virtual Constant *acceptMutator( Mutator &m ) { return m.mutate( this ); } 36 virtual void print( std::ostream &os ) const; 37 private: 38 Type *type; 39 std::string value; 35 40 }; 36 41 42 #endif // CONSTANT_H 37 43 38 39 40 #endif /* #ifndef CONSTANT_H */ 44 // Local Variables: // 45 // tab-width: 4 // 46 // mode: c++ // 47 // compile-command: "make install" // 48 // End: // -
translator/SynTree/DeclStmt.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: DeclStmt.cc,v 1.4 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // DeclStmt.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:16:03 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Statement.h" … … 10 18 #include "utility.h" 11 19 12 13 DeclStmt::DeclStmt( std::list<Label> labels, Declaration *decl ) 14 : Statement( labels ), decl( decl ) 15 { 20 DeclStmt::DeclStmt( std::list<Label> labels, Declaration *decl ) : Statement( labels ), decl( decl ) { 16 21 } 17 22 18 DeclStmt::DeclStmt( const DeclStmt &other ) 19 : Statement( other ), decl( maybeClone( other.decl ) ) 20 { 23 DeclStmt::DeclStmt( const DeclStmt &other ) : Statement( other ), decl( maybeClone( other.decl ) ) { 21 24 } 22 25 23 DeclStmt::~DeclStmt() 24 { 25 delete decl; 26 DeclStmt::~DeclStmt() { 27 delete decl; 26 28 } 27 29 28 void 29 DeclStmt::print( std::ostream &os, int indent ) 30 { 31 os << "Declaration of "; 32 if ( decl ) { 33 decl->print( os, indent ); 34 } 30 void DeclStmt::print( std::ostream &os, int indent ) { 31 os << "Declaration of "; 32 if ( decl ) { 33 decl->print( os, indent ); 34 } // if 35 35 } 36 36 37 37 // Local Variables: // 38 // tab-width: 4 // 39 // mode: c++ // 40 // compile-command: "make install" // 41 // End: // -
translator/SynTree/Declaration.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: Declaration.cc,v 1.8 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Declaration.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:18:35 2015 13 // Update Count : 2 14 // 7 15 8 16 #include <string> … … 14 22 #include "utility.h" 15 23 16 17 24 const char* Declaration::storageClassName[] = { "", "auto", "static", "extern", "register" }; 18 25 … … 22 29 23 30 Declaration::Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ) 24 : name( name ), storageClass( sc ), linkage( linkage ), uniqueId( 0 ) 25 { 31 : name( name ), storageClass( sc ), linkage( linkage ), uniqueId( 0 ) { 26 32 } 27 33 28 34 Declaration::Declaration( const Declaration &other ) 29 : name( other.name ), storageClass( other.storageClass ), linkage( other.linkage ), uniqueId( other.uniqueId ) 30 { 35 : name( other.name ), storageClass( other.storageClass ), linkage( other.linkage ), uniqueId( other.uniqueId ) { 31 36 } 32 37 33 Declaration::~Declaration() 34 { 38 Declaration::~Declaration() { 35 39 } 36 40 37 void 38 Declaration::fixUniqueId() 39 { 40 uniqueId = ++lastUniqueId; 41 idMap[ uniqueId ] = this; 41 void Declaration::fixUniqueId() { 42 uniqueId = ++lastUniqueId; 43 idMap[ uniqueId ] = this; 42 44 } 43 45 44 46 /* static class method */ 45 Declaration * 46 Declaration::declFromId( UniqueId id ) 47 { 48 IdMapType::const_iterator i = idMap.find( id ); 49 if ( i != idMap.end() ) { 50 return i->second; 51 } else { 52 return 0; 53 } 47 Declaration *Declaration::declFromId( UniqueId id ) { 48 IdMapType::const_iterator i = idMap.find( id ); 49 if ( i != idMap.end() ) { 50 return i->second; 51 } else { 52 return 0; 53 } // if 54 54 } 55 55 56 56 /* static class method */ 57 void 58 Declaration::dumpIds( std::ostream &os ) 59 { 60 for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) { 61 os << i->first << " -> "; 62 i->second->printShort( os ); 63 os << std::endl; 64 } 57 void Declaration::dumpIds( std::ostream &os ) { 58 for ( IdMapType::const_iterator i = idMap.begin(); i != idMap.end(); ++i ) { 59 os << i->first << " -> "; 60 i->second->printShort( os ); 61 os << std::endl; 62 } // for 65 63 } 66 64 65 // Local Variables: // 66 // tab-width: 4 // 67 // mode: c++ // 68 // compile-command: "make install" // 69 // End: // -
translator/SynTree/Declaration.h
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Declaration.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:46:25 2015 13 // Update Count : 2 14 // 15 1 16 #ifndef DECLARATION_H 2 17 #define DECLARATION_H … … 7 22 #include "Parser/LinkageSpec.h" 8 23 9 10 24 class Declaration { 11 25 public: 12 13 NoStorageClass,14 Extern,15 Static,16 Auto,17 Register,18 Inline,19 Fortran,20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 private: 46 47 48 49 26 enum StorageClass { 27 NoStorageClass, 28 Extern, 29 Static, 30 Auto, 31 Register, 32 Inline, 33 Fortran, 34 }; 35 36 Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ); 37 Declaration( const Declaration &other ); 38 virtual ~Declaration(); 39 40 std::string get_name() const { return name; } 41 void set_name( std::string newValue ) { name = newValue; } 42 StorageClass get_storageClass() const { return storageClass; } 43 void set_storageClass( StorageClass newValue ) { storageClass = newValue; } 44 LinkageSpec::Type get_linkage() const { return linkage; } 45 void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; } 46 UniqueId get_uniqueId() const { return uniqueId; } 47 48 void fixUniqueId( void ); 49 virtual Declaration *clone() const = 0; 50 virtual void accept( Visitor &v ) = 0; 51 virtual Declaration *acceptMutator( Mutator &m ) = 0; 52 virtual void print( std::ostream &os, int indent = 0 ) const = 0; 53 virtual void printShort( std::ostream &os, int indent = 0 ) const = 0; 54 55 static const char* storageClassName[]; 56 57 static void dumpIds( std::ostream &os ); 58 static Declaration *declFromId( UniqueId id ); 59 private: 60 std::string name; 61 StorageClass storageClass; 62 LinkageSpec::Type linkage; 63 UniqueId uniqueId; 50 64 }; 51 65 52 66 class DeclarationWithType : public Declaration { 53 67 public: 54 55 56 57 58 59 60 61 62 63 64 65 66 private: 67 68 68 DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ); 69 DeclarationWithType( const DeclarationWithType &other ); 70 virtual ~DeclarationWithType(); 71 72 std::string get_mangleName() const { return mangleName; } 73 void set_mangleName( std::string newValue ) { mangleName = newValue; } 74 75 virtual DeclarationWithType *clone() const = 0; 76 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0; 77 78 virtual Type *get_type() const = 0; 79 virtual void set_type(Type *) = 0; 80 private: 81 // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2 82 std::string mangleName; 69 83 }; 70 84 71 85 class ObjectDecl : public DeclarationWithType { 72 73 public: 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 private: 92 93 94 86 typedef DeclarationWithType Parent; 87 public: 88 ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init ); 89 ObjectDecl( const ObjectDecl &other ); 90 virtual ~ObjectDecl(); 91 92 virtual Type *get_type() const { return type; } 93 virtual void set_type(Type *newType) { type = newType; } 94 95 Initializer *get_init() const { return init; } 96 void set_init( Initializer *newValue ) { init = newValue; } 97 Expression *get_bitfieldWidth() const { return bitfieldWidth; } 98 void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; } 99 100 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); } 101 virtual void accept( Visitor &v ) { v.visit( this ); } 102 virtual ObjectDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); } 103 virtual void print( std::ostream &os, int indent = 0 ) const; 104 virtual void printShort( std::ostream &os, int indent = 0 ) const; 105 private: 106 Type *type; 107 Initializer *init; 108 Expression *bitfieldWidth; 95 109 }; 96 110 97 111 class FunctionDecl : public DeclarationWithType { 98 99 public: 100 101 102 103 104 105 106 107 108 109 110 112 typedef DeclarationWithType Parent; 113 public: 114 FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ); 115 FunctionDecl( const FunctionDecl &other ); 116 virtual ~FunctionDecl(); 117 118 Type *get_type() const; 119 virtual void set_type(Type *); 120 121 FunctionType *get_functionType() const { return type; } 122 void set_functionType( FunctionType *newValue ) { type = newValue; } 123 CompoundStmt *get_statements() const { return statements; } 124 void set_statements( CompoundStmt *newValue ) { statements = newValue; } 111 125 // bool get_isInline() const { return isInline; } 112 126 // void set_isInline( bool newValue ) { isInline = newValue; } 113 114 115 116 117 118 119 120 121 private: 122 123 124 125 126 127 std::list< std::string >& get_oldIdents() { return oldIdents; } 128 std::list< Declaration* >& get_oldDecls() { return oldDecls; } 129 130 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); } 131 virtual void accept( Visitor &v ) { v.visit( this ); } 132 virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); } 133 virtual void print( std::ostream &os, int indent = 0 ) const; 134 virtual void printShort( std::ostream &os, int indent = 0 ) const; 135 private: 136 FunctionType *type; 137 CompoundStmt *statements; 138 bool isInline; 139 std::list< std::string > oldIdents; 140 std::list< Declaration* > oldDecls; 127 141 }; 128 142 129 143 class NamedTypeDecl : public Declaration { 130 131 public: 132 133 134 135 136 137 138 139 140 141 142 143 144 typedef Declaration Parent; 145 public: 146 NamedTypeDecl( const std::string &name, StorageClass sc, Type *type ); 147 NamedTypeDecl( const TypeDecl &other ); 148 virtual ~NamedTypeDecl(); 149 150 Type *get_base() const { return base; } 151 void set_base( Type *newValue ) { base = newValue; } 152 std::list< TypeDecl* >& get_parameters() { return parameters; } 153 std::list< DeclarationWithType* >& get_assertions() { return assertions; } 154 155 virtual NamedTypeDecl *clone() const = 0; 156 virtual void print( std::ostream &os, int indent = 0 ) const; 157 virtual void printShort( std::ostream &os, int indent = 0 ) const; 144 158 protected: 145 146 private: 147 148 149 159 virtual std::string typeString() const = 0; 160 private: 161 Type *base; 162 std::list< TypeDecl* > parameters; 163 std::list< DeclarationWithType* > assertions; 150 164 }; 151 165 152 166 class TypeDecl : public NamedTypeDecl { 153 154 public: 155 156 157 158 159 160 161 162 163 164 165 private: 166 167 167 typedef NamedTypeDecl Parent; 168 public: 169 enum Kind { Any, Dtype, Ftype }; 170 171 TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ); 172 TypeDecl( const TypeDecl &other ); 173 174 Kind get_kind() const { return kind; } 175 176 virtual TypeDecl *clone() const { return new TypeDecl( *this ); } 177 virtual void accept( Visitor &v ) { v.visit( this ); } 178 virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); } 179 private: 180 virtual std::string typeString() const; 181 Kind kind; 168 182 }; 169 183 170 184 class TypedefDecl : public NamedTypeDecl { 171 172 public: 173 174 175 176 177 178 179 private: 180 185 typedef NamedTypeDecl Parent; 186 public: 187 TypedefDecl( const std::string &name, StorageClass sc, Type *type ) : Parent( name, sc, type ) {} 188 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {} 189 190 virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); } 191 virtual void accept( Visitor &v ) { v.visit( this ); } 192 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 193 private: 194 virtual std::string typeString() const; 181 195 }; 182 196 183 197 class AggregateDecl : public Declaration { 184 185 public: 186 187 188 189 190 191 192 193 194 198 typedef Declaration Parent; 199 public: 200 AggregateDecl( const std::string &name ); 201 AggregateDecl( const AggregateDecl &other ); 202 virtual ~AggregateDecl(); 203 204 std::list<Declaration*>& get_members() { return members; } 205 std::list<TypeDecl*>& get_parameters() { return parameters; } 206 207 virtual void print( std::ostream &os, int indent = 0 ) const; 208 virtual void printShort( std::ostream &os, int indent = 0 ) const; 195 209 protected: 196 197 198 private: 199 200 210 virtual std::string typeString() const = 0; 211 212 private: 213 std::list<Declaration*> members; 214 std::list<TypeDecl*> parameters; 201 215 }; 202 216 203 217 class StructDecl : public AggregateDecl { 204 205 public: 206 207 208 209 210 211 212 213 private: 214 218 typedef AggregateDecl Parent; 219 public: 220 StructDecl( const std::string &name ) : Parent( name ) {} 221 StructDecl( const StructDecl &other ) : Parent( other ) {} 222 223 virtual StructDecl *clone() const { return new StructDecl( *this ); } 224 virtual void accept( Visitor &v ) { v.visit( this ); } 225 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 226 227 private: 228 virtual std::string typeString() const; 215 229 }; 216 230 217 231 class UnionDecl : public AggregateDecl { 218 219 public: 220 221 222 223 224 225 226 private: 227 232 typedef AggregateDecl Parent; 233 public: 234 UnionDecl( const std::string &name ) : Parent( name ) {} 235 UnionDecl( const UnionDecl &other ) : Parent( other ) {} 236 237 virtual UnionDecl *clone() const { return new UnionDecl( *this ); } 238 virtual void accept( Visitor &v ) { v.visit( this ); } 239 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 240 private: 241 virtual std::string typeString() const; 228 242 }; 229 243 230 244 class EnumDecl : public AggregateDecl { 231 232 public: 233 234 235 236 237 238 239 private: 240 245 typedef AggregateDecl Parent; 246 public: 247 EnumDecl( const std::string &name ) : Parent( name ) {} 248 EnumDecl( const EnumDecl &other ) : Parent( other ) {} 249 250 virtual EnumDecl *clone() const { return new EnumDecl( *this ); } 251 virtual void accept( Visitor &v ) { v.visit( this ); } 252 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 253 private: 254 virtual std::string typeString() const; 241 255 }; 242 256 243 257 class ContextDecl : public AggregateDecl { 244 245 public: 246 247 248 249 250 251 252 private: 253 258 typedef AggregateDecl Parent; 259 public: 260 ContextDecl( const std::string &name ) : Parent( name ) {} 261 ContextDecl( const ContextDecl &other ) : Parent( other ) {} 262 263 virtual ContextDecl *clone() const { return new ContextDecl( *this ); } 264 virtual void accept( Visitor &v ) { v.visit( this ); } 265 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 266 private: 267 virtual std::string typeString() const; 254 268 }; 255 269 256 270 #endif // DECLARATION_H 271 272 // Local Variables: // 273 // tab-width: 4 // 274 // mode: c++ // 275 // compile-command: "make install" // 276 // End: // -
translator/SynTree/DeclarationWithType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: DeclarationWithType.cc,v 1.9 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // DeclarationWithType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:20:23 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Declaration.h" … … 10 18 #include "utility.h" 11 19 12 13 20 DeclarationWithType::DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ) 14 : Declaration( name, sc, linkage ) 15 { 21 : Declaration( name, sc, linkage ) { 16 22 } 17 23 18 24 DeclarationWithType::DeclarationWithType( const DeclarationWithType &other ) 19 : Declaration( other ), mangleName( other.mangleName ) 20 { 25 : Declaration( other ), mangleName( other.mangleName ) { 21 26 } 22 27 23 DeclarationWithType::~DeclarationWithType() 24 { 28 DeclarationWithType::~DeclarationWithType() { 25 29 } 26 30 31 // Local Variables: // 32 // tab-width: 4 // 33 // mode: c++ // 34 // compile-command: "make install" // 35 // End: // -
translator/SynTree/Expression.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Expression.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:27:07 2015 13 // Update Count : 2 14 // 15 1 16 #include <iostream> 2 17 #include <cassert> … … 14 29 15 30 16 //*** Expression17 31 Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {} 18 Expression::Expression( const Expression &other ) 19 : env( maybeClone( other.env ) ) 20 { 21 cloneAll( other.results, results ); 22 argName = other.get_argName(); 23 } 24 Expression::~Expression() 25 { 26 delete env; 27 // delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix 28 deleteAll( results ); 29 } 30 31 void 32 Expression::add_result( Type *t ) 33 { 34 if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) { 35 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) ); 36 } else { 37 results.push_back(t); 38 } 32 33 Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ) { 34 cloneAll( other.results, results ); 35 argName = other.get_argName(); 36 } 37 38 Expression::~Expression() { 39 delete env; 40 // delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix 41 deleteAll( results ); 42 } 43 44 void Expression::add_result( Type *t ) { 45 if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) { 46 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) ); 47 } else { 48 results.push_back(t); 49 } // if 39 50 } 40 51 41 52 void Expression::print(std::ostream &os, int indent) const { 42 if ( env ) { 43 os << std::string(indent, ' ') << "with environment:" << std::endl; 44 env->print( os, indent+2 ); 45 } 46 47 if ( argName ) { 48 os << std::string(indent, ' ') << "with designator:"; 49 argName->print( os, indent+2 ); 50 } 51 } 52 53 //*** ConstantExpr 54 ConstantExpr::ConstantExpr(Constant _c, Expression *_aname ): 55 Expression( _aname ), constant(_c) 56 { 57 add_result( constant.get_type()->clone() ); 58 } 59 60 ConstantExpr::ConstantExpr( const ConstantExpr &other) 61 : Expression( other ), constant( other.constant ) 62 {} 53 if ( env ) { 54 os << std::string(indent, ' ') << "with environment:" << std::endl; 55 env->print( os, indent+2 ); 56 } // if 57 58 if ( argName ) { 59 os << std::string(indent, ' ') << "with designator:"; 60 argName->print( os, indent+2 ); 61 } // if 62 } 63 64 ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) { 65 add_result( constant.get_type()->clone() ); 66 } 67 68 ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) { 69 } 63 70 64 71 ConstantExpr::~ConstantExpr() {} 65 72 66 void ConstantExpr::print(std::ostream &os, int indent) const { 67 os << std::string(indent, ' ') << "Constant Expression: " ; 68 constant.print(os); 69 os << std::endl; 70 Expression::print( os, indent ); 71 } 72 73 //*** VariableExpr 74 VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) 75 { 76 add_result( var->get_type()->clone() ); 77 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 78 (*i)->set_isLvalue( true ); 79 } 80 } 81 82 VariableExpr::VariableExpr( const VariableExpr &other ) 83 : Expression( other ), var( other.var ) 84 { 85 } 86 87 VariableExpr::~VariableExpr() 88 { 89 // don't delete the declaration, since it points somewhere else in the tree 90 } 91 92 void VariableExpr::print(std::ostream &os, int indent) const { 93 os << std::string(indent, ' ') << "Variable Expression: "; 94 95 Declaration *decl = get_var(); 96 // if ( decl != 0) decl->print(os, indent + 2); 97 if ( decl != 0) decl->printShort(os, indent + 2); 98 os << std::endl; 99 Expression::print( os, indent ); 100 } 101 102 //*** SizeofExpr 73 void ConstantExpr::print( std::ostream &os, int indent ) const { 74 os << std::string(indent, ' ') << "Constant Expression: " ; 75 constant.print(os); 76 os << std::endl; 77 Expression::print( os, indent ); 78 } 79 80 VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) { 81 add_result( var->get_type()->clone() ); 82 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 83 (*i)->set_isLvalue( true ); 84 } // for 85 } 86 87 VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) { 88 } 89 90 VariableExpr::~VariableExpr() { 91 // don't delete the declaration, since it points somewhere else in the tree 92 } 93 94 void VariableExpr::print( std::ostream &os, int indent ) const { 95 os << std::string(indent, ' ') << "Variable Expression: "; 96 97 Declaration *decl = get_var(); 98 // if ( decl != 0) decl->print(os, indent + 2); 99 if ( decl != 0) decl->printShort(os, indent + 2); 100 os << std::endl; 101 Expression::print( os, indent ); 102 } 103 103 104 SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) : 104 Expression( _aname ), expr(expr_), type(0), isType(false) 105 { 106 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 105 Expression( _aname ), expr(expr_), type(0), isType(false) { 106 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 107 107 } 108 108 109 109 SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) : 110 Expression( _aname ), expr(0), type(type_), isType(true) 111 { 112 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 113 } 114 115 SizeofExpr::SizeofExpr( const SizeofExpr &other ) 116 : Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) 117 { 118 } 119 120 SizeofExpr::~SizeofExpr(){ 121 delete expr; 122 delete type; 110 Expression( _aname ), expr(0), type(type_), isType(true) { 111 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 112 } 113 114 SizeofExpr::SizeofExpr( const SizeofExpr &other ) : 115 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 116 } 117 118 SizeofExpr::~SizeofExpr() { 119 delete expr; 120 delete type; 123 121 } 124 122 125 123 void SizeofExpr::print( std::ostream &os, int indent) const { 126 os << std::string(indent, ' ') << "Sizeof Expression on: "; 127 128 if (isType) 129 type->print(os, indent + 2); 130 else 131 expr->print(os, indent + 2); 132 133 os << std::endl; 134 Expression::print( os, indent ); 135 } 136 137 //*** AttrExpr 124 os << std::string(indent, ' ') << "Sizeof Expression on: "; 125 126 if (isType) 127 type->print(os, indent + 2); 128 else 129 expr->print(os, indent + 2); 130 131 os << std::endl; 132 Expression::print( os, indent ); 133 } 134 138 135 AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) : 139 Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) 140 { 136 Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) { 141 137 } 142 138 143 139 AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) : 144 Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) 145 { 146 } 147 148 AttrExpr::AttrExpr( const AttrExpr &other ) 149 : Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) 150 { 151 } 152 153 AttrExpr::~AttrExpr(){ 154 delete attr; 155 delete expr; 156 delete type; 140 Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) { 141 } 142 143 AttrExpr::AttrExpr( const AttrExpr &other ) : 144 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 145 } 146 147 AttrExpr::~AttrExpr() { 148 delete attr; 149 delete expr; 150 delete type; 157 151 } 158 152 159 153 void AttrExpr::print( std::ostream &os, int indent) const { 160 os << std::string(indent, ' ') << "Attr "; 161 attr->print( os, indent + 2 ); 162 if ( isType || expr ) { 163 os << "applied to: "; 164 165 if (isType) 166 type->print(os, indent + 2); 167 else 168 expr->print(os, indent + 2); 169 } 170 171 os << std::endl; 172 Expression::print( os, indent ); 173 } 174 175 //*** CastExpr 176 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) 177 { 178 add_result(toType); 154 os << std::string(indent, ' ') << "Attr "; 155 attr->print( os, indent + 2 ); 156 if ( isType || expr ) { 157 os << "applied to: "; 158 159 if (isType) 160 type->print(os, indent + 2); 161 else 162 expr->print(os, indent + 2); 163 } // if 164 165 os << std::endl; 166 Expression::print( os, indent ); 167 } 168 169 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { 170 add_result(toType); 179 171 } 180 172 … … 182 174 } 183 175 184 CastExpr::CastExpr( const CastExpr &other ) 185 : Expression( other ), arg( maybeClone( other.arg ) ) 186 { 176 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { 187 177 } 188 178 189 179 CastExpr::~CastExpr() { 190 180 delete arg; 191 181 } 192 182 … … 194 184 195 185 void CastExpr::print( std::ostream &os, int indent ) const { 196 os << std::string(indent, ' ') << "Cast of:" << std::endl; 197 arg->print(os, indent+2); 198 os << std::endl << std::string(indent, ' ') << "to:" << std::endl; 199 if ( results.empty() ) { 200 os << std::string(indent+2, ' ') << "nothing" << std::endl; 201 } else { 202 printAll(results, os, indent+2); 203 } 204 Expression::print( os, indent ); 205 } 206 207 //*** UntypedMemberExpr 186 os << std::string(indent, ' ') << "Cast of:" << std::endl; 187 arg->print(os, indent+2); 188 os << std::endl << std::string(indent, ' ') << "to:" << std::endl; 189 if ( results.empty() ) { 190 os << std::string(indent+2, ' ') << "nothing" << std::endl; 191 } else { 192 printAll(results, os, indent+2); 193 } // if 194 Expression::print( os, indent ); 195 } 196 208 197 UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) : 209 Expression( _aname ), member(_member), aggregate(_aggregate) {} 210 211 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) 212 : Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) 213 { 198 Expression( _aname ), member(_member), aggregate(_aggregate) {} 199 200 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : 201 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { 214 202 } 215 203 216 204 UntypedMemberExpr::~UntypedMemberExpr() { 217 205 delete aggregate; 218 206 } 219 207 220 208 void UntypedMemberExpr::print( std::ostream &os, int indent ) const { 221 os << std::string(indent, ' ') << "Member Expression, with field: " << get_member(); 222 223 Expression *agg = get_aggregate(); 224 os << std::string(indent, ' ') << "from aggregate: "; 225 if (agg != 0) agg->print(os, indent + 2); 226 Expression::print( os, indent ); 227 } 228 229 230 //*** MemberExpr 209 os << std::string(indent, ' ') << "Member Expression, with field: " << get_member(); 210 211 Expression *agg = get_aggregate(); 212 os << std::string(indent, ' ') << "from aggregate: "; 213 if (agg != 0) agg->print(os, indent + 2); 214 Expression::print( os, indent ); 215 } 216 217 231 218 MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : 232 Expression( _aname ), member(_member), aggregate(_aggregate) 233 { 234 add_result( member->get_type()->clone() ); 235 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 236 (*i)->set_isLvalue( true ); 237 } 238 } 239 240 MemberExpr::MemberExpr( const MemberExpr &other ) 241 : Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) 242 { 219 Expression( _aname ), member(_member), aggregate(_aggregate) { 220 add_result( member->get_type()->clone() ); 221 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 222 (*i)->set_isLvalue( true ); 223 } // for 224 } 225 226 MemberExpr::MemberExpr( const MemberExpr &other ) : 227 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { 243 228 } 244 229 245 230 MemberExpr::~MemberExpr() { 246 247 231 delete member; 232 delete aggregate; 248 233 } 249 234 250 235 void MemberExpr::print( std::ostream &os, int indent ) const { 251 os << std::string(indent, ' ') << "Member Expression, with field: " << std::endl; 252 253 assert( member ); 254 os << std::string(indent + 2, ' '); 255 member->print( os, indent + 2 ); 256 os << std::endl; 257 258 Expression *agg = get_aggregate(); 259 os << std::string(indent, ' ') << "from aggregate: " << std::endl; 260 if (agg != 0) agg->print(os, indent + 2); 261 Expression::print( os, indent ); 262 } 263 264 265 //*** UntypedExpr 236 os << std::string(indent, ' ') << "Member Expression, with field: " << std::endl; 237 238 assert( member ); 239 os << std::string(indent + 2, ' '); 240 member->print( os, indent + 2 ); 241 os << std::endl; 242 243 Expression *agg = get_aggregate(); 244 os << std::string(indent, ' ') << "from aggregate: " << std::endl; 245 if (agg != 0) agg->print(os, indent + 2); 246 Expression::print( os, indent ); 247 } 248 249 266 250 UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {} 267 251 268 UntypedExpr::UntypedExpr( const UntypedExpr &other ) 269 : Expression( other ), function( maybeClone( other.function ) ) 270 { 271 cloneAll( other.args, args ); 252 UntypedExpr::UntypedExpr( const UntypedExpr &other ) : 253 Expression( other ), function( maybeClone( other.function ) ) { 254 cloneAll( other.args, args ); 272 255 } 273 256 274 257 UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) : 275 258 Expression( _aname ), function(_function), args(_args) {} 276 259 277 260 UntypedExpr::~UntypedExpr() {} 278 261 279 262 void UntypedExpr::print( std::ostream &os, int indent ) const { 280 os << std::string(indent, ' ') << "Applying untyped: " << std::endl; 281 function->print(os, indent + 4); 282 os << "\r" << std::string(indent, ' ') << "...to: " << std::endl; 283 printArgs(os, indent + 4); 284 Expression::print( os, indent ); 285 } 286 287 void UntypedExpr::printArgs(std::ostream &os, int indent ) const { 288 std::list<Expression *>::const_iterator i; 289 for (i = args.begin(); i != args.end(); i++) 290 (*i)->print(os, indent); 291 } 292 293 //*** NameExpr 263 os << std::string(indent, ' ') << "Applying untyped: " << std::endl; 264 function->print(os, indent + 4); 265 os << "\r" << std::string(indent, ' ') << "...to: " << std::endl; 266 printArgs(os, indent + 4); 267 Expression::print( os, indent ); 268 } 269 270 void UntypedExpr::printArgs( std::ostream &os, int indent ) const { 271 std::list<Expression *>::const_iterator i; 272 for (i = args.begin(); i != args.end(); i++) 273 (*i)->print(os, indent); 274 } 275 294 276 NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {} 295 277 296 NameExpr::NameExpr( const NameExpr &other ) 297 : Expression( other ), name( other.name ) 298 { 278 NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) { 299 279 } 300 280 … … 302 282 303 283 void NameExpr::print( std::ostream &os, int indent ) const { 304 os << std::string(indent, ' ') << "Name: " << get_name() << std::endl; 305 Expression::print( os, indent ); 306 } 307 308 //*** LogicalExpr 284 os << std::string(indent, ' ') << "Name: " << get_name() << std::endl; 285 Expression::print( os, indent ); 286 } 287 309 288 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : 310 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) 311 { 312 add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 313 } 314 315 LogicalExpr::LogicalExpr( const LogicalExpr &other ) 316 : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) 317 { 289 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { 290 add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 291 } 292 293 LogicalExpr::LogicalExpr( const LogicalExpr &other ) : 294 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { 318 295 } 319 296 320 297 LogicalExpr::~LogicalExpr(){ 321 322 298 delete arg1; 299 delete arg2; 323 300 } 324 301 325 302 void LogicalExpr::print( std::ostream &os, int indent )const { 326 os << std::string(indent, ' ') << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; 327 arg1->print(os); 328 os << " and "; 329 arg2->print(os); 330 os << std::endl; 331 Expression::print( os, indent ); 332 } 333 334 //*** ConditionalExpr 303 os << std::string(indent, ' ') << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; 304 arg1->print(os); 305 os << " and "; 306 arg2->print(os); 307 os << std::endl; 308 Expression::print( os, indent ); 309 } 310 335 311 ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) : 336 Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {} 337 338 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) 339 : Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) 340 { 341 } 312 Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {} 313 314 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : 315 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { 316 } 342 317 343 318 ConditionalExpr::~ConditionalExpr() { 344 345 346 319 delete arg1; 320 delete arg2; 321 delete arg3; 347 322 } 348 323 349 324 void ConditionalExpr::print( std::ostream &os, int indent ) const { 350 os << std::string(indent, ' ') << "Conditional expression on: " << std::endl; 351 arg1->print( os, indent+2 ); 352 os << std::string(indent, ' ') << "First alternative:" << std::endl; 353 arg2->print( os, indent+2 ); 354 os << std::string(indent, ' ') << "Second alternative:" << std::endl; 355 arg3->print( os, indent+2 ); 356 os << std::endl; 357 Expression::print( os, indent ); 358 } 359 360 //*** UntypedValofExpr 361 void UntypedValofExpr::print( std::ostream &os, int indent ) const 362 { 363 os << std::string(indent, ' ') << "Valof Expression: " << std::endl; 364 if ( get_body() != 0 ) 365 get_body()->print( os, indent + 2 ); 366 } 367 368 325 os << std::string(indent, ' ') << "Conditional expression on: " << std::endl; 326 arg1->print( os, indent+2 ); 327 os << std::string(indent, ' ') << "First alternative:" << std::endl; 328 arg2->print( os, indent+2 ); 329 os << std::string(indent, ' ') << "Second alternative:" << std::endl; 330 arg3->print( os, indent+2 ); 331 os << std::endl; 332 Expression::print( os, indent ); 333 } 334 335 void UntypedValofExpr::print( std::ostream &os, int indent ) const { 336 os << std::string(indent, ' ') << "Valof Expression: " << std::endl; 337 if ( get_body() != 0 ) 338 get_body()->print( os, indent + 2 ); 339 } 340 341 // Local Variables: // 342 // tab-width: 4 // 343 // mode: c++ // 344 // compile-command: "make install" // 345 // End: // -
translator/SynTree/Expression.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: Expression.h,v 1.31 2005/08/29 20:59:25 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Expression.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:46:15 2015 13 // Update Count : 3 14 // 7 15 8 16 #ifndef EXPRESSION_H … … 15 23 #include "Constant.h" 16 24 17 18 class Expression 19 { 20 public: 21 Expression(Expression *_aname = 0 ); 22 Expression( const Expression &other ); 23 virtual ~Expression(); 24 25 std::list<Type *>& get_results() { return results; } 26 void add_result(Type *t); 27 28 TypeSubstitution *get_env() const { return env; } 29 void set_env( TypeSubstitution *newValue ) { env = newValue; } 30 Expression *get_argName() const { return argName; } 31 void set_argName( Expression *name ) { argName = name; } 32 33 virtual Expression *clone() const = 0; 34 virtual void accept( Visitor &v ) = 0; 35 virtual Expression *acceptMutator( Mutator &m ) = 0; 36 virtual void print( std::ostream &os, int indent = 0 ) const; 37 38 protected: 39 std::list<Type *> results; 40 TypeSubstitution *env; 41 Expression* argName; // if expression is used as an argument, it can be "designated" by this name 25 class Expression { 26 public: 27 Expression(Expression *_aname = 0 ); 28 Expression( const Expression &other ); 29 virtual ~Expression(); 30 31 std::list<Type *>& get_results() { return results; } 32 void add_result(Type *t); 33 34 TypeSubstitution *get_env() const { return env; } 35 void set_env( TypeSubstitution *newValue ) { env = newValue; } 36 Expression *get_argName() const { return argName; } 37 void set_argName( Expression *name ) { argName = name; } 38 39 virtual Expression *clone() const = 0; 40 virtual void accept( Visitor &v ) = 0; 41 virtual Expression *acceptMutator( Mutator &m ) = 0; 42 virtual void print( std::ostream &os, int indent = 0 ) const; 43 protected: 44 std::list<Type *> results; 45 TypeSubstitution *env; 46 Expression* argName; // if expression is used as an argument, it can be "designated" by this name 42 47 }; 43 48 44 49 // ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration, 45 50 // but subject to decay-to-pointer and type parameter renaming 46 struct ParamEntry 47 {48 49 50 51 52 53 54 55 56 57 51 52 struct ParamEntry { 53 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {} 54 ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {} 55 ParamEntry( const ParamEntry &other ); 56 ~ParamEntry(); 57 ParamEntry &operator=( const ParamEntry &other ); 58 59 UniqueId decl; 60 Type *actualType; 61 Type *formalType; 62 Expression* expr; 58 63 }; 59 64 … … 62 67 // ApplicationExpr represents the application of a function to a set of parameters. This is the 63 68 // result of running an UntypedExpr through the expression analyzer. 64 class ApplicationExpr : public Expression 65 { 66 public: 67 ApplicationExpr( Expression *function ); 68 ApplicationExpr( const ApplicationExpr &other ); 69 virtual ~ApplicationExpr(); 70 71 Expression *get_function() const { return function; } 72 void set_function( Expression *newValue ) { function = newValue; } 73 std::list<Expression *>& get_args() { return args; } 74 InferredParams &get_inferParams() { return inferParams; } 75 76 virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); } 77 virtual void accept( Visitor &v ) { v.visit( this ); } 78 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 79 virtual void print( std::ostream &os, int indent = 0 ) const; 80 81 private: 82 Expression *function; 83 std::list<Expression *> args; 84 InferredParams inferParams; 69 70 class ApplicationExpr : public Expression { 71 public: 72 ApplicationExpr( Expression *function ); 73 ApplicationExpr( const ApplicationExpr &other ); 74 virtual ~ApplicationExpr(); 75 76 Expression *get_function() const { return function; } 77 void set_function( Expression *newValue ) { function = newValue; } 78 std::list<Expression *>& get_args() { return args; } 79 InferredParams &get_inferParams() { return inferParams; } 80 81 virtual ApplicationExpr *clone() const { return new ApplicationExpr( *this ); } 82 virtual void accept( Visitor &v ) { v.visit( this ); } 83 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 84 virtual void print( std::ostream &os, int indent = 0 ) const; 85 private: 86 Expression *function; 87 std::list<Expression *> args; 88 InferredParams inferParams; 85 89 }; 86 90 … … 88 92 // particular overload for the function name has not yet been determined. Most operators are 89 93 // converted into functional form automatically, to permit operator overloading. 90 class UntypedExpr : public Expression 91 { 92 public: 93 UntypedExpr( Expression *function, Expression *_aname = 0 ); 94 UntypedExpr( const UntypedExpr &other ); 95 UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = 0 ); 96 virtual ~UntypedExpr(); 97 98 Expression *get_function() const { return function; } 99 void set_function( Expression *newValue ) { function = newValue; } 100 101 void set_args( std::list<Expression *> &listArgs ) { args = listArgs; } 102 std::list<Expression*>::iterator begin_args() { return args.begin(); } 103 std::list<Expression*>::iterator end_args() { return args.end(); } 104 std::list<Expression*>& get_args() { return args; } 105 106 virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); } 107 virtual void accept( Visitor &v ) { v.visit( this ); } 108 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 109 virtual void print( std::ostream &os, int indent = 0 ) const; 110 virtual void printArgs(std::ostream &os, int indent = 0) const; 111 112 private: 113 114 Expression *function; 115 std::list<Expression*> args; 94 95 class UntypedExpr : public Expression { 96 public: 97 UntypedExpr( Expression *function, Expression *_aname = 0 ); 98 UntypedExpr( const UntypedExpr &other ); 99 UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = 0 ); 100 virtual ~UntypedExpr(); 101 102 Expression *get_function() const { return function; } 103 void set_function( Expression *newValue ) { function = newValue; } 104 105 void set_args( std::list<Expression *> &listArgs ) { args = listArgs; } 106 std::list<Expression*>::iterator begin_args() { return args.begin(); } 107 std::list<Expression*>::iterator end_args() { return args.end(); } 108 std::list<Expression*>& get_args() { return args; } 109 110 virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); } 111 virtual void accept( Visitor &v ) { v.visit( this ); } 112 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 113 virtual void print( std::ostream &os, int indent = 0 ) const; 114 virtual void printArgs(std::ostream &os, int indent = 0) const; 115 private: 116 Expression *function; 117 std::list<Expression*> args; 116 118 }; 117 119 118 120 // this class contains a name whose meaning is still not determined 119 class NameExpr : public Expression 120 { 121 public: 122 NameExpr( std::string name, Expression *_aname = 0 ); 123 NameExpr( const NameExpr &other ); 124 virtual ~NameExpr(); 125 126 std::string get_name() const { return name; } 127 void set_name( std::string newValue ) { name = newValue; } 128 129 virtual NameExpr *clone() const { return new NameExpr( *this ); } 130 virtual void accept( Visitor &v ) { v.visit( this ); } 131 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 132 virtual void print( std::ostream &os, int indent = 0 ) const; 133 134 private: 135 136 std::string name; 121 class NameExpr : public Expression { 122 public: 123 NameExpr( std::string name, Expression *_aname = 0 ); 124 NameExpr( const NameExpr &other ); 125 virtual ~NameExpr(); 126 127 std::string get_name() const { return name; } 128 void set_name( std::string newValue ) { name = newValue; } 129 130 virtual NameExpr *clone() const { return new NameExpr( *this ); } 131 virtual void accept( Visitor &v ) { v.visit( this ); } 132 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 133 virtual void print( std::ostream &os, int indent = 0 ) const; 134 private: 135 std::string name; 137 136 }; 138 137 … … 141 140 142 141 // AddressExpr represents a address-of expression, e.g. &e 143 class AddressExpr : public Expression 144 { 145 public: 146 AddressExpr( Expression *arg, Expression *_aname = 0 ); 147 AddressExpr( const AddressExpr &other ); 148 virtual ~AddressExpr(); 149 150 Expression *get_arg() const { return arg; } 151 void set_arg(Expression *newValue ) { arg = newValue; } 152 153 virtual AddressExpr *clone() const { return new AddressExpr( *this ); } 154 virtual void accept( Visitor &v ) { v.visit( this ); } 155 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 156 virtual void print( std::ostream &os, int indent = 0 ) const; 157 158 private: 159 Expression *arg; 160 }; 161 162 class LabelAddressExpr : public Expression 163 { 164 public: 165 LabelAddressExpr( Expression *arg ); 166 LabelAddressExpr( const AddressExpr &other ); 167 virtual ~LabelAddressExpr(); 168 169 Expression *get_arg() const { return arg; } 170 void set_arg(Expression *newValue ) { arg = newValue; } 171 172 virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); } 173 virtual void accept( Visitor &v ) { v.visit( this ); } 174 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 175 virtual void print( std::ostream &os, int indent = 0 ) const; 176 177 private: 178 Expression *arg; 142 class AddressExpr : public Expression { 143 public: 144 AddressExpr( Expression *arg, Expression *_aname = 0 ); 145 AddressExpr( const AddressExpr &other ); 146 virtual ~AddressExpr(); 147 148 Expression *get_arg() const { return arg; } 149 void set_arg(Expression *newValue ) { arg = newValue; } 150 151 virtual AddressExpr *clone() const { return new AddressExpr( *this ); } 152 virtual void accept( Visitor &v ) { v.visit( this ); } 153 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 154 virtual void print( std::ostream &os, int indent = 0 ) const; 155 private: 156 Expression *arg; 157 }; 158 159 class LabelAddressExpr : public Expression { 160 public: 161 LabelAddressExpr( Expression *arg ); 162 LabelAddressExpr( const AddressExpr &other ); 163 virtual ~LabelAddressExpr(); 164 165 Expression *get_arg() const { return arg; } 166 void set_arg(Expression *newValue ) { arg = newValue; } 167 168 virtual LabelAddressExpr *clone() const { return new LabelAddressExpr( *this ); } 169 virtual void accept( Visitor &v ) { v.visit( this ); } 170 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 171 virtual void print( std::ostream &os, int indent = 0 ) const; 172 private: 173 Expression *arg; 179 174 }; 180 175 181 176 // CastExpr represents a type cast expression, e.g. (int)e 182 class CastExpr : public Expression 183 { 184 public: 185 CastExpr( Expression *arg, Expression *_aname = 0 ); 186 CastExpr( Expression *arg, Type *toType, Expression *_aname = 0 ); 187 CastExpr( const CastExpr &other ); 188 virtual ~CastExpr(); 189 190 Expression *get_arg() const { return arg; } 191 void set_arg(Expression *newValue ) { arg = newValue; } 192 193 virtual CastExpr *clone() const { return new CastExpr( *this ); } 194 virtual void accept( Visitor &v ) { v.visit( this ); } 195 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 196 virtual void print( std::ostream &os, int indent = 0 ) const; 197 198 private: 199 Expression *arg; 200 }; 201 202 // UntypedMemberExpr represents a member selection operation, e.g. q.p 203 // before processing by the expression analyzer 204 class UntypedMemberExpr : public Expression 205 { 206 public: 207 UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = 0 ); 208 UntypedMemberExpr( const UntypedMemberExpr &other ); 209 virtual ~UntypedMemberExpr(); 210 211 std::string get_member() const { return member; } 212 void set_member( const std::string &newValue ) { member = newValue; } 213 Expression *get_aggregate() const { return aggregate; } 214 void set_aggregate( Expression *newValue ) { aggregate = newValue; } 215 216 virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); } 217 virtual void accept( Visitor &v ) { v.visit( this ); } 218 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 219 virtual void print( std::ostream &os, int indent = 0 ) const; 220 221 private: 222 std::string member; 223 Expression *aggregate; 224 }; 225 226 // MemberExpr represents a member selection operation, e.g. q.p 227 // after processing by the expression analyzer 228 class MemberExpr : public Expression 229 { 230 public: 231 MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = 0 ); 232 MemberExpr( const MemberExpr &other ); 233 virtual ~MemberExpr(); 234 235 DeclarationWithType *get_member() const { return member; } 236 void set_member( DeclarationWithType *newValue ) { member = newValue; } 237 Expression *get_aggregate() const { return aggregate; } 238 void set_aggregate( Expression *newValue ) { aggregate = newValue; } 239 240 virtual MemberExpr *clone() const { return new MemberExpr( *this ); } 241 virtual void accept( Visitor &v ) { v.visit( this ); } 242 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 243 virtual void print( std::ostream &os, int indent = 0 ) const; 244 245 private: 246 DeclarationWithType *member; 247 Expression *aggregate; 177 class CastExpr : public Expression { 178 public: 179 CastExpr( Expression *arg, Expression *_aname = 0 ); 180 CastExpr( Expression *arg, Type *toType, Expression *_aname = 0 ); 181 CastExpr( const CastExpr &other ); 182 virtual ~CastExpr(); 183 184 Expression *get_arg() const { return arg; } 185 void set_arg(Expression *newValue ) { arg = newValue; } 186 187 virtual CastExpr *clone() const { return new CastExpr( *this ); } 188 virtual void accept( Visitor &v ) { v.visit( this ); } 189 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 190 virtual void print( std::ostream &os, int indent = 0 ) const; 191 private: 192 Expression *arg; 193 }; 194 195 // UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer 196 class UntypedMemberExpr : public Expression { 197 public: 198 UntypedMemberExpr( std::string member, Expression *aggregate, Expression *_aname = 0 ); 199 UntypedMemberExpr( const UntypedMemberExpr &other ); 200 virtual ~UntypedMemberExpr(); 201 202 std::string get_member() const { return member; } 203 void set_member( const std::string &newValue ) { member = newValue; } 204 Expression *get_aggregate() const { return aggregate; } 205 void set_aggregate( Expression *newValue ) { aggregate = newValue; } 206 207 virtual UntypedMemberExpr *clone() const { return new UntypedMemberExpr( *this ); } 208 virtual void accept( Visitor &v ) { v.visit( this ); } 209 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 210 virtual void print( std::ostream &os, int indent = 0 ) const; 211 private: 212 std::string member; 213 Expression *aggregate; 214 }; 215 216 // MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 217 class MemberExpr : public Expression { 218 public: 219 MemberExpr( DeclarationWithType *member, Expression *aggregate, Expression *_aname = 0 ); 220 MemberExpr( const MemberExpr &other ); 221 virtual ~MemberExpr(); 222 223 DeclarationWithType *get_member() const { return member; } 224 void set_member( DeclarationWithType *newValue ) { member = newValue; } 225 Expression *get_aggregate() const { return aggregate; } 226 void set_aggregate( Expression *newValue ) { aggregate = newValue; } 227 228 virtual MemberExpr *clone() const { return new MemberExpr( *this ); } 229 virtual void accept( Visitor &v ) { v.visit( this ); } 230 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 231 virtual void print( std::ostream &os, int indent = 0 ) const; 232 private: 233 DeclarationWithType *member; 234 Expression *aggregate; 248 235 }; 249 236 250 237 // VariableExpr represents an expression that simply refers to the value of a named variable 251 class VariableExpr : public Expression 252 { 253 public: 254 VariableExpr( DeclarationWithType *var, Expression *_aname = 0 ); 255 VariableExpr( const VariableExpr &other ); 256 virtual ~VariableExpr(); 257 258 DeclarationWithType *get_var() const { return var; } 259 void set_var( DeclarationWithType *newValue ) { var = newValue; } 260 261 virtual VariableExpr *clone() const { return new VariableExpr( *this ); } 262 virtual void accept( Visitor &v ) { v.visit( this ); } 263 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 264 virtual void print( std::ostream &os, int indent = 0 ) const; 265 266 private: 267 DeclarationWithType *var; 238 class VariableExpr : public Expression { 239 public: 240 VariableExpr( DeclarationWithType *var, Expression *_aname = 0 ); 241 VariableExpr( const VariableExpr &other ); 242 virtual ~VariableExpr(); 243 244 DeclarationWithType *get_var() const { return var; } 245 void set_var( DeclarationWithType *newValue ) { var = newValue; } 246 247 virtual VariableExpr *clone() const { return new VariableExpr( *this ); } 248 virtual void accept( Visitor &v ) { v.visit( this ); } 249 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 250 virtual void print( std::ostream &os, int indent = 0 ) const; 251 private: 252 DeclarationWithType *var; 268 253 }; 269 254 270 255 // ConstantExpr represents an expression that simply refers to the value of a constant 271 class ConstantExpr : public Expression 272 { 273 public: 274 ConstantExpr( Constant constant, Expression *_aname = 0 ); 275 ConstantExpr( const ConstantExpr &other ); 276 virtual ~ConstantExpr(); 277 278 Constant *get_constant() { return &constant; } 279 void set_constant( const Constant &newValue ) { constant = newValue; } 280 281 virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); } 282 virtual void accept( Visitor &v ) { v.visit( this ); } 283 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 284 virtual void print( std::ostream &os, int indent = 0 ) const; 285 286 private: 287 Constant constant; 256 class ConstantExpr : public Expression { 257 public: 258 ConstantExpr( Constant constant, Expression *_aname = 0 ); 259 ConstantExpr( const ConstantExpr &other ); 260 virtual ~ConstantExpr(); 261 262 Constant *get_constant() { return &constant; } 263 void set_constant( const Constant &newValue ) { constant = newValue; } 264 265 virtual ConstantExpr *clone() const { return new ConstantExpr( *this ); } 266 virtual void accept( Visitor &v ) { v.visit( this ); } 267 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 268 virtual void print( std::ostream &os, int indent = 0 ) const; 269 private: 270 Constant constant; 288 271 }; 289 272 290 273 // SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) 291 class SizeofExpr : public Expression 292 { 293 public: 294 SizeofExpr( Expression *expr, Expression *_aname = 0 ); 295 SizeofExpr( const SizeofExpr &other ); 296 SizeofExpr( Type *type, Expression *_aname = 0 ); 297 virtual ~SizeofExpr(); 298 299 Expression *get_expr() const { return expr; } 300 void set_expr( Expression *newValue ) { expr = newValue; } 301 Type *get_type() const { return type; } 302 void set_type( Type *newValue ) { type = newValue; } 303 bool get_isType() const { return isType; } 304 void set_isType( bool newValue ) { isType = newValue; } 305 306 virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); } 307 virtual void accept( Visitor &v ) { v.visit( this ); } 308 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 309 virtual void print( std::ostream &os, int indent = 0 ) const; 310 311 private: 312 Expression *expr; 313 Type *type; 314 bool isType; 274 class SizeofExpr : public Expression { 275 public: 276 SizeofExpr( Expression *expr, Expression *_aname = 0 ); 277 SizeofExpr( const SizeofExpr &other ); 278 SizeofExpr( Type *type, Expression *_aname = 0 ); 279 virtual ~SizeofExpr(); 280 281 Expression *get_expr() const { return expr; } 282 void set_expr( Expression *newValue ) { expr = newValue; } 283 Type *get_type() const { return type; } 284 void set_type( Type *newValue ) { type = newValue; } 285 bool get_isType() const { return isType; } 286 void set_isType( bool newValue ) { isType = newValue; } 287 288 virtual SizeofExpr *clone() const { return new SizeofExpr( *this ); } 289 virtual void accept( Visitor &v ) { v.visit( this ); } 290 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 291 virtual void print( std::ostream &os, int indent = 0 ) const; 292 private: 293 Expression *expr; 294 Type *type; 295 bool isType; 315 296 }; 316 297 317 298 // AttrExpr represents an @attribute expression (like sizeof, but user-defined) 318 class AttrExpr : public Expression 319 { 320 public: 321 AttrExpr(Expression *attr, Expression *expr, Expression *_aname = 0 ); 322 AttrExpr( const AttrExpr &other ); 323 AttrExpr( Expression *attr, Type *type, Expression *_aname = 0 ); 324 virtual ~AttrExpr(); 325 326 Expression *get_attr() const { return attr; } 327 void set_attr( Expression *newValue ) { attr = newValue; } 328 Expression *get_expr() const { return expr; } 329 void set_expr( Expression *newValue ) { expr = newValue; } 330 Type *get_type() const { return type; } 331 void set_type( Type *newValue ) { type = newValue; } 332 bool get_isType() const { return isType; } 333 void set_isType( bool newValue ) { isType = newValue; } 334 335 virtual AttrExpr *clone() const { return new AttrExpr( *this ); } 336 virtual void accept( Visitor &v ) { v.visit( this ); } 337 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 338 virtual void print( std::ostream &os, int indent = 0 ) const; 339 340 private: 341 Expression *attr; 342 Expression *expr; 343 Type *type; 344 bool isType; 299 class AttrExpr : public Expression { 300 public: 301 AttrExpr(Expression *attr, Expression *expr, Expression *_aname = 0 ); 302 AttrExpr( const AttrExpr &other ); 303 AttrExpr( Expression *attr, Type *type, Expression *_aname = 0 ); 304 virtual ~AttrExpr(); 305 306 Expression *get_attr() const { return attr; } 307 void set_attr( Expression *newValue ) { attr = newValue; } 308 Expression *get_expr() const { return expr; } 309 void set_expr( Expression *newValue ) { expr = newValue; } 310 Type *get_type() const { return type; } 311 void set_type( Type *newValue ) { type = newValue; } 312 bool get_isType() const { return isType; } 313 void set_isType( bool newValue ) { isType = newValue; } 314 315 virtual AttrExpr *clone() const { return new AttrExpr( *this ); } 316 virtual void accept( Visitor &v ) { v.visit( this ); } 317 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 318 virtual void print( std::ostream &os, int indent = 0 ) const; 319 private: 320 Expression *attr; 321 Expression *expr; 322 Type *type; 323 bool isType; 345 324 }; 346 325 347 326 // LogicalExpr represents a short-circuit boolean expression (&& or ||) 348 class LogicalExpr : public Expression 349 { 350 public: 351 LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = 0 ); 352 LogicalExpr( const LogicalExpr &other ); 353 virtual ~LogicalExpr(); 354 355 bool get_isAnd() const { return isAnd; } 356 Expression *get_arg1() { return arg1; } 357 void set_arg1( Expression *newValue ) { arg1 = newValue; } 358 Expression *get_arg2() const { return arg2; } 359 void set_arg2( Expression *newValue ) { arg2 = newValue; } 360 361 virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); } 362 virtual void accept( Visitor &v ) { v.visit( this ); } 363 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 364 virtual void print( std::ostream &os, int indent = 0 ) const; 365 366 private: 367 Expression *arg1; 368 Expression *arg2; 369 bool isAnd; 327 class LogicalExpr : public Expression { 328 public: 329 LogicalExpr( Expression *arg1, Expression *arg2, bool andp = true, Expression *_aname = 0 ); 330 LogicalExpr( const LogicalExpr &other ); 331 virtual ~LogicalExpr(); 332 333 bool get_isAnd() const { return isAnd; } 334 Expression *get_arg1() { return arg1; } 335 void set_arg1( Expression *newValue ) { arg1 = newValue; } 336 Expression *get_arg2() const { return arg2; } 337 void set_arg2( Expression *newValue ) { arg2 = newValue; } 338 339 virtual LogicalExpr *clone() const { return new LogicalExpr( *this ); } 340 virtual void accept( Visitor &v ) { v.visit( this ); } 341 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 342 virtual void print( std::ostream &os, int indent = 0 ) const; 343 private: 344 Expression *arg1; 345 Expression *arg2; 346 bool isAnd; 370 347 }; 371 348 372 349 // ConditionalExpr represents the three-argument conditional ( p ? a : b ) 373 class ConditionalExpr : public Expression 374 { 375 public: 376 ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = 0 ); 377 ConditionalExpr( const ConditionalExpr &other ); 378 virtual ~ConditionalExpr(); 379 380 Expression *get_arg1() const { return arg1; } 381 void set_arg1( Expression *newValue ) { arg1 = newValue; } 382 Expression *get_arg2() const { return arg2; } 383 void set_arg2( Expression *newValue ) { arg2 = newValue; } 384 Expression *get_arg3() const { return arg3; } 385 void set_arg3( Expression *newValue ) { arg3 = newValue; } 386 387 virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); } 388 virtual void accept( Visitor &v ) { v.visit( this ); } 389 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 390 virtual void print( std::ostream &os, int indent = 0 ) const; 391 392 private: 393 Expression *arg1; 394 Expression *arg2; 395 Expression *arg3; 350 class ConditionalExpr : public Expression { 351 public: 352 ConditionalExpr( Expression *arg1, Expression *arg2, Expression *arg3, Expression *_aname = 0 ); 353 ConditionalExpr( const ConditionalExpr &other ); 354 virtual ~ConditionalExpr(); 355 356 Expression *get_arg1() const { return arg1; } 357 void set_arg1( Expression *newValue ) { arg1 = newValue; } 358 Expression *get_arg2() const { return arg2; } 359 void set_arg2( Expression *newValue ) { arg2 = newValue; } 360 Expression *get_arg3() const { return arg3; } 361 void set_arg3( Expression *newValue ) { arg3 = newValue; } 362 363 virtual ConditionalExpr *clone() const { return new ConditionalExpr( *this ); } 364 virtual void accept( Visitor &v ) { v.visit( this ); } 365 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 366 virtual void print( std::ostream &os, int indent = 0 ) const; 367 private: 368 Expression *arg1; 369 Expression *arg2; 370 Expression *arg3; 396 371 }; 397 372 398 373 // CommaExpr represents the sequence operator ( a, b ) 399 class CommaExpr : public Expression 400 { 401 public: 402 CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = 0 ); 403 CommaExpr( const CommaExpr &other ); 404 virtual ~CommaExpr(); 405 406 Expression *get_arg1() const { return arg1; } 407 void set_arg1( Expression *newValue ) { arg1 = newValue; } 408 Expression *get_arg2() const { return arg2; } 409 void set_arg2( Expression *newValue ) { arg2 = newValue; } 410 411 virtual CommaExpr *clone() const { return new CommaExpr( *this ); } 412 virtual void accept( Visitor &v ) { v.visit( this ); } 413 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 414 virtual void print( std::ostream &os, int indent = 0 ) const; 415 416 private: 417 Expression *arg1; 418 Expression *arg2; 374 class CommaExpr : public Expression { 375 public: 376 CommaExpr( Expression *arg1, Expression *arg2, Expression *_aname = 0 ); 377 CommaExpr( const CommaExpr &other ); 378 virtual ~CommaExpr(); 379 380 Expression *get_arg1() const { return arg1; } 381 void set_arg1( Expression *newValue ) { arg1 = newValue; } 382 Expression *get_arg2() const { return arg2; } 383 void set_arg2( Expression *newValue ) { arg2 = newValue; } 384 385 virtual CommaExpr *clone() const { return new CommaExpr( *this ); } 386 virtual void accept( Visitor &v ) { v.visit( this ); } 387 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 388 virtual void print( std::ostream &os, int indent = 0 ) const; 389 private: 390 Expression *arg1; 391 Expression *arg2; 419 392 }; 420 393 421 394 // TupleExpr represents a tuple expression ( [a, b, c] ) 422 class TupleExpr : public Expression 423 { 424 public: 425 TupleExpr( Expression *_aname = 0 ); 426 TupleExpr( const TupleExpr &other ); 427 virtual ~TupleExpr(); 428 429 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; } 430 std::list<Expression*>& get_exprs() { return exprs; } 431 432 virtual TupleExpr *clone() const { return new TupleExpr( *this ); } 433 virtual void accept( Visitor &v ) { v.visit( this ); } 434 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 435 virtual void print( std::ostream &os, int indent = 0 ) const; 436 437 private: 438 std::list<Expression*> exprs; 395 class TupleExpr : public Expression { 396 public: 397 TupleExpr( Expression *_aname = 0 ); 398 TupleExpr( const TupleExpr &other ); 399 virtual ~TupleExpr(); 400 401 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; } 402 std::list<Expression*>& get_exprs() { return exprs; } 403 404 virtual TupleExpr *clone() const { return new TupleExpr( *this ); } 405 virtual void accept( Visitor &v ) { v.visit( this ); } 406 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 407 virtual void print( std::ostream &os, int indent = 0 ) const; 408 private: 409 std::list<Expression*> exprs; 439 410 }; 440 411 441 412 // SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on 442 class SolvedTupleExpr : public Expression 443 { 444 public: 445 446 SolvedTupleExpr( Expression *_aname = 0 ) : Expression( _aname ) {} 447 SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = 0 ); 448 SolvedTupleExpr( const SolvedTupleExpr &other ); 449 virtual ~SolvedTupleExpr() {} 450 451 std::list<Expression*> &get_exprs() { return exprs; } 452 453 virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); } 454 virtual void accept( Visitor &v ) { v.visit( this ); } 455 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 456 virtual void print( std::ostream &os, int indent = 0 ) const; 457 private: 458 std::list<Expression*> exprs; 413 class SolvedTupleExpr : public Expression { 414 public: 415 SolvedTupleExpr( Expression *_aname = 0 ) : Expression( _aname ) {} 416 SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = 0 ); 417 SolvedTupleExpr( const SolvedTupleExpr &other ); 418 virtual ~SolvedTupleExpr() {} 419 420 std::list<Expression*> &get_exprs() { return exprs; } 421 422 virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); } 423 virtual void accept( Visitor &v ) { v.visit( this ); } 424 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 425 virtual void print( std::ostream &os, int indent = 0 ) const; 426 private: 427 std::list<Expression*> exprs; 459 428 }; 460 429 461 430 // TypeExpr represents a type used in an expression (e.g. as a type generator parameter) 462 class TypeExpr : public Expression 463 { 464 public: 465 TypeExpr( Type *type ); 466 TypeExpr( const TypeExpr &other ); 467 virtual ~TypeExpr(); 468 469 Type *get_type() const { return type; } 470 void set_type( Type *newValue ) { type = newValue; } 471 472 virtual TypeExpr *clone() const { return new TypeExpr( *this ); } 473 virtual void accept( Visitor &v ) { v.visit( this ); } 474 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 475 virtual void print( std::ostream &os, int indent = 0 ) const; 476 477 private: 478 Type *type; 431 class TypeExpr : public Expression { 432 public: 433 TypeExpr( Type *type ); 434 TypeExpr( const TypeExpr &other ); 435 virtual ~TypeExpr(); 436 437 Type *get_type() const { return type; } 438 void set_type( Type *newValue ) { type = newValue; } 439 440 virtual TypeExpr *clone() const { return new TypeExpr( *this ); } 441 virtual void accept( Visitor &v ) { v.visit( this ); } 442 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 443 virtual void print( std::ostream &os, int indent = 0 ) const; 444 private: 445 Type *type; 479 446 }; 480 447 481 448 // ValofExpr represents a GCC 'lambda expression' 482 class UntypedValofExpr : public Expression 483 { 484 public: 485 UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {} 486 virtual ~UntypedValofExpr() {} 487 488 Expression *get_value(); 489 Statement *get_body() const { return body; } 490 491 virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); } 492 virtual void accept( Visitor &v ) { v.visit( this ); } 493 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 494 virtual void print( std::ostream &os, int indent = 0 ) const; 495 496 private: 497 Statement *body; 498 }; 499 500 501 #endif /* #ifndef EXPRESSION_H */ 502 503 /* 504 Local Variables: 505 mode: c++ 506 End: 507 */ 449 class UntypedValofExpr : public Expression { 450 public: 451 UntypedValofExpr( Statement *_body, Expression *_aname = 0 ) : Expression( _aname ), body ( _body ) {} 452 virtual ~UntypedValofExpr() {} 453 454 Expression *get_value(); 455 Statement *get_body() const { return body; } 456 457 virtual UntypedValofExpr *clone() const { return new UntypedValofExpr( *this ); } 458 virtual void accept( Visitor &v ) { v.visit( this ); } 459 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 460 virtual void print( std::ostream &os, int indent = 0 ) const; 461 private: 462 Statement *body; 463 }; 464 465 #endif // EXPRESSION_H 466 467 // Local Variables: // 468 // tab-width: 4 // 469 // mode: c++ // 470 // compile-command: "make install" // 471 // End: // -
translator/SynTree/FunctionDecl.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // FunctionDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 08:48:46 2015 13 // Update Count : 1 14 // 15 1 16 #include <cassert> 2 17 … … 6 21 #include "utility.h" 7 22 8 9 23 FunctionDecl::FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ) 10 24 : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ) { 11 12 13 set_linkage( LinkageSpec::C );14 } 25 // this is a brazen hack to force the function "main" to have C linkage 26 if ( name == "main" ) { 27 set_linkage( LinkageSpec::C ); 28 } // if 15 29 } 16 30 17 31 FunctionDecl::FunctionDecl( const FunctionDecl &other ) 18 32 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) { 19 33 } 20 34 21 35 FunctionDecl::~FunctionDecl() { 22 23 36 delete type; 37 delete statements; 24 38 } 25 39 26 40 Type * FunctionDecl::get_type() const { 27 41 return type; 28 42 } 29 43 30 44 void FunctionDecl::set_type( Type *t ) { 31 32 45 type = dynamic_cast< FunctionType* >( t ); 46 assert( type ); 33 47 } 34 48 35 49 void FunctionDecl::print( std::ostream &os, int indent ) const { 36 37 38 39 40 os << get_name() << ": a ";41 } 42 43 os << LinkageSpec::toString( get_linkage() ) << " ";44 } 45 46 os << "inline ";47 } 48 49 os << storageClassName[ get_storageClass() ] << ' ';50 } 51 52 get_type()->print( os, indent );53 54 os << "untyped entity ";55 } 56 57 os << string( indent+2, ' ' ) << "with parameter names" << endl;58 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {59 60 }61 } 62 63 os << string( indent+2, ' ' ) << "with parameter declarations" << endl;64 printAll( oldDecls, os, indent+4 );65 } 66 67 os << string( indent+2, ' ' ) << "with body " << endl;68 statements->print( os, indent+4 );69 } 50 using std::endl; 51 using std::string; 52 53 if ( get_name() != "" ) { 54 os << get_name() << ": a "; 55 } // if 56 if ( get_linkage() != LinkageSpec::Cforall ) { 57 os << LinkageSpec::toString( get_linkage() ) << " "; 58 } // if 59 if ( isInline ) { 60 os << "inline "; 61 } // if 62 if ( get_storageClass() != NoStorageClass ) { 63 os << storageClassName[ get_storageClass() ] << ' '; 64 } // if 65 if ( get_type() ) { 66 get_type()->print( os, indent ); 67 } else { 68 os << "untyped entity "; 69 } // if 70 if ( ! oldIdents.empty() ) { 71 os << string( indent+2, ' ' ) << "with parameter names" << endl; 72 for ( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) { 73 os << string( indent+4, ' ' ) << *i << endl; 74 } // for 75 } // if 76 if ( ! oldDecls.empty() ) { 77 os << string( indent+2, ' ' ) << "with parameter declarations" << endl; 78 printAll( oldDecls, os, indent+4 ); 79 } // if 80 if ( statements ) { 81 os << string( indent+2, ' ' ) << "with body " << endl; 82 statements->print( os, indent+4 ); 83 } // if 70 84 } 71 85 72 86 void FunctionDecl::printShort( std::ostream &os, int indent ) const { 73 74 75 76 77 os << get_name() << ": a ";78 } 79 80 os << "inline ";81 } 82 83 os << storageClassName[ get_storageClass() ] << ' ';84 } 85 86 get_type()->print( os, indent );87 88 os << "untyped entity ";89 } 87 using std::endl; 88 using std::string; 89 90 if ( get_name() != "" ) { 91 os << get_name() << ": a "; 92 } // if 93 if ( isInline ) { 94 os << "inline "; 95 } // if 96 if ( get_storageClass() != NoStorageClass ) { 97 os << storageClassName[ get_storageClass() ] << ' '; 98 } // if 99 if ( get_type() ) { 100 get_type()->print( os, indent ); 101 } else { 102 os << "untyped entity "; 103 } // if 90 104 } 105 106 // Local Variables: // 107 // tab-width: 4 // 108 // mode: c++ // 109 // compile-command: "make install" // 110 // End: // -
translator/SynTree/FunctionType.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // FunctionType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 09:01:28 2015 13 // Update Count : 1 14 // 15 1 16 #include <algorithm> 2 17 … … 5 20 #include "utility.h" 6 21 7 8 22 FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs ) : Type( tq ), isVarArgs( isVarArgs ) { 9 23 } 10 24 11 25 FunctionType::FunctionType( const FunctionType &other ) : Type( other ), isVarArgs( other.isVarArgs ) { 12 13 26 cloneAll( other.returnVals, returnVals ); 27 cloneAll( other.parameters, parameters ); 14 28 } 15 29 16 30 FunctionType::~FunctionType() { 17 18 31 deleteAll( returnVals ); 32 deleteAll( parameters ); 19 33 } 20 34 21 35 void FunctionType::print( std::ostream &os, int indent ) const { 22 23 36 using std::string; 37 using std::endl; 24 38 25 26 27 28 os << string( indent + 2, ' ' ) << "with parameters" << endl;29 printAll( parameters, os, indent + 4 );30 if ( isVarArgs ) {31 32 }33 34 os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl;35 } 36 37 38 os << endl << string( indent + 4, ' ' ) << "nothing " << endl;39 40 os << endl;41 printAll( returnVals, os, indent + 4 );42 } 39 Type::print( os, indent ); 40 os << "function" << endl; 41 if ( ! parameters.empty() ) { 42 os << string( indent + 2, ' ' ) << "with parameters" << endl; 43 printAll( parameters, os, indent + 4 ); 44 if ( isVarArgs ) { 45 os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl; 46 } // if 47 } else if ( isVarArgs ) { 48 os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl; 49 } // if 50 os << string( indent + 2, ' ' ) << "returning "; 51 if ( returnVals.empty() ) { 52 os << endl << string( indent + 4, ' ' ) << "nothing " << endl; 53 } else { 54 os << endl; 55 printAll( returnVals, os, indent + 4 ); 56 } // if 43 57 } 44 58 59 // Local Variables: // 60 // tab-width: 4 // 61 // mode: c++ // 62 // compile-command: "make install" // 63 // End: // -
translator/SynTree/Initializer.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Initializer.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 09:02:45 2015 13 // Update Count : 2 14 // 15 1 16 #include "Initializer.h" 2 17 #include "Expression.h" 3 18 #include "utility.h" 4 5 19 6 20 Initializer::Initializer() {} … … 9 23 10 24 std::string Initializer::designator_name( Expression *des ) { 11 12 return n->get_name();13 14 throw 0;25 if ( NameExpr *n = dynamic_cast<NameExpr *>(des) ) 26 return n->get_name(); 27 else 28 throw 0; 15 29 } 16 30 … … 21 35 22 36 SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) { 23 37 cloneAll(other.designators, designators ); 24 38 } 25 39 … … 29 43 30 44 void SingleInit::print( std::ostream &os, int indent ) { 31 32 45 os << std::endl << std::string(indent, ' ' ) << "Simple Initializer: "; 46 value->print( os, indent+2 ); 33 47 34 35 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " ;36 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ )37 38 } 48 if ( ! designators.empty() ) { 49 os << std::endl << std::string(indent + 2, ' ' ) << "designated by: " ; 50 for ( std::list < Expression * >::iterator i = designators.begin(); i != designators.end(); i++ ) 51 ( *i )->print(os, indent + 4 ); 52 } // if 39 53 } 40 54 41 55 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators ) 42 56 : initializers( _initializers ), designators( _designators ) { 43 57 } 44 58 … … 46 60 47 61 ListInit *ListInit::clone() const { 48 62 return new ListInit( *this ); 49 63 } 50 64 51 65 void ListInit::print( std::ostream &os, int indent ) { 52 53 54 os << std::string(indent + 2, ' ' ) << "designated by: [";55 for ( std::list < Expression * >::iterator i = designators.begin();56 57 58 }66 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 67 if ( ! designators.empty() ) { 68 os << std::string(indent + 2, ' ' ) << "designated by: ["; 69 for ( std::list < Expression * >::iterator i = designators.begin(); 70 i != designators.end(); i++ ) { 71 ( *i )->print(os, indent + 4 ); 72 } // for 59 73 60 os << std::string(indent + 2, ' ' ) << "]";61 } 74 os << std::string(indent + 2, ' ' ) << "]"; 75 } // if 62 76 63 64 (*i)->print( os, indent + 2 );77 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 78 (*i)->print( os, indent + 2 ); 65 79 } 80 // Local Variables: // 81 // tab-width: 4 // 82 // mode: c++ // 83 // compile-command: "make install" // 84 // End: // -
translator/SynTree/Initializer.h
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Initializer.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 09:03:48 2015 13 // Update Count : 1 14 // 15 1 16 #ifndef INITIALIZER_H 2 17 #define INITIALIZER_H … … 8 23 #include <cassert> 9 24 10 11 25 // Initializer: base class for object initializers (provide default values) 12 26 class Initializer { 13 27 public: 14 15 16 28 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 29 Initializer( ); 30 virtual ~Initializer(); 17 31 18 32 static std::string designator_name( Expression *designator ); 19 33 20 21 34 // void set_name( std::string newValue ) { name = newValue; } 35 // std::string get_name() const { return name; } 22 36 23 24 25 26 27 assert(false);28 std::list<Expression *> *ret = 0; return *ret; // never reached29 37 // void set_pos( int newValue ) { pos = newValue; } 38 // int get_pos() const { return pos; } 39 virtual void set_designators( std::list<Expression *> & ) { assert(false); } 40 virtual std::list<Expression *> &get_designators() { 41 assert(false); 42 std::list<Expression *> *ret = 0; return *ret; // never reached 43 } 30 44 31 32 33 34 45 virtual Initializer *clone() const = 0; 46 virtual void accept( Visitor &v ) = 0; 47 virtual Initializer *acceptMutator( Mutator &m ) = 0; 48 virtual void print( std::ostream &os, int indent = 0 ); 35 49 private: 36 37 50 // std::string name; 51 // int pos; 38 52 }; 39 53 … … 41 55 class SingleInit : public Initializer { 42 56 public: 43 44 45 46 47 48 57 SingleInit( Expression *value, std::list< Expression *> &designators ); 58 SingleInit( const SingleInit &other ); 59 virtual ~SingleInit(); 60 61 Expression *get_value() { return value; } 62 void set_value( Expression *newValue ) { value = newValue; } 49 63 50 51 64 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; } 65 std::list<Expression *> &get_designators() { return designators; } 52 66 53 54 55 56 67 virtual SingleInit *clone() const; 68 virtual void accept( Visitor &v ) { v.visit( this ); } 69 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 70 virtual void print( std::ostream &os, int indent = 0 ); 57 71 private: 58 59 60 72 //Constant *value; 73 Expression *value; // has to be a compile-time constant 74 std::list< Expression * > designators; 61 75 }; 62 76 … … 65 79 class ListInit : public Initializer { 66 80 public: 67 68 69 81 ListInit( std::list<Initializer*> &, 82 std::list<Expression *> &designators = *(new std::list<Expression *>()) ); 83 virtual ~ListInit(); 70 84 71 72 73 74 85 void set_designators( std::list<Expression *> &newValue ) { designators = newValue; } 86 std::list<Expression *> &get_designators() { return designators; } 87 void set_initializers( std::list<Initializer*> &newValue ) { initializers = newValue; } 88 std::list<Initializer*> &get_initializers() { return initializers; } 75 89 76 77 90 std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); } 91 std::list<Initializer*>::iterator end_initializers() { return initializers.end(); } 78 92 79 80 81 82 93 virtual ListInit *clone() const; 94 virtual void accept( Visitor &v ) { v.visit( this ); } 95 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 96 virtual void print( std::ostream &os, int indent = 0 ); 83 97 private: 84 85 98 std::list<Initializer*> initializers; // order *is* important 99 std::list<Expression *> designators; 86 100 }; 87 101 88 102 #endif // INITIALIZER_H 103 104 // Local Variables: // 105 // tab-width: 4 // 106 // mode: c++ // 107 // compile-command: "make install" // 108 // End: // -
translator/SynTree/Mutator.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Mutator.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:10:46 2015 13 // Update Count : 1 14 // 15 1 16 #include <cassert> 2 17 #include "Mutator.h" … … 14 29 15 30 ObjectDecl *Mutator::mutate( ObjectDecl *objectDecl ) { 16 17 18 19 31 objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) ); 32 objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) ); 33 objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) ); 34 return objectDecl; 20 35 } 21 36 22 37 DeclarationWithType *Mutator::mutate( FunctionDecl *functionDecl ) { 23 24 25 26 38 functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) ); 39 mutateAll( functionDecl->get_oldDecls(), *this ); 40 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); 41 return functionDecl; 27 42 } 28 43 29 44 Declaration *Mutator::handleAggregateDecl( AggregateDecl *aggregateDecl ) { 30 31 32 45 mutateAll( aggregateDecl->get_parameters(), *this ); 46 mutateAll( aggregateDecl->get_members(), *this ); 47 return aggregateDecl; 33 48 } 34 49 35 50 Declaration *Mutator::mutate( StructDecl *aggregateDecl ) { 36 37 51 handleAggregateDecl( aggregateDecl ); 52 return aggregateDecl; 38 53 } 39 54 40 55 Declaration *Mutator::mutate( UnionDecl *aggregateDecl ) { 41 42 56 handleAggregateDecl( aggregateDecl ); 57 return aggregateDecl; 43 58 } 44 59 45 60 Declaration *Mutator::mutate( EnumDecl *aggregateDecl ) { 46 47 61 handleAggregateDecl( aggregateDecl ); 62 return aggregateDecl; 48 63 } 49 64 50 65 Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) { 51 52 66 handleAggregateDecl( aggregateDecl ); 67 return aggregateDecl; 53 68 } 54 69 55 70 Declaration *Mutator::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) { 56 57 58 59 71 mutateAll( typeDecl->get_parameters(), *this ); 72 mutateAll( typeDecl->get_assertions(), *this ); 73 typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) ); 74 return typeDecl; 60 75 } 61 76 62 77 TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) { 63 64 78 handleNamedTypeDecl( typeDecl ); 79 return typeDecl; 65 80 } 66 81 67 82 Declaration *Mutator::mutate( TypedefDecl *typeDecl ) { 68 69 83 handleNamedTypeDecl( typeDecl ); 84 return typeDecl; 70 85 } 71 86 72 87 CompoundStmt *Mutator::mutate( CompoundStmt *compoundStmt ) { 73 74 88 mutateAll( compoundStmt->get_kids(), *this ); 89 return compoundStmt; 75 90 } 76 91 77 92 Statement *Mutator::mutate( ExprStmt *exprStmt ) { 78 79 93 exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) ); 94 return exprStmt; 80 95 } 81 96 82 97 Statement *Mutator::mutate( IfStmt *ifStmt ) { 83 84 85 86 98 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); 99 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); 100 ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) ); 101 return ifStmt; 87 102 } 88 103 89 104 Statement *Mutator::mutate( WhileStmt *whileStmt ) { 90 91 92 105 whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) ); 106 whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) ); 107 return whileStmt; 93 108 } 94 109 95 110 Statement *Mutator::mutate( ForStmt *forStmt ) { 96 97 98 99 100 111 forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) ); 112 forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) ); 113 forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) ); 114 forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) ); 115 return forStmt; 101 116 } 102 117 103 118 Statement *Mutator::mutate( SwitchStmt *switchStmt ) { 104 105 106 119 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 120 mutateAll( switchStmt->get_branches(), *this ); 121 return switchStmt; 107 122 } 108 123 109 124 Statement *Mutator::mutate( ChooseStmt *switchStmt ) { 110 111 112 125 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); 126 mutateAll( switchStmt->get_branches(), *this ); 127 return switchStmt; 113 128 } 114 129 115 130 Statement *Mutator::mutate( FallthruStmt *fallthruStmt ) { 116 131 return fallthruStmt; 117 132 } 118 133 119 134 Statement *Mutator::mutate( CaseStmt *caseStmt ) { 120 121 122 123 135 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); 136 mutateAll (caseStmt->get_statements(), *this ); 137 138 return caseStmt; 124 139 } 125 140 126 141 Statement *Mutator::mutate( BranchStmt *branchStmt ) { 127 142 return branchStmt; 128 143 } 129 144 130 145 Statement *Mutator::mutate( ReturnStmt *returnStmt ) { 131 132 146 returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) ); 147 return returnStmt; 133 148 } 134 149 135 150 Statement *Mutator::mutate( TryStmt *tryStmt ) { 136 137 138 151 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); 152 mutateAll( tryStmt->get_catchers(), *this ); 153 return tryStmt; 139 154 } 140 155 141 156 Statement *Mutator::mutate( CatchStmt *catchStmt ) { 142 143 144 157 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); 158 catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) ); 159 return catchStmt; 145 160 } 146 161 147 162 Statement *Mutator::mutate( FinallyStmt *finalStmt ) { 148 149 163 finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) ); 164 return finalStmt; 150 165 } 151 166 152 167 NullStmt *Mutator::mutate( NullStmt *nullStmt ) { 153 168 return nullStmt; 154 169 } 155 170 156 171 Statement *Mutator::mutate( DeclStmt *declStmt ) { 157 158 172 declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) ); 173 return declStmt; 159 174 } 160 175 161 176 Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) { 162 163 164 165 177 mutateAll( applicationExpr->get_results(), *this ); 178 applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) ); 179 mutateAll( applicationExpr->get_args(), *this ); 180 return applicationExpr; 166 181 } 167 182 168 183 Expression *Mutator::mutate( UntypedExpr *untypedExpr ) { 169 170 171 184 mutateAll( untypedExpr->get_results(), *this ); 185 mutateAll( untypedExpr->get_args(), *this ); 186 return untypedExpr; 172 187 } 173 188 174 189 Expression *Mutator::mutate( NameExpr *nameExpr ) { 175 176 190 mutateAll( nameExpr->get_results(), *this ); 191 return nameExpr; 177 192 } 178 193 179 194 Expression *Mutator::mutate( AddressExpr *addressExpr ) { 180 181 182 195 mutateAll( addressExpr->get_results(), *this ); 196 addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) ); 197 return addressExpr; 183 198 } 184 199 185 200 Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) { 186 187 188 201 mutateAll( labelAddressExpr->get_results(), *this ); 202 labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) ); 203 return labelAddressExpr; 189 204 } 190 205 191 206 Expression *Mutator::mutate( CastExpr *castExpr ) { 192 193 194 207 mutateAll( castExpr->get_results(), *this ); 208 castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) ); 209 return castExpr; 195 210 } 196 211 197 212 Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) { 198 199 200 213 mutateAll( memberExpr->get_results(), *this ); 214 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 215 return memberExpr; 201 216 } 202 217 203 218 Expression *Mutator::mutate( MemberExpr *memberExpr ) { 204 205 206 219 mutateAll( memberExpr->get_results(), *this ); 220 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 221 return memberExpr; 207 222 } 208 223 209 224 Expression *Mutator::mutate( VariableExpr *variableExpr ) { 210 211 225 mutateAll( variableExpr->get_results(), *this ); 226 return variableExpr; 212 227 } 213 228 214 229 Expression *Mutator::mutate( ConstantExpr *constantExpr ) { 215 230 mutateAll( constantExpr->get_results(), *this ); 216 231 // maybeMutate( constantExpr->get_constant(), *this ) 217 232 return constantExpr; 218 233 } 219 234 220 235 Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) { 221 222 223 sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );224 225 sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) );226 227 236 mutateAll( sizeofExpr->get_results(), *this ); 237 if ( sizeofExpr->get_isType() ) { 238 sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) ); 239 } else { 240 sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) ); 241 } 242 return sizeofExpr; 228 243 } 229 244 230 245 Expression *Mutator::mutate( AttrExpr *attrExpr ) { 231 232 233 attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );234 235 attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) );236 237 246 mutateAll( attrExpr->get_results(), *this ); 247 if ( attrExpr->get_isType() ) { 248 attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) ); 249 } else { 250 attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) ); 251 } 252 return attrExpr; 238 253 } 239 254 240 255 Expression *Mutator::mutate( LogicalExpr *logicalExpr ) { 241 242 243 244 256 mutateAll( logicalExpr->get_results(), *this ); 257 logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) ); 258 logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) ); 259 return logicalExpr; 245 260 } 246 261 247 262 Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) { 248 249 250 251 252 263 mutateAll( conditionalExpr->get_results(), *this ); 264 conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) ); 265 conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) ); 266 conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) ); 267 return conditionalExpr; 253 268 } 254 269 255 270 Expression *Mutator::mutate( CommaExpr *commaExpr ) { 256 257 258 259 271 mutateAll( commaExpr->get_results(), *this ); 272 commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) ); 273 commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) ); 274 return commaExpr; 260 275 } 261 276 262 277 Expression *Mutator::mutate( TupleExpr *tupleExpr ) { 263 264 265 278 mutateAll( tupleExpr->get_results(), *this ); 279 mutateAll( tupleExpr->get_exprs(), *this ); 280 return tupleExpr; 266 281 } 267 282 268 283 Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) { 269 270 271 284 mutateAll( tupleExpr->get_results(), *this ); 285 mutateAll( tupleExpr->get_exprs(), *this ); 286 return tupleExpr; 272 287 } 273 288 274 289 Expression *Mutator::mutate( TypeExpr *typeExpr ) { 275 276 277 290 mutateAll( typeExpr->get_results(), *this ); 291 typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) ); 292 return typeExpr; 278 293 } 279 294 280 295 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) { 281 282 296 mutateAll( valofExpr->get_results(), *this ); 297 return valofExpr; 283 298 } 284 299 285 300 Type *Mutator::mutate( VoidType *voidType ) { 286 287 301 mutateAll( voidType->get_forall(), *this ); 302 return voidType; 288 303 } 289 304 290 305 Type *Mutator::mutate( BasicType *basicType ) { 291 292 306 mutateAll( basicType->get_forall(), *this ); 307 return basicType; 293 308 } 294 309 295 310 Type *Mutator::mutate( PointerType *pointerType ) { 296 297 298 311 mutateAll( pointerType->get_forall(), *this ); 312 pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) ); 313 return pointerType; 299 314 } 300 315 301 316 Type *Mutator::mutate( ArrayType *arrayType ) { 302 303 304 305 317 mutateAll( arrayType->get_forall(), *this ); 318 arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) ); 319 arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) ); 320 return arrayType; 306 321 } 307 322 308 323 Type *Mutator::mutate( FunctionType *functionType ) { 309 310 311 312 324 mutateAll( functionType->get_forall(), *this ); 325 mutateAll( functionType->get_returnVals(), *this ); 326 mutateAll( functionType->get_parameters(), *this ); 327 return functionType; 313 328 } 314 329 315 330 Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) { 316 317 318 331 mutateAll( aggregateUseType->get_forall(), *this ); 332 mutateAll( aggregateUseType->get_parameters(), *this ); 333 return aggregateUseType; 319 334 } 320 335 321 336 Type *Mutator::mutate( StructInstType *aggregateUseType ) { 322 323 337 handleReferenceToType( aggregateUseType ); 338 return aggregateUseType; 324 339 } 325 340 326 341 Type *Mutator::mutate( UnionInstType *aggregateUseType ) { 327 328 342 handleReferenceToType( aggregateUseType ); 343 return aggregateUseType; 329 344 } 330 345 331 346 Type *Mutator::mutate( EnumInstType *aggregateUseType ) { 332 333 347 handleReferenceToType( aggregateUseType ); 348 return aggregateUseType; 334 349 } 335 350 336 351 Type *Mutator::mutate( ContextInstType *aggregateUseType ) { 337 338 339 352 handleReferenceToType( aggregateUseType ); 353 mutateAll( aggregateUseType->get_members(), *this ); 354 return aggregateUseType; 340 355 } 341 356 342 357 Type *Mutator::mutate( TypeInstType *aggregateUseType ) { 343 344 358 handleReferenceToType( aggregateUseType ); 359 return aggregateUseType; 345 360 } 346 361 347 362 Type *Mutator::mutate( TupleType *tupleType ) { 348 349 350 363 mutateAll( tupleType->get_forall(), *this ); 364 mutateAll( tupleType->get_types(), *this ); 365 return tupleType; 351 366 } 352 367 353 368 Type *Mutator::mutate( TypeofType *typeofType ) { 354 355 356 369 assert( typeofType->get_expr() ); 370 typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) ); 371 return typeofType; 357 372 } 358 373 359 374 Type *Mutator::mutate( AttrType *attrType ) { 360 361 assert( attrType->get_type() );362 attrType->set_type( attrType->get_type()->acceptMutator( *this ) );363 364 assert( attrType->get_expr() );365 attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) );366 367 375 if ( attrType->get_isType() ) { 376 assert( attrType->get_type() ); 377 attrType->set_type( attrType->get_type()->acceptMutator( *this ) ); 378 } else { 379 assert( attrType->get_expr() ); 380 attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) ); 381 } 382 return attrType; 368 383 } 369 384 370 385 Initializer *Mutator::mutate( SingleInit *singleInit ) { 371 372 386 singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); 387 return singleInit; 373 388 } 374 389 375 390 Initializer *Mutator::mutate( ListInit *listInit ) { 376 377 378 391 mutateAll( listInit->get_designators(), *this ); 392 mutateAll( listInit->get_initializers(), *this ); 393 return listInit; 379 394 } 380 395 381 396 Subrange *Mutator::mutate( Subrange *subrange ) { 382 397 return subrange; 383 398 } 384 399 385 400 Constant *Mutator::mutate( Constant *constant ) { 386 return constant; 387 } 401 return constant; 402 } 403 404 // Local Variables: // 405 // tab-width: 4 // 406 // mode: c++ // 407 // compile-command: "make install" // 408 // End: // -
translator/SynTree/Mutator.h
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Mutator.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:12:28 2015 13 // Update Count : 3 14 // 1 15 #include <cassert> 2 16 … … 4 18 #include "SemanticError.h" 5 19 6 #ifndef SYNTREE_MUTATOR_H7 #define SYNTREE_MUTATOR_H20 #ifndef MUTATOR_H 21 #define MUTATOR_H 8 22 9 23 class Mutator { 10 24 protected: 11 12 25 Mutator(); 26 virtual ~Mutator(); 13 27 public: 14 15 16 17 18 19 20 21 28 virtual ObjectDecl* mutate( ObjectDecl *objectDecl ); 29 virtual DeclarationWithType* mutate( FunctionDecl *functionDecl ); 30 virtual Declaration* mutate( StructDecl *aggregateDecl ); 31 virtual Declaration* mutate( UnionDecl *aggregateDecl ); 32 virtual Declaration* mutate( EnumDecl *aggregateDecl ); 33 virtual Declaration* mutate( ContextDecl *aggregateDecl ); 34 virtual TypeDecl* mutate( TypeDecl *typeDecl ); 35 virtual Declaration* mutate( TypedefDecl *typeDecl ); 22 36 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 37 virtual CompoundStmt* mutate( CompoundStmt *compoundStmt ); 38 virtual Statement* mutate( ExprStmt *exprStmt ); 39 virtual Statement* mutate( IfStmt *ifStmt ); 40 virtual Statement* mutate( WhileStmt *whileStmt ); 41 virtual Statement* mutate( ForStmt *forStmt ); 42 virtual Statement* mutate( SwitchStmt *switchStmt ); 43 virtual Statement* mutate( ChooseStmt *chooseStmt ); 44 virtual Statement* mutate( FallthruStmt *fallthruStmt ); 45 virtual Statement* mutate( CaseStmt *caseStmt ); 46 virtual Statement* mutate( BranchStmt *branchStmt ); 47 virtual Statement* mutate( ReturnStmt *returnStmt ); 48 virtual Statement* mutate( TryStmt *returnStmt ); 49 virtual Statement* mutate( CatchStmt *catchStmt ); 50 virtual Statement* mutate( FinallyStmt *catchStmt ); 51 virtual NullStmt* mutate( NullStmt *nullStmt ); 52 virtual Statement* mutate( DeclStmt *declStmt ); 39 53 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 54 virtual Expression* mutate( ApplicationExpr *applicationExpr ); 55 virtual Expression* mutate( UntypedExpr *untypedExpr ); 56 virtual Expression* mutate( NameExpr *nameExpr ); 57 virtual Expression* mutate( AddressExpr *castExpr ); 58 virtual Expression* mutate( LabelAddressExpr *labAddressExpr ); 59 virtual Expression* mutate( CastExpr *castExpr ); 60 virtual Expression* mutate( UntypedMemberExpr *memberExpr ); 61 virtual Expression* mutate( MemberExpr *memberExpr ); 62 virtual Expression* mutate( VariableExpr *variableExpr ); 63 virtual Expression* mutate( ConstantExpr *constantExpr ); 64 virtual Expression* mutate( SizeofExpr *sizeofExpr ); 65 virtual Expression* mutate( AttrExpr *attrExpr ); 66 virtual Expression* mutate( LogicalExpr *logicalExpr ); 67 virtual Expression* mutate( ConditionalExpr *conditionalExpr ); 68 virtual Expression* mutate( CommaExpr *commaExpr ); 69 virtual Expression* mutate( TupleExpr *tupleExpr ); 70 virtual Expression* mutate( SolvedTupleExpr *tupleExpr ); 71 virtual Expression* mutate( TypeExpr *typeExpr ); 72 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 59 73 60 61 62 63 64 65 66 67 68 69 70 71 72 74 virtual Type* mutate( VoidType *basicType ); 75 virtual Type* mutate( BasicType *basicType ); 76 virtual Type* mutate( PointerType *pointerType ); 77 virtual Type* mutate( ArrayType *arrayType ); 78 virtual Type* mutate( FunctionType *functionType ); 79 virtual Type* mutate( StructInstType *aggregateUseType ); 80 virtual Type* mutate( UnionInstType *aggregateUseType ); 81 virtual Type* mutate( EnumInstType *aggregateUseType ); 82 virtual Type* mutate( ContextInstType *aggregateUseType ); 83 virtual Type* mutate( TypeInstType *aggregateUseType ); 84 virtual Type* mutate( TupleType *tupleType ); 85 virtual Type* mutate( TypeofType *typeofType ); 86 virtual Type* mutate( AttrType *attrType ); 73 87 74 75 88 virtual Initializer* mutate( SingleInit *singleInit ); 89 virtual Initializer* mutate( ListInit *listInit ); 76 90 77 91 virtual Subrange *mutate( Subrange *subrange ); 78 92 79 93 virtual Constant *mutate( Constant *constant ); 80 94 private: 81 82 83 95 virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl ); 96 virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl ); 97 virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType ); 84 98 }; 85 99 86 100 template< typename TreeType, typename MutatorType > 87 101 inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) { 88 89 TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) );90 assert( newnode );91 return newnode;102 if ( tree ) { 103 TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) ); 104 assert( newnode ); 105 return newnode; 92 106 /// return tree->acceptMutator( mutator ); 93 94 return 0;95 } 107 } else { 108 return 0; 109 } // if 96 110 } 97 111 98 112 template< typename Container, typename MutatorType > 99 113 inline void mutateAll( Container &container, MutatorType &mutator ) { 100 101 102 try {103 114 SemanticError errors; 115 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 116 try { 117 if ( *i ) { 104 118 /// *i = (*i)->acceptMutator( mutator ); 105 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );106 assert( *i );107 }108 } catch( SemanticError &e ) {109 110 }111 } 112 113 throw errors;114 } 119 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) ); 120 assert( *i ); 121 } // if 122 } catch( SemanticError &e ) { 123 errors.append( e ); 124 } // try 125 } // for 126 if ( ! errors.isEmpty() ) { 127 throw errors; 128 } // if 115 129 } 116 130 117 #endif // SYNTREE_MUTATOR_H131 #endif // MUTATOR_H 118 132 119 133 // Local Variables: // 134 // tab-width: 4 // 120 135 // mode: c++ // 121 // End: // 136 // compile-command: "make install" // 137 // End: // -
translator/SynTree/NamedTypeDecl.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // NamedTypeDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:13:19 2015 13 // Update Count : 1 14 // 15 1 16 #include "Declaration.h" 2 17 #include "Type.h" 3 18 #include "utility.h" 4 19 5 6 20 NamedTypeDecl::NamedTypeDecl( const std::string &name, StorageClass sc, Type *base ) 7 : Parent( name, sc, LinkageSpec::Cforall ), base( base ) 8 {} 21 : Parent( name, sc, LinkageSpec::Cforall ), base( base ) {} 9 22 10 23 NamedTypeDecl::NamedTypeDecl( const TypeDecl &other ) 11 : Parent( other ), base( maybeClone( other.base ) ) 12 { 13 cloneAll( other.parameters, parameters ); 14 cloneAll( other.assertions, assertions ); 24 : Parent( other ), base( maybeClone( other.base ) ) { 25 cloneAll( other.parameters, parameters ); 26 cloneAll( other.assertions, assertions ); 15 27 } 16 28 17 29 NamedTypeDecl::~NamedTypeDecl() { 18 19 20 30 delete base; 31 deleteAll( parameters ); 32 deleteAll( assertions ); 21 33 } 22 34 23 35 void NamedTypeDecl::print( std::ostream &os, int indent ) const { 24 25 26 27 os << get_name() << ": a ";28 29 30 os << storageClassName[ get_storageClass() ] << ' ';31 32 33 34 os << " for ";35 base->print( os, indent );36 37 38 os << endl << string( indent, ' ' ) << "with parameters" << endl;39 printAll( parameters, os, indent+2 );40 41 42 os << endl << string( indent, ' ' ) << "with assertions" << endl;43 printAll( assertions, os, indent+2 );44 36 using namespace std; 37 38 if ( get_name() != "" ) { 39 os << get_name() << ": a "; 40 } // if 41 if ( get_storageClass() != NoStorageClass ) { 42 os << storageClassName[ get_storageClass() ] << ' '; 43 } // if 44 os << typeString(); 45 if ( base ) { 46 os << " for "; 47 base->print( os, indent ); 48 } // if 49 if ( ! parameters.empty() ) { 50 os << endl << string( indent, ' ' ) << "with parameters" << endl; 51 printAll( parameters, os, indent+2 ); 52 } // if 53 if ( ! assertions.empty() ) { 54 os << endl << string( indent, ' ' ) << "with assertions" << endl; 55 printAll( assertions, os, indent+2 ); 56 } // if 45 57 } 46 58 47 59 void NamedTypeDecl::printShort( std::ostream &os, int indent ) const { 48 49 50 51 os << get_name() << ": a ";52 53 54 os << storageClassName[ get_storageClass() ] << ' ';55 56 57 58 os << " for ";59 base->print( os, indent );60 61 62 os << endl << string( indent, ' ' ) << "with parameters" << endl;63 printAll( parameters, os, indent+2 );64 60 using namespace std; 61 62 if ( get_name() != "" ) { 63 os << get_name() << ": a "; 64 } // if 65 if ( get_storageClass() != NoStorageClass ) { 66 os << storageClassName[ get_storageClass() ] << ' '; 67 } // if 68 os << typeString(); 69 if ( base ) { 70 os << " for "; 71 base->print( os, indent ); 72 } // if 73 if ( ! parameters.empty() ) { 74 os << endl << string( indent, ' ' ) << "with parameters" << endl; 75 printAll( parameters, os, indent+2 ); 76 } // if 65 77 } 66 78 67 79 std::string TypedefDecl::typeString() const { return "typedef"; } 80 81 // Local Variables: // 82 // tab-width: 4 // 83 // mode: c++ // 84 // compile-command: "make install" // 85 // End: // -
translator/SynTree/ObjectDecl.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // ObjectDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:14:18 2015 13 // Update Count : 2 14 // 15 1 16 #include "Declaration.h" 2 17 #include "Type.h" … … 5 20 #include "utility.h" 6 21 7 8 22 ObjectDecl::ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init ) 9 23 : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) { 10 24 } 11 25 12 26 ObjectDecl::ObjectDecl( const ObjectDecl &other ) 13 27 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) { 14 28 } 15 29 16 30 ObjectDecl::~ObjectDecl() { 17 18 19 31 delete type; 32 delete init; 33 delete bitfieldWidth; 20 34 } 21 35 22 36 void ObjectDecl::print( std::ostream &os, int indent ) const { 23 24 os << get_name() << ": a ";25 } 37 if ( get_name() != "" ) { 38 os << get_name() << ": a "; 39 } // if 26 40 27 28 os << LinkageSpec::toString( get_linkage() ) << " ";29 } 41 if ( get_linkage() != LinkageSpec::Cforall ) { 42 os << LinkageSpec::toString( get_linkage() ) << " "; 43 } // if 30 44 31 32 os << storageClassName[ get_storageClass() ] << ' ';33 } 45 if ( get_storageClass() != NoStorageClass ) { 46 os << storageClassName[ get_storageClass() ] << ' '; 47 } // if 34 48 35 36 get_type()->print( os, indent );37 38 os << "untyped entity ";39 } 49 if ( get_type() ) { 50 get_type()->print( os, indent ); 51 } else { 52 os << "untyped entity "; 53 } // if 40 54 41 42 os << "with initializer ";43 init->print( os, indent );44 } 55 if ( init ) { 56 os << "with initializer "; 57 init->print( os, indent ); 58 } // if 45 59 46 47 os << "with bitfield width ";48 bitfieldWidth->print( os );49 } 60 if ( bitfieldWidth ) { 61 os << "with bitfield width "; 62 bitfieldWidth->print( os ); 63 } // if 50 64 } 51 65 52 66 void ObjectDecl::printShort( std::ostream &os, int indent ) const { 53 54 os << get_name() << ": a ";55 } 67 if ( get_name() != "" ) { 68 os << get_name() << ": a "; 69 } // if 56 70 57 58 os << storageClassName[ get_storageClass() ] << ' ';59 } 71 if ( get_storageClass() != NoStorageClass ) { 72 os << storageClassName[ get_storageClass() ] << ' '; 73 } // if 60 74 61 62 get_type()->print( os, indent );63 64 os << "untyped entity ";65 } 75 if ( get_type() ) { 76 get_type()->print( os, indent ); 77 } else { 78 os << "untyped entity "; 79 } // if 66 80 67 68 os << "with bitfield width ";69 bitfieldWidth->print( os );70 } 81 if ( bitfieldWidth ) { 82 os << "with bitfield width "; 83 bitfieldWidth->print( os ); 84 } // if 71 85 } 86 87 // Local Variables: // 88 // tab-width: 4 // 89 // mode: c++ // 90 // compile-command: "make install" // 91 // End: // -
translator/SynTree/PointerType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: PointerType.cc,v 1.8 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // PointerType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:15:16 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" … … 10 18 #include "utility.h" 11 19 12 13 20 PointerType::PointerType( const Type::Qualifiers &tq, Type *base ) 14 : Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false ) 15 { 16 base->set_isLvalue( false ); 21 : Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false ) { 22 base->set_isLvalue( false ); 17 23 } 18 24 19 25 PointerType::PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ) 20 : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) 21 { 22 base->set_isLvalue( false ); 26 : Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) { 27 base->set_isLvalue( false ); 23 28 } 24 29 25 30 PointerType::PointerType( const PointerType &other ) 26 : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ), 27 isVarLen( other.isVarLen ), isStatic( other.isStatic ) 28 { 31 : Type( other ), base( maybeClone( other.base ) ), dimension( maybeClone( other.dimension ) ), 32 isVarLen( other.isVarLen ), isStatic( other.isStatic ) { 29 33 } 30 34 31 PointerType::~PointerType() 32 { 33 delete base; 34 delete dimension; 35 PointerType::~PointerType() { 36 delete base; 37 delete dimension; 35 38 } 36 39 37 void 38 PointerType::print( std::ostream &os, int indent ) const 39 { 40 Type::print( os, indent ); 41 os << "pointer to "; 42 if ( isStatic ) { 43 os << "static "; 44 } 45 if ( isVarLen ) { 46 os << "variable length array of "; 47 } else if ( dimension ) { 48 os << "array of "; 49 dimension->print( os, indent ); 50 } 51 if ( base ) { 52 base->print( os, indent ); 53 } 40 void PointerType::print( std::ostream &os, int indent ) const { 41 Type::print( os, indent ); 42 os << "pointer to "; 43 if ( isStatic ) { 44 os << "static "; 45 } // if 46 if ( isVarLen ) { 47 os << "variable length array of "; 48 } else if ( dimension ) { 49 os << "array of "; 50 dimension->print( os, indent ); 51 } // if 52 if ( base ) { 53 base->print( os, indent ); 54 } // if 54 55 } 55 56 57 // Local Variables: // 58 // tab-width: 4 // 59 // mode: c++ // 60 // compile-command: "make install" // 61 // End: // -
translator/SynTree/ReferenceToType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: ReferenceToType.cc,v 1.16 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // ReferenceToType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:49:00 2015 13 // Update Count : 2 14 // 7 15 8 16 #include <string> … … 15 23 #include "utility.h" 16 24 17 18 ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) 19 : Type( tq ), name( name ) 20 { 25 ReferenceToType::ReferenceToType( const Type::Qualifiers &tq, const std::string &name ) : Type( tq ), name( name ) { 21 26 } 22 27 23 ReferenceToType::ReferenceToType( const ReferenceToType &other ) 24 : Type( other ), name( other.name ) 25 { 28 ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ) { 26 29 cloneAll( other.parameters, parameters ); 27 30 } 28 31 29 ReferenceToType::~ReferenceToType() 30 { 32 ReferenceToType::~ReferenceToType() { 31 33 deleteAll( parameters ); 32 34 } 33 35 34 void 35 ReferenceToType::print( std::ostream &os, int indent ) const 36 { 36 void ReferenceToType::print( std::ostream &os, int indent ) const { 37 37 using std::endl; 38 38 … … 40 40 os << "instance of " << typeString() << " " << name << " "; 41 41 if ( ! parameters.empty() ) { 42 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;43 printAll( parameters, os, indent+2 );44 } 42 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 43 printAll( parameters, os, indent+2 ); 44 } // if 45 45 } 46 46 47 47 namespace { 48 49 void 50 doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) 51 {52 std::list< Declaration* > found;53 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 54 if ( (*i)->get_name() == name ) {55 found.push_back( *i);48 void doLookup( const std::list< Declaration* > &members, const std::list< TypeDecl* > &parms, const std::list< Expression* > &args, const std::string &name, std::list< Declaration* > &foundDecls ) { 49 std::list< Declaration* > found; 50 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 51 if ( (*i)->get_name() == name ) { 52 found.push_back( *i ); 53 } // if 54 } // for 55 applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) ); 56 56 } 57 }58 applySubstitution( parms.begin(), parms.end(), args.begin(), found.begin(), found.end(), back_inserter( foundDecls ) );59 }60 61 57 } // namespace 62 58 63 59 std::string StructInstType::typeString() const { return "struct"; } 64 60 65 void 66 StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const 67 { 61 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 68 62 assert( baseStruct ); 69 63 doLookup( baseStruct->get_members(), baseStruct->get_parameters(), parameters, name, foundDecls ); … … 72 66 std::string UnionInstType::typeString() const { return "union"; } 73 67 74 void 75 UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const 76 { 68 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 77 69 assert( baseUnion ); 78 70 doLookup( baseUnion->get_members(), baseUnion->get_parameters(), parameters, name, foundDecls ); … … 83 75 std::string ContextInstType::typeString() const { return "context"; } 84 76 85 ContextInstType::ContextInstType( const ContextInstType &other ) 86 : Parent( other ) 87 { 77 ContextInstType::ContextInstType( const ContextInstType &other ) : Parent( other ) { 88 78 cloneAll( other.members, members ); 89 79 } 90 80 91 ContextInstType::~ContextInstType() 92 { 81 ContextInstType::~ContextInstType() { 93 82 deleteAll( members ); 94 83 } 95 84 96 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) 97 { 85 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) { 98 86 set_baseType( baseType ); 99 87 } 100 88 101 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) 102 { 89 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ) : Parent( tq, name ), baseType( 0 ), isFtype( isFtype ) { 103 90 } 104 91 105 void TypeInstType::set_baseType( TypeDecl *newValue ) 106 { 92 void TypeInstType::set_baseType( TypeDecl *newValue ) { 107 93 baseType = newValue; 108 94 isFtype = newValue->get_kind() == TypeDecl::Ftype; … … 111 97 std::string TypeInstType::typeString() const { return "type"; } 112 98 113 void 114 TypeInstType::print( std::ostream &os, int indent ) const 115 { 99 void TypeInstType::print( std::ostream &os, int indent ) const { 116 100 using std::endl; 117 101 … … 119 103 os << "instance of " << typeString() << " " << get_name() << " (" << ( isFtype ? "" : "not" ) << " a function type) "; 120 104 if ( ! parameters.empty() ) { 121 os << endl << std::string( indent, ' ' ) << "with parameters" << endl;122 printAll( parameters, os, indent+2 );123 } 105 os << endl << std::string( indent, ' ' ) << "with parameters" << endl; 106 printAll( parameters, os, indent+2 ); 107 } // if 124 108 } 125 109 110 // Local Variables: // 111 // tab-width: 4 // 112 // mode: c++ // 113 // compile-command: "make install" // 114 // End: // -
translator/SynTree/Statement.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Statement.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:55:19 2015 13 // Update Count : 2 14 // 15 1 16 #include <functional> 2 17 #include <algorithm> … … 13 28 using std::endl; 14 29 15 16 Statement::Statement(std::list<Label> _labels): 17 labels(_labels) {} 18 19 void Statement::print(std::ostream &, int indent) {} 30 Statement::Statement( std::list<Label> _labels ) : labels(_labels ) {} 31 32 void Statement::print( std::ostream &, int indent ) {} 20 33 21 34 Statement::~Statement() {} 22 35 23 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ): 24 Statement(_labels), expr(_expr) {} 36 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement(_labels ), expr(_expr ) {} 25 37 26 38 ExprStmt::~ExprStmt() {} 27 39 28 40 void ExprStmt::print( std::ostream &os, int indent ) { 29 30 expr->print(os, indent + 2);41 os << "\r" << string(indent, ' ') << "Expression Statement:" << endl; 42 expr->print( os, indent + 2 ); 31 43 } 32 44 33 45 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 34 46 35 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) 36 throw (SemanticError) : 37 Statement(labels), target(_target), type(_type) 38 { 39 //actually this is a syntactic error signaled by the parser 40 if (type == BranchStmt::Goto && target.size() == 0) 41 throw SemanticError("goto without target"); 42 } 43 44 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type) 45 throw (SemanticError) : 46 Statement(labels), computedTarget(_computedTarget), type(_type) 47 { 48 if (type != BranchStmt::Goto || computedTarget == 0) 49 throw SemanticError("Computed target not valid in branch statement"); 47 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) : 48 Statement( labels ), target(_target ), type(_type ) { 49 //actually this is a syntactic error signaled by the parser 50 if ( type == BranchStmt::Goto && target.size() == 0 ) 51 throw SemanticError("goto without target"); 52 } 53 54 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) : 55 Statement( labels ), computedTarget(_computedTarget ), type(_type ) { 56 if ( type != BranchStmt::Goto || computedTarget == 0 ) 57 throw SemanticError("Computed target not valid in branch statement"); 50 58 } 51 59 52 60 void BranchStmt::print( std::ostream &os, int indent ){ 53 os << "\r" << string(indent, ' ') << "Branch (" << brType[type] << ")" << endl ; 54 } 55 56 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : 57 Statement( labels ), expr( _expr ), isThrow( throwP ) {} 61 os << "\r" << string( indent, ' ') << "Branch (" << brType[type] << ")" << endl ; 62 } 63 64 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr, bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP ) {} 58 65 59 66 ReturnStmt::~ReturnStmt() { 60 delete expr; 61 } 62 63 void ReturnStmt::print( std::ostream &os, int indent ){ 64 os << "\r" << std::string(indent, ' ') << string ( isThrow? "Throw":"Return" ) << " Statement, returning: "; 65 if (expr != 0) expr->print(os); 66 os << endl; 67 } 68 67 delete expr; 68 } 69 70 void ReturnStmt::print( std::ostream &os, int indent ) { 71 os << "\r" << std::string( indent, ' ') << string ( isThrow? "Throw":"Return" ) << " Statement, returning: "; 72 if ( expr != 0 ) expr->print( os ); 73 os << endl; 74 } 69 75 70 76 IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ): 71 Statement(_labels), condition(_condition), thenPart(_thenPart), elsePart(_elsePart) {}77 Statement(_labels ), condition(_condition ), thenPart(_thenPart ), elsePart(_elsePart ) {} 72 78 73 79 IfStmt::~IfStmt() {} 74 80 75 81 void IfStmt::print( std::ostream &os, int indent ){ 76 os << "\r" << string(indent, ' ') << "If on condition: " << endl ;77 condition->print(os, indent + 4);78 79 os << string(indent, ' ') << ".... and branches: " << endl;80 81 thenPart->print(os, indent + 4);82 83 if (elsePart != 0){84 elsePart->print(os, indent + 4);85 } 86 } 87 88 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches):89 Statement(_labels), condition(_condition), branches(_branches) 90 {}82 os << "\r" << string( indent, ' ') << "If on condition: " << endl ; 83 condition->print( os, indent + 4 ); 84 85 os << string( indent, ' ') << ".... and branches: " << endl; 86 87 thenPart->print( os, indent + 4 ); 88 89 if ( elsePart != 0 ) { 90 elsePart->print( os, indent + 4 ); 91 } // if 92 } 93 94 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): 95 Statement(_labels ), condition(_condition ), branches(_branches ) { 96 } 91 97 92 98 SwitchStmt::~SwitchStmt() { 93 delete condition; 94 // destroy branches 95 } 96 97 void SwitchStmt::add_case(CaseStmt *c) {} 98 99 void SwitchStmt::print(std::ostream &os, int indent) { 100 os << "\r" << string(indent, ' ') << "Switch on condition: "; 101 condition->print(os); 102 os << endl; 103 104 // branches 105 std::list<Statement *>::iterator i; 106 for (i = branches.begin(); i != branches.end(); i++) 107 (*i)->print(os, indent + 4); 108 109 //for_each(branches.begin(), branches.end(), mem_fun(bind1st(&Statement::print), os)); 110 } 111 112 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, 113 std::list<Statement *> &_statements, bool deflt ) 114 throw (SemanticError) : 115 Statement(_labels), condition(_condition), stmts(_statements), _isDefault(deflt) 116 { 117 if (isDefault() && condition != 0) 118 throw SemanticError("default with conditions"); 99 delete condition; 100 // destroy branches 101 } 102 103 void SwitchStmt::add_case( CaseStmt *c ) {} 104 105 void SwitchStmt::print( std::ostream &os, int indent ) { 106 os << "\r" << string( indent, ' ') << "Switch on condition: "; 107 condition->print( os ); 108 os << endl; 109 110 // branches 111 std::list<Statement *>::iterator i; 112 for ( i = branches.begin(); i != branches.end(); i++) 113 (*i )->print( os, indent + 4 ); 114 115 //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); 116 } 117 118 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) : 119 Statement(_labels ), condition(_condition ), stmts(_statements ), _isDefault( deflt ) { 120 if ( isDefault() && condition != 0 ) 121 throw SemanticError("default with conditions"); 119 122 } 120 123 121 124 CaseStmt::~CaseStmt() { 122 123 } 124 125 void CaseStmt::print( std::ostream &os, int indent) {126 os << "\r" << string(indent, ' ');127 128 if (isDefault())129 os << "Default ";130 131 os << "Case ";132 condition->print(os);133 } 134 135 136 137 138 for (i = stmts.begin(); i != stmts.end(); i++)139 (*i)->print(os, indent + 4);125 delete condition; 126 } 127 128 void CaseStmt::print( std::ostream &os, int indent ) { 129 os << "\r" << string( indent, ' '); 130 131 if ( isDefault()) 132 os << "Default "; 133 else { 134 os << "Case "; 135 condition->print( os ); 136 } // if 137 138 os << endl; 139 140 std::list<Statement *>::iterator i; 141 for ( i = stmts.begin(); i != stmts.end(); i++) 142 (*i )->print( os, indent + 4 ); 140 143 } 141 144 142 145 //ChooseStmt::ChooseStmt( std::list<Label> labels, Expression *condition, Statement *body ) {} 143 ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches):144 Statement(_labels), condition(_condition), branches(_branches) 145 {}146 ChooseStmt::ChooseStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_branches ): 147 Statement(_labels ), condition(_condition ), branches(_branches ) { 148 } 146 149 147 150 ChooseStmt::~ChooseStmt() { 148 delete condition; 149 } 150 151 void ChooseStmt::add_case(CaseStmt *c) {} 152 153 void ChooseStmt::print(std::ostream &os, int indent) { 154 os << "\r" << string(indent, ' ') << "Choose on condition: "; 155 condition->print(os); 156 os << endl; 157 158 // branches 159 std::list<Statement *>::iterator i; 160 for (i = branches.begin(); i != branches.end(); i++) 161 (*i)->print(os, indent + 4); 162 163 //for_each(branches.begin(), branches.end(), mem_fun(bind1st(&Statement::print), os)); 164 } 165 166 void FallthruStmt::print(std::ostream &os, int indent) { 167 os << "\r" << string(indent, ' ') << "Fall-through statement" << endl; 168 } 169 170 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, 171 Statement *body_, bool isDoWhile_ ): 172 Statement( labels ), condition(condition_), body(body_), isDoWhile(isDoWhile_) 173 {} 151 delete condition; 152 } 153 154 void ChooseStmt::add_case( CaseStmt *c ) {} 155 156 void ChooseStmt::print( std::ostream &os, int indent ) { 157 os << "\r" << string( indent, ' ') << "Choose on condition: "; 158 condition->print( os ); 159 os << endl; 160 161 // branches 162 std::list<Statement *>::iterator i; 163 for ( i = branches.begin(); i != branches.end(); i++) 164 (*i )->print( os, indent + 4 ); 165 166 //for_each( branches.begin(), branches.end(), mem_fun( bind1st(&Statement::print ), os )); 167 } 168 169 void FallthruStmt::print( std::ostream &os, int indent ) { 170 os << "\r" << string( indent, ' ') << "Fall-through statement" << endl; 171 } 172 173 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ): 174 Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) { 175 } 174 176 175 177 WhileStmt::~WhileStmt(){ 176 178 delete body; 177 179 } 178 180 179 181 void WhileStmt::print( std::ostream &os, int indent ){ 180 os << "\r" << string(indent, ' ') << "While on condition: " << endl ; 181 condition->print(os, indent + 4); 182 183 os << string(indent, ' ') << ".... with body: " << endl; 184 185 if (body != 0) body->print(os, indent + 4); 186 } 187 188 ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_, 189 Expression *condition_, Expression *increment_, Statement *body_ ): 190 Statement( labels ), initialization( initialization_ ), 191 condition( condition_ ), increment( increment_ ), body( body_ ) 192 { } 193 182 os << "\r" << string( indent, ' ') << "While on condition: " << endl ; 183 condition->print( os, indent + 4 ); 184 185 os << string( indent, ' ') << ".... with body: " << endl; 186 187 if ( body != 0 ) body->print( os, indent + 4 ); 188 } 189 190 ForStmt::ForStmt( std::list<Label> labels, Statement *initialization_, Expression *condition_, Expression *increment_, Statement *body_ ): 191 Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) { 192 } 194 193 195 194 ForStmt::~ForStmt() { 196 197 198 199 195 delete initialization; 196 delete condition; 197 delete increment; 198 delete body; 200 199 } 201 200 202 201 void ForStmt::print( std::ostream &os, int indent ){ 203 os << "\r" << string(indent, ' ') << "For Statement" << endl ;204 205 os << "\r" << string(indent + 2, ' ') << "initialization: \n";206 if (initialization != 0)207 initialization->print(os, indent + 4);208 209 os << "\n\r" << string(indent + 2, ' ') << "condition: \n";210 if (condition != 0)211 condition->print(os, indent + 4);212 213 os << "\n\r" << string(indent + 2, ' ') << "increment: \n";214 if (increment != 0)215 increment->print(os, indent + 4);216 217 os << "\n\r" << string(indent + 2, ' ') << "statement block: \n";218 if (body != 0)219 body->print(os, indent + 4);220 221 202 os << "\r" << string( indent, ' ') << "For Statement" << endl ; 203 204 os << "\r" << string( indent + 2, ' ') << "initialization: \n"; 205 if ( initialization != 0 ) 206 initialization->print( os, indent + 4 ); 207 208 os << "\n\r" << string( indent + 2, ' ') << "condition: \n"; 209 if ( condition != 0 ) 210 condition->print( os, indent + 4 ); 211 212 os << "\n\r" << string( indent + 2, ' ') << "increment: \n"; 213 if ( increment != 0 ) 214 increment->print( os, indent + 4 ); 215 216 os << "\n\r" << string( indent + 2, ' ') << "statement block: \n"; 217 if ( body != 0 ) 218 body->print( os, indent + 4 ); 219 220 os << endl; 222 221 } 223 222 224 223 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_handlers, FinallyStmt *_finallyBlock ) : 225 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) 226 {}227 228 TryStmt::TryStmt( const TryStmt &other ) : Statement( other.labels ) {229 230 std::copy( other.handlers.begin(), other.handlers.end(), back_inserter(handlers) );231 224 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) { 225 } 226 227 TryStmt::TryStmt( const TryStmt &other ) : Statement( other.labels ) { 228 block = other.block; 229 std::copy( other.handlers.begin(), other.handlers.end(), back_inserter( handlers ) ); 230 finallyBlock = other.finallyBlock; 232 231 } 233 232 234 233 TryStmt::~TryStmt(){ 235 234 delete block; 236 235 } 237 236 238 237 void TryStmt::print( std::ostream &os, int indent ) { 239 os << "\r" << string(indent, ' ') << "Try Statement" << endl;240 os << string(indent + 2, ' ') << "with block: " << endl;241 block->print(os, indent + 4);242 243 244 os << string(indent + 2, ' ') << "and handlers: " << endl;245 246 for (i = handlers.begin(); i != handlers.end(); i++)247 (*i)->print(os, indent + 4);248 249 250 251 os << string(indent + 2, ' ') << "Finally block: " << endl;252 finallyBlock->print(os, indent + 4 );253 } 238 os << "\r" << string( indent, ' ') << "Try Statement" << endl; 239 os << string( indent + 2, ' ') << "with block: " << endl; 240 block->print( os, indent + 4 ); 241 242 // handlers 243 os << string( indent + 2, ' ') << "and handlers: " << endl; 244 std::list<Statement *>::iterator i; 245 for ( i = handlers.begin(); i != handlers.end(); i++) 246 (*i )->print( os, indent + 4 ); 247 248 // finally block 249 if ( finallyBlock != 0 ) { 250 os << string( indent + 2, ' ') << "Finally block: " << endl; 251 finallyBlock->print( os, indent + 4 ); 252 } // if 254 253 } 255 254 256 255 CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool isCatchRest ) : 257 Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) 258 {}256 Statement( labels ), decl ( _decl ), body( _body ), catchRest ( isCatchRest ) { 257 } 259 258 260 259 CatchStmt::~CatchStmt(){ 261 262 260 delete decl; 261 delete body; 263 262 } 264 263 265 264 void CatchStmt::print( std::ostream &os, int indent ) { 266 os << "\r" << string(indent, ' ') << "Catch Statement" << endl; 267 268 os << "\r" << string(indent, ' ') << "... catching" << endl; 269 if ( decl ) { 270 decl->printShort( os, indent + 4 ); 271 os << endl; 272 } else if ( catchRest ) 273 os << "\r" << string(indent + 4 , ' ') << "the rest" << endl; 274 else 275 os << "\r" << string(indent + 4 , ' ') << ">>> Error: this catch clause must have a declaration <<<" << endl; 276 } 277 278 279 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : 280 Statement( labels ), block( _block ) 281 { 282 assert( labels.empty() ); // finally statement cannot be labeled 283 } 284 285 FinallyStmt::~FinallyStmt(){ 286 delete block; 265 os << "\r" << string( indent, ' ') << "Catch Statement" << endl; 266 267 os << "\r" << string( indent, ' ') << "... catching" << endl; 268 if ( decl ) { 269 decl->printShort( os, indent + 4 ); 270 os << endl; 271 } else if ( catchRest ) 272 os << "\r" << string( indent + 4 , ' ') << "the rest" << endl; 273 else 274 os << "\r" << string( indent + 4 , ' ') << ">>> Error: this catch clause must have a declaration <<<" << endl; 275 } 276 277 278 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) { 279 assert( labels.empty() ); // finally statement cannot be labeled 280 } 281 282 FinallyStmt::~FinallyStmt() { 283 delete block; 287 284 } 288 285 289 286 void FinallyStmt::print( std::ostream &os, int indent ) { 290 os << "\r" << string(indent, ' ') << "Finally Statement" << endl;291 os << string(indent + 2, ' ') << "with block: " << endl;292 block->print(os, indent + 4);287 os << "\r" << string( indent, ' ') << "Finally Statement" << endl; 288 os << string( indent + 2, ' ') << "with block: " << endl; 289 block->print( os, indent + 4 ); 293 290 } 294 291 … … 298 295 299 296 void NullStmt::print( std::ostream &os, int indent ) { 300 os << "\r" << string(indent, ' ') << "Null Statement" << endl ; 301 } 302 303 304 305 /* 306 Local Variables: 307 compile-command: "cd ..; gmake" 308 End: 309 */ 297 os << "\r" << string( indent, ' ') << "Null Statement" << endl ; 298 } 299 300 // Local Variables: // 301 // tab-width: 4 // 302 // mode: c++ // 303 // compile-command: "make install" // 304 // End: // -
translator/SynTree/Statement.h
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Statement.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:57:40 2015 13 // Update Count : 2 14 // 15 1 16 #ifndef STATEMENT_H 2 17 #define STATEMENT_H … … 7 22 #include "Common/SemanticError.h" 8 23 9 10 class Statement 11 { 12 public: 13 Statement( std::list<Label> labels ); 14 virtual ~Statement(); 15 16 std::list<Label> & get_labels() { return labels; } 17 18 virtual Statement *clone() const = 0; 19 virtual void accept( Visitor &v ) = 0; 20 virtual Statement *acceptMutator( Mutator &m ) = 0; 21 virtual void print( std::ostream &os, int indent = 0 ); 22 23 protected: 24 std::list<Label> labels; 25 }; 26 27 class CompoundStmt : public Statement 28 { 29 public: 30 CompoundStmt( std::list<Label> labels ); 31 CompoundStmt( const CompoundStmt &other ); 32 virtual ~CompoundStmt(); 33 34 std::list<Statement*>& get_kids() { return kids; } 35 36 virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); } 37 virtual void accept( Visitor &v ) { v.visit( this ); } 38 virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 39 virtual void print( std::ostream &os, int indent = 0 ); 40 41 private: 42 std::list<Statement*> kids; 43 }; 44 45 class ExprStmt : public Statement 46 { 47 public: 48 ExprStmt( std::list<Label> labels, Expression *expr ); 49 virtual ~ExprStmt(); 50 51 Expression *get_expr() { return expr; } 52 void set_expr( Expression *newValue ) { expr = newValue; } 53 54 virtual ExprStmt *clone() const { return new ExprStmt( *this ); } 55 virtual void accept( Visitor &v ) { v.visit( this ); } 56 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 57 virtual void print( std::ostream &os, int indent = 0 ); 58 59 private: 60 Expression *expr; 61 }; 62 63 class IfStmt : public Statement 64 { 65 public: 66 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 67 virtual ~IfStmt(); 68 69 Expression *get_condition() { return condition; } 70 void set_condition( Expression *newValue ) { condition = newValue; } 71 Statement *get_thenPart() { return thenPart; } 72 void set_thenPart( Statement *newValue ) { thenPart = newValue; } 73 Statement *get_elsePart() { return elsePart; } 74 void set_elsePart( Statement *newValue ) { elsePart = newValue; } 75 76 virtual IfStmt *clone() const { return new IfStmt( *this ); } 77 virtual void accept( Visitor &v ) { v.visit( this ); } 78 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 79 virtual void print( std::ostream &os, int indent = 0 ); 80 81 private: 82 Expression *condition; 83 Statement *thenPart; 84 Statement *elsePart; 85 }; 86 87 class SwitchStmt : public Statement 88 { 89 public: 90 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 91 virtual ~SwitchStmt(); 92 93 Expression *get_condition() { return condition; } 94 void set_condition( Expression *newValue ) { condition = newValue; } 95 96 std::list<Statement *>& get_branches() { return branches; } 97 void add_case( CaseStmt * ); 98 99 virtual void accept( Visitor &v ) { v.visit( this ); } 100 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 101 102 virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); } 103 virtual void print( std::ostream &os, int indent = 0 ); 104 105 private: 106 Expression * condition; 107 std::list<Statement *> branches; // should be list of CaseStmt 108 }; 109 110 class ChooseStmt : public Statement 111 { 112 public: 113 ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 114 virtual ~ChooseStmt(); 115 116 Expression *get_condition() { return condition; } 117 void set_condition( Expression *newValue ) { condition = newValue; } 118 119 std::list<Statement *>& get_branches() { return branches; } 120 void add_case( CaseStmt * ); 121 122 123 virtual void accept( Visitor &v ) { v.visit( this ); } 124 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 125 126 virtual ChooseStmt *clone() const { return new ChooseStmt( *this ); } 127 virtual void print( std::ostream &os, int indent = 0 ); 128 129 private: 130 Expression *condition; 131 std::list<Statement *> branches; // should be list of CaseStmt 24 class Statement { 25 public: 26 Statement( std::list<Label> labels ); 27 virtual ~Statement(); 28 29 std::list<Label> & get_labels() { return labels; } 30 31 virtual Statement *clone() const = 0; 32 virtual void accept( Visitor &v ) = 0; 33 virtual Statement *acceptMutator( Mutator &m ) = 0; 34 virtual void print( std::ostream &os, int indent = 0 ); 35 protected: 36 std::list<Label> labels; 37 }; 38 39 class CompoundStmt : public Statement { 40 public: 41 CompoundStmt( std::list<Label> labels ); 42 CompoundStmt( const CompoundStmt &other ); 43 virtual ~CompoundStmt(); 44 45 std::list<Statement*>& get_kids() { return kids; } 46 47 virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); } 48 virtual void accept( Visitor &v ) { v.visit( this ); } 49 virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 50 virtual void print( std::ostream &os, int indent = 0 ); 51 private: 52 std::list<Statement*> kids; 53 }; 54 55 class ExprStmt : public Statement { 56 public: 57 ExprStmt( std::list<Label> labels, Expression *expr ); 58 virtual ~ExprStmt(); 59 60 Expression *get_expr() { return expr; } 61 void set_expr( Expression *newValue ) { expr = newValue; } 62 63 virtual ExprStmt *clone() const { return new ExprStmt( *this ); } 64 virtual void accept( Visitor &v ) { v.visit( this ); } 65 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 66 virtual void print( std::ostream &os, int indent = 0 ); 67 private: 68 Expression *expr; 69 }; 70 71 class IfStmt : public Statement { 72 public: 73 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 74 virtual ~IfStmt(); 75 76 Expression *get_condition() { return condition; } 77 void set_condition( Expression *newValue ) { condition = newValue; } 78 Statement *get_thenPart() { return thenPart; } 79 void set_thenPart( Statement *newValue ) { thenPart = newValue; } 80 Statement *get_elsePart() { return elsePart; } 81 void set_elsePart( Statement *newValue ) { elsePart = newValue; } 82 83 virtual IfStmt *clone() const { return new IfStmt( *this ); } 84 virtual void accept( Visitor &v ) { v.visit( this ); } 85 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 86 virtual void print( std::ostream &os, int indent = 0 ); 87 private: 88 Expression *condition; 89 Statement *thenPart; 90 Statement *elsePart; 91 }; 92 93 class SwitchStmt : public Statement { 94 public: 95 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 96 virtual ~SwitchStmt(); 97 98 Expression *get_condition() { return condition; } 99 void set_condition( Expression *newValue ) { condition = newValue; } 100 101 std::list<Statement *>& get_branches() { return branches; } 102 void add_case( CaseStmt * ); 103 104 virtual void accept( Visitor &v ) { v.visit( this ); } 105 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 106 107 virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); } 108 virtual void print( std::ostream &os, int indent = 0 ); 109 private: 110 Expression * condition; 111 std::list<Statement *> branches; // should be list of CaseStmt 112 }; 113 114 class ChooseStmt : public Statement { 115 public: 116 ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); 117 virtual ~ChooseStmt(); 118 119 Expression *get_condition() { return condition; } 120 void set_condition( Expression *newValue ) { condition = newValue; } 121 122 std::list<Statement *>& get_branches() { return branches; } 123 void add_case( CaseStmt * ); 124 125 virtual void accept( Visitor &v ) { v.visit( this ); } 126 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 127 128 virtual ChooseStmt *clone() const { return new ChooseStmt( *this ); } 129 virtual void print( std::ostream &os, int indent = 0 ); 130 private: 131 Expression *condition; 132 std::list<Statement *> branches; // should be list of CaseStmt 132 133 }; 133 134 134 135 class FallthruStmt : public Statement { 135 public: 136 FallthruStmt( std::list<Label> labels ) : Statement( labels ) { } 137 138 virtual void accept( Visitor &v ) { v.visit( this ); } 139 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 140 141 virtual FallthruStmt *clone() const { return new FallthruStmt( *this ); } 142 virtual void print( std::ostream &os, int indent = 0 ); 143 }; 144 145 class CaseStmt : public Statement 146 { 147 public: 148 CaseStmt( std::list<Label> labels, Expression *conditions, 149 std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); 150 virtual ~CaseStmt(); 151 152 bool isDefault() { return _isDefault; } 153 void set_default(bool b) { _isDefault = b; } 154 155 Expression * &get_condition() { return condition; } 156 void set_condition( Expression *newValue ) { condition = newValue; } 157 158 std::list<Statement *> &get_statements() { return stmts; } 159 void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; } 160 161 virtual void accept( Visitor &v ) { v.visit( this ); } 162 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 163 164 virtual CaseStmt *clone() const { return new CaseStmt( *this ); } 165 virtual void print( std::ostream &os, int indent = 0 ); 166 167 private: 168 Expression * condition; 169 std::list<Statement *> stmts; 170 bool _isDefault; 171 }; 172 173 class WhileStmt : public Statement 174 { 175 public: 176 WhileStmt( std::list<Label> labels, Expression *condition, 177 Statement *body, bool isDoWhile = false ); 178 virtual ~WhileStmt(); 179 180 Expression *get_condition() { return condition; } 181 void set_condition( Expression *newValue ) { condition = newValue; } 182 Statement *get_body() { return body; } 183 void set_body( Statement *newValue ) { body = newValue; } 184 bool get_isDoWhile() { return isDoWhile; } 185 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } 186 187 virtual WhileStmt *clone() const { return new WhileStmt( *this ); } 188 virtual void accept( Visitor &v ) { v.visit( this ); } 189 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 190 virtual void print( std::ostream &os, int indent = 0 ); 191 192 private: 193 Expression *condition; 194 Statement *body; 195 bool isDoWhile; 196 }; 197 198 class ForStmt : public Statement 199 { 200 public: 201 ForStmt( std::list<Label> labels, Statement *initialization = 0, 202 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 203 virtual ~ForStmt(); 204 205 Statement *get_initialization() { return initialization; } 206 void set_initialization( Statement *newValue ) { initialization = newValue; } 207 Expression *get_condition() { return condition; } 208 void set_condition( Expression *newValue ) { condition = newValue; } 209 Expression *get_increment() { return increment; } 210 void set_increment( Expression *newValue ) { increment = newValue; } 211 Statement *get_body() { return body; } 212 void set_body( Statement *newValue ) { body = newValue; } 213 214 virtual ForStmt *clone() const { return new ForStmt( *this ); } 215 virtual void accept( Visitor &v ) { v.visit( this ); } 216 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 217 virtual void print( std::ostream &os, int indent = 0 ); 218 219 private: 220 Statement *initialization; 221 Expression *condition; 222 Expression *increment; 223 Statement *body; 224 }; 225 226 class BranchStmt : public Statement 227 { 228 public: 229 230 enum Type { Goto = 0 , Break, Continue }; 231 232 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); 233 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError); 234 virtual ~BranchStmt() {} 235 236 Label get_target() { return target; } 237 void set_target( Label newValue ) { target = newValue; } 238 239 Expression *get_computedTarget() { return computedTarget; } 240 void set_target( Expression * newValue ) { computedTarget = newValue; } 241 242 Type get_type() { return type; } 243 const char *get_typename() { return brType[ type ]; } 244 245 virtual BranchStmt *clone() const { return new BranchStmt( *this ); } 246 virtual void accept( Visitor &v ) { v.visit( this ); } 247 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 248 virtual void print( std::ostream &os, int indent = 0 ); 249 250 private: 251 static const char *brType[]; 252 Label target; 253 Expression *computedTarget; 254 Type type; 255 }; 256 257 class ReturnStmt : public Statement 258 { 259 public: 260 ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false ); 261 virtual ~ReturnStmt(); 262 263 Expression *get_expr() { return expr; } 264 void set_expr( Expression *newValue ) { expr = newValue; } 265 266 virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); } 267 virtual void accept( Visitor &v ) { v.visit( this ); } 268 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 269 virtual void print( std::ostream &os, int indent = 0 ); 270 271 private: 272 Expression *expr; 273 bool isThrow; 274 }; 275 276 277 class NullStmt : public CompoundStmt 278 { 279 public: 280 NullStmt(); 281 NullStmt( std::list<Label> labels ); 282 virtual ~NullStmt(); 283 284 virtual NullStmt *clone() const { return new NullStmt( *this ); } 285 virtual void accept( Visitor &v ) { v.visit( this ); } 286 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 287 virtual void print( std::ostream &os, int indent = 0 ); 288 289 private: 290 }; 291 292 class TryStmt : public Statement 293 { 294 public: 295 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 ); 296 TryStmt( const TryStmt &other ); 297 virtual ~TryStmt(); 298 299 CompoundStmt *get_block() const { return block; } 300 void set_block( CompoundStmt *newValue ) { block = newValue; } 301 std::list<Statement *>& get_catchers() { return handlers; } 302 303 FinallyStmt *get_finally() const { return finallyBlock; } 304 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; } 305 306 virtual TryStmt *clone() const { return new TryStmt( *this ); } 307 virtual void accept( Visitor &v ) { v.visit( this ); } 308 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 309 virtual void print( std::ostream &os, int indent = 0 ); 310 311 private: 312 CompoundStmt *block; 313 std::list<Statement *> handlers; 314 FinallyStmt *finallyBlock; 136 public: 137 FallthruStmt( std::list<Label> labels ) : Statement( labels ) { } 138 139 virtual void accept( Visitor &v ) { v.visit( this ); } 140 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 141 142 virtual FallthruStmt *clone() const { return new FallthruStmt( *this ); } 143 virtual void print( std::ostream &os, int indent = 0 ); 144 }; 145 146 class CaseStmt : public Statement { 147 public: 148 CaseStmt( std::list<Label> labels, Expression *conditions, 149 std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); 150 virtual ~CaseStmt(); 151 152 bool isDefault() { return _isDefault; } 153 void set_default(bool b) { _isDefault = b; } 154 155 Expression * &get_condition() { return condition; } 156 void set_condition( Expression *newValue ) { condition = newValue; } 157 158 std::list<Statement *> &get_statements() { return stmts; } 159 void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; } 160 161 virtual void accept( Visitor &v ) { v.visit( this ); } 162 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 163 164 virtual CaseStmt *clone() const { return new CaseStmt( *this ); } 165 virtual void print( std::ostream &os, int indent = 0 ); 166 private: 167 Expression * condition; 168 std::list<Statement *> stmts; 169 bool _isDefault; 170 }; 171 172 class WhileStmt : public Statement { 173 public: 174 WhileStmt( std::list<Label> labels, Expression *condition, 175 Statement *body, bool isDoWhile = false ); 176 virtual ~WhileStmt(); 177 178 Expression *get_condition() { return condition; } 179 void set_condition( Expression *newValue ) { condition = newValue; } 180 Statement *get_body() { return body; } 181 void set_body( Statement *newValue ) { body = newValue; } 182 bool get_isDoWhile() { return isDoWhile; } 183 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } 184 185 virtual WhileStmt *clone() const { return new WhileStmt( *this ); } 186 virtual void accept( Visitor &v ) { v.visit( this ); } 187 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 188 virtual void print( std::ostream &os, int indent = 0 ); 189 private: 190 Expression *condition; 191 Statement *body; 192 bool isDoWhile; 193 }; 194 195 class ForStmt : public Statement { 196 public: 197 ForStmt( std::list<Label> labels, Statement *initialization = 0, 198 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 199 virtual ~ForStmt(); 200 201 Statement *get_initialization() { return initialization; } 202 void set_initialization( Statement *newValue ) { initialization = newValue; } 203 Expression *get_condition() { return condition; } 204 void set_condition( Expression *newValue ) { condition = newValue; } 205 Expression *get_increment() { return increment; } 206 void set_increment( Expression *newValue ) { increment = newValue; } 207 Statement *get_body() { return body; } 208 void set_body( Statement *newValue ) { body = newValue; } 209 210 virtual ForStmt *clone() const { return new ForStmt( *this ); } 211 virtual void accept( Visitor &v ) { v.visit( this ); } 212 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 213 virtual void print( std::ostream &os, int indent = 0 ); 214 private: 215 Statement *initialization; 216 Expression *condition; 217 Expression *increment; 218 Statement *body; 219 }; 220 221 class BranchStmt : public Statement { 222 public: 223 enum Type { Goto = 0 , Break, Continue }; 224 225 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); 226 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError); 227 virtual ~BranchStmt() {} 228 229 Label get_target() { return target; } 230 void set_target( Label newValue ) { target = newValue; } 231 232 Expression *get_computedTarget() { return computedTarget; } 233 void set_target( Expression * newValue ) { computedTarget = newValue; } 234 235 Type get_type() { return type; } 236 const char *get_typename() { return brType[ type ]; } 237 238 virtual BranchStmt *clone() const { return new BranchStmt( *this ); } 239 virtual void accept( Visitor &v ) { v.visit( this ); } 240 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 241 virtual void print( std::ostream &os, int indent = 0 ); 242 private: 243 static const char *brType[]; 244 Label target; 245 Expression *computedTarget; 246 Type type; 247 }; 248 249 class ReturnStmt : public Statement { 250 public: 251 ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false ); 252 virtual ~ReturnStmt(); 253 254 Expression *get_expr() { return expr; } 255 void set_expr( Expression *newValue ) { expr = newValue; } 256 257 virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); } 258 virtual void accept( Visitor &v ) { v.visit( this ); } 259 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 260 virtual void print( std::ostream &os, int indent = 0 ); 261 private: 262 Expression *expr; 263 bool isThrow; 264 }; 265 266 267 class NullStmt : public CompoundStmt { 268 public: 269 NullStmt(); 270 NullStmt( std::list<Label> labels ); 271 virtual ~NullStmt(); 272 273 virtual NullStmt *clone() const { return new NullStmt( *this ); } 274 virtual void accept( Visitor &v ) { v.visit( this ); } 275 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 276 virtual void print( std::ostream &os, int indent = 0 ); 277 278 private: 279 }; 280 281 class TryStmt : public Statement { 282 public: 283 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 ); 284 TryStmt( const TryStmt &other ); 285 virtual ~TryStmt(); 286 287 CompoundStmt *get_block() const { return block; } 288 void set_block( CompoundStmt *newValue ) { block = newValue; } 289 std::list<Statement *>& get_catchers() { return handlers; } 290 291 FinallyStmt *get_finally() const { return finallyBlock; } 292 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; } 293 294 virtual TryStmt *clone() const { return new TryStmt( *this ); } 295 virtual void accept( Visitor &v ) { v.visit( this ); } 296 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 297 virtual void print( std::ostream &os, int indent = 0 ); 298 299 private: 300 CompoundStmt *block; 301 std::list<Statement *> handlers; 302 FinallyStmt *finallyBlock; 315 303 }; 316 304 317 class CatchStmt : public Statement 318 { 319 public: 320 CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false ); 321 virtual ~CatchStmt(); 322 323 Declaration *get_decl() { return decl; } 324 void set_decl( Declaration *newValue ) { decl = newValue; } 325 326 Statement *get_body() { return body; } 327 void set_body( Statement *newValue ) { body = newValue; } 328 329 virtual CatchStmt *clone() const { return new CatchStmt( *this ); } 330 virtual void accept( Visitor &v ) { v.visit( this ); } 331 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 332 virtual void print( std::ostream &os, int indent = 0 ); 333 334 private: 335 Declaration *decl; 336 Statement *body; 337 bool catchRest; 338 }; 339 340 class FinallyStmt : public Statement 341 { 342 public: 343 FinallyStmt( std::list<Label> labels, CompoundStmt *block ); 344 virtual ~FinallyStmt(); 345 346 CompoundStmt *get_block() const { return block; } 347 void set_block( CompoundStmt *newValue ) { block = newValue; } 348 349 virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); } 350 virtual void accept( Visitor &v ) { v.visit( this ); } 351 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 352 virtual void print( std::ostream &os, int indent = 0 ); 353 354 private: 355 CompoundStmt *block; 305 class CatchStmt : public Statement { 306 public: 307 CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false ); 308 virtual ~CatchStmt(); 309 310 Declaration *get_decl() { return decl; } 311 void set_decl( Declaration *newValue ) { decl = newValue; } 312 313 Statement *get_body() { return body; } 314 void set_body( Statement *newValue ) { body = newValue; } 315 316 virtual CatchStmt *clone() const { return new CatchStmt( *this ); } 317 virtual void accept( Visitor &v ) { v.visit( this ); } 318 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 319 virtual void print( std::ostream &os, int indent = 0 ); 320 321 private: 322 Declaration *decl; 323 Statement *body; 324 bool catchRest; 325 }; 326 327 class FinallyStmt : public Statement { 328 public: 329 FinallyStmt( std::list<Label> labels, CompoundStmt *block ); 330 virtual ~FinallyStmt(); 331 332 CompoundStmt *get_block() const { return block; } 333 void set_block( CompoundStmt *newValue ) { block = newValue; } 334 335 virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); } 336 virtual void accept( Visitor &v ) { v.visit( this ); } 337 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 338 virtual void print( std::ostream &os, int indent = 0 ); 339 private: 340 CompoundStmt *block; 356 341 }; 357 342 358 343 359 344 // represents a declaration that occurs as part of a compound statement 360 class DeclStmt : public Statement 361 { 362 public: 363 DeclStmt( std::list<Label> labels, Declaration *decl ); 364 DeclStmt( const DeclStmt &other ); 365 virtual ~DeclStmt(); 366 367 Declaration *get_decl() { return decl; } 368 void set_decl( Declaration *newValue ) { decl = newValue; } 369 370 virtual DeclStmt *clone() const { return new DeclStmt( *this ); } 371 virtual void accept( Visitor &v ) { v.visit( this ); } 372 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 373 virtual void print( std::ostream &os, int indent = 0 ); 374 375 private: 376 Declaration *decl; 377 }; 378 379 380 381 #endif /* #ifndef STATEMENT_H */ 382 383 /* 384 Local Variables: 385 mode: c++ 386 End: 387 */ 345 class DeclStmt : public Statement { 346 public: 347 DeclStmt( std::list<Label> labels, Declaration *decl ); 348 DeclStmt( const DeclStmt &other ); 349 virtual ~DeclStmt(); 350 351 Declaration *get_decl() { return decl; } 352 void set_decl( Declaration *newValue ) { decl = newValue; } 353 354 virtual DeclStmt *clone() const { return new DeclStmt( *this ); } 355 virtual void accept( Visitor &v ) { v.visit( this ); } 356 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 357 virtual void print( std::ostream &os, int indent = 0 ); 358 private: 359 Declaration *decl; 360 }; 361 362 #endif // STATEMENT_H 363 364 // Local Variables: // 365 // tab-width: 4 // 366 // mode: c++ // 367 // compile-command: "make install" // 368 // End: // -
translator/SynTree/SynTree.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: SynTree.h,v 1.22 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 * Forward declarations for syntax tree classes, so that they can be mutually 7 * interdependent 8 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // SynTree.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:58:22 2015 13 // Update Count : 1 14 // 9 15 10 16 #ifndef SYNTREE_H … … 15 21 #include <map> 16 22 #include <iostream> 17 18 23 19 24 class Declaration; … … 102 107 class TypeSubstitution; 103 108 109 #endif // SYNTREE_H 104 110 105 #endif /* #ifndef SYNTREE_H */ 111 // Local Variables: // 112 // tab-width: 4 // 113 // mode: c++ // 114 // compile-command: "make install" // 115 // End: // -
translator/SynTree/TupleExpr.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TupleExpr.cc,v 1.11 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // TupleExpr.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 10:59:19 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Expression.h" 9 17 #include "utility.h" 10 18 11 12 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) 13 { 19 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) { 14 20 } 15 21 16 TupleExpr::TupleExpr( const TupleExpr &other ) 17 : Expression( other ) 18 { 19 cloneAll( other.exprs, exprs ); 22 TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) { 23 cloneAll( other.exprs, exprs ); 20 24 } 21 25 22 TupleExpr::~TupleExpr() 23 { 24 deleteAll( exprs ); 26 TupleExpr::~TupleExpr() { 27 deleteAll( exprs ); 25 28 } 26 29 27 void 28 TupleExpr::print( std::ostream &os, int indent ) const 29 { 30 os << std::string( indent, ' ' ) << "Tuple:" << std::endl; 31 printAll( exprs, os, indent+2 ); 32 Expression::print( os, indent ); 30 void TupleExpr::print( std::ostream &os, int indent ) const { 31 os << std::string( indent, ' ' ) << "Tuple:" << std::endl; 32 printAll( exprs, os, indent+2 ); 33 Expression::print( os, indent ); 33 34 } 34 35 35 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) 36 : Expression( _aname ) 37 { 38 std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs)); 36 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) : Expression( _aname ) { 37 std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs)); 39 38 } 40 39 41 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) 42 : Expression( other ) 43 { 44 cloneAll( other.exprs, exprs ); 40 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) : Expression( other ) { 41 cloneAll( other.exprs, exprs ); 45 42 } 46 43 47 void 48 SolvedTupleExpr::print( std::ostream &os, int indent ) const 49 { 50 os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl; 51 printAll( exprs, os, indent+2 ); 52 Expression::print( os, indent ); 44 void SolvedTupleExpr::print( std::ostream &os, int indent ) const { 45 os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl; 46 printAll( exprs, os, indent+2 ); 47 Expression::print( os, indent ); 53 48 } 54 49 50 // Local Variables: // 51 // tab-width: 4 // 52 // mode: c++ // 53 // compile-command: "make install" // 54 // End: // -
translator/SynTree/TupleType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TupleType.cc,v 1.6 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // TupleType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:00:01 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" 9 17 #include "utility.h" 10 18 11 12 TupleType::TupleType( const Type::Qualifiers &tq ) 13 : Type( tq ) 14 { 19 TupleType::TupleType( const Type::Qualifiers &tq ) : Type( tq ) { 15 20 } 16 21 17 TupleType::TupleType( const TupleType& other ) 18 : Type( other ) 19 { 20 cloneAll( other.types, types ); 22 TupleType::TupleType( const TupleType& other ) : Type( other ) { 23 cloneAll( other.types, types ); 21 24 } 22 25 23 TupleType::~TupleType() 24 { 25 deleteAll( types ); 26 TupleType::~TupleType() { 27 deleteAll( types ); 26 28 } 27 29 28 void 29 TupleType::print( std::ostream &os, int indent ) const 30 { 31 Type::print( os, indent ); 32 os << "tuple of types" << std::endl; 33 printAll( types, os, indent+2 ); 30 void TupleType::print( std::ostream &os, int indent ) const { 31 Type::print( os, indent ); 32 os << "tuple of types" << std::endl; 33 printAll( types, os, indent+2 ); 34 34 } 35 35 36 // Local Variables: // 37 // tab-width: 4 // 38 // mode: c++ // 39 // compile-command: "make install" // 40 // End: // -
translator/SynTree/Type.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Type.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:00:29 2015 13 // Update Count : 1 14 // 15 1 16 #include "SynTree.h" 2 17 #include "Visitor.h" … … 41 56 void Type::print( std::ostream &os, int indent ) const { 42 57 if ( ! forall.empty() ) { 43 os << "forall" << std::endl;44 printAll( forall, os, indent + 4 );45 os << std::string( indent+2, ' ' );58 os << "forall" << std::endl; 59 printAll( forall, os, indent + 4 ); 60 os << std::string( indent+2, ' ' ); 46 61 } // if 47 62 if ( tq.isConst ) { 48 os << "const ";63 os << "const "; 49 64 } // if 50 65 if ( tq.isVolatile ) { 51 os << "volatile ";66 os << "volatile "; 52 67 } // if 53 68 if ( tq.isRestrict ) { 54 os << "restrict ";69 os << "restrict "; 55 70 } // if 56 71 if ( tq.isLvalue ) { 57 os << "lvalue ";72 os << "lvalue "; 58 73 } // if 59 74 if ( tq.isAtomic ) { 60 os << "_Atomic ";75 os << "_Atomic "; 61 76 } // if 62 77 } 78 79 // Local Variables: // 80 // tab-width: 4 // 81 // mode: c++ // 82 // compile-command: "make install" // 83 // End: // -
translator/SynTree/Type.h
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Type.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:01:40 2015 13 // Update Count : 1 14 // 15 1 16 #ifndef TYPE_H 2 17 #define TYPE_H … … 6 21 #include "Mutator.h" 7 22 8 9 23 class Type { 10 24 public: 11 12 13 14 15 Qualifiers &operator+=( const Qualifiers &other );16 Qualifiers &operator-=( const Qualifiers &other );17 Qualifiers operator+( const Type::Qualifiers &other );18 bool operator==( const Qualifiers &other );19 bool operator!=( const Qualifiers &other );20 bool operator<=( const Qualifiers &other );21 bool operator>=( const Qualifiers &other );22 bool operator<( const Qualifiers &other );23 bool operator>( const Qualifiers &other );24 25 bool isConst;26 bool isVolatile;27 bool isRestrict;28 bool isLvalue;29 bool isAtomic;30 bool isAttribute;31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 private: 57 58 25 struct Qualifiers { 26 Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {} 27 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {} 28 29 Qualifiers &operator+=( const Qualifiers &other ); 30 Qualifiers &operator-=( const Qualifiers &other ); 31 Qualifiers operator+( const Type::Qualifiers &other ); 32 bool operator==( const Qualifiers &other ); 33 bool operator!=( const Qualifiers &other ); 34 bool operator<=( const Qualifiers &other ); 35 bool operator>=( const Qualifiers &other ); 36 bool operator<( const Qualifiers &other ); 37 bool operator>( const Qualifiers &other ); 38 39 bool isConst; 40 bool isVolatile; 41 bool isRestrict; 42 bool isLvalue; 43 bool isAtomic; 44 bool isAttribute; 45 }; 46 47 Type( const Qualifiers &tq ); 48 Type( const Type &other ); 49 virtual ~Type(); 50 51 Qualifiers &get_qualifiers() { return tq; } 52 bool get_isConst() { return tq.isConst; } 53 bool get_isVolatile() { return tq.isVolatile; } 54 bool get_isRestrict() { return tq.isRestrict; } 55 bool get_isLvalue() { return tq.isLvalue; } 56 bool get_isAtomic() { return tq.isAtomic; } 57 bool get_isAttribute() { return tq.isAttribute; } 58 void set_isConst( bool newValue ) { tq.isConst = newValue; } 59 void set_iisVolatile( bool newValue ) { tq.isVolatile = newValue; } 60 void set_isRestrict( bool newValue ) { tq.isRestrict = newValue; } 61 void set_isLvalue( bool newValue ) { tq.isLvalue = newValue; } 62 void set_isAtomic( bool newValue ) { tq.isAtomic = newValue; } 63 void set_isAttribute( bool newValue ) { tq.isAttribute = newValue; } 64 std::list<TypeDecl*>& get_forall() { return forall; } 65 66 virtual Type *clone() const = 0; 67 virtual void accept( Visitor &v ) = 0; 68 virtual Type *acceptMutator( Mutator &m ) = 0; 69 virtual void print( std::ostream &os, int indent = 0 ) const; 70 private: 71 Qualifiers tq; 72 std::list<TypeDecl*> forall; 59 73 }; 60 74 61 75 class VoidType : public Type { 62 76 public: 63 64 65 66 67 68 77 VoidType( const Type::Qualifiers &tq ); 78 79 virtual VoidType *clone() const { return new VoidType( *this ); } 80 virtual void accept( Visitor &v ) { v.visit( this ); } 81 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 82 virtual void print( std::ostream &os, int indent = 0 ) const; 69 83 }; 70 84 71 85 class BasicType : public Type { 72 86 public: 73 74 Bool,75 Char,76 SignedChar,77 UnsignedChar,78 ShortSignedInt,79 ShortUnsignedInt,80 SignedInt,81 UnsignedInt,82 LongSignedInt,83 LongUnsignedInt,84 LongLongSignedInt,85 LongLongUnsignedInt,86 Float,87 Double,88 LongDouble,89 FloatComplex,90 DoubleComplex,91 LongDoubleComplex,92 FloatImaginary,93 DoubleImaginary,94 LongDoubleImaginary,95 NUMBER_OF_BASIC_TYPES96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 private: 112 87 enum Kind { 88 Bool, 89 Char, 90 SignedChar, 91 UnsignedChar, 92 ShortSignedInt, 93 ShortUnsignedInt, 94 SignedInt, 95 UnsignedInt, 96 LongSignedInt, 97 LongUnsignedInt, 98 LongLongSignedInt, 99 LongLongUnsignedInt, 100 Float, 101 Double, 102 LongDouble, 103 FloatComplex, 104 DoubleComplex, 105 LongDoubleComplex, 106 FloatImaginary, 107 DoubleImaginary, 108 LongDoubleImaginary, 109 NUMBER_OF_BASIC_TYPES 110 }; 111 112 static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind 113 114 BasicType( const Type::Qualifiers &tq, Kind bt ); 115 116 Kind get_kind() { return kind; } 117 void set_kind( Kind newValue ) { kind = newValue; } 118 119 virtual BasicType *clone() const { return new BasicType( *this ); } 120 virtual void accept( Visitor &v ) { v.visit( this ); } 121 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 122 virtual void print( std::ostream &os, int indent = 0 ) const; 123 124 bool isInteger() const; 125 private: 126 Kind kind; 113 127 }; 114 128 115 129 class PointerType : public Type { 116 130 public: 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 private: 136 137 138 139 140 141 131 PointerType( const Type::Qualifiers &tq, Type *base ); 132 PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ); 133 PointerType( const PointerType& ); 134 virtual ~PointerType(); 135 136 Type *get_base() { return base; } 137 void set_base( Type *newValue ) { base = newValue; } 138 Expression *get_dimension() { return dimension; } 139 void set_dimension( Expression *newValue ) { dimension = newValue; } 140 bool get_isVarLen() { return isVarLen; } 141 void set_isVarLen( bool newValue ) { isVarLen = newValue; } 142 bool get_isStatic() { return isStatic; } 143 void set_isStatic( bool newValue ) { isStatic = newValue; } 144 145 virtual PointerType *clone() const { return new PointerType( *this ); } 146 virtual void accept( Visitor &v ) { v.visit( this ); } 147 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 148 virtual void print( std::ostream &os, int indent = 0 ) const; 149 private: 150 Type *base; 151 152 // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] ) 153 Expression *dimension; 154 bool isVarLen; 155 bool isStatic; 142 156 }; 143 157 144 158 class ArrayType : public Type { 145 159 public: 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 private: 164 165 166 167 160 ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic ); 161 ArrayType( const ArrayType& ); 162 virtual ~ArrayType(); 163 164 Type *get_base() { return base; } 165 void set_base( Type *newValue ) { base = newValue; } 166 Expression *get_dimension() { return dimension; } 167 void set_dimension( Expression *newValue ) { dimension = newValue; } 168 bool get_isVarLen() { return isVarLen; } 169 void set_isVarLen( bool newValue ) { isVarLen = newValue; } 170 bool get_isStatic() { return isStatic; } 171 void set_isStatic( bool newValue ) { isStatic = newValue; } 172 173 virtual ArrayType *clone() const { return new ArrayType( *this ); } 174 virtual void accept( Visitor &v ) { v.visit( this ); } 175 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 176 virtual void print( std::ostream &os, int indent = 0 ) const; 177 private: 178 Type *base; 179 Expression *dimension; 180 bool isVarLen; 181 bool isStatic; 168 182 }; 169 183 170 184 class FunctionType : public Type { 171 185 public: 172 173 174 175 176 177 178 179 180 181 182 183 184 185 private: 186 187 188 189 190 191 192 193 186 FunctionType( const Type::Qualifiers &tq, bool isVarArgs ); 187 FunctionType( const FunctionType& ); 188 virtual ~FunctionType(); 189 190 std::list<DeclarationWithType*>& get_returnVals() { return returnVals; } 191 std::list<DeclarationWithType*>& get_parameters() { return parameters; } 192 bool get_isVarArgs() { return isVarArgs; } 193 void set_isVarArgs( bool newValue ) { isVarArgs = newValue; } 194 195 virtual FunctionType *clone() const { return new FunctionType( *this ); } 196 virtual void accept( Visitor &v ) { v.visit( this ); } 197 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 198 virtual void print( std::ostream &os, int indent = 0 ) const; 199 private: 200 std::list<DeclarationWithType*> returnVals; 201 std::list<DeclarationWithType*> parameters; 202 203 // does the function accept a variable number of arguments following the arguments 204 // specified in the parameters list. This could be because of 205 // - an ellipsis in a prototype declaration 206 // - an unprototyped declaration 207 bool isVarArgs; 194 208 }; 195 209 196 210 class ReferenceToType : public Type { 197 211 public: 198 199 200 201 202 203 204 205 206 207 208 209 212 ReferenceToType( const Type::Qualifiers &tq, const std::string &name ); 213 ReferenceToType( const ReferenceToType &other ); 214 virtual ~ReferenceToType(); 215 216 std::string get_name() const { return name; } 217 void set_name( std::string newValue ) { name = newValue; } 218 std::list< Expression* >& get_parameters() { return parameters; } 219 220 virtual ReferenceToType *clone() const = 0; 221 virtual void accept( Visitor &v ) = 0; 222 virtual Type *acceptMutator( Mutator &m ) = 0; 223 virtual void print( std::ostream &os, int indent = 0 ) const; 210 224 protected: 211 212 213 private: 214 225 virtual std::string typeString() const = 0; 226 std::list< Expression* > parameters; 227 private: 228 std::string name; 215 229 }; 216 230 217 231 class StructInstType : public ReferenceToType { 218 typedef ReferenceToType Parent; 219 public: 220 StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {} 221 StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {} 222 223 StructDecl *get_baseStruct() const { return baseStruct; } 224 void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } 225 226 // a utility function 227 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 228 229 virtual StructInstType *clone() const { return new StructInstType( *this ); } 230 virtual void accept( Visitor &v ) { v.visit( this ); } 231 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 232 233 private: 234 virtual std::string typeString() const; 235 236 // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, 237 // where the structure used in this type is actually defined 238 StructDecl *baseStruct; 232 typedef ReferenceToType Parent; 233 public: 234 StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {} 235 StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {} 236 237 StructDecl *get_baseStruct() const { return baseStruct; } 238 void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } 239 240 // a utility function 241 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 242 243 virtual StructInstType *clone() const { return new StructInstType( *this ); } 244 virtual void accept( Visitor &v ) { v.visit( this ); } 245 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 246 private: 247 virtual std::string typeString() const; 248 249 // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, 250 // where the structure used in this type is actually defined 251 StructDecl *baseStruct; 239 252 }; 240 253 241 254 class UnionInstType : public ReferenceToType { 242 243 public: 244 245 246 247 248 249 250 251 252 253 254 255 256 private: 257 258 259 260 261 255 typedef ReferenceToType Parent; 256 public: 257 UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {} 258 UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {} 259 260 UnionDecl *get_baseUnion() const { return baseUnion; } 261 void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; } 262 263 // a utility function 264 void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; 265 266 virtual UnionInstType *clone() const { return new UnionInstType( *this ); } 267 virtual void accept( Visitor &v ) { v.visit( this ); } 268 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 269 private: 270 virtual std::string typeString() const; 271 272 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, 273 // where the union used in this type is actually defined 274 UnionDecl *baseUnion; 262 275 }; 263 276 264 277 class EnumInstType : public ReferenceToType { 265 typedef ReferenceToType Parent; 266 public: 267 EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} 268 EnumInstType( const EnumInstType &other ) : Parent( other ) {} 269 270 virtual EnumInstType *clone() const { return new EnumInstType( *this ); } 271 virtual void accept( Visitor &v ) { v.visit( this ); } 272 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 273 274 private: 275 virtual std::string typeString() const; 278 typedef ReferenceToType Parent; 279 public: 280 EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} 281 EnumInstType( const EnumInstType &other ) : Parent( other ) {} 282 283 virtual EnumInstType *clone() const { return new EnumInstType( *this ); } 284 virtual void accept( Visitor &v ) { v.visit( this ); } 285 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 286 private: 287 virtual std::string typeString() const; 276 288 }; 277 289 278 290 class ContextInstType : public ReferenceToType { 279 280 public: 281 282 283 284 285 286 287 288 289 290 private: 291 292 293 294 295 291 typedef ReferenceToType Parent; 292 public: 293 ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} 294 ContextInstType( const ContextInstType &other ); 295 ~ContextInstType(); 296 297 std::list< Declaration* >& get_members() { return members; } 298 299 virtual ContextInstType *clone() const { return new ContextInstType( *this ); } 300 virtual void accept( Visitor &v ) { v.visit( this ); } 301 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 302 private: 303 virtual std::string typeString() const; 304 305 // this member is filled in by the validate pass, which instantiates the members of the correponding 306 // aggregate with the actual type parameters specified for this use of the context 307 std::list< Declaration* > members; 296 308 }; 297 309 298 310 class TypeInstType : public ReferenceToType { 299 300 public: 301 302 303 304 305 306 307 308 309 310 311 312 313 314 private: 315 316 317 318 319 311 typedef ReferenceToType Parent; 312 public: 313 TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ); 314 TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ); 315 TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) {} 316 317 TypeDecl *get_baseType() const { return baseType; } 318 void set_baseType( TypeDecl *newValue ); 319 bool get_isFtype() const { return isFtype; } 320 void set_isFtype( bool newValue ) { isFtype = newValue; } 321 322 virtual TypeInstType *clone() const { return new TypeInstType( *this ); } 323 virtual void accept( Visitor &v ) { v.visit( this ); } 324 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 325 virtual void print( std::ostream &os, int indent = 0 ) const; 326 private: 327 virtual std::string typeString() const; 328 // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree, 329 // where the type used here is actually defined 330 TypeDecl *baseType; 331 bool isFtype; 320 332 }; 321 333 322 334 class TupleType : public Type { 323 335 public: 324 325 326 327 328 329 330 331 332 333 334 private: 335 336 TupleType( const Type::Qualifiers &tq ); 337 TupleType( const TupleType& ); 338 virtual ~TupleType(); 339 340 std::list<Type*>& get_types() { return types; } 341 342 virtual TupleType *clone() const { return new TupleType( *this ); } 343 virtual void accept( Visitor &v ) { v.visit( this ); } 344 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 345 virtual void print( std::ostream &os, int indent = 0 ) const; 346 private: 347 std::list<Type*> types; 336 348 }; 337 349 338 350 class TypeofType : public Type { 339 351 public: 340 341 342 343 344 345 346 347 348 349 350 351 private: 352 352 TypeofType( const Type::Qualifiers &tq, Expression *expr ); 353 TypeofType( const TypeofType& ); 354 virtual ~TypeofType(); 355 356 Expression *get_expr() const { return expr; } 357 void set_expr( Expression *newValue ) { expr = newValue; } 358 359 virtual TypeofType *clone() const { return new TypeofType( *this ); } 360 virtual void accept( Visitor &v ) { v.visit( this ); } 361 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 362 virtual void print( std::ostream &os, int indent = 0 ) const; 363 private: 364 Expression *expr; 353 365 }; 354 366 355 367 class AttrType : public Type { 356 368 public: 357 AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr ); 358 AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type ); 359 AttrType( const AttrType& ); 360 virtual ~AttrType(); 361 362 std::string get_name() const { return name; } 363 void set_name( const std::string &newValue ) { name = newValue; } 364 Expression *get_expr() const { return expr; } 365 void set_expr( Expression *newValue ) { expr = newValue; } 366 Type *get_type() const { return type; } 367 void set_type( Type *newValue ) { type = newValue; } 368 bool get_isType() const { return isType; } 369 void set_isType( bool newValue ) { isType = newValue; } 370 371 virtual AttrType *clone() const { return new AttrType( *this ); } 372 virtual void accept( Visitor &v ) { v.visit( this ); } 373 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 374 virtual void print( std::ostream &os, int indent = 0 ) const; 375 376 private: 377 std::string name; 378 Expression *expr; 379 Type *type; 380 bool isType; 369 AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr ); 370 AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type ); 371 AttrType( const AttrType& ); 372 virtual ~AttrType(); 373 374 std::string get_name() const { return name; } 375 void set_name( const std::string &newValue ) { name = newValue; } 376 Expression *get_expr() const { return expr; } 377 void set_expr( Expression *newValue ) { expr = newValue; } 378 Type *get_type() const { return type; } 379 void set_type( Type *newValue ) { type = newValue; } 380 bool get_isType() const { return isType; } 381 void set_isType( bool newValue ) { isType = newValue; } 382 383 virtual AttrType *clone() const { return new AttrType( *this ); } 384 virtual void accept( Visitor &v ) { v.visit( this ); } 385 virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } 386 virtual void print( std::ostream &os, int indent = 0 ) const; 387 private: 388 std::string name; 389 Expression *expr; 390 Type *type; 391 bool isType; 381 392 }; 382 393 383 394 inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) { 384 385 386 387 388 389 395 isConst |= other.isConst; 396 isVolatile |= other.isVolatile; 397 isRestrict |= other.isRestrict; 398 isLvalue |= other.isLvalue; 399 isAtomic |= other.isAtomic; 400 return *this; 390 401 } 391 402 392 403 inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) { 393 394 395 396 397 404 if ( other.isConst ) isConst = 0; 405 if ( other.isVolatile ) isVolatile = 0; 406 if ( other.isRestrict ) isRestrict = 0; 407 if ( other.isAtomic ) isAtomic = 0; 408 return *this; 398 409 } 399 410 400 411 inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) { 401 402 403 412 Qualifiers q = other; 413 q += *this; 414 return q; 404 415 } 405 416 406 417 inline bool Type::Qualifiers::operator==( const Qualifiers &other ) { 407 408 && isVolatile == other.isVolatile409 && isRestrict == other.isRestrict418 return isConst == other.isConst 419 && isVolatile == other.isVolatile 420 && isRestrict == other.isRestrict 410 421 // && isLvalue == other.isLvalue 411 && isAtomic == other.isAtomic;422 && isAtomic == other.isAtomic; 412 423 } 413 424 414 425 inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) { 415 416 || isVolatile != other.isVolatile417 || isRestrict != other.isRestrict426 return isConst != other.isConst 427 || isVolatile != other.isVolatile 428 || isRestrict != other.isRestrict 418 429 // || isLvalue != other.isLvalue 419 || isAtomic != other.isAtomic;430 || isAtomic != other.isAtomic; 420 431 } 421 432 422 433 inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) { 423 424 && isVolatile <= other.isVolatile425 && isRestrict <= other.isRestrict434 return isConst <= other.isConst 435 && isVolatile <= other.isVolatile 436 && isRestrict <= other.isRestrict 426 437 // && isLvalue >= other.isLvalue 427 && isAtomic == other.isAtomic;438 && isAtomic == other.isAtomic; 428 439 } 429 440 430 441 inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) { 431 432 && isVolatile >= other.isVolatile433 && isRestrict >= other.isRestrict442 return isConst >= other.isConst 443 && isVolatile >= other.isVolatile 444 && isRestrict >= other.isRestrict 434 445 // && isLvalue <= other.isLvalue 435 && isAtomic == other.isAtomic;446 && isAtomic == other.isAtomic; 436 447 } 437 448 438 449 inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) { 439 450 return operator!=( other ) && operator<=( other ); 440 451 } 441 452 442 453 inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) { 443 454 return operator!=( other ) && operator>=( other ); 444 455 } 445 456 446 457 #endif // TYPE_H 458 459 // Local Variables: // 460 // tab-width: 4 // 461 // mode: c++ // 462 // compile-command: "make install" // 463 // End: // -
translator/SynTree/TypeDecl.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // TypeDecl.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:02:11 2015 13 // Update Count : 1 14 // 15 1 16 #include "Declaration.h" 2 17 #include "Type.h" 3 18 #include "utility.h" 4 19 5 6 TypeDecl::TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ) 7 : Parent( name, sc, type ), kind( kind ) 8 { 20 TypeDecl::TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ) : Parent( name, sc, type ), kind( kind ) { 9 21 } 10 22 11 TypeDecl::TypeDecl( const TypeDecl &other ) 12 : Parent( other ), kind( other.kind ) 13 { 23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ) { 14 24 } 15 25 16 std::string 17 TypeDecl::typeString() const 18 { 19 static const char *kindNames[] = { "type", "incomplete type", "function type" }; 20 return kindNames[ kind ]; 26 std::string TypeDecl::typeString() const { 27 static const char *kindNames[] = { "type", "incomplete type", "function type" }; 28 return kindNames[ kind ]; 21 29 } 22 30 31 // Local Variables: // 32 // tab-width: 4 // 33 // mode: c++ // 34 // compile-command: "make install" // 35 // End: // -
translator/SynTree/TypeExpr.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TypeExpr.cc,v 1.4 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // TypeExpr.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:03:15 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Expression.h" … … 10 18 #include "utility.h" 11 19 12 13 TypeExpr::TypeExpr( Type *type ) 14 : type( type ) 15 { 20 TypeExpr::TypeExpr( Type *type ) : type( type ) { 16 21 } 17 22 18 TypeExpr::TypeExpr( const TypeExpr &other ) 19 : type( maybeClone( other.type ) ) 20 { 23 TypeExpr::TypeExpr( const TypeExpr &other ) : type( maybeClone( other.type ) ) { 21 24 } 22 25 23 TypeExpr::~TypeExpr() 24 { 25 delete type; 26 TypeExpr::~TypeExpr() { 27 delete type; 26 28 } 27 29 28 void 29 TypeExpr::print( std::ostream &os, int indent ) const 30 { 31 if ( type ) type->print( os, indent ); 32 Expression::print( os, indent ); 30 void TypeExpr::print( std::ostream &os, int indent ) const { 31 if ( type ) type->print( os, indent ); 32 Expression::print( os, indent ); 33 33 } 34 34 35 // Local Variables: // 36 // tab-width: 4 // 37 // mode: c++ // 38 // compile-command: "make install" // 39 // End: // -
translator/SynTree/TypeSubstitution.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TypeSubstitution.cc,v 1.9 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // TypeSubstitution.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:10:04 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" 9 17 #include "TypeSubstitution.h" 10 18 11 12 TypeSubstitution::TypeSubstitution() 13 { 19 TypeSubstitution::TypeSubstitution() { 14 20 } 15 21 16 TypeSubstitution::TypeSubstitution( const TypeSubstitution &other ) 17 { 18 initialize( other, *this ); 22 TypeSubstitution::TypeSubstitution( const TypeSubstitution &other ) { 23 initialize( other, *this ); 19 24 } 20 25 21 TypeSubstitution::~TypeSubstitution() 22 { 23 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 24 delete( i->second ); 25 } 26 for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 27 delete( i->second ); 28 } 26 TypeSubstitution::~TypeSubstitution() { 27 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 28 delete( i->second ); 29 } 30 for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 31 delete( i->second ); 32 } 29 33 } 30 34 31 TypeSubstitution & 32 TypeSubstitution::operator=( const TypeSubstitution &other ) 33 { 34 if ( this == &other ) return *this; 35 initialize( other, *this ); 36 return *this; 35 TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) { 36 if ( this == &other ) return *this; 37 initialize( other, *this ); 38 return *this; 37 39 } 38 40 39 void 40 TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) 41 { 42 dest.typeEnv.clear(); 43 dest.varEnv.clear(); 44 dest.add( src ); 41 void TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) { 42 dest.typeEnv.clear(); 43 dest.varEnv.clear(); 44 dest.add( src ); 45 45 } 46 46 47 void 48 TypeSubstitution::add( const TypeSubstitution &other ) 49 { 50 for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) { 51 typeEnv[ i->first ] = i->second->clone(); 52 } 53 for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) { 54 varEnv[ i->first ] = i->second->clone(); 55 } 47 void TypeSubstitution::add( const TypeSubstitution &other ) { 48 for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) { 49 typeEnv[ i->first ] = i->second->clone(); 50 } // for 51 for ( VarEnvType::const_iterator i = other.varEnv.begin(); i != other.varEnv.end(); ++i ) { 52 varEnv[ i->first ] = i->second->clone(); 53 } // for 56 54 } 57 55 58 void 59 TypeSubstitution::add( std::string formalType, Type *actualType ) 60 { 61 TypeEnvType::iterator i = typeEnv.find( formalType ); 62 if ( i != typeEnv.end() ) { 63 delete i->second; 64 } 65 typeEnv[ formalType ] = actualType->clone(); 56 void TypeSubstitution::add( std::string formalType, Type *actualType ) { 57 TypeEnvType::iterator i = typeEnv.find( formalType ); 58 if ( i != typeEnv.end() ) { 59 delete i->second; 60 } // if 61 typeEnv[ formalType ] = actualType->clone(); 66 62 } 67 63 68 void 69 TypeSubstitution::remove( std::string formalType ) 70 { 71 TypeEnvType::iterator i = typeEnv.find( formalType ); 72 if ( i != typeEnv.end() ) { 73 delete i->second; 74 typeEnv.erase( formalType ); 75 } 64 void TypeSubstitution::remove( std::string formalType ) { 65 TypeEnvType::iterator i = typeEnv.find( formalType ); 66 if ( i != typeEnv.end() ) { 67 delete i->second; 68 typeEnv.erase( formalType ); 69 } // if 76 70 } 77 71 78 Type * 79 TypeSubstitution::lookup( std::string formalType ) const 80 { 81 TypeEnvType::const_iterator i = typeEnv.find( formalType ); 82 if ( i == typeEnv.end() ) { 83 return 0; 84 } else { 85 return i->second; 86 } 72 Type *TypeSubstitution::lookup( std::string formalType ) const { 73 TypeEnvType::const_iterator i = typeEnv.find( formalType ); 74 if ( i == typeEnv.end() ) { 75 return 0; 76 } else { 77 return i->second; 78 } // if 87 79 } 88 80 89 bool 90 TypeSubstitution::empty() const 91 { 92 return typeEnv.empty() && varEnv.empty(); 81 bool TypeSubstitution::empty() const { 82 return typeEnv.empty() && varEnv.empty(); 93 83 } 94 84 95 void 96 TypeSubstitution::normalize() 97 { 98 do { 99 subCount = 0; 100 freeOnly = true; 101 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 102 i->second = i->second->acceptMutator( *this ); 103 } 104 } while ( subCount ); 85 void TypeSubstitution::normalize() { 86 do { 87 subCount = 0; 88 freeOnly = true; 89 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 90 i->second = i->second->acceptMutator( *this ); 91 } 92 } while ( subCount ); 105 93 } 106 94 107 Type* 108 TypeSubstitution::mutate(TypeInstType *inst) 109 { 110 BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() ); 111 if ( bound != boundVars.end() ) return inst; 112 113 TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() ); 114 if ( i == typeEnv.end() ) { 115 return inst; 116 } else { 95 Type * TypeSubstitution::mutate( TypeInstType *inst ) { 96 BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() ); 97 if ( bound != boundVars.end() ) return inst; 98 99 TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() ); 100 if ( i == typeEnv.end() ) { 101 return inst; 102 } else { 117 103 /// std::cout << "found " << inst->get_name() << ", replacing with "; 118 104 /// i->second->print( std::cout ); 119 105 /// std::cout << std::endl; 120 subCount++;121 Type *newtype = i->second->clone();122 newtype->get_qualifiers() += inst->get_qualifiers();123 delete inst;124 return newtype;125 } 106 subCount++; 107 Type *newtype = i->second->clone(); 108 newtype->get_qualifiers() += inst->get_qualifiers(); 109 delete inst; 110 return newtype; 111 } // if 126 112 } 127 113 128 Expression* 129 TypeSubstitution::mutate(NameExpr *nameExpr) 130 { 131 VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() ); 132 if ( i == varEnv.end() ) { 133 return nameExpr; 134 } else { 135 subCount++; 136 delete nameExpr; 137 return i->second->clone(); 138 } 114 Expression * TypeSubstitution::mutate( NameExpr *nameExpr ) { 115 VarEnvType::const_iterator i = varEnv.find( nameExpr->get_name() ); 116 if ( i == varEnv.end() ) { 117 return nameExpr; 118 } else { 119 subCount++; 120 delete nameExpr; 121 return i->second->clone(); 122 } // if 139 123 } 140 124 141 125 template< typename TypeClass > 142 Type * 143 TypeSubstitution::handleType( TypeClass *type ) 144 { 145 BoundVarsType oldBoundVars( boundVars ); 146 if ( freeOnly ) { 147 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 148 boundVars.insert( (*tyvar)->get_name() ); 149 } 150 } 151 Type *ret = Mutator::mutate( type ); 152 boundVars = oldBoundVars; 153 return ret; 126 Type *TypeSubstitution::handleType( TypeClass *type ) { 127 BoundVarsType oldBoundVars( boundVars ); 128 if ( freeOnly ) { 129 for ( std::list< TypeDecl* >::const_iterator tyvar = type->get_forall().begin(); tyvar != type->get_forall().end(); ++tyvar ) { 130 boundVars.insert( (*tyvar )->get_name() ); 131 } // for 132 } // if 133 Type *ret = Mutator::mutate( type ); 134 boundVars = oldBoundVars; 135 return ret; 154 136 } 155 137 156 Type* 157 TypeSubstitution::mutate(VoidType *basicType) 158 { 159 return handleType( basicType ); 138 Type * TypeSubstitution::mutate( VoidType *basicType ) { 139 return handleType( basicType ); 160 140 } 161 141 162 Type* 163 TypeSubstitution::mutate(BasicType *basicType) 164 { 165 return handleType( basicType ); 142 Type * TypeSubstitution::mutate( BasicType *basicType ) { 143 return handleType( basicType ); 166 144 } 167 145 168 Type* 169 TypeSubstitution::mutate(PointerType *pointerType) 170 { 171 return handleType( pointerType ); 146 Type * TypeSubstitution::mutate( PointerType *pointerType ) { 147 return handleType( pointerType ); 172 148 } 173 149 174 Type* 175 TypeSubstitution::mutate(ArrayType *arrayType) 176 { 177 return handleType( arrayType ); 150 Type * TypeSubstitution::mutate( ArrayType *arrayType ) { 151 return handleType( arrayType ); 178 152 } 179 153 180 Type* 181 TypeSubstitution::mutate(FunctionType *functionType) 182 { 183 return handleType( functionType ); 154 Type * TypeSubstitution::mutate( FunctionType *functionType ) { 155 return handleType( functionType ); 184 156 } 185 157 186 Type* 187 TypeSubstitution::mutate(StructInstType *aggregateUseType) 188 { 189 return handleType( aggregateUseType ); 158 Type * TypeSubstitution::mutate( StructInstType *aggregateUseType ) { 159 return handleType( aggregateUseType ); 190 160 } 191 161 192 Type* 193 TypeSubstitution::mutate(UnionInstType *aggregateUseType) 194 { 195 return handleType( aggregateUseType ); 162 Type * TypeSubstitution::mutate( UnionInstType *aggregateUseType ) { 163 return handleType( aggregateUseType ); 196 164 } 197 165 198 Type* 199 TypeSubstitution::mutate(EnumInstType *aggregateUseType) 200 { 201 return handleType( aggregateUseType ); 166 Type * TypeSubstitution::mutate( EnumInstType *aggregateUseType ) { 167 return handleType( aggregateUseType ); 202 168 } 203 169 204 Type* 205 TypeSubstitution::mutate(ContextInstType *aggregateUseType) 206 { 207 return handleType( aggregateUseType ); 170 Type * TypeSubstitution::mutate( ContextInstType *aggregateUseType ) { 171 return handleType( aggregateUseType ); 208 172 } 209 173 210 Type* 211 TypeSubstitution::mutate(TupleType *tupleType) 212 { 213 return handleType( tupleType ); 174 Type * TypeSubstitution::mutate( TupleType *tupleType ) { 175 return handleType( tupleType ); 214 176 } 215 177 216 void 217 TypeSubstitution::print( std::ostream &os, int indent ) const 218 { 219 os << std::string( indent, ' ' ) << "Types:" << std::endl; 220 for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 221 os << std::string( indent+2, ' ' ) << i->first << " -> "; 222 i->second->print( os, indent+4 ); 223 os << std::endl; 224 } 225 os << std::string( indent, ' ' ) << "Non-types:" << std::endl; 226 for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 227 os << std::string( indent+2, ' ' ) << i->first << " -> "; 228 i->second->print( os, indent+4 ); 229 os << std::endl; 230 } 178 void TypeSubstitution::print( std::ostream &os, int indent ) const { 179 os << std::string( indent, ' ' ) << "Types:" << std::endl; 180 for ( TypeEnvType::const_iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) { 181 os << std::string( indent+2, ' ' ) << i->first << " -> "; 182 i->second->print( os, indent+4 ); 183 os << std::endl; 184 } // for 185 os << std::string( indent, ' ' ) << "Non-types:" << std::endl; 186 for ( VarEnvType::const_iterator i = varEnv.begin(); i != varEnv.end(); ++i ) { 187 os << std::string( indent+2, ' ' ) << i->first << " -> "; 188 i->second->print( os, indent+4 ); 189 os << std::endl; 190 } // for 231 191 } 232 192 193 // Local Variables: // 194 // tab-width: 4 // 195 // mode: c++ // 196 // compile-command: "make install" // 197 // End: // -
translator/SynTree/TypeSubstitution.h
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TypeSubstitution.h,v 1.9 2005/08/29 20:59:26 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // TypeSubstitution.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:12:30 2015 13 // Update Count : 1 14 // 7 15 8 #ifndef SYNTREE_TYPESUBSTITUTION_H9 #define SYNTREE_TYPESUBSTITUTION_H16 #ifndef TYPESUBSTITUTION_H 17 #define TYPESUBSTITUTION_H 10 18 11 19 #include <map> … … 17 25 #include "SynTree/Expression.h" 18 26 27 class TypeSubstitution : public Mutator { 28 typedef Mutator Parent; 29 public: 30 TypeSubstitution(); 31 template< typename FormalIterator, typename ActualIterator > 32 TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 33 TypeSubstitution( const TypeSubstitution &other ); 34 virtual ~TypeSubstitution(); 35 36 TypeSubstitution &operator=( const TypeSubstitution &other ); 37 38 template< typename SynTreeClass > int apply( SynTreeClass *&input ); 39 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ); 40 41 void add( std::string formalType, Type *actualType ); 42 void add( const TypeSubstitution &other ); 43 void remove( std::string formalType ); 44 Type *lookup( std::string formalType ) const; 45 bool empty() const; 46 47 template< typename FormalIterator, typename ActualIterator > 48 void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 49 50 template< typename TypeInstListIterator > 51 void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ); 52 53 void normalize(); 19 54 20 class TypeSubstitution : public Mutator 21 { 22 typedef Mutator Parent; 23 24 public: 25 TypeSubstitution(); 26 template< typename FormalIterator, typename ActualIterator > 27 TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 28 TypeSubstitution( const TypeSubstitution &other ); 29 virtual ~TypeSubstitution(); 30 31 TypeSubstitution &operator=( const TypeSubstitution &other ); 32 33 template< typename SynTreeClass > int apply( SynTreeClass *&input ); 34 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ); 35 36 void add( std::string formalType, Type *actualType ); 37 void add( const TypeSubstitution &other ); 38 void remove( std::string formalType ); 39 Type *lookup( std::string formalType ) const; 40 bool empty() const; 41 42 template< typename FormalIterator, typename ActualIterator > 43 void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 44 45 template< typename TypeInstListIterator > 46 void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ); 47 48 void normalize(); 55 void print( std::ostream &os, int indent = 0 ) const; 56 TypeSubstitution *clone() const { return new TypeSubstitution( *this ); } 57 private: 58 virtual Type* mutate(TypeInstType *aggregateUseType); 59 virtual Expression* mutate(NameExpr *nameExpr); 60 61 template< typename TypeClass > Type *handleType( TypeClass *type ); 62 63 virtual Type* mutate(VoidType *basicType); 64 virtual Type* mutate(BasicType *basicType); 65 virtual Type* mutate(PointerType *pointerType); 66 virtual Type* mutate(ArrayType *arrayType); 67 virtual Type* mutate(FunctionType *functionType); 68 virtual Type* mutate(StructInstType *aggregateUseType); 69 virtual Type* mutate(UnionInstType *aggregateUseType); 70 virtual Type* mutate(EnumInstType *aggregateUseType); 71 virtual Type* mutate(ContextInstType *aggregateUseType); 72 virtual Type* mutate(TupleType *tupleType); 73 74 // TODO: worry about traversing into a forall-qualified function type or type decl with assertions 75 76 void initialize( const TypeSubstitution &src, TypeSubstitution &dest ); 49 77 50 void print( std::ostream &os, int indent = 0 ) const; 51 TypeSubstitution *clone() const { return new TypeSubstitution( *this ); } 52 53 private: 54 virtual Type* mutate(TypeInstType *aggregateUseType); 55 virtual Expression* mutate(NameExpr *nameExpr); 56 57 template< typename TypeClass > Type *handleType( TypeClass *type ); 58 59 virtual Type* mutate(VoidType *basicType); 60 virtual Type* mutate(BasicType *basicType); 61 virtual Type* mutate(PointerType *pointerType); 62 virtual Type* mutate(ArrayType *arrayType); 63 virtual Type* mutate(FunctionType *functionType); 64 virtual Type* mutate(StructInstType *aggregateUseType); 65 virtual Type* mutate(UnionInstType *aggregateUseType); 66 virtual Type* mutate(EnumInstType *aggregateUseType); 67 virtual Type* mutate(ContextInstType *aggregateUseType); 68 virtual Type* mutate(TupleType *tupleType); 69 70 // TODO: worry about traversing into a forall-qualified function type or type decl with assertions 71 72 void initialize( const TypeSubstitution &src, TypeSubstitution &dest ); 73 74 typedef std::map< std::string, Type* > TypeEnvType; 75 typedef std::map< std::string, Expression* > VarEnvType; 76 typedef std::set< std::string > BoundVarsType; 77 TypeEnvType typeEnv; 78 VarEnvType varEnv; 79 BoundVarsType boundVars; 80 int subCount; 81 bool freeOnly; 78 typedef std::map< std::string, Type* > TypeEnvType; 79 typedef std::map< std::string, Expression* > VarEnvType; 80 typedef std::set< std::string > BoundVarsType; 81 TypeEnvType typeEnv; 82 VarEnvType varEnv; 83 BoundVarsType boundVars; 84 int subCount; 85 bool freeOnly; 82 86 }; 83 87 84 88 template< typename FormalIterator, typename ActualIterator > 85 void 86 TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) 87 { 88 // FormalIterator points to a TypeDecl 89 // ActualIterator points to a Type 90 FormalIterator formalIt = formalBegin; 91 ActualIterator actualIt = actualBegin; 92 for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) { 93 if ( TypeDecl *formal = dynamic_cast< TypeDecl* >( *formalIt ) ) { 94 if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) { 95 if ( formal->get_name() != "" ) { 96 TypeEnvType::iterator i = typeEnv.find( formal->get_name() ); 97 if ( i != typeEnv.end() ) { 98 delete i->second; 99 } 100 typeEnv[ formal->get_name() ] = actual->get_type()->clone(); 101 } 102 } else { 103 throw SemanticError( "Attempt to provide non-type parameter for type parameter", formal ); 104 } 105 } else { 106 // TODO: type check the formal and actual parameters 107 if ( (*formalIt)->get_name() != "" ) { 108 varEnv[ (*formalIt)->get_name() ] = (*actualIt)->clone(); 109 } 110 } 111 } 89 void TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) { 90 // FormalIterator points to a TypeDecl 91 // ActualIterator points to a Type 92 FormalIterator formalIt = formalBegin; 93 ActualIterator actualIt = actualBegin; 94 for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) { 95 if ( TypeDecl *formal = dynamic_cast< TypeDecl* >( *formalIt ) ) { 96 if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) { 97 if ( formal->get_name() != "" ) { 98 TypeEnvType::iterator i = typeEnv.find( formal->get_name() ); 99 if ( i != typeEnv.end() ) { 100 delete i->second; 101 } // if 102 typeEnv[ formal->get_name() ] = actual->get_type()->clone(); 103 } // if 104 } else { 105 throw SemanticError( "Attempt to provide non-type parameter for type parameter", formal ); 106 } // if 107 } else { 108 // TODO: type check the formal and actual parameters 109 if ( (*formalIt)->get_name() != "" ) { 110 varEnv[ (*formalIt)->get_name() ] = (*actualIt)->clone(); 111 } // if 112 } // if 113 } // for 112 114 } 113 115 … … 115 117 TypeSubstitution::TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) 116 118 { 117 119 add( formalBegin, formalEnd, actualBegin ); 118 120 } 119 121 120 122 template< typename SynTreeClass > 121 int 122 TypeSubstitution::apply( SynTreeClass *&input ) 123 { 124 assert( input ); 125 subCount = 0; 126 freeOnly = false; 127 input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) ); 128 assert( input ); 123 int TypeSubstitution::apply( SynTreeClass *&input ) { 124 assert( input ); 125 subCount = 0; 126 freeOnly = false; 127 input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) ); 128 assert( input ); 129 129 /// std::cout << "substitution result is: "; 130 130 /// newType->print( std::cout ); 131 131 /// std::cout << std::endl; 132 132 return subCount; 133 133 } 134 134 135 135 template< typename SynTreeClass > 136 int 137 TypeSubstitution::applyFree( SynTreeClass *&input ) 138 { 139 assert( input ); 140 subCount = 0; 141 freeOnly = true; 142 input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) ); 143 assert( input ); 136 int TypeSubstitution::applyFree( SynTreeClass *&input ) { 137 assert( input ); 138 subCount = 0; 139 freeOnly = true; 140 input = dynamic_cast< SynTreeClass *>( input->acceptMutator( *this ) ); 141 assert( input ); 144 142 /// std::cout << "substitution result is: "; 145 143 /// newType->print( std::cout ); 146 144 /// std::cout << std::endl; 147 145 return subCount; 148 146 } 149 147 150 148 template< typename TypeInstListIterator > 151 void 152 TypeSubstitution::extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ) 153 { 154 while ( begin != end ) { 155 TypeEnvType::iterator cur = typeEnv.find( (*begin++)->get_name() ); 156 if ( cur != typeEnv.end() ) { 157 result.typeEnv[ cur->first ] = cur->second; 158 typeEnv.erase( cur ); 159 } 160 } 149 void TypeSubstitution::extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ) { 150 while ( begin != end ) { 151 TypeEnvType::iterator cur = typeEnv.find( (*begin++)->get_name() ); 152 if ( cur != typeEnv.end() ) { 153 result.typeEnv[ cur->first ] = cur->second; 154 typeEnv.erase( cur ); 155 } // if 156 } // while 161 157 } 162 158 163 159 // helper function 164 160 template< typename FormalIterator, typename ActualIterator, typename MemberIterator, typename OutputIterator > 165 void 166 applySubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actual, MemberIterator memberBegin, MemberIterator memberEnd, OutputIterator out ) 167 { 168 // Instantiate each member of the context given the actual parameters specified, and store the 169 // instantiations for use by the indexer 161 void applySubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actual, MemberIterator memberBegin, MemberIterator memberEnd, OutputIterator out ) { 162 // Instantiate each member of the context given the actual parameters specified, and store the 163 // instantiations for use by the indexer 170 164 171 172 173 Declaration *newdecl = (*i)->clone();174 sub.apply( newdecl );175 *out++ = newdecl;176 } 165 TypeSubstitution sub = TypeSubstitution( formalBegin, formalEnd, actual ); 166 for ( std::list< Declaration* >::iterator i = memberBegin; i != memberEnd; ++i ) { 167 Declaration *newdecl = (*i)->clone(); 168 sub.apply( newdecl ); 169 *out++ = newdecl; 170 } // for 177 171 } 178 172 173 #endif // TYPESUBSTITUTION_H 179 174 180 #endif /* #ifndef SYNTREE_TYPESUBSTITUTION_H */ 175 // Local Variables: // 176 // tab-width: 4 // 177 // mode: c++ // 178 // compile-command: "make install" // 179 // End: // -
translator/SynTree/TypeofType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: TypeofType.cc,v 1.3 2005/08/29 20:59:27 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // TypeofType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:13:29 2015 13 // Update Count : 2 14 // 7 15 8 16 #include "Type.h" … … 10 18 #include "utility.h" 11 19 12 13 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr ) 14 : Type( tq ), expr( expr ) 15 { 20 TypeofType::TypeofType( const Type::Qualifiers &tq, Expression *expr ) : Type( tq ), expr( expr ) { 16 21 } 17 22 18 TypeofType::TypeofType( const TypeofType &other ) 19 : Type( other ), expr( maybeClone( other.expr ) ) 20 { 23 TypeofType::TypeofType( const TypeofType &other ) : Type( other ), expr( maybeClone( other.expr ) ) { 21 24 } 22 25 23 TypeofType::~TypeofType() 24 { 25 delete expr; 26 TypeofType::~TypeofType() { 27 delete expr; 26 28 } 27 29 28 void 29 TypeofType::print( std::ostream &os, int indent ) const 30 { 31 Type::print( os, indent ); 32 os << "type-of expression "; 33 if ( expr ) { 34 expr->print( os, indent ); 35 } 30 void TypeofType::print( std::ostream &os, int indent ) const { 31 Type::print( os, indent ); 32 os << "type-of expression "; 33 if ( expr ) { 34 expr->print( os, indent ); 35 } 36 36 } 37 37 38 // Local Variables: // 39 // tab-width: 4 // 40 // mode: c++ // 41 // compile-command: "make install" // 42 // End: // -
translator/SynTree/Visitor.cc
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Visitor.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:14:51 2015 13 // Update Count : 2 14 // 15 1 16 #include <cassert> 2 17 #include "Visitor.h" … … 8 23 #include "Constant.h" 9 24 10 11 25 Visitor::Visitor() {} 12 26 13 27 Visitor::~Visitor() {} 14 28 15 void Visitor::visit(ObjectDecl *objectDecl) { 16 maybeAccept( objectDecl->get_type(), *this ); 17 maybeAccept( objectDecl->get_init(), *this ); 18 maybeAccept( objectDecl->get_bitfieldWidth(), *this ); 19 } 20 21 void Visitor::visit(FunctionDecl *functionDecl) { 22 maybeAccept( functionDecl->get_functionType(), *this ); 23 acceptAll( functionDecl->get_oldDecls(), *this ); 24 maybeAccept( functionDecl->get_statements(), *this ); 25 } 26 27 void Visitor::visit(AggregateDecl *aggregateDecl) { 28 acceptAll( aggregateDecl->get_parameters(), *this ); 29 acceptAll( aggregateDecl->get_members(), *this ); 30 } 31 32 void Visitor::visit(StructDecl *aggregateDecl) { 33 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 34 } 35 36 void Visitor::visit(UnionDecl *aggregateDecl) { 37 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 38 } 39 40 void Visitor::visit(EnumDecl *aggregateDecl) { 41 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 42 } 43 44 void Visitor::visit(ContextDecl *aggregateDecl) { 45 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 46 } 47 48 void Visitor::visit(NamedTypeDecl *typeDecl) { 49 acceptAll( typeDecl->get_parameters(), *this ); 50 acceptAll( typeDecl->get_assertions(), *this ); 51 maybeAccept( typeDecl->get_base(), *this ); 52 } 53 54 void Visitor::visit(TypeDecl *typeDecl) { 55 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 56 } 57 58 void Visitor::visit(TypedefDecl *typeDecl) { 59 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 60 } 61 62 void Visitor::visit(CompoundStmt *compoundStmt) { 63 acceptAll( compoundStmt->get_kids(), *this ); 64 } 65 66 void Visitor::visit(ExprStmt *exprStmt) { 67 maybeAccept( exprStmt->get_expr(), *this ); 68 } 69 70 void Visitor::visit(IfStmt *ifStmt) { 71 maybeAccept( ifStmt->get_condition(), *this ); 72 maybeAccept( ifStmt->get_thenPart(), *this ); 73 maybeAccept( ifStmt->get_elsePart(), *this ); 74 } 75 76 void Visitor::visit(WhileStmt *whileStmt) { 77 maybeAccept( whileStmt->get_condition(), *this ); 78 maybeAccept( whileStmt->get_body(), *this ); 79 } 80 81 void Visitor::visit(ForStmt *forStmt) { 82 // ForStmt still needs to be fixed 83 maybeAccept( forStmt->get_initialization(), *this ); 84 maybeAccept( forStmt->get_condition(), *this ); 85 maybeAccept( forStmt->get_increment(), *this ); 86 maybeAccept( forStmt->get_body(), *this ); 87 } 88 89 void Visitor::visit(SwitchStmt *switchStmt) { 90 maybeAccept( switchStmt->get_condition(), *this ); 91 acceptAll( switchStmt->get_branches(), *this ); 92 } 93 94 void Visitor::visit(ChooseStmt *switchStmt) { 95 maybeAccept( switchStmt->get_condition(), *this ); 96 acceptAll( switchStmt->get_branches(), *this ); 97 } 98 99 void Visitor::visit(FallthruStmt *fallthruStmt){} 100 101 void Visitor::visit(CaseStmt *caseStmt) { 102 maybeAccept( caseStmt->get_condition(), *this ); 103 acceptAll( caseStmt->get_statements(), *this ); 104 } 105 106 void Visitor::visit(BranchStmt *branchStmt) { 107 } 108 109 void Visitor::visit(ReturnStmt *returnStmt) { 110 maybeAccept( returnStmt->get_expr(), *this ); 111 } 112 113 void Visitor::visit(TryStmt *tryStmt) { 114 maybeAccept( tryStmt->get_block(), *this ); 115 acceptAll( tryStmt->get_catchers(), *this ); 116 } 117 118 void Visitor::visit(CatchStmt *catchStmt) { 119 maybeAccept( catchStmt->get_decl(), *this ); 120 maybeAccept( catchStmt->get_body(), *this ); 121 } 122 123 void Visitor::visit(FinallyStmt *finalStmt) { 124 maybeAccept( finalStmt->get_block(), *this ); 125 } 126 127 void Visitor::visit(NullStmt *nullStmt) { 128 } 129 130 void Visitor::visit(DeclStmt *declStmt) { 131 maybeAccept( declStmt->get_decl(), *this ); 132 } 133 134 void Visitor::visit(ApplicationExpr *applicationExpr) { 135 acceptAll( applicationExpr->get_results(), *this ); 136 maybeAccept( applicationExpr->get_function(), *this ); 137 acceptAll( applicationExpr->get_args(), *this ); 138 } 139 140 void Visitor::visit(UntypedExpr *untypedExpr) { 141 acceptAll( untypedExpr->get_results(), *this ); 142 acceptAll( untypedExpr->get_args(), *this ); 143 } 144 145 void Visitor::visit(NameExpr *nameExpr) { 146 acceptAll( nameExpr->get_results(), *this ); 147 } 148 149 void Visitor::visit(AddressExpr *addressExpr) { 150 acceptAll( addressExpr->get_results(), *this ); 151 maybeAccept( addressExpr->get_arg(), *this ); 152 } 153 154 void Visitor::visit(LabelAddressExpr *labAddressExpr) { 155 acceptAll( labAddressExpr->get_results(), *this ); 156 maybeAccept( labAddressExpr->get_arg(), *this ); 157 } 158 159 void Visitor::visit(CastExpr *castExpr) { 160 acceptAll( castExpr->get_results(), *this ); 161 maybeAccept( castExpr->get_arg(), *this ); 162 } 163 164 void Visitor::visit(UntypedMemberExpr *memberExpr) { 165 acceptAll( memberExpr->get_results(), *this ); 166 maybeAccept( memberExpr->get_aggregate(), *this ); 167 } 168 169 void Visitor::visit(MemberExpr *memberExpr) { 170 acceptAll( memberExpr->get_results(), *this ); 171 maybeAccept( memberExpr->get_aggregate(), *this ); 172 } 173 174 void Visitor::visit(VariableExpr *variableExpr) { 175 acceptAll( variableExpr->get_results(), *this ); 176 } 177 178 void Visitor::visit(ConstantExpr *constantExpr) { 179 acceptAll( constantExpr->get_results(), *this ); 180 maybeAccept( constantExpr->get_constant(), *this ); 181 } 182 183 void Visitor::visit(SizeofExpr *sizeofExpr) { 184 acceptAll( sizeofExpr->get_results(), *this ); 185 if ( sizeofExpr->get_isType() ) { 186 maybeAccept( sizeofExpr->get_type(), *this ); 187 } else { 188 maybeAccept( sizeofExpr->get_expr(), *this ); 189 } 190 } 191 192 void Visitor::visit(AttrExpr *attrExpr) { 193 acceptAll( attrExpr->get_results(), *this ); 194 if ( attrExpr->get_isType() ) { 195 maybeAccept( attrExpr->get_type(), *this ); 196 } else { 197 maybeAccept( attrExpr->get_expr(), *this ); 198 } 199 } 200 201 void Visitor::visit(LogicalExpr *logicalExpr) { 202 acceptAll( logicalExpr->get_results(), *this ); 203 maybeAccept( logicalExpr->get_arg1(), *this ); 204 maybeAccept( logicalExpr->get_arg2(), *this ); 205 } 206 207 void Visitor::visit(ConditionalExpr *conditionalExpr) { 208 acceptAll( conditionalExpr->get_results(), *this ); 209 maybeAccept( conditionalExpr->get_arg1(), *this ); 210 maybeAccept( conditionalExpr->get_arg2(), *this ); 211 maybeAccept( conditionalExpr->get_arg3(), *this ); 212 } 213 214 void Visitor::visit(CommaExpr *commaExpr) { 215 acceptAll( commaExpr->get_results(), *this ); 216 maybeAccept( commaExpr->get_arg1(), *this ); 217 maybeAccept( commaExpr->get_arg2(), *this ); 218 } 219 220 void Visitor::visit(TupleExpr *tupleExpr) { 221 acceptAll( tupleExpr->get_results(), *this ); 222 acceptAll( tupleExpr->get_exprs(), *this ); 223 } 224 225 void Visitor::visit(SolvedTupleExpr *tupleExpr) { 226 acceptAll( tupleExpr->get_results(), *this ); 227 acceptAll( tupleExpr->get_exprs(), *this ); 228 } 229 230 void Visitor::visit(TypeExpr *typeExpr) { 231 acceptAll( typeExpr->get_results(), *this ); 232 maybeAccept( typeExpr->get_type(), *this ); 233 } 234 235 void Visitor::visit(UntypedValofExpr *valofExpr) { 236 acceptAll( valofExpr->get_results(), *this ); 237 maybeAccept( valofExpr->get_body(), *this ); 238 } 239 240 void Visitor::visit(VoidType *voidType) { 241 acceptAll( voidType->get_forall(), *this ); 242 } 243 244 void Visitor::visit(BasicType *basicType) { 245 acceptAll( basicType->get_forall(), *this ); 246 } 247 248 void Visitor::visit(PointerType *pointerType) { 249 acceptAll( pointerType->get_forall(), *this ); 250 maybeAccept( pointerType->get_base(), *this ); 251 } 252 253 void Visitor::visit(ArrayType *arrayType) { 254 acceptAll( arrayType->get_forall(), *this ); 255 maybeAccept( arrayType->get_dimension(), *this ); 256 maybeAccept( arrayType->get_base(), *this ); 257 } 258 259 void Visitor::visit(FunctionType *functionType) { 260 acceptAll( functionType->get_forall(), *this ); 261 acceptAll( functionType->get_returnVals(), *this ); 262 acceptAll( functionType->get_parameters(), *this ); 263 } 264 265 void Visitor::visit(ReferenceToType *aggregateUseType) { 266 acceptAll( aggregateUseType->get_forall(), *this ); 267 acceptAll( aggregateUseType->get_parameters(), *this ); 268 } 269 270 void Visitor::visit(StructInstType *aggregateUseType) { 271 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 272 } 273 274 void Visitor::visit(UnionInstType *aggregateUseType) { 275 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 276 } 277 278 void Visitor::visit(EnumInstType *aggregateUseType) { 279 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 280 } 281 282 void Visitor::visit(ContextInstType *aggregateUseType) { 283 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 284 acceptAll( aggregateUseType->get_members(), *this ); 285 } 286 287 void Visitor::visit(TypeInstType *aggregateUseType) { 288 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 289 } 290 291 void Visitor::visit(TupleType *tupleType) { 292 acceptAll( tupleType->get_forall(), *this ); 293 acceptAll( tupleType->get_types(), *this ); 294 } 295 296 void Visitor::visit(TypeofType *typeofType) { 297 assert( typeofType->get_expr() ); 298 typeofType->get_expr()->accept( *this ); 299 } 300 301 void Visitor::visit(AttrType *attrType) { 302 if ( attrType->get_isType() ) { 303 assert( attrType->get_type() ); 304 attrType->get_type()->accept( *this ); 305 } else { 306 assert( attrType->get_expr() ); 307 attrType->get_expr()->accept( *this ); 308 } 309 } 310 311 void Visitor::visit(SingleInit *singleInit) { 312 singleInit->get_value()->accept( *this ); 313 } 314 315 void Visitor::visit(ListInit *listInit) { 316 acceptAll( listInit->get_designators(), *this ); 317 acceptAll( listInit->get_initializers(), *this ); 318 } 319 320 void Visitor::visit(Subrange *subrange) {} 321 322 void Visitor::visit(Constant *constant) {} 29 void Visitor::visit( ObjectDecl *objectDecl ) { 30 maybeAccept( objectDecl->get_type(), *this ); 31 maybeAccept( objectDecl->get_init(), *this ); 32 maybeAccept( objectDecl->get_bitfieldWidth(), *this ); 33 } 34 35 void Visitor::visit( FunctionDecl *functionDecl ) { 36 maybeAccept( functionDecl->get_functionType(), *this ); 37 acceptAll( functionDecl->get_oldDecls(), *this ); 38 maybeAccept( functionDecl->get_statements(), *this ); 39 } 40 41 void Visitor::visit( AggregateDecl *aggregateDecl ) { 42 acceptAll( aggregateDecl->get_parameters(), *this ); 43 acceptAll( aggregateDecl->get_members(), *this ); 44 } 45 46 void Visitor::visit( StructDecl *aggregateDecl ) { 47 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 48 } 49 50 void Visitor::visit( UnionDecl *aggregateDecl ) { 51 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 52 } 53 54 void Visitor::visit( EnumDecl *aggregateDecl ) { 55 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 56 } 57 58 void Visitor::visit( ContextDecl *aggregateDecl ) { 59 visit( static_cast< AggregateDecl* >( aggregateDecl ) ); 60 } 61 62 void Visitor::visit( NamedTypeDecl *typeDecl ) { 63 acceptAll( typeDecl->get_parameters(), *this ); 64 acceptAll( typeDecl->get_assertions(), *this ); 65 maybeAccept( typeDecl->get_base(), *this ); 66 } 67 68 void Visitor::visit( TypeDecl *typeDecl ) { 69 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 70 } 71 72 void Visitor::visit( TypedefDecl *typeDecl ) { 73 visit( static_cast< NamedTypeDecl* >( typeDecl ) ); 74 } 75 76 void Visitor::visit( CompoundStmt *compoundStmt ) { 77 acceptAll( compoundStmt->get_kids(), *this ); 78 } 79 80 void Visitor::visit( ExprStmt *exprStmt ) { 81 maybeAccept( exprStmt->get_expr(), *this ); 82 } 83 84 void Visitor::visit( IfStmt *ifStmt ) { 85 maybeAccept( ifStmt->get_condition(), *this ); 86 maybeAccept( ifStmt->get_thenPart(), *this ); 87 maybeAccept( ifStmt->get_elsePart(), *this ); 88 } 89 90 void Visitor::visit( WhileStmt *whileStmt ) { 91 maybeAccept( whileStmt->get_condition(), *this ); 92 maybeAccept( whileStmt->get_body(), *this ); 93 } 94 95 void Visitor::visit( ForStmt *forStmt ) { 96 // ForStmt still needs to be fixed 97 maybeAccept( forStmt->get_initialization(), *this ); 98 maybeAccept( forStmt->get_condition(), *this ); 99 maybeAccept( forStmt->get_increment(), *this ); 100 maybeAccept( forStmt->get_body(), *this ); 101 } 102 103 void Visitor::visit( SwitchStmt *switchStmt ) { 104 maybeAccept( switchStmt->get_condition(), *this ); 105 acceptAll( switchStmt->get_branches(), *this ); 106 } 107 108 void Visitor::visit( ChooseStmt *switchStmt ) { 109 maybeAccept( switchStmt->get_condition(), *this ); 110 acceptAll( switchStmt->get_branches(), *this ); 111 } 112 113 void Visitor::visit( FallthruStmt *fallthruStmt ){} 114 115 void Visitor::visit( CaseStmt *caseStmt ) { 116 maybeAccept( caseStmt->get_condition(), *this ); 117 acceptAll( caseStmt->get_statements(), *this ); 118 } 119 120 void Visitor::visit( BranchStmt *branchStmt ) { 121 } 122 123 void Visitor::visit( ReturnStmt *returnStmt ) { 124 maybeAccept( returnStmt->get_expr(), *this ); 125 } 126 127 void Visitor::visit( TryStmt *tryStmt ) { 128 maybeAccept( tryStmt->get_block(), *this ); 129 acceptAll( tryStmt->get_catchers(), *this ); 130 } 131 132 void Visitor::visit( CatchStmt *catchStmt ) { 133 maybeAccept( catchStmt->get_decl(), *this ); 134 maybeAccept( catchStmt->get_body(), *this ); 135 } 136 137 void Visitor::visit( FinallyStmt *finalStmt ) { 138 maybeAccept( finalStmt->get_block(), *this ); 139 } 140 141 void Visitor::visit( NullStmt *nullStmt ) { 142 } 143 144 void Visitor::visit( DeclStmt *declStmt ) { 145 maybeAccept( declStmt->get_decl(), *this ); 146 } 147 148 void Visitor::visit( ApplicationExpr *applicationExpr ) { 149 acceptAll( applicationExpr->get_results(), *this ); 150 maybeAccept( applicationExpr->get_function(), *this ); 151 acceptAll( applicationExpr->get_args(), *this ); 152 } 153 154 void Visitor::visit( UntypedExpr *untypedExpr ) { 155 acceptAll( untypedExpr->get_results(), *this ); 156 acceptAll( untypedExpr->get_args(), *this ); 157 } 158 159 void Visitor::visit( NameExpr *nameExpr ) { 160 acceptAll( nameExpr->get_results(), *this ); 161 } 162 163 void Visitor::visit( AddressExpr *addressExpr ) { 164 acceptAll( addressExpr->get_results(), *this ); 165 maybeAccept( addressExpr->get_arg(), *this ); 166 } 167 168 void Visitor::visit( LabelAddressExpr *labAddressExpr ) { 169 acceptAll( labAddressExpr->get_results(), *this ); 170 maybeAccept( labAddressExpr->get_arg(), *this ); 171 } 172 173 void Visitor::visit( CastExpr *castExpr ) { 174 acceptAll( castExpr->get_results(), *this ); 175 maybeAccept( castExpr->get_arg(), *this ); 176 } 177 178 void Visitor::visit( UntypedMemberExpr *memberExpr ) { 179 acceptAll( memberExpr->get_results(), *this ); 180 maybeAccept( memberExpr->get_aggregate(), *this ); 181 } 182 183 void Visitor::visit( MemberExpr *memberExpr ) { 184 acceptAll( memberExpr->get_results(), *this ); 185 maybeAccept( memberExpr->get_aggregate(), *this ); 186 } 187 188 void Visitor::visit( VariableExpr *variableExpr ) { 189 acceptAll( variableExpr->get_results(), *this ); 190 } 191 192 void Visitor::visit( ConstantExpr *constantExpr ) { 193 acceptAll( constantExpr->get_results(), *this ); 194 maybeAccept( constantExpr->get_constant(), *this ); 195 } 196 197 void Visitor::visit( SizeofExpr *sizeofExpr ) { 198 acceptAll( sizeofExpr->get_results(), *this ); 199 if ( sizeofExpr->get_isType() ) { 200 maybeAccept( sizeofExpr->get_type(), *this ); 201 } else { 202 maybeAccept( sizeofExpr->get_expr(), *this ); 203 } 204 } 205 206 void Visitor::visit( AttrExpr *attrExpr ) { 207 acceptAll( attrExpr->get_results(), *this ); 208 if ( attrExpr->get_isType() ) { 209 maybeAccept( attrExpr->get_type(), *this ); 210 } else { 211 maybeAccept( attrExpr->get_expr(), *this ); 212 } 213 } 214 215 void Visitor::visit( LogicalExpr *logicalExpr ) { 216 acceptAll( logicalExpr->get_results(), *this ); 217 maybeAccept( logicalExpr->get_arg1(), *this ); 218 maybeAccept( logicalExpr->get_arg2(), *this ); 219 } 220 221 void Visitor::visit( ConditionalExpr *conditionalExpr ) { 222 acceptAll( conditionalExpr->get_results(), *this ); 223 maybeAccept( conditionalExpr->get_arg1(), *this ); 224 maybeAccept( conditionalExpr->get_arg2(), *this ); 225 maybeAccept( conditionalExpr->get_arg3(), *this ); 226 } 227 228 void Visitor::visit( CommaExpr *commaExpr ) { 229 acceptAll( commaExpr->get_results(), *this ); 230 maybeAccept( commaExpr->get_arg1(), *this ); 231 maybeAccept( commaExpr->get_arg2(), *this ); 232 } 233 234 void Visitor::visit( TupleExpr *tupleExpr ) { 235 acceptAll( tupleExpr->get_results(), *this ); 236 acceptAll( tupleExpr->get_exprs(), *this ); 237 } 238 239 void Visitor::visit( SolvedTupleExpr *tupleExpr ) { 240 acceptAll( tupleExpr->get_results(), *this ); 241 acceptAll( tupleExpr->get_exprs(), *this ); 242 } 243 244 void Visitor::visit( TypeExpr *typeExpr ) { 245 acceptAll( typeExpr->get_results(), *this ); 246 maybeAccept( typeExpr->get_type(), *this ); 247 } 248 249 void Visitor::visit( UntypedValofExpr *valofExpr ) { 250 acceptAll( valofExpr->get_results(), *this ); 251 maybeAccept( valofExpr->get_body(), *this ); 252 } 253 254 void Visitor::visit( VoidType *voidType ) { 255 acceptAll( voidType->get_forall(), *this ); 256 } 257 258 void Visitor::visit( BasicType *basicType ) { 259 acceptAll( basicType->get_forall(), *this ); 260 } 261 262 void Visitor::visit( PointerType *pointerType ) { 263 acceptAll( pointerType->get_forall(), *this ); 264 maybeAccept( pointerType->get_base(), *this ); 265 } 266 267 void Visitor::visit( ArrayType *arrayType ) { 268 acceptAll( arrayType->get_forall(), *this ); 269 maybeAccept( arrayType->get_dimension(), *this ); 270 maybeAccept( arrayType->get_base(), *this ); 271 } 272 273 void Visitor::visit( FunctionType *functionType ) { 274 acceptAll( functionType->get_forall(), *this ); 275 acceptAll( functionType->get_returnVals(), *this ); 276 acceptAll( functionType->get_parameters(), *this ); 277 } 278 279 void Visitor::visit( ReferenceToType *aggregateUseType ) { 280 acceptAll( aggregateUseType->get_forall(), *this ); 281 acceptAll( aggregateUseType->get_parameters(), *this ); 282 } 283 284 void Visitor::visit( StructInstType *aggregateUseType ) { 285 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 286 } 287 288 void Visitor::visit( UnionInstType *aggregateUseType ) { 289 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 290 } 291 292 void Visitor::visit( EnumInstType *aggregateUseType ) { 293 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 294 } 295 296 void Visitor::visit( ContextInstType *aggregateUseType ) { 297 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 298 acceptAll( aggregateUseType->get_members(), *this ); 299 } 300 301 void Visitor::visit( TypeInstType *aggregateUseType ) { 302 visit( static_cast< ReferenceToType* >( aggregateUseType ) ); 303 } 304 305 void Visitor::visit( TupleType *tupleType ) { 306 acceptAll( tupleType->get_forall(), *this ); 307 acceptAll( tupleType->get_types(), *this ); 308 } 309 310 void Visitor::visit( TypeofType *typeofType ) { 311 assert( typeofType->get_expr() ); 312 typeofType->get_expr()->accept( *this ); 313 } 314 315 void Visitor::visit( AttrType *attrType ) { 316 if ( attrType->get_isType() ) { 317 assert( attrType->get_type() ); 318 attrType->get_type()->accept( *this ); 319 } else { 320 assert( attrType->get_expr() ); 321 attrType->get_expr()->accept( *this ); 322 } // if 323 } 324 325 void Visitor::visit( SingleInit *singleInit ) { 326 singleInit->get_value()->accept( *this ); 327 } 328 329 void Visitor::visit( ListInit *listInit ) { 330 acceptAll( listInit->get_designators(), *this ); 331 acceptAll( listInit->get_initializers(), *this ); 332 } 333 334 void Visitor::visit( Subrange *subrange ) {} 335 336 void Visitor::visit( Constant *constant ) {} 337 // Local Variables: // 338 // tab-width: 4 // 339 // mode: c++ // 340 // compile-command: "make install" // 341 // End: // -
translator/SynTree/Visitor.h
ra32b204 r0dd3a2f 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // Visitor.h -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:15:55 2015 13 // Update Count : 2 14 // 15 1 16 #ifndef VISITOR_H 2 17 #define VISITOR_H … … 6 21 #include "CompilerError.h" 7 22 8 9 23 class Visitor { 10 24 protected: 11 12 25 Visitor(); 26 virtual ~Visitor(); 13 27 public: 14 15 16 17 18 19 20 21 28 virtual void visit( ObjectDecl *objectDecl ); 29 virtual void visit( FunctionDecl *functionDecl ); 30 virtual void visit( StructDecl *aggregateDecl ); 31 virtual void visit( UnionDecl *aggregateDecl ); 32 virtual void visit( EnumDecl *aggregateDecl ); 33 virtual void visit( ContextDecl *aggregateDecl ); 34 virtual void visit( TypeDecl *typeDecl ); 35 virtual void visit( TypedefDecl *typeDecl ); 22 36 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 37 virtual void visit( CompoundStmt *compoundStmt ); 38 virtual void visit( ExprStmt *exprStmt ); 39 virtual void visit( IfStmt *ifStmt ); 40 virtual void visit( WhileStmt *whileStmt ); 41 virtual void visit( ForStmt *forStmt ); 42 virtual void visit( SwitchStmt *switchStmt ); 43 virtual void visit( ChooseStmt *switchStmt ); 44 virtual void visit( FallthruStmt *switchStmt ); 45 virtual void visit( CaseStmt *caseStmt ); 46 virtual void visit( BranchStmt *branchStmt ); 47 virtual void visit( ReturnStmt *returnStmt ); 48 virtual void visit( TryStmt *tryStmt ); 49 virtual void visit( CatchStmt *catchStmt ); 50 virtual void visit( FinallyStmt *finallyStmt ); 51 virtual void visit( NullStmt *nullStmt ); 52 virtual void visit( DeclStmt *declStmt ); 39 53 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 54 virtual void visit( ApplicationExpr *applicationExpr ); 55 virtual void visit( UntypedExpr *untypedExpr ); 56 virtual void visit( NameExpr *nameExpr ); 57 virtual void visit( CastExpr *castExpr ); 58 virtual void visit( AddressExpr *addressExpr ); 59 virtual void visit( LabelAddressExpr *labAddressExpr ); 60 virtual void visit( UntypedMemberExpr *memberExpr ); 61 virtual void visit( MemberExpr *memberExpr ); 62 virtual void visit( VariableExpr *variableExpr ); 63 virtual void visit( ConstantExpr *constantExpr ); 64 virtual void visit( SizeofExpr *sizeofExpr ); 65 virtual void visit( AttrExpr *attrExpr ); 66 virtual void visit( LogicalExpr *logicalExpr ); 67 virtual void visit( ConditionalExpr *conditionalExpr ); 68 virtual void visit( CommaExpr *commaExpr ); 69 virtual void visit( TupleExpr *tupleExpr ); 70 virtual void visit( SolvedTupleExpr *tupleExpr ); 71 virtual void visit( TypeExpr *typeExpr ); 72 virtual void visit( UntypedValofExpr *valofExpr ); 59 73 60 61 62 63 64 65 66 67 68 69 70 71 72 74 virtual void visit( VoidType *basicType ); 75 virtual void visit( BasicType *basicType ); 76 virtual void visit( PointerType *pointerType ); 77 virtual void visit( ArrayType *arrayType ); 78 virtual void visit( FunctionType *functionType ); 79 virtual void visit( StructInstType *aggregateUseType ); 80 virtual void visit( UnionInstType *aggregateUseType ); 81 virtual void visit( EnumInstType *aggregateUseType ); 82 virtual void visit( ContextInstType *aggregateUseType ); 83 virtual void visit( TypeInstType *aggregateUseType ); 84 virtual void visit( TupleType *tupleType ); 85 virtual void visit( TypeofType *typeofType ); 86 virtual void visit( AttrType *attrType ); 73 87 74 75 88 virtual void visit( SingleInit *singleInit ); 89 virtual void visit( ListInit *listInit ); 76 90 77 91 virtual void visit( Subrange *subrange ); 78 92 79 93 virtual void visit( Constant *constant ); 80 94 private: 81 82 83 95 virtual void visit( AggregateDecl *aggregateDecl ); 96 virtual void visit( NamedTypeDecl *typeDecl ); 97 virtual void visit( ReferenceToType *aggregateUseType ); 84 98 }; 85 99 86 100 template< typename TreeType, typename VisitorType > 87 101 inline void maybeAccept( TreeType *tree, VisitorType &visitor ) { 88 89 tree->accept( visitor );90 102 if ( tree ) { 103 tree->accept( visitor ); 104 } 91 105 } 92 106 93 107 template< typename Container, typename VisitorType > 94 108 inline void acceptAll( Container &container, VisitorType &visitor ) { 95 SemanticError errors; 96 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 97 try { 98 if ( *i ) { 99 (*i)->accept( visitor ); 100 } 101 } catch( SemanticError &e ) { 102 errors.append( e ); 109 SemanticError errors; 110 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 111 try { 112 if ( *i ) { 113 (*i)->accept( visitor ); 114 } 115 } catch( SemanticError &e ) { 116 errors.append( e ); 117 } 103 118 } 104 } 105 if ( ! errors.isEmpty() ) { 106 throw errors; 107 } 119 if ( ! errors.isEmpty() ) { 120 throw errors; 121 } 108 122 } 109 123 110 124 template< typename Container, typename VisitorType > 111 125 void acceptAllFold( Container &container, VisitorType &visitor, VisitorType &around ) { 112 113 114 try {115 116 VisitorType *v = new VisitorType;117 (*i)->accept( *v );126 SemanticError errors; 127 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 128 try { 129 if ( *i ) { 130 VisitorType *v = new VisitorType; 131 (*i)->accept( *v ); 118 132 119 typename Container::iterator nxt = i; nxt++; // forward_iterator120 if ( nxt == container.end() )121 122 else123 133 typename Container::iterator nxt = i; nxt++; // forward_iterator 134 if ( nxt == container.end() ) 135 visitor += *v; 136 else 137 visitor += *v + around; 124 138 125 delete v;126 }127 } catch( SemanticError &e ) {128 129 }130 } 131 132 throw errors;133 } 139 delete v; 140 } // if 141 } catch( SemanticError &e ) { 142 errors.append( e ); 143 } // try 144 } // for 145 if ( ! errors.isEmpty() ) { 146 throw errors; 147 } // if 134 148 } 135 149 136 150 #endif // VISITOR_H 151 152 // Local Variables: // 153 // tab-width: 4 // 154 // mode: c++ // 155 // compile-command: "make install" // 156 // End: // -
translator/SynTree/VoidType.cc
ra32b204 r0dd3a2f 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: VoidType.cc,v 1.3 2005/08/29 20:59:27 rcbilson Exp $ 5 * 6 */ 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // VoidType.cc -- 8 // 9 // Author : Richard C. Bilson 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 11:16:42 2015 13 // Update Count : 1 14 // 7 15 8 16 #include "Type.h" 9 17 10 11 VoidType::VoidType( const Type::Qualifiers &tq ) 12 : Type( tq ) 13 { 18 VoidType::VoidType( const Type::Qualifiers &tq ) : Type( tq ) { 14 19 } 15 20 16 void 17 VoidType::print( std::ostream &os, int indent ) const 18 { 19 Type::print( os, indent ); 20 os << "void "; 21 void VoidType::print( std::ostream &os, int indent ) const { 22 Type::print( os, indent ); 23 os << "void "; 21 24 } 22 25 26 // Local Variables: // 27 // tab-width: 4 // 28 // mode: c++ // 29 // compile-command: "make install" // 30 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.