module volta.ir.declaration

Code Map

module volta.ir.declaration;


//! Base class for all declarations.
class Declaration : Node
{
public:
	enum Kind
	{
		Invalid,
		Function,
		Variable,
		EnumDeclaration,
		FunctionSet,
		FunctionParam,
	}


public:
	annotations: Attribute[];


public:
	this(nt: NodeType) { }
	this(nt: NodeType, old: Declaration) { }
	fn declKind() Kind { }
}

//! Represents an instance of a type.
class Variable : Declaration
{
public:
	enum Storage
	{
		Invalid,
		//! Member of a struct/class.
		Field,
		//! Variable in a function.
		Function,
		//! Accessed in a nested function.
		Nested,
		//! Stored in TLS.
		Local,
		//! Stored in the global data segment.
		Global,
	}


public:
	isResolved: bool;
	access: Access;
	type: Type;
	name: string;
	mangledName: string;
	assign: Exp;
	storage: Storage;
	linkage: Linkage;
	isMergable: bool;
	//! Only for global variables.
	isExtern: bool;
	//! The type will be a ref storage type if this is set.
	isOut: bool;
	//! Has this variable been declared yet? (only useful in extyper)
	hasBeenDeclared: bool;
	useBaseStorage: bool;
	specialInitValue: bool;
	noInitialise: bool;


public:
	this() { }
	//! Construct a Variable with a given type and name.
	this(t: Type, name: string) { }
	this(old: Variable) { }


public:
	static fn storageToString(s: Storage) string { }
}

//! An Alias associates names with a Type. Once declared, using that name
//! is as using that Type directly.
class Alias : Node
{
public:
	isResolved: bool;
	access: Access;
	name: string;
	//! Non null type.
	externAttr: Attribute;
	type: Type;
	id: QualifiedName;
	staticIf: AliasStaticIf;
	//! Where are we looking for the symbol.
	lookScope: Scope;
	//! Where are we looking for the symbol.
	lookModule: Module;
	store: Store;
	//! Not with id. Optional.
	templateInstance: Exp;


public:
	this() { }
	this(old: Alias) { }
}

//! A function is a block of code that takes parameters, and may return a
//! value. There may be additional implied context, depending on where it's
//! defined.
class Function : Declaration
{
public:
	//! Used to specify function type.
	enum Kind
	{
		Invalid,
		//! foo()
		Function,
		//! this.foo()
		Member,
		//! Clazz.foo()
		LocalMember,
		//! Clazz.foo()
		GlobalMember,
		//! auto foo = new Clazz()
		Constructor,
		//! delete foo
		Destructor,
		//! local this() {}
		LocalConstructor,
		//! local ~this() {}
		LocalDestructor,
		//! global this() {}
		GlobalConstructor,
		//! global ~this() {}
		GlobalDestructor,
		//! void aFunction() { void foo() {} }
		Nested,
		//! void aFunction() { global void foo() {} }
		GlobalNested,
	}


public:
	isResolved: bool;
	isActualized: bool;
	access: Access;
	//! Needed for params
	myScope: Scope;
	//! What kind of function.
	kind: Kind;
	//! Prototype.
	type: FunctionType;
	params: FunctionParam[];
	nestedFunctions: Function[];
	//! The various scope (exit/success/failures) turned into inline
	//! functions.
	scopeSuccesses: Function[];
	//! The various scope (exit/success/failures) turned into inline
	//! functions.
	scopeExits: Function[];
	//! The various scope (exit/success/failures) turned into inline
	//! functions.
	scopeFailures: Function[];
	//! Pre mangling.
	name: string;
	mangledName: string;
	outParameter: string;
	//! Optional in contract.
	parsedIn: BlockStatement;
	//! Optional out contract.
	parsedOut: BlockStatement;
	//! Optional body.
	parsedBody: BlockStatement;
	//! Optional lazy parsed in contract.
	tokensIn: Token[];
	//! Optional lazy parsed out contract.
	tokensOut: Token[];
	//! Optional lazy parsed body.
	tokensBody: Token[];
	thisHiddenParameter: Variable;
	nestedHiddenParameter: Variable;
	nestedVariable: Variable;
	composableSinkVariable: Variable;
	nestStruct: Struct;
	isMergable: bool;
	//! If this is a member function, where in the vtable does it live?
	vtableIndex: i32;
	loadDynamic: bool;
	isMarkedOverride: bool;
	isOverridingInterface: bool;
	isAbstract: bool;
	isFinal: bool;
	isAutoReturn: bool;
	//! Is this a function a lowered construct, like scope.
	isLoweredScopeExit: bool;
	//! Is this a function a lowered construct, like scope.
	isLoweredScopeFailure: bool;
	//! Is this a function a lowered construct, like scope.
	isLoweredScopeSuccess: bool;
	templateName: string;
	templateType: Type;


public:
	this() { }
	this(old: Function) { }
	fn hasBody() bool { }
	fn hasInContract() bool { }
	fn hasOutContract() bool { }
}

