[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 | |
---|
[93389c1] | 36 | ObjectDecl * ObjectDecl::newObject( const std::string & name, Type * type, Initializer * init ) { |
---|
| 37 | return new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, 0, type, init ); |
---|
| 38 | } |
---|
| 39 | |
---|
[50377a4] | 40 | void ObjectDecl::print( std::ostream &os, Indenter indent ) const { |
---|
| 41 | if ( name != "" ) os << name << ": "; |
---|
[d9a0e76] | 42 | |
---|
[50377a4] | 43 | if ( linkage != LinkageSpec::Cforall ) { |
---|
| 44 | os << LinkageSpec::linkageName( linkage ) << " "; |
---|
[0dd3a2f] | 45 | } // if |
---|
[d9a0e76] | 46 | |
---|
[6e8bd43] | 47 | get_storageClasses().print( os ); |
---|
[d9a0e76] | 48 | |
---|
[50377a4] | 49 | if ( type ) { |
---|
| 50 | type->print( os, indent ); |
---|
[0dd3a2f] | 51 | } else { |
---|
[1cbca6e] | 52 | os << " untyped entity "; |
---|
[0dd3a2f] | 53 | } // if |
---|
[d9a0e76] | 54 | |
---|
[0dd3a2f] | 55 | if ( init ) { |
---|
[50377a4] | 56 | os << " with initializer (" << (init->get_maybeConstructed() ? "maybe constructed" : "not constructed") << ")" << std::endl << indent+1; |
---|
| 57 | init->print( os, indent+1 ); |
---|
| 58 | os << std::endl; |
---|
[0dd3a2f] | 59 | } // if |
---|
[d9a0e76] | 60 | |
---|
[50377a4] | 61 | if ( ! attributes.empty() ) { |
---|
| 62 | os << std::endl << indent << "... with attributes: " << std::endl; |
---|
| 63 | printAll( attributes, os, indent+1 ); |
---|
| 64 | } |
---|
| 65 | |
---|
[0dd3a2f] | 66 | if ( bitfieldWidth ) { |
---|
[50377a4] | 67 | os << indent << " with bitfield width "; |
---|
[0dd3a2f] | 68 | bitfieldWidth->print( os ); |
---|
| 69 | } // if |
---|
[51b7345] | 70 | } |
---|
| 71 | |
---|
[50377a4] | 72 | void ObjectDecl::printShort( std::ostream &os, Indenter indent ) const { |
---|
[d939274] | 73 | #if 0 |
---|
| 74 | if ( get_mangleName() != "") { |
---|
[974906e2] | 75 | os << get_mangleName() << ": "; |
---|
| 76 | } else |
---|
[d939274] | 77 | #endif |
---|
[50377a4] | 78 | if ( name != "" ) os << name << ": "; |
---|
[f9cebb5] | 79 | |
---|
[6e8bd43] | 80 | get_storageClasses().print( os ); |
---|
[d9a0e76] | 81 | |
---|
[50377a4] | 82 | if ( type ) { |
---|
| 83 | type->print( os, indent ); |
---|
[0dd3a2f] | 84 | } else { |
---|
| 85 | os << "untyped entity "; |
---|
| 86 | } // if |
---|
[d9a0e76] | 87 | |
---|
[0dd3a2f] | 88 | if ( bitfieldWidth ) { |
---|
| 89 | os << "with bitfield width "; |
---|
| 90 | bitfieldWidth->print( os ); |
---|
| 91 | } // if |
---|
[51b7345] | 92 | } |
---|
[0dd3a2f] | 93 | |
---|
| 94 | // Local Variables: // |
---|
| 95 | // tab-width: 4 // |
---|
| 96 | // mode: c++ // |
---|
| 97 | // compile-command: "make install" // |
---|
| 98 | // End: // |
---|