Instantiation and transformation of semantic nodes in the AST of expressions and statements

Introduced classes

class APlaceholderExpr

nitc :: APlaceholderExpr

A placeholder for a AExpr node
class ASTBuilder

nitc :: ASTBuilder

General factory to build semantic nodes in the AST of expressions
class ASTValidationVisitor

nitc :: ASTValidationVisitor

Check the consitency of AST

Redefined classes

redef class AAndExpr

nitc :: astbuilder $ AAndExpr

A and expression
redef class AAnnotation

nitc :: astbuilder $ AAnnotation

A single annotation
redef class AAsNotnullExpr

nitc :: astbuilder $ AAsNotnullExpr

A as-not-null cast. eg x.as(not null)
redef class AAssertExpr

nitc :: astbuilder $ AAssertExpr

An assert statement
redef class AAttrAssignExpr

nitc :: astbuilder $ AAttrAssignExpr

The assignment of an attribute. eg x._a=y
redef class AAttrExpr

nitc :: astbuilder $ AAttrExpr

The read of an attribute. eg x._a
redef class AAttrPropdef

nitc :: astbuilder $ AAttrPropdef

A definition of an attribute
redef class ABlockExpr

nitc :: astbuilder $ ABlockExpr

A sequence of AExpr (usually statements)
redef class ABreakExpr

nitc :: astbuilder $ ABreakExpr

A break statement.
redef class ACallAssignExpr

nitc :: astbuilder $ ACallAssignExpr

A setter call with a standard method-name and any number of arguments. eg x.m(y)=z. OR just a simple assignment.
redef class ACallExpr

nitc :: astbuilder $ ACallExpr

A call with a standard method-name and any number of arguments. eg x.m(y). OR just a simple id
redef class ACharExpr

nitc :: astbuilder $ ACharExpr

A character literal
redef class ADoExpr

nitc :: astbuilder $ ADoExpr

A do statement
redef abstract class AExpr

nitc :: astbuilder $ AExpr

Expression and statements
redef class AFalseExpr

nitc :: astbuilder $ AFalseExpr

A false boolean literal constant
redef class AFloatExpr

nitc :: astbuilder $ AFloatExpr

A float literal
redef class AFormaldef

nitc :: astbuilder $ AFormaldef

The definition of a formal generic parameter type. eg X: Y
redef class AIfExpr

nitc :: astbuilder $ AIfExpr

A if statement
redef class AImplicitSelfExpr

nitc :: astbuilder $ AImplicitSelfExpr

When there is no explicit receiver, self is implicit
redef class AIntegerExpr

nitc :: astbuilder $ AIntegerExpr

An integer literal
redef class ALoopExpr

nitc :: astbuilder $ ALoopExpr

A loop statement
redef class AMethPropdef

nitc :: astbuilder $ AMethPropdef

A definition of all kind of method (including constructors)
redef class ANewExpr

nitc :: astbuilder $ ANewExpr

An explicit instantiation. eg new T
redef abstract class ANode

nitc :: astbuilder $ ANode

Root of the AST class-hierarchy
redef class ANodes[E: ANode]

nitc :: astbuilder $ ANodes

A sequence of nodes
redef class ANotExpr

nitc :: astbuilder $ ANotExpr

A not expression
redef class ANullExpr

nitc :: astbuilder $ ANullExpr

A null literal constant
redef class AOrExpr

nitc :: astbuilder $ AOrExpr

A or expression
redef class AParExpr

nitc :: astbuilder $ AParExpr

A simple parenthesis. eg (x)
redef class AParam

nitc :: astbuilder $ AParam

A parameter definition in a signature. eg x:X
redef class AQclassid

nitc :: astbuilder $ AQclassid

A potentially qualified class identifier foo::bar::Baz
redef class AQid

nitc :: astbuilder $ AQid

A potentially qualified simple identifier foo::bar::baz
redef class AQualified

nitc :: astbuilder $ AQualified

A possible full method qualifier.
redef class AReturnExpr

nitc :: astbuilder $ AReturnExpr

A return statement. eg return x
redef class ASelfExpr

nitc :: astbuilder $ ASelfExpr

A read of self
redef class ASignature

nitc :: astbuilder $ ASignature

A signature in a method definition. eg (x,y:X,z:Z):T
redef class AStdClassdef

nitc :: astbuilder $ AStdClassdef

A standard class definition with a name, superclasses and properties
redef class ASuperExpr

nitc :: astbuilder $ ASuperExpr

A call to super. OR a call of a super-constructor
redef class ATrueExpr

nitc :: astbuilder $ ATrueExpr

A true boolean literal constant
redef class AType

nitc :: astbuilder $ AType

A static type. eg nullable X[Y]
redef class AVarAssignExpr

nitc :: astbuilder $ AVarAssignExpr

A local variable simple assignment access
redef class AVarExpr

nitc :: astbuilder $ AVarExpr

A local variable read access.
redef class MAttributeDef

nitc :: astbuilder $ MAttributeDef

A local definition of an attribute
redef class MClassDef

nitc :: astbuilder $ MClassDef

A definition (an introduction or a refinement) of a class in a module
redef abstract class MEntity

nitc :: astbuilder $ MEntity

A named and possibly documented entity in the model.
redef class MMethodDef

nitc :: astbuilder $ MMethodDef

A local definition of a method
redef class MParameter

nitc :: astbuilder $ MParameter

A parameter in a signature
redef class MParameterType

nitc :: astbuilder $ MParameterType

The type associated to a formal parameter generic type of a class
redef abstract class MPropDef

nitc :: astbuilder $ MPropDef

A definition of a property (local property)
redef class MSignature

nitc :: astbuilder $ MSignature

A signature of a method
redef abstract class MType

nitc :: astbuilder $ MType

A global static type
redef class MVisibility

nitc :: astbuilder $ MVisibility

A visibility (for modules, class and properties)
redef class ModelBuilder

