Types

This section contains definitions declared in the chpl::types namespace.

namespace chpl::types
class AnyType : public chpl::types::Type
#include <AnyType.h>

This class represents a generic type that can instantiate to any type.

Public Functions

~AnyType() = default

Public Static Functions

static const AnyType *get(Context *context)
class BasicClassType : public chpl::types::CompositeType
#include <BasicClassType.h>

This class represents an class type (e.g. class C) without considering decorators.

Public Functions

~BasicClassType() = default
inline const BasicClassType *parentClassType() const

Return the parent class type, or nullptr if this is the ‘object’ type.

inline bool isObjectType() const

Return true if this type is the ‘object’ type.

bool isSubtypeOf(const BasicClassType *parentType, bool &converts, bool &instantiates) const

Returns true if this class type is a subclass of the passed parent class type or an instantiaton of a passed generic class type or a combination of the two.

The argument ‘convert’ is set to true if passing required using a parent type and ‘instantiates’ is set to true if it requires instantiation.

inline const BasicClassType *instantiatedFrom() const

If this type represents an instantiated type, returns the type it was instantiated from.

This is just instantiatedFromCompositeType() with the result cast to BasicClassType.

Public Static Functions

static const BasicClassType *get(Context *context, ID id, UniqueString name, const BasicClassType *parentType, std::vector<CompositeType::FieldDetail> fields, const BasicClassType *instantiatedFrom)
static const BasicClassType *getObjectType(Context *context)
class BoolType : public chpl::types::PrimitiveType
#include <BoolType.h>

This class represents a bool type, e.g. bool or bool(32).

Note that bool normally has width 8 but bool(8) is a separate type.

Public Functions

~BoolType() = default
inline virtual int bitwidth() const override

Returns the bit width selected for numeric types. Returns 8 for the default sized bool.

inline virtual const char *c_str() const override

Returns a C string for the name of this PrimitiveType.

inline bool isDefaultBool() const

Returns true if this is the type bool which is distinct from bool(8).

Public Static Functions

static const BoolType *get(Context *context, int bitwidth)
class BuiltinType : public chpl::types::Type
#include <BuiltinType.h>

This class represents a builtin type that only needs a name to be used by resolution.

For example, numeric, borrowed, chpl_anyreal.

Types that are used very commonly (e.g. AnyType, UnknownType) should get their own classes.

Types that have need for different fields (e.g. PrimitiveType) should get their own classes.

Public Functions

~BuiltinType() = default
const char *c_str() const

Returns a C string for the name of this BuiltinType.

Public Static Functions

static void gatherBuiltins(Context *context, std::unordered_map<UniqueString, const Type*> &map)
class BytesType : public chpl::types::Type
#include <BytesType.h>

This class represents the bytes type.

Public Functions

~BytesType() = default

Public Static Functions

static const BytesType *get(Context *context)
class ClassType : public chpl::types::Type
#include <ClassType.h>

This class represents an class type including a memory management decorator. E.g. if we have class C, then borrowed C? or shared C are ClassTypes.

Public Functions

~ClassType() = default
virtual void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const override
inline ClassTypeDecorator decorator() const

Returns the ClassTypeDecorator for this ClassType. This decorator indicates the memory management strategy.

inline const Type *manager() const

Returns the manager for this ClassType, or nullptr if the decorator does not indicate a managed type. This can return a record type or AnyOwnedType / AnySharedType.

inline const BasicClassType *basicClassType() const

Returns the basic class type

inline virtual bool isGeneric() const override

Returns true if this is a generic type

const ClassType *withDecorator(Context *context, ClassTypeDecorator decorator) const

Returns the verison this ClassType with the passed decorator

Public Static Functions

static const ClassType *get(Context *context, const BasicClassType *basicType, const Type *manager, ClassTypeDecorator decorator)
class ClassTypeDecorator
#include <ClassTypeDecorator.h>

This class stores a class type decorator that describes a memory management strategy.

It wraps a ClassTypeDecoratorEnum value so that it is easy to call methods on it.

Public Types

enum ClassTypeDecoratorEnum

Values:

enumerator BORROWED
enumerator BORROWED_NONNIL
enumerator BORROWED_NILABLE
enumerator UNMANAGED
enumerator UNMANAGED_NONNIL
enumerator UNMANAGED_NILABLE
enumerator MANAGED
enumerator MANAGED_NONNIL
enumerator MANAGED_NILABLE
enumerator GENERIC
enumerator GENERIC_NONNIL
enumerator GENERIC_NILABLE
enum [anonymous]

