Class Type

Inheritance Relationships

Derived Types

Class Documentation

class Type

The class from which all Seq “types” derive

Subclassed by seq::types::AnyType, seq::types::ArrayType, seq::types::BaseSeqType, seq::types::BaseType, seq::types::BoolType, seq::types::ByteType, seq::types::FloatType, seq::types::FuncType, seq::types::GenericType, seq::types::GenType, seq::types::IntNType, seq::types::IntType, seq::types::KMer, seq::types::NumberType, seq::types::OptionalType, seq::types::PartialFuncType, seq::types::PtrType, seq::types::RecordType, seq::types::RefType, seq::types::VoidType

Public Functions

Type(std::string name, Type *parent, bool abstract = false, bool extendable = false)

Base type constructor

Parameters
  • name: base name of this type

  • parent: parent type

  • abstract: whether this type can be instantiated

  • extendable: whether this type can be extended via an extend statement

int getID() const

Returns a unique identifier for this type, based on getName().

std::string getName() const

Returns the full name (e.g. array[int], Foo[str,bool]) of this type.

types::Type *getParent() const

Returns this type’s parent type.

bool isAbstract() const

Returns whether this type is abstract (i.e. cannot be instantiated).

types::VTable &getVTable()

Returns a reference to this type’s VTable.

bool isAtomic() const

Returns whether this type is “atomic”. A type is defined to be atomic if its LLVM representation contains no pointers to heap allocated data. This is used internally by the GC, as we can allocate “atomic” and “non-atomic” blocks separately. Atomic blocks do not need to be scanned when searching for pointers.

Value *alloc(llvm::Value *count, llvm::BasicBlock *block)

Codegen’s an allocation.

Return

value representing pointer returned from allocation

Parameters
  • count: how many units of this type to allocate

  • block: where to codegen this allocation

Value *call(BaseFunc *base, llvm::Value *self, const std::vector<llvm::Value *> &args, llvm::BasicBlock *block, llvm::BasicBlock *normal, llvm::BasicBlock *unwind)

Calls this type. Usually a call to this method should be preceded by a call to getCallType() to validate types and determine the output type.

Return

value resulting from call

Parameters
  • base: the function containing block

  • self: a value of this type

  • args: vector of argument values

  • block: where to codegen this call in

  • normal: if in a try, block to branch to if call succeeds, or null otherwise

  • unwind: if in a try, block to branch to if call raises an exception, or null otherwise

Value *memb(llvm::Value *self, const std::string &name, llvm::BasicBlock *block)

Extract a given member (field or method) from this type.

Return

member value

Parameters
  • self: a value of this type

  • name: name of the member

  • block: where to codegen the member

types::Type *membType(const std::string &name)

Return the type of a given member (field or method) of this type.

Return

type of the member

Parameters
  • name: name of the member

Value *setMemb(llvm::Value *self, const std::string &name, llvm::Value *val, llvm::BasicBlock *block)

Sets the specified member of this type.

Return

value (possibly self) containing new member

Parameters
  • self: a value of this type

  • name: name of the member

  • val: value to assign to member

  • block: where to codegen the assignment

bool hasMethod(const std::string &name)

Checks whether type has specified (possibly magic) method.

Return

whether this type has the specified method

Parameters
  • name: name of the method

void addMethod(std::string name, BaseFunc *func, bool force)

Adds a specified (possibly magic) method to this type.

Parameters
  • name: name of the method

  • func: method to add

  • force: error on duplicate method names if false override existing same-name method if true

BaseFunc *getMethod(const std::string &name)

Returns the specified (non-magic) method of this type. Throws an exception if the specified method does not exist.

Return

BaseFunc representing the specified method

Parameters
  • name: name of the method

Value *staticMemb(const std::string &name, llvm::BasicBlock *block)

Returns the specified static member (usually a method) of this type. This works for both regular and magic methods.

Return

member value

Parameters
  • name: name of the member

  • block: where to codegen the member

types::Type *staticMembType(const std::string &name)

Returns the type of the specified static member (usually a method). This works for both regular and magic methods.

Return

type of the member

Parameters
  • name: name of the member

Value *defaultValue(llvm::BasicBlock *block)

Codegens the default value of this type. Usually this is just what you’d expect: zero for integral types, null for pointer and reference types, recursively defined for aggregate types.

Return

value of the default value

Parameters
  • block: where to codegen the default value

Value *boolValue(llvm::Value *self, llvm::BasicBlock *&block, TryCatch *tc)

Convenience method for calling type.__bool__.

Return

bool value of this type

Parameters
  • self: value of this type

  • block: where to codegen the bool value

  • tc: enclosing try-catch statement, or null if none

Value *strValue(llvm::Value *self, llvm::BasicBlock *&block, TryCatch *tc)

Convenience method for calling type.__str__.

Return

str value of this type

Parameters
  • self: value of this type

  • block: where to codegen the str value

  • tc: enclosing try-catch statement, or null if none

Value *lenValue(llvm::Value *self, llvm::BasicBlock *&block, TryCatch *tc)

