module volta.ir.context

Code Map

module volta.ir.context;


enum Status
{
	Success,
	Error,
}

//! A container class for a various things that can be stored in a Scope.
class Store
{
public:
	//! Class specifier.
	enum Kind
	{
		Type,
		Value,
		Scope,
		MultiScope,
		Alias,
		Merge,
		Function,
		Template,
		Reserved,
		FunctionParam,
		EnumDeclaration,
		TemplateInstance,
	}


public:
	name: string;
	parent: Scope;
	kind: Kind;
	node: Node;
	originalNodes: Node[];
	myScope: Scope;
	scopes: Scope[];
	functions: Function[];
	aliases: Alias[];
	templateInstances: TemplateInstance[];
	myAlias: Store;
	importBindAccess: Access;
	importAlias: bool;
	fromImplicitContextChain: bool;


public:
	//! Used for Alias, Value, Type and Scope stores. Not really intended for
	//! general consumption but are instead called from the add members in
	//! Scope.
	this(s: Scope, n: Node, name: string, kind: Kind) { }
	//! Used for functions. Not really intended for general consumption but are
	//! instead called from the addFunction member in Scope.
	this(s: Scope, func: Function, name: string) { }
	//! As above but for multiple functions at once. Internal use only.
	this(s: Scope, func: Function[], name: string) { }
	//! Used for enums. The name will usually be the name of the enum
	//! declaration. Not really intended for general consumption, but called
	//! from the addEnumDeclaration member in Scope.
	this(parent: Scope, ed: EnumDeclaration, name: string) { }
	this(parent: Scope, ti: TemplateInstance) { }
	//! Construct an invalid Store. Used for copying Stores for CTFE, do not
	//! use for anything else.
	this() { }
	//! Retrieve the unique id of this node.
	fn uniqueId() size_t { }
	fn addTemplateInstance(templateInstance: TemplateInstance) { }
	fn markAliasResolved(s: Store) { }
	fn markAliasResolved(t: Type) { }
}

//! A single scope containing declared items and their identifiers.
class Scope
{
public:
	anon: u32;
	name: string;
	node: Node;
	parent: Scope;
	symbols: Store[string];
	multibindScopes: Scope[];
	importedModules: Module[];
	importedAccess: Access[];
	nestedDepth: i32;


public:
	//! For toplevel modules.
	this(m: Module, name: string) { }
	//! For named imports, classes, structs and unions.
	this(parent: Scope, node: Node, name: string, nestedDepth: i32) { }
	//! Create a scope that represents multiple scopes.
	this(scopes: Scope[]) { }
	//! Create an invalid Scope. Internal use only.
	this() { }
	fn remove(name: string) { }
	fn genAnonIdent() string { }
	//! Reserve a identifier in this scope.
	fn reserveId(n: Node, name: string) Store { }
	//! Add an unresolved Alias to this scope. The scope that the alias is
	//! resolved to is defaulted to this scope, but this can be changed with
	//! the look argument, used by import rebinds.
	fn addAlias(n: Alias, name: string, status: Status) Store { }
	//! Add a named scope, @n is the node which introduced this scope, must not
	//! be null.
	fn addScope(n: Node, s: Scope, name: string, status: Status) Store { }
	//! Add a named multiscope, n is the node which introduced this scope and
	//! must not be null.
	fn addMultiScope(n: Node, s: Scope[], name: string, status: Status) Store { }
	//! Add a user defined type.
	fn addType(n: Node, name: string, status: Status) Store { }
	//! Add a value like a constant or a function variable.
	fn addValue(n: Node, name: string, status: Status) Store { }
	//! Add a function to this scope, will append function if one of declared
	//! function of the same name is found.
	fn addFunction(func: Function, name: string, status: Status) Store { }
	//! Add a user defined template.
	fn addTemplate(n: Node, name: string, status: Status) Store { }
	//! Add a template instance to the scope.
	fn addTemplateInstance(ti: TemplateInstance, status: Status) Store { }
	//! Add a named expression to the scope.
	fn addEnumDeclaration(e: EnumDeclaration, status: Status) Store { }
	//! Doesn't look in parent scopes, just this Store.
	fn getStore(name: string) Store { }
	//! Get all Variables in the Scope the have Nested storage.
	fn getNestedDeclarations() Declaration[] { }
}