Values:

enumerator NUM_DECORATORS
enumerator MANAGEMENT_MASK
enumerator NILABILITY_MASK

Public Functions

inline explicit ClassTypeDecorator(ClassTypeDecoratorEnum val)
~ClassTypeDecorator() = default
inline ClassTypeDecoratorEnum val() const

Returns the ClassTypeDecoratorEnum value

inline ClassTypeDecorator removeNilable() const

Returns a decorator based on this one but with unknown nilability

inline ClassTypeDecorator addNonNil() const

Returns a decorator based on this one but that is non-nilable

inline ClassTypeDecorator addNilable() const

Returns a decorator based on this one but that is nilable

inline ClassTypeDecorator toBorrowed() const

Returns a decorator based on this one but with borrowed management (preserving nilability)

inline bool isUnknownNilability() const

Returns true if this decorator has unknown nilability

inline bool isNonNilable() const

Returns true if this decorator is non-nilable

inline bool isNilable() const

Returns true if this decorator is nilable

inline bool isBorrowed() const

Returns true if this decorator represents a borrowed type (e.g. borrowed C)

inline bool isUnmanaged() const

Returns true if this decorator represents a unmanaged type (e.g. unmanaged C)

inline bool isManaged() const

Returns true if this decorator represents a managed type (e.g. owned or shared)

inline bool isUnknownManagement() const

Returns true if this decorator has unknown management

inline ClassTypeDecorator combine(ClassTypeDecorator actual) const

Combines decorators assuming that this is a formal and the passed decorator is an actual

inline bool operator==(ClassTypeDecorator other) const
inline bool operator!=(ClassTypeDecorator other) const
inline size_t hash() const
inline void swap(ClassTypeDecorator other)

Public Static Functions

static inline ClassTypeDecoratorEnum getIthDecorator(int i)

Given an integer i with 0 <= i < NUM_DECORATORS returns a decorator with that number. This can be used to iterate over the possible decorators.

static inline ClassTypeDecoratorEnum removeNilableFromDecorator(ClassTypeDecoratorEnum d)
static inline ClassTypeDecoratorEnum addNonNilToDecorator(ClassTypeDecoratorEnum d)
static inline ClassTypeDecoratorEnum addNilableToDecorator(ClassTypeDecoratorEnum d)
static inline bool isDecoratorUnknownNilability(ClassTypeDecoratorEnum d)
static inline bool isDecoratorNonNilable(ClassTypeDecoratorEnum d)
static inline bool isDecoratorNilable(ClassTypeDecoratorEnum d)
static inline bool isDecoratorBorrowed(ClassTypeDecoratorEnum d)
static inline bool isDecoratorUnmanaged(ClassTypeDecoratorEnum d)
static inline bool isDecoratorManaged(ClassTypeDecoratorEnum d)
static inline bool isDecoratorUnknownManagement(ClassTypeDecoratorEnum d)
static ClassTypeDecoratorEnum combineDecorators(ClassTypeDecoratorEnum formalDecorator, ClassTypeDecoratorEnum actualDecorator)
class ComplexType : public chpl::types::PrimitiveType
#include <ComplexType.h>

This class represents a complex type, e.g. complex or complex(64).

Public Functions

~ComplexType() = default
inline virtual int bitwidth() const override

Returns the bit width selected for numeric types. Returns 8 for the default sized bool.

inline virtual const char *c_str() const override

Returns a C string for the name of this PrimitiveType.

Public Static Functions

static const ComplexType *get(Context *context, int bitwidth)
class CompositeType : public chpl::types::Type
#include <CompositeType.h>

This class represents an aggregate type which is a type that contains other elements as fields. Subclasses include BasicClass, Record, Union, and Tuple types.

Subclassed by chpl::types::BasicClassType, chpl::types::RecordType, chpl::types::TupleType, chpl::types::UnionType

Public Functions

virtual ~CompositeType() = 0
virtual void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const override
inline virtual bool isGeneric() const override

Returns true if this is a generic type

inline bool isGenericWithDefaults() const

Returns true if this is a generic type where all generic fields have default values. For classes, this includes consideration of the parent class.

inline const ID &id() const

Return the uAST ID associated with this CompositeType

inline UniqueString name() const

Returns the name of the uAST associated with this CompositeType

inline int numFields() const

Return the number of fields

inline UniqueString fieldName(int i) const

Return the name of the i’th field

