[0dd3a2f] | 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 | // ImplementationType.cc -- |
---|
| 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 21:32:01 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[4040425] | 12 | // Last Modified On : Wed Mar 2 17:31:20 2016 |
---|
| 13 | // Update Count : 3 |
---|
[0dd3a2f] | 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #include "ImplementationType.h" |
---|
| 17 | #include "SynTree/Type.h" |
---|
| 18 | #include "SynTree/Declaration.h" |
---|
| 19 | #include "SynTree/Visitor.h" |
---|
| 20 | #include "SymTab/Indexer.h" |
---|
[d3b7937] | 21 | #include "Common/utility.h" |
---|
[51b7345] | 22 | |
---|
| 23 | |
---|
| 24 | namespace SymTab { |
---|
[0dd3a2f] | 25 | class ImplementationType : public Visitor { |
---|
| 26 | public: |
---|
| 27 | ImplementationType( const SymTab::Indexer &indexer ); |
---|
| 28 | |
---|
| 29 | Type *get_result() { return result; } |
---|
| 30 | private: |
---|
| 31 | virtual void visit(VoidType *voidType); |
---|
| 32 | virtual void visit(BasicType *basicType); |
---|
| 33 | virtual void visit(PointerType *pointerType); |
---|
| 34 | virtual void visit(ArrayType *arrayType); |
---|
| 35 | virtual void visit(FunctionType *functionType); |
---|
| 36 | virtual void visit(StructInstType *aggregateUseType); |
---|
| 37 | virtual void visit(UnionInstType *aggregateUseType); |
---|
| 38 | virtual void visit(EnumInstType *aggregateUseType); |
---|
[4040425] | 39 | virtual void visit(TraitInstType *aggregateUseType); |
---|
[0dd3a2f] | 40 | virtual void visit(TypeInstType *aggregateUseType); |
---|
| 41 | virtual void visit(TupleType *tupleType); |
---|
[44b7088] | 42 | virtual void visit(VarArgsType *varArgsType); |
---|
[0dd3a2f] | 43 | |
---|
| 44 | Type *result; // synthesized |
---|
| 45 | const SymTab::Indexer &indexer; |
---|
| 46 | }; |
---|
| 47 | |
---|
| 48 | Type * implementationType( Type *type, const SymTab::Indexer& indexer ) { |
---|
| 49 | ImplementationType implementor( indexer ); |
---|
| 50 | type->accept( implementor ); |
---|
| 51 | if ( implementor.get_result() == 0 ) { |
---|
| 52 | return type->clone(); |
---|
| 53 | } else { |
---|
| 54 | return implementor.get_result(); |
---|
| 55 | } // if |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | ImplementationType::ImplementationType( const SymTab::Indexer &indexer ) : result( 0 ), indexer( indexer ) { |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void ImplementationType::visit(VoidType *voidType) { |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void ImplementationType::visit(BasicType *basicType) { |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | void ImplementationType::visit(PointerType *pointerType) { |
---|
| 68 | PointerType *newType = pointerType->clone(); |
---|
| 69 | newType->set_base( implementationType( pointerType->get_base(), indexer ) ); |
---|
| 70 | result = newType; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void ImplementationType::visit(ArrayType *arrayType) { |
---|
| 74 | ArrayType *newType = arrayType->clone(); |
---|
| 75 | newType->set_base( implementationType( arrayType->get_base(), indexer ) ); |
---|
| 76 | result = newType; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | void ImplementationType::visit(FunctionType *functionType) { |
---|
[51b7345] | 80 | /// FunctionType *newType = functionType->clone(); |
---|
[a32b204] | 81 | /// for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) { |
---|
[51b7345] | 82 | /// i->set_type( implementationType( i->get_type(), indexer ) ); |
---|
| 83 | /// } |
---|
[a32b204] | 84 | /// for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) { |
---|
[51b7345] | 85 | /// i->set_type( implementationType( i->get_type(), indexer ) ); |
---|
| 86 | /// } |
---|
[0dd3a2f] | 87 | } |
---|
| 88 | |
---|
| 89 | void ImplementationType::visit(StructInstType *aggregateUseType) { |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | void ImplementationType::visit(UnionInstType *aggregateUseType) { |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | void ImplementationType::visit(EnumInstType *aggregateUseType) { |
---|
| 96 | } |
---|
| 97 | |
---|
[4040425] | 98 | void ImplementationType::visit(TraitInstType *aggregateUseType) { |
---|
[0dd3a2f] | 99 | } |
---|
| 100 | |
---|
| 101 | void ImplementationType::visit(TypeInstType *inst) { |
---|
| 102 | NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() ); |
---|
| 103 | if ( typeDecl && typeDecl->get_base() ) { |
---|
| 104 | Type *base = implementationType( typeDecl->get_base(), indexer ); |
---|
| 105 | base->get_qualifiers() += inst->get_qualifiers(); |
---|
| 106 | result = base; |
---|
| 107 | } // if |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | void ImplementationType::visit(TupleType *tupleType) { |
---|
| 111 | TupleType *newType = new TupleType( Type::Qualifiers() ); |
---|
| 112 | for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) { |
---|
| 113 | Type *implType = implementationType( *i, indexer ); |
---|
| 114 | implType->get_qualifiers() += tupleType->get_qualifiers(); |
---|
| 115 | newType->get_types().push_back( implType ); |
---|
| 116 | } // for |
---|
| 117 | result = newType; |
---|
| 118 | } |
---|
[44b7088] | 119 | |
---|
| 120 | void ImplementationType::visit(VarArgsType *varArgsType) { |
---|
| 121 | } |
---|
[51b7345] | 122 | } // namespace SymTab |
---|
[0dd3a2f] | 123 | |
---|
| 124 | // Local Variables: // |
---|
| 125 | // tab-width: 4 // |
---|
| 126 | // mode: c++ // |
---|
| 127 | // compile-command: "make install" // |
---|
| 128 | // End: // |
---|