nitc :: astbuilder $ ModelBuilder

A model builder knows how to load nit source files and build the associated model
redef class TId

nitc :: astbuilder $ TId

A standard identifier (variable, method...). They start with a lowercase.

All class definitions

redef class AAndExpr

nitc :: astbuilder $ AAndExpr

A and expression
redef class AAnnotation

nitc :: astbuilder $ AAnnotation

A single annotation
redef class AAsNotnullExpr

nitc :: astbuilder $ AAsNotnullExpr

A as-not-null cast. eg x.as(not null)
redef class AAssertExpr

nitc :: astbuilder $ AAssertExpr

An assert statement
redef class AAttrAssignExpr

nitc :: astbuilder $ AAttrAssignExpr

The assignment of an attribute. eg x._a=y
redef class AAttrExpr

nitc :: astbuilder $ AAttrExpr

The read of an attribute. eg x._a
redef class AAttrPropdef

nitc :: astbuilder $ AAttrPropdef

A definition of an attribute
redef class ABlockExpr

nitc :: astbuilder $ ABlockExpr

A sequence of AExpr (usually statements)
redef class ABreakExpr

nitc :: astbuilder $ ABreakExpr

A break statement.
redef class ACallAssignExpr

nitc :: astbuilder $ ACallAssignExpr

A setter call with a standard method-name and any number of arguments. eg x.m(y)=z. OR just a simple assignment.
redef class ACallExpr

nitc :: astbuilder $ ACallExpr

A call with a standard method-name and any number of arguments. eg x.m(y). OR just a simple id
redef class ACharExpr

nitc :: astbuilder $ ACharExpr

A character literal
redef class ADoExpr

nitc :: astbuilder $ ADoExpr

A do statement
redef abstract class AExpr

nitc :: astbuilder $ AExpr

Expression and statements
redef class AFalseExpr

nitc :: astbuilder $ AFalseExpr

A false boolean literal constant
redef class AFloatExpr

nitc :: astbuilder $ AFloatExpr

A float literal
redef class AFormaldef

nitc :: astbuilder $ AFormaldef

The definition of a formal generic parameter type. eg X: Y
redef class AIfExpr

nitc :: astbuilder $ AIfExpr

A if statement
redef class AImplicitSelfExpr

nitc :: astbuilder $ AImplicitSelfExpr

When there is no explicit receiver, self is implicit
redef class AIntegerExpr

nitc :: astbuilder $ AIntegerExpr

An integer literal
redef class ALoopExpr

nitc :: astbuilder $ ALoopExpr

A loop statement
redef class AMethPropdef

nitc :: astbuilder $ AMethPropdef

A definition of all kind of method (including constructors)
redef class ANewExpr

nitc :: astbuilder $ ANewExpr

An explicit instantiation. eg new T
redef abstract class ANode

nitc :: astbuilder $ ANode

Root of the AST class-hierarchy
redef class ANodes[E: ANode]

nitc :: astbuilder $ ANodes

A sequence of nodes
redef class ANotExpr

nitc :: astbuilder $ ANotExpr

A not expression
redef class ANullExpr

nitc :: astbuilder $ ANullExpr

A null literal constant
redef class AOrExpr

nitc :: astbuilder $ AOrExpr

A or expression
redef class AParExpr

nitc :: astbuilder $ AParExpr

A simple parenthesis. eg (x)
redef class AParam

nitc :: astbuilder $ AParam

A parameter definition in a signature. eg x:X
class APlaceholderExpr

nitc $ APlaceholderExpr

A placeholder for a AExpr node
redef class AQclassid

nitc :: astbuilder $ AQclassid

A potentially qualified class identifier foo::bar::Baz
redef class AQid

nitc :: astbuilder $ AQid

A potentially qualified simple identifier foo::bar::baz
redef class AQualified

nitc :: astbuilder $ AQualified

A possible full method qualifier.
redef class AReturnExpr

nitc :: astbuilder $ AReturnExpr

A return statement. eg return x
class ASTBuilder

nitc $ ASTBuilder

General factory to build semantic nodes in the AST of expressions
class ASTValidationVisitor

nitc $ ASTValidationVisitor

Check the consitency of AST
redef class ASelfExpr

nitc :: astbuilder $ ASelfExpr

A read of self
redef class ASignature

nitc :: astbuilder $ ASignature

A signature in a method definition. eg (x,y:X,z:Z):T
redef class AStdClassdef

nitc :: astbuilder $ AStdClassdef

A standard class definition with a name, superclasses and properties
redef class ASuperExpr

nitc :: astbuilder $ ASuperExpr

A call to super. OR a call of a super-constructor
redef class ATrueExpr

nitc :: astbuilder $ ATrueExpr

A true boolean literal constant
redef class AType

nitc :: astbuilder $ AType

A static type. eg nullable X[Y]
redef class AVarAssignExpr

nitc :: astbuilder $ AVarAssignExpr

A local variable simple assignment access
redef class AVarExpr

nitc :: astbuilder $ AVarExpr

A local variable read access.
redef class MAttributeDef

nitc :: astbuilder $ MAttributeDef

A local definition of an attribute
redef class MClassDef

nitc :: astbuilder $ MClassDef

A definition (an introduction or a refinement) of a class in a module
redef abstract class MEntity

nitc :: astbuilder $ MEntity

A named and possibly documented entity in the model.
redef class MMethodDef

nitc :: astbuilder $ MMethodDef

A local definition of a method
redef class MParameter

nitc :: astbuilder $ MParameter

A parameter in a signature
redef class MParameterType

nitc :: astbuilder $ MParameterType

The type associated to a formal parameter generic type of a class
redef abstract class MPropDef

nitc :: astbuilder $ MPropDef

A definition of a property (local property)
redef class MSignature

nitc :: astbuilder $ MSignature

A signature of a method
redef abstract class MType

