| 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.cpp --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Richard C. Bilson
|
|---|
| 10 | // Created On : Sun May 17 16:19:49 2015
|
|---|
| 11 | // Last Modified By : Andrew Beach
|
|---|
| 12 | // Last Modified On : Tue Jul 12 14:28:00 2022
|
|---|
| 13 | // Update Count : 7
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include "FixFunction.hpp"
|
|---|
| 17 |
|
|---|
| 18 | #include <list> // for list
|
|---|
| 19 |
|
|---|
| 20 | #include "AST/Decl.hpp"
|
|---|
| 21 | #include "AST/Pass.hpp"
|
|---|
| 22 | #include "AST/Type.hpp"
|
|---|
| 23 | #include "Common/Utility.hpp" // for copy
|
|---|
| 24 |
|
|---|
| 25 | namespace SymTab {
|
|---|
| 26 |
|
|---|
| 27 | namespace {
|
|---|
| 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 |
|
|---|
| 71 | } // anonymous namespace
|
|---|
| 72 |
|
|---|
| 73 | const ast::DeclWithType * fixFunction( const ast::DeclWithType * dwt, bool & isVoid ) {
|
|---|
| 74 | ast::Pass< FixFunction > fixer;
|
|---|
| 75 | dwt = dwt->accept( fixer );
|
|---|
| 76 | isVoid |= fixer.core.isVoid;
|
|---|
| 77 | return dwt;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | const ast::Type * fixFunction( const ast::Type * type, bool & isVoid ) {
|
|---|
| 81 | ast::Pass< FixFunction > fixer;
|
|---|
| 82 | type = type->accept( fixer );
|
|---|
| 83 | isVoid |= fixer.core.isVoid;
|
|---|
| 84 | return type;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | } // namespace SymTab
|
|---|
| 88 |
|
|---|
| 89 | // Local Variables: //
|
|---|
| 90 | // tab-width: 4 //
|
|---|
| 91 | // mode: c++ //
|
|---|
| 92 | // compile-command: "make install" //
|
|---|
| 93 | // End: //
|
|---|