| 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 : Sun May 17 21:34:40 2015
 | 
|---|
| 13 | // Update Count     : 2
 | 
|---|
| 14 | //
 | 
|---|
| 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"
 | 
|---|
| 21 | #include "utility.h"
 | 
|---|
| 22 | 
 | 
|---|
| 23 | 
 | 
|---|
| 24 | namespace SymTab {
 | 
|---|
| 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);
 | 
|---|
| 39 |                 virtual void visit(ContextInstType *aggregateUseType);
 | 
|---|
| 40 |                 virtual void visit(TypeInstType *aggregateUseType);
 | 
|---|
| 41 |                 virtual void visit(TupleType *tupleType);
 | 
|---|
| 42 | 
 | 
|---|
| 43 |                 Type *result;                   // synthesized
 | 
|---|
| 44 |                 const SymTab::Indexer &indexer;
 | 
|---|
| 45 |         };
 | 
|---|
| 46 | 
 | 
|---|
| 47 |         Type * implementationType( Type *type, const SymTab::Indexer& indexer ) {
 | 
|---|
| 48 |                 ImplementationType implementor( indexer );
 | 
|---|
| 49 |                 type->accept( implementor );
 | 
|---|
| 50 |                 if ( implementor.get_result() == 0 ) {
 | 
|---|
| 51 |                         return type->clone();
 | 
|---|
| 52 |                 } else {
 | 
|---|
| 53 |                         return implementor.get_result();
 | 
|---|
| 54 |                 } // if
 | 
|---|
| 55 |         }
 | 
|---|
| 56 | 
 | 
|---|
| 57 |         ImplementationType::ImplementationType( const SymTab::Indexer &indexer ) : result( 0 ), indexer( indexer ) {
 | 
|---|
| 58 |         }
 | 
|---|
| 59 | 
 | 
|---|
| 60 |         void ImplementationType::visit(VoidType *voidType) {
 | 
|---|
| 61 |         }
 | 
|---|
| 62 | 
 | 
|---|
| 63 |         void ImplementationType::visit(BasicType *basicType) {
 | 
|---|
| 64 |         }
 | 
|---|
| 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 | 
 | 
|---|
| 78 |         void ImplementationType::visit(FunctionType *functionType) {
 | 
|---|
| 79 | ///   FunctionType *newType = functionType->clone();
 | 
|---|
| 80 | ///   for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) {
 | 
|---|
| 81 | ///     i->set_type( implementationType( i->get_type(), indexer ) );
 | 
|---|
| 82 | ///   }
 | 
|---|
| 83 | ///   for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) {
 | 
|---|
| 84 | ///     i->set_type( implementationType( i->get_type(), indexer ) );
 | 
|---|
| 85 | ///   }
 | 
|---|
| 86 |         }
 | 
|---|
| 87 | 
 | 
|---|
| 88 |         void ImplementationType::visit(StructInstType *aggregateUseType) {
 | 
|---|
| 89 |         }
 | 
|---|
| 90 | 
 | 
|---|
| 91 |         void ImplementationType::visit(UnionInstType *aggregateUseType) {
 | 
|---|
| 92 |         }
 | 
|---|
| 93 | 
 | 
|---|
| 94 |         void ImplementationType::visit(EnumInstType *aggregateUseType) {
 | 
|---|
| 95 |         }
 | 
|---|
| 96 | 
 | 
|---|
| 97 |         void ImplementationType::visit(ContextInstType *aggregateUseType) {
 | 
|---|
| 98 |         }
 | 
|---|
| 99 | 
 | 
|---|
| 100 |         void ImplementationType::visit(TypeInstType *inst) {
 | 
|---|
| 101 |                 NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() );
 | 
|---|
| 102 |                 if ( typeDecl && typeDecl->get_base() ) {
 | 
|---|
| 103 |                         Type *base = implementationType( typeDecl->get_base(), indexer );
 | 
|---|
| 104 |                         base->get_qualifiers() += inst->get_qualifiers();
 | 
|---|
| 105 |                         result = base;
 | 
|---|
| 106 |                 } // if
 | 
|---|
| 107 |         }
 | 
|---|
| 108 | 
 | 
|---|
| 109 |         void ImplementationType::visit(TupleType *tupleType) {
 | 
|---|
| 110 |                 TupleType *newType = new TupleType( Type::Qualifiers() );
 | 
|---|
| 111 |                 for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) {
 | 
|---|
| 112 |                         Type *implType = implementationType( *i, indexer );
 | 
|---|
| 113 |                         implType->get_qualifiers() += tupleType->get_qualifiers();
 | 
|---|
| 114 |                         newType->get_types().push_back( implType );
 | 
|---|
| 115 |                 } // for
 | 
|---|
| 116 |                 result = newType;
 | 
|---|
| 117 |         }
 | 
|---|
| 118 | } // namespace SymTab
 | 
|---|
| 119 | 
 | 
|---|
| 120 | // Local Variables: //
 | 
|---|
| 121 | // tab-width: 4 //
 | 
|---|
| 122 | // mode: c++ //
 | 
|---|
| 123 | // compile-command: "make install" //
 | 
|---|
| 124 | // End: //
 | 
|---|