ast: remove classes AAtArg and make them simple AExpr
authorJean Privat <jean@pryen.org>
Thu, 16 Oct 2014 01:18:46 +0000 (21:18 -0400)
committerJean Privat <jean@pryen.org>
Fri, 17 Oct 2014 01:29:26 +0000 (21:29 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/annotation.nit
src/ffi/c_compiler_options.nit
src/nitpretty.nit
src/parser/nit.sablecc3xx
src/parser/parser_nodes.nit

index 6641280..3223b7c 100644 (file)
@@ -100,37 +100,31 @@ redef class AAnnotation
        end
 end
 
-redef class AAtArg
+redef class AExpr
        # Get `self` as a `String`.
        # Return null if not a string.
        fun as_string: nullable String
        do
-               if not self isa AExprAtArg then return null
-               var nexpr = n_expr
-               if not nexpr isa AStringFormExpr then return null
-               return nexpr.value.as(not null)
+               if not self isa AStringFormExpr then return null
+               return self.value.as(not null)
        end
 
        # Get `self` as an `Int`.
        # Return null if not an integer.
        fun as_int: nullable Int
        do
-               if not self isa AExprAtArg then return null
-               var nexpr = n_expr
-               if not nexpr isa AIntExpr then return null
-               return nexpr.value.as(not null)
+               if not self isa AIntExpr then return null
+               return self.value.as(not null)
        end
 
        # Get `self` as a single identifier.
        # Return null if not a single identifier.
        fun as_id: nullable String
        do
-               if not self isa AExprAtArg then return null
-               var nexpr = n_expr
-               if not nexpr isa ACallExpr then return null
-               if not nexpr.n_expr isa AImplicitSelfExpr then return null
-               if not nexpr.n_args.n_exprs.is_empty then return null
-               return nexpr.n_id.text
+               if not self isa ACallExpr then return null
+               if not self.n_expr isa AImplicitSelfExpr then return null
+               if not self.n_args.n_exprs.is_empty then return null
+               return self.n_id.text
        end
 end
 
index 7717973..1d82c0d 100644 (file)
@@ -57,13 +57,7 @@ private class CCompilerOptionsPhase
                end
 
                var options = new Array[CCompilerOption]
-               for arg in args do
-                       if not arg isa AExprAtArg then
-                               modelbuilder.error(nat, "Syntax error: \"{annotation_name}\" expects its arguments to be the name of the package as String literals or a call to `exex(\"local_program\")`.")
-                               return
-                       end
-
-                       var expr = arg.n_expr
+               for expr in args do
                        if expr isa AStringFormExpr then
                                var text = expr.collect_text
                                text = text.substring(1, text.length-2)
index e7a733a..f43c8d1 100644 (file)
@@ -627,14 +627,10 @@ redef class AAnnotation
        end
 end
 
-redef class ATypeAtArg
+redef class ATypeExpr
        redef fun accept_pretty_printer(v) do v.visit n_type
 end
 
-redef class AExprAtArg
-       redef fun accept_pretty_printer(v) do v.visit n_expr
-end
-
 # Modules
 
 redef class AModule
index a1b367b..ad3ad66 100644 (file)
@@ -559,7 +559,7 @@ expr_single~nopar~nobra {-> expr}
        | {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
        | {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
        | {superstring} superstring  {-> superstring.expr}
-!nopar | {par} opar no expr [n2]:no cpar annotations_o {-> New expr.par(opar, expr, cpar, annotations_o.annotations)}
+!nopar | {par} opar no any_expr [n2]:no cpar annotations_o {-> New expr.par(opar, any_expr.expr, cpar, annotations_o.annotations)}
 // !nopar to unambiguise 'foo[5].bar' between '(foo[5]).bar' and 'foo([5].bar),
 !nobra!nopar   | {range} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no cbra annotations_o {-> New expr.crange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
 !nobra!nopar   | {orange} obra no expr [n2]:no dotdot [n3]:no [expr2]:expr_nobra [n4]:no [cbra]:obra annotations_o {-> New expr.orange(obra, expr, expr2.expr, cbra, annotations_o.annotations)}
@@ -597,7 +597,7 @@ annotations_o~nopar {-> annotations?}
 one_annotation~nopar {-> annotation}
        = {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
 // !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
-!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.at_arg], cpar, annotations_o~nopar.annotations)}
+!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.expr], cpar, annotations_o~nopar.annotations)}
        ;
 
 many_annotations {-> annotations}