inline bool fieldHasDefaultValue(int i) const

Return whether or not the i’th field has a default value

inline const uast::Decl *fieldDecl(int i) const

Return the Decl associated with the i’th field, or nullptr if none

inline const QualifiedType &fieldType(int i) const

Return the QualifiedType of the i’th field

inline const CompositeType *instantiatedFromCompositeType() const

If this type represents an instantiated type, returns the type it was instantiated from.

This function always returns the fully generic type and never a partial instantiation. That is, the result will either be nullptr or result->instantiatedFrom() will be nullptr.

inline bool isInstantiationOf(const CompositeType *genericType) const
struct FieldDetail

Public Functions

inline FieldDetail(UniqueString name, bool hasDefaultValue, const uast::Decl *decl, QualifiedType type)
inline bool operator==(const FieldDetail &other) const
inline bool operator!=(const FieldDetail &other) const
inline size_t hash() const
inline void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const

Public Members

UniqueString name
bool hasDefaultValue = false
const uast::Decl *decl = nullptr
QualifiedType type
class CStringType : public chpl::types::Type
#include <CStringType.h>

This class represents the string type.

Public Functions

~CStringType() = default

Public Static Functions

static const CStringType *get(Context *context)
class ErroneousType : public chpl::types::Type
#include <ErroneousType.h>

This class represents an erroneous type - that is, a type used as an error sentinel type. Errors with this type should be ignored.

Public Functions

~ErroneousType() = default

Public Static Functions

static const ErroneousType *get(Context *context)
class ImagType : public chpl::types::PrimitiveType
#include <ImagType.h>

This class represents a imag type, e.g. imag or imag(32).

Public Functions

~ImagType() = default
inline virtual int bitwidth() const override

Returns the bit width selected for numeric types. Returns 8 for the default sized bool.

inline virtual const char *c_str() const override

Returns a C string for the name of this PrimitiveType.

Public Static Functions

static const ImagType *get(Context *context, int bitwidth)
class IntType : public chpl::types::PrimitiveType
#include <IntType.h>

This class represents an int type, e.g. int or int(32).

Public Functions

~IntType() = default
inline virtual int bitwidth() const override

Returns the bit width selected for numeric types. Returns 8 for the default sized bool.

inline virtual const char *c_str() const override

Returns a C string for the name of this PrimitiveType.

Public Static Functions

static const IntType *get(Context *context, int bitwidth)

Get an integer type. Bitwidth 0 creates a default width int.

class NilType : public chpl::types::Type
#include <NilType.h>

This class represents the type of nil.

Public Functions

~NilType() = default

Public Static Functions

static const NilType *get(Context *context)
class NothingType : public chpl::types::Type
#include <NothingType.h>

This class represents the nothing type.

Public Functions

~NothingType() = default

Public Static Functions

static const NothingType *get(Context *context)
class Param
#include <Param.h>

This is the base class for classes that represent a param value.

Functions like someParam->isUint32Param() / someParam->toUint32Param() are available and generated for all Param subclasses.

Public Functions

virtual ~Param() = 0
inline ParamTag tag() const

Returns the tag indicating which Param subclass this is.

inline bool operator==(const Param &other) const
inline bool operator!=(const Param &other) const
inline void mark(Context *context) const
bool completeMatch(const Param *other) const
void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const

Public Static Functions

template<typename T>
static inline bool update(owned<T> &keep, owned<T> &addin)
static bool isParamOpFoldable(chpl::uast::PrimitiveTag op)
static QualifiedType fold(Context *context, chpl::uast::PrimitiveTag op, QualifiedType a, QualifiedType b)
static uint64_t binStr2uint64(const char *str, size_t len, std::string &err)
static uint64_t octStr2uint64(const char *str, size_t len, std::string &err)
static uint64_t decStr2uint64(const char *str, size_t len, std::string &err)
static int64_t decStr2int64(const char *str, size_t len, std::string &err)
static uint64_t hexStr2uint64(const char *str, size_t len, std::string &err)
static double str2double(const char *str, size_t len, std::string &err)
struct ComplexDouble

Public Functions

inline ComplexDouble(double re, double im)
inline bool operator==(const ComplexDouble &other) const
inline bool operator!=(const ComplexDouble &other) const
inline size_t hash() const

Public Members

double re
double im
struct NoneValue

Public Functions

inline bool operator==(const NoneValue &other) const
inline bool operator!=(const NoneValue &other) const
inline size_t hash() const
class PrimitiveType : public chpl::types::Type
#include <PrimitiveType.h>

