Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This refactors m_compatible_type to go in 2 steps: one step to extract the type, and another for the match This will help #5350 test plan: make test
- Loading branch information
Showing
9 changed files
with
121 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
(* Yoann Padioleau | ||
* | ||
* Copyright (C) 2022 r2c | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public License | ||
* version 2.1 as published by the Free Software Foundation, with the | ||
* special exception on linking described in file license.txt. | ||
* | ||
* This library is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file | ||
* license.txt for more details. | ||
*) | ||
module G = AST_generic | ||
|
||
(*****************************************************************************) | ||
(* Prelude *) | ||
(*****************************************************************************) | ||
(* Common representation for (builtin) types across languages. | ||
* | ||
* In certain languages, a boolean declaration is using the type name | ||
* "boolean", in another language "Bool", in yet another "bool". | ||
* This is tedious to handle all those specifities during matching, so | ||
* the goal of this file is to factorize those specifities here. | ||
* | ||
* alt: | ||
* - store this directly in AST_generic.ml and do the work in the | ||
* xxx_to_generic.ml | ||
* | ||
* related: | ||
* - Type.ml in deep-semgrep | ||
*) | ||
|
||
(*****************************************************************************) | ||
(* Types *) | ||
(*****************************************************************************) | ||
|
||
(* | ||
* coupling: this is mostly used for typed metavariables like '($X: int)' to | ||
* match literals like 'f(1)', so most of the types below should have | ||
* a corresponding construct in AST_generic.literal | ||
*) | ||
type builtin_type = TInt | TNumber | TString | TFloat [@@deriving show] | ||
|
||
(*****************************************************************************) | ||
(* Helpers *) | ||
(*****************************************************************************) | ||
|
||
(* less: should sanity check things by looking at [lang] *) | ||
let builtin_type_of_ident _langTODO str = | ||
match str with | ||
| "int" -> Some TInt | ||
| "float" -> Some TFloat | ||
| "str" | ||
| "string" | ||
| "String" -> | ||
Some TString | ||
| _ -> None | ||
|
||
let builtin_type_of_type lang t = | ||
match t.G.t with | ||
(* for Python literal checking *) | ||
| G.TyExpr { e = G.N (G.Id ((str, _t), _idinfo)); _ } -> | ||
builtin_type_of_ident lang str | ||
(* for Java/Go/... literals *) | ||
| G.TyN (Id ((str, _t), _idinfo)) -> builtin_type_of_ident lang str | ||
| _ -> None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
val apply : Equivalence.t list -> Pattern.t -> Pattern.t | ||
val apply : Equivalence.t list -> Lang.t -> Pattern.t -> Pattern.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters