source: src/GenPoly/ScrubTyVars.cc @ 68f9c43

new-envwith_gc
Last change on this file since 68f9c43 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
Line 
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//
7// ScrubTyVars.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Mar 16 15:44:27 2017
13// Update Count     : 3
14//
15
16#include <utility>                      // for pair
17
18#include "GenPoly.h"                    // for mangleType, TyVarMap, alignof...
19#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::const_it...
20#include "ScrubTyVars.h"
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
25
26namespace GenPoly {
27        Type * ScrubTyVars::postmutate( TypeInstType * typeInst ) {
28                if ( ! tyVars ) {
29                        if ( typeInst->get_isFtype() ) {
30                                return new PointerType{ Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) };
31                        } else {
32                                return new PointerType{ Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) };
33                        }
34                }
35
36                TyVarMap::const_iterator tyVar = tyVars->find( typeInst->name );
37                if ( tyVar != tyVars->end() ) {
38                        switch ( tyVar->second.kind ) {
39                          case TypeDecl::Dtype:
40                          case TypeDecl::Ttype:
41                                return new PointerType{ Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) };
42                          case TypeDecl::Ftype:
43                                return new PointerType{ Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) };
44                        } // switch
45                } // if
46                return typeInst;
47        }
48
49        Type * ScrubTyVars::mutateAggregateType( Type * ty ) {
50                if ( shouldScrub( ty ) ) {
51                        return new PointerType{ Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) };
52                }
53                return ty;
54        }
55
56        Type * ScrubTyVars::postmutate( StructInstType * structInst ) {
57                return mutateAggregateType( structInst );
58        }
59
60        Type * ScrubTyVars::postmutate( UnionInstType * unionInst ) {
61                return mutateAggregateType( unionInst );
62        }
63
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 ) {
75                // sizeof( T ) => _sizeof_T parameter, which is the size of T
76                if ( dynType ) {
77                        Expression *expr = new NameExpr( sizeofName( mangleType( dynType ) ) );
78                        return expr;
79                } // if
80                return szeof;
81        }
82
83        Expression * ScrubTyVars::postmutate( AlignofExpr * algnof ) {
84                // alignof( T ) => _alignof_T parameter, which is the alignment of T
85                if ( dynType ) {
86                        Expression *expr = new NameExpr( alignofName( mangleType( dynType ) ) );
87                        return expr;
88                } // if
89                return algnof;
90        }
91
92        Type * ScrubTyVars::postmutate( PointerType * pointer ) {
93                if ( dynType ) {
94                        Type * ret = dynType->acceptMutator( *visitor );
95                        ret->get_qualifiers() |= pointer->get_qualifiers();
96                        return ret;
97                }
98                return pointer;
99        }
100} // namespace GenPoly
101
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.