nitc :: astbuilder $ MType

A global static type
redef class MVisibility

nitc :: astbuilder $ MVisibility

A visibility (for modules, class and properties)
redef class ModelBuilder

nitc :: astbuilder $ ModelBuilder

A model builder knows how to load nit source files and build the associated model
redef class TId

nitc :: astbuilder $ TId

A standard identifier (variable, method...). They start with a lowercase.
package_diagram nitc::astbuilder astbuilder nitc::typing typing nitc::astbuilder->nitc::typing nitc\>modelize\> modelize nitc::typing->nitc\>modelize\> nitc::local_var_init local_var_init nitc::typing->nitc::local_var_init ...nitc\>modelize\> ... ...nitc\>modelize\>->nitc\>modelize\> ...nitc::local_var_init ... ...nitc::local_var_init->nitc::local_var_init nitc::parallelization_phase parallelization_phase nitc::parallelization_phase->nitc::astbuilder nitc::i18n_phase i18n_phase nitc::i18n_phase->nitc::astbuilder nitc::explain_assert explain_assert nitc::explain_assert->nitc::astbuilder nitc::contracts contracts nitc::contracts->nitc::astbuilder nitc::ssa ssa nitc::ssa->nitc::astbuilder nitc::transform transform nitc::transform->nitc::astbuilder nitc::frontend frontend nitc::frontend->nitc::parallelization_phase nitc::frontend->nitc::i18n_phase nitc::frontend... ... nitc::frontend...->nitc::frontend nitc::code_gen code_gen nitc::code_gen->nitc::explain_assert nitc::code_gen->nitc::contracts nitc::code_gen... ... nitc::code_gen...->nitc::code_gen nitc::compilation compilation nitc::compilation->nitc::ssa nitc::compilation... ... nitc::compilation...->nitc::compilation nitc::nitc nitc nitc::nitc->nitc::transform nitc::nith nith nitc::nith->nitc::transform nitc::java_compiler java_compiler nitc::java_compiler->nitc::transform nitc::nitc... ... nitc::nitc...->nitc::nitc nitc::nith... ... nitc::nith...->nitc::nith nitc::java_compiler... ... nitc::java_compiler...->nitc::java_compiler

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module annotation

nitc :: annotation

Management and utilities on annotations
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module flow

nitc :: flow

Intraprocedural static flow.
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module ini

ini :: ini

Read and write INI configuration files
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module list

core :: list

This module handle double linked lists
module literal

nitc :: literal

Parsing of literal values in the abstract syntax tree.
module loader

nitc :: loader

Loading of Nit source files
module local_var_init

nitc :: local_var_init

Verify that local variables are initialized before their usage
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module mdoc

nitc :: mdoc

Documentation of model entities
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module mmodule_data

nitc :: mmodule_data

Define and retrieve data in modules
module model

nitc :: model

Classes, types and properties
module model_base

nitc :: model_base

The abstract concept of model and related common things
module modelbuilder_base

nitc :: modelbuilder_base

Load nit source files and build the associated model
module modelize

nitc :: modelize

Create a model from nit source files
module modelize_class

nitc :: modelize_class

Analysis and verification of class definitions to instantiate model element
module modelize_property

nitc :: modelize_property

Analysis and verification of property definitions to instantiate model element
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module nitpm_shared

nitc :: nitpm_shared

Services related to the Nit package manager
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parser

nitc :: parser

Parser.
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module phase

nitc :: phase

Phases of the processing of nit programs
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module scope

nitc :: scope

Identification and scoping of local variables and labels.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module typing

nitc :: typing

Intraprocedural resolution of static types and OO-services

Children

module contracts

nitc :: contracts

Module to build contract
module explain_assert

nitc :: explain_assert

Explain failed assert to the console by modifying the AST.
module i18n_phase

nitc :: i18n_phase

Basic support of internationalization through the generation of id-to-string tables
module parallelization_phase

nitc :: parallelization_phase

Phase generating threads for functions annotated with threaded annotation
module ssa

nitc :: ssa

Single-Static Assignment algorithm from an AST
module transform

nitc :: transform

Thansformations that simplify the AST of expressions

Descendants

module a_star-m

a_star-m

module api

nitc :: api

Components required to build a web server about the nit model.
module api_auth

nitc :: api_auth

module api_base

nitc :: api_base

Base classes used by nitweb.
module api_docdown

nitc :: api_docdown

Nitdoc specific Markdown format handling for Nitweb
module api_feedback

nitc :: api_feedback

Feedback related features
module api_light

nitc :: api_light

Highlight and collect messages from a piece of code
module api_model

nitc :: api_model

module code_gen

nitc :: code_gen

Main frontend phases plus code generation phases
module commands_docdown

nitc :: commands_docdown

Doc down related queries
module compilation

nitc :: compilation

The compilation module of the VirtualMachine
module frontend

nitc :: frontend

Collect and orchestration of main frontend phases
module highlight

nitc :: highlight

Highlighting of Nit AST
module html_commands

nitc :: html_commands

Render commands results as HTML
module html_model

nitc :: html_model

Translate mentities to html blocks.
module htmlight

nitc :: htmlight

Highlighting of Nit AST with HTML
module java_compiler

nitc :: java_compiler

Compile Nit code to Java code
module json_commands

nitc :: json_commands

Translate command results to json
module json_model

nitc :: json_model

Make model entities Serializable.
module md_commands

nitc :: md_commands

Render commands results as Markdown
module nit

nitc :: nit

A naive Nit interpreter
module nitc

nitc :: nitc

A Nit compiler
module nitcatalog

nitc :: nitcatalog

Basic catalog generator for Nit packages
module nitdoc

nitc :: nitdoc

Generator of static API documentation for the Nit language
module nith

nitc :: nith

A ligHt Nit compiler
module nitj

nitc :: nitj

Compile Nit into Java code runnable on the Java Virtual Machine.
module nitlight

