source: translator/GenPoly/ScrubTyVars.cc @ 51587aa

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 51587aa was 51587aa, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

licencing: fourth groups of files

  • Property mode set to 100644
File size: 2.0 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// XXX.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By :
12// Last Modified On :
13// Update Count     : 0
14//
15#include "GenPoly.h"
16#include "ScrubTyVars.h"
17
18#include "SynTree/Mutator.h"
19#include "SynTree/Type.h"
20#include "SynTree/Expression.h"
21
22
23namespace GenPoly {
24    Type * ScrubTyVars::mutate( TypeInstType *typeInst ) {
25        TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() );
26        if ( doAll || tyVar != tyVars.end() ) {
27            switch ( tyVar->second ) {
28              case TypeDecl::Any:
29              case TypeDecl::Dtype:
30                {
31                    PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );
32                    delete typeInst;
33                    return ret;
34                }
35              case TypeDecl::Ftype:
36                delete typeInst;
37                return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
38            }
39        }
40        return typeInst;
41    }
42
43    Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
44        // sizeof( T ) => T parameter, which is the size of T
45        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) {
46            Expression *expr = new NameExpr( typeInst->get_name() );
47            return expr;
48        } else {
49            return Mutator::mutate( szeof );
50        }
51    }
52
53    Type * ScrubTyVars::mutate( PointerType *pointer ) {
54        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) {
55            if ( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
56                Type *ret = mutate( typeInst );
57                ret->get_qualifiers() += pointer->get_qualifiers();
58                pointer->set_base( 0 );
59                delete pointer;
60                return ret;
61            }
62        }
63        return Mutator::mutate( pointer );
64    }
65} // namespace GenPoly
66// Local Variables: //
67// tab-width: 4 //
68// mode: c++ //
69// compile-command: "make install" //
70// End: //
Note: See TracBrowser for help on using the repository browser.