source: src/GenPoly/ScrubTyVars.cc@ 0f889a77

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 0f889a77 was ffad73a, checked in by Aaron Moss <a3moss@…>, 10 years ago

Refactored isPolyType and friends to account for polymorphic generic types

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[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
[78dd0da]16#include <sstream>
[db0b3ce]17#include <string>
18
[51b73452]19#include "GenPoly.h"
20#include "ScrubTyVars.h"
21
22#include "SynTree/Mutator.h"
23#include "SynTree/Type.h"
[bdd516a]24#include "SynTree/Expression.h"
[51b73452]25
26namespace GenPoly {
[a08ba92]27 Type * ScrubTyVars::mutate( TypeInstType *typeInst ) {
[01aeade]28 TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() );
29 if ( doAll || 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;
[a08ba92]44 }
[51b73452]45
[a08ba92]46 Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
[db0b3ce]47 // sizeof( T ) => _sizeof_T parameter, which is the size of T
[01aeade]48 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) {
[78dd0da]49 Expression *expr = new NameExpr( sizeofName( typeInst ) );
[01aeade]50 return expr;
51 } else {
52 return Mutator::mutate( szeof );
53 } // if
[a08ba92]54 }
[51b73452]55
[db0b3ce]56 Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) {
57 // alignof( T ) => _alignof_T parameter, which is the alignment of T
58 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( algnof->get_type() ) ) {
[78dd0da]59 Expression *expr = new NameExpr( alignofName( typeInst ) );
[db0b3ce]60 return expr;
61 } else {
62 return Mutator::mutate( algnof );
63 } // if
64 }
65
[a08ba92]66 Type * ScrubTyVars::mutate( PointerType *pointer ) {
[01aeade]67 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) {
68 if ( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
69 Type *ret = mutate( typeInst );
70 ret->get_qualifiers() += pointer->get_qualifiers();
71 pointer->set_base( 0 );
72 delete pointer;
73 return ret;
74 } // if
75 } // if
76 return Mutator::mutate( pointer );
[a08ba92]77 }
[51b73452]78} // namespace GenPoly
[01aeade]79
[51587aa]80// Local Variables: //
81// tab-width: 4 //
82// mode: c++ //
83// compile-command: "make install" //
84// End: //
Note: See TracBrowser for help on using the repository browser.