[a32b204] | 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 | // |
---|
[906e24d] | 7 | // ResolveTypeof.cc -- |
---|
[a32b204] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 12:12:20 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[a08ba92] | 12 | // Last Modified On : Tue May 19 16:49:04 2015 |
---|
| 13 | // Update Count : 3 |
---|
[a32b204] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include "ResolveTypeof.h" |
---|
| 17 | #include "Alternative.h" |
---|
| 18 | #include "AlternativeFinder.h" |
---|
| 19 | #include "Resolver.h" |
---|
| 20 | #include "TypeEnvironment.h" |
---|
| 21 | #include "SynTree/Expression.h" |
---|
| 22 | #include "SynTree/Type.h" |
---|
| 23 | |
---|
| 24 | namespace ResolvExpr { |
---|
[a08ba92] | 25 | namespace { |
---|
[51b7345] | 26 | #if 0 |
---|
[a32b204] | 27 | void |
---|
| 28 | printAlts( const AltList &list, std::ostream &os, int indent = 0 ) |
---|
| 29 | { |
---|
| 30 | for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) { |
---|
| 31 | i->print( os, indent ); |
---|
| 32 | os << std::endl; |
---|
| 33 | } |
---|
| 34 | } |
---|
[51b7345] | 35 | #endif |
---|
[a08ba92] | 36 | } |
---|
[51b7345] | 37 | |
---|
[a08ba92] | 38 | class ResolveTypeof : public Mutator { |
---|
| 39 | public: |
---|
[a32b204] | 40 | ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {} |
---|
| 41 | Type *mutate( TypeofType *typeofType ); |
---|
[51b7345] | 42 | |
---|
[a08ba92] | 43 | private: |
---|
[a32b204] | 44 | const SymTab::Indexer &indexer; |
---|
[a08ba92] | 45 | }; |
---|
[51b7345] | 46 | |
---|
[a08ba92] | 47 | Type *resolveTypeof( Type *type, const SymTab::Indexer &indexer ) { |
---|
[a32b204] | 48 | ResolveTypeof mutator( indexer ); |
---|
| 49 | return type->acceptMutator( mutator ); |
---|
[a08ba92] | 50 | } |
---|
[51b7345] | 51 | |
---|
[a08ba92] | 52 | Type *ResolveTypeof::mutate( TypeofType *typeofType ) { |
---|
[d9a0e76] | 53 | #if 0 |
---|
[a32b204] | 54 | std::cout << "resolving typeof: "; |
---|
| 55 | typeofType->print( std::cout ); |
---|
| 56 | std::cout << std::endl; |
---|
[d9a0e76] | 57 | #endif |
---|
[a32b204] | 58 | if ( typeofType->get_expr() ) { |
---|
| 59 | Expression *newExpr = resolveInVoidContext( typeofType->get_expr(), indexer ); |
---|
[906e24d] | 60 | assert( newExpr->has_result() && ! newExpr->get_result()->isVoid() ); |
---|
| 61 | Type *newType = newExpr->get_result(); |
---|
[a32b204] | 62 | delete typeofType; |
---|
| 63 | return newType; |
---|
| 64 | } // if |
---|
| 65 | return typeofType; |
---|
[a08ba92] | 66 | } |
---|
[51b7345] | 67 | } // namespace ResolvExpr |
---|
[a32b204] | 68 | |
---|
| 69 | // Local Variables: // |
---|
| 70 | // tab-width: 4 // |
---|
| 71 | // mode: c++ // |
---|
| 72 | // compile-command: "make install" // |
---|
| 73 | // End: // |
---|