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 | #include "SynTree/Type.h"
|
---|
18 | #include "SynTree/Declaration.h"
|
---|
19 | #include "SynTree/Visitor.h"
|
---|
20 | #include "SymTab/Indexer.h"
|
---|
21 | #include "Common/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(TraitInstType *aggregateUseType);
|
---|
40 | virtual void visit(TypeInstType *aggregateUseType);
|
---|
41 | virtual void visit(TupleType *tupleType);
|
---|
42 | virtual void visit(VarArgsType *varArgsType);
|
---|
43 | virtual void visit(ZeroType *zeroType);
|
---|
44 | virtual void visit(OneType *oneType);
|
---|
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 |
|
---|
63 | void ImplementationType::visit( __attribute__((unused)) VoidType *voidType ) {}
|
---|
64 | void ImplementationType::visit( __attribute__((unused)) BasicType *basicType ) {}
|
---|
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( __attribute__((unused)) FunctionType *functionType ) {}
|
---|
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 ) {}
|
---|
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 );
|
---|
88 | base->get_qualifiers() |= inst->get_qualifiers();
|
---|
89 | result = base;
|
---|
90 | } // if
|
---|
91 | }
|
---|
92 |
|
---|
93 | void ImplementationType::visit(TupleType *tupleType) {
|
---|
94 | std::list< Type * > types;
|
---|
95 | for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) {
|
---|
96 | Type *implType = implementationType( *i, indexer );
|
---|
97 | implType->get_qualifiers() |= tupleType->get_qualifiers();
|
---|
98 | types.push_back( implType );
|
---|
99 | } // for
|
---|
100 | result = new TupleType( Type::Qualifiers(), types );
|
---|
101 | }
|
---|
102 |
|
---|
103 | void ImplementationType::visit( __attribute__((unused)) VarArgsType *varArgsType ) {}
|
---|
104 | void ImplementationType::visit( __attribute__((unused)) ZeroType *zeroType ) {}
|
---|
105 | void ImplementationType::visit( __attribute__((unused)) OneType *oneType ) {}
|
---|
106 | } // namespace SymTab
|
---|
107 |
|
---|
108 | // Local Variables: //
|
---|
109 | // tab-width: 4 //
|
---|
110 | // mode: c++ //
|
---|
111 | // compile-command: "make install" //
|
---|
112 | // End: //
|
---|