source: translator/SynTree/FunctionDecl.cc @ c11e31c

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since c11e31c was c11e31c, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

add inline and attribute qualifiers, cfa.y comment formatting, fix error message in isIntegralType

  • Property mode set to 100644
File size: 2.4 KB
Line 
1#include <cassert>
2
3#include "Declaration.h"
4#include "Statement.h"
5#include "Type.h"
6#include "utility.h"
7
8
9FunctionDecl::FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline )
10        : Parent( name, sc, linkage ), type( type ), statements( statements ), isInline( isInline ) {
11    // this is a brazen hack to force the function "main" to have C linkage
12    if ( name == "main" ) {
13        set_linkage( LinkageSpec::C );
14    }
15}
16
17FunctionDecl::FunctionDecl( const FunctionDecl &other )
18    : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), isInline( other.isInline ) {
19}
20
21FunctionDecl::~FunctionDecl() {
22    delete type;
23    delete statements;
24}
25
26Type * FunctionDecl::get_type() const {
27    return type;
28}
29
30void FunctionDecl::set_type( Type *t ) {
31    type = dynamic_cast< FunctionType* >( t );
32    assert( type );
33}
34
35void FunctionDecl::print( std::ostream &os, int indent ) const {
36    using std::endl;
37    using std::string;
38   
39    if ( get_name() != "" ) {
40        os << get_name() << ": a ";
41    }
42    if ( get_linkage() != LinkageSpec::Cforall ) {
43        os << LinkageSpec::toString( get_linkage() ) << " ";
44    }
45    if ( isInline ) {
46        os << "inline ";
47    }
48    if ( get_storageClass() != NoStorageClass ) {
49        os << storageClassName[ get_storageClass() ] << ' ';
50    }
51    if ( get_type() ) {
52        get_type()->print( os, indent );
53    } else {
54        os << "untyped entity ";
55    }
56    if ( ! oldIdents.empty() ) {
57        os << string( indent+2, ' ' ) << "with parameter names" << endl;
58        for( std::list< std::string >::const_iterator i = oldIdents.begin(); i != oldIdents.end(); ++i ) {
59            os << string( indent+4, ' ' ) << *i << endl;
60        }
61    }
62    if ( ! oldDecls.empty() ) {
63        os << string( indent+2, ' ' ) << "with parameter declarations" << endl;
64        printAll( oldDecls, os, indent+4 );
65    }
66    if ( statements ) {
67        os << string( indent+2, ' ' ) << "with body " << endl;
68        statements->print( os, indent+4 );
69    }
70}
71
72void FunctionDecl::printShort( std::ostream &os, int indent ) const {
73    using std::endl;
74    using std::string;
75   
76    if ( get_name() != "" ) {
77        os << get_name() << ": a ";
78    }
79    if ( isInline ) {
80        os << "inline ";
81    }
82    if ( get_storageClass() != NoStorageClass ) {
83        os << storageClassName[ get_storageClass() ] << ' ';
84    }
85    if ( get_type() ) {
86        get_type()->print( os, indent );
87    } else {
88        os << "untyped entity ";
89    }
90}
Note: See TracBrowser for help on using the repository browser.