| 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
 | 
|---|
| 12 | // Last Modified On : Thu Mar 16 15:54:08 2017
 | 
|---|
| 13 | // Update Count     : 4
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "ImplementationType.h"
 | 
|---|
| 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
 | 
|---|
| 24 | 
 | 
|---|
| 25 | 
 | 
|---|
| 26 | namespace SymTab {
 | 
|---|
| 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);
 | 
|---|
| 41 |                 virtual void visit(TraitInstType *aggregateUseType);
 | 
|---|
| 42 |                 virtual void visit(TypeInstType *aggregateUseType);
 | 
|---|
| 43 |                 virtual void visit(TupleType *tupleType);
 | 
|---|
| 44 |                 virtual void visit(VarArgsType *varArgsType);
 | 
|---|
| 45 |                 virtual void visit(ZeroType *zeroType);
 | 
|---|
| 46 |                 virtual void visit(OneType *oneType);
 | 
|---|
| 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 | 
 | 
|---|
| 65 |         void ImplementationType::visit( __attribute__((unused)) VoidType *voidType ) {}
 | 
|---|
| 66 |         void ImplementationType::visit( __attribute__((unused)) BasicType *basicType ) {}
 | 
|---|
| 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 | 
 | 
|---|
| 80 |         void ImplementationType::visit( __attribute__((unused)) FunctionType *functionType ) {}
 | 
|---|
| 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 ) {}
 | 
|---|
| 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 );
 | 
|---|
| 90 |                         base->get_qualifiers() |= inst->get_qualifiers();
 | 
|---|
| 91 |                         result = base;
 | 
|---|
| 92 |                 } // if
 | 
|---|
| 93 |         }
 | 
|---|
| 94 | 
 | 
|---|
| 95 |         void ImplementationType::visit(TupleType *tupleType) {
 | 
|---|
| 96 |                 std::list< Type * > types;
 | 
|---|
| 97 |                 for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) {
 | 
|---|
| 98 |                         Type *implType = implementationType( *i, indexer );
 | 
|---|
| 99 |                         implType->get_qualifiers() |= tupleType->get_qualifiers();
 | 
|---|
| 100 |                         types.push_back( implType );
 | 
|---|
| 101 |                 } // for
 | 
|---|
| 102 |                 result = new TupleType( Type::Qualifiers(), types );
 | 
|---|
| 103 |         }
 | 
|---|
| 104 | 
 | 
|---|
| 105 |         void ImplementationType::visit( __attribute__((unused)) VarArgsType *varArgsType ) {}
 | 
|---|
| 106 |         void ImplementationType::visit( __attribute__((unused)) ZeroType *zeroType ) {}
 | 
|---|
| 107 |         void ImplementationType::visit( __attribute__((unused)) OneType *oneType ) {}
 | 
|---|
| 108 | } // namespace SymTab
 | 
|---|
| 109 | 
 | 
|---|
| 110 | // Local Variables: //
 | 
|---|
| 111 | // tab-width: 4 //
 | 
|---|
| 112 | // mode: c++ //
 | 
|---|
| 113 | // compile-command: "make install" //
 | 
|---|
| 114 | // End: //
 | 
|---|