Permalink
Browse files

* demos/: fix compilation errors (long time ...)

  • Loading branch information...
1 parent bbd1cdd commit 5a98cd86c7af796dfa836f6ed897fe59ee33d668 @aryx aryx committed Dec 13, 2012
View
@@ -3,6 +3,8 @@
# This is to show how to build a simple Makefile from scratch
# to people who wants to use pfff in their own application.
+all: simple_refactoring check_is_static_literal find_methods_return_this
+
##############################################################################
# Simple compilation
##############################################################################
@@ -18,7 +20,7 @@ simple_refactoring: simple_refactoring.ml
simple_refactoring.ml
clean::
- rm simple_refactoring
+ rm -f simple_refactoring
check_is_static_literal: check_is_static_literal.cmo
ocamlc -g -o $@ \
@@ -29,7 +31,18 @@ check_is_static_literal: check_is_static_literal.cmo
$^
clean::
- rm check_is_static_literal
+ rm -f check_is_static_literal
+
+find_methods_return_this: find_methods_return_this.cmo
+ ocamlc -g -o $@ \
+ -I ../commons -I ../lang_php/parsing -I ../h_program-lang \
+ str.cma unix.cma nums.cma bigarray.cma \
+ ../commons/commons.cma ../h_program-lang/lib.cma \
+ ../lang_php/parsing/lib.cma \
+ $^
+
+clean::
+ rm -f find_methods_return_this
##############################################################################
# Variables
View
@@ -157,23 +157,22 @@ let (path_analysis: Ast_php.expr -> Ast_php.info -> Common.filename) =
(Ast.string_of_info tok)));
in
- match Ast.untype e with
+ match e with
(* e.g. $_SERVER['PHP_ROOT'] . '/lib/foo.php' *)
| Binary (e1,
(BinaryConcat, _),
e2) ->
let base =
- match Ast.untype e1 with
+ match e1 with
| Lv
(VArrayAccess
- ((Var (DName (varname, _), _scope), _t),
+ ((Var (DName (varname, _), _scope)),
(_tok,
Some
- (Sc (Ast.C (String (fieldname, _info))), _t2),
- _info2)),
- _t3)
+ (Sc (Ast.C (String (fieldname, _info)))),
+ _info2)))
->
(match varname, fieldname with
| "_SERVER", "PHP_ROOT" ->
@@ -193,7 +192,7 @@ let (path_analysis: Ast_php.expr -> Ast_php.info -> Common.filename) =
| _ -> not_handled_include_format ()
in
let rest =
- match Ast.untype e2 with
+ match e2 with
| Sc (Ast.C (String (str, _info))) ->
str
| _ -> not_handled_include_format ()
@@ -261,7 +260,7 @@ let dependencies_file file =
V.kexpr = (fun (k, bigf) x ->
- match Ast.untype x with
+ match x with
| Require (tok, e) | RequireOnce (tok, e)
| Include (tok, e) | IncludeOnce (tok, e)
@@ -281,14 +280,15 @@ let dependencies_file file =
| New (tok, classname_ref, _)
| AssignNew (_, _, _, tok, classname_ref, _) ->
(match classname_ref with
- | ClassNameRefStatic classname ->
+ | ClassNameRefStatic (ClassName classname) ->
let sclass = Ast.name classname in
let info = Ast.info_of_name classname in
Common.push2 ({
e_kind = Class sclass;
e_pos = pos_of_info info;
}) depends;
+ | ClassNameRefStatic (_) -> ()
| ClassNameRefDynamic _ -> ()
);
k x
@@ -300,14 +300,12 @@ let dependencies_file file =
| Assign(
(VArrayAccess(
- (VArrayAccess((Var(DName(("GLOBALS", i_1)), t), tlval_2),
+ (VArrayAccess((Var(DName(("GLOBALS", i_1)), t)),
(i_3,
- Some((Sc(Ast.C(String(("THRIFT_AUTOLOAD", i_4)))), t_5)),
- i_6)),
- tlval_7),
- (i_8, Some((Sc(Ast.C(String((sclass, i_9)))), t_10)), i_11)),
- tlval_12), i_13,
- (Sc(Ast.C(String((sfile, info_file)))), t_15))
+ Some((Sc(Ast.C(String(("THRIFT_AUTOLOAD", i_4)))))),
+ i_6))),
+ (i_8, Some((Sc(Ast.C(String((sclass, i_9)))))), i_11))), i_13,
+ (Sc(Ast.C(String((sfile, info_file))))))
->
Common.push2 ({
@@ -323,12 +321,11 @@ let dependencies_file file =
V.klvalue = (fun (k, _) v ->
- match Ast.untype v with
+ match v with
| FunCallSimple (name, args) ->
(* recurse *)
k v;
-
let sfunc = Ast.name name in
let info = Ast.info_of_name name in
@@ -338,7 +335,7 @@ let dependencies_file file =
(match sfunc, args +> Ast.unparen +> Ast.uncomma with
| "define",
- (Arg ((Sc (Ast.C (String (s,info)))), _t))::xs ->
+ (Arg ((Sc (Ast.C (String (s,info))))))::xs ->
Common.push2 {
e_kind = Constant s;
@@ -350,13 +347,13 @@ let dependencies_file file =
* and to which include directive they expand to.
*)
| ("require_module" | "require_module_lazy") ,
- [(Arg ((Sc (Ast.C (String (str,_))), _t1)))] ->
+ [(Arg ((Sc (Ast.C (String (str,_))))))] ->
Common.push2 (
"/flib/" ^ str ^ "/__init__.php", pos_of_info info
) includes;
| "require_source",
- [(Arg ((Sc (Ast.C (String (str,_))), _t1)))] ->
+ [(Arg ((Sc (Ast.C (String (str,_))))))] ->
(* dir, base, extension *)
let (d,b,e) =
@@ -370,14 +367,14 @@ let dependencies_file file =
| "require_conf",
- [(Arg ((Sc (Ast.C (String (str,_))), _t1)))] ->
+ [(Arg ((Sc (Ast.C (String (str,_))))))] ->
Common.push2 (
"/conf/" ^ str, pos_of_info info
) includes;
| "require_thrift_package",
- [(Arg ((Sc (Ast.C (String (str,_))), _)));
- (Arg ((Sc (Ast.C (String (str2,_))), _)))
+ [(Arg ((Sc (Ast.C (String (str,_))))));
+ (Arg ((Sc (Ast.C (String (str2,_))))))
] ->
Common.push2 (
spf "/lib/thrift/packages/%s/%s.php" str str2,
@@ -434,7 +431,7 @@ let dependencies_file file =
}
in
let visitor = V.mk_visitor hooks in
- visitor.V.vprogram ast;
+ visitor (Program ast);
{
includes = List.rev !includes;
@@ -50,9 +50,11 @@ let check_is_static_scalar s =
with exn ->
false
+(*
let _ = example (check_is_static_scalar "1")
let _ = example (check_is_static_scalar "array('a' => 1)")
let _ = example (not (check_is_static_scalar "foo()"))
+*)
(*****************************************************************************)
(* Entry point *)
No changes.
View
@@ -62,12 +62,13 @@ let navigator_extract_functions file =
let hooks = { V.default_visitor with
V.kexpr = (fun (k,_) x ->
- match Ast.untype x with
+ match x with
| New (_, classref, _)
| AssignNew (_, _, _, _, classref, _) ->
(match classref with
- | ClassNameRefStatic name ->
+ | ClassNameRefStatic (ClassName name) ->
Common.push2 (Ast.name name) instances;
+ | ClassNameRefStatic _ -> ()
| ClassNameRefDynamic (var, objs) ->
(* TODO ? *)
()
@@ -76,7 +77,7 @@ let navigator_extract_functions file =
| _ -> k x
);
V.klvalue = (fun (k,_) x ->
- match Ast.untype x with
+ match x with
| FunCallSimple (name, args) ->
Common.push2 (Ast.name name) funcs;
k x
@@ -88,7 +89,7 @@ let navigator_extract_functions file =
}
in
let visitor = V.mk_visitor hooks in
- visitor.V.vtop top;
+ visitor (Toplevel top);
let stat =
(* {
@@ -108,9 +109,8 @@ let navigator_extract_functions file =
in
Some (Ast.name def.f_name, stat)
- | ClassDef _ | InterfaceDef _
+ | ClassDef _ | ConstantDef _
| StmtList _
- | Halt _
| NotParsedCorrectly _ | FinalDef _ ->
(* TODO ? *)
None
View
@@ -34,20 +34,17 @@ module V = Visitor_php
let visit asts =
let props = ref [] in
- let hooks = { V.default_visitor with
+ let visitor = V.mk_visitor { V.default_visitor with
V.ktop = (fun (k, bigf) top ->
match top with
-
| FuncDef (def) ->
let name = Ast.name def.f_name in
Common.push2 ("function:" ^name) props;
-
| _ ->
()
);
} in
- asts +> List.iter (V.mk_visitor hooks).V.vtop;
-
+ visitor (Program asts);
List.rev !props
@@ -11,18 +11,17 @@ let show_function_calls file =
(*s: iter on asts manually *)
asts |> List.iter (fun toplevel ->
-
match toplevel with
| StmtList stmts ->
(*s: iter on stmts *)
stmts |> List.iter (fun stmt ->
(match stmt with
| ExprStmt (e, _ptvirg) ->
- (match Ast_php.untype e with
+ (match e with
| Lv var ->
- (match Ast_php.untype var with
+ (match var with
| FunCallSimple (funcname, args) ->
(*s: print funcname *)
let s = Ast_php.name funcname in
@@ -39,8 +38,9 @@ let show_function_calls file =
)
(*e: iter on stmts *)
- | (FuncDef _|ClassDef _|InterfaceDef _|Halt _
- |NotParsedCorrectly _| FinalDef _)
+ | (ConstantDef _|FuncDef _|ClassDef _
+ |NotParsedCorrectly _| FinalDef _
+ )
-> ()
)
(*e: iter on asts manually *)
@@ -12,11 +12,10 @@ let show_function_calls file =
let asts = Parse_php.program_of_program2 asts2 in
(*s: create visitor *)
- let visitor = V.mk_visitor
- { V.default_visitor with
+ let visitor = V.mk_visitor { V.default_visitor with
V.klvalue = (fun (k, _) var ->
- match Ast_php.untype var with
+ match var with
| FunCallSimple (funcname, args) ->
(*s: print funcname *)
let s = Ast_php.name funcname in
@@ -34,7 +33,7 @@ let show_function_calls file =
in
(*e: create visitor *)
(*s: iter on asts using visitor *)
- asts |> List.iter visitor.V.vtop
+ visitor (Program asts)
(*e: iter on asts using visitor *)
(*e: show_function_calls v2 *)
@@ -18,10 +18,9 @@ let show_function_calls file =
(*e: initialize hfuncs *)
(*s: iter on asts using visitor, updating hfuncs *)
- let visitor = V.mk_visitor
- { V.default_visitor with
+ let visitor = V.mk_visitor { V.default_visitor with
V.klvalue = (fun (k, _) var ->
- match Ast_php.untype var with
+ match var with
| FunCallSimple (funcname, args) ->
(*s: print funcname and nbargs *)
@@ -43,7 +42,7 @@ let show_function_calls file =
);
}
in
- asts |> List.iter visitor.V.vtop;
+ visitor (Program asts);
(*e: iter on asts using visitor, updating hfuncs *)
(*s: display hfuncs to user *)
@@ -155,14 +155,13 @@ let main files_or_dirs =
(i_left_paren,
[Left(
Arg(
- (Lv((Var(DName((var_name, i_13)), _scope_info), tlval_14)),
- t_15)));
+ (Lv((Var(DName((var_name, i_13)), _scope_info))))));
Right(i_token_comma);
- Left(Arg((Sc(C(String((a_string, i_token_string)))), t_18)))
+ Left(Arg((Sc(C(String((a_string, i_token_string)))))))
],
- i_right_paren)),
- tlval_20)),
- t_21) ->
+ i_right_paren))
+ ))
+ ) ->
i_token_comma.PI.transfo <- PI.Remove;
i_token_string.PI.transfo <- PI.Remove;
@@ -176,14 +175,12 @@ let main files_or_dirs =
(i_12,
[Left(
Arg(
- (Lv((Var(DName((var_name, i_13)), _scope_info), tlval_14)),
- t_15)));
+ (Lv((Var(DName((var_name, i_13)), _scope_info))))));
Right(token_comma);
Left(Arg(an_expr))
],
- i_19)),
- tlval_20)),
- t_21) ->
+ i_19))
+ ))) ->
(* let's get all the tokens composing the expression *)
let tokens_in_expression =

0 comments on commit 5a98cd8

Please sign in to comment.