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