source: src/SynTree/ObjectDecl.cc @ a254fa56

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since a254fa56 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
Line 
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 : Mon Dec 16 15:12:03 2019
13// Update Count     : 61
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 "LinkageSpec.h"         // for Spec, linkageName, Cforall
26#include "Type.h"                // for Type, Type::StorageClasses, Type::Fu...
27
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 )
29        : Parent( name, scs, linkage, attributes, fs ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {
30}
31
32ObjectDecl::ObjectDecl( const ObjectDecl &other )
33        : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {
34}
35
36ObjectDecl::~ObjectDecl() {
37        delete type;
38        delete init;
39        delete bitfieldWidth;
40}
41
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
46void ObjectDecl::print( std::ostream &os, Indenter indent ) const {
47        if ( name != "" ) os << name << ": ";
48
49        if ( linkage != LinkageSpec::Cforall ) {
50                os << LinkageSpec::name( linkage ) << " ";
51        } // if
52
53        get_storageClasses().print( os );
54
55        if ( type ) {
56                type->print( os, indent );
57        } else {
58                os << " untyped entity ";
59        } // if
60
61        if ( init ) {
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;
65        } // if
66
67        if ( ! attributes.empty() ) {
68                os << std::endl << indent << "... with attributes:" << std::endl;
69                printAll( attributes, os, indent+1 );
70        }
71
72        if ( bitfieldWidth ) {
73                os << indent << " with bitfield width ";
74                bitfieldWidth->print( os );
75        } // if
76}
77
78void ObjectDecl::printShort( std::ostream &os, Indenter indent ) const {
79#if 0
80        if ( get_mangleName() != "") {
81                os << get_mangleName() << ": ";
82        } else
83#endif
84        if ( name != "" ) os << name << ": ";
85
86        get_storageClasses().print( os );
87
88        if ( type ) {
89                type->print( os, indent );
90        } else {
91                os << "untyped entity ";
92        } // if
93
94        if ( bitfieldWidth ) {
95                os << "with bitfield width ";
96                bitfieldWidth->print( os );
97        } // if
98}
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.