source: src/GenPoly/ScrubTyVars.cc @ 8f60f0b

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 8f60f0b was 8f60f0b, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

add support for ttype in the parser

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