nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: parse_examples: minor fixes
[nit.git]
/
src
/
astbuilder.nit
diff --git
a/src/astbuilder.nit
b/src/astbuilder.nit
index
428a5ca
..
79d0ba1
100644
(file)
--- a/
src/astbuilder.nit
+++ b/
src/astbuilder.nit
@@
-16,26
+16,26
@@
module astbuilder
intrude import semantize::typing
module astbuilder
intrude import semantize::typing
-intrude import semantize::literal
-intrude import semantize::parser
+intrude import literal
+intrude import parser
intrude import semantize::scope
# General factory to build semantic nodes in the AST of expressions
class ASTBuilder
# The module used as reference for the building
intrude import semantize::scope
# 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 stufs
+ # 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
# Make a new Int literal
var mmodule: MModule
# The anchor used for some mechanism relying on types
var anchor: nullable MClassType
# Make a new Int literal
- fun make_int(value: Int): AIntExpr
+ fun make_int(value: Int): AIntegerExpr
do
do
- return new ADecIntExpr.make(value, mmodule.get_primitive_class("Int").mclass_type)
+ return new AIntegerExpr.make(value, mmodule.int_type)
end
end
- # Make a new instatiation
+ # Make a new instantiation
fun make_new(callsite: CallSite, args: nullable Array[AExpr]): ANewExpr
do
return new ANewExpr.make(callsite, args)
fun make_new(callsite: CallSite, args: nullable Array[AExpr]): ANewExpr
do
return new ANewExpr.make(callsite, args)
@@
-96,7
+96,7
@@
class ASTBuilder
return new ABreakExpr.make(escapemark)
end
return new ABreakExpr.make(escapemark)
end
- # Make a new condinionnal
+ # 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
# `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
@@
-128,17
+128,19
@@
redef class AExpr
private var variable_cache: nullable Variable
# The `detach` method completely remove the node in the parent.
private var variable_cache: nullable Variable
# The `detach` method completely remove the node in the parent.
- # Owever, sometime, it is useful to keep the emplacement of the removed child.
+ # However, sometime, it is useful to keep the emplacement of the removed child.
#
#
- # The standard usecase is the insertion of a node beetwen a parent `p` and a child `p.c`.
+ # 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.
#
# 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.
#
- # var p: AExpr
- # var c = p.c
- # var h = c.detach_with_placeholder
- # var n = astbuilder.make_XXX(c)
- # h.replace_with(n)
+ # ~~~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
fun detach_with_placeholder: AExpr
do
var h = new APlaceholderExpr.make
@@
-154,13
+156,13
@@
redef class AExpr
# 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
# 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 inplemented in {inspect}"
+ print "add not implemented in {inspect}"
abort
end
end
# A placeholder for a `AExpr` node
abort
end
end
# A placeholder for a `AExpr` node
-# Instances are transiantly used to mark some specific emplacments in the AST
+# Instances are transiantly used to mark some specific emplacements in the AST
# during complex transformations.
#
# Their must not appear in a valid AST
# during complex transformations.
#
# Their must not appear in a valid AST
@@
-179,7
+181,7
@@
redef class ABlockExpr
self.is_typed = true
end
self.is_typed = true
end
- redef fun add(expr: AExpr)
+ redef fun add(expr)
do
n_expr.add expr
end
do
n_expr.add expr
end
@@
-194,7
+196,7
@@
redef class ALoopExpr
n_block.is_typed = true
end
n_block.is_typed = true
end
- redef fun add(expr: AExpr)
+ redef fun add(expr)
do
n_block.add expr
end
do
n_block.add expr
end
@@
-220,7
+222,7
@@
redef class ADoExpr
return new ABreakExpr.make(escapemark)
end
return new ABreakExpr.make(escapemark)
end
- redef fun add(expr: AExpr)
+ redef fun add(expr)
do
n_block.add expr
end
do
n_block.add expr
end
@@
-242,7
+244,9
@@
redef class AIfExpr
_n_kwif = new TKwif
_n_expr = condition
_n_expr.parent = self
_n_kwif = new TKwif
_n_expr = condition
_n_expr.parent = self
+ _n_kwthen = new TKwthen
_n_then = new ABlockExpr.make
_n_then = new ABlockExpr.make
+ _n_kwelse = new TKwelse
_n_else = new ABlockExpr.make
self.mtype = mtype
self.is_typed = true
_n_else = new ABlockExpr.make
self.mtype = mtype
self.is_typed = true
@@
-252,15
+256,18
@@
end
redef class AType
private init make
do
redef class AType
private init make
do
- _n_id = new TClassid
+ var n_id = new TClassid
+ var n_qid = new AQclassid
+ n_qid.n_id = n_id
+ _n_qid = n_qid
end
end
end
end
-redef class ADecIntExpr
+redef class AIntegerExpr
private init make(value: Int, t: MType)
do
self.value = value
private init make(value: Int, t: MType)
do
self.value = value
- self._n_number = new TNumber # dummy
+ self._n_integer = new TInteger # dummy
self.mtype = t
end
end
self.mtype = t
end
end
@@
-275,7
+282,12
@@
redef class ANewExpr
n_args.n_exprs.add_all(args)
end
self.callsite = callsite
n_args.n_exprs.add_all(args)
end
self.callsite = callsite
- self.mtype = callsite.recv
+ 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
self.is_typed = true
end
end
@@
-285,11
+297,11
@@
redef class ACallExpr
do
self._n_expr = recv
_n_args = new AListExprs
do
self._n_expr = recv
_n_args = new AListExprs
- _n_id = new TId
+ _n_qid = new AQid
+ _n_qid.n_id = new TId
if args != null then
self.n_args.n_exprs.add_all(args)
end
if args != null then
self.n_args.n_exprs.add_all(args)
end
- var mtype = recv.mtype.as(not null)
self.callsite = callsite
self.mtype = callsite.msignature.return_mtype
self.is_typed = true
self.callsite = callsite
self.mtype = callsite.msignature.return_mtype
self.is_typed = true