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 | // ResolveTypeof.cc -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Sun May 17 12:12:20 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Tue May 19 16:49:04 2015 |
---|
13 | // Update Count : 3 |
---|
14 | // |
---|
15 | |
---|
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 { |
---|
25 | namespace { |
---|
26 | #if 0 |
---|
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 | } |
---|
35 | #endif |
---|
36 | } |
---|
37 | |
---|
38 | class ResolveTypeof : public Mutator { |
---|
39 | public: |
---|
40 | ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {} |
---|
41 | Type *mutate( TypeofType *typeofType ); |
---|
42 | |
---|
43 | private: |
---|
44 | const SymTab::Indexer &indexer; |
---|
45 | }; |
---|
46 | |
---|
47 | Type *resolveTypeof( Type *type, const SymTab::Indexer &indexer ) { |
---|
48 | ResolveTypeof mutator( indexer ); |
---|
49 | return type->acceptMutator( mutator ); |
---|
50 | } |
---|
51 | |
---|
52 | Type *ResolveTypeof::mutate( TypeofType *typeofType ) { |
---|
53 | #if 0 |
---|
54 | std::cout << "resolving typeof: "; |
---|
55 | typeofType->print( std::cout ); |
---|
56 | std::cout << std::endl; |
---|
57 | #endif |
---|
58 | if ( typeofType->get_expr() ) { |
---|
59 | Expression *newExpr = resolveInVoidContext( typeofType->get_expr(), indexer ); |
---|
60 | assert( newExpr->get_results().size() > 0 ); |
---|
61 | Type *newType; |
---|
62 | if ( newExpr->get_results().size() > 1 ) { |
---|
63 | TupleType *tupleType = new TupleType( Type::Qualifiers() ); |
---|
64 | cloneAll( newExpr->get_results(), tupleType->get_types() ); |
---|
65 | newType = tupleType; |
---|
66 | } else { |
---|
67 | newType = newExpr->get_results().front()->clone(); |
---|
68 | } // if |
---|
69 | delete typeofType; |
---|
70 | return newType; |
---|
71 | } // if |
---|
72 | return typeofType; |
---|
73 | } |
---|
74 | } // namespace ResolvExpr |
---|
75 | |
---|
76 | // Local Variables: // |
---|
77 | // tab-width: 4 // |
---|
78 | // mode: c++ // |
---|
79 | // compile-command: "make install" // |
---|
80 | // End: // |
---|