From 2b755827e3058cd0ee6b2531ffbc750c015b0e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=95=E5=B1=B1?= Date: Tue, 26 Dec 2023 17:39:20 +0800 Subject: [PATCH 1/3] correct algorithm in example/java/UnusedMethod.gdl --- example/java/UnusedMethod.gdl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/example/java/UnusedMethod.gdl b/example/java/UnusedMethod.gdl index 11e9bd4d..354251b8 100644 --- a/example/java/UnusedMethod.gdl +++ b/example/java/UnusedMethod.gdl @@ -5,10 +5,18 @@ fn default_java_db() -> JavaDB { return JavaDB::load("coref_java_src.db") } +fn usedMethod(m: Method) -> bool { + for(c in CallableBinding(default_java_db())) { + if (c.getCallee().key_eq(m)) { + return true + } + } +} + // find unused methods fn unused_method(unused: string) -> bool { - for(c in Callable(default_java_db()), method in Callable(default_java_db()), caller in method.getCaller()) { - if (c != caller && unused = method.getSignature()) { + for(m in Method(default_java_db())) { + if (!usedMethod(m) && unused = m.getSignature()) { return true } } From cc55f3f619e33188f98649c470efa721d38f4cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=95=E5=B1=B1?= Date: Fri, 29 Dec 2023 11:17:26 +0800 Subject: [PATCH 2/3] add comments in build script --- doc/tools/generate_markdown.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/tools/generate_markdown.py b/doc/tools/generate_markdown.py index d54b3632..9169ddcb 100644 --- a/doc/tools/generate_markdown.py +++ b/doc/tools/generate_markdown.py @@ -232,12 +232,16 @@ def dump_reference_main_doc(): dump_reference_main_doc() +assets_count = 0 + for file in input_file_list: file_full_path = file["path"] + "/" + file["name"] print("Generate markdown for " + file_full_path) semantic_info = json.loads(semantic_dict[file["name"]]) comment_list = semantic_info["comments"] + # generate reference.md + assets_count += 1 output_data = "---\n" output_data += "title: \"coref::" + name_mapper[file["name"]] + "\"\n" output_data += "layout: default\n" @@ -251,6 +255,7 @@ def dump_reference_main_doc(): output_file_path = markdown_output_path + "/" + name_mapper[file["name"]] + "/reference.md" open(output_file_path, "w").write(output_data) + # generate database.md output_data = "---\n" output_data += "title: \"database\"\n" output_data += "layout: default\n" @@ -259,13 +264,16 @@ def dump_reference_main_doc(): output_data += "---\n" output_data += "# Database of " + file["name"] + "\n\n" database_list = semantic_info["semantic"]["database"] + assets_count += 1 for database in database_list: output_data += dump_database(database) output_file_path = markdown_output_path + "/" + name_mapper[file["name"]] + "/database.md" print("Generate", output_file_path) open(output_file_path, "w").write(output_data) + # generate function.md function_list = semantic_info["semantic"]["function"] + assets_count += 1 output_data = "---\n" output_data += "title: \"function\"\n" output_data += "layout: default\n" @@ -290,13 +298,17 @@ def dump_reference_main_doc(): print("Generate", output_file_path) open(output_file_path, "w").write(output_data) + # generate schema documents schema_list = semantic_info["semantic"]["schema"] + assets_count += len(schema_list) print("Generate schema documents for", file_full_path, ":", len(schema_list)) for schema in schema_list: output_data = dump_schema(comment_list, schema) output_file_path = markdown_output_path + "/" + name_mapper[file["name"]] + "/schema/" + schema["name"] + ".md" open(output_file_path, "w").write(output_data) + # generate schema hierarchy document + assets_count += 1 output_data = "---\n" output_data += "title: \"schema\"\n" output_data += "layout: default\n" @@ -307,4 +319,6 @@ def dump_reference_main_doc(): output_data += dump_schema_tree_view(schema_list) output_file_path = markdown_output_path + "/" + name_mapper[file["name"]] + "/schema.md" open(output_file_path, "w").write(output_data) - print("Generate schema documents for", file_full_path, ": Done") \ No newline at end of file + print("Generate schema documents for", file_full_path, ": Done") + +print("Generation complete, total api count:", assets_count) \ No newline at end of file From a5186fe40b9f05e755f528a190d4ccc6f7c6db77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=95=E5=B1=B1?= Date: Tue, 30 Apr 2024 17:38:58 +0800 Subject: [PATCH 3/3] add java example CallChain.gdl --- example/java/CallChain.gdl | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 example/java/CallChain.gdl diff --git a/example/java/CallChain.gdl b/example/java/CallChain.gdl new file mode 100644 index 00000000..d7257801 --- /dev/null +++ b/example/java/CallChain.gdl @@ -0,0 +1,56 @@ +// script +use coref::java::* + +pub fn default_java_db() -> JavaDB { + return JavaDB::load("coref_java_src.db") +} + +pub fn specified_callable_signature(name: string) -> bool { + // give specified callables' signatures here + [ + {"com.alipay.demo.Main.test:void()"}, + {"xxx"}, + {"xxx"} + ] +} + +schema SpecifiedCallable extends Callable {} + +impl SpecifiedCallable { + @data_constraint + pub fn __all__(db: JavaDB) -> *Self { + for(c in Callable(db)) { + if (specified_callable_signature(c.getSignature())) { + yield SpecifiedCallable { id: c.id } + } + } + } +} + +pub fn getIndirectEdges(b: Callable, c: Callable) -> bool { + for(a in SpecifiedCallable(default_java_db())) { + if (b in a.getAnAncestorCallee() && c in b.getCallee()) { + return true + } + } +} + +pub fn getDirectEdges(b: Callable, c: Callable) -> bool { + for(a in SpecifiedCallable(default_java_db())) { + if (c in a.getCallee() && b.key_eq(a)) { + return true + } + } +} + +pub fn output_signature(caller: string, callee: string) -> bool { + for(b in Callable(default_java_db()), c in Callable(default_java_db())) { + if (getIndirectEdges(b, c) || getDirectEdges(b, c)) { + return caller = b.getSignature() && callee = c.getSignature() + } + } +} + +pub fn main() { + output(output_signature()) +} \ No newline at end of file