source: src/SynTree/ObjectDecl.cc @ 2ead704

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2ead704 was d912bed, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

harmonize SynTree/LinkageSpec?.* with AST/LinkageSpec.*

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[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
[d912bed]12// Last Modified On : Mon Dec 16 15:12:03 2019
13// Update Count     : 61
[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
[07de76b]25#include "LinkageSpec.h"         // for Spec, linkageName, Cforall
[ea6332d]26#include "Type.h"                // for Type, Type::StorageClasses, Type::Fu...
[51b7345]27
[ddfd945]28ObjectDecl::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
32ObjectDecl::ObjectDecl( const ObjectDecl &other )
[71f4e4f]33        : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
[51b7345]34}
35
[d9a0e76]36ObjectDecl::~ObjectDecl() {
[0dd3a2f]37        delete type;
38        delete init;
39        delete bitfieldWidth;
[51b7345]40}
41
[93389c1]42ObjectDecl * ObjectDecl::newObject( const std::string & name, Type * type, Initializer * init ) {
43        return new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, 0, type, init );
44}
45
[50377a4]46void ObjectDecl::print( std::ostream &os, Indenter indent ) const {
47        if ( name != "" ) os << name << ": ";
[d9a0e76]48
[50377a4]49        if ( linkage != LinkageSpec::Cforall ) {
[d912bed]50                os << LinkageSpec::name( linkage ) << " ";
[0dd3a2f]51        } // if
[d9a0e76]52
[6e8bd43]53        get_storageClasses().print( os );
[d9a0e76]54
[50377a4]55        if ( type ) {
56                type->print( os, indent );
[0dd3a2f]57        } else {
[1cbca6e]58                os << " untyped entity ";
[0dd3a2f]59        } // if
[d9a0e76]60
[0dd3a2f]61        if ( init ) {
[50377a4]62                os << " with initializer (" << (init->get_maybeConstructed() ? "maybe constructed" : "not constructed") << ")" << std::endl << indent+1;
63                init->print( os, indent+1 );
64                os << std::endl;
[0dd3a2f]65        } // if
[d9a0e76]66
[50377a4]67        if ( ! attributes.empty() ) {
[08222c7]68                os << std::endl << indent << "... with attributes:" << std::endl;
[50377a4]69                printAll( attributes, os, indent+1 );
70        }
71
[0dd3a2f]72        if ( bitfieldWidth ) {
[50377a4]73                os << indent << " with bitfield width ";
[0dd3a2f]74                bitfieldWidth->print( os );
75        } // if
[51b7345]76}
77
[50377a4]78void ObjectDecl::printShort( std::ostream &os, Indenter indent ) const {
[d939274]79#if 0
80        if ( get_mangleName() != "") {
[974906e2]81                os << get_mangleName() << ": ";
82        } else
[d939274]83#endif
[50377a4]84        if ( name != "" ) os << name << ": ";
[f9cebb5]85
[6e8bd43]86        get_storageClasses().print( os );
[d9a0e76]87
[50377a4]88        if ( type ) {
89                type->print( os, indent );
[0dd3a2f]90        } else {
91                os << "untyped entity ";
92        } // if
[d9a0e76]93
[0dd3a2f]94        if ( bitfieldWidth ) {
95                os << "with bitfield width ";
96                bitfieldWidth->print( os );
97        } // if
[51b7345]98}
[0dd3a2f]99
100// Local Variables: //
101// tab-width: 4 //
102// mode: c++ //
103// compile-command: "make install" //
104// End: //
Note: See TracBrowser for help on using the repository browser.