[2bb4a01] | 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.hpp -- |
---|
| 8 | // |
---|
| 9 | // Author : Aaron B. Moss |
---|
| 10 | // Created On : Thu May 9 10:00:00 2019 |
---|
| 11 | // Last Modified By : Aaron B. Moss |
---|
| 12 | // Last Modified On : Thu May 9 10:00:00 2019 |
---|
| 13 | // Update Count : 1 |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | #pragma once |
---|
| 17 | |
---|
[9e1d485] | 18 | #include <cassert> |
---|
| 19 | #include <cstddef> // for nullptr_t |
---|
| 20 | #include <cstdint> // for uintptr_t |
---|
| 21 | #include <utility> // for move |
---|
| 22 | #include <vector> |
---|
| 23 | |
---|
| 24 | #include "CVQualifiers.hpp" |
---|
[9b4f329] | 25 | #include "Decl.hpp" // for AggregateDecl subclasses |
---|
[9e1d485] | 26 | #include "Fwd.hpp" |
---|
| 27 | #include "Node.hpp" // for Node, ptr |
---|
| 28 | #include "TypeVar.hpp" |
---|
| 29 | #include "Visitor.hpp" |
---|
[2bb4a01] | 30 | |
---|
[f3cc5b6] | 31 | // Must be included in *all* AST classes; should be #undef'd at the end of the file |
---|
[acd80b4] | 32 | #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); |
---|
[f3cc5b6] | 33 | |
---|
[2bb4a01] | 34 | namespace ast { |
---|
| 35 | |
---|
| 36 | class Type : public Node { |
---|
[9e1d485] | 37 | public: |
---|
[54e41b3] | 38 | CV::Qualifiers qualifiers; |
---|
[87701b6] | 39 | |
---|
[54e41b3] | 40 | Type( CV::Qualifiers q = {} ) : qualifiers(q) {} |
---|
| 41 | |
---|
| 42 | bool is_const() const { return qualifiers.is_const; } |
---|
| 43 | bool is_volatile() const { return qualifiers.is_volatile; } |
---|
| 44 | bool is_restrict() const { return qualifiers.is_restrict; } |
---|
| 45 | bool is_lvalue() const { return qualifiers.is_lvalue; } |
---|
| 46 | bool is_mutex() const { return qualifiers.is_mutex; } |
---|
| 47 | bool is_atomic() const { return qualifiers.is_atomic; } |
---|
| 48 | |
---|
[76ed81f] | 49 | Type * set_const( bool v ) { qualifiers.is_const = v; return this; } |
---|
| 50 | Type * set_restrict( bool v ) { qualifiers.is_restrict = v; return this; } |
---|
| 51 | Type * set_lvalue( bool v ) { qualifiers.is_lvalue = v; return this; } |
---|
| 52 | Type * set_mutex( bool v ) { qualifiers.is_mutex = v; return this; } |
---|
| 53 | Type * set_atomic( bool v ) { qualifiers.is_atomic = v; return this; } |
---|
[9e1d485] | 54 | |
---|
| 55 | /// How many elemental types are represented by this type |
---|
| 56 | virtual unsigned size() const { return 1; } |
---|
| 57 | /// Is this a void type? |
---|
| 58 | virtual bool isVoid() const { return size() == 0; } |
---|
| 59 | /// Get the i'th component of this type |
---|
| 60 | virtual const Type * getComponent( unsigned i ); |
---|
| 61 | |
---|
| 62 | /// type without outer pointers and arrays |
---|
| 63 | const Type * stripDeclarator(); |
---|
| 64 | /// type without outer references |
---|
| 65 | const Type * stripReferences(); |
---|
| 66 | /// number of reference occuring consecutively on the outermost layer of this type |
---|
| 67 | /// (i.e. do not count references nested within other types) |
---|
| 68 | virtual unsigned referenceDepth() const { return 0; } |
---|
| 69 | /// true iff type is complete type (i.e. compiler knows the size, alignment, and layout) |
---|
| 70 | virtual bool isComplete() const { return true; } |
---|
| 71 | |
---|
[69bafd2] | 72 | virtual const Type * accept( Visitor & v ) const override = 0; |
---|
[9e1d485] | 73 | private: |
---|
| 74 | virtual Type * clone() const override = 0; |
---|
[f3cc5b6] | 75 | MUTATE_FRIEND |
---|
[9e1d485] | 76 | }; |
---|
| 77 | |
---|
| 78 | /// `void` |
---|
| 79 | class VoidType final : public Type { |
---|
| 80 | public: |
---|
| 81 | VoidType( CV::Qualifiers q = {} ) : Type( q ) {} |
---|
[87701b6] | 82 | |
---|
[9e1d485] | 83 | unsigned size() const override { return 0; } |
---|
| 84 | bool isVoid() const override { return true; } |
---|
| 85 | bool isComplete() const override { return false; } |
---|
| 86 | |
---|
[69bafd2] | 87 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 88 | private: |
---|
| 89 | VoidType * clone() const override { return new VoidType{ *this }; } |
---|
[f3cc5b6] | 90 | MUTATE_FRIEND |
---|
[9e1d485] | 91 | }; |
---|
| 92 | |
---|
| 93 | /// Built-in arithmetic type |
---|
| 94 | class BasicType final : public Type { |
---|
| 95 | public: |
---|
| 96 | // GENERATED START, DO NOT EDIT |
---|
| 97 | // GENERATED BY BasicTypes-gen.cc |
---|
| 98 | enum Kind { |
---|
| 99 | Bool, |
---|
| 100 | Char, |
---|
| 101 | SignedChar, |
---|
| 102 | UnsignedChar, |
---|
| 103 | ShortSignedInt, |
---|
| 104 | ShortUnsignedInt, |
---|
| 105 | SignedInt, |
---|
| 106 | UnsignedInt, |
---|
| 107 | LongSignedInt, |
---|
| 108 | LongUnsignedInt, |
---|
| 109 | LongLongSignedInt, |
---|
| 110 | LongLongUnsignedInt, |
---|
| 111 | SignedInt128, |
---|
| 112 | UnsignedInt128, |
---|
| 113 | uFloat16, |
---|
| 114 | uFloat16Complex, |
---|
| 115 | uFloat32, |
---|
| 116 | uFloat32Complex, |
---|
| 117 | Float, |
---|
| 118 | FloatComplex, |
---|
| 119 | uFloat32x, |
---|
| 120 | uFloat32xComplex, |
---|
| 121 | uFloat64, |
---|
| 122 | uFloat64Complex, |
---|
| 123 | Double, |
---|
| 124 | DoubleComplex, |
---|
| 125 | uFloat64x, |
---|
| 126 | uFloat64xComplex, |
---|
| 127 | uuFloat80, |
---|
| 128 | uFloat128, |
---|
| 129 | uFloat128Complex, |
---|
| 130 | uuFloat128, |
---|
| 131 | LongDouble, |
---|
| 132 | LongDoubleComplex, |
---|
| 133 | uFloat128x, |
---|
| 134 | uFloat128xComplex, |
---|
| 135 | NUMBER_OF_BASIC_TYPES |
---|
| 136 | } kind; |
---|
| 137 | // GENERATED END |
---|
| 138 | |
---|
| 139 | /// xxx -- MAX_INTEGER_TYPE should probably be in BasicTypes-gen.cc, rather than hardcoded here |
---|
| 140 | enum { MAX_INTEGER_TYPE = UnsignedInt128 }; |
---|
| 141 | |
---|
| 142 | /// string names of basic types; generated to match with Kind |
---|
| 143 | static const char *typeNames[]; |
---|
| 144 | |
---|
| 145 | BasicType( Kind k, CV::Qualifiers q = {} ) : Type(q), kind(k) {} |
---|
| 146 | |
---|
| 147 | /// Check if this type represents an integer type |
---|
[3648d98] | 148 | bool isInteger() const { return (unsigned)kind <= (unsigned)MAX_INTEGER_TYPE; } |
---|
[9e1d485] | 149 | |
---|
[69bafd2] | 150 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 151 | private: |
---|
| 152 | BasicType * clone() const override { return new BasicType{ *this }; } |
---|
[f3cc5b6] | 153 | MUTATE_FRIEND |
---|
[9e1d485] | 154 | }; |
---|
| 155 | |
---|
| 156 | /// Pointer/array variable length? |
---|
| 157 | enum LengthFlag { FixedLen, VariableLen }; |
---|
| 158 | |
---|
| 159 | /// Pointer/array static dimension? |
---|
| 160 | enum DimensionFlag { DynamicDim, StaticDim }; |
---|
| 161 | |
---|
| 162 | /// Pointer type `T*` |
---|
| 163 | class PointerType final : public Type { |
---|
| 164 | public: |
---|
| 165 | ptr<Type> base; |
---|
| 166 | |
---|
| 167 | // In C99, pointer types can be qualified in many ways, e.g. `int a[ static 3 ]` |
---|
| 168 | ptr<Expr> dimension; |
---|
| 169 | LengthFlag isVarLen = FixedLen; |
---|
| 170 | DimensionFlag isStatic = DynamicDim; |
---|
| 171 | |
---|
| 172 | PointerType( const Type * b, CV::Qualifiers q = {} ) : Type(q), base(b), dimension() {} |
---|
[87701b6] | 173 | PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, |
---|
[9e1d485] | 174 | CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {} |
---|
| 175 | |
---|
| 176 | // true if this pointer is actually an array |
---|
| 177 | bool isArray() const { return isVarLen || isStatic || dimension; } |
---|
| 178 | |
---|
| 179 | bool isComplete() const override { return ! isVarLen; } |
---|
| 180 | |
---|
[69bafd2] | 181 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 182 | private: |
---|
| 183 | PointerType * clone() const override { return new PointerType{ *this }; } |
---|
[f3cc5b6] | 184 | MUTATE_FRIEND |
---|
[9e1d485] | 185 | }; |
---|
| 186 | |
---|
| 187 | /// Array type `T[]` |
---|
| 188 | class ArrayType final : public Type { |
---|
| 189 | public: |
---|
| 190 | ptr<Type> base; |
---|
| 191 | ptr<Expr> dimension; |
---|
| 192 | LengthFlag isVarLen; |
---|
| 193 | DimensionFlag isStatic; |
---|
[2bb4a01] | 194 | |
---|
[87701b6] | 195 | ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, |
---|
[9e1d485] | 196 | CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {} |
---|
| 197 | |
---|
| 198 | // array types are complete if they have a dimension expression or are |
---|
| 199 | // VLAs ('*' in parameter declaration), and incomplete otherwise. |
---|
| 200 | // See 6.7.6.2 |
---|
| 201 | bool isComplete() const override { return dimension || isVarLen; } |
---|
| 202 | |
---|
[69bafd2] | 203 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 204 | private: |
---|
| 205 | ArrayType * clone() const override { return new ArrayType{ *this }; } |
---|
[f3cc5b6] | 206 | MUTATE_FRIEND |
---|
[9e1d485] | 207 | }; |
---|
| 208 | |
---|
| 209 | /// Reference type `T&` |
---|
| 210 | class ReferenceType final : public Type { |
---|
| 211 | public: |
---|
| 212 | ptr<Type> base; |
---|
| 213 | |
---|
| 214 | ReferenceType( const Type * b, CV::Qualifiers q = {} ) : Type(q), base(b) {} |
---|
| 215 | |
---|
| 216 | unsigned referenceDepth() const override { return base->referenceDepth() + 1; } |
---|
| 217 | |
---|
| 218 | // Since reference types act like value types, their size is the size of the base. |
---|
| 219 | // This makes it simple to cast the empty tuple to a reference type, since casts that increase |
---|
| 220 | // the number of values are disallowed. |
---|
| 221 | unsigned size() const override { return base->size(); } |
---|
| 222 | |
---|
[69bafd2] | 223 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 224 | private: |
---|
| 225 | ReferenceType * clone() const override { return new ReferenceType{ *this }; } |
---|
[f3cc5b6] | 226 | MUTATE_FRIEND |
---|
[2bb4a01] | 227 | }; |
---|
| 228 | |
---|
[9e1d485] | 229 | /// Qualified type `P.C` |
---|
| 230 | class QualifiedType final : public Type { |
---|
| 231 | public: |
---|
| 232 | ptr<Type> parent; |
---|
| 233 | ptr<Type> child; |
---|
| 234 | |
---|
[87701b6] | 235 | QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} ) |
---|
[9e1d485] | 236 | : Type(q), parent(p), child(c) {} |
---|
| 237 | |
---|
[69bafd2] | 238 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 239 | private: |
---|
| 240 | QualifiedType * clone() const override { return new QualifiedType{ *this }; } |
---|
[f3cc5b6] | 241 | MUTATE_FRIEND |
---|
[9e1d485] | 242 | }; |
---|
| 243 | |
---|
| 244 | /// Base type for potentially forall-qualified types |
---|
| 245 | class ParameterizedType : public Type { |
---|
| 246 | public: |
---|
| 247 | using ForallList = std::vector<ptr<TypeDecl>>; |
---|
| 248 | |
---|
| 249 | ForallList forall; |
---|
| 250 | |
---|
[87701b6] | 251 | ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} ) |
---|
[9e1d485] | 252 | : Type(q), forall(std::move(fs)) {} |
---|
| 253 | ParameterizedType( CV::Qualifiers q ) : Type(q), forall() {} |
---|
| 254 | |
---|
| 255 | private: |
---|
| 256 | virtual ParameterizedType * clone() const override = 0; |
---|
[f3cc5b6] | 257 | MUTATE_FRIEND |
---|
[9e1d485] | 258 | }; |
---|
| 259 | |
---|
| 260 | /// Function variable arguments flag |
---|
| 261 | enum ArgumentFlag { FixedArgs, VariableArgs }; |
---|
| 262 | |
---|
| 263 | /// Type of a function `[R1, R2](*)(P1, P2, P3)` |
---|
| 264 | class FunctionType final : public ParameterizedType { |
---|
| 265 | public: |
---|
[54e41b3] | 266 | std::vector<ptr<DeclWithType>> returns; |
---|
| 267 | std::vector<ptr<DeclWithType>> params; |
---|
[9e1d485] | 268 | |
---|
[87701b6] | 269 | /// Does the function accept a variable number of arguments following the arguments specified |
---|
[9e1d485] | 270 | /// in the parameters list. |
---|
| 271 | /// This could be because of |
---|
| 272 | /// - an ellipsis in a prototype declaration |
---|
| 273 | /// - an unprototyped declaration |
---|
| 274 | ArgumentFlag isVarArgs; |
---|
| 275 | |
---|
| 276 | FunctionType( ArgumentFlag va = FixedArgs, CV::Qualifiers q = {} ) |
---|
[54e41b3] | 277 | : ParameterizedType(q), returns(), params(), isVarArgs(va) {} |
---|
[9e1d485] | 278 | |
---|
| 279 | /// true if either the parameters or return values contain a tttype |
---|
| 280 | bool isTtype() const; |
---|
| 281 | /// true if function parameters are unconstrained by prototype |
---|
[54e41b3] | 282 | bool isUnprototyped() const { return isVarArgs && params.size() == 0; } |
---|
[9e1d485] | 283 | |
---|
[69bafd2] | 284 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 285 | private: |
---|
| 286 | FunctionType * clone() const override { return new FunctionType{ *this }; } |
---|
[f3cc5b6] | 287 | MUTATE_FRIEND |
---|
[9e1d485] | 288 | }; |
---|
| 289 | |
---|
| 290 | /// base class for types that refer to types declared elsewhere (aggregates and typedefs) |
---|
| 291 | class ReferenceToType : public ParameterizedType { |
---|
| 292 | public: |
---|
[54e41b3] | 293 | std::vector<ptr<Expr>> params; |
---|
[9e1d485] | 294 | std::vector<ptr<Attribute>> attributes; |
---|
| 295 | std::string name; |
---|
| 296 | bool hoistType = false; |
---|
| 297 | |
---|
[87701b6] | 298 | ReferenceToType( const std::string& n, CV::Qualifiers q = {}, |
---|
[9e1d485] | 299 | std::vector<ptr<Attribute>> && as = {} ) |
---|
[54e41b3] | 300 | : ParameterizedType(q), params(), attributes(std::move(as)), name(n) {} |
---|
[9e1d485] | 301 | |
---|
| 302 | /// Gets aggregate declaration this type refers to |
---|
| 303 | virtual const AggregateDecl * aggr() const = 0; |
---|
| 304 | /// Looks up member declarations with given name |
---|
| 305 | std::vector<readonly<Decl>> lookup( const std::string & name ) const; |
---|
| 306 | |
---|
| 307 | private: |
---|
| 308 | virtual ReferenceToType * clone() const override = 0; |
---|
[f3cc5b6] | 309 | MUTATE_FRIEND |
---|
[9e1d485] | 310 | }; |
---|
| 311 | |
---|
| 312 | /// instance of struct type |
---|
| 313 | class StructInstType final : public ReferenceToType { |
---|
| 314 | public: |
---|
| 315 | readonly<StructDecl> base; |
---|
| 316 | |
---|
[87701b6] | 317 | StructInstType( const std::string& n, CV::Qualifiers q = {}, |
---|
[9e1d485] | 318 | std::vector<ptr<Attribute>> && as = {} ) |
---|
| 319 | : ReferenceToType( n, q, std::move(as) ), base() {} |
---|
[87701b6] | 320 | StructInstType( const StructDecl * b, CV::Qualifiers q = {}, |
---|
[9e1d485] | 321 | std::vector<ptr<Attribute>> && as = {} ); |
---|
[87701b6] | 322 | |
---|
[9e1d485] | 323 | bool isComplete() const override; |
---|
| 324 | |
---|
| 325 | const StructDecl * aggr() const override { return base; } |
---|
| 326 | |
---|
[69bafd2] | 327 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 328 | private: |
---|
| 329 | StructInstType * clone() const override { return new StructInstType{ *this }; } |
---|
[f3cc5b6] | 330 | MUTATE_FRIEND |
---|
[9e1d485] | 331 | }; |
---|
| 332 | |
---|
| 333 | /// instance of union type |
---|
| 334 | class UnionInstType final : public ReferenceToType { |
---|
| 335 | public: |
---|
| 336 | readonly<UnionDecl> base; |
---|
| 337 | |
---|
[87701b6] | 338 | UnionInstType( const std::string& n, CV::Qualifiers q = {}, |
---|
[9e1d485] | 339 | std::vector<ptr<Attribute>> && as = {} ) |
---|
| 340 | : ReferenceToType( n, q, std::move(as) ), base() {} |
---|
[87701b6] | 341 | UnionInstType( const UnionDecl * b, CV::Qualifiers q = {}, |
---|
[9e1d485] | 342 | std::vector<ptr<Attribute>> && as = {} ); |
---|
[87701b6] | 343 | |
---|
[9e1d485] | 344 | bool isComplete() const override; |
---|
| 345 | |
---|
| 346 | const UnionDecl * aggr() const override { return base; } |
---|
| 347 | |
---|
[69bafd2] | 348 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 349 | private: |
---|
| 350 | UnionInstType * clone() const override { return new UnionInstType{ *this }; } |
---|
[f3cc5b6] | 351 | MUTATE_FRIEND |
---|
[9e1d485] | 352 | }; |
---|
| 353 | |
---|
| 354 | /// instance of enum type |
---|
| 355 | class EnumInstType final : public ReferenceToType { |
---|
| 356 | public: |
---|
| 357 | readonly<EnumDecl> base; |
---|
| 358 | |
---|
[87701b6] | 359 | EnumInstType( const std::string& n, CV::Qualifiers q = {}, |
---|
[9e1d485] | 360 | std::vector<ptr<Attribute>> && as = {} ) |
---|
| 361 | : ReferenceToType( n, q, std::move(as) ), base() {} |
---|
[87701b6] | 362 | EnumInstType( const EnumDecl * b, CV::Qualifiers q = {}, |
---|
[9e1d485] | 363 | std::vector<ptr<Attribute>> && as = {} ); |
---|
[87701b6] | 364 | |
---|
[9e1d485] | 365 | bool isComplete() const override; |
---|
| 366 | |
---|
| 367 | const EnumDecl * aggr() const override { return base; } |
---|
| 368 | |
---|
[69bafd2] | 369 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 370 | private: |
---|
| 371 | EnumInstType * clone() const override { return new EnumInstType{ *this }; } |
---|
[f3cc5b6] | 372 | MUTATE_FRIEND |
---|
[9e1d485] | 373 | }; |
---|
| 374 | |
---|
| 375 | /// instance of trait type |
---|
| 376 | class TraitInstType final : public ReferenceToType { |
---|
| 377 | public: |
---|
| 378 | readonly<TraitDecl> base; |
---|
| 379 | |
---|
[87701b6] | 380 | TraitInstType( const std::string& n, CV::Qualifiers q = {}, |
---|
[9e1d485] | 381 | std::vector<ptr<Attribute>> && as = {} ) |
---|
| 382 | : ReferenceToType( n, q, std::move(as) ), base() {} |
---|
[87701b6] | 383 | TraitInstType( const TraitDecl * b, CV::Qualifiers q = {}, |
---|
[9e1d485] | 384 | std::vector<ptr<Attribute>> && as = {} ); |
---|
[87701b6] | 385 | |
---|
[9e1d485] | 386 | // not meaningful for TraitInstType |
---|
| 387 | bool isComplete() const override { assert(false); } |
---|
| 388 | |
---|
| 389 | const TraitDecl * aggr() const override { return base; } |
---|
| 390 | |
---|
[69bafd2] | 391 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 392 | private: |
---|
| 393 | TraitInstType * clone() const override { return new TraitInstType{ *this }; } |
---|
[f3cc5b6] | 394 | MUTATE_FRIEND |
---|
[9e1d485] | 395 | }; |
---|
| 396 | |
---|
| 397 | /// instance of named type alias (typedef or variable) |
---|
| 398 | class TypeInstType final : public ReferenceToType { |
---|
| 399 | public: |
---|
| 400 | readonly<TypeDecl> base; |
---|
| 401 | TypeVar::Kind kind; |
---|
| 402 | |
---|
[87701b6] | 403 | TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, |
---|
[9e1d485] | 404 | std::vector<ptr<Attribute>> && as = {} ) |
---|
| 405 | : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {} |
---|
[87701b6] | 406 | TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, |
---|
[9e1d485] | 407 | std::vector<ptr<Attribute>> && as = {} ) |
---|
| 408 | : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {} |
---|
| 409 | |
---|
| 410 | /// sets `base`, updating `kind` correctly |
---|
| 411 | void set_base( const TypeDecl * ); |
---|
| 412 | |
---|
| 413 | bool isComplete() const override; |
---|
| 414 | |
---|
| 415 | // not meaningful for TypeInstType |
---|
| 416 | const AggregateDecl * aggr() const override { assert(false); } |
---|
| 417 | |
---|
[69bafd2] | 418 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 419 | private: |
---|
| 420 | TypeInstType * clone() const override { return new TypeInstType{ *this }; } |
---|
[f3cc5b6] | 421 | MUTATE_FRIEND |
---|
[9e1d485] | 422 | }; |
---|
| 423 | |
---|
| 424 | /// tuple type e.g. `[int, char]` |
---|
| 425 | class TupleType final : public Type { |
---|
| 426 | public: |
---|
| 427 | std::vector<ptr<Type>> types; |
---|
| 428 | std::vector<ptr<Decl>> members; |
---|
| 429 | |
---|
| 430 | TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q = {} ); |
---|
| 431 | |
---|
| 432 | // collection simulation |
---|
| 433 | using iterator = std::vector<ptr<Type>>::const_iterator; |
---|
| 434 | iterator begin() const { return types.begin(); } |
---|
| 435 | iterator end() const { return types.end(); } |
---|
[87701b6] | 436 | |
---|
[9e1d485] | 437 | unsigned size() const override { return types.size(); } |
---|
| 438 | |
---|
| 439 | const Type * getComponent( unsigned i ) override { |
---|
[87701b6] | 440 | assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", |
---|
[9e1d485] | 441 | i, size() ); |
---|
| 442 | return *(begin()+i); |
---|
| 443 | } |
---|
| 444 | |
---|
[69bafd2] | 445 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 446 | private: |
---|
| 447 | TupleType * clone() const override { return new TupleType{ *this }; } |
---|
[f3cc5b6] | 448 | MUTATE_FRIEND |
---|
[9e1d485] | 449 | }; |
---|
| 450 | |
---|
| 451 | /// Type of unresolved `typeof()` expression |
---|
| 452 | class TypeofType : public Type { |
---|
| 453 | public: |
---|
| 454 | ptr<Expr> expr; |
---|
| 455 | enum Kind { Typeof, Basetypeof } kind; |
---|
| 456 | |
---|
[87701b6] | 457 | TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} ) |
---|
[9e1d485] | 458 | : Type(q), expr(e), kind(k) {} |
---|
| 459 | |
---|
[69bafd2] | 460 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 461 | private: |
---|
| 462 | TypeofType * clone() const override { return new TypeofType{ *this }; } |
---|
[f3cc5b6] | 463 | MUTATE_FRIEND |
---|
[9e1d485] | 464 | }; |
---|
| 465 | |
---|
| 466 | /// GCC built-in varargs type |
---|
| 467 | class VarArgsType final : public Type { |
---|
| 468 | public: |
---|
| 469 | VarArgsType( CV::Qualifiers q = {} ) : Type( q ) {} |
---|
[87701b6] | 470 | |
---|
[69bafd2] | 471 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 472 | private: |
---|
| 473 | VarArgsType * clone() const override { return new VarArgsType{ *this }; } |
---|
[f3cc5b6] | 474 | MUTATE_FRIEND |
---|
[9e1d485] | 475 | }; |
---|
| 476 | |
---|
| 477 | /// Type of zero constant `0` |
---|
| 478 | class ZeroType final : public Type { |
---|
| 479 | public: |
---|
| 480 | ZeroType( CV::Qualifiers q = {} ) : Type( q ) {} |
---|
[87701b6] | 481 | |
---|
[69bafd2] | 482 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 483 | private: |
---|
[f3cc5b6] | 484 | ZeroType * clone() const override { return new ZeroType{ *this }; } |
---|
| 485 | MUTATE_FRIEND |
---|
[9e1d485] | 486 | }; |
---|
| 487 | |
---|
| 488 | /// Type of one constant `1` |
---|
| 489 | class OneType final : public Type { |
---|
| 490 | public: |
---|
| 491 | OneType( CV::Qualifiers q = {} ) : Type( q ) {} |
---|
| 492 | |
---|
[69bafd2] | 493 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 494 | private: |
---|
| 495 | OneType * clone() const override { return new OneType{ *this }; } |
---|
[f3cc5b6] | 496 | MUTATE_FRIEND |
---|
[9e1d485] | 497 | }; |
---|
| 498 | |
---|
| 499 | /// Parent type for scope-qualified types at global scope |
---|
| 500 | class GlobalScopeType final : public Type { |
---|
| 501 | public: |
---|
[746ae82] | 502 | GlobalScopeType() : Type() {} |
---|
[9e1d485] | 503 | |
---|
[69bafd2] | 504 | const Type * accept( Visitor & v ) const override { return v.visit( this ); } |
---|
[9e1d485] | 505 | private: |
---|
| 506 | GlobalScopeType * clone() const override { return new GlobalScopeType{ *this }; } |
---|
[f3cc5b6] | 507 | MUTATE_FRIEND |
---|
[9e1d485] | 508 | }; |
---|
[e0115286] | 509 | |
---|
[2bb4a01] | 510 | } |
---|
| 511 | |
---|
[f3cc5b6] | 512 | #undef MUTATE_FRIEND |
---|
| 513 | |
---|
[2bb4a01] | 514 | // Local Variables: // |
---|
| 515 | // tab-width: 4 // |
---|
| 516 | // mode: c++ // |
---|
| 517 | // compile-command: "make install" // |
---|
| 518 | // End: // |
---|