source: src/SynTree/Type.cc @ aeb31b1

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since aeb31b1 was cd6a6ff, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Improved coverage of deterministic_output to be much finer grain.

  • Property mode set to 100644
File size: 5.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 : Peter A. Buhr
12// Last Modified On : Sun Dec 15 16:52:37 2019
13// Update Count     : 49
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
26// GENERATED START, DO NOT EDIT
27// GENERATED BY BasicTypes-gen.cc
28const char * BasicType::typeNames[] = {
29        "_Bool",
30        "char",
31        "signed char",
32        "unsigned char",
33        "signed short int",
34        "unsigned short int",
35        "signed int",
36        "unsigned int",
37        "signed long int",
38        "unsigned long int",
39        "signed long long int",
40        "unsigned long long int",
41        "__int128",
42        "unsigned __int128",
43        "_Float16",
44        "_Float16 _Complex",
45        "_Float32",
46        "_Float32 _Complex",
47        "float",
48        "float _Complex",
49        "_Float32x",
50        "_Float32x _Complex",
51        "_Float64",
52        "_Float64 _Complex",
53        "double",
54        "double _Complex",
55        "_Float64x",
56        "_Float64x _Complex",
57        "__float80",
58        "_Float128",
59        "_Float128 _Complex",
60        "__float128",
61        "long double",
62        "long double _Complex",
63        "_Float128x",
64        "_Float128x _Complex",
65};
66// GENERATED END
67
68Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
69
70Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
71        cloneAll( other.forall, forall );
72        cloneAll( other.attributes, attributes );
73}
74
75Type::~Type() {
76        deleteAll( forall );
77        deleteAll( attributes );
78}
79
80// These must remain in the same order as the corresponding bit fields.
81const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
82const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
83const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" };
84
85Type * Type::stripDeclarator() {
86        Type * type, * at;
87        for ( type = this; (at = InitTweak::getPointerBase( type )); type = at );
88        return type;
89}
90
91Type * Type::stripReferences() {
92        Type * type;
93        ReferenceType * ref;
94        for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
95        return type;
96}
97
98const Type * Type::stripReferences() const {
99        const Type * type;
100        const ReferenceType * ref;
101        for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base );
102        return type;
103}
104
105int Type::referenceDepth() const { return 0; }
106
107TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
108
109void Type::print( std::ostream & os, Indenter indent ) const {
110        if ( ! forall.empty() ) {
111                os << "forall" << std::endl;
112                printAll( forall, os, indent+1 );
113                os << ++indent;
114        } // if
115
116        if ( ! attributes.empty() ) {
117                os << "with attributes" << endl;
118                printAll( attributes, os, indent+1 );
119        } // if
120
121        tq.print( os );
122}
123
124
125QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) {
126}
127
128QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) {
129}
130
131QualifiedType::~QualifiedType() {
132        delete parent;
133        delete child;
134}
135
136void QualifiedType::print( std::ostream & os, Indenter indent ) const {
137        os << "Qualified Type:" << endl;
138        os << indent+1;
139        parent->print( os, indent+1 );
140        os << endl << indent+1;
141        child->print( os, indent+1 );
142        os << endl;
143        Type::print( os, indent+1 );
144}
145
146GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}
147
148void GlobalScopeType::print( std::ostream & os, Indenter ) const {
149        os << "Global Scope Type" << endl;
150}
151
152
153// Empty Variable declarations:
154const Type::FuncSpecifiers noFuncSpecifiers;
155const Type::StorageClasses noStorageClasses;
156const Type::Qualifiers noQualifiers;
157
158bool isUnboundType(const Type * type) {
159        if (auto typeInst = dynamic_cast<const TypeInstType *>(type)) {
160                // xxx - look for a type name produced by renameTyVars.
161
162                // TODO: once TypeInstType representation is updated, it should properly check
163                // if the context id is filled. this is a temporary hack for now
164                return isUnboundType(typeInst->name);
165        }
166        return false;
167}
168
169bool isUnboundType(const std::string & tname) {
170        // xxx - look for a type name produced by renameTyVars.
171
172        // TODO: once TypeInstType representation is updated, it should properly check
173        // if the context id is filled. this is a temporary hack for now
174        if (std::count(tname.begin(), tname.end(), '_') >= 3) {
175                return true;
176        }
177        return false;
178}
179
180// Local Variables: //
181// tab-width: 4 //
182// mode: c++ //
183// compile-command: "make install" //
184// End: //
Note: See TracBrowser for help on using the repository browser.