Skip to content

Commit

Permalink
Merge: Qualified class identifiers
Browse files Browse the repository at this point in the history
Extends the parsed and the AST to handle qualified class identifiers.

Now you can parse

~~~nit
redef class m0::A
        super m1::S
        redef type m2::B::T: Int
        fun foo: m3::G[m4::C] do end
end
~~~

Currently, the class qualifiers, if any, are just ignored by semantic phases. Like with method qualifiers.

Pull-Request: #1900
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
  • Loading branch information
privat committed Dec 16, 2015
2 parents e47f39f + 674f585 commit 54b20e9
Show file tree
Hide file tree
Showing 18 changed files with 5,104 additions and 4,764 deletions.
5 changes: 4 additions & 1 deletion src/astbuilder.nit
Expand Up @@ -256,7 +256,10 @@ end
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

Expand Down
10 changes: 6 additions & 4 deletions src/frontend/parallelization_phase.nit
Expand Up @@ -52,7 +52,7 @@ private class ParallelizationPhase

# Try to get the name of the class
if nmethdef.parent isa AStdClassdef then
classname += nmethdef.parent.as(AStdClassdef).n_id.text
classname += nmethdef.parent.as(AStdClassdef).n_qid.n_id.text
end

# Try to get the name of the method
Expand All @@ -64,19 +64,21 @@ private class ParallelizationPhase
var has_rvalue = nmethdef.n_signature.n_type != null
var vtype = ""
if has_rvalue then
vtype = "redef type E: " + nmethdef.n_signature.n_type.n_id.text
vtype = "redef type E: " + nmethdef.n_signature.n_type.n_qid.n_id.text
end

# create a return type
var n_id = new TClassid
n_id.text = classname
var n_qid = new AQclassid
n_qid.n_id = n_id
var n_type = new AType
n_type.n_id = n_id
n_type.n_qid = n_qid
nmethdef.n_signature.n_type = n_type

