[51b7345] | 1 | /* |
---|
| 2 | * This file is part of the Cforall project |
---|
| 3 | * |
---|
| 4 | * $Id: ImplementationType.cc,v 1.4 2005/08/29 20:14:17 rcbilson Exp $ |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "ImplementationType.h" |
---|
| 9 | #include "SynTree/Type.h" |
---|
| 10 | #include "SynTree/Declaration.h" |
---|
| 11 | #include "SynTree/Visitor.h" |
---|
| 12 | #include "SymTab/Indexer.h" |
---|
| 13 | #include "utility.h" |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | namespace SymTab { |
---|
| 17 | |
---|
| 18 | class ImplementationType : public Visitor |
---|
| 19 | { |
---|
| 20 | public: |
---|
| 21 | ImplementationType( const SymTab::Indexer &indexer ); |
---|
| 22 | |
---|
| 23 | Type *get_result() { return result; } |
---|
| 24 | |
---|
| 25 | private: |
---|
| 26 | virtual void visit(VoidType *voidType); |
---|
| 27 | virtual void visit(BasicType *basicType); |
---|
| 28 | virtual void visit(PointerType *pointerType); |
---|
| 29 | virtual void visit(ArrayType *arrayType); |
---|
| 30 | virtual void visit(FunctionType *functionType); |
---|
| 31 | virtual void visit(StructInstType *aggregateUseType); |
---|
| 32 | virtual void visit(UnionInstType *aggregateUseType); |
---|
| 33 | virtual void visit(EnumInstType *aggregateUseType); |
---|
| 34 | virtual void visit(ContextInstType *aggregateUseType); |
---|
| 35 | virtual void visit(TypeInstType *aggregateUseType); |
---|
| 36 | virtual void visit(TupleType *tupleType); |
---|
| 37 | |
---|
| 38 | Type *result; // synthesized |
---|
| 39 | const SymTab::Indexer &indexer; |
---|
| 40 | }; |
---|
| 41 | |
---|
| 42 | Type* |
---|
| 43 | implementationType( Type *type, const SymTab::Indexer& indexer ) |
---|
| 44 | { |
---|
| 45 | ImplementationType implementor( indexer ); |
---|
| 46 | type->accept( implementor ); |
---|
| 47 | if( implementor.get_result() == 0 ) { |
---|
| 48 | return type->clone(); |
---|
| 49 | } else { |
---|
| 50 | return implementor.get_result(); |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | ImplementationType::ImplementationType( const SymTab::Indexer &indexer ) |
---|
| 55 | : result( 0 ), indexer( indexer ) |
---|
| 56 | { |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void |
---|
| 60 | ImplementationType::visit(VoidType *voidType) |
---|
| 61 | { |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void |
---|
| 65 | ImplementationType::visit(BasicType *basicType) |
---|
| 66 | { |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | void |
---|
| 70 | ImplementationType::visit(PointerType *pointerType) |
---|
| 71 | { |
---|
| 72 | PointerType *newType = pointerType->clone(); |
---|
| 73 | newType->set_base( implementationType( pointerType->get_base(), indexer ) ); |
---|
| 74 | result = newType; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | void |
---|
| 78 | ImplementationType::visit(ArrayType *arrayType) |
---|
| 79 | { |
---|
| 80 | ArrayType *newType = arrayType->clone(); |
---|
| 81 | newType->set_base( implementationType( arrayType->get_base(), indexer ) ); |
---|
| 82 | result = newType; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | void |
---|
| 86 | ImplementationType::visit(FunctionType *functionType) |
---|
| 87 | { |
---|
| 88 | /// FunctionType *newType = functionType->clone(); |
---|
| 89 | /// for( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) { |
---|
| 90 | /// i->set_type( implementationType( i->get_type(), indexer ) ); |
---|
| 91 | /// } |
---|
| 92 | /// for( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) { |
---|
| 93 | /// i->set_type( implementationType( i->get_type(), indexer ) ); |
---|
| 94 | /// } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | void |
---|
| 98 | ImplementationType::visit(StructInstType *aggregateUseType) |
---|
| 99 | { |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void |
---|
| 103 | ImplementationType::visit(UnionInstType *aggregateUseType) |
---|
| 104 | { |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void |
---|
| 108 | ImplementationType::visit(EnumInstType *aggregateUseType) |
---|
| 109 | { |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | void |
---|
| 113 | ImplementationType::visit(ContextInstType *aggregateUseType) |
---|
| 114 | { |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void |
---|
| 118 | ImplementationType::visit(TypeInstType *inst) |
---|
| 119 | { |
---|
| 120 | NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() ); |
---|
| 121 | if( typeDecl && typeDecl->get_base() ) { |
---|
| 122 | Type *base = implementationType( typeDecl->get_base(), indexer ); |
---|
| 123 | base->get_qualifiers() += inst->get_qualifiers(); |
---|
| 124 | result = base; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void |
---|
| 129 | ImplementationType::visit(TupleType *tupleType) |
---|
| 130 | { |
---|
| 131 | TupleType *newType = new TupleType( Type::Qualifiers() ); |
---|
| 132 | for( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) { |
---|
| 133 | Type *implType = implementationType( *i, indexer ); |
---|
| 134 | implType->get_qualifiers() += tupleType->get_qualifiers(); |
---|
| 135 | newType->get_types().push_back( implType ); |
---|
| 136 | } |
---|
| 137 | result = newType; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | } // namespace SymTab |
---|