| 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 |
|
|---|
| 13 | namespace ResolvExpr {
|
|---|
| 14 |
|
|---|
| 15 | class AdjustExprType : public Mutator
|
|---|
| 16 | {
|
|---|
| 17 | typedef Mutator Parent;
|
|---|
| 18 |
|
|---|
| 19 | public:
|
|---|
| 20 | AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer );
|
|---|
| 21 |
|
|---|
| 22 | private:
|
|---|
| 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 |
|
|---|
| 39 | void
|
|---|
| 40 | adjustExprType( 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 |
|
|---|
| 47 | AdjustExprType::AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer )
|
|---|
| 48 | : env( env ), indexer( indexer )
|
|---|
| 49 | {
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | Type*
|
|---|
| 53 | AdjustExprType::mutate(VoidType *voidType)
|
|---|
| 54 | {
|
|---|
| 55 | return voidType;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | Type*
|
|---|
| 59 | AdjustExprType::mutate(BasicType *basicType)
|
|---|
| 60 | {
|
|---|
| 61 | return basicType;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | Type*
|
|---|
| 65 | AdjustExprType::mutate(PointerType *pointerType)
|
|---|
| 66 | {
|
|---|
| 67 | return pointerType;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | Type*
|
|---|
| 71 | AdjustExprType::mutate(ArrayType *arrayType)
|
|---|
| 72 | {
|
|---|
| 73 | PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone() );
|
|---|
| 74 | delete arrayType;
|
|---|
| 75 | return pointerType;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | Type*
|
|---|
| 79 | AdjustExprType::mutate(FunctionType *functionType)
|
|---|
| 80 | {
|
|---|
| 81 | PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType );
|
|---|
| 82 | return pointerType;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | Type*
|
|---|
| 86 | AdjustExprType::mutate(StructInstType *aggregateUseType)
|
|---|
| 87 | {
|
|---|
| 88 | return aggregateUseType;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | Type*
|
|---|
| 92 | AdjustExprType::mutate(UnionInstType *aggregateUseType)
|
|---|
| 93 | {
|
|---|
| 94 | return aggregateUseType;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | Type*
|
|---|
| 98 | AdjustExprType::mutate(EnumInstType *aggregateUseType)
|
|---|
| 99 | {
|
|---|
| 100 | return aggregateUseType;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | Type*
|
|---|
| 104 | AdjustExprType::mutate(ContextInstType *aggregateUseType)
|
|---|
| 105 | {
|
|---|
| 106 | return aggregateUseType;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | Type*
|
|---|
| 110 | AdjustExprType::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 |
|
|---|
| 129 | Type*
|
|---|
| 130 | AdjustExprType::mutate(TupleType *tupleType)
|
|---|
| 131 | {
|
|---|
| 132 | return tupleType;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | } // namespace ResolvExpr
|
|---|