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 | // NamedTypeDecl.cc -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Mon May 18 07:44:20 2015 |
---|
11 | // Last Modified By : Andrew Beach |
---|
12 | // Last Modified On : Wed Aug 9 13:28:00 2017 |
---|
13 | // Update Count : 14 |
---|
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 "Common/utility.h" // for printAll, cloneAll, deleteAll, maybe... |
---|
21 | #include "Declaration.h" // for NamedTypeDecl, DeclarationWithType |
---|
22 | #include "Parser/LinkageSpec.h" // for Spec, Cforall, linkageName |
---|
23 | #include "Type.h" // for Type, Type::StorageClasses |
---|
24 | |
---|
25 | NamedTypeDecl::NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *base ) |
---|
26 | : Parent( name, scs, LinkageSpec::Cforall ), base( base ) {} |
---|
27 | |
---|
28 | NamedTypeDecl::NamedTypeDecl( const NamedTypeDecl &other ) |
---|
29 | : Parent( other ), base( maybeClone( other.base ) ) { |
---|
30 | cloneAll( other.parameters, parameters ); |
---|
31 | cloneAll( other.assertions, assertions ); |
---|
32 | } |
---|
33 | |
---|
34 | NamedTypeDecl::~NamedTypeDecl() { |
---|
35 | delete base; |
---|
36 | deleteAll( parameters ); |
---|
37 | deleteAll( assertions ); |
---|
38 | } |
---|
39 | |
---|
40 | void NamedTypeDecl::print( std::ostream &os, int indent ) const { |
---|
41 | using namespace std; |
---|
42 | |
---|
43 | if ( get_name() != "" ) { |
---|
44 | os << get_name() << ": "; |
---|
45 | } // if |
---|
46 | if ( get_linkage() != LinkageSpec::Cforall ) { |
---|
47 | os << LinkageSpec::linkageName( get_linkage() ) << " "; |
---|
48 | } // if |
---|
49 | get_storageClasses().print( os ); |
---|
50 | os << typeString(); |
---|
51 | if ( base ) { |
---|
52 | os << " for "; |
---|
53 | base->print( os, indent ); |
---|
54 | } // if |
---|
55 | if ( ! parameters.empty() ) { |
---|
56 | os << endl << string( indent, ' ' ) << "with parameters" << endl; |
---|
57 | printAll( parameters, os, indent+2 ); |
---|
58 | } // if |
---|
59 | if ( ! assertions.empty() ) { |
---|
60 | os << endl << string( indent, ' ' ) << "with assertions" << endl; |
---|
61 | printAll( assertions, os, indent+2 ); |
---|
62 | } // if |
---|
63 | } |
---|
64 | |
---|
65 | void NamedTypeDecl::printShort( std::ostream &os, int indent ) const { |
---|
66 | using namespace std; |
---|
67 | |
---|
68 | if ( get_name() != "" ) { |
---|
69 | os << get_name() << ": "; |
---|
70 | } // if |
---|
71 | get_storageClasses().print( os ); |
---|
72 | os << typeString(); |
---|
73 | if ( base ) { |
---|
74 | os << " for "; |
---|
75 | base->print( os, indent ); |
---|
76 | } // if |
---|
77 | if ( ! parameters.empty() ) { |
---|
78 | os << endl << string( indent, ' ' ) << "with parameters" << endl; |
---|
79 | printAll( parameters, os, indent+2 ); |
---|
80 | } // if |
---|
81 | } |
---|
82 | |
---|
83 | std::string TypedefDecl::typeString() const { return "typedef"; } |
---|
84 | |
---|
85 | // Local Variables: // |
---|
86 | // tab-width: 4 // |
---|
87 | // mode: c++ // |
---|
88 | // compile-command: "make install" // |
---|
89 | // End: // |
---|