A container class for a various things that can be stored in a Scope.

If kind is Value, node is a Variable. If it's Type, the node is a Type. Scope means s is a named scope, and node contains the node that introduced the scope. Functions means that functions contain an overload set of a function. An Expression Store contains a delegate that generates a new expression in place of the lookup.

Note: not a node.

enum Kind

Class specifier.

fn uniqueId() size_t

Retrieve the unique id of this node.

this(s: Scope, n: Node, name: string, kind: Kind)

Used for Alias, Value, Type and Scope stores. Not really intended for general consumption but are instead called from the add members in Scope.

this(s: Scope, func: Function, name: string)

Used for functions. Not really intended for general consumption but are instead called from the addFunction member in Scope.

this(s: Scope, func: Function[], name: string)

As above but for multiple functions at once. Internal use only.

this(parent: Scope, ed: EnumDeclaration, name: string)

Used for enums. The name will usually be the name of the enum declaration. Not really intended for general consumption, but called from the addEnumDeclaration member in Scope.

this()

Construct an invalid Store. Used for copying Stores for CTFE, do not use for anything else.

A single scope containing declared items and their identifiers.

See store for what can be held in a scope. These things are associated with a string. Scopes have parent Scopes, but these don't affect getStores lookup -- write a look up function for your specific needs.

Structs, Classes, Interfaces, Functions, and Modules all have scopes.

Note: not a node.

this(m: Module, name: string)

For toplevel modules.

Side-effects: None.

this(parent: Scope, node: Node, name: string, nestedDepth: i32)

For named imports, classes, structs and unions.

Side-effects: None.

this(scopes: Scope[])

Create a scope that represents multiple scopes.

Used in multibind imports, by the lookup code.

this()

Create an invalid Scope. Internal use only.

fn reserveId(n: Node, name: string) Store

Reserve a identifier in this scope.

Returns: null, if an identifier couldn't be reserved.

fn addAlias(n: Alias, name: string, status: Status) Store

Add an unresolved Alias to this scope. The scope that the alias is resolved to is defaulted to this scope, but this can be changed with the look argument, used by import rebinds.

Side-effects: None.

fn addScope(n: Node, s: Scope, name: string, status: Status) Store

Add a named scope, @n is the node which introduced this scope, must not be null.

Side-effects: None.

fn addMultiScope(n: Node, s: Scope[], name: string, status: Status) Store

Add a named multiscope, n is the node which introduced this scope and must not be null.

fn addType(n: Node, name: string, status: Status) Store

Add a user defined type.

Side-effects: None.

fn addValue(n: Node, name: string, status: Status) Store

Add a value like a constant or a function variable.

Side-effects: None.

fn addFunction(func: Function, name: string, status: Status) Store

Add a function to this scope, will append function if one of declared function of the same name is found.

Throws: CompilerPanic if a non-function of the same name is found.

Side-effects: None.

fn addTemplate(n: Node, name: string, status: Status) Store

Add a user defined template.

Side-effects: None.

fn addTemplateInstance(ti: TemplateInstance, status: Status) Store

Add a template instance to the scope.

fn addEnumDeclaration(e: EnumDeclaration, status: Status) Store

Add a named expression to the scope.

Side-effects: None.

fn getStore(name: string) Store

Doesn't look in parent scopes, just this Store.

Returns: the Store found, store pointed to by alias, or null on lookup failure.

Side-effects: None.

fn getNestedDeclarations() Declaration[]

Get all Variables in the Scope the have Nested storage.