source: src/ResolvExpr/AdjustExprType.cc @ 834d4fc

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 834d4fc was 834d4fc, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

recursively convert array expression types to pointers so that multi-dimensional arrays work

  • Property mode set to 100644
File size: 3.8 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
40                const TypeEnvironment &env;
41                const SymTab::Indexer &indexer;
42        };
43
44        void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
45                AdjustExprType adjuster( env, indexer );
46                Type *newType = type->acceptMutator( adjuster );
47                type = newType;
48        }
49
50        AdjustExprType::AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer )
51                : env( env ), indexer( indexer ) {
52        }
53
54        Type *AdjustExprType::mutate( VoidType *voidType ) {
55                return voidType;
56        }
57
58        Type *AdjustExprType::mutate( BasicType *basicType ) {
59                return basicType;
60        }
61
62        Type *AdjustExprType::mutate( PointerType *pointerType ) {
63                return pointerType;
64        }
65
66        Type *AdjustExprType::mutate( ArrayType *arrayType ) {
67                // need to recursively mutate the base type in order for multi-dimensional arrays to work.
68                PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ) );
69                delete arrayType;
70                return pointerType;
71        }
72
73        Type *AdjustExprType::mutate( FunctionType *functionType ) {
74                PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType );
75                return pointerType;
76        }
77
78        Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) {
79                return aggregateUseType;
80        }
81
82        Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) {
83                return aggregateUseType;
84        }
85
86        Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) {
87                return aggregateUseType;
88        }
89
90        Type *AdjustExprType::mutate( TraitInstType *aggregateUseType ) {
91                return aggregateUseType;
92        }
93
94        Type *AdjustExprType::mutate( TypeInstType *typeInst ) {
95                EqvClass eqvClass;
96                if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
97                        if ( eqvClass.kind == TypeDecl::Ftype ) {
98                                PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
99                                return pointerType;
100                        }
101                } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
102                        if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
103                                if ( tyDecl->get_kind() == TypeDecl::Ftype ) {
104                                        PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
105                                        return pointerType;
106                                } // if
107                        } // if
108                } // if
109                return typeInst;
110        }
111
112        Type *AdjustExprType::mutate( TupleType *tupleType ) {
113                return tupleType;
114        }
115
116        Type *AdjustExprType::mutate( VarArgsType *varArgsType ) {
117                return varArgsType;
118        }
119} // namespace ResolvExpr
120
121// Local Variables: //
122// tab-width: 4 //
123// mode: c++ //
124// compile-command: "make install" //
125// End: //
Note: See TracBrowser for help on using the repository browser.