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(VoidType *voidType) {
|
---|
64 | }
|
---|
65 |
|
---|
66 | void ImplementationType::visit(BasicType *basicType) {
|
---|
67 | }
|
---|
68 |
|
---|
69 | void ImplementationType::visit(PointerType *pointerType) {
|
---|
70 | PointerType *newType = pointerType->clone();
|
---|
71 | newType->set_base( implementationType( pointerType->get_base(), indexer ) );
|
---|
72 | result = newType;
|
---|
73 | }
|
---|
74 |
|
---|
75 | void ImplementationType::visit(ArrayType *arrayType) {
|
---|
76 | ArrayType *newType = arrayType->clone();
|
---|
77 | newType->set_base( implementationType( arrayType->get_base(), indexer ) );
|
---|
78 | result = newType;
|
---|
79 | }
|
---|
80 |
|
---|
81 | void ImplementationType::visit(FunctionType *functionType) {
|
---|
82 | /// FunctionType *newType = functionType->clone();
|
---|
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 | /// for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) {
|
---|
87 | /// i->set_type( implementationType( i->get_type(), indexer ) );
|
---|
88 | /// }
|
---|
89 | }
|
---|
90 |
|
---|
91 | void ImplementationType::visit(StructInstType *aggregateUseType) {
|
---|
92 | }
|
---|
93 |
|
---|
94 | void ImplementationType::visit(UnionInstType *aggregateUseType) {
|
---|
95 | }
|
---|
96 |
|
---|
97 | void ImplementationType::visit(EnumInstType *aggregateUseType) {
|
---|
98 | }
|
---|
99 |
|
---|
100 | void ImplementationType::visit(TraitInstType *aggregateUseType) {
|
---|
101 | }
|
---|
102 |
|
---|
103 | void ImplementationType::visit(TypeInstType *inst) {
|
---|
104 | NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() );
|
---|
105 | if ( typeDecl && typeDecl->get_base() ) {
|
---|
106 | Type *base = implementationType( typeDecl->get_base(), indexer );
|
---|
107 | base->get_qualifiers() |= inst->get_qualifiers();
|
---|
108 | result = base;
|
---|
109 | } // if
|
---|
110 | }
|
---|
111 |
|
---|
112 | void ImplementationType::visit(TupleType *tupleType) {
|
---|
113 | TupleType *newType = new TupleType( Type::Qualifiers() );
|
---|
114 | for ( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) {
|
---|
115 | Type *implType = implementationType( *i, indexer );
|
---|
116 | implType->get_qualifiers() |= tupleType->get_qualifiers();
|
---|
117 | newType->get_types().push_back( implType );
|
---|
118 | } // for
|
---|
119 | result = newType;
|
---|
120 | }
|
---|
121 |
|
---|
122 | void ImplementationType::visit(VarArgsType *varArgsType) {
|
---|
123 | }
|
---|
124 |
|
---|
125 | void ImplementationType::visit(ZeroType *zeroType) {
|
---|
126 | }
|
---|
127 |
|
---|
128 | void ImplementationType::visit(OneType *oneType) {
|
---|
129 | }
|
---|
130 | } // namespace SymTab
|
---|
131 |
|
---|
132 | // Local Variables: //
|
---|
133 | // tab-width: 4 //
|
---|
134 | // mode: c++ //
|
---|
135 | // compile-command: "make install" //
|
---|
136 | // End: //
|
---|