[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 | // |
---|
[974906e2] | 7 | // ObjectDecl.cc -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[8b7ee09] | 11 | // Last Modified By : Peter A. Buhr |
---|
[ddfd945] | 12 | // Last Modified On : Thu Mar 16 08:34:27 2017 |
---|
| 13 | // Update Count : 59 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[ea6332d] | 16 | #include <list> // for list |
---|
| 17 | #include <ostream> // for operator<<, ostream, basic_ostream |
---|
| 18 | #include <string> // for operator<<, string, char_traits, ope... |
---|
| 19 | |
---|
| 20 | #include "Attribute.h" // for Attribute |
---|
| 21 | #include "Common/utility.h" // for maybeClone, printAll |
---|
| 22 | #include "Declaration.h" // for ObjectDecl, ObjectDecl::Parent |
---|
| 23 | #include "Expression.h" // for Expression |
---|
| 24 | #include "Initializer.h" // for Initializer |
---|
| 25 | #include "Parser/LinkageSpec.h" // for Spec, linkageName, Cforall |
---|
| 26 | #include "Type.h" // for Type, Type::StorageClasses, Type::Fu... |
---|
[51b7345] | 27 | |
---|
[ddfd945] | 28 | ObjectDecl::ObjectDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init, const std::list< Attribute * > attributes, Type::FuncSpecifiers fs ) |
---|
[a7c90d4] | 29 | : Parent( name, scs, linkage, attributes, fs ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) { |
---|
[51b7345] | 30 | } |
---|
| 31 | |
---|
| 32 | ObjectDecl::ObjectDecl( const ObjectDecl &other ) |
---|
[71f4e4f] | 33 | : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) { |
---|
[51b7345] | 34 | } |
---|
| 35 | |
---|
[d9a0e76] | 36 | ObjectDecl::~ObjectDecl() { |
---|
[0dd3a2f] | 37 | delete type; |
---|
| 38 | delete init; |
---|
| 39 | delete bitfieldWidth; |
---|
[51b7345] | 40 | } |
---|
| 41 | |
---|
[d9a0e76] | 42 | void ObjectDecl::print( std::ostream &os, int indent ) const { |
---|
[0dd3a2f] | 43 | if ( get_name() != "" ) { |
---|
[cf0941d] | 44 | os << get_name() << ": "; |
---|
[0dd3a2f] | 45 | } // if |
---|
[d9a0e76] | 46 | |
---|
[0dd3a2f] | 47 | if ( get_linkage() != LinkageSpec::Cforall ) { |
---|
[faddbd8] | 48 | os << LinkageSpec::linkageName( get_linkage() ) << " "; |
---|
[0dd3a2f] | 49 | } // if |
---|
[d9a0e76] | 50 | |
---|
[f9cebb5] | 51 | printAll( get_attributes(), os, indent ); |
---|
| 52 | |
---|
[6e8bd43] | 53 | get_storageClasses().print( os ); |
---|
[d9a0e76] | 54 | |
---|
[0dd3a2f] | 55 | if ( get_type() ) { |
---|
| 56 | get_type()->print( os, indent ); |
---|
| 57 | } else { |
---|
[1cbca6e] | 58 | os << " untyped entity "; |
---|
[0dd3a2f] | 59 | } // if |
---|
[d9a0e76] | 60 | |
---|
[0dd3a2f] | 61 | if ( init ) { |
---|
[2873b737] | 62 | os << " with initializer " << std::endl; |
---|
| 63 | init->print( os, indent+2 ); |
---|
| 64 | os << std::endl << std::string(indent+2, ' '); |
---|
[d668182] | 65 | os << "maybeConstructed? " << init->get_maybeConstructed(); |
---|
[0dd3a2f] | 66 | } // if |
---|
[d9a0e76] | 67 | |
---|
[0dd3a2f] | 68 | if ( bitfieldWidth ) { |
---|
[9243a501] | 69 | os << std::string(indent, ' '); |
---|
[1cbca6e] | 70 | os << " with bitfield width "; |
---|
[0dd3a2f] | 71 | bitfieldWidth->print( os ); |
---|
| 72 | } // if |
---|
[51b7345] | 73 | } |
---|
| 74 | |
---|
[d9a0e76] | 75 | void ObjectDecl::printShort( std::ostream &os, int indent ) const { |
---|
[d939274] | 76 | #if 0 |
---|
| 77 | if ( get_mangleName() != "") { |
---|
[974906e2] | 78 | os << get_mangleName() << ": "; |
---|
| 79 | } else |
---|
[d939274] | 80 | #endif |
---|
[0dd3a2f] | 81 | if ( get_name() != "" ) { |
---|
[cf0941d] | 82 | os << get_name() << ": "; |
---|
[0dd3a2f] | 83 | } // if |
---|
[d9a0e76] | 84 | |
---|
[f9cebb5] | 85 | // xxx - should printShort print attributes? |
---|
| 86 | |
---|
[6e8bd43] | 87 | get_storageClasses().print( os ); |
---|
[d9a0e76] | 88 | |
---|
[0dd3a2f] | 89 | if ( get_type() ) { |
---|
| 90 | get_type()->print( os, indent ); |
---|
| 91 | } else { |
---|
| 92 | os << "untyped entity "; |
---|
| 93 | } // if |
---|
[d9a0e76] | 94 | |
---|
[0dd3a2f] | 95 | if ( bitfieldWidth ) { |
---|
| 96 | os << "with bitfield width "; |
---|
| 97 | bitfieldWidth->print( os ); |
---|
| 98 | } // if |
---|
[51b7345] | 99 | } |
---|
[0dd3a2f] | 100 | |
---|
| 101 | // Local Variables: // |
---|
| 102 | // tab-width: 4 // |
---|
| 103 | // mode: c++ // |
---|
| 104 | // compile-command: "make install" // |
---|
| 105 | // End: // |
---|