This class represents a primitive numeric type (e.g. bool, real(32)) that can have a width.

Subclassed by chpl::types::BoolType, chpl::types::ComplexType, chpl::types::ImagType, chpl::types::IntType, chpl::types::RealType, chpl::types::UintType

Public Functions

~PrimitiveType() = default
virtual int bitwidth() const = 0

Returns the bit width selected for numeric types. Returns 8 for the default sized bool.

virtual const char *c_str() const = 0

Returns a C string for the name of this PrimitiveType.

virtual void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const override

Compute a string representing this type.

Public Static Functions

static const PrimitiveType *getWithNameAndWidth(Context *context, UniqueString name, int bitwidth)

Get the PrimitiveType according to name and bitwidth, or nullptr if the name or bitwidth are invalid.

class QualifiedType
#include <QualifiedType.h>

This class represents a combination of 3 things: a Type subclass pointer representing a Chapel type a Kind representing variable kind or intent (e.g. ref, value, const) a param value for when the Kind is PARAM.

This combination is the type information that the resolver needs.

Public Types

using Kind = uast::IntentList

Public Functions

inline QualifiedType()
inline QualifiedType(Kind kind, const Type *type)
inline QualifiedType(Kind kind, const Type *type, const Param *param)
inline Kind kind() const

Returns the kind of the expression this QualifiedType represents

inline const Type *type() const

Returns the Type subclass that represents the type part of this QualifiedType

inline const Param *param() const

Returns the param value for this QualifiedType. Note that an uninstantiated param formal will have kind() == PARAM but won’t yet have a param value.

inline bool hasTypePtr() const
inline bool hasParamPtr() const
bool isGenericType() const
bool isUnknownType() const
inline bool isGeneric() const
inline bool isUnknown() const
inline bool isGenericOrUnknown() const
inline bool isType() const

Returns true if kind is TYPE

inline bool isParam() const

Returns true if kind is PARAM

inline bool isConst() const

Returns true if the value cannot be modified directly (but might be modified by some other aliasing variable). In particular, returns true for all kinds other than REF and VALUE.

inline bool isImmutable() const

Returns true if the type refers to something immutable (that cannot be modified by any task / other reference to it).

inline bool operator==(const QualifiedType &other) const
inline bool operator!=(const QualifiedType &other) const
inline void swap(QualifiedType &other)
inline size_t hash() const
void mark(Context *context) const
void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const

Public Static Functions

static bool update(QualifiedType &keep, QualifiedType &addin)

Public Static Attributes

static const Kind UNKNOWN = uast::IntentList::UNKNOWN
static const Kind DEFAULT_INTENT = uast::IntentList::DEFAULT_INTENT
static const Kind CONST_INTENT = uast::IntentList::CONST_INTENT
static const Kind VAR = uast::IntentList::VAR
static const Kind CONST_VAR = uast::IntentList::CONST_VAR
static const Kind CONST_REF = uast::IntentList::CONST_REF
static const Kind REF = uast::IntentList::REF
static const Kind IN = uast::IntentList::IN
static const Kind CONST_IN = uast::IntentList::CONST_IN
static const Kind OUT = uast::IntentList::OUT
static const Kind INOUT = uast::IntentList::INOUT
static const Kind PARAM = uast::IntentList::PARAM
static const Kind TYPE = uast::IntentList::TYPE
static const Kind INDEX = uast::IntentList::INDEX
static const Kind FUNCTION = uast::IntentList::FUNCTION
static const Kind MODULE = uast::IntentList::MODULE
class RealType : public chpl::types::PrimitiveType
#include <RealType.h>

This class represents a real type, e.g. real or real(32).

Public Functions

~RealType() = default
inline virtual int bitwidth() const override

Returns the bit width selected for numeric types. Returns 8 for the default sized bool.

inline virtual const char *c_str() const override

Returns a C string for the name of this PrimitiveType.

Public Static Functions

static const RealType *get(Context *context, int bitwidth)
class RecordType : public chpl::types::CompositeType
#include <RecordType.h>

This class represents a record type, e.g., if we have record R, then R refers to a RecordType.

Public Functions

~RecordType() = default
inline const RecordType *instantiatedFrom() const

If this type represents an instantiated type, returns the type it was instantiated from.

This is just instantiatedFromCompositeType() with the result cast to RecordType.

Public Static Functions