@@ -611,12 +611,12 @@ annotation_list {-> annotation*}
 one_annotation_list~nopar {-> annotation}
        = {alone} redef visibility atid annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [], Null, annotations_o~nopar.annotations)}
 // !nopar to unambiguise 'new T@foo(bar)' between 'new T@(foo(bar))' and 'new (T@foo)(bar)'
-!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.at_arg], cpar, annotations_o~nopar.annotations)}
-!nopar | {nopar} redef visibility atid at_arg_single {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [at_arg_single.at_arg], Null, Null)}
+!nopar | {args} redef visibility atid opar no at_args [n2]:no cpar annotations_o~nopar {-> New annotation(Null, redef.kwredef, visibility, atid, opar, [at_args.expr], cpar, annotations_o~nopar.annotations)}
+!nopar | {nopar} redef visibility atid at_arg_single {-> New annotation(Null, redef.kwredef, visibility, atid, Null, [at_arg_single.expr], Null, Null)}
        ;
-at_arg_single {-> at_arg}
+at_arg_single {-> expr}
 // FIXME: why expr_single but not expr_atom is not clear :(
-       = {expr} [expr]:expr_single_nopar {-> New at_arg.expr(expr.expr)}
+       = {expr} [expr]:expr_single_nopar {-> expr.expr}
        ;
 
 annotations_tail {-> annotation}
@@ -628,31 +628,31 @@ line_annotations {-> annotations}
        ;
 line_annotation {-> annotation}
        = [doc]:no redef visibility atid annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [], Null, annotations)}
-       | {args} [doc]:no redef visibility atid opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, opar, [at_args.at_arg], cpar, annotations)}
-       | {nopar} [doc]:no redef visibility atid at_args_nopar n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [at_args_nopar.at_arg], Null, Null)}
+       | {args} [doc]:no redef visibility atid opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, opar, [at_args.expr], cpar, annotations)}
+       | {nopar} [doc]:no redef visibility atid at_args_nopar n1 {-> New annotation(doc.doc, redef.kwredef, visibility, atid.atid, Null, [at_args_nopar.expr], Null, Null)}
        ;
 line_annotations_forclass {-> annotations}
        = line_annotation_forclass+ {-> New annotations(Null, Null, [line_annotation_forclass.annotation], Null) }
        ;
 line_annotation_forclass {-> annotation}
        = [doc]:no atid_forclass annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [], Null, annotations)}
-       | {args} [doc]:no atid_forclass opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, opar, [at_args.at_arg], cpar, annotations)}
-       | {nopar} [doc]:no atid_forclass at_args_nopar n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [at_args_nopar.at_arg], Null, Null)}
+       | {args} [doc]:no atid_forclass opar no at_args cpar annotations? n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, opar, [at_args.expr], cpar, annotations)}
+       | {nopar} [doc]:no atid_forclass at_args_nopar n1 {-> New annotation(doc.doc, Null, Null, atid_forclass.atid, Null, [at_args_nopar.expr], Null, Null)}
        ;
 
-at_args~nopar {-> at_arg* }
-       = {many} at_arg~nopar at_args_tail* {-> [at_arg~nopar.at_arg, at_args_tail.at_arg]}
+at_args~nopar {-> expr* }
+       = {many} any_expr~nopar at_args_tail* {-> [any_expr~nopar.expr, at_args_tail.expr]}
        ;
 
