source: src/AST/Type.cpp @ cfaa2873

arm-ehjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since cfaa2873 was cfaa2873, checked in by Peter A. Buhr <pabuhr@…>, 2 years ago

generate BasicType::typeNames from BasicTypes?-gen

  • 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.cpp --
8//
9// Author           : Aaron B. Moss
10// Created On       : Mon May 13 15:00:00 2019
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sun Dec 15 16:56:28 2019
13// Update Count     : 4
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 ) const {
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() const {
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() const {
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
50// GENERATED START, DO NOT EDIT
51// GENERATED BY BasicTypes-gen.cc
52const char * BasicType::typeNames[] = {
53        "_Bool",
54        "char",
55        "signed char",
56        "unsigned char",
57        "signed short int",
58        "unsigned short int",
59        "signed int",
60        "unsigned int",
61        "signed long int",
62        "unsigned long int",
63        "signed long long int",
64        "unsigned long long int",
65        "__int128",
66        "unsigned __int128",
67        "_Float16",
68        "_Float16 _Complex",
69        "_Float32",
70        "_Float32 _Complex",
71        "float",
72        "float _Complex",
73        "_Float32x",
74        "_Float32x _Complex",
75        "_Float64",
76        "_Float64 _Complex",
77        "double",
78        "double _Complex",
79        "_Float64x",
80        "_Float64x _Complex",
81        "__float80",
82        "_Float128",
83        "_Float128 _Complex",
84        "__float128",
85        "long double",
86        "long double _Complex",
87        "_Float128x",
88        "_Float128x _Complex",
89};
90// GENERATED END
91
92// --- FunctionType
93
94namespace {
95        bool containsTtype( const std::vector<ptr<DeclWithType>> & l ) {
96                if ( ! l.empty() ) {
97                        return Tuples::isTtype( l.back()->get_type() );
98                }
99                return false;
100        }
101}
102
103bool FunctionType::isTtype() const {
104        return containsTtype( returns ) || containsTtype( params );
105}
106
107// --- ReferenceToType
108std::vector<readonly<Decl>> ReferenceToType::lookup( const std::string& name ) const {
109        assertf( aggr(), "Must have aggregate to perform lookup" );
110
111        std::vector<readonly<Decl>> found;
112        for ( const Decl * decl : aggr()->members ) {
113                if ( decl->name == name ) { found.emplace_back( decl ); }
114        }
115        return found;
116}
117
118// --- StructInstType
119
120StructInstType::StructInstType( const StructDecl * b, CV::Qualifiers q,
121        std::vector<ptr<Attribute>>&& as )
122: ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
123
124bool StructInstType::isComplete() const { return base ? base->body : false; }
125
126// --- UnionInstType
127
128UnionInstType::UnionInstType( const UnionDecl * b, CV::Qualifiers q,
129        std::vector<ptr<Attribute>>&& as )
130: ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
131
132bool UnionInstType::isComplete() const { return base ? base->body : false; }
133
134// --- EnumInstType
135
136EnumInstType::EnumInstType( const EnumDecl * b, CV::Qualifiers q,
137        std::vector<ptr<Attribute>>&& as )
138: ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
139
140bool EnumInstType::isComplete() const { return base ? base->body : false; }
141
142// --- TraitInstType
143
144TraitInstType::TraitInstType( const TraitDecl * b, CV::Qualifiers q,
145        std::vector<ptr<Attribute>>&& as )
146: ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
147
148// --- TypeInstType
149
150void TypeInstType::set_base( const TypeDecl * b ) {
151        base = b;
152        kind = b->kind;
153}
154
155bool TypeInstType::isComplete() const { return base->sized; }
156
157// --- TupleType
158
159TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q )
160: Type( q ), types( std::move(ts) ), members() {
161        // This constructor is awkward. `TupleType` needs to contain objects so that members can be
162        // named, but members without initializer nodes end up getting constructors, which breaks
163        // things. This happens because the object decls have to be visited so that their types are
164        // kept in sync with the types listed here. Ultimately, the types listed here should perhaps
165        // be eliminated and replaced with a list-view over members. The temporary solution is to
166        // make a `ListInit` with `maybeConstructed = false`, so when the object is visited it is not
167        // constructed. Potential better solutions include:
168        //   a) Separate `TupleType` from its declarations, into `TupleDecl` and `Tuple{Inst?}Type`,
169        //      similar to the aggregate types.
170        //   b) Separate initializer nodes better, e.g. add a `MaybeConstructed` node that is replaced
171        //      by `genInit`, rather than the current boolean flag.
172        members.reserve( types.size() );
173        for ( const Type * ty : types ) {
174                members.emplace_back( new ObjectDecl{
175                        CodeLocation{}, "", ty, new ListInit( CodeLocation{}, {}, {}, MaybeConstruct ),
176                        Storage::Classes{}, Linkage::Cforall } );
177        }
178}
179
180}
181
182// Local Variables: //
183// tab-width: 4 //
184// mode: c++ //
185// compile-command: "make install" //
186// End: //
Note: See TracBrowser for help on using the repository browser.