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 | // ScrubTyVars.cc -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Mon May 18 07:44:20 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Tue May 19 16:42:42 2015 |
---|
13 | // Update Count : 2 |
---|
14 | // |
---|
15 | |
---|
16 | #include "GenPoly.h" |
---|
17 | #include "ScrubTyVars.h" |
---|
18 | |
---|
19 | #include "SynTree/Mutator.h" |
---|
20 | #include "SynTree/Type.h" |
---|
21 | #include "SynTree/Expression.h" |
---|
22 | |
---|
23 | namespace GenPoly { |
---|
24 | Type * ScrubTyVars::mutate( TypeInstType *typeInst ) { |
---|
25 | TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() ); |
---|
26 | if ( doAll || tyVar != tyVars.end() ) { |
---|
27 | switch ( tyVar->second ) { |
---|
28 | case TypeDecl::Any: |
---|
29 | case TypeDecl::Dtype: |
---|
30 | { |
---|
31 | PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); |
---|
32 | delete typeInst; |
---|
33 | return ret; |
---|
34 | } |
---|
35 | case TypeDecl::Ftype: |
---|
36 | delete typeInst; |
---|
37 | return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); |
---|
38 | } // switch |
---|
39 | } // if |
---|
40 | return typeInst; |
---|
41 | } |
---|
42 | |
---|
43 | Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) { |
---|
44 | // sizeof( T ) => T parameter, which is the size of T |
---|
45 | if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) { |
---|
46 | Expression *expr = new NameExpr( typeInst->get_name() ); |
---|
47 | return expr; |
---|
48 | } else { |
---|
49 | return Mutator::mutate( szeof ); |
---|
50 | } // if |
---|
51 | } |
---|
52 | |
---|
53 | Type * ScrubTyVars::mutate( PointerType *pointer ) { |
---|
54 | if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) { |
---|
55 | if ( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) { |
---|
56 | Type *ret = mutate( typeInst ); |
---|
57 | ret->get_qualifiers() += pointer->get_qualifiers(); |
---|
58 | pointer->set_base( 0 ); |
---|
59 | delete pointer; |
---|
60 | return ret; |
---|
61 | } // if |
---|
62 | } // if |
---|
63 | return Mutator::mutate( pointer ); |
---|
64 | } |
---|
65 | } // namespace GenPoly |
---|
66 | |
---|
67 | // Local Variables: // |
---|
68 | // tab-width: 4 // |
---|
69 | // mode: c++ // |
---|
70 | // compile-command: "make install" // |
---|
71 | // End: // |
---|