[51587aa] | 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 | //
|
---|
[01aeade] | 7 | // ScrubTyVars.cc --
|
---|
[51587aa] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
---|
[01aeade] | 11 | // Last Modified By : Peter A. Buhr
|
---|
[a08ba92] | 12 | // Last Modified On : Tue May 19 16:42:42 2015
|
---|
| 13 | // Update Count : 2
|
---|
[51587aa] | 14 | //
|
---|
[01aeade] | 15 |
|
---|
[51b73452] | 16 | #include "GenPoly.h"
|
---|
| 17 | #include "ScrubTyVars.h"
|
---|
| 18 |
|
---|
| 19 | #include "SynTree/Mutator.h"
|
---|
| 20 | #include "SynTree/Type.h"
|
---|
[bdd516a] | 21 | #include "SynTree/Expression.h"
|
---|
[51b73452] | 22 |
|
---|
| 23 | namespace GenPoly {
|
---|
[a08ba92] | 24 | Type * ScrubTyVars::mutate( TypeInstType *typeInst ) {
|
---|
[01aeade] | 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 | } // switch
|
---|
| 39 | } // if
|
---|
| 40 | return typeInst;
|
---|
[a08ba92] | 41 | }
|
---|
[51b73452] | 42 |
|
---|
[a08ba92] | 43 | Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
|
---|
[01aeade] | 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 | } // if
|
---|
[a08ba92] | 51 | }
|
---|
[51b73452] | 52 |
|
---|
[a08ba92] | 53 | Type * ScrubTyVars::mutate( PointerType *pointer ) {
|
---|
[01aeade] | 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 | } // if
|
---|
| 62 | } // if
|
---|
| 63 | return Mutator::mutate( pointer );
|
---|
[a08ba92] | 64 | }
|
---|
[51b73452] | 65 | } // namespace GenPoly
|
---|
[01aeade] | 66 |
|
---|
[51587aa] | 67 | // Local Variables: //
|
---|
| 68 | // tab-width: 4 //
|
---|
| 69 | // mode: c++ //
|
---|
| 70 | // compile-command: "make install" //
|
---|
| 71 | // End: //
|
---|