| [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 | 
|---|
| [6f95000] | 12 | // Last Modified On : Thu Mar 16 15:44:27 2017 | 
|---|
|  | 13 | // Update Count     : 3 | 
|---|
| [51587aa] | 14 | // | 
|---|
| [01aeade] | 15 |  | 
|---|
| [08fc48f] | 16 | #include <utility>                      // for pair | 
|---|
| [db0b3ce] | 17 |  | 
|---|
| [08fc48f] | 18 | #include "GenPoly.h"                    // for mangleType, TyVarMap, alignof... | 
|---|
|  | 19 | #include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::const_it... | 
|---|
| [51b73452] | 20 | #include "ScrubTyVars.h" | 
|---|
| [08fc48f] | 21 | #include "SynTree/Declaration.h"        // for TypeDecl, TypeDecl::Data, Typ... | 
|---|
|  | 22 | #include "SynTree/Expression.h"         // for Expression (ptr only), NameExpr | 
|---|
|  | 23 | #include "SynTree/Mutator.h"            // for Mutator | 
|---|
|  | 24 | #include "SynTree/Type.h"               // for PointerType, TypeInstType, Type | 
|---|
| [51b73452] | 25 |  | 
|---|
|  | 26 | namespace GenPoly { | 
|---|
| [b8a4f47] | 27 | Type * ScrubTyVars::postmutate( TypeInstType * typeInst ) { | 
|---|
| [5a3ac84] | 28 | if ( ! tyVars ) { | 
|---|
|  | 29 | if ( typeInst->get_isFtype() ) { | 
|---|
|  | 30 | delete typeInst; | 
|---|
|  | 31 | return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); | 
|---|
|  | 32 | } else { | 
|---|
| [b8a4f47] | 33 | PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); | 
|---|
| [5a3ac84] | 34 | delete typeInst; | 
|---|
|  | 35 | return ret; | 
|---|
|  | 36 | } | 
|---|
|  | 37 | } | 
|---|
|  | 38 |  | 
|---|
| [b8a4f47] | 39 | TyVarMap::const_iterator tyVar = tyVars->find( typeInst->name ); | 
|---|
| [5a3ac84] | 40 | if ( tyVar != tyVars->end() ) { | 
|---|
| [2c57025] | 41 | switch ( tyVar->second.kind ) { | 
|---|
| [01aeade] | 42 | case TypeDecl::Dtype: | 
|---|
| [8f60f0b] | 43 | case TypeDecl::Ttype: | 
|---|
| [01aeade] | 44 | { | 
|---|
| [b8a4f47] | 45 | PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); | 
|---|
| [01aeade] | 46 | delete typeInst; | 
|---|
|  | 47 | return ret; | 
|---|
|  | 48 | } | 
|---|
|  | 49 | case TypeDecl::Ftype: | 
|---|
|  | 50 | delete typeInst; | 
|---|
|  | 51 | return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); | 
|---|
|  | 52 | } // switch | 
|---|
|  | 53 | } // if | 
|---|
|  | 54 | return typeInst; | 
|---|
| [a08ba92] | 55 | } | 
|---|
| [51b73452] | 56 |  | 
|---|
| [b8a4f47] | 57 | Type * ScrubTyVars::mutateAggregateType( Type * ty ) { | 
|---|
| [3bb195cb] | 58 | if ( shouldScrub( ty ) ) { | 
|---|
| [b8a4f47] | 59 | PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) ); | 
|---|
| [b18b0b5] | 60 | delete ty; | 
|---|
|  | 61 | return ret; | 
|---|
|  | 62 | } | 
|---|
|  | 63 | return ty; | 
|---|
|  | 64 | } | 
|---|
| [2c57025] | 65 |  | 
|---|
| [b8a4f47] | 66 | Type * ScrubTyVars::postmutate( StructInstType * structInst ) { | 
|---|
| [b18b0b5] | 67 | return mutateAggregateType( structInst ); | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [b8a4f47] | 70 | Type * ScrubTyVars::postmutate( UnionInstType * unionInst ) { | 
|---|
| [b18b0b5] | 71 | return mutateAggregateType( unionInst ); | 
|---|
|  | 72 | } | 
|---|
|  | 73 |  | 
|---|
| [b8a4f47] | 74 | void ScrubTyVars::primeBaseScrub( Type * type ) { | 
|---|
|  | 75 | // need to determine whether type needs to be scrubbed to determine whether | 
|---|
|  | 76 | // automatic recursion is necessary | 
|---|
|  | 77 | if ( Type * t = shouldScrub( type ) ) { | 
|---|
|  | 78 | visit_children = false; | 
|---|
|  | 79 | GuardValue( dynType ); | 
|---|
|  | 80 | dynType = t; | 
|---|
|  | 81 | } | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | Expression * ScrubTyVars::postmutate( SizeofExpr * szeof ) { | 
|---|
| [db0b3ce] | 85 | // sizeof( T ) => _sizeof_T parameter, which is the size of T | 
|---|
| [b8a4f47] | 86 | if ( dynType ) { | 
|---|
| [3bb195cb] | 87 | Expression *expr = new NameExpr( sizeofName( mangleType( dynType ) ) ); | 
|---|
| [01aeade] | 88 | return expr; | 
|---|
|  | 89 | } // if | 
|---|
| [b8a4f47] | 90 | return szeof; | 
|---|
| [a08ba92] | 91 | } | 
|---|
| [51b73452] | 92 |  | 
|---|
| [b8a4f47] | 93 | Expression * ScrubTyVars::postmutate( AlignofExpr * algnof ) { | 
|---|
| [db0b3ce] | 94 | // alignof( T ) => _alignof_T parameter, which is the alignment of T | 
|---|
| [b8a4f47] | 95 | if ( dynType ) { | 
|---|
| [3bb195cb] | 96 | Expression *expr = new NameExpr( alignofName( mangleType( dynType ) ) ); | 
|---|
| [db0b3ce] | 97 | return expr; | 
|---|
|  | 98 | } // if | 
|---|
| [b8a4f47] | 99 | return algnof; | 
|---|
| [db0b3ce] | 100 | } | 
|---|
|  | 101 |  | 
|---|
| [b8a4f47] | 102 | Type * ScrubTyVars::postmutate( PointerType * pointer ) { | 
|---|
|  | 103 | if ( dynType ) { | 
|---|
|  | 104 | Type * ret = dynType->acceptMutator( *visitor ); | 
|---|
| [6f95000] | 105 | ret->get_qualifiers() |= pointer->get_qualifiers(); | 
|---|
| [b8a4f47] | 106 | pointer->base = nullptr; | 
|---|
| [6d160d7] | 107 | delete pointer; | 
|---|
|  | 108 | return ret; | 
|---|
|  | 109 | } | 
|---|
| [b8a4f47] | 110 | return pointer; | 
|---|
| [a08ba92] | 111 | } | 
|---|
| [51b73452] | 112 | } // namespace GenPoly | 
|---|
| [01aeade] | 113 |  | 
|---|
| [51587aa] | 114 | // Local Variables: // | 
|---|
|  | 115 | // tab-width: 4 // | 
|---|
|  | 116 | // mode: c++ // | 
|---|
|  | 117 | // compile-command: "make install" // | 
|---|
|  | 118 | // End: // | 
|---|