source: src/SynTree/Type.cc @ a0c7dc36

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since a0c7dc36 was 8135d4c, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Merge branch 'master' into references

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