Changeset d9a0e76 for translator/ResolvExpr/ResolveTypeof.cc
- Timestamp:
- Dec 16, 2014, 9:41:50 PM (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:
- 17cd4eb
- Parents:
- 3848e0e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/ResolvExpr/ResolveTypeof.cc
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: ResolveTypeof.cc,v 1.2 2005/08/29 20:14:16 rcbilson Exp $5 *6 */7 8 1 #include "ResolveTypeof.h" 9 2 #include "Alternative.h" … … 15 8 16 9 namespace ResolvExpr { 10 namespace { 11 #if 0 12 void 13 printAlts( const AltList &list, std::ostream &os, int indent = 0 ) 14 { 15 for( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) { 16 i->print( os, indent ); 17 os << std::endl; 18 } 19 } 20 #endif 21 } 17 22 18 namespace { 23 class ResolveTypeof : public Mutator { 24 public: 25 ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {} 26 Type *mutate( TypeofType *typeofType ); 27 28 private: 29 const SymTab::Indexer &indexer; 30 }; 31 32 Type *resolveTypeof( Type *type, const SymTab::Indexer &indexer ) { 33 ResolveTypeof mutator( indexer ); 34 return type->acceptMutator( mutator ); 35 } 36 37 Type *ResolveTypeof::mutate( TypeofType *typeofType ) { 19 38 #if 0 20 void 21 printAlts( const AltList &list, std::ostream &os, int indent = 0 ) 22 { 23 for( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) { 24 i->print( os, indent ); 25 os << std::endl; 39 std::cout << "resolving typeof: "; 40 typeofType->print( std::cout ); 41 std::cout << std::endl; 42 #endif 43 if ( typeofType->get_expr() ) { 44 Expression *newExpr = resolveInVoidContext( typeofType->get_expr(), indexer ); 45 assert( newExpr->get_results().size() > 0 ); 46 Type *newType; 47 if ( newExpr->get_results().size() > 1 ) { 48 TupleType *tupleType = new TupleType( Type::Qualifiers() ); 49 cloneAll( newExpr->get_results(), tupleType->get_types() ); 50 newType = tupleType; 51 } else { 52 newType = newExpr->get_results().front()->clone(); 53 } 54 delete typeofType; 55 return newType; 56 } 57 return typeofType; 26 58 } 27 }28 #endif29 }30 31 class ResolveTypeof : public Mutator32 {33 public:34 ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {}35 Type *mutate( TypeofType *typeofType );36 37 private:38 const SymTab::Indexer &indexer;39 };40 41 Type *42 resolveTypeof( Type *type, const SymTab::Indexer &indexer )43 {44 ResolveTypeof mutator( indexer );45 return type->acceptMutator( mutator );46 }47 48 Type *49 ResolveTypeof::mutate( TypeofType *typeofType )50 {51 /// std::cout << "resolving typeof: ";52 /// typeofType->print( std::cout );53 /// std::cout << std::endl;54 if( typeofType->get_expr() ) {55 Expression *newExpr = resolveInVoidContext( typeofType->get_expr(), indexer );56 assert( newExpr->get_results().size() > 0 );57 Type *newType;58 if( newExpr->get_results().size() > 1 ) {59 TupleType *tupleType = new TupleType( Type::Qualifiers() );60 cloneAll( newExpr->get_results(), tupleType->get_types() );61 newType = tupleType;62 } else {63 newType = newExpr->get_results().front()->clone();64 }65 delete typeofType;66 return newType;67 }68 return typeofType;69 }70 59 71 60 } // namespace ResolvExpr
Note: See TracChangeset
for help on using the changeset viewer.