| 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 : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Thu Mar 16 08:34:27 2017
 | 
|---|
| 13 | // Update Count     : 59
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 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...
 | 
|---|
| 27 | 
 | 
|---|
| 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 )
 | 
|---|
| 29 |         : Parent( name, scs, linkage, attributes, fs ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {
 | 
|---|
| 30 | }
 | 
|---|
| 31 | 
 | 
|---|
| 32 | ObjectDecl::ObjectDecl( const ObjectDecl &other )
 | 
|---|
| 33 |         : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
 | 
|---|
| 34 | }
 | 
|---|
| 35 | 
 | 
|---|
| 36 | ObjectDecl::~ObjectDecl() {
 | 
|---|
| 37 |         delete type;
 | 
|---|
| 38 |         delete init;
 | 
|---|
| 39 |         delete bitfieldWidth;
 | 
|---|
| 40 | }
 | 
|---|
| 41 | 
 | 
|---|
| 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 | 
 | 
|---|
| 46 | void ObjectDecl::print( std::ostream &os, int indent ) const {
 | 
|---|
| 47 |         if ( get_name() != "" ) {
 | 
|---|
| 48 |                 os << get_name() << ": ";
 | 
|---|
| 49 |         } // if
 | 
|---|
| 50 | 
 | 
|---|
| 51 |         if ( get_linkage() != LinkageSpec::Cforall ) {
 | 
|---|
| 52 |                 os << LinkageSpec::linkageName( get_linkage() ) << " ";
 | 
|---|
| 53 |         } // if
 | 
|---|
| 54 | 
 | 
|---|
| 55 |         printAll( get_attributes(), os, indent );
 | 
|---|
| 56 | 
 | 
|---|
| 57 |         get_storageClasses().print( os );
 | 
|---|
| 58 | 
 | 
|---|
| 59 |         if ( get_type() ) {
 | 
|---|
| 60 |                 get_type()->print( os, indent );
 | 
|---|
| 61 |         } else {
 | 
|---|
| 62 |                 os << " untyped entity ";
 | 
|---|
| 63 |         } // if
 | 
|---|
| 64 | 
 | 
|---|
| 65 |         if ( init ) {
 | 
|---|
| 66 |                 os << " with initializer " << std::endl;
 | 
|---|
| 67 |                 init->print( os, indent+2 );
 | 
|---|
| 68 |                 os << std::endl << std::string(indent+2, ' ');
 | 
|---|
| 69 |                 os << "maybeConstructed? " << init->get_maybeConstructed();
 | 
|---|
| 70 |         } // if
 | 
|---|
| 71 | 
 | 
|---|
| 72 |         if ( bitfieldWidth ) {
 | 
|---|
| 73 |                 os << std::string(indent, ' ');
 | 
|---|
| 74 |                 os << " with bitfield width ";
 | 
|---|
| 75 |                 bitfieldWidth->print( os );
 | 
|---|
| 76 |         } // if
 | 
|---|
| 77 | }
 | 
|---|
| 78 | 
 | 
|---|
| 79 | void ObjectDecl::printShort( std::ostream &os, int indent ) const {
 | 
|---|
| 80 | #if 0
 | 
|---|
| 81 |         if ( get_mangleName() != "") {
 | 
|---|
| 82 |                 os << get_mangleName() << ": ";
 | 
|---|
| 83 |         } else
 | 
|---|
| 84 | #endif
 | 
|---|
| 85 |         if ( get_name() != "" ) {
 | 
|---|
| 86 |                 os << get_name() << ": ";
 | 
|---|
| 87 |         } // if
 | 
|---|
| 88 | 
 | 
|---|
| 89 |         // xxx - should printShort print attributes?
 | 
|---|
| 90 | 
 | 
|---|
| 91 |         get_storageClasses().print( os );
 | 
|---|
| 92 | 
 | 
|---|
| 93 |         if ( get_type() ) {
 | 
|---|
| 94 |                 get_type()->print( os, indent );
 | 
|---|
| 95 |         } else {
 | 
|---|
| 96 |                 os << "untyped entity ";
 | 
|---|
| 97 |         } // if
 | 
|---|
| 98 | 
 | 
|---|
| 99 |         if ( bitfieldWidth ) {
 | 
|---|
| 100 |                 os << "with bitfield width ";
 | 
|---|
| 101 |                 bitfieldWidth->print( os );
 | 
|---|
| 102 |         } // if
 | 
|---|
| 103 | }
 | 
|---|
| 104 | 
 | 
|---|
| 105 | // Local Variables: //
 | 
|---|
| 106 | // tab-width: 4 //
 | 
|---|
| 107 | // mode: c++ //
 | 
|---|
| 108 | // compile-command: "make install" //
 | 
|---|
| 109 | // End: //
 | 
|---|