source: src/SynTree/ObjectDecl.cc@ 4ffdd63

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory 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 4ffdd63 was 668edd6b, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

Merge branch 'fix-tree-printing' into ctor

Conflicts:

src/SynTree/Expression.cc
src/SynTree/Initializer.cc
src/SynTree/ObjectDecl.cc

  • Property mode set to 100644
File size: 2.6 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// ObjectDecl.cc --
8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Tue Apr 26 12:56:27 2016
13// Update Count : 30
14//
15
16#include "Declaration.h"
17#include "Type.h"
18#include "Initializer.h"
19#include "Expression.h"
20#include "Common/utility.h"
21#include "Statement.h"
22
23ObjectDecl::ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline, bool isNoreturn )
24 : Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {
25 set_isInline( isInline );
26 set_isNoreturn( isNoreturn );
27}
28
29ObjectDecl::ObjectDecl( const ObjectDecl &other )
30 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
31}
32
33ObjectDecl::~ObjectDecl() {
34 delete type;
35 delete init;
36 delete bitfieldWidth;
37}
38
39void ObjectDecl::print( std::ostream &os, int indent ) const {
40 if ( get_name() != "" ) {
41 os << get_name() << ": ";
42 } // if
43
44 if ( get_linkage() != LinkageSpec::Cforall ) {
45 os << LinkageSpec::toString( get_linkage() ) << " ";
46 } // if
47
48 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
49 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
50 } // if
51
52 if ( get_type() ) {
53 get_type()->print( os, indent );
54 } else {
55 os << " untyped entity ";
56 } // if
57
58 if ( init ) {
59 os << " with initializer ";
60 init->print( os, indent );
61 os << std::string(indent, ' ') << "maybeConstructed? " << init->get_maybeConstructed();
62 } // if
63
64 if ( bitfieldWidth ) {
65 os << " with bitfield width ";
66 bitfieldWidth->print( os );
67 } // if
68}
69
70void ObjectDecl::printShort( std::ostream &os, int indent ) const {
71#if 0
72 if ( get_mangleName() != "") {
73 os << get_mangleName() << ": ";
74 } else
75#endif
76 if ( get_name() != "" ) {
77 os << get_name() << ": ";
78 } // if
79
80 if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
81 os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
82 } // if
83
84 if ( get_type() ) {
85 get_type()->print( os, indent );
86 } else {
87 os << "untyped entity ";
88 } // if
89
90 if ( bitfieldWidth ) {
91 os << "with bitfield width ";
92 bitfieldWidth->print( os );
93 } // if
94}
95
96// Local Variables: //
97// tab-width: 4 //
98// mode: c++ //
99// compile-command: "make install" //
100// End: //
Note: See TracBrowser for help on using the repository browser.