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 | // Type.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 2 11:11:00 2017 |
---|
13 | // Update Count : 29 |
---|
14 | // |
---|
15 | |
---|
16 | #include "SynTree.h" |
---|
17 | #include "Visitor.h" |
---|
18 | #include "Type.h" |
---|
19 | #include "Declaration.h" |
---|
20 | #include "Attribute.h" |
---|
21 | #include "InitTweak/InitTweak.h" |
---|
22 | #include "Common/utility.h" |
---|
23 | |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | const char *BasicType::typeNames[BasicType::NUMBER_OF_BASIC_TYPES] = { |
---|
27 | "_Bool", |
---|
28 | "char", |
---|
29 | "char", |
---|
30 | "unsigned char", |
---|
31 | "short", |
---|
32 | "short unsigned", |
---|
33 | "int", |
---|
34 | "unsigned int", |
---|
35 | "long int", |
---|
36 | "long unsigned int", |
---|
37 | "long long int", |
---|
38 | "long long unsigned int", |
---|
39 | "float", |
---|
40 | "double", |
---|
41 | "long double", |
---|
42 | "float _Complex", |
---|
43 | "double _Complex", |
---|
44 | "long double _Complex", |
---|
45 | "float _Imaginary", |
---|
46 | "double _Imaginary", |
---|
47 | "long double _Imaginary", |
---|
48 | }; |
---|
49 | |
---|
50 | Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {} |
---|
51 | |
---|
52 | Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) { |
---|
53 | cloneAll( other.forall, forall ); |
---|
54 | cloneAll( other.attributes, attributes ); |
---|
55 | } |
---|
56 | |
---|
57 | Type::~Type() { |
---|
58 | deleteAll( forall ); |
---|
59 | deleteAll( attributes ); |
---|
60 | } |
---|
61 | |
---|
62 | // These must remain in the same order as the corresponding bit fields. |
---|
63 | const char * Type::FuncSpecifiersNames[] = { "inline", "fortran", "_Noreturn" }; |
---|
64 | const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" }; |
---|
65 | const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" }; |
---|
66 | |
---|
67 | Type * Type::stripDeclarator() { |
---|
68 | Type * type = this; |
---|
69 | while ( Type * at = InitTweak::getPointerBase( type ) ) { |
---|
70 | type = at; |
---|
71 | } |
---|
72 | return type; |
---|
73 | } |
---|
74 | |
---|
75 | Type * Type::stripReferences() { |
---|
76 | Type * type = this; |
---|
77 | while ( ReferenceType * ref = dynamic_cast<ReferenceType *>( type ) ) { |
---|
78 | type = ref->get_base(); |
---|
79 | } |
---|
80 | return type; |
---|
81 | } |
---|
82 | |
---|
83 | int Type::referenceDepth() const { return 0; } |
---|
84 | |
---|
85 | void Type::print( std::ostream &os, int indent ) const { |
---|
86 | if ( ! forall.empty() ) { |
---|
87 | os << "forall" << std::endl; |
---|
88 | printAll( forall, os, indent + 4 ); |
---|
89 | os << std::string( indent+2, ' ' ); |
---|
90 | } // if |
---|
91 | |
---|
92 | if ( ! attributes.empty() ) { |
---|
93 | os << endl << string( indent+2, ' ' ) << "with attributes" << endl; |
---|
94 | printAll( attributes, os, indent+4 ); |
---|
95 | } // if |
---|
96 | |
---|
97 | tq.print( os ); |
---|
98 | } |
---|
99 | |
---|
100 | // Empty Variable declarations: |
---|
101 | const Type::FuncSpecifiers noFuncSpecifiers; |
---|
102 | const Type::StorageClasses noStorageClasses; |
---|
103 | const Type::Qualifiers noQualifiers; |
---|
104 | |
---|
105 | std::ostream & operator<<( std::ostream & out, const Type * type ) { |
---|
106 | if ( type ) { |
---|
107 | type->print( out ); |
---|
108 | } else { |
---|
109 | out << "nullptr"; |
---|
110 | } // if |
---|
111 | return out; |
---|
112 | } |
---|
113 | |
---|
114 | // Local Variables: // |
---|
115 | // tab-width: 4 // |
---|
116 | // mode: c++ // |
---|
117 | // compile-command: "make install" // |
---|
118 | // End: // |
---|