source: src/AST/Type.cpp @ 6f8e87d

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 6f8e87d was acd80b4, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Fixed several compilation errors

  • Property mode set to 100644
File size: 4.9 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.cpp --
8//
9// Author           : Aaron B. Moss
10// Created On       : Mon May 13 15:00:00 2019
11// Last Modified By : Aaron B. Moss
12// Last Modified On : Mon May 13 15:00:00 2019
13// Update Count     : 1
14//
15
16#include "Type.hpp"
17
18#include <cassert>
19#include <utility>               // for move
20#include <vector>
21
22#include "Decl.hpp"
23#include "Init.hpp"
24#include "InitTweak/InitTweak.h" // for getPointerBase
25#include "Tuples/Tuples.h"       // for isTtype
26
27namespace ast {
28
29const Type * Type::getComponent( unsigned i ) {
30        assertf( size() == 1 && i == 0, "Type::getComponent was called with size %d and index %d\n", size(), i );
31        return this;
32}
33
34const Type * Type::stripDeclarator() {
35        const Type * t;
36        const Type * a;
37        for ( t = this; (a = InitTweak::getPointerBase( t )); t = a );
38        return t;
39}
40
41const Type * Type::stripReferences() {
42        const Type * t;
43        const ReferenceType * r;
44        for ( t = this; (r = dynamic_cast<const ReferenceType *>(t) ); t = r->base );
45        return t;
46}
47
48// --- BasicType
49
50const char *BasicType::typeNames[] = {
51        "_Bool",
52        "char",
53        "signed char",
54        "unsigned char",
55        "signed short int",
56        "unsigned short int",
57        "signed int",
58        "unsigned int",
59        "signed long int",
60        "unsigned long int",
61        "signed long long int",
62        "unsigned long long int",
63        "__int128",
64        "unsigned __int128",
65        "_Float16",
66        "_Float16 _Complex",
67        "_Float32",
68        "_Float32 _Complex",
69        "float",
70        "float _Complex",
71        "_Float32x",
72        "_Float32x _Complex",
73        "_Float64",
74        "_Float64 _Complex",
75        "double",
76        "double _Complex",
77        "_Float64x",
78        "_Float64x _Complex",
79        "__float80",
80        "_Float128",
81        "_Float128 _Complex",
82        "__float128",
83        "long double",
84        "long double _Complex",
85        "_Float128x",
86        "_Float128x _Complex",
87};
88static_assert(
89        sizeof(BasicType::typeNames)/sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
90        "Each basic type name should have a corresponding kind enum value"
91);
92
93// --- FunctionType
94
95namespace {
96        bool containsTtype( const std::vector<ptr<DeclWithType>> & l ) {
97                if ( ! l.empty() ) {
98                        return Tuples::isTtype( l.back()->get_type() );
99                }
100                return false;
101        }
102}
103
104bool FunctionType::isTtype() const {
105        return containsTtype( returns ) || containsTtype( params );
106}
107
108// --- ReferenceToType
109std::vector<readonly<Decl>> ReferenceToType::lookup( const std::string& name ) const {
110        assertf( aggr(), "Must have aggregate to perform lookup" );
111
112        std::vector<readonly<Decl>> found;
113        for ( const Decl * decl : aggr()->members ) {
114                if ( decl->name == name ) { found.emplace_back( decl ); }
115        }
116        return found;
117}
118
119// --- StructInstType
120
121StructInstType::StructInstType( const StructDecl * b, CV::Qualifiers q,
122        std::vector<ptr<Attribute>>&& as )
123: ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
124
125bool StructInstType::isComplete() const { return base ? base->body : false; }
126
127// --- UnionInstType
128
129UnionInstType::UnionInstType( const UnionDecl * b, CV::Qualifiers q,
130        std::vector<ptr<Attribute>>&& as )
131: ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
132
133bool UnionInstType::isComplete() const { return base ? base->body : false; }
134
135// --- EnumInstType
136
137EnumInstType::EnumInstType( const EnumDecl * b, CV::Qualifiers q,
138        std::vector<ptr<Attribute>>&& as )
139: ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
140
141bool EnumInstType::isComplete() const { return base ? base->body : false; }
142
143// --- TypeInstType
144
145void TypeInstType::set_base( const TypeDecl * b ) {
146        base = b;
147        kind = b->kind;
148}
149
150bool TypeInstType::isComplete() const { return base->sized; }
151
152// --- TupleType
153
154TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q )
155: Type( q ), types( std::move(ts) ), members() {
156        // This constructor is awkward. `TupleType` needs to contain objects so that members can be
157        // named, but members without initializer nodes end up getting constructors, which breaks
158        // things. This happens because the object decls have to be visited so that their types are
159        // kept in sync with the types listed here. Ultimately, the types listed here should perhaps
160        // be eliminated and replaced with a list-view over members. The temporary solution is to
161        // make a `ListInit` with `maybeConstructed = false`, so when the object is visited it is not
162        // constructed. Potential better solutions include:
163        //   a) Separate `TupleType` from its declarations, into `TupleDecl` and `Tuple{Inst?}Type`,
164        //      similar to the aggregate types.
165        //   b) Separate initializer nodes better, e.g. add a `MaybeConstructed` node that is replaced
166        //      by `genInit`, rather than the current boolean flag.
167        members.reserve( types.size() );
168        for ( const Type * ty : types ) {
169                members.emplace_back( new ObjectDecl{
170                        CodeLocation{}, "", ty, new ListInit( CodeLocation{}, {}, {}, MaybeConstruct ),
171                        Storage::Classes{}, Linkage::Cforall } );
172        }
173}
174
175}
176
177// Local Variables: //
178// tab-width: 4 //
179// mode: c++ //
180// compile-command: "make install" //
181// End: //
Note: See TracBrowser for help on using the repository browser.