Merge: More binary operators
authorJean Privat <jean@pryen.org>
Fri, 24 Apr 2015 08:24:01 +0000 (15:24 +0700)
committerJean Privat <jean@pryen.org>
Fri, 24 Apr 2015 08:24:01 +0000 (15:24 +0700)
The first part of the PR cleanup and factorize some things related to the operators in the grammar and the AST.
Then the four bitwise operators are added.

Close #1271 unless some more thing is added to it (like generalized unary operators)

Note: as usual, github is useless when the parser is regenerated, so review the individual commits if you prefer.

Pull-Request: #1295
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

1  2 
src/semantize/typing.nit

diff --combined src/semantize/typing.nit
@@@ -453,26 -453,12 +453,26 @@@ private class TypeVisito
                if vararg_rank >= 0 then
                        var paramtype = msignature.mparameters[vararg_rank].mtype
                        var first = args[vararg_rank]
 -                      if vararg_decl == 0 and first isa AVarargExpr then
 +                      if vararg_decl == 0 then
                                var mclass = get_mclass(node, "Array")
                                if mclass == null then return null # Forward error
                                var array_mtype = mclass.get_mtype([paramtype])
 -                              self.visit_expr_subtype(first.n_expr, array_mtype)
 -                              first.mtype  = first.n_expr.mtype
 +                              if first isa AVarargExpr then
 +                                      self.visit_expr_subtype(first.n_expr, array_mtype)
 +                                      first.mtype  = first.n_expr.mtype
 +                              else
 +                                      # only one vararg, maybe `...` was forgot, so be gentle!
 +                                      var t = visit_expr(first)
 +                                      if t == null then return null # Forward error
 +                                      if not is_subtype(t, paramtype) and is_subtype(t, array_mtype) then
 +                                              # Not acceptable but could be a `...`
 +                                              error(first, "Type Error: expected `{paramtype}`, got `{t}`. Is an ellipsis `...` missing on the argument?")
 +                                              return null
 +                                      end
 +                                      # Standard valid vararg, finish the job
 +                                      map.vararg_decl = 1
 +                                      self.visit_expr_subtype(first, paramtype)
 +                              end
                        else
                                map.vararg_decl = vararg_decl + 1
                                for i in [vararg_rank..vararg_rank+vararg_decl] do
@@@ -1655,13 -1641,8 +1655,8 @@@ redef class ANeExp
        end
  end
  
- redef class AUplusExpr
-       redef fun property_name do return "unary +"
-       redef fun compute_raw_arguments do return new Array[AExpr]
- end
- redef class AUminusExpr
-       redef fun property_name do return "unary -"
+ redef class AUnaryopExpr
+       redef fun property_name do return "unary {operator}"
        redef fun compute_raw_arguments do return new Array[AExpr]
  end