Class GenericType

Inheritance Relationships

Base Type

Class Documentation

class seq::types::GenericType : public seq::types::Type

A generic type simply delegates all of its functionality to some other type, which is determined later during type resolution. However, this class is also reused for two other purposes:

  • Realized generic types like A[int]: Realization is deferred until absolutely necessary by this class.

  • typeof expressions: This class can hold an expression object whose type will not be checked until (again) absolutely necessary.

This deferral allows some type-checking corner-cases to work properly.

Public Functions

GenericType()
GenericType(RefType *pending, std::vector<Type*> types, Expr *expr)
void setName(std::string name)
void realize(Type *type)
void realize() const
bool realized() const
void ensure() const
Type *getType() const
int getID() const override

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

std::string getName() const override

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

Type *getParent() const override

Returns this type’s parent type.

bool isAbstract() const override

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

VTable &getVTable() override

Returns a reference to this type’s VTable.

bool isAtomic() const override

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.

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

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

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

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

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

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

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

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

Return

type of the member

Parameters
  • name: name of the member

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

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) override

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) override

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) override

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

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

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

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

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

llvm::Value *defaultValue(llvm::BasicBlock *block) override

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

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

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

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

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

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

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() override

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

void initFields() override

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

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

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

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

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

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

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

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

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 override

Checks whether this type “is” another type.

bool isGeneric(Type *type) const override

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

unsigned numBaseTypes() const override

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.

Type *getBaseType(unsigned idx) const override

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

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

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

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

Returns the LLVM type corresponding to this type.

size_t size(llvm::Module *module) const override

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

RecordType *asRec() override

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.

RefType *asRef() override

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.

GenType *asGen() override

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.

OptionalType *asOpt() override

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.

KMer *asKMer() override

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.

GenericType *clone(Generic *ref) override

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

bool findInType(types::Type *type, std::vector<unsigned> &path, bool unwrapOptionals)

Public Static Functions

GenericType *get()
GenericType *get(RefType *pending, std::vector<Type*> types)
GenericType *get(Expr *expr)