source: src/GenPoly/ScrubTyVars.cc @ cdc4d43

new-envwith_gc
Last change on this file since cdc4d43 was 68f9c43, checked in by Aaron Moss <a3moss@…>, 6 years ago

First pass at delete removal

  • Property mode set to 100644
File size: 3.3 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...
[51b7345]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
[51b7345]25
26namespace GenPoly {
[b8a4f47]27        Type * ScrubTyVars::postmutate( TypeInstType * typeInst ) {
[5a3ac84]28                if ( ! tyVars ) {
29                        if ( typeInst->get_isFtype() ) {
[68f9c43]30                                return new PointerType{ Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) };
[5a3ac84]31                        } else {
[68f9c43]32                                return new PointerType{ Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) };
[5a3ac84]33                        }
34                }
35
[b8a4f47]36                TyVarMap::const_iterator tyVar = tyVars->find( typeInst->name );
[5a3ac84]37                if ( tyVar != tyVars->end() ) {
[2c57025]38                        switch ( tyVar->second.kind ) {
[01aeade]39                          case TypeDecl::Dtype:
[8f60f0b]40                          case TypeDecl::Ttype:
[68f9c43]41                                return new PointerType{ Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) };
[01aeade]42                          case TypeDecl::Ftype:
[68f9c43]43                                return new PointerType{ Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) };
[01aeade]44                        } // switch
45                } // if
46                return typeInst;
[a08ba92]47        }
[51b7345]48
[b8a4f47]49        Type * ScrubTyVars::mutateAggregateType( Type * ty ) {
[3bb195cb]50                if ( shouldScrub( ty ) ) {
[68f9c43]51                        return new PointerType{ Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) };
[b18b0b5]52                }
53                return ty;
54        }
[2c57025]55
[b8a4f47]56        Type * ScrubTyVars::postmutate( StructInstType * structInst ) {
[b18b0b5]57                return mutateAggregateType( structInst );
58        }
59
[b8a4f47]60        Type * ScrubTyVars::postmutate( UnionInstType * unionInst ) {
[b18b0b5]61                return mutateAggregateType( unionInst );
62        }
63
[b8a4f47]64        void ScrubTyVars::primeBaseScrub( Type * type ) {
65                // need to determine whether type needs to be scrubbed to determine whether
66                // automatic recursion is necessary
67                if ( Type * t = shouldScrub( type ) ) {
68                        visit_children = false;
69                        GuardValue( dynType );
70                        dynType = t;
71                }
72        }
73
74        Expression * ScrubTyVars::postmutate( SizeofExpr * szeof ) {
[db0b3ce]75                // sizeof( T ) => _sizeof_T parameter, which is the size of T
[b8a4f47]76                if ( dynType ) {
[3bb195cb]77                        Expression *expr = new NameExpr( sizeofName( mangleType( dynType ) ) );
[01aeade]78                        return expr;
79                } // if
[b8a4f47]80                return szeof;
[a08ba92]81        }
[51b7345]82
[b8a4f47]83        Expression * ScrubTyVars::postmutate( AlignofExpr * algnof ) {
[db0b3ce]84                // alignof( T ) => _alignof_T parameter, which is the alignment of T
[b8a4f47]85                if ( dynType ) {
[3bb195cb]86                        Expression *expr = new NameExpr( alignofName( mangleType( dynType ) ) );
[db0b3ce]87                        return expr;
88                } // if
[b8a4f47]89                return algnof;
[db0b3ce]90        }
91
[b8a4f47]92        Type * ScrubTyVars::postmutate( PointerType * pointer ) {
93                if ( dynType ) {
94                        Type * ret = dynType->acceptMutator( *visitor );
[6f95000]95                        ret->get_qualifiers() |= pointer->get_qualifiers();
[6d160d7]96                        return ret;
97                }
[b8a4f47]98                return pointer;
[a08ba92]99        }
[51b7345]100} // namespace GenPoly
[01aeade]101
[51587aa]102// Local Variables: //
103// tab-width: 4 //
104// mode: c++ //
105// compile-command: "make install" //
106// End: //
Note: See TracBrowser for help on using the repository browser.