| [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 | //
 | 
|---|
| [2c57025] | 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 | 
 | 
|---|
| [51b73452] | 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"
 | 
|---|
| [51b73452] | 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() ) {
 | 
|---|
| [2c57025] | 30 |                         switch ( tyVar->second.kind ) {
 | 
|---|
| [01aeade] | 31 |                           case TypeDecl::Any:
 | 
|---|
 | 32 |                           case TypeDecl::Dtype:
 | 
|---|
| [8f60f0b] | 33 |                           case TypeDecl::Ttype:
 | 
|---|
| [01aeade] | 34 |                                 {
 | 
|---|
 | 35 |                                         PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );
 | 
|---|
 | 36 |                                         delete typeInst;
 | 
|---|
 | 37 |                                         return ret;
 | 
|---|
 | 38 |                                 }
 | 
|---|
 | 39 |                           case TypeDecl::Ftype:
 | 
|---|
 | 40 |                                 delete typeInst;
 | 
|---|
 | 41 |                                 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
 | 
|---|
 | 42 |                         } // switch
 | 
|---|
 | 43 |                 } // if
 | 
|---|
 | 44 |                 return typeInst;
 | 
|---|
| [a08ba92] | 45 |         }
 | 
|---|
| [51b73452] | 46 | 
 | 
|---|
| [b18b0b5] | 47 |         Type * ScrubTyVars::mutateAggregateType( Type *ty ) {
 | 
|---|
| [3bb195cb] | 48 |                 if ( shouldScrub( ty ) ) {
 | 
|---|
| [b18b0b5] | 49 |                         PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) );
 | 
|---|
 | 50 |                         delete ty;
 | 
|---|
 | 51 |                         return ret;
 | 
|---|
 | 52 |                 }
 | 
|---|
 | 53 |                 return ty;
 | 
|---|
 | 54 |         }
 | 
|---|
| [2c57025] | 55 | 
 | 
|---|
| [b18b0b5] | 56 |         Type * ScrubTyVars::mutate( StructInstType *structInst ) {
 | 
|---|
 | 57 |                 return mutateAggregateType( structInst );
 | 
|---|
 | 58 |         }
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 |         Type * ScrubTyVars::mutate( UnionInstType *unionInst ) {
 | 
|---|
 | 61 |                 return mutateAggregateType( unionInst );
 | 
|---|
 | 62 |         }
 | 
|---|
 | 63 | 
 | 
|---|
| [a08ba92] | 64 |         Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
 | 
|---|
| [db0b3ce] | 65 |                 // sizeof( T ) => _sizeof_T parameter, which is the size of T
 | 
|---|
| [3bb195cb] | 66 |                 if ( Type *dynType = shouldScrub( szeof->get_type() ) ) {
 | 
|---|
 | 67 |                         Expression *expr = new NameExpr( sizeofName( mangleType( dynType ) ) );
 | 
|---|
| [01aeade] | 68 |                         return expr;
 | 
|---|
 | 69 |                 } else {
 | 
|---|
 | 70 |                         return Mutator::mutate( szeof );
 | 
|---|
 | 71 |                 } // if
 | 
|---|
| [a08ba92] | 72 |         }
 | 
|---|
| [51b73452] | 73 | 
 | 
|---|
| [db0b3ce] | 74 |         Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) {
 | 
|---|
 | 75 |                 // alignof( T ) => _alignof_T parameter, which is the alignment of T
 | 
|---|
| [3bb195cb] | 76 |                 if ( Type *dynType = shouldScrub( algnof->get_type() ) ) {
 | 
|---|
 | 77 |                         Expression *expr = new NameExpr( alignofName( mangleType( dynType ) ) );
 | 
|---|
| [db0b3ce] | 78 |                         return expr;
 | 
|---|
 | 79 |                 } else {
 | 
|---|
 | 80 |                         return Mutator::mutate( algnof );
 | 
|---|
 | 81 |                 } // if
 | 
|---|
 | 82 |         }
 | 
|---|
 | 83 | 
 | 
|---|
| [a08ba92] | 84 |         Type * ScrubTyVars::mutate( PointerType *pointer ) {
 | 
|---|
| [3bb195cb] | 85 | //              // special case of shouldScrub that takes all TypeInstType pointer bases, even if they're not dynamic
 | 
|---|
 | 86 | //              Type *base = pointer->get_base();
 | 
|---|
 | 87 | //              Type *dynType = 0;
 | 
|---|
 | 88 | //              if ( dynamicOnly ) {
 | 
|---|
 | 89 | //                      if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( base ) ) {
 | 
|---|
 | 90 | //                              if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { dynType = typeInst; }
 | 
|---|
 | 91 | //                      } else {
 | 
|---|
 | 92 | //                              dynType = isDynType( base, tyVars );
 | 
|---|
 | 93 | //                      }
 | 
|---|
 | 94 | //              } else {
 | 
|---|
 | 95 | //                      dynType = isPolyType( base, tyVars );
 | 
|---|
 | 96 | //              }
 | 
|---|
 | 97 | //              if ( dynType ) {
 | 
|---|
 | 98 |                 if ( Type *dynType = shouldScrub( pointer->get_base() ) ) {
 | 
|---|
 | 99 |                         Type *ret = dynType->acceptMutator( *this );
 | 
|---|
| [6d160d7] | 100 |                         ret->get_qualifiers() += pointer->get_qualifiers();
 | 
|---|
 | 101 |                         pointer->set_base( 0 );
 | 
|---|
 | 102 |                         delete pointer;
 | 
|---|
 | 103 |                         return ret;
 | 
|---|
 | 104 |                 }
 | 
|---|
| [01aeade] | 105 |                 return Mutator::mutate( pointer );
 | 
|---|
| [a08ba92] | 106 |         }
 | 
|---|
| [51b73452] | 107 | } // namespace GenPoly
 | 
|---|
| [01aeade] | 108 | 
 | 
|---|
| [51587aa] | 109 | // Local Variables: //
 | 
|---|
 | 110 | // tab-width: 4 //
 | 
|---|
 | 111 | // mode: c++ //
 | 
|---|
 | 112 | // compile-command: "make install" //
 | 
|---|
 | 113 | // End: //
 | 
|---|