[51587aa] | 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 | // |
---|
[01aeade] | 7 | // ScrubTyVars.cc -- |
---|
[51587aa] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[01aeade] | 11 | // Last Modified By : Peter A. Buhr |
---|
[a08ba92] | 12 | // Last Modified On : Tue May 19 16:42:42 2015 |
---|
| 13 | // Update Count : 2 |
---|
[51587aa] | 14 | // |
---|
[01aeade] | 15 | |
---|
[78dd0da] | 16 | #include <sstream> |
---|
[db0b3ce] | 17 | #include <string> |
---|
| 18 | |
---|
[51b7345] | 19 | #include "GenPoly.h" |
---|
| 20 | #include "ScrubTyVars.h" |
---|
| 21 | |
---|
| 22 | #include "SynTree/Mutator.h" |
---|
| 23 | #include "SynTree/Type.h" |
---|
[bdd516a] | 24 | #include "SynTree/Expression.h" |
---|
[51b7345] | 25 | |
---|
| 26 | namespace GenPoly { |
---|
[a08ba92] | 27 | Type * ScrubTyVars::mutate( TypeInstType *typeInst ) { |
---|
[01aeade] | 28 | TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() ); |
---|
[ebe9b3a] | 29 | if ( tyVar != tyVars.end() ) { |
---|
[01aeade] | 30 | switch ( tyVar->second ) { |
---|
| 31 | case TypeDecl::Any: |
---|
| 32 | case TypeDecl::Dtype: |
---|
| 33 | { |
---|
| 34 | PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); |
---|
| 35 | delete typeInst; |
---|
| 36 | return ret; |
---|
| 37 | } |
---|
| 38 | case TypeDecl::Ftype: |
---|
| 39 | delete typeInst; |
---|
| 40 | return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); |
---|
| 41 | } // switch |
---|
| 42 | } // if |
---|
| 43 | return typeInst; |
---|
[a08ba92] | 44 | } |
---|
[51b7345] | 45 | |
---|
[b18b0b5] | 46 | Type * ScrubTyVars::mutateAggregateType( Type *ty ) { |
---|
[3bb195cb] | 47 | if ( shouldScrub( ty ) ) { |
---|
[b18b0b5] | 48 | PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) ); |
---|
| 49 | delete ty; |
---|
| 50 | return ret; |
---|
| 51 | } |
---|
| 52 | return ty; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | Type * ScrubTyVars::mutate( StructInstType *structInst ) { |
---|
| 56 | return mutateAggregateType( structInst ); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | Type * ScrubTyVars::mutate( UnionInstType *unionInst ) { |
---|
| 60 | return mutateAggregateType( unionInst ); |
---|
| 61 | } |
---|
| 62 | |
---|
[a08ba92] | 63 | Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) { |
---|
[db0b3ce] | 64 | // sizeof( T ) => _sizeof_T parameter, which is the size of T |
---|
[3bb195cb] | 65 | if ( Type *dynType = shouldScrub( szeof->get_type() ) ) { |
---|
| 66 | Expression *expr = new NameExpr( sizeofName( mangleType( dynType ) ) ); |
---|
[01aeade] | 67 | return expr; |
---|
| 68 | } else { |
---|
| 69 | return Mutator::mutate( szeof ); |
---|
| 70 | } // if |
---|
[a08ba92] | 71 | } |
---|
[51b7345] | 72 | |
---|
[db0b3ce] | 73 | Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) { |
---|
| 74 | // alignof( T ) => _alignof_T parameter, which is the alignment of T |
---|
[3bb195cb] | 75 | if ( Type *dynType = shouldScrub( algnof->get_type() ) ) { |
---|
| 76 | Expression *expr = new NameExpr( alignofName( mangleType( dynType ) ) ); |
---|
[db0b3ce] | 77 | return expr; |
---|
| 78 | } else { |
---|
| 79 | return Mutator::mutate( algnof ); |
---|
| 80 | } // if |
---|
| 81 | } |
---|
| 82 | |
---|
[a08ba92] | 83 | Type * ScrubTyVars::mutate( PointerType *pointer ) { |
---|
[3bb195cb] | 84 | // // special case of shouldScrub that takes all TypeInstType pointer bases, even if they're not dynamic |
---|
| 85 | // Type *base = pointer->get_base(); |
---|
| 86 | // Type *dynType = 0; |
---|
| 87 | // if ( dynamicOnly ) { |
---|
| 88 | // if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( base ) ) { |
---|
| 89 | // if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { dynType = typeInst; } |
---|
| 90 | // } else { |
---|
| 91 | // dynType = isDynType( base, tyVars ); |
---|
| 92 | // } |
---|
| 93 | // } else { |
---|
| 94 | // dynType = isPolyType( base, tyVars ); |
---|
| 95 | // } |
---|
| 96 | // if ( dynType ) { |
---|
| 97 | if ( Type *dynType = shouldScrub( pointer->get_base() ) ) { |
---|
| 98 | Type *ret = dynType->acceptMutator( *this ); |
---|
[6d160d7] | 99 | ret->get_qualifiers() += pointer->get_qualifiers(); |
---|
| 100 | pointer->set_base( 0 ); |
---|
| 101 | delete pointer; |
---|
| 102 | return ret; |
---|
| 103 | } |
---|
[01aeade] | 104 | return Mutator::mutate( pointer ); |
---|
[a08ba92] | 105 | } |
---|
[51b7345] | 106 | } // namespace GenPoly |
---|
[01aeade] | 107 | |
---|
[51587aa] | 108 | // Local Variables: // |
---|
| 109 | // tab-width: 4 // |
---|
| 110 | // mode: c++ // |
---|
| 111 | // compile-command: "make install" // |
---|
| 112 | // End: // |
---|