nitc :: nitlight

Tool that produces highlighting for Nit programs
module nitmetrics

nitc :: nitmetrics

A program that collects various metrics on nit programs and libraries
module nitpackage

nitc :: nitpackage

Helpful features about packages
module nitpick

nitc :: nitpick

A program that collect potential style and code issues
module nitrestful

nitc :: nitrestful

Tool generating boilerplate code linking RESTful actions to Nit methods
module nitsaf

nitc :: nitsaf

Nit Static Analysis Framework client example.
module nitserial

nitc :: nitserial

Serialization support compiler, a tool to support deserialization of live generic types
module nitsmells

nitc :: nitsmells

module nituml

nitc :: nituml

UML generator in dot format.
module nitunit

nitc :: nitunit

Testing tool.
module nitvm

nitc :: nitvm

The Nit virtual machine launcher
module nitweb

nitc :: nitweb

Runs a webserver based on nitcorn that render things from model.
module nitx

nitc :: nitx

nitx, a command tool that displays useful data about Nit code
module static

nitc :: static

Nitdoc generation framework
module static_base

nitc :: static_base

Base entities shared by all the nitdoc code
module static_cards

nitc :: static_cards

Cards templates for the static documentation
module static_html

nitc :: static_html

Render documentation pages as HTML
module static_index

nitc :: static_index

Manage indexing of Nit model for Nitdoc QuickSearch.
module static_structure

nitc :: static_structure

Composes the pages of the static documentation
module term

nitc :: term

module test_astbuilder

nitc :: test_astbuilder

Program used to test the clone method of the astbuilder tool
module test_highlight

nitc :: test_highlight

Program used to test the Nit highlighter
module test_model_visitor

nitc :: test_model_visitor

Example of model_visitor
module test_neo

nitc :: test_neo

Test for neo model saving and loading.
module test_test_phase

nitc :: test_test_phase

Example of simple module that aims to do some specific work on nit programs.
module vm

nitc :: vm

Entry point of all vm components
# Instantiation and transformation of semantic nodes in the AST of expressions and statements
module astbuilder

intrude import semantize::typing
intrude import literal
intrude import parser
intrude import semantize::scope
intrude import modelbuilder_base
intrude import modelize_property

# 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_method : AMethPropdef, 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_method.mpropdef.as(not null))
		var callsite = type_visitor.build_callsite_by_property(caller_method, mproperty.intro_mclassdef.bound_mtype, mproperty, is_self_call)
		assert callsite != null
		return callsite
	end
end

redef class AExpr
	# Return a new variable read that contains the value of the expression
	# This method take care efficiently of creating and initalising an anonymous local variable
	#
	# Note: since this method do side-effects (AST replacement), there could be unexpected effects when used as
	# argument of other methods related to AST transformations.
	fun make_var_read: AVarExpr
	do
		var variable = self.variable_cache
		if variable == null then
			assert parent != null
			var place = detach_with_placeholder
			variable = new Variable("")
			variable.declared_type = self.mtype
			var nvar = new AVarAssignExpr.make(variable, self)
			place.replace_with(nvar)
			self.variable_cache = variable
		end
		return new AVarExpr.make(variable, variable.declared_type.as(not null))
	end

	private var variable_cache: nullable Variable

	# The `detach` method completely remove the node in the parent.
	# However, sometime, it is useful to keep the emplacement of the removed child.
	#
	# The standard use case is the insertion of a node between a parent `p` and a child `p.c`.
	# To create the new node `n`, we need to attach the child to it.
	# But, to put `n` where `c` was in `p`, the place has to be remembered.
	#
	# ~~~nitish
	# var p: AExpr
	# var c = p.c
	# var h = c.detach_with_placeholder
	# var n = astbuilder.make_XXX(c)
	# h.replace_with(n)
	# ~~~
	fun detach_with_placeholder: AExpr
	do
		var h = new APlaceholderExpr.make
		self.replace_with(h)
		return h
	end


	# Add `expr` at the end of the block
	#
	# REQUIRE: self isa ABlockExpr
	#
	# Note: this method, aimed to `ABlockExpr` is promoted to `AExpr` because of the limitations of the hierarchies generated by sablecc3
	fun add(expr: AExpr)
	do
		print "add not implemented in {inspect}"
		abort
	end

	redef fun accept_ast_validation(v)
	do
		super
		if mtype == null and not is_typed then
			#debug "TYPING: untyped expression"
		end
	end
end

# A placeholder for a `AExpr` node
# Instances are transiantly used to mark some specific emplacements in the AST
# during complex transformations.
#
# Their must not appear in a valid AST
#
# @see AExpr::detach_with_placeholder
class APlaceholderExpr
	super AExpr
	private init make
	do
	end

	redef fun accept_ast_validation(v)
	do
		super
		debug "PARENT: remaining placeholder"
	end
end

redef class ACallAssignExpr
	private init make(recv: AExpr, callsite: CallSite, args: nullable Collection[AExpr], n_value: AExpr)
	do
		_callsite = callsite
		_mtype = callsite.recv
		_is_typed = true
		var n_args = new AListExprs
		if args != null then
			n_args.n_exprs.add_all(args)
		end
		var n_qid = new AQid
		n_qid.n_id = new TId
		n_qid.n_id.text = callsite.mproperty.name
		init_acallassignexpr(recv, n_qid, n_args, new TAssign, n_value)
	end
end

redef class AStdClassdef
	private init make(mclassdef: nullable MClassDef,
					n_visibility: nullable AVisibility,
					n_formaldefs : Collection[Object],
					n_extern_code_block : nullable AExternCodeBlock,
					n_propdefs : Collection[Object],
					n_classkind: nullable AClasskind)
	do
		if n_visibility == null then n_visibility = new APublicVisibility
		if n_classkind == null then n_classkind = new AConcreteClasskind.init_aconcreteclasskind(new TKwclass)
		var n_qid = new AQclassid.init_aqclassid(null, new TClassid)
		init_astdclassdef(null, null, n_visibility, n_classkind, n_qid, null, n_formaldefs, null, n_extern_code_block, n_propdefs, new TKwend)
		_mclassdef = mclassdef
		_mclass = mclassdef.mclass
	end