static const RecordType *get(Context *context, ID id, UniqueString name, std::vector<CompositeType::FieldDetail> fields, const RecordType *instantiatedFrom)
class StringType : public chpl::types::Type
#include <StringType.h>

This class represents the string type.

Public Functions

~StringType() = default

Public Static Functions

static const StringType *get(Context *context)
class TupleType : public chpl::types::CompositeType
#include <TupleType.h>

This class represents a tuple type e.g. (int, real).

Public Functions

~TupleType() = default
inline const TupleType *instantiatedFrom() const

If this type represents an instantiated type, returns the type it was instantiated from.

This is just instantiatedFromCompositeType() with the result cast to TupleType.

Public Static Functions

static const TupleType *get(Context *context, ID id, UniqueString name, std::vector<CompositeType::FieldDetail> fields, const TupleType *instantiatedFrom)
class Type
#include <Type.h>

This is the base class for classes that represent a type.

Functions like someType->isRecord() / someType->toRecord() are available and generated for all Type subclasses.

Subclassed by chpl::types::AnyType, chpl::types::BuiltinType, chpl::types::BytesType, chpl::types::ClassType, chpl::types::CompositeType, chpl::types::CStringType, chpl::types::ErroneousType, chpl::types::NilType, chpl::types::NothingType, chpl::types::PrimitiveType, chpl::types::StringType, chpl::types::UnknownType, chpl::types::VoidType

Public Functions

virtual bool isGeneric() const = 0

This function needs to be defined by subclasses. It returns ‘true` if the type represents a generic type.

virtual ~Type() = 0
inline TypeTag tag() const

Returns the tag indicating which Type subclass this is.

inline bool operator==(const Type &other) const
inline bool operator!=(const Type &other) const
inline void mark(Context *context) const
bool completeMatch(const Type *other) const
virtual void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const
inline bool isStringLikeType() const

returns true if it’s string, bytes, or c_string type

inline bool isIntegralType() const

returns true if it’s an int or uint type of any width

inline bool isNumericType() const

returns true if it’s a numeric type of any width; that includes int, uint, real, imag, complex

inline bool isNumericOrBoolType() const

returns true if it’s a numeric type or bool type of any width

inline bool isPtrType() const

returns true for a type that is a kind of pointer

bool isNilablePtrType() const

returns true for a pointer type that can store nil

bool isUserRecordType() const

Returns true for a type that is a user-defined record. The compiler treats some internal types as records but the language design does not insist that they are.

const CompositeType *getCompositeType() const

If ‘this’ is a CompositeType, return it. If ‘this’ is a ClassType, return the basicClassType. Otherwise, returns nullptr.

Public Static Functions

template<typename T>
static inline bool update(owned<T> &keep, owned<T> &addin)
static void gatherBuiltins(Context *context, std::unordered_map<UniqueString, const Type*> &map)
class UintType : public chpl::types::PrimitiveType
#include <UintType.h>

This class represents a uint type, e.g. uint or uint(32).

Public Functions

~UintType() = default
inline virtual int bitwidth() const override

Returns the bit width selected for numeric types. Returns 8 for the default sized bool.

inline virtual const char *c_str() const override

Returns a C string for the name of this PrimitiveType.

Public Static Functions

static const UintType *get(Context *context, int bitwidth)
class UnionType : public chpl::types::CompositeType
#include <UnionType.h>

This class represents a union type, e.g., if we have union U, then U refers to a UnionType.

Public Functions

~UnionType() = default
inline const UnionType *instantiatedFrom() const

If this type represents an instantiated type, returns the type it was instantiated from.

This is just instantiatedFromCompositeType() with the result cast to UnionType.

Public Static Functions

static const UnionType *get(Context *context, ID id, UniqueString name, std::vector<CompositeType::FieldDetail> fields, const UnionType *instantiatedFrom)
class UnknownType : public chpl::types::Type
#include <UnknownType.h>

This class represents an unknown type when the type is not known because it is not yet established.

Public Functions

~UnknownType() = default

Public Static Functions

static const UnknownType *get(Context *context)
class VoidType : public chpl::types::Type
#include <VoidType.h>

This class represents the void type.

Public Functions

~VoidType() = default

Public Static Functions

static const VoidType *get(Context *context)
namespace paramtags

Enums

enum ParamTag

This enum is used to identify which union elements a Param stores

Values:

namespace typetags

Enums

enum TypeTag

This enum is used to identify which ASTType subclass a node is.

Values:

enumerator NUM_TYPE_TAGS

Functions

const char *tagToString(TypeTag tag)