source: src/SymTab/FixFunction.cc@ 96df1329

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since 96df1329 was d53772d, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Transfer location from function to object in FixFunction [fixes #98]

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