[51b7345] | 1 | /* |
---|
| 2 | * This file is part of the Cforall project |
---|
| 3 | * |
---|
| 4 | * $Id: ResolveTypeof.cc,v 1.2 2005/08/29 20:14:16 rcbilson Exp $ |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "ResolveTypeof.h" |
---|
| 9 | #include "Alternative.h" |
---|
| 10 | #include "AlternativeFinder.h" |
---|
| 11 | #include "Resolver.h" |
---|
| 12 | #include "TypeEnvironment.h" |
---|
| 13 | #include "SynTree/Expression.h" |
---|
| 14 | #include "SynTree/Type.h" |
---|
| 15 | |
---|
| 16 | namespace ResolvExpr { |
---|
| 17 | |
---|
| 18 | namespace { |
---|
| 19 | #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; |
---|
| 26 | } |
---|
| 27 | } |
---|
| 28 | #endif |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | class ResolveTypeof : public Mutator |
---|
| 32 | { |
---|
| 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 | |
---|
| 71 | } // namespace ResolvExpr |
---|