end

redef class AAttrPropdef

	# Create a new `AAttrPropdef`
	# Note: By default if the `AVisibility` is not given the visibility is set to public
	private init make(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)
	do
		# Set the model type
		if n_type != null then mtype = n_type.mtype
		# Define the visibility default is public
		if n_visibility == null then n_visibility = new APublicVisibility
		init_aattrpropdef(null, null, n_visibility, new TKwvar, new TId, n_type, null, initial_value, null, null , n_block, null)
		# Set the name of the attribute
		_n_id2.text = name
		_mpropdef = m_attributedef
		_mreadpropdef = m_getterdef
		_mwritepropdef = m_setterdef
		if initial_value != null or n_block != null then has_value = true
		if m_attributedef != null then self.location = m_attributedef.location
	end
end

redef class ANotExpr
	private init make(expr: AExpr)
	do
		self.init_anotexpr(new TKwnot, expr)
	end
end

redef class AReturnExpr
	private init make(expr: nullable AExpr)
	do
		self.init_areturnexpr(null, expr)
	end
end

redef class ASuperExpr
	private init make(args: nullable Array[AExpr], n_qualified: nullable AQualified, mpropdef: nullable MMethodDef)
	do
		var n_args = new AListExprs
		if args != null then
			n_args.n_exprs.add_all(args)
		end
		_mpropdef = mpropdef
		self.init_asuperexpr(n_qualified, new TKwsuper, n_args)
	end
end

redef class AOrExpr
	private init make(right_expr: AExpr, left_expr: AExpr)
	do
		self.init_aorexpr(right_expr,new TKwor,left_expr)
	end
end

redef class AAndExpr
	private init make(right_expr: AExpr, left_expr: AExpr)
	do
		self.init_aandexpr(right_expr,new TKwand ,left_expr)
	end
end

redef class AMethPropdef
	private init make(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)
	do
		var n_tid = new TId
		var n_methid = new AIdMethid.init_aidmethid(n_tid)
		if n_signature == null then n_signature = new ASignature
		if n_visibility == null then n_visibility = new APublicVisibility
		self.init_amethpropdef(null,tk_redef,n_visibility,new TKwmeth,null,null,null,n_methid,n_signature,n_annotations,n_extern_calls,n_extern_code_block,new TKwdo,n_block,new TKwend)
		self.mpropdef = mmethoddef
		if mpropdef != null then self.location = mmethoddef.location
	end
end

redef class AAssertExpr
	private init make(n_id : nullable TId , n_expr : nullable AExpr , n_else : nullable AExpr)
	do
		n_kwassert = new TKwassert
		n_kwelse = null
		if n_else != null then n_kwelse = new TKwelse
		self.init_aassertexpr(n_kwassert, n_id , n_expr , n_kwelse , n_else)
	end
end

redef class ALoopExpr
	private init make
	do
		_n_kwloop = new TKwloop
		self.is_typed = true
		n_block = new ABlockExpr
		n_block.is_typed = true
	end

	redef fun add(expr)
	do
		n_block.add expr
	end
end

redef class ADoExpr
	private init make
	do
		_n_kwdo = new TKwdo
		self.is_typed = true
		n_block = new ABlockExpr
		n_block.is_typed = true
	end

	# Make a new break expression of the given do
	fun make_break: ABreakExpr
	do
		var escapemark = self.break_mark
		if escapemark == null then
			escapemark = new EscapeMark(null)
			self.break_mark = escapemark
		end
		return new ABreakExpr.make(escapemark)
	end

	redef fun add(expr)
	do
		n_block.add expr
	end
end

redef class ABreakExpr
	private init make(escapemark: EscapeMark)
	do
		_n_kwbreak = new TKwbreak
		self.escapemark = escapemark
		escapemark.escapes.add self
		self.is_typed = true
	end
end

redef class AIfExpr
	private init make(condition: AExpr, mtype: nullable MType)
	do
		_n_kwif = new TKwif
		_n_expr = condition
		_n_expr.parent = self
		_n_kwthen = new TKwthen
		_n_then = new ABlockExpr.make
		_n_kwelse = new TKwelse
		_n_else = new ABlockExpr.make
		self.mtype = mtype
		if mtype != null then self.is_typed = true
	end
end

redef class AType

	private init make(t: nullable MType)
	do
		var n_id = new TClassid
		var n_qid = new AQclassid
		n_qid.n_id = n_id
		_n_qid = n_qid
		_mtype = t
	end

	redef fun clone: SELF
	do
		return new AType.make(mtype)
	end
end

# Primitive type

redef class AIntegerExpr

	private init make(value: nullable Numeric, t: nullable MType)
	do
		_mtype = t
		if t != null then self.is_typed = true
		_value = value
		_n_integer = new TInteger # dummy
	end

	redef fun clone: SELF
	do
		return new AIntegerExpr.make(value, mtype)
	end
end

redef class AFloatExpr

	private init make(value: nullable Float, t: nullable MType)
	do
		_mtype = t
		if t != null then self.is_typed = true
		_value = value
		_n_float = new TFloat # dummy
	end

	redef fun clone: SELF
	do
		return new AFloatExpr.make(value, mtype)
	end
end

redef class ATrueExpr

	private init make(t: nullable MType)
	do
		init_atrueexpr(new TKwtrue, null)
		_mtype = t
		if t != null then self.is_typed = true
	end

	redef fun clone: SELF
	do
		return new ATrueExpr.make(mtype)
	end
end

