source: translator/SymTab/ImplementationType.cc@ a0d9f94

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since a0d9f94 was 51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

initial commit

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: ImplementationType.cc,v 1.4 2005/08/29 20:14:17 rcbilson Exp $
5 *
6 */
7
8#include "ImplementationType.h"
9#include "SynTree/Type.h"
10#include "SynTree/Declaration.h"
11#include "SynTree/Visitor.h"
12#include "SymTab/Indexer.h"
13#include "utility.h"
14
15
16namespace SymTab {
17
18class ImplementationType : public Visitor
19{
20public:
21 ImplementationType( const SymTab::Indexer &indexer );
22
23 Type *get_result() { return result; }
24
25private:
26 virtual void visit(VoidType *voidType);
27 virtual void visit(BasicType *basicType);
28 virtual void visit(PointerType *pointerType);
29 virtual void visit(ArrayType *arrayType);
30 virtual void visit(FunctionType *functionType);
31 virtual void visit(StructInstType *aggregateUseType);
32 virtual void visit(UnionInstType *aggregateUseType);
33 virtual void visit(EnumInstType *aggregateUseType);
34 virtual void visit(ContextInstType *aggregateUseType);
35 virtual void visit(TypeInstType *aggregateUseType);
36 virtual void visit(TupleType *tupleType);
37
38 Type *result; // synthesized
39 const SymTab::Indexer &indexer;
40};
41
42Type*
43implementationType( Type *type, const SymTab::Indexer& indexer )
44{
45 ImplementationType implementor( indexer );
46 type->accept( implementor );
47 if( implementor.get_result() == 0 ) {
48 return type->clone();
49 } else {
50 return implementor.get_result();
51 }
52}
53
54ImplementationType::ImplementationType( const SymTab::Indexer &indexer )
55 : result( 0 ), indexer( indexer )
56{
57}
58
59void
60ImplementationType::visit(VoidType *voidType)
61{
62}
63
64void
65ImplementationType::visit(BasicType *basicType)
66{
67}
68
69void
70ImplementationType::visit(PointerType *pointerType)
71{
72 PointerType *newType = pointerType->clone();
73 newType->set_base( implementationType( pointerType->get_base(), indexer ) );
74 result = newType;
75}
76
77void
78ImplementationType::visit(ArrayType *arrayType)
79{
80 ArrayType *newType = arrayType->clone();
81 newType->set_base( implementationType( arrayType->get_base(), indexer ) );
82 result = newType;
83}
84
85void
86ImplementationType::visit(FunctionType *functionType)
87{
88/// FunctionType *newType = functionType->clone();
89/// for( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) {
90/// i->set_type( implementationType( i->get_type(), indexer ) );
91/// }
92/// for( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) {
93/// i->set_type( implementationType( i->get_type(), indexer ) );
94/// }
95}
96
97void
98ImplementationType::visit(StructInstType *aggregateUseType)
99{
100}
101
102void
103ImplementationType::visit(UnionInstType *aggregateUseType)
104{
105}
106
107void
108ImplementationType::visit(EnumInstType *aggregateUseType)
109{
110}
111
112void
113ImplementationType::visit(ContextInstType *aggregateUseType)
114{
115}
116
117void
118ImplementationType::visit(TypeInstType *inst)
119{
120 NamedTypeDecl *typeDecl = indexer.lookupType( inst->get_name() );
121 if( typeDecl && typeDecl->get_base() ) {
122 Type *base = implementationType( typeDecl->get_base(), indexer );
123 base->get_qualifiers() += inst->get_qualifiers();
124 result = base;
125 }
126}
127
128void
129ImplementationType::visit(TupleType *tupleType)
130{
131 TupleType *newType = new TupleType( Type::Qualifiers() );
132 for( std::list< Type* >::iterator i = tupleType->get_types().begin(); i != tupleType->get_types().end(); ++i ) {
133 Type *implType = implementationType( *i, indexer );
134 implType->get_qualifiers() += tupleType->get_qualifiers();
135 newType->get_types().push_back( implType );
136 }
137 result = newType;
138}
139
140} // namespace SymTab
Note: See TracBrowser for help on using the repository browser.