General factory to build semantic nodes in the AST of expressions

Introduced properties

private var _anchor: nullable MClassType

nitc :: ASTBuilder :: _anchor

The anchor used for some mechanism relying on types
private var _mmodule: MModule

nitc :: ASTBuilder :: _mmodule

The module used as reference for the building
fun anchor: nullable MClassType

nitc :: ASTBuilder :: anchor

The anchor used for some mechanism relying on types
protected fun anchor=(anchor: nullable MClassType)

nitc :: ASTBuilder :: anchor=

The anchor used for some mechanism relying on types
fun check_mmodule(mmodule: MModule)

nitc :: ASTBuilder :: check_mmodule

Check mmodule to avoid a new instantiation of ASTBuilder
fun create_callsite(modelbuilder: ModelBuilder, caller_property: APropdef, mproperty: MMethod, is_self_call: Bool): CallSite

nitc :: ASTBuilder :: create_callsite

Build a callsite to call the mproperty in the current method caller_method.
init defaultinit(mmodule: MModule, anchor: nullable MClassType)

nitc :: ASTBuilder :: defaultinit

fun make_and(right_expr: AExpr, left_expr: AExpr): AAndExpr

nitc :: ASTBuilder :: make_and

Make a new and with two expr
fun make_assert(n_id: nullable TId, n_expr: AExpr, n_else: nullable AExpr): AAssertExpr

nitc :: ASTBuilder :: make_assert

Make a new assert
fun make_attr_assign(recv: AExpr, attribute: MAttribute, value: AExpr): AAttrAssignExpr

nitc :: ASTBuilder :: make_attr_assign

Make a new attribute assignment
fun make_attr_read(recv: AExpr, attribute: MAttribute): AAttrExpr

nitc :: ASTBuilder :: make_attr_read

Make a new attribute read
fun make_attribute(name: String, n_type: nullable AType, n_visibility: nullable AVisibility, initial_value: nullable AExpr, n_block: nullable AExpr, m_attributedef: nullable MAttributeDef, m_setterdef: nullable MMethodDef, m_getterdef: nullable MMethodDef): AAttrPropdef

nitc :: ASTBuilder :: make_attribute

Make a new attribute
fun make_block: ABlockExpr

nitc :: ASTBuilder :: make_block

Make a new, empty, sequence of statements
fun make_break(escapemark: EscapeMark): ABreakExpr

nitc :: ASTBuilder :: make_break

Make a new break for a given escapemark
fun make_call(recv: AExpr, callsite: CallSite, args: nullable Array[AExpr]): ACallExpr

nitc :: ASTBuilder :: make_call

Make a new message send
fun make_call_assign(recv: AExpr, callsite: CallSite, n_args: nullable Collection[AExpr], n_value: AExpr): ACallAssignExpr

nitc :: ASTBuilder :: make_call_assign

Make a call assignment i.e a = 10
fun make_class(mclassdef: nullable MClassDef, n_visibility: nullable AVisibility, n_formaldefs: Collection[AFormaldef], n_extern_code_block: nullable AExternCodeBlock, n_propdefs: Collection[APropdef], n_classkind: nullable AClasskind): AStdClassdef

nitc :: ASTBuilder :: make_class

Make a new class (AStdClassdef)
fun make_do: ADoExpr

nitc :: ASTBuilder :: make_do

Make a new escapable block
fun make_if(condition: AExpr, mtype: nullable MType): AIfExpr

nitc :: ASTBuilder :: make_if

Make a new conditional
fun make_int(value: Int): AIntegerExpr

nitc :: ASTBuilder :: make_int

Make a new Int literal
fun make_loop: ALoopExpr

nitc :: ASTBuilder :: make_loop

Make a new, empty, loop of statements
fun make_method(n_visibility: nullable AVisibility, tk_redef: nullable TKwredef, mmethoddef: nullable MMethodDef, n_signature: nullable ASignature, n_annotations: nullable AAnnotations, n_extern_calls: nullable AExternCalls, n_extern_code_block: nullable AExternCodeBlock, n_block: nullable AExpr): AMethPropdef

nitc :: ASTBuilder :: make_method

Make a new method
fun make_new(callsite: CallSite, args: nullable Array[AExpr]): ANewExpr

nitc :: ASTBuilder :: make_new

Make a new instantiation
fun make_not(expr: AExpr): ANotExpr

nitc :: ASTBuilder :: make_not

Make a new not
fun make_or(right_expr: AExpr, left_expr: AExpr): AOrExpr

nitc :: ASTBuilder :: make_or

Make a new or with two expr
fun make_parenthesis(expr: AExpr, annotations: nullable AAnnotations): AParExpr

nitc :: ASTBuilder :: make_parenthesis

Make a new parenthesis expr
fun make_return(expr: nullable AExpr): AReturnExpr

nitc :: ASTBuilder :: make_return

Make a new return
fun make_super_call(args: nullable Array[AExpr], n_qualified: nullable AQualified): ASuperExpr

nitc :: ASTBuilder :: make_super_call

Make a new message super
fun make_var(variable: Variable, mtype: MType): AVarExpr

nitc :: ASTBuilder :: make_var

fun make_var_assign(variable: Variable, value: AExpr): AVarAssignExpr

nitc :: ASTBuilder :: make_var_assign

Make a new variable assignment
fun make_var_read(variable: Variable, mtype: MType): AVarExpr

nitc :: ASTBuilder :: make_var_read

Make a new variable read
fun mmodule: MModule

nitc :: ASTBuilder :: mmodule

The module used as reference for the building
protected fun mmodule=(mmodule: MModule)

nitc :: ASTBuilder :: mmodule=

The module used as reference for the building

Redefined properties

redef type SELF: ASTBuilder

nitc $ ASTBuilder :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _anchor: nullable MClassType

nitc :: ASTBuilder :: _anchor

The anchor used for some mechanism relying on types
private var _mmodule: MModule

nitc :: ASTBuilder :: _mmodule

The module used as reference for the building
fun anchor: nullable MClassType

nitc :: ASTBuilder :: anchor

The anchor used for some mechanism relying on types
protected fun anchor=(anchor: nullable MClassType)

nitc :: ASTBuilder :: anchor=

The anchor used for some mechanism relying on types
fun check_mmodule(mmodule: MModule)

nitc :: ASTBuilder :: check_mmodule

Check mmodule to avoid a new instantiation of ASTBuilder
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun create_callsite(modelbuilder: ModelBuilder, caller_property: APropdef, mproperty: MMethod, is_self_call: Bool): CallSite

nitc :: ASTBuilder :: create_callsite

Build a callsite to call the mproperty in the current method caller_method.
init defaultinit(mmodule: MModule, anchor: nullable MClassType)

nitc :: ASTBuilder :: defaultinit

fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun make_and(right_expr: AExpr, left_expr: AExpr): AAndExpr

nitc :: ASTBuilder :: make_and

Make a new and with two expr
fun make_assert(n_id: nullable TId, n_expr: AExpr, n_else: nullable AExpr): AAssertExpr

nitc :: ASTBuilder :: make_assert

Make a new assert
fun make_attr_assign(recv: AExpr, attribute: MAttribute, value: AExpr): AAttrAssignExpr

nitc :: ASTBuilder :: make_attr_assign

Make a new attribute assignment
fun make_attr_read(recv: AExpr, attribute: MAttribute): AAttrExpr

nitc :: ASTBuilder :: make_attr_read

Make a new attribute read
fun make_attribute(name: String, n_type: nullable AType, n_visibility: nullable AVisibility, initial_value: nullable AExpr, n_block: nullable AExpr, m_attributedef: nullable MAttributeDef, m_setterdef: nullable MMethodDef, m_getterdef: nullable MMethodDef): AAttrPropdef

nitc :: ASTBuilder :: make_attribute

Make a new attribute
fun make_block: ABlockExpr

nitc :: ASTBuilder :: make_block

Make a new, empty, sequence of statements
fun make_break(escapemark: EscapeMark): ABreakExpr

nitc :: ASTBuilder :: make_break

Make a new break for a given escapemark
fun make_call(recv: AExpr, callsite: CallSite, args: nullable Array[AExpr]): ACallExpr

nitc :: ASTBuilder :: make_call

Make a new message send
fun make_call_assign(recv: AExpr, callsite: CallSite, n_args: nullable Collection[AExpr], n_value: AExpr): ACallAssignExpr

nitc :: ASTBuilder :: make_call_assign

Make a call assignment i.e a = 10
fun make_class(mclassdef: nullable MClassDef, n_visibility: nullable AVisibility, n_formaldefs: Collection[AFormaldef], n_extern_code_block: nullable AExternCodeBlock, n_propdefs: Collection[APropdef], n_classkind: nullable AClasskind): AStdClassdef

nitc :: ASTBuilder :: make_class

Make a new class (AStdClassdef)
fun make_do: ADoExpr

nitc :: ASTBuilder :: make_do

Make a new escapable block
fun make_if(condition: AExpr, mtype: nullable MType): AIfExpr

nitc :: ASTBuilder :: make_if

Make a new conditional
fun make_int(value: Int): AIntegerExpr

nitc :: ASTBuilder :: make_int

Make a new Int literal
fun make_loop: ALoopExpr

nitc :: ASTBuilder :: make_loop

Make a new, empty, loop of statements
fun make_method(n_visibility: nullable AVisibility, tk_redef: nullable TKwredef, mmethoddef: nullable MMethodDef, n_signature: nullable ASignature, n_annotations: nullable AAnnotations, n_extern_calls: nullable AExternCalls, n_extern_code_block: nullable AExternCodeBlock, n_block: nullable AExpr): AMethPropdef

nitc :: ASTBuilder :: make_method

Make a new method
fun make_new(callsite: CallSite, args: nullable Array[AExpr]): ANewExpr

nitc :: ASTBuilder :: make_new

Make a new instantiation
fun make_not(expr: AExpr): ANotExpr

nitc :: ASTBuilder :: make_not

Make a new not
fun make_or(right_expr: AExpr, left_expr: AExpr): AOrExpr

nitc :: ASTBuilder :: make_or

Make a new or with two expr
fun make_parenthesis(expr: AExpr, annotations: nullable AAnnotations): AParExpr

nitc :: ASTBuilder :: make_parenthesis

Make a new parenthesis expr
fun make_return(expr: nullable AExpr): AReturnExpr

nitc :: ASTBuilder :: make_return

Make a new return
fun make_super_call(args: nullable Array[AExpr], n_qualified: nullable AQualified): ASuperExpr

nitc :: ASTBuilder :: make_super_call

Make a new message super
fun make_var(variable: Variable, mtype: MType): AVarExpr

nitc :: ASTBuilder :: make_var

fun make_var_assign(variable: Variable, value: AExpr): AVarAssignExpr

nitc :: ASTBuilder :: make_var_assign

Make a new variable assignment
fun make_var_read(variable: Variable, mtype: MType): AVarExpr

nitc :: ASTBuilder :: make_var_read

Make a new variable read
fun mmodule: MModule

nitc :: ASTBuilder :: mmodule

The module used as reference for the building
protected fun mmodule=(mmodule: MModule)

nitc :: ASTBuilder :: mmodule=

The module used as reference for the building
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram nitc::ASTBuilder ASTBuilder core::Object Object nitc::ASTBuilder->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

