source: src/GenPoly/ScrubTyVars.cc@ 1f370451

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 1f370451 was f0ecf9b, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Remove TypeDecl::Any, as it is subsumed by Dtype+sized

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