Xreate
The Xreate programming language
Functions
xreate::typeinference Namespace Reference

Type inference support. More...

Functions

llvm::Value * doAutomaticTypeConversion (llvm::Value *source, llvm::Type *tyTarget, llvm::IRBuilder<> &builder)
 Casts the given variable to the given type. More...
 
ExpandedType getType (const Expression &expression, const AST &ast)
 Performs basic type inference to deduce the type of the given expression. More...
 

Detailed Description

Type inference support.

Function Documentation

◆ doAutomaticTypeConversion()

llvm::Value * doAutomaticTypeConversion ( llvm::Value *  source,
llvm::Type *  tyTarget,
llvm::IRBuilder<> &  builder 
)

Casts the given variable to the given type.

Parameters
sourceThe variable that needs casting
tyTargetThe type to cast to
builderInstance of llvm's IRBuilder

◆ getType()

ExpandedType getType ( const Expression expression,
const AST ast 
)

Performs basic type inference to deduce the type of the given expression.

Tries several strategies in the following order:

  • Looks at expression's type if it has one.
  • Looks at Attachment<TypeInferred> if it has one. This allows assign expression's type by analyses done elsewhere.
  • For a number literal assumes i32.
Parameters
expressionInfers the given expression's type.
astAST instance.