From 1e2e72bca98bbed1a3c45c7fc1d3aaa124517c6b Mon Sep 17 00:00:00 2001 From: codefuse-admin Date: Mon, 27 Nov 2023 10:36:36 +0800 Subject: [PATCH 1/2] Initial commit from Ant Program Analysis Team --- .gitignore | 36 + LEGAL.md | 7 + README.md | 0 cli/database/__init__.py | 0 cli/database/create.py | 122 + cli/extractor/__init__.py | 0 cli/extractor/extractor.py | 192 + cli/godel/__init__.py | 0 cli/godel/godel_compiler.py | 67 + cli/query/__init__.py | 0 cli/query/run.py | 132 + cli/rebuild/__init__.py | 0 cli/rebuild/lib.py | 119 + cli/requirements.txt | 1 + cli/run/__init__.py | 1 + cli/run/runner.py | 41 + cli/sparrow | 27 + cli/sparrow-cli.py | 141 + cli/sparrow_schema/__init__.py | 0 cli/sparrow_schema/schema.py | 37 + example/go/CyclomaticComplexity.gdl | 30 + example/go/FileInfo.gdl | 39 + example/go/FunctionComment.gdl | 28 + example/java/ClassHierarchy.gdl | 23 + example/java/ClassMethods.gdl | 20 + example/java/UnusedMethod.gdl | 19 + example/javascript/ASTPrint.gdl | 62 + example/javascript/ChangeEffect.gdl | 76 + example/javascript/CyclomaticComplexity.gdl | 34 + example/python/CyclomaticComplexity.gdl | 37 + example/python/DocumentedPercentage.gdl | 80 + example/python/MethodComment.gdl | 85 + example/query/hello.gdl | 8 + example/xml/GetBean.gdl | 99 + example/xml/POM.gdl | 123 + example/xml/RPC.gdl | 61 + language/go/lib/CallableExpr.gdl | 100 + language/go/lib/Comment.gdl | 74 + language/go/lib/DOClass.gdl | 2423 ++++++++ language/go/lib/Declaration.gdl | 155 + language/go/lib/Expression.gdl | 649 ++ language/go/lib/Fields.gdl | 103 + language/go/lib/File.gdl | 184 + language/go/lib/FileData.gdl | 24 + language/go/lib/ForStmt.gdl | 56 + language/go/lib/Function.gdl | 275 + language/go/lib/Location.gdl | 20 + language/go/lib/Method.gdl | 59 + language/go/lib/Mod.gdl | 29 + language/go/lib/Node.gdl | 420 ++ language/go/lib/Packages.gdl | 17 + language/go/lib/Receiver.gdl | 36 + language/go/lib/ReternStmt.gdl | 37 + language/go/lib/SelectorExpr.gdl | 68 + language/go/lib/SliceExpr.gdl | 64 + language/go/lib/Spec.gdl | 278 + language/go/lib/Statement.gdl | 358 ++ language/go/lib/Type.gdl | 259 + language/go/lib/Utils.gdl | 27 + language/go/lib/VariableUtils.gdl | 41 + language/go/lib/Variables.gdl | 102 + language/go/lib/Writable.gdl | 227 + language/java/lib/Annotation.gdl | 729 +++ language/java/lib/Array.gdl | 270 + language/java/lib/CallGraph.gdl | 1017 ++++ language/java/lib/Class.gdl | 1754 ++++++ language/java/lib/CodeMetric.gdl | 243 + language/java/lib/Container.gdl | 689 +++ language/java/lib/DOClass.gdl | 5340 +++++++++++++++++ language/java/lib/Documentation.gdl | 314 + language/java/lib/Expression.gdl | 1581 +++++ language/java/lib/Identifier.gdl | 53 + language/java/lib/Literal.gdl | 512 ++ language/java/lib/Location.gdl | 53 + language/java/lib/Method.gdl | 388 ++ language/java/lib/Modifier.gdl | 160 + language/java/lib/Parameter.gdl | 340 ++ language/java/lib/Parent.gdl | 1234 ++++ language/java/lib/Statement.gdl | 2220 +++++++ language/java/lib/Type.gdl | 177 + language/java/lib/Utils.gdl | 133 + language/java/lib/token.gdl | 53 + language/javascript/lib/AlipayMiniProgram.gdl | 659 ++ language/javascript/lib/BasicBlock.gdl | 505 ++ language/javascript/lib/Class.gdl | 488 ++ language/javascript/lib/Comment.gdl | 38 + language/javascript/lib/Completion.gdl | 253 + language/javascript/lib/ControlFlowGraph.gdl | 2420 ++++++++ language/javascript/lib/DOClass.gdl | 761 +++ language/javascript/lib/DataFlowGraph.gdl | 395 ++ language/javascript/lib/Declaration.gdl | 922 +++ language/javascript/lib/DefUse.gdl | 706 +++ language/javascript/lib/Expression.gdl | 4759 +++++++++++++++ language/javascript/lib/FileSystem.gdl | 26 + language/javascript/lib/Function.gdl | 633 ++ language/javascript/lib/HeritageClause.gdl | 95 + .../javascript/lib/ImportOrExportElement.gdl | 265 + language/javascript/lib/JSX.gdl | 466 ++ language/javascript/lib/Location.gdl | 55 + language/javascript/lib/Modifier.gdl | 405 ++ language/javascript/lib/Node.gdl | 431 ++ language/javascript/lib/NumberOfLines.gdl | 25 + language/javascript/lib/ObjectLiteral.gdl | 444 ++ language/javascript/lib/Statement.gdl | 2093 +++++++ language/javascript/lib/Symbol.gdl | 38 + language/javascript/lib/SyntaxKind.gdl | 390 ++ language/javascript/lib/Template.gdl | 168 + language/javascript/lib/Token.gdl | 3270 ++++++++++ language/javascript/lib/TopLevel.gdl | 131 + language/javascript/lib/Type.gdl | 1268 ++++ language/javascript/lib/Util.gdl | 34 + language/python/extractor/requirements.txt | 5 + language/python/extractor/setup.py | 0 .../python/extractor/src/core/__init__.py | 0 .../python/extractor/src/core/extractor.py | 1034 ++++ .../python/extractor/src/core/idgenerator.py | 48 + language/python/extractor/src/core/storage.py | 444 ++ language/python/extractor/src/main.py | 383 ++ .../python/extractor/src/model/__init__.py | 0 language/python/extractor/src/model/alias.py | 18 + .../extractor/src/model/annotated_relation.py | 13 + .../python/extractor/src/model/annotation.py | 17 + .../model/annotation_assignment_statement.py | 15 + language/python/extractor/src/model/arg.py | 17 + .../python/extractor/src/model/arguments.py | 14 + .../extractor/src/model/assert_statement.py | 13 + .../src/model/assignment_statement.py | 14 + .../src/model/async_for_statement.py | 12 + .../src/model/async_function_def_statement.py | 13 + .../src/model/async_with_statement.py | 12 + .../src/model/attribute_expression.py | 14 + .../model/augmented_assignment_statement.py | 15 + .../extractor/src/model/await_expression.py | 13 + .../extractor/src/model/bin_op_expression.py | 15 + .../src/model/boolean_op_expression.py | 14 + .../extractor/src/model/break_statement.py | 12 + .../extractor/src/model/call_expression.py | 13 + .../extractor/src/model/callable_binding.py | 13 + .../src/model/class_def_statement.py | 13 + .../extractor/src/model/class_hierarchy.py | 13 + language/python/extractor/src/model/cmpop.py | 15 + .../python/extractor/src/model/comment.py | 15 + .../extractor/src/model/compare_expression.py | 13 + .../extractor/src/model/comprehension.py | 17 + .../python/extractor/src/model/constant.py | 13 + .../extractor/src/model/container_parent.py | 13 + .../extractor/src/model/continue_statement.py | 12 + .../extractor/src/model/decorated_relation.py | 13 + .../python/extractor/src/model/decorator.py | 14 + .../extractor/src/model/delete_statement.py | 13 + .../src/model/dict_comp_expression.py | 13 + .../extractor/src/model/dict_expression.py | 13 + .../extractor/src/model/docstring_comment.py | 14 + .../python/extractor/src/model/element.py | 15 + .../extractor/src/model/except_handler.py | 16 + .../extractor/src/model/expr_context.py | 14 + .../python/extractor/src/model/expression.py | 17 + .../src/model/expression_statement.py | 13 + language/python/extractor/src/model/file.py | 16 + .../extractor/src/model/file_md5_sum.py | 13 + .../extractor/src/model/file_sha256_sum.py | 13 + language/python/extractor/src/model/folder.py | 15 + .../extractor/src/model/for_statement.py | 12 + .../src/model/formatted_value_expression.py | 13 + .../src/model/function_def_statement.py | 13 + .../src/model/generator_expression.py | 13 + .../extractor/src/model/global_statement.py | 13 + .../extractor/src/model/if_expression.py | 12 + .../extractor/src/model/if_statement.py | 12 + .../src/model/import_from_statement.py | 14 + .../extractor/src/model/import_statement.py | 12 + .../src/model/joined_str_expression.py | 13 + .../python/extractor/src/model/keyword.py | 18 + .../extractor/src/model/lambda_expression.py | 12 + .../src/model/list_comp_expression.py | 14 + .../extractor/src/model/list_expression.py | 14 + .../python/extractor/src/model/location.py | 17 + .../extractor/src/model/long_literal.py | 13 + .../python/extractor/src/model/match_case.py | 18 + .../extractor/src/model/match_statement.py | 13 + .../python/extractor/src/model/metainfo.py | 14 + language/python/extractor/src/model/mod.py | 14 + .../python/extractor/src/model/models_main.py | 31 + .../extractor/src/model/modified_2to3_file.py | 13 + .../python/extractor/src/model/modifier.py | 15 + language/python/extractor/src/model/module.py | 15 + .../src/model/module_enclosing_expression.py | 13 + .../src/model/module_enclosing_statement.py | 13 + .../extractor/src/model/name_expression.py | 13 + .../extractor/src/model/named_expression.py | 14 + .../src/model/non_local_statement.py | 13 + .../extractor/src/model/number_of_lines.py | 15 + .../python/extractor/src/model/operator.py | 15 + language/python/extractor/src/model/parent.py | 13 + .../extractor/src/model/parse_error_file.py | 15 + .../extractor/src/model/pass_statement.py | 12 + .../python/extractor/src/model/pattern.py | 15 + .../python/extractor/src/model/program.py | 13 + .../extractor/src/model/raise_statement.py | 12 + .../extractor/src/model/reference_relation.py | 13 + .../extractor/src/model/return_statement.py | 13 + .../src/model/scope_enclosing_expression.py | 13 + .../src/model/scope_enclosing_statement.py | 13 + .../src/model/set_comp_expression.py | 14 + .../extractor/src/model/set_expression.py | 13 + language/python/extractor/src/model/slice.py | 17 + .../extractor/src/model/slice_expression.py | 15 + .../extractor/src/model/starred_expression.py | 13 + .../python/extractor/src/model/statement.py | 17 + .../extractor/src/model/string_literal.py | 13 + .../src/model/subscript_expression.py | 15 + language/python/extractor/src/model/token.py | 15 + .../extractor/src/model/try_statement.py | 12 + .../extractor/src/model/tuple_expression.py | 14 + .../python/extractor/src/model/type_ignore.py | 16 + .../extractor/src/model/unary_expression.py | 15 + .../python/extractor/src/model/unary_op.py | 15 + .../src/model/unary_op_expression.py | 14 + .../python/extractor/src/model/variable.py | 16 + .../extractor/src/model/while_statement.py | 12 + .../python/extractor/src/model/with_item.py | 15 + .../extractor/src/model/with_statement.py | 12 + .../extractor/src/model/yield_expression.py | 12 + .../src/model/yield_from_expression.py | 13 + .../src/resources/coref_python_src.sql | 546 ++ language/python/lib/Alias.gdl | 56 + language/python/lib/Argument.gdl | 131 + language/python/lib/Class.gdl | 255 + language/python/lib/Comprehension.gdl | 55 + language/python/lib/Container.gdl | 229 + language/python/lib/DOClass.gdl | 3234 ++++++++++ language/python/lib/Decorator.gdl | 80 + language/python/lib/Documentation.gdl | 162 + language/python/lib/Element.gdl | 560 ++ language/python/lib/Expression.gdl | 321 + language/python/lib/Function.gdl | 147 + language/python/lib/Keyword.gdl | 99 + language/python/lib/Location.gdl | 53 + language/python/lib/Metrics.gdl | 368 ++ language/python/lib/Scope.gdl | 59 + language/python/lib/Slice.gdl | 55 + language/python/lib/Statement.gdl | 654 ++ language/python/lib/Withitem.gdl | 53 + language/xml/lib/DOClass.gdl | 566 ++ language/xml/lib/Element.gdl | 582 ++ 245 files changed, 58891 insertions(+) create mode 100644 .gitignore create mode 100644 LEGAL.md create mode 100644 README.md create mode 100644 cli/database/__init__.py create mode 100644 cli/database/create.py create mode 100644 cli/extractor/__init__.py create mode 100644 cli/extractor/extractor.py create mode 100644 cli/godel/__init__.py create mode 100644 cli/godel/godel_compiler.py create mode 100644 cli/query/__init__.py create mode 100644 cli/query/run.py create mode 100644 cli/rebuild/__init__.py create mode 100644 cli/rebuild/lib.py create mode 100644 cli/requirements.txt create mode 100644 cli/run/__init__.py create mode 100644 cli/run/runner.py create mode 100644 cli/sparrow create mode 100644 cli/sparrow-cli.py create mode 100644 cli/sparrow_schema/__init__.py create mode 100644 cli/sparrow_schema/schema.py create mode 100644 example/go/CyclomaticComplexity.gdl create mode 100644 example/go/FileInfo.gdl create mode 100644 example/go/FunctionComment.gdl create mode 100644 example/java/ClassHierarchy.gdl create mode 100644 example/java/ClassMethods.gdl create mode 100644 example/java/UnusedMethod.gdl create mode 100644 example/javascript/ASTPrint.gdl create mode 100644 example/javascript/ChangeEffect.gdl create mode 100644 example/javascript/CyclomaticComplexity.gdl create mode 100644 example/python/CyclomaticComplexity.gdl create mode 100644 example/python/DocumentedPercentage.gdl create mode 100644 example/python/MethodComment.gdl create mode 100644 example/query/hello.gdl create mode 100644 example/xml/GetBean.gdl create mode 100644 example/xml/POM.gdl create mode 100644 example/xml/RPC.gdl create mode 100644 language/go/lib/CallableExpr.gdl create mode 100644 language/go/lib/Comment.gdl create mode 100644 language/go/lib/DOClass.gdl create mode 100644 language/go/lib/Declaration.gdl create mode 100644 language/go/lib/Expression.gdl create mode 100644 language/go/lib/Fields.gdl create mode 100644 language/go/lib/File.gdl create mode 100644 language/go/lib/FileData.gdl create mode 100644 language/go/lib/ForStmt.gdl create mode 100644 language/go/lib/Function.gdl create mode 100644 language/go/lib/Location.gdl create mode 100644 language/go/lib/Method.gdl create mode 100644 language/go/lib/Mod.gdl create mode 100644 language/go/lib/Node.gdl create mode 100644 language/go/lib/Packages.gdl create mode 100644 language/go/lib/Receiver.gdl create mode 100644 language/go/lib/ReternStmt.gdl create mode 100644 language/go/lib/SelectorExpr.gdl create mode 100644 language/go/lib/SliceExpr.gdl create mode 100644 language/go/lib/Spec.gdl create mode 100644 language/go/lib/Statement.gdl create mode 100644 language/go/lib/Type.gdl create mode 100644 language/go/lib/Utils.gdl create mode 100644 language/go/lib/VariableUtils.gdl create mode 100644 language/go/lib/Variables.gdl create mode 100644 language/go/lib/Writable.gdl create mode 100644 language/java/lib/Annotation.gdl create mode 100644 language/java/lib/Array.gdl create mode 100644 language/java/lib/CallGraph.gdl create mode 100644 language/java/lib/Class.gdl create mode 100644 language/java/lib/CodeMetric.gdl create mode 100644 language/java/lib/Container.gdl create mode 100644 language/java/lib/DOClass.gdl create mode 100644 language/java/lib/Documentation.gdl create mode 100644 language/java/lib/Expression.gdl create mode 100644 language/java/lib/Identifier.gdl create mode 100644 language/java/lib/Literal.gdl create mode 100644 language/java/lib/Location.gdl create mode 100644 language/java/lib/Method.gdl create mode 100644 language/java/lib/Modifier.gdl create mode 100644 language/java/lib/Parameter.gdl create mode 100644 language/java/lib/Parent.gdl create mode 100644 language/java/lib/Statement.gdl create mode 100644 language/java/lib/Type.gdl create mode 100644 language/java/lib/Utils.gdl create mode 100644 language/java/lib/token.gdl create mode 100644 language/javascript/lib/AlipayMiniProgram.gdl create mode 100644 language/javascript/lib/BasicBlock.gdl create mode 100644 language/javascript/lib/Class.gdl create mode 100644 language/javascript/lib/Comment.gdl create mode 100644 language/javascript/lib/Completion.gdl create mode 100644 language/javascript/lib/ControlFlowGraph.gdl create mode 100644 language/javascript/lib/DOClass.gdl create mode 100644 language/javascript/lib/DataFlowGraph.gdl create mode 100644 language/javascript/lib/Declaration.gdl create mode 100644 language/javascript/lib/DefUse.gdl create mode 100644 language/javascript/lib/Expression.gdl create mode 100644 language/javascript/lib/FileSystem.gdl create mode 100644 language/javascript/lib/Function.gdl create mode 100644 language/javascript/lib/HeritageClause.gdl create mode 100644 language/javascript/lib/ImportOrExportElement.gdl create mode 100644 language/javascript/lib/JSX.gdl create mode 100644 language/javascript/lib/Location.gdl create mode 100644 language/javascript/lib/Modifier.gdl create mode 100644 language/javascript/lib/Node.gdl create mode 100644 language/javascript/lib/NumberOfLines.gdl create mode 100644 language/javascript/lib/ObjectLiteral.gdl create mode 100644 language/javascript/lib/Statement.gdl create mode 100644 language/javascript/lib/Symbol.gdl create mode 100644 language/javascript/lib/SyntaxKind.gdl create mode 100644 language/javascript/lib/Template.gdl create mode 100644 language/javascript/lib/Token.gdl create mode 100644 language/javascript/lib/TopLevel.gdl create mode 100644 language/javascript/lib/Type.gdl create mode 100644 language/javascript/lib/Util.gdl create mode 100644 language/python/extractor/requirements.txt create mode 100644 language/python/extractor/setup.py create mode 100644 language/python/extractor/src/core/__init__.py create mode 100644 language/python/extractor/src/core/extractor.py create mode 100644 language/python/extractor/src/core/idgenerator.py create mode 100644 language/python/extractor/src/core/storage.py create mode 100644 language/python/extractor/src/main.py create mode 100644 language/python/extractor/src/model/__init__.py create mode 100644 language/python/extractor/src/model/alias.py create mode 100644 language/python/extractor/src/model/annotated_relation.py create mode 100644 language/python/extractor/src/model/annotation.py create mode 100644 language/python/extractor/src/model/annotation_assignment_statement.py create mode 100644 language/python/extractor/src/model/arg.py create mode 100644 language/python/extractor/src/model/arguments.py create mode 100644 language/python/extractor/src/model/assert_statement.py create mode 100644 language/python/extractor/src/model/assignment_statement.py create mode 100644 language/python/extractor/src/model/async_for_statement.py create mode 100644 language/python/extractor/src/model/async_function_def_statement.py create mode 100644 language/python/extractor/src/model/async_with_statement.py create mode 100644 language/python/extractor/src/model/attribute_expression.py create mode 100644 language/python/extractor/src/model/augmented_assignment_statement.py create mode 100644 language/python/extractor/src/model/await_expression.py create mode 100644 language/python/extractor/src/model/bin_op_expression.py create mode 100644 language/python/extractor/src/model/boolean_op_expression.py create mode 100644 language/python/extractor/src/model/break_statement.py create mode 100644 language/python/extractor/src/model/call_expression.py create mode 100644 language/python/extractor/src/model/callable_binding.py create mode 100644 language/python/extractor/src/model/class_def_statement.py create mode 100644 language/python/extractor/src/model/class_hierarchy.py create mode 100644 language/python/extractor/src/model/cmpop.py create mode 100644 language/python/extractor/src/model/comment.py create mode 100644 language/python/extractor/src/model/compare_expression.py create mode 100644 language/python/extractor/src/model/comprehension.py create mode 100644 language/python/extractor/src/model/constant.py create mode 100644 language/python/extractor/src/model/container_parent.py create mode 100644 language/python/extractor/src/model/continue_statement.py create mode 100644 language/python/extractor/src/model/decorated_relation.py create mode 100644 language/python/extractor/src/model/decorator.py create mode 100644 language/python/extractor/src/model/delete_statement.py create mode 100644 language/python/extractor/src/model/dict_comp_expression.py create mode 100644 language/python/extractor/src/model/dict_expression.py create mode 100644 language/python/extractor/src/model/docstring_comment.py create mode 100644 language/python/extractor/src/model/element.py create mode 100644 language/python/extractor/src/model/except_handler.py create mode 100644 language/python/extractor/src/model/expr_context.py create mode 100644 language/python/extractor/src/model/expression.py create mode 100644 language/python/extractor/src/model/expression_statement.py create mode 100644 language/python/extractor/src/model/file.py create mode 100644 language/python/extractor/src/model/file_md5_sum.py create mode 100644 language/python/extractor/src/model/file_sha256_sum.py create mode 100644 language/python/extractor/src/model/folder.py create mode 100644 language/python/extractor/src/model/for_statement.py create mode 100644 language/python/extractor/src/model/formatted_value_expression.py create mode 100644 language/python/extractor/src/model/function_def_statement.py create mode 100644 language/python/extractor/src/model/generator_expression.py create mode 100644 language/python/extractor/src/model/global_statement.py create mode 100644 language/python/extractor/src/model/if_expression.py create mode 100644 language/python/extractor/src/model/if_statement.py create mode 100644 language/python/extractor/src/model/import_from_statement.py create mode 100644 language/python/extractor/src/model/import_statement.py create mode 100644 language/python/extractor/src/model/joined_str_expression.py create mode 100644 language/python/extractor/src/model/keyword.py create mode 100644 language/python/extractor/src/model/lambda_expression.py create mode 100644 language/python/extractor/src/model/list_comp_expression.py create mode 100644 language/python/extractor/src/model/list_expression.py create mode 100644 language/python/extractor/src/model/location.py create mode 100644 language/python/extractor/src/model/long_literal.py create mode 100644 language/python/extractor/src/model/match_case.py create mode 100644 language/python/extractor/src/model/match_statement.py create mode 100644 language/python/extractor/src/model/metainfo.py create mode 100644 language/python/extractor/src/model/mod.py create mode 100644 language/python/extractor/src/model/models_main.py create mode 100644 language/python/extractor/src/model/modified_2to3_file.py create mode 100644 language/python/extractor/src/model/modifier.py create mode 100644 language/python/extractor/src/model/module.py create mode 100644 language/python/extractor/src/model/module_enclosing_expression.py create mode 100644 language/python/extractor/src/model/module_enclosing_statement.py create mode 100644 language/python/extractor/src/model/name_expression.py create mode 100644 language/python/extractor/src/model/named_expression.py create mode 100644 language/python/extractor/src/model/non_local_statement.py create mode 100644 language/python/extractor/src/model/number_of_lines.py create mode 100644 language/python/extractor/src/model/operator.py create mode 100644 language/python/extractor/src/model/parent.py create mode 100644 language/python/extractor/src/model/parse_error_file.py create mode 100644 language/python/extractor/src/model/pass_statement.py create mode 100644 language/python/extractor/src/model/pattern.py create mode 100644 language/python/extractor/src/model/program.py create mode 100644 language/python/extractor/src/model/raise_statement.py create mode 100644 language/python/extractor/src/model/reference_relation.py create mode 100644 language/python/extractor/src/model/return_statement.py create mode 100644 language/python/extractor/src/model/scope_enclosing_expression.py create mode 100644 language/python/extractor/src/model/scope_enclosing_statement.py create mode 100644 language/python/extractor/src/model/set_comp_expression.py create mode 100644 language/python/extractor/src/model/set_expression.py create mode 100644 language/python/extractor/src/model/slice.py create mode 100644 language/python/extractor/src/model/slice_expression.py create mode 100644 language/python/extractor/src/model/starred_expression.py create mode 100644 language/python/extractor/src/model/statement.py create mode 100644 language/python/extractor/src/model/string_literal.py create mode 100644 language/python/extractor/src/model/subscript_expression.py create mode 100644 language/python/extractor/src/model/token.py create mode 100644 language/python/extractor/src/model/try_statement.py create mode 100644 language/python/extractor/src/model/tuple_expression.py create mode 100644 language/python/extractor/src/model/type_ignore.py create mode 100644 language/python/extractor/src/model/unary_expression.py create mode 100644 language/python/extractor/src/model/unary_op.py create mode 100644 language/python/extractor/src/model/unary_op_expression.py create mode 100644 language/python/extractor/src/model/variable.py create mode 100644 language/python/extractor/src/model/while_statement.py create mode 100644 language/python/extractor/src/model/with_item.py create mode 100644 language/python/extractor/src/model/with_statement.py create mode 100644 language/python/extractor/src/model/yield_expression.py create mode 100644 language/python/extractor/src/model/yield_from_expression.py create mode 100644 language/python/extractor/src/resources/coref_python_src.sql create mode 100644 language/python/lib/Alias.gdl create mode 100644 language/python/lib/Argument.gdl create mode 100644 language/python/lib/Class.gdl create mode 100644 language/python/lib/Comprehension.gdl create mode 100644 language/python/lib/Container.gdl create mode 100644 language/python/lib/DOClass.gdl create mode 100644 language/python/lib/Decorator.gdl create mode 100644 language/python/lib/Documentation.gdl create mode 100644 language/python/lib/Element.gdl create mode 100644 language/python/lib/Expression.gdl create mode 100644 language/python/lib/Function.gdl create mode 100644 language/python/lib/Keyword.gdl create mode 100644 language/python/lib/Location.gdl create mode 100644 language/python/lib/Metrics.gdl create mode 100644 language/python/lib/Scope.gdl create mode 100644 language/python/lib/Slice.gdl create mode 100644 language/python/lib/Statement.gdl create mode 100644 language/python/lib/Withitem.gdl create mode 100644 language/xml/lib/DOClass.gdl create mode 100644 language/xml/lib/Element.gdl diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..35885f72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +logs/ +*.log +.DS_Store + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ +.cloudide diff --git a/LEGAL.md b/LEGAL.md new file mode 100644 index 00000000..f9689208 --- /dev/null +++ b/LEGAL.md @@ -0,0 +1,7 @@ +Legal Disclaimer + +Within this source code, the comments in Chinese shall be the original, governing version. Any comment in other languages are for reference only. In the event of any conflict between the Chinese language version comments and other language version comments, the Chinese language version shall prevail. + +法律免责声明 + +关于代码注释部分,中文注释为官方版本,其它语言注释仅做参考。中文注释可能与其它语言注释存在不一致,当中文注释与其它语言注释存在不一致时,请以中文注释为准。 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..e69de29b diff --git a/cli/database/__init__.py b/cli/database/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/database/create.py b/cli/database/create.py new file mode 100644 index 00000000..30589ec0 --- /dev/null +++ b/cli/database/create.py @@ -0,0 +1,122 @@ +import json +import re +import time +from pathlib import Path + +from extractor.extractor import * + + +def conf_check(args): + src_path = Path(args.source_root).expanduser().resolve() + if not src_path.exists(): + logging.error("source not exist, Please redefine the directory or file by --source-root or -s") + return False + output_path = Path(args.output).expanduser().resolve() + if not output_path.exists(): + logging.warning("%s not exists, it will be created", str(output_path)) + try: + output_path.mkdir(parents=True) + logging.info("%s success build", str(output_path)) + except Exception as e: + logging.error("can not to create database directory %s: %s", str(output_path), e) + return False + if args.extraction_config_file: + extraction_config_file_path = Path(args.output).expanduser().resolve() + if not extraction_config_file_path.exists(): + logging.error("extraction_config_file: %s not exists, please redefine by --extraction-config-file", + args.extraction_config_file) + return False + return True + + +def memory_statistics(): + memory = psutil.virtual_memory() + + # 获取总内存大小(以字节为单位) + total_memory = memory.total + + # 格式化内存大小 + size_units = ["B", "KB", "MB", "GB", "TB"] + unit_index = 0 + while total_memory >= 1024 and unit_index < len(size_units) - 1: + total_memory /= 1024 + unit_index += 1 + logging.info(f"current memory is : {total_memory:.2f} {size_units[unit_index]}") + logging.info(f"final -Xmx is : {max(total_memory - 1, 6):.2f} {size_units[unit_index]}") + + +def conf_option_deal(args): + options = dict() + if args.extraction_config_file: + try: + with open(args.extraction_config_file, "r") as f: + options = json.load(f) + except Exception as e: + logging.error(e) + return -1 + for language in args.language: + options[language] = dict() + if args.extraction_config: + # 要求option必须是a.b=c的形式,a为语言名,若不是报错 + pattern = r'^(.+)\.(.+)\=(.+)$' + for tmp in args.extraction_config: + match = re.match(pattern, tmp) + if match: + language = match.group(1) + key = match.group(2) + value = match.group(3) + # 若option与需要抽取的语言对不上, 报错并返回配置错误 + if language not in args.language: + logging.error("option language error: %s does not need to be extracted", language) + return -1 + options[language][key] = value + else: + logging.error("option format error: %s, it need like java.a=b", tmp) + return -1 + return options + + +def database_create(args): + if not conf_check(args): + logging.error("configuration error, Please check conf") + raise ValueError("configuration error") + options = conf_option_deal(args) + if options == -1: + logging.error("configuration error, Please check conf") + raise ValueError("configuration error") + memory_statistics() + timeout = args.timeout + extractor_fail = list() + for language in args.language: + output_path = Path(args.output).expanduser().resolve() + src_path = Path(args.source_root).expanduser().resolve() + now_output_path = output_path / ("coref_" + language + "_src.db") + # 给用户反悔机会,若添加overwrite选项则直接覆盖存量数据 + if now_output_path.exists(): + logging.info(f"{now_output_path} will be create") + if not args.overwrite: + user_input = input(f"file {now_output_path} Already exists, do you want to overwrite it? (y/n): ") + if user_input.lower() != "y": + logging.warning(" %s will use old version data", language) + continue + start_time = time.time() + return_code = extractor_run(language, src_path, output_path, timeout, options[language]) + if return_code == 0: + logging.info("Finish extracting data source %s with %s language Extractor, extraction is Success, " + "execution time is %.2fs.", args.source_root, language, time.time() - start_time) + else: + extractor_fail.append(language) + logging.error("%s extracting error with %s language Extractor, please check by log", + args.source_root, language) + timeout = timeout - time.time() + start_time + if timeout < 0: + logging.error("extract fail: timeout") + raise RuntimeError("timeout") + if len(extractor_fail) > 0: + for language in extractor_fail: + logging.error("%s extract fail, please check log", language) + logging.error("extract fail") + raise RuntimeError("extract fail") + else: + logging.info("extract success") + return diff --git a/cli/extractor/__init__.py b/cli/extractor/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/extractor/extractor.py b/cli/extractor/extractor.py new file mode 100644 index 00000000..290257dd --- /dev/null +++ b/cli/extractor/extractor.py @@ -0,0 +1,192 @@ +import logging + +import psutil + +from run.runner import Runner +from sparrow_schema.schema import sparrow + + +class Extractor: + # 若添加抽取器,请命名为language_extractor,并完成language_extractor_cmd函数实现执行指令, 可被相应展示与执行 + cfamily_extractor = "" + go_extractor = "" + java_extractor = "" + javascript_extractor = "" + properties_extractor = "" + python_extractor = "" + sql_extractor = "" + swift_extractor = "" + xml_extractor = "" + + def __init__(self): + Extractor.cfamily_extractor = sparrow.home / "language" / "cfamily" / "extractor" / "usr" / "bin" / "coref-cfamily-src-extractor" + Extractor.go_extractor = sparrow.home / "language" / "go" / "extractor" / "coref-go-src-extractor" + Extractor.java_extractor = sparrow.home / "language" / "java" / "extractor" / "coref-java-src-extractor_deploy.jar" + Extractor.javascript_extractor = sparrow.home / "language" / "javascript" / "extractor" / "coref-javascript-src-extractor" + Extractor.properties_extractor = sparrow.home / "language" / "properties" / "extractor" / "coref-properties-src-extractor_deploy.jar" + Extractor.python_extractor = sparrow.home / "language" / "python" / "extractor" / "coref-python-src-extractor" + Extractor.sql_extractor = sparrow.home / "language" / "sql" / "extractor" / "coref-sql-src-extractor_deploy.jar" + Extractor.swift_extractor = sparrow.home / "language" / "swift" / "extractor" / "usr" / "bin" / "coref-swift-src-extractor" + Extractor.xml_extractor = sparrow.home / "language" / "xml" / "extractor" / "coref-xml-extractor_deploy.jar" + + +def cfamily_extractor_cmd(source_root, database, options): + cmd = list() + cmd += [str(Extractor.cfamily_extractor)] + cmd += ["--compile-commands=", str(source_root)] + cmd += ["--output-db-path=", str(database)] + return cmd + + +def go_extractor_cmd(source_root, database, options): + cmd = list() + cmd += [str(Extractor.go_extractor)] + if options: + for (key, value) in options.items(): + if key == "extract-config": + for tmp in value.split(","): + cmd += ["-ex", tmp] + elif key == "go-build-flag": + for tmp in value.split(","): + cmd += [tmp] + else: + logging.warning("unsupported config name: %s for Go extractor.", key) + cmd += ["-o", str(database/"coref_go_src.db")] + cmd += [str(source_root)] + return cmd + + +def java_extractor_cmd(source_root, database, options): + cmd = list() + cmd += jar_extractor_cmd(Extractor.java_extractor, source_root, database) + if options: + for (key, value) in options.items(): + if key == "white-list" or key == "whiteList": + cmd += ["-w=", value] + elif key == "cp": + cmd += ["-cp=", value] + elif key == "classpath": + cmd += ["--classpath=", value] + elif key == "incremental": + if value == "true": + cmd += ["--incremental"] + cmd += ["--cache-dir=" + options.get("cache-dir", "null")] + cmd += ["--commit=" + options.get("commit", "null")] + cmd += ["--remote-cache-type=" + options.get("remote-cache-type", "null")] + cmd += ["--oss-bucket=" + options.get("oss-bucket", "null")] + cmd += ["--oss-config-file=" + options.get("oss-config-file", "null")] + cmd += ["--oss-path-prefix=" + options.get("oss-path-prefix", "null")] + else: + logging.warning("java.incremental does not take effect, please use java.incremental=true") + else: + if key != "cache-dir" and key != "commit" and key != "remote-cache-type" and \ + key != "oss-bucket" and key != "oss-config-file" and key != "oss-path-prefix": + logging.warning("unsupported config name:%s for java extractor.", key) + if "incremental" not in options or options["incremental"] != "true": + cmd += ["--parallel"] + return cmd + + +def javascript_extractor_cmd(source_root, database, options): + cmd = list() + cmd += [str(Extractor.javascript_extractor), "extract"] + \ + ["--src", str(source_root)] + \ + ["--db", str(database/"coref_javascript_src.db")] + if options: + for (key, value) in options.items(): + if key == "black-list" or key == "blacklist": + cmd += ["--blacklist"] + for tmp in value.split(','): + cmd += [tmp] + elif key == "use-gitignore": + if value == "true": + cmd += ["--use-gitignore"] + else: + logging.warning("javascript.use-gitignore does not take effect, please use " + "javascript.use-gitignore=true") + elif key == "extract-dist": + if value == "true": + cmd += ["--extract-dist"] + else: + logging.warning("javascript.extract-dist does not take effect, please use " + "javascript.extract-dist=true") + elif key == "extract-deps": + if value == "true": + cmd += ["--extract-deps"] + else: + logging.warning("javascript.extract-deps does not take effect, please use " + "javascript.extract-deps=true") + elif key == "file-size-limit": + cmd += ["--file-size-limit", value] + else: + logging.warning("unsupported config name:%s for javascript extractor.", key) + return cmd + + +def properties_extractor_cmd(source_root, database, options): + cmd = jar_extractor_cmd(Extractor.properties_extractor, source_root, database) + return cmd + + +def python_extractor_cmd(source_root, database, options): + cmd = list() + cmd += [str(Extractor.python_extractor), "-s", str(source_root), "-d", str(database)] + return cmd + + +def sql_extractor_cmd(source_root, database, options): + cmd = list() + cmd += jar_extractor_cmd(Extractor.sql_extractor, source_root, database) + if "sql-dialect-type" in options: + cmd += ["--sql-dialect-type", options["sql-dialect-type"]] + return cmd + + +def swift_extractor(source_root, database, options): + cmd = list() + cmd += [str(Extractor.swift_extractor), str(source_root), str(database)] + if options: + for (key, value) in options.items(): + if key == "corpus": + for tmp in value.split(","): + cmd += ["--corpus", tmp] + else: + logging.warning("unsupported config name:%s for Swift extractor.", key) + return cmd + + +def xml_extractor_cmd(source_root, database, options): + cmd = jar_extractor_cmd(Extractor.xml_extractor, source_root, database) + return cmd + + +def jar_extractor_cmd(extractor_path, source_root, database): + # 获取内存信息 + mem = psutil.virtual_memory() + total_memory = mem.total + total_memory_gb = round(total_memory / (1024 ** 3)) + logging.info("current memory is : %s GB", total_memory_gb) + xmx = max(total_memory_gb - 1, 6) + logging.info("final -Xmx is: %s GB", xmx) + cmd = list() + cmd += ["java", "-jar", "-Xmx" + str(xmx) + "g", str(extractor_path)] + cmd += [str(source_root), str(database)] + return cmd + + +def extractor_run(language, source_root, database, timeout, options): + function_name = language + "_extractor_cmd" + if function_name in globals(): + # 通过语言名确定函数名并直接调用对应抽取器执行函数,获取执行指令 + function = globals()[function_name] + cmd = function(source_root, database, options) + if cmd == -1: + logging.error("option error") + logging.error("Failed to obtain the %s extractor", language) + return -1 + tmp = Runner(cmd, timeout) + return tmp.subrun() + else: + logging.error("Not supported language: %s", language) + return -1 + diff --git a/cli/godel/__init__.py b/cli/godel/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/godel/godel_compiler.py b/cli/godel/godel_compiler.py new file mode 100644 index 00000000..b8e853a4 --- /dev/null +++ b/cli/godel/godel_compiler.py @@ -0,0 +1,67 @@ +import logging +import tempfile +import time +from pathlib import Path + +from run.runner import Runner +from sparrow_schema.schema import sparrow + + +def godel_version_judge(path) -> str: + # 判断脚本对应的godel编译器版本 + result = "script" + try: + with open(path, "r") as f: + tmp = f.readline() + if "1.0" in tmp: + result = "1.0" + except Exception as e: + logging.error(f"godel version judge error: {str(e)}") + return result + + +def get_godel_compile(path): + version = godel_version_judge(path) + godel = "" + if version == "1.0": + godel = sparrow.godel_1_0 + elif version == "script": + godel = sparrow.godel_script + return godel + + +def backend_execute(path, database, output, timeout, output_format, verbose): + godel = get_godel_compile(path) + version = godel_version_judge(path) + cmd = list() + cmd += [str(godel), str(path), "--run-souffle-directly", "--package-path"] + cmd += [str(sparrow.lib_1_0)] + if database is not None: + cmd += ["--souffle-fact-dir", database] + cmd += ["--souffle-output-format", output_format, "--souffle-output-path", output] + if verbose: + cmd += ["--verbose"] + tmp = Runner(cmd, timeout) + return tmp.subrun() + + +def execute(path, database, output, timeout, output_format, verbose): + godel = get_godel_compile(path) + version = godel_version_judge(path) + cmd = list() + if version == "script": + # godel-script两步编译,实际执行后端为1.0 + with tempfile.NamedTemporaryFile(suffix='.gdl') as temp_file: + cmd += [str(godel), str(path), "-p", str(sparrow.lib_1_0), "-o", temp_file.name] + if verbose: + cmd += ["--verbose"] + tmp = Runner(cmd, timeout) + start_time = time.time() + return_code = tmp.subrun() + if return_code != 0: + logging.error("%s compile error, please check it yourself", str(path)) + return -1 + logging.info("godel-script compile time: %.2fs", time.time() - start_time) + return backend_execute(Path(temp_file.name), database, output, timeout, output_format, verbose) + else: + return backend_execute(path, database, output, timeout, output_format, verbose) diff --git a/cli/query/__init__.py b/cli/query/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/query/run.py b/cli/query/run.py new file mode 100644 index 00000000..392cc321 --- /dev/null +++ b/cli/query/run.py @@ -0,0 +1,132 @@ +import logging +import time +from pathlib import Path + +from godel.godel_compiler import execute + + +def get_files(target_path, suffix) -> list: + path = Path(target_path).expanduser().resolve() + if not path.exists(): + logging.error("file or dir not exist %s", path) + return [] + result = [] + if path.is_dir(): + for file in path.rglob(f"*{suffix}"): + result.append(file) + elif path.is_file() and path.suffix == suffix: + result.append(path) + return result + + +# 结果是否为空判断 +def check_is_empty_query_result(output_path, output_format): + query_result = "EMPTY" + try: + with open(output_path, "r") as f: + content = f.read() + if output_format == "json": + if not content.startswith("[]"): + query_result = "NOT-EMPTY" + elif output_format == "csv": + if content is not None: + query_result = "NOT-EMPTY" + except FileNotFoundError: + logging.warning("%s not exist, Please check the script to see if there is output", output_path) + except PermissionError as pe: + logging.warning(f"can not open output file: {str(pe)}") + except Exception as e: + logging.warning(f"can not get output: {str(e)}") + return query_result + + +def conf_check(args): + for godel_dir in args.godel_dir: + path = Path(godel_dir).expanduser().resolve() + if not path.exists(): + logging.error("conf error: godel file or dir %s not exist, " + "Please redefine the directory or file by --gdl or -gdl", str(path)) + return False + output_path = Path(args.output).expanduser().resolve() + if not output_path.exists(): + logging.error("conf error: output directory %s does not exist, " + "Please redefine the directory or file by --output or -o", str(output_path)) + return False + if not output_path.is_dir(): + logging.error("conf error: output need to be dir," + "Please redefine the directory by --output or -o") + return False + if args.database: + database_path = Path(args.database).expanduser().resolve() + if not database_path.exists(): + logging.error("conf error: database does not exist, " + "Please redefine the database by --database or -d") + return False + if not database_path.is_dir(): + logging.error("conf error: need to be dir, " + "Please redefine the database by --database or -d") + return False + db_exist = False + for file in database_path.iterdir(): + if file.suffix == ".db": + db_exist = True + else: + continue + file_size = file.stat().st_size + # 格式化文件大小 + size_units = ["B", "KB", "MB", "GB", "TB"] + unit_index = 0 + while file_size >= 1024 and unit_index < len(size_units) - 1: + file_size /= 1024 + unit_index += 1 + logging.info(f"database {file} size: {file_size:.2f} {size_units[unit_index]}") + if not db_exist: + logging.error("conf error: There is no data in the specified database directory") + return False + else: + logging.warning("conf warning: There is no database, please make sure that this" + " gdl script can be executed without a database") + return True + + +def query_run(args): + # conf 检查 + if not conf_check(args): + logging.error("configuration error, Please check conf") + raise ValueError("configuration error") + # 脚本收集 + godel_path_list = list() + for godel_dir in args.godel_dir: + godel_path_list += get_files(godel_dir, ".gdl") + godel_path_list += get_files(godel_dir, ".gs") + if not godel_path_list: + logging.error("There is no godel script(ends with .gs or .gdl) in the specified directory," + "Please redefine the directory or file by --gdl or -gdl") + raise ValueError("path lib error") + status = 1 + # 目前先各自执行: + start_time = time.time() + for godel_query_script in godel_path_list: + output = str(Path(args.output).expanduser().resolve()/(godel_query_script.stem + "." + args.format)) + if args.database: + database = str(Path(args.database).expanduser().resolve()) + return_code = execute(godel_query_script, database, output, args.timeout - (time.time() - start_time), + args.format, args.verbose) + else: + return_code = execute(godel_query_script, None, output, args.timeout - (time.time() - start_time), + args.format, args.verbose) + if return_code == 0: + query_result = check_is_empty_query_result(output, args.format) + logging.info("Task %s is %s, result is %s, execution time is %.2fs.", + str(godel_query_script), "success", query_result, time.time() - start_time) + else: + status = 0 + logging.error("Task %s is %s, result is %s, execution time is %.2fs.", + str(godel_query_script), "fail", "null", time.time() - start_time) + logging.error("%s execute error, please check by log", str(godel_query_script)) + if status == 1: + logging.info("run success") + else: + logging.error("run fail, please check by log") + raise RuntimeError("run fail") + return diff --git a/cli/rebuild/__init__.py b/cli/rebuild/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/rebuild/lib.py b/cli/rebuild/lib.py new file mode 100644 index 00000000..c8d9313f --- /dev/null +++ b/cli/rebuild/lib.py @@ -0,0 +1,119 @@ +import logging +import re +import shutil +import tempfile +import time + +from query.run import get_files +from run.runner import Runner +from sparrow_schema.schema import sparrow + +file_list = dict() + + +# 目前仅开放下列5种语言的godel-script写法,后续根据开放的语言进行修改 +def open_lib(): + return ["java", "javascript", "go", "xml", "python"] + + +def get_rebuild_lang(args): + lib_list = list() + for lang in args.language: + if lang == "all": + lib_list += open_lib() + continue + lib_list.append(lang) + lib_list = list(set(lib_list)) + return lib_list + + +def extract_first_number(string): + pattern = r"\d+(?=.*\|)" + match = re.search(pattern, string) + if match: + return match.group() + else: + return None + + +def line_replace(output, line, base): + actual_line = int(line) - base + return output.replace(line, " " * (len(line) - len(str(actual_line))) + str(actual_line), 1) + + +# 日志输出修改:目前将lib和一进行编译,此处out通过行号将错误信息对应会原文件 +def log_out(stream): + global file_list + for line in iter(stream.readline, b''): + output = line.strip() + if output: + if "-->" in output: + match = re.search(r'-->\s*([^:]+):(\d+)', output) + if match: + file_name = match.group(1) + line = match.group(2) + num = 0 + for file in file_list: + num += file["lines"] + if int(line) <= num: + output = output.replace(file_name, str(file["name"]), 1) + output = line_replace(output, line, num - file["lines"]) + break + else: + line = extract_first_number(output) + if line is not None: + num = 0 + for file in file_list: + num += file["lines"] + if int(line) <= num: + output = line_replace(output, line, num - file["lines"]) + break + print(output) + + +def rebuild_lang(lib, verbose): + global file_list + lib_path = sparrow.lib_script / "coref" / lib + file_list = list() + gdl_list = get_files(lib_path, ".gs") + gdl_list += get_files(lib_path, ".gdl") + with tempfile.NamedTemporaryFile(suffix='.gdl', mode="w+") as output_file: + output_file.writelines("// script\n") + file_list.append({"name": "begin", "lines": 1}) + num = 1 + for file_name in gdl_list: + with open(file_name, "r") as file: + lines = file.readlines() + if len(lines) == 0: + continue + last_element = lines[-1] + if not last_element.endswith('\n'): + last_element += '\n' + lines[-1] = last_element + output_file.writelines(lines) + file_list.append({"name": file_name, "lines": len(lines)}) + num += len(lines) + output_file.seek(0) + cmd = list() + with tempfile.NamedTemporaryFile(suffix='.gdl') as tmp_out: + cmd += [str(sparrow.godel_script), str(output_file.name), "-p", str(sparrow.lib_1_0), "-o", tmp_out.name] + if verbose: + cmd += ["--verbose"] + tmp = Runner(cmd, 3600) + start_time = time.time() + return_code = tmp.subrun(log_out) + if return_code != 0: + logging.error("%s lib compile error, please check it yourself", lib_path) + return -1 + shutil.copy2(tmp_out.name, sparrow.lib_1_0 / ("coref." + lib + ".gdl")) + logging.info("%s lib compile success time: %.2fs", lib_path, time.time() - start_time) + + +def rebuild_lib(args): + lib_list = get_rebuild_lang(args) + status = 0 + for lib in lib_list: + if rebuild_lang(lib, args.verbose) == -1: + status = -1 + if status == -1: + raise RuntimeError("lib compile fail") diff --git a/cli/requirements.txt b/cli/requirements.txt new file mode 100644 index 00000000..63c468f0 --- /dev/null +++ b/cli/requirements.txt @@ -0,0 +1 @@ +psutil>=5.9.5 \ No newline at end of file diff --git a/cli/run/__init__.py b/cli/run/__init__.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cli/run/__init__.py @@ -0,0 +1 @@ + diff --git a/cli/run/runner.py b/cli/run/runner.py new file mode 100644 index 00000000..0226d7e3 --- /dev/null +++ b/cli/run/runner.py @@ -0,0 +1,41 @@ +import logging +import subprocess +import threading +import shlex + + +def output_stream(stream): + for line in iter(stream.readline, b''): + output = line.strip() + if output: + print(output) + + +class Runner: + def __init__(self, cmd, timeout_seconds): + self.cmd = cmd + self.timeout_seconds = timeout_seconds + + def subrun(self, output=None): + logging.info("execute : %s", shlex.join(self.cmd)) + try: + process = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + encoding="utf-8") + if output is None: + output = output_stream + output_thread = threading.Thread(target=output, args=(process.stdout,)) + output_thread.daemon = True # 设置为守护线程 + output_thread.start() + + process.wait(timeout=self.timeout_seconds) + + if process.returncode is None: + # 超时处理 + process.kill() + logging.error("execute time > %s s, time out, You can add -t option to adjust timeout", + self.timeout_seconds) + return_code = process.wait() + return return_code + except Exception as e: + logging.error("execute error: %s", e) + return -1 diff --git a/cli/sparrow b/cli/sparrow new file mode 100644 index 00000000..50c5f70d --- /dev/null +++ b/cli/sparrow @@ -0,0 +1,27 @@ +#!/bin/sh + +# A convenient method to return the actual path even for non symlinks +# and multi-level symlinks. +function get_realpath() { + local previous="$1" + local next=$(readlink "${previous}") + while [ -n "${next}" ]; do + previous="${next}" + next=$(readlink "${previous}") + done + echo "${previous}" +} + +PYTHON="" +if command -v python > /dev/null 2>&1; then + PYTHON="python" +elif command -v python2 > /dev/null 2>&1; then + PYTHON="python2" +elif command -v python3 > /dev/null 2>&1; then + PYTHON="python3" +else + echo "No python interpreter founded." + exit -1 +fi + +exec $PYTHON "$(dirname $(get_realpath "$0"))"/cli/sparrow-cli.zip --sparrow-cli-internal "$(dirname $(get_realpath "$0"))" "$@" diff --git a/cli/sparrow-cli.py b/cli/sparrow-cli.py new file mode 100644 index 00000000..08fa6f2e --- /dev/null +++ b/cli/sparrow-cli.py @@ -0,0 +1,141 @@ +import argparse +import os +import sys + +from rebuild.lib import rebuild_lib, open_lib + +sys.path.append(os.path.join(sys.path[0], "..")) +from sparrow_schema.schema import * +from query.run import * +from extractor.extractor import Extractor +from database.create import database_create + +SPARROW_HOME = os.path.abspath(os.path.join(os.path.join(sys.path[0], ".."))) + + +def extractor_choices(): + extractor_list = list() + for name, value in vars(Extractor).items(): + if "extractor" in name: + extractor_list.append(name.split("_")[0]) + return extractor_list + + +def parse_args(): + global SPARROW_HOME + parser = argparse.ArgumentParser(description='sparrow-cli', + formatter_class=argparse.RawTextHelpFormatter) + parser.add_argument("--version", "-v", dest='version', action="store_true", help='version') + parser.add_argument("--sparrow-home", "-sparrow-home", dest='sparrow_home', + help='sparrow home, You can specify the sparrow location yourself') + parser.add_argument('--sparrow-cli-internal', dest='sparrow_home_internal', help=argparse.SUPPRESS) + parser.add_argument('--verbose', action='store_true', help='Enable verbose mode') + subparsers = parser.add_subparsers(title='subcommands', dest='subcommand') + # 子命令query + subparser_query = subparsers.add_parser('query', help='execute godel script') + # 子命令query的子解析器 + sub_subparser_query = subparser_query.add_subparsers(title='query_subcommands', dest='query_subcommands') + # query的子命令run + subparser_query_run = sub_subparser_query.add_parser('run', help='execute godel script') + subparser_query_run.add_argument("--database", '-d', help='Directory to a godel database to query') + subparser_query_run.add_argument("--format", '-f', choices=['csv', 'json'], default='json', + help='Select output format. default output json') + subparser_query_run.add_argument("--output", '-o', default=os.getcwd(), + help='Select output dir, The output file will have the same name as the Godel ' + 'script, but with the {.json} extension') + subparser_query_run.add_argument("--timeout", '-t', type=int, default=3600, + help='Set query timeout in seconds, default 3600') + subparser_query_run.add_argument("--gdl", '-gdl', required=True, nargs="*", dest="godel_dir", + help='The location of the godel script that needs to execute') + subparser_query_run.add_argument('--verbose', action='store_true', help='Enable verbose mode') + + # 子命令database + subparser_database = subparsers.add_parser('database', help='data extract') + # 子命令database子解析器 + sub_subparser_database = subparser_database.add_subparsers(title='database_subcommands', + dest='database_subcommands') + # database的子命令create + subparser_database_create = sub_subparser_database.add_parser('create', help='data extract') + subparser_database_create.add_argument("--source-root", '-s', required=True, + help='Select source root,default to current directory') + subparser_database_create.add_argument('--data-language-type', '-lang', nargs="*", dest="language", + choices=extractor_choices(), required=True, help='data language type, Pass ' + 'in parameters separated ' + 'by whitespace. e.g. ' + '-lang java xml') + subparser_database_create.add_argument("--output", '-o', required=True, help='Database generation directory') + subparser_database_create.add_argument("--timeout", '-t', type=int, default=3600, + help='Set extract timeout in seconds, default 3600') + subparser_database_create.add_argument('--verbose', action='store_true', help='Enable verbose mode') + subparser_database_create.add_argument('--overwrite', action='store_true', + help='whether to overwrite the database, Default not') + subparser_database_create.add_argument('--extraction-config-file', + help='Extractor execute option file, The requirement is a json file') + subparser_database_create.add_argument('--extraction-config', nargs="*", help='Extractor execute option,' + 'java.a=b will regard as "java" : {' + '"a" : "b"} in ' + 'extraction-config-file,Parameters ' + 'other than a.b=c will not be ' + 'accepted') + # 子命令rebuild + subparser_rebuild = subparsers.add_parser('rebuild', help='rebuild tool') + # 子命令rebuild的子解析器 + sub_subparser_rebuild = subparser_rebuild.add_subparsers(title='rebuild_subcommands', dest='rebuild_subcommands') + # rebuild的子命令lib + subparser_rebuild_lib = sub_subparser_rebuild.add_parser('lib', help='rebuild lib') + subparser_rebuild_lib.add_argument('--data-language-type', '-lang', nargs="*", dest="language", + choices=open_lib() + ["all"], required=True, help='data language type, Pass ' + 'in parameters separated ' + 'by whitespace. e.g. ' + '-lang java xml') + subparser_rebuild_lib.add_argument('--verbose', action='store_true', help='Enable verbose mode') + args = parser.parse_args() + + # 如果没有参数输入,直接回车,则显示帮助信息 + if len(sys.argv) == 1: + parser.print_help() + logging.warning("please give conf to start sparrow as help, it will not start") + return + + # 设置SPARROW_HOME + # bazel会将脚本打包进pyz中,SPARROW_HOME需要从SHELL中传入,对用户不可见 + if args.sparrow_home_internal: + SPARROW_HOME = args.sparrow_home_internal + # 用户设置SPARROW_HOME可以覆盖掉脚本设置 + if args.sparrow_home: + SPARROW_HOME = args.sparrow_home + sparrow(SPARROW_HOME) + + Extractor() + # 查询版本号, 查找配置文件 + if args.version: + print(sparrow.version) + return + if args.verbose: + log_level = logging.DEBUG + else: + log_level = logging.INFO + console_handler = logging.StreamHandler(sys.stdout) + console_handler.setLevel(level=log_level) + formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s') + + console_handler.setFormatter(formatter) + logging.basicConfig(level=log_level, handlers=[console_handler]) + + logging.info("sparrow %s will start", sparrow.version) + if args.subcommand == "query": + if args.query_subcommands == "run": + query_run(args) + elif args.subcommand == "database": + if args.database_subcommands == "create": + database_create(args) + elif args.subcommand == "rebuild": + if args.rebuild_subcommands == "lib": + rebuild_lib(args) + else: + logging.warning("please give conf to start sparrow, it will not start") + return + + +if __name__ == '__main__': + parse_args() diff --git a/cli/sparrow_schema/__init__.py b/cli/sparrow_schema/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/sparrow_schema/schema.py b/cli/sparrow_schema/schema.py new file mode 100644 index 00000000..b8d0a402 --- /dev/null +++ b/cli/sparrow_schema/schema.py @@ -0,0 +1,37 @@ +import logging +from pathlib import Path + + +class sparrow: + home = "" + godel_1_0 = "" + godel_script = "" + language = "" + lib = "" + lib_1_0 = "" + lib_script = "" + version = "" + + def __init__(self, sparrow_home): + sparrow.home = Path(sparrow_home).expanduser().resolve() + sparrow.godel_1_0 = sparrow.home/"godel-1.0"/"usr"/"bin"/"godel" + sparrow.godel_script = sparrow.home/"godel-script"/"usr"/"bin"/"godel" + sparrow.language = sparrow.home/"language" + sparrow.lib = sparrow.home/"lib" + sparrow.lib_1_0 = sparrow.home/"lib-1.0" + sparrow.lib_script = sparrow.home/"lib-script" + version_path = sparrow.home/"version.txt" + if version_path.exists(): + try: + with open(version_path, "r") as f: + content = f.read() + sparrow.version = content + except PermissionError as pe: + sparrow.version = "no version file found!" + logging.warning(f"can not open version.txt: {str(pe)}") + except Exception as e: + sparrow.version = "no version file found!" + logging.warning(f"can not get version: {str(e)}") + else: + sparrow.version = "no version file found!" + logging.warning("no version file found!") diff --git a/example/go/CyclomaticComplexity.gdl b/example/go/CyclomaticComplexity.gdl new file mode 100644 index 00000000..bdc0289c --- /dev/null +++ b/example/go/CyclomaticComplexity.gdl @@ -0,0 +1,30 @@ +// script +use coref::go::* + +fn default_db() -> GoDB { + return GoDB::load("coref_go_src.db") +} + +/** + * @param name: file name + * @param func: function name + * @param cmplx: function cyclomatic complexity + * @param sl,el,sc,ec: function location info + */ +fn out(name: string, func: string, cmplx: int, sl: int, el: int) -> bool { + for(f in GoFile(default_db()), function in Function(default_db())) { + if ((!f.isAutoGenereatedFile()) && + f.key_eq(function.getBelongsFile()) && + name = f.getName() && + func = function.getName() && + cmplx = function.getCyclomaticComplexity() && + sl = function.getLocation().getStartLineNumber() && + el = function.getLocation().getEndLineNumber()) { + return true + } + } +} + +fn main() { + output(out()) +} \ No newline at end of file diff --git a/example/go/FileInfo.gdl b/example/go/FileInfo.gdl new file mode 100644 index 00000000..b7690b9f --- /dev/null +++ b/example/go/FileInfo.gdl @@ -0,0 +1,39 @@ +// script +use coref::go::* + +fn default_db() -> GoDB { + return GoDB::load("coref_go_src.db") +} +/** + * @param name file name + * @param funcCount function/method quantity + * @param totallines total lines of file + * @param codelines code line of file + * @param commentlines comment line of fine + * @param md5 md5 of this file + * @param sha256 sha256 of this file + */ +fn out( + name: string, + funcCount: int, + totallines: int, + codelines: int, + commentlines: int, + md5: string, + sha256: string) -> bool { + for(f in File(default_db())) { + if (name = f.getName() && + funcCount = f.getFunctionCount() && + md5 = f.getMd5Sum() && + sha256 = f.getSha256Sum() && + totallines = f.getLineInfo().getNumberOfTotalLines() && + codelines = f.getLineInfo().getNumberOfCodeLines() && + commentlines = f.getLineInfo().getNumberOfCommentLines()) { + return true + } + } +} + +fn main() { + output(out()) +} \ No newline at end of file diff --git a/example/go/FunctionComment.gdl b/example/go/FunctionComment.gdl new file mode 100644 index 00000000..1cef0b70 --- /dev/null +++ b/example/go/FunctionComment.gdl @@ -0,0 +1,28 @@ +// script +use coref::go::* + +fn default_db() -> GoDB { + return GoDB::load("coref_go_src.db") +} + +// Define a predicate called 'out' with parameters fileName, funcName, funcComment, and signature +fn out(fileName: string, funcName: string, funcComment: string, signature: string) -> bool { + // Check if there exists a Function object 'func' + for(func in Function(default_db())) { + if ( + // Get the name of the file the function belongs to and assign it to the variable 'fileName' + fileName = func.getBelongsFile().getName() && + // Get the name of the function and assign it to the variable 'funcName' + funcName = func.getName() && + // Get the associated comment string for the function and assign it to the variable 'funcComment' + funcComment = func.getAssociatedCommentString() && + // Get the function type signature and assign it to the variable 'signature' + signature = func.getFunctionTypeSignature()) { + return true + } + } +} + +fn main() { + output(out()) +} \ No newline at end of file diff --git a/example/java/ClassHierarchy.gdl b/example/java/ClassHierarchy.gdl new file mode 100644 index 00000000..4da21271 --- /dev/null +++ b/example/java/ClassHierarchy.gdl @@ -0,0 +1,23 @@ +// script +use coref::java::* + +fn default_java_db() -> JavaDB { + return JavaDB::load("coref_java_src.db") +} + +/** + * Find all class and the inheritances + * including parent class inheritance and ancestor class inheritance + */ +fn class_hierarchy(className : string, superClassName : string) -> bool { + for (c in Class(default_java_db()), ancestor in c.getAnAncestorClass()) { + if (className = c.getQualifiedName() && + superClassName = ancestor.getQualifiedName()) { + return true + } + } +} + +fn main() { + output(class_hierarchy()) +} \ No newline at end of file diff --git a/example/java/ClassMethods.gdl b/example/java/ClassMethods.gdl new file mode 100644 index 00000000..95b9fa2a --- /dev/null +++ b/example/java/ClassMethods.gdl @@ -0,0 +1,20 @@ +// script +use coref::java::* + +fn default_java_db() -> JavaDB { + return JavaDB::load("coref_java_src.db") +} + +// Find all methods of the class +fn methods(className : string, methodName : string) -> bool { + for (c in Class(default_java_db()), m in c.getAllMethods()) { + if (className = c.getQualifiedName() && + methodName = m.getName()){ + return true + } + } +} + +fn main() { + output(methods()) +} \ No newline at end of file diff --git a/example/java/UnusedMethod.gdl b/example/java/UnusedMethod.gdl new file mode 100644 index 00000000..11e9bd4d --- /dev/null +++ b/example/java/UnusedMethod.gdl @@ -0,0 +1,19 @@ +// script +use coref::java::* + +fn default_java_db() -> JavaDB { + return JavaDB::load("coref_java_src.db") +} + +// 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()) { + return true + } + } +} + +fn main() { + output(unused_method()) +} \ No newline at end of file diff --git a/example/javascript/ASTPrint.gdl b/example/javascript/ASTPrint.gdl new file mode 100644 index 00000000..8f0ea8a3 --- /dev/null +++ b/example/javascript/ASTPrint.gdl @@ -0,0 +1,62 @@ +// script +use coref::javascript::* + +/** + * print AST + * + * @param filePath file path + * @param parentId parent node ID + * @param parentKind parent node kind + * @param parentStartLine parent node start line + * @param parentEndLine parent node end line + * @param childId child node ID + * @param childKind child node kind + * @param childStartLine child node start line + * @param childEndLine child node end line + * @param index child node index + */ +fn out( + filePath: string, + parentId: int, + parentKind: string, + parentStartLine: int, + parentEndLine: int, + childId: int, + childKind: string, + childStartLine: int, + childEndLine: int, + index: int +) -> bool { + let (db = JavascriptDB::load("coref_javascript_src.db")) { + for (parent in Node(db), + child in Node(db), + parentSyntaxKind in SyntaxKind(), + childSyntaxKind in SyntaxKind(), + parentLocation in Location(db), + childLocation in Location(db), + file in File(db)) { + if (parent.key_eq(child.getParent()) && + parentId = parent.id && + childId = child.id && + parentSyntaxKind.id = parent.getKind() && + childSyntaxKind.id = child.getKind() && + parentKind = parentSyntaxKind.getName() && + childKind = childSyntaxKind.getName() && + index = child.getIndex() && + parentLocation = parent.getLocation() && + childLocation = parent.getLocation() && + file = parentLocation.getFile() && + filePath = file.getRelativePath() && + parentStartLine = parentLocation.getStartLineNumber() && + parentEndLine = parentLocation.getEndLineNumber() && + childStartLine = childLocation.getStartLineNumber() && + childEndLine = childLocation.getEndLineNumber()) { + return true + } + } + } +} + +fn main() { + output(out()) +} diff --git a/example/javascript/ChangeEffect.gdl b/example/javascript/ChangeEffect.gdl new file mode 100644 index 00000000..264713c1 --- /dev/null +++ b/example/javascript/ChangeEffect.gdl @@ -0,0 +1,76 @@ +// script +use coref::javascript::* + +fn default_db() -> JavascriptDB { + return JavascriptDB::load("coref_javascript_src.db") +} + +fn getACallerFunction(function: FunctionLikeDeclaration, callerFunction: FunctionLikeDeclaration) -> bool { + for (mayInvokeExpression in MayInvokeExpression(default_db())) { + if (mayInvokeExpression in function.getACallSite() && + callerFunction = mayInvokeExpression.getEnclosingFunction()) { + return true + } + } +} + +fn getAnEffectedFunction(function: FunctionLikeDeclaration, effectedFunction: FunctionLikeDeclaration) -> bool { + if (getACallerFunction(function, effectedFunction)) { + return true + } + for (callerFunction in FunctionLikeDeclaration(default_db())) { + if (getACallerFunction(function, callerFunction) && + getAnEffectedFunction(callerFunction, effectedFunction)) { + return true + } + } +} + +/** + * Query the effected functions according to the changed lines. + * + * @param function the changed function id + * @param signature the changed function signature + * @param functionPath the changed function file path + * @param startLine the changed function start line + * @param endLine the changed function end line + * @param effectedFunction the effected function id + * @param effectedSignature the effected function signature + * @param effectedFunctionPath the effected function file path + * @param effectedStartLine the effected function start line + * @param effectedEndLine the effected function end line + */ +fn out( + function: FunctionLikeDeclaration, + signature: string, + functionPath: string, + startLine: int, + endLine: int, + effectedFunction: FunctionLikeDeclaration, + effectedSignature: string, + effectedFunctionPath: string, + effectedStartLine: int, + effectedEndLine: int +) -> bool { + if (getAnEffectedFunction(function, effectedFunction)) { + let (symbol = function.getSymbol(), + effectedSymbol = effectedFunction.getSymbol(), + location = function.getLocation(), + effectedLocation = effectedFunction.getLocation()) { + if (signature = symbol.getDescription() && + effectedSignature = effectedSymbol.getDescription() && + functionPath = location.getRelativePath() && + startLine = location.getStartLineNumber() && + endLine = location.getEndLineNumber() && + effectedFunctionPath = effectedLocation.getRelativePath() && + effectedStartLine = effectedLocation.getStartLineNumber() && + effectedEndLine = effectedLocation.getEndLineNumber()) { + return true + } + } + } +} + +fn main() { + output(out()) +} \ No newline at end of file diff --git a/example/javascript/CyclomaticComplexity.gdl b/example/javascript/CyclomaticComplexity.gdl new file mode 100644 index 00000000..446a756a --- /dev/null +++ b/example/javascript/CyclomaticComplexity.gdl @@ -0,0 +1,34 @@ +// script +use coref::javascript::* + +fn default_db() -> JavascriptDB { + return JavascriptDB::load("coref_javascript_src.db") +} + +/** + * Output the cyclomatic complexity of each function + * + * @param filePath file path + * @param functionName function name + * @param complexity cyclomatic complexity + * @param startLine function start line + * @param endLine function end line + */ +fn out(filePath: string, functionName: string, complexity: int, startLine: int, endLine: int) -> bool { + let (db = default_db()) { + for (func in FunctionLikeDeclaration(db), file in File(db)) { + if (complexity = func.getCyclomaticComplexity() && + functionName = func.getName() && + file = func.getLocation().getFile() && + filePath = file.getRelativePath() && + startLine = func.getLocation().getStartLineNumber() && + endLine = func.getLocation().getEndLineNumber()) { + return true + } + } + } +} + +fn main() { + output(out()) +} \ No newline at end of file diff --git a/example/python/CyclomaticComplexity.gdl b/example/python/CyclomaticComplexity.gdl new file mode 100644 index 00000000..6daccde5 --- /dev/null +++ b/example/python/CyclomaticComplexity.gdl @@ -0,0 +1,37 @@ +// script +use coref::python::* + +fn default_db() -> PythonDB { + return PythonDB::load("coref_python_src.db") +} + +/** + * Get cyclomatic complexity of functions + * + * @param name function name + * @param value cyclomatic complexity of function + * @param path path of file including this function + * @param sline function start line + * @param eline function end line + */ +fn getCyclomaticComplexity( + name: string, + value: int, + path: string, + sline: int, + eline: int) -> bool { + // get metric function + for (c in MetricFunction(default_db())) { + if (path = c.getLocation().getFile().getRelativePath() && + name = c.getQualifiedName() && + value = c.getCyclomaticComplexity() && + sline = c.getLocation().getStartLineNumber() && + eline = c.getLocation().getEndLineNumber()) { + return true + } + } +} + +fn main() { + output(getCyclomaticComplexity()) +} \ No newline at end of file diff --git a/example/python/DocumentedPercentage.gdl b/example/python/DocumentedPercentage.gdl new file mode 100644 index 00000000..f4665ff6 --- /dev/null +++ b/example/python/DocumentedPercentage.gdl @@ -0,0 +1,80 @@ +// script +use coref::python::* + +schema PublicVisitedElement extends CombineElement {} + +impl PublicVisitedElement { + @data_constraint + pub fn __all__(db: PythonDB) -> *PublicVisitedElement { + for (tmp in Class(db)) { + yield PublicVisitedElement {id: tmp.element_oid} + } + for (tmp in Function(db)) { + yield PublicVisitedElement {id: tmp.element_oid} + } + } +} + +fn default_db() -> PythonDB { + return PythonDB::load("coref_python_src.db") +} + + +// count number of total public element +fn countTotalPublicElement() -> int { + return PublicVisitedElement(default_db()).len() +} + +// get public elements with Docstring comment +fn withDocstringCommentElement() -> *PublicVisitedElement { + let (db = default_db()) { + for (e in PublicVisitedElement(db), j in DocstringComment(db)) { + if (e.key_eq(j.getDocumentableElement())) { + yield e + } + } + } +} + +// count number of public elements with Docstring comment +fn countTotalPublicDocumentedElement() -> int { + return withDocstringCommentElement().len() +} + +fn withPublicDocumentedBelowElement() -> *PublicVisitedElement { + let (db = default_db()) { + for (e in PublicVisitedElement(db), j in Comment(db)) { + if (e.key_eq(j.getDocumentedClassOrFunctionElement())) { + yield e + } + } + } +} + +// count number of public element with single line comment +fn countTotalPublicDocumentedBelowElement() -> int { + return withPublicDocumentedBelowElement().len() +} + + +// calculate documented percentage +fn getDocumentedPercentage(documentedPercentage: int) -> bool { + let (i = countTotalPublicElement(), + j = countTotalPublicDocumentedElement(), + k = countTotalPublicDocumentedBelowElement()) { + if (i = 0) { + if (documentedPercentage = -1) { + return true + } + } + if (i != 0) { + if (documentedPercentage = (j + k) * 1000 / i) { + return true + } + } + } +} + +fn main() { + output(getDocumentedPercentage()) +} \ No newline at end of file diff --git a/example/python/MethodComment.gdl b/example/python/MethodComment.gdl new file mode 100644 index 00000000..c39b5612 --- /dev/null +++ b/example/python/MethodComment.gdl @@ -0,0 +1,85 @@ +// script +use coref::python::* + +schema PublicVisitedElement extends CombineElement {} + +impl PublicVisitedElement { + @data_constraint + pub fn __all__(db: PythonDB) -> *PublicVisitedElement { + for (tmp in Class(db)) { + yield PublicVisitedElement {id: tmp.element_oid} + } + for (tmp in Function(db)) { + yield PublicVisitedElement {id: tmp.element_oid} + } + } + + pub fn getName(self) -> string { + let (tmp = Class(__all_data__).find(self)) { + return tmp.getQualifiedName() + } + let (tmp = Function(__all_data__).find(self)) { + return tmp.getQualifiedName() + } + } +} + +fn default_db() -> PythonDB { + return PythonDB::load("coref_python_src.db") +} + +fn hasComment(e: PublicVisitedElement) -> bool { + let (db = default_db()) { + for (j in DocstringComment(db)) { + if (e.key_eq(j.getDocumentableElement())) { + return true + } + } + for (j in Comment(db)) { + if (e.key_eq(j.getDocumentedClassOrFunctionElement())) { + return true + } + } + } +} + +/** + * Get comment of each public element + * + * @param type public visited element type + * @param name public visited element name + * @param filePath file path + * @param sline element start line + * @param eline element end line + * @param isCommented if is commented + */ +fn output_result( + type: string, + name: string, + filePath: string, + sline: int, + eline: int, + isCommented: int) -> bool { + for (e in PublicVisitedElement(default_db())) { + if (type = e.getType() && + name = e.getName() && + filePath = e.getLocation().getFile().getRelativePath() && + sline = e.getLocation().getStartLineNumber() && + eline = e.getLocation().getEndLineNumber()) { + if (hasComment(e)) { + if (isCommented = 1) { + return true + } + } + if (!hasComment(e)) { + if (isCommented = 0) { + return true + } + } + } + } +} + +fn main() { + output(output_result()) +} \ No newline at end of file diff --git a/example/query/hello.gdl b/example/query/hello.gdl new file mode 100644 index 00000000..c4189b71 --- /dev/null +++ b/example/query/hello.gdl @@ -0,0 +1,8 @@ +// script +fn hello(greeting: string) -> bool { + return greeting = "hello world!" +} + +fn main() { + output(hello()) +} \ No newline at end of file diff --git a/example/xml/GetBean.gdl b/example/xml/GetBean.gdl new file mode 100644 index 00000000..87de2614 --- /dev/null +++ b/example/xml/GetBean.gdl @@ -0,0 +1,99 @@ +// script +use coref::xml::* + +schema BeanXmlElement extends XmlElement {} + +impl BeanXmlElement { + @data_constraint + pub fn __all__(db: XmlDB) -> *BeanXmlElement { + for (e in XmlElement(db)) { + let (path = e.getLocation().getFile().getRelativePath()) { + if (!path.contains("target") && e.getName() = "bean") { + yield BeanXmlElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } + } +} + +schema EntryXmlElement extends XmlElement {} + +impl EntryXmlElement { + @data_constraint + fn __all__(db: XmlDB) -> *EntryXmlElement { + for (e in XmlElement(db)) { + if (e.getName() = "entry") { + yield EntryXmlElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } +} + +schema PropertyXmlElement extends XmlElement {} + +impl PropertyXmlElement { + @data_constraint + fn __all__(db: XmlDB) -> *PropertyXmlElement { + for (e in XmlElement(db)) { + if (e.getName() = "property") { + yield PropertyXmlElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } +} + +fn default_db() -> XmlDB { + return XmlDB::load("coref_xml_src.db") +} + +// get class name +fn getClassName(bean: BeanXmlElement) -> string { + for (attr in bean.getAttribute()) { + if (attr.getName() = "class") { + return attr.getValue() + } + } +} + +// get key +fn getKey(e: EntryXmlElement) -> string { + for (attr in e.getAttribute()) { + if (attr.getName() = "key") { + return attr.getValue() + } + } +} + +// output value and class info of the bean +fn output1(className: string, pName: string, kName: string) -> bool { + let (db = default_db()) { + for (bean in BeanXmlElement(db), p in PropertyXmlElement(db), e in EntryXmlElement(db)) { + if (className = getClassName(bean) && + bean.key_eq(p.getParent()) && + p.key_eq(e.getParent().getParent()) && + pName = p.getName() && + kName = getKey(e)) { + return true + } + } + } +} + +fn main() { + output(output1()) +} diff --git a/example/xml/POM.gdl b/example/xml/POM.gdl new file mode 100644 index 00000000..9c7779a2 --- /dev/null +++ b/example/xml/POM.gdl @@ -0,0 +1,123 @@ +// script +use coref::xml::* + +schema DependencyElement extends XmlElement {} + +impl DependencyElement { + @data_constraint + pub fn __all__(db: XmlDB) -> *DependencyElement { + for(e in XmlElement(db)) { + if (e.getElementName() = "dependency") { + yield DependencyElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } +} + +schema GroupElement extends XmlElement {} + +impl GroupElement { + @data_constraint + pub fn __all__(db: XmlDB) -> *GroupElement { + for(e in XmlElement(db)) { + if (e.getElementName() = "groupId") { + yield GroupElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } +} + +schema VersionElement extends XmlElement {} + +impl VersionElement { + @data_constraint + pub fn __all__(db: XmlDB) -> *VersionElement { + for(e in XmlElement(db)) { + if (e.getElementName() = "version") { + yield VersionElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } +} + +schema ArtifactElement extends XmlElement {} + +impl ArtifactElement { + @data_constraint + pub fn __all__(db: XmlDB) -> *ArtifactElement { + for(e in XmlElement(db)) { + if (e.getElementName() = "artifactId") { + yield ArtifactElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } +} + +schema PomFile extends XmlFile {} + +impl PomFile { + @data_constraint + pub fn __all__(db: XmlDB) -> *PomFile { + for(f in XmlFile(db)) { + if (f.getFileName() = "pom.xml") { + yield PomFile { + id: f.id, + file_name: f.file_name, + relative_path: f.relative_path + } + } + } + } +} + +// output relative path of the file, referenced jar name and version +fn out(fileName: string, m1: string, m2: string, m3: string) -> bool { + let (db = XmlDB::load("coref_xml_src.db")) { + for (f in PomFile(db), + e1 in GroupElement(db), + e2 in VersionElement(db), + e3 in ArtifactElement(db), + c1 in XmlCharacter(db), + c2 in XmlCharacter(db), + c3 in XmlCharacter(db), + p in DependencyElement(db)) { + if (f.key_eq(p.getLocation().getFile()) && + fileName = f.getRelativePath() && + p.key_eq(e1.getParent()) && + e1.key_eq(c1.getBelongedElement()) && + m1 = c1.getText() && + p.key_eq(e2.getParent()) && + e2.key_eq(c2.getBelongedElement()) && + m2 = c2.getText() && + p.key_eq(e3.getParent()) && + e3.key_eq(c3.getBelongedElement()) && + m3 = c3.getText()) { + return true + } + } + } +} + +fn main() { + output(out()) +} \ No newline at end of file diff --git a/example/xml/RPC.gdl b/example/xml/RPC.gdl new file mode 100644 index 00000000..5e751e91 --- /dev/null +++ b/example/xml/RPC.gdl @@ -0,0 +1,61 @@ +// script +use coref::xml::* + +// select XmlElement containing "mobileService" +schema MobileServiceXmlElement extends XmlElement{} + +impl MobileServiceXmlElement { + @data_constraint + pub fn __all__(db: XmlDB) -> *MobileServiceXmlElement { + for (e in XmlElement(db)) { + if (e.getElementName() = "mobileService") { + yield MobileServiceXmlElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } + + pub fn getServiceBeanValue(self) -> string { + for (a in self.getAttribute()) { + if (a.getName() = "serviceBean") { + return a.getValue() + } + } + } +} + +// select XmlElement containing "sofa:extension" +schema SofaExtensionXmlElement extends XmlElement{} +impl SofaExtensionXmlElement { + @data_constraint + pub fn __all__(db: XmlDB) -> *SofaExtensionXmlElement { + for (e in XmlElement(db)) { + if (e.getName() = "sofa:extension") { + yield SofaExtensionXmlElement { + id: e.id, + location_id: e.location_id, + parent_id: e.parent_id, + index_order: e.index_order + } + } + } + } +} + +fn out(value: string) -> bool { + let (db = XmlDB::load("coref_xml_src.db")) { + for (m in MobileServiceXmlElement(db), s in SofaExtensionXmlElement(db), ancestor in m.getAnAncestor()) { + if (s.key_eq(ancestor) && value = m.getServiceBeanValue()) { + return true + } + } + } +} + +fn main() { + output(out()) +} \ No newline at end of file diff --git a/language/go/lib/CallableExpr.gdl b/language/go/lib/CallableExpr.gdl new file mode 100644 index 00000000..d3029a45 --- /dev/null +++ b/language/go/lib/CallableExpr.gdl @@ -0,0 +1,100 @@ +schema CallableExpr extends Expr { + +} +impl CallableExpr { + @data_constraint + @inline + fn __all__(db: GoDB) -> *CallableExpr { + for (e in Expr(db)) { + if (e.isCallorconversionExpr()) { + yield CallableExpr { + id : e.id + } + } + if (e.isSelectorExpr()) { + yield CallableExpr { + id : e.id + } + } + } + } + pub fn getCallee(self) -> *Node { + for (e in Expr(__all_data__)) { + if (e.getIdx() = 0 || e.isSelectorExpr()) { // find for Call expr and get its associated Callee + if (e.getParentNode().key_eq(self)) { + yield Node{id: e.id} + } + } + } + } + pub fn getCalleeGlobalSignature(self) -> *string { + let (pkg = self.getBelongsFile().getBelongsPkg()) { + let (a1 = pkg.getPath()) { + let (a2 = pkg.getName()) { + let (s1 = a1 + "." + a2) { + for (auto_tmp1 in self.getCalleeSignature()) { + let (s2 = auto_tmp1) { + let (s = s1 + "|" + s2) { + yield s + } + } + } + } + } + } + } + } + // For callExpr's parameter + pub fn getAParameter(self) -> *Node { + for (e in Expr(__all_data__)) { + let (idx = e.getIdx()) { + if (idx > 0) { + if (e.getParentNode().key_eq(self)) { + yield Node{id: e.id} + } + } + } + } + } + pub fn getCalleeFuncName(self) -> *string { + for (tmp in self.getCallee()) { + for (callee in Expr(__all_data__)) { + if (callee.key_eq(tmp)) { + if (!callee.isSelectorExpr()) { + yield callee.print() + } + if(callee.isSelectorExpr()) { + for (sl in SelectorExpr(__all_data__)) { + if (sl.key_eq(callee)) { + yield sl.getSelector().print() + } + } + } + } + } + } + } + pub fn getCalleeSignature(self) -> *string { + for (tmp in self.getCallee()) { + for (callee in Expr(__all_data__)) { + if (callee.key_eq(tmp)) { + if (!callee.isSelectorExpr()) { + yield callee.getSignature() + } + if (callee.isSelectorExpr()) { + for (sl in SelectorExpr(__all_data__)) { + if (sl.key_eq(callee)) { + let (e1 = Expr{id: sl.getBase().id}, + e2 = Expr{id: sl.getSelector().id}){ + for (se1 in e1.getSignature(), se2 in e2.getSignature()) { + yield "(" + se1 + ") " + se2 + } + } + } + } + } + } + } + } + } +} diff --git a/language/go/lib/Comment.gdl b/language/go/lib/Comment.gdl new file mode 100644 index 00000000..e5e7f298 --- /dev/null +++ b/language/go/lib/Comment.gdl @@ -0,0 +1,74 @@ +schema Comment extends Node { + +} +impl Comment { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Comment { + for (tmp in Node(db)) { + for (c in CommentDO(db)) { + if (tmp.key_eq(c)) { + yield Comment { + id : tmp.id + } + } + } + } + } +} +schema CommentGroup extends Node { + +} +impl CommentGroup { + @data_constraint + @inline + fn __all__(db: GoDB) -> *CommentGroup { + for (tmp in Node(db)) { + for (c in CommentGroupDO(db)) { + if (tmp.key_eq(c)) { + yield CommentGroup { + id : tmp.id + } + } + } + } + } +} +schema DocComment extends Node { + +} +impl DocComment { + @data_constraint + @inline + fn __all__(db: GoDB) -> *DocComment { + for (tmp in Node(db)) { + for (d in DocCommentDO(db)) { + if (tmp.key_eq(d)) { + yield DocComment { + id : tmp.id + } + } + } + } + } + pub fn getAssociateObj(self) -> Node { + for (n in Node(__all_data__), + d in DocCommentDO(__all_data__)) { + if (d.key_eq(self)) { + if (n.id = d.getAssociateObj()) { + return n + } + } + } + } + pub fn getCommentGroup(self) -> Node { + for (n in Node(__all_data__), + d in DocCommentDO(__all_data__)) { + if (d.key_eq(self)) { + if (n.id = d.getCommentGroupId()) { + return n + } + } + } + } +} diff --git a/language/go/lib/DOClass.gdl b/language/go/lib/DOClass.gdl new file mode 100644 index 00000000..11b5959b --- /dev/null +++ b/language/go/lib/DOClass.gdl @@ -0,0 +1,2423 @@ +/** + * @brief DO class: An array length. + */ +schema ArrayLengthDO { + @primary oid: int, + tp: int, + file_id: int, + len: int +} +impl ArrayLengthDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ArrayLengthDO { + for (tmp in db.array_length) { + yield ArrayLengthDO { + oid : tmp.oid, + tp : tmp.tp, + file_id : tmp.file_id, + len : tmp.len + } + } + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } + /** + * @brief gets the file id of this element. + * @return int + */ + pub fn getFileId(self) -> int { + return self.file_id + } + /** + * @brief gets the len of this element. + * @return int + */ + pub fn getLen(self) -> int { + return self.len + } +} +/** + * @brief DO class: A base type. + */ +schema BaseTypeDO { + @primary oid: int, + ptr: int, + tp: int +} +impl BaseTypeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *BaseTypeDO { + for (tmp in db.base_type) { + yield BaseTypeDO { + oid : tmp.oid, + ptr : tmp.ptr, + tp : tmp.tp + } + } + } + /** + * @brief gets the ptr of this element. + * @return int + */ + pub fn getPtr(self) -> int { + return self.ptr + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } +} +/** + * @brief DO class: A comment. + */ +schema CommentDO { + @primary oid: int, + file_id: int, + comment_type: int, + parent: int, + index: int, + debug_info: string +} +impl CommentDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *CommentDO { + for (tmp in db.comment) { + yield CommentDO { + oid : tmp.oid, + file_id : tmp.file_id, + comment_type : tmp.comment_type, + parent : tmp.parent, + index : tmp.index, + debug_info : tmp.debug_info + } + } + } + /** + * @brief gets the file id of this element. + * @return int + */ + pub fn getFileId(self) -> int { + return self.file_id + } + /** + * @brief gets the comment type of this element. + * @return int + */ + pub fn getCommentType(self) -> int { + return self.comment_type + } + /** + * @brief gets the parent of this element. + * @return int + */ + pub fn getParent(self) -> int { + return self.parent + } + /** + * @brief gets the index of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index + } + /** + * @brief gets the debug info of this element. + * @return string + */ + pub fn getDebugInfo(self) -> string { + return self.debug_info + } +} +/** + * @brief DO class: A comment group. + */ +schema CommentGroupDO { + @primary oid: int, + file_id: int, + parent: int, + idx: int +} +impl CommentGroupDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *CommentGroupDO { + for (tmp in db.comment_group) { + yield CommentGroupDO { + oid : tmp.oid, + file_id : tmp.file_id, + parent : tmp.parent, + idx : tmp.idx + } + } + } + /** + * @brief gets the file id of this element. + * @return int + */ + pub fn getFileId(self) -> int { + return self.file_id + } + /** + * @brief gets the parent of this element. + * @return int + */ + pub fn getParent(self) -> int { + return self.parent + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } +} +/** + * @brief DO class: A compilation. + */ +schema CompilationDO { + @primary oid: int, + cwd: string +} +impl CompilationDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *CompilationDO { + for (tmp in db.compilation) { + yield CompilationDO { + oid : tmp.oid, + cwd : tmp.cwd + } + } + } + /** + * @brief gets the cwd of this element. + * @return string + */ + pub fn getCwd(self) -> string { + return self.cwd + } +} +/** + * @brief DO class: A compilation args. + */ +schema CompilationArgsDO { + @primary oid: int, + num: int, + arg: string +} +impl CompilationArgsDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *CompilationArgsDO { + for (tmp in db.compilation_args) { + yield CompilationArgsDO { + oid : tmp.oid, + num : tmp.num, + arg : tmp.arg + } + } + } + /** + * @brief gets the num of this element. + * @return int + */ + pub fn getNum(self) -> int { + return self.num + } + /** + * @brief gets the arg of this element. + * @return string + */ + pub fn getArg(self) -> string { + return self.arg + } +} +/** + * @brief DO class: A compilation compiling file. + */ +schema CompilationCompilingFileDO { + @primary oid: int, + num: int, + file: int +} +impl CompilationCompilingFileDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *CompilationCompilingFileDO { + for (tmp in db.compilation_compiling_file) { + yield CompilationCompilingFileDO { + oid : tmp.oid, + num : tmp.num, + file : tmp.file + } + } + } + /** + * @brief gets the num of this element. + * @return int + */ + pub fn getNum(self) -> int { + return self.num + } + /** + * @brief gets the file of this element. + * @return int + */ + pub fn getFile(self) -> int { + return self.file + } +} +/** + * @brief DO class: A compilation finished. + */ +schema CompilationFinishedDO { + @primary oid: int, + cpu_seconds: int, + elapsed_seconds: int +} +impl CompilationFinishedDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *CompilationFinishedDO { + for (tmp in db.compilation_finished) { + yield CompilationFinishedDO { + oid : tmp.oid, + cpu_seconds : tmp.cpu_seconds, + elapsed_seconds : tmp.elapsed_seconds + } + } + } + /** + * @brief gets the cpu seconds of this element. + * @return int + */ + pub fn getCpuSeconds(self) -> int { + return self.cpu_seconds + } + /** + * @brief gets the elapsed seconds of this element. + * @return int + */ + pub fn getElapsedSeconds(self) -> int { + return self.elapsed_seconds + } +} +/** + * @brief DO class: A component type. + */ +schema ComponentTypeDO { + @primary oid: int, + parent: int, + index: int, + name: string, + tp: int +} +impl ComponentTypeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ComponentTypeDO { + for (tmp in db.component_type) { + yield ComponentTypeDO { + oid : tmp.oid, + parent : tmp.parent, + index : tmp.index, + name : tmp.name, + tp : tmp.tp + } + } + } + /** + * @brief gets the parent of this element. + * @return int + */ + pub fn getParent(self) -> int { + return self.parent + } + /** + * @brief gets the index of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } +} +/** + * @brief DO class: A const value. + */ +schema ConstValueDO { + @primary oid: int, + expr: int, + value: string, + exact: string +} +impl ConstValueDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ConstValueDO { + for (tmp in db.const_value) { + yield ConstValueDO { + oid : tmp.oid, + expr : tmp.expr, + value : tmp.value, + exact : tmp.exact + } + } + } + /** + * @brief gets the expr of this element. + * @return int + */ + pub fn getExpr(self) -> int { + return self.expr + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the exact of this element. + * @return string + */ + pub fn getExact(self) -> string { + return self.exact + } +} +/** + * @brief DO class: A container parent. + */ +schema ContainerParentDO { + @primary oid: int, + parent: int, + child: int +} +impl ContainerParentDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ContainerParentDO { + for (tmp in db.container_parent) { + yield ContainerParentDO { + oid : tmp.oid, + parent : tmp.parent, + child : tmp.child + } + } + } + /** + * @brief gets the parent of this element. + * @return int + */ + pub fn getParent(self) -> int { + return self.parent + } + /** + * @brief gets the child of this element. + * @return int + */ + pub fn getChild(self) -> int { + return self.child + } +} +/** + * @brief DO class: A decl. + */ +schema DeclDO { + @primary oid: int, + file_id: int, + kind: int, + parent_id: int, + idx: int, + debug_info: string +} +impl DeclDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *DeclDO { + for (tmp in db.decl) { + yield DeclDO { + oid : tmp.oid, + file_id : tmp.file_id, + kind : tmp.kind, + parent_id : tmp.parent_id, + idx : tmp.idx, + debug_info : tmp.debug_info + } + } + } + /** + * @brief gets the file id of this element. + * @return int + */ + pub fn getFileId(self) -> int { + return self.file_id + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the parent id of this element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } + /** + * @brief gets the debug info of this element. + * @return string + */ + pub fn getDebugInfo(self) -> string { + return self.debug_info + } +} +/** + * @brief DO class: A def. + */ +schema DefDO { + @primary oid: int, + ident: int, + object: int +} +impl DefDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *DefDO { + for (tmp in db.def) { + yield DefDO { + oid : tmp.oid, + ident : tmp.ident, + object : tmp.object + } + } + } + /** + * @brief gets the ident of this element. + * @return int + */ + pub fn getIdent(self) -> int { + return self.ident + } + /** + * @brief gets the object of this element. + * @return int + */ + pub fn getObject(self) -> int { + return self.object + } +} +/** + * @brief DO class: A diagnostic. + */ +schema DiagnosticDO { + @primary oid: int, + severity: int, + error_tag: string, + error_message: string, + full_error_message: string, + location_id: int +} +impl DiagnosticDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *DiagnosticDO { + for (tmp in db.diagnostic) { + yield DiagnosticDO { + oid : tmp.oid, + severity : tmp.severity, + error_tag : tmp.error_tag, + error_message : tmp.error_message, + full_error_message : tmp.full_error_message, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the severity of this element. + * @return int + */ + pub fn getSeverity(self) -> int { + return self.severity + } + /** + * @brief gets the error tag of this element. + * @return string + */ + pub fn getErrorTag(self) -> string { + return self.error_tag + } + /** + * @brief gets the error message of this element. + * @return string + */ + pub fn getErrorMessage(self) -> string { + return self.error_message + } + /** + * @brief gets the full error message of this element. + * @return string + */ + pub fn getFullErrorMessage(self) -> string { + return self.full_error_message + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: A diagnostic for. + */ +schema DiagnosticForDO { + @primary diagnostic: int, + compilation: int, + file_number: int, + file_number_diagnostic_number: int +} +impl DiagnosticForDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *DiagnosticForDO { + for (tmp in db.diagnostic_for) { + yield DiagnosticForDO { + diagnostic : tmp.diagnostic, + compilation : tmp.compilation, + file_number : tmp.file_number, + file_number_diagnostic_number : tmp.file_number_diagnostic_number + } + } + } + /** + * @brief gets the compilation of this element. + * @return int + */ + pub fn getCompilation(self) -> int { + return self.compilation + } + /** + * @brief gets the file number of this element. + * @return int + */ + pub fn getFileNumber(self) -> int { + return self.file_number + } + /** + * @brief gets the file number diagnostic number of this element. + * @return int + */ + pub fn getFileNumberDiagnosticNumber(self) -> int { + return self.file_number_diagnostic_number + } +} +/** + * @brief DO class: A doc comment. + */ +schema DocCommentDO { + @primary oid: int, + associate_obj: int, + comment_group_id: int +} +impl DocCommentDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *DocCommentDO { + for (tmp in db.doc_comment) { + yield DocCommentDO { + oid : tmp.oid, + associate_obj : tmp.associate_obj, + comment_group_id : tmp.comment_group_id + } + } + } + /** + * @brief gets the associate obj of this element. + * @return int + */ + pub fn getAssociateObj(self) -> int { + return self.associate_obj + } + /** + * @brief gets the comment group id of this element. + * @return int + */ + pub fn getCommentGroupId(self) -> int { + return self.comment_group_id + } +} +/** + * @brief DO class: An element type. + */ +schema ElementTypeDO { + @primary oid: int, + container: int, + tp: int +} +impl ElementTypeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ElementTypeDO { + for (tmp in db.element_type) { + yield ElementTypeDO { + oid : tmp.oid, + container : tmp.container, + tp : tmp.tp + } + } + } + /** + * @brief gets the container of this element. + * @return int + */ + pub fn getContainer(self) -> int { + return self.container + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } +} +/** + * @brief DO class: An error. + */ +schema ErrorDO { + @primary oid: int, + kind: int, + msg: string, + raw_pos: string, + file: string, + line: int, + col: int, + pkg: int, + idx: int +} +impl ErrorDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ErrorDO { + for (tmp in db.error) { + yield ErrorDO { + oid : tmp.oid, + kind : tmp.kind, + msg : tmp.msg, + raw_pos : tmp.raw_pos, + file : tmp.file, + line : tmp.line, + col : tmp.col, + pkg : tmp.pkg, + idx : tmp.idx + } + } + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the msg of this element. + * @return string + */ + pub fn getMsg(self) -> string { + return self.msg + } + /** + * @brief gets the raw pos of this element. + * @return string + */ + pub fn getRawPos(self) -> string { + return self.raw_pos + } + /** + * @brief gets the file of this element. + * @return string + */ + pub fn getFile(self) -> string { + return self.file + } + /** + * @brief gets the line of this element. + * @return int + */ + pub fn getLine(self) -> int { + return self.line + } + /** + * @brief gets the col of this element. + * @return int + */ + pub fn getCol(self) -> int { + return self.col + } + /** + * @brief gets the pkg of this element. + * @return int + */ + pub fn getPkg(self) -> int { + return self.pkg + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } +} +/** + * @brief DO class: An expr. + */ +schema ExprDO { + @primary oid: int, + file_id: int, + kind: int, + parent_id: int, + idx: int, + debug_info: string +} +impl ExprDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ExprDO { + for (tmp in db.expr) { + yield ExprDO { + oid : tmp.oid, + file_id : tmp.file_id, + kind : tmp.kind, + parent_id : tmp.parent_id, + idx : tmp.idx, + debug_info : tmp.debug_info + } + } + } + /** + * @brief gets the file id of this element. + * @return int + */ + pub fn getFileId(self) -> int { + return self.file_id + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the parent id of this element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } + /** + * @brief gets the debug info of this element. + * @return string + */ + pub fn getDebugInfo(self) -> string { + return self.debug_info + } +} +/** + * @brief DO class: A field struct. + */ +schema FieldStructDO { + @primary oid: int, + struct: int +} +impl FieldStructDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *FieldStructDO { + for (tmp in db.field_struct) { + yield FieldStructDO { + oid : tmp.oid, + struct : tmp.struct + } + } + } + /** + * @brief gets the struct of this element. + * @return int + */ + pub fn getStruct(self) -> int { + return self.struct + } +} +/** + * @brief DO class: A fields. + */ +schema FieldsDO { + @primary oid: int, + parent_id: int, + idx: int, + kind: int +} +impl FieldsDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *FieldsDO { + for (tmp in db.fields) { + yield FieldsDO { + oid : tmp.oid, + parent_id : tmp.parent_id, + idx : tmp.idx, + kind : tmp.kind + } + } + } + /** + * @brief gets the parent id of this element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } +} +/** + * @brief DO class: A file. + */ +schema FileDO { + @primary oid: int, + pkg_oid: int, + name: string, + md5_sum: string, + sha256_sum: string +} +impl FileDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *FileDO { + for (tmp in db.file) { + yield FileDO { + oid : tmp.oid, + pkg_oid : tmp.pkg_oid, + name : tmp.name, + md5_sum : tmp.md5_sum, + sha256_sum : tmp.sha256_sum + } + } + } + /** + * @brief gets the pkg oid of this element. + * @return int + */ + pub fn getPkgOid(self) -> int { + return self.pkg_oid + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the md5 sum of this element. + * @return string + */ + pub fn getMd5Sum(self) -> string { + return self.md5_sum + } + /** + * @brief gets the sha256 sum of this element. + * @return string + */ + pub fn getSha256Sum(self) -> string { + return self.sha256_sum + } +} +/** + * @brief DO class: A file data. + */ +schema FileDataDO { + @primary oid: int, + file_id: int, + type: int, + content: string +} +impl FileDataDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *FileDataDO { + for (tmp in db.file_data) { + yield FileDataDO { + oid : tmp.oid, + file_id : tmp.file_id, + type : tmp.type, + content : tmp.content + } + } + } + /** + * @brief gets the file id of this element. + * @return int + */ + pub fn getFileId(self) -> int { + return self.file_id + } + /** + * @brief gets the type of this element. + * @return int + */ + pub fn getType(self) -> int { + return self.type + } + /** + * @brief gets the content of this element. + * @return string + */ + pub fn getContent(self) -> string { + return self.content + } +} +/** + * @brief DO class: A folder. + */ +schema FolderDO { + @primary oid: int, + name: string +} +impl FolderDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *FolderDO { + for (tmp in db.folder) { + yield FolderDO { + oid : tmp.oid, + name : tmp.name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: A has ellipsis. + */ +schema HasEllipsisDO { + @primary oid: int, + call_or_conversion_expr_id: int +} +impl HasEllipsisDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *HasEllipsisDO { + for (tmp in db.has_ellipsis) { + yield HasEllipsisDO { + oid : tmp.oid, + call_or_conversion_expr_id : tmp.call_or_conversion_expr_id + } + } + } + /** + * @brief gets the call or conversion expr id of this element. + * @return int + */ + pub fn getCallOrConversionExprId(self) -> int { + return self.call_or_conversion_expr_id + } +} +/** + * @brief DO class: A has location. + */ +schema HasLocationDO { + @primary oid: int, + location_obj: int, + location_id: int +} +impl HasLocationDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *HasLocationDO { + for (tmp in db.has_location) { + yield HasLocationDO { + oid : tmp.oid, + location_obj : tmp.location_obj, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the location obj of this element. + * @return int + */ + pub fn getLocationObj(self) -> int { + return self.location_obj + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: A key type. + */ +schema KeyTypeDO { + @primary oid: int, + map: int, + tp: int +} +impl KeyTypeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *KeyTypeDO { + for (tmp in db.key_type) { + yield KeyTypeDO { + oid : tmp.oid, + map : tmp.map, + tp : tmp.tp + } + } + } + /** + * @brief gets the map of this element. + * @return int + */ + pub fn getMap(self) -> int { + return self.map + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } +} +/** + * @brief DO class: A literal. + */ +schema LiteralDO { + @primary oid: int, + expr: int, + value: string, + raw: string +} +impl LiteralDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *LiteralDO { + for (tmp in db.literal) { + yield LiteralDO { + oid : tmp.oid, + expr : tmp.expr, + value : tmp.value, + raw : tmp.raw + } + } + } + /** + * @brief gets the expr of this element. + * @return int + */ + pub fn getExpr(self) -> int { + return self.expr + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the raw of this element. + * @return string + */ + pub fn getRaw(self) -> string { + return self.raw + } +} +/** + * @brief DO class: A location. + */ +schema LocationDO { + @primary oid: int, + start_line_number: int, + start_column_number: int, + end_line_number: int, + end_column_number: int, + token_start_offset: int, + token_end_offset: int +} +impl LocationDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *LocationDO { + for (tmp in db.location) { + yield LocationDO { + oid : tmp.oid, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number, + token_start_offset : tmp.token_start_offset, + token_end_offset : tmp.token_end_offset + } + } + } + /** + * @brief gets the start line number of this element. + * @return int + */ + pub fn getStartLineNumber(self) -> int { + return self.start_line_number + } + /** + * @brief gets the start column number of this element. + * @return int + */ + pub fn getStartColumnNumber(self) -> int { + return self.start_column_number + } + /** + * @brief gets the end line number of this element. + * @return int + */ + pub fn getEndLineNumber(self) -> int { + return self.end_line_number + } + /** + * @brief gets the end column number of this element. + * @return int + */ + pub fn getEndColumnNumber(self) -> int { + return self.end_column_number + } + /** + * @brief gets the token start offset of this element. + * @return int + */ + pub fn getTokenStartOffset(self) -> int { + return self.token_start_offset + } + /** + * @brief gets the token end offset of this element. + * @return int + */ + pub fn getTokenEndOffset(self) -> int { + return self.token_end_offset + } +} +/** + * @brief DO class: A method host. + */ +schema MethodHostDO { + @primary oid: int, + method: int, + host: int +} +impl MethodHostDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *MethodHostDO { + for (tmp in db.method_host) { + yield MethodHostDO { + oid : tmp.oid, + method : tmp.method, + host : tmp.host + } + } + } + /** + * @brief gets the method of this element. + * @return int + */ + pub fn getMethod(self) -> int { + return self.method + } + /** + * @brief gets the host of this element. + * @return int + */ + pub fn getHost(self) -> int { + return self.host + } +} +/** + * @brief DO class: A method receiver. + */ +schema MethodReceiverDO { + @primary oid: int, + method: int, + receiver: int +} +impl MethodReceiverDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *MethodReceiverDO { + for (tmp in db.method_receiver) { + yield MethodReceiverDO { + oid : tmp.oid, + method : tmp.method, + receiver : tmp.receiver + } + } + } + /** + * @brief gets the method of this element. + * @return int + */ + pub fn getMethod(self) -> int { + return self.method + } + /** + * @brief gets the receiver of this element. + * @return int + */ + pub fn getReceiver(self) -> int { + return self.receiver + } +} +/** + * @brief DO class: A mod expr. + */ +schema ModExprDO { + @primary oid: int, + kind: int, + parent: int, + idx: int +} +impl ModExprDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ModExprDO { + for (tmp in db.mod_expr) { + yield ModExprDO { + oid : tmp.oid, + kind : tmp.kind, + parent : tmp.parent, + idx : tmp.idx + } + } + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the parent of this element. + * @return int + */ + pub fn getParent(self) -> int { + return self.parent + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } +} +/** + * @brief DO class: A mod file. + */ +schema ModFileDO { + @primary oid: int, + path: string, + name: string, + go_version: string +} +impl ModFileDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ModFileDO { + for (tmp in db.mod_file) { + yield ModFileDO { + oid : tmp.oid, + path : tmp.path, + name : tmp.name, + go_version : tmp.go_version + } + } + } + /** + * @brief gets the path of this element. + * @return string + */ + pub fn getPath(self) -> string { + return self.path + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the go version of this element. + * @return string + */ + pub fn getGoVersion(self) -> string { + return self.go_version + } +} +/** + * @brief DO class: A mod require. + */ +schema ModRequireDO { + @primary oid: int, + mod_id: int, + require: string +} +impl ModRequireDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ModRequireDO { + for (tmp in db.mod_require) { + yield ModRequireDO { + oid : tmp.oid, + mod_id : tmp.mod_id, + require : tmp.require + } + } + } + /** + * @brief gets the mod id of this element. + * @return int + */ + pub fn getModId(self) -> int { + return self.mod_id + } + /** + * @brief gets the require of this element. + * @return string + */ + pub fn getRequire(self) -> string { + return self.require + } +} +/** + * @brief DO class: A mod token. + */ +schema ModTokenDO { + @primary oid: int, + token: string, + parent: int, + idx: int +} +impl ModTokenDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ModTokenDO { + for (tmp in db.mod_token) { + yield ModTokenDO { + oid : tmp.oid, + token : tmp.token, + parent : tmp.parent, + idx : tmp.idx + } + } + } + /** + * @brief gets the token of this element. + * @return string + */ + pub fn getToken(self) -> string { + return self.token + } + /** + * @brief gets the parent of this element. + * @return int + */ + pub fn getParent(self) -> int { + return self.parent + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } +} +/** + * @brief DO class: A number of line. + */ +schema NumberOfLineDO { + @primary oid: int, + number_of_total_lines: int, + number_of_code_lines: int, + number_of_comment_lines: int +} +impl NumberOfLineDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *NumberOfLineDO { + for (tmp in db.number_of_line) { + yield NumberOfLineDO { + oid : tmp.oid, + number_of_total_lines : tmp.number_of_total_lines, + number_of_code_lines : tmp.number_of_code_lines, + number_of_comment_lines : tmp.number_of_comment_lines + } + } + } + /** + * @brief gets the number of total lines of this element. + * @return int + */ + pub fn getNumberOfTotalLines(self) -> int { + return self.number_of_total_lines + } + /** + * @brief gets the number of code lines of this element. + * @return int + */ + pub fn getNumberOfCodeLines(self) -> int { + return self.number_of_code_lines + } + /** + * @brief gets the number of comment lines of this element. + * @return int + */ + pub fn getNumberOfCommentLines(self) -> int { + return self.number_of_comment_lines + } +} +/** + * @brief DO class: An object. + */ +schema ObjectDO { + @primary oid: int, + kind: int, + name: string, + debug_info: string +} +impl ObjectDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ObjectDO { + for (tmp in db.object) { + yield ObjectDO { + oid : tmp.oid, + kind : tmp.kind, + name : tmp.name, + debug_info : tmp.debug_info + } + } + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the debug info of this element. + * @return string + */ + pub fn getDebugInfo(self) -> string { + return self.debug_info + } +} +/** + * @brief DO class: An object scope. + */ +schema ObjectScopeDO { + @primary oid: int, + object: int, + scope: int +} +impl ObjectScopeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ObjectScopeDO { + for (tmp in db.object_scope) { + yield ObjectScopeDO { + oid : tmp.oid, + object : tmp.object, + scope : tmp.scope + } + } + } + /** + * @brief gets the object of this element. + * @return int + */ + pub fn getObject(self) -> int { + return self.object + } + /** + * @brief gets the scope of this element. + * @return int + */ + pub fn getScope(self) -> int { + return self.scope + } +} +/** + * @brief DO class: An object type. + */ +schema ObjectTypeDO { + @primary object: int, + tp: int +} +impl ObjectTypeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ObjectTypeDO { + for (tmp in db.object_type) { + yield ObjectTypeDO { + object : tmp.object, + tp : tmp.tp + } + } + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } +} +/** + * @brief DO class: A pkg. + */ +schema PkgDO { + @primary oid: int, + path: string, + name: string, + scope: int +} +impl PkgDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *PkgDO { + for (tmp in db.pkg) { + yield PkgDO { + oid : tmp.oid, + path : tmp.path, + name : tmp.name, + scope : tmp.scope + } + } + } + /** + * @brief gets the path of this element. + * @return string + */ + pub fn getPath(self) -> string { + return self.path + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the scope of this element. + * @return int + */ + pub fn getScope(self) -> int { + return self.scope + } +} +/** + * @brief DO class: A runtime info. + */ +schema RuntimeInfoDO { + @primary oid: int, + build_version: string, + extractor_info: string, + go_os: string, + go_arch: string +} +impl RuntimeInfoDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *RuntimeInfoDO { + for (tmp in db.runtime_info) { + yield RuntimeInfoDO { + oid : tmp.oid, + build_version : tmp.build_version, + extractor_info : tmp.extractor_info, + go_os : tmp.go_os, + go_arch : tmp.go_arch + } + } + } + /** + * @brief gets the build version of this element. + * @return string + */ + pub fn getBuildVersion(self) -> string { + return self.build_version + } + /** + * @brief gets the extractor info of this element. + * @return string + */ + pub fn getExtractorInfo(self) -> string { + return self.extractor_info + } + /** + * @brief gets the go os of this element. + * @return string + */ + pub fn getGoOs(self) -> string { + return self.go_os + } + /** + * @brief gets the go arch of this element. + * @return string + */ + pub fn getGoArch(self) -> string { + return self.go_arch + } +} +/** + * @brief DO class: A scope. + */ +schema ScopeDO { + @primary oid: int, + kind: int, + debug_info: string +} +impl ScopeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ScopeDO { + for (tmp in db.scope) { + yield ScopeDO { + oid : tmp.oid, + kind : tmp.kind, + debug_info : tmp.debug_info + } + } + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the debug info of this element. + * @return string + */ + pub fn getDebugInfo(self) -> string { + return self.debug_info + } +} +/** + * @brief DO class: A scope nesting. + */ +schema ScopeNestingDO { + @primary oid: int, + inner: int, + outer: int +} +impl ScopeNestingDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ScopeNestingDO { + for (tmp in db.scope_nesting) { + yield ScopeNestingDO { + oid : tmp.oid, + inner : tmp.inner, + outer : tmp.outer + } + } + } + /** + * @brief gets the inner of this element. + * @return int + */ + pub fn getInner(self) -> int { + return self.inner + } + /** + * @brief gets the outer of this element. + * @return int + */ + pub fn getOuter(self) -> int { + return self.outer + } +} +/** + * @brief DO class: A scope node. + */ +schema ScopeNodeDO { + @primary oid: int, + node: int, + scope: int +} +impl ScopeNodeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *ScopeNodeDO { + for (tmp in db.scope_node) { + yield ScopeNodeDO { + oid : tmp.oid, + node : tmp.node, + scope : tmp.scope + } + } + } + /** + * @brief gets the node of this element. + * @return int + */ + pub fn getNode(self) -> int { + return self.node + } + /** + * @brief gets the scope of this element. + * @return int + */ + pub fn getScope(self) -> int { + return self.scope + } +} +/** + * @brief DO class: A spec. + */ +schema SpecDO { + @primary oid: int, + kind: int, + parent_id: int, + idx: int, + debug_info: string +} +impl SpecDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *SpecDO { + for (tmp in db.spec) { + yield SpecDO { + oid : tmp.oid, + kind : tmp.kind, + parent_id : tmp.parent_id, + idx : tmp.idx, + debug_info : tmp.debug_info + } + } + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the parent id of this element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } + /** + * @brief gets the debug info of this element. + * @return string + */ + pub fn getDebugInfo(self) -> string { + return self.debug_info + } +} +/** + * @brief DO class: A stmt. + */ +schema StmtDO { + @primary oid: int, + file_id: int, + kind: int, + parent_id: int, + idx: int, + debug_info: string +} +impl StmtDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *StmtDO { + for (tmp in db.stmt) { + yield StmtDO { + oid : tmp.oid, + file_id : tmp.file_id, + kind : tmp.kind, + parent_id : tmp.parent_id, + idx : tmp.idx, + debug_info : tmp.debug_info + } + } + } + /** + * @brief gets the file id of this element. + * @return int + */ + pub fn getFileId(self) -> int { + return self.file_id + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the parent id of this element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the idx of this element. + * @return int + */ + pub fn getIdx(self) -> int { + return self.idx + } + /** + * @brief gets the debug info of this element. + * @return string + */ + pub fn getDebugInfo(self) -> string { + return self.debug_info + } +} +/** + * @brief DO class: A type. + */ +schema TypeDO { + @primary oid: int, + kind: int, + format_string: string, + raw_string: string +} +impl TypeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *TypeDO { + for (tmp in db.type) { + yield TypeDO { + oid : tmp.oid, + kind : tmp.kind, + format_string : tmp.format_string, + raw_string : tmp.raw_string + } + } + } + /** + * @brief gets the kind of this element. + * @return int + */ + pub fn getKind(self) -> int { + return self.kind + } + /** + * @brief gets the format string of this element. + * @return string + */ + pub fn getFormatString(self) -> string { + return self.format_string + } + /** + * @brief gets the raw string of this element. + * @return string + */ + pub fn getRawString(self) -> string { + return self.raw_string + } +} +/** + * @brief DO class: A type name. + */ +schema TypeNameDO { + @primary oid: int, + name: string +} +impl TypeNameDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *TypeNameDO { + for (tmp in db.type_name) { + yield TypeNameDO { + oid : tmp.oid, + name : tmp.name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: A type object. + */ +schema TypeObjectDO { + @primary oid: int, + object: int +} +impl TypeObjectDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *TypeObjectDO { + for (tmp in db.type_object) { + yield TypeObjectDO { + oid : tmp.oid, + object : tmp.object + } + } + } + /** + * @brief gets the object of this element. + * @return int + */ + pub fn getObject(self) -> int { + return self.object + } +} +/** + * @brief DO class: A type of. + */ +schema TypeOfDO { + @primary oid: int, + expr: int, + tp: int +} +impl TypeOfDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *TypeOfDO { + for (tmp in db.type_of) { + yield TypeOfDO { + oid : tmp.oid, + expr : tmp.expr, + tp : tmp.tp + } + } + } + /** + * @brief gets the expr of this element. + * @return int + */ + pub fn getExpr(self) -> int { + return self.expr + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } +} +/** + * @brief DO class: A type param. + */ +schema TypeParamDO { + @primary oid: int, + tp: int, + name: string, + bound: int, + parent: int, + index: int +} +impl TypeParamDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *TypeParamDO { + for (tmp in db.type_param) { + yield TypeParamDO { + oid : tmp.oid, + tp : tmp.tp, + name : tmp.name, + bound : tmp.bound, + parent : tmp.parent, + index : tmp.index + } + } + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the bound of this element. + * @return int + */ + pub fn getBound(self) -> int { + return self.bound + } + /** + * @brief gets the parent of this element. + * @return int + */ + pub fn getParent(self) -> int { + return self.parent + } + /** + * @brief gets the index of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index + } +} +/** + * @brief DO class: A type param decls. + */ +schema TypeParamDeclsDO { + @primary oid: int, + parent: int, + index: int +} +impl TypeParamDeclsDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *TypeParamDeclsDO { + for (tmp in db.type_param_decls) { + yield TypeParamDeclsDO { + oid : tmp.oid, + parent : tmp.parent, + index : tmp.index + } + } + } + /** + * @brief gets the parent of this element. + * @return int + */ + pub fn getParent(self) -> int { + return self.parent + } + /** + * @brief gets the index of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index + } +} +/** + * @brief DO class: A typeiadic. + */ +schema TypeiadicDO { + @primary oid: int, + association_obj_id: int +} +impl TypeiadicDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *TypeiadicDO { + for (tmp in db.typeiadic) { + yield TypeiadicDO { + oid : tmp.oid, + association_obj_id : tmp.association_obj_id + } + } + } + /** + * @brief gets the association obj id of this element. + * @return int + */ + pub fn getAssociationObjId(self) -> int { + return self.association_obj_id + } +} +/** + * @brief DO class: An un extracted. + */ +schema UnExtractedDO { + @primary oid: int, + type: int, + name: string +} +impl UnExtractedDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *UnExtractedDO { + for (tmp in db.un_extracted) { + yield UnExtractedDO { + oid : tmp.oid, + type : tmp.type, + name : tmp.name + } + } + } + /** + * @brief gets the type of this element. + * @return int + */ + pub fn getType(self) -> int { + return self.type + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: An underlying type. + */ +schema UnderlyingTypeDO { + @primary oid: int, + named: int, + tp: int +} +impl UnderlyingTypeDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *UnderlyingTypeDO { + for (tmp in db.underlying_type) { + yield UnderlyingTypeDO { + oid : tmp.oid, + named : tmp.named, + tp : tmp.tp + } + } + } + /** + * @brief gets the named of this element. + * @return int + */ + pub fn getNamed(self) -> int { + return self.named + } + /** + * @brief gets the tp of this element. + * @return int + */ + pub fn getTp(self) -> int { + return self.tp + } +} +/** + * @brief DO class: An uses. + */ +schema UsesDO { + @primary oid: int, + ident: int, + object: int +} +impl UsesDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *UsesDO { + for (tmp in db.uses) { + yield UsesDO { + oid : tmp.oid, + ident : tmp.ident, + object : tmp.object + } + } + } + /** + * @brief gets the ident of this element. + * @return int + */ + pub fn getIdent(self) -> int { + return self.ident + } + /** + * @brief gets the object of this element. + * @return int + */ + pub fn getObject(self) -> int { + return self.object + } +} +/** + * @brief DO class: A variadic. + */ +schema VariadicDO { + @primary oid: int, + associated_node: int +} +impl VariadicDO { + @data_constraint + @inline + pub fn __all__(db: GoDB) -> *VariadicDO { + for (tmp in db.variadic) { + yield VariadicDO { + oid : tmp.oid, + associated_node : tmp.associated_node + } + } + } + /** + * @brief gets the associated node of this element. + * @return int + */ + pub fn getAssociatedNode(self) -> int { + return self.associated_node + } +} +database GoDB { + array_length: *ArrayLengthDO, + base_type: *BaseTypeDO, + comment: *CommentDO, + comment_group: *CommentGroupDO, + compilation: *CompilationDO, + compilation_args: *CompilationArgsDO, + compilation_compiling_file: *CompilationCompilingFileDO, + compilation_finished: *CompilationFinishedDO, + component_type: *ComponentTypeDO, + const_value: *ConstValueDO, + container_parent: *ContainerParentDO, + decl: *DeclDO, + def: *DefDO, + diagnostic: *DiagnosticDO, + diagnostic_for: *DiagnosticForDO, + doc_comment: *DocCommentDO, + element_type: *ElementTypeDO, + error: *ErrorDO, + expr: *ExprDO, + field_struct: *FieldStructDO, + fields: *FieldsDO, + file: *FileDO, + file_data: *FileDataDO, + folder: *FolderDO, + has_ellipsis: *HasEllipsisDO, + has_location: *HasLocationDO, + key_type: *KeyTypeDO, + literal: *LiteralDO, + location: *LocationDO, + method_host: *MethodHostDO, + method_receiver: *MethodReceiverDO, + mod_expr: *ModExprDO, + mod_file: *ModFileDO, + mod_require: *ModRequireDO, + mod_token: *ModTokenDO, + number_of_line: *NumberOfLineDO, + object: *ObjectDO, + object_scope: *ObjectScopeDO, + object_type: *ObjectTypeDO, + pkg: *PkgDO, + runtime_info: *RuntimeInfoDO, + scope: *ScopeDO, + scope_nesting: *ScopeNestingDO, + scope_node: *ScopeNodeDO, + spec: *SpecDO, + stmt: *StmtDO, + type: *TypeDO, + type_name: *TypeNameDO, + type_object: *TypeObjectDO, + type_of: *TypeOfDO, + type_param: *TypeParamDO, + type_param_decls: *TypeParamDeclsDO, + typeiadic: *TypeiadicDO, + un_extracted: *UnExtractedDO, + underlying_type: *UnderlyingTypeDO, + uses: *UsesDO, + variadic: *VariadicDO, +} diff --git a/language/go/lib/Declaration.gdl b/language/go/lib/Declaration.gdl new file mode 100644 index 00000000..baa040d9 --- /dev/null +++ b/language/go/lib/Declaration.gdl @@ -0,0 +1,155 @@ +schema Decl extends Node { + +} +impl Decl { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Decl { + for (tmp in Node(db)) { + for (d in DeclDO(db)) { + if (tmp.key_eq(d)) { + yield Decl { + id : tmp.id + } + } + } + } + } + pub fn getKind(self) -> int { + for (d in DeclDO(__all_data__)) { + if (d.key_eq(self)) { + return d.getKind() + } + } + } + pub fn getBelongsFunction(self) -> Function { + for (f in Function(__all_data__)) { + if (f.key_eq(self.getParentNode())) { + return f + } + for (d in Decl(__all_data__)) { + let (n = self.getParentNode()) { + if (d.key_eq(n)) { + if (f = d.getBelongsFunction()) { + return f + } + } + } + } + } + } + + pub fn getType(self) -> string { + if (self.isBadDecl()) { + return "BadDecl" + } + if (self.isImportDecl()) { + return "ImportDecl" + } + if (self.isConstDecl()) { + return "ConstDecl" + } + if (self.isTypeDecl()) { + return "TypeDecl" + } + if (self.isVarDecl()) { + return "VarDecl" + } + if (self.isFuncDecl()) { + return "FuncDecl" + } + } + pub fn isBadDecl(self) -> bool { + if (self.getKind() = 0) { + return true + } + } + pub fn isImportDecl(self) -> bool { + if (self.getKind() = 1) { + return true + } + } + pub fn isConstDecl(self) -> bool { + if (self.getKind() = 2) { + return true + } + } + pub fn isTypeDecl(self) -> bool { + if (self.getKind() = 3) { + return true + } + } + pub fn isVarDecl(self) -> bool { + if (self.getKind() = 4) { + return true + } + } + pub fn isFuncDecl(self) -> bool { + if (self.getKind() = 5) { + return true + } + } + pub fn isLocalVaribleDecl(self) -> bool { + if (self.isConstDecl()) { + return true + } + if (self.isTypeDecl()) { + return true + } + if (self.isVarDecl()) { + return true + } + } +} +schema ConstDecl extends Decl { + +} +impl ConstDecl { + @data_constraint + @inline + fn __all__(db: GoDB) -> *ConstDecl { + for (tmp in Decl(db)) { + for (d in DeclDO(db)) { + if (tmp.key_eq(d)) { + if (tmp.isConstDecl()) { + yield ConstDecl { + id : tmp.id + } + } + } + } + } + } +} +schema VarDecl extends Decl { + +} +impl VarDecl { + @data_constraint + @inline + fn __all__(db: GoDB) -> *VarDecl { + for (tmp in Decl(db)) { + for (d in DeclDO(db)) { + if (tmp.key_eq(d)) { + if (tmp.isVarDecl()) { + yield VarDecl { + id : tmp.id + } + } + } + } + } + } + pub fn getName(self) -> string { + for (e in Expr(__all_data__), + l in LiteralDO(__all_data__)) { + if (e.isIdent()) { + if (e.getParentNode().key_eq(self)) { + if (l.getExpr() = e.id) { + return l.getValue() + } + } + } + } + } +} diff --git a/language/go/lib/Expression.gdl b/language/go/lib/Expression.gdl new file mode 100644 index 00000000..53f16b1b --- /dev/null +++ b/language/go/lib/Expression.gdl @@ -0,0 +1,649 @@ +schema Expr extends Node { + +} +impl Expr { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Expr { + for (e in ExprDO(db)) { + yield Expr { + id : e.oid + } + } + } + pub fn getIdx(self) -> int { + for (e in ExprDO(__all_data__)) { + if (e.key_eq(self)) { + return e.getIdx() + } + } + } + pub fn getBasicLitValue(self) -> string { + if (self.isBasicLitExpr()) { + for (l in Literal(__all_data__)) { + if (l.getExpr() = self.id) { + return l.getValue() + } + } + } + } + pub fn getDebugInfo(self) -> string { + for (e in ExprDO(__all_data__)) { + if (e.key_eq(self)) { + return e.getDebugInfo() + } + } + } + pub fn getSignature(self) -> *string { + for (tp in Type(__all_data__)) { + for (auto_tmp1 in tp.getFormatString()) { + for (auto_tmp2 in tp.getExpr()) { + if (auto_tmp2 = self) { + yield auto_tmp1 + } + } + } + } + } + pub fn getKind(self) -> int { + for (e in ExprDO(__all_data__)) { + if (e.key_eq(self)) { + return e.getKind() + } + } + } + pub fn getAChildByIdx(self, idx : int) -> *Node { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + if (idx = e.getIdx()) { + yield Node(__all_data__).find(e) + } + } + } + } + pub fn getBelongsStmt(self) -> Statement { + for (s in Statement(__all_data__)) { + if (s.key_eq(self.getParentNode())) { + return s + } + for (n in Node(__all_data__), + e in Expr(__all_data__)) { + if (n = self.getParentNode()) { + if (e.key_eq(n)) { + if (s = e.getBelongsStmt()) { + return s + } + } + } + } + } + } + // Check if the expression is a control expression. + // Any of ['||', '&&'] + pub fn isControlExpr(self) -> bool { + for (e in Expr(__all_data__)) { + if (e = self) { + if (e.isLorExpr()) { + return true + } + if (e.isLandExpr()) { + return true + } + } + } + } + // Check if the expression is a binary expression. + // Any of ['||', '&&', '==', '!=', '<', '<=', '>', '+', '-', '|', '^', '*', '/', '%', '<<', '>>', '&', '&^' ] + pub fn isBinaryExpr(self) -> bool { + if (self.isLorExpr()) { + return true + } + if (self.isLandExpr()) { + return true + } + if (self.isEqlExpr()) { + return true + } + if (self.isNeqExpr()) { + return true + } + if (self.isLssExpr()) { + return true + } + if (self.isLeqExpr()) { + return true + } + if (self.isGtrExpr()) { + return true + } + if (self.isAddExpr()) { + return true + } + if (self.isSubExpr()) { + return true + } + if (self.isOrExpr()) { + return true + } + if (self.isXorExpr()) { + return true + } + if (self.isMulExpr()) { + return true + } + if (self.isQuoExpr()) { + return true + } + if (self.isRemExpr()) { + return true + } + if (self.isShlExpr()) { + return true + } + if (self.isShrExpr()) { + return true + } + if (self.isAndExpr()) { + return true + } + if (self.isAndnotExpr()) { + return true + } + } + // Check if the given expression is a unary expression. + // Any of ['+','-','!','^','*','&','->' ] + pub fn isUnaryExpr(self) -> bool { + if (self.isPlusExpr()) { + return true + } + if (self.isMinusExpr()) { + return true + } + if (self.isNotExpr()) { + return true + } + if (self.isComplementExpr()) { + return true + } + if (self.isDerefExpr()) { + return true + } + if (self.isAddressExpr()) { + return true + } + if (self.isArrowExpr()) { + return true + } + } + pub fn isBasicLitExpr(self) -> bool { + if (self.isIntLit()) { + return true + } + if (self.isFloatLit()) { + return true + } + if (self.isImagLit()) { + return true + } + if (self.isCharLit()) { + return true + } + if (self.isStringLit()) { + return true + } + } + pub fn getExprTypeName(self) -> *string { + for (to in TypeOfDO(__all_data__), + t in Type(__all_data__)) { + if (to.getExpr() = self.id) { + if (t.oid = to.getTp()) { + yield t.getFormatString() + } + } + } + } + + pub fn getType(self) -> string { + if (self.isBadExpr()) { + return "BadExpr" + } + if (self.isIdent()) { + return "Ident" + } + if (self.isEllipsis()) { + return "Ellipsis" + } + if (self.isIntLit()) { + return "IntLit" + } + if (self.isFloatLit()) { + return "FloatLit" + } + if (self.isImagLit()) { + return "ImagLit" + } + if (self.isCharLit()) { + return "CharLit" + } + if (self.isStringLit()) { + return "StringLit" + } + if (self.isFuncLit()) { + return "FuncLit" + } + if (self.isCompositeLit()) { + return "CompositeLit" + } + if (self.isParenExpr()) { + return "ParenExpr" + } + if (self.isSelectorExpr()) { + return "SelectorExpr" + } + if (self.isIndexExpr()) { + return "IndexExpr" + } + if (self.isGenericfunctioninstantiationExpr()) { + return "GenericfunctioninstantiationExpr" + } + if (self.isGenerictypeinstantiationExpr()) { + return "GenerictypeinstantiationExpr" + } + if (self.isSliceExpr()) { + return "SliceExpr" + } + if (self.isTypeassertExpr()) { + return "TypeassertExpr" + } + if (self.isCallorconversionExpr()) { + return "CallorconversionExpr" + } + if (self.isStarExpr()) { + return "StarExpr" + } + if (self.isKeyvalueExpr()) { + return"KeyvalueExpr" + } + if (self.isArraytypeExpr()) { + return"ArraytypeExpr" + } + if (self.isStructtypeExpr()) { + return "StructtypeExpr" + } + if (self.isFunctypeExpr()) { + return "FunctypeExpr" + } + if (self.isInterfacetypeExpr()) { + return "InterfacetypeExpr" + } + if (self.isMaptypeExpr()) { + return "MaptypeExpr" + } + if (self.isTypesetliteralExpr()) { + return "TypesetliteralExpr" + } + if (self.isPlusExpr()) { + return "PlusExpr" + } + if (self.isMinusExpr()) { + return "MinusExpr" + } + if (self.isNotExpr()) { + return "NotExpr" + } + if (self.isComplementExpr()) { + return "ComplementExpr" + } + if (self.isDerefExpr()) { + return "DerefExpr" + } + if (self.isAddressExpr()) { + return "AddressExpr" + } + if (self.isArrowExpr()) { + return "ArrowExpr" + } + if (self.isLorExpr()) { + return "LorExpr" + } + if (self.isLandExpr()) { + return "LandExpr" + } + if (self.isEqlExpr()) { + return "EqlExpr" + } + if (self.isNeqExpr()) { + return "NeqExpr" + } + if (self.isLssExpr()) { + return "LssExpr" + } + if (self.isLeqExpr()) { + return "LeqExpr" + } + if (self.isGtrExpr()) { + return "GtrExpr" + } + if (self.isGeqExpr()) { + return "GeqExpr" + } + if (self.isAddExpr()) { + return "AddExpr" + } + if (self.isSubExpr()) { + return "SubExpr" + } + if (self.isOrExpr()) { + return "OrExpr" + } + if (self.isXorExpr()) { + return "XorExpr" + } + if (self.isMulExpr()) { + return "MulExpr" + } + if (self.isQuoExpr()) { + return "QuoExpr" + } + if (self.isRemExpr()) { + return "RemExpr" + } + if (self.isShlExpr()) { + return "ShlExpr" + } + if (self.isShrExpr()) { + return "ShrExpr" + } + if (self.isAndExpr()) { + return "AndExpr" + } + if (self.isAndnotExpr()) { + return "AndnotExpr" + } + if (self.isSendchantypeExpr()) { + return "SendchantypeExpr" + } + if (self.isRecvchantypeExpr()) { + return "RecvchantypeExpr" + } + if (self.isSendrcvchantypeExpr()) { + return "SendrcvchantypeExpr" + } + } + + pub fn isBadExpr(self) -> bool { + if (self.getKind() = 0) { + return true + } + } + pub fn isIdent(self) -> bool { + if (self.getKind() = 1) { + return true + } + } + pub fn isEllipsis(self) -> bool { + if (self.getKind() = 2) { + return true + } + } + pub fn isIntLit(self) -> bool { + if (self.getKind() = 3) { + return true + } + } + pub fn isFloatLit(self) -> bool { + if (self.getKind() = 4) { + return true + } + } + pub fn isImagLit(self) -> bool { + if (self.getKind() = 5) { + return true + } + } + pub fn isCharLit(self) -> bool { + if (self.getKind() = 6) { + return true + } + } + pub fn isStringLit(self) -> bool { + if (self.getKind() = 7) { + return true + } + } + pub fn isFuncLit(self) -> bool { + if (self.getKind() = 8) { + return true + } + } + pub fn isCompositeLit(self) -> bool { + if (self.getKind() = 9) { + return true + } + } + pub fn isParenExpr(self) -> bool { + if (self.getKind() = 10) { + return true + } + } + pub fn isSelectorExpr(self) -> bool { + if (self.getKind() = 11) { + return true + } + } + pub fn isIndexExpr(self) -> bool { + if (self.getKind() = 12) { + return true + } + } + pub fn isGenericfunctioninstantiationExpr(self) -> bool { + if (self.getKind() = 13) { + return true + } + } + pub fn isGenerictypeinstantiationExpr(self) -> bool { + if (self.getKind() = 14) { + return true + } + } + pub fn isSliceExpr(self) -> bool { + if (self.getKind() = 15) { + return true + } + } + pub fn isTypeassertExpr(self) -> bool { + if (self.getKind() = 16) { + return true + } + } + pub fn isCallorconversionExpr(self) -> bool { + if (self.getKind() = 17) { + return true + } + } + pub fn isStarExpr(self) -> bool { + if (self.getKind() = 18) { + return true + } + } + pub fn isKeyvalueExpr(self) -> bool { + if (self.getKind() = 19) { + return true + } + } + pub fn isArraytypeExpr(self) -> bool { + if (self.getKind() = 20) { + return true + } + } + pub fn isStructtypeExpr(self) -> bool { + if (self.getKind() = 21) { + return true + } + } + pub fn isFunctypeExpr(self) -> bool { + if (self.getKind() = 22) { + return true + } + } + pub fn isInterfacetypeExpr(self) -> bool { + if (self.getKind() = 23) { + return true + } + } + pub fn isMaptypeExpr(self) -> bool { + if (self.getKind() = 24) { + return true + } + } + pub fn isTypesetliteralExpr(self) -> bool { + if (self.getKind() = 25) { + return true + } + } + pub fn isPlusExpr(self) -> bool { + if (self.getKind() = 26) { + return true + } + } + pub fn isMinusExpr(self) -> bool { + if (self.getKind() = 27) { + return true + } + } + pub fn isNotExpr(self) -> bool { + if (self.getKind() = 28) { + return true + } + } + pub fn isComplementExpr(self) -> bool { + if (self.getKind() = 29) { + return true + } + } + pub fn isDerefExpr(self) -> bool { + if (self.getKind() = 30) { + return true + } + } + pub fn isAddressExpr(self) -> bool { + if (self.getKind() = 31) { + return true + } + } + pub fn isArrowExpr(self) -> bool { + if (self.getKind() = 32) { + return true + } + } + pub fn isLorExpr(self) -> bool { + if (self.getKind() = 33) { + return true + } + } + pub fn isLandExpr(self) -> bool { + if (self.getKind() = 34) { + return true + } + } + pub fn isEqlExpr(self) -> bool { + if (self.getKind() = 35) { + return true + } + } + pub fn isNeqExpr(self) -> bool { + if (self.getKind() = 36) { + return true + } + } + pub fn isLssExpr(self) -> bool { + if (self.getKind() = 37) { + return true + } + } + pub fn isLeqExpr(self) -> bool { + if (self.getKind() = 38) { + return true + } + } + pub fn isGtrExpr(self) -> bool { + if (self.getKind() = 39) { + return true + } + } + pub fn isGeqExpr(self) -> bool { + if (self.getKind() = 40) { + return true + } + } + pub fn isAddExpr(self) -> bool { + if (self.getKind() = 41) { + return true + } + } + pub fn isSubExpr(self) -> bool { + if (self.getKind() = 42) { + return true + } + } + pub fn isOrExpr(self) -> bool { + if (self.getKind() = 43) { + return true + } + } + pub fn isXorExpr(self) -> bool { + if (self.getKind() = 44) { + return true + } + } + pub fn isMulExpr(self) -> bool { + if (self.getKind() = 45) { + return true + } + } + pub fn isQuoExpr(self) -> bool { + if (self.getKind() = 46) { + return true + } + } + pub fn isRemExpr(self) -> bool { + if (self.getKind() = 47) { + return true + } + } + pub fn isShlExpr(self) -> bool { + if (self.getKind() = 48) { + return true + } + } + pub fn isShrExpr(self) -> bool { + if (self.getKind() = 49) { + return true + } + } + pub fn isAndExpr(self) -> bool { + if (self.getKind() = 50) { + return true + } + } + pub fn isAndnotExpr(self) -> bool { + if (self.getKind() = 51) { + return true + } + } + pub fn isSendchantypeExpr(self) -> bool { + if (self.getKind() = 52) { + return true + } + } + pub fn isRecvchantypeExpr(self) -> bool { + if (self.getKind() = 53) { + return true + } + } + pub fn isSendrcvchantypeExpr(self) -> bool { + if (self.getKind() = 54) { + return true + } + } +} diff --git a/language/go/lib/Fields.gdl b/language/go/lib/Fields.gdl new file mode 100644 index 00000000..35972257 --- /dev/null +++ b/language/go/lib/Fields.gdl @@ -0,0 +1,103 @@ +schema Fields extends Node { + +} +impl Fields { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Fields { + for (f in FieldsDO(db)) { + yield Fields { + id : f.oid + } + } + } + pub fn getIdx(self) -> int { + for (f in FieldsDO(__all_data__)) { + if (f.key_eq(self)) { + return f.getIdx() + } + } + } + pub fn getKind(self) -> int { + for (f in FieldsDO(__all_data__)) { + if (f.key_eq(self)) { + return f.getKind() + } + } + } + pub fn getType(self) -> string { + if (self.isStructFields()) { + return "StructFields" + } + if (self.isFuncParamsFields()) { + return "FuncParamsFields" + } + if (self.isFuncResultsFields()) { + return "FuncResultsFields" + } + if (self.isInterfaceMethodFields()) { + return "InterfaceMethodFields" + } + if (self.isFuncDeclRecvFields()) { + return "FuncDeclRecvFields" + } + } + pub fn isStructFields(self) -> bool { + if (self.getKind() = 0) { + return true + } + } + pub fn isFuncParamsFields(self) -> bool { + if (self.getKind() = 1) { + return true + } + } + pub fn isFuncResultsFields(self) -> bool { + if (self.getKind() = 2) { + return true + } + } + pub fn isInterfaceMethodFields(self) -> bool { + if (self.getKind() = 3) { + return true + } + } + pub fn isFuncDeclRecvFields(self) -> bool { + if (self.getKind() = 4) { + return true + } + } + pub fn getFieldName(self) -> *string { + for (e in Expr(__all_data__), + l in LiteralDO(__all_data__)) { + let (id = e.id) { + if (e.getIdx() > 0) { + if (e.getParentNode().key_eq(self)) { + if (l.getExpr() = id) { + yield l.getValue() + } + } + } + } + } + } + pub fn getFieldType(self) -> *string { + for (e in Expr(__all_data__)) { + if (e.getIdx() = 0) { + if (e.getParentNode().key_eq(self)) { + yield e.getExprTypeName() + } + } + } + } + + pub fn makeFieldStringForFunctionSignature(self) -> *string { + for (auto_tmp1 in self.getFieldName()) { + for (auto_tmp2 in self.getFieldType()) { // has both Name:Type + yield auto_tmp1 + " " + auto_tmp2 + } + } + yield self.getFieldName() // has only Name + yield self.getFieldType() // has only Type + } +} diff --git a/language/go/lib/File.gdl b/language/go/lib/File.gdl new file mode 100644 index 00000000..b14dd6a8 --- /dev/null +++ b/language/go/lib/File.gdl @@ -0,0 +1,184 @@ +schema File extends Node { + +} +impl File { + @data_constraint + @inline + fn __all__(db: GoDB) -> *File { + for (f in FileDO(db)) { + yield File { + id : f.oid + } + } + } + fn getFunction(self) -> *Function { + for(function in Function(__all_data__)) { + if (self = function.getBelongsFile()) { + yield function + } + } + } + pub fn getName(self) -> string { + for (f in FileDO(__all_data__)) { + if (f.key_eq(self)) { + return f.getName() + } + } + } + pub fn getMd5Sum(self) -> string { + for (f in FileDO(__all_data__)) { + if (f.key_eq(self)) { + return f.getMd5Sum() + } + } + } + pub fn getBelongsPkg(self) -> Pkg { + for (pkg in Pkg(__all_data__), + f in FileDO(__all_data__)) { + if (f.key_eq(self)) { + if (f.getPkgOid() = pkg.oid) { + return pkg + } + } + } + } + pub fn getSha256Sum(self) -> string { + for (f in FileDO(__all_data__)) { + if (f.key_eq(self)) { + return f.getSha256Sum() + } + } + } + pub fn getLineInfo(self) -> NumberOfLineDO { + for (n in NumberOfLineDO(__all_data__)) { + if (n.key_eq(self)) { + return n + } + } + } + pub fn getPkgName(self) -> string { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + if (e.getIdx() = 0) { + for (auto_tmp1 in e.print()) { + return auto_tmp1 + } + } + } + } + } + pub fn getPkgLoc(self) -> Location { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + if (e.getIdx() = 0) { + let (l = e.getLocation()) { + return l + } + } + } + } + } + pub fn isTestFile(self) -> bool { + let (fname = self.getName()) { + if (fname.matches("^.*(_test.go)$")) { + return true + } + } + } + pub fn isGoFile(self) -> bool { + let (fname = self.getName()) { + if (fname.matches("^.*(.go)$")) { + return true + } + } + } + pub fn isModFile(self) -> bool { + let (fname = self.getName()) { + if (fname.matches("^.*(.mod)$")) { + return true + } + } + } + /** + * 获取每个文件包含的函数 + */ + pub fn getFunctionCount(self) -> int { + return self.getFunction().len() + } +} +schema GoFile extends File { + +} +impl GoFile { + @data_constraint + @inline + fn __all__(db: GoDB) -> *GoFile { + for (f in File(db)) { + if (f.isGoFile()) { + yield GoFile { + id : f.id + } + } + } + } + // filterByKeyWords + pub fn filterByKeyWords(self) -> bool { + for (c in Comment(__all_data__)) { + for (auto_tmp1 in c.print()) { + for (k in KEYWORDS_set()) { + if (auto_tmp1.contains(k)) { + if (self.key_eq(c.getBelongsFile())) { + return true + } + } + } + } + } + } + // filterByFolderNames + pub fn filterByFolderNames(self) -> bool { + for (m in string::__undetermined_all__()) { + let (n = self.getName()) { + if (FOLDERNAMES(m)) { + if (n.contains(m)) { + return true + } + } + } + } + } + pub fn isAutoGenereatedFile(self) -> bool { + if (self.filterByFolderNames()) { + return true + } + if (self.filterByKeyWords()) { + return true + } + } +} +//过滤用关键字,可修改 +// gormer, stringer, protoc-gen-go-grpc, protoc-gen-go, goyacc, goctl, generator +// {"Code generated by gormer"}, +// {"Code generated by \"stringer"}, // stringer, Gormer +// {"Code generated by protoc-gen-go-grpc."}, //protoc-gen-go-grpc +// {"Code generated by protoc-gen-go. DO NOT EDIT."}, //protoc-gen-go +// {"Code generated by generator"}, // +// {"Code generated by goyacc"} +// ... +fn KEYWORDS(k: string) -> bool { + [ + {"PLEASE DO NOT MODIFY THIS FILE MANUALLY"}, + {"DO NOT EDIT"}, + {"Code generated by"}, + ] +} +//过滤用文件夹名,可修改 +fn FOLDERNAMES(n: string) -> bool { + [{"autogenerated/"},] +} + +fn KEYWORDS_set() -> *string { + yield "PLEASE DO NOT MODIFY THIS FILE MANUALLY" + yield "DO NOT EDIT" + yield "Code generated by" +} diff --git a/language/go/lib/FileData.gdl b/language/go/lib/FileData.gdl new file mode 100644 index 00000000..c63b49ad --- /dev/null +++ b/language/go/lib/FileData.gdl @@ -0,0 +1,24 @@ +schema FileData extends FileDataDO { + +} +impl FileData { + @data_constraint + @inline + fn __all__(db: GoDB) -> *FileData { + for (tmp in FileDataDO(db)) { + yield FileData { + oid : tmp.oid, + file_id : tmp.file_id, + type : tmp.type, + content : tmp.content + } + } + } + pub fn getFile(self) -> File { + for (f in File(__all_data__)) { + if (self.getFileId() = f.id) { + return f + } + } + } +} diff --git a/language/go/lib/ForStmt.gdl b/language/go/lib/ForStmt.gdl new file mode 100644 index 00000000..cb97745e --- /dev/null +++ b/language/go/lib/ForStmt.gdl @@ -0,0 +1,56 @@ +schema ForStmt extends Statement { + +} +impl ForStmt { + @data_constraint + @inline + fn __all__(db: GoDB) -> *ForStmt { + for (tmp in Statement(db)) { + for (s in Statement(db)) { + if (tmp = s) { + if (s.isForStmt()) { + yield ForStmt { + id : tmp.id + } + } + } + } + } + } + pub fn getInitStmt(self) -> Statement { + for (s in Statement(__all_data__)) { + if (s.getParentNode().key_eq(self)) { + if (s.getIdx() = 0) { + return s + } + } + } + } + pub fn getCondExpr(self) -> Expr { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + if (e.getIdx() = 1) { + return e + } + } + } + } + pub fn getPostStmt(self) -> Statement { + for (s in Statement(__all_data__)) { + if (s.getParentNode().key_eq(self)) { + if (s.getIdx() = 2) { + return s + } + } + } + } + pub fn getBodyStmt(self) -> Statement { + for (s in Statement(__all_data__)) { + if (s.getParentNode().key_eq(self)) { + if (s.getIdx() = 3) { + return s + } + } + } + } +} diff --git a/language/go/lib/Function.gdl b/language/go/lib/Function.gdl new file mode 100644 index 00000000..799ee005 --- /dev/null +++ b/language/go/lib/Function.gdl @@ -0,0 +1,275 @@ +schema Function extends Node { + +} +impl Function { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Function { + for (tmp in Node(db)) { + for (d in Decl(db)) { + if (d.key_eq(tmp)) { + if (d.isFuncDecl()) { + yield Function { + id : tmp.id + } + } + } + } + } + } + fn getIsMethodFunctionSet(self) -> *Function { + for(func in Function(__all_data__)) { + if (self = func && func.isMethod()) { + yield func + } + } + } + fn getMethodReceiverNameSet(self) -> *Method { + for (fs in Method(__all_data__)) { + if (self.key_eq(fs)) { + let (s1 = fs.getMethodReceiverName()) { + yield fs + } + } + } + } + fn getMethodReceiverTypeSet(self) -> *Method { + for (fs in Method(__all_data__)) { + if (self.key_eq(fs)) { + let (s1 = fs.getMethodReceiverType()) { + yield fs + } + } + } + } + fn getControlStatementSet(self) -> *Statement { + for (s in Statement(__all_data__)) { + if (s.isControlStmt() && s.getBelongsFunction() = self) { + yield s + } + } + } + fn getControlExpressionSet(self) -> *Expr { + for (e in Expr(__all_data__)) { + if (e.isControlExpr() && e.getBelongsFunction() = self) { + yield e + } + } + } + pub fn getParamsField(self) -> *string { + for (e in Expr(__all_data__), + f in Fields(__all_data__)) { + if (self.key_eq(e.getParentNode())) { + if (e.key_eq(f.getParentNode())) { + if (f.isFuncParamsFields()) { + for (auto_tmp1 in f.makeFieldStringForFunctionSignature()) { + yield auto_tmp1 + } + } + } + } + } + } + pub fn getResultsField(self) -> *string { + for (e in Expr(__all_data__), + f in Fields(__all_data__)) { + if (self.key_eq(e.getParentNode())) { + if (e.key_eq(f.getParentNode())) { + if (f.isFuncResultsFields()) { + for (auto_tmp1 in f.makeFieldStringForFunctionSignature()) { + yield auto_tmp1 + } + } + } + } + } + } + pub fn getName(self) -> string { + for (e in Expr(__all_data__), + l in LiteralDO(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + if (l.getExpr() = e.id) { + if (e.isIdent()) { + return l.getValue() + } + } + } + } + } + pub fn getFunctionSignature(self) -> string { + for (e in Expr(__all_data__), + to in TypeOfDO(__all_data__), + t in Type(__all_data__)) { + if (self.key_eq(e.getParentNode())) { + if (to.getExpr() = e.id) { + if (t.oid = to.getTp()) { + if (t.isSignatureType()) { + for (auto_tmp1 in t.getFormatString()) { + return auto_tmp1 + } + } + } + } + } + } + } + pub fn isCommented(self) -> bool { + if (self.countAssociatedComment() > 0) { + return true + } + } + pub fn getAssociatedComment(self) -> string { + for (dc in DocComment(__all_data__)) { + if (self.key_eq(dc.getAssociateObj())) { + let (cmt = dc.getCommentGroup().getText()) { + return cmt + } + } + } + } + pub fn getCommentCnt(self) -> int { + return self.countAssociatedComment() + } + pub fn isPublicFunction(self) -> bool { + if (self.getName().matches("^[A-Z].*")) { + return true + } + } + pub fn isMethod(self) -> bool { + for (f in Fields(__all_data__)) { + if (self.key_eq(f.getParentNode())) { + if (f.isFuncDeclRecvFields()) { + return true + } + } + } + } + pub fn getAParameter(self) -> *Node { + for (f in Fields(__all_data__), + tp in Expr(__all_data__)) { + if (tp.getParentNode().key_eq(self)) { + if (f.getParentNode().key_eq(tp)) { + if (f.isFuncParamsFields()) { + yield Node{id: f.id} + } + } + } + } + } + pub fn getAResult(self) -> *Node { + for (f in Fields(__all_data__), + tp in Expr(__all_data__)) { + if (tp.getParentNode().key_eq(self)) { + if (f.getParentNode().key_eq(tp)) { + if (f.isFuncResultsFields()) { + yield Node{id: f.id} + } + } + } + } + } + pub fn getGlobalSignature(self) -> string { + let (pkg = self.getBelongsFile().getBelongsPkg()) { + let (a1 = pkg.getPath()) { + let (a2 = pkg.getName()) { + let (s1 = a1 + "." + a2) { + let (s2 = self.getFunctionTypeSignature()) { + let (s = s1 + "|" + s2) { + return s + } + } + } + } + } + } + } + pub fn getFunctionFullSignature(self) -> string { + for (e in Expr(__all_data__), to in TypeOfDO(__all_data__), t in Type(__all_data__)) { + if (self.key_eq(e.getParentNode()) && to.getExpr() = e.id && t.oid = to.getTp() && t.isSignatureType()) { + let (cnt = self.getIsMethodFunctionSet().len()) { + if (cnt > 0) { + for(func in Function(__all_data__)) { + if (self = func) { + let (s1 = func.getFunctionReceiverInfo()) { + for (ss in t.getRawString()) { + return s1 + ss + } + } + } + } + } + if (cnt <= 0) { + for (ss in t.getRawString()) { + return ss + } + } + } + } + } + } + pub fn getFunctionReceiverInfo(self) -> string { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + let (cnt1 = self.getMethodReceiverNameSet().len(), cnt2 = self.getMethodReceiverTypeSet().len()) { + if (cnt1 > 0) { + let (t1 = m.getMethodReceiverName()) { + if (cnt2 > 0) { + return "(" + t1 + " " + m.getMethodReceiverType() + ")" + } + if (cnt2 <= 0) { + return "(" + t1 + ")" + } + } + } + if (cnt1 <= 0) { + if (cnt2 > 0) { + return "(" + m.getMethodReceiverType() + ")" + } + if (cnt2 <= 0) { + return "nill" + } + } + } + } + } + } + pub fn getFunctionReceiverType(self) -> string { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + let (cnt2 = self.getMethodReceiverTypeSet().len()) { + if (cnt2 > 0) { + return "(" + m.getMethodReceiverType() + ")" + } + if (cnt2 <= 0) { + return "nill" + } + } + } + } + } + + pub fn getCyclomaticComplexity(self) -> int { + let (ctrlStmt = self.getControlStatementSet().len(), + ctrlExpr = self.getControlExpressionSet().len()) { + return ctrlStmt + ctrlExpr + 1 + } + } + pub fn getFunctionTypeSignature(self) -> string { + for (e in Expr(__all_data__), to in TypeOfDO(__all_data__), t in Type(__all_data__)) { + if (self.key_eq(e.getParentNode()) && to.getExpr() = e.id && t.oid = to.getTp() && t.isSignatureType()) { + let (cnt = self.getIsMethodFunctionSet().len()) { + if (cnt > 0) { + for (ss in t.getFormatString()) { + return self.getFunctionReceiverType() + " " + ss + } + } + if (cnt <= 0) { + for (ss in t.getFormatString()) { + return ss + } + } + } + } + } + } +} diff --git a/language/go/lib/Location.gdl b/language/go/lib/Location.gdl new file mode 100644 index 00000000..6c99be72 --- /dev/null +++ b/language/go/lib/Location.gdl @@ -0,0 +1,20 @@ +schema Location extends LocationDO { + +} +impl Location { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Location { + for (tmp in LocationDO(db)) { + yield Location { + oid : tmp.oid, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number, + token_start_offset : tmp.token_start_offset, + token_end_offset : tmp.token_end_offset + } + } + } +} diff --git a/language/go/lib/Method.gdl b/language/go/lib/Method.gdl new file mode 100644 index 00000000..fa3fe3b9 --- /dev/null +++ b/language/go/lib/Method.gdl @@ -0,0 +1,59 @@ +schema Method extends Function { + +} +impl Method { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Method { + for (f in Function(db)) { + if (f.isMethod()) { + yield Method { + id : f.id + } + } + } + } + pub fn getIdx(self) -> int { + for (e in ExprDO(__all_data__)) { + if (e.key_eq(self)) { + return e.getIdx() + } + } + } + pub fn getMethodReceiverName(self) -> string { + for (f in Fields(__all_data__), + e in Expr(__all_data__), + l in LiteralDO(__all_data__)) { + if (self.key_eq(f.getParentNode())) { + if (f.key_eq(e.getParentNode())) { + let (idx = e.getIdx()) { + if (l.getExpr() = e.id) { + let (r = l.getValue()) { + if (idx > 0) { + return r + } + } + } + } + } + } + } + } + + pub fn getMethodReceiverType(self) -> string { + for (f in Fields(__all_data__), + e in Expr(__all_data__)) { + if (self.key_eq(f.getParentNode())) { + if (f.key_eq(e.getParentNode())) { + for (auto_tmp1 in e.getExprTypeName()) { + let (idx = e.getIdx()) { + if (idx = 0) { + return auto_tmp1 + } + } + } + } + } + } + } +} diff --git a/language/go/lib/Mod.gdl b/language/go/lib/Mod.gdl new file mode 100644 index 00000000..0789aa02 --- /dev/null +++ b/language/go/lib/Mod.gdl @@ -0,0 +1,29 @@ +schema Mod extends ModFileDO { + +} +impl Mod { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Mod { + for (tmp in ModFileDO(db)) { + yield Mod { + oid : tmp.oid, + path : tmp.path, + name : tmp.name, + go_version : tmp.go_version + } + } + } + pub fn getARequire(self) -> string { + for (mr in ModRequireDO(__all_data__)) { + if (mr.getModId() = self.oid) { + return mr.getRequire() + } + } + } + pub fn getModDepsCount(self) -> int { + let (tmp = self.getARequire().len()) { + return tmp + } + } +} diff --git a/language/go/lib/Node.gdl b/language/go/lib/Node.gdl new file mode 100644 index 00000000..70b08f1c --- /dev/null +++ b/language/go/lib/Node.gdl @@ -0,0 +1,420 @@ +schema Node { + @primary id: int +} +impl Node { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Node { + for (d in DeclDO(db)) { + yield Node {id : d.oid} + } + for (e in ExprDO(db)) { + yield Node {id : e.oid} + } + for (s in StmtDO(db)) { + yield Node {id : s.oid} + } + for (c in CommentGroupDO(db)) { + yield Node {id : c.oid} + } + for (c in FileDO(db)) { + yield Node {id : c.oid} + } + for (c in CommentDO(db)) { + yield Node {id : c.oid} + } + for (c in DocCommentDO(db)) { + yield Node {id : c.oid} + } + for (c in FieldsDO(db)) { + yield Node {id : c.oid} + } + for (c in SpecDO(db)) { + yield Node {id : c.oid} + } + } + fn tmp_countAssociatedComment_getAssociateObj(self) -> *DocCommentDO { + for (tmp in DocCommentDO(__all_data__)) { + if (tmp.getAssociateObj() = self.id) { + yield tmp + } + } + } + pub fn getBelongsFile(self) -> File { + for (f in File(__all_data__)) { + if (f.key_eq(self)) { // root node + return f + } + if (f.key_eq(self.getParentNode())) { + return f + } + } + return self.getParentNode().getBelongsFile() + } + pub fn isRootNode(self) -> bool { + for (f in FileDO(__all_data__)) { + if (self.key_eq(f)) { + return true + } + } + } + pub fn getBelongsFunction(self) -> Function { + for (f in Function(__all_data__)) { + if (f.key_eq(self.getParentNode())) { + return f + } + let (n = self.getParentNode()) { + if (f = n.getBelongsFunction()) { + return f + } + } + } + } + pub fn getType(self) -> string { + for (st in Statement(__all_data__)) { + if (self.key_eq(st)) { + return st.getType() + } + } + for (st in Decl(__all_data__)) { + if (self.key_eq(st)) { + return st.getType() + } + } + for (st in Expr(__all_data__)) { + if (self.key_eq(st)) { + return st.getType() + } + } + for (e in CommentGroupDO(__all_data__)) { + if (self.key_eq(e)) { + return "CommentGroup" + } + } + for (e in FileDO(__all_data__)) { + if (self.key_eq(e)) { + return "File" + } + } + for (c in CommentDO(__all_data__)) { + if (self.key_eq(c)) { + return "Comment" + } + } + for (c in DocCommentDO(__all_data__)) { + if (self.key_eq(c)) { + return "DocComment" + } + } + for (f in Fields(__all_data__)) { + if (self.key_eq(f)) { + return f.getType() + } + } + for (st in Spec(__all_data__)) { + if (self.key_eq(st)) { + return st.getType() + } + } + } + + pub fn getParentNode(self) -> Node { + for (parent in Node(__all_data__)) { + for (e in DeclDO(__all_data__)) { + if (self.key_eq(e)) { + if (parent.id = e.getParentId()) { + return parent + } + } + } + for (var in ExprDO(__all_data__)) { + if (self.key_eq(var)) { + if (parent.id = var.getParentId()) { + return parent + } + } + } + for (m in StmtDO(__all_data__)) { + if (self.key_eq(m)) { + if (parent.id = m.getParentId()) { + return parent + } + } + } + for (c in CommentGroupDO(__all_data__)) { + if (self.key_eq(c)) { + if (parent.id = c.getParent()) { + return parent + } + } + } + // for (f in FileDO(__all_data__)) { + // if (self.key_eq(f)) { + // // 此处为一个假设 + // if (parent.id = -1) { + // return parent + // } + // } + // } + for (c in CommentDO(__all_data__)) { + if (self.key_eq(c)) { + if (parent.id = c.getParent()) { + return parent + } + } + } + for (c in DocCommentDO(__all_data__)) { + if (self.key_eq(c)) { + for (cg in CommentGroupDO(__all_data__)) { + if (cg.oid = c.getAssociateObj()) { + if (parent.id = cg.oid) { + return parent + } + } + } + } + } + for (c in FieldsDO(__all_data__)) { + if (self.key_eq(c)) { + if (parent.id = c.getParentId()) { + return parent + } + } + } + for (c in SpecDO(__all_data__)) { + if (self.key_eq(c)) { + if (parent.id = c.getParentId()) { + return parent + } + } + } + } + } + pub fn getAnAncestor(self) -> *Node { + yield self.getParentNode() + for (auto_tmp1 in self.getAnAncestor()) { + yield auto_tmp1.getParentNode() + } + } + pub fn getAnAncestorForIndex(self, index : int) -> Node { + let (ancestor = self.getParentNode()) { + if (index = 1) { + return ancestor + } + } + for (indexTemp in int::__undetermined_all__()) { + let (temp = self.getParentNode()) { + let (ancestor = temp.getAnAncestorForIndex(indexTemp)) { + if (index = indexTemp + 1) { + return ancestor + } + } + } + } + } + pub fn hasLocation(self) -> bool { + let (loc = self.getLocation()) { + let (sl = loc.getStartLineNumber(), + el = loc.getEndLineNumber()) { + if (el > 0 && sl > 0) { + return true + } + } + } + } + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__), + has in HasLocationDO(__all_data__)) { + if (self.id = has.getLocationObj()) { + if (loc.oid = has.getLocationId()) { + return loc + } + } + } + } + pub fn getAchildNode(self) -> *Node { + for (c in Node(__all_data__)) { + if (self = c.getParentNode()) { + yield c + } + } + } + pub fn getAssociatedCommentString(self) -> string { + for (dc in DocComment(__all_data__)) { + if (self = dc.getAssociateObj()) { + let (cmt = dc.getCommentGroup().getText()) { + return cmt + } + } + } + } + pub fn getDepthFromRoot(self) -> int { + for (f in FileDO(__all_data__)) { + if (f.key_eq(self.getBelongsFile())) { + if (f.key_eq(self)) { + return 0 + } + if (f.key_eq(self.getParentNode())) { + return 1 + } + for (dpTemp in int::__undetermined_all__()) { + let (temp = self.getParentNode()) { + if (dpTemp = temp.getDepthFromRoot()) { + return dpTemp + 1 + } + } + } + } + } + } + pub fn getTextSize(self) -> int { + let (loc = self.getLocation()) { + let (so = loc.getTokenStartOffset(), + eo = loc.getTokenEndOffset()) { + return eo - so + } + } + } + pub fn getTextStartOffset(self) -> int { + return self.getLocation().getTokenStartOffset() + } + pub fn getChildCount(self) -> int { + let (tmp = self.getAchildNode().len()) { + return tmp + } + } + pub fn countAssociatedComment(self) -> int { + let (tmp = self.tmp_countAssociatedComment_getAssociateObj().len()) { + return tmp + } + } + + // getText Extract the text associated with a specific node in a file + pub fn getText(self) -> string { + for (fd in FileData(__all_data__)) { + if (fd.getFile() = self.getBelongsFile()) { + let (so = self.getTextStartOffset()) { + let (len = self.getTextSize()) { + let (content = fd.getContent()) { + if (self.isRootNode()) { + return content + } + if (!self.isRootNode()) { + return content.substr(so, len) + } + } + } + } + } + } + } + + pub fn print(self) -> *string { + for (s in StmtDO(__all_data__)) { + if (self.key_eq(s)) { + yield s.getDebugInfo() + } + } + for (e in Expr(__all_data__)) { + if (self.key_eq(e)) { + if (e.isIdent() || e.isBasicLitExpr()) { + for (l in LiteralDO(__all_data__)) { + if (l.getExpr() = e.id) { + yield l.getValue() + } + } + } + if (e.isSelectorExpr()) { + for (sl in SelectorExpr(__all_data__)) { + if (e.key_eq(sl)) { + for (s1 in sl.getBase().print(), + s2 in sl.getSelector().print()) { + yield s1 + "." + s2 + } + } + } + } + if (!(e.isIdent() || e.isBasicLitExpr() || e.isSelectorExpr())) { + yield e.getDebugInfo() + } + } + } + for (d in DeclDO(__all_data__)) { + if (self.key_eq(d)) { + for (ex in ExprDO(__all_data__)) { + if (ex.getParentId() = self.id) { + if (ex.getKind() = 1) { + for (l in LiteralDO(__all_data__)) { + if (l.getExpr() = ex.oid) { + yield l.getValue() + } + } + } + } + } + } + } + for (e in CommentGroupDO(__all_data__)) { + if (self.key_eq(e)) { + yield "@CommentGroup" + } + } + for (e in FileDO(__all_data__)) { + if (self.key_eq(e)) { + yield e.getName() + } + } + for (c in CommentDO(__all_data__)) { + if (self.key_eq(c)) { + yield c.getDebugInfo() + } + } + for (c in DocCommentDO(__all_data__)) { + if (self.key_eq(c)) { + yield "@DocComment" + } + } + for (fd in Fields(__all_data__)) { + if (self.key_eq(fd)) { + let (cnt1 = fd.getFieldName().len(), + cnt2 = fd.getFieldType().len()) { + if (cnt1 > 0) { + for (t1 in fd.getFieldName()) { + if (cnt2 > 0) { + for (t2 in fd.getFieldType()) { + yield t1 + "[" + t2 + "]" + } + } + if (cnt2 <= 0) { + yield t1 + } + } + } + if (cnt1 <= 0) { + if (cnt2 > 0) { + for (t2 in fd.getFieldType()) { + yield "[" + t2 + "]" + } + } + if (cnt2 <= 0) { + yield "" + } + } + + } + } + } + for (c in SpecDO(__all_data__)) { + if (self.key_eq(c)) { + for (e in ExprDO(__all_data__), + l in LiteralDO(__all_data__)) { + if (e.getParentId() = self.id) { + if (l.getExpr() = e.oid) { + yield l.getValue() + } + } + } + } + } + } +} diff --git a/language/go/lib/Packages.gdl b/language/go/lib/Packages.gdl new file mode 100644 index 00000000..d18b046d --- /dev/null +++ b/language/go/lib/Packages.gdl @@ -0,0 +1,17 @@ +schema Pkg extends PkgDO { + +} +impl Pkg { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Pkg { + for (tmp in PkgDO(db)) { + yield Pkg { + oid : tmp.oid, + path : tmp.path, + name : tmp.name, + scope : tmp.scope + } + } + } +} diff --git a/language/go/lib/Receiver.gdl b/language/go/lib/Receiver.gdl new file mode 100644 index 00000000..33c6adef --- /dev/null +++ b/language/go/lib/Receiver.gdl @@ -0,0 +1,36 @@ +schema Receiver extends Method { + +} +impl Receiver { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Receiver { + for (m in Method(db)) { + yield Receiver { + id : m.id + } + } + } + pub fn isPointerReceiver(self) -> bool { + for (m in Method(__all_data__)) { + if (m.key_eq(self)) { + let (t = m.getMethodReceiverType()) { + if (t.matches("^[*&].*$")) { + return true + } + } + } + } + } + pub fn isValueReceiver(self) -> bool { + for (m in Method(__all_data__)) { + if (m.key_eq(self)) { + let (t = m.getMethodReceiverType()) { + if (t.matches("^[a-zA-Z].*$")) { + return true + } + } + } + } + } +} diff --git a/language/go/lib/ReternStmt.gdl b/language/go/lib/ReternStmt.gdl new file mode 100644 index 00000000..ba1810dd --- /dev/null +++ b/language/go/lib/ReternStmt.gdl @@ -0,0 +1,37 @@ +schema ReturnStmt extends Statement { + +} +impl ReturnStmt { + @data_constraint + @inline + fn __all__(db: GoDB) -> *ReturnStmt { + for (s in Statement(db)) { + if (s.isReturnStmt()) { + yield ReturnStmt { + id : s.id + } + } + } + } + pub fn getAReturnField(self) -> *Node { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + yield Node(__all_data__).find(e) + } + } + } + pub fn getAReturnFieldByIndex(self, index : int) -> *Node { + for (e in Expr(__all_data__)) { + if (e.getIdx() = index) { + if (e.getParentNode().key_eq(self)) { + yield Node(__all_data__).find(e) + } + } + } + } + pub fn getReturnListCount(self) -> int { + let (tmp = self.getAReturnField().len()) { + return tmp + } + } +} diff --git a/language/go/lib/SelectorExpr.gdl b/language/go/lib/SelectorExpr.gdl new file mode 100644 index 00000000..4a1b0eda --- /dev/null +++ b/language/go/lib/SelectorExpr.gdl @@ -0,0 +1,68 @@ +schema Selector extends Expr { + +} +impl Selector { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Selector { + for (tmp in Expr(db)) { + yield Selector { + id : tmp.id + } + } + } + + pub fn getSelectorSignature(self) -> *string { + for (e in Expr(__all_data__), + to in TypeOfDO(__all_data__), + t in Type(__all_data__)) { + if (e.key_eq(self)) { + if (e.id = to.getExpr()) { + if (t.oid = to.getTp()) { + yield t.getFormatString() + } + } + } + } + } +} +schema SelectorExpr extends Expr { + +} +impl SelectorExpr { + @data_constraint + @inline + fn __all__(db: GoDB) -> *SelectorExpr { + for (e in Expr(db)) { + if (e.isSelectorExpr()) { + yield SelectorExpr { + id : e.id + } + } + } + } + pub fn getBase(self) -> Node { + for (n in Node(__all_data__), + e in Expr(__all_data__)) { + if (e.getIdx() = 0) { + if (e.getParentNode().key_eq(self)) { + if (n.key_eq(e)) { + return n + } + } + } + } + } + pub fn getSelector(self) -> Selector { + for (s in Selector(__all_data__), + e in Expr(__all_data__)) { + if (e.getIdx() = 1) { + if (e.getParentNode().key_eq(self)) { + if (s.key_eq(e)) { + return s + } + } + } + } + } +} diff --git a/language/go/lib/SliceExpr.gdl b/language/go/lib/SliceExpr.gdl new file mode 100644 index 00000000..a77388af --- /dev/null +++ b/language/go/lib/SliceExpr.gdl @@ -0,0 +1,64 @@ +schema SliceExpr extends Expr { + +} +impl SliceExpr { + @data_constraint + @inline + fn __all__(db: GoDB) -> *SliceExpr { + for (e in Expr(db)) { + if (e.isSliceExpr()) { + yield SliceExpr { + id : e.id + } + } + } + } + pub fn getBase(self) -> Node { + for (b in Node(__all_data__), + s in SliceExpr(__all_data__)) { + if (s.getParentNode().key_eq(self)) { + if (s.getIdx() = 0) { + if (b.key_eq(s)) { + return b + } + } + } + } + } + pub fn getLow(self) -> Node { + for (b in Node(__all_data__), + s in SliceExpr(__all_data__)) { + if (s.getParentNode().key_eq(self)) { + if (s.getIdx() = 1) { + if (b.key_eq(s)) { + return b + } + } + } + } + } + pub fn getHigh(self) -> Node { + for (b in Node(__all_data__), + s in SliceExpr(__all_data__)) { + if (s.getParentNode().key_eq(self)) { + if (s.getIdx() = 2) { + if (b.key_eq(s)) { + return b + } + } + } + } + } + pub fn getMax(self) -> Node { + for (b in Node(__all_data__), + s in SliceExpr(__all_data__)) { + if (s.getParentNode().key_eq(self)) { + if (s.getIdx() = 3) { + if (b.key_eq(s)) { + return b + } + } + } + } + } +} diff --git a/language/go/lib/Spec.gdl b/language/go/lib/Spec.gdl new file mode 100644 index 00000000..0747a528 --- /dev/null +++ b/language/go/lib/Spec.gdl @@ -0,0 +1,278 @@ +schema Spec extends Node { + +} +impl Spec { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Spec { + for (s in SpecDO(db)) { + yield Spec { + id : s.oid + } + } + } + pub fn getKind(self) -> int { + for (s in SpecDO(__all_data__)) { + if (s.key_eq(self)) { + let (k = s.getKind()) { + return k + } + } + } + } + pub fn getIdx(self) -> int { + for (s in SpecDO(__all_data__)) { + if (s.key_eq(self)) { + let (k = s.getIdx()) { + return k + } + } + } + } + + pub fn getType(self) -> string { + if (self.isImportSpec()) { + return "ImportSpec" + } + if (self.isValueSpec()) { + return "ValueSpec" + } + if (self.isTypedefSpec()) { + return "TypedefSpec" + } + if (self.isAliasSpec()) { + return "AliasSpec" + } + } + pub fn isImportSpec(self) -> bool { + if (self.getKind() = 0) { + return true + } + } + pub fn isValueSpec(self) -> bool { + if (self.getKind() = 1) { + return true + } + } + pub fn isTypedefSpec(self) -> bool { + if (self.getKind() = 2) { + return true + } + } + pub fn isAliasSpec(self) -> bool { + if (self.getKind() = 3) { + return true + } + } + pub fn getAssociatedGenDecl(self) -> Node { + let (tmp = self.getParentNode()) { + for (d in Decl(__all_data__)) { + if (d.key_eq(tmp)) { + return tmp + } + } + } + } +} +schema ImportSpec extends Spec { + +} +impl ImportSpec { + @data_constraint + @inline + fn __all__(db: GoDB) -> *ImportSpec { + for (s in Spec(db)) { + if (s.isImportSpec()) { + yield ImportSpec { + id : s.id + } + } + } + } + pub fn getImportSpecName(self) -> string { + for (e in Expr(__all_data__)) { + if (e.getIdx() = 0) { + if (e.getParentNode().key_eq(self)) { + for (auto_tmp1 in e.print()) { + return auto_tmp1 + } + } + } + } + } + pub fn getImportSpecPath(self) -> string { + for (e in Expr(__all_data__)) { + if (e.getIdx() = 1) { + if (e.getParentNode().key_eq(self)) { + for (auto_tmp1 in e.print()) { + return auto_tmp1 + } + } + } + } + } +} +schema TypeSpec extends Spec { + +} +impl TypeSpec { + @data_constraint + @inline + fn __all__(db: GoDB) -> *TypeSpec { + for (s in Spec(db)) { + if (s.isTypedefSpec()) { + yield TypeSpec { + id : s.id + } + } + } + } + pub fn getTypeSpecName(self) -> string { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + if (e.getIdx() = 0) { + for (auto_tmp1 in e.print()) { + return auto_tmp1 + } + } + } + } + } +} +schema ValueSpec extends Spec { + +} +impl ValueSpec { + @data_constraint + @inline + fn __all__(db: GoDB) -> *ValueSpec { + for (s in Spec(db)) { + if (s.isValueSpec()) { + yield ValueSpec { + id : s.id + } + } + } + } + pub fn getAValueSpecName(self) -> *string { + for (e in Expr(__all_data__)) { + if (e.getIdx() < 0) { + if (e.getParentNode().key_eq(self)) { + for (auto_tmp1 in e.print()) { + yield auto_tmp1 + } + } + } + } + } + pub fn getAValueSpecNameByIdx(self, id : int) -> *string { + for (e in Expr(__all_data__)) { + let (idx = e.getIdx()) { + if (idx < 0 && id = idx) { + if (e.getParentNode().key_eq(self)) { + for (auto_tmp1 in e.print()) { + yield auto_tmp1 + } + } + } + } + } + } + pub fn getSignature(self) -> *string { + for (e in Expr(__all_data__), + to in TypeOfDO(__all_data__), + t in Type(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + let (idx = e.getIdx()) { + if (idx < 0) { + if (to.getExpr() = e.id) { + if (t.oid = to.getTp()) { + for (auto_tmp1 in t.getFormatString()) { + yield auto_tmp1 + } + } + } + } + } + } + } + } + pub fn hasUserInitValue(self) -> bool { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + let (idx = e.getIdx()) { + if (idx > 0) { + return true + } + } + } + } + } + pub fn getAValueByIdx(self, id : int) -> *string { + for (e in Expr(__all_data__)) { + let (idx = e.getIdx()) { + if (idx > 0 && id = idx) { + if (e.getParentNode().key_eq(self)) { + for (auto_tmp1 in e.print()) { + yield auto_tmp1 + } + } + } + } + } + } + pub fn getAValueNodeByIdx(self, id : int) -> *Node { + for (e in Expr(__all_data__)) { + let (idx = e.getIdx()) { + if (idx > 0 && idx = id) { + if (e.getParentNode().key_eq(self)) { + yield Node{id: e.id} + } + } + } + } + } +} +schema LocalVaribleDecl extends Decl { + +} +impl LocalVaribleDecl { + @data_constraint + @inline + fn __all__(db: GoDB) -> *LocalVaribleDecl { + for (d in Decl(db)) { + if (d.isLocalVaribleDecl()) { + yield LocalVaribleDecl { + id : d.id + } + } + } + } + pub fn getName(self) -> *string { + for (ts in TypeSpec(__all_data__)) { + if (ts.getAssociatedGenDecl().key_eq(self)) { + yield ts.getTypeSpecName() + } + } + for (vs in ValueSpec(__all_data__)) { + if (vs.getAssociatedGenDecl().key_eq(self)) { + yield vs.getAValueSpecName() + } + } + } + pub fn isPublicDecl(self) -> bool { + if (self.isConstDecl()) { + return true + } + for (auto_tmp1 in self.getName()) { + if (auto_tmp1.matches("^[A-Z].*")) { + return true + } + } + } + pub fn isCommented(self) -> bool { + if (self.countAssociatedComment() > 0) { + return true + } + } +} diff --git a/language/go/lib/Statement.gdl b/language/go/lib/Statement.gdl new file mode 100644 index 00000000..2a02ec54 --- /dev/null +++ b/language/go/lib/Statement.gdl @@ -0,0 +1,358 @@ +schema Statement extends Node { + +} +impl Statement { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Statement { + for (tmp in Node(db)) { + for (s in StmtDO(db)) { + if (tmp.key_eq(s)) { + yield Statement { + id : tmp.id + } + } + } + } + } + pub fn getKind(self) -> int { + for (s in StmtDO(__all_data__)) { + if (s.key_eq(self)) { + return s.getKind() + } + } + } + pub fn getIdx(self) -> int { + for (s in StmtDO(__all_data__)) { + if (s.key_eq(self)) { + return s.getIdx() + } + } + } + pub fn getBelongsFunction(self) -> Function { + for (f in Function(__all_data__)) { + if (f.key_eq(self.getParentNode())) { + return f + } + } + for (s in Statement(__all_data__)) { + if (s.key_eq(self.getParentNode())) { + let (f = s.getBelongsFunction()) { + return f + } + } + } + } + + pub fn getType(self) -> string { + if (self.isBadStmt()) { + return "BadStmt" + } + if (self.isDeclStmt()) { + return "DeclStmt" + } + if (self.isEmptyStmt()) { + return "EmptyStmt" + } + if (self.isLabeledStmt()) { + return "LabeledStmt" + } + if (self.isExprStmt()) { + return "ExprStmt" + } + if (self.isSendStmt()) { + return "SendStmt" + } + if (self.isIncStmt()) { + return "IncStmt" + } + if (self.isDecStmt()) { + return "DecStmt" + } + if (self.isGoStmt()) { + return "GoStmt" + } + if (self.isDeferStmt()) { + return "DeferStmt" + } + if (self.isReturnStmt()) { + return "ReturnStmt" + } + if (self.isBreakStmt()) { + return "BreakStmt" + } + if (self.isContinueStmt()) { + return "ContinueStmt" + } + if (self.isGotoStmt()) { + return "GotoStmt" + } + if (self.isFallthroughStmt()) { + return "FallthroughStmt" + } + if (self.isBlockStmt()) { + return "BlockStmt" + } + if (self.isIfStmt()) { + return "IfStmt" + } + if (self.isCaseClause()) { + return "CaseClause" + } + if (self.isExprswitchStmt()) { + return "ExprswitchStmt" + } + if (self.isTypeswitchStmt()) { + return "TypeswitchStmt" + } + if (self.isCommClause()) { + return "CommClause" + } + if (self.isSelectStmt()) { + return "SelectStmt" + } + if (self.isForStmt()) { + return "ForStmt" + } + if (self.isRangeStmt()) { + return "RangeStmt" + } + if (self.isAssignStmt()) { + return "AssignStmt" + } + if (self.isDefineStmt()) { + return "DefineStmt" + } + if (self.isAddassignStmt()) { + return "AddassignStmt" + } + if (self.isSubassignStmt()) { + return "SubassignStmt" + } + if (self.isMulassignStmt()) { + return "MulassignStmt" + } + if (self.isQuoassignStmt()) { + return "QuoassignStmt" + } + if (self.isRemassignStmt()) { + return "RemassignStmt" + } + if (self.isAndassignStmt()) { + return "AndassignStmt" + } + if (self.isOrassignStmt()) { + return "OrassignStmt" + } + if (self.isXorassignStmt()) { + return "XorassignStmt" + } + if (self.isShlassignStmt()) { + return "ShlassignStmt" + } + if (self.isShrassignStmt()) { + return "ShrassignStmt" + } + if (self.isAndnotassignStmt()) { + return "AndnotassignStmt" + } + } + + pub fn isControlStmt(self) -> bool { + if (self.isIfStmt()) { + return true + } + if (self.isForStmt()) { + return true + } + if (self.isCaseClause()) { + return true + } + } + + pub fn isBadStmt(self) -> bool { + if (self.getKind() = 0) { + return true + } + } + pub fn isDeclStmt(self) -> bool { + if (self.getKind() = 1) { + return true + } + } + pub fn isEmptyStmt(self) -> bool { + if (self.getKind() = 2) { + return true + } + } + pub fn isLabeledStmt(self) -> bool { + if (self.getKind() = 3) { + return true + } + } + pub fn isExprStmt(self) -> bool { + if (self.getKind() = 4) { + return true + } + } + pub fn isSendStmt(self) -> bool { + if (self.getKind() = 5) { + return true + } + } + pub fn isIncStmt(self) -> bool { + if (self.getKind() = 6) { + return true + } + } + pub fn isDecStmt(self) -> bool { + if (self.getKind() = 7) { + return true + } + } + pub fn isGoStmt(self) -> bool { + if (self.getKind() = 8) { + return true + } + } + pub fn isDeferStmt(self) -> bool { + if (self.getKind() = 9) { + return true + } + } + pub fn isReturnStmt(self) -> bool { + if (self.getKind() = 10) { + return true + } + } + pub fn isBreakStmt(self) -> bool { + if (self.getKind() = 11) { + return true + } + } + pub fn isContinueStmt(self) -> bool { + if (self.getKind() = 12) { + return true + } + } + pub fn isGotoStmt(self) -> bool { + if (self.getKind() = 13) { + return true + } + } + pub fn isFallthroughStmt(self) -> bool { + if (self.getKind() = 14) { + return true + } + } + pub fn isBlockStmt(self) -> bool { + if (self.getKind() = 15) { + return true + } + } + pub fn isIfStmt(self) -> bool { + if (self.getKind() = 16) { + return true + } + } + pub fn isCaseClause(self) -> bool { + if (self.getKind() = 17) { + return true + } + } + pub fn isExprswitchStmt(self) -> bool { + if (self.getKind() = 18) { + return true + } + } + pub fn isTypeswitchStmt(self) -> bool { + if (self.getKind() = 19) { + return true + } + } + pub fn isCommClause(self) -> bool { + if (self.getKind() = 20) { + return true + } + } + pub fn isSelectStmt(self) -> bool { + if (self.getKind() = 21) { + return true + } + } + pub fn isForStmt(self) -> bool { + if (self.getKind() = 22) { + return true + } + } + pub fn isRangeStmt(self) -> bool { + if (self.getKind() = 23) { + return true + } + } + pub fn isAssignStmt(self) -> bool { + if (self.getKind() = 24) { + return true + } + } + pub fn isDefineStmt(self) -> bool { + if (self.getKind() = 25) { + return true + } + } + pub fn isAddassignStmt(self) -> bool { + if (self.getKind() = 26) { + return true + } + } + pub fn isSubassignStmt(self) -> bool { + if (self.getKind() = 27) { + return true + } + } + pub fn isMulassignStmt(self) -> bool { + if (self.getKind() = 28) { + return true + } + } + pub fn isQuoassignStmt(self) -> bool { + if (self.getKind() = 29) { + return true + } + } + pub fn isRemassignStmt(self) -> bool { + if (self.getKind() = 30) { + return true + } + } + pub fn isAndassignStmt(self) -> bool { + if (self.getKind() = 31) { + return true + } + } + pub fn isOrassignStmt(self) -> bool { + if (self.getKind() = 32) { + return true + } + } + pub fn isXorassignStmt(self) -> bool { + if (self.getKind() = 33) { + return true + } + } + pub fn isShlassignStmt(self) -> bool { + if (self.getKind() = 34) { + return true + } + } + pub fn isShrassignStmt(self) -> bool { + if (self.getKind() = 35) { + return true + } + } + pub fn isAndnotassignStmt(self) -> bool { + if (self.getKind() = 36) { + return true + } + } +} diff --git a/language/go/lib/Type.gdl b/language/go/lib/Type.gdl new file mode 100644 index 00000000..4b337e8f --- /dev/null +++ b/language/go/lib/Type.gdl @@ -0,0 +1,259 @@ +schema Type extends TypeDO { + +} +impl Type { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Type { + for (tmp in TypeDO(db)) { + yield Type { + oid : tmp.oid, + kind : tmp.kind, + format_string : tmp.format_string, + raw_string : tmp.raw_string + } + } + } + pub fn getExpr(self) -> *Expr { + for (s in Expr(__all_data__), + t in TypeDO(__all_data__), + to in TypeOfDO(__all_data__)) { + if (t.key_eq(self)) { + if (t.oid = to.getTp()) { + if (s.id = to.getExpr()) { + yield s + } + } + } + } + } + pub fn getName(self) -> string { + for (tn in TypeName(__all_data__)) { + if (tn.key_eq(self)) { + return tn.getName() + } + } + } + pub fn getFormatString(self) -> *string { + for (t in TypeDO(__all_data__)) { + if (t.key_eq(self)) { + yield t.getFormatString() + } + } + } + pub fn getRawString(self) -> *string { + for (t in TypeDO(__all_data__)) { + if (t.key_eq(self)) { + yield t.getRawString() + } + } + } + pub fn getKind(self) -> int { + for (t in TypeDO(__all_data__)) { + if (t.key_eq(self)) { + return t.getKind() + } + } + } + + pub fn isInvalidType(self) -> bool { + if (self.getKind() = 0) { + return true + } + } + pub fn isBoolexprType(self) -> bool { + if (self.getKind() = 1) { + return true + } + } + pub fn isIntType(self) -> bool { + if (self.getKind() = 2) { + return true + } + } + pub fn isInt8Type(self) -> bool { + if (self.getKind() = 3) { + return true + } + } + pub fn isInt16Type(self) -> bool { + if (self.getKind() = 4) { + return true + } + } + pub fn isInt32Type(self) -> bool { + if (self.getKind() = 5) { + return true + } + } + pub fn isInt64Type(self) -> bool { + if (self.getKind() = 6) { + return true + } + } + pub fn isUintType(self) -> bool { + if (self.getKind() = 7) { + return true + } + } + pub fn isUint8Type(self) -> bool { + if (self.getKind() = 8) { + return true + } + } + pub fn isUint16Type(self) -> bool { + if (self.getKind() = 9) { + return true + } + } + pub fn isUint32Type(self) -> bool { + if (self.getKind() = 10) { + return true + } + } + pub fn isUint64Type(self) -> bool { + if (self.getKind() = 11) { + return true + } + } + pub fn isUintptrType(self) -> bool { + if (self.getKind() = 12) { + return true + } + } + pub fn isFloat32Type(self) -> bool { + if (self.getKind() = 13) { + return true + } + } + pub fn isFloat64Type(self) -> bool { + if (self.getKind() = 14) { + return true + } + } + pub fn isComplex64Type(self) -> bool { + if (self.getKind() = 15) { + return true + } + } + pub fn isComplex128Type(self) -> bool { + if (self.getKind() = 16) { + return true + } + } + pub fn isStringexprType(self) -> bool { + if (self.getKind() = 17) { + return true + } + } + pub fn isUnsafepointerType(self) -> bool { + if (self.getKind() = 18) { + return true + } + } + pub fn isBoolLiteraltype(self) -> bool { + if (self.getKind() = 19) { + return true + } + } + pub fn isIntLiteraltype(self) -> bool { + if (self.getKind() = 20) { + return true + } + } + pub fn isRuneLiteraltype(self) -> bool { + if (self.getKind() = 21) { + return true + } + } + pub fn isFloatLiteraltype(self) -> bool { + if (self.getKind() = 22) { + return true + } + } + pub fn isComplexLiteraltype(self) -> bool { + if (self.getKind() = 23) { + return true + } + } + pub fn isStringLiteraltype(self) -> bool { + if (self.getKind() = 24) { + return true + } + } + pub fn isNilLiteraltype(self) -> bool { + if (self.getKind() = 25) { + return true + } + } + pub fn isTypeParamtype(self) -> bool { + if (self.getKind() = 26) { + return true + } + } + pub fn isArrayType(self) -> bool { + if (self.getKind() = 27) { + return true + } + } + pub fn isSliceType(self) -> bool { + if (self.getKind() = 28) { + return true + } + } + pub fn isStructType(self) -> bool { + if (self.getKind() = 29) { + return true + } + } + pub fn isPointerType(self) -> bool { + if (self.getKind() = 30) { + return true + } + } + pub fn isInterfaceType(self) -> bool { + if (self.getKind() = 31) { + return true + } + } + pub fn isTupleType(self) -> bool { + if (self.getKind() = 32) { + return true + } + } + pub fn isSignatureType(self) -> bool { + if (self.getKind() = 33) { + return true + } + } + pub fn isMapType(self) -> bool { + if (self.getKind() = 34) { + return true + } + } + pub fn isSendchanType(self) -> bool { + if (self.getKind() = 35) { + return true + } + } + pub fn isRecvchanType(self) -> bool { + if (self.getKind() = 36) { + return true + } + } + pub fn isSendrcvchanType(self) -> bool { + if (self.getKind() = 37) { + return true + } + } + pub fn isNamedType(self) -> bool { + if (self.getKind() = 38) { + return true + } + } + pub fn isTypesetLiteraltype(self) -> bool { + if (self.getKind() = 39) { + return true + } + } +} diff --git a/language/go/lib/Utils.gdl b/language/go/lib/Utils.gdl new file mode 100644 index 00000000..7161cf72 --- /dev/null +++ b/language/go/lib/Utils.gdl @@ -0,0 +1,27 @@ +schema RuntimeInfo extends RuntimeInfoDO { + +} +impl RuntimeInfo { + @data_constraint + @inline + fn __all__(db: GoDB) -> *RuntimeInfo { + for (tmp in RuntimeInfoDO(db)) { + yield RuntimeInfo { + oid : tmp.oid, + build_version : tmp.build_version, + extractor_info : tmp.extractor_info, + go_os : tmp.go_os, + go_arch : tmp.go_arch + } + } + } +} +pub fn getSignatureByName(name : string) -> string { + for (f in Function(__all_data__)) { + let (func = f.getName()) { + if (name = func) { + return f.getFunctionFullSignature() + } + } + } +} diff --git a/language/go/lib/VariableUtils.gdl b/language/go/lib/VariableUtils.gdl new file mode 100644 index 00000000..afc16138 --- /dev/null +++ b/language/go/lib/VariableUtils.gdl @@ -0,0 +1,41 @@ +schema DefineStmt extends Statement { + +} +impl DefineStmt { + @data_constraint + @inline + fn __all__(db: GoDB) -> *DefineStmt { + for (s in Statement(db)) { + if (s.isDefineStmt()) { + yield DefineStmt { + id : s.id + } + } + } + } + pub fn getAVarible(self) -> *Node { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + if (e.getIdx() < 0) { + yield Node(__all_data__).find(e) + } + } + } + } + pub fn getVaribleName(self) -> *string { + for (var in self.getAVarible()) { + for (tmp in var.print()) { + yield tmp + } + } + } + pub fn getASource(self) -> *Expr { + for (e in Expr(__all_data__)) { + if (e.getIdx() > 0) { + if (e.getParentNode().key_eq(self)) { + yield e + } + } + } + } +} diff --git a/language/go/lib/Variables.gdl b/language/go/lib/Variables.gdl new file mode 100644 index 00000000..b1afee6d --- /dev/null +++ b/language/go/lib/Variables.gdl @@ -0,0 +1,102 @@ +schema Literal extends LiteralDO { + +} +impl Literal { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Literal { + for (tmp in LiteralDO(db)) { + yield Literal { + oid : tmp.oid, + expr : tmp.expr, + value : tmp.value, + raw : tmp.raw + } + } + } + pub fn getExpression(self) -> Expr { + for (e in Expr(__all_data__)) { + if (e.id = self.getExpr()) { + return e + } + } + } +} +schema Variables extends Literal { + +} +impl Variables { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Variables { + for (tmp in Literal(db)) { + yield Variables { + oid : tmp.oid, + expr : tmp.expr, + value : tmp.value, + raw : tmp.raw + } + } + } + pub fn getBelongsFunction(self) -> Function { + for (s in Statement(__all_data__), + e in ExprDO(__all_data__)) { + if (e.oid = self.getExpr()) { + if (s.id = e.getParentId()) { + let (f = s.getBelongsFunction()) { + return f + } + } + } + } + } + pub fn getName(self) -> string { + return self.getValue() + } + pub fn getSignature(self) -> *string { + for (to in TypeOfDO(__all_data__), + t in Type(__all_data__)) { + let (e = self.getExpression()) { + if (to.getExpr() = e.id) { + if (t.oid = to.getTp()) { + yield t.getFormatString() + } + } + } + } + } +} +schema IOTALiteral extends Literal { + +} +impl IOTALiteral { + @data_constraint + @inline + fn __all__(db: GoDB) -> *IOTALiteral { + for (tmp in Literal(db)) { + if (tmp.getValue() = "iota") { + yield IOTALiteral { + oid : tmp.oid, + expr : tmp.expr, + value : tmp.value, + raw : tmp.raw + } + } + } + } +} +schema TypeName extends TypeNameDO { + +} +impl TypeName { + @data_constraint + @inline + fn __all__(db: GoDB) -> *TypeName { + for (tmp in TypeNameDO(db)) { + yield TypeName { + oid : tmp.oid, + name : tmp.name + } + } + } +} diff --git a/language/go/lib/Writable.gdl b/language/go/lib/Writable.gdl new file mode 100644 index 00000000..44e853a8 --- /dev/null +++ b/language/go/lib/Writable.gdl @@ -0,0 +1,227 @@ +schema IncDecStmt extends Statement { + +} +impl IncDecStmt { + @data_constraint + @inline + fn __all__(db: GoDB) -> *IncDecStmt { + for (s in Statement(db)) { + if (s.isIncStmt()) { + yield IncDecStmt { + id : s.id + } + } + if (s.isDecStmt()) { + yield IncDecStmt { + id : s.id + } + } + } + } +} +schema AssignmentStmt extends Statement { + +} +impl AssignmentStmt { + @data_constraint + @inline + fn __all__(db: GoDB) -> *AssignmentStmt { + for (s in Statement(db)) { + if (s.isAssignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isDefineStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isAddassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isSubassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isMulassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isQuoassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isRemassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isMulassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isAndassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isOrassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isXorassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isShlassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isShrassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + if (s.isAndnotassignStmt()) { + yield AssignmentStmt { + id : s.id + } + } + } + } + pub fn getALhs(self) -> *Expr { + for (e in Expr(__all_data__)) { + let (idx = e.getIdx()) { + if (idx < 0) { + if (e.getParentNode().key_eq(self)) { + yield e + } + } + } + } + } + pub fn getARhs(self) -> *Expr { + for (e in Expr(__all_data__)) { + let (idx = e.getIdx()) { + if (idx > 0) { + if (e.getParentNode().key_eq(self)) { + yield e + } + } + } + } + } +} +schema Writable extends Node { + +} +impl Writable { + @data_constraint + @inline + fn __all__(db: GoDB) -> *Writable { + for (n in Node(db)) { + for (s in IncDecStmt(db)) { + if (s.key_eq(n)) { + yield Writable { + id : n.id + } + } + } + for (s in AssignmentStmt(db)) { + if (s.key_eq(n)) { + yield Writable { + id : s.id + } + } + } + } + } + pub fn getAWrite(self) -> *Node { + for (e in Expr(__all_data__)) { + if (e.getParentNode().key_eq(self)) { + yield Node{id: e.id} + } + } + } + pub fn getAWriteDist(self) -> *Node { + for (e in Expr(__all_data__)) { + if (e.getIdx() < 0) { + if (e.getParentNode().key_eq(self)) { + yield Node{id: e.id} + } + } + } + } + pub fn getAWriteSource(self) -> *Node { + for (e in Expr(__all_data__)) { + if (e.getIdx() > 0) { + if (e.getParentNode().key_eq(self)) { + yield Node{id: e.id} + } + } + } + } +} +schema WritesField { + @primary id: int +} +impl WritesField { + @data_constraint + @inline + fn __all__(db: GoDB) -> *WritesField { + for (e in Expr(db)) { + if (e.isSelectorExpr()) { + yield WritesField {id : e.id} + } + } + } + pub fn getBelongsWritable(self) -> Writable { + for (w in Writable(__all_data__)) { + for (auto_tmp1 in w.getAWrite()) { + if (self.key_eq(auto_tmp1)) { + return w + } + } + } + } + + pub fn getBaseName(self) -> string { + for (e in Expr(__all_data__), l in LiteralDO(__all_data__)) { // selectorExpr + if (self.key_eq(e.getParentNode()) && e.getIdx() = 0) { // getX + let (kind = e.getKind()) { + if (kind = 1 && l.getExpr() = e.id) { + return l.getValue() + } + if (kind != 1) { // Ident + return e.getDebugInfo() + } + } + } + } + } + + pub fn getFieldName(self) -> string { + for (e in Expr(__all_data__), l in Literal(__all_data__)) { // selectorExpr + if (e.getParentNode().key_eq(self) && e.getIdx() = 1) { // getSel + let (kind = e.getKind()) { + if (kind = 1 && e.id = l.getExpr()) { + return l.getValue() + } + if (kind != 1) { // Ident + return e.getDebugInfo() + } + } + } + } + } +} diff --git a/language/java/lib/Annotation.gdl b/language/java/lib/Annotation.gdl new file mode 100644 index 00000000..aef22b5f --- /dev/null +++ b/language/java/lib/Annotation.gdl @@ -0,0 +1,729 @@ +/** + * @brief Describe an annotated relation. + */ +schema AnnotatedRelation extends AnnotatedRelationDO { + +} +impl AnnotatedRelation { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotatedRelation { + for (tmp in AnnotatedRelationDO(db)) { + yield AnnotatedRelation { + annotation_hash_id : tmp.annotation_hash_id, + annotated_item_hash_id : tmp.annotated_item_hash_id + } + } + } + /** + * @brief gets the Annotation of the annotated relation. + * @return Annotation + */ + pub fn getAnnotation(self) -> Annotation { + for (anno in Annotation(__all_data__)) { + if (anno.key_eq(self)) { + return anno + } + } + } + /** + * @brief gets the annotated element, like class, method, field and so on. + * @return ExpressionParent + */ + pub fn getAnnotatedElement(self) -> ExpressionParent { + for (element in ExpressionParent(__all_data__)) { + if (element.id = self.getAnnotatedItemHashId()) { + return element + } + } + } +} +schema AnnotationDo { + @primary id: int +} +impl AnnotationDo { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationDo { + for (a in AnnotationCanResolvedDO(db)) { + yield AnnotationDo {id : a.element_hash_id} + } + for (a in AnnotationCanNotResolvedDO(db)) { + yield AnnotationDo {id : a.element_hash_id} + } + } + /** + * @brief gets the name for the element. + * @return string + */ + pub fn getName(self) -> string { + let (name = self.getAnnotationDeclaration().getQualifiedName()) { + return name + } + for (a in AnnotationCanNotResolvedDO(__all_data__)) { + if (self.key_eq(a)) { + let (name = a.getName()) { + return name + } + } + } + } + /** + * @brief gets the name for the element. + * @return string + */ + pub fn getPrintableText(self) -> string { + for (a in AnnotationCanResolvedDO(__all_data__)) { + if (self.key_eq(a)) { + let (name = a.getPrintableText()) { + return name + } + } + } + for (a in AnnotationCanNotResolvedDO(__all_data__)) { + if (self.key_eq(a)) { + let (name = a.getPrintableText()) { + return name + } + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + for (a in AnnotationCanResolvedDO(__all_data__)) { + if (self.key_eq(a)) { + if (loc.element_hash_id = a.getLocationHashId()) { + return loc + } + } + } + for (a in AnnotationCanNotResolvedDO(__all_data__)) { + if (self.key_eq(a)) { + if (loc.element_hash_id = a.getLocationHashId()) { + return loc + } + } + } + } + } + /** + * @brief gets the parent id of the element. + * @return int + */ + pub fn getParentHashId(self) -> int { + for (a in AnnotationCanResolvedDO(__all_data__)) { + if (self.key_eq(a)) { + let (parent = a.getParentHashId()) { + return parent + } + } + } + for (a in AnnotationCanNotResolvedDO(__all_data__)) { + if (self.key_eq(a)) { + let (parent = a.getParentHashId()) { + return parent + } + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the declaration of the element, if any. + * @return AnnotationDeclaration + */ + pub fn getAnnotationDeclaration(self) -> AnnotationDeclaration { + for (decl in AnnotationDeclaration(__all_data__)) { + for (a in AnnotationCanResolvedDO(__all_data__)) { + if (self.key_eq(a)) { + if (decl.element_hash_id = a.getAnnotationDeclarationHashId()) { + return decl + } + } + } + } + } +} +/** + * @brief An access annotation. + */ +schema Annotation extends AnnotationDo { + +} +impl Annotation { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Annotation { + for (tmp in AnnotationDo(db)) { + yield Annotation { + id : tmp.id + } + } + } + /** + * @brief gets the annotated class of the annotation. + * @return Class + */ + pub fn getAnnotatedClass(self) -> Class { + for (c in Class(__all_data__), + relation in AnnotatedRelation(__all_data__)) { + if (self.key_eq(relation)) { + if (c.element_hash_id = relation.getAnnotatedItemHashId()) { + return c + } + } + } + } + /** + * @brief gets the annotated method of the annotation. + * @return Method + */ + pub fn getAnnotatedMethod(self) -> Method { + for (m in Method(__all_data__), + relation in AnnotatedRelation(__all_data__)) { + if (self.key_eq(relation)) { + if (m.element_hash_id = relation.getAnnotatedItemHashId()) { + return m + } + } + } + } + /** + * @brief gets an argument of the annotation, if any. + * @return AnnotationAccessArgument + */ + pub fn getAnnotationArgument(self) -> *AnnotationAccessArgument { + for (arg in AnnotationAccessArgument(__all_data__)) { + if (self = arg.getAnnotation()) { + yield arg + } + } + } +} +/** + * @brief An access annotation argument class, with name or without name. + */ +schema AnnotationAccessArgumentDO { + @primary id: int +} +impl AnnotationAccessArgumentDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationAccessArgumentDO { + for (a in AnnotationAccessArgumentWithNameDO(db)) { + yield AnnotationAccessArgumentDO {id : a.element_hash_id} + } + for (a in AnnotationAccessArgumentWithoutNameDO(db)) { + yield AnnotationAccessArgumentDO {id : a.element_hash_id} + } + } + /** + * @brief gets the printable text for the element. + * @return string + */ + pub fn getPrintableText(self) -> string { + for (a in AnnotationAccessArgumentWithNameDO(__all_data__)) { + if (self.key_eq(a)) { + let (name = a.getPrintableText()) { + return name + } + } + } + for (a in AnnotationAccessArgumentWithoutNameDO(__all_data__)) { + if (self.key_eq(a)) { + let (name = a.getPrintableText()) { + return name + } + } + } + } + /** + * @brief gets the printable text for the element. + * @return int + */ + pub fn getArgumentValueHashId(self) -> int { + for (a in AnnotationAccessArgumentWithNameDO(__all_data__)) { + if (self.key_eq(a)) { + let (name = a.getArgumentValueHashId()) { + return name + } + } + } + for (a in AnnotationAccessArgumentWithoutNameDO(__all_data__)) { + if (self.key_eq(a)) { + let (name = a.getArgumentValueHashId()) { + return name + } + } + } + } + /** + * @brief gets the annotation for the element. + * @return Annotation + */ + pub fn getAnnotation(self) -> Annotation { + for (anno in Annotation(__all_data__)) { + for (a in AnnotationAccessArgumentWithNameDO(__all_data__)) { + if (self.key_eq(a)) { + if (anno.id = a.getAnnotationAccessHashId()) { + return anno + } + } + } + for (a in AnnotationAccessArgumentWithoutNameDO(__all_data__)) { + if (self.key_eq(a)) { + if (anno.id = a.getAnnotationAccessHashId()) { + return anno + } + } + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + for (a in AnnotationAccessArgumentWithNameDO(__all_data__)) { + if (self.key_eq(a)) { + if (loc.element_hash_id = a.getLocationHashId()) { + return loc + } + } + } + for (a in AnnotationAccessArgumentWithoutNameDO(__all_data__)) { + if (self.key_eq(a)) { + if (loc.element_hash_id = a.getLocationHashId()) { + return loc + } + } + } + } + } + /** + * @brief gets the type for the element. + * @return int + */ + pub fn getType(self) -> int { + for (a in AnnotationAccessArgumentWithNameDO(__all_data__)) { + if (self.key_eq(a)) { + let (type = a.getTypeHashId()) { + return type + } + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (a in AnnotationAccessArgumentWithNameDO(__all_data__)) { + if (self.key_eq(a)) { + let (tmp = ElementParent{id: a.getAnnotationAccessHashId()}) { + return tmp + } + } + } + for (a in AnnotationAccessArgumentWithoutNameDO(__all_data__)) { + if (self.key_eq(a)) { + let (tmp = ElementParent{id: a.getAnnotationAccessHashId()}) { + return tmp + } + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief An argument that applies to an annotation. + */ +schema AnnotationAccessArgument extends AnnotationAccessArgumentDO { + +} +impl AnnotationAccessArgument { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationAccessArgument { + for (tmp in AnnotationAccessArgumentDO(db)) { + yield AnnotationAccessArgument { + id : tmp.id + } + } + } + /** + * @brief gets the annotated class of the annotation argument. + * @return Class + */ + pub fn getAnnotatedClass(self) -> Class { + for (c in Class(__all_data__), + relation in AnnotatedRelation(__all_data__)) { + if (self.key_eq(relation)) { + if (c.element_hash_id = relation.getAnnotatedItemHashId()) { + return c + } + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the annotated method of the annotation argument. + * @return Method + */ + pub fn getAnnotatedMethod(self) -> Method { + for (m in Method(__all_data__), + relation in AnnotatedRelation(__all_data__)) { + if (self.key_eq(relation)) { + if (m.element_hash_id = relation.getAnnotatedItemHashId()) { + return m + } + } + } + } + /** + * @brief gets the argument value, for example, a string literal, an identifier, an array initializer or a type literal. + * @return string + */ + pub fn getAnnotationArgumentValue(self) -> string { + return self.getAnnotationArgumentValue1() + return self.getAnnotationArgumentValue2() + return self.getAnnotationArgumentValue3() + return self.getAnnotationArgumentValue4() + } + /** + * @brief gets the argument value as an annotation. + * @return Annotation + */ + pub fn getArgumentAnnotation(self) -> Annotation { + for (anno in Annotation(__all_data__), + a in AnnotationArrayInitializer(__all_data__)) { + if (anno.getParent().key_eq(a)) { + if (a.element_hash_id = self.getArgumentValueHashId()) { + return anno + } + } + } + } + pub fn getAnnotationArgumentValue4(self) -> string { + for (l in TypeLiteral(__all_data__), + a in ReferenceType(__all_data__)) { + let (argumentValue = a.getQualifiedName()) { + if (self.getArgumentValueHashId() = l.element_hash_id) { + if (a.key_eq(l.getType())) { + return argumentValue + } + } + } + } + } + /** + * @brief gets the argument name, the default name is value. + * @return string + */ + pub fn getAnnotationArgumentName(self) -> string { + for (ii in Identifier(__all_data__)) { + if (ii.element_hash_id = self.getType()) { + return ii.getName() + } + } + for (b in AnnotationAccessArgumentWithoutNameDO(__all_data__)) { + if (self.key_eq(b)) { + return "value" + } + } + } + fn getAnnotationArgumentValue1(self) -> string { + for (sLiteral in StringLiteral(__all_data__)) { + if (sLiteral.element_hash_id = self.getArgumentValueHashId()) { + return sLiteral.getValue() + } + } + } + fn getAnnotationArgumentValue2(self) -> string { + for (ident in Identifier(__all_data__)) { + if (ident.getParentHashId() = self.getArgumentValueHashId()) { + return ident.getName() + } + } + } + fn getAnnotationArgumentValue3(self) -> string { + let (a = self.getArgumentValueHashId()) { + if (isArrayInitializer(a)) { + for (anno in AnnotationArrayInitializer(__all_data__)) { + if (a = anno.element_hash_id) { + return anno.getPrintableText() + } + } + } + if (!isArrayInitializer(a)) { + for (anno in Annotation(__all_data__)) { + if (a = anno.getParentHashId()) { + return anno.getPrintableText() + } + } + for (anno in Expression(__all_data__)) { + if (a = anno.getParentHashId()) { + return anno.getPrintableText() + } + } + } + } + } +} +/** + * @brief Represents an array used as a value of an annotation element. For example: @Endorsers({"Children", "Unscrupulous dentists"}) + */ +schema AnnotationArrayInitializer extends AnnotationArrayInitializerDO { + +} +impl AnnotationArrayInitializer { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationArrayInitializer { + for (tmp in AnnotationArrayInitializerDO(db)) { + yield AnnotationArrayInitializer { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the initializer value for the element. + * @return Expression + */ + pub fn getInitializerValue(self) -> *Expression { + for (e in Expression(__all_data__)) { + if (self.element_hash_id = e.getParentHashId()) { + yield e + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> AnnotationAccessArgument { + for (parent in AnnotationAccessArgument(__all_data__)) { + if (parent.getArgumentValueHashId() = self.element_hash_id) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief An annotation that applies to a declaration. + */ +schema AnnotationDeclaration extends AnnotationDeclarationDO { + +} +impl AnnotationDeclaration { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationDeclaration { + for (tmp in AnnotationDeclarationDO(db)) { + yield AnnotationDeclaration { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name + } + } + } + /** + * @brief gets the Identifier of the annotation declaration element. + * @return Identifier + */ + pub fn getIdentifier(self) -> Identifier { + for (i in Identifier(__all_data__)) { + if (self.key_eq(i.getParent())) { + return i + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__), + i in Interface(__all_data__)) { + if (self.key_eq(i)) { + if (loc.element_hash_id = i.getLocationHashId()) { + return loc + } + } + } + } +} +/** + * @brief A parameter that applied to a annotation declaration. + */ +schema AnnotationDeclarationParameter extends AnnotationDeclarationParameterDO { + +} +impl AnnotationDeclarationParameter { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationDeclarationParameter { + for (tmp in AnnotationDeclarationParameterDO(db)) { + yield AnnotationDeclarationParameter { + element_hash_id : tmp.element_hash_id, + annotation_declaration_hash_id : tmp.annotation_declaration_hash_id, + type_hash_id : tmp.type_hash_id, + parameter_value_hash_id : tmp.parameter_value_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the annotation declaration. + * @return AnnotationDeclaration + */ + pub fn getAnnotationDeclaration(self) -> AnnotationDeclaration { + for (anno in AnnotationDeclaration(__all_data__)) { + if (anno.element_hash_id = self.getAnnotationDeclarationHashId()) { + return anno + } + } + } + /** + * @brief gets the reference type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__)) { + if (type.id = self.getTypeHashId()) { + return type + } + } + } + /** + * @brief gets the Identifier for this element. + * @return Identifier + */ + pub fn getIdentifier(self) -> Identifier { + for (i in Identifier(__all_data__)) { + if (i.element_hash_id = self.getParameterValueHashId()) { + return i + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} +/** + * @brief Default value for an annotation parameter, if any. + */ +schema AnnotationDeclarationParameterDefaultValue extends AnnotationDeclarationParameterDefaultValueDO { + +} +impl AnnotationDeclarationParameterDefaultValue { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationDeclarationParameterDefaultValue { + for (tmp in AnnotationDeclarationParameterDefaultValueDO(db)) { + yield AnnotationDeclarationParameterDefaultValue { + element_hash_id : tmp.element_hash_id, + default_value : tmp.default_value + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__), + m in Method(__all_data__)) { + if (self.key_eq(m)) { + if (loc.element_hash_id = m.getLocationHashId()) { + return loc + } + } + } + } +} +pub fn isArrayInitializer(a : int) -> bool { + for (anno in AnnotationArrayInitializer(__all_data__)) { + if (a = anno.element_hash_id) { + return true + } + } +} diff --git a/language/java/lib/Array.gdl b/language/java/lib/Array.gdl new file mode 100644 index 00000000..ea07a194 --- /dev/null +++ b/language/java/lib/Array.gdl @@ -0,0 +1,270 @@ + /** + * @brief An array creation expression. + * For example, an expression such as `new String[2][3]` or + * `new String[][] { { "a", "b", "c" } , { "d", "e", "f" } }`. + * + * In both examples, `String` is the type name. In the first + * example, `2` and `3` are the 0th and 1st dimensions, + * respectively. In the second example, + * `{ { "a", "b", "c" } , { "d", "e", "f" } }` is the initializer. + */ +schema ArrayCreationExpression extends Expression { + +} +impl ArrayCreationExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ArrayCreationExpression { + for (tmp in Expression(db)) { + for (ace in ArrayCreationExpressionDO(db)) { + if (tmp.key_eq(ace)) { + yield ArrayCreationExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets a dimension of the array creation expression. + * @return Expression + */ + pub fn getADimension(self) -> *Expression { + for (e in Expression(__all_data__), + ace in ArrayCreationExpressionDO(__all_data__)) { + if (self.key_eq(ace)) { + if (e.getParent().key_eq(ace)) { + if (ace.getNumberOfArrayDimension() > 0) { + yield e + } + } + } + } + } + /** + * @brief gets the dimension of the array creation expression. + * @return Expression + */ + pub fn getDimension(self, idx : int) -> Expression { + for (auto_tmp1 in self.getADimension()) { + if (idx = auto_tmp1.getIndex()) { + return auto_tmp1 + } + } + } + /** + * @brief counts the number of the array dimension of the array creation expression, 0 means it is an empty array. + * @return int + */ + pub fn countArrayDimension(self) -> int { + for (ace in ArrayCreationExpressionDO(__all_data__)) { + if (self.key_eq(ace)) { + return ace.getNumberOfArrayDimension() + } + } + } + /** + * @brief gets the initializer of the array creation expression. + * @return ArrayInitializer + */ + pub fn getAnInitializer(self) -> *ArrayInitializer { + for (initExp in ArrayInitializerExpression(__all_data__), + init in ArrayInitializer(__all_data__), + ace in ArrayCreationExpressionDO(__all_data__)) { + if (self.key_eq(ace)) { + if (ace.key_eq(initExp.getParent())) { + if (initExp.key_eq(init.getParent())) { + yield init + } + } + } + } + } + /** + * @brief gets the initializer expression of the array creation expression. + * @return ArrayInitializerExpression + */ + pub fn getInitializerExpression(self) -> ArrayInitializerExpression { + for (initExp in ArrayInitializerExpression(__all_data__), + ace in ArrayCreationExpressionDO(__all_data__)) { + if (self.key_eq(ace)) { + if (ace.key_eq(initExp.getParent())) { + return initExp + } + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__), + ace in ArrayCreationExpressionDO(__all_data__)) { + if (self.key_eq(ace)) { + if (type.id = ace.getTypeHashId()) { + return type + } + } + } + } +} +/** + * @brief An array initializer expression. + */ +schema ArrayInitializerExpression extends Expression { + +} +impl ArrayInitializerExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ArrayInitializerExpression { + for (tmp in Expression(db)) { + for (e in ArrayInitializerExpressionDO(db)) { + if (tmp.key_eq(e)) { + yield ArrayInitializerExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the initializer of the expression, if any. + * @return ArrayInitializer + */ + pub fn getAnInitializer(self) -> *ArrayInitializer { + for (init in ArrayInitializer(__all_data__), + e in ArrayInitializerExpressionDO(__all_data__)) { + if (self.key_eq(e)) { + if (e.key_eq(init.getParent())) { + yield init + } + } + } + } + /** + * @brief gets the ith initializer of the expression. + * @return ArrayInitializer + */ + pub fn getInitializer(self, idx : int) -> ArrayInitializer { + for (init in ArrayInitializer(__all_data__), + e in ArrayInitializerExpressionDO(__all_data__)) { + if (self.key_eq(e)) { + if (e.key_eq(init.getParent())) { + if (idx = init.getIndex()) { + return init + } + } + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__), + e in ArrayInitializerExpressionDO(__all_data__)) { + if (self.key_eq(e)) { + if (type.id = e.getTypeHashId()) { + return type + } + } + } + } +} +/** + * @brief An array access expression. + */ +schema ArrayAccessExpression extends Expression { + +} +impl ArrayAccessExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ArrayAccessExpression { + for (tmp in Expression(db)) { + for (aae in ArrayAccessExpressionDO(db)) { + if (tmp.key_eq(aae)) { + yield ArrayAccessExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the array that is accessed in the array access + * @return Expression + */ + pub fn getArrayExpression(self) -> Expression { + for (arr in Expression(__all_data__), + aae in ArrayAccessExpressionDO(__all_data__)) { + if (self.key_eq(aae)) { + if (arr.element_hash_id = aae.getArrayExpressionHashId()) { + return arr + } + } + } + } + /** + * @brief gets the index expression of the array access expression. + * @return Expression + */ + pub fn getIndexExpression(self) -> Expression { + for (idx in Expression(__all_data__), + aae in ArrayAccessExpressionDO(__all_data__)) { + if (self.key_eq(aae)) { + if (idx.element_hash_id = aae.getIndexExpressionHashId()) { + return idx + } + } + } + } +} +/** + * + * @brief DO class: An array. + */ +schema Array extends ArrayDO { + +} +impl Array { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Array { + for (tmp in ArrayDO(db)) { + yield Array { + element_hash_id : tmp.element_hash_id, + name : tmp.name + } + } + } + /** + * @brief gets the type for the element. + * @return TypeElement + */ + pub fn getTypeElement(self) -> TypeElement { + for (type in TypeElement(__all_data__)) { + if (self.key_eq(type.getParent())) { + return type + } + } + } +} diff --git a/language/java/lib/CallGraph.gdl b/language/java/lib/CallGraph.gdl new file mode 100644 index 00000000..b650f738 --- /dev/null +++ b/language/java/lib/CallGraph.gdl @@ -0,0 +1,1017 @@ +/** + * @brief: callGraph provides classes and predicates for working with Java call relations + */ +schema CallExpression extends Expression { + +} +impl CallExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CallExpression { + for (tmp in Expression(db)) { + for (m in MethodAccessExpression(db)) { + if (tmp.key_eq(m)) { + yield CallExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (m in MethodReferenceExpression(db)) { + if (tmp.key_eq(m)) { + yield CallExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + pub fn getMethod(self) -> Method { + for (e in MethodAccessExpression(__all_data__)) { + if (self.key_eq(e)) { + return e.getMethod() + } + } + for (e in MethodReferenceExpression(__all_data__)) { + if (self.key_eq(e)) { + return e.getMethod() + } + } + } + pub fn getMethodName(self) -> string { + for (i in Identifier(__all_data__)) { + for (e in MethodAccessExpression(__all_data__)) { + if (self.key_eq(e)) { + if (e.getReference().key_eq(i.getParent())) { + let (m = i.getName()) { + return m + } + } + } + } + for (e in MethodReferenceExpression(__all_data__)) { + if (self.key_eq(e)) { + if (e.key_eq(i.getParent())) { + let (m = i.getName()) { + return m + } + } + } + } + } + } + pub fn getCallSite(self) -> ReferenceExpression { + for (m in MethodAccessExpression(__all_data__)) { + if (self.key_eq(m)) { + return m.getCallSite() + } + } + for (m in MethodReferenceExpression(__all_data__)) { + if (self.key_eq(m)) { + return m.getReference() + } + } + } + pub fn getReference(self) -> ReferenceExpression { + for (m in MethodAccessExpression(__all_data__)) { + if (self.key_eq(m)) { + return m.getReference() + } + } + for (m in MethodReferenceExpression(__all_data__)) { + if (self.key_eq(m)) { + return m.getReference() + } + } + } + pub fn getCallSiteDefinition(self) -> ClassOrInterface { + for (c in ClassOrInterface(__all_data__), + r in ReferenceExpression(__all_data__)) { + if (r = self.getCallSite()) { + return ClassOrInterface(__all_data__).find(r.getDefinition()) + for (v in Variable(__all_data__)) { + if (v.key_eq(r.getDefinition())) { + if (v.getType().getQualifiedName() = c.getQualifiedName()) { + return c + } + } + } + } + } + } + pub fn getLombokField(self) -> LombokField { + for (f in LombokField(__all_data__)) { + if (self.getCallSiteDefinition() = f.getParent()) { + for (auto_tmp1 in f.getLombokMethodName()) { + if (auto_tmp1 = self.getMethodName()) { + return f + } + } + } + } + } + pub fn getArguments(self) -> *Expression { + for (e in Expression(__all_data__), + m in MethodAccessExpression(__all_data__), + l in ExpressionListExpressionRelation(__all_data__)) { + if (self.key_eq(m)) { + if (m.getExpressionList() = l.getExpressionList()) { + if (e = l.getExpression()) { + yield e + } + for (auto_tmp1 in e.getAnAncestor()) { + if (l.getExpression().key_eq(auto_tmp1)) { + yield e + } + } + } + } + } + } +} +schema LombokField extends Field { + +} +impl LombokField { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LombokField { + for (tmp in Field(db)) { + for (a in Annotation(db)) { + for (auto_tmp2 in tmp.getAnnotation()) { + if (a = auto_tmp2) { + if (a.getName() = "Data") { + yield LombokField { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + if (a.getName() = "Getter") { + yield LombokField { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + if (a.getName() = "Setter") { + yield LombokField { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + } + } + for (c in ClassOrInterface(db)) { + if (c = tmp.getParent()) { + for (auto_tmp3 in c.getAnnotation()) { + if (a = auto_tmp3) { + if (a.getName() = "Data") { + yield LombokField { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + if (a.getName() = "Getter") { + yield LombokField { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + if (a.getName() = "Setter") { + yield LombokField { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + } + } + } + } + } + } + } + pub fn getLombokMethodName(self) -> *string { + for (j in string::__undetermined_all__()) { + let (temp = self.getName()) { + let (i = temp.len()) { + let (l = temp.substr(0, 1)) { + let (p = temp.substr(1, i)) { + if (lowerToUpper(l, j)) { + let (name = "set" + j + p) { + yield name + } + let (name = "get" + j + p) { + yield name + } + } + } + } + } + } + } + } +} +/** + * @brief A callable binding relation between caller and callee. + */ +schema CallableBinding extends CallableBindingDO { + +} +impl CallableBinding { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CallableBinding { + for (tmp in CallableBindingDO(db)) { + yield CallableBinding { + caller_hash_id : tmp.caller_hash_id, + callee_hash_id : tmp.callee_hash_id + } + } + } + /** + * @brief gets the caller expression. + * @return CallExpression + */ + pub fn getCaller(self) -> CallExpression { + return CallExpression(__all_data__).find(self) + } + /** + * @brief gets the callee of the method access expression. + * @return Method + */ + pub fn getCallee(self) -> Callable { + for (callee in Callable(__all_data__)) { + if (self.getCalleeHashId() = callee.id) { + return callee + } + } + } +} +/** + * @brief A list of expression separated by commas. + */ +schema ExpressionList extends ExpressionListDO { + +} +impl ExpressionList { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionList { + for (tmp in ExpressionListDO(db)) { + yield ExpressionList { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + size : tmp.size + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + pub fn getSubExpression(self, position : int) -> Expression { + for (eler in ExpressionListExpressionRelation(__all_data__)) { + if (self = eler.getExpressionList()) { + if (position = eler.getPosition()) { + return eler.getExpression() + } + } + } + } + pub fn getContainedExpression(self) -> Expression { + for (eler in ExpressionListExpressionRelation(__all_data__)) { + if (self = eler.getExpressionList()) { + return eler.getExpression() + } + } + } +} +/** + * @brief Reference relation between expression list to its contained expression. + */ +schema ExpressionListExpressionRelation extends ExpressionListExpressionRelationDO { + +} +impl ExpressionListExpressionRelation { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionListExpressionRelation { + for (tmp in ExpressionListExpressionRelationDO(db)) { + yield ExpressionListExpressionRelation { + expression_list_hash_id : tmp.expression_list_hash_id, + expression_hash_id : tmp.expression_hash_id, + position : tmp.position + } + } + } + pub fn getExpressionList(self) -> ExpressionList { + for (expressionList in ExpressionList(__all_data__)) { + if (expressionList.element_hash_id = self.getExpressionListHashId()) { + return expressionList + } + } + } + pub fn getExpression(self) -> Expression { + return Expression(__all_data__).find(self) + } +} +/** + * @brief A callable element, either a method or a constructor. + */ +schema Callable { + @primary id: int +} +impl Callable { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Callable { + for (m in Method(db)) { + yield Callable {id : m.element_hash_id} + } + for (c in Constructor(db)) { + yield Callable {id : c.element_hash_id} + } + for (nm in NpMethod(db)) { + yield Callable {id : nm.element_hash_id} + } + } + fn tmp_getCaller_judge(tmp1: Callable, tmp2: Callable) -> bool { + if (tmp1 = tmp2) { + return true + } + if (tmp2 in tmp1.getPolyCallable()) { + return true + } + } + fn tmp_getCallee_judge(self, tmp: Callable) -> bool { + if (self = tmp) { + return true + } + if (tmp in self.getPolyCallable()) { + return true + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getReturnType(self) -> Type { + for (t in Type(__all_data__)) { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + if (t = m.getType()) { + return t + } + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + if (t.id = 10) { + return t + } + } + } + for (nm in NpMethod(__all_data__)) { + if (self.key_eq(nm)) { + if (t.key_eq(nm.getType())) { + return t + } + } + } + } + } + /** + * @brief gets the parameter of the method, if any. + * @return Parameter + */ + pub fn getParameter(self) -> *Parameter { + for (param in Parameter(__all_data__)) { + if (self.id = param.getParentHashId()) { + yield param + } + } + } + /** + * @brief gets the polymorphism methods of the method, if any. + * @return Method + */ + pub fn getPolyCallable(self) -> *Callable { + for (m in Method(__all_data__)) { + if (m.element_hash_id = self.id) { + for (tmp in m.getPolyMethod()) { + yield Callable{id: tmp.element_hash_id} + } + } + } + } + /** + * @brief gets the parent of the Callable element. + * @return Interface + */ + pub fn getBelongedInterface(self) -> Interface { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + return Interface(__all_data__).find(m.getParent()) + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + return Interface(__all_data__).find(c.getParent()) + } + } + } + /** + * @brief gets the parent of the Callable element. + * @return ClassOrInterface + */ + pub fn getBelongedClass(self) -> ClassOrInterface { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + return m.getParent() + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + return c.getParent() + } + } + for (nm in NpMethod(__all_data__)) { + if (self.key_eq(nm)) { + return ClassOrInterface(__all_data__).find(nm.getParent()) + } + } + } + /** + * @brief gets the annotation of the Callable element. + * @return Annotation + */ + pub fn getAnnotation(self) -> *Annotation { + for (c in Method(__all_data__)) { + if (self.key_eq(c)) { + yield c.getAnnotation() + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + yield c.getAnnotation() + } + } + } + /** + * @brief gets the modifier of the callable. + * @return Modifier + */ + pub fn getModifier(self) -> *Modifier { + for (m in Modifier(__all_data__), + list in ModifierList(__all_data__)) { + if (list.getParent().key_eq(self)) { + if (m.getModifierList() = list) { + yield m + } + } + } + } + /** + * @brief gets the body of the method. + * @return CodeBlock + */ + pub fn getBody(self) -> CodeBlock { + for (body in CodeBlock(__all_data__)) { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + if (m.key_eq(body.getParent())) { + return body + } + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + if (c.key_eq(body.getParent())) { + return body + } + } + } + } + } + /** + * @brief gets the name of the callable + * @return string + */ + pub fn getName(self) -> string { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + let (name = m.getName()) { + return name + } + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + let (name = c.getName()) { + return name + } + } + } + } + /** + * @brief gets the name of the callable + * @return string + */ + pub fn getType(self) -> Type { + for (t in Type(__all_data__)) { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + if (t = m.getType()) { + return t + } + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + if (t.id = 10) { + return t + } + } + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + return m.getLocation() + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + return c.getLocation() + } + } + } + /** + * @brief gets the size for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + return m.getSize() + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + return c.getSize() + } + } + } + /** + * @brief gets the name of the callable + * @return string + */ + pub fn getSignature(self) -> string { + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + let (name = m.getSignature()) { + return name + } + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + let (name = c.getSignature()) { + return name + } + } + } + } + /** + * @brief gets the caller of the callable + * @return Callable + */ + pub fn getCaller(self) -> *Callable { + for (c in Callable(__all_data__), + poly in Callable(__all_data__)) { + if (Callable::tmp_getCaller_judge(poly, c)) { + for (n in MethodAccessExpression(__all_data__)) { + if (c = n.getEnclosingCallable()) { + if (self.key_eq(n.getMethod())) { + yield poly + } + for (tmp in self.getPolyCallable()) { + if (tmp.key_eq(n.getMethod())) { + yield poly + } + } + for (tmp in Method(__all_data__)) { + if (self.key_eq(tmp)) { + if (output4(n, tmp)) { + yield poly + } + } + } + for (tmp in n.getMethod().getPolyMethod()) { + if (self.key_eq(tmp)) { + yield poly + } + } + } + } + for (m in MethodReferenceExpression(__all_data__)) { + if (c = m.getEnclosingCallable()) { + if (self.key_eq(m.getMethod())) { + yield poly + } + for (tmp in self.getPolyCallable()) { + if (tmp.key_eq(m.getMethod())) { + yield poly + } + } + for (tmp in m.getMethod().getPolyMethod()) { + if (self.key_eq(tmp)) { + yield poly + } + } + } + } + for (sci in SuperConstructorInvocation(__all_data__)) { + if (self.key_eq(sci.getConstructor()) && + c = sci.getEnclosingCallable()) { + yield poly + } + } + for (ci in ConstructorInvocation(__all_data__)) { + if (self.key_eq(ci.getConstructor()) && + c = ci.getEnclosingCallable()) { + yield poly + } + } + for (sae in SuperAccessExpression(__all_data__)) { + if (self.key_eq(sae.getMethod()) && + c = sae.getEnclosingCallable()) { + yield poly + } + } + } + } + } + /** + * @brief gets an ancestor caller of the callable, if any + * @return Callable + */ + pub fn getAnAncestorCaller(self) -> *Callable{ + yield self.getCaller() + for (tmp in self.getAnAncestorCaller()) { + yield tmp.getCaller() + } + } + /** + * @brief gets the callee of the callable + * @return Callable + */ + pub fn getCallee(self) -> *Callable { + for (c in Callable(__all_data__), + poly in Callable(__all_data__)) { + if (self.tmp_getCallee_judge(poly)) { + for (n in MethodAccessExpression(__all_data__)) { + if (poly = n.getEnclosingCallable()) { + if (c.key_eq(n.getMethod())) { + yield c + } + for (tmp in n.getMethod().getPolyMethod()) { + if (c.key_eq(tmp)) { + yield c + } + } + for (tmp in c.getPolyCallable()) { + if (n.getMethod().key_eq(tmp)) { + yield c + } + } + for (tmp in Method(__all_data__)) { + if (tmp.element_hash_id = c.id) { + if (output3(n, tmp)) { + yield c + } + } + } + } + } + for (m in MethodReferenceExpression(__all_data__)) { + if (poly = m.getEnclosingCallable()) { + if (c.key_eq(m.getMethod())) { + yield c + } + for (tmp in m.getMethod().getPolyMethod()) { + if (c.key_eq(tmp)) { + yield c + } + } + for (tmp in c.getPolyCallable()) { + if (m.getMethod().key_eq(tmp)) { + yield c + } + } + } + } + for (sci in SuperConstructorInvocation(__all_data__)) { + if (poly = sci.getEnclosingCallable() && + c.key_eq(sci.getConstructor())) { + yield c + } + } + for (ci in ConstructorInvocation(__all_data__)) { + if (poly = ci.getEnclosingCallable() && + c.key_eq(ci.getConstructor())) { + yield c + } + } + for (sae in SuperAccessExpression(__all_data__)) { + if (poly = sae.getEnclosingCallable() && + c.key_eq(sae.getMethod())) { + yield c + } + } + } + } + } + /** + * @brief gets an ancestor callee of the callable, if any + * @return Callable + */ + pub fn getAnAncestorCallee(self) -> *Callable { + yield self.getCallee() + for (auto_tmp2 in self.getAnAncestorCallee()) { + yield auto_tmp2.getCallee() + } + } + /** + * @brief gets the anonymous method enclosed by it. + * @return AnonymousMethod + */ + pub fn getEnclosedAnonymousMethod(self) -> *AnonymousMethod { + for (m in AnonymousMethod(__all_data__)) { + if (self = m.getNonAnonymousEnclosingCallable()) { + yield m + } + } + } + /** + * @brief gets the extra callee from enclosed anonymous method. + * @return callee + */ + pub fn getCalleeFromAnonymousMethod(self) -> *Callable { + for (a in AnonymousMethod(__all_data__)) { + for (auto_tmp1 in self.getEnclosedAnonymousMethod()) { + if (a = auto_tmp1) { + yield a.getCallee() + } + } + } + } +} +/** + * @brief Describe an expression enclosed by a certain callable. + */ +schema CallableEnclosingExpression extends CallableEnclosingExpressionDO { + +} +impl CallableEnclosingExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CallableEnclosingExpression { + for (tmp in CallableEnclosingExpressionDO(db)) { + yield CallableEnclosingExpression { + expression_hash_id : tmp.expression_hash_id, + callable_hash_id : tmp.callable_hash_id + } + } + } + /** + * @brief gets the expression in the callable. + * @return Expression + */ + pub fn getExpression(self) -> Expression { + return Expression(__all_data__).find(self) + } + /** + * @brief gets the callable of the expression. + * @return Callable + */ + pub fn getCallable(self) -> Callable { + for (cc in Callable(__all_data__)) { + if (cc.id = self.getCallableHashId()) { + return cc + } + } + } +} +/** + * @brief A reference in code (either an identifier or a sequence of identifiers separated by periods, optionally with generic type arguments) + */ +schema ReferenceElement extends ReferenceElementDO { + +} +impl ReferenceElement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceElement { + for (tmp in ReferenceElementDO(db)) { + yield ReferenceElement { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.id = self.getParentHashId()) { + return tmp + } + } + } + /** + * @brief gets the definition of the reference element, usually Class or Interface. + * @return ElementParent + */ + pub fn getDefinition(self) -> ElementParent { + return ReferenceRelation(__all_data__).find(self).getDestination() + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} +/** + * @brief An anonymous method, parent is an anonymous class. + */ +schema AnonymousMethod extends Callable { + +} +impl AnonymousMethod { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnonymousMethod { + for (tmp in Callable(db)) { + for (c in AnonymousClass(db)) { + if (c.key_eq(tmp.getBelongedClass())) { + yield AnonymousMethod { + id : tmp.id + } + } + } + } + } + /** + * @brief gets the enclosing callable of the element, if any, the enclosing callable may be an anonymousMethod as well. + * @return Callable. + */ + pub fn getEnclosingCallable(self) -> Callable { + for (e in Expression(__all_data__)) { + if (e.key_eq(self.getBelongedClass().getParent())) { + return e.getEnclosingCallable() + } + } + } + /** + * @brief gets the non anonymous enclosing callable of the element. + * @return Callable. + */ + pub fn getNonAnonymousEnclosingCallable(self) -> Callable { + for(c in Callable(__all_data__), temp in Callable(__all_data__)) { + if (temp = self.getEnclosingCallable()) { + if (isAnonymousMethod(temp)) { + let (m = AnonymousMethod {id: temp.id}) { + if (c = m.getEnclosingCallable()) { + return c + } + } + } + if (!isAnonymousMethod(temp)) { + return temp + } + } + } + } +} +pub fn isDirectCall(e : CallExpression) -> bool { + for (s in ExpressionStatement(__all_data__)) { + if (s.key_eq(e.getParent())) { + return true + } + } +} +pub fn output4(m : MethodAccessExpression, mm : Method) -> bool { + return output3(m, mm) +} +pub fn isAnonymousMethod(c : Callable) -> bool { + for (m in AnonymousMethod(__all_data__)) { + if (m.key_eq(c)) { + return true + } + } +} +pub fn output3(m: MethodAccessExpression, tmp: Method) -> bool { + let (temp3 = tmp_deal_txt(m.getPrintableText())) { + if (tmp.getName() = temp3.get_regex_match_result(".*\\.+(\\w+).*", 1)) { + let (c = tmp.getBelongedClass()) { + if (c.getQualifiedName() = temp3.get_regex_match_result("(\\w+)\\.+.*", 1)) { + return true + } + } + } + } +} + +@inline +fn tmp_deal_txt(tmp: string) -> string { + if (tmp.len() > 1000) { + return tmp.substr(0, 1000) + } + if (tmp.len() <= 1000) { + return tmp + } +} diff --git a/language/java/lib/Class.gdl b/language/java/lib/Class.gdl new file mode 100644 index 00000000..a83f0b14 --- /dev/null +++ b/language/java/lib/Class.gdl @@ -0,0 +1,1754 @@ +/** + * @brief A java class. + */ +schema Class extends ClassDO { + +} +impl Class { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Class { + for (tmp in ClassDO(db)) { + yield Class { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the parent of the method. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets the identifier of the class name. + * @return Identifier + */ + pub fn getIdentifier(self) -> Identifier { + for (ident in Identifier(__all_data__)) { + if (ident.element_hash_id = self.getIdentifierHashId()) { + return ident + } + } + } + /** + * @brief gets the name of the class. + * @return string + */ + pub fn getName(self) -> string { + for (ident in Identifier(__all_data__)) { + let (name = ident.getName()) { + if (ident = self.getIdentifier()) { + return name + } + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the modifier of the Class + * @return Modifier + */ + pub fn getModifier(self) -> *Modifier { + for (mo in Modifier(__all_data__)) { + let (list = mo.getModifierList()) { + if (list.getClassParent() = self) { + yield mo + } + } + } + } + /** + * @brief gets the annotation of the class, if any. + * @return Annotation + */ + pub fn getAnnotation(self) -> *Annotation { + for (relation in AnnotatedRelation(__all_data__)) { + if (self.element_hash_id = relation.getAnnotatedItemHashId()) { + yield Annotation(__all_data__).find(relation) + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the super class of the element. + * @return Class + */ + pub fn getSuperClass(self) -> Class { + for (CH in ClassHierarchy(__all_data__)) { + if (self.key_eq(CH)) { + return CH.getSuperClass() + } + } + } + /** + * @brief gets the implemented interface of the class element. + * @return Interface + */ + pub fn getImplementsInterface(self) -> *Interface { + for (CH in ClassHierarchy(__all_data__)) { + if (self.key_eq(CH)) { + yield CH.getInterface() + } + } + } + /** + * @brief gets the super class or implemented interface of the class element. + * @return ClassOrInterface + */ + pub fn getSuperOrImplementsType(self) -> *ClassOrInterface { + let (c = ClassOrInterface(__all_data__).find(self.getSuperClass())) { + yield c + } + for (auto_tmp1 in self.getImplementsInterface()) { + let (c = ClassOrInterface(__all_data__).find(auto_tmp1)) { + yield c + } + } + } + /** + * @brief gets any ascentant class or interface of the class element. + * @return ClassOrInterface + */ + pub fn getAnAscentantClassOrInterface(self) -> *ClassOrInterface { + for (c in ClassOrInterface(__all_data__)) { + for (auto_tmp1 in self.getSuperOrImplementsType()) { + if (c = auto_tmp1) { + yield c + } + } + for (auto_tmp2 in self.getAnAscentantClassOrInterface()) { + for (auto_tmp3 in auto_tmp2.getSuperOrImplementsType()) { + if (c = auto_tmp3) { + yield c + } + } + } + } + } + /** + * @brief gets all ancestor classes of the element. + * @return Class + */ + pub fn getAnAncestorClass(self) -> *Class { + yield self.getSuperClass() + for (auto_tmp1 in self.getAnAncestorClass()) { + yield auto_tmp1.getSuperClass() + } + } + /** + * @brief gets all fields of the class. + * @return Field + */ + pub fn getAllFields(self) -> *Field { + for (f in Field(__all_data__)) { + if (self = f.getBelongedClass()) { + yield f + } + } + } + /** + * @brief gets all methods of the class element. + * @return Method + */ + pub fn getAllMethods(self) -> *Method { + for (m in Method(__all_data__)) { + if (self = m.getBelongedClass()) { + yield m + } + } + } + /** + * @brief gets the containing file of the class element. + * @return File + */ + pub fn getContainingFile(self) -> File { + return self.getLocation().getFile() + } + /** + * @brief gets the package of the class element. + * @return Package + */ + pub fn getPackage(self) -> Package { + for (c in Cupackage(__all_data__)) { + if (c.getCompilationUnit() = self.getContainingFile()) { + return c.getPackage() + } + } + } + /** + * @brief gets the size information of the class element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_hash_id = self.getLocationHashId()) { + return n + } + } + } +} +/** + * @brief A class implement list. + */ +schema ClassImplementList extends ClassImplementListDO { + +} +impl ClassImplementList { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ClassImplementList { + for (tmp in ClassImplementListDO(db)) { + yield ClassImplementList { + element_hash_id : tmp.element_hash_id, + implemented_element_hash_id : tmp.implemented_element_hash_id + } + } + } + /** + * @brief gets the interface type from the implement list + * @return Interface + */ + pub fn getInterface(self) -> *Type { + for (i in Type(__all_data__)) { + if (i.id = self.getImplementedElementHashId()) { + yield i + } + } + } +} +/** + * @brief A constructor. + */ +schema Constructor extends ConstructorDO { + +} +impl Constructor { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Constructor { + for (tmp in ConstructorDO(db)) { + yield Constructor { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + signature : tmp.signature, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + definition_body : tmp.definition_body + } + } + } + /** + * @brief gets the modifier of the constructor + * @return Modifier + */ + pub fn getModifier(self) -> Modifier { + for (mo in Modifier(__all_data__), + list in ModifierList(__all_data__)) { + if (mo.getModifierList() = list) { + if (list.getConstructorParent() = self) { + return mo + } + } + } + } + /** + * @brief gets the body of the constructor. + * @return CodeBlock + */ + pub fn getBody(self) -> CodeBlock { + for (body in CodeBlock(__all_data__)) { + if (self.key_eq(body.getParent())) { + return body + } + } + } + /** + * @brief gets the parameter of the constructor. + * @return Parameter + */ + pub fn getParameter(self) -> *Parameter { + for (p in Parameter(__all_data__)) { + if (self.element_hash_id = p.getParentHashId()) { + yield p + } + } + } + /** + * @brief gets the matched field of the constructor for a given parameter index. + * @return Field + */ + pub fn getMatchedFieldByIndex(self, i : int) -> Field { + for (f in Field(__all_data__)) { + if (self.getParent() = f.getParent()) { + for (r1 in ReferenceExpression(__all_data__), + r2 in ReferenceExpression(__all_data__)) { + for (auto_tmp1 in self.getParameter()) { + if (auto_tmp1.key_eq(r1.getDefinition())) { + if (r1.getEnclosingStatement() = r2.getEnclosingStatement()) { + if (f.key_eq(r2.getDefinition())) { + if (i = auto_tmp1.getIndex()) { + return f + } + } + } + } + } + } + } + } + } + /** + * @brief gets the parent of the constructor. + * @return ClassOrInterface + */ + pub fn getParent(self) -> ClassOrInterface { + for (c in ClassOrInterface(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets the return type of the constructor, which should be null. + * @return Type + */ + pub fn getType(self) -> Type { + for (c in Type(__all_data__), + m in ConstructorDO(__all_data__)) { + if (self.key_eq(m)) { + if (c.id = 10) { + return c + } + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the annotation of the class, if any. + * @return Annotation + */ + pub fn getAnnotation(self) -> Annotation { + for (anno in Annotation(__all_data__), + relation in AnnotatedRelation(__all_data__)) { + if (self.element_hash_id = relation.getAnnotatedItemHashId()) { + if (anno.key_eq(relation)) { + return anno + } + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_hash_id = self.getLocationHashId()) { + return n + } + } + } +} +/** + * @brief Represents the class hierarchy of all classes. + */ +schema ClassHierarchy extends ClassHierarchyDO { + +} +impl ClassHierarchy { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ClassHierarchy { + for (tmp in ClassHierarchyDO(db)) { + yield ClassHierarchy { + child_hash_id : tmp.child_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the superclass of the class. + * @return Class + */ + pub fn getSuperClass(self) -> Class { + for (s in Class(__all_data__)) { + if (s.element_hash_id = self.getParentHashId()) { + return s + } + } + } + /** + * @brief gets the implements interface of the class. + * @return Interface + */ + pub fn getInterface(self) -> *Interface { + for (s in Interface(__all_data__)) { + if (s.element_hash_id = self.getParentHashId()) { + yield s + } + } + } +} +/** + * @brief A class field. + */ +schema Field extends FieldDO { + +} +impl Field { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Field { + for (tmp in FieldDO(db)) { + yield Field { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the contained class of the field. + * @return Class + */ + pub fn getBelongedClass(self) -> Class { + for (s in Class(__all_data__)) { + if (s.element_hash_id = self.getParentHashId()) { + return s + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__), + t in TypeElement(__all_data__)) { + if (t = self.getTypeElement()) { + if (type = t.getType()) { + return type + } + } + } + } + /** + * @brief gets the type element for the element. + * @return TypeElement + */ + pub fn getTypeElement(self) -> TypeElement { + for (type in TypeElement(__all_data__)) { + if (self.key_eq(type.getParent())) { + return type + } + } + } + /** + * @brief gets the annotation of the field, if any. + * @return Annotation + */ + pub fn getAnnotation(self) -> *Annotation { + for (anno in Annotation(__all_data__), + relation in AnnotatedRelation(__all_data__)) { + if (self.element_hash_id = relation.getAnnotatedItemHashId()) { + if (anno.key_eq(relation)) { + yield anno + } + } + } + } + /** + * @brief gets the location of the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the modifier of the constructor + * @return Modifier + */ + pub fn getModifier(self) -> *Modifier { + for (mo in Modifier(__all_data__), + list in ModifierList(__all_data__)) { + if (list.getFieldParent() = self) { + if (mo.getModifierList() = list) { + yield mo + } + } + } + } + /** + * @brief gets the parent of the constructor. + * @return ClassOrInterface + */ + pub fn getParent(self) -> ClassOrInterface { + for (c in ClassOrInterface(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the identifier of the element. + * @return Identifier + */ + pub fn getIdentifier(self) -> Identifier { + for (ident in Identifier(__all_data__)) { + if (self.key_eq(ident.getParent())) { + return ident + } + } + } + /** + * @brief gets the default value of the element, if any. + * @return string + */ + pub fn getDefaultValue(self) -> string { + let (f = self) { + if (hasDefaultValue(f)) { + for (l in Literal(__all_data__)) { + if (self.key_eq(l.getParent())) { + return l.getValue() + } + } + } + if (!hasDefaultValue(f)) { + return "" + } + } + } +} +/** + * @brief An interface. + */ +schema Interface extends InterfaceDO { + +} +impl Interface { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Interface { + for (tmp in InterfaceDO(db)) { + yield Interface { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the identifier of the element. + * @return Identifier + */ + pub fn getIdentifier(self) -> Identifier { + for (i in Identifier(__all_data__)) { + if (i.element_hash_id = self.getIdentifierHashId()) { + return i + } + } + } + /** + * @brief gets the name of the interface. + * @return string + */ + pub fn getName(self) -> string { + for (ident in Identifier(__all_data__)) { + let (name = ident.getName()) { + if (ident = self.getIdentifier()) { + return name + } + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the parent of the method. + * @return ClassOrInterface + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the annotation of the class, if any. + * @return Annotation + */ + pub fn getAnnotation(self) -> *Annotation { + for (relation in AnnotatedRelation(__all_data__)) { + if (self.element_hash_id = relation.getAnnotatedItemHashId()) { + yield Annotation(__all_data__).find(relation) + } + } + } + /** + * @brief gets the extends interface of the element. + * @return Interface + */ + pub fn getSuperInterface(self) -> *Interface { + for (CH in ClassHierarchy(__all_data__)) { + if (self.key_eq(CH)) { + yield CH.getInterface() + } + } + } + /** + * @brief gets all ancestor classes of the element. + * @return Interface + */ + pub fn getAnAncestorInterface(self) -> *Interface { + yield self.getSuperInterface() + for (auto_tmp2 in self.getAnAncestorInterface()) { + yield auto_tmp2.getSuperInterface() + } + } + /** + * @brief gets all fields of the class. + * @return Field + */ + pub fn getField(self) -> *Field { + for (f in Field(__all_data__)) { + if (self.key_eq(f.getParent())) { + yield f + } + } + } + /** + * @brief gets all methods of the class element. + * @return Method + */ + pub fn getMethod(self) -> *Method { + for (m in Method(__all_data__)) { + if (self.key_eq(m.getParent())) { + yield m + } + } + } +} +/** + * @brief A class or an interface or an anonymous class. + */ +schema ClassOrInterface { + @primary id: int +} +impl ClassOrInterface { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ClassOrInterface { + for (c in Class(db)) { + yield ClassOrInterface {id : c.element_hash_id} + } + for (i in Interface(db)) { + yield ClassOrInterface {id : i.element_hash_id} + } + for (a in AnonymousClass(db)) { + yield ClassOrInterface {id : a.element_hash_id} + } + for (nc in NpClass(db)) { + yield ClassOrInterface {id : nc.element_hash_id} + } + for (ni in NpInterface(db)) { + yield ClassOrInterface {id : ni.element_hash_id} + } + } + fn countExtends(self) -> *ReferenceList { + for(l in ReferenceList(__all_data__)) { + if (self.key_eq(l.getParent()) && l.getRole() = "EXTENDS_LIST") { + yield l + } + } + } + fn countImplements(self) -> *ReferenceList { + for(l in ReferenceList(__all_data__)) { + if (self.key_eq(l.getParent()) && l.getRole() = "IMPLEMENTS_LIST") { + yield l + } + } + } + /** + * @brief gets the name of the element. + * @return string + */ + pub fn getName(self) -> string { + for (c in Class(__all_data__)) { + if (self.key_eq(c)) { + let (s = c.getName()) { + return s + } + } + } + for (i in Interface(__all_data__)) { + if (self.key_eq(i)) { + let (s = i.getName()) { + return s + } + } + } + for (a in AnonymousClass(__all_data__)) { + if (self.key_eq(a)) { + let (s = "AnonymousClass:NULL") { + return s + } + } + } + for (nc in NpClass(__all_data__)) { + if (self.key_eq(nc)) { + let (s = nc.getName()) { + return s + } + } + } + for (ni in NpInterface(__all_data__)) { + if (self.key_eq(ni)) { + let (s = ni.getName()) { + return s + } + } + } + } + /** + * @brief gets the qualified name of the element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + for (c in Class(__all_data__)) { + if (self.key_eq(c)) { + let (s = c.getQualifiedName()) { + return s + } + } + } + for (i in Interface(__all_data__)) { + if (self.key_eq(i)) { + let (s = i.getQualifiedName()) { + return s + } + } + } + for (a in AnonymousClass(__all_data__)) { + if (self.key_eq(a)) { + let (s = "AnonymousClass:NULL") { + return s + } + } + } + for (nc in NpClass(__all_data__)) { + if (self.key_eq(nc)) { + let (s = nc.getQualifiedName()) { + return s + } + } + } + for (ni in NpInterface(__all_data__)) { + if (self.key_eq(ni)) { + let (s = ni.getQualifiedName()) { + return s + } + } + } + } + /** + * @brief gets the parent of the method. + * @return ClassOrInterface + */ + pub fn getParent(self) -> ElementParent { + for (c in Class(__all_data__)) { + if (self.key_eq(c)) { + return c.getParent() + } + } + for (i in Interface(__all_data__)) { + if (self.key_eq(i)) { + return i.getParent() + } + } + for (a in AnonymousClass(__all_data__)) { + if (self.key_eq(a)) { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(a.getParent())) { + return tmp + } + } + } + } + for (nc in NpClass(__all_data__)) { + if (self.key_eq(nc)) { + return nc.getParent() + } + } + for (ni in NpInterface(__all_data__)) { + if (self.key_eq(ni)) { + return ni.getParent() + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the type of the class, which can be class, interface or enum. + * @return string + */ + pub fn getClassType(self) -> string { + for (m in Modifier(__all_data__)) { + if (self.key_eq(m.getParent())) { + return m.getName() + } + } + } + /** + * @brief gets the super class or implemented interface of the class element. + * @return ClassOrInterface + */ + pub fn getSuperOrImplementsType(self) -> *ClassOrInterface { + for (coi in ClassOrInterface(__all_data__)) { + for (c in Class(__all_data__)) { + if (self.key_eq(c)) { + if (coi.key_eq(c.getSuperClass())) { + yield coi + } + for (auto_tmp1 in c.getImplementsInterface()) { + if (coi.key_eq(auto_tmp1)) { + yield coi + } + } + } + } + for (i in Interface(__all_data__)) { + if (self.key_eq(i)) { + for (auto_tmp2 in i.getSuperInterface()) { + if (coi.key_eq(auto_tmp2)) { + yield coi + } + } + } + } + } + } + /** + * @brief gets any ascentant class or interface of the class element. + * @return ClassOrInterface + */ + pub fn getAnAscentantClassOrInterface(self) -> *ClassOrInterface { + yield self.getSuperOrImplementsType() + for (auto_tmp in self.getAnAscentantClassOrInterface()) { + yield auto_tmp.getSuperOrImplementsType() + } + } + /** + * @brief gets the location info of the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (c in Class(__all_data__)) { + if (self.key_eq(c)) { + return c.getLocation() + } + } + for (i in Interface(__all_data__)) { + if (self.key_eq(i)) { + return i.getLocation() + } + } + for (a in AnonymousClass(__all_data__)) { + if (self.key_eq(a)) { + return a.getLocation() + } + } + } + /** + * @brief gets the package info of the element. + * @return string + */ + pub fn getPackageInfo(self) -> string { + for (f in File(__all_data__), + c in Cupackage(__all_data__)) { + if (f = self.getLocation().getFile()) { + if (f = c.getCompilationUnit()) { + return c.getPackage().getPackageName() + } + } + } + } + /** + * @brief gets the import info of the element. + * @return string + */ + pub fn getImportlist(self) -> *string { + for (f in File(__all_data__)) { + if (f = self.getLocation().getFile()) { + for (im in Import(__all_data__)) { + if (f = im.getContainingFile()) { + yield im.getPrintableText() + } + } + for (is in ImportStaticStatement(__all_data__)) { + if (f = is.getParent()) { + yield is.getPrintableText() + } + } + } + } + } + /** + * @brief gets the annotation info of the element. + * @return Annotation + */ + pub fn getAnnotation(self) -> *Annotation { + for (c in Class(__all_data__)) { + if (self.key_eq(c)) { + yield c.getAnnotation() + } + } + for (c in Interface(__all_data__)) { + if (self.key_eq(c)) { + yield c.getAnnotation() + } + } + } + /** + * @brief gets the modifier info of the element. + * @return Modifier + */ + pub fn getModifier(self) -> *Modifier { + for (m in Modifier(__all_data__), + list in ModifierList(__all_data__)) { + if (list.getParent().key_eq(self)) { + if (m.getModifierList() = list) { + yield m + } + } + } + } + /** + * @brief gets the extends info of the element. + * @return string + */ + pub fn getExtendsList(self) -> *string { + let (i = self.countExtends().len()) { + if (i > 0) { + for(l in ReferenceList(__all_data__)) { + if (self.key_eq(l.getParent()) && l.getRole() = "EXTENDS_LIST") { + yield l.getPrintableText() + } + } + } + if (i <= 0) { + yield "null" + } + } + } + /** + * @brief gets the implements info of the element. + * @return string + */ + pub fn getImplementsList(self) -> *string { + let (i = self.countImplements().len()) { + if (i > 0) { + for(l in ReferenceList(__all_data__)) { + if (self.key_eq(l.getParent()) && l.getRole() = "IMPLEMENTS_LIST") { + yield l.getPrintableText() + } + } + } + if (i <= 0) { + yield "null" + } + } + } +} +/** + * @brief Reference relation between reference element to its resolved element. + */ +schema ReferenceRelation extends ReferenceRelationDO { + +} +impl ReferenceRelation { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceRelation { + for (tmp in ReferenceRelationDO(db)) { + yield ReferenceRelation { + reference_element_hash_id : tmp.reference_element_hash_id, + definition_element_hash_id : tmp.definition_element_hash_id + } + } + } + /** + * @brief get the reference expression or reference element or import static reference element which references some definitions. + * @return Expression + */ + pub fn getSource(self) -> ElementParent { + for (r in ReferenceExpression(__all_data__)) { + if (r.element_hash_id = self.getSourceId()) { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(r)) { + return tmp + } + } + } + } + for (r in ReferenceElement(__all_data__)) { + if (r.element_hash_id = self.getSourceId()) { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(r)) { + return tmp + } + } + } + } + for (r in ImportStaticReferenceElement(__all_data__)) { + if (r.element_hash_id = self.getSourceId()) { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(r)) { + return tmp + } + } + } + } + } + /** + * @brief get the destination of this reference relation. + * @return ExpressionParent + */ + pub fn getDestination(self) -> ElementParent { + for (e in ElementParent(__all_data__)) { + if (e.id = self.getDefinitionElementHashId()) { + return e + } + } + } +} +/** + * @brief A local variable. + */ +schema LocalVariable extends LocalVariableDO { + +} +impl LocalVariable { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LocalVariable { + for (tmp in LocalVariableDO(db)) { + yield LocalVariable { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + name : tmp.name, + index_order : tmp.index_order + } + } + } + /** + * @brief gets the reference expression of the local variable. + * @return Expression + */ + pub fn getReferenced(self) -> Expression { + for (rr in ReferenceRelation(__all_data__)) { + if (rr.key_eq(self)) { + return Expression(__all_data__).find(rr.getSource()) + } + } + } + /** + * @brief gets the expression of the local variable. + * @return Expression + */ + pub fn getExpression(self) -> Expression { + for (e in Expression(__all_data__)) { + if (self.key_eq(e.getParent())) { + return e + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (t in TypeElement(__all_data__)) { + if (t = self.getTypeElement()) { + return t.getType() + } + } + } + /** + * @brief gets the type element for the element. + * @return TypeElement + */ + pub fn getTypeElement(self) -> TypeElement { + for (type in TypeElement(__all_data__)) { + if (self.key_eq(type.getParent())) { + return type + } + } + } + /** + * @brief gets the identifier of the local variable. + * @return Identifier + */ + pub fn getIdentifier(self) -> Identifier { + for (ident in Identifier(__all_data__)) { + if (self.key_eq(ident.getParent())) { + return ident + } + } + } + /** + * @brief gets the location of the local variable. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the annotation of the class, if any. + * @return Annotation + */ + pub fn getAnnotation(self) -> Annotation { + for (anno in Annotation(__all_data__), + relation in AnnotatedRelation(__all_data__)) { + if (self.element_hash_id = relation.getAnnotatedItemHashId()) { + if (anno.key_eq(relation)) { + return anno + } + } + } + } +} +/** + * @brief An anonymous class + */ +schema AnonymousClass extends AnonymousClassDO { + +} +impl AnonymousClass { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnonymousClass { + for (tmp in AnonymousClassDO(db)) { + yield AnonymousClass { + element_hash_id : tmp.element_hash_id, + base_class_reference_hash_id : tmp.base_class_reference_hash_id, + base_class_type_hash_id : tmp.base_class_type_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return Expression + */ + pub fn getParent(self) -> Expression { + for (parent in Expression(__all_data__)) { + if (parent.element_hash_id = self.getParentHashId()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the type for the base class of the anonymous class. + * @return ReferenceType + */ + pub fn getBaseClassType(self) -> ReferenceType { + for (type in ReferenceType(__all_data__)) { + if (type.oid = self.getBaseClassTypeHashId()) { + return type + } + } + } + /** + * @brief gets the reference element specifying the base class for the anonymous class. + * @return ReferenceElement + */ + pub fn getBaseClassReference(self) -> ReferenceElement { + for (reference in ReferenceElement(__all_data__)) { + if (reference.element_hash_id = self.getBaseClassReferenceHashId()) { + return reference + } + } + } + /** + * @brief gets the enclosing callable of the element, if any. + * @return Callable + */ + pub fn getEnclosingCallable(self) -> *Callable { + for (auto_tmp1 in self.getAnAncestor()) { + yield Callable(__all_data__).find(auto_tmp1) + } + } +} +/** + * @brief An enum constant, also a class field. + */ +schema EnumConstant extends EnumConstantDO { + +} +impl EnumConstant { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *EnumConstant { + for (tmp in EnumConstantDO(db)) { + yield EnumConstant { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the class body attached to the enum constant declaration. + * @return AnonymousClass + */ + pub fn getInitializer(self) -> AnonymousClass { + for (c in AnonymousClass(__all_data__), + e in EnumConstantDO(__all_data__)) { + if (self.key_eq(e)) { + if (e.key_eq(c.getParent())) { + return c + } + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> Class { + for (parent in Class(__all_data__)) { + if (parent.element_hash_id = self.getParentHashId()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the type of the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (t in Type(__all_data__)) { + if (t.key_eq(self.getParent())) { + return t + } + } + } + /** + * @brief gets the value list of the element. + * @return ExpressionList + */ + pub fn getValueList(self) -> ExpressionList { + for (e in ExpressionList(__all_data__)) { + if (self.element_hash_id = e.getParentHashId()) { + return e + } + } + } + /** + * @brief gets the value of the element by a given index. + * @return Expression + */ + pub fn getValueByIndex(self, i: int) -> Expression { + let (l = self.getValueList()) { + return l.getSubExpression(i) + } + } + /** + * @brief gets the corresponding field of the element by a given index, if any. + * @return Field + */ + pub fn getMatchedFieldByIndex(self, i: int) -> Field { + for (c in Constructor(__all_data__)) { + if (c.getParent().key_eq(self.getParent())) { + return c.getMatchedFieldByIndex(i) + } + } + } + /** + * @brief gets the corresponding enum value of the element by a given field, if any. + * @return Expression + */ + pub fn getValueByField(self, f: Field) -> Expression { + for (i in int::__undetermined_all__()) { + if (f = self.getMatchedFieldByIndex(i)) { + return self.getValueByIndex(i) + } + } + } + /** + * @brief gets the default value of the element. + * @return string + */ + pub fn getDefaultValue(self) -> string { + let (f = self) { + if (hasEnumDefaultValue(f)) { + for(l in Literal(__all_data__), t in ExpressionList(__all_data__)) { + if (self.key_eq(t.getParent())) { + if (t.key_eq(l.getParent())) { + return l.getValue() + } + } + } + } + if (!hasEnumDefaultValue(f)) { + return "" + } + } + } +} +/** + * @brief A java class initializer block. + */ +schema ClassInitializer extends ClassInitializerDO { + +} +impl ClassInitializer { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ClassInitializer { + for (tmp in ClassInitializerDO(db)) { + yield ClassInitializer { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} +/** + * @brief A java abstract class with a keyword 'abstract'. + */ +schema AbstractClass extends Class { + +} +impl AbstractClass { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AbstractClass { + for (tmp in Class(db)) { + for (m in Modifier(db)) { + for (auto_tmp1 in tmp.getModifier()) { + if (m = auto_tmp1) { + if (m.getName() = "abstract") { + yield AbstractClass { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + } + } + } + } +} +/** + * @brief A java enum class with a keyword 'enum'. + */ +schema EnumClass extends Class { + +} +impl EnumClass { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *EnumClass { + for (tmp in Class(db)) { + for (m in Modifier(db)) { + if (tmp.key_eq(m.getParent())) { + if (m.getName() = "enum") { + yield EnumClass { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + } + } + } +} +/** + * @brief A nested class is a member of its enclosing class. Nested classes are divided into two categories: non-static and static. Non-static nested classes are called inner classes. Nested classes that are declared static are called static nested classes. + */ +schema NestedClass extends Class { + +} +impl NestedClass { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NestedClass { + for (tmp in Class(db)) { + for (c in Class(db)) { + if (c.key_eq(tmp.getParent())) { + yield NestedClass { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + } + } +} +/** + * @brief Nested classes that are declared static are called static nested classes. + */ +schema StaticNestedClass extends NestedClass { + +} +impl StaticNestedClass { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *StaticNestedClass { + for (tmp in NestedClass(db)) { + for (m in Modifier(db)) { + for (auto_tmp2 in tmp.getModifier()) { + if (m = auto_tmp2) { + if (m.getName() = "static") { + yield StaticNestedClass { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + } + } + } + } +} +/** + * @brief Non-static nested classes are called inner classes. + */ +schema InnerClass extends NestedClass { + +} +impl InnerClass { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *InnerClass { + for (tmp in NestedClass(db)) { + for (c in NestedClass(db)) { + if (tmp = c) { + if (!isStaticClass(c)) { + yield InnerClass { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + } + } + } +} +/** + * @brief Represents a non-physical class. + */ +schema NpClass extends NpClassDO { + +} +impl NpClass { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpClass { + for (tmp in NpClassDO(db)) { + for (c in NpClassDO(db)) { + if (tmp = c) { + yield NpClass { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + qualified_name : tmp.qualified_name, + parent_hash_id : tmp.parent_hash_id + } + } + } + } + } + /** + * @brief gets the parent of this element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } +} +/** + * @brief Represents a non-physical interface. + */ +schema NpInterface extends NpInterfaceDO { + +} +impl NpInterface { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpInterface { + for (tmp in NpInterfaceDO(db)) { + for (i in NpInterfaceDO(db)) { + if (tmp = i) { + yield NpInterface { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + qualified_name : tmp.qualified_name, + parent_hash_id : tmp.parent_hash_id + } + } + } + } + } + /** + * @brief gets the parent of this element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } +} +pub fn hasDefaultValue(f : Field) -> bool { + for (l in Literal(__all_data__)) { + if (f.key_eq(l.getParent())) { + return true + } + } +} +pub fn hasEnumDefaultValue(f : EnumConstant) -> bool { + for (l in ExpressionList(__all_data__)) { + if (f.key_eq(l.getParent())) { + return true + } + } +} +pub fn isStaticClass(c : NestedClass) -> bool { + for (s in StaticNestedClass(__all_data__)) { + if (c.key_eq(s)) { + return true + } + } +} diff --git a/language/java/lib/CodeMetric.gdl b/language/java/lib/CodeMetric.gdl new file mode 100644 index 00000000..c4dc517d --- /dev/null +++ b/language/java/lib/CodeMetric.gdl @@ -0,0 +1,243 @@ +/** + * @brief This class provides access to metrics information for callables. + */ +schema MetricCallable extends Callable { + +} +impl MetricCallable { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MetricCallable { + for (tmp in Callable(db)) { + yield MetricCallable { + id : tmp.id + } + } + } + fn tmp_Expression(self) -> *Expression { + for (e in Expression(__all_data__)) { + if (self.key_eq(e.getEnclosingCallable())) { + yield e + } + } + } + fn tmp_Statement(self) -> *Statement { + for (e in Statement(__all_data__)) { + if (self.key_eq(e.getEnclosingCallable())) { + yield e + } + } + } + fn countCallable(self) -> *Callable { + for(c in Callable(__all_data__)) { + if (c in self.getCaller()) { + yield c + } + } + } + fn countCallee(self) -> *Callable { + for(c in Callable(__all_data__)) { + if (c in self.getCallee()) { + yield c + } + } + } + /** + * @brief * Gets a callable on which this callable depends. A callable `m` depends on another callable `n` if there exists a call to `n` from within `m`, taking overriding into account. + * @return Callable + */ + pub fn getADependency(self) -> *Callable { + for (c in Callable(__all_data__)) { + for (auto_tmp1 in self.getCallee()) { + if (c = auto_tmp1) { + yield c + } + } + } + } + /** + * @brief The Halstead vocabulary of a callable is estimated as the number of unique Halstead IDs of all statements and expressions within the callable. + * @return int + */ + pub fn getHalsteadVocabulary(self) -> int { + return self.tmp_Expression().len() + 1 + } + /** + * @brief The Halstead length of a callable is estimated as the sum of the number of statements and expressions within the callable, plus one for the callable itself. + * @return int + */ + pub fn getHalsteadLength(self) -> int { + return self.tmp_Expression().len() + self.tmp_Statement().len() + 1 + } + /** + * @brief The afferent coupling of a callable is defined as + * the number of callables that depend on this callable. + * + * This may also be referred to as the "fan-in" or + * "incoming dependencies" of a callable. + * @return int + */ + pub fn getAfferentCoupling(self) -> int { + return self.countCallable().len() + } + /** + * @brief * The efferent coupling of a callable is defined as + * the number of callables on which this callable depends. + * + * This may also be referred to as the "fan-out" or + * "outgoing dependencies" of a callable. + * @return int + */ + pub fn getEfferentCoupling(self) -> int { + return self.countCallee().len() + } + /** + * @brief The cyclomatic complexity of a callable is defined as the number + * of branching statements (`if`, `while`, `do`, `for`, `switch`, `case`, `catch`) + * plus the number of branching expressions (`?`, `&&` and `||`) + * plus one. + * @return int + */ + pub fn getCyclomaticComplexity(self) -> int { + let (j = tmp_getCyclomaticComplexity_1(self).len()) { + let (k = tmp_getCyclomaticComplexity_2(self).len()) { + let (l = tmp_getCyclomaticComplexity_3(self).len()) { + let (t = tmp_getCyclomaticComplexity_4(self, __all_data__, __all_data__).sum()) { + let (i = j + k + l + t + 1) { + return i + } + } + } + } + } + } +} +pub fn branchingSwitchCase(c : ConstSwitchLabelStatement) -> bool { + for (s in Statement(__all_data__)) { + if (s in c.getExecutionStatement()) { + for (b in BreakStatement(__all_data__)) { + if (s.key_eq(b)) { + return true + } + for (auto_tmp2 in b.getAnAncestor()) { + if (s.key_eq(auto_tmp2)) { + return true + } + } + } + for (r in ReturnStatement(__all_data__)) { + if (s.key_eq(r)) { + return true + } + for (auto_tmp3 in r.getAnAncestor()) { + if (s.key_eq(auto_tmp3)) { + return true + } + } + } + for (t in ThrowStatement(__all_data__)) { + if (s.key_eq(t)) { + return true + } + for (auto_tmp4 in t.getAnAncestor()) { + if (s.key_eq(auto_tmp4)) { + return true + } + } + } + } + } +} +pub fn branchingStatement(s : Statement) -> bool { + for (i in IfStatement(__all_data__)) { + if (s.key_eq(i)) { + return true + } + } + for (w in WhileStatement(__all_data__)) { + if (s.key_eq(w)) { + return true + } + } + for (d in DoWhileStatement(__all_data__)) { + if (s.key_eq(d)) { + return true + } + } + for (f in ForStatement(__all_data__)) { + if (s.key_eq(f)) { + return true + } + } + for (e in ForeachStatement(__all_data__)) { + if (s.key_eq(e)) { + return true + } + } + for (sl in ConstSwitchLabelStatement(__all_data__)) { + if (branchingSwitchCase(sl)) { + if (s.key_eq(sl)) { + return true + } + } + } +} +pub fn branchingExpression(expr : Expression) -> bool { + for (i in ConditionalExpression(__all_data__)) { + if (expr.key_eq(i)) { + return true + } + } + for (i in AndLogicalExpression(__all_data__)) { + if (expr.key_eq(i)) { + return true + } + } + for (i in OrLogicalExpression(__all_data__)) { + if (expr.key_eq(i)) { + return true + } + } +} +pub fn branchingPolyadicExpression(c : ConditionalPolyadicExpression, i : int) -> bool { + let (j = c.getSize()) { + if (i = j - 1) { + return true + } + } +} +fn tmp_getCyclomaticComplexity_1(x: MetricCallable) -> *Statement { + for (m in Statement(__all_data__)) { + if (branchingStatement(m)) { + if (x.key_eq(m.getEnclosingCallable())) { + yield m + } + } + } +} + +fn tmp_getCyclomaticComplexity_2(x: MetricCallable) -> *Expression { + for (m in Expression(__all_data__)) { + if (branchingExpression(m)) { + if (x.key_eq(m.getEnclosingCallable())) { + yield m + } + } + } +} + +fn tmp_getCyclomaticComplexity_3(x: MetricCallable) -> *CatchClause { + for (m in CatchClause(__all_data__)) { + if (x.key_eq(m.getTryStatement().getEnclosingCallable())) { + yield m + } + } +} + +fn tmp_getCyclomaticComplexity_4(x: MetricCallable, tmp: int, c: ConditionalPolyadicExpression) -> *int { + if (branchingPolyadicExpression(c, tmp)) { + if (x.key_eq(c.getEnclosingCallable())) { + yield tmp + } + } +} diff --git a/language/java/lib/Container.gdl b/language/java/lib/Container.gdl new file mode 100644 index 00000000..ef384d87 --- /dev/null +++ b/language/java/lib/Container.gdl @@ -0,0 +1,689 @@ +/** + * @brief The root of the extracted project. + */ +schema Program extends ProgramDO { + +} +impl Program { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Program { + for (tmp in ProgramDO(db)) { + yield Program { + program_hash_id : tmp.program_hash_id, + absolute_prefix_path : tmp.absolute_prefix_path + } + } + } +} +/** + * @brief A java file. + */ +schema File extends FileDO { + +} +impl File { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *File { + for (tmp in FileDO(db)) { + yield File { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + extension : tmp.extension, + name : tmp.name, + number_of_lines_hash_id : tmp.number_of_lines_hash_id + } + } + } + /** + * @brief gets the folder which contains the file, if any. + * @return Folder + */ + pub fn getBelongedFolder(self) -> Folder { + for (f in Folder(__all_data__), + container in ContainerParent(__all_data__)) { + if (self.key_eq(container)) { + if (f.element_hash_id = container.getParentHashId()) { + return f + } + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_hash_id = self.getNumberOfLinesHashId()) { + return n + } + } + } + /** + * @brief gets the package of the file. + * @return Package + */ + pub fn getPackage(self) -> Package { + for (c in Cupackage(__all_data__)) { + if (self.key_eq(c)) { + return c.getPackage() + } + } + } +} +/** + * @brief A folder. + */ +schema Folder extends FolderDO { + +} +impl Folder { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Folder { + for (tmp in FolderDO(db)) { + yield Folder { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets all files in the folder. + * @return File + */ + pub fn getAllContainingFiles(self) -> *File { + for (container in ContainerParent(__all_data__)) { + let (f = File(__all_data__).find(container)) { + if (self.element_hash_id = container.getParentHashId()) { + yield f + } + } + } + } + /** + * @brief gets the folder which contains the element. + * @return Folder + */ + pub fn getParent(self) -> Folder { + for (f in Folder(__all_data__)) { + if (f.element_hash_id = self.getParentHashId()) { + return f + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief Describe a file belonged to a certain folder. + */ +schema ContainerParent extends ContainerParentDO { + +} +impl ContainerParent { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ContainerParent { + for (tmp in ContainerParentDO(db)) { + yield ContainerParent { + child_hash_id : tmp.child_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the folder which contains the file, if any. + * @return Folder + */ + pub fn getBelongedFolder(self) -> Folder { + for (f in Folder(__all_data__)) { + if (f.element_hash_id = self.getParentHashId()) { + return f + } + } + } +} +/** + * @brief An import statement. + */ +schema Import extends ImportDO { + +} +impl Import { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Import { + for (tmp in ImportDO(db)) { + yield Import { + element_hash_id : tmp.element_hash_id, + reference_hash_id : tmp.reference_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + is_foreign_import : tmp.is_foreign_import + } + } + } + /** + * @brief gets the reference element of the statement + * @return ReferenceElement + */ + pub fn getReferenceElement(self) -> ReferenceElement { + for (r in ReferenceElement(__all_data__)) { + if (r.element_hash_id = self.getReferenceHashId()) { + return r + } + } + } + /** + * @brief gets the target name of the statement. + * @return string + */ + pub fn getTargetName(self) -> string { + for (i in Identifier(__all_data__)) { + if (i.getParentHashId() = self.getReferenceElement().element_hash_id) { + return i.getName() + } + } + } + /** + * @brief description + * @return string + */ + pub fn getIdentifier(self) -> Identifier { + for (ident in Identifier(__all_data__)) { + if (ident.getParent().id = self.getReferenceHashId()) { + return ident + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getContainingFile(self) -> File { + for (f in File(__all_data__)) { + if (f.element_hash_id = self.getParentHashId()) { + return f + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the name of the import statement. + * @return string + */ + pub fn getName(self) -> string { + let (temp = self.getPrintableText(), i = temp.len(), temp1 = temp.substr(7, i - 8)) { + if (temp1.matches(".*\\.\\*$")) { + return temp.substr(7, i - 10) + } + if (!temp1.matches(".*\\.\\*$")) { + return temp1 + } + } + } +} +/** + * @brief A package may be used to abstract over all of its members, regardless of which compilation unit they are defined in. + */ +schema Package { + @primary id: int, + qualified_name: string +} +impl Package { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Package { + for (ps in db.package_statement) { + yield Package { + id: ps.package_hash_id, + qualified_name: ps.qualified_name + } + } + } + /** + * @brief gets the name of the package. + * @return string + */ + fn getPackageName(self) -> string { + return self.qualified_name + } +} +/** + * @brief A compilation unit and its declared package, a .java file. + */ +schema Cupackage extends CupackageDO { + +} +impl Cupackage { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Cupackage { + for (tmp in CupackageDO(db)) { + yield Cupackage { + file_hash_id : tmp.file_hash_id, + package_hash_id : tmp.package_hash_id + } + } + } + /** + * @brief gets the compilation unit. + * @return File + */ + pub fn getCompilationUnit(self) -> File { + for (f in File(__all_data__)) { + if (f.key_eq(self)) { + return f + } + } + } + /** + * @brief gets the package of the element. + * @return Package + */ + pub fn getPackage(self) -> Package { + for (p in Package(__all_data__)) { + if (p.id = self.getPackageHashId()) { + return p + } + } + } +} +/** + * Represents the list of type arguments specified on a Java reference. + * + */ +schema ReferenceParameterList { + @primary id: int +} +impl ReferenceParameterList { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceParameterList { + for (r in ReferenceParameterListDO(db)) { + yield ReferenceParameterList {id : r.list_hash_id} + } + for (r in EmptyReferenceParameterListDO(db)) { + yield ReferenceParameterList {id : r.list_hash_id} + } + } + /** + * @brief gets the type element for the element, if any. + * @return TypeElement + */ + pub fn getTypeElement(self) -> *TypeElement { + for (p in TypeElement(__all_data__)) { + for (r in ReferenceParameterListDO(__all_data__)) { + if (self.key_eq(r)) { + if (p.element_hash_id = r.getTypeElementHashId()) { + yield p + } + } + } + } + } + /** + * @brief gets the printable text for the element. + * @return string + */ + pub fn getPrintableText(self) -> string { + for (r in ReferenceParameterListDO(__all_data__)) { + if (self.key_eq(r)) { + return r.getPrintableText() + } + } + for (r in EmptyReferenceParameterListDO(__all_data__)) { + if (self.key_eq(r)) { + return r.getPrintableText() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + for (r in ReferenceParameterListDO(__all_data__)) { + if (self.key_eq(r)) { + if (loc.element_hash_id = r.getLocationHashId()) { + return loc + } + } + } + for (r in EmptyReferenceParameterListDO(__all_data__)) { + if (self.key_eq(r)) { + if (loc.element_hash_id = r.getLocationHashId()) { + return loc + } + } + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (r in ReferenceParameterListDO(__all_data__)) { + if (self.key_eq(r)) { + for (tmp in ElementParent(__all_data__)) { + if (tmp.id = r.getParentHashId()) { + return tmp + } + } + } + } + for (r in EmptyReferenceParameterListDO(__all_data__)) { + if (self.key_eq(r)) { + for (tmp in ElementParent(__all_data__)) { + if (tmp.id = r.getParentHashId()) { + return tmp + } + } + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief Represents a Java import static statement. + */ +schema ImportStaticStatement extends ImportStaticStatementDO { + +} +impl ImportStaticStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ImportStaticStatement { + for (tmp in ImportStaticStatementDO(db)) { + yield ImportStaticStatement { + element_hash_id : tmp.element_hash_id, + reference_hash_id : tmp.reference_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the name of the import static statement. + * @return string + */ + pub fn getName(self) -> string { + let (temp = self.getPrintableText()) { + let (i = temp.len()) { + let (name = temp.substr(14, i - 15)) { + return name + } + } + } + } + /** + * @brief gets the reference id of the element. + * @return ImportStaticReferenceElement + */ + pub fn getReference(self) -> ImportStaticReferenceElement { + for (loc in ImportStaticReferenceElement(__all_data__)) { + if (loc.element_hash_id = self.getReferenceHashId()) { + return loc + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the parent of the element. + * @return File + */ + pub fn getParent(self) -> File { + for (parent in File(__all_data__)) { + if (parent.element_hash_id = self.getParentHashId()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief Represents a reference to the member imported by a Java import static statement. + */ +schema ImportStaticReferenceElement extends ImportStaticReferenceElementDO { + +} +impl ImportStaticReferenceElement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ImportStaticReferenceElement { + for (tmp in ImportStaticReferenceElementDO(db)) { + yield ImportStaticReferenceElement { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the parent of the element. + * @return ImportStaticStatement + */ + pub fn getParent(self) -> ImportStaticStatement { + for (parent in ImportStaticStatement(__all_data__)) { + if (parent.element_hash_id = self.getParentHashId()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief Represents a resource list of try-with-resources statement (automatic resource management) introduced in JDK 7. + */ +schema ResourceList extends ResourceListDO { + +} +impl ResourceList { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ResourceList { + for (tmp in ResourceListDO(db)) { + yield ResourceList { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief get i-th LocalVariable of the element + * @return LocalVariable + */ + pub fn getIthLocalVariable(self, index : int) -> LocalVariable { + for (localVariable in LocalVariable(__all_data__)) { + if (self.key_eq(localVariable.getParent())) { + if (index = localVariable.getIndex()) { + return localVariable + } + } + } + } + /** + * @brief get i-th LocalVariable of the element + * @return LocalVariable + */ + pub fn getLocalVariable(self) -> LocalVariable { + for (localVariable in LocalVariable(__all_data__)) { + if (self.key_eq(localVariable.getParent())) { + return localVariable + } + } + } +} +/** + * @brief Represents a non-physical project, suck as a jar from dependencies. + */ +schema NpProject extends NpProjectDO { + +} +impl NpProject { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpProject { + for (tmp in NpProjectDO(db)) { + for (np in NpProjectDO(db)) { + if (tmp = np) { + yield NpProject { + element_hash_id : tmp.element_hash_id, + extension : tmp.extension, + name : tmp.name + } + } + } + } + } +} +/** + * @brief Represents a non-physical file, suck as an class file in NpProject. + */ +schema NpFile extends NpFileDO { + +} +impl NpFile { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpFile { + for (tmp in NpFileDO(db)) { + for (nf in NpFileDO(db)) { + if (tmp = nf) { + yield NpFile { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + name : tmp.name, + project_hash_id : tmp.project_hash_id + } + } + } + } + } + /** + * @brief gets the np_project of this file. + * @return ElementParent + */ + pub fn getNpProject(self) -> NpProject { + for (project in NpProject(__all_data__)) { + if (project.element_hash_id = self.getProjectHashId()) { + return project + } + } + } +} diff --git a/language/java/lib/DOClass.gdl b/language/java/lib/DOClass.gdl new file mode 100644 index 00000000..2507a907 --- /dev/null +++ b/language/java/lib/DOClass.gdl @@ -0,0 +1,5340 @@ +/** + * @brief DO class: Describe an annotated relation. + */ +schema AnnotatedRelationDO { + @primary annotation_hash_id: int, + annotated_item_hash_id: int +} +impl AnnotatedRelationDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotatedRelationDO { + for (tmp in db.annotated_relation) { + yield AnnotatedRelationDO { + annotation_hash_id : tmp.annotation_hash_id, + annotated_item_hash_id : tmp.annotated_item_hash_id + } + } + } + /** + * @brief gets the annotated item hash id of this element. + * @return int + */ + pub fn getAnnotatedItemHashId(self) -> int { + return self.annotated_item_hash_id + } +} +/** + * @brief DO class: An argument with name that applies to an annotation. + */ +schema AnnotationAccessArgumentWithNameDO { + @primary element_hash_id: int, + annotation_access_hash_id: int, + type_hash_id: int, + argument_value_hash_id: int, + location_hash_id: int, + index_order: int, + printable_text: string +} +impl AnnotationAccessArgumentWithNameDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationAccessArgumentWithNameDO { + for (tmp in db.annotation_access_argument_with_name) { + yield AnnotationAccessArgumentWithNameDO { + element_hash_id : tmp.element_hash_id, + annotation_access_hash_id : tmp.annotation_access_hash_id, + type_hash_id : tmp.type_hash_id, + argument_value_hash_id : tmp.argument_value_hash_id, + location_hash_id : tmp.location_hash_id, + index_order : tmp.index_order, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the annotation access hash id of this element. + * @return int + */ + pub fn getAnnotationAccessHashId(self) -> int { + return self.annotation_access_hash_id + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } + /** + * @brief gets the argument value hash id of this element. + * @return int + */ + pub fn getArgumentValueHashId(self) -> int { + return self.argument_value_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An annotation access argument without name. + */ +schema AnnotationAccessArgumentWithoutNameDO { + @primary element_hash_id: int, + annotation_access_hash_id: int, + argument_value_hash_id: int, + location_hash_id: int, + index_order: int, + printable_text: string +} +impl AnnotationAccessArgumentWithoutNameDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationAccessArgumentWithoutNameDO { + for (tmp in db.annotation_access_argument_without_name) { + yield AnnotationAccessArgumentWithoutNameDO { + element_hash_id : tmp.element_hash_id, + annotation_access_hash_id : tmp.annotation_access_hash_id, + argument_value_hash_id : tmp.argument_value_hash_id, + location_hash_id : tmp.location_hash_id, + index_order : tmp.index_order, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the annotation access hash id of this element. + * @return int + */ + pub fn getAnnotationAccessHashId(self) -> int { + return self.annotation_access_hash_id + } + /** + * @brief gets the argument value hash id of this element. + * @return int + */ + pub fn getArgumentValueHashId(self) -> int { + return self.argument_value_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An annotation array initializer. + */ +schema AnnotationArrayInitializerDO { + @primary element_hash_id: int, + printable_text: string, + parent_hash_id: int, + location_hash_id: int +} +impl AnnotationArrayInitializerDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationArrayInitializerDO { + for (tmp in db.annotation_array_initializer) { + yield AnnotationArrayInitializerDO { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: An annotation can not resolved. + */ +schema AnnotationCanNotResolvedDO { + @primary element_hash_id: int, + name: string, + location_hash_id: int, + printable_text: string, + parent_hash_id: int +} +impl AnnotationCanNotResolvedDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationCanNotResolvedDO { + for (tmp in db.annotation_can_not_resolved) { + yield AnnotationCanNotResolvedDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: An annotation can resolved. + */ +schema AnnotationCanResolvedDO { + @primary element_hash_id: int, + name: string, + annotation_declaration_hash_id: int, + location_hash_id: int, + printable_text: string, + parent_hash_id: int +} +impl AnnotationCanResolvedDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationCanResolvedDO { + for (tmp in db.annotation_can_resolved) { + yield AnnotationCanResolvedDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + annotation_declaration_hash_id : tmp.annotation_declaration_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the annotation declaration hash id of this element. + * @return int + */ + pub fn getAnnotationDeclarationHashId(self) -> int { + return self.annotation_declaration_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: An annotation declaration. + */ +schema AnnotationDeclarationDO { + @primary element_hash_id: int, + qualified_name: string +} +impl AnnotationDeclarationDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationDeclarationDO { + for (tmp in db.annotation_declaration) { + yield AnnotationDeclarationDO { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name + } + } + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } +} +/** + * @brief DO class: An annotation declaration parameter. + */ +schema AnnotationDeclarationParameterDO { + @primary element_hash_id: int, + annotation_declaration_hash_id: int, + type_hash_id: int, + parameter_value_hash_id: int, + location_hash_id: int, + printable_text: string +} +impl AnnotationDeclarationParameterDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationDeclarationParameterDO { + for (tmp in db.annotation_declaration_parameter) { + yield AnnotationDeclarationParameterDO { + element_hash_id : tmp.element_hash_id, + annotation_declaration_hash_id : tmp.annotation_declaration_hash_id, + type_hash_id : tmp.type_hash_id, + parameter_value_hash_id : tmp.parameter_value_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the annotation declaration hash id of this element. + * @return int + */ + pub fn getAnnotationDeclarationHashId(self) -> int { + return self.annotation_declaration_hash_id + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } + /** + * @brief gets the parameter value hash id of this element. + * @return int + */ + pub fn getParameterValueHashId(self) -> int { + return self.parameter_value_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: Default value for an annotation parameter, if any. + */ +schema AnnotationDeclarationParameterDefaultValueDO { + @primary element_hash_id: int, + default_value: string +} +impl AnnotationDeclarationParameterDefaultValueDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnnotationDeclarationParameterDefaultValueDO { + for (tmp in db.annotation_declaration_parameter_default_value) { + yield AnnotationDeclarationParameterDefaultValueDO { + element_hash_id : tmp.element_hash_id, + default_value : tmp.default_value + } + } + } + /** + * @brief gets the default value of this element. + * @return string + */ + pub fn getDefaultValue(self) -> string { + return self.default_value + } +} +/** + * @brief DO class: An anonymous class. + */ +schema AnonymousClassDO { + @primary element_hash_id: int, + base_class_reference_hash_id: int, + base_class_type_hash_id: int, + location_hash_id: int, + parent_hash_id: int +} +impl AnonymousClassDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AnonymousClassDO { + for (tmp in db.anonymous_class) { + yield AnonymousClassDO { + element_hash_id : tmp.element_hash_id, + base_class_reference_hash_id : tmp.base_class_reference_hash_id, + base_class_type_hash_id : tmp.base_class_type_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the reference element id specifying the base class for the anonymous class. + * @return int + */ + pub fn getBaseClassReferenceHashId(self) -> int { + return self.base_class_reference_hash_id + } + /** + * @brief gets the base class type hash id of this element. + * @return int + */ + pub fn getBaseClassTypeHashId(self) -> int { + return self.base_class_type_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: An array. + */ +schema ArrayDO { + @primary element_hash_id: int, + name: string +} +impl ArrayDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ArrayDO { + for (tmp in db.array) { + yield ArrayDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: An array access expression. + */ +schema ArrayAccessExpressionDO { + @primary element_hash_id: int, + index_expression_hash_id: int, + array_expression_hash_id: int +} +impl ArrayAccessExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ArrayAccessExpressionDO { + for (tmp in db.array_access_expression) { + yield ArrayAccessExpressionDO { + element_hash_id : tmp.element_hash_id, + index_expression_hash_id : tmp.index_expression_hash_id, + array_expression_hash_id : tmp.array_expression_hash_id + } + } + } + /** + * @brief gets the index expression hash id of this element. + * @return int + */ + pub fn getIndexExpressionHashId(self) -> int { + return self.index_expression_hash_id + } + /** + * @brief gets the array expression hash id of this element. + * @return int + */ + pub fn getArrayExpressionHashId(self) -> int { + return self.array_expression_hash_id + } +} + /** + * + * @brief DO class: An array creation expression. + * For example, an expression such as `new String[2][3]` or + * `new String[][] { { "a", "b", "c" } , { "d", "e", "f" } }`. + * + * In both examples, `String` is the type name. In the first + * example, `2` and `3` are the 0th and 1st dimensions, + * respectively. In the second example, + * `{ { "a", "b", "c" } , { "d", "e", "f" } }` is the initializer. + */ +schema ArrayCreationExpressionDO { + @primary element_hash_id: int, + number_of_array_dimension: int, + type_hash_id: int +} +impl ArrayCreationExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ArrayCreationExpressionDO { + for (tmp in db.array_creation_expression) { + yield ArrayCreationExpressionDO { + element_hash_id : tmp.element_hash_id, + number_of_array_dimension : tmp.number_of_array_dimension, + type_hash_id : tmp.type_hash_id + } + } + } + /** + * @brief gets the number of array dimension of this element. + * @return int + */ + pub fn getNumberOfArrayDimension(self) -> int { + return self.number_of_array_dimension + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } +} +/** + * @brief DO class: An array initializer expression. + */ +schema ArrayInitializerExpressionDO { + @primary element_hash_id: int, + type_hash_id: int +} +impl ArrayInitializerExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ArrayInitializerExpressionDO { + for (tmp in db.array_initializer_expression) { + yield ArrayInitializerExpressionDO { + element_hash_id : tmp.element_hash_id, + type_hash_id : tmp.type_hash_id + } + } + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } +} +/** + * @brief DO class: An assert statement. + */ +schema AssertStatementDO { + @primary element_hash_id: int, + assert_condition_hash_id: int, + assert_description_hash_id: int +} +impl AssertStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AssertStatementDO { + for (tmp in db.assert_statement) { + yield AssertStatementDO { + element_hash_id : tmp.element_hash_id, + assert_condition_hash_id : tmp.assert_condition_hash_id, + assert_description_hash_id : tmp.assert_description_hash_id + } + } + } + /** + * @brief gets the assert condition hash id of this element. + * @return int + */ + pub fn getAssertConditionHashId(self) -> int { + return self.assert_condition_hash_id + } + /** + * @brief gets the assert description hash id of this element. + * @return int + */ + pub fn getAssertDescriptionHashId(self) -> int { + return self.assert_description_hash_id + } +} +/** + * @brief DO class: An assignment expression. + */ +schema AssignmentExpressionDO { + @primary element_hash_id: int, + lhs_hash_id: int, + rhs_hash_id: int, + opcode: string +} +impl AssignmentExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AssignmentExpressionDO { + for (tmp in db.assignment_expression) { + yield AssignmentExpressionDO { + element_hash_id : tmp.element_hash_id, + lhs_hash_id : tmp.lhs_hash_id, + rhs_hash_id : tmp.rhs_hash_id, + opcode : tmp.opcode + } + } + } + /** + * @brief gets the expression id on the left side of the assignment. + * @return int + */ + pub fn getLhsHashId(self) -> int { + return self.lhs_hash_id + } + /** + * @brief gets the expression id on the right side of the assignment. + * @return int + */ + pub fn getRhsHashId(self) -> int { + return self.rhs_hash_id + } + /** + * @brief gets the operation token of the assignment. + * @return string + */ + pub fn getOpcode(self) -> string { + return self.opcode + } +} +/** + * @brief DO class: A binary expression. + */ +schema BinaryExpressionDO { + @primary element_hash_id: int, + lhs_hash_id: int, + rhs_hash_id: int, + opcode: string +} +impl BinaryExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *BinaryExpressionDO { + for (tmp in db.binary_expression) { + yield BinaryExpressionDO { + element_hash_id : tmp.element_hash_id, + lhs_hash_id : tmp.lhs_hash_id, + rhs_hash_id : tmp.rhs_hash_id, + opcode : tmp.opcode + } + } + } + /** + * @brief gets the lhs hash id of this element. + * @return int + */ + pub fn getLhsHashId(self) -> int { + return self.lhs_hash_id + } + /** + * @brief gets the rhs hash id of this element. + * @return int + */ + pub fn getRhsHashId(self) -> int { + return self.rhs_hash_id + } + /** + * @brief gets the opcode of this element. + * @return string + */ + pub fn getOpcode(self) -> string { + return self.opcode + } +} +/** + * @brief DO class: A block statement (sequence of statements surrounded with curly braces). + */ +schema BlockStatementDO { + @primary element_hash_id: int, + code_block_hash_id: int +} +impl BlockStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *BlockStatementDO { + for (tmp in db.block_statement) { + yield BlockStatementDO { + element_hash_id : tmp.element_hash_id, + code_block_hash_id : tmp.code_block_hash_id + } + } + } + /** + * @brief gets the code block hash id of this element. + * @return int + */ + pub fn getCodeBlockHashId(self) -> int { + return self.code_block_hash_id + } +} +/** + * @brief DO class: A boolean literal. + */ +schema BooleanLiteralDO { + @primary element_hash_id: int, + value: string +} +impl BooleanLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *BooleanLiteralDO { + for (tmp in db.boolean_literal) { + yield BooleanLiteralDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A break statement. + */ +schema BreakStatementDO { + @primary element_hash_id: int, + exited_statement_hash_id: int +} +impl BreakStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *BreakStatementDO { + for (tmp in db.break_statement) { + yield BreakStatementDO { + element_hash_id : tmp.element_hash_id, + exited_statement_hash_id : tmp.exited_statement_hash_id + } + } + } + /** + * @brief gets the exited statement hash id of this element. + * @return int + */ + pub fn getExitedStatementHashId(self) -> int { + return self.exited_statement_hash_id + } +} +/** + * @brief DO class: A callable binding relation between caller and callee. + */ +schema CallableBindingDO { + @primary caller_hash_id: int, + callee_hash_id: int +} +impl CallableBindingDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CallableBindingDO { + for (tmp in db.callable_binding) { + yield CallableBindingDO { + caller_hash_id : tmp.caller_hash_id, + callee_hash_id : tmp.callee_hash_id + } + } + } + /** + * @brief gets the target callable id of this call. + * @return int + */ + pub fn getCalleeHashId(self) -> int { + return self.callee_hash_id + } +} +/** + * @brief DO class: Describe a expression enclosed by a certain callable. + */ +schema CallableEnclosingExpressionDO { + @primary expression_hash_id: int, + callable_hash_id: int +} +impl CallableEnclosingExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CallableEnclosingExpressionDO { + for (tmp in db.callable_enclosing_expression) { + yield CallableEnclosingExpressionDO { + expression_hash_id : tmp.expression_hash_id, + callable_hash_id : tmp.callable_hash_id + } + } + } + /** + * @brief gets the callable hash id of this element. + * @return int + */ + pub fn getCallableHashId(self) -> int { + return self.callable_hash_id + } +} +/** + * @brief DO class: Describe a statement enclosed by a certain callable. + */ +schema CallableEnclosingStatementDO { + @primary statement_hash_id: int, + callable_hash_id: int +} +impl CallableEnclosingStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CallableEnclosingStatementDO { + for (tmp in db.callable_enclosing_statement) { + yield CallableEnclosingStatementDO { + statement_hash_id : tmp.statement_hash_id, + callable_hash_id : tmp.callable_hash_id + } + } + } + /** + * @brief gets the callable hash id of this element. + * @return int + */ + pub fn getCallableHashId(self) -> int { + return self.callable_hash_id + } +} +/** + * @brief DO class: A catch section. + */ +schema CatchSectionDO { + @primary element_hash_id: int, + printable_text: string, + parameter_hash_id: int, + type_hash_id: int, + location_hash_id: int, + try_statement_hash_id: int, + index_order: int +} +impl CatchSectionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CatchSectionDO { + for (tmp in db.catch_section) { + yield CatchSectionDO { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parameter_hash_id : tmp.parameter_hash_id, + type_hash_id : tmp.type_hash_id, + location_hash_id : tmp.location_hash_id, + try_statement_hash_id : tmp.try_statement_hash_id, + index_order : tmp.index_order + } + } + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parameter hash id of this element. + * @return int + */ + pub fn getParameterHashId(self) -> int { + return self.parameter_hash_id + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the try statement hash id of this element. + * @return int + */ + pub fn getTryStatementHashId(self) -> int { + return self.try_statement_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } +} +/** + * @brief DO class: A character literal. + */ +schema CharacterLiteralDO { + @primary element_hash_id: int, + value: string +} +impl CharacterLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CharacterLiteralDO { + for (tmp in db.character_literal) { + yield CharacterLiteralDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A class. + */ +schema ClassDO { + @primary element_hash_id: int, + qualified_name: string, + identifier_hash_id: int, + location_hash_id: int, + parent_hash_id: int +} +impl ClassDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ClassDO { + for (tmp in db.class) { + yield ClassDO { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } + /** + * @brief gets the identifier hash id of this element. + * @return int + */ + pub fn getIdentifierHashId(self) -> int { + return self.identifier_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: Represents the class hierarchy of all classes. + */ +schema ClassHierarchyDO { + @primary child_hash_id: int, + parent_hash_id: int +} +impl ClassHierarchyDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ClassHierarchyDO { + for (tmp in db.class_hierarchy) { + yield ClassHierarchyDO { + child_hash_id : tmp.child_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: A class implement list. + */ +schema ClassImplementListDO { + @primary element_hash_id: int, + implemented_element_hash_id: int +} +impl ClassImplementListDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ClassImplementListDO { + for (tmp in db.class_implement_list) { + yield ClassImplementListDO { + element_hash_id : tmp.element_hash_id, + implemented_element_hash_id : tmp.implemented_element_hash_id + } + } + } + /** + * @brief gets the implemented element hash id of this element. + * @return int + */ + pub fn getImplementedElementHashId(self) -> int { + return self.implemented_element_hash_id + } +} +/** + * @brief DO class: A java class initializer block. + */ +schema ClassInitializerDO { + @primary element_hash_id: int, + printable_text: string, + parent_hash_id: int, + location_hash_id: int +} +impl ClassInitializerDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ClassInitializerDO { + for (tmp in db.class_initializer) { + yield ClassInitializerDO { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A code block. + */ +schema CodeBlockDO { + @primary element_hash_id: int, + number_of_statement: int, + parent_hash_id: int, + is_empty: int, + location_hash_id: int, + printable_text: string +} +impl CodeBlockDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CodeBlockDO { + for (tmp in db.code_block) { + yield CodeBlockDO { + element_hash_id : tmp.element_hash_id, + number_of_statement : tmp.number_of_statement, + parent_hash_id : tmp.parent_hash_id, + is_empty : tmp.is_empty, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the number of statement of this element. + * @return int + */ + pub fn getNumberOfStatement(self) -> int { + return self.number_of_statement + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the is empty of this element. + * @return int + */ + pub fn getIsEmpty(self) -> int { + return self.is_empty + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: A comment. + */ +schema CommentDO { + @primary element_hash_id: int, + text: string, + parent_hash_id: int, + location_hash_id: int, + comment_type: string +} +impl CommentDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CommentDO { + for (tmp in db.comment) { + yield CommentDO { + element_hash_id : tmp.element_hash_id, + text : tmp.text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + comment_type : tmp.comment_type + } + } + } + /** + * @brief gets the text of this element. + * @return string + */ + pub fn getText(self) -> string { + return self.text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the comment type of this element. + * @return string + */ + pub fn getCommentType(self) -> string { + return self.comment_type + } +} +/** + * @brief DO class: A conditional expression. + */ +schema ConditionalExpressionDO { + @primary element_hash_id: int, + condition_expression_hash_id: int, + then_part_hash_id: int, + else_part_hash_id: int +} +impl ConditionalExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ConditionalExpressionDO { + for (tmp in db.conditional_expression) { + yield ConditionalExpressionDO { + element_hash_id : tmp.element_hash_id, + condition_expression_hash_id : tmp.condition_expression_hash_id, + then_part_hash_id : tmp.then_part_hash_id, + else_part_hash_id : tmp.else_part_hash_id + } + } + } + /** + * @brief gets the condition expression hash id of this element. + * @return int + */ + pub fn getConditionExpressionHashId(self) -> int { + return self.condition_expression_hash_id + } + /** + * @brief gets the expression id which is the result used when the condition is true. + * @return int + */ + pub fn getThenPartHashId(self) -> int { + return self.then_part_hash_id + } + /** + * @brief gets the expression id which is the result used when the condition is false. + * @return int + */ + pub fn getElsePartHashId(self) -> int { + return self.else_part_hash_id + } +} +/** + * @brief DO class: A constructor. + */ +schema ConstructorDO { + @primary element_hash_id: int, + name: string, + signature: string, + parent_hash_id: int, + location_hash_id: int, + definition_body: string +} +impl ConstructorDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ConstructorDO { + for (tmp in db.constructor) { + yield ConstructorDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + signature : tmp.signature, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + definition_body : tmp.definition_body + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the signature of this element. + * @return string + */ + pub fn getSignature(self) -> string { + return self.signature + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + pub fn getDefinitionBody(self) -> string { + return self.definition_body + } +} +/** + * @brief DO class: A constructor invocation. + */ +schema ConstructorInvocationDO { + @primary element_hash_id: int, + class_reference_hash_id: int +} +impl ConstructorInvocationDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ConstructorInvocationDO { + for (tmp in db.constructor_invocation) { + yield ConstructorInvocationDO { + element_hash_id : tmp.element_hash_id, + class_reference_hash_id : tmp.class_reference_hash_id + } + } + } + /** + * @brief gets the class reference hash id of this element. + * @return int + */ + pub fn getClassReferenceHashId(self) -> int { + return self.class_reference_hash_id + } +} +/** + * @brief DO class: Describe a file belonged to a certain folder. + */ +schema ContainerParentDO { + @primary child_hash_id: int, + parent_hash_id: int +} +impl ContainerParentDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ContainerParentDO { + for (tmp in db.container_parent) { + yield ContainerParentDO { + child_hash_id : tmp.child_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: A continue statement. + */ +schema ContinueStatementDO { + @primary element_hash_id: int, + continued_statement_hash_id: int +} +impl ContinueStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ContinueStatementDO { + for (tmp in db.continue_statement) { + yield ContinueStatementDO { + element_hash_id : tmp.element_hash_id, + continued_statement_hash_id : tmp.continued_statement_hash_id + } + } + } + /** + * @brief gets the continued statement hash id of this element. + * @return int + */ + pub fn getContinuedStatementHashId(self) -> int { + return self.continued_statement_hash_id + } +} +/** + * @brief DO class: A compilation unit and its declared package. + */ +schema CupackageDO { + @primary file_hash_id: int, + package_hash_id: int +} +impl CupackageDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CupackageDO { + for (tmp in db.cupackage) { + yield CupackageDO { + file_hash_id : tmp.file_hash_id, + package_hash_id : tmp.package_hash_id + } + } + } + /** + * @brief gets the package hash id of this element. + * @return int + */ + pub fn getPackageHashId(self) -> int { + return self.package_hash_id + } +} +/** + * @brief DO class: A declaration element. + */ +schema DeclarationElementDO { + @primary element_hash_id: int, + index_order: int, + declaration_statement_hash_id: int +} +impl DeclarationElementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DeclarationElementDO { + for (tmp in db.declaration_element) { + yield DeclarationElementDO { + element_hash_id : tmp.element_hash_id, + index_order : tmp.index_order, + declaration_statement_hash_id : tmp.declaration_statement_hash_id + } + } + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the declaration statement hash id of this element. + * @return int + */ + pub fn getDeclarationStatementHashId(self) -> int { + return self.declaration_statement_hash_id + } +} +/** + * @brief DO class: A do while statement. + */ +schema DoWhileStatementDO { + @primary element_hash_id: int, + keyword: string, + condition_hash_id: int, + body_declaration_hash_id: int +} +impl DoWhileStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DoWhileStatementDO { + for (tmp in db.do_while_statement) { + yield DoWhileStatementDO { + element_hash_id : tmp.element_hash_id, + keyword : tmp.keyword, + condition_hash_id : tmp.condition_hash_id, + body_declaration_hash_id : tmp.body_declaration_hash_id + } + } + } + /** + * @brief gets the keyword of this element. + * @return string + */ + pub fn getKeyword(self) -> string { + return self.keyword + } + /** + * @brief gets the condition hash id of this element. + * @return int + */ + pub fn getConditionHashId(self) -> int { + return self.condition_hash_id + } + /** + * @brief gets the body declaration hash id of this element. + * @return int + */ + pub fn getBodyDeclarationHashId(self) -> int { + return self.body_declaration_hash_id + } +} +/** + * @brief DO class: A double literal. For example, "1.5". + */ +schema DoubleLiteralDO { + @primary element_hash_id: int, + value: string +} +impl DoubleLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DoubleLiteralDO { + for (tmp in db.double_literal) { + yield DoubleLiteralDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: An element. + */ +schema ElementDO { + @primary element_hash_id: int, + type: string, + parent_id: int, + parent_type: string +} +impl ElementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ElementDO { + for (tmp in db.element) { + yield ElementDO { + element_hash_id : tmp.element_hash_id, + type : tmp.type, + parent_id : tmp.parent_id, + parent_type : tmp.parent_type + } + } + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } + /** + * @brief gets the parent id of this element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the parent type of this element. + * @return string + */ + pub fn getParentType(self) -> string { + return self.parent_type + } +} +/** + * @brief DO class: An empty reference parameter list, like "<>". + */ +schema EmptyReferenceParameterListDO { + @primary list_hash_id: int, + parent_hash_id: int, + printable_text: string, + location_hash_id: int +} +impl EmptyReferenceParameterListDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *EmptyReferenceParameterListDO { + for (tmp in db.empty_reference_parameter_list) { + yield EmptyReferenceParameterListDO { + list_hash_id : tmp.list_hash_id, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: An empty statement. + */ +schema EmptyStatementDO { + @primary element_hash_id: int +} +impl EmptyStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *EmptyStatementDO { + for (tmp in db.empty_statement) { + yield EmptyStatementDO { + element_hash_id : tmp.element_hash_id + } + } + } +} +/** + * @brief DO class: An enum constant. + */ +schema EnumConstantDO { + @primary element_hash_id: int, + name: string, + parent_hash_id: int, + location_hash_id: int, + printable_text: string +} +impl EnumConstantDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *EnumConstantDO { + for (tmp in db.enum_constant) { + yield EnumConstantDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An exception. + */ +schema ExceptionDO { + @primary element_hash_id: int, + type_hash_id: int, + callable_hash_id: int, + name: string +} +impl ExceptionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExceptionDO { + for (tmp in db.exception) { + yield ExceptionDO { + element_hash_id : tmp.element_hash_id, + type_hash_id : tmp.type_hash_id, + callable_hash_id : tmp.callable_hash_id, + name : tmp.name + } + } + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } + /** + * @brief gets the callable hash id of this element. + * @return int + */ + pub fn getCallableHashId(self) -> int { + return self.callable_hash_id + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: A common super-class that represents all kinds of expressions. + */ +schema ExpressionDO { + @primary element_hash_id: int, + name: string, + parent_hash_id: int, + index_order: int, + location_hash_id: int, + printable_text: string +} +impl ExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionDO { + for (tmp in db.expression) { + yield ExpressionDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} + /** + * @brief DO class: A list of expression separated by commas. + */ +schema ExpressionListDO { + @primary element_hash_id: int, + parent_hash_id: int, + location_hash_id: int, + printable_text: string, + size: int +} +impl ExpressionListDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionListDO { + for (tmp in db.expression_list) { + yield ExpressionListDO { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + size : tmp.size + } + } + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + pub fn getSize(self) -> int { + return self.size + } +} +/** + * @brief DO class: Reference relation between expression list to its contained expression. + */ +schema ExpressionListExpressionRelationDO { + expression_list_hash_id: int, + @primary expression_hash_id: int, + position: int +} +impl ExpressionListExpressionRelationDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionListExpressionRelationDO { + for (tmp in db.expression_list_expression_relation) { + yield ExpressionListExpressionRelationDO { + expression_list_hash_id : tmp.expression_list_hash_id, + expression_hash_id : tmp.expression_hash_id, + position : tmp.position + } + } + } + /** + * @brief gets the expression hash id of this element. + * @return int + */ + pub fn getExpressionHashId(self) -> int { + return self.expression_hash_id + } + /** + * @brief gets the expression list hash id of this element. + * @return int + */ + pub fn getExpressionListHashId(self) -> int { + return self.expression_list_hash_id + } + pub fn getPosition(self) -> int { + return self.position + } +} +/** + * @brief DO class: An expression statement. + */ +schema ExpressionStatementDO { + @primary element_hash_id: int, + expression_hash_id: int +} +impl ExpressionStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionStatementDO { + for (tmp in db.expression_statement) { + yield ExpressionStatementDO { + element_hash_id : tmp.element_hash_id, + expression_hash_id : tmp.expression_hash_id + } + } + } + /** + * @brief gets the expression hash id of this element. + * @return int + */ + pub fn getExpressionHashId(self) -> int { + return self.expression_hash_id + } +} +/** + * @brief DO class: A field. + */ +schema FieldDO { + @primary element_hash_id: int, + name: string, + parent_hash_id: int, + printable_text: string, + location_hash_id: int +} +impl FieldDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *FieldDO { + for (tmp in db.field) { + yield FieldDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A file. + */ +schema FileDO { + @primary element_hash_id: int, + qualified_name: string, + extension: string, + name: string, + number_of_lines_hash_id: int +} +impl FileDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *FileDO { + for (tmp in db.file) { + yield FileDO { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + extension : tmp.extension, + name : tmp.name, + number_of_lines_hash_id : tmp.number_of_lines_hash_id + } + } + } + /** + * @brief gets the relative path of this element. + * @return string + */ + pub fn getRelativePath(self) -> string { + return self.qualified_name + } + /** + * @brief gets the extension of this element. + * @return string + */ + pub fn getExtension(self) -> string { + return self.extension + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the number of lines hash id of this element. + * @return int + */ + pub fn getNumberOfLinesHashId(self) -> int { + return self.number_of_lines_hash_id + } +} +/** + * @brief DO class: A file's md5sum value. + */ +schema FileMd5SumDO { + @primary file_hash_id: int, + value: string +} +impl FileMd5SumDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *FileMd5SumDO { + for (tmp in db.file_md5_sum) { + yield FileMd5SumDO { + file_hash_id : tmp.file_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A file's sha256 value. + */ +schema FileSha256SumDO { + @primary file_hash_id: int, + value: string +} +impl FileSha256SumDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *FileSha256SumDO { + for (tmp in db.file_sha256_sum) { + yield FileSha256SumDO { + file_hash_id : tmp.file_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A floating point literal, for example, "1.5f". + */ +schema FloatingPointLiteralDO { + @primary element_hash_id: int, + value: string +} +impl FloatingPointLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *FloatingPointLiteralDO { + for (tmp in db.floating_point_literal) { + yield FloatingPointLiteralDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A folder. + */ +schema FolderDO { + @primary element_hash_id: int, + qualified_name: string, + name: string, + parent_hash_id: int +} +impl FolderDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *FolderDO { + for (tmp in db.folder) { + yield FolderDO { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getRelativePath(self) -> string { + return self.qualified_name + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: A for statement. + */ +schema ForStatementDO { + @primary element_hash_id: int, + initialization_hash_id: int, + condition_hash_id: int, + update_hash_id: int, + body_hash_id: int +} +impl ForStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ForStatementDO { + for (tmp in db.for_statement) { + yield ForStatementDO { + element_hash_id : tmp.element_hash_id, + initialization_hash_id : tmp.initialization_hash_id, + condition_hash_id : tmp.condition_hash_id, + update_hash_id : tmp.update_hash_id, + body_hash_id : tmp.body_hash_id + } + } + } + /** + * @brief gets the initialization hash id of this element. + * @return int + */ + pub fn getInitializationHashId(self) -> int { + return self.initialization_hash_id + } + /** + * @brief gets the condition hash id of this element. + * @return int + */ + pub fn getConditionHashId(self) -> int { + return self.condition_hash_id + } + /** + * @brief gets the update hash id of this element. + * @return int + */ + pub fn getUpdateHashId(self) -> int { + return self.update_hash_id + } + /** + * @brief gets the body hash id of this element. + * @return int + */ + pub fn getBodyHashId(self) -> int { + return self.body_hash_id + } +} +/** + * @brief DO class: A foreach statement. + */ +schema ForeachStatementDO { + @primary element_hash_id: int, + iterated_value_hash_id: int, + iteration_parameter_hash_id: int, + body_hash_id: int +} +impl ForeachStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ForeachStatementDO { + for (tmp in db.foreach_statement) { + yield ForeachStatementDO { + element_hash_id : tmp.element_hash_id, + iterated_value_hash_id : tmp.iterated_value_hash_id, + iteration_parameter_hash_id : tmp.iteration_parameter_hash_id, + body_hash_id : tmp.body_hash_id + } + } + } + /** + * @brief gets the iterated value hash id of this element. + * @return int + */ + pub fn getIteratedValueHashId(self) -> int { + return self.iterated_value_hash_id + } + /** + * @brief gets the iteration parameter hash id of this element. + * @return int + */ + pub fn getIterationParameterHashId(self) -> int { + return self.iteration_parameter_hash_id + } + /** + * @brief gets the body hash id of this element. + * @return int + */ + pub fn getBodyHashId(self) -> int { + return self.body_hash_id + } +} +/** + * @brief DO class: An identifier. + */ +schema IdentifierDO { + @primary element_hash_id: int, + location_hash_id: int, + name: string, + parent_hash_id: int +} +impl IdentifierDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *IdentifierDO { + for (tmp in db.identifier) { + yield IdentifierDO { + element_hash_id : tmp.element_hash_id, + location_hash_id : tmp.location_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: An if statement with else. + */ +schema IfStatementWithElseDO { + @primary element_hash_id: int, + condition_hash_id: int, + consequent_hash_id: int, + alternate_hash_id: int +} +impl IfStatementWithElseDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *IfStatementWithElseDO { + for (tmp in db.if_statement_with_else) { + yield IfStatementWithElseDO { + element_hash_id : tmp.element_hash_id, + condition_hash_id : tmp.condition_hash_id, + consequent_hash_id : tmp.consequent_hash_id, + alternate_hash_id : tmp.alternate_hash_id + } + } + } + /** + * @brief gets the condition hash id of this element. + * @return int + */ + pub fn getConditionHashId(self) -> int { + return self.condition_hash_id + } + /** + * @brief gets the consequent hash id of this element. + * @return int + */ + pub fn getConsequentHashId(self) -> int { + return self.consequent_hash_id + } + /** + * @brief gets the alternate hash id of this element. + * @return int + */ + pub fn getAlternateHashId(self) -> int { + return self.alternate_hash_id + } +} +/** + * @brief DO class: An if statement without else. + */ +schema IfStatementWithoutElseDO { + @primary element_hash_id: int, + condition_hash_id: int, + consequent_hash_id: int +} +impl IfStatementWithoutElseDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *IfStatementWithoutElseDO { + for (tmp in db.if_statement_without_else) { + yield IfStatementWithoutElseDO { + element_hash_id : tmp.element_hash_id, + condition_hash_id : tmp.condition_hash_id, + consequent_hash_id : tmp.consequent_hash_id + } + } + } + /** + * @brief gets the condition hash id of this element. + * @return int + */ + pub fn getConditionHashId(self) -> int { + return self.condition_hash_id + } + /** + * @brief gets the consequent hash id of this element. + * @return int + */ + pub fn getConsequentHashId(self) -> int { + return self.consequent_hash_id + } +} +/** + * @brief DO class: An import. + */ +schema ImportDO { + @primary element_hash_id: int, + reference_hash_id: int, + name: string, + parent_hash_id: int, + location_hash_id: int, + is_foreign_import: int +} +impl ImportDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ImportDO { + for (tmp in db.import) { + yield ImportDO { + element_hash_id : tmp.element_hash_id, + reference_hash_id : tmp.reference_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + is_foreign_import : tmp.is_foreign_import + } + } + } + /** + * @brief gets the reference hash id of this element. + * @return int + */ + pub fn getReferenceHashId(self) -> int { + return self.reference_hash_id + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the is foreign import of this element. + * @return int + */ + pub fn getIsForeignImport(self) -> int { + return self.is_foreign_import + } +} +/** + * @brief DO class: An import static reference element. + */ +schema ImportStaticReferenceElementDO { + @primary element_hash_id: int, + printable_text: string, + parent_hash_id: int, + location_hash_id: int +} +impl ImportStaticReferenceElementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ImportStaticReferenceElementDO { + for (tmp in db.import_static_reference_element) { + yield ImportStaticReferenceElementDO { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: An import static statement. + */ +schema ImportStaticStatementDO { + @primary element_hash_id: int, + reference_hash_id: int, + name: string, + parent_hash_id: int, + location_hash_id: int +} +impl ImportStaticStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ImportStaticStatementDO { + for (tmp in db.import_static_statement) { + yield ImportStaticStatementDO { + element_hash_id : tmp.element_hash_id, + reference_hash_id : tmp.reference_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the reference hash id of this element. + * @return int + */ + pub fn getReferenceHashId(self) -> int { + return self.reference_hash_id + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: An instanceof expression. + */ +schema InstanceofExpressionDO { + @primary element_hash_id: int, + operand_hash_id: int, + check_type_hash_id: int, + pattern_hash_id: int +} +impl InstanceofExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *InstanceofExpressionDO { + for (tmp in db.instanceof_expression) { + yield InstanceofExpressionDO { + element_hash_id : tmp.element_hash_id, + operand_hash_id : tmp.operand_hash_id, + check_type_hash_id : tmp.check_type_hash_id, + pattern_hash_id : tmp.pattern_hash_id + } + } + } + /** + * @brief gets the operand hash id of this element. + * @return int + */ + pub fn getOperandHashId(self) -> int { + return self.operand_hash_id + } + /** + * @brief gets the check type hash id of this element. + * @return int + */ + pub fn getCheckTypeHashId(self) -> int { + return self.check_type_hash_id + } + /** + * @brief gets the pattern hash id of this element. + * @return int + */ + pub fn getPatternHashId(self) -> int { + return self.pattern_hash_id + } +} +/** + * @brief DO class: An integer literal, for example, "4". + */ +schema IntegerLiteralDO { + @primary element_hash_id: int, + value: string +} +impl IntegerLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *IntegerLiteralDO { + for (tmp in db.integer_literal) { + yield IntegerLiteralDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: An interface. + */ +schema InterfaceDO { + @primary element_hash_id: int, + qualified_name: string, + identifier_hash_id: int, + location_hash_id: int, + parent_hash_id: int +} +impl InterfaceDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *InterfaceDO { + for (tmp in db.interface) { + yield InterfaceDO { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + identifier_hash_id : tmp.identifier_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } + /** + * @brief gets the identifier hash id of this element. + * @return int + */ + pub fn getIdentifierHashId(self) -> int { + return self.identifier_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: A javadoc comment. + */ +schema JavadocCommentDO { + @primary element_hash_id: int, + documentable_hash_id: int, + text: string, + location_hash_id: int, + parent_hash_id: int +} +impl JavadocCommentDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JavadocCommentDO { + for (tmp in db.javadoc_comment) { + yield JavadocCommentDO { + element_hash_id : tmp.element_hash_id, + documentable_hash_id : tmp.documentable_hash_id, + text : tmp.text, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the documentable hash id of this element. + * @return int + */ + pub fn getDocumentableHashId(self) -> int { + return self.documentable_hash_id + } + /** + * @brief gets the text of this element. + * @return string + */ + pub fn getText(self) -> string { + return self.text + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: A javadoc tag. + */ +schema JavadocTagDO { + @primary element_hash_id: int, + name: string, + value: string, + containing_comment_hash_id: int, + index_order: int, + location_hash_id: int +} +impl JavadocTagDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JavadocTagDO { + for (tmp in db.javadoc_tag) { + yield JavadocTagDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + value : tmp.value, + containing_comment_hash_id : tmp.containing_comment_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the containing comment hash id of this element. + * @return int + */ + pub fn getContainingCommentHashId(self) -> int { + return self.containing_comment_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A javadoc tag value element. + */ +schema JavadocTagValueDO { + @primary element_hash_id: int, + value: string, + parent_hash_id: int, + location_hash_id: int +} +impl JavadocTagValueDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JavadocTagValueDO { + for (tmp in db.javadoc_tag_value) { + yield JavadocTagValueDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the containing comment hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A javadoc data token. + */ +schema JavadocDataTokenDO { + @primary element_hash_id: int, + value: string, + parent_hash_id: int, + index_order: int, + location_hash_id: int +} +impl JavadocDataTokenDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JavadocDataTokenDO { + for (tmp in db.javadoc_data_token) { + yield JavadocDataTokenDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A labeled statement. + */ +schema LabeledStatementDO { + @primary element_hash_id: int, + labeled_hash_identifier_hash_id: int, + statement_hash_id: int +} +impl LabeledStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LabeledStatementDO { + for (tmp in db.labeled_statement) { + yield LabeledStatementDO { + element_hash_id : tmp.element_hash_id, + labeled_hash_identifier_hash_id : tmp.labeled_hash_identifier_hash_id, + statement_hash_id : tmp.statement_hash_id + } + } + } + /** + * @brief gets the labeled hash identifier hash id of this element. + * @return int + */ + pub fn getLabeledHashIdentifierHashId(self) -> int { + return self.labeled_hash_identifier_hash_id + } + /** + * @brief gets the statement hash id of this element. + * @return int + */ + pub fn getStatementHashId(self) -> int { + return self.statement_hash_id + } +} +/** + * @brief DO class: A lambda expression. + */ +schema LambdaExpressionDO { + @primary element_hash_id: int, + parameter_list_hash_id: int, + body_hash_id: int, + is_void_compatible: int, + is_value_compatible: int +} +impl LambdaExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LambdaExpressionDO { + for (tmp in db.lambda_expression) { + yield LambdaExpressionDO { + element_hash_id : tmp.element_hash_id, + parameter_list_hash_id : tmp.parameter_list_hash_id, + body_hash_id : tmp.body_hash_id, + is_void_compatible : tmp.is_void_compatible, + is_value_compatible : tmp.is_value_compatible + } + } + } + /** + * @brief gets the parameter list hash id of this element. + * @return int + */ + pub fn getParameterListHashId(self) -> int { + return self.parameter_list_hash_id + } + /** + * @brief gets the body hash id of this element. + * @return int + */ + pub fn getBodyHashId(self) -> int { + return self.body_hash_id + } + /** + * @brief gets the is void compatible of this element. + * @return int + */ + pub fn getIsVoidCompatible(self) -> int { + return self.is_void_compatible + } + /** + * @brief gets the is value compatible of this element. + * @return int + */ + pub fn getIsValueCompatible(self) -> int { + return self.is_value_compatible + } +} +/** + * @brief DO class: A local class. + */ +schema LocalClassDO { + @primary element_hash_id: int, + name: string, + printable_text: string, + location_hash_id: int, + parent_hash_id: int +} +impl LocalClassDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LocalClassDO { + for (tmp in db.local_class) { + yield LocalClassDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: A local variable. + */ +schema LocalVariableDO { + @primary element_hash_id: int, + parent_hash_id: int, + location_hash_id: int, + printable_text: string, + name: string, + index_order: int +} +impl LocalVariableDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LocalVariableDO { + for (tmp in db.local_variable) { + yield LocalVariableDO { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + name : tmp.name, + index_order : tmp.index_order + } + } + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } +} +/** + * @brief DO class: The location information of a locatable elements. + */ +schema LocationDO { + @primary element_hash_id: int, + file_hash_id: int, + start_line_number: int, + start_column_number: int, + end_line_number: int, + end_column_number: int +} +impl LocationDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LocationDO { + for (tmp in db.location) { + yield LocationDO { + element_hash_id : tmp.element_hash_id, + file_hash_id : tmp.file_hash_id, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number + } + } + } + /** + * @brief gets the file hash id of this element. + * @return int + */ + pub fn getFileHashId(self) -> int { + return self.file_hash_id + } + /** + * @brief gets the start line number of this element. + * @return int + */ + pub fn getStartLineNumber(self) -> int { + return self.start_line_number + } + /** + * @brief gets the start column number of this element. + * @return int + */ + pub fn getStartColumnNumber(self) -> int { + return self.start_column_number + } + /** + * @brief gets the end line number of this element. + * @return int + */ + pub fn getEndLineNumber(self) -> int { + return self.end_line_number + } + /** + * @brief gets the end column number of this element. + * @return int + */ + pub fn getEndColumnNumber(self) -> int { + return self.end_column_number + } +} +/** + * @brief DO class: A long literal, for example, "15l". + */ +schema LongLiteralDO { + @primary element_hash_id: int, + value: string +} +impl LongLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LongLiteralDO { + for (tmp in db.long_literal) { + yield LongLiteralDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A metainfo. + */ +schema MetainfoDO { + @primary oid: int, + kind: string, + value: string, + program_hash_id: int +} +impl MetainfoDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MetainfoDO { + for (tmp in db.metainfo) { + yield MetainfoDO { + oid : tmp.oid, + kind : tmp.kind, + value : tmp.value, + program_hash_id : tmp.program_hash_id + } + } + } + /** + * @brief gets the kind of this element. + * @return string + */ + pub fn getKind(self) -> string { + return self.kind + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the program hash id of this element. + * @return int + */ + pub fn getProgramHashId(self) -> int { + return self.program_hash_id + } +} +/** + * @brief DO class: A method. + */ +schema MethodDO { + @primary element_hash_id: int, + name: string, + signature: string, + type_hash_id: int, + parent_hash_id: int, + location_hash_id: int, + definition_body: string +} +impl MethodDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MethodDO { + for (tmp in db.method) { + yield MethodDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + signature : tmp.signature, + type_hash_id : tmp.type_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + definition_body : tmp.definition_body + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the signature of this element. + * @return string + */ + pub fn getSignature(self) -> string { + return self.signature + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + pub fn getDefinitionBody(self) -> string { + return self.definition_body + } +} +/** + * @brief DO class: A method access expression with type. + */ +schema MethodAccessExpressionWithTypeDO { + @primary element_hash_id: int, + type_hash_id: int, + referen_method_hash_id: int, + argument_list_hash_id: int +} +impl MethodAccessExpressionWithTypeDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MethodAccessExpressionWithTypeDO { + for (tmp in db.method_access_expression_with_type) { + yield MethodAccessExpressionWithTypeDO { + element_hash_id : tmp.element_hash_id, + type_hash_id : tmp.type_hash_id, + referen_method_hash_id : tmp.referen_method_hash_id, + argument_list_hash_id : tmp.argument_list_hash_id + } + } + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } + /** + * @brief gets the referen method hash id of this element. + * @return int + */ + pub fn getReferenMethodHashId(self) -> int { + return self.referen_method_hash_id + } + /** + * @brief gets the argument list hash id of this element. + * @return int + */ + pub fn getArgumentListHashId(self) -> int { + return self.argument_list_hash_id + } +} +/** + * @brief DO class: A method access expression without type. + */ +schema MethodAccessExpressionWithoutTypeDO { + @primary element_hash_id: int, + referen_method_hash_id: int, + argument_list_hash_id: int +} +impl MethodAccessExpressionWithoutTypeDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MethodAccessExpressionWithoutTypeDO { + for (tmp in db.method_access_expression_without_type) { + yield MethodAccessExpressionWithoutTypeDO { + element_hash_id : tmp.element_hash_id, + referen_method_hash_id : tmp.referen_method_hash_id, + argument_list_hash_id : tmp.argument_list_hash_id + } + } + } + /** + * @brief gets the referen method hash id of this element. + * @return int + */ + pub fn getReferenMethodHashId(self) -> int { + return self.referen_method_hash_id + } + /** + * @brief gets the argument list hash id of this element. + * @return int + */ + pub fn getArgumentListHashId(self) -> int { + return self.argument_list_hash_id + } +} +/** + * @brief DO class: A method reference expression. + */ +schema MethodReferenceExpressionDO { + @primary element_hash_id: int, + is_constructor: int +} +impl MethodReferenceExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MethodReferenceExpressionDO { + for (tmp in db.method_reference_expression) { + yield MethodReferenceExpressionDO { + element_hash_id : tmp.element_hash_id, + is_constructor : tmp.is_constructor + } + } + } + /** + * @brief gets the is constructor of this element. + * @return int + */ + pub fn isConstructor(self) -> int { + return self.is_constructor + } +} +/** + * @brief DO class: A modifier. + */ +schema ModifierDO { + @primary element_hash_id: int, + name: string, + parent_hash_id: int, + location_hash_id: int +} +impl ModifierDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ModifierDO { + for (tmp in db.modifier) { + yield ModifierDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A list of modifiers and annotations on a java element (class, method, field and so on). + */ +schema ModifierListDO { + @primary element_hash_id: int, + parent_hash_id: int, + location_hash_id: int +} +impl ModifierListDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ModifierListDO { + for (tmp in db.modifier_list) { + yield ModifierListDO { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A module. + */ +schema ModuleDO { + @primary element_hash_id: int, + name: string +} +impl ModuleDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ModuleDO { + for (tmp in db.module) { + yield ModuleDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: Name and value for a named expression or statement, like break statement, labeled statement. + */ +schema NameStringDO { + @primary parent_hash_id: int, + name_element_hash_id: int, + value_element_hash_id: int +} +impl NameStringDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NameStringDO { + for (tmp in db.name_string) { + yield NameStringDO { + parent_hash_id : tmp.parent_hash_id, + name_element_hash_id : tmp.name_element_hash_id, + value_element_hash_id : tmp.value_element_hash_id + } + } + } + /** + * @brief gets the name element hash id of this element. + * @return int + */ + pub fn getNameElementHashId(self) -> int { + return self.name_element_hash_id + } + /** + * @brief gets the value element hash id of this element. + * @return int + */ + pub fn getValueElementHashId(self) -> int { + return self.value_element_hash_id + } +} +/** + * @brief DO class: A new expression. + */ +schema NewExpressionDO { + @primary element_hash_id: int, + reference_hash_id: int, + type_hash_id: int +} +impl NewExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NewExpressionDO { + for (tmp in db.new_expression) { + yield NewExpressionDO { + element_hash_id : tmp.element_hash_id, + reference_hash_id : tmp.reference_hash_id, + type_hash_id : tmp.type_hash_id + } + } + } + /** + * @brief gets the reference hash id of this element. + * @return int + */ + pub fn getReferenceHashId(self) -> int { + return self.reference_hash_id + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } +} +/** + * @brief DO class: A null literal, written "null". + */ +schema NullLiteralDO { + @primary element_hash_id: int, + value: string +} +impl NullLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NullLiteralDO { + for (tmp in db.null_literal) { + yield NullLiteralDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A number of lines. + */ +schema NumberOfLinesDO { + @primary element_hash_id: int, + number_of_total_lines: int, + number_of_valid_lines: int, + number_of_comment_lines: int +} +impl NumberOfLinesDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NumberOfLinesDO { + for (tmp in db.number_of_lines) { + yield NumberOfLinesDO { + element_hash_id : tmp.element_hash_id, + number_of_total_lines : tmp.number_of_total_lines, + number_of_valid_lines : tmp.number_of_valid_lines, + number_of_comment_lines : tmp.number_of_comment_lines + } + } + } + /** + * @brief gets the number of total lines of this element. + * @return int + */ + pub fn getNumberOfLines(self) -> int { + return self.number_of_total_lines + } + /** + * @brief gets the number of valid lines of this element. + * @return int + */ + pub fn getNumberOfLinesOfCode(self) -> int { + return self.number_of_valid_lines + } + /** + * @brief gets the number of comment lines of this element. + * @return int + */ + pub fn getNumberOfCommentLines(self) -> int { + return self.number_of_comment_lines + } +} +/** + * @brief DO class: A package statement. + */ +schema PackageStatementDO { + @primary element_hash_id: int, + qualified_name: string, + location_hash_id: int, + package_hash_id: int, + parent_hash_id: int +} +impl PackageStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *PackageStatementDO { + for (tmp in db.package_statement) { + yield PackageStatementDO { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + location_hash_id : tmp.location_hash_id, + package_hash_id : tmp.package_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the package hash id of this element. + * @return int + */ + pub fn getPackageHashId(self) -> int { + return self.package_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: A parameter of a method, foreach statement or catch block. + */ +schema ParameterDO { + @primary element_hash_id: int, + name: string, + index_order: int, + parent_hash_id: int, + location_hash_id: int, + printable_text: string, + type_hash_id: int +} +impl ParameterDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ParameterDO { + for (tmp in db.parameter) { + yield ParameterDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + index_order : tmp.index_order, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type_hash_id : tmp.type_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } +} +/** + * @brief DO class: A parent. + */ +schema ParentDO { + @primary parent_hash_id: int, + parent_type: string +} +impl ParentDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ParentDO { + for (tmp in db.parent) { + yield ParentDO { + parent_hash_id : tmp.parent_hash_id, + parent_type : tmp.parent_type + } + } + } + /** + * @brief gets the parent type of this element. + * @return string + */ + pub fn getParentType(self) -> string { + return self.parent_type + } +} +/** + * @brief DO class: A polyadic expression. + */ +schema PolyadicExpressionDO { + @primary element_hash_id: int, + size: int, + opcode: string +} +impl PolyadicExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *PolyadicExpressionDO { + for (tmp in db.polyadic_expression) { + yield PolyadicExpressionDO { + element_hash_id : tmp.element_hash_id, + size : tmp.size, + opcode : tmp.opcode + } + } + } + /** + * @brief gets the size of this element. + * @return int + */ + pub fn getSize(self) -> int { + return self.size + } + /** + * @brief gets the opcode of this element. + * @return string + */ + pub fn getOpcode(self) -> string { + return self.opcode + } +} +/** + * @brief DO class: A primitive type, includes "boolean", "byte", "short", "char", "int", "long", "float" and "double". + */ +schema PrimitiveDO { + @primary oid: int, + name: string +} +impl PrimitiveDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *PrimitiveDO { + for (tmp in db.primitive) { + yield PrimitiveDO { + oid : tmp.oid, + name : tmp.name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: The root of the extracted project. + */ +schema ProgramDO { + @primary program_hash_id: int, + absolute_prefix_path: string +} +impl ProgramDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ProgramDO { + for (tmp in db.program) { + yield ProgramDO { + program_hash_id : tmp.program_hash_id, + absolute_prefix_path : tmp.absolute_prefix_path + } + } + } + /** + * @brief gets the absolute prefix path of this element. + * @return string + */ + pub fn getAbsolutePrefixPath(self) -> string { + return self.absolute_prefix_path + } +} +/** + * @brief DO class: A reference in code (either an identifier or a sequence of identifiers separated by periods, optionally with generic type arguments) + */ +schema ReferenceElementDO { + @primary element_hash_id: int, + printable_text: string, + parent_hash_id: int, + location_hash_id: int +} +impl ReferenceElementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceElementDO { + for (tmp in db.reference_element) { + yield ReferenceElementDO { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A reference expression. + */ +schema ReferenceExpressionDO { + @primary element_hash_id: int +} +impl ReferenceExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceExpressionDO { + for (tmp in db.reference_expression) { + yield ReferenceExpressionDO { + element_hash_id : tmp.element_hash_id + } + } + } +} +/** + * @brief DO class: A reference list. + */ +schema ReferenceListDO { + @primary element_hash_id: int, + location_hash_id: int, + parent_hash_id: int, + printable_text: string, + role: string +} +impl ReferenceListDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceListDO { + for (tmp in db.reference_list) { + yield ReferenceListDO { + element_hash_id : tmp.element_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + role : tmp.role + } + } + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the role of this element. + * @return string + */ + pub fn getRole(self) -> string { + return self.role + } +} +/** + * @brief DO class: A reference parameter list. + */ +schema ReferenceParameterListDO { + type_element_hash_id: int, + @primary list_hash_id: int, + index_order: int, + parent_hash_id: int, + printable_text: string, + location_hash_id: int +} +impl ReferenceParameterListDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceParameterListDO { + for (tmp in db.reference_parameter_list) { + yield ReferenceParameterListDO { + type_element_hash_id : tmp.type_element_hash_id, + list_hash_id : tmp.list_hash_id, + index_order : tmp.index_order, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the type element of the list. + * @return int + */ + pub fn getTypeElementHashId(self) -> int { + return self.type_element_hash_id + } + /** + * @brief gets the list hash id of this element. + * @return int + */ + pub fn getListHashId(self) -> int { + return self.list_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: Reference relation between reference element to its resolved element. + */ +schema ReferenceRelationDO { + @primary reference_element_hash_id: int, + definition_element_hash_id: int +} +impl ReferenceRelationDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceRelationDO { + for (tmp in db.reference_relation) { + yield ReferenceRelationDO { + reference_element_hash_id : tmp.reference_element_hash_id, + definition_element_hash_id : tmp.definition_element_hash_id + } + } + } + /** + * @brief gets the definition element hash id of this element. + * @return int + */ + pub fn getDefinitionElementHashId(self) -> int { + return self.definition_element_hash_id + } + /** + * @brief gets the reference element id. + * @return int + */ + pub fn getSourceId(self) -> int { + return self.reference_element_hash_id + } +} +/** + * @brief DO class: A reference type. + */ +schema ReferenceTypeDO { + @primary oid: int, + name: string, + qualified_name: string +} +impl ReferenceTypeDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceTypeDO { + for (tmp in db.reference_type) { + yield ReferenceTypeDO { + oid : tmp.oid, + name : tmp.name, + qualified_name : tmp.qualified_name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } +} +/** + * @brief DO class: A resource list. + */ +schema ResourceListDO { + @primary element_hash_id: int, + printable_text: string, + parent_hash_id: int, + location_hash_id: int +} +impl ResourceListDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ResourceListDO { + for (tmp in db.resource_list) { + yield ResourceListDO { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A return statement. + */ +schema ReturnStatementDO { + @primary element_hash_id: int, + return_expression_hash_id: int +} +impl ReturnStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReturnStatementDO { + for (tmp in db.return_statement) { + yield ReturnStatementDO { + element_hash_id : tmp.element_hash_id, + return_expression_hash_id : tmp.return_expression_hash_id + } + } + } + /** + * @brief gets the return expression hash id of this element. + * @return int + */ + pub fn getReturnExpressionHashId(self) -> int { + return self.return_expression_hash_id + } +} +/** + * @brief DO class: A statement. + */ +schema StatementDO { + @primary element_hash_id: int, + parent_hash_id: int, + index_order: int, + location_hash_id: int, + printable_text: string, + type: string +} +impl StatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *StatementDO { + for (tmp in db.statement) { + yield StatementDO { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } +} +/** + * @brief DO class: Describe an expression enclosed by a certain statement. + */ +schema StatementEnclosingExpressionDO { + @primary expression_hash_id: int, + statement_hash_id: int +} +impl StatementEnclosingExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *StatementEnclosingExpressionDO { + for (tmp in db.statement_enclosing_expression) { + yield StatementEnclosingExpressionDO { + expression_hash_id : tmp.expression_hash_id, + statement_hash_id : tmp.statement_hash_id + } + } + } + /** + * @brief gets the statement hash id of this element. + * @return int + */ + pub fn getStatementHashId(self) -> int { + return self.statement_hash_id + } +} +/** + * @brief DO class: A string literal, for example "abc". + */ +schema StringLiteralDO { + @primary element_hash_id: int, + value: string +} +impl StringLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *StringLiteralDO { + for (tmp in db.string_literal) { + yield StringLiteralDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: An expression allows access to super-class members of an enclosing instance. For example, "A.super.x". + */ +schema SuperAccessExpressionDO { + @primary element_hash_id: int +} +impl SuperAccessExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SuperAccessExpressionDO { + for (tmp in db.super_access_expression) { + yield SuperAccessExpressionDO { + element_hash_id : tmp.element_hash_id + } + } + } +} +/** + * @brief DO class: An explicit `super(...)` constructor invocation statement. + */ +schema SuperConstructorInvocationDO { + @primary element_hash_id: int +} +impl SuperConstructorInvocationDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SuperConstructorInvocationDO { + for (tmp in db.super_constructor_invocation) { + yield SuperConstructorInvocationDO { + element_hash_id : tmp.element_hash_id + } + } + } +} +/** + * @brief DO class: A super expression. + */ +schema SuperExpressionDO { + @primary element_hash_id: int +} +impl SuperExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SuperExpressionDO { + for (tmp in db.super_expression) { + yield SuperExpressionDO { + element_hash_id : tmp.element_hash_id + } + } + } +} +/** + * @brief DO class: A super expression with qualifier. + */ +schema SuperExpressionWithQualifierDO { + @primary element_hash_id: int, + qualifier_hash_id: int +} +impl SuperExpressionWithQualifierDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SuperExpressionWithQualifierDO { + for (tmp in db.super_expression_with_qualifier) { + yield SuperExpressionWithQualifierDO { + element_hash_id : tmp.element_hash_id, + qualifier_hash_id : tmp.qualifier_hash_id + } + } + } + /** + * @brief gets the qualifier hash id of this element. + * @return int + */ + pub fn getQualifierHashId(self) -> int { + return self.qualifier_hash_id + } +} +/** + * @brief DO class: A switch label statement. + */ +schema SwitchLabelStatementDO { + @primary element_hash_id: int, + case_value_hash_id: int, + enclosing_switch_block_hash_id: int, + get_next_switch_case: int +} +impl SwitchLabelStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SwitchLabelStatementDO { + for (tmp in db.switch_label_statement) { + yield SwitchLabelStatementDO { + element_hash_id : tmp.element_hash_id, + case_value_hash_id : tmp.case_value_hash_id, + enclosing_switch_block_hash_id : tmp.enclosing_switch_block_hash_id, + get_next_switch_case : tmp.get_next_switch_case + } + } + } + /** + * @brief gets the case value hash id of this element. + * @return int + */ + pub fn getCaseValueHashId(self) -> int { + return self.case_value_hash_id + } + /** + * @brief gets the enclosing switch block hash id of this element. + * @return int + */ + pub fn getEnclosingSwitchBlockHashId(self) -> int { + return self.enclosing_switch_block_hash_id + } + /** + * @brief gets the next switch case id of the element, 0 means it's the last case. + * @return int + */ + pub fn getNext(self) -> int { + return self.get_next_switch_case + } +} +/** + * @brief DO class: A switch statement. + */ +schema SwitchStatementDO { + @primary element_hash_id: int, + discriminant_hash_id: int, + body_declaration_hash_id: int +} +impl SwitchStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SwitchStatementDO { + for (tmp in db.switch_statement) { + yield SwitchStatementDO { + element_hash_id : tmp.element_hash_id, + discriminant_hash_id : tmp.discriminant_hash_id, + body_declaration_hash_id : tmp.body_declaration_hash_id + } + } + } + /** + * @brief gets the discriminant hash id of this element. + * @return int + */ + pub fn getDiscriminantHashId(self) -> int { + return self.discriminant_hash_id + } + /** + * @brief gets the body declaration hash id of this element. + * @return int + */ + pub fn getBodyDeclarationHashId(self) -> int { + return self.body_declaration_hash_id + } +} +/** + * @brief DO class: A synchronized statement. + */ +schema SynchronizedStatementDO { + @primary element_hash_id: int, + lock_expression_hash_id: int, + body_declaration_hash_id: int +} +impl SynchronizedStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SynchronizedStatementDO { + for (tmp in db.synchronized_statement) { + yield SynchronizedStatementDO { + element_hash_id : tmp.element_hash_id, + lock_expression_hash_id : tmp.lock_expression_hash_id, + body_declaration_hash_id : tmp.body_declaration_hash_id + } + } + } + /** + * @brief gets the lock expression hash id of this element. + * @return int + */ + pub fn getLockExpressionHashId(self) -> int { + return self.lock_expression_hash_id + } + /** + * @brief gets the body declaration hash id of this element. + * @return int + */ + pub fn getBodyDeclarationHashId(self) -> int { + return self.body_declaration_hash_id + } +} + /** + * @brief DO class: A use of the keyword `this`, which may be qualified. + * + * Such an expression allows access to an enclosing instance. + * For example, `A.this` refers to the enclosing instance + * of type `A`. + */ +schema ThisAccessExpressionDO { + @primary element_hash_id: int +} +impl ThisAccessExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ThisAccessExpressionDO { + for (tmp in db.this_access_expression) { + yield ThisAccessExpressionDO { + element_hash_id : tmp.element_hash_id + } + } + } +} +/** + * @brief DO class: A this expression with qualifier. + */ +schema ThisExpressionWithQualifierDO { + @primary element_hash_id: int, + qualifier_hash_id: int +} +impl ThisExpressionWithQualifierDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ThisExpressionWithQualifierDO { + for (tmp in db.this_expression_with_qualifier) { + yield ThisExpressionWithQualifierDO { + element_hash_id : tmp.element_hash_id, + qualifier_hash_id : tmp.qualifier_hash_id + } + } + } + /** + * @brief gets the qualifier hash id of this element. + * @return int + */ + pub fn getQualifierHashId(self) -> int { + return self.qualifier_hash_id + } +} +/** + * @brief DO class: A throw statement. + */ +schema ThrowStatementDO { + @primary element_hash_id: int, + exception_hash_id: int, + block_hash_id: int +} +impl ThrowStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ThrowStatementDO { + for (tmp in db.throw_statement) { + yield ThrowStatementDO { + element_hash_id : tmp.element_hash_id, + exception_hash_id : tmp.exception_hash_id, + block_hash_id : tmp.block_hash_id + } + } + } + /** + * @brief gets the exception hash id of this element. + * @return int + */ + pub fn getExceptionHashId(self) -> int { + return self.exception_hash_id + } + /** + * @brief gets the block hash id of this element. + * @return int + */ + pub fn getBlockHashId(self) -> int { + return self.block_hash_id + } +} +/** + * @brief DO class: A single token in a Java file (the lowest-level element in the Java Ast tree). + */ +schema TokenDO { + @primary element_hash_id: int, + value: string, + location_hash_id: int, + parent_hash_id: int +} +impl TokenDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TokenDO { + for (tmp in db.token) { + yield TokenDO { + element_hash_id : tmp.element_hash_id, + value : tmp.value, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: A try statement with finally. + */ +schema TryStatementWithFinallyDO { + @primary element_hash_id: int, + try_block_hash_id: int, + finally_block_hash_id: int +} +impl TryStatementWithFinallyDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TryStatementWithFinallyDO { + for (tmp in db.try_statement_with_finally) { + yield TryStatementWithFinallyDO { + element_hash_id : tmp.element_hash_id, + try_block_hash_id : tmp.try_block_hash_id, + finally_block_hash_id : tmp.finally_block_hash_id + } + } + } + /** + * @brief gets the try block hash id of this element. + * @return int + */ + pub fn getTryBlockHashId(self) -> int { + return self.try_block_hash_id + } + /** + * @brief gets the finally block hash id of this element. + * @return int + */ + pub fn getFinallyBlockHashId(self) -> int { + return self.finally_block_hash_id + } +} +/** + * @brief DO class: A try statement without finally. + */ +schema TryStatementWithoutFinallyDO { + @primary element_hash_id: int, + try_block_hash_id: int +} +impl TryStatementWithoutFinallyDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TryStatementWithoutFinallyDO { + for (tmp in db.try_statement_without_finally) { + yield TryStatementWithoutFinallyDO { + element_hash_id : tmp.element_hash_id, + try_block_hash_id : tmp.try_block_hash_id + } + } + } + /** + * @brief gets the try block hash id of this element. + * @return int + */ + pub fn getTryBlockHashId(self) -> int { + return self.try_block_hash_id + } +} +/** + * @brief DO class: A type cast expression. + */ +schema TypeCastExpressionDO { + @primary element_hash_id: int, + cast_expression_hash_id: int +} +impl TypeCastExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TypeCastExpressionDO { + for (tmp in db.type_cast_expression) { + yield TypeCastExpressionDO { + element_hash_id : tmp.element_hash_id, + cast_expression_hash_id : tmp.cast_expression_hash_id + } + } + } + /** + * @brief gets the cast expression hash id of this element. + * @return int + */ + pub fn getCastExpressionHashId(self) -> int { + return self.cast_expression_hash_id + } +} +/** + * @brief DO class: An occurrence of a type in source code, for example, as a return type of the method or the type of a method parameter. + */ +schema TypeElementDO { + @primary element_hash_id: int, + reference_type_hash_id: int, + printable_text: string, + parent_hash_id: int, + location_hash_id: int +} +impl TypeElementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TypeElementDO { + for (tmp in db.type_element) { + yield TypeElementDO { + element_hash_id : tmp.element_hash_id, + reference_type_hash_id : tmp.reference_type_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the reference type hash id of this element. + * @return int + */ + pub fn getReferenceTypeHashId(self) -> int { + return self.reference_type_hash_id + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: A type literal, for example, "String.class". + */ +schema TypeLiteralDO { + @primary element_hash_id: int, + type_element_hash_id: int, + type_hash_id: int +} +impl TypeLiteralDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TypeLiteralDO { + for (tmp in db.type_literal) { + yield TypeLiteralDO { + element_hash_id : tmp.element_hash_id, + type_element_hash_id : tmp.type_element_hash_id, + type_hash_id : tmp.type_hash_id + } + } + } + /** + * @brief gets the type element hash id of this element. + * @return int + */ + pub fn getTypeElementHashId(self) -> int { + return self.type_element_hash_id + } + /** + * @brief gets the type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } +} +/** + * @brief DO class: A type parameter of a generic class, interface, method or constructor. + */ +schema TypeParameterDO { + @primary element_hash_id: int, + printable_text: string, + owner_hash_id: int, + index_order: int, + extends_list_hash_id: int, + parent_hash_id: int, + location_hash_id: int +} +impl TypeParameterDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TypeParameterDO { + for (tmp in db.type_parameter) { + yield TypeParameterDO { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + owner_hash_id : tmp.owner_hash_id, + index_order : tmp.index_order, + extends_list_hash_id : tmp.extends_list_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets a printed representation of this element, including its structure where applicable. + * @return string. + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the owner hash id of this element. + * @return int + */ + pub fn getOwnerHashId(self) -> int { + return self.owner_hash_id + } + /** + * @brief gets the index order of this element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the extends list hash id of this element. + * @return int + */ + pub fn getExtendsListHashId(self) -> int { + return self.extends_list_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } + /** + * @brief gets the location hash id of this element. + * @return int + */ + pub fn getLocationHashId(self) -> int { + return self.location_hash_id + } +} +/** + * @brief DO class: An unary expression. + */ +schema UnaryExpressionDO { + @primary element_hash_id: int, + operand_hash_id: int, + opcode: string, + is_postfix: int +} +impl UnaryExpressionDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *UnaryExpressionDO { + for (tmp in db.unary_expression) { + yield UnaryExpressionDO { + element_hash_id : tmp.element_hash_id, + operand_hash_id : tmp.operand_hash_id, + opcode : tmp.opcode, + is_postfix : tmp.is_postfix + } + } + } + /** + * @brief gets the operand hash id of this element. + * @return int + */ + pub fn getOperandHashId(self) -> int { + return self.operand_hash_id + } + /** + * @brief gets the opcode of this element. + * @return string + */ + pub fn getOpcode(self) -> string { + return self.opcode + } + /** + * @brief examine the expression is postfix or prefix, 1 means postfix expression. + * @return int + */ + pub fn getIsPostfix(self) -> int { + return self.is_postfix + } +} +/** + * @brief DO class: A while statement. + */ +schema WhileStatementDO { + @primary element_hash_id: int, + condition_hash_id: int, + body_declaration_hash_id: int +} +impl WhileStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *WhileStatementDO { + for (tmp in db.while_statement) { + yield WhileStatementDO { + element_hash_id : tmp.element_hash_id, + condition_hash_id : tmp.condition_hash_id, + body_declaration_hash_id : tmp.body_declaration_hash_id + } + } + } + /** + * @brief gets the expression id representing the condition of the loop. + * The condition is checked after every loop iteration, and + * iteration stops when condition evaluates to false. + * @return int + */ + pub fn getConditionHashId(self) -> int { + return self.condition_hash_id + } + /** + * @brief gets the body declaration hash id of this element. + * @return int + */ + pub fn getBodyDeclarationHashId(self) -> int { + return self.body_declaration_hash_id + } +} +/** + * @brief DO class: A yield statement. + */ +schema YieldStatementDO { + @primary element_hash_id: int, + expression_hash_id: int, + enclosing_expression_hash_id: int +} +impl YieldStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *YieldStatementDO { + for (tmp in db.yield_statement) { + yield YieldStatementDO { + element_hash_id : tmp.element_hash_id, + expression_hash_id : tmp.expression_hash_id, + enclosing_expression_hash_id : tmp.enclosing_expression_hash_id + } + } + } + /** + * @brief gets the expression hash id of this element. + * @return int + */ + pub fn getExpressionHashId(self) -> int { + return self.expression_hash_id + } + /** + * @brief gets the enclosing expression hash id of this element. + * @return int + */ + pub fn getEnclosingExpressionHashId(self) -> int { + return self.enclosing_expression_hash_id + } +} +/** + * @brief DO class: non-physical project. + */ +schema NpProjectDO { + @primary element_hash_id: int, + extension: string, + name: string +} +impl NpProjectDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpProjectDO { + for (tmp in db.np_project) { + yield NpProjectDO { + element_hash_id : tmp.element_hash_id, + extension : tmp.extension, + name : tmp.name + } + } + } + /** + * @brief gets the extension of this element. + * @return string + */ + pub fn getExtension(self) -> string { + return self.extension + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: non-physical file. + */ +schema NpFileDO { + @primary element_hash_id: int, + qualified_name: string, + name: string, + project_hash_id: int +} +impl NpFileDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpFileDO { + for (tmp in db.np_file) { + yield NpFileDO { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + name : tmp.name, + project_hash_id : tmp.project_hash_id + } + } + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the project hash id of this element. + * @return int + */ + pub fn getProjectHashId(self) -> int { + return self.project_hash_id + } +} +/** + * @brief DO class: non-physical class. + */ +schema NpClassDO { + @primary element_hash_id: int, + name: string, + qualified_name: string, + parent_hash_id: int +} +impl NpClassDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpClassDO { + for (tmp in db.np_class) { + yield NpClassDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + qualified_name : tmp.qualified_name, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: non-physical interface. + */ +schema NpInterfaceDO { + @primary element_hash_id: int, + name: string, + qualified_name: string, + parent_hash_id: int +} +impl NpInterfaceDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpInterfaceDO { + for (tmp in db.np_interface) { + yield NpInterfaceDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + qualified_name : tmp.qualified_name, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +/** + * @brief DO class: non-physical method. + */ +schema NpMethodDO { + @primary element_hash_id: int, + name: string, + signature: string, + type_hash_id: int, + parent_hash_id: int +} +impl NpMethodDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpMethodDO { + for (tmp in db.np_method) { + yield NpMethodDO { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + signature : tmp.signature, + type_hash_id : tmp.type_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the signature of this element. + * @return string + */ + pub fn getSignature(self) -> string { + return self.signature + } + /** + * @brief gets the return type hash id of this element. + * @return int + */ + pub fn getTypeHashId(self) -> int { + return self.type_hash_id + } + /** + * @brief gets the parent hash id of this element. + * @return int + */ + pub fn getParentHashId(self) -> int { + return self.parent_hash_id + } +} +database JavaDB { + annotated_relation: *AnnotatedRelationDO, + annotation_access_argument_with_name: *AnnotationAccessArgumentWithNameDO, + annotation_access_argument_without_name: *AnnotationAccessArgumentWithoutNameDO, + annotation_array_initializer: *AnnotationArrayInitializerDO, + annotation_can_not_resolved: *AnnotationCanNotResolvedDO, + annotation_can_resolved: *AnnotationCanResolvedDO, + annotation_declaration: *AnnotationDeclarationDO, + annotation_declaration_parameter: *AnnotationDeclarationParameterDO, + annotation_declaration_parameter_default_value: *AnnotationDeclarationParameterDefaultValueDO, + anonymous_class: *AnonymousClassDO, + array: *ArrayDO, + array_access_expression: *ArrayAccessExpressionDO, + array_creation_expression: *ArrayCreationExpressionDO, + array_initializer_expression: *ArrayInitializerExpressionDO, + assert_statement: *AssertStatementDO, + assignment_expression: *AssignmentExpressionDO, + binary_expression: *BinaryExpressionDO, + block_statement: *BlockStatementDO, + boolean_literal: *BooleanLiteralDO, + break_statement: *BreakStatementDO, + callable_binding: *CallableBindingDO, + callable_enclosing_expression: *CallableEnclosingExpressionDO, + callable_enclosing_statement: *CallableEnclosingStatementDO, + catch_section: *CatchSectionDO, + character_literal: *CharacterLiteralDO, + class: *ClassDO, + class_hierarchy: *ClassHierarchyDO, + class_implement_list: *ClassImplementListDO, + class_initializer: *ClassInitializerDO, + code_block: *CodeBlockDO, + comment: *CommentDO, + conditional_expression: *ConditionalExpressionDO, + constructor: *ConstructorDO, + constructor_invocation: *ConstructorInvocationDO, + container_parent: *ContainerParentDO, + continue_statement: *ContinueStatementDO, + cupackage: *CupackageDO, + declaration_element: *DeclarationElementDO, + do_while_statement: *DoWhileStatementDO, + double_literal: *DoubleLiteralDO, + element: *ElementDO, + empty_reference_parameter_list: *EmptyReferenceParameterListDO, + empty_statement: *EmptyStatementDO, + enum_constant: *EnumConstantDO, + exception: *ExceptionDO, + expression: *ExpressionDO, + expression_list: *ExpressionListDO, + expression_list_expression_relation: *ExpressionListExpressionRelationDO, + expression_statement: *ExpressionStatementDO, + field: *FieldDO, + file: *FileDO, + file_md5_sum: *FileMd5SumDO, + file_sha256_sum: *FileSha256SumDO, + floating_point_literal: *FloatingPointLiteralDO, + folder: *FolderDO, + for_statement: *ForStatementDO, + foreach_statement: *ForeachStatementDO, + identifier: *IdentifierDO, + if_statement_with_else: *IfStatementWithElseDO, + if_statement_without_else: *IfStatementWithoutElseDO, + import: *ImportDO, + import_static_reference_element: *ImportStaticReferenceElementDO, + import_static_statement: *ImportStaticStatementDO, + instanceof_expression: *InstanceofExpressionDO, + integer_literal: *IntegerLiteralDO, + interface: *InterfaceDO, + javadoc_comment: *JavadocCommentDO, + javadoc_tag: *JavadocTagDO, + javadoc_tag_value: *JavadocTagValueDO, + javadoc_data_token: *JavadocDataTokenDO, + labeled_statement: *LabeledStatementDO, + lambda_expression: *LambdaExpressionDO, + local_class: *LocalClassDO, + local_variable: *LocalVariableDO, + location: *LocationDO, + long_literal: *LongLiteralDO, + metainfo: *MetainfoDO, + method: *MethodDO, + method_access_expression_with_type: *MethodAccessExpressionWithTypeDO, + method_access_expression_without_type: *MethodAccessExpressionWithoutTypeDO, + method_reference_expression: *MethodReferenceExpressionDO, + modifier: *ModifierDO, + modifier_list: *ModifierListDO, + module: *ModuleDO, + name_string: *NameStringDO, + new_expression: *NewExpressionDO, + null_literal: *NullLiteralDO, + number_of_lines: *NumberOfLinesDO, + package_statement: *PackageStatementDO, + parameter: *ParameterDO, + parent: *ParentDO, + polyadic_expression: *PolyadicExpressionDO, + primitive: *PrimitiveDO, + program: *ProgramDO, + reference_element: *ReferenceElementDO, + reference_expression: *ReferenceExpressionDO, + reference_list: *ReferenceListDO, + reference_parameter_list: *ReferenceParameterListDO, + reference_relation: *ReferenceRelationDO, + reference_type: *ReferenceTypeDO, + resource_list: *ResourceListDO, + return_statement: *ReturnStatementDO, + statement: *StatementDO, + statement_enclosing_expression: *StatementEnclosingExpressionDO, + string_literal: *StringLiteralDO, + super_access_expression: *SuperAccessExpressionDO, + super_constructor_invocation: *SuperConstructorInvocationDO, + super_expression: *SuperExpressionDO, + super_expression_with_qualifier: *SuperExpressionWithQualifierDO, + switch_label_statement: *SwitchLabelStatementDO, + switch_statement: *SwitchStatementDO, + synchronized_statement: *SynchronizedStatementDO, + this_access_expression: *ThisAccessExpressionDO, + this_expression_with_qualifier: *ThisExpressionWithQualifierDO, + throw_statement: *ThrowStatementDO, + token: *TokenDO, + try_statement_with_finally: *TryStatementWithFinallyDO, + try_statement_without_finally: *TryStatementWithoutFinallyDO, + type_cast_expression: *TypeCastExpressionDO, + type_element: *TypeElementDO, + type_literal: *TypeLiteralDO, + type_parameter: *TypeParameterDO, + unary_expression: *UnaryExpressionDO, + while_statement: *WhileStatementDO, + yield_statement: *YieldStatementDO, + np_method: *NpMethodDO, + np_class: *NpClassDO, + np_interface: *NpInterfaceDO, + np_file: *NpFileDO, + np_project: *NpProjectDO, +} diff --git a/language/java/lib/Documentation.gdl b/language/java/lib/Documentation.gdl new file mode 100644 index 00000000..8c40d7c2 --- /dev/null +++ b/language/java/lib/Documentation.gdl @@ -0,0 +1,314 @@ +/** + * @brief a comment. + */ +schema Comment extends CommentDO { + +} +impl Comment { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Comment { + for (tmp in CommentDO(db)) { + yield Comment { + element_hash_id : tmp.element_hash_id, + text : tmp.text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + comment_type : tmp.comment_type + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} +/** + * @brief A java doc comment. + */ +schema JavadocComment extends JavadocCommentDO { + +} +impl JavadocComment { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JavadocComment { + for (tmp in JavadocCommentDO(db)) { + yield JavadocComment { + element_hash_id : tmp.element_hash_id, + documentable_hash_id : tmp.documentable_hash_id, + text : tmp.text, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the documentable element id of the java doc comment, maybe a callable, field, enumconstant, class or interface. + * @return ElementParent + */ + pub fn getDocumentableElement(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getDocumentableHashId()) { + return c + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief A javadoc tag, either an inline tag or a block tag. + */ +schema JavadocTag extends JavadocTagDO { + +} +impl JavadocTag { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JavadocTag { + for (tmp in JavadocTagDO(db)) { + yield JavadocTag { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + value : tmp.value, + containing_comment_hash_id : tmp.containing_comment_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the doc comment in which the tag is contained. + * @return JavadocComment + */ + pub fn getComment(self) -> JavadocComment { + for (comment in JavadocComment(__all_data__)) { + if (comment.element_hash_id = self.getContainingCommentHashId()) { + return comment + } + } + } + /** + * @brief gets the documented element. + * @return ExpressionParent + */ + pub fn getDocumentableElement(self) -> ExpressionParent { + let (comment = self.getComment()) { + let (element = comment.getDocumentableElement()) { + return ExpressionParent(__all_data__).find(element) + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief A javadoc tag value element. + */ +schema JavadocTagValue extends JavadocTagValueDO { + +} +impl JavadocTagValue { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JavadocTagValue { + for (tmp in JavadocTagValueDO(db)) { + yield JavadocTagValue { + element_hash_id : tmp.element_hash_id, + value : tmp.value, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the doc tag in which the element is contained. + * @return JavadocTag + */ + pub fn getJavaDocTag(self) -> JavadocTag { + for (tag in JavadocTag(__all_data__)) { + if (tag.element_hash_id = self.getParentHashId()) { + return tag + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief A javadoc data token element. + */ +schema JavadocDataToken extends JavadocDataTokenDO { + +} +impl JavadocDataToken { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JavadocDataToken { + for (tmp in JavadocDataTokenDO(db)) { + yield JavadocDataToken { + element_hash_id : tmp.element_hash_id, + value : tmp.value, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the doc tag in which the element is contained, if any. + * @return JavadocTag + */ + pub fn getJavaDocTag(self) -> JavadocTag { + for (tag in JavadocTag(__all_data__)) { + if (tag.element_hash_id = self.getParentHashId()) { + return tag + } + } + } + /** + * @brief gets the doc comment in which the element is contained, if any. + * @return JavadocComment + */ + pub fn getComment(self) -> JavadocComment { + for (comment in JavadocComment(__all_data__)) { + if (comment.element_hash_id = self.getParentHashId()) { + return comment + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} diff --git a/language/java/lib/Expression.gdl b/language/java/lib/Expression.gdl new file mode 100644 index 00000000..6ecbb843 --- /dev/null +++ b/language/java/lib/Expression.gdl @@ -0,0 +1,1581 @@ +/** + * @brief A common super-class that represents all kinds of expressions. + */ +schema Expression extends ExpressionDO { + +} +impl Expression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Expression { + for (tmp in ExpressionDO(db)) { + yield Expression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the parent of the expression. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the callable in which this expression occurs. + * @return Callable + */ + pub fn getEnclosingCallable(self) -> Callable { + let (cee = CallableEnclosingExpression(__all_data__).find(self)) { + return cee.getCallable() + } + } + /** + * @brief gets the statement which encloses the expression. + * @return Statement + */ + pub fn getEnclosingStatement(self) -> Statement { + for (stmt in Statement(__all_data__), + see in StatementEnclosingExpression(__all_data__)) { + if (self.key_eq(see)) { + if (see.getStatementHashId() = stmt.element_hash_id) { + return stmt + } + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_hash_id = self.getLocationHashId()) { + return n + } + } + } +} +/** + * @brief An array initializer. + */ +schema ArrayInitializer extends Expression { + +} +impl ArrayInitializer { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ArrayInitializer { + for (tmp in Expression(db)) { + for (ai in ArrayInitializerExpression(db)) { + if (ai.key_eq(tmp.getParent())) { + yield ArrayInitializer { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the initializer expression. + * @return ArrayInitializerExpression + */ + pub fn getInitializerExpression(self) -> int { + return self.getParent().id + } +} +/** + * @brief A element in a expression list. + */ +schema ExpressionListElement extends Expression { + +} +impl ExpressionListElement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionListElement { + for (tmp in Expression(db)) { + for (ele in ExpressionList(db)) { + if (ele.key_eq(tmp.getParent())) { + yield ExpressionListElement { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the parent of the expression list element. + * @return ExpressionList + */ + pub fn getExpressionList(self) -> ExpressionList { + return ExpressionList(__all_data__).find(self.getParent()) + } +} +/** + * @brief An assignment expression. + */ +schema AssignmentExpression extends Expression { + +} +impl AssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AssignmentExpression { + for (tmp in Expression(db)) { + for (ae in AssignmentExpressionDO(db)) { + if (tmp.key_eq(ae)) { + yield AssignmentExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the operand on the left-hand side of the binary expression. + * @return Expression + */ + pub fn getDestination(self) -> Expression { + for (lhs in Expression(__all_data__), + be in AssignmentExpressionDO(__all_data__)) { + if (self.key_eq(be)) { + if (lhs.element_hash_id = be.getLhsHashId()) { + return lhs + } + } + } + } + /** + * @brief gets the operand on the right-hand side of the binary expression. + * @return Expression + */ + pub fn getSource(self) -> Expression { + for (rhs in Expression(__all_data__), + be in AssignmentExpressionDO(__all_data__)) { + if (self.key_eq(be)) { + if (rhs.element_hash_id = be.getRhsHashId()) { + return rhs + } + } + } + } + /** + * @brief gets the opcode of the binary expression + * @return string + */ + pub fn getOpcode(self) -> string { + for (be in AssignmentExpressionDO(__all_data__)) { + if (self.key_eq(be)) { + let (op = be.getOpcode()) { + return op + } + } + } + } +} +/** + * @brief A binary expression. + */ +schema BinaryExpression extends Expression { + +} +impl BinaryExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *BinaryExpression { + for (tmp in Expression(db)) { + for (be in BinaryExpressionDO(db)) { + if (tmp.key_eq(be)) { + yield BinaryExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the operand on the left-hand side of the binary expression. + * @return Expression + */ + pub fn getLeftOperandExpression(self) -> Expression { + for (lhs in Expression(__all_data__), + be in BinaryExpressionDO(__all_data__)) { + if (self.key_eq(be)) { + if (lhs.element_hash_id = be.getLhsHashId()) { + return lhs + } + } + } + } + /** + * @brief gets an operand of the binary expression. + * @return Expression + */ + pub fn getOperand(self) -> *Expression { + for (e in Expression(__all_data__), + be in BinaryExpressionDO(__all_data__)) { + if (self.key_eq(be)) { + if (e.element_hash_id = be.getLhsHashId()) { + yield e + } + if (e.element_hash_id = be.getRhsHashId()) { + yield e + } + } + } + } + /** + * @brief gets the operand on the right-hand side of the binary expression. + * @return Expression + */ + pub fn getRightOperandExpression(self) -> Expression { + for (rhs in Expression(__all_data__), + be in BinaryExpressionDO(__all_data__)) { + if (self.key_eq(be)) { + if (rhs.element_hash_id = be.getRhsHashId()) { + return rhs + } + } + } + } + /** + * @brief gets the opcode of the binary expression + * @return string + */ + pub fn getOpcode(self) -> string { + for (be in BinaryExpressionDO(__all_data__)) { + if (self.key_eq(be)) { + let (op = be.getOpcode()) { + return op + } + } + } + } +} +/** + * @brief An '&&' expression. + */ +schema AndLogicalExpression extends BinaryExpression { + +} +impl AndLogicalExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AndLogicalExpression { + for (tmp in BinaryExpression(db)) { + for (be in BinaryExpression(db)) { + if (tmp = be) { + if (be.getOpcode() = "&&") { + yield AndLogicalExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + } +} +/** + * @brief A '||' expression. + */ +schema OrLogicalExpression extends BinaryExpression { + +} +impl OrLogicalExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *OrLogicalExpression { + for (tmp in BinaryExpression(db)) { + for (be in BinaryExpression(db)) { + if (tmp = be) { + if (be.getOpcode() = "||") { + yield OrLogicalExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + } +} +schema ConditionalPolyadicExpression extends PolyadicExpression { + +} +impl ConditionalPolyadicExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ConditionalPolyadicExpression { + for (tmp in PolyadicExpression(db)) { + for (p in PolyadicExpression(db)) { + if (tmp = p) { + if (p.getOpcode() = "ANDAND") { + yield ConditionalPolyadicExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + if (p.getOpcode() = "OROR") { + yield ConditionalPolyadicExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + } +} +/** + * @brief An unary expression. + */ +schema UnaryExpression extends Expression { + +} +impl UnaryExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *UnaryExpression { + for (tmp in Expression(db)) { + for (ue in UnaryExpressionDO(db)) { + if (tmp.key_eq(ue)) { + yield UnaryExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the operand expression of the unary expression. + * @return Expression + */ + pub fn getOperand(self) -> Expression { + for (e in Expression(__all_data__), + ue in UnaryExpressionDO(__all_data__)) { + if (self.key_eq(ue)) { + if (e.element_hash_id = ue.getOperandHashId()) { + return e + } + } + } + } + /** + * @brief gets the opcode of the unary expression + * @return string + */ + pub fn getOpcode(self) -> string { + for (ue in UnaryExpressionDO(__all_data__)) { + if (self.key_eq(ue)) { + let (op = ue.getOpcode()) { + return op + } + } + } + } +} +/** + * @brief An '!' expression. + */ +schema LogNotExpression extends UnaryExpression { + +} +impl LogNotExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LogNotExpression { + for (tmp in UnaryExpression(db)) { + if (tmp.getOpcode() = "!") { + yield LogNotExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } +} +/** + * @brief A logic expression. + */ +schema LogicExpression extends Expression { + +} +impl LogicExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LogicExpression { + for (tmp in Expression(db)) { + for (lne in LogNotExpression(db)) { + if (tmp.key_eq(lne)) { + yield LogicExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (ale in AndLogicalExpression(db)) { + if (tmp.key_eq(ale)) { + yield LogicExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (ole in OrLogicalExpression(db)) { + if (tmp.key_eq(ole)) { + yield LogicExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief description + * @return Expression + */ + pub fn getAnOperand(self) -> *Expression { + for (operand in Expression(__all_data__)) { + for (lne in LogNotExpression(__all_data__)) { + if (self.key_eq(lne)) { + if (operand = lne.getOperand()) { + yield operand + } + } + } + for (ale in AndLogicalExpression(__all_data__)) { + if (self.key_eq(ale)) { + for (auto_tmp1 in ale.getOperand()) { + if (operand = auto_tmp1) { + yield operand + } + } + } + } + for (ole in OrLogicalExpression(__all_data__)) { + if (self.key_eq(ole)) { + for (auto_tmp2 in ole.getOperand()) { + if (operand = auto_tmp2) { + yield operand + } + } + } + } + } + } +} +/** + * @classname ConditionalExpression + * @brief A conditional expression of the form a ? b : c, where a is the condition, b is the expression that is evaluated if the condition evaluates to true, and c is the expression that is evaluated if the condition evaluates to false. + */ +schema ConditionalExpression extends Expression { + +} +impl ConditionalExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ConditionalExpression { + for (tmp in Expression(db)) { + for (ce in ConditionalExpressionDO(db)) { + if (tmp.key_eq(ce)) { + yield ConditionalExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the condition of the conditional expression. + * @return Expression + */ + pub fn getCondition(self) -> Expression { + for (cond in Expression(__all_data__), + ce in ConditionalExpressionDO(__all_data__)) { + if (self.key_eq(ce)) { + if (cond.element_hash_id = ce.getConditionExpressionHashId()) { + return cond + } + } + } + } + /** + * @brief gets the true expression of the conditional expression if the condition is true. + * @return Expression + */ + pub fn getTrueExpression(self) -> Expression { + for (e in Expression(__all_data__), + ce in ConditionalExpressionDO(__all_data__)) { + if (self.key_eq(ce)) { + if (e.element_hash_id = ce.getThenPartHashId()) { + return e + } + } + } + } + /** + * @brief gets the false expression of the conditional expression if the condition is false. + * @return Expression + */ + pub fn getFalseExpression(self) -> Expression { + for (e in Expression(__all_data__), + ce in ConditionalExpressionDO(__all_data__)) { + if (self.key_eq(ce)) { + if (e.element_hash_id = ce.getElsePartHashId()) { + return e + } + } + } + } +} +/** + * @brief A lambda expression. + */ +schema LambdaExpression extends Expression { + +} +impl LambdaExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LambdaExpression { + for (tmp in Expression(db)) { + for (le in LambdaExpressionDO(db)) { + if (tmp.key_eq(le)) { + yield LambdaExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the parameter of the lambda expression. + * @return Parameter + */ + pub fn getParameter(self) -> *Parameter { + for (p in Parameter(__all_data__)) { + if (self.key_eq(p.getParent())) { + yield p + } + } + } + /** + * @brief gets the element representing lambda expression body, a code block or an expression. + * @return ElementParent + */ + pub fn getBody(self) -> ElementParent { + for (e in ElementParent(__all_data__), + l in LambdaExpressionDO(__all_data__)) { + if (self.key_eq(l)) { + if (e.id = l.getBodyHashId()) { + return e + } + } + } + } +} +/** + * @brief A this access expression. + */ +schema ThisAccessExpression extends Expression { + +} +impl ThisAccessExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ThisAccessExpression { + for (tmp in Expression(db)) { + for (tae in ThisAccessExpressionDO(db)) { + if (tmp.key_eq(tae)) { + yield ThisAccessExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A new expression. + */ +schema NewExpression extends Expression { + +} +impl NewExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NewExpression { + for (tmp in Expression(db)) { + for (ne in NewExpressionDO(db)) { + if (tmp.key_eq(ne)) { + yield NewExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__), + ne in NewExpressionDO(__all_data__)) { + if (self.key_eq(ne)) { + if (type.id = ne.getTypeHashId()) { + return type + } + } + } + } + /** + * @brief gets the created class instance. + * @return ReferenceElement + */ + pub fn getReference(self) -> ReferenceElement { + for (r in ReferenceElement(__all_data__), + ne in NewExpressionDO(__all_data__)) { + if (self.key_eq(ne)) { + if (r.element_hash_id = ne.getReferenceHashId()) { + return r + } + } + } + } + /** + * @brief gets the created anonymous class instance. + * @return AnonymousClass + */ + pub fn getAnonymousClass(self) -> AnonymousClass { + for (r in AnonymousClass(__all_data__), + ne in NewExpressionDO(__all_data__)) { + if (r.element_hash_id = ne.getReferenceHashId()) { + if (self.key_eq(ne)) { + return r + } + } + } + } +} +/** + * @brief A super access expression. + */ +schema SuperAccessExpression extends Expression { + +} +impl SuperAccessExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SuperAccessExpression { + for (tmp in Expression(db)) { + for (sae in SuperAccessExpressionDO(db)) { + if (tmp.key_eq(sae)) { + yield SuperAccessExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + pub fn getMethod(self) -> Method { + for (c in Method(__all_data__), + sae in SuperAccessExpressionDO(__all_data__), + cc in CallableBinding(__all_data__)) { + if (self.key_eq(sae)) { + if (cc.key_eq(self)) { + if (c.key_eq(cc.getCallee())) { + return c + } + } + } + } + } +} +/** + * @brief A super access expression. + */ +schema SuperConstructorInvocation extends Expression { + +} +impl SuperConstructorInvocation { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SuperConstructorInvocation { + for (tmp in Expression(db)) { + for (sci in SuperConstructorInvocationDO(db)) { + if (tmp.key_eq(sci)) { + yield SuperConstructorInvocation { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + pub fn getConstructor(self) -> Constructor { + for (c in Constructor(__all_data__), + sci in SuperConstructorInvocationDO(__all_data__), + cc in CallableBinding(__all_data__)) { + if (self.key_eq(sci)) { + if (cc.key_eq(self)) { + if (c.key_eq(cc.getCallee())) { + return c + } + } + } + } + } +} +/** + * @brief A reference in code (either an identifier or a sequence of identifiers separated by periods, optionally with generic type arguments) + */ +schema ReferenceExpression extends Expression { + +} +impl ReferenceExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceExpression { + for (tmp in Expression(db)) { + for (re in ReferenceExpressionDO(db)) { + if (tmp.key_eq(re)) { + yield ReferenceExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the definition of the reference expression. + * @return ElementParent + */ + pub fn getDefinition(self) -> ElementParent { + for (element in ElementParent(__all_data__), + rr in ReferenceRelation(__all_data__)) { + if (rr.key_eq(self)) { + if (element = rr.getDestination()) { + return element + } + } + } + } + /** + * @brief gets the MethodAccessExpression of the reference expression left. + * @return MethodAccessExpression + */ + pub fn getMethodAccessExpression(self) -> MethodAccessExpression { + for (element in MethodAccessExpression(__all_data__), + rr in ReferenceExpressionDO(__all_data__)) { + if (rr.key_eq(self)) { + if (element.getParent().key_eq(rr)) { + return element + } + } + } + } + /** + * @brief gets the Identifier of the reference expression Right. + * @return Identifier + */ + pub fn getIdentifier(self) -> Identifier { + for (element in Identifier(__all_data__), + rr in ReferenceExpressionDO(__all_data__)) { + if (rr.key_eq(self)) { + if (element.getParent().key_eq(rr)) { + return element + } + } + } + } +} +/** + * @brief Describe an expression enclosed by a certain statement. + */ +schema StatementEnclosingExpression extends StatementEnclosingExpressionDO { + +} +impl StatementEnclosingExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *StatementEnclosingExpression { + for (tmp in StatementEnclosingExpressionDO(db)) { + yield StatementEnclosingExpression { + expression_hash_id : tmp.expression_hash_id, + statement_hash_id : tmp.statement_hash_id + } + } + } + /** + * @brief gets the statement which encloses the expression. + * @return Statement + */ + pub fn getStatement(self) -> Statement { + for (s in Statement(__all_data__)) { + if (s.element_hash_id = self.getStatementHashId()) { + return s + } + } + } +} +/** + * @brief An instanceof expression + */ +schema InstanceofExpression extends Expression { + +} +impl InstanceofExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *InstanceofExpression { + for (tmp in Expression(db)) { + for (ioe in InstanceofExpressionDO(db)) { + if (tmp.key_eq(ioe)) { + yield InstanceofExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the operand expression of the instanceof expression + * @return Expression + */ + pub fn getOperand(self) -> Expression { + for (e in Expression(__all_data__), + ioe in InstanceofExpressionDO(__all_data__)) { + if (self.key_eq(ioe)) { + if (e.element_hash_id = ioe.getOperandHashId()) { + return e + } + } + } + } + /** + * @brief gets the instance type of the instanceof expression + * @return TypeElement + */ + pub fn getInstanceType(self) -> TypeElement { + for (e in TypeElement(__all_data__), + ioe in InstanceofExpressionDO(__all_data__)) { + if (self.key_eq(ioe)) { + if (e.getParent().key_eq(ioe)) { + return e + } + } + } + } +} +schema MethodAccessExpressionWithType extends Expression { + +} +impl MethodAccessExpressionWithType { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MethodAccessExpressionWithType { + for (tmp in Expression(db)) { + for (m in MethodAccessExpressionWithTypeDO(db)) { + if (tmp.key_eq(m)) { + yield MethodAccessExpressionWithType { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__), + mae in MethodAccessExpressionWithTypeDO(__all_data__)) { + if (self.key_eq(mae)) { + if (type.id = mae.getTypeHashId()) { + return type + } + } + } + } + /** + * @brief gets the reference expression of the element. + * @return ReferenceExpression + */ + pub fn getReference(self) -> ReferenceExpression { + for (expression in ReferenceExpression(__all_data__), + mae in MethodAccessExpressionWithTypeDO(__all_data__)) { + if (expression.element_hash_id = mae.getReferenMethodHashId()) { + if (self.key_eq(mae)) { + return expression + } + } + } + } +} +schema MethodAccessExpressionWithoutType extends Expression { + +} +impl MethodAccessExpressionWithoutType { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MethodAccessExpressionWithoutType { + for (tmp in Expression(db)) { + for (m in MethodAccessExpressionWithoutTypeDO(db)) { + if (tmp.key_eq(m)) { + yield MethodAccessExpressionWithoutType { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the reference expression of the element. + * @return ReferenceExpression + */ + pub fn getReference(self) -> ReferenceExpression { + for (expression in ReferenceExpression(__all_data__), + mae in MethodAccessExpressionWithoutTypeDO(__all_data__)) { + if (expression.element_hash_id = mae.getReferenMethodHashId()) { + if (self.key_eq(mae)) { + return expression + } + } + } + } +} +/** + * @brief A call of a method. + */ +schema MethodAccessExpression extends Expression { + +} +impl MethodAccessExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MethodAccessExpression { + for (tmp in Expression(db)) { + for (mae in MethodAccessExpressionWithoutType(db)) { + if (tmp.key_eq(mae)) { + yield MethodAccessExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (mae in MethodAccessExpressionWithType(db)) { + if (tmp.key_eq(mae)) { + yield MethodAccessExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + pub fn getExpressionList(self) -> ExpressionList { + for (list in ExpressionList(__all_data__)) { + if (self.element_hash_id = list.getParentHashId()) { + return list + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (mae in MethodAccessExpressionWithType(__all_data__)) { + if (self.key_eq(mae)) { + return mae.getType() + } + } + for (mae in MethodAccessExpressionWithoutType(__all_data__)) { + if (self.key_eq(mae)) { + return self.getCallable().getType() + } + } + } + /** + * @brief gets the reference expression of the element. + * @return ReferenceExpression + */ + pub fn getReference(self) -> ReferenceExpression { + for (mae in MethodAccessExpressionWithoutType(__all_data__)) { + if (self.key_eq(mae)) { + return mae.getReference() + } + } + for (mae in MethodAccessExpressionWithType(__all_data__)) { + if (self.key_eq(mae)) { + return mae.getReference() + } + } + } + /** + * @brief gets the method of the call. + * @return Method + */ + pub fn getMethod(self) -> Method { + let (c = CallableBinding(__all_data__).find(self)) { + for (tmp in Method(__all_data__)) { + if (tmp.element_hash_id = c.callee_hash_id) { + return tmp + } + } + // ElementParent{id: c.callee_hash_id} + // return Method(__all_data__).find(ElementParent{id: c.callee_hash_id}) + } + } + /** + * @brief gets the np-method of the call. + * @return NpMethod + */ + pub fn getNpMethod(self) -> NpMethod { + let (c = CallableBinding(__all_data__).find(self)) { + return NpMethod(__all_data__).find(ElementParent{id: c.callee_hash_id}) + } + } + /** + * @brief gets the constructor of the call. + * @return Constructor + */ + pub fn getConstructor(self) -> Constructor { + let (c = CallableBinding(__all_data__).find(self)) { + return Constructor(__all_data__).find(ElementParent{id: c.callee_hash_id}) + } + } + /** + * @brief gets the callable of the call. + * @return Callable + */ + pub fn getCallable(self) -> Callable { + let (m = Callable(__all_data__).find(self.getMethod())) { + return m + } + let (m = Callable(__all_data__).find(self.getConstructor())) { + return m + } + } + /** + * @brief gets the call site of the call. + * @return ReferenceExpression + */ + pub fn getCallSite(self) -> ReferenceExpression { + for (element in ReferenceExpression(__all_data__)) { + if (self.getReference().key_eq(element.getParent())) { + return element + } + } + } + /** + * @brief gets the call site of the call. + * @return ReferenceExpression + */ + pub fn getArgument(self, idx : int) -> Expression { + return self.getExpressionList().getSubExpression(idx) + } +} +/** + * @brief A call of a method. + */ +schema MethodReferenceExpression extends Expression { + +} +impl MethodReferenceExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *MethodReferenceExpression { + for (tmp in Expression(db)) { + for (m in MethodReferenceExpressionDO(db)) { + if (tmp.key_eq(m)) { + yield MethodReferenceExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__)) { + if (type = self.getMethod().getType()) { + return type + } + } + } + /** + * @brief gets the method of the call. + * @return Method + */ + pub fn getMethod(self) -> Method { + for (mae in MethodReferenceExpressionDO(__all_data__), + c in CallableBinding(__all_data__)) { + if (self.key_eq(mae)) { + if (c.key_eq(mae)) { + return Method(__all_data__).find(c.getCallee()) + } + } + } + } + /** + * @brief gets the constructor of the call. + * @return Constructor + */ + pub fn getConstructor(self) -> Constructor { + for (m in Constructor(__all_data__), + mae in MethodReferenceExpressionDO(__all_data__), + c in CallableBinding(__all_data__)) { + if (self.key_eq(mae)) { + if (mae.isConstructor() = 1) { + if (c.key_eq(mae)) { + if (m.key_eq(c.getCallee())) { + return m + } + } + } + } + } + } + /** + * @brief gets the callable of the call. + * @return Callable + */ + pub fn getCallable(self) -> Callable { + for (m in Callable(__all_data__)) { + if (m.key_eq(self.getMethod())) { + return m + } + if (m.key_eq(self.getConstructor())) { + return m + } + } + } + /** + * @brief gets the reference expression of the element. + * @return ReferenceExpression + */ + pub fn getReference(self) -> ReferenceExpression { + for (expression in ReferenceExpression(__all_data__)) { + if (expression.getParent().key_eq(self)) { + return expression + } + } + } +} +/** + * @brief A constructor invocation statement. + */ +schema ConstructorInvocation extends Expression { + +} +impl ConstructorInvocation { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ConstructorInvocation { + for (tmp in Expression(db)) { + for (ci in ConstructorInvocationDO(db)) { + if (tmp.key_eq(ci)) { + yield ConstructorInvocation { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the constructor of the expression + * @return Constructor + */ + pub fn getConstructor(self) -> Constructor { + for (c in Constructor(__all_data__), + ci in ConstructorInvocationDO(__all_data__), + cc in CallableBinding(__all_data__)) { + if (self.key_eq(ci)) { + if (ci.key_eq(cc)) { + if (c.key_eq(cc.getCallee())) { + return c + } + } + } + } + } + /** + * @brief gets the reference element of the expression + * @return ReferenceElement + */ + pub fn getReference(self) -> ReferenceElement { + for (r in ReferenceElement(__all_data__), + ci in ConstructorInvocationDO(__all_data__)) { + if (self.key_eq(ci)) { + if (ci.key_eq(r.getParent())) { + return r + } + } + } + } + /** + * @brief gets the argument of the expression + * @return ExpressionList + */ + pub fn getExpressionList(self) -> ExpressionList { + for (r in ExpressionList(__all_data__), + ci in ConstructorInvocationDO(__all_data__)) { + if (self.key_eq(ci)) { + if (ci.key_eq(r.getParent())) { + return r + } + } + } + } +} +/** + * @brief A list of reference separated by commas. + */ +schema ReferenceList extends ReferenceListDO { + +} +impl ReferenceList { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceList { + for (tmp in ReferenceListDO(db)) { + yield ReferenceList { + element_hash_id : tmp.element_hash_id, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id, + printable_text : tmp.printable_text, + role : tmp.role + } + } + } + /** + * @brief gets the reference element of the list + * @return ReferenceElement + */ + pub fn getChild(self) -> *ReferenceElement { + for (r in ReferenceElement(__all_data__)) { + if (self.element_hash_id = r.getParentHashId()) { + yield r + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the location for the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief A cast expression. + */ +schema TypeCastExpression extends Expression { + +} +impl TypeCastExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TypeCastExpression { + for (tmp in Expression(db)) { + for (m in TypeCastExpressionDO(db)) { + if (tmp.key_eq(m)) { + yield TypeCastExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @description gets the type element of the expression. + * @return TypeElement + */ + pub fn getCastType(self) -> TypeElement { + for (t in TypeElement(__all_data__)) { + if (self.key_eq(t.getParent())) { + return t + } + } + } + /** + * @description get the operand of the expression. + * @return Expression + */ + pub fn getOperand(self) -> Expression { + for (e in Expression(__all_data__)) { + if (self.key_eq(e.getParent())) { + return e + } + } + } +} +/** + * @brief A polyadic expression. + */ +schema PolyadicExpression extends Expression { + +} +impl PolyadicExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *PolyadicExpression { + for (tmp in Expression(db)) { + for (m in PolyadicExpressionDO(db)) { + if (tmp.key_eq(m)) { + yield PolyadicExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the size of the element. + * @return int + */ + pub fn getSize(self) -> int { + for (m in PolyadicExpressionDO(__all_data__)) { + if (self.key_eq(m)) { + return m.getSize() + } + } + } + /** + * @brief gets the opcode of the element. + * @return string + */ + pub fn getOpcode(self) -> string { + for (m in PolyadicExpressionDO(__all_data__)) { + if (self.key_eq(m)) { + let (name = m.getOpcode()) { + return name + } + } + } + } + /** + * @brief gets the operand of the element. + * @return Expression + */ + pub fn getOperand(self) -> *Expression { + for (e in Expression(__all_data__)) { + if (self.key_eq(e.getParent())) { + yield e + } + } + } + /** + * @brief gets the operand of the element at a given index. + * @return Expression + */ + pub fn getOperandAt(self, index : int) -> Expression { + for (e in Expression(__all_data__)) { + if (self.key_eq(e.getParent())) { + if (index = e.getIndex()) { + return e + } + } + } + } +} diff --git a/language/java/lib/Identifier.gdl b/language/java/lib/Identifier.gdl new file mode 100644 index 00000000..b62d98c7 --- /dev/null +++ b/language/java/lib/Identifier.gdl @@ -0,0 +1,53 @@ +/** + * @brief An identifier. + */ +schema Identifier extends IdentifierDO { + +} +impl Identifier { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Identifier { + for (tmp in IdentifierDO(db)) { + yield Identifier { + element_hash_id : tmp.element_hash_id, + location_hash_id : tmp.location_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} diff --git a/language/java/lib/Literal.gdl b/language/java/lib/Literal.gdl new file mode 100644 index 00000000..167c4b64 --- /dev/null +++ b/language/java/lib/Literal.gdl @@ -0,0 +1,512 @@ +/** + * @brief A literal. + */ +schema Literal extends Expression { + +} +impl Literal { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Literal { + for (tmp in Expression(db)) { + for (s in StringLiteralDO(db)) { + if (tmp.key_eq(s)) { + yield Literal { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (l in LongLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield Literal { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (d in DoubleLiteralDO(db)) { + if (tmp.key_eq(d)) { + yield Literal { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (f in FloatingPointLiteralDO(db)) { + if (tmp.key_eq(f)) { + yield Literal { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (n in NullLiteralDO(db)) { + if (tmp.key_eq(n)) { + yield Literal { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (c in CharacterLiteralDO(db)) { + if (tmp.key_eq(c)) { + yield Literal { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (b in BooleanLiteralDO(db)) { + if (tmp.key_eq(b)) { + yield Literal { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + for (i in IntegerLiteralDO(db)) { + if (tmp.key_eq(i)) { + yield Literal { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the value of the Literal. + * @return string + */ + pub fn getValue(self) -> string { + for (s in StringLiteralDO(__all_data__)) { + if (self.key_eq(s)) { + let (value = s.getValue()) { + return value + } + } + } + for (l in LongLiteralDO(__all_data__)) { + if (self.key_eq(l)) { + let (value = l.getValue()) { + return value + } + } + } + for (d in DoubleLiteralDO(__all_data__)) { + if (self.key_eq(d)) { + let (value = d.getValue()) { + return value + } + } + } + for (f in FloatingPointLiteralDO(__all_data__)) { + if (self.key_eq(f)) { + let (value = f.getValue()) { + return value + } + } + } + for (n in NullLiteralDO(__all_data__)) { + if (self.key_eq(n)) { + let (value = n.getValue()) { + return value + } + } + } + for (c in CharacterLiteralDO(__all_data__)) { + if (self.key_eq(c)) { + let (value = c.getValue()) { + return value + } + } + } + for (b in BooleanLiteralDO(__all_data__)) { + if (self.key_eq(b)) { + let (value = b.getValue()) { + return value + } + } + } + for (i in IntegerLiteralDO(__all_data__)) { + if (self.key_eq(i)) { + let (value = i.getValue()) { + return value + } + } + } + } + /** + * @brief gets the type of the Literal value. + * @return string + */ + pub fn getValueType(self) -> Type { + for (t in Type(__all_data__)) { + for (s in StringLiteralDO(__all_data__)) { + if (self.key_eq(s)) { + if (t.getQualifiedName() = "java.lang.String") { + return t + } + } + } + for (l in LongLiteralDO(__all_data__)) { + if (self.key_eq(l)) { + if (t.id = 6) { + return t + } + } + } + for (d in DoubleLiteralDO(__all_data__)) { + if (self.key_eq(d)) { + if (t.id = 3) { + return t + } + } + } + for (f in FloatingPointLiteralDO(__all_data__)) { + if (self.key_eq(f)) { + if (t.id = 4) { + return t + } + } + } + for (n in NullLiteralDO(__all_data__)) { + if (self.key_eq(n)) { + if (t.id = 10) { + return t + } + } + } + for (c in CharacterLiteralDO(__all_data__)) { + if (self.key_eq(c)) { + if (t.id = 2) { + return t + } + } + } + for (b in BooleanLiteralDO(__all_data__)) { + if (self.key_eq(b)) { + if (t.id = 8) { + return t + } + } + } + for (i in IntegerLiteralDO(__all_data__)) { + if (self.key_eq(i)) { + if (t.id = 5) { + return t + } + } + } + } + } +} +/** + * @brief A string literal, for example "abc". + */ +schema StringLiteral extends Literal { + +} +impl StringLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *StringLiteral { + for (tmp in Literal(db)) { + for (l in StringLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield StringLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + pub fn getRealValue(self) -> string { + let (temp = self.getValue()) { + let (l = temp.len()) { + let (s = temp.substr(1, l - 2)) { + return s + } + } + } + } +} +/** + * @brief A double literal. For example, "1.5". + */ +schema DoubleLiteral extends Literal { + +} + +impl DoubleLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DoubleLiteral { + for (tmp in Literal(db)) { + for (l in DoubleLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield DoubleLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief An integer literal, for example, "4". + */ +schema IntegerLiteral extends Literal { + +} +impl IntegerLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *IntegerLiteral { + for (tmp in Literal(db)) { + for (l in IntegerLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield IntegerLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A floating point literal, for example, "1.5f". + */ +schema FloatingPointLiteral extends Literal { + +} +impl FloatingPointLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *FloatingPointLiteral { + for (tmp in Literal(db)) { + for (l in FloatingPointLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield FloatingPointLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A long literal, for example, "15l". + */ +schema LongLiteral extends Literal { + +} +impl LongLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LongLiteral { + for (tmp in Literal(db)) { + for (l in LongLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield LongLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A null literal, written "null". + */ +schema NullLiteral extends Literal { + +} +impl NullLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NullLiteral { + for (tmp in Literal(db)) { + for (l in NullLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield NullLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A character literal, for example, 'a'. + */ +schema CharacterLiteral extends Literal { + +} +impl CharacterLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CharacterLiteral { + for (tmp in Literal(db)) { + for (l in CharacterLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield CharacterLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A boolean literal, either true or false. + */ +schema BooleanLiteral extends Literal { + +} +impl BooleanLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *BooleanLiteral { + for (tmp in Literal(db)) { + for (l in BooleanLiteralDO(db)) { + if (tmp.key_eq(l)) { + yield BooleanLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A type literal, for example, "String.class". + */ +schema TypeLiteral extends Expression { + +} +impl TypeLiteral { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TypeLiteral { + for (tmp in Expression(db)) { + for (t in TypeLiteralDO(db)) { + if (tmp.key_eq(t)) { + yield TypeLiteral { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the type element of the element. + * @return TypeElement + */ + pub fn getTypeElement(self) -> TypeElement { + for (t in TypeLiteralDO(__all_data__), + element in TypeElement(__all_data__)) { + if (self.key_eq(t)) { + if (element.element_hash_id = t.getTypeElementHashId()) { + return element + } + } + } + } + /** + * @brief gets the reference type of the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__)) { + if (type = self.getTypeElement().getType()) { + return type + } + } + } + /** + * @brief gets the value of the element. + * @return string + */ + pub fn getValue(self) -> string { + return self.getPrintableText() + } +} diff --git a/language/java/lib/Location.gdl b/language/java/lib/Location.gdl new file mode 100644 index 00000000..c622a60c --- /dev/null +++ b/language/java/lib/Location.gdl @@ -0,0 +1,53 @@ +/** + * @brief The location information of a locatable elements. + */ +schema Location extends LocationDO { + +} +impl Location { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Location { + for (tmp in LocationDO(db)) { + yield Location { + element_hash_id : tmp.element_hash_id, + file_hash_id : tmp.file_hash_id, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number + } + } + } + /** + * @brief gets the file information for the location + * @return File + */ + pub fn getFile(self) -> File { + for (f in File(__all_data__)) { + if (f.element_hash_id = self.getFileHashId()) { + return f + } + } + } +} +/** + * @brief The number of lines for a java file. + */ +schema NumberOfLines extends NumberOfLinesDO { + +} +impl NumberOfLines { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NumberOfLines { + for (tmp in NumberOfLinesDO(db)) { + yield NumberOfLines { + element_hash_id : tmp.element_hash_id, + number_of_total_lines : tmp.number_of_total_lines, + number_of_valid_lines : tmp.number_of_valid_lines, + number_of_comment_lines : tmp.number_of_comment_lines + } + } + } +} diff --git a/language/java/lib/Method.gdl b/language/java/lib/Method.gdl new file mode 100644 index 00000000..fc98301b --- /dev/null +++ b/language/java/lib/Method.gdl @@ -0,0 +1,388 @@ +/** + * @brief A java method. + */ +schema Method extends MethodDO { + +} +impl Method { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Method { + for (tmp in MethodDO(db)) { + yield Method { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + signature : tmp.signature, + type_hash_id : tmp.type_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + definition_body : tmp.definition_body + } + } + } + /** + * @brief gets the class contains the Method + * @return Class + */ + pub fn getBelongedClass(self) -> Class { + for (tmp in Class(__all_data__)) { + if (tmp.element_hash_id = self.getParentHashId()) { + return tmp + } + } + } + /** + * @brief gets the modifier of the Method + * @return Modifier + */ + pub fn getModifier(self) -> *Modifier { + for (mo in Modifier(__all_data__), + list in ModifierList(__all_data__)) { + if (mo.getModifierList() = list) { + if (list.getMethodParent() = self) { + yield mo + } + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_hash_id = self.getLocationHashId()) { + return n + } + } + } + /** + * @brief gets the annotation of the method, if any. + * @return Annotation + */ + pub fn getAnnotation(self) -> *Annotation { + for (relation in AnnotatedRelation(__all_data__)) { + if (self.element_hash_id = relation.getAnnotatedItemHashId()) { + yield Annotation(__all_data__).find(relation) + } + } + } + /** + * @brief gets the parameter of the method, if any. + * @return Parameter + */ + pub fn getParameter(self) -> *Parameter { + for (param in Parameter(__all_data__)) { + if (self.element_hash_id = param.getParentHashId()) { + yield param + } + } + } + /** + * @brief gets a method access expression that calls the method. + * @return MethodAccessExpression + */ + pub fn getAnAccess(self) -> *MethodAccessExpression { + for (cc in CallableBinding(__all_data__)) { + if (self.key_eq(cc.getCallee())) { + yield MethodAccessExpression(__all_data__).find(cc) + } + } + } + /** + * @brief gets the parent of the method. + * @return ClassOrInterface + */ + pub fn getParent(self) -> ClassOrInterface { + for (c in ClassOrInterface(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the body of the method. + * @return CodeBlock + */ + pub fn getBody(self) -> CodeBlock { + for (body in CodeBlock(__all_data__)) { + if (self.key_eq(body.getParent())) { + return body + } + } + } + /** + * @description gets the Throw list of the method, if any. + * @return ReferenceList + */ + pub fn getThrowsList(self) -> ReferenceList { + for (r in ReferenceList(__all_data__)) { + if (self.key_eq(r.getParent())) { + if (r.getRole() = "THROWS_LIST") { + return r + } + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__)) { + if (type.id = self.getTypeHashId()) { + return type + } + } + } + /** + * @brief gets the return type element for the method. + * @return TypeElement + */ + pub fn getReturnTypeElement(self) -> TypeElement { + for (t in TypeElement(__all_data__)) { + if (self.key_eq(t.getParent())) { + return t + } + } + } + /** + * @brief gets the polymorphism methods of the method, if any. + * @return Method + */ + pub fn getPolyMethod(self) -> *Method { + for (m in Method(__all_data__)) { + if (matchedMethod(self, m)) { + for (auto_tmp1 in m.getBelongedClass().getAnAscentantClassOrInterface()) { + if (auto_tmp1 = self.getParent()) { + yield m + } + } + } + } + } +} +/** + * @brief An Exception represents an element listed in the `throws` clause of a method of constructor. + * + * For example, `E` is an exception thrown by method `m` in + * `void m() throws E;`, whereas `T` is an exception _type_ in + * `class T extends Exception { }`. + */ +schema Exception extends ExceptionDO { + +} +impl Exception { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Exception { + for (tmp in ExceptionDO(db)) { + yield Exception { + element_hash_id : tmp.element_hash_id, + type_hash_id : tmp.type_hash_id, + callable_hash_id : tmp.callable_hash_id, + name : tmp.name + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> ReferenceType { + for (type in ReferenceType(__all_data__)) { + if (type.oid = self.getTypeHashId()) { + return type + } + } + } + /** + * @brief gets the method of the exception element. + * @return Method + */ + pub fn getCallable(self) -> Method { + for (m in Method(__all_data__)) { + if (m.element_hash_id = self.getCallableHashId()) { + return m + } + } + } + /** + * @brief gets the Class of the exception element. + * @return Class + */ + pub fn getClass(self) -> Class { + for (m in Class(__all_data__)) { + if (m.element_hash_id = self.getCallableHashId()) { + return m + } + } + } +} +/** + * @brief A super expression. + */ +schema SuperExpression extends Expression { + +} +impl SuperExpression { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SuperExpression { + for (tmp in Expression(db)) { + for (s in SuperExpressionDO(db)) { + if (tmp.key_eq(s)) { + yield SuperExpression { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A super expression. + */ +schema SuperExpressionWithQualifier extends SuperExpression { + +} +impl SuperExpressionWithQualifier { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SuperExpressionWithQualifier { + for (tmp in SuperExpression(db)) { + for (s in SuperExpressionWithQualifierDO(db)) { + if (tmp.key_eq(s)) { + yield SuperExpressionWithQualifier { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the Qualifier of the expression, if any. + * @return ReferenceElement + */ + pub fn getQualifier(self) -> ReferenceElement { + for (c in ReferenceElement(__all_data__)) { + for (s in SuperExpressionWithQualifierDO(__all_data__)) { + if (self.key_eq(s)) { + if (c.element_hash_id = s.getQualifierHashId()) { + return c + } + } + } + } + } +} +schema NpMethod extends NpMethodDO { + +} +impl NpMethod { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NpMethod { + for (tmp in NpMethodDO(db)) { + for (m in NpMethodDO(db)) { + if (tmp = m) { + yield NpMethod { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + signature : tmp.signature, + type_hash_id : tmp.type_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + } + } + /** + * @brief gets the type for this element. + * @return Type + */ + pub fn getType(self) -> ReferenceType { + for (type in ReferenceType(__all_data__)) { + if (type.oid = self.getTypeHashId()) { + return type + } + } + } + /** + * @brief gets the parent of this element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } +} +fn getMethodNameWithParam(method: Method, name: string) -> bool { + let(temp1 = method.getSignature(), callable = Callable(__all_data__).find(method)) { + if (isAnonymousMethod(callable)) { + let (temp2 = "null", j = temp2.len() + 1, i = temp1.len() - j) { + if (name = temp1.substr(j, i)) { + return true + } + } + } + if (!isAnonymousMethod(callable)) { + let (temp2 = method.getParent().getQualifiedName(), j = temp2.len() + 1, i = temp1.len() - j) { + if (name = temp1.substr(j, i)) { + return true + } + } + } + } +} +fn matchedMethod(m: Method, n: Method) -> bool { + if (m.getName() = n.getName()) { + let (i = m.getParameter().len(), j = n.getParameter().len()) { + if (i = j) { + if (i = 0 && j = 0) { + return true + } + if (i > 0 && j > 0) { + for(temp1 in string::__undetermined_all__()) { + return getMethodNameWithParam(m, temp1) && getMethodNameWithParam(n, temp1) + } + } + } + } + } +} diff --git a/language/java/lib/Modifier.gdl b/language/java/lib/Modifier.gdl new file mode 100644 index 00000000..c2dbf9a5 --- /dev/null +++ b/language/java/lib/Modifier.gdl @@ -0,0 +1,160 @@ +/** + * @brief A modifier keywords for java classes, methods and fields. + */ +schema Modifier extends ModifierDO { + +} +impl Modifier { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Modifier { + for (tmp in ModifierDO(db)) { + yield Modifier { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the modifier list of the modifier occurs. + * @return ModifierList + */ + pub fn getModifierList(self) -> ModifierList { + for (list in ModifierList(__all_data__)) { + if (list.element_hash_id = self.getParentHashId()) { + return list + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} +/** + * @brief A list of modifiers and annotations on a java element (class, method, field and so on). + */ +schema ModifierList extends ModifierListDO { + +} +impl ModifierList { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ModifierList { + for (tmp in ModifierListDO(db)) { + yield ModifierList { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the parent of the modifier list if the parent is a class. + * @return Class + */ + pub fn getClassParent(self) -> Class { + for (c in Class(__all_data__)) { + if (c.element_hash_id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets the parent of the modifier list if the parent is a Method. + * @return Method + */ + pub fn getMethodParent(self) -> Method { + for (m in Method(__all_data__)) { + if (m.element_hash_id = self.getParentHashId()) { + return m + } + } + } + /** + * @brief gets the parent of the modifier list if the parent is a Field. + * @return Field + */ + pub fn getFieldParent(self) -> Field { + for (f in Field(__all_data__)) { + if (f.element_hash_id = self.getParentHashId()) { + return f + } + } + } + /** + * @brief gets the parent of the modifier list if the parent is a Constructor. + * @return Constructor + */ + pub fn getConstructorParent(self) -> Constructor { + for (con in Constructor(__all_data__)) { + if (con.element_hash_id = self.getParentHashId()) { + return con + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} diff --git a/language/java/lib/Parameter.gdl b/language/java/lib/Parameter.gdl new file mode 100644 index 00000000..9270d0d9 --- /dev/null +++ b/language/java/lib/Parameter.gdl @@ -0,0 +1,340 @@ +/** + * @brief A parameter of a method, foreach statement or catch block. + */ +schema Parameter extends ParameterDO { + +} +impl Parameter { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Parameter { + for (tmp in ParameterDO(db)) { + yield Parameter { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + index_order : tmp.index_order, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type_hash_id : tmp.type_hash_id + } + } + } + /** + * @brief gets the identifier of the parameter. + * @return Identifier + */ + pub fn getIdentifier(self) -> Identifier { + for (ident in Identifier(__all_data__)) { + if (self.key_eq(ident.getParent())) { + return ident + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__)) { + if (type.id = self.getTypeHashId()) { + return type + } + } + } + /** + * @brief gets the type element for the element. + * @return TypeElement + */ + pub fn getTypeElement(self) -> TypeElement { + for (type in TypeElement(__all_data__)) { + if (self.element_hash_id = type.getParentHashId()) { + return type + } + } + } + /** + * @brief gets the parent of the element, which can be a for each statement, lambda expression, a callable, or a catch clause section. + * @return ExpressionParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the name of the parameter + * @return string + */ + pub fn getTypeName(self) -> string { + for (type in Type(__all_data__)) { + let (name = type.getName()) { + if (type.id = self.getTypeHashId()) { + return name + } + } + } + } + /** + * @brief gets the annotation of the class, if any. + * @return Annotation + */ + pub fn getAnnotation(self) -> Annotation { + for (anno in Annotation(__all_data__), + relation in AnnotatedRelation(__all_data__)) { + if (self.element_hash_id = relation.getAnnotatedItemHashId()) { + if (anno.key_eq(relation)) { + return anno + } + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} +/** + * @brief A type parameter of a generic class, interface, method or constructor. + */ +schema TypeParameter extends TypeParameterDO { + +} +impl TypeParameter { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TypeParameter { + for (tmp in TypeParameterDO(db)) { + yield TypeParameter { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + owner_hash_id : tmp.owner_hash_id, + index_order : tmp.index_order, + extends_list_hash_id : tmp.extends_list_hash_id, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the parent of the element. + * @return ExpressionParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the element which is parameterized by the type parameter. + * @return ExpressionParent + */ + pub fn getOwner(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets the extends list id (reference list)of the type parameter. + * @return ExpressionParent + */ + pub fn getExtendsList(self) -> ReferenceList { + for (parent in ReferenceList(__all_data__)) { + if (parent.element_hash_id = self.getExtendsListHashId()) { + return parent + } + } + } +} +/** + * @brief A variable is a field (or an enum constant), a local variable or a parameter. + */ +schema Variable { + @primary id: int +} +impl Variable { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Variable { + for (l in LocalVariable(db)) { + yield Variable {id : l.element_hash_id} + } + for (f in Field(db)) { + yield Variable {id : f.element_hash_id} + } + for (e in EnumConstant(db)) { + yield Variable {id : e.element_hash_id} + } + for (p in Parameter(db)) { + yield Variable {id : p.element_hash_id} + } + } + /** + * @brief gets the name of the element. + * @return string + */ + pub fn getName(self) -> string { + for (l in LocalVariable(__all_data__)) { + if (self.key_eq(l)) { + let (s = l.getName()) { + return s + } + } + } + for (f in Field(__all_data__)) { + if (self.key_eq(f)) { + let (s = f.getName()) { + return s + } + } + } + for (e in EnumConstant(__all_data__)) { + if (self.key_eq(e)) { + let (s = e.getName()) { + return s + } + } + } + for (p in Parameter(__all_data__)) { + if (self.key_eq(p)) { + let (s = p.getName()) { + return s + } + } + } + } + /** + * @brief gets the type of the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (l in LocalVariable(__all_data__)) { + if (self.key_eq(l)) { + return l.getType() + } + } + for (f in Field(__all_data__)) { + if (self.key_eq(f)) { + return f.getType() + } + } + for (e in EnumConstant(__all_data__)) { + if (self.key_eq(e)) { + return e.getType() + } + } + for (p in Parameter(__all_data__)) { + if (self.key_eq(p)) { + return p.getType() + } + } + } + /** + * @brief gets the location of the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (l in LocalVariable(__all_data__)) { + if (self.key_eq(l)) { + return l.getLocation() + } + } + for (f in Field(__all_data__)) { + if (self.key_eq(f)) { + return f.getLocation() + } + } + for (e in EnumConstant(__all_data__)) { + if (self.key_eq(e)) { + return e.getLocation() + } + } + for (p in Parameter(__all_data__)) { + if (self.key_eq(p)) { + return p.getLocation() + } + } + } + /** + * @brief gets the directly usage of the element. + * @return ReferenceExpression + */ + pub fn getDirectUsage(self) -> *ReferenceExpression { + for (r in ReferenceExpression(__all_data__)) { + for (l in LocalVariable(__all_data__)) { + if (self.key_eq(l)) { + if (l.key_eq(r.getDefinition())) { + yield r + } + } + } + for (f in Field(__all_data__)) { + if (self.key_eq(f)) { + if (f.key_eq(r.getDefinition())) { + yield r + } + } + } + for (e in EnumConstant(__all_data__)) { + if (self.key_eq(e)) { + if (e.key_eq(r.getDefinition())) { + yield r + } + } + } + for (p in Parameter(__all_data__)) { + if (self.key_eq(p)) { + if (p.key_eq(r.getDefinition())) { + yield r + } + } + } + } + } +} diff --git a/language/java/lib/Parent.gdl b/language/java/lib/Parent.gdl new file mode 100644 index 00000000..c5cca2a5 --- /dev/null +++ b/language/java/lib/Parent.gdl @@ -0,0 +1,1234 @@ +/** + * @brief A ast parent of a coref element. + */ +schema ElementParent { + @primary id: int +} +impl ElementParent { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ElementParent { + for (s in Statement(db)) { + yield ElementParent {id : s.element_hash_id} + } + for (e in Expression(db)) { + yield ElementParent {id : e.element_hash_id} + } + for (var in LocalVariable(db)) { + yield ElementParent {id : var.element_hash_id} + } + for (m in Method(db)) { + yield ElementParent {id : m.element_hash_id} + } + for (c in Constructor(db)) { + yield ElementParent {id : c.element_hash_id} + } + for (f in Field(db)) { + yield ElementParent {id : f.element_hash_id} + } + for (clazz in Class(db)) { + yield ElementParent {id : clazz.element_hash_id} + } + for (inf in Interface(db)) { + yield ElementParent {id : inf.element_hash_id} + } + for (p in Parameter(db)) { + yield ElementParent {id : p.element_hash_id} + } + for (cb in CodeBlock(db)) { + yield ElementParent {id : cb.element_hash_id} + } + for (ident in Identifier(db)) { + yield ElementParent {id : ident.element_hash_id} + } + for (te in TypeElement(db)) { + yield ElementParent {id : te.element_hash_id} + } + for (mo in Modifier(db)) { + yield ElementParent {id : mo.element_hash_id} + } + for (el in ExpressionList(db)) { + yield ElementParent {id : el.element_hash_id} + } + for (ml in ModifierList(db)) { + yield ElementParent {id : ml.element_hash_id} + } + for (ac in AnonymousClass(db)) { + yield ElementParent {id : ac.element_hash_id} + } + for (comment in Comment(db)) { + yield ElementParent {id : comment.element_hash_id} + } + for (ai in AnnotationArrayInitializer(db)) { + yield ElementParent {id : ai.element_hash_id} + } + for (file in File(db)) { + yield ElementParent {id : file.element_hash_id} + } + for (root in Program(db)) { + yield ElementParent {id : root.program_hash_id} + } + for (de in DeclaredElement(db)) { + yield ElementParent {id : de.element_hash_id} + } + for (re in ReferenceElement(db)) { + yield ElementParent {id : re.element_hash_id} + } + for (im in Import(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in ReferenceList(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in Annotation(db)) { + yield ElementParent {id : im.id} + } + for (im in JavadocComment(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in ReferenceParameterList(db)) { + yield ElementParent {id : im.id} + } + for (im in ImportStaticStatement(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in ImportStaticReferenceElement(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in ResourceList(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in ClassInitializer(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in CatchClause(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in EnumConstant(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in PackageStatement(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in JavadocTag(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in AnnotationAccessArgument(db)) { + yield ElementParent {id : im.id} + } + for (l in LocalClass(db)) { + yield ElementParent {id : l.element_hash_id} + } + for (im in JavadocTagValue(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (im in JavadocDataToken(db)) { + yield ElementParent {id : im.element_hash_id} + } + for (nf in NpFile(db)) { + yield ElementParent {id : nf.element_hash_id} + } + for (nc in NpClass(db)) { + yield ElementParent {id : nc.element_hash_id} + } + for (ni in NpInterface(db)) { + yield ElementParent {id : ni.element_hash_id} + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getElementParent(self) -> ElementParent { + for (tmp in Expression(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in LocalVariable(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in Method(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getParent())) { + return parent + } + } + } + } + for (tmp in Constructor(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getParent())) { + return parent + } + } + } + } + for (tmp in Field(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getParent())) { + return parent + } + } + } + } + for (tmp in Class(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in Interface(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in Parameter(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in CodeBlock(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in Statement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in Identifier(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in TypeElement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in Modifier(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in ExpressionList(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in ReferenceList(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in ModifierList(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in AnonymousClass(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getParent())) { + return parent + } + } + } + } + for (tmp in Comment(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in AnnotationArrayInitializer(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getParent())) { + return parent + } + } + } + } + for (tmp in ReferenceElement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in File(__all_data__), + p in Program(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(p)) { + return parent + } + } + } + } + for (tmp in Import(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getContainingFile())) { + return parent + } + } + } + } + for (tmp in Annotation(__all_data__)) { + if (self.id = tmp.id) { + return tmp.getParent() + } + } + for (tmp in JavadocComment(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in ReferenceParameterList(__all_data__)) { + if (self.id = tmp.id) { + return tmp.getParent() + } + } + for (tmp in ImportStaticStatement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getParent())) { + return parent + } + } + } + } + for (tmp in ImportStaticReferenceElement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getParent())) { + return parent + } + } + } + } + for (tmp in ResourceList(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in ClassInitializer(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in TypeLiteral(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in CatchClause(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in EnumConstant(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getParent())) { + return parent + } + } + } + } + for (tmp in PackageStatement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in JavadocTag(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getComment())) { + return parent + } + } + } + } + for (tmp in AnnotationAccessArgument(__all_data__)) { + if (self.id = tmp.id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getAnnotation())) { + return parent + } + } + } + } + for (tmp in LocalClass(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + for (tmp in JavadocTagValue(__all_data__)) { + if (self.id = tmp.element_hash_id) { + for (parent in ElementParent(__all_data__)) { + if (parent.key_eq(tmp.getJavaDocTag())) { + return parent + } + } + } + } + for (tmp in JavadocDataToken(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getParent() + } + } + } + /** + * @brief gets the location info of the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (tmp in Expression(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in LocalVariable(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Method(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Constructor(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Field(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Class(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Interface(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Parameter(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in CodeBlock(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Statement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Identifier(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in TypeElement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Modifier(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in ExpressionList(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in ReferenceList(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in ModifierList(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in AnonymousClass(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Comment(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in AnnotationArrayInitializer(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in ReferenceElement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Import(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in Program(__all_data__)) { + if (self.id = tmp.program_hash_id) { + for (l in Location(__all_data__)) { + if (l.element_hash_id = 0) { + return l + } + } + } + } + for (tmp in Annotation(__all_data__)) { + if (self.id = tmp.id) { + return tmp.getLocation() + } + } + for (tmp in JavadocComment(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in ReferenceParameterList(__all_data__)) { + if (self.id = tmp.id) { + return tmp.getLocation() + } + } + for (tmp in ImportStaticStatement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in ImportStaticReferenceElement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in ResourceList(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in ClassInitializer(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in TypeLiteral(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in CatchClause(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in EnumConstant(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in PackageStatement(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in JavadocTag(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in AnnotationAccessArgument(__all_data__)) { + if (self.id = tmp.id) { + return tmp.getLocation() + } + } + for (tmp in LocalClass(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in JavadocTagValue(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + for (tmp in JavadocDataToken(__all_data__)) { + if (self.id = tmp.element_hash_id) { + return tmp.getLocation() + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + yield self.getElementParent() + for (auto_tmp1 in self.getAnAncestor()) { + yield auto_tmp1.getElementParent() + } + } + /** + * @brief gets the index for printing AST. + * @return int + */ + pub fn getAnAncestorForIndex(self, index : int) -> ElementParent { + let (ancestor = self.getElementParent()) { + if (index = 1) { + return ancestor + } + } + for (indexTemp in int::__undetermined_all__()) { + let (temp = self.getElementParent()) { + let (ancestor = temp.getAnAncestorForIndex(indexTemp)) { + if (index = indexTemp + 1) { + return ancestor + } + } + } + } + } + /** + * @brief gets the type of the element for printing AST. + * @return string + */ + pub fn getType(self) -> string { + for (s in Statement(__all_data__)) { + if (self.id = s.element_hash_id) { + if (isBlock(s)) { + let (text = "BlockStatement") { + return text + } + } + if (!isBlock(s)) { + let (text = "Statement") { + return text + } + } + } + } + for (e in Expression(__all_data__)) { + if (self.id = e.element_hash_id) { + let (text = "Expression") { + return text + } + } + } + for (m in Method(__all_data__)) { + if (self.id = m.element_hash_id) { + let (text = "Method") { + return text + } + } + } + for (c in Constructor(__all_data__)) { + if (self.id = c.element_hash_id) { + let (text = "Constructor") { + return text + } + } + } + for (f in Field(__all_data__)) { + if (self.id = f.element_hash_id) { + let (text = "Field") { + return text + } + } + } + for (clazz in Class(__all_data__)) { + if (self.id = clazz.element_hash_id) { + let (text = "Class") { + return text + } + } + } + for (inf in Interface(__all_data__)) { + if (self.id = inf.element_hash_id) { + let (text = "Interface") { + return text + } + } + } + for (p in Parameter(__all_data__)) { + if (self.id = p.element_hash_id) { + let (text = "Parameter") { + return text + } + } + } + for (var in LocalVariable(__all_data__)) { + if (self.id = var.element_hash_id) { + let (text = "LocalVariable") { + return text + } + } + } + for (cb in CodeBlock(__all_data__)) { + if (self.id = cb.element_hash_id) { + let (text = "CodeBlock") { + return text + } + } + } + for (ident in Identifier(__all_data__)) { + if (self.id = ident.element_hash_id) { + let (text = "Identifier") { + return text + } + } + } + for (te in TypeElement(__all_data__)) { + if (self.id = te.element_hash_id) { + let (text = "TypeElement") { + return text + } + } + } + for (mo in Modifier(__all_data__)) { + if (self.id = mo.element_hash_id) { + let (text = "Keyword") { + return text + } + } + } + for (el in ExpressionList(__all_data__)) { + if (self.id = el.element_hash_id) { + let (text = "ExpressionList") { + return text + } + } + } + for (ml in ModifierList(__all_data__)) { + if (self.id = ml.element_hash_id) { + let (text = "ModifierList") { + return text + } + } + } + for (ac in AnonymousClass(__all_data__)) { + if (self.id = ac.element_hash_id) { + let (text = "Anonymousclass") { + return text + } + } + } + for (comment in Comment(__all_data__)) { + if (self.id = comment.element_hash_id) { + let (text = "Comment") { + return text + } + } + } + for (ai in AnnotationArrayInitializer(__all_data__)) { + if (self.id = ai.element_hash_id) { + let (text = "AnnotationArrayInitializer") { + return text + } + } + } + for (re in ReferenceElement(__all_data__)) { + if (self.id = re.element_hash_id) { + let (text = "ReferenceElement") { + return text + } + } + } + for (im in Import(__all_data__)) { + if (self.id = im.element_hash_id) { + let (text = "ImportStatement") { + return text + } + } + } + for (im in ReferenceList(__all_data__)) { + if (self.id = im.element_hash_id) { + let (text = "ReferenceList") { + return text + } + } + } + for (de in File(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "File") { + return text + } + } + } + for (de in Annotation(__all_data__)) { + if (self.id = de.id) { + let (text = "Annotation") { + return text + } + } + } + for (de in JavadocComment(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "JavaDocComment") { + return text + } + } + } + for (de in JavadocTag(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "JavaDocTag") { + return text + } + } + } + for (de in ReferenceParameterList(__all_data__)) { + if (self.id = de.id) { + let (text = "ReferenceParameterList") { + return text + } + } + } + for (de in ImportStaticStatement(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "ImportStaticStatement") { + return text + } + } + } + for (de in ImportStaticReferenceElement(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "ImportStaticReferenceElement") { + return text + } + } + } + for (de in ResourceList(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "ResourceList") { + return text + } + } + } + for (de in ClassInitializer(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "ClassInitializer") { + return text + } + } + } + for (de in CatchClause(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "CatchClauseSection") { + return text + } + } + } + for (de in EnumConstant(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "EnumConstant") { + return text + } + } + } + for (de in PackageStatement(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "PackageStatement") { + return text + } + } + } + for (de in AnnotationAccessArgument(__all_data__)) { + if (self.id = de.id) { + let (text = "AnnotationArgument") { + return text + } + } + } + for (de in LocalClass(__all_data__)) { + if (self.id = de.element_hash_id) { + let (text = "LocalClass") { + return text + } + } + } + for (im in JavadocTagValue(__all_data__)) { + if (self.id = im.element_hash_id) { + let (text = "JavadocTagValue") { + return text + } + } + } + for (im in JavadocDataToken(__all_data__)) { + if (self.id = im.element_hash_id) { + let (text = "JavadocDataToken") { + return text + } + } + } + } + /** + * @brief gets the printable text for printing AST + * @return string + */ + pub fn print(self) -> string { + for (s in Statement(__all_data__)) { + if (self.key_eq(s)) { + let (i = s.getSize().getNumberOfLines()) { + if (i > 4) { + let (text = s.getType()) { + return text + } + } + if (i <= 4) { + let (text = s.getPrintableText()) { + return text + } + } + } + } + } + for (e in Expression(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (m in Method(__all_data__)) { + if (self.key_eq(m)) { + let (text = m.getName()) { + return text + } + } + } + for (c in Constructor(__all_data__)) { + if (self.key_eq(c)) { + let (text = c.getName()) { + return text + } + } + } + for (f in Field(__all_data__)) { + if (self.key_eq(f)) { + let (text = f.getName()) { + return text + } + } + } + for (clazz in Class(__all_data__)) { + if (self.key_eq(clazz)) { + let (text = clazz.getQualifiedName()) { + return text + } + } + } + for (inf in Interface(__all_data__)) { + if (self.key_eq(inf)) { + let (text = inf.getQualifiedName()) { + return text + } + } + } + for (p in Parameter(__all_data__)) { + if (self.key_eq(p)) { + let (text = p.getPrintableText()) { + return text + } + } + } + for (var in LocalVariable(__all_data__)) { + if (self.key_eq(var)) { + let (text = var.getPrintableText()) { + return text + } + } + } + for (cb in CodeBlock(__all_data__)) { + if (self.key_eq(cb)) { + let (text = "CodeBlock{...}") { + return text + } + } + } + for (ident in Identifier(__all_data__)) { + if (self.key_eq(ident)) { + let (text = ident.getName()) { + return text + } + } + } + for (te in TypeElement(__all_data__)) { + if (self.key_eq(te)) { + let (text = te.getPrintableText()) { + return text + } + } + } + for (mo in Modifier(__all_data__)) { + if (self.key_eq(mo)) { + let (text = mo.getName()) { + return text + } + } + } + for (el in ExpressionList(__all_data__)) { + if (self.key_eq(el)) { + let (text = el.getPrintableText()) { + return text + } + } + } + for (ml in ModifierList(__all_data__)) { + if (self.key_eq(ml)) { + let (text = "modifierlist") { + return text + } + } + } + for (ac in AnonymousClass(__all_data__)) { + if (self.key_eq(ac)) { + let (text = "anonymousclass") { + return text + } + } + } + for (comment in Comment(__all_data__)) { + if (self.key_eq(comment)) { + let (text = comment.getText()) { + return text + } + } + } + for (ai in AnnotationArrayInitializer(__all_data__)) { + if (self.key_eq(ai)) { + let (text = ai.getPrintableText()) { + return text + } + } + } + for (re in ReferenceElement(__all_data__)) { + if (self.key_eq(re)) { + let (text = re.getPrintableText()) { + return text + } + } + } + for (im in Import(__all_data__)) { + if (self.key_eq(im)) { + let (text = im.getName()) { + return text + } + } + } + for (im in ReferenceList(__all_data__)) { + if (self.key_eq(im)) { + let (text = im.getPrintableText()) { + return text + } + } + } + for (de in File(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getRelativePath()) { + return text + } + } + } + for (de in Annotation(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getName()) { + return text + } + } + } + for (de in JavadocComment(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getText()) { + return text + } + } + } + for (de in JavadocTag(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getName()) { + return text + } + } + } + for (de in ReferenceParameterList(__all_data__)) { + if (self.key_eq(de)) { + let (text = "ReferenceParameterList") { + return text + } + } + } + for (de in ImportStaticStatement(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getName()) { + return text + } + } + } + for (de in ImportStaticReferenceElement(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getPrintableText()) { + return text + } + } + } + for (de in ResourceList(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getPrintableText()) { + return text + } + } + } + for (de in ClassInitializer(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getPrintableText()) { + return text + } + } + } + for (de in CatchClause(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getPrintableText()) { + return text + } + } + } + for (de in EnumConstant(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getName()) { + return text + } + } + } + for (de in PackageStatement(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getQualifiedName()) { + return text + } + } + } + for (de in AnnotationAccessArgument(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getPrintableText()) { + return text + } + } + } + for (de in LocalClass(__all_data__)) { + if (self.key_eq(de)) { + let (text = de.getName()) { + return text + } + } + } + for (im in JavadocTagValue(__all_data__)) { + if (self.key_eq(im)) { + let (text = im.getValue()) { + return text + } + } + } + for (im in JavadocDataToken(__all_data__)) { + if (self.key_eq(im)) { + let (text = im.getValue()) { + return text + } + } + } + } +} +/** + * @brief A ast parent of a statement. + */ +schema StatementParent extends ElementParent { + +} +impl StatementParent { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *StatementParent { + for (tmp in ElementParent(db)) { + for (s in Statement(db)) { + if (tmp = s.getParent()) { + yield StatementParent { + id : tmp.id + } + } + } + } + } + /** + * @brief get a child statement of the element. + * @return Statement + */ + pub fn getChild(self) -> *Statement { + for (s in Statement(__all_data__)) { + if (self.key_eq(s.getParent())) { + yield s + } + } + } +} +/** + * @brief A ast parent of an expression. + */ +schema ExpressionParent extends ElementParent { + +} +impl ExpressionParent { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionParent { + for (tmp in ElementParent(db)) { + for (s in Expression(db)) { + if (tmp = s.getParent()) { + yield ExpressionParent { + id : tmp.id + } + } + } + } + } + /** + * @brief get a child expression of the element. + * @return Expression + */ + pub fn getChild(self) -> *Expression { + for (s in Expression(__all_data__)) { + if (self.key_eq(s.getParent())) { + yield s + } + } + } +} +pub fn isBlock(s : Statement) -> bool { + for (b in BlockStatement(__all_data__)) { + if (b.key_eq(s)) { + return true + } + } +} diff --git a/language/java/lib/Statement.gdl b/language/java/lib/Statement.gdl new file mode 100644 index 00000000..4de173a7 --- /dev/null +++ b/language/java/lib/Statement.gdl @@ -0,0 +1,2220 @@ +/** + * @brief A super class for all statements. + */ +schema Statement extends StatementDO { + +} +impl Statement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Statement { + for (tmp in StatementDO(db)) { + yield Statement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_hash_id = self.getLocationHashId()) { + return n + } + } + } + /** + * @brief gets the parent element of the statement + * @return StatementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the immediately enclosing callable (method or constructor) whose body contains this statement. + * @return Callable + */ + pub fn getEnclosingCallable(self) -> Callable { + for (c in CallableEnclosingStatement(__all_data__)) { + if (self.key_eq(c)) { + return c.getEnclosingCallable() + } + } + } + /** + * @brief gets a child of this statement. + * @return Statement + */ + pub fn getAChild(self) -> *Statement { + for (child in Statement(__all_data__)) { + if (self.key_eq(child.getParent())) { + yield child + } + } + } + /** + * @brief gets the statement containing this statement. + * @return Statement + */ + pub fn getEnclosingStatement(self) -> Statement { + for (stmt in Statement(__all_data__)) { + if (stmt.element_hash_id = self.getParentHashId()) { + return stmt + } + } + } + /** + * @brief gets the transitive statement containing this statement. + * @return Statement + */ + pub fn getAEnclosingStatement(self) -> *Statement { + for (stmt in Statement(__all_data__), + temp in Statement(__all_data__)) { + if (stmt = self.getEnclosingStatement()) { + yield stmt + } + for (auto_tmp1 in self.getAEnclosingStatement()) { + if (temp = auto_tmp1) { + for (auto_tmp2 in temp.getAEnclosingStatement()) { + if (stmt = auto_tmp2) { + yield stmt + } + } + } + } + } + } +} +/** + * @brief A callable enclosing statement relation class. + */ +schema CallableEnclosingStatement extends CallableEnclosingStatementDO { + +} +impl CallableEnclosingStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CallableEnclosingStatement { + for (tmp in CallableEnclosingStatementDO(db)) { + yield CallableEnclosingStatement { + statement_hash_id : tmp.statement_hash_id, + callable_hash_id : tmp.callable_hash_id + } + } + } + /** + * @brief gets the enclosing callable of a statement, if any. + * @return Callable + */ + pub fn getEnclosingCallable(self) -> Callable { + for (c in Callable(__all_data__)) { + if (c.id = self.getCallableHashId()) { + return c + } + } + } +} +/** + * @brief A block statement (sequence of statements surrounded with curly braces). + */ +schema BlockStatement extends Statement { + +} +impl BlockStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *BlockStatement { + for (tmp in Statement(db)) { + for (bs in BlockStatementDO(db)) { + if (tmp.key_eq(bs)) { + yield BlockStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets a statement that is an immediate child of the block. + * @return Statement + */ + pub fn getAStatement(self) -> *Statement { + for (s in Statement(__all_data__)) { + if (self.getCodeBlock().element_hash_id = s.getParentHashId()) { + yield s + } + } + } + /** + * @brief gets a statement that is an immediate child of the block. + * @return Statement + */ + pub fn getStatement(self, idx : int) -> Statement { + for (s in Statement(__all_data__)) { + if (self.getCodeBlock().element_hash_id = s.getParentHashId()) { + if (s.getIndex() = idx) { + return s + } + } + } + } + /** + * @brief gets the number of immediate child statements in this block. + * @return int + */ + pub fn getNumberOfStatement(self) -> int { + return self.getCodeBlock().getNumberOfStatement() + } + /** + * @brief description + * @return Statement + */ + pub fn getLastStatement(self) -> Statement { + for (s in Statement(__all_data__)) { + let (num = self.getNumberOfStatement()) { + if (s = self.getStatement(num - 1)) { + return s + } + } + } + } + /** + * @brief gets the code block of the block statement. + * @return CodeBlock + */ + pub fn getCodeBlock(self) -> CodeBlock { + for (cb in CodeBlock(__all_data__), + bs in BlockStatementDO(__all_data__)) { + if (self.key_eq(bs)) { + if (cb.element_hash_id = bs.getCodeBlockHashId()) { + return cb + } + } + } + } +} +/** + * @brief A code block, usually surrounded by curly braces. + */ +schema CodeBlock extends CodeBlockDO { + +} +impl CodeBlock { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CodeBlock { + for (tmp in CodeBlockDO(db)) { + yield CodeBlock { + element_hash_id : tmp.element_hash_id, + number_of_statement : tmp.number_of_statement, + parent_hash_id : tmp.parent_hash_id, + is_empty : tmp.is_empty, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the parent code block of the try statement + * @return CodeBlock + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets the immediate child statement of this code block that occurs at the specified (zero-based) position. + * @return Statement + */ + pub fn getAStatement(self) -> *Statement { + for (stmt in Statement(__all_data__)) { + if (self.key_eq(stmt.getParent())) { + yield stmt + } + } + } + /** + * @brief gets the i-th child statement of this code block that occurs at the specified (zero-based) position. + * @return Statement + */ + pub fn getStatement(self, idx : int) -> Statement { + for (stmt in Statement(__all_data__)) { + if (self.key_eq(stmt.getParent())) { + if (stmt.getIndex() = idx) { + return stmt + } + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} +/** + * @brief An assert statement. + */ +schema AssertStatement extends Statement { + +} +impl AssertStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *AssertStatement { + for (tmp in Statement(db)) { + for (s in AssertStatementDO(db)) { + if (tmp.key_eq(s)) { + yield AssertStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the boolean expression of the assert statement. + * @return Expression + */ + pub fn getCondition(self) -> Expression { + for (e in Expression(__all_data__), + s in AssertStatementDO(__all_data__)) { + if (self.key_eq(s)) { + if (e.element_hash_id = s.getAssertConditionHashId()) { + return e + } + } + } + } + /** + * @brief gets the description expression of the assert statement. + * @return Expression + */ + pub fn getAssertDescription(self) -> Expression { + for (e in Expression(__all_data__), + s in AssertStatementDO(__all_data__)) { + if (self.key_eq(s)) { + if (e.element_hash_id = s.getAssertDescriptionHashId()) { + return e + } + } + } + } +} +/** + * @brief A package statement. + */ +schema PackageStatement extends PackageStatementDO { + +} +impl PackageStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *PackageStatement { + for (tmp in PackageStatementDO(db)) { + yield PackageStatement { + element_hash_id : tmp.element_hash_id, + qualified_name : tmp.qualified_name, + location_hash_id : tmp.location_hash_id, + package_hash_id : tmp.package_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the resolved package for the project. + * @return Package + */ + pub fn getPackage(self) -> Package { + for (package1 in Package(__all_data__)) { + if (package1.id = self.getPackageHashId()) { + return package1 + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the declaration statement of the element + * @return Statement + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the containing file for the element. + * @return File + */ + pub fn getContainingFile(self) -> File { + for (f in File(__all_data__)) { + if (f.element_hash_id = self.getParentHashId()) { + return f + } + } + } +} +/** + * @brief A local class declaration statement. + */ +schema LocalClass extends LocalClassDO { + +} +impl LocalClass { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LocalClass { + for (tmp in LocalClassDO(db)) { + yield LocalClass { + element_hash_id : tmp.element_hash_id, + name : tmp.name, + printable_text : tmp.printable_text, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the declaration statement of the element + * @return Statement + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } +} +/** + * @brief A empty statement. + */ +schema EmptyStatement extends Statement { + +} +impl EmptyStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *EmptyStatement { + for (tmp in Statement(db)) { + for (s in EmptyStatementDO(db)) { + if (tmp.key_eq(s)) { + yield EmptyStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } +} +/** + * @brief A return statement. + */ +schema ReturnStatement extends Statement { + +} +impl ReturnStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReturnStatement { + for (tmp in Statement(db)) { + for (ret in ReturnStatementDO(db)) { + if (tmp.key_eq(ret)) { + yield ReturnStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the return result of the statement. + * @return Expression + */ + pub fn getResult(self) -> Expression { + for (expr in Expression(__all_data__), + ret in ReturnStatementDO(__all_data__)) { + if (self.key_eq(ret)) { + if (expr.element_hash_id = ret.getReturnExpressionHashId()) { + return expr + } + } + } + } +} +/** + * @brief A declaration statement DO class. + */ +schema DeclarationStatementDO { + @primary id: int +} +impl DeclarationStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DeclarationStatementDO { + for (tmp: DeclarationElementDO in db.declaration_element) { + yield DeclarationStatementDO { id: tmp.declaration_statement_hash_id } + } + } +} +/** + * @brief A declaration statement. + */ +schema DeclarationStatement extends Statement { + +} +impl DeclarationStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DeclarationStatement { + for (tmp in Statement(db)) { + for (dsr in DeclarationStatementDO(db)) { + if (tmp.key_eq(dsr)) { + yield DeclarationStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the declared element of the statement. + * @return DeclaredElement + */ + pub fn getDeclaredElement(self) -> *DeclaredElement { + for (element in DeclaredElement(__all_data__), + dsr in DeclarationStatementDO(__all_data__)) { + if (self.key_eq(dsr)) { + if (dsr.key_eq(element.getParent())) { + yield element + } + } + } + } + /** + * @brief gets the i-th declared element of the statement. + * @return DeclaredElement + */ + pub fn getIthDeclaredElement(self, idx : int) -> DeclaredElement { + for (element in DeclaredElement(__all_data__), + dsr in DeclarationStatementDO(__all_data__)) { + if (self.key_eq(dsr)) { + if (dsr.key_eq(element.getParent())) { + if (idx = element.getIndex()) { + return element + } + } + } + } + } +} +/** + * @brief A declared element in a declaration statement. + */ +schema DeclaredElement extends DeclarationElementDO { + +} +impl DeclaredElement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DeclaredElement { + for (tmp in DeclarationElementDO(db)) { + yield DeclaredElement { + element_hash_id : tmp.element_hash_id, + index_order : tmp.index_order, + declaration_statement_hash_id : tmp.declaration_statement_hash_id + } + } + } + /** + * @brief gets the declaration statement of the element + * @return Statement + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getDeclarationStatementHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the declaration statement of the element + * @return Statement + */ + pub fn getStatement(self) -> Statement { + for (parent in Statement(__all_data__)) { + if (parent.element_hash_id = self.getDeclarationStatementHashId()) { + return parent + } + } + } +} +/** + * @brief A throw statement. + */ +schema ThrowStatement extends Statement { + +} +impl ThrowStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ThrowStatement { + for (tmp in Statement(db)) { + for (ths in ThrowStatementDO(db)) { + if (tmp.key_eq(ths)) { + yield ThrowStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief description + * @return Expression + */ + pub fn getResult(self) -> ElementParent { + for (expr in ElementParent(__all_data__), + ths in ThrowStatementDO(__all_data__)) { + if (expr.id = ths.getExceptionHashId()) { + if (self.key_eq(ths)) { + return expr + } + } + } + } + /** + * @brief gets the body of the throwStatement. + * @return CodeBlock + */ + pub fn getBlock(self) -> CodeBlock { + for (cb in CodeBlock(__all_data__), + ths in ThrowStatementDO(__all_data__)) { + if (self.key_eq(ths)) { + if (cb.element_hash_id = ths.getBlockHashId()) { + return cb + } + } + } + } + /** + * @brief gets the body of the throwStatement. + * @return Expression + */ + pub fn getException(self) -> Expression { + for (cb in Expression(__all_data__), + ths in ThrowStatementDO(__all_data__)) { + if (self.key_eq(ths)) { + if (cb.element_hash_id = ths.getExceptionHashId()) { + return cb + } + } + } + } +} +/** + * @brief A statement with an attached label. + */ +schema LabeledStatement extends Statement { + +} +impl LabeledStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LabeledStatement { + for (tmp in Statement(db)) { + for (ls in LabeledStatementDO(db)) { + if (tmp.key_eq(ls)) { + yield LabeledStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the identifier of the element's label. + * @return Identifier + */ + pub fn getStatementLabel(self) -> Identifier { + for (ident in Identifier(__all_data__), + ls in LabeledStatementDO(__all_data__)) { + if (self.key_eq(ls)) { + if (ident.element_hash_id = ls.getLabeledHashIdentifierHashId()) { + return ident + } + } + } + } + /** + * @brief gets the label name of the statement. + * @return string + */ + pub fn getLabel(self) -> string { + return self.getStatementLabel().getName() + } + /** + * @brief gets the labeled statement. + * @return Statement + */ + pub fn getStatement(self) -> Statement { + for (stmt in Statement(__all_data__), + ls in LabeledStatementDO(__all_data__)) { + if (self.key_eq(ls)) { + if (stmt.element_hash_id = ls.getStatementHashId()) { + return stmt + } + } + } + } +} +/** + * @brief A continue statement. + */ +schema ContinueStatement extends Statement { + +} +impl ContinueStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ContinueStatement { + for (tmp in Statement(db)) { + for (cs in ContinueStatementDO(db)) { + if (tmp.key_eq(cs)) { + yield ContinueStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the continued statement. + * @return Statement + */ + pub fn getStatement(self) -> Statement { + for (stmt in Statement(__all_data__), + cs in ContinueStatementDO(__all_data__)) { + if (self.key_eq(cs)) { + if (stmt.element_hash_id = cs.getContinuedStatementHashId()) { + return stmt + } + } + } + } +} +/** + * @brief A yield statement. + */ +schema YieldStatement extends Statement { + +} +impl YieldStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *YieldStatement { + for (tmp in Statement(db)) { + for (ys in YieldStatementDO(db)) { + if (tmp.key_eq(ys)) { + yield YieldStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } +} +/** + * @brief An expression statement. + */ +schema ExpressionStatement extends Statement { + +} +impl ExpressionStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ExpressionStatement { + for (tmp in Statement(db)) { + for (es in ExpressionStatementDO(db)) { + if (tmp.key_eq(es)) { + yield ExpressionStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the Expression in statement. + * @return Expression + */ + pub fn getExpression(self) -> Expression { + for (e in Expression(__all_data__)) { + if (self.key_eq(e.getParent())) { + return e + } + } + } +} +/** + * @brief A jump statement. + */ +schema JumpStatement extends Statement { + +} +impl JumpStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *JumpStatement { + for (tmp in Statement(db)) { + for (bStmt in BreakStatement(db)) { + if (tmp.key_eq(bStmt)) { + yield JumpStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + for (cStmt in ContinueStatement(db)) { + if (tmp.key_eq(cStmt)) { + yield JumpStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + for (yStmt in YieldStatement(db)) { + if (tmp.key_eq(yStmt)) { + yield JumpStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the labeled statement that the break or continue statement refers to. + * @return LabeledStatement + */ + pub fn getTargetLabel(self) -> LabeledStatement { + for (ns in NameString(__all_data__), + stmt in LabeledStatement(__all_data__)) { + if (stmt.getStatement() = ns.getValue()) { + if (ns.key_eq(self)) { + return stmt + } + } + } + } + /** + * @brief gets the statement of the labeled statement. + * @return Statement + */ + pub fn getLabelTarget(self) -> Statement { + for (stmt in Statement(__all_data__)) { + if (stmt = self.getTargetLabel().getStatement()) { + return stmt + } + } + } + pub fn getEnclosingTarget(self) -> Statement { + for (enclosing in Statement(__all_data__), + stmt in Statement(__all_data__)) { + if (self.key_eq(stmt)) { + for (auto_tmp1 in stmt.getAEnclosingStatement()) { + if (auto_tmp1 = enclosing) { + for (ls in LoopStatement(__all_data__)) { + if (enclosing.key_eq(ls)) { + return enclosing + } + } + for (bs in BreakStatement(__all_data__)) { + if (enclosing.key_eq(bs)) { + return enclosing + } + } + for (ss in SwitchStatement(__all_data__)) { + if (enclosing.key_eq(ss)) { + return enclosing + } + } + } + } + } + } + } + /** + * @brief description + * @return StatementParent + */ + pub fn getTarget(self) -> StatementParent { + for (parent in StatementParent(__all_data__)) { + if (parent.key_eq(self.getLabelTarget())) { + return parent + } + if (parent.key_eq(self.getEnclosingTarget())) { + return parent + } + } + } +} +/** + * @brief Name and value for a named expression or statement, like break statement, labeled statement. + */ +schema NameString extends NameStringDO { + +} +impl NameString { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *NameString { + for (tmp in NameStringDO(db)) { + yield NameString { + parent_hash_id : tmp.parent_hash_id, + name_element_hash_id : tmp.name_element_hash_id, + value_element_hash_id : tmp.value_element_hash_id + } + } + } + /** + * @brief get the referenced statement. + * @return Statement + */ + pub fn getValue(self) -> Statement { + for (stmt in Statement(__all_data__)) { + if (stmt.element_hash_id = self.getValueElementHashId()) { + return stmt + } + } + } + /** + * @brief get the identifier of the element. + * @return Identifier + */ + pub fn getName(self) -> Identifier { + for (ident in Identifier(__all_data__)) { + if (ident.element_hash_id = self.getNameElementHashId()) { + return ident + } + } + } +} +schema TryStatementDO { + @primary id: int +} +impl TryStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TryStatementDO { + for (t in TryStatementWithFinallyDO(db)) { + yield TryStatementDO {id : t.element_hash_id} + } + for (t in TryStatementWithoutFinallyDO(db)) { + yield TryStatementDO {id : t.element_hash_id} + } + } + pub fn getTryBlockHashId(self) -> int { + for (t in TryStatementWithFinallyDO(__all_data__)) { + if (self.key_eq(t)) { + let (id = t.getTryBlockHashId()) { + return id + } + } + } + for (t in TryStatementWithoutFinallyDO(__all_data__)) { + if (self.key_eq(t)) { + let (id = t.getTryBlockHashId()) { + return id + } + } + } + } + pub fn getFinallyBlockHashId(self) -> int { + for (t in TryStatementWithFinallyDO(__all_data__)) { + if (self.key_eq(t)) { + return t.getFinallyBlockHashId() + } + } + } +} +/** + * @brief A try ... catch ... finally statement + */ +schema TryStatement extends Statement { + +} +impl TryStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TryStatement { + for (tmp in Statement(db)) { + for (ts in TryStatementDO(db)) { + if (tmp.key_eq(ts)) { + yield TryStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + fn tmp_getCatchClauseIndexLess(self, catchBlock: CatchClause) -> *CatchClause { + for (tmp in CatchClause(__all_data__)) { + if (self = tmp.getTryStatement()) { + if (tmp.getIndex() < catchBlock.getIndex()) { + yield tmp + } + } + } + } + /** + * @brief gets the try block of the try statement. + * @return Statement + */ + pub fn getTryBlock(self) -> CodeBlock { + for (tryBlock in CodeBlock(__all_data__), + ts in TryStatementDO(__all_data__)) { + if (self.key_eq(ts)) { + if (tryBlock.element_hash_id = ts.getTryBlockHashId()) { + return tryBlock + } + } + } + } + /** + * @brief gets the catch clause of the try statement. + * @return CatchClauseStatement + */ + pub fn getCatchBlock(self) -> *CatchClause { + for (catchBlock in CatchClause(__all_data__)) { + if (self = catchBlock.getTryStatement()) { + yield catchBlock + } + } + } + /** + * @brief gets the finally block of the try statement + * @return CodeBlock + */ + pub fn getFinallyBlock(self) -> CodeBlock { + for (codeBlock in CodeBlock(__all_data__), + ts in TryStatementDO(__all_data__)) { + if (codeBlock.element_hash_id = ts.getFinallyBlockHashId()) { + if (self.key_eq(ts)) { + return codeBlock + } + } + } + } + /** + * @brief gets the ResourceList of the try statement + * @return ResourceList + */ + pub fn getResourceList(self) -> ResourceList { + for (resourceList in ResourceList(__all_data__)) { + if (self.key_eq(resourceList.getParent())) { + return resourceList + } + } + } + /** + * @brief gets the i-th catch clause of the try statement. + * @return CatchClauseStatement + */ + pub fn getIthCatchBlock(self, index: int) -> CatchClause { + for (catchBlock in CatchClause(__all_data__)) { + if (self = catchBlock.getTryStatement()) { + if (self.tmp_getCatchClauseIndexLess(catchBlock).len() = index) { + return catchBlock + } + } + } + } +} +/** + * @brief A single catch section of a try ... catch statement. + */ +schema CatchClause extends CatchSectionDO { + +} +impl CatchClause { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *CatchClause { + for (tmp in CatchSectionDO(db)) { + yield CatchClause { + element_hash_id : tmp.element_hash_id, + printable_text : tmp.printable_text, + parameter_hash_id : tmp.parameter_hash_id, + type_hash_id : tmp.type_hash_id, + location_hash_id : tmp.location_hash_id, + try_statement_hash_id : tmp.try_statement_hash_id, + index_order : tmp.index_order + } + } + } + /** + * @brief gets the parameter of this catch clause. + * @return Parameter + */ + pub fn getParameter(self) -> Parameter { + for (param in Parameter(__all_data__)) { + if (param.element_hash_id = self.getParameterHashId()) { + return param + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getTryStatementHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__)) { + if (type.id = self.getTypeHashId()) { + return type + } + } + } + /** + * @brief gets the block of this catch clause + * @return CodeBlock + */ + pub fn getBlock(self) -> CodeBlock { + for (block in CodeBlock(__all_data__)) { + if (self.key_eq(block.getParent())) { + return block + } + } + } + /** + * @brief get the try statement in which this catch clause occurs. + * @return TryStatement + */ + pub fn getTryStatement(self) -> TryStatement { + for (tryStmt in TryStatement(__all_data__)) { + if (tryStmt.element_hash_id = self.getTryStatementHashId()) { + return tryStmt + } + } + } +} +/** + * @brief A break statement. + */ +schema BreakStatement extends Statement { + +} +impl BreakStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *BreakStatement { + for (tmp in Statement(db)) { + for (bs in BreakStatementDO(db)) { + if (tmp.key_eq(bs)) { + yield BreakStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the exited statement of the break statement, if any. + * @return Statement + */ + pub fn getExitedStatement(self) -> Statement { + for (stmt in Statement(__all_data__), + bs in BreakStatementDO(__all_data__)) { + if (self.key_eq(bs)) { + if (stmt.element_hash_id = bs.getExitedStatementHashId()) { + return stmt + } + } + } + } +} +/** + * @brief A conditional statement, including if, for, foreach, while and do-while statements. + */ +schema ConditionalStatement extends Statement { + +} +impl ConditionalStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ConditionalStatement { + for (tmp in Statement(db)) { + for (ifs in IfStatement(db)) { + if (tmp.key_eq(ifs)) { + yield ConditionalStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + for (fs in ForStatement(db)) { + if (tmp.key_eq(fs)) { + yield ConditionalStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + for (ws in WhileStatement(db)) { + if (tmp.key_eq(ws)) { + yield ConditionalStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + for (dws in DoWhileStatement(db)) { + if (tmp.key_eq(dws)) { + yield ConditionalStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the boolean condition of the conditional statement. + * @return Expression + */ + pub fn getCondition(self) -> Expression { + for (e in Expression(__all_data__)) { + for (ifs in IfStatement(__all_data__)) { + if (self.key_eq(ifs)) { + if (e = ifs.getCondition()) { + return e + } + } + } + for (fs in ForStatement(__all_data__)) { + if (self.key_eq(fs)) { + if (e = fs.getCondition()) { + return e + } + } + } + for (ws in WhileStatement(__all_data__)) { + if (self.key_eq(ws)) { + if (e = ws.getCondition()) { + return e + } + } + } + for (dws in DoWhileStatement(__all_data__)) { + if (self.key_eq(dws)) { + if (e = dws.getCondition()) { + return e + } + } + } + } + } +} +schema IfStatementDO { + @primary id: int +} +impl IfStatementDO { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *IfStatementDO { + for (i in IfStatementWithElseDO(db)) { + yield IfStatementDO {id : i.element_hash_id} + } + for (i in IfStatementWithoutElseDO(db)) { + yield IfStatementDO {id : i.element_hash_id} + } + } + pub fn getConditionHashId(self) -> int { + for (i in IfStatementWithElseDO(__all_data__)) { + if (self.key_eq(i)) { + return i.getConditionHashId() + } + } + for (i in IfStatementWithoutElseDO(__all_data__)) { + if (self.key_eq(i)) { + return i.getConditionHashId() + } + } + } + pub fn getConsequentHashId(self) -> int { + for (i in IfStatementWithElseDO(__all_data__)) { + if (self.key_eq(i)) { + return i.getConsequentHashId() + } + } + for (i in IfStatementWithoutElseDO(__all_data__)) { + if (self.key_eq(i)) { + return i.getConsequentHashId() + } + } + } + pub fn getAlternateHashId(self) -> int { + for (i in IfStatementWithElseDO(__all_data__)) { + if (self.key_eq(i)) { + return i.getAlternateHashId() + } + } + } +} +/** + * @brief A if statement. + */ +schema IfStatement extends Statement { + +} +impl IfStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *IfStatement { + for (tmp in Statement(db)) { + for (ifs in IfStatementDO(db)) { + if (tmp.key_eq(ifs)) { + yield IfStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the boolean condition of this if statement. + * @return Expression + */ + pub fn getCondition(self) -> Expression { + for (expr in Expression(__all_data__), + ifs in IfStatementDO(__all_data__)) { + if (self.key_eq(ifs)) { + if (expr.element_hash_id = ifs.getConditionHashId()) { + return expr + } + } + } + } + /** + * @brief get the statement that is executed whenever the condition of this branch evaluates to true. + * @return Statement + */ + pub fn getConsequent(self) -> Statement { + for (consequent in Statement(__all_data__), + ifs in IfStatementDO(__all_data__)) { + if (self.key_eq(ifs)) { + if (consequent.element_hash_id = ifs.getConsequentHashId()) { + return consequent + } + } + } + } + /** + * @brief gets the else branch of this if statement. + * @return Statement + */ + pub fn getAlternate(self) -> Statement { + for (alternate in Statement(__all_data__), + ifs in IfStatementDO(__all_data__)) { + if (self.key_eq(ifs)) { + if (alternate.element_hash_id = ifs.getAlternateHashId()) { + return alternate + } + } + } + } +} +/** + * @brief A basic for statement. + */ +schema ForStatement extends Statement { + +} +impl ForStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ForStatement { + for (tmp in Statement(db)) { + for (fs in ForStatementDO(db)) { + if (tmp.key_eq(fs)) { + yield ForStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the initializer statement of the for loop, this maybe an assignment statement or a local variable declaration statement. + * @return Statement + */ + pub fn getInitialization(self) -> Statement { + for (init in Statement(__all_data__), + fs in ForStatementDO(__all_data__)) { + if (self.key_eq(fs)) { + if (init.element_hash_id = fs.getInitializationHashId()) { + return init + } + } + } + } + /** + * @brief gets the boolean condition of this for loop. + * @return Expression + */ + pub fn getCondition(self) -> Expression { + for (cond in Expression(__all_data__), + fs in ForStatementDO(__all_data__)) { + if (self.key_eq(fs)) { + if (cond.element_hash_id = fs.getConditionHashId()) { + return cond + } + } + } + } + /** + * @brief gets the update statement of this for loop. + * @return Statement + */ + pub fn getUpdate(self) -> Statement { + for (update in Statement(__all_data__), + fs in ForStatementDO(__all_data__)) { + if (self.key_eq(fs)) { + if (update.element_hash_id = fs.getUpdateHashId()) { + return update + } + } + } + } + /** + * @brief gets the body of this for loop, usually a block statement. + * @return Statement + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__), + fs in ForStatementDO(__all_data__)) { + if (self.key_eq(fs)) { + if (body.element_hash_id = fs.getBodyHashId()) { + return body + } + } + } + } + /** + * @brief gets the statement that is executed whenever the condition of this branch statement evaluates to true. + * @return Statement + */ + pub fn getTrueSuccessor(self) -> Statement { + return self.getBody() + } +} +/** + * @brief A foreach statement. + */ +schema ForeachStatement extends Statement { + +} +impl ForeachStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ForeachStatement { + for (tmp in Statement(db)) { + for (fs in ForeachStatementDO(db)) { + if (tmp.key_eq(fs)) { + yield ForeachStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the expression over which the foreach loop iterates. + * @return Expression + */ + pub fn getIteratedValue(self) -> Expression { + for (literalValue in Expression(__all_data__), + fs in ForeachStatementDO(__all_data__)) { + if (self.key_eq(fs)) { + if (literalValue.element_hash_id = fs.getIteratedValueHashId()) { + return literalValue + } + } + } + } + /** + * @brief gets the iteration parameter of this foreach loop. + * @return Parameter + */ + pub fn getIterationParameter(self) -> Parameter { + for (param in Parameter(__all_data__), + fs in ForeachStatementDO(__all_data__)) { + if (self.key_eq(fs)) { + if (param.element_hash_id = fs.getIterationParameterHashId()) { + return param + } + } + } + } + /** + * @brief gets the body of this for loop. + * @return Statement + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__), + fs in ForeachStatementDO(__all_data__)) { + if (self.key_eq(fs)) { + if (body.element_hash_id = fs.getBodyHashId()) { + return body + } + } + } + } +} +/** + * @brief A while statement. + */ +schema WhileStatement extends Statement { + +} +impl WhileStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *WhileStatement { + for (tmp in Statement(db)) { + for (ws in WhileStatementDO(db)) { + if (tmp.key_eq(ws)) { + yield WhileStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the boolean condition of this while loop. + * @return Expression + */ + pub fn getCondition(self) -> Expression { + for (cond in Expression(__all_data__), + ws in WhileStatementDO(__all_data__)) { + if (self.key_eq(ws)) { + if (cond.element_hash_id = ws.getConditionHashId()) { + return cond + } + } + } + } + /** + * @brief gets the body of this while loop. + * @return Statement + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__), + ws in WhileStatementDO(__all_data__)) { + if (self.key_eq(ws)) { + if (body.element_hash_id = ws.getBodyDeclarationHashId()) { + return body + } + } + } + } +} +/** + * @brief A do-while statement. + */ +schema DoWhileStatement extends Statement { + +} +impl DoWhileStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DoWhileStatement { + for (tmp in Statement(db)) { + for (dw in DoWhileStatementDO(db)) { + if (tmp.key_eq(dw)) { + yield DoWhileStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the boolean condition of this do-while loop. + * @return Expression + */ + pub fn getCondition(self) -> Expression { + for (cond in Expression(__all_data__), + dw in DoWhileStatementDO(__all_data__)) { + if (self.key_eq(dw)) { + if (cond.element_hash_id = dw.getConditionHashId()) { + return cond + } + } + } + } + /** + * @brief gets the body of this while loop. + * @return Statement + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__), + ws in DoWhileStatementDO(__all_data__)) { + if (self.key_eq(ws)) { + if (body.element_hash_id = ws.getBodyDeclarationHashId()) { + return body + } + } + } + } +} +/** + * @brief A loop statement. + */ +schema LoopStatement extends Statement { + +} +impl LoopStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *LoopStatement { + for (tmp in Statement(db)) { + for (fs in ForStatement(db)) { + if (tmp.key_eq(fs)) { + yield LoopStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + for (fs in ForeachStatement(db)) { + if (tmp.key_eq(fs)) { + yield LoopStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + for (fs in WhileStatement(db)) { + if (tmp.key_eq(fs)) { + yield LoopStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + for (fs in DoWhileStatement(db)) { + if (tmp.key_eq(fs)) { + yield LoopStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } +} +/** + * @brief A switch statement. + */ +schema SwitchStatement extends Statement { + +} +impl SwitchStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SwitchStatement { + for (tmp in Statement(db)) { + for (ss in SwitchStatementDO(db)) { + if (tmp.key_eq(ss)) { + yield SwitchStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets an immediate child statement of this switch statement. + * @return Statement + */ + pub fn getAStmt(self) -> Statement { + for (stmt in Statement(__all_data__)) { + if (self.key_eq(stmt.getParent())) { + return stmt + } + } + } + /** + * @brief gets the i-th child statement of this switch statement. + * @return Statement + */ + pub fn getIthStmt(self, idx : int) -> Statement { + for (stmt in Statement(__all_data__)) { + if (self.key_eq(stmt.getParent())) { + if (stmt.getIndex() = idx) { + return stmt + } + } + } + } + /** + * @brief gets switch Block + * @return codeBlock + */ + pub fn getCodeBlock(self) -> CodeBlock { + for (cb in CodeBlock(__all_data__)) { + if (self.key_eq(cb.getParent())) { + return cb + } + } + } + /** + * @brief gets the i-th child statement of this switch statement. + * @return Statement + */ + pub fn getDefaultStmt(self) -> DefaultSwitchLabelStatement { + for (stmt in DefaultSwitchLabelStatement(__all_data__)){ + if (self.key_eq(stmt.getParent())) { + return stmt + } + } + } + /** + * @brief gets the expression of this switch statement. + * @return Expression + */ + pub fn getExpr(self) -> Expression { + for (expr in Expression(__all_data__)) { + if (self.key_eq(expr.getParent())) { + return expr + } + } + } + /** + * @brief gets a case of this switch statement, which maybe either a normal or a default. + * @return SwitchLabelStatement + */ + pub fn getACase(self) -> *SwitchLabelStatement { + for (stmt in SwitchLabelStatement(__all_data__)) { + if (self = stmt.getEnclosingSwitchBlock()) { + yield stmt + } + } + } +} +/** + * @brief A single switch label or labeled rule in a switch statement. + */ +schema SwitchLabelStatement extends Statement { + +} +impl SwitchLabelStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SwitchLabelStatement { + for (tmp in Statement(db)) { + for (sl in SwitchLabelStatementDO(db)) { + if (tmp.key_eq(sl)) { + yield SwitchLabelStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the enclosing switch statement of this case. + * @return SwitchStatement + */ + pub fn getEnclosingSwitchBlock(self) -> SwitchStatement { + for (stmt in SwitchStatement(__all_data__), + sl in SwitchLabelStatementDO(__all_data__)) { + if (self.key_eq(sl)) { + if (stmt.element_hash_id = sl.getEnclosingSwitchBlockHashId()) { + return stmt + } + } + } + } + /** + * @brief gets the expression of the surrounding switch that this case is compared against. + * @return ExpressionListElement + */ + pub fn getSelector(self) -> ExpressionListElement { + for (selector in ExpressionListElement(__all_data__), + sl in SwitchLabelStatementDO(__all_data__)) { + if (self.key_eq(sl)) { + if (selector.getParent().id = sl.getCaseValueHashId()) { + let (i = sl.getCaseValueHashId()) { + if (i > 0) { + return selector + } + } + } + } + } + } + /** + * @brief get the default label statement. + * @return SwitchLabelStatement + */ + pub fn getDefault(self) -> SwitchLabelStatement { + for (stmt in SwitchLabelStatement(__all_data__), + sl in SwitchLabelStatementDO(__all_data__)) { + if (self.key_eq(sl)) { + if (stmt.key_eq(sl)) { + if (sl.getCaseValueHashId() = -1) { + return stmt + } + } + } + } + } + /** + * @brief the element represents a default section or not, 1 means true. + * @return int + */ + pub fn isDefaultValue(self) -> int { + for (sl in SwitchLabelStatementDO(__all_data__)) { + if (self.key_eq(sl)) { + return sl.getCaseValueHashId() + } + } + } + /** + * @brief the element represents a default section or not, 1 means true. + * @return int + */ + pub fn getNext(self) -> int { + for (sl in SwitchLabelStatementDO(__all_data__)) { + let (i = sl.getNext()) { + if (self.key_eq(sl)) { + return i + } + } + } + } + pub fn getNextSwitchCaseStatement(self) -> SwitchLabelStatement { + for (s in SwitchLabelStatement(__all_data__)) { + if (s.element_hash_id = self.getNext()) { + return s + } + } + } + pub fn getStatement(self, index : int) -> Statement { + for (statement in self.getExecutionStatement()) { + let (tmp1 = statement.getIndex() - self.getIndex()) { + if (tmp1 - 1 = index) { + return statement + } + } + } + } + pub fn getExecutionStatement(self) -> *Statement { + for (s in Statement(__all_data__)) { + if (s.getParentHashId() = self.getParentHashId()) { + let (i = s.getIndex(), + j = self.getIndex(), + tmp = self.getNext()) { + if (tmp = 0) { + if (i > j) { + yield s + } + } + if (tmp != 0) { + let (l = self.getNextSwitchCaseStatement()) { + let (k = l.getIndex()) { + if (i > j && i < k) { + yield s + } + } + } + } + } + } + } + } +} +schema DefaultSwitchLabelStatement extends SwitchLabelStatement { + +} +impl DefaultSwitchLabelStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *DefaultSwitchLabelStatement { + for (tmp in SwitchLabelStatement(db)) { + if (tmp.isDefaultValue() = -1) { + yield DefaultSwitchLabelStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } +} +schema ConstSwitchLabelStatement extends SwitchLabelStatement { + +} +impl ConstSwitchLabelStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ConstSwitchLabelStatement { + for (tmp in SwitchLabelStatement(db)) { + for (ss in SwitchLabelStatement(db)) { + if (tmp = ss) { + if (ss.isDefaultValue() != -1) { + yield ConstSwitchLabelStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + } +} +/** + * @brief A synchronized statement. + */ +schema SynchronizedStatement extends Statement { + +} +impl SynchronizedStatement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *SynchronizedStatement { + for (tmp in Statement(db)) { + for (ss in SynchronizedStatementDO(db)) { + if (tmp.key_eq(ss)) { + yield SynchronizedStatement { + element_hash_id : tmp.element_hash_id, + parent_hash_id : tmp.parent_hash_id, + index_order : tmp.index_order, + location_hash_id : tmp.location_hash_id, + printable_text : tmp.printable_text, + type : tmp.type + } + } + } + } + } + /** + * @brief gets the body of this synchronized statement + * @return Statement + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__), + ss in SynchronizedStatementDO(__all_data__)) { + if (self.key_eq(ss)) { + if (body.element_hash_id = ss.getBodyDeclarationHashId()) { + return body + } + } + } + } + /** + * @brief gets the expression on which the statement synchronizes. + * @return Expression + */ + pub fn getLockExpression(self) -> Expression { + for (expr in Expression(__all_data__), + ss in SynchronizedStatementDO(__all_data__)) { + if (self.key_eq(ss)) { + if (expr.element_hash_id = ss.getLockExpressionHashId()) { + return expr + } + } + } + } +} diff --git a/language/java/lib/Type.gdl b/language/java/lib/Type.gdl new file mode 100644 index 00000000..7eb8f981 --- /dev/null +++ b/language/java/lib/Type.gdl @@ -0,0 +1,177 @@ +/** + * @brief A java type, either a reference type or a primitive type. + */ +schema Type { + @primary id: int +} +impl Type { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Type { + for (r in ReferenceType(db)) { + yield Type {id : r.oid} + } + for (p in Primitive(db)) { + yield Type {id : p.oid} + } + for (c in Class(db)) { + yield Type {id : c.element_hash_id} + } + } + /** + * @brief gets the name of the type. + * @return string + */ + pub fn getName(self) -> string { + for (r in ReferenceType(__all_data__)) { + if (self.key_eq(r)) { + let (name = r.getName()) { + return name + } + } + } + for (p in Primitive(__all_data__)) { + if (self.key_eq(p)) { + let (name = p.getName()) { + return name + } + } + } + for (c in Class(__all_data__)) { + if (self.key_eq(c)) { + let (name = c.getName()) { + return name + } + } + } + } + /** + * @brief gets the name of the type. + * @return string + */ + pub fn getQualifiedName(self) -> string { + for (r in ReferenceType(__all_data__)) { + if (self.key_eq(r)) { + let (name = r.getQualifiedName()) { + return name + } + } + } + for (p in Primitive(__all_data__)) { + if (self.key_eq(p)) { + let (name = p.getName()) { + return name + } + } + } + for (c in Class(__all_data__)) { + if (self.key_eq(c)) { + let (name = c.getQualifiedName()) { + return name + } + } + } + } +} +/** + * @brief A java reference type. + */ +schema ReferenceType extends ReferenceTypeDO { + +} +impl ReferenceType { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *ReferenceType { + for (tmp in ReferenceTypeDO(db)) { + yield ReferenceType { + oid : tmp.oid, + name : tmp.name, + qualified_name : tmp.qualified_name + } + } + } +} +/** + * @brief An occurrence of a type in source code, for example, as a return type of the method or the type of a method parameter. + */ +schema TypeElement extends TypeElementDO { + +} +impl TypeElement { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *TypeElement { + for (tmp in TypeElementDO(db)) { + yield TypeElement { + element_hash_id : tmp.element_hash_id, + reference_type_hash_id : tmp.reference_type_hash_id, + printable_text : tmp.printable_text, + parent_hash_id : tmp.parent_hash_id, + location_hash_id : tmp.location_hash_id + } + } + } + /** + * @brief gets the type for the element. + * @return Type + */ + pub fn getType(self) -> Type { + for (type in Type(__all_data__)) { + if (type.id = self.getReferenceTypeHashId()) { + return type + } + } + } + /** + * @brief gets the ast element parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} +/** + * @brief A primitive type, includes "boolean", "byte", "short", "char", "int", "long", "float", "double" and "null". + */ +schema Primitive extends PrimitiveDO { + +} +impl Primitive { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Primitive { + for (tmp in PrimitiveDO(db)) { + yield Primitive { + oid : tmp.oid, + name : tmp.name + } + } + } +} diff --git a/language/java/lib/Utils.gdl b/language/java/lib/Utils.gdl new file mode 100644 index 00000000..4cf610e9 --- /dev/null +++ b/language/java/lib/Utils.gdl @@ -0,0 +1,133 @@ +// util function, convert letters to upper and lower case +pub fn lowerToUpper(m : string, n : string) -> bool { + if (n = "A") { + if (m = "a") { + return true + } + } + if (n = "B") { + if (m = "b") { + return true + } + } + if (n = "C") { + if (m = "c") { + return true + } + } + if (n = "D") { + if (m = "d") { + return true + } + } + if (n = "E") { + if (m = "e") { + return true + } + } + if (n = "F") { + if (m = "f") { + return true + } + } + if (n = "G") { + if (m = "g") { + return true + } + } + if (n = "H") { + if (m = "h") { + return true + } + } + if (n = "I") { + if (m = "i") { + return true + } + } + if (n = "J") { + if (m = "j") { + return true + } + } + if (n = "K") { + if (m = "k") { + return true + } + } + if (n = "L") { + if (m = "l") { + return true + } + } + if (n = "M") { + if (m = "m") { + return true + } + } + if (n = "N") { + if (m = "n") { + return true + } + } + if (n = "O") { + if (m = "o") { + return true + } + } + if (n = "P") { + if (m = "p") { + return true + } + } + if (n = "Q") { + if (m = "q") { + return true + } + } + if (n = "R") { + if (m = "r") { + return true + } + } + if (n = "S") { + if (m = "s") { + return true + } + } + if (n = "T") { + if (m = "t") { + return true + } + } + if (n = "U") { + if (m = "u") { + return true + } + } + if (n = "V") { + if (m = "v") { + return true + } + } + if (n = "W") { + if (m = "w") { + return true + } + } + if (n = "X") { + if (m = "x") { + return true + } + } + if (n = "Y") { + if (m = "y") { + return true + } + } + if (n = "Z") { + if (m = "z") { + return true + } + } +} diff --git a/language/java/lib/token.gdl b/language/java/lib/token.gdl new file mode 100644 index 00000000..da449b33 --- /dev/null +++ b/language/java/lib/token.gdl @@ -0,0 +1,53 @@ +/** + * @brief A single token in a Java file (the lowest-level element in the Java Ast tree). + */ +schema Token extends TokenDO { + +} +impl Token { + @data_constraint + @inline + fn __all__(db: JavaDB) -> *Token { + for (tmp in TokenDO(db)) { + yield Token { + element_hash_id : tmp.element_hash_id, + value : tmp.value, + location_hash_id : tmp.location_hash_id, + parent_hash_id : tmp.parent_hash_id + } + } + } + /** + * @brief gets the parent of the element. + * @return ElementParent + */ + pub fn getParent(self) -> ElementParent { + for (c in ElementParent(__all_data__)) { + if (c.id = self.getParentHashId()) { + return c + } + } + } + /** + * @brief gets an ancestor of the element. + * @return ElementParent + */ + pub fn getAnAncestor(self) -> *ElementParent { + for (tmp in ElementParent(__all_data__)) { + if (tmp.key_eq(self)) { + yield tmp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_hash_id = self.getLocationHashId()) { + return loc + } + } + } +} diff --git a/language/javascript/lib/AlipayMiniProgram.gdl b/language/javascript/lib/AlipayMiniProgram.gdl new file mode 100644 index 00000000..83cda7ef --- /dev/null +++ b/language/javascript/lib/AlipayMiniProgram.gdl @@ -0,0 +1,659 @@ +/** + * @filename: AlipayMiniProgram + * @brief: Provides classes and predicates for working with Alipay mini-program. + */ + +/** + * The `app.js` file. + */ +schema AppJsFile extends File { +} + +impl AppJsFile { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AppJsFile { + for (tmp in File(db)) { + if (tmp.getRelativePath() = "app.js") { + yield AppJsFile { + oid : tmp.oid, + name : tmp.name, + extension : tmp.extension, + relative_path : tmp.relative_path, + location_oid : tmp.location_oid + } + } + } + } +} + +/** + * The `App` call expression used to register the app. + */ +schema AppRegistrationExpression extends CallExpression { +} + +impl AppRegistrationExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AppRegistrationExpression { + for (tmp in CallExpression(db)) { + for (appIdentifier in Identifier(db), + location in Location(db), + appJsFile in AppJsFile(db)) { + if (location = tmp.getLocation()) { + if (appJsFile.key_eq(location.getFile())) { + if (appIdentifier.key_eq(tmp.getExpression())) { + if (appIdentifier.getName() = "App") { + yield AppRegistrationExpression { + id : tmp.id + } + } + } + } + } + } + } + } +} + +/** + * The app object, which is the first argument of the AppRegistrationExpression. + */ +schema AppObject extends ObjectLiteralExpression { +} + +impl AppObject { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AppObject { + for (tmp in ObjectLiteralExpression(db)) { + for (appRegistrationExpression in AppRegistrationExpression(db)) { + if (tmp.key_eq(appRegistrationExpression.getArgument(0))) { + yield AppObject { + id : tmp.id + } + } + } + } + } +} + +/** + * A `Page` call expression used to register a page. + */ +schema PageRegistrationExpression extends CallExpression { +} + +impl PageRegistrationExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PageRegistrationExpression { + for (tmp in CallExpression(db)) { + for (pageIdentifier in Identifier(db)) { + if (pageIdentifier.key_eq(tmp.getExpression())) { + if (pageIdentifier.getName() = "Page") { + yield PageRegistrationExpression { + id : tmp.id + } + } + } + } + } + } +} + +/** + * A page object, which is the first argument of a PageRegistrationExpression. + */ +schema PageObject extends ObjectLiteralExpression { +} + +impl PageObject { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PageObject { + for (tmp in ObjectLiteralExpression(db)) { + for (pageRegistrationExpression in PageRegistrationExpression(db)) { + if (tmp.key_eq(pageRegistrationExpression.getArgument(0))) { + yield PageObject { + id : tmp.id + } + } + } + } + } +} + +/** + * A `Component` call expression used to register a custom component. + */ +schema ComponentRegistrationExpression extends CallExpression { +} + +impl ComponentRegistrationExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ComponentRegistrationExpression { + for (tmp in CallExpression(db)) { + for (componentIdentifier in Identifier(db)) { + if (componentIdentifier.key_eq(tmp.getExpression())) { + if (componentIdentifier.getName() = "Component") { + yield ComponentRegistrationExpression { + id : tmp.id + } + } + } + } + } + } +} + +/** + * A component object, which is the first argument of a ComponentRegistrationExpression. + */ +schema ComponentObject extends ObjectLiteralExpression { +} + +impl ComponentObject { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ComponentObject { + for (tmp in ObjectLiteralExpression(db)) { + for (componentRegistrationExpression in ComponentRegistrationExpression(db)) { + if (tmp.key_eq(componentRegistrationExpression.getArgument(0))) { + yield ComponentObject { + id : tmp.id + } + } + } + } + } +} + +/** + * A mini-program object, which is an AppObject, PageObject or ComponentObject. + */ +schema MiniObject extends ObjectLiteralExpression { +} + +impl MiniObject { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MiniObject { + for (tmp in ObjectLiteralExpression(db)) { + for (appObject in AppObject(db)) { + if (tmp.key_eq(appObject)) { + yield MiniObject { + id : tmp.id + } + } + } + for (pageObject in PageObject(db)) { + if (tmp.key_eq(pageObject)) { + yield MiniObject { + id : tmp.id + } + } + } + for (componentObject in ComponentObject(db)) { + if (tmp.key_eq(componentObject)) { + yield MiniObject { + id : tmp.id + } + } + } + } + } +} + +/** + * An Alipay mini program API call expression. + */ +schema ApiCallExpression extends CallExpression { +} + +impl ApiCallExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ApiCallExpression { + for (tmp in CallExpression(db)) { + for (accessExpression in AccessExpression(db), + myIdentifier in Identifier(db)) { + if (accessExpression.key_eq(tmp.getExpression())) { + if (myIdentifier.key_eq(accessExpression.getExpression())) { + if (myIdentifier.getName() = "my") { + yield ApiCallExpression { + id : tmp.id + } + } + } + } + } + } + } +} + +/** + * A call expression in Alipay mini program project. + */ +schema MiniCallExpression extends CallExpression { +} + +impl MiniCallExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MiniCallExpression { + for (tmp in CallExpression(db)) { + yield MiniCallExpression { + id : tmp.id + } + } + } + + /** + * Gets the callee of this MiniCallExpression. + * + * In addition to the results of CallExpression.getCallee(), + * this method add some callees according to Alipay mini program framework. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callee in FunctionLikeDeclaration(__all_data__)) { + for (callExpression in CallExpression(__all_data__)) { + if (callExpression.key_eq(self)) { + if (callee = callExpression.getCallee()) { + return callee + } + } + } + for (accessExpression in AccessExpression(__all_data__)) { + if (accessExpression.key_eq(self.getExpression())) { + for (thisExpression in ThisExpression(__all_data__)) { + if (thisExpression.key_eq(accessExpression.getExpression())) { + let (functionName = accessExpression.getPropertyName()) { + for (miniObject in MiniObject(__all_data__)) { + for (auto_tmp1 in self.getAnAncestor()) { + if (auto_tmp1.key_eq(miniObject)) { + let (objectLiteralElement = miniObject.getPropertyByName(functionName)) { + // TODO: handle ShorthandPropertyAssignment + for (propertyAssignment in PropertyAssignment(__all_data__)) { + if (propertyAssignment.key_eq(objectLiteralElement)) { + if (callee.key_eq(propertyAssignment.getInitializer())) { + return callee + } + } + } + if (isMethodDeclaration(Node(__all_data__).find(objectLiteralElement))) { + if (callee.key_eq(objectLiteralElement)) { + return callee + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +schema RouterKind { + @primary id: int, + name: string +} + +impl RouterKind { + @data_constraint + pub fn __all__() -> *RouterKind { + for (id in int::__undetermined_all__()) { + for (name in string::__undetermined_all__()) { + if (routerKindInit(id, name)) { + yield RouterKind{id: id, name: name} + } + } + } + } + + pub fn getName(self) -> string { + return self.name + } + + pub fn getValue(self) -> int { + return self.id + } + + pub fn isSwitchTab(self) -> bool { + if (self.id = 1000011) { + return true + } + } + + pub fn isReLaunch(self) -> bool { + if (self.id = 1000012) { + return true + } + } + + pub fn isRedirectTo(self) -> bool { + if (self.id = 1000013) { + return true + } + } + + pub fn isNavigateTo(self) -> bool { + if (self.id = 1000014) { + return true + } + } + + pub fn isNavigateBack(self) -> bool { + if (self.id = 1000015) { + return true + } + } +} + +pub fn pageRouterRule(fromPage: PageObject, toPage: PageObject, kind: RouterKind) -> bool { + for (callExpression in CallExpression(__all_data__), + accessExpression in AccessExpression(__all_data__)) { + if (accessExpression.key_eq(callExpression.getExpression())) { + let (calledFuncName = accessExpression.getPropertyName()) { + for (urlAdj in string::__undetermined_all__(), + toPagePath in string::__undetermined_all__()) { + if (calledFuncName = accessExpression.getPropertyName()) { + if (calledFuncName = "switchTab") { + if (kind.isSwitchTab()) { + if (fromPage.getRelativePath() = callExpression.getRelativePath()) { + if (kind.isNavigateBack()) { + if (toPagePath = "") { + for (tmpKind in RouterKind()) { + if (!tmpKind.isNavigateBack()) { + if (pageRouterRule(toPage, __all_data__, tmpKind)) { + if (urlAdj = "") { + return true + } + } + } + } + } + } + if (!kind.isNavigateBack()) { + if (toPage.getRelativePath() = toPagePath) { + for (url in string::__undetermined_all__()) { + // TODO: router url may contains parameters, need to prune parameter sub string + for (arg in ObjectLiteralExpression(__all_data__), + urlPAE in PropertyAssignment(__all_data__), + urlSL in StringLiteral(__all_data__)) { + if (arg.key_eq(callExpression.getArgument(0))) { + if (urlPAE.key_eq(arg.getPropertyByName("url"))) { + if (urlSL.key_eq(urlPAE.getInitializer())) { + if (url = urlSL.getString()) { + if (url.substr(0, 3) = "../") { + for (urlAdjLen in int::__undetermined_all__()) { + if (urlAdjLen = url.len()) { + if (urlAdj = url.substr(3, urlAdjLen) + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + if (url.substr(0, 3) != "../") { + if (urlAdj = url + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + } + } + } + } + } + } + } + } + } + if (calledFuncName = "reLaunch") { + if (kind.isReLaunch()) { + if (fromPage.getRelativePath() = callExpression.getRelativePath()) { + if (kind.isNavigateBack()) { + if (toPagePath = "") { + for (tmpKind in RouterKind()) { + if (!tmpKind.isNavigateBack()) { + if (pageRouterRule(toPage, __all_data__, tmpKind)) { + if (urlAdj = "") { + return true + } + } + } + } + } + } + if (!kind.isNavigateBack()) { + if (toPage.getRelativePath() = toPagePath) { + for (url in string::__undetermined_all__()) { + for (arg in ObjectLiteralExpression(__all_data__), + urlPAE in PropertyAssignment(__all_data__), + urlSL in StringLiteral(__all_data__)) { + if (arg.key_eq(callExpression.getArgument(0))) { + if (urlPAE.key_eq(arg.getPropertyByName("url"))) { + if (urlSL.key_eq(urlPAE.getInitializer())) { + if (url = urlSL.getString()) { + if (url.substr(0, 3) = "../") { + for (urlAdjLen in int::__undetermined_all__()) { + if (urlAdjLen = url.len()) { + if (urlAdj = url.substr(3, urlAdjLen) + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + if (url.substr(0, 3) != "../") { + if (urlAdj = url + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + } + } + } + } + } + } + } + } + } + if (calledFuncName = "redirectTo") { + if (kind.isRedirectTo()) { + if (fromPage.getRelativePath() = callExpression.getRelativePath()) { + if (kind.isNavigateBack()) { + if (toPagePath = "") { + for (tmpKind in RouterKind()) { + if (!tmpKind.isNavigateBack()) { + if (pageRouterRule(toPage, __all_data__, tmpKind)) { + if (urlAdj = "") { + return true + } + } + } + } + } + } + if (!kind.isNavigateBack()) { + if (toPage.getRelativePath() = toPagePath) { + for (url in string::__undetermined_all__()) { + for (arg in ObjectLiteralExpression(__all_data__), + urlPAE in PropertyAssignment(__all_data__), + urlSL in StringLiteral(__all_data__)) { + if (arg.key_eq(callExpression.getArgument(0))) { + if (urlPAE.key_eq(arg.getPropertyByName("url"))) { + if (urlSL.key_eq(urlPAE.getInitializer())) { + if (url = urlSL.getString()) { + if (url.substr(0, 3) = "../") { + for (urlAdjLen in int::__undetermined_all__()) { + if (urlAdjLen = url.len()) { + if (urlAdj = url.substr(3, urlAdjLen) + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + if (url.substr(0, 3) != "../") { + if (urlAdj = url + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + } + } + } + } + } + } + } + } + } + if (calledFuncName = "navigateTo") { + if (kind.isNavigateTo()) { + if (fromPage.getRelativePath() = callExpression.getRelativePath()) { + if (kind.isNavigateBack()) { + if (toPagePath = "") { + for (tmpKind in RouterKind()) { + if (!tmpKind.isNavigateBack()) { + if (pageRouterRule(toPage, __all_data__, tmpKind)) { + if (urlAdj = "") { + return true + } + } + } + } + } + } + if (!kind.isNavigateBack()) { + if (toPage.getRelativePath() = toPagePath) { + for (url in string::__undetermined_all__()) { + for (arg in ObjectLiteralExpression(__all_data__), + urlPAE in PropertyAssignment(__all_data__), + urlSL in StringLiteral(__all_data__)) { + if (arg.key_eq(callExpression.getArgument(0))) { + if (urlPAE.key_eq(arg.getPropertyByName("url"))) { + if (urlSL.key_eq(urlPAE.getInitializer())) { + if (url = urlSL.getString()) { + if (url.substr(0, 3) = "../") { + for (urlAdjLen in int::__undetermined_all__()) { + if (urlAdjLen = url.len()) { + if (urlAdj = url.substr(3, urlAdjLen) + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + if (url.substr(0, 3) != "../") { + if (urlAdj = url + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + } + } + } + } + } + } + } + } + } + if (calledFuncName = "navigateBack") { + if (kind.isNavigateBack()) { + if (fromPage.getRelativePath() = callExpression.getRelativePath()) { + if (kind.isNavigateBack()) { + if (toPagePath = "") { + for (tmpKind in RouterKind()) { + if (!tmpKind.isNavigateBack()) { + if (pageRouterRule(toPage, __all_data__, tmpKind)) { + if (urlAdj = "") { + return true + } + } + } + } + } + } + if (!kind.isNavigateBack()) { + if (toPage.getRelativePath() = toPagePath) { + for (url in string::__undetermined_all__()) { + for (arg in ObjectLiteralExpression(__all_data__), + urlPAE in PropertyAssignment(__all_data__), + urlSL in StringLiteral(__all_data__)) { + if (arg.key_eq(callExpression.getArgument(0))) { + if (urlPAE.key_eq(arg.getPropertyByName("url"))) { + if (urlSL.key_eq(urlPAE.getInitializer())) { + if (url = urlSL.getString()) { + if (url.substr(0, 3) = "../") { + for (urlAdjLen in int::__undetermined_all__()) { + if (urlAdjLen = url.len()) { + if (urlAdj = url.substr(3, urlAdjLen) + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + if (url.substr(0, 3) != "../") { + if (urlAdj = url + ".js") { + if (toPagePath.contains(urlAdj)) { + return true + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +pub fn routerKindInit(id: int, name: string) -> bool { + [ + {1000011, "SwitchTab"}, + {1000012, "ReLaunch"}, + {1000013, "RedirectTo"}, + {1000014, "NavigateTo"}, + {1000015, "NavigateBack"}, + ] +} diff --git a/language/javascript/lib/BasicBlock.gdl b/language/javascript/lib/BasicBlock.gdl new file mode 100644 index 00000000..d4ba84aa --- /dev/null +++ b/language/javascript/lib/BasicBlock.gdl @@ -0,0 +1,505 @@ +/** + * @filename: BasicBlock + * @brief: Provides classes and predicates for working with basic block of control flow graph. + */ + +schema BasicBlock extends ControlFlowNode { +} + +impl BasicBlock { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BasicBlock { + for (cfn in ControlFlowNode(db)) { + // CfgEntryNode is a standalone BB + for (cfgEntryNode in CfgEntryNode(db)) { + for (predecessor in cfn.getAPredecessor()) { + if (predecessor.key_eq(cfgEntryNode)) { + yield BasicBlock { + id : cfn.id + } + } + } + } + // CfgExitNode is a standalone BB + for (cfgExitNode in CfgExitNode(db)) { + if (cfn.key_eq(cfgExitNode)) { + yield BasicBlock { + id : cfn.id + } + } + } + // a node don't have predecessor but successor. + let (predecessorCount = cfn.getPredecessorCount()) { + if (predecessorCount = 0) { + let (successorCount = cfn.getSuccessorCount()) { + // maybe this constraint can be deleted or adjusted + if (successorCount > 0) { + yield BasicBlock { + id : cfn.id + } + } + } + } + } + // a node have more than 1 predecessor + let (predecessorCount = cfn.getPredecessorCount()) { + if (predecessorCount > 1) { + yield BasicBlock { + id : cfn.id + } + } + } + // any predecessor of the node has more than 1 successor + for (predecessor in cfn.getAPredecessor()) { + let (successorCount = predecessor.getSuccessorCount()) { + if (successorCount > 1) { + yield BasicBlock { + id : cfn.id + } + } + } + } + } + } + + /** + * Gets an immediate successor of this basic block. + */ + pub fn getABBSuccessor(self) -> *BasicBlock { + let (lastNode = self.getLastNode()) { + for (lastNodeSucc in ControlFlowNode(__all_data__)) { + if (lastNodeSucc in lastNode.getASuccessor()) { + yield lastNodeSucc.to() + } + } + } + } + + /** + * Gets an immediate predecessor of this basic block. + */ + pub fn getABBPredecessor(self) -> *BasicBlock { + for (bbPredecessor in BasicBlock(__all_data__)) { + if (self in bbPredecessor.getABBSuccessor()) { + yield bbPredecessor + } + } + } + + /** + * Get the node in this basic block with the given index. + */ + pub fn getNode(self, index: int) -> ControlFlowNode { + for (cfn in ControlFlowNode(__all_data__)) { + if (self.key_eq(cfn)) { + if (index = 0) { + return cfn + } + } + for (middleNodeIndex in int::__undetermined_all__()) { + let (middleNode = self.getNode(middleNodeIndex)) { + if (index = middleNodeIndex + 1) { + for (auto_tmp1 in middleNode.getASuccessor()) { + if (cfn = auto_tmp1) { + if (!isFirstOfBasicBlock(cfn)) { + return cfn + } + } + } + } + } + } + } + } + + /** + * Get a node in this basic block. + */ + pub fn getANode(self) -> *ControlFlowNode { + yield self.getNode(__all_data__) + } + + /** + * Get the first node in this basic block. + */ + pub fn getFirstNode(self) -> ControlFlowNode { + for (cfn in ControlFlowNode(__all_data__)) { + if (cfn.key_eq(self)) { + return cfn + } + } + } + + /** + * Get the last node in this basic block. + */ + pub fn getLastNode(self) -> ControlFlowNode { + let (length = self.getLength()) { + return self.getNode(length - 1) + } + } + + /** + * Determine whether this basic block is an entry bb. + */ + pub fn isEntryBB(self) -> bool { + return self.isEntryNode() + } + + /** + * Determine whether this basic block is an exit bb. + */ + pub fn isExitBB(self) -> bool { + return self.isExitNode() + } + + /** + * Gets the count of bb successor of this bb. + */ + pub fn getBBSuccessorCount(self) -> int { + return self.getABBSuccessor().len() + } + + /** + * Get the length of this basic block. + */ + pub fn getLength(self) -> int { + return self.getANode().len() + } + + /** + * Gets the count of bb predecessor of this bb. + */ + pub fn getBBPredecessorCount(self) -> int { + return self.getABBPredecessor().len() + } +} + +/** + * Hold if the node is the first node of a basic block. + */ +pub fn isFirstOfBasicBlock(cfn: ControlFlowNode) -> bool { + for (basicBlock in BasicBlock(__all_data__)) { + if (basicBlock.key_eq(cfn)) { + return true + } + } +} + +/** + * Hold the entry BB and it's all reachable BBs. + */ +pub fn entryBBReachableBB(entryBB: BasicBlock, reachableBB: BasicBlock) -> bool { + if (entryBB.isEntryBB()) { + if (reachableBB = entryBB) { + return true + } + if (reachableBB in entryBB.getABBSuccessor()) { + return true + } + for (tmpReachableBB in BasicBlock(__all_data__)) { + if (entryBBReachableBB(entryBB, tmpReachableBB)) { + if (reachableBB in tmpReachableBB.getABBSuccessor()) { + return true + } + } + } + } +} + +/** + * Hold if two bb are in same CFG. + */ +pub fn bbInSameCFG(bb1: BasicBlock, bb2: BasicBlock) -> bool { + if (bb1 = bb2) { + return true + } + if (bb1 != bb2) { + for (entryBB in BasicBlock(__all_data__)) { + if (entryBBReachableBB(entryBB, bb1)) { + if (entryBBReachableBB(entryBB, bb2)) { + return true + } + } + } + } +} + + /* + * The flowing predicates are dominate analysis, + * ATTENTION: the result of the predicate + * `bbNotDominates(BasicBlock ndomBB, BasicBlock bb)` + * is not same with `not bbDominates(ndomBB, bb)`, + * it two BB are in different CFG, they have + * neither bbDominates relation nor bbNotDominates + * relation. + * So pay attention to use predicate like this + * `not bbNotDominates` or `not bbDominates`, + * make sure two BBs are in same CFG. + */ +/** + * Hold if ndomBB don't dominates bb. + */ +pub fn bbNotDominates(ndomBB: BasicBlock, bb: BasicBlock) -> bool { + // bb is entry node, all nodes in the same function + // except node itself don't dominate this bb + if (bbInSameCFG(ndomBB, bb)) { + if (bb.isEntryBB()) { + if (ndomBB != bb) { + return true + } + } + } + // if ndom don't dominate at least of of bb's predecessor, + // ndom don't dominate bb itself + for (bbPredecessor in BasicBlock(__all_data__)) { + for (auto_tmp1 in bb.getABBPredecessor()) { + if (bbPredecessor = auto_tmp1) { + if (bbNotDominates(ndomBB, bbPredecessor)) { + if (ndomBB != bb) { + return true + } + } + } + } + } +} + +/** + * Hold if domBB dominates bb. + */ +pub fn bbDominates(domBB: BasicBlock, bb: BasicBlock) -> bool { + if (bbInSameCFG(domBB, bb)) { + // domBB DON'T have the bbNotDominates relation with bb, + // means domBB is a dominator of bb + if (!bbNotDominates(domBB, bb)) { + return true + } + } +} + +/** + * Hold if sdomBB strictly dominates bb. + */ +pub fn bbStrictDominates(sdomBB: BasicBlock, bb: BasicBlock) -> bool { + // sdomBB dominates bb, but sdomBB is not same as bb + if (bbDominates(sdomBB, bb)) { + if (sdomBB != bb) { + return true + } + } +} + +/** + * Hold if dom dominates cfn. + */ +pub fn dominates(dom: ControlFlowNode, cfn: ControlFlowNode) -> bool { + for (domBB in BasicBlock(__all_data__), + cfnBB in BasicBlock(__all_data__)) { + if (domBB = dom.getBasicBlock()) { + if (cfnBB = cfn.getBasicBlock()) { + // two nodes are in different bbs, + // dom dominates cfn if domBB dominates nodeBB + if (bbDominates(domBB, cfnBB)) { + if (domBB != cfnBB) { + return true + } + } + } + } + // two node are in same bb, + // dom dominates cfn if dom's index in current basic + // block is less equal than the cfn's index + for (domIndex in int::__undetermined_all__(), + cfnIndex in int::__undetermined_all__()) { + if (dom = cfnBB.getNode(domIndex)) { + if (cfn = cfnBB.getNode(cfnIndex)) { + if (domIndex <= cfnIndex) { + return true + } + } + } + } + } +} + +/** + * Hold bb's dominance frontier. + * bb dominates at least one of df's predecessor, + * but bb don't strictly dominates df. + */ +pub fn dominanceFrontier(bb: BasicBlock, df: BasicBlock) -> bool { + for (dfBBPredecessor in df.getABBPredecessor()) { + if (bbDominates(bb, dfBBPredecessor)) { + if (!bbStrictDominates(bb, df)) { + return true + } + } + } +} + +/** + * Hold if npdomBB don't post dominates bb. + * the relation is same as not dominates relation but apply to Reverse-CFG. + */ +pub fn bbNotPostDominates(npdomBB: BasicBlock, bb: BasicBlock) -> bool { + // bb is exit node, all nodes in the same function + // except node itself don't post dominate this bb + if (bb.isExitBB()) { + if (bbInSameCFG(npdomBB, bb)) { + if (npdomBB != bb) { + return true + } + } + } + // if npdom don't dominate at least of of bb's successor, + // npdom don't post dominate bb itself + for (bbSuccessor in BasicBlock(__all_data__)) { + for (auto_tmp1 in bb.getABBSuccessor()) { + if (bbSuccessor = auto_tmp1) { + if (bbNotPostDominates(npdomBB, bbSuccessor)) { + if (npdomBB != bb) { + return true + } + } + } + } + } +} + +/** + * Hold if pdomBB post dominates bb. + */ +pub fn bbPostDominates(pdomBB: BasicBlock, bb: BasicBlock) -> bool { + if (bbInSameCFG(pdomBB, bb)) { + // pdomBB DON'T have the bbNotPostDominates relation with bb, + // means pdomBB is a post dominator of bb + if (!bbNotPostDominates(pdomBB, bb)) { + return true + } + } +} + +/** + * Hold if spdom strictly post dominates bb. + */ +pub fn bbStrictPostDominates(spdomBB: BasicBlock, bb: BasicBlock) -> bool { + // spdomBB post dominates bb, but spdomBB is not same as bb + if (bbPostDominates(spdomBB, bb)) { + if (spdomBB != bb) { + return true + } + } +} + +/** + * Hold bb's post dominance frontier. + * bb post dominates at least one of pdf's successor, + * but bb don't strictly post dominates pdf. + */ +pub fn postDominanceFrontier(bb: BasicBlock, pdf: BasicBlock) -> bool { + for (pdfBBSuccessor in pdf.getABBSuccessor()) { + if (bbPostDominates(bb, pdfBBSuccessor)) { + if (!bbStrictPostDominates(bb, pdf)) { + return true + } + } + } +} + +/** + * Hold bb's control dependencies. + * same with postDominanceFrontier+. + */ +pub fn controlDependencies(bb: BasicBlock, controlDependencyBB: BasicBlock) -> bool { + if (postDominanceFrontier(bb, controlDependencyBB)) { + return true + } + for (tmpPostDF in BasicBlock(__all_data__)) { + if (postDominanceFrontier(bb, tmpPostDF)) { + if (controlDependencies(tmpPostDF, controlDependencyBB)) { + return true + } + } + } +} + +/** + * Hold if pdom post dominates cfn. + */ +pub fn postDominates(pdom: ControlFlowNode, cfn: ControlFlowNode) -> bool { + for (pdomBB in BasicBlock(__all_data__), + cfnBB in BasicBlock(__all_data__)) { + if (pdomBB = pdom.getBasicBlock()) { + if (cfnBB = cfn.getBasicBlock()) { + // two nodes are in different bbs, + // pdom dominates cfn if pdomBB post dominates cfnBB + if (bbPostDominates(pdomBB, cfnBB)) { + if (pdomBB != cfnBB) { + return true + } + } + } + } + // two node are in same bb, + // pdom post dominates cfn if pdom's index in current basic + // block is greater equal than the cfn's index + for (pdomIndex in int::__undetermined_all__(), + cfnIndex in int::__undetermined_all__()) { + if (pdom = cfnBB.getNode(pdomIndex)) { + if (cfn = cfnBB.getNode(cfnIndex)) { + if (pdomIndex >= cfnIndex) { + return true + } + } + } + } + } +} + +/** + * Hold if idomBB immediately dominates bb. + * idomBB is the closest strict dominator of bb, fit the following conditions: + * 1. idomBB strictly dominates bb + * 2. idomBB can't dominate any other bb's strict dominator + */ +pub fn bbIDominates(idomBB: BasicBlock, bb: BasicBlock) -> bool { + for (aIDomBB in BasicBlock(__all_data__), aBB in BasicBlock(__all_data__)) { + if (bbStrictDominates(aIDomBB, aBB)) { + // the count of strict dominator + let (sdomBBCount = getBBAllSDom(aBB).len()) { + // the count of strict dominator is 1, idom is same with sdom + if (sdomBBCount = 1) { + if (idomBB = aIDomBB && bb = aBB) { + return true + } + } + /* + select the strict dominator of bb that the count of it's strict + dominator set intersect with bb's strict dominator set is (sdomBBCount - 1), + means idom don't dominate any BasicBlock in bb's strict dominator set + + ATTENTION: + count aggregator is so expensive when the counted relation is not prepared, + so can't add more logic in the fllowing count clause + */ + if (sdomBBCount != 1) { + if (getBBAllSDom(aIDomBB).len() = sdomBBCount - 1) { + if (idomBB = aIDomBB && bb = aBB) { + return true + } + } + } + } + } + } +} + +fn getBBAllSDom(bb: BasicBlock) -> *BasicBlock { + for (sdomBB in BasicBlock(__all_data__)) { + if (bbStrictDominates(sdomBB, bb)) { + yield sdomBB + } + } +} diff --git a/language/javascript/lib/Class.gdl b/language/javascript/lib/Class.gdl new file mode 100644 index 00000000..02b399b6 --- /dev/null +++ b/language/javascript/lib/Class.gdl @@ -0,0 +1,488 @@ +/** + * @filename: Class + * @brief: Provides classes and predicates for working with JavaScript / TypeScript classes + */ + +/** + * A ClassLikeDeclaration + */ +schema ClassLikeDeclaration extends Node { +} + +impl ClassLikeDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ClassLikeDeclaration { + for (tmp in Node(db)) { + if (isClassLikeDeclaration(tmp)) { + yield ClassLikeDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A ClassDeclaration + */ +schema ClassDeclaration extends ClassLikeDeclaration { +} + +impl ClassDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ClassDeclaration { + for (tmp in ClassLikeDeclaration(db)) { + if (isClassDeclaration(Node {id: tmp.id})) { + yield ClassDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A ClassExpression + */ +schema ClassExpressionDeclaration extends ClassLikeDeclaration { +} + +impl ClassExpressionDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ClassExpressionDeclaration { + for (tmp in ClassLikeDeclaration(db)) { + if (isClassExpression(Node {id: tmp.id})) { + yield ClassExpressionDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A ClassElement + */ +schema ClassElement extends Node { +} + +impl ClassElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ClassElement { + for (tmp in Node(db)) { + if (isClassElement(tmp)) { + yield ClassElement { + id : tmp.id + } + } + } + } +} + +/** + * A PropertyDeclaration + */ +schema PropertyDeclaration extends ClassElement { +} + +impl PropertyDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PropertyDeclaration { + for (tmp in ClassElement(db)) { + if (tmp.getKind() = 166) { + yield PropertyDeclaration { + id : tmp.id + } + } + } + } + + fn getAllPropertyNameIndex(self) -> *int { + for (childIndex in int::__undetermined_all__()) { + let (child = self.getChild(childIndex)) { + let (tmp = PropertyName(__all_data__).find(child)) { + yield childIndex + } + } + } + } + + /** + * Gets a decorator. + */ + pub fn getADecorator(self) -> *Decorator { + for (decorator in Decorator(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (decorator.key_eq(auto_tmp1)) { + yield decorator + } + } + } + } + + /** + * Gets the `i`th decorator. + */ + pub fn getDecorator(self, i: int) -> Decorator { + for (decorator in Decorator(__all_data__)) { + if (decorator.key_eq(self.getChild(i))) { + return decorator + } + } + } + + /** + * Gets a modifier. + */ + pub fn getAModifier(self) -> *Modifier { + for (modifier in Modifier(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (modifier.key_eq(auto_tmp1)) { + yield modifier + } + } + } + } + + /** + * Gets the `i`th modifier. + */ + pub fn getModifier(self, i: int) -> Modifier { + for (childIndex in int::__undetermined_all__()) { + for (modifier in Modifier(__all_data__)) { + let (decoratorCount = self.getDecoratorCount()) { + if (modifier.key_eq(self.getChild(childIndex))) { + if (i = childIndex - decoratorCount) { + return modifier + } + } + } + } + } + } + + /** + * Gets the name node, which is a PropertyName. + */ + pub fn getNameNode(self) -> PropertyName { + for (nameNode in PropertyName(__all_data__)) { + let (index = self.getNameNodeIndex()) { + if (nameNode.key_eq(self.getChild(index))) { + return nameNode + } + } + } + } + + /** + * Gets the `?` token. (Optional) + */ + pub fn getQuestionToken(self) -> QuestionToken { + for (questionToken in QuestionToken(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (questionToken.key_eq(auto_tmp1)) { + return questionToken + } + } + } + } + + /** + * Gets the `!` token. (Optional) + */ + pub fn getExclamationToken(self) -> ExclamationToken { + for (exclamationToken in ExclamationToken(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (exclamationToken.key_eq(auto_tmp1)) { + return exclamationToken + } + } + } + } + + /** + * Gets the type node. (Optional) + */ + pub fn getTypeNode(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeNode.key_eq(auto_tmp1)) { + return typeNode + } + } + } + } + + /** + * Gets the initializer expression. + */ + pub fn getInitializer(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getLastChild())) { + let (index = expression.getIndex()) { + let (nameNodeIndex = self.getNameNodeIndex()) { + if (index > nameNodeIndex) { + return expression + } + } + } + } + } + } + + /** + * Get the index of name node. + */ + pub fn getNameNodeIndex(self) -> int { + return self.getAllPropertyNameIndex().min() + } + + /** + * Gets the number of decorators. + */ + pub fn getDecoratorCount(self) -> int { + return self.getADecorator().len() + } + + /** + * Gets the number of modifiers. + */ + pub fn getModifierCount(self) -> int { + return self.getAModifier().len() + } +} + +/** + * A MethodElement + */ +schema MethodElement extends ClassElement { +} + +impl MethodElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MethodElement { + for (tmp in ClassElement(db)) { + if (tmp.getKind() = 168) { + yield MethodElement { + id : tmp.id + } + } + } + } +} + +/** + * A ClassStaticBlockElement + */ +schema ClassStaticBlockElement extends ClassElement { +} + +impl ClassStaticBlockElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ClassStaticBlockElement { + for (tmp in ClassElement(db)) { + // ClassStaticBlockDeclaration + if (tmp.getKind() = 169) { + yield ClassStaticBlockElement { + id : tmp.id + } + } + } + } +} + +/** + * A ConstructorElement + */ +schema ConstructorElement extends ClassElement { +} + +impl ConstructorElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ConstructorElement { + for (tmp in ClassElement(db)) { + if (tmp.getKind() = 170) { + yield ConstructorElement { + id : tmp.id + } + } + } + } +} + +/** + * An AccessorElement + */ +schema AccessorElement extends ClassElement { +} + +impl AccessorElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AccessorElement { + for (tmp in ClassElement(db)) { + if (isAccessor(Node {id: tmp.id})) { + yield AccessorElement { + id : tmp.id + } + } + } + } +} + +/** + * A GetAccessorElement + */ +schema GetAccessorElement extends AccessorElement { +} + +impl GetAccessorElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GetAccessorElement { + for (tmp in AccessorElement(db)) { + if (tmp.getKind() = 171) { + yield GetAccessorElement { + id : tmp.id + } + } + } + } +} + +/** + * A SetAccessorElement + */ +schema SetAccessorElement extends AccessorElement { +} + +impl SetAccessorElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SetAccessorElement { + for (tmp in AccessorElement(db)) { + if (tmp.getKind() = 172) { + yield SetAccessorElement { + id : tmp.id + } + } + } + } +} + +/** + * An IndexSignature + */ +schema IndexSignature extends ClassElement { +} + +impl IndexSignature { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IndexSignature { + for (tmp in ClassElement(db)) { + if (tmp.getKind() = 175) { + yield IndexSignature { + id : tmp.id + } + } + } + } +} + +/** + * A SemicolonClassElement + */ +schema SemicolonClassElement extends ClassElement { +} + +impl SemicolonClassElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SemicolonClassElement { + for (tmp in ClassElement(db)) { + if (tmp.getKind() = 233) { + yield SemicolonClassElement { + id : tmp.id + } + } + } + } +} + +/** + * Determines whether a node is a ClassLikeDeclaration + */ +pub fn isClassLikeDeclaration(node: Node) -> bool { + let (kind = node.getKind()) { + if (isClassLikeDeclarationKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node is a ClassElement + */ +pub fn isClassElement(node: Node) -> bool { + let (kind = node.getKind()) { + if (isClassElementKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node is an Accessor + */ +pub fn isAccessor(node: Node) -> bool { + let (kind = node.getKind()) { + if (isAccessorKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node kind is an Accessor kind + */ +pub fn isAccessorKind(kind: int) -> bool { + [ + {171}, // GetAccessor + {172}, // SetAccessor + ] +} + +/** + * Determines whether a node kind is a ClassLikeDeclaration kind + */ +pub fn isClassLikeDeclarationKind(kind: int) -> bool { + [ + {256}, // ClassDeclaration + {225}, // ClassExpression + ] +} + +/** + * Determines whether a node kind is a ClassElement kind + */ +pub fn isClassElementKind(kind: int) -> bool { + [ + {166}, // PropertyDeclaration + {168}, // MethodDeclaration + {169}, // ClassStaticBlockDeclaration + {170}, // Constructor + {171}, // GetAccessor + {172}, // SetAccessor + {175}, // IndexSignature + {233}, // SemicolonClassElement + ] +} diff --git a/language/javascript/lib/Comment.gdl b/language/javascript/lib/Comment.gdl new file mode 100644 index 00000000..8a6fa326 --- /dev/null +++ b/language/javascript/lib/Comment.gdl @@ -0,0 +1,38 @@ +/** + * @filename: DOCUMENTATION + * @date: 2022/01/27 + * @brief: DOCUMENTATION provides classes and predicates for working with Js comments + */ + +/** + * A Comment. + */ +schema Comment extends CommentDO { +} + +impl Comment { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Comment { + for (tmp in CommentDO(db)) { + yield Comment { + oid : tmp.oid, + kind : tmp.kind, + location_oid : tmp.location_oid + } + } + } + + /** + * Gets the location of the Comment. + * + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.oid = self.getLocationOid()) { + return loc + } + } + } +} diff --git a/language/javascript/lib/Completion.gdl b/language/javascript/lib/Completion.gdl new file mode 100644 index 00000000..93079c52 --- /dev/null +++ b/language/javascript/lib/Completion.gdl @@ -0,0 +1,253 @@ +schema Completion { + @primary id: int, + name: string +} + +impl Completion { + @data_constraint + @inline + pub fn __all__() -> *Completion { + yield Completion {id: 1001, name: "NormalCompletion"} + yield Completion {id: 1101, name: "ReturnCompletion"} + // BooleanCompletion + yield Completion {id: 1201, name: "BooleanCompletion"} + yield Completion {id: 1202, name: "TrueBooleanCompletion"} + yield Completion {id: 1203, name: "FalseBooleanCompletion"} + // end BooleanCompletion + yield Completion {id: 1301, name: "BreakCompletion"} + yield Completion {id: 1401, name: "YieldCompletion"} + yield Completion {id: 1501, name: "ContinueCompletion"} + yield Completion {id: 1601, name: "ThrowCompletion"} + } + + pub fn getValue(self) -> int { + return self.id + } + + pub fn getName(self) -> string { + return self.name + } +} + +schema NormalCompletion extends Completion { +} + +impl NormalCompletion { + @data_constraint + pub fn __all__() -> *NormalCompletion { + for (c in Completion()) { + if (isNormalCompletion(c)) { + yield NormalCompletion {id : c.id, name : c.name} + } + } + } +} + +schema ReturnCompletion extends Completion { +} + +impl ReturnCompletion { + @data_constraint + pub fn __all__() -> *ReturnCompletion { + for (c in Completion()) { + if (isReturnCompletion(c)) { + yield ReturnCompletion {id : c.id, name : c.name} + } + } + } +} + +schema BooleanCompletion extends Completion { +} + +impl BooleanCompletion { + @data_constraint + pub fn __all__() -> *BooleanCompletion { + yield BooleanCompletion {id: 1201, name: "BooleanCompletion"} + yield BooleanCompletion {id: 1202, name: "TrueBooleanCompletion"} + yield BooleanCompletion {id: 1203, name: "FalseBooleanCompletion"} + } + + pub fn isTrue(self) -> bool { + if (self.id = 1202) { + return true + } + } + + pub fn isFalse(self) -> bool { + if (self.id = 1203) { + return true + } + } + + pub fn getValue(self) -> *int { + if (self.isTrue()) { + yield 1 + } + if (self.isFalse()) { + yield 0 + } + if (self.name = "BooleanCompletion") { + yield 0 + yield 1 + } + } + + pub fn getValueName(self) -> string { + if (self.isTrue()) { + return "true" + } + if (!self.isTrue()) { + return "false" + } + } +} + +schema TrueBooleanCompletion extends BooleanCompletion { +} + +impl TrueBooleanCompletion { + @data_constraint + pub fn __all__() -> *TrueBooleanCompletion { + yield TrueBooleanCompletion {id: 1202, name: "TrueBooleanCompletion"} + } +} + +schema FalseBooleanCompletion extends BooleanCompletion { +} + +impl FalseBooleanCompletion { + @data_constraint + pub fn __all__() -> *FalseBooleanCompletion { + yield FalseBooleanCompletion {id: 1203, name: "FalseBooleanCompletion"} + } +} + +schema BreakCompletion extends Completion { +} + +impl BreakCompletion { + @data_constraint + pub fn __all__() -> *BreakCompletion { + for (c in Completion()) { + if (isBreakCompletion(c)) { + yield BreakCompletion {id : c.id, name : c.name} + } + } + } +} + +// FIXME: YieldCompletion should carry a NormalCompletion +// or a BooleanCompletion, but we don't have convenient +// representation for now +schema YieldCompletion extends Completion { +} + +impl YieldCompletion { + @data_constraint + pub fn __all__() -> *YieldCompletion { + for (c in Completion()) { + if (isYieldCompletion(c)) { + yield YieldCompletion {id : c.id, name : c.name} + } + } + } +} + +schema ContinueCompletion extends Completion { +} + +impl ContinueCompletion { + @data_constraint + pub fn __all__() -> *ContinueCompletion { + for (c in Completion()) { + if (isContinueCompletion(c)) { + yield ContinueCompletion {id : c.id, name : c.name} + } + } + } +} + +schema ThrowCompletion extends Completion { +} + +impl ThrowCompletion { + @data_constraint + pub fn __all__() -> *ThrowCompletion { + for (c in Completion()) { + if (isThrowCompletion(c)) { + yield ThrowCompletion {id : c.id, name : c.name} + } + } + } +} + +pub fn isNormalCompletion(c: Completion) -> bool { + if(c.name = "NormalCompletion") { + return true + } +} + +pub fn isReturnCompletion(c: Completion) -> bool { + if (c.name = "ReturnCompletion") { + return true + } +} + +pub fn isBooleanCompletion(c: Completion) -> bool { + if (c.name = "BooleanCompletion" || isTrueBooleanCompletion(c) || isFalseBooleanCompletion(c)) { + return true + } +} + +pub fn isTrueBooleanCompletion(c: Completion) -> bool { + if (c.name = "TrueBooleanCompletion") { + return true + } +} + +pub fn isFalseBooleanCompletion(c: Completion) -> bool { + if (c.name = "FalseBooleanCompletion") { + return true + } +} + +pub fn isBreakCompletion(c: Completion) -> bool { + if (c.name = "BreakCompletion") { + return true + } +} + +pub fn isYieldCompletion(c: Completion) -> bool { + if (c.name = "YieldCompletion") { + return true + } +} + +pub fn isContinueCompletion(c: Completion) -> bool { + if (c.name = "ContinueCompletion") { + return true + } +} + +pub fn isThrowCompletion(c: Completion) -> bool { + if(c.name = "YieldCompletion") { + return true + } +} + +pub fn completion(id: int, name: string) -> bool { + [ + {1001, "NormalCompletion"}, + {1101, "ReturnCompletion"}, + // BooleanCompletion + {1201, "BooleanCompletion"}, + {1202, "TrueBooleanCompletion"}, + {1203, "FalseBooleanCompletion"}, + // end BooleanCompletion + {1301, "BreakCompletion"}, + {1401, "YieldCompletion"}, + {1501, "ContinueCompletion"}, + {1601, "ThrowCompletion"}, + ] +} diff --git a/language/javascript/lib/ControlFlowGraph.gdl b/language/javascript/lib/ControlFlowGraph.gdl new file mode 100644 index 00000000..5925f35b --- /dev/null +++ b/language/javascript/lib/ControlFlowGraph.gdl @@ -0,0 +1,2420 @@ +/** + * @filename: ControlFlowGraph + * @brief: Provides classes and predicates for working with a CFG-based JavaScript / TypeScript program representation. + */ + +/** + * A control flow entry node. + */ +schema CfgEntryNode extends CfgEntryNodeDO { +} + +impl CfgEntryNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CfgEntryNode { + for (tmp in CfgEntryNodeDO(db)) { + for (cfgEntryNodeDO in CfgEntryNodeDO(db)) { + if (tmp = cfgEntryNodeDO) { + yield CfgEntryNode { + oid : tmp.oid, + ast_node_oid : tmp.ast_node_oid + } + } + } + } + } + + pub fn getAstNode(self) -> Node { + for (node in Node(__all_data__)) { + if (node.id = self.getAstNodeOid()) { + return node + } + } + } +} + +/** + * A control flow exit node. + */ +schema CfgExitNode extends CfgExitNodeDO { +} + +impl CfgExitNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CfgExitNode { + for (tmp in CfgExitNodeDO(db)) { + yield CfgExitNode { + oid : tmp.oid, + ast_node_oid : tmp.ast_node_oid + } + } + } + + pub fn getAstNode(self) -> Node { + for (node in Node(__all_data__)) { + if (node.id = self.getAstNodeOid()) { + return node + } + } + } +} + +/** + * A synthetic control flow node, which is an entry or exit node. + */ +schema SyntheticCfgNode { + @primary id: int +} + +impl SyntheticCfgNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SyntheticCfgNode { + for (cfgEntryNode in CfgEntryNode(db)) { + yield SyntheticCfgNode {id : cfgEntryNode.oid} + } + for (cfgExitNode in CfgExitNode(db)) { + yield SyntheticCfgNode {id : cfgExitNode.oid} + } + } + + pub fn getAstNode(self) -> Node { + for (cfgEntryNode in CfgEntryNode(__all_data__)) { + if (cfgEntryNode.key_eq(self)) { + let (node = cfgEntryNode.getAstNode()) { + return node + } + } + } + for (cfgExitNode in CfgExitNode(__all_data__)) { + if (cfgExitNode.key_eq(self)) { + let (node = cfgExitNode.getAstNode()) { + return node + } + } + } + } +} + +/* + * This class represent control flow node, all ast nodes are + * control flow nodes. + */ +schema ControlFlowNode { + @primary id: int +} + +impl ControlFlowNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ControlFlowNode { + for (node in Node(db)) { + yield ControlFlowNode {id : node.id} + } + for (syntheticCfgNode in SyntheticCfgNode(db)) { + yield ControlFlowNode {id : syntheticCfgNode.id} + } + } + + pub fn isSyntheticNode(self) -> bool { + for (syntheticCfgNode in SyntheticCfgNode(__all_data__)) { + if (self.key_eq(syntheticCfgNode)) { + return true + } + } + } + + pub fn isEntryNode(self) -> bool { + for (cfgEntryNode in CfgEntryNode(__all_data__)) { + if (self.key_eq(cfgEntryNode)) { + return true + } + } + } + + pub fn isExitNode(self) -> bool { + for (cfgExitNode in CfgExitNode(__all_data__)) { + if (self.key_eq(cfgExitNode)) { + return true + } + } + } + + pub fn isAstNode(self) -> bool { + for (node in Node(__all_data__)) { + if (self.key_eq(node)) { + return true + } + } + } + + /** + * Get the enclosing function of node. + * CfgEntryNode or CfgExitNode return belongs to function. + */ + pub fn getEnclosingFunction(self) -> FunctionLikeDeclaration { + for (enclosingFunction in FunctionLikeDeclaration(__all_data__), + astNode in Node(__all_data__)) { + if (astNode.key_eq(self)) { + if (isFunctionLikeDeclaration(astNode)) { + if (enclosingFunction.key_eq(astNode)) { + return enclosingFunction + } + } + if (!isFunctionLikeDeclaration(astNode)) { + if (enclosingFunction = astNode.getEnclosingFunction()) { + return enclosingFunction + } + } + } + for (syntheticCfgNode in SyntheticCfgNode(__all_data__)) { + if (syntheticCfgNode.key_eq(self)) { + if (astNode = syntheticCfgNode.getAstNode()) { + if (isFunctionLikeDeclaration(astNode)) { + if (enclosingFunction.key_eq(astNode)) { + return enclosingFunction + } + } + if (!isFunctionLikeDeclaration(astNode)) { + if (enclosingFunction = astNode.getEnclosingFunction()) { + return enclosingFunction + } + } + } + } + } + } + } + + /** + * Get the location of this control flow node. + */ + pub fn getLocation(self) -> Location { + let (astNode = Node {id: self.id}) { + if (astNode.key_eq(self)) { + let (location = astNode.getLocation()) { + return location + } + } + } + for (syntheticCfgNode in SyntheticCfgNode(__all_data__)) { + if (syntheticCfgNode.key_eq(self)) { + let (astNode = syntheticCfgNode.getAstNode()) { + let (location = astNode.getLocation()) { + return location + } + } + } + } + } + + /** + * Get the file of this control flow node. + */ + pub fn getFile(self) -> File { + let (location = self.getLocation()) { + return location.getFile() + } + } + + /** + * Get the relative path of this control flow node. + */ + pub fn getRelativePath(self) -> string { + let (file = self.getFile()) { + return file.getRelativePath() + } + } + + /** + * Get the text of this control flow node. + */ + pub fn getText(self) -> string { + for (astNode in Node(__all_data__)) { + if (astNode.key_eq(self)) { + return astNode.getText() + } + } + for (syntheticCfgNode in SyntheticCfgNode(__all_data__)) { + if (syntheticCfgNode.key_eq(self)) { + let (astNode = syntheticCfgNode.getAstNode()) { + return astNode.getText() + } + } + } + } + + /** + * Get the kind name of node. + * If node is ast node, just return ast node kind name; otherwise + * return node name as CfgEntryNode or CfgExitNode. + */ + pub fn getKindName(self) -> string { + for (astNode in Node(__all_data__)) { + if (astNode.key_eq(self)) { + let (kindId = astNode.getKind()) { + for (kindName in string::__undetermined_all__()) { + if (syntaxKind(kindId, kindName)) { + return kindName + } + } + } + } + } + for (entryNode in CfgEntryNode(__all_data__)) { + if (entryNode.key_eq(self)) { + return "CfgEntryNode" + } + } + for (exitNode in CfgExitNode(__all_data__)) { + if (exitNode.key_eq(self)) { + return "CfgExitNode" + } + } + } + + /** + * Get an immediate successor of this node. + */ + pub fn getASuccessor(self) -> *ControlFlowNode { + yield succ(self, __all_data__) + } + + /** + * Gets the successor of this node, and query successors recursively + */ + pub fn getASuccessorRecursive(self) -> *ControlFlowNode { + yield self.getASuccessor() + for (tmpCFN in ControlFlowNode(__all_data__)) { + if (tmpCFN in self.getASuccessor()) { + yield tmpCFN.getASuccessorRecursive() + } + } + } + + /** + * Get an immediate predecessor of this node. + */ + pub fn getAPredecessor(self) -> *ControlFlowNode { + for (predecessor in ControlFlowNode(__all_data__)) { + if (self in predecessor.getASuccessor()) { + yield predecessor + } + } + } + + /** + * Get an immediate successor of this node with the given + * type of Completion. + */ + pub fn getASuccessorWithCompletion(self, c: Completion) -> *ControlFlowNode { + for (successor in succ(self, c)) { + yield successor + } + } + + /** + * Get the basic block that contains this node. + */ + pub fn getBasicBlock(self) -> BasicBlock { + for (basicBlock in BasicBlock(__all_data__)) { + if (self in basicBlock.getANode()) { + return basicBlock + } + } + } + + /** + * Get the count of immediate successor nodes. + */ + pub fn getSuccessorCount(self) -> int { + return self.getASuccessor().len() + } + + /** + * Get the count of immediate predecessor nodes/ + */ + pub fn getPredecessorCount(self) -> int { + return self.getAPredecessor().len() + } +} + +/** + * Most of Expression and part of Statement nodes are post order nodes, + * the visit order of PostOrderNode is that: + * 1. visit it's child, ordered by child index + * 2. visit node itself + * + * PostOrderNode consist of AST nodes with the following properties: + * 1. the visit order of node's immediate children is sequential + * 2. the control flow edge label between node's immdediate children + * only contain NormalCompletion + * + * This is a convenient way to model a node, if the node can be treat as + * PostOrderNode; the necessory control flow information including first, + * last and successor are generated automatically. + */ +schema PostOrderNode extends ControlFlowNode { +} + +impl PostOrderNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PostOrderNode { + for (tmp in ControlFlowNode(db)) { + if (isPostOrderNode(tmp)) { + yield PostOrderNode { + id : tmp.id + } + } + } + } + + pub fn getAllChild(self) -> *ControlFlowNode { + for (i in int::__undetermined_all__()) { + yield self.getChildNode(i) + } + } + + /** + * Gets child node with index, start from 0. + */ + pub fn getChildNode(self, index: int) -> ControlFlowNode { + for (cn in ControlFlowNode(__all_data__)) { + for (objectLiteralExpression in ObjectLiteralExpression(__all_data__)) { + if (objectLiteralExpression.key_eq(self)) { + if (cn.key_eq(objectLiteralExpression.getProperty(index))) { + return cn + } + } + } + for (propertyAssignment in PropertyAssignment(__all_data__)) { + if (propertyAssignment.key_eq(self)) { + if (cn.key_eq(propertyAssignment.getPropertyName())) { + if (index = 0) { + return cn + } + } + if (cn.key_eq(propertyAssignment.getInitializer())) { + if (index = 1) { + return cn + } + } + } + } + for (computedPropertyName in ComputedPropertyName(__all_data__)) { + if (computedPropertyName.key_eq(self)) { + if (cn.key_eq(computedPropertyName.getExpression())) { + if (index = 0) { + return cn + } + } + } + } + for (shorthandPropertyAssignment in ShorthandPropertyAssignment(__all_data__)) { + if (shorthandPropertyAssignment.key_eq(self)) { + if (cn.key_eq(shorthandPropertyAssignment.getNameNode())) { + if (index = 0) { + return cn + } + } + } + } + for (spreadAssignment in SpreadAssignment(__all_data__)) { + if (spreadAssignment.key_eq(self)) { + if (cn.key_eq(spreadAssignment.getExpression())) { + if (index = 0) { + return cn + } + } + } + } + for (parameter in Parameter(__all_data__)) { + if (parameter.key_eq(self)) { + if (parameter.hasInitializer()) { + if (cn.key_eq(parameter.getInitializer())) { + if (index = 0) { + return cn + } + } + if (cn.key_eq(parameter.getNameNode())) { + if (index = 1) { + return cn + } + } + } + if (!parameter.hasInitializer()) { + if (cn.key_eq(parameter.getNameNode())) { + if (index = 0) { + return cn + } + } + } + } + } + // UnaryExpression's sub class + for (tae in TypeAssertionExpression(__all_data__)) { + if (self.key_eq(tae)) { + if (index = 0) { + if (cn.key_eq(tae.getExpression())) { + return cn + } + } + } + } + for (de in DeleteExpression(__all_data__)) { + if (self.key_eq(de)) { + if (index = 0) { + if (cn.key_eq(de.getExpression())) { + return cn + } + } + } + } + for (toe in TypeOfExpression(__all_data__)) { + if (self.key_eq(toe)) { + if (index = 0) { + if (cn.key_eq(toe.getExpression())) { + return cn + } + } + } + } + for (ve in VoidExpression(__all_data__)) { + if (self.key_eq(ve)) { + if (index = 0) { + if (cn.key_eq(ve.getExpression())) { + return cn + } + } + } + } + for (awaitExpr in AwaitExpression(__all_data__)) { + if (self.key_eq(awaitExpr)) { + if (index = 0) { + if (cn.key_eq(awaitExpr.getExpression())) { + return cn + } + } + } + } + for (prefixUE in PrefixUnaryExpression(__all_data__)) { + if (self.key_eq(prefixUE)) { + if (index = 0) { + if (cn.key_eq(prefixUE.getOperand())) { + return cn + } + } + } + } + for (postfixUE in PostfixUnaryExpression(__all_data__)) { + if (self.key_eq(postfixUE)) { + if (index = 0) { + if (cn.key_eq(postfixUE.getOperand())) { + return cn + } + } + } + } + for (nne in NonNullExpression(__all_data__)) { + if (self.key_eq(nne)) { + if (index = 0) { + if (cn.key_eq(nne.getExpression())) { + return cn + } + } + } + } + for (ce in CallExpression(__all_data__)) { + if (self.key_eq(ce)) { + if (index = 0) { + if (cn.key_eq(ce.getExpression())) { + return cn + } + } + for (argIndex in int::__undetermined_all__()) { + if (cn.key_eq(ce.getArgument(argIndex))) { + if (index = argIndex + 1) { + return cn + } + } + } + } + } + for (ae in AccessExpression(__all_data__)) { + if (self.key_eq(ae)) { + if (index = 0) { + if (cn.key_eq(ae.getExpression())) { + return cn + } + } + if (index = 1) { + if (cn.key_eq(ae.getPropertyExpression())) { + return cn + } + } + } + } + for (ale in ArrayLiteralExpression(__all_data__)) { + if (self.key_eq(ale)) { + if (cn.key_eq(ale.getElement(index))) { + return cn + } + } + } + for (ne in NewExpression(__all_data__)) { + if (self.key_eq(ne)) { + if (index = 0) { + if (cn.key_eq(ne.getExpression())) { + return cn + } + } + for (argIndex in int::__undetermined_all__()) { + if (cn.key_eq(ne.getArgument(argIndex))) { + if (index = argIndex + 1) { + return cn + } + } + } + } + } + for (parenthesizedExpression in ParenthesizedExpression(__all_data__)) { + if (self.key_eq(parenthesizedExpression)) { + if (index = 0) { + if (cn.key_eq(parenthesizedExpression.getExpression())) { + return cn + } + } + } + } + // BinaryExpression's sub class + for (be in BinaryExpression(__all_data__)) { + if (self.key_eq(be)) { + let (tmp = Node(__all_data__).find(be)) { + // node is assignment expr, visit right hand side first. + if (isAssignmentExpression(tmp)) { + if (index = 0) { + if (cn.key_eq(be.getRightOperand())) { + return cn + } + } + if (index = 1) { + if (cn.key_eq(be.getLeftOperand())) { + return cn + } + } + } + if (!isAssignmentExpression(tmp)) { + if (index = 0) { + if (cn.key_eq(be.getLeftOperand())) { + return cn + } + } + if (index = 1) { + if (cn.key_eq(be.getRightOperand())) { + return cn + } + } + } + } + } + } + for (vdl in VariableDeclarationList(__all_data__)) { + if (self.key_eq(vdl)) { + let (vd = vdl.getVariableDeclaration(index)) { + if (cn.key_eq(vd)) { + return cn + } + } + } + } + for (variableDeclaration in VariableDeclaration(__all_data__)) { + if (variableDeclaration.key_eq(self)) { + if (variableDeclaration.hasInitializer()) { + if (cn.key_eq(variableDeclaration.getInitializer())) { + if (index = 0) { + return cn + } + } + if (cn.key_eq(variableDeclaration.getNameNode())) { + if (index = 1) { + return cn + } + } + } + if (!variableDeclaration.hasInitializer()) { + if (cn.key_eq(variableDeclaration.getNameNode())) { + if (index = 0) { + return cn + } + } + } + } + } + for (objectBindingPattern in ObjectBindingPattern(__all_data__)) { + if (objectBindingPattern.key_eq(self)) { + if (cn.key_eq(objectBindingPattern.getElement(index))) { + return cn + } + } + } + for (arrayBindingPattern in ArrayBindingPattern(__all_data__)) { + if (arrayBindingPattern.key_eq(self)) { + if (cn.key_eq(arrayBindingPattern.getElement(index))) { + return cn + } + } + } + for (bindingElement in BindingElement(__all_data__)) { + if (bindingElement.key_eq(self)) { + if (bindingElement.hasInitializer()) { + if (cn.key_eq(bindingElement.getInitializer())) { + if (index = 0) { + return cn + } + } + if (cn.key_eq(bindingElement.getNameNode())) { + if (index = 1) { + return cn + } + } + } + if (!bindingElement.hasInitializer()) { + if (cn.key_eq(bindingElement.getNameNode())) { + if (index = 0) { + return cn + } + } + } + } + } + for (rs in ReturnStatement(__all_data__)) { + if (self.key_eq(rs)) { + if (cn.key_eq(rs.getExpression())) { + if (index = 0) { + return cn + } + } + } + } + for (ye in YieldExpression(__all_data__)) { + if (self.key_eq(ye)) { + if (cn.key_eq(ye.getExpression())) { + if (index = 0) { + return cn + } + } + } + } + for (ae in AsExpression(__all_data__)) { + if (self.key_eq(ae)) { + if (cn.key_eq(ae.getExpression())) { + if (index = 0) { + return cn + } + } + } + } + for (se in SpreadElement(__all_data__)) { + if (self.key_eq(se)) { + if (cn.key_eq(se.getExpression())) { + if (index = 0) { + return cn + } + } + } + } + for (throwStatement in ThrowStatement(__all_data__)) { + if (self.key_eq(throwStatement)) { + if (cn.key_eq(throwStatement.getExpression())) { + if (index = 0) { + return cn + } + } + } + } + for (templateExpression in TemplateExpression(__all_data__), + templateHead in TemplateHead(__all_data__)) { + if (self.key_eq(templateExpression)) { + if (templateHead = templateExpression.getHead()) { + if (cn.key_eq(templateHead)) { + if (index = 0) { + return cn + } + } + } + } + } + for (spanIndex in int::__undetermined_all__()) { + for (templateExpression in TemplateExpression(__all_data__), + templateSpan in TemplateSpan(__all_data__)) { + if (self.key_eq(templateExpression)) { + if (templateSpan = templateExpression.getTemplateSpan(spanIndex)) { + if (cn.key_eq(templateSpan)) { + if (index = spanIndex + 1) { + return cn + } + } + } + } + } + } + for (templateSpan in TemplateSpan(__all_data__), + expression in Expression(__all_data__)) { + if (self.key_eq(templateSpan)) { + if (expression = templateSpan.getExpression()) { + if (cn.key_eq(expression)) { + if (index = 0) { + return cn + } + } + } + } + } + for (templateSpan in TemplateSpan(__all_data__), + token in Token(__all_data__)) { + if (self.key_eq(templateSpan)) { + if (token = templateSpan.getLiteral()) { + if (cn.key_eq(token)) { + if (index = 1) { + return cn + } + } + } + } + } + } + } + + /** + * Gets the first child of this node. + */ + pub fn firstChild(self) -> ControlFlowNode { + return self.getChildNode(0) + } + + /** + * Hold whether this node is leaf node. + */ + pub fn isLeafNode(self) -> bool { + let (cc = self.getChildCount()) { + if (cc = 0) { + return true + } + } + } + + /** + * Holds whether this node can finish with a normalCompletion. + */ + pub fn mayCompleteNormally(self) -> bool { + let (node = self.to()) { + if (!isReturnStatement(node) && !isThrowStatement(node)) { + return true + } + } + } + + /** + * Gets the count of the children. + */ + pub fn getChildCount(self) -> int { + return self.getAllChild().len() + } +} + +/** + * a node that occur in a context in which their value affect control flow. + */ +pub fn inBooleanContext(n: ControlFlowNode) -> bool { + for (ble in BinaryLogicalExpression(__all_data__)) { + if (n.key_eq(ble.getLeftOperand())) { + return true + } + } + for (ble in BinaryLogicalExpression(__all_data__)) { + let (ro = ble.getRightOperand()) { + if (n.key_eq(ro)) { + if (inBooleanContext(ControlFlowNode(__all_data__).find(ble))) { + return true + } + } + } + } + for (ete in EqualityTestExpression(__all_data__)) { + if (n.key_eq(ete.getLeftOperand())) { + return true + } + } + for (ete in EqualityTestExpression(__all_data__)) { + let (ro = ete.getRightOperand()) { + if (n.key_eq(ro)) { + if (inBooleanContext(ControlFlowNode(__all_data__).find(ete))) { + return true + } + } + } + } + for (ce in ConditionalExpression(__all_data__)) { + if (n.key_eq(ce.getCondition())) { + return true + } + } + for (ce in ConditionalExpression(__all_data__)) { + let (thenOrElseExpr = ce.getThen()) { + if (n.key_eq(thenOrElseExpr)) { + if (inBooleanContext(ControlFlowNode(__all_data__).find(ce))) { + return true + } + } + } + let (thenOrElseExpr = ce.getElse()) { + if (n.key_eq(thenOrElseExpr)) { + if (inBooleanContext(ControlFlowNode(__all_data__).find(ce))) { + return true + } + } + } + } + for (ifStmt in IfStatement(__all_data__)) { + if (n.key_eq(ifStmt.getCondition())) { + return true + } + } + for (forStmt in ForStatement(__all_data__)) { + if (n.key_eq(forStmt.getCondition())) { + return true + } + } + for (dws in DoWhileStatement(__all_data__)) { + if (n.key_eq(dws.getCondition())) { + return true + } + } + for (ws in WhileStatement(__all_data__)) { + if (n.key_eq(ws.getCondition())) { + return true + } + } +} + +/** + * Determine whether a control flow node throws + * an exception. + */ +pub fn mayThrow(cfn: ControlFlowNode) -> bool { + for (throwStatement in ThrowStatement(__all_data__)) { + if (cfn.key_eq(throwStatement)) { + return true + } + } +} + +/** + * Determine whether a control flow node is a post order node. + */ +pub fn isPostOrderNode(controlFlowNode: ControlFlowNode) -> bool { + let (node = Node(__all_data__).find(controlFlowNode)) { + // Unary expressions + if (isTypeAssertionExpression(node)) { + return true + } + if (isDeleteExpression(node)) { + return true + } + if (isTypeOfExpression(node)) { + return true + } + if (isVoidExpression(node)) { + return true + } + if (isAwaitExpression(node)) { + return true + } + if (isPrefixUnaryExpression(node)) { + return true + } + if (isPostfixUnaryExpression(node)) { + return true + } + if (isNonNullExpression(node)) { + return true + } + if (isCallLikeExpression(node)) { + return true + } + if (isAccessExpression(node)) { + return true + } + if (isIdentifier(node)) { + return true + } + if (isPrivateIdentifier(node)) { + return true + } + if (isThisExpression(node)) { + return true + } + if (isSuperExpression(node)) { + return true + } + if (isArrayLiteralExpression(node)) { + return true + } + if (isParenthesizedExpression(node)) { + return true + } + if (isLiteralExpression(node)) { + return true + } + if (isBooleanLiteral(node)) { + return true + } + if (isTemplateExpression(node)) { + return true + } + // End of unary expressions + if (isTemplateSpan(node)) { + return true + } + if (isToken(node)) { + return true + } + // Binary expressions + if (isBinaryExpression(node)) { + if (!isBinaryLogicalExpression(node)) { + return true + } + } + // empty BlockStatement is PostOrderNode + for (bs in BlockStatement(__all_data__)) { + if (bs.key_eq(node)) { + if (bs.getStatementCount() = 0) { + return true + } + } + } + if (isVariableDeclarationList(node)) { + return true + } + if (isVariableDeclaration(node)) { + return true + } + if (isReturnStatement(node)) { + return true + } + if (isYieldExpression(node)) { + return true + } + if (isAsExpression(node)) { + return true + } + if (isSpreadElement(node)) { + return true + } + if (isAssignmentExpression(node)) { + return true + } + if (isOmittedExpression(node)) { + return true + } + // including ObjectBindingPattern and ArrayBindingPattern + if (isBindingPattern(node)) { + return true + } + // including BindingElement and OmittedExpression + if (isArrayBindingElement(node)) { + return true + } + if (isEnumMember(node)) { + return true + } + if (isEmptyStatement(node)) { + return true + } + if (isDebuggerStatement(node)) { + return true + } + if (isThrowStatement(node)) { + return true + } + if (isDeclarationStatement(node)) { + return true + } + // There is no control flow relation between FunctionExpression + // and it's body; the cfg from it's body is another cfg, don't + // have relation with current cfg; + // just treat FunctionExpression as a node without children. + // Same with ClassExpression, ObjectLiteralExpression. + if (isFunctionExpression(node)) { + return true + } + if (isArrowFunction(node)) { + return true + } + if (isClassExpression(node)) { + return true + } + if (isObjectLiteralExpression(node)) { + return true + } + if (isObjectLiteralElement(node)) { + return true + } + if (isComputedPropertyName(node)) { + return true + } + if (isParameter(node)) { + return true + } + } +} + +/** + * If the body of loop finishes with completion, + * the loop will continue executing. + */ +pub fn continues(c: Completion, loop: IterationStatement) -> bool { + if (isNormalCompletion(c)) { + for (tmp in IterationStatement(__all_data__)) { + if (tmp = loop) { + return true + } + } + } + // only consider continue completions if there actually is a `continue` + // somewhere inside this loop; we don't particularly care whether that + // `continue` could actually target this loop, we just want to restrict + // the size of the predicate + for (continueStmt in ContinueStatement(__all_data__)) { + for (auto_tmp1 in continueStmt.getAnAncestor()) { + if (auto_tmp1.key_eq(loop)) { + if (isContinueCompletion(c)) { + return true + } + } + } + } +} + +/** + * Get the node that should be visited first, + * selected from the node and it's descendants. + * Every control flow node must have and only have 1 first node. + */ +pub fn first(n: ControlFlowNode) -> ControlFlowNode { + // n is Statement, if the Statement is not PostOrderNode, visit itself first + for (s in Statement(__all_data__)) { + if (n.key_eq(s)) { + if (!isPostOrderNode(n)) { + return n + } + } + } + // n is PostOrderNode, the node has children, visit first child + for (pon in PostOrderNode(__all_data__)) { + if (n.key_eq(pon)) { + let (fcn = pon.firstChild()) { + let (f = first(fcn)) { + return f + } + } + } + } + // n is PostOrderNode, the node is leaf node, visit the node + for (pon in PostOrderNode(__all_data__)) { + if (n.key_eq(pon)) { + if (pon.isLeafNode()) { + return n + } + } + } + // the first node of ConditionalExpression is itself + for (ce in ConditionalExpression(__all_data__)) { + if (n.key_eq(ce)) { + return n + } + } + // the first node of BinaryLogicalExpression is itself + for (ble in BinaryLogicalExpression(__all_data__)) { + if (n.key_eq(ble)) { + return n + } + } +} + +/** + * Get the node that should be visited last, + * selected from the node and it's descendants. + * Every control flow node must have at least 1 last node. + */ +pub fn last(n: ControlFlowNode, ln: ControlFlowNode, c: Completion) -> bool { + // if the node is in boolean context, + // the completion should be BooleanCompletion + for (nc in NormalCompletion()) { + if (last(n, ln, nc.to())) { + if (inBooleanContext(n)) { + if (isBooleanCompletion(c)) { + return true + } + } + } + } + // the last of top-level is the last node of the last statement of the top-level + for (topLevel in TopLevel(__all_data__)) { + if (n.key_eq(topLevel)) { + let (statementCount = topLevel.getStatementCount()) { + let (lastStatement = topLevel.getStatement(statementCount - 1)) { + if (last(ControlFlowNode {id: lastStatement.id}, ln, c)) { + return true + } + } + } + } + } + // the last of BlockStatement is the last node of the statement that + // is the last statement of the BlockStatement body + for (bs in BlockStatement(__all_data__)) { + if (n.key_eq(bs)) { + let (sc = bs.getStatementCount()) { + let (lastStmt = bs.getStatement(sc - 1)) { + if (last(ControlFlowNode {id: lastStmt.id}, ln, c)) { + return true + } + } + } + } + } + // any child Statement in BlockStatement, it is the last node of + // BlockStatement if it's last node is not NormalCompletion + if (!isNormalCompletion(c)) { + for (bs in BlockStatement(__all_data__)) { + if (n.key_eq(bs)) { + for (childStmt in Statement(__all_data__)) { + if (childStmt in bs.getAStatement()) { + if (last(ControlFlowNode {id: childStmt.id}, ln, c)) { + return true + } + } + } + } + } + } + // the last of IfStatement is the last of the then block and + // the last of the else block + for (ifStmt in IfStatement(__all_data__)) { + if (n.key_eq(ifStmt)) { + let (thenNode = ifStmt.getThen()) { + if (last(ControlFlowNode {id: thenNode.id}, ln, c)) { + return true + } + } + let (elseNode = ifStmt.getElse()) { + if (last(ControlFlowNode {id: elseNode.id}, ln, c)) { + return true + } + } + } + } + // if the IfStatement don't have else block, + // the last node of condition is the last node of IfStatement, completion is NormalCompletion + if (isNormalCompletion(c)) { + for (ifStmt in IfStatement(__all_data__)) { + if (n.key_eq(ifStmt)) { + if (!ifStmt.hasElse()) { + let (cond = ifStmt.getCondition()) { + for (fbc in FalseBooleanCompletion()) { + if (last(ControlFlowNode {id: cond.id}, ln, fbc.to())) { + return true + } + } + } + } + } + } + } + for (loop in IterationStatement(__all_data__)) { + if (n.key_eq(loop)) { + // 1. The last node is the last node of condition expression, + // when a loop statement terminate normally if its condition is false. + if (isNormalCompletion(c)) { + let (condition = loop.getCondition()) { + for (falseCompletion in FalseBooleanCompletion()) { + if (falseCompletion in FalseBooleanCompletion()) { + if (last(ControlFlowNode {id: condition.id}, ln, falseCompletion.to())) { + return true + } + } + } + } + } + // 2. The last node is the iterated expression in an enhanced-for statement, + // when an enhanced-for statement iterate over immediately after the iterated expression. + if (isNormalCompletion(c)) { + let (enhancedForStmt = loop.to()) { + let (iteratedExpr = enhancedForStmt.getExpression()) { + if (last(ControlFlowNode {id: iteratedExpr.id}, ln, c)) { + return true + } + } + } + } + // 3. The last node is the last node of the body... + let (body = loop.getBody()) { + for (bodyCompletion in Completion()) { + if (last(body.to(), ln, bodyCompletion)) { + if (isNormalCompletion(c)) { + // ... when in an iteration of a enhanced-for statement, the loop would continue after the last node in the body. + let (enhancedForStmt = loop.to()) { + if (continues(bodyCompletion, loop)) { + return true + } + } + } + // ... or the loop ends after the last node in the body. + // if the completion is a break completion, the entire loop will complete normally. + if (isNormalCompletion(c)) { + if (isBreakCompletion(bodyCompletion)) { + return true + } + } + // ... or if it is some other completion that does not continue the loop, + // the loop should keep the body completion + if (!isBreakCompletion(bodyCompletion)) { + if (!continues(bodyCompletion, loop)) { + if (c = bodyCompletion) { + return true + } + } + } + } + } + } + } + } + if (isBreakCompletion(c)) { + for (breakStatement in BreakStatement(__all_data__)) { + if (n.key_eq(breakStatement)) { + if (ln = n) { + return true + } + } + } + } + if (isContinueCompletion(c)) { + if (ln = n) { + for (continueStatement in ContinueStatement(__all_data__)) { + if (n.key_eq(continueStatement)) { + return true + } + } + } + } + // the last of ExpressionStatement is the last of the expression + // of the ExpressionStatement + for (es in ExpressionStatement(__all_data__)) { + if (n.key_eq(es)) { + let (e = es.getExpression()) { + if (last(ControlFlowNode {id: e.id}, ln, c)) { + return true + } + } + } + } + // the last of the PostOrderNode is the node itself + if (isNormalCompletion(c)) { + for (pon in PostOrderNode(__all_data__)) { + if (n.key_eq(pon)) { + if (pon.mayCompleteNormally()) { + if (ln = n) { + return true + } + } + } + } + } + // the last of the ReturnStatement is the stmt itself + // completion is ReturnCompletion + if (isReturnCompletion(c)) { + for (rs in ReturnStatement(__all_data__)) { + if (n.key_eq(rs)) { + if (ln = n) { + return true + } + } + } + } + // the last node of ConditionalExpression is the last node of + // it's then or the last node of it's else + for (ce in ConditionalExpression(__all_data__)) { + if (n.key_eq(ce)) { + let (thenExpr = ce.getThen()) { + if (last(ControlFlowNode {id: thenExpr.id}, ln, c)) { + return true + } + } + let (elseExpr = ce.getElse()) { + if (last(ControlFlowNode {id: elseExpr.id}, ln, c)) { + return true + } + } + } + } + // the last node of VariableStatement is VariableDeclarationList + // because VariableDeclarationList is post order node + if (isNormalCompletion(c)) { + for (vs in VariableStatement(__all_data__)) { + if (n.key_eq(vs)) { + let (vdl = vs.getVariableDeclarationList()) { + if (ln.key_eq(vdl)) { + return true + } + } + } + } + } + // LogicalAndExpression (&&) contains control flow info, + // related with short-circuit evaluation. + // the last node of LogicalAndExpression are the last of it's + // left operand with false boolean completion and + // the last of it's right operand + for (lae in LogicalAndExpression(__all_data__)) { + if (n.key_eq(lae)) { + if (isFalseBooleanCompletion(c)) { + let (leftOperand = lae.getLeftOperand()) { + if (last(ControlFlowNode {id: leftOperand.id}, ln, c)) { + return true + } + } + } + let (rightOperand = lae.getRightOperand()) { + if (last(ControlFlowNode {id: rightOperand.id}, ln, c)) { + return true + } + } + } + } + // LogicalOrExpression (||) contains control flow info, + // related with short-circuit evaluation. + // the last node of LogicalOrExpression are the last of it's + // left operand with true boolean completion and + // the last of it's right operand + for (loe in LogicalOrExpression(__all_data__)) { + if (n.key_eq(loe)) { + if (isTrueBooleanCompletion(c)) { + let (leftOperand = loe.getLeftOperand()) { + if (last(ControlFlowNode {id: leftOperand.id}, ln, c)) { + return true + } + } + } + let (rightOperand = loe.getRightOperand()) { + if (last(ControlFlowNode {id: rightOperand.id}, ln, c)) { + return true + } + } + } + } + // NullishCoalescingExpression (??) contains control flow info, + // same with LogicalOrExpression. + for (nce in NullishCoalescingExpression(__all_data__)) { + if (n.key_eq(nce)) { + if (isTrueBooleanCompletion(c)) { + let (leftOperand = nce.getLeftOperand()) { + if (last(ControlFlowNode {id: leftOperand.id}, ln, c)) { + return true + } + } + } + let (rightOperand = nce.getRightOperand()) { + if (last(ControlFlowNode {id: rightOperand.id}, ln, c)) { + return true + } + } + } + } + // the last node of WithStatement is the last of the statement + // belongs to the WithStatement. + for (withStatement in WithStatement(__all_data__)) { + if (n.key_eq(withStatement)) { + let (statement = withStatement.getStatement()) { + if (last(ControlFlowNode {id: statement.id}, ln, c)) { + return true + } + } + } + } + // if node may throw a exception, then create control flow edge + // and set the Completion to ThrowCompletion + // maybe we can distinct the throw statement with the may throw + // call statement, this can be discussed later + if (mayThrow(n)) { + if (ln = n) { + if (isThrowCompletion(c)) { + return true + } + } + } + // the last node of SwitchStatement is the last node of CaseBlock + for (switchStatement in SwitchStatement(__all_data__)) { + if (n.key_eq(switchStatement)) { + let (caseBlock = switchStatement.getCaseBlock()) { + if (last(ControlFlowNode {id: caseBlock.id}, ln, c)) { + return true + } + } + } + } + let (caseBlock = n.to()) { + // empty CaseBlock, the last node is itself + if (ln = n) { + if (isNormalCompletion(c)) { + if (caseBlock.getChildCount() = 0) { + return true + } + } + } + for (statement in Statement(__all_data__)) { + if (statement in caseBlock.getACaseOrDefault()) { + // if any last nodes of body belongs to CaseClause or DefaultClause + // with BreakCompletion, those last nodes are last node of + // CaseBlock with NormalCompletion + for (breakCompletion in BreakCompletion()) { + if (breakCompletion in BreakCompletion()) { + if (last(ControlFlowNode {id: statement.id}, ln, Completion().find(breakCompletion))) { + if (isNormalCompletion(c)) { + return true + } + } + } + } + // if any last nodes of body belongs to CaseClause or DefaultClause + // with the Completion that is neither NormalCompletion nor BreakCompletion, + // those last nodes are last node of CaseBlock and with the same Completion + if (!isNormalCompletion(c) && !isBreakCompletion(c)) { + if (last(ControlFlowNode {id: statement.id}, ln, c)) { + return true + } + } + } + } + // if CaseBlock have DefaultClause, the last node of DefaultClause with + // NormalCompletion, is the last node of CaseBlock + if (caseBlock.haveDefaultClause()) { + let (defaultClause = caseBlock.getDefaultClause()) { + if (isNormalCompletion(c)) { + if (last(ControlFlowNode {id: defaultClause.id}, ln, c)) { + return true + } + } + } + } + // if CaseBlock don't have DefaultClause, the last node of the last CaseClause + // with NormalCompletion, is the last node of CaseBlock + if (!caseBlock.haveDefaultClause()) { + let (caseClauseCount = caseBlock.getCaseClauseCount()) { + let (caseClause = caseBlock.getCaseClause(caseClauseCount - 1)) { + if (isNormalCompletion(c)) { + if (last(caseClause.to(), ln, c)) { + return true + } + } + } + } + } + } + for (caseClause in CaseClause(__all_data__)) { + if (n.key_eq(caseClause)) { + let (statementCount = caseClause.getStatementCount()) { + // if CaseClause don't contains any Statement, + // the last node CaseClause is the last node of it's + // expression + if (statementCount = 0) { + let (expression = caseClause.getExpression()) { + if (last(ControlFlowNode {id: expression.id}, ln, c)) { + return true + } + } + } + if (statementCount != 0) { + // any Statement belongs to CaseClause with Completion is + // is not NormalCompletion, it's last node is the last node + // of CaseClause + for (statement in Statement(__all_data__)) { + if (statement in caseClause.getAStatement()) { + if (last(ControlFlowNode {id: statement.id}, ln, c)) { + if (!isNormalCompletion(c)) { + return true + } + } + } + } + // the last node of the last statement belongs to CaseClause + // with NormalCompletion, is the last node of CaseClause + let (lastIndex = statementCount - 1) { + let (lastStatement = caseClause.getStatement(lastIndex)) { + if (last(lastStatement.to(), ln, c)) { + if (isNormalCompletion(c)) { + return true + } + } + } + } + } + } + } + } + // same with CaseClause + for (defaultClause in DefaultClause(__all_data__)) { + if (n.key_eq(defaultClause)) { + let (statementCount = defaultClause.getStatementCount()) { + // if DefaultClause don't contains any Statement, + // it's last node is itself + if (statementCount = 0) { + if (ln = n) { + if (isNormalCompletion(c)) { + return true + } + } + } + if (statementCount != 0) { + for (statement in Statement(__all_data__)) { + if (statement in defaultClause.getAStatement()) { + if (last(ControlFlowNode {id: statement.id}, ln, c)) { + if (!isNormalCompletion(c)) { + return true + } + } + } + } + let (lastIndex = statementCount - 1) { + let (lastStatement = defaultClause.getStatement(lastIndex)) { + if (last(ControlFlowNode {id: lastStatement.id}, ln, c)) { + if (isNormalCompletion(c)) { + return true + } + } + } + } + } + } + } + } + // n is TryStatement, if there is finally block, the last nodes + // are finally block's last nodes; otherwise the last nodes are + // try block's last nodes and catch clause's last nodes. + for (tryStatement in TryStatement(__all_data__)) { + if (n.key_eq(tryStatement)) { + if (tryStatement.haveFinallyBlock()) { + let (finallyBlockStatement = tryStatement.getFinallyBlock()) { + if (last(ControlFlowNode {id: finallyBlockStatement.id}, ln, c)) { + return true + } + } + } + if (!tryStatement.haveFinallyBlock()) { + let (blockStatement = tryStatement.getTryBlock()) { + if (last(ControlFlowNode {id: blockStatement.id}, ln, c)) { + return true + } + } + let (catchClause = tryStatement.getCatchClause()) { + if (last(ControlFlowNode {id: catchClause.id}, ln, c)) { + return true + } + } + } + } + } + for (catchClause in CatchClause(__all_data__)) { + if (n.key_eq(catchClause)) { + let (blockStatement = catchClause.getBlock()) { + if (last(ControlFlowNode {id: blockStatement.id}, ln, c)) { + return true + } + } + } + } +} + +/** + * Hold if two control flow nodes are in same CFG. + */ +pub fn nodeInSameCFG(cfn1: ControlFlowNode, cfn2: ControlFlowNode) -> bool { + if (cfn1 = cfn2) { + return true + } + if (cfn1 != cfn2) { + for (bb1 in BasicBlock(__all_data__), + bb2 in BasicBlock(__all_data__)) { + if (bbInSameCFG(bb1, bb2)) { + if (bb1 = cfn1.getBasicBlock() && + bb2 = cfn2.getBasicBlock()) { + return true + } + } + } + } +} + +@inline +fn iterationStatementSucc(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + for (loop in IterationStatement(__all_data__)) { + if (isWhileStatement(Node(__all_data__).find(loop))) { + let (condition = loop.getCondition()) { + let (body = loop.getBody()) { + // Control goes from the condition via a true-completion to the body... + if (last(ControlFlowNode(__all_data__).find(condition), n, c)) { + if (isTrueBooleanCompletion(c)) { + yield first(ControlFlowNode(__all_data__).find(body)) + } + } + // ...or through the back edge from the body back to the condition. + if (last(ControlFlowNode(__all_data__).find(body), n, c)) { + if (continues(c, loop)) { + yield first(ControlFlowNode(__all_data__).find(condition)) + } + } + } + } + } + if (isDoWhileStatement(Node(__all_data__).find(loop))) { + let (condition = loop.getCondition()) { + let (body = loop.getBody()) { + if (last(ControlFlowNode(__all_data__).find(condition), n, c)) { + if (isTrueBooleanCompletion(c)) { + yield first(ControlFlowNode(__all_data__).find(body)) + } + } + if (last(ControlFlowNode(__all_data__).find(body), n, c)) { + if (continues(c, loop)) { + yield first(ControlFlowNode(__all_data__).find(condition)) + } + } + } + } + } + } +} + +@inline +fn forStatementSucc(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + // `for` statements + // The `iterationEntry` is the entry node of each iteration. + for (forStmt in ForStatement(__all_data__)) { + let (condition = forStmt.getCondition()) { + // The `iterationEntry` is the first of condition + let (iterationEntry = first(ControlFlowNode(__all_data__).find(condition))) { + if (n.key_eq(forStmt)) { + // The successor of `for` statement is the first node of initializer + let (initializer = forStmt.getInitializer()) { + if (isNormalCompletion(c)) { + yield first(ControlFlowNode(__all_data__).find(initializer)) + } + } + } + // The successor of `for` statement is the iterationEntry if there is no initializer. + if (n.key_eq(forStmt)) { + if (!forStmt.hasInitializer()) { + if (isNormalCompletion(c)) { + yield iterationEntry + } + } + } + // The successor of the last of initializer is the iterationEntry. + let (initializer = forStmt.getInitializer()) { + if (last(ControlFlowNode(__all_data__).find(initializer), n, c)) { + if (isNormalCompletion(c)) { + yield iterationEntry + } + } + } + // The true successor of the last of condition is the first of body. + let (body = forStmt.getBody()) { + if (last(ControlFlowNode(__all_data__).find(condition), n, c)) { + if (isTrueBooleanCompletion(c)) { + yield first(ControlFlowNode(__all_data__).find(body)) + } + } + } + // The successor of the last of incrementor is the iterationEntry. + let (incrementor = forStmt.getIncrementor()) { + if (last(ControlFlowNode(__all_data__).find(incrementor), n, c)) { + if (isNormalCompletion(c)) { + yield iterationEntry + } + } + } + // The back edge of the loop. The successor of the last of body is the first of incrementor + // or the first of condition if there is no incrementor. + let (body = forStmt.getBody()) { + if (last(ControlFlowNode(__all_data__).find(body), n, c)) { + if (continues(c, IterationStatement(__all_data__).find(forStmt))) { + let (incrementor = forStmt.getIncrementor()) { + yield first(ControlFlowNode(__all_data__).find(incrementor)) + } + if (!forStmt.hasIncrementor()) { + yield iterationEntry + } + } + } + } + } + } + if (!forStmt.hasCondition()) { + let (body = forStmt.getBody()) { + // The `iterationEntry` is the first of body if there is no condition. + let (iterationEntry = first(ControlFlowNode(__all_data__).find(body))) { + if (n.key_eq(forStmt)) { + if (isNormalCompletion(c)) { + let (initializer = forStmt.getInitializer()) { + yield first(ControlFlowNode(__all_data__).find(initializer)) + } + } + } + if (n.key_eq(forStmt)) { + if (isNormalCompletion(c)) { + if (!forStmt.hasInitializer()) { + yield iterationEntry + } + } + } + let (initializer = forStmt.getInitializer()) { + if (isNormalCompletion(c)) { + if (last(ControlFlowNode(__all_data__).find(initializer), n, c)) { + yield iterationEntry + } + } + } + let (condition = forStmt.getCondition()) { + if (isTrueBooleanCompletion(c)) { + if (last(ControlFlowNode(__all_data__).find(condition), n, c)) { + yield first(ControlFlowNode(__all_data__).find(body)) + } + } + } + let (incrementor = forStmt.getIncrementor()) { + if (isNormalCompletion(c)) { + if (last(ControlFlowNode(__all_data__).find(incrementor), n, c)) { + yield iterationEntry + } + } + } + if (body = forStmt.getBody()) { + if (last(ControlFlowNode(__all_data__).find(body), n, c)) { + if (continues(c, IterationStatement(__all_data__).find(forStmt))) { + let (incrementor = forStmt.getIncrementor()) { + yield first(ControlFlowNode(__all_data__).find(incrementor)) + } + if (!forStmt.hasIncrementor()) { + yield iterationEntry + } + } + } + } + } + } + } + } +} + +@inline +fn enhancedForStatementSucc(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + // Enhanced `for` statements + // The successor of enhanced-for statement is the first of the iterated expression. + for (enhancedForStmt in EnhancedForStatement(__all_data__)) { + if (n.key_eq(enhancedForStmt)) { + if (isNormalCompletion(c)) { + let (expr = enhancedForStmt.getExpression()) { + yield first(ControlFlowNode(__all_data__).find(expr)) + } + } + } + // The successor of the last of expression is the first of initializer. + let (initializer = enhancedForStmt.getInitializer()) { + let (expr = enhancedForStmt.getExpression()) { + if (isNormalCompletion(c)) { + if (last(ControlFlowNode(__all_data__).find(expr), n, c)) { + yield first(ControlFlowNode(__all_data__).find(initializer)) + } + } + } + } + // The successor of the last of initializer is the first of body. + let (initializer = enhancedForStmt.getInitializer()) { + let (body = enhancedForStmt.getBody()) { + if (isNormalCompletion(c)) { + if (last(ControlFlowNode(__all_data__).find(initializer), n, c)) { + yield first(ControlFlowNode(__all_data__).find(body)) + } + } + } + } + // The back edge of the loop. The successor of the last of body is the first of initializer. + let (initializer = enhancedForStmt.getInitializer()) { + let (body = enhancedForStmt.getBody()) { + if (last(ControlFlowNode(__all_data__).find(body), n, c)) { + if (continues(c, IterationStatement(__all_data__).find(enhancedForStmt))) { + yield first(ControlFlowNode(__all_data__).find(initializer)) + } + } + } + } + } +} + +@inline +fn caseBlockSucc(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + if (isNormalCompletion(c)) { + // n is CaseBlock, successors are all of it's CaseClause's first node and + // it's DefaultClause's first node + for (caseBlock in CaseBlock(__all_data__)) { + if (n.key_eq(caseBlock)) { + for (caseOrDefaultStmt in caseBlock.getACaseOrDefault()) { + yield first(ControlFlowNode(__all_data__).find(caseOrDefaultStmt)) + } + } + // n is a the last node of one of CaseClause, successor is the + // first node of the next CaseClause + for (index in int::__undetermined_all__()) { + let (caseClause = caseBlock.getCaseClause(index)) { + if (last(ControlFlowNode(__all_data__).find(caseClause), n, c)) { + let (nextClause = caseBlock.getCaseClause(index + 1)) { + yield first(ControlFlowNode(__all_data__).find(nextClause)) + } + } + } + } + // n is the last node of last CaseClause, successor is the + // first node of DefaultClause + let (caseClauseCount = caseBlock.getCaseClauseCount()) { + let (index = caseClauseCount - 1) { + let (caseClause = caseBlock.getCaseClause(index)) { + if (last(ControlFlowNode(__all_data__).find(caseClause), n, c)) { + let (defaultClause = caseBlock.getDefaultClause()) { + yield first(ControlFlowNode(__all_data__).find(defaultClause)) + } + } + } + } + } + } + } +} + +@inline +fn caseClauseSucc(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + if (isNormalCompletion(c)) { + for (caseClause in CaseClause(__all_data__)) { + // n is CaseClause, successor is the first node of Expression + // belongs to the CaseClause. + if (n.key_eq(caseClause)) { + let (expression = caseClause.getExpression()) { + yield first(ControlFlowNode(__all_data__).find(expression)) + } + } + // n is the last node of Expression belongs to CaseClause, successor + // is the first node of the first Statement belongs to CaseClause + let (expression = caseClause.getExpression()) { + if (last(ControlFlowNode(__all_data__).find(expression), n, c)) { + let (statement = caseClause.getStatement(0)) { + yield first(ControlFlowNode(__all_data__).find(statement)) + } + } + } + // n is the last node of statement belongs to CaseClause, successor + // is the first node of the next statement. + for (index in int::__undetermined_all__()) { + let (statement = caseClause.getStatement(index)) { + if (last(ControlFlowNode(__all_data__).find(statement), n, c)) { + let (nextIndex = index + 1) { + let (nextStatement = caseClause.getStatement(nextIndex)) { + yield first(ControlFlowNode(__all_data__).find(nextStatement)) + } + } + } + } + } + } + } +} + +@inline +fn tryStatementSucc(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + // TODO: we just model sequential try-catch-finally control flow for now, + // need to model exception handling runtime behavior later. + for (tryStatement in TryStatement(__all_data__)) { + // n is TryStatement, successor is CatchClause of TryStatement + if (n.key_eq(tryStatement)) { + if (isNormalCompletion(c)) { + let (tryBlockStatement = tryStatement.getTryBlock()) { + yield first(tryBlockStatement.to()) + } + } + } + // n is the last node of try block, successors are first node of + // CatchClause and finally block + let (tryBlockStatement = tryStatement.getTryBlock()) { + if (last(tryBlockStatement.to(), n, c)) { + let (catchClause = tryStatement.getCatchClause()) { + yield first(catchClause.to()) + } + let (finallyBlockStatement = tryStatement.getFinallyBlock()) { + yield first(finallyBlockStatement.to()) + } + } + } + } +} + +@inline +fn defaultClauseSucc(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + // same with CaseClause + if (isNormalCompletion(c)) { + for (defaultClause in DefaultClause(__all_data__)) { + if (n.key_eq(defaultClause)) { + let (statement = defaultClause.getStatement(0)) { + yield first(ControlFlowNode(__all_data__).find(statement)) + } + } + for (index in int::__undetermined_all__()) { + let (statement = defaultClause.getStatement(index)) { + if (last(ControlFlowNode(__all_data__).find(statement), n, c)) { + let (nextIndex = index + 1) { + let (nextStatement = defaultClause.getStatement(nextIndex)) { + yield first(ControlFlowNode(__all_data__).find(nextStatement)) + } + } + } + } + } + } + } +} + +@inline +fn catchClauseSucc(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + // n is CatchClause, successor is the first node of VariableDeclaration + // if there exists, VariableDeclaration in CatchClause, otherwise successor + // is the first node of catch block. + for (catchClause in CatchClause(__all_data__)) { + if (n.key_eq(catchClause)) { + if (isNormalCompletion(c)) { + if (catchClause.haveVariableDeclaration()) { + let (variableDeclaration = catchClause.getVariableDeclaration()) { + yield first(variableDeclaration.to()) + } + } + if (!catchClause.haveVariableDeclaration()) { + let (blockStatement = catchClause.getBlock()) { + yield first(blockStatement.to()) + } + } + } + } + // n is the last node of VariableDeclaration belongs to CatchClause, + // successor is catch block. + let (variableDeclaration = catchClause.getVariableDeclaration()) { + if (last(variableDeclaration.to(), n, c)) { + if (isNormalCompletion(c)) { + let (blockStatement = catchClause.getBlock()) { + yield first(blockStatement.to()) + } + } + } + } + // n is the last node of catch block, successor is the first node of finally block + // belongs to the same TryStatement. + for (tryStatement in TryStatement(__all_data__)) { + let (catchBlockStatement = catchClause.getBlock()) { + if (last(catchBlockStatement.to(), n, c)) { + if (catchClause = tryStatement.getCatchClause()) { + let (finallyBlock = tryStatement.getFinallyBlock()) { + yield first(finallyBlock.to()) + } + } + } + } + } + } +} + +/** + * Gets the control flow successor node of a control flow node, + * and with the Completion information. + */ +pub fn succ(n: ControlFlowNode, c: Completion) -> *ControlFlowNode { + if (isNormalCompletion(c)) { + // n is top-level entry node, succ is the first of the top-level's 0th statement + for (entryNode in CfgEntryNode(__all_data__), + topLevel in TopLevel(__all_data__)) { + if (n.key_eq(entryNode)) { + if (topLevel.key_eq(entryNode.getAstNode())) { + let (firstStatement = topLevel.getStatement(0)) { + yield first(firstStatement.to()) + } + } + } + } + } + if (isNormalCompletion(c)) { + for (i in int::__undetermined_all__()) { + // n is the last of the top-level's i th statement, + // succ is the first of the top-level's i+1 th statement + for (topLevel in TopLevel(__all_data__)) { + let (statement = topLevel.getStatement(i)) { + if (last(ControlFlowNode(__all_data__).find(statement), n, c)) { + let (nextStatement = topLevel.getStatement(i + 1)) { + yield first(nextStatement.to()) + } + } + } + } + } + } + for (exitNode in CfgExitNode(__all_data__)) { + for (topLevel in TopLevel(__all_data__)) { + if (exitNode.getAstNode().key_eq(topLevel)) { + if (last(ControlFlowNode(__all_data__).find(topLevel), n, c)) { + yield ControlFlowNode(__all_data__).find(exitNode) + } + } + } + } + if (isNormalCompletion(c)) { + for (entryNode in CfgEntryNode(__all_data__), + enclosingFunction in FunctionLikeDeclaration(__all_data__)) { + if (n.key_eq(entryNode)) { + if (enclosingFunction.key_eq(entryNode.getAstNode())) { + for (parameter in Parameter(__all_data__)) { + if (parameter = enclosingFunction.getParameter(0)) { + yield first(ControlFlowNode(__all_data__).find(parameter)) + } + } + // TODO: body may be an Expression in an ArrowFunction + for (body in BlockStatement(__all_data__)) { + if (!enclosingFunction.hasParameter()) { + if (body = enclosingFunction.getBody()) { + yield first(ControlFlowNode(__all_data__).find(body)) + } + } + } + } + } + } + } + for (exitNode in CfgExitNode(__all_data__)) { + let (enclosingFunction = n.getEnclosingFunction()) { + if (exitNode.getAstNode().key_eq(enclosingFunction)) { + let (body = enclosingFunction.getBody()) { + if (last(ControlFlowNode(__all_data__).find(body), n, c)) { + yield ControlFlowNode(__all_data__).find(exitNode) + } + } + } + } + } + + if (isNormalCompletion(c)) { + for (index in int::__undetermined_all__()) { + for (parameter in Parameter(__all_data__), + enclosingFunction in FunctionLikeDeclaration(__all_data__)) { + if (n.key_eq(parameter)) { + if (parameter = enclosingFunction.getParameter(index)) { + let (parameterCount = enclosingFunction.getParameterCount()) { + if (index = parameterCount - 1) { + let (bodyStmt = enclosingFunction.getBody()) { + yield ControlFlowNode(__all_data__).find(bodyStmt) + } + } + if (index != parameterCount - 1) { + let (nextParameter = enclosingFunction.getParameter(index + 1)) { + yield first(ControlFlowNode(__all_data__).find(nextParameter)) + } + } + } + } + } + } + } + } + // the successor of ConditionalExpression is the first node of it's condition + if (isNormalCompletion(c)) { + for (ce in ConditionalExpression(__all_data__)) { + if (n.key_eq(ce)) { + let (cond = ce.getCondition()) { + yield first(ControlFlowNode(__all_data__).find(cond)) + } + } + } + } + // n is the last node of the ConditionalExpression's condition, it have 2 successors + // one is the first node of the ConditionalExpression's then block, completion is TrueBooleanCompletion + // another is the first node of the ConditionalExpression's else block, completion is FalseBooleanCompletion + if (isTrueBooleanCompletion(c)) { + for (ce in ConditionalExpression(__all_data__)) { + let (cond = ce.getCondition()) { + if (last(ControlFlowNode(__all_data__).find(cond), n, c)) { + let (thenBlock = ce.getThen()) { + yield first(ControlFlowNode(__all_data__).find(thenBlock)) + } + } + } + } + } + if (isFalseBooleanCompletion(c)) { + for (ce in ConditionalExpression(__all_data__)) { + let (cond = ce.getCondition()) { + if (last(ControlFlowNode(__all_data__).find(cond), n, c)) { + let (elseBlock = ce.getElse()) { + yield first(ControlFlowNode(__all_data__).find(elseBlock)) + } + } + } + } + } + + if (isNormalCompletion(c)) { + for (lae in LogicalAndExpression(__all_data__)) { + if (n.key_eq(lae)) { + let (leftOperand = lae.getLeftOperand()) { + yield first(ControlFlowNode(__all_data__).find(leftOperand)) + } + } + } + } + // n is BinaryLogicalExpression, it's successor is the first of the + // BinaryLogicalExpression's left operand + if (isTrueBooleanCompletion(c)) { + for (lae in LogicalAndExpression(__all_data__)) { + if (n.key_eq(lae)) { + let (leftOperand = lae.getLeftOperand()) { + let (rightOperand = lae.getRightOperand()) { + if (last(ControlFlowNode(__all_data__).find(leftOperand), n, c)) { + yield first(ControlFlowNode(__all_data__).find(rightOperand)) + } + } + } + } + } + } + if (isNormalCompletion(c)) { + for (loe in LogicalOrExpression(__all_data__)) { + if (n.key_eq(loe)) { + let (leftOperand = loe.getLeftOperand()) { + yield first(ControlFlowNode(__all_data__).find(leftOperand)) + } + } + } + } + if (isFalseBooleanCompletion(c)) { + for (lae in LogicalOrExpression(__all_data__)) { + let (leftOperand = lae.getLeftOperand()) { + if (last(ControlFlowNode(__all_data__).find(leftOperand), n, c)) { + let (rightOperand = lae.getRightOperand()) { + yield first(ControlFlowNode(__all_data__).find(rightOperand)) + } + } + } + } + } + if (isNormalCompletion(c)) { + for (nce in NullishCoalescingExpression(__all_data__)) { + if (n.key_eq(nce)) { + let (leftOperand = nce.getLeftOperand()) { + yield first(ControlFlowNode(__all_data__).find(leftOperand)) + } + } + } + } + // IfStatement's succ is the first of the if cond + if (isNormalCompletion(c)) { + for (ifStmt in IfStatement(__all_data__)) { + if (ifStmt.key_eq(n)) { + let (cond = ifStmt.getCondition()) { + let(s = first(ControlFlowNode(__all_data__).find(cond))) { + yield s + } + } + } + } + } + // n is the last of the if cond, succ is the first of then and the first of else + if (isTrueBooleanCompletion(c)) { + for (ifStmt in IfStatement(__all_data__)) { + let (cond = ifStmt.getCondition()) { + if (last(ControlFlowNode(__all_data__).find(cond), n, c)) { + let (thenStmt = ifStmt.getThen()) { + yield first(ControlFlowNode(__all_data__).find(thenStmt)) + } + } + } + } + } + if (isFalseBooleanCompletion(c)) { + for (ifStmt in IfStatement(__all_data__)) { + let (cond = ifStmt.getCondition()) { + if (last(ControlFlowNode(__all_data__).find(cond), n, c)) { + let (elseStmt = ifStmt.getElse()) { + yield first(ControlFlowNode(__all_data__).find(elseStmt)) + } + } + } + } + } + // `while` and `do`-`while` statements + // A `while` loop start at the condition... + if (isNormalCompletion(c)) { + for (whileStmt in WhileStatement(__all_data__)) { + if (n.key_eq(whileStmt)) { + let (condition = whileStmt.getCondition()) { + let(s = first(ControlFlowNode(__all_data__).find(condition))) { + yield s + } + } + } + } + } + // ...and a `do`-`while` loop starts at the body. + if (isNormalCompletion(c)) { + for (doWhileStmt in DoWhileStatement(__all_data__)) { + if (n.key_eq(doWhileStmt)) { + let (body = doWhileStmt.getBody()) { + let (s = first(ControlFlowNode(__all_data__).find(body))) { + yield s + } + } + } + } + } + yield iterationStatementSucc(n, c) + // End of `while` and `do`-`while` statements + yield forStatementSucc(n, c) + yield enhancedForStatementSucc(n, c) + // n is BlockStatement, succ is the first of the BlockStatement's 0 th child + for (bs in BlockStatement(__all_data__)) { + if (n.key_eq(bs)) { + if (isNormalCompletion(c)) { + let (fs = bs.getStatement(0)) { + yield first(ControlFlowNode(__all_data__).find(fs)) + } + } + } + } + // n is the last of the BlockStatement's i th child, + // succ is the first of the BlockStatement's i+1 th child + for (i in int::__undetermined_all__()) { + for (bs in BlockStatement(__all_data__)) { + let (iStmt = bs.getStatement(i)) { + if (isNormalCompletion(c)) { + if (last(ControlFlowNode(__all_data__).find(iStmt), n, c)) { + let (nextStmt = bs.getStatement(i + 1)) { + yield first(ControlFlowNode(__all_data__).find(nextStmt)) + } + } + } + } + } + } + // n is ExpressionStatement, succ is the first of the expression of ExpressionStatement + if (isNormalCompletion(c)) { + for (es in ExpressionStatement(__all_data__)) { + if (n.key_eq(es)) { + let (tmpNode = es.getExpression()) { + yield first(ControlFlowNode(__all_data__).find(tmpNode)) + } + } + } + } + // n is the last of the PostOrderNode's i th child, succ is the first of the + // PostOrderNode's i+1 th child + if (isNormalCompletion(c)) { + for (index in int::__undetermined_all__()) { + for (pon in PostOrderNode(__all_data__)) { + let (cn = pon.getChildNode(index)) { + if (last(cn, n, c)) { + let (nextCN = pon.getChildNode(index + 1)) { + yield first(nextCN) + } + } + } + } + } + } + // n is the last node of the last PostOrderNode's child, succ is the PostOrderNode + if (isNormalCompletion(c)) { + for (childCount in int::__undetermined_all__()) { + for (pon in PostOrderNode(__all_data__)) { + if (childCount = pon.getChildCount()) { + let (lastChild = pon.getChildNode(childCount - 1)) { + if (last(lastChild, n, c)) { + yield ControlFlowNode(__all_data__).find(pon) + } + } + } + } + } + } + // VariableStatement just have one child, it's a VariableDeclarationList, + // the successor of the VariableStatement is the first node of it's VariableDeclarationList + // the implementation of the VariableStatement is different from SomeQL + // treat the VariableDeclarationList as PostOrderNode is more easier + if (isNormalCompletion(c)) { + for (vs in VariableStatement(__all_data__)) { + if (n.key_eq(vs)) { + let (vdl = vs.getVariableDeclarationList()) { + yield first(ControlFlowNode(__all_data__).find(vdl)) + } + } + } + } + // n is a WithStatement, successor is the first of the expression belongs to WithStatement. + if (isNormalCompletion(c)) { + for (withStatement in WithStatement(__all_data__)) { + if (n.key_eq(withStatement)) { + let (expression = withStatement.getExpression()) { + yield first(ControlFlowNode(__all_data__).find(expression)) + } + } + } + } + // n is the last of the expression belongs to WithStatement, successor is the first + // of the statement belongs to WithStatement. + if (isNormalCompletion(c)) { + for (withStatement in WithStatement(__all_data__)) { + let (expression = withStatement.getExpression()) { + if (last(ControlFlowNode(__all_data__).find(expression), n, __all_data__)) { + let (statement = withStatement.getStatement()) { + yield first(ControlFlowNode(__all_data__).find(statement)) + } + } + } + } + } + if (isNormalCompletion(c)) { + for (switchStatement in SwitchStatement(__all_data__)) { + // n is a SwitchStatement, successor is the expression of SwitchStatement + if (n.key_eq(switchStatement)) { + let (expression = switchStatement.getExpression()) { + yield first(ControlFlowNode(__all_data__).find(expression)) + } + } + // n is the last of expression belongs to SwitchStatement, + // successor is the first of CaseBlock + let (expression = switchStatement.getExpression()) { + if (last(ControlFlowNode(__all_data__).find(expression), n, c)) { + let (caseBlock = switchStatement.getCaseBlock()) { + yield first(ControlFlowNode(__all_data__).find(caseBlock)) + } + } + } + } + } + yield caseBlockSucc(n, c) + yield caseClauseSucc(n, c) + yield defaultClauseSucc(n, c) + yield tryStatementSucc(n, c) + yield catchClauseSucc(n, c) +} diff --git a/language/javascript/lib/DOClass.gdl b/language/javascript/lib/DOClass.gdl new file mode 100644 index 00000000..233db9a5 --- /dev/null +++ b/language/javascript/lib/DOClass.gdl @@ -0,0 +1,761 @@ +/** + * @filename: DOCLASS + * @brief: DOCLASS provides classes and predicates for working with basic model of JavaScript / TypeScript code database. + */ + +schema LocationDO { + @primary oid: int, + file_oid: int, + start_line_number: int, + start_column_number: int, + end_line_number: int, + end_column_number: int, + text: string +} + +impl LocationDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *LocationDO { + for (tmp in db.location) { + yield LocationDO { + oid : tmp.oid, + file_oid : tmp.file_oid, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number, + text : tmp.text + } + } + } + + pub fn getFileOid(self) -> int { + return self.file_oid + } + + pub fn getStartLineNumber(self) -> int { + return self.start_line_number + } + + pub fn getStartColumnNumber(self) -> int { + return self.start_column_number + } + + pub fn getEndLineNumber(self) -> int { + return self.end_line_number + } + + pub fn getEndColumnNumber(self) -> int { + return self.end_column_number + } + + pub fn getText(self) -> string { + return self.text + } +} + +schema NumberOfLinesDO { + @primary location_oid: int, + lines: int, + code_lines: int, + comment_lines: int +} + +impl NumberOfLinesDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *NumberOfLinesDO { + for (tmp in db.number_of_lines) { + yield NumberOfLinesDO { + location_oid : tmp.location_oid, + lines : tmp.lines, + code_lines : tmp.code_lines, + comment_lines : tmp.comment_lines + } + } + } + + pub fn getLines(self) -> int { + return self.lines + } + + pub fn getCodeLines(self) -> int { + return self.code_lines + } + + pub fn getCommentLines(self) -> int { + return self.comment_lines + } +} + +schema FileDO { + @primary oid: int, + name: string, + extension: string, + relative_path: string, + location_oid: int +} + +impl FileDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *FileDO { + for (tmp in db.file) { + yield FileDO { + oid : tmp.oid, + name : tmp.name, + extension : tmp.extension, + relative_path : tmp.relative_path, + location_oid : tmp.location_oid + } + } + } + + pub fn getName(self) -> string { + return self.name + } + + pub fn getExtension(self) -> string { + return self.extension + } + + pub fn getRelativePath(self) -> string { + return self.relative_path + } + + pub fn getLocationOid(self) -> int { + return self.location_oid + } +} + +schema DirectoryDO { + @primary oid: int, + name: string, + relative_path: string, + location_oid: int +} + +impl DirectoryDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *DirectoryDO { + for (tmp in db.directory) { + yield DirectoryDO { + oid : tmp.oid, + name : tmp.name, + relative_path : tmp.relative_path, + location_oid : tmp.location_oid + } + } + } + + pub fn getName(self) -> string { + return self.name + } + + pub fn getRelativePath(self) -> string { + return self.relative_path + } + + pub fn getLocationOid(self) -> int { + return self.location_oid + } +} + +schema DirectoryHierarchyDO { + parent_oid: int, + @primary child_oid: int +} + +impl DirectoryHierarchyDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *DirectoryHierarchyDO { + for (tmp in db.directory_hierarchy) { + yield DirectoryHierarchyDO { + parent_oid : tmp.parent_oid, + child_oid : tmp.child_oid + } + } + } + + pub fn getParentOid(self) -> int { + return self.parent_oid + } +} + +schema TopLevelDO { + @primary oid: int, + kind: int, + location_oid: int +} + +impl TopLevelDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *TopLevelDO { + for (tmp in db.top_level) { + yield TopLevelDO { + oid : tmp.oid, + kind : tmp.kind, + location_oid : tmp.location_oid + } + } + } + + pub fn getKind(self) -> int { + return self.kind + } + + pub fn getLocationOid(self) -> int { + return self.location_oid + } +} + +schema NodeDO { + @primary oid: int, + kind: int, + parent_oid: int, + index: int, + location_oid: int +} + +impl NodeDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *NodeDO { + for (tmp in db.node) { + yield NodeDO { + oid : tmp.oid, + kind : tmp.kind, + parent_oid : tmp.parent_oid, + index : tmp.index, + location_oid : tmp.location_oid + } + } + } + + pub fn getKind(self) -> int { + return self.kind + } + + pub fn getParentOid(self) -> int { + return self.parent_oid + } + + pub fn getIndex(self) -> int { + return self.index + } + + pub fn getLocationOid(self) -> int { + return self.location_oid + } +} + +schema LiteralDO { + @primary oid: int, + value: string +} + +impl LiteralDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *LiteralDO { + for (tmp in db.literal) { + yield LiteralDO { + oid : tmp.oid, + value : tmp.value + } + } + } + + pub fn getValue(self) -> string { + return self.value + } +} + +schema BindingElementPropertyNameDO { + @primary oid: int, + property_name_oid: int +} + +impl BindingElementPropertyNameDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *BindingElementPropertyNameDO { + for (tmp in db.binding_element_property_name) { + yield BindingElementPropertyNameDO { + oid : tmp.oid, + property_name_oid : tmp.property_name_oid + } + } + } + + pub fn getPropertyNameOid(self) -> int { + return self.property_name_oid + } +} + +schema BindingElementNameDO { + @primary oid: int, + name_oid: int +} + +impl BindingElementNameDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *BindingElementNameDO { + for (tmp in db.binding_element_name) { + yield BindingElementNameDO { + oid : tmp.oid, + name_oid : tmp.name_oid + } + } + } + + pub fn getNameOid(self) -> int { + return self.name_oid + } +} + +schema BindingElementInitializerDO { + @primary oid: int, + initializer_oid: int +} + +impl BindingElementInitializerDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *BindingElementInitializerDO { + for (tmp in db.binding_element_initializer) { + yield BindingElementInitializerDO { + oid : tmp.oid, + initializer_oid : tmp.initializer_oid + } + } + } + + pub fn getInitializerOid(self) -> int { + return self.initializer_oid + } +} + +schema ClassLikeDeclarationDO { + @primary oid: int, + kind: int, + name: string +} + +impl ClassLikeDeclarationDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *ClassLikeDeclarationDO { + for (tmp in db.class_like_declaration) { + yield ClassLikeDeclarationDO { + oid : tmp.oid, + kind : tmp.kind, + name : tmp.name + } + } + } + + pub fn getKind(self) -> int { + return self.kind + } + + pub fn getName(self) -> string { + return self.name + } +} + +schema FunctionLikeDeclarationDO { + @primary oid: int, + kind: int, + name: string +} + +impl FunctionLikeDeclarationDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *FunctionLikeDeclarationDO { + for (tmp in db.function_like_declaration) { + yield FunctionLikeDeclarationDO { + oid : tmp.oid, + kind : tmp.kind, + name : tmp.name + } + } + } + + pub fn getKind(self) -> int { + return self.kind + } + + pub fn getName(self) -> string { + return self.name + } +} + +schema FunctionEnclosingNodeDO { + @primary node_oid: int, + function_oid: int +} + +impl FunctionEnclosingNodeDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *FunctionEnclosingNodeDO { + for (tmp in db.function_enclosing_node) { + yield FunctionEnclosingNodeDO { + node_oid : tmp.node_oid, + function_oid : tmp.function_oid + } + } + } + + pub fn getFunctionOid(self) -> int { + return self.function_oid + } +} + +schema ModifierDO { + @primary oid: int, + index: int +} + +impl ModifierDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *ModifierDO { + for (tmp in db.modifier) { + yield ModifierDO { + oid : tmp.oid, + index : tmp.index + } + } + } + + pub fn getIndex(self) -> int { + return self.index + } +} + +schema SymbolDO { + @primary oid: int, + name: string, + description: string +} + +impl SymbolDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *SymbolDO { + for (tmp in db.symbol_) { + yield SymbolDO { + oid : tmp.oid, + name : tmp.name, + description : tmp.description + } + } + } + + pub fn getName(self) -> string { + return self.name + } + + pub fn getDescription(self) -> string { + return self.description + } +} + +schema NodeSymbolDO { + @primary node_oid: int, + symbol_oid: int +} + +impl NodeSymbolDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *NodeSymbolDO { + for (tmp in db.node_symbol) { + yield NodeSymbolDO { + node_oid : tmp.node_oid, + symbol_oid : tmp.symbol_oid + } + } + } + + pub fn getSymbolOid(self) -> int { + return self.symbol_oid + } +} + +schema ShorthandAssignmentValueSymbolDO { + @primary node_oid: int, + symbol_oid: int +} + +impl ShorthandAssignmentValueSymbolDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *ShorthandAssignmentValueSymbolDO { + for (tmp in db.shorthand_assignment_value_symbol) { + yield ShorthandAssignmentValueSymbolDO { + node_oid : tmp.node_oid, + symbol_oid : tmp.symbol_oid + } + } + } + + pub fn getSymbolOid(self) -> int { + return self.symbol_oid + } +} + +schema CallSiteDO { + @primary invoke_expression_oid: int, + callee_oid: int +} + +impl CallSiteDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *CallSiteDO { + for (tmp in db.call_site) { + yield CallSiteDO { + invoke_expression_oid : tmp.invoke_expression_oid, + callee_oid : tmp.callee_oid + } + } + } + + pub fn getCalleeOid(self) -> int { + return self.callee_oid + } +} + +schema CfgEntryNodeDO { + @primary oid: int, + ast_node_oid: int +} + +impl CfgEntryNodeDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *CfgEntryNodeDO { + for (tmp in db.cfg_entry_node) { + yield CfgEntryNodeDO { + oid : tmp.oid, + ast_node_oid : tmp.ast_node_oid + } + } + } + + pub fn getAstNodeOid(self) -> int { + return self.ast_node_oid + } +} + +schema CfgExitNodeDO { + @primary oid: int, + ast_node_oid: int +} + +impl CfgExitNodeDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *CfgExitNodeDO { + for (tmp in db.cfg_exit_node) { + yield CfgExitNodeDO { + oid : tmp.oid, + ast_node_oid : tmp.ast_node_oid + } + } + } + + pub fn getAstNodeOid(self) -> int { + return self.ast_node_oid + } +} + +schema CommentDO { + @primary oid: int, + kind: int, + location_oid: int +} + +impl CommentDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *CommentDO { + for (tmp in db.comment) { + yield CommentDO { + oid : tmp.oid, + kind : tmp.kind, + location_oid : tmp.location_oid + } + } + } + + pub fn getKind(self) -> int { + return self.kind + } + + pub fn getLocationOid(self) -> int { + return self.location_oid + } +} + +schema NodeCommentDO { + @primary oid: int, + node_oid: int, + comment_oid: int, + type: int +} + +impl NodeCommentDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *NodeCommentDO { + for (tmp in db.node_comment) { + yield NodeCommentDO { + oid : tmp.oid, + node_oid : tmp.node_oid, + comment_oid : tmp.comment_oid, + type : tmp.type + } + } + } + + pub fn getNodeOid(self) -> int { + return self.node_oid + } + + pub fn getCommentOid(self) -> int { + return self.comment_oid + } + + pub fn getType(self) -> int { + return self.type + } +} + +schema JsParseErrorDO { + @primary oid: int, + message: string, + line: string +} + +impl JsParseErrorDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *JsParseErrorDO { + for (tmp in db.js_parse_error) { + yield JsParseErrorDO { + oid : tmp.oid, + message : tmp.message, + line : tmp.line + } + } + } + + pub fn getMessage(self) -> string { + return self.message + } + + pub fn getLine(self) -> string { + return self.line + } +} + +schema MetadataDO { + @primary oid: int, + version: string, + created_time: string +} + +impl MetadataDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *MetadataDO { + for (tmp in db.metadata) { + yield MetadataDO { + oid : tmp.oid, + version : tmp.version, + created_time : tmp.created_time + } + } + } + + pub fn getVersion(self) -> string { + return self.version + } + + pub fn getCreatedTime(self) -> string { + return self.created_time + } +} + +schema IgnoredPathDO { + @primary oid: int, + path_kind: int, + path: string, + ignore_kind: int +} + +impl IgnoredPathDO { + @data_constraint + @inline + pub fn __all__(db: JavascriptDB) -> *IgnoredPathDO { + for (tmp in db.ignored_path) { + yield IgnoredPathDO { + oid : tmp.oid, + path_kind : tmp.path_kind, + path : tmp.path, + ignore_kind : tmp.ignore_kind + } + } + } + + pub fn getPathKind(self) -> int { + return self.path_kind + } + + pub fn getPath(self) -> string { + return self.path + } + + pub fn getIgnoreKind(self) -> int { + return self.ignore_kind + } +} + +database JavascriptDB { + location: *LocationDO, + number_of_lines: *NumberOfLinesDO, + file: *FileDO, + directory: *DirectoryDO, + directory_hierarchy: *DirectoryHierarchyDO, + top_level: *TopLevelDO, + node: *NodeDO, + literal: *LiteralDO, + binding_element_property_name: *BindingElementPropertyNameDO, + binding_element_name: *BindingElementNameDO, + binding_element_initializer: *BindingElementInitializerDO, + class_like_declaration: *ClassLikeDeclarationDO, + function_like_declaration: *FunctionLikeDeclarationDO, + function_enclosing_node: *FunctionEnclosingNodeDO, + modifier: *ModifierDO, + symbol_: *SymbolDO, + node_symbol: *NodeSymbolDO, + shorthand_assignment_value_symbol: *ShorthandAssignmentValueSymbolDO, + call_site: *CallSiteDO, + cfg_entry_node: *CfgEntryNodeDO, + cfg_exit_node: *CfgExitNodeDO, + comment: *CommentDO, + node_comment: *NodeCommentDO, + js_parse_error: *JsParseErrorDO, + metadata: *MetadataDO, + ignored_path: *IgnoredPathDO, +} diff --git a/language/javascript/lib/DataFlowGraph.gdl b/language/javascript/lib/DataFlowGraph.gdl new file mode 100644 index 00000000..8d7600fc --- /dev/null +++ b/language/javascript/lib/DataFlowGraph.gdl @@ -0,0 +1,395 @@ +/** + * @filename: DataFlowGraph + * @brief: Provides classes and predicates for working with a data flow graph based JavaScript / TypeScript program representation. + */ + +schema DataFlowNode extends Node { +} + +impl DataFlowNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DataFlowNode { + for (tmp in Node(db)) { + if (isDataFlowNode(tmp)) { + yield DataFlowNode { + id : tmp.id + } + } + } + } + + pub fn getAPredecessor(self) -> *DataFlowNode { + for (predecessor in DataFlowNode(__all_data__)) { + if (localFlowEdge(predecessor, self)) { + yield predecessor + } + } + } + + pub fn getASuccessor(self) -> *DataFlowNode { + for (successor in DataFlowNode(__all_data__)) { + if (localFlowEdge(self, successor)) { + yield successor + } + } + } +} + +pub fn isDataFlowNode(node: Node) -> bool { + if (isExpression(node)) { + return true + } + if (isVariableDeclaration(node)) { + return true + } + if (isBindingPattern(node)) { + return true + } + if (isFunctionLikeDeclaration(node)) { + return true + } + if (isParameter(node)) { + return true + } + if (isClassLikeDeclaration(node)) { + return true + } + if (isClassElement(node)) { + return true + } + if (isObjectLiteralElement(node)) { + return true + } + if (isModuleDeclaration(node)) { + return true + } + if (isEnumDeclaration(node)) { + return true + } + if (isEnumMember(node)) { + return true + } +} + +pub fn lvalueFlowEdge(predecessor: DataFlowNode, successor: DataFlowNode) -> bool { + for (def in VarDef(__all_data__)) { + if (predecessor.key_eq(def.getSource())) { + for (auto_tmp1 in def.getATarget()) { + if (successor.key_eq(auto_tmp1)) { + return true + } + } + } + } + for (bindingPattern in BindingPattern(__all_data__)) { + if (predecessor.key_eq(bindingPattern)) { + for (auto_tmp2 in bindingPattern.getAnElement()) { + if (successor.key_eq(auto_tmp2)) { + return true + } + } + } + } + for (bindingElement in BindingElement(__all_data__)) { + if (predecessor.key_eq(bindingElement)) { + if (successor.key_eq(bindingElement.getNameNode())) { + return true + } + } + } + for (index in int::__undetermined_all__()) { + // TODO: Process all MayInvokeExpressions + for (callExpression in CallExpression(__all_data__)) { + if (predecessor.key_eq(callExpression.getArgument(index))) { + for (function in FunctionLikeDeclaration(__all_data__)) { + if (function = callExpression.getCallee()) { + if (successor.key_eq(function.getParameter(index))) { + return true + } + } + } + // fallback if the CallExpression doesn't have a callee + if (!callExpression.hasCallee()) { + if (successor.key_eq(callExpression)) { + return true + } + } + } + } + } + for (parameter in Parameter(__all_data__)) { + if (predecessor.key_eq(parameter)) { + if (successor.key_eq(parameter.getNameNode())) { + return true + } + } + } +} + +pub fn immediateFlowEdge(predecessor: DataFlowNode, successor: DataFlowNode) -> bool { + for (varUse in VarUse(__all_data__)) { + if (successor.key_eq(varUse)) { + for (auto_tmp1 in varUse.getDefinedByLValue()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + } + for (parenthesizedExpression in ParenthesizedExpression(__all_data__)) { + if (successor.key_eq(parenthesizedExpression)) { + if (predecessor.key_eq(parenthesizedExpression.getExpression())) { + return true + } + } + } + for (commaExpression in CommaExpression(__all_data__)) { + if (successor.key_eq(commaExpression)) { + if (predecessor.key_eq(commaExpression.getRight())) { + return true + } + } + } + for (simpleAssignmentExpression in SimpleAssignmentExpression(__all_data__)) { + if (successor.key_eq(simpleAssignmentExpression)) { + if (predecessor.key_eq(simpleAssignmentExpression.getRight())) { + return true + } + } + } + for (typeAssertionExpression in TypeAssertionExpression(__all_data__)) { + if (successor.key_eq(typeAssertionExpression)) { + if (predecessor.key_eq(typeAssertionExpression.getExpression())) { + return true + } + } + } + for (asExpression in AsExpression(__all_data__)) { + if (successor.key_eq(asExpression)) { + if (predecessor.key_eq(asExpression.getExpression())) { + return true + } + } + } + for (unaryExpression in UnaryExpression(__all_data__)) { + if (successor.key_eq(unaryExpression)) { + let (tmp = unaryExpression.to()) { + if (isUpdateExpression(tmp)) { + if (predecessor.key_eq(unaryExpression.getExpression())) { + return true + } + } + if (isTypeAssertionExpression(tmp)) { + if (predecessor.key_eq(unaryExpression.getExpression())) { + return true + } + } + if (isAwaitExpression(tmp)) { + if (predecessor.key_eq(unaryExpression.getExpression())) { + return true + } + } + } + } + } + for (nonNullExpression in NonNullExpression(__all_data__)) { + if (predecessor.key_eq(nonNullExpression.getExpression())) { + if (successor.key_eq(nonNullExpression)) { + return true + } + } + } + // TODO: ExpressionWithTypeArguments + for (compoundAssignmentExpression in CompoundAssignmentExpression(__all_data__)) { + if (successor.key_eq(compoundAssignmentExpression)) { + let (tmp = compoundAssignmentExpression.to()) { + if (isLogicalAndAssignmentExpression(tmp)) { + for (auto_tmp2 in compoundAssignmentExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp2)) { + return true + } + } + } + if (isLogicalOrAssignmentExpression(tmp)) { + for (auto_tmp2 in compoundAssignmentExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp2)) { + return true + } + } + } + if (isNullishAssignmentExpression(tmp)) { + for (auto_tmp2 in compoundAssignmentExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp2)) { + return true + } + } + } + } + } + } +} + +pub fn indirectFlowEdge(predecessor: DataFlowNode, successor: DataFlowNode) -> bool { + for (unaryExpression in UnaryExpression(__all_data__)) { + if (successor.key_eq(unaryExpression)) { + if (isTypeOfExpression(Node(__all_data__).find(unaryExpression))) { + if (predecessor.key_eq(unaryExpression.getExpression())) { + return true + } + } + } + } + for (binaryExpression in BinaryExpression(__all_data__)) { + if (successor.key_eq(binaryExpression)) { + let (tmp = binaryExpression.to()) { + if (isExponentiationExpression(tmp)) { + for (auto_tmp1 in binaryExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + if (isMultiplicativeExpression(tmp)) { + for (auto_tmp1 in binaryExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + if (isAdditiveExpression(tmp)) { + for (auto_tmp1 in binaryExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + if (isShiftExpression(tmp)) { + for (auto_tmp1 in binaryExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + if (isRelationalExpression(tmp)) { + for (auto_tmp1 in binaryExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + if (isEqualityTestExpression(tmp)) { + for (auto_tmp1 in binaryExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + if (isBinaryBitwiseExpression(tmp)) { + for (auto_tmp1 in binaryExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + if (isCompoundAssignmentExpression(tmp)) { + for (auto_tmp1 in binaryExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + } + } + } + for (objectLiteralExpression in ObjectLiteralExpression(__all_data__), + varDef in VarDef(__all_data__)) { + if (varDef.getSource().key_eq(objectLiteralExpression)) { + for (accessExpression in AccessExpression(__all_data__)) { + if (successor.key_eq(accessExpression)) { + for (auto_tmp1 in varDef.getAUse()) { + if (accessExpression.key_eq(auto_tmp1)) { + let (propertyName = accessExpression.getPropertyName()) { + let (objectLiteralElement = objectLiteralExpression.getPropertyByName(propertyName)) { + for (propertyAssignment in PropertyAssignment(__all_data__)) { + if (propertyAssignment.key_eq(objectLiteralElement)) { + if (predecessor.key_eq(propertyAssignment.getInitializer())) { + return true + } + } + } + for (shorthandPropertyAssignment in ShorthandPropertyAssignment(__all_data__)) { + if (shorthandPropertyAssignment.key_eq(objectLiteralElement)) { + if (predecessor.key_eq(shorthandPropertyAssignment.getIdentifier())) { + return true + } + } + } + } + } + } + } + } + } + } + } +} + +pub fn localFlowEdge(predecessor: DataFlowNode, successor: DataFlowNode) -> bool { + /** + * @todo the edges from the default values in BindingPatterns + */ + if (lvalueFlowEdge(predecessor, successor)) { + return true + } + if (immediateFlowEdge(predecessor, successor)) { + return true + } + for (binaryLogicalExpression in BinaryLogicalExpression(__all_data__)) { + if (successor.key_eq(binaryLogicalExpression)) { + for (auto_tmp1 in binaryLogicalExpression.getAnOperand()) { + if (predecessor.key_eq(auto_tmp1)) { + return true + } + } + } + } + for (conditionalExpression in ConditionalExpression(__all_data__)) { + if (successor.key_eq(conditionalExpression)) { + for (auto_tmp2 in conditionalExpression.getABranch()) { + if (predecessor.key_eq(auto_tmp2)) { + return true + } + } + } + } + for (function in FunctionLikeDeclaration(__all_data__)) { + for (auto_tmp3 in function.getAReturnedExpression()) { + if (predecessor.key_eq(auto_tmp3)) { + for (auto_tmp4 in function.getACallSite()) { + if (successor.key_eq(auto_tmp4)) { + return true + } + } + } + } + } + if (indirectFlowEdge(predecessor, successor)) { + return true + } +} + +pub fn flowTo(source: Node, sink: Node) -> bool { + if (source = sink) { + return true + } + let (begin = source.to()) { + for (middle in Node(__all_data__)) { + if (localFlowEdge(begin, DataFlowNode(__all_data__).find(middle))) { + if (flowTo(middle, sink)) { + return true + } + } + } + } +} diff --git a/language/javascript/lib/Declaration.gdl b/language/javascript/lib/Declaration.gdl new file mode 100644 index 00000000..1f699542 --- /dev/null +++ b/language/javascript/lib/Declaration.gdl @@ -0,0 +1,922 @@ +/** + * @filename: Declaration + * @brief: Provides classes and predicates for working with JavaScript / TypeScript declarations. + */ + +/** + * A type parameter. + */ +schema TypeParameter extends Node { +} + +impl TypeParameter { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeParameter { + for (tmp in Node(db)) { + if (isTypeParameter(tmp)) { + yield TypeParameter { + id : tmp.id + } + } + } + } +} + +/** + * A parameter declaration. + */ +schema Parameter extends Node { +} + +impl Parameter { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Parameter { + for (tmp in Node(db)) { + if (isParameter(tmp)) { + yield Parameter { + id : tmp.id + } + } + } + } + + /** + * Gets the `...` token of this parameter declaration. + */ + pub fn getDotDotDotToken(self) -> DotDotDotToken { + for (dotDotDotToken in DotDotDotToken(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (dotDotDotToken.key_eq(auto_tmp1)) { + return dotDotDotToken + } + } + } + } + + /** + * Determines whether this parameter declaration is a rest parameter. + */ + pub fn isRestParameter(self) -> bool { + for (dotDotDotToken in DotDotDotToken(__all_data__)) { + if (dotDotDotToken = self.getDotDotDotToken()) { + return true + } + } + } + + /** + * Gets the name of this parameter declaration. + */ + pub fn getNameNode(self) -> BindingName { + for (bindingName in BindingName(__all_data__)) { + if (self.isRestParameter()) { + if (bindingName.key_eq(self.getChild(1))) { + return bindingName + } + } + if (!self.isRestParameter()) { + if (bindingName.key_eq(self.getChild(0))) { + return bindingName + } + } + } + } + + /** + * Gets the `?` token of this parameter declaration. + */ + pub fn getQuestionToken(self) -> QuestionToken { + for (questionToken in QuestionToken(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (questionToken.key_eq(auto_tmp1)) { + return questionToken + } + } + } + } + + /** + * Determines whether this parameter declaration is an optional parameter, which means it has a `?` token. + */ + pub fn isOptionalParameter(self) -> bool { + for (questionToken in QuestionToken(__all_data__)) { + if (questionToken = self.getQuestionToken()) { + return true + } + } + } + + /** + * Gets the type node of this parameter. + */ + pub fn getType(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeNode.key_eq(auto_tmp1)) { + return typeNode + } + } + } + } + + /** + * Gets the initializer expression of this parameter. + */ + pub fn getInitializer(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (!self.isRestParameter()) { + if (expression.key_eq(self.getLastChild())) { + let (index = expression.getIndex()) { + if (index > 0) { + return expression + } + } + } + } + } + } + + /** + * Determines whether this parameter has the initializer. + */ + pub fn hasInitializer(self) -> bool { + for (expression in Expression(__all_data__)) { + if (expression = self.getInitializer()) { + return true + } + } + } +} + +/** + * A variable declaration + */ +schema VariableDeclaration extends Node { +} + +impl VariableDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *VariableDeclaration { + for (tmp in Node(db)) { + if (isVariableDeclaration(tmp)) { + yield VariableDeclaration { + id : tmp.id + } + } + } + } + + fn getAllBindingNameIndex(self) -> *int { + for (childIndex in int::range(0, self.getChildCount())) { + let (child = self.getChild(childIndex)) { + let (tmp = BindingName(__all_data__).find(child)) { + yield childIndex + } + } + } + } + + /** + * Gets a decorator. + */ + pub fn getADecorator(self) -> *Decorator { + for (decorator in Decorator(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (decorator.key_eq(auto_tmp1)) { + yield decorator + } + } + } + } + + /** + * Gets the `i`th decorator. + */ + pub fn getDecorator(self, i: int) -> Decorator { + for (decorator in Decorator(__all_data__)) { + if (decorator.key_eq(self.getChild(i))) { + return decorator + } + } + } + + /** + * Gets a modifier. + */ + pub fn getAModifier(self) -> *Modifier { + for (modifier in Modifier(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (modifier.key_eq(auto_tmp1)) { + yield modifier + } + } + } + } + + /** + * Gets the `i`th modifier. + */ + pub fn getModifier(self, i: int) -> Modifier { + for (childIndex in int::__undetermined_all__()) { + for (modifier in Modifier(__all_data__)) { + let (decoratorCount = self.getDecoratorCount()) { + if (modifier.key_eq(self.getChild(childIndex))) { + if (i = childIndex - decoratorCount) { + return modifier + } + } + } + } + } + } + + /** + * Gets the declared variable name + */ + pub fn getNameNode(self) -> BindingName { + for (name in BindingName(__all_data__)) { + let (index = self.getNameNodeIndex()) { + if (name.key_eq(self.getChild(index))) { + return name + } + } + } + } + + /** + * Gets the `!` token of this variable declaration. (Optional) + */ + pub fn getExclamationToken(self) -> ExclamationToken { + for (exclamationToken in ExclamationToken(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (exclamationToken.key_eq(auto_tmp1)) { + return exclamationToken + } + } + } + } + + /** + * Determines whether this variable declaration has the definite assignment assertion. + */ + pub fn hasDefiniteAssignmentAssertion(self) -> bool { + for (exclamationToken in ExclamationToken(__all_data__)) { + if (exclamationToken = self.getExclamationToken()) { + return true + } + } + } + + /** + * Gets the type node of the variable declaration. (Optional) + */ + pub fn getTypeNode(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeNode.key_eq(auto_tmp1)) { + return typeNode + } + } + } + } + + /** + * Gets the initialization expression. (Optional) + */ + pub fn getInitializer(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getLastChild())) { + let (index = expression.getIndex()) { + let (nameNodeIndex = self.getNameNodeIndex()) { + if (index > nameNodeIndex) { + return expression + } + } + } + } + } + } + + /** + * Determines whether this variable declaration has the initializer. + */ + pub fn hasInitializer(self) -> bool { + for (expression in Expression(__all_data__)) { + if (expression = self.getInitializer()) { + return true + } + } + } + + /** + * Gets the number of decorators. + */ + pub fn getDecoratorCount(self) -> int { + return self.getADecorator().len() + } + + /** + * Get the index of name node. + */ + pub fn getNameNodeIndex(self) -> int { + return self.getAllBindingNameIndex().min(); + } + + /** + * Gets the number of modifiers. + */ + pub fn getModifierCount(self) -> int { + return self.getAModifier().len() + } +} + +/** + * A variable declaration list + */ +schema VariableDeclarationList extends Node { +} + +impl VariableDeclarationList { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *VariableDeclarationList { + for (tmp in Node(db)) { + if (isVariableDeclarationList(tmp)) { + yield VariableDeclarationList { + id : tmp.id + } + } + } + } + + /** + * get a variable declaration + */ + pub fn getAVariableDeclaration(self) -> *VariableDeclaration { + for (vd in VariableDeclaration(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (vd.key_eq(auto_tmp1)) { + yield vd + } + } + } + } + + /** + * get the variable declaration with given + */ + pub fn getVariableDeclaration(self, i: int) -> VariableDeclaration { + for (childIndex in int::__undetermined_all__()) { + for (vd in VariableDeclaration(__all_data__)) { + if (vd.key_eq(self.getChild(childIndex))) { + if (i = childIndex) { + return vd + } + } + } + } + } + + /** + * get the count of the variable declarations + */ + pub fn getVariableDeclarationCount(self) -> int { + return self.getAVariableDeclaration().len() + } +} + +/** + * A binding element. + */ +schema BindingElement extends Node { +} + +impl BindingElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BindingElement { + for (tmp in Node(db)) { + if (isBindingElement(tmp)) { + yield BindingElement { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> BindingPattern { + for (parent in BindingPattern(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + /** + * Gets the `...` token. + */ + pub fn getDotDotDotToken(self) -> DotDotDotToken { + for (dotDotDotToken in DotDotDotToken(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (dotDotDotToken.key_eq(auto_tmp1)) { + return dotDotDotToken + } + } + } + } + + /** + * Whether this binding element is a rest element. + */ + pub fn isRest(self) -> bool { + for (dotDotDotToken in DotDotDotToken(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (dotDotDotToken.key_eq(auto_tmp1)) { + return true + } + } + } + } + + /** + * Get the bound property name node (only in object binding pattern). + */ + pub fn getPropertyName(self) -> PropertyName { + for (bindingElementPropertyName in BindingElementPropertyNameDO(__all_data__), + propertyName in PropertyName(__all_data__)) { + if (bindingElementPropertyName.key_eq(self)) { + if (propertyName.id = bindingElementPropertyName.getPropertyNameOid()) { + return propertyName + } + } + } + } + + pub fn hasPropertyName(self) -> bool { + for (bindingElementPropertyName in BindingElementPropertyNameDO(__all_data__)) { + if (bindingElementPropertyName.key_eq(self)) { + return true + } + } + } + + pub fn getPropertyNameString(self) -> string { + if (self.hasPropertyName()) { + for (propertyName in PropertyName(__all_data__)) { + if (propertyName = self.getPropertyName()) { + let (name = propertyName.getName()) { + return name + } + } + } + } + if (!self.hasPropertyName()) { + for (bindingName in BindingName(__all_data__)) { + if (bindingName = self.getNameNode()) { + let (name = bindingName.getName()) { + return name + } + } + } + } + } + + /** + * Get the name node. + */ + pub fn getNameNode(self) -> BindingName { + for (bindingElementName in BindingElementNameDO(__all_data__), + bindingName in BindingName(__all_data__)) { + if (bindingElementName.key_eq(self)) { + if (bindingName.id = bindingElementName.getNameOid()) { + return bindingName + } + } + } + } + + /** + * Get the initialization expression. + */ + pub fn getInitializer(self) -> Expression { + for (bindingElementInitializer in BindingElementInitializerDO(__all_data__), + expression in Expression(__all_data__)) { + if (bindingElementInitializer.key_eq(self)) { + if (expression.id = bindingElementInitializer.getInitializerOid()) { + return expression + } + } + } + } + + /** + * Determines whether this BindingElement has the initializer. + */ + pub fn hasInitializer(self) -> bool { + for (expression in Expression(__all_data__)) { + if (expression = self.getInitializer()) { + return true + } + } + } +} + +/** + * An array binding element. + */ +schema ArrayBindingElement extends Node { +} + +impl ArrayBindingElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ArrayBindingElement { + for (tmp in Node(db)) { + if (isArrayBindingElement(tmp)) { + yield ArrayBindingElement { + id : tmp.id + } + } + } + } +} + +/** + * A binding pattern. + */ +schema BindingPattern extends Node { +} + +impl BindingPattern { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BindingPattern { + for (tmp in Node(db)) { + if (isBindingPattern(tmp)) { + yield BindingPattern { + id : tmp.id + } + } + } + } + + pub fn getAnElement(self) -> *ArrayBindingElement { + for (element in ArrayBindingElement(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (element.key_eq(auto_tmp1)) { + yield element + } + } + } + } + + pub fn getElement(self, i: int) -> ArrayBindingElement { + for (element in ArrayBindingElement(__all_data__)) { + if (element.key_eq(self.getChild(i))) { + return element + } + } + } +} + +/** + * A binding name. + */ +schema BindingName extends Node { +} + +impl BindingName { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BindingName { + for (tmp in Node(db)) { + if (isBindingName(tmp)) { + yield BindingName { + id : tmp.id + } + } + } + } + + pub fn getName(self) -> string { + for (identifier in Identifier(__all_data__)) { + if (self.key_eq(identifier)) { + let (name = identifier.getName()) { + return name + } + } + } + } +} + +/** + * An object binding pattern. + */ +schema ObjectBindingPattern extends BindingPattern { +} + +impl ObjectBindingPattern { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ObjectBindingPattern { + for (tmp in BindingPattern(db)) { + if (isObjectBindingPattern(Node {id: tmp.id})) { + yield ObjectBindingPattern { + id : tmp.id + } + } + } + } + + /** + * @todo: Delete this predicates with typos + */ + pub fn getAElement(self) -> *BindingElement { + for (element in BindingElement(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (element.key_eq(auto_tmp1)) { + yield element + } + } + } + } + + pub fn getAnElement(self) -> *BindingElement { + for (element in BindingElement(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (element.key_eq(auto_tmp1)) { + yield element + } + } + } + } + + pub fn getElement(self, i: int) -> BindingElement { + for (element in BindingElement(__all_data__)) { + if (element.key_eq(self.getChild(i))) { + return element + } + } + } + + pub fn getElementByPropertyName(self, name: string) -> BindingElement { + for (element in self.getAnElement()) { + if (element.getPropertyNameString() = name) { + return element + } + } + } + + pub fn getRestBindingElement(self) -> BindingElement { + for (element in self.getAnElement()) { + if (element.isRest()) { + return element + } + } + } +} + +/** + * An array binding pattern. + */ +schema ArrayBindingPattern extends BindingPattern { +} + +impl ArrayBindingPattern { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ArrayBindingPattern { + for (tmp in BindingPattern(db)) { + if (isArrayBindingPattern(Node {id: tmp.id})) { + yield ArrayBindingPattern { + id : tmp.id + } + } + } + } + + /** + * @todo: Delete this predicate with typos + */ + pub fn getAElement(self) -> *ArrayBindingElement { + for (element in ArrayBindingElement(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (element.key_eq(auto_tmp1)) { + yield element + } + } + } + } + + pub fn getAnElement(self) -> *ArrayBindingElement { + for (element in ArrayBindingElement(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (element.key_eq(auto_tmp1)) { + yield element + } + } + } + } + + pub fn getElement(self, i: int) -> ArrayBindingElement { + for (element in ArrayBindingElement(__all_data__)) { + if (element.key_eq(self.getChild(i))) { + return element + } + } + } +} + +/** + * An enum member. + */ +schema EnumMember extends Node { +} + +impl EnumMember { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EnumMember { + for (tmp in Node(db)) { + if (isEnumMember(tmp)) { + yield EnumMember { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> EnumDeclaration { + for (parent in EnumDeclaration(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + /** + * Gets the name of the current EnumMember. + */ + pub fn getName(self) -> PropertyName { + for (name in PropertyName(__all_data__)) { + if (name.key_eq(self.getChild(0))) { + return name + } + } + } + + /** + * Gets the initializer of the current EnumMember. + */ + pub fn getInitializer(self) -> Expression { + for (initializer in Expression(__all_data__)) { + if (initializer.key_eq(self.getChild(1))) { + return initializer + } + } + } + + /** + * Determine whether this EnumMember has an initializer. + */ + pub fn hasInitializer(self) -> bool { + for (initializer in Expression(__all_data__)) { + if (initializer = self.getInitializer()) { + return true + } + } + } +} + +/** + * Determines whether a node is a type parameter. + */ +pub fn isTypeParameter(node: Node) -> bool { + if (node.getKind() = 162) { + return true + } +} + +/** + * Determines whether a node kind is a parameter. + */ +pub fn isParameter(node: Node) -> bool { + if (node.getKind() = 163) { + return true + } +} + +/** + * Determines whether a node is a variable declaration + */ +pub fn isVariableDeclaration(node: Node) -> bool { + let (kind = node.getKind()) { + if (isVariableDeclarationKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node is a variable declaration list + */ +pub fn isVariableDeclarationList(node: Node) -> bool { + let (kind = node.getKind()) { + if (isVariableDeclarationListKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node is an object binding pattern. + */ +pub fn isObjectBindingPattern(node: Node) -> bool { + if (node.getKind() = 200) { + return true + } +} + +/** + * Determines whether a node is an array binding pattern. + */ +pub fn isArrayBindingPattern(node: Node) -> bool { + if (node.getKind() = 201) { + return true + } +} + +/** + * Determines whether a node is a binding element. + */ +pub fn isBindingElement(node: Node) -> bool { + if (node.getKind() = 202) { + return true + } +} + +/** + * Determines whether a node is an array binding element. + */ +pub fn isArrayBindingElement(node: Node) -> bool { + if (isBindingElement(node)) { + return true + } + if (isOmittedExpression(node)) { + return true + } +} + +/** + * Determines whether a node is a binding pattern. + */ +pub fn isBindingPattern(node: Node) -> bool { + if (isObjectBindingPattern(node)) { + return true + } + if (isArrayBindingPattern(node)) { + return true + } +} + +/** + * Determines whether a node is a binding name. + */ +pub fn isBindingName(node: Node) -> bool { + if (isIdentifier(node)) { + return true + } + if (isBindingPattern(node)) { + return true + } +} + +/** + * Determines whether a node is an enum member. + */ +pub fn isEnumMember(node: Node) -> bool { + if (node.getKind() = 297) { + return true + } +} + +/** + * Determines whether a node kind is a variable declaration list kind + */ +pub fn isVariableDeclarationListKind(kind: int) -> bool { + [ + {254}, // VariableDeclarationList + ] +} + +/** + * Determines whether a node kind is a variable declaration kind + */ +pub fn isVariableDeclarationKind(kind: int) -> bool { + [ + {253}, // VariableDeclaration + ] +} diff --git a/language/javascript/lib/DefUse.gdl b/language/javascript/lib/DefUse.gdl new file mode 100644 index 00000000..ff67131b --- /dev/null +++ b/language/javascript/lib/DefUse.gdl @@ -0,0 +1,706 @@ +/** + * @filename: DefUse + * @brief: Provides classes and predicates for working with def-use relation representation. + */ + +schema VarRef extends BindingName { +} + +impl VarRef { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *VarRef { + for (tmp in BindingName(db)) { + yield VarRef { + id : tmp.id + } + } + } +} + +/** + * An expression can be referenced, including: + * 1. VarRef: `i++` + * 2. AccessExpression: `o.p` / `o['p']` + */ +schema RefExpr extends Node { +} + +impl RefExpr { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RefExpr { + for (tmp in Node(db)) { + for (varRef in VarRef(db)) { + if (tmp.key_eq(varRef)) { + yield RefExpr { + id : tmp.id + } + } + } + if (isAccessExpression(tmp)) { + yield RefExpr { + id : tmp.id + } + } + } + } + + /** + * Get the name of this RefExpr. + */ + pub fn getRefName(self) -> string { + for (varRef in VarRef(__all_data__)) { + if (self.key_eq(varRef)) { + let (name = varRef.getName()) { + return name + } + } + } + for (accessExpression in AccessExpression(__all_data__)) { + if (self.key_eq(accessExpression)) { + let (leftHandSideExpression = accessExpression.getExpression()) { + let (leftHandName = leftHandSideExpression.getText()) { + let (rightHandName = accessExpression.getPropertyName()) { + let (name = leftHandName + "." + rightHandName) { + return name + } + } + } + } + } + } + } + + /** + * Determine whether this RefExpr has symbol. + */ + pub fn hasSymbol(self) -> bool { + for (symbol in Symbol(__all_data__)) { + if (symbol = self.getSymbol()) { + return true + } + } + } +} + +/** + * A RefExpr that is written to. + * 1. x = 1; x is LValue + * 2. o.p = 1; o.p is LValue + */ +schema LValue extends RefExpr { +} + +impl LValue { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LValue { + for (tmp in RefExpr(db)) { + if (isLValue(tmp)) { + yield LValue { + id : tmp.id + } + } + } + } + + /** + * Get the defination node in cfg. + */ + pub fn getDefNode(self) -> ControlFlowNode { + for (def in ControlFlowNode(__all_data__)) { + if (defLValue(def, RefExpr(__all_data__).find(self))) { + return def + } + } + } + + /** + * Get the source of the expression that is written to this LValue. + */ + pub fn getRhs(self) -> Expression { + for (rhs in Expression(__all_data__)) { + if (defnWithRhs(__all_data__, Expression(__all_data__).find(self), rhs)) { + return rhs + } + } + } +} + +/** + * A RefExpr that is read form. + * 1. x = y; y is RValue + * 2. x = o.p; o.p is RValue + */ +schema RValue extends RefExpr { +} + +impl RValue { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RValue { + for (tmp in RefExpr(db)) { + if (isRValue(tmp)) { + yield RValue { + id : tmp.id + } + } + } + } +} + +/** + * A ControlFlowNode that uses a single RefExpr. + */ +schema VarUse extends ControlFlowNode { +} + +impl VarUse { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *VarUse { + for (controlFlowNode in ControlFlowNode(db)) { + if (isRValue(controlFlowNode.to())) { + yield VarUse { + id : controlFlowNode.id + } + } + } + } + + /** + * Determine whether there exists a neareast LValue that defines current use node in same BB. + */ + pub fn existNearestLocalDefinedLValue(self) -> bool { + if (self.nearestLocalDefinedLValue().to_set().len() != 0) { + return true + } + } + + /** + * Gets the LValue nodes that can define this use node. + */ + pub fn getDefinedByLValue(self) -> *LValue { + if (self.existNearestLocalDefinedLValue()) { + yield self.nearestLocalDefinedLValue() + } + if (!self.existNearestLocalDefinedLValue()) { + let (bb = self.getBasicBlock()) { + let (lvalue = defLiveAtBBEntry(bb)) { + if (isSameRefExpr(lvalue.to(), self.to())) { + yield lvalue + } + } + } + } + } + + pub fn getDefinedByLValueRecursive(self) -> *LValue { + yield self.getDefinedByLValue() + for (tmpLValue in self.getDefinedByLValue()) { + for (rhs in Expression(__all_data__)) { + if (defnWithRhs(__all_data__, Expression {id: tmpLValue.id}, rhs)) { + yield VarUse{id: rhs.id}.getDefinedByLValueRecursive() + } + } + } + } + + /** + * Gets VarDef site. + */ + pub fn getADef(self) -> *ControlFlowNode { + for (lvalue in self.getDefinedByLValue()) { + for (def in VarDef(__all_data__)) { + if (lvalue in def.getATarget()) { + yield def.to() + } + } + } + } + + pub fn getADefRecursive(self) -> *ControlFlowNode { + for (lvalue in self.getDefinedByLValueRecursive()) { + for (def in VarDef(__all_data__)) { + if (lvalue in def.getATarget()) { + yield def.to() + } + } + } + } + + fn getLocalDefinedLValueIndexBefore(self) -> *int { + let (bb = self.getBasicBlock()) { + for (index in int::__undetermined_all__()) { + if (self.key_eq(bb.getNode(index))) { + for (i in int::__undetermined_all__()) { + for (lvalue in LValue(__all_data__)) { + if (i < index && defAtBB(bb, lvalue, i)) { + if (isSameRefExpr(self.to(), lvalue.to())) { + yield i + } + } + } + } + } + } + } + } + + /** + * Gets the neareast LValue that defines current use node in same BB. + */ + pub fn nearestLocalDefinedLValue(self) -> LValue { + let (bb = self.getBasicBlock()) { + let (neaerestLValueIndex = self.getLocalDefinedLValueIndexBefore().max()) { + return bb.getNode(neaerestLValueIndex).to() + } + } + } +} + +/** + * A ControlFlowNode that defines some RefExpr nodes, this node is a site. + * Including: + * 1. variable defination: let x = 1; + * 2. assignment expression: x = 1, x+= 1; + * 3. for like statement: for (x in ...); + * 4. parameter: function foo(p); + * 5. function with name: function foo(); + */ +schema VarDef extends ControlFlowNode { +} + +impl VarDef { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *VarDef { + for (tmp in ControlFlowNode(db)) { + if (defn(tmp, __all_data__)) { + yield VarDef { + id : tmp.id + } + } + } + } + + /** + * Gets the target of VarDef, maybe the type of target is LValue? + */ + pub fn getATarget(self) -> *LValue { + for (refExpr in RefExpr(__all_data__), cfn in ControlFlowNode(__all_data__)) { + if (self.key_eq(cfn) && defLValue(cfn, refExpr)) { + yield refExpr.to() + } + } + } + + /** + * Get the data source of this variable definition. + */ + pub fn getSource(self) -> Expression { + for (source in Expression(__all_data__)) { + if (defnWithRhs(self.to(), __all_data__, source)) { + return source + } + } + } + + /** + * Gets the RValue that are defined by this node. + */ + pub fn getAUse(self) -> *VarUse { + for (use1 in VarUse(__all_data__)) { + for (def in use1.getADef()) { + if (def.key_eq(self)) { + yield use1 + } + } + } + } +} + +pub fn defnWithRhs(def: ControlFlowNode, lhs: Expression, rhs: Expression) -> bool { + for (assignmentExpression in AssignmentExpression(__all_data__)) { + if (def.key_eq(assignmentExpression)) { + if (lhs = assignmentExpression.getLeftOperand()) { + if (rhs = assignmentExpression.getRightOperand()) { + return true + } + } + } + } + for (variableDeclaration in VariableDeclaration(__all_data__)) { + if (def.key_eq(variableDeclaration)) { + if (lhs.key_eq(variableDeclaration.getNameNode())) { + if (rhs = variableDeclaration.getInitializer()) { + return true + } + } + } + } + for (parameter in Parameter(__all_data__)) { + if (def.key_eq(parameter)) { + if (lhs.key_eq(parameter.getNameNode())) { + if (rhs = parameter.getInitializer()) { + return true + } + } + } + } + for (enumDeclaration in EnumDeclaration(__all_data__)) { + if (def.key_eq(lhs)) { + if (lhs.key_eq(enumDeclaration.getIdentifier())) { + if (rhs.key_eq(enumDeclaration)) { + return true + } + } + } + } + for (enumMember in EnumMember(__all_data__)) { + if (def.key_eq(enumMember.getName())) { + if (lhs.key_eq(def)) { + if (rhs = enumMember.getInitializer()) { + return true + } + } + } + } + for (functionLikeDeclaration in FunctionLikeDeclaration(__all_data__)) { + if (def.key_eq(functionLikeDeclaration.getNameNode())) { + if (lhs.key_eq(def)) { + if (rhs.key_eq(functionLikeDeclaration)) { + return true + } + } + } + } +} + +pub fn defn(def: ControlFlowNode, lhs: Expression) -> bool { + if (defnWithRhs(def, lhs, __all_data__)) { + return true + } + for (variableDeclaration in VariableDeclaration(__all_data__)) { + if (def.key_eq(variableDeclaration)) { + if (lhs.key_eq(variableDeclaration.getNameNode())) { + if (!variableDeclaration.hasInitializer()) { + return true + } + } + } + } + for (parameter in Parameter(__all_data__)) { + if (def.key_eq(parameter)) { + if (lhs.key_eq(parameter.getNameNode())) { + if (!parameter.hasInitializer()) { + return true + } + } + } + } + for (compoundAssignmentExpression in CompoundAssignmentExpression(__all_data__)) { + if (def.key_eq(compoundAssignmentExpression)) { + if (lhs = compoundAssignmentExpression.getLeftOperand()) { + return true + } + } + } + for (incrementExpression in IncrementExpression(__all_data__)) { + if (def.key_eq(incrementExpression)) { + if (lhs = incrementExpression.getExpression()) { + return true + } + } + } + for (decrementExpression in DecrementExpression(__all_data__)) { + if (def.key_eq(decrementExpression)) { + if (lhs = decrementExpression.getExpression()) { + return true + } + } + } + for (enumMember in EnumMember(__all_data__)) { + if (def.key_eq(enumMember.getName())) { + if (lhs.key_eq(def)) { + if (!enumMember.hasInitializer()) { + return true + } + } + } + } + // if expression exists in forInitializer, it is a left expression. + for (forInitializer in ForInitializer(__all_data__)) { + if (def.key_eq(forInitializer)) { + if (isExpression(forInitializer.to())) { + if (lhs.key_eq(forInitializer)) { + return true + } + } + } + } +} + +/** + * The relation of definitions and lvalues + */ +pub fn defLValue(def: ControlFlowNode, lValue: RefExpr) -> bool { + if (defn(def, Expression(__all_data__).find(lValue))) { + return true + } + // including ObjectBindingPattern and ArrayBindingPattern + for (bindingPattern in BindingPattern(__all_data__)) { + if (defLValue(def, RefExpr(__all_data__).find(bindingPattern))) { + for (bindingElement in BindingElement(__all_data__)) { + for (auto_tmp1 in bindingPattern.getAnElement()) { + if (bindingElement.key_eq(auto_tmp1)) { + if (lValue.key_eq(bindingElement.getNameNode())) { + return true + } + } + } + } + } + } +} + +pub fn isLValue(refExpr: RefExpr) -> bool { + return defLValue(__all_data__, refExpr) +} + +/** + * Determine a PropertyName expr exists in a PropertyAssignment expr. + */ +pub fn isPropertyNameInPropertyAssignment(propertyName: PropertyName) -> bool { + for (propertyAssignment in PropertyAssignment(__all_data__)) { + if (propertyName = propertyAssignment.getPropertyName()) { + return true + } + } +} + +pub fn isPropertyExpressionInAccessExpression(propertyExpression: Expression) -> bool { + for (accessExpression in AccessExpression(__all_data__)) { + if (propertyExpression = accessExpression.getPropertyExpression()) { + return true + } + } +} + +pub fn isRValue(refExpr: RefExpr) -> bool { + for (aRefExpr in RefExpr(__all_data__)) { + if (refExpr = aRefExpr) { + if (!isRefExprIsVariableDeclaration(refExpr) && + !isLValue(refExpr) && + !isRefExprIsPropertyNameInPropertyAssignment(refExpr) && + !isRefExprIsPropertyExpressionInAccessExpression(refExpr)) { + return true + } + } + } + // CompoundAssignmentExpression's left operand are both LValue and RValue + for (compoundAssignmentExpression in CompoundAssignmentExpression(__all_data__)) { + if (refExpr.key_eq(compoundAssignmentExpression.getLeftOperand())) { + return true + } + } + // the expression belongs to IncrementExpression and DecrementExpression is both LValue and RValue + for (incrementExpression in IncrementExpression(__all_data__)) { + if (refExpr.key_eq(incrementExpression.getExpression())) { + return true + } + } + for (decrementExpression in DecrementExpression(__all_data__)) { + if (refExpr.key_eq(decrementExpression.getExpression())) { + return true + } + } + // TODO: namespace identifier +} + +/** + * Gets the lvalue defined in bb, with bb index + */ +pub fn defAtBB(bb: BasicBlock, lvalue: LValue, index: int) -> bool { + for (cfn in ControlFlowNode(__all_data__)) { + if (cfn = bb.getNode(index)) { + if (cfn.key_eq(lvalue)) { + return true + } + } + } +} + +/** + * Gets the VarUse used in bb, with bb index + */ +pub fn useAtBB(bb: BasicBlock, varUse: VarUse, index: int) -> bool { + for (cfn in ControlFlowNode(__all_data__)) { + if (cfn.key_eq(varUse)) { + if (cfn = bb.getNode(index)) { + return true + } + } + } +} + +/** + * Get the corresponding symbol of a RefExpr. + * It also gets the value symbol of a ShorthandPropertyAssignment or the name node (Identifier) of it. + */ +pub fn getSymbol(refExpr: RefExpr) -> Symbol { + let (symbol = refExpr.getSymbol()) { + return symbol + } + for (shorthandPropertyAssignment in ShorthandPropertyAssignment(__all_data__)) { + if (shorthandPropertyAssignment.key_eq(refExpr)) { + let (symbol = shorthandPropertyAssignment.getValueSymbol()) { + return symbol + } + } + if (shorthandPropertyAssignment.getNameNode().key_eq(refExpr)) { + let (symbol = shorthandPropertyAssignment.getValueSymbol()) { + return symbol + } + } + } +} + +/** + * Determine whether 2 RefExpr with same "symbol". + * Actually we want to determine 2 written locations have alias. + * Current we depend on symbol information calculated by tsc, should + * improve this predicated if needed. + */ +pub fn isSameRefExpr(refExpr1: RefExpr, refExpr2: RefExpr) -> bool { + if (refExpr1 = refExpr2) { + return true + } + let (symbol = getSymbol(refExpr1)) { + if (symbol = getSymbol(refExpr2)) { + if (refExpr1 != refExpr2) { + return true + } + } + } + // FIXME: ref name query is very very slow, need to fix it later + // we should find 2 ref exprs located at same compilation unit + let (fld = refExpr1.getEnclosingFunction()) { + if (fld = refExpr2.getEnclosingFunction()) { + if (!refExpr1.hasSymbol()) { + let (symbolName = refExpr1.getRefName()) { + if (symbolName = refExpr2.getRefName()) { + if (refExpr1 != refExpr2) { + return true + } + } + } + } + if (refExpr1.hasSymbol()) { + if (!refExpr2.hasSymbol()) { + let (symbolName = refExpr1.getRefName()) { + if (symbolName = refExpr2.getRefName()) { + if (refExpr1 != refExpr2) { + return true + } + } + } + } + } + } + } +} + +/** + * Gets the killers in BB that kill the given lvalue, with BB index. + */ +pub fn killedByBBWithKiller(bb: BasicBlock, lvalue: LValue, killer: LValue, index: int) -> bool { + if (defAtBB(bb, killer, index)) { + for (lvalueCFN in ControlFlowNode(__all_data__), + killerCFN in ControlFlowNode(__all_data__)) { + if (killer.key_eq(killerCFN)) { + if (lvalue.key_eq(lvalueCFN)) { + if (nodeInSameCFG(killerCFN, lvalueCFN)) { + if (lvalue != killer) { + // lvalue and killer are in same bb, lvalue index should be less than killer index + for (lvalueIndex in int::__undetermined_all__()) { + if (defAtBB(bb, lvalue, lvalueIndex)) { + if (lvalue != killer) { + if (lvalueIndex < index) { + if (isSameRefExpr(RefExpr(__all_data__).find(lvalue), RefExpr(__all_data__).find(killer))) { + return true + } + } + } + } + } + // lvalue and killer are in different bb + if (lvalueCFN.key_eq(lvalue)) { + let (lvalueBB = lvalueCFN.getBasicBlock()) { + if (lvalueBB != bb) { + if (isSameRefExpr(RefExpr(__all_data__).find(lvalue), RefExpr(__all_data__).find(killer))) { + return true + } + } + } + } + } + } + } + } + } + } +} + +/** + * Determine whether the lvalue is killed by bb. + */ +pub fn killedByBB(bb: BasicBlock, lvalue: LValue) -> bool { + if (killedByBBWithKiller(bb, lvalue, __all_data__, __all_data__)) { + return true + } +} + +/** + * Gets the LValue nodes live at the entry of BB. + */ +pub fn defLiveAtBBEntry(bb: BasicBlock) -> LValue { + for (lvalue in LValue(__all_data__)) { + for (predecessor in bb.getABBPredecessor()) { + if (lvalue = defLiveAtBBExit(predecessor)) { + return lvalue + } + } + } +} + +/** + * Gets the LValue nodes live at the exit of BB. + */ +pub fn defLiveAtBBExit(bb: BasicBlock) -> LValue { + for (lvalue in LValue(__all_data__)) { + if (defAtBB(bb, lvalue, __all_data__)) { + if (!killedByBB(bb, lvalue)) { + return lvalue + } + } + if (lvalue = defLiveAtBBEntry(bb)) { + if (!killedByBB(bb, lvalue)) { + return lvalue + } + } + } +} + +fn isRefExprIsVariableDeclaration(refExpr: RefExpr) -> bool { + return isVariableDeclaration(refExpr.to()) +} + +fn isRefExprIsPropertyNameInPropertyAssignment(refExpr: RefExpr) -> bool { + return isPropertyNameInPropertyAssignment(refExpr.to()) +} + +fn isRefExprIsPropertyExpressionInAccessExpression(refExpr: RefExpr) -> bool { + return isPropertyExpressionInAccessExpression(refExpr.to()) +} diff --git a/language/javascript/lib/Expression.gdl b/language/javascript/lib/Expression.gdl new file mode 100644 index 00000000..bc7b59ad --- /dev/null +++ b/language/javascript/lib/Expression.gdl @@ -0,0 +1,4759 @@ +/** + * @filename: Expression + * @brief: Provides classes and predicates for working with JavaScript / TypeScript expressions + */ + +/** + * An expression. + */ +schema Expression extends Node { +} + +impl Expression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Expression { + for (tmp in Node(db)) { + if (isExpression(tmp)) { + yield Expression { + id : tmp.id + } + } + } + } +} + +/** + * An arrow function expression. + */ +schema ArrowFunctionExpression extends Expression { +} + +impl ArrowFunctionExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ArrowFunctionExpression { + for (tmp in Expression(db)) { + if (isArrowFunction(Node {id: tmp.id})) { + yield ArrowFunctionExpression { + id : tmp.id + } + } + } + } +} + +/** + * A binary expression + */ +schema BinaryExpression extends Expression { +} + +impl BinaryExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BinaryExpression { + for (tmp in Expression(db)) { + if (isBinaryExpression(Node {id: tmp.id})) { + yield BinaryExpression { + id : tmp.id + } + } + } + } + + /** + * Get the left operand of this binary expression. + */ + pub fn getLeftOperand(self) -> Expression { + for (leftOperand in Expression(__all_data__)) { + if (leftOperand.key_eq(self.getChild(0))) { + return leftOperand + } + } + } + + /** + * Get the left operand of this binary expression. An alias of `getLeftOperand`. + */ + pub fn getLeft(self) -> Expression { + for (left in Expression(__all_data__)) { + if (left.key_eq(self.getChild(0))) { + return left + } + } + } + + /** + * Get the operator of this binary expression. + */ + pub fn getOperator(self) -> BinaryOperator { + for (binaryOperator in BinaryOperator(__all_data__)) { + if (binaryOperator.key_eq(self.getChild(1))) { + return binaryOperator + } + } + } + + /** + * Get the right operand of this binary expression. + */ + pub fn getRightOperand(self) -> Expression { + for (rightOperand in Expression(__all_data__)) { + if (rightOperand.key_eq(self.getChild(2))) { + return rightOperand + } + } + } + + /** + * Get the right operand of this binary expression. An alias of `getRightOperand` + */ + pub fn getRight(self) -> Expression { + for (right in Expression(__all_data__)) { + if (right.key_eq(self.getChild(2))) { + return right + } + } + } + + pub fn getAnOperand(self) -> *Expression { + for (operand in Expression(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (operand.key_eq(auto_tmp1)) { + yield operand + } + } + } + } +} + +/** + * A exponentiation expression using `**`. + */ +schema ExponentiationExpression extends BinaryExpression { +} + +impl ExponentiationExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExponentiationExpression { + for (tmp in BinaryExpression(db)) { + if (isExponentiationExpression(Node {id: tmp.id})) { + yield ExponentiationExpression { + id : tmp.id + } + } + } + } +} + +/** + * A multiplicative expression using `*`, `/` or `%`. + */ +schema MultiplicativeExpression extends BinaryExpression { +} + +impl MultiplicativeExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MultiplicativeExpression { + for (tmp in BinaryExpression(db)) { + if (isMultiplicativeExpression(Node {id: tmp.id})) { + yield MultiplicativeExpression { + id : tmp.id + } + } + } + } +} + +/** + * A multiplication expression using `*`. + */ +schema MultiplicationExpression extends MultiplicativeExpression { +} + +impl MultiplicationExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MultiplicationExpression { + for (tmp in MultiplicativeExpression(db)) { + if (isMultiplicationExpression(Node {id: tmp.id})) { + yield MultiplicationExpression { + id : tmp.id + } + } + } + } +} + +/** + * A division expression using `/`. + */ +schema DivisionExpression extends MultiplicativeExpression { +} + +impl DivisionExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DivisionExpression { + for (tmp in MultiplicativeExpression(db)) { + if (isDivisionExpression(Node {id: tmp.id})) { + yield DivisionExpression { + id : tmp.id + } + } + } + } +} + +/** + * A remainder expression using `%`. + */ +schema RemainderExpression extends MultiplicativeExpression { +} + +impl RemainderExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RemainderExpression { + for (tmp in MultiplicativeExpression(db)) { + if (isRemainderExpression(Node {id: tmp.id})) { + yield RemainderExpression { + id : tmp.id + } + } + } + } +} + +/** + * An additive expression using `+` or `-`. + */ +schema AdditiveExpression extends BinaryExpression { +} + +impl AdditiveExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AdditiveExpression { + for (tmp in BinaryExpression(db)) { + if (isAdditiveExpression(Node {id: tmp.id})) { + yield AdditiveExpression { + id : tmp.id + } + } + } + } +} + +/** + * An addition expression using `+`. + */ +schema AdditionExpression extends AdditiveExpression { +} + +impl AdditionExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AdditionExpression { + for (tmp in AdditiveExpression(db)) { + if (isAdditionExpression(Node {id: tmp.id})) { + yield AdditionExpression { + id : tmp.id + } + } + } + } +} + +/** + * A subtraction expression using `-`. + */ +schema SubtractionExpression extends AdditiveExpression { +} + +impl SubtractionExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SubtractionExpression { + for (tmp in AdditiveExpression(db)) { + if (isSubtractionExpression(Node {id: tmp.id})) { + yield SubtractionExpression { + id : tmp.id + } + } + } + } +} + +/** + * A shift expression using `<<`, `>>` or `>>>`. + */ +schema ShiftExpression extends BinaryExpression { +} + +impl ShiftExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ShiftExpression { + for (tmp in BinaryExpression(db)) { + if (isShiftExpression(Node {id: tmp.id})) { + yield ShiftExpression { + id : tmp.id + } + } + } + } +} + +/** + * A left-shift expression using `<<`. + */ +schema LeftShiftExpression extends ShiftExpression { +} + +impl LeftShiftExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LeftShiftExpression { + for (tmp in ShiftExpression(db)) { + if (isLeftShiftExpression(Node {id: tmp.id})) { + yield LeftShiftExpression { + id : tmp.id + } + } + } + } +} + +/** + * A signed right-shift expression using `>>`. + */ +schema RightShiftExpression extends ShiftExpression { +} + +impl RightShiftExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RightShiftExpression { + for (tmp in ShiftExpression(db)) { + if (isRightShiftExpression(Node {id: tmp.id})) { + yield RightShiftExpression { + id : tmp.id + } + } + } + } +} + +/** + * A unsigned right-shift expression using `>>>`. + */ +schema UnsignedRightShiftExpression extends ShiftExpression { +} + +impl UnsignedRightShiftExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UnsignedRightShiftExpression { + for (tmp in ShiftExpression(db)) { + if (isUnsignedRightShiftExpression(Node {id: tmp.id})) { + yield UnsignedRightShiftExpression { + id : tmp.id + } + } + } + } +} + +/** + * A relational expression using `<`, `<=`, `>`, `>=`, `instanceof` or `in`. + */ +schema RelationalExpression extends BinaryExpression { +} + +impl RelationalExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RelationalExpression { + for (tmp in BinaryExpression(db)) { + if (isRelationalExpression(Node {id: tmp.id})) { + yield RelationalExpression { + id : tmp.id + } + } + } + } +} + +/** + * A less-than expression using `<`. + */ +schema LessThanExpression extends RelationalExpression { +} + +impl LessThanExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LessThanExpression { + for (tmp in RelationalExpression(db)) { + if (isLessThanExpression(Node {id: tmp.id})) { + yield LessThanExpression { + id : tmp.id + } + } + } + } +} + +/** + * A less-than-or-equal expression using `<=`. + */ +schema LessThanEqualsExpression extends RelationalExpression { +} + +impl LessThanEqualsExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LessThanEqualsExpression { + for (tmp in RelationalExpression(db)) { + if (isLessThanEqualsExpression(Node {id: tmp.id})) { + yield LessThanEqualsExpression { + id : tmp.id + } + } + } + } +} + +/** + * A greater-than expression using `>`. + */ +schema GreaterThanExpression extends RelationalExpression { +} + +impl GreaterThanExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GreaterThanExpression { + for (tmp in RelationalExpression(db)) { + if (isGreaterThanExpression(Node {id: tmp.id})) { + yield GreaterThanExpression { + id : tmp.id + } + } + } + } +} + +/** + * A greater-than-or-equal expression using `>=`. + */ +schema GreaterThanEqualsExpression extends RelationalExpression { +} + +impl GreaterThanEqualsExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GreaterThanEqualsExpression { + for (tmp in RelationalExpression(db)) { + if (isGreaterThanEqualsExpression(Node {id: tmp.id})) { + yield GreaterThanEqualsExpression { + id : tmp.id + } + } + } + } +} + +/** + * An `instanceof` expression. + */ +schema InstanceOfExpression extends RelationalExpression { +} + +impl InstanceOfExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *InstanceOfExpression { + for (tmp in RelationalExpression(db)) { + if (isInstanceOfExpression(Node {id: tmp.id})) { + yield InstanceOfExpression { + id : tmp.id + } + } + } + } +} + +/** + * An `in` expression. + */ +schema InExpression extends RelationalExpression { +} + +impl InExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *InExpression { + for (tmp in RelationalExpression(db)) { + if (isInExpression(Node {id: tmp.id})) { + yield InExpression { + id : tmp.id + } + } + } + } +} + +/** + * An equality test expression using `==`, `!=`, `===` or `!==`. + */ +schema EqualityTestExpression extends BinaryExpression { +} + +impl EqualityTestExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EqualityTestExpression { + for (tmp in BinaryExpression(db)) { + if (isEqualityTestExpression(Node {id: tmp.id})) { + yield EqualityTestExpression { + id : tmp.id + } + } + } + } +} + +/** + * An equality expression using `==`. + */ +schema EqualityExpression extends EqualityTestExpression { +} + +impl EqualityExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EqualityExpression { + for (tmp in EqualityTestExpression(db)) { + if (isEqualityExpression(Node {id: tmp.id})) { + yield EqualityExpression { + id : tmp.id + } + } + } + } +} + +/** + * An inequality expression using `!=`. + */ +schema InequalityExpression extends EqualityTestExpression { +} + +impl InequalityExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *InequalityExpression { + for (tmp in EqualityTestExpression(db)) { + if (isInequalityExpression(Node {id: tmp.id})) { + yield InequalityExpression { + id : tmp.id + } + } + } + } +} + +/** + * A strict equality expression using `===`. + */ +schema StrictEqualityExpression extends EqualityTestExpression { +} + +impl StrictEqualityExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *StrictEqualityExpression { + for (tmp in EqualityTestExpression(db)) { + if (isStrictEqualityExpression(Node {id: tmp.id})) { + yield StrictEqualityExpression { + id : tmp.id + } + } + } + } +} + +/** + * A strict inequality expression using `!==`. + */ +schema StrictInequalityExpression extends EqualityTestExpression { +} + +impl StrictInequalityExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *StrictInequalityExpression { + for (tmp in EqualityTestExpression(db)) { + if (isStrictInequalityExpression(Node {id: tmp.id})) { + yield StrictInequalityExpression { + id : tmp.id + } + } + } + } +} + +/** + * A strict equality test expression using `===` or `!==`. + */ +schema StrictEqualityTestExpression extends EqualityTestExpression { +} + +impl StrictEqualityTestExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *StrictEqualityTestExpression { + for (tmp in EqualityTestExpression(db)) { + if (isStrictEqualityTestExpression(Node {id: tmp.id})) { + yield StrictEqualityTestExpression { + id : tmp.id + } + } + } + } +} + +/** + * A non-strict equality test expression using `==` or `!=`. + */ +schema NonStrictEqualityTestExpression extends EqualityTestExpression { +} + +impl NonStrictEqualityTestExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NonStrictEqualityTestExpression { + for (tmp in EqualityTestExpression(db)) { + if (isNonStrictEqualityTestExpression(Node {id: tmp.id})) { + yield NonStrictEqualityTestExpression { + id : tmp.id + } + } + } + } +} + +/** + * A binary bitwise expression using `&`, `|` or `^`. + */ +schema BinaryBitwiseExpression extends BinaryExpression { +} + +impl BinaryBitwiseExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BinaryBitwiseExpression { + for (tmp in BinaryExpression(db)) { + if (isBinaryBitwiseExpression(Node {id: tmp.id})) { + yield BinaryBitwiseExpression { + id : tmp.id + } + } + } + } +} + +/** + * A bitwise AND expression using `&`. + */ +schema BitwiseAndExpression extends BinaryBitwiseExpression { +} + +impl BitwiseAndExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BitwiseAndExpression { + for (tmp in BinaryBitwiseExpression(db)) { + if (isBitwiseAndExpression(Node {id: tmp.id})) { + yield BitwiseAndExpression { + id : tmp.id + } + } + } + } +} + +/** + * A bitwise OR expression using `|`. + */ +schema BitwiseOrExpression extends BinaryBitwiseExpression { +} + +impl BitwiseOrExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BitwiseOrExpression { + for (tmp in BinaryBitwiseExpression(db)) { + if (isBitwiseOrExpression(Node {id: tmp.id})) { + yield BitwiseOrExpression { + id : tmp.id + } + } + } + } +} + +/** + * A bitwise XOR expression using `^`. + */ +schema BitwiseXorExpression extends BinaryBitwiseExpression { +} + +impl BitwiseXorExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BitwiseXorExpression { + for (tmp in BinaryBitwiseExpression(db)) { + if (isBitwiseXorExpression(Node {id: tmp.id})) { + yield BitwiseXorExpression { + id : tmp.id + } + } + } + } +} + +schema BinaryLogicalExpression extends BinaryExpression { +} + +impl BinaryLogicalExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BinaryLogicalExpression { + for (tmp in BinaryExpression(db)) { + if (isBinaryLogicalExpression(Node {id: tmp.id})) { + yield BinaryLogicalExpression { + id : tmp.id + } + } + } + } +} + +/** + * A logical AND expression using `&&`. + */ +schema LogicalAndExpression extends BinaryLogicalExpression { +} + +impl LogicalAndExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LogicalAndExpression { + for (tmp in BinaryLogicalExpression(db)) { + if (isLogicalAndExpression(Node {id: tmp.id})) { + yield LogicalAndExpression { + id : tmp.id + } + } + } + } +} + +/** + * A logical OR expression using `||`. + */ +schema LogicalOrExpression extends BinaryLogicalExpression { +} + +impl LogicalOrExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LogicalOrExpression { + for (tmp in BinaryLogicalExpression(db)) { + if (isLogicalOrExpression(Node {id: tmp.id})) { + yield LogicalOrExpression { + id : tmp.id + } + } + } + } +} + +/** + * A nullish coalescing expression using `??`. + */ +schema NullishCoalescingExpression extends BinaryLogicalExpression { +} + +impl NullishCoalescingExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NullishCoalescingExpression { + for (tmp in BinaryLogicalExpression(db)) { + if (isNullishCoalescingExpression(Node {id: tmp.id})) { + yield NullishCoalescingExpression { + id : tmp.id + } + } + } + } +} + +/** + * An assignment expression, either compound or simple. + */ +schema AssignmentExpression extends BinaryExpression { +} + +impl AssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AssignmentExpression { + for (tmp in BinaryExpression(db)) { + if (isAssignmentExpression(Node {id: tmp.id})) { + yield AssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A simple assignment expression using `=`. + */ +schema SimpleAssignmentExpression extends AssignmentExpression { +} + +impl SimpleAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SimpleAssignmentExpression { + for (tmp in AssignmentExpression(db)) { + if (isSimpleAssignmentExpression(Node {id: tmp.id})) { + yield SimpleAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A compound assignment expression using + * `+=`, `-=`, `**=`, `*=`, `/=`, `%=`, `&=`, `|=`, `^=`, `<<=`, `>>=`, `>>>=`, + * `&&=`, `||=` or `??=`. + */ +schema CompoundAssignmentExpression extends AssignmentExpression { +} + +impl CompoundAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CompoundAssignmentExpression { + for (tmp in AssignmentExpression(db)) { + if (isCompoundAssignmentExpression(Node {id: tmp.id})) { + yield CompoundAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * An addition assignment expression using `+=`. + */ +schema AdditionAssignmentExpression extends CompoundAssignmentExpression { +} + +impl AdditionAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AdditionAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isAdditionAssignmentExpression(Node {id: tmp.id})) { + yield AdditionAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A subtraction assignment expression using `-=`. + */ +schema SubtractionAssignmentExpression extends CompoundAssignmentExpression { +} + +impl SubtractionAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SubtractionAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isSubtractionAssignmentExpression(Node {id: tmp.id})) { + yield SubtractionAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * An exponentiation assignment expression using `**=`. + */ +schema ExponentiationAssignmentExpression extends CompoundAssignmentExpression { +} + +impl ExponentiationAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExponentiationAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isExponentiationAssignmentExpression(Node {id: tmp.id})) { + yield ExponentiationAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A multiplication assignment expression using `*=`. + */ +schema MultiplicationAssignmentExpression extends CompoundAssignmentExpression { +} + +impl MultiplicationAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MultiplicationAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isMultiplicationAssignmentExpression(Node {id: tmp.id})) { + yield MultiplicationAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A division assignment expression using `/=`. + */ +schema DivisionAssignmentExpression extends CompoundAssignmentExpression { +} + +impl DivisionAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DivisionAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isDivisionAssignmentExpression(Node {id: tmp.id})) { + yield DivisionAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A remainder assignment expression using `%=`. + */ +schema RemainderAssignmentExpression extends CompoundAssignmentExpression { +} + +impl RemainderAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RemainderAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isRemainderAssignmentExpression(Node {id: tmp.id})) { + yield RemainderAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A bitwise AND assignment expression using `&=`. + */ +schema BitwiseAndAssignmentExpression extends CompoundAssignmentExpression { +} + +impl BitwiseAndAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BitwiseAndAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isBitwiseAndAssignmentExpression(Node {id: tmp.id})) { + yield BitwiseAndAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A bitwise OR assignment expression using `|=`. + */ +schema BitwiseOrAssignmentExpression extends CompoundAssignmentExpression { +} + +impl BitwiseOrAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BitwiseOrAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isBitwiseOrAssignmentExpression(Node {id: tmp.id})) { + yield BitwiseOrAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A bitwise XOR assignment expression using `^=`. + */ +schema BitwiseXorAssignmentExpression extends CompoundAssignmentExpression { +} + +impl BitwiseXorAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BitwiseXorAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isBitwiseXorAssignmentExpression(Node {id: tmp.id})) { + yield BitwiseXorAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A left shift assignment expression using `<<=`. + */ +schema LeftShiftAssignmentExpression extends CompoundAssignmentExpression { +} + +impl LeftShiftAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LeftShiftAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isLeftShiftAssignmentExpression(Node {id: tmp.id})) { + yield LeftShiftAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A right shift assignment expression using `>>=`. + */ +schema RightShiftAssignmentExpression extends CompoundAssignmentExpression { +} + +impl RightShiftAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RightShiftAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isRightShiftAssignmentExpression(Node {id: tmp.id})) { + yield RightShiftAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * An unsigned right shift assignment expression using `>>>=`. + */ +schema UnsignedRightShiftAssignmentExpression extends CompoundAssignmentExpression { +} + +impl UnsignedRightShiftAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UnsignedRightShiftAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isUnsignedRightShiftAssignmentExpression(Node {id: tmp.id})) { + yield UnsignedRightShiftAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A logical AND assignment expression using `&&=`. + */ +schema LogicalAndAssignmentExpression extends CompoundAssignmentExpression { +} + +impl LogicalAndAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LogicalAndAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isLogicalAndAssignmentExpression(Node {id: tmp.id})) { + yield LogicalAndAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A logical OR assignment expression using `||=`. + */ +schema LogicalOrAssignmentExpression extends CompoundAssignmentExpression { +} + +impl LogicalOrAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LogicalOrAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isLogicalOrAssignmentExpression(Node {id: tmp.id})) { + yield LogicalOrAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A nullish assignment expression using `??=`. + */ +schema NullishAssignmentExpression extends CompoundAssignmentExpression { +} + +impl NullishAssignmentExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NullishAssignmentExpression { + for (tmp in CompoundAssignmentExpression(db)) { + if (isNullishAssignmentExpression(Node {id: tmp.id})) { + yield NullishAssignmentExpression { + id : tmp.id + } + } + } + } +} + +/** + * A comma expression using `,`. + */ +schema CommaExpression extends BinaryExpression { +} + +impl CommaExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CommaExpression { + for (tmp in BinaryExpression(db)) { + if (isCommaExpression(Node {id: tmp.id})) { + yield CommaExpression { + id : tmp.id + } + } + } + } +} + +/** + * A conditional expression. + */ +schema ConditionalExpression extends Expression { +} + +impl ConditionalExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ConditionalExpression { + for (tmp in Expression(db)) { + if (isConditionalExpression(Node {id: tmp.id})) { + yield ConditionalExpression { + id : tmp.id + } + } + } + } + + pub fn getCondition(self) -> Expression { + for (condition in Expression(__all_data__)) { + if (condition.key_eq(self.getChild(0))) { + return condition + } + } + } + + pub fn getThen(self) -> Expression { + for (thenExpression in Expression(__all_data__)) { + if (thenExpression.key_eq(self.getChild(2))) { + return thenExpression + } + } + } + + pub fn getElse(self) -> Expression { + for (elseExpression in Expression(__all_data__)) { + if (elseExpression.key_eq(self.getChild(4))) { + return elseExpression + } + } + } + + pub fn getABranch(self) -> *Expression { + yield self.getThen() + yield self.getElse() + } +} + +/** + * A yield expression. + */ +schema YieldExpression extends Expression { +} + +impl YieldExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *YieldExpression { + for (tmp in Expression(db)) { + if (isYieldExpression(Node {id: tmp.id})) { + yield YieldExpression { + id : tmp.id + } + } + } + } + + pub fn isDelegating(self) -> bool { + for (asteriskToken in AsteriskToken(__all_data__)) { + if (asteriskToken.key_eq(self.getChild(0))) { + return true + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (self.isDelegating()) { + if (expression.key_eq(self.getChild(1))) { + return expression + } + } + if (!self.isDelegating()) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + } +} + +/** + * A spread element. + */ +schema SpreadElement extends Expression { +} + +impl SpreadElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SpreadElement { + for (tmp in Expression(db)) { + if (isSpreadElement(Node {id: tmp.id})) { + yield SpreadElement { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * An omitted expression. + */ +schema OmittedExpression extends Expression { +} + +impl OmittedExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *OmittedExpression { + for (tmp in Expression(db)) { + if (isOmittedExpression(Node {id: tmp.id})) { + yield OmittedExpression { + id : tmp.id + } + } + } + } +} + +/** + * An `as` expression. + */ +schema AsExpression extends Expression { +} + +impl AsExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AsExpression { + for (tmp in Expression(db)) { + if (isAsExpression(Node {id: tmp.id})) { + yield AsExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + + pub fn getType(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + if (typeNode.key_eq(self.getChild(1))) { + return typeNode + } + } + } +} + +/** + * A synthetic expression. + */ +schema SyntheticExpression extends Expression { +} + +impl SyntheticExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SyntheticExpression { + for (tmp in Expression(db)) { + if (isSyntheticExpression(Node {id: tmp.id})) { + yield SyntheticExpression { + id : tmp.id + } + } + } + } +} + +/** + * A comma list expression. This node will not be + * Will not appear in the AST. + */ +schema CommaListExpression extends Expression { +} + +impl CommaListExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CommaListExpression { + for (tmp in Expression(db)) { + if (isCommaListExpression(Node {id: tmp.id})) { + yield CommaListExpression { + id : tmp.id + } + } + } + } + + /** + * Get a child expression of the CommaListExpression. + */ + pub fn getAExpression(self) -> *Expression { + for (expression in Expression(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (expression.key_eq(auto_tmp1)) { + yield expression + } + } + } + } + + /** + * Gets the `i`th child expression of CommaListExpression. + */ + pub fn getExpression(self, i: int) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(i))) { + return expression + } + } + } + + /** + * Get the count of the child expressions. + */ + pub fn getExpressionCount(self) -> int { + return self.getAExpression().len() + } +} + +/** + * An unary expression. + */ +schema UnaryExpression extends Expression { +} + +impl UnaryExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UnaryExpression { + for (tmp in Expression(db)) { + if (isUnaryExpression(Node {id: tmp.id})) { + yield UnaryExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A type assertion expression. + */ +schema TypeAssertionExpression extends UnaryExpression { +} + +impl TypeAssertionExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeAssertionExpression { + for (tmp in UnaryExpression(db)) { + if (isTypeAssertionExpression(Node {id: tmp.id})) { + yield TypeAssertionExpression { + id : tmp.id + } + } + } + } + + pub fn getType(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + if (typeNode.key_eq(self.getChild(0))) { + return typeNode + } + } + } + + pub fn getExpression(self) -> UnaryExpression { + for (expression in UnaryExpression(__all_data__)) { + if (expression.key_eq(self.getChild(1))) { + return expression + } + } + } +} + +/** + * A `delete` expression. + */ +schema DeleteExpression extends UnaryExpression { +} + +impl DeleteExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DeleteExpression { + for (tmp in UnaryExpression(db)) { + if (isDeleteExpression(Node {id: tmp.id})) { + yield DeleteExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> UnaryExpression { + for (expression in UnaryExpression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A `typeof` expression. + */ +schema TypeOfExpression extends UnaryExpression { +} + +impl TypeOfExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeOfExpression { + for (tmp in UnaryExpression(db)) { + if (isTypeOfExpression(Node {id: tmp.id})) { + yield TypeOfExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> UnaryExpression { + for (expression in UnaryExpression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A `void` expression. + */ +schema VoidExpression extends UnaryExpression { +} + +impl VoidExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *VoidExpression { + for (tmp in UnaryExpression(db)) { + if (isVoidExpression(Node {id: tmp.id})) { + yield VoidExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> UnaryExpression { + for (expression in UnaryExpression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * An `await` expression. + */ +schema AwaitExpression extends UnaryExpression { +} + +impl AwaitExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AwaitExpression { + for (tmp in UnaryExpression(db)) { + if (isAwaitExpression(Node {id: tmp.id})) { + yield AwaitExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> UnaryExpression { + for (expression in UnaryExpression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * An update expression. + */ +schema UpdateExpression extends UnaryExpression { +} + +impl UpdateExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UpdateExpression { + for (tmp in UnaryExpression(db)) { + if (isUpdateExpression(Node {id: tmp.id})) { + yield UpdateExpression { + id : tmp.id + } + } + } + } +} + +/** + * A left-hand-side expression. + */ +schema LeftHandSideExpression extends UpdateExpression { +} + +impl LeftHandSideExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LeftHandSideExpression { + for (tmp in UpdateExpression(db)) { + if (isLeftHandSideExpression(Node {id: tmp.id})) { + yield LeftHandSideExpression { + id : tmp.id + } + } + } + } +} + +/** + * A prefix unary expression. + */ +schema PrefixUnaryExpression extends UpdateExpression { +} + +impl PrefixUnaryExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PrefixUnaryExpression { + for (tmp in UpdateExpression(db)) { + if (isPrefixUnaryExpression(Node {id: tmp.id})) { + yield PrefixUnaryExpression { + id : tmp.id + } + } + } + } + + pub fn getOperator(self) -> PrefixUnaryOperator { + for (prefixUnaryOperator in PrefixUnaryOperator(__all_data__)) { + if (prefixUnaryOperator.key_eq(self.getChild(0))) { + return prefixUnaryOperator + } + } + } + + pub fn getOperand(self) -> UnaryExpression { + for (operand in UnaryExpression(__all_data__)) { + if (operand.key_eq(self.getChild(1))) { + return operand + } + } + } +} + +/** + * A prefix increment expression using `++`. + */ +schema PrefixIncrementExpression extends PrefixUnaryExpression { +} + +impl PrefixIncrementExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PrefixIncrementExpression { + for (tmp in PrefixUnaryExpression(db)) { + if (isPrefixIncrementExpression(Node {id: tmp.id})) { + yield PrefixIncrementExpression { + id : tmp.id + } + } + } + } +} + +/** + * A prefix decrement expression using `--`. + */ +schema PrefixDecrementExpression extends PrefixUnaryExpression { +} + +impl PrefixDecrementExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PrefixDecrementExpression { + for (tmp in PrefixUnaryExpression(db)) { + if (isPrefixDecrementExpression(Node {id: tmp.id})) { + yield PrefixDecrementExpression { + id : tmp.id + } + } + } + } +} + +/** + * An unary plus expression using `+`. + */ +schema UnaryPlusExpression extends PrefixUnaryExpression { +} + +impl UnaryPlusExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UnaryPlusExpression { + for (tmp in PrefixUnaryExpression(db)) { + if (isUnaryPlusExpression(Node {id: tmp.id})) { + yield UnaryPlusExpression { + id : tmp.id + } + } + } + } +} + +/** + * An unary minus (also known as negation) expression using `-`. + */ +schema UnaryMinusExpression extends PrefixUnaryExpression { +} + +impl UnaryMinusExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UnaryMinusExpression { + for (tmp in PrefixUnaryExpression(db)) { + if (isUnaryMinusExpression(Node {id: tmp.id})) { + yield UnaryMinusExpression { + id : tmp.id + } + } + } + } +} + +/** + * A bitwise NOT expression using `~`. + */ +schema BitwiseNotExpression extends PrefixUnaryExpression { +} + +impl BitwiseNotExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BitwiseNotExpression { + for (tmp in PrefixUnaryExpression(db)) { + if (isBitwiseNotExpression(Node {id: tmp.id})) { + yield BitwiseNotExpression { + id : tmp.id + } + } + } + } +} + +/** + * A logical NOT expression using `!`. + */ +schema LogicalNotExpression extends PrefixUnaryExpression { +} + +impl LogicalNotExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LogicalNotExpression { + for (tmp in PrefixUnaryExpression(db)) { + if (isLogicalNotExpression(Node {id: tmp.id})) { + yield LogicalNotExpression { + id : tmp.id + } + } + } + } +} + +/** + * A postfix unary expression. + */ +schema PostfixUnaryExpression extends UpdateExpression { +} + +impl PostfixUnaryExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PostfixUnaryExpression { + for (tmp in UpdateExpression(db)) { + if (isPostfixUnaryExpression(Node {id: tmp.id})) { + yield PostfixUnaryExpression { + id : tmp.id + } + } + } + } + + pub fn getOperand(self) -> LeftHandSideExpression { + for (operand in LeftHandSideExpression(__all_data__)) { + if (operand.key_eq(self.getChild(0))) { + return operand + } + } + } + + pub fn getOperator(self) -> PostfixUnaryOperator { + for (postfixUnaryOperator in PostfixUnaryOperator(__all_data__)) { + if (postfixUnaryOperator.key_eq(self.getChild(1))) { + return postfixUnaryOperator + } + } + } +} + +/** + * A postfix increment expression using `++`. + */ +schema PostfixIncrementExpression extends PostfixUnaryExpression { +} + +impl PostfixIncrementExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PostfixIncrementExpression { + for (tmp in PostfixUnaryExpression(db)) { + if (isPostfixIncrementExpression(Node {id: tmp.id})) { + yield PostfixIncrementExpression { + id : tmp.id + } + } + } + } +} + +/** + * A postfix decrement expression using `--`. + */ +schema PostfixDecrementExpression extends PostfixUnaryExpression { +} + +impl PostfixDecrementExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PostfixDecrementExpression { + for (tmp in PostfixUnaryExpression(db)) { + if (isPostfixDecrementExpression(Node {id: tmp.id})) { + yield PostfixDecrementExpression { + id : tmp.id + } + } + } + } +} + +/** + * An increment expression using `++`. + */ +schema IncrementExpression extends UpdateExpression { +} + +impl IncrementExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IncrementExpression { + for (tmp in UpdateExpression(db)) { + if (isIncrementExpression(Node {id: tmp.id})) { + yield IncrementExpression { + id : tmp.id + } + } + } + } +} + +/** + * A decrement expression using `--`. + */ +schema DecrementExpression extends UpdateExpression { +} + +impl DecrementExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DecrementExpression { + for (tmp in UpdateExpression(db)) { + if (isDecrementExpression(Node {id: tmp.id})) { + yield DecrementExpression { + id : tmp.id + } + } + } + } +} + +/** + * A call expression. + */ +schema CallExpression extends LeftHandSideExpression { +} + +impl CallExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CallExpression { + for (tmp in LeftHandSideExpression(db)) { + if (isCallExpression(Node {id: tmp.id})) { + yield CallExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> LeftHandSideExpression { + for (expression in LeftHandSideExpression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + + /** + * Gets the `?.` token of this call expression. + */ + pub fn getQuestionDotToken(self) -> QuestionDotToken { + for (questionDotToken in QuestionDotToken(__all_data__)) { + if (questionDotToken.key_eq(self.getChild(1))) { + return questionDotToken + } + } + } + + /** + * Determines whether this call expression is optional chaining, which means it has a `?.` token. + */ + pub fn isOptionalChaining(self) -> bool { + for (questionDotToken in QuestionDotToken(__all_data__)) { + if (questionDotToken = self.getQuestionDotToken()) { + return true + } + } + } + + /** + * Gets a type argument of this call expression. + */ + pub fn getATypeArgument(self) -> *TypeNode { + for (typeArgument in TypeNode(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeArgument.key_eq(auto_tmp1)) { + yield typeArgument + } + } + } + } + + /** + * Gets the `i`th type argument of this call expression. + */ + pub fn getTypeArgument(self, i: int) -> TypeNode { + for (childIndex in int::__undetermined_all__()) { + for (typeArgument in TypeNode(__all_data__)) { + if (typeArgument.key_eq(self.getChild(childIndex))) { + if (i = childIndex - 1) { + return typeArgument + } + } + } + } + } + + /** + * Gets an argument of this call expression. + */ + pub fn getAnArgument(self) -> *Expression { + let (typeArgumentCount = self.getTypeArgumentCount()) { + for (child in Node(__all_data__)) { + if (child in self.getAChild()) { + let (index = child.getIndex()) { + // Exclude the expression, the `?.` token and the type arguments of this new expression + if (self.isOptionalChaining()) { + if (index > typeArgumentCount + 1) { + yield child.to() + } + } + if (!self.isOptionalChaining()) { + if (index > typeArgumentCount) { + yield child.to() + } + } + } + } + } + } + } + + /** + * Gets the `i`th argument of this call expression. + * index from 0 + */ + pub fn getArgument(self, i: int) -> Expression { + for (childIndex in int::__undetermined_all__()) { + for (argument in Expression(__all_data__)) { + if (argument.key_eq(self.getChild(childIndex))) { + if (childIndex != 0) { + let (typeArgumentCount = self.getTypeArgumentCount()) { + if (i >= 0) { + // Subtract the number of nodes before the arguments from the index. + if (self.isOptionalChaining()) { + if (i = childIndex - typeArgumentCount - 2) { + return argument + } + } + if (!self.isOptionalChaining()) { + if (i = childIndex - typeArgumentCount - 1) { + return argument + } + } + } + } + } + } + } + } + } + + /** + * Gets the callee of this call expression. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callSite in CallSite(__all_data__)) { + if (self.key_eq(callSite)) { + let (callee = callSite.getCallee()) { + return callee + } + } + } + } + + /** + * Determine whether this CallExpression has a callee. + */ + pub fn hasCallee(self) -> bool { + for (callee in FunctionLikeDeclaration(__all_data__)) { + if (callee = self.getCallee()) { + return true + } + } + } + + /** + * Gets the count of the arguments. + */ + pub fn getArgumentCount(self) -> int { + return self.getAnArgument().len() + } + + /** + * Gets the count of the type arguments. + */ + pub fn getTypeArgumentCount(self) -> int { + return self.getATypeArgument().len() + } +} + +/** + * A non-null expression using `!`. + */ +schema NonNullExpression extends LeftHandSideExpression { +} + +impl NonNullExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NonNullExpression { + for (tmp in LeftHandSideExpression(db)) { + if (isNonNullExpression(Node {id: tmp.id})) { + yield NonNullExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A partially emitted expression. + * Will not appear in the AST. + */ +schema PartiallyEmittedExpression extends LeftHandSideExpression { +} + +impl PartiallyEmittedExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PartiallyEmittedExpression { + for (tmp in LeftHandSideExpression(db)) { + if (isPartiallyEmittedExpression(Node {id: tmp.id})) { + yield PartiallyEmittedExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A synthetic reference expression. + * Will not appear in the AST. + */ +schema SyntheticReferenceExpression extends LeftHandSideExpression { +} + +impl SyntheticReferenceExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SyntheticReferenceExpression { + for (tmp in LeftHandSideExpression(db)) { + if (isSyntheticReferenceExpression(Node {id: tmp.id})) { + yield SyntheticReferenceExpression { + id : tmp.id + } + } + } + } +} + +/** + * A member expression. + */ +schema MemberExpression extends LeftHandSideExpression { +} + +impl MemberExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MemberExpression { + for (tmp in LeftHandSideExpression(db)) { + if (isMemberExpression(Node {id: tmp.id})) { + yield MemberExpression { + id : tmp.id + } + } + } + } +} + +/** + * A member name. + */ +schema MemberName extends Node { +} + +impl MemberName { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MemberName { + for (tmp in Node(db)) { + if (isMemberName(tmp)) { + yield MemberName { + id : tmp.id + } + } + } + } + + /** + * Gets the name of this MemberName. + */ + pub fn getName(self) -> string { + return self.getText() + } +} + +/** + * An access expression. + * + * Examples: + * ``` + * o.p + * o['p'] + * ``` + */ +schema AccessExpression extends MemberExpression { +} + +impl AccessExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AccessExpression { + for (tmp in MemberExpression(db)) { + if (isAccessExpression(Node {id: tmp.id})) { + yield AccessExpression { + id : tmp.id + } + } + } + } + + /** + * Gets the expression on which the property is accessed. + */ + pub fn getExpression(self) -> LeftHandSideExpression { + for (expression in LeftHandSideExpression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + + /** + * Determines whether this access expression is optional chaining. + */ + pub fn isOptionalChaining(self) -> bool { + for (questionDotToken in QuestionDotToken(__all_data__)) { + if (questionDotToken.key_eq(self.getChild(1))) { + return true + } + } + } + + /** + * Gets the property expression of this AccessExpression. + */ + pub fn getPropertyExpression(self) -> Expression { + for (propertyExpression in Expression(__all_data__)) { + if (self.isOptionalChaining()) { + if (propertyExpression.key_eq(self.getChild(2))) { + return propertyExpression + } + } + if (!self.isOptionalChaining()) { + if (propertyExpression.key_eq(self.getChild(1))) { + return propertyExpression + } + } + } + } + + pub fn getPropertyName(self) -> string { + // For PropertyAccessExpression + for (property in MemberName(__all_data__)) { + if (property.key_eq(self.getPropertyExpression())) { + let (propertyName = property.getName()) { + return propertyName + } + } + } + // For ElementAccessExpression + for (literalExpression in LiteralExpression(__all_data__)) { + if (literalExpression.key_eq(self.getPropertyExpression())) { + let (propertyName = literalExpression.getValue()) { + return propertyName + } + } + } + } + + /** + * Gets the callee (GetAccessorDeclaration or SetAccessorDeclaration) of this access expression. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callSite in CallSite(__all_data__)) { + if (self.key_eq(callSite)) { + let (callee = callSite.getCallee()) { + return callee + } + } + } + } +} + +/** + * A property access expression. + * + * Example: + * ``` + * o.p + * ``` + */ +schema PropertyAccessExpression extends AccessExpression { +} + +impl PropertyAccessExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PropertyAccessExpression { + for (tmp in AccessExpression(db)) { + if (isPropertyAccessExpression(Node {id: tmp.id})) { + yield PropertyAccessExpression { + id : tmp.id + } + } + } + } + + pub fn getProperty(self) -> MemberName { + for (memberName in MemberName(__all_data__), + accessExpression in AccessExpression(__all_data__)) { + if (accessExpression.key_eq(self)) { + if (memberName.key_eq(accessExpression.getPropertyExpression())) { + return memberName + } + } + } + } + + pub fn getPropertyName(self) -> string { + return self.getProperty().getName() + } +} + +/** + * An element access expression. + * + * Example: + * ``` + * o['p'] + * ``` + */ +schema ElementAccessExpression extends AccessExpression { +} + +impl ElementAccessExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ElementAccessExpression { + for (tmp in AccessExpression(db)) { + if (isElementAccessExpression(Node {id: tmp.id})) { + yield ElementAccessExpression { + id : tmp.id + } + } + } + } + + pub fn getArgumentExpression(self) -> Expression { + for (accessExpression in AccessExpression(__all_data__)) { + if (accessExpression.key_eq(self)) { + let (argumentExpression = accessExpression.getPropertyExpression()) { + return argumentExpression + } + } + } + } + + pub fn getPropertyName(self) -> string { + for (literalExpression in LiteralExpression(__all_data__)) { + if (literalExpression.key_eq(self.getArgumentExpression())) { + let (propertyName = literalExpression.getValue()) { + return propertyName + } + } + } + } +} + +/** + * A tagged template expression. + */ +schema TaggedTemplateExpression extends MemberExpression { +} + +impl TaggedTemplateExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TaggedTemplateExpression { + for (tmp in MemberExpression(db)) { + if (isTaggedTemplateExpression(Node {id: tmp.id})) { + yield TaggedTemplateExpression { + id : tmp.id + } + } + } + } + + pub fn getTag(self) -> LeftHandSideExpression { + for (tag in LeftHandSideExpression(__all_data__)) { + if (tag.key_eq(self.getChild(0))) { + return tag + } + } + } + + /** + * Gets the callee of this tagged template expression. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callSite in CallSite(__all_data__)) { + if (self.key_eq(callSite)) { + let (callee = callSite.getCallee()) { + return callee + } + } + } + } +} + +/** + * A primary expression. + */ +schema PrimaryExpression extends MemberExpression { +} + +impl PrimaryExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PrimaryExpression { + for (tmp in MemberExpression(db)) { + if (isPrimaryExpression(Node {id: tmp.id})) { + yield PrimaryExpression { + id : tmp.id + } + } + } + } +} + +/** + * An identifier. + */ +schema Identifier extends PrimaryExpression { +} + +impl Identifier { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Identifier { + for (tmp in PrimaryExpression(db)) { + if (isIdentifier(Node {id: tmp.id})) { + yield Identifier { + id : tmp.id + } + } + } + } + + pub fn getName(self) -> string { + return self.getText() + } +} + +/** + * A private identifier. + */ +schema PrivateIdentifier extends PrimaryExpression { +} + +impl PrivateIdentifier { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PrivateIdentifier { + for (tmp in PrimaryExpression(db)) { + if (isPrivateIdentifier(Node {id: tmp.id})) { + yield PrivateIdentifier { + id : tmp.id + } + } + } + } + + pub fn getName(self) -> string { + return self.getText() + } +} + +/** + * A this expression. + */ +schema ThisExpression extends PrimaryExpression { +} + +impl ThisExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ThisExpression { + for (tmp in PrimaryExpression(db)) { + if (isThisExpression(Node {id: tmp.id})) { + yield ThisExpression { + id : tmp.id + } + } + } + } +} + +/** + * A super expression. + */ +schema SuperExpression extends PrimaryExpression { +} + +impl SuperExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SuperExpression { + for (tmp in PrimaryExpression(db)) { + if (isSuperExpression(Node {id: tmp.id})) { + yield SuperExpression { + id : tmp.id + } + } + } + } +} + +/** + * An import expression. + */ +schema ImportExpression extends PrimaryExpression { +} + +impl ImportExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ImportExpression { + for (tmp in PrimaryExpression(db)) { + if (isImportExpression(Node {id: tmp.id})) { + yield ImportExpression { + id : tmp.id + } + } + } + } +} + +/** + * An array literal expression. + */ +schema ArrayLiteralExpression extends PrimaryExpression { +} + +impl ArrayLiteralExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ArrayLiteralExpression { + for (tmp in PrimaryExpression(db)) { + if (isArrayLiteralExpression(Node {id: tmp.id})) { + yield ArrayLiteralExpression { + id : tmp.id + } + } + } + } + + pub fn getAElement(self) -> *Expression { + for (element in Expression(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (element.key_eq(auto_tmp1)) { + yield element + } + } + } + } + + pub fn getElement(self, i: int) -> Expression { + for (element in Expression(__all_data__)) { + if (element.key_eq(self.getChild(i))) { + return element + } + } + } +} + +/** + * A new expression. + */ +schema NewExpression extends PrimaryExpression { +} + +impl NewExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NewExpression { + for (tmp in PrimaryExpression(db)) { + if (isNewExpression(Node {id: tmp.id})) { + yield NewExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> LeftHandSideExpression { + for (expression in LeftHandSideExpression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + + /** + * Gets a type argument of this new expression. + */ + pub fn getATypeArgument(self) -> *TypeNode { + for (typeArgument in TypeNode(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeArgument.key_eq(auto_tmp1)) { + yield typeArgument + } + } + } + } + + /** + * Gets the `i`th type argument of this new expression. + */ + pub fn getTypeArgument(self, i: int) -> TypeNode { + for (childIndex in int::__undetermined_all__()) { + for (typeArgument in TypeNode(__all_data__)) { + if (typeArgument.key_eq(self.getChild(childIndex))) { + if (i = childIndex - 1) { + return typeArgument + } + } + } + } + } + + /** + * Gets an argument of this new expression. + */ + pub fn getAnArgument(self) -> *Expression { + for (child in Node(__all_data__)) { + if (child in self.getAChild()) { + let (index = child.getIndex()) { + let (typeArgumentCount = self.getTypeArgumentCount()) { + // Exclude the expression and the type arguments of this new expression + if (index > typeArgumentCount) { + yield child.to() + } + } + } + } + } + } + + /** + * Gets the `i`th argument of this new expression. + * index starts from 0 + */ + pub fn getArgument(self, i: int) -> Expression { + for (childIndex in int::__undetermined_all__()) { + for (argument in Expression(__all_data__)) { + if (argument.key_eq(self.getChild(childIndex))) { + if (childIndex != 0) { + let (typeArgumentCount = self.getTypeArgumentCount()) { + // Subtract the number of nodes before the arguments from the index. + if (i = childIndex - typeArgumentCount - 1) { + return argument + } + } + } + } + } + } + } + + /** + * Gets the callee of this new expression. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callSite in CallSite(__all_data__)) { + if (self.key_eq(callSite)) { + let (callee = callSite.getCallee()) { + return callee + } + } + } + } + + /** + * Gets the count of the type arguments. + */ + pub fn getTypeArgumentCount(self) -> int { + return self.getATypeArgument().len() + } + + /** + * Gets the count of the arguments. + */ + pub fn getArgumentCount(self) -> int { + return self.getAnArgument().len() + } +} + +/** + * A parenthesized expression. + */ +schema ParenthesizedExpression extends PrimaryExpression { +} + +impl ParenthesizedExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ParenthesizedExpression { + for (tmp in PrimaryExpression(db)) { + if (isParenthesizedExpression(Node {id: tmp.id})) { + yield ParenthesizedExpression { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A function expression. + */ +schema FunctionExpression extends PrimaryExpression { +} + +impl FunctionExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FunctionExpression { + for (tmp in PrimaryExpression(db)) { + if (isFunctionExpression(Node {id: tmp.id})) { + yield FunctionExpression { + id : tmp.id + } + } + } + } + + pub fn getName(self) -> Identifier { + for (name in Identifier(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (name.key_eq(auto_tmp1)) { + return name + } + } + } + } + + pub fn getAParameter(self) -> *Parameter { + for (parameter in Parameter(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (parameter.key_eq(auto_tmp1)) { + yield parameter + } + } + } + } + + pub fn getBody(self) -> BlockStatement { + for (body in BlockStatement(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (body.key_eq(auto_tmp1)) { + return body + } + } + } + } +} + +/** + * A template expression. + */ +schema TemplateExpression extends PrimaryExpression { +} + +impl TemplateExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateExpression { + for (tmp in PrimaryExpression(db)) { + if (isTemplateExpression(Node {id: tmp.id})) { + yield TemplateExpression { + id : tmp.id + } + } + } + } + + pub fn getHead(self) -> TemplateHead { + for (head in TemplateHead(__all_data__)) { + if (head.key_eq(self.getChild(0))) { + return head + } + } + } + + pub fn getATemplateSpan(self) -> *TemplateSpan { + for (templateSpan in TemplateSpan(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (templateSpan.key_eq(auto_tmp1)) { + yield templateSpan + } + } + } + } + + pub fn getTemplateSpan(self, i: int) -> TemplateSpan { + for (childIndex in int::__undetermined_all__()) { + for (templateSpan in TemplateSpan(__all_data__)) { + if (templateSpan.key_eq(self.getChild(childIndex))) { + if (i = childIndex - 1) { + return templateSpan + } + } + } + } + } +} + +/** + * A class expression. + */ +schema ClassExpression extends PrimaryExpression { +} + +impl ClassExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ClassExpression { + for (tmp in PrimaryExpression(db)) { + if (isClassExpression(Node {id: tmp.id})) { + yield ClassExpression { + id : tmp.id + } + } + } + } +} + +/** + * A meta property. + */ +schema MetaProperty extends PrimaryExpression { +} + +impl MetaProperty { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MetaProperty { + for (tmp in PrimaryExpression(db)) { + if (isMetaProperty(Node {id: tmp.id})) { + yield MetaProperty { + id : tmp.id + } + } + } + } + + pub fn getKeywordToken(self) -> KeywordToken { + for (keywordToken in KeywordToken(__all_data__)) { + if (keywordToken.key_eq(self.getChild(0))) { + return keywordToken + } + } + } + + pub fn getName(self) -> Identifier { + for (name in Identifier(__all_data__)) { + if (name.key_eq(self.getChild(1))) { + return name + } + } + } +} + +/** + * A literal expression. + */ +schema LiteralExpression extends PrimaryExpression { +} + +impl LiteralExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LiteralExpression { + for (tmp in PrimaryExpression(db)) { + if (isLiteralExpression(Node {id: tmp.id})) { + yield LiteralExpression { + id : tmp.id + } + } + } + } + + /** + * Gets the value of this literal, as a string. + */ + pub fn getValue(self) -> string { + for (literalDO in LiteralDO(__all_data__)) { + if (literalDO.key_eq(self)) { + let (value = literalDO.getValue()) { + return value + } + } + } + } +} + +/** + * A null literal. + */ +schema NullLiteral extends PrimaryExpression { +} + +impl NullLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NullLiteral { + for (tmp in PrimaryExpression(db)) { + if (isNullLiteral(Node {id: tmp.id})) { + yield NullLiteral { + id : tmp.id + } + } + } + } +} + +/** + * A true literal. + */ +schema TrueLiteral extends PrimaryExpression { +} + +impl TrueLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TrueLiteral { + for (tmp in PrimaryExpression(db)) { + if (isTrueKeyword(Node {id: tmp.id})) { + yield TrueLiteral { + id : tmp.id + } + } + } + } +} + +/** + * A false literal. + */ +schema FalseLiteral extends PrimaryExpression { +} + +impl FalseLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FalseLiteral { + for (tmp in PrimaryExpression(db)) { + if (isFalseKeyword(Node {id: tmp.id})) { + yield FalseLiteral { + id : tmp.id + } + } + } + } +} + +/** + * A boolean literal. + */ +schema BooleanLiteral extends PrimaryExpression { +} + +impl BooleanLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BooleanLiteral { + for (tmp in PrimaryExpression(db)) { + if (isBooleanLiteral(Node {id: tmp.id})) { + yield BooleanLiteral { + id : tmp.id + } + } + } + } +} + +/** + * A numeric literal. + */ +schema NumericLiteral extends LiteralExpression { +} + +impl NumericLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NumericLiteral { + for (tmp in LiteralExpression(db)) { + if (isNumericLiteral(Node {id: tmp.id})) { + yield NumericLiteral { + id : tmp.id + } + } + } + } +} + +/** + * A big-int literal. + */ +schema BigIntLiteral extends LiteralExpression { +} + +impl BigIntLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BigIntLiteral { + for (tmp in LiteralExpression(db)) { + if (isBigIntLiteral(Node {id: tmp.id})) { + yield BigIntLiteral { + id : tmp.id + } + } + } + } +} + +/** + * A string literal. + */ +schema StringLiteral extends LiteralExpression { +} + +impl StringLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *StringLiteral { + for (tmp in LiteralExpression(db)) { + if (isStringLiteral(Node {id: tmp.id})) { + yield StringLiteral { + id : tmp.id + } + } + } + } + + pub fn getString(self) -> string { + return self.getValue() + } +} + +/** + * A regular expression literal. + */ +schema RegularExpressionLiteral extends LiteralExpression { +} + +impl RegularExpressionLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RegularExpressionLiteral { + for (tmp in LiteralExpression(db)) { + if (isRegularExpressionLiteral(Node {id: tmp.id})) { + yield RegularExpressionLiteral { + id : tmp.id + } + } + } + } +} + +/** + * A no-substitution template literal. + */ +schema NoSubstitutionTemplateLiteral extends LiteralExpression { +} + +impl NoSubstitutionTemplateLiteral { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NoSubstitutionTemplateLiteral { + for (tmp in LiteralExpression(db)) { + if (isNoSubstitutionTemplateLiteral(Node {id: tmp.id})) { + yield NoSubstitutionTemplateLiteral { + id : tmp.id + } + } + } + } +} + +/** + * A decorator applied to a class, method, accessor, property or parameter. + */ +schema Decorator extends Node { +} + +impl Decorator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Decorator { + for (tmp in Node(db)) { + if (isDecorator(tmp)) { + yield Decorator { + id : tmp.id + } + } + } + } + + /** + * Gets the expression. + */ + pub fn getExpression(self) -> LeftHandSideExpression { + for (expression in LeftHandSideExpression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + + /** + * Gets the callee of this decorator. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callSite in CallSite(__all_data__)) { + if (self.key_eq(callSite)) { + let (callee = callSite.getCallee()) { + return callee + } + } + } + } +} + +/** + * A call-like expression. + */ +schema CallLikeExpression extends Expression { +} + +impl CallLikeExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CallLikeExpression { + for (tmp in Expression(db)) { + if (isCallLikeExpression(Node {id: tmp.id})) { + yield CallLikeExpression { + id : tmp.id + } + } + } + } + + /** + * Gets the callee of this call-like expression. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callSite in CallSite(__all_data__)) { + if (self.key_eq(callSite)) { + let (callee = callSite.getCallee()) { + return callee + } + } + } + } + + /** + * Determine whether this CallLikeExpression has a callee. + */ + pub fn hasCallee(self) -> bool { + for (callee in FunctionLikeDeclaration(__all_data__)) { + if (callee = self.getCallee()) { + return true + } + } + } +} + +/** + * A CallLikeExpression or AccessExpression that may invoke a FunctionLikeDeclaration. + */ +schema MayInvokeExpression extends Expression { +} + +impl MayInvokeExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MayInvokeExpression { + for (tmp in Expression(db)) { + if (isMayInvokeExpression(Node {id: tmp.id})) { + yield MayInvokeExpression { + id : tmp.id + } + } + } + } + + /** + * Gets the callee of this MayInvokeExpression. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callSite in CallSite(__all_data__)) { + if (self.key_eq(callSite)) { + let (callee = callSite.getCallee()) { + return callee + } + } + } + } + + /** + * Determine whether this MayInvokeExpression has a callee. + */ + pub fn hasCallee(self) -> bool { + for (callee in FunctionLikeDeclaration(__all_data__)) { + if (callee = self.getCallee()) { + return true + } + } + } +} + +/** + * Determines whether a node is an array literal expression. + */ +pub fn isArrayLiteralExpression(node: Node) -> bool { + if (node.getKind() = 203) { + return true + } +} + +/** + * Determines whether a node is an object literal expression. + */ +pub fn isObjectLiteralExpression(node: Node) -> bool { + if (node.getKind() = 204) { + return true + } +} + +/** + * Determines whether a node is a property access expression. + */ +pub fn isPropertyAccessExpression(node: Node) -> bool { + if (node.getKind() = 205) { + return true + } +} + +/** + * Determines whether a node is an element access expression. + */ +pub fn isElementAccessExpression(node: Node) -> bool { + if (node.getKind() = 206) { + return true + } +} + +/** + * Determines whether a node is a call expression. + */ +pub fn isCallExpression(node: Node) -> bool { + if (node.getKind() = 207) { + return true + } +} + +/** + * Determines whether a node is a new expression. + */ +pub fn isNewExpression(node: Node) -> bool { + if (node.getKind() = 208) { + return true + } +} + +/** + * Determines whether a node is a tagged template expression. + */ +pub fn isTaggedTemplateExpression(node: Node) -> bool { + if (node.getKind() = 209) { + return true + } +} + +/** + * Determines whether a node is a type assertion expression. + */ +pub fn isTypeAssertionExpression(node: Node) -> bool { + if (node.getKind() = 210) { + return true + } +} + +/** + * Determines whether a node is a parenthesized expression. + */ +pub fn isParenthesizedExpression(node: Node) -> bool { + if (node.getKind() = 211) { + return true + } +} + +/** + * Determines whether a node is a function expression + */ +pub fn isFunctionExpression(node: Node) -> bool { + if (node.getKind() = 212) { + return true + } +} + +/** + * Determines whether a node is an arrow function + */ +pub fn isArrowFunction(node: Node) -> bool { + if (node.getKind() = 213) { + return true + } +} + +/** + * Determines whether a node is a `delete` expression. + */ +pub fn isDeleteExpression(node: Node) -> bool { + if (node.getKind() = 214) { + return true + } +} + +/** + * Determines whether a node is a `typeof` expression. + */ +pub fn isTypeOfExpression(node: Node) -> bool { + if (node.getKind() = 215) { + return true + } +} + +/** + * Determines whether a node is a `void` expression. + */ +pub fn isVoidExpression(node: Node) -> bool { + if (node.getKind() = 216) { + return true + } +} + +/** + * Determines whether a node is an `await` expression. + */ +pub fn isAwaitExpression(node: Node) -> bool { + if (node.getKind() = 217) { + return true + } +} + +/** + * Determines whether a node is a prefix unary expression. + */ +pub fn isPrefixUnaryExpression(node: Node) -> bool { + if (node.getKind() = 218) { + return true + } +} + +/** + * Determines whether a node is a postfix unary expression. + */ +pub fn isPostfixUnaryExpression(node: Node) -> bool { + if (node.getKind() = 219) { + return true + } +} + +/** + * Determines whether a node is a binary expression + */ +pub fn isBinaryExpression(node: Node) -> bool { + if (node.getKind() = 220) { + return true + } +} + +/** + * Determines whether a node is a conditional expression. + */ +pub fn isConditionalExpression(node: Node) -> bool { + if (node.getKind() = 221) { + return true + } +} + +/** + * Determines whether a node is a template expression. + */ +pub fn isTemplateExpression(node: Node) -> bool { + if (node.getKind() = 222) { + return true + } +} + +/** + * Determines whether a node is a yield expression. + */ +pub fn isYieldExpression(node: Node) -> bool { + if (node.getKind() = 223) { + return true + } +} + +/** + * Determines whether a node is a spread element. + */ +pub fn isSpreadElement(node: Node) -> bool { + if (node.getKind() = 224) { + return true + } +} + +/** + * Determines whether a node is a class expression. + */ +pub fn isClassExpression(node: Node) -> bool { + if (node.getKind() = 225) { + return true + } +} + +/** + * Determines whether a node is an omitted expression. + */ +pub fn isOmittedExpression(node: Node) -> bool { + if (node.getKind() = 226) { + return true + } +} + +/** + * Determines whether a node is an `as` expression. + */ +pub fn isAsExpression(node: Node) -> bool { + if (node.getKind() = 228) { + return true + } +} + +/** + * Determines whether a node is a non-null expression. + */ +pub fn isNonNullExpression(node: Node) -> bool { + if (node.getKind() = 229) { + return true + } +} + +/** + * Determines whether a node is a meta property. + */ +pub fn isMetaProperty(node: Node) -> bool { + if (node.getKind() = 230) { + return true + } +} + +/** + * Determines whether a node is a synthetic expression. + */ +pub fn isSyntheticExpression(node: Node) -> bool { + if (node.getKind() = 231) { + return true + } +} + +/** + * Determines whether a node is a partially emitted expression. + */ +pub fn isPartiallyEmittedExpression(node: Node) -> bool { + if (node.getKind() = 348) { + return true + } +} + +/** + * Determines whether a node is a comma list expression. + */ +pub fn isCommaListExpression(node: Node) -> bool { + if (node.getKind() = 349) { + return true + } +} + +/** + * Determines whether a node is a synthetic reference expression. + */ +pub fn isSyntheticReferenceExpression(node: Node) -> bool { + if (node.getKind() = 352) { + return true + } +} + +/** + * Determines whether a node is a null literal. + */ +pub fn isNullLiteral(node: Node) -> bool { + if (isNullKeyword(node)) { + return true + } +} + +/** + * Determines whether a node is a boolean literal. + */ +pub fn isBooleanLiteral(node: Node) -> bool { + if (isTrueKeyword(node)) { + return true + } + if (isFalseKeyword(node)) { + return true + } +} + +/** + * Determines whether a node is a literal expression. + */ +pub fn isLiteralExpression(node: Node) -> bool { + if (isNumericLiteral(node)) { + return true + } + if (isBigIntLiteral(node)) { + return true + } + if (isStringLiteral(node)) { + return true + } + if (isRegularExpressionLiteral(node)) { + return true + } + if (isNoSubstitutionTemplateLiteral(node)) { + return true + } +} + +/** + * Determines whether a node is a `this` expression. + */ +pub fn isThisExpression(node: Node) -> bool { + if (isThisKeyword(node)) { + return true + } +} + +/** + * Determines whether a node is a `super` expression. + */ +pub fn isSuperExpression(node: Node) -> bool { + if (isSuperKeyword(node)) { + return true + } +} + +/** + * Determines whether a node is an `import` expression. + */ +pub fn isImportExpression(node: Node) -> bool { + if (isImportKeyword(node)) { + let (parent = node.getParent()) { + if (isCallExpression(parent)) { + return true + } + } + } +} + +/** + * Determines whether a node is a primary expression. + */ +pub fn isPrimaryExpression(node: Node) -> bool { + if (isLiteralExpression(node)) { + return true + } + if (isNullLiteral(node)) { + return true + } + if (isBooleanLiteral(node)) { + return true + } + if (isIdentifier(node)) { + return true + } + if (isPrivateIdentifier(node)) { + return true + } + if (isThisExpression(node)) { + return true + } + if (isSuperExpression(node)) { + return true + } + if (isImportExpression(node)) { + return true + } + if (isArrayLiteralExpression(node)) { + return true + } + if (isObjectLiteralExpression(node)) { + return true + } + if (isJsxAttributes(node)) { + return true + } + if (isNewExpression(node)) { + return true + } + if (isParenthesizedExpression(node)) { + return true + } + if (isFunctionExpression(node)) { + return true + } + if (isTemplateExpression(node)) { + return true + } + if (isClassExpression(node)) { + return true + } + if (isMetaProperty(node)) { + return true + } + if (isJsxElement(node)) { + return true + } + if (isJsxSelfClosingElement(node)) { + return true + } + if (isJsxFragment(node)) { + return true + } +} + +/** + * Determines whether a node is a member expression. + */ +pub fn isMemberExpression(node: Node) -> bool { + if (isPrimaryExpression(node)) { + return true + } + if (isPropertyAccessExpression(node)) { + return true + } + if (isElementAccessExpression(node)) { + return true + } + if (isTaggedTemplateExpression(node)) { + return true + } +} + +/** + * Determines whether a node is a left-hand-side expression. + */ +pub fn isLeftHandSideExpression(node: Node) -> bool { + if (isMemberExpression(node)) { + return true + } + if (isPartiallyEmittedExpression(node)) { + return true + } + if (isCallExpression(node)) { + return true + } + if (isNonNullExpression(node)) { + return true + } + if (isSyntheticReferenceExpression(node)) { + return true + } +} + +/** + * Determines whether a node is an update expression. + */ +pub fn isUpdateExpression(node: Node) -> bool { + if (isLeftHandSideExpression(node)) { + return true + } + if (isPrefixUnaryExpression(node)) { + return true + } + if (isPostfixUnaryExpression(node)) { + return true + } +} + +/** + * Determines whether a node is an unary expression. + */ +pub fn isUnaryExpression(node: Node) -> bool { + if (isUpdateExpression(node)) { + return true + } + if (isTypeAssertionExpression(node)) { + return true + } + if (isDeleteExpression(node)) { + return true + } + if (isTypeOfExpression(node)) { + return true + } + if (isVoidExpression(node)) { + return true + } + if (isAwaitExpression(node)) { + return true + } +} + +/** + * Determines whether a node is an expression. + */ +pub fn isExpression(node: Node) -> bool { + if (isUnaryExpression(node)) { + return true + } + if (isArrowFunction(node)) { + return true + } + if (isBinaryExpression(node)) { + return true + } + if (isConditionalExpression(node)) { + return true + } + if (isYieldExpression(node)) { + return true + } + if (isSpreadElement(node)) { + return true + } + if (isOmittedExpression(node)) { + return true + } + if (isAsExpression(node)) { + return true + } + if (isSyntheticExpression(node)) { + return true + } + if (isCommaListExpression(node)) { + return true + } + if (isJsxOpeningElement(node)) { + return true + } + if (isJsxClosingElement(node)) { + return true + } + if (isJsxOpeningFragment(node)) { + return true + } + if (isJsxClosingFragment(node)) { + return true + } + if (isJsxExpression(node)) { + return true + } +} + +/** + * Determines whether a node is a exponentiation expression using `**`. + */ +pub fn isExponentiationExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + asteriskAsteriskToken in AsteriskAsteriskToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(asteriskAsteriskToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a multiplicative expression using `*`, `/` or `%`. + */ +pub fn isMultiplicativeExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + multiplicativeOperator in MultiplicativeOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(multiplicativeOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is a multiplication expression using `*`. + */ +pub fn isMultiplicationExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + asteriskToken in AsteriskToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(asteriskToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a division expression using `/`. + */ +pub fn isDivisionExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + slashToken in SlashToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(slashToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a remainder expression using `%`. + */ +pub fn isRemainderExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + percentToken in PercentToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(percentToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an additive expression using `+` or `-`. + */ +pub fn isAdditiveExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + additiveOperator in AdditiveOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(additiveOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is an addition expression using `+`. + */ +pub fn isAdditionExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + plusToken in PlusToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(plusToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a subtraction expression using `-`. + */ +pub fn isSubtractionExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + minusToken in MinusToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(minusToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a shift expression using `<<`, `>>` or `>>>`. + */ +pub fn isShiftExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + shiftOperator in ShiftOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(shiftOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is a left-shift expression using `<<`. + */ +pub fn isLeftShiftExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + lessThanLessThanEqualsToken in LessThanLessThanEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(lessThanLessThanEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a signed right-shift expression using `>>`. + */ +pub fn isRightShiftExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + greaterThanGreaterThanToken in GreaterThanGreaterThanToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(greaterThanGreaterThanToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a unsigned right-shift expression using `>>>`. + */ +pub fn isUnsignedRightShiftExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + greaterThanGreaterThanGreaterThanToken in GreaterThanGreaterThanGreaterThanToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(greaterThanGreaterThanGreaterThanToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a relational expression using `<`, `<=`, `>`, `>=`, `instanceof` or `in`. + */ +pub fn isRelationalExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + relationalOperator in RelationalOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(relationalOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is a less-than expression using `<`. + */ +pub fn isLessThanExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + lessThanToken in LessThanToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(lessThanToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a less-than-or-equal expression using `<=`. + */ +pub fn isLessThanEqualsExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + lessThanEqualsToken in LessThanEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(lessThanEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a greater-than expression using `>`. + */ +pub fn isGreaterThanExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + greaterThanToken in GreaterThanToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(greaterThanToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a greater-than-or-equal expression using `>=`. + */ +pub fn isGreaterThanEqualsExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + greaterThanEqualsToken in GreaterThanEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(greaterThanEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an `instanceof` expression. + */ +pub fn isInstanceOfExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + instanceOfKeyword in InstanceOfKeyword(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(instanceOfKeyword)) { + return true + } + } + } +} + +/** + * Determines whether a node is an `in` expression. + */ +pub fn isInExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + inKeyword in InKeyword(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(inKeyword)) { + return true + } + } + } +} + +/** + * Determines whether a node is an equality test expression using `==`, `!=`, + * `===` or `!==`. + */ +pub fn isEqualityTestExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + equalityOperator in EqualityOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(equalityOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is an equality expression using `==`. + */ +pub fn isEqualityExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + equalsEqualsToken in EqualsEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(equalsEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an inequality expression using `!=`. + */ +pub fn isInequalityExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + exclamationEqualsToken in ExclamationEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(exclamationEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a strict equality expression using `===`. + */ +pub fn isStrictEqualityExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + equalsEqualsEqualsToken in EqualsEqualsEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(equalsEqualsEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a strict inequality expression using `!==`. + */ +pub fn isStrictInequalityExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + exclamationEqualsEqualsToken in ExclamationEqualsEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(exclamationEqualsEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a strict equality test expression using + * `===` or `!==`. + */ +pub fn isStrictEqualityTestExpression(node: Node) -> bool { + if (isStrictEqualityExpression(node)) { + return true + } + if (isStrictInequalityExpression(node)) { + return true + } +} + +/** + * Determines whether a node is a non-strict equality test expression using + * `==` or `!=`. + */ +pub fn isNonStrictEqualityTestExpression(node: Node) -> bool { + if (isEqualityExpression(node)) { + return true + } + if (isInequalityExpression(node)) { + return true + } +} + +/** + * Determines whether a node is a binary bitwise expression using + * `&`, `|` or `^`. + */ +pub fn isBinaryBitwiseExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + binaryBitwiseOperator in BinaryBitwiseOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(binaryBitwiseOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is a bitwise AND expression using `&`. + */ +pub fn isBitwiseAndExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + ampersandToken in AmpersandToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(ampersandToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a bitwise OR expression using `|`. + */ +pub fn isBitwiseOrExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + barToken in BarToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(barToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a bitwise XOR expression using `^`. + */ +pub fn isBitwiseXorExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + caretToken in CaretToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(caretToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a binary logical expression using + * `&&`, `||` or `??`. + */ +pub fn isBinaryLogicalExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + binaryLogicalOperator in BinaryLogicalOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(binaryLogicalOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is a logical AND expression using `&&`. + */ +pub fn isLogicalAndExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + ampersandAmpersandToken in AmpersandAmpersandToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(ampersandAmpersandToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a logical OR expression using `||`. + */ +pub fn isLogicalOrExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + barBarToken in BarBarToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(barBarToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a nullish coalescing expression using `??`. + */ +pub fn isNullishCoalescingExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + questionQuestionToken in QuestionQuestionToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(questionQuestionToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an assignment expression, either compound or simple. + */ +pub fn isAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + assignmentOperator in AssignmentOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(assignmentOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is a simple assignment expression using `=`. + */ +pub fn isSimpleAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + equalsToken in EqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(equalsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a compound assignment expression using + * `+=`, `-=`, `**=`, `*=`, `/=`, `%=`, `&=`, `|=`, `^=`, `<<=`, `>>=`, `>>>=`, + * `&&=`, `||=` or `??=`. + */ +pub fn isCompoundAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + compoundAssignmentOperator in CompoundAssignmentOperator(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(compoundAssignmentOperator)) { + return true + } + } + } +} + +/** + * Determines whether a node is an addition assignment expression using `+=`. + */ +pub fn isAdditionAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + plusEqualsToken in PlusEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(plusEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a subtraction assignment expression using `-=`. + */ +pub fn isSubtractionAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + minusEqualsToken in MinusEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(minusEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an exponentiation assignment expression using `**=`. + */ +pub fn isExponentiationAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + asteriskAsteriskEqualsToken in AsteriskAsteriskEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(asteriskAsteriskEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a multiplication assignment expression using `*=`. + */ +pub fn isMultiplicationAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + asteriskEqualsToken in AsteriskEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(asteriskEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a division assignment expression using `/=`. + */ +pub fn isDivisionAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + slashEqualsToken in SlashEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(slashEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a remainder assignment expression using `%=`. + */ +pub fn isRemainderAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + percentEqualsToken in PercentEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(percentEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a bitwise AND assignment expression using `&=`. + */ +pub fn isBitwiseAndAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + ampersandEqualsToken in AmpersandEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(ampersandEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a bitwise OR assignment expression using `|=`. + */ +pub fn isBitwiseOrAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + barEqualsToken in BarEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(barEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a bitwise XOR assignment expression using `^=`. + */ +pub fn isBitwiseXorAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + caretEqualsToken in CaretEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(caretEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a left shift assignment expression using `<<=`. + */ +pub fn isLeftShiftAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + lessThanLessThanEqualsToken in LessThanLessThanEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(lessThanLessThanEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a right shift assignment expression using `>>=`. + */ +pub fn isRightShiftAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + greaterThanGreaterThanEqualsToken in GreaterThanGreaterThanEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(greaterThanGreaterThanEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an unsigned right shift assignment expression using `>>>=`. + */ +pub fn isUnsignedRightShiftAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + greaterThanGreaterThanGreaterThanEqualsToken in GreaterThanGreaterThanGreaterThanEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(greaterThanGreaterThanGreaterThanEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a logical AND assignment expression using `&&=`. + */ +pub fn isLogicalAndAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + ampersandAmpersandEqualsToken in AmpersandAmpersandEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(ampersandAmpersandEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a logical OR assignment expression using `||=`. + */ +pub fn isLogicalOrAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + barBarEqualsToken in BarBarEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(barBarEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a nullish assignment expression using `??=`. + */ +pub fn isNullishAssignmentExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + questionQuestionEqualsToken in QuestionQuestionEqualsToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(questionQuestionEqualsToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a comma expression using `,`. + */ +pub fn isCommaExpression(node: Node) -> bool { + for (binaryExpression in BinaryExpression(__all_data__), + commaToken in CommaToken(__all_data__)) { + if (binaryExpression.key_eq(node)) { + if (binaryExpression.getOperator().key_eq(commaToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a prefix increment expression using `++`. + */ +pub fn isPrefixIncrementExpression(node: Node) -> bool { + for (prefixUnaryExpression in PrefixUnaryExpression(__all_data__), + plusPlusToken in PlusPlusToken(__all_data__)) { + if (prefixUnaryExpression.key_eq(node)) { + if (prefixUnaryExpression.getOperator().key_eq(plusPlusToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a prefix decrement expression using `--`. + */ +pub fn isPrefixDecrementExpression(node: Node) -> bool { + for (prefixUnaryExpression in PrefixUnaryExpression(__all_data__), + minusMinusToken in MinusMinusToken(__all_data__)) { + if (prefixUnaryExpression.key_eq(node)) { + if (prefixUnaryExpression.getOperator().key_eq(minusMinusToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an unary plus expression using `+`. + */ +pub fn isUnaryPlusExpression(node: Node) -> bool { + for (prefixUnaryExpression in PrefixUnaryExpression(__all_data__), + plusToken in PlusToken(__all_data__)) { + if (prefixUnaryExpression.key_eq(node)) { + if (prefixUnaryExpression.getOperator().key_eq(plusToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an unary minus (also known as negation) expression using `-`. + */ +pub fn isUnaryMinusExpression(node: Node) -> bool { + for (prefixUnaryExpression in PrefixUnaryExpression(__all_data__), + minusToken in MinusToken(__all_data__)) { + if (prefixUnaryExpression.key_eq(node)) { + if (prefixUnaryExpression.getOperator().key_eq(minusToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a bitwise NOT expression using `~`. + */ +pub fn isBitwiseNotExpression(node: Node) -> bool { + for (prefixUnaryExpression in PrefixUnaryExpression(__all_data__), + tildeToken in TildeToken(__all_data__)) { + if (prefixUnaryExpression.key_eq(node)) { + if (prefixUnaryExpression.getOperator().key_eq(tildeToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a logical NOT expression using `!`. + */ +pub fn isLogicalNotExpression(node: Node) -> bool { + for (prefixUnaryExpression in PrefixUnaryExpression(__all_data__), + exclamationToken in ExclamationToken(__all_data__)) { + if (prefixUnaryExpression.key_eq(node)) { + if (prefixUnaryExpression.getOperator().key_eq(exclamationToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a postfix increment expression using `++`. + */ +pub fn isPostfixIncrementExpression(node: Node) -> bool { + for (postfixUnaryExpression in PostfixUnaryExpression(__all_data__), + plusPlusToken in PlusPlusToken(__all_data__)) { + if (postfixUnaryExpression.key_eq(node)) { + if (postfixUnaryExpression.getOperator().key_eq(plusPlusToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is a postfix decrement expression using `--`. + */ +pub fn isPostfixDecrementExpression(node: Node) -> bool { + for (postfixUnaryExpression in PostfixUnaryExpression(__all_data__), + minusMinusToken in MinusMinusToken(__all_data__)) { + if (postfixUnaryExpression.key_eq(node)) { + if (postfixUnaryExpression.getOperator().key_eq(minusMinusToken)) { + return true + } + } + } +} + +/** + * Determines whether a node is an increment expression using `++`. + */ +pub fn isIncrementExpression(node: Node) -> bool { + if (isPrefixIncrementExpression(node)) { + return true + } + if (isPostfixIncrementExpression(node)) { + return true + } +} + +/** + * Determines whether a node is a decrement expression using `--`. + */ +pub fn isDecrementExpression(node: Node) -> bool { + if (isPrefixDecrementExpression(node)) { + return true + } + if (isPostfixDecrementExpression(node)) { + return true + } +} + +/** + * Determines whether a node is a member name. + */ +pub fn isMemberName(node: Node) -> bool { + if (isIdentifier(node)) { + return true + } + if (isPrivateIdentifier(node)) { + return true + } +} + +/** + * Determines whether a node is an access expression. + */ +pub fn isAccessExpression(node: Node) -> bool { + if (isPropertyAccessExpression(node)) { + return true + } + if (isElementAccessExpression(node)) { + return true + } +} + +/** + * Determines whether a node is a decorator. + */ +pub fn isDecorator(node: Node) -> bool { + if (node.getKind() = 164) { + return true + } +} + +/** + * Determines whether a node is a call-like expression. + */ +pub fn isCallLikeExpression(node: Node) -> bool { + if (isCallExpression(node)) { + return true + } + if (isNewExpression(node)) { + return true + } + if (isTaggedTemplateExpression(node)) { + return true + } + if (isDecorator(node)) { + return true + } + if (isJsxOpeningElement(node)) { + return true + } +} + +/** + * Determines whether a node is a CallLikeExpression or AccessExpression that may invoke a FunctionLikeDeclaration. + */ +pub fn isMayInvokeExpression(node: Node) -> bool { + if (isCallLikeExpression(node)) { + return true + } + if (isAccessExpression(node)) { + return true + } +} diff --git a/language/javascript/lib/FileSystem.gdl b/language/javascript/lib/FileSystem.gdl new file mode 100644 index 00000000..1767a3eb --- /dev/null +++ b/language/javascript/lib/FileSystem.gdl @@ -0,0 +1,26 @@ +/** + * @filename: FileSystem + * @brief: Provides classes and predicates for working with the file system. + */ + +/** + * A JavaScript / TypeScript file. + */ +schema File extends FileDO { +} + +impl File { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *File { + for (tmp in FileDO(db)) { + yield File { + oid : tmp.oid, + name : tmp.name, + extension : tmp.extension, + relative_path : tmp.relative_path, + location_oid : tmp.location_oid + } + } + } +} diff --git a/language/javascript/lib/Function.gdl b/language/javascript/lib/Function.gdl new file mode 100644 index 00000000..40e1aa3e --- /dev/null +++ b/language/javascript/lib/Function.gdl @@ -0,0 +1,633 @@ +/** + * @filename: Function + * @brief: Provides classes and predicates for working with JavaScript / TypeScript functions + */ + +/** + * A FunctionLike. It includes FunctionLikeDeclaration, FunctionType and Signature + */ +schema FunctionLike extends Node { +} + +impl FunctionLike { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FunctionLike { + for (tmp in Node(db)) { + if (isFunctionLike(tmp)) { + yield FunctionLike { + id : tmp.id + } + } + } + } +} + +/** + * A call site, which is an invoke expression with the corresponding callee. + * + * Currently, Only direct invokes are recorded. + */ +schema CallSite extends CallSiteDO { +} + +impl CallSite { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CallSite { + for (tmp in CallSiteDO(db)) { + yield CallSite { + invoke_expression_oid : tmp.invoke_expression_oid, + callee_oid : tmp.callee_oid + } + } + } + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callee in FunctionLikeDeclaration(__all_data__)) { + if (callee.id = self.getCalleeOid()) { + return callee + } + } + } +} + +/** + * A function-like declaration, including: + * - MethodDeclaration, + * - Constructor, + * - GetAccessor, + * - SetAccessor, + * - FunctionExpression, + * - ArrowFunction, + * - FunctionDeclaration, + */ +schema FunctionLikeDeclaration extends FunctionLike { +} + +impl FunctionLikeDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FunctionLikeDeclaration { + for (tmp in FunctionLike(db)) { + if (isFunctionLikeDeclaration(Node {id: tmp.id})) { + yield FunctionLikeDeclaration { + id : tmp.id + } + } + } + } + + fn getAllTypeParameterIndex(self) -> *int { + for (childIndex in int::__undetermined_all__()) { + let (child = self.getChild(childIndex)) { + let (tmp = TypeParameter(__all_data__).find(child)) { + yield childIndex + } + } + } + } + + fn getAllParameterIndex(self) -> *int { + for (childIndex in int::__undetermined_all__()) { + let (child = self.getChild(childIndex)) { + let (tmp = Parameter(__all_data__).find(child)) { + yield childIndex + } + } + } + } + + fn getAllControlNode(self) -> *Node { + for (node in Node(__all_data__)) { + if (node.getEnclosingFunction() = self && isControlNode(node)) { + yield node + } + } + } + + /** + * Gets a decorator of this FunctionLikeDeclaration. + */ + pub fn getADecorator(self) -> *Decorator { + for (decorator in Decorator(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (decorator.key_eq(auto_tmp1)) { + yield decorator + } + } + } + } + + /** + * Gets the `i`th decorator of this FunctionLikeDeclaration. + */ + pub fn getDecorator(self, i: int) -> Decorator { + for (decorator in Decorator(__all_data__)) { + if (decorator.key_eq(self.getChild(i))) { + return decorator + } + } + } + + /** + * Gets a modifier of this FunctionLikeDeclaration. + */ + pub fn getAModifier(self) -> *Modifier { + for (modifier in Modifier(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (modifier.key_eq(auto_tmp1)) { + yield modifier + } + } + } + } + + /** + * Gets the `i`th modifier of this FunctionLikeDeclaration. + */ + pub fn getModifier(self, i: int) -> Modifier { + for (childIndex in int::__undetermined_all__()) { + for (modifier in Modifier(__all_data__)) { + let (decoratorCount = self.getDecoratorCount()) { + if (modifier.key_eq(self.getChild(childIndex))) { + if (i = childIndex - decoratorCount) { + return modifier + } + } + } + } + } + } + + /** + * Determines whether this FunctionLikeDeclaration is a generator. + */ + pub fn isGenerator(self) -> bool { + for (asteriskToken in AsteriskToken(__all_data__)) { + let (modifierCount = self.getModifierCount()) { + let (tmp = self.getChild(modifierCount)) { + if (asteriskToken.key_eq(tmp)) { + return true + } + } + } + } + } + + /** + * Gets the name node, which is a PropertyName. + */ + pub fn getNameNode(self) -> PropertyName { + for (nameNode in PropertyName(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (nameNode.key_eq(auto_tmp1)) { + return nameNode + } + } + } + } + + /** + * Gets the name of this function-like declaration + */ + pub fn getName(self) -> string { + for (functionLikeDeclarationDO in FunctionLikeDeclarationDO(__all_data__)) { + if (functionLikeDeclarationDO.key_eq(self)) { + let (name = functionLikeDeclarationDO.getName()) { + return name + } + } + } + } + + /** + * Gets a type parameter. + */ + pub fn getATypeParameter(self) -> *TypeParameter { + for (typeParameter in TypeParameter(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeParameter.key_eq(auto_tmp1)) { + yield typeParameter + } + } + } + } + + /** + * Gets the `i`th type parameter. + */ + pub fn getTypeParameter(self, i: int) -> TypeParameter { + for (index in int::__undetermined_all__()) { + for (typeParameter in TypeParameter(__all_data__)) { + if (typeParameter.key_eq(self.getChild(index))) { + let (firstIndex = self.getTypeParameterFirstIndex()) { + if (i = index - firstIndex) { + return typeParameter + } + } + } + } + } + } + + /** + * Gets a parameter. + */ + pub fn getAParameter(self) -> *Parameter { + for (parameter in Parameter(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (parameter.key_eq(auto_tmp1)) { + yield parameter + } + } + } + } + + /** + * Determine this FunctionLikeDeclaration contains any parameter. + */ + pub fn hasParameter(self) -> bool { + for (parameter in Parameter(__all_data__)) { + for (auto_tmp1 in self.getAParameter()) { + if (parameter = auto_tmp1) { + return true + } + } + } + } + + /** + * Gets the `i`th parameter. + */ + pub fn getParameter(self, i: int) -> Parameter { + for (index in int::__undetermined_all__()) { + for (parameter in Parameter(__all_data__)) { + if (parameter.key_eq(self.getChild(index))) { + let (firstIndex = self.getParameterFirstIndex()) { + if (i = index - firstIndex) { + return parameter + } + } + } + } + } + } + + /** + * Gets the type node. + */ + pub fn getTypeNode(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeNode.key_eq(auto_tmp1)) { + return typeNode + } + } + } + } + + /** + * Gets the body of this function-like declaration + */ + pub fn getBody(self) -> BlockStatement { + for (body in BlockStatement(__all_data__)) { + if (self.key_eq(body.getParent())) { + return body + } + } + } + + /** + * Gets a call site of this function-like declaration + */ + pub fn getACallSite(self) -> *MayInvokeExpression { + for (callSite in MayInvokeExpression(__all_data__)) { + if (self = callSite.getCallee()) { + yield callSite + } + } + } + + pub fn getAReturnStatement(self) -> *ReturnStatement { + for (returnStatement in ReturnStatement(__all_data__)) { + if (returnStatement.getEnclosingFunction() = self) { + yield returnStatement + } + } + } + + pub fn getAReturnedExpression(self) -> *Expression { + // TODO: the body of an ArrowFunction is the returned expression if it is an expression + for (returnStatement in self.getAReturnStatement()) { + yield returnStatement.getExpression() + } + } + + /** + * Gets the count of parameters. + */ + pub fn getParameterCount(self) -> int { + return self.getAParameter().len() + } + + /** + * Gets the count of type parameters. + */ + pub fn getTypeParameterCount(self) -> int { + return self.getATypeParameter().len() + } + + pub fn getTypeParameterFirstIndex(self) -> int { + return self.getAllTypeParameterIndex().min() + } + + pub fn getParameterFirstIndex(self) -> int { + return self.getAllParameterIndex().min() + } + /** + * Gets the number of decorators of this FunctionLikeDeclaration. + */ + pub fn getDecoratorCount(self) -> int { + return self.getADecorator().len() + } + + /** + * Gets the number of modifiers of this FunctionLikeDeclaration. + */ + pub fn getModifierCount(self) -> int { + return self.getAModifier().len() + } + + /** + * Gets the cyclomatic complexity of this function-like declaration + */ + pub fn getCyclomaticComplexity(self) -> int { + return self.getAllControlNode().len() + 1 + } +} + +/** + * A FunctionDeclaration. + */ +schema FunctionDeclaration extends FunctionLikeDeclaration { +} + +impl FunctionDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FunctionDeclaration { + for (tmp in FunctionLikeDeclaration(db)) { + if (isFunctionDeclaration(Node {id: tmp.id})) { + yield FunctionDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A MethodDeclaration. + */ +schema MethodDeclaration extends FunctionLikeDeclaration { +} + +impl MethodDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MethodDeclaration { + for (tmp in FunctionLikeDeclaration(db)) { + if (isMethodDeclaration(Node {id: tmp.id})) { + yield MethodDeclaration { + id : tmp.id + } + } + } + } + + pub fn getName(self) -> string { + return self.getNameNode().getName() + } +} + +/** + * A ConstructorDeclaration. + */ +schema ConstructorDeclaration extends FunctionLikeDeclaration { +} + +impl ConstructorDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ConstructorDeclaration { + for (tmp in FunctionLikeDeclaration(db)) { + if (isConstructor(Node {id: tmp.id})) { + yield ConstructorDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A `get` accessor. + */ +schema GetAccessor extends FunctionLikeDeclaration { +} + +impl GetAccessor { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GetAccessor { + for (tmp in FunctionLikeDeclaration(db)) { + if (isGetAccessor(Node {id: tmp.id})) { + yield GetAccessor { + id : tmp.id + } + } + } + } +} + +/** + * A `set` Accessor. + */ +schema SetAccessor extends FunctionLikeDeclaration { +} + +impl SetAccessor { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SetAccessor { + for (tmp in FunctionLikeDeclaration(db)) { + if (isSetAccessor(Node {id: tmp.id})) { + yield SetAccessor { + id : tmp.id + } + } + } + } +} + +/** + * A function expression. + */ +schema FunctionExpressionDeclaration extends FunctionLikeDeclaration { +} + +impl FunctionExpressionDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FunctionExpressionDeclaration { + for (tmp in FunctionLikeDeclaration(db)) { + if (isFunctionExpression(Node {id: tmp.id})) { + yield FunctionExpressionDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A ArrowFunction. + */ +schema ArrowFunction extends FunctionLikeDeclaration { +} + +impl ArrowFunction { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ArrowFunction { + for (tmp in FunctionLikeDeclaration(db)) { + if (isArrowFunction(Node {id: tmp.id})) { + yield ArrowFunction { + id : tmp.id + } + } + } + } +} + +/** + * Determines whether a node is a MethodDeclaration + */ +pub fn isMethodDeclaration(node: Node) -> bool { + if (node.getKind() = 168) { + return true + } +} + +/** + * Determines whether a node is a Constructor + */ +pub fn isConstructor(node: Node) -> bool { + if (node.getKind() = 170) { + return true + } +} + +/** + * Determines whether a node is a `get` accessor + */ +pub fn isGetAccessor(node: Node) -> bool { + if (node.getKind() = 171) { + return true + } +} + +/** + * Determines whether a node is a `set` accessor + */ +pub fn isSetAccessor(node: Node) -> bool { + if (node.getKind() = 172) { + return true + } +} + +/** + * Determines whether a node is a function-like declaration, including: + * - MethodDeclaration, + * - Constructor, + * - GetAccessor, + * - SetAccessor, + * - FunctionExpression, + * - ArrowFunction, + * - FunctionDeclaration, + */ +pub fn isFunctionLikeDeclaration(node: Node) -> bool { + let (kind = node.getKind()) { + if (isFunctionLikeDeclarationKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node kind is a FunctionLike kind + */ +pub fn isFunctionLikeKind(kind: int) -> bool { + if (isFunctionLikeDeclarationKind(kind)) { + return true + } + if (isFunctionTypeOrSignatureKind(kind)) { + return true + } +} + +/** + * Determines whether a node is a FunctionLike + */ +pub fn isFunctionLike(node: Node) -> bool { + let (kind = node.getKind()) { + if (isFunctionLikeKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node is a FunctionBlock + */ +pub fn isFunctionBlock(node: Node) -> bool { + // Block + if (node.getKind() = 234) { + let (parent = node.getParent()) { + if (isFunctionLike(parent)) { + return true + } + } + } +} + +/** + * Determines whether a node kind is a FunctionTypeOrSignature kind + */ +pub fn isFunctionTypeOrSignatureKind(kind: int) -> bool { + [ + {167}, // MethodSignature + {173}, // CallSignature + {174}, // ConstructSignature + {175}, // IndexSignature + {178}, // FunctionType + {179}, // ConstructorType + {315}, // JSDocFunctionType + {321}, // JSDocSignature + ] +} + +/** + * Determines whether a node kind is a FunctionLikeDeclaration kind + */ +pub fn isFunctionLikeDeclarationKind(kind: int) -> bool { + [ + {168}, // MethodDeclaration + {170}, // Constructor + {171}, // GetAccessor + {172}, // SetAccessor + {212}, // FunctionExpression + {213}, // ArrowFunction + {255}, // FunctionDeclaration + ] +} diff --git a/language/javascript/lib/HeritageClause.gdl b/language/javascript/lib/HeritageClause.gdl new file mode 100644 index 00000000..bfd644eb --- /dev/null +++ b/language/javascript/lib/HeritageClause.gdl @@ -0,0 +1,95 @@ +/** + * @filename: HeritageClause + * @brief: Provides classes and predicates for working with JavaScript / TypeScript heritage clauses. + */ + +/** + * A heritage token, that is an `extends` or `implements` keyword. + */ +schema HeritageToken extends Node { +} + +impl HeritageToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *HeritageToken { + for (tmp in Node(db)) { + if (isHeritageToken(tmp)) { + yield HeritageToken { + id : tmp.id + } + } + } + } +} + +/** + * A heritage clause. + */ +schema HeritageClause extends Node { +} + +impl HeritageClause { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *HeritageClause { + for (tmp in Node(db)) { + if (isHeritageClause(tmp)) { + yield HeritageClause { + id : tmp.id + } + } + } + } + + pub fn getToken(self) -> HeritageToken { + for (token in HeritageToken(__all_data__)) { + if (token.key_eq(self.getChild(0))) { + return token + } + } + } + + pub fn getAType(self) -> *ExpressionWithTypeArguments { + for (type in ExpressionWithTypeArguments(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (type.key_eq(auto_tmp1)) { + yield type + } + } + } + } + + pub fn getType(self, i: int) -> ExpressionWithTypeArguments { + for (childIndex in int::__undetermined_all__()) { + for (type in ExpressionWithTypeArguments(__all_data__)) { + if (type.key_eq(self.getChild(childIndex))) { + if (i = childIndex - 1) { + return type + } + } + } + } + } +} + +/** + * Determines whether a node is a heritage clause. + */ +pub fn isHeritageClause(node: Node) -> bool { + if (node.getKind() = 290) { + return true + } +} + +/** + * Determines whether a node is a heritage token, that is an `extends` or `implements` keyword. + */ +pub fn isHeritageToken(node: Node) -> bool { + if (isExtendsKeyword(node)) { + return true + } + if (isImplementsKeyword(node)) { + return true + } +} diff --git a/language/javascript/lib/ImportOrExportElement.gdl b/language/javascript/lib/ImportOrExportElement.gdl new file mode 100644 index 00000000..212f255c --- /dev/null +++ b/language/javascript/lib/ImportOrExportElement.gdl @@ -0,0 +1,265 @@ +/** + * @filename: ImportOrExportElement + * @brief: Provides classes and predicates for working with JavaScript / TypeScript import or export elements. + */ + +/** + * A qualified name. + */ +schema QualifiedName extends Node { +} + +impl QualifiedName { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *QualifiedName { + for (tmp in Node(db)) { + if (isQualifiedName(tmp)) { + yield QualifiedName { + id : tmp.id + } + } + } + } +} + +/** + * An import clause. + */ +schema ImportClause extends Node { +} + +impl ImportClause { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ImportClause { + for (tmp in Node(db)) { + if (isImportClause(tmp)) { + yield ImportClause { + id : tmp.id + } + } + } + } +} + +/** + * A namespace import. + */ +schema NamespaceImport extends Node { +} + +impl NamespaceImport { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NamespaceImport { + for (tmp in Node(db)) { + if (isNamespaceImport(tmp)) { + yield NamespaceImport { + id : tmp.id + } + } + } + } +} + +/** + * A named imports. + */ +schema NamedImports extends Node { +} + +impl NamedImports { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NamedImports { + for (tmp in Node(db)) { + if (isNamedImports(tmp)) { + yield NamedImports { + id : tmp.id + } + } + } + } +} + +/** + * An import specifier. + */ +schema ImportSpecifier extends Node { +} + +impl ImportSpecifier { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ImportSpecifier { + for (tmp in Node(db)) { + if (isImportSpecifier(tmp)) { + yield ImportSpecifier { + id : tmp.id + } + } + } + } +} + +/** + * A named exports. + */ +schema NamedExports extends Node { +} + +impl NamedExports { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NamedExports { + for (tmp in Node(db)) { + if (isNamedExports(tmp)) { + yield NamedExports { + id : tmp.id + } + } + } + } +} + +/** + * A namespace export. + */ +schema NamespaceExport extends Node { +} + +impl NamespaceExport { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NamespaceExport { + for (tmp in Node(db)) { + if (isNamespaceExport(tmp)) { + yield NamespaceExport { + id : tmp.id + } + } + } + } +} + +/** + * An export specifier. + */ +schema ExportSpecifier extends Node { +} + +impl ExportSpecifier { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExportSpecifier { + for (tmp in Node(db)) { + if (isExportSpecifier(tmp)) { + yield ExportSpecifier { + id : tmp.id + } + } + } + } +} + +/** + * An external module reference. + */ +schema ExternalModuleReference extends Node { +} + +impl ExternalModuleReference { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExternalModuleReference { + for (tmp in Node(db)) { + if (isExternalModuleReference(tmp)) { + yield ExternalModuleReference { + id : tmp.id + } + } + } + } +} + +/** + * Determines whether a node is a qualified name. + */ +pub fn isQualifiedName(node: Node) -> bool { + if (node.getKind() = 160) { + return true + } +} + +/** + * Determines whether a node is an import clause. + */ +pub fn isImportClause(node: Node) -> bool { + if (node.getKind() = 266) { + return true + } +} + +/** + * Determines whether a node is a namespace import. + */ +pub fn isNamespaceImport(node: Node) -> bool { + if (node.getKind() = 267) { + return true + } +} + +/** + * Determines whether a node is a named imports. + */ +pub fn isNamedImports(node: Node) -> bool { + if (node.getKind() = 268) { + return true + } +} + +/** + * Determines whether a node is an import specifier. + */ +pub fn isImportSpecifier(node: Node) -> bool { + if (node.getKind() = 269) { + return true + } +} + +/** + * Determines whether a node is a named exports. + */ +pub fn isNamedExports(node: Node) -> bool { + if (node.getKind() = 272) { + return true + } +} + +/** + * Determines whether a node is a namespace export. + */ +pub fn isNamespaceExport(node: Node) -> bool { + if (node.getKind() = 273) { + return true + } +} + +/** + * Determines whether a node is an export specifier. + */ +pub fn isExportSpecifier(node: Node) -> bool { + if (node.getKind() = 274) { + return true + } +} + +/** + * Determines whether a node is an external module reference. + */ +pub fn isExternalModuleReference(node: Node) -> bool { + if (node.getKind() = 276) { + return true + } +} diff --git a/language/javascript/lib/JSX.gdl b/language/javascript/lib/JSX.gdl new file mode 100644 index 00000000..6ccc8a86 --- /dev/null +++ b/language/javascript/lib/JSX.gdl @@ -0,0 +1,466 @@ +/** + * @filename: Expression + * @brief: Provides classes and predicates for working with JavaScript / TypeScript expressions + */ + +/** + * A JSX text. + */ +schema JsxText extends Node { +} + +impl JsxText { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxText { + for (tmp in Node(db)) { + if (isJsxText(tmp)) { + yield JsxText { + id : tmp.id + } + } + } + } + + /** + * Gets the value of this jsx text, as a string. + */ + pub fn getValue(self) -> string { + for (literalDO in LiteralDO(__all_data__)) { + if (literalDO.key_eq(self)) { + let (value = literalDO.getValue()) { + return value + } + } + } + } +} + +/** + * A JSX element. + */ +schema JsxElement extends PrimaryExpression { +} + +impl JsxElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxElement { + for (tmp in PrimaryExpression(db)) { + if (isJsxElement(Node {id: tmp.id})) { + yield JsxElement { + id : tmp.id + } + } + } + } +} + +/** + * A JSX self closing element. + */ +schema JsxSelfClosingElement extends PrimaryExpression { +} + +impl JsxSelfClosingElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxSelfClosingElement { + for (tmp in PrimaryExpression(db)) { + if (isJsxSelfClosingElement(Node {id: tmp.id})) { + yield JsxSelfClosingElement { + id : tmp.id + } + } + } + } +} + +/** + * A JSX opening element. + */ +schema JsxOpeningElement extends Expression { +} + +impl JsxOpeningElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxOpeningElement { + for (tmp in Expression(db)) { + if (isJsxOpeningElement(Node {id: tmp.id})) { + yield JsxOpeningElement { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> JsxElement { + for (parent in JsxElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + /** + * Gets the callee of this JSX opening element. + */ + pub fn getCallee(self) -> FunctionLikeDeclaration { + for (callSite in CallSite(__all_data__)) { + if (self.key_eq(callSite)) { + let (callee = callSite.getCallee()) { + return callee + } + } + } + } +} + +/** + * A JSX closing element. + */ +schema JsxClosingElement extends Expression { +} + +impl JsxClosingElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxClosingElement { + for (tmp in Expression(db)) { + if (isJsxClosingElement(Node {id: tmp.id})) { + yield JsxClosingElement { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> JsxElement { + for (parent in JsxElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } +} + +/** + * A JSX fragment. + */ +schema JsxFragment extends PrimaryExpression { +} + +impl JsxFragment { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxFragment { + for (tmp in PrimaryExpression(db)) { + if (isJsxFragment(Node {id: tmp.id})) { + yield JsxFragment { + id : tmp.id + } + } + } + } +} + +/** + * A JSX opening fragment. + */ +schema JsxOpeningFragment extends Expression { +} + +impl JsxOpeningFragment { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxOpeningFragment { + for (tmp in Expression(db)) { + if (isJsxOpeningFragment(Node {id: tmp.id})) { + yield JsxOpeningFragment { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> JsxFragment { + for (parent in JsxFragment(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } +} + +/** + * A JSX closing fragment. + */ +schema JsxClosingFragment extends Expression { +} + +impl JsxClosingFragment { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxClosingFragment { + for (tmp in Expression(db)) { + if (isJsxClosingFragment(Node {id: tmp.id})) { + yield JsxClosingFragment { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> JsxFragment { + for (parent in JsxFragment(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } +} + +/** + * A JSX attribute. + */ +schema JsxAttribute extends Node { +} + +impl JsxAttribute { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxAttribute { + for (tmp in Node(db)) { + if (isJsxAttribute(tmp)) { + yield JsxAttribute { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> JsxAttributes { + for (parent in JsxAttributes(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + pub fn getName(self) -> Identifier { + for (name in Identifier(__all_data__)) { + if (name.key_eq(self.getChild(0))) { + return name + } + } + } + + pub fn getInitializer(self) -> JsxAttributeInitializer { + for (initializer in JsxAttributeInitializer(__all_data__)) { + if (initializer.key_eq(self.getChild(1))) { + return initializer + } + } + } +} + +/** + * A JSX attributes. + */ +schema JsxAttributes extends PrimaryExpression { +} + +impl JsxAttributes { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxAttributes { + for (tmp in PrimaryExpression(db)) { + if (isJsxAttributes(Node {id: tmp.id})) { + yield JsxAttributes { + id : tmp.id + } + } + } + } +} + +/** + * A JSX spread attribute. + */ +schema JsxSpreadAttribute extends Node { +} + +impl JsxSpreadAttribute { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxSpreadAttribute { + for (tmp in Node(db)) { + if (isJsxSpreadAttribute(tmp)) { + yield JsxSpreadAttribute { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> JsxAttributes { + for (parent in JsxAttributes(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A JSX expression. + */ +schema JsxExpression extends Expression { +} + +impl JsxExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxExpression { + for (tmp in Expression(db)) { + if (isJsxExpression(Node {id: tmp.id})) { + yield JsxExpression { + id : tmp.id + } + } + } + } +} + +/** + * A JSX attribute initializer, that is a string literal or JSX expression. + */ +schema JsxAttributeInitializer extends Node { +} + +impl JsxAttributeInitializer { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxAttributeInitializer { + for (tmp in Node(db)) { + if (isStringLiteral(tmp)) { + yield JsxAttributeInitializer { + id : tmp.id + } + } + if (isJsxExpression(tmp)) { + yield JsxAttributeInitializer { + id : tmp.id + } + } + } + } +} + +/** + * Determines whether a node is a JSX element. + */ +pub fn isJsxElement(node: Node) -> bool { + if (node.getKind() = 277) { + return true + } +} + +/** + * Determines whether a node is a JSX self closing element. + */ +pub fn isJsxSelfClosingElement(node: Node) -> bool { + if (node.getKind() = 278) { + return true + } +} + +/** + * Determines whether a node is a JSX opening element. + */ +pub fn isJsxOpeningElement(node: Node) -> bool { + if (node.getKind() = 279) { + return true + } +} + +/** + * Determines whether a node is a JSX closing element. + */ +pub fn isJsxClosingElement(node: Node) -> bool { + if (node.getKind() = 280) { + return true + } +} + +/** + * Determines whether a node is a JSX fragment. + */ +pub fn isJsxFragment(node: Node) -> bool { + if (node.getKind() = 281) { + return true + } +} + +/** + * Determines whether a node is a JSX opening fragment. + */ +pub fn isJsxOpeningFragment(node: Node) -> bool { + if (node.getKind() = 282) { + return true + } +} + +/** + * Determines whether a node is a JSX closing fragment. + */ +pub fn isJsxClosingFragment(node: Node) -> bool { + if (node.getKind() = 283) { + return true + } +} + +/** + * Determines whether a node is a JSX attribute. + */ +pub fn isJsxAttribute(node: Node) -> bool { + if (node.getKind() = 284) { + return true + } +} + +/** + * Determines whether a node is a JSX attributes. + */ +pub fn isJsxAttributes(node: Node) -> bool { + if (node.getKind() = 285) { + return true + } +} + +/** + * Determines whether a node is a JSX spread attribute. + */ +pub fn isJsxSpreadAttribute(node: Node) -> bool { + if (node.getKind() = 286) { + return true + } +} + +/** + * Determines whether a node is a JSX closing fragment. + */ +pub fn isJsxExpression(node: Node) -> bool { + if (node.getKind() = 287) { + return true + } +} diff --git a/language/javascript/lib/Location.gdl b/language/javascript/lib/Location.gdl new file mode 100644 index 00000000..4cbf7f0f --- /dev/null +++ b/language/javascript/lib/Location.gdl @@ -0,0 +1,55 @@ +/** + * @filename: LOCATION + * @brief: LOCATION provides classes and predicates for working with Js locations + */ + +/** + * The location information of a locatable. + */ +schema Location extends LocationDO { +} + +impl Location { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Location { + for (tmp in LocationDO(db)) { + yield Location { + oid : tmp.oid, + file_oid : tmp.file_oid, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number, + text : tmp.text + } + } + } + + /** + * Gets the file of this location + * @return File + */ + pub fn getFile(self) -> File { + for (file in File(__all_data__)) { + if (file.oid = self.getFileOid()) { + return file + } + } + } + + /** + * Gets the file relative path of this location + */ + pub fn getRelativePath(self) -> string { + for (relativePath in string::__undetermined_all__()) { + for (file in File(__all_data__)) { + if (file = self.getFile()) { + if (relativePath = file.getRelativePath()) { + return relativePath + } + } + } + } + } +} diff --git a/language/javascript/lib/Modifier.gdl b/language/javascript/lib/Modifier.gdl new file mode 100644 index 00000000..8fd01079 --- /dev/null +++ b/language/javascript/lib/Modifier.gdl @@ -0,0 +1,405 @@ +/** + * @filename: Statement + * @brief: Provides classes and predicates for working with JavaScript / TypeScript modifiers + */ + +/** + * A modifier. + */ +schema Modifier extends Token { +} + +impl Modifier { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Modifier { + for (tmp in Token(db)) { + if (isModifier(Node {id: tmp.id})) { + yield Modifier { + id : tmp.id + } + } + } + } +} + +/** + * A `const` keyword. + */ +schema ConstKeyword extends Modifier { +} + +impl ConstKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ConstKeyword { + for (tmp in Modifier(db)) { + if (isConstKeyword(Node {id: tmp.id})) { + yield ConstKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `default` keyword. + */ +schema DefaultKeyword extends Modifier { +} + +impl DefaultKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DefaultKeyword { + for (tmp in Modifier(db)) { + if (isDefaultKeyword(Node {id: tmp.id})) { + yield DefaultKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `export` keyword. + */ +schema ExportKeyword extends Modifier { +} + +impl ExportKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExportKeyword { + for (tmp in Modifier(db)) { + if (isExportKeyword(Node {id: tmp.id})) { + yield ExportKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `private` keyword. + */ +schema PrivateKeyword extends Modifier { +} + +impl PrivateKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PrivateKeyword { + for (tmp in Modifier(db)) { + if (isPrivateKeyword(Node {id: tmp.id})) { + yield PrivateKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `protected` keyword. + */ +schema ProtectedKeyword extends Modifier { +} + +impl ProtectedKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ProtectedKeyword { + for (tmp in Modifier(db)) { + if (isProtectedKeyword(Node {id: tmp.id})) { + yield ProtectedKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `public` keyword. + */ +schema PublicKeyword extends Modifier { +} + +impl PublicKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PublicKeyword { + for (tmp in Modifier(db)) { + if (isPublicKeyword(Node {id: tmp.id})) { + yield PublicKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `static` keyword. + */ +schema StaticKeyword extends Modifier { +} + +impl StaticKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *StaticKeyword { + for (tmp in Modifier(db)) { + if (isStaticKeyword(Node {id: tmp.id})) { + yield StaticKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `abstract` keyword. + */ +schema AbstractKeyword extends Modifier { +} + +impl AbstractKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AbstractKeyword { + for (tmp in Modifier(db)) { + if (isAbstractKeyword(Node {id: tmp.id})) { + yield AbstractKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `async` keyword. + */ +schema AsyncKeyword extends Modifier { +} + +impl AsyncKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AsyncKeyword { + for (tmp in Modifier(db)) { + if (isAsyncKeyword(Node {id: tmp.id})) { + yield AsyncKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `declare` keyword. + */ +schema DeclareKeyword extends Modifier { +} + +impl DeclareKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DeclareKeyword { + for (tmp in Modifier(db)) { + if (isDeclareKeyword(Node {id: tmp.id})) { + yield DeclareKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `readonly` keyword. + */ +schema ReadonlyKeyword extends Modifier { +} + +impl ReadonlyKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ReadonlyKeyword { + for (tmp in Modifier(db)) { + if (isReadonlyKeyword(Node {id: tmp.id})) { + yield ReadonlyKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `override` keyword. + */ +schema OverrideKeyword extends Modifier { +} + +impl OverrideKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *OverrideKeyword { + for (tmp in Modifier(db)) { + if (isOverrideKeyword(Node {id: tmp.id})) { + yield OverrideKeyword { + id : tmp.id + } + } + } + } +} + +/** + * Determines whether a node is a modifier. + */ +pub fn isModifier(node: Node) -> bool { + for (kind in int::__undetermined_all__()) { + if (kind = node.getKind()) { + if (isModifierKind(kind)) { + return true + } + } + } +} + +/** + * Determines whether a node is a `const` keyword. + */ +pub fn isConstKeyword(node: Node) -> bool { + if (node.getKind() = 85) { + return true + } +} + +/** + * Determines whether a node is a `default` keyword. + */ +pub fn isDefaultKeyword(node: Node) -> bool { + if (node.getKind() = 88) { + return true + } +} + +/** + * Determines whether a node is an `export` keyword. + */ +pub fn isExportKeyword(node: Node) -> bool { + if (node.getKind() = 93) { + return true + } +} + +/** + * Determines whether a node is a `private` keyword. + */ +pub fn isPrivateKeyword(node: Node) -> bool { + if (node.getKind() = 121) { + return true + } +} + +/** + * Determines whether a node is a `protected` keyword. + */ +pub fn isProtectedKeyword(node: Node) -> bool { + if (node.getKind() = 122) { + return true + } +} + +/** + * Determines whether a node is a `public` keyword. + */ +pub fn isPublicKeyword(node: Node) -> bool { + if (node.getKind() = 123) { + return true + } +} + +/** + * Determines whether a node is a `static` keyword. + */ +pub fn isStaticKeyword(node: Node) -> bool { + if (node.getKind() = 124) { + return true + } +} + +/** + * Determines whether a node is an `abstract` keyword. + */ +pub fn isAbstractKeyword(node: Node) -> bool { + if (node.getKind() = 126) { + return true + } +} + +/** + * Determines whether a node is an `async` keyword. + */ +pub fn isAsyncKeyword(node: Node) -> bool { + if (node.getKind() = 131) { + return true + } +} + +/** + * Determines whether a node is a `declare` keyword. + */ +pub fn isDeclareKeyword(node: Node) -> bool { + if (node.getKind() = 135) { + return true + } +} + +/** + * Determines whether a node is a `readonly` keyword. + */ +pub fn isReadonlyKeyword(node: Node) -> bool { + if (node.getKind() = 144) { + return true + } +} + +/** + * Determines whether a node is an `override` keyword. + */ +pub fn isOverrideKeyword(node: Node) -> bool { + if (node.getKind() = 158) { + return true + } +} + +/** + * Determines whether a node kind is a modifier kind. + */ +pub fn isModifierKind(kind: int) -> bool { + [ + {126}, // AbstractKeyword + {131}, // AsyncKeyword + {85}, // ConstKeyword + {135}, // DeclareKeyword + {88}, // DefaultKeyword + {93}, // ExportKeyword + {121}, // PrivateKeyword + {122}, // ProtectedKeyword + {123}, // PublicKeyword + {158}, // OverrideKeyword + {144}, // ReadonlyKeyword + {124}, // StaticKeyword + ] +} diff --git a/language/javascript/lib/Node.gdl b/language/javascript/lib/Node.gdl new file mode 100644 index 00000000..3512a019 --- /dev/null +++ b/language/javascript/lib/Node.gdl @@ -0,0 +1,431 @@ +/** + * @filename: NODE + * @brief: NODE provides classes and predicates for working with JavaScript / TypeScript AST nodes. + */ + +/** + * A JavaScript / TypeScript ast node. + */ +schema Node { + @primary id: int +} + +impl Node { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Node { + for (nodeDO in NodeDO(db)) { + yield Node {id : nodeDO.oid} + } + for (topLevelDO in TopLevelDO(db)) { + yield Node {id : topLevelDO.oid} + } + } + + /** + * Get the syntax kind of this node + */ + pub fn getKind(self) -> int { + for (nodeDO in NodeDO(__all_data__)) { + if (nodeDO.key_eq(self)) { + return nodeDO.getKind() + } + } + // Set kind to 303 (SyntaxKind.SourceFile in TypeScript) + // for all TopLevels currently + for (topLevelDO in TopLevelDO(__all_data__)) { + if (topLevelDO.key_eq(self)) { + return 303 + } + } + } + + /** + * Gets the parent oid of this node. + */ + pub fn getParentOid(self) -> int { + for (nodeDO in NodeDO(__all_data__)) { + if (nodeDO.key_eq(self)) { + return nodeDO.getParentOid() + } + } + } + + /** + * Gets the parent node of this node. + */ + pub fn getParent(self) -> Node { + let (parent = Node {id: self.getParentOid()}) { + return parent + } + } + + pub fn getIndex(self) -> int { + for (nodeDO in NodeDO(__all_data__)) { + if (nodeDO.key_eq(self)) { + return nodeDO.getIndex() + } + } + } + + /** + * Gets the location of this node. + */ + pub fn getLocation(self) -> Location { + for (nodeDO in NodeDO(__all_data__)) { + if (nodeDO.key_eq(self)) { + for (location in Location(__all_data__)) { + if (location.oid = nodeDO.getLocationOid()) { + return location + } + } + } + } + for (topLevelDO in TopLevelDO(__all_data__)) { + if (topLevelDO.key_eq(self)) { + for (location in Location(__all_data__)) { + if (location.oid = topLevelDO.getLocationOid()) { + return location + } + } + } + } + } + + /** + * Gets the file of this node. + */ + pub fn getFile(self) -> File { + let (location = self.getLocation()) { + return location.getFile() + } + } + + /** + * Gets the relative path of this node. + */ + pub fn getRelativePath(self) -> string { + let (file = self.getFile()) { + return file.getRelativePath() + } + } + + pub fn getStartLineNumber(self) -> int { + let (location = self.getLocation()) { + return location.getStartLineNumber() + } + } + + pub fn getStartColumnNumber(self) -> int { + let (location = self.getLocation()) { + return location.getStartColumnNumber() + } + } + + pub fn getEndLineNumber(self) -> int { + let (location = self.getLocation()) { + return location.getEndLineNumber() + } + } + + pub fn getEndColumnNumber(self) -> int { + let (location = self.getLocation()) { + return location.getEndColumnNumber() + } + } + + /** + * Gets a child node of this node. + */ + pub fn getAChild(self) -> *Node { + for (child in Node(__all_data__)) { + if (child.getParent() = self) { + yield child + } + } + } + + /** + * Gets the `i`th child of this node. + */ + pub fn getChild(self, i: int) -> Node { + for (child in Node(__all_data__)) { + if (child.getParent() = self) { + if (child.getIndex() = i) { + return child + } + } + } + } + + /** + * Gets the number of child nodes. + */ + pub fn getChildCount(self) -> int { + return self.getAChild().len() + } + + /** + * Gets the last child of this node parent. + */ + pub fn getLastChild(self) -> Node { + let (childCount = self.getChildCount()) { + return self.getChild(childCount - 1) + } + } + + /** + * Gets an ancestor of this node. + */ + pub fn getAnAncestor(self) -> *Node { + let (ancestor = self.getParent()) { + yield ancestor + } + let (parent = self.getParent()) { + for (ancestor in parent.getAnAncestor()) { + yield ancestor + } + } + } + + /** + * Gets the root top-level of this node. + */ + pub fn getRoot(self) -> TopLevelDO { + for (ancestor in self.getAnAncestor()) { + for (root in TopLevelDO(__all_data__)) { + if (root.key_eq(ancestor)) { + return root + } + } + } + } + + /** + * Gets an ancestor of this node by the level of the hierarchy. + * + * @param level: the number of levels to go up in the hierarchy. + */ + pub fn getAnAncestorByLevel(self, level: int) -> Node { + let (ancestor = self.getParent()) { + if (level = 1) { + return ancestor + } + } + let (parent = self.getParent()) { + for (parentLevel in int::__undetermined_all__()) { + let (ancestor = parent.getAnAncestorByLevel(parentLevel)) { + if (level = parentLevel + 1) { + return ancestor + } + } + } + } + } + + /** + * Gets a descendant of this node. + */ + pub fn getADescendant(self) -> *Node { + for (descendant in self.getAChild()) { + yield descendant + } + for (child in self.getAChild()) { + for (descendant in child.getADescendant()) { + yield descendant + } + } + } + + /** + * Gets a descendant of this node by the level of the hierarchy. + * + * @param level: the number of levels to go up in the hierarchy. + */ + pub fn getADescendantByLevel(self, level: int) -> *Node { + if (level = 1) { + yield self.getAChild() + } + for (child in self.getAChild()) { + for (childLevel in int::__undetermined_all__()) { + for (descendant in child.getADescendantByLevel(childLevel)) { + if (level = childLevel + 1) { + yield descendant + } + } + } + } + } + + /** + * Gets the enclosing function of it + */ + pub fn getEnclosingFunction(self) -> FunctionLikeDeclaration { + for (function in FunctionLikeDeclaration(__all_data__), + functionEnclosingNode in FunctionEnclosingNodeDO(__all_data__)) { + if (functionEnclosingNode.getFunctionOid() = function.id) { + if (functionEnclosingNode.key_eq(self)) { + return function + } + } + } + } + + /** + * Gets an ancestor enclosing function of it + */ + pub fn getAnAncestorEnclosingFunction(self) -> *FunctionLikeDeclaration { + for (anEnclosingFunction in FunctionLikeDeclaration(__all_data__), + anEnclosingNode in FunctionEnclosingNodeDO(__all_data__)) { + if (anEnclosingNode.getFunctionOid() = anEnclosingFunction.id) { + if (anEnclosingNode.key_eq(self)) { + yield anEnclosingFunction + } + } + for (enclosingFunction in FunctionLikeDeclaration(__all_data__), + enclosingNode in FunctionEnclosingNodeDO(__all_data__)) { + if (enclosingNode.getFunctionOid() = enclosingFunction.id) { + if (enclosingNode.key_eq(self)) { + for (auto_tmp1 in enclosingFunction.getAnAncestorEnclosingFunction()) { + if (anEnclosingFunction = auto_tmp1) { + yield anEnclosingFunction + } + } + } + } + } + } + } + + /** + * Gets the leading comments of it + */ + pub fn getALeadingComment(self) -> *Comment { + for (comment in Comment(__all_data__), + nodeComment in NodeCommentDO(__all_data__)) { + if (nodeComment.getNodeOid() = self.id) { + if (nodeComment.getCommentOid() = comment.oid) { + // Leading + if (nodeComment.getType() = 0) { + yield comment + } + } + } + } + } + + /** + * Gets the trailing comments of it + */ + pub fn getATrailingComment(self) -> *Comment { + for (comment in Comment(__all_data__), + nodeComment in NodeCommentDO(__all_data__)) { + if (nodeComment.getNodeOid() = self.id) { + if (nodeComment.getCommentOid() = comment.oid) { + // Trailing + if (nodeComment.getType() = 1) { + yield comment + } + } + } + } + } + + /** + * Gets the comments related to it + */ + pub fn getAComment(self) -> *Comment { + for (comment in Comment(__all_data__), + nodeComment in NodeCommentDO(__all_data__)) { + if (nodeComment.getNodeOid() = self.id) { + if (nodeComment.getCommentOid() = comment.oid) { + yield comment + } + } + } + } + + /** + * Gets the text of this node. + */ + pub fn getText(self) -> string { + for (text in string::__undetermined_all__()) { + for (location in Location(__all_data__)) { + if (location = self.getLocation()) { + if (text = location.getText()) { + return text + } + } + } + } + } + + /** + * Gets the symbol associated with this node. + */ + pub fn getSymbol(self) -> Symbol { + for (symbol in Symbol(__all_data__), + nodeSymbol in NodeSymbolDO(__all_data__)) { + if (nodeSymbol.key_eq(self)) { + if (symbol.oid = nodeSymbol.getSymbolOid()) { + return symbol + } + } + } + } + + /** + * Gets a decorator. + */ + pub fn getADecorator(self) -> *Decorator { + for (decorator in Decorator(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (decorator.key_eq(auto_tmp1)) { + yield decorator + } + } + } + } + + /** + * Gets the `i`th decorator. + */ + pub fn getDecorator(self, i: int) -> Decorator { + for (decorator in Decorator(__all_data__)) { + if (decorator.key_eq(self.getChild(i))) { + return decorator + } + } + } + + /** + * Gets a modifier. + */ + pub fn getAModifier(self) -> *Modifier { + for (modifier in Modifier(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (modifier.key_eq(auto_tmp1)) { + yield modifier + } + } + } + } + + /** + * Gets the `i`th modifier. + */ + pub fn getModifier(self, i: int) -> Modifier { + for (modifier in Modifier(__all_data__), + modifierDO in ModifierDO(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (modifier.key_eq(auto_tmp1)) { + if (modifierDO.key_eq(modifier)) { + if (modifierDO.getIndex() = i) { + return modifier + } + } + } + } + } + } +} diff --git a/language/javascript/lib/NumberOfLines.gdl b/language/javascript/lib/NumberOfLines.gdl new file mode 100644 index 00000000..ef3f0df6 --- /dev/null +++ b/language/javascript/lib/NumberOfLines.gdl @@ -0,0 +1,25 @@ +/** + * @filename: Statement + * @brief: Provides classes and predicates for working with the number of JavaScript / TypeScript lines. + */ + +/** + * A number-of-lines object for a location, including the number of lines, lines of code and lines of comments. + */ +schema NumberOfLines extends NumberOfLinesDO { +} + +impl NumberOfLines { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NumberOfLines { + for (tmp in NumberOfLinesDO(db)) { + yield NumberOfLines { + location_oid : tmp.location_oid, + lines : tmp.lines, + code_lines : tmp.code_lines, + comment_lines : tmp.comment_lines + } + } + } +} diff --git a/language/javascript/lib/ObjectLiteral.gdl b/language/javascript/lib/ObjectLiteral.gdl new file mode 100644 index 00000000..3415bdf2 --- /dev/null +++ b/language/javascript/lib/ObjectLiteral.gdl @@ -0,0 +1,444 @@ +/** + * @filename: ObjectLiteral + * @brief: Provides classes and predicates for working with JavaScript / TypeScript object literals. + */ + +/** + * An object literal expression. + */ +schema ObjectLiteralExpression extends PrimaryExpression { +} + +impl ObjectLiteralExpression { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ObjectLiteralExpression { + for (tmp in PrimaryExpression(db)) { + if (isObjectLiteralExpression(Node {id: tmp.id})) { + yield ObjectLiteralExpression { + id : tmp.id + } + } + } + } + + /** + * Get a property, which is an ObjectLiteralElement. + */ + pub fn getAProperty(self) -> *ObjectLiteralElement { + for (objectLiteralElement in ObjectLiteralElement(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (objectLiteralElement.key_eq(auto_tmp1)) { + yield objectLiteralElement + } + } + } + } + + /** + * Get the `i`th property. + */ + pub fn getProperty(self, i: int) -> ObjectLiteralElement { + for (objectLiteralElement in ObjectLiteralElement(__all_data__)) { + if (objectLiteralElement.key_eq(self.getChild(i))) { + return objectLiteralElement + } + } + } + + /** + * Get the property of this ObjectLiteralExpression by name. + */ + pub fn getPropertyByName(self, name: string) -> ObjectLiteralElement { + for (objectLiteralElement in ObjectLiteralElement(__all_data__)) { + if (objectLiteralElement.getParent().key_eq(self)) { + if (objectLiteralElement.getName() = name) { + return objectLiteralElement + } + } + } + } + + /** + * Determine whether this ObjectLiteralExpression has a property with the specified name. + */ + pub fn hasProperty(self, name: string) -> bool { + for (objectLiteralElement in ObjectLiteralElement(__all_data__)) { + if (objectLiteralElement = self.getPropertyByName(name)) { + return true + } + } + } + + /** + * Get the PropertyAssignment of this ObjectLiteralExpression by name. + */ + pub fn getPropertyAssignmentByName(self, name: string) -> PropertyAssignment { + for (propertyAssignment in PropertyAssignment(__all_data__)) { + if (propertyAssignment.getParent() = self) { + if (propertyAssignment.getName() = name) { + return propertyAssignment + } + } + } + } +} + +/** + * An object literal element. + */ +schema ObjectLiteralElement extends Node { +} + +impl ObjectLiteralElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ObjectLiteralElement { + for (tmp in Node(db)) { + if (isObjectLiteralElement(tmp)) { + yield ObjectLiteralElement { + id : tmp.id + } + } + } + } + + /** + * Gets the name of this ObjectLiteralElement. + * + * A SpreadAssignment doesn't have a name. + * TODO: add handling for Accessors. + */ + pub fn getName(self) -> string { + for (propertyAssignment in PropertyAssignment(__all_data__)) { + if (propertyAssignment.key_eq(self)) { + let (name = propertyAssignment.getName()) { + return name + } + } + } + for (shorthandPropertyAssignment in ShorthandPropertyAssignment(__all_data__)) { + if (shorthandPropertyAssignment.key_eq(self)) { + let (name = shorthandPropertyAssignment.getName()) { + return name + } + } + } + for (methodDeclaration in MethodDeclaration(__all_data__)) { + if (methodDeclaration.key_eq(self)) { + let (name = methodDeclaration.getName()) { + return name + } + } + } + } +} + +/** + * A computed property name. + */ +schema ComputedPropertyName extends Node { +} + +impl ComputedPropertyName { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ComputedPropertyName { + for (tmp in Node(db)) { + if (isComputedPropertyName(tmp)) { + yield ComputedPropertyName { + id : tmp.id + } + } + } + } + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A property name. + */ +schema PropertyName extends Node { +} + +impl PropertyName { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PropertyName { + for (tmp in Node(db)) { + if (isPropertyName(tmp)) { + yield PropertyName { + id : tmp.id + } + } + } + } + + /** + * Gets the name of this PropertyName. + * + * If this PropertyName is a ComputedPropertyName, it doesn't have a name + */ + pub fn getName(self) -> string { + if (isIdentifier(Node {id: self.id})) { + let (name = self.getText()) { + return name + } + } + if (isPrivateIdentifier(Node {id: self.id})) { + let (name = self.getText()) { + return name + } + } + // StringLiteral or NumericLiteral + for (literalExpression in LiteralExpression(__all_data__)) { + if (literalExpression.key_eq(self)) { + let (name = literalExpression.getValue()) { + return name + } + } + } + } +} + +/** + * A property assignment. + * + * TODO: handle decorators and modifiers + */ +schema PropertyAssignment extends ObjectLiteralElement { +} + +impl PropertyAssignment { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PropertyAssignment { + for (tmp in ObjectLiteralElement(db)) { + if (isPropertyAssignment(Node {id: tmp.id})) { + yield PropertyAssignment { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> ObjectLiteralExpression { + for (parent in ObjectLiteralExpression(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + pub fn getPropertyName(self) -> PropertyName { + for (propertyName in PropertyName(__all_data__)) { + if (propertyName.key_eq(self.getChild(0))) { + return propertyName + } + } + } + + pub fn getNameNode(self) -> PropertyName { + for (nameNode in PropertyName(__all_data__)) { + if (nameNode.key_eq(self.getChild(0))) { + return nameNode + } + } + } + + pub fn getName(self) -> string { + return self.getPropertyName().getName() + } + + pub fn getInitializer(self) -> Expression { + for (initializer in Expression(__all_data__)) { + if (initializer.key_eq(self.getChild(1))) { + return initializer + } + } + } +} + +/** + * A shorthand property assignment. + * + * TODO: handle decorators and modifiers + */ +schema ShorthandPropertyAssignment extends ObjectLiteralElement { +} + +impl ShorthandPropertyAssignment { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ShorthandPropertyAssignment { + for (tmp in ObjectLiteralElement(db)) { + if (isShorthandPropertyAssignment(Node {id: tmp.id})) { + yield ShorthandPropertyAssignment { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> ObjectLiteralExpression { + for (parent in ObjectLiteralExpression(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + pub fn getIdentifier(self) -> Identifier { + for (identifier in Identifier(__all_data__)) { + if (identifier.key_eq(self.getChild(0))) { + return identifier + } + } + } + + pub fn getNameNode(self) -> Identifier { + for (identifier in Identifier(__all_data__)) { + if (identifier.key_eq(self.getChild(0))) { + return identifier + } + } + } + + pub fn getName(self) -> string { + return self.getIdentifier().getName() + } + + /** + * Gets the value symbol associated with this shorthand property assignment. + */ + pub fn getValueSymbol(self) -> Symbol { + for (symbol in Symbol(__all_data__), + shorthandAssignmentValueSymbolDO in ShorthandAssignmentValueSymbolDO(__all_data__)) { + if (shorthandAssignmentValueSymbolDO.key_eq(self)) { + if (symbol.oid = shorthandAssignmentValueSymbolDO.getSymbolOid()) { + return symbol + } + } + } + } +} + +/** + * A spread assignment. + */ +schema SpreadAssignment extends ObjectLiteralElement { +} + +impl SpreadAssignment { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SpreadAssignment { + for (tmp in ObjectLiteralElement(db)) { + if (isSpreadAssignment(Node {id: tmp.id})) { + yield SpreadAssignment { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> ObjectLiteralExpression { + for (parent in ObjectLiteralExpression(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * Determines whether a node is a property assignment. + */ +pub fn isPropertyAssignment(node: Node) -> bool { + if (node.getKind() = 294) { + return true + } +} + +/** + * Determines whether a node is a shorthand property assignment. + */ +pub fn isShorthandPropertyAssignment(node: Node) -> bool { + if (node.getKind() = 295) { + return true + } +} + +/** + * Determines whether a node is a spread assignment. + */ +pub fn isSpreadAssignment(node: Node) -> bool { + if (node.getKind() = 296) { + return true + } +} + +/** + * Determines whether a node is an object literal element. + */ +pub fn isObjectLiteralElement(node: Node) -> bool { + if (isPropertyAssignment(node)) { + return true + } + if (isShorthandPropertyAssignment(node)) { + return true + } + if (isSpreadAssignment(node)) { + return true + } + if (isMethodDeclaration(node)) { + return true + } + if (isAccessor(node)) { + return true + } +} + +/** + * Determines whether a node is a computed property name. + */ +pub fn isComputedPropertyName(node: Node) -> bool { + if (node.getKind() = 161) { + return true + } +} + +/** + * Determines whether a node is a property name. + */ +pub fn isPropertyName(node: Node) -> bool { + if (isIdentifier(node)) { + return true + } + if (isStringLiteral(node)) { + return true + } + if (isNumericLiteral(node)) { + return true + } + if (isComputedPropertyName(node)) { + return true + } + if (isPrivateIdentifier(node)) { + return true + } +} diff --git a/language/javascript/lib/Statement.gdl b/language/javascript/lib/Statement.gdl new file mode 100644 index 00000000..07819881 --- /dev/null +++ b/language/javascript/lib/Statement.gdl @@ -0,0 +1,2093 @@ +/** + * @filename: Statement + * @brief: Provides classes and predicates for working with JavaScript / TypeScript statements + */ + +/** + * The base class for all statements + */ +schema Statement extends Node { +} + +impl Statement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Statement { + for (tmp in Node(db)) { + if (isStatement(tmp)) { + yield Statement { + id : tmp.id + } + } + } + } +} + +/** + * A declaration statement + */ +schema DeclarationStatement extends Statement { +} + +impl DeclarationStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DeclarationStatement { + for (tmp in Statement(db)) { + if (isDeclarationStatement(Node {id: tmp.id})) { + yield DeclarationStatement { + id : tmp.id + } + } + } + } +} + +/** + * A statement but not declaration + */ +schema StatementButNotDeclaration extends Statement { +} + +impl StatementButNotDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *StatementButNotDeclaration { + for (tmp in Statement(db)) { + if (isStatementButNotDeclaration(Node {id: tmp.id})) { + yield StatementButNotDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A block of statements. + */ +schema BlockStatement extends Statement { +} + +impl BlockStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BlockStatement { + for (tmp in Statement(db)) { + if (isBlockStatement(Node {id: tmp.id})) { + yield BlockStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the `i`th statement in this block. + */ + pub fn getStatement(self, i: int) -> Statement { + for (statement in Statement(__all_data__)) { + if (statement.key_eq(self.getChild(i))) { + return statement + } + } + } + + /** + * Gets a statement in this block. + */ + pub fn getAStatement(self) -> *Statement { + for (statement in Statement(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (statement.key_eq(auto_tmp1)) { + yield statement + } + } + } + } + + /** + * Gets the number of statements in this block. + */ + pub fn getStatementCount(self) -> int { + return self.getAStatement().len() + } +} + +/** + * An empty statement. + */ +schema EmptyStatement extends Statement { +} + +impl EmptyStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EmptyStatement { + for (tmp in Statement(db)) { + if (tmp.getKind() = 235) { + yield EmptyStatement { + id : tmp.id + } + } + } + } +} + +/** + * A variable declaration statement, that is, a `var`, `const` or `let` declaration + */ +schema VariableStatement extends Statement { +} + +impl VariableStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *VariableStatement { + for (tmp in Statement(db)) { + if (isVariableStatement(Node {id: tmp.id})) { + yield VariableStatement { + id : tmp.id + } + } + } + } + + /** + * VariableStatement contains a VariableDeclarationList, get that list + */ + pub fn getVariableDeclarationList(self) -> VariableDeclarationList { + for (vdl in VariableDeclarationList(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (vdl.key_eq(auto_tmp1)) { + return vdl + } + } + } + } +} + +/** + * An expression statement + */ +schema ExpressionStatement extends Statement { +} + +impl ExpressionStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExpressionStatement { + for (tmp in Statement(db)) { + if (isExpressionStatement(Node {id: tmp.id})) { + yield ExpressionStatement { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> Expression { + for (expr in Expression(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (expr.key_eq(auto_tmp1)) { + return expr + } + } + } + } +} + +/** + * An `if` statement + */ +schema IfStatement extends Statement { +} + +impl IfStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IfStatement { + for (tmp in Statement(db)) { + if (isIfStatement(Node {id: tmp.id})) { + yield IfStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the condition of this `if` statement. + */ + pub fn getCondition(self) -> Expression { + for (condition in Expression(__all_data__)) { + if (condition.key_eq(self.getChild(0))) { + return condition + } + } + } + + /** + * Gets the "then" branch of this `if` statement. + */ + pub fn getThen(self) -> Statement { + for (thenStatement in Statement(__all_data__)) { + if (thenStatement.key_eq(self.getChild(1))) { + return thenStatement + } + } + } + + /** + * Gets the "else" branch of this `if` statement, if any. + */ + pub fn getElse(self) -> Statement { + for (elseStatement in Statement(__all_data__)) { + if (elseStatement.key_eq(self.getChild(2))) { + return elseStatement + } + } + } + + /** + * Determine this IfStatement has else expr. + */ + pub fn hasElse(self) -> bool { + for (elseNode in Node(__all_data__)) { + if (elseNode.key_eq(self.getElse())) { + return true + } + } + } +} + +/** + * A `do`-`while` loop. + */ +schema DoWhileStatement extends Statement { +} + +impl DoWhileStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DoWhileStatement { + for (tmp in Statement(db)) { + if (isDoWhileStatement(Node {id: tmp.id})) { + yield DoWhileStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the loop condition of this `do`-`while` loop. + */ + pub fn getCondition(self) -> Expression { + for (condition in Expression(__all_data__)) { + if (condition.key_eq(self.getChild(1))) { + return condition + } + } + } + + /** + * Gets the body of this `do`-`while` loop. + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__)) { + if (body.key_eq(self.getChild(0))) { + return body + } + } + } +} + +/** + * A `while` loop. + */ +schema WhileStatement extends Statement { +} + +impl WhileStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *WhileStatement { + for (tmp in Statement(db)) { + if (isWhileStatement(Node {id: tmp.id})) { + yield WhileStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the loop condition of this `while` loop. + */ + pub fn getCondition(self) -> Expression { + for (condition in Expression(__all_data__)) { + if (condition.key_eq(self.getChild(0))) { + return condition + } + } + } + + /** + * Gets the body of this `while` loop. + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__)) { + if (body.key_eq(self.getChild(1))) { + return body + } + } + } +} + +/** + * A `for` initializer. + */ +schema ForInitializer extends Node { +} + +impl ForInitializer { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ForInitializer { + for (tmp in Node(db)) { + if (isForInitializer(tmp)) { + yield ForInitializer { + id : tmp.id + } + } + } + } +} + +/** + * A `for` loop. + */ +schema ForStatement extends Statement { +} + +impl ForStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ForStatement { + for (tmp in Statement(db)) { + if (isForStatement(Node {id: tmp.id})) { + yield ForStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the initializer index of this for loop. + */ + pub fn getInitializerIndex(self) -> int { + return 0 + } + + /** + * Gets the Initializer of this `for` loop. + */ + pub fn getInitializer(self) -> ForInitializer { + for (initializer in ForInitializer(__all_data__)) { + let (initializerIndex = self.getInitializerIndex()) { + if (initializer.key_eq(self.getChild(initializerIndex))) { + return initializer + } + } + } + } + + /** + * Determine this ForStatement has initializer expr. + */ + pub fn hasInitializer(self) -> bool { + for (initializer in ForInitializer(__all_data__)) { + if (initializer = self.getInitializer()) { + return true + } + } + } + + /** + * Gets the boolean condition of this `for` loop. + */ + pub fn getCondition(self) -> Expression { + for (condition in Expression(__all_data__)) { + if (condition.key_eq(self.getChild(1))) { + return condition + } + } + } + + /** + * Determine this ForStatement has condition expr. + */ + pub fn hasCondition(self) -> bool { + for (condition in Expression(__all_data__)) { + if (condition = self.getCondition()) { + return true + } + } + } + + /** + * Gets the incrementor of this `for` loop. + */ + pub fn getIncrementor(self) -> Expression { + for (update in Expression(__all_data__)) { + if (update.key_eq(self.getChild(2))) { + return update + } + } + } + + /** + * Determine this ForStatement has incrementor expr. + */ + pub fn hasIncrementor(self) -> bool { + for (incrementor in Expression(__all_data__)) { + if (incrementor = self.getIncrementor()) { + return true + } + } + } + + /** + * Gets the body of this `for` loop. + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__)) { + if (body.key_eq(self.getChild(3))) { + return body + } + } + } +} + +/** + * A `for`-`in` or `for`-`of` loop. + */ +schema EnhancedForStatement extends Statement { +} + +impl EnhancedForStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EnhancedForStatement { + for (tmp in Statement(db)) { + if (isEnhancedForStatement(Node {id: tmp.id})) { + yield EnhancedForStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the iterator index of this loop. + * + * In a `for`-`in` loop, the index is always 0. + * In a `for`-`of` loop, the index is 1 if it is a `for`-`await`-`of`, otherwise, the index is 0. + */ + pub fn getInitializerIndex(self) -> int { + for (index in int::__undetermined_all__()) { + for (enhancedForStatement in EnhancedForStatement(__all_data__), + firstChildNode in Node(__all_data__)) { + if (self = enhancedForStatement) { + if (firstChildNode = self.getChild(0)) { + if (isAwaitKeyword(firstChildNode)) { + if (index = 1) { + return index + } + } + if (!isAwaitKeyword(firstChildNode)) { + if (index = 0) { + return index + } + } + } + } + } + } + } + + /** + * Gets the iterator of this `for`-`in` or `for`-`of` loop. + */ + pub fn getInitializer(self) -> ForInitializer { + for (iterator in Node(__all_data__)) { + let (initializerIndex = self.getInitializerIndex()) { + if (iterator = self.getChild(initializerIndex)) { + return ForInitializer(__all_data__).find(iterator) + } + } + } + } + + /** + * Gets the expression over which this `for`-`in` or `for`-`of` loop iterates. + */ + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + let (initializerIndex = self.getInitializerIndex()) { + if (expression.key_eq(self.getChild(initializerIndex + 1))) { + return expression + } + } + } + } + + /** + * Gets the body of this `for`-`in` or `for`-`of` loop. + */ + pub fn getBody(self) -> Statement { + for (body in Statement(__all_data__)) { + let (initializerIndex = self.getInitializerIndex()) { + if (body.key_eq(self.getChild(initializerIndex + 2))) { + return body + } + } + } + } +} + +/** + * A `for`-`in` loop. + */ +schema ForInStatement extends EnhancedForStatement { +} + +impl ForInStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ForInStatement { + for (tmp in EnhancedForStatement(db)) { + if (isForInStatement(Node {id: tmp.id})) { + yield ForInStatement { + id : tmp.id + } + } + } + } +} + +/** + * A `for`-`of` loop. + */ +schema ForOfStatement extends EnhancedForStatement { +} + +impl ForOfStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ForOfStatement { + for (tmp in EnhancedForStatement(db)) { + if (isForOfStatement(Node {id: tmp.id})) { + yield ForOfStatement { + id : tmp.id + } + } + } + } + + /** + * Determines whether the `for`-`of` loop is a `for`-`await`-`of` loop + */ + pub fn isAwait(self) -> bool { + for (awaitKeyword in AwaitKeyword(__all_data__)) { + if (awaitKeyword.key_eq(self.getChild(0))) { + return true + } + } + } +} + +/** + * An iteration statement, including `while`, `do`-`while`, + * `for` and enhanced `for` (`for`-`in`, `for`-`of`) statements. + */ +schema IterationStatement extends Statement { +} + +impl IterationStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IterationStatement { + for (tmp in Statement(db)) { + if (isIterationStatement(Node {id: tmp.id})) { + yield IterationStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the body statement of this iteration statement. + */ + pub fn getBody(self) -> Statement { + for (whileStatement in WhileStatement(__all_data__)) { + if (whileStatement.key_eq(self)) { + let (body = whileStatement.getBody()) { + return body + } + } + } + for (doWhileStatement in DoWhileStatement(__all_data__)) { + if (doWhileStatement.key_eq(self)) { + let (body = doWhileStatement.getBody()) { + return body + } + } + } + for (forStatement in ForStatement(__all_data__)) { + if (forStatement.key_eq(self)) { + let (body = forStatement.getBody()) { + return body + } + } + } + for (enhancedForStatement in EnhancedForStatement(__all_data__)) { + if (enhancedForStatement.key_eq(self)) { + let (body = enhancedForStatement.getBody()) { + return body + } + } + } + } + + /** + * Gets the condition expression of this iteration statement. + * Only a `while`, `do`-`while` and `for` statement has a condition. + */ + pub fn getCondition(self) -> Expression { + for (whileStatement in WhileStatement(__all_data__)) { + if (whileStatement.key_eq(self)) { + let (condition = whileStatement.getCondition()) { + return condition + } + } + } + for (doWhileStatement in DoWhileStatement(__all_data__)) { + if (doWhileStatement.key_eq(self)) { + let (condition = doWhileStatement.getCondition()) { + return condition + } + } + } + for (forStatement in ForStatement(__all_data__)) { + if (forStatement.key_eq(self)) { + let (condition = forStatement.getCondition()) { + return condition + } + } + } + } +} + +/** + * A `continue` statement + */ +schema ContinueStatement extends Statement { +} + +impl ContinueStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ContinueStatement { + for (tmp in Statement(db)) { + if (isContinueStatement(Node {id: tmp.id})) { + yield ContinueStatement { + id : tmp.id + } + } + } + } +} + +/** + * A `break` statement + */ +schema BreakStatement extends Statement { +} + +impl BreakStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BreakStatement { + for (tmp in Statement(db)) { + if (isBreakStatement(Node {id: tmp.id})) { + yield BreakStatement { + id : tmp.id + } + } + } + } +} + +/** + * A `return` statement + */ +schema ReturnStatement extends Statement { +} + +impl ReturnStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ReturnStatement { + for (tmp in Statement(db)) { + if (isReturnStatement(Node {id: tmp.id})) { + yield ReturnStatement { + id : tmp.id + } + } + } + } + + /** + * Get the expression that specifies the returned value, if any. + */ + pub fn getExpression(self) -> Expression { + for (returnExpression in Expression(__all_data__)) { + if (returnExpression.key_eq(self.getChild(0))) { + return returnExpression + } + } + } +} + +/** + * A `with` statement + */ +schema WithStatement extends Statement { +} + +impl WithStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *WithStatement { + for (tmp in Statement(db)) { + if (isWithStatement(Node {id: tmp.id})) { + yield WithStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the expression belong to the WithStatement. + * Each WithStatement contains one and only one expression. + */ + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + + /** + * Gets the statement belong to the WithStatement. + * Each WithStatement contains one and only one statement, + * Multiple statements should be grounded by a BlockStatement. + */ + pub fn getStatement(self) -> Statement { + for (statement in Statement(__all_data__)) { + if (statement.key_eq(self.getChild(1))) { + return statement + } + } + } +} + +/** + * A function declaration statement. + */ +schema FunctionDeclarationStatement extends DeclarationStatement { +} + +impl FunctionDeclarationStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FunctionDeclarationStatement { + for (tmp in DeclarationStatement(db)) { + if (isFunctionDeclaration(Node {id: tmp.id})) { + yield FunctionDeclarationStatement { + id : tmp.id + } + } + } + } +} + +/** + * A class declaration statement. + */ +schema ClassDeclarationStatement extends DeclarationStatement { +} + +impl ClassDeclarationStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ClassDeclarationStatement { + for (tmp in DeclarationStatement(db)) { + if (isClassDeclaration(Node {id: tmp.id})) { + yield ClassDeclarationStatement { + id : tmp.id + } + } + } + } +} + +/** + * An interface declaration. + */ +schema InterfaceDeclaration extends DeclarationStatement { +} + +impl InterfaceDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *InterfaceDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isInterfaceDeclaration(Node {id: tmp.id})) { + yield InterfaceDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A type alias declaration. + */ +schema TypeAliasDeclaration extends DeclarationStatement { +} + +impl TypeAliasDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeAliasDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isTypeAliasDeclaration(Node {id: tmp.id})) { + yield TypeAliasDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * An enum declaration. + */ +schema EnumDeclaration extends DeclarationStatement { +} + +impl EnumDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EnumDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isEnumDeclaration(Node {id: tmp.id})) { + yield EnumDeclaration { + id : tmp.id + } + } + } + } + + /** + * Gets the identifier this EnumDeclaration. + */ + pub fn getIdentifier(self) -> Identifier { + for (identifier in Identifier(__all_data__)) { + if (identifier.key_eq(self.getChild(0))) { + return identifier + } + } + } + + /** + * Gets a EnumMember of this EnumDeclaration. + */ + pub fn getAEnumMember(self) -> *EnumMember { + for (enumMember in EnumMember(__all_data__)) { + if (self = enumMember.getParent()) { + yield enumMember + } + } + } + + /** + * Gets the EnumMember with index, start from 0. + */ + pub fn getEnumMember(self, index: int) -> EnumMember { + for (childIndex in int::__undetermined_all__()) { + for (enumMember in EnumMember(__all_data__)) { + if (index = childIndex - 1) { + if (enumMember.key_eq(self.getChild(childIndex))) { + return enumMember + } + } + } + } + } + + /** + * Gets the count of EnumMember. + */ + pub fn getEnumMemberCount(self) -> int { + return self.getAEnumMember().len() + } +} + +/** + * A module declaration. + */ +schema ModuleDeclaration extends DeclarationStatement { +} + +impl ModuleDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ModuleDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isModuleDeclaration(Node {id: tmp.id})) { + yield ModuleDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A namespace export declaration. + */ +schema NamespaceExportDeclaration extends DeclarationStatement { +} + +impl NamespaceExportDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NamespaceExportDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isNamespaceExportDeclaration(Node {id: tmp.id})) { + yield NamespaceExportDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * An import-equals declaration. + */ +schema ImportEqualsDeclaration extends DeclarationStatement { +} + +impl ImportEqualsDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ImportEqualsDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isImportEqualsDeclaration(Node {id: tmp.id})) { + yield ImportEqualsDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * An import declaration. + */ +schema ImportDeclaration extends DeclarationStatement { +} + +impl ImportDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ImportDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isImportDeclaration(Node {id: tmp.id})) { + yield ImportDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * An export assignment. + */ +schema ExportAssignment extends DeclarationStatement { +} + +impl ExportAssignment { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExportAssignment { + for (tmp in DeclarationStatement(db)) { + if (isExportAssignment(Node {id: tmp.id})) { + yield ExportAssignment { + id : tmp.id + } + } + } + } +} + +/** + * An export declaration. + */ +schema ExportDeclaration extends DeclarationStatement { +} + +impl ExportDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExportDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isExportDeclaration(Node {id: tmp.id})) { + yield ExportDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A missing declaration. + */ +schema MissingDeclaration extends DeclarationStatement { +} + +impl MissingDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MissingDeclaration { + for (tmp in DeclarationStatement(db)) { + if (isMissingDeclaration(Node {id: tmp.id})) { + yield MissingDeclaration { + id : tmp.id + } + } + } + } + + pub fn getName(self) -> Identifier { + for (identifier in Identifier(__all_data__)) { + if (self.key_eq(identifier.getParent())) { + return identifier + } + } + } + + pub fn haveName(self) -> bool { + for (identifier in Identifier(__all_data__)) { + if (identifier = self.getName()) { + return true + } + } + } +} + +/** + * A `case` clause. + */ +schema CaseClause extends Statement { +} + +impl CaseClause { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CaseClause { + for (tmp in Statement(db)) { + if (isCaseClause(Node {id: tmp.id})) { + yield CaseClause { + id : tmp.id + } + } + } + } + + /** + * Gets the expression of this CaseClause. + */ + pub fn getExpression(self) -> Expression { + return self.getChild(0).to() + } + + /** + * Gets the statement of this CaseClause with index, + * starts from 0. + */ + pub fn getStatement(self, index: int) -> Statement { + for (childIndex in int::__undetermined_all__()) { + if (index = childIndex - 1) { + return self.getChild(childIndex).to() + } + } + } + + /** + * Gets a statement of this CaseClause. + */ + pub fn getAStatement(self) -> *Statement { + for (i in int::__undetermined_all__()) { + yield self.getStatement(i) + } + } + + /** + * Gets the statement count of this CaseClause. + */ + pub fn getStatementCount(self) -> int { + return self.getAStatement().len() + } +} + +/** + * A `default` clause. + */ +schema DefaultClause extends Statement { +} + +impl DefaultClause { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DefaultClause { + for (tmp in Statement(db)) { + if (isDefaultClause(Node {id: tmp.id})) { + yield DefaultClause { + id : tmp.id + } + } + } + } + + /** + * Gets the statement of this DefaultClause with index, + * starts from 0. + */ + pub fn getStatement(self, index: int) -> Statement { + for (statement in Statement(__all_data__)) { + if (statement.key_eq(self.getChild(index))) { + return statement + } + } + } + + /** + * Gets a statement of this DefaultClause. + */ + pub fn getAStatement(self) -> *Statement { + yield self.getStatement(__all_data__) + } + + /** + * Gets the statement count of this DefaultClause. + */ + pub fn getStatementCount(self) -> int { + return self.getAStatement().len() + } +} + +schema CatchClause extends Statement { +} + +impl CatchClause { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CatchClause { + for (tmp in Statement(db)) { + if (isCatchClause(Node {id: tmp.id})) { + yield CatchClause { + id : tmp.id + } + } + } + } + + /** + * Gets the variable declaration of this CatchClause. + */ + pub fn getVariableDeclaration(self) -> VariableDeclaration { + for (variableDeclaration in VariableDeclaration(__all_data__)) { + if (self.key_eq(variableDeclaration)) { + return variableDeclaration + } + } + } + + /** + * Determine this CatchClause has variable declaration or not. + */ + pub fn haveVariableDeclaration(self) -> bool { + for (variableDeclaration in VariableDeclaration(__all_data__)) { + if (variableDeclaration = self.getVariableDeclaration()) { + return true + } + } + } + + /** + * Gets the catch block of this CatchClause. + */ + pub fn getBlock(self) -> BlockStatement { + for (blockStatement in BlockStatement(__all_data__)) { + if (self.key_eq(blockStatement.getParent())) { + return blockStatement + } + } + } +} + +/** + * A `switch`-`case` block. + */ +schema CaseBlock extends Statement { +} + +impl CaseBlock { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CaseBlock { + for (tmp in Statement(db)) { + if (isCaseBlock(Node {id: tmp.id})) { + yield CaseBlock { + id : tmp.id + } + } + } + } + + /** + * Gets a `case` clause of this `switch`-`case` block. + */ + pub fn getACaseClause(self) -> *CaseClause { + for (caseClause in CaseClause(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (caseClause.key_eq(auto_tmp1)) { + yield caseClause + } + } + } + } + + /** + * Gets the `i`th `case` clause of this `switch`-`case` block. + * index starts from 0. + */ + pub fn getCaseClause(self, i: int) -> CaseClause { + for (childIndex in int::__undetermined_all__()) { + for (caseClause in CaseClause(__all_data__)) { + if (caseClause.key_eq(self.getChild(childIndex))) { + // CaseBlock have DefaultClause, should adjust index of + // CaseClause nodes that after DefaultClause, DefaultClause + // can be any order with CaseClause. + if (self.haveDefaultClause()) { + for (defaultIndex in int::__undetermined_all__()) { + for (defaultClause in DefaultClause(__all_data__)) { + if (defaultClause.key_eq(self.getChild(defaultIndex))) { + if (childIndex < defaultIndex) { + if (i = childIndex) { + return caseClause + } + } + if (childIndex >= defaultIndex) { + if (i = childIndex - 1) { + return caseClause + } + } + } + } + } + } + // CaseBlock don't have DefaultClause, the child index + // is equal with case index + if (!self.haveDefaultClause()) { + if (i = childIndex) { + return caseClause + } + } + } + } + } + } + + /** + * Gets the `default` clause of this `switch`-`case` block. + */ + pub fn getDefaultClause(self) -> DefaultClause { + for (defaultClause in DefaultClause(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (defaultClause.key_eq(auto_tmp1)) { + return defaultClause + } + } + } + } + + /** + * Determine whether this CaseBlock has a DefaultClause. + */ + pub fn haveDefaultClause(self) -> bool { + for (defaultClause in DefaultClause(__all_data__)) { + if (defaultClause = self.getDefaultClause()) { + return true + } + } + } + + /** + * Gets a CaseClause or DefaultClause of this CaseBlock. + */ + pub fn getACaseOrDefault(self) -> *Statement { + for (statement in Statement(__all_data__)) { + if (self.key_eq(statement.getParent())) { + yield statement + } + } + } + + /** + * Gets the CaseClause count of this CaseBlock. + */ + pub fn getCaseClauseCount(self) -> int { + return self.getACaseClause().len() + } +} + +/** + * An `switch` statement + */ +schema SwitchStatement extends Statement { +} + +impl SwitchStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SwitchStatement { + for (tmp in Statement(db)) { + if (isSwitchStatement(Node {id: tmp.id})) { + yield SwitchStatement { + id : tmp.id + } + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + + pub fn getCaseBlock(self) -> CaseBlock { + for (caseBlock in CaseBlock(__all_data__)) { + if (caseBlock.key_eq(self.getChild(1))) { + return caseBlock + } + } + } +} + +/** + * A `throw` statement + */ +schema ThrowStatement extends Statement { +} + +impl ThrowStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ThrowStatement { + for (tmp in Statement(db)) { + if (isThrowStatement(Node {id: tmp.id})) { + yield ThrowStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the expression throwed by this ThrowStatement. + */ + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } +} + +/** + * A `try` Statement + */ +schema TryStatement extends Statement { +} + +impl TryStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TryStatement { + for (tmp in Statement(db)) { + if (isTryStatement(Node {id: tmp.id})) { + yield TryStatement { + id : tmp.id + } + } + } + } + + /** + * Gets the body of this `try` statement. + */ + pub fn getTryBlock(self) -> BlockStatement { + for (tryBlock in BlockStatement(__all_data__)) { + if (tryBlock.key_eq(self.getChild(0))) { + return tryBlock + } + } + } + + /** + * Gets the `catch` clause of this `try` statement, if any. + */ + pub fn getCatchClause(self) -> CatchClause { + for (catchClause in CatchClause(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (catchClause.key_eq(auto_tmp1)) { + return catchClause + } + } + } + } + + /** + * Gets the `finally` block of this `try` statement, if any. + */ + pub fn getFinallyBlock(self) -> BlockStatement { + for (finallyBlock in BlockStatement(__all_data__)) { + if (finallyBlock.getParent().key_eq(self)) { + let (finallyIndex = finallyBlock.getIndex()) { + if (finallyIndex != 0) { + return finallyBlock + } + } + } + } + } + + /** + * Determine whether this TryStatement has finally block or not. + */ + pub fn haveFinallyBlock(self) -> bool { + for (finallyBlockStatement in BlockStatement(__all_data__)) { + if (finallyBlockStatement = self.getFinallyBlock()) { + return true + } + } + } +} + +/** + * A `debugger` statement. + */ +schema DebuggerStatement extends Statement { +} + +impl DebuggerStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DebuggerStatement { + for (tmp in Statement(db)) { + if (isDebuggerStatement(Node {id: tmp.id})) { + yield DebuggerStatement { + id : tmp.id + } + } + } + } +} + +/** + * A not-emmitted statement. + * Will not appear in the AST. + */ +schema NotEmittedStatement extends Statement { +} + +impl NotEmittedStatement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NotEmittedStatement { + for (tmp in Statement(db)) { + if (isNotEmittedStatement(Node {id: tmp.id})) { + yield NotEmittedStatement { + id : tmp.id + } + } + } + } +} + +/** + * A merge-declaration marker. + * Will not appear in the AST. + */ +schema MergeDeclarationMarker extends Statement { +} + +impl MergeDeclarationMarker { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MergeDeclarationMarker { + for (tmp in Statement(db)) { + if (isMergeDeclarationMarker(Node {id: tmp.id})) { + yield MergeDeclarationMarker { + id : tmp.id + } + } + } + } +} + +/** + * An end-of-declaration marker. + * Will not appear in the AST. + */ +schema EndOfDeclarationMarker extends Statement { +} + +impl EndOfDeclarationMarker { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EndOfDeclarationMarker { + for (tmp in Statement(db)) { + if (isEndOfDeclarationMarker(Node {id: tmp.id})) { + yield EndOfDeclarationMarker { + id : tmp.id + } + } + } + } +} + +/** + * Determines whether a node is a declaration statement + */ +pub fn isDeclarationStatement(node: Node) -> bool { + let (kind = node.getKind()) { + if (isDeclarationStatementKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node is a statement, but not a declaration + */ +pub fn isStatementButNotDeclaration(node: Node) -> bool { + let (kind = node.getKind()) { + if (isStatementKindButNotDeclarationKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node is a statement + */ +pub fn isStatement(node: Node) -> bool { + if (isStatementButNotDeclaration(node)) { + return true + } + if (isDeclarationStatement(node)) { + return true + } + if (isBlockStatement(node)) { + return true + } +} + +/** + * Determines whether a node is a block statement + */ +pub fn isBlockStatement(node: Node) -> bool { + // Block + if (node.getKind() = 234) { + return true + } +} + +/** + * Determines whether a node is an empty statement. + */ +pub fn isEmptyStatement(node: Node) -> bool { + if (node.getKind() = 235) { + return true + } +} + +/** + * Determines whether a node is a variable statement + */ +pub fn isVariableStatement(node: Node) -> bool { + if (node.getKind() = 236) { + return true + } +} + +/** + * Determines whether a node is an expression statement + */ +pub fn isExpressionStatement(node: Node) -> bool { + if (node.getKind() = 237) { + return true + } +} + +/** + * Determines whether a node is an `if` statement + */ +pub fn isIfStatement(node: Node) -> bool { + if (node.getKind() = 238) { + return true + } +} + +/** + * Determines whether a node is a `do`-`while` statement + */ +pub fn isDoWhileStatement(node: Node) -> bool { + if (node.getKind() = 239) { + return true + } +} + +/** + * Determines whether a node is a `while` statement + */ +pub fn isWhileStatement(node: Node) -> bool { + if (node.getKind() = 240) { + return true + } +} + +/** + * Determines whether a node is a `for` statement + */ +pub fn isForStatement(node: Node) -> bool { + if (node.getKind() = 241) { + return true + } +} + +/** + * Determines whether a node is a initializer of for statement or enhanced for statement. + */ +pub fn isForInitializer(node: Node) -> bool { + for (forStatement in ForStatement(__all_data__)) { + let (initializerIndex = forStatement.getInitializerIndex()) { + if (node = forStatement.getChild(initializerIndex)) { + if (isVariableDeclarationList(node)) { + return true + } + if (isExpression(node)) { + return true + } + } + } + } + for (enhancedForStatement in EnhancedForStatement(__all_data__)) { + let (initializerIndex = enhancedForStatement.getInitializerIndex()) { + if (node = enhancedForStatement.getChild(initializerIndex)) { + if (isVariableDeclarationList(node)) { + return true + } + if (isExpression(node)) { + return true + } + } + } + } +} + +/** + * Determines whether a node is a `for`-`in` statement + */ +pub fn isForInStatement(node: Node) -> bool { + if (node.getKind() = 242) { + return true + } +} + +/** + * Determines whether a node is a `for`-`of` statement + */ +pub fn isForOfStatement(node: Node) -> bool { + if (node.getKind() = 243) { + return true + } +} + +/** + * Determines whether a node is a `for`-`in` or `for`-`of` statement + */ +pub fn isEnhancedForStatement(node: Node) -> bool { + if (isForInStatement(node)) { + return true + } + if (isForOfStatement(node)) { + return true + } +} + +/** + * Determine whether a node is an iteration statement, including `while`, `do`-`while`, + * `for` and enhanced `for` (`for`-`in`, `for`-`of`) statements. + */ +pub fn isIterationStatement(node: Node) -> bool { + let (kind = node.getKind()) { + if (isIterationStatementKind(kind)) { + return true + } + } +} + +/** + * @todo Labeled statement. + */ + +/** + * Determines whether a node is a `continue` statement + */ +pub fn isContinueStatement(node: Node) -> bool { + if (node.getKind() = 244) { + return true + } +} + +/** + * Determines whether a node is a `break` statement + */ +pub fn isBreakStatement(node: Node) -> bool { + if (node.getKind() = 245) { + return true + } +} + +/** + * Determines whether a node is a `return` statement + */ +pub fn isReturnStatement(node: Node) -> bool { + if (node.getKind() = 246) { + return true + } +} + +/** + * Determines whether a node is a `with` statement + */ +pub fn isWithStatement(node: Node) -> bool { + if (node.getKind() = 247) { + return true + } +} + +/** + * Determines whether a node is a function declaration. + */ +pub fn isFunctionDeclaration(node: Node) -> bool { + if (node.getKind() = 255) { + return true + } +} + +/** + * Determines whether a node is a class declaration. + */ +pub fn isClassDeclaration(node: Node) -> bool { + if (node.getKind() = 256) { + return true + } +} + +/** + * Determines whether a node is an interface declaration. + */ +pub fn isInterfaceDeclaration(node: Node) -> bool { + if (node.getKind() = 257) { + return true + } +} + +/** + * Determines whether a node is a type alias declaration. + */ +pub fn isTypeAliasDeclaration(node: Node) -> bool { + if (node.getKind() = 258) { + return true + } +} + +/** + * Determines whether a node is an enum declaration. + */ +pub fn isEnumDeclaration(node: Node) -> bool { + if (node.getKind() = 259) { + return true + } +} + +/** + * Determines whether a node is a module declaration. + */ +pub fn isModuleDeclaration(node: Node) -> bool { + if (node.getKind() = 260) { + return true + } +} + +/** + * Determines whether a node is a namespace export declaration. + */ +pub fn isNamespaceExportDeclaration(node: Node) -> bool { + if (node.getKind() = 263) { + return true + } +} + +/** + * Determines whether a node is an import-equals declaration. + */ +pub fn isImportEqualsDeclaration(node: Node) -> bool { + if (node.getKind() = 264) { + return true + } +} + +/** + * Determines whether a node is an import declaration. + */ +pub fn isImportDeclaration(node: Node) -> bool { + if (node.getKind() = 265) { + return true + } +} + +/** + * Determines whether a node is an export assignment. + */ +pub fn isExportAssignment(node: Node) -> bool { + if (node.getKind() = 270) { + return true + } +} + +/** + * Determines whether a node is an export declaration. + */ +pub fn isExportDeclaration(node: Node) -> bool { + if (node.getKind() = 271) { + return true + } +} + +/** + * Determines whether a node is a missing declaration. + */ +pub fn isMissingDeclaration(node: Node) -> bool { + if (node.getKind() = 275) { + return true + } +} + +/** + * Determines whether a node is an `case` clause + */ +pub fn isCaseClause(node: Node) -> bool { + if (node.getKind() = 288) { + return true + } +} + +/** + * Determines whether a node is an `default` clause + */ +pub fn isDefaultClause(node: Node) -> bool { + if (node.getKind() = 289) { + return true + } +} + +/** + * Determines whether a node is an `catch` clause + */ +pub fn isCatchClause(node: Node) -> bool { + if (node.getKind() = 291) { + return true + } +} + +/** + * Determines whether a node is a `switch`-`case` block. + */ +pub fn isCaseBlock(node: Node) -> bool { + if (node.getKind() = 262) { + return true + } +} + +/** + * Determines whether a node is an `switch` statement + */ +pub fn isSwitchStatement(node: Node) -> bool { + if (node.getKind() = 248) { + return true + } +} + +/** + * Determines whether a node is a `throw` statement + */ +pub fn isThrowStatement(node: Node) -> bool { + if (node.getKind() = 250) { + return true + } +} + +/** + * Determines whether a node is a `try` statement + */ +pub fn isTryStatement(node: Node) -> bool { + if (node.getKind() = 251) { + return true + } +} + +/** + * Determines whether a node is a `debugger` statement. + */ +pub fn isDebuggerStatement(node: Node) -> bool { + if (node.getKind() = 252) { + return true + } +} + +/** + * Determines whether a node is a not-emmitted statement. + */ +pub fn isNotEmittedStatement(node: Node) -> bool { + if (node.getKind() = 347) { + return true + } +} + +/** + * Determines whether a node is a merge-declaration marker. + */ +pub fn isMergeDeclarationMarker(node: Node) -> bool { + if (node.getKind() = 350) { + return true + } +} + +/** + * Determines whether a node is an end-of-declaration marker. + */ +pub fn isEndOfDeclarationMarker(node: Node) -> bool { + if (node.getKind() = 351) { + return true + } +} + +/** + * Determines whether a node kind is an iteration statement kind, + * including `while`, `do`-`while`, `for` and enhanced `for` (`for`-`in`, `for`-`of`) statements. + */ +pub fn isIterationStatementKind(kind: int) -> bool { + [ + {239}, // DoStatement + {240}, // WhileStatement + {241}, // ForStatement + {242}, // ForInStatement + {243}, // ForOfStatement + ] +} + +/** + * Determines whether a node kind is a statement kind, but not a declaration kind + */ +pub fn isStatementKindButNotDeclarationKind(kind: int) -> bool { + [ + {235}, // EmptyStatement + {236}, // VariableStatement + {237}, // ExpressionStatement + {238}, // IfStatement + {239}, // DoStatement + {240}, // WhileStatement + {241}, // ForStatement + {242}, // ForInStatement + {243}, // ForOfStatement + {244}, // ContinueStatement + {245}, // BreakStatement + {246}, // ReturnStatement + {247}, // WithStatement + {248}, // SwitchStatement + {249}, // LabeledStatement + {250}, // ThrowStatement + {251}, // TryStatement + {252}, // DebuggerStatement + {347}, // NotEmittedStatement + {350}, // MergeDeclarationMarker + {351}, // EndOfDeclarationMarker + + {262}, // CaseBlock + {291}, // CatchClause + {288}, // CaseClause + {289}, // DefaultClause + ] +} + +/** + * Determines whether a node kind is a declaration statement kind + */ +pub fn isDeclarationStatementKind(kind: int) -> bool { + [ + {255}, // FunctionDeclaration + {256}, // ClassDeclaration + {257}, // InterfaceDeclaration + {258}, // TypeAliasDeclaration + {259}, // EnumDeclaration + {260}, // ModuleDeclaration + {263}, // NamespaceExportDeclaration + {264}, // ImportEqualsDeclaration + {265}, // ImportDeclaration + {270}, // ExportAssignment + {271}, // ExportDeclaration + {275}, // MissingDeclaration + ] +} diff --git a/language/javascript/lib/Symbol.gdl b/language/javascript/lib/Symbol.gdl new file mode 100644 index 00000000..4ff2b4cc --- /dev/null +++ b/language/javascript/lib/Symbol.gdl @@ -0,0 +1,38 @@ +/** + * @filename: Statement + * @brief: Provides classes and predicates for working with JavaScript / TypeScript symbols. + */ + +/** + * A symbol. + */ +schema Symbol extends SymbolDO { +} + +impl Symbol { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Symbol { + for (tmp in SymbolDO(db)) { + yield Symbol { + oid : tmp.oid, + name : tmp.name, + description : tmp.description + } + } + } + + /** + * Gets a node associated with this symbol. + */ + pub fn getANode(self) -> *Node { + for (node in Node(__all_data__), + nodeSymbol in NodeSymbolDO(__all_data__)) { + if (node.key_eq(nodeSymbol)) { + if (nodeSymbol.getSymbolOid() = self.oid) { + yield node + } + } + } + } +} diff --git a/language/javascript/lib/SyntaxKind.gdl b/language/javascript/lib/SyntaxKind.gdl new file mode 100644 index 00000000..899d5757 --- /dev/null +++ b/language/javascript/lib/SyntaxKind.gdl @@ -0,0 +1,390 @@ +/** + * @filename: SyntaxKind + * @brief: Provides util classes and predicates for JavaScript / TypeScript SyntaxKinds + */ + +/** + * A SyntaxKind + */ +schema SyntaxKind { + @primary id: int, + name: string +} + +impl SyntaxKind { + @data_constraint + pub fn __all__() -> *SyntaxKind { + for (id in int::__undetermined_all__()) { + for (name in string::__undetermined_all__()) { + if (syntaxKind(id, name)) { + yield SyntaxKind{id: id, name: name} + } + } + } + } + + pub fn getName(self) -> string { + return self.name + } +} + +/** + * The predict for the value and name pairs of SyntaxKinds + */ +pub fn syntaxKind(kind: int, name: string) -> bool { + [ + {0, "Unknown"}, + {1, "EndOfFileToken"}, + {2, "SingleLineCommentTrivia"}, + {3, "MultiLineCommentTrivia"}, + {4, "NewLineTrivia"}, + {5, "WhitespaceTrivia"}, + {6, "ShebangTrivia"}, + {7, "ConflictMarkerTrivia"}, + {8, "NumericLiteral"}, + {9, "BigIntLiteral"}, + {10, "StringLiteral"}, + {11, "JsxText"}, + {12, "JsxTextAllWhiteSpaces"}, + {13, "RegularExpressionLiteral"}, + {14, "NoSubstitutionTemplateLiteral"}, + {15, "TemplateHead"}, + {16, "TemplateMiddle"}, + {17, "TemplateTail"}, + {18, "OpenBraceToken"}, + {19, "CloseBraceToken"}, + {20, "OpenParenToken"}, + {21, "CloseParenToken"}, + {22, "OpenBracketToken"}, + {23, "CloseBracketToken"}, + {24, "DotToken"}, + {25, "DotDotDotToken"}, + {26, "SemicolonToken"}, + {27, "CommaToken"}, + {28, "QuestionDotToken"}, + {29, "LessThanToken"}, + {30, "LessThanSlashToken"}, + {31, "GreaterThanToken"}, + {32, "LessThanEqualsToken"}, + {33, "GreaterThanEqualsToken"}, + {34, "EqualsEqualsToken"}, + {35, "ExclamationEqualsToken"}, + {36, "EqualsEqualsEqualsToken"}, + {37, "ExclamationEqualsEqualsToken"}, + {38, "EqualsGreaterThanToken"}, + {39, "PlusToken"}, + {40, "MinusToken"}, + {41, "AsteriskToken"}, + {42, "AsteriskAsteriskToken"}, + {43, "SlashToken"}, + {44, "PercentToken"}, + {45, "PlusPlusToken"}, + {46, "MinusMinusToken"}, + {47, "LessThanLessThanToken"}, + {48, "GreaterThanGreaterThanToken"}, + {49, "GreaterThanGreaterThanGreaterThanToken"}, + {50, "AmpersandToken"}, + {51, "BarToken"}, + {52, "CaretToken"}, + {53, "ExclamationToken"}, + {54, "TildeToken"}, + {55, "AmpersandAmpersandToken"}, + {56, "BarBarToken"}, + {57, "QuestionToken"}, + {58, "ColonToken"}, + {59, "AtToken"}, + {60, "QuestionQuestionToken"}, + {61, "BacktickToken"}, + {62, "HashToken"}, + {63, "EqualsToken"}, + {64, "PlusEqualsToken"}, + {65, "MinusEqualsToken"}, + {66, "AsteriskEqualsToken"}, + {67, "AsteriskAsteriskEqualsToken"}, + {68, "SlashEqualsToken"}, + {69, "PercentEqualsToken"}, + {70, "LessThanLessThanEqualsToken"}, + {71, "GreaterThanGreaterThanEqualsToken"}, + {72, "GreaterThanGreaterThanGreaterThanEqualsToken"}, + {73, "AmpersandEqualsToken"}, + {74, "BarEqualsToken"}, + {75, "BarBarEqualsToken"}, + {76, "AmpersandAmpersandEqualsToken"}, + {77, "QuestionQuestionEqualsToken"}, + {78, "CaretEqualsToken"}, + {79, "Identifier"}, + {80, "PrivateIdentifier"}, + {81, "BreakKeyword"}, + {82, "CaseKeyword"}, + {83, "CatchKeyword"}, + {84, "ClassKeyword"}, + {85, "ConstKeyword"}, + {86, "ContinueKeyword"}, + {87, "DebuggerKeyword"}, + {88, "DefaultKeyword"}, + {89, "DeleteKeyword"}, + {90, "DoKeyword"}, + {91, "ElseKeyword"}, + {92, "EnumKeyword"}, + {93, "ExportKeyword"}, + {94, "ExtendsKeyword"}, + {95, "FalseKeyword"}, + {96, "FinallyKeyword"}, + {97, "ForKeyword"}, + {98, "FunctionKeyword"}, + {99, "IfKeyword"}, + {100, "ImportKeyword"}, + {101, "InKeyword"}, + {102, "InstanceOfKeyword"}, + {103, "NewKeyword"}, + {104, "NullKeyword"}, + {105, "ReturnKeyword"}, + {106, "SuperKeyword"}, + {107, "SwitchKeyword"}, + {108, "ThisKeyword"}, + {109, "ThrowKeyword"}, + {110, "TrueKeyword"}, + {111, "TryKeyword"}, + {112, "TypeOfKeyword"}, + {113, "VarKeyword"}, + {114, "VoidKeyword"}, + {115, "WhileKeyword"}, + {116, "WithKeyword"}, + {117, "ImplementsKeyword"}, + {118, "InterfaceKeyword"}, + {119, "LetKeyword"}, + {120, "PackageKeyword"}, + {121, "PrivateKeyword"}, + {122, "ProtectedKeyword"}, + {123, "PublicKeyword"}, + {124, "StaticKeyword"}, + {125, "YieldKeyword"}, + {126, "AbstractKeyword"}, + {127, "AsKeyword"}, + {128, "AssertsKeyword"}, + {129, "AssertKeyword"}, + {130, "AnyKeyword"}, + {131, "AsyncKeyword"}, + {132, "AwaitKeyword"}, + {133, "BooleanKeyword"}, + {134, "ConstructorKeyword"}, + {135, "DeclareKeyword"}, + {136, "GetKeyword"}, + {137, "InferKeyword"}, + {138, "IntrinsicKeyword"}, + {139, "IsKeyword"}, + {140, "KeyOfKeyword"}, + {141, "ModuleKeyword"}, + {142, "NamespaceKeyword"}, + {143, "NeverKeyword"}, + {144, "ReadonlyKeyword"}, + {145, "RequireKeyword"}, + {146, "NumberKeyword"}, + {147, "ObjectKeyword"}, + {148, "SetKeyword"}, + {149, "StringKeyword"}, + {150, "SymbolKeyword"}, + {151, "TypeKeyword"}, + {152, "UndefinedKeyword"}, + {153, "UniqueKeyword"}, + {154, "UnknownKeyword"}, + {155, "FromKeyword"}, + {156, "GlobalKeyword"}, + {157, "BigIntKeyword"}, + {158, "OverrideKeyword"}, + {159, "OfKeyword"}, + {160, "QualifiedName"}, + {161, "ComputedPropertyName"}, + {162, "TypeParameter"}, + {163, "Parameter"}, + {164, "Decorator"}, + {165, "PropertySignature"}, + {166, "PropertyDeclaration"}, + {167, "MethodSignature"}, + {168, "MethodDeclaration"}, + {169, "ClassStaticBlockDeclaration"}, + {170, "Constructor"}, + {171, "GetAccessor"}, + {172, "SetAccessor"}, + {173, "CallSignature"}, + {174, "ConstructSignature"}, + {175, "IndexSignature"}, + {176, "TypePredicate"}, + {177, "TypeReference"}, + {178, "FunctionType"}, + {179, "ConstructorType"}, + {180, "TypeQuery"}, + {181, "TypeLiteral"}, + {182, "ArrayType"}, + {183, "TupleType"}, + {184, "OptionalType"}, + {185, "RestType"}, + {186, "UnionType"}, + {187, "IntersectionType"}, + {188, "ConditionalType"}, + {189, "InferType"}, + {190, "ParenthesizedType"}, + {191, "ThisType"}, + {192, "TypeOperator"}, + {193, "IndexedAccessType"}, + {194, "MappedType"}, + {195, "LiteralType"}, + {196, "NamedTupleMember"}, + {197, "TemplateLiteralType"}, + {198, "TemplateLiteralTypeSpan"}, + {199, "ImportType"}, + {200, "ObjectBindingPattern"}, + {201, "ArrayBindingPattern"}, + {202, "BindingElement"}, + {203, "ArrayLiteralExpression"}, + {204, "ObjectLiteralExpression"}, + {205, "PropertyAccessExpression"}, + {206, "ElementAccessExpression"}, + {207, "CallExpression"}, + {208, "NewExpression"}, + {209, "TaggedTemplateExpression"}, + {210, "TypeAssertionExpression"}, + {211, "ParenthesizedExpression"}, + {212, "FunctionExpression"}, + {213, "ArrowFunction"}, + {214, "DeleteExpression"}, + {215, "TypeOfExpression"}, + {216, "VoidExpression"}, + {217, "AwaitExpression"}, + {218, "PrefixUnaryExpression"}, + {219, "PostfixUnaryExpression"}, + {220, "BinaryExpression"}, + {221, "ConditionalExpression"}, + {222, "TemplateExpression"}, + {223, "YieldExpression"}, + {224, "SpreadElement"}, + {225, "ClassExpression"}, + {226, "OmittedExpression"}, + {227, "ExpressionWithTypeArguments"}, + {228, "AsExpression"}, + {229, "NonNullExpression"}, + {230, "MetaProperty"}, + {231, "SyntheticExpression"}, + {232, "TemplateSpan"}, + {233, "SemicolonClassElement"}, + {234, "Block"}, + {235, "EmptyStatement"}, + {236, "VariableStatement"}, + {237, "ExpressionStatement"}, + {238, "IfStatement"}, + {239, "DoWhileStatement"}, + {240, "WhileStatement"}, + {241, "ForStatement"}, + {242, "ForInStatement"}, + {243, "ForOfStatement"}, + {244, "ContinueStatement"}, + {245, "BreakStatement"}, + {246, "ReturnStatement"}, + {247, "WithStatement"}, + {248, "SwitchStatement"}, + {249, "LabeledStatement"}, + {250, "ThrowStatement"}, + {251, "TryStatement"}, + {252, "DebuggerStatement"}, + {253, "VariableDeclaration"}, + {254, "VariableDeclarationList"}, + {255, "FunctionDeclaration"}, + {256, "ClassDeclaration"}, + {257, "InterfaceDeclaration"}, + {258, "TypeAliasDeclaration"}, + {259, "EnumDeclaration"}, + {260, "ModuleDeclaration"}, + {261, "ModuleBlock"}, + {262, "CaseBlock"}, + {263, "NamespaceExportDeclaration"}, + {264, "ImportEqualsDeclaration"}, + {265, "ImportDeclaration"}, + {266, "ImportClause"}, + {267, "NamespaceImport"}, + {268, "NamedImports"}, + {269, "ImportSpecifier"}, + {270, "ExportAssignment"}, + {271, "ExportDeclaration"}, + {272, "NamedExports"}, + {273, "NamespaceExport"}, + {274, "ExportSpecifier"}, + {275, "MissingDeclaration"}, + {276, "ExternalModuleReference"}, + {277, "JsxElement"}, + {278, "JsxSelfClosingElement"}, + {279, "JsxOpeningElement"}, + {280, "JsxClosingElement"}, + {281, "JsxFragment"}, + {282, "JsxOpeningFragment"}, + {283, "JsxClosingFragment"}, + {284, "JsxAttribute"}, + {285, "JsxAttributes"}, + {286, "JsxSpreadAttribute"}, + {287, "JsxExpression"}, + {288, "CaseClause"}, + {289, "DefaultClause"}, + {290, "HeritageClause"}, + {291, "CatchClause"}, + {292, "AssertClause"}, + {293, "AssertEntry"}, + {294, "PropertyAssignment"}, + {295, "ShorthandPropertyAssignment"}, + {296, "SpreadAssignment"}, + {297, "EnumMember"}, + {298, "UnparsedPrologue"}, + {299, "UnparsedPrepend"}, + {300, "UnparsedText"}, + {301, "UnparsedInternalText"}, + {302, "UnparsedSyntheticReference"}, + {303, "SourceFile"}, + {304, "Bundle"}, + {305, "UnparsedSource"}, + {306, "InputFiles"}, + {307, "JSDocTypeExpression"}, + {308, "JSDocNameReference"}, + {309, "JSDocMemberName"}, + {310, "JSDocAllType"}, + {311, "JSDocUnknownType"}, + {312, "JSDocNullableType"}, + {313, "JSDocNonNullableType"}, + {314, "JSDocOptionalType"}, + {315, "JSDocFunctionType"}, + {316, "JSDocVariadicType"}, + {317, "JSDocNamepathType"}, + {318, "JSDocComment"}, + {319, "JSDocText"}, + {320, "JSDocTypeLiteral"}, + {321, "JSDocSignature"}, + {322, "JSDocLink"}, + {323, "JSDocLinkCode"}, + {324, "JSDocLinkPlain"}, + {325, "JSDocTag"}, + {326, "JSDocAugmentsTag"}, + {327, "JSDocImplementsTag"}, + {328, "JSDocAuthorTag"}, + {329, "JSDocDeprecatedTag"}, + {330, "JSDocClassTag"}, + {331, "JSDocPublicTag"}, + {332, "JSDocPrivateTag"}, + {333, "JSDocProtectedTag"}, + {334, "JSDocReadonlyTag"}, + {335, "JSDocOverrideTag"}, + {336, "JSDocCallbackTag"}, + {337, "JSDocEnumTag"}, + {338, "JSDocParameterTag"}, + {339, "JSDocReturnTag"}, + {340, "JSDocThisTag"}, + {341, "JSDocTypeTag"}, + {342, "JSDocTemplateTag"}, + {343, "JSDocTypedefTag"}, + {344, "JSDocSeeTag"}, + {345, "JSDocPropertyTag"}, + {346, "SyntaxList"}, + {347, "NotEmittedStatement"}, + {348, "PartiallyEmittedExpression"}, + {349, "CommaListExpression"}, + {350, "MergeDeclarationMarker"}, + {351, "EndOfDeclarationMarker"}, + {352, "SyntheticReferenceExpression"}, + ] +} diff --git a/language/javascript/lib/Template.gdl b/language/javascript/lib/Template.gdl new file mode 100644 index 00000000..c26f6398 --- /dev/null +++ b/language/javascript/lib/Template.gdl @@ -0,0 +1,168 @@ +/** + * @filename: Template + * @brief: Provides util classes and predicates for JavaScript / TypeScript templates. + */ + +/** + * A template literal-like node, which is a no-substitution template literal, template head, template middle or template tail. + */ +schema TemplateLiteralLikeNode extends Node { +} + +impl TemplateLiteralLikeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateLiteralLikeNode { + for (tmp in Node(db)) { + if (isTemplateLiteralLikeNode(tmp)) { + yield TemplateLiteralLikeNode { + id : tmp.id + } + } + } + } + + /** + * Gets the value of this literal-like node, as a string. + */ + pub fn getValue(self) -> string { + for (literalDO in LiteralDO(__all_data__)) { + if (literalDO.key_eq(self)) { + let (value = literalDO.getValue()) { + return value + } + } + } + } +} + +/** + * A template head. + */ +schema TemplateHead extends TemplateLiteralLikeNode { +} + +impl TemplateHead { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateHead { + for (tmp in TemplateLiteralLikeNode(db)) { + if (isTemplateHead(Node {id: tmp.id})) { + yield TemplateHead { + id : tmp.id + } + } + } + } +} + +/** + * A template middle. + */ +schema TemplateMiddle extends TemplateLiteralLikeNode { +} + +impl TemplateMiddle { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateMiddle { + for (tmp in TemplateLiteralLikeNode(db)) { + if (isTemplateMiddle(Node {id: tmp.id})) { + yield TemplateMiddle { + id : tmp.id + } + } + } + } +} + +/** + * A template tail. + */ +schema TemplateTail extends TemplateLiteralLikeNode { +} + +impl TemplateTail { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateTail { + for (tmp in TemplateLiteralLikeNode(db)) { + if (isTemplateTail(Node {id: tmp.id})) { + yield TemplateTail { + id : tmp.id + } + } + } + } +} + +/** + * A template span. + */ +schema TemplateSpan extends Node { +} + +impl TemplateSpan { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateSpan { + for (tmp in Node(db)) { + if (isTemplateSpan(tmp)) { + yield TemplateSpan { + id : tmp.id + } + } + } + } + + pub fn getParent(self) -> TemplateExpression { + for (parent in TemplateExpression(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + + pub fn getExpression(self) -> Expression { + for (expression in Expression(__all_data__)) { + if (expression.key_eq(self.getChild(0))) { + return expression + } + } + } + + pub fn getLiteral(self) -> Token { + for (literal in Token(__all_data__)) { + if (literal.key_eq(self.getChild(1))) { + return literal + } + } + } +} + +/** + * Determines whether a node is a template literal-like node, which is a no-substitution template literal, template head, template middle or template tail. + */ +pub fn isTemplateLiteralLikeNode(node: Node) -> bool { + if (isNoSubstitutionTemplateLiteral(node)) { + return true + } + if (isTemplateHead(node)) { + return true + } + if (isTemplateMiddle(node)) { + return true + } + if (isTemplateTail(node)) { + return true + } +} + +/** + * Determines whether a node is a template span. + */ +pub fn isTemplateSpan(node: Node) -> bool { + if (node.getKind() = 232) { + return true + } +} diff --git a/language/javascript/lib/Token.gdl b/language/javascript/lib/Token.gdl new file mode 100644 index 00000000..1f17d8c5 --- /dev/null +++ b/language/javascript/lib/Token.gdl @@ -0,0 +1,3270 @@ +/** + * @filename: Statement + * @brief: Provides classes and predicates for working with JavaScript / TypeScript statements + */ + +/** + * A token. + */ +schema Token extends Node { +} + +impl Token { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Token { + for (tmp in Node(db)) { + if (isToken(tmp)) { + yield Token { + id : tmp.id + } + } + } + } +} + +/** + * An unknown token. + */ +schema Unknown extends Token { +} + +impl Unknown { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *Unknown { + for (tmp in Token(db)) { + if (isUnknown(Node {id: tmp.id})) { + yield Unknown { + id : tmp.id + } + } + } + } +} + +/** + * An end-of-file token. + */ +schema EndOfFileToken extends Token { +} + +impl EndOfFileToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EndOfFileToken { + for (tmp in Token(db)) { + if (isEndOfFileToken(Node {id: tmp.id})) { + yield EndOfFileToken { + id : tmp.id + } + } + } + } +} + +/** + * A numeric literal token. + */ +schema NumericLiteralToken extends Token { +} + +impl NumericLiteralToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NumericLiteralToken { + for (tmp in Token(db)) { + if (isNumericLiteral(Node {id: tmp.id})) { + yield NumericLiteralToken { + id : tmp.id + } + } + } + } +} + +/** + * A big-int literal token. + */ +schema BigIntLiteralToken extends Token { +} + +impl BigIntLiteralToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BigIntLiteralToken { + for (tmp in Token(db)) { + if (isBigIntLiteral(Node {id: tmp.id})) { + yield BigIntLiteralToken { + id : tmp.id + } + } + } + } +} + +/** + * A string literal token. + */ +schema StringLiteralToken extends Token { +} + +impl StringLiteralToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *StringLiteralToken { + for (tmp in Token(db)) { + if (isStringLiteral(Node {id: tmp.id})) { + yield StringLiteralToken { + id : tmp.id + } + } + } + } +} + +/** + * A JSX text token. + */ +schema JsxTextToken extends Token { +} + +impl JsxTextToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *JsxTextToken { + for (tmp in Token(db)) { + if (isJsxText(Node {id: tmp.id})) { + yield JsxTextToken { + id : tmp.id + } + } + } + } +} + +/** + * A regular expression literal. + */ +schema RegularExpressionLiteralToken extends Token { +} + +impl RegularExpressionLiteralToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RegularExpressionLiteralToken { + for (tmp in Token(db)) { + if (isRegularExpressionLiteral(Node {id: tmp.id})) { + yield RegularExpressionLiteralToken { + id : tmp.id + } + } + } + } +} + +/** + * A no-substitution template literal token. + */ +schema NoSubstitutionTemplateLiteralToken extends Token { +} + +impl NoSubstitutionTemplateLiteralToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NoSubstitutionTemplateLiteralToken { + for (tmp in Token(db)) { + if (isNoSubstitutionTemplateLiteral(Node {id: tmp.id})) { + yield NoSubstitutionTemplateLiteralToken { + id : tmp.id + } + } + } + } +} + +/** + * A template head token. + */ +schema TemplateHeadToken extends Token { +} + +impl TemplateHeadToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateHeadToken { + for (tmp in Token(db)) { + if (isTemplateHead(Node {id: tmp.id})) { + yield TemplateHeadToken { + id : tmp.id + } + } + } + } +} + +/** + * A template middle token. + */ +schema TemplateMiddleToken extends Token { +} + +impl TemplateMiddleToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateMiddleToken { + for (tmp in Token(db)) { + if (isTemplateMiddle(Node {id: tmp.id})) { + yield TemplateMiddleToken { + id : tmp.id + } + } + } + } +} + +/** + * A template tail token. + */ +schema TemplateTailToken extends Token { +} + +impl TemplateTailToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateTailToken { + for (tmp in Token(db)) { + if (isTemplateTail(Node {id: tmp.id})) { + yield TemplateTailToken { + id : tmp.id + } + } + } + } +} + +/** + * A `...` token. + */ +schema DotDotDotToken extends Token { +} + +impl DotDotDotToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *DotDotDotToken { + for (tmp in Token(db)) { + if (isDotDotDotToken(Node {id: tmp.id})) { + yield DotDotDotToken { + id : tmp.id + } + } + } + } +} + +/** + * A `,` token. + */ +schema CommaToken extends Token { +} + +impl CommaToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CommaToken { + for (tmp in Token(db)) { + if (isCommaToken(Node {id: tmp.id})) { + yield CommaToken { + id : tmp.id + } + } + } + } +} + +/** + * A `?.` token. + */ +schema QuestionDotToken extends Token { +} + +impl QuestionDotToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *QuestionDotToken { + for (tmp in Token(db)) { + if (isQuestionDotToken(Node {id: tmp.id})) { + yield QuestionDotToken { + id : tmp.id + } + } + } + } +} + +/** + * A `<` token. + */ +schema LessThanToken extends Token { +} + +impl LessThanToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LessThanToken { + for (tmp in Token(db)) { + if (isLessThanToken(Node {id: tmp.id})) { + yield LessThanToken { + id : tmp.id + } + } + } + } +} + +/** + * A `>` token. + */ +schema GreaterThanToken extends Token { +} + +impl GreaterThanToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GreaterThanToken { + for (tmp in Token(db)) { + if (isGreaterThanToken(Node {id: tmp.id})) { + yield GreaterThanToken { + id : tmp.id + } + } + } + } +} + +/** + * A `<=` token. + */ +schema LessThanEqualsToken extends Token { +} + +impl LessThanEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LessThanEqualsToken { + for (tmp in Token(db)) { + if (isLessThanEqualsToken(Node {id: tmp.id})) { + yield LessThanEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `>=` token. + */ +schema GreaterThanEqualsToken extends Token { +} + +impl GreaterThanEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GreaterThanEqualsToken { + for (tmp in Token(db)) { + if (isGreaterThanEqualsToken(Node {id: tmp.id})) { + yield GreaterThanEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * An `==` token. + */ +schema EqualsEqualsToken extends Token { +} + +impl EqualsEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EqualsEqualsToken { + for (tmp in Token(db)) { + if (isEqualsEqualsToken(Node {id: tmp.id})) { + yield EqualsEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `!=` token. + */ +schema ExclamationEqualsToken extends Token { +} + +impl ExclamationEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExclamationEqualsToken { + for (tmp in Token(db)) { + if (isExclamationEqualsToken(Node {id: tmp.id})) { + yield ExclamationEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * An `===` token. + */ +schema EqualsEqualsEqualsToken extends Token { +} + +impl EqualsEqualsEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EqualsEqualsEqualsToken { + for (tmp in Token(db)) { + if (isEqualsEqualsEqualsToken(Node {id: tmp.id})) { + yield EqualsEqualsEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `!==` token. + */ +schema ExclamationEqualsEqualsToken extends Token { +} + +impl ExclamationEqualsEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExclamationEqualsEqualsToken { + for (tmp in Token(db)) { + if (isExclamationEqualsEqualsToken(Node {id: tmp.id})) { + yield ExclamationEqualsEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `+` token. + */ +schema PlusToken extends Token { +} + +impl PlusToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PlusToken { + for (tmp in Token(db)) { + if (isPlusToken(Node {id: tmp.id})) { + yield PlusToken { + id : tmp.id + } + } + } + } +} + +/** + * A `-` token. + */ +schema MinusToken extends Token { +} + +impl MinusToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MinusToken { + for (tmp in Token(db)) { + if (isMinusToken(Node {id: tmp.id})) { + yield MinusToken { + id : tmp.id + } + } + } + } +} + +/** + * A `*` token. + */ +schema AsteriskToken extends Token { +} + +impl AsteriskToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AsteriskToken { + for (tmp in Token(db)) { + if (isAsteriskToken(Node {id: tmp.id})) { + yield AsteriskToken { + id : tmp.id + } + } + } + } +} + +/** + * A `**` token. + */ +schema AsteriskAsteriskToken extends Token { +} + +impl AsteriskAsteriskToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AsteriskAsteriskToken { + for (tmp in Token(db)) { + if (isAsteriskAsteriskToken(Node {id: tmp.id})) { + yield AsteriskAsteriskToken { + id : tmp.id + } + } + } + } +} + +/** + * A `/` token. + */ +schema SlashToken extends Token { +} + +impl SlashToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SlashToken { + for (tmp in Token(db)) { + if (isSlashToken(Node {id: tmp.id})) { + yield SlashToken { + id : tmp.id + } + } + } + } +} + +/** + * A `%` token. + */ +schema PercentToken extends Token { +} + +impl PercentToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PercentToken { + for (tmp in Token(db)) { + if (isPercentToken(Node {id: tmp.id})) { + yield PercentToken { + id : tmp.id + } + } + } + } +} + +/** + * A `++` token. + */ +schema PlusPlusToken extends Token { +} + +impl PlusPlusToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PlusPlusToken { + for (tmp in Token(db)) { + if (isPlusPlusToken(Node {id: tmp.id})) { + yield PlusPlusToken { + id : tmp.id + } + } + } + } +} + +/** + * A `--` token. + */ +schema MinusMinusToken extends Token { +} + +impl MinusMinusToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MinusMinusToken { + for (tmp in Token(db)) { + if (isMinusMinusToken(Node {id: tmp.id})) { + yield MinusMinusToken { + id : tmp.id + } + } + } + } +} + +/** + * A `<<` token. + */ +schema LessThanLessThanToken extends Token { +} + +impl LessThanLessThanToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LessThanLessThanToken { + for (tmp in Token(db)) { + if (isLessThanLessThanToken(Node {id: tmp.id})) { + yield LessThanLessThanToken { + id : tmp.id + } + } + } + } +} + +/** + * A `>>` token. + */ +schema GreaterThanGreaterThanToken extends Token { +} + +impl GreaterThanGreaterThanToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GreaterThanGreaterThanToken { + for (tmp in Token(db)) { + if (isGreaterThanGreaterThanToken(Node {id: tmp.id})) { + yield GreaterThanGreaterThanToken { + id : tmp.id + } + } + } + } +} + +/** + * A `>>>` token. + */ +schema GreaterThanGreaterThanGreaterThanToken extends Token { +} + +impl GreaterThanGreaterThanGreaterThanToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GreaterThanGreaterThanGreaterThanToken { + for (tmp in Token(db)) { + if (isGreaterThanGreaterThanGreaterThanToken(Node {id: tmp.id})) { + yield GreaterThanGreaterThanGreaterThanToken { + id : tmp.id + } + } + } + } +} + +/** + * An `&` token. + */ +schema AmpersandToken extends Token { +} + +impl AmpersandToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AmpersandToken { + for (tmp in Token(db)) { + if (isAmpersandToken(Node {id: tmp.id})) { + yield AmpersandToken { + id : tmp.id + } + } + } + } +} + +/** + * A `|` token. + */ +schema BarToken extends Token { +} + +impl BarToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BarToken { + for (tmp in Token(db)) { + if (isBarToken(Node {id: tmp.id})) { + yield BarToken { + id : tmp.id + } + } + } + } +} + +/** + * A `^` token. + */ +schema CaretToken extends Token { +} + +impl CaretToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CaretToken { + for (tmp in Token(db)) { + if (isCaretToken(Node {id: tmp.id})) { + yield CaretToken { + id : tmp.id + } + } + } + } +} + +/** + * An `!` token. + */ +schema ExclamationToken extends Token { +} + +impl ExclamationToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExclamationToken { + for (tmp in Token(db)) { + if (isExclamationToken(Node {id: tmp.id})) { + yield ExclamationToken { + id : tmp.id + } + } + } + } +} + +/** + * A `~` token. + */ +schema TildeToken extends Token { +} + +impl TildeToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TildeToken { + for (tmp in Token(db)) { + if (isTildeToken(Node {id: tmp.id})) { + yield TildeToken { + id : tmp.id + } + } + } + } +} + +/** + * An `&&` token. + */ +schema AmpersandAmpersandToken extends Token { +} + +impl AmpersandAmpersandToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AmpersandAmpersandToken { + for (tmp in Token(db)) { + if (isAmpersandAmpersandToken(Node {id: tmp.id})) { + yield AmpersandAmpersandToken { + id : tmp.id + } + } + } + } +} + +/** + * A `||` token. + */ +schema BarBarToken extends Token { +} + +impl BarBarToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BarBarToken { + for (tmp in Token(db)) { + if (isBarBarToken(Node {id: tmp.id})) { + yield BarBarToken { + id : tmp.id + } + } + } + } +} + +/** + * A `?` token. + */ +schema QuestionToken extends Token { +} + +impl QuestionToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *QuestionToken { + for (tmp in Token(db)) { + if (isQuestionToken(Node {id: tmp.id})) { + yield QuestionToken { + id : tmp.id + } + } + } + } +} + +/** + * A `??` token. + */ +schema QuestionQuestionToken extends Token { +} + +impl QuestionQuestionToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *QuestionQuestionToken { + for (tmp in Token(db)) { + if (isQuestionQuestionToken(Node {id: tmp.id})) { + yield QuestionQuestionToken { + id : tmp.id + } + } + } + } +} + +/** + * An `=` token. + */ +schema EqualsToken extends Token { +} + +impl EqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EqualsToken { + for (tmp in Token(db)) { + if (isEqualsToken(Node {id: tmp.id})) { + yield EqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `+=` token. + */ +schema PlusEqualsToken extends Token { +} + +impl PlusEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PlusEqualsToken { + for (tmp in Token(db)) { + if (isPlusEqualsToken(Node {id: tmp.id})) { + yield PlusEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `-=` token. + */ +schema MinusEqualsToken extends Token { +} + +impl MinusEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MinusEqualsToken { + for (tmp in Token(db)) { + if (isMinusEqualsToken(Node {id: tmp.id})) { + yield MinusEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * An `*=` token. + */ +schema AsteriskEqualsToken extends Token { +} + +impl AsteriskEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AsteriskEqualsToken { + for (tmp in Token(db)) { + if (isAsteriskEqualsToken(Node {id: tmp.id})) { + yield AsteriskEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * An `**=` token. + */ +schema AsteriskAsteriskEqualsToken extends Token { +} + +impl AsteriskAsteriskEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AsteriskAsteriskEqualsToken { + for (tmp in Token(db)) { + if (isAsteriskAsteriskEqualsToken(Node {id: tmp.id})) { + yield AsteriskAsteriskEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `/=` token. + */ +schema SlashEqualsToken extends Token { +} + +impl SlashEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SlashEqualsToken { + for (tmp in Token(db)) { + if (isSlashEqualsToken(Node {id: tmp.id})) { + yield SlashEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `%=` token. + */ +schema PercentEqualsToken extends Token { +} + +impl PercentEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PercentEqualsToken { + for (tmp in Token(db)) { + if (isPercentEqualsToken(Node {id: tmp.id})) { + yield PercentEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `<<=` token. + */ +schema LessThanLessThanEqualsToken extends Token { +} + +impl LessThanLessThanEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LessThanLessThanEqualsToken { + for (tmp in Token(db)) { + if (isLessThanLessThanEqualsToken(Node {id: tmp.id})) { + yield LessThanLessThanEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `>>=` token. + */ +schema GreaterThanGreaterThanEqualsToken extends Token { +} + +impl GreaterThanGreaterThanEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GreaterThanGreaterThanEqualsToken { + for (tmp in Token(db)) { + if (isGreaterThanGreaterThanEqualsToken(Node {id: tmp.id})) { + yield GreaterThanGreaterThanEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `>>>=` token. + */ +schema GreaterThanGreaterThanGreaterThanEqualsToken extends Token { +} + +impl GreaterThanGreaterThanGreaterThanEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *GreaterThanGreaterThanGreaterThanEqualsToken { + for (tmp in Token(db)) { + if (isGreaterThanGreaterThanGreaterThanEqualsToken(Node {id: tmp.id})) { + yield GreaterThanGreaterThanGreaterThanEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * An `&=` token. + */ +schema AmpersandEqualsToken extends Token { +} + +impl AmpersandEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AmpersandEqualsToken { + for (tmp in Token(db)) { + if (isAmpersandEqualsToken(Node {id: tmp.id})) { + yield AmpersandEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `|=` token. + */ +schema BarEqualsToken extends Token { +} + +impl BarEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BarEqualsToken { + for (tmp in Token(db)) { + if (isBarEqualsToken(Node {id: tmp.id})) { + yield BarEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `||=` token. + */ +schema BarBarEqualsToken extends Token { +} + +impl BarBarEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BarBarEqualsToken { + for (tmp in Token(db)) { + if (isBarBarEqualsToken(Node {id: tmp.id})) { + yield BarBarEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * An `&&=` token. + */ +schema AmpersandAmpersandEqualsToken extends Token { +} + +impl AmpersandAmpersandEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AmpersandAmpersandEqualsToken { + for (tmp in Token(db)) { + if (isAmpersandAmpersandEqualsToken(Node {id: tmp.id})) { + yield AmpersandAmpersandEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `??=` token. + */ +schema QuestionQuestionEqualsToken extends Token { +} + +impl QuestionQuestionEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *QuestionQuestionEqualsToken { + for (tmp in Token(db)) { + if (isQuestionQuestionEqualsToken(Node {id: tmp.id})) { + yield QuestionQuestionEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * A `^=` token. + */ +schema CaretEqualsToken extends Token { +} + +impl CaretEqualsToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CaretEqualsToken { + for (tmp in Token(db)) { + if (isCaretEqualsToken(Node {id: tmp.id})) { + yield CaretEqualsToken { + id : tmp.id + } + } + } + } +} + +/** + * An identifier token. + */ +schema IdentifierToken extends Token { +} + +impl IdentifierToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IdentifierToken { + for (tmp in Token(db)) { + if (isIdentifier(Node {id: tmp.id})) { + yield IdentifierToken { + id : tmp.id + } + } + } + } +} + +/** + * A private identifier. + */ +schema PrivateIdentifierToken extends Token { +} + +impl PrivateIdentifierToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PrivateIdentifierToken { + for (tmp in Token(db)) { + if (isPrivateIdentifier(Node {id: tmp.id})) { + yield PrivateIdentifierToken { + id : tmp.id + } + } + } + } +} + +/** + * An `extends` keyword. + */ +schema ExtendsKeyword extends Token { +} + +impl ExtendsKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExtendsKeyword { + for (tmp in Token(db)) { + if (isExtendsKeyword(Node {id: tmp.id})) { + yield ExtendsKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `false` keyword. + */ +schema FalseKeyword extends Token { +} + +impl FalseKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FalseKeyword { + for (tmp in Token(db)) { + if (isFalseKeyword(Node {id: tmp.id})) { + yield FalseKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `import` keyword. + */ +schema ImportKeyword extends Token { +} + +impl ImportKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ImportKeyword { + for (tmp in Token(db)) { + if (isImportKeyword(Node {id: tmp.id})) { + yield ImportKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `in` keyword. + */ +schema InKeyword extends Token { +} + +impl InKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *InKeyword { + for (tmp in Token(db)) { + if (isInKeyword(Node {id: tmp.id})) { + yield InKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `instanceof` keyword. + */ +schema InstanceOfKeyword extends Token { +} + +impl InstanceOfKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *InstanceOfKeyword { + for (tmp in Token(db)) { + if (isInstanceOfKeyword(Node {id: tmp.id})) { + yield InstanceOfKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `null` keyword. + */ +schema NullKeyword extends Token { +} + +impl NullKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NullKeyword { + for (tmp in Token(db)) { + if (isNullKeyword(Node {id: tmp.id})) { + yield NullKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `super` keyword. + */ +schema SuperKeyword extends Token { +} + +impl SuperKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SuperKeyword { + for (tmp in Token(db)) { + if (isSuperKeyword(Node {id: tmp.id})) { + yield SuperKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `this` keyword. + */ +schema ThisKeyword extends Token { +} + +impl ThisKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ThisKeyword { + for (tmp in Token(db)) { + if (isThisKeyword(Node {id: tmp.id})) { + yield ThisKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `true` keyword. + */ +schema TrueKeyword extends Token { +} + +impl TrueKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TrueKeyword { + for (tmp in Token(db)) { + if (isTrueKeyword(Node {id: tmp.id})) { + yield TrueKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `void` keyword. + */ +schema VoidKeyword extends Token { +} + +impl VoidKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *VoidKeyword { + for (tmp in Token(db)) { + if (isVoidKeyword(Node {id: tmp.id})) { + yield VoidKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `implements` keyword. + */ +schema ImplementsKeyword extends Token { +} + +impl ImplementsKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ImplementsKeyword { + for (tmp in Token(db)) { + if (isImplementsKeyword(Node {id: tmp.id})) { + yield ImplementsKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `any` keyword. + */ +schema AnyKeyword extends Token { +} + +impl AnyKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AnyKeyword { + for (tmp in Token(db)) { + if (isAnyKeyword(Node {id: tmp.id})) { + yield AnyKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `await` keyword. + */ +schema AwaitKeyword extends Token { +} + +impl AwaitKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AwaitKeyword { + for (tmp in Token(db)) { + if (isAwaitKeyword(Node {id: tmp.id})) { + yield AwaitKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `boolean` keyword. + */ +schema BooleanKeyword extends Token { +} + +impl BooleanKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BooleanKeyword { + for (tmp in Token(db)) { + if (isBooleanKeyword(Node {id: tmp.id})) { + yield BooleanKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `intrinsic` keyword. + */ +schema IntrinsicKeyword extends Token { +} + +impl IntrinsicKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IntrinsicKeyword { + for (tmp in Token(db)) { + if (isIntrinsicKeyword(Node {id: tmp.id})) { + yield IntrinsicKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `never` keyword. + */ +schema NeverKeyword extends Token { +} + +impl NeverKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NeverKeyword { + for (tmp in Token(db)) { + if (isNeverKeyword(Node {id: tmp.id})) { + yield NeverKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `number` keyword. + */ +schema NumberKeyword extends Token { +} + +impl NumberKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NumberKeyword { + for (tmp in Token(db)) { + if (isNumberKeyword(Node {id: tmp.id})) { + yield NumberKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `object` keyword. + */ +schema ObjectKeyword extends Token { +} + +impl ObjectKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ObjectKeyword { + for (tmp in Token(db)) { + if (isObjectKeyword(Node {id: tmp.id})) { + yield ObjectKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `string` keyword. + */ +schema StringKeyword extends Token { +} + +impl StringKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *StringKeyword { + for (tmp in Token(db)) { + if (isStringKeyword(Node {id: tmp.id})) { + yield StringKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `symbol` keyword. + */ +schema SymbolKeyword extends Token { +} + +impl SymbolKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *SymbolKeyword { + for (tmp in Token(db)) { + if (isSymbolKeyword(Node {id: tmp.id})) { + yield SymbolKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `undefined` keyword. + */ +schema UndefinedKeyword extends Token { +} + +impl UndefinedKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UndefinedKeyword { + for (tmp in Token(db)) { + if (isUndefinedKeyword(Node {id: tmp.id})) { + yield UndefinedKeyword { + id : tmp.id + } + } + } + } +} + +/** + * An `unknown` keyword. + */ +schema UnknownKeyword extends Token { +} + +impl UnknownKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UnknownKeyword { + for (tmp in Token(db)) { + if (isUnknownKeyword(Node {id: tmp.id})) { + yield UnknownKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A `bigint` keyword. + */ +schema BigIntKeyword extends Token { +} + +impl BigIntKeyword { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BigIntKeyword { + for (tmp in Token(db)) { + if (isBigIntKeyword(Node {id: tmp.id})) { + yield BigIntKeyword { + id : tmp.id + } + } + } + } +} + +/** + * A prefix unary operator. + */ +schema PrefixUnaryOperator extends Token { +} + +impl PrefixUnaryOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PrefixUnaryOperator { + for (tmp in Token(db)) { + if (isPrefixUnaryOperator(Node {id: tmp.id})) { + yield PrefixUnaryOperator { + id : tmp.id + } + } + } + } +} + +/** + * A postfix unary operator. + */ +schema PostfixUnaryOperator extends Token { +} + +impl PostfixUnaryOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PostfixUnaryOperator { + for (tmp in Token(db)) { + if (isPostfixUnaryOperator(Node {id: tmp.id})) { + yield PostfixUnaryOperator { + id : tmp.id + } + } + } + } +} + +/** + * An update operator. + */ +schema UpdateOperator extends Token { +} + +impl UpdateOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UpdateOperator { + for (tmp in Token(db)) { + if (isUpdateOperator(Node {id: tmp.id})) { + yield UpdateOperator { + id : tmp.id + } + } + } + } +} + +/** + * An exponentiation operator `**`. + */ +schema ExponentiationOperator extends Token { +} + +impl ExponentiationOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExponentiationOperator { + for (tmp in Token(db)) { + if (isExponentiationOperator(Node {id: tmp.id})) { + yield ExponentiationOperator { + id : tmp.id + } + } + } + } +} + +/** + * A multiplicative operator `*`, `/` or `%`. + */ +schema MultiplicativeOperator extends Token { +} + +impl MultiplicativeOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MultiplicativeOperator { + for (tmp in Token(db)) { + if (isMultiplicativeOperator(Node {id: tmp.id})) { + yield MultiplicativeOperator { + id : tmp.id + } + } + } + } +} + +/** + * An additive operator `+` or `-`. + */ +schema AdditiveOperator extends Token { +} + +impl AdditiveOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AdditiveOperator { + for (tmp in Token(db)) { + if (isAdditiveOperator(Node {id: tmp.id})) { + yield AdditiveOperator { + id : tmp.id + } + } + } + } +} + +/** + * A shift operator `<<`, `>>` or `>>>`. + */ +schema ShiftOperator extends Token { +} + +impl ShiftOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ShiftOperator { + for (tmp in Token(db)) { + if (isShiftOperator(Node {id: tmp.id})) { + yield ShiftOperator { + id : tmp.id + } + } + } + } +} + +/** + * A relational operator `<`, `<=`, `>`, `>=`, `instanceof` or `in`. + */ +schema RelationalOperator extends Token { +} + +impl RelationalOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RelationalOperator { + for (tmp in Token(db)) { + if (isRelationalOperator(Node {id: tmp.id})) { + yield RelationalOperator { + id : tmp.id + } + } + } + } +} + +/** + * An equality operator `==`, `!=`, `===` or `!==`. + */ +schema EqualityOperator extends Token { +} + +impl EqualityOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *EqualityOperator { + for (tmp in Token(db)) { + if (isEqualityOperator(Node {id: tmp.id})) { + yield EqualityOperator { + id : tmp.id + } + } + } + } +} + +/** + * A binary bitwise operator `&`, `|` or `^`. + */ +schema BinaryBitwiseOperator extends Token { +} + +impl BinaryBitwiseOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BinaryBitwiseOperator { + for (tmp in Token(db)) { + if (isBinaryBitwiseOperator(Node {id: tmp.id})) { + yield BinaryBitwiseOperator { + id : tmp.id + } + } + } + } +} + +/** + * A logical operator `&&`, `||` or `??`. + */ +schema BinaryLogicalOperator extends Token { +} + +impl BinaryLogicalOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BinaryLogicalOperator { + for (tmp in Token(db)) { + if (isBinaryLogicalOperator(Node {id: tmp.id})) { + yield BinaryLogicalOperator { + id : tmp.id + } + } + } + } +} + +/** + * A compound assignment operator. + * `+=`, `-=`, `**=`, `*=`, `/=`, `%=`, `&=`, `|=`, `^=`, `<<=`, `>>=`, `>>>=`, + * `&&=`, `||=` or `??=`. + */ +schema CompoundAssignmentOperator extends Token { +} + +impl CompoundAssignmentOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CompoundAssignmentOperator { + for (tmp in Token(db)) { + if (isCompoundAssignmentOperator(Node {id: tmp.id})) { + yield CompoundAssignmentOperator { + id : tmp.id + } + } + } + } +} + +/** + * A simple assignment operator `=` or a compound assignment operator. + */ +schema AssignmentOperator extends Token { +} + +impl AssignmentOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *AssignmentOperator { + for (tmp in Token(db)) { + if (isAssignmentOperator(Node {id: tmp.id})) { + yield AssignmentOperator { + id : tmp.id + } + } + } + } +} + +/** + * A binary operator. + */ +schema BinaryOperator extends Token { +} + +impl BinaryOperator { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *BinaryOperator { + for (tmp in Token(db)) { + if (isBinaryOperator(Node {id: tmp.id})) { + yield BinaryOperator { + id : tmp.id + } + } + } + } +} + +/** + * A keyword token. + */ +schema KeywordToken extends Token { +} + +impl KeywordToken { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *KeywordToken { + for (tmp in Token(db)) { + if (isKeywordToken(Node {id: tmp.id})) { + yield KeywordToken { + id : tmp.id + } + } + } + } +} + +/** + * Determines whether a node is a token. + */ +pub fn isToken(node: Node) -> bool { + let (kind = node.getKind()) { + if (isTokenKind(kind)) { + return true + } + } +} + +/** + * Determines whether a node is an unknown token. + */ +pub fn isUnknown(node: Node) -> bool { + if (node.getKind() = 0) { + return true + } +} + +/** + * Determines whether a node is an end-of-file token. + */ +pub fn isEndOfFileToken(node: Node) -> bool { + if (node.getKind() = 1) { + return true + } +} + +/** + * Determines whether a node is a numeric literal. + */ +pub fn isNumericLiteral(node: Node) -> bool { + if (node.getKind() = 8) { + return true + } +} + +/** + * Determines whether a node is a big-int literal. + */ +pub fn isBigIntLiteral(node: Node) -> bool { + if (node.getKind() = 9) { + return true + } +} + +/** + * Determines whether a node is a string literal. + */ +pub fn isStringLiteral(node: Node) -> bool { + if (node.getKind() = 10) { + return true + } +} + +/** + * Determines whether a node is a JSX text. + */ +pub fn isJsxText(node: Node) -> bool { + if (node.getKind() = 11) { + return true + } +} + +/** + * Determines whether a node is a regular expression literal. + */ +pub fn isRegularExpressionLiteral(node: Node) -> bool { + if (node.getKind() = 13) { + return true + } +} + +/** + * Determines whether a node is a no-substitution template literal. + */ +pub fn isNoSubstitutionTemplateLiteral(node: Node) -> bool { + if (node.getKind() = 14) { + return true + } +} + +/** + * Determines whether a node is a template head. + */ +pub fn isTemplateHead(node: Node) -> bool { + if (node.getKind() = 15) { + return true + } +} + +/** + * Determines whether a node is a template middle. + */ +pub fn isTemplateMiddle(node: Node) -> bool { + if (node.getKind() = 16) { + return true + } +} + +/** + * Determines whether a node is a template tail. + */ +pub fn isTemplateTail(node: Node) -> bool { + if (node.getKind() = 17) { + return true + } +} + +/** + * Determines whether a node is a `...` token. + */ +pub fn isDotDotDotToken(node: Node) -> bool { + if (node.getKind() = 25) { + return true + } +} + +/** + * Determines whether a node is a `,` token. + */ +pub fn isCommaToken(node: Node) -> bool { + if (node.getKind() = 27) { + return true + } +} + +/** + * Determines whether a node is a `?.` token. + */ +pub fn isQuestionDotToken(node: Node) -> bool { + if (node.getKind() = 28) { + return true + } +} + +/** + * Determines whether a node is a `<` token. + */ +pub fn isLessThanToken(node: Node) -> bool { + if (node.getKind() = 29) { + return true + } +} + +/** + * Determines whether a node is a `>` token. + */ +pub fn isGreaterThanToken(node: Node) -> bool { + if (node.getKind() = 31) { + return true + } +} + +/** + * Determines whether a node is a `<=` token. + */ +pub fn isLessThanEqualsToken(node: Node) -> bool { + if (node.getKind() = 32) { + return true + } +} + +/** + * Determines whether a node is a `>=` token. + */ +pub fn isGreaterThanEqualsToken(node: Node) -> bool { + if (node.getKind() = 33) { + return true + } +} + +/** + * Determines whether a node is an `==` token. + */ +pub fn isEqualsEqualsToken(node: Node) -> bool { + if (node.getKind() = 34) { + return true + } +} + +/** + * Determines whether a node is a `!=` token. + */ +pub fn isExclamationEqualsToken(node: Node) -> bool { + if (node.getKind() = 35) { + return true + } +} + +/** + * Determines whether a node is an `===` token. + */ +pub fn isEqualsEqualsEqualsToken(node: Node) -> bool { + if (node.getKind() = 36) { + return true + } +} + +/** + * Determines whether a node is a `!==` token. + */ +pub fn isExclamationEqualsEqualsToken(node: Node) -> bool { + if (node.getKind() = 37) { + return true + } +} + +/** + * Determines whether a node is a `+` token. + */ +pub fn isPlusToken(node: Node) -> bool { + if (node.getKind() = 39) { + return true + } +} + +/** + * Determines whether a node is a `-` token. + */ +pub fn isMinusToken(node: Node) -> bool { + if (node.getKind() = 40) { + return true + } +} + +/** + * Determines whether a node is a `*` token. + */ +pub fn isAsteriskToken(node: Node) -> bool { + if (node.getKind() = 41) { + return true + } +} + +/** + * Determines whether a node is a `**` token. + */ +pub fn isAsteriskAsteriskToken(node: Node) -> bool { + if (node.getKind() = 42) { + return true + } +} + +/** + * Determines whether a node is a `/` token. + */ +pub fn isSlashToken(node: Node) -> bool { + if (node.getKind() = 43) { + return true + } +} + +/** + * Determines whether a node is a `%` token. + */ +pub fn isPercentToken(node: Node) -> bool { + if (node.getKind() = 44) { + return true + } +} + +/** + * Determines whether a node is a `++` token. + */ +pub fn isPlusPlusToken(node: Node) -> bool { + if (node.getKind() = 45) { + return true + } +} + +/** + * Determines whether a node is a `--` token. + */ +pub fn isMinusMinusToken(node: Node) -> bool { + if (node.getKind() = 46) { + return true + } +} + +/** + * Determines whether a node is a `<<` token. + */ +pub fn isLessThanLessThanToken(node: Node) -> bool { + if (node.getKind() = 47) { + return true + } +} + +/** + * Determines whether a node is a `>>` token. + */ +pub fn isGreaterThanGreaterThanToken(node: Node) -> bool { + if (node.getKind() = 48) { + return true + } +} + +/** + * Determines whether a node is a `>>>` token. + */ +pub fn isGreaterThanGreaterThanGreaterThanToken(node: Node) -> bool { + if (node.getKind() = 49) { + return true + } +} + +/** + * Determines whether a node is a `&` token. + */ +pub fn isAmpersandToken(node: Node) -> bool { + if (node.getKind() = 50) { + return true + } +} + +/** + * Determines whether a node is a `|` token. + */ +pub fn isBarToken(node: Node) -> bool { + if (node.getKind() = 51) { + return true + } +} + +/** + * Determines whether a node is a `^` token. + */ +pub fn isCaretToken(node: Node) -> bool { + if (node.getKind() = 52) { + return true + } +} + +/** + * Determines whether a node is an `!` token. + */ +pub fn isExclamationToken(node: Node) -> bool { + if (node.getKind() = 53) { + return true + } +} + +/** + * Determines whether a node is a `~` token. + */ +pub fn isTildeToken(node: Node) -> bool { + if (node.getKind() = 54) { + return true + } +} + +/** + * Determines whether a node is an `&&` token. + */ +pub fn isAmpersandAmpersandToken(node: Node) -> bool { + if (node.getKind() = 55) { + return true + } +} + +/** + * Determines whether a node is a `||` token. + */ +pub fn isBarBarToken(node: Node) -> bool { + if (node.getKind() = 56) { + return true + } +} + +/** + * Determines whether a node is a `?` token. + */ +pub fn isQuestionToken(node: Node) -> bool { + if (node.getKind() = 57) { + return true + } +} + +/** + * Determines whether a node is a `??` token. + */ +pub fn isQuestionQuestionToken(node: Node) -> bool { + if (node.getKind() = 60) { + return true + } +} + +/** + * Determines whether a node is an `=` token. + */ +pub fn isEqualsToken(node: Node) -> bool { + if (node.getKind() = 63) { + return true + } +} + +/** + * Determines whether a node is a `+=` token. + */ +pub fn isPlusEqualsToken(node: Node) -> bool { + if (node.getKind() = 64) { + return true + } +} + +/** + * Determines whether a node is a `-=` token. + */ +pub fn isMinusEqualsToken(node: Node) -> bool { + if (node.getKind() = 65) { + return true + } +} + +/** + * Determines whether a node is an `*=` token. + */ +pub fn isAsteriskEqualsToken(node: Node) -> bool { + if (node.getKind() = 66) { + return true + } +} + +/** + * Determines whether a node is an `**=` token. + */ +pub fn isAsteriskAsteriskEqualsToken(node: Node) -> bool { + if (node.getKind() = 67) { + return true + } +} + +/** + * Determines whether a node is a `/=` token. + */ +pub fn isSlashEqualsToken(node: Node) -> bool { + if (node.getKind() = 68) { + return true + } +} + +/** + * Determines whether a node is a `%=` token. + */ +pub fn isPercentEqualsToken(node: Node) -> bool { + if (node.getKind() = 69) { + return true + } +} + +/** + * Determines whether a node is a `<<=` token. + */ +pub fn isLessThanLessThanEqualsToken(node: Node) -> bool { + if (node.getKind() = 70) { + return true + } +} + +/** + * Determines whether a node is a `>>=` token. + */ +pub fn isGreaterThanGreaterThanEqualsToken(node: Node) -> bool { + if (node.getKind() = 71) { + return true + } +} + +/** + * Determines whether a node is a `>>>=` token. + */ +pub fn isGreaterThanGreaterThanGreaterThanEqualsToken(node: Node) -> bool { + if (node.getKind() = 72) { + return true + } +} + +/** + * Determines whether a node is an `&=` token. + */ +pub fn isAmpersandEqualsToken(node: Node) -> bool { + if (node.getKind() = 73) { + return true + } +} + +/** + * Determines whether a node is a `|=` token. + */ +pub fn isBarEqualsToken(node: Node) -> bool { + if (node.getKind() = 74) { + return true + } +} + +/** + * Determines whether a node is a `||=` token. + */ +pub fn isBarBarEqualsToken(node: Node) -> bool { + if (node.getKind() = 75) { + return true + } +} + +/** + * Determines whether a node is an `&&=` token. + */ +pub fn isAmpersandAmpersandEqualsToken(node: Node) -> bool { + if (node.getKind() = 76) { + return true + } +} + +/** + * Determines whether a node is a `??=` token. + */ +pub fn isQuestionQuestionEqualsToken(node: Node) -> bool { + if (node.getKind() = 77) { + return true + } +} + +/** + * Determines whether a node is a `^=` token. + */ +pub fn isCaretEqualsToken(node: Node) -> bool { + if (node.getKind() = 78) { + return true + } +} + +/** + * Determines whether a node is an identifier. + */ +pub fn isIdentifier(node: Node) -> bool { + if (node.getKind() = 79) { + return true + } +} + +/** + * Determines whether a node is a private identifier. + */ +pub fn isPrivateIdentifier(node: Node) -> bool { + if (node.getKind() = 80) { + return true + } +} + +/** + * Determines whether a node is an `extends` keyword. + */ +pub fn isExtendsKeyword(node: Node) -> bool { + if (node.getKind() = 94) { + return true + } +} + +/** + * Determines whether a node is a `false` keyword. + */ +pub fn isFalseKeyword(node: Node) -> bool { + if (node.getKind() = 95) { + return true + } +} + +/** + * Determines whether a node is an `import` keyword. + */ +pub fn isImportKeyword(node: Node) -> bool { + if (node.getKind() = 100) { + return true + } +} + +/** + * Determines whether a node is an `in` keyword. + */ +pub fn isInKeyword(node: Node) -> bool { + if (node.getKind() = 101) { + return true + } +} + +/** + * Determines whether a node is an `instanceof` keyword. + */ +pub fn isInstanceOfKeyword(node: Node) -> bool { + if (node.getKind() = 102) { + return true + } +} + +/** + * Determines whether a node is a `null` keyword. + */ +pub fn isNullKeyword(node: Node) -> bool { + if (node.getKind() = 104) { + return true + } +} + +/** + * Determines whether a node is a `super` keyword. + */ +pub fn isSuperKeyword(node: Node) -> bool { + if (node.getKind() = 106) { + return true + } +} + +/** + * Determines whether a node is a `this` keyword. + */ +pub fn isThisKeyword(node: Node) -> bool { + if (node.getKind() = 108) { + return true + } +} + +/** + * Determines whether a node is a `true` keyword. + */ +pub fn isTrueKeyword(node: Node) -> bool { + if (node.getKind() = 110) { + return true + } +} + +/** + * Determines whether a node is a `void` keyword. + */ +pub fn isVoidKeyword(node: Node) -> bool { + if (node.getKind() = 114) { + return true + } +} + +/** + * Determines whether a node is an `implements` keyword. + */ +pub fn isImplementsKeyword(node: Node) -> bool { + if (node.getKind() = 117) { + return true + } +} + +/** + * Determines whether a node is an `any` keyword. + */ +pub fn isAnyKeyword(node: Node) -> bool { + if (node.getKind() = 130) { + return true + } +} + +/** + * Determines whether a node is an `await` keyword. + */ +pub fn isAwaitKeyword(node: Node) -> bool { + if (node.getKind() = 132) { + return true + } +} + +/** + * Determines whether a node is a `boolean` keyword. + */ +pub fn isBooleanKeyword(node: Node) -> bool { + if (node.getKind() = 133) { + return true + } +} + +/** + * Determines whether a node is an `intrinsic` keyword. + */ +pub fn isIntrinsicKeyword(node: Node) -> bool { + if (node.getKind() = 138) { + return true + } +} + +/** + * Determines whether a node is a `never` keyword. + */ +pub fn isNeverKeyword(node: Node) -> bool { + if (node.getKind() = 143) { + return true + } +} + +/** + * Determines whether a node is a `number` keyword. + */ +pub fn isNumberKeyword(node: Node) -> bool { + if (node.getKind() = 146) { + return true + } +} + +/** + * Determines whether a node is an `object` keyword. + */ +pub fn isObjectKeyword(node: Node) -> bool { + if (node.getKind() = 147) { + return true + } +} + +/** + * Determines whether a node is a `string` keyword. + */ +pub fn isStringKeyword(node: Node) -> bool { + if (node.getKind() = 149) { + return true + } +} + +/** + * Determines whether a node is a `symbol` keyword. + */ +pub fn isSymbolKeyword(node: Node) -> bool { + if (node.getKind() = 150) { + return true + } +} + +/** + * Determines whether a node is an `undefined` keyword. + */ +pub fn isUndefinedKeyword(node: Node) -> bool { + if (node.getKind() = 152) { + return true + } +} + +/** + * Determines whether a node is an `unknown` keyword. + */ +pub fn isUnknownKeyword(node: Node) -> bool { + if (node.getKind() = 154) { + return true + } +} + +/** + * Determines whether a node is a `bigint` keyword. + */ +pub fn isBigIntKeyword(node: Node) -> bool { + if (node.getKind() = 157) { + return true + } +} + +/** + * Determines whether a node is a prefix unary operator. + */ +pub fn isPrefixUnaryOperator(node: Node) -> bool { + if (isPlusPlusToken(node)) { + return true + } + if (isMinusMinusToken(node)) { + return true + } + if (isPlusToken(node)) { + return true + } + if (isMinusToken(node)) { + return true + } + if (isTildeToken(node)) { + return true + } + if (isExclamationToken(node)) { + return true + } +} + +/** + * Determines whether a node is a postfix unary operator. + */ +pub fn isPostfixUnaryOperator(node: Node) -> bool { + if (isPlusPlusToken(node)) { + return true + } + if (isMinusMinusToken(node)) { + return true + } +} + +/** + * Determines whether a node is an update operator. + */ +pub fn isUpdateOperator(node: Node) -> bool { + if (isPlusPlusToken(node)) { + return true + } + if (isMinusMinusToken(node)) { + return true + } +} + +/** + * Determines whether a node is an exponentiation operator `**`. + */ +pub fn isExponentiationOperator(node: Node) -> bool { + if (isAsteriskAsteriskToken(node)) { + return true + } +} + +/** + * Determines whether a node is a multiplicative operator `*`, `/` or `%`. + */ +pub fn isMultiplicativeOperator(node: Node) -> bool { + if (isAsteriskToken(node)) { + return true + } + if (isSlashToken(node)) { + return true + } + if (isPercentToken(node)) { + return true + } +} + +/** + * Determines whether a node is a multiplicative operator or higher. + */ +pub fn isMultiplicativeOperatorOrHigher(node: Node) -> bool { + if (isExponentiationOperator(node)) { + return true + } + if (isMultiplicativeOperator(node)) { + return true + } +} + +/** + * Determines whether a node is an additive operator `+` or `-`. + */ +pub fn isAdditiveOperator(node: Node) -> bool { + if (isPlusToken(node)) { + return true + } + if (isMinusToken(node)) { + return true + } +} + +/** + * Determines whether a node is an additive operator or higher. + */ +pub fn isAdditiveOperatorOrHigher(node: Node) -> bool { + if (isMultiplicativeOperatorOrHigher(node)) { + return true + } + if (isAdditiveOperator(node)) { + return true + } +} + +/** + * Determines whether a node is a shift operator `<<`, `>>` or `>>>`. + */ +pub fn isShiftOperator(node: Node) -> bool { + if (isLessThanLessThanToken(node)) { + return true + } + if (isGreaterThanGreaterThanToken(node)) { + return true + } + if (isGreaterThanGreaterThanGreaterThanToken(node)) { + return true + } +} + +/** + * Determines whether a node is a shift operator or higher. + */ +pub fn isShiftOperatorOrHigher(node: Node) -> bool { + if (isAdditiveOperatorOrHigher(node)) { + return true + } + if (isShiftOperator(node)) { + return true + } +} + +/** + * Determines whether a node is a relational operator `<`, `<=`, `>`, `>=`, `instanceof` or `in`. + */ +pub fn isRelationalOperator(node: Node) -> bool { + if (isLessThanToken(node)) { + return true + } + if (isLessThanEqualsToken(node)) { + return true + } + if (isGreaterThanToken(node)) { + return true + } + if (isGreaterThanEqualsToken(node)) { + return true + } + if (isInstanceOfKeyword(node)) { + return true + } + if (isInKeyword(node)) { + return true + } +} + +/** + * Determines whether a node is a relational operator or higher. + */ +pub fn isRelationalOperatorOrHigher(node: Node) -> bool { + if (isShiftOperatorOrHigher(node)) { + return true + } + if (isRelationalOperator(node)) { + return true + } +} + +/** + * Determines whether a node is an equality operator `==`, `!=`, `===` or `!==`. + */ +pub fn isEqualityOperator(node: Node) -> bool { + if (isEqualsEqualsToken(node)) { + return true + } + if (isExclamationEqualsToken(node)) { + return true + } + if (isEqualsEqualsEqualsToken(node)) { + return true + } + if (isExclamationEqualsEqualsToken(node)) { + return true + } +} + +/** + * Determines whether a node is an equality operator or higher. + */ +pub fn isEqualityOperatorOrHigher(node: Node) -> bool { + if (isRelationalOperatorOrHigher(node)) { + return true + } + if (isEqualityOperator(node)) { + return true + } +} + +/** + * Determines whether a node is a binary bitwise operator `&`, `|` or `^`. + */ +pub fn isBinaryBitwiseOperator(node: Node) -> bool { + if (isAmpersandToken(node)) { + return true + } + if (isBarToken(node)) { + return true + } + if (isCaretToken(node)) { + return true + } +} + +/** + * Determines whether a node is a binary bitwise operator or higher. + */ +pub fn isBinaryBitwiseOperatorOrHigher(node: Node) -> bool { + if (isEqualityOperatorOrHigher(node)) { + return true + } + if (isBinaryBitwiseOperator(node)) { + return true + } +} + +/** + * Determines whether a node is a logical operator `&&`, `||` or `??`. + */ +pub fn isBinaryLogicalOperator(node: Node) -> bool { + if (isAmpersandAmpersandToken(node)) { + return true + } + if (isBarBarToken(node)) { + return true + } + if (isQuestionQuestionToken(node)) { + return true + } +} + +/** + * Determines whether a node is a logical operator or higher. + */ +pub fn isBinaryLogicalOperatorOrHigher(node: Node) -> bool { + if (isBinaryBitwiseOperatorOrHigher(node)) { + return true + } + if (isBinaryLogicalOperator(node)) { + return true + } +} + +/** + * Determines whether a node is a compound assignment operator + * `+=`, `-=`, `**=`, `*=`, `/=`, `%=`, `&=`, `|=`, `^=`, `<<=`, `>>=`, `>>>=`, + * `&&=`, `||=` or `??=`. + */ +pub fn isCompoundAssignmentOperator(node: Node) -> bool { + if (isPlusEqualsToken(node)) { + return true + } + if (isMinusEqualsToken(node)) { + return true + } + if (isAsteriskAsteriskEqualsToken(node)) { + return true + } + if (isAsteriskEqualsToken(node)) { + return true + } + if (isSlashEqualsToken(node)) { + return true + } + if (isPercentEqualsToken(node)) { + return true + } + if (isAmpersandEqualsToken(node)) { + return true + } + if (isBarEqualsToken(node)) { + return true + } + if (isCaretEqualsToken(node)) { + return true + } + if (isLessThanLessThanEqualsToken(node)) { + return true + } + if (isGreaterThanGreaterThanEqualsToken(node)) { + return true + } + if (isGreaterThanGreaterThanGreaterThanEqualsToken(node)) { + return true + } + if (isAmpersandAmpersandEqualsToken(node)) { + return true + } + if (isBarBarEqualsToken(node)) { + return true + } + if (isQuestionQuestionEqualsToken(node)) { + return true + } +} + +/** + * Determines whether a node is a simple assignment operator `=` or a compound + * assignment operator. + */ +pub fn isAssignmentOperator(node: Node) -> bool { + if (isEqualsToken(node)) { + return true + } + if (isCompoundAssignmentOperator(node)) { + return true + } +} + +/** + * Determines whether a node is an assignment operator or higher. + */ +pub fn isAssignmentOperatorOrHigher(node: Node) -> bool { + if (isBinaryLogicalOperatorOrHigher(node)) { + return true + } + if (isAssignmentOperator(node)) { + return true + } +} + +/** + * Determines whether a node is a binary operator. + */ +pub fn isBinaryOperator(node: Node) -> bool { + if (isAssignmentOperatorOrHigher(node)) { + return true + } + if (isCommaToken(node)) { + return true + } +} + +/** + * Determines whether a node is a keyword token. + */ +pub fn isKeywordToken(node: Node) -> bool { + let (kind = node.getKind()) { + if (kind >= 81) { + if (kind <= 159) { + return true + } + } + } +} + +/** + * Determines whether a node kind is a token kind. + */ +pub fn isTokenKind(kind: int) -> bool { + [ + {0}, // Unknown + {1}, // EndOfFileToken + {2}, // SingleLineCommentTrivia + {3}, // MultiLineCommentTrivia + {4}, // NewLineTrivia + {5}, // WhitespaceTrivia + {6}, // ShebangTrivia + {7}, // ConflictMarkerTrivia + {8}, // NumericLiteral + {9}, // BigIntLiteral + {10}, // StringLiteral + {11}, // JsxText + {12}, // JsxTextAllWhiteSpaces + {13}, // RegularExpressionLiteral + {14}, // NoSubstitutionTemplateLiteral + {15}, // TemplateHead + {16}, // TemplateMiddle + {17}, // TemplateTail + {18}, // OpenBraceToken + {19}, // CloseBraceToken + {20}, // OpenParenToken + {21}, // CloseParenToken + {22}, // OpenBracketToken + {23}, // CloseBracketToken + {24}, // DotToken + {25}, // DotDotDotToken + {26}, // SemicolonToken + {27}, // CommaToken + {28}, // QuestionDotToken + {29}, // LessThanToken + {30}, // LessThanSlashToken + {31}, // GreaterThanToken + {32}, // LessThanEqualsToken + {33}, // GreaterThanEqualsToken + {34}, // EqualsEqualsToken + {35}, // ExclamationEqualsToken + {36}, // EqualsEqualsEqualsToken + {37}, // ExclamationEqualsEqualsToken + {38}, // EqualsGreaterThanToken + {39}, // PlusToken + {40}, // MinusToken + {41}, // AsteriskToken + {42}, // AsteriskAsteriskToken + {43}, // SlashToken + {44}, // PercentToken + {45}, // PlusPlusToken + {46}, // MinusMinusToken + {47}, // LessThanLessThanToken + {48}, // GreaterThanGreaterThanToken + {49}, // GreaterThanGreaterThanGreaterThanToken + {50}, // AmpersandToken + {51}, // BarToken + {52}, // CaretToken + {53}, // ExclamationToken + {54}, // TildeToken + {55}, // AmpersandAmpersandToken + {56}, // BarBarToken + {57}, // QuestionToken + {58}, // ColonToken + {59}, // AtToken + {60}, // QuestionQuestionToken + {61}, // BacktickToken + {62}, // HashToken + {63}, // EqualsToken + {64}, // PlusEqualsToken + {65}, // MinusEqualsToken + {66}, // AsteriskEqualsToken + {67}, // AsteriskAsteriskEqualsToken + {68}, // SlashEqualsToken + {69}, // PercentEqualsToken + {70}, // LessThanLessThanEqualsToken + {71}, // GreaterThanGreaterThanEqualsToken + {72}, // GreaterThanGreaterThanGreaterThanEqualsToken + {73}, // AmpersandEqualsToken + {74}, // BarEqualsToken + {75}, // BarBarEqualsToken + {76}, // AmpersandAmpersandEqualsToken + {77}, // QuestionQuestionEqualsToken + {78}, // CaretEqualsToken + {79}, // Identifier + {80}, // PrivateIdentifier + {81}, // BreakKeyword + {82}, // CaseKeyword + {83}, // CatchKeyword + {84}, // ClassKeyword + {85}, // ConstKeyword + {86}, // ContinueKeyword + {87}, // DebuggerKeyword + {88}, // DefaultKeyword + {89}, // DeleteKeyword + {90}, // DoKeyword + {91}, // ElseKeyword + {92}, // EnumKeyword + {93}, // ExportKeyword + {94}, // ExtendsKeyword + {95}, // FalseKeyword + {96}, // FinallyKeyword + {97}, // ForKeyword + {98}, // FunctionKeyword + {99}, // IfKeyword + {100}, // ImportKeyword + {101}, // InKeyword + {102}, // InstanceOfKeyword + {103}, // NewKeyword + {104}, // NullKeyword + {105}, // ReturnKeyword + {106}, // SuperKeyword + {107}, // SwitchKeyword + {108}, // ThisKeyword + {109}, // ThrowKeyword + {110}, // TrueKeyword + {111}, // TryKeyword + {112}, // TypeOfKeyword + {113}, // VarKeyword + {114}, // VoidKeyword + {115}, // WhileKeyword + {116}, // WithKeyword + {117}, // ImplementsKeyword + {118}, // InterfaceKeyword + {119}, // LetKeyword + {120}, // PackageKeyword + {121}, // PrivateKeyword + {122}, // ProtectedKeyword + {123}, // PublicKeyword + {124}, // StaticKeyword + {125}, // YieldKeyword + {126}, // AbstractKeyword + {127}, // AsKeyword + {128}, // AssertsKeyword + {129}, // AssertKeyword + {130}, // AnyKeyword + {131}, // AsyncKeyword + {132}, // AwaitKeyword + {133}, // BooleanKeyword + {134}, // ConstructorKeyword + {135}, // DeclareKeyword + {136}, // GetKeyword + {137}, // InferKeyword + {138}, // IntrinsicKeyword + {139}, // IsKeyword + {140}, // KeyOfKeyword + {141}, // ModuleKeyword + {142}, // NamespaceKeyword + {143}, // NeverKeyword + {144}, // ReadonlyKeyword + {145}, // RequireKeyword + {146}, // NumberKeyword + {147}, // ObjectKeyword + {148}, // SetKeyword + {149}, // StringKeyword + {150}, // SymbolKeyword + {151}, // TypeKeyword + {152}, // UndefinedKeyword + {153}, // UniqueKeyword + {154}, // UnknownKeyword + {155}, // FromKeyword + {156}, // GlobalKeyword + {157}, // BigIntKeyword + {158}, // OverrideKeyword + {159}, // OfKeyword + ] +} diff --git a/language/javascript/lib/TopLevel.gdl b/language/javascript/lib/TopLevel.gdl new file mode 100644 index 00000000..d9f5c9b8 --- /dev/null +++ b/language/javascript/lib/TopLevel.gdl @@ -0,0 +1,131 @@ +/** + * @filename: Statement + * @brief: Provides classes and predicates for working with JavaScript / TypeScript top-levels. + */ + +schema TopLevel extends TopLevelDO { +} + +impl TopLevel { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TopLevel { + for (tmp in TopLevelDO(db)) { + yield TopLevel { + oid : tmp.oid, + kind : tmp.kind, + location_oid : tmp.location_oid + } + } + } + + /** + * Gets the location of this top-level. + */ + pub fn getLocation(self) -> Location { + for (location in Location(__all_data__)) { + if (location.oid = self.getLocationOid()) { + return location + } + } + } + + /** + * Gets a child node of this top-level. + */ + pub fn getAChild(self) -> *Node { + for (child in Node(__all_data__)) { + if (child.getParent().key_eq(self)) { + yield child + } + } + } + + /** + * Gets the `i`th child of this top-level. + */ + pub fn getChild(self, i: int) -> Node { + for (child in Node(__all_data__)) { + if (child.getIndex() = i) { + if (child.getParent().key_eq(self)) { + return child + } + } + } + } + + /** + * Get a statement of this top-level. + */ + pub fn getAStatement(self) -> *Statement { + for (statement in Statement(__all_data__)) { + if (statement.getParent().key_eq(self)) { + yield statement + } + } + } + + /** + * Get the `i`th statement of this top-level. + */ + pub fn getStatement(self, i: int) -> Statement { + for (statement in Statement(__all_data__)) { + if (statement.getIndex() = i) { + if (statement.getParent().key_eq(self)) { + return statement + } + } + } + } + + /** + * Gets a descendant of this top-level. + */ + pub fn getADescendant(self) -> *Node { + yield self.getAChild() + for (child in self.getAChild()) { + yield child.getADescendant() + } + } + + /** + * Gets a descendant of this top-level by the level of the hierarchy. + * + * @param level: the number of levels to go up in the hierarchy. + */ + pub fn getADescendantByLevel(self, level: int) -> *Node { + if (level = 1) { + yield self.getAChild() + } + for (child in self.getAChild()) { + for (childLevel in int::__undetermined_all__()) { + for (descendant in child.getADescendantByLevel(childLevel)) { + if (level = childLevel + 1) { + yield descendant + } + } + } + } + } + + /** + * Gets the text of this top-level. + */ + pub fn getText(self) -> string { + return self.getLocation().getText() + } + + /** + * Gets the number of child nodes. + */ + pub fn getChildCount(self) -> int { + return self.getAChild().len() + } + + /** + * Get the number of statements in this top-level. + */ + pub fn getStatementCount(self) -> int { + return self.getAStatement().len() + } +} diff --git a/language/javascript/lib/Type.gdl b/language/javascript/lib/Type.gdl new file mode 100644 index 00000000..91e24350 --- /dev/null +++ b/language/javascript/lib/Type.gdl @@ -0,0 +1,1268 @@ +/** + * @filename: Type + * @brief: Provides classes and predicates for working with JavaScript / TypeScript types. + */ + +/** + * A type node. + */ +schema TypeNode extends Node { +} + +impl TypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeNode { + for (tmp in Node(db)) { + if (isTypeNode(tmp)) { + yield TypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A keyword type node. + */ +schema KeywordTypeNode extends TypeNode { +} + +impl KeywordTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *KeywordTypeNode { + for (tmp in TypeNode(db)) { + if (isKeywordTypeNode(Node {id: tmp.id})) { + yield KeywordTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A type predicate. + */ +schema TypePredicateNode extends TypeNode { +} + +impl TypePredicateNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypePredicateNode { + for (tmp in TypeNode(db)) { + if (isTypePredicate(Node {id: tmp.id})) { + yield TypePredicateNode { + id : tmp.id + } + } + } + } +} + +/** + * A function type node. + */ +schema FunctionTypeNode extends TypeNode { +} + +impl FunctionTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *FunctionTypeNode { + for (tmp in TypeNode(db)) { + if (isFunctionType(Node {id: tmp.id})) { + yield FunctionTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A constructor type node. + */ +schema ConstructorTypeNode extends TypeNode { +} + +impl ConstructorTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ConstructorTypeNode { + for (tmp in TypeNode(db)) { + if (isConstructorType(Node {id: tmp.id})) { + yield ConstructorTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A type query node. + */ +schema TypeQueryNode extends TypeNode { +} + +impl TypeQueryNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeQueryNode { + for (tmp in TypeNode(db)) { + if (isTypeQuery(Node {id: tmp.id})) { + yield TypeQueryNode { + id : tmp.id + } + } + } + } +} + +/** + * A type literal node. + */ +schema TypeLiteralNode extends TypeNode { +} + +impl TypeLiteralNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeLiteralNode { + for (tmp in TypeNode(db)) { + if (isTypeLiteral(Node {id: tmp.id})) { + yield TypeLiteralNode { + id : tmp.id + } + } + } + } +} + +/** + * An array type node. + */ +schema ArrayTypeNode extends TypeNode { +} + +impl ArrayTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ArrayTypeNode { + for (tmp in TypeNode(db)) { + if (isArrayType(Node {id: tmp.id})) { + yield ArrayTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A tuple type node. + */ +schema TupleTypeNode extends TypeNode { +} + +impl TupleTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TupleTypeNode { + for (tmp in TypeNode(db)) { + if (isTupleType(Node {id: tmp.id})) { + yield TupleTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * An optional type node. + */ +schema OptionalTypeNode extends TypeNode { +} + +impl OptionalTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *OptionalTypeNode { + for (tmp in TypeNode(db)) { + if (isOptionalType(Node {id: tmp.id})) { + yield OptionalTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A rest type node. + */ +schema RestTypeNode extends TypeNode { +} + +impl RestTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *RestTypeNode { + for (tmp in TypeNode(db)) { + if (isRestType(Node {id: tmp.id})) { + yield RestTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * An union type node. + */ +schema UnionTypeNode extends TypeNode { +} + +impl UnionTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *UnionTypeNode { + for (tmp in TypeNode(db)) { + if (isUnionType(Node {id: tmp.id})) { + yield UnionTypeNode { + id : tmp.id + } + } + } + } + + pub fn getAType(self) -> *TypeNode { + for (typeNode in TypeNode(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeNode.key_eq(auto_tmp1)) { + yield typeNode + } + } + } + } + + pub fn getType(self, i: int) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + if (typeNode.key_eq(self.getChild(i))) { + return typeNode + } + } + } +} + +/** + * An intersection type node. + */ +schema IntersectionTypeNode extends TypeNode { +} + +impl IntersectionTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IntersectionTypeNode { + for (tmp in TypeNode(db)) { + if (isIntersectionType(Node {id: tmp.id})) { + yield IntersectionTypeNode { + id : tmp.id + } + } + } + } + + pub fn getAType(self) -> *TypeNode { + for (typeNode in TypeNode(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (typeNode.key_eq(auto_tmp1)) { + yield typeNode + } + } + } + } + + pub fn getType(self, i: int) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + if (typeNode.key_eq(self.getChild(i))) { + return typeNode + } + } + } +} + +/** + * A conditional type node. + */ +schema ConditionalTypeNode extends TypeNode { +} + +impl ConditionalTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ConditionalTypeNode { + for (tmp in TypeNode(db)) { + if (isConditionalType(Node {id: tmp.id})) { + yield ConditionalTypeNode { + id : tmp.id + } + } + } + } + + pub fn getCheckType(self) -> TypeNode { + for (checkType in TypeNode(__all_data__)) { + if (checkType.key_eq(self.getChild(0))) { + return checkType + } + } + } + + pub fn getExtendsType(self) -> TypeNode { + for (extendsType in TypeNode(__all_data__)) { + if (extendsType.key_eq(self.getChild(1))) { + return extendsType + } + } + } + + pub fn getThenType(self) -> TypeNode { + for (thenType in TypeNode(__all_data__)) { + if (thenType.key_eq(self.getChild(2))) { + return thenType + } + } + } + + pub fn getElseType(self) -> TypeNode { + for (elseType in TypeNode(__all_data__)) { + if (elseType.key_eq(self.getChild(3))) { + return elseType + } + } + } +} + +/** + * A infer type node. + */ +schema InferTypeNode extends TypeNode { +} + +impl InferTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *InferTypeNode { + for (tmp in TypeNode(db)) { + if (isInferType(Node {id: tmp.id})) { + yield InferTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A parenthesized type node. + */ +schema ParenthesizedTypeNode extends TypeNode { +} + +impl ParenthesizedTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ParenthesizedTypeNode { + for (tmp in TypeNode(db)) { + if (isParenthesizedType(Node {id: tmp.id})) { + yield ParenthesizedTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A this type node. + */ +schema ThisTypeNode extends TypeNode { +} + +impl ThisTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ThisTypeNode { + for (tmp in TypeNode(db)) { + if (isThisType(Node {id: tmp.id})) { + yield ThisTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A type operator node. + */ +schema TypeOperatorNode extends TypeNode { +} + +impl TypeOperatorNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeOperatorNode { + for (tmp in TypeNode(db)) { + if (isTypeOperator(Node {id: tmp.id})) { + yield TypeOperatorNode { + id : tmp.id + } + } + } + } + + pub fn getOperator(self) -> KeywordToken { + for (typeOperator in KeywordToken(__all_data__)) { + if (typeOperator.key_eq(self.getChild(0))) { + return typeOperator + } + } + } + + pub fn getType(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + if (typeNode.key_eq(self.getChild(1))) { + return typeNode + } + } + } +} + +/** + * An indexed access type node. + */ +schema IndexedAccessTypeNode extends TypeNode { +} + +impl IndexedAccessTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IndexedAccessTypeNode { + for (tmp in TypeNode(db)) { + if (isIndexedAccessType(Node {id: tmp.id})) { + yield IndexedAccessTypeNode { + id : tmp.id + } + } + } + } + + pub fn getObjectType(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + if (typeNode.key_eq(self.getChild(0))) { + return typeNode + } + } + } + + pub fn getIndexType(self) -> TypeNode { + for (typeNode in TypeNode(__all_data__)) { + if (typeNode.key_eq(self.getChild(1))) { + return typeNode + } + } + } +} + +/** + * A mapped type node. + */ +schema MappedTypeNode extends TypeNode { +} + +impl MappedTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MappedTypeNode { + for (tmp in TypeNode(db)) { + if (isMappedType(Node {id: tmp.id})) { + yield MappedTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * A literal type node. + */ +schema LiteralTypeNode extends TypeNode { +} + +impl LiteralTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *LiteralTypeNode { + for (tmp in TypeNode(db)) { + if (isLiteralType(Node {id: tmp.id})) { + yield LiteralTypeNode { + id : tmp.id + } + } + } + } + + pub fn getLiteral(self) -> Node { + let (literal = self.getChild(0)) { + if (isNullLiteral(literal)) { + return literal + } + if (isBooleanLiteral(literal)) { + return literal + } + if (isLiteralExpression(literal)) { + return literal + } + if (isPrefixUnaryExpression(literal)) { + return literal + } + } + } +} + +/** + * A named tuple member. + */ +schema NamedTupleMember extends TypeNode { +} + +impl NamedTupleMember { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NamedTupleMember { + for (tmp in TypeNode(db)) { + if (isNamedTupleMember(Node {id: tmp.id})) { + yield NamedTupleMember { + id : tmp.id + } + } + } + } +} + +/** + * A template literal type node. + */ +schema TemplateLiteralTypeNode extends TypeNode { +} + +impl TemplateLiteralTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateLiteralTypeNode { + for (tmp in TypeNode(db)) { + if (isTemplateLiteralType(Node {id: tmp.id})) { + yield TemplateLiteralTypeNode { + id : tmp.id + } + } + } + } + + pub fn getHead(self) -> TemplateHead { + for (head in TemplateHead(__all_data__)) { + if (head.key_eq(self.getChild(0))) { + return head + } + } + } + + pub fn getATemplateSpan(self) -> *TemplateLiteralTypeSpan { + for (templateSpan in TemplateLiteralTypeSpan(__all_data__)) { + for (auto_tmp1 in self.getAChild()) { + if (templateSpan.key_eq(auto_tmp1)) { + yield templateSpan + } + } + } + } + + pub fn getTemplateSpan(self, i: int) -> TemplateLiteralTypeSpan { + for (index in int::__undetermined_all__()) { + for (templateSpan in TemplateLiteralTypeSpan(__all_data__)) { + if (templateSpan.key_eq(self.getChild(index))) { + if (index - 1 = i) { + return templateSpan + } + } + } + } + } +} + +/** + * A template literal type span. + */ +schema TemplateLiteralTypeSpan extends TypeNode { +} + +impl TemplateLiteralTypeSpan { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TemplateLiteralTypeSpan { + for (tmp in TypeNode(db)) { + if (isTemplateLiteralTypeSpan(Node {id: tmp.id})) { + yield TemplateLiteralTypeSpan { + id : tmp.id + } + } + } + } +} + +/** + * A node with type arguments. + */ +schema NodeWithTypeArguments extends TypeNode { +} + +impl NodeWithTypeArguments { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *NodeWithTypeArguments { + for (tmp in TypeNode(db)) { + if (isNodeWithTypeArguments(Node {id: tmp.id})) { + yield NodeWithTypeArguments { + id : tmp.id + } + } + } + } +} + +/** + * A type reference node. + */ +schema TypeReferenceNode extends NodeWithTypeArguments { +} + +impl TypeReferenceNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeReferenceNode { + for (tmp in NodeWithTypeArguments(db)) { + if (isTypeReference(Node {id: tmp.id})) { + yield TypeReferenceNode { + id : tmp.id + } + } + } + } + + pub fn getTypeName(self) -> Node { + let (typeName = self.getChild(0)) { + if (isIdentifier(typeName)) { + return typeName + } + if (isQualifiedName(typeName)) { + return typeName + } + } + } +} + +/** + * An import type node. + */ +schema ImportTypeNode extends NodeWithTypeArguments { +} + +impl ImportTypeNode { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ImportTypeNode { + for (tmp in NodeWithTypeArguments(db)) { + if (isImportType(Node {id: tmp.id})) { + yield ImportTypeNode { + id : tmp.id + } + } + } + } +} + +/** + * An expression with type arguments. + */ +schema ExpressionWithTypeArguments extends NodeWithTypeArguments { +} + +impl ExpressionWithTypeArguments { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ExpressionWithTypeArguments { + for (tmp in NodeWithTypeArguments(db)) { + if (isExpressionWithTypeArguments(Node {id: tmp.id})) { + yield ExpressionWithTypeArguments { + id : tmp.id + } + } + } + } +} + +/** + * A type element. + */ +schema TypeElement extends Node { +} + +impl TypeElement { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *TypeElement { + for (tmp in Node(db)) { + if (isTypeElement(tmp)) { + yield TypeElement { + id : tmp.id + } + } + } + } +} + +/** + * A property signature. + */ +schema PropertySignature extends TypeElement { +} + +impl PropertySignature { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *PropertySignature { + for (tmp in TypeElement(db)) { + if (isPropertySignature(Node {id: tmp.id})) { + yield PropertySignature { + id : tmp.id + } + } + } + } +} + +/** + * A method signature. + */ +schema MethodSignature extends TypeElement { +} + +impl MethodSignature { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *MethodSignature { + for (tmp in TypeElement(db)) { + if (isMethodSignature(Node {id: tmp.id})) { + yield MethodSignature { + id : tmp.id + } + } + } + } +} + +/** + * A call signature declaration. + */ +schema CallSignatureDeclaration extends TypeElement { +} + +impl CallSignatureDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *CallSignatureDeclaration { + for (tmp in TypeElement(db)) { + if (isCallSignature(Node {id: tmp.id})) { + yield CallSignatureDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * A construct signature declaration. + */ +schema ConstructSignatureDeclaration extends TypeElement { +} + +impl ConstructSignatureDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *ConstructSignatureDeclaration { + for (tmp in TypeElement(db)) { + if (isConstructSignature(Node {id: tmp.id})) { + yield ConstructSignatureDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * An index signature declaration. + */ +schema IndexSignatureDeclaration extends TypeElement { +} + +impl IndexSignatureDeclaration { + @data_constraint + @inline + fn __all__(db: JavascriptDB) -> *IndexSignatureDeclaration { + for (tmp in TypeElement(db)) { + if (isIndexSignature(Node {id: tmp.id})) { + yield IndexSignatureDeclaration { + id : tmp.id + } + } + } + } +} + +/** + * Determines whether a node is a keyword type node. + */ +pub fn isKeywordTypeNode(node: Node) -> bool { + if (isAnyKeyword(node)) { + return true + } + if (isBigIntKeyword(node)) { + return true + } + if (isBooleanKeyword(node)) { + return true + } + if (isIntrinsicKeyword(node)) { + return true + } + if (isNeverKeyword(node)) { + return true + } + if (isNumberKeyword(node)) { + return true + } + if (isObjectKeyword(node)) { + return true + } + if (isStringKeyword(node)) { + return true + } + if (isSymbolKeyword(node)) { + return true + } + if (isUndefinedKeyword(node)) { + return true + } + if (isUnknownKeyword(node)) { + return true + } + if (isVoidKeyword(node)) { + return true + } +} + +/** + * Determines whether a node is a type predicate. + */ +pub fn isTypePredicate(node: Node) -> bool { + if (node.getKind() = 176) { + return true + } +} + +/** + * Determines whether a node is a type reference. + */ +pub fn isTypeReference(node: Node) -> bool { + if (node.getKind() = 177) { + return true + } +} + +/** + * Determines whether a node is a function type. + */ +pub fn isFunctionType(node: Node) -> bool { + if (node.getKind() = 178) { + return true + } +} + +/** + * Determines whether a node is a constructor type. + */ +pub fn isConstructorType(node: Node) -> bool { + if (node.getKind() = 179) { + return true + } +} + +/** + * Determines whether a node is a type query. + */ +pub fn isTypeQuery(node: Node) -> bool { + if (node.getKind() = 180) { + return true + } +} + +/** + * Determines whether a node is a type literal. + */ +pub fn isTypeLiteral(node: Node) -> bool { + if (node.getKind() = 181) { + return true + } +} + +/** + * Determines whether a node is an array type. + */ +pub fn isArrayType(node: Node) -> bool { + if (node.getKind() = 182) { + return true + } +} + +/** + * Determines whether a node is a tuple type. + */ +pub fn isTupleType(node: Node) -> bool { + if (node.getKind() = 183) { + return true + } +} + +/** + * Determines whether a node is an optional type. + */ +pub fn isOptionalType(node: Node) -> bool { + if (node.getKind() = 184) { + return true + } +} + +/** + * Determines whether a node is a rest type. + */ +pub fn isRestType(node: Node) -> bool { + if (node.getKind() = 185) { + return true + } +} + +/** + * Determines whether a node is an union type. + */ +pub fn isUnionType(node: Node) -> bool { + if (node.getKind() = 186) { + return true + } +} + +/** + * Determines whether a node is an intersection type. + */ +pub fn isIntersectionType(node: Node) -> bool { + if (node.getKind() = 187) { + return true + } +} + +/** + * Determines whether a node is a conditional type. + */ +pub fn isConditionalType(node: Node) -> bool { + if (node.getKind() = 188) { + return true + } +} + +/** + * Determines whether a node is an infer type. + */ +pub fn isInferType(node: Node) -> bool { + if (node.getKind() = 189) { + return true + } +} + +/** + * Determines whether a node is a parenthesized type. + */ +pub fn isParenthesizedType(node: Node) -> bool { + if (node.getKind() = 190) { + return true + } +} + +/** + * Determines whether a node is a this type. + */ +pub fn isThisType(node: Node) -> bool { + if (node.getKind() = 191) { + return true + } +} + +/** + * Determines whether a node is a type operator. + */ +pub fn isTypeOperator(node: Node) -> bool { + if (node.getKind() = 192) { + return true + } +} + +/** + * Determines whether a node is an indexed access type. + */ +pub fn isIndexedAccessType(node: Node) -> bool { + if (node.getKind() = 193) { + return true + } +} + +/** + * Determines whether a node is a mapped type. + */ +pub fn isMappedType(node: Node) -> bool { + if (node.getKind() = 194) { + return true + } +} + +/** + * Determines whether a node is a literal type. + */ +pub fn isLiteralType(node: Node) -> bool { + if (node.getKind() = 195) { + return true + } +} + +/** + * Determines whether a node is a named tuple member. + */ +pub fn isNamedTupleMember(node: Node) -> bool { + if (node.getKind() = 196) { + return true + } +} + +/** + * Determines whether a node is a template literal type. + */ +pub fn isTemplateLiteralType(node: Node) -> bool { + if (node.getKind() = 197) { + return true + } +} + +/** + * Determines whether a node is a template literal type span. + */ +pub fn isTemplateLiteralTypeSpan(node: Node) -> bool { + if (node.getKind() = 198) { + return true + } +} + +/** + * Determines whether a node is an import type. + */ +pub fn isImportType(node: Node) -> bool { + if (node.getKind() = 199) { + return true + } +} + +/** + * Determines whether a node is an expression with type arguments. + */ +pub fn isExpressionWithTypeArguments(node: Node) -> bool { + if (node.getKind() = 227) { + return true + } +} + +/** + * Determines whether a node is a node with type arguments. + */ +pub fn isNodeWithTypeArguments(node: Node) -> bool { + if (isTypeReference(node)) { + return true + } + if (isImportType(node)) { + return true + } + if (isExpressionWithTypeArguments(node)) { + return true + } +} + +/** + * Determines whether a node is a type node. + */ +pub fn isTypeNode(node: Node) -> bool { + if (isKeywordTypeNode(node)) { + return true + } + if (isNodeWithTypeArguments(node)) { + return true + } + if (isTypePredicate(node)) { + return true + } + if (isFunctionType(node)) { + return true + } + if (isConstructorType(node)) { + return true + } + if (isTypeQuery(node)) { + return true + } + if (isTypeLiteral(node)) { + return true + } + if (isArrayType(node)) { + return true + } + if (isTupleType(node)) { + return true + } + if (isOptionalType(node)) { + return true + } + if (isRestType(node)) { + return true + } + if (isUnionType(node)) { + return true + } + if (isIntersectionType(node)) { + return true + } + if (isConditionalType(node)) { + return true + } + if (isInferType(node)) { + return true + } + if (isParenthesizedType(node)) { + return true + } + if (isThisType(node)) { + return true + } + if (isTypeOperator(node)) { + return true + } + if (isIndexedAccessType(node)) { + return true + } + if (isMappedType(node)) { + return true + } + if (isLiteralType(node)) { + return true + } + if (isNamedTupleMember(node)) { + return true + } + if (isTemplateLiteralType(node)) { + return true + } + if (isTemplateLiteralTypeSpan(node)) { + return true + } +} + +/** + * Determines whether a node is a property signature. + */ +pub fn isPropertySignature(node: Node) -> bool { + if (node.getKind() = 165) { + return true + } +} + +/** + * Determines whether a node is a method signature. + */ +pub fn isMethodSignature(node: Node) -> bool { + if (node.getKind() = 167) { + return true + } +} + +/** + * Determines whether a node is a call signature. + */ +pub fn isCallSignature(node: Node) -> bool { + if (node.getKind() = 173) { + return true + } +} + +/** + * Determines whether a node is a construct signature. + */ +pub fn isConstructSignature(node: Node) -> bool { + if (node.getKind() = 174) { + return true + } +} + +/** + * Determines whether a node is an index signature. + */ +pub fn isIndexSignature(node: Node) -> bool { + if (node.getKind() = 175) { + return true + } +} + +/** + * Determines whether a node is a type element. + */ +pub fn isTypeElement(node: Node) -> bool { + if (isPropertySignature(node)) { + return true + } + if (isMethodSignature(node)) { + return true + } + if (isCallSignature(node)) { + return true + } + if (isConstructSignature(node)) { + return true + } + if (isIndexSignature(node)) { + return true + } +} diff --git a/language/javascript/lib/Util.gdl b/language/javascript/lib/Util.gdl new file mode 100644 index 00000000..693936e2 --- /dev/null +++ b/language/javascript/lib/Util.gdl @@ -0,0 +1,34 @@ +/** + * @filename: Statement + * @brief: Provides util classes and predicates for JavaScript / TypeScript + */ + +/** + * Determines whether a node is a control Node + */ +pub fn isControlNode(node: Node) -> bool { + if (isIterationStatement(node)) { + return true + } + if (isIfStatement(node)) { + return true + } + if (isCaseClause(node)) { + return true + } + if (isDefaultClause(node)) { + return true + } + if (isCatchClause(node)) { + return true + } + if (isConditionalExpression(node)) { + return true + } + if (isLogicalAndExpression(node)) { + return true + } + if (isLogicalOrExpression(node)) { + return true + } +} diff --git a/language/python/extractor/requirements.txt b/language/python/extractor/requirements.txt new file mode 100644 index 00000000..fe8c65a9 --- /dev/null +++ b/language/python/extractor/requirements.txt @@ -0,0 +1,5 @@ +SQLAlchemy~=1.4.32 + +tqdm~=4.64.0 +astor~=0.8.1 +pyinstaller~=5.3 \ No newline at end of file diff --git a/language/python/extractor/setup.py b/language/python/extractor/setup.py new file mode 100644 index 00000000..e69de29b diff --git a/language/python/extractor/src/core/__init__.py b/language/python/extractor/src/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/language/python/extractor/src/core/extractor.py b/language/python/extractor/src/core/extractor.py new file mode 100644 index 00000000..75388133 --- /dev/null +++ b/language/python/extractor/src/core/extractor.py @@ -0,0 +1,1034 @@ +import ast +import logging +import tokenize +from pathlib import Path + +from core.idgenerator import get_ast_element_oid, get_single_comment_element_oid +from model.parent import Parent + +parent_dict = dict() +logger = logging.getLogger() + + +class Extractor(ast.NodeVisitor): + def __init__(self, storage, file, src_path, tree, line_count_dict): + self.storage = storage + self.file = file + self.src_path = src_path + self.tree = tree + self.line_count_dict = line_count_dict + self.getParent() + self.visit(self.tree) + self.visit_single_line_comment() + + def getParent(self): + try: + for node in ast.walk(self.tree): + node.debug_message = ast.unparse(node) + index = 0 + for child in ast.iter_child_nodes(node): + child.parent = node + child.debug_message = ast.unparse(child) + child.index = index + index += 1 + except IndexError: + logger.error(f"Index Error when parsing node: {node}") + + def get_parent(self, node): + s = get_ast_element_oid(node, node.debug_message, + self.file.relative_path) + # expression statement and its expression has the same printable text, + # so add type name to verify them + if parent_dict.get(s): + return parent_dict.get(s) + else: + coref_parent = Parent( + parent_oid=s, parent_type=type(node).__name__) + parent_dict[s] = coref_parent + parent = { + "parent_oid": coref_parent.parent_oid, + "parent_type": coref_parent.parent_type, + } + self.storage.store_parent(parent) + return coref_parent + + def get_element_oid(self, node: ast.AST) -> int: + try: + oid = get_ast_element_oid( + node, node.debug_message, self.file.relative_path) + except AttributeError: + logger.error( + f"Cannot calculate the oid of the node: {node} for Attribute Error on file {self.src_path}" + ) + oid = -1 + return oid + + def generic_visit(self, node): + element_type = type(node).__name__ + p = self.get_parent(node.parent).parent_oid + oid = self.get_element_oid(node) + if isinstance(node, ast.operator): + self.visit_operator(node) + elif isinstance(node, ast.cmpop): + self.visit_cmpop(node) + elif isinstance(node, ast.boolop): + self.visit_boolop(node) + elif isinstance(node, ast.unaryop): + self.visit_unaryop(node) + else: + try: + element = { + "oid": oid, + "value": node.debug_message, + "type": element_type, + "parent_oid": p, + } + self.calculate_location(node, oid) + except (IndexError, AttributeError): + element = { + "oid": oid, + "value": node.debug_message, + "type": element_type, + "parent_oid": p, + } + self.calculate_location(node, oid) + print(element) + self.storage.store_element(element) + ast.NodeVisitor.generic_visit(self, node) + + def calculate_location(self, node, oid): + """ + Calculate and store the location info, start_line, end_line, start_column, end_column for a locatable ast node. + Args: + node: a locatable ast node + oid: the coref oid for the node + Returns: None + """ + location = { + "element_oid": oid, + "file_oid": self.file.element_oid, + "start_line_number": node.lineno, + "start_column_number": node.col_offset, + "end_line_number": node.end_lineno, + "end_column_number": node.end_col_offset, + } + self.calculate_number_of_lines(node, oid) + self.storage.store_location(location) + + def calculate_number_of_lines(self, node: ast.AST, oid): + """ + Calculate and store the number of lines for a locatable ast node. + Args: + node: a locatable ast node + oid: the coref oid for the node + Returns: None + """ + code_num = 0 + blank_num = 0 + comment_num = 0 + for key in range(node.lineno, node.end_lineno + 1): + if self.line_count_dict.get(key) == 1: + comment_num += 1 + elif self.line_count_dict.get(key) == 0: + blank_num += 1 + else: + code_num += 1 + number_of_lines = { + "element_oid": oid, + "number_of_total_lines": code_num + blank_num + comment_num, + "number_of_valid_lines": code_num, + "number_of_comment_lines": comment_num, + } + self.storage.store_number_of_lines(number_of_lines) + + def visit_single_line_comment(self): + with open(self.src_path, "r", errors="ignore") as source: + for token, text, start_loc, end_loc, src in tokenize.generate_tokens( + source.readline + ): + if token == tokenize.COMMENT: + cc = get_single_comment_element_oid( + text, self.file.relative_path, start_loc, end_loc + ) + location = { + "element_oid": cc, + "file_oid": self.file.element_oid, + "start_line_number": start_loc[0], + "start_column_number": start_loc[1], + "end_line_number": end_loc[0], + "end_column_number": end_loc[1], + } + self.storage.store_location(location) + comment = { + "element_oid": cc, + "text": text, + "parent_oid": self.file.element_oid, + "location_oid": cc, + } + self.storage.store_comment(comment) + + def visit_docstring_comment(self, node, id): + text = ast.get_docstring(node, False) + if text is not None: + d = get_ast_element_oid(node, text, self.file.relative_path) + docstring_comment = { + "element_oid": d, + "text": text, + "documented_element_oid": id, + } + self.storage.store_docstring_comment(docstring_comment) + + def generate_locatable_element(self, node, oid): + p_oid = self.get_parent(node.parent).parent_oid + element = { + "element_oid": oid, + "type": type(node).__name__, + "element_index": node.index, + "parent_oid": p_oid, + "location_oid": oid, + "printable_text": node.debug_message, + } + self.calculate_location(node, oid) + return element + + def visit_statement(self, node: ast.stmt, oid): + """ + stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment) + | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment) + | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list) + | Return(expr? value) + | Delete(expr* targets) + | Assign(expr* targets, expr value, string? type_comment) + | AugAssign(expr target, operator op, expr value) + | AnnAssign(expr target, expr annotation, expr? value, int simple) + | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment) + | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment) + | While(expr test, stmt* body, stmt* orelse) + | If(expr test, stmt* body, stmt* orelse) + | With(withitem* items, stmt* body, string? type_comment) + | AsyncWith(withitem* items, stmt* body, string? type_comment) + | Match(expr subject, match_case* cases) + | Raise(expr? exc, expr? cause) + | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) + | Assert(expr test, expr? msg) + | Import(alias* names) + | ImportFrom(identifier? module, alias* names, int? level) + | Global(identifier* names) + | Nonlocal(identifier* names) + | Expr(expr value) + | Pass + | Break + | Continue + There is no general visitor for ast.stmt type, so call it in every sub statement class visitor. + Save common info, i.e., location oid, parent oid, printable text, type in statement table. + :param node: an ast statement node. + :param oid: generated oid for the node + :return: null + """ + statement = self.generate_locatable_element(node, oid) + self.storage.store_stmt(statement) + + def visit_expression(self, node: ast.expr, oid): + """ + expr = BoolOp(boolop op, expr* values) + | NamedExpr(expr target, expr value) + | BinOp(expr left, operator op, expr right) + | UnaryOp(unaryop op, expr operand) + | Lambda(arguments args, expr body) + | IfExp(expr test, expr body, expr orelse) + | Dict(expr* keys, expr* values) + | Set(expr* elts) + | ListComp(expr elt, comprehension* generators) + | SetComp(expr elt, comprehension* generators) + | DictComp(expr key, expr value, comprehension* generators) + | GeneratorExp(expr elt, comprehension* generators) + | Await(expr value) + | Yield(expr? value) + | YieldFrom(expr value) + | Compare(expr left, cmpop* ops, expr* comparators) + | Call(expr func, expr* args, keyword* keywords) + | FormattedValue(expr value, int conversion, expr? format_spec) + | JoinedStr(expr* values) + | Constant(constant value, string? kind) + | Attribute(expr value, identifier attr, expr_context ctx) + | Subscript(expr value, expr slice, expr_context ctx) + | Starred(expr value, expr_context ctx) + | Name(identifier id, expr_context ctx) + | List(expr* elts, expr_context ctx) + | Tuple(expr* elts, expr_context ctx) + | Slice(expr? lower, expr? upper, expr? step) + There is no general visitor for ast.expr type, so call it in every sub expression class visitor. + Save common info, i.e., location oid, parent oid, printable text, type in expression table. + :param node: an ast expression node. + :param oid: generated oid for the node + :return: null + """ + expression = self.generate_locatable_element(node, oid) + self.storage.store_expr(expression) + + def visit_boolop(self, node: ast.boolop): + """ + boolop = And | Or, which has no location info, no printable text info, so omit this node. + :param node: ast.operator + :return: null + """ + pass + + def visit_operator(self, node: ast.operator): + """ + operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | + FloorDiv, which has no location info, no printable text info, so omit this node. :param node: ast.operator + :return: null + """ + pass + + def visit_cmpop(self, node: ast.cmpop): + """ + cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn, which has no location info, no printable + text info, so omit this node. :param node: ast.cmpop :return: null + """ + pass + + def visit_unaryop(self, node: ast.unaryop): + """ + unaryop = Invert | Not | UAdd | USub, which has no location info, no printable text info, so omit this node. + :param node: ast.unaryop + :return: null + """ + pass + + def visit_Global(self, node: ast.Global): + oid = self.get_element_oid(node) + statement = {"element_oid": oid, "names": node.names[0]} + self.storage.store_global_stmt(statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Nonlocal(self, node: ast.Nonlocal): + oid = self.get_element_oid(node) + statement = {"element_oid": oid, "names": node.names[0]} + self.storage.store_non_local_stmt(statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_NamedExpr(self, node: ast.NamedExpr): + oid = self.get_element_oid(node) + expression = { + "element_oid": oid, + "target_oid": self.get_element_oid(node.target), + "value_oid": self.get_element_oid(node.value), + } + self.storage.store_named_expr(expression) + self.visit_expression(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Expr(self, node: ast.Expr): + oid = self.get_element_oid(node) + statement = {"element_oid": oid, + "value_oid": self.get_element_oid(node.value)} + self.storage.store_expression_stmt(statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_FormattedValue(self, node: ast.FormattedValue): + oid = self.get_element_oid(node) + formatted_value = { + "element_oid": oid, + "value_oid": self.get_element_oid(node.value), + } + self.storage.store_formatted_value_expr(formatted_value) + self.visit_expression(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_AnnAssign(self, node: ast.AnnAssign): + oid = self.get_element_oid(node) + ann_statement = { + "element_oid": oid, + "annotation_oid": self.get_element_oid(node.annotation), + "target_oid": self.get_element_oid(node.target), + "is_simple": node.simple, + } + self.storage.store_ann_assign_stmt(ann_statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Return(self, node: ast.Return): + oid = self.get_element_oid(node) + is_return_empty = 1 if node.value is None else 0 + return_statement = {"element_oid": oid, + "is_return_empty": is_return_empty} + self.storage.store_return_stmt(return_statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Break(self, node: ast.Break): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = {"element_oid": oid} + self.storage.store_break_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Name(self, node: ast.Name): + oid = self.get_element_oid(node) + name_expression = {"element_oid": oid, + "ctx_type": type(node.ctx).__name__} + self.storage.store_name_expr(name_expression) + self.visit_expression(node, oid) + # print(node.ctx, node.id, node.lineno, self.src_path) + # for i in ast.iter_child_nodes(node): + # print(i, node.id, node.lineno, oid, self.src_path) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Load(self, node: ast.Load): + oid = self.get_element_oid(node) + expr_context = { + "element_oid": oid, + "parent_oid": self.get_parent(node.parent).parent_oid, + "printable_text": "Load", + } + self.storage.store_expr_context(expr_context) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Store(self, node: ast.Store): + oid = self.get_element_oid(node) + expr_context = { + "element_oid": oid, + "parent_oid": self.get_parent(node.parent).parent_oid, + "printable_text": "Store", + } + self.storage.store_expr_context(expr_context) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Del(self, node: ast.Del): + oid = self.get_element_oid(node) + expr_context = { + "element_oid": oid, + "parent_oid": self.get_parent(node.parent).parent_oid, + "printable_text": "Del", + } + self.storage.store_expr_context(expr_context) + ast.NodeVisitor.generic_visit(self, node) + + def visit_arguments(self, node: ast.arguments): + oid = get_ast_element_oid( + node, node.debug_message, self.file.relative_path) + arguments = { + "element_oid": oid, + "parent_oid": self.get_parent(node.parent).parent_oid, + "printable_text": node.debug_message, + } + self.storage.store_arguments(arguments) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Module(self, node: ast.Module): + oid = get_ast_element_oid( + node, node.debug_message, self.file.relative_path) + module = { + "element_oid": oid, + "name": Path(self.file.name).stem, + "file_oid": self.file.element_oid, + "location_oid": oid, + } + self.storage.store_module(module) + self.visit_docstring_comment(node, oid) + location = { + "element_oid": oid, + "file_oid": self.file.element_oid, + "start_line_number": 1, + "start_column_number": 0, + "end_line_number": len(self.line_count_dict), + "end_column_number": 0, + } + self.storage.store_location(location) + self.generate_scope_enclosing_stmt_or_expr(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_comprehension(self, node: ast.comprehension): + """ + this element has no lineno attribute, so share the same location with its parent node location + :param node: ast.comprehension + :return: null + """ + a = self.get_element_oid(node.iter) + b = self.get_element_oid(node.target) + comprehension = { + "element_oid": self.get_element_oid(node), + "target_expr_oid": b, + "iter_expr_oid": a, + "element_index": node.index, + "parent_oid": self.get_parent(node.parent).parent_oid, + "printable_text": node.debug_message, + } + self.storage.store_comprehension(comprehension) + ast.NodeVisitor.generic_visit(self, node) + + def visit_withitem(self, node: ast.withitem): + oid = self.get_element_oid(node) + p_oid = self.get_parent(node.parent).parent_oid + withitem = { + "element_oid": oid, + "printable_text": node.debug_message, + "element_index": node.index, + "parent_oid": p_oid, + } + self.storage.store_withitem(withitem) + ast.NodeVisitor.generic_visit(self, node) + + def visit_BoolOp(self, node: ast.BoolOp): + oid = self.get_element_oid(node) + bool_expression = { + "element_oid": oid, + "type": type(node.op).__name__, + "size": len(node.values) - 1, + } + self.storage.store_bool_expr(bool_expression) + self.visit_expression(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def generate_scope_enclosing_stmt_or_expr(self, node, oid): + enclosing_dict = dict() + self.generate_enclosing_list(node, enclosing_dict, oid) + for key, value in enclosing_dict.items(): + if isinstance(key, ast.stmt): + scope_enclosing_stmt = { + "statement_oid": value[0], + "scope_oid": value[1], + } + self.storage.store_scope_enclosing_stmt(scope_enclosing_stmt) + else: + scope_enclosing_expr = { + "expression_oid": value[0], + "scope_oid": value[1], + } + self.storage.store_scope_enclosing_expr(scope_enclosing_expr) + + def generate_enclosing_list(self, node, enclosing_dict, oid): + """ + Recursively to find statement or expression in the scope (class or function) + Args: + oid: scope oid + node: ast.ClassDef or ast.FunctionDef + enclosing_dict: the enclosing dict + + Returns: enclosing_dict + + """ + for child in ast.iter_child_nodes(node): + c_oid = self.get_element_oid(child) + if isinstance(child, ast.ClassDef) or isinstance(child, ast.FunctionDef): + enclosing_dict[child] = [c_oid, oid] + self.generate_enclosing_list(child, enclosing_dict, c_oid) + elif isinstance(child, ast.stmt) or isinstance(child, ast.expr): + enclosing_dict[child] = [c_oid, oid] + self.generate_enclosing_list(child, enclosing_dict, oid) + else: + self.generate_enclosing_list(child, enclosing_dict, oid) + return enclosing_dict + + def generate_decorated_relation(self, node: ast.AST, oid): + for i in node.decorator_list: + d_oid = self.get_element_oid(i) + decorator = { + "element_oid": d_oid, + "type": type(i).__name__, + "printable_text": i.debug_message, + } + self.storage.store_decorator(decorator) + relation = {"decorator_oid": d_oid, "decorated_element_oid": oid} + self.storage.store_decorated_relation(relation) + + def visit_FunctionDef(self, node: ast.FunctionDef): + oid = self.get_element_oid(node) + function_def = {"element_oid": oid, "name": node.name} + self.storage.store_function_def_stmt(function_def) + self.visit_docstring_comment(node, oid) + self.visit_statement(node, oid) + if node.decorator_list is not None: + self.generate_decorated_relation(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_ClassDef(self, node: ast.ClassDef): + oid = self.get_element_oid(node) + self.visit_docstring_comment(node, oid) + class_def = {"element_oid": oid, "name": node.name} + self.storage.store_class_def_stmt(class_def) + self.visit_statement(node, oid) + if node.decorator_list is not None: + self.generate_decorated_relation(node, oid) + for i in node.bases: + relation = {"base_oid": self.get_element_oid(i), "class_oid": oid} + self.storage.store_class_hierarchy(relation) + ast.NodeVisitor.generic_visit(self, node) + + def visit_If(self, node: ast.If): + oid = self.get_element_oid(node) + if_statement = {"element_oid": oid} + self.storage.store_if_stmt(if_statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_IfExp(self, node: ast.IfExp): + oid = self.get_element_oid(node) + if_expression = {"element_oid": oid} + self.storage.store_if_expr(if_expression) + self.visit_expression(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_For(self, node: ast.For): + oid = self.get_element_oid(node) + for_statement = {"element_oid": oid} + self.storage.store_for_stmt(for_statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_While(self, node: ast.While): + oid = self.get_element_oid(node) + while_statement = {"element_oid": oid} + self.storage.store_while_stmt(while_statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Try(self, node: ast.Try): + oid = self.get_element_oid(node) + try_statement = {"element_oid": oid} + self.storage.store_try_stmt(try_statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_ExceptHandler(self, node: ast.ExceptHandler): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + p_oid = self.get_parent(node.parent).parent_oid + handler = { + "element_oid": oid, + "element_index": node.index, + "parent_oid": p_oid, + "location_oid": oid, + "printable_text": node.debug_message, + } + self.storage.store_except_handler(handler) + self.calculate_location(node, oid) + + def visit_BinOp(self, node: ast.BinOp): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + handler = { + "element_oid": oid, + "left_expr_oid": self.get_element_oid(node.left), + "opcode": node.op.__doc__, + "right_expr_oid": self.get_element_oid(node.right), + } + self.storage.store_bin_expr(handler) + self.visit_expression(node, oid) + + def visit_Match(self, node: ast.Match): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + statement = { + "element_oid": oid, + "subject_oid": self.get_element_oid(node.subject), + } + self.storage.store_match_stmt(statement) + self.visit_statement(node, oid) + + def visit_match_case(self, node: ast.match_case): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + p_oid = self.get_parent(node.parent).parent_oid + pattern_oid = self.get_element_oid(node.pattern) + + node.lineno = node.pattern.lineno + node.col_offset = node.pattern.col_offset + if node.body is not None: + i = len(node.body) + node.end_lineno = node.body[i - 1].end_lineno + node.end_col_offset = node.body[i - 1].end_col_offset + else: + node.end_lineno = node.pattern.end_lineno + node.end_col_offset = node.pattern.end_col_offset + + is_default = 1 if isinstance(node.pattern, ast.MatchAs) else 0 + statement = { + "element_oid": oid, + "pattern_oid": pattern_oid, + "element_index": node.index, + "parent_oid": p_oid, + "location_oid": oid, + "printable_text": node.debug_message, + "is_default": is_default, + } + self.storage.store_match_case(statement) + self.calculate_location(node, oid) + + def visit_Constant(self, node: ast.Constant): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + if isinstance(node, ast.Num): + value = "Num" + elif isinstance(node, ast.Str): + value = "Str" + elif isinstance(node, ast.Bytes): + value = "Bytes" + elif isinstance(node, ast.Ellipsis): + value = "Ellipsis" + elif isinstance(node, ast.NameConstant): + value = "NameConstant" + else: + value = "Constant" + constant = {"element_oid": oid, "value": value} + self.storage.store_constant(constant) + self.visit_expression(node, oid) + + def visit_arg(self, node: ast.arg): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + p_oid = self.get_parent(node.parent).parent_oid + annotation_oid = ( + self.get_element_oid( + node.annotation) if node.annotation is not None else -1 + ) + arg = { + "element_oid": oid, + "annotation": annotation_oid, + "element_index": node.index, + "parent_oid": p_oid, + "location_oid": oid, + "printable_text": node.arg, + } + self.storage.store_arg(arg) + self.calculate_location(node, oid) + + def visit_keyword(self, node: ast.keyword): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + p_oid = self.get_parent(node.parent).parent_oid + value = node.arg if node.arg is not None else "None" + value_oid = self.get_element_oid( + node.value) if node.value is not None else -1 + keyword = { + "element_oid": oid, + "arg_value": value, + "value_oid": value_oid, + "element_index": node.index, + "parent_oid": p_oid, + "location_oid": oid, + "printable_text": node.debug_message, + } + self.storage.store_keyword(keyword) + self.calculate_location(node, oid) + + def visit_Slice(self, node: ast.Slice): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + p_oid = self.get_parent(node.parent).parent_oid + has_step = 1 if node.step is not None else 0 + slice = { + "element_oid": oid, + "element_index": node.index, + "parent_oid": p_oid, + "location_oid": oid, + "printable_text": node.debug_message, + "has_step": has_step, + } + self.storage.store_slice(slice) + self.calculate_location(node, oid) + + def visit_Call(self, node: ast.Call): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + expr = {"element_oid": oid, + "expr_func_oid": self.get_element_oid(node.func)} + self.storage.store_call_expr(expr) + self.visit_expression(node, oid) + + def visit_Attribute(self, node: ast.Attribute): + ast.NodeVisitor.generic_visit(self, node) + oid = self.get_element_oid(node) + expression = { + "element_oid": oid, + "value_oid": self.get_element_oid(node.value), + "ctx_type": type(node.ctx).__name__, + } + self.storage.store_attribute_expr(expression) + self.visit_expression(node, oid) + + def visit_Import(self, node: ast.Import): + oid = self.get_element_oid(node) + statement = {"element_oid": oid} + self.storage.store_import_stmt(statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_ImportFrom(self, node: ast.ImportFrom): + oid = self.get_element_oid(node) + module = node.module if node.module is not None else "." + statement = {"element_oid": oid, "module": module, "level": node.level} + self.storage.store_import_from_stmt(statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_alias(self, node: ast.alias): + oid = self.get_element_oid(node) + p_oid = self.get_parent(node.parent).parent_oid + value = node.debug_message + name = node.name + asname = node.asname if node.asname is not None else "None" + alias = { + "element_oid": oid, + "name": name, + "asname": asname, + "element_index": node.index, + "parent_oid": p_oid, + "location_oid": oid, + "printable_text": value, + } + self.storage.store_alias(alias) + self.calculate_location(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Await(self, node: ast.Await): + oid = self.get_element_oid(node) + expression = { + "element_oid": oid, + "expr_value_oid": self.get_element_oid(node.value), + } + self.storage.store_await_expr(expression) + self.visit_expression(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Compare(self, node: ast.Compare): + oid = self.get_element_oid(node) + expression = { + "element_oid": oid, + "left_expr_oid": self.get_element_oid(node.left), + } + self.storage.store_compare_expr(expression) + self.visit_expression(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Subscript(self, node: ast.Subscript): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = { + "element_oid": oid, + "value_oid": self.get_element_oid(node.value), + "slice_oid": self.get_element_oid(node.slice), + "ctx": type(node.ctx).__name__, + } + self.storage.store_subscript_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Dict(self, node: ast.Dict): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = {"element_oid": oid, "size": len(node.keys)} + self.storage.store_dict_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_DictComp(self, node: ast.DictComp): + oid = self.get_element_oid(node) + expression = {"element_oid": oid, + "comprehension_size": len(node.generators)} + self.storage.store_dict_comp_expr(expression) + self.visit_expression(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_GeneratorExp(self, node: ast.GeneratorExp): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = {"element_oid": oid, + "elt_oid": self.get_element_oid(node.elt)} + self.storage.store_generator_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_JoinedStr(self, node: ast.JoinedStr): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = {"element_oid": oid, "size": len(node.values)} + self.storage.store_joined_str_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Lambda(self, node: ast.Lambda): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = {"element_oid": oid} + self.storage.store_lambda_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_List(self, node: ast.List): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = { + "element_oid": oid, + "elt_size": len(node.elts), + "ctx": type(node.ctx).__name__, + } + self.storage.store_list_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_ListComp(self, node: ast.ListComp): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = { + "element_oid": oid, + "elt_oid": self.get_element_oid(node.elt), + "generator_size": len(node.generators), + } + self.storage.store_list_comp_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Set(self, node: ast.Set): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = {"element_oid": oid, "elt_size": len(node.elts)} + self.storage.store_set_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_SetComp(self, node: ast.SetComp): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = { + "element_oid": oid, + "elt_oid": self.get_element_oid(node.elt), + "generator_size": len(node.generators), + } + self.storage.store_set_comp_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Starred(self, node: ast.Starred): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = {"element_oid": oid, "ctx": type(node.ctx).__name__} + self.storage.store_starred_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Tuple(self, node: ast.Tuple): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = { + "element_oid": oid, + "elt_size": len(node.elts), + "ctx": type(node.ctx).__name__, + } + self.storage.store_tuple_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_UnaryOp(self, node: ast.UnaryOp): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = { + "element_oid": oid, + "op_code": type(node.op).__name__, + "operand_oid": self.get_element_oid(node.operand), + } + self.storage.store_unary_op_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Yield(self, node: ast.Yield): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = {"element_oid": oid} + self.storage.store_yield_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_YieldFrom(self, node: ast.YieldFrom): + oid = self.get_element_oid(node) + self.visit_expression(node, oid) + expression = {"element_oid": oid, + "value": self.get_element_oid(node.value)} + self.storage.store_yield_from_expr(expression) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Assign(self, node: ast.Assign): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = { + "element_oid": oid, + "value_oid": self.get_element_oid(node.value), + "targets_size": len(node.targets), + } + self.storage.store_assign_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_AsyncFor(self, node: ast.AsyncFor): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = {"element_oid": oid} + self.storage.store_async_for_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_AsyncWith(self, node: ast.AsyncWith): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = {"element_oid": oid} + self.storage.store_async_with_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = {"element_oid": oid, "name": node.name} + self.storage.store_async_function_def_stmt(statement) + self.generate_scope_enclosing_stmt_or_expr(node, oid) + self.visit_docstring_comment(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Continue(self, node: ast.Continue): + oid = self.get_element_oid(node) + statement = {"element_oid": oid} + self.storage.store_continue_stmt(statement) + self.visit_statement(node, oid) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Delete(self, node: ast.Delete): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = {"element_oid": oid, "targets_size": len(node.targets)} + self.storage.store_delete_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Pass(self, node: ast.Pass): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = {"element_oid": oid} + self.storage.store_pass_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Raise(self, node: ast.Raise): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = {"element_oid": oid} + self.storage.store_raise_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_AugAssign(self, node: ast.AugAssign): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = { + "element_oid": oid, + "op_code": type(node.op).__name__, + "value_expr_oid": self.get_element_oid(node.value), + "target_expr_oid": self.get_element_oid(node.target), + } + self.storage.store_augassign_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_With(self, node: ast.With): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = {"element_oid": oid} + self.storage.store_with_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Assert(self, node: ast.Assert): + oid = self.get_element_oid(node) + self.visit_statement(node, oid) + statement = { + "element_oid": oid, + "assert_condition_oid": self.get_element_oid(node.test), + } + self.storage.store_assert_stmt(statement) + ast.NodeVisitor.generic_visit(self, node) + + def visit_Expression(self, node: ast.Expression): + ast.NodeVisitor.generic_visit(self, node) diff --git a/language/python/extractor/src/core/idgenerator.py b/language/python/extractor/src/core/idgenerator.py new file mode 100644 index 00000000..ccad6a0a --- /dev/null +++ b/language/python/extractor/src/core/idgenerator.py @@ -0,0 +1,48 @@ +import ast +import hashlib +import os.path + + +def get_oid(value): + sha256_value = hashlib.sha256(value.encode("utf-8")).hexdigest() + oid = int(sha256_value[0:15], 16) + return oid + + +def calculate_file_cache(path, algorithm): + size = os.path.getsize(path) + with open(path, "rb") as f: + while size >= 1024 * 1024: + algorithm.update(f.read(1024 * 1024)) + size -= 1024 * 1024 + algorithm.update(f.read()) + return algorithm.hexdigest() + + +def get_ast_element_oid(node, value, path): + s = type(node).__name__ + if isinstance(node, ast.Module): + signature = f"path: {path} value: {value} type: {s}" + else: + try: + l = str(node.lineno) + l1 = str(node.col_offset) + l2 = str(node.end_lineno) + l3 = str(node.end_col_offset) + signature = f"path: {path} value: {value} type: {s} s_line: {l} e_line: {l2} s_col: {l1} e_col: {l3}" + except AttributeError: + l = str(node.parent.lineno) + l1 = str(node.parent.col_offset) + l2 = str(node.parent.end_lineno) + l3 = str(node.parent.end_col_offset) + signature = f"path: {path} value: {value} type: {s} s_line: {l} e_line: {l2} s_col: {l1} e_col: {l3}" + oid = get_oid(signature) + return oid + + +def get_single_comment_element_oid(value, path, start_loc, end_loc): + l = str(start_loc[0]) + l2 = str(end_loc[0]) + signature = f"path: {path} value: {value} s_line: {l} e_line: {l2}" + oid = get_oid(signature) + return oid diff --git a/language/python/extractor/src/core/storage.py b/language/python/extractor/src/core/storage.py new file mode 100644 index 00000000..7b8d51d8 --- /dev/null +++ b/language/python/extractor/src/core/storage.py @@ -0,0 +1,444 @@ +import os +import shutil +import sys + +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker, scoped_session + +from model.alias import Alias +from model.annotation_assignment_statement import AnnotationAssignmentStatement +from model.arg import Arg +from model.arguments import Argument +from model.assert_statement import AssertStatement +from model.assignment_statement import AssignmentStatement +from model.async_for_statement import AsyncForStatement +from model.async_function_def_statement import AsyncFunctionDefStatement +from model.async_with_statement import AsyncWithStatement +from model.attribute_expression import AttributeExpression +from model.augmented_assignment_statement import AugmentedAssignmentStatement +from model.await_expression import AwaitExpression +from model.bin_op_expression import BinOpExpression +from model.boolean_op_expression import BooleanOpExpression +from model.break_statement import BreakStatement +from model.call_expression import CallExpression +from model.class_def_statement import ClassDefStatement +from model.class_hierarchy import ClassHierarchy +from model.comment import Comment +from model.compare_expression import CompareExpression +from model.comprehension import Comprehension +from model.constant import Constant +from model.container_parent import ContainerParent +from model.continue_statement import ContinueStatement +from model.decorated_relation import DecoratedRelation +from model.decorator import Decorator +from model.delete_statement import DeleteStatement +from model.dict_comp_expression import DictCompExpression +from model.dict_expression import DictExpression +from model.docstring_comment import DocstringComment +from model.element import Element, Base +from model.except_handler import ExceptHandler +from model.expr_context import ExprContext +from model.expression import Expression +from model.expression_statement import ExpressionStatement +from model.file import File +from model.file_md5_sum import FileMd5Sum +from model.file_sha256_sum import FileSha256Sum +from model.folder import Folder +from model.for_statement import ForStatement +from model.formatted_value_expression import FormattedValueExpression +from model.function_def_statement import FunctionDefStatement +from model.generator_expression import GeneratorExpression +from model.global_statement import GlobalStatement +from model.if_expression import IfExpression +from model.if_statement import IfStatement +from model.import_from_statement import ImportFromStatement +from model.import_statement import ImportStatement +from model.joined_str_expression import JoinedStrExpression +from model.keyword import Keyword +from model.lambda_expression import LambdaExpression +from model.list_comp_expression import ListCompExpression +from model.list_expression import ListExpression +from model.location import Location +from model.match_case import MatchCase +from model.match_statement import MatchStatement +from model.modified_2to3_file import Modified2to3File +from model.module import Module +from model.name_expression import NameExpression +from model.named_expression import NamedExpression +from model.non_local_statement import NonLocalStatement +from model.number_of_lines import NumberOfLines +from model.parent import Parent +from model.parse_error_file import ParseErrorFile +from model.pass_statement import PassStatement +from model.program import Program +from model.raise_statement import RaiseStatement +from model.return_statement import ReturnStatement +from model.scope_enclosing_expression import ScopeEnclosingExpression +from model.scope_enclosing_statement import ScopeEnclosingStatement +from model.set_comp_expression import SetCompExpression +from model.set_expression import SetExpression +from model.slice import Slice +from model.starred_expression import StarredExpression +from model.statement import Statement +from model.subscript_expression import SubscriptExpression +from model.try_statement import TryStatement +from model.tuple_expression import TupleExpression +from model.unary_op_expression import UnaryOpExpression +from model.while_statement import WhileStatement +from model.with_item import WithItem +from model.with_statement import WithStatement +from model.yield_expression import YieldExpression +from model.yield_from_expression import YieldFromExpression + +object_dict = dict() +session = scoped_session(sessionmaker()) +engine = None + + +class Storage: + def __init__(self, dest_path): + self.db_dst_path = self.copy_db_file(dest_path) + self.create_session(self.db_dst_path) + self.insert_cache = {} + self.primary_key_cache = {} + pass + + @staticmethod + def copy_db_file(dest_path): + src_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + src_file = os.path.join(src_dir, "resources/coref_python_src.db") + + # Check if src_file exists, if not, create the database schema + if not os.path.isfile(src_file): + print("%s does not exist! Creating the database schema." % src_file) + sql_file = os.path.join(src_dir, "resources/coref_python_src.sql") + if not os.path.isfile(sql_file): + print("%s does not exist!" % sql_file) + return None + + engine = create_engine("sqlite:///" + src_file, echo=False) + Session = sessionmaker(bind=engine) + session = Session() + + with open(sql_file, "r") as f: + sql_statements = f.read() + statements = sql_statements.split(";") + for statement in statements: + session.execute(statement) + session.commit() + + session.close() + + db_file_name = os.path.split(src_file)[1] + if not os.path.exists(dest_path): + os.makedirs(dest_path) + db_dst_path = os.path.join(dest_path, db_file_name) + shutil.copy(src_file, db_dst_path) + return db_dst_path + + @staticmethod + def create_session(db_file): + global engine + if db_file is None: + print("Database preparation failed!") + sys.exit(-1) + + engine = create_engine("sqlite:///" + db_file, echo=False) + session.remove() + session.configure(bind=engine, autoflush=False, expire_on_commit=False) + Base.metadata.drop_all(engine) + Base.metadata.create_all(engine) + + def store_program(self, root): + self.insert(Program, root) + + def store_container_parent(self, container): + self.insert(ContainerParent, container) + + def store_parse_error_file(self, error): + self.insert(ParseErrorFile, error) + + def store_modified_file(self, file): + self.insert(Modified2to3File, file) + + def store_parent(self, parent): + self.insert(Parent, parent) + + def store_file(self, file): + self.insert(File, file) + + def store_comment(self, comment): + self.insert(Comment, comment) + + def store_docstring_comment(self, comment): + self.insert(DocstringComment, comment) + + def store_folder(self, folder): + self.insert(Folder, folder) + + def store_element(self, element): + self.insert(Element, element) + + def store_location(self, location): + self.insert(Location, location) + + def store_module(self, module): + self.insert(Module, module) + + def store_arguments(self, arguments): + self.insert(Argument, arguments) + + def store_constant(self, constant): + self.insert(Constant, constant) + + def store_expr_context(self, context): + self.insert(ExprContext, context) + + def store_alias(self, alias): + self.insert(Alias, alias) + + def store_comprehension(self, comprehension): + self.insert(Comprehension, comprehension) + + def store_scope_enclosing_stmt(self, enclosing): + self.insert(ScopeEnclosingStatement, enclosing) + + def store_scope_enclosing_expr(self, enclosing): + self.insert(ScopeEnclosingExpression, enclosing) + + def store_function_def_stmt(self, statement): + self.insert(FunctionDefStatement, statement) + + def store_if_stmt(self, statement): + self.insert(IfStatement, statement) + + def store_for_stmt(self, statement): + self.insert(ForStatement, statement) + + def store_while_stmt(self, statement): + self.insert(WhileStatement, statement) + + def store_try_stmt(self, statement): + self.insert(TryStatement, statement) + + def store_ann_assign_stmt(self, statement): + self.insert(AnnotationAssignmentStatement, statement) + + def store_except_handler(self, handler): + self.insert(ExceptHandler, handler) + + def store_if_expr(self, expression): + self.insert(IfExpression, expression) + + def store_name_expr(self, expression): + self.insert(NameExpression, expression) + + def store_formatted_value_expr(self, expression): + self.insert(FormattedValueExpression, expression) + + def store_bool_expr(self, expression): + self.insert(BooleanOpExpression, expression) + + def store_bin_expr(self, expression): + self.insert(BinOpExpression, expression) + + def store_call_expr(self, expression): + self.insert(CallExpression, expression) + + def store_attribute_expr(self, expression): + self.insert(AttributeExpression, expression) + + def store_await_expr(self, expression): + self.insert(AwaitExpression, expression) + + def store_compare_expr(self, expression): + self.insert(CompareExpression, expression) + + def store_dict_expr(self, expression): + self.insert(DictExpression, expression) + + def store_dict_comp_expr(self, expression): + self.insert(DictCompExpression, expression) + + def store_generator_expr(self, expression): + self.insert(GeneratorExpression, expression) + + def store_joined_str_expr(self, expression): + self.insert(JoinedStrExpression, expression) + + def store_lambda_expr(self, expression): + self.insert(LambdaExpression, expression) + + def store_list_expr(self, expression): + self.insert(ListExpression, expression) + + def store_list_comp_expr(self, expression): + self.insert(ListCompExpression, expression) + + def store_set_expr(self, expression): + self.insert(SetExpression, expression) + + def store_set_comp_expr(self, expression): + self.insert(SetCompExpression, expression) + + def store_starred_expr(self, expression): + self.insert(StarredExpression, expression) + + def store_tuple_expr(self, expression): + self.insert(TupleExpression, expression) + + def store_unary_op_expr(self, expression): + self.insert(UnaryOpExpression, expression) + + def store_yield_expr(self, expression): + self.insert(YieldExpression, expression) + + def store_yield_from_expr(self, expression): + self.insert(YieldFromExpression, expression) + + def store_named_expr(self, expression): + self.insert(NamedExpression, expression) + + def store_subscript_expr(self, expression): + self.insert(SubscriptExpression, expression) + + def store_arg(self, arg): + self.insert(Arg, arg) + + def store_keyword(self, keyword): + self.insert(Keyword, keyword) + + def store_slice(self, slice): + self.insert(Slice, slice) + + def store_withitem(self, withitem): + self.insert(WithItem, withitem) + + def store_class_def_stmt(self, statement): + self.insert(ClassDefStatement, statement) + + def store_break_stmt(self, statement): + self.insert(BreakStatement, statement) + + def store_stmt(self, statement): + self.insert(Statement, statement) + + def store_expr(self, expression): + self.insert(Expression, expression) + + def store_return_stmt(self, stmt): + self.insert(ReturnStatement, stmt) + + def store_global_stmt(self, stmt): + self.insert(GlobalStatement, stmt) + + def store_non_local_stmt(self, stmt): + self.insert(NonLocalStatement, stmt) + + def store_expression_stmt(self, stmt): + self.insert(ExpressionStatement, stmt) + + def store_match_stmt(self, statement): + self.insert(MatchStatement, statement) + + def store_import_stmt(self, statement): + self.insert(ImportStatement, statement) + + def store_import_from_stmt(self, statement): + self.insert(ImportFromStatement, statement) + + def store_assign_stmt(self, statement): + self.insert(AssignmentStatement, statement) + + def store_continue_stmt(self, statement): + self.insert(ContinueStatement, statement) + + def store_pass_stmt(self, statement): + self.insert(PassStatement, statement) + + def store_assert_stmt(self, statement): + self.insert(AssertStatement, statement) + + def store_with_stmt(self, statement): + self.insert(WithStatement, statement) + + def store_delete_stmt(self, statement): + self.insert(DeleteStatement, statement) + + def store_raise_stmt(self, statement): + self.insert(RaiseStatement, statement) + + def store_augassign_stmt(self, statement): + self.insert(AugmentedAssignmentStatement, statement) + + def store_async_for_stmt(self, statement): + self.insert(AsyncForStatement, statement) + + def store_async_with_stmt(self, statement): + self.insert(AsyncWithStatement, statement) + + def store_async_function_def_stmt(self, statement): + self.insert(AsyncFunctionDefStatement, statement) + + def store_decorator(self, decorator): + self.insert(Decorator, decorator) + + def store_decorated_relation(self, relation): + self.insert(DecoratedRelation, relation) + + def store_class_hierarchy(self, relation): + self.insert(ClassHierarchy, relation) + + def store_match_case(self, case): + self.insert(MatchCase, case) + + def store_file_md5_sum(self, md5_sum): + self.insert(FileMd5Sum, md5_sum) + + def store_file_sha256_sum(self, sha256_sum): + self.insert(FileSha256Sum, sha256_sum) + + def store_number_of_lines(self, lines): + self.insert(NumberOfLines, lines) + + @staticmethod + def get_primary_key_field_base(type_object: type) -> str: + result = None + for field, value in type_object.__dict__.items(): + if (not field.startswith("__")) and ( + getattr(value, "primary_key", None) is True + ): # 'is True' is necessary + # If two primary_keys, please check and modify this code. + assert result is None + result = field + # If there is crashed, please check the code which is generated. + assert result is not None + return result + + def get_primary_key_field(self, type_object: type) -> str: + if type_object not in self.primary_key_cache: + result = self.get_primary_key_field_base(type_object) + self.primary_key_cache[type_object] = result + return result + else: + return self.primary_key_cache[type_object] + + def insert(self, type_object, object): + key = object[self.get_primary_key_field(type_object)] + + if type_object not in self.insert_cache: + self.insert_cache[type_object] = set() + if key in self.insert_cache[type_object]: + return + self.insert_cache[type_object].add(key) + + if object_dict.get(type_object): + object_dict[type_object].append(object) + else: + object_dict.update({type_object: [object]}) + + def commit(self): + for key, value in object_dict.items(): + session.bulk_insert_mappings(key, value) + session.commit() + object_dict.clear() diff --git a/language/python/extractor/src/main.py b/language/python/extractor/src/main.py new file mode 100644 index 00000000..2f39e6a4 --- /dev/null +++ b/language/python/extractor/src/main.py @@ -0,0 +1,383 @@ +import argparse +import ast +import hashlib +import logging +import multiprocessing +import os.path +import sys +import time + +from core.extractor import Extractor +from core.idgenerator import get_oid, calculate_file_cache +from core.storage import Storage +from model.file import File + + +class ProgressBarPainter(object): + TypeOriginal = 1 + TypeScaleInLine = 2 + + def __init__(self): + self.DefaultType = ProgressBarPainter.TypeScaleInLine + self.CurrentProgress = 0.0 + self.TerminatorSize = 60 + + self.ProgressBarChar = "*" + self.ScaleBarChar = "-" + self.ScaleBarEndChar = None + self.Paint50 = True + self.Paint25And75 = True + + def set_progress_type(self, _type): + """Only support TypeOriginal and TypeScaleInLine mode.""" + self.DefaultType = _type + + def paint_progress_bar_scale(self, width): + def get_two_char_with_bar_columns(subwidth): + partition = int(subwidth / 2) + column_left = partition - 1 + column_right = subwidth - partition - 1 + return column_left, column_right + + def paint_progress_bar_scale_two_char_with_bar( + column_left, column_right, chars + ): + paint(self.ScaleBarChar * column_left) + paint(chars) + paint(self.ScaleBarChar * column_right) + + paint = sys.stdout.write + flush = sys.stdout.flush + # Paint + if self.ScaleBarEndChar is None: + paint("0") + paint(self.ScaleBarChar) + else: + paint(self.ScaleBarEndChar) + paint("0") + column_0_100 = width - 6 + if self.Paint50 and column_0_100 >= 4: # Paint 50 + column_0_50, column_50_100 = get_two_char_with_bar_columns(column_0_100) + if self.Paint25And75 and column_0_50 >= 4 and column_50_100 >= 4: + paint_progress_bar_scale_two_char_with_bar( + *get_two_char_with_bar_columns(column_0_50), "25" + ) + if self.Paint50: + paint("50") + else: + paint(self.ScaleBarChar * 2) + paint_progress_bar_scale_two_char_with_bar( + *get_two_char_with_bar_columns(column_50_100), "75" + ) + else: + paint_progress_bar_scale_two_char_with_bar( + column_0_50, column_50_100, "50" + ) + else: + paint(self.ScaleBarChar * column_0_100) + if self.ScaleBarEndChar is None: + paint(self.ScaleBarChar) + paint("100") + else: + paint("100") + paint(self.ScaleBarEndChar) + paint("\n") + flush() + + def paint_progress_bar(self, msg, percent: float): + if self.DefaultType == ProgressBarPainter.TypeOriginal: + delta = percent - self.CurrentProgress + if delta <= 0 or delta * self.TerminatorSize < 1: + return + # Base: + # Compiling[#####...] 100% + self.paint_progress_bar_1(msg, 1.0 * percent) + self.CurrentProgress = percent + elif self.DefaultType == ProgressBarPainter.TypeScaleInLine: + # Other: + # 0--25--75--100 + # Compiling ************** + # More six chars. + column = self.TerminatorSize + 6 + delta = percent - self.CurrentProgress + if delta <= 0 or delta * column < 1: + return + msg_max_width = 12 + if 0.0 == self.CurrentProgress: + sys.stdout.write(" " * msg_max_width) + self.paint_progress_bar_scale(column) + sys.stdout.write(msg) + sys.stdout.write(" " * (msg_max_width - len(msg))) + + self.CurrentProgress += int(delta * column) * 1.0 / column + sys.stdout.write(self.ProgressBarChar * int(delta * column)) + if percent >= 1: + sys.stdout.write("\n") + sys.stdout.flush() + + def paint_over(self): + if self.CurrentProgress != 0.0: + self.paint_progress_bar("", 1.0) + + def paint_progress_bar_1(self, msg, progress): + """progress a float range from 0 to 1""" + print( + "{0:9}[{1:<{2}}] {3:>3d}%\r".format( + msg, + "#" * int(progress * self.TerminatorSize), + self.TerminatorSize, + int(progress * 100), + ), + end="", + ) + + sys.stdout.flush() + + +def log_config(): + logger.setLevel(logging.DEBUG) + + console_handler = logging.StreamHandler() + console_handler.setLevel(logging.DEBUG) + + file_handler = logging.FileHandler("log.log", mode="w") + file_handler.setLevel(logging.NOTSET) + + formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + ) + console_handler.setFormatter(formatter) + file_handler.setFormatter(formatter) + + logger.addHandler(console_handler) + logger.addHandler(file_handler) + + +def main(): + start_time = time.perf_counter() + + parser = argparse.ArgumentParser(add_help=False) + parser.add_argument( + "-s", + "--src-dir", + type=str, + help="please input the source code directory path", + required=True, + ) + parser.add_argument( + "-d", + "--db-dir", + type=str, + help="please input the database directory path", + required=True, + ) + parser.add_argument( + "-h", + "--help", + action="help", + help="this is coref python extractor, please specify source " + "code root path and storage directory path of database, " + "either relative path or absolute path is acceptable.", + ) + argv = parser.parse_args() + src_dir = argv.src_dir + db_dir = argv.db_dir + + global root_dir + root_dir = os.path.abspath(src_dir) + db_dst_dir = os.path.abspath(db_dir) + + logger.info(f"Start extracting on: {root_dir}") + storage = Storage(db_dst_dir) + + global file_list + file_list = dict() + + create_program_node(root_dir, storage) + + size = len(file_list) + logger.info(f"There are total: {size} python files") + for idx, file in enumerate(file_list.values()): + extract_file(storage, file, 0) + + total_parse_time = time.perf_counter() - start_time + logger.info(f"Start commit records to db on: {db_dst_dir}") + storage.commit() + total_time = time.perf_counter() - start_time + total_insert_db_time = total_time - total_parse_time + logger.info( + f"Total execution time is: {total_time} s, total extraction time is: {total_parse_time} s, total db " + f"insertion time is: {total_insert_db_time} s" + ) + + +def extract_file(storage, file, i): + src_path = os.path.join(root_dir, file.relative_path) + line_count_dict = count_line_num(src_path, file, storage) + with open(src_path, "r", errors="ignore") as source: + import warnings + + warnings.filterwarnings("ignore") + try: + tree = ast.parse(source.read()) + Extractor(storage, file, src_path, tree, line_count_dict) + if i != 0: + modified_file = { + "element_oid": file.element_oid, + "relative_path": file.relative_path, + } + storage.store_modified_file(modified_file) + except SyntaxError as e: + logger.error( + f"Extracting syntax error (i.e., unsupported python 2.x files, indentation errors) on file {file.relative_path}" + ) + parse_error_file = { + "element_oid": file.element_oid, + "relative_path": file.relative_path, + "error_message": e.msg, + "error_text": e.text, + } + storage.store_parse_error_file(parse_error_file) + + +def create_program_node(root_path, storage): + absolute_prefix_path = os.path.abspath(root_path) + oid = get_oid(absolute_prefix_path) + program = {"program_oid": oid, "absolute_prefix_path": absolute_prefix_path} + storage.store_program(program) + visit_folder(root_path, storage, oid) + + +def visit_file(path, storage, oid): + fname = os.path.basename(path) + suffix = fname.split(".")[1] + file = File( + element_oid=oid, + relative_path=path, + extension=suffix, + name=fname, + number_of_lines_oid=oid, + ) + file_content = { + "element_oid": oid, + "relative_path": path, + "extension": suffix, + "name": fname, + "number_of_lines_oid": oid, + } + storage.store_file(file_content) + file_list[path] = file + + +def visit_folder(root_path, storage, parent_oid): + root_rel_path = os.path.relpath(root_path, root_dir) + dirs = os.listdir(root_path) + + for file in dirs: + abs_path = os.path.join(root_path, file) + if os.path.isdir(abs_path): + dir_rel_path = ( + os.path.join(root_rel_path, file) if root_rel_path != "." else file + ) + if dir_rel_path.startswith(".") or file.startswith("__"): + pass + else: + dir_oid = get_oid(dir_rel_path) + folder = { + "element_oid": dir_oid, + "qualified_name": dir_rel_path, + "name": file, + "parent_oid": parent_oid, + } + storage.store_folder(folder) + + visit_folder(abs_path, storage, dir_oid) + else: + if os.path.splitext(file)[-1] == ".py": + file_path = ( + os.path.join(root_rel_path, file) if root_rel_path != "." else file + ) + sha256_value = calculate_file_cache(abs_path, hashlib.sha256()) + md5_value = calculate_file_cache(abs_path, hashlib.md5()) + file_oid = get_oid(abs_path + sha256_value + md5_value) + + container_parent = {"child_oid": file_oid, "parent_oid": parent_oid} + storage.store_container_parent(container_parent) + file_sha256_sum = {"file_oid": file_oid, "value": sha256_value} + storage.store_file_sha256_sum(file_sha256_sum) + file_md5_sum = {"file_oid": file_oid, "value": md5_value} + storage.store_file_md5_sum(file_md5_sum) + + visit_file(file_path, storage, file_oid) + + +def count_line_num( + file_path, + file, + storage, + single_line_annotation="#", + multi_line_annotation_start=('"""', "'''"), + multi_line_annotation_end=('"""', "'''"), +): + """ + count the number of lines in a file. + Args: + file_path: the src file path + file: coref file object + storage: storage object for saving the data + single_line_annotation: the flag for single line comment, like '#' + multi_line_annotation_start: the flag for multi-line comment start line, like ''' + multi_line_annotation_end:the flag for multi-line comment end line, like ''' + Returns: the dict for every line with its flog, 0 is empty, 1 is comment, 2 is code + """ + line_count_dict = dict() + code_num = blank_num = comment_num = 0 + + with open(file_path, "r", errors="ignore") as f: + flag = False + count = 0 + try: + for i in f.readlines(): + count += 1 + i = i.strip().strip("\n") + if not i: + blank_num += 1 + line_count_dict[count] = 0 + continue + else: + if i.startswith(single_line_annotation): + comment_num += 1 + line_count_dict[count] = 1 + continue + if not flag and i.startswith(multi_line_annotation_start): + comment_num += 1 + flag = True + line_count_dict[count] = 1 + continue + if flag: + comment_num += 1 + line_count_dict[count] = 1 + if i.endswith(multi_line_annotation_end): + flag = False + continue + else: + code_num += 1 + line_count_dict[count] = 2 + number_of_lines = { + "element_oid": file.element_oid, + "number_of_total_lines": code_num + blank_num + comment_num, + "number_of_valid_lines": code_num, + "number_of_comment_lines": comment_num, + } + storage.store_number_of_lines(number_of_lines) + except (UnicodeDecodeError, TypeError) as e: + logger.error(f"Error occurs on file {file.name} line {e.lineno}") + return line_count_dict + + +if __name__ == "__main__": + logger = logging.getLogger() + log_config() + multiprocessing.freeze_support() + file_mappings = [] + main() diff --git a/language/python/extractor/src/model/__init__.py b/language/python/extractor/src/model/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/language/python/extractor/src/model/alias.py b/language/python/extractor/src/model/alias.py new file mode 100644 index 00000000..8696e554 --- /dev/null +++ b/language/python/extractor/src/model/alias.py @@ -0,0 +1,18 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Alias(Base): + __tablename__ = "alias" + + element_oid = Column(Integer, primary_key=True) + name = Column(Text, nullable=False) + asname = Column(Text, nullable=False) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/annotated_relation.py b/language/python/extractor/src/model/annotated_relation.py new file mode 100644 index 00000000..bdf4494a --- /dev/null +++ b/language/python/extractor/src/model/annotated_relation.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AnnotatedRelation(Base): + __tablename__ = "annotated_relation" + + annotation_oid = Column(Integer, primary_key=True) + annotated_item_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/annotation.py b/language/python/extractor/src/model/annotation.py new file mode 100644 index 00000000..32318d17 --- /dev/null +++ b/language/python/extractor/src/model/annotation.py @@ -0,0 +1,17 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Annotation(Base): + __tablename__ = "annotation" + + element_oid = Column(Integer, primary_key=True) + name = Column(Text, nullable=False) + annotation_declaration_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text) + parent_oid = Column(Integer) diff --git a/language/python/extractor/src/model/annotation_assignment_statement.py b/language/python/extractor/src/model/annotation_assignment_statement.py new file mode 100644 index 00000000..95dcded0 --- /dev/null +++ b/language/python/extractor/src/model/annotation_assignment_statement.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AnnotationAssignmentStatement(Base): + __tablename__ = "annotation_assignment_statement" + + element_oid = Column(Integer, primary_key=True) + annotation_oid = Column(Integer, nullable=False) + target_oid = Column(Integer, nullable=False) + is_simple = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/arg.py b/language/python/extractor/src/model/arg.py new file mode 100644 index 00000000..023b8b23 --- /dev/null +++ b/language/python/extractor/src/model/arg.py @@ -0,0 +1,17 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Arg(Base): + __tablename__ = "arg" + + element_oid = Column(Integer, primary_key=True) + annotation = Column(Integer, nullable=False) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/arguments.py b/language/python/extractor/src/model/arguments.py new file mode 100644 index 00000000..b54e2584 --- /dev/null +++ b/language/python/extractor/src/model/arguments.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Argument(Base): + __tablename__ = "arguments" + + element_oid = Column(Integer, primary_key=True) + parent_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/assert_statement.py b/language/python/extractor/src/model/assert_statement.py new file mode 100644 index 00000000..2f4f6742 --- /dev/null +++ b/language/python/extractor/src/model/assert_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AssertStatement(Base): + __tablename__ = "assert_statement" + + element_oid = Column(Integer, primary_key=True) + assert_condition_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/assignment_statement.py b/language/python/extractor/src/model/assignment_statement.py new file mode 100644 index 00000000..7314966f --- /dev/null +++ b/language/python/extractor/src/model/assignment_statement.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AssignmentStatement(Base): + __tablename__ = "assignment_statement" + + element_oid = Column(Integer, primary_key=True) + value_oid = Column(Integer, nullable=False) + targets_size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/async_for_statement.py b/language/python/extractor/src/model/async_for_statement.py new file mode 100644 index 00000000..b21bdb55 --- /dev/null +++ b/language/python/extractor/src/model/async_for_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AsyncForStatement(Base): + __tablename__ = "async_for_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/async_function_def_statement.py b/language/python/extractor/src/model/async_function_def_statement.py new file mode 100644 index 00000000..9b16353a --- /dev/null +++ b/language/python/extractor/src/model/async_function_def_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AsyncFunctionDefStatement(Base): + __tablename__ = "async_function_def_statement" + + element_oid = Column(Integer, primary_key=True) + name = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/async_with_statement.py b/language/python/extractor/src/model/async_with_statement.py new file mode 100644 index 00000000..8049e0f1 --- /dev/null +++ b/language/python/extractor/src/model/async_with_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AsyncWithStatement(Base): + __tablename__ = "async_with_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/attribute_expression.py b/language/python/extractor/src/model/attribute_expression.py new file mode 100644 index 00000000..9c79a7af --- /dev/null +++ b/language/python/extractor/src/model/attribute_expression.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AttributeExpression(Base): + __tablename__ = "attribute_expression" + + element_oid = Column(Integer, primary_key=True) + value_oid = Column(Integer, nullable=False) + ctx_type = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/augmented_assignment_statement.py b/language/python/extractor/src/model/augmented_assignment_statement.py new file mode 100644 index 00000000..6b4097e7 --- /dev/null +++ b/language/python/extractor/src/model/augmented_assignment_statement.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AugmentedAssignmentStatement(Base): + __tablename__ = "augmented_assignment_statement" + + element_oid = Column(Integer, primary_key=True) + op_code = Column(Text, nullable=False) + target_expr_oid = Column(Integer, nullable=False) + value_expr_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/await_expression.py b/language/python/extractor/src/model/await_expression.py new file mode 100644 index 00000000..07f78ce4 --- /dev/null +++ b/language/python/extractor/src/model/await_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class AwaitExpression(Base): + __tablename__ = "await_expression" + + element_oid = Column(Integer, primary_key=True) + expr_value_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/bin_op_expression.py b/language/python/extractor/src/model/bin_op_expression.py new file mode 100644 index 00000000..92cd82e7 --- /dev/null +++ b/language/python/extractor/src/model/bin_op_expression.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class BinOpExpression(Base): + __tablename__ = "bin_op_expression" + + element_oid = Column(Integer, primary_key=True) + left_expr_oid = Column(Integer, nullable=False) + opcode = Column(Integer, nullable=False) + right_expr_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/boolean_op_expression.py b/language/python/extractor/src/model/boolean_op_expression.py new file mode 100644 index 00000000..0a19089e --- /dev/null +++ b/language/python/extractor/src/model/boolean_op_expression.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class BooleanOpExpression(Base): + __tablename__ = "boolean_op_expression" + + element_oid = Column(Integer, primary_key=True) + type = Column(Text, nullable=False) + size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/break_statement.py b/language/python/extractor/src/model/break_statement.py new file mode 100644 index 00000000..abbd1e26 --- /dev/null +++ b/language/python/extractor/src/model/break_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class BreakStatement(Base): + __tablename__ = "break_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/call_expression.py b/language/python/extractor/src/model/call_expression.py new file mode 100644 index 00000000..77160f63 --- /dev/null +++ b/language/python/extractor/src/model/call_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class CallExpression(Base): + __tablename__ = "call_expression" + + element_oid = Column(Integer, primary_key=True) + expr_func_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/callable_binding.py b/language/python/extractor/src/model/callable_binding.py new file mode 100644 index 00000000..8ab40189 --- /dev/null +++ b/language/python/extractor/src/model/callable_binding.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class CallableBinding(Base): + __tablename__ = "callable_binding" + + caller_oid = Column(Integer, primary_key=True) + callee_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/class_def_statement.py b/language/python/extractor/src/model/class_def_statement.py new file mode 100644 index 00000000..69e13223 --- /dev/null +++ b/language/python/extractor/src/model/class_def_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ClassDefStatement(Base): + __tablename__ = "class_def_statement" + + element_oid = Column(Integer, primary_key=True) + name = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/class_hierarchy.py b/language/python/extractor/src/model/class_hierarchy.py new file mode 100644 index 00000000..c98a7d54 --- /dev/null +++ b/language/python/extractor/src/model/class_hierarchy.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ClassHierarchy(Base): + __tablename__ = "class_hierarchy" + + base_oid = Column(Integer, primary_key=True) + class_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/cmpop.py b/language/python/extractor/src/model/cmpop.py new file mode 100644 index 00000000..45242fe8 --- /dev/null +++ b/language/python/extractor/src/model/cmpop.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Cmpop(Base): + __tablename__ = "cmpop" + + element_oid = Column(Integer, primary_key=True) + value = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/comment.py b/language/python/extractor/src/model/comment.py new file mode 100644 index 00000000..6965a0ce --- /dev/null +++ b/language/python/extractor/src/model/comment.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Comment(Base): + __tablename__ = "comment" + + element_oid = Column(Integer, primary_key=True) + text = Column(Text, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/compare_expression.py b/language/python/extractor/src/model/compare_expression.py new file mode 100644 index 00000000..47497c12 --- /dev/null +++ b/language/python/extractor/src/model/compare_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class CompareExpression(Base): + __tablename__ = "compare_expression" + + element_oid = Column(Integer, primary_key=True) + left_expr_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/comprehension.py b/language/python/extractor/src/model/comprehension.py new file mode 100644 index 00000000..87f2fa75 --- /dev/null +++ b/language/python/extractor/src/model/comprehension.py @@ -0,0 +1,17 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Comprehension(Base): + __tablename__ = "comprehension" + + element_oid = Column(Integer, primary_key=True) + target_expr_oid = Column(Integer, nullable=False) + iter_expr_oid = Column(Integer, nullable=False) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/constant.py b/language/python/extractor/src/model/constant.py new file mode 100644 index 00000000..459a64bf --- /dev/null +++ b/language/python/extractor/src/model/constant.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Constant(Base): + __tablename__ = "constant" + + element_oid = Column(Integer, primary_key=True) + value = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/container_parent.py b/language/python/extractor/src/model/container_parent.py new file mode 100644 index 00000000..d483f86e --- /dev/null +++ b/language/python/extractor/src/model/container_parent.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ContainerParent(Base): + __tablename__ = "container_parent" + + child_oid = Column(Integer, primary_key=True) + parent_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/continue_statement.py b/language/python/extractor/src/model/continue_statement.py new file mode 100644 index 00000000..f036776f --- /dev/null +++ b/language/python/extractor/src/model/continue_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ContinueStatement(Base): + __tablename__ = "continue_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/decorated_relation.py b/language/python/extractor/src/model/decorated_relation.py new file mode 100644 index 00000000..2fcc89c6 --- /dev/null +++ b/language/python/extractor/src/model/decorated_relation.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class DecoratedRelation(Base): + __tablename__ = "decorated_relation" + + decorator_oid = Column(Integer, primary_key=True) + decorated_element_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/decorator.py b/language/python/extractor/src/model/decorator.py new file mode 100644 index 00000000..50322530 --- /dev/null +++ b/language/python/extractor/src/model/decorator.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Decorator(Base): + __tablename__ = "decorator" + + element_oid = Column(Integer, primary_key=True) + type = Column(Text, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/delete_statement.py b/language/python/extractor/src/model/delete_statement.py new file mode 100644 index 00000000..f82b8e9f --- /dev/null +++ b/language/python/extractor/src/model/delete_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class DeleteStatement(Base): + __tablename__ = "delete_statement" + + element_oid = Column(Integer, primary_key=True) + targets_size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/dict_comp_expression.py b/language/python/extractor/src/model/dict_comp_expression.py new file mode 100644 index 00000000..54c66816 --- /dev/null +++ b/language/python/extractor/src/model/dict_comp_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class DictCompExpression(Base): + __tablename__ = "dict_comp_expression" + + element_oid = Column(Integer, primary_key=True) + comprehension_size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/dict_expression.py b/language/python/extractor/src/model/dict_expression.py new file mode 100644 index 00000000..bfca16bf --- /dev/null +++ b/language/python/extractor/src/model/dict_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class DictExpression(Base): + __tablename__ = "dict_expression" + + element_oid = Column(Integer, primary_key=True) + size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/docstring_comment.py b/language/python/extractor/src/model/docstring_comment.py new file mode 100644 index 00000000..15db4ee3 --- /dev/null +++ b/language/python/extractor/src/model/docstring_comment.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class DocstringComment(Base): + __tablename__ = "docstring_comment" + + element_oid = Column(Integer, primary_key=True) + text = Column(Text, nullable=False) + documented_element_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/element.py b/language/python/extractor/src/model/element.py new file mode 100644 index 00000000..00304ef0 --- /dev/null +++ b/language/python/extractor/src/model/element.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Element(Base): + __tablename__ = "element" + + oid = Column(Integer, primary_key=True) + value = Column(Text, nullable=False) + type = Column(Text, nullable=False) + parent_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/except_handler.py b/language/python/extractor/src/model/except_handler.py new file mode 100644 index 00000000..4d2e4d1f --- /dev/null +++ b/language/python/extractor/src/model/except_handler.py @@ -0,0 +1,16 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ExceptHandler(Base): + __tablename__ = "except_handler" + + element_oid = Column(Integer, primary_key=True) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/expr_context.py b/language/python/extractor/src/model/expr_context.py new file mode 100644 index 00000000..b52d9afa --- /dev/null +++ b/language/python/extractor/src/model/expr_context.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ExprContext(Base): + __tablename__ = "expr_context" + + element_oid = Column(Integer, primary_key=True) + parent_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/expression.py b/language/python/extractor/src/model/expression.py new file mode 100644 index 00000000..0f886f01 --- /dev/null +++ b/language/python/extractor/src/model/expression.py @@ -0,0 +1,17 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Expression(Base): + __tablename__ = "expression" + + element_oid = Column(Integer, primary_key=True) + type = Column(Text, nullable=False) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/expression_statement.py b/language/python/extractor/src/model/expression_statement.py new file mode 100644 index 00000000..3ab63e92 --- /dev/null +++ b/language/python/extractor/src/model/expression_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ExpressionStatement(Base): + __tablename__ = "expression_statement" + + element_oid = Column(Integer, primary_key=True) + value_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/file.py b/language/python/extractor/src/model/file.py new file mode 100644 index 00000000..3e25647a --- /dev/null +++ b/language/python/extractor/src/model/file.py @@ -0,0 +1,16 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class File(Base): + __tablename__ = "file" + + element_oid = Column(Integer, primary_key=True) + relative_path = Column(Text, nullable=False) + extension = Column(Text, nullable=False) + name = Column(Text, nullable=False) + number_of_lines_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/file_md5_sum.py b/language/python/extractor/src/model/file_md5_sum.py new file mode 100644 index 00000000..1fe96bb0 --- /dev/null +++ b/language/python/extractor/src/model/file_md5_sum.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class FileMd5Sum(Base): + __tablename__ = "file_md5_sum" + + file_oid = Column(Integer, primary_key=True) + value = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/file_sha256_sum.py b/language/python/extractor/src/model/file_sha256_sum.py new file mode 100644 index 00000000..55069d9e --- /dev/null +++ b/language/python/extractor/src/model/file_sha256_sum.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class FileSha256Sum(Base): + __tablename__ = "file_sha256_sum" + + file_oid = Column(Integer, primary_key=True) + value = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/folder.py b/language/python/extractor/src/model/folder.py new file mode 100644 index 00000000..fa157229 --- /dev/null +++ b/language/python/extractor/src/model/folder.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Folder(Base): + __tablename__ = "folder" + + element_oid = Column(Integer, primary_key=True) + qualified_name = Column(Text, nullable=False) + name = Column(Text, nullable=False) + parent_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/for_statement.py b/language/python/extractor/src/model/for_statement.py new file mode 100644 index 00000000..d7a31991 --- /dev/null +++ b/language/python/extractor/src/model/for_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ForStatement(Base): + __tablename__ = "for_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/formatted_value_expression.py b/language/python/extractor/src/model/formatted_value_expression.py new file mode 100644 index 00000000..26d6fc5d --- /dev/null +++ b/language/python/extractor/src/model/formatted_value_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class FormattedValueExpression(Base): + __tablename__ = "formatted_value_expression" + + element_oid = Column(Integer, primary_key=True) + value_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/function_def_statement.py b/language/python/extractor/src/model/function_def_statement.py new file mode 100644 index 00000000..e75ad331 --- /dev/null +++ b/language/python/extractor/src/model/function_def_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class FunctionDefStatement(Base): + __tablename__ = "function_def_statement" + + element_oid = Column(Integer, primary_key=True) + name = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/generator_expression.py b/language/python/extractor/src/model/generator_expression.py new file mode 100644 index 00000000..1bff3bc4 --- /dev/null +++ b/language/python/extractor/src/model/generator_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class GeneratorExpression(Base): + __tablename__ = "generator_expression" + + element_oid = Column(Integer, primary_key=True) + elt_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/global_statement.py b/language/python/extractor/src/model/global_statement.py new file mode 100644 index 00000000..8f35fc43 --- /dev/null +++ b/language/python/extractor/src/model/global_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class GlobalStatement(Base): + __tablename__ = "global_statement" + + element_oid = Column(Integer, primary_key=True) + names = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/if_expression.py b/language/python/extractor/src/model/if_expression.py new file mode 100644 index 00000000..76f7863a --- /dev/null +++ b/language/python/extractor/src/model/if_expression.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class IfExpression(Base): + __tablename__ = "if_expression" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/if_statement.py b/language/python/extractor/src/model/if_statement.py new file mode 100644 index 00000000..2225d3e7 --- /dev/null +++ b/language/python/extractor/src/model/if_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class IfStatement(Base): + __tablename__ = "if_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/import_from_statement.py b/language/python/extractor/src/model/import_from_statement.py new file mode 100644 index 00000000..d5eb2a11 --- /dev/null +++ b/language/python/extractor/src/model/import_from_statement.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ImportFromStatement(Base): + __tablename__ = "import_from_statement" + + element_oid = Column(Integer, primary_key=True) + module = Column(Text, nullable=False) + level = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/import_statement.py b/language/python/extractor/src/model/import_statement.py new file mode 100644 index 00000000..17aaab37 --- /dev/null +++ b/language/python/extractor/src/model/import_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ImportStatement(Base): + __tablename__ = "import_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/joined_str_expression.py b/language/python/extractor/src/model/joined_str_expression.py new file mode 100644 index 00000000..b8355f21 --- /dev/null +++ b/language/python/extractor/src/model/joined_str_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class JoinedStrExpression(Base): + __tablename__ = "joined_str_expression" + + element_oid = Column(Integer, primary_key=True) + size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/keyword.py b/language/python/extractor/src/model/keyword.py new file mode 100644 index 00000000..99e2a4bc --- /dev/null +++ b/language/python/extractor/src/model/keyword.py @@ -0,0 +1,18 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Keyword(Base): + __tablename__ = "keyword" + + element_oid = Column(Integer, primary_key=True) + arg_value = Column(Text, nullable=False) + value_oid = Column(Integer, nullable=False) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/lambda_expression.py b/language/python/extractor/src/model/lambda_expression.py new file mode 100644 index 00000000..6dba1fa5 --- /dev/null +++ b/language/python/extractor/src/model/lambda_expression.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class LambdaExpression(Base): + __tablename__ = "lambda_expression" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/list_comp_expression.py b/language/python/extractor/src/model/list_comp_expression.py new file mode 100644 index 00000000..5eb9d16f --- /dev/null +++ b/language/python/extractor/src/model/list_comp_expression.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ListCompExpression(Base): + __tablename__ = "list_comp_expression" + + element_oid = Column(Integer, primary_key=True) + elt_oid = Column(Integer, nullable=False) + generator_size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/list_expression.py b/language/python/extractor/src/model/list_expression.py new file mode 100644 index 00000000..f7d37ae3 --- /dev/null +++ b/language/python/extractor/src/model/list_expression.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ListExpression(Base): + __tablename__ = "list_expression" + + element_oid = Column(Integer, primary_key=True) + elt_size = Column(Integer, nullable=False) + ctx = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/location.py b/language/python/extractor/src/model/location.py new file mode 100644 index 00000000..cff42fad --- /dev/null +++ b/language/python/extractor/src/model/location.py @@ -0,0 +1,17 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Location(Base): + __tablename__ = "location" + + element_oid = Column(Integer, primary_key=True) + file_oid = Column(Integer, nullable=False) + start_line_number = Column(Integer, nullable=False) + start_column_number = Column(Integer, nullable=False) + end_line_number = Column(Integer, nullable=False) + end_column_number = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/long_literal.py b/language/python/extractor/src/model/long_literal.py new file mode 100644 index 00000000..2be541ba --- /dev/null +++ b/language/python/extractor/src/model/long_literal.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class LongLiteral(Base): + __tablename__ = "long_literal" + + element_oid = Column(Integer, primary_key=True) + value = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/match_case.py b/language/python/extractor/src/model/match_case.py new file mode 100644 index 00000000..97809485 --- /dev/null +++ b/language/python/extractor/src/model/match_case.py @@ -0,0 +1,18 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class MatchCase(Base): + __tablename__ = "match_case" + + element_oid = Column(Integer, primary_key=True) + pattern_oid = Column(Integer, nullable=False) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) + is_default = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/match_statement.py b/language/python/extractor/src/model/match_statement.py new file mode 100644 index 00000000..8bd39bb2 --- /dev/null +++ b/language/python/extractor/src/model/match_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class MatchStatement(Base): + __tablename__ = "match_statement" + + element_oid = Column(Integer, primary_key=True) + subject_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/metainfo.py b/language/python/extractor/src/model/metainfo.py new file mode 100644 index 00000000..2884de33 --- /dev/null +++ b/language/python/extractor/src/model/metainfo.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, MetaData, Table, Text + +metadata = MetaData() + + +t_metainfo = Table( + "metainfo", + metadata, + Column("oid", Integer), + Column("kind", Text), + Column("value", Text), + Column("program_oid", Integer), +) diff --git a/language/python/extractor/src/model/mod.py b/language/python/extractor/src/model/mod.py new file mode 100644 index 00000000..f7abf1f8 --- /dev/null +++ b/language/python/extractor/src/model/mod.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Mod(Base): + __tablename__ = "mod" + + element_oid = Column(Integer, primary_key=True) + type = Column(Text, nullable=False) + location_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/models_main.py b/language/python/extractor/src/model/models_main.py new file mode 100644 index 00000000..503312be --- /dev/null +++ b/language/python/extractor/src/model/models_main.py @@ -0,0 +1,31 @@ +import subprocess + + +def main(): + db_path = "sqlite:///../resources/coref_python_src.db" + table_name = "yield_expression" + dao_class_name = table_name + ".py" + print( + subprocess.call( + [ + "sqlacodegen", + db_path, + "--tables", + table_name, + "--outfile", + dao_class_name, + ] + ), + flush=True, + ) + # with open("../resources/coref_python_src.sql", "r") as source: + # contents = source.readlines() + # for line in contents: + # if line.startswith("CREATE"): + # table_name = line.split("\"")[1] + # dao_class_name = table_name + ".py" + # print(subprocess.call(["sqlacodegen", db_path, "--tables", table_name, "--outfile", dao_class_name]), flush=True) + + +if __name__ == "__main__": + main() diff --git a/language/python/extractor/src/model/modified_2to3_file.py b/language/python/extractor/src/model/modified_2to3_file.py new file mode 100644 index 00000000..1eb51aa3 --- /dev/null +++ b/language/python/extractor/src/model/modified_2to3_file.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Modified2to3File(Base): + __tablename__ = "modified_2to3_file" + + element_oid = Column(Integer, primary_key=True) + relative_path = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/modifier.py b/language/python/extractor/src/model/modifier.py new file mode 100644 index 00000000..ee353cd3 --- /dev/null +++ b/language/python/extractor/src/model/modifier.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Modifier(Base): + __tablename__ = "modifier" + + element_oid = Column(Integer, primary_key=True) + name = Column(Text) + parent_oid = Column(Integer) + location_oid = Column(Integer) diff --git a/language/python/extractor/src/model/module.py b/language/python/extractor/src/model/module.py new file mode 100644 index 00000000..88509eaf --- /dev/null +++ b/language/python/extractor/src/model/module.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Module(Base): + __tablename__ = "module" + + element_oid = Column(Integer, primary_key=True) + name = Column(Text, nullable=False) + file_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/module_enclosing_expression.py b/language/python/extractor/src/model/module_enclosing_expression.py new file mode 100644 index 00000000..8b032d5a --- /dev/null +++ b/language/python/extractor/src/model/module_enclosing_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ModuleEnclosingExpression(Base): + __tablename__ = "module_enclosing_expression" + + expression_oid = Column(Integer, primary_key=True) + module_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/module_enclosing_statement.py b/language/python/extractor/src/model/module_enclosing_statement.py new file mode 100644 index 00000000..7081642a --- /dev/null +++ b/language/python/extractor/src/model/module_enclosing_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ModuleEnclosingStatement(Base): + __tablename__ = "module_enclosing_statement" + + statement_oid = Column(Integer, primary_key=True) + module_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/name_expression.py b/language/python/extractor/src/model/name_expression.py new file mode 100644 index 00000000..3c5694b7 --- /dev/null +++ b/language/python/extractor/src/model/name_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class NameExpression(Base): + __tablename__ = "name_expression" + + element_oid = Column(Integer, primary_key=True) + ctx_type = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/named_expression.py b/language/python/extractor/src/model/named_expression.py new file mode 100644 index 00000000..d8e713bf --- /dev/null +++ b/language/python/extractor/src/model/named_expression.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class NamedExpression(Base): + __tablename__ = "named_expression" + + element_oid = Column(Integer, primary_key=True) + target_oid = Column(Integer, nullable=False) + value_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/non_local_statement.py b/language/python/extractor/src/model/non_local_statement.py new file mode 100644 index 00000000..c69a17fb --- /dev/null +++ b/language/python/extractor/src/model/non_local_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class NonLocalStatement(Base): + __tablename__ = "non_local_statement" + + element_oid = Column(Integer, primary_key=True) + names = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/number_of_lines.py b/language/python/extractor/src/model/number_of_lines.py new file mode 100644 index 00000000..aa9d9a0c --- /dev/null +++ b/language/python/extractor/src/model/number_of_lines.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class NumberOfLines(Base): + __tablename__ = "number_of_lines" + + element_oid = Column(Integer, primary_key=True) + number_of_total_lines = Column(Integer) + number_of_valid_lines = Column(Integer) + number_of_comment_lines = Column(Integer) diff --git a/language/python/extractor/src/model/operator.py b/language/python/extractor/src/model/operator.py new file mode 100644 index 00000000..5a64150b --- /dev/null +++ b/language/python/extractor/src/model/operator.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Operator(Base): + __tablename__ = "operator" + + element_oid = Column(Integer, primary_key=True) + location_oid = Column(Integer) + parent_oid = Column(Integer) + printable_text = Column(Text) diff --git a/language/python/extractor/src/model/parent.py b/language/python/extractor/src/model/parent.py new file mode 100644 index 00000000..65d50fc7 --- /dev/null +++ b/language/python/extractor/src/model/parent.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Parent(Base): + __tablename__ = "parent" + + parent_oid = Column(Integer, primary_key=True) + parent_type = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/parse_error_file.py b/language/python/extractor/src/model/parse_error_file.py new file mode 100644 index 00000000..c04c8d6d --- /dev/null +++ b/language/python/extractor/src/model/parse_error_file.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ParseErrorFile(Base): + __tablename__ = "parse_error_file" + + element_oid = Column(Integer, primary_key=True) + relative_path = Column(Text, nullable=False) + error_message = Column(Text, nullable=False) + error_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/pass_statement.py b/language/python/extractor/src/model/pass_statement.py new file mode 100644 index 00000000..a77c71a2 --- /dev/null +++ b/language/python/extractor/src/model/pass_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class PassStatement(Base): + __tablename__ = "pass_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/pattern.py b/language/python/extractor/src/model/pattern.py new file mode 100644 index 00000000..a32d1752 --- /dev/null +++ b/language/python/extractor/src/model/pattern.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Pattern(Base): + __tablename__ = "pattern" + + element_oid = Column(Integer, primary_key=True) + value = Column(Text) + location_oid = Column(Integer) + parent_oid = Column(Integer) diff --git a/language/python/extractor/src/model/program.py b/language/python/extractor/src/model/program.py new file mode 100644 index 00000000..e7b67d5b --- /dev/null +++ b/language/python/extractor/src/model/program.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Program(Base): + __tablename__ = "program" + + program_oid = Column(Integer, primary_key=True) + absolute_prefix_path = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/raise_statement.py b/language/python/extractor/src/model/raise_statement.py new file mode 100644 index 00000000..11d14177 --- /dev/null +++ b/language/python/extractor/src/model/raise_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class RaiseStatement(Base): + __tablename__ = "raise_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/reference_relation.py b/language/python/extractor/src/model/reference_relation.py new file mode 100644 index 00000000..db0877ec --- /dev/null +++ b/language/python/extractor/src/model/reference_relation.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ReferenceRelation(Base): + __tablename__ = "reference_relation" + + reference_element_oid = Column(Integer, primary_key=True) + definition_element_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/return_statement.py b/language/python/extractor/src/model/return_statement.py new file mode 100644 index 00000000..092992d8 --- /dev/null +++ b/language/python/extractor/src/model/return_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ReturnStatement(Base): + __tablename__ = "return_statement" + + element_oid = Column(Integer, primary_key=True) + is_return_empty = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/scope_enclosing_expression.py b/language/python/extractor/src/model/scope_enclosing_expression.py new file mode 100644 index 00000000..4422933e --- /dev/null +++ b/language/python/extractor/src/model/scope_enclosing_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ScopeEnclosingExpression(Base): + __tablename__ = "scope_enclosing_expression" + + expression_oid = Column(Integer, primary_key=True) + scope_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/scope_enclosing_statement.py b/language/python/extractor/src/model/scope_enclosing_statement.py new file mode 100644 index 00000000..15cef4cc --- /dev/null +++ b/language/python/extractor/src/model/scope_enclosing_statement.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class ScopeEnclosingStatement(Base): + __tablename__ = "scope_enclosing_statement" + + statement_oid = Column(Integer, primary_key=True) + scope_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/set_comp_expression.py b/language/python/extractor/src/model/set_comp_expression.py new file mode 100644 index 00000000..f4e05ba3 --- /dev/null +++ b/language/python/extractor/src/model/set_comp_expression.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class SetCompExpression(Base): + __tablename__ = "set_comp_expression" + + element_oid = Column(Integer, primary_key=True) + elt_oid = Column(Integer, nullable=False) + generator_size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/set_expression.py b/language/python/extractor/src/model/set_expression.py new file mode 100644 index 00000000..e82c33d4 --- /dev/null +++ b/language/python/extractor/src/model/set_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class SetExpression(Base): + __tablename__ = "set_expression" + + element_oid = Column(Integer, primary_key=True) + elt_size = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/slice.py b/language/python/extractor/src/model/slice.py new file mode 100644 index 00000000..aa2a9582 --- /dev/null +++ b/language/python/extractor/src/model/slice.py @@ -0,0 +1,17 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Slice(Base): + __tablename__ = "slice" + + element_oid = Column(Integer, primary_key=True) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) + has_step = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/slice_expression.py b/language/python/extractor/src/model/slice_expression.py new file mode 100644 index 00000000..fa60c86c --- /dev/null +++ b/language/python/extractor/src/model/slice_expression.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class SliceExpression(Base): + __tablename__ = "slice_expression" + + element_oid = Column(Integer, primary_key=True) + lower = Column(Integer) + step = Column(Integer) + upper = Column(Integer) diff --git a/language/python/extractor/src/model/starred_expression.py b/language/python/extractor/src/model/starred_expression.py new file mode 100644 index 00000000..502989ef --- /dev/null +++ b/language/python/extractor/src/model/starred_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class StarredExpression(Base): + __tablename__ = "starred_expression" + + element_oid = Column(Integer, primary_key=True) + ctx = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/statement.py b/language/python/extractor/src/model/statement.py new file mode 100644 index 00000000..f949b9b3 --- /dev/null +++ b/language/python/extractor/src/model/statement.py @@ -0,0 +1,17 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Statement(Base): + __tablename__ = "statement" + + element_oid = Column(Integer, primary_key=True) + type = Column(Text, nullable=False) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/string_literal.py b/language/python/extractor/src/model/string_literal.py new file mode 100644 index 00000000..5bcec4b8 --- /dev/null +++ b/language/python/extractor/src/model/string_literal.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class StringLiteral(Base): + __tablename__ = "string_literal" + + element_oid = Column(Integer, primary_key=True) + value = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/subscript_expression.py b/language/python/extractor/src/model/subscript_expression.py new file mode 100644 index 00000000..a34902e9 --- /dev/null +++ b/language/python/extractor/src/model/subscript_expression.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class SubscriptExpression(Base): + __tablename__ = "subscript_expression" + + element_oid = Column(Integer, primary_key=True) + value_oid = Column(Integer, nullable=False) + slice_oid = Column(Integer, nullable=False) + ctx = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/token.py b/language/python/extractor/src/model/token.py new file mode 100644 index 00000000..351f601b --- /dev/null +++ b/language/python/extractor/src/model/token.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Token(Base): + __tablename__ = "token" + + element_oid = Column(Integer, primary_key=True) + value = Column(Text, nullable=False) + location_oid = Column(Integer) + parent_oid = Column(Integer) diff --git a/language/python/extractor/src/model/try_statement.py b/language/python/extractor/src/model/try_statement.py new file mode 100644 index 00000000..fc9aa858 --- /dev/null +++ b/language/python/extractor/src/model/try_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class TryStatement(Base): + __tablename__ = "try_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/tuple_expression.py b/language/python/extractor/src/model/tuple_expression.py new file mode 100644 index 00000000..878302ff --- /dev/null +++ b/language/python/extractor/src/model/tuple_expression.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class TupleExpression(Base): + __tablename__ = "tuple_expression" + + element_oid = Column(Integer, primary_key=True) + elt_size = Column(Integer, nullable=False) + ctx = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/type_ignore.py b/language/python/extractor/src/model/type_ignore.py new file mode 100644 index 00000000..cb01aa14 --- /dev/null +++ b/language/python/extractor/src/model/type_ignore.py @@ -0,0 +1,16 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class TypeIgnore(Base): + __tablename__ = "type_ignore" + + element_oid = Column(Integer, primary_key=True) + value = Column(Text, nullable=False) + location_oid = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) + tag = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/unary_expression.py b/language/python/extractor/src/model/unary_expression.py new file mode 100644 index 00000000..e30fc0c7 --- /dev/null +++ b/language/python/extractor/src/model/unary_expression.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class UnaryExpression(Base): + __tablename__ = "unary_expression" + + element_oid = Column(Integer, primary_key=True) + operand_oid = Column(Integer, nullable=False) + opcode = Column(Text, nullable=False) + is_postfix = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/unary_op.py b/language/python/extractor/src/model/unary_op.py new file mode 100644 index 00000000..26faf179 --- /dev/null +++ b/language/python/extractor/src/model/unary_op.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class UnaryOp(Base): + __tablename__ = "unary_op" + + element_oid = Column(Integer, primary_key=True) + type = Column(Text, nullable=False) + location_oid = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/unary_op_expression.py b/language/python/extractor/src/model/unary_op_expression.py new file mode 100644 index 00000000..6d1bbf8a --- /dev/null +++ b/language/python/extractor/src/model/unary_op_expression.py @@ -0,0 +1,14 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class UnaryOpExpression(Base): + __tablename__ = "unary_op_expression" + + element_oid = Column(Integer, primary_key=True) + op_code = Column(Text, nullable=False) + operand_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/variable.py b/language/python/extractor/src/model/variable.py new file mode 100644 index 00000000..96824483 --- /dev/null +++ b/language/python/extractor/src/model/variable.py @@ -0,0 +1,16 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class Variable(Base): + __tablename__ = "variable" + + element_oid = Column(Integer, primary_key=True) + parent_oid = Column(Integer, nullable=False) + location_oid = Column(Integer, nullable=False) + printable_text = Column(Text, nullable=False) + name = Column(Text, nullable=False) diff --git a/language/python/extractor/src/model/while_statement.py b/language/python/extractor/src/model/while_statement.py new file mode 100644 index 00000000..7425a30f --- /dev/null +++ b/language/python/extractor/src/model/while_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class WhileStatement(Base): + __tablename__ = "while_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/with_item.py b/language/python/extractor/src/model/with_item.py new file mode 100644 index 00000000..d24370ca --- /dev/null +++ b/language/python/extractor/src/model/with_item.py @@ -0,0 +1,15 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class WithItem(Base): + __tablename__ = "with_item" + + element_oid = Column(Integer, primary_key=True) + printable_text = Column(Text, nullable=False) + element_index = Column(Integer, nullable=False) + parent_oid = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/model/with_statement.py b/language/python/extractor/src/model/with_statement.py new file mode 100644 index 00000000..ea48f89b --- /dev/null +++ b/language/python/extractor/src/model/with_statement.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class WithStatement(Base): + __tablename__ = "with_statement" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/yield_expression.py b/language/python/extractor/src/model/yield_expression.py new file mode 100644 index 00000000..9d4268f9 --- /dev/null +++ b/language/python/extractor/src/model/yield_expression.py @@ -0,0 +1,12 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class YieldExpression(Base): + __tablename__ = "yield_expression" + + element_oid = Column(Integer, primary_key=True) diff --git a/language/python/extractor/src/model/yield_from_expression.py b/language/python/extractor/src/model/yield_from_expression.py new file mode 100644 index 00000000..2975f9d9 --- /dev/null +++ b/language/python/extractor/src/model/yield_from_expression.py @@ -0,0 +1,13 @@ +# coding: utf-8 +from sqlalchemy import Column, Integer +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() +metadata = Base.metadata + + +class YieldFromExpression(Base): + __tablename__ = "yield_from_expression" + + element_oid = Column(Integer, primary_key=True) + value = Column(Integer, nullable=False) diff --git a/language/python/extractor/src/resources/coref_python_src.sql b/language/python/extractor/src/resources/coref_python_src.sql new file mode 100644 index 00000000..2c4dfc23 --- /dev/null +++ b/language/python/extractor/src/resources/coref_python_src.sql @@ -0,0 +1,546 @@ +BEGIN TRANSACTION; +CREATE TABLE IF NOT EXISTS "metainfo" ( + "oid" INTEGER, + "kind" TEXT, + "value" TEXT, + "program_oid" INTEGER +); +CREATE TABLE IF NOT EXISTS "location" ( + "element_oid" INTEGER NOT NULL, + "file_oid" INTEGER NOT NULL, + "start_line_number" INTEGER NOT NULL, + "start_column_number" INTEGER NOT NULL, + "end_line_number" INTEGER NOT NULL, + "end_column_number" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "folder" ( + "element_oid" INTEGER NOT NULL, + "qualified_name" TEXT NOT NULL, + "name" TEXT NOT NULL, + "parent_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "augmented_assignment_statement" ( + "element_oid" INTEGER NOT NULL, + "op_code" TEXT NOT NULL, + "target_expr_oid" INTEGER NOT NULL, + "value_expr_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "await_expression" ( + "element_oid" INTEGER NOT NULL, + "expr_value_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "callable_binding" ( + "caller_oid" INTEGER NOT NULL, + "callee_oid" INTEGER NOT NULL, + PRIMARY KEY("caller_oid") +); +CREATE TABLE IF NOT EXISTS "cmpop" ( + "element_oid" INTEGER NOT NULL, + "value" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "comment" ( + "element_oid" INTEGER NOT NULL, + "text" text NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "container_parent" ( + "child_oid" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + PRIMARY KEY("child_oid") +); +CREATE TABLE IF NOT EXISTS "yield_from_expression" ( + "element_oid" INTEGER NOT NULL, + "value" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "variable" ( + "element_oid" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + "name" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "unary_op" ( + "element_oid" INTEGER NOT NULL, + "type" TEXT NOT NULL, + "location_oid" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "continue_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "file_md5_sum" ( + "file_oid" INTEGER NOT NULL, + "value" TEXT NOT NULL, + PRIMARY KEY("file_oid") +); +CREATE TABLE IF NOT EXISTS "file_sha256_sum" ( + "file_oid" INTEGER NOT NULL, + "value" TEXT NOT NULL, + PRIMARY KEY("file_oid") +); +CREATE TABLE IF NOT EXISTS "global_statement" ( + "element_oid" INTEGER NOT NULL, + "names" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "mod" ( + "element_oid" INTEGER NOT NULL, + "type" TEXT NOT NULL, + "location_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "named_expression" ( + "element_oid" INTEGER NOT NULL, + "target_oid" INTEGER NOT NULL, + "value_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "non_local_statement" ( + "element_oid" INTEGER NOT NULL, + "names" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "number_of_lines" ( + "element_oid" INTEGER NOT NULL, + "number_of_total_lines" INTEGER, + "number_of_valid_lines" INTEGER, + "number_of_comment_lines" INTEGER, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "operator" ( + "element_oid" INTEGER NOT NULL, + "location_oid" INTEGER, + "parent_oid" INTEGER, + "printable_text" TEXT, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "parent" ( + "parent_oid" INTEGER NOT NULL, + "parent_type" TEXT NOT NULL, + PRIMARY KEY("parent_oid") +); +CREATE TABLE IF NOT EXISTS "pass_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "program" ( + "program_oid" INTEGER NOT NULL, + "absolute_prefix_path" TEXT NOT NULL, + PRIMARY KEY("program_oid") +); +CREATE TABLE IF NOT EXISTS "reference_relation" ( + "reference_element_oid" INTEGER NOT NULL, + "definition_element_oid" INTEGER NOT NULL, + PRIMARY KEY("reference_element_oid") +); +CREATE TABLE IF NOT EXISTS "token" ( + "element_oid" INTEGER NOT NULL, + "value" TEXT NOT NULL, + "location_oid" INTEGER, + "parent_oid" INTEGER, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "docstring_comment" ( + "element_oid" INTEGER NOT NULL, + "text" TEXT NOT NULL, + "documented_element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "arguments" ( + "element_oid" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "expr_context" ( + "element_oid" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "with_item" ( + "element_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "except_handler" ( + "element_oid" INTEGER NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "alias" ( + "element_oid" INTEGER NOT NULL, + "name" TEXT NOT NULL, + "asname" TEXT NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "arg" ( + "element_oid" INTEGER NOT NULL, + "annotation" INTEGER NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "slice" ( + "element_oid" INTEGER NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + "has_step" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "match_case" ( + "element_oid" INTEGER NOT NULL, + "pattern_oid" INTEGER NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + "is_default" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "element" ( + "oid" INTEGER NOT NULL, + "value" TEXT NOT NULL, + "type" TEXT NOT NULL, + "parent_oid" INTEGER NOT NULL, + PRIMARY KEY("oid") +); +CREATE TABLE IF NOT EXISTS "statement" ( + "element_oid" INTEGER NOT NULL, + "type" TEXT NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "return_statement" ( + "element_oid" INTEGER NOT NULL, + "is_return_empty" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "while_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "try_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "match_statement" ( + "element_oid" INTEGER NOT NULL, + "subject_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "import_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "import_from_statement" ( + "element_oid" INTEGER NOT NULL, + "module" text NOT NULL, + "level" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "if_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "function_def_statement" ( + "element_oid" INTEGER NOT NULL, + "name" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "for_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "class_def_statement" ( + "element_oid" INTEGER NOT NULL, + "name" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "break_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "expression" ( + "element_oid" INTEGER NOT NULL, + "type" TEXT NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "name_expression" ( + "element_oid" INTEGER NOT NULL, + "ctx_type" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "bin_op_expression" ( + "element_oid" INTEGER NOT NULL, + "left_expr_oid" INTEGER NOT NULL, + "opcode" INTEGER NOT NULL, + "right_expr_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "call_expression" ( + "element_oid" INTEGER NOT NULL, + "expr_func_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "constant" ( + "element_oid" INTEGER NOT NULL, + "value" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "if_expression" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "attribute_expression" ( + "element_oid" INTEGER NOT NULL, + "value_oid" INTEGER NOT NULL, + "ctx_type" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "expression_statement" ( + "element_oid" INTEGER NOT NULL, + "value_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "formatted_value_expression" ( + "element_oid" INTEGER NOT NULL, + "value_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "compare_expression" ( + "element_oid" INTEGER NOT NULL, + "left_expr_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "subscript_expression" ( + "element_oid" INTEGER NOT NULL, + "value_oid" INTEGER NOT NULL, + "slice_oid" INTEGER NOT NULL, + "ctx" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "dict_expression" ( + "element_oid" INTEGER NOT NULL, + "size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "comprehension" ( + "element_oid" INTEGER NOT NULL, + "target_expr_oid" INTEGER NOT NULL, + "iter_expr_oid" INTEGER NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "dict_comp_expression" ( + "element_oid" INTEGER NOT NULL, + "comprehension_size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "generator_expression" ( + "element_oid" INTEGER NOT NULL, + "elt_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "joined_str_expression" ( + "element_oid" INTEGER NOT NULL, + "size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "lambda_expression" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "list_expression" ( + "element_oid" INTEGER NOT NULL, + "elt_size" INTEGER NOT NULL, + "ctx" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "list_comp_expression" ( + "element_oid" INTEGER NOT NULL, + "elt_oid" INTEGER NOT NULL, + "generator_size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "set_expression" ( + "element_oid" INTEGER NOT NULL, + "elt_size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "set_comp_expression" ( + "element_oid" INTEGER NOT NULL, + "elt_oid" INTEGER NOT NULL, + "generator_size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "starred_expression" ( + "element_oid" INTEGER NOT NULL, + "ctx" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "tuple_expression" ( + "element_oid" INTEGER NOT NULL, + "elt_size" INTEGER NOT NULL, + "ctx" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "unary_op_expression" ( + "element_oid" INTEGER NOT NULL, + "op_code" TEXT NOT NULL, + "operand_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "assignment_statement" ( + "element_oid" INTEGER NOT NULL, + "value_oid" INTEGER NOT NULL, + "targets_size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "assert_statement" ( + "element_oid" INTEGER NOT NULL, + "assert_condition_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "with_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "delete_statement" ( + "element_oid" INTEGER NOT NULL, + "targets_size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "raise_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "async_function_def_statement" ( + "element_oid" INTEGER NOT NULL, + "name" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "async_with_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "async_for_statement" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "annotation_assignment_statement" ( + "element_oid" INTEGER NOT NULL, + "annotation_oid" INTEGER NOT NULL, + "target_oid" INTEGER NOT NULL, + "is_simple" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "yield_expression" ( + "element_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "file" ( + "element_oid" INTEGER NOT NULL, + "relative_path" TEXT NOT NULL, + "extension" TEXT NOT NULL, + "name" TEXT NOT NULL, + "number_of_lines_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "decorated_relation" ( + "decorator_oid" INTEGER NOT NULL, + "decorated_element_oid" INTEGER NOT NULL, + PRIMARY KEY("decorator_oid") +); +CREATE TABLE IF NOT EXISTS "decorator" ( + "element_oid" INTEGER NOT NULL, + "type" TEXT NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "class_hierarchy" ( + "base_oid" INTEGER NOT NULL, + "class_oid" INTEGER NOT NULL, + PRIMARY KEY("base_oid") +); +CREATE TABLE IF NOT EXISTS "module" ( + "element_oid" INTEGER NOT NULL, + "name" TEXT NOT NULL, + "file_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "scope_enclosing_expression" ( + "expression_oid" INTEGER NOT NULL, + "scope_oid" INTEGER NOT NULL, + PRIMARY KEY("expression_oid") +); +CREATE TABLE IF NOT EXISTS "scope_enclosing_statement" ( + "statement_oid" INTEGER NOT NULL, + "scope_oid" INTEGER NOT NULL, + PRIMARY KEY("statement_oid") +); +CREATE TABLE IF NOT EXISTS "keyword" ( + "element_oid" INTEGER NOT NULL, + "arg_value" TEXT NOT NULL, + "value_oid" INTEGER NOT NULL, + "element_index" INTEGER NOT NULL, + "parent_oid" INTEGER NOT NULL, + "location_oid" INTEGER NOT NULL, + "printable_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "boolean_op_expression" ( + "element_oid" INTEGER NOT NULL, + "type" TEXT NOT NULL, + "size" INTEGER NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "parse_error_file" ( + "element_oid" INTEGER NOT NULL, + "relative_path" TEXT NOT NULL, + "error_message" TEXT NOT NULL, + "error_text" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +CREATE TABLE IF NOT EXISTS "modified_2to3_file" ( + "element_oid" INTEGER NOT NULL, + "relative_path" TEXT NOT NULL, + PRIMARY KEY("element_oid") +); +COMMIT; diff --git a/language/python/lib/Alias.gdl b/language/python/lib/Alias.gdl new file mode 100644 index 00000000..f94aa2ab --- /dev/null +++ b/language/python/lib/Alias.gdl @@ -0,0 +1,56 @@ +/** + * @brief An alias. + */ +schema Alias extends AliasDO { + +} +impl Alias { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Alias { + for (tmp in AliasDO(db)) { + yield Alias { + element_oid : tmp.element_oid, + name : tmp.name, + asname : tmp.asname, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getLocationOid()) { + return loc + } + } + } +} diff --git a/language/python/lib/Argument.gdl b/language/python/lib/Argument.gdl new file mode 100644 index 00000000..7c8f5143 --- /dev/null +++ b/language/python/lib/Argument.gdl @@ -0,0 +1,131 @@ +/** + * @brief A single argument in a list. + */ +schema Arg extends ArgDO { + +} +impl Arg { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Arg { + for (tmp in ArgDO(db)) { + yield Arg { + element_oid : tmp.element_oid, + annotation : tmp.annotation, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the annotation element of the element, if any. + * @return Expression + */ + pub fn getAnnotation(self) -> Expression { + for (c in Expression(__all_data__)) { + if (c.element_oid = self.getAnnotationOid()) { + return c + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getLocationOid()) { + return loc + } + } + } +} +/** + * @brief The arguments for a function. + */ +schema Arguments extends ArgumentsDO { + +} +impl Arguments { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Arguments { + for (tmp in ArgumentsDO(db)) { + yield Arguments { + element_oid : tmp.element_oid, + parent_oid : tmp.parent_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element's parent since this type has no location info. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getParentOid()) { + return loc + } + } + } + /** + * @brief gets the arg in the arguments by index, if any. + * @return Arg + */ + pub fn getArgByIndex(self, i : int) -> Arg { + for (a in Arg(__all_data__)) { + if (self.key_eq(a.getParent())) { + if (i = a.getElementIndex()) { + return a + } + } + } + } +} diff --git a/language/python/lib/Class.gdl b/language/python/lib/Class.gdl new file mode 100644 index 00000000..92f5d517 --- /dev/null +++ b/language/python/lib/Class.gdl @@ -0,0 +1,255 @@ +/** + * @brief A python class, which is a class def statement. + */ +schema Class extends ClassDefStatement { + +} +impl Class { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Class { + for (tmp in ClassDefStatement(db)) { + yield Class { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the qualified name of the class. + * @return string + */ + pub fn getQualifiedName(self) -> string { + for (s in Scope(__all_data__)) { + if (s = self.getEnclosingScope()) { + let (postfix = self.getName()) { + for (m in Module(__all_data__)) { + if (m.key_eq(s)) { + let (name = postfix) { + return name + } + } + } + for (c in Class(__all_data__)) { + if (c.key_eq(s)) { + let (suffix = c.getQualifiedName()) { + let (name = suffix + "." + postfix) { + return name + } + } + } + } + for (c in Function(__all_data__)) { + if (c.key_eq(s)) { + let (suffix = c.getQualifiedName()) { + let (name = suffix + "." + postfix) { + return name + } + } + } + } + } + } + } + } + /** + * @brief gets the function defined in the class, if any. + * @return Function + */ + pub fn getAFunction(self) -> *Function { + for (f in Function(__all_data__)) { + if (self.key_eq(f.getParent())) { + yield f + } + } + } + /** + * @brief gets the init function for the class, if any. + * @return Function + */ + pub fn getInitFunction(self) -> InitFunction { + for (f in InitFunction(__all_data__)) { + for (auto_tmp1 in self.getAFunction()) { + if (f.key_eq(auto_tmp1)) { + return f + } + } + } + } + /** + * @brief gets the decorator of the class, if any. + * @return Decorator + */ + pub fn getDecorator(self) -> *Decorator { + for (d in Decorator(__all_data__)) { + if (self.key_eq(d.getDecoratedElement())) { + yield d + } + } + } + /** + * @brief gets the base expression of the class, if any. + * @return Expression + */ + pub fn getBase(self) -> *Expression { + for (r in ClassHierarchy(__all_data__)) { + if (self = r.getClass()) { + yield r.getBasedClass() + } + } + } + /** + * @brief gets the base name of the class, if any. + * @return string + */ + pub fn getBaseName(self) -> *string { + for (e in self.getBase()) { + yield e.getPrintableText() + } + } + /** + * @brief gets the inherited class of the class, if any. + * @return Class + */ + pub fn getInheritedClass(self) -> Class { + for (a in Class(__all_data__)) { + for (auto_tmp1 in self.getBaseName()) { + if (getInternalInheritance(self, auto_tmp1, a)) { + return a + } + } + } + } + /** + * @brief gets an ancestor inherited class of the class, if any. + * @return Class + */ + pub fn getAnAncestorInheritedClass(self) -> *Class { + let (s = self.getInheritedClass()) { + yield s + } + for (auto_tmp1 in self.getAnAncestorInheritedClass()) { + yield auto_tmp1.getInheritedClass() + } + } +} +/** + * @brief ClassHierarchy relation. + */ +schema ClassHierarchy extends ClassHierarchyDO { + +} +impl ClassHierarchy { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ClassHierarchy { + for (tmp in ClassHierarchyDO(db)) { + yield ClassHierarchy { + base_oid : tmp.base_oid, + class_oid : tmp.class_oid + } + } + } + /** + * @brief gets the based class in the inherited relation. + * @return Expression + */ + pub fn getBasedClass(self) -> Expression { + for (e in Expression(__all_data__)) { + if (self.key_eq(e)) { + return e + } + } + } + /** + * @brief gets the class in the inherited relation. + * @return Class + */ + pub fn getClass(self) -> Class { + for (c in Class(__all_data__)) { + if (c.element_oid = self.getClassOid()) { + return c + } + } + } +} +pub fn getInheritanceFromImport(cc : Class, n : string, a : Class) -> bool { + for (c in Alias(__all_data__), + i in ImportFromStatement(__all_data__), + o in Module(__all_data__)) { + if (cc.getEnclosingScope() = i.getEnclosingScope()) { + for (auto_tmp1 in cc.getBase()) { + if (n = auto_tmp1.getPrintableText()) { + if (i.key_eq(c.getParent())) { + if (c.getName() = n) { + if (n = a.getName()) { + if (o.key_eq(a.getEnclosingScope())) { + let (m = i.getModuleName()) { + let (l = o.getName()) { + if (m.contains(l)) { + let (j = o.getParent().getRelativePath()) { + let (k = ".*" + m + ".py") { + if (j.matches(k)) { + return true + } + } + } + } + } + } + } + } + } + if (c.getAsname() = n) { + if (n = a.getName()) { + if (o.key_eq(a.getEnclosingScope())) { + let (m = i.getModuleName()) { + let (l = o.getName()) { + if (m.contains(l)) { + let (j = o.getParent().getRelativePath()) { + let (k = ".*" + m + ".py") { + if (j.matches(k)) { + return true + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} +pub fn getInheritanceInTheSameModule(c : Class, n : string, a : Class) -> bool { + if (a.getName() = n) { + for (auto_tmp1 in c.getBase()) { + if (n = auto_tmp1.getPrintableText()) { + if (c.getEnclosingScope() = a.getEnclosingScope()) { + return true + } + for (auto_tmp2 in c.getAnAncestor()) { + if (a.key_eq(auto_tmp2)) { + return true + } + } + } + } + } +} +pub fn getInternalInheritance(c : Class, n : string, a : Class) -> bool { + if (getInheritanceFromImport(c, n, a)) { + return true + } + if (getInheritanceInTheSameModule(c, n, a)) { + return true + } +} diff --git a/language/python/lib/Comprehension.gdl b/language/python/lib/Comprehension.gdl new file mode 100644 index 00000000..db68de46 --- /dev/null +++ b/language/python/lib/Comprehension.gdl @@ -0,0 +1,55 @@ +/** + * @brief One for clause in a comprehension. + */ +schema Comprehension extends ComprehensionDO { + +} +impl Comprehension { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Comprehension { + for (tmp in ComprehensionDO(db)) { + yield Comprehension { + element_oid : tmp.element_oid, + target_expr_oid : tmp.target_expr_oid, + iter_expr_oid : tmp.iter_expr_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element's parent since this type has no location info. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getParentOid()) { + return loc + } + } + } +} diff --git a/language/python/lib/Container.gdl b/language/python/lib/Container.gdl new file mode 100644 index 00000000..026e7f73 --- /dev/null +++ b/language/python/lib/Container.gdl @@ -0,0 +1,229 @@ +/** + * @brief The root of the extracted project. + */ +schema Program extends ProgramDO { + +} +impl Program { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Program { + for (tmp in ProgramDO(db)) { + yield Program { + program_oid : tmp.program_oid, + absolute_prefix_path : tmp.absolute_prefix_path + } + } + } +} +/** + * @brief A python file. + */ +schema File extends FileDO { + +} +impl File { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *File { + for (tmp in FileDO(db)) { + yield File { + element_oid : tmp.element_oid, + relative_path : tmp.relative_path, + extension : tmp.extension, + name : tmp.name, + number_of_lines_oid : tmp.number_of_lines_oid + } + } + } + /** + * @brief gets the folder which contains the file, if any. + * @return Folder + */ + pub fn getBelongedFolder(self) -> Folder { + for (f in Folder(__all_data__), + container in ContainerParent(__all_data__)) { + if (self.key_eq(container)) { + if (f.element_oid = container.getParentOid()) { + return f + } + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_oid = self.getNumberOfLinesOid()) { + return n + } + } + } +} +/** + * @brief A folder. + */ +schema Folder extends FolderDO { + +} +impl Folder { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Folder { + for (tmp in FolderDO(db)) { + yield Folder { + element_oid : tmp.element_oid, + qualified_name : tmp.qualified_name, + name : tmp.name, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets all files in the folder. + * @return File + */ + pub fn getAllContainingFiles(self) -> *File { + for (f in File(__all_data__), + container in ContainerParent(__all_data__)) { + if (f.key_eq(container)) { + if (self.element_oid = container.getParentOid()) { + yield f + } + } + } + } + /** + * @brief gets the folder which contains the folder, if any. + * @return Folder + */ + pub fn getParent(self) -> Folder { + for (f in Folder(__all_data__)) { + if (f.element_oid = self.getParentOid()) { + return f + } + } + } +} +/** + * @brief Describe a file belonged to a certain folder. + */ +schema ContainerParent extends ContainerParentDO { + +} +impl ContainerParent { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ContainerParent { + for (tmp in ContainerParentDO(db)) { + yield ContainerParent { + child_oid : tmp.child_oid, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the folder which contains the file, if any. + * @return Folder + */ + pub fn getBelongedFolder(self) -> Folder { + for (f in Folder(__all_data__)) { + if (f.element_oid = self.getParentOid()) { + return f + } + } + } +} +/** + * @brief A Module refer to a file containing Python statements and definitions. + */ +schema Module extends ModuleDO { + +} +impl Module { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Module { + for (tmp in ModuleDO(db)) { + yield Module { + element_oid : tmp.element_oid, + name : tmp.name, + file_oid : tmp.file_oid, + location_oid : tmp.location_oid + } + } + } + /** + * @brief gets the file which contains the module. + * @return File + */ + pub fn getParent(self) -> File { + for (f in File(__all_data__)) { + if (f.element_oid = self.getFileOid()) { + return f + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getNumberOfLines(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.key_eq(self.getParent())) { + return n + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getLocationOid()) { + return loc + } + } + } +} +/** + * @brief A modified python file. + */ +schema Modified2To3File extends Modified2To3FileDO { + +} +impl Modified2To3File { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Modified2To3File { + for (tmp in Modified2To3FileDO(db)) { + yield Modified2To3File { + element_oid : tmp.element_oid, + relative_path : tmp.relative_path + } + } + } +} +/** + * @brief A parsed error file. + */ +schema ParseErrorFile extends ParseErrorFileDO { + +} +impl ParseErrorFile { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ParseErrorFile { + for (tmp in ParseErrorFileDO(db)) { + yield ParseErrorFile { + element_oid : tmp.element_oid, + relative_path : tmp.relative_path, + error_message : tmp.error_message, + error_text : tmp.error_text + } + } + } +} diff --git a/language/python/lib/DOClass.gdl b/language/python/lib/DOClass.gdl new file mode 100644 index 00000000..58837532 --- /dev/null +++ b/language/python/lib/DOClass.gdl @@ -0,0 +1,3234 @@ +/** + * @brief DO class: An alias. + */ +schema AliasDO { + @primary element_oid: int, + name: string, + asname: string, + element_index: int, + parent_oid: int, + location_oid: int, + printable_text: string +} +impl AliasDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AliasDO { + for (tmp in db.alias) { + yield AliasDO { + element_oid : tmp.element_oid, + name : tmp.name, + asname : tmp.asname, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the asname of this element. + * @return string + */ + pub fn getAsname(self) -> string { + return self.asname + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An annotation assignment statement. + */ +schema AnnotationAssignmentStatementDO { + @primary element_oid: int, + annotation_oid: int, + target_oid: int, + is_simple: int +} +impl AnnotationAssignmentStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AnnotationAssignmentStatementDO { + for (tmp in db.annotation_assignment_statement) { + yield AnnotationAssignmentStatementDO { + element_oid : tmp.element_oid, + annotation_oid : tmp.annotation_oid, + target_oid : tmp.target_oid, + is_simple : tmp.is_simple + } + } + } + /** + * @brief gets the annotation oid of this element. + * @return int + */ + pub fn getAnnotationOid(self) -> int { + return self.annotation_oid + } + /** + * @brief gets the target oid of this element. + * @return int + */ + pub fn getTargetOid(self) -> int { + return self.target_oid + } + /** + * @brief gets the is simple of this element. + * @return int + */ + pub fn getIsSimple(self) -> int { + return self.is_simple + } +} +/** + * + * @brief DO class: An arg. + */ +schema ArgDO { + @primary element_oid: int, + annotation: int, + element_index: int, + parent_oid: int, + location_oid: int, + printable_text: string +} +impl ArgDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ArgDO { + for (tmp in db.arg) { + yield ArgDO { + element_oid : tmp.element_oid, + annotation : tmp.annotation, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the annotation of this element. + * @return int + */ + pub fn getAnnotationOid(self) -> int { + return self.annotation + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An arguments. + */ +schema ArgumentsDO { + @primary element_oid: int, + parent_oid: int, + printable_text: string +} +impl ArgumentsDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ArgumentsDO { + for (tmp in db.arguments) { + yield ArgumentsDO { + element_oid : tmp.element_oid, + parent_oid : tmp.parent_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An assert statement. + */ +schema AssertStatementDO { + @primary element_oid: int, + assert_condition_oid: int +} +impl AssertStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AssertStatementDO { + for (tmp in db.assert_statement) { + yield AssertStatementDO { + element_oid : tmp.element_oid, + assert_condition_oid : tmp.assert_condition_oid + } + } + } + /** + * @brief gets the assert condition oid of this element. + * @return int + */ + pub fn getAssertConditionOid(self) -> int { + return self.assert_condition_oid + } +} +/** + * @brief DO class: An assignment statement. + */ +schema AssignmentStatementDO { + @primary element_oid: int, + value_oid: int, + targets_size: int +} +impl AssignmentStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AssignmentStatementDO { + for (tmp in db.assignment_statement) { + yield AssignmentStatementDO { + element_oid : tmp.element_oid, + value_oid : tmp.value_oid, + targets_size : tmp.targets_size + } + } + } + /** + * @brief gets the value oid of this element. + * @return int + */ + pub fn getValueOid(self) -> int { + return self.value_oid + } + /** + * @brief gets the targets size of this element. + * @return int + */ + pub fn getTargetsSize(self) -> int { + return self.targets_size + } +} +/** + * @brief DO class: An async for statement. + */ +schema AsyncForStatementDO { + @primary element_oid: int +} +impl AsyncForStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AsyncForStatementDO { + for (tmp in db.async_for_statement) { + yield AsyncForStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: An async function def statement. + */ +schema AsyncFunctionDefStatementDO { + @primary element_oid: int, + name: string +} +impl AsyncFunctionDefStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AsyncFunctionDefStatementDO { + for (tmp in db.async_function_def_statement) { + yield AsyncFunctionDefStatementDO { + element_oid : tmp.element_oid, + name : tmp.name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: An async with statement. + */ +schema AsyncWithStatementDO { + @primary element_oid: int +} +impl AsyncWithStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AsyncWithStatementDO { + for (tmp in db.async_with_statement) { + yield AsyncWithStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: An attribute expression. + */ +schema AttributeExpressionDO { + @primary element_oid: int, + value_oid: int, + ctx_type: string +} +impl AttributeExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AttributeExpressionDO { + for (tmp in db.attribute_expression) { + yield AttributeExpressionDO { + element_oid : tmp.element_oid, + value_oid : tmp.value_oid, + ctx_type : tmp.ctx_type + } + } + } + /** + * @brief gets the value oid of this element. + * @return int + */ + pub fn getValueOid(self) -> int { + return self.value_oid + } + /** + * @brief gets the ctx type of this element. + * @return string + */ + pub fn getCtxType(self) -> string { + return self.ctx_type + } +} +/** + * @brief DO class: An augmented assignment statement. + */ +schema AugmentedAssignmentStatementDO { + @primary element_oid: int, + op_code: string, + target_expr_oid: int, + value_expr_oid: int +} +impl AugmentedAssignmentStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AugmentedAssignmentStatementDO { + for (tmp in db.augmented_assignment_statement) { + yield AugmentedAssignmentStatementDO { + element_oid : tmp.element_oid, + op_code : tmp.op_code, + target_expr_oid : tmp.target_expr_oid, + value_expr_oid : tmp.value_expr_oid + } + } + } + /** + * @brief gets the op code of this element. + * @return string + */ + pub fn getOpCode(self) -> string { + return self.op_code + } + /** + * @brief gets the target expr oid of this element. + * @return int + */ + pub fn getTargetExprOid(self) -> int { + return self.target_expr_oid + } + /** + * @brief gets the value expr oid of this element. + * @return int + */ + pub fn getValueExprOid(self) -> int { + return self.value_expr_oid + } +} +/** + * @brief DO class: An await expression. + */ +schema AwaitExpressionDO { + @primary element_oid: int, + expr_value_oid: int +} +impl AwaitExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *AwaitExpressionDO { + for (tmp in db.await_expression) { + yield AwaitExpressionDO { + element_oid : tmp.element_oid, + expr_value_oid : tmp.expr_value_oid + } + } + } + /** + * @brief gets the expr value oid of this element. + * @return int + */ + pub fn getExprValueOid(self) -> int { + return self.expr_value_oid + } +} +/** + * @brief DO class: A bin op expression. + */ +schema BinOpExpressionDO { + @primary element_oid: int, + left_expr_oid: int, + opcode: int, + right_expr_oid: int +} +impl BinOpExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *BinOpExpressionDO { + for (tmp in db.bin_op_expression) { + yield BinOpExpressionDO { + element_oid : tmp.element_oid, + left_expr_oid : tmp.left_expr_oid, + opcode : tmp.opcode, + right_expr_oid : tmp.right_expr_oid + } + } + } + /** + * @brief gets the left expr oid of this element. + * @return int + */ + pub fn getLeftExprOid(self) -> int { + return self.left_expr_oid + } + /** + * @brief gets the opcode of this element. + * @return int + */ + pub fn getOpcode(self) -> int { + return self.opcode + } + /** + * @brief gets the right expr oid of this element. + * @return int + */ + pub fn getRightExprOid(self) -> int { + return self.right_expr_oid + } +} +/** + * @brief DO class: A boolean op expression. + */ +schema BooleanOpExpressionDO { + @primary element_oid: int, + type: string, + size: int +} +impl BooleanOpExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *BooleanOpExpressionDO { + for (tmp in db.boolean_op_expression) { + yield BooleanOpExpressionDO { + element_oid : tmp.element_oid, + type : tmp.type, + size : tmp.size + } + } + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } + /** + * @brief gets the size of this element. + * @return int + */ + pub fn getSize(self) -> int { + return self.size + } +} +/** + * @brief DO class: A break statement. + */ +schema BreakStatementDO { + @primary element_oid: int +} +impl BreakStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *BreakStatementDO { + for (tmp in db.break_statement) { + yield BreakStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A call expression. + */ +schema CallExpressionDO { + @primary element_oid: int, + expr_func_oid: int +} +impl CallExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *CallExpressionDO { + for (tmp in db.call_expression) { + yield CallExpressionDO { + element_oid : tmp.element_oid, + expr_func_oid : tmp.expr_func_oid + } + } + } + /** + * @brief gets the expr func oid of this element. + * @return int + */ + pub fn getExprFuncOid(self) -> int { + return self.expr_func_oid + } +} +/** + * @brief DO class: A callable binding. + */ +schema CallableBindingDO { + @primary caller_oid: int, + callee_oid: int +} +impl CallableBindingDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *CallableBindingDO { + for (tmp in db.callable_binding) { + yield CallableBindingDO { + caller_oid : tmp.caller_oid, + callee_oid : tmp.callee_oid + } + } + } + /** + * @brief gets the callee oid of this element. + * @return int + */ + pub fn getCalleeOid(self) -> int { + return self.callee_oid + } +} +/** + * @brief DO class: A class def statement. + */ +schema ClassDefStatementDO { + @primary element_oid: int, + name: string +} +impl ClassDefStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ClassDefStatementDO { + for (tmp in db.class_def_statement) { + yield ClassDefStatementDO { + element_oid : tmp.element_oid, + name : tmp.name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: A class hierarchy. + */ +schema ClassHierarchyDO { + @primary base_oid: int, + class_oid: int +} +impl ClassHierarchyDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ClassHierarchyDO { + for (tmp in db.class_hierarchy) { + yield ClassHierarchyDO { + base_oid : tmp.base_oid, + class_oid : tmp.class_oid + } + } + } + /** + * @brief gets the class oid of this element. + * @return int + */ + pub fn getClassOid(self) -> int { + return self.class_oid + } +} +/** + * @brief DO class: A cmpop. + */ +schema CmpopDO { + @primary element_oid: int, + value: int, + location_oid: int, + parent_oid: int +} +impl CmpopDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *CmpopDO { + for (tmp in db.cmpop) { + yield CmpopDO { + element_oid : tmp.element_oid, + value : tmp.value, + location_oid : tmp.location_oid, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the value of this element. + * @return int + */ + pub fn getValue(self) -> int { + return self.value + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } +} +/** + * @brief DO class: A comment. + */ +schema CommentDO { + @primary element_oid: int, + text: string, + parent_oid: int, + location_oid: int +} +impl CommentDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *CommentDO { + for (tmp in db.comment) { + yield CommentDO { + element_oid : tmp.element_oid, + text : tmp.text, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid + } + } + } + /** + * @brief gets the text of this element. + * @return string + */ + pub fn getText(self) -> string { + return self.text + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } +} +/** + * @brief DO class: A compare expression. + */ +schema CompareExpressionDO { + @primary element_oid: int, + left_expr_oid: int +} +impl CompareExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *CompareExpressionDO { + for (tmp in db.compare_expression) { + yield CompareExpressionDO { + element_oid : tmp.element_oid, + left_expr_oid : tmp.left_expr_oid + } + } + } + /** + * @brief gets the left expr oid of this element. + * @return int + */ + pub fn getLeftExprOid(self) -> int { + return self.left_expr_oid + } +} +/** + * @brief DO class: A comprehension. + */ +schema ComprehensionDO { + @primary element_oid: int, + target_expr_oid: int, + iter_expr_oid: int, + element_index: int, + parent_oid: int, + printable_text: string +} +impl ComprehensionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ComprehensionDO { + for (tmp in db.comprehension) { + yield ComprehensionDO { + element_oid : tmp.element_oid, + target_expr_oid : tmp.target_expr_oid, + iter_expr_oid : tmp.iter_expr_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the target expr oid of this element. + * @return int + */ + pub fn getTargetExprOid(self) -> int { + return self.target_expr_oid + } + /** + * @brief gets the iter expr oid of this element. + * @return int + */ + pub fn getIterExprOid(self) -> int { + return self.iter_expr_oid + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: A constant. + */ +schema ConstantDO { + @primary element_oid: int, + value: string +} +impl ConstantDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ConstantDO { + for (tmp in db.constant) { + yield ConstantDO { + element_oid : tmp.element_oid, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A container parent. + */ +schema ContainerParentDO { + @primary child_oid: int, + parent_oid: int +} +impl ContainerParentDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ContainerParentDO { + for (tmp in db.container_parent) { + yield ContainerParentDO { + child_oid : tmp.child_oid, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } +} +/** + * @brief DO class: A continue statement. + */ +schema ContinueStatementDO { + @primary element_oid: int +} +impl ContinueStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ContinueStatementDO { + for (tmp in db.continue_statement) { + yield ContinueStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A decorated relation. + */ +schema DecoratedRelationDO { + @primary decorator_oid: int, + decorated_element_oid: int +} +impl DecoratedRelationDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *DecoratedRelationDO { + for (tmp in db.decorated_relation) { + yield DecoratedRelationDO { + decorator_oid : tmp.decorator_oid, + decorated_element_oid : tmp.decorated_element_oid + } + } + } + /** + * @brief gets the decorated element oid of this element. + * @return int + */ + pub fn getDecoratedElementOid(self) -> int { + return self.decorated_element_oid + } +} +/** + * @brief DO class: A decorator. + */ +schema DecoratorDO { + @primary element_oid: int, + type: string, + printable_text: string +} +impl DecoratorDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *DecoratorDO { + for (tmp in db.decorator) { + yield DecoratorDO { + element_oid : tmp.element_oid, + type : tmp.type, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: A delete statement. + */ +schema DeleteStatementDO { + @primary element_oid: int, + targets_size: int +} +impl DeleteStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *DeleteStatementDO { + for (tmp in db.delete_statement) { + yield DeleteStatementDO { + element_oid : tmp.element_oid, + targets_size : tmp.targets_size + } + } + } + /** + * @brief gets the targets size of this element. + * @return int + */ + pub fn getTargetsSize(self) -> int { + return self.targets_size + } +} +/** + * @brief DO class: A dict comp expression. + */ +schema DictCompExpressionDO { + @primary element_oid: int, + comprehension_size: int +} +impl DictCompExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *DictCompExpressionDO { + for (tmp in db.dict_comp_expression) { + yield DictCompExpressionDO { + element_oid : tmp.element_oid, + comprehension_size : tmp.comprehension_size + } + } + } + /** + * @brief gets the comprehension size of this element. + * @return int + */ + pub fn getComprehensionSize(self) -> int { + return self.comprehension_size + } +} +/** + * @brief DO class: A dict expression. + */ +schema DictExpressionDO { + @primary element_oid: int, + size: int +} +impl DictExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *DictExpressionDO { + for (tmp in db.dict_expression) { + yield DictExpressionDO { + element_oid : tmp.element_oid, + size : tmp.size + } + } + } + /** + * @brief gets the size of this element. + * @return int + */ + pub fn getSize(self) -> int { + return self.size + } +} +/** + * @brief DO class: A docstring comment. + */ +schema DocstringCommentDO { + @primary element_oid: int, + text: string, + documented_element_oid: int +} +impl DocstringCommentDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *DocstringCommentDO { + for (tmp in db.docstring_comment) { + yield DocstringCommentDO { + element_oid : tmp.element_oid, + text : tmp.text, + documented_element_oid : tmp.documented_element_oid + } + } + } + /** + * @brief gets the text of this element. + * @return string + */ + pub fn getText(self) -> string { + return self.text + } + /** + * @brief gets the documented element oid of this element. + * @return int + */ + pub fn getDocumentedElementOid(self) -> int { + return self.documented_element_oid + } +} +/** + * @brief DO class: An element. + */ +schema ElementDO { + @primary oid: int, + value: string, + type: string, + parent_oid: int +} +impl ElementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ElementDO { + for (tmp in db.element) { + yield ElementDO { + oid : tmp.oid, + value : tmp.value, + type : tmp.type, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } +} +/** + * @brief DO class: An except handler. + */ +schema ExceptHandlerDO { + @primary element_oid: int, + element_index: int, + parent_oid: int, + location_oid: int, + printable_text: string +} +impl ExceptHandlerDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ExceptHandlerDO { + for (tmp in db.except_handler) { + yield ExceptHandlerDO { + element_oid : tmp.element_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An expr context. + */ +schema ExprContextDO { + @primary element_oid: int, + parent_oid: int, + printable_text: string +} +impl ExprContextDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ExprContextDO { + for (tmp in db.expr_context) { + yield ExprContextDO { + element_oid : tmp.element_oid, + parent_oid : tmp.parent_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An expression. + */ +schema ExpressionDO { + @primary element_oid: int, + type: string, + element_index: int, + parent_oid: int, + location_oid: int, + printable_text: string +} +impl ExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ExpressionDO { + for (tmp in db.expression) { + yield ExpressionDO { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: An expression statement. + */ +schema ExpressionStatementDO { + @primary element_oid: int, + value_oid: int +} +impl ExpressionStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ExpressionStatementDO { + for (tmp in db.expression_statement) { + yield ExpressionStatementDO { + element_oid : tmp.element_oid, + value_oid : tmp.value_oid + } + } + } + /** + * @brief gets the value oid of this element. + * @return int + */ + pub fn getValueOid(self) -> int { + return self.value_oid + } +} +/** + * @brief DO class: A file. + */ +schema FileDO { + @primary element_oid: int, + relative_path: string, + extension: string, + name: string, + number_of_lines_oid: int +} +impl FileDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *FileDO { + for (tmp in db.file) { + yield FileDO { + element_oid : tmp.element_oid, + relative_path : tmp.relative_path, + extension : tmp.extension, + name : tmp.name, + number_of_lines_oid : tmp.number_of_lines_oid + } + } + } + /** + * @brief gets the relative path of this element. + * @return string + */ + pub fn getRelativePath(self) -> string { + return self.relative_path + } + /** + * @brief gets the extension of this element. + * @return string + */ + pub fn getExtension(self) -> string { + return self.extension + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the number of lines oid of this element. + * @return int + */ + pub fn getNumberOfLinesOid(self) -> int { + return self.number_of_lines_oid + } +} +/** + * @brief DO class: A modified 2to3 file. + */ +schema Modified2To3FileDO { + @primary element_oid: int, + relative_path: string +} +impl Modified2To3FileDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *Modified2To3FileDO { + for (tmp in db.modified_2to3_file) { + yield Modified2To3FileDO { + element_oid : tmp.element_oid, + relative_path : tmp.relative_path + } + } + } + /** + * @brief gets the relative path of this element. + * @return string + */ + pub fn getRelativePath(self) -> string { + return self.relative_path + } +} +/** + * @brief DO class: A parsed error file. + */ +schema ParseErrorFileDO { + @primary element_oid: int, + relative_path: string, + error_message: string, + error_text: string +} +impl ParseErrorFileDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ParseErrorFileDO { + for (tmp in db.parse_error_file) { + yield ParseErrorFileDO { + element_oid : tmp.element_oid, + relative_path : tmp.relative_path, + error_message : tmp.error_message, + error_text : tmp.error_text + } + } + } + /** + * @brief gets the relative path of this element. + * @return string + */ + pub fn getRelativePath(self) -> string { + return self.relative_path + } + /** + * @brief gets the error message of this element. + * @return string + */ + pub fn getErrorMessage(self) -> string { + return self.error_message + } + /** + * @brief gets the error text of this element. + * @return string + */ + pub fn getErrorText(self) -> string { + return self.error_text + } +} +/** + * @brief DO class: A file md5 sum. + */ +schema FileMd5SumDO { + @primary file_oid: int, + value: string +} +impl FileMd5SumDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *FileMd5SumDO { + for (tmp in db.file_md5_sum) { + yield FileMd5SumDO { + file_oid : tmp.file_oid, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A file sha256 sum. + */ +schema FileSha256SumDO { + @primary file_oid: int, + value: string +} +impl FileSha256SumDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *FileSha256SumDO { + for (tmp in db.file_sha256_sum) { + yield FileSha256SumDO { + file_oid : tmp.file_oid, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } +} +/** + * @brief DO class: A folder. + */ +schema FolderDO { + @primary element_oid: int, + qualified_name: string, + name: string, + parent_oid: int +} +impl FolderDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *FolderDO { + for (tmp in db.folder) { + yield FolderDO { + element_oid : tmp.element_oid, + qualified_name : tmp.qualified_name, + name : tmp.name, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the qualified name of this element. + * @return string + */ + pub fn getQualifiedName(self) -> string { + return self.qualified_name + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } +} +/** + * @brief DO class: A for statement. + */ +schema ForStatementDO { + @primary element_oid: int +} +impl ForStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ForStatementDO { + for (tmp in db.for_statement) { + yield ForStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A formatted value expression. + */ +schema FormattedValueExpressionDO { + @primary element_oid: int, + value_oid: int +} +impl FormattedValueExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *FormattedValueExpressionDO { + for (tmp in db.formatted_value_expression) { + yield FormattedValueExpressionDO { + element_oid : tmp.element_oid, + value_oid : tmp.value_oid + } + } + } + /** + * @brief gets the value oid of this element. + * @return int + */ + pub fn getValueOid(self) -> int { + return self.value_oid + } +} +/** + * @brief DO class: A function def statement. + */ +schema FunctionDefStatementDO { + @primary element_oid: int, + name: string +} +impl FunctionDefStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *FunctionDefStatementDO { + for (tmp in db.function_def_statement) { + yield FunctionDefStatementDO { + element_oid : tmp.element_oid, + name : tmp.name + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: A generator expression. + */ +schema GeneratorExpressionDO { + @primary element_oid: int, + elt_oid: int +} +impl GeneratorExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *GeneratorExpressionDO { + for (tmp in db.generator_expression) { + yield GeneratorExpressionDO { + element_oid : tmp.element_oid, + elt_oid : tmp.elt_oid + } + } + } + /** + * @brief gets the elt oid of this element. + * @return int + */ + pub fn getEltOid(self) -> int { + return self.elt_oid + } +} +/** + * @brief DO class: A global statement. + */ +schema GlobalStatementDO { + @primary element_oid: int, + names: string +} +impl GlobalStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *GlobalStatementDO { + for (tmp in db.global_statement) { + yield GlobalStatementDO { + element_oid : tmp.element_oid, + names : tmp.names + } + } + } + /** + * @brief gets the names of this element. + * @return string + */ + pub fn getNames(self) -> string { + return self.names + } +} +/** + * @brief DO class: An if expression. + */ +schema IfExpressionDO { + @primary element_oid: int +} +impl IfExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *IfExpressionDO { + for (tmp in db.if_expression) { + yield IfExpressionDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: An if statement. + */ +schema IfStatementDO { + @primary element_oid: int +} +impl IfStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *IfStatementDO { + for (tmp in db.if_statement) { + yield IfStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: An import from statement. + */ +schema ImportFromStatementDO { + @primary element_oid: int, + module: string, + level: int +} +impl ImportFromStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ImportFromStatementDO { + for (tmp in db.import_from_statement) { + yield ImportFromStatementDO { + element_oid : tmp.element_oid, + module : tmp.module, + level : tmp.level + } + } + } + /** + * @brief gets the module of this element. + * @return string + */ + pub fn getModule(self) -> string { + return self.module + } + /** + * @brief gets the level of this element. + * @return int + */ + pub fn getLevel(self) -> int { + return self.level + } +} +/** + * @brief DO class: An import statement. + */ +schema ImportStatementDO { + @primary element_oid: int +} +impl ImportStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ImportStatementDO { + for (tmp in db.import_statement) { + yield ImportStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A joined str expression. + */ +schema JoinedStrExpressionDO { + @primary element_oid: int, + size: int +} +impl JoinedStrExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *JoinedStrExpressionDO { + for (tmp in db.joined_str_expression) { + yield JoinedStrExpressionDO { + element_oid : tmp.element_oid, + size : tmp.size + } + } + } + /** + * @brief gets the size of this element. + * @return int + */ + pub fn getSize(self) -> int { + return self.size + } +} +/** + * @brief DO class: A keyword. + */ +schema KeywordDO { + @primary element_oid: int, + arg_value: string, + value_oid: int, + element_index: int, + parent_oid: int, + location_oid: int, + printable_text: string +} +impl KeywordDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *KeywordDO { + for (tmp in db.keyword) { + yield KeywordDO { + element_oid : tmp.element_oid, + arg_value : tmp.arg_value, + value_oid : tmp.value_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the arg value of this element. + * @return string + */ + pub fn getArgValue(self) -> string { + return self.arg_value + } + /** + * @brief gets the value oid of this element. + * @return int + */ + pub fn getValueOid(self) -> int { + return self.value_oid + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: A lambda expression. + */ +schema LambdaExpressionDO { + @primary element_oid: int +} +impl LambdaExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *LambdaExpressionDO { + for (tmp in db.lambda_expression) { + yield LambdaExpressionDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A list comp expression. + */ +schema ListCompExpressionDO { + @primary element_oid: int, + elt_oid: int, + generator_size: int +} +impl ListCompExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ListCompExpressionDO { + for (tmp in db.list_comp_expression) { + yield ListCompExpressionDO { + element_oid : tmp.element_oid, + elt_oid : tmp.elt_oid, + generator_size : tmp.generator_size + } + } + } + /** + * @brief gets the elt oid of this element. + * @return int + */ + pub fn getEltOid(self) -> int { + return self.elt_oid + } + /** + * @brief gets the generator size of this element. + * @return int + */ + pub fn getGeneratorSize(self) -> int { + return self.generator_size + } +} +/** + * @brief DO class: A list expression. + */ +schema ListExpressionDO { + @primary element_oid: int, + elt_size: int, + ctx: string +} +impl ListExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ListExpressionDO { + for (tmp in db.list_expression) { + yield ListExpressionDO { + element_oid : tmp.element_oid, + elt_size : tmp.elt_size, + ctx : tmp.ctx + } + } + } + /** + * @brief gets the elt size of this element. + * @return int + */ + pub fn getEltSize(self) -> int { + return self.elt_size + } + /** + * @brief gets the ctx of this element. + * @return string + */ + pub fn getCtx(self) -> string { + return self.ctx + } +} +/** + * @brief DO class: A location. + */ +schema LocationDO { + @primary element_oid: int, + file_oid: int, + start_line_number: int, + start_column_number: int, + end_line_number: int, + end_column_number: int +} +impl LocationDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *LocationDO { + for (tmp in db.location) { + yield LocationDO { + element_oid : tmp.element_oid, + file_oid : tmp.file_oid, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number + } + } + } + /** + * @brief gets the file oid of this element. + * @return int + */ + pub fn getFileOid(self) -> int { + return self.file_oid + } + /** + * @brief gets the start line number of this element. + * @return int + */ + pub fn getStartLineNumber(self) -> int { + return self.start_line_number + } + /** + * @brief gets the start column number of this element. + * @return int + */ + pub fn getStartColumnNumber(self) -> int { + return self.start_column_number + } + /** + * @brief gets the end line number of this element. + * @return int + */ + pub fn getEndLineNumber(self) -> int { + return self.end_line_number + } + /** + * @brief gets the end column number of this element. + * @return int + */ + pub fn getEndColumnNumber(self) -> int { + return self.end_column_number + } +} +/** + * @brief DO class: A match case. + */ +schema MatchCaseDO { + @primary element_oid: int, + pattern_oid: int, + element_index: int, + parent_oid: int, + location_oid: int, + printable_text: string, + is_default: int +} +impl MatchCaseDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *MatchCaseDO { + for (tmp in db.match_case) { + yield MatchCaseDO { + element_oid : tmp.element_oid, + pattern_oid : tmp.pattern_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text, + is_default : tmp.is_default + } + } + } + /** + * @brief gets the pattern oid of this element. + * @return int + */ + pub fn getPatternOid(self) -> int { + return self.pattern_oid + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the is default of this element. + * @return int + */ + pub fn getIsDefault(self) -> int { + return self.is_default + } +} +/** + * @brief DO class: A match statement. + */ +schema MatchStatementDO { + @primary element_oid: int, + subject_oid: int +} +impl MatchStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *MatchStatementDO { + for (tmp in db.match_statement) { + yield MatchStatementDO { + element_oid : tmp.element_oid, + subject_oid : tmp.subject_oid + } + } + } + /** + * @brief gets the subject oid of this element. + * @return int + */ + pub fn getSubjectOid(self) -> int { + return self.subject_oid + } +} +/** + * @brief DO class: A metainfo. + */ +schema MetainfoDO { + @primary oid: int, + kind: string, + value: string, + program_oid: int +} +impl MetainfoDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *MetainfoDO { + for (tmp in db.metainfo) { + yield MetainfoDO { + oid : tmp.oid, + kind : tmp.kind, + value : tmp.value, + program_oid : tmp.program_oid + } + } + } + /** + * @brief gets the kind of this element. + * @return string + */ + pub fn getKind(self) -> string { + return self.kind + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the program oid of this element. + * @return int + */ + pub fn getProgramOid(self) -> int { + return self.program_oid + } +} +/** + * @brief DO class: A mod. + */ +schema ModDO { + @primary element_oid: int, + type: string, + location_oid: int +} +impl ModDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ModDO { + for (tmp in db.mod) { + yield ModDO { + element_oid : tmp.element_oid, + type : tmp.type, + location_oid : tmp.location_oid + } + } + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } +} +/** + * @brief DO class: A module. + */ +schema ModuleDO { + @primary element_oid: int, + name: string, + file_oid: int, + location_oid: int +} +impl ModuleDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ModuleDO { + for (tmp in db.module) { + yield ModuleDO { + element_oid : tmp.element_oid, + name : tmp.name, + file_oid : tmp.file_oid, + location_oid : tmp.location_oid + } + } + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the file oid of this element. + * @return int + */ + pub fn getFileOid(self) -> int { + return self.file_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } +} +/** + * @brief DO class: A scope enclosing expression. + */ +schema ScopeEnclosingExpressionDO { + @primary expression_oid: int, + scope_oid: int +} +impl ScopeEnclosingExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ScopeEnclosingExpressionDO { + for (tmp in db.scope_enclosing_expression) { + yield ScopeEnclosingExpressionDO { + expression_oid : tmp.expression_oid, + scope_oid : tmp.scope_oid + } + } + } + /** + * @brief gets the scope oid of this element. + * @return int + */ + pub fn getScopeOid(self) -> int { + return self.scope_oid + } +} +/** + * @brief DO class: A scope enclosing statement. + */ +schema ScopeEnclosingStatementDO { + @primary statement_oid: int, + scope_oid: int +} +impl ScopeEnclosingStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ScopeEnclosingStatementDO { + for (tmp in db.scope_enclosing_statement) { + yield ScopeEnclosingStatementDO { + statement_oid : tmp.statement_oid, + scope_oid : tmp.scope_oid + } + } + } + /** + * @brief gets the scope oid of this element. + * @return int + */ + pub fn getScopeOid(self) -> int { + return self.scope_oid + } +} +/** + * @brief DO class: A name expression. + */ +schema NameExpressionDO { + @primary element_oid: int, + ctx_type: string +} +impl NameExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *NameExpressionDO { + for (tmp in db.name_expression) { + yield NameExpressionDO { + element_oid : tmp.element_oid, + ctx_type : tmp.ctx_type + } + } + } + /** + * @brief gets the ctx type of this element. + * @return string + */ + pub fn getCtxType(self) -> string { + return self.ctx_type + } +} +/** + * @brief DO class: A named expression. + */ +schema NamedExpressionDO { + @primary element_oid: int, + target_oid: int, + value_oid: int +} +impl NamedExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *NamedExpressionDO { + for (tmp in db.named_expression) { + yield NamedExpressionDO { + element_oid : tmp.element_oid, + target_oid : tmp.target_oid, + value_oid : tmp.value_oid + } + } + } + /** + * @brief gets the target oid of this element. + * @return int + */ + pub fn getTargetOid(self) -> int { + return self.target_oid + } + /** + * @brief gets the value oid of this element. + * @return int + */ + pub fn getValueOid(self) -> int { + return self.value_oid + } +} +/** + * @brief DO class: A non local statement. + */ +schema NonLocalStatementDO { + @primary element_oid: int, + names: int +} +impl NonLocalStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *NonLocalStatementDO { + for (tmp in db.non_local_statement) { + yield NonLocalStatementDO { + element_oid : tmp.element_oid, + names : tmp.names + } + } + } + /** + * @brief gets the names of this element. + * @return int + */ + pub fn getNames(self) -> int { + return self.names + } +} +/** + * @brief DO class: A number of lines. + */ +schema NumberOfLinesDO { + @primary element_oid: int, + number_of_total_lines: int, + number_of_valid_lines: int, + number_of_comment_lines: int +} +impl NumberOfLinesDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *NumberOfLinesDO { + for (tmp in db.number_of_lines) { + yield NumberOfLinesDO { + element_oid : tmp.element_oid, + number_of_total_lines : tmp.number_of_total_lines, + number_of_valid_lines : tmp.number_of_valid_lines, + number_of_comment_lines : tmp.number_of_comment_lines + } + } + } + /** + * @brief gets the number of total lines of this element. + * @return int + */ + pub fn getNumberOfTotalLines(self) -> int { + return self.number_of_total_lines + } + /** + * @brief gets the number of valid lines of this element. + * @return int + */ + pub fn getNumberOfValidLines(self) -> int { + return self.number_of_valid_lines + } + /** + * @brief gets the number of comment lines of this element. + * @return int + */ + pub fn getNumberOfCommentLines(self) -> int { + return self.number_of_comment_lines + } +} +/** + * @brief DO class: An operator. + */ +schema OperatorDO { + @primary element_oid: int, + location_oid: int, + parent_oid: int, + printable_text: string +} +impl OperatorDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *OperatorDO { + for (tmp in db.operator) { + yield OperatorDO { + element_oid : tmp.element_oid, + location_oid : tmp.location_oid, + parent_oid : tmp.parent_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: A parent. + */ +schema ParentDO { + @primary parent_oid: int, + parent_type: string +} +impl ParentDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ParentDO { + for (tmp in db.parent) { + yield ParentDO { + parent_oid : tmp.parent_oid, + parent_type : tmp.parent_type + } + } + } + /** + * @brief gets the parent type of this element. + * @return string + */ + pub fn getParentType(self) -> string { + return self.parent_type + } +} +/** + * @brief DO class: A pass statement. + */ +schema PassStatementDO { + @primary element_oid: int +} +impl PassStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *PassStatementDO { + for (tmp in db.pass_statement) { + yield PassStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A program. + */ +schema ProgramDO { + @primary program_oid: int, + absolute_prefix_path: string +} +impl ProgramDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ProgramDO { + for (tmp in db.program) { + yield ProgramDO { + program_oid : tmp.program_oid, + absolute_prefix_path : tmp.absolute_prefix_path + } + } + } + /** + * @brief gets the absolute prefix path of this element. + * @return string + */ + pub fn getAbsolutePrefixPath(self) -> string { + return self.absolute_prefix_path + } +} +/** + * @brief DO class: A raise statement. + */ +schema RaiseStatementDO { + @primary element_oid: int +} +impl RaiseStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *RaiseStatementDO { + for (tmp in db.raise_statement) { + yield RaiseStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A reference relation. + */ +schema ReferenceRelationDO { + @primary reference_element_oid: int, + definition_element_oid: int +} +impl ReferenceRelationDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ReferenceRelationDO { + for (tmp in db.reference_relation) { + yield ReferenceRelationDO { + reference_element_oid : tmp.reference_element_oid, + definition_element_oid : tmp.definition_element_oid + } + } + } + /** + * @brief gets the definition element oid of this element. + * @return int + */ + pub fn getDefinitionElementOid(self) -> int { + return self.definition_element_oid + } +} +/** + * @brief DO class: A return statement. + */ +schema ReturnStatementDO { + @primary element_oid: int, + is_return_empty: int +} +impl ReturnStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *ReturnStatementDO { + for (tmp in db.return_statement) { + yield ReturnStatementDO { + element_oid : tmp.element_oid, + is_return_empty : tmp.is_return_empty + } + } + } + /** + * @brief gets the is return empty of this element. + * @return int + */ + pub fn getIsReturnEmpty(self) -> int { + return self.is_return_empty + } +} +/** + * @brief DO class: A set comp expression. + */ +schema SetCompExpressionDO { + @primary element_oid: int, + elt_oid: int, + generator_size: int +} +impl SetCompExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *SetCompExpressionDO { + for (tmp in db.set_comp_expression) { + yield SetCompExpressionDO { + element_oid : tmp.element_oid, + elt_oid : tmp.elt_oid, + generator_size : tmp.generator_size + } + } + } + /** + * @brief gets the elt oid of this element. + * @return int + */ + pub fn getEltOid(self) -> int { + return self.elt_oid + } + /** + * @brief gets the generator size of this element. + * @return int + */ + pub fn getGeneratorSize(self) -> int { + return self.generator_size + } +} +/** + * @brief DO class: A set expression. + */ +schema SetExpressionDO { + @primary element_oid: int, + elt_size: int +} +impl SetExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *SetExpressionDO { + for (tmp in db.set_expression) { + yield SetExpressionDO { + element_oid : tmp.element_oid, + elt_size : tmp.elt_size + } + } + } + /** + * @brief gets the elt size of this element. + * @return int + */ + pub fn getEltSize(self) -> int { + return self.elt_size + } +} +/** + * @brief DO class: A slice. + */ +schema SliceDO { + @primary element_oid: int, + element_index: int, + parent_oid: int, + location_oid: int, + printable_text: string, + has_step: int +} +impl SliceDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *SliceDO { + for (tmp in db.slice) { + yield SliceDO { + element_oid : tmp.element_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text, + has_step : tmp.has_step + } + } + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the has step of this element. + * @return int + */ + pub fn getHasStep(self) -> int { + return self.has_step + } +} +/** + * @brief DO class: A starred expression. + */ +schema StarredExpressionDO { + @primary element_oid: int, + ctx: string +} +impl StarredExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *StarredExpressionDO { + for (tmp in db.starred_expression) { + yield StarredExpressionDO { + element_oid : tmp.element_oid, + ctx : tmp.ctx + } + } + } + /** + * @brief gets the ctx of this element. + * @return string + */ + pub fn getCtx(self) -> string { + return self.ctx + } +} +/** + * @brief DO class: A statement. + */ +schema StatementDO { + @primary element_oid: int, + type: string, + element_index: int, + parent_oid: int, + location_oid: int, + printable_text: string +} +impl StatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *StatementDO { + for (tmp in db.statement) { + yield StatementDO { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } +} +/** + * @brief DO class: A subscript expression. + */ +schema SubscriptExpressionDO { + @primary element_oid: int, + value_oid: int, + slice_oid: int, + ctx: string +} +impl SubscriptExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *SubscriptExpressionDO { + for (tmp in db.subscript_expression) { + yield SubscriptExpressionDO { + element_oid : tmp.element_oid, + value_oid : tmp.value_oid, + slice_oid : tmp.slice_oid, + ctx : tmp.ctx + } + } + } + /** + * @brief gets the value oid of this element. + * @return int + */ + pub fn getValueOid(self) -> int { + return self.value_oid + } + /** + * @brief gets the slice oid of this element. + * @return int + */ + pub fn getSliceOid(self) -> int { + return self.slice_oid + } + /** + * @brief gets the ctx of this element. + * @return string + */ + pub fn getCtx(self) -> string { + return self.ctx + } +} +/** + * @brief DO class: A token. + */ +schema TokenDO { + @primary element_oid: int, + value: string, + location_oid: int, + parent_oid: int +} +impl TokenDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *TokenDO { + for (tmp in db.token) { + yield TokenDO { + element_oid : tmp.element_oid, + value : tmp.value, + location_oid : tmp.location_oid, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the value of this element. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } +} +/** + * @brief DO class: A try statement. + */ +schema TryStatementDO { + @primary element_oid: int +} +impl TryStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *TryStatementDO { + for (tmp in db.try_statement) { + yield TryStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A tuple expression. + */ +schema TupleExpressionDO { + @primary element_oid: int, + elt_size: int, + ctx: string +} +impl TupleExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *TupleExpressionDO { + for (tmp in db.tuple_expression) { + yield TupleExpressionDO { + element_oid : tmp.element_oid, + elt_size : tmp.elt_size, + ctx : tmp.ctx + } + } + } + /** + * @brief gets the elt size of this element. + * @return int + */ + pub fn getEltSize(self) -> int { + return self.elt_size + } + /** + * @brief gets the ctx of this element. + * @return string + */ + pub fn getCtx(self) -> string { + return self.ctx + } +} +/** + * @brief DO class: An unary op. + */ +schema UnaryOpDO { + @primary element_oid: int, + type: string, + location_oid: int, + parent_oid: int +} +impl UnaryOpDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *UnaryOpDO { + for (tmp in db.unary_op) { + yield UnaryOpDO { + element_oid : tmp.element_oid, + type : tmp.type, + location_oid : tmp.location_oid, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the type of this element. + * @return string + */ + pub fn getType(self) -> string { + return self.type + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } +} +/** + * @brief DO class: An unary op expression. + */ +schema UnaryOpExpressionDO { + @primary element_oid: int, + op_code: string, + operand_oid: int +} +impl UnaryOpExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *UnaryOpExpressionDO { + for (tmp in db.unary_op_expression) { + yield UnaryOpExpressionDO { + element_oid : tmp.element_oid, + op_code : tmp.op_code, + operand_oid : tmp.operand_oid + } + } + } + /** + * @brief gets the op code of this element. + * @return string + */ + pub fn getOpCode(self) -> string { + return self.op_code + } + /** + * @brief gets the operand oid of this element. + * @return int + */ + pub fn getOperandOid(self) -> int { + return self.operand_oid + } +} +/** + * @brief DO class: A variable. + */ +schema VariableDO { + @primary element_oid: int, + parent_oid: int, + location_oid: int, + printable_text: string, + name: string +} +impl VariableDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *VariableDO { + for (tmp in db.variable) { + yield VariableDO { + element_oid : tmp.element_oid, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text, + name : tmp.name + } + } + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } + /** + * @brief gets the location oid of this element. + * @return int + */ + pub fn getLocationOid(self) -> int { + return self.location_oid + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the name of this element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } +} +/** + * @brief DO class: A while statement. + */ +schema WhileStatementDO { + @primary element_oid: int +} +impl WhileStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *WhileStatementDO { + for (tmp in db.while_statement) { + yield WhileStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A with item. + */ +schema WithItemDO { + @primary element_oid: int, + printable_text: string, + element_index: int, + parent_oid: int +} +impl WithItemDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *WithItemDO { + for (tmp in db.with_item) { + yield WithItemDO { + element_oid : tmp.element_oid, + printable_text : tmp.printable_text, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the printable text of this element. + * @return string + */ + pub fn getPrintableText(self) -> string { + return self.printable_text + } + /** + * @brief gets the element index of this element. + * @return int + */ + pub fn getElementIndex(self) -> int { + return self.element_index + } + /** + * @brief gets the parent oid of this element. + * @return int + */ + pub fn getParentOid(self) -> int { + return self.parent_oid + } +} +/** + * @brief DO class: A with statement. + */ +schema WithStatementDO { + @primary element_oid: int +} +impl WithStatementDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *WithStatementDO { + for (tmp in db.with_statement) { + yield WithStatementDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A yield expression. + */ +schema YieldExpressionDO { + @primary element_oid: int +} +impl YieldExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *YieldExpressionDO { + for (tmp in db.yield_expression) { + yield YieldExpressionDO { + element_oid : tmp.element_oid + } + } + } +} +/** + * @brief DO class: A yield from expression. + */ +schema YieldFromExpressionDO { + @primary element_oid: int, + value: int +} +impl YieldFromExpressionDO { + @data_constraint + @inline + pub fn __all__(db: PythonDB) -> *YieldFromExpressionDO { + for (tmp in db.yield_from_expression) { + yield YieldFromExpressionDO { + element_oid : tmp.element_oid, + value : tmp.value + } + } + } + /** + * @brief gets the value of this element. + * @return int + */ + pub fn getValue(self) -> int { + return self.value + } +} +database PythonDB { + alias: *AliasDO, + annotation_assignment_statement: *AnnotationAssignmentStatementDO, + arg: *ArgDO, + arguments: *ArgumentsDO, + assert_statement: *AssertStatementDO, + assignment_statement: *AssignmentStatementDO, + async_for_statement: *AsyncForStatementDO, + async_function_def_statement: *AsyncFunctionDefStatementDO, + async_with_statement: *AsyncWithStatementDO, + attribute_expression: *AttributeExpressionDO, + augmented_assignment_statement: *AugmentedAssignmentStatementDO, + await_expression: *AwaitExpressionDO, + bin_op_expression: *BinOpExpressionDO, + boolean_op_expression: *BooleanOpExpressionDO, + break_statement: *BreakStatementDO, + call_expression: *CallExpressionDO, + callable_binding: *CallableBindingDO, + class_def_statement: *ClassDefStatementDO, + class_hierarchy: *ClassHierarchyDO, + cmpop: *CmpopDO, + comment: *CommentDO, + compare_expression: *CompareExpressionDO, + comprehension: *ComprehensionDO, + constant: *ConstantDO, + container_parent: *ContainerParentDO, + continue_statement: *ContinueStatementDO, + decorated_relation: *DecoratedRelationDO, + decorator: *DecoratorDO, + delete_statement: *DeleteStatementDO, + dict_comp_expression: *DictCompExpressionDO, + dict_expression: *DictExpressionDO, + docstring_comment: *DocstringCommentDO, + element: *ElementDO, + except_handler: *ExceptHandlerDO, + expr_context: *ExprContextDO, + expression: *ExpressionDO, + expression_statement: *ExpressionStatementDO, + file: *FileDO, + modified_2to3_file: *Modified2To3FileDO, + parse_error_file: *ParseErrorFileDO, + file_md5_sum: *FileMd5SumDO, + file_sha256_sum: *FileSha256SumDO, + folder: *FolderDO, + for_statement: *ForStatementDO, + formatted_value_expression: *FormattedValueExpressionDO, + function_def_statement: *FunctionDefStatementDO, + generator_expression: *GeneratorExpressionDO, + global_statement: *GlobalStatementDO, + if_expression: *IfExpressionDO, + if_statement: *IfStatementDO, + import_from_statement: *ImportFromStatementDO, + import_statement: *ImportStatementDO, + joined_str_expression: *JoinedStrExpressionDO, + keyword: *KeywordDO, + lambda_expression: *LambdaExpressionDO, + list_comp_expression: *ListCompExpressionDO, + list_expression: *ListExpressionDO, + location: *LocationDO, + match_case: *MatchCaseDO, + match_statement: *MatchStatementDO, + metainfo: *MetainfoDO, + mod: *ModDO, + module: *ModuleDO, + scope_enclosing_expression: *ScopeEnclosingExpressionDO, + scope_enclosing_statement: *ScopeEnclosingStatementDO, + name_expression: *NameExpressionDO, + named_expression: *NamedExpressionDO, + non_local_statement: *NonLocalStatementDO, + number_of_lines: *NumberOfLinesDO, + operator: *OperatorDO, + parent: *ParentDO, + pass_statement: *PassStatementDO, + program: *ProgramDO, + raise_statement: *RaiseStatementDO, + reference_relation: *ReferenceRelationDO, + return_statement: *ReturnStatementDO, + set_comp_expression: *SetCompExpressionDO, + set_expression: *SetExpressionDO, + slice: *SliceDO, + starred_expression: *StarredExpressionDO, + statement: *StatementDO, + subscript_expression: *SubscriptExpressionDO, + token: *TokenDO, + try_statement: *TryStatementDO, + tuple_expression: *TupleExpressionDO, + unary_op: *UnaryOpDO, + unary_op_expression: *UnaryOpExpressionDO, + variable: *VariableDO, + while_statement: *WhileStatementDO, + with_item: *WithItemDO, + with_statement: *WithStatementDO, + yield_expression: *YieldExpressionDO, + yield_from_expression: *YieldFromExpressionDO +} diff --git a/language/python/lib/Decorator.gdl b/language/python/lib/Decorator.gdl new file mode 100644 index 00000000..629a361e --- /dev/null +++ b/language/python/lib/Decorator.gdl @@ -0,0 +1,80 @@ +/** + * @brief A decorator for a class or a function. + */ +schema Decorator extends Expression { + +} +impl Decorator { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Decorator { + for (tmp in Expression(db)) { + for (d in DecoratorDO(db)) { + if (tmp.key_eq(d)) { + yield Decorator { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the decorated element of the element, a class or a function. + * @return CombineElement + */ + pub fn getDecoratedElement(self) -> CombineElement { + for (c in CombineElement(__all_data__), + r in DecoratedRelation(__all_data__)) { + if (self.key_eq(r)) { + if (c = r.getDecoratedElement()) { + return c + } + } + } + } +} +/** + * @brief A decorated relation. + */ +schema DecoratedRelation extends DecoratedRelationDO { + +} +impl DecoratedRelation { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *DecoratedRelation { + for (tmp in DecoratedRelationDO(db)) { + yield DecoratedRelation { + decorator_oid : tmp.decorator_oid, + decorated_element_oid : tmp.decorated_element_oid + } + } + } + /** + * @brief gets the decorator of the relation. + * @return Decorator + */ + pub fn getDecorator(self) -> Decorator { + for (d in Decorator(__all_data__)) { + if (d.key_eq(self)) { + return d + } + } + } + /** + * @brief gets the decorated element of the relation. + * @return CombineElement + */ + pub fn getDecoratedElement(self) -> CombineElement { + for (c in CombineElement(__all_data__)) { + if (c.id = self.getDecoratedElementOid()) { + return c + } + } + } +} diff --git a/language/python/lib/Documentation.gdl b/language/python/lib/Documentation.gdl new file mode 100644 index 00000000..00597e96 --- /dev/null +++ b/language/python/lib/Documentation.gdl @@ -0,0 +1,162 @@ +/** + * @brief a comment. + */ +schema Comment extends CommentDO { + +} +impl Comment { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Comment { + for (tmp in CommentDO(db)) { + yield Comment { + element_oid : tmp.element_oid, + text : tmp.text, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getLocationOid()) { + return loc + } + } + } + /** + * @brief gets the documented element of the comment. + * @return CombineElement + */ + pub fn getDocumentedBelowElement(self) -> *CombineElement { + for (e in CombineElement(__all_data__), + f in File(__all_data__)) { + if (f.element_oid = self.getParentOid()) { + if (f = e.getLocation().getFile()) { + let (line = self.getLocation().getEndLineNumber()) { + if (line + 1 = e.getLocation().getStartLineNumber()) { + if (!isCommentElement(e)) { + yield e + } + } + } + } + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (e in CombineElement(__all_data__)) { + if (e.id = self.getParentOid()) { + return e + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the documented class or function of the comment. + * @return CombineElement + */ + pub fn getDocumentedClassOrFunctionElement(self) -> CombineElement { + for (h in CombineElement(__all_data__)) { + for (e in Function(__all_data__)) { + if (self.getParent().key_eq(e.getLocation().getFile())) { + let (line = self.getLocation().getEndLineNumber()) { + if (line + 1 = e.getLocation().getStartLineNumber()) { + if (h.key_eq(e)) { + return h + } + } + } + } + } + for (e in Class(__all_data__)) { + if (self.getParent().key_eq(e.getLocation().getFile())) { + let (line = self.getLocation().getEndLineNumber()) { + if (line + 1 = e.getLocation().getStartLineNumber()) { + if (h.key_eq(e)) { + return h + } + } + } + } + } + } + } +} +/** + * @brief A docstring comment. + */ +schema DocstringComment extends DocstringCommentDO { + +} +impl DocstringComment { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *DocstringComment { + for (tmp in DocstringCommentDO(db)) { + yield DocstringComment { + element_oid : tmp.element_oid, + text : tmp.text, + documented_element_oid : tmp.documented_element_oid + } + } + } + /** + * @brief gets the documentable element id of the docstring comment, maybe a callable, field, enumconstant, class or interface. + * @return CombineElement + */ + pub fn getDocumentableElement(self) -> CombineElement { + for (element in CombineElement(__all_data__)) { + if (element.id = self.getDocumentedElementOid()) { + return element + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (e in CombineElement(__all_data__)) { + if (e.id = self.getDocumentedElementOid()) { + return e + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } +} +pub fn isCommentElement(e : CombineElement) -> bool { + for (m in Comment(__all_data__)) { + if (e.key_eq(m)) { + return true + } + } +} diff --git a/language/python/lib/Element.gdl b/language/python/lib/Element.gdl new file mode 100644 index 00000000..e27c90ea --- /dev/null +++ b/language/python/lib/Element.gdl @@ -0,0 +1,560 @@ +/** + * @brief This is the base of all AST node classes. + */ +schema CombineElement { + @primary id: int +} +impl CombineElement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *CombineElement { + for (e in Element(db)) { + yield CombineElement {id : e.oid} + } + for (e in Statement(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in MatchCase(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in ExceptHandler(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Expression(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Alias(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Module(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Arg(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Arguments(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Comprehension(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Keyword(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in WithItem(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Slice(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in File(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in Comment(db)) { + yield CombineElement {id : e.element_oid} + } + for (e in DocstringComment(db)) { + yield CombineElement {id : e.element_oid} + } + } + pub fn getParentOid(self) -> int { + for (e in Element(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in Statement(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in MatchCase(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in ExceptHandler(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in Expression(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in Alias(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in Module(__all_data__)) { + if (self.key_eq(e)) { + let (id = e.getParent().element_oid) { + return id + } + } + } + for (e in Arg(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in Arguments(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in Comprehension(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in Keyword(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in WithItem(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in Slice(__all_data__)) { + if (self.key_eq(e)) { + return e.getParentOid() + } + } + for (e in File(__all_data__), + p in Program(__all_data__)) { + if (self.key_eq(e)) { + let (id = p.program_oid) { + return id + } + } + } + for (e in Comment(__all_data__), + m in Module(__all_data__)) { + if (self.key_eq(e)) { + if (m.getParent().element_oid = e.getParentOid()) { + let (id = m.element_oid) { + return id + } + } + } + } + for (e in DocstringComment(__all_data__)) { + if (self.key_eq(e)) { + let (id = e.getDocumentableElement().id) { + return id + } + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (e in CombineElement(__all_data__)) { + if (e.id = self.getParentOid()) { + return e + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + yield self.getParent() + for (auto_tmp1 in self.getAnAncestor()) { + yield auto_tmp1.getParent() + } + } + + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (id in Location(__all_data__)) { + for (e in Statement(__all_data__)) { + if (self.key_eq(e)) { + if (id.element_oid = e.getLocationOid()) { + return id + } + } + } + for (e in MatchCase(__all_data__)) { + if (self.key_eq(e)) { + if (id.element_oid = e.getLocationOid()) { + return id + } + } + } + for (e in ExceptHandler(__all_data__)) { + if (self.key_eq(e)) { + if (id.element_oid = e.getLocationOid()) { + return id + } + } + } + for (e in Expression(__all_data__)) { + if (self.key_eq(e)) { + if (id.element_oid = e.getLocationOid()) { + return id + } + } + } + for (e in Alias(__all_data__)) { + if (self.key_eq(e)) { + if (id.element_oid = e.getLocationOid()) { + return id + } + } + } + for (e in Arg(__all_data__)) { + if (self.key_eq(e)) { + if (id.element_oid = e.getLocationOid()) { + return id + } + } + } + for (e in Arguments(__all_data__)) { + if (self.key_eq(e)) { + if (id = e.getLocation()) { + return id + } + } + } + for (e in Comprehension(__all_data__)) { + if (self.key_eq(e)) { + if (id = e.getLocation()) { + return id + } + } + } + for (e in Keyword(__all_data__)) { + if (self.key_eq(e)) { + if (id = e.getLocation()) { + return id + } + } + } + for (e in WithItem(__all_data__)) { + if (self.key_eq(e)) { + if (id = e.getLocation()) { + return id + } + } + } + for (e in Slice(__all_data__)) { + if (self.key_eq(e)) { + if (id = e.getLocation()) { + return id + } + } + } + for (e in Comment(__all_data__)) { + if (self.key_eq(e)) { + if (id = e.getLocation()) { + return id + } + } + } + for (e in Module(__all_data__)) { + if (self.key_eq(e)) { + if (id = e.getLocation()) { + return id + } + } + } + for (e in DocstringComment(__all_data__)) { + if (self.key_eq(e)) { + if (id.key_eq(e.getDocumentableElement())) { + return id + } + } + } + for (e in File(__all_data__), + m in Module(__all_data__)) { + if (self.key_eq(e)) { + if (e = m.getParent()) { + if (id = m.getLocation()) { + return id + } + } + } + } + } + } + /** + * @brief gets the index for printing AST. + * @return int + */ + pub fn getAnAncestorForIndex(self, index : int) -> CombineElement { + if (index = 1) { + return self.getParent() + } + for (indexTemp in int::__undetermined_all__()) { + let (temp = self.getParent()) { + let (ancestor = temp.getAnAncestorForIndex(indexTemp)) { + if (index = indexTemp + 1) { + return ancestor + } + } + } + } + } + /** + * @brief gets the printable text for printing AST + * @return string + */ + pub fn print(self) -> string { + for (e in Element(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getValue()) { + return text + } + } + } + for (e in Statement(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in MatchCase(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in ExceptHandler(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in Expression(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in Alias(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in Module(__all_data__)) { + if (self.key_eq(e)) { + let (text = "Module") { + return text + } + } + } + for (e in Arg(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in Arguments(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in Comprehension(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in Keyword(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in WithItem(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in Slice(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getPrintableText()) { + return text + } + } + } + for (e in Comment(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getText()) { + return text + } + } + } + for (e in DocstringComment(__all_data__)) { + if (self.key_eq(e)) { + let (text = e.getText()) { + return text + } + } + } + for (e in File(__all_data__)) { + if (self.key_eq(e)) { + let (text = "File") { + return text + } + } + } + } + /** + * @brief gets the printable text for printing AST + * @return string + */ + pub fn getType(self) -> string { + for (e in Element(__all_data__)) { + if (self.key_eq(e)) { + return "Normal Element" + } + } + for (s in string::__undetermined_all__()) { + for (e in Statement(__all_data__)) { + if (self.key_eq(e)) { + return e.getType() + " Expression" + } + } + } + for (e in MatchCase(__all_data__)) { + if (self.key_eq(e)) { + return "Match Case" + } + } + for (e in ExceptHandler(__all_data__)) { + if (self.key_eq(e)) { + return "Except Handler" + } + } + for (s in string::__undetermined_all__()) { + for (e in Expression(__all_data__)) { + if (self.key_eq(e)) { + return e.getType() + " Expression" + } + } + } + for (e in Alias(__all_data__)) { + if (self.key_eq(e)) { + return "Alias" + } + } + for (e in Module(__all_data__)) { + if (self.key_eq(e)) { + return "Module" + } + } + for (e in Arg(__all_data__)) { + if (self.key_eq(e)) { + return "Arg" + } + } + for (e in Arguments(__all_data__)) { + if (self.key_eq(e)) { + return "Arguments" + } + } + for (e in Comprehension(__all_data__)) { + if (self.key_eq(e)) { + return "Comprehension" + } + } + for (e in Keyword(__all_data__)) { + if (self.key_eq(e)) { + return "Keyword" + } + } + for (e in WithItem(__all_data__)) { + if (self.key_eq(e)) { + return "With item" + } + } + for (e in Slice(__all_data__)) { + if (self.key_eq(e)) { + return "Slice" + } + } + for (e in Comment(__all_data__)) { + if (self.key_eq(e)) { + return "Comment" + } + } + for (e in DocstringComment(__all_data__)) { + if (self.key_eq(e)) { + return "Docstring Comment" + } + } + for (e in File(__all_data__)) { + if (self.key_eq(e)) { + return "File" + } + } + } +} +/** + * @brief An element without classification. + */ +schema Element extends ElementDO { + +} +impl Element { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Element { + for (tmp in ElementDO(db)) { + yield Element { + oid : tmp.oid, + value : tmp.value, + type : tmp.type, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (e in CombineElement(__all_data__)) { + if (e.id = self.getParentOid()) { + return e + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } +} diff --git a/language/python/lib/Expression.gdl b/language/python/lib/Expression.gdl new file mode 100644 index 00000000..bfeec16e --- /dev/null +++ b/language/python/lib/Expression.gdl @@ -0,0 +1,321 @@ +/** + * @brief A common super-class that represents all kinds of expressions. + */ +schema Expression extends ExpressionDO { + +} +impl Expression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Expression { + for (tmp in ExpressionDO(db)) { + yield Expression { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the parent of the expression. + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getLocationOid()) { + return loc + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_oid = self.getLocationOid()) { + return n + } + } + } + /** + * @brief gets the immediately enclosing scope (module, function or class) whose body contains this statement. + * @return Scope + */ + pub fn getEnclosingScope(self) -> Scope { + for (s in Scope(__all_data__), + m in ScopeEnclosingExpression(__all_data__)) { + if (self.key_eq(m)) { + if (s = m.getEnclosingScope()) { + return s + } + } + } + } +} +/** + * @brief An if expression. + */ +schema IfExpression extends Expression { + +} +impl IfExpression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *IfExpression { + for (tmp in Expression(db)) { + for (e in IfExpressionDO(db)) { + if (tmp.key_eq(e)) { + yield IfExpression { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A boolean expression. + */ +schema BooleanExpression extends Expression { + +} +impl BooleanExpression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *BooleanExpression { + for (tmp in Expression(db)) { + for (e in BooleanOpExpressionDO(db)) { + if (tmp.key_eq(e)) { + yield BooleanExpression { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the type of the expression. + * @return string + */ + pub fn getType(self) -> string { + for (e in BooleanOpExpressionDO(__all_data__)) { + if (self.key_eq(e)) { + return e.getType() + } + } + } + /** + * @brief gets the size information for the element. + * @return int + */ + pub fn getSize(self) -> int { + for (e in BooleanOpExpressionDO(__all_data__)) { + if (self.key_eq(e)) { + return e.getSize() + } + } + } +} +/** + * @brief An "and" logical expression. + */ +schema AndLogicalExpression extends BooleanExpression { + +} +impl AndLogicalExpression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *AndLogicalExpression { + for (tmp in BooleanExpression(db)) { + if (tmp.getType() = "And") { + yield AndLogicalExpression { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } +} +/** + * @brief A "or" logical expression. + */ +schema OrLogicalExpression extends BooleanExpression { + +} +impl OrLogicalExpression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *OrLogicalExpression { + for (tmp in BooleanExpression(db)) { + if (tmp.getType() = "Or") { + yield OrLogicalExpression { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } +} +/** + * @brief An attribute expression. + */ +schema AttributeExpression extends Expression { + +} +impl AttributeExpression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *AttributeExpression { + for (tmp in Expression(db)) { + for (a in AttributeExpressionDO(db)) { + if (tmp.key_eq(a)) { + yield AttributeExpression { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A function call expression. + */ +schema CallExpression extends Expression { + +} +impl CallExpression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *CallExpression { + for (tmp in Expression(db)) { + for (c in CallExpressionDO(db)) { + if (tmp.key_eq(c)) { + yield CallExpression { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the function expression in the call. + * @return Expression + */ + pub fn getFunctionExpression(self) -> Expression { + for (e in Expression(__all_data__), + c in CallExpressionDO(__all_data__)) { + if (self.key_eq(c)) { + if (e.element_oid = c.getExprFuncOid()) { + return e + } + } + } + } + /** + * @brief gets the arguments in the call. + * @return CombineElement + */ + pub fn getArgs(self) -> *CombineElement { + for (h in CombineElement(__all_data__), + c in CallExpressionDO(__all_data__)) { + if (self.key_eq(c)) { + for (e in Expression(__all_data__)) { + if (c.key_eq(e.getParent())) { + if (e.getElementIndex() > 0) { + if (h.key_eq(e)) { + yield h + } + } + } + } + for (e in Keyword(__all_data__)) { + if (c.key_eq(e.getParent())) { + if (h.key_eq(e)) { + yield h + } + } + } + } + } + } +} +/** + * @brief A list compare expression. + */ +schema ListCompExpression extends Expression { + +} +impl ListCompExpression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ListCompExpression { + for (tmp in Expression(db)) { + for (c in ListCompExpressionDO(db)) { + if (tmp.key_eq(c)) { + yield ListCompExpression { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} diff --git a/language/python/lib/Function.gdl b/language/python/lib/Function.gdl new file mode 100644 index 00000000..e49c8da3 --- /dev/null +++ b/language/python/lib/Function.gdl @@ -0,0 +1,147 @@ +/** + * @brief A function, a normal function def statement or an async function def statement. + */ +schema Function extends Statement { + +} +impl Function { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Function { + for (tmp in Statement(db)) { + for (f in FunctionDefStatement(db)) { + if (tmp.key_eq(f)) { + yield Function { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + for (f in AsyncFunctionDefStatement(db)) { + if (tmp.key_eq(f)) { + yield Function { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the name of the function. + * @return string + */ + pub fn getName(self) -> string { + for (name in string::__undetermined_all__()) { + for (f in FunctionDefStatement(__all_data__)) { + if (self.key_eq(f)) { + if (name = f.getName()) { + return name + } + } + } + for (f in AsyncFunctionDefStatement(__all_data__)) { + if (self.key_eq(f)) { + if (name = f.getName()) { + return name + } + } + } + } + } + /** + * @brief gets the qualified name of the function. + * @return string + */ + pub fn getQualifiedName(self) -> string { + for (s in Scope(__all_data__)) { + if (s = self.getEnclosingScope()) { + let (postfix = self.getName()) { + for (m in Module(__all_data__)) { + if (m.key_eq(s)) { + let (name = postfix) { + return name + } + } + } + for (suffix in string::__undetermined_all__()) { + for (c in Class(__all_data__)) { + if (c.key_eq(s)) { + if (suffix = c.getQualifiedName()) { + let (name = suffix + "." + postfix) { + return name + } + } + } + } + } + for (suffix in string::__undetermined_all__()) { + for (c in Function(__all_data__)) { + if (c.key_eq(s)) { + if (suffix = c.getQualifiedName()) { + let (name = suffix + "." + postfix) { + return name + } + } + } + } + } + } + } + } + } + /** + * @brief gets the arguments of the function. + * @return Arguments + */ + pub fn getArguments(self) -> Arguments { + for (a in Arguments(__all_data__)) { + if (self.key_eq(a.getParent())) { + return a + } + } + } + /** + * @brief gets the arg by index of the function. + * @return Arg + */ + pub fn getArgumentByIndex(self, i: int) -> Arg { + for (a in Arg(__all_data__)) { + if (a = self.getArguments().getArgByIndex(i)) { + return a + } + } + } +} +/** + * @brief A init function. + */ +schema InitFunction extends Function { + +} +impl InitFunction { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *InitFunction { + for (tmp in Function(db)) { + if (tmp.getName() = "__init__") { + yield InitFunction { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } +} diff --git a/language/python/lib/Keyword.gdl b/language/python/lib/Keyword.gdl new file mode 100644 index 00000000..5ff666d9 --- /dev/null +++ b/language/python/lib/Keyword.gdl @@ -0,0 +1,99 @@ +/** + * @brief A keyword argument to a function call or class definition. + */ +schema Keyword extends KeywordDO { + +} +impl Keyword { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Keyword { + for (tmp in KeywordDO(db)) { + yield Keyword { + element_oid : tmp.element_oid, + arg_value : tmp.arg_value, + value_oid : tmp.value_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the value of the keyword. + * @return Expression + */ + pub fn getValue(self) -> Expression { + for (c in Expression(__all_data__)) { + if (c.element_oid = self.getValueOid()) { + return c + } + } + } + /** + * @brief gets the parameter name of the keyword. + * @return string + */ + pub fn getArgName(self) -> string { + return self.getArgValue() + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getLocationOid()) { + return loc + } + } + } +} +/** + * @brief A keyword without name to a function call or class definition. + */ +schema KeywordWithoutName extends Keyword { + +} +impl KeywordWithoutName { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *KeywordWithoutName { + for (tmp in Keyword(db)) { + if (tmp.getArgName() = "None") { + yield KeywordWithoutName { + element_oid : tmp.element_oid, + arg_value : tmp.arg_value, + value_oid : tmp.value_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } +} diff --git a/language/python/lib/Location.gdl b/language/python/lib/Location.gdl new file mode 100644 index 00000000..1f17a348 --- /dev/null +++ b/language/python/lib/Location.gdl @@ -0,0 +1,53 @@ +/** + * @brief The location information of a locatable elements. + */ +schema Location extends LocationDO { + +} +impl Location { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Location { + for (tmp in LocationDO(db)) { + yield Location { + element_oid : tmp.element_oid, + file_oid : tmp.file_oid, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number + } + } + } + /** + * @brief gets the file information for the location + * @return File + */ + pub fn getFile(self) -> File { + for (f in File(__all_data__)) { + if (f.element_oid = self.getFileOid()) { + return f + } + } + } +} +/** + * @brief The number of lines for a python file. + */ +schema NumberOfLines extends NumberOfLinesDO { + +} +impl NumberOfLines { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *NumberOfLines { + for (tmp in NumberOfLinesDO(db)) { + yield NumberOfLines { + element_oid : tmp.element_oid, + number_of_total_lines : tmp.number_of_total_lines, + number_of_valid_lines : tmp.number_of_valid_lines, + number_of_comment_lines : tmp.number_of_comment_lines + } + } + } +} diff --git a/language/python/lib/Metrics.gdl b/language/python/lib/Metrics.gdl new file mode 100644 index 00000000..617e7c97 --- /dev/null +++ b/language/python/lib/Metrics.gdl @@ -0,0 +1,368 @@ +/** + * @brief A scope enclosing expression relation. + */ +schema ScopeEnclosingExpression extends ScopeEnclosingExpressionDO { + +} +impl ScopeEnclosingExpression { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ScopeEnclosingExpression { + for (tmp in ScopeEnclosingExpressionDO(db)) { + yield ScopeEnclosingExpression { + expression_oid : tmp.expression_oid, + scope_oid : tmp.scope_oid + } + } + } + /** + * @brief gets the enclosing expression in the relation. + * @return Expression + */ + pub fn getExpression(self) -> Expression { + for (f in Expression(__all_data__)) { + if (f.key_eq(self)) { + return f + } + } + } + /** + * @brief gets the enclosed function in the relation. + * @return Function + */ + pub fn getFunction(self) -> Function { + for (f in Function(__all_data__)) { + if (f.element_oid = self.getScopeOid()) { + return f + } + } + } + /** + * @brief gets the enclosed class in the relation. + * @return Class + */ + pub fn getClass(self) -> Class { + for (f in Class(__all_data__)) { + if (f.element_oid = self.getScopeOid()) { + return f + } + } + } + /** + * @brief gets the enclosed module in the relation. + * @return module + */ + pub fn getModule(self) -> Module { + for (m in Module(__all_data__)) { + if (m.key_eq(self.getEnclosingScope())) { + return m + } + if (m.key_eq(self.getEnclosingScope().getEnclosingScope())) { + return m + } + } + } + /** + * @brief gets the direct enclosed scope in the relation. + * @return Scope + */ + pub fn getEnclosingScope(self) -> Scope { + for (f in Scope(__all_data__)) { + if (f.id = self.getScopeOid()) { + return f + } + } + } +} +/** + * @brief A scope enclosing statement relation. + */ +schema ScopeEnclosignStatement extends ScopeEnclosingStatementDO { + +} +impl ScopeEnclosignStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ScopeEnclosignStatement { + for (tmp in ScopeEnclosingStatementDO(db)) { + yield ScopeEnclosignStatement { + statement_oid : tmp.statement_oid, + scope_oid : tmp.scope_oid + } + } + } + /** + * @brief gets the enclosing statement in the relation. + * @return Statement + */ + pub fn getStatement(self) -> Statement { + for (f in Statement(__all_data__)) { + if (f.key_eq(self)) { + return f + } + } + } + /** + * @brief gets the enclosed function in the relation. + * @return Function + */ + pub fn getFunction(self) -> Function { + for (f in Function(__all_data__)) { + if (f.element_oid = self.getScopeOid()) { + return f + } + } + } + /** + * @brief gets the enclosed class in the relation. + * @return Class + */ + pub fn getClass(self) -> Class { + for (f in Class(__all_data__)) { + if (f.element_oid = self.getScopeOid()) { + return f + } + } + } + /** + * @brief gets the enclosed module in the relation. + * @return module + */ + pub fn getModule(self) -> Module { + for (m in Module(__all_data__)) { + if (m.key_eq(self.getEnclosingScope())) { + return m + } + if (m.key_eq(self.getEnclosingScope().getEnclosingScope())) { + return m + } + } + } + /** + * @brief gets the direct enclosed scope in the relation. + * @return Scope + */ + pub fn getEnclosingScope(self) -> Scope { + for (f in Scope(__all_data__)) { + if (f.id = self.getScopeOid()) { + return f + } + } + } +} +/** + * @brief A metric function. + */ +schema MetricFunction extends Function { + +} +impl MetricFunction { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *MetricFunction { + for (tmp in Function(db)) { + yield MetricFunction { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief The cyclomatic complexity of a callable is defined as the number + * of branching statements (`if`, `while`, `do`, `for`, `matchcase`, `except`) + * plus the number of branching expressions (`?`, `&&` and `||`) + * plus one. + * @return int + */ + pub fn getCyclomaticComplexity(self) -> int { + let (tmp1 = tmp_branchingStatement(self).len(), + tmp2 = tmp_branchingExceptHandle(self).len(), + tmp3 = tmp_branchingMatchCase(self).len()) { + for (tmp4 in int::__undetermined_all__()) { + if (branchingExpression(tmp4, self.element_oid)) { + return tmp1 + tmp2 + tmp3 + tmp4 + 1 + } + } + } + } +} +pub fn branchingExceptHandle(c : ExceptHandler, f : Function) -> bool { + let (m = c.getTryStatement()) { + if (f.key_eq(m.getEnclosingScope())) { + return true + } + } +} +pub fn branchingStatement(tmp : Statement, f : Function) -> bool { + for (i in IfStatement(__all_data__)) { + if (i.key_eq(tmp)) { + if (f.key_eq(i.getEnclosingScope())) { + return true + } + } + } + for (i in WhileStatement(__all_data__)) { + if (i.key_eq(tmp)) { + if (f.key_eq(i.getEnclosingScope())) { + return true + } + } + } + for (i in ForStatement(__all_data__)) { + if (i.key_eq(tmp)) { + if (f.key_eq(i.getEnclosingScope())) { + return true + } + } + } +} +pub fn branchingMatchCase(l : MatchCase, f : Function) -> bool { + for (c in MatchStatement(__all_data__)) { + if (l.isDefault() = 0) { + if (c = l.getMatchStatement()) { + if (f.key_eq(c.getEnclosingScope())) { + for (b in BreakStatement(__all_data__)) { + for (auto_tmp1 in b.getAnAncestor()) { + if (l.key_eq(auto_tmp1)) { + return true + } + } + } + for (r in ReturnStatement(__all_data__)) { + for (auto_tmp2 in r.getAnAncestor()) { + if (l.key_eq(auto_tmp2)) { + return true + } + } + } + for (t in ExceptHandler(__all_data__)) { + for (auto_tmp3 in t.getAnAncestor()) { + if (l.key_eq(auto_tmp3)) { + return true + } + } + } + } + } + } + } +} +pub fn branchingIfExpression(tmp : int, f : int) -> bool { + for (i in IfExpression(__all_data__)) { + if (f = i.getEnclosingScope().id && tmp = i.element_oid) { + return true + } + } +} +pub fn branchingBooleanExpression(tmp : int, size : int) -> bool { + for (i in AndLogicalExpression(__all_data__)) { + if (size = i.getSize() && tmp = i.element_oid) { + return true + } + } + for (i in OrLogicalExpression(__all_data__)) { + if (size = i.getSize() && tmp = i.element_oid) { + return true + } + } +} +pub fn branchingExpression(tmp1: int, tmp2: int) -> bool { + for (f in Function(__all_data__)) { + if (f.element_oid = tmp2) { + let (m = tmp_branchingExpression_branchingIfExpression(__all_data__, tmp2).len()) { + let (n = tmp_branchingExpression_branchingBooleanExpression(__all_data__, __all_data__, tmp2).sum()) { + if (tmp1 = m + n) { + return true + } + } + } + } + } +} + +fn tmp_branchingStatement(x: MetricFunction) -> *int { + for (i in IfStatement(__all_data__)) { + if (i.getEnclosingScope().key_eq(x)) { + yield i.element_oid + } + } + for (i in WhileStatement(__all_data__)) { + if (i.getEnclosingScope().key_eq(x)) { + yield i.element_oid + } + } + for (i in ForStatement(__all_data__)) { + if (i.getEnclosingScope().key_eq(x)) { + yield i.element_oid + } + } +} + +fn tmp_branchingExceptHandle(x: MetricFunction) -> *ExceptHandler { + for (c in ExceptHandler(__all_data__)) { + let (m = c.getTryStatement()) { + if (x.key_eq(m.getEnclosingScope())) { + yield c + } + } + } +} + +fn tmp_branchingMatchCase(x: MetricFunction) -> *MatchCase { + for (l in MatchCase(__all_data__)) { + if (l.isDefault() = 0) { + let (c = l.getMatchStatement()) { + if (x.key_eq(c.getEnclosingScope())) { + for (b in BreakStatement(__all_data__)) { + for (tmp in b.getAnAncestor()) { + if (l.key_eq(tmp)) { + yield l + } + } + } + for (r in ReturnStatement(__all_data__)) { + for (tmp in r.getAnAncestor()) { + if (l.key_eq(tmp)) { + yield l + } + } + } + for (e in ExceptHandler(__all_data__)) { + for (tmp in e.getAnAncestor()) { + if (l.key_eq(tmp)) { + yield l + } + } + } + } + } + } + } +} + +fn tmp_branchingExpression_branchingIfExpression(e: Expression, f: int) -> *IfExpression{ + for (i in IfExpression(__all_data__)) { + if (i.key_eq(e)) { + if (i.getEnclosingScope().id = f) { + yield i + } + } + } +} + +fn tmp_branchingExpression_branchingBooleanExpression(e: BooleanExpression, i: int, f: int) -> *int { + for (tmp in BooleanExpression(__all_data__)) { + if (e = tmp) { + if (f = e.getEnclosingScope().id) { + if (branchingBooleanExpression(e.element_oid, i)) { + yield i + } + } + } + } + +} diff --git a/language/python/lib/Scope.gdl b/language/python/lib/Scope.gdl new file mode 100644 index 00000000..3a48405c --- /dev/null +++ b/language/python/lib/Scope.gdl @@ -0,0 +1,59 @@ +/** + * A Scope. A scope is the lexical extent over which all identifiers with the same name refer to the same variable. + * Modules, Classes and Functions are all Scopes. There are no other scopes. + * The scopes for expressions that create new scopes, lambdas and comprehensions, are handled by creating an anonymous Function. + */ +schema Scope extends CombineElement { + +} +impl Scope { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Scope { + for (tmp in CombineElement(db)) { + for (m in Module(db)) { + if (tmp.key_eq(m)) { + yield Scope { + id : tmp.id + } + } + } + for (c in Class(db)) { + if (tmp.key_eq(c)) { + yield Scope { + id : tmp.id + } + } + } + for (f in Function(db)) { + if (tmp.key_eq(f)) { + yield Scope { + id : tmp.id + } + } + } + } + } + /** + * @brief gets the immediately enclosing scope (module, function or class) whose body contains this statement. + * @return Scope + */ + pub fn getEnclosingScope(self) -> Scope { + for (s in Scope(__all_data__)) { + for (m in Module(__all_data__)) { + if (self.key_eq(m)) { + if (s.key_eq(m)) { + return s + } + } + } + for (m in ScopeEnclosignStatement(__all_data__)) { + if (self.key_eq(m)) { + if (s = m.getEnclosingScope()) { + return s + } + } + } + } + } +} diff --git a/language/python/lib/Slice.gdl b/language/python/lib/Slice.gdl new file mode 100644 index 00000000..c2d0dc1e --- /dev/null +++ b/language/python/lib/Slice.gdl @@ -0,0 +1,55 @@ +/** + * @brief Regular slicing (on the form lower:upper or lower:upper:step). Can occur only inside the slice field of Subscript, either directly or as an element of Tuple. + */ +schema Slice extends SliceDO { + +} +impl Slice { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Slice { + for (tmp in SliceDO(db)) { + yield Slice { + element_oid : tmp.element_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text, + has_step : tmp.has_step + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getLocationOid()) { + return loc + } + } + } +} diff --git a/language/python/lib/Statement.gdl b/language/python/lib/Statement.gdl new file mode 100644 index 00000000..df78c987 --- /dev/null +++ b/language/python/lib/Statement.gdl @@ -0,0 +1,654 @@ +/** + * @brief A super class for all statements. + */ +schema Statement extends StatementDO { + +} +impl Statement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *Statement { + for (tmp in StatementDO(db)) { + yield Statement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getLocationOid()) { + return loc + } + } + } + /** + * @brief gets the size information for the element. + * @return NumberOfLines + */ + pub fn getSize(self) -> NumberOfLines { + for (n in NumberOfLines(__all_data__)) { + if (n.element_oid = self.getLocationOid()) { + return n + } + } + } + /** + * @brief gets the parent element of the statement + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the immediately enclosing scope (module, function or class) whose body contains this statement. + * @return Scope + */ + pub fn getEnclosingScope(self) -> Scope { + for (s in Scope(__all_data__), + m in ScopeEnclosignStatement(__all_data__)) { + if (self.key_eq(m)) { + if (s = m.getEnclosingScope()) { + return s + } + } + } + } + /** + * @brief gets a child of this statement. + * @return Statement + */ + pub fn getAChild(self) -> *Statement { + for (child in Statement(__all_data__)) { + if (self.key_eq(child.getParent())) { + yield child + } + } + } + /** + * @brief gets the statement containing this statement. + * @return Statement + */ + pub fn getEnclosingStatement(self) -> Statement { + for (stmt in Statement(__all_data__)) { + if (stmt.element_oid = self.getParentOid()) { + return stmt + } + } + } +} +/** + * @brief A function definition. + */ +schema FunctionDefStatement extends Statement { + +} +impl FunctionDefStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *FunctionDefStatement { + for (tmp in Statement(db)) { + for (f in FunctionDefStatementDO(db)) { + if (tmp.key_eq(f)) { + yield FunctionDefStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the name of the function. + * @return string + */ + pub fn getName(self) -> string { + for (name in string::__undetermined_all__()) { + for (f in FunctionDefStatementDO(__all_data__)) { + if (self.key_eq(f)) { + if (name = f.getName()) { + return name + } + } + } + } + } +} +/** + * @brief An async function definition. + */ +schema AsyncFunctionDefStatement extends Statement { + +} +impl AsyncFunctionDefStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *AsyncFunctionDefStatement { + for (tmp in Statement(db)) { + for (f in AsyncFunctionDefStatementDO(db)) { + if (tmp.key_eq(f)) { + yield AsyncFunctionDefStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the name of the function. + * @return string + */ + pub fn getName(self) -> string { + for (name in string::__undetermined_all__()) { + for (f in AsyncFunctionDefStatementDO(__all_data__)) { + if (self.key_eq(f)) { + if (name = f.getName()) { + return name + } + } + } + } + } +} +/** + * @brief A class definition. + */ +schema ClassDefStatement extends Statement { + +} +impl ClassDefStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ClassDefStatement { + for (tmp in Statement(db)) { + for (f in ClassDefStatementDO(db)) { + if (tmp.key_eq(f)) { + yield ClassDefStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the name of the class. + * @return string + */ + pub fn getName(self) -> string { + for (name in string::__undetermined_all__()) { + for (c in ClassDefStatementDO(__all_data__)) { + if (self.key_eq(c)) { + if (name = c.getName()) { + return name + } + } + } + } + } +} +/** + * @brief A for loop statement. + */ +schema ForStatement extends Statement { + +} +impl ForStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ForStatement { + for (tmp in Statement(db)) { + for (f in ForStatementDO(db)) { + if (tmp.key_eq(f)) { + yield ForStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief An if statement. + */ +schema IfStatement extends Statement { + +} +impl IfStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *IfStatement { + for (tmp in Statement(db)) { + for (f in IfStatementDO(db)) { + if (tmp.key_eq(f)) { + yield IfStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A while loop statement. + */ +schema WhileStatement extends Statement { + +} +impl WhileStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *WhileStatement { + for (tmp in Statement(db)) { + for (f in WhileStatementDO(db)) { + if (tmp.key_eq(f)) { + yield WhileStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A try statement. + */ +schema TryStatement extends Statement { + +} +impl TryStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *TryStatement { + for (tmp in Statement(db)) { + for (f in TryStatementDO(db)) { + if (tmp.key_eq(f)) { + yield TryStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A single except clause. + */ +schema ExceptHandler extends ExceptHandlerDO { + +} +impl ExceptHandler { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ExceptHandler { + for (tmp in ExceptHandlerDO(db)) { + yield ExceptHandler { + element_oid : tmp.element_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + /** + * @brief gets the try statement of the except clause + * @return TryStatement + */ + pub fn getTryStatement(self) -> TryStatement { + for (t in TryStatement(__all_data__)) { + if (t.element_oid = self.getParentOid()) { + return t + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } +} +/** + * @brief A match statement. + */ +schema MatchStatement extends Statement { + +} +impl MatchStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *MatchStatement { + for (tmp in Statement(db)) { + for (s in MatchStatementDO(db)) { + if (tmp.key_eq(s)) { + yield MatchStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets a case pattern in the statement. + * @return MatchCase + */ + pub fn getMatchCase(self) -> MatchCase { + for (m in MatchCase(__all_data__)) { + if (self = m.getMatchStatement()) { + return m + } + } + } +} +/** + * @brief A single case pattern in a match statement. + */ +schema MatchCase extends MatchCaseDO { + +} +impl MatchCase { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *MatchCase { + for (tmp in MatchCaseDO(db)) { + yield MatchCase { + element_oid : tmp.element_oid, + pattern_oid : tmp.pattern_oid, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text, + is_default : tmp.is_default + } + } + } + /** + * @brief gets the match statement for the case. + * @return MatchStatement + */ + pub fn getMatchStatement(self) -> MatchStatement { + for (s in MatchStatement(__all_data__)) { + if (s.element_oid = self.getParentOid()) { + return s + } + } + } + /** + * @brief gets the default case pattern. + * @return int + */ + pub fn isDefault(self) -> int { + for (i in int::__undetermined_all__()) { + if (i = self.getIsDefault()) { + return i + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } +} +/** + * @brief A break statement. + */ +schema BreakStatement extends Statement { + +} +impl BreakStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *BreakStatement { + for (tmp in Statement(db)) { + for (s in BreakStatementDO(db)) { + if (tmp.key_eq(s)) { + yield BreakStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief A return statement. + */ +schema ReturnStatement extends Statement { + +} +impl ReturnStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ReturnStatement { + for (tmp in Statement(db)) { + for (s in ReturnStatementDO(db)) { + if (tmp.key_eq(s)) { + yield ReturnStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } +} +/** + * @brief An import statement. + */ +schema ImportStatement extends Statement { + +} +impl ImportStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ImportStatement { + for (tmp in Statement(db)) { + for (i in ImportStatementDO(db)) { + if (tmp.key_eq(i)) { + yield ImportStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the name element of the element. + * @return CombineElement + */ + pub fn getName(self) -> CombineElement { + for (c in CombineElement(__all_data__)) { + if (self.key_eq(c.getParent())) { + return c + } + } + } +} +/** + * @brief An import from statement. + */ +schema ImportFromStatement extends Statement { + +} +impl ImportFromStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *ImportFromStatement { + for (tmp in Statement(db)) { + for (i in ImportFromStatementDO(db)) { + if (tmp.key_eq(i)) { + yield ImportFromStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the module name of the import. + * @return string + */ + pub fn getModuleName(self) -> string { + for (name in string::__undetermined_all__()) { + for (i in ImportFromStatementDO(__all_data__)) { + if (self.key_eq(i)) { + if (name = i.getModule()) { + return name + } + } + } + } + } +} +/** + * @brief A with statement. + */ +schema WithStatement extends Statement { + +} +impl WithStatement { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *WithStatement { + for (tmp in Statement(db)) { + for (w in WithStatementDO(db)) { + if (tmp.key_eq(w)) { + yield WithStatement { + element_oid : tmp.element_oid, + type : tmp.type, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid, + location_oid : tmp.location_oid, + printable_text : tmp.printable_text + } + } + } + } + } + /** + * @brief gets the with item of the with statement. + * @return WithItem + */ + pub fn getWithItem(self) -> WithItem { + for (i in WithItem(__all_data__)) { + if (self.key_eq(i.getParent())) { + return i + } + } + } +} diff --git a/language/python/lib/Withitem.gdl b/language/python/lib/Withitem.gdl new file mode 100644 index 00000000..196a3b75 --- /dev/null +++ b/language/python/lib/Withitem.gdl @@ -0,0 +1,53 @@ +/** + * @brief A single context manager in a with block. + */ +schema WithItem extends WithItemDO { + +} +impl WithItem { + @data_constraint + @inline + fn __all__(db: PythonDB) -> *WithItem { + for (tmp in WithItemDO(db)) { + yield WithItem { + element_oid : tmp.element_oid, + printable_text : tmp.printable_text, + element_index : tmp.element_index, + parent_oid : tmp.parent_oid + } + } + } + /** + * @brief gets the parent element of the element + * @return CombineElement + */ + pub fn getParent(self) -> CombineElement { + for (parent in CombineElement(__all_data__)) { + if (parent.id = self.getParentOid()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return CombineElement + */ + pub fn getAnAncestor(self) -> *CombineElement { + for (temp in CombineElement(__all_data__)) { + if (self.key_eq(temp)) { + yield temp.getAnAncestor() + } + } + } + /** + * @brief gets the location for the element's parent since this type has no location info. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.element_oid = self.getParentOid()) { + return loc + } + } + } +} diff --git a/language/xml/lib/DOClass.gdl b/language/xml/lib/DOClass.gdl new file mode 100644 index 00000000..2f35d002 --- /dev/null +++ b/language/xml/lib/DOClass.gdl @@ -0,0 +1,566 @@ +/** + * @brief DO class: An xml attribute. + */ +schema XmlAttributeDO { + @primary id: int, + element_id: int, + name: string, + value: string, + index_order: int, + location_id: int +} +impl XmlAttributeDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlAttributeDO { + for (tmp in db.xml_attribute) { + yield XmlAttributeDO { + id : tmp.id, + element_id : tmp.element_id, + name : tmp.name, + value : tmp.value, + index_order : tmp.index_order, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the element id of the attribute. + * @return int + */ + pub fn getElementId(self) -> int { + return self.element_id + } + /** + * @brief gets the name of the attribute. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the value of the attribute. + * @return string + */ + pub fn getValue(self) -> string { + return self.value + } + /** + * @brief gets the index of the element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: An xml character. + */ +schema XmlCharacterDO { + @primary id: int, + text: string, + parentid: int, + index_order: int, + is_cdata: int, + location_id: int +} +impl XmlCharacterDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlCharacterDO { + for (tmp in db.xml_character) { + yield XmlCharacterDO { + id : tmp.id, + text : tmp.text, + parentid : tmp.parentid, + index_order : tmp.index_order, + is_cdata : tmp.is_cdata, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the text of the element. + * @return string + */ + pub fn getText(self) -> string { + return self.text + } + /** + * @brief gets the parent id of the element. + * @return int + */ + pub fn getParentid(self) -> int { + return self.parentid + } + /** + * @brief gets the index of the element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief check whether the element is Cdata or not. + * @return int + */ + pub fn isCdata(self) -> int { + return self.is_cdata + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: An xml comment. + */ +schema XmlCommentDO { + @primary id: int, + text: string, + parent_id: int, + location_id: int +} +impl XmlCommentDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlCommentDO { + for (tmp in db.xml_comment) { + yield XmlCommentDO { + id : tmp.id, + text : tmp.text, + parent_id : tmp.parent_id, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the text of the comment. + * @return string + */ + pub fn getText(self) -> string { + return self.text + } + /** + * @brief gets the parent id of the element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: An xml dtd element. + */ +schema XmlDtdDO { + @primary id: int, + root: string, + public_id: string, + system_id: string, + location_id: int +} +impl XmlDtdDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlDtdDO { + for (tmp in db.xml_dtd) { + yield XmlDtdDO { + id : tmp.id, + root : tmp.root, + public_id : tmp.public_id, + system_id : tmp.system_id, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the root of the element. + * @return string + */ + pub fn getRoot(self) -> string { + return self.root + } + /** + * @brief gets the public id (which is a string) of the element. + * @return string + */ + pub fn getPublicId(self) -> string { + return self.public_id + } + /** + * @brief gets the system id (which is a string) of the element. + * @return string + */ + pub fn getSystemId(self) -> string { + return self.system_id + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: An xml encoding. + */ +schema XmlEncodingDO { + @primary id: int, + encoding: string +} +impl XmlEncodingDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlEncodingDO { + for (tmp in db.xml_encoding) { + yield XmlEncodingDO { + id : tmp.id, + encoding : tmp.encoding + } + } + } + /** + * @brief gets the encoding information. + * @return string + */ + pub fn getEncoding(self) -> string { + return self.encoding + } +} +/** + * @brief DO class: Describe the name space relation. + */ +schema XmlHasNamespaceDO { + @primary id: int, + element_id: int, + namespace_id: int, + container_id: int +} +impl XmlHasNamespaceDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlHasNamespaceDO { + for (tmp in db.xml_has_namespace) { + yield XmlHasNamespaceDO { + id : tmp.id, + element_id : tmp.element_id, + namespace_id : tmp.namespace_id, + container_id : tmp.container_id + } + } + } + /** + * @brief gets the element id. + * @return int + */ + pub fn getElementId(self) -> int { + return self.element_id + } + /** + * @brief gets the namespace id. + * @return int + */ + pub fn getNamespaceId(self) -> int { + return self.namespace_id + } + /** + * @brief gets the container id. + * @return int + */ + pub fn getContainerId(self) -> int { + return self.container_id + } +} +/** + * @brief DO class: An xml namespace. + */ +schema XmlNamespaceDO { + @primary id: int, + prefix_name: string, + url: string, + location_id: int +} +impl XmlNamespaceDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlNamespaceDO { + for (tmp in db.xml_namespace) { + yield XmlNamespaceDO { + id : tmp.id, + prefix_name : tmp.prefix_name, + url : tmp.url, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the prefix name of the element. + * @return string + */ + pub fn getPrefixName(self) -> string { + return self.prefix_name + } + /** + * @brief gets the url of the element. + * @return string + */ + pub fn getUrl(self) -> string { + return self.url + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: An xml element prefix. + */ +schema XmlElementPrefixDO { + name: string, + @primary id: int, + parent_id: int, + location_id: int +} +impl XmlElementPrefixDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlElementPrefixDO { + for (tmp in db.xml_element_prefix) { + yield XmlElementPrefixDO { + name : tmp.name, + id : tmp.id, + parent_id : tmp.parent_id, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the name of the element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the parent id of the element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: An xml element name. + */ +schema XmlElementNameDO { + name: string, + @primary id: int, + parent_id: int, + location_id: int +} +impl XmlElementNameDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlElementNameDO { + for (tmp in db.xml_element_name) { + yield XmlElementNameDO { + name : tmp.name, + id : tmp.id, + parent_id : tmp.parent_id, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the name of the element. + * @return string + */ + pub fn getName(self) -> string { + return self.name + } + /** + * @brief gets the parent id of the element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: An xml element. + */ +schema XmlElementDO { + @primary id: int, + parent_id: int, + index_order: int, + location_id: int +} +impl XmlElementDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlElementDO { + for (tmp in db.xml_element) { + yield XmlElementDO { + id : tmp.id, + parent_id : tmp.parent_id, + index_order : tmp.index_order, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the parent id of the element. + * @return int + */ + pub fn getParentId(self) -> int { + return self.parent_id + } + /** + * @brief gets the index of the element. + * @return int + */ + pub fn getIndex(self) -> int { + return self.index_order + } + /** + * @brief gets the location id of this element. + * @return int + */ + pub fn getLocationId(self) -> int { + return self.location_id + } +} +/** + * @brief DO class: An xml file. + */ +schema XmlFileDO { + @primary id: int, + file_name: string, + relative_path: string +} +impl XmlFileDO { + @data_constraint + fn __all__(db: XmlDB) -> *XmlFileDO { + for (tmp in db.xml_file) { + yield XmlFileDO { + id : tmp.id, + file_name : tmp.file_name, + relative_path : tmp.relative_path + } + } + } + /** + * @brief gets the name of the file. + * @return string + */ + pub fn getFileName(self) -> string { + return self.file_name + } + /** + * @brief gets the relative path of the file. + * @return string + */ + pub fn getRelativePath(self) -> string { + return self.relative_path + } +} +/** + * @brief DO class: The location information of a locatable xml elements. + */ +schema LocationDO { + @primary id: int, + start_line_number: int, + start_column_number: int, + end_line_number: int, + end_column_number: int, + file_id: int +} +impl LocationDO { + @data_constraint + fn __all__(db: XmlDB) -> *LocationDO { + for (tmp in db.xml_location) { + yield LocationDO { + id : tmp.id, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number, + file_id : tmp.file_id + } + } + } + /** + * @brief gets the start line number of the location element. + * @return int + */ + pub fn getStartLineNumber(self) -> int { + return self.start_line_number + } + /** + * @brief gets the start column number of the location element. + * @return int + */ + pub fn getStartColumnNumber(self) -> int { + return self.start_column_number + } + /** + * @brief gets the end line number of the location element. + * @return int + */ + pub fn getEndLineNumber(self) -> int { + return self.end_line_number + } + /** + * @brief gets the end column number of the location element. + * @return int + */ + pub fn getEndColumnNumber(self) -> int { + return self.end_column_number + } + /** + * @brief gets the file id of the location element. + * @return int + */ + pub fn getFileId(self) -> int { + return self.file_id + } +} +database XmlDB { + xml_attribute: *XmlAttributeDO, + xml_character: *XmlCharacterDO, + xml_comment: *XmlCommentDO, + xml_dtd: *XmlDtdDO, + xml_encoding: *XmlEncodingDO, + xml_has_namespace: *XmlHasNamespaceDO, + xml_namespace: *XmlNamespaceDO, + xml_element_prefix: *XmlElementPrefixDO, + xml_element_name: *XmlElementNameDO, + xml_element: *XmlElementDO, + xml_file: *XmlFileDO, + xml_location: *LocationDO, +} diff --git a/language/xml/lib/Element.gdl b/language/xml/lib/Element.gdl new file mode 100644 index 00000000..0c884503 --- /dev/null +++ b/language/xml/lib/Element.gdl @@ -0,0 +1,582 @@ +/** + * @brief An xml attribute. + */ +schema XmlAttribute extends XmlAttributeDO { + +} +impl XmlAttribute { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlAttribute { + for (tmp in XmlAttributeDO(db)) { + yield XmlAttribute { + id : tmp.id, + element_id : tmp.element_id, + name : tmp.name, + value : tmp.value, + index_order : tmp.index_order, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the xml element of the attribute + * @return XmlElement + */ + pub fn getXmlElement(self) -> XmlElement { + for (element in XmlElement(__all_data__)) { + if (element.id = self.getElementId()) { + return element + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.id = self.getLocationId()) { + return loc + } + } + } +} +/** + * @brief An xml character. + */ +schema XmlCharacter extends XmlCharacterDO { + +} +impl XmlCharacter { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlCharacter { + for (tmp in XmlCharacterDO(db)) { + yield XmlCharacter { + id : tmp.id, + text : tmp.text, + parentid : tmp.parentid, + index_order : tmp.index_order, + is_cdata : tmp.is_cdata, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the belonged xml element of this xml character. + * @return XmlElement + */ + pub fn getBelongedElement(self) -> XmlElement { + for (e in XmlElement(__all_data__)) { + if (e.id = self.getParentid()) { + return e + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.id = self.getLocationId()) { + return loc + } + } + } +} +/** + * @brief An xml comment. + */ +schema XmlComment extends XmlCommentDO { + +} +impl XmlComment { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlComment { + for (tmp in XmlCommentDO(db)) { + yield XmlComment { + id : tmp.id, + text : tmp.text, + parent_id : tmp.parent_id, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.id = self.getLocationId()) { + return loc + } + } + } +} +/** + * @brief An xml dtd. + */ +schema XmlDtd extends XmlDtdDO { + +} +impl XmlDtd { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlDtd { + for (tmp in XmlDtdDO(db)) { + yield XmlDtd { + id : tmp.id, + root : tmp.root, + public_id : tmp.public_id, + system_id : tmp.system_id, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.id = self.getLocationId()) { + return loc + } + } + } +} +/** + * @brief An xml encoding element. + */ +schema XmlEncoding extends XmlEncodingDO { + +} +impl XmlEncoding { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlEncoding { + for (tmp in XmlEncodingDO(db)) { + yield XmlEncoding { + id : tmp.id, + encoding : tmp.encoding + } + } + } +} +/** + * @brief Describe the name space relation. + */ +schema XmlHasNamespace extends XmlHasNamespaceDO { + +} +impl XmlHasNamespace { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlHasNamespace { + for (tmp in XmlHasNamespaceDO(db)) { + yield XmlHasNamespace { + id : tmp.id, + element_id : tmp.element_id, + namespace_id : tmp.namespace_id, + container_id : tmp.container_id + } + } + } + /** + * @brief gets the element of the relation. + * @return XmlElement + */ + pub fn getXmlElement(self) -> XmlElement { + for (element in XmlElement(__all_data__)) { + if (element.id = self.getElementId()) { + return element + } + } + } + /** + * @brief gets the namespace of the relation. + * @return XmlNamespace + */ + pub fn getXmlNamespace(self) -> XmlNamespace { + for (namespace in XmlNamespace(__all_data__)) { + if (namespace.id = self.getNamespaceId()) { + return namespace + } + } + } + /** + * @brief gets the file of the location. + * @return XmlFile + */ + pub fn getFile(self) -> XmlFile { + for (file in XmlFile(__all_data__)) { + if (file.id = self.getContainerId()) { + return file + } + } + } +} +/** + * @brief An xml namespace. + */ +schema XmlNamespace extends XmlNamespaceDO { + +} +impl XmlNamespace { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlNamespace { + for (tmp in XmlNamespaceDO(db)) { + yield XmlNamespace { + id : tmp.id, + prefix_name : tmp.prefix_name, + url : tmp.url, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the belonged xml element of the element. + * @return XmlElement + */ + pub fn getXmlElement(self) -> XmlElement { + for (relation in XmlHasNamespace(__all_data__), + element in XmlElement(__all_data__)) { + if (self = relation.getXmlNamespace()) { + if (element = relation.getXmlElement()) { + return element + } + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.id = self.getLocationId()) { + return loc + } + } + } + /** + * @brief gets the name for the element. + * @return string + */ + pub fn getName(self) -> string { + let (temp = self.getPrefixName()) { + if (temp = "-1") { + return "xmlns" + } + if (temp != "-1") { + return "xmlns:" + temp + } + } + } +} +/** + * @brief An xml element prefix. + */ +schema XmlElementPrefix extends XmlElementPrefixDO { + +} +impl XmlElementPrefix { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlElementPrefix { + for (tmp in XmlElementPrefixDO(db)) { + yield XmlElementPrefix { + name : tmp.name, + id : tmp.id, + parent_id : tmp.parent_id, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.id = self.getLocationId()) { + return loc + } + } + } + /** + * @brief gets the element of the prefix. + * @return XmlElement + */ + pub fn getParent(self) -> XmlElement { + for (parent in XmlElement(__all_data__)) { + if (parent.id = self.getParentId()) { + return parent + } + } + } +} +/** + * @brief An xml element name. + */ +schema XmlElementName extends XmlElementNameDO { + +} +impl XmlElementName { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlElementName { + for (tmp in XmlElementNameDO(db)) { + yield XmlElementName { + name : tmp.name, + id : tmp.id, + parent_id : tmp.parent_id, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.id = self.getLocationId()) { + return loc + } + } + } + /** + * @brief gets the xml element of the element. + * @return XmlElement + */ + pub fn getParent(self) -> XmlElement { + for (parent in XmlElement(__all_data__)) { + if (parent.id = self.getParentId()) { + return parent + } + } + } +} +/** + * @brief An xml element. + */ +schema XmlElement extends XmlElementDO { + +} +impl XmlElement { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlElement { + for (tmp in XmlElementDO(db)) { + yield XmlElement { + id : tmp.id, + parent_id : tmp.parent_id, + index_order : tmp.index_order, + location_id : tmp.location_id + } + } + } + /** + * @brief gets the parent of the element. + * @return XmlElement + */ + pub fn getParent(self) -> XmlElement { + for (parent in XmlElement(__all_data__)) { + if (parent.id = self.getParentId()) { + return parent + } + } + } + /** + * @brief gets an ancestor of the element. + * @return XmlElement + */ + pub fn getAnAncestor(self) -> *XmlElement { + for (ancestor in XmlElement(__all_data__)) { + if (ancestor = self.getParent()) { + yield ancestor + } + for (temp in XmlElement(__all_data__)) { + if (ancestor = temp.getParent()) { + for (auto_tmp1 in self.getAnAncestor()) { + if (temp = auto_tmp1) { + yield ancestor + } + } + } + } + } + } + /** + * @brief gets a child element of the element. + * @return XmlElement + */ + pub fn getAChild(self) -> *XmlElement { + for (child in XmlElement(__all_data__)) { + if (self = child.getParent()) { + yield child + } + } + } + /** + * @brief gets the prefix of the element + * @return string + */ + pub fn getElementPrefix(self) -> string { + for (prefix in string::__undetermined_all__()) { + for (elementPrefix in XmlElementPrefix(__all_data__)) { + if (self = elementPrefix.getParent()) { + if (prefix = elementPrefix.getName()) { + return prefix + } + } + } + } + } + /** + * @brief gets the element name. + * @return string + */ + pub fn getElementName(self) -> string { + for (name in string::__undetermined_all__()) { + for (element in XmlElementName(__all_data__)) { + if (self = element.getParent()) { + if (name = element.getName()) { + return name + } + } + } + } + } + /** + * @brief gets the attribute of the element, if any. + * @return XmlAttribute + */ + pub fn getAttribute(self) -> *XmlAttribute { + for (attribute in XmlAttribute(__all_data__)) { + if (self = attribute.getXmlElement()) { + yield attribute + } + } + } + /** + * @brief gets the xml character of the element, if any. + * @return XmlCharacter + */ + pub fn getCharacter(self) -> *XmlCharacter { + for (char in XmlCharacter(__all_data__)) { + if (self = char.getBelongedElement()) { + yield char + } + } + } + /** + * @brief gets the location for the element. + * @return Location + */ + pub fn getLocation(self) -> Location { + for (loc in Location(__all_data__)) { + if (loc.id = self.getLocationId()) { + return loc + } + } + } + /** + * @brief gets the attribute's value by a given attribute name. + * @return string + */ + pub fn getValueByAttributeName(self, name : string) -> *string { + for (value in string::__undetermined_all__()) { + for (attr in XmlAttribute(__all_data__)) { + if (self = attr.getXmlElement()) { + if (name = attr.getName()) { + if (value = attr.getValue()) { + yield value + } + } + } + } + } + } + /** + * @brief gets the element's name with the prefix. + * @return string + */ + pub fn getName(self) -> string { + if (existsPrefix(self)) { + return self.getElementPrefix() + ":" + self.getElementName() + } + if (!existsPrefix(self)) { + return self.getElementName() + } + } +} +/** + * @brief An xml file. + */ +schema XmlFile extends XmlFileDO { + +} +impl XmlFile { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *XmlFile { + for (tmp in XmlFileDO(db)) { + yield XmlFile { + id : tmp.id, + file_name : tmp.file_name, + relative_path : tmp.relative_path + } + } + } +} +/** + * @brief The location information of a locatable xml elements. + */ +schema Location extends LocationDO { + +} +impl Location { + @data_constraint + @inline + fn __all__(db: XmlDB) -> *Location { + for (tmp in LocationDO(db)) { + yield Location { + id : tmp.id, + start_line_number : tmp.start_line_number, + start_column_number : tmp.start_column_number, + end_line_number : tmp.end_line_number, + end_column_number : tmp.end_column_number, + file_id : tmp.file_id + } + } + } + /** + * @brief gets the file of the location. + * @return XmlFile + */ + pub fn getFile(self) -> XmlFile { + for (file in XmlFile(__all_data__)) { + if (file.id = self.getFileId()) { + return file + } + } + } +} +pub fn existsPrefix(e : XmlElement) -> bool { + for (prefix in string::__undetermined_all__()) { + for (elementPrefix in XmlElementPrefix(__all_data__)) { + if (e = elementPrefix.getParent()) { + if (prefix = elementPrefix.getName()) { + return true + } + } + } + } +} From b75a5a7884fd49ab347700dde2dbc5471bac194e Mon Sep 17 00:00:00 2001 From: codefuse-admin Date: Mon, 27 Nov 2023 11:12:18 +0800 Subject: [PATCH 2/2] [Refactor] change tab to 4 space --- example/java/ClassHierarchy.gdl | 4 +- example/java/ClassMethods.gdl | 4 +- language/javascript/lib/Completion.gdl | 2 +- language/javascript/lib/DOClass.gdl | 104 +++---- language/python/lib/DOClass.gdl | 372 ++++++++++++------------- language/xml/lib/DOClass.gdl | 48 ++-- 6 files changed, 267 insertions(+), 267 deletions(-) diff --git a/example/java/ClassHierarchy.gdl b/example/java/ClassHierarchy.gdl index 4da21271..71794f0e 100644 --- a/example/java/ClassHierarchy.gdl +++ b/example/java/ClassHierarchy.gdl @@ -2,7 +2,7 @@ use coref::java::* fn default_java_db() -> JavaDB { - return JavaDB::load("coref_java_src.db") + return JavaDB::load("coref_java_src.db") } /** @@ -19,5 +19,5 @@ fn class_hierarchy(className : string, superClassName : string) -> bool { } fn main() { - output(class_hierarchy()) + output(class_hierarchy()) } \ No newline at end of file diff --git a/example/java/ClassMethods.gdl b/example/java/ClassMethods.gdl index 95b9fa2a..a04d4526 100644 --- a/example/java/ClassMethods.gdl +++ b/example/java/ClassMethods.gdl @@ -2,7 +2,7 @@ use coref::java::* fn default_java_db() -> JavaDB { - return JavaDB::load("coref_java_src.db") + return JavaDB::load("coref_java_src.db") } // Find all methods of the class @@ -16,5 +16,5 @@ fn methods(className : string, methodName : string) -> bool { } fn main() { - output(methods()) + output(methods()) } \ No newline at end of file diff --git a/language/javascript/lib/Completion.gdl b/language/javascript/lib/Completion.gdl index 93079c52..4e6e7554 100644 --- a/language/javascript/lib/Completion.gdl +++ b/language/javascript/lib/Completion.gdl @@ -8,7 +8,7 @@ impl Completion { @inline pub fn __all__() -> *Completion { yield Completion {id: 1001, name: "NormalCompletion"} - yield Completion {id: 1101, name: "ReturnCompletion"} + yield Completion {id: 1101, name: "ReturnCompletion"} // BooleanCompletion yield Completion {id: 1201, name: "BooleanCompletion"} yield Completion {id: 1202, name: "TrueBooleanCompletion"} diff --git a/language/javascript/lib/DOClass.gdl b/language/javascript/lib/DOClass.gdl index 233db9a5..6acbbf13 100644 --- a/language/javascript/lib/DOClass.gdl +++ b/language/javascript/lib/DOClass.gdl @@ -17,7 +17,7 @@ impl LocationDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *LocationDO { - for (tmp in db.location) { + for (tmp in db.location) { yield LocationDO { oid : tmp.oid, file_oid : tmp.file_oid, @@ -27,7 +27,7 @@ impl LocationDO { end_column_number : tmp.end_column_number, text : tmp.text } - } + } } pub fn getFileOid(self) -> int { @@ -66,14 +66,14 @@ impl NumberOfLinesDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *NumberOfLinesDO { - for (tmp in db.number_of_lines) { + for (tmp in db.number_of_lines) { yield NumberOfLinesDO { location_oid : tmp.location_oid, lines : tmp.lines, code_lines : tmp.code_lines, comment_lines : tmp.comment_lines } - } + } } pub fn getLines(self) -> int { @@ -101,7 +101,7 @@ impl FileDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *FileDO { - for (tmp in db.file) { + for (tmp in db.file) { yield FileDO { oid : tmp.oid, name : tmp.name, @@ -109,7 +109,7 @@ impl FileDO { relative_path : tmp.relative_path, location_oid : tmp.location_oid } - } + } } pub fn getName(self) -> string { @@ -140,14 +140,14 @@ impl DirectoryDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *DirectoryDO { - for (tmp in db.directory) { + for (tmp in db.directory) { yield DirectoryDO { oid : tmp.oid, name : tmp.name, relative_path : tmp.relative_path, location_oid : tmp.location_oid } - } + } } pub fn getName(self) -> string { @@ -172,12 +172,12 @@ impl DirectoryHierarchyDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *DirectoryHierarchyDO { - for (tmp in db.directory_hierarchy) { + for (tmp in db.directory_hierarchy) { yield DirectoryHierarchyDO { parent_oid : tmp.parent_oid, child_oid : tmp.child_oid } - } + } } pub fn getParentOid(self) -> int { @@ -195,13 +195,13 @@ impl TopLevelDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *TopLevelDO { - for (tmp in db.top_level) { + for (tmp in db.top_level) { yield TopLevelDO { oid : tmp.oid, kind : tmp.kind, location_oid : tmp.location_oid } - } + } } pub fn getKind(self) -> int { @@ -225,7 +225,7 @@ impl NodeDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *NodeDO { - for (tmp in db.node) { + for (tmp in db.node) { yield NodeDO { oid : tmp.oid, kind : tmp.kind, @@ -233,7 +233,7 @@ impl NodeDO { index : tmp.index, location_oid : tmp.location_oid } - } + } } pub fn getKind(self) -> int { @@ -262,12 +262,12 @@ impl LiteralDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *LiteralDO { - for (tmp in db.literal) { + for (tmp in db.literal) { yield LiteralDO { oid : tmp.oid, value : tmp.value } - } + } } pub fn getValue(self) -> string { @@ -284,12 +284,12 @@ impl BindingElementPropertyNameDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *BindingElementPropertyNameDO { - for (tmp in db.binding_element_property_name) { + for (tmp in db.binding_element_property_name) { yield BindingElementPropertyNameDO { oid : tmp.oid, property_name_oid : tmp.property_name_oid } - } + } } pub fn getPropertyNameOid(self) -> int { @@ -306,12 +306,12 @@ impl BindingElementNameDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *BindingElementNameDO { - for (tmp in db.binding_element_name) { + for (tmp in db.binding_element_name) { yield BindingElementNameDO { oid : tmp.oid, name_oid : tmp.name_oid } - } + } } pub fn getNameOid(self) -> int { @@ -328,12 +328,12 @@ impl BindingElementInitializerDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *BindingElementInitializerDO { - for (tmp in db.binding_element_initializer) { + for (tmp in db.binding_element_initializer) { yield BindingElementInitializerDO { oid : tmp.oid, initializer_oid : tmp.initializer_oid } - } + } } pub fn getInitializerOid(self) -> int { @@ -351,13 +351,13 @@ impl ClassLikeDeclarationDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *ClassLikeDeclarationDO { - for (tmp in db.class_like_declaration) { + for (tmp in db.class_like_declaration) { yield ClassLikeDeclarationDO { oid : tmp.oid, kind : tmp.kind, name : tmp.name } - } + } } pub fn getKind(self) -> int { @@ -379,13 +379,13 @@ impl FunctionLikeDeclarationDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *FunctionLikeDeclarationDO { - for (tmp in db.function_like_declaration) { + for (tmp in db.function_like_declaration) { yield FunctionLikeDeclarationDO { oid : tmp.oid, kind : tmp.kind, name : tmp.name } - } + } } pub fn getKind(self) -> int { @@ -406,12 +406,12 @@ impl FunctionEnclosingNodeDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *FunctionEnclosingNodeDO { - for (tmp in db.function_enclosing_node) { + for (tmp in db.function_enclosing_node) { yield FunctionEnclosingNodeDO { node_oid : tmp.node_oid, function_oid : tmp.function_oid } - } + } } pub fn getFunctionOid(self) -> int { @@ -428,12 +428,12 @@ impl ModifierDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *ModifierDO { - for (tmp in db.modifier) { + for (tmp in db.modifier) { yield ModifierDO { oid : tmp.oid, index : tmp.index } - } + } } pub fn getIndex(self) -> int { @@ -451,13 +451,13 @@ impl SymbolDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *SymbolDO { - for (tmp in db.symbol_) { + for (tmp in db.symbol_) { yield SymbolDO { oid : tmp.oid, name : tmp.name, description : tmp.description } - } + } } pub fn getName(self) -> string { @@ -478,12 +478,12 @@ impl NodeSymbolDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *NodeSymbolDO { - for (tmp in db.node_symbol) { + for (tmp in db.node_symbol) { yield NodeSymbolDO { node_oid : tmp.node_oid, symbol_oid : tmp.symbol_oid } - } + } } pub fn getSymbolOid(self) -> int { @@ -500,12 +500,12 @@ impl ShorthandAssignmentValueSymbolDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *ShorthandAssignmentValueSymbolDO { - for (tmp in db.shorthand_assignment_value_symbol) { + for (tmp in db.shorthand_assignment_value_symbol) { yield ShorthandAssignmentValueSymbolDO { node_oid : tmp.node_oid, symbol_oid : tmp.symbol_oid } - } + } } pub fn getSymbolOid(self) -> int { @@ -522,12 +522,12 @@ impl CallSiteDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *CallSiteDO { - for (tmp in db.call_site) { + for (tmp in db.call_site) { yield CallSiteDO { invoke_expression_oid : tmp.invoke_expression_oid, callee_oid : tmp.callee_oid } - } + } } pub fn getCalleeOid(self) -> int { @@ -544,12 +544,12 @@ impl CfgEntryNodeDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *CfgEntryNodeDO { - for (tmp in db.cfg_entry_node) { + for (tmp in db.cfg_entry_node) { yield CfgEntryNodeDO { oid : tmp.oid, ast_node_oid : tmp.ast_node_oid } - } + } } pub fn getAstNodeOid(self) -> int { @@ -566,12 +566,12 @@ impl CfgExitNodeDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *CfgExitNodeDO { - for (tmp in db.cfg_exit_node) { + for (tmp in db.cfg_exit_node) { yield CfgExitNodeDO { oid : tmp.oid, ast_node_oid : tmp.ast_node_oid } - } + } } pub fn getAstNodeOid(self) -> int { @@ -589,13 +589,13 @@ impl CommentDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *CommentDO { - for (tmp in db.comment) { + for (tmp in db.comment) { yield CommentDO { oid : tmp.oid, kind : tmp.kind, location_oid : tmp.location_oid } - } + } } pub fn getKind(self) -> int { @@ -618,14 +618,14 @@ impl NodeCommentDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *NodeCommentDO { - for (tmp in db.node_comment) { + for (tmp in db.node_comment) { yield NodeCommentDO { oid : tmp.oid, node_oid : tmp.node_oid, comment_oid : tmp.comment_oid, type : tmp.type } - } + } } pub fn getNodeOid(self) -> int { @@ -651,13 +651,13 @@ impl JsParseErrorDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *JsParseErrorDO { - for (tmp in db.js_parse_error) { + for (tmp in db.js_parse_error) { yield JsParseErrorDO { oid : tmp.oid, message : tmp.message, line : tmp.line } - } + } } pub fn getMessage(self) -> string { @@ -679,13 +679,13 @@ impl MetadataDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *MetadataDO { - for (tmp in db.metadata) { + for (tmp in db.metadata) { yield MetadataDO { oid : tmp.oid, version : tmp.version, created_time : tmp.created_time } - } + } } pub fn getVersion(self) -> string { @@ -708,14 +708,14 @@ impl IgnoredPathDO { @data_constraint @inline pub fn __all__(db: JavascriptDB) -> *IgnoredPathDO { - for (tmp in db.ignored_path) { + for (tmp in db.ignored_path) { yield IgnoredPathDO { oid : tmp.oid, path_kind : tmp.path_kind, path : tmp.path, ignore_kind : tmp.ignore_kind } - } + } } pub fn getPathKind(self) -> int { diff --git a/language/python/lib/DOClass.gdl b/language/python/lib/DOClass.gdl index 58837532..0feeb448 100644 --- a/language/python/lib/DOClass.gdl +++ b/language/python/lib/DOClass.gdl @@ -14,7 +14,7 @@ impl AliasDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AliasDO { - for (tmp in db.alias) { + for (tmp in db.alias) { yield AliasDO { element_oid : tmp.element_oid, name : tmp.name, @@ -24,7 +24,7 @@ impl AliasDO { location_oid : tmp.location_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the name of this element. @@ -82,14 +82,14 @@ impl AnnotationAssignmentStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AnnotationAssignmentStatementDO { - for (tmp in db.annotation_assignment_statement) { + for (tmp in db.annotation_assignment_statement) { yield AnnotationAssignmentStatementDO { element_oid : tmp.element_oid, annotation_oid : tmp.annotation_oid, target_oid : tmp.target_oid, is_simple : tmp.is_simple } - } + } } /** * @brief gets the annotation oid of this element. @@ -129,7 +129,7 @@ impl ArgDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ArgDO { - for (tmp in db.arg) { + for (tmp in db.arg) { yield ArgDO { element_oid : tmp.element_oid, annotation : tmp.annotation, @@ -138,7 +138,7 @@ impl ArgDO { location_oid : tmp.location_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the annotation of this element. @@ -188,13 +188,13 @@ impl ArgumentsDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ArgumentsDO { - for (tmp in db.arguments) { + for (tmp in db.arguments) { yield ArgumentsDO { element_oid : tmp.element_oid, parent_oid : tmp.parent_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the parent oid of this element. @@ -222,12 +222,12 @@ impl AssertStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AssertStatementDO { - for (tmp in db.assert_statement) { + for (tmp in db.assert_statement) { yield AssertStatementDO { element_oid : tmp.element_oid, assert_condition_oid : tmp.assert_condition_oid } - } + } } /** * @brief gets the assert condition oid of this element. @@ -249,13 +249,13 @@ impl AssignmentStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AssignmentStatementDO { - for (tmp in db.assignment_statement) { + for (tmp in db.assignment_statement) { yield AssignmentStatementDO { element_oid : tmp.element_oid, value_oid : tmp.value_oid, targets_size : tmp.targets_size } - } + } } /** * @brief gets the value oid of this element. @@ -282,11 +282,11 @@ impl AsyncForStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AsyncForStatementDO { - for (tmp in db.async_for_statement) { + for (tmp in db.async_for_statement) { yield AsyncForStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -300,12 +300,12 @@ impl AsyncFunctionDefStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AsyncFunctionDefStatementDO { - for (tmp in db.async_function_def_statement) { + for (tmp in db.async_function_def_statement) { yield AsyncFunctionDefStatementDO { element_oid : tmp.element_oid, name : tmp.name } - } + } } /** * @brief gets the name of this element. @@ -325,11 +325,11 @@ impl AsyncWithStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AsyncWithStatementDO { - for (tmp in db.async_with_statement) { + for (tmp in db.async_with_statement) { yield AsyncWithStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -344,13 +344,13 @@ impl AttributeExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AttributeExpressionDO { - for (tmp in db.attribute_expression) { + for (tmp in db.attribute_expression) { yield AttributeExpressionDO { element_oid : tmp.element_oid, value_oid : tmp.value_oid, ctx_type : tmp.ctx_type } - } + } } /** * @brief gets the value oid of this element. @@ -380,14 +380,14 @@ impl AugmentedAssignmentStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AugmentedAssignmentStatementDO { - for (tmp in db.augmented_assignment_statement) { + for (tmp in db.augmented_assignment_statement) { yield AugmentedAssignmentStatementDO { element_oid : tmp.element_oid, op_code : tmp.op_code, target_expr_oid : tmp.target_expr_oid, value_expr_oid : tmp.value_expr_oid } - } + } } /** * @brief gets the op code of this element. @@ -422,12 +422,12 @@ impl AwaitExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *AwaitExpressionDO { - for (tmp in db.await_expression) { + for (tmp in db.await_expression) { yield AwaitExpressionDO { element_oid : tmp.element_oid, expr_value_oid : tmp.expr_value_oid } - } + } } /** * @brief gets the expr value oid of this element. @@ -450,14 +450,14 @@ impl BinOpExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *BinOpExpressionDO { - for (tmp in db.bin_op_expression) { + for (tmp in db.bin_op_expression) { yield BinOpExpressionDO { element_oid : tmp.element_oid, left_expr_oid : tmp.left_expr_oid, opcode : tmp.opcode, right_expr_oid : tmp.right_expr_oid } - } + } } /** * @brief gets the left expr oid of this element. @@ -493,13 +493,13 @@ impl BooleanOpExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *BooleanOpExpressionDO { - for (tmp in db.boolean_op_expression) { + for (tmp in db.boolean_op_expression) { yield BooleanOpExpressionDO { element_oid : tmp.element_oid, type : tmp.type, size : tmp.size } - } + } } /** * @brief gets the type of this element. @@ -526,11 +526,11 @@ impl BreakStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *BreakStatementDO { - for (tmp in db.break_statement) { + for (tmp in db.break_statement) { yield BreakStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -544,12 +544,12 @@ impl CallExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *CallExpressionDO { - for (tmp in db.call_expression) { + for (tmp in db.call_expression) { yield CallExpressionDO { element_oid : tmp.element_oid, expr_func_oid : tmp.expr_func_oid } - } + } } /** * @brief gets the expr func oid of this element. @@ -570,12 +570,12 @@ impl CallableBindingDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *CallableBindingDO { - for (tmp in db.callable_binding) { + for (tmp in db.callable_binding) { yield CallableBindingDO { caller_oid : tmp.caller_oid, callee_oid : tmp.callee_oid } - } + } } /** * @brief gets the callee oid of this element. @@ -596,12 +596,12 @@ impl ClassDefStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ClassDefStatementDO { - for (tmp in db.class_def_statement) { + for (tmp in db.class_def_statement) { yield ClassDefStatementDO { element_oid : tmp.element_oid, name : tmp.name } - } + } } /** * @brief gets the name of this element. @@ -622,12 +622,12 @@ impl ClassHierarchyDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ClassHierarchyDO { - for (tmp in db.class_hierarchy) { + for (tmp in db.class_hierarchy) { yield ClassHierarchyDO { base_oid : tmp.base_oid, class_oid : tmp.class_oid } - } + } } /** * @brief gets the class oid of this element. @@ -650,14 +650,14 @@ impl CmpopDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *CmpopDO { - for (tmp in db.cmpop) { + for (tmp in db.cmpop) { yield CmpopDO { element_oid : tmp.element_oid, value : tmp.value, location_oid : tmp.location_oid, parent_oid : tmp.parent_oid } - } + } } /** * @brief gets the value of this element. @@ -694,14 +694,14 @@ impl CommentDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *CommentDO { - for (tmp in db.comment) { + for (tmp in db.comment) { yield CommentDO { element_oid : tmp.element_oid, text : tmp.text, parent_oid : tmp.parent_oid, location_oid : tmp.location_oid } - } + } } /** * @brief gets the text of this element. @@ -736,12 +736,12 @@ impl CompareExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *CompareExpressionDO { - for (tmp in db.compare_expression) { + for (tmp in db.compare_expression) { yield CompareExpressionDO { element_oid : tmp.element_oid, left_expr_oid : tmp.left_expr_oid } - } + } } /** * @brief gets the left expr oid of this element. @@ -766,7 +766,7 @@ impl ComprehensionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ComprehensionDO { - for (tmp in db.comprehension) { + for (tmp in db.comprehension) { yield ComprehensionDO { element_oid : tmp.element_oid, target_expr_oid : tmp.target_expr_oid, @@ -775,7 +775,7 @@ impl ComprehensionDO { parent_oid : tmp.parent_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the target expr oid of this element. @@ -824,12 +824,12 @@ impl ConstantDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ConstantDO { - for (tmp in db.constant) { + for (tmp in db.constant) { yield ConstantDO { element_oid : tmp.element_oid, value : tmp.value } - } + } } /** * @brief gets the value of this element. @@ -850,12 +850,12 @@ impl ContainerParentDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ContainerParentDO { - for (tmp in db.container_parent) { + for (tmp in db.container_parent) { yield ContainerParentDO { child_oid : tmp.child_oid, parent_oid : tmp.parent_oid } - } + } } /** * @brief gets the parent oid of this element. @@ -875,11 +875,11 @@ impl ContinueStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ContinueStatementDO { - for (tmp in db.continue_statement) { + for (tmp in db.continue_statement) { yield ContinueStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -893,12 +893,12 @@ impl DecoratedRelationDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *DecoratedRelationDO { - for (tmp in db.decorated_relation) { + for (tmp in db.decorated_relation) { yield DecoratedRelationDO { decorator_oid : tmp.decorator_oid, decorated_element_oid : tmp.decorated_element_oid } - } + } } /** * @brief gets the decorated element oid of this element. @@ -920,13 +920,13 @@ impl DecoratorDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *DecoratorDO { - for (tmp in db.decorator) { + for (tmp in db.decorator) { yield DecoratorDO { element_oid : tmp.element_oid, type : tmp.type, printable_text : tmp.printable_text } - } + } } /** * @brief gets the type of this element. @@ -954,12 +954,12 @@ impl DeleteStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *DeleteStatementDO { - for (tmp in db.delete_statement) { + for (tmp in db.delete_statement) { yield DeleteStatementDO { element_oid : tmp.element_oid, targets_size : tmp.targets_size } - } + } } /** * @brief gets the targets size of this element. @@ -980,12 +980,12 @@ impl DictCompExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *DictCompExpressionDO { - for (tmp in db.dict_comp_expression) { + for (tmp in db.dict_comp_expression) { yield DictCompExpressionDO { element_oid : tmp.element_oid, comprehension_size : tmp.comprehension_size } - } + } } /** * @brief gets the comprehension size of this element. @@ -1006,12 +1006,12 @@ impl DictExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *DictExpressionDO { - for (tmp in db.dict_expression) { + for (tmp in db.dict_expression) { yield DictExpressionDO { element_oid : tmp.element_oid, size : tmp.size } - } + } } /** * @brief gets the size of this element. @@ -1033,13 +1033,13 @@ impl DocstringCommentDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *DocstringCommentDO { - for (tmp in db.docstring_comment) { + for (tmp in db.docstring_comment) { yield DocstringCommentDO { element_oid : tmp.element_oid, text : tmp.text, documented_element_oid : tmp.documented_element_oid } - } + } } /** * @brief gets the text of this element. @@ -1069,14 +1069,14 @@ impl ElementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ElementDO { - for (tmp in db.element) { + for (tmp in db.element) { yield ElementDO { oid : tmp.oid, value : tmp.value, type : tmp.type, parent_oid : tmp.parent_oid } - } + } } /** * @brief gets the value of this element. @@ -1114,7 +1114,7 @@ impl ExceptHandlerDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ExceptHandlerDO { - for (tmp in db.except_handler) { + for (tmp in db.except_handler) { yield ExceptHandlerDO { element_oid : tmp.element_oid, element_index : tmp.element_index, @@ -1122,7 +1122,7 @@ impl ExceptHandlerDO { location_oid : tmp.location_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the element index of this element. @@ -1165,13 +1165,13 @@ impl ExprContextDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ExprContextDO { - for (tmp in db.expr_context) { + for (tmp in db.expr_context) { yield ExprContextDO { element_oid : tmp.element_oid, parent_oid : tmp.parent_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the parent oid of this element. @@ -1203,7 +1203,7 @@ impl ExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ExpressionDO { - for (tmp in db.expression) { + for (tmp in db.expression) { yield ExpressionDO { element_oid : tmp.element_oid, type : tmp.type, @@ -1212,7 +1212,7 @@ impl ExpressionDO { location_oid : tmp.location_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the type of this element. @@ -1261,12 +1261,12 @@ impl ExpressionStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ExpressionStatementDO { - for (tmp in db.expression_statement) { + for (tmp in db.expression_statement) { yield ExpressionStatementDO { element_oid : tmp.element_oid, value_oid : tmp.value_oid } - } + } } /** * @brief gets the value oid of this element. @@ -1290,7 +1290,7 @@ impl FileDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *FileDO { - for (tmp in db.file) { + for (tmp in db.file) { yield FileDO { element_oid : tmp.element_oid, relative_path : tmp.relative_path, @@ -1298,7 +1298,7 @@ impl FileDO { name : tmp.name, number_of_lines_oid : tmp.number_of_lines_oid } - } + } } /** * @brief gets the relative path of this element. @@ -1340,12 +1340,12 @@ impl Modified2To3FileDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *Modified2To3FileDO { - for (tmp in db.modified_2to3_file) { + for (tmp in db.modified_2to3_file) { yield Modified2To3FileDO { element_oid : tmp.element_oid, relative_path : tmp.relative_path } - } + } } /** * @brief gets the relative path of this element. @@ -1368,14 +1368,14 @@ impl ParseErrorFileDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ParseErrorFileDO { - for (tmp in db.parse_error_file) { + for (tmp in db.parse_error_file) { yield ParseErrorFileDO { element_oid : tmp.element_oid, relative_path : tmp.relative_path, error_message : tmp.error_message, error_text : tmp.error_text } - } + } } /** * @brief gets the relative path of this element. @@ -1410,12 +1410,12 @@ impl FileMd5SumDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *FileMd5SumDO { - for (tmp in db.file_md5_sum) { + for (tmp in db.file_md5_sum) { yield FileMd5SumDO { file_oid : tmp.file_oid, value : tmp.value } - } + } } /** * @brief gets the value of this element. @@ -1436,12 +1436,12 @@ impl FileSha256SumDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *FileSha256SumDO { - for (tmp in db.file_sha256_sum) { + for (tmp in db.file_sha256_sum) { yield FileSha256SumDO { file_oid : tmp.file_oid, value : tmp.value } - } + } } /** * @brief gets the value of this element. @@ -1464,14 +1464,14 @@ impl FolderDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *FolderDO { - for (tmp in db.folder) { + for (tmp in db.folder) { yield FolderDO { element_oid : tmp.element_oid, qualified_name : tmp.qualified_name, name : tmp.name, parent_oid : tmp.parent_oid } - } + } } /** * @brief gets the qualified name of this element. @@ -1505,11 +1505,11 @@ impl ForStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ForStatementDO { - for (tmp in db.for_statement) { + for (tmp in db.for_statement) { yield ForStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -1523,12 +1523,12 @@ impl FormattedValueExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *FormattedValueExpressionDO { - for (tmp in db.formatted_value_expression) { + for (tmp in db.formatted_value_expression) { yield FormattedValueExpressionDO { element_oid : tmp.element_oid, value_oid : tmp.value_oid } - } + } } /** * @brief gets the value oid of this element. @@ -1549,12 +1549,12 @@ impl FunctionDefStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *FunctionDefStatementDO { - for (tmp in db.function_def_statement) { + for (tmp in db.function_def_statement) { yield FunctionDefStatementDO { element_oid : tmp.element_oid, name : tmp.name } - } + } } /** * @brief gets the name of this element. @@ -1575,12 +1575,12 @@ impl GeneratorExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *GeneratorExpressionDO { - for (tmp in db.generator_expression) { + for (tmp in db.generator_expression) { yield GeneratorExpressionDO { element_oid : tmp.element_oid, elt_oid : tmp.elt_oid } - } + } } /** * @brief gets the elt oid of this element. @@ -1601,12 +1601,12 @@ impl GlobalStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *GlobalStatementDO { - for (tmp in db.global_statement) { + for (tmp in db.global_statement) { yield GlobalStatementDO { element_oid : tmp.element_oid, names : tmp.names } - } + } } /** * @brief gets the names of this element. @@ -1626,11 +1626,11 @@ impl IfExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *IfExpressionDO { - for (tmp in db.if_expression) { + for (tmp in db.if_expression) { yield IfExpressionDO { element_oid : tmp.element_oid } - } + } } } /** @@ -1643,11 +1643,11 @@ impl IfStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *IfStatementDO { - for (tmp in db.if_statement) { + for (tmp in db.if_statement) { yield IfStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -1662,13 +1662,13 @@ impl ImportFromStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ImportFromStatementDO { - for (tmp in db.import_from_statement) { + for (tmp in db.import_from_statement) { yield ImportFromStatementDO { element_oid : tmp.element_oid, module : tmp.module, level : tmp.level } - } + } } /** * @brief gets the module of this element. @@ -1695,11 +1695,11 @@ impl ImportStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ImportStatementDO { - for (tmp in db.import_statement) { + for (tmp in db.import_statement) { yield ImportStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -1713,12 +1713,12 @@ impl JoinedStrExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *JoinedStrExpressionDO { - for (tmp in db.joined_str_expression) { + for (tmp in db.joined_str_expression) { yield JoinedStrExpressionDO { element_oid : tmp.element_oid, size : tmp.size } - } + } } /** * @brief gets the size of this element. @@ -1744,7 +1744,7 @@ impl KeywordDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *KeywordDO { - for (tmp in db.keyword) { + for (tmp in db.keyword) { yield KeywordDO { element_oid : tmp.element_oid, arg_value : tmp.arg_value, @@ -1754,7 +1754,7 @@ impl KeywordDO { location_oid : tmp.location_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the arg value of this element. @@ -1809,11 +1809,11 @@ impl LambdaExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *LambdaExpressionDO { - for (tmp in db.lambda_expression) { + for (tmp in db.lambda_expression) { yield LambdaExpressionDO { element_oid : tmp.element_oid } - } + } } } /** @@ -1828,13 +1828,13 @@ impl ListCompExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ListCompExpressionDO { - for (tmp in db.list_comp_expression) { + for (tmp in db.list_comp_expression) { yield ListCompExpressionDO { element_oid : tmp.element_oid, elt_oid : tmp.elt_oid, generator_size : tmp.generator_size } - } + } } /** * @brief gets the elt oid of this element. @@ -1863,13 +1863,13 @@ impl ListExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ListExpressionDO { - for (tmp in db.list_expression) { + for (tmp in db.list_expression) { yield ListExpressionDO { element_oid : tmp.element_oid, elt_size : tmp.elt_size, ctx : tmp.ctx } - } + } } /** * @brief gets the elt size of this element. @@ -1901,7 +1901,7 @@ impl LocationDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *LocationDO { - for (tmp in db.location) { + for (tmp in db.location) { yield LocationDO { element_oid : tmp.element_oid, file_oid : tmp.file_oid, @@ -1910,7 +1910,7 @@ impl LocationDO { end_line_number : tmp.end_line_number, end_column_number : tmp.end_column_number } - } + } } /** * @brief gets the file oid of this element. @@ -1964,7 +1964,7 @@ impl MatchCaseDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *MatchCaseDO { - for (tmp in db.match_case) { + for (tmp in db.match_case) { yield MatchCaseDO { element_oid : tmp.element_oid, pattern_oid : tmp.pattern_oid, @@ -1974,7 +1974,7 @@ impl MatchCaseDO { printable_text : tmp.printable_text, is_default : tmp.is_default } - } + } } /** * @brief gets the pattern oid of this element. @@ -2030,12 +2030,12 @@ impl MatchStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *MatchStatementDO { - for (tmp in db.match_statement) { + for (tmp in db.match_statement) { yield MatchStatementDO { element_oid : tmp.element_oid, subject_oid : tmp.subject_oid } - } + } } /** * @brief gets the subject oid of this element. @@ -2058,14 +2058,14 @@ impl MetainfoDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *MetainfoDO { - for (tmp in db.metainfo) { + for (tmp in db.metainfo) { yield MetainfoDO { oid : tmp.oid, kind : tmp.kind, value : tmp.value, program_oid : tmp.program_oid } - } + } } /** * @brief gets the kind of this element. @@ -2101,13 +2101,13 @@ impl ModDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ModDO { - for (tmp in db.mod) { + for (tmp in db.mod) { yield ModDO { element_oid : tmp.element_oid, type : tmp.type, location_oid : tmp.location_oid } - } + } } /** * @brief gets the type of this element. @@ -2137,14 +2137,14 @@ impl ModuleDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ModuleDO { - for (tmp in db.module) { + for (tmp in db.module) { yield ModuleDO { element_oid : tmp.element_oid, name : tmp.name, file_oid : tmp.file_oid, location_oid : tmp.location_oid } - } + } } /** * @brief gets the name of this element. @@ -2179,12 +2179,12 @@ impl ScopeEnclosingExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ScopeEnclosingExpressionDO { - for (tmp in db.scope_enclosing_expression) { + for (tmp in db.scope_enclosing_expression) { yield ScopeEnclosingExpressionDO { expression_oid : tmp.expression_oid, scope_oid : tmp.scope_oid } - } + } } /** * @brief gets the scope oid of this element. @@ -2205,12 +2205,12 @@ impl ScopeEnclosingStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ScopeEnclosingStatementDO { - for (tmp in db.scope_enclosing_statement) { + for (tmp in db.scope_enclosing_statement) { yield ScopeEnclosingStatementDO { statement_oid : tmp.statement_oid, scope_oid : tmp.scope_oid } - } + } } /** * @brief gets the scope oid of this element. @@ -2231,12 +2231,12 @@ impl NameExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *NameExpressionDO { - for (tmp in db.name_expression) { + for (tmp in db.name_expression) { yield NameExpressionDO { element_oid : tmp.element_oid, ctx_type : tmp.ctx_type } - } + } } /** * @brief gets the ctx type of this element. @@ -2258,13 +2258,13 @@ impl NamedExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *NamedExpressionDO { - for (tmp in db.named_expression) { + for (tmp in db.named_expression) { yield NamedExpressionDO { element_oid : tmp.element_oid, target_oid : tmp.target_oid, value_oid : tmp.value_oid } - } + } } /** * @brief gets the target oid of this element. @@ -2292,12 +2292,12 @@ impl NonLocalStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *NonLocalStatementDO { - for (tmp in db.non_local_statement) { + for (tmp in db.non_local_statement) { yield NonLocalStatementDO { element_oid : tmp.element_oid, names : tmp.names } - } + } } /** * @brief gets the names of this element. @@ -2320,14 +2320,14 @@ impl NumberOfLinesDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *NumberOfLinesDO { - for (tmp in db.number_of_lines) { + for (tmp in db.number_of_lines) { yield NumberOfLinesDO { element_oid : tmp.element_oid, number_of_total_lines : tmp.number_of_total_lines, number_of_valid_lines : tmp.number_of_valid_lines, number_of_comment_lines : tmp.number_of_comment_lines } - } + } } /** * @brief gets the number of total lines of this element. @@ -2364,14 +2364,14 @@ impl OperatorDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *OperatorDO { - for (tmp in db.operator) { + for (tmp in db.operator) { yield OperatorDO { element_oid : tmp.element_oid, location_oid : tmp.location_oid, parent_oid : tmp.parent_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the location oid of this element. @@ -2406,12 +2406,12 @@ impl ParentDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ParentDO { - for (tmp in db.parent) { + for (tmp in db.parent) { yield ParentDO { parent_oid : tmp.parent_oid, parent_type : tmp.parent_type } - } + } } /** * @brief gets the parent type of this element. @@ -2431,11 +2431,11 @@ impl PassStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *PassStatementDO { - for (tmp in db.pass_statement) { + for (tmp in db.pass_statement) { yield PassStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -2449,12 +2449,12 @@ impl ProgramDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ProgramDO { - for (tmp in db.program) { + for (tmp in db.program) { yield ProgramDO { program_oid : tmp.program_oid, absolute_prefix_path : tmp.absolute_prefix_path } - } + } } /** * @brief gets the absolute prefix path of this element. @@ -2474,11 +2474,11 @@ impl RaiseStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *RaiseStatementDO { - for (tmp in db.raise_statement) { + for (tmp in db.raise_statement) { yield RaiseStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -2492,12 +2492,12 @@ impl ReferenceRelationDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ReferenceRelationDO { - for (tmp in db.reference_relation) { + for (tmp in db.reference_relation) { yield ReferenceRelationDO { reference_element_oid : tmp.reference_element_oid, definition_element_oid : tmp.definition_element_oid } - } + } } /** * @brief gets the definition element oid of this element. @@ -2518,12 +2518,12 @@ impl ReturnStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *ReturnStatementDO { - for (tmp in db.return_statement) { + for (tmp in db.return_statement) { yield ReturnStatementDO { element_oid : tmp.element_oid, is_return_empty : tmp.is_return_empty } - } + } } /** * @brief gets the is return empty of this element. @@ -2545,13 +2545,13 @@ impl SetCompExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *SetCompExpressionDO { - for (tmp in db.set_comp_expression) { + for (tmp in db.set_comp_expression) { yield SetCompExpressionDO { element_oid : tmp.element_oid, elt_oid : tmp.elt_oid, generator_size : tmp.generator_size } - } + } } /** * @brief gets the elt oid of this element. @@ -2579,12 +2579,12 @@ impl SetExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *SetExpressionDO { - for (tmp in db.set_expression) { + for (tmp in db.set_expression) { yield SetExpressionDO { element_oid : tmp.element_oid, elt_size : tmp.elt_size } - } + } } /** * @brief gets the elt size of this element. @@ -2609,7 +2609,7 @@ impl SliceDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *SliceDO { - for (tmp in db.slice) { + for (tmp in db.slice) { yield SliceDO { element_oid : tmp.element_oid, element_index : tmp.element_index, @@ -2618,7 +2618,7 @@ impl SliceDO { printable_text : tmp.printable_text, has_step : tmp.has_step } - } + } } /** * @brief gets the element index of this element. @@ -2667,12 +2667,12 @@ impl StarredExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *StarredExpressionDO { - for (tmp in db.starred_expression) { + for (tmp in db.starred_expression) { yield StarredExpressionDO { element_oid : tmp.element_oid, ctx : tmp.ctx } - } + } } /** * @brief gets the ctx of this element. @@ -2697,7 +2697,7 @@ impl StatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *StatementDO { - for (tmp in db.statement) { + for (tmp in db.statement) { yield StatementDO { element_oid : tmp.element_oid, type : tmp.type, @@ -2706,7 +2706,7 @@ impl StatementDO { location_oid : tmp.location_oid, printable_text : tmp.printable_text } - } + } } /** * @brief gets the type of this element. @@ -2757,14 +2757,14 @@ impl SubscriptExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *SubscriptExpressionDO { - for (tmp in db.subscript_expression) { + for (tmp in db.subscript_expression) { yield SubscriptExpressionDO { element_oid : tmp.element_oid, value_oid : tmp.value_oid, slice_oid : tmp.slice_oid, ctx : tmp.ctx } - } + } } /** * @brief gets the value oid of this element. @@ -2801,14 +2801,14 @@ impl TokenDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *TokenDO { - for (tmp in db.token) { + for (tmp in db.token) { yield TokenDO { element_oid : tmp.element_oid, value : tmp.value, location_oid : tmp.location_oid, parent_oid : tmp.parent_oid } - } + } } /** * @brief gets the value of this element. @@ -2842,11 +2842,11 @@ impl TryStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *TryStatementDO { - for (tmp in db.try_statement) { + for (tmp in db.try_statement) { yield TryStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -2861,13 +2861,13 @@ impl TupleExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *TupleExpressionDO { - for (tmp in db.tuple_expression) { + for (tmp in db.tuple_expression) { yield TupleExpressionDO { element_oid : tmp.element_oid, elt_size : tmp.elt_size, ctx : tmp.ctx } - } + } } /** * @brief gets the elt size of this element. @@ -2897,14 +2897,14 @@ impl UnaryOpDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *UnaryOpDO { - for (tmp in db.unary_op) { + for (tmp in db.unary_op) { yield UnaryOpDO { element_oid : tmp.element_oid, type : tmp.type, location_oid : tmp.location_oid, parent_oid : tmp.parent_oid } - } + } } /** * @brief gets the type of this element. @@ -2940,13 +2940,13 @@ impl UnaryOpExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *UnaryOpExpressionDO { - for (tmp in db.unary_op_expression) { + for (tmp in db.unary_op_expression) { yield UnaryOpExpressionDO { element_oid : tmp.element_oid, op_code : tmp.op_code, operand_oid : tmp.operand_oid } - } + } } /** * @brief gets the op code of this element. @@ -2977,7 +2977,7 @@ impl VariableDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *VariableDO { - for (tmp in db.variable) { + for (tmp in db.variable) { yield VariableDO { element_oid : tmp.element_oid, parent_oid : tmp.parent_oid, @@ -2985,7 +2985,7 @@ impl VariableDO { printable_text : tmp.printable_text, name : tmp.name } - } + } } /** * @brief gets the parent oid of this element. @@ -3026,11 +3026,11 @@ impl WhileStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *WhileStatementDO { - for (tmp in db.while_statement) { + for (tmp in db.while_statement) { yield WhileStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -3046,14 +3046,14 @@ impl WithItemDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *WithItemDO { - for (tmp in db.with_item) { + for (tmp in db.with_item) { yield WithItemDO { element_oid : tmp.element_oid, printable_text : tmp.printable_text, element_index : tmp.element_index, parent_oid : tmp.parent_oid } - } + } } /** * @brief gets the printable text of this element. @@ -3087,11 +3087,11 @@ impl WithStatementDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *WithStatementDO { - for (tmp in db.with_statement) { + for (tmp in db.with_statement) { yield WithStatementDO { element_oid : tmp.element_oid } - } + } } } /** @@ -3104,11 +3104,11 @@ impl YieldExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *YieldExpressionDO { - for (tmp in db.yield_expression) { + for (tmp in db.yield_expression) { yield YieldExpressionDO { element_oid : tmp.element_oid } - } + } } } /** @@ -3122,12 +3122,12 @@ impl YieldFromExpressionDO { @data_constraint @inline pub fn __all__(db: PythonDB) -> *YieldFromExpressionDO { - for (tmp in db.yield_from_expression) { + for (tmp in db.yield_from_expression) { yield YieldFromExpressionDO { element_oid : tmp.element_oid, value : tmp.value } - } + } } /** * @brief gets the value of this element. diff --git a/language/xml/lib/DOClass.gdl b/language/xml/lib/DOClass.gdl index 2f35d002..a9cd21ba 100644 --- a/language/xml/lib/DOClass.gdl +++ b/language/xml/lib/DOClass.gdl @@ -12,7 +12,7 @@ schema XmlAttributeDO { impl XmlAttributeDO { @data_constraint fn __all__(db: XmlDB) -> *XmlAttributeDO { - for (tmp in db.xml_attribute) { + for (tmp in db.xml_attribute) { yield XmlAttributeDO { id : tmp.id, element_id : tmp.element_id, @@ -21,7 +21,7 @@ impl XmlAttributeDO { index_order : tmp.index_order, location_id : tmp.location_id } - } + } } /** * @brief gets the element id of the attribute. @@ -73,7 +73,7 @@ schema XmlCharacterDO { impl XmlCharacterDO { @data_constraint fn __all__(db: XmlDB) -> *XmlCharacterDO { - for (tmp in db.xml_character) { + for (tmp in db.xml_character) { yield XmlCharacterDO { id : tmp.id, text : tmp.text, @@ -82,7 +82,7 @@ impl XmlCharacterDO { is_cdata : tmp.is_cdata, location_id : tmp.location_id } - } + } } /** * @brief gets the text of the element. @@ -132,14 +132,14 @@ schema XmlCommentDO { impl XmlCommentDO { @data_constraint fn __all__(db: XmlDB) -> *XmlCommentDO { - for (tmp in db.xml_comment) { + for (tmp in db.xml_comment) { yield XmlCommentDO { id : tmp.id, text : tmp.text, parent_id : tmp.parent_id, location_id : tmp.location_id } - } + } } /** * @brief gets the text of the comment. @@ -176,7 +176,7 @@ schema XmlDtdDO { impl XmlDtdDO { @data_constraint fn __all__(db: XmlDB) -> *XmlDtdDO { - for (tmp in db.xml_dtd) { + for (tmp in db.xml_dtd) { yield XmlDtdDO { id : tmp.id, root : tmp.root, @@ -184,7 +184,7 @@ impl XmlDtdDO { system_id : tmp.system_id, location_id : tmp.location_id } - } + } } /** * @brief gets the root of the element. @@ -225,12 +225,12 @@ schema XmlEncodingDO { impl XmlEncodingDO { @data_constraint fn __all__(db: XmlDB) -> *XmlEncodingDO { - for (tmp in db.xml_encoding) { + for (tmp in db.xml_encoding) { yield XmlEncodingDO { id : tmp.id, encoding : tmp.encoding } - } + } } /** * @brief gets the encoding information. @@ -252,14 +252,14 @@ schema XmlHasNamespaceDO { impl XmlHasNamespaceDO { @data_constraint fn __all__(db: XmlDB) -> *XmlHasNamespaceDO { - for (tmp in db.xml_has_namespace) { + for (tmp in db.xml_has_namespace) { yield XmlHasNamespaceDO { id : tmp.id, element_id : tmp.element_id, namespace_id : tmp.namespace_id, container_id : tmp.container_id } - } + } } /** * @brief gets the element id. @@ -295,14 +295,14 @@ schema XmlNamespaceDO { impl XmlNamespaceDO { @data_constraint fn __all__(db: XmlDB) -> *XmlNamespaceDO { - for (tmp in db.xml_namespace) { + for (tmp in db.xml_namespace) { yield XmlNamespaceDO { id : tmp.id, prefix_name : tmp.prefix_name, url : tmp.url, location_id : tmp.location_id } - } + } } /** * @brief gets the prefix name of the element. @@ -338,14 +338,14 @@ schema XmlElementPrefixDO { impl XmlElementPrefixDO { @data_constraint fn __all__(db: XmlDB) -> *XmlElementPrefixDO { - for (tmp in db.xml_element_prefix) { + for (tmp in db.xml_element_prefix) { yield XmlElementPrefixDO { name : tmp.name, id : tmp.id, parent_id : tmp.parent_id, location_id : tmp.location_id } - } + } } /** * @brief gets the name of the element. @@ -381,14 +381,14 @@ schema XmlElementNameDO { impl XmlElementNameDO { @data_constraint fn __all__(db: XmlDB) -> *XmlElementNameDO { - for (tmp in db.xml_element_name) { + for (tmp in db.xml_element_name) { yield XmlElementNameDO { name : tmp.name, id : tmp.id, parent_id : tmp.parent_id, location_id : tmp.location_id } - } + } } /** * @brief gets the name of the element. @@ -424,14 +424,14 @@ schema XmlElementDO { impl XmlElementDO { @data_constraint fn __all__(db: XmlDB) -> *XmlElementDO { - for (tmp in db.xml_element) { + for (tmp in db.xml_element) { yield XmlElementDO { id : tmp.id, parent_id : tmp.parent_id, index_order : tmp.index_order, location_id : tmp.location_id } - } + } } /** * @brief gets the parent id of the element. @@ -466,13 +466,13 @@ schema XmlFileDO { impl XmlFileDO { @data_constraint fn __all__(db: XmlDB) -> *XmlFileDO { - for (tmp in db.xml_file) { + for (tmp in db.xml_file) { yield XmlFileDO { id : tmp.id, file_name : tmp.file_name, relative_path : tmp.relative_path } - } + } } /** * @brief gets the name of the file. @@ -503,7 +503,7 @@ schema LocationDO { impl LocationDO { @data_constraint fn __all__(db: XmlDB) -> *LocationDO { - for (tmp in db.xml_location) { + for (tmp in db.xml_location) { yield LocationDO { id : tmp.id, start_line_number : tmp.start_line_number, @@ -512,7 +512,7 @@ impl LocationDO { end_column_number : tmp.end_column_number, file_id : tmp.file_id } - } + } } /** * @brief gets the start line number of the location element.