source: src/GenPoly/ScrubTyVars.cc@ 1b54b54

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since 1b54b54 was d978ada, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Fix unhandled enum warning in ScrubTyVars

  • Property mode set to 100644
File size: 3.6 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 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->name );
40 if ( tyVar != tyVars->end() ) {
41 switch ( tyVar->second.kind ) {
42 case TypeDecl::Dtype:
43 case TypeDecl::Ttype:
44 {
45 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );
46 delete typeInst;
47 return ret;
48 }
49 case TypeDecl::Ftype:
50 delete typeInst;
51 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
52 default:
53 assertf(false, "Unhandled tyvar kind: %d", tyVar->second.kind);
54 } // switch
55 } // if
56 return typeInst;
57 }
58
59 Type * ScrubTyVars::mutateAggregateType( Type * ty ) {
60 if ( shouldScrub( ty ) ) {
61 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) );
62 delete ty;
63 return ret;
64 }
65 return ty;
66 }
67
68 Type * ScrubTyVars::postmutate( StructInstType * structInst ) {
69 return mutateAggregateType( structInst );
70 }
71
72 Type * ScrubTyVars::postmutate( UnionInstType * unionInst ) {
73 return mutateAggregateType( unionInst );
74 }
75
76 void ScrubTyVars::primeBaseScrub( Type * type ) {
77 // need to determine whether type needs to be scrubbed to determine whether
78 // automatic recursion is necessary
79 if ( Type * t = shouldScrub( type ) ) {
80 visit_children = false;
81 GuardValue( dynType );
82 dynType = t;
83 }
84 }
85
86 Expression * ScrubTyVars::postmutate( SizeofExpr * szeof ) {
87 // sizeof( T ) => _sizeof_T parameter, which is the size of T
88 if ( dynType ) {
89 Expression *expr = new NameExpr( sizeofName( mangleType( dynType ) ) );
90 return expr;
91 } // if
92 return szeof;
93 }
94
95 Expression * ScrubTyVars::postmutate( AlignofExpr * algnof ) {
96 // alignof( T ) => _alignof_T parameter, which is the alignment of T
97 if ( dynType ) {
98 Expression *expr = new NameExpr( alignofName( mangleType( dynType ) ) );
99 return expr;
100 } // if
101 return algnof;
102 }
103
104 Type * ScrubTyVars::postmutate( PointerType * pointer ) {
105 if ( dynType ) {
106 Type * ret = dynType->acceptMutator( *visitor );
107 ret->get_qualifiers() |= pointer->get_qualifiers();
108 pointer->base = nullptr;
109 delete pointer;
110 return ret;
111 }
112 return pointer;
113 }
114} // namespace GenPoly
115
116// Local Variables: //
117// tab-width: 4 //
118// mode: c++ //
119// compile-command: "make install" //
120// End: //
Note: See TracBrowser for help on using the repository browser.