Skip to content

Commit

Permalink
Use latest pfff and fix no_file_info error (#1988)
Browse files Browse the repository at this point in the history
* Use latest pfff not generating NO_FILE_INFO_YET when parsing invalid C code

Fixes #1925

test plan:
$ /home/pad/semgrep/_build/default/cli/Main.exe -dump_ast foo.c
foo.c:3:0: Lexical error: unrecognised symbol, in token rule:#
Raised at file "parsing/Parse_code.ml", line 144, characters 24-27
Called from file "parsing/Parse_code.ml", line 236, characters 18-48

no more NO_FILE_INFO_YET error (which causes the python wrapper
to crash).

Also:
$ semgrep -l c -e 'FOO' tests/OTHER/parsing_errors/foo.c
ran 1 rules on 1 files: 0 findings
1 files could not be analyzed; run with --verbose for details or run with --strict to exit non-zero if any file cannot be analyzed

* Use latest pfff not generating NO_FILE_INFO_YET when parsing invalid C code

Fixes #1925

test plan:
$ /home/pad/semgrep/_build/default/cli/Main.exe -dump_ast foo.c
foo.c:3:0: Lexical error: unrecognised symbol, in token rule:#
Raised at file "parsing/Parse_code.ml", line 144, characters 24-27
Called from file "parsing/Parse_code.ml", line 236, characters 18-48

no more NO_FILE_INFO_YET error (which causes the python wrapper
to crash).

Also:
$ semgrep -l c -e 'FOO' tests/OTHER/parsing_errors/foo.c
ran 1 rules on 1 files: 0 findings
1 files could not be analyzed; run with --verbose for details or run with --strict to exit non-zero if any file cannot be analyzed
  • Loading branch information
aryx committed Nov 9, 2020
1 parent 07ec23a commit 0fb6321
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 2 additions & 0 deletions semgrep-core/cli/Main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,15 @@ let dump_pattern (file: Common.filename) =
let dump_ast file =
match Lang.langs_of_filename file with
| lang::_ ->
E.try_with_print_exn_and_reraise file (fun () ->
let (x, errs) =
Parse_code.parse_and_resolve_name_use_pfff_or_treesitter lang file in
if errs <> []
then failwith (spf "fail to fully parse %s" file);
let v = Meta_AST.vof_any (AST_generic.Pr x) in
let s = dump_v_to_format v in
pr s
)
| [] -> failwith (spf "unsupported language for %s" file)
(*e: function [[Main_semgrep_core.dump_ast]] *)

Expand Down
2 changes: 1 addition & 1 deletion semgrep-core/parsing/Parse_code.ml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ let just_parse_with_lang lang file =
* a generic AST (no kotlin_to_generic here)
*)
run file [TreeSitter Parse_kotlin_tree_sitter.parse] (fun x -> x)

(* default to the one in pfff for the other languages *)
| _ ->
run file [Pfff (Parse_generic.parse_with_lang lang)] (fun x -> x)
Expand Down
20 changes: 10 additions & 10 deletions semgrep-core/parsing/Parse_kotlin_tree_sitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let blank (env : env) () =
let todo (env : env) _ =
failwith "not implemented"

let token_todo (env : env) _ =
let token_todo (env : env) _ =
failwith "token Todo"

let escaped_identifier (env : env) (tok : CST.escaped_identifier) =
Expand Down Expand Up @@ -226,14 +226,14 @@ let semi (env : env) (tok : CST.semi) =
token env tok (* pattern [\r\n]+ *)

let prefix_unary_operator (env : env) (x : CST.prefix_unary_operator) =
let _ =
let _ =
(match x with
| `PLUSPLUS tok -> token env tok (* "++" *)
| `DASHDASH tok -> token env tok (* "--" *)
| `DASH tok -> token env tok (* "-" *)
| `PLUS tok -> token env tok (* "+" *)
| `BANG tok -> token env tok (* "!" *)
) in
) in
raise Todo

let in_operator (env : env) (x : CST.in_operator) =
Expand Down Expand Up @@ -464,7 +464,7 @@ and annotation (env : env) (x : CST.annotation) =
and anon_choice_param_b77c1d8 (env : env) (x : CST.anon_choice_param_b77c1d8) =
(match x with
| `Param x -> parameter env x
| `Type x -> let _ = type_ env x in
| `Type x -> let _ = type_ env x in
raise Todo
)

Expand Down Expand Up @@ -1506,7 +1506,7 @@ and simple_user_type (env : env) ((v1, v2) : CST.simple_user_type) =

and statement (env : env) (x : CST.statement) : AST.stmt =
(match x with
| `Decl x -> let _ = declaration env x in
| `Decl x -> let _ = declaration env x in
raise Todo
| `Rep_choice_label_choice_assign (v1, v2) ->
let v1 =
Expand Down Expand Up @@ -1571,7 +1571,7 @@ and string_literal (env : env) (x : CST.string_literal) =
in
let v3 = token env v3 (* "\"\"\"" *) in
todo env (v1, v2, v3)
) in
) in
raise Todo

and type_ (env : env) ((v1, v2) : CST.type_) : AST.type_ =
Expand Down Expand Up @@ -1625,7 +1625,7 @@ and type_constraints (env : env) ((v1, v2, v3) : CST.type_constraints) =
and type_modifier (env : env) (x : CST.type_modifier) =
(match x with
| `Anno x -> annotation env x
| `Susp tok -> let t = token env tok (* "suspend" *) in
| `Susp tok -> let t = token env tok (* "suspend" *) in
raise Todo
)

Expand All @@ -1651,7 +1651,7 @@ and type_parameter (env : env) ((v1, v2, v3) : CST.type_parameter) =

and type_parameter_modifier (env : env) (x : CST.type_parameter_modifier) =
(match x with
| `Reif_modi tok -> let t = token env tok in (* "reified" *)
| `Reif_modi tok -> let t = token env tok in (* "reified" *)
raise Todo
| `Vari_modi x -> type_projection_modifier env x
| `Anno x -> annotation env x
Expand Down Expand Up @@ -1719,7 +1719,7 @@ and unary_expression (env : env) (x : CST.unary_expression) =
let v1 =
(match v1 with
| `Anno x -> annotation env x
| `Label tok -> let _ = token env tok in (* label *)
| `Label tok -> let _ = token env tok in (* label *)
raise Todo
| `Prefix_un_op x -> prefix_unary_operator env x
)
Expand Down Expand Up @@ -1934,4 +1934,4 @@ let source_file (env : env) ((v1, v2, v3, v4, v5) : CST.source_file) : AST.progr
pr2 "Original backtrace:";
pr2 s;
raise exn
)
)
2 changes: 1 addition & 1 deletion semgrep-core/pfff
Submodule pfff updated from 5b7211 to f0b5b5
4 changes: 4 additions & 0 deletions semgrep-core/tests/OTHER/parsing_errors/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


# this is invalid code
int x = 1
2 changes: 1 addition & 1 deletion spacegrep/examples/python-from.doc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
function GLVertexBuffer(gl, shader, dataComponents
/* , type */
) {
var buffer = false, vertAttribute = false, components = dataComponents || 2, preAllocated = false, iterator = 0,
var buffer = false, vertAttribute = false, components = dataComponents || 2, preAllocated = false, iterator = 0,
// farray = false,
data;
// type = type || 'float';
Expand Down

0 comments on commit 0fb6321

Please sign in to comment.