source: src/ResolvExpr/AdjustExprType.cc@ 141b786

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox 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 141b786 was 89e6ffc, checked in by Aaron Moss <a3moss@…>, 9 years ago

Added support for ZeroType and OneType to all relevant visitors

  • Property mode set to 100644
File size: 4.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// AdjustExprType.cc --
8//
9// Author : Richard C. Bilson
10// Created On : Sat May 16 23:41:42 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Mar 2 17:34:53 2016
13// Update Count : 4
14//
15
16#include "typeops.h"
17#include "SynTree/Type.h"
18#include "TypeEnvironment.h"
19#include "SymTab/Indexer.h"
20
21namespace ResolvExpr {
22 class AdjustExprType : public Mutator {
23 typedef Mutator Parent;
24 public:
25 AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer );
26 private:
27 virtual Type* mutate( VoidType *voidType );
28 virtual Type* mutate( BasicType *basicType );
29 virtual Type* mutate( PointerType *pointerType );
30 virtual Type* mutate( ArrayType *arrayType );
31 virtual Type* mutate( FunctionType *functionType );
32 virtual Type* mutate( StructInstType *aggregateUseType );
33 virtual Type* mutate( UnionInstType *aggregateUseType );
34 virtual Type* mutate( EnumInstType *aggregateUseType );
35 virtual Type* mutate( TraitInstType *aggregateUseType );
36 virtual Type* mutate( TypeInstType *aggregateUseType );
37 virtual Type* mutate( TupleType *tupleType );
38 virtual Type* mutate( VarArgsType *varArgsType );
39 virtual Type* mutate( ZeroType *zeroType );
40 virtual Type* mutate( OneType *oneType );
41
42 const TypeEnvironment &env;
43 const SymTab::Indexer &indexer;
44 };
45
46 void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
47 AdjustExprType adjuster( env, indexer );
48 Type *newType = type->acceptMutator( adjuster );
49 type = newType;
50 }
51
52 AdjustExprType::AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer )
53 : env( env ), indexer( indexer ) {
54 }
55
56 Type *AdjustExprType::mutate( VoidType *voidType ) {
57 return voidType;
58 }
59
60 Type *AdjustExprType::mutate( BasicType *basicType ) {
61 return basicType;
62 }
63
64 Type *AdjustExprType::mutate( PointerType *pointerType ) {
65 return pointerType;
66 }
67
68 Type *AdjustExprType::mutate( ArrayType *arrayType ) {
69 // need to recursively mutate the base type in order for multi-dimensional arrays to work.
70 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ) );
71 delete arrayType;
72 return pointerType;
73 }
74
75 Type *AdjustExprType::mutate( FunctionType *functionType ) {
76 PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType );
77 return pointerType;
78 }
79
80 Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) {
81 return aggregateUseType;
82 }
83
84 Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) {
85 return aggregateUseType;
86 }
87
88 Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) {
89 return aggregateUseType;
90 }
91
92 Type *AdjustExprType::mutate( TraitInstType *aggregateUseType ) {
93 return aggregateUseType;
94 }
95
96 Type *AdjustExprType::mutate( TypeInstType *typeInst ) {
97 EqvClass eqvClass;
98 if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
99 if ( eqvClass.kind == TypeDecl::Ftype ) {
100 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
101 return pointerType;
102 }
103 } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
104 if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
105 if ( tyDecl->get_kind() == TypeDecl::Ftype ) {
106 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
107 return pointerType;
108 } // if
109 } // if
110 } // if
111 return typeInst;
112 }
113
114 Type *AdjustExprType::mutate( TupleType *tupleType ) {
115 return tupleType;
116 }
117
118 Type *AdjustExprType::mutate( VarArgsType *varArgsType ) {
119 return varArgsType;
120 }
121
122 Type *AdjustExprType::mutate( ZeroType *zeroType ) {
123 return zeroType;
124 }
125
126 Type *AdjustExprType::mutate( OneType *oneType ) {
127 return oneType;
128 }
129} // namespace ResolvExpr
130
131// Local Variables: //
132// tab-width: 4 //
133// mode: c++ //
134// compile-command: "make install" //
135// End: //
Note: See TracBrowser for help on using the repository browser.