source: translator/ResolvExpr/AdjustExprType.cc @ a0d9f94

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since a0d9f94 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: AdjustExprType.cc,v 1.3 2005/08/29 20:14:15 rcbilson Exp $
5 *
6 */
7
8#include "typeops.h"
9#include "SynTree/Type.h"
10#include "TypeEnvironment.h"
11#include "SymTab/Indexer.h"
12
13namespace ResolvExpr {
14
15class AdjustExprType : public Mutator
16{
17  typedef Mutator Parent;
18
19public:
20  AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer );
21
22private:
23  virtual Type* mutate(VoidType *voidType);
24  virtual Type* mutate(BasicType *basicType);
25  virtual Type* mutate(PointerType *pointerType);
26  virtual Type* mutate(ArrayType *arrayType);
27  virtual Type* mutate(FunctionType *functionType);
28  virtual Type* mutate(StructInstType *aggregateUseType);
29  virtual Type* mutate(UnionInstType *aggregateUseType);
30  virtual Type* mutate(EnumInstType *aggregateUseType);
31  virtual Type* mutate(ContextInstType *aggregateUseType);
32  virtual Type* mutate(TypeInstType *aggregateUseType);
33  virtual Type* mutate(TupleType *tupleType);
34 
35  const TypeEnvironment &env;
36  const SymTab::Indexer &indexer;
37};
38
39void
40adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer )
41{
42  AdjustExprType adjuster( env, indexer );
43  Type *newType = type->acceptMutator( adjuster );
44  type = newType;
45}
46
47AdjustExprType::AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer )
48  : env( env ), indexer( indexer )
49{
50}
51
52Type* 
53AdjustExprType::mutate(VoidType *voidType)
54{
55  return voidType;
56}
57
58Type* 
59AdjustExprType::mutate(BasicType *basicType)
60{
61  return basicType;
62}
63
64Type* 
65AdjustExprType::mutate(PointerType *pointerType)
66{
67  return pointerType;
68}
69
70Type* 
71AdjustExprType::mutate(ArrayType *arrayType)
72{
73  PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone() );
74  delete arrayType;
75  return pointerType;
76}
77
78Type* 
79AdjustExprType::mutate(FunctionType *functionType)
80{
81  PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType );
82  return pointerType;
83}
84
85Type* 
86AdjustExprType::mutate(StructInstType *aggregateUseType)
87{
88  return aggregateUseType;
89}
90
91Type* 
92AdjustExprType::mutate(UnionInstType *aggregateUseType)
93{
94  return aggregateUseType;
95}
96
97Type* 
98AdjustExprType::mutate(EnumInstType *aggregateUseType)
99{
100  return aggregateUseType;
101}
102
103Type* 
104AdjustExprType::mutate(ContextInstType *aggregateUseType)
105{
106  return aggregateUseType;
107}
108
109Type* 
110AdjustExprType::mutate(TypeInstType *typeInst)
111{
112  EqvClass eqvClass;
113  if( env.lookup( typeInst->get_name(), eqvClass ) ) {
114    if( eqvClass.kind == TypeDecl::Ftype ) {
115      PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
116      return pointerType;
117    }
118  } else if( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
119    if( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
120      if( tyDecl->get_kind() == TypeDecl::Ftype ) {
121        PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
122        return pointerType;
123      }
124    }
125  }
126  return typeInst;
127}
128
129Type* 
130AdjustExprType::mutate(TupleType *tupleType)
131{
132  return tupleType;
133}
134
135
136} // namespace ResolvExpr
Note: See TracBrowser for help on using the repository browser.