[0dd3a2f] | 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 | // |
---|
[40e636a] | 7 | // FixFunction.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 16:19:49 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[a7c90d4] | 12 | // Last Modified On : Mon Mar 6 23:36:59 2017 |
---|
| 13 | // Update Count : 6 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include "FixFunction.h" |
---|
[30f9072] | 17 | |
---|
| 18 | #include <list> // for list |
---|
| 19 | |
---|
| 20 | #include "Common/utility.h" // for maybeClone |
---|
| 21 | #include "SynTree/Declaration.h" // for FunctionDecl, ObjectDecl, Declarati... |
---|
[c3acf0aa] | 22 | #include "SynTree/Expression.h" // for Expression |
---|
[30f9072] | 23 | #include "SynTree/Type.h" // for ArrayType, PointerType, Type, Basic... |
---|
[51b7345] | 24 | |
---|
| 25 | namespace SymTab { |
---|
[a7c90d4] | 26 | FixFunction::FixFunction() : isVoid( false ) {} |
---|
[51b7345] | 27 | |
---|
[21b7161] | 28 | |
---|
| 29 | DeclarationWithType * FixFunction::postmutate(FunctionDecl *functionDecl) { |
---|
[68f9c43] | 30 | return new ObjectDecl{ |
---|
| 31 | functionDecl->name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr, |
---|
| 32 | new PointerType{ Type::Qualifiers(), functionDecl->type }, |
---|
| 33 | nullptr, functionDecl->attributes }; |
---|
[0dd3a2f] | 34 | } |
---|
[51b7345] | 35 | |
---|
[4bda2cf] | 36 | // xxx - this passes on void[], e.g. |
---|
| 37 | // void foo(void [10]); |
---|
| 38 | // does not cause an error |
---|
| 39 | |
---|
[21b7161] | 40 | Type * FixFunction::postmutate(ArrayType *arrayType) { |
---|
[40e636a] | 41 | // need to recursively mutate the base type in order for multi-dimensional arrays to work. |
---|
[68f9c43] | 42 | return new PointerType{ arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic }; |
---|
[0dd3a2f] | 43 | } |
---|
[51b7345] | 44 | |
---|
[21b7161] | 45 | void FixFunction::premutate(VoidType *) { |
---|
| 46 | isVoid = true; |
---|
[89e6ffc] | 47 | } |
---|
| 48 | |
---|
[21b7161] | 49 | void FixFunction::premutate(FunctionDecl *) { visit_children = false; } |
---|
[954ef5b] | 50 | void FixFunction::premutate(ArrayType *) { visit_children = false; } |
---|
[21b7161] | 51 | void FixFunction::premutate(BasicType *) { visit_children = false; } |
---|
| 52 | void FixFunction::premutate(PointerType *) { visit_children = false; } |
---|
| 53 | void FixFunction::premutate(StructInstType *) { visit_children = false; } |
---|
| 54 | void FixFunction::premutate(UnionInstType *) { visit_children = false; } |
---|
| 55 | void FixFunction::premutate(EnumInstType *) { visit_children = false; } |
---|
| 56 | void FixFunction::premutate(TraitInstType *) { visit_children = false; } |
---|
| 57 | void FixFunction::premutate(TypeInstType *) { visit_children = false; } |
---|
| 58 | void FixFunction::premutate(TupleType *) { visit_children = false; } |
---|
| 59 | void FixFunction::premutate(VarArgsType *) { visit_children = false; } |
---|
| 60 | void FixFunction::premutate(ZeroType *) { visit_children = false; } |
---|
| 61 | void FixFunction::premutate(OneType *) { visit_children = false; } |
---|
[4bda2cf] | 62 | |
---|
| 63 | bool fixFunction( DeclarationWithType *& dwt ) { |
---|
| 64 | PassVisitor<FixFunction> fixer; |
---|
| 65 | dwt = dwt->acceptMutator( fixer ); |
---|
| 66 | return fixer.pass.isVoid; |
---|
| 67 | } |
---|
[51b7345] | 68 | } // namespace SymTab |
---|
[0dd3a2f] | 69 | |
---|
| 70 | // Local Variables: // |
---|
| 71 | // tab-width: 4 // |
---|
| 72 | // mode: c++ // |
---|
| 73 | // compile-command: "make install" // |
---|
| 74 | // End: // |
---|