[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 | // |
---|
[62423350] | 7 | // ImplementationType.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 21:32:01 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[6f95000] | 12 | // Last Modified On : Thu Mar 16 15:54:08 2017 |
---|
| 13 | // Update Count : 4 |
---|
[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); |
---|
[89e6ffc] | 43 | virtual void visit(ZeroType *zeroType); |
---|
| 44 | virtual void visit(OneType *oneType); |
---|
[0dd3a2f] | 45 | |
---|
| 46 | Type *result; // synthesized |
---|
| 47 | const SymTab::Indexer &indexer; |
---|
| 48 | }; |
---|
| 49 | |
---|
| 50 | Type * implementationType( Type *type, const SymTab::Indexer& indexer ) { |
---|
| 51 | ImplementationType implementor( indexer ); |
---|
| 52 | type->accept( implementor ); |
---|
| 53 | if ( implementor.get_result() == 0 ) { |
---|
| 54 | return type->clone(); |
---|
| 55 | } else { |
---|
| 56 | return implementor.get_result(); |
---|
| 57 | } // if |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | ImplementationType::ImplementationType( const SymTab::Indexer &indexer ) : result( 0 ), indexer( indexer ) { |
---|
| 61 | } |
---|
| 62 | |
---|
[7e003011] | 63 | void ImplementationType::visit( __attribute__((unused)) VoidType *voidType ) {} |
---|
| 64 | void ImplementationType::visit( __attribute__((unused)) BasicType *basicType ) {} |
---|
[0dd3a2f] | 65 | |
---|
| 66 | void ImplementationType::visit(PointerType *pointerType) { |
---|
| 67 | PointerType *newType = pointerType->clone(); |
---|
| 68 | newType->set_base( implementationType( pointerType->get_base(), indexer ) ); |
---|
| 69 | result = newType; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | void ImplementationType::visit(ArrayType *arrayType) { |
---|
| 73 | ArrayType *newType = arrayType->clone(); |
---|
| 74 | newType->set_base( implementationType( arrayType->get_base(), indexer ) ); |
---|
| 75 | result = newType; |
---|
| 76 | } |
---|
| 77 | |
---|
[af397ef8] | 78 | void ImplementationType::visit( __attribute__((unused)) FunctionType *functionType ) {} |
---|
[7e003011] | 79 | void ImplementationType::visit( __attribute__((unused)) StructInstType * aggregateUseType ) {} |
---|
| 80 | void ImplementationType::visit( __attribute__((unused)) UnionInstType * aggregateUseType ) {} |
---|
| 81 | void ImplementationType::visit( __attribute__((unused)) EnumInstType * aggregateUseType ) {} |
---|
| 82 | void ImplementationType::visit( __attribute__((unused)) TraitInstType * aggregateUseType ) {} |
---|
[0dd3a2f] | 83 | |
---|
| 84 | void ImplementationType::visit(TypeInstType *inst) { |
---|
| 85 | NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() ); |
---|
| 86 | if ( typeDecl && typeDecl->get_base() ) { |
---|
| 87 | Type *base = implementationType( typeDecl->get_base(), indexer ); |
---|
[6f95000] | 88 | base->get_qualifiers() |= inst->get_qualifiers(); |
---|
[0dd3a2f] | 89 | result = base; |
---|
| 90 | } // if |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void ImplementationType::visit(TupleType *tupleType) { |
---|
[62423350] | 94 | std::list< Type * > types; |
---|
[0dd3a2f] | 95 | for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) { |
---|
| 96 | Type *implType = implementationType( *i, indexer ); |
---|
[6f95000] | 97 | implType->get_qualifiers() |= tupleType->get_qualifiers(); |
---|
[62423350] | 98 | types.push_back( implType ); |
---|
[0dd3a2f] | 99 | } // for |
---|
[62423350] | 100 | result = new TupleType( Type::Qualifiers(), types ); |
---|
[0dd3a2f] | 101 | } |
---|
[44b7088] | 102 | |
---|
[7e003011] | 103 | void ImplementationType::visit( __attribute__((unused)) VarArgsType *varArgsType ) {} |
---|
| 104 | void ImplementationType::visit( __attribute__((unused)) ZeroType *zeroType ) {} |
---|
| 105 | void ImplementationType::visit( __attribute__((unused)) OneType *oneType ) {} |
---|
[51b7345] | 106 | } // namespace SymTab |
---|
[0dd3a2f] | 107 | |
---|
| 108 | // Local Variables: // |
---|
| 109 | // tab-width: 4 // |
---|
| 110 | // mode: c++ // |
---|
| 111 | // compile-command: "make install" // |
---|
| 112 | // End: // |
---|