[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 |
---|
[1931bb01] | 11 | // Last Modified By : Andrew Beach |
---|
| 12 | // Last Modified On : Tue Jul 12 14:28:00 2022 |
---|
| 13 | // Update Count : 7 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include "FixFunction.h" |
---|
[30f9072] | 17 | |
---|
| 18 | #include <list> // for list |
---|
| 19 | |
---|
[c1ed2ee] | 20 | #include "AST/Decl.hpp" |
---|
| 21 | #include "AST/Pass.hpp" |
---|
| 22 | #include "AST/Type.hpp" |
---|
[9feb34b] | 23 | #include "Common/utility.h" // for copy |
---|
[51b7345] | 24 | |
---|
| 25 | namespace SymTab { |
---|
[c1ed2ee] | 26 | |
---|
| 27 | namespace { |
---|
[b0845f9] | 28 | |
---|
| 29 | struct FixFunction final : public ast::WithShortCircuiting { |
---|
| 30 | bool isVoid = false; |
---|
| 31 | |
---|
| 32 | void previsit( const ast::FunctionDecl * ) { visit_children = false; } |
---|
| 33 | |
---|
| 34 | const ast::DeclWithType * postvisit( const ast::FunctionDecl * func ) { |
---|
| 35 | // Cannot handle cases with asserions. |
---|
| 36 | assert( func->assertions.empty() ); |
---|
| 37 | return new ast::ObjectDecl{ |
---|
| 38 | func->location, func->name, new ast::PointerType( func->type ), nullptr, |
---|
| 39 | func->storage, func->linkage, nullptr, copy( func->attributes ) }; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | void previsit( const ast::ArrayType * ) { visit_children = false; } |
---|
| 43 | |
---|
| 44 | const ast::Type * postvisit( const ast::ArrayType * array ) { |
---|
| 45 | return new ast::PointerType{ |
---|
| 46 | array->base, array->dimension, array->isVarLen, array->isStatic, |
---|
| 47 | array->qualifiers }; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | void previsit( const ast::FunctionType * ) { visit_children = false; } |
---|
| 51 | |
---|
| 52 | const ast::Type * postvisit( const ast::FunctionType * type ) { |
---|
| 53 | return new ast::PointerType( type ); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void previsit( const ast::VoidType * ) { isVoid = true; } |
---|
| 57 | |
---|
| 58 | void previsit( const ast::BasicType * ) { visit_children = false; } |
---|
| 59 | void previsit( const ast::PointerType * ) { visit_children = false; } |
---|
| 60 | void previsit( const ast::StructInstType * ) { visit_children = false; } |
---|
| 61 | void previsit( const ast::UnionInstType * ) { visit_children = false; } |
---|
| 62 | void previsit( const ast::EnumInstType * ) { visit_children = false; } |
---|
| 63 | void previsit( const ast::TraitInstType * ) { visit_children = false; } |
---|
| 64 | void previsit( const ast::TypeInstType * ) { visit_children = false; } |
---|
| 65 | void previsit( const ast::TupleType * ) { visit_children = false; } |
---|
| 66 | void previsit( const ast::VarArgsType * ) { visit_children = false; } |
---|
| 67 | void previsit( const ast::ZeroType * ) { visit_children = false; } |
---|
| 68 | void previsit( const ast::OneType * ) { visit_children = false; } |
---|
| 69 | }; |
---|
| 70 | |
---|
[c1ed2ee] | 71 | } // anonymous namespace |
---|
| 72 | |
---|
| 73 | const ast::DeclWithType * fixFunction( const ast::DeclWithType * dwt, bool & isVoid ) { |
---|
[0bd3faf] | 74 | ast::Pass< FixFunction > fixer; |
---|
[c1ed2ee] | 75 | dwt = dwt->accept( fixer ); |
---|
[7ff3e522] | 76 | isVoid |= fixer.core.isVoid; |
---|
[c1ed2ee] | 77 | return dwt; |
---|
| 78 | } |
---|
| 79 | |
---|
[1931bb01] | 80 | const ast::Type * fixFunction( const ast::Type * type, bool & isVoid ) { |
---|
[0bd3faf] | 81 | ast::Pass< FixFunction > fixer; |
---|
[1931bb01] | 82 | type = type->accept( fixer ); |
---|
| 83 | isVoid |= fixer.core.isVoid; |
---|
| 84 | return type; |
---|
| 85 | } |
---|
| 86 | |
---|
[51b7345] | 87 | } // namespace SymTab |
---|
[0dd3a2f] | 88 | |
---|
| 89 | // Local Variables: // |
---|
| 90 | // tab-width: 4 // |
---|
| 91 | // mode: c++ // |
---|
| 92 | // compile-command: "make install" // |
---|
| 93 | // End: // |
---|