source: src/GenPoly/ScrubTyVars.cc @ 32805db

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 32805db was ebe9b3a, checked in by Aaron Moss <a3moss@…>, 8 years ago

Stripped unused and potentially buggy 'doAll' flag from ScrubTyVars?

  • Property mode set to 100644
File size: 2.8 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 : Tue May 19 16:42:42 2015
13// Update Count     : 2
14//
15
16#include <sstream>
17#include <string>
18
19#include "GenPoly.h"
20#include "ScrubTyVars.h"
21
22#include "SynTree/Mutator.h"
23#include "SynTree/Type.h"
24#include "SynTree/Expression.h"
25
26namespace GenPoly {
27        Type * ScrubTyVars::mutate( TypeInstType *typeInst ) {
28                TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() );
29                if ( tyVar != tyVars.end() ) {
30                        switch ( tyVar->second ) {
31                          case TypeDecl::Any:
32                          case TypeDecl::Dtype:
33                                {
34                                        PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );
35                                        delete typeInst;
36                                        return ret;
37                                }
38                          case TypeDecl::Ftype:
39                                delete typeInst;
40                                return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
41                        } // switch
42                } // if
43                return typeInst;
44        }
45
46        Type * ScrubTyVars::mutateAggregateType( Type *ty ) {
47                if ( isPolyType( ty, tyVars ) ) {
48                        PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) );
49                        delete ty;
50                        return ret;
51                }
52                return ty;
53        }
54       
55        Type * ScrubTyVars::mutate( StructInstType *structInst ) {
56                return mutateAggregateType( structInst );
57        }
58
59        Type * ScrubTyVars::mutate( UnionInstType *unionInst ) {
60                return mutateAggregateType( unionInst );
61        }
62
63        Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
64                // sizeof( T ) => _sizeof_T parameter, which is the size of T
65                if ( Type *polyType = isPolyType( szeof->get_type() ) ) {
66                        Expression *expr = new NameExpr( sizeofName( polyType ) );
67                        return expr;
68                } else {
69                        return Mutator::mutate( szeof );
70                } // if
71        }
72
73        Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) {
74                // alignof( T ) => _alignof_T parameter, which is the alignment of T
75                if ( Type *polyType = isPolyType( algnof->get_type() ) ) {
76                        Expression *expr = new NameExpr( alignofName( polyType ) );
77                        return expr;
78                } else {
79                        return Mutator::mutate( algnof );
80                } // if
81        }
82
83        Type * ScrubTyVars::mutate( PointerType *pointer ) {
84                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) {
85                        if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
86                                Type *ret = mutate( typeInst );
87                                ret->get_qualifiers() += pointer->get_qualifiers();
88                                pointer->set_base( 0 );
89                                delete pointer;
90                                return ret;
91                        } // if
92                } // if
93                return Mutator::mutate( pointer );
94        }
95} // namespace GenPoly
96
97// Local Variables: //
98// tab-width: 4 //
99// mode: c++ //
100// compile-command: "make install" //
101// End: //
Note: See TracBrowser for help on using the repository browser.