[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" |
---|
[30f9072] | 17 | |
---|
| 18 | #include <list> // for list, _List_iterator, list<>::iterator |
---|
| 19 | |
---|
| 20 | #include "SymTab/Indexer.h" // for Indexer |
---|
| 21 | #include "SynTree/Declaration.h" // for NamedTypeDecl |
---|
| 22 | #include "SynTree/Type.h" // for TupleType, Type, ArrayType, Pointer... |
---|
| 23 | #include "SynTree/Visitor.h" // for Visitor |
---|
[51b7345] | 24 | |
---|
| 25 | |
---|
| 26 | namespace SymTab { |
---|
[0dd3a2f] | 27 | class ImplementationType : public Visitor { |
---|
| 28 | public: |
---|
| 29 | ImplementationType( const SymTab::Indexer &indexer ); |
---|
| 30 | |
---|
| 31 | Type *get_result() { return result; } |
---|
| 32 | private: |
---|
| 33 | virtual void visit(VoidType *voidType); |
---|
| 34 | virtual void visit(BasicType *basicType); |
---|
| 35 | virtual void visit(PointerType *pointerType); |
---|
| 36 | virtual void visit(ArrayType *arrayType); |
---|
| 37 | virtual void visit(FunctionType *functionType); |
---|
| 38 | virtual void visit(StructInstType *aggregateUseType); |
---|
| 39 | virtual void visit(UnionInstType *aggregateUseType); |
---|
| 40 | virtual void visit(EnumInstType *aggregateUseType); |
---|
[4040425] | 41 | virtual void visit(TraitInstType *aggregateUseType); |
---|
[0dd3a2f] | 42 | virtual void visit(TypeInstType *aggregateUseType); |
---|
| 43 | virtual void visit(TupleType *tupleType); |
---|
[44b7088] | 44 | virtual void visit(VarArgsType *varArgsType); |
---|
[89e6ffc] | 45 | virtual void visit(ZeroType *zeroType); |
---|
| 46 | virtual void visit(OneType *oneType); |
---|
[0dd3a2f] | 47 | |
---|
| 48 | Type *result; // synthesized |
---|
| 49 | const SymTab::Indexer &indexer; |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | Type * implementationType( Type *type, const SymTab::Indexer& indexer ) { |
---|
| 53 | ImplementationType implementor( indexer ); |
---|
| 54 | type->accept( implementor ); |
---|
| 55 | if ( implementor.get_result() == 0 ) { |
---|
| 56 | return type->clone(); |
---|
| 57 | } else { |
---|
| 58 | return implementor.get_result(); |
---|
| 59 | } // if |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | ImplementationType::ImplementationType( const SymTab::Indexer &indexer ) : result( 0 ), indexer( indexer ) { |
---|
| 63 | } |
---|
| 64 | |
---|
[7e003011] | 65 | void ImplementationType::visit( __attribute__((unused)) VoidType *voidType ) {} |
---|
| 66 | void ImplementationType::visit( __attribute__((unused)) BasicType *basicType ) {} |
---|
[0dd3a2f] | 67 | |
---|
| 68 | void ImplementationType::visit(PointerType *pointerType) { |
---|
| 69 | PointerType *newType = pointerType->clone(); |
---|
| 70 | newType->set_base( implementationType( pointerType->get_base(), indexer ) ); |
---|
| 71 | result = newType; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | void ImplementationType::visit(ArrayType *arrayType) { |
---|
| 75 | ArrayType *newType = arrayType->clone(); |
---|
| 76 | newType->set_base( implementationType( arrayType->get_base(), indexer ) ); |
---|
| 77 | result = newType; |
---|
| 78 | } |
---|
| 79 | |
---|
[af397ef8] | 80 | void ImplementationType::visit( __attribute__((unused)) FunctionType *functionType ) {} |
---|
[7e003011] | 81 | void ImplementationType::visit( __attribute__((unused)) StructInstType * aggregateUseType ) {} |
---|
| 82 | void ImplementationType::visit( __attribute__((unused)) UnionInstType * aggregateUseType ) {} |
---|
| 83 | void ImplementationType::visit( __attribute__((unused)) EnumInstType * aggregateUseType ) {} |
---|
| 84 | void ImplementationType::visit( __attribute__((unused)) TraitInstType * aggregateUseType ) {} |
---|
[0dd3a2f] | 85 | |
---|
| 86 | void ImplementationType::visit(TypeInstType *inst) { |
---|
| 87 | NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() ); |
---|
| 88 | if ( typeDecl && typeDecl->get_base() ) { |
---|
| 89 | Type *base = implementationType( typeDecl->get_base(), indexer ); |
---|
[6f95000] | 90 | base->get_qualifiers() |= inst->get_qualifiers(); |
---|
[0dd3a2f] | 91 | result = base; |
---|
| 92 | } // if |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | void ImplementationType::visit(TupleType *tupleType) { |
---|
[62423350] | 96 | std::list< Type * > types; |
---|
[0dd3a2f] | 97 | for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) { |
---|
| 98 | Type *implType = implementationType( *i, indexer ); |
---|
[6f95000] | 99 | implType->get_qualifiers() |= tupleType->get_qualifiers(); |
---|
[62423350] | 100 | types.push_back( implType ); |
---|
[0dd3a2f] | 101 | } // for |
---|
[62423350] | 102 | result = new TupleType( Type::Qualifiers(), types ); |
---|
[0dd3a2f] | 103 | } |
---|
[44b7088] | 104 | |
---|
[7e003011] | 105 | void ImplementationType::visit( __attribute__((unused)) VarArgsType *varArgsType ) {} |
---|
| 106 | void ImplementationType::visit( __attribute__((unused)) ZeroType *zeroType ) {} |
---|
| 107 | void ImplementationType::visit( __attribute__((unused)) OneType *oneType ) {} |
---|
[51b7345] | 108 | } // namespace SymTab |
---|
[0dd3a2f] | 109 | |
---|
| 110 | // Local Variables: // |
---|
| 111 | // tab-width: 4 // |
---|
| 112 | // mode: c++ // |
---|
| 113 | // compile-command: "make install" // |
---|
| 114 | // End: // |
---|