class EnumDeclaration : Declaration
{
public:
	type: Type;
	assign: Exp;
	name: string;
	prevEnum: EnumDeclaration;
	resolved: bool;
	access: Access;
	isStandalone: bool;


public:
	this() { }
	this(old: EnumDeclaration) { }
}

//! Represents multiple functions associated with a single name.
class FunctionSet : Declaration
{
public:
	functions: Function[];
	//! For assigning an overloaded function to a delegate.
	reference: ExpReference;


public:
	this() { }
	this(old: FunctionSet) { }
	fn type() FunctionSetType { }
	//! Update reference to indicate function set has been resolved. Returns
	//! the function passed to it.
	fn resolved(func: Function) Function { }
}

//! Represents a parameter to a function.
class FunctionParam : Declaration
{
public:
	func: Function;
	index: size_t;
	assign: Exp;
	name: string;
	//! Has this parameter been nested into a nested context struct?
	hasBeenNested: bool;


public:
	this() { }
	this(old: FunctionParam) { }
	fn type() Type { }
}
class Declaration : Node

Base class for all declarations.

class Variable : Declaration

Represents an instance of a type.

A Variable has a type and a single name that is an instance of that type. It may also have an expression that represents a value to assign to it.

Variables are mangled as type + parent names + name.

isExtern: bool

Only for global variables.

isOut: bool

The type will be a ref storage type if this is set.

hasBeenDeclared: bool

Has this variable been declared yet? (only useful in extyper)

this(t: Type, name: string)

Construct a Variable with a given type and name.

class Alias : Node

An Alias associates names with a Type. Once declared, using that name is as using that Type directly.

externAttr: Attribute

Non null type.

lookScope: Scope

Where are we looking for the symbol.

lookModule: Module

Where are we looking for the symbol.

templateInstance: Exp

Not with id. Optional.

class Function : Declaration

A function is a block of code that takes parameters, and may return a value. There may be additional implied context, depending on where it's defined.

Functions are mangled as type + parent names + name.

enum Kind

Used to specify function type.

Some types have hidden arguments, like the this argument for member functions, constructors and destructors.

enum Function

foo()

enum Member

this.foo()

enum LocalMember

Clazz.foo()

enum GlobalMember

Clazz.foo()

enum Constructor

auto foo = new Clazz()

enum Destructor

delete foo

enum LocalConstructor

local this() {}

enum LocalDestructor

local ~this() {}

enum GlobalConstructor

global this() {}

enum GlobalDestructor

global ~this() {}

enum Nested

void aFunction() { void foo() {} }

enum GlobalNested

void aFunction() { global void foo() {} }

myScope: Scope

Needed for params

kind: Kind

What kind of function.

type: FunctionType

Prototype.

scopeSuccesses: Function[]

The various scope (exit/success/failures) turned into inline functions.

scopeExits: Function[]

The various scope (exit/success/failures) turned into inline functions.

scopeFailures: Function[]

The various scope (exit/success/failures) turned into inline functions.

name: string

Pre mangling.

parsedIn: BlockStatement

Optional in contract.

parsedOut: BlockStatement

Optional out contract.

parsedBody: BlockStatement

Optional body.

tokensIn: Token[]

Optional lazy parsed in contract.

tokensOut: Token[]

Optional lazy parsed out contract.

tokensBody: Token[]

Optional lazy parsed body.

vtableIndex: i32

If this is a member function, where in the vtable does it live?

isLoweredScopeExit: bool

Is this a function a lowered construct, like scope.

isLoweredScopeFailure: bool

Is this a function a lowered construct, like scope.

isLoweredScopeSuccess: bool

Is this a function a lowered construct, like scope.

class FunctionSet : Declaration

Represents multiple functions associated with a single name.

Contains the ExpReference that this set is associated with so that it can be transparently updated to point at the selected function.

reference: ExpReference

For assigning an overloaded function to a delegate.

fn resolved(func: Function) Function

Update reference to indicate function set has been resolved. Returns the function passed to it.

class FunctionParam : Declaration

Represents a parameter to a function.

Indirectly references the type which is on the Callable, and just contains the metadata parameters have (name, assign. etc).

hasBeenNested: bool

Has this parameter been nested into a nested context struct?