var params = new Array[String]
for param in nmethdef.n_signature.n_params do
var typ = param.n_type.n_id.text
var typ = param.n_type.n_qid.n_id.text
if param.n_type.n_kwnullable != null then typ = "nullable {typ}"
params.add """
var {{{param.n_id.text}}}: {{{typ}}}
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/serialization_phase.nit
Expand Up @@ -250,7 +250,7 @@ do
end

for nclassdef in nclassdefs do
var name = nclassdef.n_id.text
var name = nclassdef.n_qid.n_id.text
if nclassdef.n_formaldefs.is_empty and
nclassdef.n_classkind isa AConcreteClasskind then

Expand Down Expand Up @@ -321,7 +321,7 @@ end
redef class AType
private fun type_name: String
do
var name = n_id.text
var name = n_qid.n_id.text

if n_kwnullable != null then name = "nullable {name}"

Expand All @@ -338,7 +338,7 @@ redef class AModule
private fun deserializer_nclassdef: nullable AStdClassdef
do
for nclassdef in n_classdefs do
if nclassdef isa AStdClassdef and nclassdef.n_id.text == "Deserializer" then
if nclassdef isa AStdClassdef and nclassdef.n_qid.n_id.text == "Deserializer" then
return nclassdef
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/modelbuilder_base.nit
Expand Up @@ -235,7 +235,7 @@ class ModelBuilder
# FIXME: the name "resolve_mtype" is awful
fun resolve_mtype_unchecked(mmodule: MModule, mclassdef: nullable MClassDef, ntype: AType, with_virtual: Bool): nullable MType
do
var name = ntype.n_id.text
var name = ntype.n_qid.n_id.text
var res: MType

# Check virtual type
Expand Down
2 changes: 1 addition & 1 deletion src/modelize/modelize_class.nit
Expand Up @@ -47,7 +47,7 @@ redef class ModelBuilder
var arity = 0
var names = new Array[String]
if nclassdef isa AStdClassdef then
name = nclassdef.n_id.text
name = nclassdef.n_qid.n_id.text
nkind = nclassdef.n_classkind
mkind = nkind.mkind
nvisibility = nclassdef.n_visibility
Expand Down
6 changes: 3 additions & 3 deletions src/modelize/modelize_property.nit
Expand Up @@ -1570,13 +1570,13 @@ redef class ATypePropdef

redef fun build_property(modelbuilder, mclassdef)
do
var name = self.n_id.text
var mprop = modelbuilder.try_get_mproperty_by_name(self.n_id, mclassdef, name)
var name = self.n_qid.n_id.text
var mprop = modelbuilder.try_get_mproperty_by_name(self.n_qid, mclassdef, name)
if mprop == null then
var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
mprop = new MVirtualTypeProp(mclassdef, name, mvisibility)
for c in name.chars do if c >= 'a' and c<= 'z' then
modelbuilder.warning(n_id, "bad-type-name", "Warning: lowercase in the virtual type `{name}`.")
modelbuilder.warning(n_qid, "bad-type-name", "Warning: lowercase in the virtual type `{name}`.")
break
end
else
Expand Down
24 changes: 14 additions & 10 deletions src/parser/nit.sablecc3xx
Expand Up @@ -258,8 +258,8 @@ implicit_main_meth {-> propdef}

/* CLASSES *******************************************************************/
classdef
= [doc]:nd redef visibility classkind no qclassid extern_code_block? propdefs kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, qclassid.classid, Null, [], Null, extern_code_block, [propdefs.propdef], kwend)}
| {for} [doc]:nd redef visibility classkind no qclassid obra [n2]:no formaldefs cbra extern_code_block? propdefs kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, qclassid.classid, obra, [formaldefs.formaldef], cbra, extern_code_block, [propdefs.propdef], kwend)}
= [doc]:nd redef visibility classkind no qclassid extern_code_block? propdefs kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, qclassid, Null, [], Null, extern_code_block, [propdefs.propdef], kwend)}
| {for} [doc]:nd redef visibility classkind no qclassid obra [n2]:no formaldefs cbra extern_code_block? propdefs kwend {-> New classdef.std(doc.doc, redef.kwredef, visibility, classkind, qclassid, obra, [formaldefs.formaldef], cbra, extern_code_block, [propdefs.propdef], kwend)}
;

redef {-> kwredef?}
Expand Down Expand Up @@ -303,7 +303,7 @@ propdef~toplevel {-> propdef}
!toplevel| {var4} [doc]:nd redef visibility kwvar id typing_o assign [n2]:no expr annotation_withend {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, assign, expr.expr, annotation_withend.annotations, Null, Null, Null)}
!toplevel| {var5} [doc]:nd redef visibility kwvar id typing_o annotation_noend? kwdo stmtso kwend? {-> New propdef.attr(doc.doc, redef.kwredef, visibility, kwvar, id, typing_o.type, Null, Null, annotation_noend.annotations, kwdo, stmtso.expr, kwend)}
!toplevel| {init} [doc]:nd redef visibility kwinit qmethid? signature annotation_noend? kwdo stmtso kwend_o {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, kwinit, Null, qmethid.methid, signature, annotation_noend.annotations, Null, Null, kwdo, stmtso.expr, kwend_o.kwend)}
!toplevel| {type} [doc]:nd redef visibility kwtype classid typing annotation_withend {-> New propdef.type(doc.doc, redef.kwredef, visibility, kwtype, classid, typing.type, annotation_withend.annotations)}
!toplevel| {type} [doc]:nd redef visibility kwtype qclassid typing annotation_withend {-> New propdef.type(doc.doc, redef.kwredef, visibility, kwtype, qclassid, typing.type, annotation_withend.annotations)}
!toplevel| {extern_init_implicit} [doc]:nd redef visibility kwnew qmethid? signature annotation_noend? extern_calls extern_code_block {-> New propdef.meth(doc.doc, redef.kwredef, visibility, Null, Null, kwnew, qmethid.methid, signature, annotation_noend.annotations, extern_calls, extern_code_block, Null, Null, Null)}
!toplevel| {annot} line_annotation_forclass {-> line_annotation_forclass.propdef}
!toplevel| {super} superclass {-> superclass.propdef}
Expand Down Expand Up @@ -407,8 +407,8 @@ extern_code_body {-> extern_code_block} = no extern_code_block {-> extern_code_b

/* TYPES *********************************************************************/
type~nobra~nopar {-> type}
= {simple} kwnullable? classid annotations_o~nopar {-> New type(kwnullable, classid, Null, [], Null, annotations_o~nopar.annotations)}
!nobra | {generic} kwnullable? classid obra no types [n2]:no cbra annotations_o~nopar {-> New type(kwnullable, classid, obra, [types.type], cbra, annotations_o~nopar.annotations)}
= {simple} kwnullable? qclassid annotations_o~nopar {-> New type(kwnullable, qclassid, Null, [], Null, annotations_o~nopar.annotations)}
!nobra | {generic} kwnullable? qclassid obra no types [n2]:no cbra annotations_o~nopar {-> New type(kwnullable, qclassid, obra, [types.type], cbra, annotations_o~nopar.annotations)}
;
types {-> type*}
= type types_tail* {-> [type, types_tail.type]};
Expand Down Expand Up @@ -826,8 +826,8 @@ qualified_o {-> qualified?}
qid
= qualified? id
;
qclassid {-> classid}
= qualified? classid {-> classid}
qclassid
= qualified? classid
;
qmethid~noid {-> methid}
= qualified? methid~noid {-> methid~noid.methid}
Expand Down Expand Up @@ -889,7 +889,7 @@ visibility
| {intrude} kwintrude
;

classdef= {std} doc? kwredef? visibility classkind [id]:classid? obra? [formaldefs]:formaldef* cbra? extern_code_block? [propdefs]:propdef* kwend
classdef= {std} doc? kwredef? visibility classkind [qid]:qclassid? obra? [formaldefs]:formaldef* cbra? extern_code_block? [propdefs]:propdef* kwend
| {top} [propdefs]:propdef*
| {main} [propdefs]:propdef*
;
Expand All @@ -905,7 +905,7 @@ formaldef = [id]:classid type? annotations?;

propdef = {attr} doc? kwredef? visibility kwvar [id2]:id type? assign? expr? annotations? kwdo? [block]:expr? kwend?
| {main_meth} kwredef? [block]:expr?
| {type} doc? kwredef? visibility kwtype [id]:classid type annotations?
| {type} doc? kwredef? visibility kwtype [qid]:qclassid type annotations?
| {meth} doc? kwredef? visibility kwmeth? kwinit? kwnew? methid? signature annotations? extern_calls? extern_code_block? kwdo? [block]:expr? kwend?
| {super} doc? kwredef? visibility kwsuper type annotations?
| {annot} doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?
Expand Down Expand Up @@ -941,12 +941,16 @@ qid
= qualified? id
;

qclassid
= qualified? [id]:classid
;

signature = opar? [params]:param* cpar? type?;

param = id type? dotdotdot? annotations?
;

type = kwnullable? [id]:classid obra? [types]:type* cbra? annotations?;
type = kwnullable? [qid]:qclassid obra? [types]:type* cbra? annotations?;

label = kwlabel id?;

Expand Down

0 comments on commit 54b20e9

Please sign in to comment.