source: src/GenPoly/ScrubTyVars.cc@ 771b3c3

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 with_gc
Last change on this file since 771b3c3 was 7754cde, checked in by Aaron Moss <a3moss@…>, 10 years ago

First draft of passing generic size/align

  • Property mode set to 100644
File size: 2.4 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 ( 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;
44 }
45
46 Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
47 // sizeof( T ) => _sizeof_T parameter, which is the size of T
48 if ( Type *polyType = isPolyType( szeof->get_type() ) ) {
49 Expression *expr = new NameExpr( sizeofName( polyType ) );
50 return expr;
51 } else {
52 return Mutator::mutate( szeof );
53 } // if
54 }
55
56 Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) {
57 // alignof( T ) => _alignof_T parameter, which is the alignment of T
58 if ( Type *polyType = isPolyType( algnof->get_type() ) ) {
59 Expression *expr = new NameExpr( alignofName( polyType ) );
60 return expr;
61 } else {
62 return Mutator::mutate( algnof );
63 } // if
64 }
65
66 Type * ScrubTyVars::mutate( PointerType *pointer ) {
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 );
77 }
78} // namespace GenPoly
79
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.