source: src/GenPoly/ScrubTyVars.cc @ 5a3ac84

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 5a3ac84 was 5a3ac84, checked in by Aaron Moss <a3moss@…>, 7 years ago

Fixed Box(T*) generic instantiation bug

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