From a90525f6274631a343f93331b180f861667eaf93 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Thu, 6 Apr 2017 02:56:16 -0700 Subject: [PATCH] [C++] Create notion of generic procname, it will be used to store specs of generic models Summary: Initial version of naming, required for generic models. It's simply non mangled name stripped from any template arguments. This makes it impossible to have two generic models with 1. different template arguments 2. different overloads (function with same name, but different types of arguments) Reviewed By: jberdine Differential Revision: D4826358 fbshipit-source-id: 42ac763 --- infer/src/IR/QualifiedCppName.re | 14 ++++++++------ infer/src/IR/QualifiedCppName.rei | 6 ++++++ infer/src/IR/Typ.re | 9 ++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/infer/src/IR/QualifiedCppName.re b/infer/src/IR/QualifiedCppName.re index da9acc0a8..cea97502d 100644 --- a/infer/src/IR/QualifiedCppName.re +++ b/infer/src/IR/QualifiedCppName.re @@ -22,6 +22,11 @@ let extract_last = | [last, ...rest] => Some (last, rest) | [] => None; +let strip_template_args quals => { + let no_template_name s => List.hd_exn (String.split on::'<' s); + List.map f::no_template_name quals +}; + let to_list = List.rev; let to_rev_list = ident; @@ -72,12 +77,9 @@ let module Match = { let of_fuzzy_qual_names fuzzy_qual_names => List.map fuzzy_qual_names f::qualifiers_of_fuzzy_qual_name |> qualifiers_list_matcher; let match_qualifiers matcher quals => { - let normalized_qualifiers = { - /* qual_name may have qualifiers with template parameters - drop them to whitelist all - instantiations */ - let no_template_name s => List.hd_exn (String.split on::'<' s); - List.map f::no_template_name quals - }; + /* qual_name may have qualifiers with template parameters - drop them to whitelist all + instantiations */ + let normalized_qualifiers = strip_template_args quals; Str.string_match matcher (to_separated_string sep::matching_separator normalized_qualifiers) 0 }; }; diff --git a/infer/src/IR/QualifiedCppName.rei b/infer/src/IR/QualifiedCppName.rei index 428102995..9a942ec65 100644 --- a/infer/src/IR/QualifiedCppName.rei +++ b/infer/src/IR/QualifiedCppName.rei @@ -33,6 +33,12 @@ let append_qualifier: t => qual::string => t; let extract_last: t => option (string, t); +/** returns qualified name without template arguments. For example: + input: std::shared_ptr::shared_ptr + output: std::shared_ptr::shared_ptr */ +let strip_template_args: t => t; + + /** returns list of qualifers */ let to_list: t => list string; diff --git a/infer/src/IR/Typ.re b/infer/src/IR/Typ.re index 4393cb0ce..7ee248713 100644 --- a/infer/src/IR/Typ.re +++ b/infer/src/IR/Typ.re @@ -901,7 +901,7 @@ let module Procname = { }; /** Convert a proc name to a filename */ - let to_filename pname => { + let to_concrete_filename pname => { /* filenames for clang procs are REVERSED qualifiers with '#' as separator */ let get_qual_name_str pname => get_qualifiers pname |> QualifiedCppName.to_rev_list |> String.concat sep::"#"; @@ -915,6 +915,13 @@ let module Procname = { }; Escape.escape_filename @@ SourceFile.append_crc_cutoff proc_id }; + let to_generic_filename pname => { + let proc_id = + get_qualifiers pname |> QualifiedCppName.strip_template_args |> QualifiedCppName.to_rev_list |> + String.concat sep::"#"; + Escape.escape_filename @@ SourceFile.append_crc_cutoff proc_id + }; + let to_filename = to_concrete_filename; };