redef class AFalseExpr

	private init make(t: nullable MType)
	do
		init_afalseexpr(new TKwfalse, null)
		_mtype = t
		if t != null then self.is_typed = true
	end

	redef fun clone: SELF
	do
		return new AFalseExpr.make(mtype)
	end
end

redef class ACharExpr

	# `token_text` represent the real value as it's present in a file not only the char.
	# `token_text` is needed if you want to use some methods (for exemple: `prefix`, `suffix` or `is_code_point methods`)
	private init make(value: nullable Char, t: nullable MType, token_text: nullable String)
	do
		_value = value
		_mtype = t
		_n_char = new TChar
		if token_text != null then n_char.text = token_text
		if t != null then self.is_typed = true
	end

	redef fun clone: SELF
	do
		var self_clone = new ACharExpr.make(self.value, mtype, n_char.text)
		return self_clone
	end
end

redef class ANewExpr
	private init make(callsite: CallSite, args: nullable Array[AExpr])
	do
		_n_kwnew = new TKwnew
		_n_type = new AType.make
		_n_args = new AListExprs
		if args != null then
			n_args.n_exprs.add_all(args)
		end
		self.callsite = callsite
		self.recvtype = callsite.recv.as(MClassType)
		if callsite.mproperty.is_new then
			self.mtype = callsite.msignature.return_mtype
		else
			self.mtype = callsite.recv
		end
		self.is_typed = true
	end
end

redef class ACallExpr
	private init make(recv: AExpr, callsite: nullable CallSite, args: nullable Array[AExpr])
	do
		self._n_expr = recv
		_n_args = new AListExprs
		_n_qid = new AQid
		_n_qid.n_id = new TId
		_n_qid.n_id.text = callsite.mproperty.name
		if args != null then
			self.n_args.n_exprs.add_all(args)
		end

		if callsite != null then
			self.callsite = callsite
			self.mtype = callsite.msignature.return_mtype
			self.is_typed = true
		end
	end
end

redef class AAsNotnullExpr
	private init make(n_expr: AExpr, t: nullable MType)
	do
		init_aasnotnullexpr(n_expr, new TKwas, null, new TKwnot, new TKwnull, null)
		_mtype = t
		if t != null then _is_typed = true
	end
end

redef class ANullExpr

	private init make(t: nullable MType)
	do
		init_anullexpr(new TKwnull, null)
		_mtype = t
		if t != null then self.is_typed = true
	end
end

redef class ASelfExpr

	private init make(v: nullable Variable, t: nullable MType)
	do
		init_aselfexpr(new TKwself, null)
		_mtype = t
		if t != null then is_typed =true
	end

	redef fun clone: SELF
	do
		return new ASelfExpr.make(self.variable, self.mtype)
	end
end

redef class AImplicitSelfExpr

	redef fun clone: SELF
	do
		var self_clone = new AImplicitSelfExpr.make(variable, mtype)
		self_clone.is_sys = is_sys
		return self_clone
	end
end


redef class AAttrExpr
	private init make(recv: AExpr, attribute: nullable MAttribute, t: nullable MType)
	do
		_n_expr = recv
		recv.parent = self
		_n_id = new TAttrid
		_mproperty = attribute
		_mtype = t
		if t != null then _is_typed = true
	end
end

redef class AAttrAssignExpr
	private init make(recv: AExpr, attribute: nullable MAttribute, value: AExpr)
	do
		_n_expr = recv
		recv.parent = self
		_n_id = new TAttrid
		_n_value = value
		value.parent = self
		_n_assign = new TAssign
		_mproperty = attribute
		_mtype = value.mtype
	end
end

redef class AVarExpr
	private init make(v: nullable Variable, t: nullable MType)
	do
		_n_id = new TId
		if v != null then _n_id.text = v.name
		_variable = v
		_mtype = t
		if t != null then is_typed = true
	end
end

redef class AVarAssignExpr
	private init make(v: nullable Variable, value: AExpr)
	do
		_n_id = new TId
		if v != null then _n_id.text = v.name
		_n_value = value
		value.parent = self
		_n_assign = new TAssign
		_variable = v
		_mtype = value.mtype
		if _mtype != null then _is_typed = true
	end
end

redef class ASignature

	init make_from_msignature(msignature: MSignature)
	do
		var nparams = new Array[AParam]
		for mparam in msignature.mparameters do
			var variable = new Variable(mparam.name)
			variable.declared_type = mparam.mtype
			n_params.add(new AParam.make(variable, new AType.make(mparam.mtype)))
		end
		var return_type = null
		if msignature.return_mtype != null then return_type = new AType.make(msignature.return_mtype)
		init_asignature(null, nparams, null, return_type)
	end

	redef fun clone: SELF
	do
		var ntype = n_type
		if ntype != null then ntype = n_type.clone
		return new ASignature.init_asignature(null, n_params.clone, null, ntype)
	end
end

redef class AParam

	private init make(v: nullable Variable, t: nullable AType)
	do
		_n_id = new TId
		if v != null then _n_id.text = v.name
		_variable = v
		_n_type = t
	end

	redef fun clone: SELF
	do
		var ntype = n_type
		if ntype != null then ntype = n_type.clone
		return new AParam.make(variable, ntype)
	end
end

redef class AFormaldef

	private init make(mparameter: MParameterType, t: AType)
	do
		_n_id = new TClassid
		_n_id.text = mparameter.name
		_n_type = t
		_mtype = mparameter
	end
end

redef class ABlockExpr
	private init make(t: nullable MType)
	do
		if t != null then
			_mtype = t
			_is_typed = true
		end
	end

	redef fun add(expr)
	do
		n_expr.add expr
		expr.parent = self
	end

	fun add_all(exprs: Array[AExpr])
	do
		for expr in exprs do
			add(expr)
		end
	end

	redef fun clone: SELF
	do
		var clone = new ABlockExpr.make(mtype)
		for expr in self.n_expr do
			clone.add(expr.clone)
		end
		return clone
	end
