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 "SymTab/Mangler.h"
|
---|
23 |
|
---|
24 | #include "SynTree/Mutator.h"
|
---|
25 | #include "SynTree/Type.h"
|
---|
26 | #include "SynTree/Expression.h"
|
---|
27 |
|
---|
28 | namespace GenPoly {
|
---|
29 | Type * ScrubTyVars::mutate( TypeInstType *typeInst ) {
|
---|
30 | TyVarMap::const_iterator tyVar = tyVars.find( typeInst->get_name() );
|
---|
31 | if ( doAll || tyVar != tyVars.end() ) {
|
---|
32 | switch ( tyVar->second ) {
|
---|
33 | case TypeDecl::Any:
|
---|
34 | case TypeDecl::Dtype:
|
---|
35 | {
|
---|
36 | PointerType *ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) );
|
---|
37 | delete typeInst;
|
---|
38 | return ret;
|
---|
39 | }
|
---|
40 | case TypeDecl::Ftype:
|
---|
41 | delete typeInst;
|
---|
42 | return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) );
|
---|
43 | } // switch
|
---|
44 | } // if
|
---|
45 | return typeInst;
|
---|
46 | }
|
---|
47 |
|
---|
48 | Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
|
---|
49 | // sizeof( T ) => _sizeof_T parameter, which is the size of T
|
---|
50 | if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) {
|
---|
51 | Expression *expr = new NameExpr( sizeofName( typeInst ) );
|
---|
52 | return expr;
|
---|
53 | } else {
|
---|
54 | return Mutator::mutate( szeof );
|
---|
55 | } // if
|
---|
56 | }
|
---|
57 |
|
---|
58 | Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) {
|
---|
59 | // alignof( T ) => _alignof_T parameter, which is the alignment of T
|
---|
60 | if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( algnof->get_type() ) ) {
|
---|
61 | Expression *expr = new NameExpr( alignofName( typeInst ) );
|
---|
62 | return expr;
|
---|
63 | } else {
|
---|
64 | return Mutator::mutate( algnof );
|
---|
65 | } // if
|
---|
66 | }
|
---|
67 |
|
---|
68 | Type * ScrubTyVars::mutate( PointerType *pointer ) {
|
---|
69 | if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( pointer->get_base() ) ) {
|
---|
70 | if ( doAll || tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
|
---|
71 | Type *ret = mutate( typeInst );
|
---|
72 | ret->get_qualifiers() += pointer->get_qualifiers();
|
---|
73 | pointer->set_base( 0 );
|
---|
74 | delete pointer;
|
---|
75 | return ret;
|
---|
76 | } // if
|
---|
77 | } // if
|
---|
78 | return Mutator::mutate( pointer );
|
---|
79 | }
|
---|
80 |
|
---|
81 | std::string sizeofName( Type *ty ) {
|
---|
82 | return std::string( "_sizeof_" ) + SymTab::Mangler::mangle( ty, false, false );
|
---|
83 | }
|
---|
84 |
|
---|
85 | std::string alignofName( Type *ty ) {
|
---|
86 | return std::string( "_alignof_" ) + SymTab::Mangler::mangle( ty, false, false );
|
---|
87 | }
|
---|
88 | } // namespace GenPoly
|
---|
89 |
|
---|
90 | // Local Variables: //
|
---|
91 | // tab-width: 4 //
|
---|
92 | // mode: c++ //
|
---|
93 | // compile-command: "make install" //
|
---|
94 | // End: //
|
---|