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 | |
---|
29 | DeclarationWithType * FixFunction::postmutate(FunctionDecl *functionDecl) { |
---|
30 | // can't delete function type because it may contain assertions, so transfer ownership to new object |
---|
31 | ObjectDecl *pointer = new ObjectDecl( functionDecl->name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr, new PointerType( Type::Qualifiers(), functionDecl->type ), nullptr, functionDecl->attributes ); |
---|
32 | functionDecl->attributes.clear(); |
---|
33 | functionDecl->type = nullptr; |
---|
34 | delete functionDecl; |
---|
35 | return pointer; |
---|
36 | } |
---|
37 | |
---|
38 | // xxx - this passes on void[], e.g. |
---|
39 | // void foo(void [10]); |
---|
40 | // does not cause an error |
---|
41 | |
---|
42 | Type * FixFunction::postmutate(ArrayType *arrayType) { |
---|
43 | // need to recursively mutate the base type in order for multi-dimensional arrays to work. |
---|
44 | PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic ); |
---|
45 | arrayType->base = nullptr; |
---|
46 | arrayType->dimension = nullptr; |
---|
47 | delete arrayType; |
---|
48 | return pointerType; |
---|
49 | } |
---|
50 | |
---|
51 | void FixFunction::premutate(VoidType *) { |
---|
52 | isVoid = true; |
---|
53 | } |
---|
54 | |
---|
55 | void FixFunction::premutate(FunctionDecl *) { visit_children = false; } |
---|
56 | void FixFunction::premutate(ArrayType *) { visit_children = false; } |
---|
57 | void FixFunction::premutate(BasicType *) { visit_children = false; } |
---|
58 | void FixFunction::premutate(PointerType *) { visit_children = false; } |
---|
59 | void FixFunction::premutate(StructInstType *) { visit_children = false; } |
---|
60 | void FixFunction::premutate(UnionInstType *) { visit_children = false; } |
---|
61 | void FixFunction::premutate(EnumInstType *) { visit_children = false; } |
---|
62 | void FixFunction::premutate(TraitInstType *) { visit_children = false; } |
---|
63 | void FixFunction::premutate(TypeInstType *) { visit_children = false; } |
---|
64 | void FixFunction::premutate(TupleType *) { visit_children = false; } |
---|
65 | void FixFunction::premutate(VarArgsType *) { visit_children = false; } |
---|
66 | void FixFunction::premutate(ZeroType *) { visit_children = false; } |
---|
67 | void FixFunction::premutate(OneType *) { visit_children = false; } |
---|
68 | |
---|
69 | bool fixFunction( DeclarationWithType *& dwt ) { |
---|
70 | PassVisitor<FixFunction> fixer; |
---|
71 | dwt = dwt->acceptMutator( fixer ); |
---|
72 | return fixer.pass.isVoid; |
---|
73 | } |
---|
74 | } // namespace SymTab |
---|
75 | |
---|
76 | // Local Variables: // |
---|
77 | // tab-width: 4 // |
---|
78 | // mode: c++ // |
---|
79 | // compile-command: "make install" // |
---|
80 | // End: // |
---|