end

redef class AQclassid
	redef fun clone: SELF
	do
		return new AQclassid.init_aqclassid(n_qualified.clone, n_id)
	end
end

redef class AQualified
	redef fun clone: SELF
	do
		return new AQualified.init_aqualified(n_id.clone, n_classid)
	end
end

redef class AQid
	redef fun clone: SELF
	do
		var clone_n_qualified = n_qualified
		if n_qualified != null then clone_n_qualified = n_qualified.clone
		return new AQid.init_aqid(clone_n_qualified, n_id.clone)
	end
end

redef class TId
	redef fun clone: SELF
	do
		return new TId.init_tk(location)
	end
end

redef class AParExpr
	private init make(expr: AExpr, annotations: nullable AAnnotations)
	do
		self.init_aparexpr(new TOpar, expr, new TCpar, annotations)
	end
end

# Check the consitency of AST
class ASTValidationVisitor
	super Visitor
	redef fun visit(node)
	do
		node.accept_ast_validation(self)
	end
	private var path = new CircularArray[ANode]
	private var seen = new HashSet[ANode]
end

redef class ANodes
	super Cloneable

	redef fun clone: SELF
	do
		var clone_anodes = new ANodes[E](self.parent)
		for node in self do
			clone_anodes.add(node.clone)
		end
		return clone_anodes
	end
end

redef class ANode
	super Cloneable

	redef fun clone: SELF
	do
		# By default the clone abort to avoid surprises
		print "The clone method is not implemented for the `{self.class_name}` class"
		abort
	end
	# Recursively validate a AST node.
	# This ensure that location and parenting are defined and coherent.
	#
	# After complex low-level AST manipulation and construction,
	# it is recommended to call it.
	#
	# Note: this just instantiate and run an `ASTValidationVisitor`.
	fun validate
	do
		(new ASTValidationVisitor).enter_visit(self)
	end

	private fun accept_ast_validation(v: ASTValidationVisitor)
	do
		var parent = self.parent
		var path = v.path

		if path.length > 0 then
			var path_parent = v.path.first
			if parent == null then
				self.parent = path_parent
				#debug "PARENT: expected parent: {path_parent}"
				v.seen.add(self)
			else if parent != path_parent then
				self.parent = path_parent
				if v.seen.has(self) then
					debug "DUPLICATE (NOTATREE): already seen node with parent {parent} now with {path_parent}."
				else
					v.seen.add(self)
					debug "PARENT: expected parent: {path_parent}, got {parent}"
				end
			end
		end

		if not isset _location then
			#debug "LOCATION: unlocated node {v.path.join(", ")}"
			_location = self.parent.location
		end

		path.unshift(self)
		visit_all(v)
		path.shift
	end
end

redef class AAnnotation

	redef fun accept_ast_validation(v)
	do
		# Do not enter in annotations
	end

	private init make(n_args : ANodes[AExpr])
	do
		_n_visibility = new APublicVisibility
		_n_args = n_args
	end
end

redef class MEntity
	# Build a ANode from `self`
	#
	# Allows the creation of an AST node from a model entity.
	fun create_ast_representation(astbuilder: nullable ASTBuilder): ANode is abstract
end

redef class MPropDef
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): APropdef is abstract
end

redef class MClassDef
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AStdClassdef do
		if astbuilder == null then astbuilder = new ASTBuilder(mmodule)
		var n_propdefs = new Array[APropdef]
		for mpropdef in self.mpropdefs do
			n_propdefs.add(mpropdef.create_ast_representation(astbuilder))
		end
		var n_formaldefs = new Array[AFormaldef]
		for mparameter in self.mclass.mparameters do n_formaldefs.add(mparameter.create_ast_representation(astbuilder))

		return astbuilder.make_class(self, visibility.create_ast_representation(astbuilder), n_formaldefs, null, n_propdefs, null)
	end
end

redef class MAttributeDef
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AAttrPropdef do
		if astbuilder == null then astbuilder = new ASTBuilder(mclassdef.mmodule)
		var ntype = null
		if self.static_mtype != null then ntype = static_mtype.create_ast_representation(astbuilder)
		return astbuilder.make_attribute("_" + self.name, ntype, self.visibility.create_ast_representation(astbuilder), null, null, self, null, null)
	end
end

redef class MMethodDef
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AMethPropdef do
		if astbuilder == null then astbuilder = new ASTBuilder(mclassdef.mmodule)
		var tk_redef = null
		if self.mproperty.intro != self then tk_redef = new TKwredef
		var  n_signature = if self.msignature == null then new ASignature else self.msignature.create_ast_representation(astbuilder)
		return astbuilder.make_method(visibility.create_ast_representation(astbuilder), tk_redef, self, n_signature)
	end
end

redef class MVisibility
	fun create_ast_representation(astbuilder: nullable ASTBuilder): AVisibility do
		if self.to_s == "public" then
			return new APublicVisibility
		else if self.to_s == "private" then
			return new APrivateVisibility
		else if self.to_s == "protected" then
			return new AProtectedVisibility
		else
			return new AIntrudeVisibility
		end
	end
end

redef class MSignature
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): ASignature do
		var nparams = new Array[AParam]
		for mparam in mparameters do nparams.add(mparam.create_ast_representation(astbuilder))
		var return_type = null
		if self.return_mtype != null then return_type = self.return_mtype.create_ast_representation(astbuilder)
		return new ASignature.init_asignature(null, nparams, null, return_type)
	end
end

redef class MParameter
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AParam do
		var variable = new Variable(self.name)
		variable.declared_type = self.mtype
		return new AParam.make(variable, self.mtype.create_ast_representation(astbuilder))
	end
end

redef class MParameterType
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AFormaldef do
		var n_type = super
		return new AFormaldef.make(self, n_type)
	end
end

redef class MType
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AType do
		return new AType.make(self)
	end
end

