source: src/SynTree/FunctionDecl.cc@ 3f80888

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 3f80888 was dd020c0, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

first attempt to create function specifiers

  • Property mode set to 100644
File size: 3.0 KB
Line 
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// FunctionDecl.cc --
8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Mar 3 21:29:41 2017
13// Update Count : 55
14//
15
16#include <cassert>
17
18#include "Declaration.h"
19#include "Statement.h"
20#include "Type.h"
21#include "Attribute.h"
22#include "Common/utility.h"
23#include "InitTweak/InitTweak.h"
24#include "CodeGen/FixMain.h"
25
26extern bool translation_unit_nomain;
27
28FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, std::list< Attribute * > attributes, DeclarationNode::FuncSpec fs )
29 : Parent( name, sc, linkage, attributes, fs ), type( type ), statements( statements ) {
30 set_functionSpecifiers( fs );
31
32 // hack forcing the function "main" to have Cforall linkage to replace main even if it is inside an extern
33 if ( name == "main" ) {
34 set_linkage( CodeGen::FixMain::mainLinkage() );
35 } // if
36}
37
38FunctionDecl::FunctionDecl( const FunctionDecl &other )
39 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
40}
41
42FunctionDecl::~FunctionDecl() {
43 delete type;
44 delete statements;
45}
46
47Type * FunctionDecl::get_type() const {
48 return type;
49}
50
51void FunctionDecl::set_type( Type *t ) {
52 type = dynamic_cast< FunctionType* >( t );
53 assert( type );
54}
55
56void FunctionDecl::print( std::ostream &os, int indent ) const {
57 using std::endl;
58 using std::string;
59
60 if ( get_name() != "" ) {
61 os << get_name() << ": ";
62 } // if
63 if ( get_linkage() != LinkageSpec::Cforall ) {
64 os << LinkageSpec::linkageName( get_linkage() ) << " ";
65 } // if
66
67 printAll( get_attributes(), os, indent );
68
69 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
70 os << DeclarationNode::storageClassNames[ get_storageClass() ] << ' ';
71 } // if
72 DeclarationNode::print_FuncSpec( os, get_funcSpec() );
73
74 if ( get_type() ) {
75 get_type()->print( os, indent );
76 } else {
77 os << "untyped entity ";
78 } // if
79
80 if ( statements ) {
81 os << string( indent + 2, ' ' ) << "with body " << endl;
82 os << string( indent + 4, ' ' );
83 statements->print( os, indent + 4 );
84 } // if
85}
86
87void FunctionDecl::printShort( std::ostream &os, int indent ) const {
88 using std::endl;
89 using std::string;
90
91 if ( get_name() != "" ) {
92 os << get_name() << ": ";
93 } // if
94
95 // xxx - should printShort print attributes?
96
97 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
98 os << DeclarationNode::storageClassNames[ get_storageClass() ] << ' ';
99 } // if
100 DeclarationNode::print_FuncSpec( os, get_funcSpec() );
101
102 if ( get_type() ) {
103 get_type()->print( os, indent );
104 } else {
105 os << "untyped entity ";
106 } // if
107}
108
109// Local Variables: //
110// tab-width: 4 //
111// mode: c++ //
112// compile-command: "make install" //
113// End: //
Note: See TracBrowser for help on using the repository browser.