source: src/SynTree/Type.cc @ 1469a8a

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 1469a8a was b4f8808, checked in by Andrew Beach <ajbeach@…>, 5 years ago

Removed lvalue from types in the old ast.

  • Property mode set to 100644
File size: 4.4 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 : Peter A. Buhr
12// Last Modified On : Sun Aug  4 21:05:07 2019
13// Update Count     : 45
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#include "SynTree/TypeSubstitution.h" // for TypeSubstitution
23
24using namespace std;
25
26const char * BasicType::typeNames[] = {
27        "_Bool",
28        "char",
29        "signed char",
30        "unsigned char",
31        "signed short int",
32        "unsigned short int",
33        "signed int",
34        "unsigned int",
35        "signed long int",
36        "unsigned long int",
37        "signed long long int",
38        "unsigned long long int",
39        "__int128",
40        "unsigned __int128",
41        "_Float16",
42        "_Float16 _Complex",
43        "_Float32",
44        "_Float32 _Complex",
45        "float",
46        "float _Complex",
47        //"float _Imaginary",
48        "_Float32x",
49        "_Float32x _Complex",
50        "_Float64",
51        "_Float64 _Complex",
52        "double",
53        "double _Complex",
54        //"double _Imaginary",
55        "_Float64x",
56        "_Float64x _Complex",
57        "__float80",
58        "_Float128",
59        "_Float128 _Complex",
60        "__float128",
61        "long double",
62        "long double _Complex",
63        //"long double _Imaginary",
64        "_Float128x",
65        "_Float128x _Complex",
66};
67static_assert(
68        sizeof(BasicType::typeNames) / sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
69        "Each basic type name should have a corresponding kind enum value"
70);
71
72Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
73
74Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
75        cloneAll( other.forall, forall );
76        cloneAll( other.attributes, attributes );
77}
78
79Type::~Type() {
80        deleteAll( forall );
81        deleteAll( attributes );
82}
83
84// These must remain in the same order as the corresponding bit fields.
85const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
86const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
87const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" };
88
89Type * Type::stripDeclarator() {
90        Type * type, * at;
91        for ( type = this; (at = InitTweak::getPointerBase( type )); type = at );
92        return type;
93}
94
95Type * Type::stripReferences() {
96        Type * type;
97        ReferenceType * ref;
98        for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
99        return type;
100}
101
102const Type * Type::stripReferences() const {
103        const Type * type;
104        const ReferenceType * ref;
105        for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base );
106        return type;
107}
108
109int Type::referenceDepth() const { return 0; }
110
111TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
112
113void Type::print( std::ostream & os, Indenter indent ) const {
114        if ( ! forall.empty() ) {
115                os << "forall" << std::endl;
116                printAll( forall, os, indent+1 );
117                os << ++indent;
118        } // if
119
120        if ( ! attributes.empty() ) {
121                os << "with attributes" << endl;
122                printAll( attributes, os, indent+1 );
123        } // if
124
125        tq.print( os );
126}
127
128
129QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) {
130}
131
132QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) {
133}
134
135QualifiedType::~QualifiedType() {
136        delete parent;
137        delete child;
138}
139
140void QualifiedType::print( std::ostream & os, Indenter indent ) const {
141        os << "Qualified Type:" << endl;
142        os << indent+1;
143        parent->print( os, indent+1 );
144        os << endl << indent+1;
145        child->print( os, indent+1 );
146        os << endl;
147        Type::print( os, indent+1 );
148}
149
150GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}
151
152void GlobalScopeType::print( std::ostream & os, Indenter ) const {
153        os << "Global Scope Type" << endl;
154}
155
156
157// Empty Variable declarations:
158const Type::FuncSpecifiers noFuncSpecifiers;
159const Type::StorageClasses noStorageClasses;
160const Type::Qualifiers noQualifiers;
161
162// Local Variables: //
163// tab-width: 4 //
164// mode: c++ //
165// compile-command: "make install" //
166// End: //
Note: See TracBrowser for help on using the repository browser.