Convenience method for calling type.__len__.

Return

len value of this type

Parameters
  • self: value of this type

  • block: where to codegen the len value

  • tc: enclosing try-catch statement, or null if none

void initOps()

Performs a one-time initialization of this type’s methods, including magic methods.

void initFields()

Performs a one-time initialization of this type’s fields.

types::Type *magicOut(const std::string &name, std::vector<Type *> args, bool nullOnMissing = false, bool overloadsOnly = false)

Returns the output type of the specified magic method with specified argument types. Throws an exception if the specified magic method does not exist by default.

Return

output type of specified magic method

Parameters
  • name: full magic method name

  • args: vector of argument types (excluding ‘self’); last element being null indicates static.

  • nullOnMissing: return null instead of throwing an exception if magic is missing

Value *callMagic(const std::string &name, std::vector<Type *> argTypes, llvm::Value *self, std::vector<llvm::Value *> args, llvm::BasicBlock *&block, TryCatch *tc)

Codegens a call to the specified magic method. Throws an exception if the specified magic method does not exist.

Return

result of calling the magic method

Parameters
  • name: full magic method name

  • argTypes: vector of argument types (exclusing self)

  • self: value of this type; null if magic is static

  • args: vector of argument values (same size as argTypes)

  • block: where to codegen the call

  • tc: enclosing try-catch statement, or null if none

types::Type *initOut(std::vector<Type *> &args, std::vector<std::string> names, bool nullOnMissing = false, Func **initFunc = nullptr)

Returns the output type of the “__init__” magic method with specified argument types/names. Throws an exception if the “__init__” magic method does not exist for specified types/names by default. If initFunc is specified, always returns null but stores the found init function in that pointer and sets args to the fixed argument types based on names.

Return

output type of “__init__” magic method

Parameters
  • args: vector of argument types (excluding ‘self’); last element being null indicates static.

  • names: vector of argument names (same size as args)

  • nullOnMissing: return null instead of throwing an exception if magic is missing

  • initFunc: will store resulting init function if non-null

Value *callInit(std::vector<Type *> argTypes, std::vector<std::string> names, llvm::Value *self, std::vector<llvm::Value *> args, llvm::BasicBlock *&block, TryCatch *tc)

Codegens a call to the “__init__” magic method. Throws an exception if the “__init__” magic method does not exist for specified names/argument types.

Return

result of calling the “__init__” magic method

Parameters
  • argTypes: vector of argument types (exclusing self)

  • names: vector of argument names (same size as argTypes)

  • self: value of this type; null if magic is static

  • args: vector of argument values (same size as argTypes)

  • block: where to codegen the call

  • tc: enclosing try-catch statement, or null if none

bool is(Type *type) const

Checks whether this type “is” another type.

bool isGeneric(Type *type) const

Checks whether this type “is” another type, excluding base types. E.g., array[int].is(array[float]) would return true.

unsigned numBaseTypes() const

Returns the number of “base types” of this type. E.g., int.numBaseTypes() would return 0, whereas array[str].numBaseTypes() would return 1, and (int,float,str).numBaseTypes() would return 3.

types::Type *getBaseType(unsigned idx) const

Obtain the base type at index idx. idx should be less than numBaseTypes().

types::Type *getCallType(const std::vector<Type *> &inTypes)

Returns the result of calling this type with the given argument types.

Type *getLLVMType(llvm::LLVMContext &context) const

Returns the LLVM type corresponding to this type.

size_t size(llvm::Module *module) const

Returns the size (in bytes) of the LLVM type corresponding to this type.

types::RecordType *asRec()

Returns this type as a record type, or null if it isn’t a record type. This is basically for overriding C++’s RTTI/dynamic_cast so that generic types can be converted to their actual types.

types::RefType *asRef()

Returns this type as a reference type, or null if it isn’t a reference type. This is basically for overriding C++’s RTTI/dynamic_cast so that generic types can be converted to their actual types.

types::GenType *asGen()

Returns this type as a generator type, or null if it isn’t a generator type. This is basically for overriding C++’s RTTI/dynamic_cast so that generic types can be converted to their actual types.

types::OptionalType *asOpt()

Returns this type as an optional type, or null if it isn’t an optional type. This is basically for overriding C++’s RTTI/dynamic_cast so that generic types can be converted to their actual types.

types::KMer *asKMer()

Returns this type as a k-mer type, or null if it isn’t a k-mer type. This is basically for overriding C++’s RTTI/dynamic_cast so that generic types can be converted to their actual types.

types::Type *clone(Generic *ref)

Clones this type and all of its methods. ref is used internally to keep track of cloned objects, and to make sure we don’t clone certain objects twice.

Return

cloned type

Parameters
  • ref: generic object that is being cloned

Protected Attributes

std::string name

Type base name.

Type *parent

Parent type, or null if there is none.

bool abstract

Whether this type is abstract (e.g. void)

bool extendable

Whether this type can be extended via extend

VTable vtable

Fields and methods for this type.