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 | // FixFunction.cc -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Sun May 17 16:19:49 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Mon Mar 6 23:36:59 2017 |
---|
13 | // Update Count : 6 |
---|
14 | // |
---|
15 | |
---|
16 | #include "FixFunction.h" |
---|
17 | |
---|
18 | #include <list> // for list |
---|
19 | |
---|
20 | #include "Common/utility.h" // for maybeClone |
---|
21 | #include "SynTree/Declaration.h" // for FunctionDecl, ObjectDecl, Declarati... |
---|
22 | #include "SynTree/Expression.h" // for Expression |
---|
23 | #include "SynTree/Type.h" // for ArrayType, PointerType, Type, Basic... |
---|
24 | |
---|
25 | namespace SymTab { |
---|
26 | FixFunction::FixFunction() : isVoid( false ) {} |
---|
27 | |
---|
28 | DeclarationWithType * FixFunction::mutate(FunctionDecl *functionDecl) { |
---|
29 | // can't delete function type because it may contain assertions, so transfer ownership to new object |
---|
30 | ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClasses(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type() ), 0, functionDecl->get_attributes() ); |
---|
31 | functionDecl->get_attributes().clear(); |
---|
32 | functionDecl->type = nullptr; |
---|
33 | delete functionDecl; |
---|
34 | return pointer; |
---|
35 | } |
---|
36 | |
---|
37 | Type * FixFunction::mutate(VoidType *voidType) { |
---|
38 | isVoid = true; |
---|
39 | return voidType; |
---|
40 | } |
---|
41 | |
---|
42 | Type * FixFunction::mutate(BasicType *basicType) { |
---|
43 | return basicType; |
---|
44 | } |
---|
45 | |
---|
46 | Type * FixFunction::mutate(PointerType *pointerType) { |
---|
47 | return pointerType; |
---|
48 | } |
---|
49 | |
---|
50 | Type * FixFunction::mutate(ArrayType *arrayType) { |
---|
51 | // need to recursively mutate the base type in order for multi-dimensional arrays to work. |
---|
52 | PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() ); |
---|
53 | delete arrayType; |
---|
54 | return pointerType; |
---|
55 | } |
---|
56 | |
---|
57 | Type * FixFunction::mutate(StructInstType *aggregateUseType) { |
---|
58 | return aggregateUseType; |
---|
59 | } |
---|
60 | |
---|
61 | Type * FixFunction::mutate(UnionInstType *aggregateUseType) { |
---|
62 | return aggregateUseType; |
---|
63 | } |
---|
64 | |
---|
65 | Type * FixFunction::mutate(EnumInstType *aggregateUseType) { |
---|
66 | return aggregateUseType; |
---|
67 | } |
---|
68 | |
---|
69 | Type * FixFunction::mutate(TraitInstType *aggregateUseType) { |
---|
70 | return aggregateUseType; |
---|
71 | } |
---|
72 | |
---|
73 | Type * FixFunction::mutate(TypeInstType *aggregateUseType) { |
---|
74 | return aggregateUseType; |
---|
75 | } |
---|
76 | |
---|
77 | Type * FixFunction::mutate(TupleType *tupleType) { |
---|
78 | return tupleType; |
---|
79 | } |
---|
80 | |
---|
81 | Type * FixFunction::mutate(VarArgsType *varArgsType) { |
---|
82 | return varArgsType; |
---|
83 | } |
---|
84 | |
---|
85 | Type * FixFunction::mutate(ZeroType *zeroType) { |
---|
86 | return zeroType; |
---|
87 | } |
---|
88 | |
---|
89 | Type * FixFunction::mutate(OneType *oneType) { |
---|
90 | return oneType; |
---|
91 | } |
---|
92 | } // namespace SymTab |
---|
93 | |
---|
94 | // Local Variables: // |
---|
95 | // tab-width: 4 // |
---|
96 | // mode: c++ // |
---|
97 | // compile-command: "make install" // |
---|
98 | // End: // |
---|