Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
* lang_python/analyze/python_to_generic.ml: expr_to_attribute to
Browse files Browse the repository at this point in the history
transform some calls in NamedAttr

will help again

test plan:
$ ~/pfff/pfff_test -dump_generic less_attributes.py
Pr(
  [DefStmt(
     ({name=("foo", ());
       attrs=[NamedAttr(("alpha", ()), []); NamedAttr(("beta", ()), []);
              NamedAttr(("charlie", ()), [Arg(L(String(("xyz", ()))))])];
       tparams=[]; info={id_resolved=Ref(None); id_type=Ref(None); }; },
      FuncDef(
        {fparams=[]; frettype=None;
         fbody=ExprStmt(
...
  • Loading branch information
aryx committed Feb 3, 2020
1 parent b15e09d commit 3a208b7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion h_program-lang/ast_generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ and type_ =
and attribute =
| KeywordAttr of keyword_attribute wrap
(* for general @annotations *)
| NamedAttr of ident * any list
| NamedAttr of ident * argument list

| OtherAttribute of other_attribute_operator * any list

Expand Down Expand Up @@ -909,6 +909,7 @@ let expr_to_pattern e =
OtherPat (OP_ExprPattern, [E e])

(* see also Java_to_generic.entity_to_param *)
(* see also python_to_generic.expr_to_attribute *)

(* should avoid; should prefer to use 'expr option' in the AST *)
let opt_to_nop opt =
Expand Down
2 changes: 1 addition & 1 deletion lang_GENERIC/parsing/map_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ and map_attribute = function
KeywordAttr v1
| NamedAttr ((v1, v2)) ->
let v1 = map_ident v1
and v2 = map_of_list map_any v2
and v2 = map_of_list map_argument v2
in NamedAttr ((v1, v2))
| OtherAttribute ((v1, v2)) ->
let v1 = map_other_attribute_operator v1
Expand Down
2 changes: 1 addition & 1 deletion lang_GENERIC/parsing/meta_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ and vof_attribute = function
Ocaml.VSum (("KeywordAttr", [v1]))
| NamedAttr ((v1, v2)) ->
let v1 = vof_ident v1
and v2 = Ocaml.vof_list vof_any v2
and v2 = Ocaml.vof_list vof_argument v2
in Ocaml.VSum (("NamedAttr", [ v1; v2 ]))
| OtherAttribute ((v1, v2)) ->
let v1 = vof_other_attribute_operator v1
Expand Down
2 changes: 1 addition & 1 deletion lang_GENERIC/parsing/visitor_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ and v_attribute x =
let k x =
match x with
| KeywordAttr v1 -> let v1 = v_wrap v_keyword_attribute v1 in ()
| NamedAttr ((v1, v2)) -> let v1 = v_ident v1 and v2 = v_list v_any v2 in ()
| NamedAttr ((v1, v2)) -> let v1 = v_ident v1 and v2 = v_list v_argument v2 in ()
| OtherAttribute ((v1, v2)) ->
let v1 = v_other_attribute_operator v1 and v2 = v_list v_any v2 in ()
in
Expand Down
8 changes: 7 additions & 1 deletion lang_python/analyze/python_to_generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,15 @@ and excepthandler =
pat, v3
)

and expr_to_attribute v =
match v with
| G.Call (G.Name ((id, _), _), args) ->
G.NamedAttr (id, args)
| _ -> G.OtherAttribute (G.OA_Expr, [G.E v])

and decorator v =
let v = expr v in
G.OtherAttribute (G.OA_Expr, [G.E v])
expr_to_attribute v

and alias (v1, v2) =
let v1 = name v1 and v2 = option name v2 in
Expand Down

0 comments on commit 3a208b7

Please sign in to comment.