redef class ModelBuilder
	# Try to get MMethod property if exist in the given mclassdef. return new `MMethod` if not exist.
	private fun get_mmethod(name: String, mclassdef: MClassDef, visibility: nullable MVisibility): MMethod do
		visibility = visibility or else public_visibility
		var mproperty = try_get_mproperty_by_name(null, mclassdef, name).as(nullable MMethod)
		if mproperty == null then mproperty = new MMethod(mclassdef, name, mclassdef.location, visibility)
		return mproperty
	end

	# Creation of a new method (AST and model representation) with the given name.
	# See `create_method_from_property` for more information.
	fun create_method_from_name(name: String, mclassdef: MClassDef, is_abstract: Bool, msignature: nullable MSignature, visibility: nullable MVisibility): AMethPropdef do
		var mproperty = get_mmethod(name, mclassdef, visibility)
		return create_method_from_property(mproperty, mclassdef, is_abstract, msignature)
	end

	# Creation of a new method (AST and model representation) with the given MMethod.
	# Take care, if `is_abstract == false` the AMethPropdef returned has an empty body (potential error if the given signature has an return type).
	fun create_method_from_property(mproperty: MMethod,  mclassdef: MClassDef, is_abstract: Bool, msignature: nullable MSignature): AMethPropdef do
		var m_def = new MMethodDef(mclassdef, mproperty, mclassdef.location)

		if msignature == null then msignature = new MSignature(new Array[MParameter])

		m_def.msignature = msignature
		m_def.is_abstract = true
		var n_def = m_def.create_ast_representation
		# Association new npropdef to mpropdef
		unsafe_add_mpropdef2npropdef(m_def,n_def)

		if not is_abstract then
			n_def.mpropdef.is_abstract = false
			n_def.n_block = new ABlockExpr.make
		end

		return n_def
	end

	# Creation of a new attribute (AST and model representation) with the given name.
	# See `create_attribute_from_property` for more information.
	fun create_attribute_from_name(name: String, mclassdef: MClassDef, mtype: MType, visibility: nullable MVisibility): AAttrPropdef do
		if visibility == null then visibility = public_visibility
		var mattribute = try_get_mproperty_by_name(null, mclassdef, name)
		if mattribute == null then mattribute = new MAttribute(mclassdef, name, mclassdef.location, visibility)
		return create_attribute_from_property(mattribute.as(MAttribute), mclassdef, mtype)
	end

	# Creation of a new attribute (AST and model representation) with the given MAttribute.
	# See `create_attribute_from_propdef` for more information.
	fun create_attribute_from_property(mattribute: MAttribute, mclassdef: MClassDef, mtype: MType): AAttrPropdef do
		var attribut_def = new MAttributeDef(mclassdef, mattribute, mclassdef.location)
		attribut_def.static_mtype = mtype
		return create_attribute_from_propdef(attribut_def)
	end

	# Creation of a new attribute (AST representation) with the given MAttributeDef.
	fun create_attribute_from_propdef(mattribut_def: MAttributeDef): AAttrPropdef
	is
		expect(mclassdef2node(mattribut_def.mclassdef) != null)
	do
		var n_attribute = mattribut_def.create_ast_representation

		var nclass = mclassdef2node(mattribut_def.mclassdef)

		n_attribute.location = mattribut_def.location
		n_attribute.validate

		nclass.n_propdefs.unsafe_add_all([n_attribute])
		nclass.validate

		n_attribute.build_read_property(self, mattribut_def.mclassdef)
		n_attribute.build_read_signature

		mpropdef2npropdef[mattribut_def] = n_attribute
		return n_attribute
	end

	# Creation of a new class (AST and model representation) with the given name.
	# `visibility` : Define the visibility of the method. If it's `null` the default is `public_visibility`
	# See `create_class_from_mclass` for more information.
	fun create_class_from_name(name: String, super_type: Array[MClassType], mmodule: MModule, visibility: nullable MVisibility): AStdClassdef do
		if visibility == null then visibility = public_visibility
		var mclass = try_get_mclass_by_name(null, mmodule, name)
		if mclass == null then mclass = new MClass(mmodule, name, mmodule.location, new Array[String], concrete_kind, visibility)
		return create_class_from_mclass(mclass, super_type, mmodule)
	end

	# Creation of a new class (AST and model representation) with the given MClass.
	# This method creates a new concrete class definition `MClassDef`, and adds it to the class hierarchy.
	# See `create_class_from_mclassdef` for more information.
	fun create_class_from_mclass(mclass: MClass, super_type: Array[MClassType], mmodule: MModule): AStdClassdef do
		var mclassdef = new MClassDef(mmodule, mclass.mclass_type, mmodule.location)
		mclassdef.set_supertypes(super_type)
		mclassdef.add_in_hierarchy

		return create_class_from_mclassdef(mclassdef, mmodule)
	end

	# Creation of a new class (AST representation) with the given MClassDef.
	# Note all the properties of our MClassDef will also generate an AST representation.
	# Make an error if the attribute already has a representation in the modelbuilder.
	# This method also create the default constructor.
	fun create_class_from_mclassdef(mclassdef: MClassDef, mmodule: MModule): AStdClassdef do
		var n_classdef = mclassdef.create_ast_representation
		n_classdef.location = mclassdef.location
		n_classdef.validate

		for n_propdef in n_classdef.n_propdefs do
			var mpropdef = n_propdef.mpropdef
			assert mpropdef != null

			var p_npropdef = mpropdef2node(mpropdef)
			if  p_npropdef != null then error(null, "The property `{mpropdef.name}` already has a representation in the AST.")
			unsafe_add_mpropdef2npropdef(mpropdef, n_propdef)
		end

		process_default_constructors(n_classdef)
		unsafe_add_mclassdef2nclassdef(mclassdef, n_classdef)

		return n_classdef
	end
end
src/astbuilder.nit:15,1--1158,3