source: src/SynTree/FunctionDecl.cc@ 6b224a52

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 6b224a52 was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Big header cleaning pass - commit 3

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