[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" |
---|
[ea6332d] | 17 | |
---|
| 18 | #include <cassert> // for assert |
---|
| 19 | |
---|
[9d79f93] | 20 | #include "Common/PassVisitor.h" // for PassVisitor |
---|
[ea6332d] | 21 | #include "Resolver.h" // for resolveInVoidContext |
---|
| 22 | #include "SynTree/Expression.h" // for Expression |
---|
| 23 | #include "SynTree/Mutator.h" // for Mutator |
---|
| 24 | #include "SynTree/Type.h" // for TypeofType, Type |
---|
| 25 | |
---|
| 26 | namespace SymTab { |
---|
| 27 | class Indexer; |
---|
| 28 | } // namespace SymTab |
---|
[51b7345] | 29 | |
---|
| 30 | namespace ResolvExpr { |
---|
[a08ba92] | 31 | namespace { |
---|
[51b7345] | 32 | #if 0 |
---|
[a32b204] | 33 | void |
---|
| 34 | printAlts( const AltList &list, std::ostream &os, int indent = 0 ) |
---|
| 35 | { |
---|
| 36 | for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) { |
---|
| 37 | i->print( os, indent ); |
---|
| 38 | os << std::endl; |
---|
| 39 | } |
---|
| 40 | } |
---|
[51b7345] | 41 | #endif |
---|
[a08ba92] | 42 | } |
---|
[51b7345] | 43 | |
---|
[9d79f93] | 44 | class ResolveTypeof : public WithShortCircuiting { |
---|
[a08ba92] | 45 | public: |
---|
[a32b204] | 46 | ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {} |
---|
[9d79f93] | 47 | void premutate( TypeofType *typeofType ); |
---|
| 48 | Type * postmutate( TypeofType *typeofType ); |
---|
[51b7345] | 49 | |
---|
[a08ba92] | 50 | private: |
---|
[a32b204] | 51 | const SymTab::Indexer &indexer; |
---|
[a08ba92] | 52 | }; |
---|
[51b7345] | 53 | |
---|
[9d79f93] | 54 | Type * resolveTypeof( Type *type, const SymTab::Indexer &indexer ) { |
---|
| 55 | PassVisitor<ResolveTypeof> mutator( indexer ); |
---|
[a32b204] | 56 | return type->acceptMutator( mutator ); |
---|
[a08ba92] | 57 | } |
---|
[51b7345] | 58 | |
---|
[9d79f93] | 59 | void ResolveTypeof::premutate( TypeofType * ) { |
---|
| 60 | visit_children = false; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | Type * ResolveTypeof::postmutate( TypeofType *typeofType ) { |
---|
[d9a0e76] | 64 | #if 0 |
---|
[9d79f93] | 65 | std::cerr << "resolving typeof: "; |
---|
| 66 | typeofType->print( std::cerr ); |
---|
| 67 | std::cerr << std::endl; |
---|
[d9a0e76] | 68 | #endif |
---|
[9d79f93] | 69 | if ( typeofType->expr ) { |
---|
| 70 | Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer ); |
---|
| 71 | assert( newExpr->result && ! newExpr->result->isVoid() ); |
---|
| 72 | Type * newType = newExpr->result; |
---|
| 73 | newExpr->result = nullptr; |
---|
[a32b204] | 74 | delete typeofType; |
---|
[c93bc28] | 75 | delete newExpr; |
---|
[a32b204] | 76 | return newType; |
---|
| 77 | } // if |
---|
| 78 | return typeofType; |
---|
[a08ba92] | 79 | } |
---|
[51b7345] | 80 | } // namespace ResolvExpr |
---|
[a32b204] | 81 | |
---|
| 82 | // Local Variables: // |
---|
| 83 | // tab-width: 4 // |
---|
| 84 | // mode: c++ // |
---|
| 85 | // compile-command: "make install" // |
---|
| 86 | // End: // |
---|