[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...
|
---|
[51b73452] | 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 ) {
|
---|
[51b73452] | 30 | }
|
---|
| 31 |
|
---|
| 32 | ObjectDecl::ObjectDecl( const ObjectDecl &other )
|
---|
[71f4e4f] | 33 | : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
|
---|
[51b73452] | 34 | }
|
---|
| 35 |
|
---|
[d9a0e76] | 36 | ObjectDecl::~ObjectDecl() {
|
---|
[0dd3a2f] | 37 | delete type;
|
---|
| 38 | delete init;
|
---|
| 39 | delete bitfieldWidth;
|
---|
[51b73452] | 40 | }
|
---|
| 41 |
|
---|
[93389c1] | 42 | ObjectDecl * ObjectDecl::newObject( const std::string & name, Type * type, Initializer * init ) {
|
---|
| 43 | return new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, 0, type, init );
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[d9a0e76] | 46 | void ObjectDecl::print( std::ostream &os, int indent ) const {
|
---|
[0dd3a2f] | 47 | if ( get_name() != "" ) {
|
---|
[cf0941d] | 48 | os << get_name() << ": ";
|
---|
[0dd3a2f] | 49 | } // if
|
---|
[d9a0e76] | 50 |
|
---|
[0dd3a2f] | 51 | if ( get_linkage() != LinkageSpec::Cforall ) {
|
---|
[faddbd8] | 52 | os << LinkageSpec::linkageName( get_linkage() ) << " ";
|
---|
[0dd3a2f] | 53 | } // if
|
---|
[d9a0e76] | 54 |
|
---|
[f9cebb5] | 55 | printAll( get_attributes(), os, indent );
|
---|
| 56 |
|
---|
[6e8bd43] | 57 | get_storageClasses().print( os );
|
---|
[d9a0e76] | 58 |
|
---|
[0dd3a2f] | 59 | if ( get_type() ) {
|
---|
| 60 | get_type()->print( os, indent );
|
---|
| 61 | } else {
|
---|
[1cbca6e] | 62 | os << " untyped entity ";
|
---|
[0dd3a2f] | 63 | } // if
|
---|
[d9a0e76] | 64 |
|
---|
[0dd3a2f] | 65 | if ( init ) {
|
---|
[2873b737] | 66 | os << " with initializer " << std::endl;
|
---|
| 67 | init->print( os, indent+2 );
|
---|
| 68 | os << std::endl << std::string(indent+2, ' ');
|
---|
[d668182] | 69 | os << "maybeConstructed? " << init->get_maybeConstructed();
|
---|
[0dd3a2f] | 70 | } // if
|
---|
[d9a0e76] | 71 |
|
---|
[0dd3a2f] | 72 | if ( bitfieldWidth ) {
|
---|
[9243a501] | 73 | os << std::string(indent, ' ');
|
---|
[1cbca6e] | 74 | os << " with bitfield width ";
|
---|
[0dd3a2f] | 75 | bitfieldWidth->print( os );
|
---|
| 76 | } // if
|
---|
[51b73452] | 77 | }
|
---|
| 78 |
|
---|
[d9a0e76] | 79 | void ObjectDecl::printShort( std::ostream &os, int indent ) const {
|
---|
[d939274] | 80 | #if 0
|
---|
| 81 | if ( get_mangleName() != "") {
|
---|
[974906e2] | 82 | os << get_mangleName() << ": ";
|
---|
| 83 | } else
|
---|
[d939274] | 84 | #endif
|
---|
[0dd3a2f] | 85 | if ( get_name() != "" ) {
|
---|
[cf0941d] | 86 | os << get_name() << ": ";
|
---|
[0dd3a2f] | 87 | } // if
|
---|
[d9a0e76] | 88 |
|
---|
[f9cebb5] | 89 | // xxx - should printShort print attributes?
|
---|
| 90 |
|
---|
[6e8bd43] | 91 | get_storageClasses().print( os );
|
---|
[d9a0e76] | 92 |
|
---|
[0dd3a2f] | 93 | if ( get_type() ) {
|
---|
| 94 | get_type()->print( os, indent );
|
---|
| 95 | } else {
|
---|
| 96 | os << "untyped entity ";
|
---|
| 97 | } // if
|
---|
[d9a0e76] | 98 |
|
---|
[0dd3a2f] | 99 | if ( bitfieldWidth ) {
|
---|
| 100 | os << "with bitfield width ";
|
---|
| 101 | bitfieldWidth->print( os );
|
---|
| 102 | } // if
|
---|
[51b73452] | 103 | }
|
---|
[0dd3a2f] | 104 |
|
---|
| 105 | // Local Variables: //
|
---|
| 106 | // tab-width: 4 //
|
---|
| 107 | // mode: c++ //
|
---|
| 108 | // compile-command: "make install" //
|
---|
| 109 | // End: //
|
---|