nitc $ ASTBuilder
# General factory to build semantic nodes in the AST of expressions
class ASTBuilder
	# The module used as reference for the building
	# It is used to gather types and other stuff
	var mmodule: MModule

	# The anchor used for some mechanism relying on types
	var anchor: nullable MClassType

	# Check mmodule to avoid a new instantiation of ASTBuilder
	fun check_mmodule(mmodule: MModule)
	do
		if self.mmodule != mmodule then self.mmodule = mmodule
	end

	# Make a new Int literal
	fun make_int(value: Int): AIntegerExpr
	do
		return new AIntegerExpr.make(value, mmodule.int_type)
	end

	# Make a new instantiation
	fun make_new(callsite: CallSite, args: nullable Array[AExpr]): ANewExpr
	do
		return new ANewExpr.make(callsite, args)
	end

	# Make a new message send
	fun make_call(recv: AExpr, callsite: CallSite, args: nullable Array[AExpr]): ACallExpr
	do
		return new ACallExpr.make(recv, callsite, args)
	end

	# Make a new, empty, sequence of statements
	fun make_block: ABlockExpr
	do
		return new ABlockExpr.make
	end

	# Make a new, empty, loop of statements
	fun make_loop: ALoopExpr
	do
		return new ALoopExpr.make
	end

	# Make a new variable read
	fun make_var_read(variable: Variable, mtype: MType): AVarExpr
	do
		return new AVarExpr.make(variable, mtype)
	end

	# Make a new variable assignment
	fun make_var_assign(variable: Variable, value: AExpr): AVarAssignExpr
	do
		return new AVarAssignExpr.make(variable, value)
	end

	# Make a new attribute read
	fun make_attr_read(recv: AExpr, attribute: MAttribute): AAttrExpr
	do
		var mtype = attribute.intro.static_mtype.resolve_for(recv.mtype.as(not null), anchor, mmodule, true)
		return new AAttrExpr.make(recv, attribute, mtype)
	end

	# Make a new attribute assignment
	fun make_attr_assign(recv: AExpr, attribute: MAttribute, value: AExpr): AAttrAssignExpr
	do
		return new AAttrAssignExpr.make(recv, attribute, value)
	end

	# Make a new escapable block
	fun make_do: ADoExpr
	do
		return new ADoExpr.make
	end

	# Make a new break for a given escapemark
	fun make_break(escapemark: EscapeMark): ABreakExpr
	do
		return new ABreakExpr.make(escapemark)
	end

	# Make a new conditional
	# `mtype` is the return type of the whole if, in case of a ternary operator.
	fun make_if(condition: AExpr, mtype: nullable MType): AIfExpr
	do
		return new AIfExpr.make(condition, mtype)
	end

	# Make a new assert
	fun make_assert(n_id : nullable TId , n_expr : AExpr , n_else : nullable AExpr): AAssertExpr
	do
		return new AAssertExpr.make(n_id , n_expr , n_else)
	end

	# Make a new method
	fun make_method(n_visibility: nullable AVisibility,
					tk_redef: nullable TKwredef,
					mmethoddef: nullable MMethodDef,
					n_signature: nullable ASignature,
					n_annotations: nullable AAnnotations,
					n_extern_calls: nullable AExternCalls,
					n_extern_code_block: nullable AExternCodeBlock,
					n_block: nullable AExpr): AMethPropdef
	do
		return new AMethPropdef.make(n_visibility, tk_redef, mmethoddef, n_signature, n_annotations, n_extern_calls, n_extern_code_block, n_block)
	end

	# Make a new or with two expr
	fun make_or(right_expr: AExpr, left_expr: AExpr): AOrExpr
	do
		return new AOrExpr.make(right_expr,left_expr)
	end

	# Make a new and with two expr
	fun make_and(right_expr: AExpr, left_expr: AExpr): AAndExpr
	do
		return new AAndExpr.make(right_expr,left_expr)
	end

	# Make a new parenthesis expr
	fun make_parenthesis(expr: AExpr, annotations: nullable AAnnotations): AParExpr
	do
		return new AParExpr.make(expr,annotations)
	end

	# Make a new message super
	fun make_super_call(args: nullable Array[AExpr], n_qualified: nullable AQualified): ASuperExpr
	do
		return new ASuperExpr.make(args,n_qualified)
	end

	# Make a new return
	fun make_return(expr: nullable AExpr): AReturnExpr
	do
		return new AReturnExpr.make(expr)
	end

	# Make a new not
	fun make_not(expr: AExpr): ANotExpr
	do
		return new ANotExpr.make(expr)
	end

	# Make a new attribute
	fun make_attribute(name: String,
					n_type: nullable AType,
					n_visibility: nullable AVisibility,
					initial_value: nullable AExpr,
					n_block: nullable AExpr,
					m_attributedef: nullable MAttributeDef,
					m_setterdef: nullable MMethodDef,
					m_getterdef: nullable MMethodDef): AAttrPropdef
	do
		return new AAttrPropdef.make(name, n_type, n_visibility, initial_value, n_block, m_attributedef, m_setterdef, m_getterdef)
	end

	# Make a new class (AStdClassdef)
	fun make_class(mclassdef: nullable MClassDef,
					n_visibility: nullable AVisibility,
					n_formaldefs : Collection[AFormaldef],
					n_extern_code_block : nullable AExternCodeBlock,
					n_propdefs : Collection[APropdef],
					n_classkind: nullable AClasskind): AStdClassdef
	do
		return new AStdClassdef.make(mclassdef, n_visibility, n_formaldefs, n_extern_code_block, n_propdefs, n_classkind)
	end

	fun make_var(variable: Variable, mtype: MType): AVarExpr
	do
		return new AVarExpr.make(variable, mtype)
	end

	# Make a call assignment i.e `a = 10`
	fun make_call_assign(recv: AExpr, callsite: CallSite, n_args: nullable Collection[AExpr], n_value: AExpr): ACallAssignExpr
	do
		return new ACallAssignExpr.make(recv, callsite, n_args, n_value)
	end

	# Build a callsite to call the `mproperty` in the current method `caller_method`.
	# `is_self_call` indicate if the method caller is a property of `self`
	fun create_callsite(modelbuilder: ModelBuilder, caller_property: APropdef, mproperty: MMethod, is_self_call: Bool): CallSite
	do
		# FIXME It's not the better solution to call `TypeVisitor` here to build a model entity, but some make need to have a callsite
		var type_visitor = new TypeVisitor(modelbuilder, caller_property.mpropdef.as(not null))
		var callsite = type_visitor.build_callsite_by_property(caller_property, mproperty.intro_mclassdef.bound_mtype, mproperty, is_self_call)
		assert callsite != null
		return callsite
	end
end
src/astbuilder.nit:25,1--214,3