-at_args_tail {-> at_arg}
-       = comma no at_arg {-> at_arg}
+at_args_tail {-> expr}
+       = comma no any_expr {-> any_expr.expr}
        ;
 
-at_arg~nopar {-> at_arg}
-       = {type} type {-> New at_arg.type(type)}
-       | {expr} expr~nopar {-> New at_arg.expr(expr~nopar.expr)}
-       | {stmt} stmt_noexpr~nopar {-> New at_arg.expr(stmt_noexpr~nopar.expr)}
-!nopar | {at} annotations {-> New at_arg.at(annotations.annotations)}
+any_expr~nopar {-> expr}
+       = {type} type {-> New expr.type(type)}
+       | {expr} expr~nopar {-> expr~nopar.expr}
+       | {stmt} stmt_noexpr~nopar {-> stmt_noexpr~nopar.expr}
+!nopar | {at} annotations {-> New expr.at(annotations.annotations)}
        ;
 
 atid~forclass {-> atid}
@@ -869,6 +869,8 @@ expr        = {block} expr* kwend?
        | {isset_attr} kwisset expr [id]:attrid
        | {debug_type} kwdebug kwtype expr type
        | {vararg} expr dotdotdot
+       | {type} type
+       | {at} annotations
        ;
 exprs
        = {list} [exprs]:expr*
@@ -901,13 +903,8 @@ doc = comment+;
 
 annotations = at? opar? [items]:annotation* cpar?;
 
-annotation = doc? kwredef? visibility? atid opar? [args]:at_arg* cpar? annotations?;
+annotation = doc? kwredef? visibility? atid opar? [args]:expr* cpar? annotations?;
 
-at_arg
-       = {type} type
-       | {expr} expr
-       | {at} annotations
-       ;
 atid = {id} id | {kwextern} [id]:kwextern | {kwabstract} [id]:kwabstract | {kwimport} [id]:kwimport;
 
 /*****************************************************************************/
index 30faf18..4a27d61 100644 (file)
@@ -1897,10 +1897,17 @@ class AVarargExpr
        var n_dotdotdot: TDotdotdot is writable, noinit
 end
 
-# A list of expression separated with commas (arguments for instance)
-abstract class AExprs
-       super Prod 
-       var n_exprs = new ANodes[AExpr](self)
+# A special expression that encapsulates a static type
+# Can only be found in special construction like arguments of annotations.
+class ATypeExpr
+       super AExpr
+       var n_type: AType is writable, noinit
+end
+
+# A special expression that encapsulate an annotation
+# Can only be found in special construction like arguments of annotations.
+class AAtExpr
+       super AExpr
 end
 
 # A special expression to debug types
@@ -1912,6 +1919,12 @@ class ADebugTypeExpr
        var n_type: AType is writable, noinit
 end
 
+# A list of expression separated with commas (arguments for instance)
+abstract class AExprs
+       super Prod
+       var n_exprs = new ANodes[AExpr](self)
+end
+
 # A simple list of expressions
 class AListExprs
        super AExprs
@@ -2002,32 +2015,10 @@ class AAnnotation
        var n_visibility: nullable AVisibility is writable
        var n_atid: AAtid is writable, noinit
        var n_opar: nullable TOpar = null is writable
-       var n_args = new ANodes[AAtArg](self)
+       var n_args = new ANodes[AExpr](self)
        var n_cpar: nullable TCpar = null is writable
 end
 
-# A single argument of an annotation
-abstract class AAtArg
-       super Prod
-end
-
-# A type-like argument of an annotation
-class ATypeAtArg
-       super AAtArg
-       var n_type: AType is writable, noinit
-end
-
-# An expression-like argument of an annotation
-class AExprAtArg
-       super AAtArg
-       var n_expr: AExpr is writable, noinit
-end
-
-# An annotation-like argument of an annotation
-class AAtAtArg
-       super AAtArg
-end
-
 # An annotation name
 abstract class AAtid
        super Prod